]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blame - test/grsecurity-3.0-3.18.3-201501182219.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-3.0-3.18.3-201501182219.patch
CommitLineData
4f362b62
PK
1diff --git a/Documentation/dontdiff b/Documentation/dontdiff
2index 9de9813..1462492 100644
3--- a/Documentation/dontdiff
4+++ b/Documentation/dontdiff
5@@ -3,9 +3,11 @@
6 *.bc
7 *.bin
8 *.bz2
9+*.c.[012]*.*
10 *.cis
11 *.cpio
12 *.csp
13+*.dbg
14 *.dsp
15 *.dvi
16 *.elf
17@@ -15,6 +17,7 @@
18 *.gcov
19 *.gen.S
20 *.gif
21+*.gmo
22 *.grep
23 *.grp
24 *.gz
25@@ -51,14 +54,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@@ -72,9 +78,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@@ -83,6 +91,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@@ -95,32 +104,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@@ -128,12 +145,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@@ -148,14 +168,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@@ -165,14 +185,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@@ -188,6 +209,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@@ -197,6 +220,7 @@ perf-archive
165 piggyback
166 piggy.gzip
167 piggy.S
168+pmu-*
169 pnmtologo
170 ppc_defs.h*
171 pss_boot.h
172@@ -206,7 +230,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@@ -216,8 +245,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@@ -227,6 +260,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@@ -238,13 +272,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@@ -252,9 +290,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/kbuild/makefiles.txt b/Documentation/kbuild/makefiles.txt
238index a311db8..415b28c 100644
239--- a/Documentation/kbuild/makefiles.txt
240+++ b/Documentation/kbuild/makefiles.txt
241@@ -23,10 +23,11 @@ This document describes the Linux kernel Makefiles.
242 === 4 Host Program support
243 --- 4.1 Simple Host Program
244 --- 4.2 Composite Host Programs
245- --- 4.3 Using C++ for host programs
246- --- 4.4 Controlling compiler options for host programs
247- --- 4.5 When host programs are actually built
248- --- 4.6 Using hostprogs-$(CONFIG_FOO)
249+ --- 4.3 Defining shared libraries
250+ --- 4.4 Using C++ for host programs
251+ --- 4.5 Controlling compiler options for host programs
252+ --- 4.6 When host programs are actually built
253+ --- 4.7 Using hostprogs-$(CONFIG_FOO)
254
255 === 5 Kbuild clean infrastructure
256
257@@ -642,7 +643,29 @@ Both possibilities are described in the following.
258 Finally, the two .o files are linked to the executable, lxdialog.
259 Note: The syntax <executable>-y is not permitted for host-programs.
260
261---- 4.3 Using C++ for host programs
262+--- 4.3 Defining shared libraries
263+
264+ Objects with extension .so are considered shared libraries, and
265+ will be compiled as position independent objects.
266+ Kbuild provides support for shared libraries, but the usage
267+ shall be restricted.
268+ In the following example the libkconfig.so shared library is used
269+ to link the executable conf.
270+
271+ Example:
272+ #scripts/kconfig/Makefile
273+ hostprogs-y := conf
274+ conf-objs := conf.o libkconfig.so
275+ libkconfig-objs := expr.o type.o
276+
277+ Shared libraries always require a corresponding -objs line, and
278+ in the example above the shared library libkconfig is composed by
279+ the two objects expr.o and type.o.
280+ expr.o and type.o will be built as position independent code and
281+ linked as a shared library libkconfig.so. C++ is not supported for
282+ shared libraries.
283+
284+--- 4.4 Using C++ for host programs
285
286 kbuild offers support for host programs written in C++. This was
287 introduced solely to support kconfig, and is not recommended
288@@ -665,7 +688,7 @@ Both possibilities are described in the following.
289 qconf-cxxobjs := qconf.o
290 qconf-objs := check.o
291
292---- 4.4 Controlling compiler options for host programs
293+--- 4.5 Controlling compiler options for host programs
294
295 When compiling host programs, it is possible to set specific flags.
296 The programs will always be compiled utilising $(HOSTCC) passed
297@@ -693,7 +716,7 @@ Both possibilities are described in the following.
298 When linking qconf, it will be passed the extra option
299 "-L$(QTDIR)/lib".
300
301---- 4.5 When host programs are actually built
302+--- 4.6 When host programs are actually built
303
304 Kbuild will only build host-programs when they are referenced
305 as a prerequisite.
306@@ -724,7 +747,7 @@ Both possibilities are described in the following.
307 This will tell kbuild to build lxdialog even if not referenced in
308 any rule.
309
310---- 4.6 Using hostprogs-$(CONFIG_FOO)
311+--- 4.7 Using hostprogs-$(CONFIG_FOO)
312
313 A typical pattern in a Kbuild file looks like this:
314
315diff --git a/Documentation/kernel-parameters.txt b/Documentation/kernel-parameters.txt
316index 479f332..2475ac2 100644
317--- a/Documentation/kernel-parameters.txt
318+++ b/Documentation/kernel-parameters.txt
319@@ -1182,6 +1182,10 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
320 Format: <unsigned int> such that (rxsize & ~0x1fffc0) == 0.
321 Default: 1024
322
323+ grsec_proc_gid= [GRKERNSEC_PROC_USERGROUP] Chooses GID to
324+ ignore grsecurity's /proc restrictions
325+
326+
327 hashdist= [KNL,NUMA] Large hashes allocated during boot
328 are distributed across NUMA nodes. Defaults on
329 for 64-bit NUMA, off otherwise.
330@@ -2259,6 +2263,10 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
331 noexec=on: enable non-executable mappings (default)
332 noexec=off: disable non-executable mappings
333
334+ nopcid [X86-64]
335+ Disable PCID (Process-Context IDentifier) even if it
336+ is supported by the processor.
337+
338 nosmap [X86]
339 Disable SMAP (Supervisor Mode Access Prevention)
340 even if it is supported by processor.
341@@ -2551,6 +2559,30 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
342 the specified number of seconds. This is to be used if
343 your oopses keep scrolling off the screen.
344
345+ pax_nouderef [X86] disables UDEREF. Most likely needed under certain
346+ virtualization environments that don't cope well with the
347+ expand down segment used by UDEREF on X86-32 or the frequent
348+ page table updates on X86-64.
349+
350+ pax_sanitize_slab=
351+ Format: { 0 | 1 | off | fast | full }
352+ Options '0' and '1' are only provided for backward
353+ compatibility, 'off' or 'fast' should be used instead.
354+ 0|off : disable slab object sanitization
355+ 1|fast: enable slab object sanitization excluding
356+ whitelisted slabs (default)
357+ full : sanitize all slabs, even the whitelisted ones
358+
359+ pax_softmode= 0/1 to disable/enable PaX softmode on boot already.
360+
361+ pax_extra_latent_entropy
362+ Enable a very simple form of latent entropy extraction
363+ from the first 4GB of memory as the bootmem allocator
364+ passes the memory pages to the buddy allocator.
365+
366+ pax_weakuderef [X86-64] enables the weaker but faster form of UDEREF
367+ when the processor supports PCID.
368+
369 pcbit= [HW,ISDN]
370
371 pcd. [PARIDE]
372diff --git a/Makefile b/Makefile
373index 91cfe8d..ccf7329 100644
374--- a/Makefile
375+++ b/Makefile
376@@ -298,7 +298,9 @@ CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
377 HOSTCC = gcc
378 HOSTCXX = g++
379 HOSTCFLAGS = -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer -std=gnu89
380-HOSTCXXFLAGS = -O2
381+HOSTCFLAGS = -Wall -W -Wmissing-prototypes -Wstrict-prototypes -Wno-unused-parameter -Wno-missing-field-initializers -O2 -fomit-frame-pointer -std=gnu89 -fno-delete-null-pointer-checks
382+HOSTCFLAGS += $(call cc-option, -Wno-empty-body)
383+HOSTCXXFLAGS = -O2 -Wall -W -Wno-array-bounds
384
385 ifeq ($(shell $(HOSTCC) -v 2>&1 | grep -c "clang version"), 1)
386 HOSTCFLAGS += -Wno-unused-value -Wno-unused-parameter \
387@@ -445,8 +447,8 @@ export RCS_TAR_IGNORE := --exclude SCCS --exclude BitKeeper --exclude .svn \
388 # Rules shared between *config targets and build targets
389
390 # Basic helpers built in scripts/
391-PHONY += scripts_basic
392-scripts_basic:
393+PHONY += scripts_basic gcc-plugins
394+scripts_basic: gcc-plugins
395 $(Q)$(MAKE) $(build)=scripts/basic
396 $(Q)rm -f .tmp_quiet_recordmcount
397
398@@ -620,6 +622,72 @@ endif
399 # Tell gcc to never replace conditional load with a non-conditional one
400 KBUILD_CFLAGS += $(call cc-option,--param=allow-store-data-races=0)
401
402+ifndef DISABLE_PAX_PLUGINS
403+ifeq ($(call cc-ifversion, -ge, 0408, y), y)
404+PLUGINCC := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(HOSTCXX)" "$(HOSTCXX)" "$(CC)")
405+else
406+PLUGINCC := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(HOSTCC)" "$(HOSTCXX)" "$(CC)")
407+endif
408+ifneq ($(PLUGINCC),)
409+ifdef CONFIG_PAX_CONSTIFY_PLUGIN
410+CONSTIFY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/constify_plugin.so -DCONSTIFY_PLUGIN
411+endif
412+ifdef CONFIG_PAX_MEMORY_STACKLEAK
413+STACKLEAK_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/stackleak_plugin.so -DSTACKLEAK_PLUGIN
414+STACKLEAK_PLUGIN_CFLAGS += -fplugin-arg-stackleak_plugin-track-lowest-sp=100
415+endif
416+ifdef CONFIG_KALLOCSTAT_PLUGIN
417+KALLOCSTAT_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kallocstat_plugin.so
418+endif
419+ifdef CONFIG_PAX_KERNEXEC_PLUGIN
420+KERNEXEC_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kernexec_plugin.so
421+KERNEXEC_PLUGIN_CFLAGS += -fplugin-arg-kernexec_plugin-method=$(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD) -DKERNEXEC_PLUGIN
422+KERNEXEC_PLUGIN_AFLAGS := -DKERNEXEC_PLUGIN
423+endif
424+ifdef CONFIG_GRKERNSEC_RANDSTRUCT
425+RANDSTRUCT_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/randomize_layout_plugin.so -DRANDSTRUCT_PLUGIN
426+ifdef CONFIG_GRKERNSEC_RANDSTRUCT_PERFORMANCE
427+RANDSTRUCT_PLUGIN_CFLAGS += -fplugin-arg-randomize_layout_plugin-performance-mode
428+endif
429+endif
430+ifdef CONFIG_CHECKER_PLUGIN
431+ifeq ($(call cc-ifversion, -ge, 0406, y), y)
432+CHECKER_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/checker_plugin.so -DCHECKER_PLUGIN
433+endif
434+endif
435+COLORIZE_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/colorize_plugin.so
436+ifdef CONFIG_PAX_SIZE_OVERFLOW
437+SIZE_OVERFLOW_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/size_overflow_plugin/size_overflow_plugin.so -DSIZE_OVERFLOW_PLUGIN
438+endif
439+ifdef CONFIG_PAX_LATENT_ENTROPY
440+LATENT_ENTROPY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/latent_entropy_plugin.so -DLATENT_ENTROPY_PLUGIN
441+endif
442+ifdef CONFIG_PAX_MEMORY_STRUCTLEAK
443+STRUCTLEAK_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/structleak_plugin.so -DSTRUCTLEAK_PLUGIN
444+endif
445+GCC_PLUGINS_CFLAGS := $(CONSTIFY_PLUGIN_CFLAGS) $(STACKLEAK_PLUGIN_CFLAGS) $(KALLOCSTAT_PLUGIN_CFLAGS)
446+GCC_PLUGINS_CFLAGS += $(KERNEXEC_PLUGIN_CFLAGS) $(CHECKER_PLUGIN_CFLAGS) $(COLORIZE_PLUGIN_CFLAGS)
447+GCC_PLUGINS_CFLAGS += $(SIZE_OVERFLOW_PLUGIN_CFLAGS) $(LATENT_ENTROPY_PLUGIN_CFLAGS) $(STRUCTLEAK_PLUGIN_CFLAGS)
448+GCC_PLUGINS_CFLAGS += $(RANDSTRUCT_PLUGIN_CFLAGS)
449+GCC_PLUGINS_AFLAGS := $(KERNEXEC_PLUGIN_AFLAGS)
450+export PLUGINCC GCC_PLUGINS_CFLAGS GCC_PLUGINS_AFLAGS CONSTIFY_PLUGIN LATENT_ENTROPY_PLUGIN_CFLAGS
451+ifeq ($(KBUILD_EXTMOD),)
452+gcc-plugins:
453+ $(Q)$(MAKE) $(build)=tools/gcc
454+else
455+gcc-plugins: ;
456+endif
457+else
458+gcc-plugins:
459+ifeq ($(call cc-ifversion, -ge, 0405, y), y)
460+ $(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.))
461+else
462+ $(Q)echo "warning, your gcc version does not support plugins, you should upgrade it to gcc 4.5 at least"
463+endif
464+ $(Q)echo "PAX_MEMORY_STACKLEAK, constification, PAX_LATENT_ENTROPY and other features will be less secure. PAX_SIZE_OVERFLOW will not be active."
465+endif
466+endif
467+
468 ifdef CONFIG_READABLE_ASM
469 # Disable optimizations that make assembler listings hard to read.
470 # reorder blocks reorders the control in the function
471@@ -712,7 +780,7 @@ KBUILD_CFLAGS += $(call cc-option, -gsplit-dwarf, -g)
472 else
473 KBUILD_CFLAGS += -g
474 endif
475-KBUILD_AFLAGS += -Wa,-gdwarf-2
476+KBUILD_AFLAGS += -Wa,--gdwarf-2
477 endif
478 ifdef CONFIG_DEBUG_INFO_DWARF4
479 KBUILD_CFLAGS += $(call cc-option, -gdwarf-4,)
480@@ -877,7 +945,7 @@ export mod_sign_cmd
481
482
483 ifeq ($(KBUILD_EXTMOD),)
484-core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/
485+core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
486
487 vmlinux-dirs := $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \
488 $(core-y) $(core-m) $(drivers-y) $(drivers-m) \
489@@ -924,6 +992,8 @@ endif
490
491 # The actual objects are generated when descending,
492 # make sure no implicit rule kicks in
493+$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
494+$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
495 $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
496
497 # Handle descending into subdirectories listed in $(vmlinux-dirs)
498@@ -933,7 +1003,7 @@ $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
499 # Error messages still appears in the original language
500
501 PHONY += $(vmlinux-dirs)
502-$(vmlinux-dirs): prepare scripts
503+$(vmlinux-dirs): gcc-plugins prepare scripts
504 $(Q)$(MAKE) $(build)=$@
505
506 define filechk_kernel.release
507@@ -976,10 +1046,13 @@ prepare1: prepare2 $(version_h) include/generated/utsrelease.h \
508
509 archprepare: archheaders archscripts prepare1 scripts_basic
510
511+prepare0: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
512+prepare0: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
513 prepare0: archprepare FORCE
514 $(Q)$(MAKE) $(build)=.
515
516 # All the preparing..
517+prepare: KBUILD_CFLAGS := $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS))
518 prepare: prepare0
519
520 # Generate some files
521@@ -1094,6 +1167,8 @@ all: modules
522 # using awk while concatenating to the final file.
523
524 PHONY += modules
525+modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
526+modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
527 modules: $(vmlinux-dirs) $(if $(KBUILD_BUILTIN),vmlinux) modules.builtin
528 $(Q)$(AWK) '!x[$$0]++' $(vmlinux-dirs:%=$(objtree)/%/modules.order) > $(objtree)/modules.order
529 @$(kecho) ' Building modules, stage 2.';
530@@ -1109,7 +1184,7 @@ modules.builtin: $(vmlinux-dirs:%=%/modules.builtin)
531
532 # Target to prepare building external modules
533 PHONY += modules_prepare
534-modules_prepare: prepare scripts
535+modules_prepare: gcc-plugins prepare scripts
536
537 # Target to install modules
538 PHONY += modules_install
539@@ -1175,7 +1250,10 @@ MRPROPER_FILES += .config .config.old .version .old_version $(version_h) \
540 Module.symvers tags TAGS cscope* GPATH GTAGS GRTAGS GSYMS \
541 signing_key.priv signing_key.x509 x509.genkey \
542 extra_certificates signing_key.x509.keyid \
543- signing_key.x509.signer include/linux/version.h
544+ signing_key.x509.signer include/linux/version.h \
545+ tools/gcc/size_overflow_plugin/size_overflow_hash_aux.h \
546+ tools/gcc/size_overflow_plugin/size_overflow_hash.h \
547+ tools/gcc/randomize_layout_seed.h
548
549 # clean - Delete most, but leave enough to build external modules
550 #
551@@ -1214,7 +1292,7 @@ distclean: mrproper
552 @find $(srctree) $(RCS_FIND_IGNORE) \
553 \( -name '*.orig' -o -name '*.rej' -o -name '*~' \
554 -o -name '*.bak' -o -name '#*#' -o -name '.*.orig' \
555- -o -name '.*.rej' -o -name '*%' -o -name 'core' \) \
556+ -o -name '.*.rej' -o -name '*.so' -o -name '*%' -o -name 'core' \) \
557 -type f -print | xargs rm -f
558
559
560@@ -1380,6 +1458,8 @@ PHONY += $(module-dirs) modules
561 $(module-dirs): crmodverdir $(objtree)/Module.symvers
562 $(Q)$(MAKE) $(build)=$(patsubst _module_%,%,$@)
563
564+modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
565+modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
566 modules: $(module-dirs)
567 @$(kecho) ' Building modules, stage 2.';
568 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
569@@ -1520,17 +1600,21 @@ else
570 target-dir = $(if $(KBUILD_EXTMOD),$(dir $<),$(dir $@))
571 endif
572
573-%.s: %.c prepare scripts FORCE
574+%.s: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
575+%.s: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
576+%.s: %.c gcc-plugins prepare scripts FORCE
577 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
578 %.i: %.c prepare scripts FORCE
579 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
580-%.o: %.c prepare scripts FORCE
581+%.o: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
582+%.o: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
583+%.o: %.c gcc-plugins prepare scripts FORCE
584 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
585 %.lst: %.c prepare scripts FORCE
586 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
587-%.s: %.S prepare scripts FORCE
588+%.s: %.S gcc-plugins prepare scripts FORCE
589 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
590-%.o: %.S prepare scripts FORCE
591+%.o: %.S gcc-plugins prepare scripts FORCE
592 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
593 %.symtypes: %.c prepare scripts FORCE
594 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
595@@ -1542,11 +1626,15 @@ endif
596 $(build)=$(build-dir)
597 # Make sure the latest headers are built for Documentation
598 Documentation/: headers_install
599-%/: prepare scripts FORCE
600+%/: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
601+%/: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
602+%/: gcc-plugins prepare scripts FORCE
603 $(cmd_crmodverdir)
604 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
605 $(build)=$(build-dir)
606-%.ko: prepare scripts FORCE
607+%.ko: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
608+%.ko: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
609+%.ko: gcc-plugins prepare scripts FORCE
610 $(cmd_crmodverdir)
611 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
612 $(build)=$(build-dir) $(@:.ko=.o)
613diff --git a/arch/alpha/include/asm/atomic.h b/arch/alpha/include/asm/atomic.h
614index 8f8eafb..3405f46 100644
615--- a/arch/alpha/include/asm/atomic.h
616+++ b/arch/alpha/include/asm/atomic.h
617@@ -239,4 +239,14 @@ static inline long atomic64_dec_if_positive(atomic64_t *v)
618 #define atomic_dec(v) atomic_sub(1,(v))
619 #define atomic64_dec(v) atomic64_sub(1,(v))
620
621+#define atomic64_read_unchecked(v) atomic64_read(v)
622+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
623+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
624+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
625+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
626+#define atomic64_inc_unchecked(v) atomic64_inc(v)
627+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
628+#define atomic64_dec_unchecked(v) atomic64_dec(v)
629+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
630+
631 #endif /* _ALPHA_ATOMIC_H */
632diff --git a/arch/alpha/include/asm/cache.h b/arch/alpha/include/asm/cache.h
633index ad368a9..fbe0f25 100644
634--- a/arch/alpha/include/asm/cache.h
635+++ b/arch/alpha/include/asm/cache.h
636@@ -4,19 +4,19 @@
637 #ifndef __ARCH_ALPHA_CACHE_H
638 #define __ARCH_ALPHA_CACHE_H
639
640+#include <linux/const.h>
641
642 /* Bytes per L1 (data) cache line. */
643 #if defined(CONFIG_ALPHA_GENERIC) || defined(CONFIG_ALPHA_EV6)
644-# define L1_CACHE_BYTES 64
645 # define L1_CACHE_SHIFT 6
646 #else
647 /* Both EV4 and EV5 are write-through, read-allocate,
648 direct-mapped, physical.
649 */
650-# define L1_CACHE_BYTES 32
651 # define L1_CACHE_SHIFT 5
652 #endif
653
654+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
655 #define SMP_CACHE_BYTES L1_CACHE_BYTES
656
657 #endif
658diff --git a/arch/alpha/include/asm/elf.h b/arch/alpha/include/asm/elf.h
659index 968d999..d36b2df 100644
660--- a/arch/alpha/include/asm/elf.h
661+++ b/arch/alpha/include/asm/elf.h
662@@ -91,6 +91,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
663
664 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x1000000)
665
666+#ifdef CONFIG_PAX_ASLR
667+#define PAX_ELF_ET_DYN_BASE (current->personality & ADDR_LIMIT_32BIT ? 0x10000 : 0x120000000UL)
668+
669+#define PAX_DELTA_MMAP_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 28)
670+#define PAX_DELTA_STACK_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 19)
671+#endif
672+
673 /* $0 is set by ld.so to a pointer to a function which might be
674 registered using atexit. This provides a mean for the dynamic
675 linker to call DT_FINI functions for shared libraries that have
676diff --git a/arch/alpha/include/asm/pgalloc.h b/arch/alpha/include/asm/pgalloc.h
677index aab14a0..b4fa3e7 100644
678--- a/arch/alpha/include/asm/pgalloc.h
679+++ b/arch/alpha/include/asm/pgalloc.h
680@@ -29,6 +29,12 @@ pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
681 pgd_set(pgd, pmd);
682 }
683
684+static inline void
685+pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
686+{
687+ pgd_populate(mm, pgd, pmd);
688+}
689+
690 extern pgd_t *pgd_alloc(struct mm_struct *mm);
691
692 static inline void
693diff --git a/arch/alpha/include/asm/pgtable.h b/arch/alpha/include/asm/pgtable.h
694index d8f9b7e..f6222fa 100644
695--- a/arch/alpha/include/asm/pgtable.h
696+++ b/arch/alpha/include/asm/pgtable.h
697@@ -102,6 +102,17 @@ struct vm_area_struct;
698 #define PAGE_SHARED __pgprot(_PAGE_VALID | __ACCESS_BITS)
699 #define PAGE_COPY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
700 #define PAGE_READONLY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
701+
702+#ifdef CONFIG_PAX_PAGEEXEC
703+# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOE)
704+# define PAGE_COPY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
705+# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
706+#else
707+# define PAGE_SHARED_NOEXEC PAGE_SHARED
708+# define PAGE_COPY_NOEXEC PAGE_COPY
709+# define PAGE_READONLY_NOEXEC PAGE_READONLY
710+#endif
711+
712 #define PAGE_KERNEL __pgprot(_PAGE_VALID | _PAGE_ASM | _PAGE_KRE | _PAGE_KWE)
713
714 #define _PAGE_NORMAL(x) __pgprot(_PAGE_VALID | __ACCESS_BITS | (x))
715diff --git a/arch/alpha/kernel/module.c b/arch/alpha/kernel/module.c
716index 2fd00b7..cfd5069 100644
717--- a/arch/alpha/kernel/module.c
718+++ b/arch/alpha/kernel/module.c
719@@ -160,7 +160,7 @@ apply_relocate_add(Elf64_Shdr *sechdrs, const char *strtab,
720
721 /* The small sections were sorted to the end of the segment.
722 The following should definitely cover them. */
723- gp = (u64)me->module_core + me->core_size - 0x8000;
724+ gp = (u64)me->module_core_rw + me->core_size_rw - 0x8000;
725 got = sechdrs[me->arch.gotsecindex].sh_addr;
726
727 for (i = 0; i < n; i++) {
728diff --git a/arch/alpha/kernel/osf_sys.c b/arch/alpha/kernel/osf_sys.c
729index f9c732e..78fbb0f 100644
730--- a/arch/alpha/kernel/osf_sys.c
731+++ b/arch/alpha/kernel/osf_sys.c
732@@ -1295,10 +1295,11 @@ SYSCALL_DEFINE1(old_adjtimex, struct timex32 __user *, txc_p)
733 generic version except that we know how to honor ADDR_LIMIT_32BIT. */
734
735 static unsigned long
736-arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
737- unsigned long limit)
738+arch_get_unmapped_area_1(struct file *filp, unsigned long addr, unsigned long len,
739+ unsigned long limit, unsigned long flags)
740 {
741 struct vm_unmapped_area_info info;
742+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
743
744 info.flags = 0;
745 info.length = len;
746@@ -1306,6 +1307,7 @@ arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
747 info.high_limit = limit;
748 info.align_mask = 0;
749 info.align_offset = 0;
750+ info.threadstack_offset = offset;
751 return vm_unmapped_area(&info);
752 }
753
754@@ -1338,20 +1340,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
755 merely specific addresses, but regions of memory -- perhaps
756 this feature should be incorporated into all ports? */
757
758+#ifdef CONFIG_PAX_RANDMMAP
759+ if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
760+#endif
761+
762 if (addr) {
763- addr = arch_get_unmapped_area_1 (PAGE_ALIGN(addr), len, limit);
764+ addr = arch_get_unmapped_area_1 (filp, PAGE_ALIGN(addr), len, limit, flags);
765 if (addr != (unsigned long) -ENOMEM)
766 return addr;
767 }
768
769 /* Next, try allocating at TASK_UNMAPPED_BASE. */
770- addr = arch_get_unmapped_area_1 (PAGE_ALIGN(TASK_UNMAPPED_BASE),
771- len, limit);
772+ addr = arch_get_unmapped_area_1 (filp, PAGE_ALIGN(current->mm->mmap_base), len, limit, flags);
773+
774 if (addr != (unsigned long) -ENOMEM)
775 return addr;
776
777 /* Finally, try allocating in low memory. */
778- addr = arch_get_unmapped_area_1 (PAGE_SIZE, len, limit);
779+ addr = arch_get_unmapped_area_1 (filp, PAGE_SIZE, len, limit, flags);
780
781 return addr;
782 }
783diff --git a/arch/alpha/mm/fault.c b/arch/alpha/mm/fault.c
784index 98838a0..b304fb4 100644
785--- a/arch/alpha/mm/fault.c
786+++ b/arch/alpha/mm/fault.c
787@@ -53,6 +53,124 @@ __load_new_mm_context(struct mm_struct *next_mm)
788 __reload_thread(pcb);
789 }
790
791+#ifdef CONFIG_PAX_PAGEEXEC
792+/*
793+ * PaX: decide what to do with offenders (regs->pc = fault address)
794+ *
795+ * returns 1 when task should be killed
796+ * 2 when patched PLT trampoline was detected
797+ * 3 when unpatched PLT trampoline was detected
798+ */
799+static int pax_handle_fetch_fault(struct pt_regs *regs)
800+{
801+
802+#ifdef CONFIG_PAX_EMUPLT
803+ int err;
804+
805+ do { /* PaX: patched PLT emulation #1 */
806+ unsigned int ldah, ldq, jmp;
807+
808+ err = get_user(ldah, (unsigned int *)regs->pc);
809+ err |= get_user(ldq, (unsigned int *)(regs->pc+4));
810+ err |= get_user(jmp, (unsigned int *)(regs->pc+8));
811+
812+ if (err)
813+ break;
814+
815+ if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
816+ (ldq & 0xFFFF0000U) == 0xA77B0000U &&
817+ jmp == 0x6BFB0000U)
818+ {
819+ unsigned long r27, addr;
820+ unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
821+ unsigned long addrl = ldq | 0xFFFFFFFFFFFF0000UL;
822+
823+ addr = regs->r27 + ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
824+ err = get_user(r27, (unsigned long *)addr);
825+ if (err)
826+ break;
827+
828+ regs->r27 = r27;
829+ regs->pc = r27;
830+ return 2;
831+ }
832+ } while (0);
833+
834+ do { /* PaX: patched PLT emulation #2 */
835+ unsigned int ldah, lda, br;
836+
837+ err = get_user(ldah, (unsigned int *)regs->pc);
838+ err |= get_user(lda, (unsigned int *)(regs->pc+4));
839+ err |= get_user(br, (unsigned int *)(regs->pc+8));
840+
841+ if (err)
842+ break;
843+
844+ if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
845+ (lda & 0xFFFF0000U) == 0xA77B0000U &&
846+ (br & 0xFFE00000U) == 0xC3E00000U)
847+ {
848+ unsigned long addr = br | 0xFFFFFFFFFFE00000UL;
849+ unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
850+ unsigned long addrl = lda | 0xFFFFFFFFFFFF0000UL;
851+
852+ regs->r27 += ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
853+ regs->pc += 12 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
854+ return 2;
855+ }
856+ } while (0);
857+
858+ do { /* PaX: unpatched PLT emulation */
859+ unsigned int br;
860+
861+ err = get_user(br, (unsigned int *)regs->pc);
862+
863+ if (!err && (br & 0xFFE00000U) == 0xC3800000U) {
864+ unsigned int br2, ldq, nop, jmp;
865+ unsigned long addr = br | 0xFFFFFFFFFFE00000UL, resolver;
866+
867+ addr = regs->pc + 4 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
868+ err = get_user(br2, (unsigned int *)addr);
869+ err |= get_user(ldq, (unsigned int *)(addr+4));
870+ err |= get_user(nop, (unsigned int *)(addr+8));
871+ err |= get_user(jmp, (unsigned int *)(addr+12));
872+ err |= get_user(resolver, (unsigned long *)(addr+16));
873+
874+ if (err)
875+ break;
876+
877+ if (br2 == 0xC3600000U &&
878+ ldq == 0xA77B000CU &&
879+ nop == 0x47FF041FU &&
880+ jmp == 0x6B7B0000U)
881+ {
882+ regs->r28 = regs->pc+4;
883+ regs->r27 = addr+16;
884+ regs->pc = resolver;
885+ return 3;
886+ }
887+ }
888+ } while (0);
889+#endif
890+
891+ return 1;
892+}
893+
894+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
895+{
896+ unsigned long i;
897+
898+ printk(KERN_ERR "PAX: bytes at PC: ");
899+ for (i = 0; i < 5; i++) {
900+ unsigned int c;
901+ if (get_user(c, (unsigned int *)pc+i))
902+ printk(KERN_CONT "???????? ");
903+ else
904+ printk(KERN_CONT "%08x ", c);
905+ }
906+ printk("\n");
907+}
908+#endif
909
910 /*
911 * This routine handles page faults. It determines the address,
912@@ -133,8 +251,29 @@ retry:
913 good_area:
914 si_code = SEGV_ACCERR;
915 if (cause < 0) {
916- if (!(vma->vm_flags & VM_EXEC))
917+ if (!(vma->vm_flags & VM_EXEC)) {
918+
919+#ifdef CONFIG_PAX_PAGEEXEC
920+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->pc)
921+ goto bad_area;
922+
923+ up_read(&mm->mmap_sem);
924+ switch (pax_handle_fetch_fault(regs)) {
925+
926+#ifdef CONFIG_PAX_EMUPLT
927+ case 2:
928+ case 3:
929+ return;
930+#endif
931+
932+ }
933+ pax_report_fault(regs, (void *)regs->pc, (void *)rdusp());
934+ do_group_exit(SIGKILL);
935+#else
936 goto bad_area;
937+#endif
938+
939+ }
940 } else if (!cause) {
941 /* Allow reads even for write-only mappings */
942 if (!(vma->vm_flags & (VM_READ | VM_WRITE)))
943diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
944index 89c4b5c..847a7be 100644
945--- a/arch/arm/Kconfig
946+++ b/arch/arm/Kconfig
947@@ -1740,7 +1740,7 @@ config ALIGNMENT_TRAP
948
949 config UACCESS_WITH_MEMCPY
950 bool "Use kernel mem{cpy,set}() for {copy_to,clear}_user()"
951- depends on MMU
952+ depends on MMU && !PAX_MEMORY_UDEREF
953 default y if CPU_FEROCEON
954 help
955 Implement faster copy_to_user and clear_user methods for CPU
956@@ -2004,6 +2004,7 @@ config XIP_PHYS_ADDR
957 config KEXEC
958 bool "Kexec system call (EXPERIMENTAL)"
959 depends on (!SMP || PM_SLEEP_SMP)
960+ depends on !GRKERNSEC_KMEM
961 help
962 kexec is a system call that implements the ability to shutdown your
963 current kernel, and to start another kernel. It is like a reboot
964diff --git a/arch/arm/include/asm/atomic.h b/arch/arm/include/asm/atomic.h
965index e22c119..eaa807d 100644
966--- a/arch/arm/include/asm/atomic.h
967+++ b/arch/arm/include/asm/atomic.h
968@@ -18,17 +18,41 @@
969 #include <asm/barrier.h>
970 #include <asm/cmpxchg.h>
971
972+#ifdef CONFIG_GENERIC_ATOMIC64
973+#include <asm-generic/atomic64.h>
974+#endif
975+
976 #define ATOMIC_INIT(i) { (i) }
977
978 #ifdef __KERNEL__
979
980+#ifdef CONFIG_THUMB2_KERNEL
981+#define REFCOUNT_TRAP_INSN "bkpt 0xf1"
982+#else
983+#define REFCOUNT_TRAP_INSN "bkpt 0xf103"
984+#endif
985+
986+#define _ASM_EXTABLE(from, to) \
987+" .pushsection __ex_table,\"a\"\n"\
988+" .align 3\n" \
989+" .long " #from ", " #to"\n" \
990+" .popsection"
991+
992 /*
993 * On ARM, ordinary assignment (str instruction) doesn't clear the local
994 * strex/ldrex monitor on some implementations. The reason we can use it for
995 * atomic_set() is the clrex or dummy strex done on every exception return.
996 */
997 #define atomic_read(v) ACCESS_ONCE((v)->counter)
998+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
999+{
1000+ return ACCESS_ONCE(v->counter);
1001+}
1002 #define atomic_set(v,i) (((v)->counter) = (i))
1003+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
1004+{
1005+ v->counter = i;
1006+}
1007
1008 #if __LINUX_ARM_ARCH__ >= 6
1009
1010@@ -38,26 +62,50 @@
1011 * to ensure that the update happens.
1012 */
1013
1014-#define ATOMIC_OP(op, c_op, asm_op) \
1015-static inline void atomic_##op(int i, atomic_t *v) \
1016+#ifdef CONFIG_PAX_REFCOUNT
1017+#define __OVERFLOW_POST \
1018+ " bvc 3f\n" \
1019+ "2: " REFCOUNT_TRAP_INSN "\n"\
1020+ "3:\n"
1021+#define __OVERFLOW_POST_RETURN \
1022+ " bvc 3f\n" \
1023+" mov %0, %1\n" \
1024+ "2: " REFCOUNT_TRAP_INSN "\n"\
1025+ "3:\n"
1026+#define __OVERFLOW_EXTABLE \
1027+ "4:\n" \
1028+ _ASM_EXTABLE(2b, 4b)
1029+#else
1030+#define __OVERFLOW_POST
1031+#define __OVERFLOW_POST_RETURN
1032+#define __OVERFLOW_EXTABLE
1033+#endif
1034+
1035+#define __ATOMIC_OP(op, suffix, c_op, asm_op, post_op, extable) \
1036+static inline void atomic_##op##suffix(int i, atomic##suffix##_t *v) \
1037 { \
1038 unsigned long tmp; \
1039 int result; \
1040 \
1041 prefetchw(&v->counter); \
1042- __asm__ __volatile__("@ atomic_" #op "\n" \
1043+ __asm__ __volatile__("@ atomic_" #op #suffix "\n" \
1044 "1: ldrex %0, [%3]\n" \
1045 " " #asm_op " %0, %0, %4\n" \
1046+ post_op \
1047 " strex %1, %0, [%3]\n" \
1048 " teq %1, #0\n" \
1049-" bne 1b" \
1050+" bne 1b\n" \
1051+ extable \
1052 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter) \
1053 : "r" (&v->counter), "Ir" (i) \
1054 : "cc"); \
1055 } \
1056
1057-#define ATOMIC_OP_RETURN(op, c_op, asm_op) \
1058-static inline int atomic_##op##_return(int i, atomic_t *v) \
1059+#define ATOMIC_OP(op, c_op, asm_op) __ATOMIC_OP(op, , c_op, asm_op, , )\
1060+ __ATOMIC_OP(op, _unchecked, c_op, asm_op##s, __OVERFLOW_POST, __OVERFLOW_EXTABLE)
1061+
1062+#define __ATOMIC_OP_RETURN(op, suffix, c_op, asm_op, post_op, extable) \
1063+static inline int atomic_##op##_return##suffix(int i, atomic##suffix##_t *v)\
1064 { \
1065 unsigned long tmp; \
1066 int result; \
1067@@ -65,12 +113,14 @@ static inline int atomic_##op##_return(int i, atomic_t *v) \
1068 smp_mb(); \
1069 prefetchw(&v->counter); \
1070 \
1071- __asm__ __volatile__("@ atomic_" #op "_return\n" \
1072+ __asm__ __volatile__("@ atomic_" #op "_return" #suffix "\n" \
1073 "1: ldrex %0, [%3]\n" \
1074 " " #asm_op " %0, %0, %4\n" \
1075+ post_op \
1076 " strex %1, %0, [%3]\n" \
1077 " teq %1, #0\n" \
1078-" bne 1b" \
1079+" bne 1b\n" \
1080+ extable \
1081 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter) \
1082 : "r" (&v->counter), "Ir" (i) \
1083 : "cc"); \
1084@@ -80,6 +130,9 @@ static inline int atomic_##op##_return(int i, atomic_t *v) \
1085 return result; \
1086 }
1087
1088+#define ATOMIC_OP_RETURN(op, c_op, asm_op) __ATOMIC_OP_RETURN(op, , c_op, asm_op, , )\
1089+ __ATOMIC_OP_RETURN(op, _unchecked, c_op, asm_op##s, __OVERFLOW_POST_RETURN, __OVERFLOW_EXTABLE)
1090+
1091 static inline int atomic_cmpxchg(atomic_t *ptr, int old, int new)
1092 {
1093 int oldval;
1094@@ -115,12 +168,24 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1095 __asm__ __volatile__ ("@ atomic_add_unless\n"
1096 "1: ldrex %0, [%4]\n"
1097 " teq %0, %5\n"
1098-" beq 2f\n"
1099-" add %1, %0, %6\n"
1100+" beq 4f\n"
1101+" adds %1, %0, %6\n"
1102+
1103+#ifdef CONFIG_PAX_REFCOUNT
1104+" bvc 3f\n"
1105+"2: " REFCOUNT_TRAP_INSN "\n"
1106+"3:\n"
1107+#endif
1108+
1109 " strex %2, %1, [%4]\n"
1110 " teq %2, #0\n"
1111 " bne 1b\n"
1112-"2:"
1113+"4:"
1114+
1115+#ifdef CONFIG_PAX_REFCOUNT
1116+ _ASM_EXTABLE(2b, 4b)
1117+#endif
1118+
1119 : "=&r" (oldval), "=&r" (newval), "=&r" (tmp), "+Qo" (v->counter)
1120 : "r" (&v->counter), "r" (u), "r" (a)
1121 : "cc");
1122@@ -131,14 +196,36 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1123 return oldval;
1124 }
1125
1126+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *ptr, int old, int new)
1127+{
1128+ unsigned long oldval, res;
1129+
1130+ smp_mb();
1131+
1132+ do {
1133+ __asm__ __volatile__("@ atomic_cmpxchg_unchecked\n"
1134+ "ldrex %1, [%3]\n"
1135+ "mov %0, #0\n"
1136+ "teq %1, %4\n"
1137+ "strexeq %0, %5, [%3]\n"
1138+ : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1139+ : "r" (&ptr->counter), "Ir" (old), "r" (new)
1140+ : "cc");
1141+ } while (res);
1142+
1143+ smp_mb();
1144+
1145+ return oldval;
1146+}
1147+
1148 #else /* ARM_ARCH_6 */
1149
1150 #ifdef CONFIG_SMP
1151 #error SMP not supported on pre-ARMv6 CPUs
1152 #endif
1153
1154-#define ATOMIC_OP(op, c_op, asm_op) \
1155-static inline void atomic_##op(int i, atomic_t *v) \
1156+#define __ATOMIC_OP(op, suffix, c_op, asm_op) \
1157+static inline void atomic_##op##suffix(int i, atomic##suffix##_t *v) \
1158 { \
1159 unsigned long flags; \
1160 \
1161@@ -147,8 +234,11 @@ static inline void atomic_##op(int i, atomic_t *v) \
1162 raw_local_irq_restore(flags); \
1163 } \
1164
1165-#define ATOMIC_OP_RETURN(op, c_op, asm_op) \
1166-static inline int atomic_##op##_return(int i, atomic_t *v) \
1167+#define ATOMIC_OP(op, c_op, asm_op) __ATOMIC_OP(op, , c_op, asm_op) \
1168+ __ATOMIC_OP(op, _unchecked, c_op, asm_op)
1169+
1170+#define __ATOMIC_OP_RETURN(op, suffix, c_op, asm_op) \
1171+static inline int atomic_##op##_return##suffix(int i, atomic##suffix##_t *v)\
1172 { \
1173 unsigned long flags; \
1174 int val; \
1175@@ -161,6 +251,9 @@ static inline int atomic_##op##_return(int i, atomic_t *v) \
1176 return val; \
1177 }
1178
1179+#define ATOMIC_OP_RETURN(op, c_op, asm_op) __ATOMIC_OP_RETURN(op, , c_op, asm_op)\
1180+ __ATOMIC_OP_RETURN(op, _unchecked, c_op, asm_op)
1181+
1182 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1183 {
1184 int ret;
1185@@ -175,6 +268,11 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1186 return ret;
1187 }
1188
1189+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
1190+{
1191+ return atomic_cmpxchg((atomic_t *)v, old, new);
1192+}
1193+
1194 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1195 {
1196 int c, old;
1197@@ -196,16 +294,38 @@ ATOMIC_OPS(sub, -=, sub)
1198
1199 #undef ATOMIC_OPS
1200 #undef ATOMIC_OP_RETURN
1201+#undef __ATOMIC_OP_RETURN
1202 #undef ATOMIC_OP
1203+#undef __ATOMIC_OP
1204
1205 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
1206+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
1207+{
1208+ return xchg(&v->counter, new);
1209+}
1210
1211 #define atomic_inc(v) atomic_add(1, v)
1212+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
1213+{
1214+ atomic_add_unchecked(1, v);
1215+}
1216 #define atomic_dec(v) atomic_sub(1, v)
1217+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
1218+{
1219+ atomic_sub_unchecked(1, v);
1220+}
1221
1222 #define atomic_inc_and_test(v) (atomic_add_return(1, v) == 0)
1223+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
1224+{
1225+ return atomic_add_return_unchecked(1, v) == 0;
1226+}
1227 #define atomic_dec_and_test(v) (atomic_sub_return(1, v) == 0)
1228 #define atomic_inc_return(v) (atomic_add_return(1, v))
1229+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
1230+{
1231+ return atomic_add_return_unchecked(1, v);
1232+}
1233 #define atomic_dec_return(v) (atomic_sub_return(1, v))
1234 #define atomic_sub_and_test(i, v) (atomic_sub_return(i, v) == 0)
1235
1236@@ -216,6 +336,14 @@ typedef struct {
1237 long long counter;
1238 } atomic64_t;
1239
1240+#ifdef CONFIG_PAX_REFCOUNT
1241+typedef struct {
1242+ long long counter;
1243+} atomic64_unchecked_t;
1244+#else
1245+typedef atomic64_t atomic64_unchecked_t;
1246+#endif
1247+
1248 #define ATOMIC64_INIT(i) { (i) }
1249
1250 #ifdef CONFIG_ARM_LPAE
1251@@ -232,6 +360,19 @@ static inline long long atomic64_read(const atomic64_t *v)
1252 return result;
1253 }
1254
1255+static inline long long atomic64_read_unchecked(const atomic64_unchecked_t *v)
1256+{
1257+ long long result;
1258+
1259+ __asm__ __volatile__("@ atomic64_read_unchecked\n"
1260+" ldrd %0, %H0, [%1]"
1261+ : "=&r" (result)
1262+ : "r" (&v->counter), "Qo" (v->counter)
1263+ );
1264+
1265+ return result;
1266+}
1267+
1268 static inline void atomic64_set(atomic64_t *v, long long i)
1269 {
1270 __asm__ __volatile__("@ atomic64_set\n"
1271@@ -240,6 +381,15 @@ static inline void atomic64_set(atomic64_t *v, long long i)
1272 : "r" (&v->counter), "r" (i)
1273 );
1274 }
1275+
1276+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
1277+{
1278+ __asm__ __volatile__("@ atomic64_set_unchecked\n"
1279+" strd %2, %H2, [%1]"
1280+ : "=Qo" (v->counter)
1281+ : "r" (&v->counter), "r" (i)
1282+ );
1283+}
1284 #else
1285 static inline long long atomic64_read(const atomic64_t *v)
1286 {
1287@@ -254,6 +404,19 @@ static inline long long atomic64_read(const atomic64_t *v)
1288 return result;
1289 }
1290
1291+static inline long long atomic64_read_unchecked(const atomic64_unchecked_t *v)
1292+{
1293+ long long result;
1294+
1295+ __asm__ __volatile__("@ atomic64_read_unchecked\n"
1296+" ldrexd %0, %H0, [%1]"
1297+ : "=&r" (result)
1298+ : "r" (&v->counter), "Qo" (v->counter)
1299+ );
1300+
1301+ return result;
1302+}
1303+
1304 static inline void atomic64_set(atomic64_t *v, long long i)
1305 {
1306 long long tmp;
1307@@ -268,29 +431,57 @@ static inline void atomic64_set(atomic64_t *v, long long i)
1308 : "r" (&v->counter), "r" (i)
1309 : "cc");
1310 }
1311+
1312+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
1313+{
1314+ long long tmp;
1315+
1316+ prefetchw(&v->counter);
1317+ __asm__ __volatile__("@ atomic64_set_unchecked\n"
1318+"1: ldrexd %0, %H0, [%2]\n"
1319+" strexd %0, %3, %H3, [%2]\n"
1320+" teq %0, #0\n"
1321+" bne 1b"
1322+ : "=&r" (tmp), "=Qo" (v->counter)
1323+ : "r" (&v->counter), "r" (i)
1324+ : "cc");
1325+}
1326 #endif
1327
1328-#define ATOMIC64_OP(op, op1, op2) \
1329-static inline void atomic64_##op(long long i, atomic64_t *v) \
1330+#undef __OVERFLOW_POST_RETURN
1331+#define __OVERFLOW_POST_RETURN \
1332+ " bvc 3f\n" \
1333+" mov %0, %1\n" \
1334+" mov %H0, %H1\n" \
1335+ "2: " REFCOUNT_TRAP_INSN "\n"\
1336+ "3:\n"
1337+
1338+#define __ATOMIC64_OP(op, suffix, op1, op2, post_op, extable) \
1339+static inline void atomic64_##op##suffix(long long i, atomic64##suffix##_t *v)\
1340 { \
1341 long long result; \
1342 unsigned long tmp; \
1343 \
1344 prefetchw(&v->counter); \
1345- __asm__ __volatile__("@ atomic64_" #op "\n" \
1346+ __asm__ __volatile__("@ atomic64_" #op #suffix "\n" \
1347 "1: ldrexd %0, %H0, [%3]\n" \
1348 " " #op1 " %Q0, %Q0, %Q4\n" \
1349 " " #op2 " %R0, %R0, %R4\n" \
1350+ post_op \
1351 " strexd %1, %0, %H0, [%3]\n" \
1352 " teq %1, #0\n" \
1353-" bne 1b" \
1354+" bne 1b\n" \
1355+ extable \
1356 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter) \
1357 : "r" (&v->counter), "r" (i) \
1358 : "cc"); \
1359 } \
1360
1361-#define ATOMIC64_OP_RETURN(op, op1, op2) \
1362-static inline long long atomic64_##op##_return(long long i, atomic64_t *v) \
1363+#define ATOMIC64_OP(op, op1, op2) __ATOMIC64_OP(op, , op1, op2, , ) \
1364+ __ATOMIC64_OP(op, _unchecked, op1, op2##s, __OVERFLOW_POST, __OVERFLOW_EXTABLE)
1365+
1366+#define __ATOMIC64_OP_RETURN(op, suffix, op1, op2, post_op, extable) \
1367+static inline long long atomic64_##op##_return##suffix(long long i, atomic64##suffix##_t *v) \
1368 { \
1369 long long result; \
1370 unsigned long tmp; \
1371@@ -298,13 +489,15 @@ static inline long long atomic64_##op##_return(long long i, atomic64_t *v) \
1372 smp_mb(); \
1373 prefetchw(&v->counter); \
1374 \
1375- __asm__ __volatile__("@ atomic64_" #op "_return\n" \
1376+ __asm__ __volatile__("@ atomic64_" #op "_return" #suffix "\n" \
1377 "1: ldrexd %0, %H0, [%3]\n" \
1378 " " #op1 " %Q0, %Q0, %Q4\n" \
1379 " " #op2 " %R0, %R0, %R4\n" \
1380+ post_op \
1381 " strexd %1, %0, %H0, [%3]\n" \
1382 " teq %1, #0\n" \
1383-" bne 1b" \
1384+" bne 1b\n" \
1385+ extable \
1386 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter) \
1387 : "r" (&v->counter), "r" (i) \
1388 : "cc"); \
1389@@ -314,6 +507,9 @@ static inline long long atomic64_##op##_return(long long i, atomic64_t *v) \
1390 return result; \
1391 }
1392
1393+#define ATOMIC64_OP_RETURN(op, op1, op2) __ATOMIC64_OP_RETURN(op, , op1, op2, , ) \
1394+ __ATOMIC64_OP_RETURN(op, _unchecked, op1, op2##s, __OVERFLOW_POST_RETURN, __OVERFLOW_EXTABLE)
1395+
1396 #define ATOMIC64_OPS(op, op1, op2) \
1397 ATOMIC64_OP(op, op1, op2) \
1398 ATOMIC64_OP_RETURN(op, op1, op2)
1399@@ -323,7 +519,12 @@ ATOMIC64_OPS(sub, subs, sbc)
1400
1401 #undef ATOMIC64_OPS
1402 #undef ATOMIC64_OP_RETURN
1403+#undef __ATOMIC64_OP_RETURN
1404 #undef ATOMIC64_OP
1405+#undef __ATOMIC64_OP
1406+#undef __OVERFLOW_EXTABLE
1407+#undef __OVERFLOW_POST_RETURN
1408+#undef __OVERFLOW_POST
1409
1410 static inline long long atomic64_cmpxchg(atomic64_t *ptr, long long old,
1411 long long new)
1412@@ -351,6 +552,31 @@ static inline long long atomic64_cmpxchg(atomic64_t *ptr, long long old,
1413 return oldval;
1414 }
1415
1416+static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *ptr, long long old,
1417+ long long new)
1418+{
1419+ long long oldval;
1420+ unsigned long res;
1421+
1422+ smp_mb();
1423+
1424+ do {
1425+ __asm__ __volatile__("@ atomic64_cmpxchg_unchecked\n"
1426+ "ldrexd %1, %H1, [%3]\n"
1427+ "mov %0, #0\n"
1428+ "teq %1, %4\n"
1429+ "teqeq %H1, %H4\n"
1430+ "strexdeq %0, %5, %H5, [%3]"
1431+ : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1432+ : "r" (&ptr->counter), "r" (old), "r" (new)
1433+ : "cc");
1434+ } while (res);
1435+
1436+ smp_mb();
1437+
1438+ return oldval;
1439+}
1440+
1441 static inline long long atomic64_xchg(atomic64_t *ptr, long long new)
1442 {
1443 long long result;
1444@@ -376,21 +602,35 @@ static inline long long atomic64_xchg(atomic64_t *ptr, long long new)
1445 static inline long long atomic64_dec_if_positive(atomic64_t *v)
1446 {
1447 long long result;
1448- unsigned long tmp;
1449+ u64 tmp;
1450
1451 smp_mb();
1452 prefetchw(&v->counter);
1453
1454 __asm__ __volatile__("@ atomic64_dec_if_positive\n"
1455-"1: ldrexd %0, %H0, [%3]\n"
1456-" subs %Q0, %Q0, #1\n"
1457-" sbc %R0, %R0, #0\n"
1458+"1: ldrexd %1, %H1, [%3]\n"
1459+" subs %Q0, %Q1, #1\n"
1460+" sbcs %R0, %R1, #0\n"
1461+
1462+#ifdef CONFIG_PAX_REFCOUNT
1463+" bvc 3f\n"
1464+" mov %Q0, %Q1\n"
1465+" mov %R0, %R1\n"
1466+"2: " REFCOUNT_TRAP_INSN "\n"
1467+"3:\n"
1468+#endif
1469+
1470 " teq %R0, #0\n"
1471-" bmi 2f\n"
1472+" bmi 4f\n"
1473 " strexd %1, %0, %H0, [%3]\n"
1474 " teq %1, #0\n"
1475 " bne 1b\n"
1476-"2:"
1477+"4:\n"
1478+
1479+#ifdef CONFIG_PAX_REFCOUNT
1480+ _ASM_EXTABLE(2b, 4b)
1481+#endif
1482+
1483 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1484 : "r" (&v->counter)
1485 : "cc");
1486@@ -414,13 +654,25 @@ static inline int atomic64_add_unless(atomic64_t *v, long long a, long long u)
1487 " teq %0, %5\n"
1488 " teqeq %H0, %H5\n"
1489 " moveq %1, #0\n"
1490-" beq 2f\n"
1491+" beq 4f\n"
1492 " adds %Q0, %Q0, %Q6\n"
1493-" adc %R0, %R0, %R6\n"
1494+" adcs %R0, %R0, %R6\n"
1495+
1496+#ifdef CONFIG_PAX_REFCOUNT
1497+" bvc 3f\n"
1498+"2: " REFCOUNT_TRAP_INSN "\n"
1499+"3:\n"
1500+#endif
1501+
1502 " strexd %2, %0, %H0, [%4]\n"
1503 " teq %2, #0\n"
1504 " bne 1b\n"
1505-"2:"
1506+"4:\n"
1507+
1508+#ifdef CONFIG_PAX_REFCOUNT
1509+ _ASM_EXTABLE(2b, 4b)
1510+#endif
1511+
1512 : "=&r" (val), "+r" (ret), "=&r" (tmp), "+Qo" (v->counter)
1513 : "r" (&v->counter), "r" (u), "r" (a)
1514 : "cc");
1515@@ -433,10 +685,13 @@ static inline int atomic64_add_unless(atomic64_t *v, long long a, long long u)
1516
1517 #define atomic64_add_negative(a, v) (atomic64_add_return((a), (v)) < 0)
1518 #define atomic64_inc(v) atomic64_add(1LL, (v))
1519+#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1LL, (v))
1520 #define atomic64_inc_return(v) atomic64_add_return(1LL, (v))
1521+#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1LL, (v))
1522 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
1523 #define atomic64_sub_and_test(a, v) (atomic64_sub_return((a), (v)) == 0)
1524 #define atomic64_dec(v) atomic64_sub(1LL, (v))
1525+#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1LL, (v))
1526 #define atomic64_dec_return(v) atomic64_sub_return(1LL, (v))
1527 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
1528 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
1529diff --git a/arch/arm/include/asm/barrier.h b/arch/arm/include/asm/barrier.h
1530index c6a3e73..35cca85 100644
1531--- a/arch/arm/include/asm/barrier.h
1532+++ b/arch/arm/include/asm/barrier.h
1533@@ -63,7 +63,7 @@
1534 do { \
1535 compiletime_assert_atomic_type(*p); \
1536 smp_mb(); \
1537- ACCESS_ONCE(*p) = (v); \
1538+ ACCESS_ONCE_RW(*p) = (v); \
1539 } while (0)
1540
1541 #define smp_load_acquire(p) \
1542diff --git a/arch/arm/include/asm/cache.h b/arch/arm/include/asm/cache.h
1543index 75fe66b..ba3dee4 100644
1544--- a/arch/arm/include/asm/cache.h
1545+++ b/arch/arm/include/asm/cache.h
1546@@ -4,8 +4,10 @@
1547 #ifndef __ASMARM_CACHE_H
1548 #define __ASMARM_CACHE_H
1549
1550+#include <linux/const.h>
1551+
1552 #define L1_CACHE_SHIFT CONFIG_ARM_L1_CACHE_SHIFT
1553-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
1554+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
1555
1556 /*
1557 * Memory returned by kmalloc() may be used for DMA, so we must make
1558@@ -24,5 +26,6 @@
1559 #endif
1560
1561 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
1562+#define __read_only __attribute__ ((__section__(".data..read_only")))
1563
1564 #endif
1565diff --git a/arch/arm/include/asm/cacheflush.h b/arch/arm/include/asm/cacheflush.h
1566index 10e78d0..dc8505d 100644
1567--- a/arch/arm/include/asm/cacheflush.h
1568+++ b/arch/arm/include/asm/cacheflush.h
1569@@ -116,7 +116,7 @@ struct cpu_cache_fns {
1570 void (*dma_unmap_area)(const void *, size_t, int);
1571
1572 void (*dma_flush_range)(const void *, const void *);
1573-};
1574+} __no_const;
1575
1576 /*
1577 * Select the calling method
1578diff --git a/arch/arm/include/asm/checksum.h b/arch/arm/include/asm/checksum.h
1579index 5233151..87a71fa 100644
1580--- a/arch/arm/include/asm/checksum.h
1581+++ b/arch/arm/include/asm/checksum.h
1582@@ -37,7 +37,19 @@ __wsum
1583 csum_partial_copy_nocheck(const void *src, void *dst, int len, __wsum sum);
1584
1585 __wsum
1586-csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr);
1587+__csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr);
1588+
1589+static inline __wsum
1590+csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr)
1591+{
1592+ __wsum ret;
1593+ pax_open_userland();
1594+ ret = __csum_partial_copy_from_user(src, dst, len, sum, err_ptr);
1595+ pax_close_userland();
1596+ return ret;
1597+}
1598+
1599+
1600
1601 /*
1602 * Fold a partial checksum without adding pseudo headers
1603diff --git a/arch/arm/include/asm/cmpxchg.h b/arch/arm/include/asm/cmpxchg.h
1604index abb2c37..96db950 100644
1605--- a/arch/arm/include/asm/cmpxchg.h
1606+++ b/arch/arm/include/asm/cmpxchg.h
1607@@ -104,6 +104,8 @@ static inline unsigned long __xchg(unsigned long x, volatile void *ptr, int size
1608
1609 #define xchg(ptr,x) \
1610 ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1611+#define xchg_unchecked(ptr,x) \
1612+ ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1613
1614 #include <asm-generic/cmpxchg-local.h>
1615
1616diff --git a/arch/arm/include/asm/domain.h b/arch/arm/include/asm/domain.h
1617index 6ddbe44..b5e38b1 100644
1618--- a/arch/arm/include/asm/domain.h
1619+++ b/arch/arm/include/asm/domain.h
1620@@ -48,18 +48,37 @@
1621 * Domain types
1622 */
1623 #define DOMAIN_NOACCESS 0
1624-#define DOMAIN_CLIENT 1
1625 #ifdef CONFIG_CPU_USE_DOMAINS
1626+#define DOMAIN_USERCLIENT 1
1627+#define DOMAIN_KERNELCLIENT 1
1628 #define DOMAIN_MANAGER 3
1629+#define DOMAIN_VECTORS DOMAIN_USER
1630 #else
1631+
1632+#ifdef CONFIG_PAX_KERNEXEC
1633 #define DOMAIN_MANAGER 1
1634+#define DOMAIN_KERNEXEC 3
1635+#else
1636+#define DOMAIN_MANAGER 1
1637+#endif
1638+
1639+#ifdef CONFIG_PAX_MEMORY_UDEREF
1640+#define DOMAIN_USERCLIENT 0
1641+#define DOMAIN_UDEREF 1
1642+#define DOMAIN_VECTORS DOMAIN_KERNEL
1643+#else
1644+#define DOMAIN_USERCLIENT 1
1645+#define DOMAIN_VECTORS DOMAIN_USER
1646+#endif
1647+#define DOMAIN_KERNELCLIENT 1
1648+
1649 #endif
1650
1651 #define domain_val(dom,type) ((type) << (2*(dom)))
1652
1653 #ifndef __ASSEMBLY__
1654
1655-#ifdef CONFIG_CPU_USE_DOMAINS
1656+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
1657 static inline void set_domain(unsigned val)
1658 {
1659 asm volatile(
1660@@ -68,15 +87,7 @@ static inline void set_domain(unsigned val)
1661 isb();
1662 }
1663
1664-#define modify_domain(dom,type) \
1665- do { \
1666- struct thread_info *thread = current_thread_info(); \
1667- unsigned int domain = thread->cpu_domain; \
1668- domain &= ~domain_val(dom, DOMAIN_MANAGER); \
1669- thread->cpu_domain = domain | domain_val(dom, type); \
1670- set_domain(thread->cpu_domain); \
1671- } while (0)
1672-
1673+extern void modify_domain(unsigned int dom, unsigned int type);
1674 #else
1675 static inline void set_domain(unsigned val) { }
1676 static inline void modify_domain(unsigned dom, unsigned type) { }
1677diff --git a/arch/arm/include/asm/elf.h b/arch/arm/include/asm/elf.h
1678index afb9caf..9a0bac0 100644
1679--- a/arch/arm/include/asm/elf.h
1680+++ b/arch/arm/include/asm/elf.h
1681@@ -115,7 +115,14 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1682 the loader. We need to make sure that it is out of the way of the program
1683 that it will "exec", and that there is sufficient room for the brk. */
1684
1685-#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
1686+#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
1687+
1688+#ifdef CONFIG_PAX_ASLR
1689+#define PAX_ELF_ET_DYN_BASE 0x00008000UL
1690+
1691+#define PAX_DELTA_MMAP_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1692+#define PAX_DELTA_STACK_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1693+#endif
1694
1695 /* When the program starts, a1 contains a pointer to a function to be
1696 registered with atexit, as per the SVR4 ABI. A value of 0 means we
1697@@ -125,10 +132,6 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1698 extern void elf_set_personality(const struct elf32_hdr *);
1699 #define SET_PERSONALITY(ex) elf_set_personality(&(ex))
1700
1701-struct mm_struct;
1702-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
1703-#define arch_randomize_brk arch_randomize_brk
1704-
1705 #ifdef CONFIG_MMU
1706 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
1707 struct linux_binprm;
1708diff --git a/arch/arm/include/asm/fncpy.h b/arch/arm/include/asm/fncpy.h
1709index de53547..52b9a28 100644
1710--- a/arch/arm/include/asm/fncpy.h
1711+++ b/arch/arm/include/asm/fncpy.h
1712@@ -81,7 +81,9 @@
1713 BUG_ON((uintptr_t)(dest_buf) & (FNCPY_ALIGN - 1) || \
1714 (__funcp_address & ~(uintptr_t)1 & (FNCPY_ALIGN - 1))); \
1715 \
1716+ pax_open_kernel(); \
1717 memcpy(dest_buf, (void const *)(__funcp_address & ~1), size); \
1718+ pax_close_kernel(); \
1719 flush_icache_range((unsigned long)(dest_buf), \
1720 (unsigned long)(dest_buf) + (size)); \
1721 \
1722diff --git a/arch/arm/include/asm/futex.h b/arch/arm/include/asm/futex.h
1723index 53e69da..3fdc896 100644
1724--- a/arch/arm/include/asm/futex.h
1725+++ b/arch/arm/include/asm/futex.h
1726@@ -46,6 +46,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1727 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
1728 return -EFAULT;
1729
1730+ pax_open_userland();
1731+
1732 smp_mb();
1733 /* Prefetching cannot fault */
1734 prefetchw(uaddr);
1735@@ -63,6 +65,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1736 : "cc", "memory");
1737 smp_mb();
1738
1739+ pax_close_userland();
1740+
1741 *uval = val;
1742 return ret;
1743 }
1744@@ -93,6 +97,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1745 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
1746 return -EFAULT;
1747
1748+ pax_open_userland();
1749+
1750 __asm__ __volatile__("@futex_atomic_cmpxchg_inatomic\n"
1751 "1: " TUSER(ldr) " %1, [%4]\n"
1752 " teq %1, %2\n"
1753@@ -103,6 +109,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1754 : "r" (oldval), "r" (newval), "r" (uaddr), "Ir" (-EFAULT)
1755 : "cc", "memory");
1756
1757+ pax_close_userland();
1758+
1759 *uval = val;
1760 return ret;
1761 }
1762@@ -125,6 +133,7 @@ futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
1763 return -EFAULT;
1764
1765 pagefault_disable(); /* implies preempt_disable() */
1766+ pax_open_userland();
1767
1768 switch (op) {
1769 case FUTEX_OP_SET:
1770@@ -146,6 +155,7 @@ futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
1771 ret = -ENOSYS;
1772 }
1773
1774+ pax_close_userland();
1775 pagefault_enable(); /* subsumes preempt_enable() */
1776
1777 if (!ret) {
1778diff --git a/arch/arm/include/asm/kmap_types.h b/arch/arm/include/asm/kmap_types.h
1779index 83eb2f7..ed77159 100644
1780--- a/arch/arm/include/asm/kmap_types.h
1781+++ b/arch/arm/include/asm/kmap_types.h
1782@@ -4,6 +4,6 @@
1783 /*
1784 * This is the "bare minimum". AIO seems to require this.
1785 */
1786-#define KM_TYPE_NR 16
1787+#define KM_TYPE_NR 17
1788
1789 #endif
1790diff --git a/arch/arm/include/asm/mach/dma.h b/arch/arm/include/asm/mach/dma.h
1791index 9e614a1..3302cca 100644
1792--- a/arch/arm/include/asm/mach/dma.h
1793+++ b/arch/arm/include/asm/mach/dma.h
1794@@ -22,7 +22,7 @@ struct dma_ops {
1795 int (*residue)(unsigned int, dma_t *); /* optional */
1796 int (*setspeed)(unsigned int, dma_t *, int); /* optional */
1797 const char *type;
1798-};
1799+} __do_const;
1800
1801 struct dma_struct {
1802 void *addr; /* single DMA address */
1803diff --git a/arch/arm/include/asm/mach/map.h b/arch/arm/include/asm/mach/map.h
1804index f98c7f3..e5c626d 100644
1805--- a/arch/arm/include/asm/mach/map.h
1806+++ b/arch/arm/include/asm/mach/map.h
1807@@ -23,17 +23,19 @@ struct map_desc {
1808
1809 /* types 0-3 are defined in asm/io.h */
1810 enum {
1811- MT_UNCACHED = 4,
1812- MT_CACHECLEAN,
1813- MT_MINICLEAN,
1814+ MT_UNCACHED_RW = 4,
1815+ MT_CACHECLEAN_RO,
1816+ MT_MINICLEAN_RO,
1817 MT_LOW_VECTORS,
1818 MT_HIGH_VECTORS,
1819- MT_MEMORY_RWX,
1820+ __MT_MEMORY_RWX,
1821 MT_MEMORY_RW,
1822- MT_ROM,
1823- MT_MEMORY_RWX_NONCACHED,
1824+ MT_MEMORY_RX,
1825+ MT_ROM_RX,
1826+ MT_MEMORY_RW_NONCACHED,
1827+ MT_MEMORY_RX_NONCACHED,
1828 MT_MEMORY_RW_DTCM,
1829- MT_MEMORY_RWX_ITCM,
1830+ MT_MEMORY_RX_ITCM,
1831 MT_MEMORY_RW_SO,
1832 MT_MEMORY_DMA_READY,
1833 };
1834diff --git a/arch/arm/include/asm/outercache.h b/arch/arm/include/asm/outercache.h
1835index 891a56b..48f337e 100644
1836--- a/arch/arm/include/asm/outercache.h
1837+++ b/arch/arm/include/asm/outercache.h
1838@@ -36,7 +36,7 @@ struct outer_cache_fns {
1839
1840 /* This is an ARM L2C thing */
1841 void (*write_sec)(unsigned long, unsigned);
1842-};
1843+} __no_const;
1844
1845 extern struct outer_cache_fns outer_cache;
1846
1847diff --git a/arch/arm/include/asm/page.h b/arch/arm/include/asm/page.h
1848index 4355f0e..cd9168e 100644
1849--- a/arch/arm/include/asm/page.h
1850+++ b/arch/arm/include/asm/page.h
1851@@ -23,6 +23,7 @@
1852
1853 #else
1854
1855+#include <linux/compiler.h>
1856 #include <asm/glue.h>
1857
1858 /*
1859@@ -114,7 +115,7 @@ struct cpu_user_fns {
1860 void (*cpu_clear_user_highpage)(struct page *page, unsigned long vaddr);
1861 void (*cpu_copy_user_highpage)(struct page *to, struct page *from,
1862 unsigned long vaddr, struct vm_area_struct *vma);
1863-};
1864+} __no_const;
1865
1866 #ifdef MULTI_USER
1867 extern struct cpu_user_fns cpu_user;
1868diff --git a/arch/arm/include/asm/pgalloc.h b/arch/arm/include/asm/pgalloc.h
1869index 78a7793..e3dc06c 100644
1870--- a/arch/arm/include/asm/pgalloc.h
1871+++ b/arch/arm/include/asm/pgalloc.h
1872@@ -17,6 +17,7 @@
1873 #include <asm/processor.h>
1874 #include <asm/cacheflush.h>
1875 #include <asm/tlbflush.h>
1876+#include <asm/system_info.h>
1877
1878 #define check_pgt_cache() do { } while (0)
1879
1880@@ -43,6 +44,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1881 set_pud(pud, __pud(__pa(pmd) | PMD_TYPE_TABLE));
1882 }
1883
1884+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1885+{
1886+ pud_populate(mm, pud, pmd);
1887+}
1888+
1889 #else /* !CONFIG_ARM_LPAE */
1890
1891 /*
1892@@ -51,6 +57,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1893 #define pmd_alloc_one(mm,addr) ({ BUG(); ((pmd_t *)2); })
1894 #define pmd_free(mm, pmd) do { } while (0)
1895 #define pud_populate(mm,pmd,pte) BUG()
1896+#define pud_populate_kernel(mm,pmd,pte) BUG()
1897
1898 #endif /* CONFIG_ARM_LPAE */
1899
1900@@ -128,6 +135,19 @@ static inline void pte_free(struct mm_struct *mm, pgtable_t pte)
1901 __free_page(pte);
1902 }
1903
1904+static inline void __section_update(pmd_t *pmdp, unsigned long addr, pmdval_t prot)
1905+{
1906+#ifdef CONFIG_ARM_LPAE
1907+ pmdp[0] = __pmd(pmd_val(pmdp[0]) | prot);
1908+#else
1909+ if (addr & SECTION_SIZE)
1910+ pmdp[1] = __pmd(pmd_val(pmdp[1]) | prot);
1911+ else
1912+ pmdp[0] = __pmd(pmd_val(pmdp[0]) | prot);
1913+#endif
1914+ flush_pmd_entry(pmdp);
1915+}
1916+
1917 static inline void __pmd_populate(pmd_t *pmdp, phys_addr_t pte,
1918 pmdval_t prot)
1919 {
1920@@ -157,7 +177,7 @@ pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmdp, pte_t *ptep)
1921 static inline void
1922 pmd_populate(struct mm_struct *mm, pmd_t *pmdp, pgtable_t ptep)
1923 {
1924- __pmd_populate(pmdp, page_to_phys(ptep), _PAGE_USER_TABLE);
1925+ __pmd_populate(pmdp, page_to_phys(ptep), _PAGE_USER_TABLE | __supported_pmd_mask);
1926 }
1927 #define pmd_pgtable(pmd) pmd_page(pmd)
1928
1929diff --git a/arch/arm/include/asm/pgtable-2level-hwdef.h b/arch/arm/include/asm/pgtable-2level-hwdef.h
1930index 5cfba15..f415e1a 100644
1931--- a/arch/arm/include/asm/pgtable-2level-hwdef.h
1932+++ b/arch/arm/include/asm/pgtable-2level-hwdef.h
1933@@ -20,12 +20,15 @@
1934 #define PMD_TYPE_FAULT (_AT(pmdval_t, 0) << 0)
1935 #define PMD_TYPE_TABLE (_AT(pmdval_t, 1) << 0)
1936 #define PMD_TYPE_SECT (_AT(pmdval_t, 2) << 0)
1937+#define PMD_PXNTABLE (_AT(pmdval_t, 1) << 2) /* v7 */
1938 #define PMD_BIT4 (_AT(pmdval_t, 1) << 4)
1939 #define PMD_DOMAIN(x) (_AT(pmdval_t, (x)) << 5)
1940 #define PMD_PROTECTION (_AT(pmdval_t, 1) << 9) /* v5 */
1941+
1942 /*
1943 * - section
1944 */
1945+#define PMD_SECT_PXN (_AT(pmdval_t, 1) << 0) /* v7 */
1946 #define PMD_SECT_BUFFERABLE (_AT(pmdval_t, 1) << 2)
1947 #define PMD_SECT_CACHEABLE (_AT(pmdval_t, 1) << 3)
1948 #define PMD_SECT_XN (_AT(pmdval_t, 1) << 4) /* v6 */
1949@@ -37,6 +40,7 @@
1950 #define PMD_SECT_nG (_AT(pmdval_t, 1) << 17) /* v6 */
1951 #define PMD_SECT_SUPER (_AT(pmdval_t, 1) << 18) /* v6 */
1952 #define PMD_SECT_AF (_AT(pmdval_t, 0))
1953+#define PMD_SECT_RDONLY (_AT(pmdval_t, 0))
1954
1955 #define PMD_SECT_UNCACHED (_AT(pmdval_t, 0))
1956 #define PMD_SECT_BUFFERED (PMD_SECT_BUFFERABLE)
1957@@ -66,6 +70,7 @@
1958 * - extended small page/tiny page
1959 */
1960 #define PTE_EXT_XN (_AT(pteval_t, 1) << 0) /* v6 */
1961+#define PTE_EXT_PXN (_AT(pteval_t, 1) << 2) /* v7 */
1962 #define PTE_EXT_AP_MASK (_AT(pteval_t, 3) << 4)
1963 #define PTE_EXT_AP0 (_AT(pteval_t, 1) << 4)
1964 #define PTE_EXT_AP1 (_AT(pteval_t, 2) << 4)
1965diff --git a/arch/arm/include/asm/pgtable-2level.h b/arch/arm/include/asm/pgtable-2level.h
1966index f027941..f36ce30 100644
1967--- a/arch/arm/include/asm/pgtable-2level.h
1968+++ b/arch/arm/include/asm/pgtable-2level.h
1969@@ -126,6 +126,9 @@
1970 #define L_PTE_SHARED (_AT(pteval_t, 1) << 10) /* shared(v6), coherent(xsc3) */
1971 #define L_PTE_NONE (_AT(pteval_t, 1) << 11)
1972
1973+/* Two-level page tables only have PXN in the PGD, not in the PTE. */
1974+#define L_PTE_PXN (_AT(pteval_t, 0))
1975+
1976 /*
1977 * These are the memory types, defined to be compatible with
1978 * pre-ARMv6 CPUs cacheable and bufferable bits: XXCB
1979diff --git a/arch/arm/include/asm/pgtable-3level-hwdef.h b/arch/arm/include/asm/pgtable-3level-hwdef.h
1980index 9fd61c7..f8f1cff 100644
1981--- a/arch/arm/include/asm/pgtable-3level-hwdef.h
1982+++ b/arch/arm/include/asm/pgtable-3level-hwdef.h
1983@@ -76,6 +76,7 @@
1984 #define PTE_EXT_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
1985 #define PTE_EXT_AF (_AT(pteval_t, 1) << 10) /* Access Flag */
1986 #define PTE_EXT_NG (_AT(pteval_t, 1) << 11) /* nG */
1987+#define PTE_EXT_PXN (_AT(pteval_t, 1) << 53) /* PXN */
1988 #define PTE_EXT_XN (_AT(pteval_t, 1) << 54) /* XN */
1989
1990 /*
1991diff --git a/arch/arm/include/asm/pgtable-3level.h b/arch/arm/include/asm/pgtable-3level.h
1992index a31ecdad..95e98d4 100644
1993--- a/arch/arm/include/asm/pgtable-3level.h
1994+++ b/arch/arm/include/asm/pgtable-3level.h
1995@@ -81,6 +81,7 @@
1996 #define L_PTE_USER (_AT(pteval_t, 1) << 6) /* AP[1] */
1997 #define L_PTE_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
1998 #define L_PTE_YOUNG (_AT(pteval_t, 1) << 10) /* AF */
1999+#define L_PTE_PXN (_AT(pteval_t, 1) << 53) /* PXN */
2000 #define L_PTE_XN (_AT(pteval_t, 1) << 54) /* XN */
2001 #define L_PTE_DIRTY (_AT(pteval_t, 1) << 55)
2002 #define L_PTE_SPECIAL (_AT(pteval_t, 1) << 56)
2003@@ -92,10 +93,12 @@
2004 #define L_PMD_SECT_SPLITTING (_AT(pmdval_t, 1) << 56)
2005 #define L_PMD_SECT_NONE (_AT(pmdval_t, 1) << 57)
2006 #define L_PMD_SECT_RDONLY (_AT(pteval_t, 1) << 58)
2007+#define PMD_SECT_RDONLY PMD_SECT_AP2
2008
2009 /*
2010 * To be used in assembly code with the upper page attributes.
2011 */
2012+#define L_PTE_PXN_HIGH (1 << (53 - 32))
2013 #define L_PTE_XN_HIGH (1 << (54 - 32))
2014 #define L_PTE_DIRTY_HIGH (1 << (55 - 32))
2015
2016diff --git a/arch/arm/include/asm/pgtable.h b/arch/arm/include/asm/pgtable.h
2017index 3b30062..01a5f9d 100644
2018--- a/arch/arm/include/asm/pgtable.h
2019+++ b/arch/arm/include/asm/pgtable.h
2020@@ -33,6 +33,9 @@
2021 #include <asm/pgtable-2level.h>
2022 #endif
2023
2024+#define ktla_ktva(addr) (addr)
2025+#define ktva_ktla(addr) (addr)
2026+
2027 /*
2028 * Just any arbitrary offset to the start of the vmalloc VM area: the
2029 * current 8MB value just means that there will be a 8MB "hole" after the
2030@@ -48,6 +51,9 @@
2031 #define LIBRARY_TEXT_START 0x0c000000
2032
2033 #ifndef __ASSEMBLY__
2034+extern pteval_t __supported_pte_mask;
2035+extern pmdval_t __supported_pmd_mask;
2036+
2037 extern void __pte_error(const char *file, int line, pte_t);
2038 extern void __pmd_error(const char *file, int line, pmd_t);
2039 extern void __pgd_error(const char *file, int line, pgd_t);
2040@@ -56,6 +62,48 @@ extern void __pgd_error(const char *file, int line, pgd_t);
2041 #define pmd_ERROR(pmd) __pmd_error(__FILE__, __LINE__, pmd)
2042 #define pgd_ERROR(pgd) __pgd_error(__FILE__, __LINE__, pgd)
2043
2044+#define __HAVE_ARCH_PAX_OPEN_KERNEL
2045+#define __HAVE_ARCH_PAX_CLOSE_KERNEL
2046+
2047+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2048+#include <asm/domain.h>
2049+#include <linux/thread_info.h>
2050+#include <linux/preempt.h>
2051+
2052+static inline int test_domain(int domain, int domaintype)
2053+{
2054+ return ((current_thread_info()->cpu_domain) & domain_val(domain, 3)) == domain_val(domain, domaintype);
2055+}
2056+#endif
2057+
2058+#ifdef CONFIG_PAX_KERNEXEC
2059+static inline unsigned long pax_open_kernel(void) {
2060+#ifdef CONFIG_ARM_LPAE
2061+ /* TODO */
2062+#else
2063+ preempt_disable();
2064+ BUG_ON(test_domain(DOMAIN_KERNEL, DOMAIN_KERNEXEC));
2065+ modify_domain(DOMAIN_KERNEL, DOMAIN_KERNEXEC);
2066+#endif
2067+ return 0;
2068+}
2069+
2070+static inline unsigned long pax_close_kernel(void) {
2071+#ifdef CONFIG_ARM_LPAE
2072+ /* TODO */
2073+#else
2074+ BUG_ON(test_domain(DOMAIN_KERNEL, DOMAIN_MANAGER));
2075+ /* DOMAIN_MANAGER = "client" under KERNEXEC */
2076+ modify_domain(DOMAIN_KERNEL, DOMAIN_MANAGER);
2077+ preempt_enable_no_resched();
2078+#endif
2079+ return 0;
2080+}
2081+#else
2082+static inline unsigned long pax_open_kernel(void) { return 0; }
2083+static inline unsigned long pax_close_kernel(void) { return 0; }
2084+#endif
2085+
2086 /*
2087 * This is the lowest virtual address we can permit any user space
2088 * mapping to be mapped at. This is particularly important for
2089@@ -75,8 +123,8 @@ extern void __pgd_error(const char *file, int line, pgd_t);
2090 /*
2091 * The pgprot_* and protection_map entries will be fixed up in runtime
2092 * to include the cachable and bufferable bits based on memory policy,
2093- * as well as any architecture dependent bits like global/ASID and SMP
2094- * shared mapping bits.
2095+ * as well as any architecture dependent bits like global/ASID, PXN,
2096+ * and SMP shared mapping bits.
2097 */
2098 #define _L_PTE_DEFAULT L_PTE_PRESENT | L_PTE_YOUNG
2099
2100@@ -267,7 +315,7 @@ PTE_BIT_FUNC(mknexec, |= L_PTE_XN);
2101 static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
2102 {
2103 const pteval_t mask = L_PTE_XN | L_PTE_RDONLY | L_PTE_USER |
2104- L_PTE_NONE | L_PTE_VALID;
2105+ L_PTE_NONE | L_PTE_VALID | __supported_pte_mask;
2106 pte_val(pte) = (pte_val(pte) & ~mask) | (pgprot_val(newprot) & mask);
2107 return pte;
2108 }
2109diff --git a/arch/arm/include/asm/psci.h b/arch/arm/include/asm/psci.h
2110index c25ef3e..735f14b 100644
2111--- a/arch/arm/include/asm/psci.h
2112+++ b/arch/arm/include/asm/psci.h
2113@@ -32,7 +32,7 @@ struct psci_operations {
2114 int (*affinity_info)(unsigned long target_affinity,
2115 unsigned long lowest_affinity_level);
2116 int (*migrate_info_type)(void);
2117-};
2118+} __no_const;
2119
2120 extern struct psci_operations psci_ops;
2121 extern struct smp_operations psci_smp_ops;
2122diff --git a/arch/arm/include/asm/smp.h b/arch/arm/include/asm/smp.h
2123index 18f5a55..5072a40 100644
2124--- a/arch/arm/include/asm/smp.h
2125+++ b/arch/arm/include/asm/smp.h
2126@@ -107,7 +107,7 @@ struct smp_operations {
2127 int (*cpu_disable)(unsigned int cpu);
2128 #endif
2129 #endif
2130-};
2131+} __no_const;
2132
2133 struct of_cpu_method {
2134 const char *method;
2135diff --git a/arch/arm/include/asm/thread_info.h b/arch/arm/include/asm/thread_info.h
2136index ce73ab6..7310f8a 100644
2137--- a/arch/arm/include/asm/thread_info.h
2138+++ b/arch/arm/include/asm/thread_info.h
2139@@ -78,9 +78,9 @@ struct thread_info {
2140 .flags = 0, \
2141 .preempt_count = INIT_PREEMPT_COUNT, \
2142 .addr_limit = KERNEL_DS, \
2143- .cpu_domain = domain_val(DOMAIN_USER, DOMAIN_MANAGER) | \
2144- domain_val(DOMAIN_KERNEL, DOMAIN_MANAGER) | \
2145- domain_val(DOMAIN_IO, DOMAIN_CLIENT), \
2146+ .cpu_domain = domain_val(DOMAIN_USER, DOMAIN_USERCLIENT) | \
2147+ domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT) | \
2148+ domain_val(DOMAIN_IO, DOMAIN_KERNELCLIENT), \
2149 .restart_block = { \
2150 .fn = do_no_restart_syscall, \
2151 }, \
2152@@ -154,7 +154,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
2153 #define TIF_SYSCALL_AUDIT 9
2154 #define TIF_SYSCALL_TRACEPOINT 10
2155 #define TIF_SECCOMP 11 /* seccomp syscall filtering active */
2156-#define TIF_NOHZ 12 /* in adaptive nohz mode */
2157+/* within 8 bits of TIF_SYSCALL_TRACE
2158+ * to meet flexible second operand requirements
2159+ */
2160+#define TIF_GRSEC_SETXID 12
2161+#define TIF_NOHZ 13 /* in adaptive nohz mode */
2162 #define TIF_USING_IWMMXT 17
2163 #define TIF_MEMDIE 18 /* is terminating due to OOM killer */
2164 #define TIF_RESTORE_SIGMASK 20
2165@@ -168,10 +172,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
2166 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
2167 #define _TIF_SECCOMP (1 << TIF_SECCOMP)
2168 #define _TIF_USING_IWMMXT (1 << TIF_USING_IWMMXT)
2169+#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
2170
2171 /* Checks for any syscall work in entry-common.S */
2172 #define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
2173- _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP)
2174+ _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP | _TIF_GRSEC_SETXID)
2175
2176 /*
2177 * Change these and you break ASM code in entry-common.S
2178diff --git a/arch/arm/include/asm/tls.h b/arch/arm/include/asm/tls.h
2179index 5f833f7..76e6644 100644
2180--- a/arch/arm/include/asm/tls.h
2181+++ b/arch/arm/include/asm/tls.h
2182@@ -3,6 +3,7 @@
2183
2184 #include <linux/compiler.h>
2185 #include <asm/thread_info.h>
2186+#include <asm/pgtable.h>
2187
2188 #ifdef __ASSEMBLY__
2189 #include <asm/asm-offsets.h>
2190@@ -89,7 +90,9 @@ static inline void set_tls(unsigned long val)
2191 * at 0xffff0fe0 must be used instead. (see
2192 * entry-armv.S for details)
2193 */
2194+ pax_open_kernel();
2195 *((unsigned int *)0xffff0ff0) = val;
2196+ pax_close_kernel();
2197 #endif
2198 }
2199
2200diff --git a/arch/arm/include/asm/uaccess.h b/arch/arm/include/asm/uaccess.h
2201index 4767eb9..bf00668 100644
2202--- a/arch/arm/include/asm/uaccess.h
2203+++ b/arch/arm/include/asm/uaccess.h
2204@@ -18,6 +18,7 @@
2205 #include <asm/domain.h>
2206 #include <asm/unified.h>
2207 #include <asm/compiler.h>
2208+#include <asm/pgtable.h>
2209
2210 #ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
2211 #include <asm-generic/uaccess-unaligned.h>
2212@@ -70,11 +71,38 @@ extern int __put_user_bad(void);
2213 static inline void set_fs(mm_segment_t fs)
2214 {
2215 current_thread_info()->addr_limit = fs;
2216- modify_domain(DOMAIN_KERNEL, fs ? DOMAIN_CLIENT : DOMAIN_MANAGER);
2217+ modify_domain(DOMAIN_KERNEL, fs ? DOMAIN_KERNELCLIENT : DOMAIN_MANAGER);
2218 }
2219
2220 #define segment_eq(a,b) ((a) == (b))
2221
2222+#define __HAVE_ARCH_PAX_OPEN_USERLAND
2223+#define __HAVE_ARCH_PAX_CLOSE_USERLAND
2224+
2225+static inline void pax_open_userland(void)
2226+{
2227+
2228+#ifdef CONFIG_PAX_MEMORY_UDEREF
2229+ if (segment_eq(get_fs(), USER_DS)) {
2230+ BUG_ON(test_domain(DOMAIN_USER, DOMAIN_UDEREF));
2231+ modify_domain(DOMAIN_USER, DOMAIN_UDEREF);
2232+ }
2233+#endif
2234+
2235+}
2236+
2237+static inline void pax_close_userland(void)
2238+{
2239+
2240+#ifdef CONFIG_PAX_MEMORY_UDEREF
2241+ if (segment_eq(get_fs(), USER_DS)) {
2242+ BUG_ON(test_domain(DOMAIN_USER, DOMAIN_NOACCESS));
2243+ modify_domain(DOMAIN_USER, DOMAIN_NOACCESS);
2244+ }
2245+#endif
2246+
2247+}
2248+
2249 #define __addr_ok(addr) ({ \
2250 unsigned long flag; \
2251 __asm__("cmp %2, %0; movlo %0, #0" \
2252@@ -198,8 +226,12 @@ extern int __get_user_64t_4(void *);
2253
2254 #define get_user(x,p) \
2255 ({ \
2256+ int __e; \
2257 might_fault(); \
2258- __get_user_check(x,p); \
2259+ pax_open_userland(); \
2260+ __e = __get_user_check(x,p); \
2261+ pax_close_userland(); \
2262+ __e; \
2263 })
2264
2265 extern int __put_user_1(void *, unsigned int);
2266@@ -244,8 +276,12 @@ extern int __put_user_8(void *, unsigned long long);
2267
2268 #define put_user(x,p) \
2269 ({ \
2270+ int __e; \
2271 might_fault(); \
2272- __put_user_check(x,p); \
2273+ pax_open_userland(); \
2274+ __e = __put_user_check(x,p); \
2275+ pax_close_userland(); \
2276+ __e; \
2277 })
2278
2279 #else /* CONFIG_MMU */
2280@@ -269,6 +305,7 @@ static inline void set_fs(mm_segment_t fs)
2281
2282 #endif /* CONFIG_MMU */
2283
2284+#define access_ok_noprefault(type,addr,size) access_ok((type),(addr),(size))
2285 #define access_ok(type,addr,size) (__range_ok(addr,size) == 0)
2286
2287 #define user_addr_max() \
2288@@ -286,13 +323,17 @@ static inline void set_fs(mm_segment_t fs)
2289 #define __get_user(x,ptr) \
2290 ({ \
2291 long __gu_err = 0; \
2292+ pax_open_userland(); \
2293 __get_user_err((x),(ptr),__gu_err); \
2294+ pax_close_userland(); \
2295 __gu_err; \
2296 })
2297
2298 #define __get_user_error(x,ptr,err) \
2299 ({ \
2300+ pax_open_userland(); \
2301 __get_user_err((x),(ptr),err); \
2302+ pax_close_userland(); \
2303 (void) 0; \
2304 })
2305
2306@@ -368,13 +409,17 @@ do { \
2307 #define __put_user(x,ptr) \
2308 ({ \
2309 long __pu_err = 0; \
2310+ pax_open_userland(); \
2311 __put_user_err((x),(ptr),__pu_err); \
2312+ pax_close_userland(); \
2313 __pu_err; \
2314 })
2315
2316 #define __put_user_error(x,ptr,err) \
2317 ({ \
2318+ pax_open_userland(); \
2319 __put_user_err((x),(ptr),err); \
2320+ pax_close_userland(); \
2321 (void) 0; \
2322 })
2323
2324@@ -474,11 +519,44 @@ do { \
2325
2326
2327 #ifdef CONFIG_MMU
2328-extern unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n);
2329-extern unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n);
2330+extern unsigned long __must_check ___copy_from_user(void *to, const void __user *from, unsigned long n);
2331+extern unsigned long __must_check ___copy_to_user(void __user *to, const void *from, unsigned long n);
2332+
2333+static inline unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n)
2334+{
2335+ unsigned long ret;
2336+
2337+ check_object_size(to, n, false);
2338+ pax_open_userland();
2339+ ret = ___copy_from_user(to, from, n);
2340+ pax_close_userland();
2341+ return ret;
2342+}
2343+
2344+static inline unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n)
2345+{
2346+ unsigned long ret;
2347+
2348+ check_object_size(from, n, true);
2349+ pax_open_userland();
2350+ ret = ___copy_to_user(to, from, n);
2351+ pax_close_userland();
2352+ return ret;
2353+}
2354+
2355 extern unsigned long __must_check __copy_to_user_std(void __user *to, const void *from, unsigned long n);
2356-extern unsigned long __must_check __clear_user(void __user *addr, unsigned long n);
2357+extern unsigned long __must_check ___clear_user(void __user *addr, unsigned long n);
2358 extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned long n);
2359+
2360+static inline unsigned long __must_check __clear_user(void __user *addr, unsigned long n)
2361+{
2362+ unsigned long ret;
2363+ pax_open_userland();
2364+ ret = ___clear_user(addr, n);
2365+ pax_close_userland();
2366+ return ret;
2367+}
2368+
2369 #else
2370 #define __copy_from_user(to,from,n) (memcpy(to, (void __force *)from, n), 0)
2371 #define __copy_to_user(to,from,n) (memcpy((void __force *)to, from, n), 0)
2372@@ -487,6 +565,9 @@ extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned l
2373
2374 static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
2375 {
2376+ if ((long)n < 0)
2377+ return n;
2378+
2379 if (access_ok(VERIFY_READ, from, n))
2380 n = __copy_from_user(to, from, n);
2381 else /* security hole - plug it */
2382@@ -496,6 +577,9 @@ static inline unsigned long __must_check copy_from_user(void *to, const void __u
2383
2384 static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
2385 {
2386+ if ((long)n < 0)
2387+ return n;
2388+
2389 if (access_ok(VERIFY_WRITE, to, n))
2390 n = __copy_to_user(to, from, n);
2391 return n;
2392diff --git a/arch/arm/include/uapi/asm/ptrace.h b/arch/arm/include/uapi/asm/ptrace.h
2393index 5af0ed1..cea83883 100644
2394--- a/arch/arm/include/uapi/asm/ptrace.h
2395+++ b/arch/arm/include/uapi/asm/ptrace.h
2396@@ -92,7 +92,7 @@
2397 * ARMv7 groups of PSR bits
2398 */
2399 #define APSR_MASK 0xf80f0000 /* N, Z, C, V, Q and GE flags */
2400-#define PSR_ISET_MASK 0x01000010 /* ISA state (J, T) mask */
2401+#define PSR_ISET_MASK 0x01000020 /* ISA state (J, T) mask */
2402 #define PSR_IT_MASK 0x0600fc00 /* If-Then execution state mask */
2403 #define PSR_ENDIAN_MASK 0x00000200 /* Endianness state mask */
2404
2405diff --git a/arch/arm/kernel/armksyms.c b/arch/arm/kernel/armksyms.c
2406index a88671c..1cc895e 100644
2407--- a/arch/arm/kernel/armksyms.c
2408+++ b/arch/arm/kernel/armksyms.c
2409@@ -55,7 +55,7 @@ EXPORT_SYMBOL(arm_delay_ops);
2410
2411 /* networking */
2412 EXPORT_SYMBOL(csum_partial);
2413-EXPORT_SYMBOL(csum_partial_copy_from_user);
2414+EXPORT_SYMBOL(__csum_partial_copy_from_user);
2415 EXPORT_SYMBOL(csum_partial_copy_nocheck);
2416 EXPORT_SYMBOL(__csum_ipv6_magic);
2417
2418@@ -91,9 +91,9 @@ EXPORT_SYMBOL(__memzero);
2419 #ifdef CONFIG_MMU
2420 EXPORT_SYMBOL(copy_page);
2421
2422-EXPORT_SYMBOL(__copy_from_user);
2423-EXPORT_SYMBOL(__copy_to_user);
2424-EXPORT_SYMBOL(__clear_user);
2425+EXPORT_SYMBOL(___copy_from_user);
2426+EXPORT_SYMBOL(___copy_to_user);
2427+EXPORT_SYMBOL(___clear_user);
2428
2429 EXPORT_SYMBOL(__get_user_1);
2430 EXPORT_SYMBOL(__get_user_2);
2431diff --git a/arch/arm/kernel/entry-armv.S b/arch/arm/kernel/entry-armv.S
2432index 2f5555d..d493c91 100644
2433--- a/arch/arm/kernel/entry-armv.S
2434+++ b/arch/arm/kernel/entry-armv.S
2435@@ -47,6 +47,87 @@
2436 9997:
2437 .endm
2438
2439+ .macro pax_enter_kernel
2440+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2441+ @ make aligned space for saved DACR
2442+ sub sp, sp, #8
2443+ @ save regs
2444+ stmdb sp!, {r1, r2}
2445+ @ read DACR from cpu_domain into r1
2446+ mov r2, sp
2447+ @ assume 8K pages, since we have to split the immediate in two
2448+ bic r2, r2, #(0x1fc0)
2449+ bic r2, r2, #(0x3f)
2450+ ldr r1, [r2, #TI_CPU_DOMAIN]
2451+ @ store old DACR on stack
2452+ str r1, [sp, #8]
2453+#ifdef CONFIG_PAX_KERNEXEC
2454+ @ set type of DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2455+ bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2456+ orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2457+#endif
2458+#ifdef CONFIG_PAX_MEMORY_UDEREF
2459+ @ set current DOMAIN_USER to DOMAIN_NOACCESS
2460+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2461+#endif
2462+ @ write r1 to current_thread_info()->cpu_domain
2463+ str r1, [r2, #TI_CPU_DOMAIN]
2464+ @ write r1 to DACR
2465+ mcr p15, 0, r1, c3, c0, 0
2466+ @ instruction sync
2467+ instr_sync
2468+ @ restore regs
2469+ ldmia sp!, {r1, r2}
2470+#endif
2471+ .endm
2472+
2473+ .macro pax_open_userland
2474+#ifdef CONFIG_PAX_MEMORY_UDEREF
2475+ @ save regs
2476+ stmdb sp!, {r0, r1}
2477+ @ read DACR from cpu_domain into r1
2478+ mov r0, sp
2479+ @ assume 8K pages, since we have to split the immediate in two
2480+ bic r0, r0, #(0x1fc0)
2481+ bic r0, r0, #(0x3f)
2482+ ldr r1, [r0, #TI_CPU_DOMAIN]
2483+ @ set current DOMAIN_USER to DOMAIN_CLIENT
2484+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2485+ orr r1, r1, #(domain_val(DOMAIN_USER, DOMAIN_UDEREF))
2486+ @ write r1 to current_thread_info()->cpu_domain
2487+ str r1, [r0, #TI_CPU_DOMAIN]
2488+ @ write r1 to DACR
2489+ mcr p15, 0, r1, c3, c0, 0
2490+ @ instruction sync
2491+ instr_sync
2492+ @ restore regs
2493+ ldmia sp!, {r0, r1}
2494+#endif
2495+ .endm
2496+
2497+ .macro pax_close_userland
2498+#ifdef CONFIG_PAX_MEMORY_UDEREF
2499+ @ save regs
2500+ stmdb sp!, {r0, r1}
2501+ @ read DACR from cpu_domain into r1
2502+ mov r0, sp
2503+ @ assume 8K pages, since we have to split the immediate in two
2504+ bic r0, r0, #(0x1fc0)
2505+ bic r0, r0, #(0x3f)
2506+ ldr r1, [r0, #TI_CPU_DOMAIN]
2507+ @ set current DOMAIN_USER to DOMAIN_NOACCESS
2508+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2509+ @ write r1 to current_thread_info()->cpu_domain
2510+ str r1, [r0, #TI_CPU_DOMAIN]
2511+ @ write r1 to DACR
2512+ mcr p15, 0, r1, c3, c0, 0
2513+ @ instruction sync
2514+ instr_sync
2515+ @ restore regs
2516+ ldmia sp!, {r0, r1}
2517+#endif
2518+ .endm
2519+
2520 .macro pabt_helper
2521 @ PABORT handler takes pt_regs in r2, fault address in r4 and psr in r5
2522 #ifdef MULTI_PABORT
2523@@ -89,11 +170,15 @@
2524 * Invalid mode handlers
2525 */
2526 .macro inv_entry, reason
2527+
2528+ pax_enter_kernel
2529+
2530 sub sp, sp, #S_FRAME_SIZE
2531 ARM( stmib sp, {r1 - lr} )
2532 THUMB( stmia sp, {r0 - r12} )
2533 THUMB( str sp, [sp, #S_SP] )
2534 THUMB( str lr, [sp, #S_LR] )
2535+
2536 mov r1, #\reason
2537 .endm
2538
2539@@ -149,7 +234,11 @@ ENDPROC(__und_invalid)
2540 .macro svc_entry, stack_hole=0, trace=1
2541 UNWIND(.fnstart )
2542 UNWIND(.save {r0 - pc} )
2543+
2544+ pax_enter_kernel
2545+
2546 sub sp, sp, #(S_FRAME_SIZE + \stack_hole - 4)
2547+
2548 #ifdef CONFIG_THUMB2_KERNEL
2549 SPFIX( str r0, [sp] ) @ temporarily saved
2550 SPFIX( mov r0, sp )
2551@@ -164,7 +253,12 @@ ENDPROC(__und_invalid)
2552 ldmia r0, {r3 - r5}
2553 add r7, sp, #S_SP - 4 @ here for interlock avoidance
2554 mov r6, #-1 @ "" "" "" ""
2555+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2556+ @ offset sp by 8 as done in pax_enter_kernel
2557+ add r2, sp, #(S_FRAME_SIZE + \stack_hole + 4)
2558+#else
2559 add r2, sp, #(S_FRAME_SIZE + \stack_hole - 4)
2560+#endif
2561 SPFIX( addeq r2, r2, #4 )
2562 str r3, [sp, #-4]! @ save the "real" r0 copied
2563 @ from the exception stack
2564@@ -368,6 +462,9 @@ ENDPROC(__fiq_abt)
2565 .macro usr_entry, trace=1
2566 UNWIND(.fnstart )
2567 UNWIND(.cantunwind ) @ don't unwind the user space
2568+
2569+ pax_enter_kernel_user
2570+
2571 sub sp, sp, #S_FRAME_SIZE
2572 ARM( stmib sp, {r1 - r12} )
2573 THUMB( stmia sp, {r0 - r12} )
2574@@ -478,7 +575,9 @@ __und_usr:
2575 tst r3, #PSR_T_BIT @ Thumb mode?
2576 bne __und_usr_thumb
2577 sub r4, r2, #4 @ ARM instr at LR - 4
2578+ pax_open_userland
2579 1: ldrt r0, [r4]
2580+ pax_close_userland
2581 ARM_BE8(rev r0, r0) @ little endian instruction
2582
2583 @ r0 = 32-bit ARM instruction which caused the exception
2584@@ -512,11 +611,15 @@ __und_usr_thumb:
2585 */
2586 .arch armv6t2
2587 #endif
2588+ pax_open_userland
2589 2: ldrht r5, [r4]
2590+ pax_close_userland
2591 ARM_BE8(rev16 r5, r5) @ little endian instruction
2592 cmp r5, #0xe800 @ 32bit instruction if xx != 0
2593 blo __und_usr_fault_16 @ 16bit undefined instruction
2594+ pax_open_userland
2595 3: ldrht r0, [r2]
2596+ pax_close_userland
2597 ARM_BE8(rev16 r0, r0) @ little endian instruction
2598 add r2, r2, #2 @ r2 is PC + 2, make it PC + 4
2599 str r2, [sp, #S_PC] @ it's a 2x16bit instr, update
2600@@ -546,7 +649,8 @@ ENDPROC(__und_usr)
2601 */
2602 .pushsection .fixup, "ax"
2603 .align 2
2604-4: str r4, [sp, #S_PC] @ retry current instruction
2605+4: pax_close_userland
2606+ str r4, [sp, #S_PC] @ retry current instruction
2607 ret r9
2608 .popsection
2609 .pushsection __ex_table,"a"
2610@@ -766,7 +870,7 @@ ENTRY(__switch_to)
2611 THUMB( str lr, [ip], #4 )
2612 ldr r4, [r2, #TI_TP_VALUE]
2613 ldr r5, [r2, #TI_TP_VALUE + 4]
2614-#ifdef CONFIG_CPU_USE_DOMAINS
2615+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2616 ldr r6, [r2, #TI_CPU_DOMAIN]
2617 #endif
2618 switch_tls r1, r4, r5, r3, r7
2619@@ -775,7 +879,7 @@ ENTRY(__switch_to)
2620 ldr r8, =__stack_chk_guard
2621 ldr r7, [r7, #TSK_STACK_CANARY]
2622 #endif
2623-#ifdef CONFIG_CPU_USE_DOMAINS
2624+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2625 mcr p15, 0, r6, c3, c0, 0 @ Set domain register
2626 #endif
2627 mov r5, r0
2628diff --git a/arch/arm/kernel/entry-common.S b/arch/arm/kernel/entry-common.S
2629index 6bb09d4..113e875 100644
2630--- a/arch/arm/kernel/entry-common.S
2631+++ b/arch/arm/kernel/entry-common.S
2632@@ -11,18 +11,46 @@
2633 #include <asm/assembler.h>
2634 #include <asm/unistd.h>
2635 #include <asm/ftrace.h>
2636+#include <asm/domain.h>
2637 #include <asm/unwind.h>
2638
2639+#include "entry-header.S"
2640+
2641 #ifdef CONFIG_NEED_RET_TO_USER
2642 #include <mach/entry-macro.S>
2643 #else
2644 .macro arch_ret_to_user, tmp1, tmp2
2645+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2646+ @ save regs
2647+ stmdb sp!, {r1, r2}
2648+ @ read DACR from cpu_domain into r1
2649+ mov r2, sp
2650+ @ assume 8K pages, since we have to split the immediate in two
2651+ bic r2, r2, #(0x1fc0)
2652+ bic r2, r2, #(0x3f)
2653+ ldr r1, [r2, #TI_CPU_DOMAIN]
2654+#ifdef CONFIG_PAX_KERNEXEC
2655+ @ set type of DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2656+ bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2657+ orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2658+#endif
2659+#ifdef CONFIG_PAX_MEMORY_UDEREF
2660+ @ set current DOMAIN_USER to DOMAIN_UDEREF
2661+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2662+ orr r1, r1, #(domain_val(DOMAIN_USER, DOMAIN_UDEREF))
2663+#endif
2664+ @ write r1 to current_thread_info()->cpu_domain
2665+ str r1, [r2, #TI_CPU_DOMAIN]
2666+ @ write r1 to DACR
2667+ mcr p15, 0, r1, c3, c0, 0
2668+ @ instruction sync
2669+ instr_sync
2670+ @ restore regs
2671+ ldmia sp!, {r1, r2}
2672+#endif
2673 .endm
2674 #endif
2675
2676-#include "entry-header.S"
2677-
2678-
2679 .align 5
2680 /*
2681 * This is the fast syscall return path. We do as little as
2682@@ -406,6 +434,12 @@ ENTRY(vector_swi)
2683 USER( ldr scno, [lr, #-4] ) @ get SWI instruction
2684 #endif
2685
2686+ /*
2687+ * do this here to avoid a performance hit of wrapping the code above
2688+ * that directly dereferences userland to parse the SWI instruction
2689+ */
2690+ pax_enter_kernel_user
2691+
2692 adr tbl, sys_call_table @ load syscall table pointer
2693
2694 #if defined(CONFIG_OABI_COMPAT)
2695diff --git a/arch/arm/kernel/entry-header.S b/arch/arm/kernel/entry-header.S
2696index 4176df7..a901f8d 100644
2697--- a/arch/arm/kernel/entry-header.S
2698+++ b/arch/arm/kernel/entry-header.S
2699@@ -196,6 +196,60 @@
2700 msr cpsr_c, \rtemp @ switch back to the SVC mode
2701 .endm
2702
2703+ .macro pax_enter_kernel_user
2704+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2705+ @ save regs
2706+ stmdb sp!, {r0, r1}
2707+ @ read DACR from cpu_domain into r1
2708+ mov r0, sp
2709+ @ assume 8K pages, since we have to split the immediate in two
2710+ bic r0, r0, #(0x1fc0)
2711+ bic r0, r0, #(0x3f)
2712+ ldr r1, [r0, #TI_CPU_DOMAIN]
2713+#ifdef CONFIG_PAX_MEMORY_UDEREF
2714+ @ set current DOMAIN_USER to DOMAIN_NOACCESS
2715+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2716+#endif
2717+#ifdef CONFIG_PAX_KERNEXEC
2718+ @ set current DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2719+ bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2720+ orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2721+#endif
2722+ @ write r1 to current_thread_info()->cpu_domain
2723+ str r1, [r0, #TI_CPU_DOMAIN]
2724+ @ write r1 to DACR
2725+ mcr p15, 0, r1, c3, c0, 0
2726+ @ instruction sync
2727+ instr_sync
2728+ @ restore regs
2729+ ldmia sp!, {r0, r1}
2730+#endif
2731+ .endm
2732+
2733+ .macro pax_exit_kernel
2734+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2735+ @ save regs
2736+ stmdb sp!, {r0, r1}
2737+ @ read old DACR from stack into r1
2738+ ldr r1, [sp, #(8 + S_SP)]
2739+ sub r1, r1, #8
2740+ ldr r1, [r1]
2741+
2742+ @ write r1 to current_thread_info()->cpu_domain
2743+ mov r0, sp
2744+ @ assume 8K pages, since we have to split the immediate in two
2745+ bic r0, r0, #(0x1fc0)
2746+ bic r0, r0, #(0x3f)
2747+ str r1, [r0, #TI_CPU_DOMAIN]
2748+ @ write r1 to DACR
2749+ mcr p15, 0, r1, c3, c0, 0
2750+ @ instruction sync
2751+ instr_sync
2752+ @ restore regs
2753+ ldmia sp!, {r0, r1}
2754+#endif
2755+ .endm
2756+
2757 #ifndef CONFIG_THUMB2_KERNEL
2758 .macro svc_exit, rpsr, irq = 0
2759 .if \irq != 0
2760@@ -215,6 +269,9 @@
2761 blne trace_hardirqs_off
2762 #endif
2763 .endif
2764+
2765+ pax_exit_kernel
2766+
2767 msr spsr_cxsf, \rpsr
2768 #if defined(CONFIG_CPU_V6) || defined(CONFIG_CPU_32v6K)
2769 @ We must avoid clrex due to Cortex-A15 erratum #830321
2770@@ -290,6 +347,9 @@
2771 blne trace_hardirqs_off
2772 #endif
2773 .endif
2774+
2775+ pax_exit_kernel
2776+
2777 ldr lr, [sp, #S_SP] @ top of the stack
2778 ldrd r0, r1, [sp, #S_LR] @ calling lr and pc
2779
2780diff --git a/arch/arm/kernel/fiq.c b/arch/arm/kernel/fiq.c
2781index b37752a..ff5cb72 100644
2782--- a/arch/arm/kernel/fiq.c
2783+++ b/arch/arm/kernel/fiq.c
2784@@ -95,7 +95,10 @@ void set_fiq_handler(void *start, unsigned int length)
2785 void *base = vectors_page;
2786 unsigned offset = FIQ_OFFSET;
2787
2788+ pax_open_kernel();
2789 memcpy(base + offset, start, length);
2790+ pax_close_kernel();
2791+
2792 if (!cache_is_vipt_nonaliasing())
2793 flush_icache_range((unsigned long)base + offset, offset +
2794 length);
2795diff --git a/arch/arm/kernel/head.S b/arch/arm/kernel/head.S
2796index 664eee8..f470938 100644
2797--- a/arch/arm/kernel/head.S
2798+++ b/arch/arm/kernel/head.S
2799@@ -437,7 +437,7 @@ __enable_mmu:
2800 mov r5, #(domain_val(DOMAIN_USER, DOMAIN_MANAGER) | \
2801 domain_val(DOMAIN_KERNEL, DOMAIN_MANAGER) | \
2802 domain_val(DOMAIN_TABLE, DOMAIN_MANAGER) | \
2803- domain_val(DOMAIN_IO, DOMAIN_CLIENT))
2804+ domain_val(DOMAIN_IO, DOMAIN_KERNELCLIENT))
2805 mcr p15, 0, r5, c3, c0, 0 @ load domain access register
2806 mcr p15, 0, r4, c2, c0, 0 @ load page table pointer
2807 #endif
2808diff --git a/arch/arm/kernel/module.c b/arch/arm/kernel/module.c
2809index 6a4dffe..4a86a70 100644
2810--- a/arch/arm/kernel/module.c
2811+++ b/arch/arm/kernel/module.c
2812@@ -38,12 +38,39 @@
2813 #endif
2814
2815 #ifdef CONFIG_MMU
2816-void *module_alloc(unsigned long size)
2817+static inline void *__module_alloc(unsigned long size, pgprot_t prot)
2818 {
2819+ if (!size || PAGE_ALIGN(size) > MODULES_END - MODULES_VADDR)
2820+ return NULL;
2821 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
2822- GFP_KERNEL, PAGE_KERNEL_EXEC, NUMA_NO_NODE,
2823+ GFP_KERNEL, prot, NUMA_NO_NODE,
2824 __builtin_return_address(0));
2825 }
2826+
2827+void *module_alloc(unsigned long size)
2828+{
2829+
2830+#ifdef CONFIG_PAX_KERNEXEC
2831+ return __module_alloc(size, PAGE_KERNEL);
2832+#else
2833+ return __module_alloc(size, PAGE_KERNEL_EXEC);
2834+#endif
2835+
2836+}
2837+
2838+#ifdef CONFIG_PAX_KERNEXEC
2839+void module_free_exec(struct module *mod, void *module_region)
2840+{
2841+ module_free(mod, module_region);
2842+}
2843+EXPORT_SYMBOL(module_free_exec);
2844+
2845+void *module_alloc_exec(unsigned long size)
2846+{
2847+ return __module_alloc(size, PAGE_KERNEL_EXEC);
2848+}
2849+EXPORT_SYMBOL(module_alloc_exec);
2850+#endif
2851 #endif
2852
2853 int
2854diff --git a/arch/arm/kernel/patch.c b/arch/arm/kernel/patch.c
2855index 07314af..c46655c 100644
2856--- a/arch/arm/kernel/patch.c
2857+++ b/arch/arm/kernel/patch.c
2858@@ -18,6 +18,7 @@ void __kprobes __patch_text(void *addr, unsigned int insn)
2859 bool thumb2 = IS_ENABLED(CONFIG_THUMB2_KERNEL);
2860 int size;
2861
2862+ pax_open_kernel();
2863 if (thumb2 && __opcode_is_thumb16(insn)) {
2864 *(u16 *)addr = __opcode_to_mem_thumb16(insn);
2865 size = sizeof(u16);
2866@@ -39,6 +40,7 @@ void __kprobes __patch_text(void *addr, unsigned int insn)
2867 *(u32 *)addr = insn;
2868 size = sizeof(u32);
2869 }
2870+ pax_close_kernel();
2871
2872 flush_icache_range((uintptr_t)(addr),
2873 (uintptr_t)(addr) + size);
2874diff --git a/arch/arm/kernel/process.c b/arch/arm/kernel/process.c
2875index fe972a2..a772d83 100644
2876--- a/arch/arm/kernel/process.c
2877+++ b/arch/arm/kernel/process.c
2878@@ -207,6 +207,7 @@ void machine_power_off(void)
2879
2880 if (pm_power_off)
2881 pm_power_off();
2882+ BUG();
2883 }
2884
2885 /*
2886@@ -220,7 +221,7 @@ void machine_power_off(void)
2887 * executing pre-reset code, and using RAM that the primary CPU's code wishes
2888 * to use. Implementing such co-ordination would be essentially impossible.
2889 */
2890-void machine_restart(char *cmd)
2891+__noreturn void machine_restart(char *cmd)
2892 {
2893 local_irq_disable();
2894 smp_send_stop();
2895@@ -246,8 +247,8 @@ void __show_regs(struct pt_regs *regs)
2896
2897 show_regs_print_info(KERN_DEFAULT);
2898
2899- print_symbol("PC is at %s\n", instruction_pointer(regs));
2900- print_symbol("LR is at %s\n", regs->ARM_lr);
2901+ printk("PC is at %pA\n", (void *)instruction_pointer(regs));
2902+ printk("LR is at %pA\n", (void *)regs->ARM_lr);
2903 printk("pc : [<%08lx>] lr : [<%08lx>] psr: %08lx\n"
2904 "sp : %08lx ip : %08lx fp : %08lx\n",
2905 regs->ARM_pc, regs->ARM_lr, regs->ARM_cpsr,
2906@@ -424,12 +425,6 @@ unsigned long get_wchan(struct task_struct *p)
2907 return 0;
2908 }
2909
2910-unsigned long arch_randomize_brk(struct mm_struct *mm)
2911-{
2912- unsigned long range_end = mm->brk + 0x02000000;
2913- return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
2914-}
2915-
2916 #ifdef CONFIG_MMU
2917 #ifdef CONFIG_KUSER_HELPERS
2918 /*
2919@@ -445,7 +440,7 @@ static struct vm_area_struct gate_vma = {
2920
2921 static int __init gate_vma_init(void)
2922 {
2923- gate_vma.vm_page_prot = PAGE_READONLY_EXEC;
2924+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
2925 return 0;
2926 }
2927 arch_initcall(gate_vma_init);
2928@@ -474,81 +469,13 @@ const char *arch_vma_name(struct vm_area_struct *vma)
2929 return is_gate_vma(vma) ? "[vectors]" : NULL;
2930 }
2931
2932-/* If possible, provide a placement hint at a random offset from the
2933- * stack for the signal page.
2934- */
2935-static unsigned long sigpage_addr(const struct mm_struct *mm,
2936- unsigned int npages)
2937-{
2938- unsigned long offset;
2939- unsigned long first;
2940- unsigned long last;
2941- unsigned long addr;
2942- unsigned int slots;
2943-
2944- first = PAGE_ALIGN(mm->start_stack);
2945-
2946- last = TASK_SIZE - (npages << PAGE_SHIFT);
2947-
2948- /* No room after stack? */
2949- if (first > last)
2950- return 0;
2951-
2952- /* Just enough room? */
2953- if (first == last)
2954- return first;
2955-
2956- slots = ((last - first) >> PAGE_SHIFT) + 1;
2957-
2958- offset = get_random_int() % slots;
2959-
2960- addr = first + (offset << PAGE_SHIFT);
2961-
2962- return addr;
2963-}
2964-
2965-static struct page *signal_page;
2966-extern struct page *get_signal_page(void);
2967-
2968-static const struct vm_special_mapping sigpage_mapping = {
2969- .name = "[sigpage]",
2970- .pages = &signal_page,
2971-};
2972-
2973 int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
2974 {
2975 struct mm_struct *mm = current->mm;
2976- struct vm_area_struct *vma;
2977- unsigned long addr;
2978- unsigned long hint;
2979- int ret = 0;
2980-
2981- if (!signal_page)
2982- signal_page = get_signal_page();
2983- if (!signal_page)
2984- return -ENOMEM;
2985
2986 down_write(&mm->mmap_sem);
2987- hint = sigpage_addr(mm, 1);
2988- addr = get_unmapped_area(NULL, hint, PAGE_SIZE, 0, 0);
2989- if (IS_ERR_VALUE(addr)) {
2990- ret = addr;
2991- goto up_fail;
2992- }
2993-
2994- vma = _install_special_mapping(mm, addr, PAGE_SIZE,
2995- VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC,
2996- &sigpage_mapping);
2997-
2998- if (IS_ERR(vma)) {
2999- ret = PTR_ERR(vma);
3000- goto up_fail;
3001- }
3002-
3003- mm->context.sigpage = addr;
3004-
3005- up_fail:
3006+ mm->context.sigpage = (PAGE_OFFSET + (get_random_int() % 0x3FFEFFE0)) & 0xFFFFFFFC;
3007 up_write(&mm->mmap_sem);
3008- return ret;
3009+ return 0;
3010 }
3011 #endif
3012diff --git a/arch/arm/kernel/psci.c b/arch/arm/kernel/psci.c
3013index f73891b..cf3004e 100644
3014--- a/arch/arm/kernel/psci.c
3015+++ b/arch/arm/kernel/psci.c
3016@@ -28,7 +28,7 @@
3017 #include <asm/psci.h>
3018 #include <asm/system_misc.h>
3019
3020-struct psci_operations psci_ops;
3021+struct psci_operations psci_ops __read_only;
3022
3023 static int (*invoke_psci_fn)(u32, u32, u32, u32);
3024 typedef int (*psci_initcall_t)(const struct device_node *);
3025diff --git a/arch/arm/kernel/ptrace.c b/arch/arm/kernel/ptrace.c
3026index ef9119f..31995a3 100644
3027--- a/arch/arm/kernel/ptrace.c
3028+++ b/arch/arm/kernel/ptrace.c
3029@@ -928,10 +928,19 @@ static void tracehook_report_syscall(struct pt_regs *regs,
3030 regs->ARM_ip = ip;
3031 }
3032
3033+#ifdef CONFIG_GRKERNSEC_SETXID
3034+extern void gr_delayed_cred_worker(void);
3035+#endif
3036+
3037 asmlinkage int syscall_trace_enter(struct pt_regs *regs, int scno)
3038 {
3039 current_thread_info()->syscall = scno;
3040
3041+#ifdef CONFIG_GRKERNSEC_SETXID
3042+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
3043+ gr_delayed_cred_worker();
3044+#endif
3045+
3046 /* Do the secure computing check first; failures should be fast. */
3047 #ifdef CONFIG_HAVE_ARCH_SECCOMP_FILTER
3048 if (secure_computing() == -1)
3049diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c
3050index 306e1ac..1b477ed 100644
3051--- a/arch/arm/kernel/setup.c
3052+++ b/arch/arm/kernel/setup.c
3053@@ -104,21 +104,23 @@ EXPORT_SYMBOL(elf_hwcap);
3054 unsigned int elf_hwcap2 __read_mostly;
3055 EXPORT_SYMBOL(elf_hwcap2);
3056
3057+pteval_t __supported_pte_mask __read_only;
3058+pmdval_t __supported_pmd_mask __read_only;
3059
3060 #ifdef MULTI_CPU
3061-struct processor processor __read_mostly;
3062+struct processor processor __read_only;
3063 #endif
3064 #ifdef MULTI_TLB
3065-struct cpu_tlb_fns cpu_tlb __read_mostly;
3066+struct cpu_tlb_fns cpu_tlb __read_only;
3067 #endif
3068 #ifdef MULTI_USER
3069-struct cpu_user_fns cpu_user __read_mostly;
3070+struct cpu_user_fns cpu_user __read_only;
3071 #endif
3072 #ifdef MULTI_CACHE
3073-struct cpu_cache_fns cpu_cache __read_mostly;
3074+struct cpu_cache_fns cpu_cache __read_only;
3075 #endif
3076 #ifdef CONFIG_OUTER_CACHE
3077-struct outer_cache_fns outer_cache __read_mostly;
3078+struct outer_cache_fns outer_cache __read_only;
3079 EXPORT_SYMBOL(outer_cache);
3080 #endif
3081
3082@@ -252,9 +254,13 @@ static int __get_cpu_architecture(void)
3083 asm("mrc p15, 0, %0, c0, c1, 4"
3084 : "=r" (mmfr0));
3085 if ((mmfr0 & 0x0000000f) >= 0x00000003 ||
3086- (mmfr0 & 0x000000f0) >= 0x00000030)
3087+ (mmfr0 & 0x000000f0) >= 0x00000030) {
3088 cpu_arch = CPU_ARCH_ARMv7;
3089- else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
3090+ if ((mmfr0 & 0x0000000f) == 0x00000005 || (mmfr0 & 0x0000000f) == 0x00000004) {
3091+ __supported_pte_mask |= L_PTE_PXN;
3092+ __supported_pmd_mask |= PMD_PXNTABLE;
3093+ }
3094+ } else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
3095 (mmfr0 & 0x000000f0) == 0x00000020)
3096 cpu_arch = CPU_ARCH_ARMv6;
3097 else
3098diff --git a/arch/arm/kernel/signal.c b/arch/arm/kernel/signal.c
3099index bd19834..e4d8c66 100644
3100--- a/arch/arm/kernel/signal.c
3101+++ b/arch/arm/kernel/signal.c
3102@@ -24,8 +24,6 @@
3103
3104 extern const unsigned long sigreturn_codes[7];
3105
3106-static unsigned long signal_return_offset;
3107-
3108 #ifdef CONFIG_CRUNCH
3109 static int preserve_crunch_context(struct crunch_sigframe __user *frame)
3110 {
3111@@ -396,8 +394,7 @@ setup_return(struct pt_regs *regs, struct ksignal *ksig,
3112 * except when the MPU has protected the vectors
3113 * page from PL0
3114 */
3115- retcode = mm->context.sigpage + signal_return_offset +
3116- (idx << 2) + thumb;
3117+ retcode = mm->context.sigpage + (idx << 2) + thumb;
3118 } else
3119 #endif
3120 {
3121@@ -604,33 +601,3 @@ do_work_pending(struct pt_regs *regs, unsigned int thread_flags, int syscall)
3122 } while (thread_flags & _TIF_WORK_MASK);
3123 return 0;
3124 }
3125-
3126-struct page *get_signal_page(void)
3127-{
3128- unsigned long ptr;
3129- unsigned offset;
3130- struct page *page;
3131- void *addr;
3132-
3133- page = alloc_pages(GFP_KERNEL, 0);
3134-
3135- if (!page)
3136- return NULL;
3137-
3138- addr = page_address(page);
3139-
3140- /* Give the signal return code some randomness */
3141- offset = 0x200 + (get_random_int() & 0x7fc);
3142- signal_return_offset = offset;
3143-
3144- /*
3145- * Copy signal return handlers into the vector page, and
3146- * set sigreturn to be a pointer to these.
3147- */
3148- memcpy(addr + offset, sigreturn_codes, sizeof(sigreturn_codes));
3149-
3150- ptr = (unsigned long)addr + offset;
3151- flush_icache_range(ptr, ptr + sizeof(sigreturn_codes));
3152-
3153- return page;
3154-}
3155diff --git a/arch/arm/kernel/smp.c b/arch/arm/kernel/smp.c
3156index a8e32aa..b2f7198 100644
3157--- a/arch/arm/kernel/smp.c
3158+++ b/arch/arm/kernel/smp.c
3159@@ -76,7 +76,7 @@ enum ipi_msg_type {
3160
3161 static DECLARE_COMPLETION(cpu_running);
3162
3163-static struct smp_operations smp_ops;
3164+static struct smp_operations smp_ops __read_only;
3165
3166 void __init smp_set_ops(struct smp_operations *ops)
3167 {
3168diff --git a/arch/arm/kernel/tcm.c b/arch/arm/kernel/tcm.c
3169index 7a3be1d..b00c7de 100644
3170--- a/arch/arm/kernel/tcm.c
3171+++ b/arch/arm/kernel/tcm.c
3172@@ -61,7 +61,7 @@ static struct map_desc itcm_iomap[] __initdata = {
3173 .virtual = ITCM_OFFSET,
3174 .pfn = __phys_to_pfn(ITCM_OFFSET),
3175 .length = 0,
3176- .type = MT_MEMORY_RWX_ITCM,
3177+ .type = MT_MEMORY_RX_ITCM,
3178 }
3179 };
3180
3181@@ -267,7 +267,9 @@ no_dtcm:
3182 start = &__sitcm_text;
3183 end = &__eitcm_text;
3184 ram = &__itcm_start;
3185+ pax_open_kernel();
3186 memcpy(start, ram, itcm_code_sz);
3187+ pax_close_kernel();
3188 pr_debug("CPU ITCM: copied code from %p - %p\n",
3189 start, end);
3190 itcm_present = true;
3191diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c
3192index 9f5d818..e013427 100644
3193--- a/arch/arm/kernel/traps.c
3194+++ b/arch/arm/kernel/traps.c
3195@@ -65,7 +65,7 @@ static void dump_mem(const char *, const char *, unsigned long, unsigned long);
3196 void dump_backtrace_entry(unsigned long where, unsigned long from, unsigned long frame)
3197 {
3198 #ifdef CONFIG_KALLSYMS
3199- printk("[<%08lx>] (%ps) from [<%08lx>] (%pS)\n", where, (void *)where, from, (void *)from);
3200+ printk("[<%08lx>] (%pA) from [<%08lx>] (%pA)\n", where, (void *)where, from, (void *)from);
3201 #else
3202 printk("Function entered at [<%08lx>] from [<%08lx>]\n", where, from);
3203 #endif
3204@@ -267,6 +267,8 @@ static arch_spinlock_t die_lock = __ARCH_SPIN_LOCK_UNLOCKED;
3205 static int die_owner = -1;
3206 static unsigned int die_nest_count;
3207
3208+extern void gr_handle_kernel_exploit(void);
3209+
3210 static unsigned long oops_begin(void)
3211 {
3212 int cpu;
3213@@ -309,6 +311,9 @@ static void oops_end(unsigned long flags, struct pt_regs *regs, int signr)
3214 panic("Fatal exception in interrupt");
3215 if (panic_on_oops)
3216 panic("Fatal exception");
3217+
3218+ gr_handle_kernel_exploit();
3219+
3220 if (signr)
3221 do_exit(signr);
3222 }
3223@@ -880,7 +885,11 @@ void __init early_trap_init(void *vectors_base)
3224 kuser_init(vectors_base);
3225
3226 flush_icache_range(vectors, vectors + PAGE_SIZE * 2);
3227- modify_domain(DOMAIN_USER, DOMAIN_CLIENT);
3228+
3229+#ifndef CONFIG_PAX_MEMORY_UDEREF
3230+ modify_domain(DOMAIN_USER, DOMAIN_USERCLIENT);
3231+#endif
3232+
3233 #else /* ifndef CONFIG_CPU_V7M */
3234 /*
3235 * on V7-M there is no need to copy the vector table to a dedicated
3236diff --git a/arch/arm/kernel/vmlinux.lds.S b/arch/arm/kernel/vmlinux.lds.S
3237index 8e95aa4..595dfc8 100644
3238--- a/arch/arm/kernel/vmlinux.lds.S
3239+++ b/arch/arm/kernel/vmlinux.lds.S
3240@@ -8,7 +8,11 @@
3241 #include <asm/thread_info.h>
3242 #include <asm/memory.h>
3243 #include <asm/page.h>
3244-
3245+
3246+#ifdef CONFIG_PAX_KERNEXEC
3247+#include <asm/pgtable.h>
3248+#endif
3249+
3250 #define PROC_INFO \
3251 . = ALIGN(4); \
3252 VMLINUX_SYMBOL(__proc_info_begin) = .; \
3253@@ -34,7 +38,7 @@
3254 #endif
3255
3256 #if (defined(CONFIG_SMP_ON_UP) && !defined(CONFIG_DEBUG_SPINLOCK)) || \
3257- defined(CONFIG_GENERIC_BUG)
3258+ defined(CONFIG_GENERIC_BUG) || defined(CONFIG_PAX_REFCOUNT)
3259 #define ARM_EXIT_KEEP(x) x
3260 #define ARM_EXIT_DISCARD(x)
3261 #else
3262@@ -90,6 +94,11 @@ SECTIONS
3263 _text = .;
3264 HEAD_TEXT
3265 }
3266+
3267+#ifdef CONFIG_PAX_KERNEXEC
3268+ . = ALIGN(1<<SECTION_SHIFT);
3269+#endif
3270+
3271 .text : { /* Real text segment */
3272 _stext = .; /* Text and read-only data */
3273 __exception_text_start = .;
3274@@ -112,6 +121,8 @@ SECTIONS
3275 ARM_CPU_KEEP(PROC_INFO)
3276 }
3277
3278+ _etext = .; /* End of text section */
3279+
3280 RO_DATA(PAGE_SIZE)
3281
3282 . = ALIGN(4);
3283@@ -142,7 +153,9 @@ SECTIONS
3284
3285 NOTES
3286
3287- _etext = .; /* End of text and rodata section */
3288+#ifdef CONFIG_PAX_KERNEXEC
3289+ . = ALIGN(1<<SECTION_SHIFT);
3290+#endif
3291
3292 #ifndef CONFIG_XIP_KERNEL
3293 . = ALIGN(PAGE_SIZE);
3294@@ -221,6 +234,11 @@ SECTIONS
3295 #else
3296 . = ALIGN(THREAD_SIZE);
3297 __init_end = .;
3298+
3299+#ifdef CONFIG_PAX_KERNEXEC
3300+ . = ALIGN(1<<SECTION_SHIFT);
3301+#endif
3302+
3303 __data_loc = .;
3304 #endif
3305
3306diff --git a/arch/arm/kvm/arm.c b/arch/arm/kvm/arm.c
3307index 9e193c8..3560fe6 100644
3308--- a/arch/arm/kvm/arm.c
3309+++ b/arch/arm/kvm/arm.c
3310@@ -57,7 +57,7 @@ static unsigned long hyp_default_vectors;
3311 static DEFINE_PER_CPU(struct kvm_vcpu *, kvm_arm_running_vcpu);
3312
3313 /* The VMID used in the VTTBR */
3314-static atomic64_t kvm_vmid_gen = ATOMIC64_INIT(1);
3315+static atomic64_unchecked_t kvm_vmid_gen = ATOMIC64_INIT(1);
3316 static u8 kvm_next_vmid;
3317 static DEFINE_SPINLOCK(kvm_vmid_lock);
3318
3319@@ -354,7 +354,7 @@ void force_vm_exit(const cpumask_t *mask)
3320 */
3321 static bool need_new_vmid_gen(struct kvm *kvm)
3322 {
3323- return unlikely(kvm->arch.vmid_gen != atomic64_read(&kvm_vmid_gen));
3324+ return unlikely(kvm->arch.vmid_gen != atomic64_read_unchecked(&kvm_vmid_gen));
3325 }
3326
3327 /**
3328@@ -387,7 +387,7 @@ static void update_vttbr(struct kvm *kvm)
3329
3330 /* First user of a new VMID generation? */
3331 if (unlikely(kvm_next_vmid == 0)) {
3332- atomic64_inc(&kvm_vmid_gen);
3333+ atomic64_inc_unchecked(&kvm_vmid_gen);
3334 kvm_next_vmid = 1;
3335
3336 /*
3337@@ -404,7 +404,7 @@ static void update_vttbr(struct kvm *kvm)
3338 kvm_call_hyp(__kvm_flush_vm_context);
3339 }
3340
3341- kvm->arch.vmid_gen = atomic64_read(&kvm_vmid_gen);
3342+ kvm->arch.vmid_gen = atomic64_read_unchecked(&kvm_vmid_gen);
3343 kvm->arch.vmid = kvm_next_vmid;
3344 kvm_next_vmid++;
3345
3346@@ -980,7 +980,7 @@ static void check_kvm_target_cpu(void *ret)
3347 /**
3348 * Initialize Hyp-mode and memory mappings on all CPUs.
3349 */
3350-int kvm_arch_init(void *opaque)
3351+int kvm_arch_init(const void *opaque)
3352 {
3353 int err;
3354 int ret, cpu;
3355diff --git a/arch/arm/lib/clear_user.S b/arch/arm/lib/clear_user.S
3356index 14a0d98..7771a7d 100644
3357--- a/arch/arm/lib/clear_user.S
3358+++ b/arch/arm/lib/clear_user.S
3359@@ -12,14 +12,14 @@
3360
3361 .text
3362
3363-/* Prototype: int __clear_user(void *addr, size_t sz)
3364+/* Prototype: int ___clear_user(void *addr, size_t sz)
3365 * Purpose : clear some user memory
3366 * Params : addr - user memory address to clear
3367 * : sz - number of bytes to clear
3368 * Returns : number of bytes NOT cleared
3369 */
3370 ENTRY(__clear_user_std)
3371-WEAK(__clear_user)
3372+WEAK(___clear_user)
3373 stmfd sp!, {r1, lr}
3374 mov r2, #0
3375 cmp r1, #4
3376@@ -44,7 +44,7 @@ WEAK(__clear_user)
3377 USER( strnebt r2, [r0])
3378 mov r0, #0
3379 ldmfd sp!, {r1, pc}
3380-ENDPROC(__clear_user)
3381+ENDPROC(___clear_user)
3382 ENDPROC(__clear_user_std)
3383
3384 .pushsection .fixup,"ax"
3385diff --git a/arch/arm/lib/copy_from_user.S b/arch/arm/lib/copy_from_user.S
3386index 66a477a..bee61d3 100644
3387--- a/arch/arm/lib/copy_from_user.S
3388+++ b/arch/arm/lib/copy_from_user.S
3389@@ -16,7 +16,7 @@
3390 /*
3391 * Prototype:
3392 *
3393- * size_t __copy_from_user(void *to, const void *from, size_t n)
3394+ * size_t ___copy_from_user(void *to, const void *from, size_t n)
3395 *
3396 * Purpose:
3397 *
3398@@ -84,11 +84,11 @@
3399
3400 .text
3401
3402-ENTRY(__copy_from_user)
3403+ENTRY(___copy_from_user)
3404
3405 #include "copy_template.S"
3406
3407-ENDPROC(__copy_from_user)
3408+ENDPROC(___copy_from_user)
3409
3410 .pushsection .fixup,"ax"
3411 .align 0
3412diff --git a/arch/arm/lib/copy_page.S b/arch/arm/lib/copy_page.S
3413index 6ee2f67..d1cce76 100644
3414--- a/arch/arm/lib/copy_page.S
3415+++ b/arch/arm/lib/copy_page.S
3416@@ -10,6 +10,7 @@
3417 * ASM optimised string functions
3418 */
3419 #include <linux/linkage.h>
3420+#include <linux/const.h>
3421 #include <asm/assembler.h>
3422 #include <asm/asm-offsets.h>
3423 #include <asm/cache.h>
3424diff --git a/arch/arm/lib/copy_to_user.S b/arch/arm/lib/copy_to_user.S
3425index d066df6..df28194 100644
3426--- a/arch/arm/lib/copy_to_user.S
3427+++ b/arch/arm/lib/copy_to_user.S
3428@@ -16,7 +16,7 @@
3429 /*
3430 * Prototype:
3431 *
3432- * size_t __copy_to_user(void *to, const void *from, size_t n)
3433+ * size_t ___copy_to_user(void *to, const void *from, size_t n)
3434 *
3435 * Purpose:
3436 *
3437@@ -88,11 +88,11 @@
3438 .text
3439
3440 ENTRY(__copy_to_user_std)
3441-WEAK(__copy_to_user)
3442+WEAK(___copy_to_user)
3443
3444 #include "copy_template.S"
3445
3446-ENDPROC(__copy_to_user)
3447+ENDPROC(___copy_to_user)
3448 ENDPROC(__copy_to_user_std)
3449
3450 .pushsection .fixup,"ax"
3451diff --git a/arch/arm/lib/csumpartialcopyuser.S b/arch/arm/lib/csumpartialcopyuser.S
3452index 7d08b43..f7ca7ea 100644
3453--- a/arch/arm/lib/csumpartialcopyuser.S
3454+++ b/arch/arm/lib/csumpartialcopyuser.S
3455@@ -57,8 +57,8 @@
3456 * Returns : r0 = checksum, [[sp, #0], #0] = 0 or -EFAULT
3457 */
3458
3459-#define FN_ENTRY ENTRY(csum_partial_copy_from_user)
3460-#define FN_EXIT ENDPROC(csum_partial_copy_from_user)
3461+#define FN_ENTRY ENTRY(__csum_partial_copy_from_user)
3462+#define FN_EXIT ENDPROC(__csum_partial_copy_from_user)
3463
3464 #include "csumpartialcopygeneric.S"
3465
3466diff --git a/arch/arm/lib/delay.c b/arch/arm/lib/delay.c
3467index 312d43e..21d2322 100644
3468--- a/arch/arm/lib/delay.c
3469+++ b/arch/arm/lib/delay.c
3470@@ -29,7 +29,7 @@
3471 /*
3472 * Default to the loop-based delay implementation.
3473 */
3474-struct arm_delay_ops arm_delay_ops = {
3475+struct arm_delay_ops arm_delay_ops __read_only = {
3476 .delay = __loop_delay,
3477 .const_udelay = __loop_const_udelay,
3478 .udelay = __loop_udelay,
3479diff --git a/arch/arm/lib/uaccess_with_memcpy.c b/arch/arm/lib/uaccess_with_memcpy.c
3480index 3e58d71..029817c 100644
3481--- a/arch/arm/lib/uaccess_with_memcpy.c
3482+++ b/arch/arm/lib/uaccess_with_memcpy.c
3483@@ -136,7 +136,7 @@ out:
3484 }
3485
3486 unsigned long
3487-__copy_to_user(void __user *to, const void *from, unsigned long n)
3488+___copy_to_user(void __user *to, const void *from, unsigned long n)
3489 {
3490 /*
3491 * This test is stubbed out of the main function above to keep
3492@@ -190,7 +190,7 @@ out:
3493 return n;
3494 }
3495
3496-unsigned long __clear_user(void __user *addr, unsigned long n)
3497+unsigned long ___clear_user(void __user *addr, unsigned long n)
3498 {
3499 /* See rational for this in __copy_to_user() above. */
3500 if (n < 64)
3501diff --git a/arch/arm/mach-at91/setup.c b/arch/arm/mach-at91/setup.c
3502index 9610792..4dfb851 100644
3503--- a/arch/arm/mach-at91/setup.c
3504+++ b/arch/arm/mach-at91/setup.c
3505@@ -83,7 +83,7 @@ void __init at91_init_sram(int bank, unsigned long base, unsigned int length)
3506
3507 desc->pfn = __phys_to_pfn(base);
3508 desc->length = length;
3509- desc->type = MT_MEMORY_RWX_NONCACHED;
3510+ desc->type = MT_MEMORY_RW_NONCACHED;
3511
3512 pr_info("sram at 0x%lx of 0x%x mapped at 0x%lx\n",
3513 base, length, desc->virtual);
3514diff --git a/arch/arm/mach-keystone/keystone.c b/arch/arm/mach-keystone/keystone.c
3515index 7f352de..6dc0929 100644
3516--- a/arch/arm/mach-keystone/keystone.c
3517+++ b/arch/arm/mach-keystone/keystone.c
3518@@ -27,7 +27,7 @@
3519
3520 #include "keystone.h"
3521
3522-static struct notifier_block platform_nb;
3523+static notifier_block_no_const platform_nb;
3524 static unsigned long keystone_dma_pfn_offset __read_mostly;
3525
3526 static int keystone_platform_notifier(struct notifier_block *nb,
3527diff --git a/arch/arm/mach-mvebu/coherency.c b/arch/arm/mach-mvebu/coherency.c
3528index c31f4c0..c86224d 100644
3529--- a/arch/arm/mach-mvebu/coherency.c
3530+++ b/arch/arm/mach-mvebu/coherency.c
3531@@ -316,7 +316,7 @@ static void __init armada_370_coherency_init(struct device_node *np)
3532
3533 /*
3534 * This ioremap hook is used on Armada 375/38x to ensure that PCIe
3535- * memory areas are mapped as MT_UNCACHED instead of MT_DEVICE. This
3536+ * memory areas are mapped as MT_UNCACHED_RW instead of MT_DEVICE. This
3537 * is needed as a workaround for a deadlock issue between the PCIe
3538 * interface and the cache controller.
3539 */
3540@@ -329,7 +329,7 @@ armada_pcie_wa_ioremap_caller(phys_addr_t phys_addr, size_t size,
3541 mvebu_mbus_get_pcie_mem_aperture(&pcie_mem);
3542
3543 if (pcie_mem.start <= phys_addr && (phys_addr + size) <= pcie_mem.end)
3544- mtype = MT_UNCACHED;
3545+ mtype = MT_UNCACHED_RW;
3546
3547 return __arm_ioremap_caller(phys_addr, size, mtype, caller);
3548 }
3549diff --git a/arch/arm/mach-omap2/board-n8x0.c b/arch/arm/mach-omap2/board-n8x0.c
3550index 97767a2..9233746 100644
3551--- a/arch/arm/mach-omap2/board-n8x0.c
3552+++ b/arch/arm/mach-omap2/board-n8x0.c
3553@@ -569,7 +569,7 @@ static int n8x0_menelaus_late_init(struct device *dev)
3554 }
3555 #endif
3556
3557-struct menelaus_platform_data n8x0_menelaus_platform_data __initdata = {
3558+struct menelaus_platform_data n8x0_menelaus_platform_data __initconst = {
3559 .late_init = n8x0_menelaus_late_init,
3560 };
3561
3562diff --git a/arch/arm/mach-omap2/gpmc.c b/arch/arm/mach-omap2/gpmc.c
3563index 5fa3755..1e8c247 100644
3564--- a/arch/arm/mach-omap2/gpmc.c
3565+++ b/arch/arm/mach-omap2/gpmc.c
3566@@ -151,7 +151,6 @@ struct omap3_gpmc_regs {
3567 };
3568
3569 static struct gpmc_client_irq gpmc_client_irq[GPMC_NR_IRQ];
3570-static struct irq_chip gpmc_irq_chip;
3571 static int gpmc_irq_start;
3572
3573 static struct resource gpmc_mem_root;
3574@@ -736,6 +735,18 @@ static void gpmc_irq_noop(struct irq_data *data) { }
3575
3576 static unsigned int gpmc_irq_noop_ret(struct irq_data *data) { return 0; }
3577
3578+static struct irq_chip gpmc_irq_chip = {
3579+ .name = "gpmc",
3580+ .irq_startup = gpmc_irq_noop_ret,
3581+ .irq_enable = gpmc_irq_enable,
3582+ .irq_disable = gpmc_irq_disable,
3583+ .irq_shutdown = gpmc_irq_noop,
3584+ .irq_ack = gpmc_irq_noop,
3585+ .irq_mask = gpmc_irq_noop,
3586+ .irq_unmask = gpmc_irq_noop,
3587+
3588+};
3589+
3590 static int gpmc_setup_irq(void)
3591 {
3592 int i;
3593@@ -750,15 +761,6 @@ static int gpmc_setup_irq(void)
3594 return gpmc_irq_start;
3595 }
3596
3597- gpmc_irq_chip.name = "gpmc";
3598- gpmc_irq_chip.irq_startup = gpmc_irq_noop_ret;
3599- gpmc_irq_chip.irq_enable = gpmc_irq_enable;
3600- gpmc_irq_chip.irq_disable = gpmc_irq_disable;
3601- gpmc_irq_chip.irq_shutdown = gpmc_irq_noop;
3602- gpmc_irq_chip.irq_ack = gpmc_irq_noop;
3603- gpmc_irq_chip.irq_mask = gpmc_irq_noop;
3604- gpmc_irq_chip.irq_unmask = gpmc_irq_noop;
3605-
3606 gpmc_client_irq[0].bitmask = GPMC_IRQ_FIFOEVENTENABLE;
3607 gpmc_client_irq[1].bitmask = GPMC_IRQ_COUNT_EVENT;
3608
3609diff --git a/arch/arm/mach-omap2/omap-mpuss-lowpower.c b/arch/arm/mach-omap2/omap-mpuss-lowpower.c
3610index 6944ae3..bc587ca 100644
3611--- a/arch/arm/mach-omap2/omap-mpuss-lowpower.c
3612+++ b/arch/arm/mach-omap2/omap-mpuss-lowpower.c
3613@@ -86,7 +86,7 @@ struct cpu_pm_ops {
3614 void (*resume)(void);
3615 void (*scu_prepare)(unsigned int cpu_id, unsigned int cpu_state);
3616 void (*hotplug_restart)(void);
3617-};
3618+} __no_const;
3619
3620 static DEFINE_PER_CPU(struct omap4_cpu_pm_info, omap4_pm_info);
3621 static struct powerdomain *mpuss_pd;
3622@@ -105,7 +105,7 @@ static void dummy_cpu_resume(void)
3623 static void dummy_scu_prepare(unsigned int cpu_id, unsigned int cpu_state)
3624 {}
3625
3626-struct cpu_pm_ops omap_pm_ops = {
3627+static struct cpu_pm_ops omap_pm_ops __read_only = {
3628 .finish_suspend = default_finish_suspend,
3629 .resume = dummy_cpu_resume,
3630 .scu_prepare = dummy_scu_prepare,
3631diff --git a/arch/arm/mach-omap2/omap-wakeupgen.c b/arch/arm/mach-omap2/omap-wakeupgen.c
3632index f961c46..4a453dc 100644
3633--- a/arch/arm/mach-omap2/omap-wakeupgen.c
3634+++ b/arch/arm/mach-omap2/omap-wakeupgen.c
3635@@ -344,7 +344,7 @@ static int irq_cpu_hotplug_notify(struct notifier_block *self,
3636 return NOTIFY_OK;
3637 }
3638
3639-static struct notifier_block __refdata irq_hotplug_notifier = {
3640+static struct notifier_block irq_hotplug_notifier = {
3641 .notifier_call = irq_cpu_hotplug_notify,
3642 };
3643
3644diff --git a/arch/arm/mach-omap2/omap_device.c b/arch/arm/mach-omap2/omap_device.c
3645index 8c58b71..95b655f 100644
3646--- a/arch/arm/mach-omap2/omap_device.c
3647+++ b/arch/arm/mach-omap2/omap_device.c
3648@@ -510,7 +510,7 @@ void omap_device_delete(struct omap_device *od)
3649 struct platform_device __init *omap_device_build(const char *pdev_name,
3650 int pdev_id,
3651 struct omap_hwmod *oh,
3652- void *pdata, int pdata_len)
3653+ const void *pdata, int pdata_len)
3654 {
3655 struct omap_hwmod *ohs[] = { oh };
3656
3657@@ -538,7 +538,7 @@ struct platform_device __init *omap_device_build(const char *pdev_name,
3658 struct platform_device __init *omap_device_build_ss(const char *pdev_name,
3659 int pdev_id,
3660 struct omap_hwmod **ohs,
3661- int oh_cnt, void *pdata,
3662+ int oh_cnt, const void *pdata,
3663 int pdata_len)
3664 {
3665 int ret = -ENOMEM;
3666diff --git a/arch/arm/mach-omap2/omap_device.h b/arch/arm/mach-omap2/omap_device.h
3667index 78c02b3..c94109a 100644
3668--- a/arch/arm/mach-omap2/omap_device.h
3669+++ b/arch/arm/mach-omap2/omap_device.h
3670@@ -72,12 +72,12 @@ int omap_device_idle(struct platform_device *pdev);
3671 /* Core code interface */
3672
3673 struct platform_device *omap_device_build(const char *pdev_name, int pdev_id,
3674- struct omap_hwmod *oh, void *pdata,
3675+ struct omap_hwmod *oh, const void *pdata,
3676 int pdata_len);
3677
3678 struct platform_device *omap_device_build_ss(const char *pdev_name, int pdev_id,
3679 struct omap_hwmod **oh, int oh_cnt,
3680- void *pdata, int pdata_len);
3681+ const void *pdata, int pdata_len);
3682
3683 struct omap_device *omap_device_alloc(struct platform_device *pdev,
3684 struct omap_hwmod **ohs, int oh_cnt);
3685diff --git a/arch/arm/mach-omap2/omap_hwmod.c b/arch/arm/mach-omap2/omap_hwmod.c
3686index 716247e..8df346d 100644
3687--- a/arch/arm/mach-omap2/omap_hwmod.c
3688+++ b/arch/arm/mach-omap2/omap_hwmod.c
3689@@ -194,10 +194,10 @@ struct omap_hwmod_soc_ops {
3690 int (*init_clkdm)(struct omap_hwmod *oh);
3691 void (*update_context_lost)(struct omap_hwmod *oh);
3692 int (*get_context_lost)(struct omap_hwmod *oh);
3693-};
3694+} __no_const;
3695
3696 /* soc_ops: adapts the omap_hwmod code to the currently-booted SoC */
3697-static struct omap_hwmod_soc_ops soc_ops;
3698+static struct omap_hwmod_soc_ops soc_ops __read_only;
3699
3700 /* omap_hwmod_list contains all registered struct omap_hwmods */
3701 static LIST_HEAD(omap_hwmod_list);
3702diff --git a/arch/arm/mach-omap2/powerdomains43xx_data.c b/arch/arm/mach-omap2/powerdomains43xx_data.c
3703index 95fee54..cfa9cf1 100644
3704--- a/arch/arm/mach-omap2/powerdomains43xx_data.c
3705+++ b/arch/arm/mach-omap2/powerdomains43xx_data.c
3706@@ -10,6 +10,7 @@
3707
3708 #include <linux/kernel.h>
3709 #include <linux/init.h>
3710+#include <asm/pgtable.h>
3711
3712 #include "powerdomain.h"
3713
3714@@ -129,7 +130,9 @@ static int am43xx_check_vcvp(void)
3715
3716 void __init am43xx_powerdomains_init(void)
3717 {
3718- omap4_pwrdm_operations.pwrdm_has_voltdm = am43xx_check_vcvp;
3719+ pax_open_kernel();
3720+ *(void **)&omap4_pwrdm_operations.pwrdm_has_voltdm = am43xx_check_vcvp;
3721+ pax_close_kernel();
3722 pwrdm_register_platform_funcs(&omap4_pwrdm_operations);
3723 pwrdm_register_pwrdms(powerdomains_am43xx);
3724 pwrdm_complete_init();
3725diff --git a/arch/arm/mach-omap2/wd_timer.c b/arch/arm/mach-omap2/wd_timer.c
3726index ff0a68c..b312aa0 100644
3727--- a/arch/arm/mach-omap2/wd_timer.c
3728+++ b/arch/arm/mach-omap2/wd_timer.c
3729@@ -110,7 +110,9 @@ static int __init omap_init_wdt(void)
3730 struct omap_hwmod *oh;
3731 char *oh_name = "wd_timer2";
3732 char *dev_name = "omap_wdt";
3733- struct omap_wd_timer_platform_data pdata;
3734+ static struct omap_wd_timer_platform_data pdata = {
3735+ .read_reset_sources = prm_read_reset_sources
3736+ };
3737
3738 if (!cpu_class_is_omap2() || of_have_populated_dt())
3739 return 0;
3740@@ -121,8 +123,6 @@ static int __init omap_init_wdt(void)
3741 return -EINVAL;
3742 }
3743
3744- pdata.read_reset_sources = prm_read_reset_sources;
3745-
3746 pdev = omap_device_build(dev_name, id, oh, &pdata,
3747 sizeof(struct omap_wd_timer_platform_data));
3748 WARN(IS_ERR(pdev), "Can't build omap_device for %s:%s.\n",
3749diff --git a/arch/arm/mach-tegra/cpuidle-tegra20.c b/arch/arm/mach-tegra/cpuidle-tegra20.c
3750index b30bf5c..d0825bf 100644
3751--- a/arch/arm/mach-tegra/cpuidle-tegra20.c
3752+++ b/arch/arm/mach-tegra/cpuidle-tegra20.c
3753@@ -180,7 +180,7 @@ static int tegra20_idle_lp2_coupled(struct cpuidle_device *dev,
3754 bool entered_lp2 = false;
3755
3756 if (tegra_pending_sgi())
3757- ACCESS_ONCE(abort_flag) = true;
3758+ ACCESS_ONCE_RW(abort_flag) = true;
3759
3760 cpuidle_coupled_parallel_barrier(dev, &abort_barrier);
3761
3762diff --git a/arch/arm/mach-ux500/setup.h b/arch/arm/mach-ux500/setup.h
3763index 2dea8b5..6499da2 100644
3764--- a/arch/arm/mach-ux500/setup.h
3765+++ b/arch/arm/mach-ux500/setup.h
3766@@ -33,13 +33,6 @@ extern void ux500_timer_init(void);
3767 .type = MT_DEVICE, \
3768 }
3769
3770-#define __MEM_DEV_DESC(x, sz) { \
3771- .virtual = IO_ADDRESS(x), \
3772- .pfn = __phys_to_pfn(x), \
3773- .length = sz, \
3774- .type = MT_MEMORY_RWX, \
3775-}
3776-
3777 extern struct smp_operations ux500_smp_ops;
3778 extern void ux500_cpu_die(unsigned int cpu);
3779
3780diff --git a/arch/arm/mm/Kconfig b/arch/arm/mm/Kconfig
3781index 7eb94e6..799ad3e 100644
3782--- a/arch/arm/mm/Kconfig
3783+++ b/arch/arm/mm/Kconfig
3784@@ -446,6 +446,7 @@ config CPU_32v5
3785
3786 config CPU_32v6
3787 bool
3788+ select CPU_USE_DOMAINS if CPU_V6 && MMU && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
3789 select TLS_REG_EMUL if !CPU_32v6K && !MMU
3790
3791 config CPU_32v6K
3792@@ -600,6 +601,7 @@ config CPU_CP15_MPU
3793
3794 config CPU_USE_DOMAINS
3795 bool
3796+ depends on !ARM_LPAE && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
3797 help
3798 This option enables or disables the use of domain switching
3799 via the set_fs() function.
3800@@ -798,7 +800,7 @@ config NEED_KUSER_HELPERS
3801
3802 config KUSER_HELPERS
3803 bool "Enable kuser helpers in vector page" if !NEED_KUSER_HELPERS
3804- depends on MMU
3805+ depends on MMU && (!(CPU_V6 || CPU_V6K || CPU_V7) || GRKERNSEC_OLD_ARM_USERLAND)
3806 default y
3807 help
3808 Warning: disabling this option may break user programs.
3809@@ -812,7 +814,7 @@ config KUSER_HELPERS
3810 See Documentation/arm/kernel_user_helpers.txt for details.
3811
3812 However, the fixed address nature of these helpers can be used
3813- by ROP (return orientated programming) authors when creating
3814+ by ROP (Return Oriented Programming) authors when creating
3815 exploits.
3816
3817 If all of the binaries and libraries which run on your platform
3818diff --git a/arch/arm/mm/alignment.c b/arch/arm/mm/alignment.c
3819index 83792f4..c25d36b 100644
3820--- a/arch/arm/mm/alignment.c
3821+++ b/arch/arm/mm/alignment.c
3822@@ -216,10 +216,12 @@ union offset_union {
3823 #define __get16_unaligned_check(ins,val,addr) \
3824 do { \
3825 unsigned int err = 0, v, a = addr; \
3826+ pax_open_userland(); \
3827 __get8_unaligned_check(ins,v,a,err); \
3828 val = v << ((BE) ? 8 : 0); \
3829 __get8_unaligned_check(ins,v,a,err); \
3830 val |= v << ((BE) ? 0 : 8); \
3831+ pax_close_userland(); \
3832 if (err) \
3833 goto fault; \
3834 } while (0)
3835@@ -233,6 +235,7 @@ union offset_union {
3836 #define __get32_unaligned_check(ins,val,addr) \
3837 do { \
3838 unsigned int err = 0, v, a = addr; \
3839+ pax_open_userland(); \
3840 __get8_unaligned_check(ins,v,a,err); \
3841 val = v << ((BE) ? 24 : 0); \
3842 __get8_unaligned_check(ins,v,a,err); \
3843@@ -241,6 +244,7 @@ union offset_union {
3844 val |= v << ((BE) ? 8 : 16); \
3845 __get8_unaligned_check(ins,v,a,err); \
3846 val |= v << ((BE) ? 0 : 24); \
3847+ pax_close_userland(); \
3848 if (err) \
3849 goto fault; \
3850 } while (0)
3851@@ -254,6 +258,7 @@ union offset_union {
3852 #define __put16_unaligned_check(ins,val,addr) \
3853 do { \
3854 unsigned int err = 0, v = val, a = addr; \
3855+ pax_open_userland(); \
3856 __asm__( FIRST_BYTE_16 \
3857 ARM( "1: "ins" %1, [%2], #1\n" ) \
3858 THUMB( "1: "ins" %1, [%2]\n" ) \
3859@@ -273,6 +278,7 @@ union offset_union {
3860 " .popsection\n" \
3861 : "=r" (err), "=&r" (v), "=&r" (a) \
3862 : "0" (err), "1" (v), "2" (a)); \
3863+ pax_close_userland(); \
3864 if (err) \
3865 goto fault; \
3866 } while (0)
3867@@ -286,6 +292,7 @@ union offset_union {
3868 #define __put32_unaligned_check(ins,val,addr) \
3869 do { \
3870 unsigned int err = 0, v = val, a = addr; \
3871+ pax_open_userland(); \
3872 __asm__( FIRST_BYTE_32 \
3873 ARM( "1: "ins" %1, [%2], #1\n" ) \
3874 THUMB( "1: "ins" %1, [%2]\n" ) \
3875@@ -315,6 +322,7 @@ union offset_union {
3876 " .popsection\n" \
3877 : "=r" (err), "=&r" (v), "=&r" (a) \
3878 : "0" (err), "1" (v), "2" (a)); \
3879+ pax_close_userland(); \
3880 if (err) \
3881 goto fault; \
3882 } while (0)
3883diff --git a/arch/arm/mm/cache-l2x0.c b/arch/arm/mm/cache-l2x0.c
3884index 5e65ca8..879e7b3 100644
3885--- a/arch/arm/mm/cache-l2x0.c
3886+++ b/arch/arm/mm/cache-l2x0.c
3887@@ -42,7 +42,7 @@ struct l2c_init_data {
3888 void (*fixup)(void __iomem *, u32, struct outer_cache_fns *);
3889 void (*save)(void __iomem *);
3890 struct outer_cache_fns outer_cache;
3891-};
3892+} __do_const;
3893
3894 #define CACHE_LINE_SIZE 32
3895
3896diff --git a/arch/arm/mm/context.c b/arch/arm/mm/context.c
3897index 6eb97b3..ac509f6 100644
3898--- a/arch/arm/mm/context.c
3899+++ b/arch/arm/mm/context.c
3900@@ -43,7 +43,7 @@
3901 #define NUM_USER_ASIDS ASID_FIRST_VERSION
3902
3903 static DEFINE_RAW_SPINLOCK(cpu_asid_lock);
3904-static atomic64_t asid_generation = ATOMIC64_INIT(ASID_FIRST_VERSION);
3905+static atomic64_unchecked_t asid_generation = ATOMIC64_INIT(ASID_FIRST_VERSION);
3906 static DECLARE_BITMAP(asid_map, NUM_USER_ASIDS);
3907
3908 static DEFINE_PER_CPU(atomic64_t, active_asids);
3909@@ -182,7 +182,7 @@ static u64 new_context(struct mm_struct *mm, unsigned int cpu)
3910 {
3911 static u32 cur_idx = 1;
3912 u64 asid = atomic64_read(&mm->context.id);
3913- u64 generation = atomic64_read(&asid_generation);
3914+ u64 generation = atomic64_read_unchecked(&asid_generation);
3915
3916 if (asid != 0 && is_reserved_asid(asid)) {
3917 /*
3918@@ -203,7 +203,7 @@ static u64 new_context(struct mm_struct *mm, unsigned int cpu)
3919 */
3920 asid = find_next_zero_bit(asid_map, NUM_USER_ASIDS, cur_idx);
3921 if (asid == NUM_USER_ASIDS) {
3922- generation = atomic64_add_return(ASID_FIRST_VERSION,
3923+ generation = atomic64_add_return_unchecked(ASID_FIRST_VERSION,
3924 &asid_generation);
3925 flush_context(cpu);
3926 asid = find_next_zero_bit(asid_map, NUM_USER_ASIDS, 1);
3927@@ -234,14 +234,14 @@ void check_and_switch_context(struct mm_struct *mm, struct task_struct *tsk)
3928 cpu_set_reserved_ttbr0();
3929
3930 asid = atomic64_read(&mm->context.id);
3931- if (!((asid ^ atomic64_read(&asid_generation)) >> ASID_BITS)
3932+ if (!((asid ^ atomic64_read_unchecked(&asid_generation)) >> ASID_BITS)
3933 && atomic64_xchg(&per_cpu(active_asids, cpu), asid))
3934 goto switch_mm_fastpath;
3935
3936 raw_spin_lock_irqsave(&cpu_asid_lock, flags);
3937 /* Check that our ASID belongs to the current generation. */
3938 asid = atomic64_read(&mm->context.id);
3939- if ((asid ^ atomic64_read(&asid_generation)) >> ASID_BITS) {
3940+ if ((asid ^ atomic64_read_unchecked(&asid_generation)) >> ASID_BITS) {
3941 asid = new_context(mm, cpu);
3942 atomic64_set(&mm->context.id, asid);
3943 }
3944diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c
3945index eb8830a..e8ff52e 100644
3946--- a/arch/arm/mm/fault.c
3947+++ b/arch/arm/mm/fault.c
3948@@ -25,6 +25,7 @@
3949 #include <asm/system_misc.h>
3950 #include <asm/system_info.h>
3951 #include <asm/tlbflush.h>
3952+#include <asm/sections.h>
3953
3954 #include "fault.h"
3955
3956@@ -138,6 +139,31 @@ __do_kernel_fault(struct mm_struct *mm, unsigned long addr, unsigned int fsr,
3957 if (fixup_exception(regs))
3958 return;
3959
3960+#ifdef CONFIG_PAX_MEMORY_UDEREF
3961+ if (addr < TASK_SIZE) {
3962+ if (current->signal->curr_ip)
3963+ 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),
3964+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3965+ else
3966+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", current->comm, task_pid_nr(current),
3967+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3968+ }
3969+#endif
3970+
3971+#ifdef CONFIG_PAX_KERNEXEC
3972+ if ((fsr & FSR_WRITE) &&
3973+ (((unsigned long)_stext <= addr && addr < init_mm.end_code) ||
3974+ (MODULES_VADDR <= addr && addr < MODULES_END)))
3975+ {
3976+ if (current->signal->curr_ip)
3977+ 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),
3978+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
3979+ else
3980+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
3981+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
3982+ }
3983+#endif
3984+
3985 /*
3986 * No handler, we'll have to terminate things with extreme prejudice.
3987 */
3988@@ -174,6 +200,13 @@ __do_user_fault(struct task_struct *tsk, unsigned long addr,
3989 }
3990 #endif
3991
3992+#ifdef CONFIG_PAX_PAGEEXEC
3993+ if (fsr & FSR_LNX_PF) {
3994+ pax_report_fault(regs, (void *)regs->ARM_pc, (void *)regs->ARM_sp);
3995+ do_group_exit(SIGKILL);
3996+ }
3997+#endif
3998+
3999 tsk->thread.address = addr;
4000 tsk->thread.error_code = fsr;
4001 tsk->thread.trap_no = 14;
4002@@ -401,6 +434,33 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
4003 }
4004 #endif /* CONFIG_MMU */
4005
4006+#ifdef CONFIG_PAX_PAGEEXEC
4007+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
4008+{
4009+ long i;
4010+
4011+ printk(KERN_ERR "PAX: bytes at PC: ");
4012+ for (i = 0; i < 20; i++) {
4013+ unsigned char c;
4014+ if (get_user(c, (__force unsigned char __user *)pc+i))
4015+ printk(KERN_CONT "?? ");
4016+ else
4017+ printk(KERN_CONT "%02x ", c);
4018+ }
4019+ printk("\n");
4020+
4021+ printk(KERN_ERR "PAX: bytes at SP-4: ");
4022+ for (i = -1; i < 20; i++) {
4023+ unsigned long c;
4024+ if (get_user(c, (__force unsigned long __user *)sp+i))
4025+ printk(KERN_CONT "???????? ");
4026+ else
4027+ printk(KERN_CONT "%08lx ", c);
4028+ }
4029+ printk("\n");
4030+}
4031+#endif
4032+
4033 /*
4034 * First Level Translation Fault Handler
4035 *
4036@@ -548,9 +608,22 @@ do_DataAbort(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
4037 const struct fsr_info *inf = fsr_info + fsr_fs(fsr);
4038 struct siginfo info;
4039
4040+#ifdef CONFIG_PAX_MEMORY_UDEREF
4041+ if (addr < TASK_SIZE && is_domain_fault(fsr)) {
4042+ if (current->signal->curr_ip)
4043+ 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),
4044+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
4045+ else
4046+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", current->comm, task_pid_nr(current),
4047+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
4048+ goto die;
4049+ }
4050+#endif
4051+
4052 if (!inf->fn(addr, fsr & ~FSR_LNX_PF, regs))
4053 return;
4054
4055+die:
4056 printk(KERN_ALERT "Unhandled fault: %s (0x%03x) at 0x%08lx\n",
4057 inf->name, fsr, addr);
4058
4059@@ -574,15 +647,104 @@ hook_ifault_code(int nr, int (*fn)(unsigned long, unsigned int, struct pt_regs *
4060 ifsr_info[nr].name = name;
4061 }
4062
4063+asmlinkage int sys_sigreturn(struct pt_regs *regs);
4064+asmlinkage int sys_rt_sigreturn(struct pt_regs *regs);
4065+
4066 asmlinkage void __exception
4067 do_PrefetchAbort(unsigned long addr, unsigned int ifsr, struct pt_regs *regs)
4068 {
4069 const struct fsr_info *inf = ifsr_info + fsr_fs(ifsr);
4070 struct siginfo info;
4071+ unsigned long pc = instruction_pointer(regs);
4072+
4073+ if (user_mode(regs)) {
4074+ unsigned long sigpage = current->mm->context.sigpage;
4075+
4076+ if (sigpage <= pc && pc < sigpage + 7*4) {
4077+ if (pc < sigpage + 3*4)
4078+ sys_sigreturn(regs);
4079+ else
4080+ sys_rt_sigreturn(regs);
4081+ return;
4082+ }
4083+ if (pc == 0xffff0f60UL) {
4084+ /*
4085+ * PaX: __kuser_cmpxchg64 emulation
4086+ */
4087+ // TODO
4088+ //regs->ARM_pc = regs->ARM_lr;
4089+ //return;
4090+ }
4091+ if (pc == 0xffff0fa0UL) {
4092+ /*
4093+ * PaX: __kuser_memory_barrier emulation
4094+ */
4095+ // dmb(); implied by the exception
4096+ regs->ARM_pc = regs->ARM_lr;
4097+ return;
4098+ }
4099+ if (pc == 0xffff0fc0UL) {
4100+ /*
4101+ * PaX: __kuser_cmpxchg emulation
4102+ */
4103+ // TODO
4104+ //long new;
4105+ //int op;
4106+
4107+ //op = FUTEX_OP_SET << 28;
4108+ //new = futex_atomic_op_inuser(op, regs->ARM_r2);
4109+ //regs->ARM_r0 = old != new;
4110+ //regs->ARM_pc = regs->ARM_lr;
4111+ //return;
4112+ }
4113+ if (pc == 0xffff0fe0UL) {
4114+ /*
4115+ * PaX: __kuser_get_tls emulation
4116+ */
4117+ regs->ARM_r0 = current_thread_info()->tp_value[0];
4118+ regs->ARM_pc = regs->ARM_lr;
4119+ return;
4120+ }
4121+ }
4122+
4123+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
4124+ else if (is_domain_fault(ifsr) || is_xn_fault(ifsr)) {
4125+ if (current->signal->curr_ip)
4126+ 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),
4127+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()),
4128+ pc >= TASK_SIZE ? "non-executable kernel" : "userland", pc);
4129+ else
4130+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to execute %s memory at %08lx\n", current->comm, task_pid_nr(current),
4131+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()),
4132+ pc >= TASK_SIZE ? "non-executable kernel" : "userland", pc);
4133+ goto die;
4134+ }
4135+#endif
4136+
4137+#ifdef CONFIG_PAX_REFCOUNT
4138+ if (fsr_fs(ifsr) == FAULT_CODE_DEBUG) {
4139+#ifdef CONFIG_THUMB2_KERNEL
4140+ unsigned short bkpt;
4141+
4142+ if (!probe_kernel_address(pc, bkpt) && cpu_to_le16(bkpt) == 0xbef1) {
4143+#else
4144+ unsigned int bkpt;
4145+
4146+ if (!probe_kernel_address(pc, bkpt) && cpu_to_le32(bkpt) == 0xe12f1073) {
4147+#endif
4148+ current->thread.error_code = ifsr;
4149+ current->thread.trap_no = 0;
4150+ pax_report_refcount_overflow(regs);
4151+ fixup_exception(regs);
4152+ return;
4153+ }
4154+ }
4155+#endif
4156
4157 if (!inf->fn(addr, ifsr | FSR_LNX_PF, regs))
4158 return;
4159
4160+die:
4161 printk(KERN_ALERT "Unhandled prefetch abort: %s (0x%03x) at 0x%08lx\n",
4162 inf->name, ifsr, addr);
4163
4164diff --git a/arch/arm/mm/fault.h b/arch/arm/mm/fault.h
4165index cf08bdf..772656c 100644
4166--- a/arch/arm/mm/fault.h
4167+++ b/arch/arm/mm/fault.h
4168@@ -3,6 +3,7 @@
4169
4170 /*
4171 * Fault status register encodings. We steal bit 31 for our own purposes.
4172+ * Set when the FSR value is from an instruction fault.
4173 */
4174 #define FSR_LNX_PF (1 << 31)
4175 #define FSR_WRITE (1 << 11)
4176@@ -22,6 +23,17 @@ static inline int fsr_fs(unsigned int fsr)
4177 }
4178 #endif
4179
4180+/* valid for LPAE and !LPAE */
4181+static inline int is_xn_fault(unsigned int fsr)
4182+{
4183+ return ((fsr_fs(fsr) & 0x3c) == 0xc);
4184+}
4185+
4186+static inline int is_domain_fault(unsigned int fsr)
4187+{
4188+ return ((fsr_fs(fsr) & 0xD) == 0x9);
4189+}
4190+
4191 void do_bad_area(unsigned long addr, unsigned int fsr, struct pt_regs *regs);
4192 unsigned long search_exception_table(unsigned long addr);
4193
4194diff --git a/arch/arm/mm/init.c b/arch/arm/mm/init.c
4195index 9481f85..6dae261 100644
4196--- a/arch/arm/mm/init.c
4197+++ b/arch/arm/mm/init.c
4198@@ -31,6 +31,8 @@
4199 #include <asm/setup.h>
4200 #include <asm/tlb.h>
4201 #include <asm/fixmap.h>
4202+#include <asm/system_info.h>
4203+#include <asm/cp15.h>
4204
4205 #include <asm/mach/arch.h>
4206 #include <asm/mach/map.h>
4207@@ -619,7 +621,46 @@ void free_initmem(void)
4208 {
4209 #ifdef CONFIG_HAVE_TCM
4210 extern char __tcm_start, __tcm_end;
4211+#endif
4212
4213+#ifdef CONFIG_PAX_KERNEXEC
4214+ unsigned long addr;
4215+ pgd_t *pgd;
4216+ pud_t *pud;
4217+ pmd_t *pmd;
4218+ int cpu_arch = cpu_architecture();
4219+ unsigned int cr = get_cr();
4220+
4221+ if (cpu_arch >= CPU_ARCH_ARMv6 && (cr & CR_XP)) {
4222+ /* make pages tables, etc before .text NX */
4223+ for (addr = PAGE_OFFSET; addr < (unsigned long)_stext; addr += SECTION_SIZE) {
4224+ pgd = pgd_offset_k(addr);
4225+ pud = pud_offset(pgd, addr);
4226+ pmd = pmd_offset(pud, addr);
4227+ __section_update(pmd, addr, PMD_SECT_XN);
4228+ }
4229+ /* make init NX */
4230+ for (addr = (unsigned long)__init_begin; addr < (unsigned long)_sdata; addr += SECTION_SIZE) {
4231+ pgd = pgd_offset_k(addr);
4232+ pud = pud_offset(pgd, addr);
4233+ pmd = pmd_offset(pud, addr);
4234+ __section_update(pmd, addr, PMD_SECT_XN);
4235+ }
4236+ /* make kernel code/rodata RX */
4237+ for (addr = (unsigned long)_stext; addr < (unsigned long)__init_begin; addr += SECTION_SIZE) {
4238+ pgd = pgd_offset_k(addr);
4239+ pud = pud_offset(pgd, addr);
4240+ pmd = pmd_offset(pud, addr);
4241+#ifdef CONFIG_ARM_LPAE
4242+ __section_update(pmd, addr, PMD_SECT_RDONLY);
4243+#else
4244+ __section_update(pmd, addr, PMD_SECT_APX|PMD_SECT_AP_WRITE);
4245+#endif
4246+ }
4247+ }
4248+#endif
4249+
4250+#ifdef CONFIG_HAVE_TCM
4251 poison_init_mem(&__tcm_start, &__tcm_end - &__tcm_start);
4252 free_reserved_area(&__tcm_start, &__tcm_end, -1, "TCM link");
4253 #endif
4254diff --git a/arch/arm/mm/ioremap.c b/arch/arm/mm/ioremap.c
4255index d1e5ad7..84dcbf2 100644
4256--- a/arch/arm/mm/ioremap.c
4257+++ b/arch/arm/mm/ioremap.c
4258@@ -392,9 +392,9 @@ __arm_ioremap_exec(phys_addr_t phys_addr, size_t size, bool cached)
4259 unsigned int mtype;
4260
4261 if (cached)
4262- mtype = MT_MEMORY_RWX;
4263+ mtype = MT_MEMORY_RX;
4264 else
4265- mtype = MT_MEMORY_RWX_NONCACHED;
4266+ mtype = MT_MEMORY_RX_NONCACHED;
4267
4268 return __arm_ioremap_caller(phys_addr, size, mtype,
4269 __builtin_return_address(0));
4270diff --git a/arch/arm/mm/mmap.c b/arch/arm/mm/mmap.c
4271index 5e85ed3..b10a7ed 100644
4272--- a/arch/arm/mm/mmap.c
4273+++ b/arch/arm/mm/mmap.c
4274@@ -59,6 +59,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4275 struct vm_area_struct *vma;
4276 int do_align = 0;
4277 int aliasing = cache_is_vipt_aliasing();
4278+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
4279 struct vm_unmapped_area_info info;
4280
4281 /*
4282@@ -81,6 +82,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4283 if (len > TASK_SIZE)
4284 return -ENOMEM;
4285
4286+#ifdef CONFIG_PAX_RANDMMAP
4287+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4288+#endif
4289+
4290 if (addr) {
4291 if (do_align)
4292 addr = COLOUR_ALIGN(addr, pgoff);
4293@@ -88,8 +93,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4294 addr = PAGE_ALIGN(addr);
4295
4296 vma = find_vma(mm, addr);
4297- if (TASK_SIZE - len >= addr &&
4298- (!vma || addr + len <= vma->vm_start))
4299+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4300 return addr;
4301 }
4302
4303@@ -99,6 +103,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4304 info.high_limit = TASK_SIZE;
4305 info.align_mask = do_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
4306 info.align_offset = pgoff << PAGE_SHIFT;
4307+ info.threadstack_offset = offset;
4308 return vm_unmapped_area(&info);
4309 }
4310
4311@@ -112,6 +117,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4312 unsigned long addr = addr0;
4313 int do_align = 0;
4314 int aliasing = cache_is_vipt_aliasing();
4315+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
4316 struct vm_unmapped_area_info info;
4317
4318 /*
4319@@ -132,6 +138,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4320 return addr;
4321 }
4322
4323+#ifdef CONFIG_PAX_RANDMMAP
4324+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4325+#endif
4326+
4327 /* requesting a specific address */
4328 if (addr) {
4329 if (do_align)
4330@@ -139,8 +149,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4331 else
4332 addr = PAGE_ALIGN(addr);
4333 vma = find_vma(mm, addr);
4334- if (TASK_SIZE - len >= addr &&
4335- (!vma || addr + len <= vma->vm_start))
4336+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4337 return addr;
4338 }
4339
4340@@ -150,6 +159,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4341 info.high_limit = mm->mmap_base;
4342 info.align_mask = do_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
4343 info.align_offset = pgoff << PAGE_SHIFT;
4344+ info.threadstack_offset = offset;
4345 addr = vm_unmapped_area(&info);
4346
4347 /*
4348@@ -173,6 +183,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4349 {
4350 unsigned long random_factor = 0UL;
4351
4352+#ifdef CONFIG_PAX_RANDMMAP
4353+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4354+#endif
4355+
4356 /* 8 bits of randomness in 20 address space bits */
4357 if ((current->flags & PF_RANDOMIZE) &&
4358 !(current->personality & ADDR_NO_RANDOMIZE))
4359@@ -180,9 +194,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4360
4361 if (mmap_is_legacy()) {
4362 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
4363+
4364+#ifdef CONFIG_PAX_RANDMMAP
4365+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4366+ mm->mmap_base += mm->delta_mmap;
4367+#endif
4368+
4369 mm->get_unmapped_area = arch_get_unmapped_area;
4370 } else {
4371 mm->mmap_base = mmap_base(random_factor);
4372+
4373+#ifdef CONFIG_PAX_RANDMMAP
4374+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4375+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4376+#endif
4377+
4378 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4379 }
4380 }
4381diff --git a/arch/arm/mm/mmu.c b/arch/arm/mm/mmu.c
4382index 9f98cec..115fcb6 100644
4383--- a/arch/arm/mm/mmu.c
4384+++ b/arch/arm/mm/mmu.c
4385@@ -40,6 +40,22 @@
4386 #include "mm.h"
4387 #include "tcm.h"
4388
4389+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
4390+void modify_domain(unsigned int dom, unsigned int type)
4391+{
4392+ struct thread_info *thread = current_thread_info();
4393+ unsigned int domain = thread->cpu_domain;
4394+ /*
4395+ * DOMAIN_MANAGER might be defined to some other value,
4396+ * use the arch-defined constant
4397+ */
4398+ domain &= ~domain_val(dom, 3);
4399+ thread->cpu_domain = domain | domain_val(dom, type);
4400+ set_domain(thread->cpu_domain);
4401+}
4402+EXPORT_SYMBOL(modify_domain);
4403+#endif
4404+
4405 /*
4406 * empty_zero_page is a special page that is used for
4407 * zero-initialized data and COW.
4408@@ -239,7 +255,15 @@ __setup("noalign", noalign_setup);
4409 #define PROT_PTE_S2_DEVICE PROT_PTE_DEVICE
4410 #define PROT_SECT_DEVICE PMD_TYPE_SECT|PMD_SECT_AP_WRITE
4411
4412-static struct mem_type mem_types[] = {
4413+#ifdef CONFIG_PAX_KERNEXEC
4414+#define L_PTE_KERNEXEC L_PTE_RDONLY
4415+#define PMD_SECT_KERNEXEC PMD_SECT_RDONLY
4416+#else
4417+#define L_PTE_KERNEXEC L_PTE_DIRTY
4418+#define PMD_SECT_KERNEXEC PMD_SECT_AP_WRITE
4419+#endif
4420+
4421+static struct mem_type mem_types[] __read_only = {
4422 [MT_DEVICE] = { /* Strongly ordered / ARMv6 shared device */
4423 .prot_pte = PROT_PTE_DEVICE | L_PTE_MT_DEV_SHARED |
4424 L_PTE_SHARED,
4425@@ -268,19 +292,19 @@ static struct mem_type mem_types[] = {
4426 .prot_sect = PROT_SECT_DEVICE,
4427 .domain = DOMAIN_IO,
4428 },
4429- [MT_UNCACHED] = {
4430+ [MT_UNCACHED_RW] = {
4431 .prot_pte = PROT_PTE_DEVICE,
4432 .prot_l1 = PMD_TYPE_TABLE,
4433 .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4434 .domain = DOMAIN_IO,
4435 },
4436- [MT_CACHECLEAN] = {
4437- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4438+ [MT_CACHECLEAN_RO] = {
4439+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_RDONLY,
4440 .domain = DOMAIN_KERNEL,
4441 },
4442 #ifndef CONFIG_ARM_LPAE
4443- [MT_MINICLEAN] = {
4444- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_MINICACHE,
4445+ [MT_MINICLEAN_RO] = {
4446+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_MINICACHE | PMD_SECT_XN | PMD_SECT_RDONLY,
4447 .domain = DOMAIN_KERNEL,
4448 },
4449 #endif
4450@@ -288,15 +312,15 @@ static struct mem_type mem_types[] = {
4451 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4452 L_PTE_RDONLY,
4453 .prot_l1 = PMD_TYPE_TABLE,
4454- .domain = DOMAIN_USER,
4455+ .domain = DOMAIN_VECTORS,
4456 },
4457 [MT_HIGH_VECTORS] = {
4458 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4459 L_PTE_USER | L_PTE_RDONLY,
4460 .prot_l1 = PMD_TYPE_TABLE,
4461- .domain = DOMAIN_USER,
4462+ .domain = DOMAIN_VECTORS,
4463 },
4464- [MT_MEMORY_RWX] = {
4465+ [__MT_MEMORY_RWX] = {
4466 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4467 .prot_l1 = PMD_TYPE_TABLE,
4468 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4469@@ -309,17 +333,30 @@ static struct mem_type mem_types[] = {
4470 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4471 .domain = DOMAIN_KERNEL,
4472 },
4473- [MT_ROM] = {
4474- .prot_sect = PMD_TYPE_SECT,
4475+ [MT_MEMORY_RX] = {
4476+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC,
4477+ .prot_l1 = PMD_TYPE_TABLE,
4478+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4479+ .domain = DOMAIN_KERNEL,
4480+ },
4481+ [MT_ROM_RX] = {
4482+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
4483 .domain = DOMAIN_KERNEL,
4484 },
4485- [MT_MEMORY_RWX_NONCACHED] = {
4486+ [MT_MEMORY_RW_NONCACHED] = {
4487 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4488 L_PTE_MT_BUFFERABLE,
4489 .prot_l1 = PMD_TYPE_TABLE,
4490 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4491 .domain = DOMAIN_KERNEL,
4492 },
4493+ [MT_MEMORY_RX_NONCACHED] = {
4494+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC |
4495+ L_PTE_MT_BUFFERABLE,
4496+ .prot_l1 = PMD_TYPE_TABLE,
4497+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4498+ .domain = DOMAIN_KERNEL,
4499+ },
4500 [MT_MEMORY_RW_DTCM] = {
4501 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4502 L_PTE_XN,
4503@@ -327,9 +364,10 @@ static struct mem_type mem_types[] = {
4504 .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4505 .domain = DOMAIN_KERNEL,
4506 },
4507- [MT_MEMORY_RWX_ITCM] = {
4508- .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4509+ [MT_MEMORY_RX_ITCM] = {
4510+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC,
4511 .prot_l1 = PMD_TYPE_TABLE,
4512+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4513 .domain = DOMAIN_KERNEL,
4514 },
4515 [MT_MEMORY_RW_SO] = {
4516@@ -547,9 +585,14 @@ static void __init build_mem_type_table(void)
4517 * Mark cache clean areas and XIP ROM read only
4518 * from SVC mode and no access from userspace.
4519 */
4520- mem_types[MT_ROM].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4521- mem_types[MT_MINICLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4522- mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4523+ mem_types[MT_ROM_RX].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4524+#ifdef CONFIG_PAX_KERNEXEC
4525+ mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4526+ mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4527+ mem_types[MT_MEMORY_RX_ITCM].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4528+#endif
4529+ mem_types[MT_MINICLEAN_RO].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4530+ mem_types[MT_CACHECLEAN_RO].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4531 #endif
4532
4533 /*
4534@@ -566,13 +609,17 @@ static void __init build_mem_type_table(void)
4535 mem_types[MT_DEVICE_WC].prot_pte |= L_PTE_SHARED;
4536 mem_types[MT_DEVICE_CACHED].prot_sect |= PMD_SECT_S;
4537 mem_types[MT_DEVICE_CACHED].prot_pte |= L_PTE_SHARED;
4538- mem_types[MT_MEMORY_RWX].prot_sect |= PMD_SECT_S;
4539- mem_types[MT_MEMORY_RWX].prot_pte |= L_PTE_SHARED;
4540+ mem_types[__MT_MEMORY_RWX].prot_sect |= PMD_SECT_S;
4541+ mem_types[__MT_MEMORY_RWX].prot_pte |= L_PTE_SHARED;
4542 mem_types[MT_MEMORY_RW].prot_sect |= PMD_SECT_S;
4543 mem_types[MT_MEMORY_RW].prot_pte |= L_PTE_SHARED;
4544+ mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_S;
4545+ mem_types[MT_MEMORY_RX].prot_pte |= L_PTE_SHARED;
4546 mem_types[MT_MEMORY_DMA_READY].prot_pte |= L_PTE_SHARED;
4547- mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |= PMD_SECT_S;
4548- mem_types[MT_MEMORY_RWX_NONCACHED].prot_pte |= L_PTE_SHARED;
4549+ mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |= PMD_SECT_S;
4550+ mem_types[MT_MEMORY_RW_NONCACHED].prot_pte |= L_PTE_SHARED;
4551+ mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |= PMD_SECT_S;
4552+ mem_types[MT_MEMORY_RX_NONCACHED].prot_pte |= L_PTE_SHARED;
4553 }
4554 }
4555
4556@@ -583,15 +630,20 @@ static void __init build_mem_type_table(void)
4557 if (cpu_arch >= CPU_ARCH_ARMv6) {
4558 if (cpu_arch >= CPU_ARCH_ARMv7 && (cr & CR_TRE)) {
4559 /* Non-cacheable Normal is XCB = 001 */
4560- mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |=
4561+ mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |=
4562+ PMD_SECT_BUFFERED;
4563+ mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |=
4564 PMD_SECT_BUFFERED;
4565 } else {
4566 /* For both ARMv6 and non-TEX-remapping ARMv7 */
4567- mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |=
4568+ mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |=
4569+ PMD_SECT_TEX(1);
4570+ mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |=
4571 PMD_SECT_TEX(1);
4572 }
4573 } else {
4574- mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |= PMD_SECT_BUFFERABLE;
4575+ mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |= PMD_SECT_BUFFERABLE;
4576+ mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |= PMD_SECT_BUFFERABLE;
4577 }
4578
4579 #ifdef CONFIG_ARM_LPAE
4580@@ -607,6 +659,8 @@ static void __init build_mem_type_table(void)
4581 vecs_pgprot |= PTE_EXT_AF;
4582 #endif
4583
4584+ user_pgprot |= __supported_pte_mask;
4585+
4586 for (i = 0; i < 16; i++) {
4587 pteval_t v = pgprot_val(protection_map[i]);
4588 protection_map[i] = __pgprot(v | user_pgprot);
4589@@ -624,21 +678,24 @@ static void __init build_mem_type_table(void)
4590
4591 mem_types[MT_LOW_VECTORS].prot_l1 |= ecc_mask;
4592 mem_types[MT_HIGH_VECTORS].prot_l1 |= ecc_mask;
4593- mem_types[MT_MEMORY_RWX].prot_sect |= ecc_mask | cp->pmd;
4594- mem_types[MT_MEMORY_RWX].prot_pte |= kern_pgprot;
4595+ mem_types[__MT_MEMORY_RWX].prot_sect |= ecc_mask | cp->pmd;
4596+ mem_types[__MT_MEMORY_RWX].prot_pte |= kern_pgprot;
4597 mem_types[MT_MEMORY_RW].prot_sect |= ecc_mask | cp->pmd;
4598 mem_types[MT_MEMORY_RW].prot_pte |= kern_pgprot;
4599+ mem_types[MT_MEMORY_RX].prot_sect |= ecc_mask | cp->pmd;
4600+ mem_types[MT_MEMORY_RX].prot_pte |= kern_pgprot;
4601 mem_types[MT_MEMORY_DMA_READY].prot_pte |= kern_pgprot;
4602- mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |= ecc_mask;
4603- mem_types[MT_ROM].prot_sect |= cp->pmd;
4604+ mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |= ecc_mask;
4605+ mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |= ecc_mask;
4606+ mem_types[MT_ROM_RX].prot_sect |= cp->pmd;
4607
4608 switch (cp->pmd) {
4609 case PMD_SECT_WT:
4610- mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_WT;
4611+ mem_types[MT_CACHECLEAN_RO].prot_sect |= PMD_SECT_WT;
4612 break;
4613 case PMD_SECT_WB:
4614 case PMD_SECT_WBWA:
4615- mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_WB;
4616+ mem_types[MT_CACHECLEAN_RO].prot_sect |= PMD_SECT_WB;
4617 break;
4618 }
4619 pr_info("Memory policy: %sData cache %s\n",
4620@@ -856,7 +913,7 @@ static void __init create_mapping(struct map_desc *md)
4621 return;
4622 }
4623
4624- if ((md->type == MT_DEVICE || md->type == MT_ROM) &&
4625+ if ((md->type == MT_DEVICE || md->type == MT_ROM_RX) &&
4626 md->virtual >= PAGE_OFFSET &&
4627 (md->virtual < VMALLOC_START || md->virtual >= VMALLOC_END)) {
4628 printk(KERN_WARNING "BUG: mapping for 0x%08llx"
4629@@ -1224,18 +1281,15 @@ void __init arm_mm_memblock_reserve(void)
4630 * called function. This means you can't use any function or debugging
4631 * method which may touch any device, otherwise the kernel _will_ crash.
4632 */
4633+
4634+static char vectors[PAGE_SIZE * 2] __read_only __aligned(PAGE_SIZE);
4635+
4636 static void __init devicemaps_init(const struct machine_desc *mdesc)
4637 {
4638 struct map_desc map;
4639 unsigned long addr;
4640- void *vectors;
4641
4642- /*
4643- * Allocate the vector page early.
4644- */
4645- vectors = early_alloc(PAGE_SIZE * 2);
4646-
4647- early_trap_init(vectors);
4648+ early_trap_init(&vectors);
4649
4650 for (addr = VMALLOC_START; addr; addr += PMD_SIZE)
4651 pmd_clear(pmd_off_k(addr));
4652@@ -1248,7 +1302,7 @@ static void __init devicemaps_init(const struct machine_desc *mdesc)
4653 map.pfn = __phys_to_pfn(CONFIG_XIP_PHYS_ADDR & SECTION_MASK);
4654 map.virtual = MODULES_VADDR;
4655 map.length = ((unsigned long)_etext - map.virtual + ~SECTION_MASK) & SECTION_MASK;
4656- map.type = MT_ROM;
4657+ map.type = MT_ROM_RX;
4658 create_mapping(&map);
4659 #endif
4660
4661@@ -1259,14 +1313,14 @@ static void __init devicemaps_init(const struct machine_desc *mdesc)
4662 map.pfn = __phys_to_pfn(FLUSH_BASE_PHYS);
4663 map.virtual = FLUSH_BASE;
4664 map.length = SZ_1M;
4665- map.type = MT_CACHECLEAN;
4666+ map.type = MT_CACHECLEAN_RO;
4667 create_mapping(&map);
4668 #endif
4669 #ifdef FLUSH_BASE_MINICACHE
4670 map.pfn = __phys_to_pfn(FLUSH_BASE_PHYS + SZ_1M);
4671 map.virtual = FLUSH_BASE_MINICACHE;
4672 map.length = SZ_1M;
4673- map.type = MT_MINICLEAN;
4674+ map.type = MT_MINICLEAN_RO;
4675 create_mapping(&map);
4676 #endif
4677
4678@@ -1275,7 +1329,7 @@ static void __init devicemaps_init(const struct machine_desc *mdesc)
4679 * location (0xffff0000). If we aren't using high-vectors, also
4680 * create a mapping at the low-vectors virtual address.
4681 */
4682- map.pfn = __phys_to_pfn(virt_to_phys(vectors));
4683+ map.pfn = __phys_to_pfn(virt_to_phys(&vectors));
4684 map.virtual = 0xffff0000;
4685 map.length = PAGE_SIZE;
4686 #ifdef CONFIG_KUSER_HELPERS
4687@@ -1335,8 +1389,10 @@ static void __init kmap_init(void)
4688 static void __init map_lowmem(void)
4689 {
4690 struct memblock_region *reg;
4691+#ifndef CONFIG_PAX_KERNEXEC
4692 unsigned long kernel_x_start = round_down(__pa(_stext), SECTION_SIZE);
4693 unsigned long kernel_x_end = round_up(__pa(__init_end), SECTION_SIZE);
4694+#endif
4695
4696 /* Map all the lowmem memory banks. */
4697 for_each_memblock(memory, reg) {
4698@@ -1349,11 +1405,48 @@ static void __init map_lowmem(void)
4699 if (start >= end)
4700 break;
4701
4702+#ifdef CONFIG_PAX_KERNEXEC
4703+ map.pfn = __phys_to_pfn(start);
4704+ map.virtual = __phys_to_virt(start);
4705+ map.length = end - start;
4706+
4707+ if (map.virtual <= (unsigned long)_stext && ((unsigned long)_end < (map.virtual + map.length))) {
4708+ struct map_desc kernel;
4709+ struct map_desc initmap;
4710+
4711+ /* when freeing initmem we will make this RW */
4712+ initmap.pfn = __phys_to_pfn(__pa(__init_begin));
4713+ initmap.virtual = (unsigned long)__init_begin;
4714+ initmap.length = _sdata - __init_begin;
4715+ initmap.type = __MT_MEMORY_RWX;
4716+ create_mapping(&initmap);
4717+
4718+ /* when freeing initmem we will make this RX */
4719+ kernel.pfn = __phys_to_pfn(__pa(_stext));
4720+ kernel.virtual = (unsigned long)_stext;
4721+ kernel.length = __init_begin - _stext;
4722+ kernel.type = __MT_MEMORY_RWX;
4723+ create_mapping(&kernel);
4724+
4725+ if (map.virtual < (unsigned long)_stext) {
4726+ map.length = (unsigned long)_stext - map.virtual;
4727+ map.type = __MT_MEMORY_RWX;
4728+ create_mapping(&map);
4729+ }
4730+
4731+ map.pfn = __phys_to_pfn(__pa(_sdata));
4732+ map.virtual = (unsigned long)_sdata;
4733+ map.length = end - __pa(_sdata);
4734+ }
4735+
4736+ map.type = MT_MEMORY_RW;
4737+ create_mapping(&map);
4738+#else
4739 if (end < kernel_x_start || start >= kernel_x_end) {
4740 map.pfn = __phys_to_pfn(start);
4741 map.virtual = __phys_to_virt(start);
4742 map.length = end - start;
4743- map.type = MT_MEMORY_RWX;
4744+ map.type = __MT_MEMORY_RWX;
4745
4746 create_mapping(&map);
4747 } else {
4748@@ -1370,7 +1463,7 @@ static void __init map_lowmem(void)
4749 map.pfn = __phys_to_pfn(kernel_x_start);
4750 map.virtual = __phys_to_virt(kernel_x_start);
4751 map.length = kernel_x_end - kernel_x_start;
4752- map.type = MT_MEMORY_RWX;
4753+ map.type = __MT_MEMORY_RWX;
4754
4755 create_mapping(&map);
4756
4757@@ -1383,6 +1476,7 @@ static void __init map_lowmem(void)
4758 create_mapping(&map);
4759 }
4760 }
4761+#endif
4762 }
4763 }
4764
4765diff --git a/arch/arm/net/bpf_jit_32.c b/arch/arm/net/bpf_jit_32.c
4766index e1268f9..a9755a7 100644
4767--- a/arch/arm/net/bpf_jit_32.c
4768+++ b/arch/arm/net/bpf_jit_32.c
4769@@ -20,6 +20,7 @@
4770 #include <asm/cacheflush.h>
4771 #include <asm/hwcap.h>
4772 #include <asm/opcodes.h>
4773+#include <asm/pgtable.h>
4774
4775 #include "bpf_jit_32.h"
4776
4777@@ -71,7 +72,11 @@ struct jit_ctx {
4778 #endif
4779 };
4780
4781+#ifdef CONFIG_GRKERNSEC_BPF_HARDEN
4782+int bpf_jit_enable __read_only;
4783+#else
4784 int bpf_jit_enable __read_mostly;
4785+#endif
4786
4787 static u64 jit_get_skb_b(struct sk_buff *skb, unsigned offset)
4788 {
4789@@ -178,8 +183,10 @@ static void jit_fill_hole(void *area, unsigned int size)
4790 {
4791 u32 *ptr;
4792 /* We are guaranteed to have aligned memory. */
4793+ pax_open_kernel();
4794 for (ptr = area; size >= sizeof(u32); size -= sizeof(u32))
4795 *ptr++ = __opcode_to_mem_arm(ARM_INST_UDF);
4796+ pax_close_kernel();
4797 }
4798
4799 static void build_prologue(struct jit_ctx *ctx)
4800diff --git a/arch/arm/plat-iop/setup.c b/arch/arm/plat-iop/setup.c
4801index 5b217f4..c23f40e 100644
4802--- a/arch/arm/plat-iop/setup.c
4803+++ b/arch/arm/plat-iop/setup.c
4804@@ -24,7 +24,7 @@ static struct map_desc iop3xx_std_desc[] __initdata = {
4805 .virtual = IOP3XX_PERIPHERAL_VIRT_BASE,
4806 .pfn = __phys_to_pfn(IOP3XX_PERIPHERAL_PHYS_BASE),
4807 .length = IOP3XX_PERIPHERAL_SIZE,
4808- .type = MT_UNCACHED,
4809+ .type = MT_UNCACHED_RW,
4810 },
4811 };
4812
4813diff --git a/arch/arm/plat-omap/sram.c b/arch/arm/plat-omap/sram.c
4814index a5bc92d..0bb4730 100644
4815--- a/arch/arm/plat-omap/sram.c
4816+++ b/arch/arm/plat-omap/sram.c
4817@@ -93,6 +93,8 @@ void __init omap_map_sram(unsigned long start, unsigned long size,
4818 * Looks like we need to preserve some bootloader code at the
4819 * beginning of SRAM for jumping to flash for reboot to work...
4820 */
4821+ pax_open_kernel();
4822 memset_io(omap_sram_base + omap_sram_skip, 0,
4823 omap_sram_size - omap_sram_skip);
4824+ pax_close_kernel();
4825 }
4826diff --git a/arch/arm/plat-samsung/include/plat/dma-ops.h b/arch/arm/plat-samsung/include/plat/dma-ops.h
4827index ce6d763..cfea917 100644
4828--- a/arch/arm/plat-samsung/include/plat/dma-ops.h
4829+++ b/arch/arm/plat-samsung/include/plat/dma-ops.h
4830@@ -47,7 +47,7 @@ struct samsung_dma_ops {
4831 int (*started)(unsigned ch);
4832 int (*flush)(unsigned ch);
4833 int (*stop)(unsigned ch);
4834-};
4835+} __no_const;
4836
4837 extern void *samsung_dmadev_get_ops(void);
4838 extern void *s3c_dma_get_ops(void);
4839diff --git a/arch/arm64/include/asm/barrier.h b/arch/arm64/include/asm/barrier.h
4840index 6389d60..b5d3bdd 100644
4841--- a/arch/arm64/include/asm/barrier.h
4842+++ b/arch/arm64/include/asm/barrier.h
4843@@ -41,7 +41,7 @@
4844 do { \
4845 compiletime_assert_atomic_type(*p); \
4846 barrier(); \
4847- ACCESS_ONCE(*p) = (v); \
4848+ ACCESS_ONCE_RW(*p) = (v); \
4849 } while (0)
4850
4851 #define smp_load_acquire(p) \
4852diff --git a/arch/arm64/include/asm/uaccess.h b/arch/arm64/include/asm/uaccess.h
4853index 3bf8f4e..5dd5491 100644
4854--- a/arch/arm64/include/asm/uaccess.h
4855+++ b/arch/arm64/include/asm/uaccess.h
4856@@ -99,6 +99,7 @@ static inline void set_fs(mm_segment_t fs)
4857 flag; \
4858 })
4859
4860+#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
4861 #define access_ok(type, addr, size) __range_ok(addr, size)
4862 #define user_addr_max get_fs
4863
4864diff --git a/arch/avr32/include/asm/cache.h b/arch/avr32/include/asm/cache.h
4865index c3a58a1..78fbf54 100644
4866--- a/arch/avr32/include/asm/cache.h
4867+++ b/arch/avr32/include/asm/cache.h
4868@@ -1,8 +1,10 @@
4869 #ifndef __ASM_AVR32_CACHE_H
4870 #define __ASM_AVR32_CACHE_H
4871
4872+#include <linux/const.h>
4873+
4874 #define L1_CACHE_SHIFT 5
4875-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4876+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4877
4878 /*
4879 * Memory returned by kmalloc() may be used for DMA, so we must make
4880diff --git a/arch/avr32/include/asm/elf.h b/arch/avr32/include/asm/elf.h
4881index d232888..87c8df1 100644
4882--- a/arch/avr32/include/asm/elf.h
4883+++ b/arch/avr32/include/asm/elf.h
4884@@ -84,8 +84,14 @@ typedef struct user_fpu_struct elf_fpregset_t;
4885 the loader. We need to make sure that it is out of the way of the program
4886 that it will "exec", and that there is sufficient room for the brk. */
4887
4888-#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
4889+#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
4890
4891+#ifdef CONFIG_PAX_ASLR
4892+#define PAX_ELF_ET_DYN_BASE 0x00001000UL
4893+
4894+#define PAX_DELTA_MMAP_LEN 15
4895+#define PAX_DELTA_STACK_LEN 15
4896+#endif
4897
4898 /* This yields a mask that user programs can use to figure out what
4899 instruction set this CPU supports. This could be done in user space,
4900diff --git a/arch/avr32/include/asm/kmap_types.h b/arch/avr32/include/asm/kmap_types.h
4901index 479330b..53717a8 100644
4902--- a/arch/avr32/include/asm/kmap_types.h
4903+++ b/arch/avr32/include/asm/kmap_types.h
4904@@ -2,9 +2,9 @@
4905 #define __ASM_AVR32_KMAP_TYPES_H
4906
4907 #ifdef CONFIG_DEBUG_HIGHMEM
4908-# define KM_TYPE_NR 29
4909+# define KM_TYPE_NR 30
4910 #else
4911-# define KM_TYPE_NR 14
4912+# define KM_TYPE_NR 15
4913 #endif
4914
4915 #endif /* __ASM_AVR32_KMAP_TYPES_H */
4916diff --git a/arch/avr32/mm/fault.c b/arch/avr32/mm/fault.c
4917index 0eca933..eb78c7b 100644
4918--- a/arch/avr32/mm/fault.c
4919+++ b/arch/avr32/mm/fault.c
4920@@ -41,6 +41,23 @@ static inline int notify_page_fault(struct pt_regs *regs, int trap)
4921
4922 int exception_trace = 1;
4923
4924+#ifdef CONFIG_PAX_PAGEEXEC
4925+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
4926+{
4927+ unsigned long i;
4928+
4929+ printk(KERN_ERR "PAX: bytes at PC: ");
4930+ for (i = 0; i < 20; i++) {
4931+ unsigned char c;
4932+ if (get_user(c, (unsigned char *)pc+i))
4933+ printk(KERN_CONT "???????? ");
4934+ else
4935+ printk(KERN_CONT "%02x ", c);
4936+ }
4937+ printk("\n");
4938+}
4939+#endif
4940+
4941 /*
4942 * This routine handles page faults. It determines the address and the
4943 * problem, and then passes it off to one of the appropriate routines.
4944@@ -176,6 +193,16 @@ bad_area:
4945 up_read(&mm->mmap_sem);
4946
4947 if (user_mode(regs)) {
4948+
4949+#ifdef CONFIG_PAX_PAGEEXEC
4950+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
4951+ if (ecr == ECR_PROTECTION_X || ecr == ECR_TLB_MISS_X) {
4952+ pax_report_fault(regs, (void *)regs->pc, (void *)regs->sp);
4953+ do_group_exit(SIGKILL);
4954+ }
4955+ }
4956+#endif
4957+
4958 if (exception_trace && printk_ratelimit())
4959 printk("%s%s[%d]: segfault at %08lx pc %08lx "
4960 "sp %08lx ecr %lu\n",
4961diff --git a/arch/blackfin/include/asm/cache.h b/arch/blackfin/include/asm/cache.h
4962index 568885a..f8008df 100644
4963--- a/arch/blackfin/include/asm/cache.h
4964+++ b/arch/blackfin/include/asm/cache.h
4965@@ -7,6 +7,7 @@
4966 #ifndef __ARCH_BLACKFIN_CACHE_H
4967 #define __ARCH_BLACKFIN_CACHE_H
4968
4969+#include <linux/const.h>
4970 #include <linux/linkage.h> /* for asmlinkage */
4971
4972 /*
4973@@ -14,7 +15,7 @@
4974 * Blackfin loads 32 bytes for cache
4975 */
4976 #define L1_CACHE_SHIFT 5
4977-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4978+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4979 #define SMP_CACHE_BYTES L1_CACHE_BYTES
4980
4981 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
4982diff --git a/arch/cris/include/arch-v10/arch/cache.h b/arch/cris/include/arch-v10/arch/cache.h
4983index aea2718..3639a60 100644
4984--- a/arch/cris/include/arch-v10/arch/cache.h
4985+++ b/arch/cris/include/arch-v10/arch/cache.h
4986@@ -1,8 +1,9 @@
4987 #ifndef _ASM_ARCH_CACHE_H
4988 #define _ASM_ARCH_CACHE_H
4989
4990+#include <linux/const.h>
4991 /* Etrax 100LX have 32-byte cache-lines. */
4992-#define L1_CACHE_BYTES 32
4993 #define L1_CACHE_SHIFT 5
4994+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4995
4996 #endif /* _ASM_ARCH_CACHE_H */
4997diff --git a/arch/cris/include/arch-v32/arch/cache.h b/arch/cris/include/arch-v32/arch/cache.h
4998index 7caf25d..ee65ac5 100644
4999--- a/arch/cris/include/arch-v32/arch/cache.h
5000+++ b/arch/cris/include/arch-v32/arch/cache.h
5001@@ -1,11 +1,12 @@
5002 #ifndef _ASM_CRIS_ARCH_CACHE_H
5003 #define _ASM_CRIS_ARCH_CACHE_H
5004
5005+#include <linux/const.h>
5006 #include <arch/hwregs/dma.h>
5007
5008 /* A cache-line is 32 bytes. */
5009-#define L1_CACHE_BYTES 32
5010 #define L1_CACHE_SHIFT 5
5011+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5012
5013 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
5014
5015diff --git a/arch/frv/include/asm/atomic.h b/arch/frv/include/asm/atomic.h
5016index 102190a..5334cea 100644
5017--- a/arch/frv/include/asm/atomic.h
5018+++ b/arch/frv/include/asm/atomic.h
5019@@ -181,6 +181,16 @@ static inline void atomic64_dec(atomic64_t *v)
5020 #define atomic64_cmpxchg(v, old, new) (__cmpxchg_64(old, new, &(v)->counter))
5021 #define atomic64_xchg(v, new) (__xchg_64(new, &(v)->counter))
5022
5023+#define atomic64_read_unchecked(v) atomic64_read(v)
5024+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
5025+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
5026+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
5027+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
5028+#define atomic64_inc_unchecked(v) atomic64_inc(v)
5029+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
5030+#define atomic64_dec_unchecked(v) atomic64_dec(v)
5031+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
5032+
5033 static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5034 {
5035 int c, old;
5036diff --git a/arch/frv/include/asm/cache.h b/arch/frv/include/asm/cache.h
5037index 2797163..c2a401df9 100644
5038--- a/arch/frv/include/asm/cache.h
5039+++ b/arch/frv/include/asm/cache.h
5040@@ -12,10 +12,11 @@
5041 #ifndef __ASM_CACHE_H
5042 #define __ASM_CACHE_H
5043
5044+#include <linux/const.h>
5045
5046 /* bytes per L1 cache line */
5047 #define L1_CACHE_SHIFT (CONFIG_FRV_L1_CACHE_SHIFT)
5048-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5049+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5050
5051 #define __cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
5052 #define ____cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
5053diff --git a/arch/frv/include/asm/kmap_types.h b/arch/frv/include/asm/kmap_types.h
5054index 43901f2..0d8b865 100644
5055--- a/arch/frv/include/asm/kmap_types.h
5056+++ b/arch/frv/include/asm/kmap_types.h
5057@@ -2,6 +2,6 @@
5058 #ifndef _ASM_KMAP_TYPES_H
5059 #define _ASM_KMAP_TYPES_H
5060
5061-#define KM_TYPE_NR 17
5062+#define KM_TYPE_NR 18
5063
5064 #endif
5065diff --git a/arch/frv/mm/elf-fdpic.c b/arch/frv/mm/elf-fdpic.c
5066index 836f147..4cf23f5 100644
5067--- a/arch/frv/mm/elf-fdpic.c
5068+++ b/arch/frv/mm/elf-fdpic.c
5069@@ -61,6 +61,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5070 {
5071 struct vm_area_struct *vma;
5072 struct vm_unmapped_area_info info;
5073+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
5074
5075 if (len > TASK_SIZE)
5076 return -ENOMEM;
5077@@ -73,8 +74,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5078 if (addr) {
5079 addr = PAGE_ALIGN(addr);
5080 vma = find_vma(current->mm, addr);
5081- if (TASK_SIZE - len >= addr &&
5082- (!vma || addr + len <= vma->vm_start))
5083+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
5084 goto success;
5085 }
5086
5087@@ -85,6 +85,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5088 info.high_limit = (current->mm->start_stack - 0x00200000);
5089 info.align_mask = 0;
5090 info.align_offset = 0;
5091+ info.threadstack_offset = offset;
5092 addr = vm_unmapped_area(&info);
5093 if (!(addr & ~PAGE_MASK))
5094 goto success;
5095diff --git a/arch/hexagon/include/asm/cache.h b/arch/hexagon/include/asm/cache.h
5096index 2635117..fa223cb 100644
5097--- a/arch/hexagon/include/asm/cache.h
5098+++ b/arch/hexagon/include/asm/cache.h
5099@@ -21,9 +21,11 @@
5100 #ifndef __ASM_CACHE_H
5101 #define __ASM_CACHE_H
5102
5103+#include <linux/const.h>
5104+
5105 /* Bytes per L1 cache line */
5106-#define L1_CACHE_SHIFT (5)
5107-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5108+#define L1_CACHE_SHIFT 5
5109+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5110
5111 #define __cacheline_aligned __aligned(L1_CACHE_BYTES)
5112 #define ____cacheline_aligned __aligned(L1_CACHE_BYTES)
5113diff --git a/arch/ia64/Kconfig b/arch/ia64/Kconfig
5114index c84c88b..2a6e1ba 100644
5115--- a/arch/ia64/Kconfig
5116+++ b/arch/ia64/Kconfig
5117@@ -549,6 +549,7 @@ source "drivers/sn/Kconfig"
5118 config KEXEC
5119 bool "kexec system call"
5120 depends on !IA64_HP_SIM && (!SMP || HOTPLUG_CPU)
5121+ depends on !GRKERNSEC_KMEM
5122 help
5123 kexec is a system call that implements the ability to shutdown your
5124 current kernel, and to start another kernel. It is like a reboot
5125diff --git a/arch/ia64/Makefile b/arch/ia64/Makefile
5126index 5441b14..039a446 100644
5127--- a/arch/ia64/Makefile
5128+++ b/arch/ia64/Makefile
5129@@ -99,5 +99,6 @@ endef
5130 archprepare: make_nr_irqs_h FORCE
5131 PHONY += make_nr_irqs_h FORCE
5132
5133+make_nr_irqs_h: KBUILD_CFLAGS := $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS))
5134 make_nr_irqs_h: FORCE
5135 $(Q)$(MAKE) $(build)=arch/ia64/kernel include/generated/nr-irqs.h
5136diff --git a/arch/ia64/include/asm/atomic.h b/arch/ia64/include/asm/atomic.h
5137index 0bf0350..2ad1957 100644
5138--- a/arch/ia64/include/asm/atomic.h
5139+++ b/arch/ia64/include/asm/atomic.h
5140@@ -193,4 +193,14 @@ atomic64_add_negative (__s64 i, atomic64_t *v)
5141 #define atomic64_inc(v) atomic64_add(1, (v))
5142 #define atomic64_dec(v) atomic64_sub(1, (v))
5143
5144+#define atomic64_read_unchecked(v) atomic64_read(v)
5145+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
5146+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
5147+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
5148+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
5149+#define atomic64_inc_unchecked(v) atomic64_inc(v)
5150+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
5151+#define atomic64_dec_unchecked(v) atomic64_dec(v)
5152+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
5153+
5154 #endif /* _ASM_IA64_ATOMIC_H */
5155diff --git a/arch/ia64/include/asm/barrier.h b/arch/ia64/include/asm/barrier.h
5156index a48957c..e097b56 100644
5157--- a/arch/ia64/include/asm/barrier.h
5158+++ b/arch/ia64/include/asm/barrier.h
5159@@ -67,7 +67,7 @@
5160 do { \
5161 compiletime_assert_atomic_type(*p); \
5162 barrier(); \
5163- ACCESS_ONCE(*p) = (v); \
5164+ ACCESS_ONCE_RW(*p) = (v); \
5165 } while (0)
5166
5167 #define smp_load_acquire(p) \
5168diff --git a/arch/ia64/include/asm/cache.h b/arch/ia64/include/asm/cache.h
5169index 988254a..e1ee885 100644
5170--- a/arch/ia64/include/asm/cache.h
5171+++ b/arch/ia64/include/asm/cache.h
5172@@ -1,6 +1,7 @@
5173 #ifndef _ASM_IA64_CACHE_H
5174 #define _ASM_IA64_CACHE_H
5175
5176+#include <linux/const.h>
5177
5178 /*
5179 * Copyright (C) 1998-2000 Hewlett-Packard Co
5180@@ -9,7 +10,7 @@
5181
5182 /* Bytes per L1 (data) cache line. */
5183 #define L1_CACHE_SHIFT CONFIG_IA64_L1_CACHE_SHIFT
5184-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5185+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5186
5187 #ifdef CONFIG_SMP
5188 # define SMP_CACHE_SHIFT L1_CACHE_SHIFT
5189diff --git a/arch/ia64/include/asm/elf.h b/arch/ia64/include/asm/elf.h
5190index 5a83c5c..4d7f553 100644
5191--- a/arch/ia64/include/asm/elf.h
5192+++ b/arch/ia64/include/asm/elf.h
5193@@ -42,6 +42,13 @@
5194 */
5195 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x800000000UL)
5196
5197+#ifdef CONFIG_PAX_ASLR
5198+#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
5199+
5200+#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
5201+#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
5202+#endif
5203+
5204 #define PT_IA_64_UNWIND 0x70000001
5205
5206 /* IA-64 relocations: */
5207diff --git a/arch/ia64/include/asm/pgalloc.h b/arch/ia64/include/asm/pgalloc.h
5208index 5767cdf..7462574 100644
5209--- a/arch/ia64/include/asm/pgalloc.h
5210+++ b/arch/ia64/include/asm/pgalloc.h
5211@@ -39,6 +39,12 @@ pgd_populate(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
5212 pgd_val(*pgd_entry) = __pa(pud);
5213 }
5214
5215+static inline void
5216+pgd_populate_kernel(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
5217+{
5218+ pgd_populate(mm, pgd_entry, pud);
5219+}
5220+
5221 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
5222 {
5223 return quicklist_alloc(0, GFP_KERNEL, NULL);
5224@@ -57,6 +63,12 @@ pud_populate(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
5225 pud_val(*pud_entry) = __pa(pmd);
5226 }
5227
5228+static inline void
5229+pud_populate_kernel(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
5230+{
5231+ pud_populate(mm, pud_entry, pmd);
5232+}
5233+
5234 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
5235 {
5236 return quicklist_alloc(0, GFP_KERNEL, NULL);
5237diff --git a/arch/ia64/include/asm/pgtable.h b/arch/ia64/include/asm/pgtable.h
5238index 7935115..c0eca6a 100644
5239--- a/arch/ia64/include/asm/pgtable.h
5240+++ b/arch/ia64/include/asm/pgtable.h
5241@@ -12,7 +12,7 @@
5242 * David Mosberger-Tang <davidm@hpl.hp.com>
5243 */
5244
5245-
5246+#include <linux/const.h>
5247 #include <asm/mman.h>
5248 #include <asm/page.h>
5249 #include <asm/processor.h>
5250@@ -142,6 +142,17 @@
5251 #define PAGE_READONLY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5252 #define PAGE_COPY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5253 #define PAGE_COPY_EXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RX)
5254+
5255+#ifdef CONFIG_PAX_PAGEEXEC
5256+# define PAGE_SHARED_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RW)
5257+# define PAGE_READONLY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5258+# define PAGE_COPY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5259+#else
5260+# define PAGE_SHARED_NOEXEC PAGE_SHARED
5261+# define PAGE_READONLY_NOEXEC PAGE_READONLY
5262+# define PAGE_COPY_NOEXEC PAGE_COPY
5263+#endif
5264+
5265 #define PAGE_GATE __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_X_RX)
5266 #define PAGE_KERNEL __pgprot(__DIRTY_BITS | _PAGE_PL_0 | _PAGE_AR_RWX)
5267 #define PAGE_KERNELRX __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_RX)
5268diff --git a/arch/ia64/include/asm/spinlock.h b/arch/ia64/include/asm/spinlock.h
5269index 45698cd..e8e2dbc 100644
5270--- a/arch/ia64/include/asm/spinlock.h
5271+++ b/arch/ia64/include/asm/spinlock.h
5272@@ -71,7 +71,7 @@ static __always_inline void __ticket_spin_unlock(arch_spinlock_t *lock)
5273 unsigned short *p = (unsigned short *)&lock->lock + 1, tmp;
5274
5275 asm volatile ("ld2.bias %0=[%1]" : "=r"(tmp) : "r"(p));
5276- ACCESS_ONCE(*p) = (tmp + 2) & ~1;
5277+ ACCESS_ONCE_RW(*p) = (tmp + 2) & ~1;
5278 }
5279
5280 static __always_inline void __ticket_spin_unlock_wait(arch_spinlock_t *lock)
5281diff --git a/arch/ia64/include/asm/uaccess.h b/arch/ia64/include/asm/uaccess.h
5282index 449c8c0..3d4b1e9 100644
5283--- a/arch/ia64/include/asm/uaccess.h
5284+++ b/arch/ia64/include/asm/uaccess.h
5285@@ -70,6 +70,7 @@
5286 && ((segment).seg == KERNEL_DS.seg \
5287 || likely(REGION_OFFSET((unsigned long) (addr)) < RGN_MAP_LIMIT))); \
5288 })
5289+#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
5290 #define access_ok(type, addr, size) __access_ok((addr), (size), get_fs())
5291
5292 /*
5293@@ -240,12 +241,24 @@ extern unsigned long __must_check __copy_user (void __user *to, const void __use
5294 static inline unsigned long
5295 __copy_to_user (void __user *to, const void *from, unsigned long count)
5296 {
5297+ if (count > INT_MAX)
5298+ return count;
5299+
5300+ if (!__builtin_constant_p(count))
5301+ check_object_size(from, count, true);
5302+
5303 return __copy_user(to, (__force void __user *) from, count);
5304 }
5305
5306 static inline unsigned long
5307 __copy_from_user (void *to, const void __user *from, unsigned long count)
5308 {
5309+ if (count > INT_MAX)
5310+ return count;
5311+
5312+ if (!__builtin_constant_p(count))
5313+ check_object_size(to, count, false);
5314+
5315 return __copy_user((__force void __user *) to, from, count);
5316 }
5317
5318@@ -255,10 +268,13 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
5319 ({ \
5320 void __user *__cu_to = (to); \
5321 const void *__cu_from = (from); \
5322- long __cu_len = (n); \
5323+ unsigned long __cu_len = (n); \
5324 \
5325- if (__access_ok(__cu_to, __cu_len, get_fs())) \
5326+ if (__cu_len <= INT_MAX && __access_ok(__cu_to, __cu_len, get_fs())) { \
5327+ if (!__builtin_constant_p(n)) \
5328+ check_object_size(__cu_from, __cu_len, true); \
5329 __cu_len = __copy_user(__cu_to, (__force void __user *) __cu_from, __cu_len); \
5330+ } \
5331 __cu_len; \
5332 })
5333
5334@@ -266,11 +282,14 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
5335 ({ \
5336 void *__cu_to = (to); \
5337 const void __user *__cu_from = (from); \
5338- long __cu_len = (n); \
5339+ unsigned long __cu_len = (n); \
5340 \
5341 __chk_user_ptr(__cu_from); \
5342- if (__access_ok(__cu_from, __cu_len, get_fs())) \
5343+ if (__cu_len <= INT_MAX && __access_ok(__cu_from, __cu_len, get_fs())) { \
5344+ if (!__builtin_constant_p(n)) \
5345+ check_object_size(__cu_to, __cu_len, false); \
5346 __cu_len = __copy_user((__force void __user *) __cu_to, __cu_from, __cu_len); \
5347+ } \
5348 __cu_len; \
5349 })
5350
5351diff --git a/arch/ia64/kernel/module.c b/arch/ia64/kernel/module.c
5352index 24603be..948052d 100644
5353--- a/arch/ia64/kernel/module.c
5354+++ b/arch/ia64/kernel/module.c
5355@@ -307,8 +307,7 @@ plt_target (struct plt_entry *plt)
5356 void
5357 module_free (struct module *mod, void *module_region)
5358 {
5359- if (mod && mod->arch.init_unw_table &&
5360- module_region == mod->module_init) {
5361+ if (mod && mod->arch.init_unw_table && module_region == mod->module_init_rx) {
5362 unw_remove_unwind_table(mod->arch.init_unw_table);
5363 mod->arch.init_unw_table = NULL;
5364 }
5365@@ -494,15 +493,39 @@ module_frob_arch_sections (Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, char *secstrings,
5366 }
5367
5368 static inline int
5369+in_init_rx (const struct module *mod, uint64_t addr)
5370+{
5371+ return addr - (uint64_t) mod->module_init_rx < mod->init_size_rx;
5372+}
5373+
5374+static inline int
5375+in_init_rw (const struct module *mod, uint64_t addr)
5376+{
5377+ return addr - (uint64_t) mod->module_init_rw < mod->init_size_rw;
5378+}
5379+
5380+static inline int
5381 in_init (const struct module *mod, uint64_t addr)
5382 {
5383- return addr - (uint64_t) mod->module_init < mod->init_size;
5384+ return in_init_rx(mod, addr) || in_init_rw(mod, addr);
5385+}
5386+
5387+static inline int
5388+in_core_rx (const struct module *mod, uint64_t addr)
5389+{
5390+ return addr - (uint64_t) mod->module_core_rx < mod->core_size_rx;
5391+}
5392+
5393+static inline int
5394+in_core_rw (const struct module *mod, uint64_t addr)
5395+{
5396+ return addr - (uint64_t) mod->module_core_rw < mod->core_size_rw;
5397 }
5398
5399 static inline int
5400 in_core (const struct module *mod, uint64_t addr)
5401 {
5402- return addr - (uint64_t) mod->module_core < mod->core_size;
5403+ return in_core_rx(mod, addr) || in_core_rw(mod, addr);
5404 }
5405
5406 static inline int
5407@@ -685,7 +708,14 @@ do_reloc (struct module *mod, uint8_t r_type, Elf64_Sym *sym, uint64_t addend,
5408 break;
5409
5410 case RV_BDREL:
5411- val -= (uint64_t) (in_init(mod, val) ? mod->module_init : mod->module_core);
5412+ if (in_init_rx(mod, val))
5413+ val -= (uint64_t) mod->module_init_rx;
5414+ else if (in_init_rw(mod, val))
5415+ val -= (uint64_t) mod->module_init_rw;
5416+ else if (in_core_rx(mod, val))
5417+ val -= (uint64_t) mod->module_core_rx;
5418+ else if (in_core_rw(mod, val))
5419+ val -= (uint64_t) mod->module_core_rw;
5420 break;
5421
5422 case RV_LTV:
5423@@ -820,15 +850,15 @@ apply_relocate_add (Elf64_Shdr *sechdrs, const char *strtab, unsigned int symind
5424 * addresses have been selected...
5425 */
5426 uint64_t gp;
5427- if (mod->core_size > MAX_LTOFF)
5428+ if (mod->core_size_rx + mod->core_size_rw > MAX_LTOFF)
5429 /*
5430 * This takes advantage of fact that SHF_ARCH_SMALL gets allocated
5431 * at the end of the module.
5432 */
5433- gp = mod->core_size - MAX_LTOFF / 2;
5434+ gp = mod->core_size_rx + mod->core_size_rw - MAX_LTOFF / 2;
5435 else
5436- gp = mod->core_size / 2;
5437- gp = (uint64_t) mod->module_core + ((gp + 7) & -8);
5438+ gp = (mod->core_size_rx + mod->core_size_rw) / 2;
5439+ gp = (uint64_t) mod->module_core_rx + ((gp + 7) & -8);
5440 mod->arch.gp = gp;
5441 DEBUGP("%s: placing gp at 0x%lx\n", __func__, gp);
5442 }
5443diff --git a/arch/ia64/kernel/palinfo.c b/arch/ia64/kernel/palinfo.c
5444index c39c3cd..3c77738 100644
5445--- a/arch/ia64/kernel/palinfo.c
5446+++ b/arch/ia64/kernel/palinfo.c
5447@@ -980,7 +980,7 @@ static int palinfo_cpu_callback(struct notifier_block *nfb,
5448 return NOTIFY_OK;
5449 }
5450
5451-static struct notifier_block __refdata palinfo_cpu_notifier =
5452+static struct notifier_block palinfo_cpu_notifier =
5453 {
5454 .notifier_call = palinfo_cpu_callback,
5455 .priority = 0,
5456diff --git a/arch/ia64/kernel/sys_ia64.c b/arch/ia64/kernel/sys_ia64.c
5457index 41e33f8..65180b2a 100644
5458--- a/arch/ia64/kernel/sys_ia64.c
5459+++ b/arch/ia64/kernel/sys_ia64.c
5460@@ -28,6 +28,7 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5461 unsigned long align_mask = 0;
5462 struct mm_struct *mm = current->mm;
5463 struct vm_unmapped_area_info info;
5464+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
5465
5466 if (len > RGN_MAP_LIMIT)
5467 return -ENOMEM;
5468@@ -43,6 +44,13 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5469 if (REGION_NUMBER(addr) == RGN_HPAGE)
5470 addr = 0;
5471 #endif
5472+
5473+#ifdef CONFIG_PAX_RANDMMAP
5474+ if (mm->pax_flags & MF_PAX_RANDMMAP)
5475+ addr = mm->free_area_cache;
5476+ else
5477+#endif
5478+
5479 if (!addr)
5480 addr = TASK_UNMAPPED_BASE;
5481
5482@@ -61,6 +69,7 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5483 info.high_limit = TASK_SIZE;
5484 info.align_mask = align_mask;
5485 info.align_offset = 0;
5486+ info.threadstack_offset = offset;
5487 return vm_unmapped_area(&info);
5488 }
5489
5490diff --git a/arch/ia64/kernel/vmlinux.lds.S b/arch/ia64/kernel/vmlinux.lds.S
5491index 84f8a52..7c76178 100644
5492--- a/arch/ia64/kernel/vmlinux.lds.S
5493+++ b/arch/ia64/kernel/vmlinux.lds.S
5494@@ -192,7 +192,7 @@ SECTIONS {
5495 /* Per-cpu data: */
5496 . = ALIGN(PERCPU_PAGE_SIZE);
5497 PERCPU_VADDR(SMP_CACHE_BYTES, PERCPU_ADDR, :percpu)
5498- __phys_per_cpu_start = __per_cpu_load;
5499+ __phys_per_cpu_start = per_cpu_load;
5500 /*
5501 * ensure percpu data fits
5502 * into percpu page size
5503diff --git a/arch/ia64/mm/fault.c b/arch/ia64/mm/fault.c
5504index 7225dad..2a7c8256 100644
5505--- a/arch/ia64/mm/fault.c
5506+++ b/arch/ia64/mm/fault.c
5507@@ -72,6 +72,23 @@ mapped_kernel_page_is_present (unsigned long address)
5508 return pte_present(pte);
5509 }
5510
5511+#ifdef CONFIG_PAX_PAGEEXEC
5512+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
5513+{
5514+ unsigned long i;
5515+
5516+ printk(KERN_ERR "PAX: bytes at PC: ");
5517+ for (i = 0; i < 8; i++) {
5518+ unsigned int c;
5519+ if (get_user(c, (unsigned int *)pc+i))
5520+ printk(KERN_CONT "???????? ");
5521+ else
5522+ printk(KERN_CONT "%08x ", c);
5523+ }
5524+ printk("\n");
5525+}
5526+#endif
5527+
5528 # define VM_READ_BIT 0
5529 # define VM_WRITE_BIT 1
5530 # define VM_EXEC_BIT 2
5531@@ -151,8 +168,21 @@ retry:
5532 if (((isr >> IA64_ISR_R_BIT) & 1UL) && (!(vma->vm_flags & (VM_READ | VM_WRITE))))
5533 goto bad_area;
5534
5535- if ((vma->vm_flags & mask) != mask)
5536+ if ((vma->vm_flags & mask) != mask) {
5537+
5538+#ifdef CONFIG_PAX_PAGEEXEC
5539+ if (!(vma->vm_flags & VM_EXEC) && (mask & VM_EXEC)) {
5540+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->cr_iip)
5541+ goto bad_area;
5542+
5543+ up_read(&mm->mmap_sem);
5544+ pax_report_fault(regs, (void *)regs->cr_iip, (void *)regs->r12);
5545+ do_group_exit(SIGKILL);
5546+ }
5547+#endif
5548+
5549 goto bad_area;
5550+ }
5551
5552 /*
5553 * If for any reason at all we couldn't handle the fault, make
5554diff --git a/arch/ia64/mm/hugetlbpage.c b/arch/ia64/mm/hugetlbpage.c
5555index 76069c1..c2aa816 100644
5556--- a/arch/ia64/mm/hugetlbpage.c
5557+++ b/arch/ia64/mm/hugetlbpage.c
5558@@ -149,6 +149,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
5559 unsigned long pgoff, unsigned long flags)
5560 {
5561 struct vm_unmapped_area_info info;
5562+ unsigned long offset = gr_rand_threadstack_offset(current->mm, file, flags);
5563
5564 if (len > RGN_MAP_LIMIT)
5565 return -ENOMEM;
5566@@ -172,6 +173,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
5567 info.high_limit = HPAGE_REGION_BASE + RGN_MAP_LIMIT;
5568 info.align_mask = PAGE_MASK & (HPAGE_SIZE - 1);
5569 info.align_offset = 0;
5570+ info.threadstack_offset = offset;
5571 return vm_unmapped_area(&info);
5572 }
5573
5574diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c
5575index 6b33457..88b5124 100644
5576--- a/arch/ia64/mm/init.c
5577+++ b/arch/ia64/mm/init.c
5578@@ -120,6 +120,19 @@ ia64_init_addr_space (void)
5579 vma->vm_start = current->thread.rbs_bot & PAGE_MASK;
5580 vma->vm_end = vma->vm_start + PAGE_SIZE;
5581 vma->vm_flags = VM_DATA_DEFAULT_FLAGS|VM_GROWSUP|VM_ACCOUNT;
5582+
5583+#ifdef CONFIG_PAX_PAGEEXEC
5584+ if (current->mm->pax_flags & MF_PAX_PAGEEXEC) {
5585+ vma->vm_flags &= ~VM_EXEC;
5586+
5587+#ifdef CONFIG_PAX_MPROTECT
5588+ if (current->mm->pax_flags & MF_PAX_MPROTECT)
5589+ vma->vm_flags &= ~VM_MAYEXEC;
5590+#endif
5591+
5592+ }
5593+#endif
5594+
5595 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
5596 down_write(&current->mm->mmap_sem);
5597 if (insert_vm_struct(current->mm, vma)) {
5598@@ -286,7 +299,7 @@ static int __init gate_vma_init(void)
5599 gate_vma.vm_start = FIXADDR_USER_START;
5600 gate_vma.vm_end = FIXADDR_USER_END;
5601 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
5602- gate_vma.vm_page_prot = __P101;
5603+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
5604
5605 return 0;
5606 }
5607diff --git a/arch/m32r/include/asm/cache.h b/arch/m32r/include/asm/cache.h
5608index 40b3ee9..8c2c112 100644
5609--- a/arch/m32r/include/asm/cache.h
5610+++ b/arch/m32r/include/asm/cache.h
5611@@ -1,8 +1,10 @@
5612 #ifndef _ASM_M32R_CACHE_H
5613 #define _ASM_M32R_CACHE_H
5614
5615+#include <linux/const.h>
5616+
5617 /* L1 cache line size */
5618 #define L1_CACHE_SHIFT 4
5619-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5620+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5621
5622 #endif /* _ASM_M32R_CACHE_H */
5623diff --git a/arch/m32r/lib/usercopy.c b/arch/m32r/lib/usercopy.c
5624index 82abd15..d95ae5d 100644
5625--- a/arch/m32r/lib/usercopy.c
5626+++ b/arch/m32r/lib/usercopy.c
5627@@ -14,6 +14,9 @@
5628 unsigned long
5629 __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
5630 {
5631+ if ((long)n < 0)
5632+ return n;
5633+
5634 prefetch(from);
5635 if (access_ok(VERIFY_WRITE, to, n))
5636 __copy_user(to,from,n);
5637@@ -23,6 +26,9 @@ __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
5638 unsigned long
5639 __generic_copy_from_user(void *to, const void __user *from, unsigned long n)
5640 {
5641+ if ((long)n < 0)
5642+ return n;
5643+
5644 prefetchw(to);
5645 if (access_ok(VERIFY_READ, from, n))
5646 __copy_user_zeroing(to,from,n);
5647diff --git a/arch/m68k/include/asm/cache.h b/arch/m68k/include/asm/cache.h
5648index 0395c51..5f26031 100644
5649--- a/arch/m68k/include/asm/cache.h
5650+++ b/arch/m68k/include/asm/cache.h
5651@@ -4,9 +4,11 @@
5652 #ifndef __ARCH_M68K_CACHE_H
5653 #define __ARCH_M68K_CACHE_H
5654
5655+#include <linux/const.h>
5656+
5657 /* bytes per L1 cache line */
5658 #define L1_CACHE_SHIFT 4
5659-#define L1_CACHE_BYTES (1<< L1_CACHE_SHIFT)
5660+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5661
5662 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
5663
5664diff --git a/arch/metag/include/asm/barrier.h b/arch/metag/include/asm/barrier.h
5665index c7591e8..ecef036 100644
5666--- a/arch/metag/include/asm/barrier.h
5667+++ b/arch/metag/include/asm/barrier.h
5668@@ -89,7 +89,7 @@ static inline void fence(void)
5669 do { \
5670 compiletime_assert_atomic_type(*p); \
5671 smp_mb(); \
5672- ACCESS_ONCE(*p) = (v); \
5673+ ACCESS_ONCE_RW(*p) = (v); \
5674 } while (0)
5675
5676 #define smp_load_acquire(p) \
5677diff --git a/arch/metag/mm/hugetlbpage.c b/arch/metag/mm/hugetlbpage.c
5678index 3c32075..ae0ae75 100644
5679--- a/arch/metag/mm/hugetlbpage.c
5680+++ b/arch/metag/mm/hugetlbpage.c
5681@@ -200,6 +200,7 @@ hugetlb_get_unmapped_area_new_pmd(unsigned long len)
5682 info.high_limit = TASK_SIZE;
5683 info.align_mask = PAGE_MASK & HUGEPT_MASK;
5684 info.align_offset = 0;
5685+ info.threadstack_offset = 0;
5686 return vm_unmapped_area(&info);
5687 }
5688
5689diff --git a/arch/microblaze/include/asm/cache.h b/arch/microblaze/include/asm/cache.h
5690index 4efe96a..60e8699 100644
5691--- a/arch/microblaze/include/asm/cache.h
5692+++ b/arch/microblaze/include/asm/cache.h
5693@@ -13,11 +13,12 @@
5694 #ifndef _ASM_MICROBLAZE_CACHE_H
5695 #define _ASM_MICROBLAZE_CACHE_H
5696
5697+#include <linux/const.h>
5698 #include <asm/registers.h>
5699
5700 #define L1_CACHE_SHIFT 5
5701 /* word-granular cache in microblaze */
5702-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5703+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5704
5705 #define SMP_CACHE_BYTES L1_CACHE_BYTES
5706
5707diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig
5708index 9536ef9..9333776 100644
5709--- a/arch/mips/Kconfig
5710+++ b/arch/mips/Kconfig
5711@@ -2413,6 +2413,7 @@ source "kernel/Kconfig.preempt"
5712
5713 config KEXEC
5714 bool "Kexec system call"
5715+ depends on !GRKERNSEC_KMEM
5716 help
5717 kexec is a system call that implements the ability to shutdown your
5718 current kernel, and to start another kernel. It is like a reboot
5719diff --git a/arch/mips/cavium-octeon/dma-octeon.c b/arch/mips/cavium-octeon/dma-octeon.c
5720index 02f2444..506969c 100644
5721--- a/arch/mips/cavium-octeon/dma-octeon.c
5722+++ b/arch/mips/cavium-octeon/dma-octeon.c
5723@@ -199,7 +199,7 @@ static void octeon_dma_free_coherent(struct device *dev, size_t size,
5724 if (dma_release_from_coherent(dev, order, vaddr))
5725 return;
5726
5727- swiotlb_free_coherent(dev, size, vaddr, dma_handle);
5728+ swiotlb_free_coherent(dev, size, vaddr, dma_handle, attrs);
5729 }
5730
5731 static dma_addr_t octeon_unity_phys_to_dma(struct device *dev, phys_addr_t paddr)
5732diff --git a/arch/mips/include/asm/atomic.h b/arch/mips/include/asm/atomic.h
5733index 6dd6bfc..903b0d6 100644
5734--- a/arch/mips/include/asm/atomic.h
5735+++ b/arch/mips/include/asm/atomic.h
5736@@ -21,15 +21,39 @@
5737 #include <asm/cmpxchg.h>
5738 #include <asm/war.h>
5739
5740+#ifdef CONFIG_GENERIC_ATOMIC64
5741+#include <asm-generic/atomic64.h>
5742+#endif
5743+
5744 #define ATOMIC_INIT(i) { (i) }
5745
5746+#ifdef CONFIG_64BIT
5747+#define _ASM_EXTABLE(from, to) \
5748+" .section __ex_table,\"a\"\n" \
5749+" .dword " #from ", " #to"\n" \
5750+" .previous\n"
5751+#else
5752+#define _ASM_EXTABLE(from, to) \
5753+" .section __ex_table,\"a\"\n" \
5754+" .word " #from ", " #to"\n" \
5755+" .previous\n"
5756+#endif
5757+
5758 /*
5759 * atomic_read - read atomic variable
5760 * @v: pointer of type atomic_t
5761 *
5762 * Atomically reads the value of @v.
5763 */
5764-#define atomic_read(v) ACCESS_ONCE((v)->counter)
5765+static inline int atomic_read(const atomic_t *v)
5766+{
5767+ return ACCESS_ONCE(v->counter);
5768+}
5769+
5770+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
5771+{
5772+ return ACCESS_ONCE(v->counter);
5773+}
5774
5775 /*
5776 * atomic_set - set atomic variable
5777@@ -38,47 +62,77 @@
5778 *
5779 * Atomically sets the value of @v to @i.
5780 */
5781-#define atomic_set(v, i) ((v)->counter = (i))
5782+static inline void atomic_set(atomic_t *v, int i)
5783+{
5784+ v->counter = i;
5785+}
5786
5787-#define ATOMIC_OP(op, c_op, asm_op) \
5788-static __inline__ void atomic_##op(int i, atomic_t * v) \
5789+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
5790+{
5791+ v->counter = i;
5792+}
5793+
5794+#ifdef CONFIG_PAX_REFCOUNT
5795+#define __OVERFLOW_POST \
5796+ " b 4f \n" \
5797+ " .set noreorder \n" \
5798+ "3: b 5f \n" \
5799+ " move %0, %1 \n" \
5800+ " .set reorder \n"
5801+#define __OVERFLOW_EXTABLE \
5802+ "3:\n" \
5803+ _ASM_EXTABLE(2b, 3b)
5804+#else
5805+#define __OVERFLOW_POST
5806+#define __OVERFLOW_EXTABLE
5807+#endif
5808+
5809+#define __ATOMIC_OP(op, suffix, asm_op, extable) \
5810+static inline void atomic_##op##suffix(int i, atomic##suffix##_t * v) \
5811 { \
5812 if (kernel_uses_llsc && R10000_LLSC_WAR) { \
5813 int temp; \
5814 \
5815 __asm__ __volatile__( \
5816- " .set arch=r4000 \n" \
5817- "1: ll %0, %1 # atomic_" #op " \n" \
5818- " " #asm_op " %0, %2 \n" \
5819+ " .set mips3 \n" \
5820+ "1: ll %0, %1 # atomic_" #op #suffix "\n" \
5821+ "2: " #asm_op " %0, %2 \n" \
5822 " sc %0, %1 \n" \
5823 " beqzl %0, 1b \n" \
5824+ extable \
5825 " .set mips0 \n" \
5826 : "=&r" (temp), "+m" (v->counter) \
5827 : "Ir" (i)); \
5828 } else if (kernel_uses_llsc) { \
5829 int temp; \
5830 \
5831- do { \
5832- __asm__ __volatile__( \
5833- " .set arch=r4000 \n" \
5834- " ll %0, %1 # atomic_" #op "\n" \
5835- " " #asm_op " %0, %2 \n" \
5836- " sc %0, %1 \n" \
5837- " .set mips0 \n" \
5838- : "=&r" (temp), "+m" (v->counter) \
5839- : "Ir" (i)); \
5840- } while (unlikely(!temp)); \
5841+ __asm__ __volatile__( \
5842+ " .set mips3 \n" \
5843+ " ll %0, %1 # atomic_" #op #suffix "\n" \
5844+ "2: " #asm_op " %0, %2 \n" \
5845+ " sc %0, %1 \n" \
5846+ " beqz %0, 1b \n" \
5847+ extable \
5848+ " .set mips0 \n" \
5849+ : "=&r" (temp), "+m" (v->counter) \
5850+ : "Ir" (i)); \
5851 } else { \
5852 unsigned long flags; \
5853 \
5854 raw_local_irq_save(flags); \
5855- v->counter c_op i; \
5856+ __asm__ __volatile__( \
5857+ "2: " #asm_op " %0, %1 \n" \
5858+ extable \
5859+ : "+r" (v->counter) : "Ir" (i)); \
5860 raw_local_irq_restore(flags); \
5861 } \
5862 } \
5863
5864-#define ATOMIC_OP_RETURN(op, c_op, asm_op) \
5865-static __inline__ int atomic_##op##_return(int i, atomic_t * v) \
5866+#define ATOMIC_OP(op, asm_op) __ATOMIC_OP(op, , asm_op##u) \
5867+ __ATOMIC_OP(op, _unchecked, asm_op)
5868+
5869+#define __ATOMIC_OP_RETURN(op, suffix, asm_op, post_op, extable) \
5870+static inline int atomic_##op##_return##suffix(int i, atomic##suffix##_t * v) \
5871 { \
5872 int result; \
5873 \
5874@@ -88,37 +142,47 @@ static __inline__ int atomic_##op##_return(int i, atomic_t * v) \
5875 int temp; \
5876 \
5877 __asm__ __volatile__( \
5878- " .set arch=r4000 \n" \
5879- "1: ll %1, %2 # atomic_" #op "_return \n" \
5880- " " #asm_op " %0, %1, %3 \n" \
5881+ " .set mips3 \n" \
5882+ "1: ll %1, %2 # atomic_" #op "_return" #suffix "\n" \
5883+ "2: " #asm_op " %0, %1, %3 \n" \
5884 " sc %0, %2 \n" \
5885 " beqzl %0, 1b \n" \
5886- " " #asm_op " %0, %1, %3 \n" \
5887+ post_op \
5888+ extable \
5889+ "4: " #asm_op " %0, %1, %3 \n" \
5890+ "5: \n" \
5891 " .set mips0 \n" \
5892 : "=&r" (result), "=&r" (temp), "+m" (v->counter) \
5893 : "Ir" (i)); \
5894 } else if (kernel_uses_llsc) { \
5895 int temp; \
5896 \
5897- do { \
5898- __asm__ __volatile__( \
5899- " .set arch=r4000 \n" \
5900- " ll %1, %2 # atomic_" #op "_return \n" \
5901- " " #asm_op " %0, %1, %3 \n" \
5902- " sc %0, %2 \n" \
5903- " .set mips0 \n" \
5904- : "=&r" (result), "=&r" (temp), "+m" (v->counter) \
5905- : "Ir" (i)); \
5906- } while (unlikely(!result)); \
5907+ __asm__ __volatile__( \
5908+ " .set mips3 \n" \
5909+ "1: ll %1, %2 # atomic_" #op "_return" #suffix "\n" \
5910+ "2: " #asm_op " %0, %1, %3 \n" \
5911+ " sc %0, %2 \n" \
5912+ " beqz %0, 1b \n" \
5913+ post_op \
5914+ extable \
5915+ "4: " #asm_op " %0, %1, %3 \n" \
5916+ "5: \n" \
5917+ " .set mips0 \n" \
5918+ : "=&r" (result), "=&r" (temp), "+m" (v->counter) \
5919+ : "Ir" (i)); \
5920 \
5921 result = temp; result c_op i; \
5922 } else { \
5923 unsigned long flags; \
5924 \
5925 raw_local_irq_save(flags); \
5926- result = v->counter; \
5927- result c_op i; \
5928- v->counter = result; \
5929+ __asm__ __volatile__( \
5930+ " lw %0, %1 \n" \
5931+ "2: " #asm_op " %0, %1, %2 \n" \
5932+ " sw %0, %1 \n" \
5933+ "3: \n" \
5934+ extable \
5935+ : "=&r" (result), "+m" (v->counter) : "Ir" (i)); \
5936 raw_local_irq_restore(flags); \
5937 } \
5938 \
5939@@ -127,16 +191,21 @@ static __inline__ int atomic_##op##_return(int i, atomic_t * v) \
5940 return result; \
5941 }
5942
5943-#define ATOMIC_OPS(op, c_op, asm_op) \
5944- ATOMIC_OP(op, c_op, asm_op) \
5945- ATOMIC_OP_RETURN(op, c_op, asm_op)
5946+#define ATOMIC_OP_RETURN(op, asm_op) __ATOMIC_OP_RETURN(op, , asm_op##u, , __OVERFLOW_EXTABLE) \
5947+ __ATOMIC_OP_RETURN(op, _unchecked, asm_op, __OVERFLOW_POST, __OVERFLOW_EXTABLE)
5948
5949-ATOMIC_OPS(add, +=, addu)
5950-ATOMIC_OPS(sub, -=, subu)
5951+#define ATOMIC_OPS(op, asm_op) \
5952+ ATOMIC_OP(op, asm_op) \
5953+ ATOMIC_OP_RETURN(op, asm_op)
5954+
5955+ATOMIC_OPS(add, add)
5956+ATOMIC_OPS(sub, sub)
5957
5958 #undef ATOMIC_OPS
5959 #undef ATOMIC_OP_RETURN
5960+#undef __ATOMIC_OP_RETURN
5961 #undef ATOMIC_OP
5962+#undef __ATOMIC_OP
5963
5964 /*
5965 * atomic_sub_if_positive - conditionally subtract integer from atomic variable
5966@@ -146,7 +215,7 @@ ATOMIC_OPS(sub, -=, subu)
5967 * Atomically test @v and subtract @i if @v is greater or equal than @i.
5968 * The function returns the old value of @v minus @i.
5969 */
5970-static __inline__ int atomic_sub_if_positive(int i, atomic_t * v)
5971+static __inline__ int atomic_sub_if_positive(int i, atomic_t *v)
5972 {
5973 int result;
5974
5975@@ -203,8 +272,26 @@ static __inline__ int atomic_sub_if_positive(int i, atomic_t * v)
5976 return result;
5977 }
5978
5979-#define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
5980-#define atomic_xchg(v, new) (xchg(&((v)->counter), (new)))
5981+static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
5982+{
5983+ return cmpxchg(&v->counter, old, new);
5984+}
5985+
5986+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old,
5987+ int new)
5988+{
5989+ return cmpxchg(&(v->counter), old, new);
5990+}
5991+
5992+static inline int atomic_xchg(atomic_t *v, int new)
5993+{
5994+ return xchg(&v->counter, new);
5995+}
5996+
5997+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
5998+{
5999+ return xchg(&(v->counter), new);
6000+}
6001
6002 /**
6003 * __atomic_add_unless - add unless the number is a given value
6004@@ -232,6 +319,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6005
6006 #define atomic_dec_return(v) atomic_sub_return(1, (v))
6007 #define atomic_inc_return(v) atomic_add_return(1, (v))
6008+static __inline__ int atomic_inc_return_unchecked(atomic_unchecked_t *v)
6009+{
6010+ return atomic_add_return_unchecked(1, v);
6011+}
6012
6013 /*
6014 * atomic_sub_and_test - subtract value from variable and test result
6015@@ -253,6 +344,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6016 * other cases.
6017 */
6018 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
6019+static __inline__ int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
6020+{
6021+ return atomic_add_return_unchecked(1, v) == 0;
6022+}
6023
6024 /*
6025 * atomic_dec_and_test - decrement by 1 and test
6026@@ -277,6 +372,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6027 * Atomically increments @v by 1.
6028 */
6029 #define atomic_inc(v) atomic_add(1, (v))
6030+static __inline__ void atomic_inc_unchecked(atomic_unchecked_t *v)
6031+{
6032+ atomic_add_unchecked(1, v);
6033+}
6034
6035 /*
6036 * atomic_dec - decrement and test
6037@@ -285,6 +384,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6038 * Atomically decrements @v by 1.
6039 */
6040 #define atomic_dec(v) atomic_sub(1, (v))
6041+static __inline__ void atomic_dec_unchecked(atomic_unchecked_t *v)
6042+{
6043+ atomic_sub_unchecked(1, v);
6044+}
6045
6046 /*
6047 * atomic_add_negative - add and test if negative
6048@@ -306,54 +409,77 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6049 * @v: pointer of type atomic64_t
6050 *
6051 */
6052-#define atomic64_read(v) ACCESS_ONCE((v)->counter)
6053+static inline long atomic64_read(const atomic64_t *v)
6054+{
6055+ return ACCESS_ONCE(v->counter);
6056+}
6057+
6058+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
6059+{
6060+ return ACCESS_ONCE(v->counter);
6061+}
6062
6063 /*
6064 * atomic64_set - set atomic variable
6065 * @v: pointer of type atomic64_t
6066 * @i: required value
6067 */
6068-#define atomic64_set(v, i) ((v)->counter = (i))
6069+static inline void atomic64_set(atomic64_t *v, long i)
6070+{
6071+ v->counter = i;
6072+}
6073
6074-#define ATOMIC64_OP(op, c_op, asm_op) \
6075-static __inline__ void atomic64_##op(long i, atomic64_t * v) \
6076+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
6077+{
6078+ v->counter = i;
6079+}
6080+
6081+#define __ATOMIC64_OP(op, suffix, asm_op, extable) \
6082+static inline void atomic64_##op##suffix(long i, atomic64##suffix##_t * v) \
6083 { \
6084 if (kernel_uses_llsc && R10000_LLSC_WAR) { \
6085 long temp; \
6086 \
6087 __asm__ __volatile__( \
6088- " .set arch=r4000 \n" \
6089- "1: lld %0, %1 # atomic64_" #op " \n" \
6090- " " #asm_op " %0, %2 \n" \
6091+ " .set mips3 \n" \
6092+ "1: lld %0, %1 # atomic64_" #op #suffix "\n" \
6093+ "2: " #asm_op " %0, %2 \n" \
6094 " scd %0, %1 \n" \
6095 " beqzl %0, 1b \n" \
6096+ extable \
6097 " .set mips0 \n" \
6098 : "=&r" (temp), "+m" (v->counter) \
6099 : "Ir" (i)); \
6100 } else if (kernel_uses_llsc) { \
6101 long temp; \
6102 \
6103- do { \
6104- __asm__ __volatile__( \
6105- " .set arch=r4000 \n" \
6106- " lld %0, %1 # atomic64_" #op "\n" \
6107- " " #asm_op " %0, %2 \n" \
6108- " scd %0, %1 \n" \
6109- " .set mips0 \n" \
6110- : "=&r" (temp), "+m" (v->counter) \
6111- : "Ir" (i)); \
6112- } while (unlikely(!temp)); \
6113+ __asm__ __volatile__( \
6114+ " .set mips3 \n" \
6115+ " lld %0, %1 # atomic64_" #op #suffix "\n" \
6116+ "2: " #asm_op " %0, %2 \n" \
6117+ " scd %0, %1 \n" \
6118+ " beqz %0, 1b \n" \
6119+ extable \
6120+ " .set mips0 \n" \
6121+ : "=&r" (temp), "+m" (v->counter) \
6122+ : "Ir" (i)); \
6123 } else { \
6124 unsigned long flags; \
6125 \
6126 raw_local_irq_save(flags); \
6127- v->counter c_op i; \
6128+ __asm__ __volatile__( \
6129+ "2: " #asm_op " %0, %1 \n" \
6130+ extable \
6131+ : "+r" (v->counter) : "Ir" (i)); \
6132 raw_local_irq_restore(flags); \
6133 } \
6134 } \
6135
6136-#define ATOMIC64_OP_RETURN(op, c_op, asm_op) \
6137-static __inline__ long atomic64_##op##_return(long i, atomic64_t * v) \
6138+#define ATOMIC64_OP(op, asm_op) __ATOMIC64_OP(op, , asm_op##u) \
6139+ __ATOMIC64_OP(op, _unchecked, asm_op)
6140+
6141+#define __ATOMIC64_OP_RETURN(op, suffix, asm_op, post_op, extable) \
6142+static inline long atomic64_##op##_return##suffix(long i, atomic64##suffix##_t * v)\
6143 { \
6144 long result; \
6145 \
6146@@ -363,38 +489,48 @@ static __inline__ long atomic64_##op##_return(long i, atomic64_t * v) \
6147 long temp; \
6148 \
6149 __asm__ __volatile__( \
6150- " .set arch=r4000 \n" \
6151+ " .set mips3 \n" \
6152 "1: lld %1, %2 # atomic64_" #op "_return\n" \
6153- " " #asm_op " %0, %1, %3 \n" \
6154+ "2: " #asm_op " %0, %1, %3 \n" \
6155 " scd %0, %2 \n" \
6156 " beqzl %0, 1b \n" \
6157- " " #asm_op " %0, %1, %3 \n" \
6158+ post_op \
6159+ extable \
6160+ "4: " #asm_op " %0, %1, %3 \n" \
6161+ "5: \n" \
6162 " .set mips0 \n" \
6163 : "=&r" (result), "=&r" (temp), "+m" (v->counter) \
6164 : "Ir" (i)); \
6165 } else if (kernel_uses_llsc) { \
6166 long temp; \
6167 \
6168- do { \
6169- __asm__ __volatile__( \
6170- " .set arch=r4000 \n" \
6171- " lld %1, %2 # atomic64_" #op "_return\n" \
6172- " " #asm_op " %0, %1, %3 \n" \
6173- " scd %0, %2 \n" \
6174- " .set mips0 \n" \
6175- : "=&r" (result), "=&r" (temp), "=m" (v->counter) \
6176- : "Ir" (i), "m" (v->counter) \
6177- : "memory"); \
6178- } while (unlikely(!result)); \
6179+ __asm__ __volatile__( \
6180+ " .set mips3 \n" \
6181+ "1: lld %1, %2 # atomic64_" #op "_return" #suffix "\n" \
6182+ "2: " #asm_op " %0, %1, %3 \n" \
6183+ " scd %0, %2 \n" \
6184+ " beqz %0, 1b \n" \
6185+ post_op \
6186+ extable \
6187+ "4: " #asm_op " %0, %1, %3 \n" \
6188+ "5: \n" \
6189+ " .set mips0 \n" \
6190+ : "=&r" (result), "=&r" (temp), "=m" (v->counter) \
6191+ : "Ir" (i), "m" (v->counter) \
6192+ : "memory"); \
6193 \
6194 result = temp; result c_op i; \
6195 } else { \
6196 unsigned long flags; \
6197 \
6198 raw_local_irq_save(flags); \
6199- result = v->counter; \
6200- result c_op i; \
6201- v->counter = result; \
6202+ __asm__ __volatile__( \
6203+ " ld %0, %1 \n" \
6204+ "2: " #asm_op " %0, %1, %2 \n" \
6205+ " sd %0, %1 \n" \
6206+ "3: \n" \
6207+ extable \
6208+ : "=&r" (result), "+m" (v->counter) : "Ir" (i)); \
6209 raw_local_irq_restore(flags); \
6210 } \
6211 \
6212@@ -403,16 +539,23 @@ static __inline__ long atomic64_##op##_return(long i, atomic64_t * v) \
6213 return result; \
6214 }
6215
6216-#define ATOMIC64_OPS(op, c_op, asm_op) \
6217- ATOMIC64_OP(op, c_op, asm_op) \
6218- ATOMIC64_OP_RETURN(op, c_op, asm_op)
6219+#define ATOMIC64_OP_RETURN(op, asm_op) __ATOMIC64_OP_RETURN(op, , asm_op##u, , __OVERFLOW_EXTABLE) \
6220+ __ATOMIC64_OP_RETURN(op, _unchecked, asm_op, __OVERFLOW_POST, __OVERFLOW_EXTABLE)
6221
6222-ATOMIC64_OPS(add, +=, daddu)
6223-ATOMIC64_OPS(sub, -=, dsubu)
6224+#define ATOMIC64_OPS(op, asm_op) \
6225+ ATOMIC64_OP(op, asm_op) \
6226+ ATOMIC64_OP_RETURN(op, asm_op)
6227+
6228+ATOMIC64_OPS(add, dadd)
6229+ATOMIC64_OPS(sub, dsub)
6230
6231 #undef ATOMIC64_OPS
6232 #undef ATOMIC64_OP_RETURN
6233+#undef __ATOMIC64_OP_RETURN
6234 #undef ATOMIC64_OP
6235+#undef __ATOMIC64_OP
6236+#undef __OVERFLOW_EXTABLE
6237+#undef __OVERFLOW_POST
6238
6239 /*
6240 * atomic64_sub_if_positive - conditionally subtract integer from atomic variable
6241@@ -422,7 +565,7 @@ ATOMIC64_OPS(sub, -=, dsubu)
6242 * Atomically test @v and subtract @i if @v is greater or equal than @i.
6243 * The function returns the old value of @v minus @i.
6244 */
6245-static __inline__ long atomic64_sub_if_positive(long i, atomic64_t * v)
6246+static __inline__ long atomic64_sub_if_positive(long i, atomic64_t *v)
6247 {
6248 long result;
6249
6250@@ -479,9 +622,26 @@ static __inline__ long atomic64_sub_if_positive(long i, atomic64_t * v)
6251 return result;
6252 }
6253
6254-#define atomic64_cmpxchg(v, o, n) \
6255- ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
6256-#define atomic64_xchg(v, new) (xchg(&((v)->counter), (new)))
6257+static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
6258+{
6259+ return cmpxchg(&v->counter, old, new);
6260+}
6261+
6262+static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old,
6263+ long new)
6264+{
6265+ return cmpxchg(&(v->counter), old, new);
6266+}
6267+
6268+static inline long atomic64_xchg(atomic64_t *v, long new)
6269+{
6270+ return xchg(&v->counter, new);
6271+}
6272+
6273+static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
6274+{
6275+ return xchg(&(v->counter), new);
6276+}
6277
6278 /**
6279 * atomic64_add_unless - add unless the number is a given value
6280@@ -511,6 +671,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6281
6282 #define atomic64_dec_return(v) atomic64_sub_return(1, (v))
6283 #define atomic64_inc_return(v) atomic64_add_return(1, (v))
6284+#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1, (v))
6285
6286 /*
6287 * atomic64_sub_and_test - subtract value from variable and test result
6288@@ -532,6 +693,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6289 * other cases.
6290 */
6291 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
6292+#define atomic64_inc_and_test_unchecked(v) atomic64_add_return_unchecked(1, (v)) == 0)
6293
6294 /*
6295 * atomic64_dec_and_test - decrement by 1 and test
6296@@ -556,6 +718,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6297 * Atomically increments @v by 1.
6298 */
6299 #define atomic64_inc(v) atomic64_add(1, (v))
6300+#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1, (v))
6301
6302 /*
6303 * atomic64_dec - decrement and test
6304@@ -564,6 +727,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6305 * Atomically decrements @v by 1.
6306 */
6307 #define atomic64_dec(v) atomic64_sub(1, (v))
6308+#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1, (v))
6309
6310 /*
6311 * atomic64_add_negative - add and test if negative
6312diff --git a/arch/mips/include/asm/barrier.h b/arch/mips/include/asm/barrier.h
6313index d0101dd..266982c 100644
6314--- a/arch/mips/include/asm/barrier.h
6315+++ b/arch/mips/include/asm/barrier.h
6316@@ -184,7 +184,7 @@
6317 do { \
6318 compiletime_assert_atomic_type(*p); \
6319 smp_mb(); \
6320- ACCESS_ONCE(*p) = (v); \
6321+ ACCESS_ONCE_RW(*p) = (v); \
6322 } while (0)
6323
6324 #define smp_load_acquire(p) \
6325diff --git a/arch/mips/include/asm/cache.h b/arch/mips/include/asm/cache.h
6326index b4db69f..8f3b093 100644
6327--- a/arch/mips/include/asm/cache.h
6328+++ b/arch/mips/include/asm/cache.h
6329@@ -9,10 +9,11 @@
6330 #ifndef _ASM_CACHE_H
6331 #define _ASM_CACHE_H
6332
6333+#include <linux/const.h>
6334 #include <kmalloc.h>
6335
6336 #define L1_CACHE_SHIFT CONFIG_MIPS_L1_CACHE_SHIFT
6337-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
6338+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
6339
6340 #define SMP_CACHE_SHIFT L1_CACHE_SHIFT
6341 #define SMP_CACHE_BYTES L1_CACHE_BYTES
6342diff --git a/arch/mips/include/asm/elf.h b/arch/mips/include/asm/elf.h
6343index 1d38fe0..9beabc9 100644
6344--- a/arch/mips/include/asm/elf.h
6345+++ b/arch/mips/include/asm/elf.h
6346@@ -381,13 +381,16 @@ extern const char *__elf_platform;
6347 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
6348 #endif
6349
6350+#ifdef CONFIG_PAX_ASLR
6351+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
6352+
6353+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6354+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6355+#endif
6356+
6357 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
6358 struct linux_binprm;
6359 extern int arch_setup_additional_pages(struct linux_binprm *bprm,
6360 int uses_interp);
6361
6362-struct mm_struct;
6363-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
6364-#define arch_randomize_brk arch_randomize_brk
6365-
6366 #endif /* _ASM_ELF_H */
6367diff --git a/arch/mips/include/asm/exec.h b/arch/mips/include/asm/exec.h
6368index c1f6afa..38cc6e9 100644
6369--- a/arch/mips/include/asm/exec.h
6370+++ b/arch/mips/include/asm/exec.h
6371@@ -12,6 +12,6 @@
6372 #ifndef _ASM_EXEC_H
6373 #define _ASM_EXEC_H
6374
6375-extern unsigned long arch_align_stack(unsigned long sp);
6376+#define arch_align_stack(x) ((x) & ~0xfUL)
6377
6378 #endif /* _ASM_EXEC_H */
6379diff --git a/arch/mips/include/asm/hw_irq.h b/arch/mips/include/asm/hw_irq.h
6380index 9e8ef59..1139d6b 100644
6381--- a/arch/mips/include/asm/hw_irq.h
6382+++ b/arch/mips/include/asm/hw_irq.h
6383@@ -10,7 +10,7 @@
6384
6385 #include <linux/atomic.h>
6386
6387-extern atomic_t irq_err_count;
6388+extern atomic_unchecked_t irq_err_count;
6389
6390 /*
6391 * interrupt-retrigger: NOP for now. This may not be appropriate for all
6392diff --git a/arch/mips/include/asm/local.h b/arch/mips/include/asm/local.h
6393index 46dfc3c..a16b13a 100644
6394--- a/arch/mips/include/asm/local.h
6395+++ b/arch/mips/include/asm/local.h
6396@@ -12,15 +12,25 @@ typedef struct
6397 atomic_long_t a;
6398 } local_t;
6399
6400+typedef struct {
6401+ atomic_long_unchecked_t a;
6402+} local_unchecked_t;
6403+
6404 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
6405
6406 #define local_read(l) atomic_long_read(&(l)->a)
6407+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
6408 #define local_set(l, i) atomic_long_set(&(l)->a, (i))
6409+#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
6410
6411 #define local_add(i, l) atomic_long_add((i), (&(l)->a))
6412+#define local_add_unchecked(i, l) atomic_long_add_unchecked((i), (&(l)->a))
6413 #define local_sub(i, l) atomic_long_sub((i), (&(l)->a))
6414+#define local_sub_unchecked(i, l) atomic_long_sub_unchecked((i), (&(l)->a))
6415 #define local_inc(l) atomic_long_inc(&(l)->a)
6416+#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
6417 #define local_dec(l) atomic_long_dec(&(l)->a)
6418+#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
6419
6420 /*
6421 * Same as above, but return the result value
6422@@ -70,6 +80,51 @@ static __inline__ long local_add_return(long i, local_t * l)
6423 return result;
6424 }
6425
6426+static __inline__ long local_add_return_unchecked(long i, local_unchecked_t * l)
6427+{
6428+ unsigned long result;
6429+
6430+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
6431+ unsigned long temp;
6432+
6433+ __asm__ __volatile__(
6434+ " .set mips3 \n"
6435+ "1:" __LL "%1, %2 # local_add_return \n"
6436+ " addu %0, %1, %3 \n"
6437+ __SC "%0, %2 \n"
6438+ " beqzl %0, 1b \n"
6439+ " addu %0, %1, %3 \n"
6440+ " .set mips0 \n"
6441+ : "=&r" (result), "=&r" (temp), "=m" (l->a.counter)
6442+ : "Ir" (i), "m" (l->a.counter)
6443+ : "memory");
6444+ } else if (kernel_uses_llsc) {
6445+ unsigned long temp;
6446+
6447+ __asm__ __volatile__(
6448+ " .set mips3 \n"
6449+ "1:" __LL "%1, %2 # local_add_return \n"
6450+ " addu %0, %1, %3 \n"
6451+ __SC "%0, %2 \n"
6452+ " beqz %0, 1b \n"
6453+ " addu %0, %1, %3 \n"
6454+ " .set mips0 \n"
6455+ : "=&r" (result), "=&r" (temp), "=m" (l->a.counter)
6456+ : "Ir" (i), "m" (l->a.counter)
6457+ : "memory");
6458+ } else {
6459+ unsigned long flags;
6460+
6461+ local_irq_save(flags);
6462+ result = l->a.counter;
6463+ result += i;
6464+ l->a.counter = result;
6465+ local_irq_restore(flags);
6466+ }
6467+
6468+ return result;
6469+}
6470+
6471 static __inline__ long local_sub_return(long i, local_t * l)
6472 {
6473 unsigned long result;
6474@@ -117,6 +172,8 @@ static __inline__ long local_sub_return(long i, local_t * l)
6475
6476 #define local_cmpxchg(l, o, n) \
6477 ((long)cmpxchg_local(&((l)->a.counter), (o), (n)))
6478+#define local_cmpxchg_unchecked(l, o, n) \
6479+ ((long)cmpxchg_local(&((l)->a.counter), (o), (n)))
6480 #define local_xchg(l, n) (atomic_long_xchg((&(l)->a), (n)))
6481
6482 /**
6483diff --git a/arch/mips/include/asm/page.h b/arch/mips/include/asm/page.h
6484index 3be8180..c4798d5 100644
6485--- a/arch/mips/include/asm/page.h
6486+++ b/arch/mips/include/asm/page.h
6487@@ -120,7 +120,7 @@ extern void copy_user_highpage(struct page *to, struct page *from,
6488 #ifdef CONFIG_CPU_MIPS32
6489 typedef struct { unsigned long pte_low, pte_high; } pte_t;
6490 #define pte_val(x) ((x).pte_low | ((unsigned long long)(x).pte_high << 32))
6491- #define __pte(x) ({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; })
6492+ #define __pte(x) ({ pte_t __pte = {(x), (x) >> 32}; __pte; })
6493 #else
6494 typedef struct { unsigned long long pte; } pte_t;
6495 #define pte_val(x) ((x).pte)
6496diff --git a/arch/mips/include/asm/pgalloc.h b/arch/mips/include/asm/pgalloc.h
6497index b336037..5b874cc 100644
6498--- a/arch/mips/include/asm/pgalloc.h
6499+++ b/arch/mips/include/asm/pgalloc.h
6500@@ -37,6 +37,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6501 {
6502 set_pud(pud, __pud((unsigned long)pmd));
6503 }
6504+
6505+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6506+{
6507+ pud_populate(mm, pud, pmd);
6508+}
6509 #endif
6510
6511 /*
6512diff --git a/arch/mips/include/asm/pgtable.h b/arch/mips/include/asm/pgtable.h
6513index d6d1928..ce4f822 100644
6514--- a/arch/mips/include/asm/pgtable.h
6515+++ b/arch/mips/include/asm/pgtable.h
6516@@ -20,6 +20,9 @@
6517 #include <asm/io.h>
6518 #include <asm/pgtable-bits.h>
6519
6520+#define ktla_ktva(addr) (addr)
6521+#define ktva_ktla(addr) (addr)
6522+
6523 struct mm_struct;
6524 struct vm_area_struct;
6525
6526diff --git a/arch/mips/include/asm/thread_info.h b/arch/mips/include/asm/thread_info.h
6527index 7de8658..c109224 100644
6528--- a/arch/mips/include/asm/thread_info.h
6529+++ b/arch/mips/include/asm/thread_info.h
6530@@ -105,6 +105,9 @@ static inline struct thread_info *current_thread_info(void)
6531 #define TIF_SECCOMP 4 /* secure computing */
6532 #define TIF_NOTIFY_RESUME 5 /* callback before returning to user */
6533 #define TIF_RESTORE_SIGMASK 9 /* restore signal mask in do_signal() */
6534+/* li takes a 32bit immediate */
6535+#define TIF_GRSEC_SETXID 10 /* update credentials on syscall entry/exit */
6536+
6537 #define TIF_USEDFPU 16 /* FPU was used by this task this quantum (SMP) */
6538 #define TIF_MEMDIE 18 /* is terminating due to OOM killer */
6539 #define TIF_NOHZ 19 /* in adaptive nohz mode */
6540@@ -138,14 +141,16 @@ static inline struct thread_info *current_thread_info(void)
6541 #define _TIF_USEDMSA (1<<TIF_USEDMSA)
6542 #define _TIF_MSA_CTX_LIVE (1<<TIF_MSA_CTX_LIVE)
6543 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
6544+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
6545
6546 #define _TIF_WORK_SYSCALL_ENTRY (_TIF_NOHZ | _TIF_SYSCALL_TRACE | \
6547 _TIF_SYSCALL_AUDIT | \
6548- _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP)
6549+ _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP | \
6550+ _TIF_GRSEC_SETXID)
6551
6552 /* work to do in syscall_trace_leave() */
6553 #define _TIF_WORK_SYSCALL_EXIT (_TIF_NOHZ | _TIF_SYSCALL_TRACE | \
6554- _TIF_SYSCALL_AUDIT | _TIF_SYSCALL_TRACEPOINT)
6555+ _TIF_SYSCALL_AUDIT | _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
6556
6557 /* work to do on interrupt/exception return */
6558 #define _TIF_WORK_MASK \
6559@@ -153,7 +158,7 @@ static inline struct thread_info *current_thread_info(void)
6560 /* work to do on any return to u-space */
6561 #define _TIF_ALLWORK_MASK (_TIF_NOHZ | _TIF_WORK_MASK | \
6562 _TIF_WORK_SYSCALL_EXIT | \
6563- _TIF_SYSCALL_TRACEPOINT)
6564+ _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
6565
6566 /*
6567 * We stash processor id into a COP0 register to retrieve it fast
6568diff --git a/arch/mips/include/asm/uaccess.h b/arch/mips/include/asm/uaccess.h
6569index 22a5624..7c96295 100644
6570--- a/arch/mips/include/asm/uaccess.h
6571+++ b/arch/mips/include/asm/uaccess.h
6572@@ -130,6 +130,7 @@ extern u64 __ua_limit;
6573 __ok == 0; \
6574 })
6575
6576+#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
6577 #define access_ok(type, addr, size) \
6578 likely(__access_ok((addr), (size), __access_mask))
6579
6580diff --git a/arch/mips/kernel/binfmt_elfn32.c b/arch/mips/kernel/binfmt_elfn32.c
6581index 1188e00..41cf144 100644
6582--- a/arch/mips/kernel/binfmt_elfn32.c
6583+++ b/arch/mips/kernel/binfmt_elfn32.c
6584@@ -50,6 +50,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
6585 #undef ELF_ET_DYN_BASE
6586 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
6587
6588+#ifdef CONFIG_PAX_ASLR
6589+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
6590+
6591+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6592+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6593+#endif
6594+
6595 #include <asm/processor.h>
6596 #include <linux/module.h>
6597 #include <linux/elfcore.h>
6598diff --git a/arch/mips/kernel/binfmt_elfo32.c b/arch/mips/kernel/binfmt_elfo32.c
6599index 9287678..f870e47 100644
6600--- a/arch/mips/kernel/binfmt_elfo32.c
6601+++ b/arch/mips/kernel/binfmt_elfo32.c
6602@@ -70,6 +70,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
6603 #undef ELF_ET_DYN_BASE
6604 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
6605
6606+#ifdef CONFIG_PAX_ASLR
6607+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
6608+
6609+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6610+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6611+#endif
6612+
6613 #include <asm/processor.h>
6614
6615 #include <linux/module.h>
6616diff --git a/arch/mips/kernel/i8259.c b/arch/mips/kernel/i8259.c
6617index 50b3648..c2f3cec 100644
6618--- a/arch/mips/kernel/i8259.c
6619+++ b/arch/mips/kernel/i8259.c
6620@@ -201,7 +201,7 @@ spurious_8259A_irq:
6621 printk(KERN_DEBUG "spurious 8259A interrupt: IRQ%d.\n", irq);
6622 spurious_irq_mask |= irqmask;
6623 }
6624- atomic_inc(&irq_err_count);
6625+ atomic_inc_unchecked(&irq_err_count);
6626 /*
6627 * Theoretically we do not have to handle this IRQ,
6628 * but in Linux this does not cause problems and is
6629diff --git a/arch/mips/kernel/irq-gt641xx.c b/arch/mips/kernel/irq-gt641xx.c
6630index 44a1f79..2bd6aa3 100644
6631--- a/arch/mips/kernel/irq-gt641xx.c
6632+++ b/arch/mips/kernel/irq-gt641xx.c
6633@@ -110,7 +110,7 @@ void gt641xx_irq_dispatch(void)
6634 }
6635 }
6636
6637- atomic_inc(&irq_err_count);
6638+ atomic_inc_unchecked(&irq_err_count);
6639 }
6640
6641 void __init gt641xx_irq_init(void)
6642diff --git a/arch/mips/kernel/irq.c b/arch/mips/kernel/irq.c
6643index d2bfbc2..a8eacd2 100644
6644--- a/arch/mips/kernel/irq.c
6645+++ b/arch/mips/kernel/irq.c
6646@@ -76,17 +76,17 @@ void ack_bad_irq(unsigned int irq)
6647 printk("unexpected IRQ # %d\n", irq);
6648 }
6649
6650-atomic_t irq_err_count;
6651+atomic_unchecked_t irq_err_count;
6652
6653 int arch_show_interrupts(struct seq_file *p, int prec)
6654 {
6655- seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
6656+ seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
6657 return 0;
6658 }
6659
6660 asmlinkage void spurious_interrupt(void)
6661 {
6662- atomic_inc(&irq_err_count);
6663+ atomic_inc_unchecked(&irq_err_count);
6664 }
6665
6666 void __init init_IRQ(void)
6667@@ -109,7 +109,10 @@ void __init init_IRQ(void)
6668 #endif
6669 }
6670
6671+
6672 #ifdef DEBUG_STACKOVERFLOW
6673+extern void gr_handle_kernel_exploit(void);
6674+
6675 static inline void check_stack_overflow(void)
6676 {
6677 unsigned long sp;
6678@@ -125,6 +128,7 @@ static inline void check_stack_overflow(void)
6679 printk("do_IRQ: stack overflow: %ld\n",
6680 sp - sizeof(struct thread_info));
6681 dump_stack();
6682+ gr_handle_kernel_exploit();
6683 }
6684 }
6685 #else
6686diff --git a/arch/mips/kernel/pm-cps.c b/arch/mips/kernel/pm-cps.c
6687index 0614717..002fa43 100644
6688--- a/arch/mips/kernel/pm-cps.c
6689+++ b/arch/mips/kernel/pm-cps.c
6690@@ -172,7 +172,7 @@ int cps_pm_enter_state(enum cps_pm_state state)
6691 nc_core_ready_count = nc_addr;
6692
6693 /* Ensure ready_count is zero-initialised before the assembly runs */
6694- ACCESS_ONCE(*nc_core_ready_count) = 0;
6695+ ACCESS_ONCE_RW(*nc_core_ready_count) = 0;
6696 coupled_barrier(&per_cpu(pm_barrier, core), online);
6697
6698 /* Run the generated entry code */
6699diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
6700index 636b074..8fbb91f 100644
6701--- a/arch/mips/kernel/process.c
6702+++ b/arch/mips/kernel/process.c
6703@@ -520,15 +520,3 @@ unsigned long get_wchan(struct task_struct *task)
6704 out:
6705 return pc;
6706 }
6707-
6708-/*
6709- * Don't forget that the stack pointer must be aligned on a 8 bytes
6710- * boundary for 32-bits ABI and 16 bytes for 64-bits ABI.
6711- */
6712-unsigned long arch_align_stack(unsigned long sp)
6713-{
6714- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
6715- sp -= get_random_int() & ~PAGE_MASK;
6716-
6717- return sp & ALMASK;
6718-}
6719diff --git a/arch/mips/kernel/ptrace.c b/arch/mips/kernel/ptrace.c
6720index 9d1487d..10c5da5 100644
6721--- a/arch/mips/kernel/ptrace.c
6722+++ b/arch/mips/kernel/ptrace.c
6723@@ -761,6 +761,10 @@ long arch_ptrace(struct task_struct *child, long request,
6724 return ret;
6725 }
6726
6727+#ifdef CONFIG_GRKERNSEC_SETXID
6728+extern void gr_delayed_cred_worker(void);
6729+#endif
6730+
6731 /*
6732 * Notification of system call entry/exit
6733 * - triggered by current->work.syscall_trace
6734@@ -777,6 +781,11 @@ asmlinkage long syscall_trace_enter(struct pt_regs *regs, long syscall)
6735 tracehook_report_syscall_entry(regs))
6736 ret = -1;
6737
6738+#ifdef CONFIG_GRKERNSEC_SETXID
6739+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
6740+ gr_delayed_cred_worker();
6741+#endif
6742+
6743 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
6744 trace_sys_enter(regs, regs->regs[2]);
6745
6746diff --git a/arch/mips/kernel/reset.c b/arch/mips/kernel/reset.c
6747index 07fc524..b9d7f28 100644
6748--- a/arch/mips/kernel/reset.c
6749+++ b/arch/mips/kernel/reset.c
6750@@ -13,6 +13,7 @@
6751 #include <linux/reboot.h>
6752
6753 #include <asm/reboot.h>
6754+#include <asm/bug.h>
6755
6756 /*
6757 * Urgs ... Too many MIPS machines to handle this in a generic way.
6758@@ -29,16 +30,19 @@ void machine_restart(char *command)
6759 {
6760 if (_machine_restart)
6761 _machine_restart(command);
6762+ BUG();
6763 }
6764
6765 void machine_halt(void)
6766 {
6767 if (_machine_halt)
6768 _machine_halt();
6769+ BUG();
6770 }
6771
6772 void machine_power_off(void)
6773 {
6774 if (pm_power_off)
6775 pm_power_off();
6776+ BUG();
6777 }
6778diff --git a/arch/mips/kernel/sync-r4k.c b/arch/mips/kernel/sync-r4k.c
6779index 2242bdd..b284048 100644
6780--- a/arch/mips/kernel/sync-r4k.c
6781+++ b/arch/mips/kernel/sync-r4k.c
6782@@ -18,8 +18,8 @@
6783 #include <asm/mipsregs.h>
6784
6785 static atomic_t count_start_flag = ATOMIC_INIT(0);
6786-static atomic_t count_count_start = ATOMIC_INIT(0);
6787-static atomic_t count_count_stop = ATOMIC_INIT(0);
6788+static atomic_unchecked_t count_count_start = ATOMIC_INIT(0);
6789+static atomic_unchecked_t count_count_stop = ATOMIC_INIT(0);
6790 static atomic_t count_reference = ATOMIC_INIT(0);
6791
6792 #define COUNTON 100
6793@@ -58,13 +58,13 @@ void synchronise_count_master(int cpu)
6794
6795 for (i = 0; i < NR_LOOPS; i++) {
6796 /* slaves loop on '!= 2' */
6797- while (atomic_read(&count_count_start) != 1)
6798+ while (atomic_read_unchecked(&count_count_start) != 1)
6799 mb();
6800- atomic_set(&count_count_stop, 0);
6801+ atomic_set_unchecked(&count_count_stop, 0);
6802 smp_wmb();
6803
6804 /* this lets the slaves write their count register */
6805- atomic_inc(&count_count_start);
6806+ atomic_inc_unchecked(&count_count_start);
6807
6808 /*
6809 * Everyone initialises count in the last loop:
6810@@ -75,11 +75,11 @@ void synchronise_count_master(int cpu)
6811 /*
6812 * Wait for all slaves to leave the synchronization point:
6813 */
6814- while (atomic_read(&count_count_stop) != 1)
6815+ while (atomic_read_unchecked(&count_count_stop) != 1)
6816 mb();
6817- atomic_set(&count_count_start, 0);
6818+ atomic_set_unchecked(&count_count_start, 0);
6819 smp_wmb();
6820- atomic_inc(&count_count_stop);
6821+ atomic_inc_unchecked(&count_count_stop);
6822 }
6823 /* Arrange for an interrupt in a short while */
6824 write_c0_compare(read_c0_count() + COUNTON);
6825@@ -112,8 +112,8 @@ void synchronise_count_slave(int cpu)
6826 initcount = atomic_read(&count_reference);
6827
6828 for (i = 0; i < NR_LOOPS; i++) {
6829- atomic_inc(&count_count_start);
6830- while (atomic_read(&count_count_start) != 2)
6831+ atomic_inc_unchecked(&count_count_start);
6832+ while (atomic_read_unchecked(&count_count_start) != 2)
6833 mb();
6834
6835 /*
6836@@ -122,8 +122,8 @@ void synchronise_count_slave(int cpu)
6837 if (i == NR_LOOPS-1)
6838 write_c0_count(initcount);
6839
6840- atomic_inc(&count_count_stop);
6841- while (atomic_read(&count_count_stop) != 2)
6842+ atomic_inc_unchecked(&count_count_stop);
6843+ while (atomic_read_unchecked(&count_count_stop) != 2)
6844 mb();
6845 }
6846 /* Arrange for an interrupt in a short while */
6847diff --git a/arch/mips/kernel/traps.c b/arch/mips/kernel/traps.c
6848index 22b19c2..c5cc8c4 100644
6849--- a/arch/mips/kernel/traps.c
6850+++ b/arch/mips/kernel/traps.c
6851@@ -688,7 +688,18 @@ asmlinkage void do_ov(struct pt_regs *regs)
6852 siginfo_t info;
6853
6854 prev_state = exception_enter();
6855- die_if_kernel("Integer overflow", regs);
6856+ if (unlikely(!user_mode(regs))) {
6857+
6858+#ifdef CONFIG_PAX_REFCOUNT
6859+ if (fixup_exception(regs)) {
6860+ pax_report_refcount_overflow(regs);
6861+ exception_exit(prev_state);
6862+ return;
6863+ }
6864+#endif
6865+
6866+ die("Integer overflow", regs);
6867+ }
6868
6869 info.si_code = FPE_INTOVF;
6870 info.si_signo = SIGFPE;
6871diff --git a/arch/mips/kvm/mips.c b/arch/mips/kvm/mips.c
6872index e3b21e5..ea5ff7c 100644
6873--- a/arch/mips/kvm/mips.c
6874+++ b/arch/mips/kvm/mips.c
6875@@ -805,7 +805,7 @@ long kvm_arch_vm_ioctl(struct file *filp, unsigned int ioctl, unsigned long arg)
6876 return r;
6877 }
6878
6879-int kvm_arch_init(void *opaque)
6880+int kvm_arch_init(const void *opaque)
6881 {
6882 if (kvm_mips_callbacks) {
6883 kvm_err("kvm: module already exists\n");
6884diff --git a/arch/mips/mm/fault.c b/arch/mips/mm/fault.c
6885index becc42b..9e43d4b 100644
6886--- a/arch/mips/mm/fault.c
6887+++ b/arch/mips/mm/fault.c
6888@@ -28,6 +28,23 @@
6889 #include <asm/highmem.h> /* For VMALLOC_END */
6890 #include <linux/kdebug.h>
6891
6892+#ifdef CONFIG_PAX_PAGEEXEC
6893+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
6894+{
6895+ unsigned long i;
6896+
6897+ printk(KERN_ERR "PAX: bytes at PC: ");
6898+ for (i = 0; i < 5; i++) {
6899+ unsigned int c;
6900+ if (get_user(c, (unsigned int *)pc+i))
6901+ printk(KERN_CONT "???????? ");
6902+ else
6903+ printk(KERN_CONT "%08x ", c);
6904+ }
6905+ printk("\n");
6906+}
6907+#endif
6908+
6909 /*
6910 * This routine handles page faults. It determines the address,
6911 * and the problem, and then passes it off to one of the appropriate
6912@@ -199,6 +216,14 @@ bad_area:
6913 bad_area_nosemaphore:
6914 /* User mode accesses just cause a SIGSEGV */
6915 if (user_mode(regs)) {
6916+
6917+#ifdef CONFIG_PAX_PAGEEXEC
6918+ if (cpu_has_rixi && (mm->pax_flags & MF_PAX_PAGEEXEC) && !write && address == instruction_pointer(regs)) {
6919+ pax_report_fault(regs, (void *)address, (void *)user_stack_pointer(regs));
6920+ do_group_exit(SIGKILL);
6921+ }
6922+#endif
6923+
6924 tsk->thread.cp0_badvaddr = address;
6925 tsk->thread.error_code = write;
6926 #if 0
6927diff --git a/arch/mips/mm/mmap.c b/arch/mips/mm/mmap.c
6928index f1baadd..5472dca 100644
6929--- a/arch/mips/mm/mmap.c
6930+++ b/arch/mips/mm/mmap.c
6931@@ -59,6 +59,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
6932 struct vm_area_struct *vma;
6933 unsigned long addr = addr0;
6934 int do_color_align;
6935+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
6936 struct vm_unmapped_area_info info;
6937
6938 if (unlikely(len > TASK_SIZE))
6939@@ -84,6 +85,11 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
6940 do_color_align = 1;
6941
6942 /* requesting a specific address */
6943+
6944+#ifdef CONFIG_PAX_RANDMMAP
6945+ if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
6946+#endif
6947+
6948 if (addr) {
6949 if (do_color_align)
6950 addr = COLOUR_ALIGN(addr, pgoff);
6951@@ -91,14 +97,14 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
6952 addr = PAGE_ALIGN(addr);
6953
6954 vma = find_vma(mm, addr);
6955- if (TASK_SIZE - len >= addr &&
6956- (!vma || addr + len <= vma->vm_start))
6957+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
6958 return addr;
6959 }
6960
6961 info.length = len;
6962 info.align_mask = do_color_align ? (PAGE_MASK & shm_align_mask) : 0;
6963 info.align_offset = pgoff << PAGE_SHIFT;
6964+ info.threadstack_offset = offset;
6965
6966 if (dir == DOWN) {
6967 info.flags = VM_UNMAPPED_AREA_TOPDOWN;
6968@@ -146,6 +152,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
6969 {
6970 unsigned long random_factor = 0UL;
6971
6972+#ifdef CONFIG_PAX_RANDMMAP
6973+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
6974+#endif
6975+
6976 if (current->flags & PF_RANDOMIZE) {
6977 random_factor = get_random_int();
6978 random_factor = random_factor << PAGE_SHIFT;
6979@@ -157,40 +167,25 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
6980
6981 if (mmap_is_legacy()) {
6982 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
6983+
6984+#ifdef CONFIG_PAX_RANDMMAP
6985+ if (mm->pax_flags & MF_PAX_RANDMMAP)
6986+ mm->mmap_base += mm->delta_mmap;
6987+#endif
6988+
6989 mm->get_unmapped_area = arch_get_unmapped_area;
6990 } else {
6991 mm->mmap_base = mmap_base(random_factor);
6992+
6993+#ifdef CONFIG_PAX_RANDMMAP
6994+ if (mm->pax_flags & MF_PAX_RANDMMAP)
6995+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
6996+#endif
6997+
6998 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
6999 }
7000 }
7001
7002-static inline unsigned long brk_rnd(void)
7003-{
7004- unsigned long rnd = get_random_int();
7005-
7006- rnd = rnd << PAGE_SHIFT;
7007- /* 8MB for 32bit, 256MB for 64bit */
7008- if (TASK_IS_32BIT_ADDR)
7009- rnd = rnd & 0x7ffffful;
7010- else
7011- rnd = rnd & 0xffffffful;
7012-
7013- return rnd;
7014-}
7015-
7016-unsigned long arch_randomize_brk(struct mm_struct *mm)
7017-{
7018- unsigned long base = mm->brk;
7019- unsigned long ret;
7020-
7021- ret = PAGE_ALIGN(base + brk_rnd());
7022-
7023- if (ret < mm->brk)
7024- return mm->brk;
7025-
7026- return ret;
7027-}
7028-
7029 int __virt_addr_valid(const volatile void *kaddr)
7030 {
7031 return pfn_valid(PFN_DOWN(virt_to_phys(kaddr)));
7032diff --git a/arch/mips/pci/pci-octeon.c b/arch/mips/pci/pci-octeon.c
7033index 59cccd9..f39ac2f 100644
7034--- a/arch/mips/pci/pci-octeon.c
7035+++ b/arch/mips/pci/pci-octeon.c
7036@@ -327,8 +327,8 @@ static int octeon_write_config(struct pci_bus *bus, unsigned int devfn,
7037
7038
7039 static struct pci_ops octeon_pci_ops = {
7040- octeon_read_config,
7041- octeon_write_config,
7042+ .read = octeon_read_config,
7043+ .write = octeon_write_config,
7044 };
7045
7046 static struct resource octeon_pci_mem_resource = {
7047diff --git a/arch/mips/pci/pcie-octeon.c b/arch/mips/pci/pcie-octeon.c
7048index 5e36c33..eb4a17b 100644
7049--- a/arch/mips/pci/pcie-octeon.c
7050+++ b/arch/mips/pci/pcie-octeon.c
7051@@ -1792,8 +1792,8 @@ static int octeon_dummy_write_config(struct pci_bus *bus, unsigned int devfn,
7052 }
7053
7054 static struct pci_ops octeon_pcie0_ops = {
7055- octeon_pcie0_read_config,
7056- octeon_pcie0_write_config,
7057+ .read = octeon_pcie0_read_config,
7058+ .write = octeon_pcie0_write_config,
7059 };
7060
7061 static struct resource octeon_pcie0_mem_resource = {
7062@@ -1813,8 +1813,8 @@ static struct pci_controller octeon_pcie0_controller = {
7063 };
7064
7065 static struct pci_ops octeon_pcie1_ops = {
7066- octeon_pcie1_read_config,
7067- octeon_pcie1_write_config,
7068+ .read = octeon_pcie1_read_config,
7069+ .write = octeon_pcie1_write_config,
7070 };
7071
7072 static struct resource octeon_pcie1_mem_resource = {
7073@@ -1834,8 +1834,8 @@ static struct pci_controller octeon_pcie1_controller = {
7074 };
7075
7076 static struct pci_ops octeon_dummy_ops = {
7077- octeon_dummy_read_config,
7078- octeon_dummy_write_config,
7079+ .read = octeon_dummy_read_config,
7080+ .write = octeon_dummy_write_config,
7081 };
7082
7083 static struct resource octeon_dummy_mem_resource = {
7084diff --git a/arch/mips/sgi-ip27/ip27-nmi.c b/arch/mips/sgi-ip27/ip27-nmi.c
7085index a2358b4..7cead4f 100644
7086--- a/arch/mips/sgi-ip27/ip27-nmi.c
7087+++ b/arch/mips/sgi-ip27/ip27-nmi.c
7088@@ -187,9 +187,9 @@ void
7089 cont_nmi_dump(void)
7090 {
7091 #ifndef REAL_NMI_SIGNAL
7092- static atomic_t nmied_cpus = ATOMIC_INIT(0);
7093+ static atomic_unchecked_t nmied_cpus = ATOMIC_INIT(0);
7094
7095- atomic_inc(&nmied_cpus);
7096+ atomic_inc_unchecked(&nmied_cpus);
7097 #endif
7098 /*
7099 * Only allow 1 cpu to proceed
7100@@ -233,7 +233,7 @@ cont_nmi_dump(void)
7101 udelay(10000);
7102 }
7103 #else
7104- while (atomic_read(&nmied_cpus) != num_online_cpus());
7105+ while (atomic_read_unchecked(&nmied_cpus) != num_online_cpus());
7106 #endif
7107
7108 /*
7109diff --git a/arch/mips/sni/rm200.c b/arch/mips/sni/rm200.c
7110index a046b30..6799527 100644
7111--- a/arch/mips/sni/rm200.c
7112+++ b/arch/mips/sni/rm200.c
7113@@ -270,7 +270,7 @@ spurious_8259A_irq:
7114 "spurious RM200 8259A interrupt: IRQ%d.\n", irq);
7115 spurious_irq_mask |= irqmask;
7116 }
7117- atomic_inc(&irq_err_count);
7118+ atomic_inc_unchecked(&irq_err_count);
7119 /*
7120 * Theoretically we do not have to handle this IRQ,
7121 * but in Linux this does not cause problems and is
7122diff --git a/arch/mips/vr41xx/common/icu.c b/arch/mips/vr41xx/common/icu.c
7123index 41e873b..34d33a7 100644
7124--- a/arch/mips/vr41xx/common/icu.c
7125+++ b/arch/mips/vr41xx/common/icu.c
7126@@ -653,7 +653,7 @@ static int icu_get_irq(unsigned int irq)
7127
7128 printk(KERN_ERR "spurious ICU interrupt: %04x,%04x\n", pend1, pend2);
7129
7130- atomic_inc(&irq_err_count);
7131+ atomic_inc_unchecked(&irq_err_count);
7132
7133 return -1;
7134 }
7135diff --git a/arch/mips/vr41xx/common/irq.c b/arch/mips/vr41xx/common/irq.c
7136index ae0e4ee..e8f0692 100644
7137--- a/arch/mips/vr41xx/common/irq.c
7138+++ b/arch/mips/vr41xx/common/irq.c
7139@@ -64,7 +64,7 @@ static void irq_dispatch(unsigned int irq)
7140 irq_cascade_t *cascade;
7141
7142 if (irq >= NR_IRQS) {
7143- atomic_inc(&irq_err_count);
7144+ atomic_inc_unchecked(&irq_err_count);
7145 return;
7146 }
7147
7148@@ -84,7 +84,7 @@ static void irq_dispatch(unsigned int irq)
7149 ret = cascade->get_irq(irq);
7150 irq = ret;
7151 if (ret < 0)
7152- atomic_inc(&irq_err_count);
7153+ atomic_inc_unchecked(&irq_err_count);
7154 else
7155 irq_dispatch(irq);
7156 if (!irqd_irq_disabled(idata) && chip->irq_unmask)
7157diff --git a/arch/mn10300/proc-mn103e010/include/proc/cache.h b/arch/mn10300/proc-mn103e010/include/proc/cache.h
7158index 967d144..db12197 100644
7159--- a/arch/mn10300/proc-mn103e010/include/proc/cache.h
7160+++ b/arch/mn10300/proc-mn103e010/include/proc/cache.h
7161@@ -11,12 +11,14 @@
7162 #ifndef _ASM_PROC_CACHE_H
7163 #define _ASM_PROC_CACHE_H
7164
7165+#include <linux/const.h>
7166+
7167 /* L1 cache */
7168
7169 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
7170 #define L1_CACHE_NENTRIES 256 /* number of entries in each way */
7171-#define L1_CACHE_BYTES 16 /* bytes per entry */
7172 #define L1_CACHE_SHIFT 4 /* shift for bytes per entry */
7173+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
7174 #define L1_CACHE_WAYDISP 0x1000 /* displacement of one way from the next */
7175
7176 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
7177diff --git a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
7178index bcb5df2..84fabd2 100644
7179--- a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
7180+++ b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
7181@@ -16,13 +16,15 @@
7182 #ifndef _ASM_PROC_CACHE_H
7183 #define _ASM_PROC_CACHE_H
7184
7185+#include <linux/const.h>
7186+
7187 /*
7188 * L1 cache
7189 */
7190 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
7191 #define L1_CACHE_NENTRIES 128 /* number of entries in each way */
7192-#define L1_CACHE_BYTES 32 /* bytes per entry */
7193 #define L1_CACHE_SHIFT 5 /* shift for bytes per entry */
7194+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
7195 #define L1_CACHE_WAYDISP 0x1000 /* distance from one way to the next */
7196
7197 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
7198diff --git a/arch/openrisc/include/asm/cache.h b/arch/openrisc/include/asm/cache.h
7199index 4ce7a01..449202a 100644
7200--- a/arch/openrisc/include/asm/cache.h
7201+++ b/arch/openrisc/include/asm/cache.h
7202@@ -19,11 +19,13 @@
7203 #ifndef __ASM_OPENRISC_CACHE_H
7204 #define __ASM_OPENRISC_CACHE_H
7205
7206+#include <linux/const.h>
7207+
7208 /* FIXME: How can we replace these with values from the CPU...
7209 * they shouldn't be hard-coded!
7210 */
7211
7212-#define L1_CACHE_BYTES 16
7213 #define L1_CACHE_SHIFT 4
7214+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7215
7216 #endif /* __ASM_OPENRISC_CACHE_H */
7217diff --git a/arch/parisc/include/asm/atomic.h b/arch/parisc/include/asm/atomic.h
7218index 226f8ca..9d9b87d 100644
7219--- a/arch/parisc/include/asm/atomic.h
7220+++ b/arch/parisc/include/asm/atomic.h
7221@@ -273,6 +273,16 @@ static inline long atomic64_dec_if_positive(atomic64_t *v)
7222 return dec;
7223 }
7224
7225+#define atomic64_read_unchecked(v) atomic64_read(v)
7226+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
7227+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
7228+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
7229+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
7230+#define atomic64_inc_unchecked(v) atomic64_inc(v)
7231+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
7232+#define atomic64_dec_unchecked(v) atomic64_dec(v)
7233+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
7234+
7235 #endif /* !CONFIG_64BIT */
7236
7237
7238diff --git a/arch/parisc/include/asm/cache.h b/arch/parisc/include/asm/cache.h
7239index 47f11c7..3420df2 100644
7240--- a/arch/parisc/include/asm/cache.h
7241+++ b/arch/parisc/include/asm/cache.h
7242@@ -5,6 +5,7 @@
7243 #ifndef __ARCH_PARISC_CACHE_H
7244 #define __ARCH_PARISC_CACHE_H
7245
7246+#include <linux/const.h>
7247
7248 /*
7249 * PA 2.0 processors have 64-byte cachelines; PA 1.1 processors have
7250@@ -15,13 +16,13 @@
7251 * just ruin performance.
7252 */
7253 #ifdef CONFIG_PA20
7254-#define L1_CACHE_BYTES 64
7255 #define L1_CACHE_SHIFT 6
7256 #else
7257-#define L1_CACHE_BYTES 32
7258 #define L1_CACHE_SHIFT 5
7259 #endif
7260
7261+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7262+
7263 #ifndef __ASSEMBLY__
7264
7265 #define SMP_CACHE_BYTES L1_CACHE_BYTES
7266diff --git a/arch/parisc/include/asm/elf.h b/arch/parisc/include/asm/elf.h
7267index 3391d06..c23a2cc 100644
7268--- a/arch/parisc/include/asm/elf.h
7269+++ b/arch/parisc/include/asm/elf.h
7270@@ -342,6 +342,13 @@ struct pt_regs; /* forward declaration... */
7271
7272 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000)
7273
7274+#ifdef CONFIG_PAX_ASLR
7275+#define PAX_ELF_ET_DYN_BASE 0x10000UL
7276+
7277+#define PAX_DELTA_MMAP_LEN 16
7278+#define PAX_DELTA_STACK_LEN 16
7279+#endif
7280+
7281 /* This yields a mask that user programs can use to figure out what
7282 instruction set this CPU supports. This could be done in user space,
7283 but it's not easy, and we've already done it here. */
7284diff --git a/arch/parisc/include/asm/pgalloc.h b/arch/parisc/include/asm/pgalloc.h
7285index f213f5b..0af3e8e 100644
7286--- a/arch/parisc/include/asm/pgalloc.h
7287+++ b/arch/parisc/include/asm/pgalloc.h
7288@@ -61,6 +61,11 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
7289 (__u32)(__pa((unsigned long)pmd) >> PxD_VALUE_SHIFT));
7290 }
7291
7292+static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
7293+{
7294+ pgd_populate(mm, pgd, pmd);
7295+}
7296+
7297 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
7298 {
7299 pmd_t *pmd = (pmd_t *)__get_free_pages(GFP_KERNEL|__GFP_REPEAT,
7300@@ -93,6 +98,7 @@ static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
7301 #define pmd_alloc_one(mm, addr) ({ BUG(); ((pmd_t *)2); })
7302 #define pmd_free(mm, x) do { } while (0)
7303 #define pgd_populate(mm, pmd, pte) BUG()
7304+#define pgd_populate_kernel(mm, pmd, pte) BUG()
7305
7306 #endif
7307
7308diff --git a/arch/parisc/include/asm/pgtable.h b/arch/parisc/include/asm/pgtable.h
7309index 22b89d1..ce34230 100644
7310--- a/arch/parisc/include/asm/pgtable.h
7311+++ b/arch/parisc/include/asm/pgtable.h
7312@@ -223,6 +223,17 @@ extern void purge_tlb_entries(struct mm_struct *, unsigned long);
7313 #define PAGE_EXECREAD __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_EXEC |_PAGE_ACCESSED)
7314 #define PAGE_COPY PAGE_EXECREAD
7315 #define PAGE_RWX __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC |_PAGE_ACCESSED)
7316+
7317+#ifdef CONFIG_PAX_PAGEEXEC
7318+# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_ACCESSED)
7319+# define PAGE_COPY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
7320+# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
7321+#else
7322+# define PAGE_SHARED_NOEXEC PAGE_SHARED
7323+# define PAGE_COPY_NOEXEC PAGE_COPY
7324+# define PAGE_READONLY_NOEXEC PAGE_READONLY
7325+#endif
7326+
7327 #define PAGE_KERNEL __pgprot(_PAGE_KERNEL)
7328 #define PAGE_KERNEL_EXEC __pgprot(_PAGE_KERNEL_EXEC)
7329 #define PAGE_KERNEL_RWX __pgprot(_PAGE_KERNEL_RWX)
7330diff --git a/arch/parisc/include/asm/uaccess.h b/arch/parisc/include/asm/uaccess.h
7331index a5cb070..8604ddc 100644
7332--- a/arch/parisc/include/asm/uaccess.h
7333+++ b/arch/parisc/include/asm/uaccess.h
7334@@ -243,10 +243,10 @@ static inline unsigned long __must_check copy_from_user(void *to,
7335 const void __user *from,
7336 unsigned long n)
7337 {
7338- int sz = __compiletime_object_size(to);
7339+ size_t sz = __compiletime_object_size(to);
7340 int ret = -EFAULT;
7341
7342- if (likely(sz == -1 || !__builtin_constant_p(n) || sz >= n))
7343+ if (likely(sz == (size_t)-1 || !__builtin_constant_p(n) || sz >= n))
7344 ret = __copy_from_user(to, from, n);
7345 else
7346 copy_from_user_overflow();
7347diff --git a/arch/parisc/kernel/module.c b/arch/parisc/kernel/module.c
7348index 50dfafc..b9fc230 100644
7349--- a/arch/parisc/kernel/module.c
7350+++ b/arch/parisc/kernel/module.c
7351@@ -98,16 +98,38 @@
7352
7353 /* three functions to determine where in the module core
7354 * or init pieces the location is */
7355+static inline int in_init_rx(struct module *me, void *loc)
7356+{
7357+ return (loc >= me->module_init_rx &&
7358+ loc < (me->module_init_rx + me->init_size_rx));
7359+}
7360+
7361+static inline int in_init_rw(struct module *me, void *loc)
7362+{
7363+ return (loc >= me->module_init_rw &&
7364+ loc < (me->module_init_rw + me->init_size_rw));
7365+}
7366+
7367 static inline int in_init(struct module *me, void *loc)
7368 {
7369- return (loc >= me->module_init &&
7370- loc <= (me->module_init + me->init_size));
7371+ return in_init_rx(me, loc) || in_init_rw(me, loc);
7372+}
7373+
7374+static inline int in_core_rx(struct module *me, void *loc)
7375+{
7376+ return (loc >= me->module_core_rx &&
7377+ loc < (me->module_core_rx + me->core_size_rx));
7378+}
7379+
7380+static inline int in_core_rw(struct module *me, void *loc)
7381+{
7382+ return (loc >= me->module_core_rw &&
7383+ loc < (me->module_core_rw + me->core_size_rw));
7384 }
7385
7386 static inline int in_core(struct module *me, void *loc)
7387 {
7388- return (loc >= me->module_core &&
7389- loc <= (me->module_core + me->core_size));
7390+ return in_core_rx(me, loc) || in_core_rw(me, loc);
7391 }
7392
7393 static inline int in_local(struct module *me, void *loc)
7394@@ -371,13 +393,13 @@ int module_frob_arch_sections(CONST Elf_Ehdr *hdr,
7395 }
7396
7397 /* align things a bit */
7398- me->core_size = ALIGN(me->core_size, 16);
7399- me->arch.got_offset = me->core_size;
7400- me->core_size += gots * sizeof(struct got_entry);
7401+ me->core_size_rw = ALIGN(me->core_size_rw, 16);
7402+ me->arch.got_offset = me->core_size_rw;
7403+ me->core_size_rw += gots * sizeof(struct got_entry);
7404
7405- me->core_size = ALIGN(me->core_size, 16);
7406- me->arch.fdesc_offset = me->core_size;
7407- me->core_size += fdescs * sizeof(Elf_Fdesc);
7408+ me->core_size_rw = ALIGN(me->core_size_rw, 16);
7409+ me->arch.fdesc_offset = me->core_size_rw;
7410+ me->core_size_rw += fdescs * sizeof(Elf_Fdesc);
7411
7412 me->arch.got_max = gots;
7413 me->arch.fdesc_max = fdescs;
7414@@ -395,7 +417,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
7415
7416 BUG_ON(value == 0);
7417
7418- got = me->module_core + me->arch.got_offset;
7419+ got = me->module_core_rw + me->arch.got_offset;
7420 for (i = 0; got[i].addr; i++)
7421 if (got[i].addr == value)
7422 goto out;
7423@@ -413,7 +435,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
7424 #ifdef CONFIG_64BIT
7425 static Elf_Addr get_fdesc(struct module *me, unsigned long value)
7426 {
7427- Elf_Fdesc *fdesc = me->module_core + me->arch.fdesc_offset;
7428+ Elf_Fdesc *fdesc = me->module_core_rw + me->arch.fdesc_offset;
7429
7430 if (!value) {
7431 printk(KERN_ERR "%s: zero OPD requested!\n", me->name);
7432@@ -431,7 +453,7 @@ static Elf_Addr get_fdesc(struct module *me, unsigned long value)
7433
7434 /* Create new one */
7435 fdesc->addr = value;
7436- fdesc->gp = (Elf_Addr)me->module_core + me->arch.got_offset;
7437+ fdesc->gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
7438 return (Elf_Addr)fdesc;
7439 }
7440 #endif /* CONFIG_64BIT */
7441@@ -843,7 +865,7 @@ register_unwind_table(struct module *me,
7442
7443 table = (unsigned char *)sechdrs[me->arch.unwind_section].sh_addr;
7444 end = table + sechdrs[me->arch.unwind_section].sh_size;
7445- gp = (Elf_Addr)me->module_core + me->arch.got_offset;
7446+ gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
7447
7448 DEBUGP("register_unwind_table(), sect = %d at 0x%p - 0x%p (gp=0x%lx)\n",
7449 me->arch.unwind_section, table, end, gp);
7450diff --git a/arch/parisc/kernel/sys_parisc.c b/arch/parisc/kernel/sys_parisc.c
7451index e1ffea2..46ed66e 100644
7452--- a/arch/parisc/kernel/sys_parisc.c
7453+++ b/arch/parisc/kernel/sys_parisc.c
7454@@ -89,6 +89,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7455 unsigned long task_size = TASK_SIZE;
7456 int do_color_align, last_mmap;
7457 struct vm_unmapped_area_info info;
7458+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
7459
7460 if (len > task_size)
7461 return -ENOMEM;
7462@@ -106,6 +107,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7463 goto found_addr;
7464 }
7465
7466+#ifdef CONFIG_PAX_RANDMMAP
7467+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
7468+#endif
7469+
7470 if (addr) {
7471 if (do_color_align && last_mmap)
7472 addr = COLOR_ALIGN(addr, last_mmap, pgoff);
7473@@ -124,6 +129,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7474 info.high_limit = mmap_upper_limit();
7475 info.align_mask = last_mmap ? (PAGE_MASK & (SHM_COLOUR - 1)) : 0;
7476 info.align_offset = shared_align_offset(last_mmap, pgoff);
7477+ info.threadstack_offset = offset;
7478 addr = vm_unmapped_area(&info);
7479
7480 found_addr:
7481@@ -143,6 +149,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7482 unsigned long addr = addr0;
7483 int do_color_align, last_mmap;
7484 struct vm_unmapped_area_info info;
7485+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
7486
7487 #ifdef CONFIG_64BIT
7488 /* This should only ever run for 32-bit processes. */
7489@@ -167,6 +174,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7490 }
7491
7492 /* requesting a specific address */
7493+#ifdef CONFIG_PAX_RANDMMAP
7494+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
7495+#endif
7496+
7497 if (addr) {
7498 if (do_color_align && last_mmap)
7499 addr = COLOR_ALIGN(addr, last_mmap, pgoff);
7500@@ -184,6 +195,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7501 info.high_limit = mm->mmap_base;
7502 info.align_mask = last_mmap ? (PAGE_MASK & (SHM_COLOUR - 1)) : 0;
7503 info.align_offset = shared_align_offset(last_mmap, pgoff);
7504+ info.threadstack_offset = offset;
7505 addr = vm_unmapped_area(&info);
7506 if (!(addr & ~PAGE_MASK))
7507 goto found_addr;
7508@@ -249,6 +261,13 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7509 mm->mmap_legacy_base = mmap_legacy_base();
7510 mm->mmap_base = mmap_upper_limit();
7511
7512+#ifdef CONFIG_PAX_RANDMMAP
7513+ if (mm->pax_flags & MF_PAX_RANDMMAP) {
7514+ mm->mmap_legacy_base += mm->delta_mmap;
7515+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
7516+ }
7517+#endif
7518+
7519 if (mmap_is_legacy()) {
7520 mm->mmap_base = mm->mmap_legacy_base;
7521 mm->get_unmapped_area = arch_get_unmapped_area;
7522diff --git a/arch/parisc/kernel/traps.c b/arch/parisc/kernel/traps.c
7523index 47ee620..1107387 100644
7524--- a/arch/parisc/kernel/traps.c
7525+++ b/arch/parisc/kernel/traps.c
7526@@ -726,9 +726,7 @@ void notrace handle_interruption(int code, struct pt_regs *regs)
7527
7528 down_read(&current->mm->mmap_sem);
7529 vma = find_vma(current->mm,regs->iaoq[0]);
7530- if (vma && (regs->iaoq[0] >= vma->vm_start)
7531- && (vma->vm_flags & VM_EXEC)) {
7532-
7533+ if (vma && (regs->iaoq[0] >= vma->vm_start)) {
7534 fault_address = regs->iaoq[0];
7535 fault_space = regs->iasq[0];
7536
7537diff --git a/arch/parisc/mm/fault.c b/arch/parisc/mm/fault.c
7538index 3ca9c11..d163ef7 100644
7539--- a/arch/parisc/mm/fault.c
7540+++ b/arch/parisc/mm/fault.c
7541@@ -15,6 +15,7 @@
7542 #include <linux/sched.h>
7543 #include <linux/interrupt.h>
7544 #include <linux/module.h>
7545+#include <linux/unistd.h>
7546
7547 #include <asm/uaccess.h>
7548 #include <asm/traps.h>
7549@@ -50,7 +51,7 @@ int show_unhandled_signals = 1;
7550 static unsigned long
7551 parisc_acctyp(unsigned long code, unsigned int inst)
7552 {
7553- if (code == 6 || code == 16)
7554+ if (code == 6 || code == 7 || code == 16)
7555 return VM_EXEC;
7556
7557 switch (inst & 0xf0000000) {
7558@@ -136,6 +137,116 @@ parisc_acctyp(unsigned long code, unsigned int inst)
7559 }
7560 #endif
7561
7562+#ifdef CONFIG_PAX_PAGEEXEC
7563+/*
7564+ * PaX: decide what to do with offenders (instruction_pointer(regs) = fault address)
7565+ *
7566+ * returns 1 when task should be killed
7567+ * 2 when rt_sigreturn trampoline was detected
7568+ * 3 when unpatched PLT trampoline was detected
7569+ */
7570+static int pax_handle_fetch_fault(struct pt_regs *regs)
7571+{
7572+
7573+#ifdef CONFIG_PAX_EMUPLT
7574+ int err;
7575+
7576+ do { /* PaX: unpatched PLT emulation */
7577+ unsigned int bl, depwi;
7578+
7579+ err = get_user(bl, (unsigned int *)instruction_pointer(regs));
7580+ err |= get_user(depwi, (unsigned int *)(instruction_pointer(regs)+4));
7581+
7582+ if (err)
7583+ break;
7584+
7585+ if (bl == 0xEA9F1FDDU && depwi == 0xD6801C1EU) {
7586+ unsigned int ldw, bv, ldw2, addr = instruction_pointer(regs)-12;
7587+
7588+ err = get_user(ldw, (unsigned int *)addr);
7589+ err |= get_user(bv, (unsigned int *)(addr+4));
7590+ err |= get_user(ldw2, (unsigned int *)(addr+8));
7591+
7592+ if (err)
7593+ break;
7594+
7595+ if (ldw == 0x0E801096U &&
7596+ bv == 0xEAC0C000U &&
7597+ ldw2 == 0x0E881095U)
7598+ {
7599+ unsigned int resolver, map;
7600+
7601+ err = get_user(resolver, (unsigned int *)(instruction_pointer(regs)+8));
7602+ err |= get_user(map, (unsigned int *)(instruction_pointer(regs)+12));
7603+ if (err)
7604+ break;
7605+
7606+ regs->gr[20] = instruction_pointer(regs)+8;
7607+ regs->gr[21] = map;
7608+ regs->gr[22] = resolver;
7609+ regs->iaoq[0] = resolver | 3UL;
7610+ regs->iaoq[1] = regs->iaoq[0] + 4;
7611+ return 3;
7612+ }
7613+ }
7614+ } while (0);
7615+#endif
7616+
7617+#ifdef CONFIG_PAX_EMUTRAMP
7618+
7619+#ifndef CONFIG_PAX_EMUSIGRT
7620+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
7621+ return 1;
7622+#endif
7623+
7624+ do { /* PaX: rt_sigreturn emulation */
7625+ unsigned int ldi1, ldi2, bel, nop;
7626+
7627+ err = get_user(ldi1, (unsigned int *)instruction_pointer(regs));
7628+ err |= get_user(ldi2, (unsigned int *)(instruction_pointer(regs)+4));
7629+ err |= get_user(bel, (unsigned int *)(instruction_pointer(regs)+8));
7630+ err |= get_user(nop, (unsigned int *)(instruction_pointer(regs)+12));
7631+
7632+ if (err)
7633+ break;
7634+
7635+ if ((ldi1 == 0x34190000U || ldi1 == 0x34190002U) &&
7636+ ldi2 == 0x3414015AU &&
7637+ bel == 0xE4008200U &&
7638+ nop == 0x08000240U)
7639+ {
7640+ regs->gr[25] = (ldi1 & 2) >> 1;
7641+ regs->gr[20] = __NR_rt_sigreturn;
7642+ regs->gr[31] = regs->iaoq[1] + 16;
7643+ regs->sr[0] = regs->iasq[1];
7644+ regs->iaoq[0] = 0x100UL;
7645+ regs->iaoq[1] = regs->iaoq[0] + 4;
7646+ regs->iasq[0] = regs->sr[2];
7647+ regs->iasq[1] = regs->sr[2];
7648+ return 2;
7649+ }
7650+ } while (0);
7651+#endif
7652+
7653+ return 1;
7654+}
7655+
7656+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
7657+{
7658+ unsigned long i;
7659+
7660+ printk(KERN_ERR "PAX: bytes at PC: ");
7661+ for (i = 0; i < 5; i++) {
7662+ unsigned int c;
7663+ if (get_user(c, (unsigned int *)pc+i))
7664+ printk(KERN_CONT "???????? ");
7665+ else
7666+ printk(KERN_CONT "%08x ", c);
7667+ }
7668+ printk("\n");
7669+}
7670+#endif
7671+
7672 int fixup_exception(struct pt_regs *regs)
7673 {
7674 const struct exception_table_entry *fix;
7675@@ -234,8 +345,33 @@ retry:
7676
7677 good_area:
7678
7679- if ((vma->vm_flags & acc_type) != acc_type)
7680+ if ((vma->vm_flags & acc_type) != acc_type) {
7681+
7682+#ifdef CONFIG_PAX_PAGEEXEC
7683+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && (acc_type & VM_EXEC) &&
7684+ (address & ~3UL) == instruction_pointer(regs))
7685+ {
7686+ up_read(&mm->mmap_sem);
7687+ switch (pax_handle_fetch_fault(regs)) {
7688+
7689+#ifdef CONFIG_PAX_EMUPLT
7690+ case 3:
7691+ return;
7692+#endif
7693+
7694+#ifdef CONFIG_PAX_EMUTRAMP
7695+ case 2:
7696+ return;
7697+#endif
7698+
7699+ }
7700+ pax_report_fault(regs, (void *)instruction_pointer(regs), (void *)regs->gr[30]);
7701+ do_group_exit(SIGKILL);
7702+ }
7703+#endif
7704+
7705 goto bad_area;
7706+ }
7707
7708 /*
7709 * If for any reason at all we couldn't handle the fault, make
7710diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
7711index 88eace4..4ba2591 100644
7712--- a/arch/powerpc/Kconfig
7713+++ b/arch/powerpc/Kconfig
7714@@ -404,6 +404,7 @@ config PPC64_SUPPORTS_MEMORY_FAILURE
7715 config KEXEC
7716 bool "kexec system call"
7717 depends on (PPC_BOOK3S || FSL_BOOKE || (44x && !SMP))
7718+ depends on !GRKERNSEC_KMEM
7719 help
7720 kexec is a system call that implements the ability to shutdown your
7721 current kernel, and to start another kernel. It is like a reboot
7722diff --git a/arch/powerpc/include/asm/atomic.h b/arch/powerpc/include/asm/atomic.h
7723index 512d278..d31fadd 100644
7724--- a/arch/powerpc/include/asm/atomic.h
7725+++ b/arch/powerpc/include/asm/atomic.h
7726@@ -12,6 +12,11 @@
7727
7728 #define ATOMIC_INIT(i) { (i) }
7729
7730+#define _ASM_EXTABLE(from, to) \
7731+" .section __ex_table,\"a\"\n" \
7732+ PPC_LONG" " #from ", " #to"\n" \
7733+" .previous\n"
7734+
7735 static __inline__ int atomic_read(const atomic_t *v)
7736 {
7737 int t;
7738@@ -21,39 +26,80 @@ static __inline__ int atomic_read(const atomic_t *v)
7739 return t;
7740 }
7741
7742+static __inline__ int atomic_read_unchecked(const atomic_unchecked_t *v)
7743+{
7744+ int t;
7745+
7746+ __asm__ __volatile__("lwz%U1%X1 %0,%1" : "=r"(t) : "m"(v->counter));
7747+
7748+ return t;
7749+}
7750+
7751 static __inline__ void atomic_set(atomic_t *v, int i)
7752 {
7753 __asm__ __volatile__("stw%U0%X0 %1,%0" : "=m"(v->counter) : "r"(i));
7754 }
7755
7756-#define ATOMIC_OP(op, asm_op) \
7757-static __inline__ void atomic_##op(int a, atomic_t *v) \
7758+static __inline__ void atomic_set_unchecked(atomic_unchecked_t *v, int i)
7759+{
7760+ __asm__ __volatile__("stw%U0%X0 %1,%0" : "=m"(v->counter) : "r"(i));
7761+}
7762+
7763+#ifdef CONFIG_PAX_REFCOUNT
7764+#define __REFCOUNT_OP(op) op##o.
7765+#define __OVERFLOW_PRE \
7766+ " mcrxr cr0\n"
7767+#define __OVERFLOW_POST \
7768+ " bf 4*cr0+so, 3f\n" \
7769+ "2: .long 0x00c00b00\n" \
7770+ "3:\n"
7771+#define __OVERFLOW_EXTABLE \
7772+ "\n4:\n"
7773+ _ASM_EXTABLE(2b, 4b)
7774+#else
7775+#define __REFCOUNT_OP(op) op
7776+#define __OVERFLOW_PRE
7777+#define __OVERFLOW_POST
7778+#define __OVERFLOW_EXTABLE
7779+#endif
7780+
7781+#define __ATOMIC_OP(op, suffix, pre_op, asm_op, post_op, extable) \
7782+static inline void atomic_##op##suffix(int a, atomic##suffix##_t *v) \
7783 { \
7784 int t; \
7785 \
7786 __asm__ __volatile__( \
7787-"1: lwarx %0,0,%3 # atomic_" #op "\n" \
7788+"1: lwarx %0,0,%3 # atomic_" #op #suffix "\n" \
7789+ pre_op \
7790 #asm_op " %0,%2,%0\n" \
7791+ post_op \
7792 PPC405_ERR77(0,%3) \
7793 " stwcx. %0,0,%3 \n" \
7794 " bne- 1b\n" \
7795+ extable \
7796 : "=&r" (t), "+m" (v->counter) \
7797 : "r" (a), "r" (&v->counter) \
7798 : "cc"); \
7799 } \
7800
7801-#define ATOMIC_OP_RETURN(op, asm_op) \
7802-static __inline__ int atomic_##op##_return(int a, atomic_t *v) \
7803+#define ATOMIC_OP(op, asm_op) __ATOMIC_OP(op, , , asm_op, , ) \
7804+ __ATOMIC_OP(op, _unchecked, __OVERFLOW_PRE, __REFCOUNT_OP(asm_op), __OVERFLOW_POST, __OVERFLOW_EXTABLE)
7805+
7806+#define __ATOMIC_OP_RETURN(op, suffix, pre_op, asm_op, post_op, extable)\
7807+static inline int atomic_##op##_return##suffix(int a, atomic##suffix##_t *v)\
7808 { \
7809 int t; \
7810 \
7811 __asm__ __volatile__( \
7812 PPC_ATOMIC_ENTRY_BARRIER \
7813-"1: lwarx %0,0,%2 # atomic_" #op "_return\n" \
7814+"1: lwarx %0,0,%2 # atomic_" #op "_return" #suffix "\n" \
7815+ pre_op \
7816 #asm_op " %0,%1,%0\n" \
7817+ post_op \
7818 PPC405_ERR77(0,%2) \
7819 " stwcx. %0,0,%2 \n" \
7820 " bne- 1b\n" \
7821+ extable \
7822 PPC_ATOMIC_EXIT_BARRIER \
7823 : "=&r" (t) \
7824 : "r" (a), "r" (&v->counter) \
7825@@ -62,6 +108,9 @@ static __inline__ int atomic_##op##_return(int a, atomic_t *v) \
7826 return t; \
7827 }
7828
7829+#define ATOMIC_OP_RETURN(op, asm_op) __ATOMIC_OP_RETURN(op, , , asm_op, , )\
7830+ __ATOMIC_OP_RETURN(op, _unchecked, __OVERFLOW_PRE, __REFCOUNT_OP(asm_op), __OVERFLOW_POST, __OVERFLOW_EXTABLE)
7831+
7832 #define ATOMIC_OPS(op, asm_op) ATOMIC_OP(op, asm_op) ATOMIC_OP_RETURN(op, asm_op)
7833
7834 ATOMIC_OPS(add, add)
7835@@ -69,42 +118,29 @@ ATOMIC_OPS(sub, subf)
7836
7837 #undef ATOMIC_OPS
7838 #undef ATOMIC_OP_RETURN
7839+#undef __ATOMIC_OP_RETURN
7840 #undef ATOMIC_OP
7841+#undef __ATOMIC_OP
7842
7843 #define atomic_add_negative(a, v) (atomic_add_return((a), (v)) < 0)
7844
7845-static __inline__ void atomic_inc(atomic_t *v)
7846-{
7847- int t;
7848+/*
7849+ * atomic_inc - increment atomic variable
7850+ * @v: pointer of type atomic_t
7851+ *
7852+ * Automatically increments @v by 1
7853+ */
7854+#define atomic_inc(v) atomic_add(1, (v))
7855+#define atomic_inc_return(v) atomic_add_return(1, (v))
7856
7857- __asm__ __volatile__(
7858-"1: lwarx %0,0,%2 # atomic_inc\n\
7859- addic %0,%0,1\n"
7860- PPC405_ERR77(0,%2)
7861-" stwcx. %0,0,%2 \n\
7862- bne- 1b"
7863- : "=&r" (t), "+m" (v->counter)
7864- : "r" (&v->counter)
7865- : "cc", "xer");
7866+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
7867+{
7868+ atomic_add_unchecked(1, v);
7869 }
7870
7871-static __inline__ int atomic_inc_return(atomic_t *v)
7872+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
7873 {
7874- int t;
7875-
7876- __asm__ __volatile__(
7877- PPC_ATOMIC_ENTRY_BARRIER
7878-"1: lwarx %0,0,%1 # atomic_inc_return\n\
7879- addic %0,%0,1\n"
7880- PPC405_ERR77(0,%1)
7881-" stwcx. %0,0,%1 \n\
7882- bne- 1b"
7883- PPC_ATOMIC_EXIT_BARRIER
7884- : "=&r" (t)
7885- : "r" (&v->counter)
7886- : "cc", "xer", "memory");
7887-
7888- return t;
7889+ return atomic_add_return_unchecked(1, v);
7890 }
7891
7892 /*
7893@@ -117,43 +153,38 @@ static __inline__ int atomic_inc_return(atomic_t *v)
7894 */
7895 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
7896
7897-static __inline__ void atomic_dec(atomic_t *v)
7898+static __inline__ int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
7899 {
7900- int t;
7901-
7902- __asm__ __volatile__(
7903-"1: lwarx %0,0,%2 # atomic_dec\n\
7904- addic %0,%0,-1\n"
7905- PPC405_ERR77(0,%2)\
7906-" stwcx. %0,0,%2\n\
7907- bne- 1b"
7908- : "=&r" (t), "+m" (v->counter)
7909- : "r" (&v->counter)
7910- : "cc", "xer");
7911+ return atomic_add_return_unchecked(1, v) == 0;
7912 }
7913
7914-static __inline__ int atomic_dec_return(atomic_t *v)
7915+/*
7916+ * atomic_dec - decrement atomic variable
7917+ * @v: pointer of type atomic_t
7918+ *
7919+ * Atomically decrements @v by 1
7920+ */
7921+#define atomic_dec(v) atomic_sub(1, (v))
7922+#define atomic_dec_return(v) atomic_sub_return(1, (v))
7923+
7924+static __inline__ void atomic_dec_unchecked(atomic_unchecked_t *v)
7925 {
7926- int t;
7927-
7928- __asm__ __volatile__(
7929- PPC_ATOMIC_ENTRY_BARRIER
7930-"1: lwarx %0,0,%1 # atomic_dec_return\n\
7931- addic %0,%0,-1\n"
7932- PPC405_ERR77(0,%1)
7933-" stwcx. %0,0,%1\n\
7934- bne- 1b"
7935- PPC_ATOMIC_EXIT_BARRIER
7936- : "=&r" (t)
7937- : "r" (&v->counter)
7938- : "cc", "xer", "memory");
7939-
7940- return t;
7941+ atomic_sub_unchecked(1, v);
7942 }
7943
7944 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
7945 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
7946
7947+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
7948+{
7949+ return cmpxchg(&(v->counter), old, new);
7950+}
7951+
7952+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
7953+{
7954+ return xchg(&(v->counter), new);
7955+}
7956+
7957 /**
7958 * __atomic_add_unless - add unless the number is a given value
7959 * @v: pointer of type atomic_t
7960@@ -171,11 +202,27 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
7961 PPC_ATOMIC_ENTRY_BARRIER
7962 "1: lwarx %0,0,%1 # __atomic_add_unless\n\
7963 cmpw 0,%0,%3 \n\
7964- beq- 2f \n\
7965- add %0,%2,%0 \n"
7966+ beq- 2f \n"
7967+
7968+#ifdef CONFIG_PAX_REFCOUNT
7969+" mcrxr cr0\n"
7970+" addo. %0,%2,%0\n"
7971+" bf 4*cr0+so, 4f\n"
7972+"3:.long " "0x00c00b00""\n"
7973+"4:\n"
7974+#else
7975+ "add %0,%2,%0 \n"
7976+#endif
7977+
7978 PPC405_ERR77(0,%2)
7979 " stwcx. %0,0,%1 \n\
7980 bne- 1b \n"
7981+"5:"
7982+
7983+#ifdef CONFIG_PAX_REFCOUNT
7984+ _ASM_EXTABLE(3b, 5b)
7985+#endif
7986+
7987 PPC_ATOMIC_EXIT_BARRIER
7988 " subf %0,%2,%0 \n\
7989 2:"
7990@@ -248,6 +295,11 @@ static __inline__ int atomic_dec_if_positive(atomic_t *v)
7991 }
7992 #define atomic_dec_if_positive atomic_dec_if_positive
7993
7994+#define smp_mb__before_atomic_dec() smp_mb()
7995+#define smp_mb__after_atomic_dec() smp_mb()
7996+#define smp_mb__before_atomic_inc() smp_mb()
7997+#define smp_mb__after_atomic_inc() smp_mb()
7998+
7999 #ifdef __powerpc64__
8000
8001 #define ATOMIC64_INIT(i) { (i) }
8002@@ -261,37 +313,60 @@ static __inline__ long atomic64_read(const atomic64_t *v)
8003 return t;
8004 }
8005
8006+static __inline__ long atomic64_read_unchecked(const atomic64_unchecked_t *v)
8007+{
8008+ long t;
8009+
8010+ __asm__ __volatile__("ld%U1%X1 %0,%1" : "=r"(t) : "m"(v->counter));
8011+
8012+ return t;
8013+}
8014+
8015 static __inline__ void atomic64_set(atomic64_t *v, long i)
8016 {
8017 __asm__ __volatile__("std%U0%X0 %1,%0" : "=m"(v->counter) : "r"(i));
8018 }
8019
8020-#define ATOMIC64_OP(op, asm_op) \
8021-static __inline__ void atomic64_##op(long a, atomic64_t *v) \
8022+static __inline__ void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
8023+{
8024+ __asm__ __volatile__("std%U0%X0 %1,%0" : "=m"(v->counter) : "r"(i));
8025+}
8026+
8027+#define __ATOMIC64_OP(op, suffix, pre_op, asm_op, post_op, extable) \
8028+static inline void atomic64_##op##suffix(long a, atomic64##suffix##_t *v)\
8029 { \
8030 long t; \
8031 \
8032 __asm__ __volatile__( \
8033 "1: ldarx %0,0,%3 # atomic64_" #op "\n" \
8034+ pre_op \
8035 #asm_op " %0,%2,%0\n" \
8036+ post_op \
8037 " stdcx. %0,0,%3 \n" \
8038 " bne- 1b\n" \
8039+ extable \
8040 : "=&r" (t), "+m" (v->counter) \
8041 : "r" (a), "r" (&v->counter) \
8042 : "cc"); \
8043 }
8044
8045-#define ATOMIC64_OP_RETURN(op, asm_op) \
8046-static __inline__ long atomic64_##op##_return(long a, atomic64_t *v) \
8047+#define ATOMIC64_OP(op, asm_op) __ATOMIC64_OP(op, , , asm_op, , ) \
8048+ __ATOMIC64_OP(op, _unchecked, __OVERFLOW_PRE, __REFCOUNT_OP(asm_op), __OVERFLOW_POST, __OVERFLOW_EXTABLE)
8049+
8050+#define __ATOMIC64_OP_RETURN(op, suffix, pre_op, asm_op, post_op, extable)\
8051+static inline long atomic64_##op##_return##suffix(long a, atomic64##suffix##_t *v)\
8052 { \
8053 long t; \
8054 \
8055 __asm__ __volatile__( \
8056 PPC_ATOMIC_ENTRY_BARRIER \
8057 "1: ldarx %0,0,%2 # atomic64_" #op "_return\n" \
8058+ pre_op \
8059 #asm_op " %0,%1,%0\n" \
8060+ post_op \
8061 " stdcx. %0,0,%2 \n" \
8062 " bne- 1b\n" \
8063+ extable \
8064 PPC_ATOMIC_EXIT_BARRIER \
8065 : "=&r" (t) \
8066 : "r" (a), "r" (&v->counter) \
8067@@ -300,6 +375,9 @@ static __inline__ long atomic64_##op##_return(long a, atomic64_t *v) \
8068 return t; \
8069 }
8070
8071+#define ATOMIC64_OP_RETURN(op, asm_op) __ATOMIC64_OP_RETURN(op, , , asm_op, , )\
8072+ __ATOMIC64_OP_RETURN(op, _unchecked, __OVERFLOW_PRE, __REFCOUNT_OP(asm_op), __OVERFLOW_POST, __OVERFLOW_EXTABLE)
8073+
8074 #define ATOMIC64_OPS(op, asm_op) ATOMIC64_OP(op, asm_op) ATOMIC64_OP_RETURN(op, asm_op)
8075
8076 ATOMIC64_OPS(add, add)
8077@@ -307,40 +385,33 @@ ATOMIC64_OPS(sub, subf)
8078
8079 #undef ATOMIC64_OPS
8080 #undef ATOMIC64_OP_RETURN
8081+#undef __ATOMIC64_OP_RETURN
8082 #undef ATOMIC64_OP
8083+#undef __ATOMIC64_OP
8084+#undef __OVERFLOW_EXTABLE
8085+#undef __OVERFLOW_POST
8086+#undef __OVERFLOW_PRE
8087+#undef __REFCOUNT_OP
8088
8089 #define atomic64_add_negative(a, v) (atomic64_add_return((a), (v)) < 0)
8090
8091-static __inline__ void atomic64_inc(atomic64_t *v)
8092-{
8093- long t;
8094+/*
8095+ * atomic64_inc - increment atomic variable
8096+ * @v: pointer of type atomic64_t
8097+ *
8098+ * Automatically increments @v by 1
8099+ */
8100+#define atomic64_inc(v) atomic64_add(1, (v))
8101+#define atomic64_inc_return(v) atomic64_add_return(1, (v))
8102
8103- __asm__ __volatile__(
8104-"1: ldarx %0,0,%2 # atomic64_inc\n\
8105- addic %0,%0,1\n\
8106- stdcx. %0,0,%2 \n\
8107- bne- 1b"
8108- : "=&r" (t), "+m" (v->counter)
8109- : "r" (&v->counter)
8110- : "cc", "xer");
8111+static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
8112+{
8113+ atomic64_add_unchecked(1, v);
8114 }
8115
8116-static __inline__ long atomic64_inc_return(atomic64_t *v)
8117+static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
8118 {
8119- long t;
8120-
8121- __asm__ __volatile__(
8122- PPC_ATOMIC_ENTRY_BARRIER
8123-"1: ldarx %0,0,%1 # atomic64_inc_return\n\
8124- addic %0,%0,1\n\
8125- stdcx. %0,0,%1 \n\
8126- bne- 1b"
8127- PPC_ATOMIC_EXIT_BARRIER
8128- : "=&r" (t)
8129- : "r" (&v->counter)
8130- : "cc", "xer", "memory");
8131-
8132- return t;
8133+ return atomic64_add_return_unchecked(1, v);
8134 }
8135
8136 /*
8137@@ -353,36 +424,18 @@ static __inline__ long atomic64_inc_return(atomic64_t *v)
8138 */
8139 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
8140
8141-static __inline__ void atomic64_dec(atomic64_t *v)
8142+/*
8143+ * atomic64_dec - decrement atomic variable
8144+ * @v: pointer of type atomic64_t
8145+ *
8146+ * Atomically decrements @v by 1
8147+ */
8148+#define atomic64_dec(v) atomic64_sub(1, (v))
8149+#define atomic64_dec_return(v) atomic64_sub_return(1, (v))
8150+
8151+static __inline__ void atomic64_dec_unchecked(atomic64_unchecked_t *v)
8152 {
8153- long t;
8154-
8155- __asm__ __volatile__(
8156-"1: ldarx %0,0,%2 # atomic64_dec\n\
8157- addic %0,%0,-1\n\
8158- stdcx. %0,0,%2\n\
8159- bne- 1b"
8160- : "=&r" (t), "+m" (v->counter)
8161- : "r" (&v->counter)
8162- : "cc", "xer");
8163-}
8164-
8165-static __inline__ long atomic64_dec_return(atomic64_t *v)
8166-{
8167- long t;
8168-
8169- __asm__ __volatile__(
8170- PPC_ATOMIC_ENTRY_BARRIER
8171-"1: ldarx %0,0,%1 # atomic64_dec_return\n\
8172- addic %0,%0,-1\n\
8173- stdcx. %0,0,%1\n\
8174- bne- 1b"
8175- PPC_ATOMIC_EXIT_BARRIER
8176- : "=&r" (t)
8177- : "r" (&v->counter)
8178- : "cc", "xer", "memory");
8179-
8180- return t;
8181+ atomic64_sub_unchecked(1, v);
8182 }
8183
8184 #define atomic64_sub_and_test(a, v) (atomic64_sub_return((a), (v)) == 0)
8185@@ -415,6 +468,16 @@ static __inline__ long atomic64_dec_if_positive(atomic64_t *v)
8186 #define atomic64_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
8187 #define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
8188
8189+static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
8190+{
8191+ return cmpxchg(&(v->counter), old, new);
8192+}
8193+
8194+static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
8195+{
8196+ return xchg(&(v->counter), new);
8197+}
8198+
8199 /**
8200 * atomic64_add_unless - add unless the number is a given value
8201 * @v: pointer of type atomic64_t
8202@@ -430,13 +493,29 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
8203
8204 __asm__ __volatile__ (
8205 PPC_ATOMIC_ENTRY_BARRIER
8206-"1: ldarx %0,0,%1 # __atomic_add_unless\n\
8207+"1: ldarx %0,0,%1 # atomic64_add_unless\n\
8208 cmpd 0,%0,%3 \n\
8209- beq- 2f \n\
8210- add %0,%2,%0 \n"
8211+ beq- 2f \n"
8212+
8213+#ifdef CONFIG_PAX_REFCOUNT
8214+" mcrxr cr0\n"
8215+" addo. %0,%2,%0\n"
8216+" bf 4*cr0+so, 4f\n"
8217+"3:.long " "0x00c00b00""\n"
8218+"4:\n"
8219+#else
8220+ "add %0,%2,%0 \n"
8221+#endif
8222+
8223 " stdcx. %0,0,%1 \n\
8224 bne- 1b \n"
8225 PPC_ATOMIC_EXIT_BARRIER
8226+"5:"
8227+
8228+#ifdef CONFIG_PAX_REFCOUNT
8229+ _ASM_EXTABLE(3b, 5b)
8230+#endif
8231+
8232 " subf %0,%2,%0 \n\
8233 2:"
8234 : "=&r" (t)
8235diff --git a/arch/powerpc/include/asm/barrier.h b/arch/powerpc/include/asm/barrier.h
8236index bab79a1..4a3eabc 100644
8237--- a/arch/powerpc/include/asm/barrier.h
8238+++ b/arch/powerpc/include/asm/barrier.h
8239@@ -73,7 +73,7 @@
8240 do { \
8241 compiletime_assert_atomic_type(*p); \
8242 __lwsync(); \
8243- ACCESS_ONCE(*p) = (v); \
8244+ ACCESS_ONCE_RW(*p) = (v); \
8245 } while (0)
8246
8247 #define smp_load_acquire(p) \
8248diff --git a/arch/powerpc/include/asm/cache.h b/arch/powerpc/include/asm/cache.h
8249index 34a05a1..a1f2c67 100644
8250--- a/arch/powerpc/include/asm/cache.h
8251+++ b/arch/powerpc/include/asm/cache.h
8252@@ -4,6 +4,7 @@
8253 #ifdef __KERNEL__
8254
8255 #include <asm/reg.h>
8256+#include <linux/const.h>
8257
8258 /* bytes per L1 cache line */
8259 #if defined(CONFIG_8xx) || defined(CONFIG_403GCX)
8260@@ -23,7 +24,7 @@
8261 #define L1_CACHE_SHIFT 7
8262 #endif
8263
8264-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
8265+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
8266
8267 #define SMP_CACHE_BYTES L1_CACHE_BYTES
8268
8269diff --git a/arch/powerpc/include/asm/elf.h b/arch/powerpc/include/asm/elf.h
8270index 888d8f3..66f581c 100644
8271--- a/arch/powerpc/include/asm/elf.h
8272+++ b/arch/powerpc/include/asm/elf.h
8273@@ -28,8 +28,19 @@
8274 the loader. We need to make sure that it is out of the way of the program
8275 that it will "exec", and that there is sufficient room for the brk. */
8276
8277-extern unsigned long randomize_et_dyn(unsigned long base);
8278-#define ELF_ET_DYN_BASE (randomize_et_dyn(0x20000000))
8279+#define ELF_ET_DYN_BASE (0x20000000)
8280+
8281+#ifdef CONFIG_PAX_ASLR
8282+#define PAX_ELF_ET_DYN_BASE (0x10000000UL)
8283+
8284+#ifdef __powerpc64__
8285+#define PAX_DELTA_MMAP_LEN (is_32bit_task() ? 16 : 28)
8286+#define PAX_DELTA_STACK_LEN (is_32bit_task() ? 16 : 28)
8287+#else
8288+#define PAX_DELTA_MMAP_LEN 15
8289+#define PAX_DELTA_STACK_LEN 15
8290+#endif
8291+#endif
8292
8293 #define ELF_CORE_EFLAGS (is_elf2_task() ? 2 : 0)
8294
8295@@ -129,10 +140,6 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
8296 (0x7ff >> (PAGE_SHIFT - 12)) : \
8297 (0x3ffff >> (PAGE_SHIFT - 12)))
8298
8299-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
8300-#define arch_randomize_brk arch_randomize_brk
8301-
8302-
8303 #ifdef CONFIG_SPU_BASE
8304 /* Notes used in ET_CORE. Note name is "SPU/<fd>/<filename>". */
8305 #define NT_SPU 1
8306diff --git a/arch/powerpc/include/asm/exec.h b/arch/powerpc/include/asm/exec.h
8307index 8196e9c..d83a9f3 100644
8308--- a/arch/powerpc/include/asm/exec.h
8309+++ b/arch/powerpc/include/asm/exec.h
8310@@ -4,6 +4,6 @@
8311 #ifndef _ASM_POWERPC_EXEC_H
8312 #define _ASM_POWERPC_EXEC_H
8313
8314-extern unsigned long arch_align_stack(unsigned long sp);
8315+#define arch_align_stack(x) ((x) & ~0xfUL)
8316
8317 #endif /* _ASM_POWERPC_EXEC_H */
8318diff --git a/arch/powerpc/include/asm/kmap_types.h b/arch/powerpc/include/asm/kmap_types.h
8319index 5acabbd..7ea14fa 100644
8320--- a/arch/powerpc/include/asm/kmap_types.h
8321+++ b/arch/powerpc/include/asm/kmap_types.h
8322@@ -10,7 +10,7 @@
8323 * 2 of the License, or (at your option) any later version.
8324 */
8325
8326-#define KM_TYPE_NR 16
8327+#define KM_TYPE_NR 17
8328
8329 #endif /* __KERNEL__ */
8330 #endif /* _ASM_POWERPC_KMAP_TYPES_H */
8331diff --git a/arch/powerpc/include/asm/local.h b/arch/powerpc/include/asm/local.h
8332index b8da913..c02b593 100644
8333--- a/arch/powerpc/include/asm/local.h
8334+++ b/arch/powerpc/include/asm/local.h
8335@@ -9,21 +9,65 @@ typedef struct
8336 atomic_long_t a;
8337 } local_t;
8338
8339+typedef struct
8340+{
8341+ atomic_long_unchecked_t a;
8342+} local_unchecked_t;
8343+
8344 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
8345
8346 #define local_read(l) atomic_long_read(&(l)->a)
8347+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
8348 #define local_set(l,i) atomic_long_set(&(l)->a, (i))
8349+#define local_set_unchecked(l,i) atomic_long_set_unchecked(&(l)->a, (i))
8350
8351 #define local_add(i,l) atomic_long_add((i),(&(l)->a))
8352+#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
8353 #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
8354+#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
8355 #define local_inc(l) atomic_long_inc(&(l)->a)
8356+#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
8357 #define local_dec(l) atomic_long_dec(&(l)->a)
8358+#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
8359
8360 static __inline__ long local_add_return(long a, local_t *l)
8361 {
8362 long t;
8363
8364 __asm__ __volatile__(
8365+"1:" PPC_LLARX(%0,0,%2,0) " # local_add_return\n"
8366+
8367+#ifdef CONFIG_PAX_REFCOUNT
8368+" mcrxr cr0\n"
8369+" addo. %0,%1,%0\n"
8370+" bf 4*cr0+so, 3f\n"
8371+"2:.long " "0x00c00b00""\n"
8372+#else
8373+" add %0,%1,%0\n"
8374+#endif
8375+
8376+"3:\n"
8377+ PPC405_ERR77(0,%2)
8378+ PPC_STLCX "%0,0,%2 \n\
8379+ bne- 1b"
8380+
8381+#ifdef CONFIG_PAX_REFCOUNT
8382+"\n4:\n"
8383+ _ASM_EXTABLE(2b, 4b)
8384+#endif
8385+
8386+ : "=&r" (t)
8387+ : "r" (a), "r" (&(l->a.counter))
8388+ : "cc", "memory");
8389+
8390+ return t;
8391+}
8392+
8393+static __inline__ long local_add_return_unchecked(long a, local_unchecked_t *l)
8394+{
8395+ long t;
8396+
8397+ __asm__ __volatile__(
8398 "1:" PPC_LLARX(%0,0,%2,0) " # local_add_return\n\
8399 add %0,%1,%0\n"
8400 PPC405_ERR77(0,%2)
8401@@ -101,6 +145,8 @@ static __inline__ long local_dec_return(local_t *l)
8402
8403 #define local_cmpxchg(l, o, n) \
8404 (cmpxchg_local(&((l)->a.counter), (o), (n)))
8405+#define local_cmpxchg_unchecked(l, o, n) \
8406+ (cmpxchg_local(&((l)->a.counter), (o), (n)))
8407 #define local_xchg(l, n) (xchg_local(&((l)->a.counter), (n)))
8408
8409 /**
8410diff --git a/arch/powerpc/include/asm/mman.h b/arch/powerpc/include/asm/mman.h
8411index 8565c25..2865190 100644
8412--- a/arch/powerpc/include/asm/mman.h
8413+++ b/arch/powerpc/include/asm/mman.h
8414@@ -24,7 +24,7 @@ static inline unsigned long arch_calc_vm_prot_bits(unsigned long prot)
8415 }
8416 #define arch_calc_vm_prot_bits(prot) arch_calc_vm_prot_bits(prot)
8417
8418-static inline pgprot_t arch_vm_get_page_prot(unsigned long vm_flags)
8419+static inline pgprot_t arch_vm_get_page_prot(vm_flags_t vm_flags)
8420 {
8421 return (vm_flags & VM_SAO) ? __pgprot(_PAGE_SAO) : __pgprot(0);
8422 }
8423diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h
8424index 26fe1ae..987ffc5 100644
8425--- a/arch/powerpc/include/asm/page.h
8426+++ b/arch/powerpc/include/asm/page.h
8427@@ -227,8 +227,9 @@ extern long long virt_phys_offset;
8428 * and needs to be executable. This means the whole heap ends
8429 * up being executable.
8430 */
8431-#define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
8432- VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8433+#define VM_DATA_DEFAULT_FLAGS32 \
8434+ (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
8435+ VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8436
8437 #define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
8438 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8439@@ -256,6 +257,9 @@ extern long long virt_phys_offset;
8440 #define is_kernel_addr(x) ((x) >= PAGE_OFFSET)
8441 #endif
8442
8443+#define ktla_ktva(addr) (addr)
8444+#define ktva_ktla(addr) (addr)
8445+
8446 #ifndef CONFIG_PPC_BOOK3S_64
8447 /*
8448 * Use the top bit of the higher-level page table entries to indicate whether
8449diff --git a/arch/powerpc/include/asm/page_64.h b/arch/powerpc/include/asm/page_64.h
8450index d908a46..3753f71 100644
8451--- a/arch/powerpc/include/asm/page_64.h
8452+++ b/arch/powerpc/include/asm/page_64.h
8453@@ -172,15 +172,18 @@ do { \
8454 * stack by default, so in the absence of a PT_GNU_STACK program header
8455 * we turn execute permission off.
8456 */
8457-#define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
8458- VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8459+#define VM_STACK_DEFAULT_FLAGS32 \
8460+ (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
8461+ VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8462
8463 #define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
8464 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8465
8466+#ifndef CONFIG_PAX_PAGEEXEC
8467 #define VM_STACK_DEFAULT_FLAGS \
8468 (is_32bit_task() ? \
8469 VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
8470+#endif
8471
8472 #include <asm-generic/getorder.h>
8473
8474diff --git a/arch/powerpc/include/asm/pgalloc-64.h b/arch/powerpc/include/asm/pgalloc-64.h
8475index 4b0be20..c15a27d 100644
8476--- a/arch/powerpc/include/asm/pgalloc-64.h
8477+++ b/arch/powerpc/include/asm/pgalloc-64.h
8478@@ -54,6 +54,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
8479 #ifndef CONFIG_PPC_64K_PAGES
8480
8481 #define pgd_populate(MM, PGD, PUD) pgd_set(PGD, PUD)
8482+#define pgd_populate_kernel(MM, PGD, PUD) pgd_populate((MM), (PGD), (PUD))
8483
8484 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
8485 {
8486@@ -71,6 +72,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
8487 pud_set(pud, (unsigned long)pmd);
8488 }
8489
8490+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
8491+{
8492+ pud_populate(mm, pud, pmd);
8493+}
8494+
8495 #define pmd_populate(mm, pmd, pte_page) \
8496 pmd_populate_kernel(mm, pmd, page_address(pte_page))
8497 #define pmd_populate_kernel(mm, pmd, pte) pmd_set(pmd, (unsigned long)(pte))
8498@@ -173,6 +179,7 @@ extern void __tlb_remove_table(void *_table);
8499 #endif
8500
8501 #define pud_populate(mm, pud, pmd) pud_set(pud, (unsigned long)pmd)
8502+#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
8503
8504 static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,
8505 pte_t *pte)
8506diff --git a/arch/powerpc/include/asm/pgtable.h b/arch/powerpc/include/asm/pgtable.h
8507index 316f9a5..ba05c77 100644
8508--- a/arch/powerpc/include/asm/pgtable.h
8509+++ b/arch/powerpc/include/asm/pgtable.h
8510@@ -2,6 +2,7 @@
8511 #define _ASM_POWERPC_PGTABLE_H
8512 #ifdef __KERNEL__
8513
8514+#include <linux/const.h>
8515 #ifndef __ASSEMBLY__
8516 #include <linux/mmdebug.h>
8517 #include <linux/mmzone.h>
8518diff --git a/arch/powerpc/include/asm/pte-hash32.h b/arch/powerpc/include/asm/pte-hash32.h
8519index 4aad413..85d86bf 100644
8520--- a/arch/powerpc/include/asm/pte-hash32.h
8521+++ b/arch/powerpc/include/asm/pte-hash32.h
8522@@ -21,6 +21,7 @@
8523 #define _PAGE_FILE 0x004 /* when !present: nonlinear file mapping */
8524 #define _PAGE_USER 0x004 /* usermode access allowed */
8525 #define _PAGE_GUARDED 0x008 /* G: prohibit speculative access */
8526+#define _PAGE_EXEC _PAGE_GUARDED
8527 #define _PAGE_COHERENT 0x010 /* M: enforce memory coherence (SMP systems) */
8528 #define _PAGE_NO_CACHE 0x020 /* I: cache inhibit */
8529 #define _PAGE_WRITETHRU 0x040 /* W: cache write-through */
8530diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h
8531index a68ee15..552d213 100644
8532--- a/arch/powerpc/include/asm/reg.h
8533+++ b/arch/powerpc/include/asm/reg.h
8534@@ -253,6 +253,7 @@
8535 #define SPRN_DBCR 0x136 /* e300 Data Breakpoint Control Reg */
8536 #define SPRN_DSISR 0x012 /* Data Storage Interrupt Status Register */
8537 #define DSISR_NOHPTE 0x40000000 /* no translation found */
8538+#define DSISR_GUARDED 0x10000000 /* fetch from guarded storage */
8539 #define DSISR_PROTFAULT 0x08000000 /* protection fault */
8540 #define DSISR_ISSTORE 0x02000000 /* access was a store */
8541 #define DSISR_DABRMATCH 0x00400000 /* hit data breakpoint */
8542diff --git a/arch/powerpc/include/asm/smp.h b/arch/powerpc/include/asm/smp.h
8543index 5a6614a..d89995d1 100644
8544--- a/arch/powerpc/include/asm/smp.h
8545+++ b/arch/powerpc/include/asm/smp.h
8546@@ -51,7 +51,7 @@ struct smp_ops_t {
8547 int (*cpu_disable)(void);
8548 void (*cpu_die)(unsigned int nr);
8549 int (*cpu_bootable)(unsigned int nr);
8550-};
8551+} __no_const;
8552
8553 extern void smp_send_debugger_break(void);
8554 extern void start_secondary_resume(void);
8555diff --git a/arch/powerpc/include/asm/spinlock.h b/arch/powerpc/include/asm/spinlock.h
8556index 4dbe072..b803275 100644
8557--- a/arch/powerpc/include/asm/spinlock.h
8558+++ b/arch/powerpc/include/asm/spinlock.h
8559@@ -204,13 +204,29 @@ static inline long __arch_read_trylock(arch_rwlock_t *rw)
8560 __asm__ __volatile__(
8561 "1: " PPC_LWARX(%0,0,%1,1) "\n"
8562 __DO_SIGN_EXTEND
8563-" addic. %0,%0,1\n\
8564- ble- 2f\n"
8565+
8566+#ifdef CONFIG_PAX_REFCOUNT
8567+" mcrxr cr0\n"
8568+" addico. %0,%0,1\n"
8569+" bf 4*cr0+so, 3f\n"
8570+"2:.long " "0x00c00b00""\n"
8571+#else
8572+" addic. %0,%0,1\n"
8573+#endif
8574+
8575+"3:\n"
8576+ "ble- 4f\n"
8577 PPC405_ERR77(0,%1)
8578 " stwcx. %0,0,%1\n\
8579 bne- 1b\n"
8580 PPC_ACQUIRE_BARRIER
8581-"2:" : "=&r" (tmp)
8582+"4:"
8583+
8584+#ifdef CONFIG_PAX_REFCOUNT
8585+ _ASM_EXTABLE(2b,4b)
8586+#endif
8587+
8588+ : "=&r" (tmp)
8589 : "r" (&rw->lock)
8590 : "cr0", "xer", "memory");
8591
8592@@ -286,11 +302,27 @@ static inline void arch_read_unlock(arch_rwlock_t *rw)
8593 __asm__ __volatile__(
8594 "# read_unlock\n\t"
8595 PPC_RELEASE_BARRIER
8596-"1: lwarx %0,0,%1\n\
8597- addic %0,%0,-1\n"
8598+"1: lwarx %0,0,%1\n"
8599+
8600+#ifdef CONFIG_PAX_REFCOUNT
8601+" mcrxr cr0\n"
8602+" addico. %0,%0,-1\n"
8603+" bf 4*cr0+so, 3f\n"
8604+"2:.long " "0x00c00b00""\n"
8605+#else
8606+" addic. %0,%0,-1\n"
8607+#endif
8608+
8609+"3:\n"
8610 PPC405_ERR77(0,%1)
8611 " stwcx. %0,0,%1\n\
8612 bne- 1b"
8613+
8614+#ifdef CONFIG_PAX_REFCOUNT
8615+"\n4:\n"
8616+ _ASM_EXTABLE(2b, 4b)
8617+#endif
8618+
8619 : "=&r"(tmp)
8620 : "r"(&rw->lock)
8621 : "cr0", "xer", "memory");
8622diff --git a/arch/powerpc/include/asm/thread_info.h b/arch/powerpc/include/asm/thread_info.h
8623index b034ecd..af7e31f 100644
8624--- a/arch/powerpc/include/asm/thread_info.h
8625+++ b/arch/powerpc/include/asm/thread_info.h
8626@@ -107,6 +107,8 @@ static inline struct thread_info *current_thread_info(void)
8627 #if defined(CONFIG_PPC64)
8628 #define TIF_ELF2ABI 18 /* function descriptors must die! */
8629 #endif
8630+/* mask must be expressable within 16 bits to satisfy 'andi' instruction reqs */
8631+#define TIF_GRSEC_SETXID 6 /* update credentials on syscall entry/exit */
8632
8633 /* as above, but as bit values */
8634 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
8635@@ -125,9 +127,10 @@ static inline struct thread_info *current_thread_info(void)
8636 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
8637 #define _TIF_EMULATE_STACK_STORE (1<<TIF_EMULATE_STACK_STORE)
8638 #define _TIF_NOHZ (1<<TIF_NOHZ)
8639+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
8640 #define _TIF_SYSCALL_T_OR_A (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
8641 _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT | \
8642- _TIF_NOHZ)
8643+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
8644
8645 #define _TIF_USER_WORK_MASK (_TIF_SIGPENDING | _TIF_NEED_RESCHED | \
8646 _TIF_NOTIFY_RESUME | _TIF_UPROBE | \
8647diff --git a/arch/powerpc/include/asm/uaccess.h b/arch/powerpc/include/asm/uaccess.h
8648index 9485b43..3bd3c16 100644
8649--- a/arch/powerpc/include/asm/uaccess.h
8650+++ b/arch/powerpc/include/asm/uaccess.h
8651@@ -58,6 +58,7 @@
8652
8653 #endif
8654
8655+#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
8656 #define access_ok(type, addr, size) \
8657 (__chk_user_ptr(addr), \
8658 __access_ok((__force unsigned long)(addr), (size), get_fs()))
8659@@ -318,52 +319,6 @@ do { \
8660 extern unsigned long __copy_tofrom_user(void __user *to,
8661 const void __user *from, unsigned long size);
8662
8663-#ifndef __powerpc64__
8664-
8665-static inline unsigned long copy_from_user(void *to,
8666- const void __user *from, unsigned long n)
8667-{
8668- unsigned long over;
8669-
8670- if (access_ok(VERIFY_READ, from, n))
8671- return __copy_tofrom_user((__force void __user *)to, from, n);
8672- if ((unsigned long)from < TASK_SIZE) {
8673- over = (unsigned long)from + n - TASK_SIZE;
8674- return __copy_tofrom_user((__force void __user *)to, from,
8675- n - over) + over;
8676- }
8677- return n;
8678-}
8679-
8680-static inline unsigned long copy_to_user(void __user *to,
8681- const void *from, unsigned long n)
8682-{
8683- unsigned long over;
8684-
8685- if (access_ok(VERIFY_WRITE, to, n))
8686- return __copy_tofrom_user(to, (__force void __user *)from, n);
8687- if ((unsigned long)to < TASK_SIZE) {
8688- over = (unsigned long)to + n - TASK_SIZE;
8689- return __copy_tofrom_user(to, (__force void __user *)from,
8690- n - over) + over;
8691- }
8692- return n;
8693-}
8694-
8695-#else /* __powerpc64__ */
8696-
8697-#define __copy_in_user(to, from, size) \
8698- __copy_tofrom_user((to), (from), (size))
8699-
8700-extern unsigned long copy_from_user(void *to, const void __user *from,
8701- unsigned long n);
8702-extern unsigned long copy_to_user(void __user *to, const void *from,
8703- unsigned long n);
8704-extern unsigned long copy_in_user(void __user *to, const void __user *from,
8705- unsigned long n);
8706-
8707-#endif /* __powerpc64__ */
8708-
8709 static inline unsigned long __copy_from_user_inatomic(void *to,
8710 const void __user *from, unsigned long n)
8711 {
8712@@ -387,6 +342,10 @@ static inline unsigned long __copy_from_user_inatomic(void *to,
8713 if (ret == 0)
8714 return 0;
8715 }
8716+
8717+ if (!__builtin_constant_p(n))
8718+ check_object_size(to, n, false);
8719+
8720 return __copy_tofrom_user((__force void __user *)to, from, n);
8721 }
8722
8723@@ -413,6 +372,10 @@ static inline unsigned long __copy_to_user_inatomic(void __user *to,
8724 if (ret == 0)
8725 return 0;
8726 }
8727+
8728+ if (!__builtin_constant_p(n))
8729+ check_object_size(from, n, true);
8730+
8731 return __copy_tofrom_user(to, (__force const void __user *)from, n);
8732 }
8733
8734@@ -430,6 +393,92 @@ static inline unsigned long __copy_to_user(void __user *to,
8735 return __copy_to_user_inatomic(to, from, size);
8736 }
8737
8738+#ifndef __powerpc64__
8739+
8740+static inline unsigned long __must_check copy_from_user(void *to,
8741+ const void __user *from, unsigned long n)
8742+{
8743+ unsigned long over;
8744+
8745+ if ((long)n < 0)
8746+ return n;
8747+
8748+ if (access_ok(VERIFY_READ, from, n)) {
8749+ if (!__builtin_constant_p(n))
8750+ check_object_size(to, n, false);
8751+ return __copy_tofrom_user((__force void __user *)to, from, n);
8752+ }
8753+ if ((unsigned long)from < TASK_SIZE) {
8754+ over = (unsigned long)from + n - TASK_SIZE;
8755+ if (!__builtin_constant_p(n - over))
8756+ check_object_size(to, n - over, false);
8757+ return __copy_tofrom_user((__force void __user *)to, from,
8758+ n - over) + over;
8759+ }
8760+ return n;
8761+}
8762+
8763+static inline unsigned long __must_check copy_to_user(void __user *to,
8764+ const void *from, unsigned long n)
8765+{
8766+ unsigned long over;
8767+
8768+ if ((long)n < 0)
8769+ return n;
8770+
8771+ if (access_ok(VERIFY_WRITE, to, n)) {
8772+ if (!__builtin_constant_p(n))
8773+ check_object_size(from, n, true);
8774+ return __copy_tofrom_user(to, (__force void __user *)from, n);
8775+ }
8776+ if ((unsigned long)to < TASK_SIZE) {
8777+ over = (unsigned long)to + n - TASK_SIZE;
8778+ if (!__builtin_constant_p(n))
8779+ check_object_size(from, n - over, true);
8780+ return __copy_tofrom_user(to, (__force void __user *)from,
8781+ n - over) + over;
8782+ }
8783+ return n;
8784+}
8785+
8786+#else /* __powerpc64__ */
8787+
8788+#define __copy_in_user(to, from, size) \
8789+ __copy_tofrom_user((to), (from), (size))
8790+
8791+static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
8792+{
8793+ if ((long)n < 0 || n > INT_MAX)
8794+ return n;
8795+
8796+ if (!__builtin_constant_p(n))
8797+ check_object_size(to, n, false);
8798+
8799+ if (likely(access_ok(VERIFY_READ, from, n)))
8800+ n = __copy_from_user(to, from, n);
8801+ else
8802+ memset(to, 0, n);
8803+ return n;
8804+}
8805+
8806+static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
8807+{
8808+ if ((long)n < 0 || n > INT_MAX)
8809+ return n;
8810+
8811+ if (likely(access_ok(VERIFY_WRITE, to, n))) {
8812+ if (!__builtin_constant_p(n))
8813+ check_object_size(from, n, true);
8814+ n = __copy_to_user(to, from, n);
8815+ }
8816+ return n;
8817+}
8818+
8819+extern unsigned long copy_in_user(void __user *to, const void __user *from,
8820+ unsigned long n);
8821+
8822+#endif /* __powerpc64__ */
8823+
8824 extern unsigned long __clear_user(void __user *addr, unsigned long size);
8825
8826 static inline unsigned long clear_user(void __user *addr, unsigned long size)
8827diff --git a/arch/powerpc/kernel/Makefile b/arch/powerpc/kernel/Makefile
8828index 502cf69..822e63b 100644
8829--- a/arch/powerpc/kernel/Makefile
8830+++ b/arch/powerpc/kernel/Makefile
8831@@ -27,6 +27,8 @@ CFLAGS_REMOVE_ftrace.o = -pg -mno-sched-epilog
8832 CFLAGS_REMOVE_time.o = -pg -mno-sched-epilog
8833 endif
8834
8835+CFLAGS_REMOVE_prom_init.o += $(LATENT_ENTROPY_PLUGIN_CFLAGS)
8836+
8837 obj-y := cputable.o ptrace.o syscalls.o \
8838 irq.o align.o signal_32.o pmc.o vdso.o \
8839 process.o systbl.o idle.o \
8840diff --git a/arch/powerpc/kernel/exceptions-64e.S b/arch/powerpc/kernel/exceptions-64e.S
8841index 3e68d1c..72a5ee6 100644
8842--- a/arch/powerpc/kernel/exceptions-64e.S
8843+++ b/arch/powerpc/kernel/exceptions-64e.S
8844@@ -1010,6 +1010,7 @@ storage_fault_common:
8845 std r14,_DAR(r1)
8846 std r15,_DSISR(r1)
8847 addi r3,r1,STACK_FRAME_OVERHEAD
8848+ bl save_nvgprs
8849 mr r4,r14
8850 mr r5,r15
8851 ld r14,PACA_EXGEN+EX_R14(r13)
8852@@ -1018,8 +1019,7 @@ storage_fault_common:
8853 cmpdi r3,0
8854 bne- 1f
8855 b ret_from_except_lite
8856-1: bl save_nvgprs
8857- mr r5,r3
8858+1: mr r5,r3
8859 addi r3,r1,STACK_FRAME_OVERHEAD
8860 ld r4,_DAR(r1)
8861 bl bad_page_fault
8862diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
8863index 72e783e..fe058e2 100644
8864--- a/arch/powerpc/kernel/exceptions-64s.S
8865+++ b/arch/powerpc/kernel/exceptions-64s.S
8866@@ -1588,10 +1588,10 @@ handle_page_fault:
8867 11: ld r4,_DAR(r1)
8868 ld r5,_DSISR(r1)
8869 addi r3,r1,STACK_FRAME_OVERHEAD
8870+ bl save_nvgprs
8871 bl do_page_fault
8872 cmpdi r3,0
8873 beq+ 12f
8874- bl save_nvgprs
8875 mr r5,r3
8876 addi r3,r1,STACK_FRAME_OVERHEAD
8877 lwz r4,_DAR(r1)
8878diff --git a/arch/powerpc/kernel/irq.c b/arch/powerpc/kernel/irq.c
8879index c143835..5a9697f 100644
8880--- a/arch/powerpc/kernel/irq.c
8881+++ b/arch/powerpc/kernel/irq.c
8882@@ -461,6 +461,8 @@ void migrate_irqs(void)
8883 }
8884 #endif
8885
8886+extern void gr_handle_kernel_exploit(void);
8887+
8888 static inline void check_stack_overflow(void)
8889 {
8890 #ifdef CONFIG_DEBUG_STACKOVERFLOW
8891@@ -473,6 +475,7 @@ static inline void check_stack_overflow(void)
8892 pr_err("do_IRQ: stack overflow: %ld\n",
8893 sp - sizeof(struct thread_info));
8894 dump_stack();
8895+ gr_handle_kernel_exploit();
8896 }
8897 #endif
8898 }
8899diff --git a/arch/powerpc/kernel/module_32.c b/arch/powerpc/kernel/module_32.c
8900index c94d2e0..992a9ce 100644
8901--- a/arch/powerpc/kernel/module_32.c
8902+++ b/arch/powerpc/kernel/module_32.c
8903@@ -158,7 +158,7 @@ int module_frob_arch_sections(Elf32_Ehdr *hdr,
8904 me->arch.core_plt_section = i;
8905 }
8906 if (!me->arch.core_plt_section || !me->arch.init_plt_section) {
8907- pr_err("Module doesn't contain .plt or .init.plt sections.\n");
8908+ pr_err("Module $s doesn't contain .plt or .init.plt sections.\n", me->name);
8909 return -ENOEXEC;
8910 }
8911
8912@@ -188,11 +188,16 @@ static uint32_t do_plt_call(void *location,
8913
8914 pr_debug("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location);
8915 /* Init, or core PLT? */
8916- if (location >= mod->module_core
8917- && location < mod->module_core + mod->core_size)
8918+ if ((location >= mod->module_core_rx && location < mod->module_core_rx + mod->core_size_rx) ||
8919+ (location >= mod->module_core_rw && location < mod->module_core_rw + mod->core_size_rw))
8920 entry = (void *)sechdrs[mod->arch.core_plt_section].sh_addr;
8921- else
8922+ else if ((location >= mod->module_init_rx && location < mod->module_init_rx + mod->init_size_rx) ||
8923+ (location >= mod->module_init_rw && location < mod->module_init_rw + mod->init_size_rw))
8924 entry = (void *)sechdrs[mod->arch.init_plt_section].sh_addr;
8925+ else {
8926+ printk(KERN_ERR "%s: invalid R_PPC_REL24 entry found\n", mod->name);
8927+ return ~0UL;
8928+ }
8929
8930 /* Find this entry, or if that fails, the next avail. entry */
8931 while (entry->jump[0]) {
8932@@ -296,7 +301,7 @@ int apply_relocate_add(Elf32_Shdr *sechdrs,
8933 }
8934 #ifdef CONFIG_DYNAMIC_FTRACE
8935 module->arch.tramp =
8936- do_plt_call(module->module_core,
8937+ do_plt_call(module->module_core_rx,
8938 (unsigned long)ftrace_caller,
8939 sechdrs, module);
8940 #endif
8941diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
8942index 923cd2d..ae782a9 100644
8943--- a/arch/powerpc/kernel/process.c
8944+++ b/arch/powerpc/kernel/process.c
8945@@ -1040,8 +1040,8 @@ void show_regs(struct pt_regs * regs)
8946 * Lookup NIP late so we have the best change of getting the
8947 * above info out without failing
8948 */
8949- printk("NIP ["REG"] %pS\n", regs->nip, (void *)regs->nip);
8950- printk("LR ["REG"] %pS\n", regs->link, (void *)regs->link);
8951+ printk("NIP ["REG"] %pA\n", regs->nip, (void *)regs->nip);
8952+ printk("LR ["REG"] %pA\n", regs->link, (void *)regs->link);
8953 #endif
8954 show_stack(current, (unsigned long *) regs->gpr[1]);
8955 if (!user_mode(regs))
8956@@ -1560,10 +1560,10 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
8957 newsp = stack[0];
8958 ip = stack[STACK_FRAME_LR_SAVE];
8959 if (!firstframe || ip != lr) {
8960- printk("["REG"] ["REG"] %pS", sp, ip, (void *)ip);
8961+ printk("["REG"] ["REG"] %pA", sp, ip, (void *)ip);
8962 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
8963 if ((ip == rth || ip == mrth) && curr_frame >= 0) {
8964- printk(" (%pS)",
8965+ printk(" (%pA)",
8966 (void *)current->ret_stack[curr_frame].ret);
8967 curr_frame--;
8968 }
8969@@ -1583,7 +1583,7 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
8970 struct pt_regs *regs = (struct pt_regs *)
8971 (sp + STACK_FRAME_OVERHEAD);
8972 lr = regs->link;
8973- printk("--- interrupt: %lx at %pS\n LR = %pS\n",
8974+ printk("--- interrupt: %lx at %pA\n LR = %pA\n",
8975 regs->trap, (void *)regs->nip, (void *)lr);
8976 firstframe = 1;
8977 }
8978@@ -1619,58 +1619,3 @@ void notrace __ppc64_runlatch_off(void)
8979 mtspr(SPRN_CTRLT, ctrl);
8980 }
8981 #endif /* CONFIG_PPC64 */
8982-
8983-unsigned long arch_align_stack(unsigned long sp)
8984-{
8985- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
8986- sp -= get_random_int() & ~PAGE_MASK;
8987- return sp & ~0xf;
8988-}
8989-
8990-static inline unsigned long brk_rnd(void)
8991-{
8992- unsigned long rnd = 0;
8993-
8994- /* 8MB for 32bit, 1GB for 64bit */
8995- if (is_32bit_task())
8996- rnd = (long)(get_random_int() % (1<<(23-PAGE_SHIFT)));
8997- else
8998- rnd = (long)(get_random_int() % (1<<(30-PAGE_SHIFT)));
8999-
9000- return rnd << PAGE_SHIFT;
9001-}
9002-
9003-unsigned long arch_randomize_brk(struct mm_struct *mm)
9004-{
9005- unsigned long base = mm->brk;
9006- unsigned long ret;
9007-
9008-#ifdef CONFIG_PPC_STD_MMU_64
9009- /*
9010- * If we are using 1TB segments and we are allowed to randomise
9011- * the heap, we can put it above 1TB so it is backed by a 1TB
9012- * segment. Otherwise the heap will be in the bottom 1TB
9013- * which always uses 256MB segments and this may result in a
9014- * performance penalty.
9015- */
9016- if (!is_32bit_task() && (mmu_highuser_ssize == MMU_SEGSIZE_1T))
9017- base = max_t(unsigned long, mm->brk, 1UL << SID_SHIFT_1T);
9018-#endif
9019-
9020- ret = PAGE_ALIGN(base + brk_rnd());
9021-
9022- if (ret < mm->brk)
9023- return mm->brk;
9024-
9025- return ret;
9026-}
9027-
9028-unsigned long randomize_et_dyn(unsigned long base)
9029-{
9030- unsigned long ret = PAGE_ALIGN(base + brk_rnd());
9031-
9032- if (ret < base)
9033- return base;
9034-
9035- return ret;
9036-}
9037diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c
9038index f21897b..28c0428 100644
9039--- a/arch/powerpc/kernel/ptrace.c
9040+++ b/arch/powerpc/kernel/ptrace.c
9041@@ -1762,6 +1762,10 @@ long arch_ptrace(struct task_struct *child, long request,
9042 return ret;
9043 }
9044
9045+#ifdef CONFIG_GRKERNSEC_SETXID
9046+extern void gr_delayed_cred_worker(void);
9047+#endif
9048+
9049 /*
9050 * We must return the syscall number to actually look up in the table.
9051 * This can be -1L to skip running any syscall at all.
9052@@ -1774,6 +1778,11 @@ long do_syscall_trace_enter(struct pt_regs *regs)
9053
9054 secure_computing_strict(regs->gpr[0]);
9055
9056+#ifdef CONFIG_GRKERNSEC_SETXID
9057+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
9058+ gr_delayed_cred_worker();
9059+#endif
9060+
9061 if (test_thread_flag(TIF_SYSCALL_TRACE) &&
9062 tracehook_report_syscall_entry(regs))
9063 /*
9064@@ -1805,6 +1814,11 @@ void do_syscall_trace_leave(struct pt_regs *regs)
9065 {
9066 int step;
9067
9068+#ifdef CONFIG_GRKERNSEC_SETXID
9069+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
9070+ gr_delayed_cred_worker();
9071+#endif
9072+
9073 audit_syscall_exit(regs);
9074
9075 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
9076diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c
9077index b171001..4ac7ac5 100644
9078--- a/arch/powerpc/kernel/signal_32.c
9079+++ b/arch/powerpc/kernel/signal_32.c
9080@@ -1011,7 +1011,7 @@ int handle_rt_signal32(struct ksignal *ksig, sigset_t *oldset,
9081 /* Save user registers on the stack */
9082 frame = &rt_sf->uc.uc_mcontext;
9083 addr = frame;
9084- if (vdso32_rt_sigtramp && current->mm->context.vdso_base) {
9085+ if (vdso32_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
9086 sigret = 0;
9087 tramp = current->mm->context.vdso_base + vdso32_rt_sigtramp;
9088 } else {
9089diff --git a/arch/powerpc/kernel/signal_64.c b/arch/powerpc/kernel/signal_64.c
9090index 2cb0c94..c0c0bc9 100644
9091--- a/arch/powerpc/kernel/signal_64.c
9092+++ b/arch/powerpc/kernel/signal_64.c
9093@@ -754,7 +754,7 @@ int handle_rt_signal64(struct ksignal *ksig, sigset_t *set, struct pt_regs *regs
9094 current->thread.fp_state.fpscr = 0;
9095
9096 /* Set up to return from userspace. */
9097- if (vdso64_rt_sigtramp && current->mm->context.vdso_base) {
9098+ if (vdso64_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
9099 regs->link = current->mm->context.vdso_base + vdso64_rt_sigtramp;
9100 } else {
9101 err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]);
9102diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
9103index 0dc43f9..a885d33 100644
9104--- a/arch/powerpc/kernel/traps.c
9105+++ b/arch/powerpc/kernel/traps.c
9106@@ -36,6 +36,7 @@
9107 #include <linux/debugfs.h>
9108 #include <linux/ratelimit.h>
9109 #include <linux/context_tracking.h>
9110+#include <linux/uaccess.h>
9111
9112 #include <asm/emulated_ops.h>
9113 #include <asm/pgtable.h>
9114@@ -142,6 +143,8 @@ static unsigned __kprobes long oops_begin(struct pt_regs *regs)
9115 return flags;
9116 }
9117
9118+extern void gr_handle_kernel_exploit(void);
9119+
9120 static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
9121 int signr)
9122 {
9123@@ -191,6 +194,9 @@ static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
9124 panic("Fatal exception in interrupt");
9125 if (panic_on_oops)
9126 panic("Fatal exception");
9127+
9128+ gr_handle_kernel_exploit();
9129+
9130 do_exit(signr);
9131 }
9132
9133@@ -1137,6 +1143,26 @@ void __kprobes program_check_exception(struct pt_regs *regs)
9134 enum ctx_state prev_state = exception_enter();
9135 unsigned int reason = get_reason(regs);
9136
9137+#ifdef CONFIG_PAX_REFCOUNT
9138+ unsigned int bkpt;
9139+ const struct exception_table_entry *entry;
9140+
9141+ if (reason & REASON_ILLEGAL) {
9142+ /* Check if PaX bad instruction */
9143+ if (!probe_kernel_address(regs->nip, bkpt) && bkpt == 0xc00b00) {
9144+ current->thread.trap_nr = 0;
9145+ pax_report_refcount_overflow(regs);
9146+ /* fixup_exception() for PowerPC does not exist, simulate its job */
9147+ if ((entry = search_exception_tables(regs->nip)) != NULL) {
9148+ regs->nip = entry->fixup;
9149+ return;
9150+ }
9151+ /* fixup_exception() could not handle */
9152+ goto bail;
9153+ }
9154+ }
9155+#endif
9156+
9157 /* We can now get here via a FP Unavailable exception if the core
9158 * has no FPU, in that case the reason flags will be 0 */
9159
9160diff --git a/arch/powerpc/kernel/vdso.c b/arch/powerpc/kernel/vdso.c
9161index f174351..5722009 100644
9162--- a/arch/powerpc/kernel/vdso.c
9163+++ b/arch/powerpc/kernel/vdso.c
9164@@ -35,6 +35,7 @@
9165 #include <asm/vdso.h>
9166 #include <asm/vdso_datapage.h>
9167 #include <asm/setup.h>
9168+#include <asm/mman.h>
9169
9170 #undef DEBUG
9171
9172@@ -221,7 +222,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
9173 vdso_base = VDSO32_MBASE;
9174 #endif
9175
9176- current->mm->context.vdso_base = 0;
9177+ current->mm->context.vdso_base = ~0UL;
9178
9179 /* vDSO has a problem and was disabled, just don't "enable" it for the
9180 * process
9181@@ -241,7 +242,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
9182 vdso_base = get_unmapped_area(NULL, vdso_base,
9183 (vdso_pages << PAGE_SHIFT) +
9184 ((VDSO_ALIGNMENT - 1) & PAGE_MASK),
9185- 0, 0);
9186+ 0, MAP_PRIVATE | MAP_EXECUTABLE);
9187 if (IS_ERR_VALUE(vdso_base)) {
9188 rc = vdso_base;
9189 goto fail_mmapsem;
9190diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c
9191index c1f8f53..71a3b96 100644
9192--- a/arch/powerpc/kvm/powerpc.c
9193+++ b/arch/powerpc/kvm/powerpc.c
9194@@ -1409,7 +1409,7 @@ void kvmppc_init_lpid(unsigned long nr_lpids_param)
9195 }
9196 EXPORT_SYMBOL_GPL(kvmppc_init_lpid);
9197
9198-int kvm_arch_init(void *opaque)
9199+int kvm_arch_init(const void *opaque)
9200 {
9201 return 0;
9202 }
9203diff --git a/arch/powerpc/lib/usercopy_64.c b/arch/powerpc/lib/usercopy_64.c
9204index 5eea6f3..5d10396 100644
9205--- a/arch/powerpc/lib/usercopy_64.c
9206+++ b/arch/powerpc/lib/usercopy_64.c
9207@@ -9,22 +9,6 @@
9208 #include <linux/module.h>
9209 #include <asm/uaccess.h>
9210
9211-unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
9212-{
9213- if (likely(access_ok(VERIFY_READ, from, n)))
9214- n = __copy_from_user(to, from, n);
9215- else
9216- memset(to, 0, n);
9217- return n;
9218-}
9219-
9220-unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
9221-{
9222- if (likely(access_ok(VERIFY_WRITE, to, n)))
9223- n = __copy_to_user(to, from, n);
9224- return n;
9225-}
9226-
9227 unsigned long copy_in_user(void __user *to, const void __user *from,
9228 unsigned long n)
9229 {
9230@@ -35,7 +19,5 @@ unsigned long copy_in_user(void __user *to, const void __user *from,
9231 return n;
9232 }
9233
9234-EXPORT_SYMBOL(copy_from_user);
9235-EXPORT_SYMBOL(copy_to_user);
9236 EXPORT_SYMBOL(copy_in_user);
9237
9238diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
9239index 08d659a..ab329f4 100644
9240--- a/arch/powerpc/mm/fault.c
9241+++ b/arch/powerpc/mm/fault.c
9242@@ -33,6 +33,10 @@
9243 #include <linux/ratelimit.h>
9244 #include <linux/context_tracking.h>
9245 #include <linux/hugetlb.h>
9246+#include <linux/slab.h>
9247+#include <linux/pagemap.h>
9248+#include <linux/compiler.h>
9249+#include <linux/unistd.h>
9250
9251 #include <asm/firmware.h>
9252 #include <asm/page.h>
9253@@ -69,6 +73,33 @@ static inline int notify_page_fault(struct pt_regs *regs)
9254 }
9255 #endif
9256
9257+#ifdef CONFIG_PAX_PAGEEXEC
9258+/*
9259+ * PaX: decide what to do with offenders (regs->nip = fault address)
9260+ *
9261+ * returns 1 when task should be killed
9262+ */
9263+static int pax_handle_fetch_fault(struct pt_regs *regs)
9264+{
9265+ return 1;
9266+}
9267+
9268+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
9269+{
9270+ unsigned long i;
9271+
9272+ printk(KERN_ERR "PAX: bytes at PC: ");
9273+ for (i = 0; i < 5; i++) {
9274+ unsigned int c;
9275+ if (get_user(c, (unsigned int __user *)pc+i))
9276+ printk(KERN_CONT "???????? ");
9277+ else
9278+ printk(KERN_CONT "%08x ", c);
9279+ }
9280+ printk("\n");
9281+}
9282+#endif
9283+
9284 /*
9285 * Check whether the instruction at regs->nip is a store using
9286 * an update addressing form which will update r1.
9287@@ -228,7 +259,7 @@ int __kprobes do_page_fault(struct pt_regs *regs, unsigned long address,
9288 * indicate errors in DSISR but can validly be set in SRR1.
9289 */
9290 if (trap == 0x400)
9291- error_code &= 0x48200000;
9292+ error_code &= 0x58200000;
9293 else
9294 is_write = error_code & DSISR_ISSTORE;
9295 #else
9296@@ -390,7 +421,7 @@ good_area:
9297 * "undefined". Of those that can be set, this is the only
9298 * one which seems bad.
9299 */
9300- if (error_code & 0x10000000)
9301+ if (error_code & DSISR_GUARDED)
9302 /* Guarded storage error. */
9303 goto bad_area;
9304 #endif /* CONFIG_8xx */
9305@@ -405,7 +436,7 @@ good_area:
9306 * processors use the same I/D cache coherency mechanism
9307 * as embedded.
9308 */
9309- if (error_code & DSISR_PROTFAULT)
9310+ if (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))
9311 goto bad_area;
9312 #endif /* CONFIG_PPC_STD_MMU */
9313
9314@@ -495,6 +526,23 @@ bad_area:
9315 bad_area_nosemaphore:
9316 /* User mode accesses cause a SIGSEGV */
9317 if (user_mode(regs)) {
9318+
9319+#ifdef CONFIG_PAX_PAGEEXEC
9320+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
9321+#ifdef CONFIG_PPC_STD_MMU
9322+ if (is_exec && (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))) {
9323+#else
9324+ if (is_exec && regs->nip == address) {
9325+#endif
9326+ switch (pax_handle_fetch_fault(regs)) {
9327+ }
9328+
9329+ pax_report_fault(regs, (void *)regs->nip, (void *)regs->gpr[PT_R1]);
9330+ do_group_exit(SIGKILL);
9331+ }
9332+ }
9333+#endif
9334+
9335 _exception(SIGSEGV, regs, code, address);
9336 goto bail;
9337 }
9338diff --git a/arch/powerpc/mm/mmap.c b/arch/powerpc/mm/mmap.c
9339index cb8bdbe..cde4bc7 100644
9340--- a/arch/powerpc/mm/mmap.c
9341+++ b/arch/powerpc/mm/mmap.c
9342@@ -53,10 +53,14 @@ static inline int mmap_is_legacy(void)
9343 return sysctl_legacy_va_layout;
9344 }
9345
9346-static unsigned long mmap_rnd(void)
9347+static unsigned long mmap_rnd(struct mm_struct *mm)
9348 {
9349 unsigned long rnd = 0;
9350
9351+#ifdef CONFIG_PAX_RANDMMAP
9352+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9353+#endif
9354+
9355 if (current->flags & PF_RANDOMIZE) {
9356 /* 8MB for 32bit, 1GB for 64bit */
9357 if (is_32bit_task())
9358@@ -67,7 +71,7 @@ static unsigned long mmap_rnd(void)
9359 return rnd << PAGE_SHIFT;
9360 }
9361
9362-static inline unsigned long mmap_base(void)
9363+static inline unsigned long mmap_base(struct mm_struct *mm)
9364 {
9365 unsigned long gap = rlimit(RLIMIT_STACK);
9366
9367@@ -76,7 +80,7 @@ static inline unsigned long mmap_base(void)
9368 else if (gap > MAX_GAP)
9369 gap = MAX_GAP;
9370
9371- return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
9372+ return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd(mm));
9373 }
9374
9375 /*
9376@@ -91,9 +95,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
9377 */
9378 if (mmap_is_legacy()) {
9379 mm->mmap_base = TASK_UNMAPPED_BASE;
9380+
9381+#ifdef CONFIG_PAX_RANDMMAP
9382+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9383+ mm->mmap_base += mm->delta_mmap;
9384+#endif
9385+
9386 mm->get_unmapped_area = arch_get_unmapped_area;
9387 } else {
9388- mm->mmap_base = mmap_base();
9389+ mm->mmap_base = mmap_base(mm);
9390+
9391+#ifdef CONFIG_PAX_RANDMMAP
9392+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9393+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
9394+#endif
9395+
9396 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
9397 }
9398 }
9399diff --git a/arch/powerpc/mm/slice.c b/arch/powerpc/mm/slice.c
9400index ded0ea1..f213a9b 100644
9401--- a/arch/powerpc/mm/slice.c
9402+++ b/arch/powerpc/mm/slice.c
9403@@ -105,7 +105,7 @@ static int slice_area_is_free(struct mm_struct *mm, unsigned long addr,
9404 if ((mm->task_size - len) < addr)
9405 return 0;
9406 vma = find_vma(mm, addr);
9407- return (!vma || (addr + len) <= vma->vm_start);
9408+ return check_heap_stack_gap(vma, addr, len, 0);
9409 }
9410
9411 static int slice_low_has_vma(struct mm_struct *mm, unsigned long slice)
9412@@ -277,6 +277,12 @@ static unsigned long slice_find_area_bottomup(struct mm_struct *mm,
9413 info.align_offset = 0;
9414
9415 addr = TASK_UNMAPPED_BASE;
9416+
9417+#ifdef CONFIG_PAX_RANDMMAP
9418+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9419+ addr += mm->delta_mmap;
9420+#endif
9421+
9422 while (addr < TASK_SIZE) {
9423 info.low_limit = addr;
9424 if (!slice_scan_available(addr, available, 1, &addr))
9425@@ -410,6 +416,11 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len,
9426 if (fixed && addr > (mm->task_size - len))
9427 return -ENOMEM;
9428
9429+#ifdef CONFIG_PAX_RANDMMAP
9430+ if (!fixed && (mm->pax_flags & MF_PAX_RANDMMAP))
9431+ addr = 0;
9432+#endif
9433+
9434 /* If hint, make sure it matches our alignment restrictions */
9435 if (!fixed && addr) {
9436 addr = _ALIGN_UP(addr, 1ul << pshift);
9437diff --git a/arch/powerpc/platforms/cell/celleb_scc_pciex.c b/arch/powerpc/platforms/cell/celleb_scc_pciex.c
9438index 4278acf..67fd0e6 100644
9439--- a/arch/powerpc/platforms/cell/celleb_scc_pciex.c
9440+++ b/arch/powerpc/platforms/cell/celleb_scc_pciex.c
9441@@ -400,8 +400,8 @@ static int scc_pciex_write_config(struct pci_bus *bus, unsigned int devfn,
9442 }
9443
9444 static struct pci_ops scc_pciex_pci_ops = {
9445- scc_pciex_read_config,
9446- scc_pciex_write_config,
9447+ .read = scc_pciex_read_config,
9448+ .write = scc_pciex_write_config,
9449 };
9450
9451 static void pciex_clear_intr_all(unsigned int __iomem *base)
9452diff --git a/arch/powerpc/platforms/cell/spufs/file.c b/arch/powerpc/platforms/cell/spufs/file.c
9453index d966bbe..372124a 100644
9454--- a/arch/powerpc/platforms/cell/spufs/file.c
9455+++ b/arch/powerpc/platforms/cell/spufs/file.c
9456@@ -280,9 +280,9 @@ spufs_mem_mmap_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
9457 return VM_FAULT_NOPAGE;
9458 }
9459
9460-static int spufs_mem_mmap_access(struct vm_area_struct *vma,
9461+static ssize_t spufs_mem_mmap_access(struct vm_area_struct *vma,
9462 unsigned long address,
9463- void *buf, int len, int write)
9464+ void *buf, size_t len, int write)
9465 {
9466 struct spu_context *ctx = vma->vm_file->private_data;
9467 unsigned long offset = address - vma->vm_start;
9468diff --git a/arch/s390/include/asm/atomic.h b/arch/s390/include/asm/atomic.h
9469index fa934fe..c296056 100644
9470--- a/arch/s390/include/asm/atomic.h
9471+++ b/arch/s390/include/asm/atomic.h
9472@@ -412,4 +412,14 @@ static inline long long atomic64_dec_if_positive(atomic64_t *v)
9473 #define atomic64_dec_and_test(_v) (atomic64_sub_return(1, _v) == 0)
9474 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
9475
9476+#define atomic64_read_unchecked(v) atomic64_read(v)
9477+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
9478+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
9479+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
9480+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
9481+#define atomic64_inc_unchecked(v) atomic64_inc(v)
9482+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
9483+#define atomic64_dec_unchecked(v) atomic64_dec(v)
9484+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
9485+
9486 #endif /* __ARCH_S390_ATOMIC__ */
9487diff --git a/arch/s390/include/asm/barrier.h b/arch/s390/include/asm/barrier.h
9488index b5dce65..8aca09a 100644
9489--- a/arch/s390/include/asm/barrier.h
9490+++ b/arch/s390/include/asm/barrier.h
9491@@ -39,7 +39,7 @@
9492 do { \
9493 compiletime_assert_atomic_type(*p); \
9494 barrier(); \
9495- ACCESS_ONCE(*p) = (v); \
9496+ ACCESS_ONCE_RW(*p) = (v); \
9497 } while (0)
9498
9499 #define smp_load_acquire(p) \
9500diff --git a/arch/s390/include/asm/cache.h b/arch/s390/include/asm/cache.h
9501index 4d7ccac..d03d0ad 100644
9502--- a/arch/s390/include/asm/cache.h
9503+++ b/arch/s390/include/asm/cache.h
9504@@ -9,8 +9,10 @@
9505 #ifndef __ARCH_S390_CACHE_H
9506 #define __ARCH_S390_CACHE_H
9507
9508-#define L1_CACHE_BYTES 256
9509+#include <linux/const.h>
9510+
9511 #define L1_CACHE_SHIFT 8
9512+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9513 #define NET_SKB_PAD 32
9514
9515 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
9516diff --git a/arch/s390/include/asm/elf.h b/arch/s390/include/asm/elf.h
9517index f6e43d3..5f57681 100644
9518--- a/arch/s390/include/asm/elf.h
9519+++ b/arch/s390/include/asm/elf.h
9520@@ -163,8 +163,14 @@ extern unsigned int vdso_enabled;
9521 the loader. We need to make sure that it is out of the way of the program
9522 that it will "exec", and that there is sufficient room for the brk. */
9523
9524-extern unsigned long randomize_et_dyn(unsigned long base);
9525-#define ELF_ET_DYN_BASE (randomize_et_dyn(STACK_TOP / 3 * 2))
9526+#define ELF_ET_DYN_BASE (STACK_TOP / 3 * 2)
9527+
9528+#ifdef CONFIG_PAX_ASLR
9529+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_31BIT) ? 0x10000UL : 0x80000000UL)
9530+
9531+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
9532+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
9533+#endif
9534
9535 /* This yields a mask that user programs can use to figure out what
9536 instruction set this CPU supports. */
9537@@ -223,9 +229,6 @@ struct linux_binprm;
9538 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
9539 int arch_setup_additional_pages(struct linux_binprm *, int);
9540
9541-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
9542-#define arch_randomize_brk arch_randomize_brk
9543-
9544 void *fill_cpu_elf_notes(void *ptr, struct save_area *sa, __vector128 *vxrs);
9545
9546 #endif
9547diff --git a/arch/s390/include/asm/exec.h b/arch/s390/include/asm/exec.h
9548index c4a93d6..4d2a9b4 100644
9549--- a/arch/s390/include/asm/exec.h
9550+++ b/arch/s390/include/asm/exec.h
9551@@ -7,6 +7,6 @@
9552 #ifndef __ASM_EXEC_H
9553 #define __ASM_EXEC_H
9554
9555-extern unsigned long arch_align_stack(unsigned long sp);
9556+#define arch_align_stack(x) ((x) & ~0xfUL)
9557
9558 #endif /* __ASM_EXEC_H */
9559diff --git a/arch/s390/include/asm/uaccess.h b/arch/s390/include/asm/uaccess.h
9560index cd4c68e..6764641 100644
9561--- a/arch/s390/include/asm/uaccess.h
9562+++ b/arch/s390/include/asm/uaccess.h
9563@@ -59,6 +59,7 @@ static inline int __range_ok(unsigned long addr, unsigned long size)
9564 __range_ok((unsigned long)(addr), (size)); \
9565 })
9566
9567+#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
9568 #define access_ok(type, addr, size) __access_ok(addr, size)
9569
9570 /*
9571@@ -275,6 +276,10 @@ static inline unsigned long __must_check
9572 copy_to_user(void __user *to, const void *from, unsigned long n)
9573 {
9574 might_fault();
9575+
9576+ if ((long)n < 0)
9577+ return n;
9578+
9579 return __copy_to_user(to, from, n);
9580 }
9581
9582@@ -303,10 +308,14 @@ __compiletime_warning("copy_from_user() buffer size is not provably correct")
9583 static inline unsigned long __must_check
9584 copy_from_user(void *to, const void __user *from, unsigned long n)
9585 {
9586- unsigned int sz = __compiletime_object_size(to);
9587+ size_t sz = __compiletime_object_size(to);
9588
9589 might_fault();
9590- if (unlikely(sz != -1 && sz < n)) {
9591+
9592+ if ((long)n < 0)
9593+ return n;
9594+
9595+ if (unlikely(sz != (size_t)-1 && sz < n)) {
9596 copy_from_user_overflow();
9597 return n;
9598 }
9599diff --git a/arch/s390/kernel/module.c b/arch/s390/kernel/module.c
9600index b89b591..fd9609d 100644
9601--- a/arch/s390/kernel/module.c
9602+++ b/arch/s390/kernel/module.c
9603@@ -169,11 +169,11 @@ int module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
9604
9605 /* Increase core size by size of got & plt and set start
9606 offsets for got and plt. */
9607- me->core_size = ALIGN(me->core_size, 4);
9608- me->arch.got_offset = me->core_size;
9609- me->core_size += me->arch.got_size;
9610- me->arch.plt_offset = me->core_size;
9611- me->core_size += me->arch.plt_size;
9612+ me->core_size_rw = ALIGN(me->core_size_rw, 4);
9613+ me->arch.got_offset = me->core_size_rw;
9614+ me->core_size_rw += me->arch.got_size;
9615+ me->arch.plt_offset = me->core_size_rx;
9616+ me->core_size_rx += me->arch.plt_size;
9617 return 0;
9618 }
9619
9620@@ -289,7 +289,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9621 if (info->got_initialized == 0) {
9622 Elf_Addr *gotent;
9623
9624- gotent = me->module_core + me->arch.got_offset +
9625+ gotent = me->module_core_rw + me->arch.got_offset +
9626 info->got_offset;
9627 *gotent = val;
9628 info->got_initialized = 1;
9629@@ -312,7 +312,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9630 rc = apply_rela_bits(loc, val, 0, 64, 0);
9631 else if (r_type == R_390_GOTENT ||
9632 r_type == R_390_GOTPLTENT) {
9633- val += (Elf_Addr) me->module_core - loc;
9634+ val += (Elf_Addr) me->module_core_rw - loc;
9635 rc = apply_rela_bits(loc, val, 1, 32, 1);
9636 }
9637 break;
9638@@ -325,7 +325,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9639 case R_390_PLTOFF64: /* 16 bit offset from GOT to PLT. */
9640 if (info->plt_initialized == 0) {
9641 unsigned int *ip;
9642- ip = me->module_core + me->arch.plt_offset +
9643+ ip = me->module_core_rx + me->arch.plt_offset +
9644 info->plt_offset;
9645 #ifndef CONFIG_64BIT
9646 ip[0] = 0x0d105810; /* basr 1,0; l 1,6(1); br 1 */
9647@@ -350,7 +350,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9648 val - loc + 0xffffUL < 0x1ffffeUL) ||
9649 (r_type == R_390_PLT32DBL &&
9650 val - loc + 0xffffffffULL < 0x1fffffffeULL)))
9651- val = (Elf_Addr) me->module_core +
9652+ val = (Elf_Addr) me->module_core_rx +
9653 me->arch.plt_offset +
9654 info->plt_offset;
9655 val += rela->r_addend - loc;
9656@@ -372,7 +372,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9657 case R_390_GOTOFF32: /* 32 bit offset to GOT. */
9658 case R_390_GOTOFF64: /* 64 bit offset to GOT. */
9659 val = val + rela->r_addend -
9660- ((Elf_Addr) me->module_core + me->arch.got_offset);
9661+ ((Elf_Addr) me->module_core_rw + me->arch.got_offset);
9662 if (r_type == R_390_GOTOFF16)
9663 rc = apply_rela_bits(loc, val, 0, 16, 0);
9664 else if (r_type == R_390_GOTOFF32)
9665@@ -382,7 +382,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9666 break;
9667 case R_390_GOTPC: /* 32 bit PC relative offset to GOT. */
9668 case R_390_GOTPCDBL: /* 32 bit PC rel. off. to GOT shifted by 1. */
9669- val = (Elf_Addr) me->module_core + me->arch.got_offset +
9670+ val = (Elf_Addr) me->module_core_rw + me->arch.got_offset +
9671 rela->r_addend - loc;
9672 if (r_type == R_390_GOTPC)
9673 rc = apply_rela_bits(loc, val, 1, 32, 0);
9674diff --git a/arch/s390/kernel/process.c b/arch/s390/kernel/process.c
9675index ed84cc2..c05a9d2 100644
9676--- a/arch/s390/kernel/process.c
9677+++ b/arch/s390/kernel/process.c
9678@@ -218,37 +218,3 @@ unsigned long get_wchan(struct task_struct *p)
9679 }
9680 return 0;
9681 }
9682-
9683-unsigned long arch_align_stack(unsigned long sp)
9684-{
9685- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
9686- sp -= get_random_int() & ~PAGE_MASK;
9687- return sp & ~0xf;
9688-}
9689-
9690-static inline unsigned long brk_rnd(void)
9691-{
9692- /* 8MB for 32bit, 1GB for 64bit */
9693- if (is_32bit_task())
9694- return (get_random_int() & 0x7ffUL) << PAGE_SHIFT;
9695- else
9696- return (get_random_int() & 0x3ffffUL) << PAGE_SHIFT;
9697-}
9698-
9699-unsigned long arch_randomize_brk(struct mm_struct *mm)
9700-{
9701- unsigned long ret;
9702-
9703- ret = PAGE_ALIGN(mm->brk + brk_rnd());
9704- return (ret > mm->brk) ? ret : mm->brk;
9705-}
9706-
9707-unsigned long randomize_et_dyn(unsigned long base)
9708-{
9709- unsigned long ret;
9710-
9711- if (!(current->flags & PF_RANDOMIZE))
9712- return base;
9713- ret = PAGE_ALIGN(base + brk_rnd());
9714- return (ret > base) ? ret : base;
9715-}
9716diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c
9717index 9b436c2..54fbf0a 100644
9718--- a/arch/s390/mm/mmap.c
9719+++ b/arch/s390/mm/mmap.c
9720@@ -95,9 +95,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
9721 */
9722 if (mmap_is_legacy()) {
9723 mm->mmap_base = mmap_base_legacy();
9724+
9725+#ifdef CONFIG_PAX_RANDMMAP
9726+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9727+ mm->mmap_base += mm->delta_mmap;
9728+#endif
9729+
9730 mm->get_unmapped_area = arch_get_unmapped_area;
9731 } else {
9732 mm->mmap_base = mmap_base();
9733+
9734+#ifdef CONFIG_PAX_RANDMMAP
9735+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9736+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
9737+#endif
9738+
9739 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
9740 }
9741 }
9742@@ -170,9 +182,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
9743 */
9744 if (mmap_is_legacy()) {
9745 mm->mmap_base = mmap_base_legacy();
9746+
9747+#ifdef CONFIG_PAX_RANDMMAP
9748+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9749+ mm->mmap_base += mm->delta_mmap;
9750+#endif
9751+
9752 mm->get_unmapped_area = s390_get_unmapped_area;
9753 } else {
9754 mm->mmap_base = mmap_base();
9755+
9756+#ifdef CONFIG_PAX_RANDMMAP
9757+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9758+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
9759+#endif
9760+
9761 mm->get_unmapped_area = s390_get_unmapped_area_topdown;
9762 }
9763 }
9764diff --git a/arch/score/include/asm/cache.h b/arch/score/include/asm/cache.h
9765index ae3d59f..f65f075 100644
9766--- a/arch/score/include/asm/cache.h
9767+++ b/arch/score/include/asm/cache.h
9768@@ -1,7 +1,9 @@
9769 #ifndef _ASM_SCORE_CACHE_H
9770 #define _ASM_SCORE_CACHE_H
9771
9772+#include <linux/const.h>
9773+
9774 #define L1_CACHE_SHIFT 4
9775-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
9776+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9777
9778 #endif /* _ASM_SCORE_CACHE_H */
9779diff --git a/arch/score/include/asm/exec.h b/arch/score/include/asm/exec.h
9780index f9f3cd5..58ff438 100644
9781--- a/arch/score/include/asm/exec.h
9782+++ b/arch/score/include/asm/exec.h
9783@@ -1,6 +1,6 @@
9784 #ifndef _ASM_SCORE_EXEC_H
9785 #define _ASM_SCORE_EXEC_H
9786
9787-extern unsigned long arch_align_stack(unsigned long sp);
9788+#define arch_align_stack(x) (x)
9789
9790 #endif /* _ASM_SCORE_EXEC_H */
9791diff --git a/arch/score/kernel/process.c b/arch/score/kernel/process.c
9792index a1519ad3..e8ac1ff 100644
9793--- a/arch/score/kernel/process.c
9794+++ b/arch/score/kernel/process.c
9795@@ -116,8 +116,3 @@ unsigned long get_wchan(struct task_struct *task)
9796
9797 return task_pt_regs(task)->cp0_epc;
9798 }
9799-
9800-unsigned long arch_align_stack(unsigned long sp)
9801-{
9802- return sp;
9803-}
9804diff --git a/arch/sh/include/asm/cache.h b/arch/sh/include/asm/cache.h
9805index ef9e555..331bd29 100644
9806--- a/arch/sh/include/asm/cache.h
9807+++ b/arch/sh/include/asm/cache.h
9808@@ -9,10 +9,11 @@
9809 #define __ASM_SH_CACHE_H
9810 #ifdef __KERNEL__
9811
9812+#include <linux/const.h>
9813 #include <linux/init.h>
9814 #include <cpu/cache.h>
9815
9816-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
9817+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9818
9819 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
9820
9821diff --git a/arch/sh/mm/mmap.c b/arch/sh/mm/mmap.c
9822index 6777177..cb5e44f 100644
9823--- a/arch/sh/mm/mmap.c
9824+++ b/arch/sh/mm/mmap.c
9825@@ -36,6 +36,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
9826 struct mm_struct *mm = current->mm;
9827 struct vm_area_struct *vma;
9828 int do_colour_align;
9829+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
9830 struct vm_unmapped_area_info info;
9831
9832 if (flags & MAP_FIXED) {
9833@@ -55,6 +56,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
9834 if (filp || (flags & MAP_SHARED))
9835 do_colour_align = 1;
9836
9837+#ifdef CONFIG_PAX_RANDMMAP
9838+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9839+#endif
9840+
9841 if (addr) {
9842 if (do_colour_align)
9843 addr = COLOUR_ALIGN(addr, pgoff);
9844@@ -62,14 +67,13 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
9845 addr = PAGE_ALIGN(addr);
9846
9847 vma = find_vma(mm, addr);
9848- if (TASK_SIZE - len >= addr &&
9849- (!vma || addr + len <= vma->vm_start))
9850+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
9851 return addr;
9852 }
9853
9854 info.flags = 0;
9855 info.length = len;
9856- info.low_limit = TASK_UNMAPPED_BASE;
9857+ info.low_limit = mm->mmap_base;
9858 info.high_limit = TASK_SIZE;
9859 info.align_mask = do_colour_align ? (PAGE_MASK & shm_align_mask) : 0;
9860 info.align_offset = pgoff << PAGE_SHIFT;
9861@@ -85,6 +89,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9862 struct mm_struct *mm = current->mm;
9863 unsigned long addr = addr0;
9864 int do_colour_align;
9865+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
9866 struct vm_unmapped_area_info info;
9867
9868 if (flags & MAP_FIXED) {
9869@@ -104,6 +109,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9870 if (filp || (flags & MAP_SHARED))
9871 do_colour_align = 1;
9872
9873+#ifdef CONFIG_PAX_RANDMMAP
9874+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9875+#endif
9876+
9877 /* requesting a specific address */
9878 if (addr) {
9879 if (do_colour_align)
9880@@ -112,8 +121,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9881 addr = PAGE_ALIGN(addr);
9882
9883 vma = find_vma(mm, addr);
9884- if (TASK_SIZE - len >= addr &&
9885- (!vma || addr + len <= vma->vm_start))
9886+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
9887 return addr;
9888 }
9889
9890@@ -135,6 +143,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9891 VM_BUG_ON(addr != -ENOMEM);
9892 info.flags = 0;
9893 info.low_limit = TASK_UNMAPPED_BASE;
9894+
9895+#ifdef CONFIG_PAX_RANDMMAP
9896+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9897+ info.low_limit += mm->delta_mmap;
9898+#endif
9899+
9900 info.high_limit = TASK_SIZE;
9901 addr = vm_unmapped_area(&info);
9902 }
9903diff --git a/arch/sparc/include/asm/atomic_64.h b/arch/sparc/include/asm/atomic_64.h
9904index 4082749..fd97781 100644
9905--- a/arch/sparc/include/asm/atomic_64.h
9906+++ b/arch/sparc/include/asm/atomic_64.h
9907@@ -15,18 +15,38 @@
9908 #define ATOMIC64_INIT(i) { (i) }
9909
9910 #define atomic_read(v) ACCESS_ONCE((v)->counter)
9911+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
9912+{
9913+ return ACCESS_ONCE(v->counter);
9914+}
9915 #define atomic64_read(v) ACCESS_ONCE((v)->counter)
9916+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
9917+{
9918+ return ACCESS_ONCE(v->counter);
9919+}
9920
9921 #define atomic_set(v, i) (((v)->counter) = i)
9922+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
9923+{
9924+ v->counter = i;
9925+}
9926 #define atomic64_set(v, i) (((v)->counter) = i)
9927+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
9928+{
9929+ v->counter = i;
9930+}
9931
9932-#define ATOMIC_OP(op) \
9933-void atomic_##op(int, atomic_t *); \
9934-void atomic64_##op(long, atomic64_t *);
9935+#define __ATOMIC_OP(op, suffix) \
9936+void atomic_##op##suffix(int, atomic##suffix##_t *); \
9937+void atomic64_##op##suffix(long, atomic64##suffix##_t *);
9938
9939-#define ATOMIC_OP_RETURN(op) \
9940-int atomic_##op##_return(int, atomic_t *); \
9941-long atomic64_##op##_return(long, atomic64_t *);
9942+#define ATOMIC_OP(op) __ATOMIC_OP(op, ) __ATOMIC_OP(op, _unchecked)
9943+
9944+#define __ATOMIC_OP_RETURN(op, suffix) \
9945+int atomic_##op##_return##suffix(int, atomic##suffix##_t *); \
9946+long atomic64_##op##_return##suffix(long, atomic64##suffix##_t *);
9947+
9948+#define ATOMIC_OP_RETURN(op) __ATOMIC_OP_RETURN(op, ) __ATOMIC_OP_RETURN(op, _unchecked)
9949
9950 #define ATOMIC_OPS(op) ATOMIC_OP(op) ATOMIC_OP_RETURN(op)
9951
9952@@ -35,13 +55,23 @@ ATOMIC_OPS(sub)
9953
9954 #undef ATOMIC_OPS
9955 #undef ATOMIC_OP_RETURN
9956+#undef __ATOMIC_OP_RETURN
9957 #undef ATOMIC_OP
9958+#undef __ATOMIC_OP
9959
9960 #define atomic_dec_return(v) atomic_sub_return(1, v)
9961 #define atomic64_dec_return(v) atomic64_sub_return(1, v)
9962
9963 #define atomic_inc_return(v) atomic_add_return(1, v)
9964+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
9965+{
9966+ return atomic_add_return_unchecked(1, v);
9967+}
9968 #define atomic64_inc_return(v) atomic64_add_return(1, v)
9969+static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
9970+{
9971+ return atomic64_add_return_unchecked(1, v);
9972+}
9973
9974 /*
9975 * atomic_inc_and_test - increment and test
9976@@ -52,6 +82,10 @@ ATOMIC_OPS(sub)
9977 * other cases.
9978 */
9979 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
9980+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
9981+{
9982+ return atomic_inc_return_unchecked(v) == 0;
9983+}
9984 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
9985
9986 #define atomic_sub_and_test(i, v) (atomic_sub_return(i, v) == 0)
9987@@ -61,25 +95,60 @@ ATOMIC_OPS(sub)
9988 #define atomic64_dec_and_test(v) (atomic64_sub_return(1, v) == 0)
9989
9990 #define atomic_inc(v) atomic_add(1, v)
9991+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
9992+{
9993+ atomic_add_unchecked(1, v);
9994+}
9995 #define atomic64_inc(v) atomic64_add(1, v)
9996+static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
9997+{
9998+ atomic64_add_unchecked(1, v);
9999+}
10000
10001 #define atomic_dec(v) atomic_sub(1, v)
10002+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
10003+{
10004+ atomic_sub_unchecked(1, v);
10005+}
10006 #define atomic64_dec(v) atomic64_sub(1, v)
10007+static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
10008+{
10009+ atomic64_sub_unchecked(1, v);
10010+}
10011
10012 #define atomic_add_negative(i, v) (atomic_add_return(i, v) < 0)
10013 #define atomic64_add_negative(i, v) (atomic64_add_return(i, v) < 0)
10014
10015 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
10016+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
10017+{
10018+ return cmpxchg(&v->counter, old, new);
10019+}
10020 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
10021+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
10022+{
10023+ return xchg(&v->counter, new);
10024+}
10025
10026 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
10027 {
10028- int c, old;
10029+ int c, old, new;
10030 c = atomic_read(v);
10031 for (;;) {
10032- if (unlikely(c == (u)))
10033+ if (unlikely(c == u))
10034 break;
10035- old = atomic_cmpxchg((v), c, c + (a));
10036+
10037+ asm volatile("addcc %2, %0, %0\n"
10038+
10039+#ifdef CONFIG_PAX_REFCOUNT
10040+ "tvs %%icc, 6\n"
10041+#endif
10042+
10043+ : "=r" (new)
10044+ : "0" (c), "ir" (a)
10045+ : "cc");
10046+
10047+ old = atomic_cmpxchg(v, c, new);
10048 if (likely(old == c))
10049 break;
10050 c = old;
10051@@ -90,20 +159,35 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
10052 #define atomic64_cmpxchg(v, o, n) \
10053 ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
10054 #define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
10055+static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
10056+{
10057+ return xchg(&v->counter, new);
10058+}
10059
10060 static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
10061 {
10062- long c, old;
10063+ long c, old, new;
10064 c = atomic64_read(v);
10065 for (;;) {
10066- if (unlikely(c == (u)))
10067+ if (unlikely(c == u))
10068 break;
10069- old = atomic64_cmpxchg((v), c, c + (a));
10070+
10071+ asm volatile("addcc %2, %0, %0\n"
10072+
10073+#ifdef CONFIG_PAX_REFCOUNT
10074+ "tvs %%xcc, 6\n"
10075+#endif
10076+
10077+ : "=r" (new)
10078+ : "0" (c), "ir" (a)
10079+ : "cc");
10080+
10081+ old = atomic64_cmpxchg(v, c, new);
10082 if (likely(old == c))
10083 break;
10084 c = old;
10085 }
10086- return c != (u);
10087+ return c != u;
10088 }
10089
10090 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
10091diff --git a/arch/sparc/include/asm/barrier_64.h b/arch/sparc/include/asm/barrier_64.h
10092index 305dcc3..7835030 100644
10093--- a/arch/sparc/include/asm/barrier_64.h
10094+++ b/arch/sparc/include/asm/barrier_64.h
10095@@ -57,7 +57,7 @@ do { __asm__ __volatile__("ba,pt %%xcc, 1f\n\t" \
10096 do { \
10097 compiletime_assert_atomic_type(*p); \
10098 barrier(); \
10099- ACCESS_ONCE(*p) = (v); \
10100+ ACCESS_ONCE_RW(*p) = (v); \
10101 } while (0)
10102
10103 #define smp_load_acquire(p) \
10104diff --git a/arch/sparc/include/asm/cache.h b/arch/sparc/include/asm/cache.h
10105index 5bb6991..5c2132e 100644
10106--- a/arch/sparc/include/asm/cache.h
10107+++ b/arch/sparc/include/asm/cache.h
10108@@ -7,10 +7,12 @@
10109 #ifndef _SPARC_CACHE_H
10110 #define _SPARC_CACHE_H
10111
10112+#include <linux/const.h>
10113+
10114 #define ARCH_SLAB_MINALIGN __alignof__(unsigned long long)
10115
10116 #define L1_CACHE_SHIFT 5
10117-#define L1_CACHE_BYTES 32
10118+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
10119
10120 #ifdef CONFIG_SPARC32
10121 #define SMP_CACHE_BYTES_SHIFT 5
10122diff --git a/arch/sparc/include/asm/elf_32.h b/arch/sparc/include/asm/elf_32.h
10123index a24e41f..47677ff 100644
10124--- a/arch/sparc/include/asm/elf_32.h
10125+++ b/arch/sparc/include/asm/elf_32.h
10126@@ -114,6 +114,13 @@ typedef struct {
10127
10128 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE)
10129
10130+#ifdef CONFIG_PAX_ASLR
10131+#define PAX_ELF_ET_DYN_BASE 0x10000UL
10132+
10133+#define PAX_DELTA_MMAP_LEN 16
10134+#define PAX_DELTA_STACK_LEN 16
10135+#endif
10136+
10137 /* This yields a mask that user programs can use to figure out what
10138 instruction set this cpu supports. This can NOT be done in userspace
10139 on Sparc. */
10140diff --git a/arch/sparc/include/asm/elf_64.h b/arch/sparc/include/asm/elf_64.h
10141index 370ca1e..d4f4a98 100644
10142--- a/arch/sparc/include/asm/elf_64.h
10143+++ b/arch/sparc/include/asm/elf_64.h
10144@@ -189,6 +189,13 @@ typedef struct {
10145 #define ELF_ET_DYN_BASE 0x0000010000000000UL
10146 #define COMPAT_ELF_ET_DYN_BASE 0x0000000070000000UL
10147
10148+#ifdef CONFIG_PAX_ASLR
10149+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT) ? 0x10000UL : 0x100000UL)
10150+
10151+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 14 : 28)
10152+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 15 : 29)
10153+#endif
10154+
10155 extern unsigned long sparc64_elf_hwcap;
10156 #define ELF_HWCAP sparc64_elf_hwcap
10157
10158diff --git a/arch/sparc/include/asm/pgalloc_32.h b/arch/sparc/include/asm/pgalloc_32.h
10159index a3890da..f6a408e 100644
10160--- a/arch/sparc/include/asm/pgalloc_32.h
10161+++ b/arch/sparc/include/asm/pgalloc_32.h
10162@@ -35,6 +35,7 @@ static inline void pgd_set(pgd_t * pgdp, pmd_t * pmdp)
10163 }
10164
10165 #define pgd_populate(MM, PGD, PMD) pgd_set(PGD, PMD)
10166+#define pgd_populate_kernel(MM, PGD, PMD) pgd_populate((MM), (PGD), (PMD))
10167
10168 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm,
10169 unsigned long address)
10170diff --git a/arch/sparc/include/asm/pgalloc_64.h b/arch/sparc/include/asm/pgalloc_64.h
10171index 5e31871..13469c6 100644
10172--- a/arch/sparc/include/asm/pgalloc_64.h
10173+++ b/arch/sparc/include/asm/pgalloc_64.h
10174@@ -21,6 +21,7 @@ static inline void __pgd_populate(pgd_t *pgd, pud_t *pud)
10175 }
10176
10177 #define pgd_populate(MM, PGD, PUD) __pgd_populate(PGD, PUD)
10178+#define pgd_populate_kernel(MM, PGD, PMD) pgd_populate((MM), (PGD), (PMD))
10179
10180 static inline pgd_t *pgd_alloc(struct mm_struct *mm)
10181 {
10182@@ -38,6 +39,7 @@ static inline void __pud_populate(pud_t *pud, pmd_t *pmd)
10183 }
10184
10185 #define pud_populate(MM, PUD, PMD) __pud_populate(PUD, PMD)
10186+#define pud_populate_kernel(MM, PUD, PMD) pud_populate((MM), (PUD), (PMD))
10187
10188 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
10189 {
10190diff --git a/arch/sparc/include/asm/pgtable.h b/arch/sparc/include/asm/pgtable.h
10191index 59ba6f6..4518128 100644
10192--- a/arch/sparc/include/asm/pgtable.h
10193+++ b/arch/sparc/include/asm/pgtable.h
10194@@ -5,4 +5,8 @@
10195 #else
10196 #include <asm/pgtable_32.h>
10197 #endif
10198+
10199+#define ktla_ktva(addr) (addr)
10200+#define ktva_ktla(addr) (addr)
10201+
10202 #endif
10203diff --git a/arch/sparc/include/asm/pgtable_32.h b/arch/sparc/include/asm/pgtable_32.h
10204index b9b91ae..950b91e 100644
10205--- a/arch/sparc/include/asm/pgtable_32.h
10206+++ b/arch/sparc/include/asm/pgtable_32.h
10207@@ -51,6 +51,9 @@ unsigned long __init bootmem_init(unsigned long *pages_avail);
10208 #define PAGE_SHARED SRMMU_PAGE_SHARED
10209 #define PAGE_COPY SRMMU_PAGE_COPY
10210 #define PAGE_READONLY SRMMU_PAGE_RDONLY
10211+#define PAGE_SHARED_NOEXEC SRMMU_PAGE_SHARED_NOEXEC
10212+#define PAGE_COPY_NOEXEC SRMMU_PAGE_COPY_NOEXEC
10213+#define PAGE_READONLY_NOEXEC SRMMU_PAGE_RDONLY_NOEXEC
10214 #define PAGE_KERNEL SRMMU_PAGE_KERNEL
10215
10216 /* Top-level page directory - dummy used by init-mm.
10217@@ -63,18 +66,18 @@ extern unsigned long ptr_in_current_pgd;
10218
10219 /* xwr */
10220 #define __P000 PAGE_NONE
10221-#define __P001 PAGE_READONLY
10222-#define __P010 PAGE_COPY
10223-#define __P011 PAGE_COPY
10224+#define __P001 PAGE_READONLY_NOEXEC
10225+#define __P010 PAGE_COPY_NOEXEC
10226+#define __P011 PAGE_COPY_NOEXEC
10227 #define __P100 PAGE_READONLY
10228 #define __P101 PAGE_READONLY
10229 #define __P110 PAGE_COPY
10230 #define __P111 PAGE_COPY
10231
10232 #define __S000 PAGE_NONE
10233-#define __S001 PAGE_READONLY
10234-#define __S010 PAGE_SHARED
10235-#define __S011 PAGE_SHARED
10236+#define __S001 PAGE_READONLY_NOEXEC
10237+#define __S010 PAGE_SHARED_NOEXEC
10238+#define __S011 PAGE_SHARED_NOEXEC
10239 #define __S100 PAGE_READONLY
10240 #define __S101 PAGE_READONLY
10241 #define __S110 PAGE_SHARED
10242diff --git a/arch/sparc/include/asm/pgtsrmmu.h b/arch/sparc/include/asm/pgtsrmmu.h
10243index 79da178..c2eede8 100644
10244--- a/arch/sparc/include/asm/pgtsrmmu.h
10245+++ b/arch/sparc/include/asm/pgtsrmmu.h
10246@@ -115,6 +115,11 @@
10247 SRMMU_EXEC | SRMMU_REF)
10248 #define SRMMU_PAGE_RDONLY __pgprot(SRMMU_VALID | SRMMU_CACHE | \
10249 SRMMU_EXEC | SRMMU_REF)
10250+
10251+#define SRMMU_PAGE_SHARED_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_WRITE | SRMMU_REF)
10252+#define SRMMU_PAGE_COPY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
10253+#define SRMMU_PAGE_RDONLY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
10254+
10255 #define SRMMU_PAGE_KERNEL __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
10256 SRMMU_DIRTY | SRMMU_REF)
10257
10258diff --git a/arch/sparc/include/asm/setup.h b/arch/sparc/include/asm/setup.h
10259index 29d64b1..4272fe8 100644
10260--- a/arch/sparc/include/asm/setup.h
10261+++ b/arch/sparc/include/asm/setup.h
10262@@ -55,8 +55,8 @@ int handle_ldf_stq(u32 insn, struct pt_regs *regs);
10263 void handle_ld_nf(u32 insn, struct pt_regs *regs);
10264
10265 /* init_64.c */
10266-extern atomic_t dcpage_flushes;
10267-extern atomic_t dcpage_flushes_xcall;
10268+extern atomic_unchecked_t dcpage_flushes;
10269+extern atomic_unchecked_t dcpage_flushes_xcall;
10270
10271 extern int sysctl_tsb_ratio;
10272 #endif
10273diff --git a/arch/sparc/include/asm/spinlock_64.h b/arch/sparc/include/asm/spinlock_64.h
10274index 9689176..63c18ea 100644
10275--- a/arch/sparc/include/asm/spinlock_64.h
10276+++ b/arch/sparc/include/asm/spinlock_64.h
10277@@ -92,14 +92,19 @@ static inline void arch_spin_lock_flags(arch_spinlock_t *lock, unsigned long fla
10278
10279 /* Multi-reader locks, these are much saner than the 32-bit Sparc ones... */
10280
10281-static void inline arch_read_lock(arch_rwlock_t *lock)
10282+static inline void arch_read_lock(arch_rwlock_t *lock)
10283 {
10284 unsigned long tmp1, tmp2;
10285
10286 __asm__ __volatile__ (
10287 "1: ldsw [%2], %0\n"
10288 " brlz,pn %0, 2f\n"
10289-"4: add %0, 1, %1\n"
10290+"4: addcc %0, 1, %1\n"
10291+
10292+#ifdef CONFIG_PAX_REFCOUNT
10293+" tvs %%icc, 6\n"
10294+#endif
10295+
10296 " cas [%2], %0, %1\n"
10297 " cmp %0, %1\n"
10298 " bne,pn %%icc, 1b\n"
10299@@ -112,10 +117,10 @@ static void inline arch_read_lock(arch_rwlock_t *lock)
10300 " .previous"
10301 : "=&r" (tmp1), "=&r" (tmp2)
10302 : "r" (lock)
10303- : "memory");
10304+ : "memory", "cc");
10305 }
10306
10307-static int inline arch_read_trylock(arch_rwlock_t *lock)
10308+static inline int arch_read_trylock(arch_rwlock_t *lock)
10309 {
10310 int tmp1, tmp2;
10311
10312@@ -123,7 +128,12 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
10313 "1: ldsw [%2], %0\n"
10314 " brlz,a,pn %0, 2f\n"
10315 " mov 0, %0\n"
10316-" add %0, 1, %1\n"
10317+" addcc %0, 1, %1\n"
10318+
10319+#ifdef CONFIG_PAX_REFCOUNT
10320+" tvs %%icc, 6\n"
10321+#endif
10322+
10323 " cas [%2], %0, %1\n"
10324 " cmp %0, %1\n"
10325 " bne,pn %%icc, 1b\n"
10326@@ -136,13 +146,18 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
10327 return tmp1;
10328 }
10329
10330-static void inline arch_read_unlock(arch_rwlock_t *lock)
10331+static inline void arch_read_unlock(arch_rwlock_t *lock)
10332 {
10333 unsigned long tmp1, tmp2;
10334
10335 __asm__ __volatile__(
10336 "1: lduw [%2], %0\n"
10337-" sub %0, 1, %1\n"
10338+" subcc %0, 1, %1\n"
10339+
10340+#ifdef CONFIG_PAX_REFCOUNT
10341+" tvs %%icc, 6\n"
10342+#endif
10343+
10344 " cas [%2], %0, %1\n"
10345 " cmp %0, %1\n"
10346 " bne,pn %%xcc, 1b\n"
10347@@ -152,7 +167,7 @@ static void inline arch_read_unlock(arch_rwlock_t *lock)
10348 : "memory");
10349 }
10350
10351-static void inline arch_write_lock(arch_rwlock_t *lock)
10352+static inline void arch_write_lock(arch_rwlock_t *lock)
10353 {
10354 unsigned long mask, tmp1, tmp2;
10355
10356@@ -177,7 +192,7 @@ static void inline arch_write_lock(arch_rwlock_t *lock)
10357 : "memory");
10358 }
10359
10360-static void inline arch_write_unlock(arch_rwlock_t *lock)
10361+static inline void arch_write_unlock(arch_rwlock_t *lock)
10362 {
10363 __asm__ __volatile__(
10364 " stw %%g0, [%0]"
10365@@ -186,7 +201,7 @@ static void inline arch_write_unlock(arch_rwlock_t *lock)
10366 : "memory");
10367 }
10368
10369-static int inline arch_write_trylock(arch_rwlock_t *lock)
10370+static inline int arch_write_trylock(arch_rwlock_t *lock)
10371 {
10372 unsigned long mask, tmp1, tmp2, result;
10373
10374diff --git a/arch/sparc/include/asm/thread_info_32.h b/arch/sparc/include/asm/thread_info_32.h
10375index 025c984..a216504 100644
10376--- a/arch/sparc/include/asm/thread_info_32.h
10377+++ b/arch/sparc/include/asm/thread_info_32.h
10378@@ -49,6 +49,8 @@ struct thread_info {
10379 unsigned long w_saved;
10380
10381 struct restart_block restart_block;
10382+
10383+ unsigned long lowest_stack;
10384 };
10385
10386 /*
10387diff --git a/arch/sparc/include/asm/thread_info_64.h b/arch/sparc/include/asm/thread_info_64.h
10388index 798f027..b009941 100644
10389--- a/arch/sparc/include/asm/thread_info_64.h
10390+++ b/arch/sparc/include/asm/thread_info_64.h
10391@@ -63,6 +63,8 @@ struct thread_info {
10392 struct pt_regs *kern_una_regs;
10393 unsigned int kern_una_insn;
10394
10395+ unsigned long lowest_stack;
10396+
10397 unsigned long fpregs[(7 * 256) / sizeof(unsigned long)]
10398 __attribute__ ((aligned(64)));
10399 };
10400@@ -190,12 +192,13 @@ register struct thread_info *current_thread_info_reg asm("g6");
10401 #define TIF_NEED_RESCHED 3 /* rescheduling necessary */
10402 /* flag bit 4 is available */
10403 #define TIF_UNALIGNED 5 /* allowed to do unaligned accesses */
10404-/* flag bit 6 is available */
10405+#define TIF_GRSEC_SETXID 6 /* update credentials on syscall entry/exit */
10406 #define TIF_32BIT 7 /* 32-bit binary */
10407 #define TIF_NOHZ 8 /* in adaptive nohz mode */
10408 #define TIF_SECCOMP 9 /* secure computing */
10409 #define TIF_SYSCALL_AUDIT 10 /* syscall auditing active */
10410 #define TIF_SYSCALL_TRACEPOINT 11 /* syscall tracepoint instrumentation */
10411+
10412 /* NOTE: Thread flags >= 12 should be ones we have no interest
10413 * in using in assembly, else we can't use the mask as
10414 * an immediate value in instructions such as andcc.
10415@@ -215,12 +218,17 @@ register struct thread_info *current_thread_info_reg asm("g6");
10416 #define _TIF_SYSCALL_AUDIT (1<<TIF_SYSCALL_AUDIT)
10417 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
10418 #define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG)
10419+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
10420
10421 #define _TIF_USER_WORK_MASK ((0xff << TI_FLAG_WSAVED_SHIFT) | \
10422 _TIF_DO_NOTIFY_RESUME_MASK | \
10423 _TIF_NEED_RESCHED)
10424 #define _TIF_DO_NOTIFY_RESUME_MASK (_TIF_NOTIFY_RESUME | _TIF_SIGPENDING)
10425
10426+#define _TIF_WORK_SYSCALL \
10427+ (_TIF_SYSCALL_TRACE | _TIF_SECCOMP | _TIF_SYSCALL_AUDIT | \
10428+ _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ | _TIF_GRSEC_SETXID)
10429+
10430 #define is_32bit_task() (test_thread_flag(TIF_32BIT))
10431
10432 /*
10433diff --git a/arch/sparc/include/asm/uaccess.h b/arch/sparc/include/asm/uaccess.h
10434index bd56c28..4b63d83 100644
10435--- a/arch/sparc/include/asm/uaccess.h
10436+++ b/arch/sparc/include/asm/uaccess.h
10437@@ -1,5 +1,6 @@
10438 #ifndef ___ASM_SPARC_UACCESS_H
10439 #define ___ASM_SPARC_UACCESS_H
10440+
10441 #if defined(__sparc__) && defined(__arch64__)
10442 #include <asm/uaccess_64.h>
10443 #else
10444diff --git a/arch/sparc/include/asm/uaccess_32.h b/arch/sparc/include/asm/uaccess_32.h
10445index 9634d08..f55fe4f 100644
10446--- a/arch/sparc/include/asm/uaccess_32.h
10447+++ b/arch/sparc/include/asm/uaccess_32.h
10448@@ -250,27 +250,46 @@ unsigned long __copy_user(void __user *to, const void __user *from, unsigned lon
10449
10450 static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
10451 {
10452- if (n && __access_ok((unsigned long) to, n))
10453+ if ((long)n < 0)
10454+ return n;
10455+
10456+ if (n && __access_ok((unsigned long) to, n)) {
10457+ if (!__builtin_constant_p(n))
10458+ check_object_size(from, n, true);
10459 return __copy_user(to, (__force void __user *) from, n);
10460- else
10461+ } else
10462 return n;
10463 }
10464
10465 static inline unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n)
10466 {
10467+ if ((long)n < 0)
10468+ return n;
10469+
10470+ if (!__builtin_constant_p(n))
10471+ check_object_size(from, n, true);
10472+
10473 return __copy_user(to, (__force void __user *) from, n);
10474 }
10475
10476 static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
10477 {
10478- if (n && __access_ok((unsigned long) from, n))
10479+ if ((long)n < 0)
10480+ return n;
10481+
10482+ if (n && __access_ok((unsigned long) from, n)) {
10483+ if (!__builtin_constant_p(n))
10484+ check_object_size(to, n, false);
10485 return __copy_user((__force void __user *) to, from, n);
10486- else
10487+ } else
10488 return n;
10489 }
10490
10491 static inline unsigned long __copy_from_user(void *to, const void __user *from, unsigned long n)
10492 {
10493+ if ((long)n < 0)
10494+ return n;
10495+
10496 return __copy_user((__force void __user *) to, from, n);
10497 }
10498
10499diff --git a/arch/sparc/include/asm/uaccess_64.h b/arch/sparc/include/asm/uaccess_64.h
10500index c990a5e..f17b9c1 100644
10501--- a/arch/sparc/include/asm/uaccess_64.h
10502+++ b/arch/sparc/include/asm/uaccess_64.h
10503@@ -10,6 +10,7 @@
10504 #include <linux/compiler.h>
10505 #include <linux/string.h>
10506 #include <linux/thread_info.h>
10507+#include <linux/kernel.h>
10508 #include <asm/asi.h>
10509 #include <asm/spitfire.h>
10510 #include <asm-generic/uaccess-unaligned.h>
10511@@ -214,8 +215,15 @@ unsigned long copy_from_user_fixup(void *to, const void __user *from,
10512 static inline unsigned long __must_check
10513 copy_from_user(void *to, const void __user *from, unsigned long size)
10514 {
10515- unsigned long ret = ___copy_from_user(to, from, size);
10516+ unsigned long ret;
10517
10518+ if ((long)size < 0 || size > INT_MAX)
10519+ return size;
10520+
10521+ if (!__builtin_constant_p(size))
10522+ check_object_size(to, size, false);
10523+
10524+ ret = ___copy_from_user(to, from, size);
10525 if (unlikely(ret))
10526 ret = copy_from_user_fixup(to, from, size);
10527
10528@@ -231,8 +239,15 @@ unsigned long copy_to_user_fixup(void __user *to, const void *from,
10529 static inline unsigned long __must_check
10530 copy_to_user(void __user *to, const void *from, unsigned long size)
10531 {
10532- unsigned long ret = ___copy_to_user(to, from, size);
10533+ unsigned long ret;
10534
10535+ if ((long)size < 0 || size > INT_MAX)
10536+ return size;
10537+
10538+ if (!__builtin_constant_p(size))
10539+ check_object_size(from, size, true);
10540+
10541+ ret = ___copy_to_user(to, from, size);
10542 if (unlikely(ret))
10543 ret = copy_to_user_fixup(to, from, size);
10544 return ret;
10545diff --git a/arch/sparc/kernel/Makefile b/arch/sparc/kernel/Makefile
10546index 7cf9c6e..6206648 100644
10547--- a/arch/sparc/kernel/Makefile
10548+++ b/arch/sparc/kernel/Makefile
10549@@ -4,7 +4,7 @@
10550 #
10551
10552 asflags-y := -ansi
10553-ccflags-y := -Werror
10554+#ccflags-y := -Werror
10555
10556 extra-y := head_$(BITS).o
10557
10558diff --git a/arch/sparc/kernel/process_32.c b/arch/sparc/kernel/process_32.c
10559index 50e7b62..79fae35 100644
10560--- a/arch/sparc/kernel/process_32.c
10561+++ b/arch/sparc/kernel/process_32.c
10562@@ -123,14 +123,14 @@ void show_regs(struct pt_regs *r)
10563
10564 printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx %s\n",
10565 r->psr, r->pc, r->npc, r->y, print_tainted());
10566- printk("PC: <%pS>\n", (void *) r->pc);
10567+ printk("PC: <%pA>\n", (void *) r->pc);
10568 printk("%%G: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
10569 r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3],
10570 r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]);
10571 printk("%%O: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
10572 r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11],
10573 r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]);
10574- printk("RPC: <%pS>\n", (void *) r->u_regs[15]);
10575+ printk("RPC: <%pA>\n", (void *) r->u_regs[15]);
10576
10577 printk("%%L: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
10578 rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
10579@@ -167,7 +167,7 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
10580 rw = (struct reg_window32 *) fp;
10581 pc = rw->ins[7];
10582 printk("[%08lx : ", pc);
10583- printk("%pS ] ", (void *) pc);
10584+ printk("%pA ] ", (void *) pc);
10585 fp = rw->ins[6];
10586 } while (++count < 16);
10587 printk("\n");
10588diff --git a/arch/sparc/kernel/process_64.c b/arch/sparc/kernel/process_64.c
10589index 0be7bf9..2b1cba8 100644
10590--- a/arch/sparc/kernel/process_64.c
10591+++ b/arch/sparc/kernel/process_64.c
10592@@ -161,7 +161,7 @@ static void show_regwindow(struct pt_regs *regs)
10593 printk("i4: %016lx i5: %016lx i6: %016lx i7: %016lx\n",
10594 rwk->ins[4], rwk->ins[5], rwk->ins[6], rwk->ins[7]);
10595 if (regs->tstate & TSTATE_PRIV)
10596- printk("I7: <%pS>\n", (void *) rwk->ins[7]);
10597+ printk("I7: <%pA>\n", (void *) rwk->ins[7]);
10598 }
10599
10600 void show_regs(struct pt_regs *regs)
10601@@ -170,7 +170,7 @@ void show_regs(struct pt_regs *regs)
10602
10603 printk("TSTATE: %016lx TPC: %016lx TNPC: %016lx Y: %08x %s\n", regs->tstate,
10604 regs->tpc, regs->tnpc, regs->y, print_tainted());
10605- printk("TPC: <%pS>\n", (void *) regs->tpc);
10606+ printk("TPC: <%pA>\n", (void *) regs->tpc);
10607 printk("g0: %016lx g1: %016lx g2: %016lx g3: %016lx\n",
10608 regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
10609 regs->u_regs[3]);
10610@@ -183,7 +183,7 @@ void show_regs(struct pt_regs *regs)
10611 printk("o4: %016lx o5: %016lx sp: %016lx ret_pc: %016lx\n",
10612 regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
10613 regs->u_regs[15]);
10614- printk("RPC: <%pS>\n", (void *) regs->u_regs[15]);
10615+ printk("RPC: <%pA>\n", (void *) regs->u_regs[15]);
10616 show_regwindow(regs);
10617 show_stack(current, (unsigned long *) regs->u_regs[UREG_FP]);
10618 }
10619@@ -278,7 +278,7 @@ void arch_trigger_all_cpu_backtrace(bool include_self)
10620 ((tp && tp->task) ? tp->task->pid : -1));
10621
10622 if (gp->tstate & TSTATE_PRIV) {
10623- printk(" TPC[%pS] O7[%pS] I7[%pS] RPC[%pS]\n",
10624+ printk(" TPC[%pA] O7[%pA] I7[%pA] RPC[%pA]\n",
10625 (void *) gp->tpc,
10626 (void *) gp->o7,
10627 (void *) gp->i7,
10628diff --git a/arch/sparc/kernel/prom_common.c b/arch/sparc/kernel/prom_common.c
10629index 79cc0d1..ec62734 100644
10630--- a/arch/sparc/kernel/prom_common.c
10631+++ b/arch/sparc/kernel/prom_common.c
10632@@ -144,7 +144,7 @@ static int __init prom_common_nextprop(phandle node, char *prev, char *buf)
10633
10634 unsigned int prom_early_allocated __initdata;
10635
10636-static struct of_pdt_ops prom_sparc_ops __initdata = {
10637+static struct of_pdt_ops prom_sparc_ops __initconst = {
10638 .nextprop = prom_common_nextprop,
10639 .getproplen = prom_getproplen,
10640 .getproperty = prom_getproperty,
10641diff --git a/arch/sparc/kernel/ptrace_64.c b/arch/sparc/kernel/ptrace_64.c
10642index 9ddc492..27a5619 100644
10643--- a/arch/sparc/kernel/ptrace_64.c
10644+++ b/arch/sparc/kernel/ptrace_64.c
10645@@ -1060,6 +1060,10 @@ long arch_ptrace(struct task_struct *child, long request,
10646 return ret;
10647 }
10648
10649+#ifdef CONFIG_GRKERNSEC_SETXID
10650+extern void gr_delayed_cred_worker(void);
10651+#endif
10652+
10653 asmlinkage int syscall_trace_enter(struct pt_regs *regs)
10654 {
10655 int ret = 0;
10656@@ -1070,6 +1074,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
10657 if (test_thread_flag(TIF_NOHZ))
10658 user_exit();
10659
10660+#ifdef CONFIG_GRKERNSEC_SETXID
10661+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
10662+ gr_delayed_cred_worker();
10663+#endif
10664+
10665 if (test_thread_flag(TIF_SYSCALL_TRACE))
10666 ret = tracehook_report_syscall_entry(regs);
10667
10668@@ -1088,6 +1097,11 @@ asmlinkage void syscall_trace_leave(struct pt_regs *regs)
10669 if (test_thread_flag(TIF_NOHZ))
10670 user_exit();
10671
10672+#ifdef CONFIG_GRKERNSEC_SETXID
10673+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
10674+ gr_delayed_cred_worker();
10675+#endif
10676+
10677 audit_syscall_exit(regs);
10678
10679 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
10680diff --git a/arch/sparc/kernel/smp_64.c b/arch/sparc/kernel/smp_64.c
10681index da6f1a7..e5dea8f 100644
10682--- a/arch/sparc/kernel/smp_64.c
10683+++ b/arch/sparc/kernel/smp_64.c
10684@@ -887,7 +887,7 @@ void smp_flush_dcache_page_impl(struct page *page, int cpu)
10685 return;
10686
10687 #ifdef CONFIG_DEBUG_DCFLUSH
10688- atomic_inc(&dcpage_flushes);
10689+ atomic_inc_unchecked(&dcpage_flushes);
10690 #endif
10691
10692 this_cpu = get_cpu();
10693@@ -911,7 +911,7 @@ void smp_flush_dcache_page_impl(struct page *page, int cpu)
10694 xcall_deliver(data0, __pa(pg_addr),
10695 (u64) pg_addr, cpumask_of(cpu));
10696 #ifdef CONFIG_DEBUG_DCFLUSH
10697- atomic_inc(&dcpage_flushes_xcall);
10698+ atomic_inc_unchecked(&dcpage_flushes_xcall);
10699 #endif
10700 }
10701 }
10702@@ -930,7 +930,7 @@ void flush_dcache_page_all(struct mm_struct *mm, struct page *page)
10703 preempt_disable();
10704
10705 #ifdef CONFIG_DEBUG_DCFLUSH
10706- atomic_inc(&dcpage_flushes);
10707+ atomic_inc_unchecked(&dcpage_flushes);
10708 #endif
10709 data0 = 0;
10710 pg_addr = page_address(page);
10711@@ -947,7 +947,7 @@ void flush_dcache_page_all(struct mm_struct *mm, struct page *page)
10712 xcall_deliver(data0, __pa(pg_addr),
10713 (u64) pg_addr, cpu_online_mask);
10714 #ifdef CONFIG_DEBUG_DCFLUSH
10715- atomic_inc(&dcpage_flushes_xcall);
10716+ atomic_inc_unchecked(&dcpage_flushes_xcall);
10717 #endif
10718 }
10719 __local_flush_dcache_page(page);
10720diff --git a/arch/sparc/kernel/sys_sparc_32.c b/arch/sparc/kernel/sys_sparc_32.c
10721index 646988d..b88905f 100644
10722--- a/arch/sparc/kernel/sys_sparc_32.c
10723+++ b/arch/sparc/kernel/sys_sparc_32.c
10724@@ -54,7 +54,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
10725 if (len > TASK_SIZE - PAGE_SIZE)
10726 return -ENOMEM;
10727 if (!addr)
10728- addr = TASK_UNMAPPED_BASE;
10729+ addr = current->mm->mmap_base;
10730
10731 info.flags = 0;
10732 info.length = len;
10733diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
10734index c85403d..6af95c9 100644
10735--- a/arch/sparc/kernel/sys_sparc_64.c
10736+++ b/arch/sparc/kernel/sys_sparc_64.c
10737@@ -89,13 +89,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
10738 struct vm_area_struct * vma;
10739 unsigned long task_size = TASK_SIZE;
10740 int do_color_align;
10741+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
10742 struct vm_unmapped_area_info info;
10743
10744 if (flags & MAP_FIXED) {
10745 /* We do not accept a shared mapping if it would violate
10746 * cache aliasing constraints.
10747 */
10748- if ((flags & MAP_SHARED) &&
10749+ if ((filp || (flags & MAP_SHARED)) &&
10750 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
10751 return -EINVAL;
10752 return addr;
10753@@ -110,6 +111,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
10754 if (filp || (flags & MAP_SHARED))
10755 do_color_align = 1;
10756
10757+#ifdef CONFIG_PAX_RANDMMAP
10758+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
10759+#endif
10760+
10761 if (addr) {
10762 if (do_color_align)
10763 addr = COLOR_ALIGN(addr, pgoff);
10764@@ -117,22 +122,28 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
10765 addr = PAGE_ALIGN(addr);
10766
10767 vma = find_vma(mm, addr);
10768- if (task_size - len >= addr &&
10769- (!vma || addr + len <= vma->vm_start))
10770+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
10771 return addr;
10772 }
10773
10774 info.flags = 0;
10775 info.length = len;
10776- info.low_limit = TASK_UNMAPPED_BASE;
10777+ info.low_limit = mm->mmap_base;
10778 info.high_limit = min(task_size, VA_EXCLUDE_START);
10779 info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
10780 info.align_offset = pgoff << PAGE_SHIFT;
10781+ info.threadstack_offset = offset;
10782 addr = vm_unmapped_area(&info);
10783
10784 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
10785 VM_BUG_ON(addr != -ENOMEM);
10786 info.low_limit = VA_EXCLUDE_END;
10787+
10788+#ifdef CONFIG_PAX_RANDMMAP
10789+ if (mm->pax_flags & MF_PAX_RANDMMAP)
10790+ info.low_limit += mm->delta_mmap;
10791+#endif
10792+
10793 info.high_limit = task_size;
10794 addr = vm_unmapped_area(&info);
10795 }
10796@@ -150,6 +161,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10797 unsigned long task_size = STACK_TOP32;
10798 unsigned long addr = addr0;
10799 int do_color_align;
10800+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
10801 struct vm_unmapped_area_info info;
10802
10803 /* This should only ever run for 32-bit processes. */
10804@@ -159,7 +171,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10805 /* We do not accept a shared mapping if it would violate
10806 * cache aliasing constraints.
10807 */
10808- if ((flags & MAP_SHARED) &&
10809+ if ((filp || (flags & MAP_SHARED)) &&
10810 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
10811 return -EINVAL;
10812 return addr;
10813@@ -172,6 +184,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10814 if (filp || (flags & MAP_SHARED))
10815 do_color_align = 1;
10816
10817+#ifdef CONFIG_PAX_RANDMMAP
10818+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
10819+#endif
10820+
10821 /* requesting a specific address */
10822 if (addr) {
10823 if (do_color_align)
10824@@ -180,8 +196,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10825 addr = PAGE_ALIGN(addr);
10826
10827 vma = find_vma(mm, addr);
10828- if (task_size - len >= addr &&
10829- (!vma || addr + len <= vma->vm_start))
10830+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
10831 return addr;
10832 }
10833
10834@@ -191,6 +206,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10835 info.high_limit = mm->mmap_base;
10836 info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
10837 info.align_offset = pgoff << PAGE_SHIFT;
10838+ info.threadstack_offset = offset;
10839 addr = vm_unmapped_area(&info);
10840
10841 /*
10842@@ -203,6 +219,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10843 VM_BUG_ON(addr != -ENOMEM);
10844 info.flags = 0;
10845 info.low_limit = TASK_UNMAPPED_BASE;
10846+
10847+#ifdef CONFIG_PAX_RANDMMAP
10848+ if (mm->pax_flags & MF_PAX_RANDMMAP)
10849+ info.low_limit += mm->delta_mmap;
10850+#endif
10851+
10852 info.high_limit = STACK_TOP32;
10853 addr = vm_unmapped_area(&info);
10854 }
10855@@ -259,10 +281,14 @@ unsigned long get_fb_unmapped_area(struct file *filp, unsigned long orig_addr, u
10856 EXPORT_SYMBOL(get_fb_unmapped_area);
10857
10858 /* Essentially the same as PowerPC. */
10859-static unsigned long mmap_rnd(void)
10860+static unsigned long mmap_rnd(struct mm_struct *mm)
10861 {
10862 unsigned long rnd = 0UL;
10863
10864+#ifdef CONFIG_PAX_RANDMMAP
10865+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
10866+#endif
10867+
10868 if (current->flags & PF_RANDOMIZE) {
10869 unsigned long val = get_random_int();
10870 if (test_thread_flag(TIF_32BIT))
10871@@ -275,7 +301,7 @@ static unsigned long mmap_rnd(void)
10872
10873 void arch_pick_mmap_layout(struct mm_struct *mm)
10874 {
10875- unsigned long random_factor = mmap_rnd();
10876+ unsigned long random_factor = mmap_rnd(mm);
10877 unsigned long gap;
10878
10879 /*
10880@@ -288,6 +314,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
10881 gap == RLIM_INFINITY ||
10882 sysctl_legacy_va_layout) {
10883 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
10884+
10885+#ifdef CONFIG_PAX_RANDMMAP
10886+ if (mm->pax_flags & MF_PAX_RANDMMAP)
10887+ mm->mmap_base += mm->delta_mmap;
10888+#endif
10889+
10890 mm->get_unmapped_area = arch_get_unmapped_area;
10891 } else {
10892 /* We know it's 32-bit */
10893@@ -299,6 +331,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
10894 gap = (task_size / 6 * 5);
10895
10896 mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
10897+
10898+#ifdef CONFIG_PAX_RANDMMAP
10899+ if (mm->pax_flags & MF_PAX_RANDMMAP)
10900+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
10901+#endif
10902+
10903 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
10904 }
10905 }
10906diff --git a/arch/sparc/kernel/syscalls.S b/arch/sparc/kernel/syscalls.S
10907index 33a17e7..d87fb1f 100644
10908--- a/arch/sparc/kernel/syscalls.S
10909+++ b/arch/sparc/kernel/syscalls.S
10910@@ -52,7 +52,7 @@ sys32_rt_sigreturn:
10911 #endif
10912 .align 32
10913 1: ldx [%g6 + TI_FLAGS], %l5
10914- andcc %l5, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
10915+ andcc %l5, _TIF_WORK_SYSCALL, %g0
10916 be,pt %icc, rtrap
10917 nop
10918 call syscall_trace_leave
10919@@ -184,7 +184,7 @@ linux_sparc_syscall32:
10920
10921 srl %i3, 0, %o3 ! IEU0
10922 srl %i2, 0, %o2 ! IEU0 Group
10923- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
10924+ andcc %l0, _TIF_WORK_SYSCALL, %g0
10925 bne,pn %icc, linux_syscall_trace32 ! CTI
10926 mov %i0, %l5 ! IEU1
10927 5: call %l7 ! CTI Group brk forced
10928@@ -208,7 +208,7 @@ linux_sparc_syscall:
10929
10930 mov %i3, %o3 ! IEU1
10931 mov %i4, %o4 ! IEU0 Group
10932- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
10933+ andcc %l0, _TIF_WORK_SYSCALL, %g0
10934 bne,pn %icc, linux_syscall_trace ! CTI Group
10935 mov %i0, %l5 ! IEU0
10936 2: call %l7 ! CTI Group brk forced
10937@@ -223,7 +223,7 @@ ret_sys_call:
10938
10939 cmp %o0, -ERESTART_RESTARTBLOCK
10940 bgeu,pn %xcc, 1f
10941- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
10942+ andcc %l0, _TIF_WORK_SYSCALL, %g0
10943 ldx [%sp + PTREGS_OFF + PT_V9_TNPC], %l1 ! pc = npc
10944
10945 2:
10946diff --git a/arch/sparc/kernel/traps_32.c b/arch/sparc/kernel/traps_32.c
10947index 6fd386c5..6907d81 100644
10948--- a/arch/sparc/kernel/traps_32.c
10949+++ b/arch/sparc/kernel/traps_32.c
10950@@ -44,6 +44,8 @@ static void instruction_dump(unsigned long *pc)
10951 #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
10952 #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
10953
10954+extern void gr_handle_kernel_exploit(void);
10955+
10956 void __noreturn die_if_kernel(char *str, struct pt_regs *regs)
10957 {
10958 static int die_counter;
10959@@ -76,15 +78,17 @@ void __noreturn die_if_kernel(char *str, struct pt_regs *regs)
10960 count++ < 30 &&
10961 (((unsigned long) rw) >= PAGE_OFFSET) &&
10962 !(((unsigned long) rw) & 0x7)) {
10963- printk("Caller[%08lx]: %pS\n", rw->ins[7],
10964+ printk("Caller[%08lx]: %pA\n", rw->ins[7],
10965 (void *) rw->ins[7]);
10966 rw = (struct reg_window32 *)rw->ins[6];
10967 }
10968 }
10969 printk("Instruction DUMP:");
10970 instruction_dump ((unsigned long *) regs->pc);
10971- if(regs->psr & PSR_PS)
10972+ if(regs->psr & PSR_PS) {
10973+ gr_handle_kernel_exploit();
10974 do_exit(SIGKILL);
10975+ }
10976 do_exit(SIGSEGV);
10977 }
10978
10979diff --git a/arch/sparc/kernel/traps_64.c b/arch/sparc/kernel/traps_64.c
10980index 981a769..d906eda 100644
10981--- a/arch/sparc/kernel/traps_64.c
10982+++ b/arch/sparc/kernel/traps_64.c
10983@@ -79,7 +79,7 @@ static void dump_tl1_traplog(struct tl1_traplog *p)
10984 i + 1,
10985 p->trapstack[i].tstate, p->trapstack[i].tpc,
10986 p->trapstack[i].tnpc, p->trapstack[i].tt);
10987- printk("TRAPLOG: TPC<%pS>\n", (void *) p->trapstack[i].tpc);
10988+ printk("TRAPLOG: TPC<%pA>\n", (void *) p->trapstack[i].tpc);
10989 }
10990 }
10991
10992@@ -99,6 +99,12 @@ void bad_trap(struct pt_regs *regs, long lvl)
10993
10994 lvl -= 0x100;
10995 if (regs->tstate & TSTATE_PRIV) {
10996+
10997+#ifdef CONFIG_PAX_REFCOUNT
10998+ if (lvl == 6)
10999+ pax_report_refcount_overflow(regs);
11000+#endif
11001+
11002 sprintf(buffer, "Kernel bad sw trap %lx", lvl);
11003 die_if_kernel(buffer, regs);
11004 }
11005@@ -117,11 +123,16 @@ void bad_trap(struct pt_regs *regs, long lvl)
11006 void bad_trap_tl1(struct pt_regs *regs, long lvl)
11007 {
11008 char buffer[32];
11009-
11010+
11011 if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
11012 0, lvl, SIGTRAP) == NOTIFY_STOP)
11013 return;
11014
11015+#ifdef CONFIG_PAX_REFCOUNT
11016+ if (lvl == 6)
11017+ pax_report_refcount_overflow(regs);
11018+#endif
11019+
11020 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
11021
11022 sprintf (buffer, "Bad trap %lx at tl>0", lvl);
11023@@ -1151,7 +1162,7 @@ static void cheetah_log_errors(struct pt_regs *regs, struct cheetah_err_info *in
11024 regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate);
11025 printk("%s" "ERROR(%d): ",
11026 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id());
11027- printk("TPC<%pS>\n", (void *) regs->tpc);
11028+ printk("TPC<%pA>\n", (void *) regs->tpc);
11029 printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
11030 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
11031 (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
11032@@ -1758,7 +1769,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
11033 smp_processor_id(),
11034 (type & 0x1) ? 'I' : 'D',
11035 regs->tpc);
11036- printk(KERN_EMERG "TPC<%pS>\n", (void *) regs->tpc);
11037+ printk(KERN_EMERG "TPC<%pA>\n", (void *) regs->tpc);
11038 panic("Irrecoverable Cheetah+ parity error.");
11039 }
11040
11041@@ -1766,7 +1777,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
11042 smp_processor_id(),
11043 (type & 0x1) ? 'I' : 'D',
11044 regs->tpc);
11045- printk(KERN_WARNING "TPC<%pS>\n", (void *) regs->tpc);
11046+ printk(KERN_WARNING "TPC<%pA>\n", (void *) regs->tpc);
11047 }
11048
11049 struct sun4v_error_entry {
11050@@ -1839,8 +1850,8 @@ struct sun4v_error_entry {
11051 /*0x38*/u64 reserved_5;
11052 };
11053
11054-static atomic_t sun4v_resum_oflow_cnt = ATOMIC_INIT(0);
11055-static atomic_t sun4v_nonresum_oflow_cnt = ATOMIC_INIT(0);
11056+static atomic_unchecked_t sun4v_resum_oflow_cnt = ATOMIC_INIT(0);
11057+static atomic_unchecked_t sun4v_nonresum_oflow_cnt = ATOMIC_INIT(0);
11058
11059 static const char *sun4v_err_type_to_str(u8 type)
11060 {
11061@@ -1932,7 +1943,7 @@ static void sun4v_report_real_raddr(const char *pfx, struct pt_regs *regs)
11062 }
11063
11064 static void sun4v_log_error(struct pt_regs *regs, struct sun4v_error_entry *ent,
11065- int cpu, const char *pfx, atomic_t *ocnt)
11066+ int cpu, const char *pfx, atomic_unchecked_t *ocnt)
11067 {
11068 u64 *raw_ptr = (u64 *) ent;
11069 u32 attrs;
11070@@ -1990,8 +2001,8 @@ static void sun4v_log_error(struct pt_regs *regs, struct sun4v_error_entry *ent,
11071
11072 show_regs(regs);
11073
11074- if ((cnt = atomic_read(ocnt)) != 0) {
11075- atomic_set(ocnt, 0);
11076+ if ((cnt = atomic_read_unchecked(ocnt)) != 0) {
11077+ atomic_set_unchecked(ocnt, 0);
11078 wmb();
11079 printk("%s: Queue overflowed %d times.\n",
11080 pfx, cnt);
11081@@ -2048,7 +2059,7 @@ out:
11082 */
11083 void sun4v_resum_overflow(struct pt_regs *regs)
11084 {
11085- atomic_inc(&sun4v_resum_oflow_cnt);
11086+ atomic_inc_unchecked(&sun4v_resum_oflow_cnt);
11087 }
11088
11089 /* We run with %pil set to PIL_NORMAL_MAX and PSTATE_IE enabled in %pstate.
11090@@ -2101,7 +2112,7 @@ void sun4v_nonresum_overflow(struct pt_regs *regs)
11091 /* XXX Actually even this can make not that much sense. Perhaps
11092 * XXX we should just pull the plug and panic directly from here?
11093 */
11094- atomic_inc(&sun4v_nonresum_oflow_cnt);
11095+ atomic_inc_unchecked(&sun4v_nonresum_oflow_cnt);
11096 }
11097
11098 static void sun4v_tlb_error(struct pt_regs *regs)
11099@@ -2120,9 +2131,9 @@ void sun4v_itlb_error_report(struct pt_regs *regs, int tl)
11100
11101 printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
11102 regs->tpc, tl);
11103- printk(KERN_EMERG "SUN4V-ITLB: TPC<%pS>\n", (void *) regs->tpc);
11104+ printk(KERN_EMERG "SUN4V-ITLB: TPC<%pA>\n", (void *) regs->tpc);
11105 printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
11106- printk(KERN_EMERG "SUN4V-ITLB: O7<%pS>\n",
11107+ printk(KERN_EMERG "SUN4V-ITLB: O7<%pA>\n",
11108 (void *) regs->u_regs[UREG_I7]);
11109 printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] "
11110 "pte[%lx] error[%lx]\n",
11111@@ -2143,9 +2154,9 @@ void sun4v_dtlb_error_report(struct pt_regs *regs, int tl)
11112
11113 printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
11114 regs->tpc, tl);
11115- printk(KERN_EMERG "SUN4V-DTLB: TPC<%pS>\n", (void *) regs->tpc);
11116+ printk(KERN_EMERG "SUN4V-DTLB: TPC<%pA>\n", (void *) regs->tpc);
11117 printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
11118- printk(KERN_EMERG "SUN4V-DTLB: O7<%pS>\n",
11119+ printk(KERN_EMERG "SUN4V-DTLB: O7<%pA>\n",
11120 (void *) regs->u_regs[UREG_I7]);
11121 printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] "
11122 "pte[%lx] error[%lx]\n",
11123@@ -2362,13 +2373,13 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
11124 fp = (unsigned long)sf->fp + STACK_BIAS;
11125 }
11126
11127- printk(" [%016lx] %pS\n", pc, (void *) pc);
11128+ printk(" [%016lx] %pA\n", pc, (void *) pc);
11129 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
11130 if ((pc + 8UL) == (unsigned long) &return_to_handler) {
11131 int index = tsk->curr_ret_stack;
11132 if (tsk->ret_stack && index >= graph) {
11133 pc = tsk->ret_stack[index - graph].ret;
11134- printk(" [%016lx] %pS\n", pc, (void *) pc);
11135+ printk(" [%016lx] %pA\n", pc, (void *) pc);
11136 graph++;
11137 }
11138 }
11139@@ -2386,6 +2397,8 @@ static inline struct reg_window *kernel_stack_up(struct reg_window *rw)
11140 return (struct reg_window *) (fp + STACK_BIAS);
11141 }
11142
11143+extern void gr_handle_kernel_exploit(void);
11144+
11145 void __noreturn die_if_kernel(char *str, struct pt_regs *regs)
11146 {
11147 static int die_counter;
11148@@ -2414,7 +2427,7 @@ void __noreturn die_if_kernel(char *str, struct pt_regs *regs)
11149 while (rw &&
11150 count++ < 30 &&
11151 kstack_valid(tp, (unsigned long) rw)) {
11152- printk("Caller[%016lx]: %pS\n", rw->ins[7],
11153+ printk("Caller[%016lx]: %pA\n", rw->ins[7],
11154 (void *) rw->ins[7]);
11155
11156 rw = kernel_stack_up(rw);
11157@@ -2427,8 +2440,10 @@ void __noreturn die_if_kernel(char *str, struct pt_regs *regs)
11158 }
11159 user_instruction_dump ((unsigned int __user *) regs->tpc);
11160 }
11161- if (regs->tstate & TSTATE_PRIV)
11162+ if (regs->tstate & TSTATE_PRIV) {
11163+ gr_handle_kernel_exploit();
11164 do_exit(SIGKILL);
11165+ }
11166 do_exit(SIGSEGV);
11167 }
11168 EXPORT_SYMBOL(die_if_kernel);
11169diff --git a/arch/sparc/kernel/unaligned_64.c b/arch/sparc/kernel/unaligned_64.c
11170index 62098a8..547ab2c 100644
11171--- a/arch/sparc/kernel/unaligned_64.c
11172+++ b/arch/sparc/kernel/unaligned_64.c
11173@@ -297,7 +297,7 @@ static void log_unaligned(struct pt_regs *regs)
11174 static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);
11175
11176 if (__ratelimit(&ratelimit)) {
11177- printk("Kernel unaligned access at TPC[%lx] %pS\n",
11178+ printk("Kernel unaligned access at TPC[%lx] %pA\n",
11179 regs->tpc, (void *) regs->tpc);
11180 }
11181 }
11182diff --git a/arch/sparc/lib/Makefile b/arch/sparc/lib/Makefile
11183index 3269b02..64f5231 100644
11184--- a/arch/sparc/lib/Makefile
11185+++ b/arch/sparc/lib/Makefile
11186@@ -2,7 +2,7 @@
11187 #
11188
11189 asflags-y := -ansi -DST_DIV0=0x02
11190-ccflags-y := -Werror
11191+#ccflags-y := -Werror
11192
11193 lib-$(CONFIG_SPARC32) += ashrdi3.o
11194 lib-$(CONFIG_SPARC32) += memcpy.o memset.o
11195diff --git a/arch/sparc/lib/atomic_64.S b/arch/sparc/lib/atomic_64.S
11196index 05dac43..76f8ed4 100644
11197--- a/arch/sparc/lib/atomic_64.S
11198+++ b/arch/sparc/lib/atomic_64.S
11199@@ -15,11 +15,22 @@
11200 * a value and does the barriers.
11201 */
11202
11203-#define ATOMIC_OP(op) \
11204-ENTRY(atomic_##op) /* %o0 = increment, %o1 = atomic_ptr */ \
11205+#ifdef CONFIG_PAX_REFCOUNT
11206+#define __REFCOUNT_OP(op) op##cc
11207+#define __OVERFLOW_IOP tvs %icc, 6;
11208+#define __OVERFLOW_XOP tvs %xcc, 6;
11209+#else
11210+#define __REFCOUNT_OP(op) op
11211+#define __OVERFLOW_IOP
11212+#define __OVERFLOW_XOP
11213+#endif
11214+
11215+#define __ATOMIC_OP(op, suffix, asm_op, post_op) \
11216+ENTRY(atomic_##op##suffix) /* %o0 = increment, %o1 = atomic_ptr */ \
11217 BACKOFF_SETUP(%o2); \
11218 1: lduw [%o1], %g1; \
11219- op %g1, %o0, %g7; \
11220+ asm_op %g1, %o0, %g7; \
11221+ post_op \
11222 cas [%o1], %g1, %g7; \
11223 cmp %g1, %g7; \
11224 bne,pn %icc, BACKOFF_LABEL(2f, 1b); \
11225@@ -29,11 +40,15 @@ ENTRY(atomic_##op) /* %o0 = increment, %o1 = atomic_ptr */ \
11226 2: BACKOFF_SPIN(%o2, %o3, 1b); \
11227 ENDPROC(atomic_##op); \
11228
11229-#define ATOMIC_OP_RETURN(op) \
11230-ENTRY(atomic_##op##_return) /* %o0 = increment, %o1 = atomic_ptr */ \
11231+#define ATOMIC_OP(op) __ATOMIC_OP(op, , op, ) \
11232+ __ATOMIC_OP(op, _unchecked, __REFCOUNT_OP(op), __OVERFLOW_IOP)
11233+
11234+#define __ATOMIC_OP_RETURN(op, suffix, asm_op, post_op) \
11235+ENTRY(atomic_##op##_return##suffix) /* %o0 = increment, %o1 = atomic_ptr */\
11236 BACKOFF_SETUP(%o2); \
11237 1: lduw [%o1], %g1; \
11238- op %g1, %o0, %g7; \
11239+ asm_op %g1, %o0, %g7; \
11240+ post_op \
11241 cas [%o1], %g1, %g7; \
11242 cmp %g1, %g7; \
11243 bne,pn %icc, BACKOFF_LABEL(2f, 1b); \
11244@@ -43,6 +58,9 @@ ENTRY(atomic_##op##_return) /* %o0 = increment, %o1 = atomic_ptr */ \
11245 2: BACKOFF_SPIN(%o2, %o3, 1b); \
11246 ENDPROC(atomic_##op##_return);
11247
11248+#define ATOMIC_OP_RETURN(op) __ATOMIC_OP_RETURN(op, , op, ) \
11249+ __ATOMIC_OP_RETURN(op, _unchecked, __REFCOUNT_OP(op), __OVERFLOW_IOP)
11250+
11251 #define ATOMIC_OPS(op) ATOMIC_OP(op) ATOMIC_OP_RETURN(op)
11252
11253 ATOMIC_OPS(add)
11254@@ -50,13 +68,16 @@ ATOMIC_OPS(sub)
11255
11256 #undef ATOMIC_OPS
11257 #undef ATOMIC_OP_RETURN
11258+#undef __ATOMIC_OP_RETURN
11259 #undef ATOMIC_OP
11260+#undef __ATOMIC_OP
11261
11262-#define ATOMIC64_OP(op) \
11263-ENTRY(atomic64_##op) /* %o0 = increment, %o1 = atomic_ptr */ \
11264+#define __ATOMIC64_OP(op, suffix, asm_op, post_op) \
11265+ENTRY(atomic64_##op##suffix) /* %o0 = increment, %o1 = atomic_ptr */ \
11266 BACKOFF_SETUP(%o2); \
11267 1: ldx [%o1], %g1; \
11268- op %g1, %o0, %g7; \
11269+ asm_op %g1, %o0, %g7; \
11270+ post_op \
11271 casx [%o1], %g1, %g7; \
11272 cmp %g1, %g7; \
11273 bne,pn %xcc, BACKOFF_LABEL(2f, 1b); \
11274@@ -66,11 +87,15 @@ ENTRY(atomic64_##op) /* %o0 = increment, %o1 = atomic_ptr */ \
11275 2: BACKOFF_SPIN(%o2, %o3, 1b); \
11276 ENDPROC(atomic64_##op); \
11277
11278-#define ATOMIC64_OP_RETURN(op) \
11279-ENTRY(atomic64_##op##_return) /* %o0 = increment, %o1 = atomic_ptr */ \
11280+#define ATOMIC64_OP(op) __ATOMIC64_OP(op, , op, ) \
11281+ __ATOMIC64_OP(op, _unchecked, __REFCOUNT_OP(op), __OVERFLOW_XOP)
11282+
11283+#define __ATOMIC64_OP_RETURN(op, suffix, asm_op, post_op) \
11284+ENTRY(atomic64_##op##_return##suffix) /* %o0 = increment, %o1 = atomic_ptr */\
11285 BACKOFF_SETUP(%o2); \
11286 1: ldx [%o1], %g1; \
11287- op %g1, %o0, %g7; \
11288+ asm_op %g1, %o0, %g7; \
11289+ post_op \
11290 casx [%o1], %g1, %g7; \
11291 cmp %g1, %g7; \
11292 bne,pn %xcc, BACKOFF_LABEL(2f, 1b); \
11293@@ -80,6 +105,9 @@ ENTRY(atomic64_##op##_return) /* %o0 = increment, %o1 = atomic_ptr */ \
11294 2: BACKOFF_SPIN(%o2, %o3, 1b); \
11295 ENDPROC(atomic64_##op##_return);
11296
11297+#define ATOMIC64_OP_RETURN(op) __ATOMIC64_OP_RETURN(op, , op, ) \
11298+i __ATOMIC64_OP_RETURN(op, _unchecked, __REFCOUNT_OP(op), __OVERFLOW_XOP)
11299+
11300 #define ATOMIC64_OPS(op) ATOMIC64_OP(op) ATOMIC64_OP_RETURN(op)
11301
11302 ATOMIC64_OPS(add)
11303@@ -87,7 +115,12 @@ ATOMIC64_OPS(sub)
11304
11305 #undef ATOMIC64_OPS
11306 #undef ATOMIC64_OP_RETURN
11307+#undef __ATOMIC64_OP_RETURN
11308 #undef ATOMIC64_OP
11309+#undef __ATOMIC64_OP
11310+#undef __OVERFLOW_XOP
11311+#undef __OVERFLOW_IOP
11312+#undef __REFCOUNT_OP
11313
11314 ENTRY(atomic64_dec_if_positive) /* %o0 = atomic_ptr */
11315 BACKOFF_SETUP(%o2)
11316diff --git a/arch/sparc/lib/ksyms.c b/arch/sparc/lib/ksyms.c
11317index 1d649a9..fbc5bfc 100644
11318--- a/arch/sparc/lib/ksyms.c
11319+++ b/arch/sparc/lib/ksyms.c
11320@@ -101,7 +101,9 @@ EXPORT_SYMBOL(__clear_user);
11321 /* Atomic counter implementation. */
11322 #define ATOMIC_OP(op) \
11323 EXPORT_SYMBOL(atomic_##op); \
11324-EXPORT_SYMBOL(atomic64_##op);
11325+EXPORT_SYMBOL(atomic_##op##_unchecked); \
11326+EXPORT_SYMBOL(atomic64_##op); \
11327+EXPORT_SYMBOL(atomic64_##op##_unchecked);
11328
11329 #define ATOMIC_OP_RETURN(op) \
11330 EXPORT_SYMBOL(atomic_##op##_return); \
11331@@ -110,6 +112,8 @@ EXPORT_SYMBOL(atomic64_##op##_return);
11332 #define ATOMIC_OPS(op) ATOMIC_OP(op) ATOMIC_OP_RETURN(op)
11333
11334 ATOMIC_OPS(add)
11335+EXPORT_SYMBOL(atomic_add_ret_unchecked);
11336+EXPORT_SYMBOL(atomic64_add_ret_unchecked);
11337 ATOMIC_OPS(sub)
11338
11339 #undef ATOMIC_OPS
11340diff --git a/arch/sparc/mm/Makefile b/arch/sparc/mm/Makefile
11341index 30c3ecc..736f015 100644
11342--- a/arch/sparc/mm/Makefile
11343+++ b/arch/sparc/mm/Makefile
11344@@ -2,7 +2,7 @@
11345 #
11346
11347 asflags-y := -ansi
11348-ccflags-y := -Werror
11349+#ccflags-y := -Werror
11350
11351 obj-$(CONFIG_SPARC64) += ultra.o tlb.o tsb.o gup.o
11352 obj-y += fault_$(BITS).o
11353diff --git a/arch/sparc/mm/fault_32.c b/arch/sparc/mm/fault_32.c
11354index 908e8c1..1524793 100644
11355--- a/arch/sparc/mm/fault_32.c
11356+++ b/arch/sparc/mm/fault_32.c
11357@@ -21,6 +21,9 @@
11358 #include <linux/perf_event.h>
11359 #include <linux/interrupt.h>
11360 #include <linux/kdebug.h>
11361+#include <linux/slab.h>
11362+#include <linux/pagemap.h>
11363+#include <linux/compiler.h>
11364
11365 #include <asm/page.h>
11366 #include <asm/pgtable.h>
11367@@ -156,6 +159,277 @@ static unsigned long compute_si_addr(struct pt_regs *regs, int text_fault)
11368 return safe_compute_effective_address(regs, insn);
11369 }
11370
11371+#ifdef CONFIG_PAX_PAGEEXEC
11372+#ifdef CONFIG_PAX_DLRESOLVE
11373+static void pax_emuplt_close(struct vm_area_struct *vma)
11374+{
11375+ vma->vm_mm->call_dl_resolve = 0UL;
11376+}
11377+
11378+static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
11379+{
11380+ unsigned int *kaddr;
11381+
11382+ vmf->page = alloc_page(GFP_HIGHUSER);
11383+ if (!vmf->page)
11384+ return VM_FAULT_OOM;
11385+
11386+ kaddr = kmap(vmf->page);
11387+ memset(kaddr, 0, PAGE_SIZE);
11388+ kaddr[0] = 0x9DE3BFA8U; /* save */
11389+ flush_dcache_page(vmf->page);
11390+ kunmap(vmf->page);
11391+ return VM_FAULT_MAJOR;
11392+}
11393+
11394+static const struct vm_operations_struct pax_vm_ops = {
11395+ .close = pax_emuplt_close,
11396+ .fault = pax_emuplt_fault
11397+};
11398+
11399+static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
11400+{
11401+ int ret;
11402+
11403+ INIT_LIST_HEAD(&vma->anon_vma_chain);
11404+ vma->vm_mm = current->mm;
11405+ vma->vm_start = addr;
11406+ vma->vm_end = addr + PAGE_SIZE;
11407+ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
11408+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
11409+ vma->vm_ops = &pax_vm_ops;
11410+
11411+ ret = insert_vm_struct(current->mm, vma);
11412+ if (ret)
11413+ return ret;
11414+
11415+ ++current->mm->total_vm;
11416+ return 0;
11417+}
11418+#endif
11419+
11420+/*
11421+ * PaX: decide what to do with offenders (regs->pc = fault address)
11422+ *
11423+ * returns 1 when task should be killed
11424+ * 2 when patched PLT trampoline was detected
11425+ * 3 when unpatched PLT trampoline was detected
11426+ */
11427+static int pax_handle_fetch_fault(struct pt_regs *regs)
11428+{
11429+
11430+#ifdef CONFIG_PAX_EMUPLT
11431+ int err;
11432+
11433+ do { /* PaX: patched PLT emulation #1 */
11434+ unsigned int sethi1, sethi2, jmpl;
11435+
11436+ err = get_user(sethi1, (unsigned int *)regs->pc);
11437+ err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
11438+ err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
11439+
11440+ if (err)
11441+ break;
11442+
11443+ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
11444+ (sethi2 & 0xFFC00000U) == 0x03000000U &&
11445+ (jmpl & 0xFFFFE000U) == 0x81C06000U)
11446+ {
11447+ unsigned int addr;
11448+
11449+ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
11450+ addr = regs->u_regs[UREG_G1];
11451+ addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
11452+ regs->pc = addr;
11453+ regs->npc = addr+4;
11454+ return 2;
11455+ }
11456+ } while (0);
11457+
11458+ do { /* PaX: patched PLT emulation #2 */
11459+ unsigned int ba;
11460+
11461+ err = get_user(ba, (unsigned int *)regs->pc);
11462+
11463+ if (err)
11464+ break;
11465+
11466+ if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
11467+ unsigned int addr;
11468+
11469+ if ((ba & 0xFFC00000U) == 0x30800000U)
11470+ addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
11471+ else
11472+ addr = regs->pc + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
11473+ regs->pc = addr;
11474+ regs->npc = addr+4;
11475+ return 2;
11476+ }
11477+ } while (0);
11478+
11479+ do { /* PaX: patched PLT emulation #3 */
11480+ unsigned int sethi, bajmpl, nop;
11481+
11482+ err = get_user(sethi, (unsigned int *)regs->pc);
11483+ err |= get_user(bajmpl, (unsigned int *)(regs->pc+4));
11484+ err |= get_user(nop, (unsigned int *)(regs->pc+8));
11485+
11486+ if (err)
11487+ break;
11488+
11489+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
11490+ ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
11491+ nop == 0x01000000U)
11492+ {
11493+ unsigned int addr;
11494+
11495+ addr = (sethi & 0x003FFFFFU) << 10;
11496+ regs->u_regs[UREG_G1] = addr;
11497+ if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
11498+ addr += (((bajmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
11499+ else
11500+ addr = regs->pc + ((((bajmpl | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
11501+ regs->pc = addr;
11502+ regs->npc = addr+4;
11503+ return 2;
11504+ }
11505+ } while (0);
11506+
11507+ do { /* PaX: unpatched PLT emulation step 1 */
11508+ unsigned int sethi, ba, nop;
11509+
11510+ err = get_user(sethi, (unsigned int *)regs->pc);
11511+ err |= get_user(ba, (unsigned int *)(regs->pc+4));
11512+ err |= get_user(nop, (unsigned int *)(regs->pc+8));
11513+
11514+ if (err)
11515+ break;
11516+
11517+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
11518+ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
11519+ nop == 0x01000000U)
11520+ {
11521+ unsigned int addr, save, call;
11522+
11523+ if ((ba & 0xFFC00000U) == 0x30800000U)
11524+ addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
11525+ else
11526+ addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
11527+
11528+ err = get_user(save, (unsigned int *)addr);
11529+ err |= get_user(call, (unsigned int *)(addr+4));
11530+ err |= get_user(nop, (unsigned int *)(addr+8));
11531+ if (err)
11532+ break;
11533+
11534+#ifdef CONFIG_PAX_DLRESOLVE
11535+ if (save == 0x9DE3BFA8U &&
11536+ (call & 0xC0000000U) == 0x40000000U &&
11537+ nop == 0x01000000U)
11538+ {
11539+ struct vm_area_struct *vma;
11540+ unsigned long call_dl_resolve;
11541+
11542+ down_read(&current->mm->mmap_sem);
11543+ call_dl_resolve = current->mm->call_dl_resolve;
11544+ up_read(&current->mm->mmap_sem);
11545+ if (likely(call_dl_resolve))
11546+ goto emulate;
11547+
11548+ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
11549+
11550+ down_write(&current->mm->mmap_sem);
11551+ if (current->mm->call_dl_resolve) {
11552+ call_dl_resolve = current->mm->call_dl_resolve;
11553+ up_write(&current->mm->mmap_sem);
11554+ if (vma)
11555+ kmem_cache_free(vm_area_cachep, vma);
11556+ goto emulate;
11557+ }
11558+
11559+ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
11560+ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
11561+ up_write(&current->mm->mmap_sem);
11562+ if (vma)
11563+ kmem_cache_free(vm_area_cachep, vma);
11564+ return 1;
11565+ }
11566+
11567+ if (pax_insert_vma(vma, call_dl_resolve)) {
11568+ up_write(&current->mm->mmap_sem);
11569+ kmem_cache_free(vm_area_cachep, vma);
11570+ return 1;
11571+ }
11572+
11573+ current->mm->call_dl_resolve = call_dl_resolve;
11574+ up_write(&current->mm->mmap_sem);
11575+
11576+emulate:
11577+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11578+ regs->pc = call_dl_resolve;
11579+ regs->npc = addr+4;
11580+ return 3;
11581+ }
11582+#endif
11583+
11584+ /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
11585+ if ((save & 0xFFC00000U) == 0x05000000U &&
11586+ (call & 0xFFFFE000U) == 0x85C0A000U &&
11587+ nop == 0x01000000U)
11588+ {
11589+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11590+ regs->u_regs[UREG_G2] = addr + 4;
11591+ addr = (save & 0x003FFFFFU) << 10;
11592+ addr += (((call | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
11593+ regs->pc = addr;
11594+ regs->npc = addr+4;
11595+ return 3;
11596+ }
11597+ }
11598+ } while (0);
11599+
11600+ do { /* PaX: unpatched PLT emulation step 2 */
11601+ unsigned int save, call, nop;
11602+
11603+ err = get_user(save, (unsigned int *)(regs->pc-4));
11604+ err |= get_user(call, (unsigned int *)regs->pc);
11605+ err |= get_user(nop, (unsigned int *)(regs->pc+4));
11606+ if (err)
11607+ break;
11608+
11609+ if (save == 0x9DE3BFA8U &&
11610+ (call & 0xC0000000U) == 0x40000000U &&
11611+ nop == 0x01000000U)
11612+ {
11613+ unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
11614+
11615+ regs->u_regs[UREG_RETPC] = regs->pc;
11616+ regs->pc = dl_resolve;
11617+ regs->npc = dl_resolve+4;
11618+ return 3;
11619+ }
11620+ } while (0);
11621+#endif
11622+
11623+ return 1;
11624+}
11625+
11626+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
11627+{
11628+ unsigned long i;
11629+
11630+ printk(KERN_ERR "PAX: bytes at PC: ");
11631+ for (i = 0; i < 8; i++) {
11632+ unsigned int c;
11633+ if (get_user(c, (unsigned int *)pc+i))
11634+ printk(KERN_CONT "???????? ");
11635+ else
11636+ printk(KERN_CONT "%08x ", c);
11637+ }
11638+ printk("\n");
11639+}
11640+#endif
11641+
11642 static noinline void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
11643 int text_fault)
11644 {
11645@@ -226,6 +500,24 @@ good_area:
11646 if (!(vma->vm_flags & VM_WRITE))
11647 goto bad_area;
11648 } else {
11649+
11650+#ifdef CONFIG_PAX_PAGEEXEC
11651+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
11652+ up_read(&mm->mmap_sem);
11653+ switch (pax_handle_fetch_fault(regs)) {
11654+
11655+#ifdef CONFIG_PAX_EMUPLT
11656+ case 2:
11657+ case 3:
11658+ return;
11659+#endif
11660+
11661+ }
11662+ pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
11663+ do_group_exit(SIGKILL);
11664+ }
11665+#endif
11666+
11667 /* Allow reads even for write-only mappings */
11668 if (!(vma->vm_flags & (VM_READ | VM_EXEC)))
11669 goto bad_area;
11670diff --git a/arch/sparc/mm/fault_64.c b/arch/sparc/mm/fault_64.c
11671index 18fcd71..e4fe821 100644
11672--- a/arch/sparc/mm/fault_64.c
11673+++ b/arch/sparc/mm/fault_64.c
11674@@ -22,6 +22,9 @@
11675 #include <linux/kdebug.h>
11676 #include <linux/percpu.h>
11677 #include <linux/context_tracking.h>
11678+#include <linux/slab.h>
11679+#include <linux/pagemap.h>
11680+#include <linux/compiler.h>
11681
11682 #include <asm/page.h>
11683 #include <asm/pgtable.h>
11684@@ -76,7 +79,7 @@ static void __kprobes bad_kernel_pc(struct pt_regs *regs, unsigned long vaddr)
11685 printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n",
11686 regs->tpc);
11687 printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]);
11688- printk("OOPS: RPC <%pS>\n", (void *) regs->u_regs[15]);
11689+ printk("OOPS: RPC <%pA>\n", (void *) regs->u_regs[15]);
11690 printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr);
11691 dump_stack();
11692 unhandled_fault(regs->tpc, current, regs);
11693@@ -279,6 +282,466 @@ static void noinline __kprobes bogus_32bit_fault_tpc(struct pt_regs *regs)
11694 show_regs(regs);
11695 }
11696
11697+#ifdef CONFIG_PAX_PAGEEXEC
11698+#ifdef CONFIG_PAX_DLRESOLVE
11699+static void pax_emuplt_close(struct vm_area_struct *vma)
11700+{
11701+ vma->vm_mm->call_dl_resolve = 0UL;
11702+}
11703+
11704+static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
11705+{
11706+ unsigned int *kaddr;
11707+
11708+ vmf->page = alloc_page(GFP_HIGHUSER);
11709+ if (!vmf->page)
11710+ return VM_FAULT_OOM;
11711+
11712+ kaddr = kmap(vmf->page);
11713+ memset(kaddr, 0, PAGE_SIZE);
11714+ kaddr[0] = 0x9DE3BFA8U; /* save */
11715+ flush_dcache_page(vmf->page);
11716+ kunmap(vmf->page);
11717+ return VM_FAULT_MAJOR;
11718+}
11719+
11720+static const struct vm_operations_struct pax_vm_ops = {
11721+ .close = pax_emuplt_close,
11722+ .fault = pax_emuplt_fault
11723+};
11724+
11725+static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
11726+{
11727+ int ret;
11728+
11729+ INIT_LIST_HEAD(&vma->anon_vma_chain);
11730+ vma->vm_mm = current->mm;
11731+ vma->vm_start = addr;
11732+ vma->vm_end = addr + PAGE_SIZE;
11733+ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
11734+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
11735+ vma->vm_ops = &pax_vm_ops;
11736+
11737+ ret = insert_vm_struct(current->mm, vma);
11738+ if (ret)
11739+ return ret;
11740+
11741+ ++current->mm->total_vm;
11742+ return 0;
11743+}
11744+#endif
11745+
11746+/*
11747+ * PaX: decide what to do with offenders (regs->tpc = fault address)
11748+ *
11749+ * returns 1 when task should be killed
11750+ * 2 when patched PLT trampoline was detected
11751+ * 3 when unpatched PLT trampoline was detected
11752+ */
11753+static int pax_handle_fetch_fault(struct pt_regs *regs)
11754+{
11755+
11756+#ifdef CONFIG_PAX_EMUPLT
11757+ int err;
11758+
11759+ do { /* PaX: patched PLT emulation #1 */
11760+ unsigned int sethi1, sethi2, jmpl;
11761+
11762+ err = get_user(sethi1, (unsigned int *)regs->tpc);
11763+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
11764+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
11765+
11766+ if (err)
11767+ break;
11768+
11769+ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
11770+ (sethi2 & 0xFFC00000U) == 0x03000000U &&
11771+ (jmpl & 0xFFFFE000U) == 0x81C06000U)
11772+ {
11773+ unsigned long addr;
11774+
11775+ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
11776+ addr = regs->u_regs[UREG_G1];
11777+ addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
11778+
11779+ if (test_thread_flag(TIF_32BIT))
11780+ addr &= 0xFFFFFFFFUL;
11781+
11782+ regs->tpc = addr;
11783+ regs->tnpc = addr+4;
11784+ return 2;
11785+ }
11786+ } while (0);
11787+
11788+ do { /* PaX: patched PLT emulation #2 */
11789+ unsigned int ba;
11790+
11791+ err = get_user(ba, (unsigned int *)regs->tpc);
11792+
11793+ if (err)
11794+ break;
11795+
11796+ if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
11797+ unsigned long addr;
11798+
11799+ if ((ba & 0xFFC00000U) == 0x30800000U)
11800+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
11801+ else
11802+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
11803+
11804+ if (test_thread_flag(TIF_32BIT))
11805+ addr &= 0xFFFFFFFFUL;
11806+
11807+ regs->tpc = addr;
11808+ regs->tnpc = addr+4;
11809+ return 2;
11810+ }
11811+ } while (0);
11812+
11813+ do { /* PaX: patched PLT emulation #3 */
11814+ unsigned int sethi, bajmpl, nop;
11815+
11816+ err = get_user(sethi, (unsigned int *)regs->tpc);
11817+ err |= get_user(bajmpl, (unsigned int *)(regs->tpc+4));
11818+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
11819+
11820+ if (err)
11821+ break;
11822+
11823+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
11824+ ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
11825+ nop == 0x01000000U)
11826+ {
11827+ unsigned long addr;
11828+
11829+ addr = (sethi & 0x003FFFFFU) << 10;
11830+ regs->u_regs[UREG_G1] = addr;
11831+ if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
11832+ addr += (((bajmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
11833+ else
11834+ addr = regs->tpc + ((((bajmpl | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
11835+
11836+ if (test_thread_flag(TIF_32BIT))
11837+ addr &= 0xFFFFFFFFUL;
11838+
11839+ regs->tpc = addr;
11840+ regs->tnpc = addr+4;
11841+ return 2;
11842+ }
11843+ } while (0);
11844+
11845+ do { /* PaX: patched PLT emulation #4 */
11846+ unsigned int sethi, mov1, call, mov2;
11847+
11848+ err = get_user(sethi, (unsigned int *)regs->tpc);
11849+ err |= get_user(mov1, (unsigned int *)(regs->tpc+4));
11850+ err |= get_user(call, (unsigned int *)(regs->tpc+8));
11851+ err |= get_user(mov2, (unsigned int *)(regs->tpc+12));
11852+
11853+ if (err)
11854+ break;
11855+
11856+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
11857+ mov1 == 0x8210000FU &&
11858+ (call & 0xC0000000U) == 0x40000000U &&
11859+ mov2 == 0x9E100001U)
11860+ {
11861+ unsigned long addr;
11862+
11863+ regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
11864+ addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
11865+
11866+ if (test_thread_flag(TIF_32BIT))
11867+ addr &= 0xFFFFFFFFUL;
11868+
11869+ regs->tpc = addr;
11870+ regs->tnpc = addr+4;
11871+ return 2;
11872+ }
11873+ } while (0);
11874+
11875+ do { /* PaX: patched PLT emulation #5 */
11876+ unsigned int sethi, sethi1, sethi2, or1, or2, sllx, jmpl, nop;
11877+
11878+ err = get_user(sethi, (unsigned int *)regs->tpc);
11879+ err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
11880+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
11881+ err |= get_user(or1, (unsigned int *)(regs->tpc+12));
11882+ err |= get_user(or2, (unsigned int *)(regs->tpc+16));
11883+ err |= get_user(sllx, (unsigned int *)(regs->tpc+20));
11884+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+24));
11885+ err |= get_user(nop, (unsigned int *)(regs->tpc+28));
11886+
11887+ if (err)
11888+ break;
11889+
11890+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
11891+ (sethi1 & 0xFFC00000U) == 0x03000000U &&
11892+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
11893+ (or1 & 0xFFFFE000U) == 0x82106000U &&
11894+ (or2 & 0xFFFFE000U) == 0x8A116000U &&
11895+ sllx == 0x83287020U &&
11896+ jmpl == 0x81C04005U &&
11897+ nop == 0x01000000U)
11898+ {
11899+ unsigned long addr;
11900+
11901+ regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
11902+ regs->u_regs[UREG_G1] <<= 32;
11903+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
11904+ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
11905+ regs->tpc = addr;
11906+ regs->tnpc = addr+4;
11907+ return 2;
11908+ }
11909+ } while (0);
11910+
11911+ do { /* PaX: patched PLT emulation #6 */
11912+ unsigned int sethi, sethi1, sethi2, sllx, or, jmpl, nop;
11913+
11914+ err = get_user(sethi, (unsigned int *)regs->tpc);
11915+ err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
11916+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
11917+ err |= get_user(sllx, (unsigned int *)(regs->tpc+12));
11918+ err |= get_user(or, (unsigned int *)(regs->tpc+16));
11919+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
11920+ err |= get_user(nop, (unsigned int *)(regs->tpc+24));
11921+
11922+ if (err)
11923+ break;
11924+
11925+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
11926+ (sethi1 & 0xFFC00000U) == 0x03000000U &&
11927+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
11928+ sllx == 0x83287020U &&
11929+ (or & 0xFFFFE000U) == 0x8A116000U &&
11930+ jmpl == 0x81C04005U &&
11931+ nop == 0x01000000U)
11932+ {
11933+ unsigned long addr;
11934+
11935+ regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
11936+ regs->u_regs[UREG_G1] <<= 32;
11937+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
11938+ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
11939+ regs->tpc = addr;
11940+ regs->tnpc = addr+4;
11941+ return 2;
11942+ }
11943+ } while (0);
11944+
11945+ do { /* PaX: unpatched PLT emulation step 1 */
11946+ unsigned int sethi, ba, nop;
11947+
11948+ err = get_user(sethi, (unsigned int *)regs->tpc);
11949+ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
11950+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
11951+
11952+ if (err)
11953+ break;
11954+
11955+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
11956+ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
11957+ nop == 0x01000000U)
11958+ {
11959+ unsigned long addr;
11960+ unsigned int save, call;
11961+ unsigned int sethi1, sethi2, or1, or2, sllx, add, jmpl;
11962+
11963+ if ((ba & 0xFFC00000U) == 0x30800000U)
11964+ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
11965+ else
11966+ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
11967+
11968+ if (test_thread_flag(TIF_32BIT))
11969+ addr &= 0xFFFFFFFFUL;
11970+
11971+ err = get_user(save, (unsigned int *)addr);
11972+ err |= get_user(call, (unsigned int *)(addr+4));
11973+ err |= get_user(nop, (unsigned int *)(addr+8));
11974+ if (err)
11975+ break;
11976+
11977+#ifdef CONFIG_PAX_DLRESOLVE
11978+ if (save == 0x9DE3BFA8U &&
11979+ (call & 0xC0000000U) == 0x40000000U &&
11980+ nop == 0x01000000U)
11981+ {
11982+ struct vm_area_struct *vma;
11983+ unsigned long call_dl_resolve;
11984+
11985+ down_read(&current->mm->mmap_sem);
11986+ call_dl_resolve = current->mm->call_dl_resolve;
11987+ up_read(&current->mm->mmap_sem);
11988+ if (likely(call_dl_resolve))
11989+ goto emulate;
11990+
11991+ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
11992+
11993+ down_write(&current->mm->mmap_sem);
11994+ if (current->mm->call_dl_resolve) {
11995+ call_dl_resolve = current->mm->call_dl_resolve;
11996+ up_write(&current->mm->mmap_sem);
11997+ if (vma)
11998+ kmem_cache_free(vm_area_cachep, vma);
11999+ goto emulate;
12000+ }
12001+
12002+ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
12003+ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
12004+ up_write(&current->mm->mmap_sem);
12005+ if (vma)
12006+ kmem_cache_free(vm_area_cachep, vma);
12007+ return 1;
12008+ }
12009+
12010+ if (pax_insert_vma(vma, call_dl_resolve)) {
12011+ up_write(&current->mm->mmap_sem);
12012+ kmem_cache_free(vm_area_cachep, vma);
12013+ return 1;
12014+ }
12015+
12016+ current->mm->call_dl_resolve = call_dl_resolve;
12017+ up_write(&current->mm->mmap_sem);
12018+
12019+emulate:
12020+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
12021+ regs->tpc = call_dl_resolve;
12022+ regs->tnpc = addr+4;
12023+ return 3;
12024+ }
12025+#endif
12026+
12027+ /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
12028+ if ((save & 0xFFC00000U) == 0x05000000U &&
12029+ (call & 0xFFFFE000U) == 0x85C0A000U &&
12030+ nop == 0x01000000U)
12031+ {
12032+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
12033+ regs->u_regs[UREG_G2] = addr + 4;
12034+ addr = (save & 0x003FFFFFU) << 10;
12035+ addr += (((call | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
12036+
12037+ if (test_thread_flag(TIF_32BIT))
12038+ addr &= 0xFFFFFFFFUL;
12039+
12040+ regs->tpc = addr;
12041+ regs->tnpc = addr+4;
12042+ return 3;
12043+ }
12044+
12045+ /* PaX: 64-bit PLT stub */
12046+ err = get_user(sethi1, (unsigned int *)addr);
12047+ err |= get_user(sethi2, (unsigned int *)(addr+4));
12048+ err |= get_user(or1, (unsigned int *)(addr+8));
12049+ err |= get_user(or2, (unsigned int *)(addr+12));
12050+ err |= get_user(sllx, (unsigned int *)(addr+16));
12051+ err |= get_user(add, (unsigned int *)(addr+20));
12052+ err |= get_user(jmpl, (unsigned int *)(addr+24));
12053+ err |= get_user(nop, (unsigned int *)(addr+28));
12054+ if (err)
12055+ break;
12056+
12057+ if ((sethi1 & 0xFFC00000U) == 0x09000000U &&
12058+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
12059+ (or1 & 0xFFFFE000U) == 0x88112000U &&
12060+ (or2 & 0xFFFFE000U) == 0x8A116000U &&
12061+ sllx == 0x89293020U &&
12062+ add == 0x8A010005U &&
12063+ jmpl == 0x89C14000U &&
12064+ nop == 0x01000000U)
12065+ {
12066+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
12067+ regs->u_regs[UREG_G4] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
12068+ regs->u_regs[UREG_G4] <<= 32;
12069+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
12070+ regs->u_regs[UREG_G5] += regs->u_regs[UREG_G4];
12071+ regs->u_regs[UREG_G4] = addr + 24;
12072+ addr = regs->u_regs[UREG_G5];
12073+ regs->tpc = addr;
12074+ regs->tnpc = addr+4;
12075+ return 3;
12076+ }
12077+ }
12078+ } while (0);
12079+
12080+#ifdef CONFIG_PAX_DLRESOLVE
12081+ do { /* PaX: unpatched PLT emulation step 2 */
12082+ unsigned int save, call, nop;
12083+
12084+ err = get_user(save, (unsigned int *)(regs->tpc-4));
12085+ err |= get_user(call, (unsigned int *)regs->tpc);
12086+ err |= get_user(nop, (unsigned int *)(regs->tpc+4));
12087+ if (err)
12088+ break;
12089+
12090+ if (save == 0x9DE3BFA8U &&
12091+ (call & 0xC0000000U) == 0x40000000U &&
12092+ nop == 0x01000000U)
12093+ {
12094+ unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
12095+
12096+ if (test_thread_flag(TIF_32BIT))
12097+ dl_resolve &= 0xFFFFFFFFUL;
12098+
12099+ regs->u_regs[UREG_RETPC] = regs->tpc;
12100+ regs->tpc = dl_resolve;
12101+ regs->tnpc = dl_resolve+4;
12102+ return 3;
12103+ }
12104+ } while (0);
12105+#endif
12106+
12107+ do { /* PaX: patched PLT emulation #7, must be AFTER the unpatched PLT emulation */
12108+ unsigned int sethi, ba, nop;
12109+
12110+ err = get_user(sethi, (unsigned int *)regs->tpc);
12111+ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
12112+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
12113+
12114+ if (err)
12115+ break;
12116+
12117+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
12118+ (ba & 0xFFF00000U) == 0x30600000U &&
12119+ nop == 0x01000000U)
12120+ {
12121+ unsigned long addr;
12122+
12123+ addr = (sethi & 0x003FFFFFU) << 10;
12124+ regs->u_regs[UREG_G1] = addr;
12125+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
12126+
12127+ if (test_thread_flag(TIF_32BIT))
12128+ addr &= 0xFFFFFFFFUL;
12129+
12130+ regs->tpc = addr;
12131+ regs->tnpc = addr+4;
12132+ return 2;
12133+ }
12134+ } while (0);
12135+
12136+#endif
12137+
12138+ return 1;
12139+}
12140+
12141+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
12142+{
12143+ unsigned long i;
12144+
12145+ printk(KERN_ERR "PAX: bytes at PC: ");
12146+ for (i = 0; i < 8; i++) {
12147+ unsigned int c;
12148+ if (get_user(c, (unsigned int *)pc+i))
12149+ printk(KERN_CONT "???????? ");
12150+ else
12151+ printk(KERN_CONT "%08x ", c);
12152+ }
12153+ printk("\n");
12154+}
12155+#endif
12156+
12157 asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
12158 {
12159 enum ctx_state prev_state = exception_enter();
12160@@ -353,6 +816,29 @@ retry:
12161 if (!vma)
12162 goto bad_area;
12163
12164+#ifdef CONFIG_PAX_PAGEEXEC
12165+ /* PaX: detect ITLB misses on non-exec pages */
12166+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
12167+ !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
12168+ {
12169+ if (address != regs->tpc)
12170+ goto good_area;
12171+
12172+ up_read(&mm->mmap_sem);
12173+ switch (pax_handle_fetch_fault(regs)) {
12174+
12175+#ifdef CONFIG_PAX_EMUPLT
12176+ case 2:
12177+ case 3:
12178+ return;
12179+#endif
12180+
12181+ }
12182+ pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
12183+ do_group_exit(SIGKILL);
12184+ }
12185+#endif
12186+
12187 /* Pure DTLB misses do not tell us whether the fault causing
12188 * load/store/atomic was a write or not, it only says that there
12189 * was no match. So in such a case we (carefully) read the
12190diff --git a/arch/sparc/mm/hugetlbpage.c b/arch/sparc/mm/hugetlbpage.c
12191index d329537..2c3746a 100644
12192--- a/arch/sparc/mm/hugetlbpage.c
12193+++ b/arch/sparc/mm/hugetlbpage.c
12194@@ -25,8 +25,10 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
12195 unsigned long addr,
12196 unsigned long len,
12197 unsigned long pgoff,
12198- unsigned long flags)
12199+ unsigned long flags,
12200+ unsigned long offset)
12201 {
12202+ struct mm_struct *mm = current->mm;
12203 unsigned long task_size = TASK_SIZE;
12204 struct vm_unmapped_area_info info;
12205
12206@@ -35,15 +37,22 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
12207
12208 info.flags = 0;
12209 info.length = len;
12210- info.low_limit = TASK_UNMAPPED_BASE;
12211+ info.low_limit = mm->mmap_base;
12212 info.high_limit = min(task_size, VA_EXCLUDE_START);
12213 info.align_mask = PAGE_MASK & ~HPAGE_MASK;
12214 info.align_offset = 0;
12215+ info.threadstack_offset = offset;
12216 addr = vm_unmapped_area(&info);
12217
12218 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
12219 VM_BUG_ON(addr != -ENOMEM);
12220 info.low_limit = VA_EXCLUDE_END;
12221+
12222+#ifdef CONFIG_PAX_RANDMMAP
12223+ if (mm->pax_flags & MF_PAX_RANDMMAP)
12224+ info.low_limit += mm->delta_mmap;
12225+#endif
12226+
12227 info.high_limit = task_size;
12228 addr = vm_unmapped_area(&info);
12229 }
12230@@ -55,7 +64,8 @@ static unsigned long
12231 hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
12232 const unsigned long len,
12233 const unsigned long pgoff,
12234- const unsigned long flags)
12235+ const unsigned long flags,
12236+ const unsigned long offset)
12237 {
12238 struct mm_struct *mm = current->mm;
12239 unsigned long addr = addr0;
12240@@ -70,6 +80,7 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
12241 info.high_limit = mm->mmap_base;
12242 info.align_mask = PAGE_MASK & ~HPAGE_MASK;
12243 info.align_offset = 0;
12244+ info.threadstack_offset = offset;
12245 addr = vm_unmapped_area(&info);
12246
12247 /*
12248@@ -82,6 +93,12 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
12249 VM_BUG_ON(addr != -ENOMEM);
12250 info.flags = 0;
12251 info.low_limit = TASK_UNMAPPED_BASE;
12252+
12253+#ifdef CONFIG_PAX_RANDMMAP
12254+ if (mm->pax_flags & MF_PAX_RANDMMAP)
12255+ info.low_limit += mm->delta_mmap;
12256+#endif
12257+
12258 info.high_limit = STACK_TOP32;
12259 addr = vm_unmapped_area(&info);
12260 }
12261@@ -96,6 +113,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
12262 struct mm_struct *mm = current->mm;
12263 struct vm_area_struct *vma;
12264 unsigned long task_size = TASK_SIZE;
12265+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
12266
12267 if (test_thread_flag(TIF_32BIT))
12268 task_size = STACK_TOP32;
12269@@ -111,19 +129,22 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
12270 return addr;
12271 }
12272
12273+#ifdef CONFIG_PAX_RANDMMAP
12274+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
12275+#endif
12276+
12277 if (addr) {
12278 addr = ALIGN(addr, HPAGE_SIZE);
12279 vma = find_vma(mm, addr);
12280- if (task_size - len >= addr &&
12281- (!vma || addr + len <= vma->vm_start))
12282+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
12283 return addr;
12284 }
12285 if (mm->get_unmapped_area == arch_get_unmapped_area)
12286 return hugetlb_get_unmapped_area_bottomup(file, addr, len,
12287- pgoff, flags);
12288+ pgoff, flags, offset);
12289 else
12290 return hugetlb_get_unmapped_area_topdown(file, addr, len,
12291- pgoff, flags);
12292+ pgoff, flags, offset);
12293 }
12294
12295 pte_t *huge_pte_alloc(struct mm_struct *mm,
12296diff --git a/arch/sparc/mm/init_64.c b/arch/sparc/mm/init_64.c
12297index 2d91c62..17a8fff 100644
12298--- a/arch/sparc/mm/init_64.c
12299+++ b/arch/sparc/mm/init_64.c
12300@@ -186,9 +186,9 @@ unsigned long sparc64_kern_sec_context __read_mostly;
12301 int num_kernel_image_mappings;
12302
12303 #ifdef CONFIG_DEBUG_DCFLUSH
12304-atomic_t dcpage_flushes = ATOMIC_INIT(0);
12305+atomic_unchecked_t dcpage_flushes = ATOMIC_INIT(0);
12306 #ifdef CONFIG_SMP
12307-atomic_t dcpage_flushes_xcall = ATOMIC_INIT(0);
12308+atomic_unchecked_t dcpage_flushes_xcall = ATOMIC_INIT(0);
12309 #endif
12310 #endif
12311
12312@@ -196,7 +196,7 @@ inline void flush_dcache_page_impl(struct page *page)
12313 {
12314 BUG_ON(tlb_type == hypervisor);
12315 #ifdef CONFIG_DEBUG_DCFLUSH
12316- atomic_inc(&dcpage_flushes);
12317+ atomic_inc_unchecked(&dcpage_flushes);
12318 #endif
12319
12320 #ifdef DCACHE_ALIASING_POSSIBLE
12321@@ -468,10 +468,10 @@ void mmu_info(struct seq_file *m)
12322
12323 #ifdef CONFIG_DEBUG_DCFLUSH
12324 seq_printf(m, "DCPageFlushes\t: %d\n",
12325- atomic_read(&dcpage_flushes));
12326+ atomic_read_unchecked(&dcpage_flushes));
12327 #ifdef CONFIG_SMP
12328 seq_printf(m, "DCPageFlushesXC\t: %d\n",
12329- atomic_read(&dcpage_flushes_xcall));
12330+ atomic_read_unchecked(&dcpage_flushes_xcall));
12331 #endif /* CONFIG_SMP */
12332 #endif /* CONFIG_DEBUG_DCFLUSH */
12333 }
12334diff --git a/arch/tile/Kconfig b/arch/tile/Kconfig
12335index 7cca418..53fc030 100644
12336--- a/arch/tile/Kconfig
12337+++ b/arch/tile/Kconfig
12338@@ -192,6 +192,7 @@ source "kernel/Kconfig.hz"
12339
12340 config KEXEC
12341 bool "kexec system call"
12342+ depends on !GRKERNSEC_KMEM
12343 ---help---
12344 kexec is a system call that implements the ability to shutdown your
12345 current kernel, and to start another kernel. It is like a reboot
12346diff --git a/arch/tile/include/asm/atomic_64.h b/arch/tile/include/asm/atomic_64.h
12347index 7b11c5f..755a026 100644
12348--- a/arch/tile/include/asm/atomic_64.h
12349+++ b/arch/tile/include/asm/atomic_64.h
12350@@ -105,6 +105,16 @@ static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
12351
12352 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
12353
12354+#define atomic64_read_unchecked(v) atomic64_read(v)
12355+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
12356+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
12357+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
12358+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
12359+#define atomic64_inc_unchecked(v) atomic64_inc(v)
12360+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
12361+#define atomic64_dec_unchecked(v) atomic64_dec(v)
12362+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
12363+
12364 /* Define this to indicate that cmpxchg is an efficient operation. */
12365 #define __HAVE_ARCH_CMPXCHG
12366
12367diff --git a/arch/tile/include/asm/cache.h b/arch/tile/include/asm/cache.h
12368index 6160761..00cac88 100644
12369--- a/arch/tile/include/asm/cache.h
12370+++ b/arch/tile/include/asm/cache.h
12371@@ -15,11 +15,12 @@
12372 #ifndef _ASM_TILE_CACHE_H
12373 #define _ASM_TILE_CACHE_H
12374
12375+#include <linux/const.h>
12376 #include <arch/chip.h>
12377
12378 /* bytes per L1 data cache line */
12379 #define L1_CACHE_SHIFT CHIP_L1D_LOG_LINE_SIZE()
12380-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
12381+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
12382
12383 /* bytes per L2 cache line */
12384 #define L2_CACHE_SHIFT CHIP_L2_LOG_LINE_SIZE()
12385diff --git a/arch/tile/include/asm/uaccess.h b/arch/tile/include/asm/uaccess.h
12386index b6cde32..c0cb736 100644
12387--- a/arch/tile/include/asm/uaccess.h
12388+++ b/arch/tile/include/asm/uaccess.h
12389@@ -414,9 +414,9 @@ static inline unsigned long __must_check copy_from_user(void *to,
12390 const void __user *from,
12391 unsigned long n)
12392 {
12393- int sz = __compiletime_object_size(to);
12394+ size_t sz = __compiletime_object_size(to);
12395
12396- if (likely(sz == -1 || sz >= n))
12397+ if (likely(sz == (size_t)-1 || sz >= n))
12398 n = _copy_from_user(to, from, n);
12399 else
12400 copy_from_user_overflow();
12401diff --git a/arch/tile/mm/hugetlbpage.c b/arch/tile/mm/hugetlbpage.c
12402index e514899..f8743c4 100644
12403--- a/arch/tile/mm/hugetlbpage.c
12404+++ b/arch/tile/mm/hugetlbpage.c
12405@@ -207,6 +207,7 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
12406 info.high_limit = TASK_SIZE;
12407 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
12408 info.align_offset = 0;
12409+ info.threadstack_offset = 0;
12410 return vm_unmapped_area(&info);
12411 }
12412
12413@@ -224,6 +225,7 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
12414 info.high_limit = current->mm->mmap_base;
12415 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
12416 info.align_offset = 0;
12417+ info.threadstack_offset = 0;
12418 addr = vm_unmapped_area(&info);
12419
12420 /*
12421diff --git a/arch/um/Makefile b/arch/um/Makefile
12422index e4b1a96..16162f8 100644
12423--- a/arch/um/Makefile
12424+++ b/arch/um/Makefile
12425@@ -72,6 +72,10 @@ USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -D__KERNEL__,,\
12426 $(patsubst -I%,,$(KBUILD_CFLAGS)))) $(ARCH_INCLUDE) $(MODE_INCLUDE) \
12427 $(filter -I%,$(CFLAGS)) -D_FILE_OFFSET_BITS=64 -idirafter include
12428
12429+ifdef CONSTIFY_PLUGIN
12430+USER_CFLAGS += -fplugin-arg-constify_plugin-no-constify
12431+endif
12432+
12433 #This will adjust *FLAGS accordingly to the platform.
12434 include $(srctree)/$(ARCH_DIR)/Makefile-os-$(OS)
12435
12436diff --git a/arch/um/include/asm/cache.h b/arch/um/include/asm/cache.h
12437index 19e1bdd..3665b77 100644
12438--- a/arch/um/include/asm/cache.h
12439+++ b/arch/um/include/asm/cache.h
12440@@ -1,6 +1,7 @@
12441 #ifndef __UM_CACHE_H
12442 #define __UM_CACHE_H
12443
12444+#include <linux/const.h>
12445
12446 #if defined(CONFIG_UML_X86) && !defined(CONFIG_64BIT)
12447 # define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
12448@@ -12,6 +13,6 @@
12449 # define L1_CACHE_SHIFT 5
12450 #endif
12451
12452-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
12453+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
12454
12455 #endif
12456diff --git a/arch/um/include/asm/kmap_types.h b/arch/um/include/asm/kmap_types.h
12457index 2e0a6b1..a64d0f5 100644
12458--- a/arch/um/include/asm/kmap_types.h
12459+++ b/arch/um/include/asm/kmap_types.h
12460@@ -8,6 +8,6 @@
12461
12462 /* No more #include "asm/arch/kmap_types.h" ! */
12463
12464-#define KM_TYPE_NR 14
12465+#define KM_TYPE_NR 15
12466
12467 #endif
12468diff --git a/arch/um/include/asm/page.h b/arch/um/include/asm/page.h
12469index 71c5d13..4c7b9f1 100644
12470--- a/arch/um/include/asm/page.h
12471+++ b/arch/um/include/asm/page.h
12472@@ -14,6 +14,9 @@
12473 #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
12474 #define PAGE_MASK (~(PAGE_SIZE-1))
12475
12476+#define ktla_ktva(addr) (addr)
12477+#define ktva_ktla(addr) (addr)
12478+
12479 #ifndef __ASSEMBLY__
12480
12481 struct page;
12482diff --git a/arch/um/include/asm/pgtable-3level.h b/arch/um/include/asm/pgtable-3level.h
12483index 0032f92..cd151e0 100644
12484--- a/arch/um/include/asm/pgtable-3level.h
12485+++ b/arch/um/include/asm/pgtable-3level.h
12486@@ -58,6 +58,7 @@
12487 #define pud_present(x) (pud_val(x) & _PAGE_PRESENT)
12488 #define pud_populate(mm, pud, pmd) \
12489 set_pud(pud, __pud(_PAGE_TABLE + __pa(pmd)))
12490+#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
12491
12492 #ifdef CONFIG_64BIT
12493 #define set_pud(pudptr, pudval) set_64bit((u64 *) (pudptr), pud_val(pudval))
12494diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c
12495index f17bca8..48adb87 100644
12496--- a/arch/um/kernel/process.c
12497+++ b/arch/um/kernel/process.c
12498@@ -356,22 +356,6 @@ int singlestepping(void * t)
12499 return 2;
12500 }
12501
12502-/*
12503- * Only x86 and x86_64 have an arch_align_stack().
12504- * All other arches have "#define arch_align_stack(x) (x)"
12505- * in their asm/exec.h
12506- * As this is included in UML from asm-um/system-generic.h,
12507- * we can use it to behave as the subarch does.
12508- */
12509-#ifndef arch_align_stack
12510-unsigned long arch_align_stack(unsigned long sp)
12511-{
12512- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
12513- sp -= get_random_int() % 8192;
12514- return sp & ~0xf;
12515-}
12516-#endif
12517-
12518 unsigned long get_wchan(struct task_struct *p)
12519 {
12520 unsigned long stack_page, sp, ip;
12521diff --git a/arch/unicore32/include/asm/cache.h b/arch/unicore32/include/asm/cache.h
12522index ad8f795..2c7eec6 100644
12523--- a/arch/unicore32/include/asm/cache.h
12524+++ b/arch/unicore32/include/asm/cache.h
12525@@ -12,8 +12,10 @@
12526 #ifndef __UNICORE_CACHE_H__
12527 #define __UNICORE_CACHE_H__
12528
12529-#define L1_CACHE_SHIFT (5)
12530-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
12531+#include <linux/const.h>
12532+
12533+#define L1_CACHE_SHIFT 5
12534+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
12535
12536 /*
12537 * Memory returned by kmalloc() may be used for DMA, so we must make
12538diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
12539index 41a503c..cf98b04 100644
12540--- a/arch/x86/Kconfig
12541+++ b/arch/x86/Kconfig
12542@@ -129,7 +129,7 @@ config X86
12543 select RTC_LIB
12544 select HAVE_DEBUG_STACKOVERFLOW
12545 select HAVE_IRQ_EXIT_ON_IRQ_STACK if X86_64
12546- select HAVE_CC_STACKPROTECTOR
12547+ select HAVE_CC_STACKPROTECTOR if X86_64 || !PAX_MEMORY_UDEREF
12548 select GENERIC_CPU_AUTOPROBE
12549 select HAVE_ARCH_AUDITSYSCALL
12550 select ARCH_SUPPORTS_ATOMIC_RMW
12551@@ -262,7 +262,7 @@ config X86_HT
12552
12553 config X86_32_LAZY_GS
12554 def_bool y
12555- depends on X86_32 && !CC_STACKPROTECTOR
12556+ depends on X86_32 && !CC_STACKPROTECTOR && !PAX_MEMORY_UDEREF
12557
12558 config ARCH_HWEIGHT_CFLAGS
12559 string
12560@@ -600,6 +600,7 @@ config SCHED_OMIT_FRAME_POINTER
12561
12562 menuconfig HYPERVISOR_GUEST
12563 bool "Linux guest support"
12564+ depends on !GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_VIRT_GUEST || (GRKERNSEC_CONFIG_VIRT_HOST && GRKERNSEC_CONFIG_VIRT_XEN)
12565 ---help---
12566 Say Y here to enable options for running Linux under various hyper-
12567 visors. This option enables basic hypervisor detection and platform
12568@@ -973,6 +974,7 @@ config VM86
12569
12570 config X86_16BIT
12571 bool "Enable support for 16-bit segments" if EXPERT
12572+ depends on !GRKERNSEC
12573 default y
12574 ---help---
12575 This option is required by programs like Wine to run 16-bit
12576@@ -1128,6 +1130,7 @@ choice
12577
12578 config NOHIGHMEM
12579 bool "off"
12580+ depends on !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
12581 ---help---
12582 Linux can use up to 64 Gigabytes of physical memory on x86 systems.
12583 However, the address space of 32-bit x86 processors is only 4
12584@@ -1164,6 +1167,7 @@ config NOHIGHMEM
12585
12586 config HIGHMEM4G
12587 bool "4GB"
12588+ depends on !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
12589 ---help---
12590 Select this if you have a 32-bit processor and between 1 and 4
12591 gigabytes of physical RAM.
12592@@ -1216,7 +1220,7 @@ config PAGE_OFFSET
12593 hex
12594 default 0xB0000000 if VMSPLIT_3G_OPT
12595 default 0x80000000 if VMSPLIT_2G
12596- default 0x78000000 if VMSPLIT_2G_OPT
12597+ default 0x70000000 if VMSPLIT_2G_OPT
12598 default 0x40000000 if VMSPLIT_1G
12599 default 0xC0000000
12600 depends on X86_32
12601@@ -1631,6 +1635,7 @@ source kernel/Kconfig.hz
12602
12603 config KEXEC
12604 bool "kexec system call"
12605+ depends on !GRKERNSEC_KMEM
12606 ---help---
12607 kexec is a system call that implements the ability to shutdown your
12608 current kernel, and to start another kernel. It is like a reboot
12609@@ -1816,7 +1821,9 @@ config X86_NEED_RELOCS
12610
12611 config PHYSICAL_ALIGN
12612 hex "Alignment value to which kernel should be aligned"
12613- default "0x200000"
12614+ default "0x1000000"
12615+ range 0x200000 0x1000000 if PAX_KERNEXEC && X86_PAE
12616+ range 0x400000 0x1000000 if PAX_KERNEXEC && !X86_PAE
12617 range 0x2000 0x1000000 if X86_32
12618 range 0x200000 0x1000000 if X86_64
12619 ---help---
12620@@ -1899,6 +1906,7 @@ config COMPAT_VDSO
12621 def_bool n
12622 prompt "Disable the 32-bit vDSO (needed for glibc 2.3.3)"
12623 depends on X86_32 || IA32_EMULATION
12624+ depends on !PAX_PAGEEXEC && !PAX_SEGMEXEC && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
12625 ---help---
12626 Certain buggy versions of glibc will crash if they are
12627 presented with a 32-bit vDSO that is not mapped at the address
12628diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
12629index 6983314..54ad7e8 100644
12630--- a/arch/x86/Kconfig.cpu
12631+++ b/arch/x86/Kconfig.cpu
12632@@ -319,7 +319,7 @@ config X86_PPRO_FENCE
12633
12634 config X86_F00F_BUG
12635 def_bool y
12636- depends on M586MMX || M586TSC || M586 || M486
12637+ depends on (M586MMX || M586TSC || M586 || M486) && !PAX_KERNEXEC
12638
12639 config X86_INVD_BUG
12640 def_bool y
12641@@ -327,7 +327,7 @@ config X86_INVD_BUG
12642
12643 config X86_ALIGNMENT_16
12644 def_bool y
12645- depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || MELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
12646+ depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
12647
12648 config X86_INTEL_USERCOPY
12649 def_bool y
12650@@ -369,7 +369,7 @@ config X86_CMPXCHG64
12651 # generates cmov.
12652 config X86_CMOV
12653 def_bool y
12654- depends on (MK8 || MK7 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
12655+ depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
12656
12657 config X86_MINIMUM_CPU_FAMILY
12658 int
12659diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug
12660index 61bd2ad..50b625d 100644
12661--- a/arch/x86/Kconfig.debug
12662+++ b/arch/x86/Kconfig.debug
12663@@ -93,7 +93,7 @@ config EFI_PGT_DUMP
12664 config DEBUG_RODATA
12665 bool "Write protect kernel read-only data structures"
12666 default y
12667- depends on DEBUG_KERNEL
12668+ depends on DEBUG_KERNEL && BROKEN
12669 ---help---
12670 Mark the kernel read-only data as write-protected in the pagetables,
12671 in order to catch accidental (and incorrect) writes to such const
12672@@ -111,7 +111,7 @@ config DEBUG_RODATA_TEST
12673
12674 config DEBUG_SET_MODULE_RONX
12675 bool "Set loadable kernel module data as NX and text as RO"
12676- depends on MODULES
12677+ depends on MODULES && BROKEN
12678 ---help---
12679 This option helps catch unintended modifications to loadable
12680 kernel module's text and read-only data. It also prevents execution
12681diff --git a/arch/x86/Makefile b/arch/x86/Makefile
12682index 920e616..ac3d4df 100644
12683--- a/arch/x86/Makefile
12684+++ b/arch/x86/Makefile
12685@@ -65,9 +65,6 @@ ifeq ($(CONFIG_X86_32),y)
12686 # CPU-specific tuning. Anything which can be shared with UML should go here.
12687 include $(srctree)/arch/x86/Makefile_32.cpu
12688 KBUILD_CFLAGS += $(cflags-y)
12689-
12690- # temporary until string.h is fixed
12691- KBUILD_CFLAGS += -ffreestanding
12692 else
12693 BITS := 64
12694 UTS_MACHINE := x86_64
12695@@ -107,6 +104,9 @@ else
12696 KBUILD_CFLAGS += $(call cc-option,-maccumulate-outgoing-args)
12697 endif
12698
12699+# temporary until string.h is fixed
12700+KBUILD_CFLAGS += -ffreestanding
12701+
12702 # Make sure compiler does not have buggy stack-protector support.
12703 ifdef CONFIG_CC_STACKPROTECTOR
12704 cc_has_sp := $(srctree)/scripts/gcc-x86_$(BITS)-has-stack-protector.sh
12705@@ -180,6 +180,7 @@ archheaders:
12706 $(Q)$(MAKE) $(build)=arch/x86/syscalls all
12707
12708 archprepare:
12709+ $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
12710 ifeq ($(CONFIG_KEXEC_FILE),y)
12711 $(Q)$(MAKE) $(build)=arch/x86/purgatory arch/x86/purgatory/kexec-purgatory.c
12712 endif
12713@@ -263,3 +264,9 @@ define archhelp
12714 echo ' FDARGS="..." arguments for the booted kernel'
12715 echo ' FDINITRD=file initrd for the booted kernel'
12716 endef
12717+
12718+define OLD_LD
12719+
12720+*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
12721+*** Please upgrade your binutils to 2.18 or newer
12722+endef
12723diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
12724index 5b016e2..04ef69c 100644
12725--- a/arch/x86/boot/Makefile
12726+++ b/arch/x86/boot/Makefile
12727@@ -55,6 +55,9 @@ endif
12728 # ---------------------------------------------------------------------------
12729
12730 KBUILD_CFLAGS := $(USERINCLUDE) $(REALMODE_CFLAGS) -D_SETUP
12731+ifdef CONSTIFY_PLUGIN
12732+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
12733+endif
12734 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
12735 GCOV_PROFILE := n
12736
12737diff --git a/arch/x86/boot/bitops.h b/arch/x86/boot/bitops.h
12738index 878e4b9..20537ab 100644
12739--- a/arch/x86/boot/bitops.h
12740+++ b/arch/x86/boot/bitops.h
12741@@ -26,7 +26,7 @@ static inline int variable_test_bit(int nr, const void *addr)
12742 u8 v;
12743 const u32 *p = (const u32 *)addr;
12744
12745- asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
12746+ asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
12747 return v;
12748 }
12749
12750@@ -37,7 +37,7 @@ static inline int variable_test_bit(int nr, const void *addr)
12751
12752 static inline void set_bit(int nr, void *addr)
12753 {
12754- asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
12755+ asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
12756 }
12757
12758 #endif /* BOOT_BITOPS_H */
12759diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h
12760index bd49ec6..94c7f58 100644
12761--- a/arch/x86/boot/boot.h
12762+++ b/arch/x86/boot/boot.h
12763@@ -84,7 +84,7 @@ static inline void io_delay(void)
12764 static inline u16 ds(void)
12765 {
12766 u16 seg;
12767- asm("movw %%ds,%0" : "=rm" (seg));
12768+ asm volatile("movw %%ds,%0" : "=rm" (seg));
12769 return seg;
12770 }
12771
12772diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
12773index 45abc36..97bea2d 100644
12774--- a/arch/x86/boot/compressed/Makefile
12775+++ b/arch/x86/boot/compressed/Makefile
12776@@ -16,6 +16,9 @@ KBUILD_CFLAGS += $(cflags-y)
12777 KBUILD_CFLAGS += -mno-mmx -mno-sse
12778 KBUILD_CFLAGS += $(call cc-option,-ffreestanding)
12779 KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
12780+ifdef CONSTIFY_PLUGIN
12781+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
12782+endif
12783
12784 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
12785 GCOV_PROFILE := n
12786diff --git a/arch/x86/boot/compressed/efi_stub_32.S b/arch/x86/boot/compressed/efi_stub_32.S
12787index a53440e..c3dbf1e 100644
12788--- a/arch/x86/boot/compressed/efi_stub_32.S
12789+++ b/arch/x86/boot/compressed/efi_stub_32.S
12790@@ -46,16 +46,13 @@ ENTRY(efi_call_phys)
12791 * parameter 2, ..., param n. To make things easy, we save the return
12792 * address of efi_call_phys in a global variable.
12793 */
12794- popl %ecx
12795- movl %ecx, saved_return_addr(%edx)
12796- /* get the function pointer into ECX*/
12797- popl %ecx
12798- movl %ecx, efi_rt_function_ptr(%edx)
12799+ popl saved_return_addr(%edx)
12800+ popl efi_rt_function_ptr(%edx)
12801
12802 /*
12803 * 3. Call the physical function.
12804 */
12805- call *%ecx
12806+ call *efi_rt_function_ptr(%edx)
12807
12808 /*
12809 * 4. Balance the stack. And because EAX contain the return value,
12810@@ -67,15 +64,12 @@ ENTRY(efi_call_phys)
12811 1: popl %edx
12812 subl $1b, %edx
12813
12814- movl efi_rt_function_ptr(%edx), %ecx
12815- pushl %ecx
12816+ pushl efi_rt_function_ptr(%edx)
12817
12818 /*
12819 * 10. Push the saved return address onto the stack and return.
12820 */
12821- movl saved_return_addr(%edx), %ecx
12822- pushl %ecx
12823- ret
12824+ jmpl *saved_return_addr(%edx)
12825 ENDPROC(efi_call_phys)
12826 .previous
12827
12828diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
12829index 1d7fbbc..36ecd58 100644
12830--- a/arch/x86/boot/compressed/head_32.S
12831+++ b/arch/x86/boot/compressed/head_32.S
12832@@ -140,10 +140,10 @@ preferred_addr:
12833 addl %eax, %ebx
12834 notl %eax
12835 andl %eax, %ebx
12836- cmpl $LOAD_PHYSICAL_ADDR, %ebx
12837+ cmpl $____LOAD_PHYSICAL_ADDR, %ebx
12838 jge 1f
12839 #endif
12840- movl $LOAD_PHYSICAL_ADDR, %ebx
12841+ movl $____LOAD_PHYSICAL_ADDR, %ebx
12842 1:
12843
12844 /* Target address to relocate to for decompression */
12845diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
12846index 6b1766c..ad465c9 100644
12847--- a/arch/x86/boot/compressed/head_64.S
12848+++ b/arch/x86/boot/compressed/head_64.S
12849@@ -94,10 +94,10 @@ ENTRY(startup_32)
12850 addl %eax, %ebx
12851 notl %eax
12852 andl %eax, %ebx
12853- cmpl $LOAD_PHYSICAL_ADDR, %ebx
12854+ cmpl $____LOAD_PHYSICAL_ADDR, %ebx
12855 jge 1f
12856 #endif
12857- movl $LOAD_PHYSICAL_ADDR, %ebx
12858+ movl $____LOAD_PHYSICAL_ADDR, %ebx
12859 1:
12860
12861 /* Target address to relocate to for decompression */
12862@@ -322,10 +322,10 @@ preferred_addr:
12863 addq %rax, %rbp
12864 notq %rax
12865 andq %rax, %rbp
12866- cmpq $LOAD_PHYSICAL_ADDR, %rbp
12867+ cmpq $____LOAD_PHYSICAL_ADDR, %rbp
12868 jge 1f
12869 #endif
12870- movq $LOAD_PHYSICAL_ADDR, %rbp
12871+ movq $____LOAD_PHYSICAL_ADDR, %rbp
12872 1:
12873
12874 /* Target address to relocate to for decompression */
12875@@ -434,8 +434,8 @@ gdt:
12876 .long gdt
12877 .word 0
12878 .quad 0x0000000000000000 /* NULL descriptor */
12879- .quad 0x00af9a000000ffff /* __KERNEL_CS */
12880- .quad 0x00cf92000000ffff /* __KERNEL_DS */
12881+ .quad 0x00af9b000000ffff /* __KERNEL_CS */
12882+ .quad 0x00cf93000000ffff /* __KERNEL_DS */
12883 .quad 0x0080890000000000 /* TS descriptor */
12884 .quad 0x0000000000000000 /* TS continued */
12885 gdt_end:
12886diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
12887index 30dd59a..cd9edc3 100644
12888--- a/arch/x86/boot/compressed/misc.c
12889+++ b/arch/x86/boot/compressed/misc.c
12890@@ -242,7 +242,7 @@ static void handle_relocations(void *output, unsigned long output_len)
12891 * Calculate the delta between where vmlinux was linked to load
12892 * and where it was actually loaded.
12893 */
12894- delta = min_addr - LOAD_PHYSICAL_ADDR;
12895+ delta = min_addr - ____LOAD_PHYSICAL_ADDR;
12896 if (!delta) {
12897 debug_putstr("No relocation needed... ");
12898 return;
12899@@ -312,7 +312,7 @@ static void parse_elf(void *output)
12900 Elf32_Ehdr ehdr;
12901 Elf32_Phdr *phdrs, *phdr;
12902 #endif
12903- void *dest;
12904+ void *dest, *prev;
12905 int i;
12906
12907 memcpy(&ehdr, output, sizeof(ehdr));
12908@@ -339,13 +339,16 @@ static void parse_elf(void *output)
12909 case PT_LOAD:
12910 #ifdef CONFIG_RELOCATABLE
12911 dest = output;
12912- dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
12913+ dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
12914 #else
12915 dest = (void *)(phdr->p_paddr);
12916 #endif
12917 memcpy(dest,
12918 output + phdr->p_offset,
12919 phdr->p_filesz);
12920+ if (i)
12921+ memset(prev, 0xff, dest - prev);
12922+ prev = dest + phdr->p_filesz;
12923 break;
12924 default: /* Ignore other PT_* */ break;
12925 }
12926@@ -402,7 +405,7 @@ asmlinkage __visible void *decompress_kernel(void *rmode, memptr heap,
12927 error("Destination address too large");
12928 #endif
12929 #ifndef CONFIG_RELOCATABLE
12930- if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
12931+ if ((unsigned long)output != ____LOAD_PHYSICAL_ADDR)
12932 error("Wrong destination address");
12933 #endif
12934
12935diff --git a/arch/x86/boot/cpucheck.c b/arch/x86/boot/cpucheck.c
12936index 1fd7d57..0f7d096 100644
12937--- a/arch/x86/boot/cpucheck.c
12938+++ b/arch/x86/boot/cpucheck.c
12939@@ -125,9 +125,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
12940 u32 ecx = MSR_K7_HWCR;
12941 u32 eax, edx;
12942
12943- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12944+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12945 eax &= ~(1 << 15);
12946- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12947+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12948
12949 get_cpuflags(); /* Make sure it really did something */
12950 err = check_cpuflags();
12951@@ -140,9 +140,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
12952 u32 ecx = MSR_VIA_FCR;
12953 u32 eax, edx;
12954
12955- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12956+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12957 eax |= (1<<1)|(1<<7);
12958- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12959+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12960
12961 set_bit(X86_FEATURE_CX8, cpu.flags);
12962 err = check_cpuflags();
12963@@ -153,12 +153,12 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
12964 u32 eax, edx;
12965 u32 level = 1;
12966
12967- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12968- asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
12969- asm("cpuid"
12970+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12971+ asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
12972+ asm volatile("cpuid"
12973 : "+a" (level), "=d" (cpu.flags[0])
12974 : : "ecx", "ebx");
12975- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12976+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12977
12978 err = check_cpuflags();
12979 } else if (err == 0x01 &&
12980diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S
12981index 16ef025..91e033b 100644
12982--- a/arch/x86/boot/header.S
12983+++ b/arch/x86/boot/header.S
12984@@ -438,10 +438,14 @@ setup_data: .quad 0 # 64-bit physical pointer to
12985 # single linked list of
12986 # struct setup_data
12987
12988-pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
12989+pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
12990
12991 #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset)
12992+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
12993+#define VO_INIT_SIZE (VO__end - VO__text - __PAGE_OFFSET - ____LOAD_PHYSICAL_ADDR)
12994+#else
12995 #define VO_INIT_SIZE (VO__end - VO__text)
12996+#endif
12997 #if ZO_INIT_SIZE > VO_INIT_SIZE
12998 #define INIT_SIZE ZO_INIT_SIZE
12999 #else
13000diff --git a/arch/x86/boot/memory.c b/arch/x86/boot/memory.c
13001index db75d07..8e6d0af 100644
13002--- a/arch/x86/boot/memory.c
13003+++ b/arch/x86/boot/memory.c
13004@@ -19,7 +19,7 @@
13005
13006 static int detect_memory_e820(void)
13007 {
13008- int count = 0;
13009+ unsigned int count = 0;
13010 struct biosregs ireg, oreg;
13011 struct e820entry *desc = boot_params.e820_map;
13012 static struct e820entry buf; /* static so it is zeroed */
13013diff --git a/arch/x86/boot/video-vesa.c b/arch/x86/boot/video-vesa.c
13014index ba3e100..6501b8f 100644
13015--- a/arch/x86/boot/video-vesa.c
13016+++ b/arch/x86/boot/video-vesa.c
13017@@ -201,6 +201,7 @@ static void vesa_store_pm_info(void)
13018
13019 boot_params.screen_info.vesapm_seg = oreg.es;
13020 boot_params.screen_info.vesapm_off = oreg.di;
13021+ boot_params.screen_info.vesapm_size = oreg.cx;
13022 }
13023
13024 /*
13025diff --git a/arch/x86/boot/video.c b/arch/x86/boot/video.c
13026index 43eda28..5ab5fdb 100644
13027--- a/arch/x86/boot/video.c
13028+++ b/arch/x86/boot/video.c
13029@@ -96,7 +96,7 @@ static void store_mode_params(void)
13030 static unsigned int get_entry(void)
13031 {
13032 char entry_buf[4];
13033- int i, len = 0;
13034+ unsigned int i, len = 0;
13035 int key;
13036 unsigned int v;
13037
13038diff --git a/arch/x86/crypto/aes-x86_64-asm_64.S b/arch/x86/crypto/aes-x86_64-asm_64.S
13039index 9105655..41779c1 100644
13040--- a/arch/x86/crypto/aes-x86_64-asm_64.S
13041+++ b/arch/x86/crypto/aes-x86_64-asm_64.S
13042@@ -8,6 +8,8 @@
13043 * including this sentence is retained in full.
13044 */
13045
13046+#include <asm/alternative-asm.h>
13047+
13048 .extern crypto_ft_tab
13049 .extern crypto_it_tab
13050 .extern crypto_fl_tab
13051@@ -70,6 +72,8 @@
13052 je B192; \
13053 leaq 32(r9),r9;
13054
13055+#define ret pax_force_retaddr; ret
13056+
13057 #define epilogue(FUNC,r1,r2,r3,r4,r5,r6,r7,r8,r9) \
13058 movq r1,r2; \
13059 movq r3,r4; \
13060diff --git a/arch/x86/crypto/aesni-intel_asm.S b/arch/x86/crypto/aesni-intel_asm.S
13061index 477e9d7..c92c7d8 100644
13062--- a/arch/x86/crypto/aesni-intel_asm.S
13063+++ b/arch/x86/crypto/aesni-intel_asm.S
13064@@ -31,6 +31,7 @@
13065
13066 #include <linux/linkage.h>
13067 #include <asm/inst.h>
13068+#include <asm/alternative-asm.h>
13069
13070 #ifdef __x86_64__
13071 .data
13072@@ -205,7 +206,7 @@ enc: .octa 0x2
13073 * num_initial_blocks = b mod 4
13074 * encrypt the initial num_initial_blocks blocks and apply ghash on
13075 * the ciphertext
13076-* %r10, %r11, %r12, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
13077+* %r10, %r11, %r15, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
13078 * are clobbered
13079 * arg1, %arg2, %arg3, %r14 are used as a pointer only, not modified
13080 */
13081@@ -214,8 +215,8 @@ enc: .octa 0x2
13082 .macro INITIAL_BLOCKS_DEC num_initial_blocks TMP1 TMP2 TMP3 TMP4 TMP5 XMM0 XMM1 \
13083 XMM2 XMM3 XMM4 XMMDst TMP6 TMP7 i i_seq operation
13084 mov arg7, %r10 # %r10 = AAD
13085- mov arg8, %r12 # %r12 = aadLen
13086- mov %r12, %r11
13087+ mov arg8, %r15 # %r15 = aadLen
13088+ mov %r15, %r11
13089 pxor %xmm\i, %xmm\i
13090 _get_AAD_loop\num_initial_blocks\operation:
13091 movd (%r10), \TMP1
13092@@ -223,15 +224,15 @@ _get_AAD_loop\num_initial_blocks\operation:
13093 psrldq $4, %xmm\i
13094 pxor \TMP1, %xmm\i
13095 add $4, %r10
13096- sub $4, %r12
13097+ sub $4, %r15
13098 jne _get_AAD_loop\num_initial_blocks\operation
13099 cmp $16, %r11
13100 je _get_AAD_loop2_done\num_initial_blocks\operation
13101- mov $16, %r12
13102+ mov $16, %r15
13103 _get_AAD_loop2\num_initial_blocks\operation:
13104 psrldq $4, %xmm\i
13105- sub $4, %r12
13106- cmp %r11, %r12
13107+ sub $4, %r15
13108+ cmp %r11, %r15
13109 jne _get_AAD_loop2\num_initial_blocks\operation
13110 _get_AAD_loop2_done\num_initial_blocks\operation:
13111 movdqa SHUF_MASK(%rip), %xmm14
13112@@ -443,7 +444,7 @@ _initial_blocks_done\num_initial_blocks\operation:
13113 * num_initial_blocks = b mod 4
13114 * encrypt the initial num_initial_blocks blocks and apply ghash on
13115 * the ciphertext
13116-* %r10, %r11, %r12, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
13117+* %r10, %r11, %r15, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
13118 * are clobbered
13119 * arg1, %arg2, %arg3, %r14 are used as a pointer only, not modified
13120 */
13121@@ -452,8 +453,8 @@ _initial_blocks_done\num_initial_blocks\operation:
13122 .macro INITIAL_BLOCKS_ENC num_initial_blocks TMP1 TMP2 TMP3 TMP4 TMP5 XMM0 XMM1 \
13123 XMM2 XMM3 XMM4 XMMDst TMP6 TMP7 i i_seq operation
13124 mov arg7, %r10 # %r10 = AAD
13125- mov arg8, %r12 # %r12 = aadLen
13126- mov %r12, %r11
13127+ mov arg8, %r15 # %r15 = aadLen
13128+ mov %r15, %r11
13129 pxor %xmm\i, %xmm\i
13130 _get_AAD_loop\num_initial_blocks\operation:
13131 movd (%r10), \TMP1
13132@@ -461,15 +462,15 @@ _get_AAD_loop\num_initial_blocks\operation:
13133 psrldq $4, %xmm\i
13134 pxor \TMP1, %xmm\i
13135 add $4, %r10
13136- sub $4, %r12
13137+ sub $4, %r15
13138 jne _get_AAD_loop\num_initial_blocks\operation
13139 cmp $16, %r11
13140 je _get_AAD_loop2_done\num_initial_blocks\operation
13141- mov $16, %r12
13142+ mov $16, %r15
13143 _get_AAD_loop2\num_initial_blocks\operation:
13144 psrldq $4, %xmm\i
13145- sub $4, %r12
13146- cmp %r11, %r12
13147+ sub $4, %r15
13148+ cmp %r11, %r15
13149 jne _get_AAD_loop2\num_initial_blocks\operation
13150 _get_AAD_loop2_done\num_initial_blocks\operation:
13151 movdqa SHUF_MASK(%rip), %xmm14
13152@@ -1269,7 +1270,7 @@ TMP7 XMM1 XMM2 XMM3 XMM4 XMMDst
13153 *
13154 *****************************************************************************/
13155 ENTRY(aesni_gcm_dec)
13156- push %r12
13157+ push %r15
13158 push %r13
13159 push %r14
13160 mov %rsp, %r14
13161@@ -1279,8 +1280,8 @@ ENTRY(aesni_gcm_dec)
13162 */
13163 sub $VARIABLE_OFFSET, %rsp
13164 and $~63, %rsp # align rsp to 64 bytes
13165- mov %arg6, %r12
13166- movdqu (%r12), %xmm13 # %xmm13 = HashKey
13167+ mov %arg6, %r15
13168+ movdqu (%r15), %xmm13 # %xmm13 = HashKey
13169 movdqa SHUF_MASK(%rip), %xmm2
13170 PSHUFB_XMM %xmm2, %xmm13
13171
13172@@ -1308,10 +1309,10 @@ ENTRY(aesni_gcm_dec)
13173 movdqa %xmm13, HashKey(%rsp) # store HashKey<<1 (mod poly)
13174 mov %arg4, %r13 # save the number of bytes of plaintext/ciphertext
13175 and $-16, %r13 # %r13 = %r13 - (%r13 mod 16)
13176- mov %r13, %r12
13177- and $(3<<4), %r12
13178+ mov %r13, %r15
13179+ and $(3<<4), %r15
13180 jz _initial_num_blocks_is_0_decrypt
13181- cmp $(2<<4), %r12
13182+ cmp $(2<<4), %r15
13183 jb _initial_num_blocks_is_1_decrypt
13184 je _initial_num_blocks_is_2_decrypt
13185 _initial_num_blocks_is_3_decrypt:
13186@@ -1361,16 +1362,16 @@ _zero_cipher_left_decrypt:
13187 sub $16, %r11
13188 add %r13, %r11
13189 movdqu (%arg3,%r11,1), %xmm1 # receive the last <16 byte block
13190- lea SHIFT_MASK+16(%rip), %r12
13191- sub %r13, %r12
13192+ lea SHIFT_MASK+16(%rip), %r15
13193+ sub %r13, %r15
13194 # adjust the shuffle mask pointer to be able to shift 16-%r13 bytes
13195 # (%r13 is the number of bytes in plaintext mod 16)
13196- movdqu (%r12), %xmm2 # get the appropriate shuffle mask
13197+ movdqu (%r15), %xmm2 # get the appropriate shuffle mask
13198 PSHUFB_XMM %xmm2, %xmm1 # right shift 16-%r13 butes
13199
13200 movdqa %xmm1, %xmm2
13201 pxor %xmm1, %xmm0 # Ciphertext XOR E(K, Yn)
13202- movdqu ALL_F-SHIFT_MASK(%r12), %xmm1
13203+ movdqu ALL_F-SHIFT_MASK(%r15), %xmm1
13204 # get the appropriate mask to mask out top 16-%r13 bytes of %xmm0
13205 pand %xmm1, %xmm0 # mask out top 16-%r13 bytes of %xmm0
13206 pand %xmm1, %xmm2
13207@@ -1399,9 +1400,9 @@ _less_than_8_bytes_left_decrypt:
13208 sub $1, %r13
13209 jne _less_than_8_bytes_left_decrypt
13210 _multiple_of_16_bytes_decrypt:
13211- mov arg8, %r12 # %r13 = aadLen (number of bytes)
13212- shl $3, %r12 # convert into number of bits
13213- movd %r12d, %xmm15 # len(A) in %xmm15
13214+ mov arg8, %r15 # %r13 = aadLen (number of bytes)
13215+ shl $3, %r15 # convert into number of bits
13216+ movd %r15d, %xmm15 # len(A) in %xmm15
13217 shl $3, %arg4 # len(C) in bits (*128)
13218 MOVQ_R64_XMM %arg4, %xmm1
13219 pslldq $8, %xmm15 # %xmm15 = len(A)||0x0000000000000000
13220@@ -1440,7 +1441,8 @@ _return_T_done_decrypt:
13221 mov %r14, %rsp
13222 pop %r14
13223 pop %r13
13224- pop %r12
13225+ pop %r15
13226+ pax_force_retaddr
13227 ret
13228 ENDPROC(aesni_gcm_dec)
13229
13230@@ -1529,7 +1531,7 @@ ENDPROC(aesni_gcm_dec)
13231 * poly = x^128 + x^127 + x^126 + x^121 + 1
13232 ***************************************************************************/
13233 ENTRY(aesni_gcm_enc)
13234- push %r12
13235+ push %r15
13236 push %r13
13237 push %r14
13238 mov %rsp, %r14
13239@@ -1539,8 +1541,8 @@ ENTRY(aesni_gcm_enc)
13240 #
13241 sub $VARIABLE_OFFSET, %rsp
13242 and $~63, %rsp
13243- mov %arg6, %r12
13244- movdqu (%r12), %xmm13
13245+ mov %arg6, %r15
13246+ movdqu (%r15), %xmm13
13247 movdqa SHUF_MASK(%rip), %xmm2
13248 PSHUFB_XMM %xmm2, %xmm13
13249
13250@@ -1564,13 +1566,13 @@ ENTRY(aesni_gcm_enc)
13251 movdqa %xmm13, HashKey(%rsp)
13252 mov %arg4, %r13 # %xmm13 holds HashKey<<1 (mod poly)
13253 and $-16, %r13
13254- mov %r13, %r12
13255+ mov %r13, %r15
13256
13257 # Encrypt first few blocks
13258
13259- and $(3<<4), %r12
13260+ and $(3<<4), %r15
13261 jz _initial_num_blocks_is_0_encrypt
13262- cmp $(2<<4), %r12
13263+ cmp $(2<<4), %r15
13264 jb _initial_num_blocks_is_1_encrypt
13265 je _initial_num_blocks_is_2_encrypt
13266 _initial_num_blocks_is_3_encrypt:
13267@@ -1623,14 +1625,14 @@ _zero_cipher_left_encrypt:
13268 sub $16, %r11
13269 add %r13, %r11
13270 movdqu (%arg3,%r11,1), %xmm1 # receive the last <16 byte blocks
13271- lea SHIFT_MASK+16(%rip), %r12
13272- sub %r13, %r12
13273+ lea SHIFT_MASK+16(%rip), %r15
13274+ sub %r13, %r15
13275 # adjust the shuffle mask pointer to be able to shift 16-r13 bytes
13276 # (%r13 is the number of bytes in plaintext mod 16)
13277- movdqu (%r12), %xmm2 # get the appropriate shuffle mask
13278+ movdqu (%r15), %xmm2 # get the appropriate shuffle mask
13279 PSHUFB_XMM %xmm2, %xmm1 # shift right 16-r13 byte
13280 pxor %xmm1, %xmm0 # Plaintext XOR Encrypt(K, Yn)
13281- movdqu ALL_F-SHIFT_MASK(%r12), %xmm1
13282+ movdqu ALL_F-SHIFT_MASK(%r15), %xmm1
13283 # get the appropriate mask to mask out top 16-r13 bytes of xmm0
13284 pand %xmm1, %xmm0 # mask out top 16-r13 bytes of xmm0
13285 movdqa SHUF_MASK(%rip), %xmm10
13286@@ -1663,9 +1665,9 @@ _less_than_8_bytes_left_encrypt:
13287 sub $1, %r13
13288 jne _less_than_8_bytes_left_encrypt
13289 _multiple_of_16_bytes_encrypt:
13290- mov arg8, %r12 # %r12 = addLen (number of bytes)
13291- shl $3, %r12
13292- movd %r12d, %xmm15 # len(A) in %xmm15
13293+ mov arg8, %r15 # %r15 = addLen (number of bytes)
13294+ shl $3, %r15
13295+ movd %r15d, %xmm15 # len(A) in %xmm15
13296 shl $3, %arg4 # len(C) in bits (*128)
13297 MOVQ_R64_XMM %arg4, %xmm1
13298 pslldq $8, %xmm15 # %xmm15 = len(A)||0x0000000000000000
13299@@ -1704,7 +1706,8 @@ _return_T_done_encrypt:
13300 mov %r14, %rsp
13301 pop %r14
13302 pop %r13
13303- pop %r12
13304+ pop %r15
13305+ pax_force_retaddr
13306 ret
13307 ENDPROC(aesni_gcm_enc)
13308
13309@@ -1722,6 +1725,7 @@ _key_expansion_256a:
13310 pxor %xmm1, %xmm0
13311 movaps %xmm0, (TKEYP)
13312 add $0x10, TKEYP
13313+ pax_force_retaddr
13314 ret
13315 ENDPROC(_key_expansion_128)
13316 ENDPROC(_key_expansion_256a)
13317@@ -1748,6 +1752,7 @@ _key_expansion_192a:
13318 shufps $0b01001110, %xmm2, %xmm1
13319 movaps %xmm1, 0x10(TKEYP)
13320 add $0x20, TKEYP
13321+ pax_force_retaddr
13322 ret
13323 ENDPROC(_key_expansion_192a)
13324
13325@@ -1768,6 +1773,7 @@ _key_expansion_192b:
13326
13327 movaps %xmm0, (TKEYP)
13328 add $0x10, TKEYP
13329+ pax_force_retaddr
13330 ret
13331 ENDPROC(_key_expansion_192b)
13332
13333@@ -1781,6 +1787,7 @@ _key_expansion_256b:
13334 pxor %xmm1, %xmm2
13335 movaps %xmm2, (TKEYP)
13336 add $0x10, TKEYP
13337+ pax_force_retaddr
13338 ret
13339 ENDPROC(_key_expansion_256b)
13340
13341@@ -1894,6 +1901,7 @@ ENTRY(aesni_set_key)
13342 #ifndef __x86_64__
13343 popl KEYP
13344 #endif
13345+ pax_force_retaddr
13346 ret
13347 ENDPROC(aesni_set_key)
13348
13349@@ -1916,6 +1924,7 @@ ENTRY(aesni_enc)
13350 popl KLEN
13351 popl KEYP
13352 #endif
13353+ pax_force_retaddr
13354 ret
13355 ENDPROC(aesni_enc)
13356
13357@@ -1974,6 +1983,7 @@ _aesni_enc1:
13358 AESENC KEY STATE
13359 movaps 0x70(TKEYP), KEY
13360 AESENCLAST KEY STATE
13361+ pax_force_retaddr
13362 ret
13363 ENDPROC(_aesni_enc1)
13364
13365@@ -2083,6 +2093,7 @@ _aesni_enc4:
13366 AESENCLAST KEY STATE2
13367 AESENCLAST KEY STATE3
13368 AESENCLAST KEY STATE4
13369+ pax_force_retaddr
13370 ret
13371 ENDPROC(_aesni_enc4)
13372
13373@@ -2106,6 +2117,7 @@ ENTRY(aesni_dec)
13374 popl KLEN
13375 popl KEYP
13376 #endif
13377+ pax_force_retaddr
13378 ret
13379 ENDPROC(aesni_dec)
13380
13381@@ -2164,6 +2176,7 @@ _aesni_dec1:
13382 AESDEC KEY STATE
13383 movaps 0x70(TKEYP), KEY
13384 AESDECLAST KEY STATE
13385+ pax_force_retaddr
13386 ret
13387 ENDPROC(_aesni_dec1)
13388
13389@@ -2273,6 +2286,7 @@ _aesni_dec4:
13390 AESDECLAST KEY STATE2
13391 AESDECLAST KEY STATE3
13392 AESDECLAST KEY STATE4
13393+ pax_force_retaddr
13394 ret
13395 ENDPROC(_aesni_dec4)
13396
13397@@ -2331,6 +2345,7 @@ ENTRY(aesni_ecb_enc)
13398 popl KEYP
13399 popl LEN
13400 #endif
13401+ pax_force_retaddr
13402 ret
13403 ENDPROC(aesni_ecb_enc)
13404
13405@@ -2390,6 +2405,7 @@ ENTRY(aesni_ecb_dec)
13406 popl KEYP
13407 popl LEN
13408 #endif
13409+ pax_force_retaddr
13410 ret
13411 ENDPROC(aesni_ecb_dec)
13412
13413@@ -2432,6 +2448,7 @@ ENTRY(aesni_cbc_enc)
13414 popl LEN
13415 popl IVP
13416 #endif
13417+ pax_force_retaddr
13418 ret
13419 ENDPROC(aesni_cbc_enc)
13420
13421@@ -2523,6 +2540,7 @@ ENTRY(aesni_cbc_dec)
13422 popl LEN
13423 popl IVP
13424 #endif
13425+ pax_force_retaddr
13426 ret
13427 ENDPROC(aesni_cbc_dec)
13428
13429@@ -2550,6 +2568,7 @@ _aesni_inc_init:
13430 mov $1, TCTR_LOW
13431 MOVQ_R64_XMM TCTR_LOW INC
13432 MOVQ_R64_XMM CTR TCTR_LOW
13433+ pax_force_retaddr
13434 ret
13435 ENDPROC(_aesni_inc_init)
13436
13437@@ -2579,6 +2598,7 @@ _aesni_inc:
13438 .Linc_low:
13439 movaps CTR, IV
13440 PSHUFB_XMM BSWAP_MASK IV
13441+ pax_force_retaddr
13442 ret
13443 ENDPROC(_aesni_inc)
13444
13445@@ -2640,6 +2660,7 @@ ENTRY(aesni_ctr_enc)
13446 .Lctr_enc_ret:
13447 movups IV, (IVP)
13448 .Lctr_enc_just_ret:
13449+ pax_force_retaddr
13450 ret
13451 ENDPROC(aesni_ctr_enc)
13452
13453@@ -2766,6 +2787,7 @@ ENTRY(aesni_xts_crypt8)
13454 pxor INC, STATE4
13455 movdqu STATE4, 0x70(OUTP)
13456
13457+ pax_force_retaddr
13458 ret
13459 ENDPROC(aesni_xts_crypt8)
13460
13461diff --git a/arch/x86/crypto/blowfish-x86_64-asm_64.S b/arch/x86/crypto/blowfish-x86_64-asm_64.S
13462index 246c670..466e2d6 100644
13463--- a/arch/x86/crypto/blowfish-x86_64-asm_64.S
13464+++ b/arch/x86/crypto/blowfish-x86_64-asm_64.S
13465@@ -21,6 +21,7 @@
13466 */
13467
13468 #include <linux/linkage.h>
13469+#include <asm/alternative-asm.h>
13470
13471 .file "blowfish-x86_64-asm.S"
13472 .text
13473@@ -149,9 +150,11 @@ ENTRY(__blowfish_enc_blk)
13474 jnz .L__enc_xor;
13475
13476 write_block();
13477+ pax_force_retaddr
13478 ret;
13479 .L__enc_xor:
13480 xor_block();
13481+ pax_force_retaddr
13482 ret;
13483 ENDPROC(__blowfish_enc_blk)
13484
13485@@ -183,6 +186,7 @@ ENTRY(blowfish_dec_blk)
13486
13487 movq %r11, %rbp;
13488
13489+ pax_force_retaddr
13490 ret;
13491 ENDPROC(blowfish_dec_blk)
13492
13493@@ -334,6 +338,7 @@ ENTRY(__blowfish_enc_blk_4way)
13494
13495 popq %rbx;
13496 popq %rbp;
13497+ pax_force_retaddr
13498 ret;
13499
13500 .L__enc_xor4:
13501@@ -341,6 +346,7 @@ ENTRY(__blowfish_enc_blk_4way)
13502
13503 popq %rbx;
13504 popq %rbp;
13505+ pax_force_retaddr
13506 ret;
13507 ENDPROC(__blowfish_enc_blk_4way)
13508
13509@@ -375,5 +381,6 @@ ENTRY(blowfish_dec_blk_4way)
13510 popq %rbx;
13511 popq %rbp;
13512
13513+ pax_force_retaddr
13514 ret;
13515 ENDPROC(blowfish_dec_blk_4way)
13516diff --git a/arch/x86/crypto/camellia-aesni-avx-asm_64.S b/arch/x86/crypto/camellia-aesni-avx-asm_64.S
13517index ce71f92..1dce7ec 100644
13518--- a/arch/x86/crypto/camellia-aesni-avx-asm_64.S
13519+++ b/arch/x86/crypto/camellia-aesni-avx-asm_64.S
13520@@ -16,6 +16,7 @@
13521 */
13522
13523 #include <linux/linkage.h>
13524+#include <asm/alternative-asm.h>
13525
13526 #define CAMELLIA_TABLE_BYTE_LEN 272
13527
13528@@ -191,6 +192,7 @@ roundsm16_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd:
13529 roundsm16(%xmm0, %xmm1, %xmm2, %xmm3, %xmm4, %xmm5, %xmm6, %xmm7,
13530 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14, %xmm15,
13531 %rcx, (%r9));
13532+ pax_force_retaddr
13533 ret;
13534 ENDPROC(roundsm16_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd)
13535
13536@@ -199,6 +201,7 @@ roundsm16_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab:
13537 roundsm16(%xmm4, %xmm5, %xmm6, %xmm7, %xmm0, %xmm1, %xmm2, %xmm3,
13538 %xmm12, %xmm13, %xmm14, %xmm15, %xmm8, %xmm9, %xmm10, %xmm11,
13539 %rax, (%r9));
13540+ pax_force_retaddr
13541 ret;
13542 ENDPROC(roundsm16_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab)
13543
13544@@ -780,6 +783,7 @@ __camellia_enc_blk16:
13545 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14,
13546 %xmm15, (key_table)(CTX, %r8, 8), (%rax), 1 * 16(%rax));
13547
13548+ pax_force_retaddr
13549 ret;
13550
13551 .align 8
13552@@ -865,6 +869,7 @@ __camellia_dec_blk16:
13553 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14,
13554 %xmm15, (key_table)(CTX), (%rax), 1 * 16(%rax));
13555
13556+ pax_force_retaddr
13557 ret;
13558
13559 .align 8
13560@@ -904,6 +909,7 @@ ENTRY(camellia_ecb_enc_16way)
13561 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13562 %xmm8, %rsi);
13563
13564+ pax_force_retaddr
13565 ret;
13566 ENDPROC(camellia_ecb_enc_16way)
13567
13568@@ -932,6 +938,7 @@ ENTRY(camellia_ecb_dec_16way)
13569 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13570 %xmm8, %rsi);
13571
13572+ pax_force_retaddr
13573 ret;
13574 ENDPROC(camellia_ecb_dec_16way)
13575
13576@@ -981,6 +988,7 @@ ENTRY(camellia_cbc_dec_16way)
13577 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13578 %xmm8, %rsi);
13579
13580+ pax_force_retaddr
13581 ret;
13582 ENDPROC(camellia_cbc_dec_16way)
13583
13584@@ -1092,6 +1100,7 @@ ENTRY(camellia_ctr_16way)
13585 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13586 %xmm8, %rsi);
13587
13588+ pax_force_retaddr
13589 ret;
13590 ENDPROC(camellia_ctr_16way)
13591
13592@@ -1234,6 +1243,7 @@ camellia_xts_crypt_16way:
13593 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13594 %xmm8, %rsi);
13595
13596+ pax_force_retaddr
13597 ret;
13598 ENDPROC(camellia_xts_crypt_16way)
13599
13600diff --git a/arch/x86/crypto/camellia-aesni-avx2-asm_64.S b/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
13601index 0e0b886..5a3123c 100644
13602--- a/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
13603+++ b/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
13604@@ -11,6 +11,7 @@
13605 */
13606
13607 #include <linux/linkage.h>
13608+#include <asm/alternative-asm.h>
13609
13610 #define CAMELLIA_TABLE_BYTE_LEN 272
13611
13612@@ -230,6 +231,7 @@ roundsm32_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd:
13613 roundsm32(%ymm0, %ymm1, %ymm2, %ymm3, %ymm4, %ymm5, %ymm6, %ymm7,
13614 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14, %ymm15,
13615 %rcx, (%r9));
13616+ pax_force_retaddr
13617 ret;
13618 ENDPROC(roundsm32_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd)
13619
13620@@ -238,6 +240,7 @@ roundsm32_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab:
13621 roundsm32(%ymm4, %ymm5, %ymm6, %ymm7, %ymm0, %ymm1, %ymm2, %ymm3,
13622 %ymm12, %ymm13, %ymm14, %ymm15, %ymm8, %ymm9, %ymm10, %ymm11,
13623 %rax, (%r9));
13624+ pax_force_retaddr
13625 ret;
13626 ENDPROC(roundsm32_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab)
13627
13628@@ -820,6 +823,7 @@ __camellia_enc_blk32:
13629 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14,
13630 %ymm15, (key_table)(CTX, %r8, 8), (%rax), 1 * 32(%rax));
13631
13632+ pax_force_retaddr
13633 ret;
13634
13635 .align 8
13636@@ -905,6 +909,7 @@ __camellia_dec_blk32:
13637 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14,
13638 %ymm15, (key_table)(CTX), (%rax), 1 * 32(%rax));
13639
13640+ pax_force_retaddr
13641 ret;
13642
13643 .align 8
13644@@ -948,6 +953,7 @@ ENTRY(camellia_ecb_enc_32way)
13645
13646 vzeroupper;
13647
13648+ pax_force_retaddr
13649 ret;
13650 ENDPROC(camellia_ecb_enc_32way)
13651
13652@@ -980,6 +986,7 @@ ENTRY(camellia_ecb_dec_32way)
13653
13654 vzeroupper;
13655
13656+ pax_force_retaddr
13657 ret;
13658 ENDPROC(camellia_ecb_dec_32way)
13659
13660@@ -1046,6 +1053,7 @@ ENTRY(camellia_cbc_dec_32way)
13661
13662 vzeroupper;
13663
13664+ pax_force_retaddr
13665 ret;
13666 ENDPROC(camellia_cbc_dec_32way)
13667
13668@@ -1184,6 +1192,7 @@ ENTRY(camellia_ctr_32way)
13669
13670 vzeroupper;
13671
13672+ pax_force_retaddr
13673 ret;
13674 ENDPROC(camellia_ctr_32way)
13675
13676@@ -1349,6 +1358,7 @@ camellia_xts_crypt_32way:
13677
13678 vzeroupper;
13679
13680+ pax_force_retaddr
13681 ret;
13682 ENDPROC(camellia_xts_crypt_32way)
13683
13684diff --git a/arch/x86/crypto/camellia-x86_64-asm_64.S b/arch/x86/crypto/camellia-x86_64-asm_64.S
13685index 310319c..db3d7b5 100644
13686--- a/arch/x86/crypto/camellia-x86_64-asm_64.S
13687+++ b/arch/x86/crypto/camellia-x86_64-asm_64.S
13688@@ -21,6 +21,7 @@
13689 */
13690
13691 #include <linux/linkage.h>
13692+#include <asm/alternative-asm.h>
13693
13694 .file "camellia-x86_64-asm_64.S"
13695 .text
13696@@ -228,12 +229,14 @@ ENTRY(__camellia_enc_blk)
13697 enc_outunpack(mov, RT1);
13698
13699 movq RRBP, %rbp;
13700+ pax_force_retaddr
13701 ret;
13702
13703 .L__enc_xor:
13704 enc_outunpack(xor, RT1);
13705
13706 movq RRBP, %rbp;
13707+ pax_force_retaddr
13708 ret;
13709 ENDPROC(__camellia_enc_blk)
13710
13711@@ -272,6 +275,7 @@ ENTRY(camellia_dec_blk)
13712 dec_outunpack();
13713
13714 movq RRBP, %rbp;
13715+ pax_force_retaddr
13716 ret;
13717 ENDPROC(camellia_dec_blk)
13718
13719@@ -463,6 +467,7 @@ ENTRY(__camellia_enc_blk_2way)
13720
13721 movq RRBP, %rbp;
13722 popq %rbx;
13723+ pax_force_retaddr
13724 ret;
13725
13726 .L__enc2_xor:
13727@@ -470,6 +475,7 @@ ENTRY(__camellia_enc_blk_2way)
13728
13729 movq RRBP, %rbp;
13730 popq %rbx;
13731+ pax_force_retaddr
13732 ret;
13733 ENDPROC(__camellia_enc_blk_2way)
13734
13735@@ -510,5 +516,6 @@ ENTRY(camellia_dec_blk_2way)
13736
13737 movq RRBP, %rbp;
13738 movq RXOR, %rbx;
13739+ pax_force_retaddr
13740 ret;
13741 ENDPROC(camellia_dec_blk_2way)
13742diff --git a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
13743index c35fd5d..2d8c7db 100644
13744--- a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
13745+++ b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
13746@@ -24,6 +24,7 @@
13747 */
13748
13749 #include <linux/linkage.h>
13750+#include <asm/alternative-asm.h>
13751
13752 .file "cast5-avx-x86_64-asm_64.S"
13753
13754@@ -281,6 +282,7 @@ __cast5_enc_blk16:
13755 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
13756 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
13757
13758+ pax_force_retaddr
13759 ret;
13760 ENDPROC(__cast5_enc_blk16)
13761
13762@@ -352,6 +354,7 @@ __cast5_dec_blk16:
13763 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
13764 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
13765
13766+ pax_force_retaddr
13767 ret;
13768
13769 .L__skip_dec:
13770@@ -388,6 +391,7 @@ ENTRY(cast5_ecb_enc_16way)
13771 vmovdqu RR4, (6*4*4)(%r11);
13772 vmovdqu RL4, (7*4*4)(%r11);
13773
13774+ pax_force_retaddr
13775 ret;
13776 ENDPROC(cast5_ecb_enc_16way)
13777
13778@@ -420,6 +424,7 @@ ENTRY(cast5_ecb_dec_16way)
13779 vmovdqu RR4, (6*4*4)(%r11);
13780 vmovdqu RL4, (7*4*4)(%r11);
13781
13782+ pax_force_retaddr
13783 ret;
13784 ENDPROC(cast5_ecb_dec_16way)
13785
13786@@ -430,10 +435,10 @@ ENTRY(cast5_cbc_dec_16way)
13787 * %rdx: src
13788 */
13789
13790- pushq %r12;
13791+ pushq %r14;
13792
13793 movq %rsi, %r11;
13794- movq %rdx, %r12;
13795+ movq %rdx, %r14;
13796
13797 vmovdqu (0*16)(%rdx), RL1;
13798 vmovdqu (1*16)(%rdx), RR1;
13799@@ -447,16 +452,16 @@ ENTRY(cast5_cbc_dec_16way)
13800 call __cast5_dec_blk16;
13801
13802 /* xor with src */
13803- vmovq (%r12), RX;
13804+ vmovq (%r14), RX;
13805 vpshufd $0x4f, RX, RX;
13806 vpxor RX, RR1, RR1;
13807- vpxor 0*16+8(%r12), RL1, RL1;
13808- vpxor 1*16+8(%r12), RR2, RR2;
13809- vpxor 2*16+8(%r12), RL2, RL2;
13810- vpxor 3*16+8(%r12), RR3, RR3;
13811- vpxor 4*16+8(%r12), RL3, RL3;
13812- vpxor 5*16+8(%r12), RR4, RR4;
13813- vpxor 6*16+8(%r12), RL4, RL4;
13814+ vpxor 0*16+8(%r14), RL1, RL1;
13815+ vpxor 1*16+8(%r14), RR2, RR2;
13816+ vpxor 2*16+8(%r14), RL2, RL2;
13817+ vpxor 3*16+8(%r14), RR3, RR3;
13818+ vpxor 4*16+8(%r14), RL3, RL3;
13819+ vpxor 5*16+8(%r14), RR4, RR4;
13820+ vpxor 6*16+8(%r14), RL4, RL4;
13821
13822 vmovdqu RR1, (0*16)(%r11);
13823 vmovdqu RL1, (1*16)(%r11);
13824@@ -467,8 +472,9 @@ ENTRY(cast5_cbc_dec_16way)
13825 vmovdqu RR4, (6*16)(%r11);
13826 vmovdqu RL4, (7*16)(%r11);
13827
13828- popq %r12;
13829+ popq %r14;
13830
13831+ pax_force_retaddr
13832 ret;
13833 ENDPROC(cast5_cbc_dec_16way)
13834
13835@@ -480,10 +486,10 @@ ENTRY(cast5_ctr_16way)
13836 * %rcx: iv (big endian, 64bit)
13837 */
13838
13839- pushq %r12;
13840+ pushq %r14;
13841
13842 movq %rsi, %r11;
13843- movq %rdx, %r12;
13844+ movq %rdx, %r14;
13845
13846 vpcmpeqd RTMP, RTMP, RTMP;
13847 vpsrldq $8, RTMP, RTMP; /* low: -1, high: 0 */
13848@@ -523,14 +529,14 @@ ENTRY(cast5_ctr_16way)
13849 call __cast5_enc_blk16;
13850
13851 /* dst = src ^ iv */
13852- vpxor (0*16)(%r12), RR1, RR1;
13853- vpxor (1*16)(%r12), RL1, RL1;
13854- vpxor (2*16)(%r12), RR2, RR2;
13855- vpxor (3*16)(%r12), RL2, RL2;
13856- vpxor (4*16)(%r12), RR3, RR3;
13857- vpxor (5*16)(%r12), RL3, RL3;
13858- vpxor (6*16)(%r12), RR4, RR4;
13859- vpxor (7*16)(%r12), RL4, RL4;
13860+ vpxor (0*16)(%r14), RR1, RR1;
13861+ vpxor (1*16)(%r14), RL1, RL1;
13862+ vpxor (2*16)(%r14), RR2, RR2;
13863+ vpxor (3*16)(%r14), RL2, RL2;
13864+ vpxor (4*16)(%r14), RR3, RR3;
13865+ vpxor (5*16)(%r14), RL3, RL3;
13866+ vpxor (6*16)(%r14), RR4, RR4;
13867+ vpxor (7*16)(%r14), RL4, RL4;
13868 vmovdqu RR1, (0*16)(%r11);
13869 vmovdqu RL1, (1*16)(%r11);
13870 vmovdqu RR2, (2*16)(%r11);
13871@@ -540,7 +546,8 @@ ENTRY(cast5_ctr_16way)
13872 vmovdqu RR4, (6*16)(%r11);
13873 vmovdqu RL4, (7*16)(%r11);
13874
13875- popq %r12;
13876+ popq %r14;
13877
13878+ pax_force_retaddr
13879 ret;
13880 ENDPROC(cast5_ctr_16way)
13881diff --git a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
13882index e3531f8..e123f35 100644
13883--- a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
13884+++ b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
13885@@ -24,6 +24,7 @@
13886 */
13887
13888 #include <linux/linkage.h>
13889+#include <asm/alternative-asm.h>
13890 #include "glue_helper-asm-avx.S"
13891
13892 .file "cast6-avx-x86_64-asm_64.S"
13893@@ -295,6 +296,7 @@ __cast6_enc_blk8:
13894 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
13895 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
13896
13897+ pax_force_retaddr
13898 ret;
13899 ENDPROC(__cast6_enc_blk8)
13900
13901@@ -340,6 +342,7 @@ __cast6_dec_blk8:
13902 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
13903 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
13904
13905+ pax_force_retaddr
13906 ret;
13907 ENDPROC(__cast6_dec_blk8)
13908
13909@@ -358,6 +361,7 @@ ENTRY(cast6_ecb_enc_8way)
13910
13911 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13912
13913+ pax_force_retaddr
13914 ret;
13915 ENDPROC(cast6_ecb_enc_8way)
13916
13917@@ -376,6 +380,7 @@ ENTRY(cast6_ecb_dec_8way)
13918
13919 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13920
13921+ pax_force_retaddr
13922 ret;
13923 ENDPROC(cast6_ecb_dec_8way)
13924
13925@@ -386,19 +391,20 @@ ENTRY(cast6_cbc_dec_8way)
13926 * %rdx: src
13927 */
13928
13929- pushq %r12;
13930+ pushq %r14;
13931
13932 movq %rsi, %r11;
13933- movq %rdx, %r12;
13934+ movq %rdx, %r14;
13935
13936 load_8way(%rdx, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13937
13938 call __cast6_dec_blk8;
13939
13940- store_cbc_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13941+ store_cbc_8way(%r14, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13942
13943- popq %r12;
13944+ popq %r14;
13945
13946+ pax_force_retaddr
13947 ret;
13948 ENDPROC(cast6_cbc_dec_8way)
13949
13950@@ -410,20 +416,21 @@ ENTRY(cast6_ctr_8way)
13951 * %rcx: iv (little endian, 128bit)
13952 */
13953
13954- pushq %r12;
13955+ pushq %r14;
13956
13957 movq %rsi, %r11;
13958- movq %rdx, %r12;
13959+ movq %rdx, %r14;
13960
13961 load_ctr_8way(%rcx, .Lbswap128_mask, RA1, RB1, RC1, RD1, RA2, RB2, RC2,
13962 RD2, RX, RKR, RKM);
13963
13964 call __cast6_enc_blk8;
13965
13966- store_ctr_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13967+ store_ctr_8way(%r14, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13968
13969- popq %r12;
13970+ popq %r14;
13971
13972+ pax_force_retaddr
13973 ret;
13974 ENDPROC(cast6_ctr_8way)
13975
13976@@ -446,6 +453,7 @@ ENTRY(cast6_xts_enc_8way)
13977 /* dst <= regs xor IVs(in dst) */
13978 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13979
13980+ pax_force_retaddr
13981 ret;
13982 ENDPROC(cast6_xts_enc_8way)
13983
13984@@ -468,5 +476,6 @@ ENTRY(cast6_xts_dec_8way)
13985 /* dst <= regs xor IVs(in dst) */
13986 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13987
13988+ pax_force_retaddr
13989 ret;
13990 ENDPROC(cast6_xts_dec_8way)
13991diff --git a/arch/x86/crypto/crc32c-pcl-intel-asm_64.S b/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
13992index 26d49eb..c0a8c84 100644
13993--- a/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
13994+++ b/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
13995@@ -45,6 +45,7 @@
13996
13997 #include <asm/inst.h>
13998 #include <linux/linkage.h>
13999+#include <asm/alternative-asm.h>
14000
14001 ## ISCSI CRC 32 Implementation with crc32 and pclmulqdq Instruction
14002
14003@@ -309,6 +310,7 @@ do_return:
14004 popq %rsi
14005 popq %rdi
14006 popq %rbx
14007+ pax_force_retaddr
14008 ret
14009
14010 ################################################################
14011diff --git a/arch/x86/crypto/ghash-clmulni-intel_asm.S b/arch/x86/crypto/ghash-clmulni-intel_asm.S
14012index 5d1e007..098cb4f 100644
14013--- a/arch/x86/crypto/ghash-clmulni-intel_asm.S
14014+++ b/arch/x86/crypto/ghash-clmulni-intel_asm.S
14015@@ -18,6 +18,7 @@
14016
14017 #include <linux/linkage.h>
14018 #include <asm/inst.h>
14019+#include <asm/alternative-asm.h>
14020
14021 .data
14022
14023@@ -89,6 +90,7 @@ __clmul_gf128mul_ble:
14024 psrlq $1, T2
14025 pxor T2, T1
14026 pxor T1, DATA
14027+ pax_force_retaddr
14028 ret
14029 ENDPROC(__clmul_gf128mul_ble)
14030
14031@@ -101,6 +103,7 @@ ENTRY(clmul_ghash_mul)
14032 call __clmul_gf128mul_ble
14033 PSHUFB_XMM BSWAP DATA
14034 movups DATA, (%rdi)
14035+ pax_force_retaddr
14036 ret
14037 ENDPROC(clmul_ghash_mul)
14038
14039@@ -128,5 +131,6 @@ ENTRY(clmul_ghash_update)
14040 PSHUFB_XMM BSWAP DATA
14041 movups DATA, (%rdi)
14042 .Lupdate_just_ret:
14043+ pax_force_retaddr
14044 ret
14045 ENDPROC(clmul_ghash_update)
14046diff --git a/arch/x86/crypto/salsa20-x86_64-asm_64.S b/arch/x86/crypto/salsa20-x86_64-asm_64.S
14047index 9279e0b..c4b3d2c 100644
14048--- a/arch/x86/crypto/salsa20-x86_64-asm_64.S
14049+++ b/arch/x86/crypto/salsa20-x86_64-asm_64.S
14050@@ -1,4 +1,5 @@
14051 #include <linux/linkage.h>
14052+#include <asm/alternative-asm.h>
14053
14054 # enter salsa20_encrypt_bytes
14055 ENTRY(salsa20_encrypt_bytes)
14056@@ -789,6 +790,7 @@ ENTRY(salsa20_encrypt_bytes)
14057 add %r11,%rsp
14058 mov %rdi,%rax
14059 mov %rsi,%rdx
14060+ pax_force_retaddr
14061 ret
14062 # bytesatleast65:
14063 ._bytesatleast65:
14064@@ -889,6 +891,7 @@ ENTRY(salsa20_keysetup)
14065 add %r11,%rsp
14066 mov %rdi,%rax
14067 mov %rsi,%rdx
14068+ pax_force_retaddr
14069 ret
14070 ENDPROC(salsa20_keysetup)
14071
14072@@ -914,5 +917,6 @@ ENTRY(salsa20_ivsetup)
14073 add %r11,%rsp
14074 mov %rdi,%rax
14075 mov %rsi,%rdx
14076+ pax_force_retaddr
14077 ret
14078 ENDPROC(salsa20_ivsetup)
14079diff --git a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
14080index 2f202f4..d9164d6 100644
14081--- a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
14082+++ b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
14083@@ -24,6 +24,7 @@
14084 */
14085
14086 #include <linux/linkage.h>
14087+#include <asm/alternative-asm.h>
14088 #include "glue_helper-asm-avx.S"
14089
14090 .file "serpent-avx-x86_64-asm_64.S"
14091@@ -618,6 +619,7 @@ __serpent_enc_blk8_avx:
14092 write_blocks(RA1, RB1, RC1, RD1, RK0, RK1, RK2);
14093 write_blocks(RA2, RB2, RC2, RD2, RK0, RK1, RK2);
14094
14095+ pax_force_retaddr
14096 ret;
14097 ENDPROC(__serpent_enc_blk8_avx)
14098
14099@@ -672,6 +674,7 @@ __serpent_dec_blk8_avx:
14100 write_blocks(RC1, RD1, RB1, RE1, RK0, RK1, RK2);
14101 write_blocks(RC2, RD2, RB2, RE2, RK0, RK1, RK2);
14102
14103+ pax_force_retaddr
14104 ret;
14105 ENDPROC(__serpent_dec_blk8_avx)
14106
14107@@ -688,6 +691,7 @@ ENTRY(serpent_ecb_enc_8way_avx)
14108
14109 store_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14110
14111+ pax_force_retaddr
14112 ret;
14113 ENDPROC(serpent_ecb_enc_8way_avx)
14114
14115@@ -704,6 +708,7 @@ ENTRY(serpent_ecb_dec_8way_avx)
14116
14117 store_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
14118
14119+ pax_force_retaddr
14120 ret;
14121 ENDPROC(serpent_ecb_dec_8way_avx)
14122
14123@@ -720,6 +725,7 @@ ENTRY(serpent_cbc_dec_8way_avx)
14124
14125 store_cbc_8way(%rdx, %rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
14126
14127+ pax_force_retaddr
14128 ret;
14129 ENDPROC(serpent_cbc_dec_8way_avx)
14130
14131@@ -738,6 +744,7 @@ ENTRY(serpent_ctr_8way_avx)
14132
14133 store_ctr_8way(%rdx, %rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14134
14135+ pax_force_retaddr
14136 ret;
14137 ENDPROC(serpent_ctr_8way_avx)
14138
14139@@ -758,6 +765,7 @@ ENTRY(serpent_xts_enc_8way_avx)
14140 /* dst <= regs xor IVs(in dst) */
14141 store_xts_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14142
14143+ pax_force_retaddr
14144 ret;
14145 ENDPROC(serpent_xts_enc_8way_avx)
14146
14147@@ -778,5 +786,6 @@ ENTRY(serpent_xts_dec_8way_avx)
14148 /* dst <= regs xor IVs(in dst) */
14149 store_xts_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
14150
14151+ pax_force_retaddr
14152 ret;
14153 ENDPROC(serpent_xts_dec_8way_avx)
14154diff --git a/arch/x86/crypto/serpent-avx2-asm_64.S b/arch/x86/crypto/serpent-avx2-asm_64.S
14155index b222085..abd483c 100644
14156--- a/arch/x86/crypto/serpent-avx2-asm_64.S
14157+++ b/arch/x86/crypto/serpent-avx2-asm_64.S
14158@@ -15,6 +15,7 @@
14159 */
14160
14161 #include <linux/linkage.h>
14162+#include <asm/alternative-asm.h>
14163 #include "glue_helper-asm-avx2.S"
14164
14165 .file "serpent-avx2-asm_64.S"
14166@@ -610,6 +611,7 @@ __serpent_enc_blk16:
14167 write_blocks(RA1, RB1, RC1, RD1, RK0, RK1, RK2);
14168 write_blocks(RA2, RB2, RC2, RD2, RK0, RK1, RK2);
14169
14170+ pax_force_retaddr
14171 ret;
14172 ENDPROC(__serpent_enc_blk16)
14173
14174@@ -664,6 +666,7 @@ __serpent_dec_blk16:
14175 write_blocks(RC1, RD1, RB1, RE1, RK0, RK1, RK2);
14176 write_blocks(RC2, RD2, RB2, RE2, RK0, RK1, RK2);
14177
14178+ pax_force_retaddr
14179 ret;
14180 ENDPROC(__serpent_dec_blk16)
14181
14182@@ -684,6 +687,7 @@ ENTRY(serpent_ecb_enc_16way)
14183
14184 vzeroupper;
14185
14186+ pax_force_retaddr
14187 ret;
14188 ENDPROC(serpent_ecb_enc_16way)
14189
14190@@ -704,6 +708,7 @@ ENTRY(serpent_ecb_dec_16way)
14191
14192 vzeroupper;
14193
14194+ pax_force_retaddr
14195 ret;
14196 ENDPROC(serpent_ecb_dec_16way)
14197
14198@@ -725,6 +730,7 @@ ENTRY(serpent_cbc_dec_16way)
14199
14200 vzeroupper;
14201
14202+ pax_force_retaddr
14203 ret;
14204 ENDPROC(serpent_cbc_dec_16way)
14205
14206@@ -748,6 +754,7 @@ ENTRY(serpent_ctr_16way)
14207
14208 vzeroupper;
14209
14210+ pax_force_retaddr
14211 ret;
14212 ENDPROC(serpent_ctr_16way)
14213
14214@@ -772,6 +779,7 @@ ENTRY(serpent_xts_enc_16way)
14215
14216 vzeroupper;
14217
14218+ pax_force_retaddr
14219 ret;
14220 ENDPROC(serpent_xts_enc_16way)
14221
14222@@ -796,5 +804,6 @@ ENTRY(serpent_xts_dec_16way)
14223
14224 vzeroupper;
14225
14226+ pax_force_retaddr
14227 ret;
14228 ENDPROC(serpent_xts_dec_16way)
14229diff --git a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
14230index acc066c..1559cc4 100644
14231--- a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
14232+++ b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
14233@@ -25,6 +25,7 @@
14234 */
14235
14236 #include <linux/linkage.h>
14237+#include <asm/alternative-asm.h>
14238
14239 .file "serpent-sse2-x86_64-asm_64.S"
14240 .text
14241@@ -690,12 +691,14 @@ ENTRY(__serpent_enc_blk_8way)
14242 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
14243 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
14244
14245+ pax_force_retaddr
14246 ret;
14247
14248 .L__enc_xor8:
14249 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
14250 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
14251
14252+ pax_force_retaddr
14253 ret;
14254 ENDPROC(__serpent_enc_blk_8way)
14255
14256@@ -750,5 +753,6 @@ ENTRY(serpent_dec_blk_8way)
14257 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
14258 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
14259
14260+ pax_force_retaddr
14261 ret;
14262 ENDPROC(serpent_dec_blk_8way)
14263diff --git a/arch/x86/crypto/sha1_ssse3_asm.S b/arch/x86/crypto/sha1_ssse3_asm.S
14264index a410950..9dfe7ad 100644
14265--- a/arch/x86/crypto/sha1_ssse3_asm.S
14266+++ b/arch/x86/crypto/sha1_ssse3_asm.S
14267@@ -29,6 +29,7 @@
14268 */
14269
14270 #include <linux/linkage.h>
14271+#include <asm/alternative-asm.h>
14272
14273 #define CTX %rdi // arg1
14274 #define BUF %rsi // arg2
14275@@ -75,9 +76,9 @@
14276
14277 push %rbx
14278 push %rbp
14279- push %r12
14280+ push %r14
14281
14282- mov %rsp, %r12
14283+ mov %rsp, %r14
14284 sub $64, %rsp # allocate workspace
14285 and $~15, %rsp # align stack
14286
14287@@ -99,11 +100,12 @@
14288 xor %rax, %rax
14289 rep stosq
14290
14291- mov %r12, %rsp # deallocate workspace
14292+ mov %r14, %rsp # deallocate workspace
14293
14294- pop %r12
14295+ pop %r14
14296 pop %rbp
14297 pop %rbx
14298+ pax_force_retaddr
14299 ret
14300
14301 ENDPROC(\name)
14302diff --git a/arch/x86/crypto/sha256-avx-asm.S b/arch/x86/crypto/sha256-avx-asm.S
14303index 642f156..51a513c 100644
14304--- a/arch/x86/crypto/sha256-avx-asm.S
14305+++ b/arch/x86/crypto/sha256-avx-asm.S
14306@@ -49,6 +49,7 @@
14307
14308 #ifdef CONFIG_AS_AVX
14309 #include <linux/linkage.h>
14310+#include <asm/alternative-asm.h>
14311
14312 ## assume buffers not aligned
14313 #define VMOVDQ vmovdqu
14314@@ -460,6 +461,7 @@ done_hash:
14315 popq %r13
14316 popq %rbp
14317 popq %rbx
14318+ pax_force_retaddr
14319 ret
14320 ENDPROC(sha256_transform_avx)
14321
14322diff --git a/arch/x86/crypto/sha256-avx2-asm.S b/arch/x86/crypto/sha256-avx2-asm.S
14323index 9e86944..3795e6a 100644
14324--- a/arch/x86/crypto/sha256-avx2-asm.S
14325+++ b/arch/x86/crypto/sha256-avx2-asm.S
14326@@ -50,6 +50,7 @@
14327
14328 #ifdef CONFIG_AS_AVX2
14329 #include <linux/linkage.h>
14330+#include <asm/alternative-asm.h>
14331
14332 ## assume buffers not aligned
14333 #define VMOVDQ vmovdqu
14334@@ -720,6 +721,7 @@ done_hash:
14335 popq %r12
14336 popq %rbp
14337 popq %rbx
14338+ pax_force_retaddr
14339 ret
14340 ENDPROC(sha256_transform_rorx)
14341
14342diff --git a/arch/x86/crypto/sha256-ssse3-asm.S b/arch/x86/crypto/sha256-ssse3-asm.S
14343index f833b74..8c62a9e 100644
14344--- a/arch/x86/crypto/sha256-ssse3-asm.S
14345+++ b/arch/x86/crypto/sha256-ssse3-asm.S
14346@@ -47,6 +47,7 @@
14347 ########################################################################
14348
14349 #include <linux/linkage.h>
14350+#include <asm/alternative-asm.h>
14351
14352 ## assume buffers not aligned
14353 #define MOVDQ movdqu
14354@@ -471,6 +472,7 @@ done_hash:
14355 popq %rbp
14356 popq %rbx
14357
14358+ pax_force_retaddr
14359 ret
14360 ENDPROC(sha256_transform_ssse3)
14361
14362diff --git a/arch/x86/crypto/sha512-avx-asm.S b/arch/x86/crypto/sha512-avx-asm.S
14363index 974dde9..a823ff9 100644
14364--- a/arch/x86/crypto/sha512-avx-asm.S
14365+++ b/arch/x86/crypto/sha512-avx-asm.S
14366@@ -49,6 +49,7 @@
14367
14368 #ifdef CONFIG_AS_AVX
14369 #include <linux/linkage.h>
14370+#include <asm/alternative-asm.h>
14371
14372 .text
14373
14374@@ -364,6 +365,7 @@ updateblock:
14375 mov frame_RSPSAVE(%rsp), %rsp
14376
14377 nowork:
14378+ pax_force_retaddr
14379 ret
14380 ENDPROC(sha512_transform_avx)
14381
14382diff --git a/arch/x86/crypto/sha512-avx2-asm.S b/arch/x86/crypto/sha512-avx2-asm.S
14383index 568b961..ed20c37 100644
14384--- a/arch/x86/crypto/sha512-avx2-asm.S
14385+++ b/arch/x86/crypto/sha512-avx2-asm.S
14386@@ -51,6 +51,7 @@
14387
14388 #ifdef CONFIG_AS_AVX2
14389 #include <linux/linkage.h>
14390+#include <asm/alternative-asm.h>
14391
14392 .text
14393
14394@@ -678,6 +679,7 @@ done_hash:
14395
14396 # Restore Stack Pointer
14397 mov frame_RSPSAVE(%rsp), %rsp
14398+ pax_force_retaddr
14399 ret
14400 ENDPROC(sha512_transform_rorx)
14401
14402diff --git a/arch/x86/crypto/sha512-ssse3-asm.S b/arch/x86/crypto/sha512-ssse3-asm.S
14403index fb56855..6edd768 100644
14404--- a/arch/x86/crypto/sha512-ssse3-asm.S
14405+++ b/arch/x86/crypto/sha512-ssse3-asm.S
14406@@ -48,6 +48,7 @@
14407 ########################################################################
14408
14409 #include <linux/linkage.h>
14410+#include <asm/alternative-asm.h>
14411
14412 .text
14413
14414@@ -363,6 +364,7 @@ updateblock:
14415 mov frame_RSPSAVE(%rsp), %rsp
14416
14417 nowork:
14418+ pax_force_retaddr
14419 ret
14420 ENDPROC(sha512_transform_ssse3)
14421
14422diff --git a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
14423index 0505813..b067311 100644
14424--- a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
14425+++ b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
14426@@ -24,6 +24,7 @@
14427 */
14428
14429 #include <linux/linkage.h>
14430+#include <asm/alternative-asm.h>
14431 #include "glue_helper-asm-avx.S"
14432
14433 .file "twofish-avx-x86_64-asm_64.S"
14434@@ -284,6 +285,7 @@ __twofish_enc_blk8:
14435 outunpack_blocks(RC1, RD1, RA1, RB1, RK1, RX0, RY0, RK2);
14436 outunpack_blocks(RC2, RD2, RA2, RB2, RK1, RX0, RY0, RK2);
14437
14438+ pax_force_retaddr
14439 ret;
14440 ENDPROC(__twofish_enc_blk8)
14441
14442@@ -324,6 +326,7 @@ __twofish_dec_blk8:
14443 outunpack_blocks(RA1, RB1, RC1, RD1, RK1, RX0, RY0, RK2);
14444 outunpack_blocks(RA2, RB2, RC2, RD2, RK1, RX0, RY0, RK2);
14445
14446+ pax_force_retaddr
14447 ret;
14448 ENDPROC(__twofish_dec_blk8)
14449
14450@@ -342,6 +345,7 @@ ENTRY(twofish_ecb_enc_8way)
14451
14452 store_8way(%r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14453
14454+ pax_force_retaddr
14455 ret;
14456 ENDPROC(twofish_ecb_enc_8way)
14457
14458@@ -360,6 +364,7 @@ ENTRY(twofish_ecb_dec_8way)
14459
14460 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14461
14462+ pax_force_retaddr
14463 ret;
14464 ENDPROC(twofish_ecb_dec_8way)
14465
14466@@ -370,19 +375,20 @@ ENTRY(twofish_cbc_dec_8way)
14467 * %rdx: src
14468 */
14469
14470- pushq %r12;
14471+ pushq %r14;
14472
14473 movq %rsi, %r11;
14474- movq %rdx, %r12;
14475+ movq %rdx, %r14;
14476
14477 load_8way(%rdx, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14478
14479 call __twofish_dec_blk8;
14480
14481- store_cbc_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14482+ store_cbc_8way(%r14, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14483
14484- popq %r12;
14485+ popq %r14;
14486
14487+ pax_force_retaddr
14488 ret;
14489 ENDPROC(twofish_cbc_dec_8way)
14490
14491@@ -394,20 +400,21 @@ ENTRY(twofish_ctr_8way)
14492 * %rcx: iv (little endian, 128bit)
14493 */
14494
14495- pushq %r12;
14496+ pushq %r14;
14497
14498 movq %rsi, %r11;
14499- movq %rdx, %r12;
14500+ movq %rdx, %r14;
14501
14502 load_ctr_8way(%rcx, .Lbswap128_mask, RA1, RB1, RC1, RD1, RA2, RB2, RC2,
14503 RD2, RX0, RX1, RY0);
14504
14505 call __twofish_enc_blk8;
14506
14507- store_ctr_8way(%r12, %r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14508+ store_ctr_8way(%r14, %r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14509
14510- popq %r12;
14511+ popq %r14;
14512
14513+ pax_force_retaddr
14514 ret;
14515 ENDPROC(twofish_ctr_8way)
14516
14517@@ -430,6 +437,7 @@ ENTRY(twofish_xts_enc_8way)
14518 /* dst <= regs xor IVs(in dst) */
14519 store_xts_8way(%r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14520
14521+ pax_force_retaddr
14522 ret;
14523 ENDPROC(twofish_xts_enc_8way)
14524
14525@@ -452,5 +460,6 @@ ENTRY(twofish_xts_dec_8way)
14526 /* dst <= regs xor IVs(in dst) */
14527 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14528
14529+ pax_force_retaddr
14530 ret;
14531 ENDPROC(twofish_xts_dec_8way)
14532diff --git a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
14533index 1c3b7ce..02f578d 100644
14534--- a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
14535+++ b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
14536@@ -21,6 +21,7 @@
14537 */
14538
14539 #include <linux/linkage.h>
14540+#include <asm/alternative-asm.h>
14541
14542 .file "twofish-x86_64-asm-3way.S"
14543 .text
14544@@ -258,6 +259,7 @@ ENTRY(__twofish_enc_blk_3way)
14545 popq %r13;
14546 popq %r14;
14547 popq %r15;
14548+ pax_force_retaddr
14549 ret;
14550
14551 .L__enc_xor3:
14552@@ -269,6 +271,7 @@ ENTRY(__twofish_enc_blk_3way)
14553 popq %r13;
14554 popq %r14;
14555 popq %r15;
14556+ pax_force_retaddr
14557 ret;
14558 ENDPROC(__twofish_enc_blk_3way)
14559
14560@@ -308,5 +311,6 @@ ENTRY(twofish_dec_blk_3way)
14561 popq %r13;
14562 popq %r14;
14563 popq %r15;
14564+ pax_force_retaddr
14565 ret;
14566 ENDPROC(twofish_dec_blk_3way)
14567diff --git a/arch/x86/crypto/twofish-x86_64-asm_64.S b/arch/x86/crypto/twofish-x86_64-asm_64.S
14568index a039d21..524b8b2 100644
14569--- a/arch/x86/crypto/twofish-x86_64-asm_64.S
14570+++ b/arch/x86/crypto/twofish-x86_64-asm_64.S
14571@@ -22,6 +22,7 @@
14572
14573 #include <linux/linkage.h>
14574 #include <asm/asm-offsets.h>
14575+#include <asm/alternative-asm.h>
14576
14577 #define a_offset 0
14578 #define b_offset 4
14579@@ -265,6 +266,7 @@ ENTRY(twofish_enc_blk)
14580
14581 popq R1
14582 movq $1,%rax
14583+ pax_force_retaddr
14584 ret
14585 ENDPROC(twofish_enc_blk)
14586
14587@@ -317,5 +319,6 @@ ENTRY(twofish_dec_blk)
14588
14589 popq R1
14590 movq $1,%rax
14591+ pax_force_retaddr
14592 ret
14593 ENDPROC(twofish_dec_blk)
14594diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
14595index df91466..74b31cb 100644
14596--- a/arch/x86/ia32/ia32_aout.c
14597+++ b/arch/x86/ia32/ia32_aout.c
14598@@ -153,6 +153,8 @@ static int aout_core_dump(struct coredump_params *cprm)
14599 unsigned long dump_start, dump_size;
14600 struct user32 dump;
14601
14602+ memset(&dump, 0, sizeof(dump));
14603+
14604 fs = get_fs();
14605 set_fs(KERNEL_DS);
14606 has_dumped = 1;
14607diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
14608index f9e181a..300544c 100644
14609--- a/arch/x86/ia32/ia32_signal.c
14610+++ b/arch/x86/ia32/ia32_signal.c
14611@@ -218,7 +218,7 @@ asmlinkage long sys32_sigreturn(void)
14612 if (__get_user(set.sig[0], &frame->sc.oldmask)
14613 || (_COMPAT_NSIG_WORDS > 1
14614 && __copy_from_user((((char *) &set.sig) + 4),
14615- &frame->extramask,
14616+ frame->extramask,
14617 sizeof(frame->extramask))))
14618 goto badframe;
14619
14620@@ -338,7 +338,7 @@ static void __user *get_sigframe(struct ksignal *ksig, struct pt_regs *regs,
14621 sp -= frame_size;
14622 /* Align the stack pointer according to the i386 ABI,
14623 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
14624- sp = ((sp + 4) & -16ul) - 4;
14625+ sp = ((sp - 12) & -16ul) - 4;
14626 return (void __user *) sp;
14627 }
14628
14629@@ -383,10 +383,10 @@ int ia32_setup_frame(int sig, struct ksignal *ksig,
14630 } else {
14631 /* Return stub is in 32bit vsyscall page */
14632 if (current->mm->context.vdso)
14633- restorer = current->mm->context.vdso +
14634- selected_vdso32->sym___kernel_sigreturn;
14635+ restorer = (void __force_user *)(current->mm->context.vdso +
14636+ selected_vdso32->sym___kernel_sigreturn);
14637 else
14638- restorer = &frame->retcode;
14639+ restorer = frame->retcode;
14640 }
14641
14642 put_user_try {
14643@@ -396,7 +396,7 @@ int ia32_setup_frame(int sig, struct ksignal *ksig,
14644 * These are actually not used anymore, but left because some
14645 * gdb versions depend on them as a marker.
14646 */
14647- put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
14648+ put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
14649 } put_user_catch(err);
14650
14651 if (err)
14652@@ -438,7 +438,7 @@ int ia32_setup_rt_frame(int sig, struct ksignal *ksig,
14653 0xb8,
14654 __NR_ia32_rt_sigreturn,
14655 0x80cd,
14656- 0,
14657+ 0
14658 };
14659
14660 frame = get_sigframe(ksig, regs, sizeof(*frame), &fpstate);
14661@@ -461,16 +461,19 @@ int ia32_setup_rt_frame(int sig, struct ksignal *ksig,
14662
14663 if (ksig->ka.sa.sa_flags & SA_RESTORER)
14664 restorer = ksig->ka.sa.sa_restorer;
14665+ else if (current->mm->context.vdso)
14666+ /* Return stub is in 32bit vsyscall page */
14667+ restorer = (void __force_user *)(current->mm->context.vdso +
14668+ selected_vdso32->sym___kernel_rt_sigreturn);
14669 else
14670- restorer = current->mm->context.vdso +
14671- selected_vdso32->sym___kernel_rt_sigreturn;
14672+ restorer = frame->retcode;
14673 put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
14674
14675 /*
14676 * Not actually used anymore, but left because some gdb
14677 * versions need it.
14678 */
14679- put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
14680+ put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
14681 } put_user_catch(err);
14682
14683 err |= copy_siginfo_to_user32(&frame->info, &ksig->info);
14684diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
14685index ffe7122..899bad3 100644
14686--- a/arch/x86/ia32/ia32entry.S
14687+++ b/arch/x86/ia32/ia32entry.S
14688@@ -15,8 +15,10 @@
14689 #include <asm/irqflags.h>
14690 #include <asm/asm.h>
14691 #include <asm/smap.h>
14692+#include <asm/pgtable.h>
14693 #include <linux/linkage.h>
14694 #include <linux/err.h>
14695+#include <asm/alternative-asm.h>
14696
14697 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
14698 #include <linux/elf-em.h>
14699@@ -62,12 +64,12 @@
14700 */
14701 .macro LOAD_ARGS32 offset, _r9=0
14702 .if \_r9
14703- movl \offset+16(%rsp),%r9d
14704+ movl \offset+R9(%rsp),%r9d
14705 .endif
14706- movl \offset+40(%rsp),%ecx
14707- movl \offset+48(%rsp),%edx
14708- movl \offset+56(%rsp),%esi
14709- movl \offset+64(%rsp),%edi
14710+ movl \offset+RCX(%rsp),%ecx
14711+ movl \offset+RDX(%rsp),%edx
14712+ movl \offset+RSI(%rsp),%esi
14713+ movl \offset+RDI(%rsp),%edi
14714 movl %eax,%eax /* zero extension */
14715 .endm
14716
14717@@ -96,6 +98,32 @@ ENTRY(native_irq_enable_sysexit)
14718 ENDPROC(native_irq_enable_sysexit)
14719 #endif
14720
14721+ .macro pax_enter_kernel_user
14722+ pax_set_fptr_mask
14723+#ifdef CONFIG_PAX_MEMORY_UDEREF
14724+ call pax_enter_kernel_user
14725+#endif
14726+ .endm
14727+
14728+ .macro pax_exit_kernel_user
14729+#ifdef CONFIG_PAX_MEMORY_UDEREF
14730+ call pax_exit_kernel_user
14731+#endif
14732+#ifdef CONFIG_PAX_RANDKSTACK
14733+ pushq %rax
14734+ pushq %r11
14735+ call pax_randomize_kstack
14736+ popq %r11
14737+ popq %rax
14738+#endif
14739+ .endm
14740+
14741+ .macro pax_erase_kstack
14742+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14743+ call pax_erase_kstack
14744+#endif
14745+ .endm
14746+
14747 /*
14748 * 32bit SYSENTER instruction entry.
14749 *
14750@@ -122,12 +150,6 @@ ENTRY(ia32_sysenter_target)
14751 CFI_REGISTER rsp,rbp
14752 SWAPGS_UNSAFE_STACK
14753 movq PER_CPU_VAR(kernel_stack), %rsp
14754- addq $(KERNEL_STACK_OFFSET),%rsp
14755- /*
14756- * No need to follow this irqs on/off section: the syscall
14757- * disabled irqs, here we enable it straight after entry:
14758- */
14759- ENABLE_INTERRUPTS(CLBR_NONE)
14760 movl %ebp,%ebp /* zero extension */
14761 pushq_cfi $__USER32_DS
14762 /*CFI_REL_OFFSET ss,0*/
14763@@ -135,23 +157,46 @@ ENTRY(ia32_sysenter_target)
14764 CFI_REL_OFFSET rsp,0
14765 pushfq_cfi
14766 /*CFI_REL_OFFSET rflags,0*/
14767- movl TI_sysenter_return+THREAD_INFO(%rsp,3*8-KERNEL_STACK_OFFSET),%r10d
14768- CFI_REGISTER rip,r10
14769+ orl $X86_EFLAGS_IF,(%rsp)
14770+ GET_THREAD_INFO(%r11)
14771+ movl TI_sysenter_return(%r11), %r11d
14772+ CFI_REGISTER rip,r11
14773 pushq_cfi $__USER32_CS
14774 /*CFI_REL_OFFSET cs,0*/
14775 movl %eax, %eax
14776- pushq_cfi %r10
14777+ pushq_cfi %r11
14778 CFI_REL_OFFSET rip,0
14779 pushq_cfi %rax
14780 cld
14781 SAVE_ARGS 0,1,0
14782+ pax_enter_kernel_user
14783+
14784+#ifdef CONFIG_PAX_RANDKSTACK
14785+ pax_erase_kstack
14786+#endif
14787+
14788+ /*
14789+ * No need to follow this irqs on/off section: the syscall
14790+ * disabled irqs, here we enable it straight after entry:
14791+ */
14792+ ENABLE_INTERRUPTS(CLBR_NONE)
14793 /* no need to do an access_ok check here because rbp has been
14794 32bit zero extended */
14795+
14796+#ifdef CONFIG_PAX_MEMORY_UDEREF
14797+ addq pax_user_shadow_base,%rbp
14798+ ASM_PAX_OPEN_USERLAND
14799+#endif
14800+
14801 ASM_STAC
14802 1: movl (%rbp),%ebp
14803 _ASM_EXTABLE(1b,ia32_badarg)
14804 ASM_CLAC
14805
14806+#ifdef CONFIG_PAX_MEMORY_UDEREF
14807+ ASM_PAX_CLOSE_USERLAND
14808+#endif
14809+
14810 /*
14811 * Sysenter doesn't filter flags, so we need to clear NT
14812 * ourselves. To save a few cycles, we can check whether
14813@@ -161,8 +206,9 @@ ENTRY(ia32_sysenter_target)
14814 jnz sysenter_fix_flags
14815 sysenter_flags_fixed:
14816
14817- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14818- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14819+ GET_THREAD_INFO(%r11)
14820+ orl $TS_COMPAT,TI_status(%r11)
14821+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
14822 CFI_REMEMBER_STATE
14823 jnz sysenter_tracesys
14824 cmpq $(IA32_NR_syscalls-1),%rax
14825@@ -172,15 +218,18 @@ sysenter_do_call:
14826 sysenter_dispatch:
14827 call *ia32_sys_call_table(,%rax,8)
14828 movq %rax,RAX-ARGOFFSET(%rsp)
14829+ GET_THREAD_INFO(%r11)
14830 DISABLE_INTERRUPTS(CLBR_NONE)
14831 TRACE_IRQS_OFF
14832- testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14833+ testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
14834 jnz sysexit_audit
14835 sysexit_from_sys_call:
14836- andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14837+ pax_exit_kernel_user
14838+ pax_erase_kstack
14839+ andl $~TS_COMPAT,TI_status(%r11)
14840 /* clear IF, that popfq doesn't enable interrupts early */
14841- andl $~0x200,EFLAGS-R11(%rsp)
14842- movl RIP-R11(%rsp),%edx /* User %eip */
14843+ andl $~X86_EFLAGS_IF,EFLAGS(%rsp)
14844+ movl RIP(%rsp),%edx /* User %eip */
14845 CFI_REGISTER rip,rdx
14846 RESTORE_ARGS 0,24,0,0,0,0
14847 xorq %r8,%r8
14848@@ -205,6 +254,9 @@ sysexit_from_sys_call:
14849 movl %ebx,%esi /* 2nd arg: 1st syscall arg */
14850 movl %eax,%edi /* 1st arg: syscall number */
14851 call __audit_syscall_entry
14852+
14853+ pax_erase_kstack
14854+
14855 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
14856 cmpq $(IA32_NR_syscalls-1),%rax
14857 ja ia32_badsys
14858@@ -216,7 +268,7 @@ sysexit_from_sys_call:
14859 .endm
14860
14861 .macro auditsys_exit exit
14862- testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14863+ testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
14864 jnz ia32_ret_from_sys_call
14865 TRACE_IRQS_ON
14866 ENABLE_INTERRUPTS(CLBR_NONE)
14867@@ -227,11 +279,12 @@ sysexit_from_sys_call:
14868 1: setbe %al /* 1 if error, 0 if not */
14869 movzbl %al,%edi /* zero-extend that into %edi */
14870 call __audit_syscall_exit
14871+ GET_THREAD_INFO(%r11)
14872 movq RAX-ARGOFFSET(%rsp),%rax /* reload syscall return value */
14873 movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi
14874 DISABLE_INTERRUPTS(CLBR_NONE)
14875 TRACE_IRQS_OFF
14876- testl %edi,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14877+ testl %edi,TI_flags(%r11)
14878 jz \exit
14879 CLEAR_RREGS -ARGOFFSET
14880 jmp int_with_check
14881@@ -253,7 +306,7 @@ sysenter_fix_flags:
14882
14883 sysenter_tracesys:
14884 #ifdef CONFIG_AUDITSYSCALL
14885- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14886+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
14887 jz sysenter_auditsys
14888 #endif
14889 SAVE_REST
14890@@ -265,6 +318,9 @@ sysenter_tracesys:
14891 RESTORE_REST
14892 cmpq $(IA32_NR_syscalls-1),%rax
14893 ja int_ret_from_sys_call /* sysenter_tracesys has set RAX(%rsp) */
14894+
14895+ pax_erase_kstack
14896+
14897 jmp sysenter_do_call
14898 CFI_ENDPROC
14899 ENDPROC(ia32_sysenter_target)
14900@@ -292,19 +348,25 @@ ENDPROC(ia32_sysenter_target)
14901 ENTRY(ia32_cstar_target)
14902 CFI_STARTPROC32 simple
14903 CFI_SIGNAL_FRAME
14904- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
14905+ CFI_DEF_CFA rsp,0
14906 CFI_REGISTER rip,rcx
14907 /*CFI_REGISTER rflags,r11*/
14908 SWAPGS_UNSAFE_STACK
14909 movl %esp,%r8d
14910 CFI_REGISTER rsp,r8
14911 movq PER_CPU_VAR(kernel_stack),%rsp
14912+ SAVE_ARGS 8*6,0,0
14913+ pax_enter_kernel_user
14914+
14915+#ifdef CONFIG_PAX_RANDKSTACK
14916+ pax_erase_kstack
14917+#endif
14918+
14919 /*
14920 * No need to follow this irqs on/off section: the syscall
14921 * disabled irqs and here we enable it straight after entry:
14922 */
14923 ENABLE_INTERRUPTS(CLBR_NONE)
14924- SAVE_ARGS 8,0,0
14925 movl %eax,%eax /* zero extension */
14926 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
14927 movq %rcx,RIP-ARGOFFSET(%rsp)
14928@@ -320,12 +382,25 @@ ENTRY(ia32_cstar_target)
14929 /* no need to do an access_ok check here because r8 has been
14930 32bit zero extended */
14931 /* hardware stack frame is complete now */
14932+
14933+#ifdef CONFIG_PAX_MEMORY_UDEREF
14934+ ASM_PAX_OPEN_USERLAND
14935+ movq pax_user_shadow_base,%r8
14936+ addq RSP-ARGOFFSET(%rsp),%r8
14937+#endif
14938+
14939 ASM_STAC
14940 1: movl (%r8),%r9d
14941 _ASM_EXTABLE(1b,ia32_badarg)
14942 ASM_CLAC
14943- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14944- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14945+
14946+#ifdef CONFIG_PAX_MEMORY_UDEREF
14947+ ASM_PAX_CLOSE_USERLAND
14948+#endif
14949+
14950+ GET_THREAD_INFO(%r11)
14951+ orl $TS_COMPAT,TI_status(%r11)
14952+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
14953 CFI_REMEMBER_STATE
14954 jnz cstar_tracesys
14955 cmpq $IA32_NR_syscalls-1,%rax
14956@@ -335,13 +410,16 @@ cstar_do_call:
14957 cstar_dispatch:
14958 call *ia32_sys_call_table(,%rax,8)
14959 movq %rax,RAX-ARGOFFSET(%rsp)
14960+ GET_THREAD_INFO(%r11)
14961 DISABLE_INTERRUPTS(CLBR_NONE)
14962 TRACE_IRQS_OFF
14963- testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14964+ testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
14965 jnz sysretl_audit
14966 sysretl_from_sys_call:
14967- andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14968- RESTORE_ARGS 0,-ARG_SKIP,0,0,0
14969+ pax_exit_kernel_user
14970+ pax_erase_kstack
14971+ andl $~TS_COMPAT,TI_status(%r11)
14972+ RESTORE_ARGS 0,-ORIG_RAX,0,0,0
14973 movl RIP-ARGOFFSET(%rsp),%ecx
14974 CFI_REGISTER rip,rcx
14975 movl EFLAGS-ARGOFFSET(%rsp),%r11d
14976@@ -368,7 +446,7 @@ sysretl_audit:
14977
14978 cstar_tracesys:
14979 #ifdef CONFIG_AUDITSYSCALL
14980- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14981+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
14982 jz cstar_auditsys
14983 #endif
14984 xchgl %r9d,%ebp
14985@@ -382,11 +460,19 @@ cstar_tracesys:
14986 xchgl %ebp,%r9d
14987 cmpq $(IA32_NR_syscalls-1),%rax
14988 ja int_ret_from_sys_call /* cstar_tracesys has set RAX(%rsp) */
14989+
14990+ pax_erase_kstack
14991+
14992 jmp cstar_do_call
14993 END(ia32_cstar_target)
14994
14995 ia32_badarg:
14996 ASM_CLAC
14997+
14998+#ifdef CONFIG_PAX_MEMORY_UDEREF
14999+ ASM_PAX_CLOSE_USERLAND
15000+#endif
15001+
15002 movq $-EFAULT,%rax
15003 jmp ia32_sysret
15004 CFI_ENDPROC
15005@@ -423,19 +509,26 @@ ENTRY(ia32_syscall)
15006 CFI_REL_OFFSET rip,RIP-RIP
15007 PARAVIRT_ADJUST_EXCEPTION_FRAME
15008 SWAPGS
15009- /*
15010- * No need to follow this irqs on/off section: the syscall
15011- * disabled irqs and here we enable it straight after entry:
15012- */
15013- ENABLE_INTERRUPTS(CLBR_NONE)
15014 movl %eax,%eax
15015 pushq_cfi %rax
15016 cld
15017 /* note the registers are not zero extended to the sf.
15018 this could be a problem. */
15019 SAVE_ARGS 0,1,0
15020- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15021- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15022+ pax_enter_kernel_user
15023+
15024+#ifdef CONFIG_PAX_RANDKSTACK
15025+ pax_erase_kstack
15026+#endif
15027+
15028+ /*
15029+ * No need to follow this irqs on/off section: the syscall
15030+ * disabled irqs and here we enable it straight after entry:
15031+ */
15032+ ENABLE_INTERRUPTS(CLBR_NONE)
15033+ GET_THREAD_INFO(%r11)
15034+ orl $TS_COMPAT,TI_status(%r11)
15035+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
15036 jnz ia32_tracesys
15037 cmpq $(IA32_NR_syscalls-1),%rax
15038 ja ia32_badsys
15039@@ -458,6 +551,9 @@ ia32_tracesys:
15040 RESTORE_REST
15041 cmpq $(IA32_NR_syscalls-1),%rax
15042 ja int_ret_from_sys_call /* ia32_tracesys has set RAX(%rsp) */
15043+
15044+ pax_erase_kstack
15045+
15046 jmp ia32_do_call
15047 END(ia32_syscall)
15048
15049diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c
15050index 8e0ceec..af13504 100644
15051--- a/arch/x86/ia32/sys_ia32.c
15052+++ b/arch/x86/ia32/sys_ia32.c
15053@@ -69,8 +69,8 @@ asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long offset_low,
15054 */
15055 static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
15056 {
15057- typeof(ubuf->st_uid) uid = 0;
15058- typeof(ubuf->st_gid) gid = 0;
15059+ typeof(((struct stat64 *)0)->st_uid) uid = 0;
15060+ typeof(((struct stat64 *)0)->st_gid) gid = 0;
15061 SET_UID(uid, from_kuid_munged(current_user_ns(), stat->uid));
15062 SET_GID(gid, from_kgid_munged(current_user_ns(), stat->gid));
15063 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
15064diff --git a/arch/x86/include/asm/alternative-asm.h b/arch/x86/include/asm/alternative-asm.h
15065index 372231c..51b537d 100644
15066--- a/arch/x86/include/asm/alternative-asm.h
15067+++ b/arch/x86/include/asm/alternative-asm.h
15068@@ -18,6 +18,45 @@
15069 .endm
15070 #endif
15071
15072+#ifdef KERNEXEC_PLUGIN
15073+ .macro pax_force_retaddr_bts rip=0
15074+ btsq $63,\rip(%rsp)
15075+ .endm
15076+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
15077+ .macro pax_force_retaddr rip=0, reload=0
15078+ btsq $63,\rip(%rsp)
15079+ .endm
15080+ .macro pax_force_fptr ptr
15081+ btsq $63,\ptr
15082+ .endm
15083+ .macro pax_set_fptr_mask
15084+ .endm
15085+#endif
15086+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
15087+ .macro pax_force_retaddr rip=0, reload=0
15088+ .if \reload
15089+ pax_set_fptr_mask
15090+ .endif
15091+ orq %r12,\rip(%rsp)
15092+ .endm
15093+ .macro pax_force_fptr ptr
15094+ orq %r12,\ptr
15095+ .endm
15096+ .macro pax_set_fptr_mask
15097+ movabs $0x8000000000000000,%r12
15098+ .endm
15099+#endif
15100+#else
15101+ .macro pax_force_retaddr rip=0, reload=0
15102+ .endm
15103+ .macro pax_force_fptr ptr
15104+ .endm
15105+ .macro pax_force_retaddr_bts rip=0
15106+ .endm
15107+ .macro pax_set_fptr_mask
15108+ .endm
15109+#endif
15110+
15111 .macro altinstruction_entry orig alt feature orig_len alt_len
15112 .long \orig - .
15113 .long \alt - .
15114diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h
15115index 473bdbe..b1e3377 100644
15116--- a/arch/x86/include/asm/alternative.h
15117+++ b/arch/x86/include/asm/alternative.h
15118@@ -106,7 +106,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
15119 ".pushsection .discard,\"aw\",@progbits\n" \
15120 DISCARD_ENTRY(1) \
15121 ".popsection\n" \
15122- ".pushsection .altinstr_replacement, \"ax\"\n" \
15123+ ".pushsection .altinstr_replacement, \"a\"\n" \
15124 ALTINSTR_REPLACEMENT(newinstr, feature, 1) \
15125 ".popsection"
15126
15127@@ -120,7 +120,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
15128 DISCARD_ENTRY(1) \
15129 DISCARD_ENTRY(2) \
15130 ".popsection\n" \
15131- ".pushsection .altinstr_replacement, \"ax\"\n" \
15132+ ".pushsection .altinstr_replacement, \"a\"\n" \
15133 ALTINSTR_REPLACEMENT(newinstr1, feature1, 1) \
15134 ALTINSTR_REPLACEMENT(newinstr2, feature2, 2) \
15135 ".popsection"
15136diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
15137index 465b309..ab7e51f 100644
15138--- a/arch/x86/include/asm/apic.h
15139+++ b/arch/x86/include/asm/apic.h
15140@@ -45,7 +45,7 @@ static inline void generic_apic_probe(void)
15141
15142 #ifdef CONFIG_X86_LOCAL_APIC
15143
15144-extern unsigned int apic_verbosity;
15145+extern int apic_verbosity;
15146 extern int local_apic_timer_c2_ok;
15147
15148 extern int disable_apic;
15149diff --git a/arch/x86/include/asm/apm.h b/arch/x86/include/asm/apm.h
15150index 20370c6..a2eb9b0 100644
15151--- a/arch/x86/include/asm/apm.h
15152+++ b/arch/x86/include/asm/apm.h
15153@@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32 func, u32 ebx_in, u32 ecx_in,
15154 __asm__ __volatile__(APM_DO_ZERO_SEGS
15155 "pushl %%edi\n\t"
15156 "pushl %%ebp\n\t"
15157- "lcall *%%cs:apm_bios_entry\n\t"
15158+ "lcall *%%ss:apm_bios_entry\n\t"
15159 "setc %%al\n\t"
15160 "popl %%ebp\n\t"
15161 "popl %%edi\n\t"
15162@@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_asm(u32 func, u32 ebx_in,
15163 __asm__ __volatile__(APM_DO_ZERO_SEGS
15164 "pushl %%edi\n\t"
15165 "pushl %%ebp\n\t"
15166- "lcall *%%cs:apm_bios_entry\n\t"
15167+ "lcall *%%ss:apm_bios_entry\n\t"
15168 "setc %%bl\n\t"
15169 "popl %%ebp\n\t"
15170 "popl %%edi\n\t"
15171diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h
15172index 5e5cd12..3d18208 100644
15173--- a/arch/x86/include/asm/atomic.h
15174+++ b/arch/x86/include/asm/atomic.h
15175@@ -28,6 +28,17 @@ static inline int atomic_read(const atomic_t *v)
15176 }
15177
15178 /**
15179+ * atomic_read_unchecked - read atomic variable
15180+ * @v: pointer of type atomic_unchecked_t
15181+ *
15182+ * Atomically reads the value of @v.
15183+ */
15184+static inline int __intentional_overflow(-1) atomic_read_unchecked(const atomic_unchecked_t *v)
15185+{
15186+ return ACCESS_ONCE((v)->counter);
15187+}
15188+
15189+/**
15190 * atomic_set - set atomic variable
15191 * @v: pointer of type atomic_t
15192 * @i: required value
15193@@ -40,6 +51,18 @@ static inline void atomic_set(atomic_t *v, int i)
15194 }
15195
15196 /**
15197+ * atomic_set_unchecked - set atomic variable
15198+ * @v: pointer of type atomic_unchecked_t
15199+ * @i: required value
15200+ *
15201+ * Atomically sets the value of @v to @i.
15202+ */
15203+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
15204+{
15205+ v->counter = i;
15206+}
15207+
15208+/**
15209 * atomic_add - add integer to atomic variable
15210 * @i: integer value to add
15211 * @v: pointer of type atomic_t
15212@@ -48,7 +71,29 @@ static inline void atomic_set(atomic_t *v, int i)
15213 */
15214 static inline void atomic_add(int i, atomic_t *v)
15215 {
15216- asm volatile(LOCK_PREFIX "addl %1,%0"
15217+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
15218+
15219+#ifdef CONFIG_PAX_REFCOUNT
15220+ "jno 0f\n"
15221+ LOCK_PREFIX "subl %1,%0\n"
15222+ "int $4\n0:\n"
15223+ _ASM_EXTABLE(0b, 0b)
15224+#endif
15225+
15226+ : "+m" (v->counter)
15227+ : "ir" (i));
15228+}
15229+
15230+/**
15231+ * atomic_add_unchecked - add integer to atomic variable
15232+ * @i: integer value to add
15233+ * @v: pointer of type atomic_unchecked_t
15234+ *
15235+ * Atomically adds @i to @v.
15236+ */
15237+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
15238+{
15239+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
15240 : "+m" (v->counter)
15241 : "ir" (i));
15242 }
15243@@ -62,7 +107,29 @@ static inline void atomic_add(int i, atomic_t *v)
15244 */
15245 static inline void atomic_sub(int i, atomic_t *v)
15246 {
15247- asm volatile(LOCK_PREFIX "subl %1,%0"
15248+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
15249+
15250+#ifdef CONFIG_PAX_REFCOUNT
15251+ "jno 0f\n"
15252+ LOCK_PREFIX "addl %1,%0\n"
15253+ "int $4\n0:\n"
15254+ _ASM_EXTABLE(0b, 0b)
15255+#endif
15256+
15257+ : "+m" (v->counter)
15258+ : "ir" (i));
15259+}
15260+
15261+/**
15262+ * atomic_sub_unchecked - subtract integer from atomic variable
15263+ * @i: integer value to subtract
15264+ * @v: pointer of type atomic_unchecked_t
15265+ *
15266+ * Atomically subtracts @i from @v.
15267+ */
15268+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
15269+{
15270+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
15271 : "+m" (v->counter)
15272 : "ir" (i));
15273 }
15274@@ -78,7 +145,7 @@ static inline void atomic_sub(int i, atomic_t *v)
15275 */
15276 static inline int atomic_sub_and_test(int i, atomic_t *v)
15277 {
15278- GEN_BINARY_RMWcc(LOCK_PREFIX "subl", v->counter, "er", i, "%0", "e");
15279+ GEN_BINARY_RMWcc(LOCK_PREFIX "subl", LOCK_PREFIX "addl", v->counter, "er", i, "%0", "e");
15280 }
15281
15282 /**
15283@@ -89,7 +156,27 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
15284 */
15285 static inline void atomic_inc(atomic_t *v)
15286 {
15287- asm volatile(LOCK_PREFIX "incl %0"
15288+ asm volatile(LOCK_PREFIX "incl %0\n"
15289+
15290+#ifdef CONFIG_PAX_REFCOUNT
15291+ "jno 0f\n"
15292+ LOCK_PREFIX "decl %0\n"
15293+ "int $4\n0:\n"
15294+ _ASM_EXTABLE(0b, 0b)
15295+#endif
15296+
15297+ : "+m" (v->counter));
15298+}
15299+
15300+/**
15301+ * atomic_inc_unchecked - increment atomic variable
15302+ * @v: pointer of type atomic_unchecked_t
15303+ *
15304+ * Atomically increments @v by 1.
15305+ */
15306+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
15307+{
15308+ asm volatile(LOCK_PREFIX "incl %0\n"
15309 : "+m" (v->counter));
15310 }
15311
15312@@ -101,7 +188,27 @@ static inline void atomic_inc(atomic_t *v)
15313 */
15314 static inline void atomic_dec(atomic_t *v)
15315 {
15316- asm volatile(LOCK_PREFIX "decl %0"
15317+ asm volatile(LOCK_PREFIX "decl %0\n"
15318+
15319+#ifdef CONFIG_PAX_REFCOUNT
15320+ "jno 0f\n"
15321+ LOCK_PREFIX "incl %0\n"
15322+ "int $4\n0:\n"
15323+ _ASM_EXTABLE(0b, 0b)
15324+#endif
15325+
15326+ : "+m" (v->counter));
15327+}
15328+
15329+/**
15330+ * atomic_dec_unchecked - decrement atomic variable
15331+ * @v: pointer of type atomic_unchecked_t
15332+ *
15333+ * Atomically decrements @v by 1.
15334+ */
15335+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
15336+{
15337+ asm volatile(LOCK_PREFIX "decl %0\n"
15338 : "+m" (v->counter));
15339 }
15340
15341@@ -115,7 +222,7 @@ static inline void atomic_dec(atomic_t *v)
15342 */
15343 static inline int atomic_dec_and_test(atomic_t *v)
15344 {
15345- GEN_UNARY_RMWcc(LOCK_PREFIX "decl", v->counter, "%0", "e");
15346+ GEN_UNARY_RMWcc(LOCK_PREFIX "decl", LOCK_PREFIX "incl", v->counter, "%0", "e");
15347 }
15348
15349 /**
15350@@ -128,7 +235,20 @@ static inline int atomic_dec_and_test(atomic_t *v)
15351 */
15352 static inline int atomic_inc_and_test(atomic_t *v)
15353 {
15354- GEN_UNARY_RMWcc(LOCK_PREFIX "incl", v->counter, "%0", "e");
15355+ GEN_UNARY_RMWcc(LOCK_PREFIX "incl", LOCK_PREFIX "decl", v->counter, "%0", "e");
15356+}
15357+
15358+/**
15359+ * atomic_inc_and_test_unchecked - increment and test
15360+ * @v: pointer of type atomic_unchecked_t
15361+ *
15362+ * Atomically increments @v by 1
15363+ * and returns true if the result is zero, or false for all
15364+ * other cases.
15365+ */
15366+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
15367+{
15368+ GEN_UNARY_RMWcc_unchecked(LOCK_PREFIX "incl", v->counter, "%0", "e");
15369 }
15370
15371 /**
15372@@ -142,7 +262,7 @@ static inline int atomic_inc_and_test(atomic_t *v)
15373 */
15374 static inline int atomic_add_negative(int i, atomic_t *v)
15375 {
15376- GEN_BINARY_RMWcc(LOCK_PREFIX "addl", v->counter, "er", i, "%0", "s");
15377+ GEN_BINARY_RMWcc(LOCK_PREFIX "addl", LOCK_PREFIX "subl", v->counter, "er", i, "%0", "s");
15378 }
15379
15380 /**
15381@@ -152,7 +272,19 @@ static inline int atomic_add_negative(int i, atomic_t *v)
15382 *
15383 * Atomically adds @i to @v and returns @i + @v
15384 */
15385-static inline int atomic_add_return(int i, atomic_t *v)
15386+static inline int __intentional_overflow(-1) atomic_add_return(int i, atomic_t *v)
15387+{
15388+ return i + xadd_check_overflow(&v->counter, i);
15389+}
15390+
15391+/**
15392+ * atomic_add_return_unchecked - add integer and return
15393+ * @i: integer value to add
15394+ * @v: pointer of type atomic_unchecked_t
15395+ *
15396+ * Atomically adds @i to @v and returns @i + @v
15397+ */
15398+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
15399 {
15400 return i + xadd(&v->counter, i);
15401 }
15402@@ -164,15 +296,24 @@ static inline int atomic_add_return(int i, atomic_t *v)
15403 *
15404 * Atomically subtracts @i from @v and returns @v - @i
15405 */
15406-static inline int atomic_sub_return(int i, atomic_t *v)
15407+static inline int __intentional_overflow(-1) atomic_sub_return(int i, atomic_t *v)
15408 {
15409 return atomic_add_return(-i, v);
15410 }
15411
15412 #define atomic_inc_return(v) (atomic_add_return(1, v))
15413+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
15414+{
15415+ return atomic_add_return_unchecked(1, v);
15416+}
15417 #define atomic_dec_return(v) (atomic_sub_return(1, v))
15418
15419-static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
15420+static inline int __intentional_overflow(-1) atomic_cmpxchg(atomic_t *v, int old, int new)
15421+{
15422+ return cmpxchg(&v->counter, old, new);
15423+}
15424+
15425+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
15426 {
15427 return cmpxchg(&v->counter, old, new);
15428 }
15429@@ -182,6 +323,11 @@ static inline int atomic_xchg(atomic_t *v, int new)
15430 return xchg(&v->counter, new);
15431 }
15432
15433+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
15434+{
15435+ return xchg(&v->counter, new);
15436+}
15437+
15438 /**
15439 * __atomic_add_unless - add unless the number is already a given value
15440 * @v: pointer of type atomic_t
15441@@ -191,14 +337,27 @@ static inline int atomic_xchg(atomic_t *v, int new)
15442 * Atomically adds @a to @v, so long as @v was not already @u.
15443 * Returns the old value of @v.
15444 */
15445-static inline int __atomic_add_unless(atomic_t *v, int a, int u)
15446+static inline int __intentional_overflow(-1) __atomic_add_unless(atomic_t *v, int a, int u)
15447 {
15448- int c, old;
15449+ int c, old, new;
15450 c = atomic_read(v);
15451 for (;;) {
15452- if (unlikely(c == (u)))
15453+ if (unlikely(c == u))
15454 break;
15455- old = atomic_cmpxchg((v), c, c + (a));
15456+
15457+ asm volatile("addl %2,%0\n"
15458+
15459+#ifdef CONFIG_PAX_REFCOUNT
15460+ "jno 0f\n"
15461+ "subl %2,%0\n"
15462+ "int $4\n0:\n"
15463+ _ASM_EXTABLE(0b, 0b)
15464+#endif
15465+
15466+ : "=r" (new)
15467+ : "0" (c), "ir" (a));
15468+
15469+ old = atomic_cmpxchg(v, c, new);
15470 if (likely(old == c))
15471 break;
15472 c = old;
15473@@ -207,6 +366,49 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
15474 }
15475
15476 /**
15477+ * atomic_inc_not_zero_hint - increment if not null
15478+ * @v: pointer of type atomic_t
15479+ * @hint: probable value of the atomic before the increment
15480+ *
15481+ * This version of atomic_inc_not_zero() gives a hint of probable
15482+ * value of the atomic. This helps processor to not read the memory
15483+ * before doing the atomic read/modify/write cycle, lowering
15484+ * number of bus transactions on some arches.
15485+ *
15486+ * Returns: 0 if increment was not done, 1 otherwise.
15487+ */
15488+#define atomic_inc_not_zero_hint atomic_inc_not_zero_hint
15489+static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint)
15490+{
15491+ int val, c = hint, new;
15492+
15493+ /* sanity test, should be removed by compiler if hint is a constant */
15494+ if (!hint)
15495+ return __atomic_add_unless(v, 1, 0);
15496+
15497+ do {
15498+ asm volatile("incl %0\n"
15499+
15500+#ifdef CONFIG_PAX_REFCOUNT
15501+ "jno 0f\n"
15502+ "decl %0\n"
15503+ "int $4\n0:\n"
15504+ _ASM_EXTABLE(0b, 0b)
15505+#endif
15506+
15507+ : "=r" (new)
15508+ : "0" (c));
15509+
15510+ val = atomic_cmpxchg(v, c, new);
15511+ if (val == c)
15512+ return 1;
15513+ c = val;
15514+ } while (c);
15515+
15516+ return 0;
15517+}
15518+
15519+/**
15520 * atomic_inc_short - increment of a short integer
15521 * @v: pointer to type int
15522 *
15523@@ -220,14 +422,37 @@ static inline short int atomic_inc_short(short int *v)
15524 }
15525
15526 /* These are x86-specific, used by some header files */
15527-#define atomic_clear_mask(mask, addr) \
15528- asm volatile(LOCK_PREFIX "andl %0,%1" \
15529- : : "r" (~(mask)), "m" (*(addr)) : "memory")
15530+static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
15531+{
15532+ asm volatile(LOCK_PREFIX "andl %1,%0"
15533+ : "+m" (v->counter)
15534+ : "r" (~(mask))
15535+ : "memory");
15536+}
15537
15538-#define atomic_set_mask(mask, addr) \
15539- asm volatile(LOCK_PREFIX "orl %0,%1" \
15540- : : "r" ((unsigned)(mask)), "m" (*(addr)) \
15541- : "memory")
15542+static inline void atomic_clear_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
15543+{
15544+ asm volatile(LOCK_PREFIX "andl %1,%0"
15545+ : "+m" (v->counter)
15546+ : "r" (~(mask))
15547+ : "memory");
15548+}
15549+
15550+static inline void atomic_set_mask(unsigned int mask, atomic_t *v)
15551+{
15552+ asm volatile(LOCK_PREFIX "orl %1,%0"
15553+ : "+m" (v->counter)
15554+ : "r" (mask)
15555+ : "memory");
15556+}
15557+
15558+static inline void atomic_set_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
15559+{
15560+ asm volatile(LOCK_PREFIX "orl %1,%0"
15561+ : "+m" (v->counter)
15562+ : "r" (mask)
15563+ : "memory");
15564+}
15565
15566 #ifdef CONFIG_X86_32
15567 # include <asm/atomic64_32.h>
15568diff --git a/arch/x86/include/asm/atomic64_32.h b/arch/x86/include/asm/atomic64_32.h
15569index b154de7..bf18a5a 100644
15570--- a/arch/x86/include/asm/atomic64_32.h
15571+++ b/arch/x86/include/asm/atomic64_32.h
15572@@ -12,6 +12,14 @@ typedef struct {
15573 u64 __aligned(8) counter;
15574 } atomic64_t;
15575
15576+#ifdef CONFIG_PAX_REFCOUNT
15577+typedef struct {
15578+ u64 __aligned(8) counter;
15579+} atomic64_unchecked_t;
15580+#else
15581+typedef atomic64_t atomic64_unchecked_t;
15582+#endif
15583+
15584 #define ATOMIC64_INIT(val) { (val) }
15585
15586 #define __ATOMIC64_DECL(sym) void atomic64_##sym(atomic64_t *, ...)
15587@@ -37,21 +45,31 @@ typedef struct {
15588 ATOMIC64_DECL_ONE(sym##_386)
15589
15590 ATOMIC64_DECL_ONE(add_386);
15591+ATOMIC64_DECL_ONE(add_unchecked_386);
15592 ATOMIC64_DECL_ONE(sub_386);
15593+ATOMIC64_DECL_ONE(sub_unchecked_386);
15594 ATOMIC64_DECL_ONE(inc_386);
15595+ATOMIC64_DECL_ONE(inc_unchecked_386);
15596 ATOMIC64_DECL_ONE(dec_386);
15597+ATOMIC64_DECL_ONE(dec_unchecked_386);
15598 #endif
15599
15600 #define alternative_atomic64(f, out, in...) \
15601 __alternative_atomic64(f, f, ASM_OUTPUT2(out), ## in)
15602
15603 ATOMIC64_DECL(read);
15604+ATOMIC64_DECL(read_unchecked);
15605 ATOMIC64_DECL(set);
15606+ATOMIC64_DECL(set_unchecked);
15607 ATOMIC64_DECL(xchg);
15608 ATOMIC64_DECL(add_return);
15609+ATOMIC64_DECL(add_return_unchecked);
15610 ATOMIC64_DECL(sub_return);
15611+ATOMIC64_DECL(sub_return_unchecked);
15612 ATOMIC64_DECL(inc_return);
15613+ATOMIC64_DECL(inc_return_unchecked);
15614 ATOMIC64_DECL(dec_return);
15615+ATOMIC64_DECL(dec_return_unchecked);
15616 ATOMIC64_DECL(dec_if_positive);
15617 ATOMIC64_DECL(inc_not_zero);
15618 ATOMIC64_DECL(add_unless);
15619@@ -77,6 +95,21 @@ static inline long long atomic64_cmpxchg(atomic64_t *v, long long o, long long n
15620 }
15621
15622 /**
15623+ * atomic64_cmpxchg_unchecked - cmpxchg atomic64 variable
15624+ * @p: pointer to type atomic64_unchecked_t
15625+ * @o: expected value
15626+ * @n: new value
15627+ *
15628+ * Atomically sets @v to @n if it was equal to @o and returns
15629+ * the old value.
15630+ */
15631+
15632+static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long long o, long long n)
15633+{
15634+ return cmpxchg64(&v->counter, o, n);
15635+}
15636+
15637+/**
15638 * atomic64_xchg - xchg atomic64 variable
15639 * @v: pointer to type atomic64_t
15640 * @n: value to assign
15641@@ -112,6 +145,22 @@ static inline void atomic64_set(atomic64_t *v, long long i)
15642 }
15643
15644 /**
15645+ * atomic64_set_unchecked - set atomic64 variable
15646+ * @v: pointer to type atomic64_unchecked_t
15647+ * @n: value to assign
15648+ *
15649+ * Atomically sets the value of @v to @n.
15650+ */
15651+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
15652+{
15653+ unsigned high = (unsigned)(i >> 32);
15654+ unsigned low = (unsigned)i;
15655+ alternative_atomic64(set, /* no output */,
15656+ "S" (v), "b" (low), "c" (high)
15657+ : "eax", "edx", "memory");
15658+}
15659+
15660+/**
15661 * atomic64_read - read atomic64 variable
15662 * @v: pointer to type atomic64_t
15663 *
15664@@ -125,6 +174,19 @@ static inline long long atomic64_read(const atomic64_t *v)
15665 }
15666
15667 /**
15668+ * atomic64_read_unchecked - read atomic64 variable
15669+ * @v: pointer to type atomic64_unchecked_t
15670+ *
15671+ * Atomically reads the value of @v and returns it.
15672+ */
15673+static inline long long __intentional_overflow(-1) atomic64_read_unchecked(atomic64_unchecked_t *v)
15674+{
15675+ long long r;
15676+ alternative_atomic64(read, "=&A" (r), "c" (v) : "memory");
15677+ return r;
15678+ }
15679+
15680+/**
15681 * atomic64_add_return - add and return
15682 * @i: integer value to add
15683 * @v: pointer to type atomic64_t
15684@@ -139,6 +201,21 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
15685 return i;
15686 }
15687
15688+/**
15689+ * atomic64_add_return_unchecked - add and return
15690+ * @i: integer value to add
15691+ * @v: pointer to type atomic64_unchecked_t
15692+ *
15693+ * Atomically adds @i to @v and returns @i + *@v
15694+ */
15695+static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
15696+{
15697+ alternative_atomic64(add_return_unchecked,
15698+ ASM_OUTPUT2("+A" (i), "+c" (v)),
15699+ ASM_NO_INPUT_CLOBBER("memory"));
15700+ return i;
15701+}
15702+
15703 /*
15704 * Other variants with different arithmetic operators:
15705 */
15706@@ -158,6 +235,14 @@ static inline long long atomic64_inc_return(atomic64_t *v)
15707 return a;
15708 }
15709
15710+static inline long long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
15711+{
15712+ long long a;
15713+ alternative_atomic64(inc_return_unchecked, "=&A" (a),
15714+ "S" (v) : "memory", "ecx");
15715+ return a;
15716+}
15717+
15718 static inline long long atomic64_dec_return(atomic64_t *v)
15719 {
15720 long long a;
15721@@ -182,6 +267,21 @@ static inline long long atomic64_add(long long i, atomic64_t *v)
15722 }
15723
15724 /**
15725+ * atomic64_add_unchecked - add integer to atomic64 variable
15726+ * @i: integer value to add
15727+ * @v: pointer to type atomic64_unchecked_t
15728+ *
15729+ * Atomically adds @i to @v.
15730+ */
15731+static inline long long atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
15732+{
15733+ __alternative_atomic64(add_unchecked, add_return_unchecked,
15734+ ASM_OUTPUT2("+A" (i), "+c" (v)),
15735+ ASM_NO_INPUT_CLOBBER("memory"));
15736+ return i;
15737+}
15738+
15739+/**
15740 * atomic64_sub - subtract the atomic64 variable
15741 * @i: integer value to subtract
15742 * @v: pointer to type atomic64_t
15743diff --git a/arch/x86/include/asm/atomic64_64.h b/arch/x86/include/asm/atomic64_64.h
15744index f8d273e..02f39f3 100644
15745--- a/arch/x86/include/asm/atomic64_64.h
15746+++ b/arch/x86/include/asm/atomic64_64.h
15747@@ -22,6 +22,18 @@ static inline long atomic64_read(const atomic64_t *v)
15748 }
15749
15750 /**
15751+ * atomic64_read_unchecked - read atomic64 variable
15752+ * @v: pointer of type atomic64_unchecked_t
15753+ *
15754+ * Atomically reads the value of @v.
15755+ * Doesn't imply a read memory barrier.
15756+ */
15757+static inline long __intentional_overflow(-1) atomic64_read_unchecked(const atomic64_unchecked_t *v)
15758+{
15759+ return ACCESS_ONCE((v)->counter);
15760+}
15761+
15762+/**
15763 * atomic64_set - set atomic64 variable
15764 * @v: pointer to type atomic64_t
15765 * @i: required value
15766@@ -34,6 +46,18 @@ static inline void atomic64_set(atomic64_t *v, long i)
15767 }
15768
15769 /**
15770+ * atomic64_set_unchecked - set atomic64 variable
15771+ * @v: pointer to type atomic64_unchecked_t
15772+ * @i: required value
15773+ *
15774+ * Atomically sets the value of @v to @i.
15775+ */
15776+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
15777+{
15778+ v->counter = i;
15779+}
15780+
15781+/**
15782 * atomic64_add - add integer to atomic64 variable
15783 * @i: integer value to add
15784 * @v: pointer to type atomic64_t
15785@@ -42,6 +66,28 @@ static inline void atomic64_set(atomic64_t *v, long i)
15786 */
15787 static inline void atomic64_add(long i, atomic64_t *v)
15788 {
15789+ asm volatile(LOCK_PREFIX "addq %1,%0\n"
15790+
15791+#ifdef CONFIG_PAX_REFCOUNT
15792+ "jno 0f\n"
15793+ LOCK_PREFIX "subq %1,%0\n"
15794+ "int $4\n0:\n"
15795+ _ASM_EXTABLE(0b, 0b)
15796+#endif
15797+
15798+ : "=m" (v->counter)
15799+ : "er" (i), "m" (v->counter));
15800+}
15801+
15802+/**
15803+ * atomic64_add_unchecked - add integer to atomic64 variable
15804+ * @i: integer value to add
15805+ * @v: pointer to type atomic64_unchecked_t
15806+ *
15807+ * Atomically adds @i to @v.
15808+ */
15809+static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
15810+{
15811 asm volatile(LOCK_PREFIX "addq %1,%0"
15812 : "=m" (v->counter)
15813 : "er" (i), "m" (v->counter));
15814@@ -56,7 +102,29 @@ static inline void atomic64_add(long i, atomic64_t *v)
15815 */
15816 static inline void atomic64_sub(long i, atomic64_t *v)
15817 {
15818- asm volatile(LOCK_PREFIX "subq %1,%0"
15819+ asm volatile(LOCK_PREFIX "subq %1,%0\n"
15820+
15821+#ifdef CONFIG_PAX_REFCOUNT
15822+ "jno 0f\n"
15823+ LOCK_PREFIX "addq %1,%0\n"
15824+ "int $4\n0:\n"
15825+ _ASM_EXTABLE(0b, 0b)
15826+#endif
15827+
15828+ : "=m" (v->counter)
15829+ : "er" (i), "m" (v->counter));
15830+}
15831+
15832+/**
15833+ * atomic64_sub_unchecked - subtract the atomic64 variable
15834+ * @i: integer value to subtract
15835+ * @v: pointer to type atomic64_unchecked_t
15836+ *
15837+ * Atomically subtracts @i from @v.
15838+ */
15839+static inline void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
15840+{
15841+ asm volatile(LOCK_PREFIX "subq %1,%0\n"
15842 : "=m" (v->counter)
15843 : "er" (i), "m" (v->counter));
15844 }
15845@@ -72,7 +140,7 @@ static inline void atomic64_sub(long i, atomic64_t *v)
15846 */
15847 static inline int atomic64_sub_and_test(long i, atomic64_t *v)
15848 {
15849- GEN_BINARY_RMWcc(LOCK_PREFIX "subq", v->counter, "er", i, "%0", "e");
15850+ GEN_BINARY_RMWcc(LOCK_PREFIX "subq", LOCK_PREFIX "addq", v->counter, "er", i, "%0", "e");
15851 }
15852
15853 /**
15854@@ -83,6 +151,27 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
15855 */
15856 static inline void atomic64_inc(atomic64_t *v)
15857 {
15858+ asm volatile(LOCK_PREFIX "incq %0\n"
15859+
15860+#ifdef CONFIG_PAX_REFCOUNT
15861+ "jno 0f\n"
15862+ LOCK_PREFIX "decq %0\n"
15863+ "int $4\n0:\n"
15864+ _ASM_EXTABLE(0b, 0b)
15865+#endif
15866+
15867+ : "=m" (v->counter)
15868+ : "m" (v->counter));
15869+}
15870+
15871+/**
15872+ * atomic64_inc_unchecked - increment atomic64 variable
15873+ * @v: pointer to type atomic64_unchecked_t
15874+ *
15875+ * Atomically increments @v by 1.
15876+ */
15877+static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
15878+{
15879 asm volatile(LOCK_PREFIX "incq %0"
15880 : "=m" (v->counter)
15881 : "m" (v->counter));
15882@@ -96,7 +185,28 @@ static inline void atomic64_inc(atomic64_t *v)
15883 */
15884 static inline void atomic64_dec(atomic64_t *v)
15885 {
15886- asm volatile(LOCK_PREFIX "decq %0"
15887+ asm volatile(LOCK_PREFIX "decq %0\n"
15888+
15889+#ifdef CONFIG_PAX_REFCOUNT
15890+ "jno 0f\n"
15891+ LOCK_PREFIX "incq %0\n"
15892+ "int $4\n0:\n"
15893+ _ASM_EXTABLE(0b, 0b)
15894+#endif
15895+
15896+ : "=m" (v->counter)
15897+ : "m" (v->counter));
15898+}
15899+
15900+/**
15901+ * atomic64_dec_unchecked - decrement atomic64 variable
15902+ * @v: pointer to type atomic64_t
15903+ *
15904+ * Atomically decrements @v by 1.
15905+ */
15906+static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
15907+{
15908+ asm volatile(LOCK_PREFIX "decq %0\n"
15909 : "=m" (v->counter)
15910 : "m" (v->counter));
15911 }
15912@@ -111,7 +221,7 @@ static inline void atomic64_dec(atomic64_t *v)
15913 */
15914 static inline int atomic64_dec_and_test(atomic64_t *v)
15915 {
15916- GEN_UNARY_RMWcc(LOCK_PREFIX "decq", v->counter, "%0", "e");
15917+ GEN_UNARY_RMWcc(LOCK_PREFIX "decq", LOCK_PREFIX "incq", v->counter, "%0", "e");
15918 }
15919
15920 /**
15921@@ -124,7 +234,7 @@ static inline int atomic64_dec_and_test(atomic64_t *v)
15922 */
15923 static inline int atomic64_inc_and_test(atomic64_t *v)
15924 {
15925- GEN_UNARY_RMWcc(LOCK_PREFIX "incq", v->counter, "%0", "e");
15926+ GEN_UNARY_RMWcc(LOCK_PREFIX "incq", LOCK_PREFIX "decq", v->counter, "%0", "e");
15927 }
15928
15929 /**
15930@@ -138,7 +248,7 @@ static inline int atomic64_inc_and_test(atomic64_t *v)
15931 */
15932 static inline int atomic64_add_negative(long i, atomic64_t *v)
15933 {
15934- GEN_BINARY_RMWcc(LOCK_PREFIX "addq", v->counter, "er", i, "%0", "s");
15935+ GEN_BINARY_RMWcc(LOCK_PREFIX "addq", LOCK_PREFIX "subq", v->counter, "er", i, "%0", "s");
15936 }
15937
15938 /**
15939@@ -150,6 +260,18 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
15940 */
15941 static inline long atomic64_add_return(long i, atomic64_t *v)
15942 {
15943+ return i + xadd_check_overflow(&v->counter, i);
15944+}
15945+
15946+/**
15947+ * atomic64_add_return_unchecked - add and return
15948+ * @i: integer value to add
15949+ * @v: pointer to type atomic64_unchecked_t
15950+ *
15951+ * Atomically adds @i to @v and returns @i + @v
15952+ */
15953+static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
15954+{
15955 return i + xadd(&v->counter, i);
15956 }
15957
15958@@ -159,6 +281,10 @@ static inline long atomic64_sub_return(long i, atomic64_t *v)
15959 }
15960
15961 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
15962+static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
15963+{
15964+ return atomic64_add_return_unchecked(1, v);
15965+}
15966 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
15967
15968 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
15969@@ -166,6 +292,11 @@ static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
15970 return cmpxchg(&v->counter, old, new);
15971 }
15972
15973+static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
15974+{
15975+ return cmpxchg(&v->counter, old, new);
15976+}
15977+
15978 static inline long atomic64_xchg(atomic64_t *v, long new)
15979 {
15980 return xchg(&v->counter, new);
15981@@ -182,17 +313,30 @@ static inline long atomic64_xchg(atomic64_t *v, long new)
15982 */
15983 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
15984 {
15985- long c, old;
15986+ long c, old, new;
15987 c = atomic64_read(v);
15988 for (;;) {
15989- if (unlikely(c == (u)))
15990+ if (unlikely(c == u))
15991 break;
15992- old = atomic64_cmpxchg((v), c, c + (a));
15993+
15994+ asm volatile("add %2,%0\n"
15995+
15996+#ifdef CONFIG_PAX_REFCOUNT
15997+ "jno 0f\n"
15998+ "sub %2,%0\n"
15999+ "int $4\n0:\n"
16000+ _ASM_EXTABLE(0b, 0b)
16001+#endif
16002+
16003+ : "=r" (new)
16004+ : "0" (c), "ir" (a));
16005+
16006+ old = atomic64_cmpxchg(v, c, new);
16007 if (likely(old == c))
16008 break;
16009 c = old;
16010 }
16011- return c != (u);
16012+ return c != u;
16013 }
16014
16015 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
16016diff --git a/arch/x86/include/asm/barrier.h b/arch/x86/include/asm/barrier.h
16017index 0f4460b..fa1ee19 100644
16018--- a/arch/x86/include/asm/barrier.h
16019+++ b/arch/x86/include/asm/barrier.h
16020@@ -107,7 +107,7 @@
16021 do { \
16022 compiletime_assert_atomic_type(*p); \
16023 smp_mb(); \
16024- ACCESS_ONCE(*p) = (v); \
16025+ ACCESS_ONCE_RW(*p) = (v); \
16026 } while (0)
16027
16028 #define smp_load_acquire(p) \
16029@@ -124,7 +124,7 @@ do { \
16030 do { \
16031 compiletime_assert_atomic_type(*p); \
16032 barrier(); \
16033- ACCESS_ONCE(*p) = (v); \
16034+ ACCESS_ONCE_RW(*p) = (v); \
16035 } while (0)
16036
16037 #define smp_load_acquire(p) \
16038diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
16039index cfe3b95..d01b118 100644
16040--- a/arch/x86/include/asm/bitops.h
16041+++ b/arch/x86/include/asm/bitops.h
16042@@ -50,7 +50,7 @@
16043 * a mask operation on a byte.
16044 */
16045 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
16046-#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
16047+#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
16048 #define CONST_MASK(nr) (1 << ((nr) & 7))
16049
16050 /**
16051@@ -203,7 +203,7 @@ static inline void change_bit(long nr, volatile unsigned long *addr)
16052 */
16053 static inline int test_and_set_bit(long nr, volatile unsigned long *addr)
16054 {
16055- GEN_BINARY_RMWcc(LOCK_PREFIX "bts", *addr, "Ir", nr, "%0", "c");
16056+ GEN_BINARY_RMWcc_unchecked(LOCK_PREFIX "bts", *addr, "Ir", nr, "%0", "c");
16057 }
16058
16059 /**
16060@@ -249,7 +249,7 @@ static inline int __test_and_set_bit(long nr, volatile unsigned long *addr)
16061 */
16062 static inline int test_and_clear_bit(long nr, volatile unsigned long *addr)
16063 {
16064- GEN_BINARY_RMWcc(LOCK_PREFIX "btr", *addr, "Ir", nr, "%0", "c");
16065+ GEN_BINARY_RMWcc_unchecked(LOCK_PREFIX "btr", *addr, "Ir", nr, "%0", "c");
16066 }
16067
16068 /**
16069@@ -302,7 +302,7 @@ static inline int __test_and_change_bit(long nr, volatile unsigned long *addr)
16070 */
16071 static inline int test_and_change_bit(long nr, volatile unsigned long *addr)
16072 {
16073- GEN_BINARY_RMWcc(LOCK_PREFIX "btc", *addr, "Ir", nr, "%0", "c");
16074+ GEN_BINARY_RMWcc_unchecked(LOCK_PREFIX "btc", *addr, "Ir", nr, "%0", "c");
16075 }
16076
16077 static __always_inline int constant_test_bit(long nr, const volatile unsigned long *addr)
16078@@ -343,7 +343,7 @@ static int test_bit(int nr, const volatile unsigned long *addr);
16079 *
16080 * Undefined if no bit exists, so code should check against 0 first.
16081 */
16082-static inline unsigned long __ffs(unsigned long word)
16083+static inline unsigned long __intentional_overflow(-1) __ffs(unsigned long word)
16084 {
16085 asm("rep; bsf %1,%0"
16086 : "=r" (word)
16087@@ -357,7 +357,7 @@ static inline unsigned long __ffs(unsigned long word)
16088 *
16089 * Undefined if no zero exists, so code should check against ~0UL first.
16090 */
16091-static inline unsigned long ffz(unsigned long word)
16092+static inline unsigned long __intentional_overflow(-1) ffz(unsigned long word)
16093 {
16094 asm("rep; bsf %1,%0"
16095 : "=r" (word)
16096@@ -371,7 +371,7 @@ static inline unsigned long ffz(unsigned long word)
16097 *
16098 * Undefined if no set bit exists, so code should check against 0 first.
16099 */
16100-static inline unsigned long __fls(unsigned long word)
16101+static inline unsigned long __intentional_overflow(-1) __fls(unsigned long word)
16102 {
16103 asm("bsr %1,%0"
16104 : "=r" (word)
16105@@ -434,7 +434,7 @@ static inline int ffs(int x)
16106 * set bit if value is nonzero. The last (most significant) bit is
16107 * at position 32.
16108 */
16109-static inline int fls(int x)
16110+static inline int __intentional_overflow(-1) fls(int x)
16111 {
16112 int r;
16113
16114@@ -476,7 +476,7 @@ static inline int fls(int x)
16115 * at position 64.
16116 */
16117 #ifdef CONFIG_X86_64
16118-static __always_inline int fls64(__u64 x)
16119+static __always_inline __intentional_overflow(-1) int fls64(__u64 x)
16120 {
16121 int bitpos = -1;
16122 /*
16123diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h
16124index 4fa687a..60f2d39 100644
16125--- a/arch/x86/include/asm/boot.h
16126+++ b/arch/x86/include/asm/boot.h
16127@@ -6,10 +6,15 @@
16128 #include <uapi/asm/boot.h>
16129
16130 /* Physical address where kernel should be loaded. */
16131-#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
16132+#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
16133 + (CONFIG_PHYSICAL_ALIGN - 1)) \
16134 & ~(CONFIG_PHYSICAL_ALIGN - 1))
16135
16136+#ifndef __ASSEMBLY__
16137+extern unsigned char __LOAD_PHYSICAL_ADDR[];
16138+#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
16139+#endif
16140+
16141 /* Minimum kernel alignment, as a power of two */
16142 #ifdef CONFIG_X86_64
16143 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
16144diff --git a/arch/x86/include/asm/cache.h b/arch/x86/include/asm/cache.h
16145index 48f99f1..d78ebf9 100644
16146--- a/arch/x86/include/asm/cache.h
16147+++ b/arch/x86/include/asm/cache.h
16148@@ -5,12 +5,13 @@
16149
16150 /* L1 cache line size */
16151 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
16152-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
16153+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
16154
16155 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
16156+#define __read_only __attribute__((__section__(".data..read_only")))
16157
16158 #define INTERNODE_CACHE_SHIFT CONFIG_X86_INTERNODE_CACHE_SHIFT
16159-#define INTERNODE_CACHE_BYTES (1 << INTERNODE_CACHE_SHIFT)
16160+#define INTERNODE_CACHE_BYTES (_AC(1,UL) << INTERNODE_CACHE_SHIFT)
16161
16162 #ifdef CONFIG_X86_VSMP
16163 #ifdef CONFIG_SMP
16164diff --git a/arch/x86/include/asm/cacheflush.h b/arch/x86/include/asm/cacheflush.h
16165index 9863ee3..4a1f8e1 100644
16166--- a/arch/x86/include/asm/cacheflush.h
16167+++ b/arch/x86/include/asm/cacheflush.h
16168@@ -27,7 +27,7 @@ static inline unsigned long get_page_memtype(struct page *pg)
16169 unsigned long pg_flags = pg->flags & _PGMT_MASK;
16170
16171 if (pg_flags == _PGMT_DEFAULT)
16172- return -1;
16173+ return ~0UL;
16174 else if (pg_flags == _PGMT_WC)
16175 return _PAGE_CACHE_WC;
16176 else if (pg_flags == _PGMT_UC_MINUS)
16177diff --git a/arch/x86/include/asm/calling.h b/arch/x86/include/asm/calling.h
16178index 76659b6..72b8439 100644
16179--- a/arch/x86/include/asm/calling.h
16180+++ b/arch/x86/include/asm/calling.h
16181@@ -82,107 +82,117 @@ For 32-bit we have the following conventions - kernel is built with
16182 #define RSP 152
16183 #define SS 160
16184
16185-#define ARGOFFSET R11
16186-#define SWFRAME ORIG_RAX
16187+#define ARGOFFSET R15
16188
16189 .macro SAVE_ARGS addskip=0, save_rcx=1, save_r891011=1, rax_enosys=0
16190- subq $9*8+\addskip, %rsp
16191- CFI_ADJUST_CFA_OFFSET 9*8+\addskip
16192- movq_cfi rdi, 8*8
16193- movq_cfi rsi, 7*8
16194- movq_cfi rdx, 6*8
16195+ subq $ORIG_RAX-ARGOFFSET+\addskip, %rsp
16196+ CFI_ADJUST_CFA_OFFSET ORIG_RAX-ARGOFFSET+\addskip
16197+ movq_cfi rdi, RDI
16198+ movq_cfi rsi, RSI
16199+ movq_cfi rdx, RDX
16200
16201 .if \save_rcx
16202- movq_cfi rcx, 5*8
16203+ movq_cfi rcx, RCX
16204 .endif
16205
16206 .if \rax_enosys
16207- movq $-ENOSYS, 4*8(%rsp)
16208+ movq $-ENOSYS, RAX(%rsp)
16209 .else
16210- movq_cfi rax, 4*8
16211+ movq_cfi rax, RAX
16212 .endif
16213
16214 .if \save_r891011
16215- movq_cfi r8, 3*8
16216- movq_cfi r9, 2*8
16217- movq_cfi r10, 1*8
16218- movq_cfi r11, 0*8
16219+ movq_cfi r8, R8
16220+ movq_cfi r9, R9
16221+ movq_cfi r10, R10
16222+ movq_cfi r11, R11
16223 .endif
16224
16225+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
16226+ movq_cfi r12, R12
16227+#endif
16228+
16229 .endm
16230
16231-#define ARG_SKIP (9*8)
16232+#define ARG_SKIP ORIG_RAX
16233
16234 .macro RESTORE_ARGS rstor_rax=1, addskip=0, rstor_rcx=1, rstor_r11=1, \
16235 rstor_r8910=1, rstor_rdx=1
16236+
16237+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
16238+ movq_cfi_restore R12, r12
16239+#endif
16240+
16241 .if \rstor_r11
16242- movq_cfi_restore 0*8, r11
16243+ movq_cfi_restore R11, r11
16244 .endif
16245
16246 .if \rstor_r8910
16247- movq_cfi_restore 1*8, r10
16248- movq_cfi_restore 2*8, r9
16249- movq_cfi_restore 3*8, r8
16250+ movq_cfi_restore R10, r10
16251+ movq_cfi_restore R9, r9
16252+ movq_cfi_restore R8, r8
16253 .endif
16254
16255 .if \rstor_rax
16256- movq_cfi_restore 4*8, rax
16257+ movq_cfi_restore RAX, rax
16258 .endif
16259
16260 .if \rstor_rcx
16261- movq_cfi_restore 5*8, rcx
16262+ movq_cfi_restore RCX, rcx
16263 .endif
16264
16265 .if \rstor_rdx
16266- movq_cfi_restore 6*8, rdx
16267+ movq_cfi_restore RDX, rdx
16268 .endif
16269
16270- movq_cfi_restore 7*8, rsi
16271- movq_cfi_restore 8*8, rdi
16272+ movq_cfi_restore RSI, rsi
16273+ movq_cfi_restore RDI, rdi
16274
16275- .if ARG_SKIP+\addskip > 0
16276- addq $ARG_SKIP+\addskip, %rsp
16277- CFI_ADJUST_CFA_OFFSET -(ARG_SKIP+\addskip)
16278+ .if ORIG_RAX+\addskip > 0
16279+ addq $ORIG_RAX+\addskip, %rsp
16280+ CFI_ADJUST_CFA_OFFSET -(ORIG_RAX+\addskip)
16281 .endif
16282 .endm
16283
16284- .macro LOAD_ARGS offset, skiprax=0
16285- movq \offset(%rsp), %r11
16286- movq \offset+8(%rsp), %r10
16287- movq \offset+16(%rsp), %r9
16288- movq \offset+24(%rsp), %r8
16289- movq \offset+40(%rsp), %rcx
16290- movq \offset+48(%rsp), %rdx
16291- movq \offset+56(%rsp), %rsi
16292- movq \offset+64(%rsp), %rdi
16293+ .macro LOAD_ARGS skiprax=0
16294+ movq R11(%rsp), %r11
16295+ movq R10(%rsp), %r10
16296+ movq R9(%rsp), %r9
16297+ movq R8(%rsp), %r8
16298+ movq RCX(%rsp), %rcx
16299+ movq RDX(%rsp), %rdx
16300+ movq RSI(%rsp), %rsi
16301+ movq RDI(%rsp), %rdi
16302 .if \skiprax
16303 .else
16304- movq \offset+72(%rsp), %rax
16305+ movq ORIG_RAX(%rsp), %rax
16306 .endif
16307 .endm
16308
16309-#define REST_SKIP (6*8)
16310-
16311 .macro SAVE_REST
16312- subq $REST_SKIP, %rsp
16313- CFI_ADJUST_CFA_OFFSET REST_SKIP
16314- movq_cfi rbx, 5*8
16315- movq_cfi rbp, 4*8
16316- movq_cfi r12, 3*8
16317- movq_cfi r13, 2*8
16318- movq_cfi r14, 1*8
16319- movq_cfi r15, 0*8
16320+ movq_cfi rbx, RBX
16321+ movq_cfi rbp, RBP
16322+
16323+#ifndef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
16324+ movq_cfi r12, R12
16325+#endif
16326+
16327+ movq_cfi r13, R13
16328+ movq_cfi r14, R14
16329+ movq_cfi r15, R15
16330 .endm
16331
16332 .macro RESTORE_REST
16333- movq_cfi_restore 0*8, r15
16334- movq_cfi_restore 1*8, r14
16335- movq_cfi_restore 2*8, r13
16336- movq_cfi_restore 3*8, r12
16337- movq_cfi_restore 4*8, rbp
16338- movq_cfi_restore 5*8, rbx
16339- addq $REST_SKIP, %rsp
16340- CFI_ADJUST_CFA_OFFSET -(REST_SKIP)
16341+ movq_cfi_restore R15, r15
16342+ movq_cfi_restore R14, r14
16343+ movq_cfi_restore R13, r13
16344+
16345+#ifndef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
16346+ movq_cfi_restore R12, r12
16347+#endif
16348+
16349+ movq_cfi_restore RBP, rbp
16350+ movq_cfi_restore RBX, rbx
16351 .endm
16352
16353 .macro SAVE_ALL
16354diff --git a/arch/x86/include/asm/checksum_32.h b/arch/x86/include/asm/checksum_32.h
16355index f50de69..2b0a458 100644
16356--- a/arch/x86/include/asm/checksum_32.h
16357+++ b/arch/x86/include/asm/checksum_32.h
16358@@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_generic(const void *src, void *dst,
16359 int len, __wsum sum,
16360 int *src_err_ptr, int *dst_err_ptr);
16361
16362+asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
16363+ int len, __wsum sum,
16364+ int *src_err_ptr, int *dst_err_ptr);
16365+
16366+asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
16367+ int len, __wsum sum,
16368+ int *src_err_ptr, int *dst_err_ptr);
16369+
16370 /*
16371 * Note: when you get a NULL pointer exception here this means someone
16372 * passed in an incorrect kernel address to one of these functions.
16373@@ -53,7 +61,7 @@ static inline __wsum csum_partial_copy_from_user(const void __user *src,
16374
16375 might_sleep();
16376 stac();
16377- ret = csum_partial_copy_generic((__force void *)src, dst,
16378+ ret = csum_partial_copy_generic_from_user((__force void *)src, dst,
16379 len, sum, err_ptr, NULL);
16380 clac();
16381
16382@@ -187,7 +195,7 @@ static inline __wsum csum_and_copy_to_user(const void *src,
16383 might_sleep();
16384 if (access_ok(VERIFY_WRITE, dst, len)) {
16385 stac();
16386- ret = csum_partial_copy_generic(src, (__force void *)dst,
16387+ ret = csum_partial_copy_generic_to_user(src, (__force void *)dst,
16388 len, sum, NULL, err_ptr);
16389 clac();
16390 return ret;
16391diff --git a/arch/x86/include/asm/cmpxchg.h b/arch/x86/include/asm/cmpxchg.h
16392index 99c105d7..2f667ac 100644
16393--- a/arch/x86/include/asm/cmpxchg.h
16394+++ b/arch/x86/include/asm/cmpxchg.h
16395@@ -16,8 +16,12 @@ extern void __cmpxchg_wrong_size(void)
16396 __compiletime_error("Bad argument size for cmpxchg");
16397 extern void __xadd_wrong_size(void)
16398 __compiletime_error("Bad argument size for xadd");
16399+extern void __xadd_check_overflow_wrong_size(void)
16400+ __compiletime_error("Bad argument size for xadd_check_overflow");
16401 extern void __add_wrong_size(void)
16402 __compiletime_error("Bad argument size for add");
16403+extern void __add_check_overflow_wrong_size(void)
16404+ __compiletime_error("Bad argument size for add_check_overflow");
16405
16406 /*
16407 * Constants for operation sizes. On 32-bit, the 64-bit size it set to
16408@@ -69,6 +73,38 @@ extern void __add_wrong_size(void)
16409 __ret; \
16410 })
16411
16412+#ifdef CONFIG_PAX_REFCOUNT
16413+#define __xchg_op_check_overflow(ptr, arg, op, lock) \
16414+ ({ \
16415+ __typeof__ (*(ptr)) __ret = (arg); \
16416+ switch (sizeof(*(ptr))) { \
16417+ case __X86_CASE_L: \
16418+ asm volatile (lock #op "l %0, %1\n" \
16419+ "jno 0f\n" \
16420+ "mov %0,%1\n" \
16421+ "int $4\n0:\n" \
16422+ _ASM_EXTABLE(0b, 0b) \
16423+ : "+r" (__ret), "+m" (*(ptr)) \
16424+ : : "memory", "cc"); \
16425+ break; \
16426+ case __X86_CASE_Q: \
16427+ asm volatile (lock #op "q %q0, %1\n" \
16428+ "jno 0f\n" \
16429+ "mov %0,%1\n" \
16430+ "int $4\n0:\n" \
16431+ _ASM_EXTABLE(0b, 0b) \
16432+ : "+r" (__ret), "+m" (*(ptr)) \
16433+ : : "memory", "cc"); \
16434+ break; \
16435+ default: \
16436+ __ ## op ## _check_overflow_wrong_size(); \
16437+ } \
16438+ __ret; \
16439+ })
16440+#else
16441+#define __xchg_op_check_overflow(ptr, arg, op, lock) __xchg_op(ptr, arg, op, lock)
16442+#endif
16443+
16444 /*
16445 * Note: no "lock" prefix even on SMP: xchg always implies lock anyway.
16446 * Since this is generally used to protect other memory information, we
16447@@ -167,6 +203,9 @@ extern void __add_wrong_size(void)
16448 #define xadd_sync(ptr, inc) __xadd((ptr), (inc), "lock; ")
16449 #define xadd_local(ptr, inc) __xadd((ptr), (inc), "")
16450
16451+#define __xadd_check_overflow(ptr, inc, lock) __xchg_op_check_overflow((ptr), (inc), xadd, lock)
16452+#define xadd_check_overflow(ptr, inc) __xadd_check_overflow((ptr), (inc), LOCK_PREFIX)
16453+
16454 #define __add(ptr, inc, lock) \
16455 ({ \
16456 __typeof__ (*(ptr)) __ret = (inc); \
16457diff --git a/arch/x86/include/asm/compat.h b/arch/x86/include/asm/compat.h
16458index 59c6c40..5e0b22c 100644
16459--- a/arch/x86/include/asm/compat.h
16460+++ b/arch/x86/include/asm/compat.h
16461@@ -41,7 +41,7 @@ typedef s64 __attribute__((aligned(4))) compat_s64;
16462 typedef u32 compat_uint_t;
16463 typedef u32 compat_ulong_t;
16464 typedef u64 __attribute__((aligned(4))) compat_u64;
16465-typedef u32 compat_uptr_t;
16466+typedef u32 __user compat_uptr_t;
16467
16468 struct compat_timespec {
16469 compat_time_t tv_sec;
16470diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
16471index 0bb1335..8f1aec7 100644
16472--- a/arch/x86/include/asm/cpufeature.h
16473+++ b/arch/x86/include/asm/cpufeature.h
16474@@ -207,7 +207,7 @@
16475 #define X86_FEATURE_PAUSEFILTER ( 8*32+13) /* AMD filtered pause intercept */
16476 #define X86_FEATURE_PFTHRESHOLD ( 8*32+14) /* AMD pause filter threshold */
16477 #define X86_FEATURE_VMMCALL ( 8*32+15) /* Prefer vmmcall to vmcall */
16478-
16479+#define X86_FEATURE_STRONGUDEREF (8*32+31) /* PaX PCID based strong UDEREF */
16480
16481 /* Intel-defined CPU features, CPUID level 0x00000007:0 (ebx), word 9 */
16482 #define X86_FEATURE_FSGSBASE ( 9*32+ 0) /* {RD/WR}{FS/GS}BASE instructions*/
16483@@ -215,7 +215,7 @@
16484 #define X86_FEATURE_BMI1 ( 9*32+ 3) /* 1st group bit manipulation extensions */
16485 #define X86_FEATURE_HLE ( 9*32+ 4) /* Hardware Lock Elision */
16486 #define X86_FEATURE_AVX2 ( 9*32+ 5) /* AVX2 instructions */
16487-#define X86_FEATURE_SMEP ( 9*32+ 7) /* Supervisor Mode Execution Protection */
16488+#define X86_FEATURE_SMEP ( 9*32+ 7) /* Supervisor Mode Execution Prevention */
16489 #define X86_FEATURE_BMI2 ( 9*32+ 8) /* 2nd group bit manipulation extensions */
16490 #define X86_FEATURE_ERMS ( 9*32+ 9) /* Enhanced REP MOVSB/STOSB */
16491 #define X86_FEATURE_INVPCID ( 9*32+10) /* Invalidate Processor Context ID */
16492@@ -383,6 +383,7 @@ extern const char * const x86_bug_flags[NBUGINTS*32];
16493 #define cpu_has_cx16 boot_cpu_has(X86_FEATURE_CX16)
16494 #define cpu_has_eager_fpu boot_cpu_has(X86_FEATURE_EAGER_FPU)
16495 #define cpu_has_topoext boot_cpu_has(X86_FEATURE_TOPOEXT)
16496+#define cpu_has_pcid boot_cpu_has(X86_FEATURE_PCID)
16497
16498 #if __GNUC__ >= 4
16499 extern void warn_pre_alternatives(void);
16500@@ -434,7 +435,8 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
16501
16502 #ifdef CONFIG_X86_DEBUG_STATIC_CPU_HAS
16503 t_warn:
16504- warn_pre_alternatives();
16505+ if (bit != X86_FEATURE_PCID && bit != X86_FEATURE_INVPCID)
16506+ warn_pre_alternatives();
16507 return false;
16508 #endif
16509
16510@@ -454,7 +456,7 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
16511 ".section .discard,\"aw\",@progbits\n"
16512 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
16513 ".previous\n"
16514- ".section .altinstr_replacement,\"ax\"\n"
16515+ ".section .altinstr_replacement,\"a\"\n"
16516 "3: movb $1,%0\n"
16517 "4:\n"
16518 ".previous\n"
16519@@ -491,7 +493,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
16520 " .byte 2b - 1b\n" /* src len */
16521 " .byte 4f - 3f\n" /* repl len */
16522 ".previous\n"
16523- ".section .altinstr_replacement,\"ax\"\n"
16524+ ".section .altinstr_replacement,\"a\"\n"
16525 "3: .byte 0xe9\n .long %l[t_no] - 2b\n"
16526 "4:\n"
16527 ".previous\n"
16528@@ -524,7 +526,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
16529 ".section .discard,\"aw\",@progbits\n"
16530 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
16531 ".previous\n"
16532- ".section .altinstr_replacement,\"ax\"\n"
16533+ ".section .altinstr_replacement,\"a\"\n"
16534 "3: movb $0,%0\n"
16535 "4:\n"
16536 ".previous\n"
16537@@ -538,7 +540,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
16538 ".section .discard,\"aw\",@progbits\n"
16539 " .byte 0xff + (6f-5f) - (4b-3b)\n" /* size check */
16540 ".previous\n"
16541- ".section .altinstr_replacement,\"ax\"\n"
16542+ ".section .altinstr_replacement,\"a\"\n"
16543 "5: movb $1,%0\n"
16544 "6:\n"
16545 ".previous\n"
16546diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
16547index 50d033a..37deb26 100644
16548--- a/arch/x86/include/asm/desc.h
16549+++ b/arch/x86/include/asm/desc.h
16550@@ -4,6 +4,7 @@
16551 #include <asm/desc_defs.h>
16552 #include <asm/ldt.h>
16553 #include <asm/mmu.h>
16554+#include <asm/pgtable.h>
16555
16556 #include <linux/smp.h>
16557 #include <linux/percpu.h>
16558@@ -17,6 +18,7 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
16559
16560 desc->type = (info->read_exec_only ^ 1) << 1;
16561 desc->type |= info->contents << 2;
16562+ desc->type |= info->seg_not_present ^ 1;
16563
16564 desc->s = 1;
16565 desc->dpl = 0x3;
16566@@ -35,19 +37,14 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
16567 }
16568
16569 extern struct desc_ptr idt_descr;
16570-extern gate_desc idt_table[];
16571-extern struct desc_ptr debug_idt_descr;
16572-extern gate_desc debug_idt_table[];
16573-
16574-struct gdt_page {
16575- struct desc_struct gdt[GDT_ENTRIES];
16576-} __attribute__((aligned(PAGE_SIZE)));
16577-
16578-DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
16579+extern gate_desc idt_table[IDT_ENTRIES];
16580+extern const struct desc_ptr debug_idt_descr;
16581+extern gate_desc debug_idt_table[IDT_ENTRIES];
16582
16583+extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
16584 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
16585 {
16586- return per_cpu(gdt_page, cpu).gdt;
16587+ return cpu_gdt_table[cpu];
16588 }
16589
16590 #ifdef CONFIG_X86_64
16591@@ -72,8 +69,14 @@ static inline void pack_gate(gate_desc *gate, unsigned char type,
16592 unsigned long base, unsigned dpl, unsigned flags,
16593 unsigned short seg)
16594 {
16595- gate->a = (seg << 16) | (base & 0xffff);
16596- gate->b = (base & 0xffff0000) | (((0x80 | type | (dpl << 5)) & 0xff) << 8);
16597+ gate->gate.offset_low = base;
16598+ gate->gate.seg = seg;
16599+ gate->gate.reserved = 0;
16600+ gate->gate.type = type;
16601+ gate->gate.s = 0;
16602+ gate->gate.dpl = dpl;
16603+ gate->gate.p = 1;
16604+ gate->gate.offset_high = base >> 16;
16605 }
16606
16607 #endif
16608@@ -118,12 +121,16 @@ static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
16609
16610 static inline void native_write_idt_entry(gate_desc *idt, int entry, const gate_desc *gate)
16611 {
16612+ pax_open_kernel();
16613 memcpy(&idt[entry], gate, sizeof(*gate));
16614+ pax_close_kernel();
16615 }
16616
16617 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry, const void *desc)
16618 {
16619+ pax_open_kernel();
16620 memcpy(&ldt[entry], desc, 8);
16621+ pax_close_kernel();
16622 }
16623
16624 static inline void
16625@@ -137,7 +144,9 @@ native_write_gdt_entry(struct desc_struct *gdt, int entry, const void *desc, int
16626 default: size = sizeof(*gdt); break;
16627 }
16628
16629+ pax_open_kernel();
16630 memcpy(&gdt[entry], desc, size);
16631+ pax_close_kernel();
16632 }
16633
16634 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
16635@@ -210,7 +219,9 @@ static inline void native_set_ldt(const void *addr, unsigned int entries)
16636
16637 static inline void native_load_tr_desc(void)
16638 {
16639+ pax_open_kernel();
16640 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
16641+ pax_close_kernel();
16642 }
16643
16644 static inline void native_load_gdt(const struct desc_ptr *dtr)
16645@@ -247,8 +258,10 @@ static inline void native_load_tls(struct thread_struct *t, unsigned int cpu)
16646 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
16647 unsigned int i;
16648
16649+ pax_open_kernel();
16650 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
16651 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
16652+ pax_close_kernel();
16653 }
16654
16655 #define _LDT_empty(info) \
16656@@ -287,7 +300,7 @@ static inline void load_LDT(mm_context_t *pc)
16657 preempt_enable();
16658 }
16659
16660-static inline unsigned long get_desc_base(const struct desc_struct *desc)
16661+static inline unsigned long __intentional_overflow(-1) get_desc_base(const struct desc_struct *desc)
16662 {
16663 return (unsigned)(desc->base0 | ((desc->base1) << 16) | ((desc->base2) << 24));
16664 }
16665@@ -311,7 +324,7 @@ static inline void set_desc_limit(struct desc_struct *desc, unsigned long limit)
16666 }
16667
16668 #ifdef CONFIG_X86_64
16669-static inline void set_nmi_gate(int gate, void *addr)
16670+static inline void set_nmi_gate(int gate, const void *addr)
16671 {
16672 gate_desc s;
16673
16674@@ -321,14 +334,14 @@ static inline void set_nmi_gate(int gate, void *addr)
16675 #endif
16676
16677 #ifdef CONFIG_TRACING
16678-extern struct desc_ptr trace_idt_descr;
16679-extern gate_desc trace_idt_table[];
16680+extern const struct desc_ptr trace_idt_descr;
16681+extern gate_desc trace_idt_table[IDT_ENTRIES];
16682 static inline void write_trace_idt_entry(int entry, const gate_desc *gate)
16683 {
16684 write_idt_entry(trace_idt_table, entry, gate);
16685 }
16686
16687-static inline void _trace_set_gate(int gate, unsigned type, void *addr,
16688+static inline void _trace_set_gate(int gate, unsigned type, const void *addr,
16689 unsigned dpl, unsigned ist, unsigned seg)
16690 {
16691 gate_desc s;
16692@@ -348,7 +361,7 @@ static inline void write_trace_idt_entry(int entry, const gate_desc *gate)
16693 #define _trace_set_gate(gate, type, addr, dpl, ist, seg)
16694 #endif
16695
16696-static inline void _set_gate(int gate, unsigned type, void *addr,
16697+static inline void _set_gate(int gate, unsigned type, const void *addr,
16698 unsigned dpl, unsigned ist, unsigned seg)
16699 {
16700 gate_desc s;
16701@@ -371,9 +384,9 @@ static inline void _set_gate(int gate, unsigned type, void *addr,
16702 #define set_intr_gate(n, addr) \
16703 do { \
16704 BUG_ON((unsigned)n > 0xFF); \
16705- _set_gate(n, GATE_INTERRUPT, (void *)addr, 0, 0, \
16706+ _set_gate(n, GATE_INTERRUPT, (const void *)addr, 0, 0, \
16707 __KERNEL_CS); \
16708- _trace_set_gate(n, GATE_INTERRUPT, (void *)trace_##addr,\
16709+ _trace_set_gate(n, GATE_INTERRUPT, (const void *)trace_##addr,\
16710 0, 0, __KERNEL_CS); \
16711 } while (0)
16712
16713@@ -401,19 +414,19 @@ static inline void alloc_system_vector(int vector)
16714 /*
16715 * This routine sets up an interrupt gate at directory privilege level 3.
16716 */
16717-static inline void set_system_intr_gate(unsigned int n, void *addr)
16718+static inline void set_system_intr_gate(unsigned int n, const void *addr)
16719 {
16720 BUG_ON((unsigned)n > 0xFF);
16721 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
16722 }
16723
16724-static inline void set_system_trap_gate(unsigned int n, void *addr)
16725+static inline void set_system_trap_gate(unsigned int n, const void *addr)
16726 {
16727 BUG_ON((unsigned)n > 0xFF);
16728 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
16729 }
16730
16731-static inline void set_trap_gate(unsigned int n, void *addr)
16732+static inline void set_trap_gate(unsigned int n, const void *addr)
16733 {
16734 BUG_ON((unsigned)n > 0xFF);
16735 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
16736@@ -422,16 +435,16 @@ static inline void set_trap_gate(unsigned int n, void *addr)
16737 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
16738 {
16739 BUG_ON((unsigned)n > 0xFF);
16740- _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
16741+ _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
16742 }
16743
16744-static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
16745+static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
16746 {
16747 BUG_ON((unsigned)n > 0xFF);
16748 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
16749 }
16750
16751-static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
16752+static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
16753 {
16754 BUG_ON((unsigned)n > 0xFF);
16755 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
16756@@ -503,4 +516,17 @@ static inline void load_current_idt(void)
16757 else
16758 load_idt((const struct desc_ptr *)&idt_descr);
16759 }
16760+
16761+#ifdef CONFIG_X86_32
16762+static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
16763+{
16764+ struct desc_struct d;
16765+
16766+ if (likely(limit))
16767+ limit = (limit - 1UL) >> PAGE_SHIFT;
16768+ pack_descriptor(&d, base, limit, 0xFB, 0xC);
16769+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
16770+}
16771+#endif
16772+
16773 #endif /* _ASM_X86_DESC_H */
16774diff --git a/arch/x86/include/asm/desc_defs.h b/arch/x86/include/asm/desc_defs.h
16775index 278441f..b95a174 100644
16776--- a/arch/x86/include/asm/desc_defs.h
16777+++ b/arch/x86/include/asm/desc_defs.h
16778@@ -31,6 +31,12 @@ struct desc_struct {
16779 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
16780 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
16781 };
16782+ struct {
16783+ u16 offset_low;
16784+ u16 seg;
16785+ unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
16786+ unsigned offset_high: 16;
16787+ } gate;
16788 };
16789 } __attribute__((packed));
16790
16791diff --git a/arch/x86/include/asm/div64.h b/arch/x86/include/asm/div64.h
16792index ced283a..ffe04cc 100644
16793--- a/arch/x86/include/asm/div64.h
16794+++ b/arch/x86/include/asm/div64.h
16795@@ -39,7 +39,7 @@
16796 __mod; \
16797 })
16798
16799-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
16800+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
16801 {
16802 union {
16803 u64 v64;
16804diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
16805index ca3347a..1a5082a 100644
16806--- a/arch/x86/include/asm/elf.h
16807+++ b/arch/x86/include/asm/elf.h
16808@@ -75,9 +75,6 @@ typedef struct user_fxsr_struct elf_fpxregset_t;
16809
16810 #include <asm/vdso.h>
16811
16812-#ifdef CONFIG_X86_64
16813-extern unsigned int vdso64_enabled;
16814-#endif
16815 #if defined(CONFIG_X86_32) || defined(CONFIG_COMPAT)
16816 extern unsigned int vdso32_enabled;
16817 #endif
16818@@ -249,7 +246,25 @@ extern int force_personality32;
16819 the loader. We need to make sure that it is out of the way of the program
16820 that it will "exec", and that there is sufficient room for the brk. */
16821
16822+#ifdef CONFIG_PAX_SEGMEXEC
16823+#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
16824+#else
16825 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
16826+#endif
16827+
16828+#ifdef CONFIG_PAX_ASLR
16829+#ifdef CONFIG_X86_32
16830+#define PAX_ELF_ET_DYN_BASE 0x10000000UL
16831+
16832+#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
16833+#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
16834+#else
16835+#define PAX_ELF_ET_DYN_BASE 0x400000UL
16836+
16837+#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
16838+#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
16839+#endif
16840+#endif
16841
16842 /* This yields a mask that user programs can use to figure out what
16843 instruction set this CPU supports. This could be done in user space,
16844@@ -298,17 +313,13 @@ do { \
16845
16846 #define ARCH_DLINFO \
16847 do { \
16848- if (vdso64_enabled) \
16849- NEW_AUX_ENT(AT_SYSINFO_EHDR, \
16850- (unsigned long __force)current->mm->context.vdso); \
16851+ NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
16852 } while (0)
16853
16854 /* As a historical oddity, the x32 and x86_64 vDSOs are controlled together. */
16855 #define ARCH_DLINFO_X32 \
16856 do { \
16857- if (vdso64_enabled) \
16858- NEW_AUX_ENT(AT_SYSINFO_EHDR, \
16859- (unsigned long __force)current->mm->context.vdso); \
16860+ NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
16861 } while (0)
16862
16863 #define AT_SYSINFO 32
16864@@ -323,10 +334,10 @@ else \
16865
16866 #endif /* !CONFIG_X86_32 */
16867
16868-#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
16869+#define VDSO_CURRENT_BASE (current->mm->context.vdso)
16870
16871 #define VDSO_ENTRY \
16872- ((unsigned long)current->mm->context.vdso + \
16873+ (current->mm->context.vdso + \
16874 selected_vdso32->sym___kernel_vsyscall)
16875
16876 struct linux_binprm;
16877@@ -338,9 +349,6 @@ extern int compat_arch_setup_additional_pages(struct linux_binprm *bprm,
16878 int uses_interp);
16879 #define compat_arch_setup_additional_pages compat_arch_setup_additional_pages
16880
16881-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
16882-#define arch_randomize_brk arch_randomize_brk
16883-
16884 /*
16885 * True on X86_32 or when emulating IA32 on X86_64
16886 */
16887diff --git a/arch/x86/include/asm/emergency-restart.h b/arch/x86/include/asm/emergency-restart.h
16888index 77a99ac..39ff7f5 100644
16889--- a/arch/x86/include/asm/emergency-restart.h
16890+++ b/arch/x86/include/asm/emergency-restart.h
16891@@ -1,6 +1,6 @@
16892 #ifndef _ASM_X86_EMERGENCY_RESTART_H
16893 #define _ASM_X86_EMERGENCY_RESTART_H
16894
16895-extern void machine_emergency_restart(void);
16896+extern void machine_emergency_restart(void) __noreturn;
16897
16898 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
16899diff --git a/arch/x86/include/asm/floppy.h b/arch/x86/include/asm/floppy.h
16900index 1c7eefe..d0e4702 100644
16901--- a/arch/x86/include/asm/floppy.h
16902+++ b/arch/x86/include/asm/floppy.h
16903@@ -229,18 +229,18 @@ static struct fd_routine_l {
16904 int (*_dma_setup)(char *addr, unsigned long size, int mode, int io);
16905 } fd_routine[] = {
16906 {
16907- request_dma,
16908- free_dma,
16909- get_dma_residue,
16910- dma_mem_alloc,
16911- hard_dma_setup
16912+ ._request_dma = request_dma,
16913+ ._free_dma = free_dma,
16914+ ._get_dma_residue = get_dma_residue,
16915+ ._dma_mem_alloc = dma_mem_alloc,
16916+ ._dma_setup = hard_dma_setup
16917 },
16918 {
16919- vdma_request_dma,
16920- vdma_nop,
16921- vdma_get_dma_residue,
16922- vdma_mem_alloc,
16923- vdma_dma_setup
16924+ ._request_dma = vdma_request_dma,
16925+ ._free_dma = vdma_nop,
16926+ ._get_dma_residue = vdma_get_dma_residue,
16927+ ._dma_mem_alloc = vdma_mem_alloc,
16928+ ._dma_setup = vdma_dma_setup
16929 }
16930 };
16931
16932diff --git a/arch/x86/include/asm/fpu-internal.h b/arch/x86/include/asm/fpu-internal.h
16933index e97622f..d0ba77a 100644
16934--- a/arch/x86/include/asm/fpu-internal.h
16935+++ b/arch/x86/include/asm/fpu-internal.h
16936@@ -124,8 +124,11 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
16937 #define user_insn(insn, output, input...) \
16938 ({ \
16939 int err; \
16940+ pax_open_userland(); \
16941 asm volatile(ASM_STAC "\n" \
16942- "1:" #insn "\n\t" \
16943+ "1:" \
16944+ __copyuser_seg \
16945+ #insn "\n\t" \
16946 "2: " ASM_CLAC "\n" \
16947 ".section .fixup,\"ax\"\n" \
16948 "3: movl $-1,%[err]\n" \
16949@@ -134,6 +137,7 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
16950 _ASM_EXTABLE(1b, 3b) \
16951 : [err] "=r" (err), output \
16952 : "0"(0), input); \
16953+ pax_close_userland(); \
16954 err; \
16955 })
16956
16957@@ -298,7 +302,7 @@ static inline int restore_fpu_checking(struct task_struct *tsk)
16958 "fnclex\n\t"
16959 "emms\n\t"
16960 "fildl %P[addr]" /* set F?P to defined value */
16961- : : [addr] "m" (tsk->thread.fpu.has_fpu));
16962+ : : [addr] "m" (init_tss[raw_smp_processor_id()].x86_tss.sp0));
16963 }
16964
16965 return fpu_restore_checking(&tsk->thread.fpu);
16966diff --git a/arch/x86/include/asm/futex.h b/arch/x86/include/asm/futex.h
16967index b4c1f54..e290c08 100644
16968--- a/arch/x86/include/asm/futex.h
16969+++ b/arch/x86/include/asm/futex.h
16970@@ -12,6 +12,7 @@
16971 #include <asm/smap.h>
16972
16973 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
16974+ typecheck(u32 __user *, uaddr); \
16975 asm volatile("\t" ASM_STAC "\n" \
16976 "1:\t" insn "\n" \
16977 "2:\t" ASM_CLAC "\n" \
16978@@ -20,15 +21,16 @@
16979 "\tjmp\t2b\n" \
16980 "\t.previous\n" \
16981 _ASM_EXTABLE(1b, 3b) \
16982- : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
16983+ : "=r" (oldval), "=r" (ret), "+m" (*(u32 __user *)____m(uaddr)) \
16984 : "i" (-EFAULT), "0" (oparg), "1" (0))
16985
16986 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
16987+ typecheck(u32 __user *, uaddr); \
16988 asm volatile("\t" ASM_STAC "\n" \
16989 "1:\tmovl %2, %0\n" \
16990 "\tmovl\t%0, %3\n" \
16991 "\t" insn "\n" \
16992- "2:\t" LOCK_PREFIX "cmpxchgl %3, %2\n" \
16993+ "2:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %3, %2\n" \
16994 "\tjnz\t1b\n" \
16995 "3:\t" ASM_CLAC "\n" \
16996 "\t.section .fixup,\"ax\"\n" \
16997@@ -38,7 +40,7 @@
16998 _ASM_EXTABLE(1b, 4b) \
16999 _ASM_EXTABLE(2b, 4b) \
17000 : "=&a" (oldval), "=&r" (ret), \
17001- "+m" (*uaddr), "=&r" (tem) \
17002+ "+m" (*(u32 __user *)____m(uaddr)), "=&r" (tem) \
17003 : "r" (oparg), "i" (-EFAULT), "1" (0))
17004
17005 static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
17006@@ -57,12 +59,13 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
17007
17008 pagefault_disable();
17009
17010+ pax_open_userland();
17011 switch (op) {
17012 case FUTEX_OP_SET:
17013- __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
17014+ __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
17015 break;
17016 case FUTEX_OP_ADD:
17017- __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
17018+ __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
17019 uaddr, oparg);
17020 break;
17021 case FUTEX_OP_OR:
17022@@ -77,6 +80,7 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
17023 default:
17024 ret = -ENOSYS;
17025 }
17026+ pax_close_userland();
17027
17028 pagefault_enable();
17029
17030diff --git a/arch/x86/include/asm/hw_irq.h b/arch/x86/include/asm/hw_irq.h
17031index 4615906..788c817 100644
17032--- a/arch/x86/include/asm/hw_irq.h
17033+++ b/arch/x86/include/asm/hw_irq.h
17034@@ -164,8 +164,8 @@ extern void setup_ioapic_dest(void);
17035 extern void enable_IO_APIC(void);
17036
17037 /* Statistics */
17038-extern atomic_t irq_err_count;
17039-extern atomic_t irq_mis_count;
17040+extern atomic_unchecked_t irq_err_count;
17041+extern atomic_unchecked_t irq_mis_count;
17042
17043 /* EISA */
17044 extern void eisa_set_level_irq(unsigned int irq);
17045diff --git a/arch/x86/include/asm/i8259.h b/arch/x86/include/asm/i8259.h
17046index ccffa53..3c90c87 100644
17047--- a/arch/x86/include/asm/i8259.h
17048+++ b/arch/x86/include/asm/i8259.h
17049@@ -62,7 +62,7 @@ struct legacy_pic {
17050 void (*init)(int auto_eoi);
17051 int (*irq_pending)(unsigned int irq);
17052 void (*make_irq)(unsigned int irq);
17053-};
17054+} __do_const;
17055
17056 extern struct legacy_pic *legacy_pic;
17057 extern struct legacy_pic null_legacy_pic;
17058diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
17059index b8237d8..3e8864e 100644
17060--- a/arch/x86/include/asm/io.h
17061+++ b/arch/x86/include/asm/io.h
17062@@ -52,12 +52,12 @@ static inline void name(type val, volatile void __iomem *addr) \
17063 "m" (*(volatile type __force *)addr) barrier); }
17064
17065 build_mmio_read(readb, "b", unsigned char, "=q", :"memory")
17066-build_mmio_read(readw, "w", unsigned short, "=r", :"memory")
17067-build_mmio_read(readl, "l", unsigned int, "=r", :"memory")
17068+build_mmio_read(__intentional_overflow(-1) readw, "w", unsigned short, "=r", :"memory")
17069+build_mmio_read(__intentional_overflow(-1) readl, "l", unsigned int, "=r", :"memory")
17070
17071 build_mmio_read(__readb, "b", unsigned char, "=q", )
17072-build_mmio_read(__readw, "w", unsigned short, "=r", )
17073-build_mmio_read(__readl, "l", unsigned int, "=r", )
17074+build_mmio_read(__intentional_overflow(-1) __readw, "w", unsigned short, "=r", )
17075+build_mmio_read(__intentional_overflow(-1) __readl, "l", unsigned int, "=r", )
17076
17077 build_mmio_write(writeb, "b", unsigned char, "q", :"memory")
17078 build_mmio_write(writew, "w", unsigned short, "r", :"memory")
17079@@ -109,7 +109,7 @@ build_mmio_write(writeq, "q", unsigned long, "r", :"memory")
17080 * this function
17081 */
17082
17083-static inline phys_addr_t virt_to_phys(volatile void *address)
17084+static inline phys_addr_t __intentional_overflow(-1) virt_to_phys(volatile void *address)
17085 {
17086 return __pa(address);
17087 }
17088@@ -185,7 +185,7 @@ static inline void __iomem *ioremap(resource_size_t offset, unsigned long size)
17089 return ioremap_nocache(offset, size);
17090 }
17091
17092-extern void iounmap(volatile void __iomem *addr);
17093+extern void iounmap(const volatile void __iomem *addr);
17094
17095 extern void set_iounmap_nonlazy(void);
17096
17097@@ -195,6 +195,17 @@ extern void set_iounmap_nonlazy(void);
17098
17099 #include <linux/vmalloc.h>
17100
17101+#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
17102+static inline int valid_phys_addr_range(unsigned long addr, size_t count)
17103+{
17104+ return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
17105+}
17106+
17107+static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
17108+{
17109+ return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
17110+}
17111+
17112 /*
17113 * Convert a virtual cached pointer to an uncached pointer
17114 */
17115diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
17116index 0a8b519..80e7d5b 100644
17117--- a/arch/x86/include/asm/irqflags.h
17118+++ b/arch/x86/include/asm/irqflags.h
17119@@ -141,6 +141,11 @@ static inline notrace unsigned long arch_local_irq_save(void)
17120 sti; \
17121 sysexit
17122
17123+#define GET_CR0_INTO_RDI mov %cr0, %rdi
17124+#define SET_RDI_INTO_CR0 mov %rdi, %cr0
17125+#define GET_CR3_INTO_RDI mov %cr3, %rdi
17126+#define SET_RDI_INTO_CR3 mov %rdi, %cr3
17127+
17128 #else
17129 #define INTERRUPT_RETURN iret
17130 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
17131diff --git a/arch/x86/include/asm/kprobes.h b/arch/x86/include/asm/kprobes.h
17132index 4421b5d..8543006 100644
17133--- a/arch/x86/include/asm/kprobes.h
17134+++ b/arch/x86/include/asm/kprobes.h
17135@@ -37,13 +37,8 @@ typedef u8 kprobe_opcode_t;
17136 #define RELATIVEJUMP_SIZE 5
17137 #define RELATIVECALL_OPCODE 0xe8
17138 #define RELATIVE_ADDR_SIZE 4
17139-#define MAX_STACK_SIZE 64
17140-#define MIN_STACK_SIZE(ADDR) \
17141- (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
17142- THREAD_SIZE - (unsigned long)(ADDR))) \
17143- ? (MAX_STACK_SIZE) \
17144- : (((unsigned long)current_thread_info()) + \
17145- THREAD_SIZE - (unsigned long)(ADDR)))
17146+#define MAX_STACK_SIZE 64UL
17147+#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
17148
17149 #define flush_insn_slot(p) do { } while (0)
17150
17151diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
17152index 6ed0c30..74fb6c3 100644
17153--- a/arch/x86/include/asm/kvm_host.h
17154+++ b/arch/x86/include/asm/kvm_host.h
17155@@ -51,6 +51,7 @@
17156 | X86_CR0_NW | X86_CR0_CD | X86_CR0_PG))
17157
17158 #define CR3_L_MODE_RESERVED_BITS 0xFFFFFF0000000000ULL
17159+#define CR3_PCID_INVD (1UL << 63)
17160 #define CR4_RESERVED_BITS \
17161 (~(unsigned long)(X86_CR4_VME | X86_CR4_PVI | X86_CR4_TSD | X86_CR4_DE\
17162 | X86_CR4_PSE | X86_CR4_PAE | X86_CR4_MCE \
17163diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
17164index 4ad6560..75c7bdd 100644
17165--- a/arch/x86/include/asm/local.h
17166+++ b/arch/x86/include/asm/local.h
17167@@ -10,33 +10,97 @@ typedef struct {
17168 atomic_long_t a;
17169 } local_t;
17170
17171+typedef struct {
17172+ atomic_long_unchecked_t a;
17173+} local_unchecked_t;
17174+
17175 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
17176
17177 #define local_read(l) atomic_long_read(&(l)->a)
17178+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
17179 #define local_set(l, i) atomic_long_set(&(l)->a, (i))
17180+#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
17181
17182 static inline void local_inc(local_t *l)
17183 {
17184- asm volatile(_ASM_INC "%0"
17185+ asm volatile(_ASM_INC "%0\n"
17186+
17187+#ifdef CONFIG_PAX_REFCOUNT
17188+ "jno 0f\n"
17189+ _ASM_DEC "%0\n"
17190+ "int $4\n0:\n"
17191+ _ASM_EXTABLE(0b, 0b)
17192+#endif
17193+
17194+ : "+m" (l->a.counter));
17195+}
17196+
17197+static inline void local_inc_unchecked(local_unchecked_t *l)
17198+{
17199+ asm volatile(_ASM_INC "%0\n"
17200 : "+m" (l->a.counter));
17201 }
17202
17203 static inline void local_dec(local_t *l)
17204 {
17205- asm volatile(_ASM_DEC "%0"
17206+ asm volatile(_ASM_DEC "%0\n"
17207+
17208+#ifdef CONFIG_PAX_REFCOUNT
17209+ "jno 0f\n"
17210+ _ASM_INC "%0\n"
17211+ "int $4\n0:\n"
17212+ _ASM_EXTABLE(0b, 0b)
17213+#endif
17214+
17215+ : "+m" (l->a.counter));
17216+}
17217+
17218+static inline void local_dec_unchecked(local_unchecked_t *l)
17219+{
17220+ asm volatile(_ASM_DEC "%0\n"
17221 : "+m" (l->a.counter));
17222 }
17223
17224 static inline void local_add(long i, local_t *l)
17225 {
17226- asm volatile(_ASM_ADD "%1,%0"
17227+ asm volatile(_ASM_ADD "%1,%0\n"
17228+
17229+#ifdef CONFIG_PAX_REFCOUNT
17230+ "jno 0f\n"
17231+ _ASM_SUB "%1,%0\n"
17232+ "int $4\n0:\n"
17233+ _ASM_EXTABLE(0b, 0b)
17234+#endif
17235+
17236+ : "+m" (l->a.counter)
17237+ : "ir" (i));
17238+}
17239+
17240+static inline void local_add_unchecked(long i, local_unchecked_t *l)
17241+{
17242+ asm volatile(_ASM_ADD "%1,%0\n"
17243 : "+m" (l->a.counter)
17244 : "ir" (i));
17245 }
17246
17247 static inline void local_sub(long i, local_t *l)
17248 {
17249- asm volatile(_ASM_SUB "%1,%0"
17250+ asm volatile(_ASM_SUB "%1,%0\n"
17251+
17252+#ifdef CONFIG_PAX_REFCOUNT
17253+ "jno 0f\n"
17254+ _ASM_ADD "%1,%0\n"
17255+ "int $4\n0:\n"
17256+ _ASM_EXTABLE(0b, 0b)
17257+#endif
17258+
17259+ : "+m" (l->a.counter)
17260+ : "ir" (i));
17261+}
17262+
17263+static inline void local_sub_unchecked(long i, local_unchecked_t *l)
17264+{
17265+ asm volatile(_ASM_SUB "%1,%0\n"
17266 : "+m" (l->a.counter)
17267 : "ir" (i));
17268 }
17269@@ -52,7 +116,7 @@ static inline void local_sub(long i, local_t *l)
17270 */
17271 static inline int local_sub_and_test(long i, local_t *l)
17272 {
17273- GEN_BINARY_RMWcc(_ASM_SUB, l->a.counter, "er", i, "%0", "e");
17274+ GEN_BINARY_RMWcc(_ASM_SUB, _ASM_ADD, l->a.counter, "er", i, "%0", "e");
17275 }
17276
17277 /**
17278@@ -65,7 +129,7 @@ static inline int local_sub_and_test(long i, local_t *l)
17279 */
17280 static inline int local_dec_and_test(local_t *l)
17281 {
17282- GEN_UNARY_RMWcc(_ASM_DEC, l->a.counter, "%0", "e");
17283+ GEN_UNARY_RMWcc(_ASM_DEC, _ASM_INC, l->a.counter, "%0", "e");
17284 }
17285
17286 /**
17287@@ -78,7 +142,7 @@ static inline int local_dec_and_test(local_t *l)
17288 */
17289 static inline int local_inc_and_test(local_t *l)
17290 {
17291- GEN_UNARY_RMWcc(_ASM_INC, l->a.counter, "%0", "e");
17292+ GEN_UNARY_RMWcc(_ASM_INC, _ASM_DEC, l->a.counter, "%0", "e");
17293 }
17294
17295 /**
17296@@ -92,7 +156,7 @@ static inline int local_inc_and_test(local_t *l)
17297 */
17298 static inline int local_add_negative(long i, local_t *l)
17299 {
17300- GEN_BINARY_RMWcc(_ASM_ADD, l->a.counter, "er", i, "%0", "s");
17301+ GEN_BINARY_RMWcc(_ASM_ADD, _ASM_SUB, l->a.counter, "er", i, "%0", "s");
17302 }
17303
17304 /**
17305@@ -105,6 +169,30 @@ static inline int local_add_negative(long i, local_t *l)
17306 static inline long local_add_return(long i, local_t *l)
17307 {
17308 long __i = i;
17309+ asm volatile(_ASM_XADD "%0, %1\n"
17310+
17311+#ifdef CONFIG_PAX_REFCOUNT
17312+ "jno 0f\n"
17313+ _ASM_MOV "%0,%1\n"
17314+ "int $4\n0:\n"
17315+ _ASM_EXTABLE(0b, 0b)
17316+#endif
17317+
17318+ : "+r" (i), "+m" (l->a.counter)
17319+ : : "memory");
17320+ return i + __i;
17321+}
17322+
17323+/**
17324+ * local_add_return_unchecked - add and return
17325+ * @i: integer value to add
17326+ * @l: pointer to type local_unchecked_t
17327+ *
17328+ * Atomically adds @i to @l and returns @i + @l
17329+ */
17330+static inline long local_add_return_unchecked(long i, local_unchecked_t *l)
17331+{
17332+ long __i = i;
17333 asm volatile(_ASM_XADD "%0, %1;"
17334 : "+r" (i), "+m" (l->a.counter)
17335 : : "memory");
17336@@ -121,6 +209,8 @@ static inline long local_sub_return(long i, local_t *l)
17337
17338 #define local_cmpxchg(l, o, n) \
17339 (cmpxchg_local(&((l)->a.counter), (o), (n)))
17340+#define local_cmpxchg_unchecked(l, o, n) \
17341+ (cmpxchg_local(&((l)->a.counter), (o), (n)))
17342 /* Always has a lock prefix */
17343 #define local_xchg(l, n) (xchg(&((l)->a.counter), (n)))
17344
17345diff --git a/arch/x86/include/asm/mman.h b/arch/x86/include/asm/mman.h
17346new file mode 100644
17347index 0000000..2bfd3ba
17348--- /dev/null
17349+++ b/arch/x86/include/asm/mman.h
17350@@ -0,0 +1,15 @@
17351+#ifndef _X86_MMAN_H
17352+#define _X86_MMAN_H
17353+
17354+#include <uapi/asm/mman.h>
17355+
17356+#ifdef __KERNEL__
17357+#ifndef __ASSEMBLY__
17358+#ifdef CONFIG_X86_32
17359+#define arch_mmap_check i386_mmap_check
17360+int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags);
17361+#endif
17362+#endif
17363+#endif
17364+
17365+#endif /* X86_MMAN_H */
17366diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
17367index 876e74e..e20bfb1 100644
17368--- a/arch/x86/include/asm/mmu.h
17369+++ b/arch/x86/include/asm/mmu.h
17370@@ -9,7 +9,7 @@
17371 * we put the segment information here.
17372 */
17373 typedef struct {
17374- void *ldt;
17375+ struct desc_struct *ldt;
17376 int size;
17377
17378 #ifdef CONFIG_X86_64
17379@@ -18,7 +18,19 @@ typedef struct {
17380 #endif
17381
17382 struct mutex lock;
17383- void __user *vdso;
17384+ unsigned long vdso;
17385+
17386+#ifdef CONFIG_X86_32
17387+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
17388+ unsigned long user_cs_base;
17389+ unsigned long user_cs_limit;
17390+
17391+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
17392+ cpumask_t cpu_user_cs_mask;
17393+#endif
17394+
17395+#endif
17396+#endif
17397 } mm_context_t;
17398
17399 #ifdef CONFIG_SMP
17400diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
17401index 166af2a..648c200 100644
17402--- a/arch/x86/include/asm/mmu_context.h
17403+++ b/arch/x86/include/asm/mmu_context.h
17404@@ -28,6 +28,20 @@ void destroy_context(struct mm_struct *mm);
17405
17406 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
17407 {
17408+
17409+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17410+ if (!(static_cpu_has(X86_FEATURE_PCID))) {
17411+ unsigned int i;
17412+ pgd_t *pgd;
17413+
17414+ pax_open_kernel();
17415+ pgd = get_cpu_pgd(smp_processor_id(), kernel);
17416+ for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
17417+ set_pgd_batched(pgd+i, native_make_pgd(0));
17418+ pax_close_kernel();
17419+ }
17420+#endif
17421+
17422 #ifdef CONFIG_SMP
17423 if (this_cpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
17424 this_cpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
17425@@ -38,16 +52,59 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
17426 struct task_struct *tsk)
17427 {
17428 unsigned cpu = smp_processor_id();
17429+#if defined(CONFIG_X86_32) && defined(CONFIG_SMP) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
17430+ int tlbstate = TLBSTATE_OK;
17431+#endif
17432
17433 if (likely(prev != next)) {
17434 #ifdef CONFIG_SMP
17435+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
17436+ tlbstate = this_cpu_read(cpu_tlbstate.state);
17437+#endif
17438 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
17439 this_cpu_write(cpu_tlbstate.active_mm, next);
17440 #endif
17441 cpumask_set_cpu(cpu, mm_cpumask(next));
17442
17443 /* Re-load page tables */
17444+#ifdef CONFIG_PAX_PER_CPU_PGD
17445+ pax_open_kernel();
17446+
17447+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17448+ if (static_cpu_has(X86_FEATURE_PCID))
17449+ __clone_user_pgds(get_cpu_pgd(cpu, user), next->pgd);
17450+ else
17451+#endif
17452+
17453+ __clone_user_pgds(get_cpu_pgd(cpu, kernel), next->pgd);
17454+ __shadow_user_pgds(get_cpu_pgd(cpu, kernel) + USER_PGD_PTRS, next->pgd);
17455+ pax_close_kernel();
17456+ 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));
17457+
17458+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17459+ if (static_cpu_has(X86_FEATURE_PCID)) {
17460+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
17461+ u64 descriptor[2];
17462+ descriptor[0] = PCID_USER;
17463+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
17464+ if (!static_cpu_has(X86_FEATURE_STRONGUDEREF)) {
17465+ descriptor[0] = PCID_KERNEL;
17466+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
17467+ }
17468+ } else {
17469+ write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
17470+ if (static_cpu_has(X86_FEATURE_STRONGUDEREF))
17471+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
17472+ else
17473+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
17474+ }
17475+ } else
17476+#endif
17477+
17478+ load_cr3(get_cpu_pgd(cpu, kernel));
17479+#else
17480 load_cr3(next->pgd);
17481+#endif
17482 trace_tlb_flush(TLB_FLUSH_ON_TASK_SWITCH, TLB_FLUSH_ALL);
17483
17484 /* Stop flush ipis for the previous mm */
17485@@ -56,9 +113,67 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
17486 /* Load the LDT, if the LDT is different: */
17487 if (unlikely(prev->context.ldt != next->context.ldt))
17488 load_LDT_nolock(&next->context);
17489+
17490+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
17491+ if (!(__supported_pte_mask & _PAGE_NX)) {
17492+ smp_mb__before_atomic();
17493+ cpu_clear(cpu, prev->context.cpu_user_cs_mask);
17494+ smp_mb__after_atomic();
17495+ cpu_set(cpu, next->context.cpu_user_cs_mask);
17496+ }
17497+#endif
17498+
17499+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
17500+ if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
17501+ prev->context.user_cs_limit != next->context.user_cs_limit))
17502+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
17503+#ifdef CONFIG_SMP
17504+ else if (unlikely(tlbstate != TLBSTATE_OK))
17505+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
17506+#endif
17507+#endif
17508+
17509 }
17510+ else {
17511+
17512+#ifdef CONFIG_PAX_PER_CPU_PGD
17513+ pax_open_kernel();
17514+
17515+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17516+ if (static_cpu_has(X86_FEATURE_PCID))
17517+ __clone_user_pgds(get_cpu_pgd(cpu, user), next->pgd);
17518+ else
17519+#endif
17520+
17521+ __clone_user_pgds(get_cpu_pgd(cpu, kernel), next->pgd);
17522+ __shadow_user_pgds(get_cpu_pgd(cpu, kernel) + USER_PGD_PTRS, next->pgd);
17523+ pax_close_kernel();
17524+ 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));
17525+
17526+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17527+ if (static_cpu_has(X86_FEATURE_PCID)) {
17528+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
17529+ u64 descriptor[2];
17530+ descriptor[0] = PCID_USER;
17531+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
17532+ if (!static_cpu_has(X86_FEATURE_STRONGUDEREF)) {
17533+ descriptor[0] = PCID_KERNEL;
17534+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
17535+ }
17536+ } else {
17537+ write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
17538+ if (static_cpu_has(X86_FEATURE_STRONGUDEREF))
17539+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
17540+ else
17541+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
17542+ }
17543+ } else
17544+#endif
17545+
17546+ load_cr3(get_cpu_pgd(cpu, kernel));
17547+#endif
17548+
17549 #ifdef CONFIG_SMP
17550- else {
17551 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
17552 BUG_ON(this_cpu_read(cpu_tlbstate.active_mm) != next);
17553
17554@@ -75,12 +190,29 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
17555 * tlb flush IPI delivery. We must reload CR3
17556 * to make sure to use no freed page tables.
17557 */
17558+
17559+#ifndef CONFIG_PAX_PER_CPU_PGD
17560 load_cr3(next->pgd);
17561 trace_tlb_flush(TLB_FLUSH_ON_TASK_SWITCH, TLB_FLUSH_ALL);
17562+#endif
17563+
17564 load_LDT_nolock(&next->context);
17565+
17566+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
17567+ if (!(__supported_pte_mask & _PAGE_NX))
17568+ cpu_set(cpu, next->context.cpu_user_cs_mask);
17569+#endif
17570+
17571+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
17572+#ifdef CONFIG_PAX_PAGEEXEC
17573+ if (!((next->pax_flags & MF_PAX_PAGEEXEC) && (__supported_pte_mask & _PAGE_NX)))
17574+#endif
17575+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
17576+#endif
17577+
17578 }
17579+#endif
17580 }
17581-#endif
17582 }
17583
17584 #define activate_mm(prev, next) \
17585diff --git a/arch/x86/include/asm/module.h b/arch/x86/include/asm/module.h
17586index e3b7819..b257c64 100644
17587--- a/arch/x86/include/asm/module.h
17588+++ b/arch/x86/include/asm/module.h
17589@@ -5,6 +5,7 @@
17590
17591 #ifdef CONFIG_X86_64
17592 /* X86_64 does not define MODULE_PROC_FAMILY */
17593+#define MODULE_PROC_FAMILY ""
17594 #elif defined CONFIG_M486
17595 #define MODULE_PROC_FAMILY "486 "
17596 #elif defined CONFIG_M586
17597@@ -57,8 +58,20 @@
17598 #error unknown processor family
17599 #endif
17600
17601-#ifdef CONFIG_X86_32
17602-# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
17603+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
17604+#define MODULE_PAX_KERNEXEC "KERNEXEC_BTS "
17605+#elif defined(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR)
17606+#define MODULE_PAX_KERNEXEC "KERNEXEC_OR "
17607+#else
17608+#define MODULE_PAX_KERNEXEC ""
17609 #endif
17610
17611+#ifdef CONFIG_PAX_MEMORY_UDEREF
17612+#define MODULE_PAX_UDEREF "UDEREF "
17613+#else
17614+#define MODULE_PAX_UDEREF ""
17615+#endif
17616+
17617+#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF
17618+
17619 #endif /* _ASM_X86_MODULE_H */
17620diff --git a/arch/x86/include/asm/nmi.h b/arch/x86/include/asm/nmi.h
17621index 5f2fc44..106caa6 100644
17622--- a/arch/x86/include/asm/nmi.h
17623+++ b/arch/x86/include/asm/nmi.h
17624@@ -36,26 +36,35 @@ enum {
17625
17626 typedef int (*nmi_handler_t)(unsigned int, struct pt_regs *);
17627
17628+struct nmiaction;
17629+
17630+struct nmiwork {
17631+ const struct nmiaction *action;
17632+ u64 max_duration;
17633+ struct irq_work irq_work;
17634+};
17635+
17636 struct nmiaction {
17637 struct list_head list;
17638 nmi_handler_t handler;
17639- u64 max_duration;
17640- struct irq_work irq_work;
17641 unsigned long flags;
17642 const char *name;
17643-};
17644+ struct nmiwork *work;
17645+} __do_const;
17646
17647 #define register_nmi_handler(t, fn, fg, n, init...) \
17648 ({ \
17649- static struct nmiaction init fn##_na = { \
17650+ static struct nmiwork fn##_nw; \
17651+ static const struct nmiaction init fn##_na = { \
17652 .handler = (fn), \
17653 .name = (n), \
17654 .flags = (fg), \
17655+ .work = &fn##_nw, \
17656 }; \
17657 __register_nmi_handler((t), &fn##_na); \
17658 })
17659
17660-int __register_nmi_handler(unsigned int, struct nmiaction *);
17661+int __register_nmi_handler(unsigned int, const struct nmiaction *);
17662
17663 void unregister_nmi_handler(unsigned int, const char *);
17664
17665diff --git a/arch/x86/include/asm/page.h b/arch/x86/include/asm/page.h
17666index 802dde3..9183e68 100644
17667--- a/arch/x86/include/asm/page.h
17668+++ b/arch/x86/include/asm/page.h
17669@@ -52,6 +52,7 @@ static inline void copy_user_page(void *to, void *from, unsigned long vaddr,
17670 __phys_addr_symbol(__phys_reloc_hide((unsigned long)(x)))
17671
17672 #define __va(x) ((void *)((unsigned long)(x)+PAGE_OFFSET))
17673+#define __early_va(x) ((void *)((unsigned long)(x)+__START_KERNEL_map - phys_base))
17674
17675 #define __boot_va(x) __va(x)
17676 #define __boot_pa(x) __pa(x)
17677@@ -60,11 +61,21 @@ static inline void copy_user_page(void *to, void *from, unsigned long vaddr,
17678 * virt_to_page(kaddr) returns a valid pointer if and only if
17679 * virt_addr_valid(kaddr) returns true.
17680 */
17681-#define virt_to_page(kaddr) pfn_to_page(__pa(kaddr) >> PAGE_SHIFT)
17682 #define pfn_to_kaddr(pfn) __va((pfn) << PAGE_SHIFT)
17683 extern bool __virt_addr_valid(unsigned long kaddr);
17684 #define virt_addr_valid(kaddr) __virt_addr_valid((unsigned long) (kaddr))
17685
17686+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
17687+#define virt_to_page(kaddr) \
17688+ ({ \
17689+ const void *__kaddr = (const void *)(kaddr); \
17690+ BUG_ON(!virt_addr_valid(__kaddr)); \
17691+ pfn_to_page(__pa(__kaddr) >> PAGE_SHIFT); \
17692+ })
17693+#else
17694+#define virt_to_page(kaddr) pfn_to_page(__pa(kaddr) >> PAGE_SHIFT)
17695+#endif
17696+
17697 #endif /* __ASSEMBLY__ */
17698
17699 #include <asm-generic/memory_model.h>
17700diff --git a/arch/x86/include/asm/page_64.h b/arch/x86/include/asm/page_64.h
17701index f408caf..4a0455e 100644
17702--- a/arch/x86/include/asm/page_64.h
17703+++ b/arch/x86/include/asm/page_64.h
17704@@ -7,9 +7,9 @@
17705
17706 /* duplicated to the one in bootmem.h */
17707 extern unsigned long max_pfn;
17708-extern unsigned long phys_base;
17709+extern const unsigned long phys_base;
17710
17711-static inline unsigned long __phys_addr_nodebug(unsigned long x)
17712+static inline unsigned long __intentional_overflow(-1) __phys_addr_nodebug(unsigned long x)
17713 {
17714 unsigned long y = x - __START_KERNEL_map;
17715
17716diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
17717index cd6e1610..70f4418 100644
17718--- a/arch/x86/include/asm/paravirt.h
17719+++ b/arch/x86/include/asm/paravirt.h
17720@@ -560,7 +560,7 @@ static inline pmd_t __pmd(pmdval_t val)
17721 return (pmd_t) { ret };
17722 }
17723
17724-static inline pmdval_t pmd_val(pmd_t pmd)
17725+static inline __intentional_overflow(-1) pmdval_t pmd_val(pmd_t pmd)
17726 {
17727 pmdval_t ret;
17728
17729@@ -626,6 +626,18 @@ static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
17730 val);
17731 }
17732
17733+static inline void set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
17734+{
17735+ pgdval_t val = native_pgd_val(pgd);
17736+
17737+ if (sizeof(pgdval_t) > sizeof(long))
17738+ PVOP_VCALL3(pv_mmu_ops.set_pgd_batched, pgdp,
17739+ val, (u64)val >> 32);
17740+ else
17741+ PVOP_VCALL2(pv_mmu_ops.set_pgd_batched, pgdp,
17742+ val);
17743+}
17744+
17745 static inline void pgd_clear(pgd_t *pgdp)
17746 {
17747 set_pgd(pgdp, __pgd(0));
17748@@ -710,6 +722,21 @@ static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
17749 pv_mmu_ops.set_fixmap(idx, phys, flags);
17750 }
17751
17752+#ifdef CONFIG_PAX_KERNEXEC
17753+static inline unsigned long pax_open_kernel(void)
17754+{
17755+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
17756+}
17757+
17758+static inline unsigned long pax_close_kernel(void)
17759+{
17760+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
17761+}
17762+#else
17763+static inline unsigned long pax_open_kernel(void) { return 0; }
17764+static inline unsigned long pax_close_kernel(void) { return 0; }
17765+#endif
17766+
17767 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
17768
17769 static __always_inline void __ticket_lock_spinning(struct arch_spinlock *lock,
17770@@ -906,7 +933,7 @@ extern void default_banner(void);
17771
17772 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
17773 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
17774-#define PARA_INDIRECT(addr) *%cs:addr
17775+#define PARA_INDIRECT(addr) *%ss:addr
17776 #endif
17777
17778 #define INTERRUPT_RETURN \
17779@@ -981,6 +1008,21 @@ extern void default_banner(void);
17780 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
17781 CLBR_NONE, \
17782 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
17783+
17784+#define GET_CR0_INTO_RDI \
17785+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
17786+ mov %rax,%rdi
17787+
17788+#define SET_RDI_INTO_CR0 \
17789+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
17790+
17791+#define GET_CR3_INTO_RDI \
17792+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
17793+ mov %rax,%rdi
17794+
17795+#define SET_RDI_INTO_CR3 \
17796+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
17797+
17798 #endif /* CONFIG_X86_32 */
17799
17800 #endif /* __ASSEMBLY__ */
17801diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h
17802index 7549b8b..f0edfda 100644
17803--- a/arch/x86/include/asm/paravirt_types.h
17804+++ b/arch/x86/include/asm/paravirt_types.h
17805@@ -84,7 +84,7 @@ struct pv_init_ops {
17806 */
17807 unsigned (*patch)(u8 type, u16 clobber, void *insnbuf,
17808 unsigned long addr, unsigned len);
17809-};
17810+} __no_const __no_randomize_layout;
17811
17812
17813 struct pv_lazy_ops {
17814@@ -92,13 +92,13 @@ struct pv_lazy_ops {
17815 void (*enter)(void);
17816 void (*leave)(void);
17817 void (*flush)(void);
17818-};
17819+} __no_randomize_layout;
17820
17821 struct pv_time_ops {
17822 unsigned long long (*sched_clock)(void);
17823 unsigned long long (*steal_clock)(int cpu);
17824 unsigned long (*get_tsc_khz)(void);
17825-};
17826+} __no_const __no_randomize_layout;
17827
17828 struct pv_cpu_ops {
17829 /* hooks for various privileged instructions */
17830@@ -192,7 +192,7 @@ struct pv_cpu_ops {
17831
17832 void (*start_context_switch)(struct task_struct *prev);
17833 void (*end_context_switch)(struct task_struct *next);
17834-};
17835+} __no_const __no_randomize_layout;
17836
17837 struct pv_irq_ops {
17838 /*
17839@@ -215,7 +215,7 @@ struct pv_irq_ops {
17840 #ifdef CONFIG_X86_64
17841 void (*adjust_exception_frame)(void);
17842 #endif
17843-};
17844+} __no_randomize_layout;
17845
17846 struct pv_apic_ops {
17847 #ifdef CONFIG_X86_LOCAL_APIC
17848@@ -223,7 +223,7 @@ struct pv_apic_ops {
17849 unsigned long start_eip,
17850 unsigned long start_esp);
17851 #endif
17852-};
17853+} __no_const __no_randomize_layout;
17854
17855 struct pv_mmu_ops {
17856 unsigned long (*read_cr2)(void);
17857@@ -313,6 +313,7 @@ struct pv_mmu_ops {
17858 struct paravirt_callee_save make_pud;
17859
17860 void (*set_pgd)(pgd_t *pudp, pgd_t pgdval);
17861+ void (*set_pgd_batched)(pgd_t *pudp, pgd_t pgdval);
17862 #endif /* PAGETABLE_LEVELS == 4 */
17863 #endif /* PAGETABLE_LEVELS >= 3 */
17864
17865@@ -324,7 +325,13 @@ struct pv_mmu_ops {
17866 an mfn. We can tell which is which from the index. */
17867 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
17868 phys_addr_t phys, pgprot_t flags);
17869-};
17870+
17871+#ifdef CONFIG_PAX_KERNEXEC
17872+ unsigned long (*pax_open_kernel)(void);
17873+ unsigned long (*pax_close_kernel)(void);
17874+#endif
17875+
17876+} __no_randomize_layout;
17877
17878 struct arch_spinlock;
17879 #ifdef CONFIG_SMP
17880@@ -336,11 +343,14 @@ typedef u16 __ticket_t;
17881 struct pv_lock_ops {
17882 struct paravirt_callee_save lock_spinning;
17883 void (*unlock_kick)(struct arch_spinlock *lock, __ticket_t ticket);
17884-};
17885+} __no_randomize_layout;
17886
17887 /* This contains all the paravirt structures: we get a convenient
17888 * number for each function using the offset which we use to indicate
17889- * what to patch. */
17890+ * what to patch.
17891+ * shouldn't be randomized due to the "NEAT TRICK" in paravirt.c
17892+ */
17893+
17894 struct paravirt_patch_template {
17895 struct pv_init_ops pv_init_ops;
17896 struct pv_time_ops pv_time_ops;
17897@@ -349,7 +359,7 @@ struct paravirt_patch_template {
17898 struct pv_apic_ops pv_apic_ops;
17899 struct pv_mmu_ops pv_mmu_ops;
17900 struct pv_lock_ops pv_lock_ops;
17901-};
17902+} __no_randomize_layout;
17903
17904 extern struct pv_info pv_info;
17905 extern struct pv_init_ops pv_init_ops;
17906diff --git a/arch/x86/include/asm/pgalloc.h b/arch/x86/include/asm/pgalloc.h
17907index c4412e9..90e88c5 100644
17908--- a/arch/x86/include/asm/pgalloc.h
17909+++ b/arch/x86/include/asm/pgalloc.h
17910@@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(struct mm_struct *mm,
17911 pmd_t *pmd, pte_t *pte)
17912 {
17913 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
17914+ set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
17915+}
17916+
17917+static inline void pmd_populate_user(struct mm_struct *mm,
17918+ pmd_t *pmd, pte_t *pte)
17919+{
17920+ paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
17921 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
17922 }
17923
17924@@ -108,12 +115,22 @@ static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd,
17925
17926 #ifdef CONFIG_X86_PAE
17927 extern void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd);
17928+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
17929+{
17930+ pud_populate(mm, pudp, pmd);
17931+}
17932 #else /* !CONFIG_X86_PAE */
17933 static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
17934 {
17935 paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
17936 set_pud(pud, __pud(_PAGE_TABLE | __pa(pmd)));
17937 }
17938+
17939+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
17940+{
17941+ paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
17942+ set_pud(pud, __pud(_KERNPG_TABLE | __pa(pmd)));
17943+}
17944 #endif /* CONFIG_X86_PAE */
17945
17946 #if PAGETABLE_LEVELS > 3
17947@@ -123,6 +140,12 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
17948 set_pgd(pgd, __pgd(_PAGE_TABLE | __pa(pud)));
17949 }
17950
17951+static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
17952+{
17953+ paravirt_alloc_pud(mm, __pa(pud) >> PAGE_SHIFT);
17954+ set_pgd(pgd, __pgd(_KERNPG_TABLE | __pa(pud)));
17955+}
17956+
17957 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
17958 {
17959 return (pud_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
17960diff --git a/arch/x86/include/asm/pgtable-2level.h b/arch/x86/include/asm/pgtable-2level.h
17961index 206a87f..1623b06 100644
17962--- a/arch/x86/include/asm/pgtable-2level.h
17963+++ b/arch/x86/include/asm/pgtable-2level.h
17964@@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t *ptep , pte_t pte)
17965
17966 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
17967 {
17968+ pax_open_kernel();
17969 *pmdp = pmd;
17970+ pax_close_kernel();
17971 }
17972
17973 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
17974diff --git a/arch/x86/include/asm/pgtable-3level.h b/arch/x86/include/asm/pgtable-3level.h
17975index 81bb91b..9392125 100644
17976--- a/arch/x86/include/asm/pgtable-3level.h
17977+++ b/arch/x86/include/asm/pgtable-3level.h
17978@@ -92,12 +92,16 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
17979
17980 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
17981 {
17982+ pax_open_kernel();
17983 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
17984+ pax_close_kernel();
17985 }
17986
17987 static inline void native_set_pud(pud_t *pudp, pud_t pud)
17988 {
17989+ pax_open_kernel();
17990 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
17991+ pax_close_kernel();
17992 }
17993
17994 /*
17995diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
17996index aa97a07..5c53c32 100644
17997--- a/arch/x86/include/asm/pgtable.h
17998+++ b/arch/x86/include/asm/pgtable.h
17999@@ -46,6 +46,7 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
18000
18001 #ifndef __PAGETABLE_PUD_FOLDED
18002 #define set_pgd(pgdp, pgd) native_set_pgd(pgdp, pgd)
18003+#define set_pgd_batched(pgdp, pgd) native_set_pgd_batched(pgdp, pgd)
18004 #define pgd_clear(pgd) native_pgd_clear(pgd)
18005 #endif
18006
18007@@ -83,12 +84,53 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
18008
18009 #define arch_end_context_switch(prev) do {} while(0)
18010
18011+#define pax_open_kernel() native_pax_open_kernel()
18012+#define pax_close_kernel() native_pax_close_kernel()
18013 #endif /* CONFIG_PARAVIRT */
18014
18015+#define __HAVE_ARCH_PAX_OPEN_KERNEL
18016+#define __HAVE_ARCH_PAX_CLOSE_KERNEL
18017+
18018+#ifdef CONFIG_PAX_KERNEXEC
18019+static inline unsigned long native_pax_open_kernel(void)
18020+{
18021+ unsigned long cr0;
18022+
18023+ preempt_disable();
18024+ barrier();
18025+ cr0 = read_cr0() ^ X86_CR0_WP;
18026+ BUG_ON(cr0 & X86_CR0_WP);
18027+ write_cr0(cr0);
18028+ barrier();
18029+ return cr0 ^ X86_CR0_WP;
18030+}
18031+
18032+static inline unsigned long native_pax_close_kernel(void)
18033+{
18034+ unsigned long cr0;
18035+
18036+ barrier();
18037+ cr0 = read_cr0() ^ X86_CR0_WP;
18038+ BUG_ON(!(cr0 & X86_CR0_WP));
18039+ write_cr0(cr0);
18040+ barrier();
18041+ preempt_enable_no_resched();
18042+ return cr0 ^ X86_CR0_WP;
18043+}
18044+#else
18045+static inline unsigned long native_pax_open_kernel(void) { return 0; }
18046+static inline unsigned long native_pax_close_kernel(void) { return 0; }
18047+#endif
18048+
18049 /*
18050 * The following only work if pte_present() is true.
18051 * Undefined behaviour if not..
18052 */
18053+static inline int pte_user(pte_t pte)
18054+{
18055+ return pte_val(pte) & _PAGE_USER;
18056+}
18057+
18058 static inline int pte_dirty(pte_t pte)
18059 {
18060 return pte_flags(pte) & _PAGE_DIRTY;
18061@@ -155,6 +197,11 @@ static inline unsigned long pud_pfn(pud_t pud)
18062 return (pud_val(pud) & PTE_PFN_MASK) >> PAGE_SHIFT;
18063 }
18064
18065+static inline unsigned long pgd_pfn(pgd_t pgd)
18066+{
18067+ return (pgd_val(pgd) & PTE_PFN_MASK) >> PAGE_SHIFT;
18068+}
18069+
18070 #define pte_page(pte) pfn_to_page(pte_pfn(pte))
18071
18072 static inline int pmd_large(pmd_t pte)
18073@@ -208,9 +255,29 @@ static inline pte_t pte_wrprotect(pte_t pte)
18074 return pte_clear_flags(pte, _PAGE_RW);
18075 }
18076
18077+static inline pte_t pte_mkread(pte_t pte)
18078+{
18079+ return __pte(pte_val(pte) | _PAGE_USER);
18080+}
18081+
18082 static inline pte_t pte_mkexec(pte_t pte)
18083 {
18084- return pte_clear_flags(pte, _PAGE_NX);
18085+#ifdef CONFIG_X86_PAE
18086+ if (__supported_pte_mask & _PAGE_NX)
18087+ return pte_clear_flags(pte, _PAGE_NX);
18088+ else
18089+#endif
18090+ return pte_set_flags(pte, _PAGE_USER);
18091+}
18092+
18093+static inline pte_t pte_exprotect(pte_t pte)
18094+{
18095+#ifdef CONFIG_X86_PAE
18096+ if (__supported_pte_mask & _PAGE_NX)
18097+ return pte_set_flags(pte, _PAGE_NX);
18098+ else
18099+#endif
18100+ return pte_clear_flags(pte, _PAGE_USER);
18101 }
18102
18103 static inline pte_t pte_mkdirty(pte_t pte)
18104@@ -440,6 +507,16 @@ pte_t *populate_extra_pte(unsigned long vaddr);
18105 #endif
18106
18107 #ifndef __ASSEMBLY__
18108+
18109+#ifdef CONFIG_PAX_PER_CPU_PGD
18110+extern pgd_t cpu_pgd[NR_CPUS][2][PTRS_PER_PGD];
18111+enum cpu_pgd_type {kernel = 0, user = 1};
18112+static inline pgd_t *get_cpu_pgd(unsigned int cpu, enum cpu_pgd_type type)
18113+{
18114+ return cpu_pgd[cpu][type];
18115+}
18116+#endif
18117+
18118 #include <linux/mm_types.h>
18119 #include <linux/mmdebug.h>
18120 #include <linux/log2.h>
18121@@ -586,7 +663,7 @@ static inline unsigned long pud_page_vaddr(pud_t pud)
18122 * Currently stuck as a macro due to indirect forward reference to
18123 * linux/mmzone.h's __section_mem_map_addr() definition:
18124 */
18125-#define pud_page(pud) pfn_to_page(pud_val(pud) >> PAGE_SHIFT)
18126+#define pud_page(pud) pfn_to_page((pud_val(pud) & PTE_PFN_MASK) >> PAGE_SHIFT)
18127
18128 /* Find an entry in the second-level page table.. */
18129 static inline pmd_t *pmd_offset(pud_t *pud, unsigned long address)
18130@@ -626,7 +703,7 @@ static inline unsigned long pgd_page_vaddr(pgd_t pgd)
18131 * Currently stuck as a macro due to indirect forward reference to
18132 * linux/mmzone.h's __section_mem_map_addr() definition:
18133 */
18134-#define pgd_page(pgd) pfn_to_page(pgd_val(pgd) >> PAGE_SHIFT)
18135+#define pgd_page(pgd) pfn_to_page((pgd_val(pgd) & PTE_PFN_MASK) >> PAGE_SHIFT)
18136
18137 /* to find an entry in a page-table-directory. */
18138 static inline unsigned long pud_index(unsigned long address)
18139@@ -641,7 +718,7 @@ static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
18140
18141 static inline int pgd_bad(pgd_t pgd)
18142 {
18143- return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
18144+ return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
18145 }
18146
18147 static inline int pgd_none(pgd_t pgd)
18148@@ -664,7 +741,12 @@ static inline int pgd_none(pgd_t pgd)
18149 * pgd_offset() returns a (pgd_t *)
18150 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
18151 */
18152-#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
18153+#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
18154+
18155+#ifdef CONFIG_PAX_PER_CPU_PGD
18156+#define pgd_offset_cpu(cpu, type, address) (get_cpu_pgd(cpu, type) + pgd_index(address))
18157+#endif
18158+
18159 /*
18160 * a shortcut which implies the use of the kernel's pgd, instead
18161 * of a process's
18162@@ -675,6 +757,23 @@ static inline int pgd_none(pgd_t pgd)
18163 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
18164 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
18165
18166+#ifdef CONFIG_X86_32
18167+#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
18168+#else
18169+#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
18170+#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
18171+
18172+#ifdef CONFIG_PAX_MEMORY_UDEREF
18173+#ifdef __ASSEMBLY__
18174+#define pax_user_shadow_base pax_user_shadow_base(%rip)
18175+#else
18176+extern unsigned long pax_user_shadow_base;
18177+extern pgdval_t clone_pgd_mask;
18178+#endif
18179+#endif
18180+
18181+#endif
18182+
18183 #ifndef __ASSEMBLY__
18184
18185 extern int direct_gbpages;
18186@@ -841,11 +940,24 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,
18187 * dst and src can be on the same page, but the range must not overlap,
18188 * and must not cross a page boundary.
18189 */
18190-static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
18191+static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
18192 {
18193- memcpy(dst, src, count * sizeof(pgd_t));
18194+ pax_open_kernel();
18195+ while (count--)
18196+ *dst++ = *src++;
18197+ pax_close_kernel();
18198 }
18199
18200+#ifdef CONFIG_PAX_PER_CPU_PGD
18201+extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src);
18202+#endif
18203+
18204+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18205+extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src);
18206+#else
18207+static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src) {}
18208+#endif
18209+
18210 #define PTE_SHIFT ilog2(PTRS_PER_PTE)
18211 static inline int page_level_shift(enum pg_level level)
18212 {
18213diff --git a/arch/x86/include/asm/pgtable_32.h b/arch/x86/include/asm/pgtable_32.h
18214index b6c0b40..3535d47 100644
18215--- a/arch/x86/include/asm/pgtable_32.h
18216+++ b/arch/x86/include/asm/pgtable_32.h
18217@@ -25,9 +25,6 @@
18218 struct mm_struct;
18219 struct vm_area_struct;
18220
18221-extern pgd_t swapper_pg_dir[1024];
18222-extern pgd_t initial_page_table[1024];
18223-
18224 static inline void pgtable_cache_init(void) { }
18225 static inline void check_pgt_cache(void) { }
18226 void paging_init(void);
18227@@ -45,6 +42,12 @@ void paging_init(void);
18228 # include <asm/pgtable-2level.h>
18229 #endif
18230
18231+extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
18232+extern pgd_t initial_page_table[PTRS_PER_PGD];
18233+#ifdef CONFIG_X86_PAE
18234+extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
18235+#endif
18236+
18237 #if defined(CONFIG_HIGHPTE)
18238 #define pte_offset_map(dir, address) \
18239 ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
18240@@ -59,12 +62,17 @@ void paging_init(void);
18241 /* Clear a kernel PTE and flush it from the TLB */
18242 #define kpte_clear_flush(ptep, vaddr) \
18243 do { \
18244+ pax_open_kernel(); \
18245 pte_clear(&init_mm, (vaddr), (ptep)); \
18246+ pax_close_kernel(); \
18247 __flush_tlb_one((vaddr)); \
18248 } while (0)
18249
18250 #endif /* !__ASSEMBLY__ */
18251
18252+#define HAVE_ARCH_UNMAPPED_AREA
18253+#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
18254+
18255 /*
18256 * kern_addr_valid() is (1) for FLATMEM and (0) for
18257 * SPARSEMEM and DISCONTIGMEM
18258diff --git a/arch/x86/include/asm/pgtable_32_types.h b/arch/x86/include/asm/pgtable_32_types.h
18259index ed5903b..c7fe163 100644
18260--- a/arch/x86/include/asm/pgtable_32_types.h
18261+++ b/arch/x86/include/asm/pgtable_32_types.h
18262@@ -8,7 +8,7 @@
18263 */
18264 #ifdef CONFIG_X86_PAE
18265 # include <asm/pgtable-3level_types.h>
18266-# define PMD_SIZE (1UL << PMD_SHIFT)
18267+# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
18268 # define PMD_MASK (~(PMD_SIZE - 1))
18269 #else
18270 # include <asm/pgtable-2level_types.h>
18271@@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set once high_memory is set */
18272 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
18273 #endif
18274
18275+#ifdef CONFIG_PAX_KERNEXEC
18276+#ifndef __ASSEMBLY__
18277+extern unsigned char MODULES_EXEC_VADDR[];
18278+extern unsigned char MODULES_EXEC_END[];
18279+#endif
18280+#include <asm/boot.h>
18281+#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
18282+#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
18283+#else
18284+#define ktla_ktva(addr) (addr)
18285+#define ktva_ktla(addr) (addr)
18286+#endif
18287+
18288 #define MODULES_VADDR VMALLOC_START
18289 #define MODULES_END VMALLOC_END
18290 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
18291diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
18292index 4572b2f..4430113 100644
18293--- a/arch/x86/include/asm/pgtable_64.h
18294+++ b/arch/x86/include/asm/pgtable_64.h
18295@@ -16,11 +16,16 @@
18296
18297 extern pud_t level3_kernel_pgt[512];
18298 extern pud_t level3_ident_pgt[512];
18299+extern pud_t level3_vmalloc_start_pgt[512];
18300+extern pud_t level3_vmalloc_end_pgt[512];
18301+extern pud_t level3_vmemmap_pgt[512];
18302+extern pud_t level2_vmemmap_pgt[512];
18303 extern pmd_t level2_kernel_pgt[512];
18304 extern pmd_t level2_fixmap_pgt[512];
18305-extern pmd_t level2_ident_pgt[512];
18306+extern pmd_t level2_ident_pgt[512*2];
18307 extern pte_t level1_fixmap_pgt[512];
18308-extern pgd_t init_level4_pgt[];
18309+extern pte_t level1_vsyscall_pgt[512];
18310+extern pgd_t init_level4_pgt[512];
18311
18312 #define swapper_pg_dir init_level4_pgt
18313
18314@@ -62,7 +67,9 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
18315
18316 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
18317 {
18318+ pax_open_kernel();
18319 *pmdp = pmd;
18320+ pax_close_kernel();
18321 }
18322
18323 static inline void native_pmd_clear(pmd_t *pmd)
18324@@ -98,7 +105,9 @@ static inline pmd_t native_pmdp_get_and_clear(pmd_t *xp)
18325
18326 static inline void native_set_pud(pud_t *pudp, pud_t pud)
18327 {
18328+ pax_open_kernel();
18329 *pudp = pud;
18330+ pax_close_kernel();
18331 }
18332
18333 static inline void native_pud_clear(pud_t *pud)
18334@@ -108,6 +117,13 @@ static inline void native_pud_clear(pud_t *pud)
18335
18336 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
18337 {
18338+ pax_open_kernel();
18339+ *pgdp = pgd;
18340+ pax_close_kernel();
18341+}
18342+
18343+static inline void native_set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
18344+{
18345 *pgdp = pgd;
18346 }
18347
18348diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h
18349index 7166e25..baaa6fe 100644
18350--- a/arch/x86/include/asm/pgtable_64_types.h
18351+++ b/arch/x86/include/asm/pgtable_64_types.h
18352@@ -61,9 +61,14 @@ typedef struct { pteval_t pte; } pte_t;
18353 #define MODULES_VADDR (__START_KERNEL_map + KERNEL_IMAGE_SIZE)
18354 #define MODULES_END _AC(0xffffffffff000000, UL)
18355 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
18356+#define MODULES_EXEC_VADDR MODULES_VADDR
18357+#define MODULES_EXEC_END MODULES_END
18358 #define ESPFIX_PGD_ENTRY _AC(-2, UL)
18359 #define ESPFIX_BASE_ADDR (ESPFIX_PGD_ENTRY << PGDIR_SHIFT)
18360
18361+#define ktla_ktva(addr) (addr)
18362+#define ktva_ktla(addr) (addr)
18363+
18364 #define EARLY_DYNAMIC_PAGE_TABLES 64
18365
18366 #endif /* _ASM_X86_PGTABLE_64_DEFS_H */
18367diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
18368index 0778964..0e94758 100644
18369--- a/arch/x86/include/asm/pgtable_types.h
18370+++ b/arch/x86/include/asm/pgtable_types.h
18371@@ -110,8 +110,10 @@
18372
18373 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
18374 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
18375-#else
18376+#elif defined(CONFIG_KMEMCHECK) || defined(CONFIG_MEM_SOFT_DIRTY)
18377 #define _PAGE_NX (_AT(pteval_t, 0))
18378+#else
18379+#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
18380 #endif
18381
18382 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
18383@@ -150,6 +152,9 @@
18384 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
18385 _PAGE_ACCESSED)
18386
18387+#define PAGE_READONLY_NOEXEC PAGE_READONLY
18388+#define PAGE_SHARED_NOEXEC PAGE_SHARED
18389+
18390 #define __PAGE_KERNEL_EXEC \
18391 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
18392 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
18393@@ -160,7 +165,7 @@
18394 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
18395 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
18396 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
18397-#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
18398+#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
18399 #define __PAGE_KERNEL_VVAR (__PAGE_KERNEL_RO | _PAGE_USER)
18400 #define __PAGE_KERNEL_VVAR_NOCACHE (__PAGE_KERNEL_VVAR | _PAGE_PCD | _PAGE_PWT)
18401 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
18402@@ -217,7 +222,7 @@
18403 #ifdef CONFIG_X86_64
18404 #define __PAGE_KERNEL_IDENT_LARGE_EXEC __PAGE_KERNEL_LARGE_EXEC
18405 #else
18406-#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
18407+#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
18408 #define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
18409 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
18410 #endif
18411@@ -256,7 +261,17 @@ static inline pgdval_t pgd_flags(pgd_t pgd)
18412 {
18413 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
18414 }
18415+#endif
18416
18417+#if PAGETABLE_LEVELS == 3
18418+#include <asm-generic/pgtable-nopud.h>
18419+#endif
18420+
18421+#if PAGETABLE_LEVELS == 2
18422+#include <asm-generic/pgtable-nopmd.h>
18423+#endif
18424+
18425+#ifndef __ASSEMBLY__
18426 #if PAGETABLE_LEVELS > 3
18427 typedef struct { pudval_t pud; } pud_t;
18428
18429@@ -270,8 +285,6 @@ static inline pudval_t native_pud_val(pud_t pud)
18430 return pud.pud;
18431 }
18432 #else
18433-#include <asm-generic/pgtable-nopud.h>
18434-
18435 static inline pudval_t native_pud_val(pud_t pud)
18436 {
18437 return native_pgd_val(pud.pgd);
18438@@ -291,8 +304,6 @@ static inline pmdval_t native_pmd_val(pmd_t pmd)
18439 return pmd.pmd;
18440 }
18441 #else
18442-#include <asm-generic/pgtable-nopmd.h>
18443-
18444 static inline pmdval_t native_pmd_val(pmd_t pmd)
18445 {
18446 return native_pgd_val(pmd.pud.pgd);
18447@@ -346,7 +357,6 @@ typedef struct page *pgtable_t;
18448
18449 extern pteval_t __supported_pte_mask;
18450 extern void set_nx(void);
18451-extern int nx_enabled;
18452
18453 #define pgprot_writecombine pgprot_writecombine
18454 extern pgprot_t pgprot_writecombine(pgprot_t prot);
18455diff --git a/arch/x86/include/asm/preempt.h b/arch/x86/include/asm/preempt.h
18456index 4008734..48f0d81 100644
18457--- a/arch/x86/include/asm/preempt.h
18458+++ b/arch/x86/include/asm/preempt.h
18459@@ -87,7 +87,7 @@ static __always_inline void __preempt_count_sub(int val)
18460 */
18461 static __always_inline bool __preempt_count_dec_and_test(void)
18462 {
18463- GEN_UNARY_RMWcc("decl", __preempt_count, __percpu_arg(0), "e");
18464+ GEN_UNARY_RMWcc("decl", "incl", __preempt_count, __percpu_arg(0), "e");
18465 }
18466
18467 /*
18468diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
18469index eb71ec7..f06532a 100644
18470--- a/arch/x86/include/asm/processor.h
18471+++ b/arch/x86/include/asm/processor.h
18472@@ -127,7 +127,7 @@ struct cpuinfo_x86 {
18473 /* Index into per_cpu list: */
18474 u16 cpu_index;
18475 u32 microcode;
18476-} __attribute__((__aligned__(SMP_CACHE_BYTES)));
18477+} __attribute__((__aligned__(SMP_CACHE_BYTES))) __randomize_layout;
18478
18479 #define X86_VENDOR_INTEL 0
18480 #define X86_VENDOR_CYRIX 1
18481@@ -198,9 +198,21 @@ static inline void native_cpuid(unsigned int *eax, unsigned int *ebx,
18482 : "memory");
18483 }
18484
18485+/* invpcid (%rdx),%rax */
18486+#define __ASM_INVPCID ".byte 0x66,0x0f,0x38,0x82,0x02"
18487+
18488+#define INVPCID_SINGLE_ADDRESS 0UL
18489+#define INVPCID_SINGLE_CONTEXT 1UL
18490+#define INVPCID_ALL_GLOBAL 2UL
18491+#define INVPCID_ALL_NONGLOBAL 3UL
18492+
18493+#define PCID_KERNEL 0UL
18494+#define PCID_USER 1UL
18495+#define PCID_NOFLUSH (1UL << 63)
18496+
18497 static inline void load_cr3(pgd_t *pgdir)
18498 {
18499- write_cr3(__pa(pgdir));
18500+ write_cr3(__pa(pgdir) | PCID_KERNEL);
18501 }
18502
18503 #ifdef CONFIG_X86_32
18504@@ -282,7 +294,7 @@ struct tss_struct {
18505
18506 } ____cacheline_aligned;
18507
18508-DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
18509+extern struct tss_struct init_tss[NR_CPUS];
18510
18511 /*
18512 * Save the original ist values for checking stack pointers during debugging
18513@@ -478,6 +490,7 @@ struct thread_struct {
18514 unsigned short ds;
18515 unsigned short fsindex;
18516 unsigned short gsindex;
18517+ unsigned short ss;
18518 #endif
18519 #ifdef CONFIG_X86_32
18520 unsigned long ip;
18521@@ -587,29 +600,8 @@ static inline void load_sp0(struct tss_struct *tss,
18522 extern unsigned long mmu_cr4_features;
18523 extern u32 *trampoline_cr4_features;
18524
18525-static inline void set_in_cr4(unsigned long mask)
18526-{
18527- unsigned long cr4;
18528-
18529- mmu_cr4_features |= mask;
18530- if (trampoline_cr4_features)
18531- *trampoline_cr4_features = mmu_cr4_features;
18532- cr4 = read_cr4();
18533- cr4 |= mask;
18534- write_cr4(cr4);
18535-}
18536-
18537-static inline void clear_in_cr4(unsigned long mask)
18538-{
18539- unsigned long cr4;
18540-
18541- mmu_cr4_features &= ~mask;
18542- if (trampoline_cr4_features)
18543- *trampoline_cr4_features = mmu_cr4_features;
18544- cr4 = read_cr4();
18545- cr4 &= ~mask;
18546- write_cr4(cr4);
18547-}
18548+extern void set_in_cr4(unsigned long mask);
18549+extern void clear_in_cr4(unsigned long mask);
18550
18551 typedef struct {
18552 unsigned long seg;
18553@@ -837,11 +829,18 @@ static inline void spin_lock_prefetch(const void *x)
18554 */
18555 #define TASK_SIZE PAGE_OFFSET
18556 #define TASK_SIZE_MAX TASK_SIZE
18557+
18558+#ifdef CONFIG_PAX_SEGMEXEC
18559+#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
18560+#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
18561+#else
18562 #define STACK_TOP TASK_SIZE
18563-#define STACK_TOP_MAX STACK_TOP
18564+#endif
18565+
18566+#define STACK_TOP_MAX TASK_SIZE
18567
18568 #define INIT_THREAD { \
18569- .sp0 = sizeof(init_stack) + (long)&init_stack, \
18570+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
18571 .vm86_info = NULL, \
18572 .sysenter_cs = __KERNEL_CS, \
18573 .io_bitmap_ptr = NULL, \
18574@@ -855,7 +854,7 @@ static inline void spin_lock_prefetch(const void *x)
18575 */
18576 #define INIT_TSS { \
18577 .x86_tss = { \
18578- .sp0 = sizeof(init_stack) + (long)&init_stack, \
18579+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
18580 .ss0 = __KERNEL_DS, \
18581 .ss1 = __KERNEL_CS, \
18582 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
18583@@ -866,11 +865,7 @@ static inline void spin_lock_prefetch(const void *x)
18584 extern unsigned long thread_saved_pc(struct task_struct *tsk);
18585
18586 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
18587-#define KSTK_TOP(info) \
18588-({ \
18589- unsigned long *__ptr = (unsigned long *)(info); \
18590- (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
18591-})
18592+#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
18593
18594 /*
18595 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
18596@@ -885,7 +880,7 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
18597 #define task_pt_regs(task) \
18598 ({ \
18599 struct pt_regs *__regs__; \
18600- __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
18601+ __regs__ = (struct pt_regs *)((task)->thread.sp0); \
18602 __regs__ - 1; \
18603 })
18604
18605@@ -895,13 +890,13 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
18606 /*
18607 * User space process size. 47bits minus one guard page.
18608 */
18609-#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
18610+#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
18611
18612 /* This decides where the kernel will search for a free chunk of vm
18613 * space during mmap's.
18614 */
18615 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
18616- 0xc0000000 : 0xFFFFe000)
18617+ 0xc0000000 : 0xFFFFf000)
18618
18619 #define TASK_SIZE (test_thread_flag(TIF_ADDR32) ? \
18620 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
18621@@ -912,11 +907,11 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
18622 #define STACK_TOP_MAX TASK_SIZE_MAX
18623
18624 #define INIT_THREAD { \
18625- .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
18626+ .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
18627 }
18628
18629 #define INIT_TSS { \
18630- .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
18631+ .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
18632 }
18633
18634 /*
18635@@ -944,6 +939,10 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
18636 */
18637 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
18638
18639+#ifdef CONFIG_PAX_SEGMEXEC
18640+#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
18641+#endif
18642+
18643 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
18644
18645 /* Get/set a process' ability to use the timestamp counter instruction */
18646@@ -970,7 +969,7 @@ static inline uint32_t hypervisor_cpuid_base(const char *sig, uint32_t leaves)
18647 return 0;
18648 }
18649
18650-extern unsigned long arch_align_stack(unsigned long sp);
18651+#define arch_align_stack(x) ((x) & ~0xfUL)
18652 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
18653
18654 void default_idle(void);
18655@@ -980,6 +979,6 @@ bool xen_set_default_idle(void);
18656 #define xen_set_default_idle 0
18657 #endif
18658
18659-void stop_this_cpu(void *dummy);
18660+void stop_this_cpu(void *dummy) __noreturn;
18661 void df_debug(struct pt_regs *regs, long error_code);
18662 #endif /* _ASM_X86_PROCESSOR_H */
18663diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
18664index 86fc2bb..bd5049a 100644
18665--- a/arch/x86/include/asm/ptrace.h
18666+++ b/arch/x86/include/asm/ptrace.h
18667@@ -89,28 +89,29 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
18668 }
18669
18670 /*
18671- * user_mode_vm(regs) determines whether a register set came from user mode.
18672+ * user_mode(regs) determines whether a register set came from user mode.
18673 * This is true if V8086 mode was enabled OR if the register set was from
18674 * protected mode with RPL-3 CS value. This tricky test checks that with
18675 * one comparison. Many places in the kernel can bypass this full check
18676- * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
18677+ * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
18678+ * be used.
18679 */
18680-static inline int user_mode(struct pt_regs *regs)
18681+static inline int user_mode_novm(struct pt_regs *regs)
18682 {
18683 #ifdef CONFIG_X86_32
18684 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
18685 #else
18686- return !!(regs->cs & 3);
18687+ return !!(regs->cs & SEGMENT_RPL_MASK);
18688 #endif
18689 }
18690
18691-static inline int user_mode_vm(struct pt_regs *regs)
18692+static inline int user_mode(struct pt_regs *regs)
18693 {
18694 #ifdef CONFIG_X86_32
18695 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
18696 USER_RPL;
18697 #else
18698- return user_mode(regs);
18699+ return user_mode_novm(regs);
18700 #endif
18701 }
18702
18703@@ -126,15 +127,16 @@ static inline int v8086_mode(struct pt_regs *regs)
18704 #ifdef CONFIG_X86_64
18705 static inline bool user_64bit_mode(struct pt_regs *regs)
18706 {
18707+ unsigned long cs = regs->cs & 0xffff;
18708 #ifndef CONFIG_PARAVIRT
18709 /*
18710 * On non-paravirt systems, this is the only long mode CPL 3
18711 * selector. We do not allow long mode selectors in the LDT.
18712 */
18713- return regs->cs == __USER_CS;
18714+ return cs == __USER_CS;
18715 #else
18716 /* Headers are too twisted for this to go in paravirt.h. */
18717- return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs;
18718+ return cs == __USER_CS || cs == pv_info.extra_user_64bit_cs;
18719 #endif
18720 }
18721
18722@@ -185,9 +187,11 @@ static inline unsigned long regs_get_register(struct pt_regs *regs,
18723 * Traps from the kernel do not save sp and ss.
18724 * Use the helper function to retrieve sp.
18725 */
18726- if (offset == offsetof(struct pt_regs, sp) &&
18727- regs->cs == __KERNEL_CS)
18728- return kernel_stack_pointer(regs);
18729+ if (offset == offsetof(struct pt_regs, sp)) {
18730+ unsigned long cs = regs->cs & 0xffff;
18731+ if (cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS)
18732+ return kernel_stack_pointer(regs);
18733+ }
18734 #endif
18735 return *(unsigned long *)((unsigned long)regs + offset);
18736 }
18737diff --git a/arch/x86/include/asm/qrwlock.h b/arch/x86/include/asm/qrwlock.h
18738index ae0e241..e80b10b 100644
18739--- a/arch/x86/include/asm/qrwlock.h
18740+++ b/arch/x86/include/asm/qrwlock.h
18741@@ -7,8 +7,8 @@
18742 #define queue_write_unlock queue_write_unlock
18743 static inline void queue_write_unlock(struct qrwlock *lock)
18744 {
18745- barrier();
18746- ACCESS_ONCE(*(u8 *)&lock->cnts) = 0;
18747+ barrier();
18748+ ACCESS_ONCE_RW(*(u8 *)&lock->cnts) = 0;
18749 }
18750 #endif
18751
18752diff --git a/arch/x86/include/asm/realmode.h b/arch/x86/include/asm/realmode.h
18753index 9c6b890..5305f53 100644
18754--- a/arch/x86/include/asm/realmode.h
18755+++ b/arch/x86/include/asm/realmode.h
18756@@ -22,16 +22,14 @@ struct real_mode_header {
18757 #endif
18758 /* APM/BIOS reboot */
18759 u32 machine_real_restart_asm;
18760-#ifdef CONFIG_X86_64
18761 u32 machine_real_restart_seg;
18762-#endif
18763 };
18764
18765 /* This must match data at trampoline_32/64.S */
18766 struct trampoline_header {
18767 #ifdef CONFIG_X86_32
18768 u32 start;
18769- u16 gdt_pad;
18770+ u16 boot_cs;
18771 u16 gdt_limit;
18772 u32 gdt_base;
18773 #else
18774diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h
18775index a82c4f1..ac45053 100644
18776--- a/arch/x86/include/asm/reboot.h
18777+++ b/arch/x86/include/asm/reboot.h
18778@@ -6,13 +6,13 @@
18779 struct pt_regs;
18780
18781 struct machine_ops {
18782- void (*restart)(char *cmd);
18783- void (*halt)(void);
18784- void (*power_off)(void);
18785+ void (* __noreturn restart)(char *cmd);
18786+ void (* __noreturn halt)(void);
18787+ void (* __noreturn power_off)(void);
18788 void (*shutdown)(void);
18789 void (*crash_shutdown)(struct pt_regs *);
18790- void (*emergency_restart)(void);
18791-};
18792+ void (* __noreturn emergency_restart)(void);
18793+} __no_const;
18794
18795 extern struct machine_ops machine_ops;
18796
18797diff --git a/arch/x86/include/asm/rmwcc.h b/arch/x86/include/asm/rmwcc.h
18798index 8f7866a..e442f20 100644
18799--- a/arch/x86/include/asm/rmwcc.h
18800+++ b/arch/x86/include/asm/rmwcc.h
18801@@ -3,7 +3,34 @@
18802
18803 #ifdef CC_HAVE_ASM_GOTO
18804
18805-#define __GEN_RMWcc(fullop, var, cc, ...) \
18806+#ifdef CONFIG_PAX_REFCOUNT
18807+#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
18808+do { \
18809+ asm_volatile_goto (fullop \
18810+ ";jno 0f\n" \
18811+ fullantiop \
18812+ ";int $4\n0:\n" \
18813+ _ASM_EXTABLE(0b, 0b) \
18814+ ";j" cc " %l[cc_label]" \
18815+ : : "m" (var), ## __VA_ARGS__ \
18816+ : "memory" : cc_label); \
18817+ return 0; \
18818+cc_label: \
18819+ return 1; \
18820+} while (0)
18821+#else
18822+#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
18823+do { \
18824+ asm_volatile_goto (fullop ";j" cc " %l[cc_label]" \
18825+ : : "m" (var), ## __VA_ARGS__ \
18826+ : "memory" : cc_label); \
18827+ return 0; \
18828+cc_label: \
18829+ return 1; \
18830+} while (0)
18831+#endif
18832+
18833+#define __GEN_RMWcc_unchecked(fullop, var, cc, ...) \
18834 do { \
18835 asm_volatile_goto (fullop "; j" cc " %l[cc_label]" \
18836 : : "m" (var), ## __VA_ARGS__ \
18837@@ -13,15 +40,46 @@ cc_label: \
18838 return 1; \
18839 } while (0)
18840
18841-#define GEN_UNARY_RMWcc(op, var, arg0, cc) \
18842- __GEN_RMWcc(op " " arg0, var, cc)
18843+#define GEN_UNARY_RMWcc(op, antiop, var, arg0, cc) \
18844+ __GEN_RMWcc(op " " arg0, antiop " " arg0, var, cc)
18845
18846-#define GEN_BINARY_RMWcc(op, var, vcon, val, arg0, cc) \
18847- __GEN_RMWcc(op " %1, " arg0, var, cc, vcon (val))
18848+#define GEN_UNARY_RMWcc_unchecked(op, var, arg0, cc) \
18849+ __GEN_RMWcc_unchecked(op " " arg0, var, cc)
18850+
18851+#define GEN_BINARY_RMWcc(op, antiop, var, vcon, val, arg0, cc) \
18852+ __GEN_RMWcc(op " %1, " arg0, antiop " %1, " arg0, var, cc, vcon (val))
18853+
18854+#define GEN_BINARY_RMWcc_unchecked(op, var, vcon, val, arg0, cc) \
18855+ __GEN_RMWcc_unchecked(op " %1, " arg0, var, cc, vcon (val))
18856
18857 #else /* !CC_HAVE_ASM_GOTO */
18858
18859-#define __GEN_RMWcc(fullop, var, cc, ...) \
18860+#ifdef CONFIG_PAX_REFCOUNT
18861+#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
18862+do { \
18863+ char c; \
18864+ asm volatile (fullop \
18865+ ";jno 0f\n" \
18866+ fullantiop \
18867+ ";int $4\n0:\n" \
18868+ _ASM_EXTABLE(0b, 0b) \
18869+ "; set" cc " %1" \
18870+ : "+m" (var), "=qm" (c) \
18871+ : __VA_ARGS__ : "memory"); \
18872+ return c != 0; \
18873+} while (0)
18874+#else
18875+#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
18876+do { \
18877+ char c; \
18878+ asm volatile (fullop "; set" cc " %1" \
18879+ : "+m" (var), "=qm" (c) \
18880+ : __VA_ARGS__ : "memory"); \
18881+ return c != 0; \
18882+} while (0)
18883+#endif
18884+
18885+#define __GEN_RMWcc_unchecked(fullop, var, cc, ...) \
18886 do { \
18887 char c; \
18888 asm volatile (fullop "; set" cc " %1" \
18889@@ -30,11 +88,17 @@ do { \
18890 return c != 0; \
18891 } while (0)
18892
18893-#define GEN_UNARY_RMWcc(op, var, arg0, cc) \
18894- __GEN_RMWcc(op " " arg0, var, cc)
18895+#define GEN_UNARY_RMWcc(op, antiop, var, arg0, cc) \
18896+ __GEN_RMWcc(op " " arg0, antiop " " arg0, var, cc)
18897+
18898+#define GEN_UNARY_RMWcc_unchecked(op, var, arg0, cc) \
18899+ __GEN_RMWcc_unchecked(op " " arg0, var, cc)
18900+
18901+#define GEN_BINARY_RMWcc(op, antiop, var, vcon, val, arg0, cc) \
18902+ __GEN_RMWcc(op " %2, " arg0, antiop " %2, " arg0, var, cc, vcon (val))
18903
18904-#define GEN_BINARY_RMWcc(op, var, vcon, val, arg0, cc) \
18905- __GEN_RMWcc(op " %2, " arg0, var, cc, vcon (val))
18906+#define GEN_BINARY_RMWcc_unchecked(op, var, vcon, val, arg0, cc) \
18907+ __GEN_RMWcc_unchecked(op " %2, " arg0, var, cc, vcon (val))
18908
18909 #endif /* CC_HAVE_ASM_GOTO */
18910
18911diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h
18912index cad82c9..2e5c5c1 100644
18913--- a/arch/x86/include/asm/rwsem.h
18914+++ b/arch/x86/include/asm/rwsem.h
18915@@ -64,6 +64,14 @@ static inline void __down_read(struct rw_semaphore *sem)
18916 {
18917 asm volatile("# beginning down_read\n\t"
18918 LOCK_PREFIX _ASM_INC "(%1)\n\t"
18919+
18920+#ifdef CONFIG_PAX_REFCOUNT
18921+ "jno 0f\n"
18922+ LOCK_PREFIX _ASM_DEC "(%1)\n"
18923+ "int $4\n0:\n"
18924+ _ASM_EXTABLE(0b, 0b)
18925+#endif
18926+
18927 /* adds 0x00000001 */
18928 " jns 1f\n"
18929 " call call_rwsem_down_read_failed\n"
18930@@ -85,6 +93,14 @@ static inline int __down_read_trylock(struct rw_semaphore *sem)
18931 "1:\n\t"
18932 " mov %1,%2\n\t"
18933 " add %3,%2\n\t"
18934+
18935+#ifdef CONFIG_PAX_REFCOUNT
18936+ "jno 0f\n"
18937+ "sub %3,%2\n"
18938+ "int $4\n0:\n"
18939+ _ASM_EXTABLE(0b, 0b)
18940+#endif
18941+
18942 " jle 2f\n\t"
18943 LOCK_PREFIX " cmpxchg %2,%0\n\t"
18944 " jnz 1b\n\t"
18945@@ -104,6 +120,14 @@ static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
18946 long tmp;
18947 asm volatile("# beginning down_write\n\t"
18948 LOCK_PREFIX " xadd %1,(%2)\n\t"
18949+
18950+#ifdef CONFIG_PAX_REFCOUNT
18951+ "jno 0f\n"
18952+ "mov %1,(%2)\n"
18953+ "int $4\n0:\n"
18954+ _ASM_EXTABLE(0b, 0b)
18955+#endif
18956+
18957 /* adds 0xffff0001, returns the old value */
18958 " test " __ASM_SEL(%w1,%k1) "," __ASM_SEL(%w1,%k1) "\n\t"
18959 /* was the active mask 0 before? */
18960@@ -155,6 +179,14 @@ static inline void __up_read(struct rw_semaphore *sem)
18961 long tmp;
18962 asm volatile("# beginning __up_read\n\t"
18963 LOCK_PREFIX " xadd %1,(%2)\n\t"
18964+
18965+#ifdef CONFIG_PAX_REFCOUNT
18966+ "jno 0f\n"
18967+ "mov %1,(%2)\n"
18968+ "int $4\n0:\n"
18969+ _ASM_EXTABLE(0b, 0b)
18970+#endif
18971+
18972 /* subtracts 1, returns the old value */
18973 " jns 1f\n\t"
18974 " call call_rwsem_wake\n" /* expects old value in %edx */
18975@@ -173,6 +205,14 @@ static inline void __up_write(struct rw_semaphore *sem)
18976 long tmp;
18977 asm volatile("# beginning __up_write\n\t"
18978 LOCK_PREFIX " xadd %1,(%2)\n\t"
18979+
18980+#ifdef CONFIG_PAX_REFCOUNT
18981+ "jno 0f\n"
18982+ "mov %1,(%2)\n"
18983+ "int $4\n0:\n"
18984+ _ASM_EXTABLE(0b, 0b)
18985+#endif
18986+
18987 /* subtracts 0xffff0001, returns the old value */
18988 " jns 1f\n\t"
18989 " call call_rwsem_wake\n" /* expects old value in %edx */
18990@@ -190,6 +230,14 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
18991 {
18992 asm volatile("# beginning __downgrade_write\n\t"
18993 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
18994+
18995+#ifdef CONFIG_PAX_REFCOUNT
18996+ "jno 0f\n"
18997+ LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
18998+ "int $4\n0:\n"
18999+ _ASM_EXTABLE(0b, 0b)
19000+#endif
19001+
19002 /*
19003 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
19004 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
19005@@ -208,7 +256,15 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
19006 */
19007 static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
19008 {
19009- asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
19010+ asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
19011+
19012+#ifdef CONFIG_PAX_REFCOUNT
19013+ "jno 0f\n"
19014+ LOCK_PREFIX _ASM_SUB "%1,%0\n"
19015+ "int $4\n0:\n"
19016+ _ASM_EXTABLE(0b, 0b)
19017+#endif
19018+
19019 : "+m" (sem->count)
19020 : "er" (delta));
19021 }
19022@@ -218,7 +274,7 @@ static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
19023 */
19024 static inline long rwsem_atomic_update(long delta, struct rw_semaphore *sem)
19025 {
19026- return delta + xadd(&sem->count, delta);
19027+ return delta + xadd_check_overflow(&sem->count, delta);
19028 }
19029
19030 #endif /* __KERNEL__ */
19031diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
19032index 6f1c3a8..7744f19 100644
19033--- a/arch/x86/include/asm/segment.h
19034+++ b/arch/x86/include/asm/segment.h
19035@@ -64,10 +64,15 @@
19036 * 26 - ESPFIX small SS
19037 * 27 - per-cpu [ offset to per-cpu data area ]
19038 * 28 - stack_canary-20 [ for stack protector ]
19039- * 29 - unused
19040- * 30 - unused
19041+ * 29 - PCI BIOS CS
19042+ * 30 - PCI BIOS DS
19043 * 31 - TSS for double fault handler
19044 */
19045+#define GDT_ENTRY_KERNEXEC_EFI_CS (1)
19046+#define GDT_ENTRY_KERNEXEC_EFI_DS (2)
19047+#define __KERNEXEC_EFI_CS (GDT_ENTRY_KERNEXEC_EFI_CS*8)
19048+#define __KERNEXEC_EFI_DS (GDT_ENTRY_KERNEXEC_EFI_DS*8)
19049+
19050 #define GDT_ENTRY_TLS_MIN 6
19051 #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
19052
19053@@ -79,6 +84,8 @@
19054
19055 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
19056
19057+#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
19058+
19059 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
19060
19061 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
19062@@ -104,6 +111,12 @@
19063 #define __KERNEL_STACK_CANARY 0
19064 #endif
19065
19066+#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
19067+#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
19068+
19069+#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
19070+#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
19071+
19072 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
19073
19074 /*
19075@@ -141,7 +154,7 @@
19076 */
19077
19078 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
19079-#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
19080+#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
19081
19082
19083 #else
19084@@ -165,6 +178,8 @@
19085 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS*8+3)
19086 #define __USER32_DS __USER_DS
19087
19088+#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
19089+
19090 #define GDT_ENTRY_TSS 8 /* needs two entries */
19091 #define GDT_ENTRY_LDT 10 /* needs two entries */
19092 #define GDT_ENTRY_TLS_MIN 12
19093@@ -173,6 +188,8 @@
19094 #define GDT_ENTRY_PER_CPU 15 /* Abused to load per CPU data from limit */
19095 #define __PER_CPU_SEG (GDT_ENTRY_PER_CPU * 8 + 3)
19096
19097+#define GDT_ENTRY_UDEREF_KERNEL_DS 16
19098+
19099 /* TLS indexes for 64bit - hardcoded in arch_prctl */
19100 #define FS_TLS 0
19101 #define GS_TLS 1
19102@@ -180,12 +197,14 @@
19103 #define GS_TLS_SEL ((GDT_ENTRY_TLS_MIN+GS_TLS)*8 + 3)
19104 #define FS_TLS_SEL ((GDT_ENTRY_TLS_MIN+FS_TLS)*8 + 3)
19105
19106-#define GDT_ENTRIES 16
19107+#define GDT_ENTRIES 17
19108
19109 #endif
19110
19111 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
19112+#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
19113 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
19114+#define __UDEREF_KERNEL_DS (GDT_ENTRY_UDEREF_KERNEL_DS*8)
19115 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
19116 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
19117 #ifndef CONFIG_PARAVIRT
19118@@ -268,7 +287,7 @@ static inline unsigned long get_limit(unsigned long segment)
19119 {
19120 unsigned long __limit;
19121 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
19122- return __limit + 1;
19123+ return __limit;
19124 }
19125
19126 #endif /* !__ASSEMBLY__ */
19127diff --git a/arch/x86/include/asm/smap.h b/arch/x86/include/asm/smap.h
19128index 8d3120f..352b440 100644
19129--- a/arch/x86/include/asm/smap.h
19130+++ b/arch/x86/include/asm/smap.h
19131@@ -25,11 +25,40 @@
19132
19133 #include <asm/alternative-asm.h>
19134
19135+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19136+#define ASM_PAX_OPEN_USERLAND \
19137+ 661: jmp 663f; \
19138+ .pushsection .altinstr_replacement, "a" ; \
19139+ 662: pushq %rax; nop; \
19140+ .popsection ; \
19141+ .pushsection .altinstructions, "a" ; \
19142+ altinstruction_entry 661b, 662b, X86_FEATURE_STRONGUDEREF, 2, 2;\
19143+ .popsection ; \
19144+ call __pax_open_userland; \
19145+ popq %rax; \
19146+ 663:
19147+
19148+#define ASM_PAX_CLOSE_USERLAND \
19149+ 661: jmp 663f; \
19150+ .pushsection .altinstr_replacement, "a" ; \
19151+ 662: pushq %rax; nop; \
19152+ .popsection; \
19153+ .pushsection .altinstructions, "a" ; \
19154+ altinstruction_entry 661b, 662b, X86_FEATURE_STRONGUDEREF, 2, 2;\
19155+ .popsection; \
19156+ call __pax_close_userland; \
19157+ popq %rax; \
19158+ 663:
19159+#else
19160+#define ASM_PAX_OPEN_USERLAND
19161+#define ASM_PAX_CLOSE_USERLAND
19162+#endif
19163+
19164 #ifdef CONFIG_X86_SMAP
19165
19166 #define ASM_CLAC \
19167 661: ASM_NOP3 ; \
19168- .pushsection .altinstr_replacement, "ax" ; \
19169+ .pushsection .altinstr_replacement, "a" ; \
19170 662: __ASM_CLAC ; \
19171 .popsection ; \
19172 .pushsection .altinstructions, "a" ; \
19173@@ -38,7 +67,7 @@
19174
19175 #define ASM_STAC \
19176 661: ASM_NOP3 ; \
19177- .pushsection .altinstr_replacement, "ax" ; \
19178+ .pushsection .altinstr_replacement, "a" ; \
19179 662: __ASM_STAC ; \
19180 .popsection ; \
19181 .pushsection .altinstructions, "a" ; \
19182@@ -56,6 +85,37 @@
19183
19184 #include <asm/alternative.h>
19185
19186+#define __HAVE_ARCH_PAX_OPEN_USERLAND
19187+#define __HAVE_ARCH_PAX_CLOSE_USERLAND
19188+
19189+extern void __pax_open_userland(void);
19190+static __always_inline unsigned long pax_open_userland(void)
19191+{
19192+
19193+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19194+ asm volatile(ALTERNATIVE(ASM_NOP5, "call %P[open]", X86_FEATURE_STRONGUDEREF)
19195+ :
19196+ : [open] "i" (__pax_open_userland)
19197+ : "memory", "rax");
19198+#endif
19199+
19200+ return 0;
19201+}
19202+
19203+extern void __pax_close_userland(void);
19204+static __always_inline unsigned long pax_close_userland(void)
19205+{
19206+
19207+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19208+ asm volatile(ALTERNATIVE(ASM_NOP5, "call %P[close]", X86_FEATURE_STRONGUDEREF)
19209+ :
19210+ : [close] "i" (__pax_close_userland)
19211+ : "memory", "rax");
19212+#endif
19213+
19214+ return 0;
19215+}
19216+
19217 #ifdef CONFIG_X86_SMAP
19218
19219 static __always_inline void clac(void)
19220diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
19221index 8cd1cc3..827e09e 100644
19222--- a/arch/x86/include/asm/smp.h
19223+++ b/arch/x86/include/asm/smp.h
19224@@ -35,7 +35,7 @@ DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_core_map);
19225 /* cpus sharing the last level cache: */
19226 DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_llc_shared_map);
19227 DECLARE_PER_CPU_READ_MOSTLY(u16, cpu_llc_id);
19228-DECLARE_PER_CPU_READ_MOSTLY(int, cpu_number);
19229+DECLARE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
19230
19231 static inline struct cpumask *cpu_sibling_mask(int cpu)
19232 {
19233@@ -78,7 +78,7 @@ struct smp_ops {
19234
19235 void (*send_call_func_ipi)(const struct cpumask *mask);
19236 void (*send_call_func_single_ipi)(int cpu);
19237-};
19238+} __no_const;
19239
19240 /* Globals due to paravirt */
19241 extern void set_cpu_sibling_map(int cpu);
19242@@ -191,14 +191,8 @@ extern unsigned disabled_cpus;
19243 extern int safe_smp_processor_id(void);
19244
19245 #elif defined(CONFIG_X86_64_SMP)
19246-#define raw_smp_processor_id() (this_cpu_read(cpu_number))
19247-
19248-#define stack_smp_processor_id() \
19249-({ \
19250- struct thread_info *ti; \
19251- __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
19252- ti->cpu; \
19253-})
19254+#define raw_smp_processor_id() (this_cpu_read(cpu_number))
19255+#define stack_smp_processor_id() raw_smp_processor_id()
19256 #define safe_smp_processor_id() smp_processor_id()
19257
19258 #endif
19259diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
19260index 6a99859..03cb807 100644
19261--- a/arch/x86/include/asm/stackprotector.h
19262+++ b/arch/x86/include/asm/stackprotector.h
19263@@ -47,7 +47,7 @@
19264 * head_32 for boot CPU and setup_per_cpu_areas() for others.
19265 */
19266 #define GDT_STACK_CANARY_INIT \
19267- [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
19268+ [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
19269
19270 /*
19271 * Initialize the stackprotector canary value.
19272@@ -112,7 +112,7 @@ static inline void setup_stack_canary_segment(int cpu)
19273
19274 static inline void load_stack_canary_segment(void)
19275 {
19276-#ifdef CONFIG_X86_32
19277+#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
19278 asm volatile ("mov %0, %%gs" : : "r" (0));
19279 #endif
19280 }
19281diff --git a/arch/x86/include/asm/stacktrace.h b/arch/x86/include/asm/stacktrace.h
19282index 70bbe39..4ae2bd4 100644
19283--- a/arch/x86/include/asm/stacktrace.h
19284+++ b/arch/x86/include/asm/stacktrace.h
19285@@ -11,28 +11,20 @@
19286
19287 extern int kstack_depth_to_print;
19288
19289-struct thread_info;
19290+struct task_struct;
19291 struct stacktrace_ops;
19292
19293-typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
19294- unsigned long *stack,
19295- unsigned long bp,
19296- const struct stacktrace_ops *ops,
19297- void *data,
19298- unsigned long *end,
19299- int *graph);
19300+typedef unsigned long walk_stack_t(struct task_struct *task,
19301+ void *stack_start,
19302+ unsigned long *stack,
19303+ unsigned long bp,
19304+ const struct stacktrace_ops *ops,
19305+ void *data,
19306+ unsigned long *end,
19307+ int *graph);
19308
19309-extern unsigned long
19310-print_context_stack(struct thread_info *tinfo,
19311- unsigned long *stack, unsigned long bp,
19312- const struct stacktrace_ops *ops, void *data,
19313- unsigned long *end, int *graph);
19314-
19315-extern unsigned long
19316-print_context_stack_bp(struct thread_info *tinfo,
19317- unsigned long *stack, unsigned long bp,
19318- const struct stacktrace_ops *ops, void *data,
19319- unsigned long *end, int *graph);
19320+extern walk_stack_t print_context_stack;
19321+extern walk_stack_t print_context_stack_bp;
19322
19323 /* Generic stack tracer with callbacks */
19324
19325@@ -40,7 +32,7 @@ struct stacktrace_ops {
19326 void (*address)(void *data, unsigned long address, int reliable);
19327 /* On negative return stop dumping */
19328 int (*stack)(void *data, char *name);
19329- walk_stack_t walk_stack;
19330+ walk_stack_t *walk_stack;
19331 };
19332
19333 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
19334diff --git a/arch/x86/include/asm/switch_to.h b/arch/x86/include/asm/switch_to.h
19335index d7f3b3b..3cc39f1 100644
19336--- a/arch/x86/include/asm/switch_to.h
19337+++ b/arch/x86/include/asm/switch_to.h
19338@@ -108,7 +108,7 @@ do { \
19339 "call __switch_to\n\t" \
19340 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
19341 __switch_canary \
19342- "movq %P[thread_info](%%rsi),%%r8\n\t" \
19343+ "movq "__percpu_arg([thread_info])",%%r8\n\t" \
19344 "movq %%rax,%%rdi\n\t" \
19345 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
19346 "jnz ret_from_fork\n\t" \
19347@@ -119,7 +119,7 @@ do { \
19348 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
19349 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
19350 [_tif_fork] "i" (_TIF_FORK), \
19351- [thread_info] "i" (offsetof(struct task_struct, stack)), \
19352+ [thread_info] "m" (current_tinfo), \
19353 [current_task] "m" (current_task) \
19354 __switch_canary_iparam \
19355 : "memory", "cc" __EXTRA_CLOBBER)
19356diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
19357index 547e344..6be1175 100644
19358--- a/arch/x86/include/asm/thread_info.h
19359+++ b/arch/x86/include/asm/thread_info.h
19360@@ -24,7 +24,6 @@ struct exec_domain;
19361 #include <linux/atomic.h>
19362
19363 struct thread_info {
19364- struct task_struct *task; /* main task structure */
19365 struct exec_domain *exec_domain; /* execution domain */
19366 __u32 flags; /* low level flags */
19367 __u32 status; /* thread synchronous flags */
19368@@ -33,13 +32,13 @@ struct thread_info {
19369 mm_segment_t addr_limit;
19370 struct restart_block restart_block;
19371 void __user *sysenter_return;
19372+ unsigned long lowest_stack;
19373 unsigned int sig_on_uaccess_error:1;
19374 unsigned int uaccess_err:1; /* uaccess failed */
19375 };
19376
19377-#define INIT_THREAD_INFO(tsk) \
19378+#define INIT_THREAD_INFO \
19379 { \
19380- .task = &tsk, \
19381 .exec_domain = &default_exec_domain, \
19382 .flags = 0, \
19383 .cpu = 0, \
19384@@ -50,7 +49,7 @@ struct thread_info {
19385 }, \
19386 }
19387
19388-#define init_thread_info (init_thread_union.thread_info)
19389+#define init_thread_info (init_thread_union.stack)
19390 #define init_stack (init_thread_union.stack)
19391
19392 #else /* !__ASSEMBLY__ */
19393@@ -91,6 +90,7 @@ struct thread_info {
19394 #define TIF_SYSCALL_TRACEPOINT 28 /* syscall tracepoint instrumentation */
19395 #define TIF_ADDR32 29 /* 32-bit address space on 64 bits */
19396 #define TIF_X32 30 /* 32-bit native x86-64 binary */
19397+#define TIF_GRSEC_SETXID 31 /* update credentials on syscall entry/exit */
19398
19399 #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
19400 #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
19401@@ -115,17 +115,18 @@ struct thread_info {
19402 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
19403 #define _TIF_ADDR32 (1 << TIF_ADDR32)
19404 #define _TIF_X32 (1 << TIF_X32)
19405+#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
19406
19407 /* work to do in syscall_trace_enter() */
19408 #define _TIF_WORK_SYSCALL_ENTRY \
19409 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_EMU | _TIF_SYSCALL_AUDIT | \
19410 _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT | \
19411- _TIF_NOHZ)
19412+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
19413
19414 /* work to do in syscall_trace_leave() */
19415 #define _TIF_WORK_SYSCALL_EXIT \
19416 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SINGLESTEP | \
19417- _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ)
19418+ _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ | _TIF_GRSEC_SETXID)
19419
19420 /* work to do on interrupt/exception return */
19421 #define _TIF_WORK_MASK \
19422@@ -136,7 +137,7 @@ struct thread_info {
19423 /* work to do on any return to user space */
19424 #define _TIF_ALLWORK_MASK \
19425 ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT | \
19426- _TIF_NOHZ)
19427+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
19428
19429 /* Only used for 64 bit */
19430 #define _TIF_DO_NOTIFY_MASK \
19431@@ -151,7 +152,6 @@ struct thread_info {
19432 #define _TIF_WORK_CTXSW_NEXT (_TIF_WORK_CTXSW)
19433
19434 #define STACK_WARN (THREAD_SIZE/8)
19435-#define KERNEL_STACK_OFFSET (5*(BITS_PER_LONG/8))
19436
19437 /*
19438 * macros/functions for gaining access to the thread information structure
19439@@ -162,26 +162,18 @@ struct thread_info {
19440
19441 DECLARE_PER_CPU(unsigned long, kernel_stack);
19442
19443+DECLARE_PER_CPU(struct thread_info *, current_tinfo);
19444+
19445 static inline struct thread_info *current_thread_info(void)
19446 {
19447- struct thread_info *ti;
19448- ti = (void *)(this_cpu_read_stable(kernel_stack) +
19449- KERNEL_STACK_OFFSET - THREAD_SIZE);
19450- return ti;
19451+ return this_cpu_read_stable(current_tinfo);
19452 }
19453
19454 #else /* !__ASSEMBLY__ */
19455
19456 /* how to get the thread information struct from ASM */
19457 #define GET_THREAD_INFO(reg) \
19458- _ASM_MOV PER_CPU_VAR(kernel_stack),reg ; \
19459- _ASM_SUB $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg ;
19460-
19461-/*
19462- * Same if PER_CPU_VAR(kernel_stack) is, perhaps with some offset, already in
19463- * a certain register (to be used in assembler memory operands).
19464- */
19465-#define THREAD_INFO(reg, off) KERNEL_STACK_OFFSET+(off)-THREAD_SIZE(reg)
19466+ _ASM_MOV PER_CPU_VAR(current_tinfo),reg ;
19467
19468 #endif
19469
19470@@ -237,5 +229,12 @@ static inline bool is_ia32_task(void)
19471 extern void arch_task_cache_init(void);
19472 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
19473 extern void arch_release_task_struct(struct task_struct *tsk);
19474+
19475+#define __HAVE_THREAD_FUNCTIONS
19476+#define task_thread_info(task) (&(task)->tinfo)
19477+#define task_stack_page(task) ((task)->stack)
19478+#define setup_thread_stack(p, org) do {} while (0)
19479+#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
19480+
19481 #endif
19482 #endif /* _ASM_X86_THREAD_INFO_H */
19483diff --git a/arch/x86/include/asm/tlbflush.h b/arch/x86/include/asm/tlbflush.h
19484index 04905bf..1178cdf 100644
19485--- a/arch/x86/include/asm/tlbflush.h
19486+++ b/arch/x86/include/asm/tlbflush.h
19487@@ -17,18 +17,44 @@
19488
19489 static inline void __native_flush_tlb(void)
19490 {
19491+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
19492+ u64 descriptor[2];
19493+
19494+ descriptor[0] = PCID_KERNEL;
19495+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_ALL_NONGLOBAL) : "memory");
19496+ return;
19497+ }
19498+
19499+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19500+ if (static_cpu_has(X86_FEATURE_PCID)) {
19501+ unsigned int cpu = raw_get_cpu();
19502+
19503+ native_write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
19504+ native_write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
19505+ raw_put_cpu_no_resched();
19506+ return;
19507+ }
19508+#endif
19509+
19510 native_write_cr3(native_read_cr3());
19511 }
19512
19513 static inline void __native_flush_tlb_global_irq_disabled(void)
19514 {
19515- unsigned long cr4;
19516+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
19517+ u64 descriptor[2];
19518
19519- cr4 = native_read_cr4();
19520- /* clear PGE */
19521- native_write_cr4(cr4 & ~X86_CR4_PGE);
19522- /* write old PGE again and flush TLBs */
19523- native_write_cr4(cr4);
19524+ descriptor[0] = PCID_KERNEL;
19525+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_ALL_GLOBAL) : "memory");
19526+ } else {
19527+ unsigned long cr4;
19528+
19529+ cr4 = native_read_cr4();
19530+ /* clear PGE */
19531+ native_write_cr4(cr4 & ~X86_CR4_PGE);
19532+ /* write old PGE again and flush TLBs */
19533+ native_write_cr4(cr4);
19534+ }
19535 }
19536
19537 static inline void __native_flush_tlb_global(void)
19538@@ -49,6 +75,41 @@ static inline void __native_flush_tlb_global(void)
19539
19540 static inline void __native_flush_tlb_single(unsigned long addr)
19541 {
19542+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
19543+ u64 descriptor[2];
19544+
19545+ descriptor[0] = PCID_KERNEL;
19546+ descriptor[1] = addr;
19547+
19548+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19549+ if (!static_cpu_has(X86_FEATURE_STRONGUDEREF) || addr >= TASK_SIZE_MAX) {
19550+ if (addr < TASK_SIZE_MAX)
19551+ descriptor[1] += pax_user_shadow_base;
19552+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_ADDRESS) : "memory");
19553+ }
19554+
19555+ descriptor[0] = PCID_USER;
19556+ descriptor[1] = addr;
19557+#endif
19558+
19559+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_ADDRESS) : "memory");
19560+ return;
19561+ }
19562+
19563+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19564+ if (static_cpu_has(X86_FEATURE_PCID)) {
19565+ unsigned int cpu = raw_get_cpu();
19566+
19567+ native_write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER | PCID_NOFLUSH);
19568+ asm volatile("invlpg (%0)" ::"r" (addr) : "memory");
19569+ native_write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
19570+ raw_put_cpu_no_resched();
19571+
19572+ if (!static_cpu_has(X86_FEATURE_STRONGUDEREF) && addr < TASK_SIZE_MAX)
19573+ addr += pax_user_shadow_base;
19574+ }
19575+#endif
19576+
19577 asm volatile("invlpg (%0)" ::"r" (addr) : "memory");
19578 }
19579
19580diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
19581index 0d592e0..526f797 100644
19582--- a/arch/x86/include/asm/uaccess.h
19583+++ b/arch/x86/include/asm/uaccess.h
19584@@ -7,6 +7,7 @@
19585 #include <linux/compiler.h>
19586 #include <linux/thread_info.h>
19587 #include <linux/string.h>
19588+#include <linux/spinlock.h>
19589 #include <asm/asm.h>
19590 #include <asm/page.h>
19591 #include <asm/smap.h>
19592@@ -29,7 +30,12 @@
19593
19594 #define get_ds() (KERNEL_DS)
19595 #define get_fs() (current_thread_info()->addr_limit)
19596+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
19597+void __set_fs(mm_segment_t x);
19598+void set_fs(mm_segment_t x);
19599+#else
19600 #define set_fs(x) (current_thread_info()->addr_limit = (x))
19601+#endif
19602
19603 #define segment_eq(a, b) ((a).seg == (b).seg)
19604
19605@@ -85,8 +91,36 @@ static inline bool __chk_range_not_ok(unsigned long addr, unsigned long size, un
19606 * checks that the pointer is in the user space range - after calling
19607 * this function, memory access functions may still return -EFAULT.
19608 */
19609-#define access_ok(type, addr, size) \
19610- likely(!__range_not_ok(addr, size, user_addr_max()))
19611+extern int _cond_resched(void);
19612+#define access_ok_noprefault(type, addr, size) (likely(!__range_not_ok(addr, size, user_addr_max())))
19613+#define access_ok(type, addr, size) \
19614+({ \
19615+ unsigned long __size = size; \
19616+ unsigned long __addr = (unsigned long)addr; \
19617+ bool __ret_ao = __range_not_ok(__addr, __size, user_addr_max()) == 0;\
19618+ if (__ret_ao && __size) { \
19619+ unsigned long __addr_ao = __addr & PAGE_MASK; \
19620+ unsigned long __end_ao = __addr + __size - 1; \
19621+ if (unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
19622+ while (__addr_ao <= __end_ao) { \
19623+ char __c_ao; \
19624+ __addr_ao += PAGE_SIZE; \
19625+ if (__size > PAGE_SIZE) \
19626+ _cond_resched(); \
19627+ if (__get_user(__c_ao, (char __user *)__addr)) \
19628+ break; \
19629+ if (type != VERIFY_WRITE) { \
19630+ __addr = __addr_ao; \
19631+ continue; \
19632+ } \
19633+ if (__put_user(__c_ao, (char __user *)__addr)) \
19634+ break; \
19635+ __addr = __addr_ao; \
19636+ } \
19637+ } \
19638+ } \
19639+ __ret_ao; \
19640+})
19641
19642 /*
19643 * The exception table consists of pairs of addresses relative to the
19644@@ -176,10 +210,12 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
19645 register __inttype(*(ptr)) __val_gu asm("%"_ASM_DX); \
19646 __chk_user_ptr(ptr); \
19647 might_fault(); \
19648+ pax_open_userland(); \
19649 asm volatile("call __get_user_%P3" \
19650 : "=a" (__ret_gu), "=r" (__val_gu) \
19651 : "0" (ptr), "i" (sizeof(*(ptr)))); \
19652 (x) = (__typeof__(*(ptr))) __val_gu; \
19653+ pax_close_userland(); \
19654 __ret_gu; \
19655 })
19656
19657@@ -187,13 +223,21 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
19658 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
19659 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
19660
19661-
19662+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
19663+#define __copyuser_seg "gs;"
19664+#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
19665+#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
19666+#else
19667+#define __copyuser_seg
19668+#define __COPYUSER_SET_ES
19669+#define __COPYUSER_RESTORE_ES
19670+#endif
19671
19672 #ifdef CONFIG_X86_32
19673 #define __put_user_asm_u64(x, addr, err, errret) \
19674 asm volatile(ASM_STAC "\n" \
19675- "1: movl %%eax,0(%2)\n" \
19676- "2: movl %%edx,4(%2)\n" \
19677+ "1: "__copyuser_seg"movl %%eax,0(%2)\n" \
19678+ "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
19679 "3: " ASM_CLAC "\n" \
19680 ".section .fixup,\"ax\"\n" \
19681 "4: movl %3,%0\n" \
19682@@ -206,8 +250,8 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
19683
19684 #define __put_user_asm_ex_u64(x, addr) \
19685 asm volatile(ASM_STAC "\n" \
19686- "1: movl %%eax,0(%1)\n" \
19687- "2: movl %%edx,4(%1)\n" \
19688+ "1: "__copyuser_seg"movl %%eax,0(%1)\n" \
19689+ "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
19690 "3: " ASM_CLAC "\n" \
19691 _ASM_EXTABLE_EX(1b, 2b) \
19692 _ASM_EXTABLE_EX(2b, 3b) \
19693@@ -257,7 +301,8 @@ extern void __put_user_8(void);
19694 __typeof__(*(ptr)) __pu_val; \
19695 __chk_user_ptr(ptr); \
19696 might_fault(); \
19697- __pu_val = x; \
19698+ __pu_val = (x); \
19699+ pax_open_userland(); \
19700 switch (sizeof(*(ptr))) { \
19701 case 1: \
19702 __put_user_x(1, __pu_val, ptr, __ret_pu); \
19703@@ -275,6 +320,7 @@ extern void __put_user_8(void);
19704 __put_user_x(X, __pu_val, ptr, __ret_pu); \
19705 break; \
19706 } \
19707+ pax_close_userland(); \
19708 __ret_pu; \
19709 })
19710
19711@@ -355,8 +401,10 @@ do { \
19712 } while (0)
19713
19714 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
19715+do { \
19716+ pax_open_userland(); \
19717 asm volatile(ASM_STAC "\n" \
19718- "1: mov"itype" %2,%"rtype"1\n" \
19719+ "1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
19720 "2: " ASM_CLAC "\n" \
19721 ".section .fixup,\"ax\"\n" \
19722 "3: mov %3,%0\n" \
19723@@ -364,8 +412,10 @@ do { \
19724 " jmp 2b\n" \
19725 ".previous\n" \
19726 _ASM_EXTABLE(1b, 3b) \
19727- : "=r" (err), ltype(x) \
19728- : "m" (__m(addr)), "i" (errret), "0" (err))
19729+ : "=r" (err), ltype (x) \
19730+ : "m" (__m(addr)), "i" (errret), "0" (err)); \
19731+ pax_close_userland(); \
19732+} while (0)
19733
19734 #define __get_user_size_ex(x, ptr, size) \
19735 do { \
19736@@ -389,7 +439,7 @@ do { \
19737 } while (0)
19738
19739 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
19740- asm volatile("1: mov"itype" %1,%"rtype"0\n" \
19741+ asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
19742 "2:\n" \
19743 _ASM_EXTABLE_EX(1b, 2b) \
19744 : ltype(x) : "m" (__m(addr)))
19745@@ -406,13 +456,24 @@ do { \
19746 int __gu_err; \
19747 unsigned long __gu_val; \
19748 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
19749- (x) = (__force __typeof__(*(ptr)))__gu_val; \
19750+ (x) = (__typeof__(*(ptr)))__gu_val; \
19751 __gu_err; \
19752 })
19753
19754 /* FIXME: this hack is definitely wrong -AK */
19755 struct __large_struct { unsigned long buf[100]; };
19756-#define __m(x) (*(struct __large_struct __user *)(x))
19757+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19758+#define ____m(x) \
19759+({ \
19760+ unsigned long ____x = (unsigned long)(x); \
19761+ if (____x < pax_user_shadow_base) \
19762+ ____x += pax_user_shadow_base; \
19763+ (typeof(x))____x; \
19764+})
19765+#else
19766+#define ____m(x) (x)
19767+#endif
19768+#define __m(x) (*(struct __large_struct __user *)____m(x))
19769
19770 /*
19771 * Tell gcc we read from memory instead of writing: this is because
19772@@ -420,8 +481,10 @@ struct __large_struct { unsigned long buf[100]; };
19773 * aliasing issues.
19774 */
19775 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
19776+do { \
19777+ pax_open_userland(); \
19778 asm volatile(ASM_STAC "\n" \
19779- "1: mov"itype" %"rtype"1,%2\n" \
19780+ "1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
19781 "2: " ASM_CLAC "\n" \
19782 ".section .fixup,\"ax\"\n" \
19783 "3: mov %3,%0\n" \
19784@@ -429,10 +492,12 @@ struct __large_struct { unsigned long buf[100]; };
19785 ".previous\n" \
19786 _ASM_EXTABLE(1b, 3b) \
19787 : "=r"(err) \
19788- : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
19789+ : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err));\
19790+ pax_close_userland(); \
19791+} while (0)
19792
19793 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
19794- asm volatile("1: mov"itype" %"rtype"0,%1\n" \
19795+ asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
19796 "2:\n" \
19797 _ASM_EXTABLE_EX(1b, 2b) \
19798 : : ltype(x), "m" (__m(addr)))
19799@@ -442,11 +507,13 @@ struct __large_struct { unsigned long buf[100]; };
19800 */
19801 #define uaccess_try do { \
19802 current_thread_info()->uaccess_err = 0; \
19803+ pax_open_userland(); \
19804 stac(); \
19805 barrier();
19806
19807 #define uaccess_catch(err) \
19808 clac(); \
19809+ pax_close_userland(); \
19810 (err) |= (current_thread_info()->uaccess_err ? -EFAULT : 0); \
19811 } while (0)
19812
19813@@ -471,8 +538,12 @@ struct __large_struct { unsigned long buf[100]; };
19814 * On error, the variable @x is set to zero.
19815 */
19816
19817+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19818+#define __get_user(x, ptr) get_user((x), (ptr))
19819+#else
19820 #define __get_user(x, ptr) \
19821 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
19822+#endif
19823
19824 /**
19825 * __put_user: - Write a simple value into user space, with less checking.
19826@@ -494,8 +565,12 @@ struct __large_struct { unsigned long buf[100]; };
19827 * Returns zero on success, or -EFAULT on error.
19828 */
19829
19830+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19831+#define __put_user(x, ptr) put_user((x), (ptr))
19832+#else
19833 #define __put_user(x, ptr) \
19834 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
19835+#endif
19836
19837 #define __get_user_unaligned __get_user
19838 #define __put_user_unaligned __put_user
19839@@ -513,7 +588,7 @@ struct __large_struct { unsigned long buf[100]; };
19840 #define get_user_ex(x, ptr) do { \
19841 unsigned long __gue_val; \
19842 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
19843- (x) = (__force __typeof__(*(ptr)))__gue_val; \
19844+ (x) = (__typeof__(*(ptr)))__gue_val; \
19845 } while (0)
19846
19847 #define put_user_try uaccess_try
19848@@ -542,18 +617,19 @@ extern void __cmpxchg_wrong_size(void)
19849 __typeof__(ptr) __uval = (uval); \
19850 __typeof__(*(ptr)) __old = (old); \
19851 __typeof__(*(ptr)) __new = (new); \
19852+ pax_open_userland(); \
19853 switch (size) { \
19854 case 1: \
19855 { \
19856 asm volatile("\t" ASM_STAC "\n" \
19857- "1:\t" LOCK_PREFIX "cmpxchgb %4, %2\n" \
19858+ "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgb %4, %2\n"\
19859 "2:\t" ASM_CLAC "\n" \
19860 "\t.section .fixup, \"ax\"\n" \
19861 "3:\tmov %3, %0\n" \
19862 "\tjmp 2b\n" \
19863 "\t.previous\n" \
19864 _ASM_EXTABLE(1b, 3b) \
19865- : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
19866+ : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
19867 : "i" (-EFAULT), "q" (__new), "1" (__old) \
19868 : "memory" \
19869 ); \
19870@@ -562,14 +638,14 @@ extern void __cmpxchg_wrong_size(void)
19871 case 2: \
19872 { \
19873 asm volatile("\t" ASM_STAC "\n" \
19874- "1:\t" LOCK_PREFIX "cmpxchgw %4, %2\n" \
19875+ "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgw %4, %2\n"\
19876 "2:\t" ASM_CLAC "\n" \
19877 "\t.section .fixup, \"ax\"\n" \
19878 "3:\tmov %3, %0\n" \
19879 "\tjmp 2b\n" \
19880 "\t.previous\n" \
19881 _ASM_EXTABLE(1b, 3b) \
19882- : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
19883+ : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
19884 : "i" (-EFAULT), "r" (__new), "1" (__old) \
19885 : "memory" \
19886 ); \
19887@@ -578,14 +654,14 @@ extern void __cmpxchg_wrong_size(void)
19888 case 4: \
19889 { \
19890 asm volatile("\t" ASM_STAC "\n" \
19891- "1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n" \
19892+ "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %4, %2\n"\
19893 "2:\t" ASM_CLAC "\n" \
19894 "\t.section .fixup, \"ax\"\n" \
19895 "3:\tmov %3, %0\n" \
19896 "\tjmp 2b\n" \
19897 "\t.previous\n" \
19898 _ASM_EXTABLE(1b, 3b) \
19899- : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
19900+ : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
19901 : "i" (-EFAULT), "r" (__new), "1" (__old) \
19902 : "memory" \
19903 ); \
19904@@ -597,14 +673,14 @@ extern void __cmpxchg_wrong_size(void)
19905 __cmpxchg_wrong_size(); \
19906 \
19907 asm volatile("\t" ASM_STAC "\n" \
19908- "1:\t" LOCK_PREFIX "cmpxchgq %4, %2\n" \
19909+ "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgq %4, %2\n"\
19910 "2:\t" ASM_CLAC "\n" \
19911 "\t.section .fixup, \"ax\"\n" \
19912 "3:\tmov %3, %0\n" \
19913 "\tjmp 2b\n" \
19914 "\t.previous\n" \
19915 _ASM_EXTABLE(1b, 3b) \
19916- : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
19917+ : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
19918 : "i" (-EFAULT), "r" (__new), "1" (__old) \
19919 : "memory" \
19920 ); \
19921@@ -613,6 +689,7 @@ extern void __cmpxchg_wrong_size(void)
19922 default: \
19923 __cmpxchg_wrong_size(); \
19924 } \
19925+ pax_close_userland(); \
19926 *__uval = __old; \
19927 __ret; \
19928 })
19929@@ -636,17 +713,6 @@ extern struct movsl_mask {
19930
19931 #define ARCH_HAS_NOCACHE_UACCESS 1
19932
19933-#ifdef CONFIG_X86_32
19934-# include <asm/uaccess_32.h>
19935-#else
19936-# include <asm/uaccess_64.h>
19937-#endif
19938-
19939-unsigned long __must_check _copy_from_user(void *to, const void __user *from,
19940- unsigned n);
19941-unsigned long __must_check _copy_to_user(void __user *to, const void *from,
19942- unsigned n);
19943-
19944 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
19945 # define copy_user_diag __compiletime_error
19946 #else
19947@@ -656,7 +722,7 @@ unsigned long __must_check _copy_to_user(void __user *to, const void *from,
19948 extern void copy_user_diag("copy_from_user() buffer size is too small")
19949 copy_from_user_overflow(void);
19950 extern void copy_user_diag("copy_to_user() buffer size is too small")
19951-copy_to_user_overflow(void) __asm__("copy_from_user_overflow");
19952+copy_to_user_overflow(void);
19953
19954 #undef copy_user_diag
19955
19956@@ -669,7 +735,7 @@ __copy_from_user_overflow(void) __asm__("copy_from_user_overflow");
19957
19958 extern void
19959 __compiletime_warning("copy_to_user() buffer size is not provably correct")
19960-__copy_to_user_overflow(void) __asm__("copy_from_user_overflow");
19961+__copy_to_user_overflow(void) __asm__("copy_to_user_overflow");
19962 #define __copy_to_user_overflow(size, count) __copy_to_user_overflow()
19963
19964 #else
19965@@ -684,10 +750,16 @@ __copy_from_user_overflow(int size, unsigned long count)
19966
19967 #endif
19968
19969+#ifdef CONFIG_X86_32
19970+# include <asm/uaccess_32.h>
19971+#else
19972+# include <asm/uaccess_64.h>
19973+#endif
19974+
19975 static inline unsigned long __must_check
19976 copy_from_user(void *to, const void __user *from, unsigned long n)
19977 {
19978- int sz = __compiletime_object_size(to);
19979+ size_t sz = __compiletime_object_size(to);
19980
19981 might_fault();
19982
19983@@ -709,12 +781,15 @@ copy_from_user(void *to, const void __user *from, unsigned long n)
19984 * case, and do only runtime checking for non-constant sizes.
19985 */
19986
19987- if (likely(sz < 0 || sz >= n))
19988- n = _copy_from_user(to, from, n);
19989- else if(__builtin_constant_p(n))
19990- copy_from_user_overflow();
19991- else
19992- __copy_from_user_overflow(sz, n);
19993+ if (likely(sz != (size_t)-1 && sz < n)) {
19994+ if(__builtin_constant_p(n))
19995+ copy_from_user_overflow();
19996+ else
19997+ __copy_from_user_overflow(sz, n);
19998+ } else if (access_ok(VERIFY_READ, from, n))
19999+ n = __copy_from_user(to, from, n);
20000+ else if ((long)n > 0)
20001+ memset(to, 0, n);
20002
20003 return n;
20004 }
20005@@ -722,17 +797,18 @@ copy_from_user(void *to, const void __user *from, unsigned long n)
20006 static inline unsigned long __must_check
20007 copy_to_user(void __user *to, const void *from, unsigned long n)
20008 {
20009- int sz = __compiletime_object_size(from);
20010+ size_t sz = __compiletime_object_size(from);
20011
20012 might_fault();
20013
20014 /* See the comment in copy_from_user() above. */
20015- if (likely(sz < 0 || sz >= n))
20016- n = _copy_to_user(to, from, n);
20017- else if(__builtin_constant_p(n))
20018- copy_to_user_overflow();
20019- else
20020- __copy_to_user_overflow(sz, n);
20021+ if (likely(sz != (size_t)-1 && sz < n)) {
20022+ if(__builtin_constant_p(n))
20023+ copy_to_user_overflow();
20024+ else
20025+ __copy_to_user_overflow(sz, n);
20026+ } else if (access_ok(VERIFY_WRITE, to, n))
20027+ n = __copy_to_user(to, from, n);
20028
20029 return n;
20030 }
20031diff --git a/arch/x86/include/asm/uaccess_32.h b/arch/x86/include/asm/uaccess_32.h
20032index 3c03a5d..1071638 100644
20033--- a/arch/x86/include/asm/uaccess_32.h
20034+++ b/arch/x86/include/asm/uaccess_32.h
20035@@ -43,6 +43,11 @@ unsigned long __must_check __copy_from_user_ll_nocache_nozero
20036 static __always_inline unsigned long __must_check
20037 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
20038 {
20039+ if ((long)n < 0)
20040+ return n;
20041+
20042+ check_object_size(from, n, true);
20043+
20044 if (__builtin_constant_p(n)) {
20045 unsigned long ret;
20046
20047@@ -82,12 +87,16 @@ static __always_inline unsigned long __must_check
20048 __copy_to_user(void __user *to, const void *from, unsigned long n)
20049 {
20050 might_fault();
20051+
20052 return __copy_to_user_inatomic(to, from, n);
20053 }
20054
20055 static __always_inline unsigned long
20056 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
20057 {
20058+ if ((long)n < 0)
20059+ return n;
20060+
20061 /* Avoid zeroing the tail if the copy fails..
20062 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
20063 * but as the zeroing behaviour is only significant when n is not
20064@@ -137,6 +146,12 @@ static __always_inline unsigned long
20065 __copy_from_user(void *to, const void __user *from, unsigned long n)
20066 {
20067 might_fault();
20068+
20069+ if ((long)n < 0)
20070+ return n;
20071+
20072+ check_object_size(to, n, false);
20073+
20074 if (__builtin_constant_p(n)) {
20075 unsigned long ret;
20076
20077@@ -159,6 +174,10 @@ static __always_inline unsigned long __copy_from_user_nocache(void *to,
20078 const void __user *from, unsigned long n)
20079 {
20080 might_fault();
20081+
20082+ if ((long)n < 0)
20083+ return n;
20084+
20085 if (__builtin_constant_p(n)) {
20086 unsigned long ret;
20087
20088@@ -181,7 +200,10 @@ static __always_inline unsigned long
20089 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
20090 unsigned long n)
20091 {
20092- return __copy_from_user_ll_nocache_nozero(to, from, n);
20093+ if ((long)n < 0)
20094+ return n;
20095+
20096+ return __copy_from_user_ll_nocache_nozero(to, from, n);
20097 }
20098
20099 #endif /* _ASM_X86_UACCESS_32_H */
20100diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
20101index 12a26b9..206c200 100644
20102--- a/arch/x86/include/asm/uaccess_64.h
20103+++ b/arch/x86/include/asm/uaccess_64.h
20104@@ -10,6 +10,9 @@
20105 #include <asm/alternative.h>
20106 #include <asm/cpufeature.h>
20107 #include <asm/page.h>
20108+#include <asm/pgtable.h>
20109+
20110+#define set_fs(x) (current_thread_info()->addr_limit = (x))
20111
20112 /*
20113 * Copy To/From Userspace
20114@@ -17,14 +20,14 @@
20115
20116 /* Handles exceptions in both to and from, but doesn't do access_ok */
20117 __must_check unsigned long
20118-copy_user_enhanced_fast_string(void *to, const void *from, unsigned len);
20119+copy_user_enhanced_fast_string(void *to, const void *from, unsigned len) __size_overflow(3);
20120 __must_check unsigned long
20121-copy_user_generic_string(void *to, const void *from, unsigned len);
20122+copy_user_generic_string(void *to, const void *from, unsigned len) __size_overflow(3);
20123 __must_check unsigned long
20124-copy_user_generic_unrolled(void *to, const void *from, unsigned len);
20125+copy_user_generic_unrolled(void *to, const void *from, unsigned len) __size_overflow(3);
20126
20127 static __always_inline __must_check unsigned long
20128-copy_user_generic(void *to, const void *from, unsigned len)
20129+copy_user_generic(void *to, const void *from, unsigned long len)
20130 {
20131 unsigned ret;
20132
20133@@ -46,121 +49,170 @@ copy_user_generic(void *to, const void *from, unsigned len)
20134 }
20135
20136 __must_check unsigned long
20137-copy_in_user(void __user *to, const void __user *from, unsigned len);
20138+copy_in_user(void __user *to, const void __user *from, unsigned long len);
20139
20140 static __always_inline __must_check
20141-int __copy_from_user_nocheck(void *dst, const void __user *src, unsigned size)
20142+unsigned long __copy_from_user_nocheck(void *dst, const void __user *src, unsigned long size)
20143 {
20144- int ret = 0;
20145+ size_t sz = __compiletime_object_size(dst);
20146+ unsigned ret = 0;
20147+
20148+ if (size > INT_MAX)
20149+ return size;
20150+
20151+ check_object_size(dst, size, false);
20152+
20153+#ifdef CONFIG_PAX_MEMORY_UDEREF
20154+ if (!access_ok_noprefault(VERIFY_READ, src, size))
20155+ return size;
20156+#endif
20157+
20158+ if (unlikely(sz != (size_t)-1 && sz < size)) {
20159+ if(__builtin_constant_p(size))
20160+ copy_from_user_overflow();
20161+ else
20162+ __copy_from_user_overflow(sz, size);
20163+ return size;
20164+ }
20165
20166 if (!__builtin_constant_p(size))
20167- return copy_user_generic(dst, (__force void *)src, size);
20168+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
20169 switch (size) {
20170- case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
20171+ case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
20172 ret, "b", "b", "=q", 1);
20173 return ret;
20174- case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
20175+ case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
20176 ret, "w", "w", "=r", 2);
20177 return ret;
20178- case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
20179+ case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
20180 ret, "l", "k", "=r", 4);
20181 return ret;
20182- case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
20183+ case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
20184 ret, "q", "", "=r", 8);
20185 return ret;
20186 case 10:
20187- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
20188+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
20189 ret, "q", "", "=r", 10);
20190 if (unlikely(ret))
20191 return ret;
20192 __get_user_asm(*(u16 *)(8 + (char *)dst),
20193- (u16 __user *)(8 + (char __user *)src),
20194+ (const u16 __user *)(8 + (const char __user *)src),
20195 ret, "w", "w", "=r", 2);
20196 return ret;
20197 case 16:
20198- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
20199+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
20200 ret, "q", "", "=r", 16);
20201 if (unlikely(ret))
20202 return ret;
20203 __get_user_asm(*(u64 *)(8 + (char *)dst),
20204- (u64 __user *)(8 + (char __user *)src),
20205+ (const u64 __user *)(8 + (const char __user *)src),
20206 ret, "q", "", "=r", 8);
20207 return ret;
20208 default:
20209- return copy_user_generic(dst, (__force void *)src, size);
20210+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
20211 }
20212 }
20213
20214 static __always_inline __must_check
20215-int __copy_from_user(void *dst, const void __user *src, unsigned size)
20216+unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size)
20217 {
20218 might_fault();
20219 return __copy_from_user_nocheck(dst, src, size);
20220 }
20221
20222 static __always_inline __must_check
20223-int __copy_to_user_nocheck(void __user *dst, const void *src, unsigned size)
20224+unsigned long __copy_to_user_nocheck(void __user *dst, const void *src, unsigned long size)
20225 {
20226- int ret = 0;
20227+ size_t sz = __compiletime_object_size(src);
20228+ unsigned ret = 0;
20229+
20230+ if (size > INT_MAX)
20231+ return size;
20232+
20233+ check_object_size(src, size, true);
20234+
20235+#ifdef CONFIG_PAX_MEMORY_UDEREF
20236+ if (!access_ok_noprefault(VERIFY_WRITE, dst, size))
20237+ return size;
20238+#endif
20239+
20240+ if (unlikely(sz != (size_t)-1 && sz < size)) {
20241+ if(__builtin_constant_p(size))
20242+ copy_to_user_overflow();
20243+ else
20244+ __copy_to_user_overflow(sz, size);
20245+ return size;
20246+ }
20247
20248 if (!__builtin_constant_p(size))
20249- return copy_user_generic((__force void *)dst, src, size);
20250+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
20251 switch (size) {
20252- case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
20253+ case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
20254 ret, "b", "b", "iq", 1);
20255 return ret;
20256- case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
20257+ case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
20258 ret, "w", "w", "ir", 2);
20259 return ret;
20260- case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
20261+ case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
20262 ret, "l", "k", "ir", 4);
20263 return ret;
20264- case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
20265+ case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
20266 ret, "q", "", "er", 8);
20267 return ret;
20268 case 10:
20269- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
20270+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
20271 ret, "q", "", "er", 10);
20272 if (unlikely(ret))
20273 return ret;
20274 asm("":::"memory");
20275- __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
20276+ __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
20277 ret, "w", "w", "ir", 2);
20278 return ret;
20279 case 16:
20280- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
20281+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
20282 ret, "q", "", "er", 16);
20283 if (unlikely(ret))
20284 return ret;
20285 asm("":::"memory");
20286- __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
20287+ __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
20288 ret, "q", "", "er", 8);
20289 return ret;
20290 default:
20291- return copy_user_generic((__force void *)dst, src, size);
20292+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
20293 }
20294 }
20295
20296 static __always_inline __must_check
20297-int __copy_to_user(void __user *dst, const void *src, unsigned size)
20298+unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size)
20299 {
20300 might_fault();
20301 return __copy_to_user_nocheck(dst, src, size);
20302 }
20303
20304 static __always_inline __must_check
20305-int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20306+unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20307 {
20308- int ret = 0;
20309+ unsigned ret = 0;
20310
20311 might_fault();
20312+
20313+ if (size > INT_MAX)
20314+ return size;
20315+
20316+#ifdef CONFIG_PAX_MEMORY_UDEREF
20317+ if (!access_ok_noprefault(VERIFY_READ, src, size))
20318+ return size;
20319+ if (!access_ok_noprefault(VERIFY_WRITE, dst, size))
20320+ return size;
20321+#endif
20322+
20323 if (!__builtin_constant_p(size))
20324- return copy_user_generic((__force void *)dst,
20325- (__force void *)src, size);
20326+ return copy_user_generic((__force_kernel void *)____m(dst),
20327+ (__force_kernel const void *)____m(src), size);
20328 switch (size) {
20329 case 1: {
20330 u8 tmp;
20331- __get_user_asm(tmp, (u8 __user *)src,
20332+ __get_user_asm(tmp, (const u8 __user *)src,
20333 ret, "b", "b", "=q", 1);
20334 if (likely(!ret))
20335 __put_user_asm(tmp, (u8 __user *)dst,
20336@@ -169,7 +221,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20337 }
20338 case 2: {
20339 u16 tmp;
20340- __get_user_asm(tmp, (u16 __user *)src,
20341+ __get_user_asm(tmp, (const u16 __user *)src,
20342 ret, "w", "w", "=r", 2);
20343 if (likely(!ret))
20344 __put_user_asm(tmp, (u16 __user *)dst,
20345@@ -179,7 +231,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20346
20347 case 4: {
20348 u32 tmp;
20349- __get_user_asm(tmp, (u32 __user *)src,
20350+ __get_user_asm(tmp, (const u32 __user *)src,
20351 ret, "l", "k", "=r", 4);
20352 if (likely(!ret))
20353 __put_user_asm(tmp, (u32 __user *)dst,
20354@@ -188,7 +240,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20355 }
20356 case 8: {
20357 u64 tmp;
20358- __get_user_asm(tmp, (u64 __user *)src,
20359+ __get_user_asm(tmp, (const u64 __user *)src,
20360 ret, "q", "", "=r", 8);
20361 if (likely(!ret))
20362 __put_user_asm(tmp, (u64 __user *)dst,
20363@@ -196,41 +248,58 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20364 return ret;
20365 }
20366 default:
20367- return copy_user_generic((__force void *)dst,
20368- (__force void *)src, size);
20369+ return copy_user_generic((__force_kernel void *)____m(dst),
20370+ (__force_kernel const void *)____m(src), size);
20371 }
20372 }
20373
20374-static __must_check __always_inline int
20375-__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
20376+static __must_check __always_inline unsigned long
20377+__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size)
20378 {
20379 return __copy_from_user_nocheck(dst, src, size);
20380 }
20381
20382-static __must_check __always_inline int
20383-__copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
20384+static __must_check __always_inline unsigned long
20385+__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size)
20386 {
20387 return __copy_to_user_nocheck(dst, src, size);
20388 }
20389
20390-extern long __copy_user_nocache(void *dst, const void __user *src,
20391- unsigned size, int zerorest);
20392+extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
20393+ unsigned long size, int zerorest);
20394
20395-static inline int
20396-__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
20397+static inline unsigned long
20398+__copy_from_user_nocache(void *dst, const void __user *src, unsigned long size)
20399 {
20400 might_fault();
20401+
20402+ if (size > INT_MAX)
20403+ return size;
20404+
20405+#ifdef CONFIG_PAX_MEMORY_UDEREF
20406+ if (!access_ok_noprefault(VERIFY_READ, src, size))
20407+ return size;
20408+#endif
20409+
20410 return __copy_user_nocache(dst, src, size, 1);
20411 }
20412
20413-static inline int
20414+static inline unsigned long
20415 __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
20416- unsigned size)
20417+ unsigned long size)
20418 {
20419+ if (size > INT_MAX)
20420+ return size;
20421+
20422+#ifdef CONFIG_PAX_MEMORY_UDEREF
20423+ if (!access_ok_noprefault(VERIFY_READ, src, size))
20424+ return size;
20425+#endif
20426+
20427 return __copy_user_nocache(dst, src, size, 0);
20428 }
20429
20430 unsigned long
20431-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
20432+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest) __size_overflow(3);
20433
20434 #endif /* _ASM_X86_UACCESS_64_H */
20435diff --git a/arch/x86/include/asm/word-at-a-time.h b/arch/x86/include/asm/word-at-a-time.h
20436index 5b238981..77fdd78 100644
20437--- a/arch/x86/include/asm/word-at-a-time.h
20438+++ b/arch/x86/include/asm/word-at-a-time.h
20439@@ -11,7 +11,7 @@
20440 * and shift, for example.
20441 */
20442 struct word_at_a_time {
20443- const unsigned long one_bits, high_bits;
20444+ unsigned long one_bits, high_bits;
20445 };
20446
20447 #define WORD_AT_A_TIME_CONSTANTS { REPEAT_BYTE(0x01), REPEAT_BYTE(0x80) }
20448diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h
20449index e45e4da..44e8572 100644
20450--- a/arch/x86/include/asm/x86_init.h
20451+++ b/arch/x86/include/asm/x86_init.h
20452@@ -129,7 +129,7 @@ struct x86_init_ops {
20453 struct x86_init_timers timers;
20454 struct x86_init_iommu iommu;
20455 struct x86_init_pci pci;
20456-};
20457+} __no_const;
20458
20459 /**
20460 * struct x86_cpuinit_ops - platform specific cpu hotplug setups
20461@@ -140,7 +140,7 @@ struct x86_cpuinit_ops {
20462 void (*setup_percpu_clockev)(void);
20463 void (*early_percpu_clock_init)(void);
20464 void (*fixup_cpu_id)(struct cpuinfo_x86 *c, int node);
20465-};
20466+} __no_const;
20467
20468 struct timespec;
20469
20470@@ -168,7 +168,7 @@ struct x86_platform_ops {
20471 void (*save_sched_clock_state)(void);
20472 void (*restore_sched_clock_state)(void);
20473 void (*apic_post_init)(void);
20474-};
20475+} __no_const;
20476
20477 struct pci_dev;
20478 struct msi_msg;
20479@@ -185,7 +185,7 @@ struct x86_msi_ops {
20480 int (*setup_hpet_msi)(unsigned int irq, unsigned int id);
20481 u32 (*msi_mask_irq)(struct msi_desc *desc, u32 mask, u32 flag);
20482 u32 (*msix_mask_irq)(struct msi_desc *desc, u32 flag);
20483-};
20484+} __no_const;
20485
20486 struct IO_APIC_route_entry;
20487 struct io_apic_irq_attr;
20488@@ -206,7 +206,7 @@ struct x86_io_apic_ops {
20489 unsigned int destination, int vector,
20490 struct io_apic_irq_attr *attr);
20491 void (*eoi_ioapic_pin)(int apic, int pin, int vector);
20492-};
20493+} __no_const;
20494
20495 extern struct x86_init_ops x86_init;
20496 extern struct x86_cpuinit_ops x86_cpuinit;
20497diff --git a/arch/x86/include/asm/xen/page.h b/arch/x86/include/asm/xen/page.h
20498index c949923..c22bfa4 100644
20499--- a/arch/x86/include/asm/xen/page.h
20500+++ b/arch/x86/include/asm/xen/page.h
20501@@ -63,7 +63,7 @@ extern int m2p_remove_override(struct page *page,
20502 extern struct page *m2p_find_override(unsigned long mfn);
20503 extern unsigned long m2p_find_override_pfn(unsigned long mfn, unsigned long pfn);
20504
20505-static inline unsigned long pfn_to_mfn(unsigned long pfn)
20506+static inline unsigned long __intentional_overflow(-1) pfn_to_mfn(unsigned long pfn)
20507 {
20508 unsigned long mfn;
20509
20510diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
20511index 7e7a79a..0824666 100644
20512--- a/arch/x86/include/asm/xsave.h
20513+++ b/arch/x86/include/asm/xsave.h
20514@@ -228,12 +228,16 @@ static inline int xsave_user(struct xsave_struct __user *buf)
20515 if (unlikely(err))
20516 return -EFAULT;
20517
20518+ pax_open_userland();
20519 __asm__ __volatile__(ASM_STAC "\n"
20520- "1:"XSAVE"\n"
20521+ "1:"
20522+ __copyuser_seg
20523+ XSAVE"\n"
20524 "2: " ASM_CLAC "\n"
20525 xstate_fault
20526 : "D" (buf), "a" (-1), "d" (-1), "0" (0)
20527 : "memory");
20528+ pax_close_userland();
20529 return err;
20530 }
20531
20532@@ -243,16 +247,20 @@ static inline int xsave_user(struct xsave_struct __user *buf)
20533 static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
20534 {
20535 int err = 0;
20536- struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
20537+ struct xsave_struct *xstate = ((__force_kernel struct xsave_struct *)buf);
20538 u32 lmask = mask;
20539 u32 hmask = mask >> 32;
20540
20541+ pax_open_userland();
20542 __asm__ __volatile__(ASM_STAC "\n"
20543- "1:"XRSTOR"\n"
20544+ "1:"
20545+ __copyuser_seg
20546+ XRSTOR"\n"
20547 "2: " ASM_CLAC "\n"
20548 xstate_fault
20549 : "D" (xstate), "a" (lmask), "d" (hmask), "0" (0)
20550 : "memory"); /* memory required? */
20551+ pax_close_userland();
20552 return err;
20553 }
20554
20555diff --git a/arch/x86/include/uapi/asm/e820.h b/arch/x86/include/uapi/asm/e820.h
20556index d993e33..8db1b18 100644
20557--- a/arch/x86/include/uapi/asm/e820.h
20558+++ b/arch/x86/include/uapi/asm/e820.h
20559@@ -58,7 +58,7 @@ struct e820map {
20560 #define ISA_START_ADDRESS 0xa0000
20561 #define ISA_END_ADDRESS 0x100000
20562
20563-#define BIOS_BEGIN 0x000a0000
20564+#define BIOS_BEGIN 0x000c0000
20565 #define BIOS_END 0x00100000
20566
20567 #define BIOS_ROM_BASE 0xffe00000
20568diff --git a/arch/x86/include/uapi/asm/ptrace-abi.h b/arch/x86/include/uapi/asm/ptrace-abi.h
20569index 7b0a55a..ad115bf 100644
20570--- a/arch/x86/include/uapi/asm/ptrace-abi.h
20571+++ b/arch/x86/include/uapi/asm/ptrace-abi.h
20572@@ -49,7 +49,6 @@
20573 #define EFLAGS 144
20574 #define RSP 152
20575 #define SS 160
20576-#define ARGOFFSET R11
20577 #endif /* __ASSEMBLY__ */
20578
20579 /* top of stack page */
20580diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile
20581index 8f1e774..9b4c381 100644
20582--- a/arch/x86/kernel/Makefile
20583+++ b/arch/x86/kernel/Makefile
20584@@ -24,7 +24,7 @@ obj-y += time.o ioport.o ldt.o dumpstack.o nmi.o
20585 obj-y += setup.o x86_init.o i8259.o irqinit.o jump_label.o
20586 obj-$(CONFIG_IRQ_WORK) += irq_work.o
20587 obj-y += probe_roms.o
20588-obj-$(CONFIG_X86_32) += i386_ksyms_32.o
20589+obj-$(CONFIG_X86_32) += sys_i386_32.o i386_ksyms_32.o
20590 obj-$(CONFIG_X86_64) += sys_x86_64.o x8664_ksyms_64.o
20591 obj-$(CONFIG_X86_64) += mcount_64.o
20592 obj-y += syscall_$(BITS).o vsyscall_gtod.o
20593diff --git a/arch/x86/kernel/acpi/boot.c b/arch/x86/kernel/acpi/boot.c
20594index a142e77..6222cdd 100644
20595--- a/arch/x86/kernel/acpi/boot.c
20596+++ b/arch/x86/kernel/acpi/boot.c
20597@@ -1276,7 +1276,7 @@ static int __init dmi_ignore_irq0_timer_override(const struct dmi_system_id *d)
20598 * If your system is blacklisted here, but you find that acpi=force
20599 * works for you, please contact linux-acpi@vger.kernel.org
20600 */
20601-static struct dmi_system_id __initdata acpi_dmi_table[] = {
20602+static const struct dmi_system_id __initconst acpi_dmi_table[] = {
20603 /*
20604 * Boxes that need ACPI disabled
20605 */
20606@@ -1351,7 +1351,7 @@ static struct dmi_system_id __initdata acpi_dmi_table[] = {
20607 };
20608
20609 /* second table for DMI checks that should run after early-quirks */
20610-static struct dmi_system_id __initdata acpi_dmi_table_late[] = {
20611+static const struct dmi_system_id __initconst acpi_dmi_table_late[] = {
20612 /*
20613 * HP laptops which use a DSDT reporting as HP/SB400/10000,
20614 * which includes some code which overrides all temperature
20615diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
20616index 3136820..e2c6577 100644
20617--- a/arch/x86/kernel/acpi/sleep.c
20618+++ b/arch/x86/kernel/acpi/sleep.c
20619@@ -99,8 +99,12 @@ int x86_acpi_suspend_lowlevel(void)
20620 #else /* CONFIG_64BIT */
20621 #ifdef CONFIG_SMP
20622 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
20623+
20624+ pax_open_kernel();
20625 early_gdt_descr.address =
20626 (unsigned long)get_cpu_gdt_table(smp_processor_id());
20627+ pax_close_kernel();
20628+
20629 initial_gs = per_cpu_offset(smp_processor_id());
20630 #endif
20631 initial_code = (unsigned long)wakeup_long64;
20632diff --git a/arch/x86/kernel/acpi/wakeup_32.S b/arch/x86/kernel/acpi/wakeup_32.S
20633index 665c6b7..eae4d56 100644
20634--- a/arch/x86/kernel/acpi/wakeup_32.S
20635+++ b/arch/x86/kernel/acpi/wakeup_32.S
20636@@ -29,13 +29,11 @@ wakeup_pmode_return:
20637 # and restore the stack ... but you need gdt for this to work
20638 movl saved_context_esp, %esp
20639
20640- movl %cs:saved_magic, %eax
20641- cmpl $0x12345678, %eax
20642+ cmpl $0x12345678, saved_magic
20643 jne bogus_magic
20644
20645 # jump to place where we left off
20646- movl saved_eip, %eax
20647- jmp *%eax
20648+ jmp *(saved_eip)
20649
20650 bogus_magic:
20651 jmp bogus_magic
20652diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
20653index 703130f..27a155d 100644
20654--- a/arch/x86/kernel/alternative.c
20655+++ b/arch/x86/kernel/alternative.c
20656@@ -268,6 +268,13 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
20657 */
20658 for (a = start; a < end; a++) {
20659 instr = (u8 *)&a->instr_offset + a->instr_offset;
20660+
20661+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20662+ instr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20663+ if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
20664+ instr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20665+#endif
20666+
20667 replacement = (u8 *)&a->repl_offset + a->repl_offset;
20668 BUG_ON(a->replacementlen > a->instrlen);
20669 BUG_ON(a->instrlen > sizeof(insnbuf));
20670@@ -284,6 +291,11 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
20671 add_nops(insnbuf + a->replacementlen,
20672 a->instrlen - a->replacementlen);
20673
20674+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20675+ if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
20676+ instr = ktva_ktla(instr);
20677+#endif
20678+
20679 text_poke_early(instr, insnbuf, a->instrlen);
20680 }
20681 }
20682@@ -299,10 +311,16 @@ static void alternatives_smp_lock(const s32 *start, const s32 *end,
20683 for (poff = start; poff < end; poff++) {
20684 u8 *ptr = (u8 *)poff + *poff;
20685
20686+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20687+ ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20688+ if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
20689+ ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20690+#endif
20691+
20692 if (!*poff || ptr < text || ptr >= text_end)
20693 continue;
20694 /* turn DS segment override prefix into lock prefix */
20695- if (*ptr == 0x3e)
20696+ if (*ktla_ktva(ptr) == 0x3e)
20697 text_poke(ptr, ((unsigned char []){0xf0}), 1);
20698 }
20699 mutex_unlock(&text_mutex);
20700@@ -317,10 +335,16 @@ static void alternatives_smp_unlock(const s32 *start, const s32 *end,
20701 for (poff = start; poff < end; poff++) {
20702 u8 *ptr = (u8 *)poff + *poff;
20703
20704+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20705+ ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20706+ if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
20707+ ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20708+#endif
20709+
20710 if (!*poff || ptr < text || ptr >= text_end)
20711 continue;
20712 /* turn lock prefix into DS segment override prefix */
20713- if (*ptr == 0xf0)
20714+ if (*ktla_ktva(ptr) == 0xf0)
20715 text_poke(ptr, ((unsigned char []){0x3E}), 1);
20716 }
20717 mutex_unlock(&text_mutex);
20718@@ -457,7 +481,7 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
20719
20720 BUG_ON(p->len > MAX_PATCH_LEN);
20721 /* prep the buffer with the original instructions */
20722- memcpy(insnbuf, p->instr, p->len);
20723+ memcpy(insnbuf, ktla_ktva(p->instr), p->len);
20724 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
20725 (unsigned long)p->instr, p->len);
20726
20727@@ -504,7 +528,7 @@ void __init alternative_instructions(void)
20728 if (!uniproc_patched || num_possible_cpus() == 1)
20729 free_init_pages("SMP alternatives",
20730 (unsigned long)__smp_locks,
20731- (unsigned long)__smp_locks_end);
20732+ PAGE_ALIGN((unsigned long)__smp_locks_end));
20733 #endif
20734
20735 apply_paravirt(__parainstructions, __parainstructions_end);
20736@@ -524,13 +548,17 @@ void __init alternative_instructions(void)
20737 * instructions. And on the local CPU you need to be protected again NMI or MCE
20738 * handlers seeing an inconsistent instruction while you patch.
20739 */
20740-void *__init_or_module text_poke_early(void *addr, const void *opcode,
20741+void *__kprobes text_poke_early(void *addr, const void *opcode,
20742 size_t len)
20743 {
20744 unsigned long flags;
20745 local_irq_save(flags);
20746- memcpy(addr, opcode, len);
20747+
20748+ pax_open_kernel();
20749+ memcpy(ktla_ktva(addr), opcode, len);
20750 sync_core();
20751+ pax_close_kernel();
20752+
20753 local_irq_restore(flags);
20754 /* Could also do a CLFLUSH here to speed up CPU recovery; but
20755 that causes hangs on some VIA CPUs. */
20756@@ -552,36 +580,22 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode,
20757 */
20758 void *text_poke(void *addr, const void *opcode, size_t len)
20759 {
20760- unsigned long flags;
20761- char *vaddr;
20762+ unsigned char *vaddr = ktla_ktva(addr);
20763 struct page *pages[2];
20764- int i;
20765+ size_t i;
20766
20767 if (!core_kernel_text((unsigned long)addr)) {
20768- pages[0] = vmalloc_to_page(addr);
20769- pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
20770+ pages[0] = vmalloc_to_page(vaddr);
20771+ pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
20772 } else {
20773- pages[0] = virt_to_page(addr);
20774+ pages[0] = virt_to_page(vaddr);
20775 WARN_ON(!PageReserved(pages[0]));
20776- pages[1] = virt_to_page(addr + PAGE_SIZE);
20777+ pages[1] = virt_to_page(vaddr + PAGE_SIZE);
20778 }
20779 BUG_ON(!pages[0]);
20780- local_irq_save(flags);
20781- set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
20782- if (pages[1])
20783- set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
20784- vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
20785- memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
20786- clear_fixmap(FIX_TEXT_POKE0);
20787- if (pages[1])
20788- clear_fixmap(FIX_TEXT_POKE1);
20789- local_flush_tlb();
20790- sync_core();
20791- /* Could also do a CLFLUSH here to speed up CPU recovery; but
20792- that causes hangs on some VIA CPUs. */
20793+ text_poke_early(addr, opcode, len);
20794 for (i = 0; i < len; i++)
20795- BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
20796- local_irq_restore(flags);
20797+ BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
20798 return addr;
20799 }
20800
20801@@ -601,7 +615,7 @@ int poke_int3_handler(struct pt_regs *regs)
20802 if (likely(!bp_patching_in_progress))
20803 return 0;
20804
20805- if (user_mode_vm(regs) || regs->ip != (unsigned long)bp_int3_addr)
20806+ if (user_mode(regs) || regs->ip != (unsigned long)bp_int3_addr)
20807 return 0;
20808
20809 /* set up the specified breakpoint handler */
20810@@ -635,7 +649,7 @@ int poke_int3_handler(struct pt_regs *regs)
20811 */
20812 void *text_poke_bp(void *addr, const void *opcode, size_t len, void *handler)
20813 {
20814- unsigned char int3 = 0xcc;
20815+ const unsigned char int3 = 0xcc;
20816
20817 bp_int3_handler = handler;
20818 bp_int3_addr = (u8 *)addr + sizeof(int3);
20819diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
20820index ba6cc04..06fd971 100644
20821--- a/arch/x86/kernel/apic/apic.c
20822+++ b/arch/x86/kernel/apic/apic.c
20823@@ -201,7 +201,7 @@ int first_system_vector = 0xfe;
20824 /*
20825 * Debug level, exported for io_apic.c
20826 */
20827-unsigned int apic_verbosity;
20828+int apic_verbosity;
20829
20830 int pic_mode;
20831
20832@@ -1989,7 +1989,7 @@ static inline void __smp_error_interrupt(struct pt_regs *regs)
20833 apic_write(APIC_ESR, 0);
20834 v = apic_read(APIC_ESR);
20835 ack_APIC_irq();
20836- atomic_inc(&irq_err_count);
20837+ atomic_inc_unchecked(&irq_err_count);
20838
20839 apic_printk(APIC_DEBUG, KERN_DEBUG "APIC error on CPU%d: %02x",
20840 smp_processor_id(), v);
20841diff --git a/arch/x86/kernel/apic/apic_flat_64.c b/arch/x86/kernel/apic/apic_flat_64.c
20842index de918c4..32eed23 100644
20843--- a/arch/x86/kernel/apic/apic_flat_64.c
20844+++ b/arch/x86/kernel/apic/apic_flat_64.c
20845@@ -154,7 +154,7 @@ static int flat_probe(void)
20846 return 1;
20847 }
20848
20849-static struct apic apic_flat = {
20850+static struct apic apic_flat __read_only = {
20851 .name = "flat",
20852 .probe = flat_probe,
20853 .acpi_madt_oem_check = flat_acpi_madt_oem_check,
20854@@ -260,7 +260,7 @@ static int physflat_probe(void)
20855 return 0;
20856 }
20857
20858-static struct apic apic_physflat = {
20859+static struct apic apic_physflat __read_only = {
20860
20861 .name = "physical flat",
20862 .probe = physflat_probe,
20863diff --git a/arch/x86/kernel/apic/apic_noop.c b/arch/x86/kernel/apic/apic_noop.c
20864index b205cdb..d8503ff 100644
20865--- a/arch/x86/kernel/apic/apic_noop.c
20866+++ b/arch/x86/kernel/apic/apic_noop.c
20867@@ -108,7 +108,7 @@ static void noop_apic_write(u32 reg, u32 v)
20868 WARN_ON_ONCE(cpu_has_apic && !disable_apic);
20869 }
20870
20871-struct apic apic_noop = {
20872+struct apic apic_noop __read_only = {
20873 .name = "noop",
20874 .probe = noop_probe,
20875 .acpi_madt_oem_check = NULL,
20876diff --git a/arch/x86/kernel/apic/bigsmp_32.c b/arch/x86/kernel/apic/bigsmp_32.c
20877index c4a8d63..fe893ac 100644
20878--- a/arch/x86/kernel/apic/bigsmp_32.c
20879+++ b/arch/x86/kernel/apic/bigsmp_32.c
20880@@ -147,7 +147,7 @@ static int probe_bigsmp(void)
20881 return dmi_bigsmp;
20882 }
20883
20884-static struct apic apic_bigsmp = {
20885+static struct apic apic_bigsmp __read_only = {
20886
20887 .name = "bigsmp",
20888 .probe = probe_bigsmp,
20889diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
20890index 1183d54..6158e47 100644
20891--- a/arch/x86/kernel/apic/io_apic.c
20892+++ b/arch/x86/kernel/apic/io_apic.c
20893@@ -1230,7 +1230,7 @@ out:
20894 }
20895 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
20896
20897-void lock_vector_lock(void)
20898+void lock_vector_lock(void) __acquires(vector_lock)
20899 {
20900 /* Used to the online set of cpus does not change
20901 * during assign_irq_vector.
20902@@ -1238,7 +1238,7 @@ void lock_vector_lock(void)
20903 raw_spin_lock(&vector_lock);
20904 }
20905
20906-void unlock_vector_lock(void)
20907+void unlock_vector_lock(void) __releases(vector_lock)
20908 {
20909 raw_spin_unlock(&vector_lock);
20910 }
20911@@ -2465,7 +2465,7 @@ static void ack_apic_edge(struct irq_data *data)
20912 ack_APIC_irq();
20913 }
20914
20915-atomic_t irq_mis_count;
20916+atomic_unchecked_t irq_mis_count;
20917
20918 #ifdef CONFIG_GENERIC_PENDING_IRQ
20919 static bool io_apic_level_ack_pending(struct irq_cfg *cfg)
20920@@ -2606,7 +2606,7 @@ static void ack_apic_level(struct irq_data *data)
20921 * at the cpu.
20922 */
20923 if (!(v & (1 << (i & 0x1f)))) {
20924- atomic_inc(&irq_mis_count);
20925+ atomic_inc_unchecked(&irq_mis_count);
20926
20927 eoi_ioapic_irq(irq, cfg);
20928 }
20929diff --git a/arch/x86/kernel/apic/probe_32.c b/arch/x86/kernel/apic/probe_32.c
20930index bda4886..f9c7195 100644
20931--- a/arch/x86/kernel/apic/probe_32.c
20932+++ b/arch/x86/kernel/apic/probe_32.c
20933@@ -72,7 +72,7 @@ static int probe_default(void)
20934 return 1;
20935 }
20936
20937-static struct apic apic_default = {
20938+static struct apic apic_default __read_only = {
20939
20940 .name = "default",
20941 .probe = probe_default,
20942diff --git a/arch/x86/kernel/apic/x2apic_cluster.c b/arch/x86/kernel/apic/x2apic_cluster.c
20943index e658f21..b695a1a 100644
20944--- a/arch/x86/kernel/apic/x2apic_cluster.c
20945+++ b/arch/x86/kernel/apic/x2apic_cluster.c
20946@@ -182,7 +182,7 @@ update_clusterinfo(struct notifier_block *nfb, unsigned long action, void *hcpu)
20947 return notifier_from_errno(err);
20948 }
20949
20950-static struct notifier_block __refdata x2apic_cpu_notifier = {
20951+static struct notifier_block x2apic_cpu_notifier = {
20952 .notifier_call = update_clusterinfo,
20953 };
20954
20955@@ -234,7 +234,7 @@ static void cluster_vector_allocation_domain(int cpu, struct cpumask *retmask,
20956 cpumask_and(retmask, mask, per_cpu(cpus_in_cluster, cpu));
20957 }
20958
20959-static struct apic apic_x2apic_cluster = {
20960+static struct apic apic_x2apic_cluster __read_only = {
20961
20962 .name = "cluster x2apic",
20963 .probe = x2apic_cluster_probe,
20964diff --git a/arch/x86/kernel/apic/x2apic_phys.c b/arch/x86/kernel/apic/x2apic_phys.c
20965index 6fae733..5ca17af 100644
20966--- a/arch/x86/kernel/apic/x2apic_phys.c
20967+++ b/arch/x86/kernel/apic/x2apic_phys.c
20968@@ -88,7 +88,7 @@ static int x2apic_phys_probe(void)
20969 return apic == &apic_x2apic_phys;
20970 }
20971
20972-static struct apic apic_x2apic_phys = {
20973+static struct apic apic_x2apic_phys __read_only = {
20974
20975 .name = "physical x2apic",
20976 .probe = x2apic_phys_probe,
20977diff --git a/arch/x86/kernel/apic/x2apic_uv_x.c b/arch/x86/kernel/apic/x2apic_uv_x.c
20978index 8e9dcfd..c61b3e4 100644
20979--- a/arch/x86/kernel/apic/x2apic_uv_x.c
20980+++ b/arch/x86/kernel/apic/x2apic_uv_x.c
20981@@ -348,7 +348,7 @@ static int uv_probe(void)
20982 return apic == &apic_x2apic_uv_x;
20983 }
20984
20985-static struct apic __refdata apic_x2apic_uv_x = {
20986+static struct apic apic_x2apic_uv_x __read_only = {
20987
20988 .name = "UV large system",
20989 .probe = uv_probe,
20990diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
20991index 5848744..56cb598 100644
20992--- a/arch/x86/kernel/apm_32.c
20993+++ b/arch/x86/kernel/apm_32.c
20994@@ -433,7 +433,7 @@ static DEFINE_MUTEX(apm_mutex);
20995 * This is for buggy BIOS's that refer to (real mode) segment 0x40
20996 * even though they are called in protected mode.
20997 */
20998-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
20999+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
21000 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
21001
21002 static const char driver_version[] = "1.16ac"; /* no spaces */
21003@@ -611,7 +611,10 @@ static long __apm_bios_call(void *_call)
21004 BUG_ON(cpu != 0);
21005 gdt = get_cpu_gdt_table(cpu);
21006 save_desc_40 = gdt[0x40 / 8];
21007+
21008+ pax_open_kernel();
21009 gdt[0x40 / 8] = bad_bios_desc;
21010+ pax_close_kernel();
21011
21012 apm_irq_save(flags);
21013 APM_DO_SAVE_SEGS;
21014@@ -620,7 +623,11 @@ static long __apm_bios_call(void *_call)
21015 &call->esi);
21016 APM_DO_RESTORE_SEGS;
21017 apm_irq_restore(flags);
21018+
21019+ pax_open_kernel();
21020 gdt[0x40 / 8] = save_desc_40;
21021+ pax_close_kernel();
21022+
21023 put_cpu();
21024
21025 return call->eax & 0xff;
21026@@ -687,7 +694,10 @@ static long __apm_bios_call_simple(void *_call)
21027 BUG_ON(cpu != 0);
21028 gdt = get_cpu_gdt_table(cpu);
21029 save_desc_40 = gdt[0x40 / 8];
21030+
21031+ pax_open_kernel();
21032 gdt[0x40 / 8] = bad_bios_desc;
21033+ pax_close_kernel();
21034
21035 apm_irq_save(flags);
21036 APM_DO_SAVE_SEGS;
21037@@ -695,7 +705,11 @@ static long __apm_bios_call_simple(void *_call)
21038 &call->eax);
21039 APM_DO_RESTORE_SEGS;
21040 apm_irq_restore(flags);
21041+
21042+ pax_open_kernel();
21043 gdt[0x40 / 8] = save_desc_40;
21044+ pax_close_kernel();
21045+
21046 put_cpu();
21047 return error;
21048 }
21049@@ -2350,12 +2364,15 @@ static int __init apm_init(void)
21050 * code to that CPU.
21051 */
21052 gdt = get_cpu_gdt_table(0);
21053+
21054+ pax_open_kernel();
21055 set_desc_base(&gdt[APM_CS >> 3],
21056 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
21057 set_desc_base(&gdt[APM_CS_16 >> 3],
21058 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
21059 set_desc_base(&gdt[APM_DS >> 3],
21060 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
21061+ pax_close_kernel();
21062
21063 proc_create("apm", 0, NULL, &apm_file_ops);
21064
21065diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
21066index 9f6b934..cf5ffb3 100644
21067--- a/arch/x86/kernel/asm-offsets.c
21068+++ b/arch/x86/kernel/asm-offsets.c
21069@@ -32,6 +32,8 @@ void common(void) {
21070 OFFSET(TI_flags, thread_info, flags);
21071 OFFSET(TI_status, thread_info, status);
21072 OFFSET(TI_addr_limit, thread_info, addr_limit);
21073+ OFFSET(TI_lowest_stack, thread_info, lowest_stack);
21074+ DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
21075
21076 BLANK();
21077 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
21078@@ -52,8 +54,26 @@ void common(void) {
21079 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
21080 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
21081 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
21082+
21083+#ifdef CONFIG_PAX_KERNEXEC
21084+ OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
21085 #endif
21086
21087+#ifdef CONFIG_PAX_MEMORY_UDEREF
21088+ OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
21089+ OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
21090+#ifdef CONFIG_X86_64
21091+ OFFSET(PV_MMU_set_pgd_batched, pv_mmu_ops, set_pgd_batched);
21092+#endif
21093+#endif
21094+
21095+#endif
21096+
21097+ BLANK();
21098+ DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
21099+ DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
21100+ DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
21101+
21102 #ifdef CONFIG_XEN
21103 BLANK();
21104 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
21105diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
21106index e7c798b..2b2019b 100644
21107--- a/arch/x86/kernel/asm-offsets_64.c
21108+++ b/arch/x86/kernel/asm-offsets_64.c
21109@@ -77,6 +77,7 @@ int main(void)
21110 BLANK();
21111 #undef ENTRY
21112
21113+ DEFINE(TSS_size, sizeof(struct tss_struct));
21114 OFFSET(TSS_ist, tss_struct, x86_tss.ist);
21115 BLANK();
21116
21117diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
21118index e27b49d..85b106c 100644
21119--- a/arch/x86/kernel/cpu/Makefile
21120+++ b/arch/x86/kernel/cpu/Makefile
21121@@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
21122 CFLAGS_REMOVE_perf_event.o = -pg
21123 endif
21124
21125-# Make sure load_percpu_segment has no stackprotector
21126-nostackp := $(call cc-option, -fno-stack-protector)
21127-CFLAGS_common.o := $(nostackp)
21128-
21129 obj-y := intel_cacheinfo.o scattered.o topology.o
21130 obj-y += common.o
21131 obj-y += rdrand.o
21132diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
21133index 813d29d..6e542d4 100644
21134--- a/arch/x86/kernel/cpu/amd.c
21135+++ b/arch/x86/kernel/cpu/amd.c
21136@@ -718,7 +718,7 @@ static void init_amd(struct cpuinfo_x86 *c)
21137 static unsigned int amd_size_cache(struct cpuinfo_x86 *c, unsigned int size)
21138 {
21139 /* AMD errata T13 (order #21922) */
21140- if ((c->x86 == 6)) {
21141+ if (c->x86 == 6) {
21142 /* Duron Rev A0 */
21143 if (c->x86_model == 3 && c->x86_mask == 0)
21144 size = 64;
21145diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
21146index cfa9b5b..19b5084 100644
21147--- a/arch/x86/kernel/cpu/common.c
21148+++ b/arch/x86/kernel/cpu/common.c
21149@@ -90,60 +90,6 @@ static const struct cpu_dev default_cpu = {
21150
21151 static const struct cpu_dev *this_cpu = &default_cpu;
21152
21153-DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
21154-#ifdef CONFIG_X86_64
21155- /*
21156- * We need valid kernel segments for data and code in long mode too
21157- * IRET will check the segment types kkeil 2000/10/28
21158- * Also sysret mandates a special GDT layout
21159- *
21160- * TLS descriptors are currently at a different place compared to i386.
21161- * Hopefully nobody expects them at a fixed place (Wine?)
21162- */
21163- [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
21164- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
21165- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
21166- [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
21167- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
21168- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
21169-#else
21170- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
21171- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
21172- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
21173- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
21174- /*
21175- * Segments used for calling PnP BIOS have byte granularity.
21176- * They code segments and data segments have fixed 64k limits,
21177- * the transfer segment sizes are set at run time.
21178- */
21179- /* 32-bit code */
21180- [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
21181- /* 16-bit code */
21182- [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
21183- /* 16-bit data */
21184- [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
21185- /* 16-bit data */
21186- [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
21187- /* 16-bit data */
21188- [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
21189- /*
21190- * The APM segments have byte granularity and their bases
21191- * are set at run time. All have 64k limits.
21192- */
21193- /* 32-bit code */
21194- [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
21195- /* 16-bit code */
21196- [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
21197- /* data */
21198- [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
21199-
21200- [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
21201- [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
21202- GDT_STACK_CANARY_INIT
21203-#endif
21204-} };
21205-EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
21206-
21207 static int __init x86_xsave_setup(char *s)
21208 {
21209 if (strlen(s))
21210@@ -305,6 +251,59 @@ static __always_inline void setup_smap(struct cpuinfo_x86 *c)
21211 }
21212 }
21213
21214+#ifdef CONFIG_X86_64
21215+static __init int setup_disable_pcid(char *arg)
21216+{
21217+ setup_clear_cpu_cap(X86_FEATURE_PCID);
21218+ setup_clear_cpu_cap(X86_FEATURE_INVPCID);
21219+
21220+#ifdef CONFIG_PAX_MEMORY_UDEREF
21221+ if (clone_pgd_mask != ~(pgdval_t)0UL)
21222+ pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
21223+#endif
21224+
21225+ return 1;
21226+}
21227+__setup("nopcid", setup_disable_pcid);
21228+
21229+static void setup_pcid(struct cpuinfo_x86 *c)
21230+{
21231+ if (!cpu_has(c, X86_FEATURE_PCID)) {
21232+ clear_cpu_cap(c, X86_FEATURE_INVPCID);
21233+
21234+#ifdef CONFIG_PAX_MEMORY_UDEREF
21235+ if (clone_pgd_mask != ~(pgdval_t)0UL) {
21236+ pax_open_kernel();
21237+ pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
21238+ pax_close_kernel();
21239+ printk("PAX: slow and weak UDEREF enabled\n");
21240+ } else
21241+ printk("PAX: UDEREF disabled\n");
21242+#endif
21243+
21244+ return;
21245+ }
21246+
21247+ printk("PAX: PCID detected\n");
21248+ set_in_cr4(X86_CR4_PCIDE);
21249+
21250+#ifdef CONFIG_PAX_MEMORY_UDEREF
21251+ pax_open_kernel();
21252+ clone_pgd_mask = ~(pgdval_t)0UL;
21253+ pax_close_kernel();
21254+ if (pax_user_shadow_base)
21255+ printk("PAX: weak UDEREF enabled\n");
21256+ else {
21257+ set_cpu_cap(c, X86_FEATURE_STRONGUDEREF);
21258+ printk("PAX: strong UDEREF enabled\n");
21259+ }
21260+#endif
21261+
21262+ if (cpu_has(c, X86_FEATURE_INVPCID))
21263+ printk("PAX: INVPCID detected\n");
21264+}
21265+#endif
21266+
21267 /*
21268 * Some CPU features depend on higher CPUID levels, which may not always
21269 * be available due to CPUID level capping or broken virtualization
21270@@ -405,7 +404,7 @@ void switch_to_new_gdt(int cpu)
21271 {
21272 struct desc_ptr gdt_descr;
21273
21274- gdt_descr.address = (long)get_cpu_gdt_table(cpu);
21275+ gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
21276 gdt_descr.size = GDT_SIZE - 1;
21277 load_gdt(&gdt_descr);
21278 /* Reload the per-cpu base */
21279@@ -895,6 +894,10 @@ static void identify_cpu(struct cpuinfo_x86 *c)
21280 setup_smep(c);
21281 setup_smap(c);
21282
21283+#ifdef CONFIG_X86_64
21284+ setup_pcid(c);
21285+#endif
21286+
21287 /*
21288 * The vendor-specific functions might have changed features.
21289 * Now we do "generic changes."
21290@@ -903,6 +906,10 @@ static void identify_cpu(struct cpuinfo_x86 *c)
21291 /* Filter out anything that depends on CPUID levels we don't have */
21292 filter_cpuid_features(c, true);
21293
21294+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
21295+ setup_clear_cpu_cap(X86_FEATURE_SEP);
21296+#endif
21297+
21298 /* If the model name is still unset, do table lookup. */
21299 if (!c->x86_model_id[0]) {
21300 const char *p;
21301@@ -985,7 +992,7 @@ static void syscall32_cpu_init(void)
21302 void enable_sep_cpu(void)
21303 {
21304 int cpu = get_cpu();
21305- struct tss_struct *tss = &per_cpu(init_tss, cpu);
21306+ struct tss_struct *tss = init_tss + cpu;
21307
21308 if (!boot_cpu_has(X86_FEATURE_SEP)) {
21309 put_cpu();
21310@@ -1125,14 +1132,16 @@ static __init int setup_disablecpuid(char *arg)
21311 }
21312 __setup("clearcpuid=", setup_disablecpuid);
21313
21314+DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
21315+EXPORT_PER_CPU_SYMBOL(current_tinfo);
21316+
21317 DEFINE_PER_CPU(unsigned long, kernel_stack) =
21318- (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
21319+ (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
21320 EXPORT_PER_CPU_SYMBOL(kernel_stack);
21321
21322 #ifdef CONFIG_X86_64
21323-struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
21324-struct desc_ptr debug_idt_descr = { NR_VECTORS * 16 - 1,
21325- (unsigned long) debug_idt_table };
21326+struct desc_ptr idt_descr __read_only = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
21327+const struct desc_ptr debug_idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) debug_idt_table };
21328
21329 DEFINE_PER_CPU_FIRST(union irq_stack_union,
21330 irq_stack_union) __aligned(PAGE_SIZE) __visible;
21331@@ -1309,7 +1318,7 @@ void cpu_init(void)
21332 */
21333 load_ucode_ap();
21334
21335- t = &per_cpu(init_tss, cpu);
21336+ t = init_tss + cpu;
21337 oist = &per_cpu(orig_ist, cpu);
21338
21339 #ifdef CONFIG_NUMA
21340@@ -1341,7 +1350,6 @@ void cpu_init(void)
21341 wrmsrl(MSR_KERNEL_GS_BASE, 0);
21342 barrier();
21343
21344- x86_configure_nx();
21345 enable_x2apic();
21346
21347 /*
21348@@ -1393,7 +1401,7 @@ void cpu_init(void)
21349 {
21350 int cpu = smp_processor_id();
21351 struct task_struct *curr = current;
21352- struct tss_struct *t = &per_cpu(init_tss, cpu);
21353+ struct tss_struct *t = init_tss + cpu;
21354 struct thread_struct *thread = &curr->thread;
21355
21356 wait_for_master_cpu(cpu);
21357diff --git a/arch/x86/kernel/cpu/intel_cacheinfo.c b/arch/x86/kernel/cpu/intel_cacheinfo.c
21358index c703507..28535e3 100644
21359--- a/arch/x86/kernel/cpu/intel_cacheinfo.c
21360+++ b/arch/x86/kernel/cpu/intel_cacheinfo.c
21361@@ -1026,6 +1026,22 @@ static struct attribute *default_attrs[] = {
21362 };
21363
21364 #ifdef CONFIG_AMD_NB
21365+static struct attribute *default_attrs_amd_nb[] = {
21366+ &type.attr,
21367+ &level.attr,
21368+ &coherency_line_size.attr,
21369+ &physical_line_partition.attr,
21370+ &ways_of_associativity.attr,
21371+ &number_of_sets.attr,
21372+ &size.attr,
21373+ &shared_cpu_map.attr,
21374+ &shared_cpu_list.attr,
21375+ NULL,
21376+ NULL,
21377+ NULL,
21378+ NULL
21379+};
21380+
21381 static struct attribute **amd_l3_attrs(void)
21382 {
21383 static struct attribute **attrs;
21384@@ -1036,18 +1052,7 @@ static struct attribute **amd_l3_attrs(void)
21385
21386 n = ARRAY_SIZE(default_attrs);
21387
21388- if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE))
21389- n += 2;
21390-
21391- if (amd_nb_has_feature(AMD_NB_L3_PARTITIONING))
21392- n += 1;
21393-
21394- attrs = kzalloc(n * sizeof (struct attribute *), GFP_KERNEL);
21395- if (attrs == NULL)
21396- return attrs = default_attrs;
21397-
21398- for (n = 0; default_attrs[n]; n++)
21399- attrs[n] = default_attrs[n];
21400+ attrs = default_attrs_amd_nb;
21401
21402 if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE)) {
21403 attrs[n++] = &cache_disable_0.attr;
21404@@ -1098,6 +1103,13 @@ static struct kobj_type ktype_cache = {
21405 .default_attrs = default_attrs,
21406 };
21407
21408+#ifdef CONFIG_AMD_NB
21409+static struct kobj_type ktype_cache_amd_nb = {
21410+ .sysfs_ops = &sysfs_ops,
21411+ .default_attrs = default_attrs_amd_nb,
21412+};
21413+#endif
21414+
21415 static struct kobj_type ktype_percpu_entry = {
21416 .sysfs_ops = &sysfs_ops,
21417 };
21418@@ -1163,20 +1175,26 @@ static int cache_add_dev(struct device *dev)
21419 return retval;
21420 }
21421
21422+#ifdef CONFIG_AMD_NB
21423+ amd_l3_attrs();
21424+#endif
21425+
21426 for (i = 0; i < num_cache_leaves; i++) {
21427+ struct kobj_type *ktype;
21428+
21429 this_object = INDEX_KOBJECT_PTR(cpu, i);
21430 this_object->cpu = cpu;
21431 this_object->index = i;
21432
21433 this_leaf = CPUID4_INFO_IDX(cpu, i);
21434
21435- ktype_cache.default_attrs = default_attrs;
21436+ ktype = &ktype_cache;
21437 #ifdef CONFIG_AMD_NB
21438 if (this_leaf->base.nb)
21439- ktype_cache.default_attrs = amd_l3_attrs();
21440+ ktype = &ktype_cache_amd_nb;
21441 #endif
21442 retval = kobject_init_and_add(&(this_object->kobj),
21443- &ktype_cache,
21444+ ktype,
21445 per_cpu(ici_cache_kobject, cpu),
21446 "index%1lu", i);
21447 if (unlikely(retval)) {
21448diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
21449index 61a9668ce..b446a37 100644
21450--- a/arch/x86/kernel/cpu/mcheck/mce.c
21451+++ b/arch/x86/kernel/cpu/mcheck/mce.c
21452@@ -45,6 +45,7 @@
21453 #include <asm/processor.h>
21454 #include <asm/mce.h>
21455 #include <asm/msr.h>
21456+#include <asm/local.h>
21457
21458 #include "mce-internal.h"
21459
21460@@ -259,7 +260,7 @@ static void print_mce(struct mce *m)
21461 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
21462 m->cs, m->ip);
21463
21464- if (m->cs == __KERNEL_CS)
21465+ if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
21466 print_symbol("{%s}", m->ip);
21467 pr_cont("\n");
21468 }
21469@@ -292,10 +293,10 @@ static void print_mce(struct mce *m)
21470
21471 #define PANIC_TIMEOUT 5 /* 5 seconds */
21472
21473-static atomic_t mce_paniced;
21474+static atomic_unchecked_t mce_paniced;
21475
21476 static int fake_panic;
21477-static atomic_t mce_fake_paniced;
21478+static atomic_unchecked_t mce_fake_paniced;
21479
21480 /* Panic in progress. Enable interrupts and wait for final IPI */
21481 static void wait_for_panic(void)
21482@@ -319,7 +320,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
21483 /*
21484 * Make sure only one CPU runs in machine check panic
21485 */
21486- if (atomic_inc_return(&mce_paniced) > 1)
21487+ if (atomic_inc_return_unchecked(&mce_paniced) > 1)
21488 wait_for_panic();
21489 barrier();
21490
21491@@ -327,7 +328,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
21492 console_verbose();
21493 } else {
21494 /* Don't log too much for fake panic */
21495- if (atomic_inc_return(&mce_fake_paniced) > 1)
21496+ if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
21497 return;
21498 }
21499 /* First print corrected ones that are still unlogged */
21500@@ -366,7 +367,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
21501 if (!fake_panic) {
21502 if (panic_timeout == 0)
21503 panic_timeout = mca_cfg.panic_timeout;
21504- panic(msg);
21505+ panic("%s", msg);
21506 } else
21507 pr_emerg(HW_ERR "Fake kernel panic: %s\n", msg);
21508 }
21509@@ -697,7 +698,7 @@ static int mce_timed_out(u64 *t)
21510 * might have been modified by someone else.
21511 */
21512 rmb();
21513- if (atomic_read(&mce_paniced))
21514+ if (atomic_read_unchecked(&mce_paniced))
21515 wait_for_panic();
21516 if (!mca_cfg.monarch_timeout)
21517 goto out;
21518@@ -1674,7 +1675,7 @@ static void unexpected_machine_check(struct pt_regs *regs, long error_code)
21519 }
21520
21521 /* Call the installed machine check handler for this CPU setup. */
21522-void (*machine_check_vector)(struct pt_regs *, long error_code) =
21523+void (*machine_check_vector)(struct pt_regs *, long error_code) __read_only =
21524 unexpected_machine_check;
21525
21526 /*
21527@@ -1697,7 +1698,9 @@ void mcheck_cpu_init(struct cpuinfo_x86 *c)
21528 return;
21529 }
21530
21531+ pax_open_kernel();
21532 machine_check_vector = do_machine_check;
21533+ pax_close_kernel();
21534
21535 __mcheck_cpu_init_generic();
21536 __mcheck_cpu_init_vendor(c);
21537@@ -1711,7 +1714,7 @@ void mcheck_cpu_init(struct cpuinfo_x86 *c)
21538 */
21539
21540 static DEFINE_SPINLOCK(mce_chrdev_state_lock);
21541-static int mce_chrdev_open_count; /* #times opened */
21542+static local_t mce_chrdev_open_count; /* #times opened */
21543 static int mce_chrdev_open_exclu; /* already open exclusive? */
21544
21545 static int mce_chrdev_open(struct inode *inode, struct file *file)
21546@@ -1719,7 +1722,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
21547 spin_lock(&mce_chrdev_state_lock);
21548
21549 if (mce_chrdev_open_exclu ||
21550- (mce_chrdev_open_count && (file->f_flags & O_EXCL))) {
21551+ (local_read(&mce_chrdev_open_count) && (file->f_flags & O_EXCL))) {
21552 spin_unlock(&mce_chrdev_state_lock);
21553
21554 return -EBUSY;
21555@@ -1727,7 +1730,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
21556
21557 if (file->f_flags & O_EXCL)
21558 mce_chrdev_open_exclu = 1;
21559- mce_chrdev_open_count++;
21560+ local_inc(&mce_chrdev_open_count);
21561
21562 spin_unlock(&mce_chrdev_state_lock);
21563
21564@@ -1738,7 +1741,7 @@ static int mce_chrdev_release(struct inode *inode, struct file *file)
21565 {
21566 spin_lock(&mce_chrdev_state_lock);
21567
21568- mce_chrdev_open_count--;
21569+ local_dec(&mce_chrdev_open_count);
21570 mce_chrdev_open_exclu = 0;
21571
21572 spin_unlock(&mce_chrdev_state_lock);
21573@@ -2413,7 +2416,7 @@ static __init void mce_init_banks(void)
21574
21575 for (i = 0; i < mca_cfg.banks; i++) {
21576 struct mce_bank *b = &mce_banks[i];
21577- struct device_attribute *a = &b->attr;
21578+ device_attribute_no_const *a = &b->attr;
21579
21580 sysfs_attr_init(&a->attr);
21581 a->attr.name = b->attrname;
21582@@ -2520,7 +2523,7 @@ struct dentry *mce_get_debugfs_dir(void)
21583 static void mce_reset(void)
21584 {
21585 cpu_missing = 0;
21586- atomic_set(&mce_fake_paniced, 0);
21587+ atomic_set_unchecked(&mce_fake_paniced, 0);
21588 atomic_set(&mce_executing, 0);
21589 atomic_set(&mce_callin, 0);
21590 atomic_set(&global_nwo, 0);
21591diff --git a/arch/x86/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
21592index a304298..49b6d06 100644
21593--- a/arch/x86/kernel/cpu/mcheck/p5.c
21594+++ b/arch/x86/kernel/cpu/mcheck/p5.c
21595@@ -10,6 +10,7 @@
21596 #include <asm/processor.h>
21597 #include <asm/mce.h>
21598 #include <asm/msr.h>
21599+#include <asm/pgtable.h>
21600
21601 /* By default disabled */
21602 int mce_p5_enabled __read_mostly;
21603@@ -48,7 +49,9 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
21604 if (!cpu_has(c, X86_FEATURE_MCE))
21605 return;
21606
21607+ pax_open_kernel();
21608 machine_check_vector = pentium_machine_check;
21609+ pax_close_kernel();
21610 /* Make sure the vector pointer is visible before we enable MCEs: */
21611 wmb();
21612
21613diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
21614index 7dc5564..1273569 100644
21615--- a/arch/x86/kernel/cpu/mcheck/winchip.c
21616+++ b/arch/x86/kernel/cpu/mcheck/winchip.c
21617@@ -9,6 +9,7 @@
21618 #include <asm/processor.h>
21619 #include <asm/mce.h>
21620 #include <asm/msr.h>
21621+#include <asm/pgtable.h>
21622
21623 /* Machine check handler for WinChip C6: */
21624 static void winchip_machine_check(struct pt_regs *regs, long error_code)
21625@@ -22,7 +23,9 @@ void winchip_mcheck_init(struct cpuinfo_x86 *c)
21626 {
21627 u32 lo, hi;
21628
21629+ pax_open_kernel();
21630 machine_check_vector = winchip_machine_check;
21631+ pax_close_kernel();
21632 /* Make sure the vector pointer is visible before we enable MCEs: */
21633 wmb();
21634
21635diff --git a/arch/x86/kernel/cpu/microcode/core.c b/arch/x86/kernel/cpu/microcode/core.c
21636index 15c2909..2cef20c 100644
21637--- a/arch/x86/kernel/cpu/microcode/core.c
21638+++ b/arch/x86/kernel/cpu/microcode/core.c
21639@@ -518,7 +518,7 @@ mc_cpu_callback(struct notifier_block *nb, unsigned long action, void *hcpu)
21640 return NOTIFY_OK;
21641 }
21642
21643-static struct notifier_block __refdata mc_cpu_notifier = {
21644+static struct notifier_block mc_cpu_notifier = {
21645 .notifier_call = mc_cpu_callback,
21646 };
21647
21648diff --git a/arch/x86/kernel/cpu/microcode/intel.c b/arch/x86/kernel/cpu/microcode/intel.c
21649index c6826d1..ad18e14a 100644
21650--- a/arch/x86/kernel/cpu/microcode/intel.c
21651+++ b/arch/x86/kernel/cpu/microcode/intel.c
21652@@ -293,13 +293,13 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device,
21653
21654 static int get_ucode_user(void *to, const void *from, size_t n)
21655 {
21656- return copy_from_user(to, from, n);
21657+ return copy_from_user(to, (const void __force_user *)from, n);
21658 }
21659
21660 static enum ucode_state
21661 request_microcode_user(int cpu, const void __user *buf, size_t size)
21662 {
21663- return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
21664+ return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
21665 }
21666
21667 static void microcode_fini_cpu(int cpu)
21668diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
21669index ea5f363..cb0e905 100644
21670--- a/arch/x86/kernel/cpu/mtrr/main.c
21671+++ b/arch/x86/kernel/cpu/mtrr/main.c
21672@@ -66,7 +66,7 @@ static DEFINE_MUTEX(mtrr_mutex);
21673 u64 size_or_mask, size_and_mask;
21674 static bool mtrr_aps_delayed_init;
21675
21676-static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
21677+static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
21678
21679 const struct mtrr_ops *mtrr_if;
21680
21681diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
21682index df5e41f..816c719 100644
21683--- a/arch/x86/kernel/cpu/mtrr/mtrr.h
21684+++ b/arch/x86/kernel/cpu/mtrr/mtrr.h
21685@@ -25,7 +25,7 @@ struct mtrr_ops {
21686 int (*validate_add_page)(unsigned long base, unsigned long size,
21687 unsigned int type);
21688 int (*have_wrcomb)(void);
21689-};
21690+} __do_const;
21691
21692 extern int generic_get_free_region(unsigned long base, unsigned long size,
21693 int replace_reg);
21694diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
21695index 143e5f5..5825081 100644
21696--- a/arch/x86/kernel/cpu/perf_event.c
21697+++ b/arch/x86/kernel/cpu/perf_event.c
21698@@ -1374,7 +1374,7 @@ static void __init pmu_check_apic(void)
21699
21700 }
21701
21702-static struct attribute_group x86_pmu_format_group = {
21703+static attribute_group_no_const x86_pmu_format_group = {
21704 .name = "format",
21705 .attrs = NULL,
21706 };
21707@@ -1473,7 +1473,7 @@ static struct attribute *events_attr[] = {
21708 NULL,
21709 };
21710
21711-static struct attribute_group x86_pmu_events_group = {
21712+static attribute_group_no_const x86_pmu_events_group = {
21713 .name = "events",
21714 .attrs = events_attr,
21715 };
21716@@ -1997,7 +1997,7 @@ static unsigned long get_segment_base(unsigned int segment)
21717 if (idx > GDT_ENTRIES)
21718 return 0;
21719
21720- desc = raw_cpu_ptr(gdt_page.gdt);
21721+ desc = get_cpu_gdt_table(smp_processor_id());
21722 }
21723
21724 return get_desc_base(desc + idx);
21725@@ -2087,7 +2087,7 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
21726 break;
21727
21728 perf_callchain_store(entry, frame.return_address);
21729- fp = frame.next_frame;
21730+ fp = (const void __force_user *)frame.next_frame;
21731 }
21732 }
21733
21734diff --git a/arch/x86/kernel/cpu/perf_event_amd_iommu.c b/arch/x86/kernel/cpu/perf_event_amd_iommu.c
21735index 639d128..e92d7e5 100644
21736--- a/arch/x86/kernel/cpu/perf_event_amd_iommu.c
21737+++ b/arch/x86/kernel/cpu/perf_event_amd_iommu.c
21738@@ -405,7 +405,7 @@ static void perf_iommu_del(struct perf_event *event, int flags)
21739 static __init int _init_events_attrs(struct perf_amd_iommu *perf_iommu)
21740 {
21741 struct attribute **attrs;
21742- struct attribute_group *attr_group;
21743+ attribute_group_no_const *attr_group;
21744 int i = 0, j;
21745
21746 while (amd_iommu_v2_event_descs[i].attr.attr.name)
21747diff --git a/arch/x86/kernel/cpu/perf_event_intel.c b/arch/x86/kernel/cpu/perf_event_intel.c
21748index 944bf01..4a4392f 100644
21749--- a/arch/x86/kernel/cpu/perf_event_intel.c
21750+++ b/arch/x86/kernel/cpu/perf_event_intel.c
21751@@ -2353,10 +2353,10 @@ __init int intel_pmu_init(void)
21752 x86_pmu.num_counters_fixed = max((int)edx.split.num_counters_fixed, 3);
21753
21754 if (boot_cpu_has(X86_FEATURE_PDCM)) {
21755- u64 capabilities;
21756+ u64 capabilities = x86_pmu.intel_cap.capabilities;
21757
21758- rdmsrl(MSR_IA32_PERF_CAPABILITIES, capabilities);
21759- x86_pmu.intel_cap.capabilities = capabilities;
21760+ if (rdmsrl_safe(MSR_IA32_PERF_CAPABILITIES, &x86_pmu.intel_cap.capabilities))
21761+ x86_pmu.intel_cap.capabilities = capabilities;
21762 }
21763
21764 intel_ds_init();
21765diff --git a/arch/x86/kernel/cpu/perf_event_intel_rapl.c b/arch/x86/kernel/cpu/perf_event_intel_rapl.c
21766index d64f275..26522ff 100644
21767--- a/arch/x86/kernel/cpu/perf_event_intel_rapl.c
21768+++ b/arch/x86/kernel/cpu/perf_event_intel_rapl.c
21769@@ -449,7 +449,7 @@ static struct attribute *rapl_events_hsw_attr[] = {
21770 NULL,
21771 };
21772
21773-static struct attribute_group rapl_pmu_events_group = {
21774+static attribute_group_no_const rapl_pmu_events_group __read_only = {
21775 .name = "events",
21776 .attrs = NULL, /* patched at runtime */
21777 };
21778diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.c b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
21779index e98f68c..1992b15 100644
21780--- a/arch/x86/kernel/cpu/perf_event_intel_uncore.c
21781+++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
21782@@ -737,7 +737,7 @@ static void __init uncore_types_exit(struct intel_uncore_type **types)
21783 static int __init uncore_type_init(struct intel_uncore_type *type)
21784 {
21785 struct intel_uncore_pmu *pmus;
21786- struct attribute_group *attr_group;
21787+ attribute_group_no_const *attr_group;
21788 struct attribute **attrs;
21789 int i, j;
21790
21791diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.h b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
21792index 863d9b0..6289b63 100644
21793--- a/arch/x86/kernel/cpu/perf_event_intel_uncore.h
21794+++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
21795@@ -114,7 +114,7 @@ struct intel_uncore_box {
21796 struct uncore_event_desc {
21797 struct kobj_attribute attr;
21798 const char *config;
21799-};
21800+} __do_const;
21801
21802 ssize_t uncore_event_show(struct kobject *kobj,
21803 struct kobj_attribute *attr, char *buf);
21804diff --git a/arch/x86/kernel/cpuid.c b/arch/x86/kernel/cpuid.c
21805index 3225ae6c..ee3c6db 100644
21806--- a/arch/x86/kernel/cpuid.c
21807+++ b/arch/x86/kernel/cpuid.c
21808@@ -170,7 +170,7 @@ static int cpuid_class_cpu_callback(struct notifier_block *nfb,
21809 return notifier_from_errno(err);
21810 }
21811
21812-static struct notifier_block __refdata cpuid_class_cpu_notifier =
21813+static struct notifier_block cpuid_class_cpu_notifier =
21814 {
21815 .notifier_call = cpuid_class_cpu_callback,
21816 };
21817diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
21818index f5ab56d..d3b201a 100644
21819--- a/arch/x86/kernel/crash.c
21820+++ b/arch/x86/kernel/crash.c
21821@@ -104,7 +104,7 @@ static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
21822 #ifdef CONFIG_X86_32
21823 struct pt_regs fixed_regs;
21824
21825- if (!user_mode_vm(regs)) {
21826+ if (!user_mode(regs)) {
21827 crash_fixup_ss_esp(&fixed_regs, regs);
21828 regs = &fixed_regs;
21829 }
21830diff --git a/arch/x86/kernel/crash_dump_64.c b/arch/x86/kernel/crash_dump_64.c
21831index afa64ad..dce67dd 100644
21832--- a/arch/x86/kernel/crash_dump_64.c
21833+++ b/arch/x86/kernel/crash_dump_64.c
21834@@ -36,7 +36,7 @@ ssize_t copy_oldmem_page(unsigned long pfn, char *buf,
21835 return -ENOMEM;
21836
21837 if (userbuf) {
21838- if (copy_to_user(buf, vaddr + offset, csize)) {
21839+ if (copy_to_user((char __force_user *)buf, vaddr + offset, csize)) {
21840 iounmap(vaddr);
21841 return -EFAULT;
21842 }
21843diff --git a/arch/x86/kernel/doublefault.c b/arch/x86/kernel/doublefault.c
21844index f6dfd93..892ade4 100644
21845--- a/arch/x86/kernel/doublefault.c
21846+++ b/arch/x86/kernel/doublefault.c
21847@@ -12,7 +12,7 @@
21848
21849 #define DOUBLEFAULT_STACKSIZE (1024)
21850 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
21851-#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
21852+#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
21853
21854 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
21855
21856@@ -22,7 +22,7 @@ static void doublefault_fn(void)
21857 unsigned long gdt, tss;
21858
21859 native_store_gdt(&gdt_desc);
21860- gdt = gdt_desc.address;
21861+ gdt = (unsigned long)gdt_desc.address;
21862
21863 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
21864
21865@@ -59,10 +59,10 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
21866 /* 0x2 bit is always set */
21867 .flags = X86_EFLAGS_SF | 0x2,
21868 .sp = STACK_START,
21869- .es = __USER_DS,
21870+ .es = __KERNEL_DS,
21871 .cs = __KERNEL_CS,
21872 .ss = __KERNEL_DS,
21873- .ds = __USER_DS,
21874+ .ds = __KERNEL_DS,
21875 .fs = __KERNEL_PERCPU,
21876
21877 .__cr3 = __pa_nodebug(swapper_pg_dir),
21878diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
21879index b74ebc7..2c95874 100644
21880--- a/arch/x86/kernel/dumpstack.c
21881+++ b/arch/x86/kernel/dumpstack.c
21882@@ -2,6 +2,9 @@
21883 * Copyright (C) 1991, 1992 Linus Torvalds
21884 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
21885 */
21886+#ifdef CONFIG_GRKERNSEC_HIDESYM
21887+#define __INCLUDED_BY_HIDESYM 1
21888+#endif
21889 #include <linux/kallsyms.h>
21890 #include <linux/kprobes.h>
21891 #include <linux/uaccess.h>
21892@@ -33,23 +36,21 @@ static void printk_stack_address(unsigned long address, int reliable)
21893
21894 void printk_address(unsigned long address)
21895 {
21896- pr_cont(" [<%p>] %pS\n", (void *)address, (void *)address);
21897+ pr_cont(" [<%p>] %pA\n", (void *)address, (void *)address);
21898 }
21899
21900 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
21901 static void
21902 print_ftrace_graph_addr(unsigned long addr, void *data,
21903 const struct stacktrace_ops *ops,
21904- struct thread_info *tinfo, int *graph)
21905+ struct task_struct *task, int *graph)
21906 {
21907- struct task_struct *task;
21908 unsigned long ret_addr;
21909 int index;
21910
21911 if (addr != (unsigned long)return_to_handler)
21912 return;
21913
21914- task = tinfo->task;
21915 index = task->curr_ret_stack;
21916
21917 if (!task->ret_stack || index < *graph)
21918@@ -66,7 +67,7 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
21919 static inline void
21920 print_ftrace_graph_addr(unsigned long addr, void *data,
21921 const struct stacktrace_ops *ops,
21922- struct thread_info *tinfo, int *graph)
21923+ struct task_struct *task, int *graph)
21924 { }
21925 #endif
21926
21927@@ -77,10 +78,8 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
21928 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
21929 */
21930
21931-static inline int valid_stack_ptr(struct thread_info *tinfo,
21932- void *p, unsigned int size, void *end)
21933+static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
21934 {
21935- void *t = tinfo;
21936 if (end) {
21937 if (p < end && p >= (end-THREAD_SIZE))
21938 return 1;
21939@@ -91,14 +90,14 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
21940 }
21941
21942 unsigned long
21943-print_context_stack(struct thread_info *tinfo,
21944+print_context_stack(struct task_struct *task, void *stack_start,
21945 unsigned long *stack, unsigned long bp,
21946 const struct stacktrace_ops *ops, void *data,
21947 unsigned long *end, int *graph)
21948 {
21949 struct stack_frame *frame = (struct stack_frame *)bp;
21950
21951- while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
21952+ while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
21953 unsigned long addr;
21954
21955 addr = *stack;
21956@@ -110,7 +109,7 @@ print_context_stack(struct thread_info *tinfo,
21957 } else {
21958 ops->address(data, addr, 0);
21959 }
21960- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
21961+ print_ftrace_graph_addr(addr, data, ops, task, graph);
21962 }
21963 stack++;
21964 }
21965@@ -119,7 +118,7 @@ print_context_stack(struct thread_info *tinfo,
21966 EXPORT_SYMBOL_GPL(print_context_stack);
21967
21968 unsigned long
21969-print_context_stack_bp(struct thread_info *tinfo,
21970+print_context_stack_bp(struct task_struct *task, void *stack_start,
21971 unsigned long *stack, unsigned long bp,
21972 const struct stacktrace_ops *ops, void *data,
21973 unsigned long *end, int *graph)
21974@@ -127,7 +126,7 @@ print_context_stack_bp(struct thread_info *tinfo,
21975 struct stack_frame *frame = (struct stack_frame *)bp;
21976 unsigned long *ret_addr = &frame->return_address;
21977
21978- while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
21979+ while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
21980 unsigned long addr = *ret_addr;
21981
21982 if (!__kernel_text_address(addr))
21983@@ -136,7 +135,7 @@ print_context_stack_bp(struct thread_info *tinfo,
21984 ops->address(data, addr, 1);
21985 frame = frame->next_frame;
21986 ret_addr = &frame->return_address;
21987- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
21988+ print_ftrace_graph_addr(addr, data, ops, task, graph);
21989 }
21990
21991 return (unsigned long)frame;
21992@@ -155,7 +154,7 @@ static int print_trace_stack(void *data, char *name)
21993 static void print_trace_address(void *data, unsigned long addr, int reliable)
21994 {
21995 touch_nmi_watchdog();
21996- printk(data);
21997+ printk("%s", (char *)data);
21998 printk_stack_address(addr, reliable);
21999 }
22000
22001@@ -225,6 +224,8 @@ unsigned long oops_begin(void)
22002 EXPORT_SYMBOL_GPL(oops_begin);
22003 NOKPROBE_SYMBOL(oops_begin);
22004
22005+extern void gr_handle_kernel_exploit(void);
22006+
22007 void oops_end(unsigned long flags, struct pt_regs *regs, int signr)
22008 {
22009 if (regs && kexec_should_crash(current))
22010@@ -246,7 +247,10 @@ void oops_end(unsigned long flags, struct pt_regs *regs, int signr)
22011 panic("Fatal exception in interrupt");
22012 if (panic_on_oops)
22013 panic("Fatal exception");
22014- do_exit(signr);
22015+
22016+ gr_handle_kernel_exploit();
22017+
22018+ do_group_exit(signr);
22019 }
22020 NOKPROBE_SYMBOL(oops_end);
22021
22022@@ -275,7 +279,7 @@ int __die(const char *str, struct pt_regs *regs, long err)
22023 print_modules();
22024 show_regs(regs);
22025 #ifdef CONFIG_X86_32
22026- if (user_mode_vm(regs)) {
22027+ if (user_mode(regs)) {
22028 sp = regs->sp;
22029 ss = regs->ss & 0xffff;
22030 } else {
22031@@ -304,7 +308,7 @@ void die(const char *str, struct pt_regs *regs, long err)
22032 unsigned long flags = oops_begin();
22033 int sig = SIGSEGV;
22034
22035- if (!user_mode_vm(regs))
22036+ if (!user_mode(regs))
22037 report_bug(regs->ip, regs);
22038
22039 if (__die(str, regs, err))
22040diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
22041index 5abd4cd..c65733b 100644
22042--- a/arch/x86/kernel/dumpstack_32.c
22043+++ b/arch/x86/kernel/dumpstack_32.c
22044@@ -61,15 +61,14 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22045 bp = stack_frame(task, regs);
22046
22047 for (;;) {
22048- struct thread_info *context;
22049+ void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
22050 void *end_stack;
22051
22052 end_stack = is_hardirq_stack(stack, cpu);
22053 if (!end_stack)
22054 end_stack = is_softirq_stack(stack, cpu);
22055
22056- context = task_thread_info(task);
22057- bp = ops->walk_stack(context, stack, bp, ops, data,
22058+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data,
22059 end_stack, &graph);
22060
22061 /* Stop if not on irq stack */
22062@@ -123,27 +122,28 @@ void show_regs(struct pt_regs *regs)
22063 int i;
22064
22065 show_regs_print_info(KERN_EMERG);
22066- __show_regs(regs, !user_mode_vm(regs));
22067+ __show_regs(regs, !user_mode(regs));
22068
22069 /*
22070 * When in-kernel, we also print out the stack and code at the
22071 * time of the fault..
22072 */
22073- if (!user_mode_vm(regs)) {
22074+ if (!user_mode(regs)) {
22075 unsigned int code_prologue = code_bytes * 43 / 64;
22076 unsigned int code_len = code_bytes;
22077 unsigned char c;
22078 u8 *ip;
22079+ unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(0)[(0xffff & regs->cs) >> 3]);
22080
22081 pr_emerg("Stack:\n");
22082 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
22083
22084 pr_emerg("Code:");
22085
22086- ip = (u8 *)regs->ip - code_prologue;
22087+ ip = (u8 *)regs->ip - code_prologue + cs_base;
22088 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
22089 /* try starting at IP */
22090- ip = (u8 *)regs->ip;
22091+ ip = (u8 *)regs->ip + cs_base;
22092 code_len = code_len - code_prologue + 1;
22093 }
22094 for (i = 0; i < code_len; i++, ip++) {
22095@@ -152,7 +152,7 @@ void show_regs(struct pt_regs *regs)
22096 pr_cont(" Bad EIP value.");
22097 break;
22098 }
22099- if (ip == (u8 *)regs->ip)
22100+ if (ip == (u8 *)regs->ip + cs_base)
22101 pr_cont(" <%02x>", c);
22102 else
22103 pr_cont(" %02x", c);
22104@@ -165,6 +165,7 @@ int is_valid_bugaddr(unsigned long ip)
22105 {
22106 unsigned short ud2;
22107
22108+ ip = ktla_ktva(ip);
22109 if (ip < PAGE_OFFSET)
22110 return 0;
22111 if (probe_kernel_address((unsigned short *)ip, ud2))
22112@@ -172,3 +173,15 @@ int is_valid_bugaddr(unsigned long ip)
22113
22114 return ud2 == 0x0b0f;
22115 }
22116+
22117+#if defined(CONFIG_PAX_MEMORY_STACKLEAK) || defined(CONFIG_PAX_USERCOPY)
22118+void pax_check_alloca(unsigned long size)
22119+{
22120+ unsigned long sp = (unsigned long)&sp, stack_left;
22121+
22122+ /* all kernel stacks are of the same size */
22123+ stack_left = sp & (THREAD_SIZE - 1);
22124+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
22125+}
22126+EXPORT_SYMBOL(pax_check_alloca);
22127+#endif
22128diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
22129index ff86f19..a20c62c 100644
22130--- a/arch/x86/kernel/dumpstack_64.c
22131+++ b/arch/x86/kernel/dumpstack_64.c
22132@@ -153,12 +153,12 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22133 const struct stacktrace_ops *ops, void *data)
22134 {
22135 const unsigned cpu = get_cpu();
22136- struct thread_info *tinfo;
22137 unsigned long *irq_stack = (unsigned long *)per_cpu(irq_stack_ptr, cpu);
22138 unsigned long dummy;
22139 unsigned used = 0;
22140 int graph = 0;
22141 int done = 0;
22142+ void *stack_start;
22143
22144 if (!task)
22145 task = current;
22146@@ -179,7 +179,6 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22147 * current stack address. If the stacks consist of nested
22148 * exceptions
22149 */
22150- tinfo = task_thread_info(task);
22151 while (!done) {
22152 unsigned long *stack_end;
22153 enum stack_type stype;
22154@@ -202,7 +201,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22155 if (ops->stack(data, id) < 0)
22156 break;
22157
22158- bp = ops->walk_stack(tinfo, stack, bp, ops,
22159+ bp = ops->walk_stack(task, stack_end - EXCEPTION_STKSZ, stack, bp, ops,
22160 data, stack_end, &graph);
22161 ops->stack(data, "<EOE>");
22162 /*
22163@@ -210,6 +209,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22164 * second-to-last pointer (index -2 to end) in the
22165 * exception stack:
22166 */
22167+ if ((u16)stack_end[-1] != __KERNEL_DS)
22168+ goto out;
22169 stack = (unsigned long *) stack_end[-2];
22170 done = 0;
22171 break;
22172@@ -218,7 +219,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22173
22174 if (ops->stack(data, "IRQ") < 0)
22175 break;
22176- bp = ops->walk_stack(tinfo, stack, bp,
22177+ bp = ops->walk_stack(task, irq_stack, stack, bp,
22178 ops, data, stack_end, &graph);
22179 /*
22180 * We link to the next stack (which would be
22181@@ -240,7 +241,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22182 /*
22183 * This handles the process stack:
22184 */
22185- bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
22186+ stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
22187+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
22188+out:
22189 put_cpu();
22190 }
22191 EXPORT_SYMBOL(dump_trace);
22192@@ -349,3 +352,50 @@ int is_valid_bugaddr(unsigned long ip)
22193
22194 return ud2 == 0x0b0f;
22195 }
22196+
22197+#if defined(CONFIG_PAX_MEMORY_STACKLEAK) || defined(CONFIG_PAX_USERCOPY)
22198+void pax_check_alloca(unsigned long size)
22199+{
22200+ unsigned long sp = (unsigned long)&sp, stack_start, stack_end;
22201+ unsigned cpu, used;
22202+ char *id;
22203+
22204+ /* check the process stack first */
22205+ stack_start = (unsigned long)task_stack_page(current);
22206+ stack_end = stack_start + THREAD_SIZE;
22207+ if (likely(stack_start <= sp && sp < stack_end)) {
22208+ unsigned long stack_left = sp & (THREAD_SIZE - 1);
22209+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
22210+ return;
22211+ }
22212+
22213+ cpu = get_cpu();
22214+
22215+ /* check the irq stacks */
22216+ stack_end = (unsigned long)per_cpu(irq_stack_ptr, cpu);
22217+ stack_start = stack_end - IRQ_STACK_SIZE;
22218+ if (stack_start <= sp && sp < stack_end) {
22219+ unsigned long stack_left = sp & (IRQ_STACK_SIZE - 1);
22220+ put_cpu();
22221+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
22222+ return;
22223+ }
22224+
22225+ /* check the exception stacks */
22226+ used = 0;
22227+ stack_end = (unsigned long)in_exception_stack(cpu, sp, &used, &id);
22228+ stack_start = stack_end - EXCEPTION_STKSZ;
22229+ if (stack_end && stack_start <= sp && sp < stack_end) {
22230+ unsigned long stack_left = sp & (EXCEPTION_STKSZ - 1);
22231+ put_cpu();
22232+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
22233+ return;
22234+ }
22235+
22236+ put_cpu();
22237+
22238+ /* unknown stack */
22239+ BUG();
22240+}
22241+EXPORT_SYMBOL(pax_check_alloca);
22242+#endif
22243diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c
22244index 49f8864..1cc6d07 100644
22245--- a/arch/x86/kernel/e820.c
22246+++ b/arch/x86/kernel/e820.c
22247@@ -802,8 +802,8 @@ unsigned long __init e820_end_of_low_ram_pfn(void)
22248
22249 static void early_panic(char *msg)
22250 {
22251- early_printk(msg);
22252- panic(msg);
22253+ early_printk("%s", msg);
22254+ panic("%s", msg);
22255 }
22256
22257 static int userdef __initdata;
22258diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
22259index 01d1c18..8073693 100644
22260--- a/arch/x86/kernel/early_printk.c
22261+++ b/arch/x86/kernel/early_printk.c
22262@@ -7,6 +7,7 @@
22263 #include <linux/pci_regs.h>
22264 #include <linux/pci_ids.h>
22265 #include <linux/errno.h>
22266+#include <linux/sched.h>
22267 #include <asm/io.h>
22268 #include <asm/processor.h>
22269 #include <asm/fcntl.h>
22270diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
22271index 344b63f..55adf14 100644
22272--- a/arch/x86/kernel/entry_32.S
22273+++ b/arch/x86/kernel/entry_32.S
22274@@ -177,13 +177,154 @@
22275 /*CFI_REL_OFFSET gs, PT_GS*/
22276 .endm
22277 .macro SET_KERNEL_GS reg
22278+
22279+#ifdef CONFIG_CC_STACKPROTECTOR
22280 movl $(__KERNEL_STACK_CANARY), \reg
22281+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
22282+ movl $(__USER_DS), \reg
22283+#else
22284+ xorl \reg, \reg
22285+#endif
22286+
22287 movl \reg, %gs
22288 .endm
22289
22290 #endif /* CONFIG_X86_32_LAZY_GS */
22291
22292-.macro SAVE_ALL
22293+.macro pax_enter_kernel
22294+#ifdef CONFIG_PAX_KERNEXEC
22295+ call pax_enter_kernel
22296+#endif
22297+.endm
22298+
22299+.macro pax_exit_kernel
22300+#ifdef CONFIG_PAX_KERNEXEC
22301+ call pax_exit_kernel
22302+#endif
22303+.endm
22304+
22305+#ifdef CONFIG_PAX_KERNEXEC
22306+ENTRY(pax_enter_kernel)
22307+#ifdef CONFIG_PARAVIRT
22308+ pushl %eax
22309+ pushl %ecx
22310+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
22311+ mov %eax, %esi
22312+#else
22313+ mov %cr0, %esi
22314+#endif
22315+ bts $16, %esi
22316+ jnc 1f
22317+ mov %cs, %esi
22318+ cmp $__KERNEL_CS, %esi
22319+ jz 3f
22320+ ljmp $__KERNEL_CS, $3f
22321+1: ljmp $__KERNEXEC_KERNEL_CS, $2f
22322+2:
22323+#ifdef CONFIG_PARAVIRT
22324+ mov %esi, %eax
22325+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
22326+#else
22327+ mov %esi, %cr0
22328+#endif
22329+3:
22330+#ifdef CONFIG_PARAVIRT
22331+ popl %ecx
22332+ popl %eax
22333+#endif
22334+ ret
22335+ENDPROC(pax_enter_kernel)
22336+
22337+ENTRY(pax_exit_kernel)
22338+#ifdef CONFIG_PARAVIRT
22339+ pushl %eax
22340+ pushl %ecx
22341+#endif
22342+ mov %cs, %esi
22343+ cmp $__KERNEXEC_KERNEL_CS, %esi
22344+ jnz 2f
22345+#ifdef CONFIG_PARAVIRT
22346+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
22347+ mov %eax, %esi
22348+#else
22349+ mov %cr0, %esi
22350+#endif
22351+ btr $16, %esi
22352+ ljmp $__KERNEL_CS, $1f
22353+1:
22354+#ifdef CONFIG_PARAVIRT
22355+ mov %esi, %eax
22356+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
22357+#else
22358+ mov %esi, %cr0
22359+#endif
22360+2:
22361+#ifdef CONFIG_PARAVIRT
22362+ popl %ecx
22363+ popl %eax
22364+#endif
22365+ ret
22366+ENDPROC(pax_exit_kernel)
22367+#endif
22368+
22369+ .macro pax_erase_kstack
22370+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
22371+ call pax_erase_kstack
22372+#endif
22373+ .endm
22374+
22375+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
22376+/*
22377+ * ebp: thread_info
22378+ */
22379+ENTRY(pax_erase_kstack)
22380+ pushl %edi
22381+ pushl %ecx
22382+ pushl %eax
22383+
22384+ mov TI_lowest_stack(%ebp), %edi
22385+ mov $-0xBEEF, %eax
22386+ std
22387+
22388+1: mov %edi, %ecx
22389+ and $THREAD_SIZE_asm - 1, %ecx
22390+ shr $2, %ecx
22391+ repne scasl
22392+ jecxz 2f
22393+
22394+ cmp $2*16, %ecx
22395+ jc 2f
22396+
22397+ mov $2*16, %ecx
22398+ repe scasl
22399+ jecxz 2f
22400+ jne 1b
22401+
22402+2: cld
22403+ or $2*4, %edi
22404+ mov %esp, %ecx
22405+ sub %edi, %ecx
22406+
22407+ cmp $THREAD_SIZE_asm, %ecx
22408+ jb 3f
22409+ ud2
22410+3:
22411+
22412+ shr $2, %ecx
22413+ rep stosl
22414+
22415+ mov TI_task_thread_sp0(%ebp), %edi
22416+ sub $128, %edi
22417+ mov %edi, TI_lowest_stack(%ebp)
22418+
22419+ popl %eax
22420+ popl %ecx
22421+ popl %edi
22422+ ret
22423+ENDPROC(pax_erase_kstack)
22424+#endif
22425+
22426+.macro __SAVE_ALL _DS
22427 cld
22428 PUSH_GS
22429 pushl_cfi %fs
22430@@ -206,7 +347,7 @@
22431 CFI_REL_OFFSET ecx, 0
22432 pushl_cfi %ebx
22433 CFI_REL_OFFSET ebx, 0
22434- movl $(__USER_DS), %edx
22435+ movl $\_DS, %edx
22436 movl %edx, %ds
22437 movl %edx, %es
22438 movl $(__KERNEL_PERCPU), %edx
22439@@ -214,6 +355,15 @@
22440 SET_KERNEL_GS %edx
22441 .endm
22442
22443+.macro SAVE_ALL
22444+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
22445+ __SAVE_ALL __KERNEL_DS
22446+ pax_enter_kernel
22447+#else
22448+ __SAVE_ALL __USER_DS
22449+#endif
22450+.endm
22451+
22452 .macro RESTORE_INT_REGS
22453 popl_cfi %ebx
22454 CFI_RESTORE ebx
22455@@ -297,7 +447,7 @@ ENTRY(ret_from_fork)
22456 popfl_cfi
22457 jmp syscall_exit
22458 CFI_ENDPROC
22459-END(ret_from_fork)
22460+ENDPROC(ret_from_fork)
22461
22462 ENTRY(ret_from_kernel_thread)
22463 CFI_STARTPROC
22464@@ -340,7 +490,15 @@ ret_from_intr:
22465 andl $SEGMENT_RPL_MASK, %eax
22466 #endif
22467 cmpl $USER_RPL, %eax
22468+
22469+#ifdef CONFIG_PAX_KERNEXEC
22470+ jae resume_userspace
22471+
22472+ pax_exit_kernel
22473+ jmp resume_kernel
22474+#else
22475 jb resume_kernel # not returning to v8086 or userspace
22476+#endif
22477
22478 ENTRY(resume_userspace)
22479 LOCKDEP_SYS_EXIT
22480@@ -352,8 +510,8 @@ ENTRY(resume_userspace)
22481 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
22482 # int/exception return?
22483 jne work_pending
22484- jmp restore_all
22485-END(ret_from_exception)
22486+ jmp restore_all_pax
22487+ENDPROC(ret_from_exception)
22488
22489 #ifdef CONFIG_PREEMPT
22490 ENTRY(resume_kernel)
22491@@ -365,7 +523,7 @@ need_resched:
22492 jz restore_all
22493 call preempt_schedule_irq
22494 jmp need_resched
22495-END(resume_kernel)
22496+ENDPROC(resume_kernel)
22497 #endif
22498 CFI_ENDPROC
22499
22500@@ -395,30 +553,45 @@ sysenter_past_esp:
22501 /*CFI_REL_OFFSET cs, 0*/
22502 /*
22503 * Push current_thread_info()->sysenter_return to the stack.
22504- * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
22505- * pushed above; +8 corresponds to copy_thread's esp0 setting.
22506 */
22507- pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
22508+ pushl_cfi $0
22509 CFI_REL_OFFSET eip, 0
22510
22511 pushl_cfi %eax
22512 SAVE_ALL
22513+ GET_THREAD_INFO(%ebp)
22514+ movl TI_sysenter_return(%ebp),%ebp
22515+ movl %ebp,PT_EIP(%esp)
22516 ENABLE_INTERRUPTS(CLBR_NONE)
22517
22518 /*
22519 * Load the potential sixth argument from user stack.
22520 * Careful about security.
22521 */
22522+ movl PT_OLDESP(%esp),%ebp
22523+
22524+#ifdef CONFIG_PAX_MEMORY_UDEREF
22525+ mov PT_OLDSS(%esp),%ds
22526+1: movl %ds:(%ebp),%ebp
22527+ push %ss
22528+ pop %ds
22529+#else
22530 cmpl $__PAGE_OFFSET-3,%ebp
22531 jae syscall_fault
22532 ASM_STAC
22533 1: movl (%ebp),%ebp
22534 ASM_CLAC
22535+#endif
22536+
22537 movl %ebp,PT_EBP(%esp)
22538 _ASM_EXTABLE(1b,syscall_fault)
22539
22540 GET_THREAD_INFO(%ebp)
22541
22542+#ifdef CONFIG_PAX_RANDKSTACK
22543+ pax_erase_kstack
22544+#endif
22545+
22546 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
22547 jnz sysenter_audit
22548 sysenter_do_call:
22549@@ -434,12 +607,24 @@ sysenter_after_call:
22550 testl $_TIF_ALLWORK_MASK, %ecx
22551 jne sysexit_audit
22552 sysenter_exit:
22553+
22554+#ifdef CONFIG_PAX_RANDKSTACK
22555+ pushl_cfi %eax
22556+ movl %esp, %eax
22557+ call pax_randomize_kstack
22558+ popl_cfi %eax
22559+#endif
22560+
22561+ pax_erase_kstack
22562+
22563 /* if something modifies registers it must also disable sysexit */
22564 movl PT_EIP(%esp), %edx
22565 movl PT_OLDESP(%esp), %ecx
22566 xorl %ebp,%ebp
22567 TRACE_IRQS_ON
22568 1: mov PT_FS(%esp), %fs
22569+2: mov PT_DS(%esp), %ds
22570+3: mov PT_ES(%esp), %es
22571 PTGS_TO_GS
22572 ENABLE_INTERRUPTS_SYSEXIT
22573
22574@@ -453,6 +638,9 @@ sysenter_audit:
22575 pushl_cfi PT_ESI(%esp) /* a3: 5th arg */
22576 pushl_cfi PT_EDX+4(%esp) /* a2: 4th arg */
22577 call __audit_syscall_entry
22578+
22579+ pax_erase_kstack
22580+
22581 popl_cfi %ecx /* get that remapped edx off the stack */
22582 popl_cfi %ecx /* get that remapped esi off the stack */
22583 movl PT_EAX(%esp),%eax /* reload syscall number */
22584@@ -479,10 +667,16 @@ sysexit_audit:
22585
22586 CFI_ENDPROC
22587 .pushsection .fixup,"ax"
22588-2: movl $0,PT_FS(%esp)
22589+4: movl $0,PT_FS(%esp)
22590+ jmp 1b
22591+5: movl $0,PT_DS(%esp)
22592+ jmp 1b
22593+6: movl $0,PT_ES(%esp)
22594 jmp 1b
22595 .popsection
22596- _ASM_EXTABLE(1b,2b)
22597+ _ASM_EXTABLE(1b,4b)
22598+ _ASM_EXTABLE(2b,5b)
22599+ _ASM_EXTABLE(3b,6b)
22600 PTGS_TO_GS_EX
22601 ENDPROC(ia32_sysenter_target)
22602
22603@@ -493,6 +687,11 @@ ENTRY(system_call)
22604 pushl_cfi %eax # save orig_eax
22605 SAVE_ALL
22606 GET_THREAD_INFO(%ebp)
22607+
22608+#ifdef CONFIG_PAX_RANDKSTACK
22609+ pax_erase_kstack
22610+#endif
22611+
22612 # system call tracing in operation / emulation
22613 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
22614 jnz syscall_trace_entry
22615@@ -512,6 +711,15 @@ syscall_exit:
22616 testl $_TIF_ALLWORK_MASK, %ecx # current->work
22617 jne syscall_exit_work
22618
22619+restore_all_pax:
22620+
22621+#ifdef CONFIG_PAX_RANDKSTACK
22622+ movl %esp, %eax
22623+ call pax_randomize_kstack
22624+#endif
22625+
22626+ pax_erase_kstack
22627+
22628 restore_all:
22629 TRACE_IRQS_IRET
22630 restore_all_notrace:
22631@@ -566,14 +774,34 @@ ldt_ss:
22632 * compensating for the offset by changing to the ESPFIX segment with
22633 * a base address that matches for the difference.
22634 */
22635-#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
22636+#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
22637 mov %esp, %edx /* load kernel esp */
22638 mov PT_OLDESP(%esp), %eax /* load userspace esp */
22639 mov %dx, %ax /* eax: new kernel esp */
22640 sub %eax, %edx /* offset (low word is 0) */
22641+#ifdef CONFIG_SMP
22642+ movl PER_CPU_VAR(cpu_number), %ebx
22643+ shll $PAGE_SHIFT_asm, %ebx
22644+ addl $cpu_gdt_table, %ebx
22645+#else
22646+ movl $cpu_gdt_table, %ebx
22647+#endif
22648 shr $16, %edx
22649- mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
22650- mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
22651+
22652+#ifdef CONFIG_PAX_KERNEXEC
22653+ mov %cr0, %esi
22654+ btr $16, %esi
22655+ mov %esi, %cr0
22656+#endif
22657+
22658+ mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
22659+ mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
22660+
22661+#ifdef CONFIG_PAX_KERNEXEC
22662+ bts $16, %esi
22663+ mov %esi, %cr0
22664+#endif
22665+
22666 pushl_cfi $__ESPFIX_SS
22667 pushl_cfi %eax /* new kernel esp */
22668 /* Disable interrupts, but do not irqtrace this section: we
22669@@ -603,20 +831,18 @@ work_resched:
22670 movl TI_flags(%ebp), %ecx
22671 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
22672 # than syscall tracing?
22673- jz restore_all
22674+ jz restore_all_pax
22675 testb $_TIF_NEED_RESCHED, %cl
22676 jnz work_resched
22677
22678 work_notifysig: # deal with pending signals and
22679 # notify-resume requests
22680+ movl %esp, %eax
22681 #ifdef CONFIG_VM86
22682 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
22683- movl %esp, %eax
22684 jne work_notifysig_v86 # returning to kernel-space or
22685 # vm86-space
22686 1:
22687-#else
22688- movl %esp, %eax
22689 #endif
22690 TRACE_IRQS_ON
22691 ENABLE_INTERRUPTS(CLBR_NONE)
22692@@ -637,7 +863,7 @@ work_notifysig_v86:
22693 movl %eax, %esp
22694 jmp 1b
22695 #endif
22696-END(work_pending)
22697+ENDPROC(work_pending)
22698
22699 # perform syscall exit tracing
22700 ALIGN
22701@@ -645,11 +871,14 @@ syscall_trace_entry:
22702 movl $-ENOSYS,PT_EAX(%esp)
22703 movl %esp, %eax
22704 call syscall_trace_enter
22705+
22706+ pax_erase_kstack
22707+
22708 /* What it returned is what we'll actually use. */
22709 cmpl $(NR_syscalls), %eax
22710 jnae syscall_call
22711 jmp syscall_exit
22712-END(syscall_trace_entry)
22713+ENDPROC(syscall_trace_entry)
22714
22715 # perform syscall exit tracing
22716 ALIGN
22717@@ -662,26 +891,30 @@ syscall_exit_work:
22718 movl %esp, %eax
22719 call syscall_trace_leave
22720 jmp resume_userspace
22721-END(syscall_exit_work)
22722+ENDPROC(syscall_exit_work)
22723 CFI_ENDPROC
22724
22725 RING0_INT_FRAME # can't unwind into user space anyway
22726 syscall_fault:
22727+#ifdef CONFIG_PAX_MEMORY_UDEREF
22728+ push %ss
22729+ pop %ds
22730+#endif
22731 ASM_CLAC
22732 GET_THREAD_INFO(%ebp)
22733 movl $-EFAULT,PT_EAX(%esp)
22734 jmp resume_userspace
22735-END(syscall_fault)
22736+ENDPROC(syscall_fault)
22737
22738 syscall_badsys:
22739 movl $-ENOSYS,%eax
22740 jmp syscall_after_call
22741-END(syscall_badsys)
22742+ENDPROC(syscall_badsys)
22743
22744 sysenter_badsys:
22745 movl $-ENOSYS,%eax
22746 jmp sysenter_after_call
22747-END(sysenter_badsys)
22748+ENDPROC(sysenter_badsys)
22749 CFI_ENDPROC
22750
22751 .macro FIXUP_ESPFIX_STACK
22752@@ -694,8 +927,15 @@ END(sysenter_badsys)
22753 */
22754 #ifdef CONFIG_X86_ESPFIX32
22755 /* fixup the stack */
22756- mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
22757- mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
22758+#ifdef CONFIG_SMP
22759+ movl PER_CPU_VAR(cpu_number), %ebx
22760+ shll $PAGE_SHIFT_asm, %ebx
22761+ addl $cpu_gdt_table, %ebx
22762+#else
22763+ movl $cpu_gdt_table, %ebx
22764+#endif
22765+ mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
22766+ mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
22767 shl $16, %eax
22768 addl %esp, %eax /* the adjusted stack pointer */
22769 pushl_cfi $__KERNEL_DS
22770@@ -751,7 +991,7 @@ vector=vector+1
22771 .endr
22772 2: jmp common_interrupt
22773 .endr
22774-END(irq_entries_start)
22775+ENDPROC(irq_entries_start)
22776
22777 .previous
22778 END(interrupt)
22779@@ -808,7 +1048,7 @@ ENTRY(coprocessor_error)
22780 pushl_cfi $do_coprocessor_error
22781 jmp error_code
22782 CFI_ENDPROC
22783-END(coprocessor_error)
22784+ENDPROC(coprocessor_error)
22785
22786 ENTRY(simd_coprocessor_error)
22787 RING0_INT_FRAME
22788@@ -821,7 +1061,7 @@ ENTRY(simd_coprocessor_error)
22789 .section .altinstructions,"a"
22790 altinstruction_entry 661b, 663f, X86_FEATURE_XMM, 662b-661b, 664f-663f
22791 .previous
22792-.section .altinstr_replacement,"ax"
22793+.section .altinstr_replacement,"a"
22794 663: pushl $do_simd_coprocessor_error
22795 664:
22796 .previous
22797@@ -830,7 +1070,7 @@ ENTRY(simd_coprocessor_error)
22798 #endif
22799 jmp error_code
22800 CFI_ENDPROC
22801-END(simd_coprocessor_error)
22802+ENDPROC(simd_coprocessor_error)
22803
22804 ENTRY(device_not_available)
22805 RING0_INT_FRAME
22806@@ -839,18 +1079,18 @@ ENTRY(device_not_available)
22807 pushl_cfi $do_device_not_available
22808 jmp error_code
22809 CFI_ENDPROC
22810-END(device_not_available)
22811+ENDPROC(device_not_available)
22812
22813 #ifdef CONFIG_PARAVIRT
22814 ENTRY(native_iret)
22815 iret
22816 _ASM_EXTABLE(native_iret, iret_exc)
22817-END(native_iret)
22818+ENDPROC(native_iret)
22819
22820 ENTRY(native_irq_enable_sysexit)
22821 sti
22822 sysexit
22823-END(native_irq_enable_sysexit)
22824+ENDPROC(native_irq_enable_sysexit)
22825 #endif
22826
22827 ENTRY(overflow)
22828@@ -860,7 +1100,7 @@ ENTRY(overflow)
22829 pushl_cfi $do_overflow
22830 jmp error_code
22831 CFI_ENDPROC
22832-END(overflow)
22833+ENDPROC(overflow)
22834
22835 ENTRY(bounds)
22836 RING0_INT_FRAME
22837@@ -869,7 +1109,7 @@ ENTRY(bounds)
22838 pushl_cfi $do_bounds
22839 jmp error_code
22840 CFI_ENDPROC
22841-END(bounds)
22842+ENDPROC(bounds)
22843
22844 ENTRY(invalid_op)
22845 RING0_INT_FRAME
22846@@ -878,7 +1118,7 @@ ENTRY(invalid_op)
22847 pushl_cfi $do_invalid_op
22848 jmp error_code
22849 CFI_ENDPROC
22850-END(invalid_op)
22851+ENDPROC(invalid_op)
22852
22853 ENTRY(coprocessor_segment_overrun)
22854 RING0_INT_FRAME
22855@@ -887,7 +1127,7 @@ ENTRY(coprocessor_segment_overrun)
22856 pushl_cfi $do_coprocessor_segment_overrun
22857 jmp error_code
22858 CFI_ENDPROC
22859-END(coprocessor_segment_overrun)
22860+ENDPROC(coprocessor_segment_overrun)
22861
22862 ENTRY(invalid_TSS)
22863 RING0_EC_FRAME
22864@@ -895,7 +1135,7 @@ ENTRY(invalid_TSS)
22865 pushl_cfi $do_invalid_TSS
22866 jmp error_code
22867 CFI_ENDPROC
22868-END(invalid_TSS)
22869+ENDPROC(invalid_TSS)
22870
22871 ENTRY(segment_not_present)
22872 RING0_EC_FRAME
22873@@ -903,7 +1143,7 @@ ENTRY(segment_not_present)
22874 pushl_cfi $do_segment_not_present
22875 jmp error_code
22876 CFI_ENDPROC
22877-END(segment_not_present)
22878+ENDPROC(segment_not_present)
22879
22880 ENTRY(stack_segment)
22881 RING0_EC_FRAME
22882@@ -911,7 +1151,7 @@ ENTRY(stack_segment)
22883 pushl_cfi $do_stack_segment
22884 jmp error_code
22885 CFI_ENDPROC
22886-END(stack_segment)
22887+ENDPROC(stack_segment)
22888
22889 ENTRY(alignment_check)
22890 RING0_EC_FRAME
22891@@ -919,7 +1159,7 @@ ENTRY(alignment_check)
22892 pushl_cfi $do_alignment_check
22893 jmp error_code
22894 CFI_ENDPROC
22895-END(alignment_check)
22896+ENDPROC(alignment_check)
22897
22898 ENTRY(divide_error)
22899 RING0_INT_FRAME
22900@@ -928,7 +1168,7 @@ ENTRY(divide_error)
22901 pushl_cfi $do_divide_error
22902 jmp error_code
22903 CFI_ENDPROC
22904-END(divide_error)
22905+ENDPROC(divide_error)
22906
22907 #ifdef CONFIG_X86_MCE
22908 ENTRY(machine_check)
22909@@ -938,7 +1178,7 @@ ENTRY(machine_check)
22910 pushl_cfi machine_check_vector
22911 jmp error_code
22912 CFI_ENDPROC
22913-END(machine_check)
22914+ENDPROC(machine_check)
22915 #endif
22916
22917 ENTRY(spurious_interrupt_bug)
22918@@ -948,7 +1188,7 @@ ENTRY(spurious_interrupt_bug)
22919 pushl_cfi $do_spurious_interrupt_bug
22920 jmp error_code
22921 CFI_ENDPROC
22922-END(spurious_interrupt_bug)
22923+ENDPROC(spurious_interrupt_bug)
22924
22925 #ifdef CONFIG_XEN
22926 /* Xen doesn't set %esp to be precisely what the normal sysenter
22927@@ -1054,7 +1294,7 @@ BUILD_INTERRUPT3(hyperv_callback_vector, HYPERVISOR_CALLBACK_VECTOR,
22928
22929 ENTRY(mcount)
22930 ret
22931-END(mcount)
22932+ENDPROC(mcount)
22933
22934 ENTRY(ftrace_caller)
22935 pushl %eax
22936@@ -1084,7 +1324,7 @@ ftrace_graph_call:
22937 .globl ftrace_stub
22938 ftrace_stub:
22939 ret
22940-END(ftrace_caller)
22941+ENDPROC(ftrace_caller)
22942
22943 ENTRY(ftrace_regs_caller)
22944 pushf /* push flags before compare (in cs location) */
22945@@ -1182,7 +1422,7 @@ trace:
22946 popl %ecx
22947 popl %eax
22948 jmp ftrace_stub
22949-END(mcount)
22950+ENDPROC(mcount)
22951 #endif /* CONFIG_DYNAMIC_FTRACE */
22952 #endif /* CONFIG_FUNCTION_TRACER */
22953
22954@@ -1200,7 +1440,7 @@ ENTRY(ftrace_graph_caller)
22955 popl %ecx
22956 popl %eax
22957 ret
22958-END(ftrace_graph_caller)
22959+ENDPROC(ftrace_graph_caller)
22960
22961 .globl return_to_handler
22962 return_to_handler:
22963@@ -1261,15 +1501,18 @@ error_code:
22964 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
22965 REG_TO_PTGS %ecx
22966 SET_KERNEL_GS %ecx
22967- movl $(__USER_DS), %ecx
22968+ movl $(__KERNEL_DS), %ecx
22969 movl %ecx, %ds
22970 movl %ecx, %es
22971+
22972+ pax_enter_kernel
22973+
22974 TRACE_IRQS_OFF
22975 movl %esp,%eax # pt_regs pointer
22976 call *%edi
22977 jmp ret_from_exception
22978 CFI_ENDPROC
22979-END(page_fault)
22980+ENDPROC(page_fault)
22981
22982 /*
22983 * Debug traps and NMI can happen at the one SYSENTER instruction
22984@@ -1312,7 +1555,7 @@ debug_stack_correct:
22985 call do_debug
22986 jmp ret_from_exception
22987 CFI_ENDPROC
22988-END(debug)
22989+ENDPROC(debug)
22990
22991 /*
22992 * NMI is doubly nasty. It can happen _while_ we're handling
22993@@ -1352,6 +1595,9 @@ nmi_stack_correct:
22994 xorl %edx,%edx # zero error code
22995 movl %esp,%eax # pt_regs pointer
22996 call do_nmi
22997+
22998+ pax_exit_kernel
22999+
23000 jmp restore_all_notrace
23001 CFI_ENDPROC
23002
23003@@ -1389,13 +1635,16 @@ nmi_espfix_stack:
23004 FIXUP_ESPFIX_STACK # %eax == %esp
23005 xorl %edx,%edx # zero error code
23006 call do_nmi
23007+
23008+ pax_exit_kernel
23009+
23010 RESTORE_REGS
23011 lss 12+4(%esp), %esp # back to espfix stack
23012 CFI_ADJUST_CFA_OFFSET -24
23013 jmp irq_return
23014 #endif
23015 CFI_ENDPROC
23016-END(nmi)
23017+ENDPROC(nmi)
23018
23019 ENTRY(int3)
23020 RING0_INT_FRAME
23021@@ -1408,14 +1657,14 @@ ENTRY(int3)
23022 call do_int3
23023 jmp ret_from_exception
23024 CFI_ENDPROC
23025-END(int3)
23026+ENDPROC(int3)
23027
23028 ENTRY(general_protection)
23029 RING0_EC_FRAME
23030 pushl_cfi $do_general_protection
23031 jmp error_code
23032 CFI_ENDPROC
23033-END(general_protection)
23034+ENDPROC(general_protection)
23035
23036 #ifdef CONFIG_KVM_GUEST
23037 ENTRY(async_page_fault)
23038@@ -1424,6 +1673,6 @@ ENTRY(async_page_fault)
23039 pushl_cfi $do_async_page_fault
23040 jmp error_code
23041 CFI_ENDPROC
23042-END(async_page_fault)
23043+ENDPROC(async_page_fault)
23044 #endif
23045
23046diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
23047index c0226ab..0d1dc48 100644
23048--- a/arch/x86/kernel/entry_64.S
23049+++ b/arch/x86/kernel/entry_64.S
23050@@ -59,6 +59,8 @@
23051 #include <asm/smap.h>
23052 #include <asm/pgtable_types.h>
23053 #include <linux/err.h>
23054+#include <asm/pgtable.h>
23055+#include <asm/alternative-asm.h>
23056
23057 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
23058 #include <linux/elf-em.h>
23059@@ -81,6 +83,431 @@ ENTRY(native_usergs_sysret64)
23060 ENDPROC(native_usergs_sysret64)
23061 #endif /* CONFIG_PARAVIRT */
23062
23063+ .macro ljmpq sel, off
23064+#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
23065+ .byte 0x48; ljmp *1234f(%rip)
23066+ .pushsection .rodata
23067+ .align 16
23068+ 1234: .quad \off; .word \sel
23069+ .popsection
23070+#else
23071+ pushq $\sel
23072+ pushq $\off
23073+ lretq
23074+#endif
23075+ .endm
23076+
23077+ .macro pax_enter_kernel
23078+ pax_set_fptr_mask
23079+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
23080+ call pax_enter_kernel
23081+#endif
23082+ .endm
23083+
23084+ .macro pax_exit_kernel
23085+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
23086+ call pax_exit_kernel
23087+#endif
23088+
23089+ .endm
23090+
23091+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
23092+ENTRY(pax_enter_kernel)
23093+ pushq %rdi
23094+
23095+#ifdef CONFIG_PARAVIRT
23096+ PV_SAVE_REGS(CLBR_RDI)
23097+#endif
23098+
23099+#ifdef CONFIG_PAX_KERNEXEC
23100+ GET_CR0_INTO_RDI
23101+ bts $16,%rdi
23102+ jnc 3f
23103+ mov %cs,%edi
23104+ cmp $__KERNEL_CS,%edi
23105+ jnz 2f
23106+1:
23107+#endif
23108+
23109+#ifdef CONFIG_PAX_MEMORY_UDEREF
23110+ 661: jmp 111f
23111+ .pushsection .altinstr_replacement, "a"
23112+ 662: ASM_NOP2
23113+ .popsection
23114+ .pushsection .altinstructions, "a"
23115+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23116+ .popsection
23117+ GET_CR3_INTO_RDI
23118+ cmp $0,%dil
23119+ jnz 112f
23120+ mov $__KERNEL_DS,%edi
23121+ mov %edi,%ss
23122+ jmp 111f
23123+112: cmp $1,%dil
23124+ jz 113f
23125+ ud2
23126+113: sub $4097,%rdi
23127+ bts $63,%rdi
23128+ SET_RDI_INTO_CR3
23129+ mov $__UDEREF_KERNEL_DS,%edi
23130+ mov %edi,%ss
23131+111:
23132+#endif
23133+
23134+#ifdef CONFIG_PARAVIRT
23135+ PV_RESTORE_REGS(CLBR_RDI)
23136+#endif
23137+
23138+ popq %rdi
23139+ pax_force_retaddr
23140+ retq
23141+
23142+#ifdef CONFIG_PAX_KERNEXEC
23143+2: ljmpq __KERNEL_CS,1b
23144+3: ljmpq __KERNEXEC_KERNEL_CS,4f
23145+4: SET_RDI_INTO_CR0
23146+ jmp 1b
23147+#endif
23148+ENDPROC(pax_enter_kernel)
23149+
23150+ENTRY(pax_exit_kernel)
23151+ pushq %rdi
23152+
23153+#ifdef CONFIG_PARAVIRT
23154+ PV_SAVE_REGS(CLBR_RDI)
23155+#endif
23156+
23157+#ifdef CONFIG_PAX_KERNEXEC
23158+ mov %cs,%rdi
23159+ cmp $__KERNEXEC_KERNEL_CS,%edi
23160+ jz 2f
23161+ GET_CR0_INTO_RDI
23162+ bts $16,%rdi
23163+ jnc 4f
23164+1:
23165+#endif
23166+
23167+#ifdef CONFIG_PAX_MEMORY_UDEREF
23168+ 661: jmp 111f
23169+ .pushsection .altinstr_replacement, "a"
23170+ 662: ASM_NOP2
23171+ .popsection
23172+ .pushsection .altinstructions, "a"
23173+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23174+ .popsection
23175+ mov %ss,%edi
23176+ cmp $__UDEREF_KERNEL_DS,%edi
23177+ jnz 111f
23178+ GET_CR3_INTO_RDI
23179+ cmp $0,%dil
23180+ jz 112f
23181+ ud2
23182+112: add $4097,%rdi
23183+ bts $63,%rdi
23184+ SET_RDI_INTO_CR3
23185+ mov $__KERNEL_DS,%edi
23186+ mov %edi,%ss
23187+111:
23188+#endif
23189+
23190+#ifdef CONFIG_PARAVIRT
23191+ PV_RESTORE_REGS(CLBR_RDI);
23192+#endif
23193+
23194+ popq %rdi
23195+ pax_force_retaddr
23196+ retq
23197+
23198+#ifdef CONFIG_PAX_KERNEXEC
23199+2: GET_CR0_INTO_RDI
23200+ btr $16,%rdi
23201+ jnc 4f
23202+ ljmpq __KERNEL_CS,3f
23203+3: SET_RDI_INTO_CR0
23204+ jmp 1b
23205+4: ud2
23206+ jmp 4b
23207+#endif
23208+ENDPROC(pax_exit_kernel)
23209+#endif
23210+
23211+ .macro pax_enter_kernel_user
23212+ pax_set_fptr_mask
23213+#ifdef CONFIG_PAX_MEMORY_UDEREF
23214+ call pax_enter_kernel_user
23215+#endif
23216+ .endm
23217+
23218+ .macro pax_exit_kernel_user
23219+#ifdef CONFIG_PAX_MEMORY_UDEREF
23220+ call pax_exit_kernel_user
23221+#endif
23222+#ifdef CONFIG_PAX_RANDKSTACK
23223+ pushq %rax
23224+ pushq %r11
23225+ call pax_randomize_kstack
23226+ popq %r11
23227+ popq %rax
23228+#endif
23229+ .endm
23230+
23231+#ifdef CONFIG_PAX_MEMORY_UDEREF
23232+ENTRY(pax_enter_kernel_user)
23233+ pushq %rdi
23234+ pushq %rbx
23235+
23236+#ifdef CONFIG_PARAVIRT
23237+ PV_SAVE_REGS(CLBR_RDI)
23238+#endif
23239+
23240+ 661: jmp 111f
23241+ .pushsection .altinstr_replacement, "a"
23242+ 662: ASM_NOP2
23243+ .popsection
23244+ .pushsection .altinstructions, "a"
23245+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23246+ .popsection
23247+ GET_CR3_INTO_RDI
23248+ cmp $1,%dil
23249+ jnz 4f
23250+ sub $4097,%rdi
23251+ bts $63,%rdi
23252+ SET_RDI_INTO_CR3
23253+ jmp 3f
23254+111:
23255+
23256+ GET_CR3_INTO_RDI
23257+ mov %rdi,%rbx
23258+ add $__START_KERNEL_map,%rbx
23259+ sub phys_base(%rip),%rbx
23260+
23261+#ifdef CONFIG_PARAVIRT
23262+ cmpl $0, pv_info+PARAVIRT_enabled
23263+ jz 1f
23264+ pushq %rdi
23265+ i = 0
23266+ .rept USER_PGD_PTRS
23267+ mov i*8(%rbx),%rsi
23268+ mov $0,%sil
23269+ lea i*8(%rbx),%rdi
23270+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
23271+ i = i + 1
23272+ .endr
23273+ popq %rdi
23274+ jmp 2f
23275+1:
23276+#endif
23277+
23278+ i = 0
23279+ .rept USER_PGD_PTRS
23280+ movb $0,i*8(%rbx)
23281+ i = i + 1
23282+ .endr
23283+
23284+2: SET_RDI_INTO_CR3
23285+
23286+#ifdef CONFIG_PAX_KERNEXEC
23287+ GET_CR0_INTO_RDI
23288+ bts $16,%rdi
23289+ SET_RDI_INTO_CR0
23290+#endif
23291+
23292+3:
23293+
23294+#ifdef CONFIG_PARAVIRT
23295+ PV_RESTORE_REGS(CLBR_RDI)
23296+#endif
23297+
23298+ popq %rbx
23299+ popq %rdi
23300+ pax_force_retaddr
23301+ retq
23302+4: ud2
23303+ENDPROC(pax_enter_kernel_user)
23304+
23305+ENTRY(pax_exit_kernel_user)
23306+ pushq %rdi
23307+ pushq %rbx
23308+
23309+#ifdef CONFIG_PARAVIRT
23310+ PV_SAVE_REGS(CLBR_RDI)
23311+#endif
23312+
23313+ GET_CR3_INTO_RDI
23314+ 661: jmp 1f
23315+ .pushsection .altinstr_replacement, "a"
23316+ 662: ASM_NOP2
23317+ .popsection
23318+ .pushsection .altinstructions, "a"
23319+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23320+ .popsection
23321+ cmp $0,%dil
23322+ jnz 3f
23323+ add $4097,%rdi
23324+ bts $63,%rdi
23325+ SET_RDI_INTO_CR3
23326+ jmp 2f
23327+1:
23328+
23329+ mov %rdi,%rbx
23330+
23331+#ifdef CONFIG_PAX_KERNEXEC
23332+ GET_CR0_INTO_RDI
23333+ btr $16,%rdi
23334+ jnc 3f
23335+ SET_RDI_INTO_CR0
23336+#endif
23337+
23338+ add $__START_KERNEL_map,%rbx
23339+ sub phys_base(%rip),%rbx
23340+
23341+#ifdef CONFIG_PARAVIRT
23342+ cmpl $0, pv_info+PARAVIRT_enabled
23343+ jz 1f
23344+ i = 0
23345+ .rept USER_PGD_PTRS
23346+ mov i*8(%rbx),%rsi
23347+ mov $0x67,%sil
23348+ lea i*8(%rbx),%rdi
23349+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
23350+ i = i + 1
23351+ .endr
23352+ jmp 2f
23353+1:
23354+#endif
23355+
23356+ i = 0
23357+ .rept USER_PGD_PTRS
23358+ movb $0x67,i*8(%rbx)
23359+ i = i + 1
23360+ .endr
23361+2:
23362+
23363+#ifdef CONFIG_PARAVIRT
23364+ PV_RESTORE_REGS(CLBR_RDI)
23365+#endif
23366+
23367+ popq %rbx
23368+ popq %rdi
23369+ pax_force_retaddr
23370+ retq
23371+3: ud2
23372+ENDPROC(pax_exit_kernel_user)
23373+#endif
23374+
23375+ .macro pax_enter_kernel_nmi
23376+ pax_set_fptr_mask
23377+
23378+#ifdef CONFIG_PAX_KERNEXEC
23379+ GET_CR0_INTO_RDI
23380+ bts $16,%rdi
23381+ jc 110f
23382+ SET_RDI_INTO_CR0
23383+ or $2,%ebx
23384+110:
23385+#endif
23386+
23387+#ifdef CONFIG_PAX_MEMORY_UDEREF
23388+ 661: jmp 111f
23389+ .pushsection .altinstr_replacement, "a"
23390+ 662: ASM_NOP2
23391+ .popsection
23392+ .pushsection .altinstructions, "a"
23393+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23394+ .popsection
23395+ GET_CR3_INTO_RDI
23396+ cmp $0,%dil
23397+ jz 111f
23398+ sub $4097,%rdi
23399+ or $4,%ebx
23400+ bts $63,%rdi
23401+ SET_RDI_INTO_CR3
23402+ mov $__UDEREF_KERNEL_DS,%edi
23403+ mov %edi,%ss
23404+111:
23405+#endif
23406+ .endm
23407+
23408+ .macro pax_exit_kernel_nmi
23409+#ifdef CONFIG_PAX_KERNEXEC
23410+ btr $1,%ebx
23411+ jnc 110f
23412+ GET_CR0_INTO_RDI
23413+ btr $16,%rdi
23414+ SET_RDI_INTO_CR0
23415+110:
23416+#endif
23417+
23418+#ifdef CONFIG_PAX_MEMORY_UDEREF
23419+ btr $2,%ebx
23420+ jnc 111f
23421+ GET_CR3_INTO_RDI
23422+ add $4097,%rdi
23423+ bts $63,%rdi
23424+ SET_RDI_INTO_CR3
23425+ mov $__KERNEL_DS,%edi
23426+ mov %edi,%ss
23427+111:
23428+#endif
23429+ .endm
23430+
23431+ .macro pax_erase_kstack
23432+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
23433+ call pax_erase_kstack
23434+#endif
23435+ .endm
23436+
23437+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
23438+ENTRY(pax_erase_kstack)
23439+ pushq %rdi
23440+ pushq %rcx
23441+ pushq %rax
23442+ pushq %r11
23443+
23444+ GET_THREAD_INFO(%r11)
23445+ mov TI_lowest_stack(%r11), %rdi
23446+ mov $-0xBEEF, %rax
23447+ std
23448+
23449+1: mov %edi, %ecx
23450+ and $THREAD_SIZE_asm - 1, %ecx
23451+ shr $3, %ecx
23452+ repne scasq
23453+ jecxz 2f
23454+
23455+ cmp $2*8, %ecx
23456+ jc 2f
23457+
23458+ mov $2*8, %ecx
23459+ repe scasq
23460+ jecxz 2f
23461+ jne 1b
23462+
23463+2: cld
23464+ or $2*8, %rdi
23465+ mov %esp, %ecx
23466+ sub %edi, %ecx
23467+
23468+ cmp $THREAD_SIZE_asm, %rcx
23469+ jb 3f
23470+ ud2
23471+3:
23472+
23473+ shr $3, %ecx
23474+ rep stosq
23475+
23476+ mov TI_task_thread_sp0(%r11), %rdi
23477+ sub $256, %rdi
23478+ mov %rdi, TI_lowest_stack(%r11)
23479+
23480+ popq %r11
23481+ popq %rax
23482+ popq %rcx
23483+ popq %rdi
23484+ pax_force_retaddr
23485+ ret
23486+ENDPROC(pax_erase_kstack)
23487+#endif
23488
23489 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
23490 #ifdef CONFIG_TRACE_IRQFLAGS
23491@@ -117,7 +544,7 @@ ENDPROC(native_usergs_sysret64)
23492 .endm
23493
23494 .macro TRACE_IRQS_IRETQ_DEBUG offset=ARGOFFSET
23495- bt $9,EFLAGS-\offset(%rsp) /* interrupts off? */
23496+ bt $X86_EFLAGS_IF_BIT,EFLAGS-\offset(%rsp) /* interrupts off? */
23497 jnc 1f
23498 TRACE_IRQS_ON_DEBUG
23499 1:
23500@@ -155,27 +582,6 @@ ENDPROC(native_usergs_sysret64)
23501 movq \tmp,R11+\offset(%rsp)
23502 .endm
23503
23504- .macro FAKE_STACK_FRAME child_rip
23505- /* push in order ss, rsp, eflags, cs, rip */
23506- xorl %eax, %eax
23507- pushq_cfi $__KERNEL_DS /* ss */
23508- /*CFI_REL_OFFSET ss,0*/
23509- pushq_cfi %rax /* rsp */
23510- CFI_REL_OFFSET rsp,0
23511- pushq_cfi $(X86_EFLAGS_IF|X86_EFLAGS_FIXED) /* eflags - interrupts on */
23512- /*CFI_REL_OFFSET rflags,0*/
23513- pushq_cfi $__KERNEL_CS /* cs */
23514- /*CFI_REL_OFFSET cs,0*/
23515- pushq_cfi \child_rip /* rip */
23516- CFI_REL_OFFSET rip,0
23517- pushq_cfi %rax /* orig rax */
23518- .endm
23519-
23520- .macro UNFAKE_STACK_FRAME
23521- addq $8*6, %rsp
23522- CFI_ADJUST_CFA_OFFSET -(6*8)
23523- .endm
23524-
23525 /*
23526 * initial frame state for interrupts (and exceptions without error code)
23527 */
23528@@ -241,25 +647,26 @@ ENDPROC(native_usergs_sysret64)
23529 /* save partial stack frame */
23530 .macro SAVE_ARGS_IRQ
23531 cld
23532- /* start from rbp in pt_regs and jump over */
23533- movq_cfi rdi, (RDI-RBP)
23534- movq_cfi rsi, (RSI-RBP)
23535- movq_cfi rdx, (RDX-RBP)
23536- movq_cfi rcx, (RCX-RBP)
23537- movq_cfi rax, (RAX-RBP)
23538- movq_cfi r8, (R8-RBP)
23539- movq_cfi r9, (R9-RBP)
23540- movq_cfi r10, (R10-RBP)
23541- movq_cfi r11, (R11-RBP)
23542+ /* start from r15 in pt_regs and jump over */
23543+ movq_cfi rdi, RDI
23544+ movq_cfi rsi, RSI
23545+ movq_cfi rdx, RDX
23546+ movq_cfi rcx, RCX
23547+ movq_cfi rax, RAX
23548+ movq_cfi r8, R8
23549+ movq_cfi r9, R9
23550+ movq_cfi r10, R10
23551+ movq_cfi r11, R11
23552+ movq_cfi r12, R12
23553
23554 /* Save rbp so that we can unwind from get_irq_regs() */
23555- movq_cfi rbp, 0
23556+ movq_cfi rbp, RBP
23557
23558 /* Save previous stack value */
23559 movq %rsp, %rsi
23560
23561- leaq -RBP(%rsp),%rdi /* arg1 for handler */
23562- testl $3, CS-RBP(%rsi)
23563+ movq %rsp,%rdi /* arg1 for handler */
23564+ testb $3, CS(%rsi)
23565 je 1f
23566 SWAPGS
23567 /*
23568@@ -279,6 +686,18 @@ ENDPROC(native_usergs_sysret64)
23569 0x06 /* DW_OP_deref */, \
23570 0x08 /* DW_OP_const1u */, SS+8-RBP, \
23571 0x22 /* DW_OP_plus */
23572+
23573+#ifdef CONFIG_PAX_MEMORY_UDEREF
23574+ testb $3, CS(%rdi)
23575+ jnz 1f
23576+ pax_enter_kernel
23577+ jmp 2f
23578+1: pax_enter_kernel_user
23579+2:
23580+#else
23581+ pax_enter_kernel
23582+#endif
23583+
23584 /* We entered an interrupt context - irqs are off: */
23585 TRACE_IRQS_OFF
23586 .endm
23587@@ -308,9 +727,52 @@ ENTRY(save_paranoid)
23588 js 1f /* negative -> in kernel */
23589 SWAPGS
23590 xorl %ebx,%ebx
23591-1: ret
23592+1:
23593+#ifdef CONFIG_PAX_MEMORY_UDEREF
23594+ testb $3, CS+8(%rsp)
23595+ jnz 1f
23596+ pax_enter_kernel
23597+ jmp 2f
23598+1: pax_enter_kernel_user
23599+2:
23600+#else
23601+ pax_enter_kernel
23602+#endif
23603+ pax_force_retaddr
23604+ ret
23605 CFI_ENDPROC
23606-END(save_paranoid)
23607+ENDPROC(save_paranoid)
23608+
23609+ENTRY(save_paranoid_nmi)
23610+ XCPT_FRAME 1 RDI+8
23611+ cld
23612+ movq_cfi rdi, RDI+8
23613+ movq_cfi rsi, RSI+8
23614+ movq_cfi rdx, RDX+8
23615+ movq_cfi rcx, RCX+8
23616+ movq_cfi rax, RAX+8
23617+ movq_cfi r8, R8+8
23618+ movq_cfi r9, R9+8
23619+ movq_cfi r10, R10+8
23620+ movq_cfi r11, R11+8
23621+ movq_cfi rbx, RBX+8
23622+ movq_cfi rbp, RBP+8
23623+ movq_cfi r12, R12+8
23624+ movq_cfi r13, R13+8
23625+ movq_cfi r14, R14+8
23626+ movq_cfi r15, R15+8
23627+ movl $1,%ebx
23628+ movl $MSR_GS_BASE,%ecx
23629+ rdmsr
23630+ testl %edx,%edx
23631+ js 1f /* negative -> in kernel */
23632+ SWAPGS
23633+ xorl %ebx,%ebx
23634+1: pax_enter_kernel_nmi
23635+ pax_force_retaddr
23636+ ret
23637+ CFI_ENDPROC
23638+ENDPROC(save_paranoid_nmi)
23639
23640 /*
23641 * A newly forked process directly context switches into this address.
23642@@ -331,7 +793,7 @@ ENTRY(ret_from_fork)
23643
23644 RESTORE_REST
23645
23646- testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
23647+ testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
23648 jz 1f
23649
23650 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
23651@@ -341,15 +803,13 @@ ENTRY(ret_from_fork)
23652 jmp ret_from_sys_call # go to the SYSRET fastpath
23653
23654 1:
23655- subq $REST_SKIP, %rsp # leave space for volatiles
23656- CFI_ADJUST_CFA_OFFSET REST_SKIP
23657 movq %rbp, %rdi
23658 call *%rbx
23659 movl $0, RAX(%rsp)
23660 RESTORE_REST
23661 jmp int_ret_from_sys_call
23662 CFI_ENDPROC
23663-END(ret_from_fork)
23664+ENDPROC(ret_from_fork)
23665
23666 /*
23667 * System call entry. Up to 6 arguments in registers are supported.
23668@@ -386,7 +846,7 @@ END(ret_from_fork)
23669 ENTRY(system_call)
23670 CFI_STARTPROC simple
23671 CFI_SIGNAL_FRAME
23672- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
23673+ CFI_DEF_CFA rsp,0
23674 CFI_REGISTER rip,rcx
23675 /*CFI_REGISTER rflags,r11*/
23676 SWAPGS_UNSAFE_STACK
23677@@ -399,16 +859,23 @@ GLOBAL(system_call_after_swapgs)
23678
23679 movq %rsp,PER_CPU_VAR(old_rsp)
23680 movq PER_CPU_VAR(kernel_stack),%rsp
23681+ SAVE_ARGS 8*6, 0, rax_enosys=1
23682+ pax_enter_kernel_user
23683+
23684+#ifdef CONFIG_PAX_RANDKSTACK
23685+ pax_erase_kstack
23686+#endif
23687+
23688 /*
23689 * No need to follow this irqs off/on section - it's straight
23690 * and short:
23691 */
23692 ENABLE_INTERRUPTS(CLBR_NONE)
23693- SAVE_ARGS 8, 0, rax_enosys=1
23694 movq_cfi rax,(ORIG_RAX-ARGOFFSET)
23695 movq %rcx,RIP-ARGOFFSET(%rsp)
23696 CFI_REL_OFFSET rip,RIP-ARGOFFSET
23697- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
23698+ GET_THREAD_INFO(%rcx)
23699+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%rcx)
23700 jnz tracesys
23701 system_call_fastpath:
23702 #if __SYSCALL_MASK == ~0
23703@@ -432,10 +899,13 @@ sysret_check:
23704 LOCKDEP_SYS_EXIT
23705 DISABLE_INTERRUPTS(CLBR_NONE)
23706 TRACE_IRQS_OFF
23707- movl TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET),%edx
23708+ GET_THREAD_INFO(%rcx)
23709+ movl TI_flags(%rcx),%edx
23710 andl %edi,%edx
23711 jnz sysret_careful
23712 CFI_REMEMBER_STATE
23713+ pax_exit_kernel_user
23714+ pax_erase_kstack
23715 /*
23716 * sysretq will re-enable interrupts:
23717 */
23718@@ -494,12 +964,15 @@ sysret_audit:
23719
23720 /* Do syscall tracing */
23721 tracesys:
23722- leaq -REST_SKIP(%rsp), %rdi
23723+ movq %rsp, %rdi
23724 movq $AUDIT_ARCH_X86_64, %rsi
23725 call syscall_trace_enter_phase1
23726 test %rax, %rax
23727 jnz tracesys_phase2 /* if needed, run the slow path */
23728- LOAD_ARGS 0 /* else restore clobbered regs */
23729+
23730+ pax_erase_kstack
23731+
23732+ LOAD_ARGS /* else restore clobbered regs */
23733 jmp system_call_fastpath /* and return to the fast path */
23734
23735 tracesys_phase2:
23736@@ -510,12 +983,14 @@ tracesys_phase2:
23737 movq %rax,%rdx
23738 call syscall_trace_enter_phase2
23739
23740+ pax_erase_kstack
23741+
23742 /*
23743 * Reload arg registers from stack in case ptrace changed them.
23744 * We don't reload %rax because syscall_trace_entry_phase2() returned
23745 * the value it wants us to use in the table lookup.
23746 */
23747- LOAD_ARGS ARGOFFSET, 1
23748+ LOAD_ARGS 1
23749 RESTORE_REST
23750 #if __SYSCALL_MASK == ~0
23751 cmpq $__NR_syscall_max,%rax
23752@@ -545,7 +1020,9 @@ GLOBAL(int_with_check)
23753 andl %edi,%edx
23754 jnz int_careful
23755 andl $~TS_COMPAT,TI_status(%rcx)
23756- jmp retint_swapgs
23757+ pax_exit_kernel_user
23758+ pax_erase_kstack
23759+ jmp retint_swapgs_pax
23760
23761 /* Either reschedule or signal or syscall exit tracking needed. */
23762 /* First do a reschedule test. */
23763@@ -591,7 +1068,7 @@ int_restore_rest:
23764 TRACE_IRQS_OFF
23765 jmp int_with_check
23766 CFI_ENDPROC
23767-END(system_call)
23768+ENDPROC(system_call)
23769
23770 .macro FORK_LIKE func
23771 ENTRY(stub_\func)
23772@@ -604,9 +1081,10 @@ ENTRY(stub_\func)
23773 DEFAULT_FRAME 0 8 /* offset 8: return address */
23774 call sys_\func
23775 RESTORE_TOP_OF_STACK %r11, 8
23776- ret $REST_SKIP /* pop extended registers */
23777+ pax_force_retaddr
23778+ ret
23779 CFI_ENDPROC
23780-END(stub_\func)
23781+ENDPROC(stub_\func)
23782 .endm
23783
23784 .macro FIXED_FRAME label,func
23785@@ -616,9 +1094,10 @@ ENTRY(\label)
23786 FIXUP_TOP_OF_STACK %r11, 8-ARGOFFSET
23787 call \func
23788 RESTORE_TOP_OF_STACK %r11, 8-ARGOFFSET
23789+ pax_force_retaddr
23790 ret
23791 CFI_ENDPROC
23792-END(\label)
23793+ENDPROC(\label)
23794 .endm
23795
23796 FORK_LIKE clone
23797@@ -626,19 +1105,6 @@ END(\label)
23798 FORK_LIKE vfork
23799 FIXED_FRAME stub_iopl, sys_iopl
23800
23801-ENTRY(ptregscall_common)
23802- DEFAULT_FRAME 1 8 /* offset 8: return address */
23803- RESTORE_TOP_OF_STACK %r11, 8
23804- movq_cfi_restore R15+8, r15
23805- movq_cfi_restore R14+8, r14
23806- movq_cfi_restore R13+8, r13
23807- movq_cfi_restore R12+8, r12
23808- movq_cfi_restore RBP+8, rbp
23809- movq_cfi_restore RBX+8, rbx
23810- ret $REST_SKIP /* pop extended registers */
23811- CFI_ENDPROC
23812-END(ptregscall_common)
23813-
23814 ENTRY(stub_execve)
23815 CFI_STARTPROC
23816 addq $8, %rsp
23817@@ -650,7 +1116,7 @@ ENTRY(stub_execve)
23818 RESTORE_REST
23819 jmp int_ret_from_sys_call
23820 CFI_ENDPROC
23821-END(stub_execve)
23822+ENDPROC(stub_execve)
23823
23824 /*
23825 * sigreturn is special because it needs to restore all registers on return.
23826@@ -667,7 +1133,7 @@ ENTRY(stub_rt_sigreturn)
23827 RESTORE_REST
23828 jmp int_ret_from_sys_call
23829 CFI_ENDPROC
23830-END(stub_rt_sigreturn)
23831+ENDPROC(stub_rt_sigreturn)
23832
23833 #ifdef CONFIG_X86_X32_ABI
23834 ENTRY(stub_x32_rt_sigreturn)
23835@@ -681,7 +1147,7 @@ ENTRY(stub_x32_rt_sigreturn)
23836 RESTORE_REST
23837 jmp int_ret_from_sys_call
23838 CFI_ENDPROC
23839-END(stub_x32_rt_sigreturn)
23840+ENDPROC(stub_x32_rt_sigreturn)
23841
23842 ENTRY(stub_x32_execve)
23843 CFI_STARTPROC
23844@@ -695,7 +1161,7 @@ ENTRY(stub_x32_execve)
23845 RESTORE_REST
23846 jmp int_ret_from_sys_call
23847 CFI_ENDPROC
23848-END(stub_x32_execve)
23849+ENDPROC(stub_x32_execve)
23850
23851 #endif
23852
23853@@ -732,7 +1198,7 @@ vector=vector+1
23854 2: jmp common_interrupt
23855 .endr
23856 CFI_ENDPROC
23857-END(irq_entries_start)
23858+ENDPROC(irq_entries_start)
23859
23860 .previous
23861 END(interrupt)
23862@@ -749,8 +1215,8 @@ END(interrupt)
23863 /* 0(%rsp): ~(interrupt number) */
23864 .macro interrupt func
23865 /* reserve pt_regs for scratch regs and rbp */
23866- subq $ORIG_RAX-RBP, %rsp
23867- CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
23868+ subq $ORIG_RAX, %rsp
23869+ CFI_ADJUST_CFA_OFFSET ORIG_RAX
23870 SAVE_ARGS_IRQ
23871 call \func
23872 .endm
23873@@ -773,14 +1239,14 @@ ret_from_intr:
23874
23875 /* Restore saved previous stack */
23876 popq %rsi
23877- CFI_DEF_CFA rsi,SS+8-RBP /* reg/off reset after def_cfa_expr */
23878- leaq ARGOFFSET-RBP(%rsi), %rsp
23879+ CFI_DEF_CFA rsi,SS+8 /* reg/off reset after def_cfa_expr */
23880+ movq %rsi, %rsp
23881 CFI_DEF_CFA_REGISTER rsp
23882- CFI_ADJUST_CFA_OFFSET RBP-ARGOFFSET
23883+ CFI_ADJUST_CFA_OFFSET -ARGOFFSET
23884
23885 exit_intr:
23886 GET_THREAD_INFO(%rcx)
23887- testl $3,CS-ARGOFFSET(%rsp)
23888+ testb $3,CS-ARGOFFSET(%rsp)
23889 je retint_kernel
23890
23891 /* Interrupt came from user space */
23892@@ -802,12 +1268,35 @@ retint_swapgs: /* return to user-space */
23893 * The iretq could re-enable interrupts:
23894 */
23895 DISABLE_INTERRUPTS(CLBR_ANY)
23896+ pax_exit_kernel_user
23897+retint_swapgs_pax:
23898 TRACE_IRQS_IRETQ
23899 SWAPGS
23900 jmp restore_args
23901
23902 retint_restore_args: /* return to kernel space */
23903 DISABLE_INTERRUPTS(CLBR_ANY)
23904+ pax_exit_kernel
23905+
23906+#if defined(CONFIG_EFI) && defined(CONFIG_PAX_KERNEXEC)
23907+ /* This is a quirk to allow IRQs/NMIs/MCEs during early EFI setup,
23908+ * namely calling EFI runtime services with a phys mapping. We're
23909+ * starting off with NOPs and patch in the real instrumentation
23910+ * (BTS/OR) before starting any userland process; even before starting
23911+ * up the APs.
23912+ */
23913+ .pushsection .altinstr_replacement, "a"
23914+ 601: pax_force_retaddr (RIP-ARGOFFSET)
23915+ 602:
23916+ .popsection
23917+ 603: .fill 602b-601b, 1, 0x90
23918+ .pushsection .altinstructions, "a"
23919+ altinstruction_entry 603b, 601b, X86_FEATURE_ALWAYS, 602b-601b, 602b-601b
23920+ .popsection
23921+#else
23922+ pax_force_retaddr (RIP-ARGOFFSET)
23923+#endif
23924+
23925 /*
23926 * The iretq could re-enable interrupts:
23927 */
23928@@ -845,15 +1334,15 @@ native_irq_return_ldt:
23929 SWAPGS
23930 movq PER_CPU_VAR(espfix_waddr),%rdi
23931 movq %rax,(0*8)(%rdi) /* RAX */
23932- movq (2*8)(%rsp),%rax /* RIP */
23933+ movq (2*8 + RIP-RIP)(%rsp),%rax /* RIP */
23934 movq %rax,(1*8)(%rdi)
23935- movq (3*8)(%rsp),%rax /* CS */
23936+ movq (2*8 + CS-RIP)(%rsp),%rax /* CS */
23937 movq %rax,(2*8)(%rdi)
23938- movq (4*8)(%rsp),%rax /* RFLAGS */
23939+ movq (2*8 + EFLAGS-RIP)(%rsp),%rax /* RFLAGS */
23940 movq %rax,(3*8)(%rdi)
23941- movq (6*8)(%rsp),%rax /* SS */
23942+ movq (2*8 + SS-RIP)(%rsp),%rax /* SS */
23943 movq %rax,(5*8)(%rdi)
23944- movq (5*8)(%rsp),%rax /* RSP */
23945+ movq (2*8 + RSP-RIP)(%rsp),%rax /* RSP */
23946 movq %rax,(4*8)(%rdi)
23947 andl $0xffff0000,%eax
23948 popq_cfi %rdi
23949@@ -907,7 +1396,7 @@ ENTRY(retint_kernel)
23950 jmp exit_intr
23951 #endif
23952 CFI_ENDPROC
23953-END(common_interrupt)
23954+ENDPROC(common_interrupt)
23955
23956 /*
23957 * APIC interrupts.
23958@@ -921,7 +1410,7 @@ ENTRY(\sym)
23959 interrupt \do_sym
23960 jmp ret_from_intr
23961 CFI_ENDPROC
23962-END(\sym)
23963+ENDPROC(\sym)
23964 .endm
23965
23966 #ifdef CONFIG_TRACING
23967@@ -994,7 +1483,7 @@ apicinterrupt IRQ_WORK_VECTOR \
23968 /*
23969 * Exception entry points.
23970 */
23971-#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
23972+#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r13)
23973
23974 .macro idtentry sym do_sym has_error_code:req paranoid=0 shift_ist=-1
23975 ENTRY(\sym)
23976@@ -1045,6 +1534,12 @@ ENTRY(\sym)
23977 .endif
23978
23979 .if \shift_ist != -1
23980+#ifdef CONFIG_SMP
23981+ imul $TSS_size, PER_CPU_VAR(cpu_number), %r13d
23982+ lea init_tss(%r13), %r13
23983+#else
23984+ lea init_tss(%rip), %r13
23985+#endif
23986 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\shift_ist)
23987 .endif
23988
23989@@ -1061,7 +1556,7 @@ ENTRY(\sym)
23990 .endif
23991
23992 CFI_ENDPROC
23993-END(\sym)
23994+ENDPROC(\sym)
23995 .endm
23996
23997 #ifdef CONFIG_TRACING
23998@@ -1102,9 +1597,10 @@ gs_change:
23999 2: mfence /* workaround */
24000 SWAPGS
24001 popfq_cfi
24002+ pax_force_retaddr
24003 ret
24004 CFI_ENDPROC
24005-END(native_load_gs_index)
24006+ENDPROC(native_load_gs_index)
24007
24008 _ASM_EXTABLE(gs_change,bad_gs)
24009 .section .fixup,"ax"
24010@@ -1132,9 +1628,10 @@ ENTRY(do_softirq_own_stack)
24011 CFI_DEF_CFA_REGISTER rsp
24012 CFI_ADJUST_CFA_OFFSET -8
24013 decl PER_CPU_VAR(irq_count)
24014+ pax_force_retaddr
24015 ret
24016 CFI_ENDPROC
24017-END(do_softirq_own_stack)
24018+ENDPROC(do_softirq_own_stack)
24019
24020 #ifdef CONFIG_XEN
24021 idtentry xen_hypervisor_callback xen_do_hypervisor_callback has_error_code=0
24022@@ -1172,7 +1669,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
24023 decl PER_CPU_VAR(irq_count)
24024 jmp error_exit
24025 CFI_ENDPROC
24026-END(xen_do_hypervisor_callback)
24027+ENDPROC(xen_do_hypervisor_callback)
24028
24029 /*
24030 * Hypervisor uses this for application faults while it executes.
24031@@ -1231,7 +1728,7 @@ ENTRY(xen_failsafe_callback)
24032 SAVE_ALL
24033 jmp error_exit
24034 CFI_ENDPROC
24035-END(xen_failsafe_callback)
24036+ENDPROC(xen_failsafe_callback)
24037
24038 apicinterrupt3 HYPERVISOR_CALLBACK_VECTOR \
24039 xen_hvm_callback_vector xen_evtchn_do_upcall
24040@@ -1278,18 +1775,33 @@ ENTRY(paranoid_exit)
24041 DEFAULT_FRAME
24042 DISABLE_INTERRUPTS(CLBR_NONE)
24043 TRACE_IRQS_OFF_DEBUG
24044- testl %ebx,%ebx /* swapgs needed? */
24045+ testl $1,%ebx /* swapgs needed? */
24046 jnz paranoid_restore
24047- testl $3,CS(%rsp)
24048+ testb $3,CS(%rsp)
24049 jnz paranoid_userspace
24050+#ifdef CONFIG_PAX_MEMORY_UDEREF
24051+ pax_exit_kernel
24052+ TRACE_IRQS_IRETQ 0
24053+ SWAPGS_UNSAFE_STACK
24054+ RESTORE_ALL 8
24055+ pax_force_retaddr_bts
24056+ jmp irq_return
24057+#endif
24058 paranoid_swapgs:
24059+#ifdef CONFIG_PAX_MEMORY_UDEREF
24060+ pax_exit_kernel_user
24061+#else
24062+ pax_exit_kernel
24063+#endif
24064 TRACE_IRQS_IRETQ 0
24065 SWAPGS_UNSAFE_STACK
24066 RESTORE_ALL 8
24067 jmp irq_return
24068 paranoid_restore:
24069+ pax_exit_kernel
24070 TRACE_IRQS_IRETQ_DEBUG 0
24071 RESTORE_ALL 8
24072+ pax_force_retaddr_bts
24073 jmp irq_return
24074 paranoid_userspace:
24075 GET_THREAD_INFO(%rcx)
24076@@ -1318,7 +1830,7 @@ paranoid_schedule:
24077 TRACE_IRQS_OFF
24078 jmp paranoid_userspace
24079 CFI_ENDPROC
24080-END(paranoid_exit)
24081+ENDPROC(paranoid_exit)
24082
24083 /*
24084 * Exception entry point. This expects an error code/orig_rax on the stack.
24085@@ -1345,12 +1857,23 @@ ENTRY(error_entry)
24086 movq %r14, R14+8(%rsp)
24087 movq %r15, R15+8(%rsp)
24088 xorl %ebx,%ebx
24089- testl $3,CS+8(%rsp)
24090+ testb $3,CS+8(%rsp)
24091 je error_kernelspace
24092 error_swapgs:
24093 SWAPGS
24094 error_sti:
24095+#ifdef CONFIG_PAX_MEMORY_UDEREF
24096+ testb $3, CS+8(%rsp)
24097+ jnz 1f
24098+ pax_enter_kernel
24099+ jmp 2f
24100+1: pax_enter_kernel_user
24101+2:
24102+#else
24103+ pax_enter_kernel
24104+#endif
24105 TRACE_IRQS_OFF
24106+ pax_force_retaddr
24107 ret
24108
24109 /*
24110@@ -1385,7 +1908,7 @@ error_bad_iret:
24111 decl %ebx /* Return to usergs */
24112 jmp error_sti
24113 CFI_ENDPROC
24114-END(error_entry)
24115+ENDPROC(error_entry)
24116
24117
24118 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
24119@@ -1396,7 +1919,7 @@ ENTRY(error_exit)
24120 DISABLE_INTERRUPTS(CLBR_NONE)
24121 TRACE_IRQS_OFF
24122 GET_THREAD_INFO(%rcx)
24123- testl %eax,%eax
24124+ testl $1,%eax
24125 jne retint_kernel
24126 LOCKDEP_SYS_EXIT_IRQ
24127 movl TI_flags(%rcx),%edx
24128@@ -1405,7 +1928,7 @@ ENTRY(error_exit)
24129 jnz retint_careful
24130 jmp retint_swapgs
24131 CFI_ENDPROC
24132-END(error_exit)
24133+ENDPROC(error_exit)
24134
24135 /*
24136 * Test if a given stack is an NMI stack or not.
24137@@ -1463,9 +1986,11 @@ ENTRY(nmi)
24138 * If %cs was not the kernel segment, then the NMI triggered in user
24139 * space, which means it is definitely not nested.
24140 */
24141+ cmpl $__KERNEXEC_KERNEL_CS, 16(%rsp)
24142+ je 1f
24143 cmpl $__KERNEL_CS, 16(%rsp)
24144 jne first_nmi
24145-
24146+1:
24147 /*
24148 * Check the special variable on the stack to see if NMIs are
24149 * executing.
24150@@ -1499,8 +2024,7 @@ nested_nmi:
24151
24152 1:
24153 /* Set up the interrupted NMIs stack to jump to repeat_nmi */
24154- leaq -1*8(%rsp), %rdx
24155- movq %rdx, %rsp
24156+ subq $8, %rsp
24157 CFI_ADJUST_CFA_OFFSET 1*8
24158 leaq -10*8(%rsp), %rdx
24159 pushq_cfi $__KERNEL_DS
24160@@ -1518,6 +2042,7 @@ nested_nmi_out:
24161 CFI_RESTORE rdx
24162
24163 /* No need to check faults here */
24164+# pax_force_retaddr_bts
24165 INTERRUPT_RETURN
24166
24167 CFI_RESTORE_STATE
24168@@ -1614,13 +2139,13 @@ end_repeat_nmi:
24169 subq $ORIG_RAX-R15, %rsp
24170 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
24171 /*
24172- * Use save_paranoid to handle SWAPGS, but no need to use paranoid_exit
24173+ * Use save_paranoid_nmi to handle SWAPGS, but no need to use paranoid_exit
24174 * as we should not be calling schedule in NMI context.
24175 * Even with normal interrupts enabled. An NMI should not be
24176 * setting NEED_RESCHED or anything that normal interrupts and
24177 * exceptions might do.
24178 */
24179- call save_paranoid
24180+ call save_paranoid_nmi
24181 DEFAULT_FRAME 0
24182
24183 /*
24184@@ -1630,9 +2155,9 @@ end_repeat_nmi:
24185 * NMI itself takes a page fault, the page fault that was preempted
24186 * will read the information from the NMI page fault and not the
24187 * origin fault. Save it off and restore it if it changes.
24188- * Use the r12 callee-saved register.
24189+ * Use the r13 callee-saved register.
24190 */
24191- movq %cr2, %r12
24192+ movq %cr2, %r13
24193
24194 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
24195 movq %rsp,%rdi
24196@@ -1641,29 +2166,34 @@ end_repeat_nmi:
24197
24198 /* Did the NMI take a page fault? Restore cr2 if it did */
24199 movq %cr2, %rcx
24200- cmpq %rcx, %r12
24201+ cmpq %rcx, %r13
24202 je 1f
24203- movq %r12, %cr2
24204+ movq %r13, %cr2
24205 1:
24206
24207- testl %ebx,%ebx /* swapgs needed? */
24208+ testl $1,%ebx /* swapgs needed? */
24209 jnz nmi_restore
24210 nmi_swapgs:
24211 SWAPGS_UNSAFE_STACK
24212 nmi_restore:
24213+ pax_exit_kernel_nmi
24214 /* Pop the extra iret frame at once */
24215 RESTORE_ALL 6*8
24216+ testb $3, 8(%rsp)
24217+ jnz 1f
24218+ pax_force_retaddr_bts
24219+1:
24220
24221 /* Clear the NMI executing stack variable */
24222 movq $0, 5*8(%rsp)
24223 jmp irq_return
24224 CFI_ENDPROC
24225-END(nmi)
24226+ENDPROC(nmi)
24227
24228 ENTRY(ignore_sysret)
24229 CFI_STARTPROC
24230 mov $-ENOSYS,%eax
24231 sysret
24232 CFI_ENDPROC
24233-END(ignore_sysret)
24234+ENDPROC(ignore_sysret)
24235
24236diff --git a/arch/x86/kernel/espfix_64.c b/arch/x86/kernel/espfix_64.c
24237index 94d857f..5bce89c 100644
24238--- a/arch/x86/kernel/espfix_64.c
24239+++ b/arch/x86/kernel/espfix_64.c
24240@@ -70,8 +70,7 @@ static DEFINE_MUTEX(espfix_init_mutex);
24241 #define ESPFIX_MAX_PAGES DIV_ROUND_UP(CONFIG_NR_CPUS, ESPFIX_STACKS_PER_PAGE)
24242 static void *espfix_pages[ESPFIX_MAX_PAGES];
24243
24244-static __page_aligned_bss pud_t espfix_pud_page[PTRS_PER_PUD]
24245- __aligned(PAGE_SIZE);
24246+static pud_t espfix_pud_page[PTRS_PER_PUD] __page_aligned_rodata;
24247
24248 static unsigned int page_random, slot_random;
24249
24250@@ -122,14 +121,17 @@ static void init_espfix_random(void)
24251 void __init init_espfix_bsp(void)
24252 {
24253 pgd_t *pgd_p;
24254- pteval_t ptemask;
24255-
24256- ptemask = __supported_pte_mask;
24257+ unsigned long index = pgd_index(ESPFIX_BASE_ADDR);
24258
24259 /* Install the espfix pud into the kernel page directory */
24260- pgd_p = &init_level4_pgt[pgd_index(ESPFIX_BASE_ADDR)];
24261+ pgd_p = &init_level4_pgt[index];
24262 pgd_populate(&init_mm, pgd_p, (pud_t *)espfix_pud_page);
24263
24264+#ifdef CONFIG_PAX_PER_CPU_PGD
24265+ clone_pgd_range(get_cpu_pgd(0, kernel) + index, swapper_pg_dir + index, 1);
24266+ clone_pgd_range(get_cpu_pgd(0, user) + index, swapper_pg_dir + index, 1);
24267+#endif
24268+
24269 /* Randomize the locations */
24270 init_espfix_random();
24271
24272@@ -197,7 +199,7 @@ void init_espfix_ap(void)
24273 set_pte(&pte_p[n*PTE_STRIDE], pte);
24274
24275 /* Job is done for this CPU and any CPU which shares this page */
24276- ACCESS_ONCE(espfix_pages[page]) = stack_page;
24277+ ACCESS_ONCE_RW(espfix_pages[page]) = stack_page;
24278
24279 unlock_done:
24280 mutex_unlock(&espfix_init_mutex);
24281diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
24282index 3386dc9..28bdf81 100644
24283--- a/arch/x86/kernel/ftrace.c
24284+++ b/arch/x86/kernel/ftrace.c
24285@@ -88,7 +88,7 @@ static unsigned long text_ip_addr(unsigned long ip)
24286 * kernel identity mapping to modify code.
24287 */
24288 if (within(ip, (unsigned long)_text, (unsigned long)_etext))
24289- ip = (unsigned long)__va(__pa_symbol(ip));
24290+ ip = (unsigned long)__va(__pa_symbol(ktla_ktva(ip)));
24291
24292 return ip;
24293 }
24294@@ -104,6 +104,8 @@ ftrace_modify_code_direct(unsigned long ip, unsigned const char *old_code,
24295 {
24296 unsigned char replaced[MCOUNT_INSN_SIZE];
24297
24298+ ip = ktla_ktva(ip);
24299+
24300 /*
24301 * Note: Due to modules and __init, code can
24302 * disappear and change, we need to protect against faulting
24303@@ -229,7 +231,7 @@ static int update_ftrace_func(unsigned long ip, void *new)
24304 unsigned char old[MCOUNT_INSN_SIZE];
24305 int ret;
24306
24307- memcpy(old, (void *)ip, MCOUNT_INSN_SIZE);
24308+ memcpy(old, (void *)ktla_ktva(ip), MCOUNT_INSN_SIZE);
24309
24310 ftrace_update_func = ip;
24311 /* Make sure the breakpoints see the ftrace_update_func update */
24312@@ -310,7 +312,7 @@ static int add_break(unsigned long ip, const char *old)
24313 unsigned char replaced[MCOUNT_INSN_SIZE];
24314 unsigned char brk = BREAKPOINT_INSTRUCTION;
24315
24316- if (probe_kernel_read(replaced, (void *)ip, MCOUNT_INSN_SIZE))
24317+ if (probe_kernel_read(replaced, (void *)ktla_ktva(ip), MCOUNT_INSN_SIZE))
24318 return -EFAULT;
24319
24320 /* Make sure it is what we expect it to be */
24321diff --git a/arch/x86/kernel/head64.c b/arch/x86/kernel/head64.c
24322index eda1a86..8f6df48 100644
24323--- a/arch/x86/kernel/head64.c
24324+++ b/arch/x86/kernel/head64.c
24325@@ -67,12 +67,12 @@ again:
24326 pgd = *pgd_p;
24327
24328 /*
24329- * The use of __START_KERNEL_map rather than __PAGE_OFFSET here is
24330- * critical -- __PAGE_OFFSET would point us back into the dynamic
24331+ * The use of __early_va rather than __va here is critical:
24332+ * __va would point us back into the dynamic
24333 * range and we might end up looping forever...
24334 */
24335 if (pgd)
24336- pud_p = (pudval_t *)((pgd & PTE_PFN_MASK) + __START_KERNEL_map - phys_base);
24337+ pud_p = (pudval_t *)(__early_va(pgd & PTE_PFN_MASK));
24338 else {
24339 if (next_early_pgt >= EARLY_DYNAMIC_PAGE_TABLES) {
24340 reset_early_page_tables();
24341@@ -82,13 +82,13 @@ again:
24342 pud_p = (pudval_t *)early_dynamic_pgts[next_early_pgt++];
24343 for (i = 0; i < PTRS_PER_PUD; i++)
24344 pud_p[i] = 0;
24345- *pgd_p = (pgdval_t)pud_p - __START_KERNEL_map + phys_base + _KERNPG_TABLE;
24346+ *pgd_p = (pgdval_t)__pa(pud_p) + _KERNPG_TABLE;
24347 }
24348 pud_p += pud_index(address);
24349 pud = *pud_p;
24350
24351 if (pud)
24352- pmd_p = (pmdval_t *)((pud & PTE_PFN_MASK) + __START_KERNEL_map - phys_base);
24353+ pmd_p = (pmdval_t *)(__early_va(pud & PTE_PFN_MASK));
24354 else {
24355 if (next_early_pgt >= EARLY_DYNAMIC_PAGE_TABLES) {
24356 reset_early_page_tables();
24357@@ -98,7 +98,7 @@ again:
24358 pmd_p = (pmdval_t *)early_dynamic_pgts[next_early_pgt++];
24359 for (i = 0; i < PTRS_PER_PMD; i++)
24360 pmd_p[i] = 0;
24361- *pud_p = (pudval_t)pmd_p - __START_KERNEL_map + phys_base + _KERNPG_TABLE;
24362+ *pud_p = (pudval_t)__pa(pmd_p) + _KERNPG_TABLE;
24363 }
24364 pmd = (physaddr & PMD_MASK) + early_pmd_flags;
24365 pmd_p[pmd_index(address)] = pmd;
24366@@ -175,7 +175,6 @@ asmlinkage __visible void __init x86_64_start_kernel(char * real_mode_data)
24367 if (console_loglevel >= CONSOLE_LOGLEVEL_DEBUG)
24368 early_printk("Kernel alive\n");
24369
24370- clear_page(init_level4_pgt);
24371 /* set init_level4_pgt kernel high mapping*/
24372 init_level4_pgt[511] = early_level4_pgt[511];
24373
24374diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
24375index f36bd42..0ab4474 100644
24376--- a/arch/x86/kernel/head_32.S
24377+++ b/arch/x86/kernel/head_32.S
24378@@ -26,6 +26,12 @@
24379 /* Physical address */
24380 #define pa(X) ((X) - __PAGE_OFFSET)
24381
24382+#ifdef CONFIG_PAX_KERNEXEC
24383+#define ta(X) (X)
24384+#else
24385+#define ta(X) ((X) - __PAGE_OFFSET)
24386+#endif
24387+
24388 /*
24389 * References to members of the new_cpu_data structure.
24390 */
24391@@ -55,11 +61,7 @@
24392 * and small than max_low_pfn, otherwise will waste some page table entries
24393 */
24394
24395-#if PTRS_PER_PMD > 1
24396-#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
24397-#else
24398-#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
24399-#endif
24400+#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
24401
24402 /* Number of possible pages in the lowmem region */
24403 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
24404@@ -78,6 +80,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE
24405 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
24406
24407 /*
24408+ * Real beginning of normal "text" segment
24409+ */
24410+ENTRY(stext)
24411+ENTRY(_stext)
24412+
24413+/*
24414 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
24415 * %esi points to the real-mode code as a 32-bit pointer.
24416 * CS and DS must be 4 GB flat segments, but we don't depend on
24417@@ -85,6 +93,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
24418 * can.
24419 */
24420 __HEAD
24421+
24422+#ifdef CONFIG_PAX_KERNEXEC
24423+ jmp startup_32
24424+/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
24425+.fill PAGE_SIZE-5,1,0xcc
24426+#endif
24427+
24428 ENTRY(startup_32)
24429 movl pa(stack_start),%ecx
24430
24431@@ -106,6 +121,59 @@ ENTRY(startup_32)
24432 2:
24433 leal -__PAGE_OFFSET(%ecx),%esp
24434
24435+#ifdef CONFIG_SMP
24436+ movl $pa(cpu_gdt_table),%edi
24437+ movl $__per_cpu_load,%eax
24438+ movw %ax,GDT_ENTRY_PERCPU * 8 + 2(%edi)
24439+ rorl $16,%eax
24440+ movb %al,GDT_ENTRY_PERCPU * 8 + 4(%edi)
24441+ movb %ah,GDT_ENTRY_PERCPU * 8 + 7(%edi)
24442+ movl $__per_cpu_end - 1,%eax
24443+ subl $__per_cpu_start,%eax
24444+ movw %ax,GDT_ENTRY_PERCPU * 8 + 0(%edi)
24445+#endif
24446+
24447+#ifdef CONFIG_PAX_MEMORY_UDEREF
24448+ movl $NR_CPUS,%ecx
24449+ movl $pa(cpu_gdt_table),%edi
24450+1:
24451+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
24452+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
24453+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
24454+ addl $PAGE_SIZE_asm,%edi
24455+ loop 1b
24456+#endif
24457+
24458+#ifdef CONFIG_PAX_KERNEXEC
24459+ movl $pa(boot_gdt),%edi
24460+ movl $__LOAD_PHYSICAL_ADDR,%eax
24461+ movw %ax,GDT_ENTRY_BOOT_CS * 8 + 2(%edi)
24462+ rorl $16,%eax
24463+ movb %al,GDT_ENTRY_BOOT_CS * 8 + 4(%edi)
24464+ movb %ah,GDT_ENTRY_BOOT_CS * 8 + 7(%edi)
24465+ rorl $16,%eax
24466+
24467+ ljmp $(__BOOT_CS),$1f
24468+1:
24469+
24470+ movl $NR_CPUS,%ecx
24471+ movl $pa(cpu_gdt_table),%edi
24472+ addl $__PAGE_OFFSET,%eax
24473+1:
24474+ movb $0xc0,GDT_ENTRY_KERNEL_CS * 8 + 6(%edi)
24475+ movb $0xc0,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 6(%edi)
24476+ movw %ax,GDT_ENTRY_KERNEL_CS * 8 + 2(%edi)
24477+ movw %ax,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 2(%edi)
24478+ rorl $16,%eax
24479+ movb %al,GDT_ENTRY_KERNEL_CS * 8 + 4(%edi)
24480+ movb %al,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 4(%edi)
24481+ movb %ah,GDT_ENTRY_KERNEL_CS * 8 + 7(%edi)
24482+ movb %ah,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 7(%edi)
24483+ rorl $16,%eax
24484+ addl $PAGE_SIZE_asm,%edi
24485+ loop 1b
24486+#endif
24487+
24488 /*
24489 * Clear BSS first so that there are no surprises...
24490 */
24491@@ -201,8 +269,11 @@ ENTRY(startup_32)
24492 movl %eax, pa(max_pfn_mapped)
24493
24494 /* Do early initialization of the fixmap area */
24495- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
24496- movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
24497+#ifdef CONFIG_COMPAT_VDSO
24498+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
24499+#else
24500+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
24501+#endif
24502 #else /* Not PAE */
24503
24504 page_pde_offset = (__PAGE_OFFSET >> 20);
24505@@ -232,8 +303,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
24506 movl %eax, pa(max_pfn_mapped)
24507
24508 /* Do early initialization of the fixmap area */
24509- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
24510- movl %eax,pa(initial_page_table+0xffc)
24511+#ifdef CONFIG_COMPAT_VDSO
24512+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
24513+#else
24514+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
24515+#endif
24516 #endif
24517
24518 #ifdef CONFIG_PARAVIRT
24519@@ -247,9 +321,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
24520 cmpl $num_subarch_entries, %eax
24521 jae bad_subarch
24522
24523- movl pa(subarch_entries)(,%eax,4), %eax
24524- subl $__PAGE_OFFSET, %eax
24525- jmp *%eax
24526+ jmp *pa(subarch_entries)(,%eax,4)
24527
24528 bad_subarch:
24529 WEAK(lguest_entry)
24530@@ -261,10 +333,10 @@ WEAK(xen_entry)
24531 __INITDATA
24532
24533 subarch_entries:
24534- .long default_entry /* normal x86/PC */
24535- .long lguest_entry /* lguest hypervisor */
24536- .long xen_entry /* Xen hypervisor */
24537- .long default_entry /* Moorestown MID */
24538+ .long ta(default_entry) /* normal x86/PC */
24539+ .long ta(lguest_entry) /* lguest hypervisor */
24540+ .long ta(xen_entry) /* Xen hypervisor */
24541+ .long ta(default_entry) /* Moorestown MID */
24542 num_subarch_entries = (. - subarch_entries) / 4
24543 .previous
24544 #else
24545@@ -354,6 +426,7 @@ default_entry:
24546 movl pa(mmu_cr4_features),%eax
24547 movl %eax,%cr4
24548
24549+#ifdef CONFIG_X86_PAE
24550 testb $X86_CR4_PAE, %al # check if PAE is enabled
24551 jz enable_paging
24552
24553@@ -382,6 +455,9 @@ default_entry:
24554 /* Make changes effective */
24555 wrmsr
24556
24557+ btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
24558+#endif
24559+
24560 enable_paging:
24561
24562 /*
24563@@ -449,14 +525,20 @@ is486:
24564 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
24565 movl %eax,%ss # after changing gdt.
24566
24567- movl $(__USER_DS),%eax # DS/ES contains default USER segment
24568+# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
24569 movl %eax,%ds
24570 movl %eax,%es
24571
24572 movl $(__KERNEL_PERCPU), %eax
24573 movl %eax,%fs # set this cpu's percpu
24574
24575+#ifdef CONFIG_CC_STACKPROTECTOR
24576 movl $(__KERNEL_STACK_CANARY),%eax
24577+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
24578+ movl $(__USER_DS),%eax
24579+#else
24580+ xorl %eax,%eax
24581+#endif
24582 movl %eax,%gs
24583
24584 xorl %eax,%eax # Clear LDT
24585@@ -512,8 +594,11 @@ setup_once:
24586 * relocation. Manually set base address in stack canary
24587 * segment descriptor.
24588 */
24589- movl $gdt_page,%eax
24590+ movl $cpu_gdt_table,%eax
24591 movl $stack_canary,%ecx
24592+#ifdef CONFIG_SMP
24593+ addl $__per_cpu_load,%ecx
24594+#endif
24595 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
24596 shrl $16, %ecx
24597 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
24598@@ -548,7 +633,7 @@ ENTRY(early_idt_handler)
24599 cmpl $2,(%esp) # X86_TRAP_NMI
24600 je is_nmi # Ignore NMI
24601
24602- cmpl $2,%ss:early_recursion_flag
24603+ cmpl $1,%ss:early_recursion_flag
24604 je hlt_loop
24605 incl %ss:early_recursion_flag
24606
24607@@ -586,8 +671,8 @@ ENTRY(early_idt_handler)
24608 pushl (20+6*4)(%esp) /* trapno */
24609 pushl $fault_msg
24610 call printk
24611-#endif
24612 call dump_stack
24613+#endif
24614 hlt_loop:
24615 hlt
24616 jmp hlt_loop
24617@@ -607,8 +692,11 @@ ENDPROC(early_idt_handler)
24618 /* This is the default interrupt "handler" :-) */
24619 ALIGN
24620 ignore_int:
24621- cld
24622 #ifdef CONFIG_PRINTK
24623+ cmpl $2,%ss:early_recursion_flag
24624+ je hlt_loop
24625+ incl %ss:early_recursion_flag
24626+ cld
24627 pushl %eax
24628 pushl %ecx
24629 pushl %edx
24630@@ -617,9 +705,6 @@ ignore_int:
24631 movl $(__KERNEL_DS),%eax
24632 movl %eax,%ds
24633 movl %eax,%es
24634- cmpl $2,early_recursion_flag
24635- je hlt_loop
24636- incl early_recursion_flag
24637 pushl 16(%esp)
24638 pushl 24(%esp)
24639 pushl 32(%esp)
24640@@ -653,29 +738,34 @@ ENTRY(setup_once_ref)
24641 /*
24642 * BSS section
24643 */
24644-__PAGE_ALIGNED_BSS
24645- .align PAGE_SIZE
24646 #ifdef CONFIG_X86_PAE
24647+.section .initial_pg_pmd,"a",@progbits
24648 initial_pg_pmd:
24649 .fill 1024*KPMDS,4,0
24650 #else
24651+.section .initial_page_table,"a",@progbits
24652 ENTRY(initial_page_table)
24653 .fill 1024,4,0
24654 #endif
24655+.section .initial_pg_fixmap,"a",@progbits
24656 initial_pg_fixmap:
24657 .fill 1024,4,0
24658+.section .empty_zero_page,"a",@progbits
24659 ENTRY(empty_zero_page)
24660 .fill 4096,1,0
24661+.section .swapper_pg_dir,"a",@progbits
24662 ENTRY(swapper_pg_dir)
24663+#ifdef CONFIG_X86_PAE
24664+ .fill 4,8,0
24665+#else
24666 .fill 1024,4,0
24667+#endif
24668
24669 /*
24670 * This starts the data section.
24671 */
24672 #ifdef CONFIG_X86_PAE
24673-__PAGE_ALIGNED_DATA
24674- /* Page-aligned for the benefit of paravirt? */
24675- .align PAGE_SIZE
24676+.section .initial_page_table,"a",@progbits
24677 ENTRY(initial_page_table)
24678 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
24679 # if KPMDS == 3
24680@@ -694,12 +784,20 @@ ENTRY(initial_page_table)
24681 # error "Kernel PMDs should be 1, 2 or 3"
24682 # endif
24683 .align PAGE_SIZE /* needs to be page-sized too */
24684+
24685+#ifdef CONFIG_PAX_PER_CPU_PGD
24686+ENTRY(cpu_pgd)
24687+ .rept 2*NR_CPUS
24688+ .fill 4,8,0
24689+ .endr
24690+#endif
24691+
24692 #endif
24693
24694 .data
24695 .balign 4
24696 ENTRY(stack_start)
24697- .long init_thread_union+THREAD_SIZE
24698+ .long init_thread_union+THREAD_SIZE-8
24699
24700 __INITRODATA
24701 int_msg:
24702@@ -727,7 +825,7 @@ fault_msg:
24703 * segment size, and 32-bit linear address value:
24704 */
24705
24706- .data
24707+.section .rodata,"a",@progbits
24708 .globl boot_gdt_descr
24709 .globl idt_descr
24710
24711@@ -736,7 +834,7 @@ fault_msg:
24712 .word 0 # 32 bit align gdt_desc.address
24713 boot_gdt_descr:
24714 .word __BOOT_DS+7
24715- .long boot_gdt - __PAGE_OFFSET
24716+ .long pa(boot_gdt)
24717
24718 .word 0 # 32-bit align idt_desc.address
24719 idt_descr:
24720@@ -747,7 +845,7 @@ idt_descr:
24721 .word 0 # 32 bit align gdt_desc.address
24722 ENTRY(early_gdt_descr)
24723 .word GDT_ENTRIES*8-1
24724- .long gdt_page /* Overwritten for secondary CPUs */
24725+ .long cpu_gdt_table /* Overwritten for secondary CPUs */
24726
24727 /*
24728 * The boot_gdt must mirror the equivalent in setup.S and is
24729@@ -756,5 +854,65 @@ ENTRY(early_gdt_descr)
24730 .align L1_CACHE_BYTES
24731 ENTRY(boot_gdt)
24732 .fill GDT_ENTRY_BOOT_CS,8,0
24733- .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
24734- .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
24735+ .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
24736+ .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
24737+
24738+ .align PAGE_SIZE_asm
24739+ENTRY(cpu_gdt_table)
24740+ .rept NR_CPUS
24741+ .quad 0x0000000000000000 /* NULL descriptor */
24742+ .quad 0x0000000000000000 /* 0x0b reserved */
24743+ .quad 0x0000000000000000 /* 0x13 reserved */
24744+ .quad 0x0000000000000000 /* 0x1b reserved */
24745+
24746+#ifdef CONFIG_PAX_KERNEXEC
24747+ .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
24748+#else
24749+ .quad 0x0000000000000000 /* 0x20 unused */
24750+#endif
24751+
24752+ .quad 0x0000000000000000 /* 0x28 unused */
24753+ .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
24754+ .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
24755+ .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
24756+ .quad 0x0000000000000000 /* 0x4b reserved */
24757+ .quad 0x0000000000000000 /* 0x53 reserved */
24758+ .quad 0x0000000000000000 /* 0x5b reserved */
24759+
24760+ .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
24761+ .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
24762+ .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
24763+ .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
24764+
24765+ .quad 0x0000000000000000 /* 0x80 TSS descriptor */
24766+ .quad 0x0000000000000000 /* 0x88 LDT descriptor */
24767+
24768+ /*
24769+ * Segments used for calling PnP BIOS have byte granularity.
24770+ * The code segments and data segments have fixed 64k limits,
24771+ * the transfer segment sizes are set at run time.
24772+ */
24773+ .quad 0x00409b000000ffff /* 0x90 32-bit code */
24774+ .quad 0x00009b000000ffff /* 0x98 16-bit code */
24775+ .quad 0x000093000000ffff /* 0xa0 16-bit data */
24776+ .quad 0x0000930000000000 /* 0xa8 16-bit data */
24777+ .quad 0x0000930000000000 /* 0xb0 16-bit data */
24778+
24779+ /*
24780+ * The APM segments have byte granularity and their bases
24781+ * are set at run time. All have 64k limits.
24782+ */
24783+ .quad 0x00409b000000ffff /* 0xb8 APM CS code */
24784+ .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
24785+ .quad 0x004093000000ffff /* 0xc8 APM DS data */
24786+
24787+ .quad 0x00c093000000ffff /* 0xd0 - ESPFIX SS */
24788+ .quad 0x0040930000000000 /* 0xd8 - PERCPU */
24789+ .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
24790+ .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
24791+ .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
24792+ .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
24793+
24794+ /* Be sure this is zeroed to avoid false validations in Xen */
24795+ .fill PAGE_SIZE_asm - GDT_SIZE,1,0
24796+ .endr
24797diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
24798index a468c0a..8b5a879 100644
24799--- a/arch/x86/kernel/head_64.S
24800+++ b/arch/x86/kernel/head_64.S
24801@@ -20,6 +20,8 @@
24802 #include <asm/processor-flags.h>
24803 #include <asm/percpu.h>
24804 #include <asm/nops.h>
24805+#include <asm/cpufeature.h>
24806+#include <asm/alternative-asm.h>
24807
24808 #ifdef CONFIG_PARAVIRT
24809 #include <asm/asm-offsets.h>
24810@@ -41,6 +43,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
24811 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
24812 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
24813 L3_START_KERNEL = pud_index(__START_KERNEL_map)
24814+L4_VMALLOC_START = pgd_index(VMALLOC_START)
24815+L3_VMALLOC_START = pud_index(VMALLOC_START)
24816+L4_VMALLOC_END = pgd_index(VMALLOC_END)
24817+L3_VMALLOC_END = pud_index(VMALLOC_END)
24818+L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
24819+L3_VMEMMAP_START = pud_index(VMEMMAP_START)
24820
24821 .text
24822 __HEAD
24823@@ -89,11 +97,24 @@ startup_64:
24824 * Fixup the physical addresses in the page table
24825 */
24826 addq %rbp, early_level4_pgt + (L4_START_KERNEL*8)(%rip)
24827+ addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
24828+ addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
24829+ addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
24830+ addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
24831+ addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
24832
24833- addq %rbp, level3_kernel_pgt + (510*8)(%rip)
24834- addq %rbp, level3_kernel_pgt + (511*8)(%rip)
24835+ addq %rbp, level3_ident_pgt + (0*8)(%rip)
24836+#ifndef CONFIG_XEN
24837+ addq %rbp, level3_ident_pgt + (1*8)(%rip)
24838+#endif
24839+
24840+ addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
24841+
24842+ addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
24843+ addq %rbp, level3_kernel_pgt + ((L3_START_KERNEL+1)*8)(%rip)
24844
24845 addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
24846+ addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
24847
24848 /*
24849 * Set up the identity mapping for the switchover. These
24850@@ -174,11 +195,12 @@ ENTRY(secondary_startup_64)
24851 * after the boot processor executes this code.
24852 */
24853
24854+ orq $-1, %rbp
24855 movq $(init_level4_pgt - __START_KERNEL_map), %rax
24856 1:
24857
24858- /* Enable PAE mode and PGE */
24859- movl $(X86_CR4_PAE | X86_CR4_PGE), %ecx
24860+ /* Enable PAE mode and PSE/PGE */
24861+ movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %ecx
24862 movq %rcx, %cr4
24863
24864 /* Setup early boot stage 4 level pagetables. */
24865@@ -199,10 +221,19 @@ ENTRY(secondary_startup_64)
24866 movl $MSR_EFER, %ecx
24867 rdmsr
24868 btsl $_EFER_SCE, %eax /* Enable System Call */
24869- btl $20,%edi /* No Execute supported? */
24870+ btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
24871 jnc 1f
24872 btsl $_EFER_NX, %eax
24873+ cmpq $-1, %rbp
24874+ je 1f
24875 btsq $_PAGE_BIT_NX,early_pmd_flags(%rip)
24876+ btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_PAGE_OFFSET(%rip)
24877+ btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMALLOC_START(%rip)
24878+ btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMALLOC_END(%rip)
24879+ btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMEMMAP_START(%rip)
24880+ btsq $_PAGE_BIT_NX, level2_fixmap_pgt + 8*506(%rip)
24881+ btsq $_PAGE_BIT_NX, level2_fixmap_pgt + 8*507(%rip)
24882+ btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
24883 1: wrmsr /* Make changes effective */
24884
24885 /* Setup cr0 */
24886@@ -282,6 +313,7 @@ ENTRY(secondary_startup_64)
24887 * REX.W + FF /5 JMP m16:64 Jump far, absolute indirect,
24888 * address given in m16:64.
24889 */
24890+ pax_set_fptr_mask
24891 movq initial_code(%rip),%rax
24892 pushq $0 # fake return address to stop unwinder
24893 pushq $__KERNEL_CS # set correct cs
24894@@ -313,7 +345,7 @@ ENDPROC(start_cpu0)
24895 .quad INIT_PER_CPU_VAR(irq_stack_union)
24896
24897 GLOBAL(stack_start)
24898- .quad init_thread_union+THREAD_SIZE-8
24899+ .quad init_thread_union+THREAD_SIZE-16
24900 .word 0
24901 __FINITDATA
24902
24903@@ -391,7 +423,7 @@ ENTRY(early_idt_handler)
24904 call dump_stack
24905 #ifdef CONFIG_KALLSYMS
24906 leaq early_idt_ripmsg(%rip),%rdi
24907- movq 40(%rsp),%rsi # %rip again
24908+ movq 88(%rsp),%rsi # %rip again
24909 call __print_symbol
24910 #endif
24911 #endif /* EARLY_PRINTK */
24912@@ -420,6 +452,7 @@ ENDPROC(early_idt_handler)
24913 early_recursion_flag:
24914 .long 0
24915
24916+ .section .rodata,"a",@progbits
24917 #ifdef CONFIG_EARLY_PRINTK
24918 early_idt_msg:
24919 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
24920@@ -447,29 +480,52 @@ NEXT_PAGE(early_level4_pgt)
24921 NEXT_PAGE(early_dynamic_pgts)
24922 .fill 512*EARLY_DYNAMIC_PAGE_TABLES,8,0
24923
24924- .data
24925+ .section .rodata,"a",@progbits
24926
24927-#ifndef CONFIG_XEN
24928 NEXT_PAGE(init_level4_pgt)
24929- .fill 512,8,0
24930-#else
24931-NEXT_PAGE(init_level4_pgt)
24932- .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
24933 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
24934 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
24935+ .org init_level4_pgt + L4_VMALLOC_START*8, 0
24936+ .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
24937+ .org init_level4_pgt + L4_VMALLOC_END*8, 0
24938+ .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
24939+ .org init_level4_pgt + L4_VMEMMAP_START*8, 0
24940+ .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
24941 .org init_level4_pgt + L4_START_KERNEL*8, 0
24942 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
24943 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
24944
24945+#ifdef CONFIG_PAX_PER_CPU_PGD
24946+NEXT_PAGE(cpu_pgd)
24947+ .rept 2*NR_CPUS
24948+ .fill 512,8,0
24949+ .endr
24950+#endif
24951+
24952 NEXT_PAGE(level3_ident_pgt)
24953 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
24954+#ifdef CONFIG_XEN
24955 .fill 511, 8, 0
24956+#else
24957+ .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
24958+ .fill 510,8,0
24959+#endif
24960+
24961+NEXT_PAGE(level3_vmalloc_start_pgt)
24962+ .fill 512,8,0
24963+
24964+NEXT_PAGE(level3_vmalloc_end_pgt)
24965+ .fill 512,8,0
24966+
24967+NEXT_PAGE(level3_vmemmap_pgt)
24968+ .fill L3_VMEMMAP_START,8,0
24969+ .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
24970+
24971 NEXT_PAGE(level2_ident_pgt)
24972- /* Since I easily can, map the first 1G.
24973+ /* Since I easily can, map the first 2G.
24974 * Don't set NX because code runs from these pages.
24975 */
24976- PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
24977-#endif
24978+ PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
24979
24980 NEXT_PAGE(level3_kernel_pgt)
24981 .fill L3_START_KERNEL,8,0
24982@@ -477,6 +533,9 @@ NEXT_PAGE(level3_kernel_pgt)
24983 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
24984 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
24985
24986+NEXT_PAGE(level2_vmemmap_pgt)
24987+ .fill 512,8,0
24988+
24989 NEXT_PAGE(level2_kernel_pgt)
24990 /*
24991 * 512 MB kernel mapping. We spend a full page on this pagetable
24992@@ -494,28 +553,64 @@ NEXT_PAGE(level2_kernel_pgt)
24993 NEXT_PAGE(level2_fixmap_pgt)
24994 .fill 506,8,0
24995 .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
24996- /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
24997- .fill 5,8,0
24998+ .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
24999+ /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
25000+ .fill 4,8,0
25001
25002 NEXT_PAGE(level1_fixmap_pgt)
25003 .fill 512,8,0
25004
25005+NEXT_PAGE(level1_vsyscall_pgt)
25006+ .fill 512,8,0
25007+
25008 #undef PMDS
25009
25010- .data
25011+ .align PAGE_SIZE
25012+ENTRY(cpu_gdt_table)
25013+ .rept NR_CPUS
25014+ .quad 0x0000000000000000 /* NULL descriptor */
25015+ .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
25016+ .quad 0x00af9b000000ffff /* __KERNEL_CS */
25017+ .quad 0x00cf93000000ffff /* __KERNEL_DS */
25018+ .quad 0x00cffb000000ffff /* __USER32_CS */
25019+ .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
25020+ .quad 0x00affb000000ffff /* __USER_CS */
25021+
25022+#ifdef CONFIG_PAX_KERNEXEC
25023+ .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
25024+#else
25025+ .quad 0x0 /* unused */
25026+#endif
25027+
25028+ .quad 0,0 /* TSS */
25029+ .quad 0,0 /* LDT */
25030+ .quad 0,0,0 /* three TLS descriptors */
25031+ .quad 0x0000f40000000000 /* node/CPU stored in limit */
25032+ /* asm/segment.h:GDT_ENTRIES must match this */
25033+
25034+#ifdef CONFIG_PAX_MEMORY_UDEREF
25035+ .quad 0x00cf93000000ffff /* __UDEREF_KERNEL_DS */
25036+#else
25037+ .quad 0x0 /* unused */
25038+#endif
25039+
25040+ /* zero the remaining page */
25041+ .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
25042+ .endr
25043+
25044 .align 16
25045 .globl early_gdt_descr
25046 early_gdt_descr:
25047 .word GDT_ENTRIES*8-1
25048 early_gdt_descr_base:
25049- .quad INIT_PER_CPU_VAR(gdt_page)
25050+ .quad cpu_gdt_table
25051
25052 ENTRY(phys_base)
25053 /* This must match the first entry in level2_kernel_pgt */
25054 .quad 0x0000000000000000
25055
25056 #include "../../x86/xen/xen-head.S"
25057-
25058- __PAGE_ALIGNED_BSS
25059+
25060+ .section .rodata,"a",@progbits
25061 NEXT_PAGE(empty_zero_page)
25062 .skip PAGE_SIZE
25063diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
25064index 05fd74f..c3548b1 100644
25065--- a/arch/x86/kernel/i386_ksyms_32.c
25066+++ b/arch/x86/kernel/i386_ksyms_32.c
25067@@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
25068 EXPORT_SYMBOL(cmpxchg8b_emu);
25069 #endif
25070
25071+EXPORT_SYMBOL_GPL(cpu_gdt_table);
25072+
25073 /* Networking helper routines. */
25074 EXPORT_SYMBOL(csum_partial_copy_generic);
25075+EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
25076+EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
25077
25078 EXPORT_SYMBOL(__get_user_1);
25079 EXPORT_SYMBOL(__get_user_2);
25080@@ -44,3 +48,11 @@ EXPORT_SYMBOL(___preempt_schedule);
25081 EXPORT_SYMBOL(___preempt_schedule_context);
25082 #endif
25083 #endif
25084+
25085+#ifdef CONFIG_PAX_KERNEXEC
25086+EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
25087+#endif
25088+
25089+#ifdef CONFIG_PAX_PER_CPU_PGD
25090+EXPORT_SYMBOL(cpu_pgd);
25091+#endif
25092diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
25093index a9a4229..6f4d476 100644
25094--- a/arch/x86/kernel/i387.c
25095+++ b/arch/x86/kernel/i387.c
25096@@ -51,7 +51,7 @@ static inline bool interrupted_kernel_fpu_idle(void)
25097 static inline bool interrupted_user_mode(void)
25098 {
25099 struct pt_regs *regs = get_irq_regs();
25100- return regs && user_mode_vm(regs);
25101+ return regs && user_mode(regs);
25102 }
25103
25104 /*
25105diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
25106index e7cc537..67d7372 100644
25107--- a/arch/x86/kernel/i8259.c
25108+++ b/arch/x86/kernel/i8259.c
25109@@ -110,7 +110,7 @@ static int i8259A_irq_pending(unsigned int irq)
25110 static void make_8259A_irq(unsigned int irq)
25111 {
25112 disable_irq_nosync(irq);
25113- io_apic_irqs &= ~(1<<irq);
25114+ io_apic_irqs &= ~(1UL<<irq);
25115 irq_set_chip_and_handler(irq, &i8259A_chip, handle_level_irq);
25116 enable_irq(irq);
25117 }
25118@@ -208,7 +208,7 @@ spurious_8259A_irq:
25119 "spurious 8259A interrupt: IRQ%d.\n", irq);
25120 spurious_irq_mask |= irqmask;
25121 }
25122- atomic_inc(&irq_err_count);
25123+ atomic_inc_unchecked(&irq_err_count);
25124 /*
25125 * Theoretically we do not have to handle this IRQ,
25126 * but in Linux this does not cause problems and is
25127@@ -349,14 +349,16 @@ static void init_8259A(int auto_eoi)
25128 /* (slave's support for AEOI in flat mode is to be investigated) */
25129 outb_pic(SLAVE_ICW4_DEFAULT, PIC_SLAVE_IMR);
25130
25131+ pax_open_kernel();
25132 if (auto_eoi)
25133 /*
25134 * In AEOI mode we just have to mask the interrupt
25135 * when acking.
25136 */
25137- i8259A_chip.irq_mask_ack = disable_8259A_irq;
25138+ *(void **)&i8259A_chip.irq_mask_ack = disable_8259A_irq;
25139 else
25140- i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
25141+ *(void **)&i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
25142+ pax_close_kernel();
25143
25144 udelay(100); /* wait for 8259A to initialize */
25145
25146diff --git a/arch/x86/kernel/io_delay.c b/arch/x86/kernel/io_delay.c
25147index a979b5b..1d6db75 100644
25148--- a/arch/x86/kernel/io_delay.c
25149+++ b/arch/x86/kernel/io_delay.c
25150@@ -58,7 +58,7 @@ static int __init dmi_io_delay_0xed_port(const struct dmi_system_id *id)
25151 * Quirk table for systems that misbehave (lock up, etc.) if port
25152 * 0x80 is used:
25153 */
25154-static struct dmi_system_id __initdata io_delay_0xed_port_dmi_table[] = {
25155+static const struct dmi_system_id __initconst io_delay_0xed_port_dmi_table[] = {
25156 {
25157 .callback = dmi_io_delay_0xed_port,
25158 .ident = "Compaq Presario V6000",
25159diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
25160index 4ddaf66..49d5c18 100644
25161--- a/arch/x86/kernel/ioport.c
25162+++ b/arch/x86/kernel/ioport.c
25163@@ -6,6 +6,7 @@
25164 #include <linux/sched.h>
25165 #include <linux/kernel.h>
25166 #include <linux/capability.h>
25167+#include <linux/security.h>
25168 #include <linux/errno.h>
25169 #include <linux/types.h>
25170 #include <linux/ioport.h>
25171@@ -30,6 +31,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
25172 return -EINVAL;
25173 if (turn_on && !capable(CAP_SYS_RAWIO))
25174 return -EPERM;
25175+#ifdef CONFIG_GRKERNSEC_IO
25176+ if (turn_on && grsec_disable_privio) {
25177+ gr_handle_ioperm();
25178+ return -ENODEV;
25179+ }
25180+#endif
25181
25182 /*
25183 * If it's the first ioperm() call in this thread's lifetime, set the
25184@@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
25185 * because the ->io_bitmap_max value must match the bitmap
25186 * contents:
25187 */
25188- tss = &per_cpu(init_tss, get_cpu());
25189+ tss = init_tss + get_cpu();
25190
25191 if (turn_on)
25192 bitmap_clear(t->io_bitmap_ptr, from, num);
25193@@ -105,6 +112,12 @@ SYSCALL_DEFINE1(iopl, unsigned int, level)
25194 if (level > old) {
25195 if (!capable(CAP_SYS_RAWIO))
25196 return -EPERM;
25197+#ifdef CONFIG_GRKERNSEC_IO
25198+ if (grsec_disable_privio) {
25199+ gr_handle_iopl();
25200+ return -ENODEV;
25201+ }
25202+#endif
25203 }
25204 regs->flags = (regs->flags & ~X86_EFLAGS_IOPL) | (level << 12);
25205 t->iopl = level << 12;
25206diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
25207index 922d285..6d20692 100644
25208--- a/arch/x86/kernel/irq.c
25209+++ b/arch/x86/kernel/irq.c
25210@@ -22,7 +22,7 @@
25211 #define CREATE_TRACE_POINTS
25212 #include <asm/trace/irq_vectors.h>
25213
25214-atomic_t irq_err_count;
25215+atomic_unchecked_t irq_err_count;
25216
25217 /* Function pointer for generic interrupt vector handling */
25218 void (*x86_platform_ipi_callback)(void) = NULL;
25219@@ -132,9 +132,9 @@ int arch_show_interrupts(struct seq_file *p, int prec)
25220 seq_printf(p, "%10u ", irq_stats(j)->irq_hv_callback_count);
25221 seq_printf(p, " Hypervisor callback interrupts\n");
25222 #endif
25223- seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
25224+ seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
25225 #if defined(CONFIG_X86_IO_APIC)
25226- seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
25227+ seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
25228 #endif
25229 return 0;
25230 }
25231@@ -174,7 +174,7 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
25232
25233 u64 arch_irq_stat(void)
25234 {
25235- u64 sum = atomic_read(&irq_err_count);
25236+ u64 sum = atomic_read_unchecked(&irq_err_count);
25237 return sum;
25238 }
25239
25240diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
25241index 63ce838..2ea3e06 100644
25242--- a/arch/x86/kernel/irq_32.c
25243+++ b/arch/x86/kernel/irq_32.c
25244@@ -29,6 +29,8 @@ EXPORT_PER_CPU_SYMBOL(irq_regs);
25245
25246 #ifdef CONFIG_DEBUG_STACKOVERFLOW
25247
25248+extern void gr_handle_kernel_exploit(void);
25249+
25250 int sysctl_panic_on_stackoverflow __read_mostly;
25251
25252 /* Debugging check for stack overflow: is there less than 1KB free? */
25253@@ -39,13 +41,14 @@ static int check_stack_overflow(void)
25254 __asm__ __volatile__("andl %%esp,%0" :
25255 "=r" (sp) : "0" (THREAD_SIZE - 1));
25256
25257- return sp < (sizeof(struct thread_info) + STACK_WARN);
25258+ return sp < STACK_WARN;
25259 }
25260
25261 static void print_stack_overflow(void)
25262 {
25263 printk(KERN_WARNING "low stack detected by irq handler\n");
25264 dump_stack();
25265+ gr_handle_kernel_exploit();
25266 if (sysctl_panic_on_stackoverflow)
25267 panic("low stack detected by irq handler - check messages\n");
25268 }
25269@@ -84,10 +87,9 @@ static inline void *current_stack(void)
25270 static inline int
25271 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
25272 {
25273- struct irq_stack *curstk, *irqstk;
25274+ struct irq_stack *irqstk;
25275 u32 *isp, *prev_esp, arg1, arg2;
25276
25277- curstk = (struct irq_stack *) current_stack();
25278 irqstk = __this_cpu_read(hardirq_stack);
25279
25280 /*
25281@@ -96,15 +98,19 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
25282 * handler) we can't do that and just have to keep using the
25283 * current stack (which is the irq stack already after all)
25284 */
25285- if (unlikely(curstk == irqstk))
25286+ if (unlikely((void *)current_stack_pointer - (void *)irqstk < THREAD_SIZE))
25287 return 0;
25288
25289- isp = (u32 *) ((char *)irqstk + sizeof(*irqstk));
25290+ isp = (u32 *) ((char *)irqstk + sizeof(*irqstk) - 8);
25291
25292 /* Save the next esp at the bottom of the stack */
25293 prev_esp = (u32 *)irqstk;
25294 *prev_esp = current_stack_pointer;
25295
25296+#ifdef CONFIG_PAX_MEMORY_UDEREF
25297+ __set_fs(MAKE_MM_SEG(0));
25298+#endif
25299+
25300 if (unlikely(overflow))
25301 call_on_stack(print_stack_overflow, isp);
25302
25303@@ -115,6 +121,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
25304 : "0" (irq), "1" (desc), "2" (isp),
25305 "D" (desc->handle_irq)
25306 : "memory", "cc", "ecx");
25307+
25308+#ifdef CONFIG_PAX_MEMORY_UDEREF
25309+ __set_fs(current_thread_info()->addr_limit);
25310+#endif
25311+
25312 return 1;
25313 }
25314
25315@@ -123,32 +134,18 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
25316 */
25317 void irq_ctx_init(int cpu)
25318 {
25319- struct irq_stack *irqstk;
25320-
25321 if (per_cpu(hardirq_stack, cpu))
25322 return;
25323
25324- irqstk = page_address(alloc_pages_node(cpu_to_node(cpu),
25325- THREADINFO_GFP,
25326- THREAD_SIZE_ORDER));
25327- per_cpu(hardirq_stack, cpu) = irqstk;
25328-
25329- irqstk = page_address(alloc_pages_node(cpu_to_node(cpu),
25330- THREADINFO_GFP,
25331- THREAD_SIZE_ORDER));
25332- per_cpu(softirq_stack, cpu) = irqstk;
25333-
25334- printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
25335- cpu, per_cpu(hardirq_stack, cpu), per_cpu(softirq_stack, cpu));
25336+ per_cpu(hardirq_stack, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
25337+ per_cpu(softirq_stack, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
25338 }
25339
25340 void do_softirq_own_stack(void)
25341 {
25342- struct thread_info *curstk;
25343 struct irq_stack *irqstk;
25344 u32 *isp, *prev_esp;
25345
25346- curstk = current_stack();
25347 irqstk = __this_cpu_read(softirq_stack);
25348
25349 /* build the stack frame on the softirq stack */
25350@@ -158,7 +155,16 @@ void do_softirq_own_stack(void)
25351 prev_esp = (u32 *)irqstk;
25352 *prev_esp = current_stack_pointer;
25353
25354+#ifdef CONFIG_PAX_MEMORY_UDEREF
25355+ __set_fs(MAKE_MM_SEG(0));
25356+#endif
25357+
25358 call_on_stack(__do_softirq, isp);
25359+
25360+#ifdef CONFIG_PAX_MEMORY_UDEREF
25361+ __set_fs(current_thread_info()->addr_limit);
25362+#endif
25363+
25364 }
25365
25366 bool handle_irq(unsigned irq, struct pt_regs *regs)
25367@@ -172,7 +178,7 @@ bool handle_irq(unsigned irq, struct pt_regs *regs)
25368 if (unlikely(!desc))
25369 return false;
25370
25371- if (user_mode_vm(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
25372+ if (user_mode(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
25373 if (unlikely(overflow))
25374 print_stack_overflow();
25375 desc->handle_irq(irq, desc);
25376diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
25377index e4b503d..824fce8 100644
25378--- a/arch/x86/kernel/irq_64.c
25379+++ b/arch/x86/kernel/irq_64.c
25380@@ -26,6 +26,8 @@ EXPORT_PER_CPU_SYMBOL(irq_stat);
25381 DEFINE_PER_CPU(struct pt_regs *, irq_regs);
25382 EXPORT_PER_CPU_SYMBOL(irq_regs);
25383
25384+extern void gr_handle_kernel_exploit(void);
25385+
25386 int sysctl_panic_on_stackoverflow;
25387
25388 /*
25389@@ -44,7 +46,7 @@ static inline void stack_overflow_check(struct pt_regs *regs)
25390 u64 estack_top, estack_bottom;
25391 u64 curbase = (u64)task_stack_page(current);
25392
25393- if (user_mode_vm(regs))
25394+ if (user_mode(regs))
25395 return;
25396
25397 if (regs->sp >= curbase + sizeof(struct thread_info) +
25398@@ -69,6 +71,8 @@ static inline void stack_overflow_check(struct pt_regs *regs)
25399 irq_stack_top, irq_stack_bottom,
25400 estack_top, estack_bottom);
25401
25402+ gr_handle_kernel_exploit();
25403+
25404 if (sysctl_panic_on_stackoverflow)
25405 panic("low stack detected by irq handler - check messages\n");
25406 #endif
25407diff --git a/arch/x86/kernel/jump_label.c b/arch/x86/kernel/jump_label.c
25408index 26d5a55..a01160a 100644
25409--- a/arch/x86/kernel/jump_label.c
25410+++ b/arch/x86/kernel/jump_label.c
25411@@ -51,7 +51,7 @@ static void __jump_label_transform(struct jump_entry *entry,
25412 * Jump label is enabled for the first time.
25413 * So we expect a default_nop...
25414 */
25415- if (unlikely(memcmp((void *)entry->code, default_nop, 5)
25416+ if (unlikely(memcmp((void *)ktla_ktva(entry->code), default_nop, 5)
25417 != 0))
25418 bug_at((void *)entry->code, __LINE__);
25419 } else {
25420@@ -59,7 +59,7 @@ static void __jump_label_transform(struct jump_entry *entry,
25421 * ...otherwise expect an ideal_nop. Otherwise
25422 * something went horribly wrong.
25423 */
25424- if (unlikely(memcmp((void *)entry->code, ideal_nop, 5)
25425+ if (unlikely(memcmp((void *)ktla_ktva(entry->code), ideal_nop, 5)
25426 != 0))
25427 bug_at((void *)entry->code, __LINE__);
25428 }
25429@@ -75,13 +75,13 @@ static void __jump_label_transform(struct jump_entry *entry,
25430 * are converting the default nop to the ideal nop.
25431 */
25432 if (init) {
25433- if (unlikely(memcmp((void *)entry->code, default_nop, 5) != 0))
25434+ if (unlikely(memcmp((void *)ktla_ktva(entry->code), default_nop, 5) != 0))
25435 bug_at((void *)entry->code, __LINE__);
25436 } else {
25437 code.jump = 0xe9;
25438 code.offset = entry->target -
25439 (entry->code + JUMP_LABEL_NOP_SIZE);
25440- if (unlikely(memcmp((void *)entry->code, &code, 5) != 0))
25441+ if (unlikely(memcmp((void *)ktla_ktva(entry->code), &code, 5) != 0))
25442 bug_at((void *)entry->code, __LINE__);
25443 }
25444 memcpy(&code, ideal_nops[NOP_ATOMIC5], JUMP_LABEL_NOP_SIZE);
25445diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
25446index 7ec1d5f..5a7d130 100644
25447--- a/arch/x86/kernel/kgdb.c
25448+++ b/arch/x86/kernel/kgdb.c
25449@@ -126,11 +126,11 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
25450 #ifdef CONFIG_X86_32
25451 switch (regno) {
25452 case GDB_SS:
25453- if (!user_mode_vm(regs))
25454+ if (!user_mode(regs))
25455 *(unsigned long *)mem = __KERNEL_DS;
25456 break;
25457 case GDB_SP:
25458- if (!user_mode_vm(regs))
25459+ if (!user_mode(regs))
25460 *(unsigned long *)mem = kernel_stack_pointer(regs);
25461 break;
25462 case GDB_GS:
25463@@ -228,7 +228,10 @@ static void kgdb_correct_hw_break(void)
25464 bp->attr.bp_addr = breakinfo[breakno].addr;
25465 bp->attr.bp_len = breakinfo[breakno].len;
25466 bp->attr.bp_type = breakinfo[breakno].type;
25467- info->address = breakinfo[breakno].addr;
25468+ if (breakinfo[breakno].type == X86_BREAKPOINT_EXECUTE)
25469+ info->address = ktla_ktva(breakinfo[breakno].addr);
25470+ else
25471+ info->address = breakinfo[breakno].addr;
25472 info->len = breakinfo[breakno].len;
25473 info->type = breakinfo[breakno].type;
25474 val = arch_install_hw_breakpoint(bp);
25475@@ -475,12 +478,12 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
25476 case 'k':
25477 /* clear the trace bit */
25478 linux_regs->flags &= ~X86_EFLAGS_TF;
25479- atomic_set(&kgdb_cpu_doing_single_step, -1);
25480+ atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
25481
25482 /* set the trace bit if we're stepping */
25483 if (remcomInBuffer[0] == 's') {
25484 linux_regs->flags |= X86_EFLAGS_TF;
25485- atomic_set(&kgdb_cpu_doing_single_step,
25486+ atomic_set_unchecked(&kgdb_cpu_doing_single_step,
25487 raw_smp_processor_id());
25488 }
25489
25490@@ -545,7 +548,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
25491
25492 switch (cmd) {
25493 case DIE_DEBUG:
25494- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
25495+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
25496 if (user_mode(regs))
25497 return single_step_cont(regs, args);
25498 break;
25499@@ -750,11 +753,11 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
25500 #endif /* CONFIG_DEBUG_RODATA */
25501
25502 bpt->type = BP_BREAKPOINT;
25503- err = probe_kernel_read(bpt->saved_instr, (char *)bpt->bpt_addr,
25504+ err = probe_kernel_read(bpt->saved_instr, ktla_ktva((char *)bpt->bpt_addr),
25505 BREAK_INSTR_SIZE);
25506 if (err)
25507 return err;
25508- err = probe_kernel_write((char *)bpt->bpt_addr,
25509+ err = probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
25510 arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE);
25511 #ifdef CONFIG_DEBUG_RODATA
25512 if (!err)
25513@@ -767,7 +770,7 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
25514 return -EBUSY;
25515 text_poke((void *)bpt->bpt_addr, arch_kgdb_ops.gdb_bpt_instr,
25516 BREAK_INSTR_SIZE);
25517- err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
25518+ err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
25519 if (err)
25520 return err;
25521 if (memcmp(opc, arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE))
25522@@ -792,13 +795,13 @@ int kgdb_arch_remove_breakpoint(struct kgdb_bkpt *bpt)
25523 if (mutex_is_locked(&text_mutex))
25524 goto knl_write;
25525 text_poke((void *)bpt->bpt_addr, bpt->saved_instr, BREAK_INSTR_SIZE);
25526- err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
25527+ err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
25528 if (err || memcmp(opc, bpt->saved_instr, BREAK_INSTR_SIZE))
25529 goto knl_write;
25530 return err;
25531 knl_write:
25532 #endif /* CONFIG_DEBUG_RODATA */
25533- return probe_kernel_write((char *)bpt->bpt_addr,
25534+ return probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
25535 (char *)bpt->saved_instr, BREAK_INSTR_SIZE);
25536 }
25537
25538diff --git a/arch/x86/kernel/kprobes/core.c b/arch/x86/kernel/kprobes/core.c
25539index 67e6d19..731ed28 100644
25540--- a/arch/x86/kernel/kprobes/core.c
25541+++ b/arch/x86/kernel/kprobes/core.c
25542@@ -120,9 +120,12 @@ __synthesize_relative_insn(void *from, void *to, u8 op)
25543 s32 raddr;
25544 } __packed *insn;
25545
25546- insn = (struct __arch_relative_insn *)from;
25547+ insn = (struct __arch_relative_insn *)ktla_ktva(from);
25548+
25549+ pax_open_kernel();
25550 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
25551 insn->op = op;
25552+ pax_close_kernel();
25553 }
25554
25555 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
25556@@ -168,7 +171,7 @@ int can_boost(kprobe_opcode_t *opcodes)
25557 kprobe_opcode_t opcode;
25558 kprobe_opcode_t *orig_opcodes = opcodes;
25559
25560- if (search_exception_tables((unsigned long)opcodes))
25561+ if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
25562 return 0; /* Page fault may occur on this address. */
25563
25564 retry:
25565@@ -242,9 +245,9 @@ __recover_probed_insn(kprobe_opcode_t *buf, unsigned long addr)
25566 * for the first byte, we can recover the original instruction
25567 * from it and kp->opcode.
25568 */
25569- memcpy(buf, kp->addr, MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
25570+ memcpy(buf, ktla_ktva(kp->addr), MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
25571 buf[0] = kp->opcode;
25572- return (unsigned long)buf;
25573+ return ktva_ktla((unsigned long)buf);
25574 }
25575
25576 /*
25577@@ -336,7 +339,9 @@ int __copy_instruction(u8 *dest, u8 *src)
25578 /* Another subsystem puts a breakpoint, failed to recover */
25579 if (insn.opcode.bytes[0] == BREAKPOINT_INSTRUCTION)
25580 return 0;
25581+ pax_open_kernel();
25582 memcpy(dest, insn.kaddr, insn.length);
25583+ pax_close_kernel();
25584
25585 #ifdef CONFIG_X86_64
25586 if (insn_rip_relative(&insn)) {
25587@@ -363,7 +368,9 @@ int __copy_instruction(u8 *dest, u8 *src)
25588 return 0;
25589 }
25590 disp = (u8 *) dest + insn_offset_displacement(&insn);
25591+ pax_open_kernel();
25592 *(s32 *) disp = (s32) newdisp;
25593+ pax_close_kernel();
25594 }
25595 #endif
25596 return insn.length;
25597@@ -505,7 +512,7 @@ static void setup_singlestep(struct kprobe *p, struct pt_regs *regs,
25598 * nor set current_kprobe, because it doesn't use single
25599 * stepping.
25600 */
25601- regs->ip = (unsigned long)p->ainsn.insn;
25602+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
25603 preempt_enable_no_resched();
25604 return;
25605 }
25606@@ -522,9 +529,9 @@ static void setup_singlestep(struct kprobe *p, struct pt_regs *regs,
25607 regs->flags &= ~X86_EFLAGS_IF;
25608 /* single step inline if the instruction is an int3 */
25609 if (p->opcode == BREAKPOINT_INSTRUCTION)
25610- regs->ip = (unsigned long)p->addr;
25611+ regs->ip = ktla_ktva((unsigned long)p->addr);
25612 else
25613- regs->ip = (unsigned long)p->ainsn.insn;
25614+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
25615 }
25616 NOKPROBE_SYMBOL(setup_singlestep);
25617
25618@@ -574,7 +581,7 @@ int kprobe_int3_handler(struct pt_regs *regs)
25619 struct kprobe *p;
25620 struct kprobe_ctlblk *kcb;
25621
25622- if (user_mode_vm(regs))
25623+ if (user_mode(regs))
25624 return 0;
25625
25626 addr = (kprobe_opcode_t *)(regs->ip - sizeof(kprobe_opcode_t));
25627@@ -609,7 +616,7 @@ int kprobe_int3_handler(struct pt_regs *regs)
25628 setup_singlestep(p, regs, kcb, 0);
25629 return 1;
25630 }
25631- } else if (*addr != BREAKPOINT_INSTRUCTION) {
25632+ } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
25633 /*
25634 * The breakpoint instruction was removed right
25635 * after we hit it. Another cpu has removed
25636@@ -656,6 +663,9 @@ static void __used kretprobe_trampoline_holder(void)
25637 " movq %rax, 152(%rsp)\n"
25638 RESTORE_REGS_STRING
25639 " popfq\n"
25640+#ifdef KERNEXEC_PLUGIN
25641+ " btsq $63,(%rsp)\n"
25642+#endif
25643 #else
25644 " pushf\n"
25645 SAVE_REGS_STRING
25646@@ -796,7 +806,7 @@ static void resume_execution(struct kprobe *p, struct pt_regs *regs,
25647 struct kprobe_ctlblk *kcb)
25648 {
25649 unsigned long *tos = stack_addr(regs);
25650- unsigned long copy_ip = (unsigned long)p->ainsn.insn;
25651+ unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
25652 unsigned long orig_ip = (unsigned long)p->addr;
25653 kprobe_opcode_t *insn = p->ainsn.insn;
25654
25655@@ -979,7 +989,7 @@ int kprobe_exceptions_notify(struct notifier_block *self, unsigned long val,
25656 struct die_args *args = data;
25657 int ret = NOTIFY_DONE;
25658
25659- if (args->regs && user_mode_vm(args->regs))
25660+ if (args->regs && user_mode(args->regs))
25661 return ret;
25662
25663 if (val == DIE_GPF) {
25664diff --git a/arch/x86/kernel/kprobes/opt.c b/arch/x86/kernel/kprobes/opt.c
25665index f1314d0..15f3154 100644
25666--- a/arch/x86/kernel/kprobes/opt.c
25667+++ b/arch/x86/kernel/kprobes/opt.c
25668@@ -79,6 +79,7 @@ found:
25669 /* Insert a move instruction which sets a pointer to eax/rdi (1st arg). */
25670 static void synthesize_set_arg1(kprobe_opcode_t *addr, unsigned long val)
25671 {
25672+ pax_open_kernel();
25673 #ifdef CONFIG_X86_64
25674 *addr++ = 0x48;
25675 *addr++ = 0xbf;
25676@@ -86,6 +87,7 @@ static void synthesize_set_arg1(kprobe_opcode_t *addr, unsigned long val)
25677 *addr++ = 0xb8;
25678 #endif
25679 *(unsigned long *)addr = val;
25680+ pax_close_kernel();
25681 }
25682
25683 asm (
25684@@ -337,7 +339,7 @@ int arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
25685 * Verify if the address gap is in 2GB range, because this uses
25686 * a relative jump.
25687 */
25688- rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
25689+ rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
25690 if (abs(rel) > 0x7fffffff) {
25691 __arch_remove_optimized_kprobe(op, 0);
25692 return -ERANGE;
25693@@ -354,16 +356,18 @@ int arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
25694 op->optinsn.size = ret;
25695
25696 /* Copy arch-dep-instance from template */
25697- memcpy(buf, &optprobe_template_entry, TMPL_END_IDX);
25698+ pax_open_kernel();
25699+ memcpy(buf, ktla_ktva(&optprobe_template_entry), TMPL_END_IDX);
25700+ pax_close_kernel();
25701
25702 /* Set probe information */
25703 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
25704
25705 /* Set probe function call */
25706- synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
25707+ synthesize_relcall(ktva_ktla(buf) + TMPL_CALL_IDX, optimized_callback);
25708
25709 /* Set returning jmp instruction at the tail of out-of-line buffer */
25710- synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
25711+ synthesize_reljump(ktva_ktla(buf) + TMPL_END_IDX + op->optinsn.size,
25712 (u8 *)op->kp.addr + op->optinsn.size);
25713
25714 flush_icache_range((unsigned long) buf,
25715@@ -388,7 +392,7 @@ void arch_optimize_kprobes(struct list_head *oplist)
25716 WARN_ON(kprobe_disabled(&op->kp));
25717
25718 /* Backup instructions which will be replaced by jump address */
25719- memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
25720+ memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
25721 RELATIVE_ADDR_SIZE);
25722
25723 insn_buf[0] = RELATIVEJUMP_OPCODE;
25724@@ -436,7 +440,7 @@ int setup_detour_execution(struct kprobe *p, struct pt_regs *regs, int reenter)
25725 /* This kprobe is really able to run optimized path. */
25726 op = container_of(p, struct optimized_kprobe, kp);
25727 /* Detour through copied instructions */
25728- regs->ip = (unsigned long)op->optinsn.insn + TMPL_END_IDX;
25729+ regs->ip = ktva_ktla((unsigned long)op->optinsn.insn) + TMPL_END_IDX;
25730 if (!reenter)
25731 reset_current_kprobe();
25732 preempt_enable_no_resched();
25733diff --git a/arch/x86/kernel/ksysfs.c b/arch/x86/kernel/ksysfs.c
25734index c2bedae..25e7ab60 100644
25735--- a/arch/x86/kernel/ksysfs.c
25736+++ b/arch/x86/kernel/ksysfs.c
25737@@ -184,7 +184,7 @@ out:
25738
25739 static struct kobj_attribute type_attr = __ATTR_RO(type);
25740
25741-static struct bin_attribute data_attr = {
25742+static bin_attribute_no_const data_attr __read_only = {
25743 .attr = {
25744 .name = "data",
25745 .mode = S_IRUGO,
25746diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
25747index c37886d..d851d32 100644
25748--- a/arch/x86/kernel/ldt.c
25749+++ b/arch/x86/kernel/ldt.c
25750@@ -66,13 +66,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
25751 if (reload) {
25752 #ifdef CONFIG_SMP
25753 preempt_disable();
25754- load_LDT(pc);
25755+ load_LDT_nolock(pc);
25756 if (!cpumask_equal(mm_cpumask(current->mm),
25757 cpumask_of(smp_processor_id())))
25758 smp_call_function(flush_ldt, current->mm, 1);
25759 preempt_enable();
25760 #else
25761- load_LDT(pc);
25762+ load_LDT_nolock(pc);
25763 #endif
25764 }
25765 if (oldsize) {
25766@@ -94,7 +94,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
25767 return err;
25768
25769 for (i = 0; i < old->size; i++)
25770- write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
25771+ write_ldt_entry(new->ldt, i, old->ldt + i);
25772 return 0;
25773 }
25774
25775@@ -115,6 +115,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
25776 retval = copy_ldt(&mm->context, &old_mm->context);
25777 mutex_unlock(&old_mm->context.lock);
25778 }
25779+
25780+ if (tsk == current) {
25781+ mm->context.vdso = 0;
25782+
25783+#ifdef CONFIG_X86_32
25784+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
25785+ mm->context.user_cs_base = 0UL;
25786+ mm->context.user_cs_limit = ~0UL;
25787+
25788+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
25789+ cpus_clear(mm->context.cpu_user_cs_mask);
25790+#endif
25791+
25792+#endif
25793+#endif
25794+
25795+ }
25796+
25797 return retval;
25798 }
25799
25800@@ -229,6 +247,13 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
25801 }
25802 }
25803
25804+#ifdef CONFIG_PAX_SEGMEXEC
25805+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
25806+ error = -EINVAL;
25807+ goto out_unlock;
25808+ }
25809+#endif
25810+
25811 if (!IS_ENABLED(CONFIG_X86_16BIT) && !ldt_info.seg_32bit) {
25812 error = -EINVAL;
25813 goto out_unlock;
25814diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
25815index 72e8e31..f2f1605 100644
25816--- a/arch/x86/kernel/machine_kexec_32.c
25817+++ b/arch/x86/kernel/machine_kexec_32.c
25818@@ -25,7 +25,7 @@
25819 #include <asm/cacheflush.h>
25820 #include <asm/debugreg.h>
25821
25822-static void set_idt(void *newidt, __u16 limit)
25823+static void set_idt(struct desc_struct *newidt, __u16 limit)
25824 {
25825 struct desc_ptr curidt;
25826
25827@@ -37,7 +37,7 @@ static void set_idt(void *newidt, __u16 limit)
25828 }
25829
25830
25831-static void set_gdt(void *newgdt, __u16 limit)
25832+static void set_gdt(struct desc_struct *newgdt, __u16 limit)
25833 {
25834 struct desc_ptr curgdt;
25835
25836@@ -215,7 +215,7 @@ void machine_kexec(struct kimage *image)
25837 }
25838
25839 control_page = page_address(image->control_code_page);
25840- memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
25841+ memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
25842
25843 relocate_kernel_ptr = control_page;
25844 page_list[PA_CONTROL_PAGE] = __pa(control_page);
25845diff --git a/arch/x86/kernel/mcount_64.S b/arch/x86/kernel/mcount_64.S
25846index c73aecf..4c63630 100644
25847--- a/arch/x86/kernel/mcount_64.S
25848+++ b/arch/x86/kernel/mcount_64.S
25849@@ -7,7 +7,7 @@
25850 #include <linux/linkage.h>
25851 #include <asm/ptrace.h>
25852 #include <asm/ftrace.h>
25853-
25854+#include <asm/alternative-asm.h>
25855
25856 .code64
25857 .section .entry.text, "ax"
25858@@ -24,8 +24,9 @@
25859 #ifdef CONFIG_DYNAMIC_FTRACE
25860
25861 ENTRY(function_hook)
25862+ pax_force_retaddr
25863 retq
25864-END(function_hook)
25865+ENDPROC(function_hook)
25866
25867 /* skip is set if stack has been adjusted */
25868 .macro ftrace_caller_setup skip=0
25869@@ -62,8 +63,9 @@ GLOBAL(ftrace_graph_call)
25870 #endif
25871
25872 GLOBAL(ftrace_stub)
25873+ pax_force_retaddr
25874 retq
25875-END(ftrace_caller)
25876+ENDPROC(ftrace_caller)
25877
25878 ENTRY(ftrace_regs_caller)
25879 /* Save the current flags before compare (in SS location)*/
25880@@ -127,7 +129,7 @@ GLOBAL(ftrace_regs_call)
25881 popfq
25882 jmp ftrace_stub
25883
25884-END(ftrace_regs_caller)
25885+ENDPROC(ftrace_regs_caller)
25886
25887
25888 #else /* ! CONFIG_DYNAMIC_FTRACE */
25889@@ -145,6 +147,7 @@ ENTRY(function_hook)
25890 #endif
25891
25892 GLOBAL(ftrace_stub)
25893+ pax_force_retaddr
25894 retq
25895
25896 trace:
25897@@ -158,12 +161,13 @@ trace:
25898 #endif
25899 subq $MCOUNT_INSN_SIZE, %rdi
25900
25901+ pax_force_fptr ftrace_trace_function
25902 call *ftrace_trace_function
25903
25904 MCOUNT_RESTORE_FRAME
25905
25906 jmp ftrace_stub
25907-END(function_hook)
25908+ENDPROC(function_hook)
25909 #endif /* CONFIG_DYNAMIC_FTRACE */
25910 #endif /* CONFIG_FUNCTION_TRACER */
25911
25912@@ -185,8 +189,9 @@ ENTRY(ftrace_graph_caller)
25913
25914 MCOUNT_RESTORE_FRAME
25915
25916+ pax_force_retaddr
25917 retq
25918-END(ftrace_graph_caller)
25919+ENDPROC(ftrace_graph_caller)
25920
25921 GLOBAL(return_to_handler)
25922 subq $24, %rsp
25923@@ -202,5 +207,7 @@ GLOBAL(return_to_handler)
25924 movq 8(%rsp), %rdx
25925 movq (%rsp), %rax
25926 addq $24, %rsp
25927+ pax_force_fptr %rdi
25928 jmp *%rdi
25929+ENDPROC(return_to_handler)
25930 #endif
25931diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
25932index e69f988..da078ea 100644
25933--- a/arch/x86/kernel/module.c
25934+++ b/arch/x86/kernel/module.c
25935@@ -81,17 +81,62 @@ static unsigned long int get_module_load_offset(void)
25936 }
25937 #endif
25938
25939-void *module_alloc(unsigned long size)
25940+static inline void *__module_alloc(unsigned long size, pgprot_t prot)
25941 {
25942- if (PAGE_ALIGN(size) > MODULES_LEN)
25943+ if (!size || PAGE_ALIGN(size) > MODULES_LEN)
25944 return NULL;
25945 return __vmalloc_node_range(size, 1,
25946 MODULES_VADDR + get_module_load_offset(),
25947- MODULES_END, GFP_KERNEL | __GFP_HIGHMEM,
25948- PAGE_KERNEL_EXEC, NUMA_NO_NODE,
25949+ MODULES_END, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO,
25950+ prot, NUMA_NO_NODE,
25951 __builtin_return_address(0));
25952 }
25953
25954+void *module_alloc(unsigned long size)
25955+{
25956+
25957+#ifdef CONFIG_PAX_KERNEXEC
25958+ return __module_alloc(size, PAGE_KERNEL);
25959+#else
25960+ return __module_alloc(size, PAGE_KERNEL_EXEC);
25961+#endif
25962+
25963+}
25964+
25965+#ifdef CONFIG_PAX_KERNEXEC
25966+#ifdef CONFIG_X86_32
25967+void *module_alloc_exec(unsigned long size)
25968+{
25969+ struct vm_struct *area;
25970+
25971+ if (size == 0)
25972+ return NULL;
25973+
25974+ area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
25975+return area ? area->addr : NULL;
25976+}
25977+EXPORT_SYMBOL(module_alloc_exec);
25978+
25979+void module_free_exec(struct module *mod, void *module_region)
25980+{
25981+ vunmap(module_region);
25982+}
25983+EXPORT_SYMBOL(module_free_exec);
25984+#else
25985+void module_free_exec(struct module *mod, void *module_region)
25986+{
25987+ module_free(mod, module_region);
25988+}
25989+EXPORT_SYMBOL(module_free_exec);
25990+
25991+void *module_alloc_exec(unsigned long size)
25992+{
25993+ return __module_alloc(size, PAGE_KERNEL_RX);
25994+}
25995+EXPORT_SYMBOL(module_alloc_exec);
25996+#endif
25997+#endif
25998+
25999 #ifdef CONFIG_X86_32
26000 int apply_relocate(Elf32_Shdr *sechdrs,
26001 const char *strtab,
26002@@ -102,14 +147,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
26003 unsigned int i;
26004 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
26005 Elf32_Sym *sym;
26006- uint32_t *location;
26007+ uint32_t *plocation, location;
26008
26009 DEBUGP("Applying relocate section %u to %u\n",
26010 relsec, sechdrs[relsec].sh_info);
26011 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
26012 /* This is where to make the change */
26013- location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
26014- + rel[i].r_offset;
26015+ plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
26016+ location = (uint32_t)plocation;
26017+ if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
26018+ plocation = ktla_ktva((void *)plocation);
26019 /* This is the symbol it is referring to. Note that all
26020 undefined symbols have been resolved. */
26021 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
26022@@ -118,11 +165,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
26023 switch (ELF32_R_TYPE(rel[i].r_info)) {
26024 case R_386_32:
26025 /* We add the value into the location given */
26026- *location += sym->st_value;
26027+ pax_open_kernel();
26028+ *plocation += sym->st_value;
26029+ pax_close_kernel();
26030 break;
26031 case R_386_PC32:
26032 /* Add the value, subtract its position */
26033- *location += sym->st_value - (uint32_t)location;
26034+ pax_open_kernel();
26035+ *plocation += sym->st_value - location;
26036+ pax_close_kernel();
26037 break;
26038 default:
26039 pr_err("%s: Unknown relocation: %u\n",
26040@@ -167,21 +218,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
26041 case R_X86_64_NONE:
26042 break;
26043 case R_X86_64_64:
26044+ pax_open_kernel();
26045 *(u64 *)loc = val;
26046+ pax_close_kernel();
26047 break;
26048 case R_X86_64_32:
26049+ pax_open_kernel();
26050 *(u32 *)loc = val;
26051+ pax_close_kernel();
26052 if (val != *(u32 *)loc)
26053 goto overflow;
26054 break;
26055 case R_X86_64_32S:
26056+ pax_open_kernel();
26057 *(s32 *)loc = val;
26058+ pax_close_kernel();
26059 if ((s64)val != *(s32 *)loc)
26060 goto overflow;
26061 break;
26062 case R_X86_64_PC32:
26063 val -= (u64)loc;
26064+ pax_open_kernel();
26065 *(u32 *)loc = val;
26066+ pax_close_kernel();
26067+
26068 #if 0
26069 if ((s64)val != *(s32 *)loc)
26070 goto overflow;
26071diff --git a/arch/x86/kernel/msr.c b/arch/x86/kernel/msr.c
26072index c9603ac..9f88728 100644
26073--- a/arch/x86/kernel/msr.c
26074+++ b/arch/x86/kernel/msr.c
26075@@ -37,6 +37,7 @@
26076 #include <linux/notifier.h>
26077 #include <linux/uaccess.h>
26078 #include <linux/gfp.h>
26079+#include <linux/grsecurity.h>
26080
26081 #include <asm/processor.h>
26082 #include <asm/msr.h>
26083@@ -103,6 +104,11 @@ static ssize_t msr_write(struct file *file, const char __user *buf,
26084 int err = 0;
26085 ssize_t bytes = 0;
26086
26087+#ifdef CONFIG_GRKERNSEC_KMEM
26088+ gr_handle_msr_write();
26089+ return -EPERM;
26090+#endif
26091+
26092 if (count % 8)
26093 return -EINVAL; /* Invalid chunk size */
26094
26095@@ -150,6 +156,10 @@ static long msr_ioctl(struct file *file, unsigned int ioc, unsigned long arg)
26096 err = -EBADF;
26097 break;
26098 }
26099+#ifdef CONFIG_GRKERNSEC_KMEM
26100+ gr_handle_msr_write();
26101+ return -EPERM;
26102+#endif
26103 if (copy_from_user(&regs, uregs, sizeof regs)) {
26104 err = -EFAULT;
26105 break;
26106@@ -233,7 +243,7 @@ static int msr_class_cpu_callback(struct notifier_block *nfb,
26107 return notifier_from_errno(err);
26108 }
26109
26110-static struct notifier_block __refdata msr_class_cpu_notifier = {
26111+static struct notifier_block msr_class_cpu_notifier = {
26112 .notifier_call = msr_class_cpu_callback,
26113 };
26114
26115diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
26116index c3e985d..110a36a 100644
26117--- a/arch/x86/kernel/nmi.c
26118+++ b/arch/x86/kernel/nmi.c
26119@@ -98,16 +98,16 @@ fs_initcall(nmi_warning_debugfs);
26120
26121 static void nmi_max_handler(struct irq_work *w)
26122 {
26123- struct nmiaction *a = container_of(w, struct nmiaction, irq_work);
26124+ struct nmiwork *n = container_of(w, struct nmiwork, irq_work);
26125 int remainder_ns, decimal_msecs;
26126- u64 whole_msecs = ACCESS_ONCE(a->max_duration);
26127+ u64 whole_msecs = ACCESS_ONCE(n->max_duration);
26128
26129 remainder_ns = do_div(whole_msecs, (1000 * 1000));
26130 decimal_msecs = remainder_ns / 1000;
26131
26132 printk_ratelimited(KERN_INFO
26133 "INFO: NMI handler (%ps) took too long to run: %lld.%03d msecs\n",
26134- a->handler, whole_msecs, decimal_msecs);
26135+ n->action->handler, whole_msecs, decimal_msecs);
26136 }
26137
26138 static int nmi_handle(unsigned int type, struct pt_regs *regs, bool b2b)
26139@@ -134,11 +134,11 @@ static int nmi_handle(unsigned int type, struct pt_regs *regs, bool b2b)
26140 delta = sched_clock() - delta;
26141 trace_nmi_handler(a->handler, (int)delta, thishandled);
26142
26143- if (delta < nmi_longest_ns || delta < a->max_duration)
26144+ if (delta < nmi_longest_ns || delta < a->work->max_duration)
26145 continue;
26146
26147- a->max_duration = delta;
26148- irq_work_queue(&a->irq_work);
26149+ a->work->max_duration = delta;
26150+ irq_work_queue(&a->work->irq_work);
26151 }
26152
26153 rcu_read_unlock();
26154@@ -148,7 +148,7 @@ static int nmi_handle(unsigned int type, struct pt_regs *regs, bool b2b)
26155 }
26156 NOKPROBE_SYMBOL(nmi_handle);
26157
26158-int __register_nmi_handler(unsigned int type, struct nmiaction *action)
26159+int __register_nmi_handler(unsigned int type, const struct nmiaction *action)
26160 {
26161 struct nmi_desc *desc = nmi_to_desc(type);
26162 unsigned long flags;
26163@@ -156,7 +156,8 @@ int __register_nmi_handler(unsigned int type, struct nmiaction *action)
26164 if (!action->handler)
26165 return -EINVAL;
26166
26167- init_irq_work(&action->irq_work, nmi_max_handler);
26168+ action->work->action = action;
26169+ init_irq_work(&action->work->irq_work, nmi_max_handler);
26170
26171 spin_lock_irqsave(&desc->lock, flags);
26172
26173@@ -174,9 +175,9 @@ int __register_nmi_handler(unsigned int type, struct nmiaction *action)
26174 * event confuses some handlers (kdump uses this flag)
26175 */
26176 if (action->flags & NMI_FLAG_FIRST)
26177- list_add_rcu(&action->list, &desc->head);
26178+ pax_list_add_rcu((struct list_head *)&action->list, &desc->head);
26179 else
26180- list_add_tail_rcu(&action->list, &desc->head);
26181+ pax_list_add_tail_rcu((struct list_head *)&action->list, &desc->head);
26182
26183 spin_unlock_irqrestore(&desc->lock, flags);
26184 return 0;
26185@@ -199,7 +200,7 @@ void unregister_nmi_handler(unsigned int type, const char *name)
26186 if (!strcmp(n->name, name)) {
26187 WARN(in_nmi(),
26188 "Trying to free NMI (%s) from NMI context!\n", n->name);
26189- list_del_rcu(&n->list);
26190+ pax_list_del_rcu((struct list_head *)&n->list);
26191 break;
26192 }
26193 }
26194@@ -528,6 +529,17 @@ static inline void nmi_nesting_postprocess(void)
26195 dotraplinkage notrace void
26196 do_nmi(struct pt_regs *regs, long error_code)
26197 {
26198+
26199+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
26200+ if (!user_mode(regs)) {
26201+ unsigned long cs = regs->cs & 0xFFFF;
26202+ unsigned long ip = ktva_ktla(regs->ip);
26203+
26204+ if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
26205+ regs->ip = ip;
26206+ }
26207+#endif
26208+
26209 nmi_nesting_preprocess(regs);
26210
26211 nmi_enter();
26212diff --git a/arch/x86/kernel/nmi_selftest.c b/arch/x86/kernel/nmi_selftest.c
26213index 6d9582e..f746287 100644
26214--- a/arch/x86/kernel/nmi_selftest.c
26215+++ b/arch/x86/kernel/nmi_selftest.c
26216@@ -43,7 +43,7 @@ static void __init init_nmi_testsuite(void)
26217 {
26218 /* trap all the unknown NMIs we may generate */
26219 register_nmi_handler(NMI_UNKNOWN, nmi_unk_cb, 0, "nmi_selftest_unk",
26220- __initdata);
26221+ __initconst);
26222 }
26223
26224 static void __init cleanup_nmi_testsuite(void)
26225@@ -66,7 +66,7 @@ static void __init test_nmi_ipi(struct cpumask *mask)
26226 unsigned long timeout;
26227
26228 if (register_nmi_handler(NMI_LOCAL, test_nmi_ipi_callback,
26229- NMI_FLAG_FIRST, "nmi_selftest", __initdata)) {
26230+ NMI_FLAG_FIRST, "nmi_selftest", __initconst)) {
26231 nmi_fail = FAILURE;
26232 return;
26233 }
26234diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
26235index bbb6c73..24a58ef 100644
26236--- a/arch/x86/kernel/paravirt-spinlocks.c
26237+++ b/arch/x86/kernel/paravirt-spinlocks.c
26238@@ -8,7 +8,7 @@
26239
26240 #include <asm/paravirt.h>
26241
26242-struct pv_lock_ops pv_lock_ops = {
26243+struct pv_lock_ops pv_lock_ops __read_only = {
26244 #ifdef CONFIG_SMP
26245 .lock_spinning = __PV_IS_CALLEE_SAVE(paravirt_nop),
26246 .unlock_kick = paravirt_nop,
26247diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
26248index 548d25f..f8fb99c 100644
26249--- a/arch/x86/kernel/paravirt.c
26250+++ b/arch/x86/kernel/paravirt.c
26251@@ -56,6 +56,9 @@ u64 _paravirt_ident_64(u64 x)
26252 {
26253 return x;
26254 }
26255+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
26256+PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
26257+#endif
26258
26259 void __init default_banner(void)
26260 {
26261@@ -142,16 +145,20 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
26262
26263 if (opfunc == NULL)
26264 /* If there's no function, patch it with a ud2a (BUG) */
26265- ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
26266- else if (opfunc == _paravirt_nop)
26267+ ret = paravirt_patch_insns(insnbuf, len, ktva_ktla(ud2a), ud2a+sizeof(ud2a));
26268+ else if (opfunc == (void *)_paravirt_nop)
26269 /* If the operation is a nop, then nop the callsite */
26270 ret = paravirt_patch_nop();
26271
26272 /* identity functions just return their single argument */
26273- else if (opfunc == _paravirt_ident_32)
26274+ else if (opfunc == (void *)_paravirt_ident_32)
26275 ret = paravirt_patch_ident_32(insnbuf, len);
26276- else if (opfunc == _paravirt_ident_64)
26277+ else if (opfunc == (void *)_paravirt_ident_64)
26278 ret = paravirt_patch_ident_64(insnbuf, len);
26279+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
26280+ else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
26281+ ret = paravirt_patch_ident_64(insnbuf, len);
26282+#endif
26283
26284 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
26285 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
26286@@ -176,7 +183,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
26287 if (insn_len > len || start == NULL)
26288 insn_len = len;
26289 else
26290- memcpy(insnbuf, start, insn_len);
26291+ memcpy(insnbuf, ktla_ktva(start), insn_len);
26292
26293 return insn_len;
26294 }
26295@@ -300,7 +307,7 @@ enum paravirt_lazy_mode paravirt_get_lazy_mode(void)
26296 return this_cpu_read(paravirt_lazy_mode);
26297 }
26298
26299-struct pv_info pv_info = {
26300+struct pv_info pv_info __read_only = {
26301 .name = "bare hardware",
26302 .paravirt_enabled = 0,
26303 .kernel_rpl = 0,
26304@@ -311,16 +318,16 @@ struct pv_info pv_info = {
26305 #endif
26306 };
26307
26308-struct pv_init_ops pv_init_ops = {
26309+struct pv_init_ops pv_init_ops __read_only = {
26310 .patch = native_patch,
26311 };
26312
26313-struct pv_time_ops pv_time_ops = {
26314+struct pv_time_ops pv_time_ops __read_only = {
26315 .sched_clock = native_sched_clock,
26316 .steal_clock = native_steal_clock,
26317 };
26318
26319-__visible struct pv_irq_ops pv_irq_ops = {
26320+__visible struct pv_irq_ops pv_irq_ops __read_only = {
26321 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
26322 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
26323 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
26324@@ -332,7 +339,7 @@ __visible struct pv_irq_ops pv_irq_ops = {
26325 #endif
26326 };
26327
26328-__visible struct pv_cpu_ops pv_cpu_ops = {
26329+__visible struct pv_cpu_ops pv_cpu_ops __read_only = {
26330 .cpuid = native_cpuid,
26331 .get_debugreg = native_get_debugreg,
26332 .set_debugreg = native_set_debugreg,
26333@@ -395,21 +402,26 @@ NOKPROBE_SYMBOL(native_get_debugreg);
26334 NOKPROBE_SYMBOL(native_set_debugreg);
26335 NOKPROBE_SYMBOL(native_load_idt);
26336
26337-struct pv_apic_ops pv_apic_ops = {
26338+struct pv_apic_ops pv_apic_ops __read_only= {
26339 #ifdef CONFIG_X86_LOCAL_APIC
26340 .startup_ipi_hook = paravirt_nop,
26341 #endif
26342 };
26343
26344-#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
26345+#ifdef CONFIG_X86_32
26346+#ifdef CONFIG_X86_PAE
26347+/* 64-bit pagetable entries */
26348+#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
26349+#else
26350 /* 32-bit pagetable entries */
26351 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
26352+#endif
26353 #else
26354 /* 64-bit pagetable entries */
26355 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
26356 #endif
26357
26358-struct pv_mmu_ops pv_mmu_ops = {
26359+struct pv_mmu_ops pv_mmu_ops __read_only = {
26360
26361 .read_cr2 = native_read_cr2,
26362 .write_cr2 = native_write_cr2,
26363@@ -459,6 +471,7 @@ struct pv_mmu_ops pv_mmu_ops = {
26364 .make_pud = PTE_IDENT,
26365
26366 .set_pgd = native_set_pgd,
26367+ .set_pgd_batched = native_set_pgd_batched,
26368 #endif
26369 #endif /* PAGETABLE_LEVELS >= 3 */
26370
26371@@ -479,6 +492,12 @@ struct pv_mmu_ops pv_mmu_ops = {
26372 },
26373
26374 .set_fixmap = native_set_fixmap,
26375+
26376+#ifdef CONFIG_PAX_KERNEXEC
26377+ .pax_open_kernel = native_pax_open_kernel,
26378+ .pax_close_kernel = native_pax_close_kernel,
26379+#endif
26380+
26381 };
26382
26383 EXPORT_SYMBOL_GPL(pv_time_ops);
26384diff --git a/arch/x86/kernel/paravirt_patch_64.c b/arch/x86/kernel/paravirt_patch_64.c
26385index a1da673..b6f5831 100644
26386--- a/arch/x86/kernel/paravirt_patch_64.c
26387+++ b/arch/x86/kernel/paravirt_patch_64.c
26388@@ -9,7 +9,11 @@ DEF_NATIVE(pv_irq_ops, save_fl, "pushfq; popq %rax");
26389 DEF_NATIVE(pv_mmu_ops, read_cr2, "movq %cr2, %rax");
26390 DEF_NATIVE(pv_mmu_ops, read_cr3, "movq %cr3, %rax");
26391 DEF_NATIVE(pv_mmu_ops, write_cr3, "movq %rdi, %cr3");
26392+
26393+#ifndef CONFIG_PAX_MEMORY_UDEREF
26394 DEF_NATIVE(pv_mmu_ops, flush_tlb_single, "invlpg (%rdi)");
26395+#endif
26396+
26397 DEF_NATIVE(pv_cpu_ops, clts, "clts");
26398 DEF_NATIVE(pv_cpu_ops, wbinvd, "wbinvd");
26399
26400@@ -57,7 +61,11 @@ unsigned native_patch(u8 type, u16 clobbers, void *ibuf,
26401 PATCH_SITE(pv_mmu_ops, read_cr3);
26402 PATCH_SITE(pv_mmu_ops, write_cr3);
26403 PATCH_SITE(pv_cpu_ops, clts);
26404+
26405+#ifndef CONFIG_PAX_MEMORY_UDEREF
26406 PATCH_SITE(pv_mmu_ops, flush_tlb_single);
26407+#endif
26408+
26409 PATCH_SITE(pv_cpu_ops, wbinvd);
26410
26411 patch_site:
26412diff --git a/arch/x86/kernel/pci-calgary_64.c b/arch/x86/kernel/pci-calgary_64.c
26413index 0497f71..7186c0d 100644
26414--- a/arch/x86/kernel/pci-calgary_64.c
26415+++ b/arch/x86/kernel/pci-calgary_64.c
26416@@ -1347,7 +1347,7 @@ static void __init get_tce_space_from_tar(void)
26417 tce_space = be64_to_cpu(readq(target));
26418 tce_space = tce_space & TAR_SW_BITS;
26419
26420- tce_space = tce_space & (~specified_table_size);
26421+ tce_space = tce_space & (~(unsigned long)specified_table_size);
26422 info->tce_space = (u64 *)__va(tce_space);
26423 }
26424 }
26425diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
26426index 35ccf75..7a15747 100644
26427--- a/arch/x86/kernel/pci-iommu_table.c
26428+++ b/arch/x86/kernel/pci-iommu_table.c
26429@@ -2,7 +2,7 @@
26430 #include <asm/iommu_table.h>
26431 #include <linux/string.h>
26432 #include <linux/kallsyms.h>
26433-
26434+#include <linux/sched.h>
26435
26436 #define DEBUG 1
26437
26438diff --git a/arch/x86/kernel/pci-swiotlb.c b/arch/x86/kernel/pci-swiotlb.c
26439index 77dd0ad..9ec4723 100644
26440--- a/arch/x86/kernel/pci-swiotlb.c
26441+++ b/arch/x86/kernel/pci-swiotlb.c
26442@@ -33,7 +33,7 @@ void x86_swiotlb_free_coherent(struct device *dev, size_t size,
26443 struct dma_attrs *attrs)
26444 {
26445 if (is_swiotlb_buffer(dma_to_phys(dev, dma_addr)))
26446- swiotlb_free_coherent(dev, size, vaddr, dma_addr);
26447+ swiotlb_free_coherent(dev, size, vaddr, dma_addr, attrs);
26448 else
26449 dma_generic_free_coherent(dev, size, vaddr, dma_addr, attrs);
26450 }
26451diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
26452index e127dda..94e384d 100644
26453--- a/arch/x86/kernel/process.c
26454+++ b/arch/x86/kernel/process.c
26455@@ -36,7 +36,8 @@
26456 * section. Since TSS's are completely CPU-local, we want them
26457 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
26458 */
26459-__visible DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
26460+struct tss_struct init_tss[NR_CPUS] __visible ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
26461+EXPORT_SYMBOL(init_tss);
26462
26463 #ifdef CONFIG_X86_64
26464 static DEFINE_PER_CPU(unsigned char, is_idle);
26465@@ -94,7 +95,7 @@ void arch_task_cache_init(void)
26466 task_xstate_cachep =
26467 kmem_cache_create("task_xstate", xstate_size,
26468 __alignof__(union thread_xstate),
26469- SLAB_PANIC | SLAB_NOTRACK, NULL);
26470+ SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
26471 setup_xstate_comp();
26472 }
26473
26474@@ -108,7 +109,7 @@ void exit_thread(void)
26475 unsigned long *bp = t->io_bitmap_ptr;
26476
26477 if (bp) {
26478- struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
26479+ struct tss_struct *tss = init_tss + get_cpu();
26480
26481 t->io_bitmap_ptr = NULL;
26482 clear_thread_flag(TIF_IO_BITMAP);
26483@@ -128,6 +129,9 @@ void flush_thread(void)
26484 {
26485 struct task_struct *tsk = current;
26486
26487+#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
26488+ loadsegment(gs, 0);
26489+#endif
26490 flush_ptrace_hw_breakpoint(tsk);
26491 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
26492 drop_init_fpu(tsk);
26493@@ -274,7 +278,7 @@ static void __exit_idle(void)
26494 void exit_idle(void)
26495 {
26496 /* idle loop has pid 0 */
26497- if (current->pid)
26498+ if (task_pid_nr(current))
26499 return;
26500 __exit_idle();
26501 }
26502@@ -327,7 +331,7 @@ bool xen_set_default_idle(void)
26503 return ret;
26504 }
26505 #endif
26506-void stop_this_cpu(void *dummy)
26507+__noreturn void stop_this_cpu(void *dummy)
26508 {
26509 local_irq_disable();
26510 /*
26511@@ -456,16 +460,37 @@ static int __init idle_setup(char *str)
26512 }
26513 early_param("idle", idle_setup);
26514
26515-unsigned long arch_align_stack(unsigned long sp)
26516+#ifdef CONFIG_PAX_RANDKSTACK
26517+void pax_randomize_kstack(struct pt_regs *regs)
26518 {
26519- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
26520- sp -= get_random_int() % 8192;
26521- return sp & ~0xf;
26522-}
26523+ struct thread_struct *thread = &current->thread;
26524+ unsigned long time;
26525
26526-unsigned long arch_randomize_brk(struct mm_struct *mm)
26527-{
26528- unsigned long range_end = mm->brk + 0x02000000;
26529- return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
26530-}
26531+ if (!randomize_va_space)
26532+ return;
26533+
26534+ if (v8086_mode(regs))
26535+ return;
26536
26537+ rdtscl(time);
26538+
26539+ /* P4 seems to return a 0 LSB, ignore it */
26540+#ifdef CONFIG_MPENTIUM4
26541+ time &= 0x3EUL;
26542+ time <<= 2;
26543+#elif defined(CONFIG_X86_64)
26544+ time &= 0xFUL;
26545+ time <<= 4;
26546+#else
26547+ time &= 0x1FUL;
26548+ time <<= 3;
26549+#endif
26550+
26551+ thread->sp0 ^= time;
26552+ load_sp0(init_tss + smp_processor_id(), thread);
26553+
26554+#ifdef CONFIG_X86_64
26555+ this_cpu_write(kernel_stack, thread->sp0);
26556+#endif
26557+}
26558+#endif
26559diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
26560index 8f3ebfe..cbc731b 100644
26561--- a/arch/x86/kernel/process_32.c
26562+++ b/arch/x86/kernel/process_32.c
26563@@ -64,6 +64,7 @@ asmlinkage void ret_from_kernel_thread(void) __asm__("ret_from_kernel_thread");
26564 unsigned long thread_saved_pc(struct task_struct *tsk)
26565 {
26566 return ((unsigned long *)tsk->thread.sp)[3];
26567+//XXX return tsk->thread.eip;
26568 }
26569
26570 void __show_regs(struct pt_regs *regs, int all)
26571@@ -73,19 +74,18 @@ void __show_regs(struct pt_regs *regs, int all)
26572 unsigned long sp;
26573 unsigned short ss, gs;
26574
26575- if (user_mode_vm(regs)) {
26576+ if (user_mode(regs)) {
26577 sp = regs->sp;
26578 ss = regs->ss & 0xffff;
26579- gs = get_user_gs(regs);
26580 } else {
26581 sp = kernel_stack_pointer(regs);
26582 savesegment(ss, ss);
26583- savesegment(gs, gs);
26584 }
26585+ gs = get_user_gs(regs);
26586
26587 printk(KERN_DEFAULT "EIP: %04x:[<%08lx>] EFLAGS: %08lx CPU: %d\n",
26588 (u16)regs->cs, regs->ip, regs->flags,
26589- smp_processor_id());
26590+ raw_smp_processor_id());
26591 print_symbol("EIP is at %s\n", regs->ip);
26592
26593 printk(KERN_DEFAULT "EAX: %08lx EBX: %08lx ECX: %08lx EDX: %08lx\n",
26594@@ -132,21 +132,22 @@ void release_thread(struct task_struct *dead_task)
26595 int copy_thread(unsigned long clone_flags, unsigned long sp,
26596 unsigned long arg, struct task_struct *p)
26597 {
26598- struct pt_regs *childregs = task_pt_regs(p);
26599+ struct pt_regs *childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
26600 struct task_struct *tsk;
26601 int err;
26602
26603 p->thread.sp = (unsigned long) childregs;
26604 p->thread.sp0 = (unsigned long) (childregs+1);
26605+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p) + 2 * sizeof(unsigned long);
26606 memset(p->thread.ptrace_bps, 0, sizeof(p->thread.ptrace_bps));
26607
26608 if (unlikely(p->flags & PF_KTHREAD)) {
26609 /* kernel thread */
26610 memset(childregs, 0, sizeof(struct pt_regs));
26611 p->thread.ip = (unsigned long) ret_from_kernel_thread;
26612- task_user_gs(p) = __KERNEL_STACK_CANARY;
26613- childregs->ds = __USER_DS;
26614- childregs->es = __USER_DS;
26615+ savesegment(gs, childregs->gs);
26616+ childregs->ds = __KERNEL_DS;
26617+ childregs->es = __KERNEL_DS;
26618 childregs->fs = __KERNEL_PERCPU;
26619 childregs->bx = sp; /* function */
26620 childregs->bp = arg;
26621@@ -248,7 +249,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26622 struct thread_struct *prev = &prev_p->thread,
26623 *next = &next_p->thread;
26624 int cpu = smp_processor_id();
26625- struct tss_struct *tss = &per_cpu(init_tss, cpu);
26626+ struct tss_struct *tss = init_tss + cpu;
26627 fpu_switch_t fpu;
26628
26629 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
26630@@ -272,6 +273,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26631 */
26632 lazy_save_gs(prev->gs);
26633
26634+#ifdef CONFIG_PAX_MEMORY_UDEREF
26635+ __set_fs(task_thread_info(next_p)->addr_limit);
26636+#endif
26637+
26638 /*
26639 * Load the per-thread Thread-Local Storage descriptor.
26640 */
26641@@ -310,9 +315,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26642 */
26643 arch_end_context_switch(next_p);
26644
26645- this_cpu_write(kernel_stack,
26646- (unsigned long)task_stack_page(next_p) +
26647- THREAD_SIZE - KERNEL_STACK_OFFSET);
26648+ this_cpu_write(current_task, next_p);
26649+ this_cpu_write(current_tinfo, &next_p->tinfo);
26650+ this_cpu_write(kernel_stack, next->sp0);
26651
26652 /*
26653 * Restore %gs if needed (which is common)
26654@@ -322,8 +327,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26655
26656 switch_fpu_finish(next_p, fpu);
26657
26658- this_cpu_write(current_task, next_p);
26659-
26660 return prev_p;
26661 }
26662
26663@@ -353,4 +356,3 @@ unsigned long get_wchan(struct task_struct *p)
26664 } while (count++ < 16);
26665 return 0;
26666 }
26667-
26668diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
26669index 5a2c029..ec8611d 100644
26670--- a/arch/x86/kernel/process_64.c
26671+++ b/arch/x86/kernel/process_64.c
26672@@ -158,10 +158,11 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
26673 struct pt_regs *childregs;
26674 struct task_struct *me = current;
26675
26676- p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE;
26677+ p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE - 16;
26678 childregs = task_pt_regs(p);
26679 p->thread.sp = (unsigned long) childregs;
26680 p->thread.usersp = me->thread.usersp;
26681+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p) + 2 * sizeof(unsigned long);
26682 set_tsk_thread_flag(p, TIF_FORK);
26683 p->thread.io_bitmap_ptr = NULL;
26684
26685@@ -171,6 +172,8 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
26686 p->thread.fs = p->thread.fsindex ? 0 : me->thread.fs;
26687 savesegment(es, p->thread.es);
26688 savesegment(ds, p->thread.ds);
26689+ savesegment(ss, p->thread.ss);
26690+ BUG_ON(p->thread.ss == __UDEREF_KERNEL_DS);
26691 memset(p->thread.ptrace_bps, 0, sizeof(p->thread.ptrace_bps));
26692
26693 if (unlikely(p->flags & PF_KTHREAD)) {
26694@@ -277,7 +280,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26695 struct thread_struct *prev = &prev_p->thread;
26696 struct thread_struct *next = &next_p->thread;
26697 int cpu = smp_processor_id();
26698- struct tss_struct *tss = &per_cpu(init_tss, cpu);
26699+ struct tss_struct *tss = init_tss + cpu;
26700 unsigned fsindex, gsindex;
26701 fpu_switch_t fpu;
26702
26703@@ -331,6 +334,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26704 if (unlikely(next->ds | prev->ds))
26705 loadsegment(ds, next->ds);
26706
26707+ savesegment(ss, prev->ss);
26708+ if (unlikely(next->ss != prev->ss))
26709+ loadsegment(ss, next->ss);
26710+
26711 /*
26712 * Switch FS and GS.
26713 *
26714@@ -404,6 +411,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26715 prev->usersp = this_cpu_read(old_rsp);
26716 this_cpu_write(old_rsp, next->usersp);
26717 this_cpu_write(current_task, next_p);
26718+ this_cpu_write(current_tinfo, &next_p->tinfo);
26719
26720 /*
26721 * If it were not for PREEMPT_ACTIVE we could guarantee that the
26722@@ -413,9 +421,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26723 task_thread_info(prev_p)->saved_preempt_count = this_cpu_read(__preempt_count);
26724 this_cpu_write(__preempt_count, task_thread_info(next_p)->saved_preempt_count);
26725
26726- this_cpu_write(kernel_stack,
26727- (unsigned long)task_stack_page(next_p) +
26728- THREAD_SIZE - KERNEL_STACK_OFFSET);
26729+ this_cpu_write(kernel_stack, next->sp0);
26730
26731 /*
26732 * Now maybe reload the debug registers and handle I/O bitmaps
26733@@ -485,12 +491,11 @@ unsigned long get_wchan(struct task_struct *p)
26734 if (!p || p == current || p->state == TASK_RUNNING)
26735 return 0;
26736 stack = (unsigned long)task_stack_page(p);
26737- if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
26738+ if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
26739 return 0;
26740 fp = *(u64 *)(p->thread.sp);
26741 do {
26742- if (fp < (unsigned long)stack ||
26743- fp >= (unsigned long)stack+THREAD_SIZE)
26744+ if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
26745 return 0;
26746 ip = *(u64 *)(fp+8);
26747 if (!in_sched_functions(ip))
26748diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
26749index e510618..5165ac0 100644
26750--- a/arch/x86/kernel/ptrace.c
26751+++ b/arch/x86/kernel/ptrace.c
26752@@ -186,10 +186,10 @@ unsigned long kernel_stack_pointer(struct pt_regs *regs)
26753 unsigned long sp = (unsigned long)&regs->sp;
26754 u32 *prev_esp;
26755
26756- if (context == (sp & ~(THREAD_SIZE - 1)))
26757+ if (context == ((sp + 8) & ~(THREAD_SIZE - 1)))
26758 return sp;
26759
26760- prev_esp = (u32 *)(context);
26761+ prev_esp = *(u32 **)(context);
26762 if (prev_esp)
26763 return (unsigned long)prev_esp;
26764
26765@@ -452,6 +452,20 @@ static int putreg(struct task_struct *child,
26766 if (child->thread.gs != value)
26767 return do_arch_prctl(child, ARCH_SET_GS, value);
26768 return 0;
26769+
26770+ case offsetof(struct user_regs_struct,ip):
26771+ /*
26772+ * Protect against any attempt to set ip to an
26773+ * impossible address. There are dragons lurking if the
26774+ * address is noncanonical. (This explicitly allows
26775+ * setting ip to TASK_SIZE_MAX, because user code can do
26776+ * that all by itself by running off the end of its
26777+ * address space.
26778+ */
26779+ if (value > TASK_SIZE_MAX)
26780+ return -EIO;
26781+ break;
26782+
26783 #endif
26784 }
26785
26786@@ -588,7 +602,7 @@ static void ptrace_triggered(struct perf_event *bp,
26787 static unsigned long ptrace_get_dr7(struct perf_event *bp[])
26788 {
26789 int i;
26790- int dr7 = 0;
26791+ unsigned long dr7 = 0;
26792 struct arch_hw_breakpoint *info;
26793
26794 for (i = 0; i < HBP_NUM; i++) {
26795@@ -822,7 +836,7 @@ long arch_ptrace(struct task_struct *child, long request,
26796 unsigned long addr, unsigned long data)
26797 {
26798 int ret;
26799- unsigned long __user *datap = (unsigned long __user *)data;
26800+ unsigned long __user *datap = (__force unsigned long __user *)data;
26801
26802 switch (request) {
26803 /* read the word at location addr in the USER area. */
26804@@ -907,14 +921,14 @@ long arch_ptrace(struct task_struct *child, long request,
26805 if ((int) addr < 0)
26806 return -EIO;
26807 ret = do_get_thread_area(child, addr,
26808- (struct user_desc __user *)data);
26809+ (__force struct user_desc __user *) data);
26810 break;
26811
26812 case PTRACE_SET_THREAD_AREA:
26813 if ((int) addr < 0)
26814 return -EIO;
26815 ret = do_set_thread_area(child, addr,
26816- (struct user_desc __user *)data, 0);
26817+ (__force struct user_desc __user *) data, 0);
26818 break;
26819 #endif
26820
26821@@ -1292,7 +1306,7 @@ long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
26822
26823 #ifdef CONFIG_X86_64
26824
26825-static struct user_regset x86_64_regsets[] __read_mostly = {
26826+static user_regset_no_const x86_64_regsets[] __read_only = {
26827 [REGSET_GENERAL] = {
26828 .core_note_type = NT_PRSTATUS,
26829 .n = sizeof(struct user_regs_struct) / sizeof(long),
26830@@ -1333,7 +1347,7 @@ static const struct user_regset_view user_x86_64_view = {
26831 #endif /* CONFIG_X86_64 */
26832
26833 #if defined CONFIG_X86_32 || defined CONFIG_IA32_EMULATION
26834-static struct user_regset x86_32_regsets[] __read_mostly = {
26835+static user_regset_no_const x86_32_regsets[] __read_only = {
26836 [REGSET_GENERAL] = {
26837 .core_note_type = NT_PRSTATUS,
26838 .n = sizeof(struct user_regs_struct32) / sizeof(u32),
26839@@ -1386,7 +1400,7 @@ static const struct user_regset_view user_x86_32_view = {
26840 */
26841 u64 xstate_fx_sw_bytes[USER_XSTATE_FX_SW_WORDS];
26842
26843-void update_regset_xstate_info(unsigned int size, u64 xstate_mask)
26844+void __init update_regset_xstate_info(unsigned int size, u64 xstate_mask)
26845 {
26846 #ifdef CONFIG_X86_64
26847 x86_64_regsets[REGSET_XSTATE].n = size / sizeof(u64);
26848@@ -1421,7 +1435,7 @@ static void fill_sigtrap_info(struct task_struct *tsk,
26849 memset(info, 0, sizeof(*info));
26850 info->si_signo = SIGTRAP;
26851 info->si_code = si_code;
26852- info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
26853+ info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
26854 }
26855
26856 void user_single_step_siginfo(struct task_struct *tsk,
26857@@ -1455,6 +1469,10 @@ static void do_audit_syscall_entry(struct pt_regs *regs, u32 arch)
26858 }
26859 }
26860
26861+#ifdef CONFIG_GRKERNSEC_SETXID
26862+extern void gr_delayed_cred_worker(void);
26863+#endif
26864+
26865 /*
26866 * We can return 0 to resume the syscall or anything else to go to phase
26867 * 2. If we resume the syscall, we need to put something appropriate in
26868@@ -1562,6 +1580,11 @@ long syscall_trace_enter_phase2(struct pt_regs *regs, u32 arch,
26869
26870 BUG_ON(regs != task_pt_regs(current));
26871
26872+#ifdef CONFIG_GRKERNSEC_SETXID
26873+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
26874+ gr_delayed_cred_worker();
26875+#endif
26876+
26877 /*
26878 * If we stepped into a sysenter/syscall insn, it trapped in
26879 * kernel mode; do_debug() cleared TF and set TIF_SINGLESTEP.
26880@@ -1620,6 +1643,11 @@ void syscall_trace_leave(struct pt_regs *regs)
26881 */
26882 user_exit();
26883
26884+#ifdef CONFIG_GRKERNSEC_SETXID
26885+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
26886+ gr_delayed_cred_worker();
26887+#endif
26888+
26889 audit_syscall_exit(regs);
26890
26891 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
26892diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
26893index 2f355d2..e75ed0a 100644
26894--- a/arch/x86/kernel/pvclock.c
26895+++ b/arch/x86/kernel/pvclock.c
26896@@ -51,11 +51,11 @@ void pvclock_touch_watchdogs(void)
26897 reset_hung_task_detector();
26898 }
26899
26900-static atomic64_t last_value = ATOMIC64_INIT(0);
26901+static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
26902
26903 void pvclock_resume(void)
26904 {
26905- atomic64_set(&last_value, 0);
26906+ atomic64_set_unchecked(&last_value, 0);
26907 }
26908
26909 u8 pvclock_read_flags(struct pvclock_vcpu_time_info *src)
26910@@ -105,11 +105,11 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
26911 * updating at the same time, and one of them could be slightly behind,
26912 * making the assumption that last_value always go forward fail to hold.
26913 */
26914- last = atomic64_read(&last_value);
26915+ last = atomic64_read_unchecked(&last_value);
26916 do {
26917 if (ret < last)
26918 return last;
26919- last = atomic64_cmpxchg(&last_value, last, ret);
26920+ last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
26921 } while (unlikely(last != ret));
26922
26923 return ret;
26924diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
26925index 17962e6..47f55db 100644
26926--- a/arch/x86/kernel/reboot.c
26927+++ b/arch/x86/kernel/reboot.c
26928@@ -69,6 +69,11 @@ static int __init set_bios_reboot(const struct dmi_system_id *d)
26929
26930 void __noreturn machine_real_restart(unsigned int type)
26931 {
26932+
26933+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
26934+ struct desc_struct *gdt;
26935+#endif
26936+
26937 local_irq_disable();
26938
26939 /*
26940@@ -96,7 +101,29 @@ void __noreturn machine_real_restart(unsigned int type)
26941
26942 /* Jump to the identity-mapped low memory code */
26943 #ifdef CONFIG_X86_32
26944- asm volatile("jmpl *%0" : :
26945+
26946+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
26947+ gdt = get_cpu_gdt_table(smp_processor_id());
26948+ pax_open_kernel();
26949+#ifdef CONFIG_PAX_MEMORY_UDEREF
26950+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
26951+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
26952+ loadsegment(ds, __KERNEL_DS);
26953+ loadsegment(es, __KERNEL_DS);
26954+ loadsegment(ss, __KERNEL_DS);
26955+#endif
26956+#ifdef CONFIG_PAX_KERNEXEC
26957+ gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
26958+ gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
26959+ gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
26960+ gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
26961+ gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
26962+ gdt[GDT_ENTRY_KERNEL_CS].g = 1;
26963+#endif
26964+ pax_close_kernel();
26965+#endif
26966+
26967+ asm volatile("ljmpl *%0" : :
26968 "rm" (real_mode_header->machine_real_restart_asm),
26969 "a" (type));
26970 #else
26971@@ -500,7 +527,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
26972 * This means that this function can never return, it can misbehave
26973 * by not rebooting properly and hanging.
26974 */
26975-static void native_machine_emergency_restart(void)
26976+static void __noreturn native_machine_emergency_restart(void)
26977 {
26978 int i;
26979 int attempt = 0;
26980@@ -620,13 +647,13 @@ void native_machine_shutdown(void)
26981 #endif
26982 }
26983
26984-static void __machine_emergency_restart(int emergency)
26985+static void __noreturn __machine_emergency_restart(int emergency)
26986 {
26987 reboot_emergency = emergency;
26988 machine_ops.emergency_restart();
26989 }
26990
26991-static void native_machine_restart(char *__unused)
26992+static void __noreturn native_machine_restart(char *__unused)
26993 {
26994 pr_notice("machine restart\n");
26995
26996@@ -635,7 +662,7 @@ static void native_machine_restart(char *__unused)
26997 __machine_emergency_restart(0);
26998 }
26999
27000-static void native_machine_halt(void)
27001+static void __noreturn native_machine_halt(void)
27002 {
27003 /* Stop other cpus and apics */
27004 machine_shutdown();
27005@@ -645,7 +672,7 @@ static void native_machine_halt(void)
27006 stop_this_cpu(NULL);
27007 }
27008
27009-static void native_machine_power_off(void)
27010+static void __noreturn native_machine_power_off(void)
27011 {
27012 if (pm_power_off) {
27013 if (!reboot_force)
27014@@ -654,9 +681,10 @@ static void native_machine_power_off(void)
27015 }
27016 /* A fallback in case there is no PM info available */
27017 tboot_shutdown(TB_SHUTDOWN_HALT);
27018+ unreachable();
27019 }
27020
27021-struct machine_ops machine_ops = {
27022+struct machine_ops machine_ops __read_only = {
27023 .power_off = native_machine_power_off,
27024 .shutdown = native_machine_shutdown,
27025 .emergency_restart = native_machine_emergency_restart,
27026diff --git a/arch/x86/kernel/reboot_fixups_32.c b/arch/x86/kernel/reboot_fixups_32.c
27027index c8e41e9..64049ef 100644
27028--- a/arch/x86/kernel/reboot_fixups_32.c
27029+++ b/arch/x86/kernel/reboot_fixups_32.c
27030@@ -57,7 +57,7 @@ struct device_fixup {
27031 unsigned int vendor;
27032 unsigned int device;
27033 void (*reboot_fixup)(struct pci_dev *);
27034-};
27035+} __do_const;
27036
27037 /*
27038 * PCI ids solely used for fixups_table go here
27039diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
27040index 3fd2c69..a444264 100644
27041--- a/arch/x86/kernel/relocate_kernel_64.S
27042+++ b/arch/x86/kernel/relocate_kernel_64.S
27043@@ -96,8 +96,7 @@ relocate_kernel:
27044
27045 /* jump to identity mapped page */
27046 addq $(identity_mapped - relocate_kernel), %r8
27047- pushq %r8
27048- ret
27049+ jmp *%r8
27050
27051 identity_mapped:
27052 /* set return address to 0 if not preserving context */
27053diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
27054index ab08aa2..6d74a3a 100644
27055--- a/arch/x86/kernel/setup.c
27056+++ b/arch/x86/kernel/setup.c
27057@@ -110,6 +110,7 @@
27058 #include <asm/mce.h>
27059 #include <asm/alternative.h>
27060 #include <asm/prom.h>
27061+#include <asm/boot.h>
27062
27063 /*
27064 * max_low_pfn_mapped: highest direct mapped pfn under 4GB
27065@@ -205,12 +206,50 @@ EXPORT_SYMBOL(boot_cpu_data);
27066 #endif
27067
27068
27069-#if !defined(CONFIG_X86_PAE) || defined(CONFIG_X86_64)
27070-__visible unsigned long mmu_cr4_features;
27071+#ifdef CONFIG_X86_64
27072+__visible unsigned long mmu_cr4_features __read_only = X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE;
27073+#elif defined(CONFIG_X86_PAE)
27074+__visible unsigned long mmu_cr4_features __read_only = X86_CR4_PAE;
27075 #else
27076-__visible unsigned long mmu_cr4_features = X86_CR4_PAE;
27077+__visible unsigned long mmu_cr4_features __read_only;
27078 #endif
27079
27080+void set_in_cr4(unsigned long mask)
27081+{
27082+ unsigned long cr4 = read_cr4();
27083+
27084+ if ((cr4 & mask) == mask && cr4 == mmu_cr4_features)
27085+ return;
27086+
27087+ pax_open_kernel();
27088+ mmu_cr4_features |= mask;
27089+ pax_close_kernel();
27090+
27091+ if (trampoline_cr4_features)
27092+ *trampoline_cr4_features = mmu_cr4_features;
27093+ cr4 |= mask;
27094+ write_cr4(cr4);
27095+}
27096+EXPORT_SYMBOL(set_in_cr4);
27097+
27098+void clear_in_cr4(unsigned long mask)
27099+{
27100+ unsigned long cr4 = read_cr4();
27101+
27102+ if (!(cr4 & mask) && cr4 == mmu_cr4_features)
27103+ return;
27104+
27105+ pax_open_kernel();
27106+ mmu_cr4_features &= ~mask;
27107+ pax_close_kernel();
27108+
27109+ if (trampoline_cr4_features)
27110+ *trampoline_cr4_features = mmu_cr4_features;
27111+ cr4 &= ~mask;
27112+ write_cr4(cr4);
27113+}
27114+EXPORT_SYMBOL(clear_in_cr4);
27115+
27116 /* Boot loader ID and version as integers, for the benefit of proc_dointvec */
27117 int bootloader_type, bootloader_version;
27118
27119@@ -772,7 +811,7 @@ static void __init trim_bios_range(void)
27120 * area (640->1Mb) as ram even though it is not.
27121 * take them out.
27122 */
27123- e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
27124+ e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
27125
27126 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
27127 }
27128@@ -780,7 +819,7 @@ static void __init trim_bios_range(void)
27129 /* called before trim_bios_range() to spare extra sanitize */
27130 static void __init e820_add_kernel_range(void)
27131 {
27132- u64 start = __pa_symbol(_text);
27133+ u64 start = __pa_symbol(ktla_ktva(_text));
27134 u64 size = __pa_symbol(_end) - start;
27135
27136 /*
27137@@ -856,8 +895,12 @@ dump_kernel_offset(struct notifier_block *self, unsigned long v, void *p)
27138
27139 void __init setup_arch(char **cmdline_p)
27140 {
27141+#ifdef CONFIG_X86_32
27142+ memblock_reserve(LOAD_PHYSICAL_ADDR, __pa_symbol(__bss_stop) - LOAD_PHYSICAL_ADDR);
27143+#else
27144 memblock_reserve(__pa_symbol(_text),
27145 (unsigned long)__bss_stop - (unsigned long)_text);
27146+#endif
27147
27148 early_reserve_initrd();
27149
27150@@ -955,14 +998,14 @@ void __init setup_arch(char **cmdline_p)
27151
27152 if (!boot_params.hdr.root_flags)
27153 root_mountflags &= ~MS_RDONLY;
27154- init_mm.start_code = (unsigned long) _text;
27155- init_mm.end_code = (unsigned long) _etext;
27156+ init_mm.start_code = ktla_ktva((unsigned long) _text);
27157+ init_mm.end_code = ktla_ktva((unsigned long) _etext);
27158 init_mm.end_data = (unsigned long) _edata;
27159 init_mm.brk = _brk_end;
27160
27161- code_resource.start = __pa_symbol(_text);
27162- code_resource.end = __pa_symbol(_etext)-1;
27163- data_resource.start = __pa_symbol(_etext);
27164+ code_resource.start = __pa_symbol(ktla_ktva(_text));
27165+ code_resource.end = __pa_symbol(ktla_ktva(_etext))-1;
27166+ data_resource.start = __pa_symbol(_sdata);
27167 data_resource.end = __pa_symbol(_edata)-1;
27168 bss_resource.start = __pa_symbol(__bss_start);
27169 bss_resource.end = __pa_symbol(__bss_stop)-1;
27170diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
27171index 5cdff03..80fa283 100644
27172--- a/arch/x86/kernel/setup_percpu.c
27173+++ b/arch/x86/kernel/setup_percpu.c
27174@@ -21,19 +21,17 @@
27175 #include <asm/cpu.h>
27176 #include <asm/stackprotector.h>
27177
27178-DEFINE_PER_CPU_READ_MOSTLY(int, cpu_number);
27179+#ifdef CONFIG_SMP
27180+DEFINE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
27181 EXPORT_PER_CPU_SYMBOL(cpu_number);
27182+#endif
27183
27184-#ifdef CONFIG_X86_64
27185 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
27186-#else
27187-#define BOOT_PERCPU_OFFSET 0
27188-#endif
27189
27190 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
27191 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
27192
27193-unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
27194+unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
27195 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
27196 };
27197 EXPORT_SYMBOL(__per_cpu_offset);
27198@@ -66,7 +64,7 @@ static bool __init pcpu_need_numa(void)
27199 {
27200 #ifdef CONFIG_NEED_MULTIPLE_NODES
27201 pg_data_t *last = NULL;
27202- unsigned int cpu;
27203+ int cpu;
27204
27205 for_each_possible_cpu(cpu) {
27206 int node = early_cpu_to_node(cpu);
27207@@ -155,10 +153,10 @@ static inline void setup_percpu_segment(int cpu)
27208 {
27209 #ifdef CONFIG_X86_32
27210 struct desc_struct gdt;
27211+ unsigned long base = per_cpu_offset(cpu);
27212
27213- pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
27214- 0x2 | DESCTYPE_S, 0x8);
27215- gdt.s = 1;
27216+ pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
27217+ 0x83 | DESCTYPE_S, 0xC);
27218 write_gdt_entry(get_cpu_gdt_table(cpu),
27219 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
27220 #endif
27221@@ -219,6 +217,11 @@ void __init setup_per_cpu_areas(void)
27222 /* alrighty, percpu areas up and running */
27223 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
27224 for_each_possible_cpu(cpu) {
27225+#ifdef CONFIG_CC_STACKPROTECTOR
27226+#ifdef CONFIG_X86_32
27227+ unsigned long canary = per_cpu(stack_canary.canary, cpu);
27228+#endif
27229+#endif
27230 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
27231 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
27232 per_cpu(cpu_number, cpu) = cpu;
27233@@ -259,6 +262,12 @@ void __init setup_per_cpu_areas(void)
27234 */
27235 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
27236 #endif
27237+#ifdef CONFIG_CC_STACKPROTECTOR
27238+#ifdef CONFIG_X86_32
27239+ if (!cpu)
27240+ per_cpu(stack_canary.canary, cpu) = canary;
27241+#endif
27242+#endif
27243 /*
27244 * Up to this point, the boot CPU has been using .init.data
27245 * area. Reload any changed state for the boot CPU.
27246diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
27247index ed37a76..39f936e 100644
27248--- a/arch/x86/kernel/signal.c
27249+++ b/arch/x86/kernel/signal.c
27250@@ -190,7 +190,7 @@ static unsigned long align_sigframe(unsigned long sp)
27251 * Align the stack pointer according to the i386 ABI,
27252 * i.e. so that on function entry ((sp + 4) & 15) == 0.
27253 */
27254- sp = ((sp + 4) & -16ul) - 4;
27255+ sp = ((sp - 12) & -16ul) - 4;
27256 #else /* !CONFIG_X86_32 */
27257 sp = round_down(sp, 16) - 8;
27258 #endif
27259@@ -298,10 +298,9 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
27260 }
27261
27262 if (current->mm->context.vdso)
27263- restorer = current->mm->context.vdso +
27264- selected_vdso32->sym___kernel_sigreturn;
27265+ restorer = (void __force_user *)(current->mm->context.vdso + selected_vdso32->sym___kernel_sigreturn);
27266 else
27267- restorer = &frame->retcode;
27268+ restorer = (void __user *)&frame->retcode;
27269 if (ksig->ka.sa.sa_flags & SA_RESTORER)
27270 restorer = ksig->ka.sa.sa_restorer;
27271
27272@@ -315,7 +314,7 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
27273 * reasons and because gdb uses it as a signature to notice
27274 * signal handler stack frames.
27275 */
27276- err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
27277+ err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
27278
27279 if (err)
27280 return -EFAULT;
27281@@ -362,8 +361,10 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
27282 save_altstack_ex(&frame->uc.uc_stack, regs->sp);
27283
27284 /* Set up to return from userspace. */
27285- restorer = current->mm->context.vdso +
27286- selected_vdso32->sym___kernel_rt_sigreturn;
27287+ if (current->mm->context.vdso)
27288+ restorer = (void __force_user *)(current->mm->context.vdso + selected_vdso32->sym___kernel_rt_sigreturn);
27289+ else
27290+ restorer = (void __user *)&frame->retcode;
27291 if (ksig->ka.sa.sa_flags & SA_RESTORER)
27292 restorer = ksig->ka.sa.sa_restorer;
27293 put_user_ex(restorer, &frame->pretcode);
27294@@ -375,7 +376,7 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
27295 * reasons and because gdb uses it as a signature to notice
27296 * signal handler stack frames.
27297 */
27298- put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
27299+ put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
27300 } put_user_catch(err);
27301
27302 err |= copy_siginfo_to_user(&frame->info, &ksig->info);
27303@@ -611,7 +612,12 @@ setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
27304 {
27305 int usig = signr_convert(ksig->sig);
27306 sigset_t *set = sigmask_to_save();
27307- compat_sigset_t *cset = (compat_sigset_t *) set;
27308+ sigset_t sigcopy;
27309+ compat_sigset_t *cset;
27310+
27311+ sigcopy = *set;
27312+
27313+ cset = (compat_sigset_t *) &sigcopy;
27314
27315 /* Set up the stack frame */
27316 if (is_ia32_frame()) {
27317@@ -622,7 +628,7 @@ setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
27318 } else if (is_x32_frame()) {
27319 return x32_setup_rt_frame(ksig, cset, regs);
27320 } else {
27321- return __setup_rt_frame(ksig->sig, ksig, set, regs);
27322+ return __setup_rt_frame(ksig->sig, ksig, &sigcopy, regs);
27323 }
27324 }
27325
27326diff --git a/arch/x86/kernel/smp.c b/arch/x86/kernel/smp.c
27327index be8e1bd..a3d93fa 100644
27328--- a/arch/x86/kernel/smp.c
27329+++ b/arch/x86/kernel/smp.c
27330@@ -341,7 +341,7 @@ static int __init nonmi_ipi_setup(char *str)
27331
27332 __setup("nonmi_ipi", nonmi_ipi_setup);
27333
27334-struct smp_ops smp_ops = {
27335+struct smp_ops smp_ops __read_only = {
27336 .smp_prepare_boot_cpu = native_smp_prepare_boot_cpu,
27337 .smp_prepare_cpus = native_smp_prepare_cpus,
27338 .smp_cpus_done = native_smp_cpus_done,
27339diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
27340index 668d8f2..84a9d54 100644
27341--- a/arch/x86/kernel/smpboot.c
27342+++ b/arch/x86/kernel/smpboot.c
27343@@ -194,14 +194,17 @@ static void notrace start_secondary(void *unused)
27344
27345 enable_start_cpu0 = 0;
27346
27347-#ifdef CONFIG_X86_32
27348+ /* otherwise gcc will move up smp_processor_id before the cpu_init */
27349+ barrier();
27350+
27351 /* switch away from the initial page table */
27352+#ifdef CONFIG_PAX_PER_CPU_PGD
27353+ load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
27354+#else
27355 load_cr3(swapper_pg_dir);
27356+#endif
27357 __flush_tlb_all();
27358-#endif
27359
27360- /* otherwise gcc will move up smp_processor_id before the cpu_init */
27361- barrier();
27362 /*
27363 * Check TSC synchronization with the BP:
27364 */
27365@@ -765,8 +768,9 @@ static int do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
27366 alternatives_enable_smp();
27367
27368 idle->thread.sp = (unsigned long) (((struct pt_regs *)
27369- (THREAD_SIZE + task_stack_page(idle))) - 1);
27370+ (THREAD_SIZE - 16 + task_stack_page(idle))) - 1);
27371 per_cpu(current_task, cpu) = idle;
27372+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
27373
27374 #ifdef CONFIG_X86_32
27375 /* Stack for startup_32 can be just as for start_secondary onwards */
27376@@ -775,10 +779,10 @@ static int do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
27377 clear_tsk_thread_flag(idle, TIF_FORK);
27378 initial_gs = per_cpu_offset(cpu);
27379 #endif
27380- per_cpu(kernel_stack, cpu) =
27381- (unsigned long)task_stack_page(idle) -
27382- KERNEL_STACK_OFFSET + THREAD_SIZE;
27383+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
27384+ pax_open_kernel();
27385 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
27386+ pax_close_kernel();
27387 initial_code = (unsigned long)start_secondary;
27388 stack_start = idle->thread.sp;
27389
27390@@ -918,6 +922,15 @@ int native_cpu_up(unsigned int cpu, struct task_struct *tidle)
27391 /* the FPU context is blank, nobody can own it */
27392 __cpu_disable_lazy_restore(cpu);
27393
27394+#ifdef CONFIG_PAX_PER_CPU_PGD
27395+ clone_pgd_range(get_cpu_pgd(cpu, kernel) + KERNEL_PGD_BOUNDARY,
27396+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
27397+ KERNEL_PGD_PTRS);
27398+ clone_pgd_range(get_cpu_pgd(cpu, user) + KERNEL_PGD_BOUNDARY,
27399+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
27400+ KERNEL_PGD_PTRS);
27401+#endif
27402+
27403 err = do_boot_cpu(apicid, cpu, tidle);
27404 if (err) {
27405 pr_err("do_boot_cpu failed(%d) to wakeup CPU#%u\n", err, cpu);
27406diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
27407index 9b4d51d..5d28b58 100644
27408--- a/arch/x86/kernel/step.c
27409+++ b/arch/x86/kernel/step.c
27410@@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
27411 struct desc_struct *desc;
27412 unsigned long base;
27413
27414- seg &= ~7UL;
27415+ seg >>= 3;
27416
27417 mutex_lock(&child->mm->context.lock);
27418- if (unlikely((seg >> 3) >= child->mm->context.size))
27419+ if (unlikely(seg >= child->mm->context.size))
27420 addr = -1L; /* bogus selector, access would fault */
27421 else {
27422 desc = child->mm->context.ldt + seg;
27423@@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
27424 addr += base;
27425 }
27426 mutex_unlock(&child->mm->context.lock);
27427- }
27428+ } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
27429+ addr = ktla_ktva(addr);
27430
27431 return addr;
27432 }
27433@@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
27434 unsigned char opcode[15];
27435 unsigned long addr = convert_ip_to_linear(child, regs);
27436
27437+ if (addr == -EINVAL)
27438+ return 0;
27439+
27440 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
27441 for (i = 0; i < copied; i++) {
27442 switch (opcode[i]) {
27443diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
27444new file mode 100644
27445index 0000000..5877189
27446--- /dev/null
27447+++ b/arch/x86/kernel/sys_i386_32.c
27448@@ -0,0 +1,189 @@
27449+/*
27450+ * This file contains various random system calls that
27451+ * have a non-standard calling sequence on the Linux/i386
27452+ * platform.
27453+ */
27454+
27455+#include <linux/errno.h>
27456+#include <linux/sched.h>
27457+#include <linux/mm.h>
27458+#include <linux/fs.h>
27459+#include <linux/smp.h>
27460+#include <linux/sem.h>
27461+#include <linux/msg.h>
27462+#include <linux/shm.h>
27463+#include <linux/stat.h>
27464+#include <linux/syscalls.h>
27465+#include <linux/mman.h>
27466+#include <linux/file.h>
27467+#include <linux/utsname.h>
27468+#include <linux/ipc.h>
27469+#include <linux/elf.h>
27470+
27471+#include <linux/uaccess.h>
27472+#include <linux/unistd.h>
27473+
27474+#include <asm/syscalls.h>
27475+
27476+int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
27477+{
27478+ unsigned long pax_task_size = TASK_SIZE;
27479+
27480+#ifdef CONFIG_PAX_SEGMEXEC
27481+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
27482+ pax_task_size = SEGMEXEC_TASK_SIZE;
27483+#endif
27484+
27485+ if (flags & MAP_FIXED)
27486+ if (len > pax_task_size || addr > pax_task_size - len)
27487+ return -EINVAL;
27488+
27489+ return 0;
27490+}
27491+
27492+/*
27493+ * Align a virtual address to avoid aliasing in the I$ on AMD F15h.
27494+ */
27495+static unsigned long get_align_mask(void)
27496+{
27497+ if (va_align.flags < 0 || !(va_align.flags & ALIGN_VA_32))
27498+ return 0;
27499+
27500+ if (!(current->flags & PF_RANDOMIZE))
27501+ return 0;
27502+
27503+ return va_align.mask;
27504+}
27505+
27506+unsigned long
27507+arch_get_unmapped_area(struct file *filp, unsigned long addr,
27508+ unsigned long len, unsigned long pgoff, unsigned long flags)
27509+{
27510+ struct mm_struct *mm = current->mm;
27511+ struct vm_area_struct *vma;
27512+ unsigned long pax_task_size = TASK_SIZE;
27513+ struct vm_unmapped_area_info info;
27514+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
27515+
27516+#ifdef CONFIG_PAX_SEGMEXEC
27517+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
27518+ pax_task_size = SEGMEXEC_TASK_SIZE;
27519+#endif
27520+
27521+ pax_task_size -= PAGE_SIZE;
27522+
27523+ if (len > pax_task_size)
27524+ return -ENOMEM;
27525+
27526+ if (flags & MAP_FIXED)
27527+ return addr;
27528+
27529+#ifdef CONFIG_PAX_RANDMMAP
27530+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27531+#endif
27532+
27533+ if (addr) {
27534+ addr = PAGE_ALIGN(addr);
27535+ if (pax_task_size - len >= addr) {
27536+ vma = find_vma(mm, addr);
27537+ if (check_heap_stack_gap(vma, addr, len, offset))
27538+ return addr;
27539+ }
27540+ }
27541+
27542+ info.flags = 0;
27543+ info.length = len;
27544+ info.align_mask = filp ? get_align_mask() : 0;
27545+ info.align_offset = pgoff << PAGE_SHIFT;
27546+ info.threadstack_offset = offset;
27547+
27548+#ifdef CONFIG_PAX_PAGEEXEC
27549+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE)) {
27550+ info.low_limit = 0x00110000UL;
27551+ info.high_limit = mm->start_code;
27552+
27553+#ifdef CONFIG_PAX_RANDMMAP
27554+ if (mm->pax_flags & MF_PAX_RANDMMAP)
27555+ info.low_limit += mm->delta_mmap & 0x03FFF000UL;
27556+#endif
27557+
27558+ if (info.low_limit < info.high_limit) {
27559+ addr = vm_unmapped_area(&info);
27560+ if (!IS_ERR_VALUE(addr))
27561+ return addr;
27562+ }
27563+ } else
27564+#endif
27565+
27566+ info.low_limit = mm->mmap_base;
27567+ info.high_limit = pax_task_size;
27568+
27569+ return vm_unmapped_area(&info);
27570+}
27571+
27572+unsigned long
27573+arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27574+ const unsigned long len, const unsigned long pgoff,
27575+ const unsigned long flags)
27576+{
27577+ struct vm_area_struct *vma;
27578+ struct mm_struct *mm = current->mm;
27579+ unsigned long addr = addr0, pax_task_size = TASK_SIZE;
27580+ struct vm_unmapped_area_info info;
27581+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
27582+
27583+#ifdef CONFIG_PAX_SEGMEXEC
27584+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
27585+ pax_task_size = SEGMEXEC_TASK_SIZE;
27586+#endif
27587+
27588+ pax_task_size -= PAGE_SIZE;
27589+
27590+ /* requested length too big for entire address space */
27591+ if (len > pax_task_size)
27592+ return -ENOMEM;
27593+
27594+ if (flags & MAP_FIXED)
27595+ return addr;
27596+
27597+#ifdef CONFIG_PAX_PAGEEXEC
27598+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
27599+ goto bottomup;
27600+#endif
27601+
27602+#ifdef CONFIG_PAX_RANDMMAP
27603+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27604+#endif
27605+
27606+ /* requesting a specific address */
27607+ if (addr) {
27608+ addr = PAGE_ALIGN(addr);
27609+ if (pax_task_size - len >= addr) {
27610+ vma = find_vma(mm, addr);
27611+ if (check_heap_stack_gap(vma, addr, len, offset))
27612+ return addr;
27613+ }
27614+ }
27615+
27616+ info.flags = VM_UNMAPPED_AREA_TOPDOWN;
27617+ info.length = len;
27618+ info.low_limit = PAGE_SIZE;
27619+ info.high_limit = mm->mmap_base;
27620+ info.align_mask = filp ? get_align_mask() : 0;
27621+ info.align_offset = pgoff << PAGE_SHIFT;
27622+ info.threadstack_offset = offset;
27623+
27624+ addr = vm_unmapped_area(&info);
27625+ if (!(addr & ~PAGE_MASK))
27626+ return addr;
27627+ VM_BUG_ON(addr != -ENOMEM);
27628+
27629+bottomup:
27630+ /*
27631+ * A failed mmap() very likely causes application failure,
27632+ * so fall back to the bottom-up function here. This scenario
27633+ * can happen with large stack limits and large mmap()
27634+ * allocations.
27635+ */
27636+ return arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
27637+}
27638diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
27639index 30277e2..5664a29 100644
27640--- a/arch/x86/kernel/sys_x86_64.c
27641+++ b/arch/x86/kernel/sys_x86_64.c
27642@@ -81,8 +81,8 @@ out:
27643 return error;
27644 }
27645
27646-static void find_start_end(unsigned long flags, unsigned long *begin,
27647- unsigned long *end)
27648+static void find_start_end(struct mm_struct *mm, unsigned long flags,
27649+ unsigned long *begin, unsigned long *end)
27650 {
27651 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT)) {
27652 unsigned long new_begin;
27653@@ -101,7 +101,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
27654 *begin = new_begin;
27655 }
27656 } else {
27657- *begin = current->mm->mmap_legacy_base;
27658+ *begin = mm->mmap_legacy_base;
27659 *end = TASK_SIZE;
27660 }
27661 }
27662@@ -114,20 +114,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
27663 struct vm_area_struct *vma;
27664 struct vm_unmapped_area_info info;
27665 unsigned long begin, end;
27666+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
27667
27668 if (flags & MAP_FIXED)
27669 return addr;
27670
27671- find_start_end(flags, &begin, &end);
27672+ find_start_end(mm, flags, &begin, &end);
27673
27674 if (len > end)
27675 return -ENOMEM;
27676
27677+#ifdef CONFIG_PAX_RANDMMAP
27678+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27679+#endif
27680+
27681 if (addr) {
27682 addr = PAGE_ALIGN(addr);
27683 vma = find_vma(mm, addr);
27684- if (end - len >= addr &&
27685- (!vma || addr + len <= vma->vm_start))
27686+ if (end - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
27687 return addr;
27688 }
27689
27690@@ -137,6 +141,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
27691 info.high_limit = end;
27692 info.align_mask = filp ? get_align_mask() : 0;
27693 info.align_offset = pgoff << PAGE_SHIFT;
27694+ info.threadstack_offset = offset;
27695 return vm_unmapped_area(&info);
27696 }
27697
27698@@ -149,6 +154,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27699 struct mm_struct *mm = current->mm;
27700 unsigned long addr = addr0;
27701 struct vm_unmapped_area_info info;
27702+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
27703
27704 /* requested length too big for entire address space */
27705 if (len > TASK_SIZE)
27706@@ -161,12 +167,15 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27707 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT))
27708 goto bottomup;
27709
27710+#ifdef CONFIG_PAX_RANDMMAP
27711+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27712+#endif
27713+
27714 /* requesting a specific address */
27715 if (addr) {
27716 addr = PAGE_ALIGN(addr);
27717 vma = find_vma(mm, addr);
27718- if (TASK_SIZE - len >= addr &&
27719- (!vma || addr + len <= vma->vm_start))
27720+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
27721 return addr;
27722 }
27723
27724@@ -176,6 +185,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27725 info.high_limit = mm->mmap_base;
27726 info.align_mask = filp ? get_align_mask() : 0;
27727 info.align_offset = pgoff << PAGE_SHIFT;
27728+ info.threadstack_offset = offset;
27729 addr = vm_unmapped_area(&info);
27730 if (!(addr & ~PAGE_MASK))
27731 return addr;
27732diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
27733index 91a4496..bb87552 100644
27734--- a/arch/x86/kernel/tboot.c
27735+++ b/arch/x86/kernel/tboot.c
27736@@ -221,7 +221,7 @@ static int tboot_setup_sleep(void)
27737
27738 void tboot_shutdown(u32 shutdown_type)
27739 {
27740- void (*shutdown)(void);
27741+ void (* __noreturn shutdown)(void);
27742
27743 if (!tboot_enabled())
27744 return;
27745@@ -243,7 +243,7 @@ void tboot_shutdown(u32 shutdown_type)
27746
27747 switch_to_tboot_pt();
27748
27749- shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
27750+ shutdown = (void *)(unsigned long)tboot->shutdown_entry;
27751 shutdown();
27752
27753 /* should not reach here */
27754@@ -310,7 +310,7 @@ static int tboot_extended_sleep(u8 sleep_state, u32 val_a, u32 val_b)
27755 return -ENODEV;
27756 }
27757
27758-static atomic_t ap_wfs_count;
27759+static atomic_unchecked_t ap_wfs_count;
27760
27761 static int tboot_wait_for_aps(int num_aps)
27762 {
27763@@ -334,9 +334,9 @@ static int tboot_cpu_callback(struct notifier_block *nfb, unsigned long action,
27764 {
27765 switch (action) {
27766 case CPU_DYING:
27767- atomic_inc(&ap_wfs_count);
27768+ atomic_inc_unchecked(&ap_wfs_count);
27769 if (num_online_cpus() == 1)
27770- if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
27771+ if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
27772 return NOTIFY_BAD;
27773 break;
27774 }
27775@@ -422,7 +422,7 @@ static __init int tboot_late_init(void)
27776
27777 tboot_create_trampoline();
27778
27779- atomic_set(&ap_wfs_count, 0);
27780+ atomic_set_unchecked(&ap_wfs_count, 0);
27781 register_hotcpu_notifier(&tboot_cpu_notifier);
27782
27783 #ifdef CONFIG_DEBUG_FS
27784diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
27785index 0fa2960..91eabbe 100644
27786--- a/arch/x86/kernel/time.c
27787+++ b/arch/x86/kernel/time.c
27788@@ -30,9 +30,9 @@ unsigned long profile_pc(struct pt_regs *regs)
27789 {
27790 unsigned long pc = instruction_pointer(regs);
27791
27792- if (!user_mode_vm(regs) && in_lock_functions(pc)) {
27793+ if (!user_mode(regs) && in_lock_functions(pc)) {
27794 #ifdef CONFIG_FRAME_POINTER
27795- return *(unsigned long *)(regs->bp + sizeof(long));
27796+ return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
27797 #else
27798 unsigned long *sp =
27799 (unsigned long *)kernel_stack_pointer(regs);
27800@@ -41,11 +41,17 @@ unsigned long profile_pc(struct pt_regs *regs)
27801 * or above a saved flags. Eflags has bits 22-31 zero,
27802 * kernel addresses don't.
27803 */
27804+
27805+#ifdef CONFIG_PAX_KERNEXEC
27806+ return ktla_ktva(sp[0]);
27807+#else
27808 if (sp[0] >> 22)
27809 return sp[0];
27810 if (sp[1] >> 22)
27811 return sp[1];
27812 #endif
27813+
27814+#endif
27815 }
27816 return pc;
27817 }
27818diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
27819index 4e942f3..d0f623f 100644
27820--- a/arch/x86/kernel/tls.c
27821+++ b/arch/x86/kernel/tls.c
27822@@ -118,6 +118,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
27823 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
27824 return -EINVAL;
27825
27826+#ifdef CONFIG_PAX_SEGMEXEC
27827+ if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
27828+ return -EINVAL;
27829+#endif
27830+
27831 set_tls_desc(p, idx, &info, 1);
27832
27833 return 0;
27834@@ -235,7 +240,7 @@ int regset_tls_set(struct task_struct *target, const struct user_regset *regset,
27835
27836 if (kbuf)
27837 info = kbuf;
27838- else if (__copy_from_user(infobuf, ubuf, count))
27839+ else if (count > sizeof infobuf || __copy_from_user(infobuf, ubuf, count))
27840 return -EFAULT;
27841 else
27842 info = infobuf;
27843diff --git a/arch/x86/kernel/tracepoint.c b/arch/x86/kernel/tracepoint.c
27844index 1c113db..287b42e 100644
27845--- a/arch/x86/kernel/tracepoint.c
27846+++ b/arch/x86/kernel/tracepoint.c
27847@@ -9,11 +9,11 @@
27848 #include <linux/atomic.h>
27849
27850 atomic_t trace_idt_ctr = ATOMIC_INIT(0);
27851-struct desc_ptr trace_idt_descr = { NR_VECTORS * 16 - 1,
27852+const struct desc_ptr trace_idt_descr = { NR_VECTORS * 16 - 1,
27853 (unsigned long) trace_idt_table };
27854
27855 /* No need to be aligned, but done to keep all IDTs defined the same way. */
27856-gate_desc trace_idt_table[NR_VECTORS] __page_aligned_bss;
27857+gate_desc trace_idt_table[NR_VECTORS] __page_aligned_rodata;
27858
27859 static int trace_irq_vector_refcount;
27860 static DEFINE_MUTEX(irq_vector_mutex);
27861diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
27862index 07ab8e9..99c8456 100644
27863--- a/arch/x86/kernel/traps.c
27864+++ b/arch/x86/kernel/traps.c
27865@@ -67,7 +67,7 @@
27866 #include <asm/proto.h>
27867
27868 /* No need to be aligned, but done to keep all IDTs defined the same way. */
27869-gate_desc debug_idt_table[NR_VECTORS] __page_aligned_bss;
27870+gate_desc debug_idt_table[NR_VECTORS] __page_aligned_rodata;
27871 #else
27872 #include <asm/processor-flags.h>
27873 #include <asm/setup.h>
27874@@ -76,7 +76,7 @@ asmlinkage int system_call(void);
27875 #endif
27876
27877 /* Must be page-aligned because the real IDT is used in a fixmap. */
27878-gate_desc idt_table[NR_VECTORS] __page_aligned_bss;
27879+gate_desc idt_table[NR_VECTORS] __page_aligned_rodata;
27880
27881 DECLARE_BITMAP(used_vectors, NR_VECTORS);
27882 EXPORT_SYMBOL_GPL(used_vectors);
27883@@ -108,11 +108,11 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
27884 }
27885
27886 static nokprobe_inline int
27887-do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
27888+do_trap_no_signal(struct task_struct *tsk, int trapnr, const char *str,
27889 struct pt_regs *regs, long error_code)
27890 {
27891 #ifdef CONFIG_X86_32
27892- if (regs->flags & X86_VM_MASK) {
27893+ if (v8086_mode(regs)) {
27894 /*
27895 * Traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
27896 * On nmi (interrupt 2), do_trap should not be called.
27897@@ -125,12 +125,24 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
27898 return -1;
27899 }
27900 #endif
27901- if (!user_mode(regs)) {
27902+ if (!user_mode_novm(regs)) {
27903 if (!fixup_exception(regs)) {
27904 tsk->thread.error_code = error_code;
27905 tsk->thread.trap_nr = trapnr;
27906+
27907+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
27908+ if (trapnr == X86_TRAP_SS && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
27909+ str = "PAX: suspicious stack segment fault";
27910+#endif
27911+
27912 die(str, regs, error_code);
27913 }
27914+
27915+#ifdef CONFIG_PAX_REFCOUNT
27916+ if (trapnr == X86_TRAP_OF)
27917+ pax_report_refcount_overflow(regs);
27918+#endif
27919+
27920 return 0;
27921 }
27922
27923@@ -169,7 +181,7 @@ static siginfo_t *fill_trap_info(struct pt_regs *regs, int signr, int trapnr,
27924 }
27925
27926 static void
27927-do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
27928+do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
27929 long error_code, siginfo_t *info)
27930 {
27931 struct task_struct *tsk = current;
27932@@ -193,7 +205,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
27933 if (show_unhandled_signals && unhandled_signal(tsk, signr) &&
27934 printk_ratelimit()) {
27935 pr_info("%s[%d] trap %s ip:%lx sp:%lx error:%lx",
27936- tsk->comm, tsk->pid, str,
27937+ tsk->comm, task_pid_nr(tsk), str,
27938 regs->ip, regs->sp, error_code);
27939 print_vma_addr(" in ", regs->ip);
27940 pr_cont("\n");
27941@@ -274,6 +286,11 @@ dotraplinkage void do_double_fault(struct pt_regs *regs, long error_code)
27942 tsk->thread.error_code = error_code;
27943 tsk->thread.trap_nr = X86_TRAP_DF;
27944
27945+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
27946+ if ((unsigned long)tsk->stack - regs->sp <= PAGE_SIZE)
27947+ die("grsec: kernel stack overflow detected", regs, error_code);
27948+#endif
27949+
27950 #ifdef CONFIG_DOUBLEFAULT
27951 df_debug(regs, error_code);
27952 #endif
27953@@ -296,7 +313,7 @@ do_general_protection(struct pt_regs *regs, long error_code)
27954 conditional_sti(regs);
27955
27956 #ifdef CONFIG_X86_32
27957- if (regs->flags & X86_VM_MASK) {
27958+ if (v8086_mode(regs)) {
27959 local_irq_enable();
27960 handle_vm86_fault((struct kernel_vm86_regs *) regs, error_code);
27961 goto exit;
27962@@ -304,18 +321,42 @@ do_general_protection(struct pt_regs *regs, long error_code)
27963 #endif
27964
27965 tsk = current;
27966- if (!user_mode(regs)) {
27967+ if (!user_mode_novm(regs)) {
27968 if (fixup_exception(regs))
27969 goto exit;
27970
27971 tsk->thread.error_code = error_code;
27972 tsk->thread.trap_nr = X86_TRAP_GP;
27973 if (notify_die(DIE_GPF, "general protection fault", regs, error_code,
27974- X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP)
27975+ X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP) {
27976+
27977+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
27978+ if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
27979+ die("PAX: suspicious general protection fault", regs, error_code);
27980+ else
27981+#endif
27982+
27983 die("general protection fault", regs, error_code);
27984+ }
27985 goto exit;
27986 }
27987
27988+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
27989+ if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
27990+ struct mm_struct *mm = tsk->mm;
27991+ unsigned long limit;
27992+
27993+ down_write(&mm->mmap_sem);
27994+ limit = mm->context.user_cs_limit;
27995+ if (limit < TASK_SIZE) {
27996+ track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
27997+ up_write(&mm->mmap_sem);
27998+ return;
27999+ }
28000+ up_write(&mm->mmap_sem);
28001+ }
28002+#endif
28003+
28004 tsk->thread.error_code = error_code;
28005 tsk->thread.trap_nr = X86_TRAP_GP;
28006
28007@@ -427,13 +468,16 @@ struct bad_iret_stack *fixup_bad_iret(struct bad_iret_stack *s)
28008 container_of(task_pt_regs(current),
28009 struct bad_iret_stack, regs);
28010
28011+ if ((current->thread.sp0 ^ (unsigned long)s) < THREAD_SIZE)
28012+ new_stack = s;
28013+
28014 /* Copy the IRET target to the new stack. */
28015 memmove(&new_stack->regs.ip, (void *)s->regs.sp, 5*8);
28016
28017 /* Copy the remainder of the stack from the current stack. */
28018 memmove(new_stack, s, offsetof(struct bad_iret_stack, regs.ip));
28019
28020- BUG_ON(!user_mode_vm(&new_stack->regs));
28021+ BUG_ON(!user_mode(&new_stack->regs));
28022 return new_stack;
28023 }
28024 NOKPROBE_SYMBOL(fixup_bad_iret);
28025@@ -519,7 +563,7 @@ dotraplinkage void do_debug(struct pt_regs *regs, long error_code)
28026 /* It's safe to allow irq's after DR6 has been saved */
28027 preempt_conditional_sti(regs);
28028
28029- if (regs->flags & X86_VM_MASK) {
28030+ if (v8086_mode(regs)) {
28031 handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code,
28032 X86_TRAP_DB);
28033 preempt_conditional_cli(regs);
28034@@ -534,7 +578,7 @@ dotraplinkage void do_debug(struct pt_regs *regs, long error_code)
28035 * We already checked v86 mode above, so we can check for kernel mode
28036 * by just checking the CPL of CS.
28037 */
28038- if ((dr6 & DR_STEP) && !user_mode(regs)) {
28039+ if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
28040 tsk->thread.debugreg6 &= ~DR_STEP;
28041 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
28042 regs->flags &= ~X86_EFLAGS_TF;
28043@@ -567,7 +611,7 @@ static void math_error(struct pt_regs *regs, int error_code, int trapnr)
28044 return;
28045 conditional_sti(regs);
28046
28047- if (!user_mode_vm(regs))
28048+ if (!user_mode(regs))
28049 {
28050 if (!fixup_exception(regs)) {
28051 task->thread.error_code = error_code;
28052diff --git a/arch/x86/kernel/tsc.c b/arch/x86/kernel/tsc.c
28053index b7e50bb..f4a93ae 100644
28054--- a/arch/x86/kernel/tsc.c
28055+++ b/arch/x86/kernel/tsc.c
28056@@ -150,7 +150,7 @@ static void cyc2ns_write_end(int cpu, struct cyc2ns_data *data)
28057 */
28058 smp_wmb();
28059
28060- ACCESS_ONCE(c2n->head) = data;
28061+ ACCESS_ONCE_RW(c2n->head) = data;
28062 }
28063
28064 /*
28065diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c
28066index 5d1cbfe..2a21feb 100644
28067--- a/arch/x86/kernel/uprobes.c
28068+++ b/arch/x86/kernel/uprobes.c
28069@@ -845,7 +845,7 @@ int arch_uprobe_exception_notify(struct notifier_block *self, unsigned long val,
28070 int ret = NOTIFY_DONE;
28071
28072 /* We are only interested in userspace traps */
28073- if (regs && !user_mode_vm(regs))
28074+ if (regs && !user_mode(regs))
28075 return NOTIFY_DONE;
28076
28077 switch (val) {
28078@@ -919,7 +919,7 @@ arch_uretprobe_hijack_return_addr(unsigned long trampoline_vaddr, struct pt_regs
28079
28080 if (nleft != rasize) {
28081 pr_err("uprobe: return address clobbered: pid=%d, %%sp=%#lx, "
28082- "%%ip=%#lx\n", current->pid, regs->sp, regs->ip);
28083+ "%%ip=%#lx\n", task_pid_nr(current), regs->sp, regs->ip);
28084
28085 force_sig_info(SIGSEGV, SEND_SIG_FORCED, current);
28086 }
28087diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
28088index b9242ba..50c5edd 100644
28089--- a/arch/x86/kernel/verify_cpu.S
28090+++ b/arch/x86/kernel/verify_cpu.S
28091@@ -20,6 +20,7 @@
28092 * arch/x86/boot/compressed/head_64.S: Boot cpu verification
28093 * arch/x86/kernel/trampoline_64.S: secondary processor verification
28094 * arch/x86/kernel/head_32.S: processor startup
28095+ * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
28096 *
28097 * verify_cpu, returns the status of longmode and SSE in register %eax.
28098 * 0: Success 1: Failure
28099diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
28100index e8edcf5..27f9344 100644
28101--- a/arch/x86/kernel/vm86_32.c
28102+++ b/arch/x86/kernel/vm86_32.c
28103@@ -44,6 +44,7 @@
28104 #include <linux/ptrace.h>
28105 #include <linux/audit.h>
28106 #include <linux/stddef.h>
28107+#include <linux/grsecurity.h>
28108
28109 #include <asm/uaccess.h>
28110 #include <asm/io.h>
28111@@ -150,7 +151,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
28112 do_exit(SIGSEGV);
28113 }
28114
28115- tss = &per_cpu(init_tss, get_cpu());
28116+ tss = init_tss + get_cpu();
28117 current->thread.sp0 = current->thread.saved_sp0;
28118 current->thread.sysenter_cs = __KERNEL_CS;
28119 load_sp0(tss, &current->thread);
28120@@ -214,6 +215,14 @@ SYSCALL_DEFINE1(vm86old, struct vm86_struct __user *, v86)
28121
28122 if (tsk->thread.saved_sp0)
28123 return -EPERM;
28124+
28125+#ifdef CONFIG_GRKERNSEC_VM86
28126+ if (!capable(CAP_SYS_RAWIO)) {
28127+ gr_handle_vm86();
28128+ return -EPERM;
28129+ }
28130+#endif
28131+
28132 tmp = copy_vm86_regs_from_user(&info.regs, &v86->regs,
28133 offsetof(struct kernel_vm86_struct, vm86plus) -
28134 sizeof(info.regs));
28135@@ -238,6 +247,13 @@ SYSCALL_DEFINE2(vm86, unsigned long, cmd, unsigned long, arg)
28136 int tmp;
28137 struct vm86plus_struct __user *v86;
28138
28139+#ifdef CONFIG_GRKERNSEC_VM86
28140+ if (!capable(CAP_SYS_RAWIO)) {
28141+ gr_handle_vm86();
28142+ return -EPERM;
28143+ }
28144+#endif
28145+
28146 tsk = current;
28147 switch (cmd) {
28148 case VM86_REQUEST_IRQ:
28149@@ -318,7 +334,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
28150 tsk->thread.saved_fs = info->regs32->fs;
28151 tsk->thread.saved_gs = get_user_gs(info->regs32);
28152
28153- tss = &per_cpu(init_tss, get_cpu());
28154+ tss = init_tss + get_cpu();
28155 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
28156 if (cpu_has_sep)
28157 tsk->thread.sysenter_cs = 0;
28158@@ -525,7 +541,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
28159 goto cannot_handle;
28160 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
28161 goto cannot_handle;
28162- intr_ptr = (unsigned long __user *) (i << 2);
28163+ intr_ptr = (__force unsigned long __user *) (i << 2);
28164 if (get_user(segoffs, intr_ptr))
28165 goto cannot_handle;
28166 if ((segoffs >> 16) == BIOSSEG)
28167diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
28168index 49edf2d..c0d1362 100644
28169--- a/arch/x86/kernel/vmlinux.lds.S
28170+++ b/arch/x86/kernel/vmlinux.lds.S
28171@@ -26,6 +26,13 @@
28172 #include <asm/page_types.h>
28173 #include <asm/cache.h>
28174 #include <asm/boot.h>
28175+#include <asm/segment.h>
28176+
28177+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
28178+#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
28179+#else
28180+#define __KERNEL_TEXT_OFFSET 0
28181+#endif
28182
28183 #undef i386 /* in case the preprocessor is a 32bit one */
28184
28185@@ -69,30 +76,43 @@ jiffies_64 = jiffies;
28186
28187 PHDRS {
28188 text PT_LOAD FLAGS(5); /* R_E */
28189+#ifdef CONFIG_X86_32
28190+ module PT_LOAD FLAGS(5); /* R_E */
28191+#endif
28192+#ifdef CONFIG_XEN
28193+ rodata PT_LOAD FLAGS(5); /* R_E */
28194+#else
28195+ rodata PT_LOAD FLAGS(4); /* R__ */
28196+#endif
28197 data PT_LOAD FLAGS(6); /* RW_ */
28198-#ifdef CONFIG_X86_64
28199+ init.begin PT_LOAD FLAGS(6); /* RW_ */
28200 #ifdef CONFIG_SMP
28201 percpu PT_LOAD FLAGS(6); /* RW_ */
28202 #endif
28203+ text.init PT_LOAD FLAGS(5); /* R_E */
28204+ text.exit PT_LOAD FLAGS(5); /* R_E */
28205 init PT_LOAD FLAGS(7); /* RWE */
28206-#endif
28207 note PT_NOTE FLAGS(0); /* ___ */
28208 }
28209
28210 SECTIONS
28211 {
28212 #ifdef CONFIG_X86_32
28213- . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
28214- phys_startup_32 = startup_32 - LOAD_OFFSET;
28215+ . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
28216 #else
28217- . = __START_KERNEL;
28218- phys_startup_64 = startup_64 - LOAD_OFFSET;
28219+ . = __START_KERNEL;
28220 #endif
28221
28222 /* Text and read-only data */
28223- .text : AT(ADDR(.text) - LOAD_OFFSET) {
28224- _text = .;
28225+ .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
28226 /* bootstrapping code */
28227+#ifdef CONFIG_X86_32
28228+ phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
28229+#else
28230+ phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
28231+#endif
28232+ __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
28233+ _text = .;
28234 HEAD_TEXT
28235 . = ALIGN(8);
28236 _stext = .;
28237@@ -104,13 +124,47 @@ SECTIONS
28238 IRQENTRY_TEXT
28239 *(.fixup)
28240 *(.gnu.warning)
28241- /* End of text section */
28242- _etext = .;
28243 } :text = 0x9090
28244
28245- NOTES :text :note
28246+ . += __KERNEL_TEXT_OFFSET;
28247
28248- EXCEPTION_TABLE(16) :text = 0x9090
28249+#ifdef CONFIG_X86_32
28250+ . = ALIGN(PAGE_SIZE);
28251+ .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
28252+
28253+#ifdef CONFIG_PAX_KERNEXEC
28254+ MODULES_EXEC_VADDR = .;
28255+ BYTE(0)
28256+ . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
28257+ . = ALIGN(HPAGE_SIZE) - 1;
28258+ MODULES_EXEC_END = .;
28259+#endif
28260+
28261+ } :module
28262+#endif
28263+
28264+ .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
28265+ /* End of text section */
28266+ BYTE(0)
28267+ _etext = . - __KERNEL_TEXT_OFFSET;
28268+ }
28269+
28270+#ifdef CONFIG_X86_32
28271+ . = ALIGN(PAGE_SIZE);
28272+ .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
28273+ . = ALIGN(PAGE_SIZE);
28274+ *(.empty_zero_page)
28275+ *(.initial_pg_fixmap)
28276+ *(.initial_pg_pmd)
28277+ *(.initial_page_table)
28278+ *(.swapper_pg_dir)
28279+ } :rodata
28280+#endif
28281+
28282+ . = ALIGN(PAGE_SIZE);
28283+ NOTES :rodata :note
28284+
28285+ EXCEPTION_TABLE(16) :rodata
28286
28287 #if defined(CONFIG_DEBUG_RODATA)
28288 /* .text should occupy whole number of pages */
28289@@ -122,16 +176,20 @@ SECTIONS
28290
28291 /* Data */
28292 .data : AT(ADDR(.data) - LOAD_OFFSET) {
28293+
28294+#ifdef CONFIG_PAX_KERNEXEC
28295+ . = ALIGN(HPAGE_SIZE);
28296+#else
28297+ . = ALIGN(PAGE_SIZE);
28298+#endif
28299+
28300 /* Start of data section */
28301 _sdata = .;
28302
28303 /* init_task */
28304 INIT_TASK_DATA(THREAD_SIZE)
28305
28306-#ifdef CONFIG_X86_32
28307- /* 32 bit has nosave before _edata */
28308 NOSAVE_DATA
28309-#endif
28310
28311 PAGE_ALIGNED_DATA(PAGE_SIZE)
28312
28313@@ -174,12 +232,19 @@ SECTIONS
28314 . = ALIGN(__vvar_page + PAGE_SIZE, PAGE_SIZE);
28315
28316 /* Init code and data - will be freed after init */
28317- . = ALIGN(PAGE_SIZE);
28318 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
28319+ BYTE(0)
28320+
28321+#ifdef CONFIG_PAX_KERNEXEC
28322+ . = ALIGN(HPAGE_SIZE);
28323+#else
28324+ . = ALIGN(PAGE_SIZE);
28325+#endif
28326+
28327 __init_begin = .; /* paired with __init_end */
28328- }
28329+ } :init.begin
28330
28331-#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
28332+#ifdef CONFIG_SMP
28333 /*
28334 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
28335 * output PHDR, so the next output section - .init.text - should
28336@@ -188,12 +253,27 @@ SECTIONS
28337 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
28338 #endif
28339
28340- INIT_TEXT_SECTION(PAGE_SIZE)
28341-#ifdef CONFIG_X86_64
28342- :init
28343-#endif
28344+ . = ALIGN(PAGE_SIZE);
28345+ init_begin = .;
28346+ .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
28347+ VMLINUX_SYMBOL(_sinittext) = .;
28348+ INIT_TEXT
28349+ VMLINUX_SYMBOL(_einittext) = .;
28350+ . = ALIGN(PAGE_SIZE);
28351+ } :text.init
28352
28353- INIT_DATA_SECTION(16)
28354+ /*
28355+ * .exit.text is discard at runtime, not link time, to deal with
28356+ * references from .altinstructions and .eh_frame
28357+ */
28358+ .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
28359+ EXIT_TEXT
28360+ . = ALIGN(16);
28361+ } :text.exit
28362+ . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
28363+
28364+ . = ALIGN(PAGE_SIZE);
28365+ INIT_DATA_SECTION(16) :init
28366
28367 .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
28368 __x86_cpu_dev_start = .;
28369@@ -264,19 +344,12 @@ SECTIONS
28370 }
28371
28372 . = ALIGN(8);
28373- /*
28374- * .exit.text is discard at runtime, not link time, to deal with
28375- * references from .altinstructions and .eh_frame
28376- */
28377- .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
28378- EXIT_TEXT
28379- }
28380
28381 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
28382 EXIT_DATA
28383 }
28384
28385-#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
28386+#ifndef CONFIG_SMP
28387 PERCPU_SECTION(INTERNODE_CACHE_BYTES)
28388 #endif
28389
28390@@ -295,16 +368,10 @@ SECTIONS
28391 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
28392 __smp_locks = .;
28393 *(.smp_locks)
28394- . = ALIGN(PAGE_SIZE);
28395 __smp_locks_end = .;
28396+ . = ALIGN(PAGE_SIZE);
28397 }
28398
28399-#ifdef CONFIG_X86_64
28400- .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
28401- NOSAVE_DATA
28402- }
28403-#endif
28404-
28405 /* BSS */
28406 . = ALIGN(PAGE_SIZE);
28407 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
28408@@ -320,6 +387,7 @@ SECTIONS
28409 __brk_base = .;
28410 . += 64 * 1024; /* 64k alignment slop space */
28411 *(.brk_reservation) /* areas brk users have reserved */
28412+ . = ALIGN(HPAGE_SIZE);
28413 __brk_limit = .;
28414 }
28415
28416@@ -346,13 +414,12 @@ SECTIONS
28417 * for the boot processor.
28418 */
28419 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
28420-INIT_PER_CPU(gdt_page);
28421 INIT_PER_CPU(irq_stack_union);
28422
28423 /*
28424 * Build-time check on the image size:
28425 */
28426-. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
28427+. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
28428 "kernel image bigger than KERNEL_IMAGE_SIZE");
28429
28430 #ifdef CONFIG_SMP
28431diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
28432index 957779f..74e405c 100644
28433--- a/arch/x86/kernel/vsyscall_64.c
28434+++ b/arch/x86/kernel/vsyscall_64.c
28435@@ -54,15 +54,13 @@
28436
28437 DEFINE_VVAR(int, vgetcpu_mode);
28438
28439-static enum { EMULATE, NATIVE, NONE } vsyscall_mode = EMULATE;
28440+static enum { EMULATE, NONE } vsyscall_mode = EMULATE;
28441
28442 static int __init vsyscall_setup(char *str)
28443 {
28444 if (str) {
28445 if (!strcmp("emulate", str))
28446 vsyscall_mode = EMULATE;
28447- else if (!strcmp("native", str))
28448- vsyscall_mode = NATIVE;
28449 else if (!strcmp("none", str))
28450 vsyscall_mode = NONE;
28451 else
28452@@ -279,8 +277,7 @@ do_ret:
28453 return true;
28454
28455 sigsegv:
28456- force_sig(SIGSEGV, current);
28457- return true;
28458+ do_group_exit(SIGKILL);
28459 }
28460
28461 /*
28462@@ -331,10 +328,7 @@ void __init map_vsyscall(void)
28463 extern char __vsyscall_page;
28464 unsigned long physaddr_vsyscall = __pa_symbol(&__vsyscall_page);
28465
28466- __set_fixmap(VSYSCALL_PAGE, physaddr_vsyscall,
28467- vsyscall_mode == NATIVE
28468- ? PAGE_KERNEL_VSYSCALL
28469- : PAGE_KERNEL_VVAR);
28470+ __set_fixmap(VSYSCALL_PAGE, physaddr_vsyscall, PAGE_KERNEL_VVAR);
28471 BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_PAGE) !=
28472 (unsigned long)VSYSCALL_ADDR);
28473 }
28474diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
28475index 04068192..4d75aa6 100644
28476--- a/arch/x86/kernel/x8664_ksyms_64.c
28477+++ b/arch/x86/kernel/x8664_ksyms_64.c
28478@@ -34,8 +34,6 @@ EXPORT_SYMBOL(copy_user_generic_string);
28479 EXPORT_SYMBOL(copy_user_generic_unrolled);
28480 EXPORT_SYMBOL(copy_user_enhanced_fast_string);
28481 EXPORT_SYMBOL(__copy_user_nocache);
28482-EXPORT_SYMBOL(_copy_from_user);
28483-EXPORT_SYMBOL(_copy_to_user);
28484
28485 EXPORT_SYMBOL(copy_page);
28486 EXPORT_SYMBOL(clear_page);
28487@@ -73,3 +71,7 @@ EXPORT_SYMBOL(___preempt_schedule);
28488 EXPORT_SYMBOL(___preempt_schedule_context);
28489 #endif
28490 #endif
28491+
28492+#ifdef CONFIG_PAX_PER_CPU_PGD
28493+EXPORT_SYMBOL(cpu_pgd);
28494+#endif
28495diff --git a/arch/x86/kernel/x86_init.c b/arch/x86/kernel/x86_init.c
28496index e48b674..a451dd9 100644
28497--- a/arch/x86/kernel/x86_init.c
28498+++ b/arch/x86/kernel/x86_init.c
28499@@ -93,7 +93,7 @@ struct x86_cpuinit_ops x86_cpuinit = {
28500 static void default_nmi_init(void) { };
28501 static int default_i8042_detect(void) { return 1; };
28502
28503-struct x86_platform_ops x86_platform = {
28504+struct x86_platform_ops x86_platform __read_only = {
28505 .calibrate_tsc = native_calibrate_tsc,
28506 .get_wallclock = mach_get_cmos_time,
28507 .set_wallclock = mach_set_rtc_mmss,
28508@@ -109,7 +109,7 @@ struct x86_platform_ops x86_platform = {
28509 EXPORT_SYMBOL_GPL(x86_platform);
28510
28511 #if defined(CONFIG_PCI_MSI)
28512-struct x86_msi_ops x86_msi = {
28513+struct x86_msi_ops x86_msi __read_only = {
28514 .setup_msi_irqs = native_setup_msi_irqs,
28515 .compose_msi_msg = native_compose_msi_msg,
28516 .teardown_msi_irq = native_teardown_msi_irq,
28517@@ -150,7 +150,7 @@ u32 arch_msix_mask_irq(struct msi_desc *desc, u32 flag)
28518 }
28519 #endif
28520
28521-struct x86_io_apic_ops x86_io_apic_ops = {
28522+struct x86_io_apic_ops x86_io_apic_ops __read_only = {
28523 .init = native_io_apic_init_mappings,
28524 .read = native_io_apic_read,
28525 .write = native_io_apic_write,
28526diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
28527index 0de1fae..298d037 100644
28528--- a/arch/x86/kernel/xsave.c
28529+++ b/arch/x86/kernel/xsave.c
28530@@ -167,18 +167,18 @@ static inline int save_xstate_epilog(void __user *buf, int ia32_frame)
28531
28532 /* Setup the bytes not touched by the [f]xsave and reserved for SW. */
28533 sw_bytes = ia32_frame ? &fx_sw_reserved_ia32 : &fx_sw_reserved;
28534- err = __copy_to_user(&x->i387.sw_reserved, sw_bytes, sizeof(*sw_bytes));
28535+ err = __copy_to_user(x->i387.sw_reserved, sw_bytes, sizeof(*sw_bytes));
28536
28537 if (!use_xsave())
28538 return err;
28539
28540- err |= __put_user(FP_XSTATE_MAGIC2, (__u32 *)(buf + xstate_size));
28541+ err |= __put_user(FP_XSTATE_MAGIC2, (__u32 __user *)(buf + xstate_size));
28542
28543 /*
28544 * Read the xstate_bv which we copied (directly from the cpu or
28545 * from the state in task struct) to the user buffers.
28546 */
28547- err |= __get_user(xstate_bv, (__u32 *)&x->xsave_hdr.xstate_bv);
28548+ err |= __get_user(xstate_bv, (__u32 __user *)&x->xsave_hdr.xstate_bv);
28549
28550 /*
28551 * For legacy compatible, we always set FP/SSE bits in the bit
28552@@ -193,7 +193,7 @@ static inline int save_xstate_epilog(void __user *buf, int ia32_frame)
28553 */
28554 xstate_bv |= XSTATE_FPSSE;
28555
28556- err |= __put_user(xstate_bv, (__u32 *)&x->xsave_hdr.xstate_bv);
28557+ err |= __put_user(xstate_bv, (__u32 __user *)&x->xsave_hdr.xstate_bv);
28558
28559 return err;
28560 }
28561@@ -202,6 +202,7 @@ static inline int save_user_xstate(struct xsave_struct __user *buf)
28562 {
28563 int err;
28564
28565+ buf = (struct xsave_struct __user *)____m(buf);
28566 if (use_xsave())
28567 err = xsave_user(buf);
28568 else if (use_fxsr())
28569@@ -312,6 +313,7 @@ sanitize_restored_xstate(struct task_struct *tsk,
28570 */
28571 static inline int restore_user_xstate(void __user *buf, u64 xbv, int fx_only)
28572 {
28573+ buf = (void __user *)____m(buf);
28574 if (use_xsave()) {
28575 if ((unsigned long)buf % 64 || fx_only) {
28576 u64 init_bv = pcntxt_mask & ~XSTATE_FPSSE;
28577diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
28578index 88f9201..0e7f1a3 100644
28579--- a/arch/x86/kvm/cpuid.c
28580+++ b/arch/x86/kvm/cpuid.c
28581@@ -175,15 +175,20 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
28582 struct kvm_cpuid2 *cpuid,
28583 struct kvm_cpuid_entry2 __user *entries)
28584 {
28585- int r;
28586+ int r, i;
28587
28588 r = -E2BIG;
28589 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
28590 goto out;
28591 r = -EFAULT;
28592- if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
28593- cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
28594+ if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
28595 goto out;
28596+ for (i = 0; i < cpuid->nent; ++i) {
28597+ struct kvm_cpuid_entry2 cpuid_entry;
28598+ if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
28599+ goto out;
28600+ vcpu->arch.cpuid_entries[i] = cpuid_entry;
28601+ }
28602 vcpu->arch.cpuid_nent = cpuid->nent;
28603 kvm_apic_set_version(vcpu);
28604 kvm_x86_ops->cpuid_update(vcpu);
28605@@ -196,15 +201,19 @@ int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
28606 struct kvm_cpuid2 *cpuid,
28607 struct kvm_cpuid_entry2 __user *entries)
28608 {
28609- int r;
28610+ int r, i;
28611
28612 r = -E2BIG;
28613 if (cpuid->nent < vcpu->arch.cpuid_nent)
28614 goto out;
28615 r = -EFAULT;
28616- if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
28617- vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
28618+ if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
28619 goto out;
28620+ for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
28621+ struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
28622+ if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
28623+ goto out;
28624+ }
28625 return 0;
28626
28627 out:
28628diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
28629index 22e7ed9..e03a378 100644
28630--- a/arch/x86/kvm/emulate.c
28631+++ b/arch/x86/kvm/emulate.c
28632@@ -3519,7 +3519,7 @@ static int check_cr_write(struct x86_emulate_ctxt *ctxt)
28633 int cr = ctxt->modrm_reg;
28634 u64 efer = 0;
28635
28636- static u64 cr_reserved_bits[] = {
28637+ static const u64 cr_reserved_bits[] = {
28638 0xffffffff00000000ULL,
28639 0, 0, 0, /* CR3 checked later */
28640 CR4_RESERVED_BITS,
28641@@ -3554,7 +3554,7 @@ static int check_cr_write(struct x86_emulate_ctxt *ctxt)
28642
28643 ctxt->ops->get_msr(ctxt, MSR_EFER, &efer);
28644 if (efer & EFER_LMA)
28645- rsvd = CR3_L_MODE_RESERVED_BITS;
28646+ rsvd = CR3_L_MODE_RESERVED_BITS & ~CR3_PCID_INVD;
28647
28648 if (new_val & rsvd)
28649 return emulate_gp(ctxt, 0);
28650diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
28651index b8345dd..f225d71 100644
28652--- a/arch/x86/kvm/lapic.c
28653+++ b/arch/x86/kvm/lapic.c
28654@@ -55,7 +55,7 @@
28655 #define APIC_BUS_CYCLE_NS 1
28656
28657 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
28658-#define apic_debug(fmt, arg...)
28659+#define apic_debug(fmt, arg...) do {} while (0)
28660
28661 #define APIC_LVT_NUM 6
28662 /* 14 is the version for Xeon and Pentium 8.4.8*/
28663diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
28664index fd49c86..77e1aa0 100644
28665--- a/arch/x86/kvm/paging_tmpl.h
28666+++ b/arch/x86/kvm/paging_tmpl.h
28667@@ -343,7 +343,7 @@ retry_walk:
28668 if (unlikely(kvm_is_error_hva(host_addr)))
28669 goto error;
28670
28671- ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
28672+ ptep_user = (pt_element_t __force_user *)((void *)host_addr + offset);
28673 if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte))))
28674 goto error;
28675 walker->ptep_user[walker->level - 1] = ptep_user;
28676diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
28677index 7527cef..c63a838e 100644
28678--- a/arch/x86/kvm/svm.c
28679+++ b/arch/x86/kvm/svm.c
28680@@ -3564,7 +3564,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
28681 int cpu = raw_smp_processor_id();
28682
28683 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
28684+
28685+ pax_open_kernel();
28686 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
28687+ pax_close_kernel();
28688+
28689 load_TR_desc();
28690 }
28691
28692@@ -3965,6 +3969,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
28693 #endif
28694 #endif
28695
28696+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
28697+ __set_fs(current_thread_info()->addr_limit);
28698+#endif
28699+
28700 reload_tss(vcpu);
28701
28702 local_irq_disable();
28703diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
28704index 3e556c6..08bbf7f 100644
28705--- a/arch/x86/kvm/vmx.c
28706+++ b/arch/x86/kvm/vmx.c
28707@@ -1366,12 +1366,12 @@ static void vmcs_write64(unsigned long field, u64 value)
28708 #endif
28709 }
28710
28711-static void vmcs_clear_bits(unsigned long field, u32 mask)
28712+static void vmcs_clear_bits(unsigned long field, unsigned long mask)
28713 {
28714 vmcs_writel(field, vmcs_readl(field) & ~mask);
28715 }
28716
28717-static void vmcs_set_bits(unsigned long field, u32 mask)
28718+static void vmcs_set_bits(unsigned long field, unsigned long mask)
28719 {
28720 vmcs_writel(field, vmcs_readl(field) | mask);
28721 }
28722@@ -1631,7 +1631,11 @@ static void reload_tss(void)
28723 struct desc_struct *descs;
28724
28725 descs = (void *)gdt->address;
28726+
28727+ pax_open_kernel();
28728 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
28729+ pax_close_kernel();
28730+
28731 load_TR_desc();
28732 }
28733
28734@@ -1859,6 +1863,10 @@ static void vmx_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
28735 vmcs_writel(HOST_TR_BASE, kvm_read_tr_base()); /* 22.2.4 */
28736 vmcs_writel(HOST_GDTR_BASE, gdt->address); /* 22.2.4 */
28737
28738+#ifdef CONFIG_PAX_PER_CPU_PGD
28739+ vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
28740+#endif
28741+
28742 rdmsrl(MSR_IA32_SYSENTER_ESP, sysenter_esp);
28743 vmcs_writel(HOST_IA32_SYSENTER_ESP, sysenter_esp); /* 22.2.3 */
28744 vmx->loaded_vmcs->cpu = cpu;
28745@@ -2148,7 +2156,7 @@ static void setup_msrs(struct vcpu_vmx *vmx)
28746 * reads and returns guest's timestamp counter "register"
28747 * guest_tsc = host_tsc + tsc_offset -- 21.3
28748 */
28749-static u64 guest_read_tsc(void)
28750+static u64 __intentional_overflow(-1) guest_read_tsc(void)
28751 {
28752 u64 host_tsc, tsc_offset;
28753
28754@@ -3146,11 +3154,16 @@ static __init int hardware_setup(void)
28755 * page upon invalidation. No need to do anything if the
28756 * processor does not have the APIC_ACCESS_ADDR VMCS field.
28757 */
28758- kvm_x86_ops->set_apic_access_page_addr = NULL;
28759+ pax_open_kernel();
28760+ *(void **)&kvm_x86_ops->set_apic_access_page_addr = NULL;
28761+ pax_close_kernel();
28762 }
28763
28764- if (!cpu_has_vmx_tpr_shadow())
28765- kvm_x86_ops->update_cr8_intercept = NULL;
28766+ if (!cpu_has_vmx_tpr_shadow()) {
28767+ pax_open_kernel();
28768+ *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
28769+ pax_close_kernel();
28770+ }
28771
28772 if (enable_ept && !cpu_has_vmx_ept_2m_page())
28773 kvm_disable_largepages();
28774@@ -3161,13 +3174,15 @@ static __init int hardware_setup(void)
28775 if (!cpu_has_vmx_apicv())
28776 enable_apicv = 0;
28777
28778+ pax_open_kernel();
28779 if (enable_apicv)
28780- kvm_x86_ops->update_cr8_intercept = NULL;
28781+ *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
28782 else {
28783- kvm_x86_ops->hwapic_irr_update = NULL;
28784- kvm_x86_ops->deliver_posted_interrupt = NULL;
28785- kvm_x86_ops->sync_pir_to_irr = vmx_sync_pir_to_irr_dummy;
28786+ *(void **)&kvm_x86_ops->hwapic_irr_update = NULL;
28787+ *(void **)&kvm_x86_ops->deliver_posted_interrupt = NULL;
28788+ *(void **)&kvm_x86_ops->sync_pir_to_irr = vmx_sync_pir_to_irr_dummy;
28789 }
28790+ pax_close_kernel();
28791
28792 if (nested)
28793 nested_vmx_setup_ctls_msrs();
28794@@ -4274,7 +4289,10 @@ static void vmx_set_constant_host_state(struct vcpu_vmx *vmx)
28795 unsigned long cr4;
28796
28797 vmcs_writel(HOST_CR0, read_cr0() & ~X86_CR0_TS); /* 22.2.3 */
28798+
28799+#ifndef CONFIG_PAX_PER_CPU_PGD
28800 vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
28801+#endif
28802
28803 /* Save the most likely value for this task's CR4 in the VMCS. */
28804 cr4 = read_cr4();
28805@@ -4301,7 +4319,7 @@ static void vmx_set_constant_host_state(struct vcpu_vmx *vmx)
28806 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
28807 vmx->host_idt_base = dt.address;
28808
28809- vmcs_writel(HOST_RIP, vmx_return); /* 22.2.5 */
28810+ vmcs_writel(HOST_RIP, ktla_ktva(vmx_return)); /* 22.2.5 */
28811
28812 rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
28813 vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
28814@@ -7622,6 +7640,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
28815 "jmp 2f \n\t"
28816 "1: " __ex(ASM_VMX_VMRESUME) "\n\t"
28817 "2: "
28818+
28819+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
28820+ "ljmp %[cs],$3f\n\t"
28821+ "3: "
28822+#endif
28823+
28824 /* Save guest registers, load host registers, keep flags */
28825 "mov %0, %c[wordsize](%%" _ASM_SP ") \n\t"
28826 "pop %0 \n\t"
28827@@ -7674,6 +7698,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
28828 #endif
28829 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
28830 [wordsize]"i"(sizeof(ulong))
28831+
28832+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
28833+ ,[cs]"i"(__KERNEL_CS)
28834+#endif
28835+
28836 : "cc", "memory"
28837 #ifdef CONFIG_X86_64
28838 , "rax", "rbx", "rdi", "rsi"
28839@@ -7687,7 +7716,7 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
28840 if (debugctlmsr)
28841 update_debugctlmsr(debugctlmsr);
28842
28843-#ifndef CONFIG_X86_64
28844+#ifdef CONFIG_X86_32
28845 /*
28846 * The sysexit path does not restore ds/es, so we must set them to
28847 * a reasonable value ourselves.
28848@@ -7696,8 +7725,18 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
28849 * may be executed in interrupt context, which saves and restore segments
28850 * around it, nullifying its effect.
28851 */
28852- loadsegment(ds, __USER_DS);
28853- loadsegment(es, __USER_DS);
28854+ loadsegment(ds, __KERNEL_DS);
28855+ loadsegment(es, __KERNEL_DS);
28856+ loadsegment(ss, __KERNEL_DS);
28857+
28858+#ifdef CONFIG_PAX_KERNEXEC
28859+ loadsegment(fs, __KERNEL_PERCPU);
28860+#endif
28861+
28862+#ifdef CONFIG_PAX_MEMORY_UDEREF
28863+ __set_fs(current_thread_info()->addr_limit);
28864+#endif
28865+
28866 #endif
28867
28868 vcpu->arch.regs_avail = ~((1 << VCPU_REGS_RIP) | (1 << VCPU_REGS_RSP)
28869diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
28870index 506488c..f8df17e 100644
28871--- a/arch/x86/kvm/x86.c
28872+++ b/arch/x86/kvm/x86.c
28873@@ -732,6 +732,8 @@ EXPORT_SYMBOL_GPL(kvm_set_cr4);
28874
28875 int kvm_set_cr3(struct kvm_vcpu *vcpu, unsigned long cr3)
28876 {
28877+ cr3 &= ~CR3_PCID_INVD;
28878+
28879 if (cr3 == kvm_read_cr3(vcpu) && !pdptrs_changed(vcpu)) {
28880 kvm_mmu_sync_roots(vcpu);
28881 kvm_make_request(KVM_REQ_TLB_FLUSH, vcpu);
28882@@ -1878,8 +1880,8 @@ static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
28883 {
28884 struct kvm *kvm = vcpu->kvm;
28885 int lm = is_long_mode(vcpu);
28886- u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64
28887- : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
28888+ u8 __user *blob_addr = lm ? (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_64
28889+ : (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
28890 u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
28891 : kvm->arch.xen_hvm_config.blob_size_32;
28892 u32 page_num = data & ~PAGE_MASK;
28893@@ -2806,6 +2808,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
28894 if (n < msr_list.nmsrs)
28895 goto out;
28896 r = -EFAULT;
28897+ if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
28898+ goto out;
28899 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
28900 num_msrs_to_save * sizeof(u32)))
28901 goto out;
28902@@ -5743,7 +5747,7 @@ static struct notifier_block pvclock_gtod_notifier = {
28903 };
28904 #endif
28905
28906-int kvm_arch_init(void *opaque)
28907+int kvm_arch_init(const void *opaque)
28908 {
28909 int r;
28910 struct kvm_x86_ops *ops = opaque;
28911diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
28912index aae9413..d11e829 100644
28913--- a/arch/x86/lguest/boot.c
28914+++ b/arch/x86/lguest/boot.c
28915@@ -1206,9 +1206,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
28916 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
28917 * Launcher to reboot us.
28918 */
28919-static void lguest_restart(char *reason)
28920+static __noreturn void lguest_restart(char *reason)
28921 {
28922 hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
28923+ BUG();
28924 }
28925
28926 /*G:050
28927diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
28928index 00933d5..3a64af9 100644
28929--- a/arch/x86/lib/atomic64_386_32.S
28930+++ b/arch/x86/lib/atomic64_386_32.S
28931@@ -48,6 +48,10 @@ BEGIN(read)
28932 movl (v), %eax
28933 movl 4(v), %edx
28934 RET_ENDP
28935+BEGIN(read_unchecked)
28936+ movl (v), %eax
28937+ movl 4(v), %edx
28938+RET_ENDP
28939 #undef v
28940
28941 #define v %esi
28942@@ -55,6 +59,10 @@ BEGIN(set)
28943 movl %ebx, (v)
28944 movl %ecx, 4(v)
28945 RET_ENDP
28946+BEGIN(set_unchecked)
28947+ movl %ebx, (v)
28948+ movl %ecx, 4(v)
28949+RET_ENDP
28950 #undef v
28951
28952 #define v %esi
28953@@ -70,6 +78,20 @@ RET_ENDP
28954 BEGIN(add)
28955 addl %eax, (v)
28956 adcl %edx, 4(v)
28957+
28958+#ifdef CONFIG_PAX_REFCOUNT
28959+ jno 0f
28960+ subl %eax, (v)
28961+ sbbl %edx, 4(v)
28962+ int $4
28963+0:
28964+ _ASM_EXTABLE(0b, 0b)
28965+#endif
28966+
28967+RET_ENDP
28968+BEGIN(add_unchecked)
28969+ addl %eax, (v)
28970+ adcl %edx, 4(v)
28971 RET_ENDP
28972 #undef v
28973
28974@@ -77,6 +99,24 @@ RET_ENDP
28975 BEGIN(add_return)
28976 addl (v), %eax
28977 adcl 4(v), %edx
28978+
28979+#ifdef CONFIG_PAX_REFCOUNT
28980+ into
28981+1234:
28982+ _ASM_EXTABLE(1234b, 2f)
28983+#endif
28984+
28985+ movl %eax, (v)
28986+ movl %edx, 4(v)
28987+
28988+#ifdef CONFIG_PAX_REFCOUNT
28989+2:
28990+#endif
28991+
28992+RET_ENDP
28993+BEGIN(add_return_unchecked)
28994+ addl (v), %eax
28995+ adcl 4(v), %edx
28996 movl %eax, (v)
28997 movl %edx, 4(v)
28998 RET_ENDP
28999@@ -86,6 +126,20 @@ RET_ENDP
29000 BEGIN(sub)
29001 subl %eax, (v)
29002 sbbl %edx, 4(v)
29003+
29004+#ifdef CONFIG_PAX_REFCOUNT
29005+ jno 0f
29006+ addl %eax, (v)
29007+ adcl %edx, 4(v)
29008+ int $4
29009+0:
29010+ _ASM_EXTABLE(0b, 0b)
29011+#endif
29012+
29013+RET_ENDP
29014+BEGIN(sub_unchecked)
29015+ subl %eax, (v)
29016+ sbbl %edx, 4(v)
29017 RET_ENDP
29018 #undef v
29019
29020@@ -96,6 +150,27 @@ BEGIN(sub_return)
29021 sbbl $0, %edx
29022 addl (v), %eax
29023 adcl 4(v), %edx
29024+
29025+#ifdef CONFIG_PAX_REFCOUNT
29026+ into
29027+1234:
29028+ _ASM_EXTABLE(1234b, 2f)
29029+#endif
29030+
29031+ movl %eax, (v)
29032+ movl %edx, 4(v)
29033+
29034+#ifdef CONFIG_PAX_REFCOUNT
29035+2:
29036+#endif
29037+
29038+RET_ENDP
29039+BEGIN(sub_return_unchecked)
29040+ negl %edx
29041+ negl %eax
29042+ sbbl $0, %edx
29043+ addl (v), %eax
29044+ adcl 4(v), %edx
29045 movl %eax, (v)
29046 movl %edx, 4(v)
29047 RET_ENDP
29048@@ -105,6 +180,20 @@ RET_ENDP
29049 BEGIN(inc)
29050 addl $1, (v)
29051 adcl $0, 4(v)
29052+
29053+#ifdef CONFIG_PAX_REFCOUNT
29054+ jno 0f
29055+ subl $1, (v)
29056+ sbbl $0, 4(v)
29057+ int $4
29058+0:
29059+ _ASM_EXTABLE(0b, 0b)
29060+#endif
29061+
29062+RET_ENDP
29063+BEGIN(inc_unchecked)
29064+ addl $1, (v)
29065+ adcl $0, 4(v)
29066 RET_ENDP
29067 #undef v
29068
29069@@ -114,6 +203,26 @@ BEGIN(inc_return)
29070 movl 4(v), %edx
29071 addl $1, %eax
29072 adcl $0, %edx
29073+
29074+#ifdef CONFIG_PAX_REFCOUNT
29075+ into
29076+1234:
29077+ _ASM_EXTABLE(1234b, 2f)
29078+#endif
29079+
29080+ movl %eax, (v)
29081+ movl %edx, 4(v)
29082+
29083+#ifdef CONFIG_PAX_REFCOUNT
29084+2:
29085+#endif
29086+
29087+RET_ENDP
29088+BEGIN(inc_return_unchecked)
29089+ movl (v), %eax
29090+ movl 4(v), %edx
29091+ addl $1, %eax
29092+ adcl $0, %edx
29093 movl %eax, (v)
29094 movl %edx, 4(v)
29095 RET_ENDP
29096@@ -123,6 +232,20 @@ RET_ENDP
29097 BEGIN(dec)
29098 subl $1, (v)
29099 sbbl $0, 4(v)
29100+
29101+#ifdef CONFIG_PAX_REFCOUNT
29102+ jno 0f
29103+ addl $1, (v)
29104+ adcl $0, 4(v)
29105+ int $4
29106+0:
29107+ _ASM_EXTABLE(0b, 0b)
29108+#endif
29109+
29110+RET_ENDP
29111+BEGIN(dec_unchecked)
29112+ subl $1, (v)
29113+ sbbl $0, 4(v)
29114 RET_ENDP
29115 #undef v
29116
29117@@ -132,6 +255,26 @@ BEGIN(dec_return)
29118 movl 4(v), %edx
29119 subl $1, %eax
29120 sbbl $0, %edx
29121+
29122+#ifdef CONFIG_PAX_REFCOUNT
29123+ into
29124+1234:
29125+ _ASM_EXTABLE(1234b, 2f)
29126+#endif
29127+
29128+ movl %eax, (v)
29129+ movl %edx, 4(v)
29130+
29131+#ifdef CONFIG_PAX_REFCOUNT
29132+2:
29133+#endif
29134+
29135+RET_ENDP
29136+BEGIN(dec_return_unchecked)
29137+ movl (v), %eax
29138+ movl 4(v), %edx
29139+ subl $1, %eax
29140+ sbbl $0, %edx
29141 movl %eax, (v)
29142 movl %edx, 4(v)
29143 RET_ENDP
29144@@ -143,6 +286,13 @@ BEGIN(add_unless)
29145 adcl %edx, %edi
29146 addl (v), %eax
29147 adcl 4(v), %edx
29148+
29149+#ifdef CONFIG_PAX_REFCOUNT
29150+ into
29151+1234:
29152+ _ASM_EXTABLE(1234b, 2f)
29153+#endif
29154+
29155 cmpl %eax, %ecx
29156 je 3f
29157 1:
29158@@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
29159 1:
29160 addl $1, %eax
29161 adcl $0, %edx
29162+
29163+#ifdef CONFIG_PAX_REFCOUNT
29164+ into
29165+1234:
29166+ _ASM_EXTABLE(1234b, 2f)
29167+#endif
29168+
29169 movl %eax, (v)
29170 movl %edx, 4(v)
29171 movl $1, %eax
29172@@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
29173 movl 4(v), %edx
29174 subl $1, %eax
29175 sbbl $0, %edx
29176+
29177+#ifdef CONFIG_PAX_REFCOUNT
29178+ into
29179+1234:
29180+ _ASM_EXTABLE(1234b, 1f)
29181+#endif
29182+
29183 js 1f
29184 movl %eax, (v)
29185 movl %edx, 4(v)
29186diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
29187index f5cc9eb..51fa319 100644
29188--- a/arch/x86/lib/atomic64_cx8_32.S
29189+++ b/arch/x86/lib/atomic64_cx8_32.S
29190@@ -35,10 +35,20 @@ ENTRY(atomic64_read_cx8)
29191 CFI_STARTPROC
29192
29193 read64 %ecx
29194+ pax_force_retaddr
29195 ret
29196 CFI_ENDPROC
29197 ENDPROC(atomic64_read_cx8)
29198
29199+ENTRY(atomic64_read_unchecked_cx8)
29200+ CFI_STARTPROC
29201+
29202+ read64 %ecx
29203+ pax_force_retaddr
29204+ ret
29205+ CFI_ENDPROC
29206+ENDPROC(atomic64_read_unchecked_cx8)
29207+
29208 ENTRY(atomic64_set_cx8)
29209 CFI_STARTPROC
29210
29211@@ -48,10 +58,25 @@ ENTRY(atomic64_set_cx8)
29212 cmpxchg8b (%esi)
29213 jne 1b
29214
29215+ pax_force_retaddr
29216 ret
29217 CFI_ENDPROC
29218 ENDPROC(atomic64_set_cx8)
29219
29220+ENTRY(atomic64_set_unchecked_cx8)
29221+ CFI_STARTPROC
29222+
29223+1:
29224+/* we don't need LOCK_PREFIX since aligned 64-bit writes
29225+ * are atomic on 586 and newer */
29226+ cmpxchg8b (%esi)
29227+ jne 1b
29228+
29229+ pax_force_retaddr
29230+ ret
29231+ CFI_ENDPROC
29232+ENDPROC(atomic64_set_unchecked_cx8)
29233+
29234 ENTRY(atomic64_xchg_cx8)
29235 CFI_STARTPROC
29236
29237@@ -60,12 +85,13 @@ ENTRY(atomic64_xchg_cx8)
29238 cmpxchg8b (%esi)
29239 jne 1b
29240
29241+ pax_force_retaddr
29242 ret
29243 CFI_ENDPROC
29244 ENDPROC(atomic64_xchg_cx8)
29245
29246-.macro addsub_return func ins insc
29247-ENTRY(atomic64_\func\()_return_cx8)
29248+.macro addsub_return func ins insc unchecked=""
29249+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
29250 CFI_STARTPROC
29251 SAVE ebp
29252 SAVE ebx
29253@@ -82,27 +108,44 @@ ENTRY(atomic64_\func\()_return_cx8)
29254 movl %edx, %ecx
29255 \ins\()l %esi, %ebx
29256 \insc\()l %edi, %ecx
29257+
29258+.ifb \unchecked
29259+#ifdef CONFIG_PAX_REFCOUNT
29260+ into
29261+2:
29262+ _ASM_EXTABLE(2b, 3f)
29263+#endif
29264+.endif
29265+
29266 LOCK_PREFIX
29267 cmpxchg8b (%ebp)
29268 jne 1b
29269-
29270-10:
29271 movl %ebx, %eax
29272 movl %ecx, %edx
29273+
29274+.ifb \unchecked
29275+#ifdef CONFIG_PAX_REFCOUNT
29276+3:
29277+#endif
29278+.endif
29279+
29280 RESTORE edi
29281 RESTORE esi
29282 RESTORE ebx
29283 RESTORE ebp
29284+ pax_force_retaddr
29285 ret
29286 CFI_ENDPROC
29287-ENDPROC(atomic64_\func\()_return_cx8)
29288+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
29289 .endm
29290
29291 addsub_return add add adc
29292 addsub_return sub sub sbb
29293+addsub_return add add adc _unchecked
29294+addsub_return sub sub sbb _unchecked
29295
29296-.macro incdec_return func ins insc
29297-ENTRY(atomic64_\func\()_return_cx8)
29298+.macro incdec_return func ins insc unchecked=""
29299+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
29300 CFI_STARTPROC
29301 SAVE ebx
29302
29303@@ -112,21 +155,39 @@ ENTRY(atomic64_\func\()_return_cx8)
29304 movl %edx, %ecx
29305 \ins\()l $1, %ebx
29306 \insc\()l $0, %ecx
29307+
29308+.ifb \unchecked
29309+#ifdef CONFIG_PAX_REFCOUNT
29310+ into
29311+2:
29312+ _ASM_EXTABLE(2b, 3f)
29313+#endif
29314+.endif
29315+
29316 LOCK_PREFIX
29317 cmpxchg8b (%esi)
29318 jne 1b
29319
29320-10:
29321 movl %ebx, %eax
29322 movl %ecx, %edx
29323+
29324+.ifb \unchecked
29325+#ifdef CONFIG_PAX_REFCOUNT
29326+3:
29327+#endif
29328+.endif
29329+
29330 RESTORE ebx
29331+ pax_force_retaddr
29332 ret
29333 CFI_ENDPROC
29334-ENDPROC(atomic64_\func\()_return_cx8)
29335+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
29336 .endm
29337
29338 incdec_return inc add adc
29339 incdec_return dec sub sbb
29340+incdec_return inc add adc _unchecked
29341+incdec_return dec sub sbb _unchecked
29342
29343 ENTRY(atomic64_dec_if_positive_cx8)
29344 CFI_STARTPROC
29345@@ -138,6 +199,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
29346 movl %edx, %ecx
29347 subl $1, %ebx
29348 sbb $0, %ecx
29349+
29350+#ifdef CONFIG_PAX_REFCOUNT
29351+ into
29352+1234:
29353+ _ASM_EXTABLE(1234b, 2f)
29354+#endif
29355+
29356 js 2f
29357 LOCK_PREFIX
29358 cmpxchg8b (%esi)
29359@@ -147,6 +215,7 @@ ENTRY(atomic64_dec_if_positive_cx8)
29360 movl %ebx, %eax
29361 movl %ecx, %edx
29362 RESTORE ebx
29363+ pax_force_retaddr
29364 ret
29365 CFI_ENDPROC
29366 ENDPROC(atomic64_dec_if_positive_cx8)
29367@@ -171,6 +240,13 @@ ENTRY(atomic64_add_unless_cx8)
29368 movl %edx, %ecx
29369 addl %ebp, %ebx
29370 adcl %edi, %ecx
29371+
29372+#ifdef CONFIG_PAX_REFCOUNT
29373+ into
29374+1234:
29375+ _ASM_EXTABLE(1234b, 3f)
29376+#endif
29377+
29378 LOCK_PREFIX
29379 cmpxchg8b (%esi)
29380 jne 1b
29381@@ -181,6 +257,7 @@ ENTRY(atomic64_add_unless_cx8)
29382 CFI_ADJUST_CFA_OFFSET -8
29383 RESTORE ebx
29384 RESTORE ebp
29385+ pax_force_retaddr
29386 ret
29387 4:
29388 cmpl %edx, 4(%esp)
29389@@ -203,6 +280,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
29390 xorl %ecx, %ecx
29391 addl $1, %ebx
29392 adcl %edx, %ecx
29393+
29394+#ifdef CONFIG_PAX_REFCOUNT
29395+ into
29396+1234:
29397+ _ASM_EXTABLE(1234b, 3f)
29398+#endif
29399+
29400 LOCK_PREFIX
29401 cmpxchg8b (%esi)
29402 jne 1b
29403@@ -210,6 +294,7 @@ ENTRY(atomic64_inc_not_zero_cx8)
29404 movl $1, %eax
29405 3:
29406 RESTORE ebx
29407+ pax_force_retaddr
29408 ret
29409 CFI_ENDPROC
29410 ENDPROC(atomic64_inc_not_zero_cx8)
29411diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
29412index e78b8eee..7e173a8 100644
29413--- a/arch/x86/lib/checksum_32.S
29414+++ b/arch/x86/lib/checksum_32.S
29415@@ -29,7 +29,8 @@
29416 #include <asm/dwarf2.h>
29417 #include <asm/errno.h>
29418 #include <asm/asm.h>
29419-
29420+#include <asm/segment.h>
29421+
29422 /*
29423 * computes a partial checksum, e.g. for TCP/UDP fragments
29424 */
29425@@ -293,9 +294,24 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
29426
29427 #define ARGBASE 16
29428 #define FP 12
29429-
29430-ENTRY(csum_partial_copy_generic)
29431+
29432+ENTRY(csum_partial_copy_generic_to_user)
29433 CFI_STARTPROC
29434+
29435+#ifdef CONFIG_PAX_MEMORY_UDEREF
29436+ pushl_cfi %gs
29437+ popl_cfi %es
29438+ jmp csum_partial_copy_generic
29439+#endif
29440+
29441+ENTRY(csum_partial_copy_generic_from_user)
29442+
29443+#ifdef CONFIG_PAX_MEMORY_UDEREF
29444+ pushl_cfi %gs
29445+ popl_cfi %ds
29446+#endif
29447+
29448+ENTRY(csum_partial_copy_generic)
29449 subl $4,%esp
29450 CFI_ADJUST_CFA_OFFSET 4
29451 pushl_cfi %edi
29452@@ -317,7 +333,7 @@ ENTRY(csum_partial_copy_generic)
29453 jmp 4f
29454 SRC(1: movw (%esi), %bx )
29455 addl $2, %esi
29456-DST( movw %bx, (%edi) )
29457+DST( movw %bx, %es:(%edi) )
29458 addl $2, %edi
29459 addw %bx, %ax
29460 adcl $0, %eax
29461@@ -329,30 +345,30 @@ DST( movw %bx, (%edi) )
29462 SRC(1: movl (%esi), %ebx )
29463 SRC( movl 4(%esi), %edx )
29464 adcl %ebx, %eax
29465-DST( movl %ebx, (%edi) )
29466+DST( movl %ebx, %es:(%edi) )
29467 adcl %edx, %eax
29468-DST( movl %edx, 4(%edi) )
29469+DST( movl %edx, %es:4(%edi) )
29470
29471 SRC( movl 8(%esi), %ebx )
29472 SRC( movl 12(%esi), %edx )
29473 adcl %ebx, %eax
29474-DST( movl %ebx, 8(%edi) )
29475+DST( movl %ebx, %es:8(%edi) )
29476 adcl %edx, %eax
29477-DST( movl %edx, 12(%edi) )
29478+DST( movl %edx, %es:12(%edi) )
29479
29480 SRC( movl 16(%esi), %ebx )
29481 SRC( movl 20(%esi), %edx )
29482 adcl %ebx, %eax
29483-DST( movl %ebx, 16(%edi) )
29484+DST( movl %ebx, %es:16(%edi) )
29485 adcl %edx, %eax
29486-DST( movl %edx, 20(%edi) )
29487+DST( movl %edx, %es:20(%edi) )
29488
29489 SRC( movl 24(%esi), %ebx )
29490 SRC( movl 28(%esi), %edx )
29491 adcl %ebx, %eax
29492-DST( movl %ebx, 24(%edi) )
29493+DST( movl %ebx, %es:24(%edi) )
29494 adcl %edx, %eax
29495-DST( movl %edx, 28(%edi) )
29496+DST( movl %edx, %es:28(%edi) )
29497
29498 lea 32(%esi), %esi
29499 lea 32(%edi), %edi
29500@@ -366,7 +382,7 @@ DST( movl %edx, 28(%edi) )
29501 shrl $2, %edx # This clears CF
29502 SRC(3: movl (%esi), %ebx )
29503 adcl %ebx, %eax
29504-DST( movl %ebx, (%edi) )
29505+DST( movl %ebx, %es:(%edi) )
29506 lea 4(%esi), %esi
29507 lea 4(%edi), %edi
29508 dec %edx
29509@@ -378,12 +394,12 @@ DST( movl %ebx, (%edi) )
29510 jb 5f
29511 SRC( movw (%esi), %cx )
29512 leal 2(%esi), %esi
29513-DST( movw %cx, (%edi) )
29514+DST( movw %cx, %es:(%edi) )
29515 leal 2(%edi), %edi
29516 je 6f
29517 shll $16,%ecx
29518 SRC(5: movb (%esi), %cl )
29519-DST( movb %cl, (%edi) )
29520+DST( movb %cl, %es:(%edi) )
29521 6: addl %ecx, %eax
29522 adcl $0, %eax
29523 7:
29524@@ -394,7 +410,7 @@ DST( movb %cl, (%edi) )
29525
29526 6001:
29527 movl ARGBASE+20(%esp), %ebx # src_err_ptr
29528- movl $-EFAULT, (%ebx)
29529+ movl $-EFAULT, %ss:(%ebx)
29530
29531 # zero the complete destination - computing the rest
29532 # is too much work
29533@@ -407,11 +423,15 @@ DST( movb %cl, (%edi) )
29534
29535 6002:
29536 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
29537- movl $-EFAULT,(%ebx)
29538+ movl $-EFAULT,%ss:(%ebx)
29539 jmp 5000b
29540
29541 .previous
29542
29543+ pushl_cfi %ss
29544+ popl_cfi %ds
29545+ pushl_cfi %ss
29546+ popl_cfi %es
29547 popl_cfi %ebx
29548 CFI_RESTORE ebx
29549 popl_cfi %esi
29550@@ -421,26 +441,43 @@ DST( movb %cl, (%edi) )
29551 popl_cfi %ecx # equivalent to addl $4,%esp
29552 ret
29553 CFI_ENDPROC
29554-ENDPROC(csum_partial_copy_generic)
29555+ENDPROC(csum_partial_copy_generic_to_user)
29556
29557 #else
29558
29559 /* Version for PentiumII/PPro */
29560
29561 #define ROUND1(x) \
29562+ nop; nop; nop; \
29563 SRC(movl x(%esi), %ebx ) ; \
29564 addl %ebx, %eax ; \
29565- DST(movl %ebx, x(%edi) ) ;
29566+ DST(movl %ebx, %es:x(%edi)) ;
29567
29568 #define ROUND(x) \
29569+ nop; nop; nop; \
29570 SRC(movl x(%esi), %ebx ) ; \
29571 adcl %ebx, %eax ; \
29572- DST(movl %ebx, x(%edi) ) ;
29573+ DST(movl %ebx, %es:x(%edi)) ;
29574
29575 #define ARGBASE 12
29576-
29577-ENTRY(csum_partial_copy_generic)
29578+
29579+ENTRY(csum_partial_copy_generic_to_user)
29580 CFI_STARTPROC
29581+
29582+#ifdef CONFIG_PAX_MEMORY_UDEREF
29583+ pushl_cfi %gs
29584+ popl_cfi %es
29585+ jmp csum_partial_copy_generic
29586+#endif
29587+
29588+ENTRY(csum_partial_copy_generic_from_user)
29589+
29590+#ifdef CONFIG_PAX_MEMORY_UDEREF
29591+ pushl_cfi %gs
29592+ popl_cfi %ds
29593+#endif
29594+
29595+ENTRY(csum_partial_copy_generic)
29596 pushl_cfi %ebx
29597 CFI_REL_OFFSET ebx, 0
29598 pushl_cfi %edi
29599@@ -461,7 +498,7 @@ ENTRY(csum_partial_copy_generic)
29600 subl %ebx, %edi
29601 lea -1(%esi),%edx
29602 andl $-32,%edx
29603- lea 3f(%ebx,%ebx), %ebx
29604+ lea 3f(%ebx,%ebx,2), %ebx
29605 testl %esi, %esi
29606 jmp *%ebx
29607 1: addl $64,%esi
29608@@ -482,19 +519,19 @@ ENTRY(csum_partial_copy_generic)
29609 jb 5f
29610 SRC( movw (%esi), %dx )
29611 leal 2(%esi), %esi
29612-DST( movw %dx, (%edi) )
29613+DST( movw %dx, %es:(%edi) )
29614 leal 2(%edi), %edi
29615 je 6f
29616 shll $16,%edx
29617 5:
29618 SRC( movb (%esi), %dl )
29619-DST( movb %dl, (%edi) )
29620+DST( movb %dl, %es:(%edi) )
29621 6: addl %edx, %eax
29622 adcl $0, %eax
29623 7:
29624 .section .fixup, "ax"
29625 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
29626- movl $-EFAULT, (%ebx)
29627+ movl $-EFAULT, %ss:(%ebx)
29628 # zero the complete destination (computing the rest is too much work)
29629 movl ARGBASE+8(%esp),%edi # dst
29630 movl ARGBASE+12(%esp),%ecx # len
29631@@ -502,10 +539,17 @@ DST( movb %dl, (%edi) )
29632 rep; stosb
29633 jmp 7b
29634 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
29635- movl $-EFAULT, (%ebx)
29636+ movl $-EFAULT, %ss:(%ebx)
29637 jmp 7b
29638 .previous
29639
29640+#ifdef CONFIG_PAX_MEMORY_UDEREF
29641+ pushl_cfi %ss
29642+ popl_cfi %ds
29643+ pushl_cfi %ss
29644+ popl_cfi %es
29645+#endif
29646+
29647 popl_cfi %esi
29648 CFI_RESTORE esi
29649 popl_cfi %edi
29650@@ -514,7 +558,7 @@ DST( movb %dl, (%edi) )
29651 CFI_RESTORE ebx
29652 ret
29653 CFI_ENDPROC
29654-ENDPROC(csum_partial_copy_generic)
29655+ENDPROC(csum_partial_copy_generic_to_user)
29656
29657 #undef ROUND
29658 #undef ROUND1
29659diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
29660index f2145cf..cea889d 100644
29661--- a/arch/x86/lib/clear_page_64.S
29662+++ b/arch/x86/lib/clear_page_64.S
29663@@ -11,6 +11,7 @@ ENTRY(clear_page_c)
29664 movl $4096/8,%ecx
29665 xorl %eax,%eax
29666 rep stosq
29667+ pax_force_retaddr
29668 ret
29669 CFI_ENDPROC
29670 ENDPROC(clear_page_c)
29671@@ -20,6 +21,7 @@ ENTRY(clear_page_c_e)
29672 movl $4096,%ecx
29673 xorl %eax,%eax
29674 rep stosb
29675+ pax_force_retaddr
29676 ret
29677 CFI_ENDPROC
29678 ENDPROC(clear_page_c_e)
29679@@ -43,6 +45,7 @@ ENTRY(clear_page)
29680 leaq 64(%rdi),%rdi
29681 jnz .Lloop
29682 nop
29683+ pax_force_retaddr
29684 ret
29685 CFI_ENDPROC
29686 .Lclear_page_end:
29687@@ -58,7 +61,7 @@ ENDPROC(clear_page)
29688
29689 #include <asm/cpufeature.h>
29690
29691- .section .altinstr_replacement,"ax"
29692+ .section .altinstr_replacement,"a"
29693 1: .byte 0xeb /* jmp <disp8> */
29694 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
29695 2: .byte 0xeb /* jmp <disp8> */
29696diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S
29697index 40a1725..5d12ac4 100644
29698--- a/arch/x86/lib/cmpxchg16b_emu.S
29699+++ b/arch/x86/lib/cmpxchg16b_emu.S
29700@@ -8,6 +8,7 @@
29701 #include <linux/linkage.h>
29702 #include <asm/dwarf2.h>
29703 #include <asm/percpu.h>
29704+#include <asm/alternative-asm.h>
29705
29706 .text
29707
29708@@ -46,12 +47,14 @@ CFI_STARTPROC
29709 CFI_REMEMBER_STATE
29710 popfq_cfi
29711 mov $1, %al
29712+ pax_force_retaddr
29713 ret
29714
29715 CFI_RESTORE_STATE
29716 .Lnot_same:
29717 popfq_cfi
29718 xor %al,%al
29719+ pax_force_retaddr
29720 ret
29721
29722 CFI_ENDPROC
29723diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
29724index 176cca6..e0d658e 100644
29725--- a/arch/x86/lib/copy_page_64.S
29726+++ b/arch/x86/lib/copy_page_64.S
29727@@ -9,6 +9,7 @@ copy_page_rep:
29728 CFI_STARTPROC
29729 movl $4096/8, %ecx
29730 rep movsq
29731+ pax_force_retaddr
29732 ret
29733 CFI_ENDPROC
29734 ENDPROC(copy_page_rep)
29735@@ -24,8 +25,8 @@ ENTRY(copy_page)
29736 CFI_ADJUST_CFA_OFFSET 2*8
29737 movq %rbx, (%rsp)
29738 CFI_REL_OFFSET rbx, 0
29739- movq %r12, 1*8(%rsp)
29740- CFI_REL_OFFSET r12, 1*8
29741+ movq %r13, 1*8(%rsp)
29742+ CFI_REL_OFFSET r13, 1*8
29743
29744 movl $(4096/64)-5, %ecx
29745 .p2align 4
29746@@ -38,7 +39,7 @@ ENTRY(copy_page)
29747 movq 0x8*4(%rsi), %r9
29748 movq 0x8*5(%rsi), %r10
29749 movq 0x8*6(%rsi), %r11
29750- movq 0x8*7(%rsi), %r12
29751+ movq 0x8*7(%rsi), %r13
29752
29753 prefetcht0 5*64(%rsi)
29754
29755@@ -49,7 +50,7 @@ ENTRY(copy_page)
29756 movq %r9, 0x8*4(%rdi)
29757 movq %r10, 0x8*5(%rdi)
29758 movq %r11, 0x8*6(%rdi)
29759- movq %r12, 0x8*7(%rdi)
29760+ movq %r13, 0x8*7(%rdi)
29761
29762 leaq 64 (%rsi), %rsi
29763 leaq 64 (%rdi), %rdi
29764@@ -68,7 +69,7 @@ ENTRY(copy_page)
29765 movq 0x8*4(%rsi), %r9
29766 movq 0x8*5(%rsi), %r10
29767 movq 0x8*6(%rsi), %r11
29768- movq 0x8*7(%rsi), %r12
29769+ movq 0x8*7(%rsi), %r13
29770
29771 movq %rax, 0x8*0(%rdi)
29772 movq %rbx, 0x8*1(%rdi)
29773@@ -77,7 +78,7 @@ ENTRY(copy_page)
29774 movq %r9, 0x8*4(%rdi)
29775 movq %r10, 0x8*5(%rdi)
29776 movq %r11, 0x8*6(%rdi)
29777- movq %r12, 0x8*7(%rdi)
29778+ movq %r13, 0x8*7(%rdi)
29779
29780 leaq 64(%rdi), %rdi
29781 leaq 64(%rsi), %rsi
29782@@ -85,10 +86,11 @@ ENTRY(copy_page)
29783
29784 movq (%rsp), %rbx
29785 CFI_RESTORE rbx
29786- movq 1*8(%rsp), %r12
29787- CFI_RESTORE r12
29788+ movq 1*8(%rsp), %r13
29789+ CFI_RESTORE r13
29790 addq $2*8, %rsp
29791 CFI_ADJUST_CFA_OFFSET -2*8
29792+ pax_force_retaddr
29793 ret
29794 .Lcopy_page_end:
29795 CFI_ENDPROC
29796@@ -99,7 +101,7 @@ ENDPROC(copy_page)
29797
29798 #include <asm/cpufeature.h>
29799
29800- .section .altinstr_replacement,"ax"
29801+ .section .altinstr_replacement,"a"
29802 1: .byte 0xeb /* jmp <disp8> */
29803 .byte (copy_page_rep - copy_page) - (2f - 1b) /* offset */
29804 2:
29805diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
29806index dee945d..a84067b 100644
29807--- a/arch/x86/lib/copy_user_64.S
29808+++ b/arch/x86/lib/copy_user_64.S
29809@@ -18,31 +18,7 @@
29810 #include <asm/alternative-asm.h>
29811 #include <asm/asm.h>
29812 #include <asm/smap.h>
29813-
29814-/*
29815- * By placing feature2 after feature1 in altinstructions section, we logically
29816- * implement:
29817- * If CPU has feature2, jmp to alt2 is used
29818- * else if CPU has feature1, jmp to alt1 is used
29819- * else jmp to orig is used.
29820- */
29821- .macro ALTERNATIVE_JUMP feature1,feature2,orig,alt1,alt2
29822-0:
29823- .byte 0xe9 /* 32bit jump */
29824- .long \orig-1f /* by default jump to orig */
29825-1:
29826- .section .altinstr_replacement,"ax"
29827-2: .byte 0xe9 /* near jump with 32bit immediate */
29828- .long \alt1-1b /* offset */ /* or alternatively to alt1 */
29829-3: .byte 0xe9 /* near jump with 32bit immediate */
29830- .long \alt2-1b /* offset */ /* or alternatively to alt2 */
29831- .previous
29832-
29833- .section .altinstructions,"a"
29834- altinstruction_entry 0b,2b,\feature1,5,5
29835- altinstruction_entry 0b,3b,\feature2,5,5
29836- .previous
29837- .endm
29838+#include <asm/pgtable.h>
29839
29840 .macro ALIGN_DESTINATION
29841 #ifdef FIX_ALIGNMENT
29842@@ -70,52 +46,6 @@
29843 #endif
29844 .endm
29845
29846-/* Standard copy_to_user with segment limit checking */
29847-ENTRY(_copy_to_user)
29848- CFI_STARTPROC
29849- GET_THREAD_INFO(%rax)
29850- movq %rdi,%rcx
29851- addq %rdx,%rcx
29852- jc bad_to_user
29853- cmpq TI_addr_limit(%rax),%rcx
29854- ja bad_to_user
29855- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
29856- copy_user_generic_unrolled,copy_user_generic_string, \
29857- copy_user_enhanced_fast_string
29858- CFI_ENDPROC
29859-ENDPROC(_copy_to_user)
29860-
29861-/* Standard copy_from_user with segment limit checking */
29862-ENTRY(_copy_from_user)
29863- CFI_STARTPROC
29864- GET_THREAD_INFO(%rax)
29865- movq %rsi,%rcx
29866- addq %rdx,%rcx
29867- jc bad_from_user
29868- cmpq TI_addr_limit(%rax),%rcx
29869- ja bad_from_user
29870- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
29871- copy_user_generic_unrolled,copy_user_generic_string, \
29872- copy_user_enhanced_fast_string
29873- CFI_ENDPROC
29874-ENDPROC(_copy_from_user)
29875-
29876- .section .fixup,"ax"
29877- /* must zero dest */
29878-ENTRY(bad_from_user)
29879-bad_from_user:
29880- CFI_STARTPROC
29881- movl %edx,%ecx
29882- xorl %eax,%eax
29883- rep
29884- stosb
29885-bad_to_user:
29886- movl %edx,%eax
29887- ret
29888- CFI_ENDPROC
29889-ENDPROC(bad_from_user)
29890- .previous
29891-
29892 /*
29893 * copy_user_generic_unrolled - memory copy with exception handling.
29894 * This version is for CPUs like P4 that don't have efficient micro
29895@@ -131,6 +61,7 @@ ENDPROC(bad_from_user)
29896 */
29897 ENTRY(copy_user_generic_unrolled)
29898 CFI_STARTPROC
29899+ ASM_PAX_OPEN_USERLAND
29900 ASM_STAC
29901 cmpl $8,%edx
29902 jb 20f /* less then 8 bytes, go to byte copy loop */
29903@@ -180,6 +111,8 @@ ENTRY(copy_user_generic_unrolled)
29904 jnz 21b
29905 23: xor %eax,%eax
29906 ASM_CLAC
29907+ ASM_PAX_CLOSE_USERLAND
29908+ pax_force_retaddr
29909 ret
29910
29911 .section .fixup,"ax"
29912@@ -235,6 +168,7 @@ ENDPROC(copy_user_generic_unrolled)
29913 */
29914 ENTRY(copy_user_generic_string)
29915 CFI_STARTPROC
29916+ ASM_PAX_OPEN_USERLAND
29917 ASM_STAC
29918 cmpl $8,%edx
29919 jb 2f /* less than 8 bytes, go to byte copy loop */
29920@@ -249,6 +183,8 @@ ENTRY(copy_user_generic_string)
29921 movsb
29922 xorl %eax,%eax
29923 ASM_CLAC
29924+ ASM_PAX_CLOSE_USERLAND
29925+ pax_force_retaddr
29926 ret
29927
29928 .section .fixup,"ax"
29929@@ -276,12 +212,15 @@ ENDPROC(copy_user_generic_string)
29930 */
29931 ENTRY(copy_user_enhanced_fast_string)
29932 CFI_STARTPROC
29933+ ASM_PAX_OPEN_USERLAND
29934 ASM_STAC
29935 movl %edx,%ecx
29936 1: rep
29937 movsb
29938 xorl %eax,%eax
29939 ASM_CLAC
29940+ ASM_PAX_CLOSE_USERLAND
29941+ pax_force_retaddr
29942 ret
29943
29944 .section .fixup,"ax"
29945diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
29946index 6a4f43c..c70fb52 100644
29947--- a/arch/x86/lib/copy_user_nocache_64.S
29948+++ b/arch/x86/lib/copy_user_nocache_64.S
29949@@ -8,6 +8,7 @@
29950
29951 #include <linux/linkage.h>
29952 #include <asm/dwarf2.h>
29953+#include <asm/alternative-asm.h>
29954
29955 #define FIX_ALIGNMENT 1
29956
29957@@ -16,6 +17,7 @@
29958 #include <asm/thread_info.h>
29959 #include <asm/asm.h>
29960 #include <asm/smap.h>
29961+#include <asm/pgtable.h>
29962
29963 .macro ALIGN_DESTINATION
29964 #ifdef FIX_ALIGNMENT
29965@@ -49,6 +51,16 @@
29966 */
29967 ENTRY(__copy_user_nocache)
29968 CFI_STARTPROC
29969+
29970+#ifdef CONFIG_PAX_MEMORY_UDEREF
29971+ mov pax_user_shadow_base,%rcx
29972+ cmp %rcx,%rsi
29973+ jae 1f
29974+ add %rcx,%rsi
29975+1:
29976+#endif
29977+
29978+ ASM_PAX_OPEN_USERLAND
29979 ASM_STAC
29980 cmpl $8,%edx
29981 jb 20f /* less then 8 bytes, go to byte copy loop */
29982@@ -98,7 +110,9 @@ ENTRY(__copy_user_nocache)
29983 jnz 21b
29984 23: xorl %eax,%eax
29985 ASM_CLAC
29986+ ASM_PAX_CLOSE_USERLAND
29987 sfence
29988+ pax_force_retaddr
29989 ret
29990
29991 .section .fixup,"ax"
29992diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
29993index 2419d5f..fe52d0e 100644
29994--- a/arch/x86/lib/csum-copy_64.S
29995+++ b/arch/x86/lib/csum-copy_64.S
29996@@ -9,6 +9,7 @@
29997 #include <asm/dwarf2.h>
29998 #include <asm/errno.h>
29999 #include <asm/asm.h>
30000+#include <asm/alternative-asm.h>
30001
30002 /*
30003 * Checksum copy with exception handling.
30004@@ -56,8 +57,8 @@ ENTRY(csum_partial_copy_generic)
30005 CFI_ADJUST_CFA_OFFSET 7*8
30006 movq %rbx, 2*8(%rsp)
30007 CFI_REL_OFFSET rbx, 2*8
30008- movq %r12, 3*8(%rsp)
30009- CFI_REL_OFFSET r12, 3*8
30010+ movq %r15, 3*8(%rsp)
30011+ CFI_REL_OFFSET r15, 3*8
30012 movq %r14, 4*8(%rsp)
30013 CFI_REL_OFFSET r14, 4*8
30014 movq %r13, 5*8(%rsp)
30015@@ -72,16 +73,16 @@ ENTRY(csum_partial_copy_generic)
30016 movl %edx, %ecx
30017
30018 xorl %r9d, %r9d
30019- movq %rcx, %r12
30020+ movq %rcx, %r15
30021
30022- shrq $6, %r12
30023+ shrq $6, %r15
30024 jz .Lhandle_tail /* < 64 */
30025
30026 clc
30027
30028 /* main loop. clear in 64 byte blocks */
30029 /* r9: zero, r8: temp2, rbx: temp1, rax: sum, rcx: saved length */
30030- /* r11: temp3, rdx: temp4, r12 loopcnt */
30031+ /* r11: temp3, rdx: temp4, r15 loopcnt */
30032 /* r10: temp5, rbp: temp6, r14 temp7, r13 temp8 */
30033 .p2align 4
30034 .Lloop:
30035@@ -115,7 +116,7 @@ ENTRY(csum_partial_copy_generic)
30036 adcq %r14, %rax
30037 adcq %r13, %rax
30038
30039- decl %r12d
30040+ decl %r15d
30041
30042 dest
30043 movq %rbx, (%rsi)
30044@@ -210,8 +211,8 @@ ENTRY(csum_partial_copy_generic)
30045 .Lende:
30046 movq 2*8(%rsp), %rbx
30047 CFI_RESTORE rbx
30048- movq 3*8(%rsp), %r12
30049- CFI_RESTORE r12
30050+ movq 3*8(%rsp), %r15
30051+ CFI_RESTORE r15
30052 movq 4*8(%rsp), %r14
30053 CFI_RESTORE r14
30054 movq 5*8(%rsp), %r13
30055@@ -220,6 +221,7 @@ ENTRY(csum_partial_copy_generic)
30056 CFI_RESTORE rbp
30057 addq $7*8, %rsp
30058 CFI_ADJUST_CFA_OFFSET -7*8
30059+ pax_force_retaddr
30060 ret
30061 CFI_RESTORE_STATE
30062
30063diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
30064index 1318f75..44c30fd 100644
30065--- a/arch/x86/lib/csum-wrappers_64.c
30066+++ b/arch/x86/lib/csum-wrappers_64.c
30067@@ -52,10 +52,12 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
30068 len -= 2;
30069 }
30070 }
30071+ pax_open_userland();
30072 stac();
30073- isum = csum_partial_copy_generic((__force const void *)src,
30074+ isum = csum_partial_copy_generic((const void __force_kernel *)____m(src),
30075 dst, len, isum, errp, NULL);
30076 clac();
30077+ pax_close_userland();
30078 if (unlikely(*errp))
30079 goto out_err;
30080
30081@@ -109,10 +111,12 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
30082 }
30083
30084 *errp = 0;
30085+ pax_open_userland();
30086 stac();
30087- ret = csum_partial_copy_generic(src, (void __force *)dst,
30088+ ret = csum_partial_copy_generic(src, (void __force_kernel *)____m(dst),
30089 len, isum, NULL, errp);
30090 clac();
30091+ pax_close_userland();
30092 return ret;
30093 }
30094 EXPORT_SYMBOL(csum_partial_copy_to_user);
30095diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
30096index a451235..1daa956 100644
30097--- a/arch/x86/lib/getuser.S
30098+++ b/arch/x86/lib/getuser.S
30099@@ -33,17 +33,40 @@
30100 #include <asm/thread_info.h>
30101 #include <asm/asm.h>
30102 #include <asm/smap.h>
30103+#include <asm/segment.h>
30104+#include <asm/pgtable.h>
30105+#include <asm/alternative-asm.h>
30106+
30107+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
30108+#define __copyuser_seg gs;
30109+#else
30110+#define __copyuser_seg
30111+#endif
30112
30113 .text
30114 ENTRY(__get_user_1)
30115 CFI_STARTPROC
30116+
30117+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30118 GET_THREAD_INFO(%_ASM_DX)
30119 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
30120 jae bad_get_user
30121 ASM_STAC
30122-1: movzbl (%_ASM_AX),%edx
30123+
30124+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30125+ mov pax_user_shadow_base,%_ASM_DX
30126+ cmp %_ASM_DX,%_ASM_AX
30127+ jae 1234f
30128+ add %_ASM_DX,%_ASM_AX
30129+1234:
30130+#endif
30131+
30132+#endif
30133+
30134+1: __copyuser_seg movzbl (%_ASM_AX),%edx
30135 xor %eax,%eax
30136 ASM_CLAC
30137+ pax_force_retaddr
30138 ret
30139 CFI_ENDPROC
30140 ENDPROC(__get_user_1)
30141@@ -51,14 +74,28 @@ ENDPROC(__get_user_1)
30142 ENTRY(__get_user_2)
30143 CFI_STARTPROC
30144 add $1,%_ASM_AX
30145+
30146+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30147 jc bad_get_user
30148 GET_THREAD_INFO(%_ASM_DX)
30149 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
30150 jae bad_get_user
30151 ASM_STAC
30152-2: movzwl -1(%_ASM_AX),%edx
30153+
30154+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30155+ mov pax_user_shadow_base,%_ASM_DX
30156+ cmp %_ASM_DX,%_ASM_AX
30157+ jae 1234f
30158+ add %_ASM_DX,%_ASM_AX
30159+1234:
30160+#endif
30161+
30162+#endif
30163+
30164+2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
30165 xor %eax,%eax
30166 ASM_CLAC
30167+ pax_force_retaddr
30168 ret
30169 CFI_ENDPROC
30170 ENDPROC(__get_user_2)
30171@@ -66,14 +103,28 @@ ENDPROC(__get_user_2)
30172 ENTRY(__get_user_4)
30173 CFI_STARTPROC
30174 add $3,%_ASM_AX
30175+
30176+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30177 jc bad_get_user
30178 GET_THREAD_INFO(%_ASM_DX)
30179 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
30180 jae bad_get_user
30181 ASM_STAC
30182-3: movl -3(%_ASM_AX),%edx
30183+
30184+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30185+ mov pax_user_shadow_base,%_ASM_DX
30186+ cmp %_ASM_DX,%_ASM_AX
30187+ jae 1234f
30188+ add %_ASM_DX,%_ASM_AX
30189+1234:
30190+#endif
30191+
30192+#endif
30193+
30194+3: __copyuser_seg movl -3(%_ASM_AX),%edx
30195 xor %eax,%eax
30196 ASM_CLAC
30197+ pax_force_retaddr
30198 ret
30199 CFI_ENDPROC
30200 ENDPROC(__get_user_4)
30201@@ -86,10 +137,20 @@ ENTRY(__get_user_8)
30202 GET_THREAD_INFO(%_ASM_DX)
30203 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
30204 jae bad_get_user
30205+
30206+#ifdef CONFIG_PAX_MEMORY_UDEREF
30207+ mov pax_user_shadow_base,%_ASM_DX
30208+ cmp %_ASM_DX,%_ASM_AX
30209+ jae 1234f
30210+ add %_ASM_DX,%_ASM_AX
30211+1234:
30212+#endif
30213+
30214 ASM_STAC
30215 4: movq -7(%_ASM_AX),%rdx
30216 xor %eax,%eax
30217 ASM_CLAC
30218+ pax_force_retaddr
30219 ret
30220 #else
30221 add $7,%_ASM_AX
30222@@ -98,10 +159,11 @@ ENTRY(__get_user_8)
30223 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
30224 jae bad_get_user_8
30225 ASM_STAC
30226-4: movl -7(%_ASM_AX),%edx
30227-5: movl -3(%_ASM_AX),%ecx
30228+4: __copyuser_seg movl -7(%_ASM_AX),%edx
30229+5: __copyuser_seg movl -3(%_ASM_AX),%ecx
30230 xor %eax,%eax
30231 ASM_CLAC
30232+ pax_force_retaddr
30233 ret
30234 #endif
30235 CFI_ENDPROC
30236@@ -113,6 +175,7 @@ bad_get_user:
30237 xor %edx,%edx
30238 mov $(-EFAULT),%_ASM_AX
30239 ASM_CLAC
30240+ pax_force_retaddr
30241 ret
30242 CFI_ENDPROC
30243 END(bad_get_user)
30244@@ -124,6 +187,7 @@ bad_get_user_8:
30245 xor %ecx,%ecx
30246 mov $(-EFAULT),%_ASM_AX
30247 ASM_CLAC
30248+ pax_force_retaddr
30249 ret
30250 CFI_ENDPROC
30251 END(bad_get_user_8)
30252diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
30253index 54fcffe..7be149e 100644
30254--- a/arch/x86/lib/insn.c
30255+++ b/arch/x86/lib/insn.c
30256@@ -20,8 +20,10 @@
30257
30258 #ifdef __KERNEL__
30259 #include <linux/string.h>
30260+#include <asm/pgtable_types.h>
30261 #else
30262 #include <string.h>
30263+#define ktla_ktva(addr) addr
30264 #endif
30265 #include <asm/inat.h>
30266 #include <asm/insn.h>
30267@@ -53,8 +55,8 @@
30268 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
30269 {
30270 memset(insn, 0, sizeof(*insn));
30271- insn->kaddr = kaddr;
30272- insn->next_byte = kaddr;
30273+ insn->kaddr = ktla_ktva(kaddr);
30274+ insn->next_byte = ktla_ktva(kaddr);
30275 insn->x86_64 = x86_64 ? 1 : 0;
30276 insn->opnd_bytes = 4;
30277 if (x86_64)
30278diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
30279index 05a95e7..326f2fa 100644
30280--- a/arch/x86/lib/iomap_copy_64.S
30281+++ b/arch/x86/lib/iomap_copy_64.S
30282@@ -17,6 +17,7 @@
30283
30284 #include <linux/linkage.h>
30285 #include <asm/dwarf2.h>
30286+#include <asm/alternative-asm.h>
30287
30288 /*
30289 * override generic version in lib/iomap_copy.c
30290@@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
30291 CFI_STARTPROC
30292 movl %edx,%ecx
30293 rep movsd
30294+ pax_force_retaddr
30295 ret
30296 CFI_ENDPROC
30297 ENDPROC(__iowrite32_copy)
30298diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
30299index 56313a3..0db417e 100644
30300--- a/arch/x86/lib/memcpy_64.S
30301+++ b/arch/x86/lib/memcpy_64.S
30302@@ -24,7 +24,7 @@
30303 * This gets patched over the unrolled variant (below) via the
30304 * alternative instructions framework:
30305 */
30306- .section .altinstr_replacement, "ax", @progbits
30307+ .section .altinstr_replacement, "a", @progbits
30308 .Lmemcpy_c:
30309 movq %rdi, %rax
30310 movq %rdx, %rcx
30311@@ -33,6 +33,7 @@
30312 rep movsq
30313 movl %edx, %ecx
30314 rep movsb
30315+ pax_force_retaddr
30316 ret
30317 .Lmemcpy_e:
30318 .previous
30319@@ -44,11 +45,12 @@
30320 * This gets patched over the unrolled variant (below) via the
30321 * alternative instructions framework:
30322 */
30323- .section .altinstr_replacement, "ax", @progbits
30324+ .section .altinstr_replacement, "a", @progbits
30325 .Lmemcpy_c_e:
30326 movq %rdi, %rax
30327 movq %rdx, %rcx
30328 rep movsb
30329+ pax_force_retaddr
30330 ret
30331 .Lmemcpy_e_e:
30332 .previous
30333@@ -136,6 +138,7 @@ ENTRY(memcpy)
30334 movq %r9, 1*8(%rdi)
30335 movq %r10, -2*8(%rdi, %rdx)
30336 movq %r11, -1*8(%rdi, %rdx)
30337+ pax_force_retaddr
30338 retq
30339 .p2align 4
30340 .Lless_16bytes:
30341@@ -148,6 +151,7 @@ ENTRY(memcpy)
30342 movq -1*8(%rsi, %rdx), %r9
30343 movq %r8, 0*8(%rdi)
30344 movq %r9, -1*8(%rdi, %rdx)
30345+ pax_force_retaddr
30346 retq
30347 .p2align 4
30348 .Lless_8bytes:
30349@@ -161,6 +165,7 @@ ENTRY(memcpy)
30350 movl -4(%rsi, %rdx), %r8d
30351 movl %ecx, (%rdi)
30352 movl %r8d, -4(%rdi, %rdx)
30353+ pax_force_retaddr
30354 retq
30355 .p2align 4
30356 .Lless_3bytes:
30357@@ -179,6 +184,7 @@ ENTRY(memcpy)
30358 movb %cl, (%rdi)
30359
30360 .Lend:
30361+ pax_force_retaddr
30362 retq
30363 CFI_ENDPROC
30364 ENDPROC(memcpy)
30365diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
30366index 65268a6..dd1de11 100644
30367--- a/arch/x86/lib/memmove_64.S
30368+++ b/arch/x86/lib/memmove_64.S
30369@@ -202,14 +202,16 @@ ENTRY(memmove)
30370 movb (%rsi), %r11b
30371 movb %r11b, (%rdi)
30372 13:
30373+ pax_force_retaddr
30374 retq
30375 CFI_ENDPROC
30376
30377- .section .altinstr_replacement,"ax"
30378+ .section .altinstr_replacement,"a"
30379 .Lmemmove_begin_forward_efs:
30380 /* Forward moving data. */
30381 movq %rdx, %rcx
30382 rep movsb
30383+ pax_force_retaddr
30384 retq
30385 .Lmemmove_end_forward_efs:
30386 .previous
30387diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
30388index 2dcb380..2eb79fe 100644
30389--- a/arch/x86/lib/memset_64.S
30390+++ b/arch/x86/lib/memset_64.S
30391@@ -16,7 +16,7 @@
30392 *
30393 * rax original destination
30394 */
30395- .section .altinstr_replacement, "ax", @progbits
30396+ .section .altinstr_replacement, "a", @progbits
30397 .Lmemset_c:
30398 movq %rdi,%r9
30399 movq %rdx,%rcx
30400@@ -30,6 +30,7 @@
30401 movl %edx,%ecx
30402 rep stosb
30403 movq %r9,%rax
30404+ pax_force_retaddr
30405 ret
30406 .Lmemset_e:
30407 .previous
30408@@ -45,13 +46,14 @@
30409 *
30410 * rax original destination
30411 */
30412- .section .altinstr_replacement, "ax", @progbits
30413+ .section .altinstr_replacement, "a", @progbits
30414 .Lmemset_c_e:
30415 movq %rdi,%r9
30416 movb %sil,%al
30417 movq %rdx,%rcx
30418 rep stosb
30419 movq %r9,%rax
30420+ pax_force_retaddr
30421 ret
30422 .Lmemset_e_e:
30423 .previous
30424@@ -118,6 +120,7 @@ ENTRY(__memset)
30425
30426 .Lende:
30427 movq %r10,%rax
30428+ pax_force_retaddr
30429 ret
30430
30431 CFI_RESTORE_STATE
30432diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
30433index c9f2d9b..e7fd2c0 100644
30434--- a/arch/x86/lib/mmx_32.c
30435+++ b/arch/x86/lib/mmx_32.c
30436@@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
30437 {
30438 void *p;
30439 int i;
30440+ unsigned long cr0;
30441
30442 if (unlikely(in_interrupt()))
30443 return __memcpy(to, from, len);
30444@@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
30445 kernel_fpu_begin();
30446
30447 __asm__ __volatile__ (
30448- "1: prefetch (%0)\n" /* This set is 28 bytes */
30449- " prefetch 64(%0)\n"
30450- " prefetch 128(%0)\n"
30451- " prefetch 192(%0)\n"
30452- " prefetch 256(%0)\n"
30453+ "1: prefetch (%1)\n" /* This set is 28 bytes */
30454+ " prefetch 64(%1)\n"
30455+ " prefetch 128(%1)\n"
30456+ " prefetch 192(%1)\n"
30457+ " prefetch 256(%1)\n"
30458 "2: \n"
30459 ".section .fixup, \"ax\"\n"
30460- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30461+ "3: \n"
30462+
30463+#ifdef CONFIG_PAX_KERNEXEC
30464+ " movl %%cr0, %0\n"
30465+ " movl %0, %%eax\n"
30466+ " andl $0xFFFEFFFF, %%eax\n"
30467+ " movl %%eax, %%cr0\n"
30468+#endif
30469+
30470+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30471+
30472+#ifdef CONFIG_PAX_KERNEXEC
30473+ " movl %0, %%cr0\n"
30474+#endif
30475+
30476 " jmp 2b\n"
30477 ".previous\n"
30478 _ASM_EXTABLE(1b, 3b)
30479- : : "r" (from));
30480+ : "=&r" (cr0) : "r" (from) : "ax");
30481
30482 for ( ; i > 5; i--) {
30483 __asm__ __volatile__ (
30484- "1: prefetch 320(%0)\n"
30485- "2: movq (%0), %%mm0\n"
30486- " movq 8(%0), %%mm1\n"
30487- " movq 16(%0), %%mm2\n"
30488- " movq 24(%0), %%mm3\n"
30489- " movq %%mm0, (%1)\n"
30490- " movq %%mm1, 8(%1)\n"
30491- " movq %%mm2, 16(%1)\n"
30492- " movq %%mm3, 24(%1)\n"
30493- " movq 32(%0), %%mm0\n"
30494- " movq 40(%0), %%mm1\n"
30495- " movq 48(%0), %%mm2\n"
30496- " movq 56(%0), %%mm3\n"
30497- " movq %%mm0, 32(%1)\n"
30498- " movq %%mm1, 40(%1)\n"
30499- " movq %%mm2, 48(%1)\n"
30500- " movq %%mm3, 56(%1)\n"
30501+ "1: prefetch 320(%1)\n"
30502+ "2: movq (%1), %%mm0\n"
30503+ " movq 8(%1), %%mm1\n"
30504+ " movq 16(%1), %%mm2\n"
30505+ " movq 24(%1), %%mm3\n"
30506+ " movq %%mm0, (%2)\n"
30507+ " movq %%mm1, 8(%2)\n"
30508+ " movq %%mm2, 16(%2)\n"
30509+ " movq %%mm3, 24(%2)\n"
30510+ " movq 32(%1), %%mm0\n"
30511+ " movq 40(%1), %%mm1\n"
30512+ " movq 48(%1), %%mm2\n"
30513+ " movq 56(%1), %%mm3\n"
30514+ " movq %%mm0, 32(%2)\n"
30515+ " movq %%mm1, 40(%2)\n"
30516+ " movq %%mm2, 48(%2)\n"
30517+ " movq %%mm3, 56(%2)\n"
30518 ".section .fixup, \"ax\"\n"
30519- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30520+ "3:\n"
30521+
30522+#ifdef CONFIG_PAX_KERNEXEC
30523+ " movl %%cr0, %0\n"
30524+ " movl %0, %%eax\n"
30525+ " andl $0xFFFEFFFF, %%eax\n"
30526+ " movl %%eax, %%cr0\n"
30527+#endif
30528+
30529+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30530+
30531+#ifdef CONFIG_PAX_KERNEXEC
30532+ " movl %0, %%cr0\n"
30533+#endif
30534+
30535 " jmp 2b\n"
30536 ".previous\n"
30537 _ASM_EXTABLE(1b, 3b)
30538- : : "r" (from), "r" (to) : "memory");
30539+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
30540
30541 from += 64;
30542 to += 64;
30543@@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
30544 static void fast_copy_page(void *to, void *from)
30545 {
30546 int i;
30547+ unsigned long cr0;
30548
30549 kernel_fpu_begin();
30550
30551@@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
30552 * but that is for later. -AV
30553 */
30554 __asm__ __volatile__(
30555- "1: prefetch (%0)\n"
30556- " prefetch 64(%0)\n"
30557- " prefetch 128(%0)\n"
30558- " prefetch 192(%0)\n"
30559- " prefetch 256(%0)\n"
30560+ "1: prefetch (%1)\n"
30561+ " prefetch 64(%1)\n"
30562+ " prefetch 128(%1)\n"
30563+ " prefetch 192(%1)\n"
30564+ " prefetch 256(%1)\n"
30565 "2: \n"
30566 ".section .fixup, \"ax\"\n"
30567- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30568+ "3: \n"
30569+
30570+#ifdef CONFIG_PAX_KERNEXEC
30571+ " movl %%cr0, %0\n"
30572+ " movl %0, %%eax\n"
30573+ " andl $0xFFFEFFFF, %%eax\n"
30574+ " movl %%eax, %%cr0\n"
30575+#endif
30576+
30577+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30578+
30579+#ifdef CONFIG_PAX_KERNEXEC
30580+ " movl %0, %%cr0\n"
30581+#endif
30582+
30583 " jmp 2b\n"
30584 ".previous\n"
30585- _ASM_EXTABLE(1b, 3b) : : "r" (from));
30586+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
30587
30588 for (i = 0; i < (4096-320)/64; i++) {
30589 __asm__ __volatile__ (
30590- "1: prefetch 320(%0)\n"
30591- "2: movq (%0), %%mm0\n"
30592- " movntq %%mm0, (%1)\n"
30593- " movq 8(%0), %%mm1\n"
30594- " movntq %%mm1, 8(%1)\n"
30595- " movq 16(%0), %%mm2\n"
30596- " movntq %%mm2, 16(%1)\n"
30597- " movq 24(%0), %%mm3\n"
30598- " movntq %%mm3, 24(%1)\n"
30599- " movq 32(%0), %%mm4\n"
30600- " movntq %%mm4, 32(%1)\n"
30601- " movq 40(%0), %%mm5\n"
30602- " movntq %%mm5, 40(%1)\n"
30603- " movq 48(%0), %%mm6\n"
30604- " movntq %%mm6, 48(%1)\n"
30605- " movq 56(%0), %%mm7\n"
30606- " movntq %%mm7, 56(%1)\n"
30607+ "1: prefetch 320(%1)\n"
30608+ "2: movq (%1), %%mm0\n"
30609+ " movntq %%mm0, (%2)\n"
30610+ " movq 8(%1), %%mm1\n"
30611+ " movntq %%mm1, 8(%2)\n"
30612+ " movq 16(%1), %%mm2\n"
30613+ " movntq %%mm2, 16(%2)\n"
30614+ " movq 24(%1), %%mm3\n"
30615+ " movntq %%mm3, 24(%2)\n"
30616+ " movq 32(%1), %%mm4\n"
30617+ " movntq %%mm4, 32(%2)\n"
30618+ " movq 40(%1), %%mm5\n"
30619+ " movntq %%mm5, 40(%2)\n"
30620+ " movq 48(%1), %%mm6\n"
30621+ " movntq %%mm6, 48(%2)\n"
30622+ " movq 56(%1), %%mm7\n"
30623+ " movntq %%mm7, 56(%2)\n"
30624 ".section .fixup, \"ax\"\n"
30625- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30626+ "3:\n"
30627+
30628+#ifdef CONFIG_PAX_KERNEXEC
30629+ " movl %%cr0, %0\n"
30630+ " movl %0, %%eax\n"
30631+ " andl $0xFFFEFFFF, %%eax\n"
30632+ " movl %%eax, %%cr0\n"
30633+#endif
30634+
30635+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30636+
30637+#ifdef CONFIG_PAX_KERNEXEC
30638+ " movl %0, %%cr0\n"
30639+#endif
30640+
30641 " jmp 2b\n"
30642 ".previous\n"
30643- _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
30644+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
30645
30646 from += 64;
30647 to += 64;
30648@@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
30649 static void fast_copy_page(void *to, void *from)
30650 {
30651 int i;
30652+ unsigned long cr0;
30653
30654 kernel_fpu_begin();
30655
30656 __asm__ __volatile__ (
30657- "1: prefetch (%0)\n"
30658- " prefetch 64(%0)\n"
30659- " prefetch 128(%0)\n"
30660- " prefetch 192(%0)\n"
30661- " prefetch 256(%0)\n"
30662+ "1: prefetch (%1)\n"
30663+ " prefetch 64(%1)\n"
30664+ " prefetch 128(%1)\n"
30665+ " prefetch 192(%1)\n"
30666+ " prefetch 256(%1)\n"
30667 "2: \n"
30668 ".section .fixup, \"ax\"\n"
30669- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30670+ "3: \n"
30671+
30672+#ifdef CONFIG_PAX_KERNEXEC
30673+ " movl %%cr0, %0\n"
30674+ " movl %0, %%eax\n"
30675+ " andl $0xFFFEFFFF, %%eax\n"
30676+ " movl %%eax, %%cr0\n"
30677+#endif
30678+
30679+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30680+
30681+#ifdef CONFIG_PAX_KERNEXEC
30682+ " movl %0, %%cr0\n"
30683+#endif
30684+
30685 " jmp 2b\n"
30686 ".previous\n"
30687- _ASM_EXTABLE(1b, 3b) : : "r" (from));
30688+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
30689
30690 for (i = 0; i < 4096/64; i++) {
30691 __asm__ __volatile__ (
30692- "1: prefetch 320(%0)\n"
30693- "2: movq (%0), %%mm0\n"
30694- " movq 8(%0), %%mm1\n"
30695- " movq 16(%0), %%mm2\n"
30696- " movq 24(%0), %%mm3\n"
30697- " movq %%mm0, (%1)\n"
30698- " movq %%mm1, 8(%1)\n"
30699- " movq %%mm2, 16(%1)\n"
30700- " movq %%mm3, 24(%1)\n"
30701- " movq 32(%0), %%mm0\n"
30702- " movq 40(%0), %%mm1\n"
30703- " movq 48(%0), %%mm2\n"
30704- " movq 56(%0), %%mm3\n"
30705- " movq %%mm0, 32(%1)\n"
30706- " movq %%mm1, 40(%1)\n"
30707- " movq %%mm2, 48(%1)\n"
30708- " movq %%mm3, 56(%1)\n"
30709+ "1: prefetch 320(%1)\n"
30710+ "2: movq (%1), %%mm0\n"
30711+ " movq 8(%1), %%mm1\n"
30712+ " movq 16(%1), %%mm2\n"
30713+ " movq 24(%1), %%mm3\n"
30714+ " movq %%mm0, (%2)\n"
30715+ " movq %%mm1, 8(%2)\n"
30716+ " movq %%mm2, 16(%2)\n"
30717+ " movq %%mm3, 24(%2)\n"
30718+ " movq 32(%1), %%mm0\n"
30719+ " movq 40(%1), %%mm1\n"
30720+ " movq 48(%1), %%mm2\n"
30721+ " movq 56(%1), %%mm3\n"
30722+ " movq %%mm0, 32(%2)\n"
30723+ " movq %%mm1, 40(%2)\n"
30724+ " movq %%mm2, 48(%2)\n"
30725+ " movq %%mm3, 56(%2)\n"
30726 ".section .fixup, \"ax\"\n"
30727- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30728+ "3:\n"
30729+
30730+#ifdef CONFIG_PAX_KERNEXEC
30731+ " movl %%cr0, %0\n"
30732+ " movl %0, %%eax\n"
30733+ " andl $0xFFFEFFFF, %%eax\n"
30734+ " movl %%eax, %%cr0\n"
30735+#endif
30736+
30737+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30738+
30739+#ifdef CONFIG_PAX_KERNEXEC
30740+ " movl %0, %%cr0\n"
30741+#endif
30742+
30743 " jmp 2b\n"
30744 ".previous\n"
30745 _ASM_EXTABLE(1b, 3b)
30746- : : "r" (from), "r" (to) : "memory");
30747+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
30748
30749 from += 64;
30750 to += 64;
30751diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
30752index f6d13ee..d789440 100644
30753--- a/arch/x86/lib/msr-reg.S
30754+++ b/arch/x86/lib/msr-reg.S
30755@@ -3,6 +3,7 @@
30756 #include <asm/dwarf2.h>
30757 #include <asm/asm.h>
30758 #include <asm/msr.h>
30759+#include <asm/alternative-asm.h>
30760
30761 #ifdef CONFIG_X86_64
30762 /*
30763@@ -37,6 +38,7 @@ ENTRY(\op\()_safe_regs)
30764 movl %edi, 28(%r10)
30765 popq_cfi %rbp
30766 popq_cfi %rbx
30767+ pax_force_retaddr
30768 ret
30769 3:
30770 CFI_RESTORE_STATE
30771diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
30772index fc6ba17..d4d989d 100644
30773--- a/arch/x86/lib/putuser.S
30774+++ b/arch/x86/lib/putuser.S
30775@@ -16,7 +16,9 @@
30776 #include <asm/errno.h>
30777 #include <asm/asm.h>
30778 #include <asm/smap.h>
30779-
30780+#include <asm/segment.h>
30781+#include <asm/pgtable.h>
30782+#include <asm/alternative-asm.h>
30783
30784 /*
30785 * __put_user_X
30786@@ -30,57 +32,125 @@
30787 * as they get called from within inline assembly.
30788 */
30789
30790-#define ENTER CFI_STARTPROC ; \
30791- GET_THREAD_INFO(%_ASM_BX)
30792-#define EXIT ASM_CLAC ; \
30793- ret ; \
30794+#define ENTER CFI_STARTPROC
30795+#define EXIT ASM_CLAC ; \
30796+ pax_force_retaddr ; \
30797+ ret ; \
30798 CFI_ENDPROC
30799
30800+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30801+#define _DEST %_ASM_CX,%_ASM_BX
30802+#else
30803+#define _DEST %_ASM_CX
30804+#endif
30805+
30806+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
30807+#define __copyuser_seg gs;
30808+#else
30809+#define __copyuser_seg
30810+#endif
30811+
30812 .text
30813 ENTRY(__put_user_1)
30814 ENTER
30815+
30816+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30817+ GET_THREAD_INFO(%_ASM_BX)
30818 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
30819 jae bad_put_user
30820 ASM_STAC
30821-1: movb %al,(%_ASM_CX)
30822+
30823+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30824+ mov pax_user_shadow_base,%_ASM_BX
30825+ cmp %_ASM_BX,%_ASM_CX
30826+ jb 1234f
30827+ xor %ebx,%ebx
30828+1234:
30829+#endif
30830+
30831+#endif
30832+
30833+1: __copyuser_seg movb %al,(_DEST)
30834 xor %eax,%eax
30835 EXIT
30836 ENDPROC(__put_user_1)
30837
30838 ENTRY(__put_user_2)
30839 ENTER
30840+
30841+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30842+ GET_THREAD_INFO(%_ASM_BX)
30843 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
30844 sub $1,%_ASM_BX
30845 cmp %_ASM_BX,%_ASM_CX
30846 jae bad_put_user
30847 ASM_STAC
30848-2: movw %ax,(%_ASM_CX)
30849+
30850+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30851+ mov pax_user_shadow_base,%_ASM_BX
30852+ cmp %_ASM_BX,%_ASM_CX
30853+ jb 1234f
30854+ xor %ebx,%ebx
30855+1234:
30856+#endif
30857+
30858+#endif
30859+
30860+2: __copyuser_seg movw %ax,(_DEST)
30861 xor %eax,%eax
30862 EXIT
30863 ENDPROC(__put_user_2)
30864
30865 ENTRY(__put_user_4)
30866 ENTER
30867+
30868+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30869+ GET_THREAD_INFO(%_ASM_BX)
30870 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
30871 sub $3,%_ASM_BX
30872 cmp %_ASM_BX,%_ASM_CX
30873 jae bad_put_user
30874 ASM_STAC
30875-3: movl %eax,(%_ASM_CX)
30876+
30877+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30878+ mov pax_user_shadow_base,%_ASM_BX
30879+ cmp %_ASM_BX,%_ASM_CX
30880+ jb 1234f
30881+ xor %ebx,%ebx
30882+1234:
30883+#endif
30884+
30885+#endif
30886+
30887+3: __copyuser_seg movl %eax,(_DEST)
30888 xor %eax,%eax
30889 EXIT
30890 ENDPROC(__put_user_4)
30891
30892 ENTRY(__put_user_8)
30893 ENTER
30894+
30895+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30896+ GET_THREAD_INFO(%_ASM_BX)
30897 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
30898 sub $7,%_ASM_BX
30899 cmp %_ASM_BX,%_ASM_CX
30900 jae bad_put_user
30901 ASM_STAC
30902-4: mov %_ASM_AX,(%_ASM_CX)
30903+
30904+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30905+ mov pax_user_shadow_base,%_ASM_BX
30906+ cmp %_ASM_BX,%_ASM_CX
30907+ jb 1234f
30908+ xor %ebx,%ebx
30909+1234:
30910+#endif
30911+
30912+#endif
30913+
30914+4: __copyuser_seg mov %_ASM_AX,(_DEST)
30915 #ifdef CONFIG_X86_32
30916-5: movl %edx,4(%_ASM_CX)
30917+5: __copyuser_seg movl %edx,4(_DEST)
30918 #endif
30919 xor %eax,%eax
30920 EXIT
30921diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
30922index 5dff5f0..cadebf4 100644
30923--- a/arch/x86/lib/rwsem.S
30924+++ b/arch/x86/lib/rwsem.S
30925@@ -94,6 +94,7 @@ ENTRY(call_rwsem_down_read_failed)
30926 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
30927 CFI_RESTORE __ASM_REG(dx)
30928 restore_common_regs
30929+ pax_force_retaddr
30930 ret
30931 CFI_ENDPROC
30932 ENDPROC(call_rwsem_down_read_failed)
30933@@ -104,6 +105,7 @@ ENTRY(call_rwsem_down_write_failed)
30934 movq %rax,%rdi
30935 call rwsem_down_write_failed
30936 restore_common_regs
30937+ pax_force_retaddr
30938 ret
30939 CFI_ENDPROC
30940 ENDPROC(call_rwsem_down_write_failed)
30941@@ -117,7 +119,8 @@ ENTRY(call_rwsem_wake)
30942 movq %rax,%rdi
30943 call rwsem_wake
30944 restore_common_regs
30945-1: ret
30946+1: pax_force_retaddr
30947+ ret
30948 CFI_ENDPROC
30949 ENDPROC(call_rwsem_wake)
30950
30951@@ -131,6 +134,7 @@ ENTRY(call_rwsem_downgrade_wake)
30952 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
30953 CFI_RESTORE __ASM_REG(dx)
30954 restore_common_regs
30955+ pax_force_retaddr
30956 ret
30957 CFI_ENDPROC
30958 ENDPROC(call_rwsem_downgrade_wake)
30959diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
30960index b30b5eb..2b57052 100644
30961--- a/arch/x86/lib/thunk_64.S
30962+++ b/arch/x86/lib/thunk_64.S
30963@@ -9,6 +9,7 @@
30964 #include <asm/dwarf2.h>
30965 #include <asm/calling.h>
30966 #include <asm/asm.h>
30967+#include <asm/alternative-asm.h>
30968
30969 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
30970 .macro THUNK name, func, put_ret_addr_in_rdi=0
30971@@ -16,11 +17,11 @@
30972 \name:
30973 CFI_STARTPROC
30974
30975- /* this one pushes 9 elems, the next one would be %rIP */
30976- SAVE_ARGS
30977+ /* this one pushes 15+1 elems, the next one would be %rIP */
30978+ SAVE_ARGS 8
30979
30980 .if \put_ret_addr_in_rdi
30981- movq_cfi_restore 9*8, rdi
30982+ movq_cfi_restore RIP, rdi
30983 .endif
30984
30985 call \func
30986@@ -47,9 +48,10 @@
30987
30988 /* SAVE_ARGS below is used only for the .cfi directives it contains. */
30989 CFI_STARTPROC
30990- SAVE_ARGS
30991+ SAVE_ARGS 8
30992 restore:
30993- RESTORE_ARGS
30994+ RESTORE_ARGS 1,8
30995+ pax_force_retaddr
30996 ret
30997 CFI_ENDPROC
30998 _ASM_NOKPROBE(restore)
30999diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
31000index e2f5e21..4b22130 100644
31001--- a/arch/x86/lib/usercopy_32.c
31002+++ b/arch/x86/lib/usercopy_32.c
31003@@ -42,11 +42,13 @@ do { \
31004 int __d0; \
31005 might_fault(); \
31006 __asm__ __volatile__( \
31007+ __COPYUSER_SET_ES \
31008 ASM_STAC "\n" \
31009 "0: rep; stosl\n" \
31010 " movl %2,%0\n" \
31011 "1: rep; stosb\n" \
31012 "2: " ASM_CLAC "\n" \
31013+ __COPYUSER_RESTORE_ES \
31014 ".section .fixup,\"ax\"\n" \
31015 "3: lea 0(%2,%0,4),%0\n" \
31016 " jmp 2b\n" \
31017@@ -98,7 +100,7 @@ EXPORT_SYMBOL(__clear_user);
31018
31019 #ifdef CONFIG_X86_INTEL_USERCOPY
31020 static unsigned long
31021-__copy_user_intel(void __user *to, const void *from, unsigned long size)
31022+__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
31023 {
31024 int d0, d1;
31025 __asm__ __volatile__(
31026@@ -110,36 +112,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
31027 " .align 2,0x90\n"
31028 "3: movl 0(%4), %%eax\n"
31029 "4: movl 4(%4), %%edx\n"
31030- "5: movl %%eax, 0(%3)\n"
31031- "6: movl %%edx, 4(%3)\n"
31032+ "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
31033+ "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
31034 "7: movl 8(%4), %%eax\n"
31035 "8: movl 12(%4),%%edx\n"
31036- "9: movl %%eax, 8(%3)\n"
31037- "10: movl %%edx, 12(%3)\n"
31038+ "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
31039+ "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
31040 "11: movl 16(%4), %%eax\n"
31041 "12: movl 20(%4), %%edx\n"
31042- "13: movl %%eax, 16(%3)\n"
31043- "14: movl %%edx, 20(%3)\n"
31044+ "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
31045+ "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
31046 "15: movl 24(%4), %%eax\n"
31047 "16: movl 28(%4), %%edx\n"
31048- "17: movl %%eax, 24(%3)\n"
31049- "18: movl %%edx, 28(%3)\n"
31050+ "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
31051+ "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
31052 "19: movl 32(%4), %%eax\n"
31053 "20: movl 36(%4), %%edx\n"
31054- "21: movl %%eax, 32(%3)\n"
31055- "22: movl %%edx, 36(%3)\n"
31056+ "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
31057+ "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
31058 "23: movl 40(%4), %%eax\n"
31059 "24: movl 44(%4), %%edx\n"
31060- "25: movl %%eax, 40(%3)\n"
31061- "26: movl %%edx, 44(%3)\n"
31062+ "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
31063+ "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
31064 "27: movl 48(%4), %%eax\n"
31065 "28: movl 52(%4), %%edx\n"
31066- "29: movl %%eax, 48(%3)\n"
31067- "30: movl %%edx, 52(%3)\n"
31068+ "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
31069+ "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
31070 "31: movl 56(%4), %%eax\n"
31071 "32: movl 60(%4), %%edx\n"
31072- "33: movl %%eax, 56(%3)\n"
31073- "34: movl %%edx, 60(%3)\n"
31074+ "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
31075+ "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
31076 " addl $-64, %0\n"
31077 " addl $64, %4\n"
31078 " addl $64, %3\n"
31079@@ -149,10 +151,116 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
31080 " shrl $2, %0\n"
31081 " andl $3, %%eax\n"
31082 " cld\n"
31083+ __COPYUSER_SET_ES
31084 "99: rep; movsl\n"
31085 "36: movl %%eax, %0\n"
31086 "37: rep; movsb\n"
31087 "100:\n"
31088+ __COPYUSER_RESTORE_ES
31089+ ".section .fixup,\"ax\"\n"
31090+ "101: lea 0(%%eax,%0,4),%0\n"
31091+ " jmp 100b\n"
31092+ ".previous\n"
31093+ _ASM_EXTABLE(1b,100b)
31094+ _ASM_EXTABLE(2b,100b)
31095+ _ASM_EXTABLE(3b,100b)
31096+ _ASM_EXTABLE(4b,100b)
31097+ _ASM_EXTABLE(5b,100b)
31098+ _ASM_EXTABLE(6b,100b)
31099+ _ASM_EXTABLE(7b,100b)
31100+ _ASM_EXTABLE(8b,100b)
31101+ _ASM_EXTABLE(9b,100b)
31102+ _ASM_EXTABLE(10b,100b)
31103+ _ASM_EXTABLE(11b,100b)
31104+ _ASM_EXTABLE(12b,100b)
31105+ _ASM_EXTABLE(13b,100b)
31106+ _ASM_EXTABLE(14b,100b)
31107+ _ASM_EXTABLE(15b,100b)
31108+ _ASM_EXTABLE(16b,100b)
31109+ _ASM_EXTABLE(17b,100b)
31110+ _ASM_EXTABLE(18b,100b)
31111+ _ASM_EXTABLE(19b,100b)
31112+ _ASM_EXTABLE(20b,100b)
31113+ _ASM_EXTABLE(21b,100b)
31114+ _ASM_EXTABLE(22b,100b)
31115+ _ASM_EXTABLE(23b,100b)
31116+ _ASM_EXTABLE(24b,100b)
31117+ _ASM_EXTABLE(25b,100b)
31118+ _ASM_EXTABLE(26b,100b)
31119+ _ASM_EXTABLE(27b,100b)
31120+ _ASM_EXTABLE(28b,100b)
31121+ _ASM_EXTABLE(29b,100b)
31122+ _ASM_EXTABLE(30b,100b)
31123+ _ASM_EXTABLE(31b,100b)
31124+ _ASM_EXTABLE(32b,100b)
31125+ _ASM_EXTABLE(33b,100b)
31126+ _ASM_EXTABLE(34b,100b)
31127+ _ASM_EXTABLE(35b,100b)
31128+ _ASM_EXTABLE(36b,100b)
31129+ _ASM_EXTABLE(37b,100b)
31130+ _ASM_EXTABLE(99b,101b)
31131+ : "=&c"(size), "=&D" (d0), "=&S" (d1)
31132+ : "1"(to), "2"(from), "0"(size)
31133+ : "eax", "edx", "memory");
31134+ return size;
31135+}
31136+
31137+static unsigned long
31138+__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
31139+{
31140+ int d0, d1;
31141+ __asm__ __volatile__(
31142+ " .align 2,0x90\n"
31143+ "1: "__copyuser_seg" movl 32(%4), %%eax\n"
31144+ " cmpl $67, %0\n"
31145+ " jbe 3f\n"
31146+ "2: "__copyuser_seg" movl 64(%4), %%eax\n"
31147+ " .align 2,0x90\n"
31148+ "3: "__copyuser_seg" movl 0(%4), %%eax\n"
31149+ "4: "__copyuser_seg" movl 4(%4), %%edx\n"
31150+ "5: movl %%eax, 0(%3)\n"
31151+ "6: movl %%edx, 4(%3)\n"
31152+ "7: "__copyuser_seg" movl 8(%4), %%eax\n"
31153+ "8: "__copyuser_seg" movl 12(%4),%%edx\n"
31154+ "9: movl %%eax, 8(%3)\n"
31155+ "10: movl %%edx, 12(%3)\n"
31156+ "11: "__copyuser_seg" movl 16(%4), %%eax\n"
31157+ "12: "__copyuser_seg" movl 20(%4), %%edx\n"
31158+ "13: movl %%eax, 16(%3)\n"
31159+ "14: movl %%edx, 20(%3)\n"
31160+ "15: "__copyuser_seg" movl 24(%4), %%eax\n"
31161+ "16: "__copyuser_seg" movl 28(%4), %%edx\n"
31162+ "17: movl %%eax, 24(%3)\n"
31163+ "18: movl %%edx, 28(%3)\n"
31164+ "19: "__copyuser_seg" movl 32(%4), %%eax\n"
31165+ "20: "__copyuser_seg" movl 36(%4), %%edx\n"
31166+ "21: movl %%eax, 32(%3)\n"
31167+ "22: movl %%edx, 36(%3)\n"
31168+ "23: "__copyuser_seg" movl 40(%4), %%eax\n"
31169+ "24: "__copyuser_seg" movl 44(%4), %%edx\n"
31170+ "25: movl %%eax, 40(%3)\n"
31171+ "26: movl %%edx, 44(%3)\n"
31172+ "27: "__copyuser_seg" movl 48(%4), %%eax\n"
31173+ "28: "__copyuser_seg" movl 52(%4), %%edx\n"
31174+ "29: movl %%eax, 48(%3)\n"
31175+ "30: movl %%edx, 52(%3)\n"
31176+ "31: "__copyuser_seg" movl 56(%4), %%eax\n"
31177+ "32: "__copyuser_seg" movl 60(%4), %%edx\n"
31178+ "33: movl %%eax, 56(%3)\n"
31179+ "34: movl %%edx, 60(%3)\n"
31180+ " addl $-64, %0\n"
31181+ " addl $64, %4\n"
31182+ " addl $64, %3\n"
31183+ " cmpl $63, %0\n"
31184+ " ja 1b\n"
31185+ "35: movl %0, %%eax\n"
31186+ " shrl $2, %0\n"
31187+ " andl $3, %%eax\n"
31188+ " cld\n"
31189+ "99: rep; "__copyuser_seg" movsl\n"
31190+ "36: movl %%eax, %0\n"
31191+ "37: rep; "__copyuser_seg" movsb\n"
31192+ "100:\n"
31193 ".section .fixup,\"ax\"\n"
31194 "101: lea 0(%%eax,%0,4),%0\n"
31195 " jmp 100b\n"
31196@@ -207,41 +315,41 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
31197 int d0, d1;
31198 __asm__ __volatile__(
31199 " .align 2,0x90\n"
31200- "0: movl 32(%4), %%eax\n"
31201+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
31202 " cmpl $67, %0\n"
31203 " jbe 2f\n"
31204- "1: movl 64(%4), %%eax\n"
31205+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
31206 " .align 2,0x90\n"
31207- "2: movl 0(%4), %%eax\n"
31208- "21: movl 4(%4), %%edx\n"
31209+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
31210+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
31211 " movl %%eax, 0(%3)\n"
31212 " movl %%edx, 4(%3)\n"
31213- "3: movl 8(%4), %%eax\n"
31214- "31: movl 12(%4),%%edx\n"
31215+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
31216+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
31217 " movl %%eax, 8(%3)\n"
31218 " movl %%edx, 12(%3)\n"
31219- "4: movl 16(%4), %%eax\n"
31220- "41: movl 20(%4), %%edx\n"
31221+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
31222+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
31223 " movl %%eax, 16(%3)\n"
31224 " movl %%edx, 20(%3)\n"
31225- "10: movl 24(%4), %%eax\n"
31226- "51: movl 28(%4), %%edx\n"
31227+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
31228+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
31229 " movl %%eax, 24(%3)\n"
31230 " movl %%edx, 28(%3)\n"
31231- "11: movl 32(%4), %%eax\n"
31232- "61: movl 36(%4), %%edx\n"
31233+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
31234+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
31235 " movl %%eax, 32(%3)\n"
31236 " movl %%edx, 36(%3)\n"
31237- "12: movl 40(%4), %%eax\n"
31238- "71: movl 44(%4), %%edx\n"
31239+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
31240+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
31241 " movl %%eax, 40(%3)\n"
31242 " movl %%edx, 44(%3)\n"
31243- "13: movl 48(%4), %%eax\n"
31244- "81: movl 52(%4), %%edx\n"
31245+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
31246+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
31247 " movl %%eax, 48(%3)\n"
31248 " movl %%edx, 52(%3)\n"
31249- "14: movl 56(%4), %%eax\n"
31250- "91: movl 60(%4), %%edx\n"
31251+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
31252+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
31253 " movl %%eax, 56(%3)\n"
31254 " movl %%edx, 60(%3)\n"
31255 " addl $-64, %0\n"
31256@@ -253,9 +361,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
31257 " shrl $2, %0\n"
31258 " andl $3, %%eax\n"
31259 " cld\n"
31260- "6: rep; movsl\n"
31261+ "6: rep; "__copyuser_seg" movsl\n"
31262 " movl %%eax,%0\n"
31263- "7: rep; movsb\n"
31264+ "7: rep; "__copyuser_seg" movsb\n"
31265 "8:\n"
31266 ".section .fixup,\"ax\"\n"
31267 "9: lea 0(%%eax,%0,4),%0\n"
31268@@ -305,41 +413,41 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
31269
31270 __asm__ __volatile__(
31271 " .align 2,0x90\n"
31272- "0: movl 32(%4), %%eax\n"
31273+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
31274 " cmpl $67, %0\n"
31275 " jbe 2f\n"
31276- "1: movl 64(%4), %%eax\n"
31277+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
31278 " .align 2,0x90\n"
31279- "2: movl 0(%4), %%eax\n"
31280- "21: movl 4(%4), %%edx\n"
31281+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
31282+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
31283 " movnti %%eax, 0(%3)\n"
31284 " movnti %%edx, 4(%3)\n"
31285- "3: movl 8(%4), %%eax\n"
31286- "31: movl 12(%4),%%edx\n"
31287+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
31288+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
31289 " movnti %%eax, 8(%3)\n"
31290 " movnti %%edx, 12(%3)\n"
31291- "4: movl 16(%4), %%eax\n"
31292- "41: movl 20(%4), %%edx\n"
31293+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
31294+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
31295 " movnti %%eax, 16(%3)\n"
31296 " movnti %%edx, 20(%3)\n"
31297- "10: movl 24(%4), %%eax\n"
31298- "51: movl 28(%4), %%edx\n"
31299+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
31300+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
31301 " movnti %%eax, 24(%3)\n"
31302 " movnti %%edx, 28(%3)\n"
31303- "11: movl 32(%4), %%eax\n"
31304- "61: movl 36(%4), %%edx\n"
31305+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
31306+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
31307 " movnti %%eax, 32(%3)\n"
31308 " movnti %%edx, 36(%3)\n"
31309- "12: movl 40(%4), %%eax\n"
31310- "71: movl 44(%4), %%edx\n"
31311+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
31312+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
31313 " movnti %%eax, 40(%3)\n"
31314 " movnti %%edx, 44(%3)\n"
31315- "13: movl 48(%4), %%eax\n"
31316- "81: movl 52(%4), %%edx\n"
31317+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
31318+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
31319 " movnti %%eax, 48(%3)\n"
31320 " movnti %%edx, 52(%3)\n"
31321- "14: movl 56(%4), %%eax\n"
31322- "91: movl 60(%4), %%edx\n"
31323+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
31324+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
31325 " movnti %%eax, 56(%3)\n"
31326 " movnti %%edx, 60(%3)\n"
31327 " addl $-64, %0\n"
31328@@ -352,9 +460,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
31329 " shrl $2, %0\n"
31330 " andl $3, %%eax\n"
31331 " cld\n"
31332- "6: rep; movsl\n"
31333+ "6: rep; "__copyuser_seg" movsl\n"
31334 " movl %%eax,%0\n"
31335- "7: rep; movsb\n"
31336+ "7: rep; "__copyuser_seg" movsb\n"
31337 "8:\n"
31338 ".section .fixup,\"ax\"\n"
31339 "9: lea 0(%%eax,%0,4),%0\n"
31340@@ -399,41 +507,41 @@ static unsigned long __copy_user_intel_nocache(void *to,
31341
31342 __asm__ __volatile__(
31343 " .align 2,0x90\n"
31344- "0: movl 32(%4), %%eax\n"
31345+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
31346 " cmpl $67, %0\n"
31347 " jbe 2f\n"
31348- "1: movl 64(%4), %%eax\n"
31349+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
31350 " .align 2,0x90\n"
31351- "2: movl 0(%4), %%eax\n"
31352- "21: movl 4(%4), %%edx\n"
31353+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
31354+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
31355 " movnti %%eax, 0(%3)\n"
31356 " movnti %%edx, 4(%3)\n"
31357- "3: movl 8(%4), %%eax\n"
31358- "31: movl 12(%4),%%edx\n"
31359+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
31360+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
31361 " movnti %%eax, 8(%3)\n"
31362 " movnti %%edx, 12(%3)\n"
31363- "4: movl 16(%4), %%eax\n"
31364- "41: movl 20(%4), %%edx\n"
31365+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
31366+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
31367 " movnti %%eax, 16(%3)\n"
31368 " movnti %%edx, 20(%3)\n"
31369- "10: movl 24(%4), %%eax\n"
31370- "51: movl 28(%4), %%edx\n"
31371+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
31372+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
31373 " movnti %%eax, 24(%3)\n"
31374 " movnti %%edx, 28(%3)\n"
31375- "11: movl 32(%4), %%eax\n"
31376- "61: movl 36(%4), %%edx\n"
31377+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
31378+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
31379 " movnti %%eax, 32(%3)\n"
31380 " movnti %%edx, 36(%3)\n"
31381- "12: movl 40(%4), %%eax\n"
31382- "71: movl 44(%4), %%edx\n"
31383+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
31384+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
31385 " movnti %%eax, 40(%3)\n"
31386 " movnti %%edx, 44(%3)\n"
31387- "13: movl 48(%4), %%eax\n"
31388- "81: movl 52(%4), %%edx\n"
31389+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
31390+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
31391 " movnti %%eax, 48(%3)\n"
31392 " movnti %%edx, 52(%3)\n"
31393- "14: movl 56(%4), %%eax\n"
31394- "91: movl 60(%4), %%edx\n"
31395+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
31396+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
31397 " movnti %%eax, 56(%3)\n"
31398 " movnti %%edx, 60(%3)\n"
31399 " addl $-64, %0\n"
31400@@ -446,9 +554,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
31401 " shrl $2, %0\n"
31402 " andl $3, %%eax\n"
31403 " cld\n"
31404- "6: rep; movsl\n"
31405+ "6: rep; "__copyuser_seg" movsl\n"
31406 " movl %%eax,%0\n"
31407- "7: rep; movsb\n"
31408+ "7: rep; "__copyuser_seg" movsb\n"
31409 "8:\n"
31410 ".section .fixup,\"ax\"\n"
31411 "9: lea 0(%%eax,%0,4),%0\n"
31412@@ -488,32 +596,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
31413 */
31414 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
31415 unsigned long size);
31416-unsigned long __copy_user_intel(void __user *to, const void *from,
31417+unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
31418+ unsigned long size);
31419+unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
31420 unsigned long size);
31421 unsigned long __copy_user_zeroing_intel_nocache(void *to,
31422 const void __user *from, unsigned long size);
31423 #endif /* CONFIG_X86_INTEL_USERCOPY */
31424
31425 /* Generic arbitrary sized copy. */
31426-#define __copy_user(to, from, size) \
31427+#define __copy_user(to, from, size, prefix, set, restore) \
31428 do { \
31429 int __d0, __d1, __d2; \
31430 __asm__ __volatile__( \
31431+ set \
31432 " cmp $7,%0\n" \
31433 " jbe 1f\n" \
31434 " movl %1,%0\n" \
31435 " negl %0\n" \
31436 " andl $7,%0\n" \
31437 " subl %0,%3\n" \
31438- "4: rep; movsb\n" \
31439+ "4: rep; "prefix"movsb\n" \
31440 " movl %3,%0\n" \
31441 " shrl $2,%0\n" \
31442 " andl $3,%3\n" \
31443 " .align 2,0x90\n" \
31444- "0: rep; movsl\n" \
31445+ "0: rep; "prefix"movsl\n" \
31446 " movl %3,%0\n" \
31447- "1: rep; movsb\n" \
31448+ "1: rep; "prefix"movsb\n" \
31449 "2:\n" \
31450+ restore \
31451 ".section .fixup,\"ax\"\n" \
31452 "5: addl %3,%0\n" \
31453 " jmp 2b\n" \
31454@@ -538,14 +650,14 @@ do { \
31455 " negl %0\n" \
31456 " andl $7,%0\n" \
31457 " subl %0,%3\n" \
31458- "4: rep; movsb\n" \
31459+ "4: rep; "__copyuser_seg"movsb\n" \
31460 " movl %3,%0\n" \
31461 " shrl $2,%0\n" \
31462 " andl $3,%3\n" \
31463 " .align 2,0x90\n" \
31464- "0: rep; movsl\n" \
31465+ "0: rep; "__copyuser_seg"movsl\n" \
31466 " movl %3,%0\n" \
31467- "1: rep; movsb\n" \
31468+ "1: rep; "__copyuser_seg"movsb\n" \
31469 "2:\n" \
31470 ".section .fixup,\"ax\"\n" \
31471 "5: addl %3,%0\n" \
31472@@ -572,9 +684,9 @@ unsigned long __copy_to_user_ll(void __user *to, const void *from,
31473 {
31474 stac();
31475 if (movsl_is_ok(to, from, n))
31476- __copy_user(to, from, n);
31477+ __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
31478 else
31479- n = __copy_user_intel(to, from, n);
31480+ n = __generic_copy_to_user_intel(to, from, n);
31481 clac();
31482 return n;
31483 }
31484@@ -598,10 +710,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
31485 {
31486 stac();
31487 if (movsl_is_ok(to, from, n))
31488- __copy_user(to, from, n);
31489+ __copy_user(to, from, n, __copyuser_seg, "", "");
31490 else
31491- n = __copy_user_intel((void __user *)to,
31492- (const void *)from, n);
31493+ n = __generic_copy_from_user_intel(to, from, n);
31494 clac();
31495 return n;
31496 }
31497@@ -632,58 +743,38 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
31498 if (n > 64 && cpu_has_xmm2)
31499 n = __copy_user_intel_nocache(to, from, n);
31500 else
31501- __copy_user(to, from, n);
31502+ __copy_user(to, from, n, __copyuser_seg, "", "");
31503 #else
31504- __copy_user(to, from, n);
31505+ __copy_user(to, from, n, __copyuser_seg, "", "");
31506 #endif
31507 clac();
31508 return n;
31509 }
31510 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
31511
31512-/**
31513- * copy_to_user: - Copy a block of data into user space.
31514- * @to: Destination address, in user space.
31515- * @from: Source address, in kernel space.
31516- * @n: Number of bytes to copy.
31517- *
31518- * Context: User context only. This function may sleep.
31519- *
31520- * Copy data from kernel space to user space.
31521- *
31522- * Returns number of bytes that could not be copied.
31523- * On success, this will be zero.
31524- */
31525-unsigned long _copy_to_user(void __user *to, const void *from, unsigned n)
31526+#ifdef CONFIG_PAX_MEMORY_UDEREF
31527+void __set_fs(mm_segment_t x)
31528 {
31529- if (access_ok(VERIFY_WRITE, to, n))
31530- n = __copy_to_user(to, from, n);
31531- return n;
31532+ switch (x.seg) {
31533+ case 0:
31534+ loadsegment(gs, 0);
31535+ break;
31536+ case TASK_SIZE_MAX:
31537+ loadsegment(gs, __USER_DS);
31538+ break;
31539+ case -1UL:
31540+ loadsegment(gs, __KERNEL_DS);
31541+ break;
31542+ default:
31543+ BUG();
31544+ }
31545 }
31546-EXPORT_SYMBOL(_copy_to_user);
31547+EXPORT_SYMBOL(__set_fs);
31548
31549-/**
31550- * copy_from_user: - Copy a block of data from user space.
31551- * @to: Destination address, in kernel space.
31552- * @from: Source address, in user space.
31553- * @n: Number of bytes to copy.
31554- *
31555- * Context: User context only. This function may sleep.
31556- *
31557- * Copy data from user space to kernel space.
31558- *
31559- * Returns number of bytes that could not be copied.
31560- * On success, this will be zero.
31561- *
31562- * If some data could not be copied, this function will pad the copied
31563- * data to the requested size using zero bytes.
31564- */
31565-unsigned long _copy_from_user(void *to, const void __user *from, unsigned n)
31566+void set_fs(mm_segment_t x)
31567 {
31568- if (access_ok(VERIFY_READ, from, n))
31569- n = __copy_from_user(to, from, n);
31570- else
31571- memset(to, 0, n);
31572- return n;
31573+ current_thread_info()->addr_limit = x;
31574+ __set_fs(x);
31575 }
31576-EXPORT_SYMBOL(_copy_from_user);
31577+EXPORT_SYMBOL(set_fs);
31578+#endif
31579diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
31580index c905e89..01ab928 100644
31581--- a/arch/x86/lib/usercopy_64.c
31582+++ b/arch/x86/lib/usercopy_64.c
31583@@ -18,6 +18,7 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
31584 might_fault();
31585 /* no memory constraint because it doesn't change any memory gcc knows
31586 about */
31587+ pax_open_userland();
31588 stac();
31589 asm volatile(
31590 " testq %[size8],%[size8]\n"
31591@@ -39,9 +40,10 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
31592 _ASM_EXTABLE(0b,3b)
31593 _ASM_EXTABLE(1b,2b)
31594 : [size8] "=&c"(size), [dst] "=&D" (__d0)
31595- : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(addr),
31596+ : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(____m(addr)),
31597 [zero] "r" (0UL), [eight] "r" (8UL));
31598 clac();
31599+ pax_close_userland();
31600 return size;
31601 }
31602 EXPORT_SYMBOL(__clear_user);
31603@@ -54,12 +56,11 @@ unsigned long clear_user(void __user *to, unsigned long n)
31604 }
31605 EXPORT_SYMBOL(clear_user);
31606
31607-unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
31608+unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
31609 {
31610- if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
31611- return copy_user_generic((__force void *)to, (__force void *)from, len);
31612- }
31613- return len;
31614+ if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len))
31615+ return copy_user_generic((void __force_kernel *)____m(to), (void __force_kernel *)____m(from), len);
31616+ return len;
31617 }
31618 EXPORT_SYMBOL(copy_in_user);
31619
31620@@ -69,11 +70,13 @@ EXPORT_SYMBOL(copy_in_user);
31621 * it is not necessary to optimize tail handling.
31622 */
31623 __visible unsigned long
31624-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
31625+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
31626 {
31627 char c;
31628 unsigned zero_len;
31629
31630+ clac();
31631+ pax_close_userland();
31632 for (; len; --len, to++) {
31633 if (__get_user_nocheck(c, from++, sizeof(char)))
31634 break;
31635@@ -84,6 +87,5 @@ copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
31636 for (c = 0, zero_len = len; zerorest && zero_len; --zero_len)
31637 if (__put_user_nocheck(c, to++, sizeof(char)))
31638 break;
31639- clac();
31640 return len;
31641 }
31642diff --git a/arch/x86/mm/Makefile b/arch/x86/mm/Makefile
31643index 6a19ad9..1c48f9a 100644
31644--- a/arch/x86/mm/Makefile
31645+++ b/arch/x86/mm/Makefile
31646@@ -30,3 +30,7 @@ obj-$(CONFIG_ACPI_NUMA) += srat.o
31647 obj-$(CONFIG_NUMA_EMU) += numa_emulation.o
31648
31649 obj-$(CONFIG_MEMTEST) += memtest.o
31650+
31651+quote:="
31652+obj-$(CONFIG_X86_64) += uderef_64.o
31653+CFLAGS_uderef_64.o := $(subst $(quote),,$(CONFIG_ARCH_HWEIGHT_CFLAGS))
31654diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
31655index 903ec1e..c4166b2 100644
31656--- a/arch/x86/mm/extable.c
31657+++ b/arch/x86/mm/extable.c
31658@@ -6,12 +6,24 @@
31659 static inline unsigned long
31660 ex_insn_addr(const struct exception_table_entry *x)
31661 {
31662- return (unsigned long)&x->insn + x->insn;
31663+ unsigned long reloc = 0;
31664+
31665+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
31666+ reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
31667+#endif
31668+
31669+ return (unsigned long)&x->insn + x->insn + reloc;
31670 }
31671 static inline unsigned long
31672 ex_fixup_addr(const struct exception_table_entry *x)
31673 {
31674- return (unsigned long)&x->fixup + x->fixup;
31675+ unsigned long reloc = 0;
31676+
31677+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
31678+ reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
31679+#endif
31680+
31681+ return (unsigned long)&x->fixup + x->fixup + reloc;
31682 }
31683
31684 int fixup_exception(struct pt_regs *regs)
31685@@ -20,7 +32,7 @@ int fixup_exception(struct pt_regs *regs)
31686 unsigned long new_ip;
31687
31688 #ifdef CONFIG_PNPBIOS
31689- if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
31690+ if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
31691 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
31692 extern u32 pnp_bios_is_utter_crap;
31693 pnp_bios_is_utter_crap = 1;
31694@@ -145,6 +157,13 @@ void sort_extable(struct exception_table_entry *start,
31695 i += 4;
31696 p->fixup -= i;
31697 i += 4;
31698+
31699+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
31700+ BUILD_BUG_ON(!IS_ENABLED(CONFIG_BUILDTIME_EXTABLE_SORT));
31701+ p->insn -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
31702+ p->fixup -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
31703+#endif
31704+
31705 }
31706 }
31707
31708diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
31709index d973e61..fb868e9 100644
31710--- a/arch/x86/mm/fault.c
31711+++ b/arch/x86/mm/fault.c
31712@@ -13,12 +13,19 @@
31713 #include <linux/hugetlb.h> /* hstate_index_to_shift */
31714 #include <linux/prefetch.h> /* prefetchw */
31715 #include <linux/context_tracking.h> /* exception_enter(), ... */
31716+#include <linux/unistd.h>
31717+#include <linux/compiler.h>
31718
31719 #include <asm/traps.h> /* dotraplinkage, ... */
31720 #include <asm/pgalloc.h> /* pgd_*(), ... */
31721 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
31722 #include <asm/fixmap.h> /* VSYSCALL_ADDR */
31723 #include <asm/vsyscall.h> /* emulate_vsyscall */
31724+#include <asm/tlbflush.h>
31725+
31726+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
31727+#include <asm/stacktrace.h>
31728+#endif
31729
31730 #define CREATE_TRACE_POINTS
31731 #include <asm/trace/exceptions.h>
31732@@ -59,7 +66,7 @@ static nokprobe_inline int kprobes_fault(struct pt_regs *regs)
31733 int ret = 0;
31734
31735 /* kprobe_running() needs smp_processor_id() */
31736- if (kprobes_built_in() && !user_mode_vm(regs)) {
31737+ if (kprobes_built_in() && !user_mode(regs)) {
31738 preempt_disable();
31739 if (kprobe_running() && kprobe_fault_handler(regs, 14))
31740 ret = 1;
31741@@ -120,7 +127,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
31742 return !instr_lo || (instr_lo>>1) == 1;
31743 case 0x00:
31744 /* Prefetch instruction is 0x0F0D or 0x0F18 */
31745- if (probe_kernel_address(instr, opcode))
31746+ if (user_mode(regs)) {
31747+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
31748+ return 0;
31749+ } else if (probe_kernel_address(instr, opcode))
31750 return 0;
31751
31752 *prefetch = (instr_lo == 0xF) &&
31753@@ -154,7 +164,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
31754 while (instr < max_instr) {
31755 unsigned char opcode;
31756
31757- if (probe_kernel_address(instr, opcode))
31758+ if (user_mode(regs)) {
31759+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
31760+ break;
31761+ } else if (probe_kernel_address(instr, opcode))
31762 break;
31763
31764 instr++;
31765@@ -185,6 +198,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
31766 force_sig_info(si_signo, &info, tsk);
31767 }
31768
31769+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
31770+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
31771+#endif
31772+
31773+#ifdef CONFIG_PAX_EMUTRAMP
31774+static int pax_handle_fetch_fault(struct pt_regs *regs);
31775+#endif
31776+
31777+#ifdef CONFIG_PAX_PAGEEXEC
31778+static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
31779+{
31780+ pgd_t *pgd;
31781+ pud_t *pud;
31782+ pmd_t *pmd;
31783+
31784+ pgd = pgd_offset(mm, address);
31785+ if (!pgd_present(*pgd))
31786+ return NULL;
31787+ pud = pud_offset(pgd, address);
31788+ if (!pud_present(*pud))
31789+ return NULL;
31790+ pmd = pmd_offset(pud, address);
31791+ if (!pmd_present(*pmd))
31792+ return NULL;
31793+ return pmd;
31794+}
31795+#endif
31796+
31797 DEFINE_SPINLOCK(pgd_lock);
31798 LIST_HEAD(pgd_list);
31799
31800@@ -235,10 +276,27 @@ void vmalloc_sync_all(void)
31801 for (address = VMALLOC_START & PMD_MASK;
31802 address >= TASK_SIZE && address < FIXADDR_TOP;
31803 address += PMD_SIZE) {
31804+
31805+#ifdef CONFIG_PAX_PER_CPU_PGD
31806+ unsigned long cpu;
31807+#else
31808 struct page *page;
31809+#endif
31810
31811 spin_lock(&pgd_lock);
31812+
31813+#ifdef CONFIG_PAX_PER_CPU_PGD
31814+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
31815+ pgd_t *pgd = get_cpu_pgd(cpu, user);
31816+ pmd_t *ret;
31817+
31818+ ret = vmalloc_sync_one(pgd, address);
31819+ if (!ret)
31820+ break;
31821+ pgd = get_cpu_pgd(cpu, kernel);
31822+#else
31823 list_for_each_entry(page, &pgd_list, lru) {
31824+ pgd_t *pgd;
31825 spinlock_t *pgt_lock;
31826 pmd_t *ret;
31827
31828@@ -246,8 +304,14 @@ void vmalloc_sync_all(void)
31829 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
31830
31831 spin_lock(pgt_lock);
31832- ret = vmalloc_sync_one(page_address(page), address);
31833+ pgd = page_address(page);
31834+#endif
31835+
31836+ ret = vmalloc_sync_one(pgd, address);
31837+
31838+#ifndef CONFIG_PAX_PER_CPU_PGD
31839 spin_unlock(pgt_lock);
31840+#endif
31841
31842 if (!ret)
31843 break;
31844@@ -281,6 +345,12 @@ static noinline int vmalloc_fault(unsigned long address)
31845 * an interrupt in the middle of a task switch..
31846 */
31847 pgd_paddr = read_cr3();
31848+
31849+#ifdef CONFIG_PAX_PER_CPU_PGD
31850+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id(), kernel)) != (pgd_paddr & __PHYSICAL_MASK));
31851+ vmalloc_sync_one(__va(pgd_paddr + PAGE_SIZE), address);
31852+#endif
31853+
31854 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
31855 if (!pmd_k)
31856 return -1;
31857@@ -377,11 +447,25 @@ static noinline int vmalloc_fault(unsigned long address)
31858 * happen within a race in page table update. In the later
31859 * case just flush:
31860 */
31861- pgd = pgd_offset(current->active_mm, address);
31862+
31863 pgd_ref = pgd_offset_k(address);
31864 if (pgd_none(*pgd_ref))
31865 return -1;
31866
31867+#ifdef CONFIG_PAX_PER_CPU_PGD
31868+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id(), kernel)) != (read_cr3() & __PHYSICAL_MASK));
31869+ pgd = pgd_offset_cpu(smp_processor_id(), user, address);
31870+ if (pgd_none(*pgd)) {
31871+ set_pgd(pgd, *pgd_ref);
31872+ arch_flush_lazy_mmu_mode();
31873+ } else {
31874+ BUG_ON(pgd_page_vaddr(*pgd) != pgd_page_vaddr(*pgd_ref));
31875+ }
31876+ pgd = pgd_offset_cpu(smp_processor_id(), kernel, address);
31877+#else
31878+ pgd = pgd_offset(current->active_mm, address);
31879+#endif
31880+
31881 if (pgd_none(*pgd)) {
31882 set_pgd(pgd, *pgd_ref);
31883 arch_flush_lazy_mmu_mode();
31884@@ -548,7 +632,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
31885 static int is_errata100(struct pt_regs *regs, unsigned long address)
31886 {
31887 #ifdef CONFIG_X86_64
31888- if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
31889+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
31890 return 1;
31891 #endif
31892 return 0;
31893@@ -575,9 +659,9 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
31894 }
31895
31896 static const char nx_warning[] = KERN_CRIT
31897-"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
31898+"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
31899 static const char smep_warning[] = KERN_CRIT
31900-"unable to execute userspace code (SMEP?) (uid: %d)\n";
31901+"unable to execute userspace code (SMEP?) (uid: %d, task: %s, pid: %d)\n";
31902
31903 static void
31904 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
31905@@ -586,7 +670,7 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
31906 if (!oops_may_print())
31907 return;
31908
31909- if (error_code & PF_INSTR) {
31910+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
31911 unsigned int level;
31912 pgd_t *pgd;
31913 pte_t *pte;
31914@@ -597,13 +681,25 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
31915 pte = lookup_address_in_pgd(pgd, address, &level);
31916
31917 if (pte && pte_present(*pte) && !pte_exec(*pte))
31918- printk(nx_warning, from_kuid(&init_user_ns, current_uid()));
31919+ printk(nx_warning, from_kuid_munged(&init_user_ns, current_uid()), current->comm, task_pid_nr(current));
31920 if (pte && pte_present(*pte) && pte_exec(*pte) &&
31921 (pgd_flags(*pgd) & _PAGE_USER) &&
31922 (read_cr4() & X86_CR4_SMEP))
31923- printk(smep_warning, from_kuid(&init_user_ns, current_uid()));
31924+ printk(smep_warning, from_kuid(&init_user_ns, current_uid()), current->comm, task_pid_nr(current));
31925 }
31926
31927+#ifdef CONFIG_PAX_KERNEXEC
31928+ if (init_mm.start_code <= address && address < init_mm.end_code) {
31929+ if (current->signal->curr_ip)
31930+ printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
31931+ &current->signal->curr_ip, current->comm, task_pid_nr(current),
31932+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
31933+ else
31934+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
31935+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
31936+ }
31937+#endif
31938+
31939 printk(KERN_ALERT "BUG: unable to handle kernel ");
31940 if (address < PAGE_SIZE)
31941 printk(KERN_CONT "NULL pointer dereference");
31942@@ -782,6 +878,22 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
31943 return;
31944 }
31945 #endif
31946+
31947+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
31948+ if (pax_is_fetch_fault(regs, error_code, address)) {
31949+
31950+#ifdef CONFIG_PAX_EMUTRAMP
31951+ switch (pax_handle_fetch_fault(regs)) {
31952+ case 2:
31953+ return;
31954+ }
31955+#endif
31956+
31957+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
31958+ do_group_exit(SIGKILL);
31959+ }
31960+#endif
31961+
31962 /* Kernel addresses are always protection faults: */
31963 if (address >= TASK_SIZE)
31964 error_code |= PF_PROT;
31965@@ -867,7 +979,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
31966 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
31967 printk(KERN_ERR
31968 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
31969- tsk->comm, tsk->pid, address);
31970+ tsk->comm, task_pid_nr(tsk), address);
31971 code = BUS_MCEERR_AR;
31972 }
31973 #endif
31974@@ -921,6 +1033,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
31975 return 1;
31976 }
31977
31978+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
31979+static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
31980+{
31981+ pte_t *pte;
31982+ pmd_t *pmd;
31983+ spinlock_t *ptl;
31984+ unsigned char pte_mask;
31985+
31986+ if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
31987+ !(mm->pax_flags & MF_PAX_PAGEEXEC))
31988+ return 0;
31989+
31990+ /* PaX: it's our fault, let's handle it if we can */
31991+
31992+ /* PaX: take a look at read faults before acquiring any locks */
31993+ if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
31994+ /* instruction fetch attempt from a protected page in user mode */
31995+ up_read(&mm->mmap_sem);
31996+
31997+#ifdef CONFIG_PAX_EMUTRAMP
31998+ switch (pax_handle_fetch_fault(regs)) {
31999+ case 2:
32000+ return 1;
32001+ }
32002+#endif
32003+
32004+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
32005+ do_group_exit(SIGKILL);
32006+ }
32007+
32008+ pmd = pax_get_pmd(mm, address);
32009+ if (unlikely(!pmd))
32010+ return 0;
32011+
32012+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
32013+ if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
32014+ pte_unmap_unlock(pte, ptl);
32015+ return 0;
32016+ }
32017+
32018+ if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
32019+ /* write attempt to a protected page in user mode */
32020+ pte_unmap_unlock(pte, ptl);
32021+ return 0;
32022+ }
32023+
32024+#ifdef CONFIG_SMP
32025+ if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
32026+#else
32027+ if (likely(address > get_limit(regs->cs)))
32028+#endif
32029+ {
32030+ set_pte(pte, pte_mkread(*pte));
32031+ __flush_tlb_one(address);
32032+ pte_unmap_unlock(pte, ptl);
32033+ up_read(&mm->mmap_sem);
32034+ return 1;
32035+ }
32036+
32037+ pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
32038+
32039+ /*
32040+ * PaX: fill DTLB with user rights and retry
32041+ */
32042+ __asm__ __volatile__ (
32043+ "orb %2,(%1)\n"
32044+#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
32045+/*
32046+ * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
32047+ * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
32048+ * page fault when examined during a TLB load attempt. this is true not only
32049+ * for PTEs holding a non-present entry but also present entries that will
32050+ * raise a page fault (such as those set up by PaX, or the copy-on-write
32051+ * mechanism). in effect it means that we do *not* need to flush the TLBs
32052+ * for our target pages since their PTEs are simply not in the TLBs at all.
32053+
32054+ * the best thing in omitting it is that we gain around 15-20% speed in the
32055+ * fast path of the page fault handler and can get rid of tracing since we
32056+ * can no longer flush unintended entries.
32057+ */
32058+ "invlpg (%0)\n"
32059+#endif
32060+ __copyuser_seg"testb $0,(%0)\n"
32061+ "xorb %3,(%1)\n"
32062+ :
32063+ : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
32064+ : "memory", "cc");
32065+ pte_unmap_unlock(pte, ptl);
32066+ up_read(&mm->mmap_sem);
32067+ return 1;
32068+}
32069+#endif
32070+
32071 /*
32072 * Handle a spurious fault caused by a stale TLB entry.
32073 *
32074@@ -1006,6 +1211,9 @@ int show_unhandled_signals = 1;
32075 static inline int
32076 access_error(unsigned long error_code, struct vm_area_struct *vma)
32077 {
32078+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
32079+ return 1;
32080+
32081 if (error_code & PF_WRITE) {
32082 /* write, present and write, not present: */
32083 if (unlikely(!(vma->vm_flags & VM_WRITE)))
32084@@ -1040,7 +1248,7 @@ static inline bool smap_violation(int error_code, struct pt_regs *regs)
32085 if (error_code & PF_USER)
32086 return false;
32087
32088- if (!user_mode_vm(regs) && (regs->flags & X86_EFLAGS_AC))
32089+ if (!user_mode(regs) && (regs->flags & X86_EFLAGS_AC))
32090 return false;
32091
32092 return true;
32093@@ -1068,6 +1276,22 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code,
32094 tsk = current;
32095 mm = tsk->mm;
32096
32097+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
32098+ if (!user_mode(regs) && address < 2 * pax_user_shadow_base) {
32099+ if (!search_exception_tables(regs->ip)) {
32100+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
32101+ bad_area_nosemaphore(regs, error_code, address);
32102+ return;
32103+ }
32104+ if (address < pax_user_shadow_base) {
32105+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
32106+ printk(KERN_ERR "PAX: faulting IP: %pS\n", (void *)regs->ip);
32107+ show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
32108+ } else
32109+ address -= pax_user_shadow_base;
32110+ }
32111+#endif
32112+
32113 /*
32114 * Detect and handle instructions that would cause a page fault for
32115 * both a tracked kernel page and a userspace page.
32116@@ -1145,7 +1369,7 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code,
32117 * User-mode registers count as a user access even for any
32118 * potential system fault or CPU buglet:
32119 */
32120- if (user_mode_vm(regs)) {
32121+ if (user_mode(regs)) {
32122 local_irq_enable();
32123 error_code |= PF_USER;
32124 flags |= FAULT_FLAG_USER;
32125@@ -1192,6 +1416,11 @@ retry:
32126 might_sleep();
32127 }
32128
32129+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
32130+ if (pax_handle_pageexec_fault(regs, mm, address, error_code))
32131+ return;
32132+#endif
32133+
32134 vma = find_vma(mm, address);
32135 if (unlikely(!vma)) {
32136 bad_area(regs, error_code, address);
32137@@ -1203,18 +1432,24 @@ retry:
32138 bad_area(regs, error_code, address);
32139 return;
32140 }
32141- if (error_code & PF_USER) {
32142- /*
32143- * Accessing the stack below %sp is always a bug.
32144- * The large cushion allows instructions like enter
32145- * and pusha to work. ("enter $65535, $31" pushes
32146- * 32 pointers and then decrements %sp by 65535.)
32147- */
32148- if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
32149- bad_area(regs, error_code, address);
32150- return;
32151- }
32152+ /*
32153+ * Accessing the stack below %sp is always a bug.
32154+ * The large cushion allows instructions like enter
32155+ * and pusha to work. ("enter $65535, $31" pushes
32156+ * 32 pointers and then decrements %sp by 65535.)
32157+ */
32158+ if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
32159+ bad_area(regs, error_code, address);
32160+ return;
32161 }
32162+
32163+#ifdef CONFIG_PAX_SEGMEXEC
32164+ if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
32165+ bad_area(regs, error_code, address);
32166+ return;
32167+ }
32168+#endif
32169+
32170 if (unlikely(expand_stack(vma, address))) {
32171 bad_area(regs, error_code, address);
32172 return;
32173@@ -1331,3 +1566,292 @@ trace_do_page_fault(struct pt_regs *regs, unsigned long error_code)
32174 }
32175 NOKPROBE_SYMBOL(trace_do_page_fault);
32176 #endif /* CONFIG_TRACING */
32177+
32178+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
32179+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
32180+{
32181+ struct mm_struct *mm = current->mm;
32182+ unsigned long ip = regs->ip;
32183+
32184+ if (v8086_mode(regs))
32185+ ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
32186+
32187+#ifdef CONFIG_PAX_PAGEEXEC
32188+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
32189+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
32190+ return true;
32191+ if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
32192+ return true;
32193+ return false;
32194+ }
32195+#endif
32196+
32197+#ifdef CONFIG_PAX_SEGMEXEC
32198+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
32199+ if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
32200+ return true;
32201+ return false;
32202+ }
32203+#endif
32204+
32205+ return false;
32206+}
32207+#endif
32208+
32209+#ifdef CONFIG_PAX_EMUTRAMP
32210+static int pax_handle_fetch_fault_32(struct pt_regs *regs)
32211+{
32212+ int err;
32213+
32214+ do { /* PaX: libffi trampoline emulation */
32215+ unsigned char mov, jmp;
32216+ unsigned int addr1, addr2;
32217+
32218+#ifdef CONFIG_X86_64
32219+ if ((regs->ip + 9) >> 32)
32220+ break;
32221+#endif
32222+
32223+ err = get_user(mov, (unsigned char __user *)regs->ip);
32224+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
32225+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
32226+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
32227+
32228+ if (err)
32229+ break;
32230+
32231+ if (mov == 0xB8 && jmp == 0xE9) {
32232+ regs->ax = addr1;
32233+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
32234+ return 2;
32235+ }
32236+ } while (0);
32237+
32238+ do { /* PaX: gcc trampoline emulation #1 */
32239+ unsigned char mov1, mov2;
32240+ unsigned short jmp;
32241+ unsigned int addr1, addr2;
32242+
32243+#ifdef CONFIG_X86_64
32244+ if ((regs->ip + 11) >> 32)
32245+ break;
32246+#endif
32247+
32248+ err = get_user(mov1, (unsigned char __user *)regs->ip);
32249+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
32250+ err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
32251+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
32252+ err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
32253+
32254+ if (err)
32255+ break;
32256+
32257+ if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
32258+ regs->cx = addr1;
32259+ regs->ax = addr2;
32260+ regs->ip = addr2;
32261+ return 2;
32262+ }
32263+ } while (0);
32264+
32265+ do { /* PaX: gcc trampoline emulation #2 */
32266+ unsigned char mov, jmp;
32267+ unsigned int addr1, addr2;
32268+
32269+#ifdef CONFIG_X86_64
32270+ if ((regs->ip + 9) >> 32)
32271+ break;
32272+#endif
32273+
32274+ err = get_user(mov, (unsigned char __user *)regs->ip);
32275+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
32276+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
32277+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
32278+
32279+ if (err)
32280+ break;
32281+
32282+ if (mov == 0xB9 && jmp == 0xE9) {
32283+ regs->cx = addr1;
32284+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
32285+ return 2;
32286+ }
32287+ } while (0);
32288+
32289+ return 1; /* PaX in action */
32290+}
32291+
32292+#ifdef CONFIG_X86_64
32293+static int pax_handle_fetch_fault_64(struct pt_regs *regs)
32294+{
32295+ int err;
32296+
32297+ do { /* PaX: libffi trampoline emulation */
32298+ unsigned short mov1, mov2, jmp1;
32299+ unsigned char stcclc, jmp2;
32300+ unsigned long addr1, addr2;
32301+
32302+ err = get_user(mov1, (unsigned short __user *)regs->ip);
32303+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
32304+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
32305+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
32306+ err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
32307+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
32308+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
32309+
32310+ if (err)
32311+ break;
32312+
32313+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
32314+ regs->r11 = addr1;
32315+ regs->r10 = addr2;
32316+ if (stcclc == 0xF8)
32317+ regs->flags &= ~X86_EFLAGS_CF;
32318+ else
32319+ regs->flags |= X86_EFLAGS_CF;
32320+ regs->ip = addr1;
32321+ return 2;
32322+ }
32323+ } while (0);
32324+
32325+ do { /* PaX: gcc trampoline emulation #1 */
32326+ unsigned short mov1, mov2, jmp1;
32327+ unsigned char jmp2;
32328+ unsigned int addr1;
32329+ unsigned long addr2;
32330+
32331+ err = get_user(mov1, (unsigned short __user *)regs->ip);
32332+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
32333+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
32334+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
32335+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
32336+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
32337+
32338+ if (err)
32339+ break;
32340+
32341+ if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
32342+ regs->r11 = addr1;
32343+ regs->r10 = addr2;
32344+ regs->ip = addr1;
32345+ return 2;
32346+ }
32347+ } while (0);
32348+
32349+ do { /* PaX: gcc trampoline emulation #2 */
32350+ unsigned short mov1, mov2, jmp1;
32351+ unsigned char jmp2;
32352+ unsigned long addr1, addr2;
32353+
32354+ err = get_user(mov1, (unsigned short __user *)regs->ip);
32355+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
32356+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
32357+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
32358+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
32359+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
32360+
32361+ if (err)
32362+ break;
32363+
32364+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
32365+ regs->r11 = addr1;
32366+ regs->r10 = addr2;
32367+ regs->ip = addr1;
32368+ return 2;
32369+ }
32370+ } while (0);
32371+
32372+ return 1; /* PaX in action */
32373+}
32374+#endif
32375+
32376+/*
32377+ * PaX: decide what to do with offenders (regs->ip = fault address)
32378+ *
32379+ * returns 1 when task should be killed
32380+ * 2 when gcc trampoline was detected
32381+ */
32382+static int pax_handle_fetch_fault(struct pt_regs *regs)
32383+{
32384+ if (v8086_mode(regs))
32385+ return 1;
32386+
32387+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
32388+ return 1;
32389+
32390+#ifdef CONFIG_X86_32
32391+ return pax_handle_fetch_fault_32(regs);
32392+#else
32393+ if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
32394+ return pax_handle_fetch_fault_32(regs);
32395+ else
32396+ return pax_handle_fetch_fault_64(regs);
32397+#endif
32398+}
32399+#endif
32400+
32401+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
32402+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
32403+{
32404+ long i;
32405+
32406+ printk(KERN_ERR "PAX: bytes at PC: ");
32407+ for (i = 0; i < 20; i++) {
32408+ unsigned char c;
32409+ if (get_user(c, (unsigned char __force_user *)pc+i))
32410+ printk(KERN_CONT "?? ");
32411+ else
32412+ printk(KERN_CONT "%02x ", c);
32413+ }
32414+ printk("\n");
32415+
32416+ printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
32417+ for (i = -1; i < 80 / (long)sizeof(long); i++) {
32418+ unsigned long c;
32419+ if (get_user(c, (unsigned long __force_user *)sp+i)) {
32420+#ifdef CONFIG_X86_32
32421+ printk(KERN_CONT "???????? ");
32422+#else
32423+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
32424+ printk(KERN_CONT "???????? ???????? ");
32425+ else
32426+ printk(KERN_CONT "???????????????? ");
32427+#endif
32428+ } else {
32429+#ifdef CONFIG_X86_64
32430+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
32431+ printk(KERN_CONT "%08x ", (unsigned int)c);
32432+ printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
32433+ } else
32434+#endif
32435+ printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
32436+ }
32437+ }
32438+ printk("\n");
32439+}
32440+#endif
32441+
32442+/**
32443+ * probe_kernel_write(): safely attempt to write to a location
32444+ * @dst: address to write to
32445+ * @src: pointer to the data that shall be written
32446+ * @size: size of the data chunk
32447+ *
32448+ * Safely write to address @dst from the buffer at @src. If a kernel fault
32449+ * happens, handle that and return -EFAULT.
32450+ */
32451+long notrace probe_kernel_write(void *dst, const void *src, size_t size)
32452+{
32453+ long ret;
32454+ mm_segment_t old_fs = get_fs();
32455+
32456+ set_fs(KERNEL_DS);
32457+ pagefault_disable();
32458+ pax_open_kernel();
32459+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
32460+ pax_close_kernel();
32461+ pagefault_enable();
32462+ set_fs(old_fs);
32463+
32464+ return ret ? -EFAULT : 0;
32465+}
32466diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
32467index 207d9aef..69030980 100644
32468--- a/arch/x86/mm/gup.c
32469+++ b/arch/x86/mm/gup.c
32470@@ -268,7 +268,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
32471 addr = start;
32472 len = (unsigned long) nr_pages << PAGE_SHIFT;
32473 end = start + len;
32474- if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
32475+ if (unlikely(!access_ok_noprefault(write ? VERIFY_WRITE : VERIFY_READ,
32476 (void __user *)start, len)))
32477 return 0;
32478
32479@@ -344,6 +344,10 @@ int get_user_pages_fast(unsigned long start, int nr_pages, int write,
32480 goto slow_irqon;
32481 #endif
32482
32483+ if (unlikely(!access_ok_noprefault(write ? VERIFY_WRITE : VERIFY_READ,
32484+ (void __user *)start, len)))
32485+ return 0;
32486+
32487 /*
32488 * XXX: batch / limit 'nr', to avoid large irq off latency
32489 * needs some instrumenting to determine the common sizes used by
32490diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
32491index 4500142..53a363c 100644
32492--- a/arch/x86/mm/highmem_32.c
32493+++ b/arch/x86/mm/highmem_32.c
32494@@ -45,7 +45,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot)
32495 idx = type + KM_TYPE_NR*smp_processor_id();
32496 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
32497 BUG_ON(!pte_none(*(kmap_pte-idx)));
32498+
32499+ pax_open_kernel();
32500 set_pte(kmap_pte-idx, mk_pte(page, prot));
32501+ pax_close_kernel();
32502+
32503 arch_flush_lazy_mmu_mode();
32504
32505 return (void *)vaddr;
32506diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
32507index 8b977eb..4732c33 100644
32508--- a/arch/x86/mm/hugetlbpage.c
32509+++ b/arch/x86/mm/hugetlbpage.c
32510@@ -80,23 +80,24 @@ int pud_huge(pud_t pud)
32511 #ifdef CONFIG_HUGETLB_PAGE
32512 static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
32513 unsigned long addr, unsigned long len,
32514- unsigned long pgoff, unsigned long flags)
32515+ unsigned long pgoff, unsigned long flags, unsigned long offset)
32516 {
32517 struct hstate *h = hstate_file(file);
32518 struct vm_unmapped_area_info info;
32519-
32520+
32521 info.flags = 0;
32522 info.length = len;
32523 info.low_limit = current->mm->mmap_legacy_base;
32524 info.high_limit = TASK_SIZE;
32525 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
32526 info.align_offset = 0;
32527+ info.threadstack_offset = offset;
32528 return vm_unmapped_area(&info);
32529 }
32530
32531 static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
32532 unsigned long addr0, unsigned long len,
32533- unsigned long pgoff, unsigned long flags)
32534+ unsigned long pgoff, unsigned long flags, unsigned long offset)
32535 {
32536 struct hstate *h = hstate_file(file);
32537 struct vm_unmapped_area_info info;
32538@@ -108,6 +109,7 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
32539 info.high_limit = current->mm->mmap_base;
32540 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
32541 info.align_offset = 0;
32542+ info.threadstack_offset = offset;
32543 addr = vm_unmapped_area(&info);
32544
32545 /*
32546@@ -120,6 +122,12 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
32547 VM_BUG_ON(addr != -ENOMEM);
32548 info.flags = 0;
32549 info.low_limit = TASK_UNMAPPED_BASE;
32550+
32551+#ifdef CONFIG_PAX_RANDMMAP
32552+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
32553+ info.low_limit += current->mm->delta_mmap;
32554+#endif
32555+
32556 info.high_limit = TASK_SIZE;
32557 addr = vm_unmapped_area(&info);
32558 }
32559@@ -134,10 +142,20 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
32560 struct hstate *h = hstate_file(file);
32561 struct mm_struct *mm = current->mm;
32562 struct vm_area_struct *vma;
32563+ unsigned long pax_task_size = TASK_SIZE;
32564+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
32565
32566 if (len & ~huge_page_mask(h))
32567 return -EINVAL;
32568- if (len > TASK_SIZE)
32569+
32570+#ifdef CONFIG_PAX_SEGMEXEC
32571+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
32572+ pax_task_size = SEGMEXEC_TASK_SIZE;
32573+#endif
32574+
32575+ pax_task_size -= PAGE_SIZE;
32576+
32577+ if (len > pax_task_size)
32578 return -ENOMEM;
32579
32580 if (flags & MAP_FIXED) {
32581@@ -146,19 +164,22 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
32582 return addr;
32583 }
32584
32585+#ifdef CONFIG_PAX_RANDMMAP
32586+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
32587+#endif
32588+
32589 if (addr) {
32590 addr = ALIGN(addr, huge_page_size(h));
32591 vma = find_vma(mm, addr);
32592- if (TASK_SIZE - len >= addr &&
32593- (!vma || addr + len <= vma->vm_start))
32594+ if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
32595 return addr;
32596 }
32597 if (mm->get_unmapped_area == arch_get_unmapped_area)
32598 return hugetlb_get_unmapped_area_bottomup(file, addr, len,
32599- pgoff, flags);
32600+ pgoff, flags, offset);
32601 else
32602 return hugetlb_get_unmapped_area_topdown(file, addr, len,
32603- pgoff, flags);
32604+ pgoff, flags, offset);
32605 }
32606 #endif /* CONFIG_HUGETLB_PAGE */
32607
32608diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
32609index 66dba36..f8082ec 100644
32610--- a/arch/x86/mm/init.c
32611+++ b/arch/x86/mm/init.c
32612@@ -4,6 +4,7 @@
32613 #include <linux/swap.h>
32614 #include <linux/memblock.h>
32615 #include <linux/bootmem.h> /* for max_low_pfn */
32616+#include <linux/tboot.h>
32617
32618 #include <asm/cacheflush.h>
32619 #include <asm/e820.h>
32620@@ -17,6 +18,8 @@
32621 #include <asm/proto.h>
32622 #include <asm/dma.h> /* for MAX_DMA_PFN */
32623 #include <asm/microcode.h>
32624+#include <asm/desc.h>
32625+#include <asm/bios_ebda.h>
32626
32627 /*
32628 * We need to define the tracepoints somewhere, and tlb.c
32629@@ -570,7 +573,18 @@ void __init init_mem_mapping(void)
32630 early_ioremap_page_table_range_init();
32631 #endif
32632
32633+#ifdef CONFIG_PAX_PER_CPU_PGD
32634+ clone_pgd_range(get_cpu_pgd(0, kernel) + KERNEL_PGD_BOUNDARY,
32635+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
32636+ KERNEL_PGD_PTRS);
32637+ clone_pgd_range(get_cpu_pgd(0, user) + KERNEL_PGD_BOUNDARY,
32638+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
32639+ KERNEL_PGD_PTRS);
32640+ load_cr3(get_cpu_pgd(0, kernel));
32641+#else
32642 load_cr3(swapper_pg_dir);
32643+#endif
32644+
32645 __flush_tlb_all();
32646
32647 early_memtest(0, max_pfn_mapped << PAGE_SHIFT);
32648@@ -586,10 +600,40 @@ void __init init_mem_mapping(void)
32649 * Access has to be given to non-kernel-ram areas as well, these contain the PCI
32650 * mmio resources as well as potential bios/acpi data regions.
32651 */
32652+
32653+#ifdef CONFIG_GRKERNSEC_KMEM
32654+static unsigned int ebda_start __read_only;
32655+static unsigned int ebda_end __read_only;
32656+#endif
32657+
32658 int devmem_is_allowed(unsigned long pagenr)
32659 {
32660- if (pagenr < 256)
32661+#ifdef CONFIG_GRKERNSEC_KMEM
32662+ /* allow BDA */
32663+ if (!pagenr)
32664 return 1;
32665+ /* allow EBDA */
32666+ if (pagenr >= ebda_start && pagenr < ebda_end)
32667+ return 1;
32668+ /* if tboot is in use, allow access to its hardcoded serial log range */
32669+ if (tboot_enabled() && ((0x60000 >> PAGE_SHIFT) <= pagenr) && (pagenr < (0x68000 >> PAGE_SHIFT)))
32670+ return 1;
32671+#else
32672+ if (!pagenr)
32673+ return 1;
32674+#ifdef CONFIG_VM86
32675+ if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
32676+ return 1;
32677+#endif
32678+#endif
32679+
32680+ if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
32681+ return 1;
32682+#ifdef CONFIG_GRKERNSEC_KMEM
32683+ /* throw out everything else below 1MB */
32684+ if (pagenr <= 256)
32685+ return 0;
32686+#endif
32687 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
32688 return 0;
32689 if (!page_is_ram(pagenr))
32690@@ -635,8 +679,117 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
32691 #endif
32692 }
32693
32694+#ifdef CONFIG_GRKERNSEC_KMEM
32695+static inline void gr_init_ebda(void)
32696+{
32697+ unsigned int ebda_addr;
32698+ unsigned int ebda_size = 0;
32699+
32700+ ebda_addr = get_bios_ebda();
32701+ if (ebda_addr) {
32702+ ebda_size = *(unsigned char *)phys_to_virt(ebda_addr);
32703+ ebda_size <<= 10;
32704+ }
32705+ if (ebda_addr && ebda_size) {
32706+ ebda_start = ebda_addr >> PAGE_SHIFT;
32707+ ebda_end = min((unsigned int)PAGE_ALIGN(ebda_addr + ebda_size), (unsigned int)0xa0000) >> PAGE_SHIFT;
32708+ } else {
32709+ ebda_start = 0x9f000 >> PAGE_SHIFT;
32710+ ebda_end = 0xa0000 >> PAGE_SHIFT;
32711+ }
32712+}
32713+#else
32714+static inline void gr_init_ebda(void) { }
32715+#endif
32716+
32717 void free_initmem(void)
32718 {
32719+#ifdef CONFIG_PAX_KERNEXEC
32720+#ifdef CONFIG_X86_32
32721+ /* PaX: limit KERNEL_CS to actual size */
32722+ unsigned long addr, limit;
32723+ struct desc_struct d;
32724+ int cpu;
32725+#else
32726+ pgd_t *pgd;
32727+ pud_t *pud;
32728+ pmd_t *pmd;
32729+ unsigned long addr, end;
32730+#endif
32731+#endif
32732+
32733+ gr_init_ebda();
32734+
32735+#ifdef CONFIG_PAX_KERNEXEC
32736+#ifdef CONFIG_X86_32
32737+ limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
32738+ limit = (limit - 1UL) >> PAGE_SHIFT;
32739+
32740+ memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
32741+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
32742+ pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
32743+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
32744+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEXEC_KERNEL_CS, &d, DESCTYPE_S);
32745+ }
32746+
32747+ /* PaX: make KERNEL_CS read-only */
32748+ addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
32749+ if (!paravirt_enabled())
32750+ set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
32751+/*
32752+ for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
32753+ pgd = pgd_offset_k(addr);
32754+ pud = pud_offset(pgd, addr);
32755+ pmd = pmd_offset(pud, addr);
32756+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
32757+ }
32758+*/
32759+#ifdef CONFIG_X86_PAE
32760+ set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
32761+/*
32762+ for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
32763+ pgd = pgd_offset_k(addr);
32764+ pud = pud_offset(pgd, addr);
32765+ pmd = pmd_offset(pud, addr);
32766+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
32767+ }
32768+*/
32769+#endif
32770+
32771+#ifdef CONFIG_MODULES
32772+ set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
32773+#endif
32774+
32775+#else
32776+ /* PaX: make kernel code/rodata read-only, rest non-executable */
32777+ for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
32778+ pgd = pgd_offset_k(addr);
32779+ pud = pud_offset(pgd, addr);
32780+ pmd = pmd_offset(pud, addr);
32781+ if (!pmd_present(*pmd))
32782+ continue;
32783+ if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
32784+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
32785+ else
32786+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
32787+ }
32788+
32789+ addr = (unsigned long)__va(__pa(__START_KERNEL_map));
32790+ end = addr + KERNEL_IMAGE_SIZE;
32791+ for (; addr < end; addr += PMD_SIZE) {
32792+ pgd = pgd_offset_k(addr);
32793+ pud = pud_offset(pgd, addr);
32794+ pmd = pmd_offset(pud, addr);
32795+ if (!pmd_present(*pmd))
32796+ continue;
32797+ if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
32798+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
32799+ }
32800+#endif
32801+
32802+ flush_tlb_all();
32803+#endif
32804+
32805 free_init_pages("unused kernel",
32806 (unsigned long)(&__init_begin),
32807 (unsigned long)(&__init_end));
32808diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
32809index c8140e1..59257fc 100644
32810--- a/arch/x86/mm/init_32.c
32811+++ b/arch/x86/mm/init_32.c
32812@@ -62,33 +62,6 @@ static noinline int do_test_wp_bit(void);
32813 bool __read_mostly __vmalloc_start_set = false;
32814
32815 /*
32816- * Creates a middle page table and puts a pointer to it in the
32817- * given global directory entry. This only returns the gd entry
32818- * in non-PAE compilation mode, since the middle layer is folded.
32819- */
32820-static pmd_t * __init one_md_table_init(pgd_t *pgd)
32821-{
32822- pud_t *pud;
32823- pmd_t *pmd_table;
32824-
32825-#ifdef CONFIG_X86_PAE
32826- if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
32827- pmd_table = (pmd_t *)alloc_low_page();
32828- paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
32829- set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
32830- pud = pud_offset(pgd, 0);
32831- BUG_ON(pmd_table != pmd_offset(pud, 0));
32832-
32833- return pmd_table;
32834- }
32835-#endif
32836- pud = pud_offset(pgd, 0);
32837- pmd_table = pmd_offset(pud, 0);
32838-
32839- return pmd_table;
32840-}
32841-
32842-/*
32843 * Create a page table and place a pointer to it in a middle page
32844 * directory entry:
32845 */
32846@@ -98,13 +71,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
32847 pte_t *page_table = (pte_t *)alloc_low_page();
32848
32849 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
32850+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
32851+ set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
32852+#else
32853 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
32854+#endif
32855 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
32856 }
32857
32858 return pte_offset_kernel(pmd, 0);
32859 }
32860
32861+static pmd_t * __init one_md_table_init(pgd_t *pgd)
32862+{
32863+ pud_t *pud;
32864+ pmd_t *pmd_table;
32865+
32866+ pud = pud_offset(pgd, 0);
32867+ pmd_table = pmd_offset(pud, 0);
32868+
32869+ return pmd_table;
32870+}
32871+
32872 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
32873 {
32874 int pgd_idx = pgd_index(vaddr);
32875@@ -208,6 +196,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
32876 int pgd_idx, pmd_idx;
32877 unsigned long vaddr;
32878 pgd_t *pgd;
32879+ pud_t *pud;
32880 pmd_t *pmd;
32881 pte_t *pte = NULL;
32882 unsigned long count = page_table_range_init_count(start, end);
32883@@ -222,8 +211,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
32884 pgd = pgd_base + pgd_idx;
32885
32886 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
32887- pmd = one_md_table_init(pgd);
32888- pmd = pmd + pmd_index(vaddr);
32889+ pud = pud_offset(pgd, vaddr);
32890+ pmd = pmd_offset(pud, vaddr);
32891+
32892+#ifdef CONFIG_X86_PAE
32893+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
32894+#endif
32895+
32896 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
32897 pmd++, pmd_idx++) {
32898 pte = page_table_kmap_check(one_page_table_init(pmd),
32899@@ -235,11 +229,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
32900 }
32901 }
32902
32903-static inline int is_kernel_text(unsigned long addr)
32904+static inline int is_kernel_text(unsigned long start, unsigned long end)
32905 {
32906- if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
32907- return 1;
32908- return 0;
32909+ if ((start >= ktla_ktva((unsigned long)_etext) ||
32910+ end <= ktla_ktva((unsigned long)_stext)) &&
32911+ (start >= ktla_ktva((unsigned long)_einittext) ||
32912+ end <= ktla_ktva((unsigned long)_sinittext)) &&
32913+
32914+#ifdef CONFIG_ACPI_SLEEP
32915+ (start >= (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
32916+#endif
32917+
32918+ (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
32919+ return 0;
32920+ return 1;
32921 }
32922
32923 /*
32924@@ -256,9 +259,10 @@ kernel_physical_mapping_init(unsigned long start,
32925 unsigned long last_map_addr = end;
32926 unsigned long start_pfn, end_pfn;
32927 pgd_t *pgd_base = swapper_pg_dir;
32928- int pgd_idx, pmd_idx, pte_ofs;
32929+ unsigned int pgd_idx, pmd_idx, pte_ofs;
32930 unsigned long pfn;
32931 pgd_t *pgd;
32932+ pud_t *pud;
32933 pmd_t *pmd;
32934 pte_t *pte;
32935 unsigned pages_2m, pages_4k;
32936@@ -291,8 +295,13 @@ repeat:
32937 pfn = start_pfn;
32938 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
32939 pgd = pgd_base + pgd_idx;
32940- for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
32941- pmd = one_md_table_init(pgd);
32942+ for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
32943+ pud = pud_offset(pgd, 0);
32944+ pmd = pmd_offset(pud, 0);
32945+
32946+#ifdef CONFIG_X86_PAE
32947+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
32948+#endif
32949
32950 if (pfn >= end_pfn)
32951 continue;
32952@@ -304,14 +313,13 @@ repeat:
32953 #endif
32954 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
32955 pmd++, pmd_idx++) {
32956- unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
32957+ unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
32958
32959 /*
32960 * Map with big pages if possible, otherwise
32961 * create normal page tables:
32962 */
32963 if (use_pse) {
32964- unsigned int addr2;
32965 pgprot_t prot = PAGE_KERNEL_LARGE;
32966 /*
32967 * first pass will use the same initial
32968@@ -322,11 +330,7 @@ repeat:
32969 _PAGE_PSE);
32970
32971 pfn &= PMD_MASK >> PAGE_SHIFT;
32972- addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
32973- PAGE_OFFSET + PAGE_SIZE-1;
32974-
32975- if (is_kernel_text(addr) ||
32976- is_kernel_text(addr2))
32977+ if (is_kernel_text(address, address + PMD_SIZE))
32978 prot = PAGE_KERNEL_LARGE_EXEC;
32979
32980 pages_2m++;
32981@@ -343,7 +347,7 @@ repeat:
32982 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
32983 pte += pte_ofs;
32984 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
32985- pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
32986+ pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
32987 pgprot_t prot = PAGE_KERNEL;
32988 /*
32989 * first pass will use the same initial
32990@@ -351,7 +355,7 @@ repeat:
32991 */
32992 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
32993
32994- if (is_kernel_text(addr))
32995+ if (is_kernel_text(address, address + PAGE_SIZE))
32996 prot = PAGE_KERNEL_EXEC;
32997
32998 pages_4k++;
32999@@ -474,7 +478,7 @@ void __init native_pagetable_init(void)
33000
33001 pud = pud_offset(pgd, va);
33002 pmd = pmd_offset(pud, va);
33003- if (!pmd_present(*pmd))
33004+ if (!pmd_present(*pmd)) // PAX TODO || pmd_large(*pmd))
33005 break;
33006
33007 /* should not be large page here */
33008@@ -532,12 +536,10 @@ void __init early_ioremap_page_table_range_init(void)
33009
33010 static void __init pagetable_init(void)
33011 {
33012- pgd_t *pgd_base = swapper_pg_dir;
33013-
33014- permanent_kmaps_init(pgd_base);
33015+ permanent_kmaps_init(swapper_pg_dir);
33016 }
33017
33018-pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL);
33019+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL);
33020 EXPORT_SYMBOL_GPL(__supported_pte_mask);
33021
33022 /* user-defined highmem size */
33023@@ -787,10 +789,10 @@ void __init mem_init(void)
33024 ((unsigned long)&__init_end -
33025 (unsigned long)&__init_begin) >> 10,
33026
33027- (unsigned long)&_etext, (unsigned long)&_edata,
33028- ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
33029+ (unsigned long)&_sdata, (unsigned long)&_edata,
33030+ ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
33031
33032- (unsigned long)&_text, (unsigned long)&_etext,
33033+ ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
33034 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
33035
33036 /*
33037@@ -884,6 +886,7 @@ void set_kernel_text_rw(void)
33038 if (!kernel_set_to_readonly)
33039 return;
33040
33041+ start = ktla_ktva(start);
33042 pr_debug("Set kernel text: %lx - %lx for read write\n",
33043 start, start+size);
33044
33045@@ -898,6 +901,7 @@ void set_kernel_text_ro(void)
33046 if (!kernel_set_to_readonly)
33047 return;
33048
33049+ start = ktla_ktva(start);
33050 pr_debug("Set kernel text: %lx - %lx for read only\n",
33051 start, start+size);
33052
33053@@ -926,6 +930,7 @@ void mark_rodata_ro(void)
33054 unsigned long start = PFN_ALIGN(_text);
33055 unsigned long size = PFN_ALIGN(_etext) - start;
33056
33057+ start = ktla_ktva(start);
33058 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
33059 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
33060 size >> 10);
33061diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
33062index 4e5dfec..6fd6dc5 100644
33063--- a/arch/x86/mm/init_64.c
33064+++ b/arch/x86/mm/init_64.c
33065@@ -151,7 +151,7 @@ early_param("gbpages", parse_direct_gbpages_on);
33066 * around without checking the pgd every time.
33067 */
33068
33069-pteval_t __supported_pte_mask __read_mostly = ~0;
33070+pteval_t __supported_pte_mask __read_only = ~_PAGE_NX;
33071 EXPORT_SYMBOL_GPL(__supported_pte_mask);
33072
33073 int force_personality32;
33074@@ -184,7 +184,12 @@ void sync_global_pgds(unsigned long start, unsigned long end, int removed)
33075
33076 for (address = start; address <= end; address += PGDIR_SIZE) {
33077 const pgd_t *pgd_ref = pgd_offset_k(address);
33078+
33079+#ifdef CONFIG_PAX_PER_CPU_PGD
33080+ unsigned long cpu;
33081+#else
33082 struct page *page;
33083+#endif
33084
33085 /*
33086 * When it is called after memory hot remove, pgd_none()
33087@@ -195,6 +200,25 @@ void sync_global_pgds(unsigned long start, unsigned long end, int removed)
33088 continue;
33089
33090 spin_lock(&pgd_lock);
33091+
33092+#ifdef CONFIG_PAX_PER_CPU_PGD
33093+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
33094+ pgd_t *pgd = pgd_offset_cpu(cpu, user, address);
33095+
33096+ if (!pgd_none(*pgd_ref) && !pgd_none(*pgd))
33097+ BUG_ON(pgd_page_vaddr(*pgd)
33098+ != pgd_page_vaddr(*pgd_ref));
33099+
33100+ if (removed) {
33101+ if (pgd_none(*pgd_ref) && !pgd_none(*pgd))
33102+ pgd_clear(pgd);
33103+ } else {
33104+ if (pgd_none(*pgd))
33105+ set_pgd(pgd, *pgd_ref);
33106+ }
33107+
33108+ pgd = pgd_offset_cpu(cpu, kernel, address);
33109+#else
33110 list_for_each_entry(page, &pgd_list, lru) {
33111 pgd_t *pgd;
33112 spinlock_t *pgt_lock;
33113@@ -203,6 +227,7 @@ void sync_global_pgds(unsigned long start, unsigned long end, int removed)
33114 /* the pgt_lock only for Xen */
33115 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
33116 spin_lock(pgt_lock);
33117+#endif
33118
33119 if (!pgd_none(*pgd_ref) && !pgd_none(*pgd))
33120 BUG_ON(pgd_page_vaddr(*pgd)
33121@@ -216,7 +241,10 @@ void sync_global_pgds(unsigned long start, unsigned long end, int removed)
33122 set_pgd(pgd, *pgd_ref);
33123 }
33124
33125+#ifndef CONFIG_PAX_PER_CPU_PGD
33126 spin_unlock(pgt_lock);
33127+#endif
33128+
33129 }
33130 spin_unlock(&pgd_lock);
33131 }
33132@@ -249,7 +277,7 @@ static pud_t *fill_pud(pgd_t *pgd, unsigned long vaddr)
33133 {
33134 if (pgd_none(*pgd)) {
33135 pud_t *pud = (pud_t *)spp_getpage();
33136- pgd_populate(&init_mm, pgd, pud);
33137+ pgd_populate_kernel(&init_mm, pgd, pud);
33138 if (pud != pud_offset(pgd, 0))
33139 printk(KERN_ERR "PAGETABLE BUG #00! %p <-> %p\n",
33140 pud, pud_offset(pgd, 0));
33141@@ -261,7 +289,7 @@ static pmd_t *fill_pmd(pud_t *pud, unsigned long vaddr)
33142 {
33143 if (pud_none(*pud)) {
33144 pmd_t *pmd = (pmd_t *) spp_getpage();
33145- pud_populate(&init_mm, pud, pmd);
33146+ pud_populate_kernel(&init_mm, pud, pmd);
33147 if (pmd != pmd_offset(pud, 0))
33148 printk(KERN_ERR "PAGETABLE BUG #01! %p <-> %p\n",
33149 pmd, pmd_offset(pud, 0));
33150@@ -290,7 +318,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
33151 pmd = fill_pmd(pud, vaddr);
33152 pte = fill_pte(pmd, vaddr);
33153
33154+ pax_open_kernel();
33155 set_pte(pte, new_pte);
33156+ pax_close_kernel();
33157
33158 /*
33159 * It's enough to flush this one mapping.
33160@@ -349,14 +379,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
33161 pgd = pgd_offset_k((unsigned long)__va(phys));
33162 if (pgd_none(*pgd)) {
33163 pud = (pud_t *) spp_getpage();
33164- set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
33165- _PAGE_USER));
33166+ set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
33167 }
33168 pud = pud_offset(pgd, (unsigned long)__va(phys));
33169 if (pud_none(*pud)) {
33170 pmd = (pmd_t *) spp_getpage();
33171- set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
33172- _PAGE_USER));
33173+ set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
33174 }
33175 pmd = pmd_offset(pud, phys);
33176 BUG_ON(!pmd_none(*pmd));
33177@@ -597,7 +625,7 @@ phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end,
33178 prot);
33179
33180 spin_lock(&init_mm.page_table_lock);
33181- pud_populate(&init_mm, pud, pmd);
33182+ pud_populate_kernel(&init_mm, pud, pmd);
33183 spin_unlock(&init_mm.page_table_lock);
33184 }
33185 __flush_tlb_all();
33186@@ -638,7 +666,7 @@ kernel_physical_mapping_init(unsigned long start,
33187 page_size_mask);
33188
33189 spin_lock(&init_mm.page_table_lock);
33190- pgd_populate(&init_mm, pgd, pud);
33191+ pgd_populate_kernel(&init_mm, pgd, pud);
33192 spin_unlock(&init_mm.page_table_lock);
33193 pgd_changed = true;
33194 }
33195@@ -1217,8 +1245,8 @@ static struct vm_operations_struct gate_vma_ops = {
33196 static struct vm_area_struct gate_vma = {
33197 .vm_start = VSYSCALL_ADDR,
33198 .vm_end = VSYSCALL_ADDR + PAGE_SIZE,
33199- .vm_page_prot = PAGE_READONLY_EXEC,
33200- .vm_flags = VM_READ | VM_EXEC,
33201+ .vm_page_prot = PAGE_READONLY,
33202+ .vm_flags = VM_READ,
33203 .vm_ops = &gate_vma_ops,
33204 };
33205
33206diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
33207index 7b179b49..6bd17777 100644
33208--- a/arch/x86/mm/iomap_32.c
33209+++ b/arch/x86/mm/iomap_32.c
33210@@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
33211 type = kmap_atomic_idx_push();
33212 idx = type + KM_TYPE_NR * smp_processor_id();
33213 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
33214+
33215+ pax_open_kernel();
33216 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
33217+ pax_close_kernel();
33218+
33219 arch_flush_lazy_mmu_mode();
33220
33221 return (void *)vaddr;
33222diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
33223index af78e50..0790b03 100644
33224--- a/arch/x86/mm/ioremap.c
33225+++ b/arch/x86/mm/ioremap.c
33226@@ -56,8 +56,8 @@ static int __ioremap_check_ram(unsigned long start_pfn, unsigned long nr_pages,
33227 unsigned long i;
33228
33229 for (i = 0; i < nr_pages; ++i)
33230- if (pfn_valid(start_pfn + i) &&
33231- !PageReserved(pfn_to_page(start_pfn + i)))
33232+ if (pfn_valid(start_pfn + i) && (start_pfn + i >= 0x100 ||
33233+ !PageReserved(pfn_to_page(start_pfn + i))))
33234 return 1;
33235
33236 WARN_ONCE(1, "ioremap on RAM pfn 0x%lx\n", start_pfn);
33237@@ -280,7 +280,7 @@ EXPORT_SYMBOL(ioremap_prot);
33238 *
33239 * Caller must ensure there is only one unmapping for the same pointer.
33240 */
33241-void iounmap(volatile void __iomem *addr)
33242+void iounmap(const volatile void __iomem *addr)
33243 {
33244 struct vm_struct *p, *o;
33245
33246@@ -334,6 +334,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
33247
33248 /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
33249 if (page_is_ram(start >> PAGE_SHIFT))
33250+#ifdef CONFIG_HIGHMEM
33251+ if ((start >> PAGE_SHIFT) < max_low_pfn)
33252+#endif
33253 return __va(phys);
33254
33255 addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
33256@@ -346,13 +349,16 @@ void *xlate_dev_mem_ptr(unsigned long phys)
33257 void unxlate_dev_mem_ptr(unsigned long phys, void *addr)
33258 {
33259 if (page_is_ram(phys >> PAGE_SHIFT))
33260+#ifdef CONFIG_HIGHMEM
33261+ if ((phys >> PAGE_SHIFT) < max_low_pfn)
33262+#endif
33263 return;
33264
33265 iounmap((void __iomem *)((unsigned long)addr & PAGE_MASK));
33266 return;
33267 }
33268
33269-static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
33270+static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
33271
33272 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
33273 {
33274@@ -388,8 +394,7 @@ void __init early_ioremap_init(void)
33275 early_ioremap_setup();
33276
33277 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
33278- memset(bm_pte, 0, sizeof(bm_pte));
33279- pmd_populate_kernel(&init_mm, pmd, bm_pte);
33280+ pmd_populate_user(&init_mm, pmd, bm_pte);
33281
33282 /*
33283 * The boot-ioremap range spans multiple pmds, for which
33284diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
33285index b4f2e7e..96c9c3e 100644
33286--- a/arch/x86/mm/kmemcheck/kmemcheck.c
33287+++ b/arch/x86/mm/kmemcheck/kmemcheck.c
33288@@ -628,9 +628,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
33289 * memory (e.g. tracked pages)? For now, we need this to avoid
33290 * invoking kmemcheck for PnP BIOS calls.
33291 */
33292- if (regs->flags & X86_VM_MASK)
33293+ if (v8086_mode(regs))
33294 return false;
33295- if (regs->cs != __KERNEL_CS)
33296+ if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
33297 return false;
33298
33299 pte = kmemcheck_pte_lookup(address);
33300diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
33301index 919b912..9267313 100644
33302--- a/arch/x86/mm/mmap.c
33303+++ b/arch/x86/mm/mmap.c
33304@@ -52,7 +52,7 @@ static unsigned int stack_maxrandom_size(void)
33305 * Leave an at least ~128 MB hole with possible stack randomization.
33306 */
33307 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
33308-#define MAX_GAP (TASK_SIZE/6*5)
33309+#define MAX_GAP (pax_task_size/6*5)
33310
33311 static int mmap_is_legacy(void)
33312 {
33313@@ -82,27 +82,40 @@ static unsigned long mmap_rnd(void)
33314 return rnd << PAGE_SHIFT;
33315 }
33316
33317-static unsigned long mmap_base(void)
33318+static unsigned long mmap_base(struct mm_struct *mm)
33319 {
33320 unsigned long gap = rlimit(RLIMIT_STACK);
33321+ unsigned long pax_task_size = TASK_SIZE;
33322+
33323+#ifdef CONFIG_PAX_SEGMEXEC
33324+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
33325+ pax_task_size = SEGMEXEC_TASK_SIZE;
33326+#endif
33327
33328 if (gap < MIN_GAP)
33329 gap = MIN_GAP;
33330 else if (gap > MAX_GAP)
33331 gap = MAX_GAP;
33332
33333- return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
33334+ return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
33335 }
33336
33337 /*
33338 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
33339 * does, but not when emulating X86_32
33340 */
33341-static unsigned long mmap_legacy_base(void)
33342+static unsigned long mmap_legacy_base(struct mm_struct *mm)
33343 {
33344- if (mmap_is_ia32())
33345+ if (mmap_is_ia32()) {
33346+
33347+#ifdef CONFIG_PAX_SEGMEXEC
33348+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
33349+ return SEGMEXEC_TASK_UNMAPPED_BASE;
33350+ else
33351+#endif
33352+
33353 return TASK_UNMAPPED_BASE;
33354- else
33355+ } else
33356 return TASK_UNMAPPED_BASE + mmap_rnd();
33357 }
33358
33359@@ -112,8 +125,15 @@ static unsigned long mmap_legacy_base(void)
33360 */
33361 void arch_pick_mmap_layout(struct mm_struct *mm)
33362 {
33363- mm->mmap_legacy_base = mmap_legacy_base();
33364- mm->mmap_base = mmap_base();
33365+ mm->mmap_legacy_base = mmap_legacy_base(mm);
33366+ mm->mmap_base = mmap_base(mm);
33367+
33368+#ifdef CONFIG_PAX_RANDMMAP
33369+ if (mm->pax_flags & MF_PAX_RANDMMAP) {
33370+ mm->mmap_legacy_base += mm->delta_mmap;
33371+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
33372+ }
33373+#endif
33374
33375 if (mmap_is_legacy()) {
33376 mm->mmap_base = mm->mmap_legacy_base;
33377diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
33378index 0057a7a..95c7edd 100644
33379--- a/arch/x86/mm/mmio-mod.c
33380+++ b/arch/x86/mm/mmio-mod.c
33381@@ -194,7 +194,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
33382 break;
33383 default:
33384 {
33385- unsigned char *ip = (unsigned char *)instptr;
33386+ unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
33387 my_trace->opcode = MMIO_UNKNOWN_OP;
33388 my_trace->width = 0;
33389 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
33390@@ -234,7 +234,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
33391 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
33392 void __iomem *addr)
33393 {
33394- static atomic_t next_id;
33395+ static atomic_unchecked_t next_id;
33396 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
33397 /* These are page-unaligned. */
33398 struct mmiotrace_map map = {
33399@@ -258,7 +258,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
33400 .private = trace
33401 },
33402 .phys = offset,
33403- .id = atomic_inc_return(&next_id)
33404+ .id = atomic_inc_return_unchecked(&next_id)
33405 };
33406 map.map_id = trace->id;
33407
33408@@ -290,7 +290,7 @@ void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
33409 ioremap_trace_core(offset, size, addr);
33410 }
33411
33412-static void iounmap_trace_core(volatile void __iomem *addr)
33413+static void iounmap_trace_core(const volatile void __iomem *addr)
33414 {
33415 struct mmiotrace_map map = {
33416 .phys = 0,
33417@@ -328,7 +328,7 @@ not_enabled:
33418 }
33419 }
33420
33421-void mmiotrace_iounmap(volatile void __iomem *addr)
33422+void mmiotrace_iounmap(const volatile void __iomem *addr)
33423 {
33424 might_sleep();
33425 if (is_enabled()) /* recheck and proper locking in *_core() */
33426diff --git a/arch/x86/mm/numa.c b/arch/x86/mm/numa.c
33427index 1a88370..3f598b5 100644
33428--- a/arch/x86/mm/numa.c
33429+++ b/arch/x86/mm/numa.c
33430@@ -499,7 +499,7 @@ static void __init numa_clear_kernel_node_hotplug(void)
33431 }
33432 }
33433
33434-static int __init numa_register_memblks(struct numa_meminfo *mi)
33435+static int __init __intentional_overflow(-1) numa_register_memblks(struct numa_meminfo *mi)
33436 {
33437 unsigned long uninitialized_var(pfn_align);
33438 int i, nid;
33439diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
33440index 36de293..b820ddc 100644
33441--- a/arch/x86/mm/pageattr.c
33442+++ b/arch/x86/mm/pageattr.c
33443@@ -262,7 +262,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
33444 */
33445 #ifdef CONFIG_PCI_BIOS
33446 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
33447- pgprot_val(forbidden) |= _PAGE_NX;
33448+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
33449 #endif
33450
33451 /*
33452@@ -270,9 +270,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
33453 * Does not cover __inittext since that is gone later on. On
33454 * 64bit we do not enforce !NX on the low mapping
33455 */
33456- if (within(address, (unsigned long)_text, (unsigned long)_etext))
33457- pgprot_val(forbidden) |= _PAGE_NX;
33458+ if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
33459+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
33460
33461+#ifdef CONFIG_DEBUG_RODATA
33462 /*
33463 * The .rodata section needs to be read-only. Using the pfn
33464 * catches all aliases.
33465@@ -280,6 +281,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
33466 if (within(pfn, __pa_symbol(__start_rodata) >> PAGE_SHIFT,
33467 __pa_symbol(__end_rodata) >> PAGE_SHIFT))
33468 pgprot_val(forbidden) |= _PAGE_RW;
33469+#endif
33470
33471 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
33472 /*
33473@@ -318,6 +320,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
33474 }
33475 #endif
33476
33477+#ifdef CONFIG_PAX_KERNEXEC
33478+ if (within(pfn, __pa(ktla_ktva((unsigned long)&_text)), __pa((unsigned long)&_sdata))) {
33479+ pgprot_val(forbidden) |= _PAGE_RW;
33480+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
33481+ }
33482+#endif
33483+
33484 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
33485
33486 return prot;
33487@@ -420,23 +429,37 @@ EXPORT_SYMBOL_GPL(slow_virt_to_phys);
33488 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
33489 {
33490 /* change init_mm */
33491+ pax_open_kernel();
33492 set_pte_atomic(kpte, pte);
33493+
33494 #ifdef CONFIG_X86_32
33495 if (!SHARED_KERNEL_PMD) {
33496+
33497+#ifdef CONFIG_PAX_PER_CPU_PGD
33498+ unsigned long cpu;
33499+#else
33500 struct page *page;
33501+#endif
33502
33503+#ifdef CONFIG_PAX_PER_CPU_PGD
33504+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
33505+ pgd_t *pgd = get_cpu_pgd(cpu, kernel);
33506+#else
33507 list_for_each_entry(page, &pgd_list, lru) {
33508- pgd_t *pgd;
33509+ pgd_t *pgd = (pgd_t *)page_address(page);
33510+#endif
33511+
33512 pud_t *pud;
33513 pmd_t *pmd;
33514
33515- pgd = (pgd_t *)page_address(page) + pgd_index(address);
33516+ pgd += pgd_index(address);
33517 pud = pud_offset(pgd, address);
33518 pmd = pmd_offset(pud, address);
33519 set_pte_atomic((pte_t *)pmd, pte);
33520 }
33521 }
33522 #endif
33523+ pax_close_kernel();
33524 }
33525
33526 static int
33527diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
33528index 6574388..87e9bef 100644
33529--- a/arch/x86/mm/pat.c
33530+++ b/arch/x86/mm/pat.c
33531@@ -376,7 +376,7 @@ int free_memtype(u64 start, u64 end)
33532
33533 if (!entry) {
33534 printk(KERN_INFO "%s:%d freeing invalid memtype [mem %#010Lx-%#010Lx]\n",
33535- current->comm, current->pid, start, end - 1);
33536+ current->comm, task_pid_nr(current), start, end - 1);
33537 return -EINVAL;
33538 }
33539
33540@@ -506,8 +506,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
33541
33542 while (cursor < to) {
33543 if (!devmem_is_allowed(pfn)) {
33544- printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx]\n",
33545- current->comm, from, to - 1);
33546+ printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx] (%#010Lx)\n",
33547+ current->comm, from, to - 1, cursor);
33548 return 0;
33549 }
33550 cursor += PAGE_SIZE;
33551@@ -577,7 +577,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
33552 if (ioremap_change_attr((unsigned long)__va(base), id_sz, flags) < 0) {
33553 printk(KERN_INFO "%s:%d ioremap_change_attr failed %s "
33554 "for [mem %#010Lx-%#010Lx]\n",
33555- current->comm, current->pid,
33556+ current->comm, task_pid_nr(current),
33557 cattr_name(flags),
33558 base, (unsigned long long)(base + size-1));
33559 return -EINVAL;
33560@@ -612,7 +612,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
33561 flags = lookup_memtype(paddr);
33562 if (want_flags != flags) {
33563 printk(KERN_WARNING "%s:%d map pfn RAM range req %s for [mem %#010Lx-%#010Lx], got %s\n",
33564- current->comm, current->pid,
33565+ current->comm, task_pid_nr(current),
33566 cattr_name(want_flags),
33567 (unsigned long long)paddr,
33568 (unsigned long long)(paddr + size - 1),
33569@@ -634,7 +634,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
33570 free_memtype(paddr, paddr + size);
33571 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
33572 " for [mem %#010Lx-%#010Lx], got %s\n",
33573- current->comm, current->pid,
33574+ current->comm, task_pid_nr(current),
33575 cattr_name(want_flags),
33576 (unsigned long long)paddr,
33577 (unsigned long long)(paddr + size - 1),
33578diff --git a/arch/x86/mm/pat_rbtree.c b/arch/x86/mm/pat_rbtree.c
33579index 415f6c4..d319983 100644
33580--- a/arch/x86/mm/pat_rbtree.c
33581+++ b/arch/x86/mm/pat_rbtree.c
33582@@ -160,7 +160,7 @@ success:
33583
33584 failure:
33585 printk(KERN_INFO "%s:%d conflicting memory types "
33586- "%Lx-%Lx %s<->%s\n", current->comm, current->pid, start,
33587+ "%Lx-%Lx %s<->%s\n", current->comm, task_pid_nr(current), start,
33588 end, cattr_name(found_type), cattr_name(match->type));
33589 return -EBUSY;
33590 }
33591diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
33592index 9f0614d..92ae64a 100644
33593--- a/arch/x86/mm/pf_in.c
33594+++ b/arch/x86/mm/pf_in.c
33595@@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
33596 int i;
33597 enum reason_type rv = OTHERS;
33598
33599- p = (unsigned char *)ins_addr;
33600+ p = (unsigned char *)ktla_ktva(ins_addr);
33601 p += skip_prefix(p, &prf);
33602 p += get_opcode(p, &opcode);
33603
33604@@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
33605 struct prefix_bits prf;
33606 int i;
33607
33608- p = (unsigned char *)ins_addr;
33609+ p = (unsigned char *)ktla_ktva(ins_addr);
33610 p += skip_prefix(p, &prf);
33611 p += get_opcode(p, &opcode);
33612
33613@@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
33614 struct prefix_bits prf;
33615 int i;
33616
33617- p = (unsigned char *)ins_addr;
33618+ p = (unsigned char *)ktla_ktva(ins_addr);
33619 p += skip_prefix(p, &prf);
33620 p += get_opcode(p, &opcode);
33621
33622@@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
33623 struct prefix_bits prf;
33624 int i;
33625
33626- p = (unsigned char *)ins_addr;
33627+ p = (unsigned char *)ktla_ktva(ins_addr);
33628 p += skip_prefix(p, &prf);
33629 p += get_opcode(p, &opcode);
33630 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
33631@@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
33632 struct prefix_bits prf;
33633 int i;
33634
33635- p = (unsigned char *)ins_addr;
33636+ p = (unsigned char *)ktla_ktva(ins_addr);
33637 p += skip_prefix(p, &prf);
33638 p += get_opcode(p, &opcode);
33639 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
33640diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
33641index 6fb6927..4fc13c0 100644
33642--- a/arch/x86/mm/pgtable.c
33643+++ b/arch/x86/mm/pgtable.c
33644@@ -97,10 +97,71 @@ static inline void pgd_list_del(pgd_t *pgd)
33645 list_del(&page->lru);
33646 }
33647
33648-#define UNSHARED_PTRS_PER_PGD \
33649- (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
33650+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
33651+pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
33652
33653+void __shadow_user_pgds(pgd_t *dst, const pgd_t *src)
33654+{
33655+ unsigned int count = USER_PGD_PTRS;
33656
33657+ if (!pax_user_shadow_base)
33658+ return;
33659+
33660+ while (count--)
33661+ *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
33662+}
33663+#endif
33664+
33665+#ifdef CONFIG_PAX_PER_CPU_PGD
33666+void __clone_user_pgds(pgd_t *dst, const pgd_t *src)
33667+{
33668+ unsigned int count = USER_PGD_PTRS;
33669+
33670+ while (count--) {
33671+ pgd_t pgd;
33672+
33673+#ifdef CONFIG_X86_64
33674+ pgd = __pgd(pgd_val(*src++) | _PAGE_USER);
33675+#else
33676+ pgd = *src++;
33677+#endif
33678+
33679+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
33680+ pgd = __pgd(pgd_val(pgd) & clone_pgd_mask);
33681+#endif
33682+
33683+ *dst++ = pgd;
33684+ }
33685+
33686+}
33687+#endif
33688+
33689+#ifdef CONFIG_X86_64
33690+#define pxd_t pud_t
33691+#define pyd_t pgd_t
33692+#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
33693+#define pgtable_pxd_page_ctor(page) true
33694+#define pgtable_pxd_page_dtor(page)
33695+#define pxd_free(mm, pud) pud_free((mm), (pud))
33696+#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
33697+#define pyd_offset(mm, address) pgd_offset((mm), (address))
33698+#define PYD_SIZE PGDIR_SIZE
33699+#else
33700+#define pxd_t pmd_t
33701+#define pyd_t pud_t
33702+#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
33703+#define pgtable_pxd_page_ctor(page) pgtable_pmd_page_ctor(page)
33704+#define pgtable_pxd_page_dtor(page) pgtable_pmd_page_dtor(page)
33705+#define pxd_free(mm, pud) pmd_free((mm), (pud))
33706+#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
33707+#define pyd_offset(mm, address) pud_offset((mm), (address))
33708+#define PYD_SIZE PUD_SIZE
33709+#endif
33710+
33711+#ifdef CONFIG_PAX_PER_CPU_PGD
33712+static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
33713+static inline void pgd_dtor(pgd_t *pgd) {}
33714+#else
33715 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
33716 {
33717 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
33718@@ -141,6 +202,7 @@ static void pgd_dtor(pgd_t *pgd)
33719 pgd_list_del(pgd);
33720 spin_unlock(&pgd_lock);
33721 }
33722+#endif
33723
33724 /*
33725 * List of all pgd's needed for non-PAE so it can invalidate entries
33726@@ -153,7 +215,7 @@ static void pgd_dtor(pgd_t *pgd)
33727 * -- nyc
33728 */
33729
33730-#ifdef CONFIG_X86_PAE
33731+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
33732 /*
33733 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
33734 * updating the top-level pagetable entries to guarantee the
33735@@ -165,7 +227,7 @@ static void pgd_dtor(pgd_t *pgd)
33736 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
33737 * and initialize the kernel pmds here.
33738 */
33739-#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
33740+#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
33741
33742 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
33743 {
33744@@ -183,43 +245,45 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
33745 */
33746 flush_tlb_mm(mm);
33747 }
33748+#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
33749+#define PREALLOCATED_PXDS USER_PGD_PTRS
33750 #else /* !CONFIG_X86_PAE */
33751
33752 /* No need to prepopulate any pagetable entries in non-PAE modes. */
33753-#define PREALLOCATED_PMDS 0
33754+#define PREALLOCATED_PXDS 0
33755
33756 #endif /* CONFIG_X86_PAE */
33757
33758-static void free_pmds(pmd_t *pmds[])
33759+static void free_pxds(pxd_t *pxds[])
33760 {
33761 int i;
33762
33763- for(i = 0; i < PREALLOCATED_PMDS; i++)
33764- if (pmds[i]) {
33765- pgtable_pmd_page_dtor(virt_to_page(pmds[i]));
33766- free_page((unsigned long)pmds[i]);
33767+ for(i = 0; i < PREALLOCATED_PXDS; i++)
33768+ if (pxds[i]) {
33769+ pgtable_pxd_page_dtor(virt_to_page(pxds[i]));
33770+ free_page((unsigned long)pxds[i]);
33771 }
33772 }
33773
33774-static int preallocate_pmds(pmd_t *pmds[])
33775+static int preallocate_pxds(pxd_t *pxds[])
33776 {
33777 int i;
33778 bool failed = false;
33779
33780- for(i = 0; i < PREALLOCATED_PMDS; i++) {
33781- pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
33782- if (!pmd)
33783+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
33784+ pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
33785+ if (!pxd)
33786 failed = true;
33787- if (pmd && !pgtable_pmd_page_ctor(virt_to_page(pmd))) {
33788- free_page((unsigned long)pmd);
33789- pmd = NULL;
33790+ if (pxd && !pgtable_pxd_page_ctor(virt_to_page(pxd))) {
33791+ free_page((unsigned long)pxd);
33792+ pxd = NULL;
33793 failed = true;
33794 }
33795- pmds[i] = pmd;
33796+ pxds[i] = pxd;
33797 }
33798
33799 if (failed) {
33800- free_pmds(pmds);
33801+ free_pxds(pxds);
33802 return -ENOMEM;
33803 }
33804
33805@@ -232,49 +296,52 @@ static int preallocate_pmds(pmd_t *pmds[])
33806 * preallocate which never got a corresponding vma will need to be
33807 * freed manually.
33808 */
33809-static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
33810+static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
33811 {
33812 int i;
33813
33814- for(i = 0; i < PREALLOCATED_PMDS; i++) {
33815+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
33816 pgd_t pgd = pgdp[i];
33817
33818 if (pgd_val(pgd) != 0) {
33819- pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
33820+ pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
33821
33822- pgdp[i] = native_make_pgd(0);
33823+ set_pgd(pgdp + i, native_make_pgd(0));
33824
33825- paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
33826- pmd_free(mm, pmd);
33827+ paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
33828+ pxd_free(mm, pxd);
33829 }
33830 }
33831 }
33832
33833-static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
33834+static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
33835 {
33836- pud_t *pud;
33837+ pyd_t *pyd;
33838 int i;
33839
33840- if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
33841+ if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
33842 return;
33843
33844- pud = pud_offset(pgd, 0);
33845-
33846- for (i = 0; i < PREALLOCATED_PMDS; i++, pud++) {
33847- pmd_t *pmd = pmds[i];
33848+#ifdef CONFIG_X86_64
33849+ pyd = pyd_offset(mm, 0L);
33850+#else
33851+ pyd = pyd_offset(pgd, 0L);
33852+#endif
33853
33854+ for (i = 0; i < PREALLOCATED_PXDS; i++, pyd++) {
33855+ pxd_t *pxd = pxds[i];
33856 if (i >= KERNEL_PGD_BOUNDARY)
33857- memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
33858- sizeof(pmd_t) * PTRS_PER_PMD);
33859+ memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
33860+ sizeof(pxd_t) * PTRS_PER_PMD);
33861
33862- pud_populate(mm, pud, pmd);
33863+ pyd_populate(mm, pyd, pxd);
33864 }
33865 }
33866
33867 pgd_t *pgd_alloc(struct mm_struct *mm)
33868 {
33869 pgd_t *pgd;
33870- pmd_t *pmds[PREALLOCATED_PMDS];
33871+ pxd_t *pxds[PREALLOCATED_PXDS];
33872
33873 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
33874
33875@@ -283,11 +350,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
33876
33877 mm->pgd = pgd;
33878
33879- if (preallocate_pmds(pmds) != 0)
33880+ if (preallocate_pxds(pxds) != 0)
33881 goto out_free_pgd;
33882
33883 if (paravirt_pgd_alloc(mm) != 0)
33884- goto out_free_pmds;
33885+ goto out_free_pxds;
33886
33887 /*
33888 * Make sure that pre-populating the pmds is atomic with
33889@@ -297,14 +364,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
33890 spin_lock(&pgd_lock);
33891
33892 pgd_ctor(mm, pgd);
33893- pgd_prepopulate_pmd(mm, pgd, pmds);
33894+ pgd_prepopulate_pxd(mm, pgd, pxds);
33895
33896 spin_unlock(&pgd_lock);
33897
33898 return pgd;
33899
33900-out_free_pmds:
33901- free_pmds(pmds);
33902+out_free_pxds:
33903+ free_pxds(pxds);
33904 out_free_pgd:
33905 free_page((unsigned long)pgd);
33906 out:
33907@@ -313,7 +380,7 @@ out:
33908
33909 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
33910 {
33911- pgd_mop_up_pmds(mm, pgd);
33912+ pgd_mop_up_pxds(mm, pgd);
33913 pgd_dtor(pgd);
33914 paravirt_pgd_free(mm, pgd);
33915 free_page((unsigned long)pgd);
33916diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
33917index 75cc097..79a097f 100644
33918--- a/arch/x86/mm/pgtable_32.c
33919+++ b/arch/x86/mm/pgtable_32.c
33920@@ -47,10 +47,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
33921 return;
33922 }
33923 pte = pte_offset_kernel(pmd, vaddr);
33924+
33925+ pax_open_kernel();
33926 if (pte_val(pteval))
33927 set_pte_at(&init_mm, vaddr, pte, pteval);
33928 else
33929 pte_clear(&init_mm, vaddr, pte);
33930+ pax_close_kernel();
33931
33932 /*
33933 * It's enough to flush this one mapping.
33934diff --git a/arch/x86/mm/physaddr.c b/arch/x86/mm/physaddr.c
33935index e666cbb..61788c45 100644
33936--- a/arch/x86/mm/physaddr.c
33937+++ b/arch/x86/mm/physaddr.c
33938@@ -10,7 +10,7 @@
33939 #ifdef CONFIG_X86_64
33940
33941 #ifdef CONFIG_DEBUG_VIRTUAL
33942-unsigned long __phys_addr(unsigned long x)
33943+unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
33944 {
33945 unsigned long y = x - __START_KERNEL_map;
33946
33947@@ -67,7 +67,7 @@ EXPORT_SYMBOL(__virt_addr_valid);
33948 #else
33949
33950 #ifdef CONFIG_DEBUG_VIRTUAL
33951-unsigned long __phys_addr(unsigned long x)
33952+unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
33953 {
33954 unsigned long phys_addr = x - PAGE_OFFSET;
33955 /* VMALLOC_* aren't constants */
33956diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
33957index 90555bf..f5f1828 100644
33958--- a/arch/x86/mm/setup_nx.c
33959+++ b/arch/x86/mm/setup_nx.c
33960@@ -5,8 +5,10 @@
33961 #include <asm/pgtable.h>
33962 #include <asm/proto.h>
33963
33964+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
33965 static int disable_nx;
33966
33967+#ifndef CONFIG_PAX_PAGEEXEC
33968 /*
33969 * noexec = on|off
33970 *
33971@@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
33972 return 0;
33973 }
33974 early_param("noexec", noexec_setup);
33975+#endif
33976+
33977+#endif
33978
33979 void x86_configure_nx(void)
33980 {
33981+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
33982 if (cpu_has_nx && !disable_nx)
33983 __supported_pte_mask |= _PAGE_NX;
33984 else
33985+#endif
33986 __supported_pte_mask &= ~_PAGE_NX;
33987 }
33988
33989diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
33990index ee61c36..e6fedeb 100644
33991--- a/arch/x86/mm/tlb.c
33992+++ b/arch/x86/mm/tlb.c
33993@@ -48,7 +48,11 @@ void leave_mm(int cpu)
33994 BUG();
33995 if (cpumask_test_cpu(cpu, mm_cpumask(active_mm))) {
33996 cpumask_clear_cpu(cpu, mm_cpumask(active_mm));
33997+
33998+#ifndef CONFIG_PAX_PER_CPU_PGD
33999 load_cr3(swapper_pg_dir);
34000+#endif
34001+
34002 /*
34003 * This gets called in the idle path where RCU
34004 * functions differently. Tracing normally
34005diff --git a/arch/x86/mm/uderef_64.c b/arch/x86/mm/uderef_64.c
34006new file mode 100644
34007index 0000000..dace51c
34008--- /dev/null
34009+++ b/arch/x86/mm/uderef_64.c
34010@@ -0,0 +1,37 @@
34011+#include <linux/mm.h>
34012+#include <asm/pgtable.h>
34013+#include <asm/uaccess.h>
34014+
34015+#ifdef CONFIG_PAX_MEMORY_UDEREF
34016+/* PaX: due to the special call convention these functions must
34017+ * - remain leaf functions under all configurations,
34018+ * - never be called directly, only dereferenced from the wrappers.
34019+ */
34020+void __pax_open_userland(void)
34021+{
34022+ unsigned int cpu;
34023+
34024+ if (unlikely(!segment_eq(get_fs(), USER_DS)))
34025+ return;
34026+
34027+ cpu = raw_get_cpu();
34028+ BUG_ON((read_cr3() & ~PAGE_MASK) != PCID_KERNEL);
34029+ write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER | PCID_NOFLUSH);
34030+ raw_put_cpu_no_resched();
34031+}
34032+EXPORT_SYMBOL(__pax_open_userland);
34033+
34034+void __pax_close_userland(void)
34035+{
34036+ unsigned int cpu;
34037+
34038+ if (unlikely(!segment_eq(get_fs(), USER_DS)))
34039+ return;
34040+
34041+ cpu = raw_get_cpu();
34042+ BUG_ON((read_cr3() & ~PAGE_MASK) != PCID_USER);
34043+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
34044+ raw_put_cpu_no_resched();
34045+}
34046+EXPORT_SYMBOL(__pax_close_userland);
34047+#endif
34048diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
34049index 6440221..f84b5c7 100644
34050--- a/arch/x86/net/bpf_jit.S
34051+++ b/arch/x86/net/bpf_jit.S
34052@@ -9,6 +9,7 @@
34053 */
34054 #include <linux/linkage.h>
34055 #include <asm/dwarf2.h>
34056+#include <asm/alternative-asm.h>
34057
34058 /*
34059 * Calling convention :
34060@@ -38,6 +39,7 @@ sk_load_word_positive_offset:
34061 jle bpf_slow_path_word
34062 mov (SKBDATA,%rsi),%eax
34063 bswap %eax /* ntohl() */
34064+ pax_force_retaddr
34065 ret
34066
34067 sk_load_half:
34068@@ -55,6 +57,7 @@ sk_load_half_positive_offset:
34069 jle bpf_slow_path_half
34070 movzwl (SKBDATA,%rsi),%eax
34071 rol $8,%ax # ntohs()
34072+ pax_force_retaddr
34073 ret
34074
34075 sk_load_byte:
34076@@ -69,6 +72,7 @@ sk_load_byte_positive_offset:
34077 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
34078 jle bpf_slow_path_byte
34079 movzbl (SKBDATA,%rsi),%eax
34080+ pax_force_retaddr
34081 ret
34082
34083 /* rsi contains offset and can be scratched */
34084@@ -90,6 +94,7 @@ bpf_slow_path_word:
34085 js bpf_error
34086 mov - MAX_BPF_STACK + 32(%rbp),%eax
34087 bswap %eax
34088+ pax_force_retaddr
34089 ret
34090
34091 bpf_slow_path_half:
34092@@ -98,12 +103,14 @@ bpf_slow_path_half:
34093 mov - MAX_BPF_STACK + 32(%rbp),%ax
34094 rol $8,%ax
34095 movzwl %ax,%eax
34096+ pax_force_retaddr
34097 ret
34098
34099 bpf_slow_path_byte:
34100 bpf_slow_path_common(1)
34101 js bpf_error
34102 movzbl - MAX_BPF_STACK + 32(%rbp),%eax
34103+ pax_force_retaddr
34104 ret
34105
34106 #define sk_negative_common(SIZE) \
34107@@ -126,6 +133,7 @@ sk_load_word_negative_offset:
34108 sk_negative_common(4)
34109 mov (%rax), %eax
34110 bswap %eax
34111+ pax_force_retaddr
34112 ret
34113
34114 bpf_slow_path_half_neg:
34115@@ -137,6 +145,7 @@ sk_load_half_negative_offset:
34116 mov (%rax),%ax
34117 rol $8,%ax
34118 movzwl %ax,%eax
34119+ pax_force_retaddr
34120 ret
34121
34122 bpf_slow_path_byte_neg:
34123@@ -146,6 +155,7 @@ sk_load_byte_negative_offset:
34124 .globl sk_load_byte_negative_offset
34125 sk_negative_common(1)
34126 movzbl (%rax), %eax
34127+ pax_force_retaddr
34128 ret
34129
34130 bpf_error:
34131@@ -156,4 +166,5 @@ bpf_error:
34132 mov - MAX_BPF_STACK + 16(%rbp),%r14
34133 mov - MAX_BPF_STACK + 24(%rbp),%r15
34134 leaveq
34135+ pax_force_retaddr
34136 ret
34137diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
34138index 3f62734..a57894f 100644
34139--- a/arch/x86/net/bpf_jit_comp.c
34140+++ b/arch/x86/net/bpf_jit_comp.c
34141@@ -13,7 +13,11 @@
34142 #include <linux/if_vlan.h>
34143 #include <asm/cacheflush.h>
34144
34145+#ifdef CONFIG_GRKERNSEC_BPF_HARDEN
34146+int bpf_jit_enable __read_only;
34147+#else
34148 int bpf_jit_enable __read_mostly;
34149+#endif
34150
34151 /*
34152 * assembly code in arch/x86/net/bpf_jit.S
34153@@ -174,7 +178,9 @@ static inline u8 add_2reg(u8 byte, u32 dst_reg, u32 src_reg)
34154 static void jit_fill_hole(void *area, unsigned int size)
34155 {
34156 /* fill whole space with int3 instructions */
34157+ pax_open_kernel();
34158 memset(area, 0xcc, size);
34159+ pax_close_kernel();
34160 }
34161
34162 struct jit_context {
34163@@ -894,7 +900,9 @@ common_load:
34164 pr_err("bpf_jit_compile fatal error\n");
34165 return -EFAULT;
34166 }
34167+ pax_open_kernel();
34168 memcpy(image + proglen, temp, ilen);
34169+ pax_close_kernel();
34170 }
34171 proglen += ilen;
34172 addrs[i] = proglen;
34173@@ -966,7 +974,6 @@ void bpf_int_jit_compile(struct bpf_prog *prog)
34174
34175 if (image) {
34176 bpf_flush_icache(header, image + proglen);
34177- set_memory_ro((unsigned long)header, header->pages);
34178 prog->bpf_func = (void *)image;
34179 prog->jited = true;
34180 }
34181@@ -979,12 +986,8 @@ void bpf_jit_free(struct bpf_prog *fp)
34182 unsigned long addr = (unsigned long)fp->bpf_func & PAGE_MASK;
34183 struct bpf_binary_header *header = (void *)addr;
34184
34185- if (!fp->jited)
34186- goto free_filter;
34187+ if (fp->jited)
34188+ bpf_jit_binary_free(header);
34189
34190- set_memory_rw(addr, header->pages);
34191- bpf_jit_binary_free(header);
34192-
34193-free_filter:
34194 bpf_prog_unlock_free(fp);
34195 }
34196diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
34197index 5d04be5..2beeaa2 100644
34198--- a/arch/x86/oprofile/backtrace.c
34199+++ b/arch/x86/oprofile/backtrace.c
34200@@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
34201 struct stack_frame_ia32 *fp;
34202 unsigned long bytes;
34203
34204- bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
34205+ bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
34206 if (bytes != 0)
34207 return NULL;
34208
34209- fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
34210+ fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
34211
34212 oprofile_add_trace(bufhead[0].return_address);
34213
34214@@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
34215 struct stack_frame bufhead[2];
34216 unsigned long bytes;
34217
34218- bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
34219+ bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
34220 if (bytes != 0)
34221 return NULL;
34222
34223@@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
34224 {
34225 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
34226
34227- if (!user_mode_vm(regs)) {
34228+ if (!user_mode(regs)) {
34229 unsigned long stack = kernel_stack_pointer(regs);
34230 if (depth)
34231 dump_trace(NULL, regs, (unsigned long *)stack, 0,
34232diff --git a/arch/x86/oprofile/nmi_int.c b/arch/x86/oprofile/nmi_int.c
34233index 1d2e639..f6ef82a 100644
34234--- a/arch/x86/oprofile/nmi_int.c
34235+++ b/arch/x86/oprofile/nmi_int.c
34236@@ -23,6 +23,7 @@
34237 #include <asm/nmi.h>
34238 #include <asm/msr.h>
34239 #include <asm/apic.h>
34240+#include <asm/pgtable.h>
34241
34242 #include "op_counter.h"
34243 #include "op_x86_model.h"
34244@@ -785,8 +786,11 @@ int __init op_nmi_init(struct oprofile_operations *ops)
34245 if (ret)
34246 return ret;
34247
34248- if (!model->num_virt_counters)
34249- model->num_virt_counters = model->num_counters;
34250+ if (!model->num_virt_counters) {
34251+ pax_open_kernel();
34252+ *(unsigned int *)&model->num_virt_counters = model->num_counters;
34253+ pax_close_kernel();
34254+ }
34255
34256 mux_init(ops);
34257
34258diff --git a/arch/x86/oprofile/op_model_amd.c b/arch/x86/oprofile/op_model_amd.c
34259index 50d86c0..7985318 100644
34260--- a/arch/x86/oprofile/op_model_amd.c
34261+++ b/arch/x86/oprofile/op_model_amd.c
34262@@ -519,9 +519,11 @@ static int op_amd_init(struct oprofile_operations *ops)
34263 num_counters = AMD64_NUM_COUNTERS;
34264 }
34265
34266- op_amd_spec.num_counters = num_counters;
34267- op_amd_spec.num_controls = num_counters;
34268- op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
34269+ pax_open_kernel();
34270+ *(unsigned int *)&op_amd_spec.num_counters = num_counters;
34271+ *(unsigned int *)&op_amd_spec.num_controls = num_counters;
34272+ *(unsigned int *)&op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
34273+ pax_close_kernel();
34274
34275 return 0;
34276 }
34277diff --git a/arch/x86/oprofile/op_model_ppro.c b/arch/x86/oprofile/op_model_ppro.c
34278index d90528e..0127e2b 100644
34279--- a/arch/x86/oprofile/op_model_ppro.c
34280+++ b/arch/x86/oprofile/op_model_ppro.c
34281@@ -19,6 +19,7 @@
34282 #include <asm/msr.h>
34283 #include <asm/apic.h>
34284 #include <asm/nmi.h>
34285+#include <asm/pgtable.h>
34286
34287 #include "op_x86_model.h"
34288 #include "op_counter.h"
34289@@ -221,8 +222,10 @@ static void arch_perfmon_setup_counters(void)
34290
34291 num_counters = min((int)eax.split.num_counters, OP_MAX_COUNTER);
34292
34293- op_arch_perfmon_spec.num_counters = num_counters;
34294- op_arch_perfmon_spec.num_controls = num_counters;
34295+ pax_open_kernel();
34296+ *(unsigned int *)&op_arch_perfmon_spec.num_counters = num_counters;
34297+ *(unsigned int *)&op_arch_perfmon_spec.num_controls = num_counters;
34298+ pax_close_kernel();
34299 }
34300
34301 static int arch_perfmon_init(struct oprofile_operations *ignore)
34302diff --git a/arch/x86/oprofile/op_x86_model.h b/arch/x86/oprofile/op_x86_model.h
34303index 71e8a67..6a313bb 100644
34304--- a/arch/x86/oprofile/op_x86_model.h
34305+++ b/arch/x86/oprofile/op_x86_model.h
34306@@ -52,7 +52,7 @@ struct op_x86_model_spec {
34307 void (*switch_ctrl)(struct op_x86_model_spec const *model,
34308 struct op_msrs const * const msrs);
34309 #endif
34310-};
34311+} __do_const;
34312
34313 struct op_counter_config;
34314
34315diff --git a/arch/x86/pci/intel_mid_pci.c b/arch/x86/pci/intel_mid_pci.c
34316index b9958c3..24229ab 100644
34317--- a/arch/x86/pci/intel_mid_pci.c
34318+++ b/arch/x86/pci/intel_mid_pci.c
34319@@ -250,7 +250,7 @@ int __init intel_mid_pci_init(void)
34320 pci_mmcfg_late_init();
34321 pcibios_enable_irq = intel_mid_pci_irq_enable;
34322 pcibios_disable_irq = intel_mid_pci_irq_disable;
34323- pci_root_ops = intel_mid_pci_ops;
34324+ memcpy((void *)&pci_root_ops, &intel_mid_pci_ops, sizeof pci_root_ops);
34325 pci_soc_mode = 1;
34326 /* Continue with standard init */
34327 return 1;
34328diff --git a/arch/x86/pci/irq.c b/arch/x86/pci/irq.c
34329index eb500c2..eab9e70 100644
34330--- a/arch/x86/pci/irq.c
34331+++ b/arch/x86/pci/irq.c
34332@@ -51,7 +51,7 @@ struct irq_router {
34333 struct irq_router_handler {
34334 u16 vendor;
34335 int (*probe)(struct irq_router *r, struct pci_dev *router, u16 device);
34336-};
34337+} __do_const;
34338
34339 int (*pcibios_enable_irq)(struct pci_dev *dev) = pirq_enable_irq;
34340 void (*pcibios_disable_irq)(struct pci_dev *dev) = pirq_disable_irq;
34341@@ -791,7 +791,7 @@ static __init int pico_router_probe(struct irq_router *r, struct pci_dev *router
34342 return 0;
34343 }
34344
34345-static __initdata struct irq_router_handler pirq_routers[] = {
34346+static __initconst const struct irq_router_handler pirq_routers[] = {
34347 { PCI_VENDOR_ID_INTEL, intel_router_probe },
34348 { PCI_VENDOR_ID_AL, ali_router_probe },
34349 { PCI_VENDOR_ID_ITE, ite_router_probe },
34350@@ -818,7 +818,7 @@ static struct pci_dev *pirq_router_dev;
34351 static void __init pirq_find_router(struct irq_router *r)
34352 {
34353 struct irq_routing_table *rt = pirq_table;
34354- struct irq_router_handler *h;
34355+ const struct irq_router_handler *h;
34356
34357 #ifdef CONFIG_PCI_BIOS
34358 if (!rt->signature) {
34359@@ -1091,7 +1091,7 @@ static int __init fix_acer_tm360_irqrouting(const struct dmi_system_id *d)
34360 return 0;
34361 }
34362
34363-static struct dmi_system_id __initdata pciirq_dmi_table[] = {
34364+static const struct dmi_system_id __initconst pciirq_dmi_table[] = {
34365 {
34366 .callback = fix_broken_hp_bios_irq9,
34367 .ident = "HP Pavilion N5400 Series Laptop",
34368diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
34369index 9b83b90..4112152 100644
34370--- a/arch/x86/pci/pcbios.c
34371+++ b/arch/x86/pci/pcbios.c
34372@@ -79,7 +79,7 @@ union bios32 {
34373 static struct {
34374 unsigned long address;
34375 unsigned short segment;
34376-} bios32_indirect __initdata = { 0, __KERNEL_CS };
34377+} bios32_indirect __initconst = { 0, __PCIBIOS_CS };
34378
34379 /*
34380 * Returns the entry point for the given service, NULL on error
34381@@ -92,37 +92,80 @@ static unsigned long __init bios32_service(unsigned long service)
34382 unsigned long length; /* %ecx */
34383 unsigned long entry; /* %edx */
34384 unsigned long flags;
34385+ struct desc_struct d, *gdt;
34386
34387 local_irq_save(flags);
34388- __asm__("lcall *(%%edi); cld"
34389+
34390+ gdt = get_cpu_gdt_table(smp_processor_id());
34391+
34392+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
34393+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
34394+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
34395+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
34396+
34397+ __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
34398 : "=a" (return_code),
34399 "=b" (address),
34400 "=c" (length),
34401 "=d" (entry)
34402 : "0" (service),
34403 "1" (0),
34404- "D" (&bios32_indirect));
34405+ "D" (&bios32_indirect),
34406+ "r"(__PCIBIOS_DS)
34407+ : "memory");
34408+
34409+ pax_open_kernel();
34410+ gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
34411+ gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
34412+ gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
34413+ gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
34414+ pax_close_kernel();
34415+
34416 local_irq_restore(flags);
34417
34418 switch (return_code) {
34419- case 0:
34420- return address + entry;
34421- case 0x80: /* Not present */
34422- printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
34423- return 0;
34424- default: /* Shouldn't happen */
34425- printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
34426- service, return_code);
34427+ case 0: {
34428+ int cpu;
34429+ unsigned char flags;
34430+
34431+ printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
34432+ if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
34433+ printk(KERN_WARNING "bios32_service: not valid\n");
34434 return 0;
34435+ }
34436+ address = address + PAGE_OFFSET;
34437+ length += 16UL; /* some BIOSs underreport this... */
34438+ flags = 4;
34439+ if (length >= 64*1024*1024) {
34440+ length >>= PAGE_SHIFT;
34441+ flags |= 8;
34442+ }
34443+
34444+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
34445+ gdt = get_cpu_gdt_table(cpu);
34446+ pack_descriptor(&d, address, length, 0x9b, flags);
34447+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
34448+ pack_descriptor(&d, address, length, 0x93, flags);
34449+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
34450+ }
34451+ return entry;
34452+ }
34453+ case 0x80: /* Not present */
34454+ printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
34455+ return 0;
34456+ default: /* Shouldn't happen */
34457+ printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
34458+ service, return_code);
34459+ return 0;
34460 }
34461 }
34462
34463 static struct {
34464 unsigned long address;
34465 unsigned short segment;
34466-} pci_indirect = { 0, __KERNEL_CS };
34467+} pci_indirect __read_only = { 0, __PCIBIOS_CS };
34468
34469-static int pci_bios_present;
34470+static int pci_bios_present __read_only;
34471
34472 static int __init check_pcibios(void)
34473 {
34474@@ -131,11 +174,13 @@ static int __init check_pcibios(void)
34475 unsigned long flags, pcibios_entry;
34476
34477 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
34478- pci_indirect.address = pcibios_entry + PAGE_OFFSET;
34479+ pci_indirect.address = pcibios_entry;
34480
34481 local_irq_save(flags);
34482- __asm__(
34483- "lcall *(%%edi); cld\n\t"
34484+ __asm__("movw %w6, %%ds\n\t"
34485+ "lcall *%%ss:(%%edi); cld\n\t"
34486+ "push %%ss\n\t"
34487+ "pop %%ds\n\t"
34488 "jc 1f\n\t"
34489 "xor %%ah, %%ah\n"
34490 "1:"
34491@@ -144,7 +189,8 @@ static int __init check_pcibios(void)
34492 "=b" (ebx),
34493 "=c" (ecx)
34494 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
34495- "D" (&pci_indirect)
34496+ "D" (&pci_indirect),
34497+ "r" (__PCIBIOS_DS)
34498 : "memory");
34499 local_irq_restore(flags);
34500
34501@@ -189,7 +235,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34502
34503 switch (len) {
34504 case 1:
34505- __asm__("lcall *(%%esi); cld\n\t"
34506+ __asm__("movw %w6, %%ds\n\t"
34507+ "lcall *%%ss:(%%esi); cld\n\t"
34508+ "push %%ss\n\t"
34509+ "pop %%ds\n\t"
34510 "jc 1f\n\t"
34511 "xor %%ah, %%ah\n"
34512 "1:"
34513@@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34514 : "1" (PCIBIOS_READ_CONFIG_BYTE),
34515 "b" (bx),
34516 "D" ((long)reg),
34517- "S" (&pci_indirect));
34518+ "S" (&pci_indirect),
34519+ "r" (__PCIBIOS_DS));
34520 /*
34521 * Zero-extend the result beyond 8 bits, do not trust the
34522 * BIOS having done it:
34523@@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34524 *value &= 0xff;
34525 break;
34526 case 2:
34527- __asm__("lcall *(%%esi); cld\n\t"
34528+ __asm__("movw %w6, %%ds\n\t"
34529+ "lcall *%%ss:(%%esi); cld\n\t"
34530+ "push %%ss\n\t"
34531+ "pop %%ds\n\t"
34532 "jc 1f\n\t"
34533 "xor %%ah, %%ah\n"
34534 "1:"
34535@@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34536 : "1" (PCIBIOS_READ_CONFIG_WORD),
34537 "b" (bx),
34538 "D" ((long)reg),
34539- "S" (&pci_indirect));
34540+ "S" (&pci_indirect),
34541+ "r" (__PCIBIOS_DS));
34542 /*
34543 * Zero-extend the result beyond 16 bits, do not trust the
34544 * BIOS having done it:
34545@@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34546 *value &= 0xffff;
34547 break;
34548 case 4:
34549- __asm__("lcall *(%%esi); cld\n\t"
34550+ __asm__("movw %w6, %%ds\n\t"
34551+ "lcall *%%ss:(%%esi); cld\n\t"
34552+ "push %%ss\n\t"
34553+ "pop %%ds\n\t"
34554 "jc 1f\n\t"
34555 "xor %%ah, %%ah\n"
34556 "1:"
34557@@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34558 : "1" (PCIBIOS_READ_CONFIG_DWORD),
34559 "b" (bx),
34560 "D" ((long)reg),
34561- "S" (&pci_indirect));
34562+ "S" (&pci_indirect),
34563+ "r" (__PCIBIOS_DS));
34564 break;
34565 }
34566
34567@@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
34568
34569 switch (len) {
34570 case 1:
34571- __asm__("lcall *(%%esi); cld\n\t"
34572+ __asm__("movw %w6, %%ds\n\t"
34573+ "lcall *%%ss:(%%esi); cld\n\t"
34574+ "push %%ss\n\t"
34575+ "pop %%ds\n\t"
34576 "jc 1f\n\t"
34577 "xor %%ah, %%ah\n"
34578 "1:"
34579@@ -265,10 +326,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
34580 "c" (value),
34581 "b" (bx),
34582 "D" ((long)reg),
34583- "S" (&pci_indirect));
34584+ "S" (&pci_indirect),
34585+ "r" (__PCIBIOS_DS));
34586 break;
34587 case 2:
34588- __asm__("lcall *(%%esi); cld\n\t"
34589+ __asm__("movw %w6, %%ds\n\t"
34590+ "lcall *%%ss:(%%esi); cld\n\t"
34591+ "push %%ss\n\t"
34592+ "pop %%ds\n\t"
34593 "jc 1f\n\t"
34594 "xor %%ah, %%ah\n"
34595 "1:"
34596@@ -277,10 +342,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
34597 "c" (value),
34598 "b" (bx),
34599 "D" ((long)reg),
34600- "S" (&pci_indirect));
34601+ "S" (&pci_indirect),
34602+ "r" (__PCIBIOS_DS));
34603 break;
34604 case 4:
34605- __asm__("lcall *(%%esi); cld\n\t"
34606+ __asm__("movw %w6, %%ds\n\t"
34607+ "lcall *%%ss:(%%esi); cld\n\t"
34608+ "push %%ss\n\t"
34609+ "pop %%ds\n\t"
34610 "jc 1f\n\t"
34611 "xor %%ah, %%ah\n"
34612 "1:"
34613@@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
34614 "c" (value),
34615 "b" (bx),
34616 "D" ((long)reg),
34617- "S" (&pci_indirect));
34618+ "S" (&pci_indirect),
34619+ "r" (__PCIBIOS_DS));
34620 break;
34621 }
34622
34623@@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
34624
34625 DBG("PCI: Fetching IRQ routing table... ");
34626 __asm__("push %%es\n\t"
34627+ "movw %w8, %%ds\n\t"
34628 "push %%ds\n\t"
34629 "pop %%es\n\t"
34630- "lcall *(%%esi); cld\n\t"
34631+ "lcall *%%ss:(%%esi); cld\n\t"
34632 "pop %%es\n\t"
34633+ "push %%ss\n\t"
34634+ "pop %%ds\n"
34635 "jc 1f\n\t"
34636 "xor %%ah, %%ah\n"
34637 "1:"
34638@@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
34639 "1" (0),
34640 "D" ((long) &opt),
34641 "S" (&pci_indirect),
34642- "m" (opt)
34643+ "m" (opt),
34644+ "r" (__PCIBIOS_DS)
34645 : "memory");
34646 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
34647 if (ret & 0xff00)
34648@@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
34649 {
34650 int ret;
34651
34652- __asm__("lcall *(%%esi); cld\n\t"
34653+ __asm__("movw %w5, %%ds\n\t"
34654+ "lcall *%%ss:(%%esi); cld\n\t"
34655+ "push %%ss\n\t"
34656+ "pop %%ds\n"
34657 "jc 1f\n\t"
34658 "xor %%ah, %%ah\n"
34659 "1:"
34660@@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
34661 : "0" (PCIBIOS_SET_PCI_HW_INT),
34662 "b" ((dev->bus->number << 8) | dev->devfn),
34663 "c" ((irq << 8) | (pin + 10)),
34664- "S" (&pci_indirect));
34665+ "S" (&pci_indirect),
34666+ "r" (__PCIBIOS_DS));
34667 return !(ret & 0xff00);
34668 }
34669 EXPORT_SYMBOL(pcibios_set_irq_routing);
34670diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
34671index 40e7cda..c7e6672 100644
34672--- a/arch/x86/platform/efi/efi_32.c
34673+++ b/arch/x86/platform/efi/efi_32.c
34674@@ -61,11 +61,22 @@ void __init efi_call_phys_prolog(void)
34675 {
34676 struct desc_ptr gdt_descr;
34677
34678+#ifdef CONFIG_PAX_KERNEXEC
34679+ struct desc_struct d;
34680+#endif
34681+
34682 local_irq_save(efi_rt_eflags);
34683
34684 load_cr3(initial_page_table);
34685 __flush_tlb_all();
34686
34687+#ifdef CONFIG_PAX_KERNEXEC
34688+ pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
34689+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
34690+ pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
34691+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
34692+#endif
34693+
34694 gdt_descr.address = __pa(get_cpu_gdt_table(0));
34695 gdt_descr.size = GDT_SIZE - 1;
34696 load_gdt(&gdt_descr);
34697@@ -75,11 +86,24 @@ void __init efi_call_phys_epilog(void)
34698 {
34699 struct desc_ptr gdt_descr;
34700
34701+#ifdef CONFIG_PAX_KERNEXEC
34702+ struct desc_struct d;
34703+
34704+ memset(&d, 0, sizeof d);
34705+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
34706+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
34707+#endif
34708+
34709 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
34710 gdt_descr.size = GDT_SIZE - 1;
34711 load_gdt(&gdt_descr);
34712
34713+#ifdef CONFIG_PAX_PER_CPU_PGD
34714+ load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
34715+#else
34716 load_cr3(swapper_pg_dir);
34717+#endif
34718+
34719 __flush_tlb_all();
34720
34721 local_irq_restore(efi_rt_eflags);
34722diff --git a/arch/x86/platform/efi/efi_64.c b/arch/x86/platform/efi/efi_64.c
34723index 35aecb6..46177db 100644
34724--- a/arch/x86/platform/efi/efi_64.c
34725+++ b/arch/x86/platform/efi/efi_64.c
34726@@ -99,6 +99,11 @@ void __init efi_call_phys_prolog(void)
34727 vaddress = (unsigned long)__va(pgd * PGDIR_SIZE);
34728 set_pgd(pgd_offset_k(pgd * PGDIR_SIZE), *pgd_offset_k(vaddress));
34729 }
34730+
34731+#ifdef CONFIG_PAX_PER_CPU_PGD
34732+ load_cr3(swapper_pg_dir);
34733+#endif
34734+
34735 __flush_tlb_all();
34736 }
34737
34738@@ -116,6 +121,11 @@ void __init efi_call_phys_epilog(void)
34739 for (pgd = 0; pgd < n_pgds; pgd++)
34740 set_pgd(pgd_offset_k(pgd * PGDIR_SIZE), save_pgd[pgd]);
34741 kfree(save_pgd);
34742+
34743+#ifdef CONFIG_PAX_PER_CPU_PGD
34744+ load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
34745+#endif
34746+
34747 __flush_tlb_all();
34748 local_irq_restore(efi_flags);
34749 early_code_mapping_set_exec(0);
34750@@ -146,8 +156,23 @@ int __init efi_setup_page_tables(unsigned long pa_memmap, unsigned num_pages)
34751 unsigned npages;
34752 pgd_t *pgd;
34753
34754- if (efi_enabled(EFI_OLD_MEMMAP))
34755+ if (efi_enabled(EFI_OLD_MEMMAP)) {
34756+ /* PaX: We need to disable the NX bit in the PGD, otherwise we won't be
34757+ * able to execute the EFI services.
34758+ */
34759+ if (__supported_pte_mask & _PAGE_NX) {
34760+ unsigned long addr = (unsigned long) __va(0);
34761+ pgd_t pe = __pgd(pgd_val(*pgd_offset_k(addr)) & ~_PAGE_NX);
34762+
34763+ pr_alert("PAX: Disabling NX protection for low memory map. Try booting without \"efi=old_map\"\n");
34764+#ifdef CONFIG_PAX_PER_CPU_PGD
34765+ set_pgd(pgd_offset_cpu(0, kernel, addr), pe);
34766+#endif
34767+ set_pgd(pgd_offset_k(addr), pe);
34768+ }
34769+
34770 return 0;
34771+ }
34772
34773 efi_scratch.efi_pgt = (pgd_t *)(unsigned long)real_mode_header->trampoline_pgd;
34774 pgd = __va(efi_scratch.efi_pgt);
34775diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
34776index 040192b..7d3300f 100644
34777--- a/arch/x86/platform/efi/efi_stub_32.S
34778+++ b/arch/x86/platform/efi/efi_stub_32.S
34779@@ -6,7 +6,9 @@
34780 */
34781
34782 #include <linux/linkage.h>
34783+#include <linux/init.h>
34784 #include <asm/page_types.h>
34785+#include <asm/segment.h>
34786
34787 /*
34788 * efi_call_phys(void *, ...) is a function with variable parameters.
34789@@ -20,7 +22,7 @@
34790 * service functions will comply with gcc calling convention, too.
34791 */
34792
34793-.text
34794+__INIT
34795 ENTRY(efi_call_phys)
34796 /*
34797 * 0. The function can only be called in Linux kernel. So CS has been
34798@@ -36,10 +38,24 @@ ENTRY(efi_call_phys)
34799 * The mapping of lower virtual memory has been created in prolog and
34800 * epilog.
34801 */
34802- movl $1f, %edx
34803- subl $__PAGE_OFFSET, %edx
34804- jmp *%edx
34805+#ifdef CONFIG_PAX_KERNEXEC
34806+ movl $(__KERNEXEC_EFI_DS), %edx
34807+ mov %edx, %ds
34808+ mov %edx, %es
34809+ mov %edx, %ss
34810+ addl $2f,(1f)
34811+ ljmp *(1f)
34812+
34813+__INITDATA
34814+1: .long __LOAD_PHYSICAL_ADDR, __KERNEXEC_EFI_CS
34815+.previous
34816+
34817+2:
34818+ subl $2b,(1b)
34819+#else
34820+ jmp 1f-__PAGE_OFFSET
34821 1:
34822+#endif
34823
34824 /*
34825 * 2. Now on the top of stack is the return
34826@@ -47,14 +63,8 @@ ENTRY(efi_call_phys)
34827 * parameter 2, ..., param n. To make things easy, we save the return
34828 * address of efi_call_phys in a global variable.
34829 */
34830- popl %edx
34831- movl %edx, saved_return_addr
34832- /* get the function pointer into ECX*/
34833- popl %ecx
34834- movl %ecx, efi_rt_function_ptr
34835- movl $2f, %edx
34836- subl $__PAGE_OFFSET, %edx
34837- pushl %edx
34838+ popl (saved_return_addr)
34839+ popl (efi_rt_function_ptr)
34840
34841 /*
34842 * 3. Clear PG bit in %CR0.
34843@@ -73,9 +83,8 @@ ENTRY(efi_call_phys)
34844 /*
34845 * 5. Call the physical function.
34846 */
34847- jmp *%ecx
34848+ call *(efi_rt_function_ptr-__PAGE_OFFSET)
34849
34850-2:
34851 /*
34852 * 6. After EFI runtime service returns, control will return to
34853 * following instruction. We'd better readjust stack pointer first.
34854@@ -88,35 +97,36 @@ ENTRY(efi_call_phys)
34855 movl %cr0, %edx
34856 orl $0x80000000, %edx
34857 movl %edx, %cr0
34858- jmp 1f
34859-1:
34860+
34861 /*
34862 * 8. Now restore the virtual mode from flat mode by
34863 * adding EIP with PAGE_OFFSET.
34864 */
34865- movl $1f, %edx
34866- jmp *%edx
34867+#ifdef CONFIG_PAX_KERNEXEC
34868+ movl $(__KERNEL_DS), %edx
34869+ mov %edx, %ds
34870+ mov %edx, %es
34871+ mov %edx, %ss
34872+ ljmp $(__KERNEL_CS),$1f
34873+#else
34874+ jmp 1f+__PAGE_OFFSET
34875+#endif
34876 1:
34877
34878 /*
34879 * 9. Balance the stack. And because EAX contain the return value,
34880 * we'd better not clobber it.
34881 */
34882- leal efi_rt_function_ptr, %edx
34883- movl (%edx), %ecx
34884- pushl %ecx
34885+ pushl (efi_rt_function_ptr)
34886
34887 /*
34888- * 10. Push the saved return address onto the stack and return.
34889+ * 10. Return to the saved return address.
34890 */
34891- leal saved_return_addr, %edx
34892- movl (%edx), %ecx
34893- pushl %ecx
34894- ret
34895+ jmpl *(saved_return_addr)
34896 ENDPROC(efi_call_phys)
34897 .previous
34898
34899-.data
34900+__INITDATA
34901 saved_return_addr:
34902 .long 0
34903 efi_rt_function_ptr:
34904diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
34905index 5fcda72..cd4dc41 100644
34906--- a/arch/x86/platform/efi/efi_stub_64.S
34907+++ b/arch/x86/platform/efi/efi_stub_64.S
34908@@ -11,6 +11,7 @@
34909 #include <asm/msr.h>
34910 #include <asm/processor-flags.h>
34911 #include <asm/page_types.h>
34912+#include <asm/alternative-asm.h>
34913
34914 #define SAVE_XMM \
34915 mov %rsp, %rax; \
34916@@ -88,6 +89,7 @@ ENTRY(efi_call)
34917 RESTORE_PGT
34918 addq $48, %rsp
34919 RESTORE_XMM
34920+ pax_force_retaddr 0, 1
34921 ret
34922 ENDPROC(efi_call)
34923
34924@@ -245,8 +247,8 @@ efi_gdt64:
34925 .long 0 /* Filled out by user */
34926 .word 0
34927 .quad 0x0000000000000000 /* NULL descriptor */
34928- .quad 0x00af9a000000ffff /* __KERNEL_CS */
34929- .quad 0x00cf92000000ffff /* __KERNEL_DS */
34930+ .quad 0x00af9b000000ffff /* __KERNEL_CS */
34931+ .quad 0x00cf93000000ffff /* __KERNEL_DS */
34932 .quad 0x0080890000000000 /* TS descriptor */
34933 .quad 0x0000000000000000 /* TS continued */
34934 efi_gdt64_end:
34935diff --git a/arch/x86/platform/intel-mid/intel-mid.c b/arch/x86/platform/intel-mid/intel-mid.c
34936index 1bbedc4..eb795b5 100644
34937--- a/arch/x86/platform/intel-mid/intel-mid.c
34938+++ b/arch/x86/platform/intel-mid/intel-mid.c
34939@@ -71,9 +71,10 @@ static void intel_mid_power_off(void)
34940 {
34941 };
34942
34943-static void intel_mid_reboot(void)
34944+static void __noreturn intel_mid_reboot(void)
34945 {
34946 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
34947+ BUG();
34948 }
34949
34950 static unsigned long __init intel_mid_calibrate_tsc(void)
34951diff --git a/arch/x86/platform/intel-mid/intel_mid_weak_decls.h b/arch/x86/platform/intel-mid/intel_mid_weak_decls.h
34952index 3c1c386..59a68ed 100644
34953--- a/arch/x86/platform/intel-mid/intel_mid_weak_decls.h
34954+++ b/arch/x86/platform/intel-mid/intel_mid_weak_decls.h
34955@@ -13,6 +13,6 @@
34956 /* For every CPU addition a new get_<cpuname>_ops interface needs
34957 * to be added.
34958 */
34959-extern void *get_penwell_ops(void);
34960-extern void *get_cloverview_ops(void);
34961-extern void *get_tangier_ops(void);
34962+extern const void *get_penwell_ops(void);
34963+extern const void *get_cloverview_ops(void);
34964+extern const void *get_tangier_ops(void);
34965diff --git a/arch/x86/platform/intel-mid/mfld.c b/arch/x86/platform/intel-mid/mfld.c
34966index 23381d2..8ddc10e 100644
34967--- a/arch/x86/platform/intel-mid/mfld.c
34968+++ b/arch/x86/platform/intel-mid/mfld.c
34969@@ -64,12 +64,12 @@ static void __init penwell_arch_setup(void)
34970 pm_power_off = mfld_power_off;
34971 }
34972
34973-void *get_penwell_ops(void)
34974+const void *get_penwell_ops(void)
34975 {
34976 return &penwell_ops;
34977 }
34978
34979-void *get_cloverview_ops(void)
34980+const void *get_cloverview_ops(void)
34981 {
34982 return &penwell_ops;
34983 }
34984diff --git a/arch/x86/platform/intel-mid/mrfl.c b/arch/x86/platform/intel-mid/mrfl.c
34985index aaca917..66eadbc 100644
34986--- a/arch/x86/platform/intel-mid/mrfl.c
34987+++ b/arch/x86/platform/intel-mid/mrfl.c
34988@@ -97,7 +97,7 @@ static struct intel_mid_ops tangier_ops = {
34989 .arch_setup = tangier_arch_setup,
34990 };
34991
34992-void *get_tangier_ops(void)
34993+const void *get_tangier_ops(void)
34994 {
34995 return &tangier_ops;
34996 }
34997diff --git a/arch/x86/platform/olpc/olpc_dt.c b/arch/x86/platform/olpc/olpc_dt.c
34998index d6ee929..3637cb5 100644
34999--- a/arch/x86/platform/olpc/olpc_dt.c
35000+++ b/arch/x86/platform/olpc/olpc_dt.c
35001@@ -156,7 +156,7 @@ void * __init prom_early_alloc(unsigned long size)
35002 return res;
35003 }
35004
35005-static struct of_pdt_ops prom_olpc_ops __initdata = {
35006+static struct of_pdt_ops prom_olpc_ops __initconst = {
35007 .nextprop = olpc_dt_nextprop,
35008 .getproplen = olpc_dt_getproplen,
35009 .getproperty = olpc_dt_getproperty,
35010diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
35011index 6ec7910..ecdbb11 100644
35012--- a/arch/x86/power/cpu.c
35013+++ b/arch/x86/power/cpu.c
35014@@ -137,11 +137,8 @@ static void do_fpu_end(void)
35015 static void fix_processor_context(void)
35016 {
35017 int cpu = smp_processor_id();
35018- struct tss_struct *t = &per_cpu(init_tss, cpu);
35019-#ifdef CONFIG_X86_64
35020- struct desc_struct *desc = get_cpu_gdt_table(cpu);
35021- tss_desc tss;
35022-#endif
35023+ struct tss_struct *t = init_tss + cpu;
35024+
35025 set_tss_desc(cpu, t); /*
35026 * This just modifies memory; should not be
35027 * necessary. But... This is necessary, because
35028@@ -150,10 +147,6 @@ static void fix_processor_context(void)
35029 */
35030
35031 #ifdef CONFIG_X86_64
35032- memcpy(&tss, &desc[GDT_ENTRY_TSS], sizeof(tss_desc));
35033- tss.type = 0x9; /* The available 64-bit TSS (see AMD vol 2, pg 91 */
35034- write_gdt_entry(desc, GDT_ENTRY_TSS, &tss, DESC_TSS);
35035-
35036 syscall_init(); /* This sets MSR_*STAR and related */
35037 #endif
35038 load_TR_desc(); /* This does ltr */
35039diff --git a/arch/x86/realmode/init.c b/arch/x86/realmode/init.c
35040index bad628a..a102610 100644
35041--- a/arch/x86/realmode/init.c
35042+++ b/arch/x86/realmode/init.c
35043@@ -68,7 +68,13 @@ void __init setup_real_mode(void)
35044 __va(real_mode_header->trampoline_header);
35045
35046 #ifdef CONFIG_X86_32
35047- trampoline_header->start = __pa_symbol(startup_32_smp);
35048+ trampoline_header->start = __pa_symbol(ktla_ktva(startup_32_smp));
35049+
35050+#ifdef CONFIG_PAX_KERNEXEC
35051+ trampoline_header->start -= LOAD_PHYSICAL_ADDR;
35052+#endif
35053+
35054+ trampoline_header->boot_cs = __BOOT_CS;
35055 trampoline_header->gdt_limit = __BOOT_DS + 7;
35056 trampoline_header->gdt_base = __pa_symbol(boot_gdt);
35057 #else
35058@@ -84,7 +90,7 @@ void __init setup_real_mode(void)
35059 *trampoline_cr4_features = read_cr4();
35060
35061 trampoline_pgd = (u64 *) __va(real_mode_header->trampoline_pgd);
35062- trampoline_pgd[0] = init_level4_pgt[pgd_index(__PAGE_OFFSET)].pgd;
35063+ trampoline_pgd[0] = init_level4_pgt[pgd_index(__PAGE_OFFSET)].pgd & ~_PAGE_NX;
35064 trampoline_pgd[511] = init_level4_pgt[511].pgd;
35065 #endif
35066 }
35067diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile
35068index 7c0d7be..d24dc88 100644
35069--- a/arch/x86/realmode/rm/Makefile
35070+++ b/arch/x86/realmode/rm/Makefile
35071@@ -67,5 +67,8 @@ $(obj)/realmode.relocs: $(obj)/realmode.elf FORCE
35072
35073 KBUILD_CFLAGS := $(LINUXINCLUDE) $(REALMODE_CFLAGS) -D_SETUP -D_WAKEUP \
35074 -I$(srctree)/arch/x86/boot
35075+ifdef CONSTIFY_PLUGIN
35076+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
35077+endif
35078 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
35079 GCOV_PROFILE := n
35080diff --git a/arch/x86/realmode/rm/header.S b/arch/x86/realmode/rm/header.S
35081index a28221d..93c40f1 100644
35082--- a/arch/x86/realmode/rm/header.S
35083+++ b/arch/x86/realmode/rm/header.S
35084@@ -30,7 +30,9 @@ GLOBAL(real_mode_header)
35085 #endif
35086 /* APM/BIOS reboot */
35087 .long pa_machine_real_restart_asm
35088-#ifdef CONFIG_X86_64
35089+#ifdef CONFIG_X86_32
35090+ .long __KERNEL_CS
35091+#else
35092 .long __KERNEL32_CS
35093 #endif
35094 END(real_mode_header)
35095diff --git a/arch/x86/realmode/rm/trampoline_32.S b/arch/x86/realmode/rm/trampoline_32.S
35096index 48ddd76..c26749f 100644
35097--- a/arch/x86/realmode/rm/trampoline_32.S
35098+++ b/arch/x86/realmode/rm/trampoline_32.S
35099@@ -24,6 +24,12 @@
35100 #include <asm/page_types.h>
35101 #include "realmode.h"
35102
35103+#ifdef CONFIG_PAX_KERNEXEC
35104+#define ta(X) (X)
35105+#else
35106+#define ta(X) (pa_ ## X)
35107+#endif
35108+
35109 .text
35110 .code16
35111
35112@@ -38,8 +44,6 @@ ENTRY(trampoline_start)
35113
35114 cli # We should be safe anyway
35115
35116- movl tr_start, %eax # where we need to go
35117-
35118 movl $0xA5A5A5A5, trampoline_status
35119 # write marker for master knows we're running
35120
35121@@ -55,7 +59,7 @@ ENTRY(trampoline_start)
35122 movw $1, %dx # protected mode (PE) bit
35123 lmsw %dx # into protected mode
35124
35125- ljmpl $__BOOT_CS, $pa_startup_32
35126+ ljmpl *(trampoline_header)
35127
35128 .section ".text32","ax"
35129 .code32
35130@@ -66,7 +70,7 @@ ENTRY(startup_32) # note: also used from wakeup_asm.S
35131 .balign 8
35132 GLOBAL(trampoline_header)
35133 tr_start: .space 4
35134- tr_gdt_pad: .space 2
35135+ tr_boot_cs: .space 2
35136 tr_gdt: .space 6
35137 END(trampoline_header)
35138
35139diff --git a/arch/x86/realmode/rm/trampoline_64.S b/arch/x86/realmode/rm/trampoline_64.S
35140index dac7b20..72dbaca 100644
35141--- a/arch/x86/realmode/rm/trampoline_64.S
35142+++ b/arch/x86/realmode/rm/trampoline_64.S
35143@@ -93,6 +93,7 @@ ENTRY(startup_32)
35144 movl %edx, %gs
35145
35146 movl pa_tr_cr4, %eax
35147+ andl $~X86_CR4_PCIDE, %eax
35148 movl %eax, %cr4 # Enable PAE mode
35149
35150 # Setup trampoline 4 level pagetables
35151@@ -106,7 +107,7 @@ ENTRY(startup_32)
35152 wrmsr
35153
35154 # Enable paging and in turn activate Long Mode
35155- movl $(X86_CR0_PG | X86_CR0_WP | X86_CR0_PE), %eax
35156+ movl $(X86_CR0_PG | X86_CR0_PE), %eax
35157 movl %eax, %cr0
35158
35159 /*
35160diff --git a/arch/x86/realmode/rm/wakeup_asm.S b/arch/x86/realmode/rm/wakeup_asm.S
35161index 9e7e147..25a4158 100644
35162--- a/arch/x86/realmode/rm/wakeup_asm.S
35163+++ b/arch/x86/realmode/rm/wakeup_asm.S
35164@@ -126,11 +126,10 @@ ENTRY(wakeup_start)
35165 lgdtl pmode_gdt
35166
35167 /* This really couldn't... */
35168- movl pmode_entry, %eax
35169 movl pmode_cr0, %ecx
35170 movl %ecx, %cr0
35171- ljmpl $__KERNEL_CS, $pa_startup_32
35172- /* -> jmp *%eax in trampoline_32.S */
35173+
35174+ ljmpl *pmode_entry
35175 #else
35176 jmp trampoline_start
35177 #endif
35178diff --git a/arch/x86/tools/Makefile b/arch/x86/tools/Makefile
35179index 604a37e..e49702a 100644
35180--- a/arch/x86/tools/Makefile
35181+++ b/arch/x86/tools/Makefile
35182@@ -37,7 +37,7 @@ $(obj)/test_get_len.o: $(srctree)/arch/x86/lib/insn.c $(srctree)/arch/x86/lib/in
35183
35184 $(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
35185
35186-HOST_EXTRACFLAGS += -I$(srctree)/tools/include
35187+HOST_EXTRACFLAGS += -I$(srctree)/tools/include -ggdb
35188 hostprogs-y += relocs
35189 relocs-objs := relocs_32.o relocs_64.o relocs_common.o
35190 PHONY += relocs
35191diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c
35192index a5efb21..97490e9 100644
35193--- a/arch/x86/tools/relocs.c
35194+++ b/arch/x86/tools/relocs.c
35195@@ -1,5 +1,7 @@
35196 /* This is included from relocs_32/64.c */
35197
35198+#include "../../../include/generated/autoconf.h"
35199+
35200 #define ElfW(type) _ElfW(ELF_BITS, type)
35201 #define _ElfW(bits, type) __ElfW(bits, type)
35202 #define __ElfW(bits, type) Elf##bits##_##type
35203@@ -11,6 +13,7 @@
35204 #define Elf_Sym ElfW(Sym)
35205
35206 static Elf_Ehdr ehdr;
35207+static Elf_Phdr *phdr;
35208
35209 struct relocs {
35210 uint32_t *offset;
35211@@ -383,9 +386,39 @@ static void read_ehdr(FILE *fp)
35212 }
35213 }
35214
35215+static void read_phdrs(FILE *fp)
35216+{
35217+ unsigned int i;
35218+
35219+ phdr = calloc(ehdr.e_phnum, sizeof(Elf_Phdr));
35220+ if (!phdr) {
35221+ die("Unable to allocate %d program headers\n",
35222+ ehdr.e_phnum);
35223+ }
35224+ if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
35225+ die("Seek to %d failed: %s\n",
35226+ ehdr.e_phoff, strerror(errno));
35227+ }
35228+ if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
35229+ die("Cannot read ELF program headers: %s\n",
35230+ strerror(errno));
35231+ }
35232+ for(i = 0; i < ehdr.e_phnum; i++) {
35233+ phdr[i].p_type = elf_word_to_cpu(phdr[i].p_type);
35234+ phdr[i].p_offset = elf_off_to_cpu(phdr[i].p_offset);
35235+ phdr[i].p_vaddr = elf_addr_to_cpu(phdr[i].p_vaddr);
35236+ phdr[i].p_paddr = elf_addr_to_cpu(phdr[i].p_paddr);
35237+ phdr[i].p_filesz = elf_word_to_cpu(phdr[i].p_filesz);
35238+ phdr[i].p_memsz = elf_word_to_cpu(phdr[i].p_memsz);
35239+ phdr[i].p_flags = elf_word_to_cpu(phdr[i].p_flags);
35240+ phdr[i].p_align = elf_word_to_cpu(phdr[i].p_align);
35241+ }
35242+
35243+}
35244+
35245 static void read_shdrs(FILE *fp)
35246 {
35247- int i;
35248+ unsigned int i;
35249 Elf_Shdr shdr;
35250
35251 secs = calloc(ehdr.e_shnum, sizeof(struct section));
35252@@ -420,7 +453,7 @@ static void read_shdrs(FILE *fp)
35253
35254 static void read_strtabs(FILE *fp)
35255 {
35256- int i;
35257+ unsigned int i;
35258 for (i = 0; i < ehdr.e_shnum; i++) {
35259 struct section *sec = &secs[i];
35260 if (sec->shdr.sh_type != SHT_STRTAB) {
35261@@ -445,7 +478,7 @@ static void read_strtabs(FILE *fp)
35262
35263 static void read_symtabs(FILE *fp)
35264 {
35265- int i,j;
35266+ unsigned int i,j;
35267 for (i = 0; i < ehdr.e_shnum; i++) {
35268 struct section *sec = &secs[i];
35269 if (sec->shdr.sh_type != SHT_SYMTAB) {
35270@@ -476,9 +509,11 @@ static void read_symtabs(FILE *fp)
35271 }
35272
35273
35274-static void read_relocs(FILE *fp)
35275+static void read_relocs(FILE *fp, int use_real_mode)
35276 {
35277- int i,j;
35278+ unsigned int i,j;
35279+ uint32_t base;
35280+
35281 for (i = 0; i < ehdr.e_shnum; i++) {
35282 struct section *sec = &secs[i];
35283 if (sec->shdr.sh_type != SHT_REL_TYPE) {
35284@@ -498,9 +533,22 @@ static void read_relocs(FILE *fp)
35285 die("Cannot read symbol table: %s\n",
35286 strerror(errno));
35287 }
35288+ base = 0;
35289+
35290+#ifdef CONFIG_X86_32
35291+ for (j = 0; !use_real_mode && j < ehdr.e_phnum; j++) {
35292+ if (phdr[j].p_type != PT_LOAD )
35293+ continue;
35294+ 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)
35295+ continue;
35296+ base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
35297+ break;
35298+ }
35299+#endif
35300+
35301 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf_Rel); j++) {
35302 Elf_Rel *rel = &sec->reltab[j];
35303- rel->r_offset = elf_addr_to_cpu(rel->r_offset);
35304+ rel->r_offset = elf_addr_to_cpu(rel->r_offset) + base;
35305 rel->r_info = elf_xword_to_cpu(rel->r_info);
35306 #if (SHT_REL_TYPE == SHT_RELA)
35307 rel->r_addend = elf_xword_to_cpu(rel->r_addend);
35308@@ -512,7 +560,7 @@ static void read_relocs(FILE *fp)
35309
35310 static void print_absolute_symbols(void)
35311 {
35312- int i;
35313+ unsigned int i;
35314 const char *format;
35315
35316 if (ELF_BITS == 64)
35317@@ -525,7 +573,7 @@ static void print_absolute_symbols(void)
35318 for (i = 0; i < ehdr.e_shnum; i++) {
35319 struct section *sec = &secs[i];
35320 char *sym_strtab;
35321- int j;
35322+ unsigned int j;
35323
35324 if (sec->shdr.sh_type != SHT_SYMTAB) {
35325 continue;
35326@@ -552,7 +600,7 @@ static void print_absolute_symbols(void)
35327
35328 static void print_absolute_relocs(void)
35329 {
35330- int i, printed = 0;
35331+ unsigned int i, printed = 0;
35332 const char *format;
35333
35334 if (ELF_BITS == 64)
35335@@ -565,7 +613,7 @@ static void print_absolute_relocs(void)
35336 struct section *sec_applies, *sec_symtab;
35337 char *sym_strtab;
35338 Elf_Sym *sh_symtab;
35339- int j;
35340+ unsigned int j;
35341 if (sec->shdr.sh_type != SHT_REL_TYPE) {
35342 continue;
35343 }
35344@@ -642,13 +690,13 @@ static void add_reloc(struct relocs *r, uint32_t offset)
35345 static void walk_relocs(int (*process)(struct section *sec, Elf_Rel *rel,
35346 Elf_Sym *sym, const char *symname))
35347 {
35348- int i;
35349+ unsigned int i;
35350 /* Walk through the relocations */
35351 for (i = 0; i < ehdr.e_shnum; i++) {
35352 char *sym_strtab;
35353 Elf_Sym *sh_symtab;
35354 struct section *sec_applies, *sec_symtab;
35355- int j;
35356+ unsigned int j;
35357 struct section *sec = &secs[i];
35358
35359 if (sec->shdr.sh_type != SHT_REL_TYPE) {
35360@@ -822,6 +870,23 @@ static int do_reloc32(struct section *sec, Elf_Rel *rel, Elf_Sym *sym,
35361 {
35362 unsigned r_type = ELF32_R_TYPE(rel->r_info);
35363 int shn_abs = (sym->st_shndx == SHN_ABS) && !is_reloc(S_REL, symname);
35364+ char *sym_strtab = sec->link->link->strtab;
35365+
35366+ /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
35367+ if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
35368+ return 0;
35369+
35370+#ifdef CONFIG_PAX_KERNEXEC
35371+ /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
35372+ if (!strcmp(sec_name(sym->st_shndx), ".text.end") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
35373+ return 0;
35374+ if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
35375+ return 0;
35376+ if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
35377+ return 0;
35378+ if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
35379+ return 0;
35380+#endif
35381
35382 switch (r_type) {
35383 case R_386_NONE:
35384@@ -960,7 +1025,7 @@ static int write32_as_text(uint32_t v, FILE *f)
35385
35386 static void emit_relocs(int as_text, int use_real_mode)
35387 {
35388- int i;
35389+ unsigned int i;
35390 int (*write_reloc)(uint32_t, FILE *) = write32;
35391 int (*do_reloc)(struct section *sec, Elf_Rel *rel, Elf_Sym *sym,
35392 const char *symname);
35393@@ -1060,10 +1125,11 @@ void process(FILE *fp, int use_real_mode, int as_text,
35394 {
35395 regex_init(use_real_mode);
35396 read_ehdr(fp);
35397+ read_phdrs(fp);
35398 read_shdrs(fp);
35399 read_strtabs(fp);
35400 read_symtabs(fp);
35401- read_relocs(fp);
35402+ read_relocs(fp, use_real_mode);
35403 if (ELF_BITS == 64)
35404 percpu_init();
35405 if (show_absolute_syms) {
35406diff --git a/arch/x86/um/mem_32.c b/arch/x86/um/mem_32.c
35407index f40281e..92728c9 100644
35408--- a/arch/x86/um/mem_32.c
35409+++ b/arch/x86/um/mem_32.c
35410@@ -21,7 +21,7 @@ static int __init gate_vma_init(void)
35411 gate_vma.vm_start = FIXADDR_USER_START;
35412 gate_vma.vm_end = FIXADDR_USER_END;
35413 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
35414- gate_vma.vm_page_prot = __P101;
35415+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
35416
35417 return 0;
35418 }
35419diff --git a/arch/x86/um/tls_32.c b/arch/x86/um/tls_32.c
35420index 80ffa5b..a33bd15 100644
35421--- a/arch/x86/um/tls_32.c
35422+++ b/arch/x86/um/tls_32.c
35423@@ -260,7 +260,7 @@ out:
35424 if (unlikely(task == current &&
35425 !t->arch.tls_array[idx - GDT_ENTRY_TLS_MIN].flushed)) {
35426 printk(KERN_ERR "get_tls_entry: task with pid %d got here "
35427- "without flushed TLS.", current->pid);
35428+ "without flushed TLS.", task_pid_nr(current));
35429 }
35430
35431 return 0;
35432diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
35433index 5a4affe..9e2d522 100644
35434--- a/arch/x86/vdso/Makefile
35435+++ b/arch/x86/vdso/Makefile
35436@@ -174,7 +174,7 @@ quiet_cmd_vdso = VDSO $@
35437 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
35438 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
35439
35440-VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv) \
35441+VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv) \
35442 $(call cc-ldoption, -Wl$(comma)--build-id) -Wl,-Bsymbolic $(LTO_CFLAGS)
35443 GCOV_PROFILE := n
35444
35445diff --git a/arch/x86/vdso/vdso2c.h b/arch/x86/vdso/vdso2c.h
35446index 0224987..c7d65a5 100644
35447--- a/arch/x86/vdso/vdso2c.h
35448+++ b/arch/x86/vdso/vdso2c.h
35449@@ -12,7 +12,7 @@ static void BITSFUNC(go)(void *raw_addr, size_t raw_len,
35450 unsigned long load_size = -1; /* Work around bogus warning */
35451 unsigned long mapping_size;
35452 ELF(Ehdr) *hdr = (ELF(Ehdr) *)raw_addr;
35453- int i;
35454+ unsigned int i;
35455 unsigned long j;
35456 ELF(Shdr) *symtab_hdr = NULL, *strtab_hdr, *secstrings_hdr,
35457 *alt_sec = NULL;
35458diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
35459index e904c27..b9eaa03 100644
35460--- a/arch/x86/vdso/vdso32-setup.c
35461+++ b/arch/x86/vdso/vdso32-setup.c
35462@@ -14,6 +14,7 @@
35463 #include <asm/cpufeature.h>
35464 #include <asm/processor.h>
35465 #include <asm/vdso.h>
35466+#include <asm/mman.h>
35467
35468 #ifdef CONFIG_COMPAT_VDSO
35469 #define VDSO_DEFAULT 0
35470diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
35471index 208c220..54f1447 100644
35472--- a/arch/x86/vdso/vma.c
35473+++ b/arch/x86/vdso/vma.c
35474@@ -16,10 +16,9 @@
35475 #include <asm/vdso.h>
35476 #include <asm/page.h>
35477 #include <asm/hpet.h>
35478+#include <asm/mman.h>
35479
35480 #if defined(CONFIG_X86_64)
35481-unsigned int __read_mostly vdso64_enabled = 1;
35482-
35483 extern unsigned short vdso_sync_cpuid;
35484 #endif
35485
35486@@ -114,6 +113,11 @@ static int map_vdso(const struct vdso_image *image, bool calculate_addr)
35487 .pages = no_pages,
35488 };
35489
35490+#ifdef CONFIG_PAX_RANDMMAP
35491+ if (mm->pax_flags & MF_PAX_RANDMMAP)
35492+ calculate_addr = false;
35493+#endif
35494+
35495 if (calculate_addr) {
35496 addr = vdso_addr(current->mm->start_stack,
35497 image->size - image->sym_vvar_start);
35498@@ -124,14 +128,14 @@ static int map_vdso(const struct vdso_image *image, bool calculate_addr)
35499 down_write(&mm->mmap_sem);
35500
35501 addr = get_unmapped_area(NULL, addr,
35502- image->size - image->sym_vvar_start, 0, 0);
35503+ image->size - image->sym_vvar_start, 0, MAP_EXECUTABLE);
35504 if (IS_ERR_VALUE(addr)) {
35505 ret = addr;
35506 goto up_fail;
35507 }
35508
35509 text_start = addr - image->sym_vvar_start;
35510- current->mm->context.vdso = (void __user *)text_start;
35511+ mm->context.vdso = text_start;
35512
35513 /*
35514 * MAYWRITE to allow gdb to COW and set breakpoints
35515@@ -176,15 +180,12 @@ static int map_vdso(const struct vdso_image *image, bool calculate_addr)
35516 hpet_address >> PAGE_SHIFT,
35517 PAGE_SIZE,
35518 pgprot_noncached(PAGE_READONLY));
35519-
35520- if (ret)
35521- goto up_fail;
35522 }
35523 #endif
35524
35525 up_fail:
35526 if (ret)
35527- current->mm->context.vdso = NULL;
35528+ current->mm->context.vdso = 0;
35529
35530 up_write(&mm->mmap_sem);
35531 return ret;
35532@@ -204,8 +205,8 @@ static int load_vdso32(void)
35533
35534 if (selected_vdso32->sym_VDSO32_SYSENTER_RETURN)
35535 current_thread_info()->sysenter_return =
35536- current->mm->context.vdso +
35537- selected_vdso32->sym_VDSO32_SYSENTER_RETURN;
35538+ (void __force_user *)(current->mm->context.vdso +
35539+ selected_vdso32->sym_VDSO32_SYSENTER_RETURN);
35540
35541 return 0;
35542 }
35543@@ -214,9 +215,6 @@ static int load_vdso32(void)
35544 #ifdef CONFIG_X86_64
35545 int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
35546 {
35547- if (!vdso64_enabled)
35548- return 0;
35549-
35550 return map_vdso(&vdso_image_64, true);
35551 }
35552
35553@@ -225,12 +223,8 @@ int compat_arch_setup_additional_pages(struct linux_binprm *bprm,
35554 int uses_interp)
35555 {
35556 #ifdef CONFIG_X86_X32_ABI
35557- if (test_thread_flag(TIF_X32)) {
35558- if (!vdso64_enabled)
35559- return 0;
35560-
35561+ if (test_thread_flag(TIF_X32))
35562 return map_vdso(&vdso_image_x32, true);
35563- }
35564 #endif
35565
35566 return load_vdso32();
35567@@ -242,12 +236,3 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
35568 return load_vdso32();
35569 }
35570 #endif
35571-
35572-#ifdef CONFIG_X86_64
35573-static __init int vdso_setup(char *s)
35574-{
35575- vdso64_enabled = simple_strtoul(s, NULL, 0);
35576- return 0;
35577-}
35578-__setup("vdso=", vdso_setup);
35579-#endif
35580diff --git a/arch/x86/xen/Kconfig b/arch/x86/xen/Kconfig
35581index e88fda8..76ce7ce 100644
35582--- a/arch/x86/xen/Kconfig
35583+++ b/arch/x86/xen/Kconfig
35584@@ -9,6 +9,7 @@ config XEN
35585 select XEN_HAVE_PVMMU
35586 depends on X86_64 || (X86_32 && X86_PAE)
35587 depends on X86_TSC
35588+ depends on !GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_VIRT_XEN
35589 help
35590 This is the Linux Xen port. Enabling this will allow the
35591 kernel to boot in a paravirtualized environment under the
35592diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
35593index fac5e4f..e421c18 100644
35594--- a/arch/x86/xen/enlighten.c
35595+++ b/arch/x86/xen/enlighten.c
35596@@ -123,8 +123,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
35597
35598 struct shared_info xen_dummy_shared_info;
35599
35600-void *xen_initial_gdt;
35601-
35602 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
35603 __read_mostly int xen_have_vector_callback;
35604 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
35605@@ -542,8 +540,7 @@ static void xen_load_gdt(const struct desc_ptr *dtr)
35606 {
35607 unsigned long va = dtr->address;
35608 unsigned int size = dtr->size + 1;
35609- unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
35610- unsigned long frames[pages];
35611+ unsigned long frames[65536 / PAGE_SIZE];
35612 int f;
35613
35614 /*
35615@@ -591,8 +588,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
35616 {
35617 unsigned long va = dtr->address;
35618 unsigned int size = dtr->size + 1;
35619- unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
35620- unsigned long frames[pages];
35621+ unsigned long frames[(GDT_SIZE + PAGE_SIZE - 1) / PAGE_SIZE];
35622 int f;
35623
35624 /*
35625@@ -600,7 +596,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
35626 * 8-byte entries, or 16 4k pages..
35627 */
35628
35629- BUG_ON(size > 65536);
35630+ BUG_ON(size > GDT_SIZE);
35631 BUG_ON(va & ~PAGE_MASK);
35632
35633 for (f = 0; va < dtr->address + size; va += PAGE_SIZE, f++) {
35634@@ -989,7 +985,7 @@ static u32 xen_safe_apic_wait_icr_idle(void)
35635 return 0;
35636 }
35637
35638-static void set_xen_basic_apic_ops(void)
35639+static void __init set_xen_basic_apic_ops(void)
35640 {
35641 apic->read = xen_apic_read;
35642 apic->write = xen_apic_write;
35643@@ -1295,30 +1291,30 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
35644 #endif
35645 };
35646
35647-static void xen_reboot(int reason)
35648+static __noreturn void xen_reboot(int reason)
35649 {
35650 struct sched_shutdown r = { .reason = reason };
35651
35652- if (HYPERVISOR_sched_op(SCHEDOP_shutdown, &r))
35653- BUG();
35654+ HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
35655+ BUG();
35656 }
35657
35658-static void xen_restart(char *msg)
35659+static __noreturn void xen_restart(char *msg)
35660 {
35661 xen_reboot(SHUTDOWN_reboot);
35662 }
35663
35664-static void xen_emergency_restart(void)
35665+static __noreturn void xen_emergency_restart(void)
35666 {
35667 xen_reboot(SHUTDOWN_reboot);
35668 }
35669
35670-static void xen_machine_halt(void)
35671+static __noreturn void xen_machine_halt(void)
35672 {
35673 xen_reboot(SHUTDOWN_poweroff);
35674 }
35675
35676-static void xen_machine_power_off(void)
35677+static __noreturn void xen_machine_power_off(void)
35678 {
35679 if (pm_power_off)
35680 pm_power_off();
35681@@ -1456,8 +1452,9 @@ static void __ref xen_setup_gdt(int cpu)
35682 pv_cpu_ops.write_gdt_entry = xen_write_gdt_entry_boot;
35683 pv_cpu_ops.load_gdt = xen_load_gdt_boot;
35684
35685- setup_stack_canary_segment(0);
35686- switch_to_new_gdt(0);
35687+ setup_stack_canary_segment(cpu);
35688+ load_percpu_segment(cpu);
35689+ switch_to_new_gdt(cpu);
35690
35691 pv_cpu_ops.write_gdt_entry = xen_write_gdt_entry;
35692 pv_cpu_ops.load_gdt = xen_load_gdt;
35693@@ -1573,7 +1570,17 @@ asmlinkage __visible void __init xen_start_kernel(void)
35694 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
35695
35696 /* Work out if we support NX */
35697- x86_configure_nx();
35698+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
35699+ if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
35700+ (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
35701+ unsigned l, h;
35702+
35703+ __supported_pte_mask |= _PAGE_NX;
35704+ rdmsr(MSR_EFER, l, h);
35705+ l |= EFER_NX;
35706+ wrmsr(MSR_EFER, l, h);
35707+ }
35708+#endif
35709
35710 /* Get mfn list */
35711 xen_build_dynamic_phys_to_machine();
35712@@ -1601,13 +1608,6 @@ asmlinkage __visible void __init xen_start_kernel(void)
35713
35714 machine_ops = xen_machine_ops;
35715
35716- /*
35717- * The only reliable way to retain the initial address of the
35718- * percpu gdt_page is to remember it here, so we can go and
35719- * mark it RW later, when the initial percpu area is freed.
35720- */
35721- xen_initial_gdt = &per_cpu(gdt_page, 0);
35722-
35723 xen_smp_init();
35724
35725 #ifdef CONFIG_ACPI_NUMA
35726diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
35727index a8a1a3d..8216142 100644
35728--- a/arch/x86/xen/mmu.c
35729+++ b/arch/x86/xen/mmu.c
35730@@ -379,7 +379,7 @@ static pteval_t pte_mfn_to_pfn(pteval_t val)
35731 return val;
35732 }
35733
35734-static pteval_t pte_pfn_to_mfn(pteval_t val)
35735+static pteval_t __intentional_overflow(-1) pte_pfn_to_mfn(pteval_t val)
35736 {
35737 if (val & _PAGE_PRESENT) {
35738 unsigned long pfn = (val & PTE_PFN_MASK) >> PAGE_SHIFT;
35739@@ -1867,7 +1867,11 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
35740 * L3_k[511] -> level2_fixmap_pgt */
35741 convert_pfn_mfn(level3_kernel_pgt);
35742
35743+ convert_pfn_mfn(level3_vmalloc_start_pgt);
35744+ convert_pfn_mfn(level3_vmalloc_end_pgt);
35745+ convert_pfn_mfn(level3_vmemmap_pgt);
35746 /* L3_k[511][506] -> level1_fixmap_pgt */
35747+ /* L3_k[511][507] -> level1_vsyscall_pgt */
35748 convert_pfn_mfn(level2_fixmap_pgt);
35749 }
35750 /* We get [511][511] and have Xen's version of level2_kernel_pgt */
35751@@ -1892,11 +1896,16 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
35752 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
35753 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
35754 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
35755+ set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
35756+ set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
35757+ set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
35758 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
35759 set_page_prot(level2_ident_pgt, PAGE_KERNEL_RO);
35760+ set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
35761 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
35762 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
35763 set_page_prot(level1_fixmap_pgt, PAGE_KERNEL_RO);
35764+ set_page_prot(level1_vsyscall_pgt, PAGE_KERNEL_RO);
35765
35766 /* Pin down new L4 */
35767 pin_pagetable_pfn(MMUEXT_PIN_L4_TABLE,
35768@@ -2080,6 +2089,7 @@ static void __init xen_post_allocator_init(void)
35769 pv_mmu_ops.set_pud = xen_set_pud;
35770 #if PAGETABLE_LEVELS == 4
35771 pv_mmu_ops.set_pgd = xen_set_pgd;
35772+ pv_mmu_ops.set_pgd_batched = xen_set_pgd;
35773 #endif
35774
35775 /* This will work as long as patching hasn't happened yet
35776@@ -2158,6 +2168,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
35777 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
35778 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
35779 .set_pgd = xen_set_pgd_hyper,
35780+ .set_pgd_batched = xen_set_pgd_hyper,
35781
35782 .alloc_pud = xen_alloc_pmd_init,
35783 .release_pud = xen_release_pmd_init,
35784diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
35785index 4c071ae..00e7049 100644
35786--- a/arch/x86/xen/smp.c
35787+++ b/arch/x86/xen/smp.c
35788@@ -288,17 +288,13 @@ static void __init xen_smp_prepare_boot_cpu(void)
35789
35790 if (xen_pv_domain()) {
35791 if (!xen_feature(XENFEAT_writable_page_tables))
35792- /* We've switched to the "real" per-cpu gdt, so make
35793- * sure the old memory can be recycled. */
35794- make_lowmem_page_readwrite(xen_initial_gdt);
35795-
35796 #ifdef CONFIG_X86_32
35797 /*
35798 * Xen starts us with XEN_FLAT_RING1_DS, but linux code
35799 * expects __USER_DS
35800 */
35801- loadsegment(ds, __USER_DS);
35802- loadsegment(es, __USER_DS);
35803+ loadsegment(ds, __KERNEL_DS);
35804+ loadsegment(es, __KERNEL_DS);
35805 #endif
35806
35807 xen_filter_cpu_maps();
35808@@ -379,7 +375,7 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
35809 #ifdef CONFIG_X86_32
35810 /* Note: PVH is not yet supported on x86_32. */
35811 ctxt->user_regs.fs = __KERNEL_PERCPU;
35812- ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
35813+ savesegment(gs, ctxt->user_regs.gs);
35814 #endif
35815 memset(&ctxt->fpu_ctxt, 0, sizeof(ctxt->fpu_ctxt));
35816
35817@@ -387,8 +383,8 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
35818 ctxt->user_regs.eip = (unsigned long)cpu_bringup_and_idle;
35819 ctxt->flags = VGCF_IN_KERNEL;
35820 ctxt->user_regs.eflags = 0x1000; /* IOPL_RING1 */
35821- ctxt->user_regs.ds = __USER_DS;
35822- ctxt->user_regs.es = __USER_DS;
35823+ ctxt->user_regs.ds = __KERNEL_DS;
35824+ ctxt->user_regs.es = __KERNEL_DS;
35825 ctxt->user_regs.ss = __KERNEL_DS;
35826
35827 xen_copy_trap_info(ctxt->trap_ctxt);
35828@@ -446,14 +442,13 @@ static int xen_cpu_up(unsigned int cpu, struct task_struct *idle)
35829 int rc;
35830
35831 per_cpu(current_task, cpu) = idle;
35832+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
35833 #ifdef CONFIG_X86_32
35834 irq_ctx_init(cpu);
35835 #else
35836 clear_tsk_thread_flag(idle, TIF_FORK);
35837 #endif
35838- per_cpu(kernel_stack, cpu) =
35839- (unsigned long)task_stack_page(idle) -
35840- KERNEL_STACK_OFFSET + THREAD_SIZE;
35841+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
35842
35843 xen_setup_runstate_info(cpu);
35844 xen_setup_timer(cpu);
35845@@ -732,7 +727,7 @@ static const struct smp_ops xen_smp_ops __initconst = {
35846
35847 void __init xen_smp_init(void)
35848 {
35849- smp_ops = xen_smp_ops;
35850+ memcpy((void *)&smp_ops, &xen_smp_ops, sizeof smp_ops);
35851 xen_fill_possible_map();
35852 }
35853
35854diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
35855index fd92a64..1f72641 100644
35856--- a/arch/x86/xen/xen-asm_32.S
35857+++ b/arch/x86/xen/xen-asm_32.S
35858@@ -99,7 +99,7 @@ ENTRY(xen_iret)
35859 pushw %fs
35860 movl $(__KERNEL_PERCPU), %eax
35861 movl %eax, %fs
35862- movl %fs:xen_vcpu, %eax
35863+ mov PER_CPU_VAR(xen_vcpu), %eax
35864 POP_FS
35865 #else
35866 movl %ss:xen_vcpu, %eax
35867diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
35868index 674b2225..f1f5dc1 100644
35869--- a/arch/x86/xen/xen-head.S
35870+++ b/arch/x86/xen/xen-head.S
35871@@ -39,6 +39,17 @@ ENTRY(startup_xen)
35872 #ifdef CONFIG_X86_32
35873 mov %esi,xen_start_info
35874 mov $init_thread_union+THREAD_SIZE,%esp
35875+#ifdef CONFIG_SMP
35876+ movl $cpu_gdt_table,%edi
35877+ movl $__per_cpu_load,%eax
35878+ movw %ax,__KERNEL_PERCPU + 2(%edi)
35879+ rorl $16,%eax
35880+ movb %al,__KERNEL_PERCPU + 4(%edi)
35881+ movb %ah,__KERNEL_PERCPU + 7(%edi)
35882+ movl $__per_cpu_end - 1,%eax
35883+ subl $__per_cpu_start,%eax
35884+ movw %ax,__KERNEL_PERCPU + 0(%edi)
35885+#endif
35886 #else
35887 mov %rsi,xen_start_info
35888 mov $init_thread_union+THREAD_SIZE,%rsp
35889diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
35890index 28c7e0b..2acfec7 100644
35891--- a/arch/x86/xen/xen-ops.h
35892+++ b/arch/x86/xen/xen-ops.h
35893@@ -10,8 +10,6 @@
35894 extern const char xen_hypervisor_callback[];
35895 extern const char xen_failsafe_callback[];
35896
35897-extern void *xen_initial_gdt;
35898-
35899 struct trap_info;
35900 void xen_copy_trap_info(struct trap_info *traps);
35901
35902diff --git a/arch/xtensa/variants/dc232b/include/variant/core.h b/arch/xtensa/variants/dc232b/include/variant/core.h
35903index 525bd3d..ef888b1 100644
35904--- a/arch/xtensa/variants/dc232b/include/variant/core.h
35905+++ b/arch/xtensa/variants/dc232b/include/variant/core.h
35906@@ -119,9 +119,9 @@
35907 ----------------------------------------------------------------------*/
35908
35909 #define XCHAL_ICACHE_LINESIZE 32 /* I-cache line size in bytes */
35910-#define XCHAL_DCACHE_LINESIZE 32 /* D-cache line size in bytes */
35911 #define XCHAL_ICACHE_LINEWIDTH 5 /* log2(I line size in bytes) */
35912 #define XCHAL_DCACHE_LINEWIDTH 5 /* log2(D line size in bytes) */
35913+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
35914
35915 #define XCHAL_ICACHE_SIZE 16384 /* I-cache size in bytes or 0 */
35916 #define XCHAL_DCACHE_SIZE 16384 /* D-cache size in bytes or 0 */
35917diff --git a/arch/xtensa/variants/fsf/include/variant/core.h b/arch/xtensa/variants/fsf/include/variant/core.h
35918index 2f33760..835e50a 100644
35919--- a/arch/xtensa/variants/fsf/include/variant/core.h
35920+++ b/arch/xtensa/variants/fsf/include/variant/core.h
35921@@ -11,6 +11,7 @@
35922 #ifndef _XTENSA_CORE_H
35923 #define _XTENSA_CORE_H
35924
35925+#include <linux/const.h>
35926
35927 /****************************************************************************
35928 Parameters Useful for Any Code, USER or PRIVILEGED
35929@@ -112,9 +113,9 @@
35930 ----------------------------------------------------------------------*/
35931
35932 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
35933-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
35934 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
35935 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
35936+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
35937
35938 #define XCHAL_ICACHE_SIZE 8192 /* I-cache size in bytes or 0 */
35939 #define XCHAL_DCACHE_SIZE 8192 /* D-cache size in bytes or 0 */
35940diff --git a/arch/xtensa/variants/s6000/include/variant/core.h b/arch/xtensa/variants/s6000/include/variant/core.h
35941index af00795..2bb8105 100644
35942--- a/arch/xtensa/variants/s6000/include/variant/core.h
35943+++ b/arch/xtensa/variants/s6000/include/variant/core.h
35944@@ -11,6 +11,7 @@
35945 #ifndef _XTENSA_CORE_CONFIGURATION_H
35946 #define _XTENSA_CORE_CONFIGURATION_H
35947
35948+#include <linux/const.h>
35949
35950 /****************************************************************************
35951 Parameters Useful for Any Code, USER or PRIVILEGED
35952@@ -118,9 +119,9 @@
35953 ----------------------------------------------------------------------*/
35954
35955 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
35956-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
35957 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
35958 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
35959+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
35960
35961 #define XCHAL_ICACHE_SIZE 32768 /* I-cache size in bytes or 0 */
35962 #define XCHAL_DCACHE_SIZE 32768 /* D-cache size in bytes or 0 */
35963diff --git a/block/bio.c b/block/bio.c
35964index 3e6e198..5c65199 100644
35965--- a/block/bio.c
35966+++ b/block/bio.c
35967@@ -1163,7 +1163,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
35968 /*
35969 * Overflow, abort
35970 */
35971- if (end < start)
35972+ if (end < start || end - start > INT_MAX - nr_pages)
35973 return ERR_PTR(-EINVAL);
35974
35975 nr_pages += end - start;
35976@@ -1297,7 +1297,7 @@ static struct bio *__bio_map_user_iov(struct request_queue *q,
35977 /*
35978 * Overflow, abort
35979 */
35980- if (end < start)
35981+ if (end < start || end - start > INT_MAX - nr_pages)
35982 return ERR_PTR(-EINVAL);
35983
35984 nr_pages += end - start;
35985@@ -1559,7 +1559,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
35986 const int read = bio_data_dir(bio) == READ;
35987 struct bio_map_data *bmd = bio->bi_private;
35988 int i;
35989- char *p = bmd->sgvecs[0].iov_base;
35990+ char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
35991
35992 bio_for_each_segment_all(bvec, bio, i) {
35993 char *addr = page_address(bvec->bv_page);
35994diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
35995index 0736729..2ec3b48 100644
35996--- a/block/blk-iopoll.c
35997+++ b/block/blk-iopoll.c
35998@@ -74,7 +74,7 @@ void blk_iopoll_complete(struct blk_iopoll *iop)
35999 }
36000 EXPORT_SYMBOL(blk_iopoll_complete);
36001
36002-static void blk_iopoll_softirq(struct softirq_action *h)
36003+static __latent_entropy void blk_iopoll_softirq(void)
36004 {
36005 struct list_head *list = this_cpu_ptr(&blk_cpu_iopoll);
36006 int rearm = 0, budget = blk_iopoll_budget;
36007diff --git a/block/blk-map.c b/block/blk-map.c
36008index f890d43..97b0482 100644
36009--- a/block/blk-map.c
36010+++ b/block/blk-map.c
36011@@ -300,7 +300,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
36012 if (!len || !kbuf)
36013 return -EINVAL;
36014
36015- do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
36016+ do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
36017 if (do_copy)
36018 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
36019 else
36020diff --git a/block/blk-softirq.c b/block/blk-softirq.c
36021index 53b1737..08177d2e 100644
36022--- a/block/blk-softirq.c
36023+++ b/block/blk-softirq.c
36024@@ -18,7 +18,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
36025 * Softirq action handler - move entries to local list and loop over them
36026 * while passing them to the queue registered handler.
36027 */
36028-static void blk_done_softirq(struct softirq_action *h)
36029+static __latent_entropy void blk_done_softirq(void)
36030 {
36031 struct list_head *cpu_list, local_list;
36032
36033diff --git a/block/bsg.c b/block/bsg.c
36034index 276e869..6fe4c61 100644
36035--- a/block/bsg.c
36036+++ b/block/bsg.c
36037@@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
36038 struct sg_io_v4 *hdr, struct bsg_device *bd,
36039 fmode_t has_write_perm)
36040 {
36041+ unsigned char tmpcmd[sizeof(rq->__cmd)];
36042+ unsigned char *cmdptr;
36043+
36044 if (hdr->request_len > BLK_MAX_CDB) {
36045 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
36046 if (!rq->cmd)
36047 return -ENOMEM;
36048- }
36049+ cmdptr = rq->cmd;
36050+ } else
36051+ cmdptr = tmpcmd;
36052
36053- if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
36054+ if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
36055 hdr->request_len))
36056 return -EFAULT;
36057
36058+ if (cmdptr != rq->cmd)
36059+ memcpy(rq->cmd, cmdptr, hdr->request_len);
36060+
36061 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
36062 if (blk_verify_command(rq->cmd, has_write_perm))
36063 return -EPERM;
36064diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
36065index f678c73..f35aa18 100644
36066--- a/block/compat_ioctl.c
36067+++ b/block/compat_ioctl.c
36068@@ -156,7 +156,7 @@ static int compat_cdrom_generic_command(struct block_device *bdev, fmode_t mode,
36069 cgc = compat_alloc_user_space(sizeof(*cgc));
36070 cgc32 = compat_ptr(arg);
36071
36072- if (copy_in_user(&cgc->cmd, &cgc32->cmd, sizeof(cgc->cmd)) ||
36073+ if (copy_in_user(cgc->cmd, cgc32->cmd, sizeof(cgc->cmd)) ||
36074 get_user(data, &cgc32->buffer) ||
36075 put_user(compat_ptr(data), &cgc->buffer) ||
36076 copy_in_user(&cgc->buflen, &cgc32->buflen,
36077@@ -341,7 +341,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
36078 err |= __get_user(f->spec1, &uf->spec1);
36079 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
36080 err |= __get_user(name, &uf->name);
36081- f->name = compat_ptr(name);
36082+ f->name = (void __force_kernel *)compat_ptr(name);
36083 if (err) {
36084 err = -EFAULT;
36085 goto out;
36086diff --git a/block/genhd.c b/block/genhd.c
36087index 0a536dc..b8f7aca 100644
36088--- a/block/genhd.c
36089+++ b/block/genhd.c
36090@@ -469,21 +469,24 @@ static char *bdevt_str(dev_t devt, char *buf)
36091
36092 /*
36093 * Register device numbers dev..(dev+range-1)
36094- * range must be nonzero
36095+ * Noop if @range is zero.
36096 * The hash chain is sorted on range, so that subranges can override.
36097 */
36098 void blk_register_region(dev_t devt, unsigned long range, struct module *module,
36099 struct kobject *(*probe)(dev_t, int *, void *),
36100 int (*lock)(dev_t, void *), void *data)
36101 {
36102- kobj_map(bdev_map, devt, range, module, probe, lock, data);
36103+ if (range)
36104+ kobj_map(bdev_map, devt, range, module, probe, lock, data);
36105 }
36106
36107 EXPORT_SYMBOL(blk_register_region);
36108
36109+/* undo blk_register_region(), noop if @range is zero */
36110 void blk_unregister_region(dev_t devt, unsigned long range)
36111 {
36112- kobj_unmap(bdev_map, devt, range);
36113+ if (range)
36114+ kobj_unmap(bdev_map, devt, range);
36115 }
36116
36117 EXPORT_SYMBOL(blk_unregister_region);
36118diff --git a/block/partitions/efi.c b/block/partitions/efi.c
36119index 56d08fd..2e07090 100644
36120--- a/block/partitions/efi.c
36121+++ b/block/partitions/efi.c
36122@@ -293,14 +293,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
36123 if (!gpt)
36124 return NULL;
36125
36126+ if (!le32_to_cpu(gpt->num_partition_entries))
36127+ return NULL;
36128+ pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
36129+ if (!pte)
36130+ return NULL;
36131+
36132 count = le32_to_cpu(gpt->num_partition_entries) *
36133 le32_to_cpu(gpt->sizeof_partition_entry);
36134- if (!count)
36135- return NULL;
36136- pte = kmalloc(count, GFP_KERNEL);
36137- if (!pte)
36138- return NULL;
36139-
36140 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
36141 (u8 *) pte, count) < count) {
36142 kfree(pte);
36143diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
36144index b0c2a61..10bb6ec 100644
36145--- a/block/scsi_ioctl.c
36146+++ b/block/scsi_ioctl.c
36147@@ -67,7 +67,7 @@ static int scsi_get_bus(struct request_queue *q, int __user *p)
36148 return put_user(0, p);
36149 }
36150
36151-static int sg_get_timeout(struct request_queue *q)
36152+static int __intentional_overflow(-1) sg_get_timeout(struct request_queue *q)
36153 {
36154 return jiffies_to_clock_t(q->sg_timeout);
36155 }
36156@@ -227,8 +227,20 @@ EXPORT_SYMBOL(blk_verify_command);
36157 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
36158 struct sg_io_hdr *hdr, fmode_t mode)
36159 {
36160- if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
36161+ unsigned char tmpcmd[sizeof(rq->__cmd)];
36162+ unsigned char *cmdptr;
36163+
36164+ if (rq->cmd != rq->__cmd)
36165+ cmdptr = rq->cmd;
36166+ else
36167+ cmdptr = tmpcmd;
36168+
36169+ if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
36170 return -EFAULT;
36171+
36172+ if (cmdptr != rq->cmd)
36173+ memcpy(rq->cmd, cmdptr, hdr->cmd_len);
36174+
36175 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
36176 return -EPERM;
36177
36178@@ -431,6 +443,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
36179 int err;
36180 unsigned int in_len, out_len, bytes, opcode, cmdlen;
36181 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
36182+ unsigned char tmpcmd[sizeof(rq->__cmd)];
36183+ unsigned char *cmdptr;
36184
36185 if (!sic)
36186 return -EINVAL;
36187@@ -469,9 +483,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
36188 */
36189 err = -EFAULT;
36190 rq->cmd_len = cmdlen;
36191- if (copy_from_user(rq->cmd, sic->data, cmdlen))
36192+
36193+ if (rq->cmd != rq->__cmd)
36194+ cmdptr = rq->cmd;
36195+ else
36196+ cmdptr = tmpcmd;
36197+
36198+ if (copy_from_user(cmdptr, sic->data, cmdlen))
36199 goto error;
36200
36201+ if (rq->cmd != cmdptr)
36202+ memcpy(rq->cmd, cmdptr, cmdlen);
36203+
36204 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
36205 goto error;
36206
36207diff --git a/crypto/cryptd.c b/crypto/cryptd.c
36208index e592c90..c566114 100644
36209--- a/crypto/cryptd.c
36210+++ b/crypto/cryptd.c
36211@@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
36212
36213 struct cryptd_blkcipher_request_ctx {
36214 crypto_completion_t complete;
36215-};
36216+} __no_const;
36217
36218 struct cryptd_hash_ctx {
36219 struct crypto_shash *child;
36220@@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
36221
36222 struct cryptd_aead_request_ctx {
36223 crypto_completion_t complete;
36224-};
36225+} __no_const;
36226
36227 static void cryptd_queue_worker(struct work_struct *work);
36228
36229diff --git a/crypto/pcrypt.c b/crypto/pcrypt.c
36230index 309d345..1632720 100644
36231--- a/crypto/pcrypt.c
36232+++ b/crypto/pcrypt.c
36233@@ -440,7 +440,7 @@ static int pcrypt_sysfs_add(struct padata_instance *pinst, const char *name)
36234 int ret;
36235
36236 pinst->kobj.kset = pcrypt_kset;
36237- ret = kobject_add(&pinst->kobj, NULL, name);
36238+ ret = kobject_add(&pinst->kobj, NULL, "%s", name);
36239 if (!ret)
36240 kobject_uevent(&pinst->kobj, KOBJ_ADD);
36241
36242diff --git a/drivers/acpi/acpica/hwxfsleep.c b/drivers/acpi/acpica/hwxfsleep.c
36243index 6921c7f..78e1af7 100644
36244--- a/drivers/acpi/acpica/hwxfsleep.c
36245+++ b/drivers/acpi/acpica/hwxfsleep.c
36246@@ -63,11 +63,12 @@ static acpi_status acpi_hw_sleep_dispatch(u8 sleep_state, u32 function_id);
36247 /* Legacy functions are optional, based upon ACPI_REDUCED_HARDWARE */
36248
36249 static struct acpi_sleep_functions acpi_sleep_dispatch[] = {
36250- {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_sleep),
36251- acpi_hw_extended_sleep},
36252- {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake_prep),
36253- acpi_hw_extended_wake_prep},
36254- {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake), acpi_hw_extended_wake}
36255+ {.legacy_function = ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_sleep),
36256+ .extended_function = acpi_hw_extended_sleep},
36257+ {.legacy_function = ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake_prep),
36258+ .extended_function = acpi_hw_extended_wake_prep},
36259+ {.legacy_function = ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake),
36260+ .extended_function = acpi_hw_extended_wake}
36261 };
36262
36263 /*
36264diff --git a/drivers/acpi/apei/apei-internal.h b/drivers/acpi/apei/apei-internal.h
36265index 16129c7..8b675cd 100644
36266--- a/drivers/acpi/apei/apei-internal.h
36267+++ b/drivers/acpi/apei/apei-internal.h
36268@@ -19,7 +19,7 @@ typedef int (*apei_exec_ins_func_t)(struct apei_exec_context *ctx,
36269 struct apei_exec_ins_type {
36270 u32 flags;
36271 apei_exec_ins_func_t run;
36272-};
36273+} __do_const;
36274
36275 struct apei_exec_context {
36276 u32 ip;
36277diff --git a/drivers/acpi/apei/ghes.c b/drivers/acpi/apei/ghes.c
36278index fc5f780..e5ac91a 100644
36279--- a/drivers/acpi/apei/ghes.c
36280+++ b/drivers/acpi/apei/ghes.c
36281@@ -478,7 +478,7 @@ static void __ghes_print_estatus(const char *pfx,
36282 const struct acpi_hest_generic *generic,
36283 const struct acpi_hest_generic_status *estatus)
36284 {
36285- static atomic_t seqno;
36286+ static atomic_unchecked_t seqno;
36287 unsigned int curr_seqno;
36288 char pfx_seq[64];
36289
36290@@ -489,7 +489,7 @@ static void __ghes_print_estatus(const char *pfx,
36291 else
36292 pfx = KERN_ERR;
36293 }
36294- curr_seqno = atomic_inc_return(&seqno);
36295+ curr_seqno = atomic_inc_return_unchecked(&seqno);
36296 snprintf(pfx_seq, sizeof(pfx_seq), "%s{%u}" HW_ERR, pfx, curr_seqno);
36297 printk("%s""Hardware error from APEI Generic Hardware Error Source: %d\n",
36298 pfx_seq, generic->header.source_id);
36299diff --git a/drivers/acpi/bgrt.c b/drivers/acpi/bgrt.c
36300index a83e3c6..c3d617f 100644
36301--- a/drivers/acpi/bgrt.c
36302+++ b/drivers/acpi/bgrt.c
36303@@ -86,8 +86,10 @@ static int __init bgrt_init(void)
36304 if (!bgrt_image)
36305 return -ENODEV;
36306
36307- bin_attr_image.private = bgrt_image;
36308- bin_attr_image.size = bgrt_image_size;
36309+ pax_open_kernel();
36310+ *(void **)&bin_attr_image.private = bgrt_image;
36311+ *(size_t *)&bin_attr_image.size = bgrt_image_size;
36312+ pax_close_kernel();
36313
36314 bgrt_kobj = kobject_create_and_add("bgrt", acpi_kobj);
36315 if (!bgrt_kobj)
36316diff --git a/drivers/acpi/blacklist.c b/drivers/acpi/blacklist.c
36317index 7556e7c..89a96bd 100644
36318--- a/drivers/acpi/blacklist.c
36319+++ b/drivers/acpi/blacklist.c
36320@@ -51,7 +51,7 @@ struct acpi_blacklist_item {
36321 u32 is_critical_error;
36322 };
36323
36324-static struct dmi_system_id acpi_osi_dmi_table[] __initdata;
36325+static const struct dmi_system_id acpi_osi_dmi_table[] __initconst;
36326
36327 /*
36328 * POLICY: If *anything* doesn't work, put it on the blacklist.
36329@@ -163,7 +163,7 @@ static int __init dmi_disable_osi_win8(const struct dmi_system_id *d)
36330 return 0;
36331 }
36332
36333-static struct dmi_system_id acpi_osi_dmi_table[] __initdata = {
36334+static const struct dmi_system_id acpi_osi_dmi_table[] __initconst = {
36335 {
36336 .callback = dmi_disable_osi_vista,
36337 .ident = "Fujitsu Siemens",
36338diff --git a/drivers/acpi/custom_method.c b/drivers/acpi/custom_method.c
36339index c68e724..e863008 100644
36340--- a/drivers/acpi/custom_method.c
36341+++ b/drivers/acpi/custom_method.c
36342@@ -29,6 +29,10 @@ static ssize_t cm_write(struct file *file, const char __user * user_buf,
36343 struct acpi_table_header table;
36344 acpi_status status;
36345
36346+#ifdef CONFIG_GRKERNSEC_KMEM
36347+ return -EPERM;
36348+#endif
36349+
36350 if (!(*ppos)) {
36351 /* parse the table header to get the table length */
36352 if (count <= sizeof(struct acpi_table_header))
36353diff --git a/drivers/acpi/device_pm.c b/drivers/acpi/device_pm.c
36354index 93b7142..5676c75 100644
36355--- a/drivers/acpi/device_pm.c
36356+++ b/drivers/acpi/device_pm.c
36357@@ -1021,6 +1021,8 @@ EXPORT_SYMBOL_GPL(acpi_subsys_freeze);
36358
36359 #endif /* CONFIG_PM_SLEEP */
36360
36361+static void acpi_dev_pm_detach(struct device *dev, bool power_off);
36362+
36363 static struct dev_pm_domain acpi_general_pm_domain = {
36364 .ops = {
36365 #ifdef CONFIG_PM_RUNTIME
36366@@ -1039,6 +1041,7 @@ static struct dev_pm_domain acpi_general_pm_domain = {
36367 .restore_early = acpi_subsys_resume_early,
36368 #endif
36369 },
36370+ .detach = acpi_dev_pm_detach
36371 };
36372
36373 /**
36374@@ -1108,7 +1111,6 @@ int acpi_dev_pm_attach(struct device *dev, bool power_on)
36375 acpi_device_wakeup(adev, ACPI_STATE_S0, false);
36376 }
36377
36378- dev->pm_domain->detach = acpi_dev_pm_detach;
36379 return 0;
36380 }
36381 EXPORT_SYMBOL_GPL(acpi_dev_pm_attach);
36382diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c
36383index 17f9ec5..d9a455e 100644
36384--- a/drivers/acpi/processor_idle.c
36385+++ b/drivers/acpi/processor_idle.c
36386@@ -952,7 +952,7 @@ static int acpi_processor_setup_cpuidle_states(struct acpi_processor *pr)
36387 {
36388 int i, count = CPUIDLE_DRIVER_STATE_START;
36389 struct acpi_processor_cx *cx;
36390- struct cpuidle_state *state;
36391+ cpuidle_state_no_const *state;
36392 struct cpuidle_driver *drv = &acpi_idle_driver;
36393
36394 if (!pr->flags.power_setup_done)
36395diff --git a/drivers/acpi/sysfs.c b/drivers/acpi/sysfs.c
36396index 13e577c..cef11ee 100644
36397--- a/drivers/acpi/sysfs.c
36398+++ b/drivers/acpi/sysfs.c
36399@@ -423,11 +423,11 @@ static u32 num_counters;
36400 static struct attribute **all_attrs;
36401 static u32 acpi_gpe_count;
36402
36403-static struct attribute_group interrupt_stats_attr_group = {
36404+static attribute_group_no_const interrupt_stats_attr_group = {
36405 .name = "interrupts",
36406 };
36407
36408-static struct kobj_attribute *counter_attrs;
36409+static kobj_attribute_no_const *counter_attrs;
36410
36411 static void delete_gpe_attr_array(void)
36412 {
36413diff --git a/drivers/ata/libahci.c b/drivers/ata/libahci.c
36414index 97683e4..655f6ba 100644
36415--- a/drivers/ata/libahci.c
36416+++ b/drivers/ata/libahci.c
36417@@ -1252,7 +1252,7 @@ int ahci_kick_engine(struct ata_port *ap)
36418 }
36419 EXPORT_SYMBOL_GPL(ahci_kick_engine);
36420
36421-static int ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
36422+static int __intentional_overflow(-1) ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
36423 struct ata_taskfile *tf, int is_cmd, u16 flags,
36424 unsigned long timeout_msec)
36425 {
36426diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
36427index c5ba15a..75ec7a8 100644
36428--- a/drivers/ata/libata-core.c
36429+++ b/drivers/ata/libata-core.c
36430@@ -99,7 +99,7 @@ static unsigned int ata_dev_set_xfermode(struct ata_device *dev);
36431 static void ata_dev_xfermask(struct ata_device *dev);
36432 static unsigned long ata_dev_blacklisted(const struct ata_device *dev);
36433
36434-atomic_t ata_print_id = ATOMIC_INIT(0);
36435+atomic_unchecked_t ata_print_id = ATOMIC_INIT(0);
36436
36437 struct ata_force_param {
36438 const char *name;
36439@@ -4797,7 +4797,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
36440 struct ata_port *ap;
36441 unsigned int tag;
36442
36443- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
36444+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
36445 ap = qc->ap;
36446
36447 qc->flags = 0;
36448@@ -4813,7 +4813,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
36449 struct ata_port *ap;
36450 struct ata_link *link;
36451
36452- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
36453+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
36454 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
36455 ap = qc->ap;
36456 link = qc->dev->link;
36457@@ -5917,6 +5917,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
36458 return;
36459
36460 spin_lock(&lock);
36461+ pax_open_kernel();
36462
36463 for (cur = ops->inherits; cur; cur = cur->inherits) {
36464 void **inherit = (void **)cur;
36465@@ -5930,8 +5931,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
36466 if (IS_ERR(*pp))
36467 *pp = NULL;
36468
36469- ops->inherits = NULL;
36470+ *(struct ata_port_operations **)&ops->inherits = NULL;
36471
36472+ pax_close_kernel();
36473 spin_unlock(&lock);
36474 }
36475
36476@@ -6127,7 +6129,7 @@ int ata_host_register(struct ata_host *host, struct scsi_host_template *sht)
36477
36478 /* give ports names and add SCSI hosts */
36479 for (i = 0; i < host->n_ports; i++) {
36480- host->ports[i]->print_id = atomic_inc_return(&ata_print_id);
36481+ host->ports[i]->print_id = atomic_inc_return_unchecked(&ata_print_id);
36482 host->ports[i]->local_port_no = i + 1;
36483 }
36484
36485diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
36486index 0586f66..1a8f74a 100644
36487--- a/drivers/ata/libata-scsi.c
36488+++ b/drivers/ata/libata-scsi.c
36489@@ -4151,7 +4151,7 @@ int ata_sas_port_init(struct ata_port *ap)
36490
36491 if (rc)
36492 return rc;
36493- ap->print_id = atomic_inc_return(&ata_print_id);
36494+ ap->print_id = atomic_inc_return_unchecked(&ata_print_id);
36495 return 0;
36496 }
36497 EXPORT_SYMBOL_GPL(ata_sas_port_init);
36498diff --git a/drivers/ata/libata.h b/drivers/ata/libata.h
36499index 5f4e0cc..ff2c347 100644
36500--- a/drivers/ata/libata.h
36501+++ b/drivers/ata/libata.h
36502@@ -53,7 +53,7 @@ enum {
36503 ATA_DNXFER_QUIET = (1 << 31),
36504 };
36505
36506-extern atomic_t ata_print_id;
36507+extern atomic_unchecked_t ata_print_id;
36508 extern int atapi_passthru16;
36509 extern int libata_fua;
36510 extern int libata_noacpi;
36511diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
36512index 38216b9..4ec6aeb 100644
36513--- a/drivers/ata/pata_arasan_cf.c
36514+++ b/drivers/ata/pata_arasan_cf.c
36515@@ -865,7 +865,9 @@ static int arasan_cf_probe(struct platform_device *pdev)
36516 /* Handle platform specific quirks */
36517 if (quirk) {
36518 if (quirk & CF_BROKEN_PIO) {
36519- ap->ops->set_piomode = NULL;
36520+ pax_open_kernel();
36521+ *(void **)&ap->ops->set_piomode = NULL;
36522+ pax_close_kernel();
36523 ap->pio_mask = 0;
36524 }
36525 if (quirk & CF_BROKEN_MWDMA)
36526diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
36527index f9b983a..887b9d8 100644
36528--- a/drivers/atm/adummy.c
36529+++ b/drivers/atm/adummy.c
36530@@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
36531 vcc->pop(vcc, skb);
36532 else
36533 dev_kfree_skb_any(skb);
36534- atomic_inc(&vcc->stats->tx);
36535+ atomic_inc_unchecked(&vcc->stats->tx);
36536
36537 return 0;
36538 }
36539diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
36540index f1a9198..f466a4a 100644
36541--- a/drivers/atm/ambassador.c
36542+++ b/drivers/atm/ambassador.c
36543@@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
36544 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
36545
36546 // VC layer stats
36547- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
36548+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
36549
36550 // free the descriptor
36551 kfree (tx_descr);
36552@@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
36553 dump_skb ("<<<", vc, skb);
36554
36555 // VC layer stats
36556- atomic_inc(&atm_vcc->stats->rx);
36557+ atomic_inc_unchecked(&atm_vcc->stats->rx);
36558 __net_timestamp(skb);
36559 // end of our responsibility
36560 atm_vcc->push (atm_vcc, skb);
36561@@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
36562 } else {
36563 PRINTK (KERN_INFO, "dropped over-size frame");
36564 // should we count this?
36565- atomic_inc(&atm_vcc->stats->rx_drop);
36566+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
36567 }
36568
36569 } else {
36570@@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
36571 }
36572
36573 if (check_area (skb->data, skb->len)) {
36574- atomic_inc(&atm_vcc->stats->tx_err);
36575+ atomic_inc_unchecked(&atm_vcc->stats->tx_err);
36576 return -ENOMEM; // ?
36577 }
36578
36579diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
36580index 480fa6f..947067c 100644
36581--- a/drivers/atm/atmtcp.c
36582+++ b/drivers/atm/atmtcp.c
36583@@ -206,7 +206,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
36584 if (vcc->pop) vcc->pop(vcc,skb);
36585 else dev_kfree_skb(skb);
36586 if (dev_data) return 0;
36587- atomic_inc(&vcc->stats->tx_err);
36588+ atomic_inc_unchecked(&vcc->stats->tx_err);
36589 return -ENOLINK;
36590 }
36591 size = skb->len+sizeof(struct atmtcp_hdr);
36592@@ -214,7 +214,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
36593 if (!new_skb) {
36594 if (vcc->pop) vcc->pop(vcc,skb);
36595 else dev_kfree_skb(skb);
36596- atomic_inc(&vcc->stats->tx_err);
36597+ atomic_inc_unchecked(&vcc->stats->tx_err);
36598 return -ENOBUFS;
36599 }
36600 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
36601@@ -225,8 +225,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
36602 if (vcc->pop) vcc->pop(vcc,skb);
36603 else dev_kfree_skb(skb);
36604 out_vcc->push(out_vcc,new_skb);
36605- atomic_inc(&vcc->stats->tx);
36606- atomic_inc(&out_vcc->stats->rx);
36607+ atomic_inc_unchecked(&vcc->stats->tx);
36608+ atomic_inc_unchecked(&out_vcc->stats->rx);
36609 return 0;
36610 }
36611
36612@@ -300,7 +300,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
36613 read_unlock(&vcc_sklist_lock);
36614 if (!out_vcc) {
36615 result = -EUNATCH;
36616- atomic_inc(&vcc->stats->tx_err);
36617+ atomic_inc_unchecked(&vcc->stats->tx_err);
36618 goto done;
36619 }
36620 skb_pull(skb,sizeof(struct atmtcp_hdr));
36621@@ -312,8 +312,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
36622 __net_timestamp(new_skb);
36623 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
36624 out_vcc->push(out_vcc,new_skb);
36625- atomic_inc(&vcc->stats->tx);
36626- atomic_inc(&out_vcc->stats->rx);
36627+ atomic_inc_unchecked(&vcc->stats->tx);
36628+ atomic_inc_unchecked(&out_vcc->stats->rx);
36629 done:
36630 if (vcc->pop) vcc->pop(vcc,skb);
36631 else dev_kfree_skb(skb);
36632diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
36633index d65975a..0b87e20 100644
36634--- a/drivers/atm/eni.c
36635+++ b/drivers/atm/eni.c
36636@@ -522,7 +522,7 @@ static int rx_aal0(struct atm_vcc *vcc)
36637 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
36638 vcc->dev->number);
36639 length = 0;
36640- atomic_inc(&vcc->stats->rx_err);
36641+ atomic_inc_unchecked(&vcc->stats->rx_err);
36642 }
36643 else {
36644 length = ATM_CELL_SIZE-1; /* no HEC */
36645@@ -577,7 +577,7 @@ static int rx_aal5(struct atm_vcc *vcc)
36646 size);
36647 }
36648 eff = length = 0;
36649- atomic_inc(&vcc->stats->rx_err);
36650+ atomic_inc_unchecked(&vcc->stats->rx_err);
36651 }
36652 else {
36653 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
36654@@ -594,7 +594,7 @@ static int rx_aal5(struct atm_vcc *vcc)
36655 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
36656 vcc->dev->number,vcc->vci,length,size << 2,descr);
36657 length = eff = 0;
36658- atomic_inc(&vcc->stats->rx_err);
36659+ atomic_inc_unchecked(&vcc->stats->rx_err);
36660 }
36661 }
36662 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
36663@@ -767,7 +767,7 @@ rx_dequeued++;
36664 vcc->push(vcc,skb);
36665 pushed++;
36666 }
36667- atomic_inc(&vcc->stats->rx);
36668+ atomic_inc_unchecked(&vcc->stats->rx);
36669 }
36670 wake_up(&eni_dev->rx_wait);
36671 }
36672@@ -1227,7 +1227,7 @@ static void dequeue_tx(struct atm_dev *dev)
36673 PCI_DMA_TODEVICE);
36674 if (vcc->pop) vcc->pop(vcc,skb);
36675 else dev_kfree_skb_irq(skb);
36676- atomic_inc(&vcc->stats->tx);
36677+ atomic_inc_unchecked(&vcc->stats->tx);
36678 wake_up(&eni_dev->tx_wait);
36679 dma_complete++;
36680 }
36681diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
36682index 82f2ae0..f205c02 100644
36683--- a/drivers/atm/firestream.c
36684+++ b/drivers/atm/firestream.c
36685@@ -749,7 +749,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
36686 }
36687 }
36688
36689- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
36690+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
36691
36692 fs_dprintk (FS_DEBUG_TXMEM, "i");
36693 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
36694@@ -816,7 +816,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
36695 #endif
36696 skb_put (skb, qe->p1 & 0xffff);
36697 ATM_SKB(skb)->vcc = atm_vcc;
36698- atomic_inc(&atm_vcc->stats->rx);
36699+ atomic_inc_unchecked(&atm_vcc->stats->rx);
36700 __net_timestamp(skb);
36701 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
36702 atm_vcc->push (atm_vcc, skb);
36703@@ -837,12 +837,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
36704 kfree (pe);
36705 }
36706 if (atm_vcc)
36707- atomic_inc(&atm_vcc->stats->rx_drop);
36708+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
36709 break;
36710 case 0x1f: /* Reassembly abort: no buffers. */
36711 /* Silently increment error counter. */
36712 if (atm_vcc)
36713- atomic_inc(&atm_vcc->stats->rx_drop);
36714+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
36715 break;
36716 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
36717 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
36718diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
36719index d4725fc..2d4ea65 100644
36720--- a/drivers/atm/fore200e.c
36721+++ b/drivers/atm/fore200e.c
36722@@ -931,9 +931,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
36723 #endif
36724 /* check error condition */
36725 if (*entry->status & STATUS_ERROR)
36726- atomic_inc(&vcc->stats->tx_err);
36727+ atomic_inc_unchecked(&vcc->stats->tx_err);
36728 else
36729- atomic_inc(&vcc->stats->tx);
36730+ atomic_inc_unchecked(&vcc->stats->tx);
36731 }
36732 }
36733
36734@@ -1082,7 +1082,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
36735 if (skb == NULL) {
36736 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
36737
36738- atomic_inc(&vcc->stats->rx_drop);
36739+ atomic_inc_unchecked(&vcc->stats->rx_drop);
36740 return -ENOMEM;
36741 }
36742
36743@@ -1125,14 +1125,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
36744
36745 dev_kfree_skb_any(skb);
36746
36747- atomic_inc(&vcc->stats->rx_drop);
36748+ atomic_inc_unchecked(&vcc->stats->rx_drop);
36749 return -ENOMEM;
36750 }
36751
36752 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
36753
36754 vcc->push(vcc, skb);
36755- atomic_inc(&vcc->stats->rx);
36756+ atomic_inc_unchecked(&vcc->stats->rx);
36757
36758 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
36759
36760@@ -1210,7 +1210,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
36761 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
36762 fore200e->atm_dev->number,
36763 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
36764- atomic_inc(&vcc->stats->rx_err);
36765+ atomic_inc_unchecked(&vcc->stats->rx_err);
36766 }
36767 }
36768
36769@@ -1655,7 +1655,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
36770 goto retry_here;
36771 }
36772
36773- atomic_inc(&vcc->stats->tx_err);
36774+ atomic_inc_unchecked(&vcc->stats->tx_err);
36775
36776 fore200e->tx_sat++;
36777 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
36778diff --git a/drivers/atm/he.c b/drivers/atm/he.c
36779index c39702b..785b73b 100644
36780--- a/drivers/atm/he.c
36781+++ b/drivers/atm/he.c
36782@@ -1689,7 +1689,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
36783
36784 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
36785 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
36786- atomic_inc(&vcc->stats->rx_drop);
36787+ atomic_inc_unchecked(&vcc->stats->rx_drop);
36788 goto return_host_buffers;
36789 }
36790
36791@@ -1716,7 +1716,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
36792 RBRQ_LEN_ERR(he_dev->rbrq_head)
36793 ? "LEN_ERR" : "",
36794 vcc->vpi, vcc->vci);
36795- atomic_inc(&vcc->stats->rx_err);
36796+ atomic_inc_unchecked(&vcc->stats->rx_err);
36797 goto return_host_buffers;
36798 }
36799
36800@@ -1768,7 +1768,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
36801 vcc->push(vcc, skb);
36802 spin_lock(&he_dev->global_lock);
36803
36804- atomic_inc(&vcc->stats->rx);
36805+ atomic_inc_unchecked(&vcc->stats->rx);
36806
36807 return_host_buffers:
36808 ++pdus_assembled;
36809@@ -2094,7 +2094,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
36810 tpd->vcc->pop(tpd->vcc, tpd->skb);
36811 else
36812 dev_kfree_skb_any(tpd->skb);
36813- atomic_inc(&tpd->vcc->stats->tx_err);
36814+ atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
36815 }
36816 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
36817 return;
36818@@ -2506,7 +2506,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36819 vcc->pop(vcc, skb);
36820 else
36821 dev_kfree_skb_any(skb);
36822- atomic_inc(&vcc->stats->tx_err);
36823+ atomic_inc_unchecked(&vcc->stats->tx_err);
36824 return -EINVAL;
36825 }
36826
36827@@ -2517,7 +2517,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36828 vcc->pop(vcc, skb);
36829 else
36830 dev_kfree_skb_any(skb);
36831- atomic_inc(&vcc->stats->tx_err);
36832+ atomic_inc_unchecked(&vcc->stats->tx_err);
36833 return -EINVAL;
36834 }
36835 #endif
36836@@ -2529,7 +2529,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36837 vcc->pop(vcc, skb);
36838 else
36839 dev_kfree_skb_any(skb);
36840- atomic_inc(&vcc->stats->tx_err);
36841+ atomic_inc_unchecked(&vcc->stats->tx_err);
36842 spin_unlock_irqrestore(&he_dev->global_lock, flags);
36843 return -ENOMEM;
36844 }
36845@@ -2571,7 +2571,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36846 vcc->pop(vcc, skb);
36847 else
36848 dev_kfree_skb_any(skb);
36849- atomic_inc(&vcc->stats->tx_err);
36850+ atomic_inc_unchecked(&vcc->stats->tx_err);
36851 spin_unlock_irqrestore(&he_dev->global_lock, flags);
36852 return -ENOMEM;
36853 }
36854@@ -2602,7 +2602,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36855 __enqueue_tpd(he_dev, tpd, cid);
36856 spin_unlock_irqrestore(&he_dev->global_lock, flags);
36857
36858- atomic_inc(&vcc->stats->tx);
36859+ atomic_inc_unchecked(&vcc->stats->tx);
36860
36861 return 0;
36862 }
36863diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
36864index 1dc0519..1aadaf7 100644
36865--- a/drivers/atm/horizon.c
36866+++ b/drivers/atm/horizon.c
36867@@ -1034,7 +1034,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
36868 {
36869 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
36870 // VC layer stats
36871- atomic_inc(&vcc->stats->rx);
36872+ atomic_inc_unchecked(&vcc->stats->rx);
36873 __net_timestamp(skb);
36874 // end of our responsibility
36875 vcc->push (vcc, skb);
36876@@ -1186,7 +1186,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
36877 dev->tx_iovec = NULL;
36878
36879 // VC layer stats
36880- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
36881+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
36882
36883 // free the skb
36884 hrz_kfree_skb (skb);
36885diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
36886index 2b24ed0..b3d6acc 100644
36887--- a/drivers/atm/idt77252.c
36888+++ b/drivers/atm/idt77252.c
36889@@ -810,7 +810,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
36890 else
36891 dev_kfree_skb(skb);
36892
36893- atomic_inc(&vcc->stats->tx);
36894+ atomic_inc_unchecked(&vcc->stats->tx);
36895 }
36896
36897 atomic_dec(&scq->used);
36898@@ -1072,13 +1072,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36899 if ((sb = dev_alloc_skb(64)) == NULL) {
36900 printk("%s: Can't allocate buffers for aal0.\n",
36901 card->name);
36902- atomic_add(i, &vcc->stats->rx_drop);
36903+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
36904 break;
36905 }
36906 if (!atm_charge(vcc, sb->truesize)) {
36907 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
36908 card->name);
36909- atomic_add(i - 1, &vcc->stats->rx_drop);
36910+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
36911 dev_kfree_skb(sb);
36912 break;
36913 }
36914@@ -1095,7 +1095,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36915 ATM_SKB(sb)->vcc = vcc;
36916 __net_timestamp(sb);
36917 vcc->push(vcc, sb);
36918- atomic_inc(&vcc->stats->rx);
36919+ atomic_inc_unchecked(&vcc->stats->rx);
36920
36921 cell += ATM_CELL_PAYLOAD;
36922 }
36923@@ -1132,13 +1132,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36924 "(CDC: %08x)\n",
36925 card->name, len, rpp->len, readl(SAR_REG_CDC));
36926 recycle_rx_pool_skb(card, rpp);
36927- atomic_inc(&vcc->stats->rx_err);
36928+ atomic_inc_unchecked(&vcc->stats->rx_err);
36929 return;
36930 }
36931 if (stat & SAR_RSQE_CRC) {
36932 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
36933 recycle_rx_pool_skb(card, rpp);
36934- atomic_inc(&vcc->stats->rx_err);
36935+ atomic_inc_unchecked(&vcc->stats->rx_err);
36936 return;
36937 }
36938 if (skb_queue_len(&rpp->queue) > 1) {
36939@@ -1149,7 +1149,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36940 RXPRINTK("%s: Can't alloc RX skb.\n",
36941 card->name);
36942 recycle_rx_pool_skb(card, rpp);
36943- atomic_inc(&vcc->stats->rx_err);
36944+ atomic_inc_unchecked(&vcc->stats->rx_err);
36945 return;
36946 }
36947 if (!atm_charge(vcc, skb->truesize)) {
36948@@ -1168,7 +1168,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36949 __net_timestamp(skb);
36950
36951 vcc->push(vcc, skb);
36952- atomic_inc(&vcc->stats->rx);
36953+ atomic_inc_unchecked(&vcc->stats->rx);
36954
36955 return;
36956 }
36957@@ -1190,7 +1190,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36958 __net_timestamp(skb);
36959
36960 vcc->push(vcc, skb);
36961- atomic_inc(&vcc->stats->rx);
36962+ atomic_inc_unchecked(&vcc->stats->rx);
36963
36964 if (skb->truesize > SAR_FB_SIZE_3)
36965 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
36966@@ -1301,14 +1301,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
36967 if (vcc->qos.aal != ATM_AAL0) {
36968 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
36969 card->name, vpi, vci);
36970- atomic_inc(&vcc->stats->rx_drop);
36971+ atomic_inc_unchecked(&vcc->stats->rx_drop);
36972 goto drop;
36973 }
36974
36975 if ((sb = dev_alloc_skb(64)) == NULL) {
36976 printk("%s: Can't allocate buffers for AAL0.\n",
36977 card->name);
36978- atomic_inc(&vcc->stats->rx_err);
36979+ atomic_inc_unchecked(&vcc->stats->rx_err);
36980 goto drop;
36981 }
36982
36983@@ -1327,7 +1327,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
36984 ATM_SKB(sb)->vcc = vcc;
36985 __net_timestamp(sb);
36986 vcc->push(vcc, sb);
36987- atomic_inc(&vcc->stats->rx);
36988+ atomic_inc_unchecked(&vcc->stats->rx);
36989
36990 drop:
36991 skb_pull(queue, 64);
36992@@ -1952,13 +1952,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
36993
36994 if (vc == NULL) {
36995 printk("%s: NULL connection in send().\n", card->name);
36996- atomic_inc(&vcc->stats->tx_err);
36997+ atomic_inc_unchecked(&vcc->stats->tx_err);
36998 dev_kfree_skb(skb);
36999 return -EINVAL;
37000 }
37001 if (!test_bit(VCF_TX, &vc->flags)) {
37002 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
37003- atomic_inc(&vcc->stats->tx_err);
37004+ atomic_inc_unchecked(&vcc->stats->tx_err);
37005 dev_kfree_skb(skb);
37006 return -EINVAL;
37007 }
37008@@ -1970,14 +1970,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
37009 break;
37010 default:
37011 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
37012- atomic_inc(&vcc->stats->tx_err);
37013+ atomic_inc_unchecked(&vcc->stats->tx_err);
37014 dev_kfree_skb(skb);
37015 return -EINVAL;
37016 }
37017
37018 if (skb_shinfo(skb)->nr_frags != 0) {
37019 printk("%s: No scatter-gather yet.\n", card->name);
37020- atomic_inc(&vcc->stats->tx_err);
37021+ atomic_inc_unchecked(&vcc->stats->tx_err);
37022 dev_kfree_skb(skb);
37023 return -EINVAL;
37024 }
37025@@ -1985,7 +1985,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
37026
37027 err = queue_skb(card, vc, skb, oam);
37028 if (err) {
37029- atomic_inc(&vcc->stats->tx_err);
37030+ atomic_inc_unchecked(&vcc->stats->tx_err);
37031 dev_kfree_skb(skb);
37032 return err;
37033 }
37034@@ -2008,7 +2008,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
37035 skb = dev_alloc_skb(64);
37036 if (!skb) {
37037 printk("%s: Out of memory in send_oam().\n", card->name);
37038- atomic_inc(&vcc->stats->tx_err);
37039+ atomic_inc_unchecked(&vcc->stats->tx_err);
37040 return -ENOMEM;
37041 }
37042 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
37043diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
37044index 4217f29..88f547a 100644
37045--- a/drivers/atm/iphase.c
37046+++ b/drivers/atm/iphase.c
37047@@ -1145,7 +1145,7 @@ static int rx_pkt(struct atm_dev *dev)
37048 status = (u_short) (buf_desc_ptr->desc_mode);
37049 if (status & (RX_CER | RX_PTE | RX_OFL))
37050 {
37051- atomic_inc(&vcc->stats->rx_err);
37052+ atomic_inc_unchecked(&vcc->stats->rx_err);
37053 IF_ERR(printk("IA: bad packet, dropping it");)
37054 if (status & RX_CER) {
37055 IF_ERR(printk(" cause: packet CRC error\n");)
37056@@ -1168,7 +1168,7 @@ static int rx_pkt(struct atm_dev *dev)
37057 len = dma_addr - buf_addr;
37058 if (len > iadev->rx_buf_sz) {
37059 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
37060- atomic_inc(&vcc->stats->rx_err);
37061+ atomic_inc_unchecked(&vcc->stats->rx_err);
37062 goto out_free_desc;
37063 }
37064
37065@@ -1318,7 +1318,7 @@ static void rx_dle_intr(struct atm_dev *dev)
37066 ia_vcc = INPH_IA_VCC(vcc);
37067 if (ia_vcc == NULL)
37068 {
37069- atomic_inc(&vcc->stats->rx_err);
37070+ atomic_inc_unchecked(&vcc->stats->rx_err);
37071 atm_return(vcc, skb->truesize);
37072 dev_kfree_skb_any(skb);
37073 goto INCR_DLE;
37074@@ -1330,7 +1330,7 @@ static void rx_dle_intr(struct atm_dev *dev)
37075 if ((length > iadev->rx_buf_sz) || (length >
37076 (skb->len - sizeof(struct cpcs_trailer))))
37077 {
37078- atomic_inc(&vcc->stats->rx_err);
37079+ atomic_inc_unchecked(&vcc->stats->rx_err);
37080 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
37081 length, skb->len);)
37082 atm_return(vcc, skb->truesize);
37083@@ -1346,7 +1346,7 @@ static void rx_dle_intr(struct atm_dev *dev)
37084
37085 IF_RX(printk("rx_dle_intr: skb push");)
37086 vcc->push(vcc,skb);
37087- atomic_inc(&vcc->stats->rx);
37088+ atomic_inc_unchecked(&vcc->stats->rx);
37089 iadev->rx_pkt_cnt++;
37090 }
37091 INCR_DLE:
37092@@ -2826,15 +2826,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
37093 {
37094 struct k_sonet_stats *stats;
37095 stats = &PRIV(_ia_dev[board])->sonet_stats;
37096- printk("section_bip: %d\n", atomic_read(&stats->section_bip));
37097- printk("line_bip : %d\n", atomic_read(&stats->line_bip));
37098- printk("path_bip : %d\n", atomic_read(&stats->path_bip));
37099- printk("line_febe : %d\n", atomic_read(&stats->line_febe));
37100- printk("path_febe : %d\n", atomic_read(&stats->path_febe));
37101- printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
37102- printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
37103- printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
37104- printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
37105+ printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
37106+ printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
37107+ printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
37108+ printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
37109+ printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
37110+ printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
37111+ printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
37112+ printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
37113+ printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
37114 }
37115 ia_cmds.status = 0;
37116 break;
37117@@ -2939,7 +2939,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
37118 if ((desc == 0) || (desc > iadev->num_tx_desc))
37119 {
37120 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
37121- atomic_inc(&vcc->stats->tx);
37122+ atomic_inc_unchecked(&vcc->stats->tx);
37123 if (vcc->pop)
37124 vcc->pop(vcc, skb);
37125 else
37126@@ -3044,14 +3044,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
37127 ATM_DESC(skb) = vcc->vci;
37128 skb_queue_tail(&iadev->tx_dma_q, skb);
37129
37130- atomic_inc(&vcc->stats->tx);
37131+ atomic_inc_unchecked(&vcc->stats->tx);
37132 iadev->tx_pkt_cnt++;
37133 /* Increment transaction counter */
37134 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
37135
37136 #if 0
37137 /* add flow control logic */
37138- if (atomic_read(&vcc->stats->tx) % 20 == 0) {
37139+ if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
37140 if (iavcc->vc_desc_cnt > 10) {
37141 vcc->tx_quota = vcc->tx_quota * 3 / 4;
37142 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
37143diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
37144index 93eaf8d..b4ca7da 100644
37145--- a/drivers/atm/lanai.c
37146+++ b/drivers/atm/lanai.c
37147@@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
37148 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
37149 lanai_endtx(lanai, lvcc);
37150 lanai_free_skb(lvcc->tx.atmvcc, skb);
37151- atomic_inc(&lvcc->tx.atmvcc->stats->tx);
37152+ atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
37153 }
37154
37155 /* Try to fill the buffer - don't call unless there is backlog */
37156@@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
37157 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
37158 __net_timestamp(skb);
37159 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
37160- atomic_inc(&lvcc->rx.atmvcc->stats->rx);
37161+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
37162 out:
37163 lvcc->rx.buf.ptr = end;
37164 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
37165@@ -1667,7 +1667,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
37166 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
37167 "vcc %d\n", lanai->number, (unsigned int) s, vci);
37168 lanai->stats.service_rxnotaal5++;
37169- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
37170+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
37171 return 0;
37172 }
37173 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
37174@@ -1679,7 +1679,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
37175 int bytes;
37176 read_unlock(&vcc_sklist_lock);
37177 DPRINTK("got trashed rx pdu on vci %d\n", vci);
37178- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
37179+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
37180 lvcc->stats.x.aal5.service_trash++;
37181 bytes = (SERVICE_GET_END(s) * 16) -
37182 (((unsigned long) lvcc->rx.buf.ptr) -
37183@@ -1691,7 +1691,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
37184 }
37185 if (s & SERVICE_STREAM) {
37186 read_unlock(&vcc_sklist_lock);
37187- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
37188+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
37189 lvcc->stats.x.aal5.service_stream++;
37190 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
37191 "PDU on VCI %d!\n", lanai->number, vci);
37192@@ -1699,7 +1699,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
37193 return 0;
37194 }
37195 DPRINTK("got rx crc error on vci %d\n", vci);
37196- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
37197+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
37198 lvcc->stats.x.aal5.service_rxcrc++;
37199 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
37200 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
37201diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
37202index 9988ac9..7c52585 100644
37203--- a/drivers/atm/nicstar.c
37204+++ b/drivers/atm/nicstar.c
37205@@ -1640,7 +1640,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
37206 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
37207 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
37208 card->index);
37209- atomic_inc(&vcc->stats->tx_err);
37210+ atomic_inc_unchecked(&vcc->stats->tx_err);
37211 dev_kfree_skb_any(skb);
37212 return -EINVAL;
37213 }
37214@@ -1648,7 +1648,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
37215 if (!vc->tx) {
37216 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
37217 card->index);
37218- atomic_inc(&vcc->stats->tx_err);
37219+ atomic_inc_unchecked(&vcc->stats->tx_err);
37220 dev_kfree_skb_any(skb);
37221 return -EINVAL;
37222 }
37223@@ -1656,14 +1656,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
37224 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
37225 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
37226 card->index);
37227- atomic_inc(&vcc->stats->tx_err);
37228+ atomic_inc_unchecked(&vcc->stats->tx_err);
37229 dev_kfree_skb_any(skb);
37230 return -EINVAL;
37231 }
37232
37233 if (skb_shinfo(skb)->nr_frags != 0) {
37234 printk("nicstar%d: No scatter-gather yet.\n", card->index);
37235- atomic_inc(&vcc->stats->tx_err);
37236+ atomic_inc_unchecked(&vcc->stats->tx_err);
37237 dev_kfree_skb_any(skb);
37238 return -EINVAL;
37239 }
37240@@ -1711,11 +1711,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
37241 }
37242
37243 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
37244- atomic_inc(&vcc->stats->tx_err);
37245+ atomic_inc_unchecked(&vcc->stats->tx_err);
37246 dev_kfree_skb_any(skb);
37247 return -EIO;
37248 }
37249- atomic_inc(&vcc->stats->tx);
37250+ atomic_inc_unchecked(&vcc->stats->tx);
37251
37252 return 0;
37253 }
37254@@ -2032,14 +2032,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37255 printk
37256 ("nicstar%d: Can't allocate buffers for aal0.\n",
37257 card->index);
37258- atomic_add(i, &vcc->stats->rx_drop);
37259+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
37260 break;
37261 }
37262 if (!atm_charge(vcc, sb->truesize)) {
37263 RXPRINTK
37264 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
37265 card->index);
37266- atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
37267+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
37268 dev_kfree_skb_any(sb);
37269 break;
37270 }
37271@@ -2054,7 +2054,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37272 ATM_SKB(sb)->vcc = vcc;
37273 __net_timestamp(sb);
37274 vcc->push(vcc, sb);
37275- atomic_inc(&vcc->stats->rx);
37276+ atomic_inc_unchecked(&vcc->stats->rx);
37277 cell += ATM_CELL_PAYLOAD;
37278 }
37279
37280@@ -2071,7 +2071,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37281 if (iovb == NULL) {
37282 printk("nicstar%d: Out of iovec buffers.\n",
37283 card->index);
37284- atomic_inc(&vcc->stats->rx_drop);
37285+ atomic_inc_unchecked(&vcc->stats->rx_drop);
37286 recycle_rx_buf(card, skb);
37287 return;
37288 }
37289@@ -2095,7 +2095,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37290 small or large buffer itself. */
37291 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
37292 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
37293- atomic_inc(&vcc->stats->rx_err);
37294+ atomic_inc_unchecked(&vcc->stats->rx_err);
37295 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
37296 NS_MAX_IOVECS);
37297 NS_PRV_IOVCNT(iovb) = 0;
37298@@ -2115,7 +2115,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37299 ("nicstar%d: Expected a small buffer, and this is not one.\n",
37300 card->index);
37301 which_list(card, skb);
37302- atomic_inc(&vcc->stats->rx_err);
37303+ atomic_inc_unchecked(&vcc->stats->rx_err);
37304 recycle_rx_buf(card, skb);
37305 vc->rx_iov = NULL;
37306 recycle_iov_buf(card, iovb);
37307@@ -2128,7 +2128,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37308 ("nicstar%d: Expected a large buffer, and this is not one.\n",
37309 card->index);
37310 which_list(card, skb);
37311- atomic_inc(&vcc->stats->rx_err);
37312+ atomic_inc_unchecked(&vcc->stats->rx_err);
37313 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
37314 NS_PRV_IOVCNT(iovb));
37315 vc->rx_iov = NULL;
37316@@ -2151,7 +2151,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37317 printk(" - PDU size mismatch.\n");
37318 else
37319 printk(".\n");
37320- atomic_inc(&vcc->stats->rx_err);
37321+ atomic_inc_unchecked(&vcc->stats->rx_err);
37322 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
37323 NS_PRV_IOVCNT(iovb));
37324 vc->rx_iov = NULL;
37325@@ -2165,7 +2165,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37326 /* skb points to a small buffer */
37327 if (!atm_charge(vcc, skb->truesize)) {
37328 push_rxbufs(card, skb);
37329- atomic_inc(&vcc->stats->rx_drop);
37330+ atomic_inc_unchecked(&vcc->stats->rx_drop);
37331 } else {
37332 skb_put(skb, len);
37333 dequeue_sm_buf(card, skb);
37334@@ -2175,7 +2175,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37335 ATM_SKB(skb)->vcc = vcc;
37336 __net_timestamp(skb);
37337 vcc->push(vcc, skb);
37338- atomic_inc(&vcc->stats->rx);
37339+ atomic_inc_unchecked(&vcc->stats->rx);
37340 }
37341 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
37342 struct sk_buff *sb;
37343@@ -2186,7 +2186,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37344 if (len <= NS_SMBUFSIZE) {
37345 if (!atm_charge(vcc, sb->truesize)) {
37346 push_rxbufs(card, sb);
37347- atomic_inc(&vcc->stats->rx_drop);
37348+ atomic_inc_unchecked(&vcc->stats->rx_drop);
37349 } else {
37350 skb_put(sb, len);
37351 dequeue_sm_buf(card, sb);
37352@@ -2196,7 +2196,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37353 ATM_SKB(sb)->vcc = vcc;
37354 __net_timestamp(sb);
37355 vcc->push(vcc, sb);
37356- atomic_inc(&vcc->stats->rx);
37357+ atomic_inc_unchecked(&vcc->stats->rx);
37358 }
37359
37360 push_rxbufs(card, skb);
37361@@ -2205,7 +2205,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37362
37363 if (!atm_charge(vcc, skb->truesize)) {
37364 push_rxbufs(card, skb);
37365- atomic_inc(&vcc->stats->rx_drop);
37366+ atomic_inc_unchecked(&vcc->stats->rx_drop);
37367 } else {
37368 dequeue_lg_buf(card, skb);
37369 #ifdef NS_USE_DESTRUCTORS
37370@@ -2218,7 +2218,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37371 ATM_SKB(skb)->vcc = vcc;
37372 __net_timestamp(skb);
37373 vcc->push(vcc, skb);
37374- atomic_inc(&vcc->stats->rx);
37375+ atomic_inc_unchecked(&vcc->stats->rx);
37376 }
37377
37378 push_rxbufs(card, sb);
37379@@ -2239,7 +2239,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37380 printk
37381 ("nicstar%d: Out of huge buffers.\n",
37382 card->index);
37383- atomic_inc(&vcc->stats->rx_drop);
37384+ atomic_inc_unchecked(&vcc->stats->rx_drop);
37385 recycle_iovec_rx_bufs(card,
37386 (struct iovec *)
37387 iovb->data,
37388@@ -2290,7 +2290,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37389 card->hbpool.count++;
37390 } else
37391 dev_kfree_skb_any(hb);
37392- atomic_inc(&vcc->stats->rx_drop);
37393+ atomic_inc_unchecked(&vcc->stats->rx_drop);
37394 } else {
37395 /* Copy the small buffer to the huge buffer */
37396 sb = (struct sk_buff *)iov->iov_base;
37397@@ -2327,7 +2327,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37398 #endif /* NS_USE_DESTRUCTORS */
37399 __net_timestamp(hb);
37400 vcc->push(vcc, hb);
37401- atomic_inc(&vcc->stats->rx);
37402+ atomic_inc_unchecked(&vcc->stats->rx);
37403 }
37404 }
37405
37406diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
37407index 21b0bc6..b5f40ba 100644
37408--- a/drivers/atm/solos-pci.c
37409+++ b/drivers/atm/solos-pci.c
37410@@ -838,7 +838,7 @@ static void solos_bh(unsigned long card_arg)
37411 }
37412 atm_charge(vcc, skb->truesize);
37413 vcc->push(vcc, skb);
37414- atomic_inc(&vcc->stats->rx);
37415+ atomic_inc_unchecked(&vcc->stats->rx);
37416 break;
37417
37418 case PKT_STATUS:
37419@@ -1116,7 +1116,7 @@ static uint32_t fpga_tx(struct solos_card *card)
37420 vcc = SKB_CB(oldskb)->vcc;
37421
37422 if (vcc) {
37423- atomic_inc(&vcc->stats->tx);
37424+ atomic_inc_unchecked(&vcc->stats->tx);
37425 solos_pop(vcc, oldskb);
37426 } else {
37427 dev_kfree_skb_irq(oldskb);
37428diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
37429index 0215934..ce9f5b1 100644
37430--- a/drivers/atm/suni.c
37431+++ b/drivers/atm/suni.c
37432@@ -49,8 +49,8 @@ static DEFINE_SPINLOCK(sunis_lock);
37433
37434
37435 #define ADD_LIMITED(s,v) \
37436- atomic_add((v),&stats->s); \
37437- if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
37438+ atomic_add_unchecked((v),&stats->s); \
37439+ if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
37440
37441
37442 static void suni_hz(unsigned long from_timer)
37443diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
37444index 5120a96..e2572bd 100644
37445--- a/drivers/atm/uPD98402.c
37446+++ b/drivers/atm/uPD98402.c
37447@@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
37448 struct sonet_stats tmp;
37449 int error = 0;
37450
37451- atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
37452+ atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
37453 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
37454 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
37455 if (zero && !error) {
37456@@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
37457
37458
37459 #define ADD_LIMITED(s,v) \
37460- { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
37461- if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
37462- atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
37463+ { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
37464+ if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
37465+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
37466
37467
37468 static void stat_event(struct atm_dev *dev)
37469@@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
37470 if (reason & uPD98402_INT_PFM) stat_event(dev);
37471 if (reason & uPD98402_INT_PCO) {
37472 (void) GET(PCOCR); /* clear interrupt cause */
37473- atomic_add(GET(HECCT),
37474+ atomic_add_unchecked(GET(HECCT),
37475 &PRIV(dev)->sonet_stats.uncorr_hcs);
37476 }
37477 if ((reason & uPD98402_INT_RFO) &&
37478@@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
37479 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
37480 uPD98402_INT_LOS),PIMR); /* enable them */
37481 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
37482- atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
37483- atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
37484- atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
37485+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
37486+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
37487+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
37488 return 0;
37489 }
37490
37491diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
37492index 969c3c2..9b72956 100644
37493--- a/drivers/atm/zatm.c
37494+++ b/drivers/atm/zatm.c
37495@@ -459,7 +459,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
37496 }
37497 if (!size) {
37498 dev_kfree_skb_irq(skb);
37499- if (vcc) atomic_inc(&vcc->stats->rx_err);
37500+ if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
37501 continue;
37502 }
37503 if (!atm_charge(vcc,skb->truesize)) {
37504@@ -469,7 +469,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
37505 skb->len = size;
37506 ATM_SKB(skb)->vcc = vcc;
37507 vcc->push(vcc,skb);
37508- atomic_inc(&vcc->stats->rx);
37509+ atomic_inc_unchecked(&vcc->stats->rx);
37510 }
37511 zout(pos & 0xffff,MTA(mbx));
37512 #if 0 /* probably a stupid idea */
37513@@ -733,7 +733,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
37514 skb_queue_head(&zatm_vcc->backlog,skb);
37515 break;
37516 }
37517- atomic_inc(&vcc->stats->tx);
37518+ atomic_inc_unchecked(&vcc->stats->tx);
37519 wake_up(&zatm_vcc->tx_wait);
37520 }
37521
37522diff --git a/drivers/base/bus.c b/drivers/base/bus.c
37523index 876bae5..8978785 100644
37524--- a/drivers/base/bus.c
37525+++ b/drivers/base/bus.c
37526@@ -1126,7 +1126,7 @@ int subsys_interface_register(struct subsys_interface *sif)
37527 return -EINVAL;
37528
37529 mutex_lock(&subsys->p->mutex);
37530- list_add_tail(&sif->node, &subsys->p->interfaces);
37531+ pax_list_add_tail((struct list_head *)&sif->node, &subsys->p->interfaces);
37532 if (sif->add_dev) {
37533 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
37534 while ((dev = subsys_dev_iter_next(&iter)))
37535@@ -1151,7 +1151,7 @@ void subsys_interface_unregister(struct subsys_interface *sif)
37536 subsys = sif->subsys;
37537
37538 mutex_lock(&subsys->p->mutex);
37539- list_del_init(&sif->node);
37540+ pax_list_del_init((struct list_head *)&sif->node);
37541 if (sif->remove_dev) {
37542 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
37543 while ((dev = subsys_dev_iter_next(&iter)))
37544diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
37545index 25798db..15f130e 100644
37546--- a/drivers/base/devtmpfs.c
37547+++ b/drivers/base/devtmpfs.c
37548@@ -354,7 +354,7 @@ int devtmpfs_mount(const char *mntdir)
37549 if (!thread)
37550 return 0;
37551
37552- err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
37553+ err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
37554 if (err)
37555 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
37556 else
37557@@ -380,11 +380,11 @@ static int devtmpfsd(void *p)
37558 *err = sys_unshare(CLONE_NEWNS);
37559 if (*err)
37560 goto out;
37561- *err = sys_mount("devtmpfs", "/", "devtmpfs", MS_SILENT, options);
37562+ *err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)"/", (char __force_user *)"devtmpfs", MS_SILENT, (char __force_user *)options);
37563 if (*err)
37564 goto out;
37565- sys_chdir("/.."); /* will traverse into overmounted root */
37566- sys_chroot(".");
37567+ sys_chdir((char __force_user *)"/.."); /* will traverse into overmounted root */
37568+ sys_chroot((char __force_user *)".");
37569 complete(&setup_done);
37570 while (1) {
37571 spin_lock(&req_lock);
37572diff --git a/drivers/base/node.c b/drivers/base/node.c
37573index 472168c..4af587e 100644
37574--- a/drivers/base/node.c
37575+++ b/drivers/base/node.c
37576@@ -620,7 +620,7 @@ static ssize_t print_nodes_state(enum node_states state, char *buf)
37577 struct node_attr {
37578 struct device_attribute attr;
37579 enum node_states state;
37580-};
37581+} __do_const;
37582
37583 static ssize_t show_node_state(struct device *dev,
37584 struct device_attribute *attr, char *buf)
37585diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c
37586index fb83d4a..e1797b3 100644
37587--- a/drivers/base/power/domain.c
37588+++ b/drivers/base/power/domain.c
37589@@ -1725,7 +1725,7 @@ int pm_genpd_attach_cpuidle(struct generic_pm_domain *genpd, int state)
37590 {
37591 struct cpuidle_driver *cpuidle_drv;
37592 struct gpd_cpuidle_data *cpuidle_data;
37593- struct cpuidle_state *idle_state;
37594+ cpuidle_state_no_const *idle_state;
37595 int ret = 0;
37596
37597 if (IS_ERR_OR_NULL(genpd) || state < 0)
37598@@ -1793,7 +1793,7 @@ int pm_genpd_name_attach_cpuidle(const char *name, int state)
37599 int pm_genpd_detach_cpuidle(struct generic_pm_domain *genpd)
37600 {
37601 struct gpd_cpuidle_data *cpuidle_data;
37602- struct cpuidle_state *idle_state;
37603+ cpuidle_state_no_const *idle_state;
37604 int ret = 0;
37605
37606 if (IS_ERR_OR_NULL(genpd))
37607@@ -2215,7 +2215,9 @@ int genpd_dev_pm_attach(struct device *dev)
37608 return ret;
37609 }
37610
37611- dev->pm_domain->detach = genpd_dev_pm_detach;
37612+ pax_open_kernel();
37613+ *(void **)&dev->pm_domain->detach = genpd_dev_pm_detach;
37614+ pax_close_kernel();
37615
37616 return 0;
37617 }
37618diff --git a/drivers/base/power/sysfs.c b/drivers/base/power/sysfs.c
37619index a9d26ed..74b8405 100644
37620--- a/drivers/base/power/sysfs.c
37621+++ b/drivers/base/power/sysfs.c
37622@@ -182,7 +182,7 @@ static ssize_t rtpm_status_show(struct device *dev,
37623 return -EIO;
37624 }
37625 }
37626- return sprintf(buf, p);
37627+ return sprintf(buf, "%s", p);
37628 }
37629
37630 static DEVICE_ATTR(runtime_status, 0444, rtpm_status_show, NULL);
37631diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
37632index c2744b3..08fac19 100644
37633--- a/drivers/base/power/wakeup.c
37634+++ b/drivers/base/power/wakeup.c
37635@@ -32,14 +32,14 @@ static bool pm_abort_suspend __read_mostly;
37636 * They need to be modified together atomically, so it's better to use one
37637 * atomic variable to hold them both.
37638 */
37639-static atomic_t combined_event_count = ATOMIC_INIT(0);
37640+static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
37641
37642 #define IN_PROGRESS_BITS (sizeof(int) * 4)
37643 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
37644
37645 static void split_counters(unsigned int *cnt, unsigned int *inpr)
37646 {
37647- unsigned int comb = atomic_read(&combined_event_count);
37648+ unsigned int comb = atomic_read_unchecked(&combined_event_count);
37649
37650 *cnt = (comb >> IN_PROGRESS_BITS);
37651 *inpr = comb & MAX_IN_PROGRESS;
37652@@ -404,7 +404,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
37653 ws->start_prevent_time = ws->last_time;
37654
37655 /* Increment the counter of events in progress. */
37656- cec = atomic_inc_return(&combined_event_count);
37657+ cec = atomic_inc_return_unchecked(&combined_event_count);
37658
37659 trace_wakeup_source_activate(ws->name, cec);
37660 }
37661@@ -530,7 +530,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
37662 * Increment the counter of registered wakeup events and decrement the
37663 * couter of wakeup events in progress simultaneously.
37664 */
37665- cec = atomic_add_return(MAX_IN_PROGRESS, &combined_event_count);
37666+ cec = atomic_add_return_unchecked(MAX_IN_PROGRESS, &combined_event_count);
37667 trace_wakeup_source_deactivate(ws->name, cec);
37668
37669 split_counters(&cnt, &inpr);
37670diff --git a/drivers/base/syscore.c b/drivers/base/syscore.c
37671index 8d98a32..61d3165 100644
37672--- a/drivers/base/syscore.c
37673+++ b/drivers/base/syscore.c
37674@@ -22,7 +22,7 @@ static DEFINE_MUTEX(syscore_ops_lock);
37675 void register_syscore_ops(struct syscore_ops *ops)
37676 {
37677 mutex_lock(&syscore_ops_lock);
37678- list_add_tail(&ops->node, &syscore_ops_list);
37679+ pax_list_add_tail((struct list_head *)&ops->node, &syscore_ops_list);
37680 mutex_unlock(&syscore_ops_lock);
37681 }
37682 EXPORT_SYMBOL_GPL(register_syscore_ops);
37683@@ -34,7 +34,7 @@ EXPORT_SYMBOL_GPL(register_syscore_ops);
37684 void unregister_syscore_ops(struct syscore_ops *ops)
37685 {
37686 mutex_lock(&syscore_ops_lock);
37687- list_del(&ops->node);
37688+ pax_list_del((struct list_head *)&ops->node);
37689 mutex_unlock(&syscore_ops_lock);
37690 }
37691 EXPORT_SYMBOL_GPL(unregister_syscore_ops);
37692diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
37693index ff20f19..018f1da 100644
37694--- a/drivers/block/cciss.c
37695+++ b/drivers/block/cciss.c
37696@@ -3008,7 +3008,7 @@ static void start_io(ctlr_info_t *h)
37697 while (!list_empty(&h->reqQ)) {
37698 c = list_entry(h->reqQ.next, CommandList_struct, list);
37699 /* can't do anything if fifo is full */
37700- if ((h->access.fifo_full(h))) {
37701+ if ((h->access->fifo_full(h))) {
37702 dev_warn(&h->pdev->dev, "fifo full\n");
37703 break;
37704 }
37705@@ -3018,7 +3018,7 @@ static void start_io(ctlr_info_t *h)
37706 h->Qdepth--;
37707
37708 /* Tell the controller execute command */
37709- h->access.submit_command(h, c);
37710+ h->access->submit_command(h, c);
37711
37712 /* Put job onto the completed Q */
37713 addQ(&h->cmpQ, c);
37714@@ -3444,17 +3444,17 @@ startio:
37715
37716 static inline unsigned long get_next_completion(ctlr_info_t *h)
37717 {
37718- return h->access.command_completed(h);
37719+ return h->access->command_completed(h);
37720 }
37721
37722 static inline int interrupt_pending(ctlr_info_t *h)
37723 {
37724- return h->access.intr_pending(h);
37725+ return h->access->intr_pending(h);
37726 }
37727
37728 static inline long interrupt_not_for_us(ctlr_info_t *h)
37729 {
37730- return ((h->access.intr_pending(h) == 0) ||
37731+ return ((h->access->intr_pending(h) == 0) ||
37732 (h->interrupts_enabled == 0));
37733 }
37734
37735@@ -3487,7 +3487,7 @@ static inline u32 next_command(ctlr_info_t *h)
37736 u32 a;
37737
37738 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
37739- return h->access.command_completed(h);
37740+ return h->access->command_completed(h);
37741
37742 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
37743 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
37744@@ -4044,7 +4044,7 @@ static void cciss_put_controller_into_performant_mode(ctlr_info_t *h)
37745 trans_support & CFGTBL_Trans_use_short_tags);
37746
37747 /* Change the access methods to the performant access methods */
37748- h->access = SA5_performant_access;
37749+ h->access = &SA5_performant_access;
37750 h->transMethod = CFGTBL_Trans_Performant;
37751
37752 return;
37753@@ -4318,7 +4318,7 @@ static int cciss_pci_init(ctlr_info_t *h)
37754 if (prod_index < 0)
37755 return -ENODEV;
37756 h->product_name = products[prod_index].product_name;
37757- h->access = *(products[prod_index].access);
37758+ h->access = products[prod_index].access;
37759
37760 if (cciss_board_disabled(h)) {
37761 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
37762@@ -5050,7 +5050,7 @@ reinit_after_soft_reset:
37763 }
37764
37765 /* make sure the board interrupts are off */
37766- h->access.set_intr_mask(h, CCISS_INTR_OFF);
37767+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
37768 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
37769 if (rc)
37770 goto clean2;
37771@@ -5100,7 +5100,7 @@ reinit_after_soft_reset:
37772 * fake ones to scoop up any residual completions.
37773 */
37774 spin_lock_irqsave(&h->lock, flags);
37775- h->access.set_intr_mask(h, CCISS_INTR_OFF);
37776+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
37777 spin_unlock_irqrestore(&h->lock, flags);
37778 free_irq(h->intr[h->intr_mode], h);
37779 rc = cciss_request_irq(h, cciss_msix_discard_completions,
37780@@ -5120,9 +5120,9 @@ reinit_after_soft_reset:
37781 dev_info(&h->pdev->dev, "Board READY.\n");
37782 dev_info(&h->pdev->dev,
37783 "Waiting for stale completions to drain.\n");
37784- h->access.set_intr_mask(h, CCISS_INTR_ON);
37785+ h->access->set_intr_mask(h, CCISS_INTR_ON);
37786 msleep(10000);
37787- h->access.set_intr_mask(h, CCISS_INTR_OFF);
37788+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
37789
37790 rc = controller_reset_failed(h->cfgtable);
37791 if (rc)
37792@@ -5145,7 +5145,7 @@ reinit_after_soft_reset:
37793 cciss_scsi_setup(h);
37794
37795 /* Turn the interrupts on so we can service requests */
37796- h->access.set_intr_mask(h, CCISS_INTR_ON);
37797+ h->access->set_intr_mask(h, CCISS_INTR_ON);
37798
37799 /* Get the firmware version */
37800 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
37801@@ -5217,7 +5217,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
37802 kfree(flush_buf);
37803 if (return_code != IO_OK)
37804 dev_warn(&h->pdev->dev, "Error flushing cache\n");
37805- h->access.set_intr_mask(h, CCISS_INTR_OFF);
37806+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
37807 free_irq(h->intr[h->intr_mode], h);
37808 }
37809
37810diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
37811index 7fda30e..2f27946 100644
37812--- a/drivers/block/cciss.h
37813+++ b/drivers/block/cciss.h
37814@@ -101,7 +101,7 @@ struct ctlr_info
37815 /* information about each logical volume */
37816 drive_info_struct *drv[CISS_MAX_LUN];
37817
37818- struct access_method access;
37819+ struct access_method *access;
37820
37821 /* queue and queue Info */
37822 struct list_head reqQ;
37823@@ -402,27 +402,27 @@ static bool SA5_performant_intr_pending(ctlr_info_t *h)
37824 }
37825
37826 static struct access_method SA5_access = {
37827- SA5_submit_command,
37828- SA5_intr_mask,
37829- SA5_fifo_full,
37830- SA5_intr_pending,
37831- SA5_completed,
37832+ .submit_command = SA5_submit_command,
37833+ .set_intr_mask = SA5_intr_mask,
37834+ .fifo_full = SA5_fifo_full,
37835+ .intr_pending = SA5_intr_pending,
37836+ .command_completed = SA5_completed,
37837 };
37838
37839 static struct access_method SA5B_access = {
37840- SA5_submit_command,
37841- SA5B_intr_mask,
37842- SA5_fifo_full,
37843- SA5B_intr_pending,
37844- SA5_completed,
37845+ .submit_command = SA5_submit_command,
37846+ .set_intr_mask = SA5B_intr_mask,
37847+ .fifo_full = SA5_fifo_full,
37848+ .intr_pending = SA5B_intr_pending,
37849+ .command_completed = SA5_completed,
37850 };
37851
37852 static struct access_method SA5_performant_access = {
37853- SA5_submit_command,
37854- SA5_performant_intr_mask,
37855- SA5_fifo_full,
37856- SA5_performant_intr_pending,
37857- SA5_performant_completed,
37858+ .submit_command = SA5_submit_command,
37859+ .set_intr_mask = SA5_performant_intr_mask,
37860+ .fifo_full = SA5_fifo_full,
37861+ .intr_pending = SA5_performant_intr_pending,
37862+ .command_completed = SA5_performant_completed,
37863 };
37864
37865 struct board_type {
37866diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
37867index 2b94403..fd6ad1f 100644
37868--- a/drivers/block/cpqarray.c
37869+++ b/drivers/block/cpqarray.c
37870@@ -404,7 +404,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
37871 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
37872 goto Enomem4;
37873 }
37874- hba[i]->access.set_intr_mask(hba[i], 0);
37875+ hba[i]->access->set_intr_mask(hba[i], 0);
37876 if (request_irq(hba[i]->intr, do_ida_intr,
37877 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
37878 {
37879@@ -459,7 +459,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
37880 add_timer(&hba[i]->timer);
37881
37882 /* Enable IRQ now that spinlock and rate limit timer are set up */
37883- hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
37884+ hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
37885
37886 for(j=0; j<NWD; j++) {
37887 struct gendisk *disk = ida_gendisk[i][j];
37888@@ -694,7 +694,7 @@ DBGINFO(
37889 for(i=0; i<NR_PRODUCTS; i++) {
37890 if (board_id == products[i].board_id) {
37891 c->product_name = products[i].product_name;
37892- c->access = *(products[i].access);
37893+ c->access = products[i].access;
37894 break;
37895 }
37896 }
37897@@ -792,7 +792,7 @@ static int cpqarray_eisa_detect(void)
37898 hba[ctlr]->intr = intr;
37899 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
37900 hba[ctlr]->product_name = products[j].product_name;
37901- hba[ctlr]->access = *(products[j].access);
37902+ hba[ctlr]->access = products[j].access;
37903 hba[ctlr]->ctlr = ctlr;
37904 hba[ctlr]->board_id = board_id;
37905 hba[ctlr]->pci_dev = NULL; /* not PCI */
37906@@ -978,7 +978,7 @@ static void start_io(ctlr_info_t *h)
37907
37908 while((c = h->reqQ) != NULL) {
37909 /* Can't do anything if we're busy */
37910- if (h->access.fifo_full(h) == 0)
37911+ if (h->access->fifo_full(h) == 0)
37912 return;
37913
37914 /* Get the first entry from the request Q */
37915@@ -986,7 +986,7 @@ static void start_io(ctlr_info_t *h)
37916 h->Qdepth--;
37917
37918 /* Tell the controller to do our bidding */
37919- h->access.submit_command(h, c);
37920+ h->access->submit_command(h, c);
37921
37922 /* Get onto the completion Q */
37923 addQ(&h->cmpQ, c);
37924@@ -1048,7 +1048,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
37925 unsigned long flags;
37926 __u32 a,a1;
37927
37928- istat = h->access.intr_pending(h);
37929+ istat = h->access->intr_pending(h);
37930 /* Is this interrupt for us? */
37931 if (istat == 0)
37932 return IRQ_NONE;
37933@@ -1059,7 +1059,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
37934 */
37935 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
37936 if (istat & FIFO_NOT_EMPTY) {
37937- while((a = h->access.command_completed(h))) {
37938+ while((a = h->access->command_completed(h))) {
37939 a1 = a; a &= ~3;
37940 if ((c = h->cmpQ) == NULL)
37941 {
37942@@ -1448,11 +1448,11 @@ static int sendcmd(
37943 /*
37944 * Disable interrupt
37945 */
37946- info_p->access.set_intr_mask(info_p, 0);
37947+ info_p->access->set_intr_mask(info_p, 0);
37948 /* Make sure there is room in the command FIFO */
37949 /* Actually it should be completely empty at this time. */
37950 for (i = 200000; i > 0; i--) {
37951- temp = info_p->access.fifo_full(info_p);
37952+ temp = info_p->access->fifo_full(info_p);
37953 if (temp != 0) {
37954 break;
37955 }
37956@@ -1465,7 +1465,7 @@ DBG(
37957 /*
37958 * Send the cmd
37959 */
37960- info_p->access.submit_command(info_p, c);
37961+ info_p->access->submit_command(info_p, c);
37962 complete = pollcomplete(ctlr);
37963
37964 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
37965@@ -1548,9 +1548,9 @@ static int revalidate_allvol(ctlr_info_t *host)
37966 * we check the new geometry. Then turn interrupts back on when
37967 * we're done.
37968 */
37969- host->access.set_intr_mask(host, 0);
37970+ host->access->set_intr_mask(host, 0);
37971 getgeometry(ctlr);
37972- host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
37973+ host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
37974
37975 for(i=0; i<NWD; i++) {
37976 struct gendisk *disk = ida_gendisk[ctlr][i];
37977@@ -1590,7 +1590,7 @@ static int pollcomplete(int ctlr)
37978 /* Wait (up to 2 seconds) for a command to complete */
37979
37980 for (i = 200000; i > 0; i--) {
37981- done = hba[ctlr]->access.command_completed(hba[ctlr]);
37982+ done = hba[ctlr]->access->command_completed(hba[ctlr]);
37983 if (done == 0) {
37984 udelay(10); /* a short fixed delay */
37985 } else
37986diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
37987index be73e9d..7fbf140 100644
37988--- a/drivers/block/cpqarray.h
37989+++ b/drivers/block/cpqarray.h
37990@@ -99,7 +99,7 @@ struct ctlr_info {
37991 drv_info_t drv[NWD];
37992 struct proc_dir_entry *proc;
37993
37994- struct access_method access;
37995+ struct access_method *access;
37996
37997 cmdlist_t *reqQ;
37998 cmdlist_t *cmpQ;
37999diff --git a/drivers/block/drbd/drbd_bitmap.c b/drivers/block/drbd/drbd_bitmap.c
38000index 434c77d..6d3219a 100644
38001--- a/drivers/block/drbd/drbd_bitmap.c
38002+++ b/drivers/block/drbd/drbd_bitmap.c
38003@@ -1036,7 +1036,7 @@ static void bm_page_io_async(struct drbd_bm_aio_ctx *ctx, int page_nr) __must_ho
38004 submit_bio(rw, bio);
38005 /* this should not count as user activity and cause the
38006 * resync to throttle -- see drbd_rs_should_slow_down(). */
38007- atomic_add(len >> 9, &device->rs_sect_ev);
38008+ atomic_add_unchecked(len >> 9, &device->rs_sect_ev);
38009 }
38010 }
38011
38012diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
38013index 9b22f8f..f2932af 100644
38014--- a/drivers/block/drbd/drbd_int.h
38015+++ b/drivers/block/drbd/drbd_int.h
38016@@ -385,7 +385,7 @@ struct drbd_epoch {
38017 struct drbd_connection *connection;
38018 struct list_head list;
38019 unsigned int barrier_nr;
38020- atomic_t epoch_size; /* increased on every request added. */
38021+ atomic_unchecked_t epoch_size; /* increased on every request added. */
38022 atomic_t active; /* increased on every req. added, and dec on every finished. */
38023 unsigned long flags;
38024 };
38025@@ -946,7 +946,7 @@ struct drbd_device {
38026 unsigned int al_tr_number;
38027 int al_tr_cycle;
38028 wait_queue_head_t seq_wait;
38029- atomic_t packet_seq;
38030+ atomic_unchecked_t packet_seq;
38031 unsigned int peer_seq;
38032 spinlock_t peer_seq_lock;
38033 unsigned long comm_bm_set; /* communicated number of set bits. */
38034@@ -955,8 +955,8 @@ struct drbd_device {
38035 struct mutex own_state_mutex;
38036 struct mutex *state_mutex; /* either own_state_mutex or first_peer_device(device)->connection->cstate_mutex */
38037 char congestion_reason; /* Why we where congested... */
38038- atomic_t rs_sect_in; /* for incoming resync data rate, SyncTarget */
38039- atomic_t rs_sect_ev; /* for submitted resync data rate, both */
38040+ atomic_unchecked_t rs_sect_in; /* for incoming resync data rate, SyncTarget */
38041+ atomic_unchecked_t rs_sect_ev; /* for submitted resync data rate, both */
38042 int rs_last_sect_ev; /* counter to compare with */
38043 int rs_last_events; /* counter of read or write "events" (unit sectors)
38044 * on the lower level device when we last looked. */
38045@@ -1567,7 +1567,7 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
38046 char __user *uoptval;
38047 int err;
38048
38049- uoptval = (char __user __force *)optval;
38050+ uoptval = (char __force_user *)optval;
38051
38052 set_fs(KERNEL_DS);
38053 if (level == SOL_SOCKET)
38054diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
38055index 973c185..05d8b1a 100644
38056--- a/drivers/block/drbd/drbd_main.c
38057+++ b/drivers/block/drbd/drbd_main.c
38058@@ -1328,7 +1328,7 @@ static int _drbd_send_ack(struct drbd_peer_device *peer_device, enum drbd_packet
38059 p->sector = sector;
38060 p->block_id = block_id;
38061 p->blksize = blksize;
38062- p->seq_num = cpu_to_be32(atomic_inc_return(&peer_device->device->packet_seq));
38063+ p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&peer_device->device->packet_seq));
38064 return drbd_send_command(peer_device, sock, cmd, sizeof(*p), NULL, 0);
38065 }
38066
38067@@ -1634,7 +1634,7 @@ int drbd_send_dblock(struct drbd_peer_device *peer_device, struct drbd_request *
38068 return -EIO;
38069 p->sector = cpu_to_be64(req->i.sector);
38070 p->block_id = (unsigned long)req;
38071- p->seq_num = cpu_to_be32(atomic_inc_return(&device->packet_seq));
38072+ p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&device->packet_seq));
38073 dp_flags = bio_flags_to_wire(peer_device->connection, req->master_bio->bi_rw);
38074 if (device->state.conn >= C_SYNC_SOURCE &&
38075 device->state.conn <= C_PAUSED_SYNC_T)
38076@@ -1915,8 +1915,8 @@ void drbd_init_set_defaults(struct drbd_device *device)
38077 atomic_set(&device->unacked_cnt, 0);
38078 atomic_set(&device->local_cnt, 0);
38079 atomic_set(&device->pp_in_use_by_net, 0);
38080- atomic_set(&device->rs_sect_in, 0);
38081- atomic_set(&device->rs_sect_ev, 0);
38082+ atomic_set_unchecked(&device->rs_sect_in, 0);
38083+ atomic_set_unchecked(&device->rs_sect_ev, 0);
38084 atomic_set(&device->ap_in_flight, 0);
38085 atomic_set(&device->md_io.in_use, 0);
38086
38087@@ -2688,8 +2688,8 @@ void drbd_destroy_connection(struct kref *kref)
38088 struct drbd_connection *connection = container_of(kref, struct drbd_connection, kref);
38089 struct drbd_resource *resource = connection->resource;
38090
38091- if (atomic_read(&connection->current_epoch->epoch_size) != 0)
38092- drbd_err(connection, "epoch_size:%d\n", atomic_read(&connection->current_epoch->epoch_size));
38093+ if (atomic_read_unchecked(&connection->current_epoch->epoch_size) != 0)
38094+ drbd_err(connection, "epoch_size:%d\n", atomic_read_unchecked(&connection->current_epoch->epoch_size));
38095 kfree(connection->current_epoch);
38096
38097 idr_destroy(&connection->peer_devices);
38098diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
38099index 1cd47df..57c53c0 100644
38100--- a/drivers/block/drbd/drbd_nl.c
38101+++ b/drivers/block/drbd/drbd_nl.c
38102@@ -3645,13 +3645,13 @@ finish:
38103
38104 void drbd_bcast_event(struct drbd_device *device, const struct sib_info *sib)
38105 {
38106- static atomic_t drbd_genl_seq = ATOMIC_INIT(2); /* two. */
38107+ static atomic_unchecked_t drbd_genl_seq = ATOMIC_INIT(2); /* two. */
38108 struct sk_buff *msg;
38109 struct drbd_genlmsghdr *d_out;
38110 unsigned seq;
38111 int err = -ENOMEM;
38112
38113- seq = atomic_inc_return(&drbd_genl_seq);
38114+ seq = atomic_inc_return_unchecked(&drbd_genl_seq);
38115 msg = genlmsg_new(NLMSG_GOODSIZE, GFP_NOIO);
38116 if (!msg)
38117 goto failed;
38118diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
38119index 6960fb0..215d76b 100644
38120--- a/drivers/block/drbd/drbd_receiver.c
38121+++ b/drivers/block/drbd/drbd_receiver.c
38122@@ -870,7 +870,7 @@ int drbd_connected(struct drbd_peer_device *peer_device)
38123 struct drbd_device *device = peer_device->device;
38124 int err;
38125
38126- atomic_set(&device->packet_seq, 0);
38127+ atomic_set_unchecked(&device->packet_seq, 0);
38128 device->peer_seq = 0;
38129
38130 device->state_mutex = peer_device->connection->agreed_pro_version < 100 ?
38131@@ -1233,7 +1233,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_connection *connectio
38132 do {
38133 next_epoch = NULL;
38134
38135- epoch_size = atomic_read(&epoch->epoch_size);
38136+ epoch_size = atomic_read_unchecked(&epoch->epoch_size);
38137
38138 switch (ev & ~EV_CLEANUP) {
38139 case EV_PUT:
38140@@ -1273,7 +1273,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_connection *connectio
38141 rv = FE_DESTROYED;
38142 } else {
38143 epoch->flags = 0;
38144- atomic_set(&epoch->epoch_size, 0);
38145+ atomic_set_unchecked(&epoch->epoch_size, 0);
38146 /* atomic_set(&epoch->active, 0); is already zero */
38147 if (rv == FE_STILL_LIVE)
38148 rv = FE_RECYCLED;
38149@@ -1550,7 +1550,7 @@ static int receive_Barrier(struct drbd_connection *connection, struct packet_inf
38150 conn_wait_active_ee_empty(connection);
38151 drbd_flush(connection);
38152
38153- if (atomic_read(&connection->current_epoch->epoch_size)) {
38154+ if (atomic_read_unchecked(&connection->current_epoch->epoch_size)) {
38155 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
38156 if (epoch)
38157 break;
38158@@ -1564,11 +1564,11 @@ static int receive_Barrier(struct drbd_connection *connection, struct packet_inf
38159 }
38160
38161 epoch->flags = 0;
38162- atomic_set(&epoch->epoch_size, 0);
38163+ atomic_set_unchecked(&epoch->epoch_size, 0);
38164 atomic_set(&epoch->active, 0);
38165
38166 spin_lock(&connection->epoch_lock);
38167- if (atomic_read(&connection->current_epoch->epoch_size)) {
38168+ if (atomic_read_unchecked(&connection->current_epoch->epoch_size)) {
38169 list_add(&epoch->list, &connection->current_epoch->list);
38170 connection->current_epoch = epoch;
38171 connection->epochs++;
38172@@ -1802,7 +1802,7 @@ static int recv_resync_read(struct drbd_peer_device *peer_device, sector_t secto
38173 list_add_tail(&peer_req->w.list, &device->sync_ee);
38174 spin_unlock_irq(&device->resource->req_lock);
38175
38176- atomic_add(pi->size >> 9, &device->rs_sect_ev);
38177+ atomic_add_unchecked(pi->size >> 9, &device->rs_sect_ev);
38178 if (drbd_submit_peer_request(device, peer_req, WRITE, DRBD_FAULT_RS_WR) == 0)
38179 return 0;
38180
38181@@ -1900,7 +1900,7 @@ static int receive_RSDataReply(struct drbd_connection *connection, struct packet
38182 drbd_send_ack_dp(peer_device, P_NEG_ACK, p, pi->size);
38183 }
38184
38185- atomic_add(pi->size >> 9, &device->rs_sect_in);
38186+ atomic_add_unchecked(pi->size >> 9, &device->rs_sect_in);
38187
38188 return err;
38189 }
38190@@ -2290,7 +2290,7 @@ static int receive_Data(struct drbd_connection *connection, struct packet_info *
38191
38192 err = wait_for_and_update_peer_seq(peer_device, peer_seq);
38193 drbd_send_ack_dp(peer_device, P_NEG_ACK, p, pi->size);
38194- atomic_inc(&connection->current_epoch->epoch_size);
38195+ atomic_inc_unchecked(&connection->current_epoch->epoch_size);
38196 err2 = drbd_drain_block(peer_device, pi->size);
38197 if (!err)
38198 err = err2;
38199@@ -2334,7 +2334,7 @@ static int receive_Data(struct drbd_connection *connection, struct packet_info *
38200
38201 spin_lock(&connection->epoch_lock);
38202 peer_req->epoch = connection->current_epoch;
38203- atomic_inc(&peer_req->epoch->epoch_size);
38204+ atomic_inc_unchecked(&peer_req->epoch->epoch_size);
38205 atomic_inc(&peer_req->epoch->active);
38206 spin_unlock(&connection->epoch_lock);
38207
38208@@ -2479,7 +2479,7 @@ bool drbd_rs_c_min_rate_throttle(struct drbd_device *device)
38209
38210 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
38211 (int)part_stat_read(&disk->part0, sectors[1]) -
38212- atomic_read(&device->rs_sect_ev);
38213+ atomic_read_unchecked(&device->rs_sect_ev);
38214
38215 if (atomic_read(&device->ap_actlog_cnt)
38216 || !device->rs_last_events || curr_events - device->rs_last_events > 64) {
38217@@ -2618,7 +2618,7 @@ static int receive_DataRequest(struct drbd_connection *connection, struct packet
38218 device->use_csums = true;
38219 } else if (pi->cmd == P_OV_REPLY) {
38220 /* track progress, we may need to throttle */
38221- atomic_add(size >> 9, &device->rs_sect_in);
38222+ atomic_add_unchecked(size >> 9, &device->rs_sect_in);
38223 peer_req->w.cb = w_e_end_ov_reply;
38224 dec_rs_pending(device);
38225 /* drbd_rs_begin_io done when we sent this request,
38226@@ -2691,7 +2691,7 @@ static int receive_DataRequest(struct drbd_connection *connection, struct packet
38227 goto out_free_e;
38228
38229 submit_for_resync:
38230- atomic_add(size >> 9, &device->rs_sect_ev);
38231+ atomic_add_unchecked(size >> 9, &device->rs_sect_ev);
38232
38233 submit:
38234 update_receiver_timing_details(connection, drbd_submit_peer_request);
38235@@ -4564,7 +4564,7 @@ struct data_cmd {
38236 int expect_payload;
38237 size_t pkt_size;
38238 int (*fn)(struct drbd_connection *, struct packet_info *);
38239-};
38240+} __do_const;
38241
38242 static struct data_cmd drbd_cmd_handler[] = {
38243 [P_DATA] = { 1, sizeof(struct p_data), receive_Data },
38244@@ -4678,7 +4678,7 @@ static void conn_disconnect(struct drbd_connection *connection)
38245 if (!list_empty(&connection->current_epoch->list))
38246 drbd_err(connection, "ASSERTION FAILED: connection->current_epoch->list not empty\n");
38247 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
38248- atomic_set(&connection->current_epoch->epoch_size, 0);
38249+ atomic_set_unchecked(&connection->current_epoch->epoch_size, 0);
38250 connection->send.seen_any_write_yet = false;
38251
38252 drbd_info(connection, "Connection closed\n");
38253@@ -5182,7 +5182,7 @@ static int got_IsInSync(struct drbd_connection *connection, struct packet_info *
38254 put_ldev(device);
38255 }
38256 dec_rs_pending(device);
38257- atomic_add(blksize >> 9, &device->rs_sect_in);
38258+ atomic_add_unchecked(blksize >> 9, &device->rs_sect_in);
38259
38260 return 0;
38261 }
38262@@ -5470,7 +5470,7 @@ static int connection_finish_peer_reqs(struct drbd_connection *connection)
38263 struct asender_cmd {
38264 size_t pkt_size;
38265 int (*fn)(struct drbd_connection *connection, struct packet_info *);
38266-};
38267+} __do_const;
38268
38269 static struct asender_cmd asender_tbl[] = {
38270 [P_PING] = { 0, got_Ping },
38271diff --git a/drivers/block/drbd/drbd_worker.c b/drivers/block/drbd/drbd_worker.c
38272index d2d1f97..6a1188f 100644
38273--- a/drivers/block/drbd/drbd_worker.c
38274+++ b/drivers/block/drbd/drbd_worker.c
38275@@ -408,7 +408,7 @@ static int read_for_csum(struct drbd_peer_device *peer_device, sector_t sector,
38276 list_add_tail(&peer_req->w.list, &device->read_ee);
38277 spin_unlock_irq(&device->resource->req_lock);
38278
38279- atomic_add(size >> 9, &device->rs_sect_ev);
38280+ atomic_add_unchecked(size >> 9, &device->rs_sect_ev);
38281 if (drbd_submit_peer_request(device, peer_req, READ, DRBD_FAULT_RS_RD) == 0)
38282 return 0;
38283
38284@@ -553,7 +553,7 @@ static int drbd_rs_number_requests(struct drbd_device *device)
38285 unsigned int sect_in; /* Number of sectors that came in since the last turn */
38286 int number, mxb;
38287
38288- sect_in = atomic_xchg(&device->rs_sect_in, 0);
38289+ sect_in = atomic_xchg_unchecked(&device->rs_sect_in, 0);
38290 device->rs_in_flight -= sect_in;
38291
38292 rcu_read_lock();
38293@@ -1594,8 +1594,8 @@ void drbd_rs_controller_reset(struct drbd_device *device)
38294 {
38295 struct fifo_buffer *plan;
38296
38297- atomic_set(&device->rs_sect_in, 0);
38298- atomic_set(&device->rs_sect_ev, 0);
38299+ atomic_set_unchecked(&device->rs_sect_in, 0);
38300+ atomic_set_unchecked(&device->rs_sect_ev, 0);
38301 device->rs_in_flight = 0;
38302
38303 /* Updating the RCU protected object in place is necessary since
38304diff --git a/drivers/block/loop.c b/drivers/block/loop.c
38305index 6cb1beb..bf490f7 100644
38306--- a/drivers/block/loop.c
38307+++ b/drivers/block/loop.c
38308@@ -232,7 +232,7 @@ static int __do_lo_send_write(struct file *file,
38309
38310 file_start_write(file);
38311 set_fs(get_ds());
38312- bw = file->f_op->write(file, buf, len, &pos);
38313+ bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
38314 set_fs(old_fs);
38315 file_end_write(file);
38316 if (likely(bw == len))
38317diff --git a/drivers/block/nvme-core.c b/drivers/block/nvme-core.c
38318index e2bb8af..44b8aef 100644
38319--- a/drivers/block/nvme-core.c
38320+++ b/drivers/block/nvme-core.c
38321@@ -73,7 +73,6 @@ static LIST_HEAD(dev_list);
38322 static struct task_struct *nvme_thread;
38323 static struct workqueue_struct *nvme_workq;
38324 static wait_queue_head_t nvme_kthread_wait;
38325-static struct notifier_block nvme_nb;
38326
38327 static void nvme_reset_failed_dev(struct work_struct *ws);
38328
38329@@ -2926,6 +2925,10 @@ static struct pci_driver nvme_driver = {
38330 .err_handler = &nvme_err_handler,
38331 };
38332
38333+static struct notifier_block nvme_nb = {
38334+ .notifier_call = &nvme_cpu_notify,
38335+};
38336+
38337 static int __init nvme_init(void)
38338 {
38339 int result;
38340@@ -2942,7 +2945,6 @@ static int __init nvme_init(void)
38341 else if (result > 0)
38342 nvme_major = result;
38343
38344- nvme_nb.notifier_call = &nvme_cpu_notify;
38345 result = register_hotcpu_notifier(&nvme_nb);
38346 if (result)
38347 goto unregister_blkdev;
38348diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c
38349index 09e628da..7607aaa 100644
38350--- a/drivers/block/pktcdvd.c
38351+++ b/drivers/block/pktcdvd.c
38352@@ -108,7 +108,7 @@ static int pkt_seq_show(struct seq_file *m, void *p);
38353
38354 static sector_t get_zone(sector_t sector, struct pktcdvd_device *pd)
38355 {
38356- return (sector + pd->offset) & ~(sector_t)(pd->settings.size - 1);
38357+ return (sector + pd->offset) & ~(sector_t)(pd->settings.size - 1UL);
38358 }
38359
38360 /*
38361@@ -1890,7 +1890,7 @@ static noinline_for_stack int pkt_probe_settings(struct pktcdvd_device *pd)
38362 return -EROFS;
38363 }
38364 pd->settings.fp = ti.fp;
38365- pd->offset = (be32_to_cpu(ti.track_start) << 2) & (pd->settings.size - 1);
38366+ pd->offset = (be32_to_cpu(ti.track_start) << 2) & (pd->settings.size - 1UL);
38367
38368 if (ti.nwa_v) {
38369 pd->nwa = be32_to_cpu(ti.next_writable);
38370diff --git a/drivers/block/smart1,2.h b/drivers/block/smart1,2.h
38371index e5565fb..71be10b4 100644
38372--- a/drivers/block/smart1,2.h
38373+++ b/drivers/block/smart1,2.h
38374@@ -108,11 +108,11 @@ static unsigned long smart4_intr_pending(ctlr_info_t *h)
38375 }
38376
38377 static struct access_method smart4_access = {
38378- smart4_submit_command,
38379- smart4_intr_mask,
38380- smart4_fifo_full,
38381- smart4_intr_pending,
38382- smart4_completed,
38383+ .submit_command = smart4_submit_command,
38384+ .set_intr_mask = smart4_intr_mask,
38385+ .fifo_full = smart4_fifo_full,
38386+ .intr_pending = smart4_intr_pending,
38387+ .command_completed = smart4_completed,
38388 };
38389
38390 /*
38391@@ -144,11 +144,11 @@ static unsigned long smart2_intr_pending(ctlr_info_t *h)
38392 }
38393
38394 static struct access_method smart2_access = {
38395- smart2_submit_command,
38396- smart2_intr_mask,
38397- smart2_fifo_full,
38398- smart2_intr_pending,
38399- smart2_completed,
38400+ .submit_command = smart2_submit_command,
38401+ .set_intr_mask = smart2_intr_mask,
38402+ .fifo_full = smart2_fifo_full,
38403+ .intr_pending = smart2_intr_pending,
38404+ .command_completed = smart2_completed,
38405 };
38406
38407 /*
38408@@ -180,11 +180,11 @@ static unsigned long smart2e_intr_pending(ctlr_info_t *h)
38409 }
38410
38411 static struct access_method smart2e_access = {
38412- smart2e_submit_command,
38413- smart2e_intr_mask,
38414- smart2e_fifo_full,
38415- smart2e_intr_pending,
38416- smart2e_completed,
38417+ .submit_command = smart2e_submit_command,
38418+ .set_intr_mask = smart2e_intr_mask,
38419+ .fifo_full = smart2e_fifo_full,
38420+ .intr_pending = smart2e_intr_pending,
38421+ .command_completed = smart2e_completed,
38422 };
38423
38424 /*
38425@@ -270,9 +270,9 @@ static unsigned long smart1_intr_pending(ctlr_info_t *h)
38426 }
38427
38428 static struct access_method smart1_access = {
38429- smart1_submit_command,
38430- smart1_intr_mask,
38431- smart1_fifo_full,
38432- smart1_intr_pending,
38433- smart1_completed,
38434+ .submit_command = smart1_submit_command,
38435+ .set_intr_mask = smart1_intr_mask,
38436+ .fifo_full = smart1_fifo_full,
38437+ .intr_pending = smart1_intr_pending,
38438+ .command_completed = smart1_completed,
38439 };
38440diff --git a/drivers/bluetooth/btwilink.c b/drivers/bluetooth/btwilink.c
38441index f038dba..bb74c08 100644
38442--- a/drivers/bluetooth/btwilink.c
38443+++ b/drivers/bluetooth/btwilink.c
38444@@ -288,7 +288,7 @@ static int ti_st_send_frame(struct hci_dev *hdev, struct sk_buff *skb)
38445
38446 static int bt_ti_probe(struct platform_device *pdev)
38447 {
38448- static struct ti_st *hst;
38449+ struct ti_st *hst;
38450 struct hci_dev *hdev;
38451 int err;
38452
38453diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c
38454index 5d28a45..a538f90 100644
38455--- a/drivers/cdrom/cdrom.c
38456+++ b/drivers/cdrom/cdrom.c
38457@@ -610,7 +610,6 @@ int register_cdrom(struct cdrom_device_info *cdi)
38458 ENSURE(reset, CDC_RESET);
38459 ENSURE(generic_packet, CDC_GENERIC_PACKET);
38460 cdi->mc_flags = 0;
38461- cdo->n_minors = 0;
38462 cdi->options = CDO_USE_FFLAGS;
38463
38464 if (autoclose == 1 && CDROM_CAN(CDC_CLOSE_TRAY))
38465@@ -630,8 +629,11 @@ int register_cdrom(struct cdrom_device_info *cdi)
38466 else
38467 cdi->cdda_method = CDDA_OLD;
38468
38469- if (!cdo->generic_packet)
38470- cdo->generic_packet = cdrom_dummy_generic_packet;
38471+ if (!cdo->generic_packet) {
38472+ pax_open_kernel();
38473+ *(void **)&cdo->generic_packet = cdrom_dummy_generic_packet;
38474+ pax_close_kernel();
38475+ }
38476
38477 cd_dbg(CD_REG_UNREG, "drive \"/dev/%s\" registered\n", cdi->name);
38478 mutex_lock(&cdrom_mutex);
38479@@ -652,7 +654,6 @@ void unregister_cdrom(struct cdrom_device_info *cdi)
38480 if (cdi->exit)
38481 cdi->exit(cdi);
38482
38483- cdi->ops->n_minors--;
38484 cd_dbg(CD_REG_UNREG, "drive \"/dev/%s\" unregistered\n", cdi->name);
38485 }
38486
38487@@ -2126,7 +2127,7 @@ static int cdrom_read_cdda_old(struct cdrom_device_info *cdi, __u8 __user *ubuf,
38488 */
38489 nr = nframes;
38490 do {
38491- cgc.buffer = kmalloc(CD_FRAMESIZE_RAW * nr, GFP_KERNEL);
38492+ cgc.buffer = kzalloc(CD_FRAMESIZE_RAW * nr, GFP_KERNEL);
38493 if (cgc.buffer)
38494 break;
38495
38496@@ -3434,7 +3435,7 @@ static int cdrom_print_info(const char *header, int val, char *info,
38497 struct cdrom_device_info *cdi;
38498 int ret;
38499
38500- ret = scnprintf(info + *pos, max_size - *pos, header);
38501+ ret = scnprintf(info + *pos, max_size - *pos, "%s", header);
38502 if (!ret)
38503 return 1;
38504
38505diff --git a/drivers/cdrom/gdrom.c b/drivers/cdrom/gdrom.c
38506index 584bc31..e64a12c 100644
38507--- a/drivers/cdrom/gdrom.c
38508+++ b/drivers/cdrom/gdrom.c
38509@@ -491,7 +491,6 @@ static struct cdrom_device_ops gdrom_ops = {
38510 .audio_ioctl = gdrom_audio_ioctl,
38511 .capability = CDC_MULTI_SESSION | CDC_MEDIA_CHANGED |
38512 CDC_RESET | CDC_DRIVE_STATUS | CDC_CD_R,
38513- .n_minors = 1,
38514 };
38515
38516 static int gdrom_bdops_open(struct block_device *bdev, fmode_t mode)
38517diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
38518index efefd12..4f1d494 100644
38519--- a/drivers/char/Kconfig
38520+++ b/drivers/char/Kconfig
38521@@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
38522
38523 config DEVKMEM
38524 bool "/dev/kmem virtual device support"
38525- default y
38526+ default n
38527+ depends on !GRKERNSEC_KMEM
38528 help
38529 Say Y here if you want to support the /dev/kmem device. The
38530 /dev/kmem device is rarely used, but can be used for certain
38531@@ -577,6 +578,7 @@ config DEVPORT
38532 bool
38533 depends on !M68K
38534 depends on ISA || PCI
38535+ depends on !GRKERNSEC_KMEM
38536 default y
38537
38538 source "drivers/s390/char/Kconfig"
38539diff --git a/drivers/char/agp/compat_ioctl.c b/drivers/char/agp/compat_ioctl.c
38540index a48e05b..6bac831 100644
38541--- a/drivers/char/agp/compat_ioctl.c
38542+++ b/drivers/char/agp/compat_ioctl.c
38543@@ -108,7 +108,7 @@ static int compat_agpioc_reserve_wrap(struct agp_file_private *priv, void __user
38544 return -ENOMEM;
38545 }
38546
38547- if (copy_from_user(usegment, (void __user *) ureserve.seg_list,
38548+ if (copy_from_user(usegment, (void __force_user *) ureserve.seg_list,
38549 sizeof(*usegment) * ureserve.seg_count)) {
38550 kfree(usegment);
38551 kfree(ksegment);
38552diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
38553index 09f17eb..8531d2f 100644
38554--- a/drivers/char/agp/frontend.c
38555+++ b/drivers/char/agp/frontend.c
38556@@ -806,7 +806,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
38557 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
38558 return -EFAULT;
38559
38560- if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
38561+ if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
38562 return -EFAULT;
38563
38564 client = agp_find_client_by_pid(reserve.pid);
38565@@ -836,7 +836,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
38566 if (segment == NULL)
38567 return -ENOMEM;
38568
38569- if (copy_from_user(segment, (void __user *) reserve.seg_list,
38570+ if (copy_from_user(segment, (void __force_user *) reserve.seg_list,
38571 sizeof(struct agp_segment) * reserve.seg_count)) {
38572 kfree(segment);
38573 return -EFAULT;
38574diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
38575index 4f94375..413694e 100644
38576--- a/drivers/char/genrtc.c
38577+++ b/drivers/char/genrtc.c
38578@@ -273,6 +273,7 @@ static int gen_rtc_ioctl(struct file *file,
38579 switch (cmd) {
38580
38581 case RTC_PLL_GET:
38582+ memset(&pll, 0, sizeof(pll));
38583 if (get_rtc_pll(&pll))
38584 return -EINVAL;
38585 else
38586diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
38587index d5d4cd8..22d561d 100644
38588--- a/drivers/char/hpet.c
38589+++ b/drivers/char/hpet.c
38590@@ -575,7 +575,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
38591 }
38592
38593 static int
38594-hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
38595+hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
38596 struct hpet_info *info)
38597 {
38598 struct hpet_timer __iomem *timer;
38599diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
38600index f816211..89eadea 100644
38601--- a/drivers/char/ipmi/ipmi_msghandler.c
38602+++ b/drivers/char/ipmi/ipmi_msghandler.c
38603@@ -438,7 +438,7 @@ struct ipmi_smi {
38604 struct proc_dir_entry *proc_dir;
38605 char proc_dir_name[10];
38606
38607- atomic_t stats[IPMI_NUM_STATS];
38608+ atomic_unchecked_t stats[IPMI_NUM_STATS];
38609
38610 /*
38611 * run_to_completion duplicate of smb_info, smi_info
38612@@ -470,9 +470,9 @@ static LIST_HEAD(smi_watchers);
38613 static DEFINE_MUTEX(smi_watchers_mutex);
38614
38615 #define ipmi_inc_stat(intf, stat) \
38616- atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
38617+ atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
38618 #define ipmi_get_stat(intf, stat) \
38619- ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
38620+ ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
38621
38622 static int is_lan_addr(struct ipmi_addr *addr)
38623 {
38624@@ -2925,7 +2925,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
38625 INIT_LIST_HEAD(&intf->cmd_rcvrs);
38626 init_waitqueue_head(&intf->waitq);
38627 for (i = 0; i < IPMI_NUM_STATS; i++)
38628- atomic_set(&intf->stats[i], 0);
38629+ atomic_set_unchecked(&intf->stats[i], 0);
38630
38631 intf->proc_dir = NULL;
38632
38633diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
38634index 5c4e1f6..0ea58f9 100644
38635--- a/drivers/char/ipmi/ipmi_si_intf.c
38636+++ b/drivers/char/ipmi/ipmi_si_intf.c
38637@@ -285,7 +285,7 @@ struct smi_info {
38638 unsigned char slave_addr;
38639
38640 /* Counters and things for the proc filesystem. */
38641- atomic_t stats[SI_NUM_STATS];
38642+ atomic_unchecked_t stats[SI_NUM_STATS];
38643
38644 struct task_struct *thread;
38645
38646@@ -294,9 +294,9 @@ struct smi_info {
38647 };
38648
38649 #define smi_inc_stat(smi, stat) \
38650- atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
38651+ atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
38652 #define smi_get_stat(smi, stat) \
38653- ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
38654+ ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
38655
38656 #define SI_MAX_PARMS 4
38657
38658@@ -3377,7 +3377,7 @@ static int try_smi_init(struct smi_info *new_smi)
38659 atomic_set(&new_smi->req_events, 0);
38660 new_smi->run_to_completion = false;
38661 for (i = 0; i < SI_NUM_STATS; i++)
38662- atomic_set(&new_smi->stats[i], 0);
38663+ atomic_set_unchecked(&new_smi->stats[i], 0);
38664
38665 new_smi->interrupt_disabled = true;
38666 atomic_set(&new_smi->stop_operation, 0);
38667diff --git a/drivers/char/mem.c b/drivers/char/mem.c
38668index 524b707..29d07c1 100644
38669--- a/drivers/char/mem.c
38670+++ b/drivers/char/mem.c
38671@@ -18,6 +18,7 @@
38672 #include <linux/raw.h>
38673 #include <linux/tty.h>
38674 #include <linux/capability.h>
38675+#include <linux/security.h>
38676 #include <linux/ptrace.h>
38677 #include <linux/device.h>
38678 #include <linux/highmem.h>
38679@@ -36,6 +37,10 @@
38680
38681 #define DEVPORT_MINOR 4
38682
38683+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
38684+extern const struct file_operations grsec_fops;
38685+#endif
38686+
38687 static inline unsigned long size_inside_page(unsigned long start,
38688 unsigned long size)
38689 {
38690@@ -67,9 +72,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
38691
38692 while (cursor < to) {
38693 if (!devmem_is_allowed(pfn)) {
38694+#ifdef CONFIG_GRKERNSEC_KMEM
38695+ gr_handle_mem_readwrite(from, to);
38696+#else
38697 printk(KERN_INFO
38698 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
38699 current->comm, from, to);
38700+#endif
38701 return 0;
38702 }
38703 cursor += PAGE_SIZE;
38704@@ -77,6 +86,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
38705 }
38706 return 1;
38707 }
38708+#elif defined(CONFIG_GRKERNSEC_KMEM)
38709+static inline int range_is_allowed(unsigned long pfn, unsigned long size)
38710+{
38711+ return 0;
38712+}
38713 #else
38714 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
38715 {
38716@@ -122,6 +136,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,
38717
38718 while (count > 0) {
38719 unsigned long remaining;
38720+ char *temp;
38721
38722 sz = size_inside_page(p, count);
38723
38724@@ -137,7 +152,23 @@ static ssize_t read_mem(struct file *file, char __user *buf,
38725 if (!ptr)
38726 return -EFAULT;
38727
38728- remaining = copy_to_user(buf, ptr, sz);
38729+#ifdef CONFIG_PAX_USERCOPY
38730+ temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
38731+ if (!temp) {
38732+ unxlate_dev_mem_ptr(p, ptr);
38733+ return -ENOMEM;
38734+ }
38735+ memcpy(temp, ptr, sz);
38736+#else
38737+ temp = ptr;
38738+#endif
38739+
38740+ remaining = copy_to_user(buf, temp, sz);
38741+
38742+#ifdef CONFIG_PAX_USERCOPY
38743+ kfree(temp);
38744+#endif
38745+
38746 unxlate_dev_mem_ptr(p, ptr);
38747 if (remaining)
38748 return -EFAULT;
38749@@ -369,9 +400,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
38750 size_t count, loff_t *ppos)
38751 {
38752 unsigned long p = *ppos;
38753- ssize_t low_count, read, sz;
38754+ ssize_t low_count, read, sz, err = 0;
38755 char *kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
38756- int err = 0;
38757
38758 read = 0;
38759 if (p < (unsigned long) high_memory) {
38760@@ -393,6 +423,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
38761 }
38762 #endif
38763 while (low_count > 0) {
38764+ char *temp;
38765+
38766 sz = size_inside_page(p, low_count);
38767
38768 /*
38769@@ -402,7 +434,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
38770 */
38771 kbuf = xlate_dev_kmem_ptr((char *)p);
38772
38773- if (copy_to_user(buf, kbuf, sz))
38774+#ifdef CONFIG_PAX_USERCOPY
38775+ temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
38776+ if (!temp)
38777+ return -ENOMEM;
38778+ memcpy(temp, kbuf, sz);
38779+#else
38780+ temp = kbuf;
38781+#endif
38782+
38783+ err = copy_to_user(buf, temp, sz);
38784+
38785+#ifdef CONFIG_PAX_USERCOPY
38786+ kfree(temp);
38787+#endif
38788+
38789+ if (err)
38790 return -EFAULT;
38791 buf += sz;
38792 p += sz;
38793@@ -797,6 +844,9 @@ static const struct memdev {
38794 #ifdef CONFIG_PRINTK
38795 [11] = { "kmsg", 0644, &kmsg_fops, NULL },
38796 #endif
38797+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
38798+ [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
38799+#endif
38800 };
38801
38802 static int memory_open(struct inode *inode, struct file *filp)
38803@@ -868,7 +918,7 @@ static int __init chr_dev_init(void)
38804 continue;
38805
38806 device_create(mem_class, NULL, MKDEV(MEM_MAJOR, minor),
38807- NULL, devlist[minor].name);
38808+ NULL, "%s", devlist[minor].name);
38809 }
38810
38811 return tty_init();
38812diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
38813index 9df78e2..01ba9ae 100644
38814--- a/drivers/char/nvram.c
38815+++ b/drivers/char/nvram.c
38816@@ -247,7 +247,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
38817
38818 spin_unlock_irq(&rtc_lock);
38819
38820- if (copy_to_user(buf, contents, tmp - contents))
38821+ if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
38822 return -EFAULT;
38823
38824 *ppos = i;
38825diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
38826index 0ea9986..e7b07e4 100644
38827--- a/drivers/char/pcmcia/synclink_cs.c
38828+++ b/drivers/char/pcmcia/synclink_cs.c
38829@@ -2345,7 +2345,7 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
38830
38831 if (debug_level >= DEBUG_LEVEL_INFO)
38832 printk("%s(%d):mgslpc_close(%s) entry, count=%d\n",
38833- __FILE__, __LINE__, info->device_name, port->count);
38834+ __FILE__, __LINE__, info->device_name, atomic_read(&port->count));
38835
38836 if (tty_port_close_start(port, tty, filp) == 0)
38837 goto cleanup;
38838@@ -2363,7 +2363,7 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
38839 cleanup:
38840 if (debug_level >= DEBUG_LEVEL_INFO)
38841 printk("%s(%d):mgslpc_close(%s) exit, count=%d\n", __FILE__, __LINE__,
38842- tty->driver->name, port->count);
38843+ tty->driver->name, atomic_read(&port->count));
38844 }
38845
38846 /* Wait until the transmitter is empty.
38847@@ -2505,7 +2505,7 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
38848
38849 if (debug_level >= DEBUG_LEVEL_INFO)
38850 printk("%s(%d):mgslpc_open(%s), old ref count = %d\n",
38851- __FILE__, __LINE__, tty->driver->name, port->count);
38852+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
38853
38854 /* If port is closing, signal caller to try again */
38855 if (port->flags & ASYNC_CLOSING){
38856@@ -2525,11 +2525,11 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
38857 goto cleanup;
38858 }
38859 spin_lock(&port->lock);
38860- port->count++;
38861+ atomic_inc(&port->count);
38862 spin_unlock(&port->lock);
38863 spin_unlock_irqrestore(&info->netlock, flags);
38864
38865- if (port->count == 1) {
38866+ if (atomic_read(&port->count) == 1) {
38867 /* 1st open on this device, init hardware */
38868 retval = startup(info, tty);
38869 if (retval < 0)
38870@@ -3918,7 +3918,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
38871 unsigned short new_crctype;
38872
38873 /* return error if TTY interface open */
38874- if (info->port.count)
38875+ if (atomic_read(&info->port.count))
38876 return -EBUSY;
38877
38878 switch (encoding)
38879@@ -4022,7 +4022,7 @@ static int hdlcdev_open(struct net_device *dev)
38880
38881 /* arbitrate between network and tty opens */
38882 spin_lock_irqsave(&info->netlock, flags);
38883- if (info->port.count != 0 || info->netcount != 0) {
38884+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
38885 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
38886 spin_unlock_irqrestore(&info->netlock, flags);
38887 return -EBUSY;
38888@@ -4112,7 +4112,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
38889 printk("%s:hdlcdev_ioctl(%s)\n", __FILE__, dev->name);
38890
38891 /* return error if TTY interface open */
38892- if (info->port.count)
38893+ if (atomic_read(&info->port.count))
38894 return -EBUSY;
38895
38896 if (cmd != SIOCWANDEV)
38897diff --git a/drivers/char/random.c b/drivers/char/random.c
38898index 04645c0..560e350 100644
38899--- a/drivers/char/random.c
38900+++ b/drivers/char/random.c
38901@@ -289,9 +289,6 @@
38902 /*
38903 * To allow fractional bits to be tracked, the entropy_count field is
38904 * denominated in units of 1/8th bits.
38905- *
38906- * 2*(ENTROPY_SHIFT + log2(poolbits)) must <= 31, or the multiply in
38907- * credit_entropy_bits() needs to be 64 bits wide.
38908 */
38909 #define ENTROPY_SHIFT 3
38910 #define ENTROPY_BITS(r) ((r)->entropy_count >> ENTROPY_SHIFT)
38911@@ -439,9 +436,9 @@ struct entropy_store {
38912 };
38913
38914 static void push_to_pool(struct work_struct *work);
38915-static __u32 input_pool_data[INPUT_POOL_WORDS];
38916-static __u32 blocking_pool_data[OUTPUT_POOL_WORDS];
38917-static __u32 nonblocking_pool_data[OUTPUT_POOL_WORDS];
38918+static __u32 input_pool_data[INPUT_POOL_WORDS] __latent_entropy;
38919+static __u32 blocking_pool_data[OUTPUT_POOL_WORDS] __latent_entropy;
38920+static __u32 nonblocking_pool_data[OUTPUT_POOL_WORDS] __latent_entropy;
38921
38922 static struct entropy_store input_pool = {
38923 .poolinfo = &poolinfo_table[0],
38924@@ -635,7 +632,7 @@ retry:
38925 /* The +2 corresponds to the /4 in the denominator */
38926
38927 do {
38928- unsigned int anfrac = min(pnfrac, pool_size/2);
38929+ u64 anfrac = min(pnfrac, pool_size/2);
38930 unsigned int add =
38931 ((pool_size - entropy_count)*anfrac*3) >> s;
38932
38933@@ -1207,7 +1204,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
38934
38935 extract_buf(r, tmp);
38936 i = min_t(int, nbytes, EXTRACT_SIZE);
38937- if (copy_to_user(buf, tmp, i)) {
38938+ if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
38939 ret = -EFAULT;
38940 break;
38941 }
38942@@ -1590,7 +1587,7 @@ static char sysctl_bootid[16];
38943 static int proc_do_uuid(struct ctl_table *table, int write,
38944 void __user *buffer, size_t *lenp, loff_t *ppos)
38945 {
38946- struct ctl_table fake_table;
38947+ ctl_table_no_const fake_table;
38948 unsigned char buf[64], tmp_uuid[16], *uuid;
38949
38950 uuid = table->data;
38951@@ -1620,7 +1617,7 @@ static int proc_do_uuid(struct ctl_table *table, int write,
38952 static int proc_do_entropy(struct ctl_table *table, int write,
38953 void __user *buffer, size_t *lenp, loff_t *ppos)
38954 {
38955- struct ctl_table fake_table;
38956+ ctl_table_no_const fake_table;
38957 int entropy_count;
38958
38959 entropy_count = *(int *)table->data >> ENTROPY_SHIFT;
38960diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
38961index 7cc1fe22..b602d6b 100644
38962--- a/drivers/char/sonypi.c
38963+++ b/drivers/char/sonypi.c
38964@@ -54,6 +54,7 @@
38965
38966 #include <asm/uaccess.h>
38967 #include <asm/io.h>
38968+#include <asm/local.h>
38969
38970 #include <linux/sonypi.h>
38971
38972@@ -490,7 +491,7 @@ static struct sonypi_device {
38973 spinlock_t fifo_lock;
38974 wait_queue_head_t fifo_proc_list;
38975 struct fasync_struct *fifo_async;
38976- int open_count;
38977+ local_t open_count;
38978 int model;
38979 struct input_dev *input_jog_dev;
38980 struct input_dev *input_key_dev;
38981@@ -892,7 +893,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
38982 static int sonypi_misc_release(struct inode *inode, struct file *file)
38983 {
38984 mutex_lock(&sonypi_device.lock);
38985- sonypi_device.open_count--;
38986+ local_dec(&sonypi_device.open_count);
38987 mutex_unlock(&sonypi_device.lock);
38988 return 0;
38989 }
38990@@ -901,9 +902,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
38991 {
38992 mutex_lock(&sonypi_device.lock);
38993 /* Flush input queue on first open */
38994- if (!sonypi_device.open_count)
38995+ if (!local_read(&sonypi_device.open_count))
38996 kfifo_reset(&sonypi_device.fifo);
38997- sonypi_device.open_count++;
38998+ local_inc(&sonypi_device.open_count);
38999 mutex_unlock(&sonypi_device.lock);
39000
39001 return 0;
39002diff --git a/drivers/char/tpm/tpm_acpi.c b/drivers/char/tpm/tpm_acpi.c
39003index 565a947..dcdc06e 100644
39004--- a/drivers/char/tpm/tpm_acpi.c
39005+++ b/drivers/char/tpm/tpm_acpi.c
39006@@ -98,11 +98,12 @@ int read_log(struct tpm_bios_log *log)
39007 virt = acpi_os_map_iomem(start, len);
39008 if (!virt) {
39009 kfree(log->bios_event_log);
39010+ log->bios_event_log = NULL;
39011 printk("%s: ERROR - Unable to map memory\n", __func__);
39012 return -EIO;
39013 }
39014
39015- memcpy_fromio(log->bios_event_log, virt, len);
39016+ memcpy_fromio(log->bios_event_log, (const char __force_kernel *)virt, len);
39017
39018 acpi_os_unmap_iomem(virt, len);
39019 return 0;
39020diff --git a/drivers/char/tpm/tpm_eventlog.c b/drivers/char/tpm/tpm_eventlog.c
39021index 3a56a13..f8cbd25 100644
39022--- a/drivers/char/tpm/tpm_eventlog.c
39023+++ b/drivers/char/tpm/tpm_eventlog.c
39024@@ -95,7 +95,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
39025 event = addr;
39026
39027 if ((event->event_type == 0 && event->event_size == 0) ||
39028- ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
39029+ (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
39030 return NULL;
39031
39032 return addr;
39033@@ -120,7 +120,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
39034 return NULL;
39035
39036 if ((event->event_type == 0 && event->event_size == 0) ||
39037- ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
39038+ (event->event_size >= limit - v - sizeof(struct tcpa_event)))
39039 return NULL;
39040
39041 (*pos)++;
39042@@ -213,7 +213,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
39043 int i;
39044
39045 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
39046- seq_putc(m, data[i]);
39047+ if (!seq_putc(m, data[i]))
39048+ return -EFAULT;
39049
39050 return 0;
39051 }
39052diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
39053index cf7a561..c319ce0 100644
39054--- a/drivers/char/virtio_console.c
39055+++ b/drivers/char/virtio_console.c
39056@@ -684,7 +684,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
39057 if (to_user) {
39058 ssize_t ret;
39059
39060- ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
39061+ ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
39062 if (ret)
39063 return -EFAULT;
39064 } else {
39065@@ -787,7 +787,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
39066 if (!port_has_data(port) && !port->host_connected)
39067 return 0;
39068
39069- return fill_readbuf(port, ubuf, count, true);
39070+ return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
39071 }
39072
39073 static int wait_port_writable(struct port *port, bool nonblock)
39074diff --git a/drivers/clk/clk-composite.c b/drivers/clk/clk-composite.c
39075index b9355da..9611f4e 100644
39076--- a/drivers/clk/clk-composite.c
39077+++ b/drivers/clk/clk-composite.c
39078@@ -191,7 +191,7 @@ struct clk *clk_register_composite(struct device *dev, const char *name,
39079 struct clk *clk;
39080 struct clk_init_data init;
39081 struct clk_composite *composite;
39082- struct clk_ops *clk_composite_ops;
39083+ clk_ops_no_const *clk_composite_ops;
39084
39085 composite = kzalloc(sizeof(*composite), GFP_KERNEL);
39086 if (!composite) {
39087diff --git a/drivers/clk/socfpga/clk-gate.c b/drivers/clk/socfpga/clk-gate.c
39088index dd3a78c..386d49c 100644
39089--- a/drivers/clk/socfpga/clk-gate.c
39090+++ b/drivers/clk/socfpga/clk-gate.c
39091@@ -22,6 +22,7 @@
39092 #include <linux/mfd/syscon.h>
39093 #include <linux/of.h>
39094 #include <linux/regmap.h>
39095+#include <asm/pgtable.h>
39096
39097 #include "clk.h"
39098
39099@@ -174,7 +175,7 @@ static int socfpga_clk_prepare(struct clk_hw *hwclk)
39100 return 0;
39101 }
39102
39103-static struct clk_ops gateclk_ops = {
39104+static clk_ops_no_const gateclk_ops __read_only = {
39105 .prepare = socfpga_clk_prepare,
39106 .recalc_rate = socfpga_clk_recalc_rate,
39107 .get_parent = socfpga_clk_get_parent,
39108@@ -208,8 +209,10 @@ static void __init __socfpga_gate_init(struct device_node *node,
39109 socfpga_clk->hw.reg = clk_mgr_base_addr + clk_gate[0];
39110 socfpga_clk->hw.bit_idx = clk_gate[1];
39111
39112- gateclk_ops.enable = clk_gate_ops.enable;
39113- gateclk_ops.disable = clk_gate_ops.disable;
39114+ pax_open_kernel();
39115+ *(void **)&gateclk_ops.enable = clk_gate_ops.enable;
39116+ *(void **)&gateclk_ops.disable = clk_gate_ops.disable;
39117+ pax_close_kernel();
39118 }
39119
39120 rc = of_property_read_u32(node, "fixed-divider", &fixed_div);
39121diff --git a/drivers/clk/socfpga/clk-pll.c b/drivers/clk/socfpga/clk-pll.c
39122index de6da95..c98278b 100644
39123--- a/drivers/clk/socfpga/clk-pll.c
39124+++ b/drivers/clk/socfpga/clk-pll.c
39125@@ -21,6 +21,7 @@
39126 #include <linux/io.h>
39127 #include <linux/of.h>
39128 #include <linux/of_address.h>
39129+#include <asm/pgtable.h>
39130
39131 #include "clk.h"
39132
39133@@ -76,7 +77,7 @@ static u8 clk_pll_get_parent(struct clk_hw *hwclk)
39134 CLK_MGR_PLL_CLK_SRC_MASK;
39135 }
39136
39137-static struct clk_ops clk_pll_ops = {
39138+static clk_ops_no_const clk_pll_ops __read_only = {
39139 .recalc_rate = clk_pll_recalc_rate,
39140 .get_parent = clk_pll_get_parent,
39141 };
39142@@ -120,8 +121,10 @@ static __init struct clk *__socfpga_pll_init(struct device_node *node,
39143 pll_clk->hw.hw.init = &init;
39144
39145 pll_clk->hw.bit_idx = SOCFPGA_PLL_EXT_ENA;
39146- clk_pll_ops.enable = clk_gate_ops.enable;
39147- clk_pll_ops.disable = clk_gate_ops.disable;
39148+ pax_open_kernel();
39149+ *(void **)&clk_pll_ops.enable = clk_gate_ops.enable;
39150+ *(void **)&clk_pll_ops.disable = clk_gate_ops.disable;
39151+ pax_close_kernel();
39152
39153 clk = clk_register(NULL, &pll_clk->hw.hw);
39154 if (WARN_ON(IS_ERR(clk))) {
39155diff --git a/drivers/cpufreq/acpi-cpufreq.c b/drivers/cpufreq/acpi-cpufreq.c
39156index b0c18ed..1713a80 100644
39157--- a/drivers/cpufreq/acpi-cpufreq.c
39158+++ b/drivers/cpufreq/acpi-cpufreq.c
39159@@ -675,8 +675,11 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
39160 data->acpi_data = per_cpu_ptr(acpi_perf_data, cpu);
39161 per_cpu(acfreq_data, cpu) = data;
39162
39163- if (cpu_has(c, X86_FEATURE_CONSTANT_TSC))
39164- acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
39165+ if (cpu_has(c, X86_FEATURE_CONSTANT_TSC)) {
39166+ pax_open_kernel();
39167+ *(u8 *)&acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
39168+ pax_close_kernel();
39169+ }
39170
39171 result = acpi_processor_register_performance(data->acpi_data, cpu);
39172 if (result)
39173@@ -809,7 +812,9 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
39174 policy->cur = acpi_cpufreq_guess_freq(data, policy->cpu);
39175 break;
39176 case ACPI_ADR_SPACE_FIXED_HARDWARE:
39177- acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
39178+ pax_open_kernel();
39179+ *(void **)&acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
39180+ pax_close_kernel();
39181 break;
39182 default:
39183 break;
39184@@ -903,8 +908,10 @@ static void __init acpi_cpufreq_boost_init(void)
39185 if (!msrs)
39186 return;
39187
39188- acpi_cpufreq_driver.boost_supported = true;
39189- acpi_cpufreq_driver.boost_enabled = boost_state(0);
39190+ pax_open_kernel();
39191+ *(bool *)&acpi_cpufreq_driver.boost_supported = true;
39192+ *(bool *)&acpi_cpufreq_driver.boost_enabled = boost_state(0);
39193+ pax_close_kernel();
39194
39195 cpu_notifier_register_begin();
39196
39197diff --git a/drivers/cpufreq/cpufreq-dt.c b/drivers/cpufreq/cpufreq-dt.c
39198index f657c57..31d97ae 100644
39199--- a/drivers/cpufreq/cpufreq-dt.c
39200+++ b/drivers/cpufreq/cpufreq-dt.c
39201@@ -362,7 +362,9 @@ static int dt_cpufreq_probe(struct platform_device *pdev)
39202 if (!IS_ERR(cpu_reg))
39203 regulator_put(cpu_reg);
39204
39205- dt_cpufreq_driver.driver_data = dev_get_platdata(&pdev->dev);
39206+ pax_open_kernel();
39207+ *(void **)&dt_cpufreq_driver.driver_data = dev_get_platdata(&pdev->dev);
39208+ pax_close_kernel();
39209
39210 ret = cpufreq_register_driver(&dt_cpufreq_driver);
39211 if (ret)
39212diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
39213index 4473eba..a4c9dc2 100644
39214--- a/drivers/cpufreq/cpufreq.c
39215+++ b/drivers/cpufreq/cpufreq.c
39216@@ -2122,7 +2122,7 @@ void cpufreq_unregister_governor(struct cpufreq_governor *governor)
39217 }
39218
39219 mutex_lock(&cpufreq_governor_mutex);
39220- list_del(&governor->governor_list);
39221+ pax_list_del(&governor->governor_list);
39222 mutex_unlock(&cpufreq_governor_mutex);
39223 return;
39224 }
39225@@ -2338,7 +2338,7 @@ static int cpufreq_cpu_callback(struct notifier_block *nfb,
39226 return NOTIFY_OK;
39227 }
39228
39229-static struct notifier_block __refdata cpufreq_cpu_notifier = {
39230+static struct notifier_block cpufreq_cpu_notifier = {
39231 .notifier_call = cpufreq_cpu_callback,
39232 };
39233
39234@@ -2378,13 +2378,17 @@ int cpufreq_boost_trigger_state(int state)
39235 return 0;
39236
39237 write_lock_irqsave(&cpufreq_driver_lock, flags);
39238- cpufreq_driver->boost_enabled = state;
39239+ pax_open_kernel();
39240+ *(bool *)&cpufreq_driver->boost_enabled = state;
39241+ pax_close_kernel();
39242 write_unlock_irqrestore(&cpufreq_driver_lock, flags);
39243
39244 ret = cpufreq_driver->set_boost(state);
39245 if (ret) {
39246 write_lock_irqsave(&cpufreq_driver_lock, flags);
39247- cpufreq_driver->boost_enabled = !state;
39248+ pax_open_kernel();
39249+ *(bool *)&cpufreq_driver->boost_enabled = !state;
39250+ pax_close_kernel();
39251 write_unlock_irqrestore(&cpufreq_driver_lock, flags);
39252
39253 pr_err("%s: Cannot %s BOOST\n",
39254@@ -2441,8 +2445,11 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data)
39255
39256 pr_debug("trying to register driver %s\n", driver_data->name);
39257
39258- if (driver_data->setpolicy)
39259- driver_data->flags |= CPUFREQ_CONST_LOOPS;
39260+ if (driver_data->setpolicy) {
39261+ pax_open_kernel();
39262+ *(u8 *)&driver_data->flags |= CPUFREQ_CONST_LOOPS;
39263+ pax_close_kernel();
39264+ }
39265
39266 write_lock_irqsave(&cpufreq_driver_lock, flags);
39267 if (cpufreq_driver) {
39268@@ -2457,8 +2464,11 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data)
39269 * Check if driver provides function to enable boost -
39270 * if not, use cpufreq_boost_set_sw as default
39271 */
39272- if (!cpufreq_driver->set_boost)
39273- cpufreq_driver->set_boost = cpufreq_boost_set_sw;
39274+ if (!cpufreq_driver->set_boost) {
39275+ pax_open_kernel();
39276+ *(void **)&cpufreq_driver->set_boost = cpufreq_boost_set_sw;
39277+ pax_close_kernel();
39278+ }
39279
39280 ret = cpufreq_sysfs_create_file(&boost.attr);
39281 if (ret) {
39282diff --git a/drivers/cpufreq/cpufreq_governor.c b/drivers/cpufreq/cpufreq_governor.c
39283index 1b44496..b80ff5e 100644
39284--- a/drivers/cpufreq/cpufreq_governor.c
39285+++ b/drivers/cpufreq/cpufreq_governor.c
39286@@ -245,7 +245,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
39287 struct dbs_data *dbs_data;
39288 struct od_cpu_dbs_info_s *od_dbs_info = NULL;
39289 struct cs_cpu_dbs_info_s *cs_dbs_info = NULL;
39290- struct od_ops *od_ops = NULL;
39291+ const struct od_ops *od_ops = NULL;
39292 struct od_dbs_tuners *od_tuners = NULL;
39293 struct cs_dbs_tuners *cs_tuners = NULL;
39294 struct cpu_dbs_common_info *cpu_cdbs;
39295@@ -311,7 +311,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
39296
39297 if ((cdata->governor == GOV_CONSERVATIVE) &&
39298 (!policy->governor->initialized)) {
39299- struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
39300+ const struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
39301
39302 cpufreq_register_notifier(cs_ops->notifier_block,
39303 CPUFREQ_TRANSITION_NOTIFIER);
39304@@ -331,7 +331,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
39305
39306 if ((dbs_data->cdata->governor == GOV_CONSERVATIVE) &&
39307 (policy->governor->initialized == 1)) {
39308- struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
39309+ const struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
39310
39311 cpufreq_unregister_notifier(cs_ops->notifier_block,
39312 CPUFREQ_TRANSITION_NOTIFIER);
39313diff --git a/drivers/cpufreq/cpufreq_governor.h b/drivers/cpufreq/cpufreq_governor.h
39314index cc401d1..8197340 100644
39315--- a/drivers/cpufreq/cpufreq_governor.h
39316+++ b/drivers/cpufreq/cpufreq_governor.h
39317@@ -212,7 +212,7 @@ struct common_dbs_data {
39318 void (*exit)(struct dbs_data *dbs_data);
39319
39320 /* Governor specific ops, see below */
39321- void *gov_ops;
39322+ const void *gov_ops;
39323 };
39324
39325 /* Governor Per policy data */
39326@@ -232,7 +232,7 @@ struct od_ops {
39327 unsigned int (*powersave_bias_target)(struct cpufreq_policy *policy,
39328 unsigned int freq_next, unsigned int relation);
39329 void (*freq_increase)(struct cpufreq_policy *policy, unsigned int freq);
39330-};
39331+} __no_const;
39332
39333 struct cs_ops {
39334 struct notifier_block *notifier_block;
39335diff --git a/drivers/cpufreq/cpufreq_ondemand.c b/drivers/cpufreq/cpufreq_ondemand.c
39336index ad3f38f..8f086cd 100644
39337--- a/drivers/cpufreq/cpufreq_ondemand.c
39338+++ b/drivers/cpufreq/cpufreq_ondemand.c
39339@@ -524,7 +524,7 @@ static void od_exit(struct dbs_data *dbs_data)
39340
39341 define_get_cpu_dbs_routines(od_cpu_dbs_info);
39342
39343-static struct od_ops od_ops = {
39344+static struct od_ops od_ops __read_only = {
39345 .powersave_bias_init_cpu = ondemand_powersave_bias_init_cpu,
39346 .powersave_bias_target = generic_powersave_bias_target,
39347 .freq_increase = dbs_freq_increase,
39348@@ -579,14 +579,18 @@ void od_register_powersave_bias_handler(unsigned int (*f)
39349 (struct cpufreq_policy *, unsigned int, unsigned int),
39350 unsigned int powersave_bias)
39351 {
39352- od_ops.powersave_bias_target = f;
39353+ pax_open_kernel();
39354+ *(void **)&od_ops.powersave_bias_target = f;
39355+ pax_close_kernel();
39356 od_set_powersave_bias(powersave_bias);
39357 }
39358 EXPORT_SYMBOL_GPL(od_register_powersave_bias_handler);
39359
39360 void od_unregister_powersave_bias_handler(void)
39361 {
39362- od_ops.powersave_bias_target = generic_powersave_bias_target;
39363+ pax_open_kernel();
39364+ *(void **)&od_ops.powersave_bias_target = generic_powersave_bias_target;
39365+ pax_close_kernel();
39366 od_set_powersave_bias(0);
39367 }
39368 EXPORT_SYMBOL_GPL(od_unregister_powersave_bias_handler);
39369diff --git a/drivers/cpufreq/intel_pstate.c b/drivers/cpufreq/intel_pstate.c
39370index 27bb6d3..4cf595c 100644
39371--- a/drivers/cpufreq/intel_pstate.c
39372+++ b/drivers/cpufreq/intel_pstate.c
39373@@ -133,10 +133,10 @@ struct pstate_funcs {
39374 struct cpu_defaults {
39375 struct pstate_adjust_policy pid_policy;
39376 struct pstate_funcs funcs;
39377-};
39378+} __do_const;
39379
39380 static struct pstate_adjust_policy pid_params;
39381-static struct pstate_funcs pstate_funcs;
39382+static struct pstate_funcs *pstate_funcs;
39383
39384 struct perf_limits {
39385 int no_turbo;
39386@@ -594,18 +594,18 @@ static void intel_pstate_set_pstate(struct cpudata *cpu, int pstate)
39387
39388 cpu->pstate.current_pstate = pstate;
39389
39390- pstate_funcs.set(cpu, pstate);
39391+ pstate_funcs->set(cpu, pstate);
39392 }
39393
39394 static void intel_pstate_get_cpu_pstates(struct cpudata *cpu)
39395 {
39396- cpu->pstate.min_pstate = pstate_funcs.get_min();
39397- cpu->pstate.max_pstate = pstate_funcs.get_max();
39398- cpu->pstate.turbo_pstate = pstate_funcs.get_turbo();
39399- cpu->pstate.scaling = pstate_funcs.get_scaling();
39400+ cpu->pstate.min_pstate = pstate_funcs->get_min();
39401+ cpu->pstate.max_pstate = pstate_funcs->get_max();
39402+ cpu->pstate.turbo_pstate = pstate_funcs->get_turbo();
39403+ cpu->pstate.scaling = pstate_funcs->get_scaling();
39404
39405- if (pstate_funcs.get_vid)
39406- pstate_funcs.get_vid(cpu);
39407+ if (pstate_funcs->get_vid)
39408+ pstate_funcs->get_vid(cpu);
39409 intel_pstate_set_pstate(cpu, cpu->pstate.min_pstate);
39410 }
39411
39412@@ -875,9 +875,9 @@ static int intel_pstate_msrs_not_valid(void)
39413 rdmsrl(MSR_IA32_APERF, aperf);
39414 rdmsrl(MSR_IA32_MPERF, mperf);
39415
39416- if (!pstate_funcs.get_max() ||
39417- !pstate_funcs.get_min() ||
39418- !pstate_funcs.get_turbo())
39419+ if (!pstate_funcs->get_max() ||
39420+ !pstate_funcs->get_min() ||
39421+ !pstate_funcs->get_turbo())
39422 return -ENODEV;
39423
39424 rdmsrl(MSR_IA32_APERF, tmp);
39425@@ -891,7 +891,7 @@ static int intel_pstate_msrs_not_valid(void)
39426 return 0;
39427 }
39428
39429-static void copy_pid_params(struct pstate_adjust_policy *policy)
39430+static void copy_pid_params(const struct pstate_adjust_policy *policy)
39431 {
39432 pid_params.sample_rate_ms = policy->sample_rate_ms;
39433 pid_params.p_gain_pct = policy->p_gain_pct;
39434@@ -903,12 +903,7 @@ static void copy_pid_params(struct pstate_adjust_policy *policy)
39435
39436 static void copy_cpu_funcs(struct pstate_funcs *funcs)
39437 {
39438- pstate_funcs.get_max = funcs->get_max;
39439- pstate_funcs.get_min = funcs->get_min;
39440- pstate_funcs.get_turbo = funcs->get_turbo;
39441- pstate_funcs.get_scaling = funcs->get_scaling;
39442- pstate_funcs.set = funcs->set;
39443- pstate_funcs.get_vid = funcs->get_vid;
39444+ pstate_funcs = funcs;
39445 }
39446
39447 #if IS_ENABLED(CONFIG_ACPI)
39448diff --git a/drivers/cpufreq/p4-clockmod.c b/drivers/cpufreq/p4-clockmod.c
39449index 529cfd9..0e28fff 100644
39450--- a/drivers/cpufreq/p4-clockmod.c
39451+++ b/drivers/cpufreq/p4-clockmod.c
39452@@ -134,10 +134,14 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
39453 case 0x0F: /* Core Duo */
39454 case 0x16: /* Celeron Core */
39455 case 0x1C: /* Atom */
39456- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39457+ pax_open_kernel();
39458+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39459+ pax_close_kernel();
39460 return speedstep_get_frequency(SPEEDSTEP_CPU_PCORE);
39461 case 0x0D: /* Pentium M (Dothan) */
39462- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39463+ pax_open_kernel();
39464+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39465+ pax_close_kernel();
39466 /* fall through */
39467 case 0x09: /* Pentium M (Banias) */
39468 return speedstep_get_frequency(SPEEDSTEP_CPU_PM);
39469@@ -149,7 +153,9 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
39470
39471 /* on P-4s, the TSC runs with constant frequency independent whether
39472 * throttling is active or not. */
39473- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39474+ pax_open_kernel();
39475+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39476+ pax_close_kernel();
39477
39478 if (speedstep_detect_processor() == SPEEDSTEP_CPU_P4M) {
39479 printk(KERN_WARNING PFX "Warning: Pentium 4-M detected. "
39480diff --git a/drivers/cpufreq/sparc-us3-cpufreq.c b/drivers/cpufreq/sparc-us3-cpufreq.c
39481index 9bb42ba..b01b4a2 100644
39482--- a/drivers/cpufreq/sparc-us3-cpufreq.c
39483+++ b/drivers/cpufreq/sparc-us3-cpufreq.c
39484@@ -18,14 +18,12 @@
39485 #include <asm/head.h>
39486 #include <asm/timer.h>
39487
39488-static struct cpufreq_driver *cpufreq_us3_driver;
39489-
39490 struct us3_freq_percpu_info {
39491 struct cpufreq_frequency_table table[4];
39492 };
39493
39494 /* Indexed by cpu number. */
39495-static struct us3_freq_percpu_info *us3_freq_table;
39496+static struct us3_freq_percpu_info us3_freq_table[NR_CPUS];
39497
39498 /* UltraSPARC-III has three dividers: 1, 2, and 32. These are controlled
39499 * in the Safari config register.
39500@@ -156,16 +154,27 @@ static int __init us3_freq_cpu_init(struct cpufreq_policy *policy)
39501
39502 static int us3_freq_cpu_exit(struct cpufreq_policy *policy)
39503 {
39504- if (cpufreq_us3_driver)
39505- us3_freq_target(policy, 0);
39506+ us3_freq_target(policy, 0);
39507
39508 return 0;
39509 }
39510
39511+static int __init us3_freq_init(void);
39512+static void __exit us3_freq_exit(void);
39513+
39514+static struct cpufreq_driver cpufreq_us3_driver = {
39515+ .init = us3_freq_cpu_init,
39516+ .verify = cpufreq_generic_frequency_table_verify,
39517+ .target_index = us3_freq_target,
39518+ .get = us3_freq_get,
39519+ .exit = us3_freq_cpu_exit,
39520+ .name = "UltraSPARC-III",
39521+
39522+};
39523+
39524 static int __init us3_freq_init(void)
39525 {
39526 unsigned long manuf, impl, ver;
39527- int ret;
39528
39529 if (tlb_type != cheetah && tlb_type != cheetah_plus)
39530 return -ENODEV;
39531@@ -178,55 +187,15 @@ static int __init us3_freq_init(void)
39532 (impl == CHEETAH_IMPL ||
39533 impl == CHEETAH_PLUS_IMPL ||
39534 impl == JAGUAR_IMPL ||
39535- impl == PANTHER_IMPL)) {
39536- struct cpufreq_driver *driver;
39537-
39538- ret = -ENOMEM;
39539- driver = kzalloc(sizeof(*driver), GFP_KERNEL);
39540- if (!driver)
39541- goto err_out;
39542-
39543- us3_freq_table = kzalloc((NR_CPUS * sizeof(*us3_freq_table)),
39544- GFP_KERNEL);
39545- if (!us3_freq_table)
39546- goto err_out;
39547-
39548- driver->init = us3_freq_cpu_init;
39549- driver->verify = cpufreq_generic_frequency_table_verify;
39550- driver->target_index = us3_freq_target;
39551- driver->get = us3_freq_get;
39552- driver->exit = us3_freq_cpu_exit;
39553- strcpy(driver->name, "UltraSPARC-III");
39554-
39555- cpufreq_us3_driver = driver;
39556- ret = cpufreq_register_driver(driver);
39557- if (ret)
39558- goto err_out;
39559-
39560- return 0;
39561-
39562-err_out:
39563- if (driver) {
39564- kfree(driver);
39565- cpufreq_us3_driver = NULL;
39566- }
39567- kfree(us3_freq_table);
39568- us3_freq_table = NULL;
39569- return ret;
39570- }
39571+ impl == PANTHER_IMPL))
39572+ return cpufreq_register_driver(&cpufreq_us3_driver);
39573
39574 return -ENODEV;
39575 }
39576
39577 static void __exit us3_freq_exit(void)
39578 {
39579- if (cpufreq_us3_driver) {
39580- cpufreq_unregister_driver(cpufreq_us3_driver);
39581- kfree(cpufreq_us3_driver);
39582- cpufreq_us3_driver = NULL;
39583- kfree(us3_freq_table);
39584- us3_freq_table = NULL;
39585- }
39586+ cpufreq_unregister_driver(&cpufreq_us3_driver);
39587 }
39588
39589 MODULE_AUTHOR("David S. Miller <davem@redhat.com>");
39590diff --git a/drivers/cpufreq/speedstep-centrino.c b/drivers/cpufreq/speedstep-centrino.c
39591index 7d4a315..21bb886 100644
39592--- a/drivers/cpufreq/speedstep-centrino.c
39593+++ b/drivers/cpufreq/speedstep-centrino.c
39594@@ -351,8 +351,11 @@ static int centrino_cpu_init(struct cpufreq_policy *policy)
39595 !cpu_has(cpu, X86_FEATURE_EST))
39596 return -ENODEV;
39597
39598- if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC))
39599- centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
39600+ if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC)) {
39601+ pax_open_kernel();
39602+ *(u8 *)&centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
39603+ pax_close_kernel();
39604+ }
39605
39606 if (policy->cpu != 0)
39607 return -ENODEV;
39608diff --git a/drivers/cpuidle/driver.c b/drivers/cpuidle/driver.c
39609index e431d11..d0b997e 100644
39610--- a/drivers/cpuidle/driver.c
39611+++ b/drivers/cpuidle/driver.c
39612@@ -194,7 +194,7 @@ static int poll_idle(struct cpuidle_device *dev,
39613
39614 static void poll_idle_init(struct cpuidle_driver *drv)
39615 {
39616- struct cpuidle_state *state = &drv->states[0];
39617+ cpuidle_state_no_const *state = &drv->states[0];
39618
39619 snprintf(state->name, CPUIDLE_NAME_LEN, "POLL");
39620 snprintf(state->desc, CPUIDLE_DESC_LEN, "CPUIDLE CORE POLL IDLE");
39621diff --git a/drivers/cpuidle/governor.c b/drivers/cpuidle/governor.c
39622index fb9f511..213e6cc 100644
39623--- a/drivers/cpuidle/governor.c
39624+++ b/drivers/cpuidle/governor.c
39625@@ -87,7 +87,7 @@ int cpuidle_register_governor(struct cpuidle_governor *gov)
39626 mutex_lock(&cpuidle_lock);
39627 if (__cpuidle_find_governor(gov->name) == NULL) {
39628 ret = 0;
39629- list_add_tail(&gov->governor_list, &cpuidle_governors);
39630+ pax_list_add_tail((struct list_head *)&gov->governor_list, &cpuidle_governors);
39631 if (!cpuidle_curr_governor ||
39632 cpuidle_curr_governor->rating < gov->rating)
39633 cpuidle_switch_governor(gov);
39634diff --git a/drivers/cpuidle/sysfs.c b/drivers/cpuidle/sysfs.c
39635index 97c5903..023ad23 100644
39636--- a/drivers/cpuidle/sysfs.c
39637+++ b/drivers/cpuidle/sysfs.c
39638@@ -135,7 +135,7 @@ static struct attribute *cpuidle_switch_attrs[] = {
39639 NULL
39640 };
39641
39642-static struct attribute_group cpuidle_attr_group = {
39643+static attribute_group_no_const cpuidle_attr_group = {
39644 .attrs = cpuidle_default_attrs,
39645 .name = "cpuidle",
39646 };
39647diff --git a/drivers/crypto/hifn_795x.c b/drivers/crypto/hifn_795x.c
39648index 8d2a772..33826c9 100644
39649--- a/drivers/crypto/hifn_795x.c
39650+++ b/drivers/crypto/hifn_795x.c
39651@@ -51,7 +51,7 @@ module_param_string(hifn_pll_ref, hifn_pll_ref, sizeof(hifn_pll_ref), 0444);
39652 MODULE_PARM_DESC(hifn_pll_ref,
39653 "PLL reference clock (pci[freq] or ext[freq], default ext)");
39654
39655-static atomic_t hifn_dev_number;
39656+static atomic_unchecked_t hifn_dev_number;
39657
39658 #define ACRYPTO_OP_DECRYPT 0
39659 #define ACRYPTO_OP_ENCRYPT 1
39660@@ -2577,7 +2577,7 @@ static int hifn_probe(struct pci_dev *pdev, const struct pci_device_id *id)
39661 goto err_out_disable_pci_device;
39662
39663 snprintf(name, sizeof(name), "hifn%d",
39664- atomic_inc_return(&hifn_dev_number)-1);
39665+ atomic_inc_return_unchecked(&hifn_dev_number)-1);
39666
39667 err = pci_request_regions(pdev, name);
39668 if (err)
39669diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
39670index 30b538d8..1610d75 100644
39671--- a/drivers/devfreq/devfreq.c
39672+++ b/drivers/devfreq/devfreq.c
39673@@ -673,7 +673,7 @@ int devfreq_add_governor(struct devfreq_governor *governor)
39674 goto err_out;
39675 }
39676
39677- list_add(&governor->node, &devfreq_governor_list);
39678+ pax_list_add((struct list_head *)&governor->node, &devfreq_governor_list);
39679
39680 list_for_each_entry(devfreq, &devfreq_list, node) {
39681 int ret = 0;
39682@@ -761,7 +761,7 @@ int devfreq_remove_governor(struct devfreq_governor *governor)
39683 }
39684 }
39685
39686- list_del(&governor->node);
39687+ pax_list_del((struct list_head *)&governor->node);
39688 err_out:
39689 mutex_unlock(&devfreq_list_lock);
39690
39691diff --git a/drivers/dma/sh/shdma-base.c b/drivers/dma/sh/shdma-base.c
39692index 42d4974..2714f36 100644
39693--- a/drivers/dma/sh/shdma-base.c
39694+++ b/drivers/dma/sh/shdma-base.c
39695@@ -228,8 +228,8 @@ static int shdma_alloc_chan_resources(struct dma_chan *chan)
39696 schan->slave_id = -EINVAL;
39697 }
39698
39699- schan->desc = kcalloc(NR_DESCS_PER_CHANNEL,
39700- sdev->desc_size, GFP_KERNEL);
39701+ schan->desc = kcalloc(sdev->desc_size,
39702+ NR_DESCS_PER_CHANNEL, GFP_KERNEL);
39703 if (!schan->desc) {
39704 ret = -ENOMEM;
39705 goto edescalloc;
39706diff --git a/drivers/dma/sh/shdmac.c b/drivers/dma/sh/shdmac.c
39707index 58eb857..d7e42c8 100644
39708--- a/drivers/dma/sh/shdmac.c
39709+++ b/drivers/dma/sh/shdmac.c
39710@@ -513,7 +513,7 @@ static int sh_dmae_nmi_handler(struct notifier_block *self,
39711 return ret;
39712 }
39713
39714-static struct notifier_block sh_dmae_nmi_notifier __read_mostly = {
39715+static struct notifier_block sh_dmae_nmi_notifier = {
39716 .notifier_call = sh_dmae_nmi_handler,
39717
39718 /* Run before NMI debug handler and KGDB */
39719diff --git a/drivers/edac/edac_device.c b/drivers/edac/edac_device.c
39720index 592af5f..bb1d583 100644
39721--- a/drivers/edac/edac_device.c
39722+++ b/drivers/edac/edac_device.c
39723@@ -477,9 +477,9 @@ void edac_device_reset_delay_period(struct edac_device_ctl_info *edac_dev,
39724 */
39725 int edac_device_alloc_index(void)
39726 {
39727- static atomic_t device_indexes = ATOMIC_INIT(0);
39728+ static atomic_unchecked_t device_indexes = ATOMIC_INIT(0);
39729
39730- return atomic_inc_return(&device_indexes) - 1;
39731+ return atomic_inc_return_unchecked(&device_indexes) - 1;
39732 }
39733 EXPORT_SYMBOL_GPL(edac_device_alloc_index);
39734
39735diff --git a/drivers/edac/edac_mc_sysfs.c b/drivers/edac/edac_mc_sysfs.c
39736index a6cd361..7bdbf53 100644
39737--- a/drivers/edac/edac_mc_sysfs.c
39738+++ b/drivers/edac/edac_mc_sysfs.c
39739@@ -154,7 +154,7 @@ static const char * const edac_caps[] = {
39740 struct dev_ch_attribute {
39741 struct device_attribute attr;
39742 int channel;
39743-};
39744+} __do_const;
39745
39746 #define DEVICE_CHANNEL(_name, _mode, _show, _store, _var) \
39747 struct dev_ch_attribute dev_attr_legacy_##_name = \
39748@@ -1011,14 +1011,16 @@ int edac_create_sysfs_mci_device(struct mem_ctl_info *mci)
39749 }
39750
39751 if (mci->set_sdram_scrub_rate || mci->get_sdram_scrub_rate) {
39752+ pax_open_kernel();
39753 if (mci->get_sdram_scrub_rate) {
39754- dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO;
39755- dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show;
39756+ *(umode_t *)&dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO;
39757+ *(void **)&dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show;
39758 }
39759 if (mci->set_sdram_scrub_rate) {
39760- dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR;
39761- dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store;
39762+ *(umode_t *)&dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR;
39763+ *(void **)&dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store;
39764 }
39765+ pax_close_kernel();
39766 err = device_create_file(&mci->dev,
39767 &dev_attr_sdram_scrub_rate);
39768 if (err) {
39769diff --git a/drivers/edac/edac_pci.c b/drivers/edac/edac_pci.c
39770index 2cf44b4d..6dd2dc7 100644
39771--- a/drivers/edac/edac_pci.c
39772+++ b/drivers/edac/edac_pci.c
39773@@ -29,7 +29,7 @@
39774
39775 static DEFINE_MUTEX(edac_pci_ctls_mutex);
39776 static LIST_HEAD(edac_pci_list);
39777-static atomic_t pci_indexes = ATOMIC_INIT(0);
39778+static atomic_unchecked_t pci_indexes = ATOMIC_INIT(0);
39779
39780 /*
39781 * edac_pci_alloc_ctl_info
39782@@ -315,7 +315,7 @@ EXPORT_SYMBOL_GPL(edac_pci_reset_delay_period);
39783 */
39784 int edac_pci_alloc_index(void)
39785 {
39786- return atomic_inc_return(&pci_indexes) - 1;
39787+ return atomic_inc_return_unchecked(&pci_indexes) - 1;
39788 }
39789 EXPORT_SYMBOL_GPL(edac_pci_alloc_index);
39790
39791diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
39792index e8658e4..22746d6 100644
39793--- a/drivers/edac/edac_pci_sysfs.c
39794+++ b/drivers/edac/edac_pci_sysfs.c
39795@@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
39796 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
39797 static int edac_pci_poll_msec = 1000; /* one second workq period */
39798
39799-static atomic_t pci_parity_count = ATOMIC_INIT(0);
39800-static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
39801+static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
39802+static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
39803
39804 static struct kobject *edac_pci_top_main_kobj;
39805 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
39806@@ -235,7 +235,7 @@ struct edac_pci_dev_attribute {
39807 void *value;
39808 ssize_t(*show) (void *, char *);
39809 ssize_t(*store) (void *, const char *, size_t);
39810-};
39811+} __do_const;
39812
39813 /* Set of show/store abstract level functions for PCI Parity object */
39814 static ssize_t edac_pci_dev_show(struct kobject *kobj, struct attribute *attr,
39815@@ -579,7 +579,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39816 edac_printk(KERN_CRIT, EDAC_PCI,
39817 "Signaled System Error on %s\n",
39818 pci_name(dev));
39819- atomic_inc(&pci_nonparity_count);
39820+ atomic_inc_unchecked(&pci_nonparity_count);
39821 }
39822
39823 if (status & (PCI_STATUS_PARITY)) {
39824@@ -587,7 +587,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39825 "Master Data Parity Error on %s\n",
39826 pci_name(dev));
39827
39828- atomic_inc(&pci_parity_count);
39829+ atomic_inc_unchecked(&pci_parity_count);
39830 }
39831
39832 if (status & (PCI_STATUS_DETECTED_PARITY)) {
39833@@ -595,7 +595,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39834 "Detected Parity Error on %s\n",
39835 pci_name(dev));
39836
39837- atomic_inc(&pci_parity_count);
39838+ atomic_inc_unchecked(&pci_parity_count);
39839 }
39840 }
39841
39842@@ -618,7 +618,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39843 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
39844 "Signaled System Error on %s\n",
39845 pci_name(dev));
39846- atomic_inc(&pci_nonparity_count);
39847+ atomic_inc_unchecked(&pci_nonparity_count);
39848 }
39849
39850 if (status & (PCI_STATUS_PARITY)) {
39851@@ -626,7 +626,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39852 "Master Data Parity Error on "
39853 "%s\n", pci_name(dev));
39854
39855- atomic_inc(&pci_parity_count);
39856+ atomic_inc_unchecked(&pci_parity_count);
39857 }
39858
39859 if (status & (PCI_STATUS_DETECTED_PARITY)) {
39860@@ -634,7 +634,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39861 "Detected Parity Error on %s\n",
39862 pci_name(dev));
39863
39864- atomic_inc(&pci_parity_count);
39865+ atomic_inc_unchecked(&pci_parity_count);
39866 }
39867 }
39868 }
39869@@ -672,7 +672,7 @@ void edac_pci_do_parity_check(void)
39870 if (!check_pci_errors)
39871 return;
39872
39873- before_count = atomic_read(&pci_parity_count);
39874+ before_count = atomic_read_unchecked(&pci_parity_count);
39875
39876 /* scan all PCI devices looking for a Parity Error on devices and
39877 * bridges.
39878@@ -684,7 +684,7 @@ void edac_pci_do_parity_check(void)
39879 /* Only if operator has selected panic on PCI Error */
39880 if (edac_pci_get_panic_on_pe()) {
39881 /* If the count is different 'after' from 'before' */
39882- if (before_count != atomic_read(&pci_parity_count))
39883+ if (before_count != atomic_read_unchecked(&pci_parity_count))
39884 panic("EDAC: PCI Parity Error");
39885 }
39886 }
39887diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
39888index 51b7e3a..aa8a3e8 100644
39889--- a/drivers/edac/mce_amd.h
39890+++ b/drivers/edac/mce_amd.h
39891@@ -77,7 +77,7 @@ struct amd_decoder_ops {
39892 bool (*mc0_mce)(u16, u8);
39893 bool (*mc1_mce)(u16, u8);
39894 bool (*mc2_mce)(u16, u8);
39895-};
39896+} __no_const;
39897
39898 void amd_report_gart_errors(bool);
39899 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
39900diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
39901index 57ea7f4..af06b76 100644
39902--- a/drivers/firewire/core-card.c
39903+++ b/drivers/firewire/core-card.c
39904@@ -528,9 +528,9 @@ void fw_card_initialize(struct fw_card *card,
39905 const struct fw_card_driver *driver,
39906 struct device *device)
39907 {
39908- static atomic_t index = ATOMIC_INIT(-1);
39909+ static atomic_unchecked_t index = ATOMIC_INIT(-1);
39910
39911- card->index = atomic_inc_return(&index);
39912+ card->index = atomic_inc_return_unchecked(&index);
39913 card->driver = driver;
39914 card->device = device;
39915 card->current_tlabel = 0;
39916@@ -680,7 +680,7 @@ EXPORT_SYMBOL_GPL(fw_card_release);
39917
39918 void fw_core_remove_card(struct fw_card *card)
39919 {
39920- struct fw_card_driver dummy_driver = dummy_driver_template;
39921+ fw_card_driver_no_const dummy_driver = dummy_driver_template;
39922
39923 card->driver->update_phy_reg(card, 4,
39924 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
39925diff --git a/drivers/firewire/core-device.c b/drivers/firewire/core-device.c
39926index 2c6d5e1..a2cca6b 100644
39927--- a/drivers/firewire/core-device.c
39928+++ b/drivers/firewire/core-device.c
39929@@ -253,7 +253,7 @@ EXPORT_SYMBOL(fw_device_enable_phys_dma);
39930 struct config_rom_attribute {
39931 struct device_attribute attr;
39932 u32 key;
39933-};
39934+} __do_const;
39935
39936 static ssize_t show_immediate(struct device *dev,
39937 struct device_attribute *dattr, char *buf)
39938diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
39939index eb6935c..3cc2bfa 100644
39940--- a/drivers/firewire/core-transaction.c
39941+++ b/drivers/firewire/core-transaction.c
39942@@ -38,6 +38,7 @@
39943 #include <linux/timer.h>
39944 #include <linux/types.h>
39945 #include <linux/workqueue.h>
39946+#include <linux/sched.h>
39947
39948 #include <asm/byteorder.h>
39949
39950diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
39951index e1480ff6..1a429bd 100644
39952--- a/drivers/firewire/core.h
39953+++ b/drivers/firewire/core.h
39954@@ -111,6 +111,7 @@ struct fw_card_driver {
39955
39956 int (*stop_iso)(struct fw_iso_context *ctx);
39957 };
39958+typedef struct fw_card_driver __no_const fw_card_driver_no_const;
39959
39960 void fw_card_initialize(struct fw_card *card,
39961 const struct fw_card_driver *driver, struct device *device);
39962diff --git a/drivers/firewire/ohci.c b/drivers/firewire/ohci.c
39963index a66a321..f6caf20 100644
39964--- a/drivers/firewire/ohci.c
39965+++ b/drivers/firewire/ohci.c
39966@@ -2056,10 +2056,12 @@ static void bus_reset_work(struct work_struct *work)
39967 be32_to_cpu(ohci->next_header));
39968 }
39969
39970+#ifndef CONFIG_GRKERNSEC
39971 if (param_remote_dma) {
39972 reg_write(ohci, OHCI1394_PhyReqFilterHiSet, ~0);
39973 reg_write(ohci, OHCI1394_PhyReqFilterLoSet, ~0);
39974 }
39975+#endif
39976
39977 spin_unlock_irq(&ohci->lock);
39978
39979@@ -2591,8 +2593,10 @@ static int ohci_enable_phys_dma(struct fw_card *card,
39980 unsigned long flags;
39981 int n, ret = 0;
39982
39983+#ifndef CONFIG_GRKERNSEC
39984 if (param_remote_dma)
39985 return 0;
39986+#endif
39987
39988 /*
39989 * FIXME: Make sure this bitmask is cleared when we clear the busReset
39990diff --git a/drivers/firmware/dmi-id.c b/drivers/firmware/dmi-id.c
39991index 94a58a0..f5eba42 100644
39992--- a/drivers/firmware/dmi-id.c
39993+++ b/drivers/firmware/dmi-id.c
39994@@ -16,7 +16,7 @@
39995 struct dmi_device_attribute{
39996 struct device_attribute dev_attr;
39997 int field;
39998-};
39999+} __do_const;
40000 #define to_dmi_dev_attr(_dev_attr) \
40001 container_of(_dev_attr, struct dmi_device_attribute, dev_attr)
40002
40003diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
40004index 17afc51..0ef90cd 100644
40005--- a/drivers/firmware/dmi_scan.c
40006+++ b/drivers/firmware/dmi_scan.c
40007@@ -835,7 +835,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
40008 if (buf == NULL)
40009 return -1;
40010
40011- dmi_table(buf, dmi_len, dmi_num, decode, private_data);
40012+ dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
40013
40014 dmi_unmap(buf);
40015 return 0;
40016diff --git a/drivers/firmware/efi/cper.c b/drivers/firmware/efi/cper.c
40017index 5b53d61..72cee96 100644
40018--- a/drivers/firmware/efi/cper.c
40019+++ b/drivers/firmware/efi/cper.c
40020@@ -44,12 +44,12 @@ static char rcd_decode_str[CPER_REC_LEN];
40021 */
40022 u64 cper_next_record_id(void)
40023 {
40024- static atomic64_t seq;
40025+ static atomic64_unchecked_t seq;
40026
40027- if (!atomic64_read(&seq))
40028- atomic64_set(&seq, ((u64)get_seconds()) << 32);
40029+ if (!atomic64_read_unchecked(&seq))
40030+ atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
40031
40032- return atomic64_inc_return(&seq);
40033+ return atomic64_inc_return_unchecked(&seq);
40034 }
40035 EXPORT_SYMBOL_GPL(cper_next_record_id);
40036
40037diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c
40038index 8590099..d83627a 100644
40039--- a/drivers/firmware/efi/efi.c
40040+++ b/drivers/firmware/efi/efi.c
40041@@ -148,14 +148,16 @@ static struct attribute_group efi_subsys_attr_group = {
40042 };
40043
40044 static struct efivars generic_efivars;
40045-static struct efivar_operations generic_ops;
40046+static efivar_operations_no_const generic_ops __read_only;
40047
40048 static int generic_ops_register(void)
40049 {
40050- generic_ops.get_variable = efi.get_variable;
40051- generic_ops.set_variable = efi.set_variable;
40052- generic_ops.get_next_variable = efi.get_next_variable;
40053- generic_ops.query_variable_store = efi_query_variable_store;
40054+ pax_open_kernel();
40055+ *(void **)&generic_ops.get_variable = efi.get_variable;
40056+ *(void **)&generic_ops.set_variable = efi.set_variable;
40057+ *(void **)&generic_ops.get_next_variable = efi.get_next_variable;
40058+ *(void **)&generic_ops.query_variable_store = efi_query_variable_store;
40059+ pax_close_kernel();
40060
40061 return efivars_register(&generic_efivars, &generic_ops, efi_kobj);
40062 }
40063diff --git a/drivers/firmware/efi/efivars.c b/drivers/firmware/efi/efivars.c
40064index f256ecd..387dcb1 100644
40065--- a/drivers/firmware/efi/efivars.c
40066+++ b/drivers/firmware/efi/efivars.c
40067@@ -589,7 +589,7 @@ efivar_create_sysfs_entry(struct efivar_entry *new_var)
40068 static int
40069 create_efivars_bin_attributes(void)
40070 {
40071- struct bin_attribute *attr;
40072+ bin_attribute_no_const *attr;
40073 int error;
40074
40075 /* new_var */
40076diff --git a/drivers/firmware/google/memconsole.c b/drivers/firmware/google/memconsole.c
40077index 2f569aa..c95f4fb 100644
40078--- a/drivers/firmware/google/memconsole.c
40079+++ b/drivers/firmware/google/memconsole.c
40080@@ -155,7 +155,10 @@ static int __init memconsole_init(void)
40081 if (!found_memconsole())
40082 return -ENODEV;
40083
40084- memconsole_bin_attr.size = memconsole_length;
40085+ pax_open_kernel();
40086+ *(size_t *)&memconsole_bin_attr.size = memconsole_length;
40087+ pax_close_kernel();
40088+
40089 return sysfs_create_bin_file(firmware_kobj, &memconsole_bin_attr);
40090 }
40091
40092diff --git a/drivers/gpio/gpio-em.c b/drivers/gpio/gpio-em.c
40093index fe49ec3..1ade794 100644
40094--- a/drivers/gpio/gpio-em.c
40095+++ b/drivers/gpio/gpio-em.c
40096@@ -278,7 +278,7 @@ static int em_gio_probe(struct platform_device *pdev)
40097 struct em_gio_priv *p;
40098 struct resource *io[2], *irq[2];
40099 struct gpio_chip *gpio_chip;
40100- struct irq_chip *irq_chip;
40101+ irq_chip_no_const *irq_chip;
40102 const char *name = dev_name(&pdev->dev);
40103 int ret;
40104
40105diff --git a/drivers/gpio/gpio-ich.c b/drivers/gpio/gpio-ich.c
40106index 3784e81..73637b5 100644
40107--- a/drivers/gpio/gpio-ich.c
40108+++ b/drivers/gpio/gpio-ich.c
40109@@ -94,7 +94,7 @@ struct ichx_desc {
40110 * this option allows driver caching written output values
40111 */
40112 bool use_outlvl_cache;
40113-};
40114+} __do_const;
40115
40116 static struct {
40117 spinlock_t lock;
40118diff --git a/drivers/gpio/gpio-omap.c b/drivers/gpio/gpio-omap.c
40119index 415682f..08438b8 100644
40120--- a/drivers/gpio/gpio-omap.c
40121+++ b/drivers/gpio/gpio-omap.c
40122@@ -1162,7 +1162,7 @@ static int omap_gpio_probe(struct platform_device *pdev)
40123 const struct omap_gpio_platform_data *pdata;
40124 struct resource *res;
40125 struct gpio_bank *bank;
40126- struct irq_chip *irqc;
40127+ irq_chip_no_const *irqc;
40128 int ret;
40129
40130 match = of_match_device(of_match_ptr(omap_gpio_match), dev);
40131diff --git a/drivers/gpio/gpio-rcar.c b/drivers/gpio/gpio-rcar.c
40132index bf6c094..6573caf 100644
40133--- a/drivers/gpio/gpio-rcar.c
40134+++ b/drivers/gpio/gpio-rcar.c
40135@@ -357,7 +357,7 @@ static int gpio_rcar_probe(struct platform_device *pdev)
40136 struct gpio_rcar_priv *p;
40137 struct resource *io, *irq;
40138 struct gpio_chip *gpio_chip;
40139- struct irq_chip *irq_chip;
40140+ irq_chip_no_const *irq_chip;
40141 struct device *dev = &pdev->dev;
40142 const char *name = dev_name(dev);
40143 int ret;
40144diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
40145index dbf28fa..04dad4e 100644
40146--- a/drivers/gpio/gpio-vr41xx.c
40147+++ b/drivers/gpio/gpio-vr41xx.c
40148@@ -224,7 +224,7 @@ static int giu_get_irq(unsigned int irq)
40149 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
40150 maskl, pendl, maskh, pendh);
40151
40152- atomic_inc(&irq_err_count);
40153+ atomic_inc_unchecked(&irq_err_count);
40154
40155 return -EINVAL;
40156 }
40157diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
40158index e8e98ca..10f416e 100644
40159--- a/drivers/gpio/gpiolib.c
40160+++ b/drivers/gpio/gpiolib.c
40161@@ -537,8 +537,10 @@ static void gpiochip_irqchip_remove(struct gpio_chip *gpiochip)
40162 }
40163
40164 if (gpiochip->irqchip) {
40165- gpiochip->irqchip->irq_request_resources = NULL;
40166- gpiochip->irqchip->irq_release_resources = NULL;
40167+ pax_open_kernel();
40168+ *(void **)&gpiochip->irqchip->irq_request_resources = NULL;
40169+ *(void **)&gpiochip->irqchip->irq_release_resources = NULL;
40170+ pax_close_kernel();
40171 gpiochip->irqchip = NULL;
40172 }
40173 }
40174@@ -604,8 +606,11 @@ int gpiochip_irqchip_add(struct gpio_chip *gpiochip,
40175 gpiochip->irqchip = NULL;
40176 return -EINVAL;
40177 }
40178- irqchip->irq_request_resources = gpiochip_irq_reqres;
40179- irqchip->irq_release_resources = gpiochip_irq_relres;
40180+
40181+ pax_open_kernel();
40182+ *(void **)&irqchip->irq_request_resources = gpiochip_irq_reqres;
40183+ *(void **)&irqchip->irq_release_resources = gpiochip_irq_relres;
40184+ pax_close_kernel();
40185
40186 /*
40187 * Prepare the mapping since the irqchip shall be orthogonal to
40188diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c
40189index e79c8d3..a9370bc 100644
40190--- a/drivers/gpu/drm/drm_crtc.c
40191+++ b/drivers/gpu/drm/drm_crtc.c
40192@@ -3900,7 +3900,7 @@ int drm_mode_getproperty_ioctl(struct drm_device *dev,
40193 goto done;
40194 }
40195
40196- if (copy_to_user(&enum_ptr[copied].name,
40197+ if (copy_to_user(enum_ptr[copied].name,
40198 &prop_enum->name, DRM_PROP_NAME_LEN)) {
40199 ret = -EFAULT;
40200 goto done;
40201diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
40202index bc3da32..7289357 100644
40203--- a/drivers/gpu/drm/drm_drv.c
40204+++ b/drivers/gpu/drm/drm_drv.c
40205@@ -443,7 +443,7 @@ void drm_unplug_dev(struct drm_device *dev)
40206
40207 drm_device_set_unplugged(dev);
40208
40209- if (dev->open_count == 0) {
40210+ if (local_read(&dev->open_count) == 0) {
40211 drm_put_dev(dev);
40212 }
40213 mutex_unlock(&drm_global_mutex);
40214diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
40215index ed7bc68..0d536af 100644
40216--- a/drivers/gpu/drm/drm_fops.c
40217+++ b/drivers/gpu/drm/drm_fops.c
40218@@ -89,7 +89,7 @@ int drm_open(struct inode *inode, struct file *filp)
40219 return PTR_ERR(minor);
40220
40221 dev = minor->dev;
40222- if (!dev->open_count++)
40223+ if (local_inc_return(&dev->open_count) == 1)
40224 need_setup = 1;
40225
40226 /* share address_space across all char-devs of a single device */
40227@@ -106,7 +106,7 @@ int drm_open(struct inode *inode, struct file *filp)
40228 return 0;
40229
40230 err_undo:
40231- dev->open_count--;
40232+ local_dec(&dev->open_count);
40233 drm_minor_release(minor);
40234 return retcode;
40235 }
40236@@ -376,7 +376,7 @@ int drm_release(struct inode *inode, struct file *filp)
40237
40238 mutex_lock(&drm_global_mutex);
40239
40240- DRM_DEBUG("open_count = %d\n", dev->open_count);
40241+ DRM_DEBUG("open_count = %ld\n", local_read(&dev->open_count));
40242
40243 mutex_lock(&dev->struct_mutex);
40244 list_del(&file_priv->lhead);
40245@@ -389,10 +389,10 @@ int drm_release(struct inode *inode, struct file *filp)
40246 * Begin inline drm_release
40247 */
40248
40249- DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
40250+ DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %ld\n",
40251 task_pid_nr(current),
40252 (long)old_encode_dev(file_priv->minor->kdev->devt),
40253- dev->open_count);
40254+ local_read(&dev->open_count));
40255
40256 /* Release any auth tokens that might point to this file_priv,
40257 (do that under the drm_global_mutex) */
40258@@ -465,7 +465,7 @@ int drm_release(struct inode *inode, struct file *filp)
40259 * End inline drm_release
40260 */
40261
40262- if (!--dev->open_count) {
40263+ if (local_dec_and_test(&dev->open_count)) {
40264 retcode = drm_lastclose(dev);
40265 if (drm_device_is_unplugged(dev))
40266 drm_put_dev(dev);
40267diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
40268index 3d2e91c..d31c4c9 100644
40269--- a/drivers/gpu/drm/drm_global.c
40270+++ b/drivers/gpu/drm/drm_global.c
40271@@ -36,7 +36,7 @@
40272 struct drm_global_item {
40273 struct mutex mutex;
40274 void *object;
40275- int refcount;
40276+ atomic_t refcount;
40277 };
40278
40279 static struct drm_global_item glob[DRM_GLOBAL_NUM];
40280@@ -49,7 +49,7 @@ void drm_global_init(void)
40281 struct drm_global_item *item = &glob[i];
40282 mutex_init(&item->mutex);
40283 item->object = NULL;
40284- item->refcount = 0;
40285+ atomic_set(&item->refcount, 0);
40286 }
40287 }
40288
40289@@ -59,7 +59,7 @@ void drm_global_release(void)
40290 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
40291 struct drm_global_item *item = &glob[i];
40292 BUG_ON(item->object != NULL);
40293- BUG_ON(item->refcount != 0);
40294+ BUG_ON(atomic_read(&item->refcount) != 0);
40295 }
40296 }
40297
40298@@ -69,7 +69,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
40299 struct drm_global_item *item = &glob[ref->global_type];
40300
40301 mutex_lock(&item->mutex);
40302- if (item->refcount == 0) {
40303+ if (atomic_read(&item->refcount) == 0) {
40304 item->object = kzalloc(ref->size, GFP_KERNEL);
40305 if (unlikely(item->object == NULL)) {
40306 ret = -ENOMEM;
40307@@ -82,7 +82,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
40308 goto out_err;
40309
40310 }
40311- ++item->refcount;
40312+ atomic_inc(&item->refcount);
40313 ref->object = item->object;
40314 mutex_unlock(&item->mutex);
40315 return 0;
40316@@ -98,9 +98,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
40317 struct drm_global_item *item = &glob[ref->global_type];
40318
40319 mutex_lock(&item->mutex);
40320- BUG_ON(item->refcount == 0);
40321+ BUG_ON(atomic_read(&item->refcount) == 0);
40322 BUG_ON(ref->object != item->object);
40323- if (--item->refcount == 0) {
40324+ if (atomic_dec_and_test(&item->refcount)) {
40325 ref->release(ref);
40326 item->object = NULL;
40327 }
40328diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
40329index 51efebd..2b70935 100644
40330--- a/drivers/gpu/drm/drm_info.c
40331+++ b/drivers/gpu/drm/drm_info.c
40332@@ -76,10 +76,13 @@ int drm_vm_info(struct seq_file *m, void *data)
40333 struct drm_local_map *map;
40334 struct drm_map_list *r_list;
40335
40336- /* Hardcoded from _DRM_FRAME_BUFFER,
40337- _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
40338- _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
40339- const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
40340+ static const char * const types[] = {
40341+ [_DRM_FRAME_BUFFER] = "FB",
40342+ [_DRM_REGISTERS] = "REG",
40343+ [_DRM_SHM] = "SHM",
40344+ [_DRM_AGP] = "AGP",
40345+ [_DRM_SCATTER_GATHER] = "SG",
40346+ [_DRM_CONSISTENT] = "PCI"};
40347 const char *type;
40348 int i;
40349
40350@@ -90,7 +93,7 @@ int drm_vm_info(struct seq_file *m, void *data)
40351 map = r_list->map;
40352 if (!map)
40353 continue;
40354- if (map->type < 0 || map->type > 5)
40355+ if (map->type >= ARRAY_SIZE(types))
40356 type = "??";
40357 else
40358 type = types[map->type];
40359diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
40360index 2f4c4343..dd12cd2 100644
40361--- a/drivers/gpu/drm/drm_ioc32.c
40362+++ b/drivers/gpu/drm/drm_ioc32.c
40363@@ -457,7 +457,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
40364 request = compat_alloc_user_space(nbytes);
40365 if (!access_ok(VERIFY_WRITE, request, nbytes))
40366 return -EFAULT;
40367- list = (struct drm_buf_desc *) (request + 1);
40368+ list = (struct drm_buf_desc __user *) (request + 1);
40369
40370 if (__put_user(count, &request->count)
40371 || __put_user(list, &request->list))
40372@@ -518,7 +518,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
40373 request = compat_alloc_user_space(nbytes);
40374 if (!access_ok(VERIFY_WRITE, request, nbytes))
40375 return -EFAULT;
40376- list = (struct drm_buf_pub *) (request + 1);
40377+ list = (struct drm_buf_pub __user *) (request + 1);
40378
40379 if (__put_user(count, &request->count)
40380 || __put_user(list, &request->list))
40381@@ -1016,7 +1016,7 @@ static int compat_drm_wait_vblank(struct file *file, unsigned int cmd,
40382 return 0;
40383 }
40384
40385-drm_ioctl_compat_t *drm_compat_ioctls[] = {
40386+drm_ioctl_compat_t drm_compat_ioctls[] = {
40387 [DRM_IOCTL_NR(DRM_IOCTL_VERSION32)] = compat_drm_version,
40388 [DRM_IOCTL_NR(DRM_IOCTL_GET_UNIQUE32)] = compat_drm_getunique,
40389 [DRM_IOCTL_NR(DRM_IOCTL_GET_MAP32)] = compat_drm_getmap,
40390@@ -1062,7 +1062,6 @@ drm_ioctl_compat_t *drm_compat_ioctls[] = {
40391 long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40392 {
40393 unsigned int nr = DRM_IOCTL_NR(cmd);
40394- drm_ioctl_compat_t *fn;
40395 int ret;
40396
40397 /* Assume that ioctls without an explicit compat routine will just
40398@@ -1072,10 +1071,8 @@ long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40399 if (nr >= ARRAY_SIZE(drm_compat_ioctls))
40400 return drm_ioctl(filp, cmd, arg);
40401
40402- fn = drm_compat_ioctls[nr];
40403-
40404- if (fn != NULL)
40405- ret = (*fn) (filp, cmd, arg);
40406+ if (drm_compat_ioctls[nr] != NULL)
40407+ ret = (*drm_compat_ioctls[nr]) (filp, cmd, arg);
40408 else
40409 ret = drm_ioctl(filp, cmd, arg);
40410
40411diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
40412index 00587a1..57a65ca 100644
40413--- a/drivers/gpu/drm/drm_ioctl.c
40414+++ b/drivers/gpu/drm/drm_ioctl.c
40415@@ -642,7 +642,7 @@ long drm_ioctl(struct file *filp,
40416 struct drm_file *file_priv = filp->private_data;
40417 struct drm_device *dev;
40418 const struct drm_ioctl_desc *ioctl = NULL;
40419- drm_ioctl_t *func;
40420+ drm_ioctl_no_const_t func;
40421 unsigned int nr = DRM_IOCTL_NR(cmd);
40422 int retcode = -EINVAL;
40423 char stack_kdata[128];
40424diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
40425index 93ec5dc..82acbaf 100644
40426--- a/drivers/gpu/drm/i810/i810_drv.h
40427+++ b/drivers/gpu/drm/i810/i810_drv.h
40428@@ -110,8 +110,8 @@ typedef struct drm_i810_private {
40429 int page_flipping;
40430
40431 wait_queue_head_t irq_queue;
40432- atomic_t irq_received;
40433- atomic_t irq_emitted;
40434+ atomic_unchecked_t irq_received;
40435+ atomic_unchecked_t irq_emitted;
40436
40437 int front_offset;
40438 } drm_i810_private_t;
40439diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
40440index 318ade9..1f5de55 100644
40441--- a/drivers/gpu/drm/i915/i915_dma.c
40442+++ b/drivers/gpu/drm/i915/i915_dma.c
40443@@ -1294,7 +1294,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
40444 * locking inversion with the driver load path. And the access here is
40445 * completely racy anyway. So don't bother with locking for now.
40446 */
40447- return dev->open_count == 0;
40448+ return local_read(&dev->open_count) == 0;
40449 }
40450
40451 static const struct vga_switcheroo_client_ops i915_switcheroo_ops = {
40452diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
40453index 1a0611b..dd1fbfc 100644
40454--- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
40455+++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
40456@@ -866,12 +866,12 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
40457 static int
40458 validate_exec_list(struct drm_device *dev,
40459 struct drm_i915_gem_exec_object2 *exec,
40460- int count)
40461+ unsigned int count)
40462 {
40463 unsigned relocs_total = 0;
40464 unsigned relocs_max = UINT_MAX / sizeof(struct drm_i915_gem_relocation_entry);
40465 unsigned invalid_flags;
40466- int i;
40467+ unsigned int i;
40468
40469 invalid_flags = __EXEC_OBJECT_UNKNOWN_FLAGS;
40470 if (USES_FULL_PPGTT(dev))
40471diff --git a/drivers/gpu/drm/i915/i915_ioc32.c b/drivers/gpu/drm/i915/i915_ioc32.c
40472index 2e0613e..a8b94d9 100644
40473--- a/drivers/gpu/drm/i915/i915_ioc32.c
40474+++ b/drivers/gpu/drm/i915/i915_ioc32.c
40475@@ -181,7 +181,7 @@ static int compat_i915_alloc(struct file *file, unsigned int cmd,
40476 (unsigned long)request);
40477 }
40478
40479-static drm_ioctl_compat_t *i915_compat_ioctls[] = {
40480+static drm_ioctl_compat_t i915_compat_ioctls[] = {
40481 [DRM_I915_BATCHBUFFER] = compat_i915_batchbuffer,
40482 [DRM_I915_CMDBUFFER] = compat_i915_cmdbuffer,
40483 [DRM_I915_GETPARAM] = compat_i915_getparam,
40484@@ -202,18 +202,15 @@ static drm_ioctl_compat_t *i915_compat_ioctls[] = {
40485 long i915_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40486 {
40487 unsigned int nr = DRM_IOCTL_NR(cmd);
40488- drm_ioctl_compat_t *fn = NULL;
40489 int ret;
40490
40491 if (nr < DRM_COMMAND_BASE)
40492 return drm_compat_ioctl(filp, cmd, arg);
40493
40494- if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(i915_compat_ioctls))
40495- fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
40496-
40497- if (fn != NULL)
40498+ if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(i915_compat_ioctls)) {
40499+ drm_ioctl_compat_t fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
40500 ret = (*fn) (filp, cmd, arg);
40501- else
40502+ } else
40503 ret = drm_ioctl(filp, cmd, arg);
40504
40505 return ret;
40506diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
40507index 9cb5c95..9228666 100644
40508--- a/drivers/gpu/drm/i915/intel_display.c
40509+++ b/drivers/gpu/drm/i915/intel_display.c
40510@@ -12811,13 +12811,13 @@ struct intel_quirk {
40511 int subsystem_vendor;
40512 int subsystem_device;
40513 void (*hook)(struct drm_device *dev);
40514-};
40515+} __do_const;
40516
40517 /* For systems that don't have a meaningful PCI subdevice/subvendor ID */
40518 struct intel_dmi_quirk {
40519 void (*hook)(struct drm_device *dev);
40520 const struct dmi_system_id (*dmi_id_list)[];
40521-};
40522+} __do_const;
40523
40524 static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
40525 {
40526@@ -12825,18 +12825,20 @@ static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
40527 return 1;
40528 }
40529
40530-static const struct intel_dmi_quirk intel_dmi_quirks[] = {
40531+static const struct dmi_system_id intel_dmi_quirks_table[] = {
40532 {
40533- .dmi_id_list = &(const struct dmi_system_id[]) {
40534- {
40535- .callback = intel_dmi_reverse_brightness,
40536- .ident = "NCR Corporation",
40537- .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
40538- DMI_MATCH(DMI_PRODUCT_NAME, ""),
40539- },
40540- },
40541- { } /* terminating entry */
40542+ .callback = intel_dmi_reverse_brightness,
40543+ .ident = "NCR Corporation",
40544+ .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
40545+ DMI_MATCH(DMI_PRODUCT_NAME, ""),
40546 },
40547+ },
40548+ { } /* terminating entry */
40549+};
40550+
40551+static const struct intel_dmi_quirk intel_dmi_quirks[] = {
40552+ {
40553+ .dmi_id_list = &intel_dmi_quirks_table,
40554 .hook = quirk_invert_brightness,
40555 },
40556 };
40557diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
40558index b4a2014..219ab78 100644
40559--- a/drivers/gpu/drm/mga/mga_drv.h
40560+++ b/drivers/gpu/drm/mga/mga_drv.h
40561@@ -122,9 +122,9 @@ typedef struct drm_mga_private {
40562 u32 clear_cmd;
40563 u32 maccess;
40564
40565- atomic_t vbl_received; /**< Number of vblanks received. */
40566+ atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
40567 wait_queue_head_t fence_queue;
40568- atomic_t last_fence_retired;
40569+ atomic_unchecked_t last_fence_retired;
40570 u32 next_fence_to_post;
40571
40572 unsigned int fb_cpp;
40573diff --git a/drivers/gpu/drm/mga/mga_ioc32.c b/drivers/gpu/drm/mga/mga_ioc32.c
40574index 729bfd5..ead8823 100644
40575--- a/drivers/gpu/drm/mga/mga_ioc32.c
40576+++ b/drivers/gpu/drm/mga/mga_ioc32.c
40577@@ -190,7 +190,7 @@ static int compat_mga_dma_bootstrap(struct file *file, unsigned int cmd,
40578 return 0;
40579 }
40580
40581-drm_ioctl_compat_t *mga_compat_ioctls[] = {
40582+drm_ioctl_compat_t mga_compat_ioctls[] = {
40583 [DRM_MGA_INIT] = compat_mga_init,
40584 [DRM_MGA_GETPARAM] = compat_mga_getparam,
40585 [DRM_MGA_DMA_BOOTSTRAP] = compat_mga_dma_bootstrap,
40586@@ -208,18 +208,15 @@ drm_ioctl_compat_t *mga_compat_ioctls[] = {
40587 long mga_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40588 {
40589 unsigned int nr = DRM_IOCTL_NR(cmd);
40590- drm_ioctl_compat_t *fn = NULL;
40591 int ret;
40592
40593 if (nr < DRM_COMMAND_BASE)
40594 return drm_compat_ioctl(filp, cmd, arg);
40595
40596- if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(mga_compat_ioctls))
40597- fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
40598-
40599- if (fn != NULL)
40600+ if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(mga_compat_ioctls)) {
40601+ drm_ioctl_compat_t fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
40602 ret = (*fn) (filp, cmd, arg);
40603- else
40604+ } else
40605 ret = drm_ioctl(filp, cmd, arg);
40606
40607 return ret;
40608diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
40609index 1b071b8..de8601a 100644
40610--- a/drivers/gpu/drm/mga/mga_irq.c
40611+++ b/drivers/gpu/drm/mga/mga_irq.c
40612@@ -43,7 +43,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
40613 if (crtc != 0)
40614 return 0;
40615
40616- return atomic_read(&dev_priv->vbl_received);
40617+ return atomic_read_unchecked(&dev_priv->vbl_received);
40618 }
40619
40620
40621@@ -59,7 +59,7 @@ irqreturn_t mga_driver_irq_handler(int irq, void *arg)
40622 /* VBLANK interrupt */
40623 if (status & MGA_VLINEPEN) {
40624 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
40625- atomic_inc(&dev_priv->vbl_received);
40626+ atomic_inc_unchecked(&dev_priv->vbl_received);
40627 drm_handle_vblank(dev, 0);
40628 handled = 1;
40629 }
40630@@ -78,7 +78,7 @@ irqreturn_t mga_driver_irq_handler(int irq, void *arg)
40631 if ((prim_start & ~0x03) != (prim_end & ~0x03))
40632 MGA_WRITE(MGA_PRIMEND, prim_end);
40633
40634- atomic_inc(&dev_priv->last_fence_retired);
40635+ atomic_inc_unchecked(&dev_priv->last_fence_retired);
40636 wake_up(&dev_priv->fence_queue);
40637 handled = 1;
40638 }
40639@@ -129,7 +129,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
40640 * using fences.
40641 */
40642 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * HZ,
40643- (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
40644+ (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
40645 - *sequence) <= (1 << 23)));
40646
40647 *sequence = cur_fence;
40648diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
40649index dae2c96..324dbe4 100644
40650--- a/drivers/gpu/drm/nouveau/nouveau_bios.c
40651+++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
40652@@ -963,7 +963,7 @@ static int parse_bit_tmds_tbl_entry(struct drm_device *dev, struct nvbios *bios,
40653 struct bit_table {
40654 const char id;
40655 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
40656-};
40657+} __no_const;
40658
40659 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
40660
40661diff --git a/drivers/gpu/drm/nouveau/nouveau_drm.h b/drivers/gpu/drm/nouveau/nouveau_drm.h
40662index 8ae36f2..1147a30 100644
40663--- a/drivers/gpu/drm/nouveau/nouveau_drm.h
40664+++ b/drivers/gpu/drm/nouveau/nouveau_drm.h
40665@@ -121,7 +121,6 @@ struct nouveau_drm {
40666 struct drm_global_reference mem_global_ref;
40667 struct ttm_bo_global_ref bo_global_ref;
40668 struct ttm_bo_device bdev;
40669- atomic_t validate_sequence;
40670 int (*move)(struct nouveau_channel *,
40671 struct ttm_buffer_object *,
40672 struct ttm_mem_reg *, struct ttm_mem_reg *);
40673diff --git a/drivers/gpu/drm/nouveau/nouveau_ioc32.c b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
40674index 462679a..88e32a7 100644
40675--- a/drivers/gpu/drm/nouveau/nouveau_ioc32.c
40676+++ b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
40677@@ -50,7 +50,7 @@ long nouveau_compat_ioctl(struct file *filp, unsigned int cmd,
40678 unsigned long arg)
40679 {
40680 unsigned int nr = DRM_IOCTL_NR(cmd);
40681- drm_ioctl_compat_t *fn = NULL;
40682+ drm_ioctl_compat_t fn = NULL;
40683 int ret;
40684
40685 if (nr < DRM_COMMAND_BASE)
40686diff --git a/drivers/gpu/drm/nouveau/nouveau_ttm.c b/drivers/gpu/drm/nouveau/nouveau_ttm.c
40687index 3d1cfcb..0542700 100644
40688--- a/drivers/gpu/drm/nouveau/nouveau_ttm.c
40689+++ b/drivers/gpu/drm/nouveau/nouveau_ttm.c
40690@@ -127,11 +127,11 @@ nouveau_vram_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
40691 }
40692
40693 const struct ttm_mem_type_manager_func nouveau_vram_manager = {
40694- nouveau_vram_manager_init,
40695- nouveau_vram_manager_fini,
40696- nouveau_vram_manager_new,
40697- nouveau_vram_manager_del,
40698- nouveau_vram_manager_debug
40699+ .init = nouveau_vram_manager_init,
40700+ .takedown = nouveau_vram_manager_fini,
40701+ .get_node = nouveau_vram_manager_new,
40702+ .put_node = nouveau_vram_manager_del,
40703+ .debug = nouveau_vram_manager_debug
40704 };
40705
40706 static int
40707@@ -195,11 +195,11 @@ nouveau_gart_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
40708 }
40709
40710 const struct ttm_mem_type_manager_func nouveau_gart_manager = {
40711- nouveau_gart_manager_init,
40712- nouveau_gart_manager_fini,
40713- nouveau_gart_manager_new,
40714- nouveau_gart_manager_del,
40715- nouveau_gart_manager_debug
40716+ .init = nouveau_gart_manager_init,
40717+ .takedown = nouveau_gart_manager_fini,
40718+ .get_node = nouveau_gart_manager_new,
40719+ .put_node = nouveau_gart_manager_del,
40720+ .debug = nouveau_gart_manager_debug
40721 };
40722
40723 /*XXX*/
40724@@ -268,11 +268,11 @@ nv04_gart_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
40725 }
40726
40727 const struct ttm_mem_type_manager_func nv04_gart_manager = {
40728- nv04_gart_manager_init,
40729- nv04_gart_manager_fini,
40730- nv04_gart_manager_new,
40731- nv04_gart_manager_del,
40732- nv04_gart_manager_debug
40733+ .init = nv04_gart_manager_init,
40734+ .takedown = nv04_gart_manager_fini,
40735+ .get_node = nv04_gart_manager_new,
40736+ .put_node = nv04_gart_manager_del,
40737+ .debug = nv04_gart_manager_debug
40738 };
40739
40740 int
40741diff --git a/drivers/gpu/drm/nouveau/nouveau_vga.c b/drivers/gpu/drm/nouveau/nouveau_vga.c
40742index c7592ec..dd45ebc 100644
40743--- a/drivers/gpu/drm/nouveau/nouveau_vga.c
40744+++ b/drivers/gpu/drm/nouveau/nouveau_vga.c
40745@@ -72,7 +72,7 @@ nouveau_switcheroo_can_switch(struct pci_dev *pdev)
40746 * locking inversion with the driver load path. And the access here is
40747 * completely racy anyway. So don't bother with locking for now.
40748 */
40749- return dev->open_count == 0;
40750+ return local_read(&dev->open_count) == 0;
40751 }
40752
40753 static const struct vga_switcheroo_client_ops
40754diff --git a/drivers/gpu/drm/qxl/qxl_cmd.c b/drivers/gpu/drm/qxl/qxl_cmd.c
40755index 9782364..89bd954 100644
40756--- a/drivers/gpu/drm/qxl/qxl_cmd.c
40757+++ b/drivers/gpu/drm/qxl/qxl_cmd.c
40758@@ -285,27 +285,27 @@ static int wait_for_io_cmd_user(struct qxl_device *qdev, uint8_t val, long port,
40759 int ret;
40760
40761 mutex_lock(&qdev->async_io_mutex);
40762- irq_num = atomic_read(&qdev->irq_received_io_cmd);
40763+ irq_num = atomic_read_unchecked(&qdev->irq_received_io_cmd);
40764 if (qdev->last_sent_io_cmd > irq_num) {
40765 if (intr)
40766 ret = wait_event_interruptible_timeout(qdev->io_cmd_event,
40767- atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40768+ atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40769 else
40770 ret = wait_event_timeout(qdev->io_cmd_event,
40771- atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40772+ atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40773 /* 0 is timeout, just bail the "hw" has gone away */
40774 if (ret <= 0)
40775 goto out;
40776- irq_num = atomic_read(&qdev->irq_received_io_cmd);
40777+ irq_num = atomic_read_unchecked(&qdev->irq_received_io_cmd);
40778 }
40779 outb(val, addr);
40780 qdev->last_sent_io_cmd = irq_num + 1;
40781 if (intr)
40782 ret = wait_event_interruptible_timeout(qdev->io_cmd_event,
40783- atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40784+ atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40785 else
40786 ret = wait_event_timeout(qdev->io_cmd_event,
40787- atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40788+ atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40789 out:
40790 if (ret > 0)
40791 ret = 0;
40792diff --git a/drivers/gpu/drm/qxl/qxl_debugfs.c b/drivers/gpu/drm/qxl/qxl_debugfs.c
40793index 6911b8c..89d6867 100644
40794--- a/drivers/gpu/drm/qxl/qxl_debugfs.c
40795+++ b/drivers/gpu/drm/qxl/qxl_debugfs.c
40796@@ -42,10 +42,10 @@ qxl_debugfs_irq_received(struct seq_file *m, void *data)
40797 struct drm_info_node *node = (struct drm_info_node *) m->private;
40798 struct qxl_device *qdev = node->minor->dev->dev_private;
40799
40800- seq_printf(m, "%d\n", atomic_read(&qdev->irq_received));
40801- seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_display));
40802- seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_cursor));
40803- seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_io_cmd));
40804+ seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received));
40805+ seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_display));
40806+ seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_cursor));
40807+ seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_io_cmd));
40808 seq_printf(m, "%d\n", qdev->irq_received_error);
40809 return 0;
40810 }
40811diff --git a/drivers/gpu/drm/qxl/qxl_drv.h b/drivers/gpu/drm/qxl/qxl_drv.h
40812index 7c6cafe..460f542 100644
40813--- a/drivers/gpu/drm/qxl/qxl_drv.h
40814+++ b/drivers/gpu/drm/qxl/qxl_drv.h
40815@@ -290,10 +290,10 @@ struct qxl_device {
40816 unsigned int last_sent_io_cmd;
40817
40818 /* interrupt handling */
40819- atomic_t irq_received;
40820- atomic_t irq_received_display;
40821- atomic_t irq_received_cursor;
40822- atomic_t irq_received_io_cmd;
40823+ atomic_unchecked_t irq_received;
40824+ atomic_unchecked_t irq_received_display;
40825+ atomic_unchecked_t irq_received_cursor;
40826+ atomic_unchecked_t irq_received_io_cmd;
40827 unsigned irq_received_error;
40828 wait_queue_head_t display_event;
40829 wait_queue_head_t cursor_event;
40830diff --git a/drivers/gpu/drm/qxl/qxl_ioctl.c b/drivers/gpu/drm/qxl/qxl_ioctl.c
40831index b110883..dd06418 100644
40832--- a/drivers/gpu/drm/qxl/qxl_ioctl.c
40833+++ b/drivers/gpu/drm/qxl/qxl_ioctl.c
40834@@ -181,7 +181,7 @@ static int qxl_process_single_command(struct qxl_device *qdev,
40835
40836 /* TODO copy slow path code from i915 */
40837 fb_cmd = qxl_bo_kmap_atomic_page(qdev, cmd_bo, (release->release_offset & PAGE_SIZE));
40838- 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);
40839+ 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);
40840
40841 {
40842 struct qxl_drawable *draw = fb_cmd;
40843@@ -201,7 +201,7 @@ static int qxl_process_single_command(struct qxl_device *qdev,
40844 struct drm_qxl_reloc reloc;
40845
40846 if (copy_from_user(&reloc,
40847- &((struct drm_qxl_reloc *)(uintptr_t)cmd->relocs)[i],
40848+ &((struct drm_qxl_reloc __force_user *)(uintptr_t)cmd->relocs)[i],
40849 sizeof(reloc))) {
40850 ret = -EFAULT;
40851 goto out_free_bos;
40852@@ -294,10 +294,10 @@ static int qxl_execbuffer_ioctl(struct drm_device *dev, void *data,
40853
40854 for (cmd_num = 0; cmd_num < execbuffer->commands_num; ++cmd_num) {
40855
40856- struct drm_qxl_command *commands =
40857- (struct drm_qxl_command *)(uintptr_t)execbuffer->commands;
40858+ struct drm_qxl_command __user *commands =
40859+ (struct drm_qxl_command __user *)(uintptr_t)execbuffer->commands;
40860
40861- if (copy_from_user(&user_cmd, &commands[cmd_num],
40862+ if (copy_from_user(&user_cmd, (struct drm_qxl_command __force_user *)&commands[cmd_num],
40863 sizeof(user_cmd)))
40864 return -EFAULT;
40865
40866diff --git a/drivers/gpu/drm/qxl/qxl_irq.c b/drivers/gpu/drm/qxl/qxl_irq.c
40867index 0bf1e20..42a7310 100644
40868--- a/drivers/gpu/drm/qxl/qxl_irq.c
40869+++ b/drivers/gpu/drm/qxl/qxl_irq.c
40870@@ -36,19 +36,19 @@ irqreturn_t qxl_irq_handler(int irq, void *arg)
40871 if (!pending)
40872 return IRQ_NONE;
40873
40874- atomic_inc(&qdev->irq_received);
40875+ atomic_inc_unchecked(&qdev->irq_received);
40876
40877 if (pending & QXL_INTERRUPT_DISPLAY) {
40878- atomic_inc(&qdev->irq_received_display);
40879+ atomic_inc_unchecked(&qdev->irq_received_display);
40880 wake_up_all(&qdev->display_event);
40881 qxl_queue_garbage_collect(qdev, false);
40882 }
40883 if (pending & QXL_INTERRUPT_CURSOR) {
40884- atomic_inc(&qdev->irq_received_cursor);
40885+ atomic_inc_unchecked(&qdev->irq_received_cursor);
40886 wake_up_all(&qdev->cursor_event);
40887 }
40888 if (pending & QXL_INTERRUPT_IO_CMD) {
40889- atomic_inc(&qdev->irq_received_io_cmd);
40890+ atomic_inc_unchecked(&qdev->irq_received_io_cmd);
40891 wake_up_all(&qdev->io_cmd_event);
40892 }
40893 if (pending & QXL_INTERRUPT_ERROR) {
40894@@ -85,10 +85,10 @@ int qxl_irq_init(struct qxl_device *qdev)
40895 init_waitqueue_head(&qdev->io_cmd_event);
40896 INIT_WORK(&qdev->client_monitors_config_work,
40897 qxl_client_monitors_config_work_func);
40898- atomic_set(&qdev->irq_received, 0);
40899- atomic_set(&qdev->irq_received_display, 0);
40900- atomic_set(&qdev->irq_received_cursor, 0);
40901- atomic_set(&qdev->irq_received_io_cmd, 0);
40902+ atomic_set_unchecked(&qdev->irq_received, 0);
40903+ atomic_set_unchecked(&qdev->irq_received_display, 0);
40904+ atomic_set_unchecked(&qdev->irq_received_cursor, 0);
40905+ atomic_set_unchecked(&qdev->irq_received_io_cmd, 0);
40906 qdev->irq_received_error = 0;
40907 ret = drm_irq_install(qdev->ddev, qdev->ddev->pdev->irq);
40908 qdev->ram_header->int_mask = QXL_INTERRUPT_MASK;
40909diff --git a/drivers/gpu/drm/qxl/qxl_ttm.c b/drivers/gpu/drm/qxl/qxl_ttm.c
40910index 0cbc4c9..0e46686 100644
40911--- a/drivers/gpu/drm/qxl/qxl_ttm.c
40912+++ b/drivers/gpu/drm/qxl/qxl_ttm.c
40913@@ -103,7 +103,7 @@ static void qxl_ttm_global_fini(struct qxl_device *qdev)
40914 }
40915 }
40916
40917-static struct vm_operations_struct qxl_ttm_vm_ops;
40918+static vm_operations_struct_no_const qxl_ttm_vm_ops __read_only;
40919 static const struct vm_operations_struct *ttm_vm_ops;
40920
40921 static int qxl_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
40922@@ -145,8 +145,10 @@ int qxl_mmap(struct file *filp, struct vm_area_struct *vma)
40923 return r;
40924 if (unlikely(ttm_vm_ops == NULL)) {
40925 ttm_vm_ops = vma->vm_ops;
40926+ pax_open_kernel();
40927 qxl_ttm_vm_ops = *ttm_vm_ops;
40928 qxl_ttm_vm_ops.fault = &qxl_ttm_fault;
40929+ pax_close_kernel();
40930 }
40931 vma->vm_ops = &qxl_ttm_vm_ops;
40932 return 0;
40933@@ -464,25 +466,23 @@ static int qxl_mm_dump_table(struct seq_file *m, void *data)
40934 static int qxl_ttm_debugfs_init(struct qxl_device *qdev)
40935 {
40936 #if defined(CONFIG_DEBUG_FS)
40937- static struct drm_info_list qxl_mem_types_list[QXL_DEBUGFS_MEM_TYPES];
40938- static char qxl_mem_types_names[QXL_DEBUGFS_MEM_TYPES][32];
40939- unsigned i;
40940+ static struct drm_info_list qxl_mem_types_list[QXL_DEBUGFS_MEM_TYPES] = {
40941+ {
40942+ .name = "qxl_mem_mm",
40943+ .show = &qxl_mm_dump_table,
40944+ },
40945+ {
40946+ .name = "qxl_surf_mm",
40947+ .show = &qxl_mm_dump_table,
40948+ }
40949+ };
40950
40951- for (i = 0; i < QXL_DEBUGFS_MEM_TYPES; i++) {
40952- if (i == 0)
40953- sprintf(qxl_mem_types_names[i], "qxl_mem_mm");
40954- else
40955- sprintf(qxl_mem_types_names[i], "qxl_surf_mm");
40956- qxl_mem_types_list[i].name = qxl_mem_types_names[i];
40957- qxl_mem_types_list[i].show = &qxl_mm_dump_table;
40958- qxl_mem_types_list[i].driver_features = 0;
40959- if (i == 0)
40960- qxl_mem_types_list[i].data = qdev->mman.bdev.man[TTM_PL_VRAM].priv;
40961- else
40962- qxl_mem_types_list[i].data = qdev->mman.bdev.man[TTM_PL_PRIV0].priv;
40963+ pax_open_kernel();
40964+ *(void **)&qxl_mem_types_list[0].data = qdev->mman.bdev.man[TTM_PL_VRAM].priv;
40965+ *(void **)&qxl_mem_types_list[1].data = qdev->mman.bdev.man[TTM_PL_PRIV0].priv;
40966+ pax_close_kernel();
40967
40968- }
40969- return qxl_debugfs_add_files(qdev, qxl_mem_types_list, i);
40970+ return qxl_debugfs_add_files(qdev, qxl_mem_types_list, QXL_DEBUGFS_MEM_TYPES);
40971 #else
40972 return 0;
40973 #endif
40974diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
40975index 2c45ac9..5d740f8 100644
40976--- a/drivers/gpu/drm/r128/r128_cce.c
40977+++ b/drivers/gpu/drm/r128/r128_cce.c
40978@@ -377,7 +377,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
40979
40980 /* GH: Simple idle check.
40981 */
40982- atomic_set(&dev_priv->idle_count, 0);
40983+ atomic_set_unchecked(&dev_priv->idle_count, 0);
40984
40985 /* We don't support anything other than bus-mastering ring mode,
40986 * but the ring can be in either AGP or PCI space for the ring
40987diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
40988index 723e5d6..102dbaf 100644
40989--- a/drivers/gpu/drm/r128/r128_drv.h
40990+++ b/drivers/gpu/drm/r128/r128_drv.h
40991@@ -93,14 +93,14 @@ typedef struct drm_r128_private {
40992 int is_pci;
40993 unsigned long cce_buffers_offset;
40994
40995- atomic_t idle_count;
40996+ atomic_unchecked_t idle_count;
40997
40998 int page_flipping;
40999 int current_page;
41000 u32 crtc_offset;
41001 u32 crtc_offset_cntl;
41002
41003- atomic_t vbl_received;
41004+ atomic_unchecked_t vbl_received;
41005
41006 u32 color_fmt;
41007 unsigned int front_offset;
41008diff --git a/drivers/gpu/drm/r128/r128_ioc32.c b/drivers/gpu/drm/r128/r128_ioc32.c
41009index 663f38c..c689495 100644
41010--- a/drivers/gpu/drm/r128/r128_ioc32.c
41011+++ b/drivers/gpu/drm/r128/r128_ioc32.c
41012@@ -178,7 +178,7 @@ static int compat_r128_getparam(struct file *file, unsigned int cmd,
41013 return drm_ioctl(file, DRM_IOCTL_R128_GETPARAM, (unsigned long)getparam);
41014 }
41015
41016-drm_ioctl_compat_t *r128_compat_ioctls[] = {
41017+drm_ioctl_compat_t r128_compat_ioctls[] = {
41018 [DRM_R128_INIT] = compat_r128_init,
41019 [DRM_R128_DEPTH] = compat_r128_depth,
41020 [DRM_R128_STIPPLE] = compat_r128_stipple,
41021@@ -197,18 +197,15 @@ drm_ioctl_compat_t *r128_compat_ioctls[] = {
41022 long r128_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
41023 {
41024 unsigned int nr = DRM_IOCTL_NR(cmd);
41025- drm_ioctl_compat_t *fn = NULL;
41026 int ret;
41027
41028 if (nr < DRM_COMMAND_BASE)
41029 return drm_compat_ioctl(filp, cmd, arg);
41030
41031- if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(r128_compat_ioctls))
41032- fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
41033-
41034- if (fn != NULL)
41035+ if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(r128_compat_ioctls)) {
41036+ drm_ioctl_compat_t fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
41037 ret = (*fn) (filp, cmd, arg);
41038- else
41039+ } else
41040 ret = drm_ioctl(filp, cmd, arg);
41041
41042 return ret;
41043diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
41044index c2ae496..30b5993 100644
41045--- a/drivers/gpu/drm/r128/r128_irq.c
41046+++ b/drivers/gpu/drm/r128/r128_irq.c
41047@@ -41,7 +41,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
41048 if (crtc != 0)
41049 return 0;
41050
41051- return atomic_read(&dev_priv->vbl_received);
41052+ return atomic_read_unchecked(&dev_priv->vbl_received);
41053 }
41054
41055 irqreturn_t r128_driver_irq_handler(int irq, void *arg)
41056@@ -55,7 +55,7 @@ irqreturn_t r128_driver_irq_handler(int irq, void *arg)
41057 /* VBLANK interrupt */
41058 if (status & R128_CRTC_VBLANK_INT) {
41059 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
41060- atomic_inc(&dev_priv->vbl_received);
41061+ atomic_inc_unchecked(&dev_priv->vbl_received);
41062 drm_handle_vblank(dev, 0);
41063 return IRQ_HANDLED;
41064 }
41065diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
41066index 575e986..66e62ca 100644
41067--- a/drivers/gpu/drm/r128/r128_state.c
41068+++ b/drivers/gpu/drm/r128/r128_state.c
41069@@ -320,10 +320,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
41070
41071 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
41072 {
41073- if (atomic_read(&dev_priv->idle_count) == 0)
41074+ if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
41075 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
41076 else
41077- atomic_set(&dev_priv->idle_count, 0);
41078+ atomic_set_unchecked(&dev_priv->idle_count, 0);
41079 }
41080
41081 #endif
41082diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
41083index 4a85bb6..aaea819 100644
41084--- a/drivers/gpu/drm/radeon/mkregtable.c
41085+++ b/drivers/gpu/drm/radeon/mkregtable.c
41086@@ -624,14 +624,14 @@ static int parser_auth(struct table *t, const char *filename)
41087 regex_t mask_rex;
41088 regmatch_t match[4];
41089 char buf[1024];
41090- size_t end;
41091+ long end;
41092 int len;
41093 int done = 0;
41094 int r;
41095 unsigned o;
41096 struct offset *offset;
41097 char last_reg_s[10];
41098- int last_reg;
41099+ unsigned long last_reg;
41100
41101 if (regcomp
41102 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
41103diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
41104index 995a8b1..b7cb898 100644
41105--- a/drivers/gpu/drm/radeon/radeon_device.c
41106+++ b/drivers/gpu/drm/radeon/radeon_device.c
41107@@ -1214,7 +1214,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
41108 * locking inversion with the driver load path. And the access here is
41109 * completely racy anyway. So don't bother with locking for now.
41110 */
41111- return dev->open_count == 0;
41112+ return local_read(&dev->open_count) == 0;
41113 }
41114
41115 static const struct vga_switcheroo_client_ops radeon_switcheroo_ops = {
41116diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
41117index 46bd393..6ae4719 100644
41118--- a/drivers/gpu/drm/radeon/radeon_drv.h
41119+++ b/drivers/gpu/drm/radeon/radeon_drv.h
41120@@ -264,7 +264,7 @@ typedef struct drm_radeon_private {
41121
41122 /* SW interrupt */
41123 wait_queue_head_t swi_queue;
41124- atomic_t swi_emitted;
41125+ atomic_unchecked_t swi_emitted;
41126 int vblank_crtc;
41127 uint32_t irq_enable_reg;
41128 uint32_t r500_disp_irq_reg;
41129diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
41130index 0b98ea1..0881827 100644
41131--- a/drivers/gpu/drm/radeon/radeon_ioc32.c
41132+++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
41133@@ -358,7 +358,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
41134 request = compat_alloc_user_space(sizeof(*request));
41135 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
41136 || __put_user(req32.param, &request->param)
41137- || __put_user((void __user *)(unsigned long)req32.value,
41138+ || __put_user((unsigned long)req32.value,
41139 &request->value))
41140 return -EFAULT;
41141
41142@@ -368,7 +368,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
41143 #define compat_radeon_cp_setparam NULL
41144 #endif /* X86_64 || IA64 */
41145
41146-static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
41147+static drm_ioctl_compat_t radeon_compat_ioctls[] = {
41148 [DRM_RADEON_CP_INIT] = compat_radeon_cp_init,
41149 [DRM_RADEON_CLEAR] = compat_radeon_cp_clear,
41150 [DRM_RADEON_STIPPLE] = compat_radeon_cp_stipple,
41151@@ -393,18 +393,15 @@ static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
41152 long radeon_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
41153 {
41154 unsigned int nr = DRM_IOCTL_NR(cmd);
41155- drm_ioctl_compat_t *fn = NULL;
41156 int ret;
41157
41158 if (nr < DRM_COMMAND_BASE)
41159 return drm_compat_ioctl(filp, cmd, arg);
41160
41161- if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(radeon_compat_ioctls))
41162- fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
41163-
41164- if (fn != NULL)
41165+ if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(radeon_compat_ioctls)) {
41166+ drm_ioctl_compat_t fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
41167 ret = (*fn) (filp, cmd, arg);
41168- else
41169+ } else
41170 ret = drm_ioctl(filp, cmd, arg);
41171
41172 return ret;
41173diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
41174index 244b19b..c19226d 100644
41175--- a/drivers/gpu/drm/radeon/radeon_irq.c
41176+++ b/drivers/gpu/drm/radeon/radeon_irq.c
41177@@ -226,8 +226,8 @@ static int radeon_emit_irq(struct drm_device * dev)
41178 unsigned int ret;
41179 RING_LOCALS;
41180
41181- atomic_inc(&dev_priv->swi_emitted);
41182- ret = atomic_read(&dev_priv->swi_emitted);
41183+ atomic_inc_unchecked(&dev_priv->swi_emitted);
41184+ ret = atomic_read_unchecked(&dev_priv->swi_emitted);
41185
41186 BEGIN_RING(4);
41187 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
41188@@ -353,7 +353,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
41189 drm_radeon_private_t *dev_priv =
41190 (drm_radeon_private_t *) dev->dev_private;
41191
41192- atomic_set(&dev_priv->swi_emitted, 0);
41193+ atomic_set_unchecked(&dev_priv->swi_emitted, 0);
41194 init_waitqueue_head(&dev_priv->swi_queue);
41195
41196 dev->max_vblank_count = 0x001fffff;
41197diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
41198index 535403e..5dd655b 100644
41199--- a/drivers/gpu/drm/radeon/radeon_state.c
41200+++ b/drivers/gpu/drm/radeon/radeon_state.c
41201@@ -2168,7 +2168,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
41202 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
41203 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
41204
41205- if (copy_from_user(&depth_boxes, clear->depth_boxes,
41206+ if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || copy_from_user(&depth_boxes, clear->depth_boxes,
41207 sarea_priv->nbox * sizeof(depth_boxes[0])))
41208 return -EFAULT;
41209
41210@@ -3031,7 +3031,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
41211 {
41212 drm_radeon_private_t *dev_priv = dev->dev_private;
41213 drm_radeon_getparam_t *param = data;
41214- int value;
41215+ int value = 0;
41216
41217 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
41218
41219diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
41220index 8624979..65e5243 100644
41221--- a/drivers/gpu/drm/radeon/radeon_ttm.c
41222+++ b/drivers/gpu/drm/radeon/radeon_ttm.c
41223@@ -936,7 +936,7 @@ void radeon_ttm_set_active_vram_size(struct radeon_device *rdev, u64 size)
41224 man->size = size >> PAGE_SHIFT;
41225 }
41226
41227-static struct vm_operations_struct radeon_ttm_vm_ops;
41228+static vm_operations_struct_no_const radeon_ttm_vm_ops __read_only;
41229 static const struct vm_operations_struct *ttm_vm_ops = NULL;
41230
41231 static int radeon_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
41232@@ -977,8 +977,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
41233 }
41234 if (unlikely(ttm_vm_ops == NULL)) {
41235 ttm_vm_ops = vma->vm_ops;
41236+ pax_open_kernel();
41237 radeon_ttm_vm_ops = *ttm_vm_ops;
41238 radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
41239+ pax_close_kernel();
41240 }
41241 vma->vm_ops = &radeon_ttm_vm_ops;
41242 return 0;
41243diff --git a/drivers/gpu/drm/tegra/dc.c b/drivers/gpu/drm/tegra/dc.c
41244index 054a79f..30d9ac4 100644
41245--- a/drivers/gpu/drm/tegra/dc.c
41246+++ b/drivers/gpu/drm/tegra/dc.c
41247@@ -1242,7 +1242,7 @@ static int tegra_dc_debugfs_init(struct tegra_dc *dc, struct drm_minor *minor)
41248 }
41249
41250 for (i = 0; i < ARRAY_SIZE(debugfs_files); i++)
41251- dc->debugfs_files[i].data = dc;
41252+ *(void **)&dc->debugfs_files[i].data = dc;
41253
41254 err = drm_debugfs_create_files(dc->debugfs_files,
41255 ARRAY_SIZE(debugfs_files),
41256diff --git a/drivers/gpu/drm/tegra/dsi.c b/drivers/gpu/drm/tegra/dsi.c
41257index f787445..2df2c65 100644
41258--- a/drivers/gpu/drm/tegra/dsi.c
41259+++ b/drivers/gpu/drm/tegra/dsi.c
41260@@ -41,7 +41,7 @@ struct tegra_dsi {
41261 struct clk *clk_lp;
41262 struct clk *clk;
41263
41264- struct drm_info_list *debugfs_files;
41265+ drm_info_list_no_const *debugfs_files;
41266 struct drm_minor *minor;
41267 struct dentry *debugfs;
41268
41269diff --git a/drivers/gpu/drm/tegra/hdmi.c b/drivers/gpu/drm/tegra/hdmi.c
41270index ffe2654..03c7b1c 100644
41271--- a/drivers/gpu/drm/tegra/hdmi.c
41272+++ b/drivers/gpu/drm/tegra/hdmi.c
41273@@ -60,7 +60,7 @@ struct tegra_hdmi {
41274 bool stereo;
41275 bool dvi;
41276
41277- struct drm_info_list *debugfs_files;
41278+ drm_info_list_no_const *debugfs_files;
41279 struct drm_minor *minor;
41280 struct dentry *debugfs;
41281 };
41282diff --git a/drivers/gpu/drm/ttm/ttm_bo_manager.c b/drivers/gpu/drm/ttm/ttm_bo_manager.c
41283index 964387f..4eafc00 100644
41284--- a/drivers/gpu/drm/ttm/ttm_bo_manager.c
41285+++ b/drivers/gpu/drm/ttm/ttm_bo_manager.c
41286@@ -146,10 +146,10 @@ static void ttm_bo_man_debug(struct ttm_mem_type_manager *man,
41287 }
41288
41289 const struct ttm_mem_type_manager_func ttm_bo_manager_func = {
41290- ttm_bo_man_init,
41291- ttm_bo_man_takedown,
41292- ttm_bo_man_get_node,
41293- ttm_bo_man_put_node,
41294- ttm_bo_man_debug
41295+ .init = ttm_bo_man_init,
41296+ .takedown = ttm_bo_man_takedown,
41297+ .get_node = ttm_bo_man_get_node,
41298+ .put_node = ttm_bo_man_put_node,
41299+ .debug = ttm_bo_man_debug
41300 };
41301 EXPORT_SYMBOL(ttm_bo_manager_func);
41302diff --git a/drivers/gpu/drm/ttm/ttm_memory.c b/drivers/gpu/drm/ttm/ttm_memory.c
41303index a1803fb..c53f6b0 100644
41304--- a/drivers/gpu/drm/ttm/ttm_memory.c
41305+++ b/drivers/gpu/drm/ttm/ttm_memory.c
41306@@ -264,7 +264,7 @@ static int ttm_mem_init_kernel_zone(struct ttm_mem_global *glob,
41307 zone->glob = glob;
41308 glob->zone_kernel = zone;
41309 ret = kobject_init_and_add(
41310- &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, zone->name);
41311+ &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, "%s", zone->name);
41312 if (unlikely(ret != 0)) {
41313 kobject_put(&zone->kobj);
41314 return ret;
41315@@ -348,7 +348,7 @@ static int ttm_mem_init_dma32_zone(struct ttm_mem_global *glob,
41316 zone->glob = glob;
41317 glob->zone_dma32 = zone;
41318 ret = kobject_init_and_add(
41319- &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, zone->name);
41320+ &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, "%s", zone->name);
41321 if (unlikely(ret != 0)) {
41322 kobject_put(&zone->kobj);
41323 return ret;
41324diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
41325index 09874d6..d6da1de 100644
41326--- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
41327+++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
41328@@ -54,7 +54,7 @@
41329
41330 #define NUM_PAGES_TO_ALLOC (PAGE_SIZE/sizeof(struct page *))
41331 #define SMALL_ALLOCATION 16
41332-#define FREE_ALL_PAGES (~0U)
41333+#define FREE_ALL_PAGES (~0UL)
41334 /* times are in msecs */
41335 #define PAGE_FREE_INTERVAL 1000
41336
41337@@ -299,14 +299,13 @@ static void ttm_pool_update_free_locked(struct ttm_page_pool *pool,
41338 * @free_all: If set to true will free all pages in pool
41339 * @gfp: GFP flags.
41340 **/
41341-static int ttm_page_pool_free(struct ttm_page_pool *pool, unsigned nr_free,
41342+static unsigned long ttm_page_pool_free(struct ttm_page_pool *pool, unsigned long nr_free,
41343 gfp_t gfp)
41344 {
41345 unsigned long irq_flags;
41346 struct page *p;
41347 struct page **pages_to_free;
41348- unsigned freed_pages = 0,
41349- npages_to_free = nr_free;
41350+ unsigned long freed_pages = 0, npages_to_free = nr_free;
41351
41352 if (NUM_PAGES_TO_ALLOC < nr_free)
41353 npages_to_free = NUM_PAGES_TO_ALLOC;
41354@@ -366,7 +365,8 @@ restart:
41355 __list_del(&p->lru, &pool->list);
41356
41357 ttm_pool_update_free_locked(pool, freed_pages);
41358- nr_free -= freed_pages;
41359+ if (likely(nr_free != FREE_ALL_PAGES))
41360+ nr_free -= freed_pages;
41361 }
41362
41363 spin_unlock_irqrestore(&pool->lock, irq_flags);
41364@@ -395,7 +395,7 @@ ttm_pool_shrink_scan(struct shrinker *shrink, struct shrink_control *sc)
41365 unsigned i;
41366 unsigned pool_offset;
41367 struct ttm_page_pool *pool;
41368- int shrink_pages = sc->nr_to_scan;
41369+ unsigned long shrink_pages = sc->nr_to_scan;
41370 unsigned long freed = 0;
41371
41372 if (!mutex_trylock(&lock))
41373@@ -403,7 +403,7 @@ ttm_pool_shrink_scan(struct shrinker *shrink, struct shrink_control *sc)
41374 pool_offset = ++start_pool % NUM_POOLS;
41375 /* select start pool in round robin fashion */
41376 for (i = 0; i < NUM_POOLS; ++i) {
41377- unsigned nr_free = shrink_pages;
41378+ unsigned long nr_free = shrink_pages;
41379 if (shrink_pages == 0)
41380 break;
41381 pool = &_manager->pools[(i + pool_offset)%NUM_POOLS];
41382@@ -669,7 +669,7 @@ out:
41383 }
41384
41385 /* Put all pages in pages list to correct pool to wait for reuse */
41386-static void ttm_put_pages(struct page **pages, unsigned npages, int flags,
41387+static void ttm_put_pages(struct page **pages, unsigned long npages, int flags,
41388 enum ttm_caching_state cstate)
41389 {
41390 unsigned long irq_flags;
41391@@ -724,7 +724,7 @@ static int ttm_get_pages(struct page **pages, unsigned npages, int flags,
41392 struct list_head plist;
41393 struct page *p = NULL;
41394 gfp_t gfp_flags = GFP_USER;
41395- unsigned count;
41396+ unsigned long count;
41397 int r;
41398
41399 /* set zero flag for page allocation if required */
41400diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc_dma.c b/drivers/gpu/drm/ttm/ttm_page_alloc_dma.c
41401index c96db43..c367557 100644
41402--- a/drivers/gpu/drm/ttm/ttm_page_alloc_dma.c
41403+++ b/drivers/gpu/drm/ttm/ttm_page_alloc_dma.c
41404@@ -56,7 +56,7 @@
41405
41406 #define NUM_PAGES_TO_ALLOC (PAGE_SIZE/sizeof(struct page *))
41407 #define SMALL_ALLOCATION 4
41408-#define FREE_ALL_PAGES (~0U)
41409+#define FREE_ALL_PAGES (~0UL)
41410 /* times are in msecs */
41411 #define IS_UNDEFINED (0)
41412 #define IS_WC (1<<1)
41413@@ -413,15 +413,14 @@ static void ttm_dma_page_put(struct dma_pool *pool, struct dma_page *d_page)
41414 * @nr_free: If set to true will free all pages in pool
41415 * @gfp: GFP flags.
41416 **/
41417-static unsigned ttm_dma_page_pool_free(struct dma_pool *pool, unsigned nr_free,
41418+static unsigned long ttm_dma_page_pool_free(struct dma_pool *pool, unsigned long nr_free,
41419 gfp_t gfp)
41420 {
41421 unsigned long irq_flags;
41422 struct dma_page *dma_p, *tmp;
41423 struct page **pages_to_free;
41424 struct list_head d_pages;
41425- unsigned freed_pages = 0,
41426- npages_to_free = nr_free;
41427+ unsigned long freed_pages = 0, npages_to_free = nr_free;
41428
41429 if (NUM_PAGES_TO_ALLOC < nr_free)
41430 npages_to_free = NUM_PAGES_TO_ALLOC;
41431@@ -494,7 +493,8 @@ restart:
41432 /* remove range of pages from the pool */
41433 if (freed_pages) {
41434 ttm_pool_update_free_locked(pool, freed_pages);
41435- nr_free -= freed_pages;
41436+ if (likely(nr_free != FREE_ALL_PAGES))
41437+ nr_free -= freed_pages;
41438 }
41439
41440 spin_unlock_irqrestore(&pool->lock, irq_flags);
41441@@ -929,7 +929,7 @@ void ttm_dma_unpopulate(struct ttm_dma_tt *ttm_dma, struct device *dev)
41442 struct dma_page *d_page, *next;
41443 enum pool_type type;
41444 bool is_cached = false;
41445- unsigned count = 0, i, npages = 0;
41446+ unsigned long count = 0, i, npages = 0;
41447 unsigned long irq_flags;
41448
41449 type = ttm_to_type(ttm->page_flags, ttm->caching_state);
41450@@ -1007,7 +1007,7 @@ ttm_dma_pool_shrink_scan(struct shrinker *shrink, struct shrink_control *sc)
41451 static unsigned start_pool;
41452 unsigned idx = 0;
41453 unsigned pool_offset;
41454- unsigned shrink_pages = sc->nr_to_scan;
41455+ unsigned long shrink_pages = sc->nr_to_scan;
41456 struct device_pools *p;
41457 unsigned long freed = 0;
41458
41459@@ -1020,7 +1020,7 @@ ttm_dma_pool_shrink_scan(struct shrinker *shrink, struct shrink_control *sc)
41460 goto out;
41461 pool_offset = ++start_pool % _manager->npools;
41462 list_for_each_entry(p, &_manager->pools, pools) {
41463- unsigned nr_free;
41464+ unsigned long nr_free;
41465
41466 if (!p->dev)
41467 continue;
41468@@ -1034,7 +1034,7 @@ ttm_dma_pool_shrink_scan(struct shrinker *shrink, struct shrink_control *sc)
41469 sc->gfp_mask);
41470 freed += nr_free - shrink_pages;
41471
41472- pr_debug("%s: (%s:%d) Asked to shrink %d, have %d more to go\n",
41473+ pr_debug("%s: (%s:%d) Asked to shrink %lu, have %lu more to go\n",
41474 p->pool->dev_name, p->pool->name, current->pid,
41475 nr_free, shrink_pages);
41476 }
41477diff --git a/drivers/gpu/drm/udl/udl_fb.c b/drivers/gpu/drm/udl/udl_fb.c
41478index 8cbcb45..a4d9cf7 100644
41479--- a/drivers/gpu/drm/udl/udl_fb.c
41480+++ b/drivers/gpu/drm/udl/udl_fb.c
41481@@ -367,7 +367,6 @@ static int udl_fb_release(struct fb_info *info, int user)
41482 fb_deferred_io_cleanup(info);
41483 kfree(info->fbdefio);
41484 info->fbdefio = NULL;
41485- info->fbops->fb_mmap = udl_fb_mmap;
41486 }
41487
41488 pr_warn("released /dev/fb%d user=%d count=%d\n",
41489diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
41490index ef8c500..01030c8 100644
41491--- a/drivers/gpu/drm/via/via_drv.h
41492+++ b/drivers/gpu/drm/via/via_drv.h
41493@@ -53,7 +53,7 @@ typedef struct drm_via_ring_buffer {
41494 typedef uint32_t maskarray_t[5];
41495
41496 typedef struct drm_via_irq {
41497- atomic_t irq_received;
41498+ atomic_unchecked_t irq_received;
41499 uint32_t pending_mask;
41500 uint32_t enable_mask;
41501 wait_queue_head_t irq_queue;
41502@@ -77,7 +77,7 @@ typedef struct drm_via_private {
41503 struct timeval last_vblank;
41504 int last_vblank_valid;
41505 unsigned usec_per_vblank;
41506- atomic_t vbl_received;
41507+ atomic_unchecked_t vbl_received;
41508 drm_via_state_t hc_state;
41509 char pci_buf[VIA_PCI_BUF_SIZE];
41510 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
41511diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
41512index 1319433..a993b0c 100644
41513--- a/drivers/gpu/drm/via/via_irq.c
41514+++ b/drivers/gpu/drm/via/via_irq.c
41515@@ -101,7 +101,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
41516 if (crtc != 0)
41517 return 0;
41518
41519- return atomic_read(&dev_priv->vbl_received);
41520+ return atomic_read_unchecked(&dev_priv->vbl_received);
41521 }
41522
41523 irqreturn_t via_driver_irq_handler(int irq, void *arg)
41524@@ -116,8 +116,8 @@ irqreturn_t via_driver_irq_handler(int irq, void *arg)
41525
41526 status = VIA_READ(VIA_REG_INTERRUPT);
41527 if (status & VIA_IRQ_VBLANK_PENDING) {
41528- atomic_inc(&dev_priv->vbl_received);
41529- if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
41530+ atomic_inc_unchecked(&dev_priv->vbl_received);
41531+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
41532 do_gettimeofday(&cur_vblank);
41533 if (dev_priv->last_vblank_valid) {
41534 dev_priv->usec_per_vblank =
41535@@ -127,7 +127,7 @@ irqreturn_t via_driver_irq_handler(int irq, void *arg)
41536 dev_priv->last_vblank = cur_vblank;
41537 dev_priv->last_vblank_valid = 1;
41538 }
41539- if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
41540+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
41541 DRM_DEBUG("US per vblank is: %u\n",
41542 dev_priv->usec_per_vblank);
41543 }
41544@@ -137,7 +137,7 @@ irqreturn_t via_driver_irq_handler(int irq, void *arg)
41545
41546 for (i = 0; i < dev_priv->num_irqs; ++i) {
41547 if (status & cur_irq->pending_mask) {
41548- atomic_inc(&cur_irq->irq_received);
41549+ atomic_inc_unchecked(&cur_irq->irq_received);
41550 wake_up(&cur_irq->irq_queue);
41551 handled = 1;
41552 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
41553@@ -242,11 +242,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
41554 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * HZ,
41555 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
41556 masks[irq][4]));
41557- cur_irq_sequence = atomic_read(&cur_irq->irq_received);
41558+ cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
41559 } else {
41560 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * HZ,
41561 (((cur_irq_sequence =
41562- atomic_read(&cur_irq->irq_received)) -
41563+ atomic_read_unchecked(&cur_irq->irq_received)) -
41564 *sequence) <= (1 << 23)));
41565 }
41566 *sequence = cur_irq_sequence;
41567@@ -284,7 +284,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
41568 }
41569
41570 for (i = 0; i < dev_priv->num_irqs; ++i) {
41571- atomic_set(&cur_irq->irq_received, 0);
41572+ atomic_set_unchecked(&cur_irq->irq_received, 0);
41573 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
41574 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
41575 init_waitqueue_head(&cur_irq->irq_queue);
41576@@ -366,7 +366,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
41577 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
41578 case VIA_IRQ_RELATIVE:
41579 irqwait->request.sequence +=
41580- atomic_read(&cur_irq->irq_received);
41581+ atomic_read_unchecked(&cur_irq->irq_received);
41582 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
41583 case VIA_IRQ_ABSOLUTE:
41584 break;
41585diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
41586index 4ee799b..69fc0d1 100644
41587--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
41588+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
41589@@ -446,7 +446,7 @@ struct vmw_private {
41590 * Fencing and IRQs.
41591 */
41592
41593- atomic_t marker_seq;
41594+ atomic_unchecked_t marker_seq;
41595 wait_queue_head_t fence_queue;
41596 wait_queue_head_t fifo_queue;
41597 int fence_queue_waiters; /* Protected by hw_mutex */
41598diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
41599index 09e10ae..cb76c60 100644
41600--- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
41601+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
41602@@ -154,7 +154,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
41603 (unsigned int) min,
41604 (unsigned int) fifo->capabilities);
41605
41606- atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
41607+ atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
41608 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
41609 vmw_marker_queue_init(&fifo->marker_queue);
41610 return vmw_fifo_send_fence(dev_priv, &dummy);
41611@@ -378,7 +378,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
41612 if (reserveable)
41613 iowrite32(bytes, fifo_mem +
41614 SVGA_FIFO_RESERVED);
41615- return fifo_mem + (next_cmd >> 2);
41616+ return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
41617 } else {
41618 need_bounce = true;
41619 }
41620@@ -498,7 +498,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
41621
41622 fm = vmw_fifo_reserve(dev_priv, bytes);
41623 if (unlikely(fm == NULL)) {
41624- *seqno = atomic_read(&dev_priv->marker_seq);
41625+ *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
41626 ret = -ENOMEM;
41627 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
41628 false, 3*HZ);
41629@@ -506,7 +506,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
41630 }
41631
41632 do {
41633- *seqno = atomic_add_return(1, &dev_priv->marker_seq);
41634+ *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
41635 } while (*seqno == 0);
41636
41637 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
41638diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c b/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
41639index 170b61b..fec7348 100644
41640--- a/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
41641+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
41642@@ -164,9 +164,9 @@ static void vmw_gmrid_man_debug(struct ttm_mem_type_manager *man,
41643 }
41644
41645 const struct ttm_mem_type_manager_func vmw_gmrid_manager_func = {
41646- vmw_gmrid_man_init,
41647- vmw_gmrid_man_takedown,
41648- vmw_gmrid_man_get_node,
41649- vmw_gmrid_man_put_node,
41650- vmw_gmrid_man_debug
41651+ .init = vmw_gmrid_man_init,
41652+ .takedown = vmw_gmrid_man_takedown,
41653+ .get_node = vmw_gmrid_man_get_node,
41654+ .put_node = vmw_gmrid_man_put_node,
41655+ .debug = vmw_gmrid_man_debug
41656 };
41657diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
41658index 37881ec..319065d 100644
41659--- a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
41660+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
41661@@ -235,7 +235,7 @@ int vmw_present_ioctl(struct drm_device *dev, void *data,
41662 int ret;
41663
41664 num_clips = arg->num_clips;
41665- clips_ptr = (struct drm_vmw_rect *)(unsigned long)arg->clips_ptr;
41666+ clips_ptr = (struct drm_vmw_rect __user *)(unsigned long)arg->clips_ptr;
41667
41668 if (unlikely(num_clips == 0))
41669 return 0;
41670@@ -318,7 +318,7 @@ int vmw_present_readback_ioctl(struct drm_device *dev, void *data,
41671 int ret;
41672
41673 num_clips = arg->num_clips;
41674- clips_ptr = (struct drm_vmw_rect *)(unsigned long)arg->clips_ptr;
41675+ clips_ptr = (struct drm_vmw_rect __user *)(unsigned long)arg->clips_ptr;
41676
41677 if (unlikely(num_clips == 0))
41678 return 0;
41679diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
41680index 0c42376..6febe77 100644
41681--- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
41682+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
41683@@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
41684 * emitted. Then the fence is stale and signaled.
41685 */
41686
41687- ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
41688+ ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
41689 > VMW_FENCE_WRAP);
41690
41691 return ret;
41692@@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
41693
41694 if (fifo_idle)
41695 down_read(&fifo_state->rwsem);
41696- signal_seq = atomic_read(&dev_priv->marker_seq);
41697+ signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
41698 ret = 0;
41699
41700 for (;;) {
41701diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
41702index efd1ffd..0ae13ca 100644
41703--- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
41704+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
41705@@ -135,7 +135,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
41706 while (!vmw_lag_lt(queue, us)) {
41707 spin_lock(&queue->lock);
41708 if (list_empty(&queue->head))
41709- seqno = atomic_read(&dev_priv->marker_seq);
41710+ seqno = atomic_read_unchecked(&dev_priv->marker_seq);
41711 else {
41712 marker = list_first_entry(&queue->head,
41713 struct vmw_marker, head);
41714diff --git a/drivers/gpu/vga/vga_switcheroo.c b/drivers/gpu/vga/vga_switcheroo.c
41715index 37ac7b5..d52a5c9 100644
41716--- a/drivers/gpu/vga/vga_switcheroo.c
41717+++ b/drivers/gpu/vga/vga_switcheroo.c
41718@@ -644,7 +644,7 @@ static int vga_switcheroo_runtime_resume(struct device *dev)
41719
41720 /* this version is for the case where the power switch is separate
41721 to the device being powered down. */
41722-int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain)
41723+int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain)
41724 {
41725 /* copy over all the bus versions */
41726 if (dev->bus && dev->bus->pm) {
41727@@ -695,7 +695,7 @@ static int vga_switcheroo_runtime_resume_hdmi_audio(struct device *dev)
41728 return ret;
41729 }
41730
41731-int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain)
41732+int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain)
41733 {
41734 /* copy over all the bus versions */
41735 if (dev->bus && dev->bus->pm) {
41736diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
41737index dfaccfc..bfea740 100644
41738--- a/drivers/hid/hid-core.c
41739+++ b/drivers/hid/hid-core.c
41740@@ -2507,7 +2507,7 @@ EXPORT_SYMBOL_GPL(hid_ignore);
41741
41742 int hid_add_device(struct hid_device *hdev)
41743 {
41744- static atomic_t id = ATOMIC_INIT(0);
41745+ static atomic_unchecked_t id = ATOMIC_INIT(0);
41746 int ret;
41747
41748 if (WARN_ON(hdev->status & HID_STAT_ADDED))
41749@@ -2549,7 +2549,7 @@ int hid_add_device(struct hid_device *hdev)
41750 /* XXX hack, any other cleaner solution after the driver core
41751 * is converted to allow more than 20 bytes as the device name? */
41752 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
41753- hdev->vendor, hdev->product, atomic_inc_return(&id));
41754+ hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
41755
41756 hid_debug_register(hdev, dev_name(&hdev->dev));
41757 ret = device_add(&hdev->dev);
41758diff --git a/drivers/hid/hid-logitech-dj.c b/drivers/hid/hid-logitech-dj.c
41759index 71f5692..147d3da 100644
41760--- a/drivers/hid/hid-logitech-dj.c
41761+++ b/drivers/hid/hid-logitech-dj.c
41762@@ -658,6 +658,12 @@ static int logi_dj_raw_event(struct hid_device *hdev,
41763 * device (via hid_input_report() ) and return 1 so hid-core does not do
41764 * anything else with it.
41765 */
41766+ if ((dj_report->device_index < DJ_DEVICE_INDEX_MIN) ||
41767+ (dj_report->device_index > DJ_DEVICE_INDEX_MAX)) {
41768+ dev_err(&hdev->dev, "%s: invalid device index:%d\n",
41769+ __func__, dj_report->device_index);
41770+ return false;
41771+ }
41772
41773 /* case 1) */
41774 if (data[0] != REPORT_ID_DJ_SHORT)
41775diff --git a/drivers/hid/hid-sony.c b/drivers/hid/hid-sony.c
41776index bc4269e..b6e6102 100644
41777--- a/drivers/hid/hid-sony.c
41778+++ b/drivers/hid/hid-sony.c
41779@@ -798,6 +798,12 @@ union sixaxis_output_report_01 {
41780 __u8 buf[36];
41781 };
41782
41783+#define DS4_REPORT_0x02_SIZE 37
41784+#define DS4_REPORT_0x05_SIZE 32
41785+#define DS4_REPORT_0x11_SIZE 78
41786+#define DS4_REPORT_0x81_SIZE 7
41787+#define SIXAXIS_REPORT_0xF2_SIZE 18
41788+
41789 static spinlock_t sony_dev_list_lock;
41790 static LIST_HEAD(sony_device_list);
41791 static DEFINE_IDA(sony_device_id_allocator);
41792@@ -811,6 +817,7 @@ struct sony_sc {
41793 struct work_struct state_worker;
41794 struct power_supply battery;
41795 int device_id;
41796+ __u8 *output_report_dmabuf;
41797
41798 #ifdef CONFIG_SONY_FF
41799 __u8 left;
41800@@ -1142,9 +1149,20 @@ static int sixaxis_set_operational_usb(struct hid_device *hdev)
41801
41802 static int sixaxis_set_operational_bt(struct hid_device *hdev)
41803 {
41804- unsigned char buf[] = { 0xf4, 0x42, 0x03, 0x00, 0x00 };
41805- return hid_hw_raw_request(hdev, buf[0], buf, sizeof(buf),
41806+ static const __u8 report[] = { 0xf4, 0x42, 0x03, 0x00, 0x00 };
41807+ __u8 *buf;
41808+ int ret;
41809+
41810+ buf = kmemdup(report, sizeof(report), GFP_KERNEL);
41811+ if (!buf)
41812+ return -ENOMEM;
41813+
41814+ ret = hid_hw_raw_request(hdev, buf[0], buf, sizeof(report),
41815 HID_FEATURE_REPORT, HID_REQ_SET_REPORT);
41816+
41817+ kfree(buf);
41818+
41819+ return ret;
41820 }
41821
41822 /*
41823@@ -1153,10 +1171,19 @@ static int sixaxis_set_operational_bt(struct hid_device *hdev)
41824 */
41825 static int dualshock4_set_operational_bt(struct hid_device *hdev)
41826 {
41827- __u8 buf[37] = { 0 };
41828+ __u8 *buf;
41829+ int ret;
41830
41831- return hid_hw_raw_request(hdev, 0x02, buf, sizeof(buf),
41832+ buf = kmalloc(DS4_REPORT_0x02_SIZE, GFP_KERNEL);
41833+ if (!buf)
41834+ return -ENOMEM;
41835+
41836+ ret = hid_hw_raw_request(hdev, 0x02, buf, DS4_REPORT_0x02_SIZE,
41837 HID_FEATURE_REPORT, HID_REQ_GET_REPORT);
41838+
41839+ kfree(buf);
41840+
41841+ return ret;
41842 }
41843
41844 static void sixaxis_set_leds_from_id(int id, __u8 values[MAX_LEDS])
41845@@ -1471,9 +1498,7 @@ error_leds:
41846
41847 static void sixaxis_state_worker(struct work_struct *work)
41848 {
41849- struct sony_sc *sc = container_of(work, struct sony_sc, state_worker);
41850- int n;
41851- union sixaxis_output_report_01 report = {
41852+ static const union sixaxis_output_report_01 default_report = {
41853 .buf = {
41854 0x01,
41855 0x00, 0xff, 0x00, 0xff, 0x00,
41856@@ -1485,20 +1510,27 @@ static void sixaxis_state_worker(struct work_struct *work)
41857 0x00, 0x00, 0x00, 0x00, 0x00
41858 }
41859 };
41860+ struct sony_sc *sc = container_of(work, struct sony_sc, state_worker);
41861+ struct sixaxis_output_report *report =
41862+ (struct sixaxis_output_report *)sc->output_report_dmabuf;
41863+ int n;
41864+
41865+ /* Initialize the report with default values */
41866+ memcpy(report, &default_report, sizeof(struct sixaxis_output_report));
41867
41868 #ifdef CONFIG_SONY_FF
41869- report.data.rumble.right_motor_on = sc->right ? 1 : 0;
41870- report.data.rumble.left_motor_force = sc->left;
41871+ report->rumble.right_motor_on = sc->right ? 1 : 0;
41872+ report->rumble.left_motor_force = sc->left;
41873 #endif
41874
41875- report.data.leds_bitmap |= sc->led_state[0] << 1;
41876- report.data.leds_bitmap |= sc->led_state[1] << 2;
41877- report.data.leds_bitmap |= sc->led_state[2] << 3;
41878- report.data.leds_bitmap |= sc->led_state[3] << 4;
41879+ report->leds_bitmap |= sc->led_state[0] << 1;
41880+ report->leds_bitmap |= sc->led_state[1] << 2;
41881+ report->leds_bitmap |= sc->led_state[2] << 3;
41882+ report->leds_bitmap |= sc->led_state[3] << 4;
41883
41884 /* Set flag for all leds off, required for 3rd party INTEC controller */
41885- if ((report.data.leds_bitmap & 0x1E) == 0)
41886- report.data.leds_bitmap |= 0x20;
41887+ if ((report->leds_bitmap & 0x1E) == 0)
41888+ report->leds_bitmap |= 0x20;
41889
41890 /*
41891 * The LEDs in the report are indexed in reverse order to their
41892@@ -1511,28 +1543,30 @@ static void sixaxis_state_worker(struct work_struct *work)
41893 */
41894 for (n = 0; n < 4; n++) {
41895 if (sc->led_delay_on[n] || sc->led_delay_off[n]) {
41896- report.data.led[3 - n].duty_off = sc->led_delay_off[n];
41897- report.data.led[3 - n].duty_on = sc->led_delay_on[n];
41898+ report->led[3 - n].duty_off = sc->led_delay_off[n];
41899+ report->led[3 - n].duty_on = sc->led_delay_on[n];
41900 }
41901 }
41902
41903- hid_hw_raw_request(sc->hdev, report.data.report_id, report.buf,
41904- sizeof(report), HID_OUTPUT_REPORT, HID_REQ_SET_REPORT);
41905+ hid_hw_raw_request(sc->hdev, report->report_id, (__u8 *)report,
41906+ sizeof(struct sixaxis_output_report),
41907+ HID_OUTPUT_REPORT, HID_REQ_SET_REPORT);
41908 }
41909
41910 static void dualshock4_state_worker(struct work_struct *work)
41911 {
41912 struct sony_sc *sc = container_of(work, struct sony_sc, state_worker);
41913 struct hid_device *hdev = sc->hdev;
41914+ __u8 *buf = sc->output_report_dmabuf;
41915 int offset;
41916
41917- __u8 buf[78] = { 0 };
41918-
41919 if (sc->quirks & DUALSHOCK4_CONTROLLER_USB) {
41920+ memset(buf, 0, DS4_REPORT_0x05_SIZE);
41921 buf[0] = 0x05;
41922 buf[1] = 0xFF;
41923 offset = 4;
41924 } else {
41925+ memset(buf, 0, DS4_REPORT_0x11_SIZE);
41926 buf[0] = 0x11;
41927 buf[1] = 0xB0;
41928 buf[3] = 0x0F;
41929@@ -1560,12 +1594,33 @@ static void dualshock4_state_worker(struct work_struct *work)
41930 buf[offset++] = sc->led_delay_off[3];
41931
41932 if (sc->quirks & DUALSHOCK4_CONTROLLER_USB)
41933- hid_hw_output_report(hdev, buf, 32);
41934+ hid_hw_output_report(hdev, buf, DS4_REPORT_0x05_SIZE);
41935 else
41936- hid_hw_raw_request(hdev, 0x11, buf, 78,
41937+ hid_hw_raw_request(hdev, 0x11, buf, DS4_REPORT_0x11_SIZE,
41938 HID_OUTPUT_REPORT, HID_REQ_SET_REPORT);
41939 }
41940
41941+static int sony_allocate_output_report(struct sony_sc *sc)
41942+{
41943+ if (sc->quirks & SIXAXIS_CONTROLLER)
41944+ sc->output_report_dmabuf =
41945+ kmalloc(sizeof(union sixaxis_output_report_01),
41946+ GFP_KERNEL);
41947+ else if (sc->quirks & DUALSHOCK4_CONTROLLER_BT)
41948+ sc->output_report_dmabuf = kmalloc(DS4_REPORT_0x11_SIZE,
41949+ GFP_KERNEL);
41950+ else if (sc->quirks & DUALSHOCK4_CONTROLLER_USB)
41951+ sc->output_report_dmabuf = kmalloc(DS4_REPORT_0x05_SIZE,
41952+ GFP_KERNEL);
41953+ else
41954+ return 0;
41955+
41956+ if (!sc->output_report_dmabuf)
41957+ return -ENOMEM;
41958+
41959+ return 0;
41960+}
41961+
41962 #ifdef CONFIG_SONY_FF
41963 static int sony_play_effect(struct input_dev *dev, void *data,
41964 struct ff_effect *effect)
41965@@ -1754,6 +1809,7 @@ static int sony_get_bt_devaddr(struct sony_sc *sc)
41966
41967 static int sony_check_add(struct sony_sc *sc)
41968 {
41969+ __u8 *buf = NULL;
41970 int n, ret;
41971
41972 if ((sc->quirks & DUALSHOCK4_CONTROLLER_BT) ||
41973@@ -1769,36 +1825,44 @@ static int sony_check_add(struct sony_sc *sc)
41974 return 0;
41975 }
41976 } else if (sc->quirks & DUALSHOCK4_CONTROLLER_USB) {
41977- __u8 buf[7];
41978+ buf = kmalloc(DS4_REPORT_0x81_SIZE, GFP_KERNEL);
41979+ if (!buf)
41980+ return -ENOMEM;
41981
41982 /*
41983 * The MAC address of a DS4 controller connected via USB can be
41984 * retrieved with feature report 0x81. The address begins at
41985 * offset 1.
41986 */
41987- ret = hid_hw_raw_request(sc->hdev, 0x81, buf, sizeof(buf),
41988- HID_FEATURE_REPORT, HID_REQ_GET_REPORT);
41989+ ret = hid_hw_raw_request(sc->hdev, 0x81, buf,
41990+ DS4_REPORT_0x81_SIZE, HID_FEATURE_REPORT,
41991+ HID_REQ_GET_REPORT);
41992
41993- if (ret != 7) {
41994+ if (ret != DS4_REPORT_0x81_SIZE) {
41995 hid_err(sc->hdev, "failed to retrieve feature report 0x81 with the DualShock 4 MAC address\n");
41996- return ret < 0 ? ret : -EINVAL;
41997+ ret = ret < 0 ? ret : -EINVAL;
41998+ goto out_free;
41999 }
42000
42001 memcpy(sc->mac_address, &buf[1], sizeof(sc->mac_address));
42002 } else if (sc->quirks & SIXAXIS_CONTROLLER_USB) {
42003- __u8 buf[18];
42004+ buf = kmalloc(SIXAXIS_REPORT_0xF2_SIZE, GFP_KERNEL);
42005+ if (!buf)
42006+ return -ENOMEM;
42007
42008 /*
42009 * The MAC address of a Sixaxis controller connected via USB can
42010 * be retrieved with feature report 0xf2. The address begins at
42011 * offset 4.
42012 */
42013- ret = hid_hw_raw_request(sc->hdev, 0xf2, buf, sizeof(buf),
42014- HID_FEATURE_REPORT, HID_REQ_GET_REPORT);
42015+ ret = hid_hw_raw_request(sc->hdev, 0xf2, buf,
42016+ SIXAXIS_REPORT_0xF2_SIZE, HID_FEATURE_REPORT,
42017+ HID_REQ_GET_REPORT);
42018
42019- if (ret != 18) {
42020+ if (ret != SIXAXIS_REPORT_0xF2_SIZE) {
42021 hid_err(sc->hdev, "failed to retrieve feature report 0xf2 with the Sixaxis MAC address\n");
42022- return ret < 0 ? ret : -EINVAL;
42023+ ret = ret < 0 ? ret : -EINVAL;
42024+ goto out_free;
42025 }
42026
42027 /*
42028@@ -1811,7 +1875,13 @@ static int sony_check_add(struct sony_sc *sc)
42029 return 0;
42030 }
42031
42032- return sony_check_add_dev_list(sc);
42033+ ret = sony_check_add_dev_list(sc);
42034+
42035+out_free:
42036+
42037+ kfree(buf);
42038+
42039+ return ret;
42040 }
42041
42042 static int sony_set_device_id(struct sony_sc *sc)
42043@@ -1895,6 +1965,12 @@ static int sony_probe(struct hid_device *hdev, const struct hid_device_id *id)
42044 return ret;
42045 }
42046
42047+ ret = sony_allocate_output_report(sc);
42048+ if (ret < 0) {
42049+ hid_err(hdev, "failed to allocate the output report buffer\n");
42050+ goto err_stop;
42051+ }
42052+
42053 ret = sony_set_device_id(sc);
42054 if (ret < 0) {
42055 hid_err(hdev, "failed to allocate the device id\n");
42056@@ -1984,6 +2060,7 @@ err_stop:
42057 if (sc->quirks & SONY_BATTERY_SUPPORT)
42058 sony_battery_remove(sc);
42059 sony_cancel_work_sync(sc);
42060+ kfree(sc->output_report_dmabuf);
42061 sony_remove_dev_list(sc);
42062 sony_release_device_id(sc);
42063 hid_hw_stop(hdev);
42064@@ -2004,6 +2081,8 @@ static void sony_remove(struct hid_device *hdev)
42065
42066 sony_cancel_work_sync(sc);
42067
42068+ kfree(sc->output_report_dmabuf);
42069+
42070 sony_remove_dev_list(sc);
42071
42072 sony_release_device_id(sc);
42073diff --git a/drivers/hid/hid-wiimote-debug.c b/drivers/hid/hid-wiimote-debug.c
42074index c13fb5b..55a3802 100644
42075--- a/drivers/hid/hid-wiimote-debug.c
42076+++ b/drivers/hid/hid-wiimote-debug.c
42077@@ -66,7 +66,7 @@ static ssize_t wiidebug_eeprom_read(struct file *f, char __user *u, size_t s,
42078 else if (size == 0)
42079 return -EIO;
42080
42081- if (copy_to_user(u, buf, size))
42082+ if (size > sizeof(buf) || copy_to_user(u, buf, size))
42083 return -EFAULT;
42084
42085 *off += size;
42086diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
42087index 433f72a..2926005 100644
42088--- a/drivers/hv/channel.c
42089+++ b/drivers/hv/channel.c
42090@@ -366,8 +366,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
42091 unsigned long flags;
42092 int ret = 0;
42093
42094- next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
42095- atomic_inc(&vmbus_connection.next_gpadl_handle);
42096+ next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
42097+ atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
42098
42099 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
42100 if (ret)
42101diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
42102index 3e4235c..877d0e5 100644
42103--- a/drivers/hv/hv.c
42104+++ b/drivers/hv/hv.c
42105@@ -112,7 +112,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
42106 u64 output_address = (output) ? virt_to_phys(output) : 0;
42107 u32 output_address_hi = output_address >> 32;
42108 u32 output_address_lo = output_address & 0xFFFFFFFF;
42109- void *hypercall_page = hv_context.hypercall_page;
42110+ void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
42111
42112 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
42113 "=a"(hv_status_lo) : "d" (control_hi),
42114@@ -156,7 +156,7 @@ int hv_init(void)
42115 /* See if the hypercall page is already set */
42116 rdmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64);
42117
42118- virtaddr = __vmalloc(PAGE_SIZE, GFP_KERNEL, PAGE_KERNEL_EXEC);
42119+ virtaddr = __vmalloc(PAGE_SIZE, GFP_KERNEL, PAGE_KERNEL_RX);
42120
42121 if (!virtaddr)
42122 goto cleanup;
42123diff --git a/drivers/hv/hv_balloon.c b/drivers/hv/hv_balloon.c
42124index 5e90c5d..d8fcefb 100644
42125--- a/drivers/hv/hv_balloon.c
42126+++ b/drivers/hv/hv_balloon.c
42127@@ -470,7 +470,7 @@ MODULE_PARM_DESC(hot_add, "If set attempt memory hot_add");
42128
42129 module_param(pressure_report_delay, uint, (S_IRUGO | S_IWUSR));
42130 MODULE_PARM_DESC(pressure_report_delay, "Delay in secs in reporting pressure");
42131-static atomic_t trans_id = ATOMIC_INIT(0);
42132+static atomic_unchecked_t trans_id = ATOMIC_INIT(0);
42133
42134 static int dm_ring_size = (5 * PAGE_SIZE);
42135
42136@@ -893,7 +893,7 @@ static void hot_add_req(struct work_struct *dummy)
42137 pr_info("Memory hot add failed\n");
42138
42139 dm->state = DM_INITIALIZED;
42140- resp.hdr.trans_id = atomic_inc_return(&trans_id);
42141+ resp.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
42142 vmbus_sendpacket(dm->dev->channel, &resp,
42143 sizeof(struct dm_hot_add_response),
42144 (unsigned long)NULL,
42145@@ -973,7 +973,7 @@ static void post_status(struct hv_dynmem_device *dm)
42146 memset(&status, 0, sizeof(struct dm_status));
42147 status.hdr.type = DM_STATUS_REPORT;
42148 status.hdr.size = sizeof(struct dm_status);
42149- status.hdr.trans_id = atomic_inc_return(&trans_id);
42150+ status.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
42151
42152 /*
42153 * The host expects the guest to report free memory.
42154@@ -993,7 +993,7 @@ static void post_status(struct hv_dynmem_device *dm)
42155 * send the status. This can happen if we were interrupted
42156 * after we picked our transaction ID.
42157 */
42158- if (status.hdr.trans_id != atomic_read(&trans_id))
42159+ if (status.hdr.trans_id != atomic_read_unchecked(&trans_id))
42160 return;
42161
42162 /*
42163@@ -1129,7 +1129,7 @@ static void balloon_up(struct work_struct *dummy)
42164 */
42165
42166 do {
42167- bl_resp->hdr.trans_id = atomic_inc_return(&trans_id);
42168+ bl_resp->hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
42169 ret = vmbus_sendpacket(dm_device.dev->channel,
42170 bl_resp,
42171 bl_resp->hdr.size,
42172@@ -1175,7 +1175,7 @@ static void balloon_down(struct hv_dynmem_device *dm,
42173
42174 memset(&resp, 0, sizeof(struct dm_unballoon_response));
42175 resp.hdr.type = DM_UNBALLOON_RESPONSE;
42176- resp.hdr.trans_id = atomic_inc_return(&trans_id);
42177+ resp.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
42178 resp.hdr.size = sizeof(struct dm_unballoon_response);
42179
42180 vmbus_sendpacket(dm_device.dev->channel, &resp,
42181@@ -1239,7 +1239,7 @@ static void version_resp(struct hv_dynmem_device *dm,
42182 memset(&version_req, 0, sizeof(struct dm_version_request));
42183 version_req.hdr.type = DM_VERSION_REQUEST;
42184 version_req.hdr.size = sizeof(struct dm_version_request);
42185- version_req.hdr.trans_id = atomic_inc_return(&trans_id);
42186+ version_req.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
42187 version_req.version.version = DYNMEM_PROTOCOL_VERSION_WIN7;
42188 version_req.is_last_attempt = 1;
42189
42190@@ -1409,7 +1409,7 @@ static int balloon_probe(struct hv_device *dev,
42191 memset(&version_req, 0, sizeof(struct dm_version_request));
42192 version_req.hdr.type = DM_VERSION_REQUEST;
42193 version_req.hdr.size = sizeof(struct dm_version_request);
42194- version_req.hdr.trans_id = atomic_inc_return(&trans_id);
42195+ version_req.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
42196 version_req.version.version = DYNMEM_PROTOCOL_VERSION_WIN8;
42197 version_req.is_last_attempt = 0;
42198
42199@@ -1440,7 +1440,7 @@ static int balloon_probe(struct hv_device *dev,
42200 memset(&cap_msg, 0, sizeof(struct dm_capabilities));
42201 cap_msg.hdr.type = DM_CAPABILITIES_REPORT;
42202 cap_msg.hdr.size = sizeof(struct dm_capabilities);
42203- cap_msg.hdr.trans_id = atomic_inc_return(&trans_id);
42204+ cap_msg.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
42205
42206 cap_msg.caps.cap_bits.balloon = 1;
42207 cap_msg.caps.cap_bits.hot_add = 1;
42208diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
42209index c386d8d..d6004c4 100644
42210--- a/drivers/hv/hyperv_vmbus.h
42211+++ b/drivers/hv/hyperv_vmbus.h
42212@@ -611,7 +611,7 @@ enum vmbus_connect_state {
42213 struct vmbus_connection {
42214 enum vmbus_connect_state conn_state;
42215
42216- atomic_t next_gpadl_handle;
42217+ atomic_unchecked_t next_gpadl_handle;
42218
42219 /*
42220 * Represents channel interrupts. Each bit position represents a
42221diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
42222index 4d6b269..2e23b86 100644
42223--- a/drivers/hv/vmbus_drv.c
42224+++ b/drivers/hv/vmbus_drv.c
42225@@ -807,10 +807,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
42226 {
42227 int ret = 0;
42228
42229- static atomic_t device_num = ATOMIC_INIT(0);
42230+ static atomic_unchecked_t device_num = ATOMIC_INIT(0);
42231
42232 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
42233- atomic_inc_return(&device_num));
42234+ atomic_inc_return_unchecked(&device_num));
42235
42236 child_device_obj->device.bus = &hv_bus;
42237 child_device_obj->device.parent = &hv_acpi_dev->dev;
42238diff --git a/drivers/hwmon/acpi_power_meter.c b/drivers/hwmon/acpi_power_meter.c
42239index 579bdf9..75118b5 100644
42240--- a/drivers/hwmon/acpi_power_meter.c
42241+++ b/drivers/hwmon/acpi_power_meter.c
42242@@ -116,7 +116,7 @@ struct sensor_template {
42243 struct device_attribute *devattr,
42244 const char *buf, size_t count);
42245 int index;
42246-};
42247+} __do_const;
42248
42249 /* Averaging interval */
42250 static int update_avg_interval(struct acpi_power_meter_resource *resource)
42251@@ -631,7 +631,7 @@ static int register_attrs(struct acpi_power_meter_resource *resource,
42252 struct sensor_template *attrs)
42253 {
42254 struct device *dev = &resource->acpi_dev->dev;
42255- struct sensor_device_attribute *sensors =
42256+ sensor_device_attribute_no_const *sensors =
42257 &resource->sensors[resource->num_sensors];
42258 int res = 0;
42259
42260diff --git a/drivers/hwmon/applesmc.c b/drivers/hwmon/applesmc.c
42261index 3288f13..71cfb4e 100644
42262--- a/drivers/hwmon/applesmc.c
42263+++ b/drivers/hwmon/applesmc.c
42264@@ -1106,7 +1106,7 @@ static int applesmc_create_nodes(struct applesmc_node_group *groups, int num)
42265 {
42266 struct applesmc_node_group *grp;
42267 struct applesmc_dev_attr *node;
42268- struct attribute *attr;
42269+ attribute_no_const *attr;
42270 int ret, i;
42271
42272 for (grp = groups; grp->format; grp++) {
42273diff --git a/drivers/hwmon/asus_atk0110.c b/drivers/hwmon/asus_atk0110.c
42274index cccef87..06ce8ec 100644
42275--- a/drivers/hwmon/asus_atk0110.c
42276+++ b/drivers/hwmon/asus_atk0110.c
42277@@ -147,10 +147,10 @@ MODULE_DEVICE_TABLE(acpi, atk_ids);
42278 struct atk_sensor_data {
42279 struct list_head list;
42280 struct atk_data *data;
42281- struct device_attribute label_attr;
42282- struct device_attribute input_attr;
42283- struct device_attribute limit1_attr;
42284- struct device_attribute limit2_attr;
42285+ device_attribute_no_const label_attr;
42286+ device_attribute_no_const input_attr;
42287+ device_attribute_no_const limit1_attr;
42288+ device_attribute_no_const limit2_attr;
42289 char label_attr_name[ATTR_NAME_SIZE];
42290 char input_attr_name[ATTR_NAME_SIZE];
42291 char limit1_attr_name[ATTR_NAME_SIZE];
42292@@ -270,7 +270,7 @@ static ssize_t atk_name_show(struct device *dev,
42293 static struct device_attribute atk_name_attr =
42294 __ATTR(name, 0444, atk_name_show, NULL);
42295
42296-static void atk_init_attribute(struct device_attribute *attr, char *name,
42297+static void atk_init_attribute(device_attribute_no_const *attr, char *name,
42298 sysfs_show_func show)
42299 {
42300 sysfs_attr_init(&attr->attr);
42301diff --git a/drivers/hwmon/coretemp.c b/drivers/hwmon/coretemp.c
42302index d76f0b7..55ae976 100644
42303--- a/drivers/hwmon/coretemp.c
42304+++ b/drivers/hwmon/coretemp.c
42305@@ -784,7 +784,7 @@ static int coretemp_cpu_callback(struct notifier_block *nfb,
42306 return NOTIFY_OK;
42307 }
42308
42309-static struct notifier_block coretemp_cpu_notifier __refdata = {
42310+static struct notifier_block coretemp_cpu_notifier = {
42311 .notifier_call = coretemp_cpu_callback,
42312 };
42313
42314diff --git a/drivers/hwmon/ibmaem.c b/drivers/hwmon/ibmaem.c
42315index 7a8a6fb..015c1fd 100644
42316--- a/drivers/hwmon/ibmaem.c
42317+++ b/drivers/hwmon/ibmaem.c
42318@@ -924,7 +924,7 @@ static int aem_register_sensors(struct aem_data *data,
42319 struct aem_rw_sensor_template *rw)
42320 {
42321 struct device *dev = &data->pdev->dev;
42322- struct sensor_device_attribute *sensors = data->sensors;
42323+ sensor_device_attribute_no_const *sensors = data->sensors;
42324 int err;
42325
42326 /* Set up read-only sensors */
42327diff --git a/drivers/hwmon/iio_hwmon.c b/drivers/hwmon/iio_hwmon.c
42328index 14c82da..09b25d7 100644
42329--- a/drivers/hwmon/iio_hwmon.c
42330+++ b/drivers/hwmon/iio_hwmon.c
42331@@ -61,7 +61,7 @@ static int iio_hwmon_probe(struct platform_device *pdev)
42332 {
42333 struct device *dev = &pdev->dev;
42334 struct iio_hwmon_state *st;
42335- struct sensor_device_attribute *a;
42336+ sensor_device_attribute_no_const *a;
42337 int ret, i;
42338 int in_i = 1, temp_i = 1, curr_i = 1;
42339 enum iio_chan_type type;
42340diff --git a/drivers/hwmon/nct6683.c b/drivers/hwmon/nct6683.c
42341index 7710f46..427a28d 100644
42342--- a/drivers/hwmon/nct6683.c
42343+++ b/drivers/hwmon/nct6683.c
42344@@ -397,11 +397,11 @@ static struct attribute_group *
42345 nct6683_create_attr_group(struct device *dev, struct sensor_template_group *tg,
42346 int repeat)
42347 {
42348- struct sensor_device_attribute_2 *a2;
42349- struct sensor_device_attribute *a;
42350+ sensor_device_attribute_2_no_const *a2;
42351+ sensor_device_attribute_no_const *a;
42352 struct sensor_device_template **t;
42353 struct sensor_device_attr_u *su;
42354- struct attribute_group *group;
42355+ attribute_group_no_const *group;
42356 struct attribute **attrs;
42357 int i, j, count;
42358
42359diff --git a/drivers/hwmon/nct6775.c b/drivers/hwmon/nct6775.c
42360index 504cbdd..35d6f25 100644
42361--- a/drivers/hwmon/nct6775.c
42362+++ b/drivers/hwmon/nct6775.c
42363@@ -943,10 +943,10 @@ static struct attribute_group *
42364 nct6775_create_attr_group(struct device *dev, struct sensor_template_group *tg,
42365 int repeat)
42366 {
42367- struct attribute_group *group;
42368+ attribute_group_no_const *group;
42369 struct sensor_device_attr_u *su;
42370- struct sensor_device_attribute *a;
42371- struct sensor_device_attribute_2 *a2;
42372+ sensor_device_attribute_no_const *a;
42373+ sensor_device_attribute_2_no_const *a2;
42374 struct attribute **attrs;
42375 struct sensor_device_template **t;
42376 int i, count;
42377diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
42378index 291d11f..3f0dbbd 100644
42379--- a/drivers/hwmon/pmbus/pmbus_core.c
42380+++ b/drivers/hwmon/pmbus/pmbus_core.c
42381@@ -783,7 +783,7 @@ static int pmbus_add_attribute(struct pmbus_data *data, struct attribute *attr)
42382 return 0;
42383 }
42384
42385-static void pmbus_dev_attr_init(struct device_attribute *dev_attr,
42386+static void pmbus_dev_attr_init(device_attribute_no_const *dev_attr,
42387 const char *name,
42388 umode_t mode,
42389 ssize_t (*show)(struct device *dev,
42390@@ -800,7 +800,7 @@ static void pmbus_dev_attr_init(struct device_attribute *dev_attr,
42391 dev_attr->store = store;
42392 }
42393
42394-static void pmbus_attr_init(struct sensor_device_attribute *a,
42395+static void pmbus_attr_init(sensor_device_attribute_no_const *a,
42396 const char *name,
42397 umode_t mode,
42398 ssize_t (*show)(struct device *dev,
42399@@ -822,7 +822,7 @@ static int pmbus_add_boolean(struct pmbus_data *data,
42400 u16 reg, u8 mask)
42401 {
42402 struct pmbus_boolean *boolean;
42403- struct sensor_device_attribute *a;
42404+ sensor_device_attribute_no_const *a;
42405
42406 boolean = devm_kzalloc(data->dev, sizeof(*boolean), GFP_KERNEL);
42407 if (!boolean)
42408@@ -847,7 +847,7 @@ static struct pmbus_sensor *pmbus_add_sensor(struct pmbus_data *data,
42409 bool update, bool readonly)
42410 {
42411 struct pmbus_sensor *sensor;
42412- struct device_attribute *a;
42413+ device_attribute_no_const *a;
42414
42415 sensor = devm_kzalloc(data->dev, sizeof(*sensor), GFP_KERNEL);
42416 if (!sensor)
42417@@ -878,7 +878,7 @@ static int pmbus_add_label(struct pmbus_data *data,
42418 const char *lstring, int index)
42419 {
42420 struct pmbus_label *label;
42421- struct device_attribute *a;
42422+ device_attribute_no_const *a;
42423
42424 label = devm_kzalloc(data->dev, sizeof(*label), GFP_KERNEL);
42425 if (!label)
42426diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
42427index 97cd45a..ac54d8b 100644
42428--- a/drivers/hwmon/sht15.c
42429+++ b/drivers/hwmon/sht15.c
42430@@ -169,7 +169,7 @@ struct sht15_data {
42431 int supply_uv;
42432 bool supply_uv_valid;
42433 struct work_struct update_supply_work;
42434- atomic_t interrupt_handled;
42435+ atomic_unchecked_t interrupt_handled;
42436 };
42437
42438 /**
42439@@ -542,13 +542,13 @@ static int sht15_measurement(struct sht15_data *data,
42440 ret = gpio_direction_input(data->pdata->gpio_data);
42441 if (ret)
42442 return ret;
42443- atomic_set(&data->interrupt_handled, 0);
42444+ atomic_set_unchecked(&data->interrupt_handled, 0);
42445
42446 enable_irq(gpio_to_irq(data->pdata->gpio_data));
42447 if (gpio_get_value(data->pdata->gpio_data) == 0) {
42448 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
42449 /* Only relevant if the interrupt hasn't occurred. */
42450- if (!atomic_read(&data->interrupt_handled))
42451+ if (!atomic_read_unchecked(&data->interrupt_handled))
42452 schedule_work(&data->read_work);
42453 }
42454 ret = wait_event_timeout(data->wait_queue,
42455@@ -820,7 +820,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
42456
42457 /* First disable the interrupt */
42458 disable_irq_nosync(irq);
42459- atomic_inc(&data->interrupt_handled);
42460+ atomic_inc_unchecked(&data->interrupt_handled);
42461 /* Then schedule a reading work struct */
42462 if (data->state != SHT15_READING_NOTHING)
42463 schedule_work(&data->read_work);
42464@@ -842,11 +842,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
42465 * If not, then start the interrupt again - care here as could
42466 * have gone low in meantime so verify it hasn't!
42467 */
42468- atomic_set(&data->interrupt_handled, 0);
42469+ atomic_set_unchecked(&data->interrupt_handled, 0);
42470 enable_irq(gpio_to_irq(data->pdata->gpio_data));
42471 /* If still not occurred or another handler was scheduled */
42472 if (gpio_get_value(data->pdata->gpio_data)
42473- || atomic_read(&data->interrupt_handled))
42474+ || atomic_read_unchecked(&data->interrupt_handled))
42475 return;
42476 }
42477
42478diff --git a/drivers/hwmon/via-cputemp.c b/drivers/hwmon/via-cputemp.c
42479index 8df43c5..b07b91d 100644
42480--- a/drivers/hwmon/via-cputemp.c
42481+++ b/drivers/hwmon/via-cputemp.c
42482@@ -296,7 +296,7 @@ static int via_cputemp_cpu_callback(struct notifier_block *nfb,
42483 return NOTIFY_OK;
42484 }
42485
42486-static struct notifier_block via_cputemp_cpu_notifier __refdata = {
42487+static struct notifier_block via_cputemp_cpu_notifier = {
42488 .notifier_call = via_cputemp_cpu_callback,
42489 };
42490
42491diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
42492index 65e3240..e6c511d 100644
42493--- a/drivers/i2c/busses/i2c-amd756-s4882.c
42494+++ b/drivers/i2c/busses/i2c-amd756-s4882.c
42495@@ -39,7 +39,7 @@
42496 extern struct i2c_adapter amd756_smbus;
42497
42498 static struct i2c_adapter *s4882_adapter;
42499-static struct i2c_algorithm *s4882_algo;
42500+static i2c_algorithm_no_const *s4882_algo;
42501
42502 /* Wrapper access functions for multiplexed SMBus */
42503 static DEFINE_MUTEX(amd756_lock);
42504diff --git a/drivers/i2c/busses/i2c-diolan-u2c.c b/drivers/i2c/busses/i2c-diolan-u2c.c
42505index b19a310..d6eece0 100644
42506--- a/drivers/i2c/busses/i2c-diolan-u2c.c
42507+++ b/drivers/i2c/busses/i2c-diolan-u2c.c
42508@@ -98,7 +98,7 @@ MODULE_PARM_DESC(frequency, "I2C clock frequency in hertz");
42509 /* usb layer */
42510
42511 /* Send command to device, and get response. */
42512-static int diolan_usb_transfer(struct i2c_diolan_u2c *dev)
42513+static int __intentional_overflow(-1) diolan_usb_transfer(struct i2c_diolan_u2c *dev)
42514 {
42515 int ret = 0;
42516 int actual;
42517diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
42518index 88eda09..cf40434 100644
42519--- a/drivers/i2c/busses/i2c-nforce2-s4985.c
42520+++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
42521@@ -37,7 +37,7 @@
42522 extern struct i2c_adapter *nforce2_smbus;
42523
42524 static struct i2c_adapter *s4985_adapter;
42525-static struct i2c_algorithm *s4985_algo;
42526+static i2c_algorithm_no_const *s4985_algo;
42527
42528 /* Wrapper access functions for multiplexed SMBus */
42529 static DEFINE_MUTEX(nforce2_lock);
42530diff --git a/drivers/i2c/i2c-dev.c b/drivers/i2c/i2c-dev.c
42531index 71c7a39..71dd3e0 100644
42532--- a/drivers/i2c/i2c-dev.c
42533+++ b/drivers/i2c/i2c-dev.c
42534@@ -272,7 +272,7 @@ static noinline int i2cdev_ioctl_rdrw(struct i2c_client *client,
42535 break;
42536 }
42537
42538- data_ptrs[i] = (u8 __user *)rdwr_pa[i].buf;
42539+ data_ptrs[i] = (u8 __force_user *)rdwr_pa[i].buf;
42540 rdwr_pa[i].buf = memdup_user(data_ptrs[i], rdwr_pa[i].len);
42541 if (IS_ERR(rdwr_pa[i].buf)) {
42542 res = PTR_ERR(rdwr_pa[i].buf);
42543diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
42544index 0b510ba..4fbb5085 100644
42545--- a/drivers/ide/ide-cd.c
42546+++ b/drivers/ide/ide-cd.c
42547@@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
42548 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
42549 if ((unsigned long)buf & alignment
42550 || blk_rq_bytes(rq) & q->dma_pad_mask
42551- || object_is_on_stack(buf))
42552+ || object_starts_on_stack(buf))
42553 drive->dma = 0;
42554 }
42555 }
42556diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
42557index af3e76d..96dfe5e 100644
42558--- a/drivers/iio/industrialio-core.c
42559+++ b/drivers/iio/industrialio-core.c
42560@@ -555,7 +555,7 @@ static ssize_t iio_write_channel_info(struct device *dev,
42561 }
42562
42563 static
42564-int __iio_device_attr_init(struct device_attribute *dev_attr,
42565+int __iio_device_attr_init(device_attribute_no_const *dev_attr,
42566 const char *postfix,
42567 struct iio_chan_spec const *chan,
42568 ssize_t (*readfunc)(struct device *dev,
42569diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
42570index e28a494..f7c2671 100644
42571--- a/drivers/infiniband/core/cm.c
42572+++ b/drivers/infiniband/core/cm.c
42573@@ -115,7 +115,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
42574
42575 struct cm_counter_group {
42576 struct kobject obj;
42577- atomic_long_t counter[CM_ATTR_COUNT];
42578+ atomic_long_unchecked_t counter[CM_ATTR_COUNT];
42579 };
42580
42581 struct cm_counter_attribute {
42582@@ -1398,7 +1398,7 @@ static void cm_dup_req_handler(struct cm_work *work,
42583 struct ib_mad_send_buf *msg = NULL;
42584 int ret;
42585
42586- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42587+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42588 counter[CM_REQ_COUNTER]);
42589
42590 /* Quick state check to discard duplicate REQs. */
42591@@ -1785,7 +1785,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
42592 if (!cm_id_priv)
42593 return;
42594
42595- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42596+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42597 counter[CM_REP_COUNTER]);
42598 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
42599 if (ret)
42600@@ -1952,7 +1952,7 @@ static int cm_rtu_handler(struct cm_work *work)
42601 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
42602 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
42603 spin_unlock_irq(&cm_id_priv->lock);
42604- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42605+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42606 counter[CM_RTU_COUNTER]);
42607 goto out;
42608 }
42609@@ -2135,7 +2135,7 @@ static int cm_dreq_handler(struct cm_work *work)
42610 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
42611 dreq_msg->local_comm_id);
42612 if (!cm_id_priv) {
42613- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42614+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42615 counter[CM_DREQ_COUNTER]);
42616 cm_issue_drep(work->port, work->mad_recv_wc);
42617 return -EINVAL;
42618@@ -2160,7 +2160,7 @@ static int cm_dreq_handler(struct cm_work *work)
42619 case IB_CM_MRA_REP_RCVD:
42620 break;
42621 case IB_CM_TIMEWAIT:
42622- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42623+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42624 counter[CM_DREQ_COUNTER]);
42625 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
42626 goto unlock;
42627@@ -2174,7 +2174,7 @@ static int cm_dreq_handler(struct cm_work *work)
42628 cm_free_msg(msg);
42629 goto deref;
42630 case IB_CM_DREQ_RCVD:
42631- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42632+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42633 counter[CM_DREQ_COUNTER]);
42634 goto unlock;
42635 default:
42636@@ -2541,7 +2541,7 @@ static int cm_mra_handler(struct cm_work *work)
42637 ib_modify_mad(cm_id_priv->av.port->mad_agent,
42638 cm_id_priv->msg, timeout)) {
42639 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
42640- atomic_long_inc(&work->port->
42641+ atomic_long_inc_unchecked(&work->port->
42642 counter_group[CM_RECV_DUPLICATES].
42643 counter[CM_MRA_COUNTER]);
42644 goto out;
42645@@ -2550,7 +2550,7 @@ static int cm_mra_handler(struct cm_work *work)
42646 break;
42647 case IB_CM_MRA_REQ_RCVD:
42648 case IB_CM_MRA_REP_RCVD:
42649- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42650+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42651 counter[CM_MRA_COUNTER]);
42652 /* fall through */
42653 default:
42654@@ -2712,7 +2712,7 @@ static int cm_lap_handler(struct cm_work *work)
42655 case IB_CM_LAP_IDLE:
42656 break;
42657 case IB_CM_MRA_LAP_SENT:
42658- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42659+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42660 counter[CM_LAP_COUNTER]);
42661 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
42662 goto unlock;
42663@@ -2728,7 +2728,7 @@ static int cm_lap_handler(struct cm_work *work)
42664 cm_free_msg(msg);
42665 goto deref;
42666 case IB_CM_LAP_RCVD:
42667- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42668+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42669 counter[CM_LAP_COUNTER]);
42670 goto unlock;
42671 default:
42672@@ -3012,7 +3012,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
42673 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
42674 if (cur_cm_id_priv) {
42675 spin_unlock_irq(&cm.lock);
42676- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42677+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42678 counter[CM_SIDR_REQ_COUNTER]);
42679 goto out; /* Duplicate message. */
42680 }
42681@@ -3224,10 +3224,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
42682 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
42683 msg->retries = 1;
42684
42685- atomic_long_add(1 + msg->retries,
42686+ atomic_long_add_unchecked(1 + msg->retries,
42687 &port->counter_group[CM_XMIT].counter[attr_index]);
42688 if (msg->retries)
42689- atomic_long_add(msg->retries,
42690+ atomic_long_add_unchecked(msg->retries,
42691 &port->counter_group[CM_XMIT_RETRIES].
42692 counter[attr_index]);
42693
42694@@ -3437,7 +3437,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
42695 }
42696
42697 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
42698- atomic_long_inc(&port->counter_group[CM_RECV].
42699+ atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
42700 counter[attr_id - CM_ATTR_ID_OFFSET]);
42701
42702 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
42703@@ -3668,7 +3668,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
42704 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
42705
42706 return sprintf(buf, "%ld\n",
42707- atomic_long_read(&group->counter[cm_attr->index]));
42708+ atomic_long_read_unchecked(&group->counter[cm_attr->index]));
42709 }
42710
42711 static const struct sysfs_ops cm_counter_ops = {
42712diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
42713index 9f5ad7c..588cd84 100644
42714--- a/drivers/infiniband/core/fmr_pool.c
42715+++ b/drivers/infiniband/core/fmr_pool.c
42716@@ -98,8 +98,8 @@ struct ib_fmr_pool {
42717
42718 struct task_struct *thread;
42719
42720- atomic_t req_ser;
42721- atomic_t flush_ser;
42722+ atomic_unchecked_t req_ser;
42723+ atomic_unchecked_t flush_ser;
42724
42725 wait_queue_head_t force_wait;
42726 };
42727@@ -179,10 +179,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
42728 struct ib_fmr_pool *pool = pool_ptr;
42729
42730 do {
42731- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
42732+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
42733 ib_fmr_batch_release(pool);
42734
42735- atomic_inc(&pool->flush_ser);
42736+ atomic_inc_unchecked(&pool->flush_ser);
42737 wake_up_interruptible(&pool->force_wait);
42738
42739 if (pool->flush_function)
42740@@ -190,7 +190,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
42741 }
42742
42743 set_current_state(TASK_INTERRUPTIBLE);
42744- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
42745+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
42746 !kthread_should_stop())
42747 schedule();
42748 __set_current_state(TASK_RUNNING);
42749@@ -282,8 +282,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
42750 pool->dirty_watermark = params->dirty_watermark;
42751 pool->dirty_len = 0;
42752 spin_lock_init(&pool->pool_lock);
42753- atomic_set(&pool->req_ser, 0);
42754- atomic_set(&pool->flush_ser, 0);
42755+ atomic_set_unchecked(&pool->req_ser, 0);
42756+ atomic_set_unchecked(&pool->flush_ser, 0);
42757 init_waitqueue_head(&pool->force_wait);
42758
42759 pool->thread = kthread_run(ib_fmr_cleanup_thread,
42760@@ -411,11 +411,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
42761 }
42762 spin_unlock_irq(&pool->pool_lock);
42763
42764- serial = atomic_inc_return(&pool->req_ser);
42765+ serial = atomic_inc_return_unchecked(&pool->req_ser);
42766 wake_up_process(pool->thread);
42767
42768 if (wait_event_interruptible(pool->force_wait,
42769- atomic_read(&pool->flush_ser) - serial >= 0))
42770+ atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
42771 return -EINTR;
42772
42773 return 0;
42774@@ -525,7 +525,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
42775 } else {
42776 list_add_tail(&fmr->list, &pool->dirty_list);
42777 if (++pool->dirty_len >= pool->dirty_watermark) {
42778- atomic_inc(&pool->req_ser);
42779+ atomic_inc_unchecked(&pool->req_ser);
42780 wake_up_process(pool->thread);
42781 }
42782 }
42783diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
42784index ec7a298..8742e59 100644
42785--- a/drivers/infiniband/hw/cxgb4/mem.c
42786+++ b/drivers/infiniband/hw/cxgb4/mem.c
42787@@ -249,7 +249,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
42788 int err;
42789 struct fw_ri_tpte tpt;
42790 u32 stag_idx;
42791- static atomic_t key;
42792+ static atomic_unchecked_t key;
42793
42794 if (c4iw_fatal_error(rdev))
42795 return -EIO;
42796@@ -270,7 +270,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
42797 if (rdev->stats.stag.cur > rdev->stats.stag.max)
42798 rdev->stats.stag.max = rdev->stats.stag.cur;
42799 mutex_unlock(&rdev->stats.lock);
42800- *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
42801+ *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
42802 }
42803 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
42804 __func__, stag_state, type, pdid, stag_idx);
42805diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
42806index 79b3dbc..96e5fcc 100644
42807--- a/drivers/infiniband/hw/ipath/ipath_rc.c
42808+++ b/drivers/infiniband/hw/ipath/ipath_rc.c
42809@@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
42810 struct ib_atomic_eth *ateth;
42811 struct ipath_ack_entry *e;
42812 u64 vaddr;
42813- atomic64_t *maddr;
42814+ atomic64_unchecked_t *maddr;
42815 u64 sdata;
42816 u32 rkey;
42817 u8 next;
42818@@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
42819 IB_ACCESS_REMOTE_ATOMIC)))
42820 goto nack_acc_unlck;
42821 /* Perform atomic OP and save result. */
42822- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
42823+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
42824 sdata = be64_to_cpu(ateth->swap_data);
42825 e = &qp->s_ack_queue[qp->r_head_ack_queue];
42826 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
42827- (u64) atomic64_add_return(sdata, maddr) - sdata :
42828+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
42829 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
42830 be64_to_cpu(ateth->compare_data),
42831 sdata);
42832diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
42833index 1f95bba..9530f87 100644
42834--- a/drivers/infiniband/hw/ipath/ipath_ruc.c
42835+++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
42836@@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
42837 unsigned long flags;
42838 struct ib_wc wc;
42839 u64 sdata;
42840- atomic64_t *maddr;
42841+ atomic64_unchecked_t *maddr;
42842 enum ib_wc_status send_status;
42843
42844 /*
42845@@ -382,11 +382,11 @@ again:
42846 IB_ACCESS_REMOTE_ATOMIC)))
42847 goto acc_err;
42848 /* Perform atomic OP and save result. */
42849- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
42850+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
42851 sdata = wqe->wr.wr.atomic.compare_add;
42852 *(u64 *) sqp->s_sge.sge.vaddr =
42853 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
42854- (u64) atomic64_add_return(sdata, maddr) - sdata :
42855+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
42856 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
42857 sdata, wqe->wr.wr.atomic.swap);
42858 goto send_comp;
42859diff --git a/drivers/infiniband/hw/mlx4/mad.c b/drivers/infiniband/hw/mlx4/mad.c
42860index 82a7dd8..8fb6ba6 100644
42861--- a/drivers/infiniband/hw/mlx4/mad.c
42862+++ b/drivers/infiniband/hw/mlx4/mad.c
42863@@ -98,7 +98,7 @@ __be64 mlx4_ib_gen_node_guid(void)
42864
42865 __be64 mlx4_ib_get_new_demux_tid(struct mlx4_ib_demux_ctx *ctx)
42866 {
42867- return cpu_to_be64(atomic_inc_return(&ctx->tid)) |
42868+ return cpu_to_be64(atomic_inc_return_unchecked(&ctx->tid)) |
42869 cpu_to_be64(0xff00000000000000LL);
42870 }
42871
42872diff --git a/drivers/infiniband/hw/mlx4/mcg.c b/drivers/infiniband/hw/mlx4/mcg.c
42873index ed327e6..ca1739e0 100644
42874--- a/drivers/infiniband/hw/mlx4/mcg.c
42875+++ b/drivers/infiniband/hw/mlx4/mcg.c
42876@@ -1041,7 +1041,7 @@ int mlx4_ib_mcg_port_init(struct mlx4_ib_demux_ctx *ctx)
42877 {
42878 char name[20];
42879
42880- atomic_set(&ctx->tid, 0);
42881+ atomic_set_unchecked(&ctx->tid, 0);
42882 sprintf(name, "mlx4_ib_mcg%d", ctx->port);
42883 ctx->mcg_wq = create_singlethread_workqueue(name);
42884 if (!ctx->mcg_wq)
42885diff --git a/drivers/infiniband/hw/mlx4/mlx4_ib.h b/drivers/infiniband/hw/mlx4/mlx4_ib.h
42886index 6eb743f..a7b0f6d 100644
42887--- a/drivers/infiniband/hw/mlx4/mlx4_ib.h
42888+++ b/drivers/infiniband/hw/mlx4/mlx4_ib.h
42889@@ -426,7 +426,7 @@ struct mlx4_ib_demux_ctx {
42890 struct list_head mcg_mgid0_list;
42891 struct workqueue_struct *mcg_wq;
42892 struct mlx4_ib_demux_pv_ctx **tun;
42893- atomic_t tid;
42894+ atomic_unchecked_t tid;
42895 int flushing; /* flushing the work queue */
42896 };
42897
42898diff --git a/drivers/infiniband/hw/mthca/mthca_cmd.c b/drivers/infiniband/hw/mthca/mthca_cmd.c
42899index 9d3e5c1..6f166df 100644
42900--- a/drivers/infiniband/hw/mthca/mthca_cmd.c
42901+++ b/drivers/infiniband/hw/mthca/mthca_cmd.c
42902@@ -772,7 +772,7 @@ static void mthca_setup_cmd_doorbells(struct mthca_dev *dev, u64 base)
42903 mthca_dbg(dev, "Mapped doorbell page for posting FW commands\n");
42904 }
42905
42906-int mthca_QUERY_FW(struct mthca_dev *dev)
42907+int __intentional_overflow(-1) mthca_QUERY_FW(struct mthca_dev *dev)
42908 {
42909 struct mthca_mailbox *mailbox;
42910 u32 *outbox;
42911@@ -1612,7 +1612,7 @@ int mthca_HW2SW_MPT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42912 CMD_TIME_CLASS_B);
42913 }
42914
42915-int mthca_WRITE_MTT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42916+int __intentional_overflow(-1) mthca_WRITE_MTT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42917 int num_mtt)
42918 {
42919 return mthca_cmd(dev, mailbox->dma, num_mtt, 0, CMD_WRITE_MTT,
42920@@ -1634,7 +1634,7 @@ int mthca_MAP_EQ(struct mthca_dev *dev, u64 event_mask, int unmap,
42921 0, CMD_MAP_EQ, CMD_TIME_CLASS_B);
42922 }
42923
42924-int mthca_SW2HW_EQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42925+int __intentional_overflow(-1) mthca_SW2HW_EQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42926 int eq_num)
42927 {
42928 return mthca_cmd(dev, mailbox->dma, eq_num, 0, CMD_SW2HW_EQ,
42929@@ -1857,7 +1857,7 @@ int mthca_CONF_SPECIAL_QP(struct mthca_dev *dev, int type, u32 qpn)
42930 CMD_TIME_CLASS_B);
42931 }
42932
42933-int mthca_MAD_IFC(struct mthca_dev *dev, int ignore_mkey, int ignore_bkey,
42934+int __intentional_overflow(-1) mthca_MAD_IFC(struct mthca_dev *dev, int ignore_mkey, int ignore_bkey,
42935 int port, struct ib_wc *in_wc, struct ib_grh *in_grh,
42936 void *in_mad, void *response_mad)
42937 {
42938diff --git a/drivers/infiniband/hw/mthca/mthca_main.c b/drivers/infiniband/hw/mthca/mthca_main.c
42939index ded76c1..0cf0a08 100644
42940--- a/drivers/infiniband/hw/mthca/mthca_main.c
42941+++ b/drivers/infiniband/hw/mthca/mthca_main.c
42942@@ -692,7 +692,7 @@ err_close:
42943 return err;
42944 }
42945
42946-static int mthca_setup_hca(struct mthca_dev *dev)
42947+static int __intentional_overflow(-1) mthca_setup_hca(struct mthca_dev *dev)
42948 {
42949 int err;
42950
42951diff --git a/drivers/infiniband/hw/mthca/mthca_mr.c b/drivers/infiniband/hw/mthca/mthca_mr.c
42952index ed9a989..6aa5dc2 100644
42953--- a/drivers/infiniband/hw/mthca/mthca_mr.c
42954+++ b/drivers/infiniband/hw/mthca/mthca_mr.c
42955@@ -81,7 +81,7 @@ struct mthca_mpt_entry {
42956 * through the bitmaps)
42957 */
42958
42959-static u32 mthca_buddy_alloc(struct mthca_buddy *buddy, int order)
42960+static u32 __intentional_overflow(-1) mthca_buddy_alloc(struct mthca_buddy *buddy, int order)
42961 {
42962 int o;
42963 int m;
42964@@ -426,7 +426,7 @@ static inline u32 adjust_key(struct mthca_dev *dev, u32 key)
42965 return key;
42966 }
42967
42968-int mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
42969+int __intentional_overflow(-1) mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
42970 u64 iova, u64 total_size, u32 access, struct mthca_mr *mr)
42971 {
42972 struct mthca_mailbox *mailbox;
42973@@ -516,7 +516,7 @@ int mthca_mr_alloc_notrans(struct mthca_dev *dev, u32 pd,
42974 return mthca_mr_alloc(dev, pd, 12, 0, ~0ULL, access, mr);
42975 }
42976
42977-int mthca_mr_alloc_phys(struct mthca_dev *dev, u32 pd,
42978+int __intentional_overflow(-1) mthca_mr_alloc_phys(struct mthca_dev *dev, u32 pd,
42979 u64 *buffer_list, int buffer_size_shift,
42980 int list_len, u64 iova, u64 total_size,
42981 u32 access, struct mthca_mr *mr)
42982diff --git a/drivers/infiniband/hw/mthca/mthca_provider.c b/drivers/infiniband/hw/mthca/mthca_provider.c
42983index 415f8e1..e34214e 100644
42984--- a/drivers/infiniband/hw/mthca/mthca_provider.c
42985+++ b/drivers/infiniband/hw/mthca/mthca_provider.c
42986@@ -764,7 +764,7 @@ unlock:
42987 return 0;
42988 }
42989
42990-static int mthca_resize_cq(struct ib_cq *ibcq, int entries, struct ib_udata *udata)
42991+static int __intentional_overflow(-1) mthca_resize_cq(struct ib_cq *ibcq, int entries, struct ib_udata *udata)
42992 {
42993 struct mthca_dev *dev = to_mdev(ibcq->device);
42994 struct mthca_cq *cq = to_mcq(ibcq);
42995diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
42996index 3b2a6dc..bce26ff 100644
42997--- a/drivers/infiniband/hw/nes/nes.c
42998+++ b/drivers/infiniband/hw/nes/nes.c
42999@@ -97,7 +97,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
43000 LIST_HEAD(nes_adapter_list);
43001 static LIST_HEAD(nes_dev_list);
43002
43003-atomic_t qps_destroyed;
43004+atomic_unchecked_t qps_destroyed;
43005
43006 static unsigned int ee_flsh_adapter;
43007 static unsigned int sysfs_nonidx_addr;
43008@@ -278,7 +278,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
43009 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
43010 struct nes_adapter *nesadapter = nesdev->nesadapter;
43011
43012- atomic_inc(&qps_destroyed);
43013+ atomic_inc_unchecked(&qps_destroyed);
43014
43015 /* Free the control structures */
43016
43017diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
43018index bd9d132..70d84f4 100644
43019--- a/drivers/infiniband/hw/nes/nes.h
43020+++ b/drivers/infiniband/hw/nes/nes.h
43021@@ -180,17 +180,17 @@ extern unsigned int nes_debug_level;
43022 extern unsigned int wqm_quanta;
43023 extern struct list_head nes_adapter_list;
43024
43025-extern atomic_t cm_connects;
43026-extern atomic_t cm_accepts;
43027-extern atomic_t cm_disconnects;
43028-extern atomic_t cm_closes;
43029-extern atomic_t cm_connecteds;
43030-extern atomic_t cm_connect_reqs;
43031-extern atomic_t cm_rejects;
43032-extern atomic_t mod_qp_timouts;
43033-extern atomic_t qps_created;
43034-extern atomic_t qps_destroyed;
43035-extern atomic_t sw_qps_destroyed;
43036+extern atomic_unchecked_t cm_connects;
43037+extern atomic_unchecked_t cm_accepts;
43038+extern atomic_unchecked_t cm_disconnects;
43039+extern atomic_unchecked_t cm_closes;
43040+extern atomic_unchecked_t cm_connecteds;
43041+extern atomic_unchecked_t cm_connect_reqs;
43042+extern atomic_unchecked_t cm_rejects;
43043+extern atomic_unchecked_t mod_qp_timouts;
43044+extern atomic_unchecked_t qps_created;
43045+extern atomic_unchecked_t qps_destroyed;
43046+extern atomic_unchecked_t sw_qps_destroyed;
43047 extern u32 mh_detected;
43048 extern u32 mh_pauses_sent;
43049 extern u32 cm_packets_sent;
43050@@ -199,16 +199,16 @@ extern u32 cm_packets_created;
43051 extern u32 cm_packets_received;
43052 extern u32 cm_packets_dropped;
43053 extern u32 cm_packets_retrans;
43054-extern atomic_t cm_listens_created;
43055-extern atomic_t cm_listens_destroyed;
43056+extern atomic_unchecked_t cm_listens_created;
43057+extern atomic_unchecked_t cm_listens_destroyed;
43058 extern u32 cm_backlog_drops;
43059-extern atomic_t cm_loopbacks;
43060-extern atomic_t cm_nodes_created;
43061-extern atomic_t cm_nodes_destroyed;
43062-extern atomic_t cm_accel_dropped_pkts;
43063-extern atomic_t cm_resets_recvd;
43064-extern atomic_t pau_qps_created;
43065-extern atomic_t pau_qps_destroyed;
43066+extern atomic_unchecked_t cm_loopbacks;
43067+extern atomic_unchecked_t cm_nodes_created;
43068+extern atomic_unchecked_t cm_nodes_destroyed;
43069+extern atomic_unchecked_t cm_accel_dropped_pkts;
43070+extern atomic_unchecked_t cm_resets_recvd;
43071+extern atomic_unchecked_t pau_qps_created;
43072+extern atomic_unchecked_t pau_qps_destroyed;
43073
43074 extern u32 int_mod_timer_init;
43075 extern u32 int_mod_cq_depth_256;
43076diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
43077index 6f09a72..cf4399d 100644
43078--- a/drivers/infiniband/hw/nes/nes_cm.c
43079+++ b/drivers/infiniband/hw/nes/nes_cm.c
43080@@ -69,14 +69,14 @@ u32 cm_packets_dropped;
43081 u32 cm_packets_retrans;
43082 u32 cm_packets_created;
43083 u32 cm_packets_received;
43084-atomic_t cm_listens_created;
43085-atomic_t cm_listens_destroyed;
43086+atomic_unchecked_t cm_listens_created;
43087+atomic_unchecked_t cm_listens_destroyed;
43088 u32 cm_backlog_drops;
43089-atomic_t cm_loopbacks;
43090-atomic_t cm_nodes_created;
43091-atomic_t cm_nodes_destroyed;
43092-atomic_t cm_accel_dropped_pkts;
43093-atomic_t cm_resets_recvd;
43094+atomic_unchecked_t cm_loopbacks;
43095+atomic_unchecked_t cm_nodes_created;
43096+atomic_unchecked_t cm_nodes_destroyed;
43097+atomic_unchecked_t cm_accel_dropped_pkts;
43098+atomic_unchecked_t cm_resets_recvd;
43099
43100 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
43101 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
43102@@ -135,28 +135,28 @@ static void record_ird_ord(struct nes_cm_node *, u16, u16);
43103 /* instance of function pointers for client API */
43104 /* set address of this instance to cm_core->cm_ops at cm_core alloc */
43105 static struct nes_cm_ops nes_cm_api = {
43106- mini_cm_accelerated,
43107- mini_cm_listen,
43108- mini_cm_del_listen,
43109- mini_cm_connect,
43110- mini_cm_close,
43111- mini_cm_accept,
43112- mini_cm_reject,
43113- mini_cm_recv_pkt,
43114- mini_cm_dealloc_core,
43115- mini_cm_get,
43116- mini_cm_set
43117+ .accelerated = mini_cm_accelerated,
43118+ .listen = mini_cm_listen,
43119+ .stop_listener = mini_cm_del_listen,
43120+ .connect = mini_cm_connect,
43121+ .close = mini_cm_close,
43122+ .accept = mini_cm_accept,
43123+ .reject = mini_cm_reject,
43124+ .recv_pkt = mini_cm_recv_pkt,
43125+ .destroy_cm_core = mini_cm_dealloc_core,
43126+ .get = mini_cm_get,
43127+ .set = mini_cm_set
43128 };
43129
43130 static struct nes_cm_core *g_cm_core;
43131
43132-atomic_t cm_connects;
43133-atomic_t cm_accepts;
43134-atomic_t cm_disconnects;
43135-atomic_t cm_closes;
43136-atomic_t cm_connecteds;
43137-atomic_t cm_connect_reqs;
43138-atomic_t cm_rejects;
43139+atomic_unchecked_t cm_connects;
43140+atomic_unchecked_t cm_accepts;
43141+atomic_unchecked_t cm_disconnects;
43142+atomic_unchecked_t cm_closes;
43143+atomic_unchecked_t cm_connecteds;
43144+atomic_unchecked_t cm_connect_reqs;
43145+atomic_unchecked_t cm_rejects;
43146
43147 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
43148 {
43149@@ -1436,7 +1436,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
43150 kfree(listener);
43151 listener = NULL;
43152 ret = 0;
43153- atomic_inc(&cm_listens_destroyed);
43154+ atomic_inc_unchecked(&cm_listens_destroyed);
43155 } else {
43156 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
43157 }
43158@@ -1637,7 +1637,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
43159 cm_node->rem_mac);
43160
43161 add_hte_node(cm_core, cm_node);
43162- atomic_inc(&cm_nodes_created);
43163+ atomic_inc_unchecked(&cm_nodes_created);
43164
43165 return cm_node;
43166 }
43167@@ -1698,7 +1698,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
43168 }
43169
43170 atomic_dec(&cm_core->node_cnt);
43171- atomic_inc(&cm_nodes_destroyed);
43172+ atomic_inc_unchecked(&cm_nodes_destroyed);
43173 nesqp = cm_node->nesqp;
43174 if (nesqp) {
43175 nesqp->cm_node = NULL;
43176@@ -1762,7 +1762,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
43177
43178 static void drop_packet(struct sk_buff *skb)
43179 {
43180- atomic_inc(&cm_accel_dropped_pkts);
43181+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
43182 dev_kfree_skb_any(skb);
43183 }
43184
43185@@ -1825,7 +1825,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
43186 {
43187
43188 int reset = 0; /* whether to send reset in case of err.. */
43189- atomic_inc(&cm_resets_recvd);
43190+ atomic_inc_unchecked(&cm_resets_recvd);
43191 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
43192 " refcnt=%d\n", cm_node, cm_node->state,
43193 atomic_read(&cm_node->ref_count));
43194@@ -2492,7 +2492,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
43195 rem_ref_cm_node(cm_node->cm_core, cm_node);
43196 return NULL;
43197 }
43198- atomic_inc(&cm_loopbacks);
43199+ atomic_inc_unchecked(&cm_loopbacks);
43200 loopbackremotenode->loopbackpartner = cm_node;
43201 loopbackremotenode->tcp_cntxt.rcv_wscale =
43202 NES_CM_DEFAULT_RCV_WND_SCALE;
43203@@ -2773,7 +2773,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
43204 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
43205 else {
43206 rem_ref_cm_node(cm_core, cm_node);
43207- atomic_inc(&cm_accel_dropped_pkts);
43208+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
43209 dev_kfree_skb_any(skb);
43210 }
43211 break;
43212@@ -3081,7 +3081,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
43213
43214 if ((cm_id) && (cm_id->event_handler)) {
43215 if (issue_disconn) {
43216- atomic_inc(&cm_disconnects);
43217+ atomic_inc_unchecked(&cm_disconnects);
43218 cm_event.event = IW_CM_EVENT_DISCONNECT;
43219 cm_event.status = disconn_status;
43220 cm_event.local_addr = cm_id->local_addr;
43221@@ -3103,7 +3103,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
43222 }
43223
43224 if (issue_close) {
43225- atomic_inc(&cm_closes);
43226+ atomic_inc_unchecked(&cm_closes);
43227 nes_disconnect(nesqp, 1);
43228
43229 cm_id->provider_data = nesqp;
43230@@ -3241,7 +3241,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
43231
43232 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
43233 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
43234- atomic_inc(&cm_accepts);
43235+ atomic_inc_unchecked(&cm_accepts);
43236
43237 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
43238 netdev_refcnt_read(nesvnic->netdev));
43239@@ -3439,7 +3439,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
43240 struct nes_cm_core *cm_core;
43241 u8 *start_buff;
43242
43243- atomic_inc(&cm_rejects);
43244+ atomic_inc_unchecked(&cm_rejects);
43245 cm_node = (struct nes_cm_node *)cm_id->provider_data;
43246 loopback = cm_node->loopbackpartner;
43247 cm_core = cm_node->cm_core;
43248@@ -3504,7 +3504,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
43249 ntohs(raddr->sin_port), ntohl(laddr->sin_addr.s_addr),
43250 ntohs(laddr->sin_port));
43251
43252- atomic_inc(&cm_connects);
43253+ atomic_inc_unchecked(&cm_connects);
43254 nesqp->active_conn = 1;
43255
43256 /* cache the cm_id in the qp */
43257@@ -3649,7 +3649,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
43258 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
43259 return err;
43260 }
43261- atomic_inc(&cm_listens_created);
43262+ atomic_inc_unchecked(&cm_listens_created);
43263 }
43264
43265 cm_id->add_ref(cm_id);
43266@@ -3756,7 +3756,7 @@ static void cm_event_connected(struct nes_cm_event *event)
43267
43268 if (nesqp->destroyed)
43269 return;
43270- atomic_inc(&cm_connecteds);
43271+ atomic_inc_unchecked(&cm_connecteds);
43272 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
43273 " local port 0x%04X. jiffies = %lu.\n",
43274 nesqp->hwqp.qp_id, ntohl(raddr->sin_addr.s_addr),
43275@@ -3941,7 +3941,7 @@ static void cm_event_reset(struct nes_cm_event *event)
43276
43277 cm_id->add_ref(cm_id);
43278 ret = cm_id->event_handler(cm_id, &cm_event);
43279- atomic_inc(&cm_closes);
43280+ atomic_inc_unchecked(&cm_closes);
43281 cm_event.event = IW_CM_EVENT_CLOSE;
43282 cm_event.status = 0;
43283 cm_event.provider_data = cm_id->provider_data;
43284@@ -3981,7 +3981,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
43285 return;
43286 cm_id = cm_node->cm_id;
43287
43288- atomic_inc(&cm_connect_reqs);
43289+ atomic_inc_unchecked(&cm_connect_reqs);
43290 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
43291 cm_node, cm_id, jiffies);
43292
43293@@ -4030,7 +4030,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
43294 return;
43295 cm_id = cm_node->cm_id;
43296
43297- atomic_inc(&cm_connect_reqs);
43298+ atomic_inc_unchecked(&cm_connect_reqs);
43299 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
43300 cm_node, cm_id, jiffies);
43301
43302diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
43303index 4166452..fc952c3 100644
43304--- a/drivers/infiniband/hw/nes/nes_mgt.c
43305+++ b/drivers/infiniband/hw/nes/nes_mgt.c
43306@@ -40,8 +40,8 @@
43307 #include "nes.h"
43308 #include "nes_mgt.h"
43309
43310-atomic_t pau_qps_created;
43311-atomic_t pau_qps_destroyed;
43312+atomic_unchecked_t pau_qps_created;
43313+atomic_unchecked_t pau_qps_destroyed;
43314
43315 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
43316 {
43317@@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
43318 {
43319 struct sk_buff *skb;
43320 unsigned long flags;
43321- atomic_inc(&pau_qps_destroyed);
43322+ atomic_inc_unchecked(&pau_qps_destroyed);
43323
43324 /* Free packets that have not yet been forwarded */
43325 /* Lock is acquired by skb_dequeue when removing the skb */
43326@@ -810,7 +810,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
43327 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
43328 skb_queue_head_init(&nesqp->pau_list);
43329 spin_lock_init(&nesqp->pau_lock);
43330- atomic_inc(&pau_qps_created);
43331+ atomic_inc_unchecked(&pau_qps_created);
43332 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
43333 }
43334
43335diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
43336index 49eb511..a774366 100644
43337--- a/drivers/infiniband/hw/nes/nes_nic.c
43338+++ b/drivers/infiniband/hw/nes/nes_nic.c
43339@@ -1273,39 +1273,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
43340 target_stat_values[++index] = mh_detected;
43341 target_stat_values[++index] = mh_pauses_sent;
43342 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
43343- target_stat_values[++index] = atomic_read(&cm_connects);
43344- target_stat_values[++index] = atomic_read(&cm_accepts);
43345- target_stat_values[++index] = atomic_read(&cm_disconnects);
43346- target_stat_values[++index] = atomic_read(&cm_connecteds);
43347- target_stat_values[++index] = atomic_read(&cm_connect_reqs);
43348- target_stat_values[++index] = atomic_read(&cm_rejects);
43349- target_stat_values[++index] = atomic_read(&mod_qp_timouts);
43350- target_stat_values[++index] = atomic_read(&qps_created);
43351- target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
43352- target_stat_values[++index] = atomic_read(&qps_destroyed);
43353- target_stat_values[++index] = atomic_read(&cm_closes);
43354+ target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
43355+ target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
43356+ target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
43357+ target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
43358+ target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
43359+ target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
43360+ target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
43361+ target_stat_values[++index] = atomic_read_unchecked(&qps_created);
43362+ target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
43363+ target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
43364+ target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
43365 target_stat_values[++index] = cm_packets_sent;
43366 target_stat_values[++index] = cm_packets_bounced;
43367 target_stat_values[++index] = cm_packets_created;
43368 target_stat_values[++index] = cm_packets_received;
43369 target_stat_values[++index] = cm_packets_dropped;
43370 target_stat_values[++index] = cm_packets_retrans;
43371- target_stat_values[++index] = atomic_read(&cm_listens_created);
43372- target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
43373+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
43374+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
43375 target_stat_values[++index] = cm_backlog_drops;
43376- target_stat_values[++index] = atomic_read(&cm_loopbacks);
43377- target_stat_values[++index] = atomic_read(&cm_nodes_created);
43378- target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
43379- target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
43380- target_stat_values[++index] = atomic_read(&cm_resets_recvd);
43381+ target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
43382+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
43383+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
43384+ target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
43385+ target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
43386 target_stat_values[++index] = nesadapter->free_4kpbl;
43387 target_stat_values[++index] = nesadapter->free_256pbl;
43388 target_stat_values[++index] = int_mod_timer_init;
43389 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
43390 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
43391 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
43392- target_stat_values[++index] = atomic_read(&pau_qps_created);
43393- target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
43394+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
43395+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
43396 }
43397
43398 /**
43399diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
43400index fef067c..6a25ccd 100644
43401--- a/drivers/infiniband/hw/nes/nes_verbs.c
43402+++ b/drivers/infiniband/hw/nes/nes_verbs.c
43403@@ -46,9 +46,9 @@
43404
43405 #include <rdma/ib_umem.h>
43406
43407-atomic_t mod_qp_timouts;
43408-atomic_t qps_created;
43409-atomic_t sw_qps_destroyed;
43410+atomic_unchecked_t mod_qp_timouts;
43411+atomic_unchecked_t qps_created;
43412+atomic_unchecked_t sw_qps_destroyed;
43413
43414 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
43415
43416@@ -1134,7 +1134,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
43417 if (init_attr->create_flags)
43418 return ERR_PTR(-EINVAL);
43419
43420- atomic_inc(&qps_created);
43421+ atomic_inc_unchecked(&qps_created);
43422 switch (init_attr->qp_type) {
43423 case IB_QPT_RC:
43424 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
43425@@ -1468,7 +1468,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
43426 struct iw_cm_event cm_event;
43427 int ret = 0;
43428
43429- atomic_inc(&sw_qps_destroyed);
43430+ atomic_inc_unchecked(&sw_qps_destroyed);
43431 nesqp->destroyed = 1;
43432
43433 /* Blow away the connection if it exists. */
43434diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
43435index c00ae09..04e91be 100644
43436--- a/drivers/infiniband/hw/qib/qib.h
43437+++ b/drivers/infiniband/hw/qib/qib.h
43438@@ -52,6 +52,7 @@
43439 #include <linux/kref.h>
43440 #include <linux/sched.h>
43441 #include <linux/kthread.h>
43442+#include <linux/slab.h>
43443
43444 #include "qib_common.h"
43445 #include "qib_verbs.h"
43446diff --git a/drivers/infiniband/ulp/ipoib/ipoib_netlink.c b/drivers/infiniband/ulp/ipoib/ipoib_netlink.c
43447index cdc7df4..a2fdfdb 100644
43448--- a/drivers/infiniband/ulp/ipoib/ipoib_netlink.c
43449+++ b/drivers/infiniband/ulp/ipoib/ipoib_netlink.c
43450@@ -156,7 +156,7 @@ static size_t ipoib_get_size(const struct net_device *dev)
43451 nla_total_size(2); /* IFLA_IPOIB_UMCAST */
43452 }
43453
43454-static struct rtnl_link_ops ipoib_link_ops __read_mostly = {
43455+static struct rtnl_link_ops ipoib_link_ops = {
43456 .kind = "ipoib",
43457 .maxtype = IFLA_IPOIB_MAX,
43458 .policy = ipoib_policy,
43459diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
43460index e29c04e..adbf68c 100644
43461--- a/drivers/input/gameport/gameport.c
43462+++ b/drivers/input/gameport/gameport.c
43463@@ -527,14 +527,14 @@ EXPORT_SYMBOL(gameport_set_phys);
43464 */
43465 static void gameport_init_port(struct gameport *gameport)
43466 {
43467- static atomic_t gameport_no = ATOMIC_INIT(0);
43468+ static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
43469
43470 __module_get(THIS_MODULE);
43471
43472 mutex_init(&gameport->drv_mutex);
43473 device_initialize(&gameport->dev);
43474 dev_set_name(&gameport->dev, "gameport%lu",
43475- (unsigned long)atomic_inc_return(&gameport_no) - 1);
43476+ (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
43477 gameport->dev.bus = &gameport_bus;
43478 gameport->dev.release = gameport_release_port;
43479 if (gameport->parent)
43480diff --git a/drivers/input/input.c b/drivers/input/input.c
43481index 0f175f5..4c481c0 100644
43482--- a/drivers/input/input.c
43483+++ b/drivers/input/input.c
43484@@ -1775,7 +1775,7 @@ EXPORT_SYMBOL_GPL(input_class);
43485 */
43486 struct input_dev *input_allocate_device(void)
43487 {
43488- static atomic_t input_no = ATOMIC_INIT(0);
43489+ static atomic_unchecked_t input_no = ATOMIC_INIT(0);
43490 struct input_dev *dev;
43491
43492 dev = kzalloc(sizeof(struct input_dev), GFP_KERNEL);
43493@@ -1790,7 +1790,7 @@ struct input_dev *input_allocate_device(void)
43494 INIT_LIST_HEAD(&dev->node);
43495
43496 dev_set_name(&dev->dev, "input%lu",
43497- (unsigned long) atomic_inc_return(&input_no) - 1);
43498+ (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
43499
43500 __module_get(THIS_MODULE);
43501 }
43502diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
43503index 4a95b22..874c182 100644
43504--- a/drivers/input/joystick/sidewinder.c
43505+++ b/drivers/input/joystick/sidewinder.c
43506@@ -30,6 +30,7 @@
43507 #include <linux/kernel.h>
43508 #include <linux/module.h>
43509 #include <linux/slab.h>
43510+#include <linux/sched.h>
43511 #include <linux/input.h>
43512 #include <linux/gameport.h>
43513 #include <linux/jiffies.h>
43514diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
43515index fc55f0d..11e2aa6 100644
43516--- a/drivers/input/joystick/xpad.c
43517+++ b/drivers/input/joystick/xpad.c
43518@@ -886,7 +886,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
43519
43520 static int xpad_led_probe(struct usb_xpad *xpad)
43521 {
43522- static atomic_t led_seq = ATOMIC_INIT(0);
43523+ static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
43524 long led_no;
43525 struct xpad_led *led;
43526 struct led_classdev *led_cdev;
43527@@ -899,7 +899,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
43528 if (!led)
43529 return -ENOMEM;
43530
43531- led_no = (long)atomic_inc_return(&led_seq) - 1;
43532+ led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
43533
43534 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
43535 led->xpad = xpad;
43536diff --git a/drivers/input/misc/ims-pcu.c b/drivers/input/misc/ims-pcu.c
43537index afed8e2..3aa8a18 100644
43538--- a/drivers/input/misc/ims-pcu.c
43539+++ b/drivers/input/misc/ims-pcu.c
43540@@ -1851,7 +1851,7 @@ static int ims_pcu_identify_type(struct ims_pcu *pcu, u8 *device_id)
43541
43542 static int ims_pcu_init_application_mode(struct ims_pcu *pcu)
43543 {
43544- static atomic_t device_no = ATOMIC_INIT(0);
43545+ static atomic_unchecked_t device_no = ATOMIC_INIT(0);
43546
43547 const struct ims_pcu_device_info *info;
43548 int error;
43549@@ -1882,7 +1882,7 @@ static int ims_pcu_init_application_mode(struct ims_pcu *pcu)
43550 }
43551
43552 /* Device appears to be operable, complete initialization */
43553- pcu->device_no = atomic_inc_return(&device_no) - 1;
43554+ pcu->device_no = atomic_inc_return_unchecked(&device_no) - 1;
43555
43556 /*
43557 * PCU-B devices, both GEN_1 and GEN_2 do not have OFN sensor
43558diff --git a/drivers/input/mouse/psmouse.h b/drivers/input/mouse/psmouse.h
43559index f4cf664..3204fda 100644
43560--- a/drivers/input/mouse/psmouse.h
43561+++ b/drivers/input/mouse/psmouse.h
43562@@ -117,7 +117,7 @@ struct psmouse_attribute {
43563 ssize_t (*set)(struct psmouse *psmouse, void *data,
43564 const char *buf, size_t count);
43565 bool protect;
43566-};
43567+} __do_const;
43568 #define to_psmouse_attr(a) container_of((a), struct psmouse_attribute, dattr)
43569
43570 ssize_t psmouse_attr_show_helper(struct device *dev, struct device_attribute *attr,
43571diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
43572index b604564..3f14ae4 100644
43573--- a/drivers/input/mousedev.c
43574+++ b/drivers/input/mousedev.c
43575@@ -744,7 +744,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
43576
43577 spin_unlock_irq(&client->packet_lock);
43578
43579- if (copy_to_user(buffer, data, count))
43580+ if (count > sizeof(data) || copy_to_user(buffer, data, count))
43581 return -EFAULT;
43582
43583 return count;
43584diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
43585index d399b8b..4913ede 100644
43586--- a/drivers/input/serio/serio.c
43587+++ b/drivers/input/serio/serio.c
43588@@ -514,7 +514,7 @@ static void serio_release_port(struct device *dev)
43589 */
43590 static void serio_init_port(struct serio *serio)
43591 {
43592- static atomic_t serio_no = ATOMIC_INIT(0);
43593+ static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
43594
43595 __module_get(THIS_MODULE);
43596
43597@@ -525,7 +525,7 @@ static void serio_init_port(struct serio *serio)
43598 mutex_init(&serio->drv_mutex);
43599 device_initialize(&serio->dev);
43600 dev_set_name(&serio->dev, "serio%lu",
43601- (unsigned long)atomic_inc_return(&serio_no) - 1);
43602+ (unsigned long)atomic_inc_return_unchecked(&serio_no) - 1);
43603 serio->dev.bus = &serio_bus;
43604 serio->dev.release = serio_release_port;
43605 serio->dev.groups = serio_device_attr_groups;
43606diff --git a/drivers/input/serio/serio_raw.c b/drivers/input/serio/serio_raw.c
43607index c9a02fe..0debc75 100644
43608--- a/drivers/input/serio/serio_raw.c
43609+++ b/drivers/input/serio/serio_raw.c
43610@@ -292,7 +292,7 @@ static irqreturn_t serio_raw_interrupt(struct serio *serio, unsigned char data,
43611
43612 static int serio_raw_connect(struct serio *serio, struct serio_driver *drv)
43613 {
43614- static atomic_t serio_raw_no = ATOMIC_INIT(0);
43615+ static atomic_unchecked_t serio_raw_no = ATOMIC_INIT(0);
43616 struct serio_raw *serio_raw;
43617 int err;
43618
43619@@ -303,7 +303,7 @@ static int serio_raw_connect(struct serio *serio, struct serio_driver *drv)
43620 }
43621
43622 snprintf(serio_raw->name, sizeof(serio_raw->name),
43623- "serio_raw%ld", (long)atomic_inc_return(&serio_raw_no) - 1);
43624+ "serio_raw%ld", (long)atomic_inc_return_unchecked(&serio_raw_no) - 1);
43625 kref_init(&serio_raw->kref);
43626 INIT_LIST_HEAD(&serio_raw->client_list);
43627 init_waitqueue_head(&serio_raw->wait);
43628diff --git a/drivers/iommu/amd_iommu.c b/drivers/iommu/amd_iommu.c
43629index 505a9ad..356734c 100644
43630--- a/drivers/iommu/amd_iommu.c
43631+++ b/drivers/iommu/amd_iommu.c
43632@@ -823,11 +823,21 @@ static void copy_cmd_to_buffer(struct amd_iommu *iommu,
43633
43634 static void build_completion_wait(struct iommu_cmd *cmd, u64 address)
43635 {
43636+ phys_addr_t physaddr;
43637 WARN_ON(address & 0x7ULL);
43638
43639 memset(cmd, 0, sizeof(*cmd));
43640- cmd->data[0] = lower_32_bits(__pa(address)) | CMD_COMPL_WAIT_STORE_MASK;
43641- cmd->data[1] = upper_32_bits(__pa(address));
43642+
43643+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
43644+ if (object_starts_on_stack((void *)address)) {
43645+ void *adjbuf = (void *)address - current->stack + current->lowmem_stack;
43646+ physaddr = __pa((u64)adjbuf);
43647+ } else
43648+#endif
43649+ physaddr = __pa(address);
43650+
43651+ cmd->data[0] = lower_32_bits(physaddr) | CMD_COMPL_WAIT_STORE_MASK;
43652+ cmd->data[1] = upper_32_bits(physaddr);
43653 cmd->data[2] = 1;
43654 CMD_SET_TYPE(cmd, CMD_COMPL_WAIT);
43655 }
43656diff --git a/drivers/iommu/arm-smmu.c b/drivers/iommu/arm-smmu.c
43657index 60558f7..5a02369 100644
43658--- a/drivers/iommu/arm-smmu.c
43659+++ b/drivers/iommu/arm-smmu.c
43660@@ -934,7 +934,7 @@ static int arm_smmu_init_domain_context(struct iommu_domain *domain,
43661 cfg->irptndx = cfg->cbndx;
43662 }
43663
43664- ACCESS_ONCE(smmu_domain->smmu) = smmu;
43665+ ACCESS_ONCE_RW(smmu_domain->smmu) = smmu;
43666 arm_smmu_init_context_bank(smmu_domain);
43667 spin_unlock_irqrestore(&smmu_domain->lock, flags);
43668
43669diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
43670index ed8b048..7fbcc01 100644
43671--- a/drivers/iommu/iommu.c
43672+++ b/drivers/iommu/iommu.c
43673@@ -802,7 +802,7 @@ static int iommu_bus_notifier(struct notifier_block *nb,
43674 static int iommu_bus_init(struct bus_type *bus, const struct iommu_ops *ops)
43675 {
43676 int err;
43677- struct notifier_block *nb;
43678+ notifier_block_no_const *nb;
43679 struct iommu_callback_data cb = {
43680 .ops = ops,
43681 };
43682diff --git a/drivers/iommu/irq_remapping.c b/drivers/iommu/irq_remapping.c
43683index 74a1767..5a359e8 100644
43684--- a/drivers/iommu/irq_remapping.c
43685+++ b/drivers/iommu/irq_remapping.c
43686@@ -361,7 +361,7 @@ int setup_hpet_msi_remapped(unsigned int irq, unsigned int id)
43687 void panic_if_irq_remap(const char *msg)
43688 {
43689 if (irq_remapping_enabled)
43690- panic(msg);
43691+ panic("%s", msg);
43692 }
43693
43694 static void ir_ack_apic_edge(struct irq_data *data)
43695@@ -382,10 +382,12 @@ static void ir_print_prefix(struct irq_data *data, struct seq_file *p)
43696
43697 void irq_remap_modify_chip_defaults(struct irq_chip *chip)
43698 {
43699- chip->irq_print_chip = ir_print_prefix;
43700- chip->irq_ack = ir_ack_apic_edge;
43701- chip->irq_eoi = ir_ack_apic_level;
43702- chip->irq_set_affinity = x86_io_apic_ops.set_affinity;
43703+ pax_open_kernel();
43704+ *(void **)&chip->irq_print_chip = ir_print_prefix;
43705+ *(void **)&chip->irq_ack = ir_ack_apic_edge;
43706+ *(void **)&chip->irq_eoi = ir_ack_apic_level;
43707+ *(void **)&chip->irq_set_affinity = x86_io_apic_ops.set_affinity;
43708+ pax_close_kernel();
43709 }
43710
43711 bool setup_remapped_irq(int irq, struct irq_cfg *cfg, struct irq_chip *chip)
43712diff --git a/drivers/irqchip/irq-gic.c b/drivers/irqchip/irq-gic.c
43713index 38493ff..001538b 100644
43714--- a/drivers/irqchip/irq-gic.c
43715+++ b/drivers/irqchip/irq-gic.c
43716@@ -84,7 +84,7 @@ static u8 gic_cpu_map[NR_GIC_CPU_IF] __read_mostly;
43717 * Supported arch specific GIC irq extension.
43718 * Default make them NULL.
43719 */
43720-struct irq_chip gic_arch_extn = {
43721+irq_chip_no_const gic_arch_extn = {
43722 .irq_eoi = NULL,
43723 .irq_mask = NULL,
43724 .irq_unmask = NULL,
43725@@ -311,7 +311,7 @@ static void gic_handle_cascade_irq(unsigned int irq, struct irq_desc *desc)
43726 chained_irq_exit(chip, desc);
43727 }
43728
43729-static struct irq_chip gic_chip = {
43730+static irq_chip_no_const gic_chip __read_only = {
43731 .name = "GIC",
43732 .irq_mask = gic_mask_irq,
43733 .irq_unmask = gic_unmask_irq,
43734diff --git a/drivers/irqchip/irq-renesas-intc-irqpin.c b/drivers/irqchip/irq-renesas-intc-irqpin.c
43735index 542e850..1bb094c 100644
43736--- a/drivers/irqchip/irq-renesas-intc-irqpin.c
43737+++ b/drivers/irqchip/irq-renesas-intc-irqpin.c
43738@@ -353,7 +353,7 @@ static int intc_irqpin_probe(struct platform_device *pdev)
43739 struct intc_irqpin_iomem *i;
43740 struct resource *io[INTC_IRQPIN_REG_NR];
43741 struct resource *irq;
43742- struct irq_chip *irq_chip;
43743+ irq_chip_no_const *irq_chip;
43744 void (*enable_fn)(struct irq_data *d);
43745 void (*disable_fn)(struct irq_data *d);
43746 const char *name = dev_name(dev);
43747diff --git a/drivers/irqchip/irq-renesas-irqc.c b/drivers/irqchip/irq-renesas-irqc.c
43748index 8777065..a4a9967 100644
43749--- a/drivers/irqchip/irq-renesas-irqc.c
43750+++ b/drivers/irqchip/irq-renesas-irqc.c
43751@@ -151,7 +151,7 @@ static int irqc_probe(struct platform_device *pdev)
43752 struct irqc_priv *p;
43753 struct resource *io;
43754 struct resource *irq;
43755- struct irq_chip *irq_chip;
43756+ irq_chip_no_const *irq_chip;
43757 const char *name = dev_name(&pdev->dev);
43758 int ret;
43759 int k;
43760diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
43761index 6a2df32..dc962f1 100644
43762--- a/drivers/isdn/capi/capi.c
43763+++ b/drivers/isdn/capi/capi.c
43764@@ -81,8 +81,8 @@ struct capiminor {
43765
43766 struct capi20_appl *ap;
43767 u32 ncci;
43768- atomic_t datahandle;
43769- atomic_t msgid;
43770+ atomic_unchecked_t datahandle;
43771+ atomic_unchecked_t msgid;
43772
43773 struct tty_port port;
43774 int ttyinstop;
43775@@ -391,7 +391,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
43776 capimsg_setu16(s, 2, mp->ap->applid);
43777 capimsg_setu8 (s, 4, CAPI_DATA_B3);
43778 capimsg_setu8 (s, 5, CAPI_RESP);
43779- capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
43780+ capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
43781 capimsg_setu32(s, 8, mp->ncci);
43782 capimsg_setu16(s, 12, datahandle);
43783 }
43784@@ -512,14 +512,14 @@ static void handle_minor_send(struct capiminor *mp)
43785 mp->outbytes -= len;
43786 spin_unlock_bh(&mp->outlock);
43787
43788- datahandle = atomic_inc_return(&mp->datahandle);
43789+ datahandle = atomic_inc_return_unchecked(&mp->datahandle);
43790 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
43791 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
43792 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
43793 capimsg_setu16(skb->data, 2, mp->ap->applid);
43794 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
43795 capimsg_setu8 (skb->data, 5, CAPI_REQ);
43796- capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
43797+ capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
43798 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
43799 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
43800 capimsg_setu16(skb->data, 16, len); /* Data length */
43801diff --git a/drivers/isdn/gigaset/bas-gigaset.c b/drivers/isdn/gigaset/bas-gigaset.c
43802index aecec6d..11e13c5 100644
43803--- a/drivers/isdn/gigaset/bas-gigaset.c
43804+++ b/drivers/isdn/gigaset/bas-gigaset.c
43805@@ -2565,22 +2565,22 @@ static int gigaset_post_reset(struct usb_interface *intf)
43806
43807
43808 static const struct gigaset_ops gigops = {
43809- gigaset_write_cmd,
43810- gigaset_write_room,
43811- gigaset_chars_in_buffer,
43812- gigaset_brkchars,
43813- gigaset_init_bchannel,
43814- gigaset_close_bchannel,
43815- gigaset_initbcshw,
43816- gigaset_freebcshw,
43817- gigaset_reinitbcshw,
43818- gigaset_initcshw,
43819- gigaset_freecshw,
43820- gigaset_set_modem_ctrl,
43821- gigaset_baud_rate,
43822- gigaset_set_line_ctrl,
43823- gigaset_isoc_send_skb,
43824- gigaset_isoc_input,
43825+ .write_cmd = gigaset_write_cmd,
43826+ .write_room = gigaset_write_room,
43827+ .chars_in_buffer = gigaset_chars_in_buffer,
43828+ .brkchars = gigaset_brkchars,
43829+ .init_bchannel = gigaset_init_bchannel,
43830+ .close_bchannel = gigaset_close_bchannel,
43831+ .initbcshw = gigaset_initbcshw,
43832+ .freebcshw = gigaset_freebcshw,
43833+ .reinitbcshw = gigaset_reinitbcshw,
43834+ .initcshw = gigaset_initcshw,
43835+ .freecshw = gigaset_freecshw,
43836+ .set_modem_ctrl = gigaset_set_modem_ctrl,
43837+ .baud_rate = gigaset_baud_rate,
43838+ .set_line_ctrl = gigaset_set_line_ctrl,
43839+ .send_skb = gigaset_isoc_send_skb,
43840+ .handle_input = gigaset_isoc_input,
43841 };
43842
43843 /* bas_gigaset_init
43844diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
43845index 600c79b..3752bab 100644
43846--- a/drivers/isdn/gigaset/interface.c
43847+++ b/drivers/isdn/gigaset/interface.c
43848@@ -130,9 +130,9 @@ static int if_open(struct tty_struct *tty, struct file *filp)
43849 }
43850 tty->driver_data = cs;
43851
43852- ++cs->port.count;
43853+ atomic_inc(&cs->port.count);
43854
43855- if (cs->port.count == 1) {
43856+ if (atomic_read(&cs->port.count) == 1) {
43857 tty_port_tty_set(&cs->port, tty);
43858 cs->port.low_latency = 1;
43859 }
43860@@ -156,9 +156,9 @@ static void if_close(struct tty_struct *tty, struct file *filp)
43861
43862 if (!cs->connected)
43863 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
43864- else if (!cs->port.count)
43865+ else if (!atomic_read(&cs->port.count))
43866 dev_warn(cs->dev, "%s: device not opened\n", __func__);
43867- else if (!--cs->port.count)
43868+ else if (!atomic_dec_return(&cs->port.count))
43869 tty_port_tty_set(&cs->port, NULL);
43870
43871 mutex_unlock(&cs->mutex);
43872diff --git a/drivers/isdn/gigaset/ser-gigaset.c b/drivers/isdn/gigaset/ser-gigaset.c
43873index 8c91fd5..14f13ce 100644
43874--- a/drivers/isdn/gigaset/ser-gigaset.c
43875+++ b/drivers/isdn/gigaset/ser-gigaset.c
43876@@ -453,22 +453,22 @@ static int gigaset_set_line_ctrl(struct cardstate *cs, unsigned cflag)
43877 }
43878
43879 static const struct gigaset_ops ops = {
43880- gigaset_write_cmd,
43881- gigaset_write_room,
43882- gigaset_chars_in_buffer,
43883- gigaset_brkchars,
43884- gigaset_init_bchannel,
43885- gigaset_close_bchannel,
43886- gigaset_initbcshw,
43887- gigaset_freebcshw,
43888- gigaset_reinitbcshw,
43889- gigaset_initcshw,
43890- gigaset_freecshw,
43891- gigaset_set_modem_ctrl,
43892- gigaset_baud_rate,
43893- gigaset_set_line_ctrl,
43894- gigaset_m10x_send_skb, /* asyncdata.c */
43895- gigaset_m10x_input, /* asyncdata.c */
43896+ .write_cmd = gigaset_write_cmd,
43897+ .write_room = gigaset_write_room,
43898+ .chars_in_buffer = gigaset_chars_in_buffer,
43899+ .brkchars = gigaset_brkchars,
43900+ .init_bchannel = gigaset_init_bchannel,
43901+ .close_bchannel = gigaset_close_bchannel,
43902+ .initbcshw = gigaset_initbcshw,
43903+ .freebcshw = gigaset_freebcshw,
43904+ .reinitbcshw = gigaset_reinitbcshw,
43905+ .initcshw = gigaset_initcshw,
43906+ .freecshw = gigaset_freecshw,
43907+ .set_modem_ctrl = gigaset_set_modem_ctrl,
43908+ .baud_rate = gigaset_baud_rate,
43909+ .set_line_ctrl = gigaset_set_line_ctrl,
43910+ .send_skb = gigaset_m10x_send_skb, /* asyncdata.c */
43911+ .handle_input = gigaset_m10x_input, /* asyncdata.c */
43912 };
43913
43914
43915diff --git a/drivers/isdn/gigaset/usb-gigaset.c b/drivers/isdn/gigaset/usb-gigaset.c
43916index a8e652d..edadaa4 100644
43917--- a/drivers/isdn/gigaset/usb-gigaset.c
43918+++ b/drivers/isdn/gigaset/usb-gigaset.c
43919@@ -548,7 +548,7 @@ static int gigaset_brkchars(struct cardstate *cs, const unsigned char buf[6])
43920 gigaset_dbg_buffer(DEBUG_USBREQ, "brkchars", 6, buf);
43921 memcpy(cs->hw.usb->bchars, buf, 6);
43922 return usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0x19, 0x41,
43923- 0, 0, &buf, 6, 2000);
43924+ 0, 0, buf, 6, 2000);
43925 }
43926
43927 static void gigaset_freebcshw(struct bc_state *bcs)
43928@@ -867,22 +867,22 @@ static int gigaset_pre_reset(struct usb_interface *intf)
43929 }
43930
43931 static const struct gigaset_ops ops = {
43932- gigaset_write_cmd,
43933- gigaset_write_room,
43934- gigaset_chars_in_buffer,
43935- gigaset_brkchars,
43936- gigaset_init_bchannel,
43937- gigaset_close_bchannel,
43938- gigaset_initbcshw,
43939- gigaset_freebcshw,
43940- gigaset_reinitbcshw,
43941- gigaset_initcshw,
43942- gigaset_freecshw,
43943- gigaset_set_modem_ctrl,
43944- gigaset_baud_rate,
43945- gigaset_set_line_ctrl,
43946- gigaset_m10x_send_skb,
43947- gigaset_m10x_input,
43948+ .write_cmd = gigaset_write_cmd,
43949+ .write_room = gigaset_write_room,
43950+ .chars_in_buffer = gigaset_chars_in_buffer,
43951+ .brkchars = gigaset_brkchars,
43952+ .init_bchannel = gigaset_init_bchannel,
43953+ .close_bchannel = gigaset_close_bchannel,
43954+ .initbcshw = gigaset_initbcshw,
43955+ .freebcshw = gigaset_freebcshw,
43956+ .reinitbcshw = gigaset_reinitbcshw,
43957+ .initcshw = gigaset_initcshw,
43958+ .freecshw = gigaset_freecshw,
43959+ .set_modem_ctrl = gigaset_set_modem_ctrl,
43960+ .baud_rate = gigaset_baud_rate,
43961+ .set_line_ctrl = gigaset_set_line_ctrl,
43962+ .send_skb = gigaset_m10x_send_skb,
43963+ .handle_input = gigaset_m10x_input,
43964 };
43965
43966 /*
43967diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
43968index 4d9b195..455075c 100644
43969--- a/drivers/isdn/hardware/avm/b1.c
43970+++ b/drivers/isdn/hardware/avm/b1.c
43971@@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart *t4file)
43972 }
43973 if (left) {
43974 if (t4file->user) {
43975- if (copy_from_user(buf, dp, left))
43976+ if (left > sizeof buf || copy_from_user(buf, dp, left))
43977 return -EFAULT;
43978 } else {
43979 memcpy(buf, dp, left);
43980@@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart *config)
43981 }
43982 if (left) {
43983 if (config->user) {
43984- if (copy_from_user(buf, dp, left))
43985+ if (left > sizeof buf || copy_from_user(buf, dp, left))
43986 return -EFAULT;
43987 } else {
43988 memcpy(buf, dp, left);
43989diff --git a/drivers/isdn/i4l/isdn_common.c b/drivers/isdn/i4l/isdn_common.c
43990index 9b856e1..fa03c92 100644
43991--- a/drivers/isdn/i4l/isdn_common.c
43992+++ b/drivers/isdn/i4l/isdn_common.c
43993@@ -1654,6 +1654,8 @@ isdn_ioctl(struct file *file, uint cmd, ulong arg)
43994 } else
43995 return -EINVAL;
43996 case IIOCDBGVAR:
43997+ if (!capable(CAP_SYS_RAWIO))
43998+ return -EPERM;
43999 if (arg) {
44000 if (copy_to_user(argp, &dev, sizeof(ulong)))
44001 return -EFAULT;
44002diff --git a/drivers/isdn/i4l/isdn_concap.c b/drivers/isdn/i4l/isdn_concap.c
44003index 91d5730..336523e 100644
44004--- a/drivers/isdn/i4l/isdn_concap.c
44005+++ b/drivers/isdn/i4l/isdn_concap.c
44006@@ -80,9 +80,9 @@ static int isdn_concap_dl_disconn_req(struct concap_proto *concap)
44007 }
44008
44009 struct concap_device_ops isdn_concap_reliable_dl_dops = {
44010- &isdn_concap_dl_data_req,
44011- &isdn_concap_dl_connect_req,
44012- &isdn_concap_dl_disconn_req
44013+ .data_req = &isdn_concap_dl_data_req,
44014+ .connect_req = &isdn_concap_dl_connect_req,
44015+ .disconn_req = &isdn_concap_dl_disconn_req
44016 };
44017
44018 /* The following should better go into a dedicated source file such that
44019diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
44020index bc91261..2ef7e36 100644
44021--- a/drivers/isdn/i4l/isdn_tty.c
44022+++ b/drivers/isdn/i4l/isdn_tty.c
44023@@ -1503,9 +1503,9 @@ isdn_tty_open(struct tty_struct *tty, struct file *filp)
44024
44025 #ifdef ISDN_DEBUG_MODEM_OPEN
44026 printk(KERN_DEBUG "isdn_tty_open %s, count = %d\n", tty->name,
44027- port->count);
44028+ atomic_read(&port->count));
44029 #endif
44030- port->count++;
44031+ atomic_inc(&port->count);
44032 port->tty = tty;
44033 /*
44034 * Start up serial port
44035@@ -1549,7 +1549,7 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
44036 #endif
44037 return;
44038 }
44039- if ((tty->count == 1) && (port->count != 1)) {
44040+ if ((tty->count == 1) && (atomic_read(&port->count) != 1)) {
44041 /*
44042 * Uh, oh. tty->count is 1, which means that the tty
44043 * structure will be freed. Info->count should always
44044@@ -1558,15 +1558,15 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
44045 * serial port won't be shutdown.
44046 */
44047 printk(KERN_ERR "isdn_tty_close: bad port count; tty->count is 1, "
44048- "info->count is %d\n", port->count);
44049- port->count = 1;
44050+ "info->count is %d\n", atomic_read(&port->count));
44051+ atomic_set(&port->count, 1);
44052 }
44053- if (--port->count < 0) {
44054+ if (atomic_dec_return(&port->count) < 0) {
44055 printk(KERN_ERR "isdn_tty_close: bad port count for ttyi%d: %d\n",
44056- info->line, port->count);
44057- port->count = 0;
44058+ info->line, atomic_read(&port->count));
44059+ atomic_set(&port->count, 0);
44060 }
44061- if (port->count) {
44062+ if (atomic_read(&port->count)) {
44063 #ifdef ISDN_DEBUG_MODEM_OPEN
44064 printk(KERN_DEBUG "isdn_tty_close after info->count != 0\n");
44065 #endif
44066@@ -1620,7 +1620,7 @@ isdn_tty_hangup(struct tty_struct *tty)
44067 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_hangup"))
44068 return;
44069 isdn_tty_shutdown(info);
44070- port->count = 0;
44071+ atomic_set(&port->count, 0);
44072 port->flags &= ~ASYNC_NORMAL_ACTIVE;
44073 port->tty = NULL;
44074 wake_up_interruptible(&port->open_wait);
44075@@ -1965,7 +1965,7 @@ isdn_tty_find_icall(int di, int ch, setup_parm *setup)
44076 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
44077 modem_info *info = &dev->mdm.info[i];
44078
44079- if (info->port.count == 0)
44080+ if (atomic_read(&info->port.count) == 0)
44081 continue;
44082 if ((info->emu.mdmreg[REG_SI1] & si2bit[si1]) && /* SI1 is matching */
44083 (info->emu.mdmreg[REG_SI2] == si2)) { /* SI2 is matching */
44084diff --git a/drivers/isdn/i4l/isdn_x25iface.c b/drivers/isdn/i4l/isdn_x25iface.c
44085index e2d4e58..40cd045 100644
44086--- a/drivers/isdn/i4l/isdn_x25iface.c
44087+++ b/drivers/isdn/i4l/isdn_x25iface.c
44088@@ -53,14 +53,14 @@ static int isdn_x25iface_disconn_ind(struct concap_proto *);
44089
44090
44091 static struct concap_proto_ops ix25_pops = {
44092- &isdn_x25iface_proto_new,
44093- &isdn_x25iface_proto_del,
44094- &isdn_x25iface_proto_restart,
44095- &isdn_x25iface_proto_close,
44096- &isdn_x25iface_xmit,
44097- &isdn_x25iface_receive,
44098- &isdn_x25iface_connect_ind,
44099- &isdn_x25iface_disconn_ind
44100+ .proto_new = &isdn_x25iface_proto_new,
44101+ .proto_del = &isdn_x25iface_proto_del,
44102+ .restart = &isdn_x25iface_proto_restart,
44103+ .close = &isdn_x25iface_proto_close,
44104+ .encap_and_xmit = &isdn_x25iface_xmit,
44105+ .data_ind = &isdn_x25iface_receive,
44106+ .connect_ind = &isdn_x25iface_connect_ind,
44107+ .disconn_ind = &isdn_x25iface_disconn_ind
44108 };
44109
44110 /* error message helper function */
44111diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
44112index 6a7447c..cae33fe 100644
44113--- a/drivers/isdn/icn/icn.c
44114+++ b/drivers/isdn/icn/icn.c
44115@@ -1045,7 +1045,7 @@ icn_writecmd(const u_char *buf, int len, int user, icn_card *card)
44116 if (count > len)
44117 count = len;
44118 if (user) {
44119- if (copy_from_user(msg, buf, count))
44120+ if (count > sizeof msg || copy_from_user(msg, buf, count))
44121 return -EFAULT;
44122 } else
44123 memcpy(msg, buf, count);
44124diff --git a/drivers/isdn/mISDN/dsp_cmx.c b/drivers/isdn/mISDN/dsp_cmx.c
44125index 87f7dff..7300125 100644
44126--- a/drivers/isdn/mISDN/dsp_cmx.c
44127+++ b/drivers/isdn/mISDN/dsp_cmx.c
44128@@ -1625,7 +1625,7 @@ unsigned long dsp_spl_jiffies; /* calculate the next time to fire */
44129 static u16 dsp_count; /* last sample count */
44130 static int dsp_count_valid; /* if we have last sample count */
44131
44132-void
44133+void __intentional_overflow(-1)
44134 dsp_cmx_send(void *arg)
44135 {
44136 struct dsp_conf *conf;
44137diff --git a/drivers/leds/leds-clevo-mail.c b/drivers/leds/leds-clevo-mail.c
44138index f58a354..fbae176 100644
44139--- a/drivers/leds/leds-clevo-mail.c
44140+++ b/drivers/leds/leds-clevo-mail.c
44141@@ -40,7 +40,7 @@ static int __init clevo_mail_led_dmi_callback(const struct dmi_system_id *id)
44142 * detected as working, but in reality it is not) as low as
44143 * possible.
44144 */
44145-static struct dmi_system_id clevo_mail_led_dmi_table[] __initdata = {
44146+static struct dmi_system_id clevo_mail_led_dmi_table[] __initconst = {
44147 {
44148 .callback = clevo_mail_led_dmi_callback,
44149 .ident = "Clevo D410J",
44150diff --git a/drivers/leds/leds-ss4200.c b/drivers/leds/leds-ss4200.c
44151index 046cb70..6b20d39 100644
44152--- a/drivers/leds/leds-ss4200.c
44153+++ b/drivers/leds/leds-ss4200.c
44154@@ -91,7 +91,7 @@ MODULE_PARM_DESC(nodetect, "Skip DMI-based hardware detection");
44155 * detected as working, but in reality it is not) as low as
44156 * possible.
44157 */
44158-static struct dmi_system_id nas_led_whitelist[] __initdata = {
44159+static struct dmi_system_id nas_led_whitelist[] __initconst = {
44160 {
44161 .callback = ss4200_led_dmi_callback,
44162 .ident = "Intel SS4200-E",
44163diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
44164index 6590558..a74c5dd 100644
44165--- a/drivers/lguest/core.c
44166+++ b/drivers/lguest/core.c
44167@@ -96,9 +96,17 @@ static __init int map_switcher(void)
44168 * The end address needs +1 because __get_vm_area allocates an
44169 * extra guard page, so we need space for that.
44170 */
44171+
44172+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
44173+ switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
44174+ VM_ALLOC | VM_KERNEXEC, switcher_addr, switcher_addr
44175+ + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
44176+#else
44177 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
44178 VM_ALLOC, switcher_addr, switcher_addr
44179 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
44180+#endif
44181+
44182 if (!switcher_vma) {
44183 err = -ENOMEM;
44184 printk("lguest: could not map switcher pages high\n");
44185@@ -121,7 +129,7 @@ static __init int map_switcher(void)
44186 * Now the Switcher is mapped at the right address, we can't fail!
44187 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
44188 */
44189- memcpy(switcher_vma->addr, start_switcher_text,
44190+ memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
44191 end_switcher_text - start_switcher_text);
44192
44193 printk(KERN_INFO "lguest: mapped switcher at %p\n",
44194diff --git a/drivers/lguest/page_tables.c b/drivers/lguest/page_tables.c
44195index e8b55c3..3514c37 100644
44196--- a/drivers/lguest/page_tables.c
44197+++ b/drivers/lguest/page_tables.c
44198@@ -559,7 +559,7 @@ void pin_page(struct lg_cpu *cpu, unsigned long vaddr)
44199 /*:*/
44200
44201 #ifdef CONFIG_X86_PAE
44202-static void release_pmd(pmd_t *spmd)
44203+static void __intentional_overflow(-1) release_pmd(pmd_t *spmd)
44204 {
44205 /* If the entry's not present, there's nothing to release. */
44206 if (pmd_flags(*spmd) & _PAGE_PRESENT) {
44207diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
44208index 922a1ac..9dd0c2a 100644
44209--- a/drivers/lguest/x86/core.c
44210+++ b/drivers/lguest/x86/core.c
44211@@ -59,7 +59,7 @@ static struct {
44212 /* Offset from where switcher.S was compiled to where we've copied it */
44213 static unsigned long switcher_offset(void)
44214 {
44215- return switcher_addr - (unsigned long)start_switcher_text;
44216+ return switcher_addr - (unsigned long)ktla_ktva(start_switcher_text);
44217 }
44218
44219 /* This cpu's struct lguest_pages (after the Switcher text page) */
44220@@ -99,7 +99,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
44221 * These copies are pretty cheap, so we do them unconditionally: */
44222 /* Save the current Host top-level page directory.
44223 */
44224+
44225+#ifdef CONFIG_PAX_PER_CPU_PGD
44226+ pages->state.host_cr3 = read_cr3();
44227+#else
44228 pages->state.host_cr3 = __pa(current->mm->pgd);
44229+#endif
44230+
44231 /*
44232 * Set up the Guest's page tables to see this CPU's pages (and no
44233 * other CPU's pages).
44234@@ -477,7 +483,7 @@ void __init lguest_arch_host_init(void)
44235 * compiled-in switcher code and the high-mapped copy we just made.
44236 */
44237 for (i = 0; i < IDT_ENTRIES; i++)
44238- default_idt_entries[i] += switcher_offset();
44239+ default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
44240
44241 /*
44242 * Set up the Switcher's per-cpu areas.
44243@@ -560,7 +566,7 @@ void __init lguest_arch_host_init(void)
44244 * it will be undisturbed when we switch. To change %cs and jump we
44245 * need this structure to feed to Intel's "lcall" instruction.
44246 */
44247- lguest_entry.offset = (long)switch_to_guest + switcher_offset();
44248+ lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
44249 lguest_entry.segment = LGUEST_CS;
44250
44251 /*
44252diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
44253index 40634b0..4f5855e 100644
44254--- a/drivers/lguest/x86/switcher_32.S
44255+++ b/drivers/lguest/x86/switcher_32.S
44256@@ -87,6 +87,7 @@
44257 #include <asm/page.h>
44258 #include <asm/segment.h>
44259 #include <asm/lguest.h>
44260+#include <asm/processor-flags.h>
44261
44262 // We mark the start of the code to copy
44263 // It's placed in .text tho it's never run here
44264@@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
44265 // Changes type when we load it: damn Intel!
44266 // For after we switch over our page tables
44267 // That entry will be read-only: we'd crash.
44268+
44269+#ifdef CONFIG_PAX_KERNEXEC
44270+ mov %cr0, %edx
44271+ xor $X86_CR0_WP, %edx
44272+ mov %edx, %cr0
44273+#endif
44274+
44275 movl $(GDT_ENTRY_TSS*8), %edx
44276 ltr %dx
44277
44278@@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
44279 // Let's clear it again for our return.
44280 // The GDT descriptor of the Host
44281 // Points to the table after two "size" bytes
44282- movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
44283+ movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
44284 // Clear "used" from type field (byte 5, bit 2)
44285- andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
44286+ andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
44287+
44288+#ifdef CONFIG_PAX_KERNEXEC
44289+ mov %cr0, %eax
44290+ xor $X86_CR0_WP, %eax
44291+ mov %eax, %cr0
44292+#endif
44293
44294 // Once our page table's switched, the Guest is live!
44295 // The Host fades as we run this final step.
44296@@ -295,13 +309,12 @@ deliver_to_host:
44297 // I consulted gcc, and it gave
44298 // These instructions, which I gladly credit:
44299 leal (%edx,%ebx,8), %eax
44300- movzwl (%eax),%edx
44301- movl 4(%eax), %eax
44302- xorw %ax, %ax
44303- orl %eax, %edx
44304+ movl 4(%eax), %edx
44305+ movw (%eax), %dx
44306 // Now the address of the handler's in %edx
44307 // We call it now: its "iret" drops us home.
44308- jmp *%edx
44309+ ljmp $__KERNEL_CS, $1f
44310+1: jmp *%edx
44311
44312 // Every interrupt can come to us here
44313 // But we must truly tell each apart.
44314diff --git a/drivers/md/bcache/closure.h b/drivers/md/bcache/closure.h
44315index a08e3ee..df8ade2 100644
44316--- a/drivers/md/bcache/closure.h
44317+++ b/drivers/md/bcache/closure.h
44318@@ -238,7 +238,7 @@ static inline void closure_set_stopped(struct closure *cl)
44319 static inline void set_closure_fn(struct closure *cl, closure_fn *fn,
44320 struct workqueue_struct *wq)
44321 {
44322- BUG_ON(object_is_on_stack(cl));
44323+ BUG_ON(object_starts_on_stack(cl));
44324 closure_set_ip(cl);
44325 cl->fn = fn;
44326 cl->wq = wq;
44327diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
44328index da3604e..7789cb4c 100644
44329--- a/drivers/md/bitmap.c
44330+++ b/drivers/md/bitmap.c
44331@@ -1771,7 +1771,7 @@ void bitmap_status(struct seq_file *seq, struct bitmap *bitmap)
44332 chunk_kb ? "KB" : "B");
44333 if (bitmap->storage.file) {
44334 seq_printf(seq, ", file: ");
44335- seq_path(seq, &bitmap->storage.file->f_path, " \t\n");
44336+ seq_path(seq, &bitmap->storage.file->f_path, " \t\n\\");
44337 }
44338
44339 seq_printf(seq, "\n");
44340diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
44341index 0be9381..114262b 100644
44342--- a/drivers/md/dm-ioctl.c
44343+++ b/drivers/md/dm-ioctl.c
44344@@ -1769,7 +1769,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
44345 cmd == DM_LIST_VERSIONS_CMD)
44346 return 0;
44347
44348- if ((cmd == DM_DEV_CREATE_CMD)) {
44349+ if (cmd == DM_DEV_CREATE_CMD) {
44350 if (!*param->name) {
44351 DMWARN("name not supplied when creating device");
44352 return -EINVAL;
44353diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
44354index 7dfdb5c..4caada6 100644
44355--- a/drivers/md/dm-raid1.c
44356+++ b/drivers/md/dm-raid1.c
44357@@ -40,7 +40,7 @@ enum dm_raid1_error {
44358
44359 struct mirror {
44360 struct mirror_set *ms;
44361- atomic_t error_count;
44362+ atomic_unchecked_t error_count;
44363 unsigned long error_type;
44364 struct dm_dev *dev;
44365 sector_t offset;
44366@@ -186,7 +186,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
44367 struct mirror *m;
44368
44369 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
44370- if (!atomic_read(&m->error_count))
44371+ if (!atomic_read_unchecked(&m->error_count))
44372 return m;
44373
44374 return NULL;
44375@@ -218,7 +218,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
44376 * simple way to tell if a device has encountered
44377 * errors.
44378 */
44379- atomic_inc(&m->error_count);
44380+ atomic_inc_unchecked(&m->error_count);
44381
44382 if (test_and_set_bit(error_type, &m->error_type))
44383 return;
44384@@ -409,7 +409,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
44385 struct mirror *m = get_default_mirror(ms);
44386
44387 do {
44388- if (likely(!atomic_read(&m->error_count)))
44389+ if (likely(!atomic_read_unchecked(&m->error_count)))
44390 return m;
44391
44392 if (m-- == ms->mirror)
44393@@ -423,7 +423,7 @@ static int default_ok(struct mirror *m)
44394 {
44395 struct mirror *default_mirror = get_default_mirror(m->ms);
44396
44397- return !atomic_read(&default_mirror->error_count);
44398+ return !atomic_read_unchecked(&default_mirror->error_count);
44399 }
44400
44401 static int mirror_available(struct mirror_set *ms, struct bio *bio)
44402@@ -560,7 +560,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
44403 */
44404 if (likely(region_in_sync(ms, region, 1)))
44405 m = choose_mirror(ms, bio->bi_iter.bi_sector);
44406- else if (m && atomic_read(&m->error_count))
44407+ else if (m && atomic_read_unchecked(&m->error_count))
44408 m = NULL;
44409
44410 if (likely(m))
44411@@ -927,7 +927,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
44412 }
44413
44414 ms->mirror[mirror].ms = ms;
44415- atomic_set(&(ms->mirror[mirror].error_count), 0);
44416+ atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
44417 ms->mirror[mirror].error_type = 0;
44418 ms->mirror[mirror].offset = offset;
44419
44420@@ -1342,7 +1342,7 @@ static void mirror_resume(struct dm_target *ti)
44421 */
44422 static char device_status_char(struct mirror *m)
44423 {
44424- if (!atomic_read(&(m->error_count)))
44425+ if (!atomic_read_unchecked(&(m->error_count)))
44426 return 'A';
44427
44428 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
44429diff --git a/drivers/md/dm-stats.c b/drivers/md/dm-stats.c
44430index 87f86c7..a1a4100 100644
44431--- a/drivers/md/dm-stats.c
44432+++ b/drivers/md/dm-stats.c
44433@@ -382,7 +382,7 @@ do_sync_free:
44434 synchronize_rcu_expedited();
44435 dm_stat_free(&s->rcu_head);
44436 } else {
44437- ACCESS_ONCE(dm_stat_need_rcu_barrier) = 1;
44438+ ACCESS_ONCE_RW(dm_stat_need_rcu_barrier) = 1;
44439 call_rcu(&s->rcu_head, dm_stat_free);
44440 }
44441 return 0;
44442@@ -554,8 +554,8 @@ void dm_stats_account_io(struct dm_stats *stats, unsigned long bi_rw,
44443 ((bi_rw & (REQ_WRITE | REQ_DISCARD)) ==
44444 (ACCESS_ONCE(last->last_rw) & (REQ_WRITE | REQ_DISCARD)))
44445 ));
44446- ACCESS_ONCE(last->last_sector) = end_sector;
44447- ACCESS_ONCE(last->last_rw) = bi_rw;
44448+ ACCESS_ONCE_RW(last->last_sector) = end_sector;
44449+ ACCESS_ONCE_RW(last->last_rw) = bi_rw;
44450 }
44451
44452 rcu_read_lock();
44453diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
44454index f8b37d4..5c5cafd 100644
44455--- a/drivers/md/dm-stripe.c
44456+++ b/drivers/md/dm-stripe.c
44457@@ -21,7 +21,7 @@ struct stripe {
44458 struct dm_dev *dev;
44459 sector_t physical_start;
44460
44461- atomic_t error_count;
44462+ atomic_unchecked_t error_count;
44463 };
44464
44465 struct stripe_c {
44466@@ -188,7 +188,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
44467 kfree(sc);
44468 return r;
44469 }
44470- atomic_set(&(sc->stripe[i].error_count), 0);
44471+ atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
44472 }
44473
44474 ti->private = sc;
44475@@ -332,7 +332,7 @@ static void stripe_status(struct dm_target *ti, status_type_t type,
44476 DMEMIT("%d ", sc->stripes);
44477 for (i = 0; i < sc->stripes; i++) {
44478 DMEMIT("%s ", sc->stripe[i].dev->name);
44479- buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
44480+ buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
44481 'D' : 'A';
44482 }
44483 buffer[i] = '\0';
44484@@ -377,8 +377,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio, int error)
44485 */
44486 for (i = 0; i < sc->stripes; i++)
44487 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
44488- atomic_inc(&(sc->stripe[i].error_count));
44489- if (atomic_read(&(sc->stripe[i].error_count)) <
44490+ atomic_inc_unchecked(&(sc->stripe[i].error_count));
44491+ if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
44492 DM_IO_ERROR_THRESHOLD)
44493 schedule_work(&sc->trigger_event);
44494 }
44495diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
44496index b2bd1eb..38f7a44 100644
44497--- a/drivers/md/dm-table.c
44498+++ b/drivers/md/dm-table.c
44499@@ -303,7 +303,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
44500 if (!dev_size)
44501 return 0;
44502
44503- if ((start >= dev_size) || (start + len > dev_size)) {
44504+ if ((start >= dev_size) || (len > dev_size - start)) {
44505 DMWARN("%s: %s too small for target: "
44506 "start=%llu, len=%llu, dev_size=%llu",
44507 dm_device_name(ti->table->md), bdevname(bdev, b),
44508diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
44509index e9d33ad..dae9880d 100644
44510--- a/drivers/md/dm-thin-metadata.c
44511+++ b/drivers/md/dm-thin-metadata.c
44512@@ -404,7 +404,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
44513 {
44514 pmd->info.tm = pmd->tm;
44515 pmd->info.levels = 2;
44516- pmd->info.value_type.context = pmd->data_sm;
44517+ pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
44518 pmd->info.value_type.size = sizeof(__le64);
44519 pmd->info.value_type.inc = data_block_inc;
44520 pmd->info.value_type.dec = data_block_dec;
44521@@ -423,7 +423,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
44522
44523 pmd->bl_info.tm = pmd->tm;
44524 pmd->bl_info.levels = 1;
44525- pmd->bl_info.value_type.context = pmd->data_sm;
44526+ pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
44527 pmd->bl_info.value_type.size = sizeof(__le64);
44528 pmd->bl_info.value_type.inc = data_block_inc;
44529 pmd->bl_info.value_type.dec = data_block_dec;
44530diff --git a/drivers/md/dm.c b/drivers/md/dm.c
44531index 58f3927..bfbad3e 100644
44532--- a/drivers/md/dm.c
44533+++ b/drivers/md/dm.c
44534@@ -183,9 +183,9 @@ struct mapped_device {
44535 /*
44536 * Event handling.
44537 */
44538- atomic_t event_nr;
44539+ atomic_unchecked_t event_nr;
44540 wait_queue_head_t eventq;
44541- atomic_t uevent_seq;
44542+ atomic_unchecked_t uevent_seq;
44543 struct list_head uevent_list;
44544 spinlock_t uevent_lock; /* Protect access to uevent_list */
44545
44546@@ -2071,8 +2071,8 @@ static struct mapped_device *alloc_dev(int minor)
44547 spin_lock_init(&md->deferred_lock);
44548 atomic_set(&md->holders, 1);
44549 atomic_set(&md->open_count, 0);
44550- atomic_set(&md->event_nr, 0);
44551- atomic_set(&md->uevent_seq, 0);
44552+ atomic_set_unchecked(&md->event_nr, 0);
44553+ atomic_set_unchecked(&md->uevent_seq, 0);
44554 INIT_LIST_HEAD(&md->uevent_list);
44555 INIT_LIST_HEAD(&md->table_devices);
44556 spin_lock_init(&md->uevent_lock);
44557@@ -2228,7 +2228,7 @@ static void event_callback(void *context)
44558
44559 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
44560
44561- atomic_inc(&md->event_nr);
44562+ atomic_inc_unchecked(&md->event_nr);
44563 wake_up(&md->eventq);
44564 }
44565
44566@@ -2921,18 +2921,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
44567
44568 uint32_t dm_next_uevent_seq(struct mapped_device *md)
44569 {
44570- return atomic_add_return(1, &md->uevent_seq);
44571+ return atomic_add_return_unchecked(1, &md->uevent_seq);
44572 }
44573
44574 uint32_t dm_get_event_nr(struct mapped_device *md)
44575 {
44576- return atomic_read(&md->event_nr);
44577+ return atomic_read_unchecked(&md->event_nr);
44578 }
44579
44580 int dm_wait_event(struct mapped_device *md, int event_nr)
44581 {
44582 return wait_event_interruptible(md->eventq,
44583- (event_nr != atomic_read(&md->event_nr)));
44584+ (event_nr != atomic_read_unchecked(&md->event_nr)));
44585 }
44586
44587 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
44588diff --git a/drivers/md/md.c b/drivers/md/md.c
44589index 9233c71..ed5243a 100644
44590--- a/drivers/md/md.c
44591+++ b/drivers/md/md.c
44592@@ -190,10 +190,10 @@ EXPORT_SYMBOL_GPL(bio_clone_mddev);
44593 * start build, activate spare
44594 */
44595 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
44596-static atomic_t md_event_count;
44597+static atomic_unchecked_t md_event_count;
44598 void md_new_event(struct mddev *mddev)
44599 {
44600- atomic_inc(&md_event_count);
44601+ atomic_inc_unchecked(&md_event_count);
44602 wake_up(&md_event_waiters);
44603 }
44604 EXPORT_SYMBOL_GPL(md_new_event);
44605@@ -203,7 +203,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
44606 */
44607 static void md_new_event_inintr(struct mddev *mddev)
44608 {
44609- atomic_inc(&md_event_count);
44610+ atomic_inc_unchecked(&md_event_count);
44611 wake_up(&md_event_waiters);
44612 }
44613
44614@@ -1426,7 +1426,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
44615 if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_RESHAPE_ACTIVE) &&
44616 (le32_to_cpu(sb->feature_map) & MD_FEATURE_NEW_OFFSET))
44617 rdev->new_data_offset += (s32)le32_to_cpu(sb->new_offset);
44618- atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
44619+ atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
44620
44621 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
44622 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
44623@@ -1677,7 +1677,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
44624 else
44625 sb->resync_offset = cpu_to_le64(0);
44626
44627- sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
44628+ sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
44629
44630 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
44631 sb->size = cpu_to_le64(mddev->dev_sectors);
44632@@ -2547,7 +2547,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
44633 static ssize_t
44634 errors_show(struct md_rdev *rdev, char *page)
44635 {
44636- return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
44637+ return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
44638 }
44639
44640 static ssize_t
44641@@ -2556,7 +2556,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
44642 char *e;
44643 unsigned long n = simple_strtoul(buf, &e, 10);
44644 if (*buf && (*e == 0 || *e == '\n')) {
44645- atomic_set(&rdev->corrected_errors, n);
44646+ atomic_set_unchecked(&rdev->corrected_errors, n);
44647 return len;
44648 }
44649 return -EINVAL;
44650@@ -3000,8 +3000,8 @@ int md_rdev_init(struct md_rdev *rdev)
44651 rdev->sb_loaded = 0;
44652 rdev->bb_page = NULL;
44653 atomic_set(&rdev->nr_pending, 0);
44654- atomic_set(&rdev->read_errors, 0);
44655- atomic_set(&rdev->corrected_errors, 0);
44656+ atomic_set_unchecked(&rdev->read_errors, 0);
44657+ atomic_set_unchecked(&rdev->corrected_errors, 0);
44658
44659 INIT_LIST_HEAD(&rdev->same_set);
44660 init_waitqueue_head(&rdev->blocked_wait);
44661@@ -6855,7 +6855,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
44662
44663 spin_unlock(&pers_lock);
44664 seq_printf(seq, "\n");
44665- seq->poll_event = atomic_read(&md_event_count);
44666+ seq->poll_event = atomic_read_unchecked(&md_event_count);
44667 return 0;
44668 }
44669 if (v == (void*)2) {
44670@@ -6958,7 +6958,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
44671 return error;
44672
44673 seq = file->private_data;
44674- seq->poll_event = atomic_read(&md_event_count);
44675+ seq->poll_event = atomic_read_unchecked(&md_event_count);
44676 return error;
44677 }
44678
44679@@ -6975,7 +6975,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
44680 /* always allow read */
44681 mask = POLLIN | POLLRDNORM;
44682
44683- if (seq->poll_event != atomic_read(&md_event_count))
44684+ if (seq->poll_event != atomic_read_unchecked(&md_event_count))
44685 mask |= POLLERR | POLLPRI;
44686 return mask;
44687 }
44688@@ -7022,7 +7022,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
44689 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
44690 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
44691 (int)part_stat_read(&disk->part0, sectors[1]) -
44692- atomic_read(&disk->sync_io);
44693+ atomic_read_unchecked(&disk->sync_io);
44694 /* sync IO will cause sync_io to increase before the disk_stats
44695 * as sync_io is counted when a request starts, and
44696 * disk_stats is counted when it completes.
44697diff --git a/drivers/md/md.h b/drivers/md/md.h
44698index 03cec5b..0a658c1 100644
44699--- a/drivers/md/md.h
44700+++ b/drivers/md/md.h
44701@@ -94,13 +94,13 @@ struct md_rdev {
44702 * only maintained for arrays that
44703 * support hot removal
44704 */
44705- atomic_t read_errors; /* number of consecutive read errors that
44706+ atomic_unchecked_t read_errors; /* number of consecutive read errors that
44707 * we have tried to ignore.
44708 */
44709 struct timespec last_read_error; /* monotonic time since our
44710 * last read error
44711 */
44712- atomic_t corrected_errors; /* number of corrected read errors,
44713+ atomic_unchecked_t corrected_errors; /* number of corrected read errors,
44714 * for reporting to userspace and storing
44715 * in superblock.
44716 */
44717@@ -448,7 +448,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
44718
44719 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
44720 {
44721- atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
44722+ atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
44723 }
44724
44725 struct md_personality
44726diff --git a/drivers/md/persistent-data/dm-space-map-metadata.c b/drivers/md/persistent-data/dm-space-map-metadata.c
44727index f4e22bc..8f83114 100644
44728--- a/drivers/md/persistent-data/dm-space-map-metadata.c
44729+++ b/drivers/md/persistent-data/dm-space-map-metadata.c
44730@@ -681,7 +681,7 @@ static int sm_metadata_extend(struct dm_space_map *sm, dm_block_t extra_blocks)
44731 * Flick into a mode where all blocks get allocated in the new area.
44732 */
44733 smm->begin = old_len;
44734- memcpy(sm, &bootstrap_ops, sizeof(*sm));
44735+ memcpy((void *)sm, &bootstrap_ops, sizeof(*sm));
44736
44737 /*
44738 * Extend.
44739@@ -712,7 +712,7 @@ out:
44740 /*
44741 * Switch back to normal behaviour.
44742 */
44743- memcpy(sm, &ops, sizeof(*sm));
44744+ memcpy((void *)sm, &ops, sizeof(*sm));
44745 return r;
44746 }
44747
44748diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
44749index 3e6d115..ffecdeb 100644
44750--- a/drivers/md/persistent-data/dm-space-map.h
44751+++ b/drivers/md/persistent-data/dm-space-map.h
44752@@ -71,6 +71,7 @@ struct dm_space_map {
44753 dm_sm_threshold_fn fn,
44754 void *context);
44755 };
44756+typedef struct dm_space_map __no_const dm_space_map_no_const;
44757
44758 /*----------------------------------------------------------------*/
44759
44760diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
44761index 40b35be..a327e11 100644
44762--- a/drivers/md/raid1.c
44763+++ b/drivers/md/raid1.c
44764@@ -1931,7 +1931,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
44765 if (r1_sync_page_io(rdev, sect, s,
44766 bio->bi_io_vec[idx].bv_page,
44767 READ) != 0)
44768- atomic_add(s, &rdev->corrected_errors);
44769+ atomic_add_unchecked(s, &rdev->corrected_errors);
44770 }
44771 sectors -= s;
44772 sect += s;
44773@@ -2164,7 +2164,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
44774 !test_bit(Faulty, &rdev->flags)) {
44775 if (r1_sync_page_io(rdev, sect, s,
44776 conf->tmppage, READ)) {
44777- atomic_add(s, &rdev->corrected_errors);
44778+ atomic_add_unchecked(s, &rdev->corrected_errors);
44779 printk(KERN_INFO
44780 "md/raid1:%s: read error corrected "
44781 "(%d sectors at %llu on %s)\n",
44782diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
44783index 32e282f..5cec803 100644
44784--- a/drivers/md/raid10.c
44785+++ b/drivers/md/raid10.c
44786@@ -1944,7 +1944,7 @@ static void end_sync_read(struct bio *bio, int error)
44787 /* The write handler will notice the lack of
44788 * R10BIO_Uptodate and record any errors etc
44789 */
44790- atomic_add(r10_bio->sectors,
44791+ atomic_add_unchecked(r10_bio->sectors,
44792 &conf->mirrors[d].rdev->corrected_errors);
44793
44794 /* for reconstruct, we always reschedule after a read.
44795@@ -2301,7 +2301,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
44796 {
44797 struct timespec cur_time_mon;
44798 unsigned long hours_since_last;
44799- unsigned int read_errors = atomic_read(&rdev->read_errors);
44800+ unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
44801
44802 ktime_get_ts(&cur_time_mon);
44803
44804@@ -2323,9 +2323,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
44805 * overflowing the shift of read_errors by hours_since_last.
44806 */
44807 if (hours_since_last >= 8 * sizeof(read_errors))
44808- atomic_set(&rdev->read_errors, 0);
44809+ atomic_set_unchecked(&rdev->read_errors, 0);
44810 else
44811- atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
44812+ atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
44813 }
44814
44815 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
44816@@ -2379,8 +2379,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
44817 return;
44818
44819 check_decay_read_errors(mddev, rdev);
44820- atomic_inc(&rdev->read_errors);
44821- if (atomic_read(&rdev->read_errors) > max_read_errors) {
44822+ atomic_inc_unchecked(&rdev->read_errors);
44823+ if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
44824 char b[BDEVNAME_SIZE];
44825 bdevname(rdev->bdev, b);
44826
44827@@ -2388,7 +2388,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
44828 "md/raid10:%s: %s: Raid device exceeded "
44829 "read_error threshold [cur %d:max %d]\n",
44830 mdname(mddev), b,
44831- atomic_read(&rdev->read_errors), max_read_errors);
44832+ atomic_read_unchecked(&rdev->read_errors), max_read_errors);
44833 printk(KERN_NOTICE
44834 "md/raid10:%s: %s: Failing raid device\n",
44835 mdname(mddev), b);
44836@@ -2543,7 +2543,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
44837 sect +
44838 choose_data_offset(r10_bio, rdev)),
44839 bdevname(rdev->bdev, b));
44840- atomic_add(s, &rdev->corrected_errors);
44841+ atomic_add_unchecked(s, &rdev->corrected_errors);
44842 }
44843
44844 rdev_dec_pending(rdev, mddev);
44845diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
44846index c1b0d52..07a0a5d 100644
44847--- a/drivers/md/raid5.c
44848+++ b/drivers/md/raid5.c
44849@@ -1730,6 +1730,10 @@ static int grow_one_stripe(struct r5conf *conf, int hash)
44850 return 1;
44851 }
44852
44853+#ifdef CONFIG_GRKERNSEC_HIDESYM
44854+static atomic_unchecked_t raid5_cache_id = ATOMIC_INIT(0);
44855+#endif
44856+
44857 static int grow_stripes(struct r5conf *conf, int num)
44858 {
44859 struct kmem_cache *sc;
44860@@ -1741,7 +1745,11 @@ static int grow_stripes(struct r5conf *conf, int num)
44861 "raid%d-%s", conf->level, mdname(conf->mddev));
44862 else
44863 sprintf(conf->cache_name[0],
44864+#ifdef CONFIG_GRKERNSEC_HIDESYM
44865+ "raid%d-%08lx", conf->level, atomic_inc_return_unchecked(&raid5_cache_id));
44866+#else
44867 "raid%d-%p", conf->level, conf->mddev);
44868+#endif
44869 sprintf(conf->cache_name[1], "%s-alt", conf->cache_name[0]);
44870
44871 conf->active_name = 0;
44872@@ -2017,21 +2025,21 @@ static void raid5_end_read_request(struct bio * bi, int error)
44873 mdname(conf->mddev), STRIPE_SECTORS,
44874 (unsigned long long)s,
44875 bdevname(rdev->bdev, b));
44876- atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
44877+ atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
44878 clear_bit(R5_ReadError, &sh->dev[i].flags);
44879 clear_bit(R5_ReWrite, &sh->dev[i].flags);
44880 } else if (test_bit(R5_ReadNoMerge, &sh->dev[i].flags))
44881 clear_bit(R5_ReadNoMerge, &sh->dev[i].flags);
44882
44883- if (atomic_read(&rdev->read_errors))
44884- atomic_set(&rdev->read_errors, 0);
44885+ if (atomic_read_unchecked(&rdev->read_errors))
44886+ atomic_set_unchecked(&rdev->read_errors, 0);
44887 } else {
44888 const char *bdn = bdevname(rdev->bdev, b);
44889 int retry = 0;
44890 int set_bad = 0;
44891
44892 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
44893- atomic_inc(&rdev->read_errors);
44894+ atomic_inc_unchecked(&rdev->read_errors);
44895 if (test_bit(R5_ReadRepl, &sh->dev[i].flags))
44896 printk_ratelimited(
44897 KERN_WARNING
44898@@ -2059,7 +2067,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
44899 mdname(conf->mddev),
44900 (unsigned long long)s,
44901 bdn);
44902- } else if (atomic_read(&rdev->read_errors)
44903+ } else if (atomic_read_unchecked(&rdev->read_errors)
44904 > conf->max_nr_stripes)
44905 printk(KERN_WARNING
44906 "md/raid:%s: Too many read errors, failing device %s.\n",
44907diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
44908index 983db75..ef9248c 100644
44909--- a/drivers/media/dvb-core/dvbdev.c
44910+++ b/drivers/media/dvb-core/dvbdev.c
44911@@ -185,7 +185,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
44912 const struct dvb_device *template, void *priv, int type)
44913 {
44914 struct dvb_device *dvbdev;
44915- struct file_operations *dvbdevfops;
44916+ file_operations_no_const *dvbdevfops;
44917 struct device *clsdev;
44918 int minor;
44919 int id;
44920diff --git a/drivers/media/dvb-frontends/af9033.h b/drivers/media/dvb-frontends/af9033.h
44921index 6ad22b6..6e90e2a 100644
44922--- a/drivers/media/dvb-frontends/af9033.h
44923+++ b/drivers/media/dvb-frontends/af9033.h
44924@@ -96,6 +96,6 @@ struct af9033_ops {
44925 int (*pid_filter_ctrl)(struct dvb_frontend *fe, int onoff);
44926 int (*pid_filter)(struct dvb_frontend *fe, int index, u16 pid,
44927 int onoff);
44928-};
44929+} __no_const;
44930
44931 #endif /* AF9033_H */
44932diff --git a/drivers/media/dvb-frontends/dib3000.h b/drivers/media/dvb-frontends/dib3000.h
44933index 9b6c3bb..baeb5c7 100644
44934--- a/drivers/media/dvb-frontends/dib3000.h
44935+++ b/drivers/media/dvb-frontends/dib3000.h
44936@@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
44937 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
44938 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
44939 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
44940-};
44941+} __no_const;
44942
44943 #if IS_ENABLED(CONFIG_DVB_DIB3000MB)
44944 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
44945diff --git a/drivers/media/dvb-frontends/dib7000p.h b/drivers/media/dvb-frontends/dib7000p.h
44946index 1fea0e9..321ce8f 100644
44947--- a/drivers/media/dvb-frontends/dib7000p.h
44948+++ b/drivers/media/dvb-frontends/dib7000p.h
44949@@ -64,7 +64,7 @@ struct dib7000p_ops {
44950 int (*get_adc_power)(struct dvb_frontend *fe);
44951 int (*slave_reset)(struct dvb_frontend *fe);
44952 struct dvb_frontend *(*init)(struct i2c_adapter *i2c_adap, u8 i2c_addr, struct dib7000p_config *cfg);
44953-};
44954+} __no_const;
44955
44956 #if IS_ENABLED(CONFIG_DVB_DIB7000P)
44957 void *dib7000p_attach(struct dib7000p_ops *ops);
44958diff --git a/drivers/media/dvb-frontends/dib8000.h b/drivers/media/dvb-frontends/dib8000.h
44959index 84cc103..5780c54 100644
44960--- a/drivers/media/dvb-frontends/dib8000.h
44961+++ b/drivers/media/dvb-frontends/dib8000.h
44962@@ -61,7 +61,7 @@ struct dib8000_ops {
44963 int (*pid_filter_ctrl)(struct dvb_frontend *fe, u8 onoff);
44964 int (*pid_filter)(struct dvb_frontend *fe, u8 id, u16 pid, u8 onoff);
44965 struct dvb_frontend *(*init)(struct i2c_adapter *i2c_adap, u8 i2c_addr, struct dib8000_config *cfg);
44966-};
44967+} __no_const;
44968
44969 #if IS_ENABLED(CONFIG_DVB_DIB8000)
44970 void *dib8000_attach(struct dib8000_ops *ops);
44971diff --git a/drivers/media/pci/cx88/cx88-video.c b/drivers/media/pci/cx88/cx88-video.c
44972index ce27e6d..b70435a 100644
44973--- a/drivers/media/pci/cx88/cx88-video.c
44974+++ b/drivers/media/pci/cx88/cx88-video.c
44975@@ -50,9 +50,9 @@ MODULE_VERSION(CX88_VERSION);
44976
44977 /* ------------------------------------------------------------------ */
44978
44979-static unsigned int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44980-static unsigned int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44981-static unsigned int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44982+static int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44983+static int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44984+static int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44985
44986 module_param_array(video_nr, int, NULL, 0444);
44987 module_param_array(vbi_nr, int, NULL, 0444);
44988diff --git a/drivers/media/pci/ivtv/ivtv-driver.c b/drivers/media/pci/ivtv/ivtv-driver.c
44989index 802642d..5534900 100644
44990--- a/drivers/media/pci/ivtv/ivtv-driver.c
44991+++ b/drivers/media/pci/ivtv/ivtv-driver.c
44992@@ -83,7 +83,7 @@ static struct pci_device_id ivtv_pci_tbl[] = {
44993 MODULE_DEVICE_TABLE(pci,ivtv_pci_tbl);
44994
44995 /* ivtv instance counter */
44996-static atomic_t ivtv_instance = ATOMIC_INIT(0);
44997+static atomic_unchecked_t ivtv_instance = ATOMIC_INIT(0);
44998
44999 /* Parameter declarations */
45000 static int cardtype[IVTV_MAX_CARDS];
45001diff --git a/drivers/media/pci/solo6x10/solo6x10-core.c b/drivers/media/pci/solo6x10/solo6x10-core.c
45002index 8cbe6b4..ea3601c 100644
45003--- a/drivers/media/pci/solo6x10/solo6x10-core.c
45004+++ b/drivers/media/pci/solo6x10/solo6x10-core.c
45005@@ -424,7 +424,7 @@ static void solo_device_release(struct device *dev)
45006
45007 static int solo_sysfs_init(struct solo_dev *solo_dev)
45008 {
45009- struct bin_attribute *sdram_attr = &solo_dev->sdram_attr;
45010+ bin_attribute_no_const *sdram_attr = &solo_dev->sdram_attr;
45011 struct device *dev = &solo_dev->dev;
45012 const char *driver;
45013 int i;
45014diff --git a/drivers/media/pci/solo6x10/solo6x10-g723.c b/drivers/media/pci/solo6x10/solo6x10-g723.c
45015index c7141f2..5301fec 100644
45016--- a/drivers/media/pci/solo6x10/solo6x10-g723.c
45017+++ b/drivers/media/pci/solo6x10/solo6x10-g723.c
45018@@ -351,7 +351,7 @@ static int solo_snd_pcm_init(struct solo_dev *solo_dev)
45019
45020 int solo_g723_init(struct solo_dev *solo_dev)
45021 {
45022- static struct snd_device_ops ops = { NULL };
45023+ static struct snd_device_ops ops = { };
45024 struct snd_card *card;
45025 struct snd_kcontrol_new kctl;
45026 char name[32];
45027diff --git a/drivers/media/pci/solo6x10/solo6x10-p2m.c b/drivers/media/pci/solo6x10/solo6x10-p2m.c
45028index 8c84846..27b4f83 100644
45029--- a/drivers/media/pci/solo6x10/solo6x10-p2m.c
45030+++ b/drivers/media/pci/solo6x10/solo6x10-p2m.c
45031@@ -73,7 +73,7 @@ int solo_p2m_dma_desc(struct solo_dev *solo_dev,
45032
45033 /* Get next ID. According to Softlogic, 6110 has problems on !=0 P2M */
45034 if (solo_dev->type != SOLO_DEV_6110 && multi_p2m) {
45035- p2m_id = atomic_inc_return(&solo_dev->p2m_count) % SOLO_NR_P2M;
45036+ p2m_id = atomic_inc_return_unchecked(&solo_dev->p2m_count) % SOLO_NR_P2M;
45037 if (p2m_id < 0)
45038 p2m_id = -p2m_id;
45039 }
45040diff --git a/drivers/media/pci/solo6x10/solo6x10.h b/drivers/media/pci/solo6x10/solo6x10.h
45041index 72017b7..dd37ae6 100644
45042--- a/drivers/media/pci/solo6x10/solo6x10.h
45043+++ b/drivers/media/pci/solo6x10/solo6x10.h
45044@@ -219,7 +219,7 @@ struct solo_dev {
45045
45046 /* P2M DMA Engine */
45047 struct solo_p2m_dev p2m_dev[SOLO_NR_P2M];
45048- atomic_t p2m_count;
45049+ atomic_unchecked_t p2m_count;
45050 int p2m_jiffies;
45051 unsigned int p2m_timeouts;
45052
45053diff --git a/drivers/media/pci/tw68/tw68-core.c b/drivers/media/pci/tw68/tw68-core.c
45054index 63f0b64..a017c1c 100644
45055--- a/drivers/media/pci/tw68/tw68-core.c
45056+++ b/drivers/media/pci/tw68/tw68-core.c
45057@@ -60,7 +60,7 @@ static unsigned int card[] = {[0 ... (TW68_MAXBOARDS - 1)] = UNSET };
45058 module_param_array(card, int, NULL, 0444);
45059 MODULE_PARM_DESC(card, "card type");
45060
45061-static atomic_t tw68_instance = ATOMIC_INIT(0);
45062+static atomic_unchecked_t tw68_instance = ATOMIC_INIT(0);
45063
45064 /* ------------------------------------------------------------------ */
45065
45066diff --git a/drivers/media/platform/omap/omap_vout.c b/drivers/media/platform/omap/omap_vout.c
45067index 64ab6fb..ef4a8b9 100644
45068--- a/drivers/media/platform/omap/omap_vout.c
45069+++ b/drivers/media/platform/omap/omap_vout.c
45070@@ -63,7 +63,6 @@ enum omap_vout_channels {
45071 OMAP_VIDEO2,
45072 };
45073
45074-static struct videobuf_queue_ops video_vbq_ops;
45075 /* Variables configurable through module params*/
45076 static u32 video1_numbuffers = 3;
45077 static u32 video2_numbuffers = 3;
45078@@ -1012,6 +1011,12 @@ static int omap_vout_open(struct file *file)
45079 {
45080 struct videobuf_queue *q;
45081 struct omap_vout_device *vout = NULL;
45082+ static struct videobuf_queue_ops video_vbq_ops = {
45083+ .buf_setup = omap_vout_buffer_setup,
45084+ .buf_prepare = omap_vout_buffer_prepare,
45085+ .buf_release = omap_vout_buffer_release,
45086+ .buf_queue = omap_vout_buffer_queue,
45087+ };
45088
45089 vout = video_drvdata(file);
45090 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
45091@@ -1029,10 +1034,6 @@ static int omap_vout_open(struct file *file)
45092 vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
45093
45094 q = &vout->vbq;
45095- video_vbq_ops.buf_setup = omap_vout_buffer_setup;
45096- video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
45097- video_vbq_ops.buf_release = omap_vout_buffer_release;
45098- video_vbq_ops.buf_queue = omap_vout_buffer_queue;
45099 spin_lock_init(&vout->vbq_lock);
45100
45101 videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
45102diff --git a/drivers/media/platform/s5p-tv/mixer.h b/drivers/media/platform/s5p-tv/mixer.h
45103index fb2acc5..a2fcbdc4 100644
45104--- a/drivers/media/platform/s5p-tv/mixer.h
45105+++ b/drivers/media/platform/s5p-tv/mixer.h
45106@@ -156,7 +156,7 @@ struct mxr_layer {
45107 /** layer index (unique identifier) */
45108 int idx;
45109 /** callbacks for layer methods */
45110- struct mxr_layer_ops ops;
45111+ struct mxr_layer_ops *ops;
45112 /** format array */
45113 const struct mxr_format **fmt_array;
45114 /** size of format array */
45115diff --git a/drivers/media/platform/s5p-tv/mixer_grp_layer.c b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
45116index 74344c7..a39e70e 100644
45117--- a/drivers/media/platform/s5p-tv/mixer_grp_layer.c
45118+++ b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
45119@@ -235,7 +235,7 @@ struct mxr_layer *mxr_graph_layer_create(struct mxr_device *mdev, int idx)
45120 {
45121 struct mxr_layer *layer;
45122 int ret;
45123- struct mxr_layer_ops ops = {
45124+ static struct mxr_layer_ops ops = {
45125 .release = mxr_graph_layer_release,
45126 .buffer_set = mxr_graph_buffer_set,
45127 .stream_set = mxr_graph_stream_set,
45128diff --git a/drivers/media/platform/s5p-tv/mixer_reg.c b/drivers/media/platform/s5p-tv/mixer_reg.c
45129index b713403..53cb5ad 100644
45130--- a/drivers/media/platform/s5p-tv/mixer_reg.c
45131+++ b/drivers/media/platform/s5p-tv/mixer_reg.c
45132@@ -276,7 +276,7 @@ static void mxr_irq_layer_handle(struct mxr_layer *layer)
45133 layer->update_buf = next;
45134 }
45135
45136- layer->ops.buffer_set(layer, layer->update_buf);
45137+ layer->ops->buffer_set(layer, layer->update_buf);
45138
45139 if (done && done != layer->shadow_buf)
45140 vb2_buffer_done(&done->vb, VB2_BUF_STATE_DONE);
45141diff --git a/drivers/media/platform/s5p-tv/mixer_video.c b/drivers/media/platform/s5p-tv/mixer_video.c
45142index b4d2696..91df48e 100644
45143--- a/drivers/media/platform/s5p-tv/mixer_video.c
45144+++ b/drivers/media/platform/s5p-tv/mixer_video.c
45145@@ -210,7 +210,7 @@ static void mxr_layer_default_geo(struct mxr_layer *layer)
45146 layer->geo.src.height = layer->geo.src.full_height;
45147
45148 mxr_geometry_dump(mdev, &layer->geo);
45149- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
45150+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
45151 mxr_geometry_dump(mdev, &layer->geo);
45152 }
45153
45154@@ -228,7 +228,7 @@ static void mxr_layer_update_output(struct mxr_layer *layer)
45155 layer->geo.dst.full_width = mbus_fmt.width;
45156 layer->geo.dst.full_height = mbus_fmt.height;
45157 layer->geo.dst.field = mbus_fmt.field;
45158- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
45159+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
45160
45161 mxr_geometry_dump(mdev, &layer->geo);
45162 }
45163@@ -334,7 +334,7 @@ static int mxr_s_fmt(struct file *file, void *priv,
45164 /* set source size to highest accepted value */
45165 geo->src.full_width = max(geo->dst.full_width, pix->width);
45166 geo->src.full_height = max(geo->dst.full_height, pix->height);
45167- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
45168+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
45169 mxr_geometry_dump(mdev, &layer->geo);
45170 /* set cropping to total visible screen */
45171 geo->src.width = pix->width;
45172@@ -342,12 +342,12 @@ static int mxr_s_fmt(struct file *file, void *priv,
45173 geo->src.x_offset = 0;
45174 geo->src.y_offset = 0;
45175 /* assure consistency of geometry */
45176- layer->ops.fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
45177+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
45178 mxr_geometry_dump(mdev, &layer->geo);
45179 /* set full size to lowest possible value */
45180 geo->src.full_width = 0;
45181 geo->src.full_height = 0;
45182- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
45183+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
45184 mxr_geometry_dump(mdev, &layer->geo);
45185
45186 /* returning results */
45187@@ -474,7 +474,7 @@ static int mxr_s_selection(struct file *file, void *fh,
45188 target->width = s->r.width;
45189 target->height = s->r.height;
45190
45191- layer->ops.fix_geometry(layer, stage, s->flags);
45192+ layer->ops->fix_geometry(layer, stage, s->flags);
45193
45194 /* retrieve update selection rectangle */
45195 res.left = target->x_offset;
45196@@ -954,13 +954,13 @@ static int start_streaming(struct vb2_queue *vq, unsigned int count)
45197 mxr_output_get(mdev);
45198
45199 mxr_layer_update_output(layer);
45200- layer->ops.format_set(layer);
45201+ layer->ops->format_set(layer);
45202 /* enabling layer in hardware */
45203 spin_lock_irqsave(&layer->enq_slock, flags);
45204 layer->state = MXR_LAYER_STREAMING;
45205 spin_unlock_irqrestore(&layer->enq_slock, flags);
45206
45207- layer->ops.stream_set(layer, MXR_ENABLE);
45208+ layer->ops->stream_set(layer, MXR_ENABLE);
45209 mxr_streamer_get(mdev);
45210
45211 return 0;
45212@@ -1030,7 +1030,7 @@ static void stop_streaming(struct vb2_queue *vq)
45213 spin_unlock_irqrestore(&layer->enq_slock, flags);
45214
45215 /* disabling layer in hardware */
45216- layer->ops.stream_set(layer, MXR_DISABLE);
45217+ layer->ops->stream_set(layer, MXR_DISABLE);
45218 /* remove one streamer */
45219 mxr_streamer_put(mdev);
45220 /* allow changes in output configuration */
45221@@ -1068,8 +1068,8 @@ void mxr_base_layer_unregister(struct mxr_layer *layer)
45222
45223 void mxr_layer_release(struct mxr_layer *layer)
45224 {
45225- if (layer->ops.release)
45226- layer->ops.release(layer);
45227+ if (layer->ops->release)
45228+ layer->ops->release(layer);
45229 }
45230
45231 void mxr_base_layer_release(struct mxr_layer *layer)
45232@@ -1095,7 +1095,7 @@ struct mxr_layer *mxr_base_layer_create(struct mxr_device *mdev,
45233
45234 layer->mdev = mdev;
45235 layer->idx = idx;
45236- layer->ops = *ops;
45237+ layer->ops = ops;
45238
45239 spin_lock_init(&layer->enq_slock);
45240 INIT_LIST_HEAD(&layer->enq_list);
45241diff --git a/drivers/media/platform/s5p-tv/mixer_vp_layer.c b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
45242index c9388c4..ce71ece 100644
45243--- a/drivers/media/platform/s5p-tv/mixer_vp_layer.c
45244+++ b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
45245@@ -206,7 +206,7 @@ struct mxr_layer *mxr_vp_layer_create(struct mxr_device *mdev, int idx)
45246 {
45247 struct mxr_layer *layer;
45248 int ret;
45249- struct mxr_layer_ops ops = {
45250+ static struct mxr_layer_ops ops = {
45251 .release = mxr_vp_layer_release,
45252 .buffer_set = mxr_vp_buffer_set,
45253 .stream_set = mxr_vp_stream_set,
45254diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
45255index 82affae..42833ec 100644
45256--- a/drivers/media/radio/radio-cadet.c
45257+++ b/drivers/media/radio/radio-cadet.c
45258@@ -333,6 +333,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
45259 unsigned char readbuf[RDS_BUFFER];
45260 int i = 0;
45261
45262+ if (count > RDS_BUFFER)
45263+ return -EFAULT;
45264 mutex_lock(&dev->lock);
45265 if (dev->rdsstat == 0)
45266 cadet_start_rds(dev);
45267@@ -349,8 +351,9 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
45268 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
45269 mutex_unlock(&dev->lock);
45270
45271- if (i && copy_to_user(data, readbuf, i))
45272- return -EFAULT;
45273+ if (i > sizeof(readbuf) || (i && copy_to_user(data, readbuf, i)))
45274+ i = -EFAULT;
45275+
45276 return i;
45277 }
45278
45279diff --git a/drivers/media/radio/radio-maxiradio.c b/drivers/media/radio/radio-maxiradio.c
45280index 5236035..c622c74 100644
45281--- a/drivers/media/radio/radio-maxiradio.c
45282+++ b/drivers/media/radio/radio-maxiradio.c
45283@@ -61,7 +61,7 @@ MODULE_PARM_DESC(radio_nr, "Radio device number");
45284 /* TEA5757 pin mappings */
45285 static const int clk = 1, data = 2, wren = 4, mo_st = 8, power = 16;
45286
45287-static atomic_t maxiradio_instance = ATOMIC_INIT(0);
45288+static atomic_unchecked_t maxiradio_instance = ATOMIC_INIT(0);
45289
45290 #define PCI_VENDOR_ID_GUILLEMOT 0x5046
45291 #define PCI_DEVICE_ID_GUILLEMOT_MAXIRADIO 0x1001
45292diff --git a/drivers/media/radio/radio-shark.c b/drivers/media/radio/radio-shark.c
45293index 050b3bb..79f62b9 100644
45294--- a/drivers/media/radio/radio-shark.c
45295+++ b/drivers/media/radio/radio-shark.c
45296@@ -79,7 +79,7 @@ struct shark_device {
45297 u32 last_val;
45298 };
45299
45300-static atomic_t shark_instance = ATOMIC_INIT(0);
45301+static atomic_unchecked_t shark_instance = ATOMIC_INIT(0);
45302
45303 static void shark_write_val(struct snd_tea575x *tea, u32 val)
45304 {
45305diff --git a/drivers/media/radio/radio-shark2.c b/drivers/media/radio/radio-shark2.c
45306index 8654e0d..0608a64 100644
45307--- a/drivers/media/radio/radio-shark2.c
45308+++ b/drivers/media/radio/radio-shark2.c
45309@@ -74,7 +74,7 @@ struct shark_device {
45310 u8 *transfer_buffer;
45311 };
45312
45313-static atomic_t shark_instance = ATOMIC_INIT(0);
45314+static atomic_unchecked_t shark_instance = ATOMIC_INIT(0);
45315
45316 static int shark_write_reg(struct radio_tea5777 *tea, u64 reg)
45317 {
45318diff --git a/drivers/media/radio/radio-si476x.c b/drivers/media/radio/radio-si476x.c
45319index 633022b..7f10754 100644
45320--- a/drivers/media/radio/radio-si476x.c
45321+++ b/drivers/media/radio/radio-si476x.c
45322@@ -1445,7 +1445,7 @@ static int si476x_radio_probe(struct platform_device *pdev)
45323 struct si476x_radio *radio;
45324 struct v4l2_ctrl *ctrl;
45325
45326- static atomic_t instance = ATOMIC_INIT(0);
45327+ static atomic_unchecked_t instance = ATOMIC_INIT(0);
45328
45329 radio = devm_kzalloc(&pdev->dev, sizeof(*radio), GFP_KERNEL);
45330 if (!radio)
45331diff --git a/drivers/media/usb/dvb-usb/cinergyT2-core.c b/drivers/media/usb/dvb-usb/cinergyT2-core.c
45332index 9fd1527..8927230 100644
45333--- a/drivers/media/usb/dvb-usb/cinergyT2-core.c
45334+++ b/drivers/media/usb/dvb-usb/cinergyT2-core.c
45335@@ -50,29 +50,73 @@ static struct dvb_usb_device_properties cinergyt2_properties;
45336
45337 static int cinergyt2_streaming_ctrl(struct dvb_usb_adapter *adap, int enable)
45338 {
45339- char buf[] = { CINERGYT2_EP1_CONTROL_STREAM_TRANSFER, enable ? 1 : 0 };
45340- char result[64];
45341- return dvb_usb_generic_rw(adap->dev, buf, sizeof(buf), result,
45342- sizeof(result), 0);
45343+ char *buf;
45344+ char *result;
45345+ int retval;
45346+
45347+ buf = kmalloc(2, GFP_KERNEL);
45348+ if (buf == NULL)
45349+ return -ENOMEM;
45350+ result = kmalloc(64, GFP_KERNEL);
45351+ if (result == NULL) {
45352+ kfree(buf);
45353+ return -ENOMEM;
45354+ }
45355+
45356+ buf[0] = CINERGYT2_EP1_CONTROL_STREAM_TRANSFER;
45357+ buf[1] = enable ? 1 : 0;
45358+
45359+ retval = dvb_usb_generic_rw(adap->dev, buf, 2, result, 64, 0);
45360+
45361+ kfree(buf);
45362+ kfree(result);
45363+ return retval;
45364 }
45365
45366 static int cinergyt2_power_ctrl(struct dvb_usb_device *d, int enable)
45367 {
45368- char buf[] = { CINERGYT2_EP1_SLEEP_MODE, enable ? 0 : 1 };
45369- char state[3];
45370- return dvb_usb_generic_rw(d, buf, sizeof(buf), state, sizeof(state), 0);
45371+ char *buf;
45372+ char *state;
45373+ int retval;
45374+
45375+ buf = kmalloc(2, GFP_KERNEL);
45376+ if (buf == NULL)
45377+ return -ENOMEM;
45378+ state = kmalloc(3, GFP_KERNEL);
45379+ if (state == NULL) {
45380+ kfree(buf);
45381+ return -ENOMEM;
45382+ }
45383+
45384+ buf[0] = CINERGYT2_EP1_SLEEP_MODE;
45385+ buf[1] = enable ? 1 : 0;
45386+
45387+ retval = dvb_usb_generic_rw(d, buf, 2, state, 3, 0);
45388+
45389+ kfree(buf);
45390+ kfree(state);
45391+ return retval;
45392 }
45393
45394 static int cinergyt2_frontend_attach(struct dvb_usb_adapter *adap)
45395 {
45396- char query[] = { CINERGYT2_EP1_GET_FIRMWARE_VERSION };
45397- char state[3];
45398+ char *query;
45399+ char *state;
45400 int ret;
45401+ query = kmalloc(1, GFP_KERNEL);
45402+ if (query == NULL)
45403+ return -ENOMEM;
45404+ state = kmalloc(3, GFP_KERNEL);
45405+ if (state == NULL) {
45406+ kfree(query);
45407+ return -ENOMEM;
45408+ }
45409+
45410+ query[0] = CINERGYT2_EP1_GET_FIRMWARE_VERSION;
45411
45412 adap->fe_adap[0].fe = cinergyt2_fe_attach(adap->dev);
45413
45414- ret = dvb_usb_generic_rw(adap->dev, query, sizeof(query), state,
45415- sizeof(state), 0);
45416+ ret = dvb_usb_generic_rw(adap->dev, query, 1, state, 3, 0);
45417 if (ret < 0) {
45418 deb_rc("cinergyt2_power_ctrl() Failed to retrieve sleep "
45419 "state info\n");
45420@@ -80,7 +124,8 @@ static int cinergyt2_frontend_attach(struct dvb_usb_adapter *adap)
45421
45422 /* Copy this pointer as we are gonna need it in the release phase */
45423 cinergyt2_usb_device = adap->dev;
45424-
45425+ kfree(query);
45426+ kfree(state);
45427 return 0;
45428 }
45429
45430@@ -141,12 +186,23 @@ static int repeatable_keys[] = {
45431 static int cinergyt2_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
45432 {
45433 struct cinergyt2_state *st = d->priv;
45434- u8 key[5] = {0, 0, 0, 0, 0}, cmd = CINERGYT2_EP1_GET_RC_EVENTS;
45435+ u8 *key, *cmd;
45436 int i;
45437
45438+ cmd = kmalloc(1, GFP_KERNEL);
45439+ if (cmd == NULL)
45440+ return -EINVAL;
45441+ key = kzalloc(5, GFP_KERNEL);
45442+ if (key == NULL) {
45443+ kfree(cmd);
45444+ return -EINVAL;
45445+ }
45446+
45447+ cmd[0] = CINERGYT2_EP1_GET_RC_EVENTS;
45448+
45449 *state = REMOTE_NO_KEY_PRESSED;
45450
45451- dvb_usb_generic_rw(d, &cmd, 1, key, sizeof(key), 0);
45452+ dvb_usb_generic_rw(d, cmd, 1, key, 5, 0);
45453 if (key[4] == 0xff) {
45454 /* key repeat */
45455 st->rc_counter++;
45456@@ -157,12 +213,12 @@ static int cinergyt2_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
45457 *event = d->last_event;
45458 deb_rc("repeat key, event %x\n",
45459 *event);
45460- return 0;
45461+ goto out;
45462 }
45463 }
45464 deb_rc("repeated key (non repeatable)\n");
45465 }
45466- return 0;
45467+ goto out;
45468 }
45469
45470 /* hack to pass checksum on the custom field */
45471@@ -174,6 +230,9 @@ static int cinergyt2_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
45472
45473 deb_rc("key: %*ph\n", 5, key);
45474 }
45475+out:
45476+ kfree(cmd);
45477+ kfree(key);
45478 return 0;
45479 }
45480
45481diff --git a/drivers/media/usb/dvb-usb/cinergyT2-fe.c b/drivers/media/usb/dvb-usb/cinergyT2-fe.c
45482index c890fe4..f9b2ae6 100644
45483--- a/drivers/media/usb/dvb-usb/cinergyT2-fe.c
45484+++ b/drivers/media/usb/dvb-usb/cinergyT2-fe.c
45485@@ -145,103 +145,176 @@ static int cinergyt2_fe_read_status(struct dvb_frontend *fe,
45486 fe_status_t *status)
45487 {
45488 struct cinergyt2_fe_state *state = fe->demodulator_priv;
45489- struct dvbt_get_status_msg result;
45490- u8 cmd[] = { CINERGYT2_EP1_GET_TUNER_STATUS };
45491+ struct dvbt_get_status_msg *result;
45492+ u8 *cmd;
45493 int ret;
45494
45495- ret = dvb_usb_generic_rw(state->d, cmd, sizeof(cmd), (u8 *)&result,
45496- sizeof(result), 0);
45497+ cmd = kmalloc(1, GFP_KERNEL);
45498+ if (cmd == NULL)
45499+ return -ENOMEM;
45500+ result = kmalloc(sizeof(*result), GFP_KERNEL);
45501+ if (result == NULL) {
45502+ kfree(cmd);
45503+ return -ENOMEM;
45504+ }
45505+
45506+ cmd[0] = CINERGYT2_EP1_GET_TUNER_STATUS;
45507+
45508+ ret = dvb_usb_generic_rw(state->d, cmd, 1, (u8 *)result,
45509+ sizeof(*result), 0);
45510 if (ret < 0)
45511- return ret;
45512+ goto out;
45513
45514 *status = 0;
45515
45516- if (0xffff - le16_to_cpu(result.gain) > 30)
45517+ if (0xffff - le16_to_cpu(result->gain) > 30)
45518 *status |= FE_HAS_SIGNAL;
45519- if (result.lock_bits & (1 << 6))
45520+ if (result->lock_bits & (1 << 6))
45521 *status |= FE_HAS_LOCK;
45522- if (result.lock_bits & (1 << 5))
45523+ if (result->lock_bits & (1 << 5))
45524 *status |= FE_HAS_SYNC;
45525- if (result.lock_bits & (1 << 4))
45526+ if (result->lock_bits & (1 << 4))
45527 *status |= FE_HAS_CARRIER;
45528- if (result.lock_bits & (1 << 1))
45529+ if (result->lock_bits & (1 << 1))
45530 *status |= FE_HAS_VITERBI;
45531
45532 if ((*status & (FE_HAS_CARRIER | FE_HAS_VITERBI | FE_HAS_SYNC)) !=
45533 (FE_HAS_CARRIER | FE_HAS_VITERBI | FE_HAS_SYNC))
45534 *status &= ~FE_HAS_LOCK;
45535
45536- return 0;
45537+out:
45538+ kfree(cmd);
45539+ kfree(result);
45540+ return ret;
45541 }
45542
45543 static int cinergyt2_fe_read_ber(struct dvb_frontend *fe, u32 *ber)
45544 {
45545 struct cinergyt2_fe_state *state = fe->demodulator_priv;
45546- struct dvbt_get_status_msg status;
45547- char cmd[] = { CINERGYT2_EP1_GET_TUNER_STATUS };
45548+ struct dvbt_get_status_msg *status;
45549+ char *cmd;
45550 int ret;
45551
45552- ret = dvb_usb_generic_rw(state->d, cmd, sizeof(cmd), (char *)&status,
45553- sizeof(status), 0);
45554+ cmd = kmalloc(1, GFP_KERNEL);
45555+ if (cmd == NULL)
45556+ return -ENOMEM;
45557+ status = kmalloc(sizeof(*status), GFP_KERNEL);
45558+ if (status == NULL) {
45559+ kfree(cmd);
45560+ return -ENOMEM;
45561+ }
45562+
45563+ cmd[0] = CINERGYT2_EP1_GET_TUNER_STATUS;
45564+
45565+ ret = dvb_usb_generic_rw(state->d, cmd, 1, (char *)status,
45566+ sizeof(*status), 0);
45567 if (ret < 0)
45568- return ret;
45569+ goto out;
45570
45571- *ber = le32_to_cpu(status.viterbi_error_rate);
45572+ *ber = le32_to_cpu(status->viterbi_error_rate);
45573+out:
45574+ kfree(cmd);
45575+ kfree(status);
45576 return 0;
45577 }
45578
45579 static int cinergyt2_fe_read_unc_blocks(struct dvb_frontend *fe, u32 *unc)
45580 {
45581 struct cinergyt2_fe_state *state = fe->demodulator_priv;
45582- struct dvbt_get_status_msg status;
45583- u8 cmd[] = { CINERGYT2_EP1_GET_TUNER_STATUS };
45584+ struct dvbt_get_status_msg *status;
45585+ u8 *cmd;
45586 int ret;
45587
45588- ret = dvb_usb_generic_rw(state->d, cmd, sizeof(cmd), (u8 *)&status,
45589- sizeof(status), 0);
45590+ cmd = kmalloc(1, GFP_KERNEL);
45591+ if (cmd == NULL)
45592+ return -ENOMEM;
45593+ status = kmalloc(sizeof(*status), GFP_KERNEL);
45594+ if (status == NULL) {
45595+ kfree(cmd);
45596+ return -ENOMEM;
45597+ }
45598+
45599+ cmd[0] = CINERGYT2_EP1_GET_TUNER_STATUS;
45600+
45601+ ret = dvb_usb_generic_rw(state->d, cmd, 1, (u8 *)status,
45602+ sizeof(*status), 0);
45603 if (ret < 0) {
45604 err("cinergyt2_fe_read_unc_blocks() Failed! (Error=%d)\n",
45605 ret);
45606- return ret;
45607+ goto out;
45608 }
45609- *unc = le32_to_cpu(status.uncorrected_block_count);
45610- return 0;
45611+ *unc = le32_to_cpu(status->uncorrected_block_count);
45612+
45613+out:
45614+ kfree(cmd);
45615+ kfree(status);
45616+ return ret;
45617 }
45618
45619 static int cinergyt2_fe_read_signal_strength(struct dvb_frontend *fe,
45620 u16 *strength)
45621 {
45622 struct cinergyt2_fe_state *state = fe->demodulator_priv;
45623- struct dvbt_get_status_msg status;
45624- char cmd[] = { CINERGYT2_EP1_GET_TUNER_STATUS };
45625+ struct dvbt_get_status_msg *status;
45626+ char *cmd;
45627 int ret;
45628
45629- ret = dvb_usb_generic_rw(state->d, cmd, sizeof(cmd), (char *)&status,
45630- sizeof(status), 0);
45631+ cmd = kmalloc(1, GFP_KERNEL);
45632+ if (cmd == NULL)
45633+ return -ENOMEM;
45634+ status = kmalloc(sizeof(*status), GFP_KERNEL);
45635+ if (status == NULL) {
45636+ kfree(cmd);
45637+ return -ENOMEM;
45638+ }
45639+
45640+ cmd[0] = CINERGYT2_EP1_GET_TUNER_STATUS;
45641+
45642+ ret = dvb_usb_generic_rw(state->d, cmd, 1, (char *)status,
45643+ sizeof(*status), 0);
45644 if (ret < 0) {
45645 err("cinergyt2_fe_read_signal_strength() Failed!"
45646 " (Error=%d)\n", ret);
45647- return ret;
45648+ goto out;
45649 }
45650- *strength = (0xffff - le16_to_cpu(status.gain));
45651+ *strength = (0xffff - le16_to_cpu(status->gain));
45652+
45653+out:
45654+ kfree(cmd);
45655+ kfree(status);
45656 return 0;
45657 }
45658
45659 static int cinergyt2_fe_read_snr(struct dvb_frontend *fe, u16 *snr)
45660 {
45661 struct cinergyt2_fe_state *state = fe->demodulator_priv;
45662- struct dvbt_get_status_msg status;
45663- char cmd[] = { CINERGYT2_EP1_GET_TUNER_STATUS };
45664+ struct dvbt_get_status_msg *status;
45665+ char *cmd;
45666 int ret;
45667
45668- ret = dvb_usb_generic_rw(state->d, cmd, sizeof(cmd), (char *)&status,
45669- sizeof(status), 0);
45670+ cmd = kmalloc(1, GFP_KERNEL);
45671+ if (cmd == NULL)
45672+ return -ENOMEM;
45673+ status = kmalloc(sizeof(*status), GFP_KERNEL);
45674+ if (status == NULL) {
45675+ kfree(cmd);
45676+ return -ENOMEM;
45677+ }
45678+
45679+ cmd[0] = CINERGYT2_EP1_GET_TUNER_STATUS;
45680+
45681+ ret = dvb_usb_generic_rw(state->d, cmd, 1, (char *)status,
45682+ sizeof(*status), 0);
45683 if (ret < 0) {
45684 err("cinergyt2_fe_read_snr() Failed! (Error=%d)\n", ret);
45685- return ret;
45686+ goto out;
45687 }
45688- *snr = (status.snr << 8) | status.snr;
45689- return 0;
45690+ *snr = (status->snr << 8) | status->snr;
45691+
45692+out:
45693+ kfree(cmd);
45694+ kfree(status);
45695+ return ret;
45696 }
45697
45698 static int cinergyt2_fe_init(struct dvb_frontend *fe)
45699@@ -266,35 +339,46 @@ static int cinergyt2_fe_set_frontend(struct dvb_frontend *fe)
45700 {
45701 struct dtv_frontend_properties *fep = &fe->dtv_property_cache;
45702 struct cinergyt2_fe_state *state = fe->demodulator_priv;
45703- struct dvbt_set_parameters_msg param;
45704- char result[2];
45705+ struct dvbt_set_parameters_msg *param;
45706+ char *result;
45707 int err;
45708
45709- param.cmd = CINERGYT2_EP1_SET_TUNER_PARAMETERS;
45710- param.tps = cpu_to_le16(compute_tps(fep));
45711- param.freq = cpu_to_le32(fep->frequency / 1000);
45712- param.flags = 0;
45713+ result = kmalloc(2, GFP_KERNEL);
45714+ if (result == NULL)
45715+ return -ENOMEM;
45716+ param = kmalloc(sizeof(*param), GFP_KERNEL);
45717+ if (param == NULL) {
45718+ kfree(result);
45719+ return -ENOMEM;
45720+ }
45721+
45722+ param->cmd = CINERGYT2_EP1_SET_TUNER_PARAMETERS;
45723+ param->tps = cpu_to_le16(compute_tps(fep));
45724+ param->freq = cpu_to_le32(fep->frequency / 1000);
45725+ param->flags = 0;
45726
45727 switch (fep->bandwidth_hz) {
45728 default:
45729 case 8000000:
45730- param.bandwidth = 8;
45731+ param->bandwidth = 8;
45732 break;
45733 case 7000000:
45734- param.bandwidth = 7;
45735+ param->bandwidth = 7;
45736 break;
45737 case 6000000:
45738- param.bandwidth = 6;
45739+ param->bandwidth = 6;
45740 break;
45741 }
45742
45743 err = dvb_usb_generic_rw(state->d,
45744- (char *)&param, sizeof(param),
45745- result, sizeof(result), 0);
45746+ (char *)param, sizeof(*param),
45747+ result, 2, 0);
45748 if (err < 0)
45749 err("cinergyt2_fe_set_frontend() Failed! err=%d\n", err);
45750
45751- return (err < 0) ? err : 0;
45752+ kfree(result);
45753+ kfree(param);
45754+ return err;
45755 }
45756
45757 static void cinergyt2_fe_release(struct dvb_frontend *fe)
45758diff --git a/drivers/media/usb/dvb-usb/dvb-usb-firmware.c b/drivers/media/usb/dvb-usb/dvb-usb-firmware.c
45759index 733a7ff..f8b52e3 100644
45760--- a/drivers/media/usb/dvb-usb/dvb-usb-firmware.c
45761+++ b/drivers/media/usb/dvb-usb/dvb-usb-firmware.c
45762@@ -35,42 +35,57 @@ static int usb_cypress_writemem(struct usb_device *udev,u16 addr,u8 *data, u8 le
45763
45764 int usb_cypress_load_firmware(struct usb_device *udev, const struct firmware *fw, int type)
45765 {
45766- struct hexline hx;
45767- u8 reset;
45768+ struct hexline *hx;
45769+ u8 *reset;
45770 int ret,pos=0;
45771
45772+ reset = kmalloc(1, GFP_KERNEL);
45773+ if (reset == NULL)
45774+ return -ENOMEM;
45775+
45776+ hx = kmalloc(sizeof(struct hexline), GFP_KERNEL);
45777+ if (hx == NULL) {
45778+ kfree(reset);
45779+ return -ENOMEM;
45780+ }
45781+
45782 /* stop the CPU */
45783- reset = 1;
45784- if ((ret = usb_cypress_writemem(udev,cypress[type].cpu_cs_register,&reset,1)) != 1)
45785+ reset[0] = 1;
45786+ if ((ret = usb_cypress_writemem(udev,cypress[type].cpu_cs_register,reset,1)) != 1)
45787 err("could not stop the USB controller CPU.");
45788
45789- while ((ret = dvb_usb_get_hexline(fw,&hx,&pos)) > 0) {
45790- deb_fw("writing to address 0x%04x (buffer: 0x%02x %02x)\n",hx.addr,hx.len,hx.chk);
45791- ret = usb_cypress_writemem(udev,hx.addr,hx.data,hx.len);
45792+ while ((ret = dvb_usb_get_hexline(fw,hx,&pos)) > 0) {
45793+ deb_fw("writing to address 0x%04x (buffer: 0x%02x %02x)\n",hx->addr,hx->len,hx->chk);
45794+ ret = usb_cypress_writemem(udev,hx->addr,hx->data,hx->len);
45795
45796- if (ret != hx.len) {
45797+ if (ret != hx->len) {
45798 err("error while transferring firmware "
45799 "(transferred size: %d, block size: %d)",
45800- ret,hx.len);
45801+ ret,hx->len);
45802 ret = -EINVAL;
45803 break;
45804 }
45805 }
45806 if (ret < 0) {
45807 err("firmware download failed at %d with %d",pos,ret);
45808+ kfree(reset);
45809+ kfree(hx);
45810 return ret;
45811 }
45812
45813 if (ret == 0) {
45814 /* restart the CPU */
45815- reset = 0;
45816- if (ret || usb_cypress_writemem(udev,cypress[type].cpu_cs_register,&reset,1) != 1) {
45817+ reset[0] = 0;
45818+ if (ret || usb_cypress_writemem(udev,cypress[type].cpu_cs_register,reset,1) != 1) {
45819 err("could not restart the USB controller CPU.");
45820 ret = -EINVAL;
45821 }
45822 } else
45823 ret = -EIO;
45824
45825+ kfree(reset);
45826+ kfree(hx);
45827+
45828 return ret;
45829 }
45830 EXPORT_SYMBOL(usb_cypress_load_firmware);
45831diff --git a/drivers/media/usb/dvb-usb/dw2102.c b/drivers/media/usb/dvb-usb/dw2102.c
45832index 1a3df10..57997a5 100644
45833--- a/drivers/media/usb/dvb-usb/dw2102.c
45834+++ b/drivers/media/usb/dvb-usb/dw2102.c
45835@@ -118,7 +118,7 @@ struct su3000_state {
45836
45837 struct s6x0_state {
45838 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
45839-};
45840+} __no_const;
45841
45842 /* debug */
45843 static int dvb_usb_dw2102_debug;
45844diff --git a/drivers/media/usb/dvb-usb/technisat-usb2.c b/drivers/media/usb/dvb-usb/technisat-usb2.c
45845index 6b0b8b6b..4038398 100644
45846--- a/drivers/media/usb/dvb-usb/technisat-usb2.c
45847+++ b/drivers/media/usb/dvb-usb/technisat-usb2.c
45848@@ -87,8 +87,11 @@ struct technisat_usb2_state {
45849 static int technisat_usb2_i2c_access(struct usb_device *udev,
45850 u8 device_addr, u8 *tx, u8 txlen, u8 *rx, u8 rxlen)
45851 {
45852- u8 b[64];
45853- int ret, actual_length;
45854+ u8 *b = kmalloc(64, GFP_KERNEL);
45855+ int ret, actual_length, error = 0;
45856+
45857+ if (b == NULL)
45858+ return -ENOMEM;
45859
45860 deb_i2c("i2c-access: %02x, tx: ", device_addr);
45861 debug_dump(tx, txlen, deb_i2c);
45862@@ -121,7 +124,8 @@ static int technisat_usb2_i2c_access(struct usb_device *udev,
45863
45864 if (ret < 0) {
45865 err("i2c-error: out failed %02x = %d", device_addr, ret);
45866- return -ENODEV;
45867+ error = -ENODEV;
45868+ goto out;
45869 }
45870
45871 ret = usb_bulk_msg(udev,
45872@@ -129,7 +133,8 @@ static int technisat_usb2_i2c_access(struct usb_device *udev,
45873 b, 64, &actual_length, 1000);
45874 if (ret < 0) {
45875 err("i2c-error: in failed %02x = %d", device_addr, ret);
45876- return -ENODEV;
45877+ error = -ENODEV;
45878+ goto out;
45879 }
45880
45881 if (b[0] != I2C_STATUS_OK) {
45882@@ -137,8 +142,10 @@ static int technisat_usb2_i2c_access(struct usb_device *udev,
45883 /* handle tuner-i2c-nak */
45884 if (!(b[0] == I2C_STATUS_NAK &&
45885 device_addr == 0x60
45886- /* && device_is_technisat_usb2 */))
45887- return -ENODEV;
45888+ /* && device_is_technisat_usb2 */)) {
45889+ error = -ENODEV;
45890+ goto out;
45891+ }
45892 }
45893
45894 deb_i2c("status: %d, ", b[0]);
45895@@ -152,7 +159,9 @@ static int technisat_usb2_i2c_access(struct usb_device *udev,
45896
45897 deb_i2c("\n");
45898
45899- return 0;
45900+out:
45901+ kfree(b);
45902+ return error;
45903 }
45904
45905 static int technisat_usb2_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg *msg,
45906@@ -224,14 +233,16 @@ static int technisat_usb2_set_led(struct dvb_usb_device *d, int red, enum techni
45907 {
45908 int ret;
45909
45910- u8 led[8] = {
45911- red ? SET_RED_LED_VENDOR_REQUEST : SET_GREEN_LED_VENDOR_REQUEST,
45912- 0
45913- };
45914+ u8 *led = kzalloc(8, GFP_KERNEL);
45915+
45916+ if (led == NULL)
45917+ return -ENOMEM;
45918
45919 if (disable_led_control && state != TECH_LED_OFF)
45920 return 0;
45921
45922+ led[0] = red ? SET_RED_LED_VENDOR_REQUEST : SET_GREEN_LED_VENDOR_REQUEST;
45923+
45924 switch (state) {
45925 case TECH_LED_ON:
45926 led[1] = 0x82;
45927@@ -263,16 +274,22 @@ static int technisat_usb2_set_led(struct dvb_usb_device *d, int red, enum techni
45928 red ? SET_RED_LED_VENDOR_REQUEST : SET_GREEN_LED_VENDOR_REQUEST,
45929 USB_TYPE_VENDOR | USB_DIR_OUT,
45930 0, 0,
45931- led, sizeof(led), 500);
45932+ led, 8, 500);
45933
45934 mutex_unlock(&d->i2c_mutex);
45935+
45936+ kfree(led);
45937+
45938 return ret;
45939 }
45940
45941 static int technisat_usb2_set_led_timer(struct dvb_usb_device *d, u8 red, u8 green)
45942 {
45943 int ret;
45944- u8 b = 0;
45945+ u8 *b = kzalloc(1, GFP_KERNEL);
45946+
45947+ if (b == NULL)
45948+ return -ENOMEM;
45949
45950 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
45951 return -EAGAIN;
45952@@ -281,10 +298,12 @@ static int technisat_usb2_set_led_timer(struct dvb_usb_device *d, u8 red, u8 gre
45953 SET_LED_TIMER_DIVIDER_VENDOR_REQUEST,
45954 USB_TYPE_VENDOR | USB_DIR_OUT,
45955 (red << 8) | green, 0,
45956- &b, 1, 500);
45957+ b, 1, 500);
45958
45959 mutex_unlock(&d->i2c_mutex);
45960
45961+ kfree(b);
45962+
45963 return ret;
45964 }
45965
45966@@ -328,7 +347,7 @@ static int technisat_usb2_identify_state(struct usb_device *udev,
45967 struct dvb_usb_device_description **desc, int *cold)
45968 {
45969 int ret;
45970- u8 version[3];
45971+ u8 *version = kmalloc(3, GFP_KERNEL);
45972
45973 /* first select the interface */
45974 if (usb_set_interface(udev, 0, 1) != 0)
45975@@ -338,11 +357,14 @@ static int technisat_usb2_identify_state(struct usb_device *udev,
45976
45977 *cold = 0; /* by default do not download a firmware - just in case something is wrong */
45978
45979+ if (version == NULL)
45980+ return 0;
45981+
45982 ret = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
45983 GET_VERSION_INFO_VENDOR_REQUEST,
45984 USB_TYPE_VENDOR | USB_DIR_IN,
45985 0, 0,
45986- version, sizeof(version), 500);
45987+ version, 3, 500);
45988
45989 if (ret < 0)
45990 *cold = 1;
45991@@ -351,6 +373,8 @@ static int technisat_usb2_identify_state(struct usb_device *udev,
45992 *cold = 0;
45993 }
45994
45995+ kfree(version);
45996+
45997 return 0;
45998 }
45999
46000@@ -591,10 +615,15 @@ static int technisat_usb2_frontend_attach(struct dvb_usb_adapter *a)
46001
46002 static int technisat_usb2_get_ir(struct dvb_usb_device *d)
46003 {
46004- u8 buf[62], *b;
46005+ u8 *buf, *b;
46006 int ret;
46007 struct ir_raw_event ev;
46008
46009+ buf = kmalloc(62, GFP_KERNEL);
46010+
46011+ if (buf == NULL)
46012+ return -ENOMEM;
46013+
46014 buf[0] = GET_IR_DATA_VENDOR_REQUEST;
46015 buf[1] = 0x08;
46016 buf[2] = 0x8f;
46017@@ -617,16 +646,20 @@ static int technisat_usb2_get_ir(struct dvb_usb_device *d)
46018 GET_IR_DATA_VENDOR_REQUEST,
46019 USB_TYPE_VENDOR | USB_DIR_IN,
46020 0x8080, 0,
46021- buf, sizeof(buf), 500);
46022+ buf, 62, 500);
46023
46024 unlock:
46025 mutex_unlock(&d->i2c_mutex);
46026
46027- if (ret < 0)
46028+ if (ret < 0) {
46029+ kfree(buf);
46030 return ret;
46031+ }
46032
46033- if (ret == 1)
46034+ if (ret == 1) {
46035+ kfree(buf);
46036 return 0; /* no key pressed */
46037+ }
46038
46039 /* decoding */
46040 b = buf+1;
46041@@ -653,6 +686,8 @@ unlock:
46042
46043 ir_raw_event_handle(d->rc_dev);
46044
46045+ kfree(buf);
46046+
46047 return 1;
46048 }
46049
46050diff --git a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
46051index e502a5f..2a27f40 100644
46052--- a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
46053+++ b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
46054@@ -427,7 +427,7 @@ static int get_v4l2_buffer32(struct v4l2_buffer *kp, struct v4l2_buffer32 __user
46055 * by passing a very big num_planes value */
46056 uplane = compat_alloc_user_space(num_planes *
46057 sizeof(struct v4l2_plane));
46058- kp->m.planes = (__force struct v4l2_plane *)uplane;
46059+ kp->m.planes = (__force_kernel struct v4l2_plane *)uplane;
46060
46061 while (--num_planes >= 0) {
46062 ret = get_v4l2_plane32(uplane, uplane32, kp->memory);
46063@@ -498,7 +498,7 @@ static int put_v4l2_buffer32(struct v4l2_buffer *kp, struct v4l2_buffer32 __user
46064 if (num_planes == 0)
46065 return 0;
46066
46067- uplane = (__force struct v4l2_plane __user *)kp->m.planes;
46068+ uplane = (struct v4l2_plane __force_user *)kp->m.planes;
46069 if (get_user(p, &up->m.planes))
46070 return -EFAULT;
46071 uplane32 = compat_ptr(p);
46072@@ -562,7 +562,7 @@ static int get_v4l2_framebuffer32(struct v4l2_framebuffer *kp, struct v4l2_frame
46073 get_user(kp->flags, &up->flags) ||
46074 copy_from_user(&kp->fmt, &up->fmt, sizeof(up->fmt)))
46075 return -EFAULT;
46076- kp->base = (__force void *)compat_ptr(tmp);
46077+ kp->base = (__force_kernel void *)compat_ptr(tmp);
46078 return 0;
46079 }
46080
46081@@ -667,7 +667,7 @@ static int get_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext
46082 n * sizeof(struct v4l2_ext_control32)))
46083 return -EFAULT;
46084 kcontrols = compat_alloc_user_space(n * sizeof(struct v4l2_ext_control));
46085- kp->controls = (__force struct v4l2_ext_control *)kcontrols;
46086+ kp->controls = (__force_kernel struct v4l2_ext_control *)kcontrols;
46087 while (--n >= 0) {
46088 u32 id;
46089
46090@@ -694,7 +694,7 @@ static int put_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext
46091 {
46092 struct v4l2_ext_control32 __user *ucontrols;
46093 struct v4l2_ext_control __user *kcontrols =
46094- (__force struct v4l2_ext_control __user *)kp->controls;
46095+ (struct v4l2_ext_control __force_user *)kp->controls;
46096 int n = kp->count;
46097 compat_caddr_t p;
46098
46099@@ -778,7 +778,7 @@ static int get_v4l2_edid32(struct v4l2_edid *kp, struct v4l2_edid32 __user *up)
46100 get_user(tmp, &up->edid) ||
46101 copy_from_user(kp->reserved, up->reserved, sizeof(kp->reserved)))
46102 return -EFAULT;
46103- kp->edid = (__force u8 *)compat_ptr(tmp);
46104+ kp->edid = (__force_kernel u8 *)compat_ptr(tmp);
46105 return 0;
46106 }
46107
46108diff --git a/drivers/media/v4l2-core/v4l2-device.c b/drivers/media/v4l2-core/v4l2-device.c
46109index 015f92a..59e311e 100644
46110--- a/drivers/media/v4l2-core/v4l2-device.c
46111+++ b/drivers/media/v4l2-core/v4l2-device.c
46112@@ -75,9 +75,9 @@ int v4l2_device_put(struct v4l2_device *v4l2_dev)
46113 EXPORT_SYMBOL_GPL(v4l2_device_put);
46114
46115 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
46116- atomic_t *instance)
46117+ atomic_unchecked_t *instance)
46118 {
46119- int num = atomic_inc_return(instance) - 1;
46120+ int num = atomic_inc_return_unchecked(instance) - 1;
46121 int len = strlen(basename);
46122
46123 if (basename[len - 1] >= '0' && basename[len - 1] <= '9')
46124diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c
46125index 9ccb19a..d131468 100644
46126--- a/drivers/media/v4l2-core/v4l2-ioctl.c
46127+++ b/drivers/media/v4l2-core/v4l2-ioctl.c
46128@@ -2142,7 +2142,8 @@ struct v4l2_ioctl_info {
46129 struct file *file, void *fh, void *p);
46130 } u;
46131 void (*debug)(const void *arg, bool write_only);
46132-};
46133+} __do_const;
46134+typedef struct v4l2_ioctl_info __no_const v4l2_ioctl_info_no_const;
46135
46136 /* This control needs a priority check */
46137 #define INFO_FL_PRIO (1 << 0)
46138@@ -2326,7 +2327,7 @@ static long __video_do_ioctl(struct file *file,
46139 struct video_device *vfd = video_devdata(file);
46140 const struct v4l2_ioctl_ops *ops = vfd->ioctl_ops;
46141 bool write_only = false;
46142- struct v4l2_ioctl_info default_info;
46143+ v4l2_ioctl_info_no_const default_info;
46144 const struct v4l2_ioctl_info *info;
46145 void *fh = file->private_data;
46146 struct v4l2_fh *vfh = NULL;
46147@@ -2413,7 +2414,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
46148 ret = -EINVAL;
46149 break;
46150 }
46151- *user_ptr = (void __user *)buf->m.planes;
46152+ *user_ptr = (void __force_user *)buf->m.planes;
46153 *kernel_ptr = (void **)&buf->m.planes;
46154 *array_size = sizeof(struct v4l2_plane) * buf->length;
46155 ret = 1;
46156@@ -2430,7 +2431,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
46157 ret = -EINVAL;
46158 break;
46159 }
46160- *user_ptr = (void __user *)edid->edid;
46161+ *user_ptr = (void __force_user *)edid->edid;
46162 *kernel_ptr = (void **)&edid->edid;
46163 *array_size = edid->blocks * 128;
46164 ret = 1;
46165@@ -2448,7 +2449,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
46166 ret = -EINVAL;
46167 break;
46168 }
46169- *user_ptr = (void __user *)ctrls->controls;
46170+ *user_ptr = (void __force_user *)ctrls->controls;
46171 *kernel_ptr = (void **)&ctrls->controls;
46172 *array_size = sizeof(struct v4l2_ext_control)
46173 * ctrls->count;
46174@@ -2549,7 +2550,7 @@ video_usercopy(struct file *file, unsigned int cmd, unsigned long arg,
46175 }
46176
46177 if (has_array_args) {
46178- *kernel_ptr = (void __force *)user_ptr;
46179+ *kernel_ptr = (void __force_kernel *)user_ptr;
46180 if (copy_to_user(user_ptr, mbuf, array_size))
46181 err = -EFAULT;
46182 goto out_array_args;
46183diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
46184index 187f836..679544b 100644
46185--- a/drivers/message/fusion/mptbase.c
46186+++ b/drivers/message/fusion/mptbase.c
46187@@ -6746,8 +6746,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
46188 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
46189 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
46190
46191+#ifdef CONFIG_GRKERNSEC_HIDESYM
46192+ seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
46193+#else
46194 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
46195 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
46196+#endif
46197+
46198 /*
46199 * Rounding UP to nearest 4-kB boundary here...
46200 */
46201@@ -6760,7 +6765,11 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
46202 ioc->facts.GlobalCredits);
46203
46204 seq_printf(m, " Frames @ 0x%p (Dma @ 0x%p)\n",
46205+#ifdef CONFIG_GRKERNSEC_HIDESYM
46206+ NULL, NULL);
46207+#else
46208 (void *)ioc->alloc, (void *)(ulong)ioc->alloc_dma);
46209+#endif
46210 sz = (ioc->reply_sz * ioc->reply_depth) + 128;
46211 seq_printf(m, " {CurRepSz=%d} x {CurRepDepth=%d} = %d bytes ^= 0x%x\n",
46212 ioc->reply_sz, ioc->reply_depth, ioc->reply_sz*ioc->reply_depth, sz);
46213diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
46214index 0707fa2..70ca794 100644
46215--- a/drivers/message/fusion/mptsas.c
46216+++ b/drivers/message/fusion/mptsas.c
46217@@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
46218 return 0;
46219 }
46220
46221+static inline void
46222+mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
46223+{
46224+ if (phy_info->port_details) {
46225+ phy_info->port_details->rphy = rphy;
46226+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
46227+ ioc->name, rphy));
46228+ }
46229+
46230+ if (rphy) {
46231+ dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
46232+ &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
46233+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
46234+ ioc->name, rphy, rphy->dev.release));
46235+ }
46236+}
46237+
46238 /* no mutex */
46239 static void
46240 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
46241@@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
46242 return NULL;
46243 }
46244
46245-static inline void
46246-mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
46247-{
46248- if (phy_info->port_details) {
46249- phy_info->port_details->rphy = rphy;
46250- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
46251- ioc->name, rphy));
46252- }
46253-
46254- if (rphy) {
46255- dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
46256- &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
46257- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
46258- ioc->name, rphy, rphy->dev.release));
46259- }
46260-}
46261-
46262 static inline struct sas_port *
46263 mptsas_get_port(struct mptsas_phyinfo *phy_info)
46264 {
46265diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
46266index b7d87cd..3fb36da 100644
46267--- a/drivers/message/i2o/i2o_proc.c
46268+++ b/drivers/message/i2o/i2o_proc.c
46269@@ -255,12 +255,6 @@ static char *scsi_devices[] = {
46270 "Array Controller Device"
46271 };
46272
46273-static char *chtostr(char *tmp, u8 *chars, int n)
46274-{
46275- tmp[0] = 0;
46276- return strncat(tmp, (char *)chars, n);
46277-}
46278-
46279 static int i2o_report_query_status(struct seq_file *seq, int block_status,
46280 char *group)
46281 {
46282@@ -707,9 +701,9 @@ static int i2o_seq_show_status(struct seq_file *seq, void *v)
46283 static int i2o_seq_show_hw(struct seq_file *seq, void *v)
46284 {
46285 struct i2o_controller *c = (struct i2o_controller *)seq->private;
46286- static u32 work32[5];
46287- static u8 *work8 = (u8 *) work32;
46288- static u16 *work16 = (u16 *) work32;
46289+ u32 work32[5];
46290+ u8 *work8 = (u8 *) work32;
46291+ u16 *work16 = (u16 *) work32;
46292 int token;
46293 u32 hwcap;
46294
46295@@ -790,7 +784,6 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
46296 } *result;
46297
46298 i2o_exec_execute_ddm_table ddm_table;
46299- char tmp[28 + 1];
46300
46301 result = kmalloc(sizeof(*result), GFP_KERNEL);
46302 if (!result)
46303@@ -825,8 +818,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
46304
46305 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
46306 seq_printf(seq, "%-#8x", ddm_table.module_id);
46307- seq_printf(seq, "%-29s",
46308- chtostr(tmp, ddm_table.module_name_version, 28));
46309+ seq_printf(seq, "%-.28s", ddm_table.module_name_version);
46310 seq_printf(seq, "%9d ", ddm_table.data_size);
46311 seq_printf(seq, "%8d", ddm_table.code_size);
46312
46313@@ -893,7 +885,6 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
46314
46315 i2o_driver_result_table *result;
46316 i2o_driver_store_table *dst;
46317- char tmp[28 + 1];
46318
46319 result = kmalloc(sizeof(i2o_driver_result_table), GFP_KERNEL);
46320 if (result == NULL)
46321@@ -928,9 +919,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
46322
46323 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
46324 seq_printf(seq, "%-#8x", dst->module_id);
46325- seq_printf(seq, "%-29s",
46326- chtostr(tmp, dst->module_name_version, 28));
46327- seq_printf(seq, "%-9s", chtostr(tmp, dst->date, 8));
46328+ seq_printf(seq, "%-.28s", dst->module_name_version);
46329+ seq_printf(seq, "%-.8s", dst->date);
46330 seq_printf(seq, "%8d ", dst->module_size);
46331 seq_printf(seq, "%8d ", dst->mpb_size);
46332 seq_printf(seq, "0x%04x", dst->module_flags);
46333@@ -1246,11 +1236,10 @@ static int i2o_seq_show_authorized_users(struct seq_file *seq, void *v)
46334 static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
46335 {
46336 struct i2o_device *d = (struct i2o_device *)seq->private;
46337- static u32 work32[128]; // allow for "stuff" + up to 256 byte (max) serial number
46338+ u32 work32[128]; // allow for "stuff" + up to 256 byte (max) serial number
46339 // == (allow) 512d bytes (max)
46340- static u16 *work16 = (u16 *) work32;
46341+ u16 *work16 = (u16 *) work32;
46342 int token;
46343- char tmp[16 + 1];
46344
46345 token = i2o_parm_field_get(d, 0xF100, -1, &work32, sizeof(work32));
46346
46347@@ -1262,14 +1251,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
46348 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
46349 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
46350 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
46351- seq_printf(seq, "Vendor info : %s\n",
46352- chtostr(tmp, (u8 *) (work32 + 2), 16));
46353- seq_printf(seq, "Product info : %s\n",
46354- chtostr(tmp, (u8 *) (work32 + 6), 16));
46355- seq_printf(seq, "Description : %s\n",
46356- chtostr(tmp, (u8 *) (work32 + 10), 16));
46357- seq_printf(seq, "Product rev. : %s\n",
46358- chtostr(tmp, (u8 *) (work32 + 14), 8));
46359+ seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
46360+ seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
46361+ seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
46362+ seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
46363
46364 seq_printf(seq, "Serial number : ");
46365 print_serial_number(seq, (u8 *) (work32 + 16),
46366@@ -1306,8 +1291,6 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
46367 u8 pad[256]; // allow up to 256 byte (max) serial number
46368 } result;
46369
46370- char tmp[24 + 1];
46371-
46372 token = i2o_parm_field_get(d, 0xF101, -1, &result, sizeof(result));
46373
46374 if (token < 0) {
46375@@ -1316,10 +1299,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
46376 }
46377
46378 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
46379- seq_printf(seq, "Module name : %s\n",
46380- chtostr(tmp, result.module_name, 24));
46381- seq_printf(seq, "Module revision : %s\n",
46382- chtostr(tmp, result.module_rev, 8));
46383+ seq_printf(seq, "Module name : %.24s\n", result.module_name);
46384+ seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
46385
46386 seq_printf(seq, "Serial number : ");
46387 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
46388@@ -1343,8 +1324,6 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
46389 u8 instance_number[4];
46390 } result;
46391
46392- char tmp[64 + 1];
46393-
46394 token = i2o_parm_field_get(d, 0xF102, -1, &result, sizeof(result));
46395
46396 if (token < 0) {
46397@@ -1352,14 +1331,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
46398 return 0;
46399 }
46400
46401- seq_printf(seq, "Device name : %s\n",
46402- chtostr(tmp, result.device_name, 64));
46403- seq_printf(seq, "Service name : %s\n",
46404- chtostr(tmp, result.service_name, 64));
46405- seq_printf(seq, "Physical name : %s\n",
46406- chtostr(tmp, result.physical_location, 64));
46407- seq_printf(seq, "Instance number : %s\n",
46408- chtostr(tmp, result.instance_number, 4));
46409+ seq_printf(seq, "Device name : %.64s\n", result.device_name);
46410+ seq_printf(seq, "Service name : %.64s\n", result.service_name);
46411+ seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
46412+ seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
46413
46414 return 0;
46415 }
46416@@ -1368,9 +1343,9 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
46417 static int i2o_seq_show_sgl_limits(struct seq_file *seq, void *v)
46418 {
46419 struct i2o_device *d = (struct i2o_device *)seq->private;
46420- static u32 work32[12];
46421- static u16 *work16 = (u16 *) work32;
46422- static u8 *work8 = (u8 *) work32;
46423+ u32 work32[12];
46424+ u16 *work16 = (u16 *) work32;
46425+ u8 *work8 = (u8 *) work32;
46426 int token;
46427
46428 token = i2o_parm_field_get(d, 0xF103, -1, &work32, sizeof(work32));
46429diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
46430index 92752fb..a7494f6 100644
46431--- a/drivers/message/i2o/iop.c
46432+++ b/drivers/message/i2o/iop.c
46433@@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
46434
46435 spin_lock_irqsave(&c->context_list_lock, flags);
46436
46437- if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
46438- atomic_inc(&c->context_list_counter);
46439+ if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
46440+ atomic_inc_unchecked(&c->context_list_counter);
46441
46442- entry->context = atomic_read(&c->context_list_counter);
46443+ entry->context = atomic_read_unchecked(&c->context_list_counter);
46444
46445 list_add(&entry->list, &c->context_list);
46446
46447@@ -1076,7 +1076,7 @@ struct i2o_controller *i2o_iop_alloc(void)
46448
46449 #if BITS_PER_LONG == 64
46450 spin_lock_init(&c->context_list_lock);
46451- atomic_set(&c->context_list_counter, 0);
46452+ atomic_set_unchecked(&c->context_list_counter, 0);
46453 INIT_LIST_HEAD(&c->context_list);
46454 #endif
46455
46456diff --git a/drivers/mfd/ab8500-debugfs.c b/drivers/mfd/ab8500-debugfs.c
46457index b2c7e3b..85aa4764 100644
46458--- a/drivers/mfd/ab8500-debugfs.c
46459+++ b/drivers/mfd/ab8500-debugfs.c
46460@@ -100,7 +100,7 @@ static int irq_last;
46461 static u32 *irq_count;
46462 static int num_irqs;
46463
46464-static struct device_attribute **dev_attr;
46465+static device_attribute_no_const **dev_attr;
46466 static char **event_name;
46467
46468 static u8 avg_sample = SAMPLE_16;
46469diff --git a/drivers/mfd/max8925-i2c.c b/drivers/mfd/max8925-i2c.c
46470index c880c89..45a7c68 100644
46471--- a/drivers/mfd/max8925-i2c.c
46472+++ b/drivers/mfd/max8925-i2c.c
46473@@ -152,7 +152,7 @@ static int max8925_probe(struct i2c_client *client,
46474 const struct i2c_device_id *id)
46475 {
46476 struct max8925_platform_data *pdata = dev_get_platdata(&client->dev);
46477- static struct max8925_chip *chip;
46478+ struct max8925_chip *chip;
46479 struct device_node *node = client->dev.of_node;
46480
46481 if (node && !pdata) {
46482diff --git a/drivers/mfd/tps65910.c b/drivers/mfd/tps65910.c
46483index 7612d89..70549c2 100644
46484--- a/drivers/mfd/tps65910.c
46485+++ b/drivers/mfd/tps65910.c
46486@@ -230,7 +230,7 @@ static int tps65910_irq_init(struct tps65910 *tps65910, int irq,
46487 struct tps65910_platform_data *pdata)
46488 {
46489 int ret = 0;
46490- static struct regmap_irq_chip *tps6591x_irqs_chip;
46491+ struct regmap_irq_chip *tps6591x_irqs_chip;
46492
46493 if (!irq) {
46494 dev_warn(tps65910->dev, "No interrupt support, no core IRQ\n");
46495diff --git a/drivers/mfd/twl4030-irq.c b/drivers/mfd/twl4030-irq.c
46496index 1b772ef..01e77d33 100644
46497--- a/drivers/mfd/twl4030-irq.c
46498+++ b/drivers/mfd/twl4030-irq.c
46499@@ -34,6 +34,7 @@
46500 #include <linux/of.h>
46501 #include <linux/irqdomain.h>
46502 #include <linux/i2c/twl.h>
46503+#include <asm/pgtable.h>
46504
46505 #include "twl-core.h"
46506
46507@@ -729,10 +730,12 @@ int twl4030_init_irq(struct device *dev, int irq_num)
46508 * Install an irq handler for each of the SIH modules;
46509 * clone dummy irq_chip since PIH can't *do* anything
46510 */
46511- twl4030_irq_chip = dummy_irq_chip;
46512- twl4030_irq_chip.name = "twl4030";
46513+ pax_open_kernel();
46514+ memcpy((void *)&twl4030_irq_chip, &dummy_irq_chip, sizeof twl4030_irq_chip);
46515+ *(const char **)&twl4030_irq_chip.name = "twl4030";
46516
46517- twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
46518+ *(void **)&twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
46519+ pax_close_kernel();
46520
46521 for (i = irq_base; i < irq_end; i++) {
46522 irq_set_chip_and_handler(i, &twl4030_irq_chip,
46523diff --git a/drivers/misc/c2port/core.c b/drivers/misc/c2port/core.c
46524index 464419b..64bae8d 100644
46525--- a/drivers/misc/c2port/core.c
46526+++ b/drivers/misc/c2port/core.c
46527@@ -922,7 +922,9 @@ struct c2port_device *c2port_device_register(char *name,
46528 goto error_idr_alloc;
46529 c2dev->id = ret;
46530
46531- bin_attr_flash_data.size = ops->blocks_num * ops->block_size;
46532+ pax_open_kernel();
46533+ *(size_t *)&bin_attr_flash_data.size = ops->blocks_num * ops->block_size;
46534+ pax_close_kernel();
46535
46536 c2dev->dev = device_create(c2port_class, NULL, 0, c2dev,
46537 "c2port%d", c2dev->id);
46538diff --git a/drivers/misc/eeprom/sunxi_sid.c b/drivers/misc/eeprom/sunxi_sid.c
46539index 3f2b625..945e179 100644
46540--- a/drivers/misc/eeprom/sunxi_sid.c
46541+++ b/drivers/misc/eeprom/sunxi_sid.c
46542@@ -126,7 +126,9 @@ static int sunxi_sid_probe(struct platform_device *pdev)
46543
46544 platform_set_drvdata(pdev, sid_data);
46545
46546- sid_bin_attr.size = sid_data->keysize;
46547+ pax_open_kernel();
46548+ *(size_t *)&sid_bin_attr.size = sid_data->keysize;
46549+ pax_close_kernel();
46550 if (device_create_bin_file(&pdev->dev, &sid_bin_attr))
46551 return -ENODEV;
46552
46553diff --git a/drivers/misc/kgdbts.c b/drivers/misc/kgdbts.c
46554index 36f5d52..32311c3 100644
46555--- a/drivers/misc/kgdbts.c
46556+++ b/drivers/misc/kgdbts.c
46557@@ -834,7 +834,7 @@ static void run_plant_and_detach_test(int is_early)
46558 char before[BREAK_INSTR_SIZE];
46559 char after[BREAK_INSTR_SIZE];
46560
46561- probe_kernel_read(before, (char *)kgdbts_break_test,
46562+ probe_kernel_read(before, ktla_ktva((char *)kgdbts_break_test),
46563 BREAK_INSTR_SIZE);
46564 init_simple_test();
46565 ts.tst = plant_and_detach_test;
46566@@ -842,7 +842,7 @@ static void run_plant_and_detach_test(int is_early)
46567 /* Activate test with initial breakpoint */
46568 if (!is_early)
46569 kgdb_breakpoint();
46570- probe_kernel_read(after, (char *)kgdbts_break_test,
46571+ probe_kernel_read(after, ktla_ktva((char *)kgdbts_break_test),
46572 BREAK_INSTR_SIZE);
46573 if (memcmp(before, after, BREAK_INSTR_SIZE)) {
46574 printk(KERN_CRIT "kgdbts: ERROR kgdb corrupted memory\n");
46575diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
46576index 3ef4627..8d00486 100644
46577--- a/drivers/misc/lis3lv02d/lis3lv02d.c
46578+++ b/drivers/misc/lis3lv02d/lis3lv02d.c
46579@@ -497,7 +497,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
46580 * the lid is closed. This leads to interrupts as soon as a little move
46581 * is done.
46582 */
46583- atomic_inc(&lis3->count);
46584+ atomic_inc_unchecked(&lis3->count);
46585
46586 wake_up_interruptible(&lis3->misc_wait);
46587 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
46588@@ -583,7 +583,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
46589 if (lis3->pm_dev)
46590 pm_runtime_get_sync(lis3->pm_dev);
46591
46592- atomic_set(&lis3->count, 0);
46593+ atomic_set_unchecked(&lis3->count, 0);
46594 return 0;
46595 }
46596
46597@@ -615,7 +615,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
46598 add_wait_queue(&lis3->misc_wait, &wait);
46599 while (true) {
46600 set_current_state(TASK_INTERRUPTIBLE);
46601- data = atomic_xchg(&lis3->count, 0);
46602+ data = atomic_xchg_unchecked(&lis3->count, 0);
46603 if (data)
46604 break;
46605
46606@@ -656,7 +656,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
46607 struct lis3lv02d, miscdev);
46608
46609 poll_wait(file, &lis3->misc_wait, wait);
46610- if (atomic_read(&lis3->count))
46611+ if (atomic_read_unchecked(&lis3->count))
46612 return POLLIN | POLLRDNORM;
46613 return 0;
46614 }
46615diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
46616index c439c82..1f20f57 100644
46617--- a/drivers/misc/lis3lv02d/lis3lv02d.h
46618+++ b/drivers/misc/lis3lv02d/lis3lv02d.h
46619@@ -297,7 +297,7 @@ struct lis3lv02d {
46620 struct input_polled_dev *idev; /* input device */
46621 struct platform_device *pdev; /* platform device */
46622 struct regulator_bulk_data regulators[2];
46623- atomic_t count; /* interrupt count after last read */
46624+ atomic_unchecked_t count; /* interrupt count after last read */
46625 union axis_conversion ac; /* hw -> logical axis */
46626 int mapped_btns[3];
46627
46628diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
46629index 2f30bad..c4c13d0 100644
46630--- a/drivers/misc/sgi-gru/gruhandles.c
46631+++ b/drivers/misc/sgi-gru/gruhandles.c
46632@@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
46633 unsigned long nsec;
46634
46635 nsec = CLKS2NSEC(clks);
46636- atomic_long_inc(&mcs_op_statistics[op].count);
46637- atomic_long_add(nsec, &mcs_op_statistics[op].total);
46638+ atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
46639+ atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
46640 if (mcs_op_statistics[op].max < nsec)
46641 mcs_op_statistics[op].max = nsec;
46642 }
46643diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
46644index 4f76359..cdfcb2e 100644
46645--- a/drivers/misc/sgi-gru/gruprocfs.c
46646+++ b/drivers/misc/sgi-gru/gruprocfs.c
46647@@ -32,9 +32,9 @@
46648
46649 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
46650
46651-static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
46652+static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
46653 {
46654- unsigned long val = atomic_long_read(v);
46655+ unsigned long val = atomic_long_read_unchecked(v);
46656
46657 seq_printf(s, "%16lu %s\n", val, id);
46658 }
46659@@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
46660
46661 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
46662 for (op = 0; op < mcsop_last; op++) {
46663- count = atomic_long_read(&mcs_op_statistics[op].count);
46664- total = atomic_long_read(&mcs_op_statistics[op].total);
46665+ count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
46666+ total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
46667 max = mcs_op_statistics[op].max;
46668 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
46669 count ? total / count : 0, max);
46670diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
46671index 5c3ce24..4915ccb 100644
46672--- a/drivers/misc/sgi-gru/grutables.h
46673+++ b/drivers/misc/sgi-gru/grutables.h
46674@@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
46675 * GRU statistics.
46676 */
46677 struct gru_stats_s {
46678- atomic_long_t vdata_alloc;
46679- atomic_long_t vdata_free;
46680- atomic_long_t gts_alloc;
46681- atomic_long_t gts_free;
46682- atomic_long_t gms_alloc;
46683- atomic_long_t gms_free;
46684- atomic_long_t gts_double_allocate;
46685- atomic_long_t assign_context;
46686- atomic_long_t assign_context_failed;
46687- atomic_long_t free_context;
46688- atomic_long_t load_user_context;
46689- atomic_long_t load_kernel_context;
46690- atomic_long_t lock_kernel_context;
46691- atomic_long_t unlock_kernel_context;
46692- atomic_long_t steal_user_context;
46693- atomic_long_t steal_kernel_context;
46694- atomic_long_t steal_context_failed;
46695- atomic_long_t nopfn;
46696- atomic_long_t asid_new;
46697- atomic_long_t asid_next;
46698- atomic_long_t asid_wrap;
46699- atomic_long_t asid_reuse;
46700- atomic_long_t intr;
46701- atomic_long_t intr_cbr;
46702- atomic_long_t intr_tfh;
46703- atomic_long_t intr_spurious;
46704- atomic_long_t intr_mm_lock_failed;
46705- atomic_long_t call_os;
46706- atomic_long_t call_os_wait_queue;
46707- atomic_long_t user_flush_tlb;
46708- atomic_long_t user_unload_context;
46709- atomic_long_t user_exception;
46710- atomic_long_t set_context_option;
46711- atomic_long_t check_context_retarget_intr;
46712- atomic_long_t check_context_unload;
46713- atomic_long_t tlb_dropin;
46714- atomic_long_t tlb_preload_page;
46715- atomic_long_t tlb_dropin_fail_no_asid;
46716- atomic_long_t tlb_dropin_fail_upm;
46717- atomic_long_t tlb_dropin_fail_invalid;
46718- atomic_long_t tlb_dropin_fail_range_active;
46719- atomic_long_t tlb_dropin_fail_idle;
46720- atomic_long_t tlb_dropin_fail_fmm;
46721- atomic_long_t tlb_dropin_fail_no_exception;
46722- atomic_long_t tfh_stale_on_fault;
46723- atomic_long_t mmu_invalidate_range;
46724- atomic_long_t mmu_invalidate_page;
46725- atomic_long_t flush_tlb;
46726- atomic_long_t flush_tlb_gru;
46727- atomic_long_t flush_tlb_gru_tgh;
46728- atomic_long_t flush_tlb_gru_zero_asid;
46729+ atomic_long_unchecked_t vdata_alloc;
46730+ atomic_long_unchecked_t vdata_free;
46731+ atomic_long_unchecked_t gts_alloc;
46732+ atomic_long_unchecked_t gts_free;
46733+ atomic_long_unchecked_t gms_alloc;
46734+ atomic_long_unchecked_t gms_free;
46735+ atomic_long_unchecked_t gts_double_allocate;
46736+ atomic_long_unchecked_t assign_context;
46737+ atomic_long_unchecked_t assign_context_failed;
46738+ atomic_long_unchecked_t free_context;
46739+ atomic_long_unchecked_t load_user_context;
46740+ atomic_long_unchecked_t load_kernel_context;
46741+ atomic_long_unchecked_t lock_kernel_context;
46742+ atomic_long_unchecked_t unlock_kernel_context;
46743+ atomic_long_unchecked_t steal_user_context;
46744+ atomic_long_unchecked_t steal_kernel_context;
46745+ atomic_long_unchecked_t steal_context_failed;
46746+ atomic_long_unchecked_t nopfn;
46747+ atomic_long_unchecked_t asid_new;
46748+ atomic_long_unchecked_t asid_next;
46749+ atomic_long_unchecked_t asid_wrap;
46750+ atomic_long_unchecked_t asid_reuse;
46751+ atomic_long_unchecked_t intr;
46752+ atomic_long_unchecked_t intr_cbr;
46753+ atomic_long_unchecked_t intr_tfh;
46754+ atomic_long_unchecked_t intr_spurious;
46755+ atomic_long_unchecked_t intr_mm_lock_failed;
46756+ atomic_long_unchecked_t call_os;
46757+ atomic_long_unchecked_t call_os_wait_queue;
46758+ atomic_long_unchecked_t user_flush_tlb;
46759+ atomic_long_unchecked_t user_unload_context;
46760+ atomic_long_unchecked_t user_exception;
46761+ atomic_long_unchecked_t set_context_option;
46762+ atomic_long_unchecked_t check_context_retarget_intr;
46763+ atomic_long_unchecked_t check_context_unload;
46764+ atomic_long_unchecked_t tlb_dropin;
46765+ atomic_long_unchecked_t tlb_preload_page;
46766+ atomic_long_unchecked_t tlb_dropin_fail_no_asid;
46767+ atomic_long_unchecked_t tlb_dropin_fail_upm;
46768+ atomic_long_unchecked_t tlb_dropin_fail_invalid;
46769+ atomic_long_unchecked_t tlb_dropin_fail_range_active;
46770+ atomic_long_unchecked_t tlb_dropin_fail_idle;
46771+ atomic_long_unchecked_t tlb_dropin_fail_fmm;
46772+ atomic_long_unchecked_t tlb_dropin_fail_no_exception;
46773+ atomic_long_unchecked_t tfh_stale_on_fault;
46774+ atomic_long_unchecked_t mmu_invalidate_range;
46775+ atomic_long_unchecked_t mmu_invalidate_page;
46776+ atomic_long_unchecked_t flush_tlb;
46777+ atomic_long_unchecked_t flush_tlb_gru;
46778+ atomic_long_unchecked_t flush_tlb_gru_tgh;
46779+ atomic_long_unchecked_t flush_tlb_gru_zero_asid;
46780
46781- atomic_long_t copy_gpa;
46782- atomic_long_t read_gpa;
46783+ atomic_long_unchecked_t copy_gpa;
46784+ atomic_long_unchecked_t read_gpa;
46785
46786- atomic_long_t mesq_receive;
46787- atomic_long_t mesq_receive_none;
46788- atomic_long_t mesq_send;
46789- atomic_long_t mesq_send_failed;
46790- atomic_long_t mesq_noop;
46791- atomic_long_t mesq_send_unexpected_error;
46792- atomic_long_t mesq_send_lb_overflow;
46793- atomic_long_t mesq_send_qlimit_reached;
46794- atomic_long_t mesq_send_amo_nacked;
46795- atomic_long_t mesq_send_put_nacked;
46796- atomic_long_t mesq_page_overflow;
46797- atomic_long_t mesq_qf_locked;
46798- atomic_long_t mesq_qf_noop_not_full;
46799- atomic_long_t mesq_qf_switch_head_failed;
46800- atomic_long_t mesq_qf_unexpected_error;
46801- atomic_long_t mesq_noop_unexpected_error;
46802- atomic_long_t mesq_noop_lb_overflow;
46803- atomic_long_t mesq_noop_qlimit_reached;
46804- atomic_long_t mesq_noop_amo_nacked;
46805- atomic_long_t mesq_noop_put_nacked;
46806- atomic_long_t mesq_noop_page_overflow;
46807+ atomic_long_unchecked_t mesq_receive;
46808+ atomic_long_unchecked_t mesq_receive_none;
46809+ atomic_long_unchecked_t mesq_send;
46810+ atomic_long_unchecked_t mesq_send_failed;
46811+ atomic_long_unchecked_t mesq_noop;
46812+ atomic_long_unchecked_t mesq_send_unexpected_error;
46813+ atomic_long_unchecked_t mesq_send_lb_overflow;
46814+ atomic_long_unchecked_t mesq_send_qlimit_reached;
46815+ atomic_long_unchecked_t mesq_send_amo_nacked;
46816+ atomic_long_unchecked_t mesq_send_put_nacked;
46817+ atomic_long_unchecked_t mesq_page_overflow;
46818+ atomic_long_unchecked_t mesq_qf_locked;
46819+ atomic_long_unchecked_t mesq_qf_noop_not_full;
46820+ atomic_long_unchecked_t mesq_qf_switch_head_failed;
46821+ atomic_long_unchecked_t mesq_qf_unexpected_error;
46822+ atomic_long_unchecked_t mesq_noop_unexpected_error;
46823+ atomic_long_unchecked_t mesq_noop_lb_overflow;
46824+ atomic_long_unchecked_t mesq_noop_qlimit_reached;
46825+ atomic_long_unchecked_t mesq_noop_amo_nacked;
46826+ atomic_long_unchecked_t mesq_noop_put_nacked;
46827+ atomic_long_unchecked_t mesq_noop_page_overflow;
46828
46829 };
46830
46831@@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
46832 tghop_invalidate, mcsop_last};
46833
46834 struct mcs_op_statistic {
46835- atomic_long_t count;
46836- atomic_long_t total;
46837+ atomic_long_unchecked_t count;
46838+ atomic_long_unchecked_t total;
46839 unsigned long max;
46840 };
46841
46842@@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
46843
46844 #define STAT(id) do { \
46845 if (gru_options & OPT_STATS) \
46846- atomic_long_inc(&gru_stats.id); \
46847+ atomic_long_inc_unchecked(&gru_stats.id); \
46848 } while (0)
46849
46850 #ifdef CONFIG_SGI_GRU_DEBUG
46851diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
46852index c862cd4..0d176fe 100644
46853--- a/drivers/misc/sgi-xp/xp.h
46854+++ b/drivers/misc/sgi-xp/xp.h
46855@@ -288,7 +288,7 @@ struct xpc_interface {
46856 xpc_notify_func, void *);
46857 void (*received) (short, int, void *);
46858 enum xp_retval (*partid_to_nasids) (short, void *);
46859-};
46860+} __no_const;
46861
46862 extern struct xpc_interface xpc_interface;
46863
46864diff --git a/drivers/misc/sgi-xp/xp_main.c b/drivers/misc/sgi-xp/xp_main.c
46865index 01be66d..e3a0c7e 100644
46866--- a/drivers/misc/sgi-xp/xp_main.c
46867+++ b/drivers/misc/sgi-xp/xp_main.c
46868@@ -78,13 +78,13 @@ xpc_notloaded(void)
46869 }
46870
46871 struct xpc_interface xpc_interface = {
46872- (void (*)(int))xpc_notloaded,
46873- (void (*)(int))xpc_notloaded,
46874- (enum xp_retval(*)(short, int, u32, void *, u16))xpc_notloaded,
46875- (enum xp_retval(*)(short, int, u32, void *, u16, xpc_notify_func,
46876+ .connect = (void (*)(int))xpc_notloaded,
46877+ .disconnect = (void (*)(int))xpc_notloaded,
46878+ .send = (enum xp_retval(*)(short, int, u32, void *, u16))xpc_notloaded,
46879+ .send_notify = (enum xp_retval(*)(short, int, u32, void *, u16, xpc_notify_func,
46880 void *))xpc_notloaded,
46881- (void (*)(short, int, void *))xpc_notloaded,
46882- (enum xp_retval(*)(short, void *))xpc_notloaded
46883+ .received = (void (*)(short, int, void *))xpc_notloaded,
46884+ .partid_to_nasids = (enum xp_retval(*)(short, void *))xpc_notloaded
46885 };
46886 EXPORT_SYMBOL_GPL(xpc_interface);
46887
46888diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
46889index b94d5f7..7f494c5 100644
46890--- a/drivers/misc/sgi-xp/xpc.h
46891+++ b/drivers/misc/sgi-xp/xpc.h
46892@@ -835,6 +835,7 @@ struct xpc_arch_operations {
46893 void (*received_payload) (struct xpc_channel *, void *);
46894 void (*notify_senders_of_disconnect) (struct xpc_channel *);
46895 };
46896+typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
46897
46898 /* struct xpc_partition act_state values (for XPC HB) */
46899
46900@@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
46901 /* found in xpc_main.c */
46902 extern struct device *xpc_part;
46903 extern struct device *xpc_chan;
46904-extern struct xpc_arch_operations xpc_arch_ops;
46905+extern xpc_arch_operations_no_const xpc_arch_ops;
46906 extern int xpc_disengage_timelimit;
46907 extern int xpc_disengage_timedout;
46908 extern int xpc_activate_IRQ_rcvd;
46909diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
46910index 82dc574..8539ab2 100644
46911--- a/drivers/misc/sgi-xp/xpc_main.c
46912+++ b/drivers/misc/sgi-xp/xpc_main.c
46913@@ -166,7 +166,7 @@ static struct notifier_block xpc_die_notifier = {
46914 .notifier_call = xpc_system_die,
46915 };
46916
46917-struct xpc_arch_operations xpc_arch_ops;
46918+xpc_arch_operations_no_const xpc_arch_ops;
46919
46920 /*
46921 * Timer function to enforce the timelimit on the partition disengage.
46922@@ -1210,7 +1210,7 @@ xpc_system_die(struct notifier_block *nb, unsigned long event, void *_die_args)
46923
46924 if (((die_args->trapnr == X86_TRAP_MF) ||
46925 (die_args->trapnr == X86_TRAP_XF)) &&
46926- !user_mode_vm(die_args->regs))
46927+ !user_mode(die_args->regs))
46928 xpc_die_deactivate();
46929
46930 break;
46931diff --git a/drivers/mmc/card/block.c b/drivers/mmc/card/block.c
46932index a11451f..9e1bbad 100644
46933--- a/drivers/mmc/card/block.c
46934+++ b/drivers/mmc/card/block.c
46935@@ -574,7 +574,7 @@ static int mmc_blk_ioctl_cmd(struct block_device *bdev,
46936 if (idata->ic.postsleep_min_us)
46937 usleep_range(idata->ic.postsleep_min_us, idata->ic.postsleep_max_us);
46938
46939- if (copy_to_user(&(ic_ptr->response), cmd.resp, sizeof(cmd.resp))) {
46940+ if (copy_to_user(ic_ptr->response, cmd.resp, sizeof(cmd.resp))) {
46941 err = -EFAULT;
46942 goto cmd_rel_host;
46943 }
46944diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c
46945index 7911e05..d0f9dda 100644
46946--- a/drivers/mmc/core/mmc_ops.c
46947+++ b/drivers/mmc/core/mmc_ops.c
46948@@ -267,7 +267,7 @@ mmc_send_cxd_data(struct mmc_card *card, struct mmc_host *host,
46949 void *data_buf;
46950 int is_on_stack;
46951
46952- is_on_stack = object_is_on_stack(buf);
46953+ is_on_stack = object_starts_on_stack(buf);
46954 if (is_on_stack) {
46955 /*
46956 * dma onto stack is unsafe/nonportable, but callers to this
46957diff --git a/drivers/mmc/host/dw_mmc.h b/drivers/mmc/host/dw_mmc.h
46958index 01b99e8..5c325e3 100644
46959--- a/drivers/mmc/host/dw_mmc.h
46960+++ b/drivers/mmc/host/dw_mmc.h
46961@@ -265,5 +265,5 @@ struct dw_mci_drv_data {
46962 int (*parse_dt)(struct dw_mci *host);
46963 int (*execute_tuning)(struct dw_mci_slot *slot, u32 opcode,
46964 struct dw_mci_tuning_data *tuning_data);
46965-};
46966+} __do_const;
46967 #endif /* _DW_MMC_H_ */
46968diff --git a/drivers/mmc/host/mmci.c b/drivers/mmc/host/mmci.c
46969index 43af791..86f4c48 100644
46970--- a/drivers/mmc/host/mmci.c
46971+++ b/drivers/mmc/host/mmci.c
46972@@ -1628,7 +1628,9 @@ static int mmci_probe(struct amba_device *dev,
46973 mmc->caps |= MMC_CAP_CMD23;
46974
46975 if (variant->busy_detect) {
46976- mmci_ops.card_busy = mmci_card_busy;
46977+ pax_open_kernel();
46978+ *(void **)&mmci_ops.card_busy = mmci_card_busy;
46979+ pax_close_kernel();
46980 mmci_write_datactrlreg(host, MCI_ST_DPSM_BUSYMODE);
46981 mmc->caps |= MMC_CAP_WAIT_WHILE_BUSY;
46982 mmc->max_busy_timeout = 0;
46983diff --git a/drivers/mmc/host/omap_hsmmc.c b/drivers/mmc/host/omap_hsmmc.c
46984index 9c2b9cb..cebb09a 100644
46985--- a/drivers/mmc/host/omap_hsmmc.c
46986+++ b/drivers/mmc/host/omap_hsmmc.c
46987@@ -2113,7 +2113,9 @@ static int omap_hsmmc_probe(struct platform_device *pdev)
46988
46989 if (host->pdata->controller_flags & OMAP_HSMMC_BROKEN_MULTIBLOCK_READ) {
46990 dev_info(&pdev->dev, "multiblock reads disabled due to 35xx erratum 2.1.1.128; MMC read performance may suffer\n");
46991- omap_hsmmc_ops.multi_io_quirk = omap_hsmmc_multi_io_quirk;
46992+ pax_open_kernel();
46993+ *(void **)&omap_hsmmc_ops.multi_io_quirk = omap_hsmmc_multi_io_quirk;
46994+ pax_close_kernel();
46995 }
46996
46997 pm_runtime_enable(host->dev);
46998diff --git a/drivers/mmc/host/sdhci-esdhc-imx.c b/drivers/mmc/host/sdhci-esdhc-imx.c
46999index 587ee0e..b3bbcab 100644
47000--- a/drivers/mmc/host/sdhci-esdhc-imx.c
47001+++ b/drivers/mmc/host/sdhci-esdhc-imx.c
47002@@ -1054,9 +1054,12 @@ static int sdhci_esdhc_imx_probe(struct platform_device *pdev)
47003 host->mmc->caps |= MMC_CAP_1_8V_DDR;
47004 }
47005
47006- if (imx_data->socdata->flags & ESDHC_FLAG_MAN_TUNING)
47007- sdhci_esdhc_ops.platform_execute_tuning =
47008+ if (imx_data->socdata->flags & ESDHC_FLAG_MAN_TUNING) {
47009+ pax_open_kernel();
47010+ *(void **)&sdhci_esdhc_ops.platform_execute_tuning =
47011 esdhc_executing_tuning;
47012+ pax_close_kernel();
47013+ }
47014
47015 if (imx_data->socdata->flags & ESDHC_FLAG_STD_TUNING)
47016 writel(readl(host->ioaddr + ESDHC_TUNING_CTRL) |
47017diff --git a/drivers/mmc/host/sdhci-s3c.c b/drivers/mmc/host/sdhci-s3c.c
47018index 0ce6eb1..8dcce1b 100644
47019--- a/drivers/mmc/host/sdhci-s3c.c
47020+++ b/drivers/mmc/host/sdhci-s3c.c
47021@@ -584,9 +584,11 @@ static int sdhci_s3c_probe(struct platform_device *pdev)
47022 * we can use overriding functions instead of default.
47023 */
47024 if (sc->no_divider) {
47025- sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
47026- sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
47027- sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
47028+ pax_open_kernel();
47029+ *(void **)&sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
47030+ *(void **)&sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
47031+ *(void **)&sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
47032+ pax_close_kernel();
47033 }
47034
47035 /* It supports additional host capabilities if needed */
47036diff --git a/drivers/mtd/chips/cfi_cmdset_0020.c b/drivers/mtd/chips/cfi_cmdset_0020.c
47037index 423666b..81ff5eb 100644
47038--- a/drivers/mtd/chips/cfi_cmdset_0020.c
47039+++ b/drivers/mtd/chips/cfi_cmdset_0020.c
47040@@ -666,7 +666,7 @@ cfi_staa_writev(struct mtd_info *mtd, const struct kvec *vecs,
47041 size_t totlen = 0, thislen;
47042 int ret = 0;
47043 size_t buflen = 0;
47044- static char *buffer;
47045+ char *buffer;
47046
47047 if (!ECCBUF_SIZE) {
47048 /* We should fall back to a general writev implementation.
47049diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
47050index b3b7ca1..5dd4634 100644
47051--- a/drivers/mtd/nand/denali.c
47052+++ b/drivers/mtd/nand/denali.c
47053@@ -24,6 +24,7 @@
47054 #include <linux/slab.h>
47055 #include <linux/mtd/mtd.h>
47056 #include <linux/module.h>
47057+#include <linux/slab.h>
47058
47059 #include "denali.h"
47060
47061diff --git a/drivers/mtd/nand/gpmi-nand/gpmi-nand.c b/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
47062index 959cb9b..8520fe5 100644
47063--- a/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
47064+++ b/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
47065@@ -386,7 +386,7 @@ void prepare_data_dma(struct gpmi_nand_data *this, enum dma_data_direction dr)
47066
47067 /* first try to map the upper buffer directly */
47068 if (virt_addr_valid(this->upper_buf) &&
47069- !object_is_on_stack(this->upper_buf)) {
47070+ !object_starts_on_stack(this->upper_buf)) {
47071 sg_init_one(sgl, this->upper_buf, this->upper_len);
47072 ret = dma_map_sg(this->dev, sgl, 1, dr);
47073 if (ret == 0)
47074diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
47075index 51b9d6a..52af9a7 100644
47076--- a/drivers/mtd/nftlmount.c
47077+++ b/drivers/mtd/nftlmount.c
47078@@ -24,6 +24,7 @@
47079 #include <asm/errno.h>
47080 #include <linux/delay.h>
47081 #include <linux/slab.h>
47082+#include <linux/sched.h>
47083 #include <linux/mtd/mtd.h>
47084 #include <linux/mtd/nand.h>
47085 #include <linux/mtd/nftl.h>
47086diff --git a/drivers/mtd/sm_ftl.c b/drivers/mtd/sm_ftl.c
47087index c23184a..4115c41 100644
47088--- a/drivers/mtd/sm_ftl.c
47089+++ b/drivers/mtd/sm_ftl.c
47090@@ -56,7 +56,7 @@ static ssize_t sm_attr_show(struct device *dev, struct device_attribute *attr,
47091 #define SM_CIS_VENDOR_OFFSET 0x59
47092 static struct attribute_group *sm_create_sysfs_attributes(struct sm_ftl *ftl)
47093 {
47094- struct attribute_group *attr_group;
47095+ attribute_group_no_const *attr_group;
47096 struct attribute **attributes;
47097 struct sm_sysfs_attribute *vendor_attribute;
47098 char *vendor;
47099diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
47100index a5115fb..81b03f6 100644
47101--- a/drivers/net/bonding/bond_main.c
47102+++ b/drivers/net/bonding/bond_main.c
47103@@ -3749,7 +3749,7 @@ int bond_3ad_xor_xmit(struct sk_buff *skb, struct net_device *dev)
47104 bond_dev_queue_xmit(bond, skb, slave->dev);
47105 } else {
47106 dev_kfree_skb_any(skb);
47107- atomic_long_inc(&dev->tx_dropped);
47108+ atomic_long_inc_unchecked(&dev->tx_dropped);
47109 }
47110
47111 return NETDEV_TX_OK;
47112diff --git a/drivers/net/bonding/bond_netlink.c b/drivers/net/bonding/bond_netlink.c
47113index 45f09a6..f154f8d 100644
47114--- a/drivers/net/bonding/bond_netlink.c
47115+++ b/drivers/net/bonding/bond_netlink.c
47116@@ -585,7 +585,7 @@ nla_put_failure:
47117 return -EMSGSIZE;
47118 }
47119
47120-struct rtnl_link_ops bond_link_ops __read_mostly = {
47121+struct rtnl_link_ops bond_link_ops = {
47122 .kind = "bond",
47123 .priv_size = sizeof(struct bonding),
47124 .setup = bond_setup,
47125diff --git a/drivers/net/caif/caif_hsi.c b/drivers/net/caif/caif_hsi.c
47126index 5e40a8b..126bfda 100644
47127--- a/drivers/net/caif/caif_hsi.c
47128+++ b/drivers/net/caif/caif_hsi.c
47129@@ -1445,7 +1445,7 @@ err:
47130 return -ENODEV;
47131 }
47132
47133-static struct rtnl_link_ops caif_hsi_link_ops __read_mostly = {
47134+static struct rtnl_link_ops caif_hsi_link_ops = {
47135 .kind = "cfhsi",
47136 .priv_size = sizeof(struct cfhsi),
47137 .setup = cfhsi_setup,
47138diff --git a/drivers/net/can/Kconfig b/drivers/net/can/Kconfig
47139index 98d73aa..63ef9da 100644
47140--- a/drivers/net/can/Kconfig
47141+++ b/drivers/net/can/Kconfig
47142@@ -98,7 +98,7 @@ config CAN_JANZ_ICAN3
47143
47144 config CAN_FLEXCAN
47145 tristate "Support for Freescale FLEXCAN based chips"
47146- depends on ARM || PPC
47147+ depends on (ARM && CPU_LITTLE_ENDIAN) || PPC
47148 ---help---
47149 Say Y here if you want to support for Freescale FlexCAN.
47150
47151diff --git a/drivers/net/can/dev.c b/drivers/net/can/dev.c
47152index 2cfe501..477d4b5 100644
47153--- a/drivers/net/can/dev.c
47154+++ b/drivers/net/can/dev.c
47155@@ -868,7 +868,7 @@ static int can_newlink(struct net *src_net, struct net_device *dev,
47156 return -EOPNOTSUPP;
47157 }
47158
47159-static struct rtnl_link_ops can_link_ops __read_mostly = {
47160+static struct rtnl_link_ops can_link_ops = {
47161 .kind = "can",
47162 .maxtype = IFLA_CAN_MAX,
47163 .policy = can_policy,
47164diff --git a/drivers/net/can/vcan.c b/drivers/net/can/vcan.c
47165index 4e94057..32032ff 100644
47166--- a/drivers/net/can/vcan.c
47167+++ b/drivers/net/can/vcan.c
47168@@ -166,7 +166,7 @@ static void vcan_setup(struct net_device *dev)
47169 dev->destructor = free_netdev;
47170 }
47171
47172-static struct rtnl_link_ops vcan_link_ops __read_mostly = {
47173+static struct rtnl_link_ops vcan_link_ops = {
47174 .kind = "vcan",
47175 .setup = vcan_setup,
47176 };
47177diff --git a/drivers/net/dummy.c b/drivers/net/dummy.c
47178index ff435fb..d408b1f 100644
47179--- a/drivers/net/dummy.c
47180+++ b/drivers/net/dummy.c
47181@@ -149,7 +149,7 @@ static int dummy_validate(struct nlattr *tb[], struct nlattr *data[])
47182 return 0;
47183 }
47184
47185-static struct rtnl_link_ops dummy_link_ops __read_mostly = {
47186+static struct rtnl_link_ops dummy_link_ops = {
47187 .kind = "dummy",
47188 .setup = dummy_setup,
47189 .validate = dummy_validate,
47190diff --git a/drivers/net/ethernet/8390/ax88796.c b/drivers/net/ethernet/8390/ax88796.c
47191index 1d162cc..b546a75 100644
47192--- a/drivers/net/ethernet/8390/ax88796.c
47193+++ b/drivers/net/ethernet/8390/ax88796.c
47194@@ -889,9 +889,11 @@ static int ax_probe(struct platform_device *pdev)
47195 if (ax->plat->reg_offsets)
47196 ei_local->reg_offset = ax->plat->reg_offsets;
47197 else {
47198+ resource_size_t _mem_size = mem_size;
47199+ do_div(_mem_size, 0x18);
47200 ei_local->reg_offset = ax->reg_offsets;
47201 for (ret = 0; ret < 0x18; ret++)
47202- ax->reg_offsets[ret] = (mem_size / 0x18) * ret;
47203+ ax->reg_offsets[ret] = _mem_size * ret;
47204 }
47205
47206 if (!request_mem_region(mem->start, mem_size, pdev->name)) {
47207diff --git a/drivers/net/ethernet/altera/altera_tse_main.c b/drivers/net/ethernet/altera/altera_tse_main.c
47208index 4efc435..4ab9e14 100644
47209--- a/drivers/net/ethernet/altera/altera_tse_main.c
47210+++ b/drivers/net/ethernet/altera/altera_tse_main.c
47211@@ -1224,7 +1224,7 @@ static int tse_shutdown(struct net_device *dev)
47212 return 0;
47213 }
47214
47215-static struct net_device_ops altera_tse_netdev_ops = {
47216+static net_device_ops_no_const altera_tse_netdev_ops __read_only = {
47217 .ndo_open = tse_open,
47218 .ndo_stop = tse_shutdown,
47219 .ndo_start_xmit = tse_start_xmit,
47220@@ -1461,11 +1461,13 @@ static int altera_tse_probe(struct platform_device *pdev)
47221 ndev->netdev_ops = &altera_tse_netdev_ops;
47222 altera_tse_set_ethtool_ops(ndev);
47223
47224+ pax_open_kernel();
47225 altera_tse_netdev_ops.ndo_set_rx_mode = tse_set_rx_mode;
47226
47227 if (priv->hash_filter)
47228 altera_tse_netdev_ops.ndo_set_rx_mode =
47229 tse_set_rx_mode_hashfilter;
47230+ pax_close_kernel();
47231
47232 /* Scatter/gather IO is not supported,
47233 * so it is turned off
47234diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-common.h b/drivers/net/ethernet/amd/xgbe/xgbe-common.h
47235index caade30..3e257d9 100644
47236--- a/drivers/net/ethernet/amd/xgbe/xgbe-common.h
47237+++ b/drivers/net/ethernet/amd/xgbe/xgbe-common.h
47238@@ -1072,14 +1072,14 @@ do { \
47239 * operations, everything works on mask values.
47240 */
47241 #define XMDIO_READ(_pdata, _mmd, _reg) \
47242- ((_pdata)->hw_if.read_mmd_regs((_pdata), 0, \
47243+ ((_pdata)->hw_if->read_mmd_regs((_pdata), 0, \
47244 MII_ADDR_C45 | (_mmd << 16) | ((_reg) & 0xffff)))
47245
47246 #define XMDIO_READ_BITS(_pdata, _mmd, _reg, _mask) \
47247 (XMDIO_READ((_pdata), _mmd, _reg) & _mask)
47248
47249 #define XMDIO_WRITE(_pdata, _mmd, _reg, _val) \
47250- ((_pdata)->hw_if.write_mmd_regs((_pdata), 0, \
47251+ ((_pdata)->hw_if->write_mmd_regs((_pdata), 0, \
47252 MII_ADDR_C45 | (_mmd << 16) | ((_reg) & 0xffff), (_val)))
47253
47254 #define XMDIO_WRITE_BITS(_pdata, _mmd, _reg, _mask, _val) \
47255diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-dcb.c b/drivers/net/ethernet/amd/xgbe/xgbe-dcb.c
47256index 8a50b01..39c1ad0 100644
47257--- a/drivers/net/ethernet/amd/xgbe/xgbe-dcb.c
47258+++ b/drivers/net/ethernet/amd/xgbe/xgbe-dcb.c
47259@@ -187,7 +187,7 @@ static int xgbe_dcb_ieee_setets(struct net_device *netdev,
47260
47261 memcpy(pdata->ets, ets, sizeof(*pdata->ets));
47262
47263- pdata->hw_if.config_dcb_tc(pdata);
47264+ pdata->hw_if->config_dcb_tc(pdata);
47265
47266 return 0;
47267 }
47268@@ -226,7 +226,7 @@ static int xgbe_dcb_ieee_setpfc(struct net_device *netdev,
47269
47270 memcpy(pdata->pfc, pfc, sizeof(*pdata->pfc));
47271
47272- pdata->hw_if.config_dcb_pfc(pdata);
47273+ pdata->hw_if->config_dcb_pfc(pdata);
47274
47275 return 0;
47276 }
47277diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-desc.c b/drivers/net/ethernet/amd/xgbe/xgbe-desc.c
47278index 6fc5da0..61ac2cb 100644
47279--- a/drivers/net/ethernet/amd/xgbe/xgbe-desc.c
47280+++ b/drivers/net/ethernet/amd/xgbe/xgbe-desc.c
47281@@ -235,7 +235,7 @@ err_ring:
47282
47283 static void xgbe_wrapper_tx_descriptor_init(struct xgbe_prv_data *pdata)
47284 {
47285- struct xgbe_hw_if *hw_if = &pdata->hw_if;
47286+ struct xgbe_hw_if *hw_if = pdata->hw_if;
47287 struct xgbe_channel *channel;
47288 struct xgbe_ring *ring;
47289 struct xgbe_ring_data *rdata;
47290@@ -276,7 +276,7 @@ static void xgbe_wrapper_tx_descriptor_init(struct xgbe_prv_data *pdata)
47291
47292 static void xgbe_wrapper_rx_descriptor_init(struct xgbe_prv_data *pdata)
47293 {
47294- struct xgbe_hw_if *hw_if = &pdata->hw_if;
47295+ struct xgbe_hw_if *hw_if = pdata->hw_if;
47296 struct xgbe_channel *channel;
47297 struct xgbe_ring *ring;
47298 struct xgbe_ring_desc *rdesc;
47299@@ -505,7 +505,7 @@ err_out:
47300 static void xgbe_realloc_skb(struct xgbe_channel *channel)
47301 {
47302 struct xgbe_prv_data *pdata = channel->pdata;
47303- struct xgbe_hw_if *hw_if = &pdata->hw_if;
47304+ struct xgbe_hw_if *hw_if = pdata->hw_if;
47305 struct xgbe_ring *ring = channel->rx_ring;
47306 struct xgbe_ring_data *rdata;
47307 struct sk_buff *skb = NULL;
47308@@ -546,17 +546,12 @@ static void xgbe_realloc_skb(struct xgbe_channel *channel)
47309 DBGPR("<--xgbe_realloc_skb\n");
47310 }
47311
47312-void xgbe_init_function_ptrs_desc(struct xgbe_desc_if *desc_if)
47313-{
47314- DBGPR("-->xgbe_init_function_ptrs_desc\n");
47315-
47316- desc_if->alloc_ring_resources = xgbe_alloc_ring_resources;
47317- desc_if->free_ring_resources = xgbe_free_ring_resources;
47318- desc_if->map_tx_skb = xgbe_map_tx_skb;
47319- desc_if->realloc_skb = xgbe_realloc_skb;
47320- desc_if->unmap_skb = xgbe_unmap_skb;
47321- desc_if->wrapper_tx_desc_init = xgbe_wrapper_tx_descriptor_init;
47322- desc_if->wrapper_rx_desc_init = xgbe_wrapper_rx_descriptor_init;
47323-
47324- DBGPR("<--xgbe_init_function_ptrs_desc\n");
47325-}
47326+const struct xgbe_desc_if default_xgbe_desc_if = {
47327+ .alloc_ring_resources = xgbe_alloc_ring_resources,
47328+ .free_ring_resources = xgbe_free_ring_resources,
47329+ .map_tx_skb = xgbe_map_tx_skb,
47330+ .realloc_skb = xgbe_realloc_skb,
47331+ .unmap_skb = xgbe_unmap_skb,
47332+ .wrapper_tx_desc_init = xgbe_wrapper_tx_descriptor_init,
47333+ .wrapper_rx_desc_init = xgbe_wrapper_rx_descriptor_init,
47334+};
47335diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-dev.c b/drivers/net/ethernet/amd/xgbe/xgbe-dev.c
47336index 9da3a03..022f15c 100644
47337--- a/drivers/net/ethernet/amd/xgbe/xgbe-dev.c
47338+++ b/drivers/net/ethernet/amd/xgbe/xgbe-dev.c
47339@@ -2462,7 +2462,7 @@ static void xgbe_powerdown_rx(struct xgbe_prv_data *pdata)
47340
47341 static int xgbe_init(struct xgbe_prv_data *pdata)
47342 {
47343- struct xgbe_desc_if *desc_if = &pdata->desc_if;
47344+ struct xgbe_desc_if *desc_if = pdata->desc_if;
47345 int ret;
47346
47347 DBGPR("-->xgbe_init\n");
47348@@ -2524,101 +2524,96 @@ static int xgbe_init(struct xgbe_prv_data *pdata)
47349 return 0;
47350 }
47351
47352-void xgbe_init_function_ptrs_dev(struct xgbe_hw_if *hw_if)
47353-{
47354- DBGPR("-->xgbe_init_function_ptrs\n");
47355-
47356- hw_if->tx_complete = xgbe_tx_complete;
47357-
47358- hw_if->set_promiscuous_mode = xgbe_set_promiscuous_mode;
47359- hw_if->set_all_multicast_mode = xgbe_set_all_multicast_mode;
47360- hw_if->add_mac_addresses = xgbe_add_mac_addresses;
47361- hw_if->set_mac_address = xgbe_set_mac_address;
47362-
47363- hw_if->enable_rx_csum = xgbe_enable_rx_csum;
47364- hw_if->disable_rx_csum = xgbe_disable_rx_csum;
47365-
47366- hw_if->enable_rx_vlan_stripping = xgbe_enable_rx_vlan_stripping;
47367- hw_if->disable_rx_vlan_stripping = xgbe_disable_rx_vlan_stripping;
47368- hw_if->enable_rx_vlan_filtering = xgbe_enable_rx_vlan_filtering;
47369- hw_if->disable_rx_vlan_filtering = xgbe_disable_rx_vlan_filtering;
47370- hw_if->update_vlan_hash_table = xgbe_update_vlan_hash_table;
47371-
47372- hw_if->read_mmd_regs = xgbe_read_mmd_regs;
47373- hw_if->write_mmd_regs = xgbe_write_mmd_regs;
47374-
47375- hw_if->set_gmii_speed = xgbe_set_gmii_speed;
47376- hw_if->set_gmii_2500_speed = xgbe_set_gmii_2500_speed;
47377- hw_if->set_xgmii_speed = xgbe_set_xgmii_speed;
47378-
47379- hw_if->enable_tx = xgbe_enable_tx;
47380- hw_if->disable_tx = xgbe_disable_tx;
47381- hw_if->enable_rx = xgbe_enable_rx;
47382- hw_if->disable_rx = xgbe_disable_rx;
47383-
47384- hw_if->powerup_tx = xgbe_powerup_tx;
47385- hw_if->powerdown_tx = xgbe_powerdown_tx;
47386- hw_if->powerup_rx = xgbe_powerup_rx;
47387- hw_if->powerdown_rx = xgbe_powerdown_rx;
47388-
47389- hw_if->pre_xmit = xgbe_pre_xmit;
47390- hw_if->dev_read = xgbe_dev_read;
47391- hw_if->enable_int = xgbe_enable_int;
47392- hw_if->disable_int = xgbe_disable_int;
47393- hw_if->init = xgbe_init;
47394- hw_if->exit = xgbe_exit;
47395+const struct xgbe_hw_if default_xgbe_hw_if = {
47396+ .tx_complete = xgbe_tx_complete,
47397+
47398+ .set_promiscuous_mode = xgbe_set_promiscuous_mode,
47399+ .set_all_multicast_mode = xgbe_set_all_multicast_mode,
47400+ .add_mac_addresses = xgbe_add_mac_addresses,
47401+ .set_mac_address = xgbe_set_mac_address,
47402+
47403+ .enable_rx_csum = xgbe_enable_rx_csum,
47404+ .disable_rx_csum = xgbe_disable_rx_csum,
47405+
47406+ .enable_rx_vlan_stripping = xgbe_enable_rx_vlan_stripping,
47407+ .disable_rx_vlan_stripping = xgbe_disable_rx_vlan_stripping,
47408+ .enable_rx_vlan_filtering = xgbe_enable_rx_vlan_filtering,
47409+ .disable_rx_vlan_filtering = xgbe_disable_rx_vlan_filtering,
47410+ .update_vlan_hash_table = xgbe_update_vlan_hash_table,
47411+
47412+ .read_mmd_regs = xgbe_read_mmd_regs,
47413+ .write_mmd_regs = xgbe_write_mmd_regs,
47414+
47415+ .set_gmii_speed = xgbe_set_gmii_speed,
47416+ .set_gmii_2500_speed = xgbe_set_gmii_2500_speed,
47417+ .set_xgmii_speed = xgbe_set_xgmii_speed,
47418+
47419+ .enable_tx = xgbe_enable_tx,
47420+ .disable_tx = xgbe_disable_tx,
47421+ .enable_rx = xgbe_enable_rx,
47422+ .disable_rx = xgbe_disable_rx,
47423+
47424+ .powerup_tx = xgbe_powerup_tx,
47425+ .powerdown_tx = xgbe_powerdown_tx,
47426+ .powerup_rx = xgbe_powerup_rx,
47427+ .powerdown_rx = xgbe_powerdown_rx,
47428+
47429+ .pre_xmit = xgbe_pre_xmit,
47430+ .dev_read = xgbe_dev_read,
47431+ .enable_int = xgbe_enable_int,
47432+ .disable_int = xgbe_disable_int,
47433+ .init = xgbe_init,
47434+ .exit = xgbe_exit,
47435
47436 /* Descriptor related Sequences have to be initialized here */
47437- hw_if->tx_desc_init = xgbe_tx_desc_init;
47438- hw_if->rx_desc_init = xgbe_rx_desc_init;
47439- hw_if->tx_desc_reset = xgbe_tx_desc_reset;
47440- hw_if->rx_desc_reset = xgbe_rx_desc_reset;
47441- hw_if->is_last_desc = xgbe_is_last_desc;
47442- hw_if->is_context_desc = xgbe_is_context_desc;
47443+ .tx_desc_init = xgbe_tx_desc_init,
47444+ .rx_desc_init = xgbe_rx_desc_init,
47445+ .tx_desc_reset = xgbe_tx_desc_reset,
47446+ .rx_desc_reset = xgbe_rx_desc_reset,
47447+ .is_last_desc = xgbe_is_last_desc,
47448+ .is_context_desc = xgbe_is_context_desc,
47449
47450 /* For FLOW ctrl */
47451- hw_if->config_tx_flow_control = xgbe_config_tx_flow_control;
47452- hw_if->config_rx_flow_control = xgbe_config_rx_flow_control;
47453+ .config_tx_flow_control = xgbe_config_tx_flow_control,
47454+ .config_rx_flow_control = xgbe_config_rx_flow_control,
47455
47456 /* For RX coalescing */
47457- hw_if->config_rx_coalesce = xgbe_config_rx_coalesce;
47458- hw_if->config_tx_coalesce = xgbe_config_tx_coalesce;
47459- hw_if->usec_to_riwt = xgbe_usec_to_riwt;
47460- hw_if->riwt_to_usec = xgbe_riwt_to_usec;
47461+ .config_rx_coalesce = xgbe_config_rx_coalesce,
47462+ .config_tx_coalesce = xgbe_config_tx_coalesce,
47463+ .usec_to_riwt = xgbe_usec_to_riwt,
47464+ .riwt_to_usec = xgbe_riwt_to_usec,
47465
47466 /* For RX and TX threshold config */
47467- hw_if->config_rx_threshold = xgbe_config_rx_threshold;
47468- hw_if->config_tx_threshold = xgbe_config_tx_threshold;
47469+ .config_rx_threshold = xgbe_config_rx_threshold,
47470+ .config_tx_threshold = xgbe_config_tx_threshold,
47471
47472 /* For RX and TX Store and Forward Mode config */
47473- hw_if->config_rsf_mode = xgbe_config_rsf_mode;
47474- hw_if->config_tsf_mode = xgbe_config_tsf_mode;
47475+ .config_rsf_mode = xgbe_config_rsf_mode,
47476+ .config_tsf_mode = xgbe_config_tsf_mode,
47477
47478 /* For TX DMA Operating on Second Frame config */
47479- hw_if->config_osp_mode = xgbe_config_osp_mode;
47480+ .config_osp_mode = xgbe_config_osp_mode,
47481
47482 /* For RX and TX PBL config */
47483- hw_if->config_rx_pbl_val = xgbe_config_rx_pbl_val;
47484- hw_if->get_rx_pbl_val = xgbe_get_rx_pbl_val;
47485- hw_if->config_tx_pbl_val = xgbe_config_tx_pbl_val;
47486- hw_if->get_tx_pbl_val = xgbe_get_tx_pbl_val;
47487- hw_if->config_pblx8 = xgbe_config_pblx8;
47488+ .config_rx_pbl_val = xgbe_config_rx_pbl_val,
47489+ .get_rx_pbl_val = xgbe_get_rx_pbl_val,
47490+ .config_tx_pbl_val = xgbe_config_tx_pbl_val,
47491+ .get_tx_pbl_val = xgbe_get_tx_pbl_val,
47492+ .config_pblx8 = xgbe_config_pblx8,
47493
47494 /* For MMC statistics support */
47495- hw_if->tx_mmc_int = xgbe_tx_mmc_int;
47496- hw_if->rx_mmc_int = xgbe_rx_mmc_int;
47497- hw_if->read_mmc_stats = xgbe_read_mmc_stats;
47498+ .tx_mmc_int = xgbe_tx_mmc_int,
47499+ .rx_mmc_int = xgbe_rx_mmc_int,
47500+ .read_mmc_stats = xgbe_read_mmc_stats,
47501
47502 /* For PTP config */
47503- hw_if->config_tstamp = xgbe_config_tstamp;
47504- hw_if->update_tstamp_addend = xgbe_update_tstamp_addend;
47505- hw_if->set_tstamp_time = xgbe_set_tstamp_time;
47506- hw_if->get_tstamp_time = xgbe_get_tstamp_time;
47507- hw_if->get_tx_tstamp = xgbe_get_tx_tstamp;
47508+ .config_tstamp = xgbe_config_tstamp,
47509+ .update_tstamp_addend = xgbe_update_tstamp_addend,
47510+ .set_tstamp_time = xgbe_set_tstamp_time,
47511+ .get_tstamp_time = xgbe_get_tstamp_time,
47512+ .get_tx_tstamp = xgbe_get_tx_tstamp,
47513
47514 /* For Data Center Bridging config */
47515- hw_if->config_dcb_tc = xgbe_config_dcb_tc;
47516- hw_if->config_dcb_pfc = xgbe_config_dcb_pfc;
47517-
47518- DBGPR("<--xgbe_init_function_ptrs\n");
47519-}
47520+ .config_dcb_tc = xgbe_config_dcb_tc,
47521+ .config_dcb_pfc = xgbe_config_dcb_pfc,
47522+};
47523diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-drv.c b/drivers/net/ethernet/amd/xgbe/xgbe-drv.c
47524index 2349ea9..a83a677 100644
47525--- a/drivers/net/ethernet/amd/xgbe/xgbe-drv.c
47526+++ b/drivers/net/ethernet/amd/xgbe/xgbe-drv.c
47527@@ -154,7 +154,7 @@ static int xgbe_calc_rx_buf_size(struct net_device *netdev, unsigned int mtu)
47528
47529 static void xgbe_enable_rx_tx_ints(struct xgbe_prv_data *pdata)
47530 {
47531- struct xgbe_hw_if *hw_if = &pdata->hw_if;
47532+ struct xgbe_hw_if *hw_if = pdata->hw_if;
47533 struct xgbe_channel *channel;
47534 enum xgbe_int int_id;
47535 unsigned int i;
47536@@ -176,7 +176,7 @@ static void xgbe_enable_rx_tx_ints(struct xgbe_prv_data *pdata)
47537
47538 static void xgbe_disable_rx_tx_ints(struct xgbe_prv_data *pdata)
47539 {
47540- struct xgbe_hw_if *hw_if = &pdata->hw_if;
47541+ struct xgbe_hw_if *hw_if = pdata->hw_if;
47542 struct xgbe_channel *channel;
47543 enum xgbe_int int_id;
47544 unsigned int i;
47545@@ -199,7 +199,7 @@ static void xgbe_disable_rx_tx_ints(struct xgbe_prv_data *pdata)
47546 static irqreturn_t xgbe_isr(int irq, void *data)
47547 {
47548 struct xgbe_prv_data *pdata = data;
47549- struct xgbe_hw_if *hw_if = &pdata->hw_if;
47550+ struct xgbe_hw_if *hw_if = pdata->hw_if;
47551 struct xgbe_channel *channel;
47552 unsigned int dma_isr, dma_ch_isr;
47553 unsigned int mac_isr, mac_tssr;
47554@@ -446,7 +446,7 @@ static void xgbe_napi_disable(struct xgbe_prv_data *pdata, unsigned int del)
47555
47556 void xgbe_init_tx_coalesce(struct xgbe_prv_data *pdata)
47557 {
47558- struct xgbe_hw_if *hw_if = &pdata->hw_if;
47559+ struct xgbe_hw_if *hw_if = pdata->hw_if;
47560
47561 DBGPR("-->xgbe_init_tx_coalesce\n");
47562
47563@@ -460,7 +460,7 @@ void xgbe_init_tx_coalesce(struct xgbe_prv_data *pdata)
47564
47565 void xgbe_init_rx_coalesce(struct xgbe_prv_data *pdata)
47566 {
47567- struct xgbe_hw_if *hw_if = &pdata->hw_if;
47568+ struct xgbe_hw_if *hw_if = pdata->hw_if;
47569
47570 DBGPR("-->xgbe_init_rx_coalesce\n");
47571
47572@@ -474,7 +474,7 @@ void xgbe_init_rx_coalesce(struct xgbe_prv_data *pdata)
47573
47574 static void xgbe_free_tx_skbuff(struct xgbe_prv_data *pdata)
47575 {
47576- struct xgbe_desc_if *desc_if = &pdata->desc_if;
47577+ struct xgbe_desc_if *desc_if = pdata->desc_if;
47578 struct xgbe_channel *channel;
47579 struct xgbe_ring *ring;
47580 struct xgbe_ring_data *rdata;
47581@@ -499,7 +499,7 @@ static void xgbe_free_tx_skbuff(struct xgbe_prv_data *pdata)
47582
47583 static void xgbe_free_rx_skbuff(struct xgbe_prv_data *pdata)
47584 {
47585- struct xgbe_desc_if *desc_if = &pdata->desc_if;
47586+ struct xgbe_desc_if *desc_if = pdata->desc_if;
47587 struct xgbe_channel *channel;
47588 struct xgbe_ring *ring;
47589 struct xgbe_ring_data *rdata;
47590@@ -525,7 +525,7 @@ static void xgbe_free_rx_skbuff(struct xgbe_prv_data *pdata)
47591 static void xgbe_adjust_link(struct net_device *netdev)
47592 {
47593 struct xgbe_prv_data *pdata = netdev_priv(netdev);
47594- struct xgbe_hw_if *hw_if = &pdata->hw_if;
47595+ struct xgbe_hw_if *hw_if = pdata->hw_if;
47596 struct phy_device *phydev = pdata->phydev;
47597 int new_state = 0;
47598
47599@@ -633,7 +633,7 @@ static void xgbe_phy_exit(struct xgbe_prv_data *pdata)
47600 int xgbe_powerdown(struct net_device *netdev, unsigned int caller)
47601 {
47602 struct xgbe_prv_data *pdata = netdev_priv(netdev);
47603- struct xgbe_hw_if *hw_if = &pdata->hw_if;
47604+ struct xgbe_hw_if *hw_if = pdata->hw_if;
47605 unsigned long flags;
47606
47607 DBGPR("-->xgbe_powerdown\n");
47608@@ -671,7 +671,7 @@ int xgbe_powerdown(struct net_device *netdev, unsigned int caller)
47609 int xgbe_powerup(struct net_device *netdev, unsigned int caller)
47610 {
47611 struct xgbe_prv_data *pdata = netdev_priv(netdev);
47612- struct xgbe_hw_if *hw_if = &pdata->hw_if;
47613+ struct xgbe_hw_if *hw_if = pdata->hw_if;
47614 unsigned long flags;
47615
47616 DBGPR("-->xgbe_powerup\n");
47617@@ -708,7 +708,7 @@ int xgbe_powerup(struct net_device *netdev, unsigned int caller)
47618
47619 static int xgbe_start(struct xgbe_prv_data *pdata)
47620 {
47621- struct xgbe_hw_if *hw_if = &pdata->hw_if;
47622+ struct xgbe_hw_if *hw_if = pdata->hw_if;
47623 struct net_device *netdev = pdata->netdev;
47624
47625 DBGPR("-->xgbe_start\n");
47626@@ -734,7 +734,7 @@ static int xgbe_start(struct xgbe_prv_data *pdata)
47627
47628 static void xgbe_stop(struct xgbe_prv_data *pdata)
47629 {
47630- struct xgbe_hw_if *hw_if = &pdata->hw_if;
47631+ struct xgbe_hw_if *hw_if = pdata->hw_if;
47632 struct net_device *netdev = pdata->netdev;
47633
47634 DBGPR("-->xgbe_stop\n");
47635@@ -754,7 +754,7 @@ static void xgbe_stop(struct xgbe_prv_data *pdata)
47636
47637 static void xgbe_restart_dev(struct xgbe_prv_data *pdata, unsigned int reset)
47638 {
47639- struct xgbe_hw_if *hw_if = &pdata->hw_if;
47640+ struct xgbe_hw_if *hw_if = pdata->hw_if;
47641
47642 DBGPR("-->xgbe_restart_dev\n");
47643
47644@@ -951,7 +951,7 @@ static int xgbe_set_hwtstamp_settings(struct xgbe_prv_data *pdata,
47645 return -ERANGE;
47646 }
47647
47648- pdata->hw_if.config_tstamp(pdata, mac_tscr);
47649+ pdata->hw_if->config_tstamp(pdata, mac_tscr);
47650
47651 memcpy(&pdata->tstamp_config, &config, sizeof(config));
47652
47653@@ -1089,8 +1089,8 @@ static void xgbe_packet_info(struct xgbe_prv_data *pdata,
47654 static int xgbe_open(struct net_device *netdev)
47655 {
47656 struct xgbe_prv_data *pdata = netdev_priv(netdev);
47657- struct xgbe_hw_if *hw_if = &pdata->hw_if;
47658- struct xgbe_desc_if *desc_if = &pdata->desc_if;
47659+ struct xgbe_hw_if *hw_if = pdata->hw_if;
47660+ struct xgbe_desc_if *desc_if = pdata->desc_if;
47661 int ret;
47662
47663 DBGPR("-->xgbe_open\n");
47664@@ -1170,8 +1170,8 @@ err_phy_init:
47665 static int xgbe_close(struct net_device *netdev)
47666 {
47667 struct xgbe_prv_data *pdata = netdev_priv(netdev);
47668- struct xgbe_hw_if *hw_if = &pdata->hw_if;
47669- struct xgbe_desc_if *desc_if = &pdata->desc_if;
47670+ struct xgbe_hw_if *hw_if = pdata->hw_if;
47671+ struct xgbe_desc_if *desc_if = pdata->desc_if;
47672
47673 DBGPR("-->xgbe_close\n");
47674
47675@@ -1205,8 +1205,8 @@ static int xgbe_close(struct net_device *netdev)
47676 static int xgbe_xmit(struct sk_buff *skb, struct net_device *netdev)
47677 {
47678 struct xgbe_prv_data *pdata = netdev_priv(netdev);
47679- struct xgbe_hw_if *hw_if = &pdata->hw_if;
47680- struct xgbe_desc_if *desc_if = &pdata->desc_if;
47681+ struct xgbe_hw_if *hw_if = pdata->hw_if;
47682+ struct xgbe_desc_if *desc_if = pdata->desc_if;
47683 struct xgbe_channel *channel;
47684 struct xgbe_ring *ring;
47685 struct xgbe_packet_data *packet;
47686@@ -1275,7 +1275,7 @@ tx_netdev_return:
47687 static void xgbe_set_rx_mode(struct net_device *netdev)
47688 {
47689 struct xgbe_prv_data *pdata = netdev_priv(netdev);
47690- struct xgbe_hw_if *hw_if = &pdata->hw_if;
47691+ struct xgbe_hw_if *hw_if = pdata->hw_if;
47692 unsigned int pr_mode, am_mode;
47693
47694 DBGPR("-->xgbe_set_rx_mode\n");
47695@@ -1294,7 +1294,7 @@ static void xgbe_set_rx_mode(struct net_device *netdev)
47696 static int xgbe_set_mac_address(struct net_device *netdev, void *addr)
47697 {
47698 struct xgbe_prv_data *pdata = netdev_priv(netdev);
47699- struct xgbe_hw_if *hw_if = &pdata->hw_if;
47700+ struct xgbe_hw_if *hw_if = pdata->hw_if;
47701 struct sockaddr *saddr = addr;
47702
47703 DBGPR("-->xgbe_set_mac_address\n");
47704@@ -1361,7 +1361,7 @@ static struct rtnl_link_stats64 *xgbe_get_stats64(struct net_device *netdev,
47705
47706 DBGPR("-->%s\n", __func__);
47707
47708- pdata->hw_if.read_mmc_stats(pdata);
47709+ pdata->hw_if->read_mmc_stats(pdata);
47710
47711 s->rx_packets = pstats->rxframecount_gb;
47712 s->rx_bytes = pstats->rxoctetcount_gb;
47713@@ -1388,7 +1388,7 @@ static int xgbe_vlan_rx_add_vid(struct net_device *netdev, __be16 proto,
47714 u16 vid)
47715 {
47716 struct xgbe_prv_data *pdata = netdev_priv(netdev);
47717- struct xgbe_hw_if *hw_if = &pdata->hw_if;
47718+ struct xgbe_hw_if *hw_if = pdata->hw_if;
47719
47720 DBGPR("-->%s\n", __func__);
47721
47722@@ -1404,7 +1404,7 @@ static int xgbe_vlan_rx_kill_vid(struct net_device *netdev, __be16 proto,
47723 u16 vid)
47724 {
47725 struct xgbe_prv_data *pdata = netdev_priv(netdev);
47726- struct xgbe_hw_if *hw_if = &pdata->hw_if;
47727+ struct xgbe_hw_if *hw_if = pdata->hw_if;
47728
47729 DBGPR("-->%s\n", __func__);
47730
47731@@ -1464,7 +1464,7 @@ static int xgbe_set_features(struct net_device *netdev,
47732 netdev_features_t features)
47733 {
47734 struct xgbe_prv_data *pdata = netdev_priv(netdev);
47735- struct xgbe_hw_if *hw_if = &pdata->hw_if;
47736+ struct xgbe_hw_if *hw_if = pdata->hw_if;
47737 netdev_features_t rxcsum, rxvlan, rxvlan_filter;
47738
47739 rxcsum = pdata->netdev_features & NETIF_F_RXCSUM;
47740@@ -1520,7 +1520,7 @@ struct net_device_ops *xgbe_get_netdev_ops(void)
47741 static void xgbe_rx_refresh(struct xgbe_channel *channel)
47742 {
47743 struct xgbe_prv_data *pdata = channel->pdata;
47744- struct xgbe_desc_if *desc_if = &pdata->desc_if;
47745+ struct xgbe_desc_if *desc_if = pdata->desc_if;
47746 struct xgbe_ring *ring = channel->rx_ring;
47747 struct xgbe_ring_data *rdata;
47748
47749@@ -1536,8 +1536,8 @@ static void xgbe_rx_refresh(struct xgbe_channel *channel)
47750 static int xgbe_tx_poll(struct xgbe_channel *channel)
47751 {
47752 struct xgbe_prv_data *pdata = channel->pdata;
47753- struct xgbe_hw_if *hw_if = &pdata->hw_if;
47754- struct xgbe_desc_if *desc_if = &pdata->desc_if;
47755+ struct xgbe_hw_if *hw_if = pdata->hw_if;
47756+ struct xgbe_desc_if *desc_if = pdata->desc_if;
47757 struct xgbe_ring *ring = channel->tx_ring;
47758 struct xgbe_ring_data *rdata;
47759 struct xgbe_ring_desc *rdesc;
47760@@ -1589,7 +1589,7 @@ static int xgbe_tx_poll(struct xgbe_channel *channel)
47761 static int xgbe_rx_poll(struct xgbe_channel *channel, int budget)
47762 {
47763 struct xgbe_prv_data *pdata = channel->pdata;
47764- struct xgbe_hw_if *hw_if = &pdata->hw_if;
47765+ struct xgbe_hw_if *hw_if = pdata->hw_if;
47766 struct xgbe_ring *ring = channel->rx_ring;
47767 struct xgbe_ring_data *rdata;
47768 struct xgbe_packet_data *packet;
47769diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-ethtool.c b/drivers/net/ethernet/amd/xgbe/xgbe-ethtool.c
47770index 49508ec..2617cca 100644
47771--- a/drivers/net/ethernet/amd/xgbe/xgbe-ethtool.c
47772+++ b/drivers/net/ethernet/amd/xgbe/xgbe-ethtool.c
47773@@ -203,7 +203,7 @@ static void xgbe_get_ethtool_stats(struct net_device *netdev,
47774
47775 DBGPR("-->%s\n", __func__);
47776
47777- pdata->hw_if.read_mmc_stats(pdata);
47778+ pdata->hw_if->read_mmc_stats(pdata);
47779 for (i = 0; i < XGBE_STATS_COUNT; i++) {
47780 stat = (u8 *)pdata + xgbe_gstring_stats[i].stat_offset;
47781 *data++ = *(u64 *)stat;
47782@@ -378,7 +378,7 @@ static int xgbe_get_coalesce(struct net_device *netdev,
47783 struct ethtool_coalesce *ec)
47784 {
47785 struct xgbe_prv_data *pdata = netdev_priv(netdev);
47786- struct xgbe_hw_if *hw_if = &pdata->hw_if;
47787+ struct xgbe_hw_if *hw_if = pdata->hw_if;
47788 unsigned int riwt;
47789
47790 DBGPR("-->xgbe_get_coalesce\n");
47791@@ -401,7 +401,7 @@ static int xgbe_set_coalesce(struct net_device *netdev,
47792 struct ethtool_coalesce *ec)
47793 {
47794 struct xgbe_prv_data *pdata = netdev_priv(netdev);
47795- struct xgbe_hw_if *hw_if = &pdata->hw_if;
47796+ struct xgbe_hw_if *hw_if = pdata->hw_if;
47797 unsigned int rx_frames, rx_riwt, rx_usecs;
47798 unsigned int tx_frames, tx_usecs;
47799
47800diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-main.c b/drivers/net/ethernet/amd/xgbe/xgbe-main.c
47801index f5a8fa0..0bb58ff 100644
47802--- a/drivers/net/ethernet/amd/xgbe/xgbe-main.c
47803+++ b/drivers/net/ethernet/amd/xgbe/xgbe-main.c
47804@@ -209,12 +209,6 @@ static void xgbe_default_config(struct xgbe_prv_data *pdata)
47805 DBGPR("<--xgbe_default_config\n");
47806 }
47807
47808-static void xgbe_init_all_fptrs(struct xgbe_prv_data *pdata)
47809-{
47810- xgbe_init_function_ptrs_dev(&pdata->hw_if);
47811- xgbe_init_function_ptrs_desc(&pdata->desc_if);
47812-}
47813-
47814 static int xgbe_probe(struct platform_device *pdev)
47815 {
47816 struct xgbe_prv_data *pdata;
47817@@ -327,9 +321,8 @@ static int xgbe_probe(struct platform_device *pdev)
47818 netdev->base_addr = (unsigned long)pdata->xgmac_regs;
47819
47820 /* Set all the function pointers */
47821- xgbe_init_all_fptrs(pdata);
47822- hw_if = &pdata->hw_if;
47823- desc_if = &pdata->desc_if;
47824+ hw_if = pdata->hw_if = &default_xgbe_hw_if;
47825+ desc_if = pdata->desc_if = &default_xgbe_desc_if;
47826
47827 /* Issue software reset to device */
47828 hw_if->exit(pdata);
47829diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-mdio.c b/drivers/net/ethernet/amd/xgbe/xgbe-mdio.c
47830index 363b210..b241389 100644
47831--- a/drivers/net/ethernet/amd/xgbe/xgbe-mdio.c
47832+++ b/drivers/net/ethernet/amd/xgbe/xgbe-mdio.c
47833@@ -126,7 +126,7 @@
47834 static int xgbe_mdio_read(struct mii_bus *mii, int prtad, int mmd_reg)
47835 {
47836 struct xgbe_prv_data *pdata = mii->priv;
47837- struct xgbe_hw_if *hw_if = &pdata->hw_if;
47838+ struct xgbe_hw_if *hw_if = pdata->hw_if;
47839 int mmd_data;
47840
47841 DBGPR_MDIO("-->xgbe_mdio_read: prtad=%#x mmd_reg=%#x\n",
47842@@ -143,7 +143,7 @@ static int xgbe_mdio_write(struct mii_bus *mii, int prtad, int mmd_reg,
47843 u16 mmd_val)
47844 {
47845 struct xgbe_prv_data *pdata = mii->priv;
47846- struct xgbe_hw_if *hw_if = &pdata->hw_if;
47847+ struct xgbe_hw_if *hw_if = pdata->hw_if;
47848 int mmd_data = mmd_val;
47849
47850 DBGPR_MDIO("-->xgbe_mdio_write: prtad=%#x mmd_reg=%#x mmd_data=%#x\n",
47851diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-ptp.c b/drivers/net/ethernet/amd/xgbe/xgbe-ptp.c
47852index a1bf9d1c..84adcab 100644
47853--- a/drivers/net/ethernet/amd/xgbe/xgbe-ptp.c
47854+++ b/drivers/net/ethernet/amd/xgbe/xgbe-ptp.c
47855@@ -129,7 +129,7 @@ static cycle_t xgbe_cc_read(const struct cyclecounter *cc)
47856 tstamp_cc);
47857 u64 nsec;
47858
47859- nsec = pdata->hw_if.get_tstamp_time(pdata);
47860+ nsec = pdata->hw_if->get_tstamp_time(pdata);
47861
47862 return nsec;
47863 }
47864@@ -158,7 +158,7 @@ static int xgbe_adjfreq(struct ptp_clock_info *info, s32 delta)
47865
47866 spin_lock_irqsave(&pdata->tstamp_lock, flags);
47867
47868- pdata->hw_if.update_tstamp_addend(pdata, addend);
47869+ pdata->hw_if->update_tstamp_addend(pdata, addend);
47870
47871 spin_unlock_irqrestore(&pdata->tstamp_lock, flags);
47872
47873diff --git a/drivers/net/ethernet/amd/xgbe/xgbe.h b/drivers/net/ethernet/amd/xgbe/xgbe.h
47874index 789957d..d7d0245 100644
47875--- a/drivers/net/ethernet/amd/xgbe/xgbe.h
47876+++ b/drivers/net/ethernet/amd/xgbe/xgbe.h
47877@@ -583,8 +583,8 @@ struct xgbe_prv_data {
47878
47879 int irq_number;
47880
47881- struct xgbe_hw_if hw_if;
47882- struct xgbe_desc_if desc_if;
47883+ const struct xgbe_hw_if *hw_if;
47884+ const struct xgbe_desc_if *desc_if;
47885
47886 /* AXI DMA settings */
47887 unsigned int axdomain;
47888@@ -697,6 +697,9 @@ struct xgbe_prv_data {
47889 #endif
47890 };
47891
47892+extern const struct xgbe_hw_if default_xgbe_hw_if;
47893+extern const struct xgbe_desc_if default_xgbe_desc_if;
47894+
47895 /* Function prototypes*/
47896
47897 void xgbe_init_function_ptrs_dev(struct xgbe_hw_if *);
47898diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
47899index adcacda..fa6e0ae 100644
47900--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
47901+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
47902@@ -1065,7 +1065,7 @@ static inline u8 bnx2x_get_path_func_num(struct bnx2x *bp)
47903 static inline void bnx2x_init_bp_objs(struct bnx2x *bp)
47904 {
47905 /* RX_MODE controlling object */
47906- bnx2x_init_rx_mode_obj(bp, &bp->rx_mode_obj);
47907+ bnx2x_init_rx_mode_obj(bp);
47908
47909 /* multicast configuration controlling object */
47910 bnx2x_init_mcast_obj(bp, &bp->mcast_obj, bp->fp->cl_id, bp->fp->cid,
47911diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
47912index 7bc2924..2112002 100644
47913--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
47914+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
47915@@ -2329,15 +2329,14 @@ int bnx2x_config_rx_mode(struct bnx2x *bp,
47916 return rc;
47917 }
47918
47919-void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
47920- struct bnx2x_rx_mode_obj *o)
47921+void bnx2x_init_rx_mode_obj(struct bnx2x *bp)
47922 {
47923 if (CHIP_IS_E1x(bp)) {
47924- o->wait_comp = bnx2x_empty_rx_mode_wait;
47925- o->config_rx_mode = bnx2x_set_rx_mode_e1x;
47926+ bp->rx_mode_obj.wait_comp = bnx2x_empty_rx_mode_wait;
47927+ bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e1x;
47928 } else {
47929- o->wait_comp = bnx2x_wait_rx_mode_comp_e2;
47930- o->config_rx_mode = bnx2x_set_rx_mode_e2;
47931+ bp->rx_mode_obj.wait_comp = bnx2x_wait_rx_mode_comp_e2;
47932+ bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e2;
47933 }
47934 }
47935
47936diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
47937index e97275f..52e28bc 100644
47938--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
47939+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
47940@@ -1409,8 +1409,7 @@ int bnx2x_vlan_mac_move(struct bnx2x *bp,
47941
47942 /********************* RX MODE ****************/
47943
47944-void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
47945- struct bnx2x_rx_mode_obj *o);
47946+void bnx2x_init_rx_mode_obj(struct bnx2x *bp);
47947
47948 /**
47949 * bnx2x_config_rx_mode - Send and RX_MODE ramrod according to the provided parameters.
47950diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
47951index 31c9f82..e65e986 100644
47952--- a/drivers/net/ethernet/broadcom/tg3.h
47953+++ b/drivers/net/ethernet/broadcom/tg3.h
47954@@ -150,6 +150,7 @@
47955 #define CHIPREV_ID_5750_A0 0x4000
47956 #define CHIPREV_ID_5750_A1 0x4001
47957 #define CHIPREV_ID_5750_A3 0x4003
47958+#define CHIPREV_ID_5750_C1 0x4201
47959 #define CHIPREV_ID_5750_C2 0x4202
47960 #define CHIPREV_ID_5752_A0_HW 0x5000
47961 #define CHIPREV_ID_5752_A0 0x6000
47962diff --git a/drivers/net/ethernet/brocade/bna/bna_enet.c b/drivers/net/ethernet/brocade/bna/bna_enet.c
47963index 903466e..b285864 100644
47964--- a/drivers/net/ethernet/brocade/bna/bna_enet.c
47965+++ b/drivers/net/ethernet/brocade/bna/bna_enet.c
47966@@ -1693,10 +1693,10 @@ bna_cb_ioceth_reset(void *arg)
47967 }
47968
47969 static struct bfa_ioc_cbfn bna_ioceth_cbfn = {
47970- bna_cb_ioceth_enable,
47971- bna_cb_ioceth_disable,
47972- bna_cb_ioceth_hbfail,
47973- bna_cb_ioceth_reset
47974+ .enable_cbfn = bna_cb_ioceth_enable,
47975+ .disable_cbfn = bna_cb_ioceth_disable,
47976+ .hbfail_cbfn = bna_cb_ioceth_hbfail,
47977+ .reset_cbfn = bna_cb_ioceth_reset
47978 };
47979
47980 static void bna_attr_init(struct bna_ioceth *ioceth)
47981diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
47982index 8cffcdf..aadf043 100644
47983--- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
47984+++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
47985@@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
47986 */
47987 struct l2t_skb_cb {
47988 arp_failure_handler_func arp_failure_handler;
47989-};
47990+} __no_const;
47991
47992 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
47993
47994diff --git a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
47995index 279873c..11e1921 100644
47996--- a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
47997+++ b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
47998@@ -2365,7 +2365,7 @@ static void get_regs(struct net_device *dev, struct ethtool_regs *regs,
47999
48000 int i;
48001 struct adapter *ap = netdev2adap(dev);
48002- static const unsigned int *reg_ranges;
48003+ const unsigned int *reg_ranges;
48004 int arr_size = 0, buf_size = 0;
48005
48006 if (is_t4(ap->params.chip)) {
48007diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
48008index cf8b6ff..274271e 100644
48009--- a/drivers/net/ethernet/dec/tulip/de4x5.c
48010+++ b/drivers/net/ethernet/dec/tulip/de4x5.c
48011@@ -5387,7 +5387,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
48012 for (i=0; i<ETH_ALEN; i++) {
48013 tmp.addr[i] = dev->dev_addr[i];
48014 }
48015- if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
48016+ if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
48017 break;
48018
48019 case DE4X5_SET_HWADDR: /* Set the hardware address */
48020@@ -5427,7 +5427,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
48021 spin_lock_irqsave(&lp->lock, flags);
48022 memcpy(&statbuf, &lp->pktStats, ioc->len);
48023 spin_unlock_irqrestore(&lp->lock, flags);
48024- if (copy_to_user(ioc->data, &statbuf, ioc->len))
48025+ if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
48026 return -EFAULT;
48027 break;
48028 }
48029diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
48030index 597c463..5cc1a7f 100644
48031--- a/drivers/net/ethernet/emulex/benet/be_main.c
48032+++ b/drivers/net/ethernet/emulex/benet/be_main.c
48033@@ -537,7 +537,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
48034
48035 if (wrapped)
48036 newacc += 65536;
48037- ACCESS_ONCE(*acc) = newacc;
48038+ ACCESS_ONCE_RW(*acc) = newacc;
48039 }
48040
48041 static void populate_erx_stats(struct be_adapter *adapter,
48042diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
48043index c77fa4a..7fd42fc 100644
48044--- a/drivers/net/ethernet/faraday/ftgmac100.c
48045+++ b/drivers/net/ethernet/faraday/ftgmac100.c
48046@@ -30,6 +30,8 @@
48047 #include <linux/netdevice.h>
48048 #include <linux/phy.h>
48049 #include <linux/platform_device.h>
48050+#include <linux/interrupt.h>
48051+#include <linux/irqreturn.h>
48052 #include <net/ip.h>
48053
48054 #include "ftgmac100.h"
48055diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
48056index 4ff1adc..0ea6bf4 100644
48057--- a/drivers/net/ethernet/faraday/ftmac100.c
48058+++ b/drivers/net/ethernet/faraday/ftmac100.c
48059@@ -31,6 +31,8 @@
48060 #include <linux/module.h>
48061 #include <linux/netdevice.h>
48062 #include <linux/platform_device.h>
48063+#include <linux/interrupt.h>
48064+#include <linux/irqreturn.h>
48065
48066 #include "ftmac100.h"
48067
48068diff --git a/drivers/net/ethernet/intel/i40e/i40e_ptp.c b/drivers/net/ethernet/intel/i40e/i40e_ptp.c
48069index 537b621..07f87ce 100644
48070--- a/drivers/net/ethernet/intel/i40e/i40e_ptp.c
48071+++ b/drivers/net/ethernet/intel/i40e/i40e_ptp.c
48072@@ -401,7 +401,7 @@ void i40e_ptp_set_increment(struct i40e_pf *pf)
48073 wr32(hw, I40E_PRTTSYN_INC_H, incval >> 32);
48074
48075 /* Update the base adjustement value. */
48076- ACCESS_ONCE(pf->ptp_base_adj) = incval;
48077+ ACCESS_ONCE_RW(pf->ptp_base_adj) = incval;
48078 smp_mb(); /* Force the above update. */
48079 }
48080
48081diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
48082index 5fd4b52..87aa34b 100644
48083--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
48084+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
48085@@ -794,7 +794,7 @@ void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
48086 }
48087
48088 /* update the base incval used to calculate frequency adjustment */
48089- ACCESS_ONCE(adapter->base_incval) = incval;
48090+ ACCESS_ONCE_RW(adapter->base_incval) = incval;
48091 smp_mb();
48092
48093 /* need lock to prevent incorrect read while modifying cyclecounter */
48094diff --git a/drivers/net/ethernet/mellanox/mlx4/en_tx.c b/drivers/net/ethernet/mellanox/mlx4/en_tx.c
48095index 454d9fe..59f0f0b 100644
48096--- a/drivers/net/ethernet/mellanox/mlx4/en_tx.c
48097+++ b/drivers/net/ethernet/mellanox/mlx4/en_tx.c
48098@@ -458,8 +458,8 @@ static bool mlx4_en_process_tx_cq(struct net_device *dev,
48099 wmb();
48100
48101 /* we want to dirty this cache line once */
48102- ACCESS_ONCE(ring->last_nr_txbb) = last_nr_txbb;
48103- ACCESS_ONCE(ring->cons) = ring_cons + txbbs_skipped;
48104+ ACCESS_ONCE_RW(ring->last_nr_txbb) = last_nr_txbb;
48105+ ACCESS_ONCE_RW(ring->cons) = ring_cons + txbbs_skipped;
48106
48107 netdev_tx_completed_queue(ring->tx_queue, packets, bytes);
48108
48109diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.c b/drivers/net/ethernet/neterion/vxge/vxge-config.c
48110index 2bbd01f..e8baa64 100644
48111--- a/drivers/net/ethernet/neterion/vxge/vxge-config.c
48112+++ b/drivers/net/ethernet/neterion/vxge/vxge-config.c
48113@@ -3457,7 +3457,10 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
48114 struct __vxge_hw_fifo *fifo;
48115 struct vxge_hw_fifo_config *config;
48116 u32 txdl_size, txdl_per_memblock;
48117- struct vxge_hw_mempool_cbs fifo_mp_callback;
48118+ static struct vxge_hw_mempool_cbs fifo_mp_callback = {
48119+ .item_func_alloc = __vxge_hw_fifo_mempool_item_alloc,
48120+ };
48121+
48122 struct __vxge_hw_virtualpath *vpath;
48123
48124 if ((vp == NULL) || (attr == NULL)) {
48125@@ -3540,8 +3543,6 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
48126 goto exit;
48127 }
48128
48129- fifo_mp_callback.item_func_alloc = __vxge_hw_fifo_mempool_item_alloc;
48130-
48131 fifo->mempool =
48132 __vxge_hw_mempool_create(vpath->hldev,
48133 fifo->config->memblock_size,
48134diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
48135index 2bb48d5..d1a865d 100644
48136--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
48137+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
48138@@ -2324,7 +2324,9 @@ int qlcnic_83xx_configure_opmode(struct qlcnic_adapter *adapter)
48139 max_tx_rings = QLCNIC_MAX_VNIC_TX_RINGS;
48140 } else if (ret == QLC_83XX_DEFAULT_OPMODE) {
48141 ahw->nic_mode = QLCNIC_DEFAULT_MODE;
48142- adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
48143+ pax_open_kernel();
48144+ *(void **)&adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
48145+ pax_close_kernel();
48146 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
48147 max_sds_rings = QLCNIC_MAX_SDS_RINGS;
48148 max_tx_rings = QLCNIC_MAX_TX_RINGS;
48149diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
48150index be7d7a6..a8983f8 100644
48151--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
48152+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
48153@@ -207,17 +207,23 @@ int qlcnic_83xx_config_vnic_opmode(struct qlcnic_adapter *adapter)
48154 case QLCNIC_NON_PRIV_FUNC:
48155 ahw->op_mode = QLCNIC_NON_PRIV_FUNC;
48156 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
48157- nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
48158+ pax_open_kernel();
48159+ *(void **)&nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
48160+ pax_close_kernel();
48161 break;
48162 case QLCNIC_PRIV_FUNC:
48163 ahw->op_mode = QLCNIC_PRIV_FUNC;
48164 ahw->idc.state_entry = qlcnic_83xx_idc_vnic_pf_entry;
48165- nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
48166+ pax_open_kernel();
48167+ *(void **)&nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
48168+ pax_close_kernel();
48169 break;
48170 case QLCNIC_MGMT_FUNC:
48171 ahw->op_mode = QLCNIC_MGMT_FUNC;
48172 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
48173- nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
48174+ pax_open_kernel();
48175+ *(void **)&nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
48176+ pax_close_kernel();
48177 break;
48178 default:
48179 dev_err(&adapter->pdev->dev, "Invalid Virtual NIC opmode\n");
48180diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
48181index c9f57fb..208bdc1 100644
48182--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
48183+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
48184@@ -1285,7 +1285,7 @@ flash_temp:
48185 int qlcnic_dump_fw(struct qlcnic_adapter *adapter)
48186 {
48187 struct qlcnic_fw_dump *fw_dump = &adapter->ahw->fw_dump;
48188- static const struct qlcnic_dump_operations *fw_dump_ops;
48189+ const struct qlcnic_dump_operations *fw_dump_ops;
48190 struct qlcnic_83xx_dump_template_hdr *hdr_83xx;
48191 u32 entry_offset, dump, no_entries, buf_offset = 0;
48192 int i, k, ops_cnt, ops_index, dump_size = 0;
48193diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
48194index cf154f7..c948d1b 100644
48195--- a/drivers/net/ethernet/realtek/r8169.c
48196+++ b/drivers/net/ethernet/realtek/r8169.c
48197@@ -788,22 +788,22 @@ struct rtl8169_private {
48198 struct mdio_ops {
48199 void (*write)(struct rtl8169_private *, int, int);
48200 int (*read)(struct rtl8169_private *, int);
48201- } mdio_ops;
48202+ } __no_const mdio_ops;
48203
48204 struct pll_power_ops {
48205 void (*down)(struct rtl8169_private *);
48206 void (*up)(struct rtl8169_private *);
48207- } pll_power_ops;
48208+ } __no_const pll_power_ops;
48209
48210 struct jumbo_ops {
48211 void (*enable)(struct rtl8169_private *);
48212 void (*disable)(struct rtl8169_private *);
48213- } jumbo_ops;
48214+ } __no_const jumbo_ops;
48215
48216 struct csi_ops {
48217 void (*write)(struct rtl8169_private *, int, int);
48218 u32 (*read)(struct rtl8169_private *, int);
48219- } csi_ops;
48220+ } __no_const csi_ops;
48221
48222 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
48223 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
48224diff --git a/drivers/net/ethernet/sfc/ptp.c b/drivers/net/ethernet/sfc/ptp.c
48225index 6b861e3..204ac86 100644
48226--- a/drivers/net/ethernet/sfc/ptp.c
48227+++ b/drivers/net/ethernet/sfc/ptp.c
48228@@ -822,7 +822,7 @@ static int efx_ptp_synchronize(struct efx_nic *efx, unsigned int num_readings)
48229 ptp->start.dma_addr);
48230
48231 /* Clear flag that signals MC ready */
48232- ACCESS_ONCE(*start) = 0;
48233+ ACCESS_ONCE_RW(*start) = 0;
48234 rc = efx_mcdi_rpc_start(efx, MC_CMD_PTP, synch_buf,
48235 MC_CMD_PTP_IN_SYNCHRONIZE_LEN);
48236 EFX_BUG_ON_PARANOID(rc);
48237diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
48238index 08c483b..2c4a553 100644
48239--- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
48240+++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
48241@@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
48242
48243 writel(value, ioaddr + MMC_CNTRL);
48244
48245- pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
48246- MMC_CNTRL, value);
48247+// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
48248+// MMC_CNTRL, value);
48249 }
48250
48251 /* To mask all all interrupts.*/
48252diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
48253index 2f48f79..8ae1a1a 100644
48254--- a/drivers/net/hyperv/hyperv_net.h
48255+++ b/drivers/net/hyperv/hyperv_net.h
48256@@ -171,7 +171,7 @@ struct rndis_device {
48257 enum rndis_device_state state;
48258 bool link_state;
48259 bool link_change;
48260- atomic_t new_req_id;
48261+ atomic_unchecked_t new_req_id;
48262
48263 spinlock_t request_lock;
48264 struct list_head req_list;
48265diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
48266index 2b86f0b..ecc996f 100644
48267--- a/drivers/net/hyperv/rndis_filter.c
48268+++ b/drivers/net/hyperv/rndis_filter.c
48269@@ -102,7 +102,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
48270 * template
48271 */
48272 set = &rndis_msg->msg.set_req;
48273- set->req_id = atomic_inc_return(&dev->new_req_id);
48274+ set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
48275
48276 /* Add to the request list */
48277 spin_lock_irqsave(&dev->request_lock, flags);
48278@@ -911,7 +911,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
48279
48280 /* Setup the rndis set */
48281 halt = &request->request_msg.msg.halt_req;
48282- halt->req_id = atomic_inc_return(&dev->new_req_id);
48283+ halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
48284
48285 /* Ignore return since this msg is optional. */
48286 rndis_filter_send_request(dev, request);
48287diff --git a/drivers/net/ieee802154/fakehard.c b/drivers/net/ieee802154/fakehard.c
48288index 6cbc56a..5f7e6c8 100644
48289--- a/drivers/net/ieee802154/fakehard.c
48290+++ b/drivers/net/ieee802154/fakehard.c
48291@@ -365,7 +365,7 @@ static int ieee802154fake_probe(struct platform_device *pdev)
48292 phy->transmit_power = 0xbf;
48293
48294 dev->netdev_ops = &fake_ops;
48295- dev->ml_priv = &fake_mlme;
48296+ dev->ml_priv = (void *)&fake_mlme;
48297
48298 priv = netdev_priv(dev);
48299 priv->phy = phy;
48300diff --git a/drivers/net/ifb.c b/drivers/net/ifb.c
48301index 34f846b..4a0d5b1 100644
48302--- a/drivers/net/ifb.c
48303+++ b/drivers/net/ifb.c
48304@@ -253,7 +253,7 @@ static int ifb_validate(struct nlattr *tb[], struct nlattr *data[])
48305 return 0;
48306 }
48307
48308-static struct rtnl_link_ops ifb_link_ops __read_mostly = {
48309+static struct rtnl_link_ops ifb_link_ops = {
48310 .kind = "ifb",
48311 .priv_size = sizeof(struct ifb_private),
48312 .setup = ifb_setup,
48313diff --git a/drivers/net/macvlan.c b/drivers/net/macvlan.c
48314index bfb0b6e..5c396ce 100644
48315--- a/drivers/net/macvlan.c
48316+++ b/drivers/net/macvlan.c
48317@@ -335,7 +335,7 @@ static void macvlan_broadcast_enqueue(struct macvlan_port *port,
48318 free_nskb:
48319 kfree_skb(nskb);
48320 err:
48321- atomic_long_inc(&skb->dev->rx_dropped);
48322+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
48323 }
48324
48325 static void macvlan_flush_sources(struct macvlan_port *port,
48326@@ -1454,13 +1454,15 @@ static const struct nla_policy macvlan_policy[IFLA_MACVLAN_MAX + 1] = {
48327 int macvlan_link_register(struct rtnl_link_ops *ops)
48328 {
48329 /* common fields */
48330- ops->priv_size = sizeof(struct macvlan_dev);
48331- ops->validate = macvlan_validate;
48332- ops->maxtype = IFLA_MACVLAN_MAX;
48333- ops->policy = macvlan_policy;
48334- ops->changelink = macvlan_changelink;
48335- ops->get_size = macvlan_get_size;
48336- ops->fill_info = macvlan_fill_info;
48337+ pax_open_kernel();
48338+ *(size_t *)&ops->priv_size = sizeof(struct macvlan_dev);
48339+ *(void **)&ops->validate = macvlan_validate;
48340+ *(int *)&ops->maxtype = IFLA_MACVLAN_MAX;
48341+ *(const void **)&ops->policy = macvlan_policy;
48342+ *(void **)&ops->changelink = macvlan_changelink;
48343+ *(void **)&ops->get_size = macvlan_get_size;
48344+ *(void **)&ops->fill_info = macvlan_fill_info;
48345+ pax_close_kernel();
48346
48347 return rtnl_link_register(ops);
48348 };
48349@@ -1540,7 +1542,7 @@ static int macvlan_device_event(struct notifier_block *unused,
48350 return NOTIFY_DONE;
48351 }
48352
48353-static struct notifier_block macvlan_notifier_block __read_mostly = {
48354+static struct notifier_block macvlan_notifier_block = {
48355 .notifier_call = macvlan_device_event,
48356 };
48357
48358diff --git a/drivers/net/macvtap.c b/drivers/net/macvtap.c
48359index 880cc09..6a68ba6 100644
48360--- a/drivers/net/macvtap.c
48361+++ b/drivers/net/macvtap.c
48362@@ -422,7 +422,7 @@ static void macvtap_setup(struct net_device *dev)
48363 dev->tx_queue_len = TUN_READQ_SIZE;
48364 }
48365
48366-static struct rtnl_link_ops macvtap_link_ops __read_mostly = {
48367+static struct rtnl_link_ops macvtap_link_ops = {
48368 .kind = "macvtap",
48369 .setup = macvtap_setup,
48370 .newlink = macvtap_newlink,
48371@@ -1020,7 +1020,7 @@ static long macvtap_ioctl(struct file *file, unsigned int cmd,
48372 }
48373
48374 ret = 0;
48375- if (copy_to_user(&ifr->ifr_name, vlan->dev->name, IFNAMSIZ) ||
48376+ if (copy_to_user(ifr->ifr_name, vlan->dev->name, IFNAMSIZ) ||
48377 put_user(q->flags, &ifr->ifr_flags))
48378 ret = -EFAULT;
48379 macvtap_put_vlan(vlan);
48380@@ -1190,7 +1190,7 @@ static int macvtap_device_event(struct notifier_block *unused,
48381 return NOTIFY_DONE;
48382 }
48383
48384-static struct notifier_block macvtap_notifier_block __read_mostly = {
48385+static struct notifier_block macvtap_notifier_block = {
48386 .notifier_call = macvtap_device_event,
48387 };
48388
48389diff --git a/drivers/net/nlmon.c b/drivers/net/nlmon.c
48390index 34924df..a747360 100644
48391--- a/drivers/net/nlmon.c
48392+++ b/drivers/net/nlmon.c
48393@@ -154,7 +154,7 @@ static int nlmon_validate(struct nlattr *tb[], struct nlattr *data[])
48394 return 0;
48395 }
48396
48397-static struct rtnl_link_ops nlmon_link_ops __read_mostly = {
48398+static struct rtnl_link_ops nlmon_link_ops = {
48399 .kind = "nlmon",
48400 .priv_size = sizeof(struct nlmon),
48401 .setup = nlmon_setup,
48402diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
48403index 794a473..9fd437b 100644
48404--- a/drivers/net/ppp/ppp_generic.c
48405+++ b/drivers/net/ppp/ppp_generic.c
48406@@ -1020,7 +1020,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
48407 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
48408 struct ppp_stats stats;
48409 struct ppp_comp_stats cstats;
48410- char *vers;
48411
48412 switch (cmd) {
48413 case SIOCGPPPSTATS:
48414@@ -1042,8 +1041,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
48415 break;
48416
48417 case SIOCGPPPVER:
48418- vers = PPP_VERSION;
48419- if (copy_to_user(addr, vers, strlen(vers) + 1))
48420+ if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
48421 break;
48422 err = 0;
48423 break;
48424diff --git a/drivers/net/slip/slhc.c b/drivers/net/slip/slhc.c
48425index 079f7ad..b2a2bfa7 100644
48426--- a/drivers/net/slip/slhc.c
48427+++ b/drivers/net/slip/slhc.c
48428@@ -487,7 +487,7 @@ slhc_uncompress(struct slcompress *comp, unsigned char *icp, int isize)
48429 register struct tcphdr *thp;
48430 register struct iphdr *ip;
48431 register struct cstate *cs;
48432- int len, hdrlen;
48433+ long len, hdrlen;
48434 unsigned char *cp = icp;
48435
48436 /* We've got a compressed packet; read the change byte */
48437diff --git a/drivers/net/team/team.c b/drivers/net/team/team.c
48438index 2368395..bf6fe96 100644
48439--- a/drivers/net/team/team.c
48440+++ b/drivers/net/team/team.c
48441@@ -2090,7 +2090,7 @@ static unsigned int team_get_num_rx_queues(void)
48442 return TEAM_DEFAULT_NUM_RX_QUEUES;
48443 }
48444
48445-static struct rtnl_link_ops team_link_ops __read_mostly = {
48446+static struct rtnl_link_ops team_link_ops = {
48447 .kind = DRV_NAME,
48448 .priv_size = sizeof(struct team),
48449 .setup = team_setup,
48450@@ -2880,7 +2880,7 @@ static int team_device_event(struct notifier_block *unused,
48451 return NOTIFY_DONE;
48452 }
48453
48454-static struct notifier_block team_notifier_block __read_mostly = {
48455+static struct notifier_block team_notifier_block = {
48456 .notifier_call = team_device_event,
48457 };
48458
48459diff --git a/drivers/net/tun.c b/drivers/net/tun.c
48460index 9dd3746..74f191e 100644
48461--- a/drivers/net/tun.c
48462+++ b/drivers/net/tun.c
48463@@ -1426,7 +1426,7 @@ static int tun_validate(struct nlattr *tb[], struct nlattr *data[])
48464 return -EINVAL;
48465 }
48466
48467-static struct rtnl_link_ops tun_link_ops __read_mostly = {
48468+static struct rtnl_link_ops tun_link_ops = {
48469 .kind = DRV_NAME,
48470 .priv_size = sizeof(struct tun_struct),
48471 .setup = tun_setup,
48472@@ -1868,7 +1868,7 @@ unlock:
48473 }
48474
48475 static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
48476- unsigned long arg, int ifreq_len)
48477+ unsigned long arg, size_t ifreq_len)
48478 {
48479 struct tun_file *tfile = file->private_data;
48480 struct tun_struct *tun;
48481@@ -1881,6 +1881,9 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
48482 unsigned int ifindex;
48483 int ret;
48484
48485+ if (ifreq_len > sizeof ifr)
48486+ return -EFAULT;
48487+
48488 if (cmd == TUNSETIFF || cmd == TUNSETQUEUE || _IOC_TYPE(cmd) == 0x89) {
48489 if (copy_from_user(&ifr, argp, ifreq_len))
48490 return -EFAULT;
48491diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
48492index babda7d..e40c90a 100644
48493--- a/drivers/net/usb/hso.c
48494+++ b/drivers/net/usb/hso.c
48495@@ -71,7 +71,7 @@
48496 #include <asm/byteorder.h>
48497 #include <linux/serial_core.h>
48498 #include <linux/serial.h>
48499-
48500+#include <asm/local.h>
48501
48502 #define MOD_AUTHOR "Option Wireless"
48503 #define MOD_DESCRIPTION "USB High Speed Option driver"
48504@@ -1178,7 +1178,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
48505 struct urb *urb;
48506
48507 urb = serial->rx_urb[0];
48508- if (serial->port.count > 0) {
48509+ if (atomic_read(&serial->port.count) > 0) {
48510 count = put_rxbuf_data(urb, serial);
48511 if (count == -1)
48512 return;
48513@@ -1216,7 +1216,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
48514 DUMP1(urb->transfer_buffer, urb->actual_length);
48515
48516 /* Anyone listening? */
48517- if (serial->port.count == 0)
48518+ if (atomic_read(&serial->port.count) == 0)
48519 return;
48520
48521 if (serial->parent->port_spec & HSO_INFO_CRC_BUG)
48522@@ -1278,8 +1278,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
48523 tty_port_tty_set(&serial->port, tty);
48524
48525 /* check for port already opened, if not set the termios */
48526- serial->port.count++;
48527- if (serial->port.count == 1) {
48528+ if (atomic_inc_return(&serial->port.count) == 1) {
48529 serial->rx_state = RX_IDLE;
48530 /* Force default termio settings */
48531 _hso_serial_set_termios(tty, NULL);
48532@@ -1289,7 +1288,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
48533 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
48534 if (result) {
48535 hso_stop_serial_device(serial->parent);
48536- serial->port.count--;
48537+ atomic_dec(&serial->port.count);
48538 kref_put(&serial->parent->ref, hso_serial_ref_free);
48539 }
48540 } else {
48541@@ -1326,10 +1325,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
48542
48543 /* reset the rts and dtr */
48544 /* do the actual close */
48545- serial->port.count--;
48546+ atomic_dec(&serial->port.count);
48547
48548- if (serial->port.count <= 0) {
48549- serial->port.count = 0;
48550+ if (atomic_read(&serial->port.count) <= 0) {
48551+ atomic_set(&serial->port.count, 0);
48552 tty_port_tty_set(&serial->port, NULL);
48553 if (!usb_gone)
48554 hso_stop_serial_device(serial->parent);
48555@@ -1404,7 +1403,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
48556
48557 /* the actual setup */
48558 spin_lock_irqsave(&serial->serial_lock, flags);
48559- if (serial->port.count)
48560+ if (atomic_read(&serial->port.count))
48561 _hso_serial_set_termios(tty, old);
48562 else
48563 tty->termios = *old;
48564@@ -1873,7 +1872,7 @@ static void intr_callback(struct urb *urb)
48565 D1("Pending read interrupt on port %d\n", i);
48566 spin_lock(&serial->serial_lock);
48567 if (serial->rx_state == RX_IDLE &&
48568- serial->port.count > 0) {
48569+ atomic_read(&serial->port.count) > 0) {
48570 /* Setup and send a ctrl req read on
48571 * port i */
48572 if (!serial->rx_urb_filled[0]) {
48573@@ -3047,7 +3046,7 @@ static int hso_resume(struct usb_interface *iface)
48574 /* Start all serial ports */
48575 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
48576 if (serial_table[i] && (serial_table[i]->interface == iface)) {
48577- if (dev2ser(serial_table[i])->port.count) {
48578+ if (atomic_read(&dev2ser(serial_table[i])->port.count)) {
48579 result =
48580 hso_start_serial_device(serial_table[i], GFP_NOIO);
48581 hso_kick_transmit(dev2ser(serial_table[i]));
48582diff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c
48583index c6554c7..7e2ebd7 100644
48584--- a/drivers/net/usb/r8152.c
48585+++ b/drivers/net/usb/r8152.c
48586@@ -577,7 +577,7 @@ struct r8152 {
48587 void (*unload)(struct r8152 *);
48588 int (*eee_get)(struct r8152 *, struct ethtool_eee *);
48589 int (*eee_set)(struct r8152 *, struct ethtool_eee *);
48590- } rtl_ops;
48591+ } __no_const rtl_ops;
48592
48593 int intr_interval;
48594 u32 saved_wolopts;
48595diff --git a/drivers/net/usb/sierra_net.c b/drivers/net/usb/sierra_net.c
48596index a2515887..6d13233 100644
48597--- a/drivers/net/usb/sierra_net.c
48598+++ b/drivers/net/usb/sierra_net.c
48599@@ -51,7 +51,7 @@ static const char driver_name[] = "sierra_net";
48600 /* atomic counter partially included in MAC address to make sure 2 devices
48601 * do not end up with the same MAC - concept breaks in case of > 255 ifaces
48602 */
48603-static atomic_t iface_counter = ATOMIC_INIT(0);
48604+static atomic_unchecked_t iface_counter = ATOMIC_INIT(0);
48605
48606 /*
48607 * SYNC Timer Delay definition used to set the expiry time
48608@@ -697,7 +697,7 @@ static int sierra_net_bind(struct usbnet *dev, struct usb_interface *intf)
48609 dev->net->netdev_ops = &sierra_net_device_ops;
48610
48611 /* change MAC addr to include, ifacenum, and to be unique */
48612- dev->net->dev_addr[ETH_ALEN-2] = atomic_inc_return(&iface_counter);
48613+ dev->net->dev_addr[ETH_ALEN-2] = atomic_inc_return_unchecked(&iface_counter);
48614 dev->net->dev_addr[ETH_ALEN-1] = ifacenum;
48615
48616 /* we will have to manufacture ethernet headers, prepare template */
48617diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
48618index b0bc8ea..3af931b5 100644
48619--- a/drivers/net/virtio_net.c
48620+++ b/drivers/net/virtio_net.c
48621@@ -48,7 +48,7 @@ module_param(gso, bool, 0444);
48622 #define RECEIVE_AVG_WEIGHT 64
48623
48624 /* Minimum alignment for mergeable packet buffers. */
48625-#define MERGEABLE_BUFFER_ALIGN max(L1_CACHE_BYTES, 256)
48626+#define MERGEABLE_BUFFER_ALIGN max(L1_CACHE_BYTES, 256UL)
48627
48628 #define VIRTNET_DRIVER_VERSION "1.0.0"
48629
48630diff --git a/drivers/net/vxlan.c b/drivers/net/vxlan.c
48631index 42b2d6a5..2a2cb41 100644
48632--- a/drivers/net/vxlan.c
48633+++ b/drivers/net/vxlan.c
48634@@ -2695,7 +2695,7 @@ nla_put_failure:
48635 return -EMSGSIZE;
48636 }
48637
48638-static struct rtnl_link_ops vxlan_link_ops __read_mostly = {
48639+static struct rtnl_link_ops vxlan_link_ops = {
48640 .kind = "vxlan",
48641 .maxtype = IFLA_VXLAN_MAX,
48642 .policy = vxlan_policy,
48643@@ -2742,7 +2742,7 @@ static int vxlan_lowerdev_event(struct notifier_block *unused,
48644 return NOTIFY_DONE;
48645 }
48646
48647-static struct notifier_block vxlan_notifier_block __read_mostly = {
48648+static struct notifier_block vxlan_notifier_block = {
48649 .notifier_call = vxlan_lowerdev_event,
48650 };
48651
48652diff --git a/drivers/net/wan/lmc/lmc_media.c b/drivers/net/wan/lmc/lmc_media.c
48653index 5920c99..ff2e4a5 100644
48654--- a/drivers/net/wan/lmc/lmc_media.c
48655+++ b/drivers/net/wan/lmc/lmc_media.c
48656@@ -95,62 +95,63 @@ static inline void write_av9110_bit (lmc_softc_t *, int);
48657 static void write_av9110(lmc_softc_t *, u32, u32, u32, u32, u32);
48658
48659 lmc_media_t lmc_ds3_media = {
48660- lmc_ds3_init, /* special media init stuff */
48661- lmc_ds3_default, /* reset to default state */
48662- lmc_ds3_set_status, /* reset status to state provided */
48663- lmc_dummy_set_1, /* set clock source */
48664- lmc_dummy_set2_1, /* set line speed */
48665- lmc_ds3_set_100ft, /* set cable length */
48666- lmc_ds3_set_scram, /* set scrambler */
48667- lmc_ds3_get_link_status, /* get link status */
48668- lmc_dummy_set_1, /* set link status */
48669- lmc_ds3_set_crc_length, /* set CRC length */
48670- lmc_dummy_set_1, /* set T1 or E1 circuit type */
48671- lmc_ds3_watchdog
48672+ .init = lmc_ds3_init, /* special media init stuff */
48673+ .defaults = lmc_ds3_default, /* reset to default state */
48674+ .set_status = lmc_ds3_set_status, /* reset status to state provided */
48675+ .set_clock_source = lmc_dummy_set_1, /* set clock source */
48676+ .set_speed = lmc_dummy_set2_1, /* set line speed */
48677+ .set_cable_length = lmc_ds3_set_100ft, /* set cable length */
48678+ .set_scrambler = lmc_ds3_set_scram, /* set scrambler */
48679+ .get_link_status = lmc_ds3_get_link_status, /* get link status */
48680+ .set_link_status = lmc_dummy_set_1, /* set link status */
48681+ .set_crc_length = lmc_ds3_set_crc_length, /* set CRC length */
48682+ .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
48683+ .watchdog = lmc_ds3_watchdog
48684 };
48685
48686 lmc_media_t lmc_hssi_media = {
48687- lmc_hssi_init, /* special media init stuff */
48688- lmc_hssi_default, /* reset to default state */
48689- lmc_hssi_set_status, /* reset status to state provided */
48690- lmc_hssi_set_clock, /* set clock source */
48691- lmc_dummy_set2_1, /* set line speed */
48692- lmc_dummy_set_1, /* set cable length */
48693- lmc_dummy_set_1, /* set scrambler */
48694- lmc_hssi_get_link_status, /* get link status */
48695- lmc_hssi_set_link_status, /* set link status */
48696- lmc_hssi_set_crc_length, /* set CRC length */
48697- lmc_dummy_set_1, /* set T1 or E1 circuit type */
48698- lmc_hssi_watchdog
48699+ .init = lmc_hssi_init, /* special media init stuff */
48700+ .defaults = lmc_hssi_default, /* reset to default state */
48701+ .set_status = lmc_hssi_set_status, /* reset status to state provided */
48702+ .set_clock_source = lmc_hssi_set_clock, /* set clock source */
48703+ .set_speed = lmc_dummy_set2_1, /* set line speed */
48704+ .set_cable_length = lmc_dummy_set_1, /* set cable length */
48705+ .set_scrambler = lmc_dummy_set_1, /* set scrambler */
48706+ .get_link_status = lmc_hssi_get_link_status, /* get link status */
48707+ .set_link_status = lmc_hssi_set_link_status, /* set link status */
48708+ .set_crc_length = lmc_hssi_set_crc_length, /* set CRC length */
48709+ .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
48710+ .watchdog = lmc_hssi_watchdog
48711 };
48712
48713-lmc_media_t lmc_ssi_media = { lmc_ssi_init, /* special media init stuff */
48714- lmc_ssi_default, /* reset to default state */
48715- lmc_ssi_set_status, /* reset status to state provided */
48716- lmc_ssi_set_clock, /* set clock source */
48717- lmc_ssi_set_speed, /* set line speed */
48718- lmc_dummy_set_1, /* set cable length */
48719- lmc_dummy_set_1, /* set scrambler */
48720- lmc_ssi_get_link_status, /* get link status */
48721- lmc_ssi_set_link_status, /* set link status */
48722- lmc_ssi_set_crc_length, /* set CRC length */
48723- lmc_dummy_set_1, /* set T1 or E1 circuit type */
48724- lmc_ssi_watchdog
48725+lmc_media_t lmc_ssi_media = {
48726+ .init = lmc_ssi_init, /* special media init stuff */
48727+ .defaults = lmc_ssi_default, /* reset to default state */
48728+ .set_status = lmc_ssi_set_status, /* reset status to state provided */
48729+ .set_clock_source = lmc_ssi_set_clock, /* set clock source */
48730+ .set_speed = lmc_ssi_set_speed, /* set line speed */
48731+ .set_cable_length = lmc_dummy_set_1, /* set cable length */
48732+ .set_scrambler = lmc_dummy_set_1, /* set scrambler */
48733+ .get_link_status = lmc_ssi_get_link_status, /* get link status */
48734+ .set_link_status = lmc_ssi_set_link_status, /* set link status */
48735+ .set_crc_length = lmc_ssi_set_crc_length, /* set CRC length */
48736+ .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
48737+ .watchdog = lmc_ssi_watchdog
48738 };
48739
48740 lmc_media_t lmc_t1_media = {
48741- lmc_t1_init, /* special media init stuff */
48742- lmc_t1_default, /* reset to default state */
48743- lmc_t1_set_status, /* reset status to state provided */
48744- lmc_t1_set_clock, /* set clock source */
48745- lmc_dummy_set2_1, /* set line speed */
48746- lmc_dummy_set_1, /* set cable length */
48747- lmc_dummy_set_1, /* set scrambler */
48748- lmc_t1_get_link_status, /* get link status */
48749- lmc_dummy_set_1, /* set link status */
48750- lmc_t1_set_crc_length, /* set CRC length */
48751- lmc_t1_set_circuit_type, /* set T1 or E1 circuit type */
48752- lmc_t1_watchdog
48753+ .init = lmc_t1_init, /* special media init stuff */
48754+ .defaults = lmc_t1_default, /* reset to default state */
48755+ .set_status = lmc_t1_set_status, /* reset status to state provided */
48756+ .set_clock_source = lmc_t1_set_clock, /* set clock source */
48757+ .set_speed = lmc_dummy_set2_1, /* set line speed */
48758+ .set_cable_length = lmc_dummy_set_1, /* set cable length */
48759+ .set_scrambler = lmc_dummy_set_1, /* set scrambler */
48760+ .get_link_status = lmc_t1_get_link_status, /* get link status */
48761+ .set_link_status = lmc_dummy_set_1, /* set link status */
48762+ .set_crc_length = lmc_t1_set_crc_length, /* set CRC length */
48763+ .set_circuit_type = lmc_t1_set_circuit_type, /* set T1 or E1 circuit type */
48764+ .watchdog = lmc_t1_watchdog
48765 };
48766
48767 static void
48768diff --git a/drivers/net/wan/z85230.c b/drivers/net/wan/z85230.c
48769index feacc3b..5bac0de 100644
48770--- a/drivers/net/wan/z85230.c
48771+++ b/drivers/net/wan/z85230.c
48772@@ -485,9 +485,9 @@ static void z8530_status(struct z8530_channel *chan)
48773
48774 struct z8530_irqhandler z8530_sync =
48775 {
48776- z8530_rx,
48777- z8530_tx,
48778- z8530_status
48779+ .rx = z8530_rx,
48780+ .tx = z8530_tx,
48781+ .status = z8530_status
48782 };
48783
48784 EXPORT_SYMBOL(z8530_sync);
48785@@ -605,15 +605,15 @@ static void z8530_dma_status(struct z8530_channel *chan)
48786 }
48787
48788 static struct z8530_irqhandler z8530_dma_sync = {
48789- z8530_dma_rx,
48790- z8530_dma_tx,
48791- z8530_dma_status
48792+ .rx = z8530_dma_rx,
48793+ .tx = z8530_dma_tx,
48794+ .status = z8530_dma_status
48795 };
48796
48797 static struct z8530_irqhandler z8530_txdma_sync = {
48798- z8530_rx,
48799- z8530_dma_tx,
48800- z8530_dma_status
48801+ .rx = z8530_rx,
48802+ .tx = z8530_dma_tx,
48803+ .status = z8530_dma_status
48804 };
48805
48806 /**
48807@@ -680,9 +680,9 @@ static void z8530_status_clear(struct z8530_channel *chan)
48808
48809 struct z8530_irqhandler z8530_nop=
48810 {
48811- z8530_rx_clear,
48812- z8530_tx_clear,
48813- z8530_status_clear
48814+ .rx = z8530_rx_clear,
48815+ .tx = z8530_tx_clear,
48816+ .status = z8530_status_clear
48817 };
48818
48819
48820diff --git a/drivers/net/wimax/i2400m/rx.c b/drivers/net/wimax/i2400m/rx.c
48821index 0b60295..b8bfa5b 100644
48822--- a/drivers/net/wimax/i2400m/rx.c
48823+++ b/drivers/net/wimax/i2400m/rx.c
48824@@ -1359,7 +1359,7 @@ int i2400m_rx_setup(struct i2400m *i2400m)
48825 if (i2400m->rx_roq == NULL)
48826 goto error_roq_alloc;
48827
48828- rd = kcalloc(I2400M_RO_CIN + 1, sizeof(*i2400m->rx_roq[0].log),
48829+ rd = kcalloc(sizeof(*i2400m->rx_roq[0].log), I2400M_RO_CIN + 1,
48830 GFP_KERNEL);
48831 if (rd == NULL) {
48832 result = -ENOMEM;
48833diff --git a/drivers/net/wireless/airo.c b/drivers/net/wireless/airo.c
48834index e71a2ce..2268d61 100644
48835--- a/drivers/net/wireless/airo.c
48836+++ b/drivers/net/wireless/airo.c
48837@@ -7846,7 +7846,7 @@ static int writerids(struct net_device *dev, aironet_ioctl *comp) {
48838 struct airo_info *ai = dev->ml_priv;
48839 int ridcode;
48840 int enabled;
48841- static int (* writer)(struct airo_info *, u16 rid, const void *, int, int);
48842+ int (* writer)(struct airo_info *, u16 rid, const void *, int, int);
48843 unsigned char *iobuf;
48844
48845 /* Only super-user can write RIDs */
48846diff --git a/drivers/net/wireless/at76c50x-usb.c b/drivers/net/wireless/at76c50x-usb.c
48847index da92bfa..5a9001a 100644
48848--- a/drivers/net/wireless/at76c50x-usb.c
48849+++ b/drivers/net/wireless/at76c50x-usb.c
48850@@ -353,7 +353,7 @@ static int at76_dfu_get_state(struct usb_device *udev, u8 *state)
48851 }
48852
48853 /* Convert timeout from the DFU status to jiffies */
48854-static inline unsigned long at76_get_timeout(struct dfu_status *s)
48855+static inline unsigned long __intentional_overflow(-1) at76_get_timeout(struct dfu_status *s)
48856 {
48857 return msecs_to_jiffies((s->poll_timeout[2] << 16)
48858 | (s->poll_timeout[1] << 8)
48859diff --git a/drivers/net/wireless/ath/ath10k/htc.c b/drivers/net/wireless/ath/ath10k/htc.c
48860index 676bd4e..0b807a3 100644
48861--- a/drivers/net/wireless/ath/ath10k/htc.c
48862+++ b/drivers/net/wireless/ath/ath10k/htc.c
48863@@ -848,7 +848,10 @@ int ath10k_htc_start(struct ath10k_htc *htc)
48864 /* registered target arrival callback from the HIF layer */
48865 int ath10k_htc_init(struct ath10k *ar)
48866 {
48867- struct ath10k_hif_cb htc_callbacks;
48868+ static struct ath10k_hif_cb htc_callbacks = {
48869+ .rx_completion = ath10k_htc_rx_completion_handler,
48870+ .tx_completion = ath10k_htc_tx_completion_handler,
48871+ };
48872 struct ath10k_htc_ep *ep = NULL;
48873 struct ath10k_htc *htc = &ar->htc;
48874
48875@@ -857,8 +860,6 @@ int ath10k_htc_init(struct ath10k *ar)
48876 ath10k_htc_reset_endpoint_states(htc);
48877
48878 /* setup HIF layer callbacks */
48879- htc_callbacks.rx_completion = ath10k_htc_rx_completion_handler;
48880- htc_callbacks.tx_completion = ath10k_htc_tx_completion_handler;
48881 htc->ar = ar;
48882
48883 /* Get HIF default pipe for HTC message exchange */
48884diff --git a/drivers/net/wireless/ath/ath10k/htc.h b/drivers/net/wireless/ath/ath10k/htc.h
48885index 527179c..a890150 100644
48886--- a/drivers/net/wireless/ath/ath10k/htc.h
48887+++ b/drivers/net/wireless/ath/ath10k/htc.h
48888@@ -270,13 +270,13 @@ enum ath10k_htc_ep_id {
48889
48890 struct ath10k_htc_ops {
48891 void (*target_send_suspend_complete)(struct ath10k *ar);
48892-};
48893+} __no_const;
48894
48895 struct ath10k_htc_ep_ops {
48896 void (*ep_tx_complete)(struct ath10k *, struct sk_buff *);
48897 void (*ep_rx_complete)(struct ath10k *, struct sk_buff *);
48898 void (*ep_tx_credits)(struct ath10k *);
48899-};
48900+} __no_const;
48901
48902 /* service connection information */
48903 struct ath10k_htc_svc_conn_req {
48904diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
48905index 2a93519..7052786 100644
48906--- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
48907+++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
48908@@ -220,8 +220,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
48909 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
48910 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
48911
48912- ACCESS_ONCE(ads->ds_link) = i->link;
48913- ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
48914+ ACCESS_ONCE_RW(ads->ds_link) = i->link;
48915+ ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
48916
48917 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
48918 ctl6 = SM(i->keytype, AR_EncrType);
48919@@ -235,26 +235,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
48920
48921 if ((i->is_first || i->is_last) &&
48922 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
48923- ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
48924+ ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
48925 | set11nTries(i->rates, 1)
48926 | set11nTries(i->rates, 2)
48927 | set11nTries(i->rates, 3)
48928 | (i->dur_update ? AR_DurUpdateEna : 0)
48929 | SM(0, AR_BurstDur);
48930
48931- ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
48932+ ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
48933 | set11nRate(i->rates, 1)
48934 | set11nRate(i->rates, 2)
48935 | set11nRate(i->rates, 3);
48936 } else {
48937- ACCESS_ONCE(ads->ds_ctl2) = 0;
48938- ACCESS_ONCE(ads->ds_ctl3) = 0;
48939+ ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
48940+ ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
48941 }
48942
48943 if (!i->is_first) {
48944- ACCESS_ONCE(ads->ds_ctl0) = 0;
48945- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
48946- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
48947+ ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
48948+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
48949+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
48950 return;
48951 }
48952
48953@@ -279,7 +279,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
48954 break;
48955 }
48956
48957- ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
48958+ ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
48959 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
48960 | SM(i->txpower, AR_XmitPower0)
48961 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
48962@@ -289,27 +289,27 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
48963 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
48964 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
48965
48966- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
48967- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
48968+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
48969+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
48970
48971 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
48972 return;
48973
48974- ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
48975+ ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
48976 | set11nPktDurRTSCTS(i->rates, 1);
48977
48978- ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
48979+ ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
48980 | set11nPktDurRTSCTS(i->rates, 3);
48981
48982- ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
48983+ ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
48984 | set11nRateFlags(i->rates, 1)
48985 | set11nRateFlags(i->rates, 2)
48986 | set11nRateFlags(i->rates, 3)
48987 | SM(i->rtscts_rate, AR_RTSCTSRate);
48988
48989- ACCESS_ONCE(ads->ds_ctl9) = SM(i->txpower, AR_XmitPower1);
48990- ACCESS_ONCE(ads->ds_ctl10) = SM(i->txpower, AR_XmitPower2);
48991- ACCESS_ONCE(ads->ds_ctl11) = SM(i->txpower, AR_XmitPower3);
48992+ ACCESS_ONCE_RW(ads->ds_ctl9) = SM(i->txpower, AR_XmitPower1);
48993+ ACCESS_ONCE_RW(ads->ds_ctl10) = SM(i->txpower, AR_XmitPower2);
48994+ ACCESS_ONCE_RW(ads->ds_ctl11) = SM(i->txpower, AR_XmitPower3);
48995 }
48996
48997 static int ar9002_hw_proc_txdesc(struct ath_hw *ah, void *ds,
48998diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
48999index 057b165..98ae88f 100644
49000--- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
49001+++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
49002@@ -39,47 +39,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
49003 (i->qcu << AR_TxQcuNum_S) | desc_len;
49004
49005 checksum += val;
49006- ACCESS_ONCE(ads->info) = val;
49007+ ACCESS_ONCE_RW(ads->info) = val;
49008
49009 checksum += i->link;
49010- ACCESS_ONCE(ads->link) = i->link;
49011+ ACCESS_ONCE_RW(ads->link) = i->link;
49012
49013 checksum += i->buf_addr[0];
49014- ACCESS_ONCE(ads->data0) = i->buf_addr[0];
49015+ ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
49016 checksum += i->buf_addr[1];
49017- ACCESS_ONCE(ads->data1) = i->buf_addr[1];
49018+ ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
49019 checksum += i->buf_addr[2];
49020- ACCESS_ONCE(ads->data2) = i->buf_addr[2];
49021+ ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
49022 checksum += i->buf_addr[3];
49023- ACCESS_ONCE(ads->data3) = i->buf_addr[3];
49024+ ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
49025
49026 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
49027- ACCESS_ONCE(ads->ctl3) = val;
49028+ ACCESS_ONCE_RW(ads->ctl3) = val;
49029 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
49030- ACCESS_ONCE(ads->ctl5) = val;
49031+ ACCESS_ONCE_RW(ads->ctl5) = val;
49032 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
49033- ACCESS_ONCE(ads->ctl7) = val;
49034+ ACCESS_ONCE_RW(ads->ctl7) = val;
49035 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
49036- ACCESS_ONCE(ads->ctl9) = val;
49037+ ACCESS_ONCE_RW(ads->ctl9) = val;
49038
49039 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
49040- ACCESS_ONCE(ads->ctl10) = checksum;
49041+ ACCESS_ONCE_RW(ads->ctl10) = checksum;
49042
49043 if (i->is_first || i->is_last) {
49044- ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
49045+ ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
49046 | set11nTries(i->rates, 1)
49047 | set11nTries(i->rates, 2)
49048 | set11nTries(i->rates, 3)
49049 | (i->dur_update ? AR_DurUpdateEna : 0)
49050 | SM(0, AR_BurstDur);
49051
49052- ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
49053+ ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
49054 | set11nRate(i->rates, 1)
49055 | set11nRate(i->rates, 2)
49056 | set11nRate(i->rates, 3);
49057 } else {
49058- ACCESS_ONCE(ads->ctl13) = 0;
49059- ACCESS_ONCE(ads->ctl14) = 0;
49060+ ACCESS_ONCE_RW(ads->ctl13) = 0;
49061+ ACCESS_ONCE_RW(ads->ctl14) = 0;
49062 }
49063
49064 ads->ctl20 = 0;
49065@@ -89,17 +89,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
49066
49067 ctl17 = SM(i->keytype, AR_EncrType);
49068 if (!i->is_first) {
49069- ACCESS_ONCE(ads->ctl11) = 0;
49070- ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
49071- ACCESS_ONCE(ads->ctl15) = 0;
49072- ACCESS_ONCE(ads->ctl16) = 0;
49073- ACCESS_ONCE(ads->ctl17) = ctl17;
49074- ACCESS_ONCE(ads->ctl18) = 0;
49075- ACCESS_ONCE(ads->ctl19) = 0;
49076+ ACCESS_ONCE_RW(ads->ctl11) = 0;
49077+ ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
49078+ ACCESS_ONCE_RW(ads->ctl15) = 0;
49079+ ACCESS_ONCE_RW(ads->ctl16) = 0;
49080+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
49081+ ACCESS_ONCE_RW(ads->ctl18) = 0;
49082+ ACCESS_ONCE_RW(ads->ctl19) = 0;
49083 return;
49084 }
49085
49086- ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
49087+ ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
49088 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
49089 | SM(i->txpower, AR_XmitPower0)
49090 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
49091@@ -135,26 +135,26 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
49092 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
49093 ctl12 |= SM(val, AR_PAPRDChainMask);
49094
49095- ACCESS_ONCE(ads->ctl12) = ctl12;
49096- ACCESS_ONCE(ads->ctl17) = ctl17;
49097+ ACCESS_ONCE_RW(ads->ctl12) = ctl12;
49098+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
49099
49100- ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
49101+ ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
49102 | set11nPktDurRTSCTS(i->rates, 1);
49103
49104- ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
49105+ ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
49106 | set11nPktDurRTSCTS(i->rates, 3);
49107
49108- ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
49109+ ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
49110 | set11nRateFlags(i->rates, 1)
49111 | set11nRateFlags(i->rates, 2)
49112 | set11nRateFlags(i->rates, 3)
49113 | SM(i->rtscts_rate, AR_RTSCTSRate);
49114
49115- ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
49116+ ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
49117
49118- ACCESS_ONCE(ads->ctl20) = SM(i->txpower, AR_XmitPower1);
49119- ACCESS_ONCE(ads->ctl21) = SM(i->txpower, AR_XmitPower2);
49120- ACCESS_ONCE(ads->ctl22) = SM(i->txpower, AR_XmitPower3);
49121+ ACCESS_ONCE_RW(ads->ctl20) = SM(i->txpower, AR_XmitPower1);
49122+ ACCESS_ONCE_RW(ads->ctl21) = SM(i->txpower, AR_XmitPower2);
49123+ ACCESS_ONCE_RW(ads->ctl22) = SM(i->txpower, AR_XmitPower3);
49124 }
49125
49126 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
49127diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
49128index e8e8dd2..030f80e 100644
49129--- a/drivers/net/wireless/ath/ath9k/hw.h
49130+++ b/drivers/net/wireless/ath/ath9k/hw.h
49131@@ -630,7 +630,7 @@ struct ath_hw_private_ops {
49132
49133 /* ANI */
49134 void (*ani_cache_ini_regs)(struct ath_hw *ah);
49135-};
49136+} __no_const;
49137
49138 /**
49139 * struct ath_spec_scan - parameters for Atheros spectral scan
49140@@ -708,7 +708,7 @@ struct ath_hw_ops {
49141 #ifdef CONFIG_ATH9K_BTCOEX_SUPPORT
49142 void (*set_bt_ant_diversity)(struct ath_hw *hw, bool enable);
49143 #endif
49144-};
49145+} __no_const;
49146
49147 struct ath_nf_limits {
49148 s16 max;
49149diff --git a/drivers/net/wireless/ath/ath9k/main.c b/drivers/net/wireless/ath/ath9k/main.c
49150index 4f18a6b..b07d92f 100644
49151--- a/drivers/net/wireless/ath/ath9k/main.c
49152+++ b/drivers/net/wireless/ath/ath9k/main.c
49153@@ -2454,16 +2454,18 @@ void ath9k_fill_chanctx_ops(void)
49154 if (!ath9k_is_chanctx_enabled())
49155 return;
49156
49157- ath9k_ops.hw_scan = ath9k_hw_scan;
49158- ath9k_ops.cancel_hw_scan = ath9k_cancel_hw_scan;
49159- ath9k_ops.remain_on_channel = ath9k_remain_on_channel;
49160- ath9k_ops.cancel_remain_on_channel = ath9k_cancel_remain_on_channel;
49161- ath9k_ops.add_chanctx = ath9k_add_chanctx;
49162- ath9k_ops.remove_chanctx = ath9k_remove_chanctx;
49163- ath9k_ops.change_chanctx = ath9k_change_chanctx;
49164- ath9k_ops.assign_vif_chanctx = ath9k_assign_vif_chanctx;
49165- ath9k_ops.unassign_vif_chanctx = ath9k_unassign_vif_chanctx;
49166- ath9k_ops.mgd_prepare_tx = ath9k_mgd_prepare_tx;
49167+ pax_open_kernel();
49168+ *(void **)&ath9k_ops.hw_scan = ath9k_hw_scan;
49169+ *(void **)&ath9k_ops.cancel_hw_scan = ath9k_cancel_hw_scan;
49170+ *(void **)&ath9k_ops.remain_on_channel = ath9k_remain_on_channel;
49171+ *(void **)&ath9k_ops.cancel_remain_on_channel = ath9k_cancel_remain_on_channel;
49172+ *(void **)&ath9k_ops.add_chanctx = ath9k_add_chanctx;
49173+ *(void **)&ath9k_ops.remove_chanctx = ath9k_remove_chanctx;
49174+ *(void **)&ath9k_ops.change_chanctx = ath9k_change_chanctx;
49175+ *(void **)&ath9k_ops.assign_vif_chanctx = ath9k_assign_vif_chanctx;
49176+ *(void **)&ath9k_ops.unassign_vif_chanctx = ath9k_unassign_vif_chanctx;
49177+ *(void **)&ath9k_ops.mgd_prepare_tx = ath9k_mgd_prepare_tx;
49178+ pax_close_kernel();
49179 }
49180
49181 #endif
49182diff --git a/drivers/net/wireless/b43/phy_lp.c b/drivers/net/wireless/b43/phy_lp.c
49183index 058a9f2..d5cb1ba 100644
49184--- a/drivers/net/wireless/b43/phy_lp.c
49185+++ b/drivers/net/wireless/b43/phy_lp.c
49186@@ -2502,7 +2502,7 @@ static int lpphy_b2063_tune(struct b43_wldev *dev,
49187 {
49188 struct ssb_bus *bus = dev->dev->sdev->bus;
49189
49190- static const struct b206x_channel *chandata = NULL;
49191+ const struct b206x_channel *chandata = NULL;
49192 u32 crystal_freq = bus->chipco.pmu.crystalfreq * 1000;
49193 u32 freqref, vco_freq, val1, val2, val3, timeout, timeoutref, count;
49194 u16 old_comm15, scale;
49195diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
49196index dc1d20c..f7a4f06 100644
49197--- a/drivers/net/wireless/iwlegacy/3945-mac.c
49198+++ b/drivers/net/wireless/iwlegacy/3945-mac.c
49199@@ -3633,7 +3633,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
49200 */
49201 if (il3945_mod_params.disable_hw_scan) {
49202 D_INFO("Disabling hw_scan\n");
49203- il3945_mac_ops.hw_scan = NULL;
49204+ pax_open_kernel();
49205+ *(void **)&il3945_mac_ops.hw_scan = NULL;
49206+ pax_close_kernel();
49207 }
49208
49209 D_INFO("*** LOAD DRIVER ***\n");
49210diff --git a/drivers/net/wireless/iwlwifi/dvm/debugfs.c b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
49211index 0ffb6ff..c0b7f0e 100644
49212--- a/drivers/net/wireless/iwlwifi/dvm/debugfs.c
49213+++ b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
49214@@ -188,7 +188,7 @@ static ssize_t iwl_dbgfs_sram_write(struct file *file,
49215 {
49216 struct iwl_priv *priv = file->private_data;
49217 char buf[64];
49218- int buf_size;
49219+ size_t buf_size;
49220 u32 offset, len;
49221
49222 memset(buf, 0, sizeof(buf));
49223@@ -458,7 +458,7 @@ static ssize_t iwl_dbgfs_rx_handlers_write(struct file *file,
49224 struct iwl_priv *priv = file->private_data;
49225
49226 char buf[8];
49227- int buf_size;
49228+ size_t buf_size;
49229 u32 reset_flag;
49230
49231 memset(buf, 0, sizeof(buf));
49232@@ -539,7 +539,7 @@ static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
49233 {
49234 struct iwl_priv *priv = file->private_data;
49235 char buf[8];
49236- int buf_size;
49237+ size_t buf_size;
49238 int ht40;
49239
49240 memset(buf, 0, sizeof(buf));
49241@@ -591,7 +591,7 @@ static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file,
49242 {
49243 struct iwl_priv *priv = file->private_data;
49244 char buf[8];
49245- int buf_size;
49246+ size_t buf_size;
49247 int value;
49248
49249 memset(buf, 0, sizeof(buf));
49250@@ -683,10 +683,10 @@ DEBUGFS_READ_FILE_OPS(temperature);
49251 DEBUGFS_READ_WRITE_FILE_OPS(sleep_level_override);
49252 DEBUGFS_READ_FILE_OPS(current_sleep_command);
49253
49254-static const char *fmt_value = " %-30s %10u\n";
49255-static const char *fmt_hex = " %-30s 0x%02X\n";
49256-static const char *fmt_table = " %-30s %10u %10u %10u %10u\n";
49257-static const char *fmt_header =
49258+static const char fmt_value[] = " %-30s %10u\n";
49259+static const char fmt_hex[] = " %-30s 0x%02X\n";
49260+static const char fmt_table[] = " %-30s %10u %10u %10u %10u\n";
49261+static const char fmt_header[] =
49262 "%-32s current cumulative delta max\n";
49263
49264 static int iwl_statistics_flag(struct iwl_priv *priv, char *buf, int bufsz)
49265@@ -1856,7 +1856,7 @@ static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
49266 {
49267 struct iwl_priv *priv = file->private_data;
49268 char buf[8];
49269- int buf_size;
49270+ size_t buf_size;
49271 int clear;
49272
49273 memset(buf, 0, sizeof(buf));
49274@@ -1901,7 +1901,7 @@ static ssize_t iwl_dbgfs_ucode_tracing_write(struct file *file,
49275 {
49276 struct iwl_priv *priv = file->private_data;
49277 char buf[8];
49278- int buf_size;
49279+ size_t buf_size;
49280 int trace;
49281
49282 memset(buf, 0, sizeof(buf));
49283@@ -1972,7 +1972,7 @@ static ssize_t iwl_dbgfs_missed_beacon_write(struct file *file,
49284 {
49285 struct iwl_priv *priv = file->private_data;
49286 char buf[8];
49287- int buf_size;
49288+ size_t buf_size;
49289 int missed;
49290
49291 memset(buf, 0, sizeof(buf));
49292@@ -2013,7 +2013,7 @@ static ssize_t iwl_dbgfs_plcp_delta_write(struct file *file,
49293
49294 struct iwl_priv *priv = file->private_data;
49295 char buf[8];
49296- int buf_size;
49297+ size_t buf_size;
49298 int plcp;
49299
49300 memset(buf, 0, sizeof(buf));
49301@@ -2073,7 +2073,7 @@ static ssize_t iwl_dbgfs_txfifo_flush_write(struct file *file,
49302
49303 struct iwl_priv *priv = file->private_data;
49304 char buf[8];
49305- int buf_size;
49306+ size_t buf_size;
49307 int flush;
49308
49309 memset(buf, 0, sizeof(buf));
49310@@ -2163,7 +2163,7 @@ static ssize_t iwl_dbgfs_protection_mode_write(struct file *file,
49311
49312 struct iwl_priv *priv = file->private_data;
49313 char buf[8];
49314- int buf_size;
49315+ size_t buf_size;
49316 int rts;
49317
49318 if (!priv->cfg->ht_params)
49319@@ -2204,7 +2204,7 @@ static ssize_t iwl_dbgfs_echo_test_write(struct file *file,
49320 {
49321 struct iwl_priv *priv = file->private_data;
49322 char buf[8];
49323- int buf_size;
49324+ size_t buf_size;
49325
49326 memset(buf, 0, sizeof(buf));
49327 buf_size = min(count, sizeof(buf) - 1);
49328@@ -2238,7 +2238,7 @@ static ssize_t iwl_dbgfs_log_event_write(struct file *file,
49329 struct iwl_priv *priv = file->private_data;
49330 u32 event_log_flag;
49331 char buf[8];
49332- int buf_size;
49333+ size_t buf_size;
49334
49335 /* check that the interface is up */
49336 if (!iwl_is_ready(priv))
49337@@ -2292,7 +2292,7 @@ static ssize_t iwl_dbgfs_calib_disabled_write(struct file *file,
49338 struct iwl_priv *priv = file->private_data;
49339 char buf[8];
49340 u32 calib_disabled;
49341- int buf_size;
49342+ size_t buf_size;
49343
49344 memset(buf, 0, sizeof(buf));
49345 buf_size = min(count, sizeof(buf) - 1);
49346diff --git a/drivers/net/wireless/iwlwifi/pcie/trans.c b/drivers/net/wireless/iwlwifi/pcie/trans.c
49347index dd2f3f8..fb1ae88 100644
49348--- a/drivers/net/wireless/iwlwifi/pcie/trans.c
49349+++ b/drivers/net/wireless/iwlwifi/pcie/trans.c
49350@@ -1689,7 +1689,7 @@ static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
49351 struct isr_statistics *isr_stats = &trans_pcie->isr_stats;
49352
49353 char buf[8];
49354- int buf_size;
49355+ size_t buf_size;
49356 u32 reset_flag;
49357
49358 memset(buf, 0, sizeof(buf));
49359@@ -1710,7 +1710,7 @@ static ssize_t iwl_dbgfs_csr_write(struct file *file,
49360 {
49361 struct iwl_trans *trans = file->private_data;
49362 char buf[8];
49363- int buf_size;
49364+ size_t buf_size;
49365 int csr;
49366
49367 memset(buf, 0, sizeof(buf));
49368diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
49369index c9ad4cf..49a2fa0 100644
49370--- a/drivers/net/wireless/mac80211_hwsim.c
49371+++ b/drivers/net/wireless/mac80211_hwsim.c
49372@@ -2577,20 +2577,20 @@ static int __init init_mac80211_hwsim(void)
49373 if (channels < 1)
49374 return -EINVAL;
49375
49376- mac80211_hwsim_mchan_ops = mac80211_hwsim_ops;
49377- mac80211_hwsim_mchan_ops.hw_scan = mac80211_hwsim_hw_scan;
49378- mac80211_hwsim_mchan_ops.cancel_hw_scan = mac80211_hwsim_cancel_hw_scan;
49379- mac80211_hwsim_mchan_ops.sw_scan_start = NULL;
49380- mac80211_hwsim_mchan_ops.sw_scan_complete = NULL;
49381- mac80211_hwsim_mchan_ops.remain_on_channel = mac80211_hwsim_roc;
49382- mac80211_hwsim_mchan_ops.cancel_remain_on_channel = mac80211_hwsim_croc;
49383- mac80211_hwsim_mchan_ops.add_chanctx = mac80211_hwsim_add_chanctx;
49384- mac80211_hwsim_mchan_ops.remove_chanctx = mac80211_hwsim_remove_chanctx;
49385- mac80211_hwsim_mchan_ops.change_chanctx = mac80211_hwsim_change_chanctx;
49386- mac80211_hwsim_mchan_ops.assign_vif_chanctx =
49387- mac80211_hwsim_assign_vif_chanctx;
49388- mac80211_hwsim_mchan_ops.unassign_vif_chanctx =
49389- mac80211_hwsim_unassign_vif_chanctx;
49390+ pax_open_kernel();
49391+ memcpy((void *)&mac80211_hwsim_mchan_ops, &mac80211_hwsim_ops, sizeof mac80211_hwsim_mchan_ops);
49392+ *(void **)&mac80211_hwsim_mchan_ops.hw_scan = mac80211_hwsim_hw_scan;
49393+ *(void **)&mac80211_hwsim_mchan_ops.cancel_hw_scan = mac80211_hwsim_cancel_hw_scan;
49394+ *(void **)&mac80211_hwsim_mchan_ops.sw_scan_start = NULL;
49395+ *(void **)&mac80211_hwsim_mchan_ops.sw_scan_complete = NULL;
49396+ *(void **)&mac80211_hwsim_mchan_ops.remain_on_channel = mac80211_hwsim_roc;
49397+ *(void **)&mac80211_hwsim_mchan_ops.cancel_remain_on_channel = mac80211_hwsim_croc;
49398+ *(void **)&mac80211_hwsim_mchan_ops.add_chanctx = mac80211_hwsim_add_chanctx;
49399+ *(void **)&mac80211_hwsim_mchan_ops.remove_chanctx = mac80211_hwsim_remove_chanctx;
49400+ *(void **)&mac80211_hwsim_mchan_ops.change_chanctx = mac80211_hwsim_change_chanctx;
49401+ *(void **)&mac80211_hwsim_mchan_ops.assign_vif_chanctx = mac80211_hwsim_assign_vif_chanctx;
49402+ *(void **)&mac80211_hwsim_mchan_ops.unassign_vif_chanctx = mac80211_hwsim_unassign_vif_chanctx;
49403+ pax_close_kernel();
49404
49405 spin_lock_init(&hwsim_radio_lock);
49406 INIT_LIST_HEAD(&hwsim_radios);
49407diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
49408index 1a4facd..a2ecbbd 100644
49409--- a/drivers/net/wireless/rndis_wlan.c
49410+++ b/drivers/net/wireless/rndis_wlan.c
49411@@ -1236,7 +1236,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
49412
49413 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
49414
49415- if (rts_threshold < 0 || rts_threshold > 2347)
49416+ if (rts_threshold > 2347)
49417 rts_threshold = 2347;
49418
49419 tmp = cpu_to_le32(rts_threshold);
49420diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
49421index d13f25c..2573994 100644
49422--- a/drivers/net/wireless/rt2x00/rt2x00.h
49423+++ b/drivers/net/wireless/rt2x00/rt2x00.h
49424@@ -375,7 +375,7 @@ struct rt2x00_intf {
49425 * for hardware which doesn't support hardware
49426 * sequence counting.
49427 */
49428- atomic_t seqno;
49429+ atomic_unchecked_t seqno;
49430 };
49431
49432 static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
49433diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.c b/drivers/net/wireless/rt2x00/rt2x00queue.c
49434index 66ff364..3ce34f7 100644
49435--- a/drivers/net/wireless/rt2x00/rt2x00queue.c
49436+++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
49437@@ -224,9 +224,9 @@ static void rt2x00queue_create_tx_descriptor_seq(struct rt2x00_dev *rt2x00dev,
49438 * sequence counter given by mac80211.
49439 */
49440 if (test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags))
49441- seqno = atomic_add_return(0x10, &intf->seqno);
49442+ seqno = atomic_add_return_unchecked(0x10, &intf->seqno);
49443 else
49444- seqno = atomic_read(&intf->seqno);
49445+ seqno = atomic_read_unchecked(&intf->seqno);
49446
49447 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
49448 hdr->seq_ctrl |= cpu_to_le16(seqno);
49449diff --git a/drivers/net/wireless/ti/wl1251/sdio.c b/drivers/net/wireless/ti/wl1251/sdio.c
49450index b661f896..ddf7d2b 100644
49451--- a/drivers/net/wireless/ti/wl1251/sdio.c
49452+++ b/drivers/net/wireless/ti/wl1251/sdio.c
49453@@ -282,13 +282,17 @@ static int wl1251_sdio_probe(struct sdio_func *func,
49454
49455 irq_set_irq_type(wl->irq, IRQ_TYPE_EDGE_RISING);
49456
49457- wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
49458- wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
49459+ pax_open_kernel();
49460+ *(void **)&wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
49461+ *(void **)&wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
49462+ pax_close_kernel();
49463
49464 wl1251_info("using dedicated interrupt line");
49465 } else {
49466- wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
49467- wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
49468+ pax_open_kernel();
49469+ *(void **)&wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
49470+ *(void **)&wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
49471+ pax_close_kernel();
49472
49473 wl1251_info("using SDIO interrupt");
49474 }
49475diff --git a/drivers/net/wireless/ti/wl12xx/main.c b/drivers/net/wireless/ti/wl12xx/main.c
49476index 0bccf12..3d95068 100644
49477--- a/drivers/net/wireless/ti/wl12xx/main.c
49478+++ b/drivers/net/wireless/ti/wl12xx/main.c
49479@@ -656,7 +656,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
49480 sizeof(wl->conf.mem));
49481
49482 /* read data preparation is only needed by wl127x */
49483- wl->ops->prepare_read = wl127x_prepare_read;
49484+ pax_open_kernel();
49485+ *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
49486+ pax_close_kernel();
49487
49488 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
49489 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
49490@@ -681,7 +683,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
49491 sizeof(wl->conf.mem));
49492
49493 /* read data preparation is only needed by wl127x */
49494- wl->ops->prepare_read = wl127x_prepare_read;
49495+ pax_open_kernel();
49496+ *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
49497+ pax_close_kernel();
49498
49499 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
49500 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
49501diff --git a/drivers/net/wireless/ti/wl18xx/main.c b/drivers/net/wireless/ti/wl18xx/main.c
49502index 7af1936..128bb35 100644
49503--- a/drivers/net/wireless/ti/wl18xx/main.c
49504+++ b/drivers/net/wireless/ti/wl18xx/main.c
49505@@ -1916,8 +1916,10 @@ static int wl18xx_setup(struct wl1271 *wl)
49506 }
49507
49508 if (!checksum_param) {
49509- wl18xx_ops.set_rx_csum = NULL;
49510- wl18xx_ops.init_vif = NULL;
49511+ pax_open_kernel();
49512+ *(void **)&wl18xx_ops.set_rx_csum = NULL;
49513+ *(void **)&wl18xx_ops.init_vif = NULL;
49514+ pax_close_kernel();
49515 }
49516
49517 /* Enable 11a Band only if we have 5G antennas */
49518diff --git a/drivers/net/wireless/zd1211rw/zd_usb.c b/drivers/net/wireless/zd1211rw/zd_usb.c
49519index a912dc0..a8225ba 100644
49520--- a/drivers/net/wireless/zd1211rw/zd_usb.c
49521+++ b/drivers/net/wireless/zd1211rw/zd_usb.c
49522@@ -385,7 +385,7 @@ static inline void handle_regs_int(struct urb *urb)
49523 {
49524 struct zd_usb *usb = urb->context;
49525 struct zd_usb_interrupt *intr = &usb->intr;
49526- int len;
49527+ unsigned int len;
49528 u16 int_num;
49529
49530 ZD_ASSERT(in_interrupt());
49531diff --git a/drivers/nfc/nfcwilink.c b/drivers/nfc/nfcwilink.c
49532index 683671a..4519fc2 100644
49533--- a/drivers/nfc/nfcwilink.c
49534+++ b/drivers/nfc/nfcwilink.c
49535@@ -497,7 +497,7 @@ static struct nci_ops nfcwilink_ops = {
49536
49537 static int nfcwilink_probe(struct platform_device *pdev)
49538 {
49539- static struct nfcwilink *drv;
49540+ struct nfcwilink *drv;
49541 int rc;
49542 __u32 protocols;
49543
49544diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
49545index d93b2b6..ae50401 100644
49546--- a/drivers/oprofile/buffer_sync.c
49547+++ b/drivers/oprofile/buffer_sync.c
49548@@ -332,7 +332,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
49549 if (cookie == NO_COOKIE)
49550 offset = pc;
49551 if (cookie == INVALID_COOKIE) {
49552- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
49553+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
49554 offset = pc;
49555 }
49556 if (cookie != last_cookie) {
49557@@ -376,14 +376,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
49558 /* add userspace sample */
49559
49560 if (!mm) {
49561- atomic_inc(&oprofile_stats.sample_lost_no_mm);
49562+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
49563 return 0;
49564 }
49565
49566 cookie = lookup_dcookie(mm, s->eip, &offset);
49567
49568 if (cookie == INVALID_COOKIE) {
49569- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
49570+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
49571 return 0;
49572 }
49573
49574@@ -552,7 +552,7 @@ void sync_buffer(int cpu)
49575 /* ignore backtraces if failed to add a sample */
49576 if (state == sb_bt_start) {
49577 state = sb_bt_ignore;
49578- atomic_inc(&oprofile_stats.bt_lost_no_mapping);
49579+ atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
49580 }
49581 }
49582 release_mm(mm);
49583diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
49584index c0cc4e7..44d4e54 100644
49585--- a/drivers/oprofile/event_buffer.c
49586+++ b/drivers/oprofile/event_buffer.c
49587@@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
49588 }
49589
49590 if (buffer_pos == buffer_size) {
49591- atomic_inc(&oprofile_stats.event_lost_overflow);
49592+ atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
49593 return;
49594 }
49595
49596diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
49597index ed2c3ec..deda85a 100644
49598--- a/drivers/oprofile/oprof.c
49599+++ b/drivers/oprofile/oprof.c
49600@@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
49601 if (oprofile_ops.switch_events())
49602 return;
49603
49604- atomic_inc(&oprofile_stats.multiplex_counter);
49605+ atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
49606 start_switch_worker();
49607 }
49608
49609diff --git a/drivers/oprofile/oprofile_files.c b/drivers/oprofile/oprofile_files.c
49610index ee2cfce..7f8f699 100644
49611--- a/drivers/oprofile/oprofile_files.c
49612+++ b/drivers/oprofile/oprofile_files.c
49613@@ -27,7 +27,7 @@ unsigned long oprofile_time_slice;
49614
49615 #ifdef CONFIG_OPROFILE_EVENT_MULTIPLEX
49616
49617-static ssize_t timeout_read(struct file *file, char __user *buf,
49618+static ssize_t __intentional_overflow(-1) timeout_read(struct file *file, char __user *buf,
49619 size_t count, loff_t *offset)
49620 {
49621 return oprofilefs_ulong_to_user(jiffies_to_msecs(oprofile_time_slice),
49622diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
49623index 59659ce..6c860a0 100644
49624--- a/drivers/oprofile/oprofile_stats.c
49625+++ b/drivers/oprofile/oprofile_stats.c
49626@@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
49627 cpu_buf->sample_invalid_eip = 0;
49628 }
49629
49630- atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
49631- atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
49632- atomic_set(&oprofile_stats.event_lost_overflow, 0);
49633- atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
49634- atomic_set(&oprofile_stats.multiplex_counter, 0);
49635+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
49636+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
49637+ atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
49638+ atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
49639+ atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
49640 }
49641
49642
49643diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
49644index 1fc622b..8c48fc3 100644
49645--- a/drivers/oprofile/oprofile_stats.h
49646+++ b/drivers/oprofile/oprofile_stats.h
49647@@ -13,11 +13,11 @@
49648 #include <linux/atomic.h>
49649
49650 struct oprofile_stat_struct {
49651- atomic_t sample_lost_no_mm;
49652- atomic_t sample_lost_no_mapping;
49653- atomic_t bt_lost_no_mapping;
49654- atomic_t event_lost_overflow;
49655- atomic_t multiplex_counter;
49656+ atomic_unchecked_t sample_lost_no_mm;
49657+ atomic_unchecked_t sample_lost_no_mapping;
49658+ atomic_unchecked_t bt_lost_no_mapping;
49659+ atomic_unchecked_t event_lost_overflow;
49660+ atomic_unchecked_t multiplex_counter;
49661 };
49662
49663 extern struct oprofile_stat_struct oprofile_stats;
49664diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
49665index 3f49345..c750d0b 100644
49666--- a/drivers/oprofile/oprofilefs.c
49667+++ b/drivers/oprofile/oprofilefs.c
49668@@ -176,8 +176,8 @@ int oprofilefs_create_ro_ulong(struct dentry *root,
49669
49670 static ssize_t atomic_read_file(struct file *file, char __user *buf, size_t count, loff_t *offset)
49671 {
49672- atomic_t *val = file->private_data;
49673- return oprofilefs_ulong_to_user(atomic_read(val), buf, count, offset);
49674+ atomic_unchecked_t *val = file->private_data;
49675+ return oprofilefs_ulong_to_user(atomic_read_unchecked(val), buf, count, offset);
49676 }
49677
49678
49679@@ -189,7 +189,7 @@ static const struct file_operations atomic_ro_fops = {
49680
49681
49682 int oprofilefs_create_ro_atomic(struct dentry *root,
49683- char const *name, atomic_t *val)
49684+ char const *name, atomic_unchecked_t *val)
49685 {
49686 return __oprofilefs_create_file(root, name,
49687 &atomic_ro_fops, 0444, val);
49688diff --git a/drivers/oprofile/timer_int.c b/drivers/oprofile/timer_int.c
49689index bdef916..88c7dee 100644
49690--- a/drivers/oprofile/timer_int.c
49691+++ b/drivers/oprofile/timer_int.c
49692@@ -93,7 +93,7 @@ static int oprofile_cpu_notify(struct notifier_block *self,
49693 return NOTIFY_OK;
49694 }
49695
49696-static struct notifier_block __refdata oprofile_cpu_notifier = {
49697+static struct notifier_block oprofile_cpu_notifier = {
49698 .notifier_call = oprofile_cpu_notify,
49699 };
49700
49701diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
49702index 3b47080..6cd05dd 100644
49703--- a/drivers/parport/procfs.c
49704+++ b/drivers/parport/procfs.c
49705@@ -64,7 +64,7 @@ static int do_active_device(struct ctl_table *table, int write,
49706
49707 *ppos += len;
49708
49709- return copy_to_user(result, buffer, len) ? -EFAULT : 0;
49710+ return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
49711 }
49712
49713 #ifdef CONFIG_PARPORT_1284
49714@@ -106,7 +106,7 @@ static int do_autoprobe(struct ctl_table *table, int write,
49715
49716 *ppos += len;
49717
49718- return copy_to_user (result, buffer, len) ? -EFAULT : 0;
49719+ return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
49720 }
49721 #endif /* IEEE1284.3 support. */
49722
49723diff --git a/drivers/pci/hotplug/acpiphp_ibm.c b/drivers/pci/hotplug/acpiphp_ibm.c
49724index 6ca2399..68d866b 100644
49725--- a/drivers/pci/hotplug/acpiphp_ibm.c
49726+++ b/drivers/pci/hotplug/acpiphp_ibm.c
49727@@ -452,7 +452,9 @@ static int __init ibm_acpiphp_init(void)
49728 goto init_cleanup;
49729 }
49730
49731- ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
49732+ pax_open_kernel();
49733+ *(size_t *)&ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
49734+ pax_close_kernel();
49735 retval = sysfs_create_bin_file(sysdir, &ibm_apci_table_attr);
49736
49737 return retval;
49738diff --git a/drivers/pci/hotplug/cpcihp_generic.c b/drivers/pci/hotplug/cpcihp_generic.c
49739index 66b7bbe..26bee78 100644
49740--- a/drivers/pci/hotplug/cpcihp_generic.c
49741+++ b/drivers/pci/hotplug/cpcihp_generic.c
49742@@ -73,7 +73,6 @@ static u16 port;
49743 static unsigned int enum_bit;
49744 static u8 enum_mask;
49745
49746-static struct cpci_hp_controller_ops generic_hpc_ops;
49747 static struct cpci_hp_controller generic_hpc;
49748
49749 static int __init validate_parameters(void)
49750@@ -139,6 +138,10 @@ static int query_enum(void)
49751 return ((value & enum_mask) == enum_mask);
49752 }
49753
49754+static struct cpci_hp_controller_ops generic_hpc_ops = {
49755+ .query_enum = query_enum,
49756+};
49757+
49758 static int __init cpcihp_generic_init(void)
49759 {
49760 int status;
49761@@ -165,7 +168,6 @@ static int __init cpcihp_generic_init(void)
49762 pci_dev_put(dev);
49763
49764 memset(&generic_hpc, 0, sizeof (struct cpci_hp_controller));
49765- generic_hpc_ops.query_enum = query_enum;
49766 generic_hpc.ops = &generic_hpc_ops;
49767
49768 status = cpci_hp_register_controller(&generic_hpc);
49769diff --git a/drivers/pci/hotplug/cpcihp_zt5550.c b/drivers/pci/hotplug/cpcihp_zt5550.c
49770index 7ecf34e..effed62 100644
49771--- a/drivers/pci/hotplug/cpcihp_zt5550.c
49772+++ b/drivers/pci/hotplug/cpcihp_zt5550.c
49773@@ -59,7 +59,6 @@
49774 /* local variables */
49775 static bool debug;
49776 static bool poll;
49777-static struct cpci_hp_controller_ops zt5550_hpc_ops;
49778 static struct cpci_hp_controller zt5550_hpc;
49779
49780 /* Primary cPCI bus bridge device */
49781@@ -204,6 +203,10 @@ static int zt5550_hc_disable_irq(void)
49782 return 0;
49783 }
49784
49785+static struct cpci_hp_controller_ops zt5550_hpc_ops = {
49786+ .query_enum = zt5550_hc_query_enum,
49787+};
49788+
49789 static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
49790 {
49791 int status;
49792@@ -215,16 +218,17 @@ static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id
49793 dbg("returned from zt5550_hc_config");
49794
49795 memset(&zt5550_hpc, 0, sizeof (struct cpci_hp_controller));
49796- zt5550_hpc_ops.query_enum = zt5550_hc_query_enum;
49797 zt5550_hpc.ops = &zt5550_hpc_ops;
49798 if (!poll) {
49799 zt5550_hpc.irq = hc_dev->irq;
49800 zt5550_hpc.irq_flags = IRQF_SHARED;
49801 zt5550_hpc.dev_id = hc_dev;
49802
49803- zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
49804- zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
49805- zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
49806+ pax_open_kernel();
49807+ *(void **)&zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
49808+ *(void **)&zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
49809+ *(void **)&zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
49810+ pax_open_kernel();
49811 } else {
49812 info("using ENUM# polling mode");
49813 }
49814diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
49815index 1e08ff8c..3cd145f 100644
49816--- a/drivers/pci/hotplug/cpqphp_nvram.c
49817+++ b/drivers/pci/hotplug/cpqphp_nvram.c
49818@@ -425,8 +425,10 @@ static u32 store_HRT (void __iomem *rom_start)
49819
49820 void compaq_nvram_init (void __iomem *rom_start)
49821 {
49822+#ifndef CONFIG_PAX_KERNEXEC
49823 if (rom_start)
49824 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
49825+#endif
49826
49827 dbg("int15 entry = %p\n", compaq_int15_entry_point);
49828
49829diff --git a/drivers/pci/hotplug/pci_hotplug_core.c b/drivers/pci/hotplug/pci_hotplug_core.c
49830index 56d8486..f26113f 100644
49831--- a/drivers/pci/hotplug/pci_hotplug_core.c
49832+++ b/drivers/pci/hotplug/pci_hotplug_core.c
49833@@ -436,8 +436,10 @@ int __pci_hp_register(struct hotplug_slot *slot, struct pci_bus *bus,
49834 return -EINVAL;
49835 }
49836
49837- slot->ops->owner = owner;
49838- slot->ops->mod_name = mod_name;
49839+ pax_open_kernel();
49840+ *(struct module **)&slot->ops->owner = owner;
49841+ *(const char **)&slot->ops->mod_name = mod_name;
49842+ pax_close_kernel();
49843
49844 mutex_lock(&pci_hp_mutex);
49845 /*
49846diff --git a/drivers/pci/hotplug/pciehp_core.c b/drivers/pci/hotplug/pciehp_core.c
49847index 07aa722..84514b4 100644
49848--- a/drivers/pci/hotplug/pciehp_core.c
49849+++ b/drivers/pci/hotplug/pciehp_core.c
49850@@ -92,7 +92,7 @@ static int init_slot(struct controller *ctrl)
49851 struct slot *slot = ctrl->slot;
49852 struct hotplug_slot *hotplug = NULL;
49853 struct hotplug_slot_info *info = NULL;
49854- struct hotplug_slot_ops *ops = NULL;
49855+ hotplug_slot_ops_no_const *ops = NULL;
49856 char name[SLOT_NAME_SIZE];
49857 int retval = -ENOMEM;
49858
49859diff --git a/drivers/pci/msi.c b/drivers/pci/msi.c
49860index 084587d..4a8f9df 100644
49861--- a/drivers/pci/msi.c
49862+++ b/drivers/pci/msi.c
49863@@ -488,8 +488,8 @@ static int populate_msi_sysfs(struct pci_dev *pdev)
49864 {
49865 struct attribute **msi_attrs;
49866 struct attribute *msi_attr;
49867- struct device_attribute *msi_dev_attr;
49868- struct attribute_group *msi_irq_group;
49869+ device_attribute_no_const *msi_dev_attr;
49870+ attribute_group_no_const *msi_irq_group;
49871 const struct attribute_group **msi_irq_groups;
49872 struct msi_desc *entry;
49873 int ret = -ENOMEM;
49874@@ -549,7 +549,7 @@ error_attrs:
49875 count = 0;
49876 msi_attr = msi_attrs[count];
49877 while (msi_attr) {
49878- msi_dev_attr = container_of(msi_attr, struct device_attribute, attr);
49879+ msi_dev_attr = container_of(msi_attr, device_attribute_no_const, attr);
49880 kfree(msi_attr->name);
49881 kfree(msi_dev_attr);
49882 ++count;
49883diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
49884index 2c6643f..3a6d8e0 100644
49885--- a/drivers/pci/pci-sysfs.c
49886+++ b/drivers/pci/pci-sysfs.c
49887@@ -1133,7 +1133,7 @@ static int pci_create_attr(struct pci_dev *pdev, int num, int write_combine)
49888 {
49889 /* allocate attribute structure, piggyback attribute name */
49890 int name_len = write_combine ? 13 : 10;
49891- struct bin_attribute *res_attr;
49892+ bin_attribute_no_const *res_attr;
49893 int retval;
49894
49895 res_attr = kzalloc(sizeof(*res_attr) + name_len, GFP_ATOMIC);
49896@@ -1310,7 +1310,7 @@ static struct device_attribute reset_attr = __ATTR(reset, 0200, NULL, reset_stor
49897 static int pci_create_capabilities_sysfs(struct pci_dev *dev)
49898 {
49899 int retval;
49900- struct bin_attribute *attr;
49901+ bin_attribute_no_const *attr;
49902
49903 /* If the device has VPD, try to expose it in sysfs. */
49904 if (dev->vpd) {
49905@@ -1357,7 +1357,7 @@ int __must_check pci_create_sysfs_dev_files(struct pci_dev *pdev)
49906 {
49907 int retval;
49908 int rom_size = 0;
49909- struct bin_attribute *attr;
49910+ bin_attribute_no_const *attr;
49911
49912 if (!sysfs_initialized)
49913 return -EACCES;
49914diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
49915index 4a3902d..7f1fc42 100644
49916--- a/drivers/pci/pci.h
49917+++ b/drivers/pci/pci.h
49918@@ -93,7 +93,7 @@ struct pci_vpd_ops {
49919 struct pci_vpd {
49920 unsigned int len;
49921 const struct pci_vpd_ops *ops;
49922- struct bin_attribute *attr; /* descriptor for sysfs VPD entry */
49923+ bin_attribute_no_const *attr; /* descriptor for sysfs VPD entry */
49924 };
49925
49926 int pci_vpd_pci22_init(struct pci_dev *dev);
49927diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
49928index e1e7026..d28dd33 100644
49929--- a/drivers/pci/pcie/aspm.c
49930+++ b/drivers/pci/pcie/aspm.c
49931@@ -27,9 +27,9 @@
49932 #define MODULE_PARAM_PREFIX "pcie_aspm."
49933
49934 /* Note: those are not register definitions */
49935-#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
49936-#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
49937-#define ASPM_STATE_L1 (4) /* L1 state */
49938+#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
49939+#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
49940+#define ASPM_STATE_L1 (4U) /* L1 state */
49941 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
49942 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
49943
49944diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
49945index 3010ffc..5e2e133 100644
49946--- a/drivers/pci/probe.c
49947+++ b/drivers/pci/probe.c
49948@@ -177,7 +177,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
49949 struct pci_bus_region region, inverted_region;
49950 bool bar_too_big = false, bar_too_high = false, bar_invalid = false;
49951
49952- mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
49953+ mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
49954
49955 /* No printks while decoding is disabled! */
49956 if (!dev->mmio_always_on) {
49957diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
49958index 3f155e7..0f4b1f0 100644
49959--- a/drivers/pci/proc.c
49960+++ b/drivers/pci/proc.c
49961@@ -434,7 +434,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
49962 static int __init pci_proc_init(void)
49963 {
49964 struct pci_dev *dev = NULL;
49965+
49966+#ifdef CONFIG_GRKERNSEC_PROC_ADD
49967+#ifdef CONFIG_GRKERNSEC_PROC_USER
49968+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
49969+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49970+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
49971+#endif
49972+#else
49973 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
49974+#endif
49975 proc_create("devices", 0, proc_bus_pci_dir,
49976 &proc_bus_pci_dev_operations);
49977 proc_initialized = 1;
49978diff --git a/drivers/platform/chrome/chromeos_laptop.c b/drivers/platform/chrome/chromeos_laptop.c
49979index d866db8..c827d1f 100644
49980--- a/drivers/platform/chrome/chromeos_laptop.c
49981+++ b/drivers/platform/chrome/chromeos_laptop.c
49982@@ -479,7 +479,7 @@ static struct chromeos_laptop cr48 = {
49983 .callback = chromeos_laptop_dmi_matched, \
49984 .driver_data = (void *)&board_
49985
49986-static struct dmi_system_id chromeos_laptop_dmi_table[] __initdata = {
49987+static struct dmi_system_id chromeos_laptop_dmi_table[] __initconst = {
49988 {
49989 .ident = "Samsung Series 5 550",
49990 .matches = {
49991diff --git a/drivers/platform/x86/alienware-wmi.c b/drivers/platform/x86/alienware-wmi.c
49992index c5af23b..3d62d5e 100644
49993--- a/drivers/platform/x86/alienware-wmi.c
49994+++ b/drivers/platform/x86/alienware-wmi.c
49995@@ -150,7 +150,7 @@ struct wmax_led_args {
49996 } __packed;
49997
49998 static struct platform_device *platform_device;
49999-static struct device_attribute *zone_dev_attrs;
50000+static device_attribute_no_const *zone_dev_attrs;
50001 static struct attribute **zone_attrs;
50002 static struct platform_zone *zone_data;
50003
50004@@ -161,7 +161,7 @@ static struct platform_driver platform_driver = {
50005 }
50006 };
50007
50008-static struct attribute_group zone_attribute_group = {
50009+static attribute_group_no_const zone_attribute_group = {
50010 .name = "rgb_zones",
50011 };
50012
50013diff --git a/drivers/platform/x86/asus-wmi.c b/drivers/platform/x86/asus-wmi.c
50014index 21fc932..ee9394a 100644
50015--- a/drivers/platform/x86/asus-wmi.c
50016+++ b/drivers/platform/x86/asus-wmi.c
50017@@ -1590,6 +1590,10 @@ static int show_dsts(struct seq_file *m, void *data)
50018 int err;
50019 u32 retval = -1;
50020
50021+#ifdef CONFIG_GRKERNSEC_KMEM
50022+ return -EPERM;
50023+#endif
50024+
50025 err = asus_wmi_get_devstate(asus, asus->debug.dev_id, &retval);
50026
50027 if (err < 0)
50028@@ -1606,6 +1610,10 @@ static int show_devs(struct seq_file *m, void *data)
50029 int err;
50030 u32 retval = -1;
50031
50032+#ifdef CONFIG_GRKERNSEC_KMEM
50033+ return -EPERM;
50034+#endif
50035+
50036 err = asus_wmi_set_devstate(asus->debug.dev_id, asus->debug.ctrl_param,
50037 &retval);
50038
50039@@ -1630,6 +1638,10 @@ static int show_call(struct seq_file *m, void *data)
50040 union acpi_object *obj;
50041 acpi_status status;
50042
50043+#ifdef CONFIG_GRKERNSEC_KMEM
50044+ return -EPERM;
50045+#endif
50046+
50047 status = wmi_evaluate_method(ASUS_WMI_MGMT_GUID,
50048 1, asus->debug.method_id,
50049 &input, &output);
50050diff --git a/drivers/platform/x86/msi-laptop.c b/drivers/platform/x86/msi-laptop.c
50051index 62f8030..c7f2a45 100644
50052--- a/drivers/platform/x86/msi-laptop.c
50053+++ b/drivers/platform/x86/msi-laptop.c
50054@@ -1000,12 +1000,14 @@ static int __init load_scm_model_init(struct platform_device *sdev)
50055
50056 if (!quirks->ec_read_only) {
50057 /* allow userland write sysfs file */
50058- dev_attr_bluetooth.store = store_bluetooth;
50059- dev_attr_wlan.store = store_wlan;
50060- dev_attr_threeg.store = store_threeg;
50061- dev_attr_bluetooth.attr.mode |= S_IWUSR;
50062- dev_attr_wlan.attr.mode |= S_IWUSR;
50063- dev_attr_threeg.attr.mode |= S_IWUSR;
50064+ pax_open_kernel();
50065+ *(void **)&dev_attr_bluetooth.store = store_bluetooth;
50066+ *(void **)&dev_attr_wlan.store = store_wlan;
50067+ *(void **)&dev_attr_threeg.store = store_threeg;
50068+ *(umode_t *)&dev_attr_bluetooth.attr.mode |= S_IWUSR;
50069+ *(umode_t *)&dev_attr_wlan.attr.mode |= S_IWUSR;
50070+ *(umode_t *)&dev_attr_threeg.attr.mode |= S_IWUSR;
50071+ pax_close_kernel();
50072 }
50073
50074 /* disable hardware control by fn key */
50075diff --git a/drivers/platform/x86/msi-wmi.c b/drivers/platform/x86/msi-wmi.c
50076index 70222f2..8c8ce66 100644
50077--- a/drivers/platform/x86/msi-wmi.c
50078+++ b/drivers/platform/x86/msi-wmi.c
50079@@ -183,7 +183,7 @@ static const struct backlight_ops msi_backlight_ops = {
50080 static void msi_wmi_notify(u32 value, void *context)
50081 {
50082 struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL };
50083- static struct key_entry *key;
50084+ struct key_entry *key;
50085 union acpi_object *obj;
50086 acpi_status status;
50087
50088diff --git a/drivers/platform/x86/sony-laptop.c b/drivers/platform/x86/sony-laptop.c
50089index 26ad9ff..7c52909 100644
50090--- a/drivers/platform/x86/sony-laptop.c
50091+++ b/drivers/platform/x86/sony-laptop.c
50092@@ -2527,7 +2527,7 @@ static void sony_nc_gfx_switch_cleanup(struct platform_device *pd)
50093 }
50094
50095 /* High speed charging function */
50096-static struct device_attribute *hsc_handle;
50097+static device_attribute_no_const *hsc_handle;
50098
50099 static ssize_t sony_nc_highspeed_charging_store(struct device *dev,
50100 struct device_attribute *attr,
50101@@ -2601,7 +2601,7 @@ static void sony_nc_highspeed_charging_cleanup(struct platform_device *pd)
50102 }
50103
50104 /* low battery function */
50105-static struct device_attribute *lowbatt_handle;
50106+static device_attribute_no_const *lowbatt_handle;
50107
50108 static ssize_t sony_nc_lowbatt_store(struct device *dev,
50109 struct device_attribute *attr,
50110@@ -2667,7 +2667,7 @@ static void sony_nc_lowbatt_cleanup(struct platform_device *pd)
50111 }
50112
50113 /* fan speed function */
50114-static struct device_attribute *fan_handle, *hsf_handle;
50115+static device_attribute_no_const *fan_handle, *hsf_handle;
50116
50117 static ssize_t sony_nc_hsfan_store(struct device *dev,
50118 struct device_attribute *attr,
50119@@ -2774,7 +2774,7 @@ static void sony_nc_fanspeed_cleanup(struct platform_device *pd)
50120 }
50121
50122 /* USB charge function */
50123-static struct device_attribute *uc_handle;
50124+static device_attribute_no_const *uc_handle;
50125
50126 static ssize_t sony_nc_usb_charge_store(struct device *dev,
50127 struct device_attribute *attr,
50128@@ -2848,7 +2848,7 @@ static void sony_nc_usb_charge_cleanup(struct platform_device *pd)
50129 }
50130
50131 /* Panel ID function */
50132-static struct device_attribute *panel_handle;
50133+static device_attribute_no_const *panel_handle;
50134
50135 static ssize_t sony_nc_panelid_show(struct device *dev,
50136 struct device_attribute *attr, char *buffer)
50137@@ -2895,7 +2895,7 @@ static void sony_nc_panelid_cleanup(struct platform_device *pd)
50138 }
50139
50140 /* smart connect function */
50141-static struct device_attribute *sc_handle;
50142+static device_attribute_no_const *sc_handle;
50143
50144 static ssize_t sony_nc_smart_conn_store(struct device *dev,
50145 struct device_attribute *attr,
50146diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
50147index cf0f893..5955997 100644
50148--- a/drivers/platform/x86/thinkpad_acpi.c
50149+++ b/drivers/platform/x86/thinkpad_acpi.c
50150@@ -2094,7 +2094,7 @@ static int hotkey_mask_get(void)
50151 return 0;
50152 }
50153
50154-void static hotkey_mask_warn_incomplete_mask(void)
50155+static void hotkey_mask_warn_incomplete_mask(void)
50156 {
50157 /* log only what the user can fix... */
50158 const u32 wantedmask = hotkey_driver_mask &
50159@@ -2438,10 +2438,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
50160 && !tp_features.bright_unkfw)
50161 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
50162 }
50163+}
50164
50165 #undef TPACPI_COMPARE_KEY
50166 #undef TPACPI_MAY_SEND_KEY
50167-}
50168
50169 /*
50170 * Polling driver
50171diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
50172index 438d4c7..ca8a2fb 100644
50173--- a/drivers/pnp/pnpbios/bioscalls.c
50174+++ b/drivers/pnp/pnpbios/bioscalls.c
50175@@ -59,7 +59,7 @@ do { \
50176 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
50177 } while(0)
50178
50179-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
50180+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
50181 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
50182
50183 /*
50184@@ -96,7 +96,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
50185
50186 cpu = get_cpu();
50187 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
50188+
50189+ pax_open_kernel();
50190 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
50191+ pax_close_kernel();
50192
50193 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
50194 spin_lock_irqsave(&pnp_bios_lock, flags);
50195@@ -134,7 +137,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
50196 :"memory");
50197 spin_unlock_irqrestore(&pnp_bios_lock, flags);
50198
50199+ pax_open_kernel();
50200 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
50201+ pax_close_kernel();
50202+
50203 put_cpu();
50204
50205 /* If we get here and this is set then the PnP BIOS faulted on us. */
50206@@ -468,7 +474,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
50207 return status;
50208 }
50209
50210-void pnpbios_calls_init(union pnp_bios_install_struct *header)
50211+void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
50212 {
50213 int i;
50214
50215@@ -476,6 +482,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
50216 pnp_bios_callpoint.offset = header->fields.pm16offset;
50217 pnp_bios_callpoint.segment = PNP_CS16;
50218
50219+ pax_open_kernel();
50220+
50221 for_each_possible_cpu(i) {
50222 struct desc_struct *gdt = get_cpu_gdt_table(i);
50223 if (!gdt)
50224@@ -487,4 +495,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
50225 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
50226 (unsigned long)__va(header->fields.pm16dseg));
50227 }
50228+
50229+ pax_close_kernel();
50230 }
50231diff --git a/drivers/power/pda_power.c b/drivers/power/pda_power.c
50232index 0c52e2a..3421ab7 100644
50233--- a/drivers/power/pda_power.c
50234+++ b/drivers/power/pda_power.c
50235@@ -37,7 +37,11 @@ static int polling;
50236
50237 #if IS_ENABLED(CONFIG_USB_PHY)
50238 static struct usb_phy *transceiver;
50239-static struct notifier_block otg_nb;
50240+static int otg_handle_notification(struct notifier_block *nb,
50241+ unsigned long event, void *unused);
50242+static struct notifier_block otg_nb = {
50243+ .notifier_call = otg_handle_notification
50244+};
50245 #endif
50246
50247 static struct regulator *ac_draw;
50248@@ -369,7 +373,6 @@ static int pda_power_probe(struct platform_device *pdev)
50249
50250 #if IS_ENABLED(CONFIG_USB_PHY)
50251 if (!IS_ERR_OR_NULL(transceiver) && pdata->use_otg_notifier) {
50252- otg_nb.notifier_call = otg_handle_notification;
50253 ret = usb_register_notifier(transceiver, &otg_nb);
50254 if (ret) {
50255 dev_err(dev, "failure to register otg notifier\n");
50256diff --git a/drivers/power/power_supply.h b/drivers/power/power_supply.h
50257index cc439fd..8fa30df 100644
50258--- a/drivers/power/power_supply.h
50259+++ b/drivers/power/power_supply.h
50260@@ -16,12 +16,12 @@ struct power_supply;
50261
50262 #ifdef CONFIG_SYSFS
50263
50264-extern void power_supply_init_attrs(struct device_type *dev_type);
50265+extern void power_supply_init_attrs(void);
50266 extern int power_supply_uevent(struct device *dev, struct kobj_uevent_env *env);
50267
50268 #else
50269
50270-static inline void power_supply_init_attrs(struct device_type *dev_type) {}
50271+static inline void power_supply_init_attrs(void) {}
50272 #define power_supply_uevent NULL
50273
50274 #endif /* CONFIG_SYSFS */
50275diff --git a/drivers/power/power_supply_core.c b/drivers/power/power_supply_core.c
50276index 694e8cd..9f03483 100644
50277--- a/drivers/power/power_supply_core.c
50278+++ b/drivers/power/power_supply_core.c
50279@@ -28,7 +28,10 @@ EXPORT_SYMBOL_GPL(power_supply_class);
50280 ATOMIC_NOTIFIER_HEAD(power_supply_notifier);
50281 EXPORT_SYMBOL_GPL(power_supply_notifier);
50282
50283-static struct device_type power_supply_dev_type;
50284+extern const struct attribute_group *power_supply_attr_groups[];
50285+static struct device_type power_supply_dev_type = {
50286+ .groups = power_supply_attr_groups,
50287+};
50288
50289 static bool __power_supply_is_supplied_by(struct power_supply *supplier,
50290 struct power_supply *supply)
50291@@ -637,7 +640,7 @@ static int __init power_supply_class_init(void)
50292 return PTR_ERR(power_supply_class);
50293
50294 power_supply_class->dev_uevent = power_supply_uevent;
50295- power_supply_init_attrs(&power_supply_dev_type);
50296+ power_supply_init_attrs();
50297
50298 return 0;
50299 }
50300diff --git a/drivers/power/power_supply_sysfs.c b/drivers/power/power_supply_sysfs.c
50301index 62653f5..d0bb485 100644
50302--- a/drivers/power/power_supply_sysfs.c
50303+++ b/drivers/power/power_supply_sysfs.c
50304@@ -238,17 +238,15 @@ static struct attribute_group power_supply_attr_group = {
50305 .is_visible = power_supply_attr_is_visible,
50306 };
50307
50308-static const struct attribute_group *power_supply_attr_groups[] = {
50309+const struct attribute_group *power_supply_attr_groups[] = {
50310 &power_supply_attr_group,
50311 NULL,
50312 };
50313
50314-void power_supply_init_attrs(struct device_type *dev_type)
50315+void power_supply_init_attrs(void)
50316 {
50317 int i;
50318
50319- dev_type->groups = power_supply_attr_groups;
50320-
50321 for (i = 0; i < ARRAY_SIZE(power_supply_attrs); i++)
50322 __power_supply_attrs[i] = &power_supply_attrs[i].attr;
50323 }
50324diff --git a/drivers/powercap/powercap_sys.c b/drivers/powercap/powercap_sys.c
50325index 84419af..268ede8 100644
50326--- a/drivers/powercap/powercap_sys.c
50327+++ b/drivers/powercap/powercap_sys.c
50328@@ -154,8 +154,77 @@ struct powercap_constraint_attr {
50329 struct device_attribute name_attr;
50330 };
50331
50332+static ssize_t show_constraint_name(struct device *dev,
50333+ struct device_attribute *dev_attr,
50334+ char *buf);
50335+
50336 static struct powercap_constraint_attr
50337- constraint_attrs[MAX_CONSTRAINTS_PER_ZONE];
50338+ constraint_attrs[MAX_CONSTRAINTS_PER_ZONE] = {
50339+ [0 ... MAX_CONSTRAINTS_PER_ZONE - 1] = {
50340+ .power_limit_attr = {
50341+ .attr = {
50342+ .name = NULL,
50343+ .mode = S_IWUSR | S_IRUGO
50344+ },
50345+ .show = show_constraint_power_limit_uw,
50346+ .store = store_constraint_power_limit_uw
50347+ },
50348+
50349+ .time_window_attr = {
50350+ .attr = {
50351+ .name = NULL,
50352+ .mode = S_IWUSR | S_IRUGO
50353+ },
50354+ .show = show_constraint_time_window_us,
50355+ .store = store_constraint_time_window_us
50356+ },
50357+
50358+ .max_power_attr = {
50359+ .attr = {
50360+ .name = NULL,
50361+ .mode = S_IRUGO
50362+ },
50363+ .show = show_constraint_max_power_uw,
50364+ .store = NULL
50365+ },
50366+
50367+ .min_power_attr = {
50368+ .attr = {
50369+ .name = NULL,
50370+ .mode = S_IRUGO
50371+ },
50372+ .show = show_constraint_min_power_uw,
50373+ .store = NULL
50374+ },
50375+
50376+ .max_time_window_attr = {
50377+ .attr = {
50378+ .name = NULL,
50379+ .mode = S_IRUGO
50380+ },
50381+ .show = show_constraint_max_time_window_us,
50382+ .store = NULL
50383+ },
50384+
50385+ .min_time_window_attr = {
50386+ .attr = {
50387+ .name = NULL,
50388+ .mode = S_IRUGO
50389+ },
50390+ .show = show_constraint_min_time_window_us,
50391+ .store = NULL
50392+ },
50393+
50394+ .name_attr = {
50395+ .attr = {
50396+ .name = NULL,
50397+ .mode = S_IRUGO
50398+ },
50399+ .show = show_constraint_name,
50400+ .store = NULL
50401+ }
50402+ }
50403+};
50404
50405 /* A list of powercap control_types */
50406 static LIST_HEAD(powercap_cntrl_list);
50407@@ -193,23 +262,16 @@ static ssize_t show_constraint_name(struct device *dev,
50408 }
50409
50410 static int create_constraint_attribute(int id, const char *name,
50411- int mode,
50412- struct device_attribute *dev_attr,
50413- ssize_t (*show)(struct device *,
50414- struct device_attribute *, char *),
50415- ssize_t (*store)(struct device *,
50416- struct device_attribute *,
50417- const char *, size_t)
50418- )
50419+ struct device_attribute *dev_attr)
50420 {
50421+ name = kasprintf(GFP_KERNEL, "constraint_%d_%s", id, name);
50422
50423- dev_attr->attr.name = kasprintf(GFP_KERNEL, "constraint_%d_%s",
50424- id, name);
50425- if (!dev_attr->attr.name)
50426+ if (!name)
50427 return -ENOMEM;
50428- dev_attr->attr.mode = mode;
50429- dev_attr->show = show;
50430- dev_attr->store = store;
50431+
50432+ pax_open_kernel();
50433+ *(const char **)&dev_attr->attr.name = name;
50434+ pax_close_kernel();
50435
50436 return 0;
50437 }
50438@@ -236,49 +298,31 @@ static int seed_constraint_attributes(void)
50439
50440 for (i = 0; i < MAX_CONSTRAINTS_PER_ZONE; ++i) {
50441 ret = create_constraint_attribute(i, "power_limit_uw",
50442- S_IWUSR | S_IRUGO,
50443- &constraint_attrs[i].power_limit_attr,
50444- show_constraint_power_limit_uw,
50445- store_constraint_power_limit_uw);
50446+ &constraint_attrs[i].power_limit_attr);
50447 if (ret)
50448 goto err_alloc;
50449 ret = create_constraint_attribute(i, "time_window_us",
50450- S_IWUSR | S_IRUGO,
50451- &constraint_attrs[i].time_window_attr,
50452- show_constraint_time_window_us,
50453- store_constraint_time_window_us);
50454+ &constraint_attrs[i].time_window_attr);
50455 if (ret)
50456 goto err_alloc;
50457- ret = create_constraint_attribute(i, "name", S_IRUGO,
50458- &constraint_attrs[i].name_attr,
50459- show_constraint_name,
50460- NULL);
50461+ ret = create_constraint_attribute(i, "name",
50462+ &constraint_attrs[i].name_attr);
50463 if (ret)
50464 goto err_alloc;
50465- ret = create_constraint_attribute(i, "max_power_uw", S_IRUGO,
50466- &constraint_attrs[i].max_power_attr,
50467- show_constraint_max_power_uw,
50468- NULL);
50469+ ret = create_constraint_attribute(i, "max_power_uw",
50470+ &constraint_attrs[i].max_power_attr);
50471 if (ret)
50472 goto err_alloc;
50473- ret = create_constraint_attribute(i, "min_power_uw", S_IRUGO,
50474- &constraint_attrs[i].min_power_attr,
50475- show_constraint_min_power_uw,
50476- NULL);
50477+ ret = create_constraint_attribute(i, "min_power_uw",
50478+ &constraint_attrs[i].min_power_attr);
50479 if (ret)
50480 goto err_alloc;
50481 ret = create_constraint_attribute(i, "max_time_window_us",
50482- S_IRUGO,
50483- &constraint_attrs[i].max_time_window_attr,
50484- show_constraint_max_time_window_us,
50485- NULL);
50486+ &constraint_attrs[i].max_time_window_attr);
50487 if (ret)
50488 goto err_alloc;
50489 ret = create_constraint_attribute(i, "min_time_window_us",
50490- S_IRUGO,
50491- &constraint_attrs[i].min_time_window_attr,
50492- show_constraint_min_time_window_us,
50493- NULL);
50494+ &constraint_attrs[i].min_time_window_attr);
50495 if (ret)
50496 goto err_alloc;
50497
50498@@ -378,10 +422,12 @@ static void create_power_zone_common_attributes(
50499 power_zone->zone_dev_attrs[count++] =
50500 &dev_attr_max_energy_range_uj.attr;
50501 if (power_zone->ops->get_energy_uj) {
50502+ pax_open_kernel();
50503 if (power_zone->ops->reset_energy_uj)
50504- dev_attr_energy_uj.attr.mode = S_IWUSR | S_IRUGO;
50505+ *(umode_t *)&dev_attr_energy_uj.attr.mode = S_IWUSR | S_IRUGO;
50506 else
50507- dev_attr_energy_uj.attr.mode = S_IRUGO;
50508+ *(umode_t *)&dev_attr_energy_uj.attr.mode = S_IRUGO;
50509+ pax_close_kernel();
50510 power_zone->zone_dev_attrs[count++] =
50511 &dev_attr_energy_uj.attr;
50512 }
50513diff --git a/drivers/ptp/ptp_private.h b/drivers/ptp/ptp_private.h
50514index 9c5d414..c7900ce 100644
50515--- a/drivers/ptp/ptp_private.h
50516+++ b/drivers/ptp/ptp_private.h
50517@@ -51,7 +51,7 @@ struct ptp_clock {
50518 struct mutex pincfg_mux; /* protect concurrent info->pin_config access */
50519 wait_queue_head_t tsev_wq;
50520 int defunct; /* tells readers to go away when clock is being removed */
50521- struct device_attribute *pin_dev_attr;
50522+ device_attribute_no_const *pin_dev_attr;
50523 struct attribute **pin_attr;
50524 struct attribute_group pin_attr_group;
50525 };
50526diff --git a/drivers/ptp/ptp_sysfs.c b/drivers/ptp/ptp_sysfs.c
50527index 302e626..12579af 100644
50528--- a/drivers/ptp/ptp_sysfs.c
50529+++ b/drivers/ptp/ptp_sysfs.c
50530@@ -280,7 +280,7 @@ static int ptp_populate_pins(struct ptp_clock *ptp)
50531 goto no_pin_attr;
50532
50533 for (i = 0; i < n_pins; i++) {
50534- struct device_attribute *da = &ptp->pin_dev_attr[i];
50535+ device_attribute_no_const *da = &ptp->pin_dev_attr[i];
50536 sysfs_attr_init(&da->attr);
50537 da->attr.name = info->pin_config[i].name;
50538 da->attr.mode = 0644;
50539diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
50540index cd87c0c..715ecbe 100644
50541--- a/drivers/regulator/core.c
50542+++ b/drivers/regulator/core.c
50543@@ -3567,7 +3567,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
50544 {
50545 const struct regulation_constraints *constraints = NULL;
50546 const struct regulator_init_data *init_data;
50547- static atomic_t regulator_no = ATOMIC_INIT(0);
50548+ static atomic_unchecked_t regulator_no = ATOMIC_INIT(0);
50549 struct regulator_dev *rdev;
50550 struct device *dev;
50551 int ret, i;
50552@@ -3641,7 +3641,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
50553 rdev->dev.class = &regulator_class;
50554 rdev->dev.parent = dev;
50555 dev_set_name(&rdev->dev, "regulator.%d",
50556- atomic_inc_return(&regulator_no) - 1);
50557+ atomic_inc_return_unchecked(&regulator_no) - 1);
50558 ret = device_register(&rdev->dev);
50559 if (ret != 0) {
50560 put_device(&rdev->dev);
50561diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
50562index 7eee2ca..4024513 100644
50563--- a/drivers/regulator/max8660.c
50564+++ b/drivers/regulator/max8660.c
50565@@ -424,8 +424,10 @@ static int max8660_probe(struct i2c_client *client,
50566 max8660->shadow_regs[MAX8660_OVER1] = 5;
50567 } else {
50568 /* Otherwise devices can be toggled via software */
50569- max8660_dcdc_ops.enable = max8660_dcdc_enable;
50570- max8660_dcdc_ops.disable = max8660_dcdc_disable;
50571+ pax_open_kernel();
50572+ *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
50573+ *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
50574+ pax_close_kernel();
50575 }
50576
50577 /*
50578diff --git a/drivers/regulator/max8973-regulator.c b/drivers/regulator/max8973-regulator.c
50579index dbedf17..18ff6b7 100644
50580--- a/drivers/regulator/max8973-regulator.c
50581+++ b/drivers/regulator/max8973-regulator.c
50582@@ -403,9 +403,11 @@ static int max8973_probe(struct i2c_client *client,
50583 if (!pdata || !pdata->enable_ext_control) {
50584 max->desc.enable_reg = MAX8973_VOUT;
50585 max->desc.enable_mask = MAX8973_VOUT_ENABLE;
50586- max->ops.enable = regulator_enable_regmap;
50587- max->ops.disable = regulator_disable_regmap;
50588- max->ops.is_enabled = regulator_is_enabled_regmap;
50589+ pax_open_kernel();
50590+ *(void **)&max->ops.enable = regulator_enable_regmap;
50591+ *(void **)&max->ops.disable = regulator_disable_regmap;
50592+ *(void **)&max->ops.is_enabled = regulator_is_enabled_regmap;
50593+ pax_close_kernel();
50594 }
50595
50596 if (pdata) {
50597diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
50598index 793b662..85f74cd 100644
50599--- a/drivers/regulator/mc13892-regulator.c
50600+++ b/drivers/regulator/mc13892-regulator.c
50601@@ -584,10 +584,12 @@ static int mc13892_regulator_probe(struct platform_device *pdev)
50602 mc13xxx_unlock(mc13892);
50603
50604 /* update mc13892_vcam ops */
50605+ pax_open_kernel();
50606 memcpy(&mc13892_vcam_ops, mc13892_regulators[MC13892_VCAM].desc.ops,
50607 sizeof(struct regulator_ops));
50608- mc13892_vcam_ops.set_mode = mc13892_vcam_set_mode,
50609- mc13892_vcam_ops.get_mode = mc13892_vcam_get_mode,
50610+ *(void **)&mc13892_vcam_ops.set_mode = mc13892_vcam_set_mode,
50611+ *(void **)&mc13892_vcam_ops.get_mode = mc13892_vcam_get_mode,
50612+ pax_close_kernel();
50613 mc13892_regulators[MC13892_VCAM].desc.ops = &mc13892_vcam_ops;
50614
50615 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
50616diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c
50617index 5b2e761..c8c8a4a 100644
50618--- a/drivers/rtc/rtc-cmos.c
50619+++ b/drivers/rtc/rtc-cmos.c
50620@@ -789,7 +789,9 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq)
50621 hpet_rtc_timer_init();
50622
50623 /* export at least the first block of NVRAM */
50624- nvram.size = address_space - NVRAM_OFFSET;
50625+ pax_open_kernel();
50626+ *(size_t *)&nvram.size = address_space - NVRAM_OFFSET;
50627+ pax_close_kernel();
50628 retval = sysfs_create_bin_file(&dev->kobj, &nvram);
50629 if (retval < 0) {
50630 dev_dbg(dev, "can't create nvram file? %d\n", retval);
50631diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
50632index d049393..bb20be0 100644
50633--- a/drivers/rtc/rtc-dev.c
50634+++ b/drivers/rtc/rtc-dev.c
50635@@ -16,6 +16,7 @@
50636 #include <linux/module.h>
50637 #include <linux/rtc.h>
50638 #include <linux/sched.h>
50639+#include <linux/grsecurity.h>
50640 #include "rtc-core.h"
50641
50642 static dev_t rtc_devt;
50643@@ -347,6 +348,8 @@ static long rtc_dev_ioctl(struct file *file,
50644 if (copy_from_user(&tm, uarg, sizeof(tm)))
50645 return -EFAULT;
50646
50647+ gr_log_timechange();
50648+
50649 return rtc_set_time(rtc, &tm);
50650
50651 case RTC_PIE_ON:
50652diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c
50653index bb43cf7..ee4d274 100644
50654--- a/drivers/rtc/rtc-ds1307.c
50655+++ b/drivers/rtc/rtc-ds1307.c
50656@@ -107,7 +107,7 @@ struct ds1307 {
50657 u8 offset; /* register's offset */
50658 u8 regs[11];
50659 u16 nvram_offset;
50660- struct bin_attribute *nvram;
50661+ bin_attribute_no_const *nvram;
50662 enum ds_type type;
50663 unsigned long flags;
50664 #define HAS_NVRAM 0 /* bit 0 == sysfs file active */
50665diff --git a/drivers/rtc/rtc-m48t59.c b/drivers/rtc/rtc-m48t59.c
50666index 11880c1..b823aa4 100644
50667--- a/drivers/rtc/rtc-m48t59.c
50668+++ b/drivers/rtc/rtc-m48t59.c
50669@@ -483,7 +483,9 @@ static int m48t59_rtc_probe(struct platform_device *pdev)
50670 if (IS_ERR(m48t59->rtc))
50671 return PTR_ERR(m48t59->rtc);
50672
50673- m48t59_nvram_attr.size = pdata->offset;
50674+ pax_open_kernel();
50675+ *(size_t *)&m48t59_nvram_attr.size = pdata->offset;
50676+ pax_close_kernel();
50677
50678 ret = sysfs_create_bin_file(&pdev->dev.kobj, &m48t59_nvram_attr);
50679 if (ret)
50680diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
50681index e693af6..2e525b6 100644
50682--- a/drivers/scsi/bfa/bfa_fcpim.h
50683+++ b/drivers/scsi/bfa/bfa_fcpim.h
50684@@ -36,7 +36,7 @@ struct bfa_iotag_s {
50685
50686 struct bfa_itn_s {
50687 bfa_isr_func_t isr;
50688-};
50689+} __no_const;
50690
50691 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
50692 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
50693diff --git a/drivers/scsi/bfa/bfa_fcs.c b/drivers/scsi/bfa/bfa_fcs.c
50694index 0f19455..ef7adb5 100644
50695--- a/drivers/scsi/bfa/bfa_fcs.c
50696+++ b/drivers/scsi/bfa/bfa_fcs.c
50697@@ -38,10 +38,21 @@ struct bfa_fcs_mod_s {
50698 #define BFA_FCS_MODULE(_mod) { _mod ## _modinit, _mod ## _modexit }
50699
50700 static struct bfa_fcs_mod_s fcs_modules[] = {
50701- { bfa_fcs_port_attach, NULL, NULL },
50702- { bfa_fcs_uf_attach, NULL, NULL },
50703- { bfa_fcs_fabric_attach, bfa_fcs_fabric_modinit,
50704- bfa_fcs_fabric_modexit },
50705+ {
50706+ .attach = bfa_fcs_port_attach,
50707+ .modinit = NULL,
50708+ .modexit = NULL
50709+ },
50710+ {
50711+ .attach = bfa_fcs_uf_attach,
50712+ .modinit = NULL,
50713+ .modexit = NULL
50714+ },
50715+ {
50716+ .attach = bfa_fcs_fabric_attach,
50717+ .modinit = bfa_fcs_fabric_modinit,
50718+ .modexit = bfa_fcs_fabric_modexit
50719+ },
50720 };
50721
50722 /*
50723diff --git a/drivers/scsi/bfa/bfa_fcs_lport.c b/drivers/scsi/bfa/bfa_fcs_lport.c
50724index ff75ef8..2dfe00a 100644
50725--- a/drivers/scsi/bfa/bfa_fcs_lport.c
50726+++ b/drivers/scsi/bfa/bfa_fcs_lport.c
50727@@ -89,15 +89,26 @@ static struct {
50728 void (*offline) (struct bfa_fcs_lport_s *port);
50729 } __port_action[] = {
50730 {
50731- bfa_fcs_lport_unknown_init, bfa_fcs_lport_unknown_online,
50732- bfa_fcs_lport_unknown_offline}, {
50733- bfa_fcs_lport_fab_init, bfa_fcs_lport_fab_online,
50734- bfa_fcs_lport_fab_offline}, {
50735- bfa_fcs_lport_n2n_init, bfa_fcs_lport_n2n_online,
50736- bfa_fcs_lport_n2n_offline}, {
50737- bfa_fcs_lport_loop_init, bfa_fcs_lport_loop_online,
50738- bfa_fcs_lport_loop_offline},
50739- };
50740+ .init = bfa_fcs_lport_unknown_init,
50741+ .online = bfa_fcs_lport_unknown_online,
50742+ .offline = bfa_fcs_lport_unknown_offline
50743+ },
50744+ {
50745+ .init = bfa_fcs_lport_fab_init,
50746+ .online = bfa_fcs_lport_fab_online,
50747+ .offline = bfa_fcs_lport_fab_offline
50748+ },
50749+ {
50750+ .init = bfa_fcs_lport_n2n_init,
50751+ .online = bfa_fcs_lport_n2n_online,
50752+ .offline = bfa_fcs_lport_n2n_offline
50753+ },
50754+ {
50755+ .init = bfa_fcs_lport_loop_init,
50756+ .online = bfa_fcs_lport_loop_online,
50757+ .offline = bfa_fcs_lport_loop_offline
50758+ },
50759+};
50760
50761 /*
50762 * fcs_port_sm FCS logical port state machine
50763diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
50764index a38aafa0..fe8f03b 100644
50765--- a/drivers/scsi/bfa/bfa_ioc.h
50766+++ b/drivers/scsi/bfa/bfa_ioc.h
50767@@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
50768 bfa_ioc_disable_cbfn_t disable_cbfn;
50769 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
50770 bfa_ioc_reset_cbfn_t reset_cbfn;
50771-};
50772+} __no_const;
50773
50774 /*
50775 * IOC event notification mechanism.
50776@@ -352,7 +352,7 @@ struct bfa_ioc_hwif_s {
50777 void (*ioc_set_alt_fwstate) (struct bfa_ioc_s *ioc,
50778 enum bfi_ioc_state fwstate);
50779 enum bfi_ioc_state (*ioc_get_alt_fwstate) (struct bfa_ioc_s *ioc);
50780-};
50781+} __no_const;
50782
50783 /*
50784 * Queue element to wait for room in request queue. FIFO order is
50785diff --git a/drivers/scsi/bfa/bfa_modules.h b/drivers/scsi/bfa/bfa_modules.h
50786index a14c784..6de6790 100644
50787--- a/drivers/scsi/bfa/bfa_modules.h
50788+++ b/drivers/scsi/bfa/bfa_modules.h
50789@@ -78,12 +78,12 @@ enum {
50790 \
50791 extern struct bfa_module_s hal_mod_ ## __mod; \
50792 struct bfa_module_s hal_mod_ ## __mod = { \
50793- bfa_ ## __mod ## _meminfo, \
50794- bfa_ ## __mod ## _attach, \
50795- bfa_ ## __mod ## _detach, \
50796- bfa_ ## __mod ## _start, \
50797- bfa_ ## __mod ## _stop, \
50798- bfa_ ## __mod ## _iocdisable, \
50799+ .meminfo = bfa_ ## __mod ## _meminfo, \
50800+ .attach = bfa_ ## __mod ## _attach, \
50801+ .detach = bfa_ ## __mod ## _detach, \
50802+ .start = bfa_ ## __mod ## _start, \
50803+ .stop = bfa_ ## __mod ## _stop, \
50804+ .iocdisable = bfa_ ## __mod ## _iocdisable, \
50805 }
50806
50807 #define BFA_CACHELINE_SZ (256)
50808diff --git a/drivers/scsi/fcoe/fcoe_sysfs.c b/drivers/scsi/fcoe/fcoe_sysfs.c
50809index 045c4e1..13de803 100644
50810--- a/drivers/scsi/fcoe/fcoe_sysfs.c
50811+++ b/drivers/scsi/fcoe/fcoe_sysfs.c
50812@@ -33,8 +33,8 @@
50813 */
50814 #include "libfcoe.h"
50815
50816-static atomic_t ctlr_num;
50817-static atomic_t fcf_num;
50818+static atomic_unchecked_t ctlr_num;
50819+static atomic_unchecked_t fcf_num;
50820
50821 /*
50822 * fcoe_fcf_dev_loss_tmo: the default number of seconds that fcoe sysfs
50823@@ -685,7 +685,7 @@ struct fcoe_ctlr_device *fcoe_ctlr_device_add(struct device *parent,
50824 if (!ctlr)
50825 goto out;
50826
50827- ctlr->id = atomic_inc_return(&ctlr_num) - 1;
50828+ ctlr->id = atomic_inc_return_unchecked(&ctlr_num) - 1;
50829 ctlr->f = f;
50830 ctlr->mode = FIP_CONN_TYPE_FABRIC;
50831 INIT_LIST_HEAD(&ctlr->fcfs);
50832@@ -902,7 +902,7 @@ struct fcoe_fcf_device *fcoe_fcf_device_add(struct fcoe_ctlr_device *ctlr,
50833 fcf->dev.parent = &ctlr->dev;
50834 fcf->dev.bus = &fcoe_bus_type;
50835 fcf->dev.type = &fcoe_fcf_device_type;
50836- fcf->id = atomic_inc_return(&fcf_num) - 1;
50837+ fcf->id = atomic_inc_return_unchecked(&fcf_num) - 1;
50838 fcf->state = FCOE_FCF_STATE_UNKNOWN;
50839
50840 fcf->dev_loss_tmo = ctlr->fcf_dev_loss_tmo;
50841@@ -938,8 +938,8 @@ int __init fcoe_sysfs_setup(void)
50842 {
50843 int error;
50844
50845- atomic_set(&ctlr_num, 0);
50846- atomic_set(&fcf_num, 0);
50847+ atomic_set_unchecked(&ctlr_num, 0);
50848+ atomic_set_unchecked(&fcf_num, 0);
50849
50850 error = bus_register(&fcoe_bus_type);
50851 if (error)
50852diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
50853index 6de80e3..a11e0ac 100644
50854--- a/drivers/scsi/hosts.c
50855+++ b/drivers/scsi/hosts.c
50856@@ -42,7 +42,7 @@
50857 #include "scsi_logging.h"
50858
50859
50860-static atomic_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
50861+static atomic_unchecked_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
50862
50863
50864 static void scsi_host_cls_release(struct device *dev)
50865@@ -392,7 +392,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
50866 * subtract one because we increment first then return, but we need to
50867 * know what the next host number was before increment
50868 */
50869- shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
50870+ shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
50871 shost->dma_channel = 0xff;
50872
50873 /* These three are default values which can be overridden */
50874diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
50875index cef5d49..01e280e 100644
50876--- a/drivers/scsi/hpsa.c
50877+++ b/drivers/scsi/hpsa.c
50878@@ -701,10 +701,10 @@ static inline u32 next_command(struct ctlr_info *h, u8 q)
50879 unsigned long flags;
50880
50881 if (h->transMethod & CFGTBL_Trans_io_accel1)
50882- return h->access.command_completed(h, q);
50883+ return h->access->command_completed(h, q);
50884
50885 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
50886- return h->access.command_completed(h, q);
50887+ return h->access->command_completed(h, q);
50888
50889 if ((rq->head[rq->current_entry] & 1) == rq->wraparound) {
50890 a = rq->head[rq->current_entry];
50891@@ -5454,7 +5454,7 @@ static void start_io(struct ctlr_info *h, unsigned long *flags)
50892 while (!list_empty(&h->reqQ)) {
50893 c = list_entry(h->reqQ.next, struct CommandList, list);
50894 /* can't do anything if fifo is full */
50895- if ((h->access.fifo_full(h))) {
50896+ if ((h->access->fifo_full(h))) {
50897 h->fifo_recently_full = 1;
50898 dev_warn(&h->pdev->dev, "fifo full\n");
50899 break;
50900@@ -5476,7 +5476,7 @@ static void start_io(struct ctlr_info *h, unsigned long *flags)
50901
50902 /* Tell the controller execute command */
50903 spin_unlock_irqrestore(&h->lock, *flags);
50904- h->access.submit_command(h, c);
50905+ h->access->submit_command(h, c);
50906 spin_lock_irqsave(&h->lock, *flags);
50907 }
50908 }
50909@@ -5492,17 +5492,17 @@ static void lock_and_start_io(struct ctlr_info *h)
50910
50911 static inline unsigned long get_next_completion(struct ctlr_info *h, u8 q)
50912 {
50913- return h->access.command_completed(h, q);
50914+ return h->access->command_completed(h, q);
50915 }
50916
50917 static inline bool interrupt_pending(struct ctlr_info *h)
50918 {
50919- return h->access.intr_pending(h);
50920+ return h->access->intr_pending(h);
50921 }
50922
50923 static inline long interrupt_not_for_us(struct ctlr_info *h)
50924 {
50925- return (h->access.intr_pending(h) == 0) ||
50926+ return (h->access->intr_pending(h) == 0) ||
50927 (h->interrupts_enabled == 0);
50928 }
50929
50930@@ -6445,7 +6445,7 @@ static int hpsa_pci_init(struct ctlr_info *h)
50931 if (prod_index < 0)
50932 return -ENODEV;
50933 h->product_name = products[prod_index].product_name;
50934- h->access = *(products[prod_index].access);
50935+ h->access = products[prod_index].access;
50936
50937 pci_disable_link_state(h->pdev, PCIE_LINK_STATE_L0S |
50938 PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM);
50939@@ -6790,7 +6790,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
50940 unsigned long flags;
50941 u32 lockup_detected;
50942
50943- h->access.set_intr_mask(h, HPSA_INTR_OFF);
50944+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
50945 spin_lock_irqsave(&h->lock, flags);
50946 lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
50947 if (!lockup_detected) {
50948@@ -7037,7 +7037,7 @@ reinit_after_soft_reset:
50949 }
50950
50951 /* make sure the board interrupts are off */
50952- h->access.set_intr_mask(h, HPSA_INTR_OFF);
50953+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
50954
50955 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
50956 goto clean2;
50957@@ -7072,7 +7072,7 @@ reinit_after_soft_reset:
50958 * fake ones to scoop up any residual completions.
50959 */
50960 spin_lock_irqsave(&h->lock, flags);
50961- h->access.set_intr_mask(h, HPSA_INTR_OFF);
50962+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
50963 spin_unlock_irqrestore(&h->lock, flags);
50964 free_irqs(h);
50965 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
50966@@ -7091,9 +7091,9 @@ reinit_after_soft_reset:
50967 dev_info(&h->pdev->dev, "Board READY.\n");
50968 dev_info(&h->pdev->dev,
50969 "Waiting for stale completions to drain.\n");
50970- h->access.set_intr_mask(h, HPSA_INTR_ON);
50971+ h->access->set_intr_mask(h, HPSA_INTR_ON);
50972 msleep(10000);
50973- h->access.set_intr_mask(h, HPSA_INTR_OFF);
50974+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
50975
50976 rc = controller_reset_failed(h->cfgtable);
50977 if (rc)
50978@@ -7119,7 +7119,7 @@ reinit_after_soft_reset:
50979 h->drv_req_rescan = 0;
50980
50981 /* Turn the interrupts on so we can service requests */
50982- h->access.set_intr_mask(h, HPSA_INTR_ON);
50983+ h->access->set_intr_mask(h, HPSA_INTR_ON);
50984
50985 hpsa_hba_inquiry(h);
50986 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
50987@@ -7184,7 +7184,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
50988 * To write all data in the battery backed cache to disks
50989 */
50990 hpsa_flush_cache(h);
50991- h->access.set_intr_mask(h, HPSA_INTR_OFF);
50992+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
50993 hpsa_free_irqs_and_disable_msix(h);
50994 }
50995
50996@@ -7302,7 +7302,7 @@ static void hpsa_enter_performant_mode(struct ctlr_info *h, u32 trans_support)
50997 CFGTBL_Trans_enable_directed_msix |
50998 (trans_support & (CFGTBL_Trans_io_accel1 |
50999 CFGTBL_Trans_io_accel2));
51000- struct access_method access = SA5_performant_access;
51001+ struct access_method *access = &SA5_performant_access;
51002
51003 /* This is a bit complicated. There are 8 registers on
51004 * the controller which we write to to tell it 8 different
51005@@ -7344,7 +7344,7 @@ static void hpsa_enter_performant_mode(struct ctlr_info *h, u32 trans_support)
51006 * perform the superfluous readl() after each command submission.
51007 */
51008 if (trans_support & (CFGTBL_Trans_io_accel1 | CFGTBL_Trans_io_accel2))
51009- access = SA5_performant_access_no_read;
51010+ access = &SA5_performant_access_no_read;
51011
51012 /* Controller spec: zero out this buffer. */
51013 for (i = 0; i < h->nreply_queues; i++)
51014@@ -7374,12 +7374,12 @@ static void hpsa_enter_performant_mode(struct ctlr_info *h, u32 trans_support)
51015 * enable outbound interrupt coalescing in accelerator mode;
51016 */
51017 if (trans_support & CFGTBL_Trans_io_accel1) {
51018- access = SA5_ioaccel_mode1_access;
51019+ access = &SA5_ioaccel_mode1_access;
51020 writel(10, &h->cfgtable->HostWrite.CoalIntDelay);
51021 writel(4, &h->cfgtable->HostWrite.CoalIntCount);
51022 } else {
51023 if (trans_support & CFGTBL_Trans_io_accel2) {
51024- access = SA5_ioaccel_mode2_access;
51025+ access = &SA5_ioaccel_mode2_access;
51026 writel(10, &h->cfgtable->HostWrite.CoalIntDelay);
51027 writel(4, &h->cfgtable->HostWrite.CoalIntCount);
51028 }
51029diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
51030index 24472ce..8782caf 100644
51031--- a/drivers/scsi/hpsa.h
51032+++ b/drivers/scsi/hpsa.h
51033@@ -127,7 +127,7 @@ struct ctlr_info {
51034 unsigned int msix_vector;
51035 unsigned int msi_vector;
51036 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
51037- struct access_method access;
51038+ struct access_method *access;
51039 char hba_mode_enabled;
51040
51041 /* queue and queue Info */
51042@@ -536,43 +536,43 @@ static unsigned long SA5_ioaccel_mode1_completed(struct ctlr_info *h, u8 q)
51043 }
51044
51045 static struct access_method SA5_access = {
51046- SA5_submit_command,
51047- SA5_intr_mask,
51048- SA5_fifo_full,
51049- SA5_intr_pending,
51050- SA5_completed,
51051+ .submit_command = SA5_submit_command,
51052+ .set_intr_mask = SA5_intr_mask,
51053+ .fifo_full = SA5_fifo_full,
51054+ .intr_pending = SA5_intr_pending,
51055+ .command_completed = SA5_completed,
51056 };
51057
51058 static struct access_method SA5_ioaccel_mode1_access = {
51059- SA5_submit_command,
51060- SA5_performant_intr_mask,
51061- SA5_fifo_full,
51062- SA5_ioaccel_mode1_intr_pending,
51063- SA5_ioaccel_mode1_completed,
51064+ .submit_command = SA5_submit_command,
51065+ .set_intr_mask = SA5_performant_intr_mask,
51066+ .fifo_full = SA5_fifo_full,
51067+ .intr_pending = SA5_ioaccel_mode1_intr_pending,
51068+ .command_completed = SA5_ioaccel_mode1_completed,
51069 };
51070
51071 static struct access_method SA5_ioaccel_mode2_access = {
51072- SA5_submit_command_ioaccel2,
51073- SA5_performant_intr_mask,
51074- SA5_fifo_full,
51075- SA5_performant_intr_pending,
51076- SA5_performant_completed,
51077+ .submit_command = SA5_submit_command_ioaccel2,
51078+ .set_intr_mask = SA5_performant_intr_mask,
51079+ .fifo_full = SA5_fifo_full,
51080+ .intr_pending = SA5_performant_intr_pending,
51081+ .command_completed = SA5_performant_completed,
51082 };
51083
51084 static struct access_method SA5_performant_access = {
51085- SA5_submit_command,
51086- SA5_performant_intr_mask,
51087- SA5_fifo_full,
51088- SA5_performant_intr_pending,
51089- SA5_performant_completed,
51090+ .submit_command = SA5_submit_command,
51091+ .set_intr_mask = SA5_performant_intr_mask,
51092+ .fifo_full = SA5_fifo_full,
51093+ .intr_pending = SA5_performant_intr_pending,
51094+ .command_completed = SA5_performant_completed,
51095 };
51096
51097 static struct access_method SA5_performant_access_no_read = {
51098- SA5_submit_command_no_read,
51099- SA5_performant_intr_mask,
51100- SA5_fifo_full,
51101- SA5_performant_intr_pending,
51102- SA5_performant_completed,
51103+ .submit_command = SA5_submit_command_no_read,
51104+ .set_intr_mask = SA5_performant_intr_mask,
51105+ .fifo_full = SA5_fifo_full,
51106+ .intr_pending = SA5_performant_intr_pending,
51107+ .command_completed = SA5_performant_completed,
51108 };
51109
51110 struct board_type {
51111diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
51112index 1b3a094..068e683 100644
51113--- a/drivers/scsi/libfc/fc_exch.c
51114+++ b/drivers/scsi/libfc/fc_exch.c
51115@@ -101,12 +101,12 @@ struct fc_exch_mgr {
51116 u16 pool_max_index;
51117
51118 struct {
51119- atomic_t no_free_exch;
51120- atomic_t no_free_exch_xid;
51121- atomic_t xid_not_found;
51122- atomic_t xid_busy;
51123- atomic_t seq_not_found;
51124- atomic_t non_bls_resp;
51125+ atomic_unchecked_t no_free_exch;
51126+ atomic_unchecked_t no_free_exch_xid;
51127+ atomic_unchecked_t xid_not_found;
51128+ atomic_unchecked_t xid_busy;
51129+ atomic_unchecked_t seq_not_found;
51130+ atomic_unchecked_t non_bls_resp;
51131 } stats;
51132 };
51133
51134@@ -811,7 +811,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
51135 /* allocate memory for exchange */
51136 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
51137 if (!ep) {
51138- atomic_inc(&mp->stats.no_free_exch);
51139+ atomic_inc_unchecked(&mp->stats.no_free_exch);
51140 goto out;
51141 }
51142 memset(ep, 0, sizeof(*ep));
51143@@ -874,7 +874,7 @@ out:
51144 return ep;
51145 err:
51146 spin_unlock_bh(&pool->lock);
51147- atomic_inc(&mp->stats.no_free_exch_xid);
51148+ atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
51149 mempool_free(ep, mp->ep_pool);
51150 return NULL;
51151 }
51152@@ -1023,7 +1023,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
51153 xid = ntohs(fh->fh_ox_id); /* we originated exch */
51154 ep = fc_exch_find(mp, xid);
51155 if (!ep) {
51156- atomic_inc(&mp->stats.xid_not_found);
51157+ atomic_inc_unchecked(&mp->stats.xid_not_found);
51158 reject = FC_RJT_OX_ID;
51159 goto out;
51160 }
51161@@ -1053,7 +1053,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
51162 ep = fc_exch_find(mp, xid);
51163 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
51164 if (ep) {
51165- atomic_inc(&mp->stats.xid_busy);
51166+ atomic_inc_unchecked(&mp->stats.xid_busy);
51167 reject = FC_RJT_RX_ID;
51168 goto rel;
51169 }
51170@@ -1064,7 +1064,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
51171 }
51172 xid = ep->xid; /* get our XID */
51173 } else if (!ep) {
51174- atomic_inc(&mp->stats.xid_not_found);
51175+ atomic_inc_unchecked(&mp->stats.xid_not_found);
51176 reject = FC_RJT_RX_ID; /* XID not found */
51177 goto out;
51178 }
51179@@ -1082,7 +1082,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
51180 } else {
51181 sp = &ep->seq;
51182 if (sp->id != fh->fh_seq_id) {
51183- atomic_inc(&mp->stats.seq_not_found);
51184+ atomic_inc_unchecked(&mp->stats.seq_not_found);
51185 if (f_ctl & FC_FC_END_SEQ) {
51186 /*
51187 * Update sequence_id based on incoming last
51188@@ -1533,22 +1533,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
51189
51190 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
51191 if (!ep) {
51192- atomic_inc(&mp->stats.xid_not_found);
51193+ atomic_inc_unchecked(&mp->stats.xid_not_found);
51194 goto out;
51195 }
51196 if (ep->esb_stat & ESB_ST_COMPLETE) {
51197- atomic_inc(&mp->stats.xid_not_found);
51198+ atomic_inc_unchecked(&mp->stats.xid_not_found);
51199 goto rel;
51200 }
51201 if (ep->rxid == FC_XID_UNKNOWN)
51202 ep->rxid = ntohs(fh->fh_rx_id);
51203 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
51204- atomic_inc(&mp->stats.xid_not_found);
51205+ atomic_inc_unchecked(&mp->stats.xid_not_found);
51206 goto rel;
51207 }
51208 if (ep->did != ntoh24(fh->fh_s_id) &&
51209 ep->did != FC_FID_FLOGI) {
51210- atomic_inc(&mp->stats.xid_not_found);
51211+ atomic_inc_unchecked(&mp->stats.xid_not_found);
51212 goto rel;
51213 }
51214 sof = fr_sof(fp);
51215@@ -1557,7 +1557,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
51216 sp->ssb_stat |= SSB_ST_RESP;
51217 sp->id = fh->fh_seq_id;
51218 } else if (sp->id != fh->fh_seq_id) {
51219- atomic_inc(&mp->stats.seq_not_found);
51220+ atomic_inc_unchecked(&mp->stats.seq_not_found);
51221 goto rel;
51222 }
51223
51224@@ -1619,9 +1619,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
51225 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
51226
51227 if (!sp)
51228- atomic_inc(&mp->stats.xid_not_found);
51229+ atomic_inc_unchecked(&mp->stats.xid_not_found);
51230 else
51231- atomic_inc(&mp->stats.non_bls_resp);
51232+ atomic_inc_unchecked(&mp->stats.non_bls_resp);
51233
51234 fc_frame_free(fp);
51235 }
51236@@ -2261,13 +2261,13 @@ void fc_exch_update_stats(struct fc_lport *lport)
51237
51238 list_for_each_entry(ema, &lport->ema_list, ema_list) {
51239 mp = ema->mp;
51240- st->fc_no_free_exch += atomic_read(&mp->stats.no_free_exch);
51241+ st->fc_no_free_exch += atomic_read_unchecked(&mp->stats.no_free_exch);
51242 st->fc_no_free_exch_xid +=
51243- atomic_read(&mp->stats.no_free_exch_xid);
51244- st->fc_xid_not_found += atomic_read(&mp->stats.xid_not_found);
51245- st->fc_xid_busy += atomic_read(&mp->stats.xid_busy);
51246- st->fc_seq_not_found += atomic_read(&mp->stats.seq_not_found);
51247- st->fc_non_bls_resp += atomic_read(&mp->stats.non_bls_resp);
51248+ atomic_read_unchecked(&mp->stats.no_free_exch_xid);
51249+ st->fc_xid_not_found += atomic_read_unchecked(&mp->stats.xid_not_found);
51250+ st->fc_xid_busy += atomic_read_unchecked(&mp->stats.xid_busy);
51251+ st->fc_seq_not_found += atomic_read_unchecked(&mp->stats.seq_not_found);
51252+ st->fc_non_bls_resp += atomic_read_unchecked(&mp->stats.non_bls_resp);
51253 }
51254 }
51255 EXPORT_SYMBOL(fc_exch_update_stats);
51256diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
51257index 766098a..1c6c971 100644
51258--- a/drivers/scsi/libsas/sas_ata.c
51259+++ b/drivers/scsi/libsas/sas_ata.c
51260@@ -554,7 +554,7 @@ static struct ata_port_operations sas_sata_ops = {
51261 .postreset = ata_std_postreset,
51262 .error_handler = ata_std_error_handler,
51263 .post_internal_cmd = sas_ata_post_internal,
51264- .qc_defer = ata_std_qc_defer,
51265+ .qc_defer = ata_std_qc_defer,
51266 .qc_prep = ata_noop_qc_prep,
51267 .qc_issue = sas_ata_qc_issue,
51268 .qc_fill_rtf = sas_ata_qc_fill_rtf,
51269diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
51270index 434e903..5a4a79b 100644
51271--- a/drivers/scsi/lpfc/lpfc.h
51272+++ b/drivers/scsi/lpfc/lpfc.h
51273@@ -430,7 +430,7 @@ struct lpfc_vport {
51274 struct dentry *debug_nodelist;
51275 struct dentry *vport_debugfs_root;
51276 struct lpfc_debugfs_trc *disc_trc;
51277- atomic_t disc_trc_cnt;
51278+ atomic_unchecked_t disc_trc_cnt;
51279 #endif
51280 uint8_t stat_data_enabled;
51281 uint8_t stat_data_blocked;
51282@@ -880,8 +880,8 @@ struct lpfc_hba {
51283 struct timer_list fabric_block_timer;
51284 unsigned long bit_flags;
51285 #define FABRIC_COMANDS_BLOCKED 0
51286- atomic_t num_rsrc_err;
51287- atomic_t num_cmd_success;
51288+ atomic_unchecked_t num_rsrc_err;
51289+ atomic_unchecked_t num_cmd_success;
51290 unsigned long last_rsrc_error_time;
51291 unsigned long last_ramp_down_time;
51292 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
51293@@ -916,7 +916,7 @@ struct lpfc_hba {
51294
51295 struct dentry *debug_slow_ring_trc;
51296 struct lpfc_debugfs_trc *slow_ring_trc;
51297- atomic_t slow_ring_trc_cnt;
51298+ atomic_unchecked_t slow_ring_trc_cnt;
51299 /* iDiag debugfs sub-directory */
51300 struct dentry *idiag_root;
51301 struct dentry *idiag_pci_cfg;
51302diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
51303index 786a2af..562c6a2 100644
51304--- a/drivers/scsi/lpfc/lpfc_debugfs.c
51305+++ b/drivers/scsi/lpfc/lpfc_debugfs.c
51306@@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
51307
51308 #include <linux/debugfs.h>
51309
51310-static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
51311+static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
51312 static unsigned long lpfc_debugfs_start_time = 0L;
51313
51314 /* iDiag */
51315@@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
51316 lpfc_debugfs_enable = 0;
51317
51318 len = 0;
51319- index = (atomic_read(&vport->disc_trc_cnt) + 1) &
51320+ index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
51321 (lpfc_debugfs_max_disc_trc - 1);
51322 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
51323 dtp = vport->disc_trc + i;
51324@@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
51325 lpfc_debugfs_enable = 0;
51326
51327 len = 0;
51328- index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
51329+ index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
51330 (lpfc_debugfs_max_slow_ring_trc - 1);
51331 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
51332 dtp = phba->slow_ring_trc + i;
51333@@ -646,14 +646,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
51334 !vport || !vport->disc_trc)
51335 return;
51336
51337- index = atomic_inc_return(&vport->disc_trc_cnt) &
51338+ index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
51339 (lpfc_debugfs_max_disc_trc - 1);
51340 dtp = vport->disc_trc + index;
51341 dtp->fmt = fmt;
51342 dtp->data1 = data1;
51343 dtp->data2 = data2;
51344 dtp->data3 = data3;
51345- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
51346+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
51347 dtp->jif = jiffies;
51348 #endif
51349 return;
51350@@ -684,14 +684,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
51351 !phba || !phba->slow_ring_trc)
51352 return;
51353
51354- index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
51355+ index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
51356 (lpfc_debugfs_max_slow_ring_trc - 1);
51357 dtp = phba->slow_ring_trc + index;
51358 dtp->fmt = fmt;
51359 dtp->data1 = data1;
51360 dtp->data2 = data2;
51361 dtp->data3 = data3;
51362- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
51363+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
51364 dtp->jif = jiffies;
51365 #endif
51366 return;
51367@@ -4268,7 +4268,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
51368 "slow_ring buffer\n");
51369 goto debug_failed;
51370 }
51371- atomic_set(&phba->slow_ring_trc_cnt, 0);
51372+ atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
51373 memset(phba->slow_ring_trc, 0,
51374 (sizeof(struct lpfc_debugfs_trc) *
51375 lpfc_debugfs_max_slow_ring_trc));
51376@@ -4314,7 +4314,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
51377 "buffer\n");
51378 goto debug_failed;
51379 }
51380- atomic_set(&vport->disc_trc_cnt, 0);
51381+ atomic_set_unchecked(&vport->disc_trc_cnt, 0);
51382
51383 snprintf(name, sizeof(name), "discovery_trace");
51384 vport->debug_disc_trc =
51385diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
51386index 0b2c53a..aec2b45 100644
51387--- a/drivers/scsi/lpfc/lpfc_init.c
51388+++ b/drivers/scsi/lpfc/lpfc_init.c
51389@@ -11290,8 +11290,10 @@ lpfc_init(void)
51390 "misc_register returned with status %d", error);
51391
51392 if (lpfc_enable_npiv) {
51393- lpfc_transport_functions.vport_create = lpfc_vport_create;
51394- lpfc_transport_functions.vport_delete = lpfc_vport_delete;
51395+ pax_open_kernel();
51396+ *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
51397+ *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
51398+ pax_close_kernel();
51399 }
51400 lpfc_transport_template =
51401 fc_attach_transport(&lpfc_transport_functions);
51402diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
51403index b99399f..d29dc75 100644
51404--- a/drivers/scsi/lpfc/lpfc_scsi.c
51405+++ b/drivers/scsi/lpfc/lpfc_scsi.c
51406@@ -383,7 +383,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
51407 unsigned long expires;
51408
51409 spin_lock_irqsave(&phba->hbalock, flags);
51410- atomic_inc(&phba->num_rsrc_err);
51411+ atomic_inc_unchecked(&phba->num_rsrc_err);
51412 phba->last_rsrc_error_time = jiffies;
51413
51414 expires = phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL;
51415@@ -425,8 +425,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
51416 unsigned long num_rsrc_err, num_cmd_success;
51417 int i;
51418
51419- num_rsrc_err = atomic_read(&phba->num_rsrc_err);
51420- num_cmd_success = atomic_read(&phba->num_cmd_success);
51421+ num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
51422+ num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
51423
51424 /*
51425 * The error and success command counters are global per
51426@@ -454,8 +454,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
51427 }
51428 }
51429 lpfc_destroy_vport_work_array(phba, vports);
51430- atomic_set(&phba->num_rsrc_err, 0);
51431- atomic_set(&phba->num_cmd_success, 0);
51432+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
51433+ atomic_set_unchecked(&phba->num_cmd_success, 0);
51434 }
51435
51436 /**
51437diff --git a/drivers/scsi/mpt2sas/mpt2sas_scsih.c b/drivers/scsi/mpt2sas/mpt2sas_scsih.c
51438index c80ed04..e674f01 100644
51439--- a/drivers/scsi/mpt2sas/mpt2sas_scsih.c
51440+++ b/drivers/scsi/mpt2sas/mpt2sas_scsih.c
51441@@ -1561,7 +1561,7 @@ _scsih_get_resync(struct device *dev)
51442 {
51443 struct scsi_device *sdev = to_scsi_device(dev);
51444 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
51445- static struct _raid_device *raid_device;
51446+ struct _raid_device *raid_device;
51447 unsigned long flags;
51448 Mpi2RaidVolPage0_t vol_pg0;
51449 Mpi2ConfigReply_t mpi_reply;
51450@@ -1613,7 +1613,7 @@ _scsih_get_state(struct device *dev)
51451 {
51452 struct scsi_device *sdev = to_scsi_device(dev);
51453 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
51454- static struct _raid_device *raid_device;
51455+ struct _raid_device *raid_device;
51456 unsigned long flags;
51457 Mpi2RaidVolPage0_t vol_pg0;
51458 Mpi2ConfigReply_t mpi_reply;
51459@@ -6663,7 +6663,7 @@ _scsih_sas_ir_operation_status_event(struct MPT2SAS_ADAPTER *ioc,
51460 Mpi2EventDataIrOperationStatus_t *event_data =
51461 (Mpi2EventDataIrOperationStatus_t *)
51462 fw_event->event_data;
51463- static struct _raid_device *raid_device;
51464+ struct _raid_device *raid_device;
51465 unsigned long flags;
51466 u16 handle;
51467
51468@@ -7134,7 +7134,7 @@ _scsih_scan_for_devices_after_reset(struct MPT2SAS_ADAPTER *ioc)
51469 u64 sas_address;
51470 struct _sas_device *sas_device;
51471 struct _sas_node *expander_device;
51472- static struct _raid_device *raid_device;
51473+ struct _raid_device *raid_device;
51474 u8 retry_count;
51475 unsigned long flags;
51476
51477diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
51478index bcb64eb..f08cf71 100644
51479--- a/drivers/scsi/pmcraid.c
51480+++ b/drivers/scsi/pmcraid.c
51481@@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
51482 res->scsi_dev = scsi_dev;
51483 scsi_dev->hostdata = res;
51484 res->change_detected = 0;
51485- atomic_set(&res->read_failures, 0);
51486- atomic_set(&res->write_failures, 0);
51487+ atomic_set_unchecked(&res->read_failures, 0);
51488+ atomic_set_unchecked(&res->write_failures, 0);
51489 rc = 0;
51490 }
51491 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
51492@@ -2687,9 +2687,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
51493
51494 /* If this was a SCSI read/write command keep count of errors */
51495 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
51496- atomic_inc(&res->read_failures);
51497+ atomic_inc_unchecked(&res->read_failures);
51498 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
51499- atomic_inc(&res->write_failures);
51500+ atomic_inc_unchecked(&res->write_failures);
51501
51502 if (!RES_IS_GSCSI(res->cfg_entry) &&
51503 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
51504@@ -3545,7 +3545,7 @@ static int pmcraid_queuecommand_lck(
51505 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
51506 * hrrq_id assigned here in queuecommand
51507 */
51508- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
51509+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
51510 pinstance->num_hrrq;
51511 cmd->cmd_done = pmcraid_io_done;
51512
51513@@ -3857,7 +3857,7 @@ static long pmcraid_ioctl_passthrough(
51514 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
51515 * hrrq_id assigned here in queuecommand
51516 */
51517- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
51518+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
51519 pinstance->num_hrrq;
51520
51521 if (request_size) {
51522@@ -4495,7 +4495,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
51523
51524 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
51525 /* add resources only after host is added into system */
51526- if (!atomic_read(&pinstance->expose_resources))
51527+ if (!atomic_read_unchecked(&pinstance->expose_resources))
51528 return;
51529
51530 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
51531@@ -5312,8 +5312,8 @@ static int pmcraid_init_instance(struct pci_dev *pdev, struct Scsi_Host *host,
51532 init_waitqueue_head(&pinstance->reset_wait_q);
51533
51534 atomic_set(&pinstance->outstanding_cmds, 0);
51535- atomic_set(&pinstance->last_message_id, 0);
51536- atomic_set(&pinstance->expose_resources, 0);
51537+ atomic_set_unchecked(&pinstance->last_message_id, 0);
51538+ atomic_set_unchecked(&pinstance->expose_resources, 0);
51539
51540 INIT_LIST_HEAD(&pinstance->free_res_q);
51541 INIT_LIST_HEAD(&pinstance->used_res_q);
51542@@ -6026,7 +6026,7 @@ static int pmcraid_probe(struct pci_dev *pdev,
51543 /* Schedule worker thread to handle CCN and take care of adding and
51544 * removing devices to OS
51545 */
51546- atomic_set(&pinstance->expose_resources, 1);
51547+ atomic_set_unchecked(&pinstance->expose_resources, 1);
51548 schedule_work(&pinstance->worker_q);
51549 return rc;
51550
51551diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
51552index e1d150f..6c6df44 100644
51553--- a/drivers/scsi/pmcraid.h
51554+++ b/drivers/scsi/pmcraid.h
51555@@ -748,7 +748,7 @@ struct pmcraid_instance {
51556 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
51557
51558 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
51559- atomic_t last_message_id;
51560+ atomic_unchecked_t last_message_id;
51561
51562 /* configuration table */
51563 struct pmcraid_config_table *cfg_table;
51564@@ -777,7 +777,7 @@ struct pmcraid_instance {
51565 atomic_t outstanding_cmds;
51566
51567 /* should add/delete resources to mid-layer now ?*/
51568- atomic_t expose_resources;
51569+ atomic_unchecked_t expose_resources;
51570
51571
51572
51573@@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
51574 struct pmcraid_config_table_entry_ext cfg_entry_ext;
51575 };
51576 struct scsi_device *scsi_dev; /* Link scsi_device structure */
51577- atomic_t read_failures; /* count of failed READ commands */
51578- atomic_t write_failures; /* count of failed WRITE commands */
51579+ atomic_unchecked_t read_failures; /* count of failed READ commands */
51580+ atomic_unchecked_t write_failures; /* count of failed WRITE commands */
51581
51582 /* To indicate add/delete/modify during CCN */
51583 u8 change_detected;
51584diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
51585index 82b92c4..3178171 100644
51586--- a/drivers/scsi/qla2xxx/qla_attr.c
51587+++ b/drivers/scsi/qla2xxx/qla_attr.c
51588@@ -2192,7 +2192,7 @@ qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
51589 return 0;
51590 }
51591
51592-struct fc_function_template qla2xxx_transport_functions = {
51593+fc_function_template_no_const qla2xxx_transport_functions = {
51594
51595 .show_host_node_name = 1,
51596 .show_host_port_name = 1,
51597@@ -2240,7 +2240,7 @@ struct fc_function_template qla2xxx_transport_functions = {
51598 .bsg_timeout = qla24xx_bsg_timeout,
51599 };
51600
51601-struct fc_function_template qla2xxx_transport_vport_functions = {
51602+fc_function_template_no_const qla2xxx_transport_vport_functions = {
51603
51604 .show_host_node_name = 1,
51605 .show_host_port_name = 1,
51606diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
51607index b1865a7..a7723d3 100644
51608--- a/drivers/scsi/qla2xxx/qla_gbl.h
51609+++ b/drivers/scsi/qla2xxx/qla_gbl.h
51610@@ -571,8 +571,8 @@ extern void qla2x00_get_sym_node_name(scsi_qla_host_t *, uint8_t *, size_t);
51611 struct device_attribute;
51612 extern struct device_attribute *qla2x00_host_attrs[];
51613 struct fc_function_template;
51614-extern struct fc_function_template qla2xxx_transport_functions;
51615-extern struct fc_function_template qla2xxx_transport_vport_functions;
51616+extern fc_function_template_no_const qla2xxx_transport_functions;
51617+extern fc_function_template_no_const qla2xxx_transport_vport_functions;
51618 extern void qla2x00_alloc_sysfs_attr(scsi_qla_host_t *);
51619 extern void qla2x00_free_sysfs_attr(scsi_qla_host_t *, bool);
51620 extern void qla2x00_init_host_attr(scsi_qla_host_t *);
51621diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
51622index db3dbd9..2492392 100644
51623--- a/drivers/scsi/qla2xxx/qla_os.c
51624+++ b/drivers/scsi/qla2xxx/qla_os.c
51625@@ -1507,8 +1507,10 @@ qla2x00_config_dma_addressing(struct qla_hw_data *ha)
51626 !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
51627 /* Ok, a 64bit DMA mask is applicable. */
51628 ha->flags.enable_64bit_addressing = 1;
51629- ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
51630- ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
51631+ pax_open_kernel();
51632+ *(void **)&ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
51633+ *(void **)&ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
51634+ pax_close_kernel();
51635 return;
51636 }
51637 }
51638diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
51639index 8f6d0fb..1b21097 100644
51640--- a/drivers/scsi/qla4xxx/ql4_def.h
51641+++ b/drivers/scsi/qla4xxx/ql4_def.h
51642@@ -305,7 +305,7 @@ struct ddb_entry {
51643 * (4000 only) */
51644 atomic_t relogin_timer; /* Max Time to wait for
51645 * relogin to complete */
51646- atomic_t relogin_retry_count; /* Num of times relogin has been
51647+ atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
51648 * retried */
51649 uint32_t default_time2wait; /* Default Min time between
51650 * relogins (+aens) */
51651diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
51652index 199fcf7..3c3a918 100644
51653--- a/drivers/scsi/qla4xxx/ql4_os.c
51654+++ b/drivers/scsi/qla4xxx/ql4_os.c
51655@@ -4496,12 +4496,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
51656 */
51657 if (!iscsi_is_session_online(cls_sess)) {
51658 /* Reset retry relogin timer */
51659- atomic_inc(&ddb_entry->relogin_retry_count);
51660+ atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
51661 DEBUG2(ql4_printk(KERN_INFO, ha,
51662 "%s: index[%d] relogin timed out-retrying"
51663 " relogin (%d), retry (%d)\n", __func__,
51664 ddb_entry->fw_ddb_index,
51665- atomic_read(&ddb_entry->relogin_retry_count),
51666+ atomic_read_unchecked(&ddb_entry->relogin_retry_count),
51667 ddb_entry->default_time2wait + 4));
51668 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
51669 atomic_set(&ddb_entry->retry_relogin_timer,
51670@@ -6609,7 +6609,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
51671
51672 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
51673 atomic_set(&ddb_entry->relogin_timer, 0);
51674- atomic_set(&ddb_entry->relogin_retry_count, 0);
51675+ atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
51676 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
51677 ddb_entry->default_relogin_timeout =
51678 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
51679diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
51680index 79c77b4..ef6ec0b 100644
51681--- a/drivers/scsi/scsi.c
51682+++ b/drivers/scsi/scsi.c
51683@@ -645,7 +645,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
51684 struct Scsi_Host *host = cmd->device->host;
51685 int rtn = 0;
51686
51687- atomic_inc(&cmd->device->iorequest_cnt);
51688+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
51689
51690 /* check if the device is still usable */
51691 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
51692diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
51693index 50a6e1a..de5252e 100644
51694--- a/drivers/scsi/scsi_lib.c
51695+++ b/drivers/scsi/scsi_lib.c
51696@@ -1583,7 +1583,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
51697 shost = sdev->host;
51698 scsi_init_cmd_errh(cmd);
51699 cmd->result = DID_NO_CONNECT << 16;
51700- atomic_inc(&cmd->device->iorequest_cnt);
51701+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
51702
51703 /*
51704 * SCSI request completion path will do scsi_device_unbusy(),
51705@@ -1606,9 +1606,9 @@ static void scsi_softirq_done(struct request *rq)
51706
51707 INIT_LIST_HEAD(&cmd->eh_entry);
51708
51709- atomic_inc(&cmd->device->iodone_cnt);
51710+ atomic_inc_unchecked(&cmd->device->iodone_cnt);
51711 if (cmd->result)
51712- atomic_inc(&cmd->device->ioerr_cnt);
51713+ atomic_inc_unchecked(&cmd->device->ioerr_cnt);
51714
51715 disposition = scsi_decide_disposition(cmd);
51716 if (disposition != SUCCESS &&
51717diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
51718index f4cb7b3..dfa79c4 100644
51719--- a/drivers/scsi/scsi_sysfs.c
51720+++ b/drivers/scsi/scsi_sysfs.c
51721@@ -805,7 +805,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
51722 char *buf) \
51723 { \
51724 struct scsi_device *sdev = to_scsi_device(dev); \
51725- unsigned long long count = atomic_read(&sdev->field); \
51726+ unsigned long long count = atomic_read_unchecked(&sdev->field); \
51727 return snprintf(buf, 20, "0x%llx\n", count); \
51728 } \
51729 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
51730diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
51731index 5d6f348..18778a6b 100644
51732--- a/drivers/scsi/scsi_transport_fc.c
51733+++ b/drivers/scsi/scsi_transport_fc.c
51734@@ -501,7 +501,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
51735 * Netlink Infrastructure
51736 */
51737
51738-static atomic_t fc_event_seq;
51739+static atomic_unchecked_t fc_event_seq;
51740
51741 /**
51742 * fc_get_event_number - Obtain the next sequential FC event number
51743@@ -514,7 +514,7 @@ static atomic_t fc_event_seq;
51744 u32
51745 fc_get_event_number(void)
51746 {
51747- return atomic_add_return(1, &fc_event_seq);
51748+ return atomic_add_return_unchecked(1, &fc_event_seq);
51749 }
51750 EXPORT_SYMBOL(fc_get_event_number);
51751
51752@@ -658,7 +658,7 @@ static __init int fc_transport_init(void)
51753 {
51754 int error;
51755
51756- atomic_set(&fc_event_seq, 0);
51757+ atomic_set_unchecked(&fc_event_seq, 0);
51758
51759 error = transport_class_register(&fc_host_class);
51760 if (error)
51761@@ -848,7 +848,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
51762 char *cp;
51763
51764 *val = simple_strtoul(buf, &cp, 0);
51765- if ((*cp && (*cp != '\n')) || (*val < 0))
51766+ if (*cp && (*cp != '\n'))
51767 return -EINVAL;
51768 /*
51769 * Check for overflow; dev_loss_tmo is u32
51770diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
51771index 67d43e3..8cee73c 100644
51772--- a/drivers/scsi/scsi_transport_iscsi.c
51773+++ b/drivers/scsi/scsi_transport_iscsi.c
51774@@ -79,7 +79,7 @@ struct iscsi_internal {
51775 struct transport_container session_cont;
51776 };
51777
51778-static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
51779+static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
51780 static struct workqueue_struct *iscsi_eh_timer_workq;
51781
51782 static DEFINE_IDA(iscsi_sess_ida);
51783@@ -2071,7 +2071,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
51784 int err;
51785
51786 ihost = shost->shost_data;
51787- session->sid = atomic_add_return(1, &iscsi_session_nr);
51788+ session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
51789
51790 if (target_id == ISCSI_MAX_TARGET) {
51791 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
51792@@ -4515,7 +4515,7 @@ static __init int iscsi_transport_init(void)
51793 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
51794 ISCSI_TRANSPORT_VERSION);
51795
51796- atomic_set(&iscsi_session_nr, 0);
51797+ atomic_set_unchecked(&iscsi_session_nr, 0);
51798
51799 err = class_register(&iscsi_transport_class);
51800 if (err)
51801diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
51802index ae45bd9..c32a586 100644
51803--- a/drivers/scsi/scsi_transport_srp.c
51804+++ b/drivers/scsi/scsi_transport_srp.c
51805@@ -35,7 +35,7 @@
51806 #include "scsi_priv.h"
51807
51808 struct srp_host_attrs {
51809- atomic_t next_port_id;
51810+ atomic_unchecked_t next_port_id;
51811 };
51812 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
51813
51814@@ -100,7 +100,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
51815 struct Scsi_Host *shost = dev_to_shost(dev);
51816 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
51817
51818- atomic_set(&srp_host->next_port_id, 0);
51819+ atomic_set_unchecked(&srp_host->next_port_id, 0);
51820 return 0;
51821 }
51822
51823@@ -734,7 +734,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
51824 rport_fast_io_fail_timedout);
51825 INIT_DELAYED_WORK(&rport->dev_loss_work, rport_dev_loss_timedout);
51826
51827- id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
51828+ id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
51829 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
51830
51831 transport_setup_device(&rport->dev);
51832diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
51833index cfba74c..415f09b 100644
51834--- a/drivers/scsi/sd.c
51835+++ b/drivers/scsi/sd.c
51836@@ -3022,7 +3022,7 @@ static int sd_probe(struct device *dev)
51837 sdkp->disk = gd;
51838 sdkp->index = index;
51839 atomic_set(&sdkp->openers, 0);
51840- atomic_set(&sdkp->device->ioerr_cnt, 0);
51841+ atomic_set_unchecked(&sdkp->device->ioerr_cnt, 0);
51842
51843 if (!sdp->request_queue->rq_timeout) {
51844 if (sdp->type != TYPE_MOD)
51845diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
51846index 6035444..c82edd4 100644
51847--- a/drivers/scsi/sg.c
51848+++ b/drivers/scsi/sg.c
51849@@ -1138,7 +1138,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
51850 sdp->disk->disk_name,
51851 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
51852 NULL,
51853- (char *)arg);
51854+ (char __user *)arg);
51855 case BLKTRACESTART:
51856 return blk_trace_startstop(sdp->device->request_queue, 1);
51857 case BLKTRACESTOP:
51858diff --git a/drivers/soc/tegra/fuse/fuse-tegra.c b/drivers/soc/tegra/fuse/fuse-tegra.c
51859index 11a5043..e36f04c 100644
51860--- a/drivers/soc/tegra/fuse/fuse-tegra.c
51861+++ b/drivers/soc/tegra/fuse/fuse-tegra.c
51862@@ -70,7 +70,7 @@ static ssize_t fuse_read(struct file *fd, struct kobject *kobj,
51863 return i;
51864 }
51865
51866-static struct bin_attribute fuse_bin_attr = {
51867+static bin_attribute_no_const fuse_bin_attr = {
51868 .attr = { .name = "fuse", .mode = S_IRUGO, },
51869 .read = fuse_read,
51870 };
51871diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
51872index 50f20f2..6bd81e0 100644
51873--- a/drivers/spi/spi.c
51874+++ b/drivers/spi/spi.c
51875@@ -2224,7 +2224,7 @@ int spi_bus_unlock(struct spi_master *master)
51876 EXPORT_SYMBOL_GPL(spi_bus_unlock);
51877
51878 /* portable code must never pass more than 32 bytes */
51879-#define SPI_BUFSIZ max(32, SMP_CACHE_BYTES)
51880+#define SPI_BUFSIZ max(32UL, SMP_CACHE_BYTES)
51881
51882 static u8 *buf;
51883
51884diff --git a/drivers/staging/android/timed_output.c b/drivers/staging/android/timed_output.c
51885index b41429f..2de5373 100644
51886--- a/drivers/staging/android/timed_output.c
51887+++ b/drivers/staging/android/timed_output.c
51888@@ -25,7 +25,7 @@
51889 #include "timed_output.h"
51890
51891 static struct class *timed_output_class;
51892-static atomic_t device_count;
51893+static atomic_unchecked_t device_count;
51894
51895 static ssize_t enable_show(struct device *dev, struct device_attribute *attr,
51896 char *buf)
51897@@ -65,7 +65,7 @@ static int create_timed_output_class(void)
51898 timed_output_class = class_create(THIS_MODULE, "timed_output");
51899 if (IS_ERR(timed_output_class))
51900 return PTR_ERR(timed_output_class);
51901- atomic_set(&device_count, 0);
51902+ atomic_set_unchecked(&device_count, 0);
51903 timed_output_class->dev_groups = timed_output_groups;
51904 }
51905
51906@@ -83,7 +83,7 @@ int timed_output_dev_register(struct timed_output_dev *tdev)
51907 if (ret < 0)
51908 return ret;
51909
51910- tdev->index = atomic_inc_return(&device_count);
51911+ tdev->index = atomic_inc_return_unchecked(&device_count);
51912 tdev->dev = device_create(timed_output_class, NULL,
51913 MKDEV(0, tdev->index), NULL, "%s", tdev->name);
51914 if (IS_ERR(tdev->dev))
51915diff --git a/drivers/staging/gdm724x/gdm_tty.c b/drivers/staging/gdm724x/gdm_tty.c
51916index 001348c..cfaac8a 100644
51917--- a/drivers/staging/gdm724x/gdm_tty.c
51918+++ b/drivers/staging/gdm724x/gdm_tty.c
51919@@ -44,7 +44,7 @@
51920 #define gdm_tty_send_control(n, r, v, d, l) (\
51921 n->tty_dev->send_control(n->tty_dev->priv_dev, r, v, d, l))
51922
51923-#define GDM_TTY_READY(gdm) (gdm && gdm->tty_dev && gdm->port.count)
51924+#define GDM_TTY_READY(gdm) (gdm && gdm->tty_dev && atomic_read(&gdm->port.count))
51925
51926 static struct tty_driver *gdm_driver[TTY_MAX_COUNT];
51927 static struct gdm *gdm_table[TTY_MAX_COUNT][GDM_TTY_MINOR];
51928diff --git a/drivers/staging/imx-drm/imx-drm-core.c b/drivers/staging/imx-drm/imx-drm-core.c
51929index 9cb222e..8766f26 100644
51930--- a/drivers/staging/imx-drm/imx-drm-core.c
51931+++ b/drivers/staging/imx-drm/imx-drm-core.c
51932@@ -357,7 +357,7 @@ int imx_drm_add_crtc(struct drm_device *drm, struct drm_crtc *crtc,
51933 if (imxdrm->pipes >= MAX_CRTC)
51934 return -EINVAL;
51935
51936- if (imxdrm->drm->open_count)
51937+ if (local_read(&imxdrm->drm->open_count))
51938 return -EBUSY;
51939
51940 imx_drm_crtc = kzalloc(sizeof(*imx_drm_crtc), GFP_KERNEL);
51941diff --git a/drivers/staging/line6/driver.c b/drivers/staging/line6/driver.c
51942index 503b2d7..c904931 100644
51943--- a/drivers/staging/line6/driver.c
51944+++ b/drivers/staging/line6/driver.c
51945@@ -463,7 +463,7 @@ int line6_read_data(struct usb_line6 *line6, int address, void *data,
51946 {
51947 struct usb_device *usbdev = line6->usbdev;
51948 int ret;
51949- unsigned char len;
51950+ unsigned char *plen;
51951
51952 /* query the serial number: */
51953 ret = usb_control_msg(usbdev, usb_sndctrlpipe(usbdev, 0), 0x67,
51954@@ -476,27 +476,34 @@ int line6_read_data(struct usb_line6 *line6, int address, void *data,
51955 return ret;
51956 }
51957
51958+ plen = kmalloc(1, GFP_KERNEL);
51959+ if (plen == NULL)
51960+ return -ENOMEM;
51961+
51962 /* Wait for data length. We'll get 0xff until length arrives. */
51963 do {
51964 ret = usb_control_msg(usbdev, usb_rcvctrlpipe(usbdev, 0), 0x67,
51965 USB_TYPE_VENDOR | USB_RECIP_DEVICE |
51966 USB_DIR_IN,
51967- 0x0012, 0x0000, &len, 1,
51968+ 0x0012, 0x0000, plen, 1,
51969 LINE6_TIMEOUT * HZ);
51970 if (ret < 0) {
51971 dev_err(line6->ifcdev,
51972 "receive length failed (error %d)\n", ret);
51973+ kfree(plen);
51974 return ret;
51975 }
51976- } while (len == 0xff);
51977+ } while (*plen == 0xff);
51978
51979- if (len != datalen) {
51980+ if (*plen != datalen) {
51981 /* should be equal or something went wrong */
51982 dev_err(line6->ifcdev,
51983 "length mismatch (expected %d, got %d)\n",
51984- (int)datalen, (int)len);
51985+ (int)datalen, (int)*plen);
51986+ kfree(plen);
51987 return -EINVAL;
51988 }
51989+ kfree(plen);
51990
51991 /* receive the result: */
51992 ret = usb_control_msg(usbdev, usb_rcvctrlpipe(usbdev, 0), 0x67,
51993@@ -520,7 +527,7 @@ int line6_write_data(struct usb_line6 *line6, int address, void *data,
51994 {
51995 struct usb_device *usbdev = line6->usbdev;
51996 int ret;
51997- unsigned char status;
51998+ unsigned char *status;
51999
52000 ret = usb_control_msg(usbdev, usb_sndctrlpipe(usbdev, 0), 0x67,
52001 USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_OUT,
52002@@ -533,26 +540,34 @@ int line6_write_data(struct usb_line6 *line6, int address, void *data,
52003 return ret;
52004 }
52005
52006+ status = kmalloc(1, GFP_KERNEL);
52007+ if (status == NULL)
52008+ return -ENOMEM;
52009+
52010 do {
52011 ret = usb_control_msg(usbdev, usb_rcvctrlpipe(usbdev, 0),
52012 0x67,
52013 USB_TYPE_VENDOR | USB_RECIP_DEVICE |
52014 USB_DIR_IN,
52015 0x0012, 0x0000,
52016- &status, 1, LINE6_TIMEOUT * HZ);
52017+ status, 1, LINE6_TIMEOUT * HZ);
52018
52019 if (ret < 0) {
52020 dev_err(line6->ifcdev,
52021 "receiving status failed (error %d)\n", ret);
52022+ kfree(status);
52023 return ret;
52024 }
52025- } while (status == 0xff);
52026+ } while (*status == 0xff);
52027
52028- if (status != 0) {
52029+ if (*status != 0) {
52030 dev_err(line6->ifcdev, "write failed (error %d)\n", ret);
52031+ kfree(status);
52032 return -EINVAL;
52033 }
52034
52035+ kfree(status);
52036+
52037 return 0;
52038 }
52039
52040diff --git a/drivers/staging/line6/toneport.c b/drivers/staging/line6/toneport.c
52041index 6943715..0a93632 100644
52042--- a/drivers/staging/line6/toneport.c
52043+++ b/drivers/staging/line6/toneport.c
52044@@ -11,6 +11,7 @@
52045 */
52046
52047 #include <linux/wait.h>
52048+#include <linux/slab.h>
52049 #include <sound/control.h>
52050
52051 #include "audio.h"
52052@@ -307,14 +308,20 @@ static void toneport_destruct(struct usb_interface *interface)
52053 */
52054 static void toneport_setup(struct usb_line6_toneport *toneport)
52055 {
52056- int ticks;
52057+ int *ticks;
52058 struct usb_line6 *line6 = &toneport->line6;
52059 struct usb_device *usbdev = line6->usbdev;
52060 u16 idProduct = le16_to_cpu(usbdev->descriptor.idProduct);
52061
52062+ ticks = kmalloc(sizeof(int), GFP_KERNEL);
52063+ if (ticks == NULL)
52064+ return;
52065+
52066 /* sync time on device with host: */
52067- ticks = (int)get_seconds();
52068- line6_write_data(line6, 0x80c6, &ticks, 4);
52069+ *ticks = (int)get_seconds();
52070+ line6_write_data(line6, 0x80c6, ticks, sizeof(int));
52071+
52072+ kfree(ticks);
52073
52074 /* enable device: */
52075 toneport_send_cmd(usbdev, 0x0301, 0x0000);
52076diff --git a/drivers/staging/lustre/lnet/selftest/brw_test.c b/drivers/staging/lustre/lnet/selftest/brw_test.c
52077index a94f336..6a1924d 100644
52078--- a/drivers/staging/lustre/lnet/selftest/brw_test.c
52079+++ b/drivers/staging/lustre/lnet/selftest/brw_test.c
52080@@ -488,13 +488,11 @@ brw_server_handle(struct srpc_server_rpc *rpc)
52081 return 0;
52082 }
52083
52084-sfw_test_client_ops_t brw_test_client;
52085-void brw_init_test_client(void)
52086-{
52087- brw_test_client.tso_init = brw_client_init;
52088- brw_test_client.tso_fini = brw_client_fini;
52089- brw_test_client.tso_prep_rpc = brw_client_prep_rpc;
52090- brw_test_client.tso_done_rpc = brw_client_done_rpc;
52091+sfw_test_client_ops_t brw_test_client = {
52092+ .tso_init = brw_client_init,
52093+ .tso_fini = brw_client_fini,
52094+ .tso_prep_rpc = brw_client_prep_rpc,
52095+ .tso_done_rpc = brw_client_done_rpc,
52096 };
52097
52098 srpc_service_t brw_test_service;
52099diff --git a/drivers/staging/lustre/lnet/selftest/framework.c b/drivers/staging/lustre/lnet/selftest/framework.c
52100index df04ab7..1deb1ac 100644
52101--- a/drivers/staging/lustre/lnet/selftest/framework.c
52102+++ b/drivers/staging/lustre/lnet/selftest/framework.c
52103@@ -1632,12 +1632,10 @@ static srpc_service_t sfw_services[] = {
52104
52105 extern sfw_test_client_ops_t ping_test_client;
52106 extern srpc_service_t ping_test_service;
52107-extern void ping_init_test_client(void);
52108 extern void ping_init_test_service(void);
52109
52110 extern sfw_test_client_ops_t brw_test_client;
52111 extern srpc_service_t brw_test_service;
52112-extern void brw_init_test_client(void);
52113 extern void brw_init_test_service(void);
52114
52115
52116@@ -1681,12 +1679,10 @@ sfw_startup (void)
52117 INIT_LIST_HEAD(&sfw_data.fw_zombie_rpcs);
52118 INIT_LIST_HEAD(&sfw_data.fw_zombie_sessions);
52119
52120- brw_init_test_client();
52121 brw_init_test_service();
52122 rc = sfw_register_test(&brw_test_service, &brw_test_client);
52123 LASSERT (rc == 0);
52124
52125- ping_init_test_client();
52126 ping_init_test_service();
52127 rc = sfw_register_test(&ping_test_service, &ping_test_client);
52128 LASSERT (rc == 0);
52129diff --git a/drivers/staging/lustre/lnet/selftest/ping_test.c b/drivers/staging/lustre/lnet/selftest/ping_test.c
52130index 750cac4..e4d751f 100644
52131--- a/drivers/staging/lustre/lnet/selftest/ping_test.c
52132+++ b/drivers/staging/lustre/lnet/selftest/ping_test.c
52133@@ -211,14 +211,12 @@ ping_server_handle(struct srpc_server_rpc *rpc)
52134 return 0;
52135 }
52136
52137-sfw_test_client_ops_t ping_test_client;
52138-void ping_init_test_client(void)
52139-{
52140- ping_test_client.tso_init = ping_client_init;
52141- ping_test_client.tso_fini = ping_client_fini;
52142- ping_test_client.tso_prep_rpc = ping_client_prep_rpc;
52143- ping_test_client.tso_done_rpc = ping_client_done_rpc;
52144-}
52145+sfw_test_client_ops_t ping_test_client = {
52146+ .tso_init = ping_client_init,
52147+ .tso_fini = ping_client_fini,
52148+ .tso_prep_rpc = ping_client_prep_rpc,
52149+ .tso_done_rpc = ping_client_done_rpc,
52150+};
52151
52152 srpc_service_t ping_test_service;
52153 void ping_init_test_service(void)
52154diff --git a/drivers/staging/lustre/lustre/include/lustre_dlm.h b/drivers/staging/lustre/lustre/include/lustre_dlm.h
52155index 14ac46f..eca2c16 100644
52156--- a/drivers/staging/lustre/lustre/include/lustre_dlm.h
52157+++ b/drivers/staging/lustre/lustre/include/lustre_dlm.h
52158@@ -1139,7 +1139,7 @@ struct ldlm_callback_suite {
52159 ldlm_completion_callback lcs_completion;
52160 ldlm_blocking_callback lcs_blocking;
52161 ldlm_glimpse_callback lcs_glimpse;
52162-};
52163+} __no_const;
52164
52165 /* ldlm_lockd.c */
52166 int ldlm_del_waiting_lock(struct ldlm_lock *lock);
52167diff --git a/drivers/staging/lustre/lustre/include/obd.h b/drivers/staging/lustre/lustre/include/obd.h
52168index 2a88b80..62e7e5f 100644
52169--- a/drivers/staging/lustre/lustre/include/obd.h
52170+++ b/drivers/staging/lustre/lustre/include/obd.h
52171@@ -1362,7 +1362,7 @@ struct md_ops {
52172 * lprocfs_alloc_md_stats() in obdclass/lprocfs_status.c. Also, add a
52173 * wrapper function in include/linux/obd_class.h.
52174 */
52175-};
52176+} __no_const;
52177
52178 struct lsm_operations {
52179 void (*lsm_free)(struct lov_stripe_md *);
52180diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c b/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
52181index b798daa..b28ca8f 100644
52182--- a/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
52183+++ b/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
52184@@ -258,7 +258,7 @@ ldlm_process_flock_lock(struct ldlm_lock *req, __u64 *flags, int first_enq,
52185 int added = (mode == LCK_NL);
52186 int overlaps = 0;
52187 int splitted = 0;
52188- const struct ldlm_callback_suite null_cbs = { NULL };
52189+ const struct ldlm_callback_suite null_cbs = { };
52190
52191 CDEBUG(D_DLMTRACE, "flags %#llx owner %llu pid %u mode %u start %llu end %llu\n",
52192 *flags, new->l_policy_data.l_flock.owner,
52193diff --git a/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c b/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
52194index bbe2c68..c6b4275 100644
52195--- a/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
52196+++ b/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
52197@@ -236,7 +236,7 @@ int proc_console_max_delay_cs(struct ctl_table *table, int write,
52198 void __user *buffer, size_t *lenp, loff_t *ppos)
52199 {
52200 int rc, max_delay_cs;
52201- struct ctl_table dummy = *table;
52202+ ctl_table_no_const dummy = *table;
52203 long d;
52204
52205 dummy.data = &max_delay_cs;
52206@@ -268,7 +268,7 @@ int proc_console_min_delay_cs(struct ctl_table *table, int write,
52207 void __user *buffer, size_t *lenp, loff_t *ppos)
52208 {
52209 int rc, min_delay_cs;
52210- struct ctl_table dummy = *table;
52211+ ctl_table_no_const dummy = *table;
52212 long d;
52213
52214 dummy.data = &min_delay_cs;
52215@@ -300,7 +300,7 @@ int proc_console_backoff(struct ctl_table *table, int write,
52216 void __user *buffer, size_t *lenp, loff_t *ppos)
52217 {
52218 int rc, backoff;
52219- struct ctl_table dummy = *table;
52220+ ctl_table_no_const dummy = *table;
52221
52222 dummy.data = &backoff;
52223 dummy.proc_handler = &proc_dointvec;
52224diff --git a/drivers/staging/lustre/lustre/libcfs/module.c b/drivers/staging/lustre/lustre/libcfs/module.c
52225index 2c4fc74..b04ca79 100644
52226--- a/drivers/staging/lustre/lustre/libcfs/module.c
52227+++ b/drivers/staging/lustre/lustre/libcfs/module.c
52228@@ -315,11 +315,11 @@ out:
52229
52230
52231 struct cfs_psdev_ops libcfs_psdev_ops = {
52232- libcfs_psdev_open,
52233- libcfs_psdev_release,
52234- NULL,
52235- NULL,
52236- libcfs_ioctl
52237+ .p_open = libcfs_psdev_open,
52238+ .p_close = libcfs_psdev_release,
52239+ .p_read = NULL,
52240+ .p_write = NULL,
52241+ .p_ioctl = libcfs_ioctl
52242 };
52243
52244 extern int insert_proc(void);
52245diff --git a/drivers/staging/lustre/lustre/llite/dir.c b/drivers/staging/lustre/lustre/llite/dir.c
52246index b0bb709..0117c96 100644
52247--- a/drivers/staging/lustre/lustre/llite/dir.c
52248+++ b/drivers/staging/lustre/lustre/llite/dir.c
52249@@ -661,7 +661,7 @@ int ll_dir_setdirstripe(struct inode *dir, struct lmv_user_md *lump,
52250 int mode;
52251 int err;
52252
52253- mode = (0755 & (S_IRWXUGO|S_ISVTX) & ~current->fs->umask) | S_IFDIR;
52254+ mode = (0755 & (S_IRWXUGO|S_ISVTX) & ~current_umask()) | S_IFDIR;
52255 op_data = ll_prep_md_op_data(NULL, dir, NULL, filename,
52256 strlen(filename), mode, LUSTRE_OPC_MKDIR,
52257 lump);
52258diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
52259index b2b6c3c..302e4e4 100644
52260--- a/drivers/staging/octeon/ethernet-rx.c
52261+++ b/drivers/staging/octeon/ethernet-rx.c
52262@@ -416,11 +416,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
52263 /* Increment RX stats for virtual ports */
52264 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
52265 #ifdef CONFIG_64BIT
52266- atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
52267- atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
52268+ atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
52269+ atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
52270 #else
52271- atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
52272- atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
52273+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
52274+ atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
52275 #endif
52276 }
52277 netif_receive_skb(skb);
52278@@ -431,9 +431,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
52279 dev->name);
52280 */
52281 #ifdef CONFIG_64BIT
52282- atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
52283+ atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
52284 #else
52285- atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
52286+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
52287 #endif
52288 dev_kfree_skb_irq(skb);
52289 }
52290diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
52291index 8f9e3fb..d283fb9 100644
52292--- a/drivers/staging/octeon/ethernet.c
52293+++ b/drivers/staging/octeon/ethernet.c
52294@@ -247,11 +247,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
52295 * since the RX tasklet also increments it.
52296 */
52297 #ifdef CONFIG_64BIT
52298- atomic64_add(rx_status.dropped_packets,
52299- (atomic64_t *)&priv->stats.rx_dropped);
52300+ atomic64_add_unchecked(rx_status.dropped_packets,
52301+ (atomic64_unchecked_t *)&priv->stats.rx_dropped);
52302 #else
52303- atomic_add(rx_status.dropped_packets,
52304- (atomic_t *)&priv->stats.rx_dropped);
52305+ atomic_add_unchecked(rx_status.dropped_packets,
52306+ (atomic_unchecked_t *)&priv->stats.rx_dropped);
52307 #endif
52308 }
52309
52310diff --git a/drivers/staging/rtl8188eu/include/hal_intf.h b/drivers/staging/rtl8188eu/include/hal_intf.h
52311index 9191993..30e9817 100644
52312--- a/drivers/staging/rtl8188eu/include/hal_intf.h
52313+++ b/drivers/staging/rtl8188eu/include/hal_intf.h
52314@@ -225,7 +225,7 @@ struct hal_ops {
52315
52316 void (*hal_notch_filter)(struct adapter *adapter, bool enable);
52317 void (*hal_reset_security_engine)(struct adapter *adapter);
52318-};
52319+} __no_const;
52320
52321 enum rt_eeprom_type {
52322 EEPROM_93C46,
52323diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
52324index 070cc03..6806e37 100644
52325--- a/drivers/staging/rtl8712/rtl871x_io.h
52326+++ b/drivers/staging/rtl8712/rtl871x_io.h
52327@@ -108,7 +108,7 @@ struct _io_ops {
52328 u8 *pmem);
52329 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
52330 u8 *pmem);
52331-};
52332+} __no_const;
52333
52334 struct io_req {
52335 struct list_head list;
52336diff --git a/drivers/staging/unisys/visorchipset/visorchipset.h b/drivers/staging/unisys/visorchipset/visorchipset.h
52337index 2bf2e2f..84421c9 100644
52338--- a/drivers/staging/unisys/visorchipset/visorchipset.h
52339+++ b/drivers/staging/unisys/visorchipset/visorchipset.h
52340@@ -228,7 +228,7 @@ typedef struct {
52341 void (*device_resume)(ulong busNo, ulong devNo);
52342 int (*get_channel_info)(uuid_le typeGuid, ulong *minSize,
52343 ulong *maxSize);
52344-} VISORCHIPSET_BUSDEV_NOTIFIERS;
52345+} __no_const VISORCHIPSET_BUSDEV_NOTIFIERS;
52346
52347 /* These functions live inside visorchipset, and will be called to indicate
52348 * responses to specific events (by code outside of visorchipset).
52349@@ -243,7 +243,7 @@ typedef struct {
52350 void (*device_destroy)(ulong busNo, ulong devNo, int response);
52351 void (*device_pause)(ulong busNo, ulong devNo, int response);
52352 void (*device_resume)(ulong busNo, ulong devNo, int response);
52353-} VISORCHIPSET_BUSDEV_RESPONDERS;
52354+} __no_const VISORCHIPSET_BUSDEV_RESPONDERS;
52355
52356 /** Register functions (in the bus driver) to get called by visorchipset
52357 * whenever a bus or device appears for which this service partition is
52358diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
52359index ae0dade..803d53a 100644
52360--- a/drivers/staging/vt6655/hostap.c
52361+++ b/drivers/staging/vt6655/hostap.c
52362@@ -65,14 +65,13 @@
52363 *
52364 */
52365
52366+static net_device_ops_no_const apdev_netdev_ops;
52367+
52368 static int hostap_enable_hostapd(struct vnt_private *pDevice, int rtnl_locked)
52369 {
52370 struct vnt_private *apdev_priv;
52371 struct net_device *dev = pDevice->dev;
52372 int ret;
52373- const struct net_device_ops apdev_netdev_ops = {
52374- .ndo_start_xmit = pDevice->tx_80211,
52375- };
52376
52377 pr_debug("%s: Enabling hostapd mode\n", dev->name);
52378
52379@@ -84,6 +83,8 @@ static int hostap_enable_hostapd(struct vnt_private *pDevice, int rtnl_locked)
52380 *apdev_priv = *pDevice;
52381 eth_hw_addr_inherit(pDevice->apdev, dev);
52382
52383+ /* only half broken now */
52384+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
52385 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
52386
52387 pDevice->apdev->type = ARPHRD_IEEE80211;
52388diff --git a/drivers/target/sbp/sbp_target.c b/drivers/target/sbp/sbp_target.c
52389index e7e9372..161f530 100644
52390--- a/drivers/target/sbp/sbp_target.c
52391+++ b/drivers/target/sbp/sbp_target.c
52392@@ -62,7 +62,7 @@ static const u32 sbp_unit_directory_template[] = {
52393
52394 #define SESSION_MAINTENANCE_INTERVAL HZ
52395
52396-static atomic_t login_id = ATOMIC_INIT(0);
52397+static atomic_unchecked_t login_id = ATOMIC_INIT(0);
52398
52399 static void session_maintenance_work(struct work_struct *);
52400 static int sbp_run_transaction(struct fw_card *, int, int, int, int,
52401@@ -444,7 +444,7 @@ static void sbp_management_request_login(
52402 login->lun = se_lun;
52403 login->status_fifo_addr = sbp2_pointer_to_addr(&req->orb.status_fifo);
52404 login->exclusive = LOGIN_ORB_EXCLUSIVE(be32_to_cpu(req->orb.misc));
52405- login->login_id = atomic_inc_return(&login_id);
52406+ login->login_id = atomic_inc_return_unchecked(&login_id);
52407
52408 login->tgt_agt = sbp_target_agent_register(login);
52409 if (IS_ERR(login->tgt_agt)) {
52410diff --git a/drivers/target/target_core_device.c b/drivers/target/target_core_device.c
52411index c45f9e9..00e85f0 100644
52412--- a/drivers/target/target_core_device.c
52413+++ b/drivers/target/target_core_device.c
52414@@ -1532,7 +1532,7 @@ struct se_device *target_alloc_device(struct se_hba *hba, const char *name)
52415 spin_lock_init(&dev->se_tmr_lock);
52416 spin_lock_init(&dev->qf_cmd_lock);
52417 sema_init(&dev->caw_sem, 1);
52418- atomic_set(&dev->dev_ordered_id, 0);
52419+ atomic_set_unchecked(&dev->dev_ordered_id, 0);
52420 INIT_LIST_HEAD(&dev->t10_wwn.t10_vpd_list);
52421 spin_lock_init(&dev->t10_wwn.t10_vpd_lock);
52422 INIT_LIST_HEAD(&dev->t10_pr.registration_list);
52423diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
52424index be877bf..7be9cd4 100644
52425--- a/drivers/target/target_core_transport.c
52426+++ b/drivers/target/target_core_transport.c
52427@@ -1168,7 +1168,7 @@ transport_check_alloc_task_attr(struct se_cmd *cmd)
52428 * Used to determine when ORDERED commands should go from
52429 * Dormant to Active status.
52430 */
52431- cmd->se_ordered_id = atomic_inc_return(&dev->dev_ordered_id);
52432+ cmd->se_ordered_id = atomic_inc_return_unchecked(&dev->dev_ordered_id);
52433 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
52434 cmd->se_ordered_id, cmd->sam_task_attr,
52435 dev->transport->name);
52436diff --git a/drivers/thermal/int340x_thermal/int3400_thermal.c b/drivers/thermal/int340x_thermal/int3400_thermal.c
52437index edc1cce..769e4cb 100644
52438--- a/drivers/thermal/int340x_thermal/int3400_thermal.c
52439+++ b/drivers/thermal/int340x_thermal/int3400_thermal.c
52440@@ -209,8 +209,10 @@ static int int3400_thermal_probe(struct platform_device *pdev)
52441 platform_set_drvdata(pdev, priv);
52442
52443 if (priv->uuid_bitmap & 1 << INT3400_THERMAL_PASSIVE_1) {
52444- int3400_thermal_ops.get_mode = int3400_thermal_get_mode;
52445- int3400_thermal_ops.set_mode = int3400_thermal_set_mode;
52446+ pax_open_kernel();
52447+ *(void **)&int3400_thermal_ops.get_mode = int3400_thermal_get_mode;
52448+ *(void **)&int3400_thermal_ops.set_mode = int3400_thermal_set_mode;
52449+ pax_close_kernel();
52450 }
52451 priv->thermal = thermal_zone_device_register("INT3400 Thermal", 0, 0,
52452 priv, &int3400_thermal_ops,
52453diff --git a/drivers/thermal/of-thermal.c b/drivers/thermal/of-thermal.c
52454index 62143ba..ae21165 100644
52455--- a/drivers/thermal/of-thermal.c
52456+++ b/drivers/thermal/of-thermal.c
52457@@ -30,6 +30,7 @@
52458 #include <linux/err.h>
52459 #include <linux/export.h>
52460 #include <linux/string.h>
52461+#include <linux/mm.h>
52462
52463 #include "thermal_core.h"
52464
52465@@ -341,8 +342,10 @@ thermal_zone_of_add_sensor(struct device_node *zone,
52466 tz->get_trend = get_trend;
52467 tz->sensor_data = data;
52468
52469- tzd->ops->get_temp = of_thermal_get_temp;
52470- tzd->ops->get_trend = of_thermal_get_trend;
52471+ pax_open_kernel();
52472+ *(void **)&tzd->ops->get_temp = of_thermal_get_temp;
52473+ *(void **)&tzd->ops->get_trend = of_thermal_get_trend;
52474+ pax_close_kernel();
52475 mutex_unlock(&tzd->lock);
52476
52477 return tzd;
52478@@ -473,8 +476,10 @@ void thermal_zone_of_sensor_unregister(struct device *dev,
52479 return;
52480
52481 mutex_lock(&tzd->lock);
52482- tzd->ops->get_temp = NULL;
52483- tzd->ops->get_trend = NULL;
52484+ pax_open_kernel();
52485+ *(void **)&tzd->ops->get_temp = NULL;
52486+ *(void **)&tzd->ops->get_trend = NULL;
52487+ pax_close_kernel();
52488
52489 tz->get_temp = NULL;
52490 tz->get_trend = NULL;
52491diff --git a/drivers/tty/cyclades.c b/drivers/tty/cyclades.c
52492index fd66f57..48e6376 100644
52493--- a/drivers/tty/cyclades.c
52494+++ b/drivers/tty/cyclades.c
52495@@ -1570,10 +1570,10 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
52496 printk(KERN_DEBUG "cyc:cy_open ttyC%d, count = %d\n", info->line,
52497 info->port.count);
52498 #endif
52499- info->port.count++;
52500+ atomic_inc(&info->port.count);
52501 #ifdef CY_DEBUG_COUNT
52502 printk(KERN_DEBUG "cyc:cy_open (%d): incrementing count to %d\n",
52503- current->pid, info->port.count);
52504+ current->pid, atomic_read(&info->port.count));
52505 #endif
52506
52507 /*
52508@@ -3974,7 +3974,7 @@ static int cyclades_proc_show(struct seq_file *m, void *v)
52509 for (j = 0; j < cy_card[i].nports; j++) {
52510 info = &cy_card[i].ports[j];
52511
52512- if (info->port.count) {
52513+ if (atomic_read(&info->port.count)) {
52514 /* XXX is the ldisc num worth this? */
52515 struct tty_struct *tty;
52516 struct tty_ldisc *ld;
52517diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
52518index 4fcec1d..5a036f7 100644
52519--- a/drivers/tty/hvc/hvc_console.c
52520+++ b/drivers/tty/hvc/hvc_console.c
52521@@ -342,7 +342,7 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
52522
52523 spin_lock_irqsave(&hp->port.lock, flags);
52524 /* Check and then increment for fast path open. */
52525- if (hp->port.count++ > 0) {
52526+ if (atomic_inc_return(&hp->port.count) > 1) {
52527 spin_unlock_irqrestore(&hp->port.lock, flags);
52528 hvc_kick();
52529 return 0;
52530@@ -397,7 +397,7 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
52531
52532 spin_lock_irqsave(&hp->port.lock, flags);
52533
52534- if (--hp->port.count == 0) {
52535+ if (atomic_dec_return(&hp->port.count) == 0) {
52536 spin_unlock_irqrestore(&hp->port.lock, flags);
52537 /* We are done with the tty pointer now. */
52538 tty_port_tty_set(&hp->port, NULL);
52539@@ -419,9 +419,9 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
52540 */
52541 tty_wait_until_sent_from_close(tty, HVC_CLOSE_WAIT);
52542 } else {
52543- if (hp->port.count < 0)
52544+ if (atomic_read(&hp->port.count) < 0)
52545 printk(KERN_ERR "hvc_close %X: oops, count is %d\n",
52546- hp->vtermno, hp->port.count);
52547+ hp->vtermno, atomic_read(&hp->port.count));
52548 spin_unlock_irqrestore(&hp->port.lock, flags);
52549 }
52550 }
52551@@ -451,12 +451,12 @@ static void hvc_hangup(struct tty_struct *tty)
52552 * open->hangup case this can be called after the final close so prevent
52553 * that from happening for now.
52554 */
52555- if (hp->port.count <= 0) {
52556+ if (atomic_read(&hp->port.count) <= 0) {
52557 spin_unlock_irqrestore(&hp->port.lock, flags);
52558 return;
52559 }
52560
52561- hp->port.count = 0;
52562+ atomic_set(&hp->port.count, 0);
52563 spin_unlock_irqrestore(&hp->port.lock, flags);
52564 tty_port_tty_set(&hp->port, NULL);
52565
52566@@ -504,7 +504,7 @@ static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count
52567 return -EPIPE;
52568
52569 /* FIXME what's this (unprotected) check for? */
52570- if (hp->port.count <= 0)
52571+ if (atomic_read(&hp->port.count) <= 0)
52572 return -EIO;
52573
52574 spin_lock_irqsave(&hp->lock, flags);
52575diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
52576index 81e939e..95ead10 100644
52577--- a/drivers/tty/hvc/hvcs.c
52578+++ b/drivers/tty/hvc/hvcs.c
52579@@ -83,6 +83,7 @@
52580 #include <asm/hvcserver.h>
52581 #include <asm/uaccess.h>
52582 #include <asm/vio.h>
52583+#include <asm/local.h>
52584
52585 /*
52586 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
52587@@ -416,7 +417,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
52588
52589 spin_lock_irqsave(&hvcsd->lock, flags);
52590
52591- if (hvcsd->port.count > 0) {
52592+ if (atomic_read(&hvcsd->port.count) > 0) {
52593 spin_unlock_irqrestore(&hvcsd->lock, flags);
52594 printk(KERN_INFO "HVCS: vterm state unchanged. "
52595 "The hvcs device node is still in use.\n");
52596@@ -1127,7 +1128,7 @@ static int hvcs_install(struct tty_driver *driver, struct tty_struct *tty)
52597 }
52598 }
52599
52600- hvcsd->port.count = 0;
52601+ atomic_set(&hvcsd->port.count, 0);
52602 hvcsd->port.tty = tty;
52603 tty->driver_data = hvcsd;
52604
52605@@ -1180,7 +1181,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
52606 unsigned long flags;
52607
52608 spin_lock_irqsave(&hvcsd->lock, flags);
52609- hvcsd->port.count++;
52610+ atomic_inc(&hvcsd->port.count);
52611 hvcsd->todo_mask |= HVCS_SCHED_READ;
52612 spin_unlock_irqrestore(&hvcsd->lock, flags);
52613
52614@@ -1216,7 +1217,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
52615 hvcsd = tty->driver_data;
52616
52617 spin_lock_irqsave(&hvcsd->lock, flags);
52618- if (--hvcsd->port.count == 0) {
52619+ if (atomic_dec_and_test(&hvcsd->port.count)) {
52620
52621 vio_disable_interrupts(hvcsd->vdev);
52622
52623@@ -1241,10 +1242,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
52624
52625 free_irq(irq, hvcsd);
52626 return;
52627- } else if (hvcsd->port.count < 0) {
52628+ } else if (atomic_read(&hvcsd->port.count) < 0) {
52629 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
52630 " is missmanaged.\n",
52631- hvcsd->vdev->unit_address, hvcsd->port.count);
52632+ hvcsd->vdev->unit_address, atomic_read(&hvcsd->port.count));
52633 }
52634
52635 spin_unlock_irqrestore(&hvcsd->lock, flags);
52636@@ -1266,7 +1267,7 @@ static void hvcs_hangup(struct tty_struct * tty)
52637
52638 spin_lock_irqsave(&hvcsd->lock, flags);
52639 /* Preserve this so that we know how many kref refs to put */
52640- temp_open_count = hvcsd->port.count;
52641+ temp_open_count = atomic_read(&hvcsd->port.count);
52642
52643 /*
52644 * Don't kref put inside the spinlock because the destruction
52645@@ -1281,7 +1282,7 @@ static void hvcs_hangup(struct tty_struct * tty)
52646 tty->driver_data = NULL;
52647 hvcsd->port.tty = NULL;
52648
52649- hvcsd->port.count = 0;
52650+ atomic_set(&hvcsd->port.count, 0);
52651
52652 /* This will drop any buffered data on the floor which is OK in a hangup
52653 * scenario. */
52654@@ -1352,7 +1353,7 @@ static int hvcs_write(struct tty_struct *tty,
52655 * the middle of a write operation? This is a crummy place to do this
52656 * but we want to keep it all in the spinlock.
52657 */
52658- if (hvcsd->port.count <= 0) {
52659+ if (atomic_read(&hvcsd->port.count) <= 0) {
52660 spin_unlock_irqrestore(&hvcsd->lock, flags);
52661 return -ENODEV;
52662 }
52663@@ -1426,7 +1427,7 @@ static int hvcs_write_room(struct tty_struct *tty)
52664 {
52665 struct hvcs_struct *hvcsd = tty->driver_data;
52666
52667- if (!hvcsd || hvcsd->port.count <= 0)
52668+ if (!hvcsd || atomic_read(&hvcsd->port.count) <= 0)
52669 return 0;
52670
52671 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
52672diff --git a/drivers/tty/hvc/hvsi.c b/drivers/tty/hvc/hvsi.c
52673index 4190199..06d5bfa 100644
52674--- a/drivers/tty/hvc/hvsi.c
52675+++ b/drivers/tty/hvc/hvsi.c
52676@@ -85,7 +85,7 @@ struct hvsi_struct {
52677 int n_outbuf;
52678 uint32_t vtermno;
52679 uint32_t virq;
52680- atomic_t seqno; /* HVSI packet sequence number */
52681+ atomic_unchecked_t seqno; /* HVSI packet sequence number */
52682 uint16_t mctrl;
52683 uint8_t state; /* HVSI protocol state */
52684 uint8_t flags;
52685@@ -295,7 +295,7 @@ static int hvsi_version_respond(struct hvsi_struct *hp, uint16_t query_seqno)
52686
52687 packet.hdr.type = VS_QUERY_RESPONSE_PACKET_HEADER;
52688 packet.hdr.len = sizeof(struct hvsi_query_response);
52689- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
52690+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
52691 packet.verb = VSV_SEND_VERSION_NUMBER;
52692 packet.u.version = HVSI_VERSION;
52693 packet.query_seqno = query_seqno+1;
52694@@ -555,7 +555,7 @@ static int hvsi_query(struct hvsi_struct *hp, uint16_t verb)
52695
52696 packet.hdr.type = VS_QUERY_PACKET_HEADER;
52697 packet.hdr.len = sizeof(struct hvsi_query);
52698- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
52699+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
52700 packet.verb = verb;
52701
52702 pr_debug("%s: sending %i bytes\n", __func__, packet.hdr.len);
52703@@ -597,7 +597,7 @@ static int hvsi_set_mctrl(struct hvsi_struct *hp, uint16_t mctrl)
52704 int wrote;
52705
52706 packet.hdr.type = VS_CONTROL_PACKET_HEADER,
52707- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
52708+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
52709 packet.hdr.len = sizeof(struct hvsi_control);
52710 packet.verb = VSV_SET_MODEM_CTL;
52711 packet.mask = HVSI_TSDTR;
52712@@ -680,7 +680,7 @@ static int hvsi_put_chars(struct hvsi_struct *hp, const char *buf, int count)
52713 BUG_ON(count > HVSI_MAX_OUTGOING_DATA);
52714
52715 packet.hdr.type = VS_DATA_PACKET_HEADER;
52716- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
52717+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
52718 packet.hdr.len = count + sizeof(struct hvsi_header);
52719 memcpy(&packet.data, buf, count);
52720
52721@@ -697,7 +697,7 @@ static void hvsi_close_protocol(struct hvsi_struct *hp)
52722 struct hvsi_control packet __ALIGNED__;
52723
52724 packet.hdr.type = VS_CONTROL_PACKET_HEADER;
52725- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
52726+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
52727 packet.hdr.len = 6;
52728 packet.verb = VSV_CLOSE_PROTOCOL;
52729
52730@@ -725,7 +725,7 @@ static int hvsi_open(struct tty_struct *tty, struct file *filp)
52731
52732 tty_port_tty_set(&hp->port, tty);
52733 spin_lock_irqsave(&hp->lock, flags);
52734- hp->port.count++;
52735+ atomic_inc(&hp->port.count);
52736 atomic_set(&hp->seqno, 0);
52737 h_vio_signal(hp->vtermno, VIO_IRQ_ENABLE);
52738 spin_unlock_irqrestore(&hp->lock, flags);
52739@@ -782,7 +782,7 @@ static void hvsi_close(struct tty_struct *tty, struct file *filp)
52740
52741 spin_lock_irqsave(&hp->lock, flags);
52742
52743- if (--hp->port.count == 0) {
52744+ if (atomic_dec_return(&hp->port.count) == 0) {
52745 tty_port_tty_set(&hp->port, NULL);
52746 hp->inbuf_end = hp->inbuf; /* discard remaining partial packets */
52747
52748@@ -815,9 +815,9 @@ static void hvsi_close(struct tty_struct *tty, struct file *filp)
52749
52750 spin_lock_irqsave(&hp->lock, flags);
52751 }
52752- } else if (hp->port.count < 0)
52753+ } else if (atomic_read(&hp->port.count) < 0)
52754 printk(KERN_ERR "hvsi_close %lu: oops, count is %d\n",
52755- hp - hvsi_ports, hp->port.count);
52756+ hp - hvsi_ports, atomic_read(&hp->port.count));
52757
52758 spin_unlock_irqrestore(&hp->lock, flags);
52759 }
52760@@ -832,7 +832,7 @@ static void hvsi_hangup(struct tty_struct *tty)
52761 tty_port_tty_set(&hp->port, NULL);
52762
52763 spin_lock_irqsave(&hp->lock, flags);
52764- hp->port.count = 0;
52765+ atomic_set(&hp->port.count, 0);
52766 hp->n_outbuf = 0;
52767 spin_unlock_irqrestore(&hp->lock, flags);
52768 }
52769diff --git a/drivers/tty/hvc/hvsi_lib.c b/drivers/tty/hvc/hvsi_lib.c
52770index 7ae6c29..05c6dba 100644
52771--- a/drivers/tty/hvc/hvsi_lib.c
52772+++ b/drivers/tty/hvc/hvsi_lib.c
52773@@ -8,7 +8,7 @@
52774
52775 static int hvsi_send_packet(struct hvsi_priv *pv, struct hvsi_header *packet)
52776 {
52777- packet->seqno = cpu_to_be16(atomic_inc_return(&pv->seqno));
52778+ packet->seqno = cpu_to_be16(atomic_inc_return_unchecked(&pv->seqno));
52779
52780 /* Assumes that always succeeds, works in practice */
52781 return pv->put_chars(pv->termno, (char *)packet, packet->len);
52782@@ -20,7 +20,7 @@ static void hvsi_start_handshake(struct hvsi_priv *pv)
52783
52784 /* Reset state */
52785 pv->established = 0;
52786- atomic_set(&pv->seqno, 0);
52787+ atomic_set_unchecked(&pv->seqno, 0);
52788
52789 pr_devel("HVSI@%x: Handshaking started\n", pv->termno);
52790
52791diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
52792index 345cebb..d5a1e9e 100644
52793--- a/drivers/tty/ipwireless/tty.c
52794+++ b/drivers/tty/ipwireless/tty.c
52795@@ -28,6 +28,7 @@
52796 #include <linux/tty_driver.h>
52797 #include <linux/tty_flip.h>
52798 #include <linux/uaccess.h>
52799+#include <asm/local.h>
52800
52801 #include "tty.h"
52802 #include "network.h"
52803@@ -93,10 +94,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
52804 return -ENODEV;
52805
52806 mutex_lock(&tty->ipw_tty_mutex);
52807- if (tty->port.count == 0)
52808+ if (atomic_read(&tty->port.count) == 0)
52809 tty->tx_bytes_queued = 0;
52810
52811- tty->port.count++;
52812+ atomic_inc(&tty->port.count);
52813
52814 tty->port.tty = linux_tty;
52815 linux_tty->driver_data = tty;
52816@@ -112,9 +113,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
52817
52818 static void do_ipw_close(struct ipw_tty *tty)
52819 {
52820- tty->port.count--;
52821-
52822- if (tty->port.count == 0) {
52823+ if (atomic_dec_return(&tty->port.count) == 0) {
52824 struct tty_struct *linux_tty = tty->port.tty;
52825
52826 if (linux_tty != NULL) {
52827@@ -135,7 +134,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
52828 return;
52829
52830 mutex_lock(&tty->ipw_tty_mutex);
52831- if (tty->port.count == 0) {
52832+ if (atomic_read(&tty->port.count) == 0) {
52833 mutex_unlock(&tty->ipw_tty_mutex);
52834 return;
52835 }
52836@@ -158,7 +157,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
52837
52838 mutex_lock(&tty->ipw_tty_mutex);
52839
52840- if (!tty->port.count) {
52841+ if (!atomic_read(&tty->port.count)) {
52842 mutex_unlock(&tty->ipw_tty_mutex);
52843 return;
52844 }
52845@@ -197,7 +196,7 @@ static int ipw_write(struct tty_struct *linux_tty,
52846 return -ENODEV;
52847
52848 mutex_lock(&tty->ipw_tty_mutex);
52849- if (!tty->port.count) {
52850+ if (!atomic_read(&tty->port.count)) {
52851 mutex_unlock(&tty->ipw_tty_mutex);
52852 return -EINVAL;
52853 }
52854@@ -237,7 +236,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
52855 if (!tty)
52856 return -ENODEV;
52857
52858- if (!tty->port.count)
52859+ if (!atomic_read(&tty->port.count))
52860 return -EINVAL;
52861
52862 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
52863@@ -279,7 +278,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
52864 if (!tty)
52865 return 0;
52866
52867- if (!tty->port.count)
52868+ if (!atomic_read(&tty->port.count))
52869 return 0;
52870
52871 return tty->tx_bytes_queued;
52872@@ -360,7 +359,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
52873 if (!tty)
52874 return -ENODEV;
52875
52876- if (!tty->port.count)
52877+ if (!atomic_read(&tty->port.count))
52878 return -EINVAL;
52879
52880 return get_control_lines(tty);
52881@@ -376,7 +375,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
52882 if (!tty)
52883 return -ENODEV;
52884
52885- if (!tty->port.count)
52886+ if (!atomic_read(&tty->port.count))
52887 return -EINVAL;
52888
52889 return set_control_lines(tty, set, clear);
52890@@ -390,7 +389,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
52891 if (!tty)
52892 return -ENODEV;
52893
52894- if (!tty->port.count)
52895+ if (!atomic_read(&tty->port.count))
52896 return -EINVAL;
52897
52898 /* FIXME: Exactly how is the tty object locked here .. */
52899@@ -546,7 +545,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
52900 * are gone */
52901 mutex_lock(&ttyj->ipw_tty_mutex);
52902 }
52903- while (ttyj->port.count)
52904+ while (atomic_read(&ttyj->port.count))
52905 do_ipw_close(ttyj);
52906 ipwireless_disassociate_network_ttys(network,
52907 ttyj->channel_idx);
52908diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
52909index 14c54e0..1efd4f2 100644
52910--- a/drivers/tty/moxa.c
52911+++ b/drivers/tty/moxa.c
52912@@ -1189,7 +1189,7 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
52913 }
52914
52915 ch = &brd->ports[port % MAX_PORTS_PER_BOARD];
52916- ch->port.count++;
52917+ atomic_inc(&ch->port.count);
52918 tty->driver_data = ch;
52919 tty_port_tty_set(&ch->port, tty);
52920 mutex_lock(&ch->port.mutex);
52921diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
52922index c434376..114ce13 100644
52923--- a/drivers/tty/n_gsm.c
52924+++ b/drivers/tty/n_gsm.c
52925@@ -1644,7 +1644,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
52926 spin_lock_init(&dlci->lock);
52927 mutex_init(&dlci->mutex);
52928 dlci->fifo = &dlci->_fifo;
52929- if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
52930+ if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
52931 kfree(dlci);
52932 return NULL;
52933 }
52934@@ -2958,7 +2958,7 @@ static int gsmtty_open(struct tty_struct *tty, struct file *filp)
52935 struct gsm_dlci *dlci = tty->driver_data;
52936 struct tty_port *port = &dlci->port;
52937
52938- port->count++;
52939+ atomic_inc(&port->count);
52940 tty_port_tty_set(port, tty);
52941
52942 dlci->modem_rx = 0;
52943diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
52944index 47ca0f3..3c0b803 100644
52945--- a/drivers/tty/n_tty.c
52946+++ b/drivers/tty/n_tty.c
52947@@ -115,7 +115,7 @@ struct n_tty_data {
52948 int minimum_to_wake;
52949
52950 /* consumer-published */
52951- size_t read_tail;
52952+ size_t read_tail __intentional_overflow(-1);
52953 size_t line_start;
52954
52955 /* protected by output lock */
52956@@ -2523,6 +2523,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
52957 {
52958 *ops = tty_ldisc_N_TTY;
52959 ops->owner = NULL;
52960- ops->refcount = ops->flags = 0;
52961+ atomic_set(&ops->refcount, 0);
52962+ ops->flags = 0;
52963 }
52964 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
52965diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
52966index 7c4447a..70fbc1e 100644
52967--- a/drivers/tty/pty.c
52968+++ b/drivers/tty/pty.c
52969@@ -830,8 +830,10 @@ static void __init unix98_pty_init(void)
52970 panic("Couldn't register Unix98 pts driver");
52971
52972 /* Now create the /dev/ptmx special device */
52973+ pax_open_kernel();
52974 tty_default_fops(&ptmx_fops);
52975- ptmx_fops.open = ptmx_open;
52976+ *(void **)&ptmx_fops.open = ptmx_open;
52977+ pax_close_kernel();
52978
52979 cdev_init(&ptmx_cdev, &ptmx_fops);
52980 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
52981diff --git a/drivers/tty/rocket.c b/drivers/tty/rocket.c
52982index 383c4c7..d408e21 100644
52983--- a/drivers/tty/rocket.c
52984+++ b/drivers/tty/rocket.c
52985@@ -914,7 +914,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
52986 tty->driver_data = info;
52987 tty_port_tty_set(port, tty);
52988
52989- if (port->count++ == 0) {
52990+ if (atomic_inc_return(&port->count) == 1) {
52991 atomic_inc(&rp_num_ports_open);
52992
52993 #ifdef ROCKET_DEBUG_OPEN
52994@@ -923,7 +923,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
52995 #endif
52996 }
52997 #ifdef ROCKET_DEBUG_OPEN
52998- printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, info->port.count);
52999+ printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, atomic-read(&info->port.count));
53000 #endif
53001
53002 /*
53003@@ -1515,7 +1515,7 @@ static void rp_hangup(struct tty_struct *tty)
53004 spin_unlock_irqrestore(&info->port.lock, flags);
53005 return;
53006 }
53007- if (info->port.count)
53008+ if (atomic_read(&info->port.count))
53009 atomic_dec(&rp_num_ports_open);
53010 clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
53011 spin_unlock_irqrestore(&info->port.lock, flags);
53012diff --git a/drivers/tty/serial/ioc4_serial.c b/drivers/tty/serial/ioc4_serial.c
53013index aa28209..e08fb85 100644
53014--- a/drivers/tty/serial/ioc4_serial.c
53015+++ b/drivers/tty/serial/ioc4_serial.c
53016@@ -437,7 +437,7 @@ struct ioc4_soft {
53017 } is_intr_info[MAX_IOC4_INTR_ENTS];
53018
53019 /* Number of entries active in the above array */
53020- atomic_t is_num_intrs;
53021+ atomic_unchecked_t is_num_intrs;
53022 } is_intr_type[IOC4_NUM_INTR_TYPES];
53023
53024 /* is_ir_lock must be held while
53025@@ -974,7 +974,7 @@ intr_connect(struct ioc4_soft *soft, int type,
53026 BUG_ON(!((type == IOC4_SIO_INTR_TYPE)
53027 || (type == IOC4_OTHER_INTR_TYPE)));
53028
53029- i = atomic_inc_return(&soft-> is_intr_type[type].is_num_intrs) - 1;
53030+ i = atomic_inc_return_unchecked(&soft-> is_intr_type[type].is_num_intrs) - 1;
53031 BUG_ON(!(i < MAX_IOC4_INTR_ENTS || (printk("i %d\n", i), 0)));
53032
53033 /* Save off the lower level interrupt handler */
53034@@ -1001,7 +1001,7 @@ static irqreturn_t ioc4_intr(int irq, void *arg)
53035
53036 soft = arg;
53037 for (intr_type = 0; intr_type < IOC4_NUM_INTR_TYPES; intr_type++) {
53038- num_intrs = (int)atomic_read(
53039+ num_intrs = (int)atomic_read_unchecked(
53040 &soft->is_intr_type[intr_type].is_num_intrs);
53041
53042 this_mir = this_ir = pending_intrs(soft, intr_type);
53043diff --git a/drivers/tty/serial/kgdb_nmi.c b/drivers/tty/serial/kgdb_nmi.c
53044index 129dc5b..1da5bb8 100644
53045--- a/drivers/tty/serial/kgdb_nmi.c
53046+++ b/drivers/tty/serial/kgdb_nmi.c
53047@@ -53,7 +53,9 @@ static int kgdb_nmi_console_setup(struct console *co, char *options)
53048 * I/O utilities that messages sent to the console will automatically
53049 * be displayed on the dbg_io.
53050 */
53051- dbg_io_ops->is_console = true;
53052+ pax_open_kernel();
53053+ *(int *)&dbg_io_ops->is_console = true;
53054+ pax_close_kernel();
53055
53056 return 0;
53057 }
53058diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
53059index a260cde..6b2b5ce 100644
53060--- a/drivers/tty/serial/kgdboc.c
53061+++ b/drivers/tty/serial/kgdboc.c
53062@@ -24,8 +24,9 @@
53063 #define MAX_CONFIG_LEN 40
53064
53065 static struct kgdb_io kgdboc_io_ops;
53066+static struct kgdb_io kgdboc_io_ops_console;
53067
53068-/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
53069+/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
53070 static int configured = -1;
53071
53072 static char config[MAX_CONFIG_LEN];
53073@@ -151,6 +152,8 @@ static void cleanup_kgdboc(void)
53074 kgdboc_unregister_kbd();
53075 if (configured == 1)
53076 kgdb_unregister_io_module(&kgdboc_io_ops);
53077+ else if (configured == 2)
53078+ kgdb_unregister_io_module(&kgdboc_io_ops_console);
53079 }
53080
53081 static int configure_kgdboc(void)
53082@@ -160,13 +163,13 @@ static int configure_kgdboc(void)
53083 int err;
53084 char *cptr = config;
53085 struct console *cons;
53086+ int is_console = 0;
53087
53088 err = kgdboc_option_setup(config);
53089 if (err || !strlen(config) || isspace(config[0]))
53090 goto noconfig;
53091
53092 err = -ENODEV;
53093- kgdboc_io_ops.is_console = 0;
53094 kgdb_tty_driver = NULL;
53095
53096 kgdboc_use_kms = 0;
53097@@ -187,7 +190,7 @@ static int configure_kgdboc(void)
53098 int idx;
53099 if (cons->device && cons->device(cons, &idx) == p &&
53100 idx == tty_line) {
53101- kgdboc_io_ops.is_console = 1;
53102+ is_console = 1;
53103 break;
53104 }
53105 cons = cons->next;
53106@@ -197,7 +200,13 @@ static int configure_kgdboc(void)
53107 kgdb_tty_line = tty_line;
53108
53109 do_register:
53110- err = kgdb_register_io_module(&kgdboc_io_ops);
53111+ if (is_console) {
53112+ err = kgdb_register_io_module(&kgdboc_io_ops_console);
53113+ configured = 2;
53114+ } else {
53115+ err = kgdb_register_io_module(&kgdboc_io_ops);
53116+ configured = 1;
53117+ }
53118 if (err)
53119 goto noconfig;
53120
53121@@ -205,8 +214,6 @@ do_register:
53122 if (err)
53123 goto nmi_con_failed;
53124
53125- configured = 1;
53126-
53127 return 0;
53128
53129 nmi_con_failed:
53130@@ -223,7 +230,7 @@ noconfig:
53131 static int __init init_kgdboc(void)
53132 {
53133 /* Already configured? */
53134- if (configured == 1)
53135+ if (configured >= 1)
53136 return 0;
53137
53138 return configure_kgdboc();
53139@@ -272,7 +279,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
53140 if (config[len - 1] == '\n')
53141 config[len - 1] = '\0';
53142
53143- if (configured == 1)
53144+ if (configured >= 1)
53145 cleanup_kgdboc();
53146
53147 /* Go and configure with the new params. */
53148@@ -312,6 +319,15 @@ static struct kgdb_io kgdboc_io_ops = {
53149 .post_exception = kgdboc_post_exp_handler,
53150 };
53151
53152+static struct kgdb_io kgdboc_io_ops_console = {
53153+ .name = "kgdboc",
53154+ .read_char = kgdboc_get_char,
53155+ .write_char = kgdboc_put_char,
53156+ .pre_exception = kgdboc_pre_exp_handler,
53157+ .post_exception = kgdboc_post_exp_handler,
53158+ .is_console = 1
53159+};
53160+
53161 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
53162 /* This is only available if kgdboc is a built in for early debugging */
53163 static int __init kgdboc_early_init(char *opt)
53164diff --git a/drivers/tty/serial/msm_serial.c b/drivers/tty/serial/msm_serial.c
53165index 4b6c783..9a19db3 100644
53166--- a/drivers/tty/serial/msm_serial.c
53167+++ b/drivers/tty/serial/msm_serial.c
53168@@ -1028,7 +1028,7 @@ static struct uart_driver msm_uart_driver = {
53169 .cons = MSM_CONSOLE,
53170 };
53171
53172-static atomic_t msm_uart_next_id = ATOMIC_INIT(0);
53173+static atomic_unchecked_t msm_uart_next_id = ATOMIC_INIT(0);
53174
53175 static const struct of_device_id msm_uartdm_table[] = {
53176 { .compatible = "qcom,msm-uartdm-v1.1", .data = (void *)UARTDM_1P1 },
53177@@ -1047,7 +1047,7 @@ static int msm_serial_probe(struct platform_device *pdev)
53178 int irq;
53179
53180 if (pdev->id == -1)
53181- pdev->id = atomic_inc_return(&msm_uart_next_id) - 1;
53182+ pdev->id = atomic_inc_return_unchecked(&msm_uart_next_id) - 1;
53183
53184 if (unlikely(pdev->id < 0 || pdev->id >= UART_NR))
53185 return -ENXIO;
53186diff --git a/drivers/tty/serial/samsung.c b/drivers/tty/serial/samsung.c
53187index 587d63b..48423a6 100644
53188--- a/drivers/tty/serial/samsung.c
53189+++ b/drivers/tty/serial/samsung.c
53190@@ -478,11 +478,16 @@ static void s3c24xx_serial_shutdown(struct uart_port *port)
53191 }
53192 }
53193
53194+static int s3c64xx_serial_startup(struct uart_port *port);
53195 static int s3c24xx_serial_startup(struct uart_port *port)
53196 {
53197 struct s3c24xx_uart_port *ourport = to_ourport(port);
53198 int ret;
53199
53200+ /* Startup sequence is different for s3c64xx and higher SoC's */
53201+ if (s3c24xx_serial_has_interrupt_mask(port))
53202+ return s3c64xx_serial_startup(port);
53203+
53204 dbg("s3c24xx_serial_startup: port=%p (%08llx,%p)\n",
53205 port, (unsigned long long)port->mapbase, port->membase);
53206
53207@@ -1159,10 +1164,6 @@ static int s3c24xx_serial_init_port(struct s3c24xx_uart_port *ourport,
53208 /* setup info for port */
53209 port->dev = &platdev->dev;
53210
53211- /* Startup sequence is different for s3c64xx and higher SoC's */
53212- if (s3c24xx_serial_has_interrupt_mask(port))
53213- s3c24xx_serial_ops.startup = s3c64xx_serial_startup;
53214-
53215 port->uartclk = 1;
53216
53217 if (cfg->uart_flags & UPF_CONS_FLOW) {
53218diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
53219index eaeb9a0..01a238c 100644
53220--- a/drivers/tty/serial/serial_core.c
53221+++ b/drivers/tty/serial/serial_core.c
53222@@ -1339,7 +1339,7 @@ static void uart_close(struct tty_struct *tty, struct file *filp)
53223
53224 pr_debug("uart_close(%d) called\n", uport ? uport->line : -1);
53225
53226- if (!port->count || tty_port_close_start(port, tty, filp) == 0)
53227+ if (!atomic_read(&port->count) || tty_port_close_start(port, tty, filp) == 0)
53228 return;
53229
53230 /*
53231@@ -1466,7 +1466,7 @@ static void uart_hangup(struct tty_struct *tty)
53232 uart_flush_buffer(tty);
53233 uart_shutdown(tty, state);
53234 spin_lock_irqsave(&port->lock, flags);
53235- port->count = 0;
53236+ atomic_set(&port->count, 0);
53237 clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
53238 spin_unlock_irqrestore(&port->lock, flags);
53239 tty_port_tty_set(port, NULL);
53240@@ -1564,7 +1564,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
53241 goto end;
53242 }
53243
53244- port->count++;
53245+ atomic_inc(&port->count);
53246 if (!state->uart_port || state->uart_port->flags & UPF_DEAD) {
53247 retval = -ENXIO;
53248 goto err_dec_count;
53249@@ -1596,7 +1596,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
53250 end:
53251 return retval;
53252 err_dec_count:
53253- port->count--;
53254+ atomic_dec(&port->count);
53255 mutex_unlock(&port->mutex);
53256 goto end;
53257 }
53258diff --git a/drivers/tty/synclink.c b/drivers/tty/synclink.c
53259index b799170..87dafd5 100644
53260--- a/drivers/tty/synclink.c
53261+++ b/drivers/tty/synclink.c
53262@@ -3090,7 +3090,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
53263
53264 if (debug_level >= DEBUG_LEVEL_INFO)
53265 printk("%s(%d):mgsl_close(%s) entry, count=%d\n",
53266- __FILE__,__LINE__, info->device_name, info->port.count);
53267+ __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
53268
53269 if (tty_port_close_start(&info->port, tty, filp) == 0)
53270 goto cleanup;
53271@@ -3108,7 +3108,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
53272 cleanup:
53273 if (debug_level >= DEBUG_LEVEL_INFO)
53274 printk("%s(%d):mgsl_close(%s) exit, count=%d\n", __FILE__,__LINE__,
53275- tty->driver->name, info->port.count);
53276+ tty->driver->name, atomic_read(&info->port.count));
53277
53278 } /* end of mgsl_close() */
53279
53280@@ -3207,8 +3207,8 @@ static void mgsl_hangup(struct tty_struct *tty)
53281
53282 mgsl_flush_buffer(tty);
53283 shutdown(info);
53284-
53285- info->port.count = 0;
53286+
53287+ atomic_set(&info->port.count, 0);
53288 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
53289 info->port.tty = NULL;
53290
53291@@ -3296,10 +3296,10 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
53292
53293 if (debug_level >= DEBUG_LEVEL_INFO)
53294 printk("%s(%d):block_til_ready before block on %s count=%d\n",
53295- __FILE__,__LINE__, tty->driver->name, port->count );
53296+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
53297
53298 spin_lock_irqsave(&info->irq_spinlock, flags);
53299- port->count--;
53300+ atomic_dec(&port->count);
53301 spin_unlock_irqrestore(&info->irq_spinlock, flags);
53302 port->blocked_open++;
53303
53304@@ -3327,7 +3327,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
53305
53306 if (debug_level >= DEBUG_LEVEL_INFO)
53307 printk("%s(%d):block_til_ready blocking on %s count=%d\n",
53308- __FILE__,__LINE__, tty->driver->name, port->count );
53309+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
53310
53311 tty_unlock(tty);
53312 schedule();
53313@@ -3339,12 +3339,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
53314
53315 /* FIXME: Racy on hangup during close wait */
53316 if (!tty_hung_up_p(filp))
53317- port->count++;
53318+ atomic_inc(&port->count);
53319 port->blocked_open--;
53320
53321 if (debug_level >= DEBUG_LEVEL_INFO)
53322 printk("%s(%d):block_til_ready after blocking on %s count=%d\n",
53323- __FILE__,__LINE__, tty->driver->name, port->count );
53324+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
53325
53326 if (!retval)
53327 port->flags |= ASYNC_NORMAL_ACTIVE;
53328@@ -3396,7 +3396,7 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
53329
53330 if (debug_level >= DEBUG_LEVEL_INFO)
53331 printk("%s(%d):mgsl_open(%s), old ref count = %d\n",
53332- __FILE__,__LINE__,tty->driver->name, info->port.count);
53333+ __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
53334
53335 /* If port is closing, signal caller to try again */
53336 if (info->port.flags & ASYNC_CLOSING){
53337@@ -3415,10 +3415,10 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
53338 spin_unlock_irqrestore(&info->netlock, flags);
53339 goto cleanup;
53340 }
53341- info->port.count++;
53342+ atomic_inc(&info->port.count);
53343 spin_unlock_irqrestore(&info->netlock, flags);
53344
53345- if (info->port.count == 1) {
53346+ if (atomic_read(&info->port.count) == 1) {
53347 /* 1st open on this device, init hardware */
53348 retval = startup(info);
53349 if (retval < 0)
53350@@ -3442,8 +3442,8 @@ cleanup:
53351 if (retval) {
53352 if (tty->count == 1)
53353 info->port.tty = NULL; /* tty layer will release tty struct */
53354- if(info->port.count)
53355- info->port.count--;
53356+ if (atomic_read(&info->port.count))
53357+ atomic_dec(&info->port.count);
53358 }
53359
53360 return retval;
53361@@ -7661,7 +7661,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
53362 unsigned short new_crctype;
53363
53364 /* return error if TTY interface open */
53365- if (info->port.count)
53366+ if (atomic_read(&info->port.count))
53367 return -EBUSY;
53368
53369 switch (encoding)
53370@@ -7756,7 +7756,7 @@ static int hdlcdev_open(struct net_device *dev)
53371
53372 /* arbitrate between network and tty opens */
53373 spin_lock_irqsave(&info->netlock, flags);
53374- if (info->port.count != 0 || info->netcount != 0) {
53375+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
53376 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
53377 spin_unlock_irqrestore(&info->netlock, flags);
53378 return -EBUSY;
53379@@ -7842,7 +7842,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
53380 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
53381
53382 /* return error if TTY interface open */
53383- if (info->port.count)
53384+ if (atomic_read(&info->port.count))
53385 return -EBUSY;
53386
53387 if (cmd != SIOCWANDEV)
53388diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
53389index 0e8c39b..e0cb171 100644
53390--- a/drivers/tty/synclink_gt.c
53391+++ b/drivers/tty/synclink_gt.c
53392@@ -670,7 +670,7 @@ static int open(struct tty_struct *tty, struct file *filp)
53393 tty->driver_data = info;
53394 info->port.tty = tty;
53395
53396- DBGINFO(("%s open, old ref count = %d\n", info->device_name, info->port.count));
53397+ DBGINFO(("%s open, old ref count = %d\n", info->device_name, atomic_read(&info->port.count)));
53398
53399 /* If port is closing, signal caller to try again */
53400 if (info->port.flags & ASYNC_CLOSING){
53401@@ -691,10 +691,10 @@ static int open(struct tty_struct *tty, struct file *filp)
53402 mutex_unlock(&info->port.mutex);
53403 goto cleanup;
53404 }
53405- info->port.count++;
53406+ atomic_inc(&info->port.count);
53407 spin_unlock_irqrestore(&info->netlock, flags);
53408
53409- if (info->port.count == 1) {
53410+ if (atomic_read(&info->port.count) == 1) {
53411 /* 1st open on this device, init hardware */
53412 retval = startup(info);
53413 if (retval < 0) {
53414@@ -715,8 +715,8 @@ cleanup:
53415 if (retval) {
53416 if (tty->count == 1)
53417 info->port.tty = NULL; /* tty layer will release tty struct */
53418- if(info->port.count)
53419- info->port.count--;
53420+ if(atomic_read(&info->port.count))
53421+ atomic_dec(&info->port.count);
53422 }
53423
53424 DBGINFO(("%s open rc=%d\n", info->device_name, retval));
53425@@ -729,7 +729,7 @@ static void close(struct tty_struct *tty, struct file *filp)
53426
53427 if (sanity_check(info, tty->name, "close"))
53428 return;
53429- DBGINFO(("%s close entry, count=%d\n", info->device_name, info->port.count));
53430+ DBGINFO(("%s close entry, count=%d\n", info->device_name, atomic_read(&info->port.count)));
53431
53432 if (tty_port_close_start(&info->port, tty, filp) == 0)
53433 goto cleanup;
53434@@ -746,7 +746,7 @@ static void close(struct tty_struct *tty, struct file *filp)
53435 tty_port_close_end(&info->port, tty);
53436 info->port.tty = NULL;
53437 cleanup:
53438- DBGINFO(("%s close exit, count=%d\n", tty->driver->name, info->port.count));
53439+ DBGINFO(("%s close exit, count=%d\n", tty->driver->name, atomic_read(&info->port.count)));
53440 }
53441
53442 static void hangup(struct tty_struct *tty)
53443@@ -764,7 +764,7 @@ static void hangup(struct tty_struct *tty)
53444 shutdown(info);
53445
53446 spin_lock_irqsave(&info->port.lock, flags);
53447- info->port.count = 0;
53448+ atomic_set(&info->port.count, 0);
53449 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
53450 info->port.tty = NULL;
53451 spin_unlock_irqrestore(&info->port.lock, flags);
53452@@ -1449,7 +1449,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
53453 unsigned short new_crctype;
53454
53455 /* return error if TTY interface open */
53456- if (info->port.count)
53457+ if (atomic_read(&info->port.count))
53458 return -EBUSY;
53459
53460 DBGINFO(("%s hdlcdev_attach\n", info->device_name));
53461@@ -1544,7 +1544,7 @@ static int hdlcdev_open(struct net_device *dev)
53462
53463 /* arbitrate between network and tty opens */
53464 spin_lock_irqsave(&info->netlock, flags);
53465- if (info->port.count != 0 || info->netcount != 0) {
53466+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
53467 DBGINFO(("%s hdlc_open busy\n", dev->name));
53468 spin_unlock_irqrestore(&info->netlock, flags);
53469 return -EBUSY;
53470@@ -1629,7 +1629,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
53471 DBGINFO(("%s hdlcdev_ioctl\n", dev->name));
53472
53473 /* return error if TTY interface open */
53474- if (info->port.count)
53475+ if (atomic_read(&info->port.count))
53476 return -EBUSY;
53477
53478 if (cmd != SIOCWANDEV)
53479@@ -2413,7 +2413,7 @@ static irqreturn_t slgt_interrupt(int dummy, void *dev_id)
53480 if (port == NULL)
53481 continue;
53482 spin_lock(&port->lock);
53483- if ((port->port.count || port->netcount) &&
53484+ if ((atomic_read(&port->port.count) || port->netcount) &&
53485 port->pending_bh && !port->bh_running &&
53486 !port->bh_requested) {
53487 DBGISR(("%s bh queued\n", port->device_name));
53488@@ -3299,7 +3299,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
53489 add_wait_queue(&port->open_wait, &wait);
53490
53491 spin_lock_irqsave(&info->lock, flags);
53492- port->count--;
53493+ atomic_dec(&port->count);
53494 spin_unlock_irqrestore(&info->lock, flags);
53495 port->blocked_open++;
53496
53497@@ -3335,7 +3335,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
53498 remove_wait_queue(&port->open_wait, &wait);
53499
53500 if (!tty_hung_up_p(filp))
53501- port->count++;
53502+ atomic_inc(&port->count);
53503 port->blocked_open--;
53504
53505 if (!retval)
53506diff --git a/drivers/tty/synclinkmp.c b/drivers/tty/synclinkmp.c
53507index c3f9091..abe4601 100644
53508--- a/drivers/tty/synclinkmp.c
53509+++ b/drivers/tty/synclinkmp.c
53510@@ -750,7 +750,7 @@ static int open(struct tty_struct *tty, struct file *filp)
53511
53512 if (debug_level >= DEBUG_LEVEL_INFO)
53513 printk("%s(%d):%s open(), old ref count = %d\n",
53514- __FILE__,__LINE__,tty->driver->name, info->port.count);
53515+ __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
53516
53517 /* If port is closing, signal caller to try again */
53518 if (info->port.flags & ASYNC_CLOSING){
53519@@ -769,10 +769,10 @@ static int open(struct tty_struct *tty, struct file *filp)
53520 spin_unlock_irqrestore(&info->netlock, flags);
53521 goto cleanup;
53522 }
53523- info->port.count++;
53524+ atomic_inc(&info->port.count);
53525 spin_unlock_irqrestore(&info->netlock, flags);
53526
53527- if (info->port.count == 1) {
53528+ if (atomic_read(&info->port.count) == 1) {
53529 /* 1st open on this device, init hardware */
53530 retval = startup(info);
53531 if (retval < 0)
53532@@ -796,8 +796,8 @@ cleanup:
53533 if (retval) {
53534 if (tty->count == 1)
53535 info->port.tty = NULL; /* tty layer will release tty struct */
53536- if(info->port.count)
53537- info->port.count--;
53538+ if(atomic_read(&info->port.count))
53539+ atomic_dec(&info->port.count);
53540 }
53541
53542 return retval;
53543@@ -815,7 +815,7 @@ static void close(struct tty_struct *tty, struct file *filp)
53544
53545 if (debug_level >= DEBUG_LEVEL_INFO)
53546 printk("%s(%d):%s close() entry, count=%d\n",
53547- __FILE__,__LINE__, info->device_name, info->port.count);
53548+ __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
53549
53550 if (tty_port_close_start(&info->port, tty, filp) == 0)
53551 goto cleanup;
53552@@ -834,7 +834,7 @@ static void close(struct tty_struct *tty, struct file *filp)
53553 cleanup:
53554 if (debug_level >= DEBUG_LEVEL_INFO)
53555 printk("%s(%d):%s close() exit, count=%d\n", __FILE__,__LINE__,
53556- tty->driver->name, info->port.count);
53557+ tty->driver->name, atomic_read(&info->port.count));
53558 }
53559
53560 /* Called by tty_hangup() when a hangup is signaled.
53561@@ -857,7 +857,7 @@ static void hangup(struct tty_struct *tty)
53562 shutdown(info);
53563
53564 spin_lock_irqsave(&info->port.lock, flags);
53565- info->port.count = 0;
53566+ atomic_set(&info->port.count, 0);
53567 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
53568 info->port.tty = NULL;
53569 spin_unlock_irqrestore(&info->port.lock, flags);
53570@@ -1565,7 +1565,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
53571 unsigned short new_crctype;
53572
53573 /* return error if TTY interface open */
53574- if (info->port.count)
53575+ if (atomic_read(&info->port.count))
53576 return -EBUSY;
53577
53578 switch (encoding)
53579@@ -1660,7 +1660,7 @@ static int hdlcdev_open(struct net_device *dev)
53580
53581 /* arbitrate between network and tty opens */
53582 spin_lock_irqsave(&info->netlock, flags);
53583- if (info->port.count != 0 || info->netcount != 0) {
53584+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
53585 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
53586 spin_unlock_irqrestore(&info->netlock, flags);
53587 return -EBUSY;
53588@@ -1746,7 +1746,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
53589 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
53590
53591 /* return error if TTY interface open */
53592- if (info->port.count)
53593+ if (atomic_read(&info->port.count))
53594 return -EBUSY;
53595
53596 if (cmd != SIOCWANDEV)
53597@@ -2621,7 +2621,7 @@ static irqreturn_t synclinkmp_interrupt(int dummy, void *dev_id)
53598 * do not request bottom half processing if the
53599 * device is not open in a normal mode.
53600 */
53601- if ( port && (port->port.count || port->netcount) &&
53602+ if ( port && (atomic_read(&port->port.count) || port->netcount) &&
53603 port->pending_bh && !port->bh_running &&
53604 !port->bh_requested ) {
53605 if ( debug_level >= DEBUG_LEVEL_ISR )
53606@@ -3318,10 +3318,10 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
53607
53608 if (debug_level >= DEBUG_LEVEL_INFO)
53609 printk("%s(%d):%s block_til_ready() before block, count=%d\n",
53610- __FILE__,__LINE__, tty->driver->name, port->count );
53611+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
53612
53613 spin_lock_irqsave(&info->lock, flags);
53614- port->count--;
53615+ atomic_dec(&port->count);
53616 spin_unlock_irqrestore(&info->lock, flags);
53617 port->blocked_open++;
53618
53619@@ -3349,7 +3349,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
53620
53621 if (debug_level >= DEBUG_LEVEL_INFO)
53622 printk("%s(%d):%s block_til_ready() count=%d\n",
53623- __FILE__,__LINE__, tty->driver->name, port->count );
53624+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
53625
53626 tty_unlock(tty);
53627 schedule();
53628@@ -3359,12 +3359,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
53629 set_current_state(TASK_RUNNING);
53630 remove_wait_queue(&port->open_wait, &wait);
53631 if (!tty_hung_up_p(filp))
53632- port->count++;
53633+ atomic_inc(&port->count);
53634 port->blocked_open--;
53635
53636 if (debug_level >= DEBUG_LEVEL_INFO)
53637 printk("%s(%d):%s block_til_ready() after, count=%d\n",
53638- __FILE__,__LINE__, tty->driver->name, port->count );
53639+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
53640
53641 if (!retval)
53642 port->flags |= ASYNC_NORMAL_ACTIVE;
53643diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
53644index 42bad18..447d7a2 100644
53645--- a/drivers/tty/sysrq.c
53646+++ b/drivers/tty/sysrq.c
53647@@ -1084,7 +1084,7 @@ EXPORT_SYMBOL(unregister_sysrq_key);
53648 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
53649 size_t count, loff_t *ppos)
53650 {
53651- if (count) {
53652+ if (count && capable(CAP_SYS_ADMIN)) {
53653 char c;
53654
53655 if (get_user(c, buf))
53656diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
53657index 0508a1d..b610592 100644
53658--- a/drivers/tty/tty_io.c
53659+++ b/drivers/tty/tty_io.c
53660@@ -3498,7 +3498,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
53661
53662 void tty_default_fops(struct file_operations *fops)
53663 {
53664- *fops = tty_fops;
53665+ memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
53666 }
53667
53668 /*
53669diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
53670index 2d822aa..a566234 100644
53671--- a/drivers/tty/tty_ldisc.c
53672+++ b/drivers/tty/tty_ldisc.c
53673@@ -71,7 +71,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
53674 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
53675 tty_ldiscs[disc] = new_ldisc;
53676 new_ldisc->num = disc;
53677- new_ldisc->refcount = 0;
53678+ atomic_set(&new_ldisc->refcount, 0);
53679 raw_spin_unlock_irqrestore(&tty_ldiscs_lock, flags);
53680
53681 return ret;
53682@@ -99,7 +99,7 @@ int tty_unregister_ldisc(int disc)
53683 return -EINVAL;
53684
53685 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
53686- if (tty_ldiscs[disc]->refcount)
53687+ if (atomic_read(&tty_ldiscs[disc]->refcount))
53688 ret = -EBUSY;
53689 else
53690 tty_ldiscs[disc] = NULL;
53691@@ -120,7 +120,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
53692 if (ldops) {
53693 ret = ERR_PTR(-EAGAIN);
53694 if (try_module_get(ldops->owner)) {
53695- ldops->refcount++;
53696+ atomic_inc(&ldops->refcount);
53697 ret = ldops;
53698 }
53699 }
53700@@ -133,7 +133,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
53701 unsigned long flags;
53702
53703 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
53704- ldops->refcount--;
53705+ atomic_dec(&ldops->refcount);
53706 module_put(ldops->owner);
53707 raw_spin_unlock_irqrestore(&tty_ldiscs_lock, flags);
53708 }
53709diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
53710index 1b93357..ea9f82c 100644
53711--- a/drivers/tty/tty_port.c
53712+++ b/drivers/tty/tty_port.c
53713@@ -237,7 +237,7 @@ void tty_port_hangup(struct tty_port *port)
53714 unsigned long flags;
53715
53716 spin_lock_irqsave(&port->lock, flags);
53717- port->count = 0;
53718+ atomic_set(&port->count, 0);
53719 port->flags &= ~ASYNC_NORMAL_ACTIVE;
53720 tty = port->tty;
53721 if (tty)
53722@@ -399,7 +399,7 @@ int tty_port_block_til_ready(struct tty_port *port,
53723
53724 /* The port lock protects the port counts */
53725 spin_lock_irqsave(&port->lock, flags);
53726- port->count--;
53727+ atomic_dec(&port->count);
53728 port->blocked_open++;
53729 spin_unlock_irqrestore(&port->lock, flags);
53730
53731@@ -441,7 +441,7 @@ int tty_port_block_til_ready(struct tty_port *port,
53732 we must not mess that up further */
53733 spin_lock_irqsave(&port->lock, flags);
53734 if (!tty_hung_up_p(filp))
53735- port->count++;
53736+ atomic_inc(&port->count);
53737 port->blocked_open--;
53738 if (retval == 0)
53739 port->flags |= ASYNC_NORMAL_ACTIVE;
53740@@ -479,19 +479,19 @@ int tty_port_close_start(struct tty_port *port,
53741 return 0;
53742 }
53743
53744- if (tty->count == 1 && port->count != 1) {
53745+ if (tty->count == 1 && atomic_read(&port->count) != 1) {
53746 printk(KERN_WARNING
53747 "tty_port_close_start: tty->count = 1 port count = %d.\n",
53748- port->count);
53749- port->count = 1;
53750+ atomic_read(&port->count));
53751+ atomic_set(&port->count, 1);
53752 }
53753- if (--port->count < 0) {
53754+ if (atomic_dec_return(&port->count) < 0) {
53755 printk(KERN_WARNING "tty_port_close_start: count = %d\n",
53756- port->count);
53757- port->count = 0;
53758+ atomic_read(&port->count));
53759+ atomic_set(&port->count, 0);
53760 }
53761
53762- if (port->count) {
53763+ if (atomic_read(&port->count)) {
53764 spin_unlock_irqrestore(&port->lock, flags);
53765 return 0;
53766 }
53767@@ -592,7 +592,7 @@ int tty_port_open(struct tty_port *port, struct tty_struct *tty,
53768 struct file *filp)
53769 {
53770 spin_lock_irq(&port->lock);
53771- ++port->count;
53772+ atomic_inc(&port->count);
53773 spin_unlock_irq(&port->lock);
53774 tty_port_tty_set(port, tty);
53775
53776diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
53777index c039cfe..0b463b0 100644
53778--- a/drivers/tty/vt/keyboard.c
53779+++ b/drivers/tty/vt/keyboard.c
53780@@ -641,6 +641,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
53781 kbd->kbdmode == VC_OFF) &&
53782 value != KVAL(K_SAK))
53783 return; /* SAK is allowed even in raw mode */
53784+
53785+#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
53786+ {
53787+ void *func = fn_handler[value];
53788+ if (func == fn_show_state || func == fn_show_ptregs ||
53789+ func == fn_show_mem)
53790+ return;
53791+ }
53792+#endif
53793+
53794 fn_handler[value](vc);
53795 }
53796
53797@@ -1776,9 +1786,6 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
53798 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
53799 return -EFAULT;
53800
53801- if (!capable(CAP_SYS_TTY_CONFIG))
53802- perm = 0;
53803-
53804 switch (cmd) {
53805 case KDGKBENT:
53806 /* Ensure another thread doesn't free it under us */
53807@@ -1793,6 +1800,9 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
53808 spin_unlock_irqrestore(&kbd_event_lock, flags);
53809 return put_user(val, &user_kbe->kb_value);
53810 case KDSKBENT:
53811+ if (!capable(CAP_SYS_TTY_CONFIG))
53812+ perm = 0;
53813+
53814 if (!perm)
53815 return -EPERM;
53816 if (!i && v == K_NOSUCHMAP) {
53817@@ -1883,9 +1893,6 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
53818 int i, j, k;
53819 int ret;
53820
53821- if (!capable(CAP_SYS_TTY_CONFIG))
53822- perm = 0;
53823-
53824 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
53825 if (!kbs) {
53826 ret = -ENOMEM;
53827@@ -1919,6 +1926,9 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
53828 kfree(kbs);
53829 return ((p && *p) ? -EOVERFLOW : 0);
53830 case KDSKBSENT:
53831+ if (!capable(CAP_SYS_TTY_CONFIG))
53832+ perm = 0;
53833+
53834 if (!perm) {
53835 ret = -EPERM;
53836 goto reterr;
53837diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
53838index 60fa627..7214965 100644
53839--- a/drivers/uio/uio.c
53840+++ b/drivers/uio/uio.c
53841@@ -25,6 +25,7 @@
53842 #include <linux/kobject.h>
53843 #include <linux/cdev.h>
53844 #include <linux/uio_driver.h>
53845+#include <asm/local.h>
53846
53847 #define UIO_MAX_DEVICES (1U << MINORBITS)
53848
53849@@ -231,7 +232,7 @@ static ssize_t event_show(struct device *dev,
53850 struct device_attribute *attr, char *buf)
53851 {
53852 struct uio_device *idev = dev_get_drvdata(dev);
53853- return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
53854+ return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
53855 }
53856 static DEVICE_ATTR_RO(event);
53857
53858@@ -393,7 +394,7 @@ void uio_event_notify(struct uio_info *info)
53859 {
53860 struct uio_device *idev = info->uio_dev;
53861
53862- atomic_inc(&idev->event);
53863+ atomic_inc_unchecked(&idev->event);
53864 wake_up_interruptible(&idev->wait);
53865 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
53866 }
53867@@ -446,7 +447,7 @@ static int uio_open(struct inode *inode, struct file *filep)
53868 }
53869
53870 listener->dev = idev;
53871- listener->event_count = atomic_read(&idev->event);
53872+ listener->event_count = atomic_read_unchecked(&idev->event);
53873 filep->private_data = listener;
53874
53875 if (idev->info->open) {
53876@@ -497,7 +498,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
53877 return -EIO;
53878
53879 poll_wait(filep, &idev->wait, wait);
53880- if (listener->event_count != atomic_read(&idev->event))
53881+ if (listener->event_count != atomic_read_unchecked(&idev->event))
53882 return POLLIN | POLLRDNORM;
53883 return 0;
53884 }
53885@@ -522,7 +523,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
53886 do {
53887 set_current_state(TASK_INTERRUPTIBLE);
53888
53889- event_count = atomic_read(&idev->event);
53890+ event_count = atomic_read_unchecked(&idev->event);
53891 if (event_count != listener->event_count) {
53892 if (copy_to_user(buf, &event_count, count))
53893 retval = -EFAULT;
53894@@ -579,9 +580,13 @@ static ssize_t uio_write(struct file *filep, const char __user *buf,
53895 static int uio_find_mem_index(struct vm_area_struct *vma)
53896 {
53897 struct uio_device *idev = vma->vm_private_data;
53898+ unsigned long size;
53899
53900 if (vma->vm_pgoff < MAX_UIO_MAPS) {
53901- if (idev->info->mem[vma->vm_pgoff].size == 0)
53902+ size = idev->info->mem[vma->vm_pgoff].size;
53903+ if (size == 0)
53904+ return -1;
53905+ if (vma->vm_end - vma->vm_start > size)
53906 return -1;
53907 return (int)vma->vm_pgoff;
53908 }
53909@@ -813,7 +818,7 @@ int __uio_register_device(struct module *owner,
53910 idev->owner = owner;
53911 idev->info = info;
53912 init_waitqueue_head(&idev->wait);
53913- atomic_set(&idev->event, 0);
53914+ atomic_set_unchecked(&idev->event, 0);
53915
53916 ret = uio_get_minor(idev);
53917 if (ret)
53918diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
53919index 813d4d3..a71934f 100644
53920--- a/drivers/usb/atm/cxacru.c
53921+++ b/drivers/usb/atm/cxacru.c
53922@@ -472,7 +472,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
53923 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
53924 if (ret < 2)
53925 return -EINVAL;
53926- if (index < 0 || index > 0x7f)
53927+ if (index > 0x7f)
53928 return -EINVAL;
53929 pos += tmp;
53930
53931diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
53932index dada014..1d0d517 100644
53933--- a/drivers/usb/atm/usbatm.c
53934+++ b/drivers/usb/atm/usbatm.c
53935@@ -331,7 +331,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
53936 if (printk_ratelimit())
53937 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
53938 __func__, vpi, vci);
53939- atomic_inc(&vcc->stats->rx_err);
53940+ atomic_inc_unchecked(&vcc->stats->rx_err);
53941 return;
53942 }
53943
53944@@ -358,7 +358,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
53945 if (length > ATM_MAX_AAL5_PDU) {
53946 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
53947 __func__, length, vcc);
53948- atomic_inc(&vcc->stats->rx_err);
53949+ atomic_inc_unchecked(&vcc->stats->rx_err);
53950 goto out;
53951 }
53952
53953@@ -367,14 +367,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
53954 if (sarb->len < pdu_length) {
53955 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
53956 __func__, pdu_length, sarb->len, vcc);
53957- atomic_inc(&vcc->stats->rx_err);
53958+ atomic_inc_unchecked(&vcc->stats->rx_err);
53959 goto out;
53960 }
53961
53962 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
53963 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
53964 __func__, vcc);
53965- atomic_inc(&vcc->stats->rx_err);
53966+ atomic_inc_unchecked(&vcc->stats->rx_err);
53967 goto out;
53968 }
53969
53970@@ -386,7 +386,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
53971 if (printk_ratelimit())
53972 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
53973 __func__, length);
53974- atomic_inc(&vcc->stats->rx_drop);
53975+ atomic_inc_unchecked(&vcc->stats->rx_drop);
53976 goto out;
53977 }
53978
53979@@ -414,7 +414,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
53980
53981 vcc->push(vcc, skb);
53982
53983- atomic_inc(&vcc->stats->rx);
53984+ atomic_inc_unchecked(&vcc->stats->rx);
53985 out:
53986 skb_trim(sarb, 0);
53987 }
53988@@ -612,7 +612,7 @@ static void usbatm_tx_process(unsigned long data)
53989 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
53990
53991 usbatm_pop(vcc, skb);
53992- atomic_inc(&vcc->stats->tx);
53993+ atomic_inc_unchecked(&vcc->stats->tx);
53994
53995 skb = skb_dequeue(&instance->sndqueue);
53996 }
53997@@ -756,11 +756,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t *pos, char *page
53998 if (!left--)
53999 return sprintf(page,
54000 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
54001- atomic_read(&atm_dev->stats.aal5.tx),
54002- atomic_read(&atm_dev->stats.aal5.tx_err),
54003- atomic_read(&atm_dev->stats.aal5.rx),
54004- atomic_read(&atm_dev->stats.aal5.rx_err),
54005- atomic_read(&atm_dev->stats.aal5.rx_drop));
54006+ atomic_read_unchecked(&atm_dev->stats.aal5.tx),
54007+ atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
54008+ atomic_read_unchecked(&atm_dev->stats.aal5.rx),
54009+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
54010+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
54011
54012 if (!left--) {
54013 if (instance->disconnected)
54014diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
54015index 2a3bbdf..91d72cf 100644
54016--- a/drivers/usb/core/devices.c
54017+++ b/drivers/usb/core/devices.c
54018@@ -126,7 +126,7 @@ static const char format_endpt[] =
54019 * time it gets called.
54020 */
54021 static struct device_connect_event {
54022- atomic_t count;
54023+ atomic_unchecked_t count;
54024 wait_queue_head_t wait;
54025 } device_event = {
54026 .count = ATOMIC_INIT(1),
54027@@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
54028
54029 void usbfs_conn_disc_event(void)
54030 {
54031- atomic_add(2, &device_event.count);
54032+ atomic_add_unchecked(2, &device_event.count);
54033 wake_up(&device_event.wait);
54034 }
54035
54036@@ -652,7 +652,7 @@ static unsigned int usb_device_poll(struct file *file,
54037
54038 poll_wait(file, &device_event.wait, wait);
54039
54040- event_count = atomic_read(&device_event.count);
54041+ event_count = atomic_read_unchecked(&device_event.count);
54042 if (file->f_version != event_count) {
54043 file->f_version = event_count;
54044 return POLLIN | POLLRDNORM;
54045diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c
54046index 0b59731..46ee7d1 100644
54047--- a/drivers/usb/core/devio.c
54048+++ b/drivers/usb/core/devio.c
54049@@ -187,7 +187,7 @@ static ssize_t usbdev_read(struct file *file, char __user *buf, size_t nbytes,
54050 struct usb_dev_state *ps = file->private_data;
54051 struct usb_device *dev = ps->dev;
54052 ssize_t ret = 0;
54053- unsigned len;
54054+ size_t len;
54055 loff_t pos;
54056 int i;
54057
54058@@ -229,22 +229,22 @@ static ssize_t usbdev_read(struct file *file, char __user *buf, size_t nbytes,
54059 for (i = 0; nbytes && i < dev->descriptor.bNumConfigurations; i++) {
54060 struct usb_config_descriptor *config =
54061 (struct usb_config_descriptor *)dev->rawdescriptors[i];
54062- unsigned int length = le16_to_cpu(config->wTotalLength);
54063+ size_t length = le16_to_cpu(config->wTotalLength);
54064
54065 if (*ppos < pos + length) {
54066
54067 /* The descriptor may claim to be longer than it
54068 * really is. Here is the actual allocated length. */
54069- unsigned alloclen =
54070+ size_t alloclen =
54071 le16_to_cpu(dev->config[i].desc.wTotalLength);
54072
54073- len = length - (*ppos - pos);
54074+ len = length + pos - *ppos;
54075 if (len > nbytes)
54076 len = nbytes;
54077
54078 /* Simply don't write (skip over) unallocated parts */
54079 if (alloclen > (*ppos - pos)) {
54080- alloclen -= (*ppos - pos);
54081+ alloclen = alloclen + pos - *ppos;
54082 if (copy_to_user(buf,
54083 dev->rawdescriptors[i] + (*ppos - pos),
54084 min(len, alloclen))) {
54085diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
54086index a6efb41..6f72549b 100644
54087--- a/drivers/usb/core/hcd.c
54088+++ b/drivers/usb/core/hcd.c
54089@@ -1551,7 +1551,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
54090 */
54091 usb_get_urb(urb);
54092 atomic_inc(&urb->use_count);
54093- atomic_inc(&urb->dev->urbnum);
54094+ atomic_inc_unchecked(&urb->dev->urbnum);
54095 usbmon_urb_submit(&hcd->self, urb);
54096
54097 /* NOTE requirements on root-hub callers (usbfs and the hub
54098@@ -1578,7 +1578,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
54099 urb->hcpriv = NULL;
54100 INIT_LIST_HEAD(&urb->urb_list);
54101 atomic_dec(&urb->use_count);
54102- atomic_dec(&urb->dev->urbnum);
54103+ atomic_dec_unchecked(&urb->dev->urbnum);
54104 if (atomic_read(&urb->reject))
54105 wake_up(&usb_kill_urb_queue);
54106 usb_put_urb(urb);
54107diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
54108index b649fef..c7107a0 100644
54109--- a/drivers/usb/core/hub.c
54110+++ b/drivers/usb/core/hub.c
54111@@ -26,6 +26,7 @@
54112 #include <linux/mutex.h>
54113 #include <linux/random.h>
54114 #include <linux/pm_qos.h>
54115+#include <linux/grsecurity.h>
54116
54117 #include <asm/uaccess.h>
54118 #include <asm/byteorder.h>
54119@@ -4666,6 +4667,10 @@ static void hub_port_connect(struct usb_hub *hub, int port1, u16 portstatus,
54120 goto done;
54121 return;
54122 }
54123+
54124+ if (gr_handle_new_usb())
54125+ goto done;
54126+
54127 if (hub_is_superspeed(hub->hdev))
54128 unit_load = 150;
54129 else
54130diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
54131index f7b7713..23d07ec 100644
54132--- a/drivers/usb/core/message.c
54133+++ b/drivers/usb/core/message.c
54134@@ -128,7 +128,7 @@ static int usb_internal_control_msg(struct usb_device *usb_dev,
54135 * Return: If successful, the number of bytes transferred. Otherwise, a negative
54136 * error number.
54137 */
54138-int usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
54139+int __intentional_overflow(-1) usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
54140 __u8 requesttype, __u16 value, __u16 index, void *data,
54141 __u16 size, int timeout)
54142 {
54143@@ -180,7 +180,7 @@ EXPORT_SYMBOL_GPL(usb_control_msg);
54144 * If successful, 0. Otherwise a negative error number. The number of actual
54145 * bytes transferred will be stored in the @actual_length parameter.
54146 */
54147-int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
54148+int __intentional_overflow(-1) usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
54149 void *data, int len, int *actual_length, int timeout)
54150 {
54151 return usb_bulk_msg(usb_dev, pipe, data, len, actual_length, timeout);
54152@@ -220,7 +220,7 @@ EXPORT_SYMBOL_GPL(usb_interrupt_msg);
54153 * bytes transferred will be stored in the @actual_length parameter.
54154 *
54155 */
54156-int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
54157+int __intentional_overflow(-1) usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
54158 void *data, int len, int *actual_length, int timeout)
54159 {
54160 struct urb *urb;
54161diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
54162index 1236c60..d47a51c 100644
54163--- a/drivers/usb/core/sysfs.c
54164+++ b/drivers/usb/core/sysfs.c
54165@@ -244,7 +244,7 @@ static ssize_t urbnum_show(struct device *dev, struct device_attribute *attr,
54166 struct usb_device *udev;
54167
54168 udev = to_usb_device(dev);
54169- return sprintf(buf, "%d\n", atomic_read(&udev->urbnum));
54170+ return sprintf(buf, "%d\n", atomic_read_unchecked(&udev->urbnum));
54171 }
54172 static DEVICE_ATTR_RO(urbnum);
54173
54174diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
54175index 2dd2362..1135437 100644
54176--- a/drivers/usb/core/usb.c
54177+++ b/drivers/usb/core/usb.c
54178@@ -433,7 +433,7 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent,
54179 set_dev_node(&dev->dev, dev_to_node(bus->controller));
54180 dev->state = USB_STATE_ATTACHED;
54181 dev->lpm_disable_count = 1;
54182- atomic_set(&dev->urbnum, 0);
54183+ atomic_set_unchecked(&dev->urbnum, 0);
54184
54185 INIT_LIST_HEAD(&dev->ep0.urb_list);
54186 dev->ep0.desc.bLength = USB_DT_ENDPOINT_SIZE;
54187diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
54188index 8cfc319..4868255 100644
54189--- a/drivers/usb/early/ehci-dbgp.c
54190+++ b/drivers/usb/early/ehci-dbgp.c
54191@@ -98,7 +98,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
54192
54193 #ifdef CONFIG_KGDB
54194 static struct kgdb_io kgdbdbgp_io_ops;
54195-#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
54196+static struct kgdb_io kgdbdbgp_io_ops_console;
54197+#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
54198 #else
54199 #define dbgp_kgdb_mode (0)
54200 #endif
54201@@ -1043,6 +1044,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
54202 .write_char = kgdbdbgp_write_char,
54203 };
54204
54205+static struct kgdb_io kgdbdbgp_io_ops_console = {
54206+ .name = "kgdbdbgp",
54207+ .read_char = kgdbdbgp_read_char,
54208+ .write_char = kgdbdbgp_write_char,
54209+ .is_console = 1
54210+};
54211+
54212 static int kgdbdbgp_wait_time;
54213
54214 static int __init kgdbdbgp_parse_config(char *str)
54215@@ -1058,8 +1066,10 @@ static int __init kgdbdbgp_parse_config(char *str)
54216 ptr++;
54217 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
54218 }
54219- kgdb_register_io_module(&kgdbdbgp_io_ops);
54220- kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
54221+ if (early_dbgp_console.index != -1)
54222+ kgdb_register_io_module(&kgdbdbgp_io_ops_console);
54223+ else
54224+ kgdb_register_io_module(&kgdbdbgp_io_ops);
54225
54226 return 0;
54227 }
54228diff --git a/drivers/usb/gadget/function/f_uac1.c b/drivers/usb/gadget/function/f_uac1.c
54229index f7b2032..fbb340c 100644
54230--- a/drivers/usb/gadget/function/f_uac1.c
54231+++ b/drivers/usb/gadget/function/f_uac1.c
54232@@ -14,6 +14,7 @@
54233 #include <linux/module.h>
54234 #include <linux/device.h>
54235 #include <linux/atomic.h>
54236+#include <linux/module.h>
54237
54238 #include "u_uac1.h"
54239
54240diff --git a/drivers/usb/gadget/function/u_serial.c b/drivers/usb/gadget/function/u_serial.c
54241index 491082a..dfd7d17 100644
54242--- a/drivers/usb/gadget/function/u_serial.c
54243+++ b/drivers/usb/gadget/function/u_serial.c
54244@@ -729,9 +729,9 @@ static int gs_open(struct tty_struct *tty, struct file *file)
54245 spin_lock_irq(&port->port_lock);
54246
54247 /* already open? Great. */
54248- if (port->port.count) {
54249+ if (atomic_read(&port->port.count)) {
54250 status = 0;
54251- port->port.count++;
54252+ atomic_inc(&port->port.count);
54253
54254 /* currently opening/closing? wait ... */
54255 } else if (port->openclose) {
54256@@ -790,7 +790,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
54257 tty->driver_data = port;
54258 port->port.tty = tty;
54259
54260- port->port.count = 1;
54261+ atomic_set(&port->port.count, 1);
54262 port->openclose = false;
54263
54264 /* if connected, start the I/O stream */
54265@@ -832,11 +832,11 @@ static void gs_close(struct tty_struct *tty, struct file *file)
54266
54267 spin_lock_irq(&port->port_lock);
54268
54269- if (port->port.count != 1) {
54270- if (port->port.count == 0)
54271+ if (atomic_read(&port->port.count) != 1) {
54272+ if (atomic_read(&port->port.count) == 0)
54273 WARN_ON(1);
54274 else
54275- --port->port.count;
54276+ atomic_dec(&port->port.count);
54277 goto exit;
54278 }
54279
54280@@ -846,7 +846,7 @@ static void gs_close(struct tty_struct *tty, struct file *file)
54281 * and sleep if necessary
54282 */
54283 port->openclose = true;
54284- port->port.count = 0;
54285+ atomic_set(&port->port.count, 0);
54286
54287 gser = port->port_usb;
54288 if (gser && gser->disconnect)
54289@@ -1062,7 +1062,7 @@ static int gs_closed(struct gs_port *port)
54290 int cond;
54291
54292 spin_lock_irq(&port->port_lock);
54293- cond = (port->port.count == 0) && !port->openclose;
54294+ cond = (atomic_read(&port->port.count) == 0) && !port->openclose;
54295 spin_unlock_irq(&port->port_lock);
54296 return cond;
54297 }
54298@@ -1205,7 +1205,7 @@ int gserial_connect(struct gserial *gser, u8 port_num)
54299 /* if it's already open, start I/O ... and notify the serial
54300 * protocol about open/close status (connect/disconnect).
54301 */
54302- if (port->port.count) {
54303+ if (atomic_read(&port->port.count)) {
54304 pr_debug("gserial_connect: start ttyGS%d\n", port->port_num);
54305 gs_start_io(port);
54306 if (gser->connect)
54307@@ -1252,7 +1252,7 @@ void gserial_disconnect(struct gserial *gser)
54308
54309 port->port_usb = NULL;
54310 gser->ioport = NULL;
54311- if (port->port.count > 0 || port->openclose) {
54312+ if (atomic_read(&port->port.count) > 0 || port->openclose) {
54313 wake_up_interruptible(&port->drain_wait);
54314 if (port->port.tty)
54315 tty_hangup(port->port.tty);
54316@@ -1268,7 +1268,7 @@ void gserial_disconnect(struct gserial *gser)
54317
54318 /* finally, free any unused/unusable I/O buffers */
54319 spin_lock_irqsave(&port->port_lock, flags);
54320- if (port->port.count == 0 && !port->openclose)
54321+ if (atomic_read(&port->port.count) == 0 && !port->openclose)
54322 gs_buf_free(&port->port_write_buf);
54323 gs_free_requests(gser->out, &port->read_pool, NULL);
54324 gs_free_requests(gser->out, &port->read_queue, NULL);
54325diff --git a/drivers/usb/gadget/function/u_uac1.c b/drivers/usb/gadget/function/u_uac1.c
54326index a44a07f..ecea924 100644
54327--- a/drivers/usb/gadget/function/u_uac1.c
54328+++ b/drivers/usb/gadget/function/u_uac1.c
54329@@ -17,6 +17,7 @@
54330 #include <linux/ctype.h>
54331 #include <linux/random.h>
54332 #include <linux/syscalls.h>
54333+#include <linux/module.h>
54334
54335 #include "u_uac1.h"
54336
54337diff --git a/drivers/usb/host/ehci-hub.c b/drivers/usb/host/ehci-hub.c
54338index 5728829..fefc6bf 100644
54339--- a/drivers/usb/host/ehci-hub.c
54340+++ b/drivers/usb/host/ehci-hub.c
54341@@ -771,7 +771,7 @@ static struct urb *request_single_step_set_feature_urb(
54342 urb->transfer_flags = URB_DIR_IN;
54343 usb_get_urb(urb);
54344 atomic_inc(&urb->use_count);
54345- atomic_inc(&urb->dev->urbnum);
54346+ atomic_inc_unchecked(&urb->dev->urbnum);
54347 urb->setup_dma = dma_map_single(
54348 hcd->self.controller,
54349 urb->setup_packet,
54350@@ -838,7 +838,7 @@ static int ehset_single_step_set_feature(struct usb_hcd *hcd, int port)
54351 urb->status = -EINPROGRESS;
54352 usb_get_urb(urb);
54353 atomic_inc(&urb->use_count);
54354- atomic_inc(&urb->dev->urbnum);
54355+ atomic_inc_unchecked(&urb->dev->urbnum);
54356 retval = submit_single_step_set_feature(hcd, urb, 0);
54357 if (!retval && !wait_for_completion_timeout(&done,
54358 msecs_to_jiffies(2000))) {
54359diff --git a/drivers/usb/host/hwa-hc.c b/drivers/usb/host/hwa-hc.c
54360index 1db0626..4948782 100644
54361--- a/drivers/usb/host/hwa-hc.c
54362+++ b/drivers/usb/host/hwa-hc.c
54363@@ -337,7 +337,10 @@ static int __hwahc_op_bwa_set(struct wusbhc *wusbhc, s8 stream_index,
54364 struct hwahc *hwahc = container_of(wusbhc, struct hwahc, wusbhc);
54365 struct wahc *wa = &hwahc->wa;
54366 struct device *dev = &wa->usb_iface->dev;
54367- u8 mas_le[UWB_NUM_MAS/8];
54368+ u8 *mas_le = kmalloc(UWB_NUM_MAS/8, GFP_KERNEL);
54369+
54370+ if (mas_le == NULL)
54371+ return -ENOMEM;
54372
54373 /* Set the stream index */
54374 result = usb_control_msg(wa->usb_dev, usb_sndctrlpipe(wa->usb_dev, 0),
54375@@ -356,10 +359,12 @@ static int __hwahc_op_bwa_set(struct wusbhc *wusbhc, s8 stream_index,
54376 WUSB_REQ_SET_WUSB_MAS,
54377 USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE,
54378 0, wa->usb_iface->cur_altsetting->desc.bInterfaceNumber,
54379- mas_le, 32, USB_CTRL_SET_TIMEOUT);
54380+ mas_le, UWB_NUM_MAS/8, USB_CTRL_SET_TIMEOUT);
54381 if (result < 0)
54382 dev_err(dev, "Cannot set WUSB MAS allocation: %d\n", result);
54383 out:
54384+ kfree(mas_le);
54385+
54386 return result;
54387 }
54388
54389diff --git a/drivers/usb/misc/appledisplay.c b/drivers/usb/misc/appledisplay.c
54390index b3d245e..99549ed 100644
54391--- a/drivers/usb/misc/appledisplay.c
54392+++ b/drivers/usb/misc/appledisplay.c
54393@@ -84,7 +84,7 @@ struct appledisplay {
54394 struct mutex sysfslock; /* concurrent read and write */
54395 };
54396
54397-static atomic_t count_displays = ATOMIC_INIT(0);
54398+static atomic_unchecked_t count_displays = ATOMIC_INIT(0);
54399 static struct workqueue_struct *wq;
54400
54401 static void appledisplay_complete(struct urb *urb)
54402@@ -288,7 +288,7 @@ static int appledisplay_probe(struct usb_interface *iface,
54403
54404 /* Register backlight device */
54405 snprintf(bl_name, sizeof(bl_name), "appledisplay%d",
54406- atomic_inc_return(&count_displays) - 1);
54407+ atomic_inc_return_unchecked(&count_displays) - 1);
54408 memset(&props, 0, sizeof(struct backlight_properties));
54409 props.type = BACKLIGHT_RAW;
54410 props.max_brightness = 0xff;
54411diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
54412index 8d7fc48..01c4986 100644
54413--- a/drivers/usb/serial/console.c
54414+++ b/drivers/usb/serial/console.c
54415@@ -123,7 +123,7 @@ static int usb_console_setup(struct console *co, char *options)
54416
54417 info->port = port;
54418
54419- ++port->port.count;
54420+ atomic_inc(&port->port.count);
54421 if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) {
54422 if (serial->type->set_termios) {
54423 /*
54424@@ -167,7 +167,7 @@ static int usb_console_setup(struct console *co, char *options)
54425 }
54426 /* Now that any required fake tty operations are completed restore
54427 * the tty port count */
54428- --port->port.count;
54429+ atomic_dec(&port->port.count);
54430 /* The console is special in terms of closing the device so
54431 * indicate this port is now acting as a system console. */
54432 port->port.console = 1;
54433@@ -180,7 +180,7 @@ static int usb_console_setup(struct console *co, char *options)
54434 free_tty:
54435 kfree(tty);
54436 reset_open_count:
54437- port->port.count = 0;
54438+ atomic_set(&port->port.count, 0);
54439 usb_autopm_put_interface(serial->interface);
54440 error_get_interface:
54441 usb_serial_put(serial);
54442@@ -191,7 +191,7 @@ static int usb_console_setup(struct console *co, char *options)
54443 static void usb_console_write(struct console *co,
54444 const char *buf, unsigned count)
54445 {
54446- static struct usbcons_info *info = &usbcons_info;
54447+ struct usbcons_info *info = &usbcons_info;
54448 struct usb_serial_port *port = info->port;
54449 struct usb_serial *serial;
54450 int retval = -ENODEV;
54451diff --git a/drivers/usb/storage/usb.h b/drivers/usb/storage/usb.h
54452index 307e339..6aa97cb 100644
54453--- a/drivers/usb/storage/usb.h
54454+++ b/drivers/usb/storage/usb.h
54455@@ -63,7 +63,7 @@ struct us_unusual_dev {
54456 __u8 useProtocol;
54457 __u8 useTransport;
54458 int (*initFunction)(struct us_data *);
54459-};
54460+} __do_const;
54461
54462
54463 /* Dynamic bitflag definitions (us->dflags): used in set_bit() etc. */
54464diff --git a/drivers/usb/usbip/vhci.h b/drivers/usb/usbip/vhci.h
54465index a863a98..d272795 100644
54466--- a/drivers/usb/usbip/vhci.h
54467+++ b/drivers/usb/usbip/vhci.h
54468@@ -83,7 +83,7 @@ struct vhci_hcd {
54469 unsigned resuming:1;
54470 unsigned long re_timeout;
54471
54472- atomic_t seqnum;
54473+ atomic_unchecked_t seqnum;
54474
54475 /*
54476 * NOTE:
54477diff --git a/drivers/usb/usbip/vhci_hcd.c b/drivers/usb/usbip/vhci_hcd.c
54478index c02374b..32d47a9 100644
54479--- a/drivers/usb/usbip/vhci_hcd.c
54480+++ b/drivers/usb/usbip/vhci_hcd.c
54481@@ -439,7 +439,7 @@ static void vhci_tx_urb(struct urb *urb)
54482
54483 spin_lock(&vdev->priv_lock);
54484
54485- priv->seqnum = atomic_inc_return(&the_controller->seqnum);
54486+ priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
54487 if (priv->seqnum == 0xffff)
54488 dev_info(&urb->dev->dev, "seqnum max\n");
54489
54490@@ -686,7 +686,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
54491 return -ENOMEM;
54492 }
54493
54494- unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
54495+ unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
54496 if (unlink->seqnum == 0xffff)
54497 pr_info("seqnum max\n");
54498
54499@@ -891,7 +891,7 @@ static int vhci_start(struct usb_hcd *hcd)
54500 vdev->rhport = rhport;
54501 }
54502
54503- atomic_set(&vhci->seqnum, 0);
54504+ atomic_set_unchecked(&vhci->seqnum, 0);
54505 spin_lock_init(&vhci->lock);
54506
54507 hcd->power_budget = 0; /* no limit */
54508diff --git a/drivers/usb/usbip/vhci_rx.c b/drivers/usb/usbip/vhci_rx.c
54509index 00e4a54..d676f85 100644
54510--- a/drivers/usb/usbip/vhci_rx.c
54511+++ b/drivers/usb/usbip/vhci_rx.c
54512@@ -80,7 +80,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
54513 if (!urb) {
54514 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
54515 pr_info("max seqnum %d\n",
54516- atomic_read(&the_controller->seqnum));
54517+ atomic_read_unchecked(&the_controller->seqnum));
54518 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
54519 return;
54520 }
54521diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
54522index edc7267..9f65ce2 100644
54523--- a/drivers/usb/wusbcore/wa-hc.h
54524+++ b/drivers/usb/wusbcore/wa-hc.h
54525@@ -240,7 +240,7 @@ struct wahc {
54526 spinlock_t xfer_list_lock;
54527 struct work_struct xfer_enqueue_work;
54528 struct work_struct xfer_error_work;
54529- atomic_t xfer_id_count;
54530+ atomic_unchecked_t xfer_id_count;
54531
54532 kernel_ulong_t quirks;
54533 };
54534@@ -305,7 +305,7 @@ static inline void wa_init(struct wahc *wa)
54535 INIT_WORK(&wa->xfer_enqueue_work, wa_urb_enqueue_run);
54536 INIT_WORK(&wa->xfer_error_work, wa_process_errored_transfers_run);
54537 wa->dto_in_use = 0;
54538- atomic_set(&wa->xfer_id_count, 1);
54539+ atomic_set_unchecked(&wa->xfer_id_count, 1);
54540 /* init the buf in URBs */
54541 for (index = 0; index < WA_MAX_BUF_IN_URBS; ++index)
54542 usb_init_urb(&(wa->buf_in_urbs[index]));
54543diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
54544index 69af4fd..da390d7 100644
54545--- a/drivers/usb/wusbcore/wa-xfer.c
54546+++ b/drivers/usb/wusbcore/wa-xfer.c
54547@@ -314,7 +314,7 @@ static void wa_xfer_completion(struct wa_xfer *xfer)
54548 */
54549 static void wa_xfer_id_init(struct wa_xfer *xfer)
54550 {
54551- xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
54552+ xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
54553 }
54554
54555 /* Return the xfer's ID. */
54556diff --git a/drivers/vfio/vfio.c b/drivers/vfio/vfio.c
54557index f018d8d..ccab63f 100644
54558--- a/drivers/vfio/vfio.c
54559+++ b/drivers/vfio/vfio.c
54560@@ -481,7 +481,7 @@ static int vfio_group_nb_add_dev(struct vfio_group *group, struct device *dev)
54561 return 0;
54562
54563 /* TODO Prevent device auto probing */
54564- WARN("Device %s added to live group %d!\n", dev_name(dev),
54565+ WARN(1, "Device %s added to live group %d!\n", dev_name(dev),
54566 iommu_group_id(group->iommu_group));
54567
54568 return 0;
54569diff --git a/drivers/vhost/vringh.c b/drivers/vhost/vringh.c
54570index 5174eba..451e6bc 100644
54571--- a/drivers/vhost/vringh.c
54572+++ b/drivers/vhost/vringh.c
54573@@ -530,17 +530,17 @@ static inline void __vringh_notify_disable(struct vringh *vrh,
54574 /* Userspace access helpers: in this case, addresses are really userspace. */
54575 static inline int getu16_user(u16 *val, const u16 *p)
54576 {
54577- return get_user(*val, (__force u16 __user *)p);
54578+ return get_user(*val, (u16 __force_user *)p);
54579 }
54580
54581 static inline int putu16_user(u16 *p, u16 val)
54582 {
54583- return put_user(val, (__force u16 __user *)p);
54584+ return put_user(val, (u16 __force_user *)p);
54585 }
54586
54587 static inline int copydesc_user(void *dst, const void *src, size_t len)
54588 {
54589- return copy_from_user(dst, (__force void __user *)src, len) ?
54590+ return copy_from_user(dst, (void __force_user *)src, len) ?
54591 -EFAULT : 0;
54592 }
54593
54594@@ -548,19 +548,19 @@ static inline int putused_user(struct vring_used_elem *dst,
54595 const struct vring_used_elem *src,
54596 unsigned int num)
54597 {
54598- return copy_to_user((__force void __user *)dst, src,
54599+ return copy_to_user((void __force_user *)dst, src,
54600 sizeof(*dst) * num) ? -EFAULT : 0;
54601 }
54602
54603 static inline int xfer_from_user(void *src, void *dst, size_t len)
54604 {
54605- return copy_from_user(dst, (__force void __user *)src, len) ?
54606+ return copy_from_user(dst, (void __force_user *)src, len) ?
54607 -EFAULT : 0;
54608 }
54609
54610 static inline int xfer_to_user(void *dst, void *src, size_t len)
54611 {
54612- return copy_to_user((__force void __user *)dst, src, len) ?
54613+ return copy_to_user((void __force_user *)dst, src, len) ?
54614 -EFAULT : 0;
54615 }
54616
54617@@ -596,9 +596,9 @@ int vringh_init_user(struct vringh *vrh, u32 features,
54618 vrh->last_used_idx = 0;
54619 vrh->vring.num = num;
54620 /* vring expects kernel addresses, but only used via accessors. */
54621- vrh->vring.desc = (__force struct vring_desc *)desc;
54622- vrh->vring.avail = (__force struct vring_avail *)avail;
54623- vrh->vring.used = (__force struct vring_used *)used;
54624+ vrh->vring.desc = (__force_kernel struct vring_desc *)desc;
54625+ vrh->vring.avail = (__force_kernel struct vring_avail *)avail;
54626+ vrh->vring.used = (__force_kernel struct vring_used *)used;
54627 return 0;
54628 }
54629 EXPORT_SYMBOL(vringh_init_user);
54630@@ -800,7 +800,7 @@ static inline int getu16_kern(u16 *val, const u16 *p)
54631
54632 static inline int putu16_kern(u16 *p, u16 val)
54633 {
54634- ACCESS_ONCE(*p) = val;
54635+ ACCESS_ONCE_RW(*p) = val;
54636 return 0;
54637 }
54638
54639diff --git a/drivers/video/backlight/kb3886_bl.c b/drivers/video/backlight/kb3886_bl.c
54640index 84a110a..96312c3 100644
54641--- a/drivers/video/backlight/kb3886_bl.c
54642+++ b/drivers/video/backlight/kb3886_bl.c
54643@@ -78,7 +78,7 @@ static struct kb3886bl_machinfo *bl_machinfo;
54644 static unsigned long kb3886bl_flags;
54645 #define KB3886BL_SUSPENDED 0x01
54646
54647-static struct dmi_system_id kb3886bl_device_table[] __initdata = {
54648+static const struct dmi_system_id kb3886bl_device_table[] __initconst = {
54649 {
54650 .ident = "Sahara Touch-iT",
54651 .matches = {
54652diff --git a/drivers/video/fbdev/arcfb.c b/drivers/video/fbdev/arcfb.c
54653index 1b0b233..6f34c2c 100644
54654--- a/drivers/video/fbdev/arcfb.c
54655+++ b/drivers/video/fbdev/arcfb.c
54656@@ -458,7 +458,7 @@ static ssize_t arcfb_write(struct fb_info *info, const char __user *buf,
54657 return -ENOSPC;
54658
54659 err = 0;
54660- if ((count + p) > fbmemlength) {
54661+ if (count > (fbmemlength - p)) {
54662 count = fbmemlength - p;
54663 err = -ENOSPC;
54664 }
54665diff --git a/drivers/video/fbdev/aty/aty128fb.c b/drivers/video/fbdev/aty/aty128fb.c
54666index aedf2fb..47c9aca 100644
54667--- a/drivers/video/fbdev/aty/aty128fb.c
54668+++ b/drivers/video/fbdev/aty/aty128fb.c
54669@@ -149,7 +149,7 @@ enum {
54670 };
54671
54672 /* Must match above enum */
54673-static char * const r128_family[] = {
54674+static const char * const r128_family[] = {
54675 "AGP",
54676 "PCI",
54677 "PRO AGP",
54678diff --git a/drivers/video/fbdev/aty/atyfb_base.c b/drivers/video/fbdev/aty/atyfb_base.c
54679index 37ec09b..98f8862 100644
54680--- a/drivers/video/fbdev/aty/atyfb_base.c
54681+++ b/drivers/video/fbdev/aty/atyfb_base.c
54682@@ -1326,10 +1326,14 @@ static int atyfb_set_par(struct fb_info *info)
54683 par->accel_flags = var->accel_flags; /* hack */
54684
54685 if (var->accel_flags) {
54686- info->fbops->fb_sync = atyfb_sync;
54687+ pax_open_kernel();
54688+ *(void **)&info->fbops->fb_sync = atyfb_sync;
54689+ pax_close_kernel();
54690 info->flags &= ~FBINFO_HWACCEL_DISABLED;
54691 } else {
54692- info->fbops->fb_sync = NULL;
54693+ pax_open_kernel();
54694+ *(void **)&info->fbops->fb_sync = NULL;
54695+ pax_close_kernel();
54696 info->flags |= FBINFO_HWACCEL_DISABLED;
54697 }
54698
54699diff --git a/drivers/video/fbdev/aty/mach64_cursor.c b/drivers/video/fbdev/aty/mach64_cursor.c
54700index 2fa0317..4983f2a 100644
54701--- a/drivers/video/fbdev/aty/mach64_cursor.c
54702+++ b/drivers/video/fbdev/aty/mach64_cursor.c
54703@@ -8,6 +8,7 @@
54704 #include "../core/fb_draw.h"
54705
54706 #include <asm/io.h>
54707+#include <asm/pgtable.h>
54708
54709 #ifdef __sparc__
54710 #include <asm/fbio.h>
54711@@ -218,7 +219,9 @@ int aty_init_cursor(struct fb_info *info)
54712 info->sprite.buf_align = 16; /* and 64 lines tall. */
54713 info->sprite.flags = FB_PIXMAP_IO;
54714
54715- info->fbops->fb_cursor = atyfb_cursor;
54716+ pax_open_kernel();
54717+ *(void **)&info->fbops->fb_cursor = atyfb_cursor;
54718+ pax_close_kernel();
54719
54720 return 0;
54721 }
54722diff --git a/drivers/video/fbdev/core/fb_defio.c b/drivers/video/fbdev/core/fb_defio.c
54723index 900aa4e..6d49418 100644
54724--- a/drivers/video/fbdev/core/fb_defio.c
54725+++ b/drivers/video/fbdev/core/fb_defio.c
54726@@ -206,7 +206,9 @@ void fb_deferred_io_init(struct fb_info *info)
54727
54728 BUG_ON(!fbdefio);
54729 mutex_init(&fbdefio->lock);
54730- info->fbops->fb_mmap = fb_deferred_io_mmap;
54731+ pax_open_kernel();
54732+ *(void **)&info->fbops->fb_mmap = fb_deferred_io_mmap;
54733+ pax_close_kernel();
54734 INIT_DELAYED_WORK(&info->deferred_work, fb_deferred_io_work);
54735 INIT_LIST_HEAD(&fbdefio->pagelist);
54736 if (fbdefio->delay == 0) /* set a default of 1 s */
54737@@ -237,7 +239,7 @@ void fb_deferred_io_cleanup(struct fb_info *info)
54738 page->mapping = NULL;
54739 }
54740
54741- info->fbops->fb_mmap = NULL;
54742+ *(void **)&info->fbops->fb_mmap = NULL;
54743 mutex_destroy(&fbdefio->lock);
54744 }
54745 EXPORT_SYMBOL_GPL(fb_deferred_io_cleanup);
54746diff --git a/drivers/video/fbdev/core/fbmem.c b/drivers/video/fbdev/core/fbmem.c
54747index 0705d88..d9429bf 100644
54748--- a/drivers/video/fbdev/core/fbmem.c
54749+++ b/drivers/video/fbdev/core/fbmem.c
54750@@ -1301,7 +1301,7 @@ static int do_fscreeninfo_to_user(struct fb_fix_screeninfo *fix,
54751 __u32 data;
54752 int err;
54753
54754- err = copy_to_user(&fix32->id, &fix->id, sizeof(fix32->id));
54755+ err = copy_to_user(fix32->id, &fix->id, sizeof(fix32->id));
54756
54757 data = (__u32) (unsigned long) fix->smem_start;
54758 err |= put_user(data, &fix32->smem_start);
54759diff --git a/drivers/video/fbdev/hyperv_fb.c b/drivers/video/fbdev/hyperv_fb.c
54760index 4254336..282567e 100644
54761--- a/drivers/video/fbdev/hyperv_fb.c
54762+++ b/drivers/video/fbdev/hyperv_fb.c
54763@@ -240,7 +240,7 @@ static uint screen_fb_size;
54764 static inline int synthvid_send(struct hv_device *hdev,
54765 struct synthvid_msg *msg)
54766 {
54767- static atomic64_t request_id = ATOMIC64_INIT(0);
54768+ static atomic64_unchecked_t request_id = ATOMIC64_INIT(0);
54769 int ret;
54770
54771 msg->pipe_hdr.type = PIPE_MSG_DATA;
54772@@ -248,7 +248,7 @@ static inline int synthvid_send(struct hv_device *hdev,
54773
54774 ret = vmbus_sendpacket(hdev->channel, msg,
54775 msg->vid_hdr.size + sizeof(struct pipe_msg_hdr),
54776- atomic64_inc_return(&request_id),
54777+ atomic64_inc_return_unchecked(&request_id),
54778 VM_PKT_DATA_INBAND, 0);
54779
54780 if (ret)
54781diff --git a/drivers/video/fbdev/i810/i810_accel.c b/drivers/video/fbdev/i810/i810_accel.c
54782index 7672d2e..b56437f 100644
54783--- a/drivers/video/fbdev/i810/i810_accel.c
54784+++ b/drivers/video/fbdev/i810/i810_accel.c
54785@@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
54786 }
54787 }
54788 printk("ringbuffer lockup!!!\n");
54789+ printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
54790 i810_report_error(mmio);
54791 par->dev_flags |= LOCKUP;
54792 info->pixmap.scan_align = 1;
54793diff --git a/drivers/video/fbdev/matrox/matroxfb_DAC1064.c b/drivers/video/fbdev/matrox/matroxfb_DAC1064.c
54794index a01147f..5d896f8 100644
54795--- a/drivers/video/fbdev/matrox/matroxfb_DAC1064.c
54796+++ b/drivers/video/fbdev/matrox/matroxfb_DAC1064.c
54797@@ -1088,14 +1088,20 @@ static void MGAG100_restore(struct matrox_fb_info *minfo)
54798
54799 #ifdef CONFIG_FB_MATROX_MYSTIQUE
54800 struct matrox_switch matrox_mystique = {
54801- MGA1064_preinit, MGA1064_reset, MGA1064_init, MGA1064_restore,
54802+ .preinit = MGA1064_preinit,
54803+ .reset = MGA1064_reset,
54804+ .init = MGA1064_init,
54805+ .restore = MGA1064_restore,
54806 };
54807 EXPORT_SYMBOL(matrox_mystique);
54808 #endif
54809
54810 #ifdef CONFIG_FB_MATROX_G
54811 struct matrox_switch matrox_G100 = {
54812- MGAG100_preinit, MGAG100_reset, MGAG100_init, MGAG100_restore,
54813+ .preinit = MGAG100_preinit,
54814+ .reset = MGAG100_reset,
54815+ .init = MGAG100_init,
54816+ .restore = MGAG100_restore,
54817 };
54818 EXPORT_SYMBOL(matrox_G100);
54819 #endif
54820diff --git a/drivers/video/fbdev/matrox/matroxfb_Ti3026.c b/drivers/video/fbdev/matrox/matroxfb_Ti3026.c
54821index 195ad7c..09743fc 100644
54822--- a/drivers/video/fbdev/matrox/matroxfb_Ti3026.c
54823+++ b/drivers/video/fbdev/matrox/matroxfb_Ti3026.c
54824@@ -738,7 +738,10 @@ static int Ti3026_preinit(struct matrox_fb_info *minfo)
54825 }
54826
54827 struct matrox_switch matrox_millennium = {
54828- Ti3026_preinit, Ti3026_reset, Ti3026_init, Ti3026_restore
54829+ .preinit = Ti3026_preinit,
54830+ .reset = Ti3026_reset,
54831+ .init = Ti3026_init,
54832+ .restore = Ti3026_restore
54833 };
54834 EXPORT_SYMBOL(matrox_millennium);
54835 #endif
54836diff --git a/drivers/video/fbdev/mb862xx/mb862xxfb_accel.c b/drivers/video/fbdev/mb862xx/mb862xxfb_accel.c
54837index fe92eed..106e085 100644
54838--- a/drivers/video/fbdev/mb862xx/mb862xxfb_accel.c
54839+++ b/drivers/video/fbdev/mb862xx/mb862xxfb_accel.c
54840@@ -312,14 +312,18 @@ void mb862xxfb_init_accel(struct fb_info *info, int xres)
54841 struct mb862xxfb_par *par = info->par;
54842
54843 if (info->var.bits_per_pixel == 32) {
54844- info->fbops->fb_fillrect = cfb_fillrect;
54845- info->fbops->fb_copyarea = cfb_copyarea;
54846- info->fbops->fb_imageblit = cfb_imageblit;
54847+ pax_open_kernel();
54848+ *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
54849+ *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
54850+ *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
54851+ pax_close_kernel();
54852 } else {
54853 outreg(disp, GC_L0EM, 3);
54854- info->fbops->fb_fillrect = mb86290fb_fillrect;
54855- info->fbops->fb_copyarea = mb86290fb_copyarea;
54856- info->fbops->fb_imageblit = mb86290fb_imageblit;
54857+ pax_open_kernel();
54858+ *(void **)&info->fbops->fb_fillrect = mb86290fb_fillrect;
54859+ *(void **)&info->fbops->fb_copyarea = mb86290fb_copyarea;
54860+ *(void **)&info->fbops->fb_imageblit = mb86290fb_imageblit;
54861+ pax_close_kernel();
54862 }
54863 outreg(draw, GDC_REG_DRAW_BASE, 0);
54864 outreg(draw, GDC_REG_MODE_MISC, 0x8000);
54865diff --git a/drivers/video/fbdev/nvidia/nvidia.c b/drivers/video/fbdev/nvidia/nvidia.c
54866index def0412..fed6529 100644
54867--- a/drivers/video/fbdev/nvidia/nvidia.c
54868+++ b/drivers/video/fbdev/nvidia/nvidia.c
54869@@ -669,19 +669,23 @@ static int nvidiafb_set_par(struct fb_info *info)
54870 info->fix.line_length = (info->var.xres_virtual *
54871 info->var.bits_per_pixel) >> 3;
54872 if (info->var.accel_flags) {
54873- info->fbops->fb_imageblit = nvidiafb_imageblit;
54874- info->fbops->fb_fillrect = nvidiafb_fillrect;
54875- info->fbops->fb_copyarea = nvidiafb_copyarea;
54876- info->fbops->fb_sync = nvidiafb_sync;
54877+ pax_open_kernel();
54878+ *(void **)&info->fbops->fb_imageblit = nvidiafb_imageblit;
54879+ *(void **)&info->fbops->fb_fillrect = nvidiafb_fillrect;
54880+ *(void **)&info->fbops->fb_copyarea = nvidiafb_copyarea;
54881+ *(void **)&info->fbops->fb_sync = nvidiafb_sync;
54882+ pax_close_kernel();
54883 info->pixmap.scan_align = 4;
54884 info->flags &= ~FBINFO_HWACCEL_DISABLED;
54885 info->flags |= FBINFO_READS_FAST;
54886 NVResetGraphics(info);
54887 } else {
54888- info->fbops->fb_imageblit = cfb_imageblit;
54889- info->fbops->fb_fillrect = cfb_fillrect;
54890- info->fbops->fb_copyarea = cfb_copyarea;
54891- info->fbops->fb_sync = NULL;
54892+ pax_open_kernel();
54893+ *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
54894+ *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
54895+ *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
54896+ *(void **)&info->fbops->fb_sync = NULL;
54897+ pax_close_kernel();
54898 info->pixmap.scan_align = 1;
54899 info->flags |= FBINFO_HWACCEL_DISABLED;
54900 info->flags &= ~FBINFO_READS_FAST;
54901@@ -1173,8 +1177,11 @@ static int nvidia_set_fbinfo(struct fb_info *info)
54902 info->pixmap.size = 8 * 1024;
54903 info->pixmap.flags = FB_PIXMAP_SYSTEM;
54904
54905- if (!hwcur)
54906- info->fbops->fb_cursor = NULL;
54907+ if (!hwcur) {
54908+ pax_open_kernel();
54909+ *(void **)&info->fbops->fb_cursor = NULL;
54910+ pax_close_kernel();
54911+ }
54912
54913 info->var.accel_flags = (!noaccel);
54914
54915diff --git a/drivers/video/fbdev/omap2/dss/display.c b/drivers/video/fbdev/omap2/dss/display.c
54916index 2412a0d..294215b 100644
54917--- a/drivers/video/fbdev/omap2/dss/display.c
54918+++ b/drivers/video/fbdev/omap2/dss/display.c
54919@@ -161,12 +161,14 @@ int omapdss_register_display(struct omap_dss_device *dssdev)
54920 if (dssdev->name == NULL)
54921 dssdev->name = dssdev->alias;
54922
54923+ pax_open_kernel();
54924 if (drv && drv->get_resolution == NULL)
54925- drv->get_resolution = omapdss_default_get_resolution;
54926+ *(void **)&drv->get_resolution = omapdss_default_get_resolution;
54927 if (drv && drv->get_recommended_bpp == NULL)
54928- drv->get_recommended_bpp = omapdss_default_get_recommended_bpp;
54929+ *(void **)&drv->get_recommended_bpp = omapdss_default_get_recommended_bpp;
54930 if (drv && drv->get_timings == NULL)
54931- drv->get_timings = omapdss_default_get_timings;
54932+ *(void **)&drv->get_timings = omapdss_default_get_timings;
54933+ pax_close_kernel();
54934
54935 mutex_lock(&panel_list_mutex);
54936 list_add_tail(&dssdev->panel_list, &panel_list);
54937diff --git a/drivers/video/fbdev/s1d13xxxfb.c b/drivers/video/fbdev/s1d13xxxfb.c
54938index 83433cb..71e9b98 100644
54939--- a/drivers/video/fbdev/s1d13xxxfb.c
54940+++ b/drivers/video/fbdev/s1d13xxxfb.c
54941@@ -881,8 +881,10 @@ static int s1d13xxxfb_probe(struct platform_device *pdev)
54942
54943 switch(prod_id) {
54944 case S1D13506_PROD_ID: /* activate acceleration */
54945- s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
54946- s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
54947+ pax_open_kernel();
54948+ *(void **)&s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
54949+ *(void **)&s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
54950+ pax_close_kernel();
54951 info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN |
54952 FBINFO_HWACCEL_FILLRECT | FBINFO_HWACCEL_COPYAREA;
54953 break;
54954diff --git a/drivers/video/fbdev/sh_mobile_lcdcfb.c b/drivers/video/fbdev/sh_mobile_lcdcfb.c
54955index 2bcc84a..29dd1ea 100644
54956--- a/drivers/video/fbdev/sh_mobile_lcdcfb.c
54957+++ b/drivers/video/fbdev/sh_mobile_lcdcfb.c
54958@@ -439,9 +439,9 @@ static unsigned long lcdc_sys_read_data(void *handle)
54959 }
54960
54961 static struct sh_mobile_lcdc_sys_bus_ops sh_mobile_lcdc_sys_bus_ops = {
54962- lcdc_sys_write_index,
54963- lcdc_sys_write_data,
54964- lcdc_sys_read_data,
54965+ .write_index = lcdc_sys_write_index,
54966+ .write_data = lcdc_sys_write_data,
54967+ .read_data = lcdc_sys_read_data,
54968 };
54969
54970 static int sh_mobile_lcdc_sginit(struct fb_info *info,
54971diff --git a/drivers/video/fbdev/smscufx.c b/drivers/video/fbdev/smscufx.c
54972index d513ed6..90b0de9 100644
54973--- a/drivers/video/fbdev/smscufx.c
54974+++ b/drivers/video/fbdev/smscufx.c
54975@@ -1175,7 +1175,9 @@ static int ufx_ops_release(struct fb_info *info, int user)
54976 fb_deferred_io_cleanup(info);
54977 kfree(info->fbdefio);
54978 info->fbdefio = NULL;
54979- info->fbops->fb_mmap = ufx_ops_mmap;
54980+ pax_open_kernel();
54981+ *(void **)&info->fbops->fb_mmap = ufx_ops_mmap;
54982+ pax_close_kernel();
54983 }
54984
54985 pr_debug("released /dev/fb%d user=%d count=%d",
54986diff --git a/drivers/video/fbdev/udlfb.c b/drivers/video/fbdev/udlfb.c
54987index 046d51d..be564da 100644
54988--- a/drivers/video/fbdev/udlfb.c
54989+++ b/drivers/video/fbdev/udlfb.c
54990@@ -623,11 +623,11 @@ static int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
54991 dlfb_urb_completion(urb);
54992
54993 error:
54994- atomic_add(bytes_sent, &dev->bytes_sent);
54995- atomic_add(bytes_identical, &dev->bytes_identical);
54996- atomic_add(width*height*2, &dev->bytes_rendered);
54997+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
54998+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
54999+ atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
55000 end_cycles = get_cycles();
55001- atomic_add(((unsigned int) ((end_cycles - start_cycles)
55002+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
55003 >> 10)), /* Kcycles */
55004 &dev->cpu_kcycles_used);
55005
55006@@ -748,11 +748,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
55007 dlfb_urb_completion(urb);
55008
55009 error:
55010- atomic_add(bytes_sent, &dev->bytes_sent);
55011- atomic_add(bytes_identical, &dev->bytes_identical);
55012- atomic_add(bytes_rendered, &dev->bytes_rendered);
55013+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
55014+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
55015+ atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
55016 end_cycles = get_cycles();
55017- atomic_add(((unsigned int) ((end_cycles - start_cycles)
55018+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
55019 >> 10)), /* Kcycles */
55020 &dev->cpu_kcycles_used);
55021 }
55022@@ -993,7 +993,9 @@ static int dlfb_ops_release(struct fb_info *info, int user)
55023 fb_deferred_io_cleanup(info);
55024 kfree(info->fbdefio);
55025 info->fbdefio = NULL;
55026- info->fbops->fb_mmap = dlfb_ops_mmap;
55027+ pax_open_kernel();
55028+ *(void **)&info->fbops->fb_mmap = dlfb_ops_mmap;
55029+ pax_close_kernel();
55030 }
55031
55032 pr_warn("released /dev/fb%d user=%d count=%d\n",
55033@@ -1376,7 +1378,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
55034 struct fb_info *fb_info = dev_get_drvdata(fbdev);
55035 struct dlfb_data *dev = fb_info->par;
55036 return snprintf(buf, PAGE_SIZE, "%u\n",
55037- atomic_read(&dev->bytes_rendered));
55038+ atomic_read_unchecked(&dev->bytes_rendered));
55039 }
55040
55041 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
55042@@ -1384,7 +1386,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
55043 struct fb_info *fb_info = dev_get_drvdata(fbdev);
55044 struct dlfb_data *dev = fb_info->par;
55045 return snprintf(buf, PAGE_SIZE, "%u\n",
55046- atomic_read(&dev->bytes_identical));
55047+ atomic_read_unchecked(&dev->bytes_identical));
55048 }
55049
55050 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
55051@@ -1392,7 +1394,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
55052 struct fb_info *fb_info = dev_get_drvdata(fbdev);
55053 struct dlfb_data *dev = fb_info->par;
55054 return snprintf(buf, PAGE_SIZE, "%u\n",
55055- atomic_read(&dev->bytes_sent));
55056+ atomic_read_unchecked(&dev->bytes_sent));
55057 }
55058
55059 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
55060@@ -1400,7 +1402,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
55061 struct fb_info *fb_info = dev_get_drvdata(fbdev);
55062 struct dlfb_data *dev = fb_info->par;
55063 return snprintf(buf, PAGE_SIZE, "%u\n",
55064- atomic_read(&dev->cpu_kcycles_used));
55065+ atomic_read_unchecked(&dev->cpu_kcycles_used));
55066 }
55067
55068 static ssize_t edid_show(
55069@@ -1460,10 +1462,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
55070 struct fb_info *fb_info = dev_get_drvdata(fbdev);
55071 struct dlfb_data *dev = fb_info->par;
55072
55073- atomic_set(&dev->bytes_rendered, 0);
55074- atomic_set(&dev->bytes_identical, 0);
55075- atomic_set(&dev->bytes_sent, 0);
55076- atomic_set(&dev->cpu_kcycles_used, 0);
55077+ atomic_set_unchecked(&dev->bytes_rendered, 0);
55078+ atomic_set_unchecked(&dev->bytes_identical, 0);
55079+ atomic_set_unchecked(&dev->bytes_sent, 0);
55080+ atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
55081
55082 return count;
55083 }
55084diff --git a/drivers/video/fbdev/uvesafb.c b/drivers/video/fbdev/uvesafb.c
55085index 509d452..7c9d2de 100644
55086--- a/drivers/video/fbdev/uvesafb.c
55087+++ b/drivers/video/fbdev/uvesafb.c
55088@@ -19,6 +19,7 @@
55089 #include <linux/io.h>
55090 #include <linux/mutex.h>
55091 #include <linux/slab.h>
55092+#include <linux/moduleloader.h>
55093 #include <video/edid.h>
55094 #include <video/uvesafb.h>
55095 #ifdef CONFIG_X86
55096@@ -565,10 +566,32 @@ static int uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
55097 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
55098 par->pmi_setpal = par->ypan = 0;
55099 } else {
55100+
55101+#ifdef CONFIG_PAX_KERNEXEC
55102+#ifdef CONFIG_MODULES
55103+ par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
55104+#endif
55105+ if (!par->pmi_code) {
55106+ par->pmi_setpal = par->ypan = 0;
55107+ return 0;
55108+ }
55109+#endif
55110+
55111 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
55112 + task->t.regs.edi);
55113+
55114+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55115+ pax_open_kernel();
55116+ memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
55117+ pax_close_kernel();
55118+
55119+ par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
55120+ par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
55121+#else
55122 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
55123 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
55124+#endif
55125+
55126 printk(KERN_INFO "uvesafb: protected mode interface info at "
55127 "%04x:%04x\n",
55128 (u16)task->t.regs.es, (u16)task->t.regs.edi);
55129@@ -813,13 +836,14 @@ static int uvesafb_vbe_init(struct fb_info *info)
55130 par->ypan = ypan;
55131
55132 if (par->pmi_setpal || par->ypan) {
55133+#if !defined(CONFIG_MODULES) || !defined(CONFIG_PAX_KERNEXEC)
55134 if (__supported_pte_mask & _PAGE_NX) {
55135 par->pmi_setpal = par->ypan = 0;
55136 printk(KERN_WARNING "uvesafb: NX protection is active, "
55137 "better not use the PMI.\n");
55138- } else {
55139+ } else
55140+#endif
55141 uvesafb_vbe_getpmi(task, par);
55142- }
55143 }
55144 #else
55145 /* The protected mode interface is not available on non-x86. */
55146@@ -1453,8 +1477,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
55147 info->fix.ywrapstep = (par->ypan > 1) ? 1 : 0;
55148
55149 /* Disable blanking if the user requested so. */
55150- if (!blank)
55151- info->fbops->fb_blank = NULL;
55152+ if (!blank) {
55153+ pax_open_kernel();
55154+ *(void **)&info->fbops->fb_blank = NULL;
55155+ pax_close_kernel();
55156+ }
55157
55158 /*
55159 * Find out how much IO memory is required for the mode with
55160@@ -1525,8 +1552,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
55161 info->flags = FBINFO_FLAG_DEFAULT |
55162 (par->ypan ? FBINFO_HWACCEL_YPAN : 0);
55163
55164- if (!par->ypan)
55165- info->fbops->fb_pan_display = NULL;
55166+ if (!par->ypan) {
55167+ pax_open_kernel();
55168+ *(void **)&info->fbops->fb_pan_display = NULL;
55169+ pax_close_kernel();
55170+ }
55171 }
55172
55173 static void uvesafb_init_mtrr(struct fb_info *info)
55174@@ -1787,6 +1817,11 @@ out_mode:
55175 out:
55176 kfree(par->vbe_modes);
55177
55178+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55179+ if (par->pmi_code)
55180+ module_free_exec(NULL, par->pmi_code);
55181+#endif
55182+
55183 framebuffer_release(info);
55184 return err;
55185 }
55186@@ -1811,6 +1846,11 @@ static int uvesafb_remove(struct platform_device *dev)
55187 kfree(par->vbe_state_orig);
55188 kfree(par->vbe_state_saved);
55189
55190+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55191+ if (par->pmi_code)
55192+ module_free_exec(NULL, par->pmi_code);
55193+#endif
55194+
55195 framebuffer_release(info);
55196 }
55197 return 0;
55198diff --git a/drivers/video/fbdev/vesafb.c b/drivers/video/fbdev/vesafb.c
55199index 6170e7f..dd63031 100644
55200--- a/drivers/video/fbdev/vesafb.c
55201+++ b/drivers/video/fbdev/vesafb.c
55202@@ -9,6 +9,7 @@
55203 */
55204
55205 #include <linux/module.h>
55206+#include <linux/moduleloader.h>
55207 #include <linux/kernel.h>
55208 #include <linux/errno.h>
55209 #include <linux/string.h>
55210@@ -52,8 +53,8 @@ static int vram_remap; /* Set amount of memory to be used */
55211 static int vram_total; /* Set total amount of memory */
55212 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
55213 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
55214-static void (*pmi_start)(void) __read_mostly;
55215-static void (*pmi_pal) (void) __read_mostly;
55216+static void (*pmi_start)(void) __read_only;
55217+static void (*pmi_pal) (void) __read_only;
55218 static int depth __read_mostly;
55219 static int vga_compat __read_mostly;
55220 /* --------------------------------------------------------------------- */
55221@@ -233,6 +234,7 @@ static int vesafb_probe(struct platform_device *dev)
55222 unsigned int size_remap;
55223 unsigned int size_total;
55224 char *option = NULL;
55225+ void *pmi_code = NULL;
55226
55227 /* ignore error return of fb_get_options */
55228 fb_get_options("vesafb", &option);
55229@@ -279,10 +281,6 @@ static int vesafb_probe(struct platform_device *dev)
55230 size_remap = size_total;
55231 vesafb_fix.smem_len = size_remap;
55232
55233-#ifndef __i386__
55234- screen_info.vesapm_seg = 0;
55235-#endif
55236-
55237 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
55238 printk(KERN_WARNING
55239 "vesafb: cannot reserve video memory at 0x%lx\n",
55240@@ -312,9 +310,21 @@ static int vesafb_probe(struct platform_device *dev)
55241 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
55242 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
55243
55244+#ifdef __i386__
55245+
55246+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55247+ pmi_code = module_alloc_exec(screen_info.vesapm_size);
55248+ if (!pmi_code)
55249+#elif !defined(CONFIG_PAX_KERNEXEC)
55250+ if (0)
55251+#endif
55252+
55253+#endif
55254+ screen_info.vesapm_seg = 0;
55255+
55256 if (screen_info.vesapm_seg) {
55257- printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
55258- screen_info.vesapm_seg,screen_info.vesapm_off);
55259+ printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
55260+ screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
55261 }
55262
55263 if (screen_info.vesapm_seg < 0xc000)
55264@@ -322,9 +332,25 @@ static int vesafb_probe(struct platform_device *dev)
55265
55266 if (ypan || pmi_setpal) {
55267 unsigned short *pmi_base;
55268+
55269 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
55270- pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
55271- pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
55272+
55273+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55274+ pax_open_kernel();
55275+ memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
55276+#else
55277+ pmi_code = pmi_base;
55278+#endif
55279+
55280+ pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
55281+ pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
55282+
55283+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55284+ pmi_start = ktva_ktla(pmi_start);
55285+ pmi_pal = ktva_ktla(pmi_pal);
55286+ pax_close_kernel();
55287+#endif
55288+
55289 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
55290 if (pmi_base[3]) {
55291 printk(KERN_INFO "vesafb: pmi: ports = ");
55292@@ -477,8 +503,11 @@ static int vesafb_probe(struct platform_device *dev)
55293 info->flags = FBINFO_FLAG_DEFAULT | FBINFO_MISC_FIRMWARE |
55294 (ypan ? FBINFO_HWACCEL_YPAN : 0);
55295
55296- if (!ypan)
55297- info->fbops->fb_pan_display = NULL;
55298+ if (!ypan) {
55299+ pax_open_kernel();
55300+ *(void **)&info->fbops->fb_pan_display = NULL;
55301+ pax_close_kernel();
55302+ }
55303
55304 if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) {
55305 err = -ENOMEM;
55306@@ -492,6 +521,11 @@ static int vesafb_probe(struct platform_device *dev)
55307 fb_info(info, "%s frame buffer device\n", info->fix.id);
55308 return 0;
55309 err:
55310+
55311+#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55312+ module_free_exec(NULL, pmi_code);
55313+#endif
55314+
55315 if (info->screen_base)
55316 iounmap(info->screen_base);
55317 framebuffer_release(info);
55318diff --git a/drivers/video/fbdev/via/via_clock.h b/drivers/video/fbdev/via/via_clock.h
55319index 88714ae..16c2e11 100644
55320--- a/drivers/video/fbdev/via/via_clock.h
55321+++ b/drivers/video/fbdev/via/via_clock.h
55322@@ -56,7 +56,7 @@ struct via_clock {
55323
55324 void (*set_engine_pll_state)(u8 state);
55325 void (*set_engine_pll)(struct via_pll_config config);
55326-};
55327+} __no_const;
55328
55329
55330 static inline u32 get_pll_internal_frequency(u32 ref_freq,
55331diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
55332index 3c14e43..2630570 100644
55333--- a/drivers/video/logo/logo_linux_clut224.ppm
55334+++ b/drivers/video/logo/logo_linux_clut224.ppm
55335@@ -2,1603 +2,1123 @@ P3
55336 # Standard 224-color Linux logo
55337 80 80
55338 255
55339- 0 0 0 0 0 0 0 0 0 0 0 0
55340- 0 0 0 0 0 0 0 0 0 0 0 0
55341- 0 0 0 0 0 0 0 0 0 0 0 0
55342- 0 0 0 0 0 0 0 0 0 0 0 0
55343- 0 0 0 0 0 0 0 0 0 0 0 0
55344- 0 0 0 0 0 0 0 0 0 0 0 0
55345- 0 0 0 0 0 0 0 0 0 0 0 0
55346- 0 0 0 0 0 0 0 0 0 0 0 0
55347- 0 0 0 0 0 0 0 0 0 0 0 0
55348- 6 6 6 6 6 6 10 10 10 10 10 10
55349- 10 10 10 6 6 6 6 6 6 6 6 6
55350- 0 0 0 0 0 0 0 0 0 0 0 0
55351- 0 0 0 0 0 0 0 0 0 0 0 0
55352- 0 0 0 0 0 0 0 0 0 0 0 0
55353- 0 0 0 0 0 0 0 0 0 0 0 0
55354- 0 0 0 0 0 0 0 0 0 0 0 0
55355- 0 0 0 0 0 0 0 0 0 0 0 0
55356- 0 0 0 0 0 0 0 0 0 0 0 0
55357- 0 0 0 0 0 0 0 0 0 0 0 0
55358- 0 0 0 0 0 0 0 0 0 0 0 0
55359- 0 0 0 0 0 0 0 0 0 0 0 0
55360- 0 0 0 0 0 0 0 0 0 0 0 0
55361- 0 0 0 0 0 0 0 0 0 0 0 0
55362- 0 0 0 0 0 0 0 0 0 0 0 0
55363- 0 0 0 0 0 0 0 0 0 0 0 0
55364- 0 0 0 0 0 0 0 0 0 0 0 0
55365- 0 0 0 0 0 0 0 0 0 0 0 0
55366- 0 0 0 0 0 0 0 0 0 0 0 0
55367- 0 0 0 6 6 6 10 10 10 14 14 14
55368- 22 22 22 26 26 26 30 30 30 34 34 34
55369- 30 30 30 30 30 30 26 26 26 18 18 18
55370- 14 14 14 10 10 10 6 6 6 0 0 0
55371- 0 0 0 0 0 0 0 0 0 0 0 0
55372- 0 0 0 0 0 0 0 0 0 0 0 0
55373- 0 0 0 0 0 0 0 0 0 0 0 0
55374- 0 0 0 0 0 0 0 0 0 0 0 0
55375- 0 0 0 0 0 0 0 0 0 0 0 0
55376- 0 0 0 0 0 0 0 0 0 0 0 0
55377- 0 0 0 0 0 0 0 0 0 0 0 0
55378- 0 0 0 0 0 0 0 0 0 0 0 0
55379- 0 0 0 0 0 0 0 0 0 0 0 0
55380- 0 0 0 0 0 1 0 0 1 0 0 0
55381- 0 0 0 0 0 0 0 0 0 0 0 0
55382- 0 0 0 0 0 0 0 0 0 0 0 0
55383- 0 0 0 0 0 0 0 0 0 0 0 0
55384- 0 0 0 0 0 0 0 0 0 0 0 0
55385- 0 0 0 0 0 0 0 0 0 0 0 0
55386- 0 0 0 0 0 0 0 0 0 0 0 0
55387- 6 6 6 14 14 14 26 26 26 42 42 42
55388- 54 54 54 66 66 66 78 78 78 78 78 78
55389- 78 78 78 74 74 74 66 66 66 54 54 54
55390- 42 42 42 26 26 26 18 18 18 10 10 10
55391- 6 6 6 0 0 0 0 0 0 0 0 0
55392- 0 0 0 0 0 0 0 0 0 0 0 0
55393- 0 0 0 0 0 0 0 0 0 0 0 0
55394- 0 0 0 0 0 0 0 0 0 0 0 0
55395- 0 0 0 0 0 0 0 0 0 0 0 0
55396- 0 0 0 0 0 0 0 0 0 0 0 0
55397- 0 0 0 0 0 0 0 0 0 0 0 0
55398- 0 0 0 0 0 0 0 0 0 0 0 0
55399- 0 0 0 0 0 0 0 0 0 0 0 0
55400- 0 0 1 0 0 0 0 0 0 0 0 0
55401- 0 0 0 0 0 0 0 0 0 0 0 0
55402- 0 0 0 0 0 0 0 0 0 0 0 0
55403- 0 0 0 0 0 0 0 0 0 0 0 0
55404- 0 0 0 0 0 0 0 0 0 0 0 0
55405- 0 0 0 0 0 0 0 0 0 0 0 0
55406- 0 0 0 0 0 0 0 0 0 10 10 10
55407- 22 22 22 42 42 42 66 66 66 86 86 86
55408- 66 66 66 38 38 38 38 38 38 22 22 22
55409- 26 26 26 34 34 34 54 54 54 66 66 66
55410- 86 86 86 70 70 70 46 46 46 26 26 26
55411- 14 14 14 6 6 6 0 0 0 0 0 0
55412- 0 0 0 0 0 0 0 0 0 0 0 0
55413- 0 0 0 0 0 0 0 0 0 0 0 0
55414- 0 0 0 0 0 0 0 0 0 0 0 0
55415- 0 0 0 0 0 0 0 0 0 0 0 0
55416- 0 0 0 0 0 0 0 0 0 0 0 0
55417- 0 0 0 0 0 0 0 0 0 0 0 0
55418- 0 0 0 0 0 0 0 0 0 0 0 0
55419- 0 0 0 0 0 0 0 0 0 0 0 0
55420- 0 0 1 0 0 1 0 0 1 0 0 0
55421- 0 0 0 0 0 0 0 0 0 0 0 0
55422- 0 0 0 0 0 0 0 0 0 0 0 0
55423- 0 0 0 0 0 0 0 0 0 0 0 0
55424- 0 0 0 0 0 0 0 0 0 0 0 0
55425- 0 0 0 0 0 0 0 0 0 0 0 0
55426- 0 0 0 0 0 0 10 10 10 26 26 26
55427- 50 50 50 82 82 82 58 58 58 6 6 6
55428- 2 2 6 2 2 6 2 2 6 2 2 6
55429- 2 2 6 2 2 6 2 2 6 2 2 6
55430- 6 6 6 54 54 54 86 86 86 66 66 66
55431- 38 38 38 18 18 18 6 6 6 0 0 0
55432- 0 0 0 0 0 0 0 0 0 0 0 0
55433- 0 0 0 0 0 0 0 0 0 0 0 0
55434- 0 0 0 0 0 0 0 0 0 0 0 0
55435- 0 0 0 0 0 0 0 0 0 0 0 0
55436- 0 0 0 0 0 0 0 0 0 0 0 0
55437- 0 0 0 0 0 0 0 0 0 0 0 0
55438- 0 0 0 0 0 0 0 0 0 0 0 0
55439- 0 0 0 0 0 0 0 0 0 0 0 0
55440- 0 0 0 0 0 0 0 0 0 0 0 0
55441- 0 0 0 0 0 0 0 0 0 0 0 0
55442- 0 0 0 0 0 0 0 0 0 0 0 0
55443- 0 0 0 0 0 0 0 0 0 0 0 0
55444- 0 0 0 0 0 0 0 0 0 0 0 0
55445- 0 0 0 0 0 0 0 0 0 0 0 0
55446- 0 0 0 6 6 6 22 22 22 50 50 50
55447- 78 78 78 34 34 34 2 2 6 2 2 6
55448- 2 2 6 2 2 6 2 2 6 2 2 6
55449- 2 2 6 2 2 6 2 2 6 2 2 6
55450- 2 2 6 2 2 6 6 6 6 70 70 70
55451- 78 78 78 46 46 46 22 22 22 6 6 6
55452- 0 0 0 0 0 0 0 0 0 0 0 0
55453- 0 0 0 0 0 0 0 0 0 0 0 0
55454- 0 0 0 0 0 0 0 0 0 0 0 0
55455- 0 0 0 0 0 0 0 0 0 0 0 0
55456- 0 0 0 0 0 0 0 0 0 0 0 0
55457- 0 0 0 0 0 0 0 0 0 0 0 0
55458- 0 0 0 0 0 0 0 0 0 0 0 0
55459- 0 0 0 0 0 0 0 0 0 0 0 0
55460- 0 0 1 0 0 1 0 0 1 0 0 0
55461- 0 0 0 0 0 0 0 0 0 0 0 0
55462- 0 0 0 0 0 0 0 0 0 0 0 0
55463- 0 0 0 0 0 0 0 0 0 0 0 0
55464- 0 0 0 0 0 0 0 0 0 0 0 0
55465- 0 0 0 0 0 0 0 0 0 0 0 0
55466- 6 6 6 18 18 18 42 42 42 82 82 82
55467- 26 26 26 2 2 6 2 2 6 2 2 6
55468- 2 2 6 2 2 6 2 2 6 2 2 6
55469- 2 2 6 2 2 6 2 2 6 14 14 14
55470- 46 46 46 34 34 34 6 6 6 2 2 6
55471- 42 42 42 78 78 78 42 42 42 18 18 18
55472- 6 6 6 0 0 0 0 0 0 0 0 0
55473- 0 0 0 0 0 0 0 0 0 0 0 0
55474- 0 0 0 0 0 0 0 0 0 0 0 0
55475- 0 0 0 0 0 0 0 0 0 0 0 0
55476- 0 0 0 0 0 0 0 0 0 0 0 0
55477- 0 0 0 0 0 0 0 0 0 0 0 0
55478- 0 0 0 0 0 0 0 0 0 0 0 0
55479- 0 0 0 0 0 0 0 0 0 0 0 0
55480- 0 0 1 0 0 0 0 0 1 0 0 0
55481- 0 0 0 0 0 0 0 0 0 0 0 0
55482- 0 0 0 0 0 0 0 0 0 0 0 0
55483- 0 0 0 0 0 0 0 0 0 0 0 0
55484- 0 0 0 0 0 0 0 0 0 0 0 0
55485- 0 0 0 0 0 0 0 0 0 0 0 0
55486- 10 10 10 30 30 30 66 66 66 58 58 58
55487- 2 2 6 2 2 6 2 2 6 2 2 6
55488- 2 2 6 2 2 6 2 2 6 2 2 6
55489- 2 2 6 2 2 6 2 2 6 26 26 26
55490- 86 86 86 101 101 101 46 46 46 10 10 10
55491- 2 2 6 58 58 58 70 70 70 34 34 34
55492- 10 10 10 0 0 0 0 0 0 0 0 0
55493- 0 0 0 0 0 0 0 0 0 0 0 0
55494- 0 0 0 0 0 0 0 0 0 0 0 0
55495- 0 0 0 0 0 0 0 0 0 0 0 0
55496- 0 0 0 0 0 0 0 0 0 0 0 0
55497- 0 0 0 0 0 0 0 0 0 0 0 0
55498- 0 0 0 0 0 0 0 0 0 0 0 0
55499- 0 0 0 0 0 0 0 0 0 0 0 0
55500- 0 0 1 0 0 1 0 0 1 0 0 0
55501- 0 0 0 0 0 0 0 0 0 0 0 0
55502- 0 0 0 0 0 0 0 0 0 0 0 0
55503- 0 0 0 0 0 0 0 0 0 0 0 0
55504- 0 0 0 0 0 0 0 0 0 0 0 0
55505- 0 0 0 0 0 0 0 0 0 0 0 0
55506- 14 14 14 42 42 42 86 86 86 10 10 10
55507- 2 2 6 2 2 6 2 2 6 2 2 6
55508- 2 2 6 2 2 6 2 2 6 2 2 6
55509- 2 2 6 2 2 6 2 2 6 30 30 30
55510- 94 94 94 94 94 94 58 58 58 26 26 26
55511- 2 2 6 6 6 6 78 78 78 54 54 54
55512- 22 22 22 6 6 6 0 0 0 0 0 0
55513- 0 0 0 0 0 0 0 0 0 0 0 0
55514- 0 0 0 0 0 0 0 0 0 0 0 0
55515- 0 0 0 0 0 0 0 0 0 0 0 0
55516- 0 0 0 0 0 0 0 0 0 0 0 0
55517- 0 0 0 0 0 0 0 0 0 0 0 0
55518- 0 0 0 0 0 0 0 0 0 0 0 0
55519- 0 0 0 0 0 0 0 0 0 0 0 0
55520- 0 0 0 0 0 0 0 0 0 0 0 0
55521- 0 0 0 0 0 0 0 0 0 0 0 0
55522- 0 0 0 0 0 0 0 0 0 0 0 0
55523- 0 0 0 0 0 0 0 0 0 0 0 0
55524- 0 0 0 0 0 0 0 0 0 0 0 0
55525- 0 0 0 0 0 0 0 0 0 6 6 6
55526- 22 22 22 62 62 62 62 62 62 2 2 6
55527- 2 2 6 2 2 6 2 2 6 2 2 6
55528- 2 2 6 2 2 6 2 2 6 2 2 6
55529- 2 2 6 2 2 6 2 2 6 26 26 26
55530- 54 54 54 38 38 38 18 18 18 10 10 10
55531- 2 2 6 2 2 6 34 34 34 82 82 82
55532- 38 38 38 14 14 14 0 0 0 0 0 0
55533- 0 0 0 0 0 0 0 0 0 0 0 0
55534- 0 0 0 0 0 0 0 0 0 0 0 0
55535- 0 0 0 0 0 0 0 0 0 0 0 0
55536- 0 0 0 0 0 0 0 0 0 0 0 0
55537- 0 0 0 0 0 0 0 0 0 0 0 0
55538- 0 0 0 0 0 0 0 0 0 0 0 0
55539- 0 0 0 0 0 0 0 0 0 0 0 0
55540- 0 0 0 0 0 1 0 0 1 0 0 0
55541- 0 0 0 0 0 0 0 0 0 0 0 0
55542- 0 0 0 0 0 0 0 0 0 0 0 0
55543- 0 0 0 0 0 0 0 0 0 0 0 0
55544- 0 0 0 0 0 0 0 0 0 0 0 0
55545- 0 0 0 0 0 0 0 0 0 6 6 6
55546- 30 30 30 78 78 78 30 30 30 2 2 6
55547- 2 2 6 2 2 6 2 2 6 2 2 6
55548- 2 2 6 2 2 6 2 2 6 2 2 6
55549- 2 2 6 2 2 6 2 2 6 10 10 10
55550- 10 10 10 2 2 6 2 2 6 2 2 6
55551- 2 2 6 2 2 6 2 2 6 78 78 78
55552- 50 50 50 18 18 18 6 6 6 0 0 0
55553- 0 0 0 0 0 0 0 0 0 0 0 0
55554- 0 0 0 0 0 0 0 0 0 0 0 0
55555- 0 0 0 0 0 0 0 0 0 0 0 0
55556- 0 0 0 0 0 0 0 0 0 0 0 0
55557- 0 0 0 0 0 0 0 0 0 0 0 0
55558- 0 0 0 0 0 0 0 0 0 0 0 0
55559- 0 0 0 0 0 0 0 0 0 0 0 0
55560- 0 0 1 0 0 0 0 0 0 0 0 0
55561- 0 0 0 0 0 0 0 0 0 0 0 0
55562- 0 0 0 0 0 0 0 0 0 0 0 0
55563- 0 0 0 0 0 0 0 0 0 0 0 0
55564- 0 0 0 0 0 0 0 0 0 0 0 0
55565- 0 0 0 0 0 0 0 0 0 10 10 10
55566- 38 38 38 86 86 86 14 14 14 2 2 6
55567- 2 2 6 2 2 6 2 2 6 2 2 6
55568- 2 2 6 2 2 6 2 2 6 2 2 6
55569- 2 2 6 2 2 6 2 2 6 2 2 6
55570- 2 2 6 2 2 6 2 2 6 2 2 6
55571- 2 2 6 2 2 6 2 2 6 54 54 54
55572- 66 66 66 26 26 26 6 6 6 0 0 0
55573- 0 0 0 0 0 0 0 0 0 0 0 0
55574- 0 0 0 0 0 0 0 0 0 0 0 0
55575- 0 0 0 0 0 0 0 0 0 0 0 0
55576- 0 0 0 0 0 0 0 0 0 0 0 0
55577- 0 0 0 0 0 0 0 0 0 0 0 0
55578- 0 0 0 0 0 0 0 0 0 0 0 0
55579- 0 0 0 0 0 0 0 0 0 0 0 0
55580- 0 0 0 0 0 1 0 0 1 0 0 0
55581- 0 0 0 0 0 0 0 0 0 0 0 0
55582- 0 0 0 0 0 0 0 0 0 0 0 0
55583- 0 0 0 0 0 0 0 0 0 0 0 0
55584- 0 0 0 0 0 0 0 0 0 0 0 0
55585- 0 0 0 0 0 0 0 0 0 14 14 14
55586- 42 42 42 82 82 82 2 2 6 2 2 6
55587- 2 2 6 6 6 6 10 10 10 2 2 6
55588- 2 2 6 2 2 6 2 2 6 2 2 6
55589- 2 2 6 2 2 6 2 2 6 6 6 6
55590- 14 14 14 10 10 10 2 2 6 2 2 6
55591- 2 2 6 2 2 6 2 2 6 18 18 18
55592- 82 82 82 34 34 34 10 10 10 0 0 0
55593- 0 0 0 0 0 0 0 0 0 0 0 0
55594- 0 0 0 0 0 0 0 0 0 0 0 0
55595- 0 0 0 0 0 0 0 0 0 0 0 0
55596- 0 0 0 0 0 0 0 0 0 0 0 0
55597- 0 0 0 0 0 0 0 0 0 0 0 0
55598- 0 0 0 0 0 0 0 0 0 0 0 0
55599- 0 0 0 0 0 0 0 0 0 0 0 0
55600- 0 0 1 0 0 0 0 0 0 0 0 0
55601- 0 0 0 0 0 0 0 0 0 0 0 0
55602- 0 0 0 0 0 0 0 0 0 0 0 0
55603- 0 0 0 0 0 0 0 0 0 0 0 0
55604- 0 0 0 0 0 0 0 0 0 0 0 0
55605- 0 0 0 0 0 0 0 0 0 14 14 14
55606- 46 46 46 86 86 86 2 2 6 2 2 6
55607- 6 6 6 6 6 6 22 22 22 34 34 34
55608- 6 6 6 2 2 6 2 2 6 2 2 6
55609- 2 2 6 2 2 6 18 18 18 34 34 34
55610- 10 10 10 50 50 50 22 22 22 2 2 6
55611- 2 2 6 2 2 6 2 2 6 10 10 10
55612- 86 86 86 42 42 42 14 14 14 0 0 0
55613- 0 0 0 0 0 0 0 0 0 0 0 0
55614- 0 0 0 0 0 0 0 0 0 0 0 0
55615- 0 0 0 0 0 0 0 0 0 0 0 0
55616- 0 0 0 0 0 0 0 0 0 0 0 0
55617- 0 0 0 0 0 0 0 0 0 0 0 0
55618- 0 0 0 0 0 0 0 0 0 0 0 0
55619- 0 0 0 0 0 0 0 0 0 0 0 0
55620- 0 0 1 0 0 1 0 0 1 0 0 0
55621- 0 0 0 0 0 0 0 0 0 0 0 0
55622- 0 0 0 0 0 0 0 0 0 0 0 0
55623- 0 0 0 0 0 0 0 0 0 0 0 0
55624- 0 0 0 0 0 0 0 0 0 0 0 0
55625- 0 0 0 0 0 0 0 0 0 14 14 14
55626- 46 46 46 86 86 86 2 2 6 2 2 6
55627- 38 38 38 116 116 116 94 94 94 22 22 22
55628- 22 22 22 2 2 6 2 2 6 2 2 6
55629- 14 14 14 86 86 86 138 138 138 162 162 162
55630-154 154 154 38 38 38 26 26 26 6 6 6
55631- 2 2 6 2 2 6 2 2 6 2 2 6
55632- 86 86 86 46 46 46 14 14 14 0 0 0
55633- 0 0 0 0 0 0 0 0 0 0 0 0
55634- 0 0 0 0 0 0 0 0 0 0 0 0
55635- 0 0 0 0 0 0 0 0 0 0 0 0
55636- 0 0 0 0 0 0 0 0 0 0 0 0
55637- 0 0 0 0 0 0 0 0 0 0 0 0
55638- 0 0 0 0 0 0 0 0 0 0 0 0
55639- 0 0 0 0 0 0 0 0 0 0 0 0
55640- 0 0 0 0 0 0 0 0 0 0 0 0
55641- 0 0 0 0 0 0 0 0 0 0 0 0
55642- 0 0 0 0 0 0 0 0 0 0 0 0
55643- 0 0 0 0 0 0 0 0 0 0 0 0
55644- 0 0 0 0 0 0 0 0 0 0 0 0
55645- 0 0 0 0 0 0 0 0 0 14 14 14
55646- 46 46 46 86 86 86 2 2 6 14 14 14
55647-134 134 134 198 198 198 195 195 195 116 116 116
55648- 10 10 10 2 2 6 2 2 6 6 6 6
55649-101 98 89 187 187 187 210 210 210 218 218 218
55650-214 214 214 134 134 134 14 14 14 6 6 6
55651- 2 2 6 2 2 6 2 2 6 2 2 6
55652- 86 86 86 50 50 50 18 18 18 6 6 6
55653- 0 0 0 0 0 0 0 0 0 0 0 0
55654- 0 0 0 0 0 0 0 0 0 0 0 0
55655- 0 0 0 0 0 0 0 0 0 0 0 0
55656- 0 0 0 0 0 0 0 0 0 0 0 0
55657- 0 0 0 0 0 0 0 0 0 0 0 0
55658- 0 0 0 0 0 0 0 0 0 0 0 0
55659- 0 0 0 0 0 0 0 0 1 0 0 0
55660- 0 0 1 0 0 1 0 0 1 0 0 0
55661- 0 0 0 0 0 0 0 0 0 0 0 0
55662- 0 0 0 0 0 0 0 0 0 0 0 0
55663- 0 0 0 0 0 0 0 0 0 0 0 0
55664- 0 0 0 0 0 0 0 0 0 0 0 0
55665- 0 0 0 0 0 0 0 0 0 14 14 14
55666- 46 46 46 86 86 86 2 2 6 54 54 54
55667-218 218 218 195 195 195 226 226 226 246 246 246
55668- 58 58 58 2 2 6 2 2 6 30 30 30
55669-210 210 210 253 253 253 174 174 174 123 123 123
55670-221 221 221 234 234 234 74 74 74 2 2 6
55671- 2 2 6 2 2 6 2 2 6 2 2 6
55672- 70 70 70 58 58 58 22 22 22 6 6 6
55673- 0 0 0 0 0 0 0 0 0 0 0 0
55674- 0 0 0 0 0 0 0 0 0 0 0 0
55675- 0 0 0 0 0 0 0 0 0 0 0 0
55676- 0 0 0 0 0 0 0 0 0 0 0 0
55677- 0 0 0 0 0 0 0 0 0 0 0 0
55678- 0 0 0 0 0 0 0 0 0 0 0 0
55679- 0 0 0 0 0 0 0 0 0 0 0 0
55680- 0 0 0 0 0 0 0 0 0 0 0 0
55681- 0 0 0 0 0 0 0 0 0 0 0 0
55682- 0 0 0 0 0 0 0 0 0 0 0 0
55683- 0 0 0 0 0 0 0 0 0 0 0 0
55684- 0 0 0 0 0 0 0 0 0 0 0 0
55685- 0 0 0 0 0 0 0 0 0 14 14 14
55686- 46 46 46 82 82 82 2 2 6 106 106 106
55687-170 170 170 26 26 26 86 86 86 226 226 226
55688-123 123 123 10 10 10 14 14 14 46 46 46
55689-231 231 231 190 190 190 6 6 6 70 70 70
55690- 90 90 90 238 238 238 158 158 158 2 2 6
55691- 2 2 6 2 2 6 2 2 6 2 2 6
55692- 70 70 70 58 58 58 22 22 22 6 6 6
55693- 0 0 0 0 0 0 0 0 0 0 0 0
55694- 0 0 0 0 0 0 0 0 0 0 0 0
55695- 0 0 0 0 0 0 0 0 0 0 0 0
55696- 0 0 0 0 0 0 0 0 0 0 0 0
55697- 0 0 0 0 0 0 0 0 0 0 0 0
55698- 0 0 0 0 0 0 0 0 0 0 0 0
55699- 0 0 0 0 0 0 0 0 1 0 0 0
55700- 0 0 1 0 0 1 0 0 1 0 0 0
55701- 0 0 0 0 0 0 0 0 0 0 0 0
55702- 0 0 0 0 0 0 0 0 0 0 0 0
55703- 0 0 0 0 0 0 0 0 0 0 0 0
55704- 0 0 0 0 0 0 0 0 0 0 0 0
55705- 0 0 0 0 0 0 0 0 0 14 14 14
55706- 42 42 42 86 86 86 6 6 6 116 116 116
55707-106 106 106 6 6 6 70 70 70 149 149 149
55708-128 128 128 18 18 18 38 38 38 54 54 54
55709-221 221 221 106 106 106 2 2 6 14 14 14
55710- 46 46 46 190 190 190 198 198 198 2 2 6
55711- 2 2 6 2 2 6 2 2 6 2 2 6
55712- 74 74 74 62 62 62 22 22 22 6 6 6
55713- 0 0 0 0 0 0 0 0 0 0 0 0
55714- 0 0 0 0 0 0 0 0 0 0 0 0
55715- 0 0 0 0 0 0 0 0 0 0 0 0
55716- 0 0 0 0 0 0 0 0 0 0 0 0
55717- 0 0 0 0 0 0 0 0 0 0 0 0
55718- 0 0 0 0 0 0 0 0 0 0 0 0
55719- 0 0 0 0 0 0 0 0 1 0 0 0
55720- 0 0 1 0 0 0 0 0 1 0 0 0
55721- 0 0 0 0 0 0 0 0 0 0 0 0
55722- 0 0 0 0 0 0 0 0 0 0 0 0
55723- 0 0 0 0 0 0 0 0 0 0 0 0
55724- 0 0 0 0 0 0 0 0 0 0 0 0
55725- 0 0 0 0 0 0 0 0 0 14 14 14
55726- 42 42 42 94 94 94 14 14 14 101 101 101
55727-128 128 128 2 2 6 18 18 18 116 116 116
55728-118 98 46 121 92 8 121 92 8 98 78 10
55729-162 162 162 106 106 106 2 2 6 2 2 6
55730- 2 2 6 195 195 195 195 195 195 6 6 6
55731- 2 2 6 2 2 6 2 2 6 2 2 6
55732- 74 74 74 62 62 62 22 22 22 6 6 6
55733- 0 0 0 0 0 0 0 0 0 0 0 0
55734- 0 0 0 0 0 0 0 0 0 0 0 0
55735- 0 0 0 0 0 0 0 0 0 0 0 0
55736- 0 0 0 0 0 0 0 0 0 0 0 0
55737- 0 0 0 0 0 0 0 0 0 0 0 0
55738- 0 0 0 0 0 0 0 0 0 0 0 0
55739- 0 0 0 0 0 0 0 0 1 0 0 1
55740- 0 0 1 0 0 0 0 0 1 0 0 0
55741- 0 0 0 0 0 0 0 0 0 0 0 0
55742- 0 0 0 0 0 0 0 0 0 0 0 0
55743- 0 0 0 0 0 0 0 0 0 0 0 0
55744- 0 0 0 0 0 0 0 0 0 0 0 0
55745- 0 0 0 0 0 0 0 0 0 10 10 10
55746- 38 38 38 90 90 90 14 14 14 58 58 58
55747-210 210 210 26 26 26 54 38 6 154 114 10
55748-226 170 11 236 186 11 225 175 15 184 144 12
55749-215 174 15 175 146 61 37 26 9 2 2 6
55750- 70 70 70 246 246 246 138 138 138 2 2 6
55751- 2 2 6 2 2 6 2 2 6 2 2 6
55752- 70 70 70 66 66 66 26 26 26 6 6 6
55753- 0 0 0 0 0 0 0 0 0 0 0 0
55754- 0 0 0 0 0 0 0 0 0 0 0 0
55755- 0 0 0 0 0 0 0 0 0 0 0 0
55756- 0 0 0 0 0 0 0 0 0 0 0 0
55757- 0 0 0 0 0 0 0 0 0 0 0 0
55758- 0 0 0 0 0 0 0 0 0 0 0 0
55759- 0 0 0 0 0 0 0 0 0 0 0 0
55760- 0 0 0 0 0 0 0 0 0 0 0 0
55761- 0 0 0 0 0 0 0 0 0 0 0 0
55762- 0 0 0 0 0 0 0 0 0 0 0 0
55763- 0 0 0 0 0 0 0 0 0 0 0 0
55764- 0 0 0 0 0 0 0 0 0 0 0 0
55765- 0 0 0 0 0 0 0 0 0 10 10 10
55766- 38 38 38 86 86 86 14 14 14 10 10 10
55767-195 195 195 188 164 115 192 133 9 225 175 15
55768-239 182 13 234 190 10 232 195 16 232 200 30
55769-245 207 45 241 208 19 232 195 16 184 144 12
55770-218 194 134 211 206 186 42 42 42 2 2 6
55771- 2 2 6 2 2 6 2 2 6 2 2 6
55772- 50 50 50 74 74 74 30 30 30 6 6 6
55773- 0 0 0 0 0 0 0 0 0 0 0 0
55774- 0 0 0 0 0 0 0 0 0 0 0 0
55775- 0 0 0 0 0 0 0 0 0 0 0 0
55776- 0 0 0 0 0 0 0 0 0 0 0 0
55777- 0 0 0 0 0 0 0 0 0 0 0 0
55778- 0 0 0 0 0 0 0 0 0 0 0 0
55779- 0 0 0 0 0 0 0 0 0 0 0 0
55780- 0 0 0 0 0 0 0 0 0 0 0 0
55781- 0 0 0 0 0 0 0 0 0 0 0 0
55782- 0 0 0 0 0 0 0 0 0 0 0 0
55783- 0 0 0 0 0 0 0 0 0 0 0 0
55784- 0 0 0 0 0 0 0 0 0 0 0 0
55785- 0 0 0 0 0 0 0 0 0 10 10 10
55786- 34 34 34 86 86 86 14 14 14 2 2 6
55787-121 87 25 192 133 9 219 162 10 239 182 13
55788-236 186 11 232 195 16 241 208 19 244 214 54
55789-246 218 60 246 218 38 246 215 20 241 208 19
55790-241 208 19 226 184 13 121 87 25 2 2 6
55791- 2 2 6 2 2 6 2 2 6 2 2 6
55792- 50 50 50 82 82 82 34 34 34 10 10 10
55793- 0 0 0 0 0 0 0 0 0 0 0 0
55794- 0 0 0 0 0 0 0 0 0 0 0 0
55795- 0 0 0 0 0 0 0 0 0 0 0 0
55796- 0 0 0 0 0 0 0 0 0 0 0 0
55797- 0 0 0 0 0 0 0 0 0 0 0 0
55798- 0 0 0 0 0 0 0 0 0 0 0 0
55799- 0 0 0 0 0 0 0 0 0 0 0 0
55800- 0 0 0 0 0 0 0 0 0 0 0 0
55801- 0 0 0 0 0 0 0 0 0 0 0 0
55802- 0 0 0 0 0 0 0 0 0 0 0 0
55803- 0 0 0 0 0 0 0 0 0 0 0 0
55804- 0 0 0 0 0 0 0 0 0 0 0 0
55805- 0 0 0 0 0 0 0 0 0 10 10 10
55806- 34 34 34 82 82 82 30 30 30 61 42 6
55807-180 123 7 206 145 10 230 174 11 239 182 13
55808-234 190 10 238 202 15 241 208 19 246 218 74
55809-246 218 38 246 215 20 246 215 20 246 215 20
55810-226 184 13 215 174 15 184 144 12 6 6 6
55811- 2 2 6 2 2 6 2 2 6 2 2 6
55812- 26 26 26 94 94 94 42 42 42 14 14 14
55813- 0 0 0 0 0 0 0 0 0 0 0 0
55814- 0 0 0 0 0 0 0 0 0 0 0 0
55815- 0 0 0 0 0 0 0 0 0 0 0 0
55816- 0 0 0 0 0 0 0 0 0 0 0 0
55817- 0 0 0 0 0 0 0 0 0 0 0 0
55818- 0 0 0 0 0 0 0 0 0 0 0 0
55819- 0 0 0 0 0 0 0 0 0 0 0 0
55820- 0 0 0 0 0 0 0 0 0 0 0 0
55821- 0 0 0 0 0 0 0 0 0 0 0 0
55822- 0 0 0 0 0 0 0 0 0 0 0 0
55823- 0 0 0 0 0 0 0 0 0 0 0 0
55824- 0 0 0 0 0 0 0 0 0 0 0 0
55825- 0 0 0 0 0 0 0 0 0 10 10 10
55826- 30 30 30 78 78 78 50 50 50 104 69 6
55827-192 133 9 216 158 10 236 178 12 236 186 11
55828-232 195 16 241 208 19 244 214 54 245 215 43
55829-246 215 20 246 215 20 241 208 19 198 155 10
55830-200 144 11 216 158 10 156 118 10 2 2 6
55831- 2 2 6 2 2 6 2 2 6 2 2 6
55832- 6 6 6 90 90 90 54 54 54 18 18 18
55833- 6 6 6 0 0 0 0 0 0 0 0 0
55834- 0 0 0 0 0 0 0 0 0 0 0 0
55835- 0 0 0 0 0 0 0 0 0 0 0 0
55836- 0 0 0 0 0 0 0 0 0 0 0 0
55837- 0 0 0 0 0 0 0 0 0 0 0 0
55838- 0 0 0 0 0 0 0 0 0 0 0 0
55839- 0 0 0 0 0 0 0 0 0 0 0 0
55840- 0 0 0 0 0 0 0 0 0 0 0 0
55841- 0 0 0 0 0 0 0 0 0 0 0 0
55842- 0 0 0 0 0 0 0 0 0 0 0 0
55843- 0 0 0 0 0 0 0 0 0 0 0 0
55844- 0 0 0 0 0 0 0 0 0 0 0 0
55845- 0 0 0 0 0 0 0 0 0 10 10 10
55846- 30 30 30 78 78 78 46 46 46 22 22 22
55847-137 92 6 210 162 10 239 182 13 238 190 10
55848-238 202 15 241 208 19 246 215 20 246 215 20
55849-241 208 19 203 166 17 185 133 11 210 150 10
55850-216 158 10 210 150 10 102 78 10 2 2 6
55851- 6 6 6 54 54 54 14 14 14 2 2 6
55852- 2 2 6 62 62 62 74 74 74 30 30 30
55853- 10 10 10 0 0 0 0 0 0 0 0 0
55854- 0 0 0 0 0 0 0 0 0 0 0 0
55855- 0 0 0 0 0 0 0 0 0 0 0 0
55856- 0 0 0 0 0 0 0 0 0 0 0 0
55857- 0 0 0 0 0 0 0 0 0 0 0 0
55858- 0 0 0 0 0 0 0 0 0 0 0 0
55859- 0 0 0 0 0 0 0 0 0 0 0 0
55860- 0 0 0 0 0 0 0 0 0 0 0 0
55861- 0 0 0 0 0 0 0 0 0 0 0 0
55862- 0 0 0 0 0 0 0 0 0 0 0 0
55863- 0 0 0 0 0 0 0 0 0 0 0 0
55864- 0 0 0 0 0 0 0 0 0 0 0 0
55865- 0 0 0 0 0 0 0 0 0 10 10 10
55866- 34 34 34 78 78 78 50 50 50 6 6 6
55867- 94 70 30 139 102 15 190 146 13 226 184 13
55868-232 200 30 232 195 16 215 174 15 190 146 13
55869-168 122 10 192 133 9 210 150 10 213 154 11
55870-202 150 34 182 157 106 101 98 89 2 2 6
55871- 2 2 6 78 78 78 116 116 116 58 58 58
55872- 2 2 6 22 22 22 90 90 90 46 46 46
55873- 18 18 18 6 6 6 0 0 0 0 0 0
55874- 0 0 0 0 0 0 0 0 0 0 0 0
55875- 0 0 0 0 0 0 0 0 0 0 0 0
55876- 0 0 0 0 0 0 0 0 0 0 0 0
55877- 0 0 0 0 0 0 0 0 0 0 0 0
55878- 0 0 0 0 0 0 0 0 0 0 0 0
55879- 0 0 0 0 0 0 0 0 0 0 0 0
55880- 0 0 0 0 0 0 0 0 0 0 0 0
55881- 0 0 0 0 0 0 0 0 0 0 0 0
55882- 0 0 0 0 0 0 0 0 0 0 0 0
55883- 0 0 0 0 0 0 0 0 0 0 0 0
55884- 0 0 0 0 0 0 0 0 0 0 0 0
55885- 0 0 0 0 0 0 0 0 0 10 10 10
55886- 38 38 38 86 86 86 50 50 50 6 6 6
55887-128 128 128 174 154 114 156 107 11 168 122 10
55888-198 155 10 184 144 12 197 138 11 200 144 11
55889-206 145 10 206 145 10 197 138 11 188 164 115
55890-195 195 195 198 198 198 174 174 174 14 14 14
55891- 2 2 6 22 22 22 116 116 116 116 116 116
55892- 22 22 22 2 2 6 74 74 74 70 70 70
55893- 30 30 30 10 10 10 0 0 0 0 0 0
55894- 0 0 0 0 0 0 0 0 0 0 0 0
55895- 0 0 0 0 0 0 0 0 0 0 0 0
55896- 0 0 0 0 0 0 0 0 0 0 0 0
55897- 0 0 0 0 0 0 0 0 0 0 0 0
55898- 0 0 0 0 0 0 0 0 0 0 0 0
55899- 0 0 0 0 0 0 0 0 0 0 0 0
55900- 0 0 0 0 0 0 0 0 0 0 0 0
55901- 0 0 0 0 0 0 0 0 0 0 0 0
55902- 0 0 0 0 0 0 0 0 0 0 0 0
55903- 0 0 0 0 0 0 0 0 0 0 0 0
55904- 0 0 0 0 0 0 0 0 0 0 0 0
55905- 0 0 0 0 0 0 6 6 6 18 18 18
55906- 50 50 50 101 101 101 26 26 26 10 10 10
55907-138 138 138 190 190 190 174 154 114 156 107 11
55908-197 138 11 200 144 11 197 138 11 192 133 9
55909-180 123 7 190 142 34 190 178 144 187 187 187
55910-202 202 202 221 221 221 214 214 214 66 66 66
55911- 2 2 6 2 2 6 50 50 50 62 62 62
55912- 6 6 6 2 2 6 10 10 10 90 90 90
55913- 50 50 50 18 18 18 6 6 6 0 0 0
55914- 0 0 0 0 0 0 0 0 0 0 0 0
55915- 0 0 0 0 0 0 0 0 0 0 0 0
55916- 0 0 0 0 0 0 0 0 0 0 0 0
55917- 0 0 0 0 0 0 0 0 0 0 0 0
55918- 0 0 0 0 0 0 0 0 0 0 0 0
55919- 0 0 0 0 0 0 0 0 0 0 0 0
55920- 0 0 0 0 0 0 0 0 0 0 0 0
55921- 0 0 0 0 0 0 0 0 0 0 0 0
55922- 0 0 0 0 0 0 0 0 0 0 0 0
55923- 0 0 0 0 0 0 0 0 0 0 0 0
55924- 0 0 0 0 0 0 0 0 0 0 0 0
55925- 0 0 0 0 0 0 10 10 10 34 34 34
55926- 74 74 74 74 74 74 2 2 6 6 6 6
55927-144 144 144 198 198 198 190 190 190 178 166 146
55928-154 121 60 156 107 11 156 107 11 168 124 44
55929-174 154 114 187 187 187 190 190 190 210 210 210
55930-246 246 246 253 253 253 253 253 253 182 182 182
55931- 6 6 6 2 2 6 2 2 6 2 2 6
55932- 2 2 6 2 2 6 2 2 6 62 62 62
55933- 74 74 74 34 34 34 14 14 14 0 0 0
55934- 0 0 0 0 0 0 0 0 0 0 0 0
55935- 0 0 0 0 0 0 0 0 0 0 0 0
55936- 0 0 0 0 0 0 0 0 0 0 0 0
55937- 0 0 0 0 0 0 0 0 0 0 0 0
55938- 0 0 0 0 0 0 0 0 0 0 0 0
55939- 0 0 0 0 0 0 0 0 0 0 0 0
55940- 0 0 0 0 0 0 0 0 0 0 0 0
55941- 0 0 0 0 0 0 0 0 0 0 0 0
55942- 0 0 0 0 0 0 0 0 0 0 0 0
55943- 0 0 0 0 0 0 0 0 0 0 0 0
55944- 0 0 0 0 0 0 0 0 0 0 0 0
55945- 0 0 0 10 10 10 22 22 22 54 54 54
55946- 94 94 94 18 18 18 2 2 6 46 46 46
55947-234 234 234 221 221 221 190 190 190 190 190 190
55948-190 190 190 187 187 187 187 187 187 190 190 190
55949-190 190 190 195 195 195 214 214 214 242 242 242
55950-253 253 253 253 253 253 253 253 253 253 253 253
55951- 82 82 82 2 2 6 2 2 6 2 2 6
55952- 2 2 6 2 2 6 2 2 6 14 14 14
55953- 86 86 86 54 54 54 22 22 22 6 6 6
55954- 0 0 0 0 0 0 0 0 0 0 0 0
55955- 0 0 0 0 0 0 0 0 0 0 0 0
55956- 0 0 0 0 0 0 0 0 0 0 0 0
55957- 0 0 0 0 0 0 0 0 0 0 0 0
55958- 0 0 0 0 0 0 0 0 0 0 0 0
55959- 0 0 0 0 0 0 0 0 0 0 0 0
55960- 0 0 0 0 0 0 0 0 0 0 0 0
55961- 0 0 0 0 0 0 0 0 0 0 0 0
55962- 0 0 0 0 0 0 0 0 0 0 0 0
55963- 0 0 0 0 0 0 0 0 0 0 0 0
55964- 0 0 0 0 0 0 0 0 0 0 0 0
55965- 6 6 6 18 18 18 46 46 46 90 90 90
55966- 46 46 46 18 18 18 6 6 6 182 182 182
55967-253 253 253 246 246 246 206 206 206 190 190 190
55968-190 190 190 190 190 190 190 190 190 190 190 190
55969-206 206 206 231 231 231 250 250 250 253 253 253
55970-253 253 253 253 253 253 253 253 253 253 253 253
55971-202 202 202 14 14 14 2 2 6 2 2 6
55972- 2 2 6 2 2 6 2 2 6 2 2 6
55973- 42 42 42 86 86 86 42 42 42 18 18 18
55974- 6 6 6 0 0 0 0 0 0 0 0 0
55975- 0 0 0 0 0 0 0 0 0 0 0 0
55976- 0 0 0 0 0 0 0 0 0 0 0 0
55977- 0 0 0 0 0 0 0 0 0 0 0 0
55978- 0 0 0 0 0 0 0 0 0 0 0 0
55979- 0 0 0 0 0 0 0 0 0 0 0 0
55980- 0 0 0 0 0 0 0 0 0 0 0 0
55981- 0 0 0 0 0 0 0 0 0 0 0 0
55982- 0 0 0 0 0 0 0 0 0 0 0 0
55983- 0 0 0 0 0 0 0 0 0 0 0 0
55984- 0 0 0 0 0 0 0 0 0 6 6 6
55985- 14 14 14 38 38 38 74 74 74 66 66 66
55986- 2 2 6 6 6 6 90 90 90 250 250 250
55987-253 253 253 253 253 253 238 238 238 198 198 198
55988-190 190 190 190 190 190 195 195 195 221 221 221
55989-246 246 246 253 253 253 253 253 253 253 253 253
55990-253 253 253 253 253 253 253 253 253 253 253 253
55991-253 253 253 82 82 82 2 2 6 2 2 6
55992- 2 2 6 2 2 6 2 2 6 2 2 6
55993- 2 2 6 78 78 78 70 70 70 34 34 34
55994- 14 14 14 6 6 6 0 0 0 0 0 0
55995- 0 0 0 0 0 0 0 0 0 0 0 0
55996- 0 0 0 0 0 0 0 0 0 0 0 0
55997- 0 0 0 0 0 0 0 0 0 0 0 0
55998- 0 0 0 0 0 0 0 0 0 0 0 0
55999- 0 0 0 0 0 0 0 0 0 0 0 0
56000- 0 0 0 0 0 0 0 0 0 0 0 0
56001- 0 0 0 0 0 0 0 0 0 0 0 0
56002- 0 0 0 0 0 0 0 0 0 0 0 0
56003- 0 0 0 0 0 0 0 0 0 0 0 0
56004- 0 0 0 0 0 0 0 0 0 14 14 14
56005- 34 34 34 66 66 66 78 78 78 6 6 6
56006- 2 2 6 18 18 18 218 218 218 253 253 253
56007-253 253 253 253 253 253 253 253 253 246 246 246
56008-226 226 226 231 231 231 246 246 246 253 253 253
56009-253 253 253 253 253 253 253 253 253 253 253 253
56010-253 253 253 253 253 253 253 253 253 253 253 253
56011-253 253 253 178 178 178 2 2 6 2 2 6
56012- 2 2 6 2 2 6 2 2 6 2 2 6
56013- 2 2 6 18 18 18 90 90 90 62 62 62
56014- 30 30 30 10 10 10 0 0 0 0 0 0
56015- 0 0 0 0 0 0 0 0 0 0 0 0
56016- 0 0 0 0 0 0 0 0 0 0 0 0
56017- 0 0 0 0 0 0 0 0 0 0 0 0
56018- 0 0 0 0 0 0 0 0 0 0 0 0
56019- 0 0 0 0 0 0 0 0 0 0 0 0
56020- 0 0 0 0 0 0 0 0 0 0 0 0
56021- 0 0 0 0 0 0 0 0 0 0 0 0
56022- 0 0 0 0 0 0 0 0 0 0 0 0
56023- 0 0 0 0 0 0 0 0 0 0 0 0
56024- 0 0 0 0 0 0 10 10 10 26 26 26
56025- 58 58 58 90 90 90 18 18 18 2 2 6
56026- 2 2 6 110 110 110 253 253 253 253 253 253
56027-253 253 253 253 253 253 253 253 253 253 253 253
56028-250 250 250 253 253 253 253 253 253 253 253 253
56029-253 253 253 253 253 253 253 253 253 253 253 253
56030-253 253 253 253 253 253 253 253 253 253 253 253
56031-253 253 253 231 231 231 18 18 18 2 2 6
56032- 2 2 6 2 2 6 2 2 6 2 2 6
56033- 2 2 6 2 2 6 18 18 18 94 94 94
56034- 54 54 54 26 26 26 10 10 10 0 0 0
56035- 0 0 0 0 0 0 0 0 0 0 0 0
56036- 0 0 0 0 0 0 0 0 0 0 0 0
56037- 0 0 0 0 0 0 0 0 0 0 0 0
56038- 0 0 0 0 0 0 0 0 0 0 0 0
56039- 0 0 0 0 0 0 0 0 0 0 0 0
56040- 0 0 0 0 0 0 0 0 0 0 0 0
56041- 0 0 0 0 0 0 0 0 0 0 0 0
56042- 0 0 0 0 0 0 0 0 0 0 0 0
56043- 0 0 0 0 0 0 0 0 0 0 0 0
56044- 0 0 0 6 6 6 22 22 22 50 50 50
56045- 90 90 90 26 26 26 2 2 6 2 2 6
56046- 14 14 14 195 195 195 250 250 250 253 253 253
56047-253 253 253 253 253 253 253 253 253 253 253 253
56048-253 253 253 253 253 253 253 253 253 253 253 253
56049-253 253 253 253 253 253 253 253 253 253 253 253
56050-253 253 253 253 253 253 253 253 253 253 253 253
56051-250 250 250 242 242 242 54 54 54 2 2 6
56052- 2 2 6 2 2 6 2 2 6 2 2 6
56053- 2 2 6 2 2 6 2 2 6 38 38 38
56054- 86 86 86 50 50 50 22 22 22 6 6 6
56055- 0 0 0 0 0 0 0 0 0 0 0 0
56056- 0 0 0 0 0 0 0 0 0 0 0 0
56057- 0 0 0 0 0 0 0 0 0 0 0 0
56058- 0 0 0 0 0 0 0 0 0 0 0 0
56059- 0 0 0 0 0 0 0 0 0 0 0 0
56060- 0 0 0 0 0 0 0 0 0 0 0 0
56061- 0 0 0 0 0 0 0 0 0 0 0 0
56062- 0 0 0 0 0 0 0 0 0 0 0 0
56063- 0 0 0 0 0 0 0 0 0 0 0 0
56064- 6 6 6 14 14 14 38 38 38 82 82 82
56065- 34 34 34 2 2 6 2 2 6 2 2 6
56066- 42 42 42 195 195 195 246 246 246 253 253 253
56067-253 253 253 253 253 253 253 253 253 250 250 250
56068-242 242 242 242 242 242 250 250 250 253 253 253
56069-253 253 253 253 253 253 253 253 253 253 253 253
56070-253 253 253 250 250 250 246 246 246 238 238 238
56071-226 226 226 231 231 231 101 101 101 6 6 6
56072- 2 2 6 2 2 6 2 2 6 2 2 6
56073- 2 2 6 2 2 6 2 2 6 2 2 6
56074- 38 38 38 82 82 82 42 42 42 14 14 14
56075- 6 6 6 0 0 0 0 0 0 0 0 0
56076- 0 0 0 0 0 0 0 0 0 0 0 0
56077- 0 0 0 0 0 0 0 0 0 0 0 0
56078- 0 0 0 0 0 0 0 0 0 0 0 0
56079- 0 0 0 0 0 0 0 0 0 0 0 0
56080- 0 0 0 0 0 0 0 0 0 0 0 0
56081- 0 0 0 0 0 0 0 0 0 0 0 0
56082- 0 0 0 0 0 0 0 0 0 0 0 0
56083- 0 0 0 0 0 0 0 0 0 0 0 0
56084- 10 10 10 26 26 26 62 62 62 66 66 66
56085- 2 2 6 2 2 6 2 2 6 6 6 6
56086- 70 70 70 170 170 170 206 206 206 234 234 234
56087-246 246 246 250 250 250 250 250 250 238 238 238
56088-226 226 226 231 231 231 238 238 238 250 250 250
56089-250 250 250 250 250 250 246 246 246 231 231 231
56090-214 214 214 206 206 206 202 202 202 202 202 202
56091-198 198 198 202 202 202 182 182 182 18 18 18
56092- 2 2 6 2 2 6 2 2 6 2 2 6
56093- 2 2 6 2 2 6 2 2 6 2 2 6
56094- 2 2 6 62 62 62 66 66 66 30 30 30
56095- 10 10 10 0 0 0 0 0 0 0 0 0
56096- 0 0 0 0 0 0 0 0 0 0 0 0
56097- 0 0 0 0 0 0 0 0 0 0 0 0
56098- 0 0 0 0 0 0 0 0 0 0 0 0
56099- 0 0 0 0 0 0 0 0 0 0 0 0
56100- 0 0 0 0 0 0 0 0 0 0 0 0
56101- 0 0 0 0 0 0 0 0 0 0 0 0
56102- 0 0 0 0 0 0 0 0 0 0 0 0
56103- 0 0 0 0 0 0 0 0 0 0 0 0
56104- 14 14 14 42 42 42 82 82 82 18 18 18
56105- 2 2 6 2 2 6 2 2 6 10 10 10
56106- 94 94 94 182 182 182 218 218 218 242 242 242
56107-250 250 250 253 253 253 253 253 253 250 250 250
56108-234 234 234 253 253 253 253 253 253 253 253 253
56109-253 253 253 253 253 253 253 253 253 246 246 246
56110-238 238 238 226 226 226 210 210 210 202 202 202
56111-195 195 195 195 195 195 210 210 210 158 158 158
56112- 6 6 6 14 14 14 50 50 50 14 14 14
56113- 2 2 6 2 2 6 2 2 6 2 2 6
56114- 2 2 6 6 6 6 86 86 86 46 46 46
56115- 18 18 18 6 6 6 0 0 0 0 0 0
56116- 0 0 0 0 0 0 0 0 0 0 0 0
56117- 0 0 0 0 0 0 0 0 0 0 0 0
56118- 0 0 0 0 0 0 0 0 0 0 0 0
56119- 0 0 0 0 0 0 0 0 0 0 0 0
56120- 0 0 0 0 0 0 0 0 0 0 0 0
56121- 0 0 0 0 0 0 0 0 0 0 0 0
56122- 0 0 0 0 0 0 0 0 0 0 0 0
56123- 0 0 0 0 0 0 0 0 0 6 6 6
56124- 22 22 22 54 54 54 70 70 70 2 2 6
56125- 2 2 6 10 10 10 2 2 6 22 22 22
56126-166 166 166 231 231 231 250 250 250 253 253 253
56127-253 253 253 253 253 253 253 253 253 250 250 250
56128-242 242 242 253 253 253 253 253 253 253 253 253
56129-253 253 253 253 253 253 253 253 253 253 253 253
56130-253 253 253 253 253 253 253 253 253 246 246 246
56131-231 231 231 206 206 206 198 198 198 226 226 226
56132- 94 94 94 2 2 6 6 6 6 38 38 38
56133- 30 30 30 2 2 6 2 2 6 2 2 6
56134- 2 2 6 2 2 6 62 62 62 66 66 66
56135- 26 26 26 10 10 10 0 0 0 0 0 0
56136- 0 0 0 0 0 0 0 0 0 0 0 0
56137- 0 0 0 0 0 0 0 0 0 0 0 0
56138- 0 0 0 0 0 0 0 0 0 0 0 0
56139- 0 0 0 0 0 0 0 0 0 0 0 0
56140- 0 0 0 0 0 0 0 0 0 0 0 0
56141- 0 0 0 0 0 0 0 0 0 0 0 0
56142- 0 0 0 0 0 0 0 0 0 0 0 0
56143- 0 0 0 0 0 0 0 0 0 10 10 10
56144- 30 30 30 74 74 74 50 50 50 2 2 6
56145- 26 26 26 26 26 26 2 2 6 106 106 106
56146-238 238 238 253 253 253 253 253 253 253 253 253
56147-253 253 253 253 253 253 253 253 253 253 253 253
56148-253 253 253 253 253 253 253 253 253 253 253 253
56149-253 253 253 253 253 253 253 253 253 253 253 253
56150-253 253 253 253 253 253 253 253 253 253 253 253
56151-253 253 253 246 246 246 218 218 218 202 202 202
56152-210 210 210 14 14 14 2 2 6 2 2 6
56153- 30 30 30 22 22 22 2 2 6 2 2 6
56154- 2 2 6 2 2 6 18 18 18 86 86 86
56155- 42 42 42 14 14 14 0 0 0 0 0 0
56156- 0 0 0 0 0 0 0 0 0 0 0 0
56157- 0 0 0 0 0 0 0 0 0 0 0 0
56158- 0 0 0 0 0 0 0 0 0 0 0 0
56159- 0 0 0 0 0 0 0 0 0 0 0 0
56160- 0 0 0 0 0 0 0 0 0 0 0 0
56161- 0 0 0 0 0 0 0 0 0 0 0 0
56162- 0 0 0 0 0 0 0 0 0 0 0 0
56163- 0 0 0 0 0 0 0 0 0 14 14 14
56164- 42 42 42 90 90 90 22 22 22 2 2 6
56165- 42 42 42 2 2 6 18 18 18 218 218 218
56166-253 253 253 253 253 253 253 253 253 253 253 253
56167-253 253 253 253 253 253 253 253 253 253 253 253
56168-253 253 253 253 253 253 253 253 253 253 253 253
56169-253 253 253 253 253 253 253 253 253 253 253 253
56170-253 253 253 253 253 253 253 253 253 253 253 253
56171-253 253 253 253 253 253 250 250 250 221 221 221
56172-218 218 218 101 101 101 2 2 6 14 14 14
56173- 18 18 18 38 38 38 10 10 10 2 2 6
56174- 2 2 6 2 2 6 2 2 6 78 78 78
56175- 58 58 58 22 22 22 6 6 6 0 0 0
56176- 0 0 0 0 0 0 0 0 0 0 0 0
56177- 0 0 0 0 0 0 0 0 0 0 0 0
56178- 0 0 0 0 0 0 0 0 0 0 0 0
56179- 0 0 0 0 0 0 0 0 0 0 0 0
56180- 0 0 0 0 0 0 0 0 0 0 0 0
56181- 0 0 0 0 0 0 0 0 0 0 0 0
56182- 0 0 0 0 0 0 0 0 0 0 0 0
56183- 0 0 0 0 0 0 6 6 6 18 18 18
56184- 54 54 54 82 82 82 2 2 6 26 26 26
56185- 22 22 22 2 2 6 123 123 123 253 253 253
56186-253 253 253 253 253 253 253 253 253 253 253 253
56187-253 253 253 253 253 253 253 253 253 253 253 253
56188-253 253 253 253 253 253 253 253 253 253 253 253
56189-253 253 253 253 253 253 253 253 253 253 253 253
56190-253 253 253 253 253 253 253 253 253 253 253 253
56191-253 253 253 253 253 253 253 253 253 250 250 250
56192-238 238 238 198 198 198 6 6 6 38 38 38
56193- 58 58 58 26 26 26 38 38 38 2 2 6
56194- 2 2 6 2 2 6 2 2 6 46 46 46
56195- 78 78 78 30 30 30 10 10 10 0 0 0
56196- 0 0 0 0 0 0 0 0 0 0 0 0
56197- 0 0 0 0 0 0 0 0 0 0 0 0
56198- 0 0 0 0 0 0 0 0 0 0 0 0
56199- 0 0 0 0 0 0 0 0 0 0 0 0
56200- 0 0 0 0 0 0 0 0 0 0 0 0
56201- 0 0 0 0 0 0 0 0 0 0 0 0
56202- 0 0 0 0 0 0 0 0 0 0 0 0
56203- 0 0 0 0 0 0 10 10 10 30 30 30
56204- 74 74 74 58 58 58 2 2 6 42 42 42
56205- 2 2 6 22 22 22 231 231 231 253 253 253
56206-253 253 253 253 253 253 253 253 253 253 253 253
56207-253 253 253 253 253 253 253 253 253 250 250 250
56208-253 253 253 253 253 253 253 253 253 253 253 253
56209-253 253 253 253 253 253 253 253 253 253 253 253
56210-253 253 253 253 253 253 253 253 253 253 253 253
56211-253 253 253 253 253 253 253 253 253 253 253 253
56212-253 253 253 246 246 246 46 46 46 38 38 38
56213- 42 42 42 14 14 14 38 38 38 14 14 14
56214- 2 2 6 2 2 6 2 2 6 6 6 6
56215- 86 86 86 46 46 46 14 14 14 0 0 0
56216- 0 0 0 0 0 0 0 0 0 0 0 0
56217- 0 0 0 0 0 0 0 0 0 0 0 0
56218- 0 0 0 0 0 0 0 0 0 0 0 0
56219- 0 0 0 0 0 0 0 0 0 0 0 0
56220- 0 0 0 0 0 0 0 0 0 0 0 0
56221- 0 0 0 0 0 0 0 0 0 0 0 0
56222- 0 0 0 0 0 0 0 0 0 0 0 0
56223- 0 0 0 6 6 6 14 14 14 42 42 42
56224- 90 90 90 18 18 18 18 18 18 26 26 26
56225- 2 2 6 116 116 116 253 253 253 253 253 253
56226-253 253 253 253 253 253 253 253 253 253 253 253
56227-253 253 253 253 253 253 250 250 250 238 238 238
56228-253 253 253 253 253 253 253 253 253 253 253 253
56229-253 253 253 253 253 253 253 253 253 253 253 253
56230-253 253 253 253 253 253 253 253 253 253 253 253
56231-253 253 253 253 253 253 253 253 253 253 253 253
56232-253 253 253 253 253 253 94 94 94 6 6 6
56233- 2 2 6 2 2 6 10 10 10 34 34 34
56234- 2 2 6 2 2 6 2 2 6 2 2 6
56235- 74 74 74 58 58 58 22 22 22 6 6 6
56236- 0 0 0 0 0 0 0 0 0 0 0 0
56237- 0 0 0 0 0 0 0 0 0 0 0 0
56238- 0 0 0 0 0 0 0 0 0 0 0 0
56239- 0 0 0 0 0 0 0 0 0 0 0 0
56240- 0 0 0 0 0 0 0 0 0 0 0 0
56241- 0 0 0 0 0 0 0 0 0 0 0 0
56242- 0 0 0 0 0 0 0 0 0 0 0 0
56243- 0 0 0 10 10 10 26 26 26 66 66 66
56244- 82 82 82 2 2 6 38 38 38 6 6 6
56245- 14 14 14 210 210 210 253 253 253 253 253 253
56246-253 253 253 253 253 253 253 253 253 253 253 253
56247-253 253 253 253 253 253 246 246 246 242 242 242
56248-253 253 253 253 253 253 253 253 253 253 253 253
56249-253 253 253 253 253 253 253 253 253 253 253 253
56250-253 253 253 253 253 253 253 253 253 253 253 253
56251-253 253 253 253 253 253 253 253 253 253 253 253
56252-253 253 253 253 253 253 144 144 144 2 2 6
56253- 2 2 6 2 2 6 2 2 6 46 46 46
56254- 2 2 6 2 2 6 2 2 6 2 2 6
56255- 42 42 42 74 74 74 30 30 30 10 10 10
56256- 0 0 0 0 0 0 0 0 0 0 0 0
56257- 0 0 0 0 0 0 0 0 0 0 0 0
56258- 0 0 0 0 0 0 0 0 0 0 0 0
56259- 0 0 0 0 0 0 0 0 0 0 0 0
56260- 0 0 0 0 0 0 0 0 0 0 0 0
56261- 0 0 0 0 0 0 0 0 0 0 0 0
56262- 0 0 0 0 0 0 0 0 0 0 0 0
56263- 6 6 6 14 14 14 42 42 42 90 90 90
56264- 26 26 26 6 6 6 42 42 42 2 2 6
56265- 74 74 74 250 250 250 253 253 253 253 253 253
56266-253 253 253 253 253 253 253 253 253 253 253 253
56267-253 253 253 253 253 253 242 242 242 242 242 242
56268-253 253 253 253 253 253 253 253 253 253 253 253
56269-253 253 253 253 253 253 253 253 253 253 253 253
56270-253 253 253 253 253 253 253 253 253 253 253 253
56271-253 253 253 253 253 253 253 253 253 253 253 253
56272-253 253 253 253 253 253 182 182 182 2 2 6
56273- 2 2 6 2 2 6 2 2 6 46 46 46
56274- 2 2 6 2 2 6 2 2 6 2 2 6
56275- 10 10 10 86 86 86 38 38 38 10 10 10
56276- 0 0 0 0 0 0 0 0 0 0 0 0
56277- 0 0 0 0 0 0 0 0 0 0 0 0
56278- 0 0 0 0 0 0 0 0 0 0 0 0
56279- 0 0 0 0 0 0 0 0 0 0 0 0
56280- 0 0 0 0 0 0 0 0 0 0 0 0
56281- 0 0 0 0 0 0 0 0 0 0 0 0
56282- 0 0 0 0 0 0 0 0 0 0 0 0
56283- 10 10 10 26 26 26 66 66 66 82 82 82
56284- 2 2 6 22 22 22 18 18 18 2 2 6
56285-149 149 149 253 253 253 253 253 253 253 253 253
56286-253 253 253 253 253 253 253 253 253 253 253 253
56287-253 253 253 253 253 253 234 234 234 242 242 242
56288-253 253 253 253 253 253 253 253 253 253 253 253
56289-253 253 253 253 253 253 253 253 253 253 253 253
56290-253 253 253 253 253 253 253 253 253 253 253 253
56291-253 253 253 253 253 253 253 253 253 253 253 253
56292-253 253 253 253 253 253 206 206 206 2 2 6
56293- 2 2 6 2 2 6 2 2 6 38 38 38
56294- 2 2 6 2 2 6 2 2 6 2 2 6
56295- 6 6 6 86 86 86 46 46 46 14 14 14
56296- 0 0 0 0 0 0 0 0 0 0 0 0
56297- 0 0 0 0 0 0 0 0 0 0 0 0
56298- 0 0 0 0 0 0 0 0 0 0 0 0
56299- 0 0 0 0 0 0 0 0 0 0 0 0
56300- 0 0 0 0 0 0 0 0 0 0 0 0
56301- 0 0 0 0 0 0 0 0 0 0 0 0
56302- 0 0 0 0 0 0 0 0 0 6 6 6
56303- 18 18 18 46 46 46 86 86 86 18 18 18
56304- 2 2 6 34 34 34 10 10 10 6 6 6
56305-210 210 210 253 253 253 253 253 253 253 253 253
56306-253 253 253 253 253 253 253 253 253 253 253 253
56307-253 253 253 253 253 253 234 234 234 242 242 242
56308-253 253 253 253 253 253 253 253 253 253 253 253
56309-253 253 253 253 253 253 253 253 253 253 253 253
56310-253 253 253 253 253 253 253 253 253 253 253 253
56311-253 253 253 253 253 253 253 253 253 253 253 253
56312-253 253 253 253 253 253 221 221 221 6 6 6
56313- 2 2 6 2 2 6 6 6 6 30 30 30
56314- 2 2 6 2 2 6 2 2 6 2 2 6
56315- 2 2 6 82 82 82 54 54 54 18 18 18
56316- 6 6 6 0 0 0 0 0 0 0 0 0
56317- 0 0 0 0 0 0 0 0 0 0 0 0
56318- 0 0 0 0 0 0 0 0 0 0 0 0
56319- 0 0 0 0 0 0 0 0 0 0 0 0
56320- 0 0 0 0 0 0 0 0 0 0 0 0
56321- 0 0 0 0 0 0 0 0 0 0 0 0
56322- 0 0 0 0 0 0 0 0 0 10 10 10
56323- 26 26 26 66 66 66 62 62 62 2 2 6
56324- 2 2 6 38 38 38 10 10 10 26 26 26
56325-238 238 238 253 253 253 253 253 253 253 253 253
56326-253 253 253 253 253 253 253 253 253 253 253 253
56327-253 253 253 253 253 253 231 231 231 238 238 238
56328-253 253 253 253 253 253 253 253 253 253 253 253
56329-253 253 253 253 253 253 253 253 253 253 253 253
56330-253 253 253 253 253 253 253 253 253 253 253 253
56331-253 253 253 253 253 253 253 253 253 253 253 253
56332-253 253 253 253 253 253 231 231 231 6 6 6
56333- 2 2 6 2 2 6 10 10 10 30 30 30
56334- 2 2 6 2 2 6 2 2 6 2 2 6
56335- 2 2 6 66 66 66 58 58 58 22 22 22
56336- 6 6 6 0 0 0 0 0 0 0 0 0
56337- 0 0 0 0 0 0 0 0 0 0 0 0
56338- 0 0 0 0 0 0 0 0 0 0 0 0
56339- 0 0 0 0 0 0 0 0 0 0 0 0
56340- 0 0 0 0 0 0 0 0 0 0 0 0
56341- 0 0 0 0 0 0 0 0 0 0 0 0
56342- 0 0 0 0 0 0 0 0 0 10 10 10
56343- 38 38 38 78 78 78 6 6 6 2 2 6
56344- 2 2 6 46 46 46 14 14 14 42 42 42
56345-246 246 246 253 253 253 253 253 253 253 253 253
56346-253 253 253 253 253 253 253 253 253 253 253 253
56347-253 253 253 253 253 253 231 231 231 242 242 242
56348-253 253 253 253 253 253 253 253 253 253 253 253
56349-253 253 253 253 253 253 253 253 253 253 253 253
56350-253 253 253 253 253 253 253 253 253 253 253 253
56351-253 253 253 253 253 253 253 253 253 253 253 253
56352-253 253 253 253 253 253 234 234 234 10 10 10
56353- 2 2 6 2 2 6 22 22 22 14 14 14
56354- 2 2 6 2 2 6 2 2 6 2 2 6
56355- 2 2 6 66 66 66 62 62 62 22 22 22
56356- 6 6 6 0 0 0 0 0 0 0 0 0
56357- 0 0 0 0 0 0 0 0 0 0 0 0
56358- 0 0 0 0 0 0 0 0 0 0 0 0
56359- 0 0 0 0 0 0 0 0 0 0 0 0
56360- 0 0 0 0 0 0 0 0 0 0 0 0
56361- 0 0 0 0 0 0 0 0 0 0 0 0
56362- 0 0 0 0 0 0 6 6 6 18 18 18
56363- 50 50 50 74 74 74 2 2 6 2 2 6
56364- 14 14 14 70 70 70 34 34 34 62 62 62
56365-250 250 250 253 253 253 253 253 253 253 253 253
56366-253 253 253 253 253 253 253 253 253 253 253 253
56367-253 253 253 253 253 253 231 231 231 246 246 246
56368-253 253 253 253 253 253 253 253 253 253 253 253
56369-253 253 253 253 253 253 253 253 253 253 253 253
56370-253 253 253 253 253 253 253 253 253 253 253 253
56371-253 253 253 253 253 253 253 253 253 253 253 253
56372-253 253 253 253 253 253 234 234 234 14 14 14
56373- 2 2 6 2 2 6 30 30 30 2 2 6
56374- 2 2 6 2 2 6 2 2 6 2 2 6
56375- 2 2 6 66 66 66 62 62 62 22 22 22
56376- 6 6 6 0 0 0 0 0 0 0 0 0
56377- 0 0 0 0 0 0 0 0 0 0 0 0
56378- 0 0 0 0 0 0 0 0 0 0 0 0
56379- 0 0 0 0 0 0 0 0 0 0 0 0
56380- 0 0 0 0 0 0 0 0 0 0 0 0
56381- 0 0 0 0 0 0 0 0 0 0 0 0
56382- 0 0 0 0 0 0 6 6 6 18 18 18
56383- 54 54 54 62 62 62 2 2 6 2 2 6
56384- 2 2 6 30 30 30 46 46 46 70 70 70
56385-250 250 250 253 253 253 253 253 253 253 253 253
56386-253 253 253 253 253 253 253 253 253 253 253 253
56387-253 253 253 253 253 253 231 231 231 246 246 246
56388-253 253 253 253 253 253 253 253 253 253 253 253
56389-253 253 253 253 253 253 253 253 253 253 253 253
56390-253 253 253 253 253 253 253 253 253 253 253 253
56391-253 253 253 253 253 253 253 253 253 253 253 253
56392-253 253 253 253 253 253 226 226 226 10 10 10
56393- 2 2 6 6 6 6 30 30 30 2 2 6
56394- 2 2 6 2 2 6 2 2 6 2 2 6
56395- 2 2 6 66 66 66 58 58 58 22 22 22
56396- 6 6 6 0 0 0 0 0 0 0 0 0
56397- 0 0 0 0 0 0 0 0 0 0 0 0
56398- 0 0 0 0 0 0 0 0 0 0 0 0
56399- 0 0 0 0 0 0 0 0 0 0 0 0
56400- 0 0 0 0 0 0 0 0 0 0 0 0
56401- 0 0 0 0 0 0 0 0 0 0 0 0
56402- 0 0 0 0 0 0 6 6 6 22 22 22
56403- 58 58 58 62 62 62 2 2 6 2 2 6
56404- 2 2 6 2 2 6 30 30 30 78 78 78
56405-250 250 250 253 253 253 253 253 253 253 253 253
56406-253 253 253 253 253 253 253 253 253 253 253 253
56407-253 253 253 253 253 253 231 231 231 246 246 246
56408-253 253 253 253 253 253 253 253 253 253 253 253
56409-253 253 253 253 253 253 253 253 253 253 253 253
56410-253 253 253 253 253 253 253 253 253 253 253 253
56411-253 253 253 253 253 253 253 253 253 253 253 253
56412-253 253 253 253 253 253 206 206 206 2 2 6
56413- 22 22 22 34 34 34 18 14 6 22 22 22
56414- 26 26 26 18 18 18 6 6 6 2 2 6
56415- 2 2 6 82 82 82 54 54 54 18 18 18
56416- 6 6 6 0 0 0 0 0 0 0 0 0
56417- 0 0 0 0 0 0 0 0 0 0 0 0
56418- 0 0 0 0 0 0 0 0 0 0 0 0
56419- 0 0 0 0 0 0 0 0 0 0 0 0
56420- 0 0 0 0 0 0 0 0 0 0 0 0
56421- 0 0 0 0 0 0 0 0 0 0 0 0
56422- 0 0 0 0 0 0 6 6 6 26 26 26
56423- 62 62 62 106 106 106 74 54 14 185 133 11
56424-210 162 10 121 92 8 6 6 6 62 62 62
56425-238 238 238 253 253 253 253 253 253 253 253 253
56426-253 253 253 253 253 253 253 253 253 253 253 253
56427-253 253 253 253 253 253 231 231 231 246 246 246
56428-253 253 253 253 253 253 253 253 253 253 253 253
56429-253 253 253 253 253 253 253 253 253 253 253 253
56430-253 253 253 253 253 253 253 253 253 253 253 253
56431-253 253 253 253 253 253 253 253 253 253 253 253
56432-253 253 253 253 253 253 158 158 158 18 18 18
56433- 14 14 14 2 2 6 2 2 6 2 2 6
56434- 6 6 6 18 18 18 66 66 66 38 38 38
56435- 6 6 6 94 94 94 50 50 50 18 18 18
56436- 6 6 6 0 0 0 0 0 0 0 0 0
56437- 0 0 0 0 0 0 0 0 0 0 0 0
56438- 0 0 0 0 0 0 0 0 0 0 0 0
56439- 0 0 0 0 0 0 0 0 0 0 0 0
56440- 0 0 0 0 0 0 0 0 0 0 0 0
56441- 0 0 0 0 0 0 0 0 0 6 6 6
56442- 10 10 10 10 10 10 18 18 18 38 38 38
56443- 78 78 78 142 134 106 216 158 10 242 186 14
56444-246 190 14 246 190 14 156 118 10 10 10 10
56445- 90 90 90 238 238 238 253 253 253 253 253 253
56446-253 253 253 253 253 253 253 253 253 253 253 253
56447-253 253 253 253 253 253 231 231 231 250 250 250
56448-253 253 253 253 253 253 253 253 253 253 253 253
56449-253 253 253 253 253 253 253 253 253 253 253 253
56450-253 253 253 253 253 253 253 253 253 253 253 253
56451-253 253 253 253 253 253 253 253 253 246 230 190
56452-238 204 91 238 204 91 181 142 44 37 26 9
56453- 2 2 6 2 2 6 2 2 6 2 2 6
56454- 2 2 6 2 2 6 38 38 38 46 46 46
56455- 26 26 26 106 106 106 54 54 54 18 18 18
56456- 6 6 6 0 0 0 0 0 0 0 0 0
56457- 0 0 0 0 0 0 0 0 0 0 0 0
56458- 0 0 0 0 0 0 0 0 0 0 0 0
56459- 0 0 0 0 0 0 0 0 0 0 0 0
56460- 0 0 0 0 0 0 0 0 0 0 0 0
56461- 0 0 0 6 6 6 14 14 14 22 22 22
56462- 30 30 30 38 38 38 50 50 50 70 70 70
56463-106 106 106 190 142 34 226 170 11 242 186 14
56464-246 190 14 246 190 14 246 190 14 154 114 10
56465- 6 6 6 74 74 74 226 226 226 253 253 253
56466-253 253 253 253 253 253 253 253 253 253 253 253
56467-253 253 253 253 253 253 231 231 231 250 250 250
56468-253 253 253 253 253 253 253 253 253 253 253 253
56469-253 253 253 253 253 253 253 253 253 253 253 253
56470-253 253 253 253 253 253 253 253 253 253 253 253
56471-253 253 253 253 253 253 253 253 253 228 184 62
56472-241 196 14 241 208 19 232 195 16 38 30 10
56473- 2 2 6 2 2 6 2 2 6 2 2 6
56474- 2 2 6 6 6 6 30 30 30 26 26 26
56475-203 166 17 154 142 90 66 66 66 26 26 26
56476- 6 6 6 0 0 0 0 0 0 0 0 0
56477- 0 0 0 0 0 0 0 0 0 0 0 0
56478- 0 0 0 0 0 0 0 0 0 0 0 0
56479- 0 0 0 0 0 0 0 0 0 0 0 0
56480- 0 0 0 0 0 0 0 0 0 0 0 0
56481- 6 6 6 18 18 18 38 38 38 58 58 58
56482- 78 78 78 86 86 86 101 101 101 123 123 123
56483-175 146 61 210 150 10 234 174 13 246 186 14
56484-246 190 14 246 190 14 246 190 14 238 190 10
56485-102 78 10 2 2 6 46 46 46 198 198 198
56486-253 253 253 253 253 253 253 253 253 253 253 253
56487-253 253 253 253 253 253 234 234 234 242 242 242
56488-253 253 253 253 253 253 253 253 253 253 253 253
56489-253 253 253 253 253 253 253 253 253 253 253 253
56490-253 253 253 253 253 253 253 253 253 253 253 253
56491-253 253 253 253 253 253 253 253 253 224 178 62
56492-242 186 14 241 196 14 210 166 10 22 18 6
56493- 2 2 6 2 2 6 2 2 6 2 2 6
56494- 2 2 6 2 2 6 6 6 6 121 92 8
56495-238 202 15 232 195 16 82 82 82 34 34 34
56496- 10 10 10 0 0 0 0 0 0 0 0 0
56497- 0 0 0 0 0 0 0 0 0 0 0 0
56498- 0 0 0 0 0 0 0 0 0 0 0 0
56499- 0 0 0 0 0 0 0 0 0 0 0 0
56500- 0 0 0 0 0 0 0 0 0 0 0 0
56501- 14 14 14 38 38 38 70 70 70 154 122 46
56502-190 142 34 200 144 11 197 138 11 197 138 11
56503-213 154 11 226 170 11 242 186 14 246 190 14
56504-246 190 14 246 190 14 246 190 14 246 190 14
56505-225 175 15 46 32 6 2 2 6 22 22 22
56506-158 158 158 250 250 250 253 253 253 253 253 253
56507-253 253 253 253 253 253 253 253 253 253 253 253
56508-253 253 253 253 253 253 253 253 253 253 253 253
56509-253 253 253 253 253 253 253 253 253 253 253 253
56510-253 253 253 253 253 253 253 253 253 253 253 253
56511-253 253 253 250 250 250 242 242 242 224 178 62
56512-239 182 13 236 186 11 213 154 11 46 32 6
56513- 2 2 6 2 2 6 2 2 6 2 2 6
56514- 2 2 6 2 2 6 61 42 6 225 175 15
56515-238 190 10 236 186 11 112 100 78 42 42 42
56516- 14 14 14 0 0 0 0 0 0 0 0 0
56517- 0 0 0 0 0 0 0 0 0 0 0 0
56518- 0 0 0 0 0 0 0 0 0 0 0 0
56519- 0 0 0 0 0 0 0 0 0 0 0 0
56520- 0 0 0 0 0 0 0 0 0 6 6 6
56521- 22 22 22 54 54 54 154 122 46 213 154 11
56522-226 170 11 230 174 11 226 170 11 226 170 11
56523-236 178 12 242 186 14 246 190 14 246 190 14
56524-246 190 14 246 190 14 246 190 14 246 190 14
56525-241 196 14 184 144 12 10 10 10 2 2 6
56526- 6 6 6 116 116 116 242 242 242 253 253 253
56527-253 253 253 253 253 253 253 253 253 253 253 253
56528-253 253 253 253 253 253 253 253 253 253 253 253
56529-253 253 253 253 253 253 253 253 253 253 253 253
56530-253 253 253 253 253 253 253 253 253 253 253 253
56531-253 253 253 231 231 231 198 198 198 214 170 54
56532-236 178 12 236 178 12 210 150 10 137 92 6
56533- 18 14 6 2 2 6 2 2 6 2 2 6
56534- 6 6 6 70 47 6 200 144 11 236 178 12
56535-239 182 13 239 182 13 124 112 88 58 58 58
56536- 22 22 22 6 6 6 0 0 0 0 0 0
56537- 0 0 0 0 0 0 0 0 0 0 0 0
56538- 0 0 0 0 0 0 0 0 0 0 0 0
56539- 0 0 0 0 0 0 0 0 0 0 0 0
56540- 0 0 0 0 0 0 0 0 0 10 10 10
56541- 30 30 30 70 70 70 180 133 36 226 170 11
56542-239 182 13 242 186 14 242 186 14 246 186 14
56543-246 190 14 246 190 14 246 190 14 246 190 14
56544-246 190 14 246 190 14 246 190 14 246 190 14
56545-246 190 14 232 195 16 98 70 6 2 2 6
56546- 2 2 6 2 2 6 66 66 66 221 221 221
56547-253 253 253 253 253 253 253 253 253 253 253 253
56548-253 253 253 253 253 253 253 253 253 253 253 253
56549-253 253 253 253 253 253 253 253 253 253 253 253
56550-253 253 253 253 253 253 253 253 253 253 253 253
56551-253 253 253 206 206 206 198 198 198 214 166 58
56552-230 174 11 230 174 11 216 158 10 192 133 9
56553-163 110 8 116 81 8 102 78 10 116 81 8
56554-167 114 7 197 138 11 226 170 11 239 182 13
56555-242 186 14 242 186 14 162 146 94 78 78 78
56556- 34 34 34 14 14 14 6 6 6 0 0 0
56557- 0 0 0 0 0 0 0 0 0 0 0 0
56558- 0 0 0 0 0 0 0 0 0 0 0 0
56559- 0 0 0 0 0 0 0 0 0 0 0 0
56560- 0 0 0 0 0 0 0 0 0 6 6 6
56561- 30 30 30 78 78 78 190 142 34 226 170 11
56562-239 182 13 246 190 14 246 190 14 246 190 14
56563-246 190 14 246 190 14 246 190 14 246 190 14
56564-246 190 14 246 190 14 246 190 14 246 190 14
56565-246 190 14 241 196 14 203 166 17 22 18 6
56566- 2 2 6 2 2 6 2 2 6 38 38 38
56567-218 218 218 253 253 253 253 253 253 253 253 253
56568-253 253 253 253 253 253 253 253 253 253 253 253
56569-253 253 253 253 253 253 253 253 253 253 253 253
56570-253 253 253 253 253 253 253 253 253 253 253 253
56571-250 250 250 206 206 206 198 198 198 202 162 69
56572-226 170 11 236 178 12 224 166 10 210 150 10
56573-200 144 11 197 138 11 192 133 9 197 138 11
56574-210 150 10 226 170 11 242 186 14 246 190 14
56575-246 190 14 246 186 14 225 175 15 124 112 88
56576- 62 62 62 30 30 30 14 14 14 6 6 6
56577- 0 0 0 0 0 0 0 0 0 0 0 0
56578- 0 0 0 0 0 0 0 0 0 0 0 0
56579- 0 0 0 0 0 0 0 0 0 0 0 0
56580- 0 0 0 0 0 0 0 0 0 10 10 10
56581- 30 30 30 78 78 78 174 135 50 224 166 10
56582-239 182 13 246 190 14 246 190 14 246 190 14
56583-246 190 14 246 190 14 246 190 14 246 190 14
56584-246 190 14 246 190 14 246 190 14 246 190 14
56585-246 190 14 246 190 14 241 196 14 139 102 15
56586- 2 2 6 2 2 6 2 2 6 2 2 6
56587- 78 78 78 250 250 250 253 253 253 253 253 253
56588-253 253 253 253 253 253 253 253 253 253 253 253
56589-253 253 253 253 253 253 253 253 253 253 253 253
56590-253 253 253 253 253 253 253 253 253 253 253 253
56591-250 250 250 214 214 214 198 198 198 190 150 46
56592-219 162 10 236 178 12 234 174 13 224 166 10
56593-216 158 10 213 154 11 213 154 11 216 158 10
56594-226 170 11 239 182 13 246 190 14 246 190 14
56595-246 190 14 246 190 14 242 186 14 206 162 42
56596-101 101 101 58 58 58 30 30 30 14 14 14
56597- 6 6 6 0 0 0 0 0 0 0 0 0
56598- 0 0 0 0 0 0 0 0 0 0 0 0
56599- 0 0 0 0 0 0 0 0 0 0 0 0
56600- 0 0 0 0 0 0 0 0 0 10 10 10
56601- 30 30 30 74 74 74 174 135 50 216 158 10
56602-236 178 12 246 190 14 246 190 14 246 190 14
56603-246 190 14 246 190 14 246 190 14 246 190 14
56604-246 190 14 246 190 14 246 190 14 246 190 14
56605-246 190 14 246 190 14 241 196 14 226 184 13
56606- 61 42 6 2 2 6 2 2 6 2 2 6
56607- 22 22 22 238 238 238 253 253 253 253 253 253
56608-253 253 253 253 253 253 253 253 253 253 253 253
56609-253 253 253 253 253 253 253 253 253 253 253 253
56610-253 253 253 253 253 253 253 253 253 253 253 253
56611-253 253 253 226 226 226 187 187 187 180 133 36
56612-216 158 10 236 178 12 239 182 13 236 178 12
56613-230 174 11 226 170 11 226 170 11 230 174 11
56614-236 178 12 242 186 14 246 190 14 246 190 14
56615-246 190 14 246 190 14 246 186 14 239 182 13
56616-206 162 42 106 106 106 66 66 66 34 34 34
56617- 14 14 14 6 6 6 0 0 0 0 0 0
56618- 0 0 0 0 0 0 0 0 0 0 0 0
56619- 0 0 0 0 0 0 0 0 0 0 0 0
56620- 0 0 0 0 0 0 0 0 0 6 6 6
56621- 26 26 26 70 70 70 163 133 67 213 154 11
56622-236 178 12 246 190 14 246 190 14 246 190 14
56623-246 190 14 246 190 14 246 190 14 246 190 14
56624-246 190 14 246 190 14 246 190 14 246 190 14
56625-246 190 14 246 190 14 246 190 14 241 196 14
56626-190 146 13 18 14 6 2 2 6 2 2 6
56627- 46 46 46 246 246 246 253 253 253 253 253 253
56628-253 253 253 253 253 253 253 253 253 253 253 253
56629-253 253 253 253 253 253 253 253 253 253 253 253
56630-253 253 253 253 253 253 253 253 253 253 253 253
56631-253 253 253 221 221 221 86 86 86 156 107 11
56632-216 158 10 236 178 12 242 186 14 246 186 14
56633-242 186 14 239 182 13 239 182 13 242 186 14
56634-242 186 14 246 186 14 246 190 14 246 190 14
56635-246 190 14 246 190 14 246 190 14 246 190 14
56636-242 186 14 225 175 15 142 122 72 66 66 66
56637- 30 30 30 10 10 10 0 0 0 0 0 0
56638- 0 0 0 0 0 0 0 0 0 0 0 0
56639- 0 0 0 0 0 0 0 0 0 0 0 0
56640- 0 0 0 0 0 0 0 0 0 6 6 6
56641- 26 26 26 70 70 70 163 133 67 210 150 10
56642-236 178 12 246 190 14 246 190 14 246 190 14
56643-246 190 14 246 190 14 246 190 14 246 190 14
56644-246 190 14 246 190 14 246 190 14 246 190 14
56645-246 190 14 246 190 14 246 190 14 246 190 14
56646-232 195 16 121 92 8 34 34 34 106 106 106
56647-221 221 221 253 253 253 253 253 253 253 253 253
56648-253 253 253 253 253 253 253 253 253 253 253 253
56649-253 253 253 253 253 253 253 253 253 253 253 253
56650-253 253 253 253 253 253 253 253 253 253 253 253
56651-242 242 242 82 82 82 18 14 6 163 110 8
56652-216 158 10 236 178 12 242 186 14 246 190 14
56653-246 190 14 246 190 14 246 190 14 246 190 14
56654-246 190 14 246 190 14 246 190 14 246 190 14
56655-246 190 14 246 190 14 246 190 14 246 190 14
56656-246 190 14 246 190 14 242 186 14 163 133 67
56657- 46 46 46 18 18 18 6 6 6 0 0 0
56658- 0 0 0 0 0 0 0 0 0 0 0 0
56659- 0 0 0 0 0 0 0 0 0 0 0 0
56660- 0 0 0 0 0 0 0 0 0 10 10 10
56661- 30 30 30 78 78 78 163 133 67 210 150 10
56662-236 178 12 246 186 14 246 190 14 246 190 14
56663-246 190 14 246 190 14 246 190 14 246 190 14
56664-246 190 14 246 190 14 246 190 14 246 190 14
56665-246 190 14 246 190 14 246 190 14 246 190 14
56666-241 196 14 215 174 15 190 178 144 253 253 253
56667-253 253 253 253 253 253 253 253 253 253 253 253
56668-253 253 253 253 253 253 253 253 253 253 253 253
56669-253 253 253 253 253 253 253 253 253 253 253 253
56670-253 253 253 253 253 253 253 253 253 218 218 218
56671- 58 58 58 2 2 6 22 18 6 167 114 7
56672-216 158 10 236 178 12 246 186 14 246 190 14
56673-246 190 14 246 190 14 246 190 14 246 190 14
56674-246 190 14 246 190 14 246 190 14 246 190 14
56675-246 190 14 246 190 14 246 190 14 246 190 14
56676-246 190 14 246 186 14 242 186 14 190 150 46
56677- 54 54 54 22 22 22 6 6 6 0 0 0
56678- 0 0 0 0 0 0 0 0 0 0 0 0
56679- 0 0 0 0 0 0 0 0 0 0 0 0
56680- 0 0 0 0 0 0 0 0 0 14 14 14
56681- 38 38 38 86 86 86 180 133 36 213 154 11
56682-236 178 12 246 186 14 246 190 14 246 190 14
56683-246 190 14 246 190 14 246 190 14 246 190 14
56684-246 190 14 246 190 14 246 190 14 246 190 14
56685-246 190 14 246 190 14 246 190 14 246 190 14
56686-246 190 14 232 195 16 190 146 13 214 214 214
56687-253 253 253 253 253 253 253 253 253 253 253 253
56688-253 253 253 253 253 253 253 253 253 253 253 253
56689-253 253 253 253 253 253 253 253 253 253 253 253
56690-253 253 253 250 250 250 170 170 170 26 26 26
56691- 2 2 6 2 2 6 37 26 9 163 110 8
56692-219 162 10 239 182 13 246 186 14 246 190 14
56693-246 190 14 246 190 14 246 190 14 246 190 14
56694-246 190 14 246 190 14 246 190 14 246 190 14
56695-246 190 14 246 190 14 246 190 14 246 190 14
56696-246 186 14 236 178 12 224 166 10 142 122 72
56697- 46 46 46 18 18 18 6 6 6 0 0 0
56698- 0 0 0 0 0 0 0 0 0 0 0 0
56699- 0 0 0 0 0 0 0 0 0 0 0 0
56700- 0 0 0 0 0 0 6 6 6 18 18 18
56701- 50 50 50 109 106 95 192 133 9 224 166 10
56702-242 186 14 246 190 14 246 190 14 246 190 14
56703-246 190 14 246 190 14 246 190 14 246 190 14
56704-246 190 14 246 190 14 246 190 14 246 190 14
56705-246 190 14 246 190 14 246 190 14 246 190 14
56706-242 186 14 226 184 13 210 162 10 142 110 46
56707-226 226 226 253 253 253 253 253 253 253 253 253
56708-253 253 253 253 253 253 253 253 253 253 253 253
56709-253 253 253 253 253 253 253 253 253 253 253 253
56710-198 198 198 66 66 66 2 2 6 2 2 6
56711- 2 2 6 2 2 6 50 34 6 156 107 11
56712-219 162 10 239 182 13 246 186 14 246 190 14
56713-246 190 14 246 190 14 246 190 14 246 190 14
56714-246 190 14 246 190 14 246 190 14 246 190 14
56715-246 190 14 246 190 14 246 190 14 242 186 14
56716-234 174 13 213 154 11 154 122 46 66 66 66
56717- 30 30 30 10 10 10 0 0 0 0 0 0
56718- 0 0 0 0 0 0 0 0 0 0 0 0
56719- 0 0 0 0 0 0 0 0 0 0 0 0
56720- 0 0 0 0 0 0 6 6 6 22 22 22
56721- 58 58 58 154 121 60 206 145 10 234 174 13
56722-242 186 14 246 186 14 246 190 14 246 190 14
56723-246 190 14 246 190 14 246 190 14 246 190 14
56724-246 190 14 246 190 14 246 190 14 246 190 14
56725-246 190 14 246 190 14 246 190 14 246 190 14
56726-246 186 14 236 178 12 210 162 10 163 110 8
56727- 61 42 6 138 138 138 218 218 218 250 250 250
56728-253 253 253 253 253 253 253 253 253 250 250 250
56729-242 242 242 210 210 210 144 144 144 66 66 66
56730- 6 6 6 2 2 6 2 2 6 2 2 6
56731- 2 2 6 2 2 6 61 42 6 163 110 8
56732-216 158 10 236 178 12 246 190 14 246 190 14
56733-246 190 14 246 190 14 246 190 14 246 190 14
56734-246 190 14 246 190 14 246 190 14 246 190 14
56735-246 190 14 239 182 13 230 174 11 216 158 10
56736-190 142 34 124 112 88 70 70 70 38 38 38
56737- 18 18 18 6 6 6 0 0 0 0 0 0
56738- 0 0 0 0 0 0 0 0 0 0 0 0
56739- 0 0 0 0 0 0 0 0 0 0 0 0
56740- 0 0 0 0 0 0 6 6 6 22 22 22
56741- 62 62 62 168 124 44 206 145 10 224 166 10
56742-236 178 12 239 182 13 242 186 14 242 186 14
56743-246 186 14 246 190 14 246 190 14 246 190 14
56744-246 190 14 246 190 14 246 190 14 246 190 14
56745-246 190 14 246 190 14 246 190 14 246 190 14
56746-246 190 14 236 178 12 216 158 10 175 118 6
56747- 80 54 7 2 2 6 6 6 6 30 30 30
56748- 54 54 54 62 62 62 50 50 50 38 38 38
56749- 14 14 14 2 2 6 2 2 6 2 2 6
56750- 2 2 6 2 2 6 2 2 6 2 2 6
56751- 2 2 6 6 6 6 80 54 7 167 114 7
56752-213 154 11 236 178 12 246 190 14 246 190 14
56753-246 190 14 246 190 14 246 190 14 246 190 14
56754-246 190 14 242 186 14 239 182 13 239 182 13
56755-230 174 11 210 150 10 174 135 50 124 112 88
56756- 82 82 82 54 54 54 34 34 34 18 18 18
56757- 6 6 6 0 0 0 0 0 0 0 0 0
56758- 0 0 0 0 0 0 0 0 0 0 0 0
56759- 0 0 0 0 0 0 0 0 0 0 0 0
56760- 0 0 0 0 0 0 6 6 6 18 18 18
56761- 50 50 50 158 118 36 192 133 9 200 144 11
56762-216 158 10 219 162 10 224 166 10 226 170 11
56763-230 174 11 236 178 12 239 182 13 239 182 13
56764-242 186 14 246 186 14 246 190 14 246 190 14
56765-246 190 14 246 190 14 246 190 14 246 190 14
56766-246 186 14 230 174 11 210 150 10 163 110 8
56767-104 69 6 10 10 10 2 2 6 2 2 6
56768- 2 2 6 2 2 6 2 2 6 2 2 6
56769- 2 2 6 2 2 6 2 2 6 2 2 6
56770- 2 2 6 2 2 6 2 2 6 2 2 6
56771- 2 2 6 6 6 6 91 60 6 167 114 7
56772-206 145 10 230 174 11 242 186 14 246 190 14
56773-246 190 14 246 190 14 246 186 14 242 186 14
56774-239 182 13 230 174 11 224 166 10 213 154 11
56775-180 133 36 124 112 88 86 86 86 58 58 58
56776- 38 38 38 22 22 22 10 10 10 6 6 6
56777- 0 0 0 0 0 0 0 0 0 0 0 0
56778- 0 0 0 0 0 0 0 0 0 0 0 0
56779- 0 0 0 0 0 0 0 0 0 0 0 0
56780- 0 0 0 0 0 0 0 0 0 14 14 14
56781- 34 34 34 70 70 70 138 110 50 158 118 36
56782-167 114 7 180 123 7 192 133 9 197 138 11
56783-200 144 11 206 145 10 213 154 11 219 162 10
56784-224 166 10 230 174 11 239 182 13 242 186 14
56785-246 186 14 246 186 14 246 186 14 246 186 14
56786-239 182 13 216 158 10 185 133 11 152 99 6
56787-104 69 6 18 14 6 2 2 6 2 2 6
56788- 2 2 6 2 2 6 2 2 6 2 2 6
56789- 2 2 6 2 2 6 2 2 6 2 2 6
56790- 2 2 6 2 2 6 2 2 6 2 2 6
56791- 2 2 6 6 6 6 80 54 7 152 99 6
56792-192 133 9 219 162 10 236 178 12 239 182 13
56793-246 186 14 242 186 14 239 182 13 236 178 12
56794-224 166 10 206 145 10 192 133 9 154 121 60
56795- 94 94 94 62 62 62 42 42 42 22 22 22
56796- 14 14 14 6 6 6 0 0 0 0 0 0
56797- 0 0 0 0 0 0 0 0 0 0 0 0
56798- 0 0 0 0 0 0 0 0 0 0 0 0
56799- 0 0 0 0 0 0 0 0 0 0 0 0
56800- 0 0 0 0 0 0 0 0 0 6 6 6
56801- 18 18 18 34 34 34 58 58 58 78 78 78
56802-101 98 89 124 112 88 142 110 46 156 107 11
56803-163 110 8 167 114 7 175 118 6 180 123 7
56804-185 133 11 197 138 11 210 150 10 219 162 10
56805-226 170 11 236 178 12 236 178 12 234 174 13
56806-219 162 10 197 138 11 163 110 8 130 83 6
56807- 91 60 6 10 10 10 2 2 6 2 2 6
56808- 18 18 18 38 38 38 38 38 38 38 38 38
56809- 38 38 38 38 38 38 38 38 38 38 38 38
56810- 38 38 38 38 38 38 26 26 26 2 2 6
56811- 2 2 6 6 6 6 70 47 6 137 92 6
56812-175 118 6 200 144 11 219 162 10 230 174 11
56813-234 174 13 230 174 11 219 162 10 210 150 10
56814-192 133 9 163 110 8 124 112 88 82 82 82
56815- 50 50 50 30 30 30 14 14 14 6 6 6
56816- 0 0 0 0 0 0 0 0 0 0 0 0
56817- 0 0 0 0 0 0 0 0 0 0 0 0
56818- 0 0 0 0 0 0 0 0 0 0 0 0
56819- 0 0 0 0 0 0 0 0 0 0 0 0
56820- 0 0 0 0 0 0 0 0 0 0 0 0
56821- 6 6 6 14 14 14 22 22 22 34 34 34
56822- 42 42 42 58 58 58 74 74 74 86 86 86
56823-101 98 89 122 102 70 130 98 46 121 87 25
56824-137 92 6 152 99 6 163 110 8 180 123 7
56825-185 133 11 197 138 11 206 145 10 200 144 11
56826-180 123 7 156 107 11 130 83 6 104 69 6
56827- 50 34 6 54 54 54 110 110 110 101 98 89
56828- 86 86 86 82 82 82 78 78 78 78 78 78
56829- 78 78 78 78 78 78 78 78 78 78 78 78
56830- 78 78 78 82 82 82 86 86 86 94 94 94
56831-106 106 106 101 101 101 86 66 34 124 80 6
56832-156 107 11 180 123 7 192 133 9 200 144 11
56833-206 145 10 200 144 11 192 133 9 175 118 6
56834-139 102 15 109 106 95 70 70 70 42 42 42
56835- 22 22 22 10 10 10 0 0 0 0 0 0
56836- 0 0 0 0 0 0 0 0 0 0 0 0
56837- 0 0 0 0 0 0 0 0 0 0 0 0
56838- 0 0 0 0 0 0 0 0 0 0 0 0
56839- 0 0 0 0 0 0 0 0 0 0 0 0
56840- 0 0 0 0 0 0 0 0 0 0 0 0
56841- 0 0 0 0 0 0 6 6 6 10 10 10
56842- 14 14 14 22 22 22 30 30 30 38 38 38
56843- 50 50 50 62 62 62 74 74 74 90 90 90
56844-101 98 89 112 100 78 121 87 25 124 80 6
56845-137 92 6 152 99 6 152 99 6 152 99 6
56846-138 86 6 124 80 6 98 70 6 86 66 30
56847-101 98 89 82 82 82 58 58 58 46 46 46
56848- 38 38 38 34 34 34 34 34 34 34 34 34
56849- 34 34 34 34 34 34 34 34 34 34 34 34
56850- 34 34 34 34 34 34 38 38 38 42 42 42
56851- 54 54 54 82 82 82 94 86 76 91 60 6
56852-134 86 6 156 107 11 167 114 7 175 118 6
56853-175 118 6 167 114 7 152 99 6 121 87 25
56854-101 98 89 62 62 62 34 34 34 18 18 18
56855- 6 6 6 0 0 0 0 0 0 0 0 0
56856- 0 0 0 0 0 0 0 0 0 0 0 0
56857- 0 0 0 0 0 0 0 0 0 0 0 0
56858- 0 0 0 0 0 0 0 0 0 0 0 0
56859- 0 0 0 0 0 0 0 0 0 0 0 0
56860- 0 0 0 0 0 0 0 0 0 0 0 0
56861- 0 0 0 0 0 0 0 0 0 0 0 0
56862- 0 0 0 6 6 6 6 6 6 10 10 10
56863- 18 18 18 22 22 22 30 30 30 42 42 42
56864- 50 50 50 66 66 66 86 86 86 101 98 89
56865-106 86 58 98 70 6 104 69 6 104 69 6
56866-104 69 6 91 60 6 82 62 34 90 90 90
56867- 62 62 62 38 38 38 22 22 22 14 14 14
56868- 10 10 10 10 10 10 10 10 10 10 10 10
56869- 10 10 10 10 10 10 6 6 6 10 10 10
56870- 10 10 10 10 10 10 10 10 10 14 14 14
56871- 22 22 22 42 42 42 70 70 70 89 81 66
56872- 80 54 7 104 69 6 124 80 6 137 92 6
56873-134 86 6 116 81 8 100 82 52 86 86 86
56874- 58 58 58 30 30 30 14 14 14 6 6 6
56875- 0 0 0 0 0 0 0 0 0 0 0 0
56876- 0 0 0 0 0 0 0 0 0 0 0 0
56877- 0 0 0 0 0 0 0 0 0 0 0 0
56878- 0 0 0 0 0 0 0 0 0 0 0 0
56879- 0 0 0 0 0 0 0 0 0 0 0 0
56880- 0 0 0 0 0 0 0 0 0 0 0 0
56881- 0 0 0 0 0 0 0 0 0 0 0 0
56882- 0 0 0 0 0 0 0 0 0 0 0 0
56883- 0 0 0 6 6 6 10 10 10 14 14 14
56884- 18 18 18 26 26 26 38 38 38 54 54 54
56885- 70 70 70 86 86 86 94 86 76 89 81 66
56886- 89 81 66 86 86 86 74 74 74 50 50 50
56887- 30 30 30 14 14 14 6 6 6 0 0 0
56888- 0 0 0 0 0 0 0 0 0 0 0 0
56889- 0 0 0 0 0 0 0 0 0 0 0 0
56890- 0 0 0 0 0 0 0 0 0 0 0 0
56891- 6 6 6 18 18 18 34 34 34 58 58 58
56892- 82 82 82 89 81 66 89 81 66 89 81 66
56893- 94 86 66 94 86 76 74 74 74 50 50 50
56894- 26 26 26 14 14 14 6 6 6 0 0 0
56895- 0 0 0 0 0 0 0 0 0 0 0 0
56896- 0 0 0 0 0 0 0 0 0 0 0 0
56897- 0 0 0 0 0 0 0 0 0 0 0 0
56898- 0 0 0 0 0 0 0 0 0 0 0 0
56899- 0 0 0 0 0 0 0 0 0 0 0 0
56900- 0 0 0 0 0 0 0 0 0 0 0 0
56901- 0 0 0 0 0 0 0 0 0 0 0 0
56902- 0 0 0 0 0 0 0 0 0 0 0 0
56903- 0 0 0 0 0 0 0 0 0 0 0 0
56904- 6 6 6 6 6 6 14 14 14 18 18 18
56905- 30 30 30 38 38 38 46 46 46 54 54 54
56906- 50 50 50 42 42 42 30 30 30 18 18 18
56907- 10 10 10 0 0 0 0 0 0 0 0 0
56908- 0 0 0 0 0 0 0 0 0 0 0 0
56909- 0 0 0 0 0 0 0 0 0 0 0 0
56910- 0 0 0 0 0 0 0 0 0 0 0 0
56911- 0 0 0 6 6 6 14 14 14 26 26 26
56912- 38 38 38 50 50 50 58 58 58 58 58 58
56913- 54 54 54 42 42 42 30 30 30 18 18 18
56914- 10 10 10 0 0 0 0 0 0 0 0 0
56915- 0 0 0 0 0 0 0 0 0 0 0 0
56916- 0 0 0 0 0 0 0 0 0 0 0 0
56917- 0 0 0 0 0 0 0 0 0 0 0 0
56918- 0 0 0 0 0 0 0 0 0 0 0 0
56919- 0 0 0 0 0 0 0 0 0 0 0 0
56920- 0 0 0 0 0 0 0 0 0 0 0 0
56921- 0 0 0 0 0 0 0 0 0 0 0 0
56922- 0 0 0 0 0 0 0 0 0 0 0 0
56923- 0 0 0 0 0 0 0 0 0 0 0 0
56924- 0 0 0 0 0 0 0 0 0 6 6 6
56925- 6 6 6 10 10 10 14 14 14 18 18 18
56926- 18 18 18 14 14 14 10 10 10 6 6 6
56927- 0 0 0 0 0 0 0 0 0 0 0 0
56928- 0 0 0 0 0 0 0 0 0 0 0 0
56929- 0 0 0 0 0 0 0 0 0 0 0 0
56930- 0 0 0 0 0 0 0 0 0 0 0 0
56931- 0 0 0 0 0 0 0 0 0 6 6 6
56932- 14 14 14 18 18 18 22 22 22 22 22 22
56933- 18 18 18 14 14 14 10 10 10 6 6 6
56934- 0 0 0 0 0 0 0 0 0 0 0 0
56935- 0 0 0 0 0 0 0 0 0 0 0 0
56936- 0 0 0 0 0 0 0 0 0 0 0 0
56937- 0 0 0 0 0 0 0 0 0 0 0 0
56938- 0 0 0 0 0 0 0 0 0 0 0 0
56939+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56940+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56941+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56942+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56943+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56944+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56945+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56946+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56947+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56948+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56949+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56950+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56951+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56952+4 4 4 4 4 4
56953+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56954+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56955+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56956+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56957+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56958+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56959+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56960+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56961+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56962+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56963+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56964+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56965+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56966+4 4 4 4 4 4
56967+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56968+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56969+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56970+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56971+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56972+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56973+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56974+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56975+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56976+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56977+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56978+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56979+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56980+4 4 4 4 4 4
56981+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56982+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56983+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56984+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56985+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56986+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56987+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56988+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56989+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56990+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56991+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56992+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56993+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56994+4 4 4 4 4 4
56995+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56996+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56997+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56998+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56999+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57000+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57001+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57002+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57003+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57004+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57005+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57006+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57007+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57008+4 4 4 4 4 4
57009+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57010+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57011+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57012+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57013+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57014+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57015+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57016+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57017+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57018+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57019+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57020+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57021+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57022+4 4 4 4 4 4
57023+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57024+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57025+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57026+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57027+4 4 4 4 4 4 4 4 4 3 3 3 0 0 0 0 0 0
57028+0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 4 4 4
57029+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57030+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57031+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57032+4 4 4 4 4 4 4 4 4 4 4 4 1 1 1 0 0 0
57033+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
57034+4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
57035+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57036+4 4 4 4 4 4
57037+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57038+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57039+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57040+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57041+4 4 4 4 4 4 2 2 2 0 0 0 3 4 3 26 28 28
57042+37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
57043+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57044+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57045+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57046+4 4 4 4 4 4 3 3 3 0 0 0 1 1 1 6 6 6
57047+2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
57048+4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
57049+1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57050+4 4 4 4 4 4
57051+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57052+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57053+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57054+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57055+2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
57056+153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
57057+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
57058+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57059+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57060+4 4 4 4 4 4 0 0 0 4 4 4 41 54 63 125 124 125
57061+60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
57062+4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
57063+2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
57064+4 4 4 4 4 4
57065+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57066+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57067+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57068+4 4 4 4 4 4 5 5 5 5 5 5 2 2 2 0 0 0
57069+4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
57070+165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
57071+1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 4 4 4
57072+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57073+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
57074+3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
57075+163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
57076+0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
57077+37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
57078+4 4 4 4 4 4
57079+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57080+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57081+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57082+4 4 4 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
57083+37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
57084+156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
57085+125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
57086+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
57087+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
57088+0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
57089+174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
57090+0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
57091+64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
57092+4 4 4 4 4 4
57093+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57094+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57095+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
57096+5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
57097+156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
57098+156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
57099+174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
57100+1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
57101+4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
57102+13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
57103+174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
57104+22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
57105+90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
57106+4 4 4 4 4 4
57107+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57108+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57109+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 3 3 3
57110+0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
57111+174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
57112+156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
57113+163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
57114+4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
57115+5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
57116+131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
57117+190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
57118+90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
57119+31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
57120+4 4 4 4 4 4
57121+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57122+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57123+4 4 4 4 4 4 4 4 4 2 2 2 0 0 0 4 0 0
57124+4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
57125+155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
57126+167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
57127+153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
57128+41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
57129+1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
57130+177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
57131+125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
57132+136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
57133+7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
57134+4 4 4 4 4 4
57135+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57136+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57137+4 4 4 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
57138+125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
57139+156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
57140+137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
57141+156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
57142+167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
57143+0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
57144+166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
57145+6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
57146+90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
57147+1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
57148+4 4 4 4 4 4
57149+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57150+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57151+1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
57152+167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
57153+157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
57154+26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
57155+158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
57156+165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
57157+60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
57158+137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
57159+52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
57160+13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
57161+4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
57162+4 4 4 4 4 4
57163+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57164+4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
57165+0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
57166+158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
57167+167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
57168+4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
57169+174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
57170+155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
57171+137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
57172+16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
57173+136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
57174+2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
57175+4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
57176+4 4 4 4 4 4
57177+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57178+4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
57179+37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
57180+157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
57181+153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
57182+4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
57183+125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
57184+156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
57185+174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
57186+4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
57187+136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
57188+1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
57189+2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
57190+0 0 0 4 4 4
57191+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
57192+4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
57193+158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
57194+153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
57195+37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
57196+4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
57197+4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
57198+154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
57199+174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
57200+32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
57201+28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
57202+50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
57203+0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
57204+2 0 0 0 0 0
57205+4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
57206+0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
57207+174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
57208+165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
57209+4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
57210+4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
57211+4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
57212+174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
57213+60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
57214+136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
57215+22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
57216+136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
57217+26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
57218+37 38 37 0 0 0
57219+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
57220+13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
57221+153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
57222+177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
57223+4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
57224+5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
57225+6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
57226+166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
57227+4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
57228+146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
57229+71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
57230+90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
57231+125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
57232+85 115 134 4 0 0
57233+4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
57234+125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
57235+155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
57236+125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
57237+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
57238+0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
57239+5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
57240+37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
57241+4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
57242+90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
57243+2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
57244+13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
57245+166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
57246+60 73 81 4 0 0
57247+4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
57248+174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
57249+156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
57250+4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
57251+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
57252+10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
57253+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
57254+4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
57255+80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
57256+28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
57257+50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
57258+1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
57259+167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
57260+16 19 21 4 0 0
57261+4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
57262+158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
57263+167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
57264+4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
57265+4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
57266+80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
57267+4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
57268+3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
57269+146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
57270+68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
57271+136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
57272+24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
57273+163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
57274+4 0 0 4 3 3
57275+3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
57276+156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
57277+155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
57278+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
57279+2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
57280+136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
57281+0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
57282+0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
57283+136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
57284+28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
57285+22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
57286+137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
57287+60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
57288+3 2 2 4 4 4
57289+3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
57290+157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
57291+37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
57292+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
57293+0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
57294+101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
57295+14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
57296+22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
57297+136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
57298+17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
57299+2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
57300+166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
57301+13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
57302+4 4 4 4 4 4
57303+1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
57304+163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
57305+4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
57306+4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
57307+40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
57308+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
57309+101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
57310+136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
57311+136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
57312+136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
57313+3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
57314+174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
57315+4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
57316+4 4 4 4 4 4
57317+4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
57318+155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
57319+4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
57320+4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
57321+101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
57322+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
57323+136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
57324+136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
57325+136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
57326+90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
57327+85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
57328+167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
57329+6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
57330+5 5 5 5 5 5
57331+1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
57332+131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
57333+6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
57334+0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
57335+101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
57336+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
57337+101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
57338+136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
57339+101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
57340+7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
57341+174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
57342+24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
57343+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
57344+5 5 5 4 4 4
57345+4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
57346+131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
57347+6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
57348+13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
57349+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
57350+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
57351+101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
57352+136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
57353+136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
57354+2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
57355+174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
57356+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
57357+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57358+4 4 4 4 4 4
57359+1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
57360+137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
57361+4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
57362+64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
57363+90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
57364+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
57365+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
57366+136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
57367+101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
57368+37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
57369+167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
57370+3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
57371+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57372+4 4 4 4 4 4
57373+4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
57374+153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
57375+4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
57376+90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
57377+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
57378+90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
57379+101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
57380+101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
57381+35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
57382+154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
57383+60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
57384+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57385+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57386+4 4 4 4 4 4
57387+1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
57388+153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
57389+4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
57390+64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
57391+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
57392+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
57393+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
57394+136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
57395+13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
57396+174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
57397+6 6 6 4 0 0 4 0 0 4 4 4 4 4 4 4 4 4
57398+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57399+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57400+4 4 4 4 4 4
57401+4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
57402+156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
57403+4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
57404+90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
57405+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
57406+90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
57407+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
57408+101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
57409+2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
57410+174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
57411+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57412+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57413+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57414+4 4 4 4 4 4
57415+3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
57416+158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
57417+4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
57418+37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
57419+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
57420+90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
57421+101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
57422+90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
57423+5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
57424+167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
57425+6 6 6 4 0 0 6 6 6 4 4 4 4 4 4 4 4 4
57426+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57427+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57428+4 4 4 4 4 4
57429+4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
57430+163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
57431+4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
57432+18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
57433+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
57434+90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
57435+101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
57436+13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
57437+3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
57438+174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
57439+4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
57440+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57441+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57442+4 4 4 4 4 4
57443+1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
57444+167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
57445+4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
57446+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
57447+26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
57448+90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
57449+101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
57450+7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
57451+4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
57452+174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
57453+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57454+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57455+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57456+4 4 4 4 4 4
57457+4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
57458+174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
57459+5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
57460+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
57461+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
57462+90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
57463+101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
57464+2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
57465+3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
57466+153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
57467+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57468+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57469+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57470+4 4 4 4 4 4
57471+1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
57472+174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
57473+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
57474+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
57475+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
57476+26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
57477+35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
57478+2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
57479+3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
57480+131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
57481+4 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57482+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57483+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57484+4 4 4 4 4 4
57485+3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
57486+174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
57487+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
57488+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
57489+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
57490+26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
57491+7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
57492+4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
57493+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
57494+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57495+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57496+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57497+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57498+4 4 4 4 4 4
57499+1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
57500+174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
57501+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
57502+18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
57503+18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
57504+26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
57505+28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
57506+3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
57507+4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
57508+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57509+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57510+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57511+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57512+4 4 4 4 4 4
57513+4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
57514+174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
57515+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
57516+10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
57517+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
57518+18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
57519+90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
57520+3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
57521+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
57522+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57523+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57524+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57525+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57526+4 4 4 4 4 4
57527+1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
57528+177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
57529+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
57530+10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
57531+26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
57532+6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
57533+10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
57534+2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
57535+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
57536+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57537+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57538+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57539+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57540+4 4 4 4 4 4
57541+4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
57542+177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
57543+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
57544+10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
57545+26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
57546+7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
57547+3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
57548+21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
57549+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
57550+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57551+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57552+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57553+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57554+4 4 4 4 4 4
57555+3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
57556+190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
57557+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
57558+10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
57559+24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
57560+18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
57561+28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
57562+26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
57563+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
57564+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57565+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57566+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57567+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57568+4 4 4 4 4 4
57569+4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
57570+190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
57571+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
57572+10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
57573+0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
57574+26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
57575+37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
57576+90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
57577+4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
57578+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57579+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57580+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57581+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57582+4 4 4 4 4 4
57583+4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
57584+193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
57585+5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
57586+10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
57587+1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
57588+26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
57589+22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
57590+26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
57591+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
57592+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57593+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57594+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57595+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57596+4 4 4 4 4 4
57597+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
57598+190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
57599+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
57600+10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
57601+2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
57602+26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
57603+10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
57604+26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
57605+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
57606+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57607+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57608+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57609+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57610+4 4 4 4 4 4
57611+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
57612+193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
57613+5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
57614+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
57615+13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
57616+10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
57617+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
57618+26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
57619+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
57620+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57621+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57622+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57623+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57624+4 4 4 4 4 4
57625+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
57626+190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
57627+5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
57628+28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
57629+10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
57630+28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
57631+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
57632+26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
57633+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
57634+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57635+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57636+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57637+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57638+4 4 4 4 4 4
57639+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
57640+193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
57641+5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
57642+4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
57643+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
57644+10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
57645+18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
57646+22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
57647+4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
57648+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57649+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57650+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57651+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57652+4 4 4 4 4 4
57653+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
57654+190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
57655+6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
57656+1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
57657+18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
57658+10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
57659+26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
57660+1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
57661+5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
57662+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57663+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57664+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57665+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57666+4 4 4 4 4 4
57667+4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
57668+193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
57669+2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
57670+4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
57671+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
57672+10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
57673+26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
57674+2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
57675+3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
57676+131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57677+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57678+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57679+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57680+4 4 4 4 4 4
57681+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
57682+193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
57683+0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
57684+4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
57685+13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
57686+10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
57687+28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
57688+4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
57689+0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
57690+125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57691+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57692+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57693+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57694+4 4 4 4 4 4
57695+4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
57696+193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
57697+120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
57698+4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
57699+4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
57700+10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
57701+4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
57702+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
57703+24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
57704+125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
57705+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57706+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57707+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57708+4 4 4 4 4 4
57709+4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
57710+174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
57711+220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
57712+3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
57713+4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
57714+10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
57715+1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
57716+5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
57717+137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
57718+125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
57719+0 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57720+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57721+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57722+4 4 4 4 4 4
57723+5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
57724+193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
57725+220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
57726+4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
57727+4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
57728+22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
57729+4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57730+1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
57731+166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
57732+125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
57733+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
57734+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57735+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57736+4 4 4 4 4 4
57737+4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
57738+220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
57739+205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
57740+24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
57741+4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
57742+4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
57743+4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
57744+2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
57745+156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
57746+137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
57747+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57748+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57749+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57750+4 4 4 4 4 4
57751+5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
57752+125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
57753+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
57754+193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
57755+5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
57756+1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
57757+5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
57758+60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
57759+153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
57760+125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
57761+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57762+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57763+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57764+4 4 4 4 4 4
57765+4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
57766+6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
57767+193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
57768+244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
57769+0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
57770+4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
57771+3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
57772+220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
57773+153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
57774+13 16 17 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
57775+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57776+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57777+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57778+4 4 4 4 4 4
57779+5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
57780+6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
57781+244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
57782+220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
57783+3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
57784+4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
57785+0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
57786+177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
57787+158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
57788+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
57789+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57790+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57791+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57792+4 4 4 4 4 4
57793+5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
57794+6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
57795+177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
57796+220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
57797+125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
57798+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
57799+37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
57800+174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
57801+158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
57802+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
57803+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57804+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57805+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57806+4 4 4 4 4 4
57807+4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
57808+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
57809+26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
57810+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
57811+244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
57812+0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
57813+177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
57814+174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
57815+60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
57816+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57817+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57818+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57819+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57820+4 4 4 4 4 4
57821+5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
57822+6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
57823+6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
57824+220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
57825+220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
57826+0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
57827+220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
57828+174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
57829+4 0 0 4 0 0 4 0 0 6 6 6 4 4 4 4 4 4
57830+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57831+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57832+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57833+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57834+4 4 4 4 4 4
57835+4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
57836+6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
57837+4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
57838+220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
57839+205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
57840+60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
57841+177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
57842+190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
57843+4 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57844+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57845+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57846+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57847+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57848+4 4 4 4 4 4
57849+4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
57850+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
57851+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
57852+125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
57853+205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
57854+193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
57855+190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
57856+153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
57857+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57858+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57859+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57860+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57861+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57862+4 4 4 4 4 4
57863+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
57864+6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
57865+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
57866+4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
57867+205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
57868+220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
57869+174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
57870+6 6 6 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
57871+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57872+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57873+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57874+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57875+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57876+4 4 4 4 4 4
57877+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
57878+5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
57879+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
57880+4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
57881+220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
57882+190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
57883+193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
57884+4 0 0 4 3 3 6 6 6 4 4 4 4 4 4 4 4 4
57885+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57886+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57887+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57888+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57889+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57890+4 4 4 4 4 4
57891+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57892+4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
57893+4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
57894+6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
57895+174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
57896+193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
57897+193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
57898+6 6 6 6 6 6 4 3 3 5 5 5 4 4 4 4 4 4
57899+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57900+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57901+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57902+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57903+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57904+4 4 4 4 4 4
57905+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57906+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
57907+5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
57908+5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
57909+6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
57910+193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
57911+60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
57912+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
57913+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57914+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57915+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57916+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57917+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57918+4 4 4 4 4 4
57919+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57920+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57921+4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
57922+5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
57923+4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
57924+193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
57925+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
57926+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
57927+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57928+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57929+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57930+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57931+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57932+4 4 4 4 4 4
57933+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57934+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57935+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
57936+4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
57937+6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
57938+153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
57939+6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
57940+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57941+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57942+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57943+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57944+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57945+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57946+4 4 4 4 4 4
57947+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57948+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57949+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57950+4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
57951+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
57952+24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
57953+6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
57954+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57955+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57956+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57957+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57958+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57959+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57960+4 4 4 4 4 4
57961+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57962+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57963+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57964+4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
57965+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
57966+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
57967+4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 4 4 4
57968+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57969+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57970+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57971+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57972+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57973+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57974+4 4 4 4 4 4
57975+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57976+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57977+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57978+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 5 5 5
57979+5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
57980+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
57981+6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 4 4 4
57982+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57983+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57984+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57985+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57986+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57987+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57988+4 4 4 4 4 4
57989+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57990+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57991+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57992+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
57993+4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
57994+4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
57995+6 6 6 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57996+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57997+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57998+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57999+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58000+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58001+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58002+4 4 4 4 4 4
58003+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58004+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58005+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58006+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58007+4 4 4 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
58008+6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
58009+4 3 3 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
58010+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58011+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58012+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58013+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58014+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58015+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58016+4 4 4 4 4 4
58017+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58018+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58019+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58020+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58021+4 4 4 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
58022+4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
58023+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58024+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58025+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58026+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58027+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58028+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58029+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58030+4 4 4 4 4 4
58031+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58032+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58033+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58034+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58035+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 6 6 6
58036+5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
58037+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58038+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58039+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58040+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58041+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58042+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58043+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58044+4 4 4 4 4 4
58045+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58046+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58047+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58048+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58049+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
58050+5 5 5 4 3 3 5 5 5 5 5 5 4 4 4 4 4 4
58051+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58052+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58053+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58054+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58055+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58056+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58057+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58058+4 4 4 4 4 4
58059diff --git a/drivers/xen/xenfs/xenstored.c b/drivers/xen/xenfs/xenstored.c
58060index fef20db..d28b1ab 100644
58061--- a/drivers/xen/xenfs/xenstored.c
58062+++ b/drivers/xen/xenfs/xenstored.c
58063@@ -24,7 +24,12 @@ static int xsd_release(struct inode *inode, struct file *file)
58064 static int xsd_kva_open(struct inode *inode, struct file *file)
58065 {
58066 file->private_data = (void *)kasprintf(GFP_KERNEL, "0x%p",
58067+#ifdef CONFIG_GRKERNSEC_HIDESYM
58068+ NULL);
58069+#else
58070 xen_store_interface);
58071+#endif
58072+
58073 if (!file->private_data)
58074 return -ENOMEM;
58075 return 0;
58076diff --git a/fs/9p/vfs_addr.c b/fs/9p/vfs_addr.c
58077index eb14e05..5156de7 100644
58078--- a/fs/9p/vfs_addr.c
58079+++ b/fs/9p/vfs_addr.c
58080@@ -187,7 +187,7 @@ static int v9fs_vfs_writepage_locked(struct page *page)
58081
58082 retval = v9fs_file_write_internal(inode,
58083 v9inode->writeback_fid,
58084- (__force const char __user *)buffer,
58085+ (const char __force_user *)buffer,
58086 len, &offset, 0);
58087 if (retval > 0)
58088 retval = 0;
58089diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
58090index 296482f..183ddc3 100644
58091--- a/fs/9p/vfs_inode.c
58092+++ b/fs/9p/vfs_inode.c
58093@@ -1312,7 +1312,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
58094 void
58095 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
58096 {
58097- char *s = nd_get_link(nd);
58098+ const char *s = nd_get_link(nd);
58099
58100 p9_debug(P9_DEBUG_VFS, " %pd %s\n",
58101 dentry, IS_ERR(s) ? "<error>" : s);
58102diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
58103index 370b24c..ff0be7b 100644
58104--- a/fs/Kconfig.binfmt
58105+++ b/fs/Kconfig.binfmt
58106@@ -103,7 +103,7 @@ config HAVE_AOUT
58107
58108 config BINFMT_AOUT
58109 tristate "Kernel support for a.out and ECOFF binaries"
58110- depends on HAVE_AOUT
58111+ depends on HAVE_AOUT && BROKEN
58112 ---help---
58113 A.out (Assembler.OUTput) is a set of formats for libraries and
58114 executables used in the earliest versions of UNIX. Linux used
58115diff --git a/fs/afs/inode.c b/fs/afs/inode.c
58116index 2946712..f737435 100644
58117--- a/fs/afs/inode.c
58118+++ b/fs/afs/inode.c
58119@@ -141,7 +141,7 @@ struct inode *afs_iget_autocell(struct inode *dir, const char *dev_name,
58120 struct afs_vnode *vnode;
58121 struct super_block *sb;
58122 struct inode *inode;
58123- static atomic_t afs_autocell_ino;
58124+ static atomic_unchecked_t afs_autocell_ino;
58125
58126 _enter("{%x:%u},%*.*s,",
58127 AFS_FS_I(dir)->fid.vid, AFS_FS_I(dir)->fid.vnode,
58128@@ -154,7 +154,7 @@ struct inode *afs_iget_autocell(struct inode *dir, const char *dev_name,
58129 data.fid.unique = 0;
58130 data.fid.vnode = 0;
58131
58132- inode = iget5_locked(sb, atomic_inc_return(&afs_autocell_ino),
58133+ inode = iget5_locked(sb, atomic_inc_return_unchecked(&afs_autocell_ino),
58134 afs_iget5_autocell_test, afs_iget5_set,
58135 &data);
58136 if (!inode) {
58137diff --git a/fs/aio.c b/fs/aio.c
58138index 14b9315..365980f 100644
58139--- a/fs/aio.c
58140+++ b/fs/aio.c
58141@@ -388,7 +388,7 @@ static int aio_setup_ring(struct kioctx *ctx)
58142 size += sizeof(struct io_event) * nr_events;
58143
58144 nr_pages = PFN_UP(size);
58145- if (nr_pages < 0)
58146+ if (nr_pages <= 0)
58147 return -EINVAL;
58148
58149 file = aio_private_file(ctx, nr_pages);
58150diff --git a/fs/attr.c b/fs/attr.c
58151index 6530ced..4a827e2 100644
58152--- a/fs/attr.c
58153+++ b/fs/attr.c
58154@@ -102,6 +102,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
58155 unsigned long limit;
58156
58157 limit = rlimit(RLIMIT_FSIZE);
58158+ gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
58159 if (limit != RLIM_INFINITY && offset > limit)
58160 goto out_sig;
58161 if (offset > inode->i_sb->s_maxbytes)
58162diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
58163index 116fd38..c04182da 100644
58164--- a/fs/autofs4/waitq.c
58165+++ b/fs/autofs4/waitq.c
58166@@ -59,7 +59,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
58167 {
58168 unsigned long sigpipe, flags;
58169 mm_segment_t fs;
58170- const char *data = (const char *)addr;
58171+ const char __user *data = (const char __force_user *)addr;
58172 ssize_t wr = 0;
58173
58174 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
58175@@ -340,6 +340,10 @@ static int validate_request(struct autofs_wait_queue **wait,
58176 return 1;
58177 }
58178
58179+#ifdef CONFIG_GRKERNSEC_HIDESYM
58180+static atomic_unchecked_t autofs_dummy_name_id = ATOMIC_INIT(0);
58181+#endif
58182+
58183 int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
58184 enum autofs_notify notify)
58185 {
58186@@ -385,7 +389,12 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
58187
58188 /* If this is a direct mount request create a dummy name */
58189 if (IS_ROOT(dentry) && autofs_type_trigger(sbi->type))
58190+#ifdef CONFIG_GRKERNSEC_HIDESYM
58191+ /* this name does get written to userland via autofs4_write() */
58192+ qstr.len = sprintf(name, "%08x", atomic_inc_return_unchecked(&autofs_dummy_name_id));
58193+#else
58194 qstr.len = sprintf(name, "%p", dentry);
58195+#endif
58196 else {
58197 qstr.len = autofs4_getpath(sbi, dentry, &name);
58198 if (!qstr.len) {
58199diff --git a/fs/befs/endian.h b/fs/befs/endian.h
58200index 2722387..56059b5 100644
58201--- a/fs/befs/endian.h
58202+++ b/fs/befs/endian.h
58203@@ -11,7 +11,7 @@
58204
58205 #include <asm/byteorder.h>
58206
58207-static inline u64
58208+static inline u64 __intentional_overflow(-1)
58209 fs64_to_cpu(const struct super_block *sb, fs64 n)
58210 {
58211 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
58212@@ -29,7 +29,7 @@ cpu_to_fs64(const struct super_block *sb, u64 n)
58213 return (__force fs64)cpu_to_be64(n);
58214 }
58215
58216-static inline u32
58217+static inline u32 __intentional_overflow(-1)
58218 fs32_to_cpu(const struct super_block *sb, fs32 n)
58219 {
58220 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
58221@@ -47,7 +47,7 @@ cpu_to_fs32(const struct super_block *sb, u32 n)
58222 return (__force fs32)cpu_to_be32(n);
58223 }
58224
58225-static inline u16
58226+static inline u16 __intentional_overflow(-1)
58227 fs16_to_cpu(const struct super_block *sb, fs16 n)
58228 {
58229 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
58230diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
58231index 929dec0..84bd914 100644
58232--- a/fs/binfmt_aout.c
58233+++ b/fs/binfmt_aout.c
58234@@ -16,6 +16,7 @@
58235 #include <linux/string.h>
58236 #include <linux/fs.h>
58237 #include <linux/file.h>
58238+#include <linux/security.h>
58239 #include <linux/stat.h>
58240 #include <linux/fcntl.h>
58241 #include <linux/ptrace.h>
58242@@ -58,6 +59,8 @@ static int aout_core_dump(struct coredump_params *cprm)
58243 #endif
58244 # define START_STACK(u) ((void __user *)u.start_stack)
58245
58246+ memset(&dump, 0, sizeof(dump));
58247+
58248 fs = get_fs();
58249 set_fs(KERNEL_DS);
58250 has_dumped = 1;
58251@@ -68,10 +71,12 @@ static int aout_core_dump(struct coredump_params *cprm)
58252
58253 /* If the size of the dump file exceeds the rlimit, then see what would happen
58254 if we wrote the stack, but not the data area. */
58255+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
58256 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
58257 dump.u_dsize = 0;
58258
58259 /* Make sure we have enough room to write the stack and data areas. */
58260+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
58261 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
58262 dump.u_ssize = 0;
58263
58264@@ -232,6 +237,8 @@ static int load_aout_binary(struct linux_binprm * bprm)
58265 rlim = rlimit(RLIMIT_DATA);
58266 if (rlim >= RLIM_INFINITY)
58267 rlim = ~0;
58268+
58269+ gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
58270 if (ex.a_data + ex.a_bss > rlim)
58271 return -ENOMEM;
58272
58273@@ -261,6 +268,27 @@ static int load_aout_binary(struct linux_binprm * bprm)
58274
58275 install_exec_creds(bprm);
58276
58277+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
58278+ current->mm->pax_flags = 0UL;
58279+#endif
58280+
58281+#ifdef CONFIG_PAX_PAGEEXEC
58282+ if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
58283+ current->mm->pax_flags |= MF_PAX_PAGEEXEC;
58284+
58285+#ifdef CONFIG_PAX_EMUTRAMP
58286+ if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
58287+ current->mm->pax_flags |= MF_PAX_EMUTRAMP;
58288+#endif
58289+
58290+#ifdef CONFIG_PAX_MPROTECT
58291+ if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
58292+ current->mm->pax_flags |= MF_PAX_MPROTECT;
58293+#endif
58294+
58295+ }
58296+#endif
58297+
58298 if (N_MAGIC(ex) == OMAGIC) {
58299 unsigned long text_addr, map_size;
58300 loff_t pos;
58301@@ -312,7 +340,7 @@ static int load_aout_binary(struct linux_binprm * bprm)
58302 return error;
58303
58304 error = vm_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
58305- PROT_READ | PROT_WRITE | PROT_EXEC,
58306+ PROT_READ | PROT_WRITE,
58307 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
58308 fd_offset + ex.a_text);
58309 if (error != N_DATADDR(ex))
58310diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
58311index d8fc060..cbd44d5 100644
58312--- a/fs/binfmt_elf.c
58313+++ b/fs/binfmt_elf.c
58314@@ -34,6 +34,7 @@
58315 #include <linux/utsname.h>
58316 #include <linux/coredump.h>
58317 #include <linux/sched.h>
58318+#include <linux/xattr.h>
58319 #include <asm/uaccess.h>
58320 #include <asm/param.h>
58321 #include <asm/page.h>
58322@@ -47,7 +48,7 @@
58323
58324 static int load_elf_binary(struct linux_binprm *bprm);
58325 static unsigned long elf_map(struct file *, unsigned long, struct elf_phdr *,
58326- int, int, unsigned long);
58327+ int, int, unsigned long) __intentional_overflow(-1);
58328
58329 #ifdef CONFIG_USELIB
58330 static int load_elf_library(struct file *);
58331@@ -65,6 +66,14 @@ static int elf_core_dump(struct coredump_params *cprm);
58332 #define elf_core_dump NULL
58333 #endif
58334
58335+#ifdef CONFIG_PAX_MPROTECT
58336+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
58337+#endif
58338+
58339+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
58340+static void elf_handle_mmap(struct file *file);
58341+#endif
58342+
58343 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
58344 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
58345 #else
58346@@ -84,6 +93,15 @@ static struct linux_binfmt elf_format = {
58347 .load_binary = load_elf_binary,
58348 .load_shlib = load_elf_library,
58349 .core_dump = elf_core_dump,
58350+
58351+#ifdef CONFIG_PAX_MPROTECT
58352+ .handle_mprotect= elf_handle_mprotect,
58353+#endif
58354+
58355+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
58356+ .handle_mmap = elf_handle_mmap,
58357+#endif
58358+
58359 .min_coredump = ELF_EXEC_PAGESIZE,
58360 };
58361
58362@@ -91,6 +109,8 @@ static struct linux_binfmt elf_format = {
58363
58364 static int set_brk(unsigned long start, unsigned long end)
58365 {
58366+ unsigned long e = end;
58367+
58368 start = ELF_PAGEALIGN(start);
58369 end = ELF_PAGEALIGN(end);
58370 if (end > start) {
58371@@ -99,7 +119,7 @@ static int set_brk(unsigned long start, unsigned long end)
58372 if (BAD_ADDR(addr))
58373 return addr;
58374 }
58375- current->mm->start_brk = current->mm->brk = end;
58376+ current->mm->start_brk = current->mm->brk = e;
58377 return 0;
58378 }
58379
58380@@ -160,12 +180,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
58381 elf_addr_t __user *u_rand_bytes;
58382 const char *k_platform = ELF_PLATFORM;
58383 const char *k_base_platform = ELF_BASE_PLATFORM;
58384- unsigned char k_rand_bytes[16];
58385+ u32 k_rand_bytes[4];
58386 int items;
58387 elf_addr_t *elf_info;
58388 int ei_index = 0;
58389 const struct cred *cred = current_cred();
58390 struct vm_area_struct *vma;
58391+ unsigned long saved_auxv[AT_VECTOR_SIZE];
58392
58393 /*
58394 * In some cases (e.g. Hyper-Threading), we want to avoid L1
58395@@ -207,8 +228,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
58396 * Generate 16 random bytes for userspace PRNG seeding.
58397 */
58398 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
58399- u_rand_bytes = (elf_addr_t __user *)
58400- STACK_ALLOC(p, sizeof(k_rand_bytes));
58401+ prandom_seed(k_rand_bytes[0] ^ prandom_u32());
58402+ prandom_seed(k_rand_bytes[1] ^ prandom_u32());
58403+ prandom_seed(k_rand_bytes[2] ^ prandom_u32());
58404+ prandom_seed(k_rand_bytes[3] ^ prandom_u32());
58405+ p = STACK_ROUND(p, sizeof(k_rand_bytes));
58406+ u_rand_bytes = (elf_addr_t __user *) p;
58407 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
58408 return -EFAULT;
58409
58410@@ -323,9 +348,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
58411 return -EFAULT;
58412 current->mm->env_end = p;
58413
58414+ memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
58415+
58416 /* Put the elf_info on the stack in the right place. */
58417 sp = (elf_addr_t __user *)envp + 1;
58418- if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
58419+ if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
58420 return -EFAULT;
58421 return 0;
58422 }
58423@@ -393,15 +420,14 @@ static unsigned long total_mapping_size(struct elf_phdr *cmds, int nr)
58424 an ELF header */
58425
58426 static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
58427- struct file *interpreter, unsigned long *interp_map_addr,
58428- unsigned long no_base)
58429+ struct file *interpreter, unsigned long no_base)
58430 {
58431 struct elf_phdr *elf_phdata;
58432 struct elf_phdr *eppnt;
58433- unsigned long load_addr = 0;
58434+ unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
58435 int load_addr_set = 0;
58436 unsigned long last_bss = 0, elf_bss = 0;
58437- unsigned long error = ~0UL;
58438+ unsigned long error = -EINVAL;
58439 unsigned long total_size;
58440 int retval, i, size;
58441
58442@@ -447,6 +473,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
58443 goto out_close;
58444 }
58445
58446+#ifdef CONFIG_PAX_SEGMEXEC
58447+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
58448+ pax_task_size = SEGMEXEC_TASK_SIZE;
58449+#endif
58450+
58451 eppnt = elf_phdata;
58452 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
58453 if (eppnt->p_type == PT_LOAD) {
58454@@ -470,8 +501,6 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
58455 map_addr = elf_map(interpreter, load_addr + vaddr,
58456 eppnt, elf_prot, elf_type, total_size);
58457 total_size = 0;
58458- if (!*interp_map_addr)
58459- *interp_map_addr = map_addr;
58460 error = map_addr;
58461 if (BAD_ADDR(map_addr))
58462 goto out_close;
58463@@ -490,8 +519,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
58464 k = load_addr + eppnt->p_vaddr;
58465 if (BAD_ADDR(k) ||
58466 eppnt->p_filesz > eppnt->p_memsz ||
58467- eppnt->p_memsz > TASK_SIZE ||
58468- TASK_SIZE - eppnt->p_memsz < k) {
58469+ eppnt->p_memsz > pax_task_size ||
58470+ pax_task_size - eppnt->p_memsz < k) {
58471 error = -ENOMEM;
58472 goto out_close;
58473 }
58474@@ -530,9 +559,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
58475 elf_bss = ELF_PAGESTART(elf_bss + ELF_MIN_ALIGN - 1);
58476
58477 /* Map the last of the bss segment */
58478- error = vm_brk(elf_bss, last_bss - elf_bss);
58479- if (BAD_ADDR(error))
58480- goto out_close;
58481+ if (last_bss > elf_bss) {
58482+ error = vm_brk(elf_bss, last_bss - elf_bss);
58483+ if (BAD_ADDR(error))
58484+ goto out_close;
58485+ }
58486 }
58487
58488 error = load_addr;
58489@@ -543,6 +574,336 @@ out:
58490 return error;
58491 }
58492
58493+#ifdef CONFIG_PAX_PT_PAX_FLAGS
58494+#ifdef CONFIG_PAX_SOFTMODE
58495+static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
58496+{
58497+ unsigned long pax_flags = 0UL;
58498+
58499+#ifdef CONFIG_PAX_PAGEEXEC
58500+ if (elf_phdata->p_flags & PF_PAGEEXEC)
58501+ pax_flags |= MF_PAX_PAGEEXEC;
58502+#endif
58503+
58504+#ifdef CONFIG_PAX_SEGMEXEC
58505+ if (elf_phdata->p_flags & PF_SEGMEXEC)
58506+ pax_flags |= MF_PAX_SEGMEXEC;
58507+#endif
58508+
58509+#ifdef CONFIG_PAX_EMUTRAMP
58510+ if ((elf_phdata->p_flags & PF_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
58511+ pax_flags |= MF_PAX_EMUTRAMP;
58512+#endif
58513+
58514+#ifdef CONFIG_PAX_MPROTECT
58515+ if (elf_phdata->p_flags & PF_MPROTECT)
58516+ pax_flags |= MF_PAX_MPROTECT;
58517+#endif
58518+
58519+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
58520+ if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
58521+ pax_flags |= MF_PAX_RANDMMAP;
58522+#endif
58523+
58524+ return pax_flags;
58525+}
58526+#endif
58527+
58528+static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
58529+{
58530+ unsigned long pax_flags = 0UL;
58531+
58532+#ifdef CONFIG_PAX_PAGEEXEC
58533+ if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
58534+ pax_flags |= MF_PAX_PAGEEXEC;
58535+#endif
58536+
58537+#ifdef CONFIG_PAX_SEGMEXEC
58538+ if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
58539+ pax_flags |= MF_PAX_SEGMEXEC;
58540+#endif
58541+
58542+#ifdef CONFIG_PAX_EMUTRAMP
58543+ if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
58544+ pax_flags |= MF_PAX_EMUTRAMP;
58545+#endif
58546+
58547+#ifdef CONFIG_PAX_MPROTECT
58548+ if (!(elf_phdata->p_flags & PF_NOMPROTECT))
58549+ pax_flags |= MF_PAX_MPROTECT;
58550+#endif
58551+
58552+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
58553+ if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
58554+ pax_flags |= MF_PAX_RANDMMAP;
58555+#endif
58556+
58557+ return pax_flags;
58558+}
58559+#endif
58560+
58561+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
58562+#ifdef CONFIG_PAX_SOFTMODE
58563+static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
58564+{
58565+ unsigned long pax_flags = 0UL;
58566+
58567+#ifdef CONFIG_PAX_PAGEEXEC
58568+ if (pax_flags_softmode & MF_PAX_PAGEEXEC)
58569+ pax_flags |= MF_PAX_PAGEEXEC;
58570+#endif
58571+
58572+#ifdef CONFIG_PAX_SEGMEXEC
58573+ if (pax_flags_softmode & MF_PAX_SEGMEXEC)
58574+ pax_flags |= MF_PAX_SEGMEXEC;
58575+#endif
58576+
58577+#ifdef CONFIG_PAX_EMUTRAMP
58578+ if ((pax_flags_softmode & MF_PAX_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
58579+ pax_flags |= MF_PAX_EMUTRAMP;
58580+#endif
58581+
58582+#ifdef CONFIG_PAX_MPROTECT
58583+ if (pax_flags_softmode & MF_PAX_MPROTECT)
58584+ pax_flags |= MF_PAX_MPROTECT;
58585+#endif
58586+
58587+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
58588+ if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
58589+ pax_flags |= MF_PAX_RANDMMAP;
58590+#endif
58591+
58592+ return pax_flags;
58593+}
58594+#endif
58595+
58596+static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
58597+{
58598+ unsigned long pax_flags = 0UL;
58599+
58600+#ifdef CONFIG_PAX_PAGEEXEC
58601+ if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
58602+ pax_flags |= MF_PAX_PAGEEXEC;
58603+#endif
58604+
58605+#ifdef CONFIG_PAX_SEGMEXEC
58606+ if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
58607+ pax_flags |= MF_PAX_SEGMEXEC;
58608+#endif
58609+
58610+#ifdef CONFIG_PAX_EMUTRAMP
58611+ if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
58612+ pax_flags |= MF_PAX_EMUTRAMP;
58613+#endif
58614+
58615+#ifdef CONFIG_PAX_MPROTECT
58616+ if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
58617+ pax_flags |= MF_PAX_MPROTECT;
58618+#endif
58619+
58620+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
58621+ if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
58622+ pax_flags |= MF_PAX_RANDMMAP;
58623+#endif
58624+
58625+ return pax_flags;
58626+}
58627+#endif
58628+
58629+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
58630+static unsigned long pax_parse_defaults(void)
58631+{
58632+ unsigned long pax_flags = 0UL;
58633+
58634+#ifdef CONFIG_PAX_SOFTMODE
58635+ if (pax_softmode)
58636+ return pax_flags;
58637+#endif
58638+
58639+#ifdef CONFIG_PAX_PAGEEXEC
58640+ pax_flags |= MF_PAX_PAGEEXEC;
58641+#endif
58642+
58643+#ifdef CONFIG_PAX_SEGMEXEC
58644+ pax_flags |= MF_PAX_SEGMEXEC;
58645+#endif
58646+
58647+#ifdef CONFIG_PAX_MPROTECT
58648+ pax_flags |= MF_PAX_MPROTECT;
58649+#endif
58650+
58651+#ifdef CONFIG_PAX_RANDMMAP
58652+ if (randomize_va_space)
58653+ pax_flags |= MF_PAX_RANDMMAP;
58654+#endif
58655+
58656+ return pax_flags;
58657+}
58658+
58659+static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
58660+{
58661+ unsigned long pax_flags = PAX_PARSE_FLAGS_FALLBACK;
58662+
58663+#ifdef CONFIG_PAX_EI_PAX
58664+
58665+#ifdef CONFIG_PAX_SOFTMODE
58666+ if (pax_softmode)
58667+ return pax_flags;
58668+#endif
58669+
58670+ pax_flags = 0UL;
58671+
58672+#ifdef CONFIG_PAX_PAGEEXEC
58673+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
58674+ pax_flags |= MF_PAX_PAGEEXEC;
58675+#endif
58676+
58677+#ifdef CONFIG_PAX_SEGMEXEC
58678+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
58679+ pax_flags |= MF_PAX_SEGMEXEC;
58680+#endif
58681+
58682+#ifdef CONFIG_PAX_EMUTRAMP
58683+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
58684+ pax_flags |= MF_PAX_EMUTRAMP;
58685+#endif
58686+
58687+#ifdef CONFIG_PAX_MPROTECT
58688+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
58689+ pax_flags |= MF_PAX_MPROTECT;
58690+#endif
58691+
58692+#ifdef CONFIG_PAX_ASLR
58693+ if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
58694+ pax_flags |= MF_PAX_RANDMMAP;
58695+#endif
58696+
58697+#endif
58698+
58699+ return pax_flags;
58700+
58701+}
58702+
58703+static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
58704+{
58705+
58706+#ifdef CONFIG_PAX_PT_PAX_FLAGS
58707+ unsigned long i;
58708+
58709+ for (i = 0UL; i < elf_ex->e_phnum; i++)
58710+ if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
58711+ if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
58712+ ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
58713+ ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
58714+ ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
58715+ ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
58716+ return PAX_PARSE_FLAGS_FALLBACK;
58717+
58718+#ifdef CONFIG_PAX_SOFTMODE
58719+ if (pax_softmode)
58720+ return pax_parse_pt_pax_softmode(&elf_phdata[i]);
58721+ else
58722+#endif
58723+
58724+ return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
58725+ break;
58726+ }
58727+#endif
58728+
58729+ return PAX_PARSE_FLAGS_FALLBACK;
58730+}
58731+
58732+static unsigned long pax_parse_xattr_pax(struct file * const file)
58733+{
58734+
58735+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
58736+ ssize_t xattr_size, i;
58737+ unsigned char xattr_value[sizeof("pemrs") - 1];
58738+ unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
58739+
58740+ xattr_size = pax_getxattr(file->f_path.dentry, xattr_value, sizeof xattr_value);
58741+ if (xattr_size < 0 || xattr_size > sizeof xattr_value)
58742+ return PAX_PARSE_FLAGS_FALLBACK;
58743+
58744+ for (i = 0; i < xattr_size; i++)
58745+ switch (xattr_value[i]) {
58746+ default:
58747+ return PAX_PARSE_FLAGS_FALLBACK;
58748+
58749+#define parse_flag(option1, option2, flag) \
58750+ case option1: \
58751+ if (pax_flags_hardmode & MF_PAX_##flag) \
58752+ return PAX_PARSE_FLAGS_FALLBACK;\
58753+ pax_flags_hardmode |= MF_PAX_##flag; \
58754+ break; \
58755+ case option2: \
58756+ if (pax_flags_softmode & MF_PAX_##flag) \
58757+ return PAX_PARSE_FLAGS_FALLBACK;\
58758+ pax_flags_softmode |= MF_PAX_##flag; \
58759+ break;
58760+
58761+ parse_flag('p', 'P', PAGEEXEC);
58762+ parse_flag('e', 'E', EMUTRAMP);
58763+ parse_flag('m', 'M', MPROTECT);
58764+ parse_flag('r', 'R', RANDMMAP);
58765+ parse_flag('s', 'S', SEGMEXEC);
58766+
58767+#undef parse_flag
58768+ }
58769+
58770+ if (pax_flags_hardmode & pax_flags_softmode)
58771+ return PAX_PARSE_FLAGS_FALLBACK;
58772+
58773+#ifdef CONFIG_PAX_SOFTMODE
58774+ if (pax_softmode)
58775+ return pax_parse_xattr_pax_softmode(pax_flags_softmode);
58776+ else
58777+#endif
58778+
58779+ return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
58780+#else
58781+ return PAX_PARSE_FLAGS_FALLBACK;
58782+#endif
58783+
58784+}
58785+
58786+static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
58787+{
58788+ unsigned long pax_flags, ei_pax_flags, pt_pax_flags, xattr_pax_flags;
58789+
58790+ pax_flags = pax_parse_defaults();
58791+ ei_pax_flags = pax_parse_ei_pax(elf_ex);
58792+ pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
58793+ xattr_pax_flags = pax_parse_xattr_pax(file);
58794+
58795+ if (pt_pax_flags != PAX_PARSE_FLAGS_FALLBACK &&
58796+ xattr_pax_flags != PAX_PARSE_FLAGS_FALLBACK &&
58797+ pt_pax_flags != xattr_pax_flags)
58798+ return -EINVAL;
58799+ if (xattr_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
58800+ pax_flags = xattr_pax_flags;
58801+ else if (pt_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
58802+ pax_flags = pt_pax_flags;
58803+ else if (ei_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
58804+ pax_flags = ei_pax_flags;
58805+
58806+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
58807+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
58808+ if ((__supported_pte_mask & _PAGE_NX))
58809+ pax_flags &= ~MF_PAX_SEGMEXEC;
58810+ else
58811+ pax_flags &= ~MF_PAX_PAGEEXEC;
58812+ }
58813+#endif
58814+
58815+ if (0 > pax_check_flags(&pax_flags))
58816+ return -EINVAL;
58817+
58818+ current->mm->pax_flags = pax_flags;
58819+ return 0;
58820+}
58821+#endif
58822+
58823 /*
58824 * These are the functions used to load ELF style executables and shared
58825 * libraries. There is no binary dependent code anywhere else.
58826@@ -556,6 +917,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
58827 {
58828 unsigned int random_variable = 0;
58829
58830+#ifdef CONFIG_PAX_RANDUSTACK
58831+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
58832+ return stack_top - current->mm->delta_stack;
58833+#endif
58834+
58835 if ((current->flags & PF_RANDOMIZE) &&
58836 !(current->personality & ADDR_NO_RANDOMIZE)) {
58837 random_variable = get_random_int() & STACK_RND_MASK;
58838@@ -574,7 +940,7 @@ static int load_elf_binary(struct linux_binprm *bprm)
58839 unsigned long load_addr = 0, load_bias = 0;
58840 int load_addr_set = 0;
58841 char * elf_interpreter = NULL;
58842- unsigned long error;
58843+ unsigned long error = 0;
58844 struct elf_phdr *elf_ppnt, *elf_phdata;
58845 unsigned long elf_bss, elf_brk;
58846 int retval, i;
58847@@ -589,6 +955,7 @@ static int load_elf_binary(struct linux_binprm *bprm)
58848 struct elfhdr elf_ex;
58849 struct elfhdr interp_elf_ex;
58850 } *loc;
58851+ unsigned long pax_task_size;
58852
58853 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
58854 if (!loc) {
58855@@ -726,6 +1093,77 @@ static int load_elf_binary(struct linux_binprm *bprm)
58856 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
58857 may depend on the personality. */
58858 SET_PERSONALITY(loc->elf_ex);
58859+
58860+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
58861+ current->mm->pax_flags = 0UL;
58862+#endif
58863+
58864+#ifdef CONFIG_PAX_DLRESOLVE
58865+ current->mm->call_dl_resolve = 0UL;
58866+#endif
58867+
58868+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
58869+ current->mm->call_syscall = 0UL;
58870+#endif
58871+
58872+#ifdef CONFIG_PAX_ASLR
58873+ current->mm->delta_mmap = 0UL;
58874+ current->mm->delta_stack = 0UL;
58875+#endif
58876+
58877+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
58878+ if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
58879+ send_sig(SIGKILL, current, 0);
58880+ goto out_free_dentry;
58881+ }
58882+#endif
58883+
58884+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
58885+ pax_set_initial_flags(bprm);
58886+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
58887+ if (pax_set_initial_flags_func)
58888+ (pax_set_initial_flags_func)(bprm);
58889+#endif
58890+
58891+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
58892+ if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
58893+ current->mm->context.user_cs_limit = PAGE_SIZE;
58894+ current->mm->def_flags |= VM_PAGEEXEC | VM_NOHUGEPAGE;
58895+ }
58896+#endif
58897+
58898+#ifdef CONFIG_PAX_SEGMEXEC
58899+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
58900+ current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
58901+ current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
58902+ pax_task_size = SEGMEXEC_TASK_SIZE;
58903+ current->mm->def_flags |= VM_NOHUGEPAGE;
58904+ } else
58905+#endif
58906+
58907+ pax_task_size = TASK_SIZE;
58908+
58909+#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
58910+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
58911+ set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
58912+ put_cpu();
58913+ }
58914+#endif
58915+
58916+#ifdef CONFIG_PAX_ASLR
58917+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
58918+ current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
58919+ current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
58920+ }
58921+#endif
58922+
58923+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
58924+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
58925+ executable_stack = EXSTACK_DISABLE_X;
58926+ current->personality &= ~READ_IMPLIES_EXEC;
58927+ } else
58928+#endif
58929+
58930 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
58931 current->personality |= READ_IMPLIES_EXEC;
58932
58933@@ -811,6 +1249,20 @@ static int load_elf_binary(struct linux_binprm *bprm)
58934 #else
58935 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
58936 #endif
58937+
58938+#ifdef CONFIG_PAX_RANDMMAP
58939+ /* PaX: randomize base address at the default exe base if requested */
58940+ if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
58941+#ifdef CONFIG_SPARC64
58942+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
58943+#else
58944+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
58945+#endif
58946+ load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
58947+ elf_flags |= MAP_FIXED;
58948+ }
58949+#endif
58950+
58951 }
58952
58953 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
58954@@ -842,9 +1294,9 @@ static int load_elf_binary(struct linux_binprm *bprm)
58955 * allowed task size. Note that p_filesz must always be
58956 * <= p_memsz so it is only necessary to check p_memsz.
58957 */
58958- if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
58959- elf_ppnt->p_memsz > TASK_SIZE ||
58960- TASK_SIZE - elf_ppnt->p_memsz < k) {
58961+ if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
58962+ elf_ppnt->p_memsz > pax_task_size ||
58963+ pax_task_size - elf_ppnt->p_memsz < k) {
58964 /* set_brk can never work. Avoid overflows. */
58965 retval = -EINVAL;
58966 goto out_free_dentry;
58967@@ -880,16 +1332,43 @@ static int load_elf_binary(struct linux_binprm *bprm)
58968 if (retval)
58969 goto out_free_dentry;
58970 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
58971- retval = -EFAULT; /* Nobody gets to see this, but.. */
58972- goto out_free_dentry;
58973+ /*
58974+ * This bss-zeroing can fail if the ELF
58975+ * file specifies odd protections. So
58976+ * we don't check the return value
58977+ */
58978 }
58979
58980+#ifdef CONFIG_PAX_RANDMMAP
58981+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
58982+ unsigned long start, size, flags;
58983+ vm_flags_t vm_flags;
58984+
58985+ start = ELF_PAGEALIGN(elf_brk);
58986+ size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
58987+ flags = MAP_FIXED | MAP_PRIVATE;
58988+ vm_flags = VM_DONTEXPAND | VM_DONTDUMP;
58989+
58990+ down_write(&current->mm->mmap_sem);
58991+ start = get_unmapped_area(NULL, start, PAGE_ALIGN(size), 0, flags);
58992+ retval = -ENOMEM;
58993+ if (!IS_ERR_VALUE(start) && !find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
58994+// if (current->personality & ADDR_NO_RANDOMIZE)
58995+// vm_flags |= VM_READ | VM_MAYREAD;
58996+ start = mmap_region(NULL, start, PAGE_ALIGN(size), vm_flags, 0);
58997+ retval = IS_ERR_VALUE(start) ? start : 0;
58998+ }
58999+ up_write(&current->mm->mmap_sem);
59000+ if (retval == 0)
59001+ retval = set_brk(start + size, start + size + PAGE_SIZE);
59002+ if (retval < 0)
59003+ goto out_free_dentry;
59004+ }
59005+#endif
59006+
59007 if (elf_interpreter) {
59008- unsigned long interp_map_addr = 0;
59009-
59010 elf_entry = load_elf_interp(&loc->interp_elf_ex,
59011 interpreter,
59012- &interp_map_addr,
59013 load_bias);
59014 if (!IS_ERR((void *)elf_entry)) {
59015 /*
59016@@ -1115,7 +1594,7 @@ static bool always_dump_vma(struct vm_area_struct *vma)
59017 * Decide what to dump of a segment, part, all or none.
59018 */
59019 static unsigned long vma_dump_size(struct vm_area_struct *vma,
59020- unsigned long mm_flags)
59021+ unsigned long mm_flags, long signr)
59022 {
59023 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
59024
59025@@ -1153,7 +1632,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
59026 if (vma->vm_file == NULL)
59027 return 0;
59028
59029- if (FILTER(MAPPED_PRIVATE))
59030+ if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
59031 goto whole;
59032
59033 /*
59034@@ -1360,9 +1839,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
59035 {
59036 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
59037 int i = 0;
59038- do
59039+ do {
59040 i += 2;
59041- while (auxv[i - 2] != AT_NULL);
59042+ } while (auxv[i - 2] != AT_NULL);
59043 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
59044 }
59045
59046@@ -1371,7 +1850,7 @@ static void fill_siginfo_note(struct memelfnote *note, user_siginfo_t *csigdata,
59047 {
59048 mm_segment_t old_fs = get_fs();
59049 set_fs(KERNEL_DS);
59050- copy_siginfo_to_user((user_siginfo_t __user *) csigdata, siginfo);
59051+ copy_siginfo_to_user((user_siginfo_t __force_user *) csigdata, siginfo);
59052 set_fs(old_fs);
59053 fill_note(note, "CORE", NT_SIGINFO, sizeof(*csigdata), csigdata);
59054 }
59055@@ -1995,14 +2474,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
59056 }
59057
59058 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
59059- unsigned long mm_flags)
59060+ struct coredump_params *cprm)
59061 {
59062 struct vm_area_struct *vma;
59063 size_t size = 0;
59064
59065 for (vma = first_vma(current, gate_vma); vma != NULL;
59066 vma = next_vma(vma, gate_vma))
59067- size += vma_dump_size(vma, mm_flags);
59068+ size += vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
59069 return size;
59070 }
59071
59072@@ -2093,7 +2572,7 @@ static int elf_core_dump(struct coredump_params *cprm)
59073
59074 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
59075
59076- offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
59077+ offset += elf_core_vma_data_size(gate_vma, cprm);
59078 offset += elf_core_extra_data_size();
59079 e_shoff = offset;
59080
59081@@ -2121,7 +2600,7 @@ static int elf_core_dump(struct coredump_params *cprm)
59082 phdr.p_offset = offset;
59083 phdr.p_vaddr = vma->vm_start;
59084 phdr.p_paddr = 0;
59085- phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
59086+ phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
59087 phdr.p_memsz = vma->vm_end - vma->vm_start;
59088 offset += phdr.p_filesz;
59089 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
59090@@ -2154,7 +2633,7 @@ static int elf_core_dump(struct coredump_params *cprm)
59091 unsigned long addr;
59092 unsigned long end;
59093
59094- end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
59095+ end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
59096
59097 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
59098 struct page *page;
59099@@ -2195,6 +2674,167 @@ out:
59100
59101 #endif /* CONFIG_ELF_CORE */
59102
59103+#ifdef CONFIG_PAX_MPROTECT
59104+/* PaX: non-PIC ELF libraries need relocations on their executable segments
59105+ * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
59106+ * we'll remove VM_MAYWRITE for good on RELRO segments.
59107+ *
59108+ * The checks favour ld-linux.so behaviour which operates on a per ELF segment
59109+ * basis because we want to allow the common case and not the special ones.
59110+ */
59111+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
59112+{
59113+ struct elfhdr elf_h;
59114+ struct elf_phdr elf_p;
59115+ unsigned long i;
59116+ unsigned long oldflags;
59117+ bool is_textrel_rw, is_textrel_rx, is_relro;
59118+
59119+ if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT) || !vma->vm_file)
59120+ return;
59121+
59122+ oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
59123+ newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
59124+
59125+#ifdef CONFIG_PAX_ELFRELOCS
59126+ /* possible TEXTREL */
59127+ is_textrel_rw = !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
59128+ is_textrel_rx = vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_WRITE | VM_READ) && newflags == (VM_EXEC | VM_READ);
59129+#else
59130+ is_textrel_rw = false;
59131+ is_textrel_rx = false;
59132+#endif
59133+
59134+ /* possible RELRO */
59135+ is_relro = vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
59136+
59137+ if (!is_textrel_rw && !is_textrel_rx && !is_relro)
59138+ return;
59139+
59140+ if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
59141+ memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
59142+
59143+#ifdef CONFIG_PAX_ETEXECRELOCS
59144+ ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
59145+#else
59146+ ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
59147+#endif
59148+
59149+ (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
59150+ !elf_check_arch(&elf_h) ||
59151+ elf_h.e_phentsize != sizeof(struct elf_phdr) ||
59152+ elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
59153+ return;
59154+
59155+ for (i = 0UL; i < elf_h.e_phnum; i++) {
59156+ if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
59157+ return;
59158+ switch (elf_p.p_type) {
59159+ case PT_DYNAMIC:
59160+ if (!is_textrel_rw && !is_textrel_rx)
59161+ continue;
59162+ i = 0UL;
59163+ while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
59164+ elf_dyn dyn;
59165+
59166+ if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
59167+ break;
59168+ if (dyn.d_tag == DT_NULL)
59169+ break;
59170+ if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
59171+ gr_log_textrel(vma);
59172+ if (is_textrel_rw)
59173+ vma->vm_flags |= VM_MAYWRITE;
59174+ else
59175+ /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
59176+ vma->vm_flags &= ~VM_MAYWRITE;
59177+ break;
59178+ }
59179+ i++;
59180+ }
59181+ is_textrel_rw = false;
59182+ is_textrel_rx = false;
59183+ continue;
59184+
59185+ case PT_GNU_RELRO:
59186+ if (!is_relro)
59187+ continue;
59188+ if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
59189+ vma->vm_flags &= ~VM_MAYWRITE;
59190+ is_relro = false;
59191+ continue;
59192+
59193+#ifdef CONFIG_PAX_PT_PAX_FLAGS
59194+ case PT_PAX_FLAGS: {
59195+ const char *msg_mprotect = "", *msg_emutramp = "";
59196+ char *buffer_lib, *buffer_exe;
59197+
59198+ if (elf_p.p_flags & PF_NOMPROTECT)
59199+ msg_mprotect = "MPROTECT disabled";
59200+
59201+#ifdef CONFIG_PAX_EMUTRAMP
59202+ if (!(vma->vm_mm->pax_flags & MF_PAX_EMUTRAMP) && !(elf_p.p_flags & PF_NOEMUTRAMP))
59203+ msg_emutramp = "EMUTRAMP enabled";
59204+#endif
59205+
59206+ if (!msg_mprotect[0] && !msg_emutramp[0])
59207+ continue;
59208+
59209+ if (!printk_ratelimit())
59210+ continue;
59211+
59212+ buffer_lib = (char *)__get_free_page(GFP_KERNEL);
59213+ buffer_exe = (char *)__get_free_page(GFP_KERNEL);
59214+ if (buffer_lib && buffer_exe) {
59215+ char *path_lib, *path_exe;
59216+
59217+ path_lib = pax_get_path(&vma->vm_file->f_path, buffer_lib, PAGE_SIZE);
59218+ path_exe = pax_get_path(&vma->vm_mm->exe_file->f_path, buffer_exe, PAGE_SIZE);
59219+
59220+ pr_info("PAX: %s wants %s%s%s on %s\n", path_lib, msg_mprotect,
59221+ (msg_mprotect[0] && msg_emutramp[0] ? " and " : ""), msg_emutramp, path_exe);
59222+
59223+ }
59224+ free_page((unsigned long)buffer_exe);
59225+ free_page((unsigned long)buffer_lib);
59226+ continue;
59227+ }
59228+#endif
59229+
59230+ }
59231+ }
59232+}
59233+#endif
59234+
59235+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
59236+
59237+extern int grsec_enable_log_rwxmaps;
59238+
59239+static void elf_handle_mmap(struct file *file)
59240+{
59241+ struct elfhdr elf_h;
59242+ struct elf_phdr elf_p;
59243+ unsigned long i;
59244+
59245+ if (!grsec_enable_log_rwxmaps)
59246+ return;
59247+
59248+ if (sizeof(elf_h) != kernel_read(file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
59249+ memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
59250+ (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC) || !elf_check_arch(&elf_h) ||
59251+ elf_h.e_phentsize != sizeof(struct elf_phdr) ||
59252+ elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
59253+ return;
59254+
59255+ for (i = 0UL; i < elf_h.e_phnum; i++) {
59256+ if (sizeof(elf_p) != kernel_read(file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
59257+ return;
59258+ if (elf_p.p_type == PT_GNU_STACK && (elf_p.p_flags & PF_X))
59259+ gr_log_ptgnustack(file);
59260+ }
59261+}
59262+#endif
59263+
59264 static int __init init_elf_binfmt(void)
59265 {
59266 register_binfmt(&elf_format);
59267diff --git a/fs/block_dev.c b/fs/block_dev.c
59268index 1d9c9f3..2905786 100644
59269--- a/fs/block_dev.c
59270+++ b/fs/block_dev.c
59271@@ -697,7 +697,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
59272 else if (bdev->bd_contains == bdev)
59273 return true; /* is a whole device which isn't held */
59274
59275- else if (whole->bd_holder == bd_may_claim)
59276+ else if (whole->bd_holder == (void *)bd_may_claim)
59277 return true; /* is a partition of a device that is being partitioned */
59278 else if (whole->bd_holder != NULL)
59279 return false; /* is a partition of a held device */
59280diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
59281index 150822e..75bb326 100644
59282--- a/fs/btrfs/ctree.c
59283+++ b/fs/btrfs/ctree.c
59284@@ -1173,9 +1173,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
59285 free_extent_buffer(buf);
59286 add_root_to_dirty_list(root);
59287 } else {
59288- if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
59289- parent_start = parent->start;
59290- else
59291+ if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
59292+ if (parent)
59293+ parent_start = parent->start;
59294+ else
59295+ parent_start = 0;
59296+ } else
59297 parent_start = 0;
59298
59299 WARN_ON(trans->transid != btrfs_header_generation(parent));
59300diff --git a/fs/btrfs/delayed-inode.c b/fs/btrfs/delayed-inode.c
59301index de4e70f..b41dc45 100644
59302--- a/fs/btrfs/delayed-inode.c
59303+++ b/fs/btrfs/delayed-inode.c
59304@@ -462,7 +462,7 @@ static int __btrfs_add_delayed_deletion_item(struct btrfs_delayed_node *node,
59305
59306 static void finish_one_item(struct btrfs_delayed_root *delayed_root)
59307 {
59308- int seq = atomic_inc_return(&delayed_root->items_seq);
59309+ int seq = atomic_inc_return_unchecked(&delayed_root->items_seq);
59310 if ((atomic_dec_return(&delayed_root->items) <
59311 BTRFS_DELAYED_BACKGROUND || seq % BTRFS_DELAYED_BATCH == 0) &&
59312 waitqueue_active(&delayed_root->wait))
59313@@ -1412,7 +1412,7 @@ void btrfs_assert_delayed_root_empty(struct btrfs_root *root)
59314
59315 static int could_end_wait(struct btrfs_delayed_root *delayed_root, int seq)
59316 {
59317- int val = atomic_read(&delayed_root->items_seq);
59318+ int val = atomic_read_unchecked(&delayed_root->items_seq);
59319
59320 if (val < seq || val >= seq + BTRFS_DELAYED_BATCH)
59321 return 1;
59322@@ -1436,7 +1436,7 @@ void btrfs_balance_delayed_items(struct btrfs_root *root)
59323 int seq;
59324 int ret;
59325
59326- seq = atomic_read(&delayed_root->items_seq);
59327+ seq = atomic_read_unchecked(&delayed_root->items_seq);
59328
59329 ret = btrfs_wq_run_delayed_node(delayed_root, root, 0);
59330 if (ret)
59331diff --git a/fs/btrfs/delayed-inode.h b/fs/btrfs/delayed-inode.h
59332index f70119f..ab5894d 100644
59333--- a/fs/btrfs/delayed-inode.h
59334+++ b/fs/btrfs/delayed-inode.h
59335@@ -43,7 +43,7 @@ struct btrfs_delayed_root {
59336 */
59337 struct list_head prepare_list;
59338 atomic_t items; /* for delayed items */
59339- atomic_t items_seq; /* for delayed items */
59340+ atomic_unchecked_t items_seq; /* for delayed items */
59341 int nodes; /* for delayed nodes */
59342 wait_queue_head_t wait;
59343 };
59344@@ -90,7 +90,7 @@ static inline void btrfs_init_delayed_root(
59345 struct btrfs_delayed_root *delayed_root)
59346 {
59347 atomic_set(&delayed_root->items, 0);
59348- atomic_set(&delayed_root->items_seq, 0);
59349+ atomic_set_unchecked(&delayed_root->items_seq, 0);
59350 delayed_root->nodes = 0;
59351 spin_lock_init(&delayed_root->lock);
59352 init_waitqueue_head(&delayed_root->wait);
59353diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
59354index 4399f0c..a34d8b4 100644
59355--- a/fs/btrfs/ioctl.c
59356+++ b/fs/btrfs/ioctl.c
59357@@ -3953,9 +3953,12 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
59358 for (i = 0; i < num_types; i++) {
59359 struct btrfs_space_info *tmp;
59360
59361+ /* Don't copy in more than we allocated */
59362 if (!slot_count)
59363 break;
59364
59365+ slot_count--;
59366+
59367 info = NULL;
59368 rcu_read_lock();
59369 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
59370@@ -3977,10 +3980,7 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
59371 memcpy(dest, &space, sizeof(space));
59372 dest++;
59373 space_args.total_spaces++;
59374- slot_count--;
59375 }
59376- if (!slot_count)
59377- break;
59378 }
59379 up_read(&info->groups_sem);
59380 }
59381diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
59382index cde9c03..ad4d4db 100644
59383--- a/fs/btrfs/super.c
59384+++ b/fs/btrfs/super.c
59385@@ -271,7 +271,7 @@ void __btrfs_abort_transaction(struct btrfs_trans_handle *trans,
59386 function, line, errstr);
59387 return;
59388 }
59389- ACCESS_ONCE(trans->transaction->aborted) = errno;
59390+ ACCESS_ONCE_RW(trans->transaction->aborted) = errno;
59391 /* Wake up anybody who may be waiting on this transaction */
59392 wake_up(&root->fs_info->transaction_wait);
59393 wake_up(&root->fs_info->transaction_blocked_wait);
59394diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
59395index b2e7bb4..3719201 100644
59396--- a/fs/btrfs/sysfs.c
59397+++ b/fs/btrfs/sysfs.c
59398@@ -480,7 +480,7 @@ static int addrm_unknown_feature_attrs(struct btrfs_fs_info *fs_info, bool add)
59399 for (set = 0; set < FEAT_MAX; set++) {
59400 int i;
59401 struct attribute *attrs[2];
59402- struct attribute_group agroup = {
59403+ attribute_group_no_const agroup = {
59404 .name = "features",
59405 .attrs = attrs,
59406 };
59407diff --git a/fs/btrfs/tests/free-space-tests.c b/fs/btrfs/tests/free-space-tests.c
59408index 2299bfd..4098e72 100644
59409--- a/fs/btrfs/tests/free-space-tests.c
59410+++ b/fs/btrfs/tests/free-space-tests.c
59411@@ -463,7 +463,9 @@ test_steal_space_from_bitmap_to_extent(struct btrfs_block_group_cache *cache)
59412 * extent entry.
59413 */
59414 use_bitmap_op = cache->free_space_ctl->op->use_bitmap;
59415- cache->free_space_ctl->op->use_bitmap = test_use_bitmap;
59416+ pax_open_kernel();
59417+ *(void **)&cache->free_space_ctl->op->use_bitmap = test_use_bitmap;
59418+ pax_close_kernel();
59419
59420 /*
59421 * Extent entry covering free space range [128Mb - 256Kb, 128Mb - 128Kb[
59422@@ -870,7 +872,9 @@ test_steal_space_from_bitmap_to_extent(struct btrfs_block_group_cache *cache)
59423 if (ret)
59424 return ret;
59425
59426- cache->free_space_ctl->op->use_bitmap = use_bitmap_op;
59427+ pax_open_kernel();
59428+ *(void **)&cache->free_space_ctl->op->use_bitmap = use_bitmap_op;
59429+ pax_close_kernel();
59430 __btrfs_remove_free_space_cache(cache->free_space_ctl);
59431
59432 return 0;
59433diff --git a/fs/btrfs/tree-log.h b/fs/btrfs/tree-log.h
59434index 154990c..d0cf699 100644
59435--- a/fs/btrfs/tree-log.h
59436+++ b/fs/btrfs/tree-log.h
59437@@ -43,7 +43,7 @@ static inline void btrfs_init_log_ctx(struct btrfs_log_ctx *ctx)
59438 static inline void btrfs_set_log_full_commit(struct btrfs_fs_info *fs_info,
59439 struct btrfs_trans_handle *trans)
59440 {
59441- ACCESS_ONCE(fs_info->last_trans_log_full_commit) = trans->transid;
59442+ ACCESS_ONCE_RW(fs_info->last_trans_log_full_commit) = trans->transid;
59443 }
59444
59445 static inline int btrfs_need_log_full_commit(struct btrfs_fs_info *fs_info,
59446diff --git a/fs/buffer.c b/fs/buffer.c
59447index 20805db..2e8fc69 100644
59448--- a/fs/buffer.c
59449+++ b/fs/buffer.c
59450@@ -3417,7 +3417,7 @@ void __init buffer_init(void)
59451 bh_cachep = kmem_cache_create("buffer_head",
59452 sizeof(struct buffer_head), 0,
59453 (SLAB_RECLAIM_ACCOUNT|SLAB_PANIC|
59454- SLAB_MEM_SPREAD),
59455+ SLAB_MEM_SPREAD|SLAB_NO_SANITIZE),
59456 NULL);
59457
59458 /*
59459diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
59460index fbb08e9..0fda764 100644
59461--- a/fs/cachefiles/bind.c
59462+++ b/fs/cachefiles/bind.c
59463@@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
59464 args);
59465
59466 /* start by checking things over */
59467- ASSERT(cache->fstop_percent >= 0 &&
59468- cache->fstop_percent < cache->fcull_percent &&
59469+ ASSERT(cache->fstop_percent < cache->fcull_percent &&
59470 cache->fcull_percent < cache->frun_percent &&
59471 cache->frun_percent < 100);
59472
59473- ASSERT(cache->bstop_percent >= 0 &&
59474- cache->bstop_percent < cache->bcull_percent &&
59475+ ASSERT(cache->bstop_percent < cache->bcull_percent &&
59476 cache->bcull_percent < cache->brun_percent &&
59477 cache->brun_percent < 100);
59478
59479diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
59480index ce1b115..4a6852c 100644
59481--- a/fs/cachefiles/daemon.c
59482+++ b/fs/cachefiles/daemon.c
59483@@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
59484 if (n > buflen)
59485 return -EMSGSIZE;
59486
59487- if (copy_to_user(_buffer, buffer, n) != 0)
59488+ if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
59489 return -EFAULT;
59490
59491 return n;
59492@@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
59493 if (test_bit(CACHEFILES_DEAD, &cache->flags))
59494 return -EIO;
59495
59496- if (datalen < 0 || datalen > PAGE_SIZE - 1)
59497+ if (datalen > PAGE_SIZE - 1)
59498 return -EOPNOTSUPP;
59499
59500 /* drag the command string into the kernel so we can parse it */
59501@@ -385,7 +385,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
59502 if (args[0] != '%' || args[1] != '\0')
59503 return -EINVAL;
59504
59505- if (fstop < 0 || fstop >= cache->fcull_percent)
59506+ if (fstop >= cache->fcull_percent)
59507 return cachefiles_daemon_range_error(cache, args);
59508
59509 cache->fstop_percent = fstop;
59510@@ -457,7 +457,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
59511 if (args[0] != '%' || args[1] != '\0')
59512 return -EINVAL;
59513
59514- if (bstop < 0 || bstop >= cache->bcull_percent)
59515+ if (bstop >= cache->bcull_percent)
59516 return cachefiles_daemon_range_error(cache, args);
59517
59518 cache->bstop_percent = bstop;
59519diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
59520index 8c52472..c4e3a69 100644
59521--- a/fs/cachefiles/internal.h
59522+++ b/fs/cachefiles/internal.h
59523@@ -66,7 +66,7 @@ struct cachefiles_cache {
59524 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
59525 struct rb_root active_nodes; /* active nodes (can't be culled) */
59526 rwlock_t active_lock; /* lock for active_nodes */
59527- atomic_t gravecounter; /* graveyard uniquifier */
59528+ atomic_unchecked_t gravecounter; /* graveyard uniquifier */
59529 unsigned frun_percent; /* when to stop culling (% files) */
59530 unsigned fcull_percent; /* when to start culling (% files) */
59531 unsigned fstop_percent; /* when to stop allocating (% files) */
59532@@ -178,19 +178,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
59533 * proc.c
59534 */
59535 #ifdef CONFIG_CACHEFILES_HISTOGRAM
59536-extern atomic_t cachefiles_lookup_histogram[HZ];
59537-extern atomic_t cachefiles_mkdir_histogram[HZ];
59538-extern atomic_t cachefiles_create_histogram[HZ];
59539+extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
59540+extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
59541+extern atomic_unchecked_t cachefiles_create_histogram[HZ];
59542
59543 extern int __init cachefiles_proc_init(void);
59544 extern void cachefiles_proc_cleanup(void);
59545 static inline
59546-void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
59547+void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
59548 {
59549 unsigned long jif = jiffies - start_jif;
59550 if (jif >= HZ)
59551 jif = HZ - 1;
59552- atomic_inc(&histogram[jif]);
59553+ atomic_inc_unchecked(&histogram[jif]);
59554 }
59555
59556 #else
59557diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
59558index e12f189..ed17244 100644
59559--- a/fs/cachefiles/namei.c
59560+++ b/fs/cachefiles/namei.c
59561@@ -312,7 +312,7 @@ try_again:
59562 /* first step is to make up a grave dentry in the graveyard */
59563 sprintf(nbuffer, "%08x%08x",
59564 (uint32_t) get_seconds(),
59565- (uint32_t) atomic_inc_return(&cache->gravecounter));
59566+ (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
59567
59568 /* do the multiway lock magic */
59569 trap = lock_rename(cache->graveyard, dir);
59570diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
59571index eccd339..4c1d995 100644
59572--- a/fs/cachefiles/proc.c
59573+++ b/fs/cachefiles/proc.c
59574@@ -14,9 +14,9 @@
59575 #include <linux/seq_file.h>
59576 #include "internal.h"
59577
59578-atomic_t cachefiles_lookup_histogram[HZ];
59579-atomic_t cachefiles_mkdir_histogram[HZ];
59580-atomic_t cachefiles_create_histogram[HZ];
59581+atomic_unchecked_t cachefiles_lookup_histogram[HZ];
59582+atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
59583+atomic_unchecked_t cachefiles_create_histogram[HZ];
59584
59585 /*
59586 * display the latency histogram
59587@@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
59588 return 0;
59589 default:
59590 index = (unsigned long) v - 3;
59591- x = atomic_read(&cachefiles_lookup_histogram[index]);
59592- y = atomic_read(&cachefiles_mkdir_histogram[index]);
59593- z = atomic_read(&cachefiles_create_histogram[index]);
59594+ x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
59595+ y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
59596+ z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
59597 if (x == 0 && y == 0 && z == 0)
59598 return 0;
59599
59600diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
59601index 695e788..f4a9d4d 100644
59602--- a/fs/ceph/dir.c
59603+++ b/fs/ceph/dir.c
59604@@ -129,6 +129,8 @@ static int __dcache_readdir(struct file *file, struct dir_context *ctx,
59605 struct dentry *dentry, *last;
59606 struct ceph_dentry_info *di;
59607 int err = 0;
59608+ char d_name[DNAME_INLINE_LEN];
59609+ const unsigned char *name;
59610
59611 /* claim ref on last dentry we returned */
59612 last = fi->dentry;
59613@@ -192,7 +194,12 @@ more:
59614
59615 dout(" %llu (%llu) dentry %p %.*s %p\n", di->offset, ctx->pos,
59616 dentry, dentry->d_name.len, dentry->d_name.name, dentry->d_inode);
59617- if (!dir_emit(ctx, dentry->d_name.name,
59618+ name = dentry->d_name.name;
59619+ if (name == dentry->d_iname) {
59620+ memcpy(d_name, name, dentry->d_name.len);
59621+ name = d_name;
59622+ }
59623+ if (!dir_emit(ctx, name,
59624 dentry->d_name.len,
59625 ceph_translate_ino(dentry->d_sb, dentry->d_inode->i_ino),
59626 dentry->d_inode->i_mode >> 12)) {
59627@@ -250,7 +257,7 @@ static int ceph_readdir(struct file *file, struct dir_context *ctx)
59628 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
59629 struct ceph_mds_client *mdsc = fsc->mdsc;
59630 unsigned frag = fpos_frag(ctx->pos);
59631- int off = fpos_off(ctx->pos);
59632+ unsigned int off = fpos_off(ctx->pos);
59633 int err;
59634 u32 ftype;
59635 struct ceph_mds_reply_info_parsed *rinfo;
59636diff --git a/fs/ceph/super.c b/fs/ceph/super.c
59637index f6e1237..796ffd1 100644
59638--- a/fs/ceph/super.c
59639+++ b/fs/ceph/super.c
59640@@ -895,7 +895,7 @@ static int ceph_compare_super(struct super_block *sb, void *data)
59641 /*
59642 * construct our own bdi so we can control readahead, etc.
59643 */
59644-static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
59645+static atomic_long_unchecked_t bdi_seq = ATOMIC_LONG_INIT(0);
59646
59647 static int ceph_register_bdi(struct super_block *sb,
59648 struct ceph_fs_client *fsc)
59649@@ -912,7 +912,7 @@ static int ceph_register_bdi(struct super_block *sb,
59650 default_backing_dev_info.ra_pages;
59651
59652 err = bdi_register(&fsc->backing_dev_info, NULL, "ceph-%ld",
59653- atomic_long_inc_return(&bdi_seq));
59654+ atomic_long_inc_return_unchecked(&bdi_seq));
59655 if (!err)
59656 sb->s_bdi = &fsc->backing_dev_info;
59657 return err;
59658diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
59659index 44ec726..bcb06a3 100644
59660--- a/fs/cifs/cifs_debug.c
59661+++ b/fs/cifs/cifs_debug.c
59662@@ -286,8 +286,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
59663
59664 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
59665 #ifdef CONFIG_CIFS_STATS2
59666- atomic_set(&totBufAllocCount, 0);
59667- atomic_set(&totSmBufAllocCount, 0);
59668+ atomic_set_unchecked(&totBufAllocCount, 0);
59669+ atomic_set_unchecked(&totSmBufAllocCount, 0);
59670 #endif /* CONFIG_CIFS_STATS2 */
59671 spin_lock(&cifs_tcp_ses_lock);
59672 list_for_each(tmp1, &cifs_tcp_ses_list) {
59673@@ -300,7 +300,7 @@ static ssize_t cifs_stats_proc_write(struct file *file,
59674 tcon = list_entry(tmp3,
59675 struct cifs_tcon,
59676 tcon_list);
59677- atomic_set(&tcon->num_smbs_sent, 0);
59678+ atomic_set_unchecked(&tcon->num_smbs_sent, 0);
59679 if (server->ops->clear_stats)
59680 server->ops->clear_stats(tcon);
59681 }
59682@@ -332,8 +332,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
59683 smBufAllocCount.counter, cifs_min_small);
59684 #ifdef CONFIG_CIFS_STATS2
59685 seq_printf(m, "Total Large %d Small %d Allocations\n",
59686- atomic_read(&totBufAllocCount),
59687- atomic_read(&totSmBufAllocCount));
59688+ atomic_read_unchecked(&totBufAllocCount),
59689+ atomic_read_unchecked(&totSmBufAllocCount));
59690 #endif /* CONFIG_CIFS_STATS2 */
59691
59692 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
59693@@ -362,7 +362,7 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
59694 if (tcon->need_reconnect)
59695 seq_puts(m, "\tDISCONNECTED ");
59696 seq_printf(m, "\nSMBs: %d",
59697- atomic_read(&tcon->num_smbs_sent));
59698+ atomic_read_unchecked(&tcon->num_smbs_sent));
59699 if (server->ops->print_stats)
59700 server->ops->print_stats(m, tcon);
59701 }
59702diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
59703index 9d7996e..35ad5cf4 100644
59704--- a/fs/cifs/cifsfs.c
59705+++ b/fs/cifs/cifsfs.c
59706@@ -1093,7 +1093,7 @@ cifs_init_request_bufs(void)
59707 */
59708 cifs_req_cachep = kmem_cache_create("cifs_request",
59709 CIFSMaxBufSize + max_hdr_size, 0,
59710- SLAB_HWCACHE_ALIGN, NULL);
59711+ SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
59712 if (cifs_req_cachep == NULL)
59713 return -ENOMEM;
59714
59715@@ -1120,7 +1120,7 @@ cifs_init_request_bufs(void)
59716 efficient to alloc 1 per page off the slab compared to 17K (5page)
59717 alloc of large cifs buffers even when page debugging is on */
59718 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
59719- MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
59720+ MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
59721 NULL);
59722 if (cifs_sm_req_cachep == NULL) {
59723 mempool_destroy(cifs_req_poolp);
59724@@ -1205,8 +1205,8 @@ init_cifs(void)
59725 atomic_set(&bufAllocCount, 0);
59726 atomic_set(&smBufAllocCount, 0);
59727 #ifdef CONFIG_CIFS_STATS2
59728- atomic_set(&totBufAllocCount, 0);
59729- atomic_set(&totSmBufAllocCount, 0);
59730+ atomic_set_unchecked(&totBufAllocCount, 0);
59731+ atomic_set_unchecked(&totSmBufAllocCount, 0);
59732 #endif /* CONFIG_CIFS_STATS2 */
59733
59734 atomic_set(&midCount, 0);
59735diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
59736index 02a33e5..3a28b5a 100644
59737--- a/fs/cifs/cifsglob.h
59738+++ b/fs/cifs/cifsglob.h
59739@@ -823,35 +823,35 @@ struct cifs_tcon {
59740 __u16 Flags; /* optional support bits */
59741 enum statusEnum tidStatus;
59742 #ifdef CONFIG_CIFS_STATS
59743- atomic_t num_smbs_sent;
59744+ atomic_unchecked_t num_smbs_sent;
59745 union {
59746 struct {
59747- atomic_t num_writes;
59748- atomic_t num_reads;
59749- atomic_t num_flushes;
59750- atomic_t num_oplock_brks;
59751- atomic_t num_opens;
59752- atomic_t num_closes;
59753- atomic_t num_deletes;
59754- atomic_t num_mkdirs;
59755- atomic_t num_posixopens;
59756- atomic_t num_posixmkdirs;
59757- atomic_t num_rmdirs;
59758- atomic_t num_renames;
59759- atomic_t num_t2renames;
59760- atomic_t num_ffirst;
59761- atomic_t num_fnext;
59762- atomic_t num_fclose;
59763- atomic_t num_hardlinks;
59764- atomic_t num_symlinks;
59765- atomic_t num_locks;
59766- atomic_t num_acl_get;
59767- atomic_t num_acl_set;
59768+ atomic_unchecked_t num_writes;
59769+ atomic_unchecked_t num_reads;
59770+ atomic_unchecked_t num_flushes;
59771+ atomic_unchecked_t num_oplock_brks;
59772+ atomic_unchecked_t num_opens;
59773+ atomic_unchecked_t num_closes;
59774+ atomic_unchecked_t num_deletes;
59775+ atomic_unchecked_t num_mkdirs;
59776+ atomic_unchecked_t num_posixopens;
59777+ atomic_unchecked_t num_posixmkdirs;
59778+ atomic_unchecked_t num_rmdirs;
59779+ atomic_unchecked_t num_renames;
59780+ atomic_unchecked_t num_t2renames;
59781+ atomic_unchecked_t num_ffirst;
59782+ atomic_unchecked_t num_fnext;
59783+ atomic_unchecked_t num_fclose;
59784+ atomic_unchecked_t num_hardlinks;
59785+ atomic_unchecked_t num_symlinks;
59786+ atomic_unchecked_t num_locks;
59787+ atomic_unchecked_t num_acl_get;
59788+ atomic_unchecked_t num_acl_set;
59789 } cifs_stats;
59790 #ifdef CONFIG_CIFS_SMB2
59791 struct {
59792- atomic_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
59793- atomic_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
59794+ atomic_unchecked_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
59795+ atomic_unchecked_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
59796 } smb2_stats;
59797 #endif /* CONFIG_CIFS_SMB2 */
59798 } stats;
59799@@ -1192,7 +1192,7 @@ convert_delimiter(char *path, char delim)
59800 }
59801
59802 #ifdef CONFIG_CIFS_STATS
59803-#define cifs_stats_inc atomic_inc
59804+#define cifs_stats_inc atomic_inc_unchecked
59805
59806 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
59807 unsigned int bytes)
59808@@ -1559,8 +1559,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
59809 /* Various Debug counters */
59810 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
59811 #ifdef CONFIG_CIFS_STATS2
59812-GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
59813-GLOBAL_EXTERN atomic_t totSmBufAllocCount;
59814+GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
59815+GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
59816 #endif
59817 GLOBAL_EXTERN atomic_t smBufAllocCount;
59818 GLOBAL_EXTERN atomic_t midCount;
59819diff --git a/fs/cifs/file.c b/fs/cifs/file.c
59820index 3e4d00a..38a122d 100644
59821--- a/fs/cifs/file.c
59822+++ b/fs/cifs/file.c
59823@@ -2056,10 +2056,14 @@ static int cifs_writepages(struct address_space *mapping,
59824 index = mapping->writeback_index; /* Start from prev offset */
59825 end = -1;
59826 } else {
59827- index = wbc->range_start >> PAGE_CACHE_SHIFT;
59828- end = wbc->range_end >> PAGE_CACHE_SHIFT;
59829- if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX)
59830+ if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX) {
59831 range_whole = true;
59832+ index = 0;
59833+ end = ULONG_MAX;
59834+ } else {
59835+ index = wbc->range_start >> PAGE_CACHE_SHIFT;
59836+ end = wbc->range_end >> PAGE_CACHE_SHIFT;
59837+ }
59838 scanned = true;
59839 }
59840 server = cifs_sb_master_tcon(cifs_sb)->ses->server;
59841diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
59842index b7415d5..3984ec0 100644
59843--- a/fs/cifs/misc.c
59844+++ b/fs/cifs/misc.c
59845@@ -170,7 +170,7 @@ cifs_buf_get(void)
59846 memset(ret_buf, 0, buf_size + 3);
59847 atomic_inc(&bufAllocCount);
59848 #ifdef CONFIG_CIFS_STATS2
59849- atomic_inc(&totBufAllocCount);
59850+ atomic_inc_unchecked(&totBufAllocCount);
59851 #endif /* CONFIG_CIFS_STATS2 */
59852 }
59853
59854@@ -205,7 +205,7 @@ cifs_small_buf_get(void)
59855 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
59856 atomic_inc(&smBufAllocCount);
59857 #ifdef CONFIG_CIFS_STATS2
59858- atomic_inc(&totSmBufAllocCount);
59859+ atomic_inc_unchecked(&totSmBufAllocCount);
59860 #endif /* CONFIG_CIFS_STATS2 */
59861
59862 }
59863diff --git a/fs/cifs/smb1ops.c b/fs/cifs/smb1ops.c
59864index d297903..1cb7516 100644
59865--- a/fs/cifs/smb1ops.c
59866+++ b/fs/cifs/smb1ops.c
59867@@ -622,27 +622,27 @@ static void
59868 cifs_clear_stats(struct cifs_tcon *tcon)
59869 {
59870 #ifdef CONFIG_CIFS_STATS
59871- atomic_set(&tcon->stats.cifs_stats.num_writes, 0);
59872- atomic_set(&tcon->stats.cifs_stats.num_reads, 0);
59873- atomic_set(&tcon->stats.cifs_stats.num_flushes, 0);
59874- atomic_set(&tcon->stats.cifs_stats.num_oplock_brks, 0);
59875- atomic_set(&tcon->stats.cifs_stats.num_opens, 0);
59876- atomic_set(&tcon->stats.cifs_stats.num_posixopens, 0);
59877- atomic_set(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
59878- atomic_set(&tcon->stats.cifs_stats.num_closes, 0);
59879- atomic_set(&tcon->stats.cifs_stats.num_deletes, 0);
59880- atomic_set(&tcon->stats.cifs_stats.num_mkdirs, 0);
59881- atomic_set(&tcon->stats.cifs_stats.num_rmdirs, 0);
59882- atomic_set(&tcon->stats.cifs_stats.num_renames, 0);
59883- atomic_set(&tcon->stats.cifs_stats.num_t2renames, 0);
59884- atomic_set(&tcon->stats.cifs_stats.num_ffirst, 0);
59885- atomic_set(&tcon->stats.cifs_stats.num_fnext, 0);
59886- atomic_set(&tcon->stats.cifs_stats.num_fclose, 0);
59887- atomic_set(&tcon->stats.cifs_stats.num_hardlinks, 0);
59888- atomic_set(&tcon->stats.cifs_stats.num_symlinks, 0);
59889- atomic_set(&tcon->stats.cifs_stats.num_locks, 0);
59890- atomic_set(&tcon->stats.cifs_stats.num_acl_get, 0);
59891- atomic_set(&tcon->stats.cifs_stats.num_acl_set, 0);
59892+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_writes, 0);
59893+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_reads, 0);
59894+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_flushes, 0);
59895+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_oplock_brks, 0);
59896+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_opens, 0);
59897+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixopens, 0);
59898+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
59899+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_closes, 0);
59900+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_deletes, 0);
59901+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_mkdirs, 0);
59902+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_rmdirs, 0);
59903+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_renames, 0);
59904+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_t2renames, 0);
59905+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_ffirst, 0);
59906+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_fnext, 0);
59907+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_fclose, 0);
59908+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_hardlinks, 0);
59909+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_symlinks, 0);
59910+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_locks, 0);
59911+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_get, 0);
59912+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_set, 0);
59913 #endif
59914 }
59915
59916@@ -651,36 +651,36 @@ cifs_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
59917 {
59918 #ifdef CONFIG_CIFS_STATS
59919 seq_printf(m, " Oplocks breaks: %d",
59920- atomic_read(&tcon->stats.cifs_stats.num_oplock_brks));
59921+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_oplock_brks));
59922 seq_printf(m, "\nReads: %d Bytes: %llu",
59923- atomic_read(&tcon->stats.cifs_stats.num_reads),
59924+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_reads),
59925 (long long)(tcon->bytes_read));
59926 seq_printf(m, "\nWrites: %d Bytes: %llu",
59927- atomic_read(&tcon->stats.cifs_stats.num_writes),
59928+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_writes),
59929 (long long)(tcon->bytes_written));
59930 seq_printf(m, "\nFlushes: %d",
59931- atomic_read(&tcon->stats.cifs_stats.num_flushes));
59932+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_flushes));
59933 seq_printf(m, "\nLocks: %d HardLinks: %d Symlinks: %d",
59934- atomic_read(&tcon->stats.cifs_stats.num_locks),
59935- atomic_read(&tcon->stats.cifs_stats.num_hardlinks),
59936- atomic_read(&tcon->stats.cifs_stats.num_symlinks));
59937+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_locks),
59938+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_hardlinks),
59939+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_symlinks));
59940 seq_printf(m, "\nOpens: %d Closes: %d Deletes: %d",
59941- atomic_read(&tcon->stats.cifs_stats.num_opens),
59942- atomic_read(&tcon->stats.cifs_stats.num_closes),
59943- atomic_read(&tcon->stats.cifs_stats.num_deletes));
59944+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_opens),
59945+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_closes),
59946+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_deletes));
59947 seq_printf(m, "\nPosix Opens: %d Posix Mkdirs: %d",
59948- atomic_read(&tcon->stats.cifs_stats.num_posixopens),
59949- atomic_read(&tcon->stats.cifs_stats.num_posixmkdirs));
59950+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixopens),
59951+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs));
59952 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
59953- atomic_read(&tcon->stats.cifs_stats.num_mkdirs),
59954- atomic_read(&tcon->stats.cifs_stats.num_rmdirs));
59955+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_mkdirs),
59956+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_rmdirs));
59957 seq_printf(m, "\nRenames: %d T2 Renames %d",
59958- atomic_read(&tcon->stats.cifs_stats.num_renames),
59959- atomic_read(&tcon->stats.cifs_stats.num_t2renames));
59960+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_renames),
59961+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_t2renames));
59962 seq_printf(m, "\nFindFirst: %d FNext %d FClose %d",
59963- atomic_read(&tcon->stats.cifs_stats.num_ffirst),
59964- atomic_read(&tcon->stats.cifs_stats.num_fnext),
59965- atomic_read(&tcon->stats.cifs_stats.num_fclose));
59966+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_ffirst),
59967+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_fnext),
59968+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_fclose));
59969 #endif
59970 }
59971
59972diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
59973index c5f521b..1a40865 100644
59974--- a/fs/cifs/smb2ops.c
59975+++ b/fs/cifs/smb2ops.c
59976@@ -417,8 +417,8 @@ smb2_clear_stats(struct cifs_tcon *tcon)
59977 #ifdef CONFIG_CIFS_STATS
59978 int i;
59979 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
59980- atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
59981- atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
59982+ atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
59983+ atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
59984 }
59985 #endif
59986 }
59987@@ -458,65 +458,65 @@ static void
59988 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
59989 {
59990 #ifdef CONFIG_CIFS_STATS
59991- atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
59992- atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
59993+ atomic_unchecked_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
59994+ atomic_unchecked_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
59995 seq_printf(m, "\nNegotiates: %d sent %d failed",
59996- atomic_read(&sent[SMB2_NEGOTIATE_HE]),
59997- atomic_read(&failed[SMB2_NEGOTIATE_HE]));
59998+ atomic_read_unchecked(&sent[SMB2_NEGOTIATE_HE]),
59999+ atomic_read_unchecked(&failed[SMB2_NEGOTIATE_HE]));
60000 seq_printf(m, "\nSessionSetups: %d sent %d failed",
60001- atomic_read(&sent[SMB2_SESSION_SETUP_HE]),
60002- atomic_read(&failed[SMB2_SESSION_SETUP_HE]));
60003+ atomic_read_unchecked(&sent[SMB2_SESSION_SETUP_HE]),
60004+ atomic_read_unchecked(&failed[SMB2_SESSION_SETUP_HE]));
60005 seq_printf(m, "\nLogoffs: %d sent %d failed",
60006- atomic_read(&sent[SMB2_LOGOFF_HE]),
60007- atomic_read(&failed[SMB2_LOGOFF_HE]));
60008+ atomic_read_unchecked(&sent[SMB2_LOGOFF_HE]),
60009+ atomic_read_unchecked(&failed[SMB2_LOGOFF_HE]));
60010 seq_printf(m, "\nTreeConnects: %d sent %d failed",
60011- atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
60012- atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
60013+ atomic_read_unchecked(&sent[SMB2_TREE_CONNECT_HE]),
60014+ atomic_read_unchecked(&failed[SMB2_TREE_CONNECT_HE]));
60015 seq_printf(m, "\nTreeDisconnects: %d sent %d failed",
60016- atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
60017- atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
60018+ atomic_read_unchecked(&sent[SMB2_TREE_DISCONNECT_HE]),
60019+ atomic_read_unchecked(&failed[SMB2_TREE_DISCONNECT_HE]));
60020 seq_printf(m, "\nCreates: %d sent %d failed",
60021- atomic_read(&sent[SMB2_CREATE_HE]),
60022- atomic_read(&failed[SMB2_CREATE_HE]));
60023+ atomic_read_unchecked(&sent[SMB2_CREATE_HE]),
60024+ atomic_read_unchecked(&failed[SMB2_CREATE_HE]));
60025 seq_printf(m, "\nCloses: %d sent %d failed",
60026- atomic_read(&sent[SMB2_CLOSE_HE]),
60027- atomic_read(&failed[SMB2_CLOSE_HE]));
60028+ atomic_read_unchecked(&sent[SMB2_CLOSE_HE]),
60029+ atomic_read_unchecked(&failed[SMB2_CLOSE_HE]));
60030 seq_printf(m, "\nFlushes: %d sent %d failed",
60031- atomic_read(&sent[SMB2_FLUSH_HE]),
60032- atomic_read(&failed[SMB2_FLUSH_HE]));
60033+ atomic_read_unchecked(&sent[SMB2_FLUSH_HE]),
60034+ atomic_read_unchecked(&failed[SMB2_FLUSH_HE]));
60035 seq_printf(m, "\nReads: %d sent %d failed",
60036- atomic_read(&sent[SMB2_READ_HE]),
60037- atomic_read(&failed[SMB2_READ_HE]));
60038+ atomic_read_unchecked(&sent[SMB2_READ_HE]),
60039+ atomic_read_unchecked(&failed[SMB2_READ_HE]));
60040 seq_printf(m, "\nWrites: %d sent %d failed",
60041- atomic_read(&sent[SMB2_WRITE_HE]),
60042- atomic_read(&failed[SMB2_WRITE_HE]));
60043+ atomic_read_unchecked(&sent[SMB2_WRITE_HE]),
60044+ atomic_read_unchecked(&failed[SMB2_WRITE_HE]));
60045 seq_printf(m, "\nLocks: %d sent %d failed",
60046- atomic_read(&sent[SMB2_LOCK_HE]),
60047- atomic_read(&failed[SMB2_LOCK_HE]));
60048+ atomic_read_unchecked(&sent[SMB2_LOCK_HE]),
60049+ atomic_read_unchecked(&failed[SMB2_LOCK_HE]));
60050 seq_printf(m, "\nIOCTLs: %d sent %d failed",
60051- atomic_read(&sent[SMB2_IOCTL_HE]),
60052- atomic_read(&failed[SMB2_IOCTL_HE]));
60053+ atomic_read_unchecked(&sent[SMB2_IOCTL_HE]),
60054+ atomic_read_unchecked(&failed[SMB2_IOCTL_HE]));
60055 seq_printf(m, "\nCancels: %d sent %d failed",
60056- atomic_read(&sent[SMB2_CANCEL_HE]),
60057- atomic_read(&failed[SMB2_CANCEL_HE]));
60058+ atomic_read_unchecked(&sent[SMB2_CANCEL_HE]),
60059+ atomic_read_unchecked(&failed[SMB2_CANCEL_HE]));
60060 seq_printf(m, "\nEchos: %d sent %d failed",
60061- atomic_read(&sent[SMB2_ECHO_HE]),
60062- atomic_read(&failed[SMB2_ECHO_HE]));
60063+ atomic_read_unchecked(&sent[SMB2_ECHO_HE]),
60064+ atomic_read_unchecked(&failed[SMB2_ECHO_HE]));
60065 seq_printf(m, "\nQueryDirectories: %d sent %d failed",
60066- atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
60067- atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
60068+ atomic_read_unchecked(&sent[SMB2_QUERY_DIRECTORY_HE]),
60069+ atomic_read_unchecked(&failed[SMB2_QUERY_DIRECTORY_HE]));
60070 seq_printf(m, "\nChangeNotifies: %d sent %d failed",
60071- atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
60072- atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
60073+ atomic_read_unchecked(&sent[SMB2_CHANGE_NOTIFY_HE]),
60074+ atomic_read_unchecked(&failed[SMB2_CHANGE_NOTIFY_HE]));
60075 seq_printf(m, "\nQueryInfos: %d sent %d failed",
60076- atomic_read(&sent[SMB2_QUERY_INFO_HE]),
60077- atomic_read(&failed[SMB2_QUERY_INFO_HE]));
60078+ atomic_read_unchecked(&sent[SMB2_QUERY_INFO_HE]),
60079+ atomic_read_unchecked(&failed[SMB2_QUERY_INFO_HE]));
60080 seq_printf(m, "\nSetInfos: %d sent %d failed",
60081- atomic_read(&sent[SMB2_SET_INFO_HE]),
60082- atomic_read(&failed[SMB2_SET_INFO_HE]));
60083+ atomic_read_unchecked(&sent[SMB2_SET_INFO_HE]),
60084+ atomic_read_unchecked(&failed[SMB2_SET_INFO_HE]));
60085 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
60086- atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
60087- atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
60088+ atomic_read_unchecked(&sent[SMB2_OPLOCK_BREAK_HE]),
60089+ atomic_read_unchecked(&failed[SMB2_OPLOCK_BREAK_HE]));
60090 #endif
60091 }
60092
60093diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c
60094index 8f1672b..af339c07 100644
60095--- a/fs/cifs/smb2pdu.c
60096+++ b/fs/cifs/smb2pdu.c
60097@@ -2145,8 +2145,7 @@ SMB2_query_directory(const unsigned int xid, struct cifs_tcon *tcon,
60098 default:
60099 cifs_dbg(VFS, "info level %u isn't supported\n",
60100 srch_inf->info_level);
60101- rc = -EINVAL;
60102- goto qdir_exit;
60103+ return -EINVAL;
60104 }
60105
60106 req->FileIndex = cpu_to_le32(index);
60107diff --git a/fs/coda/cache.c b/fs/coda/cache.c
60108index 46ee6f2..89a9e7f 100644
60109--- a/fs/coda/cache.c
60110+++ b/fs/coda/cache.c
60111@@ -24,7 +24,7 @@
60112 #include "coda_linux.h"
60113 #include "coda_cache.h"
60114
60115-static atomic_t permission_epoch = ATOMIC_INIT(0);
60116+static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
60117
60118 /* replace or extend an acl cache hit */
60119 void coda_cache_enter(struct inode *inode, int mask)
60120@@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
60121 struct coda_inode_info *cii = ITOC(inode);
60122
60123 spin_lock(&cii->c_lock);
60124- cii->c_cached_epoch = atomic_read(&permission_epoch);
60125+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
60126 if (!uid_eq(cii->c_uid, current_fsuid())) {
60127 cii->c_uid = current_fsuid();
60128 cii->c_cached_perm = mask;
60129@@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
60130 {
60131 struct coda_inode_info *cii = ITOC(inode);
60132 spin_lock(&cii->c_lock);
60133- cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
60134+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
60135 spin_unlock(&cii->c_lock);
60136 }
60137
60138 /* remove all acl caches */
60139 void coda_cache_clear_all(struct super_block *sb)
60140 {
60141- atomic_inc(&permission_epoch);
60142+ atomic_inc_unchecked(&permission_epoch);
60143 }
60144
60145
60146@@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
60147 spin_lock(&cii->c_lock);
60148 hit = (mask & cii->c_cached_perm) == mask &&
60149 uid_eq(cii->c_uid, current_fsuid()) &&
60150- cii->c_cached_epoch == atomic_read(&permission_epoch);
60151+ cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
60152 spin_unlock(&cii->c_lock);
60153
60154 return hit;
60155diff --git a/fs/compat.c b/fs/compat.c
60156index b13df99..6f6f4a3 100644
60157--- a/fs/compat.c
60158+++ b/fs/compat.c
60159@@ -54,7 +54,7 @@
60160 #include <asm/ioctls.h>
60161 #include "internal.h"
60162
60163-int compat_log = 1;
60164+int compat_log = 0;
60165
60166 int compat_printk(const char *fmt, ...)
60167 {
60168@@ -512,7 +512,7 @@ COMPAT_SYSCALL_DEFINE2(io_setup, unsigned, nr_reqs, u32 __user *, ctx32p)
60169
60170 set_fs(KERNEL_DS);
60171 /* The __user pointer cast is valid because of the set_fs() */
60172- ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
60173+ ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
60174 set_fs(oldfs);
60175 /* truncating is ok because it's a user address */
60176 if (!ret)
60177@@ -562,7 +562,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
60178 goto out;
60179
60180 ret = -EINVAL;
60181- if (nr_segs > UIO_MAXIOV || nr_segs < 0)
60182+ if (nr_segs > UIO_MAXIOV)
60183 goto out;
60184 if (nr_segs > fast_segs) {
60185 ret = -ENOMEM;
60186@@ -844,6 +844,7 @@ struct compat_old_linux_dirent {
60187 struct compat_readdir_callback {
60188 struct dir_context ctx;
60189 struct compat_old_linux_dirent __user *dirent;
60190+ struct file * file;
60191 int result;
60192 };
60193
60194@@ -861,6 +862,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
60195 buf->result = -EOVERFLOW;
60196 return -EOVERFLOW;
60197 }
60198+
60199+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
60200+ return 0;
60201+
60202 buf->result++;
60203 dirent = buf->dirent;
60204 if (!access_ok(VERIFY_WRITE, dirent,
60205@@ -892,6 +897,7 @@ COMPAT_SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
60206 if (!f.file)
60207 return -EBADF;
60208
60209+ buf.file = f.file;
60210 error = iterate_dir(f.file, &buf.ctx);
60211 if (buf.result)
60212 error = buf.result;
60213@@ -911,6 +917,7 @@ struct compat_getdents_callback {
60214 struct dir_context ctx;
60215 struct compat_linux_dirent __user *current_dir;
60216 struct compat_linux_dirent __user *previous;
60217+ struct file * file;
60218 int count;
60219 int error;
60220 };
60221@@ -932,6 +939,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
60222 buf->error = -EOVERFLOW;
60223 return -EOVERFLOW;
60224 }
60225+
60226+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
60227+ return 0;
60228+
60229 dirent = buf->previous;
60230 if (dirent) {
60231 if (__put_user(offset, &dirent->d_off))
60232@@ -977,6 +988,7 @@ COMPAT_SYSCALL_DEFINE3(getdents, unsigned int, fd,
60233 if (!f.file)
60234 return -EBADF;
60235
60236+ buf.file = f.file;
60237 error = iterate_dir(f.file, &buf.ctx);
60238 if (error >= 0)
60239 error = buf.error;
60240@@ -997,6 +1009,7 @@ struct compat_getdents_callback64 {
60241 struct dir_context ctx;
60242 struct linux_dirent64 __user *current_dir;
60243 struct linux_dirent64 __user *previous;
60244+ struct file * file;
60245 int count;
60246 int error;
60247 };
60248@@ -1013,6 +1026,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
60249 buf->error = -EINVAL; /* only used if we fail.. */
60250 if (reclen > buf->count)
60251 return -EINVAL;
60252+
60253+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
60254+ return 0;
60255+
60256 dirent = buf->previous;
60257
60258 if (dirent) {
60259@@ -1062,6 +1079,7 @@ COMPAT_SYSCALL_DEFINE3(getdents64, unsigned int, fd,
60260 if (!f.file)
60261 return -EBADF;
60262
60263+ buf.file = f.file;
60264 error = iterate_dir(f.file, &buf.ctx);
60265 if (error >= 0)
60266 error = buf.error;
60267diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
60268index 4d24d17..4f8c09e 100644
60269--- a/fs/compat_binfmt_elf.c
60270+++ b/fs/compat_binfmt_elf.c
60271@@ -30,11 +30,13 @@
60272 #undef elf_phdr
60273 #undef elf_shdr
60274 #undef elf_note
60275+#undef elf_dyn
60276 #undef elf_addr_t
60277 #define elfhdr elf32_hdr
60278 #define elf_phdr elf32_phdr
60279 #define elf_shdr elf32_shdr
60280 #define elf_note elf32_note
60281+#define elf_dyn Elf32_Dyn
60282 #define elf_addr_t Elf32_Addr
60283
60284 /*
60285diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
60286index afec645..9c65620 100644
60287--- a/fs/compat_ioctl.c
60288+++ b/fs/compat_ioctl.c
60289@@ -621,7 +621,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
60290 return -EFAULT;
60291 if (__get_user(udata, &ss32->iomem_base))
60292 return -EFAULT;
60293- ss.iomem_base = compat_ptr(udata);
60294+ ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
60295 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
60296 __get_user(ss.port_high, &ss32->port_high))
60297 return -EFAULT;
60298@@ -703,8 +703,8 @@ static int do_i2c_rdwr_ioctl(unsigned int fd, unsigned int cmd,
60299 for (i = 0; i < nmsgs; i++) {
60300 if (copy_in_user(&tmsgs[i].addr, &umsgs[i].addr, 3*sizeof(u16)))
60301 return -EFAULT;
60302- if (get_user(datap, &umsgs[i].buf) ||
60303- put_user(compat_ptr(datap), &tmsgs[i].buf))
60304+ if (get_user(datap, (compat_caddr_t __user *)&umsgs[i].buf) ||
60305+ put_user(compat_ptr(datap), (u8 __user * __user *)&tmsgs[i].buf))
60306 return -EFAULT;
60307 }
60308 return sys_ioctl(fd, cmd, (unsigned long)tdata);
60309@@ -797,7 +797,7 @@ static int compat_ioctl_preallocate(struct file *file,
60310 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
60311 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
60312 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
60313- copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
60314+ copy_in_user(p->l_pad, p32->l_pad, 4*sizeof(u32)))
60315 return -EFAULT;
60316
60317 return ioctl_preallocate(file, p);
60318@@ -1618,8 +1618,8 @@ COMPAT_SYSCALL_DEFINE3(ioctl, unsigned int, fd, unsigned int, cmd,
60319 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
60320 {
60321 unsigned int a, b;
60322- a = *(unsigned int *)p;
60323- b = *(unsigned int *)q;
60324+ a = *(const unsigned int *)p;
60325+ b = *(const unsigned int *)q;
60326 if (a > b)
60327 return 1;
60328 if (a < b)
60329diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
60330index 668dcab..daebcd6 100644
60331--- a/fs/configfs/dir.c
60332+++ b/fs/configfs/dir.c
60333@@ -1548,7 +1548,8 @@ static int configfs_readdir(struct file *file, struct dir_context *ctx)
60334 }
60335 for (p = q->next; p != &parent_sd->s_children; p = p->next) {
60336 struct configfs_dirent *next;
60337- const char *name;
60338+ const unsigned char * name;
60339+ char d_name[sizeof(next->s_dentry->d_iname)];
60340 int len;
60341 struct inode *inode = NULL;
60342
60343@@ -1557,7 +1558,12 @@ static int configfs_readdir(struct file *file, struct dir_context *ctx)
60344 continue;
60345
60346 name = configfs_get_name(next);
60347- len = strlen(name);
60348+ if (next->s_dentry && name == next->s_dentry->d_iname) {
60349+ len = next->s_dentry->d_name.len;
60350+ memcpy(d_name, name, len);
60351+ name = d_name;
60352+ } else
60353+ len = strlen(name);
60354
60355 /*
60356 * We'll have a dentry and an inode for
60357diff --git a/fs/coredump.c b/fs/coredump.c
60358index b5c86ff..0dac262 100644
60359--- a/fs/coredump.c
60360+++ b/fs/coredump.c
60361@@ -450,8 +450,8 @@ static void wait_for_dump_helpers(struct file *file)
60362 struct pipe_inode_info *pipe = file->private_data;
60363
60364 pipe_lock(pipe);
60365- pipe->readers++;
60366- pipe->writers--;
60367+ atomic_inc(&pipe->readers);
60368+ atomic_dec(&pipe->writers);
60369 wake_up_interruptible_sync(&pipe->wait);
60370 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
60371 pipe_unlock(pipe);
60372@@ -460,11 +460,11 @@ static void wait_for_dump_helpers(struct file *file)
60373 * We actually want wait_event_freezable() but then we need
60374 * to clear TIF_SIGPENDING and improve dump_interrupted().
60375 */
60376- wait_event_interruptible(pipe->wait, pipe->readers == 1);
60377+ wait_event_interruptible(pipe->wait, atomic_read(&pipe->readers) == 1);
60378
60379 pipe_lock(pipe);
60380- pipe->readers--;
60381- pipe->writers++;
60382+ atomic_dec(&pipe->readers);
60383+ atomic_inc(&pipe->writers);
60384 pipe_unlock(pipe);
60385 }
60386
60387@@ -511,7 +511,9 @@ void do_coredump(const siginfo_t *siginfo)
60388 struct files_struct *displaced;
60389 bool need_nonrelative = false;
60390 bool core_dumped = false;
60391- static atomic_t core_dump_count = ATOMIC_INIT(0);
60392+ static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
60393+ long signr = siginfo->si_signo;
60394+ int dumpable;
60395 struct coredump_params cprm = {
60396 .siginfo = siginfo,
60397 .regs = signal_pt_regs(),
60398@@ -524,12 +526,17 @@ void do_coredump(const siginfo_t *siginfo)
60399 .mm_flags = mm->flags,
60400 };
60401
60402- audit_core_dumps(siginfo->si_signo);
60403+ audit_core_dumps(signr);
60404+
60405+ dumpable = __get_dumpable(cprm.mm_flags);
60406+
60407+ if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
60408+ gr_handle_brute_attach(dumpable);
60409
60410 binfmt = mm->binfmt;
60411 if (!binfmt || !binfmt->core_dump)
60412 goto fail;
60413- if (!__get_dumpable(cprm.mm_flags))
60414+ if (!dumpable)
60415 goto fail;
60416
60417 cred = prepare_creds();
60418@@ -548,7 +555,7 @@ void do_coredump(const siginfo_t *siginfo)
60419 need_nonrelative = true;
60420 }
60421
60422- retval = coredump_wait(siginfo->si_signo, &core_state);
60423+ retval = coredump_wait(signr, &core_state);
60424 if (retval < 0)
60425 goto fail_creds;
60426
60427@@ -591,7 +598,7 @@ void do_coredump(const siginfo_t *siginfo)
60428 }
60429 cprm.limit = RLIM_INFINITY;
60430
60431- dump_count = atomic_inc_return(&core_dump_count);
60432+ dump_count = atomic_inc_return_unchecked(&core_dump_count);
60433 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
60434 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
60435 task_tgid_vnr(current), current->comm);
60436@@ -623,6 +630,8 @@ void do_coredump(const siginfo_t *siginfo)
60437 } else {
60438 struct inode *inode;
60439
60440+ gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
60441+
60442 if (cprm.limit < binfmt->min_coredump)
60443 goto fail_unlock;
60444
60445@@ -681,7 +690,7 @@ close_fail:
60446 filp_close(cprm.file, NULL);
60447 fail_dropcount:
60448 if (ispipe)
60449- atomic_dec(&core_dump_count);
60450+ atomic_dec_unchecked(&core_dump_count);
60451 fail_unlock:
60452 kfree(cn.corename);
60453 coredump_finish(mm, core_dumped);
60454@@ -702,6 +711,8 @@ int dump_emit(struct coredump_params *cprm, const void *addr, int nr)
60455 struct file *file = cprm->file;
60456 loff_t pos = file->f_pos;
60457 ssize_t n;
60458+
60459+ gr_learn_resource(current, RLIMIT_CORE, cprm->written + nr, 1);
60460 if (cprm->written + nr > cprm->limit)
60461 return 0;
60462 while (nr) {
60463diff --git a/fs/dcache.c b/fs/dcache.c
60464index 03dca3c..f66c622 100644
60465--- a/fs/dcache.c
60466+++ b/fs/dcache.c
60467@@ -508,7 +508,7 @@ static void __dentry_kill(struct dentry *dentry)
60468 * dentry_iput drops the locks, at which point nobody (except
60469 * transient RCU lookups) can reach this dentry.
60470 */
60471- BUG_ON((int)dentry->d_lockref.count > 0);
60472+ BUG_ON((int)__lockref_read(&dentry->d_lockref) > 0);
60473 this_cpu_dec(nr_dentry);
60474 if (dentry->d_op && dentry->d_op->d_release)
60475 dentry->d_op->d_release(dentry);
60476@@ -561,7 +561,7 @@ static inline struct dentry *lock_parent(struct dentry *dentry)
60477 struct dentry *parent = dentry->d_parent;
60478 if (IS_ROOT(dentry))
60479 return NULL;
60480- if (unlikely((int)dentry->d_lockref.count < 0))
60481+ if (unlikely((int)__lockref_read(&dentry->d_lockref) < 0))
60482 return NULL;
60483 if (likely(spin_trylock(&parent->d_lock)))
60484 return parent;
60485@@ -638,7 +638,7 @@ repeat:
60486 dentry->d_flags |= DCACHE_REFERENCED;
60487 dentry_lru_add(dentry);
60488
60489- dentry->d_lockref.count--;
60490+ __lockref_dec(&dentry->d_lockref);
60491 spin_unlock(&dentry->d_lock);
60492 return;
60493
60494@@ -653,7 +653,7 @@ EXPORT_SYMBOL(dput);
60495 /* This must be called with d_lock held */
60496 static inline void __dget_dlock(struct dentry *dentry)
60497 {
60498- dentry->d_lockref.count++;
60499+ __lockref_inc(&dentry->d_lockref);
60500 }
60501
60502 static inline void __dget(struct dentry *dentry)
60503@@ -694,8 +694,8 @@ repeat:
60504 goto repeat;
60505 }
60506 rcu_read_unlock();
60507- BUG_ON(!ret->d_lockref.count);
60508- ret->d_lockref.count++;
60509+ BUG_ON(!__lockref_read(&ret->d_lockref));
60510+ __lockref_inc(&ret->d_lockref);
60511 spin_unlock(&ret->d_lock);
60512 return ret;
60513 }
60514@@ -773,9 +773,9 @@ restart:
60515 spin_lock(&inode->i_lock);
60516 hlist_for_each_entry(dentry, &inode->i_dentry, d_u.d_alias) {
60517 spin_lock(&dentry->d_lock);
60518- if (!dentry->d_lockref.count) {
60519+ if (!__lockref_read(&dentry->d_lockref)) {
60520 struct dentry *parent = lock_parent(dentry);
60521- if (likely(!dentry->d_lockref.count)) {
60522+ if (likely(!__lockref_read(&dentry->d_lockref))) {
60523 __dentry_kill(dentry);
60524 dput(parent);
60525 goto restart;
60526@@ -810,7 +810,7 @@ static void shrink_dentry_list(struct list_head *list)
60527 * We found an inuse dentry which was not removed from
60528 * the LRU because of laziness during lookup. Do not free it.
60529 */
60530- if ((int)dentry->d_lockref.count > 0) {
60531+ if ((int)__lockref_read(&dentry->d_lockref) > 0) {
60532 spin_unlock(&dentry->d_lock);
60533 if (parent)
60534 spin_unlock(&parent->d_lock);
60535@@ -848,8 +848,8 @@ static void shrink_dentry_list(struct list_head *list)
60536 dentry = parent;
60537 while (dentry && !lockref_put_or_lock(&dentry->d_lockref)) {
60538 parent = lock_parent(dentry);
60539- if (dentry->d_lockref.count != 1) {
60540- dentry->d_lockref.count--;
60541+ if (__lockref_read(&dentry->d_lockref) != 1) {
60542+ __lockref_inc(&dentry->d_lockref);
60543 spin_unlock(&dentry->d_lock);
60544 if (parent)
60545 spin_unlock(&parent->d_lock);
60546@@ -889,7 +889,7 @@ dentry_lru_isolate(struct list_head *item, spinlock_t *lru_lock, void *arg)
60547 * counts, just remove them from the LRU. Otherwise give them
60548 * another pass through the LRU.
60549 */
60550- if (dentry->d_lockref.count) {
60551+ if (__lockref_read(&dentry->d_lockref) > 0) {
60552 d_lru_isolate(dentry);
60553 spin_unlock(&dentry->d_lock);
60554 return LRU_REMOVED;
60555@@ -1225,7 +1225,7 @@ static enum d_walk_ret select_collect(void *_data, struct dentry *dentry)
60556 } else {
60557 if (dentry->d_flags & DCACHE_LRU_LIST)
60558 d_lru_del(dentry);
60559- if (!dentry->d_lockref.count) {
60560+ if (!__lockref_read(&dentry->d_lockref)) {
60561 d_shrink_add(dentry, &data->dispose);
60562 data->found++;
60563 }
60564@@ -1273,7 +1273,7 @@ static enum d_walk_ret umount_check(void *_data, struct dentry *dentry)
60565 return D_WALK_CONTINUE;
60566
60567 /* root with refcount 1 is fine */
60568- if (dentry == _data && dentry->d_lockref.count == 1)
60569+ if (dentry == _data && __lockref_read(&dentry->d_lockref) == 1)
60570 return D_WALK_CONTINUE;
60571
60572 printk(KERN_ERR "BUG: Dentry %p{i=%lx,n=%pd} "
60573@@ -1282,7 +1282,7 @@ static enum d_walk_ret umount_check(void *_data, struct dentry *dentry)
60574 dentry->d_inode ?
60575 dentry->d_inode->i_ino : 0UL,
60576 dentry,
60577- dentry->d_lockref.count,
60578+ __lockref_read(&dentry->d_lockref),
60579 dentry->d_sb->s_type->name,
60580 dentry->d_sb->s_id);
60581 WARN_ON(1);
60582@@ -1423,7 +1423,7 @@ struct dentry *__d_alloc(struct super_block *sb, const struct qstr *name)
60583 dentry->d_iname[DNAME_INLINE_LEN-1] = 0;
60584 if (name->len > DNAME_INLINE_LEN-1) {
60585 size_t size = offsetof(struct external_name, name[1]);
60586- struct external_name *p = kmalloc(size + name->len, GFP_KERNEL);
60587+ struct external_name *p = kmalloc(round_up(size + name->len, sizeof(unsigned long)), GFP_KERNEL);
60588 if (!p) {
60589 kmem_cache_free(dentry_cache, dentry);
60590 return NULL;
60591@@ -1443,7 +1443,7 @@ struct dentry *__d_alloc(struct super_block *sb, const struct qstr *name)
60592 smp_wmb();
60593 dentry->d_name.name = dname;
60594
60595- dentry->d_lockref.count = 1;
60596+ __lockref_set(&dentry->d_lockref, 1);
60597 dentry->d_flags = 0;
60598 spin_lock_init(&dentry->d_lock);
60599 seqcount_init(&dentry->d_seq);
60600@@ -2183,7 +2183,7 @@ struct dentry *__d_lookup(const struct dentry *parent, const struct qstr *name)
60601 goto next;
60602 }
60603
60604- dentry->d_lockref.count++;
60605+ __lockref_inc(&dentry->d_lockref);
60606 found = dentry;
60607 spin_unlock(&dentry->d_lock);
60608 break;
60609@@ -2282,7 +2282,7 @@ again:
60610 spin_lock(&dentry->d_lock);
60611 inode = dentry->d_inode;
60612 isdir = S_ISDIR(inode->i_mode);
60613- if (dentry->d_lockref.count == 1) {
60614+ if (__lockref_read(&dentry->d_lockref) == 1) {
60615 if (!spin_trylock(&inode->i_lock)) {
60616 spin_unlock(&dentry->d_lock);
60617 cpu_relax();
60618@@ -3308,7 +3308,7 @@ static enum d_walk_ret d_genocide_kill(void *data, struct dentry *dentry)
60619
60620 if (!(dentry->d_flags & DCACHE_GENOCIDE)) {
60621 dentry->d_flags |= DCACHE_GENOCIDE;
60622- dentry->d_lockref.count--;
60623+ __lockref_dec(&dentry->d_lockref);
60624 }
60625 }
60626 return D_WALK_CONTINUE;
60627@@ -3424,7 +3424,8 @@ void __init vfs_caches_init(unsigned long mempages)
60628 mempages -= reserve;
60629
60630 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
60631- SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
60632+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY|
60633+ SLAB_NO_SANITIZE, NULL);
60634
60635 dcache_init();
60636 inode_init();
60637diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
60638index 05f2960..b012481 100644
60639--- a/fs/debugfs/inode.c
60640+++ b/fs/debugfs/inode.c
60641@@ -416,7 +416,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
60642 */
60643 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
60644 {
60645+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
60646+ return __create_file(name, S_IFDIR | S_IRWXU,
60647+#else
60648 return __create_file(name, S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
60649+#endif
60650 parent, NULL, NULL);
60651 }
60652 EXPORT_SYMBOL_GPL(debugfs_create_dir);
60653diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
60654index 1686dc2..9611c50 100644
60655--- a/fs/ecryptfs/inode.c
60656+++ b/fs/ecryptfs/inode.c
60657@@ -664,7 +664,7 @@ static char *ecryptfs_readlink_lower(struct dentry *dentry, size_t *bufsiz)
60658 old_fs = get_fs();
60659 set_fs(get_ds());
60660 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
60661- (char __user *)lower_buf,
60662+ (char __force_user *)lower_buf,
60663 PATH_MAX);
60664 set_fs(old_fs);
60665 if (rc < 0)
60666diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
60667index e4141f2..d8263e8 100644
60668--- a/fs/ecryptfs/miscdev.c
60669+++ b/fs/ecryptfs/miscdev.c
60670@@ -304,7 +304,7 @@ check_list:
60671 goto out_unlock_msg_ctx;
60672 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
60673 if (msg_ctx->msg) {
60674- if (copy_to_user(&buf[i], packet_length, packet_length_size))
60675+ if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
60676 goto out_unlock_msg_ctx;
60677 i += packet_length_size;
60678 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
60679diff --git a/fs/exec.c b/fs/exec.c
60680index 7302b75..b917171 100644
60681--- a/fs/exec.c
60682+++ b/fs/exec.c
60683@@ -56,8 +56,20 @@
60684 #include <linux/pipe_fs_i.h>
60685 #include <linux/oom.h>
60686 #include <linux/compat.h>
60687+#include <linux/random.h>
60688+#include <linux/seq_file.h>
60689+#include <linux/coredump.h>
60690+#include <linux/mman.h>
60691+
60692+#ifdef CONFIG_PAX_REFCOUNT
60693+#include <linux/kallsyms.h>
60694+#include <linux/kdebug.h>
60695+#endif
60696+
60697+#include <trace/events/fs.h>
60698
60699 #include <asm/uaccess.h>
60700+#include <asm/sections.h>
60701 #include <asm/mmu_context.h>
60702 #include <asm/tlb.h>
60703
60704@@ -66,19 +78,34 @@
60705
60706 #include <trace/events/sched.h>
60707
60708+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
60709+void __weak pax_set_initial_flags(struct linux_binprm *bprm)
60710+{
60711+ 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");
60712+}
60713+#endif
60714+
60715+#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
60716+void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
60717+EXPORT_SYMBOL(pax_set_initial_flags_func);
60718+#endif
60719+
60720 int suid_dumpable = 0;
60721
60722 static LIST_HEAD(formats);
60723 static DEFINE_RWLOCK(binfmt_lock);
60724
60725+extern int gr_process_kernel_exec_ban(void);
60726+extern int gr_process_suid_exec_ban(const struct linux_binprm *bprm);
60727+
60728 void __register_binfmt(struct linux_binfmt * fmt, int insert)
60729 {
60730 BUG_ON(!fmt);
60731 if (WARN_ON(!fmt->load_binary))
60732 return;
60733 write_lock(&binfmt_lock);
60734- insert ? list_add(&fmt->lh, &formats) :
60735- list_add_tail(&fmt->lh, &formats);
60736+ insert ? pax_list_add((struct list_head *)&fmt->lh, &formats) :
60737+ pax_list_add_tail((struct list_head *)&fmt->lh, &formats);
60738 write_unlock(&binfmt_lock);
60739 }
60740
60741@@ -87,7 +114,7 @@ EXPORT_SYMBOL(__register_binfmt);
60742 void unregister_binfmt(struct linux_binfmt * fmt)
60743 {
60744 write_lock(&binfmt_lock);
60745- list_del(&fmt->lh);
60746+ pax_list_del((struct list_head *)&fmt->lh);
60747 write_unlock(&binfmt_lock);
60748 }
60749
60750@@ -183,18 +210,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
60751 int write)
60752 {
60753 struct page *page;
60754- int ret;
60755
60756-#ifdef CONFIG_STACK_GROWSUP
60757- if (write) {
60758- ret = expand_downwards(bprm->vma, pos);
60759- if (ret < 0)
60760- return NULL;
60761- }
60762-#endif
60763- ret = get_user_pages(current, bprm->mm, pos,
60764- 1, write, 1, &page, NULL);
60765- if (ret <= 0)
60766+ if (0 > expand_downwards(bprm->vma, pos))
60767+ return NULL;
60768+ if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
60769 return NULL;
60770
60771 if (write) {
60772@@ -210,6 +229,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
60773 if (size <= ARG_MAX)
60774 return page;
60775
60776+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60777+ // only allow 512KB for argv+env on suid/sgid binaries
60778+ // to prevent easy ASLR exhaustion
60779+ if (((!uid_eq(bprm->cred->euid, current_euid())) ||
60780+ (!gid_eq(bprm->cred->egid, current_egid()))) &&
60781+ (size > (512 * 1024))) {
60782+ put_page(page);
60783+ return NULL;
60784+ }
60785+#endif
60786+
60787 /*
60788 * Limit to 1/4-th the stack size for the argv+env strings.
60789 * This ensures that:
60790@@ -269,6 +299,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
60791 vma->vm_end = STACK_TOP_MAX;
60792 vma->vm_start = vma->vm_end - PAGE_SIZE;
60793 vma->vm_flags = VM_SOFTDIRTY | VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
60794+
60795+#ifdef CONFIG_PAX_SEGMEXEC
60796+ vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
60797+#endif
60798+
60799 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
60800 INIT_LIST_HEAD(&vma->anon_vma_chain);
60801
60802@@ -279,6 +314,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
60803 mm->stack_vm = mm->total_vm = 1;
60804 up_write(&mm->mmap_sem);
60805 bprm->p = vma->vm_end - sizeof(void *);
60806+
60807+#ifdef CONFIG_PAX_RANDUSTACK
60808+ if (randomize_va_space)
60809+ bprm->p ^= prandom_u32() & ~PAGE_MASK;
60810+#endif
60811+
60812 return 0;
60813 err:
60814 up_write(&mm->mmap_sem);
60815@@ -395,7 +436,7 @@ struct user_arg_ptr {
60816 } ptr;
60817 };
60818
60819-static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
60820+const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
60821 {
60822 const char __user *native;
60823
60824@@ -404,14 +445,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
60825 compat_uptr_t compat;
60826
60827 if (get_user(compat, argv.ptr.compat + nr))
60828- return ERR_PTR(-EFAULT);
60829+ return (const char __force_user *)ERR_PTR(-EFAULT);
60830
60831 return compat_ptr(compat);
60832 }
60833 #endif
60834
60835 if (get_user(native, argv.ptr.native + nr))
60836- return ERR_PTR(-EFAULT);
60837+ return (const char __force_user *)ERR_PTR(-EFAULT);
60838
60839 return native;
60840 }
60841@@ -430,7 +471,7 @@ static int count(struct user_arg_ptr argv, int max)
60842 if (!p)
60843 break;
60844
60845- if (IS_ERR(p))
60846+ if (IS_ERR((const char __force_kernel *)p))
60847 return -EFAULT;
60848
60849 if (i >= max)
60850@@ -465,7 +506,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
60851
60852 ret = -EFAULT;
60853 str = get_user_arg_ptr(argv, argc);
60854- if (IS_ERR(str))
60855+ if (IS_ERR((const char __force_kernel *)str))
60856 goto out;
60857
60858 len = strnlen_user(str, MAX_ARG_STRLEN);
60859@@ -547,7 +588,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
60860 int r;
60861 mm_segment_t oldfs = get_fs();
60862 struct user_arg_ptr argv = {
60863- .ptr.native = (const char __user *const __user *)__argv,
60864+ .ptr.native = (const char __user * const __force_user *)__argv,
60865 };
60866
60867 set_fs(KERNEL_DS);
60868@@ -582,7 +623,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
60869 unsigned long new_end = old_end - shift;
60870 struct mmu_gather tlb;
60871
60872- BUG_ON(new_start > new_end);
60873+ if (new_start >= new_end || new_start < mmap_min_addr)
60874+ return -ENOMEM;
60875
60876 /*
60877 * ensure there are no vmas between where we want to go
60878@@ -591,6 +633,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
60879 if (vma != find_vma(mm, new_start))
60880 return -EFAULT;
60881
60882+#ifdef CONFIG_PAX_SEGMEXEC
60883+ BUG_ON(pax_find_mirror_vma(vma));
60884+#endif
60885+
60886 /*
60887 * cover the whole range: [new_start, old_end)
60888 */
60889@@ -671,10 +717,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
60890 stack_top = arch_align_stack(stack_top);
60891 stack_top = PAGE_ALIGN(stack_top);
60892
60893- if (unlikely(stack_top < mmap_min_addr) ||
60894- unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
60895- return -ENOMEM;
60896-
60897 stack_shift = vma->vm_end - stack_top;
60898
60899 bprm->p -= stack_shift;
60900@@ -686,8 +728,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
60901 bprm->exec -= stack_shift;
60902
60903 down_write(&mm->mmap_sem);
60904+
60905+ /* Move stack pages down in memory. */
60906+ if (stack_shift) {
60907+ ret = shift_arg_pages(vma, stack_shift);
60908+ if (ret)
60909+ goto out_unlock;
60910+ }
60911+
60912 vm_flags = VM_STACK_FLAGS;
60913
60914+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
60915+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
60916+ vm_flags &= ~VM_EXEC;
60917+
60918+#ifdef CONFIG_PAX_MPROTECT
60919+ if (mm->pax_flags & MF_PAX_MPROTECT)
60920+ vm_flags &= ~VM_MAYEXEC;
60921+#endif
60922+
60923+ }
60924+#endif
60925+
60926 /*
60927 * Adjust stack execute permissions; explicitly enable for
60928 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
60929@@ -706,13 +768,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
60930 goto out_unlock;
60931 BUG_ON(prev != vma);
60932
60933- /* Move stack pages down in memory. */
60934- if (stack_shift) {
60935- ret = shift_arg_pages(vma, stack_shift);
60936- if (ret)
60937- goto out_unlock;
60938- }
60939-
60940 /* mprotect_fixup is overkill to remove the temporary stack flags */
60941 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
60942
60943@@ -736,6 +791,27 @@ int setup_arg_pages(struct linux_binprm *bprm,
60944 #endif
60945 current->mm->start_stack = bprm->p;
60946 ret = expand_stack(vma, stack_base);
60947+
60948+#if !defined(CONFIG_STACK_GROWSUP) && defined(CONFIG_PAX_RANDMMAP)
60949+ if (!ret && (mm->pax_flags & MF_PAX_RANDMMAP) && STACK_TOP <= 0xFFFFFFFFU && STACK_TOP > vma->vm_end) {
60950+ unsigned long size;
60951+ vm_flags_t vm_flags;
60952+
60953+ size = STACK_TOP - vma->vm_end;
60954+ vm_flags = VM_NONE | VM_DONTEXPAND | VM_DONTDUMP;
60955+
60956+ ret = vma->vm_end != mmap_region(NULL, vma->vm_end, size, vm_flags, 0);
60957+
60958+#ifdef CONFIG_X86
60959+ if (!ret) {
60960+ size = PAGE_SIZE + mmap_min_addr + ((mm->delta_mmap ^ mm->delta_stack) & (0xFFUL << PAGE_SHIFT));
60961+ ret = 0 != mmap_region(NULL, 0, PAGE_ALIGN(size), vm_flags, 0);
60962+ }
60963+#endif
60964+
60965+ }
60966+#endif
60967+
60968 if (ret)
60969 ret = -EFAULT;
60970
60971@@ -771,6 +847,8 @@ static struct file *do_open_exec(struct filename *name)
60972
60973 fsnotify_open(file);
60974
60975+ trace_open_exec(name->name);
60976+
60977 err = deny_write_access(file);
60978 if (err)
60979 goto exit;
60980@@ -800,7 +878,7 @@ int kernel_read(struct file *file, loff_t offset,
60981 old_fs = get_fs();
60982 set_fs(get_ds());
60983 /* The cast to a user pointer is valid due to the set_fs() */
60984- result = vfs_read(file, (void __user *)addr, count, &pos);
60985+ result = vfs_read(file, (void __force_user *)addr, count, &pos);
60986 set_fs(old_fs);
60987 return result;
60988 }
60989@@ -845,6 +923,7 @@ static int exec_mmap(struct mm_struct *mm)
60990 tsk->mm = mm;
60991 tsk->active_mm = mm;
60992 activate_mm(active_mm, mm);
60993+ populate_stack();
60994 tsk->mm->vmacache_seqnum = 0;
60995 vmacache_flush(tsk);
60996 task_unlock(tsk);
60997@@ -1243,7 +1322,7 @@ static void check_unsafe_exec(struct linux_binprm *bprm)
60998 }
60999 rcu_read_unlock();
61000
61001- if (p->fs->users > n_fs)
61002+ if (atomic_read(&p->fs->users) > n_fs)
61003 bprm->unsafe |= LSM_UNSAFE_SHARE;
61004 else
61005 p->fs->in_exec = 1;
61006@@ -1424,6 +1503,31 @@ static int exec_binprm(struct linux_binprm *bprm)
61007 return ret;
61008 }
61009
61010+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
61011+static DEFINE_PER_CPU(u64, exec_counter);
61012+static int __init init_exec_counters(void)
61013+{
61014+ unsigned int cpu;
61015+
61016+ for_each_possible_cpu(cpu) {
61017+ per_cpu(exec_counter, cpu) = (u64)cpu;
61018+ }
61019+
61020+ return 0;
61021+}
61022+early_initcall(init_exec_counters);
61023+static inline void increment_exec_counter(void)
61024+{
61025+ BUILD_BUG_ON(NR_CPUS > (1 << 16));
61026+ current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
61027+}
61028+#else
61029+static inline void increment_exec_counter(void) {}
61030+#endif
61031+
61032+extern void gr_handle_exec_args(struct linux_binprm *bprm,
61033+ struct user_arg_ptr argv);
61034+
61035 /*
61036 * sys_execve() executes a new program.
61037 */
61038@@ -1431,6 +1535,11 @@ static int do_execve_common(struct filename *filename,
61039 struct user_arg_ptr argv,
61040 struct user_arg_ptr envp)
61041 {
61042+#ifdef CONFIG_GRKERNSEC
61043+ struct file *old_exec_file;
61044+ struct acl_subject_label *old_acl;
61045+ struct rlimit old_rlim[RLIM_NLIMITS];
61046+#endif
61047 struct linux_binprm *bprm;
61048 struct file *file;
61049 struct files_struct *displaced;
61050@@ -1439,6 +1548,8 @@ static int do_execve_common(struct filename *filename,
61051 if (IS_ERR(filename))
61052 return PTR_ERR(filename);
61053
61054+ gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current_user()->processes), 1);
61055+
61056 /*
61057 * We move the actual failure in case of RLIMIT_NPROC excess from
61058 * set*uid() to execve() because too many poorly written programs
61059@@ -1476,11 +1587,21 @@ static int do_execve_common(struct filename *filename,
61060 if (IS_ERR(file))
61061 goto out_unmark;
61062
61063+ if (gr_ptrace_readexec(file, bprm->unsafe)) {
61064+ retval = -EPERM;
61065+ goto out_unmark;
61066+ }
61067+
61068 sched_exec();
61069
61070 bprm->file = file;
61071 bprm->filename = bprm->interp = filename->name;
61072
61073+ if (!gr_acl_handle_execve(file->f_path.dentry, file->f_path.mnt)) {
61074+ retval = -EACCES;
61075+ goto out_unmark;
61076+ }
61077+
61078 retval = bprm_mm_init(bprm);
61079 if (retval)
61080 goto out_unmark;
61081@@ -1497,24 +1618,70 @@ static int do_execve_common(struct filename *filename,
61082 if (retval < 0)
61083 goto out;
61084
61085+#ifdef CONFIG_GRKERNSEC
61086+ old_acl = current->acl;
61087+ memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
61088+ old_exec_file = current->exec_file;
61089+ get_file(file);
61090+ current->exec_file = file;
61091+#endif
61092+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
61093+ /* limit suid stack to 8MB
61094+ * we saved the old limits above and will restore them if this exec fails
61095+ */
61096+ if (((!uid_eq(bprm->cred->euid, current_euid())) || (!gid_eq(bprm->cred->egid, current_egid()))) &&
61097+ (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
61098+ current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
61099+#endif
61100+
61101+ if (gr_process_kernel_exec_ban() || gr_process_suid_exec_ban(bprm)) {
61102+ retval = -EPERM;
61103+ goto out_fail;
61104+ }
61105+
61106+ if (!gr_tpe_allow(file)) {
61107+ retval = -EACCES;
61108+ goto out_fail;
61109+ }
61110+
61111+ if (gr_check_crash_exec(file)) {
61112+ retval = -EACCES;
61113+ goto out_fail;
61114+ }
61115+
61116+ retval = gr_set_proc_label(file->f_path.dentry, file->f_path.mnt,
61117+ bprm->unsafe);
61118+ if (retval < 0)
61119+ goto out_fail;
61120+
61121 retval = copy_strings_kernel(1, &bprm->filename, bprm);
61122 if (retval < 0)
61123- goto out;
61124+ goto out_fail;
61125
61126 bprm->exec = bprm->p;
61127 retval = copy_strings(bprm->envc, envp, bprm);
61128 if (retval < 0)
61129- goto out;
61130+ goto out_fail;
61131
61132 retval = copy_strings(bprm->argc, argv, bprm);
61133 if (retval < 0)
61134- goto out;
61135+ goto out_fail;
61136+
61137+ gr_log_chroot_exec(file->f_path.dentry, file->f_path.mnt);
61138+
61139+ gr_handle_exec_args(bprm, argv);
61140
61141 retval = exec_binprm(bprm);
61142 if (retval < 0)
61143- goto out;
61144+ goto out_fail;
61145+#ifdef CONFIG_GRKERNSEC
61146+ if (old_exec_file)
61147+ fput(old_exec_file);
61148+#endif
61149
61150 /* execve succeeded */
61151+
61152+ increment_exec_counter();
61153 current->fs->in_exec = 0;
61154 current->in_execve = 0;
61155 acct_update_integrals(current);
61156@@ -1525,6 +1692,14 @@ static int do_execve_common(struct filename *filename,
61157 put_files_struct(displaced);
61158 return retval;
61159
61160+out_fail:
61161+#ifdef CONFIG_GRKERNSEC
61162+ current->acl = old_acl;
61163+ memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
61164+ fput(current->exec_file);
61165+ current->exec_file = old_exec_file;
61166+#endif
61167+
61168 out:
61169 if (bprm->mm) {
61170 acct_arg_size(bprm, 0);
61171@@ -1616,3 +1791,312 @@ COMPAT_SYSCALL_DEFINE3(execve, const char __user *, filename,
61172 return compat_do_execve(getname(filename), argv, envp);
61173 }
61174 #endif
61175+
61176+int pax_check_flags(unsigned long *flags)
61177+{
61178+ int retval = 0;
61179+
61180+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
61181+ if (*flags & MF_PAX_SEGMEXEC)
61182+ {
61183+ *flags &= ~MF_PAX_SEGMEXEC;
61184+ retval = -EINVAL;
61185+ }
61186+#endif
61187+
61188+ if ((*flags & MF_PAX_PAGEEXEC)
61189+
61190+#ifdef CONFIG_PAX_PAGEEXEC
61191+ && (*flags & MF_PAX_SEGMEXEC)
61192+#endif
61193+
61194+ )
61195+ {
61196+ *flags &= ~MF_PAX_PAGEEXEC;
61197+ retval = -EINVAL;
61198+ }
61199+
61200+ if ((*flags & MF_PAX_MPROTECT)
61201+
61202+#ifdef CONFIG_PAX_MPROTECT
61203+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
61204+#endif
61205+
61206+ )
61207+ {
61208+ *flags &= ~MF_PAX_MPROTECT;
61209+ retval = -EINVAL;
61210+ }
61211+
61212+ if ((*flags & MF_PAX_EMUTRAMP)
61213+
61214+#ifdef CONFIG_PAX_EMUTRAMP
61215+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
61216+#endif
61217+
61218+ )
61219+ {
61220+ *flags &= ~MF_PAX_EMUTRAMP;
61221+ retval = -EINVAL;
61222+ }
61223+
61224+ return retval;
61225+}
61226+
61227+EXPORT_SYMBOL(pax_check_flags);
61228+
61229+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
61230+char *pax_get_path(const struct path *path, char *buf, int buflen)
61231+{
61232+ char *pathname = d_path(path, buf, buflen);
61233+
61234+ if (IS_ERR(pathname))
61235+ goto toolong;
61236+
61237+ pathname = mangle_path(buf, pathname, "\t\n\\");
61238+ if (!pathname)
61239+ goto toolong;
61240+
61241+ *pathname = 0;
61242+ return buf;
61243+
61244+toolong:
61245+ return "<path too long>";
61246+}
61247+EXPORT_SYMBOL(pax_get_path);
61248+
61249+void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
61250+{
61251+ struct task_struct *tsk = current;
61252+ struct mm_struct *mm = current->mm;
61253+ char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
61254+ char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
61255+ char *path_exec = NULL;
61256+ char *path_fault = NULL;
61257+ unsigned long start = 0UL, end = 0UL, offset = 0UL;
61258+ siginfo_t info = { };
61259+
61260+ if (buffer_exec && buffer_fault) {
61261+ struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
61262+
61263+ down_read(&mm->mmap_sem);
61264+ vma = mm->mmap;
61265+ while (vma && (!vma_exec || !vma_fault)) {
61266+ if (vma->vm_file && mm->exe_file == vma->vm_file && (vma->vm_flags & VM_EXEC))
61267+ vma_exec = vma;
61268+ if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
61269+ vma_fault = vma;
61270+ vma = vma->vm_next;
61271+ }
61272+ if (vma_exec)
61273+ path_exec = pax_get_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
61274+ if (vma_fault) {
61275+ start = vma_fault->vm_start;
61276+ end = vma_fault->vm_end;
61277+ offset = vma_fault->vm_pgoff << PAGE_SHIFT;
61278+ if (vma_fault->vm_file)
61279+ path_fault = pax_get_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
61280+ else if ((unsigned long)pc >= mm->start_brk && (unsigned long)pc < mm->brk)
61281+ path_fault = "<heap>";
61282+ else if (vma_fault->vm_flags & (VM_GROWSDOWN | VM_GROWSUP))
61283+ path_fault = "<stack>";
61284+ else
61285+ path_fault = "<anonymous mapping>";
61286+ }
61287+ up_read(&mm->mmap_sem);
61288+ }
61289+ if (tsk->signal->curr_ip)
61290+ printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
61291+ else
61292+ printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
61293+ 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),
61294+ from_kuid_munged(&init_user_ns, task_uid(tsk)), from_kuid_munged(&init_user_ns, task_euid(tsk)), pc, sp);
61295+ free_page((unsigned long)buffer_exec);
61296+ free_page((unsigned long)buffer_fault);
61297+ pax_report_insns(regs, pc, sp);
61298+ info.si_signo = SIGKILL;
61299+ info.si_errno = 0;
61300+ info.si_code = SI_KERNEL;
61301+ info.si_pid = 0;
61302+ info.si_uid = 0;
61303+ do_coredump(&info);
61304+}
61305+#endif
61306+
61307+#ifdef CONFIG_PAX_REFCOUNT
61308+void pax_report_refcount_overflow(struct pt_regs *regs)
61309+{
61310+ if (current->signal->curr_ip)
61311+ printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
61312+ &current->signal->curr_ip, current->comm, task_pid_nr(current),
61313+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
61314+ else
61315+ printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n", current->comm, task_pid_nr(current),
61316+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
61317+ print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
61318+ preempt_disable();
61319+ show_regs(regs);
61320+ preempt_enable();
61321+ force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
61322+}
61323+#endif
61324+
61325+#ifdef CONFIG_PAX_USERCOPY
61326+/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
61327+static noinline int check_stack_object(const void *obj, unsigned long len)
61328+{
61329+ const void * const stack = task_stack_page(current);
61330+ const void * const stackend = stack + THREAD_SIZE;
61331+
61332+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
61333+ const void *frame = NULL;
61334+ const void *oldframe;
61335+#endif
61336+
61337+ if (obj + len < obj)
61338+ return -1;
61339+
61340+ if (obj + len <= stack || stackend <= obj)
61341+ return 0;
61342+
61343+ if (obj < stack || stackend < obj + len)
61344+ return -1;
61345+
61346+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
61347+ oldframe = __builtin_frame_address(1);
61348+ if (oldframe)
61349+ frame = __builtin_frame_address(2);
61350+ /*
61351+ low ----------------------------------------------> high
61352+ [saved bp][saved ip][args][local vars][saved bp][saved ip]
61353+ ^----------------^
61354+ allow copies only within here
61355+ */
61356+ while (stack <= frame && frame < stackend) {
61357+ /* if obj + len extends past the last frame, this
61358+ check won't pass and the next frame will be 0,
61359+ causing us to bail out and correctly report
61360+ the copy as invalid
61361+ */
61362+ if (obj + len <= frame)
61363+ return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
61364+ oldframe = frame;
61365+ frame = *(const void * const *)frame;
61366+ }
61367+ return -1;
61368+#else
61369+ return 1;
61370+#endif
61371+}
61372+
61373+static __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to_user, const char *type)
61374+{
61375+ if (current->signal->curr_ip)
61376+ printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
61377+ &current->signal->curr_ip, to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
61378+ else
61379+ printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
61380+ to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
61381+ dump_stack();
61382+ gr_handle_kernel_exploit();
61383+ do_group_exit(SIGKILL);
61384+}
61385+#endif
61386+
61387+#ifdef CONFIG_PAX_USERCOPY
61388+
61389+static inline bool check_kernel_text_object(unsigned long low, unsigned long high)
61390+{
61391+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
61392+ unsigned long textlow = ktla_ktva((unsigned long)_stext);
61393+#ifdef CONFIG_MODULES
61394+ unsigned long texthigh = (unsigned long)MODULES_EXEC_VADDR;
61395+#else
61396+ unsigned long texthigh = ktla_ktva((unsigned long)_etext);
61397+#endif
61398+
61399+#else
61400+ unsigned long textlow = (unsigned long)_stext;
61401+ unsigned long texthigh = (unsigned long)_etext;
61402+
61403+#ifdef CONFIG_X86_64
61404+ /* check against linear mapping as well */
61405+ if (high > (unsigned long)__va(__pa(textlow)) &&
61406+ low < (unsigned long)__va(__pa(texthigh)))
61407+ return true;
61408+#endif
61409+
61410+#endif
61411+
61412+ if (high <= textlow || low >= texthigh)
61413+ return false;
61414+ else
61415+ return true;
61416+}
61417+#endif
61418+
61419+void __check_object_size(const void *ptr, unsigned long n, bool to_user, bool const_size)
61420+{
61421+#ifdef CONFIG_PAX_USERCOPY
61422+ const char *type;
61423+#endif
61424+
61425+#ifndef CONFIG_STACK_GROWSUP
61426+ unsigned long stackstart = (unsigned long)task_stack_page(current);
61427+ unsigned long currentsp = (unsigned long)&stackstart;
61428+ if (unlikely((currentsp < stackstart + 512 ||
61429+ currentsp >= stackstart + THREAD_SIZE) && !in_interrupt()))
61430+ BUG();
61431+#endif
61432+
61433+#ifndef CONFIG_PAX_USERCOPY_DEBUG
61434+ if (const_size)
61435+ return;
61436+#endif
61437+
61438+#ifdef CONFIG_PAX_USERCOPY
61439+ if (!n)
61440+ return;
61441+
61442+ type = check_heap_object(ptr, n);
61443+ if (!type) {
61444+ int ret = check_stack_object(ptr, n);
61445+ if (ret == 1 || ret == 2)
61446+ return;
61447+ if (ret == 0) {
61448+ if (check_kernel_text_object((unsigned long)ptr, (unsigned long)ptr + n))
61449+ type = "<kernel text>";
61450+ else
61451+ return;
61452+ } else
61453+ type = "<process stack>";
61454+ }
61455+
61456+ pax_report_usercopy(ptr, n, to_user, type);
61457+#endif
61458+
61459+}
61460+EXPORT_SYMBOL(__check_object_size);
61461+
61462+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
61463+void pax_track_stack(void)
61464+{
61465+ unsigned long sp = (unsigned long)&sp;
61466+ if (sp < current_thread_info()->lowest_stack &&
61467+ sp >= (unsigned long)task_stack_page(current) + 2 * sizeof(unsigned long))
61468+ current_thread_info()->lowest_stack = sp;
61469+ if (unlikely((sp & ~(THREAD_SIZE - 1)) < (THREAD_SIZE/16)))
61470+ BUG();
61471+}
61472+EXPORT_SYMBOL(pax_track_stack);
61473+#endif
61474+
61475+#ifdef CONFIG_PAX_SIZE_OVERFLOW
61476+void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
61477+{
61478+ printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u %s", func, file, line, ssa_name);
61479+ dump_stack();
61480+ do_group_exit(SIGKILL);
61481+}
61482+EXPORT_SYMBOL(report_size_overflow);
61483+#endif
61484diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
61485index 9f9992b..8b59411 100644
61486--- a/fs/ext2/balloc.c
61487+++ b/fs/ext2/balloc.c
61488@@ -1184,10 +1184,10 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
61489
61490 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
61491 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
61492- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
61493+ if (free_blocks < root_blocks + 1 &&
61494 !uid_eq(sbi->s_resuid, current_fsuid()) &&
61495 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
61496- !in_group_p (sbi->s_resgid))) {
61497+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
61498 return 0;
61499 }
61500 return 1;
61501diff --git a/fs/ext2/super.c b/fs/ext2/super.c
61502index 170dc41..62f6b18 100644
61503--- a/fs/ext2/super.c
61504+++ b/fs/ext2/super.c
61505@@ -264,10 +264,8 @@ static int ext2_show_options(struct seq_file *seq, struct dentry *root)
61506 #ifdef CONFIG_EXT2_FS_XATTR
61507 if (test_opt(sb, XATTR_USER))
61508 seq_puts(seq, ",user_xattr");
61509- if (!test_opt(sb, XATTR_USER) &&
61510- (def_mount_opts & EXT2_DEFM_XATTR_USER)) {
61511+ if (!test_opt(sb, XATTR_USER))
61512 seq_puts(seq, ",nouser_xattr");
61513- }
61514 #endif
61515
61516 #ifdef CONFIG_EXT2_FS_POSIX_ACL
61517@@ -841,8 +839,8 @@ static int ext2_fill_super(struct super_block *sb, void *data, int silent)
61518 if (def_mount_opts & EXT2_DEFM_UID16)
61519 set_opt(sbi->s_mount_opt, NO_UID32);
61520 #ifdef CONFIG_EXT2_FS_XATTR
61521- if (def_mount_opts & EXT2_DEFM_XATTR_USER)
61522- set_opt(sbi->s_mount_opt, XATTR_USER);
61523+ /* always enable user xattrs */
61524+ set_opt(sbi->s_mount_opt, XATTR_USER);
61525 #endif
61526 #ifdef CONFIG_EXT2_FS_POSIX_ACL
61527 if (def_mount_opts & EXT2_DEFM_ACL)
61528diff --git a/fs/ext2/xattr.c b/fs/ext2/xattr.c
61529index 9142614..97484fa 100644
61530--- a/fs/ext2/xattr.c
61531+++ b/fs/ext2/xattr.c
61532@@ -247,7 +247,7 @@ ext2_xattr_list(struct dentry *dentry, char *buffer, size_t buffer_size)
61533 struct buffer_head *bh = NULL;
61534 struct ext2_xattr_entry *entry;
61535 char *end;
61536- size_t rest = buffer_size;
61537+ size_t rest = buffer_size, total_size = 0;
61538 int error;
61539
61540 ea_idebug(inode, "buffer=%p, buffer_size=%ld",
61541@@ -305,9 +305,10 @@ bad_block: ext2_error(inode->i_sb, "ext2_xattr_list",
61542 buffer += size;
61543 }
61544 rest -= size;
61545+ total_size += size;
61546 }
61547 }
61548- error = buffer_size - rest; /* total size */
61549+ error = total_size;
61550
61551 cleanup:
61552 brelse(bh);
61553diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
61554index 158b5d4..2432610 100644
61555--- a/fs/ext3/balloc.c
61556+++ b/fs/ext3/balloc.c
61557@@ -1438,10 +1438,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
61558
61559 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
61560 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
61561- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
61562+ if (free_blocks < root_blocks + 1 &&
61563 !use_reservation && !uid_eq(sbi->s_resuid, current_fsuid()) &&
61564 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
61565- !in_group_p (sbi->s_resgid))) {
61566+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
61567 return 0;
61568 }
61569 return 1;
61570diff --git a/fs/ext3/super.c b/fs/ext3/super.c
61571index eb742d0..c19f705 100644
61572--- a/fs/ext3/super.c
61573+++ b/fs/ext3/super.c
61574@@ -649,10 +649,8 @@ static int ext3_show_options(struct seq_file *seq, struct dentry *root)
61575 #ifdef CONFIG_EXT3_FS_XATTR
61576 if (test_opt(sb, XATTR_USER))
61577 seq_puts(seq, ",user_xattr");
61578- if (!test_opt(sb, XATTR_USER) &&
61579- (def_mount_opts & EXT3_DEFM_XATTR_USER)) {
61580+ if (!test_opt(sb, XATTR_USER))
61581 seq_puts(seq, ",nouser_xattr");
61582- }
61583 #endif
61584 #ifdef CONFIG_EXT3_FS_POSIX_ACL
61585 if (test_opt(sb, POSIX_ACL))
61586@@ -1749,8 +1747,8 @@ static int ext3_fill_super (struct super_block *sb, void *data, int silent)
61587 if (def_mount_opts & EXT3_DEFM_UID16)
61588 set_opt(sbi->s_mount_opt, NO_UID32);
61589 #ifdef CONFIG_EXT3_FS_XATTR
61590- if (def_mount_opts & EXT3_DEFM_XATTR_USER)
61591- set_opt(sbi->s_mount_opt, XATTR_USER);
61592+ /* always enable user xattrs */
61593+ set_opt(sbi->s_mount_opt, XATTR_USER);
61594 #endif
61595 #ifdef CONFIG_EXT3_FS_POSIX_ACL
61596 if (def_mount_opts & EXT3_DEFM_ACL)
61597diff --git a/fs/ext3/xattr.c b/fs/ext3/xattr.c
61598index c6874be..f8a6ae8 100644
61599--- a/fs/ext3/xattr.c
61600+++ b/fs/ext3/xattr.c
61601@@ -330,7 +330,7 @@ static int
61602 ext3_xattr_list_entries(struct dentry *dentry, struct ext3_xattr_entry *entry,
61603 char *buffer, size_t buffer_size)
61604 {
61605- size_t rest = buffer_size;
61606+ size_t rest = buffer_size, total_size = 0;
61607
61608 for (; !IS_LAST_ENTRY(entry); entry = EXT3_XATTR_NEXT(entry)) {
61609 const struct xattr_handler *handler =
61610@@ -347,9 +347,10 @@ ext3_xattr_list_entries(struct dentry *dentry, struct ext3_xattr_entry *entry,
61611 buffer += size;
61612 }
61613 rest -= size;
61614+ total_size += size;
61615 }
61616 }
61617- return buffer_size - rest;
61618+ return total_size;
61619 }
61620
61621 static int
61622diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
61623index 83a6f49..d4e4d03 100644
61624--- a/fs/ext4/balloc.c
61625+++ b/fs/ext4/balloc.c
61626@@ -557,8 +557,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
61627 /* Hm, nope. Are (enough) root reserved clusters available? */
61628 if (uid_eq(sbi->s_resuid, current_fsuid()) ||
61629 (!gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) && in_group_p(sbi->s_resgid)) ||
61630- capable(CAP_SYS_RESOURCE) ||
61631- (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
61632+ (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
61633+ capable_nolog(CAP_SYS_RESOURCE)) {
61634
61635 if (free_clusters >= (nclusters + dirty_clusters +
61636 resv_clusters))
61637diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
61638index c55a1fa..9904ebb 100644
61639--- a/fs/ext4/ext4.h
61640+++ b/fs/ext4/ext4.h
61641@@ -1279,19 +1279,19 @@ struct ext4_sb_info {
61642 unsigned long s_mb_last_start;
61643
61644 /* stats for buddy allocator */
61645- atomic_t s_bal_reqs; /* number of reqs with len > 1 */
61646- atomic_t s_bal_success; /* we found long enough chunks */
61647- atomic_t s_bal_allocated; /* in blocks */
61648- atomic_t s_bal_ex_scanned; /* total extents scanned */
61649- atomic_t s_bal_goals; /* goal hits */
61650- atomic_t s_bal_breaks; /* too long searches */
61651- atomic_t s_bal_2orders; /* 2^order hits */
61652+ atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
61653+ atomic_unchecked_t s_bal_success; /* we found long enough chunks */
61654+ atomic_unchecked_t s_bal_allocated; /* in blocks */
61655+ atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
61656+ atomic_unchecked_t s_bal_goals; /* goal hits */
61657+ atomic_unchecked_t s_bal_breaks; /* too long searches */
61658+ atomic_unchecked_t s_bal_2orders; /* 2^order hits */
61659 spinlock_t s_bal_lock;
61660 unsigned long s_mb_buddies_generated;
61661 unsigned long long s_mb_generation_time;
61662- atomic_t s_mb_lost_chunks;
61663- atomic_t s_mb_preallocated;
61664- atomic_t s_mb_discarded;
61665+ atomic_unchecked_t s_mb_lost_chunks;
61666+ atomic_unchecked_t s_mb_preallocated;
61667+ atomic_unchecked_t s_mb_discarded;
61668 atomic_t s_lock_busy;
61669
61670 /* locality groups */
61671diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
61672index dbfe15c..9a6ee8d 100644
61673--- a/fs/ext4/mballoc.c
61674+++ b/fs/ext4/mballoc.c
61675@@ -1901,7 +1901,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
61676 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
61677
61678 if (EXT4_SB(sb)->s_mb_stats)
61679- atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
61680+ atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
61681
61682 break;
61683 }
61684@@ -2211,7 +2211,7 @@ repeat:
61685 ac->ac_status = AC_STATUS_CONTINUE;
61686 ac->ac_flags |= EXT4_MB_HINT_FIRST;
61687 cr = 3;
61688- atomic_inc(&sbi->s_mb_lost_chunks);
61689+ atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
61690 goto repeat;
61691 }
61692 }
61693@@ -2717,25 +2717,25 @@ int ext4_mb_release(struct super_block *sb)
61694 if (sbi->s_mb_stats) {
61695 ext4_msg(sb, KERN_INFO,
61696 "mballoc: %u blocks %u reqs (%u success)",
61697- atomic_read(&sbi->s_bal_allocated),
61698- atomic_read(&sbi->s_bal_reqs),
61699- atomic_read(&sbi->s_bal_success));
61700+ atomic_read_unchecked(&sbi->s_bal_allocated),
61701+ atomic_read_unchecked(&sbi->s_bal_reqs),
61702+ atomic_read_unchecked(&sbi->s_bal_success));
61703 ext4_msg(sb, KERN_INFO,
61704 "mballoc: %u extents scanned, %u goal hits, "
61705 "%u 2^N hits, %u breaks, %u lost",
61706- atomic_read(&sbi->s_bal_ex_scanned),
61707- atomic_read(&sbi->s_bal_goals),
61708- atomic_read(&sbi->s_bal_2orders),
61709- atomic_read(&sbi->s_bal_breaks),
61710- atomic_read(&sbi->s_mb_lost_chunks));
61711+ atomic_read_unchecked(&sbi->s_bal_ex_scanned),
61712+ atomic_read_unchecked(&sbi->s_bal_goals),
61713+ atomic_read_unchecked(&sbi->s_bal_2orders),
61714+ atomic_read_unchecked(&sbi->s_bal_breaks),
61715+ atomic_read_unchecked(&sbi->s_mb_lost_chunks));
61716 ext4_msg(sb, KERN_INFO,
61717 "mballoc: %lu generated and it took %Lu",
61718 sbi->s_mb_buddies_generated,
61719 sbi->s_mb_generation_time);
61720 ext4_msg(sb, KERN_INFO,
61721 "mballoc: %u preallocated, %u discarded",
61722- atomic_read(&sbi->s_mb_preallocated),
61723- atomic_read(&sbi->s_mb_discarded));
61724+ atomic_read_unchecked(&sbi->s_mb_preallocated),
61725+ atomic_read_unchecked(&sbi->s_mb_discarded));
61726 }
61727
61728 free_percpu(sbi->s_locality_groups);
61729@@ -3191,16 +3191,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
61730 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
61731
61732 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
61733- atomic_inc(&sbi->s_bal_reqs);
61734- atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
61735+ atomic_inc_unchecked(&sbi->s_bal_reqs);
61736+ atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
61737 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
61738- atomic_inc(&sbi->s_bal_success);
61739- atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
61740+ atomic_inc_unchecked(&sbi->s_bal_success);
61741+ atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
61742 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
61743 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
61744- atomic_inc(&sbi->s_bal_goals);
61745+ atomic_inc_unchecked(&sbi->s_bal_goals);
61746 if (ac->ac_found > sbi->s_mb_max_to_scan)
61747- atomic_inc(&sbi->s_bal_breaks);
61748+ atomic_inc_unchecked(&sbi->s_bal_breaks);
61749 }
61750
61751 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
61752@@ -3627,7 +3627,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
61753 trace_ext4_mb_new_inode_pa(ac, pa);
61754
61755 ext4_mb_use_inode_pa(ac, pa);
61756- atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
61757+ atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
61758
61759 ei = EXT4_I(ac->ac_inode);
61760 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
61761@@ -3687,7 +3687,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
61762 trace_ext4_mb_new_group_pa(ac, pa);
61763
61764 ext4_mb_use_group_pa(ac, pa);
61765- atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
61766+ atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
61767
61768 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
61769 lg = ac->ac_lg;
61770@@ -3776,7 +3776,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
61771 * from the bitmap and continue.
61772 */
61773 }
61774- atomic_add(free, &sbi->s_mb_discarded);
61775+ atomic_add_unchecked(free, &sbi->s_mb_discarded);
61776
61777 return err;
61778 }
61779@@ -3794,7 +3794,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
61780 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
61781 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
61782 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
61783- atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
61784+ atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
61785 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
61786
61787 return 0;
61788diff --git a/fs/ext4/mmp.c b/fs/ext4/mmp.c
61789index 8313ca3..8a37d08 100644
61790--- a/fs/ext4/mmp.c
61791+++ b/fs/ext4/mmp.c
61792@@ -111,7 +111,7 @@ static int read_mmp_block(struct super_block *sb, struct buffer_head **bh,
61793 void __dump_mmp_msg(struct super_block *sb, struct mmp_struct *mmp,
61794 const char *function, unsigned int line, const char *msg)
61795 {
61796- __ext4_warning(sb, function, line, msg);
61797+ __ext4_warning(sb, function, line, "%s", msg);
61798 __ext4_warning(sb, function, line,
61799 "MMP failure info: last update time: %llu, last update "
61800 "node: %s, last update device: %s\n",
61801diff --git a/fs/ext4/super.c b/fs/ext4/super.c
61802index 2c9e686..6a40edc 100644
61803--- a/fs/ext4/super.c
61804+++ b/fs/ext4/super.c
61805@@ -1254,7 +1254,7 @@ static ext4_fsblk_t get_sb_block(void **data)
61806 }
61807
61808 #define DEFAULT_JOURNAL_IOPRIO (IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, 3))
61809-static char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
61810+static const char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
61811 "Contact linux-ext4@vger.kernel.org if you think we should keep it.\n";
61812
61813 #ifdef CONFIG_QUOTA
61814@@ -2434,7 +2434,7 @@ struct ext4_attr {
61815 int offset;
61816 int deprecated_val;
61817 } u;
61818-};
61819+} __do_const;
61820
61821 static int parse_strtoull(const char *buf,
61822 unsigned long long max, unsigned long long *value)
61823diff --git a/fs/ext4/xattr.c b/fs/ext4/xattr.c
61824index 1e09fc7..0400dd4 100644
61825--- a/fs/ext4/xattr.c
61826+++ b/fs/ext4/xattr.c
61827@@ -399,7 +399,7 @@ static int
61828 ext4_xattr_list_entries(struct dentry *dentry, struct ext4_xattr_entry *entry,
61829 char *buffer, size_t buffer_size)
61830 {
61831- size_t rest = buffer_size;
61832+ size_t rest = buffer_size, total_size = 0;
61833
61834 for (; !IS_LAST_ENTRY(entry); entry = EXT4_XATTR_NEXT(entry)) {
61835 const struct xattr_handler *handler =
61836@@ -416,9 +416,10 @@ ext4_xattr_list_entries(struct dentry *dentry, struct ext4_xattr_entry *entry,
61837 buffer += size;
61838 }
61839 rest -= size;
61840+ total_size += size;
61841 }
61842 }
61843- return buffer_size - rest;
61844+ return total_size;
61845 }
61846
61847 static int
61848diff --git a/fs/fcntl.c b/fs/fcntl.c
61849index 99d440a..eb979d1 100644
61850--- a/fs/fcntl.c
61851+++ b/fs/fcntl.c
61852@@ -102,6 +102,10 @@ void __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
61853 int force)
61854 {
61855 security_file_set_fowner(filp);
61856+ if (gr_handle_chroot_fowner(pid, type))
61857+ return;
61858+ if (gr_check_protected_task_fowner(pid, type))
61859+ return;
61860 f_modown(filp, pid, type, force);
61861 }
61862 EXPORT_SYMBOL(__f_setown);
61863diff --git a/fs/fhandle.c b/fs/fhandle.c
61864index 999ff5c..ac037c9 100644
61865--- a/fs/fhandle.c
61866+++ b/fs/fhandle.c
61867@@ -8,6 +8,7 @@
61868 #include <linux/fs_struct.h>
61869 #include <linux/fsnotify.h>
61870 #include <linux/personality.h>
61871+#include <linux/grsecurity.h>
61872 #include <asm/uaccess.h>
61873 #include "internal.h"
61874 #include "mount.h"
61875@@ -67,8 +68,7 @@ static long do_sys_name_to_handle(struct path *path,
61876 } else
61877 retval = 0;
61878 /* copy the mount id */
61879- if (copy_to_user(mnt_id, &real_mount(path->mnt)->mnt_id,
61880- sizeof(*mnt_id)) ||
61881+ if (put_user(real_mount(path->mnt)->mnt_id, mnt_id) ||
61882 copy_to_user(ufh, handle,
61883 sizeof(struct file_handle) + handle_bytes))
61884 retval = -EFAULT;
61885@@ -175,7 +175,7 @@ static int handle_to_path(int mountdirfd, struct file_handle __user *ufh,
61886 * the directory. Ideally we would like CAP_DAC_SEARCH.
61887 * But we don't have that
61888 */
61889- if (!capable(CAP_DAC_READ_SEARCH)) {
61890+ if (!capable(CAP_DAC_READ_SEARCH) || !gr_chroot_fhandle()) {
61891 retval = -EPERM;
61892 goto out_err;
61893 }
61894diff --git a/fs/file.c b/fs/file.c
61895index ab3eb6a..8de2392 100644
61896--- a/fs/file.c
61897+++ b/fs/file.c
61898@@ -16,6 +16,7 @@
61899 #include <linux/slab.h>
61900 #include <linux/vmalloc.h>
61901 #include <linux/file.h>
61902+#include <linux/security.h>
61903 #include <linux/fdtable.h>
61904 #include <linux/bitops.h>
61905 #include <linux/interrupt.h>
61906@@ -139,7 +140,7 @@ out:
61907 * Return <0 error code on error; 1 on successful completion.
61908 * The files->file_lock should be held on entry, and will be held on exit.
61909 */
61910-static int expand_fdtable(struct files_struct *files, int nr)
61911+static int expand_fdtable(struct files_struct *files, unsigned int nr)
61912 __releases(files->file_lock)
61913 __acquires(files->file_lock)
61914 {
61915@@ -184,7 +185,7 @@ static int expand_fdtable(struct files_struct *files, int nr)
61916 * expanded and execution may have blocked.
61917 * The files->file_lock should be held on entry, and will be held on exit.
61918 */
61919-static int expand_files(struct files_struct *files, int nr)
61920+static int expand_files(struct files_struct *files, unsigned int nr)
61921 {
61922 struct fdtable *fdt;
61923
61924@@ -800,6 +801,7 @@ int replace_fd(unsigned fd, struct file *file, unsigned flags)
61925 if (!file)
61926 return __close_fd(files, fd);
61927
61928+ gr_learn_resource(current, RLIMIT_NOFILE, fd, 0);
61929 if (fd >= rlimit(RLIMIT_NOFILE))
61930 return -EBADF;
61931
61932@@ -826,6 +828,7 @@ SYSCALL_DEFINE3(dup3, unsigned int, oldfd, unsigned int, newfd, int, flags)
61933 if (unlikely(oldfd == newfd))
61934 return -EINVAL;
61935
61936+ gr_learn_resource(current, RLIMIT_NOFILE, newfd, 0);
61937 if (newfd >= rlimit(RLIMIT_NOFILE))
61938 return -EBADF;
61939
61940@@ -881,6 +884,7 @@ SYSCALL_DEFINE1(dup, unsigned int, fildes)
61941 int f_dupfd(unsigned int from, struct file *file, unsigned flags)
61942 {
61943 int err;
61944+ gr_learn_resource(current, RLIMIT_NOFILE, from, 0);
61945 if (from >= rlimit(RLIMIT_NOFILE))
61946 return -EINVAL;
61947 err = alloc_fd(from, flags);
61948diff --git a/fs/filesystems.c b/fs/filesystems.c
61949index 5797d45..7d7d79a 100644
61950--- a/fs/filesystems.c
61951+++ b/fs/filesystems.c
61952@@ -275,7 +275,11 @@ struct file_system_type *get_fs_type(const char *name)
61953 int len = dot ? dot - name : strlen(name);
61954
61955 fs = __get_fs_type(name, len);
61956+#ifdef CONFIG_GRKERNSEC_MODHARDEN
61957+ if (!fs && (___request_module(true, "grsec_modharden_fs", "fs-%.*s", len, name) == 0))
61958+#else
61959 if (!fs && (request_module("fs-%.*s", len, name) == 0))
61960+#endif
61961 fs = __get_fs_type(name, len);
61962
61963 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
61964diff --git a/fs/fs_struct.c b/fs/fs_struct.c
61965index 7dca743..543d620 100644
61966--- a/fs/fs_struct.c
61967+++ b/fs/fs_struct.c
61968@@ -4,6 +4,7 @@
61969 #include <linux/path.h>
61970 #include <linux/slab.h>
61971 #include <linux/fs_struct.h>
61972+#include <linux/grsecurity.h>
61973 #include "internal.h"
61974
61975 /*
61976@@ -19,6 +20,7 @@ void set_fs_root(struct fs_struct *fs, const struct path *path)
61977 write_seqcount_begin(&fs->seq);
61978 old_root = fs->root;
61979 fs->root = *path;
61980+ gr_set_chroot_entries(current, path);
61981 write_seqcount_end(&fs->seq);
61982 spin_unlock(&fs->lock);
61983 if (old_root.dentry)
61984@@ -67,6 +69,10 @@ void chroot_fs_refs(const struct path *old_root, const struct path *new_root)
61985 int hits = 0;
61986 spin_lock(&fs->lock);
61987 write_seqcount_begin(&fs->seq);
61988+ /* this root replacement is only done by pivot_root,
61989+ leave grsec's chroot tagging alone for this task
61990+ so that a pivoted root isn't treated as a chroot
61991+ */
61992 hits += replace_path(&fs->root, old_root, new_root);
61993 hits += replace_path(&fs->pwd, old_root, new_root);
61994 write_seqcount_end(&fs->seq);
61995@@ -99,7 +105,8 @@ void exit_fs(struct task_struct *tsk)
61996 task_lock(tsk);
61997 spin_lock(&fs->lock);
61998 tsk->fs = NULL;
61999- kill = !--fs->users;
62000+ gr_clear_chroot_entries(tsk);
62001+ kill = !atomic_dec_return(&fs->users);
62002 spin_unlock(&fs->lock);
62003 task_unlock(tsk);
62004 if (kill)
62005@@ -112,7 +119,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
62006 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
62007 /* We don't need to lock fs - think why ;-) */
62008 if (fs) {
62009- fs->users = 1;
62010+ atomic_set(&fs->users, 1);
62011 fs->in_exec = 0;
62012 spin_lock_init(&fs->lock);
62013 seqcount_init(&fs->seq);
62014@@ -121,6 +128,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
62015 spin_lock(&old->lock);
62016 fs->root = old->root;
62017 path_get(&fs->root);
62018+ /* instead of calling gr_set_chroot_entries here,
62019+ we call it from every caller of this function
62020+ */
62021 fs->pwd = old->pwd;
62022 path_get(&fs->pwd);
62023 spin_unlock(&old->lock);
62024@@ -139,8 +149,9 @@ int unshare_fs_struct(void)
62025
62026 task_lock(current);
62027 spin_lock(&fs->lock);
62028- kill = !--fs->users;
62029+ kill = !atomic_dec_return(&fs->users);
62030 current->fs = new_fs;
62031+ gr_set_chroot_entries(current, &new_fs->root);
62032 spin_unlock(&fs->lock);
62033 task_unlock(current);
62034
62035@@ -153,13 +164,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
62036
62037 int current_umask(void)
62038 {
62039- return current->fs->umask;
62040+ return current->fs->umask | gr_acl_umask();
62041 }
62042 EXPORT_SYMBOL(current_umask);
62043
62044 /* to be mentioned only in INIT_TASK */
62045 struct fs_struct init_fs = {
62046- .users = 1,
62047+ .users = ATOMIC_INIT(1),
62048 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
62049 .seq = SEQCNT_ZERO(init_fs.seq),
62050 .umask = 0022,
62051diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
62052index 89acec7..a575262 100644
62053--- a/fs/fscache/cookie.c
62054+++ b/fs/fscache/cookie.c
62055@@ -19,7 +19,7 @@
62056
62057 struct kmem_cache *fscache_cookie_jar;
62058
62059-static atomic_t fscache_object_debug_id = ATOMIC_INIT(0);
62060+static atomic_unchecked_t fscache_object_debug_id = ATOMIC_INIT(0);
62061
62062 static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie);
62063 static int fscache_alloc_object(struct fscache_cache *cache,
62064@@ -69,11 +69,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
62065 parent ? (char *) parent->def->name : "<no-parent>",
62066 def->name, netfs_data, enable);
62067
62068- fscache_stat(&fscache_n_acquires);
62069+ fscache_stat_unchecked(&fscache_n_acquires);
62070
62071 /* if there's no parent cookie, then we don't create one here either */
62072 if (!parent) {
62073- fscache_stat(&fscache_n_acquires_null);
62074+ fscache_stat_unchecked(&fscache_n_acquires_null);
62075 _leave(" [no parent]");
62076 return NULL;
62077 }
62078@@ -88,7 +88,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
62079 /* allocate and initialise a cookie */
62080 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
62081 if (!cookie) {
62082- fscache_stat(&fscache_n_acquires_oom);
62083+ fscache_stat_unchecked(&fscache_n_acquires_oom);
62084 _leave(" [ENOMEM]");
62085 return NULL;
62086 }
62087@@ -115,13 +115,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
62088
62089 switch (cookie->def->type) {
62090 case FSCACHE_COOKIE_TYPE_INDEX:
62091- fscache_stat(&fscache_n_cookie_index);
62092+ fscache_stat_unchecked(&fscache_n_cookie_index);
62093 break;
62094 case FSCACHE_COOKIE_TYPE_DATAFILE:
62095- fscache_stat(&fscache_n_cookie_data);
62096+ fscache_stat_unchecked(&fscache_n_cookie_data);
62097 break;
62098 default:
62099- fscache_stat(&fscache_n_cookie_special);
62100+ fscache_stat_unchecked(&fscache_n_cookie_special);
62101 break;
62102 }
62103
62104@@ -135,7 +135,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
62105 } else {
62106 atomic_dec(&parent->n_children);
62107 __fscache_cookie_put(cookie);
62108- fscache_stat(&fscache_n_acquires_nobufs);
62109+ fscache_stat_unchecked(&fscache_n_acquires_nobufs);
62110 _leave(" = NULL");
62111 return NULL;
62112 }
62113@@ -144,7 +144,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
62114 }
62115 }
62116
62117- fscache_stat(&fscache_n_acquires_ok);
62118+ fscache_stat_unchecked(&fscache_n_acquires_ok);
62119 _leave(" = %p", cookie);
62120 return cookie;
62121 }
62122@@ -213,7 +213,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
62123 cache = fscache_select_cache_for_object(cookie->parent);
62124 if (!cache) {
62125 up_read(&fscache_addremove_sem);
62126- fscache_stat(&fscache_n_acquires_no_cache);
62127+ fscache_stat_unchecked(&fscache_n_acquires_no_cache);
62128 _leave(" = -ENOMEDIUM [no cache]");
62129 return -ENOMEDIUM;
62130 }
62131@@ -297,14 +297,14 @@ static int fscache_alloc_object(struct fscache_cache *cache,
62132 object = cache->ops->alloc_object(cache, cookie);
62133 fscache_stat_d(&fscache_n_cop_alloc_object);
62134 if (IS_ERR(object)) {
62135- fscache_stat(&fscache_n_object_no_alloc);
62136+ fscache_stat_unchecked(&fscache_n_object_no_alloc);
62137 ret = PTR_ERR(object);
62138 goto error;
62139 }
62140
62141- fscache_stat(&fscache_n_object_alloc);
62142+ fscache_stat_unchecked(&fscache_n_object_alloc);
62143
62144- object->debug_id = atomic_inc_return(&fscache_object_debug_id);
62145+ object->debug_id = atomic_inc_return_unchecked(&fscache_object_debug_id);
62146
62147 _debug("ALLOC OBJ%x: %s {%lx}",
62148 object->debug_id, cookie->def->name, object->events);
62149@@ -418,7 +418,7 @@ void __fscache_invalidate(struct fscache_cookie *cookie)
62150
62151 _enter("{%s}", cookie->def->name);
62152
62153- fscache_stat(&fscache_n_invalidates);
62154+ fscache_stat_unchecked(&fscache_n_invalidates);
62155
62156 /* Only permit invalidation of data files. Invalidating an index will
62157 * require the caller to release all its attachments to the tree rooted
62158@@ -476,10 +476,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
62159 {
62160 struct fscache_object *object;
62161
62162- fscache_stat(&fscache_n_updates);
62163+ fscache_stat_unchecked(&fscache_n_updates);
62164
62165 if (!cookie) {
62166- fscache_stat(&fscache_n_updates_null);
62167+ fscache_stat_unchecked(&fscache_n_updates_null);
62168 _leave(" [no cookie]");
62169 return;
62170 }
62171@@ -580,12 +580,12 @@ EXPORT_SYMBOL(__fscache_disable_cookie);
62172 */
62173 void __fscache_relinquish_cookie(struct fscache_cookie *cookie, bool retire)
62174 {
62175- fscache_stat(&fscache_n_relinquishes);
62176+ fscache_stat_unchecked(&fscache_n_relinquishes);
62177 if (retire)
62178- fscache_stat(&fscache_n_relinquishes_retire);
62179+ fscache_stat_unchecked(&fscache_n_relinquishes_retire);
62180
62181 if (!cookie) {
62182- fscache_stat(&fscache_n_relinquishes_null);
62183+ fscache_stat_unchecked(&fscache_n_relinquishes_null);
62184 _leave(" [no cookie]");
62185 return;
62186 }
62187@@ -686,7 +686,7 @@ int __fscache_check_consistency(struct fscache_cookie *cookie)
62188 if (test_bit(FSCACHE_IOERROR, &object->cache->flags))
62189 goto inconsistent;
62190
62191- op->debug_id = atomic_inc_return(&fscache_op_debug_id);
62192+ op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
62193
62194 __fscache_use_cookie(cookie);
62195 if (fscache_submit_op(object, op) < 0)
62196diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
62197index 7872a62..d91b19f 100644
62198--- a/fs/fscache/internal.h
62199+++ b/fs/fscache/internal.h
62200@@ -137,8 +137,8 @@ extern void fscache_operation_gc(struct work_struct *);
62201 extern int fscache_wait_for_deferred_lookup(struct fscache_cookie *);
62202 extern int fscache_wait_for_operation_activation(struct fscache_object *,
62203 struct fscache_operation *,
62204- atomic_t *,
62205- atomic_t *,
62206+ atomic_unchecked_t *,
62207+ atomic_unchecked_t *,
62208 void (*)(struct fscache_operation *));
62209 extern void fscache_invalidate_writes(struct fscache_cookie *);
62210
62211@@ -157,101 +157,101 @@ extern void fscache_proc_cleanup(void);
62212 * stats.c
62213 */
62214 #ifdef CONFIG_FSCACHE_STATS
62215-extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
62216-extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
62217+extern atomic_unchecked_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
62218+extern atomic_unchecked_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
62219
62220-extern atomic_t fscache_n_op_pend;
62221-extern atomic_t fscache_n_op_run;
62222-extern atomic_t fscache_n_op_enqueue;
62223-extern atomic_t fscache_n_op_deferred_release;
62224-extern atomic_t fscache_n_op_release;
62225-extern atomic_t fscache_n_op_gc;
62226-extern atomic_t fscache_n_op_cancelled;
62227-extern atomic_t fscache_n_op_rejected;
62228+extern atomic_unchecked_t fscache_n_op_pend;
62229+extern atomic_unchecked_t fscache_n_op_run;
62230+extern atomic_unchecked_t fscache_n_op_enqueue;
62231+extern atomic_unchecked_t fscache_n_op_deferred_release;
62232+extern atomic_unchecked_t fscache_n_op_release;
62233+extern atomic_unchecked_t fscache_n_op_gc;
62234+extern atomic_unchecked_t fscache_n_op_cancelled;
62235+extern atomic_unchecked_t fscache_n_op_rejected;
62236
62237-extern atomic_t fscache_n_attr_changed;
62238-extern atomic_t fscache_n_attr_changed_ok;
62239-extern atomic_t fscache_n_attr_changed_nobufs;
62240-extern atomic_t fscache_n_attr_changed_nomem;
62241-extern atomic_t fscache_n_attr_changed_calls;
62242+extern atomic_unchecked_t fscache_n_attr_changed;
62243+extern atomic_unchecked_t fscache_n_attr_changed_ok;
62244+extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
62245+extern atomic_unchecked_t fscache_n_attr_changed_nomem;
62246+extern atomic_unchecked_t fscache_n_attr_changed_calls;
62247
62248-extern atomic_t fscache_n_allocs;
62249-extern atomic_t fscache_n_allocs_ok;
62250-extern atomic_t fscache_n_allocs_wait;
62251-extern atomic_t fscache_n_allocs_nobufs;
62252-extern atomic_t fscache_n_allocs_intr;
62253-extern atomic_t fscache_n_allocs_object_dead;
62254-extern atomic_t fscache_n_alloc_ops;
62255-extern atomic_t fscache_n_alloc_op_waits;
62256+extern atomic_unchecked_t fscache_n_allocs;
62257+extern atomic_unchecked_t fscache_n_allocs_ok;
62258+extern atomic_unchecked_t fscache_n_allocs_wait;
62259+extern atomic_unchecked_t fscache_n_allocs_nobufs;
62260+extern atomic_unchecked_t fscache_n_allocs_intr;
62261+extern atomic_unchecked_t fscache_n_allocs_object_dead;
62262+extern atomic_unchecked_t fscache_n_alloc_ops;
62263+extern atomic_unchecked_t fscache_n_alloc_op_waits;
62264
62265-extern atomic_t fscache_n_retrievals;
62266-extern atomic_t fscache_n_retrievals_ok;
62267-extern atomic_t fscache_n_retrievals_wait;
62268-extern atomic_t fscache_n_retrievals_nodata;
62269-extern atomic_t fscache_n_retrievals_nobufs;
62270-extern atomic_t fscache_n_retrievals_intr;
62271-extern atomic_t fscache_n_retrievals_nomem;
62272-extern atomic_t fscache_n_retrievals_object_dead;
62273-extern atomic_t fscache_n_retrieval_ops;
62274-extern atomic_t fscache_n_retrieval_op_waits;
62275+extern atomic_unchecked_t fscache_n_retrievals;
62276+extern atomic_unchecked_t fscache_n_retrievals_ok;
62277+extern atomic_unchecked_t fscache_n_retrievals_wait;
62278+extern atomic_unchecked_t fscache_n_retrievals_nodata;
62279+extern atomic_unchecked_t fscache_n_retrievals_nobufs;
62280+extern atomic_unchecked_t fscache_n_retrievals_intr;
62281+extern atomic_unchecked_t fscache_n_retrievals_nomem;
62282+extern atomic_unchecked_t fscache_n_retrievals_object_dead;
62283+extern atomic_unchecked_t fscache_n_retrieval_ops;
62284+extern atomic_unchecked_t fscache_n_retrieval_op_waits;
62285
62286-extern atomic_t fscache_n_stores;
62287-extern atomic_t fscache_n_stores_ok;
62288-extern atomic_t fscache_n_stores_again;
62289-extern atomic_t fscache_n_stores_nobufs;
62290-extern atomic_t fscache_n_stores_oom;
62291-extern atomic_t fscache_n_store_ops;
62292-extern atomic_t fscache_n_store_calls;
62293-extern atomic_t fscache_n_store_pages;
62294-extern atomic_t fscache_n_store_radix_deletes;
62295-extern atomic_t fscache_n_store_pages_over_limit;
62296+extern atomic_unchecked_t fscache_n_stores;
62297+extern atomic_unchecked_t fscache_n_stores_ok;
62298+extern atomic_unchecked_t fscache_n_stores_again;
62299+extern atomic_unchecked_t fscache_n_stores_nobufs;
62300+extern atomic_unchecked_t fscache_n_stores_oom;
62301+extern atomic_unchecked_t fscache_n_store_ops;
62302+extern atomic_unchecked_t fscache_n_store_calls;
62303+extern atomic_unchecked_t fscache_n_store_pages;
62304+extern atomic_unchecked_t fscache_n_store_radix_deletes;
62305+extern atomic_unchecked_t fscache_n_store_pages_over_limit;
62306
62307-extern atomic_t fscache_n_store_vmscan_not_storing;
62308-extern atomic_t fscache_n_store_vmscan_gone;
62309-extern atomic_t fscache_n_store_vmscan_busy;
62310-extern atomic_t fscache_n_store_vmscan_cancelled;
62311-extern atomic_t fscache_n_store_vmscan_wait;
62312+extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
62313+extern atomic_unchecked_t fscache_n_store_vmscan_gone;
62314+extern atomic_unchecked_t fscache_n_store_vmscan_busy;
62315+extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
62316+extern atomic_unchecked_t fscache_n_store_vmscan_wait;
62317
62318-extern atomic_t fscache_n_marks;
62319-extern atomic_t fscache_n_uncaches;
62320+extern atomic_unchecked_t fscache_n_marks;
62321+extern atomic_unchecked_t fscache_n_uncaches;
62322
62323-extern atomic_t fscache_n_acquires;
62324-extern atomic_t fscache_n_acquires_null;
62325-extern atomic_t fscache_n_acquires_no_cache;
62326-extern atomic_t fscache_n_acquires_ok;
62327-extern atomic_t fscache_n_acquires_nobufs;
62328-extern atomic_t fscache_n_acquires_oom;
62329+extern atomic_unchecked_t fscache_n_acquires;
62330+extern atomic_unchecked_t fscache_n_acquires_null;
62331+extern atomic_unchecked_t fscache_n_acquires_no_cache;
62332+extern atomic_unchecked_t fscache_n_acquires_ok;
62333+extern atomic_unchecked_t fscache_n_acquires_nobufs;
62334+extern atomic_unchecked_t fscache_n_acquires_oom;
62335
62336-extern atomic_t fscache_n_invalidates;
62337-extern atomic_t fscache_n_invalidates_run;
62338+extern atomic_unchecked_t fscache_n_invalidates;
62339+extern atomic_unchecked_t fscache_n_invalidates_run;
62340
62341-extern atomic_t fscache_n_updates;
62342-extern atomic_t fscache_n_updates_null;
62343-extern atomic_t fscache_n_updates_run;
62344+extern atomic_unchecked_t fscache_n_updates;
62345+extern atomic_unchecked_t fscache_n_updates_null;
62346+extern atomic_unchecked_t fscache_n_updates_run;
62347
62348-extern atomic_t fscache_n_relinquishes;
62349-extern atomic_t fscache_n_relinquishes_null;
62350-extern atomic_t fscache_n_relinquishes_waitcrt;
62351-extern atomic_t fscache_n_relinquishes_retire;
62352+extern atomic_unchecked_t fscache_n_relinquishes;
62353+extern atomic_unchecked_t fscache_n_relinquishes_null;
62354+extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
62355+extern atomic_unchecked_t fscache_n_relinquishes_retire;
62356
62357-extern atomic_t fscache_n_cookie_index;
62358-extern atomic_t fscache_n_cookie_data;
62359-extern atomic_t fscache_n_cookie_special;
62360+extern atomic_unchecked_t fscache_n_cookie_index;
62361+extern atomic_unchecked_t fscache_n_cookie_data;
62362+extern atomic_unchecked_t fscache_n_cookie_special;
62363
62364-extern atomic_t fscache_n_object_alloc;
62365-extern atomic_t fscache_n_object_no_alloc;
62366-extern atomic_t fscache_n_object_lookups;
62367-extern atomic_t fscache_n_object_lookups_negative;
62368-extern atomic_t fscache_n_object_lookups_positive;
62369-extern atomic_t fscache_n_object_lookups_timed_out;
62370-extern atomic_t fscache_n_object_created;
62371-extern atomic_t fscache_n_object_avail;
62372-extern atomic_t fscache_n_object_dead;
62373+extern atomic_unchecked_t fscache_n_object_alloc;
62374+extern atomic_unchecked_t fscache_n_object_no_alloc;
62375+extern atomic_unchecked_t fscache_n_object_lookups;
62376+extern atomic_unchecked_t fscache_n_object_lookups_negative;
62377+extern atomic_unchecked_t fscache_n_object_lookups_positive;
62378+extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
62379+extern atomic_unchecked_t fscache_n_object_created;
62380+extern atomic_unchecked_t fscache_n_object_avail;
62381+extern atomic_unchecked_t fscache_n_object_dead;
62382
62383-extern atomic_t fscache_n_checkaux_none;
62384-extern atomic_t fscache_n_checkaux_okay;
62385-extern atomic_t fscache_n_checkaux_update;
62386-extern atomic_t fscache_n_checkaux_obsolete;
62387+extern atomic_unchecked_t fscache_n_checkaux_none;
62388+extern atomic_unchecked_t fscache_n_checkaux_okay;
62389+extern atomic_unchecked_t fscache_n_checkaux_update;
62390+extern atomic_unchecked_t fscache_n_checkaux_obsolete;
62391
62392 extern atomic_t fscache_n_cop_alloc_object;
62393 extern atomic_t fscache_n_cop_lookup_object;
62394@@ -276,6 +276,11 @@ static inline void fscache_stat(atomic_t *stat)
62395 atomic_inc(stat);
62396 }
62397
62398+static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
62399+{
62400+ atomic_inc_unchecked(stat);
62401+}
62402+
62403 static inline void fscache_stat_d(atomic_t *stat)
62404 {
62405 atomic_dec(stat);
62406@@ -288,6 +293,7 @@ extern const struct file_operations fscache_stats_fops;
62407
62408 #define __fscache_stat(stat) (NULL)
62409 #define fscache_stat(stat) do {} while (0)
62410+#define fscache_stat_unchecked(stat) do {} while (0)
62411 #define fscache_stat_d(stat) do {} while (0)
62412 #endif
62413
62414diff --git a/fs/fscache/object.c b/fs/fscache/object.c
62415index da032da..0076ce7 100644
62416--- a/fs/fscache/object.c
62417+++ b/fs/fscache/object.c
62418@@ -454,7 +454,7 @@ static const struct fscache_state *fscache_look_up_object(struct fscache_object
62419 _debug("LOOKUP \"%s\" in \"%s\"",
62420 cookie->def->name, object->cache->tag->name);
62421
62422- fscache_stat(&fscache_n_object_lookups);
62423+ fscache_stat_unchecked(&fscache_n_object_lookups);
62424 fscache_stat(&fscache_n_cop_lookup_object);
62425 ret = object->cache->ops->lookup_object(object);
62426 fscache_stat_d(&fscache_n_cop_lookup_object);
62427@@ -464,7 +464,7 @@ static const struct fscache_state *fscache_look_up_object(struct fscache_object
62428 if (ret == -ETIMEDOUT) {
62429 /* probably stuck behind another object, so move this one to
62430 * the back of the queue */
62431- fscache_stat(&fscache_n_object_lookups_timed_out);
62432+ fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
62433 _leave(" [timeout]");
62434 return NO_TRANSIT;
62435 }
62436@@ -492,7 +492,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
62437 _enter("{OBJ%x,%s}", object->debug_id, object->state->name);
62438
62439 if (!test_and_set_bit(FSCACHE_OBJECT_IS_LOOKED_UP, &object->flags)) {
62440- fscache_stat(&fscache_n_object_lookups_negative);
62441+ fscache_stat_unchecked(&fscache_n_object_lookups_negative);
62442
62443 /* Allow write requests to begin stacking up and read requests to begin
62444 * returning ENODATA.
62445@@ -527,7 +527,7 @@ void fscache_obtained_object(struct fscache_object *object)
62446 /* if we were still looking up, then we must have a positive lookup
62447 * result, in which case there may be data available */
62448 if (!test_and_set_bit(FSCACHE_OBJECT_IS_LOOKED_UP, &object->flags)) {
62449- fscache_stat(&fscache_n_object_lookups_positive);
62450+ fscache_stat_unchecked(&fscache_n_object_lookups_positive);
62451
62452 /* We do (presumably) have data */
62453 clear_bit_unlock(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
62454@@ -539,7 +539,7 @@ void fscache_obtained_object(struct fscache_object *object)
62455 clear_bit_unlock(FSCACHE_COOKIE_LOOKING_UP, &cookie->flags);
62456 wake_up_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP);
62457 } else {
62458- fscache_stat(&fscache_n_object_created);
62459+ fscache_stat_unchecked(&fscache_n_object_created);
62460 }
62461
62462 set_bit(FSCACHE_OBJECT_IS_AVAILABLE, &object->flags);
62463@@ -575,7 +575,7 @@ static const struct fscache_state *fscache_object_available(struct fscache_objec
62464 fscache_stat_d(&fscache_n_cop_lookup_complete);
62465
62466 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
62467- fscache_stat(&fscache_n_object_avail);
62468+ fscache_stat_unchecked(&fscache_n_object_avail);
62469
62470 _leave("");
62471 return transit_to(JUMPSTART_DEPS);
62472@@ -722,7 +722,7 @@ static const struct fscache_state *fscache_drop_object(struct fscache_object *ob
62473
62474 /* this just shifts the object release to the work processor */
62475 fscache_put_object(object);
62476- fscache_stat(&fscache_n_object_dead);
62477+ fscache_stat_unchecked(&fscache_n_object_dead);
62478
62479 _leave("");
62480 return transit_to(OBJECT_DEAD);
62481@@ -887,7 +887,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
62482 enum fscache_checkaux result;
62483
62484 if (!object->cookie->def->check_aux) {
62485- fscache_stat(&fscache_n_checkaux_none);
62486+ fscache_stat_unchecked(&fscache_n_checkaux_none);
62487 return FSCACHE_CHECKAUX_OKAY;
62488 }
62489
62490@@ -896,17 +896,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
62491 switch (result) {
62492 /* entry okay as is */
62493 case FSCACHE_CHECKAUX_OKAY:
62494- fscache_stat(&fscache_n_checkaux_okay);
62495+ fscache_stat_unchecked(&fscache_n_checkaux_okay);
62496 break;
62497
62498 /* entry requires update */
62499 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
62500- fscache_stat(&fscache_n_checkaux_update);
62501+ fscache_stat_unchecked(&fscache_n_checkaux_update);
62502 break;
62503
62504 /* entry requires deletion */
62505 case FSCACHE_CHECKAUX_OBSOLETE:
62506- fscache_stat(&fscache_n_checkaux_obsolete);
62507+ fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
62508 break;
62509
62510 default:
62511@@ -993,7 +993,7 @@ static const struct fscache_state *fscache_invalidate_object(struct fscache_obje
62512 {
62513 const struct fscache_state *s;
62514
62515- fscache_stat(&fscache_n_invalidates_run);
62516+ fscache_stat_unchecked(&fscache_n_invalidates_run);
62517 fscache_stat(&fscache_n_cop_invalidate_object);
62518 s = _fscache_invalidate_object(object, event);
62519 fscache_stat_d(&fscache_n_cop_invalidate_object);
62520@@ -1008,7 +1008,7 @@ static const struct fscache_state *fscache_update_object(struct fscache_object *
62521 {
62522 _enter("{OBJ%x},%d", object->debug_id, event);
62523
62524- fscache_stat(&fscache_n_updates_run);
62525+ fscache_stat_unchecked(&fscache_n_updates_run);
62526 fscache_stat(&fscache_n_cop_update_object);
62527 object->cache->ops->update_object(object);
62528 fscache_stat_d(&fscache_n_cop_update_object);
62529diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
62530index e7b87a0..a85d47a 100644
62531--- a/fs/fscache/operation.c
62532+++ b/fs/fscache/operation.c
62533@@ -17,7 +17,7 @@
62534 #include <linux/slab.h>
62535 #include "internal.h"
62536
62537-atomic_t fscache_op_debug_id;
62538+atomic_unchecked_t fscache_op_debug_id;
62539 EXPORT_SYMBOL(fscache_op_debug_id);
62540
62541 /**
62542@@ -39,7 +39,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
62543 ASSERTCMP(atomic_read(&op->usage), >, 0);
62544 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_IN_PROGRESS);
62545
62546- fscache_stat(&fscache_n_op_enqueue);
62547+ fscache_stat_unchecked(&fscache_n_op_enqueue);
62548 switch (op->flags & FSCACHE_OP_TYPE) {
62549 case FSCACHE_OP_ASYNC:
62550 _debug("queue async");
62551@@ -72,7 +72,7 @@ static void fscache_run_op(struct fscache_object *object,
62552 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
62553 if (op->processor)
62554 fscache_enqueue_operation(op);
62555- fscache_stat(&fscache_n_op_run);
62556+ fscache_stat_unchecked(&fscache_n_op_run);
62557 }
62558
62559 /*
62560@@ -104,11 +104,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
62561 if (object->n_in_progress > 0) {
62562 atomic_inc(&op->usage);
62563 list_add_tail(&op->pend_link, &object->pending_ops);
62564- fscache_stat(&fscache_n_op_pend);
62565+ fscache_stat_unchecked(&fscache_n_op_pend);
62566 } else if (!list_empty(&object->pending_ops)) {
62567 atomic_inc(&op->usage);
62568 list_add_tail(&op->pend_link, &object->pending_ops);
62569- fscache_stat(&fscache_n_op_pend);
62570+ fscache_stat_unchecked(&fscache_n_op_pend);
62571 fscache_start_operations(object);
62572 } else {
62573 ASSERTCMP(object->n_in_progress, ==, 0);
62574@@ -124,7 +124,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
62575 object->n_exclusive++; /* reads and writes must wait */
62576 atomic_inc(&op->usage);
62577 list_add_tail(&op->pend_link, &object->pending_ops);
62578- fscache_stat(&fscache_n_op_pend);
62579+ fscache_stat_unchecked(&fscache_n_op_pend);
62580 ret = 0;
62581 } else {
62582 /* If we're in any other state, there must have been an I/O
62583@@ -211,11 +211,11 @@ int fscache_submit_op(struct fscache_object *object,
62584 if (object->n_exclusive > 0) {
62585 atomic_inc(&op->usage);
62586 list_add_tail(&op->pend_link, &object->pending_ops);
62587- fscache_stat(&fscache_n_op_pend);
62588+ fscache_stat_unchecked(&fscache_n_op_pend);
62589 } else if (!list_empty(&object->pending_ops)) {
62590 atomic_inc(&op->usage);
62591 list_add_tail(&op->pend_link, &object->pending_ops);
62592- fscache_stat(&fscache_n_op_pend);
62593+ fscache_stat_unchecked(&fscache_n_op_pend);
62594 fscache_start_operations(object);
62595 } else {
62596 ASSERTCMP(object->n_exclusive, ==, 0);
62597@@ -227,10 +227,10 @@ int fscache_submit_op(struct fscache_object *object,
62598 object->n_ops++;
62599 atomic_inc(&op->usage);
62600 list_add_tail(&op->pend_link, &object->pending_ops);
62601- fscache_stat(&fscache_n_op_pend);
62602+ fscache_stat_unchecked(&fscache_n_op_pend);
62603 ret = 0;
62604 } else if (fscache_object_is_dying(object)) {
62605- fscache_stat(&fscache_n_op_rejected);
62606+ fscache_stat_unchecked(&fscache_n_op_rejected);
62607 op->state = FSCACHE_OP_ST_CANCELLED;
62608 ret = -ENOBUFS;
62609 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
62610@@ -309,7 +309,7 @@ int fscache_cancel_op(struct fscache_operation *op,
62611 ret = -EBUSY;
62612 if (op->state == FSCACHE_OP_ST_PENDING) {
62613 ASSERT(!list_empty(&op->pend_link));
62614- fscache_stat(&fscache_n_op_cancelled);
62615+ fscache_stat_unchecked(&fscache_n_op_cancelled);
62616 list_del_init(&op->pend_link);
62617 if (do_cancel)
62618 do_cancel(op);
62619@@ -341,7 +341,7 @@ void fscache_cancel_all_ops(struct fscache_object *object)
62620 while (!list_empty(&object->pending_ops)) {
62621 op = list_entry(object->pending_ops.next,
62622 struct fscache_operation, pend_link);
62623- fscache_stat(&fscache_n_op_cancelled);
62624+ fscache_stat_unchecked(&fscache_n_op_cancelled);
62625 list_del_init(&op->pend_link);
62626
62627 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_PENDING);
62628@@ -413,7 +413,7 @@ void fscache_put_operation(struct fscache_operation *op)
62629 op->state, ==, FSCACHE_OP_ST_CANCELLED);
62630 op->state = FSCACHE_OP_ST_DEAD;
62631
62632- fscache_stat(&fscache_n_op_release);
62633+ fscache_stat_unchecked(&fscache_n_op_release);
62634
62635 if (op->release) {
62636 op->release(op);
62637@@ -432,7 +432,7 @@ void fscache_put_operation(struct fscache_operation *op)
62638 * lock, and defer it otherwise */
62639 if (!spin_trylock(&object->lock)) {
62640 _debug("defer put");
62641- fscache_stat(&fscache_n_op_deferred_release);
62642+ fscache_stat_unchecked(&fscache_n_op_deferred_release);
62643
62644 cache = object->cache;
62645 spin_lock(&cache->op_gc_list_lock);
62646@@ -485,7 +485,7 @@ void fscache_operation_gc(struct work_struct *work)
62647
62648 _debug("GC DEFERRED REL OBJ%x OP%x",
62649 object->debug_id, op->debug_id);
62650- fscache_stat(&fscache_n_op_gc);
62651+ fscache_stat_unchecked(&fscache_n_op_gc);
62652
62653 ASSERTCMP(atomic_read(&op->usage), ==, 0);
62654 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_DEAD);
62655diff --git a/fs/fscache/page.c b/fs/fscache/page.c
62656index de33b3f..8be4d29 100644
62657--- a/fs/fscache/page.c
62658+++ b/fs/fscache/page.c
62659@@ -74,7 +74,7 @@ try_again:
62660 val = radix_tree_lookup(&cookie->stores, page->index);
62661 if (!val) {
62662 rcu_read_unlock();
62663- fscache_stat(&fscache_n_store_vmscan_not_storing);
62664+ fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
62665 __fscache_uncache_page(cookie, page);
62666 return true;
62667 }
62668@@ -104,11 +104,11 @@ try_again:
62669 spin_unlock(&cookie->stores_lock);
62670
62671 if (xpage) {
62672- fscache_stat(&fscache_n_store_vmscan_cancelled);
62673- fscache_stat(&fscache_n_store_radix_deletes);
62674+ fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
62675+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
62676 ASSERTCMP(xpage, ==, page);
62677 } else {
62678- fscache_stat(&fscache_n_store_vmscan_gone);
62679+ fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
62680 }
62681
62682 wake_up_bit(&cookie->flags, 0);
62683@@ -123,11 +123,11 @@ page_busy:
62684 * sleeping on memory allocation, so we may need to impose a timeout
62685 * too. */
62686 if (!(gfp & __GFP_WAIT) || !(gfp & __GFP_FS)) {
62687- fscache_stat(&fscache_n_store_vmscan_busy);
62688+ fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
62689 return false;
62690 }
62691
62692- fscache_stat(&fscache_n_store_vmscan_wait);
62693+ fscache_stat_unchecked(&fscache_n_store_vmscan_wait);
62694 if (!release_page_wait_timeout(cookie, page))
62695 _debug("fscache writeout timeout page: %p{%lx}",
62696 page, page->index);
62697@@ -156,7 +156,7 @@ static void fscache_end_page_write(struct fscache_object *object,
62698 FSCACHE_COOKIE_STORING_TAG);
62699 if (!radix_tree_tag_get(&cookie->stores, page->index,
62700 FSCACHE_COOKIE_PENDING_TAG)) {
62701- fscache_stat(&fscache_n_store_radix_deletes);
62702+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
62703 xpage = radix_tree_delete(&cookie->stores, page->index);
62704 }
62705 spin_unlock(&cookie->stores_lock);
62706@@ -177,7 +177,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
62707
62708 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
62709
62710- fscache_stat(&fscache_n_attr_changed_calls);
62711+ fscache_stat_unchecked(&fscache_n_attr_changed_calls);
62712
62713 if (fscache_object_is_active(object)) {
62714 fscache_stat(&fscache_n_cop_attr_changed);
62715@@ -204,11 +204,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
62716
62717 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
62718
62719- fscache_stat(&fscache_n_attr_changed);
62720+ fscache_stat_unchecked(&fscache_n_attr_changed);
62721
62722 op = kzalloc(sizeof(*op), GFP_KERNEL);
62723 if (!op) {
62724- fscache_stat(&fscache_n_attr_changed_nomem);
62725+ fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
62726 _leave(" = -ENOMEM");
62727 return -ENOMEM;
62728 }
62729@@ -230,7 +230,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
62730 if (fscache_submit_exclusive_op(object, op) < 0)
62731 goto nobufs_dec;
62732 spin_unlock(&cookie->lock);
62733- fscache_stat(&fscache_n_attr_changed_ok);
62734+ fscache_stat_unchecked(&fscache_n_attr_changed_ok);
62735 fscache_put_operation(op);
62736 _leave(" = 0");
62737 return 0;
62738@@ -242,7 +242,7 @@ nobufs:
62739 kfree(op);
62740 if (wake_cookie)
62741 __fscache_wake_unused_cookie(cookie);
62742- fscache_stat(&fscache_n_attr_changed_nobufs);
62743+ fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
62744 _leave(" = %d", -ENOBUFS);
62745 return -ENOBUFS;
62746 }
62747@@ -281,7 +281,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
62748 /* allocate a retrieval operation and attempt to submit it */
62749 op = kzalloc(sizeof(*op), GFP_NOIO);
62750 if (!op) {
62751- fscache_stat(&fscache_n_retrievals_nomem);
62752+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
62753 return NULL;
62754 }
62755
62756@@ -311,12 +311,12 @@ int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
62757 return 0;
62758 }
62759
62760- fscache_stat(&fscache_n_retrievals_wait);
62761+ fscache_stat_unchecked(&fscache_n_retrievals_wait);
62762
62763 jif = jiffies;
62764 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
62765 TASK_INTERRUPTIBLE) != 0) {
62766- fscache_stat(&fscache_n_retrievals_intr);
62767+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
62768 _leave(" = -ERESTARTSYS");
62769 return -ERESTARTSYS;
62770 }
62771@@ -345,8 +345,8 @@ static void fscache_do_cancel_retrieval(struct fscache_operation *_op)
62772 */
62773 int fscache_wait_for_operation_activation(struct fscache_object *object,
62774 struct fscache_operation *op,
62775- atomic_t *stat_op_waits,
62776- atomic_t *stat_object_dead,
62777+ atomic_unchecked_t *stat_op_waits,
62778+ atomic_unchecked_t *stat_object_dead,
62779 void (*do_cancel)(struct fscache_operation *))
62780 {
62781 int ret;
62782@@ -356,7 +356,7 @@ int fscache_wait_for_operation_activation(struct fscache_object *object,
62783
62784 _debug(">>> WT");
62785 if (stat_op_waits)
62786- fscache_stat(stat_op_waits);
62787+ fscache_stat_unchecked(stat_op_waits);
62788 if (wait_on_bit(&op->flags, FSCACHE_OP_WAITING,
62789 TASK_INTERRUPTIBLE) != 0) {
62790 ret = fscache_cancel_op(op, do_cancel);
62791@@ -373,7 +373,7 @@ int fscache_wait_for_operation_activation(struct fscache_object *object,
62792 check_if_dead:
62793 if (op->state == FSCACHE_OP_ST_CANCELLED) {
62794 if (stat_object_dead)
62795- fscache_stat(stat_object_dead);
62796+ fscache_stat_unchecked(stat_object_dead);
62797 _leave(" = -ENOBUFS [cancelled]");
62798 return -ENOBUFS;
62799 }
62800@@ -381,7 +381,7 @@ check_if_dead:
62801 pr_err("%s() = -ENOBUFS [obj dead %d]\n", __func__, op->state);
62802 fscache_cancel_op(op, do_cancel);
62803 if (stat_object_dead)
62804- fscache_stat(stat_object_dead);
62805+ fscache_stat_unchecked(stat_object_dead);
62806 return -ENOBUFS;
62807 }
62808 return 0;
62809@@ -409,7 +409,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
62810
62811 _enter("%p,%p,,,", cookie, page);
62812
62813- fscache_stat(&fscache_n_retrievals);
62814+ fscache_stat_unchecked(&fscache_n_retrievals);
62815
62816 if (hlist_empty(&cookie->backing_objects))
62817 goto nobufs;
62818@@ -451,7 +451,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
62819 goto nobufs_unlock_dec;
62820 spin_unlock(&cookie->lock);
62821
62822- fscache_stat(&fscache_n_retrieval_ops);
62823+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
62824
62825 /* pin the netfs read context in case we need to do the actual netfs
62826 * read because we've encountered a cache read failure */
62827@@ -482,15 +482,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
62828
62829 error:
62830 if (ret == -ENOMEM)
62831- fscache_stat(&fscache_n_retrievals_nomem);
62832+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
62833 else if (ret == -ERESTARTSYS)
62834- fscache_stat(&fscache_n_retrievals_intr);
62835+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
62836 else if (ret == -ENODATA)
62837- fscache_stat(&fscache_n_retrievals_nodata);
62838+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
62839 else if (ret < 0)
62840- fscache_stat(&fscache_n_retrievals_nobufs);
62841+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
62842 else
62843- fscache_stat(&fscache_n_retrievals_ok);
62844+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
62845
62846 fscache_put_retrieval(op);
62847 _leave(" = %d", ret);
62848@@ -505,7 +505,7 @@ nobufs_unlock:
62849 __fscache_wake_unused_cookie(cookie);
62850 kfree(op);
62851 nobufs:
62852- fscache_stat(&fscache_n_retrievals_nobufs);
62853+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
62854 _leave(" = -ENOBUFS");
62855 return -ENOBUFS;
62856 }
62857@@ -544,7 +544,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
62858
62859 _enter("%p,,%d,,,", cookie, *nr_pages);
62860
62861- fscache_stat(&fscache_n_retrievals);
62862+ fscache_stat_unchecked(&fscache_n_retrievals);
62863
62864 if (hlist_empty(&cookie->backing_objects))
62865 goto nobufs;
62866@@ -582,7 +582,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
62867 goto nobufs_unlock_dec;
62868 spin_unlock(&cookie->lock);
62869
62870- fscache_stat(&fscache_n_retrieval_ops);
62871+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
62872
62873 /* pin the netfs read context in case we need to do the actual netfs
62874 * read because we've encountered a cache read failure */
62875@@ -613,15 +613,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
62876
62877 error:
62878 if (ret == -ENOMEM)
62879- fscache_stat(&fscache_n_retrievals_nomem);
62880+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
62881 else if (ret == -ERESTARTSYS)
62882- fscache_stat(&fscache_n_retrievals_intr);
62883+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
62884 else if (ret == -ENODATA)
62885- fscache_stat(&fscache_n_retrievals_nodata);
62886+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
62887 else if (ret < 0)
62888- fscache_stat(&fscache_n_retrievals_nobufs);
62889+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
62890 else
62891- fscache_stat(&fscache_n_retrievals_ok);
62892+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
62893
62894 fscache_put_retrieval(op);
62895 _leave(" = %d", ret);
62896@@ -636,7 +636,7 @@ nobufs_unlock:
62897 if (wake_cookie)
62898 __fscache_wake_unused_cookie(cookie);
62899 nobufs:
62900- fscache_stat(&fscache_n_retrievals_nobufs);
62901+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
62902 _leave(" = -ENOBUFS");
62903 return -ENOBUFS;
62904 }
62905@@ -661,7 +661,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
62906
62907 _enter("%p,%p,,,", cookie, page);
62908
62909- fscache_stat(&fscache_n_allocs);
62910+ fscache_stat_unchecked(&fscache_n_allocs);
62911
62912 if (hlist_empty(&cookie->backing_objects))
62913 goto nobufs;
62914@@ -695,7 +695,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
62915 goto nobufs_unlock_dec;
62916 spin_unlock(&cookie->lock);
62917
62918- fscache_stat(&fscache_n_alloc_ops);
62919+ fscache_stat_unchecked(&fscache_n_alloc_ops);
62920
62921 ret = fscache_wait_for_operation_activation(
62922 object, &op->op,
62923@@ -712,11 +712,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
62924
62925 error:
62926 if (ret == -ERESTARTSYS)
62927- fscache_stat(&fscache_n_allocs_intr);
62928+ fscache_stat_unchecked(&fscache_n_allocs_intr);
62929 else if (ret < 0)
62930- fscache_stat(&fscache_n_allocs_nobufs);
62931+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
62932 else
62933- fscache_stat(&fscache_n_allocs_ok);
62934+ fscache_stat_unchecked(&fscache_n_allocs_ok);
62935
62936 fscache_put_retrieval(op);
62937 _leave(" = %d", ret);
62938@@ -730,7 +730,7 @@ nobufs_unlock:
62939 if (wake_cookie)
62940 __fscache_wake_unused_cookie(cookie);
62941 nobufs:
62942- fscache_stat(&fscache_n_allocs_nobufs);
62943+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
62944 _leave(" = -ENOBUFS");
62945 return -ENOBUFS;
62946 }
62947@@ -806,7 +806,7 @@ static void fscache_write_op(struct fscache_operation *_op)
62948
62949 spin_lock(&cookie->stores_lock);
62950
62951- fscache_stat(&fscache_n_store_calls);
62952+ fscache_stat_unchecked(&fscache_n_store_calls);
62953
62954 /* find a page to store */
62955 page = NULL;
62956@@ -817,7 +817,7 @@ static void fscache_write_op(struct fscache_operation *_op)
62957 page = results[0];
62958 _debug("gang %d [%lx]", n, page->index);
62959 if (page->index > op->store_limit) {
62960- fscache_stat(&fscache_n_store_pages_over_limit);
62961+ fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
62962 goto superseded;
62963 }
62964
62965@@ -829,7 +829,7 @@ static void fscache_write_op(struct fscache_operation *_op)
62966 spin_unlock(&cookie->stores_lock);
62967 spin_unlock(&object->lock);
62968
62969- fscache_stat(&fscache_n_store_pages);
62970+ fscache_stat_unchecked(&fscache_n_store_pages);
62971 fscache_stat(&fscache_n_cop_write_page);
62972 ret = object->cache->ops->write_page(op, page);
62973 fscache_stat_d(&fscache_n_cop_write_page);
62974@@ -933,7 +933,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
62975 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
62976 ASSERT(PageFsCache(page));
62977
62978- fscache_stat(&fscache_n_stores);
62979+ fscache_stat_unchecked(&fscache_n_stores);
62980
62981 if (test_bit(FSCACHE_COOKIE_INVALIDATING, &cookie->flags)) {
62982 _leave(" = -ENOBUFS [invalidating]");
62983@@ -992,7 +992,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
62984 spin_unlock(&cookie->stores_lock);
62985 spin_unlock(&object->lock);
62986
62987- op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
62988+ op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
62989 op->store_limit = object->store_limit;
62990
62991 __fscache_use_cookie(cookie);
62992@@ -1001,8 +1001,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
62993
62994 spin_unlock(&cookie->lock);
62995 radix_tree_preload_end();
62996- fscache_stat(&fscache_n_store_ops);
62997- fscache_stat(&fscache_n_stores_ok);
62998+ fscache_stat_unchecked(&fscache_n_store_ops);
62999+ fscache_stat_unchecked(&fscache_n_stores_ok);
63000
63001 /* the work queue now carries its own ref on the object */
63002 fscache_put_operation(&op->op);
63003@@ -1010,14 +1010,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
63004 return 0;
63005
63006 already_queued:
63007- fscache_stat(&fscache_n_stores_again);
63008+ fscache_stat_unchecked(&fscache_n_stores_again);
63009 already_pending:
63010 spin_unlock(&cookie->stores_lock);
63011 spin_unlock(&object->lock);
63012 spin_unlock(&cookie->lock);
63013 radix_tree_preload_end();
63014 kfree(op);
63015- fscache_stat(&fscache_n_stores_ok);
63016+ fscache_stat_unchecked(&fscache_n_stores_ok);
63017 _leave(" = 0");
63018 return 0;
63019
63020@@ -1039,14 +1039,14 @@ nobufs:
63021 kfree(op);
63022 if (wake_cookie)
63023 __fscache_wake_unused_cookie(cookie);
63024- fscache_stat(&fscache_n_stores_nobufs);
63025+ fscache_stat_unchecked(&fscache_n_stores_nobufs);
63026 _leave(" = -ENOBUFS");
63027 return -ENOBUFS;
63028
63029 nomem_free:
63030 kfree(op);
63031 nomem:
63032- fscache_stat(&fscache_n_stores_oom);
63033+ fscache_stat_unchecked(&fscache_n_stores_oom);
63034 _leave(" = -ENOMEM");
63035 return -ENOMEM;
63036 }
63037@@ -1064,7 +1064,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
63038 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
63039 ASSERTCMP(page, !=, NULL);
63040
63041- fscache_stat(&fscache_n_uncaches);
63042+ fscache_stat_unchecked(&fscache_n_uncaches);
63043
63044 /* cache withdrawal may beat us to it */
63045 if (!PageFsCache(page))
63046@@ -1115,7 +1115,7 @@ void fscache_mark_page_cached(struct fscache_retrieval *op, struct page *page)
63047 struct fscache_cookie *cookie = op->op.object->cookie;
63048
63049 #ifdef CONFIG_FSCACHE_STATS
63050- atomic_inc(&fscache_n_marks);
63051+ atomic_inc_unchecked(&fscache_n_marks);
63052 #endif
63053
63054 _debug("- mark %p{%lx}", page, page->index);
63055diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
63056index 40d13c7..ddf52b9 100644
63057--- a/fs/fscache/stats.c
63058+++ b/fs/fscache/stats.c
63059@@ -18,99 +18,99 @@
63060 /*
63061 * operation counters
63062 */
63063-atomic_t fscache_n_op_pend;
63064-atomic_t fscache_n_op_run;
63065-atomic_t fscache_n_op_enqueue;
63066-atomic_t fscache_n_op_requeue;
63067-atomic_t fscache_n_op_deferred_release;
63068-atomic_t fscache_n_op_release;
63069-atomic_t fscache_n_op_gc;
63070-atomic_t fscache_n_op_cancelled;
63071-atomic_t fscache_n_op_rejected;
63072+atomic_unchecked_t fscache_n_op_pend;
63073+atomic_unchecked_t fscache_n_op_run;
63074+atomic_unchecked_t fscache_n_op_enqueue;
63075+atomic_unchecked_t fscache_n_op_requeue;
63076+atomic_unchecked_t fscache_n_op_deferred_release;
63077+atomic_unchecked_t fscache_n_op_release;
63078+atomic_unchecked_t fscache_n_op_gc;
63079+atomic_unchecked_t fscache_n_op_cancelled;
63080+atomic_unchecked_t fscache_n_op_rejected;
63081
63082-atomic_t fscache_n_attr_changed;
63083-atomic_t fscache_n_attr_changed_ok;
63084-atomic_t fscache_n_attr_changed_nobufs;
63085-atomic_t fscache_n_attr_changed_nomem;
63086-atomic_t fscache_n_attr_changed_calls;
63087+atomic_unchecked_t fscache_n_attr_changed;
63088+atomic_unchecked_t fscache_n_attr_changed_ok;
63089+atomic_unchecked_t fscache_n_attr_changed_nobufs;
63090+atomic_unchecked_t fscache_n_attr_changed_nomem;
63091+atomic_unchecked_t fscache_n_attr_changed_calls;
63092
63093-atomic_t fscache_n_allocs;
63094-atomic_t fscache_n_allocs_ok;
63095-atomic_t fscache_n_allocs_wait;
63096-atomic_t fscache_n_allocs_nobufs;
63097-atomic_t fscache_n_allocs_intr;
63098-atomic_t fscache_n_allocs_object_dead;
63099-atomic_t fscache_n_alloc_ops;
63100-atomic_t fscache_n_alloc_op_waits;
63101+atomic_unchecked_t fscache_n_allocs;
63102+atomic_unchecked_t fscache_n_allocs_ok;
63103+atomic_unchecked_t fscache_n_allocs_wait;
63104+atomic_unchecked_t fscache_n_allocs_nobufs;
63105+atomic_unchecked_t fscache_n_allocs_intr;
63106+atomic_unchecked_t fscache_n_allocs_object_dead;
63107+atomic_unchecked_t fscache_n_alloc_ops;
63108+atomic_unchecked_t fscache_n_alloc_op_waits;
63109
63110-atomic_t fscache_n_retrievals;
63111-atomic_t fscache_n_retrievals_ok;
63112-atomic_t fscache_n_retrievals_wait;
63113-atomic_t fscache_n_retrievals_nodata;
63114-atomic_t fscache_n_retrievals_nobufs;
63115-atomic_t fscache_n_retrievals_intr;
63116-atomic_t fscache_n_retrievals_nomem;
63117-atomic_t fscache_n_retrievals_object_dead;
63118-atomic_t fscache_n_retrieval_ops;
63119-atomic_t fscache_n_retrieval_op_waits;
63120+atomic_unchecked_t fscache_n_retrievals;
63121+atomic_unchecked_t fscache_n_retrievals_ok;
63122+atomic_unchecked_t fscache_n_retrievals_wait;
63123+atomic_unchecked_t fscache_n_retrievals_nodata;
63124+atomic_unchecked_t fscache_n_retrievals_nobufs;
63125+atomic_unchecked_t fscache_n_retrievals_intr;
63126+atomic_unchecked_t fscache_n_retrievals_nomem;
63127+atomic_unchecked_t fscache_n_retrievals_object_dead;
63128+atomic_unchecked_t fscache_n_retrieval_ops;
63129+atomic_unchecked_t fscache_n_retrieval_op_waits;
63130
63131-atomic_t fscache_n_stores;
63132-atomic_t fscache_n_stores_ok;
63133-atomic_t fscache_n_stores_again;
63134-atomic_t fscache_n_stores_nobufs;
63135-atomic_t fscache_n_stores_oom;
63136-atomic_t fscache_n_store_ops;
63137-atomic_t fscache_n_store_calls;
63138-atomic_t fscache_n_store_pages;
63139-atomic_t fscache_n_store_radix_deletes;
63140-atomic_t fscache_n_store_pages_over_limit;
63141+atomic_unchecked_t fscache_n_stores;
63142+atomic_unchecked_t fscache_n_stores_ok;
63143+atomic_unchecked_t fscache_n_stores_again;
63144+atomic_unchecked_t fscache_n_stores_nobufs;
63145+atomic_unchecked_t fscache_n_stores_oom;
63146+atomic_unchecked_t fscache_n_store_ops;
63147+atomic_unchecked_t fscache_n_store_calls;
63148+atomic_unchecked_t fscache_n_store_pages;
63149+atomic_unchecked_t fscache_n_store_radix_deletes;
63150+atomic_unchecked_t fscache_n_store_pages_over_limit;
63151
63152-atomic_t fscache_n_store_vmscan_not_storing;
63153-atomic_t fscache_n_store_vmscan_gone;
63154-atomic_t fscache_n_store_vmscan_busy;
63155-atomic_t fscache_n_store_vmscan_cancelled;
63156-atomic_t fscache_n_store_vmscan_wait;
63157+atomic_unchecked_t fscache_n_store_vmscan_not_storing;
63158+atomic_unchecked_t fscache_n_store_vmscan_gone;
63159+atomic_unchecked_t fscache_n_store_vmscan_busy;
63160+atomic_unchecked_t fscache_n_store_vmscan_cancelled;
63161+atomic_unchecked_t fscache_n_store_vmscan_wait;
63162
63163-atomic_t fscache_n_marks;
63164-atomic_t fscache_n_uncaches;
63165+atomic_unchecked_t fscache_n_marks;
63166+atomic_unchecked_t fscache_n_uncaches;
63167
63168-atomic_t fscache_n_acquires;
63169-atomic_t fscache_n_acquires_null;
63170-atomic_t fscache_n_acquires_no_cache;
63171-atomic_t fscache_n_acquires_ok;
63172-atomic_t fscache_n_acquires_nobufs;
63173-atomic_t fscache_n_acquires_oom;
63174+atomic_unchecked_t fscache_n_acquires;
63175+atomic_unchecked_t fscache_n_acquires_null;
63176+atomic_unchecked_t fscache_n_acquires_no_cache;
63177+atomic_unchecked_t fscache_n_acquires_ok;
63178+atomic_unchecked_t fscache_n_acquires_nobufs;
63179+atomic_unchecked_t fscache_n_acquires_oom;
63180
63181-atomic_t fscache_n_invalidates;
63182-atomic_t fscache_n_invalidates_run;
63183+atomic_unchecked_t fscache_n_invalidates;
63184+atomic_unchecked_t fscache_n_invalidates_run;
63185
63186-atomic_t fscache_n_updates;
63187-atomic_t fscache_n_updates_null;
63188-atomic_t fscache_n_updates_run;
63189+atomic_unchecked_t fscache_n_updates;
63190+atomic_unchecked_t fscache_n_updates_null;
63191+atomic_unchecked_t fscache_n_updates_run;
63192
63193-atomic_t fscache_n_relinquishes;
63194-atomic_t fscache_n_relinquishes_null;
63195-atomic_t fscache_n_relinquishes_waitcrt;
63196-atomic_t fscache_n_relinquishes_retire;
63197+atomic_unchecked_t fscache_n_relinquishes;
63198+atomic_unchecked_t fscache_n_relinquishes_null;
63199+atomic_unchecked_t fscache_n_relinquishes_waitcrt;
63200+atomic_unchecked_t fscache_n_relinquishes_retire;
63201
63202-atomic_t fscache_n_cookie_index;
63203-atomic_t fscache_n_cookie_data;
63204-atomic_t fscache_n_cookie_special;
63205+atomic_unchecked_t fscache_n_cookie_index;
63206+atomic_unchecked_t fscache_n_cookie_data;
63207+atomic_unchecked_t fscache_n_cookie_special;
63208
63209-atomic_t fscache_n_object_alloc;
63210-atomic_t fscache_n_object_no_alloc;
63211-atomic_t fscache_n_object_lookups;
63212-atomic_t fscache_n_object_lookups_negative;
63213-atomic_t fscache_n_object_lookups_positive;
63214-atomic_t fscache_n_object_lookups_timed_out;
63215-atomic_t fscache_n_object_created;
63216-atomic_t fscache_n_object_avail;
63217-atomic_t fscache_n_object_dead;
63218+atomic_unchecked_t fscache_n_object_alloc;
63219+atomic_unchecked_t fscache_n_object_no_alloc;
63220+atomic_unchecked_t fscache_n_object_lookups;
63221+atomic_unchecked_t fscache_n_object_lookups_negative;
63222+atomic_unchecked_t fscache_n_object_lookups_positive;
63223+atomic_unchecked_t fscache_n_object_lookups_timed_out;
63224+atomic_unchecked_t fscache_n_object_created;
63225+atomic_unchecked_t fscache_n_object_avail;
63226+atomic_unchecked_t fscache_n_object_dead;
63227
63228-atomic_t fscache_n_checkaux_none;
63229-atomic_t fscache_n_checkaux_okay;
63230-atomic_t fscache_n_checkaux_update;
63231-atomic_t fscache_n_checkaux_obsolete;
63232+atomic_unchecked_t fscache_n_checkaux_none;
63233+atomic_unchecked_t fscache_n_checkaux_okay;
63234+atomic_unchecked_t fscache_n_checkaux_update;
63235+atomic_unchecked_t fscache_n_checkaux_obsolete;
63236
63237 atomic_t fscache_n_cop_alloc_object;
63238 atomic_t fscache_n_cop_lookup_object;
63239@@ -138,118 +138,118 @@ static int fscache_stats_show(struct seq_file *m, void *v)
63240 seq_puts(m, "FS-Cache statistics\n");
63241
63242 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
63243- atomic_read(&fscache_n_cookie_index),
63244- atomic_read(&fscache_n_cookie_data),
63245- atomic_read(&fscache_n_cookie_special));
63246+ atomic_read_unchecked(&fscache_n_cookie_index),
63247+ atomic_read_unchecked(&fscache_n_cookie_data),
63248+ atomic_read_unchecked(&fscache_n_cookie_special));
63249
63250 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
63251- atomic_read(&fscache_n_object_alloc),
63252- atomic_read(&fscache_n_object_no_alloc),
63253- atomic_read(&fscache_n_object_avail),
63254- atomic_read(&fscache_n_object_dead));
63255+ atomic_read_unchecked(&fscache_n_object_alloc),
63256+ atomic_read_unchecked(&fscache_n_object_no_alloc),
63257+ atomic_read_unchecked(&fscache_n_object_avail),
63258+ atomic_read_unchecked(&fscache_n_object_dead));
63259 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
63260- atomic_read(&fscache_n_checkaux_none),
63261- atomic_read(&fscache_n_checkaux_okay),
63262- atomic_read(&fscache_n_checkaux_update),
63263- atomic_read(&fscache_n_checkaux_obsolete));
63264+ atomic_read_unchecked(&fscache_n_checkaux_none),
63265+ atomic_read_unchecked(&fscache_n_checkaux_okay),
63266+ atomic_read_unchecked(&fscache_n_checkaux_update),
63267+ atomic_read_unchecked(&fscache_n_checkaux_obsolete));
63268
63269 seq_printf(m, "Pages : mrk=%u unc=%u\n",
63270- atomic_read(&fscache_n_marks),
63271- atomic_read(&fscache_n_uncaches));
63272+ atomic_read_unchecked(&fscache_n_marks),
63273+ atomic_read_unchecked(&fscache_n_uncaches));
63274
63275 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
63276 " oom=%u\n",
63277- atomic_read(&fscache_n_acquires),
63278- atomic_read(&fscache_n_acquires_null),
63279- atomic_read(&fscache_n_acquires_no_cache),
63280- atomic_read(&fscache_n_acquires_ok),
63281- atomic_read(&fscache_n_acquires_nobufs),
63282- atomic_read(&fscache_n_acquires_oom));
63283+ atomic_read_unchecked(&fscache_n_acquires),
63284+ atomic_read_unchecked(&fscache_n_acquires_null),
63285+ atomic_read_unchecked(&fscache_n_acquires_no_cache),
63286+ atomic_read_unchecked(&fscache_n_acquires_ok),
63287+ atomic_read_unchecked(&fscache_n_acquires_nobufs),
63288+ atomic_read_unchecked(&fscache_n_acquires_oom));
63289
63290 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
63291- atomic_read(&fscache_n_object_lookups),
63292- atomic_read(&fscache_n_object_lookups_negative),
63293- atomic_read(&fscache_n_object_lookups_positive),
63294- atomic_read(&fscache_n_object_created),
63295- atomic_read(&fscache_n_object_lookups_timed_out));
63296+ atomic_read_unchecked(&fscache_n_object_lookups),
63297+ atomic_read_unchecked(&fscache_n_object_lookups_negative),
63298+ atomic_read_unchecked(&fscache_n_object_lookups_positive),
63299+ atomic_read_unchecked(&fscache_n_object_created),
63300+ atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
63301
63302 seq_printf(m, "Invals : n=%u run=%u\n",
63303- atomic_read(&fscache_n_invalidates),
63304- atomic_read(&fscache_n_invalidates_run));
63305+ atomic_read_unchecked(&fscache_n_invalidates),
63306+ atomic_read_unchecked(&fscache_n_invalidates_run));
63307
63308 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
63309- atomic_read(&fscache_n_updates),
63310- atomic_read(&fscache_n_updates_null),
63311- atomic_read(&fscache_n_updates_run));
63312+ atomic_read_unchecked(&fscache_n_updates),
63313+ atomic_read_unchecked(&fscache_n_updates_null),
63314+ atomic_read_unchecked(&fscache_n_updates_run));
63315
63316 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
63317- atomic_read(&fscache_n_relinquishes),
63318- atomic_read(&fscache_n_relinquishes_null),
63319- atomic_read(&fscache_n_relinquishes_waitcrt),
63320- atomic_read(&fscache_n_relinquishes_retire));
63321+ atomic_read_unchecked(&fscache_n_relinquishes),
63322+ atomic_read_unchecked(&fscache_n_relinquishes_null),
63323+ atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
63324+ atomic_read_unchecked(&fscache_n_relinquishes_retire));
63325
63326 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
63327- atomic_read(&fscache_n_attr_changed),
63328- atomic_read(&fscache_n_attr_changed_ok),
63329- atomic_read(&fscache_n_attr_changed_nobufs),
63330- atomic_read(&fscache_n_attr_changed_nomem),
63331- atomic_read(&fscache_n_attr_changed_calls));
63332+ atomic_read_unchecked(&fscache_n_attr_changed),
63333+ atomic_read_unchecked(&fscache_n_attr_changed_ok),
63334+ atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
63335+ atomic_read_unchecked(&fscache_n_attr_changed_nomem),
63336+ atomic_read_unchecked(&fscache_n_attr_changed_calls));
63337
63338 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
63339- atomic_read(&fscache_n_allocs),
63340- atomic_read(&fscache_n_allocs_ok),
63341- atomic_read(&fscache_n_allocs_wait),
63342- atomic_read(&fscache_n_allocs_nobufs),
63343- atomic_read(&fscache_n_allocs_intr));
63344+ atomic_read_unchecked(&fscache_n_allocs),
63345+ atomic_read_unchecked(&fscache_n_allocs_ok),
63346+ atomic_read_unchecked(&fscache_n_allocs_wait),
63347+ atomic_read_unchecked(&fscache_n_allocs_nobufs),
63348+ atomic_read_unchecked(&fscache_n_allocs_intr));
63349 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
63350- atomic_read(&fscache_n_alloc_ops),
63351- atomic_read(&fscache_n_alloc_op_waits),
63352- atomic_read(&fscache_n_allocs_object_dead));
63353+ atomic_read_unchecked(&fscache_n_alloc_ops),
63354+ atomic_read_unchecked(&fscache_n_alloc_op_waits),
63355+ atomic_read_unchecked(&fscache_n_allocs_object_dead));
63356
63357 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
63358 " int=%u oom=%u\n",
63359- atomic_read(&fscache_n_retrievals),
63360- atomic_read(&fscache_n_retrievals_ok),
63361- atomic_read(&fscache_n_retrievals_wait),
63362- atomic_read(&fscache_n_retrievals_nodata),
63363- atomic_read(&fscache_n_retrievals_nobufs),
63364- atomic_read(&fscache_n_retrievals_intr),
63365- atomic_read(&fscache_n_retrievals_nomem));
63366+ atomic_read_unchecked(&fscache_n_retrievals),
63367+ atomic_read_unchecked(&fscache_n_retrievals_ok),
63368+ atomic_read_unchecked(&fscache_n_retrievals_wait),
63369+ atomic_read_unchecked(&fscache_n_retrievals_nodata),
63370+ atomic_read_unchecked(&fscache_n_retrievals_nobufs),
63371+ atomic_read_unchecked(&fscache_n_retrievals_intr),
63372+ atomic_read_unchecked(&fscache_n_retrievals_nomem));
63373 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
63374- atomic_read(&fscache_n_retrieval_ops),
63375- atomic_read(&fscache_n_retrieval_op_waits),
63376- atomic_read(&fscache_n_retrievals_object_dead));
63377+ atomic_read_unchecked(&fscache_n_retrieval_ops),
63378+ atomic_read_unchecked(&fscache_n_retrieval_op_waits),
63379+ atomic_read_unchecked(&fscache_n_retrievals_object_dead));
63380
63381 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
63382- atomic_read(&fscache_n_stores),
63383- atomic_read(&fscache_n_stores_ok),
63384- atomic_read(&fscache_n_stores_again),
63385- atomic_read(&fscache_n_stores_nobufs),
63386- atomic_read(&fscache_n_stores_oom));
63387+ atomic_read_unchecked(&fscache_n_stores),
63388+ atomic_read_unchecked(&fscache_n_stores_ok),
63389+ atomic_read_unchecked(&fscache_n_stores_again),
63390+ atomic_read_unchecked(&fscache_n_stores_nobufs),
63391+ atomic_read_unchecked(&fscache_n_stores_oom));
63392 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
63393- atomic_read(&fscache_n_store_ops),
63394- atomic_read(&fscache_n_store_calls),
63395- atomic_read(&fscache_n_store_pages),
63396- atomic_read(&fscache_n_store_radix_deletes),
63397- atomic_read(&fscache_n_store_pages_over_limit));
63398+ atomic_read_unchecked(&fscache_n_store_ops),
63399+ atomic_read_unchecked(&fscache_n_store_calls),
63400+ atomic_read_unchecked(&fscache_n_store_pages),
63401+ atomic_read_unchecked(&fscache_n_store_radix_deletes),
63402+ atomic_read_unchecked(&fscache_n_store_pages_over_limit));
63403
63404 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u wt=%u\n",
63405- atomic_read(&fscache_n_store_vmscan_not_storing),
63406- atomic_read(&fscache_n_store_vmscan_gone),
63407- atomic_read(&fscache_n_store_vmscan_busy),
63408- atomic_read(&fscache_n_store_vmscan_cancelled),
63409- atomic_read(&fscache_n_store_vmscan_wait));
63410+ atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
63411+ atomic_read_unchecked(&fscache_n_store_vmscan_gone),
63412+ atomic_read_unchecked(&fscache_n_store_vmscan_busy),
63413+ atomic_read_unchecked(&fscache_n_store_vmscan_cancelled),
63414+ atomic_read_unchecked(&fscache_n_store_vmscan_wait));
63415
63416 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
63417- atomic_read(&fscache_n_op_pend),
63418- atomic_read(&fscache_n_op_run),
63419- atomic_read(&fscache_n_op_enqueue),
63420- atomic_read(&fscache_n_op_cancelled),
63421- atomic_read(&fscache_n_op_rejected));
63422+ atomic_read_unchecked(&fscache_n_op_pend),
63423+ atomic_read_unchecked(&fscache_n_op_run),
63424+ atomic_read_unchecked(&fscache_n_op_enqueue),
63425+ atomic_read_unchecked(&fscache_n_op_cancelled),
63426+ atomic_read_unchecked(&fscache_n_op_rejected));
63427 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
63428- atomic_read(&fscache_n_op_deferred_release),
63429- atomic_read(&fscache_n_op_release),
63430- atomic_read(&fscache_n_op_gc));
63431+ atomic_read_unchecked(&fscache_n_op_deferred_release),
63432+ atomic_read_unchecked(&fscache_n_op_release),
63433+ atomic_read_unchecked(&fscache_n_op_gc));
63434
63435 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
63436 atomic_read(&fscache_n_cop_alloc_object),
63437diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
63438index 966ace8..030a03a 100644
63439--- a/fs/fuse/cuse.c
63440+++ b/fs/fuse/cuse.c
63441@@ -611,10 +611,12 @@ static int __init cuse_init(void)
63442 INIT_LIST_HEAD(&cuse_conntbl[i]);
63443
63444 /* inherit and extend fuse_dev_operations */
63445- cuse_channel_fops = fuse_dev_operations;
63446- cuse_channel_fops.owner = THIS_MODULE;
63447- cuse_channel_fops.open = cuse_channel_open;
63448- cuse_channel_fops.release = cuse_channel_release;
63449+ pax_open_kernel();
63450+ memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
63451+ *(void **)&cuse_channel_fops.owner = THIS_MODULE;
63452+ *(void **)&cuse_channel_fops.open = cuse_channel_open;
63453+ *(void **)&cuse_channel_fops.release = cuse_channel_release;
63454+ pax_close_kernel();
63455
63456 cuse_class = class_create(THIS_MODULE, "cuse");
63457 if (IS_ERR(cuse_class))
63458diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
63459index ca88731..8e9c55d 100644
63460--- a/fs/fuse/dev.c
63461+++ b/fs/fuse/dev.c
63462@@ -1318,7 +1318,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
63463 ret = 0;
63464 pipe_lock(pipe);
63465
63466- if (!pipe->readers) {
63467+ if (!atomic_read(&pipe->readers)) {
63468 send_sig(SIGPIPE, current, 0);
63469 if (!ret)
63470 ret = -EPIPE;
63471@@ -1347,7 +1347,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
63472 page_nr++;
63473 ret += buf->len;
63474
63475- if (pipe->files)
63476+ if (atomic_read(&pipe->files))
63477 do_wakeup = 1;
63478 }
63479
63480diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
63481index dbab798..fefa22b 100644
63482--- a/fs/fuse/dir.c
63483+++ b/fs/fuse/dir.c
63484@@ -1474,7 +1474,7 @@ static char *read_link(struct dentry *dentry)
63485 return link;
63486 }
63487
63488-static void free_link(char *link)
63489+static void free_link(const char *link)
63490 {
63491 if (!IS_ERR(link))
63492 free_page((unsigned long) link);
63493diff --git a/fs/hostfs/hostfs_kern.c b/fs/hostfs/hostfs_kern.c
63494index fd62cae..3494dfa 100644
63495--- a/fs/hostfs/hostfs_kern.c
63496+++ b/fs/hostfs/hostfs_kern.c
63497@@ -908,7 +908,7 @@ static void *hostfs_follow_link(struct dentry *dentry, struct nameidata *nd)
63498
63499 static void hostfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
63500 {
63501- char *s = nd_get_link(nd);
63502+ const char *s = nd_get_link(nd);
63503 if (!IS_ERR(s))
63504 __putname(s);
63505 }
63506diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
63507index 1e2872b..7aea000 100644
63508--- a/fs/hugetlbfs/inode.c
63509+++ b/fs/hugetlbfs/inode.c
63510@@ -154,6 +154,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
63511 struct mm_struct *mm = current->mm;
63512 struct vm_area_struct *vma;
63513 struct hstate *h = hstate_file(file);
63514+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
63515 struct vm_unmapped_area_info info;
63516
63517 if (len & ~huge_page_mask(h))
63518@@ -167,17 +168,26 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
63519 return addr;
63520 }
63521
63522+#ifdef CONFIG_PAX_RANDMMAP
63523+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
63524+#endif
63525+
63526 if (addr) {
63527 addr = ALIGN(addr, huge_page_size(h));
63528 vma = find_vma(mm, addr);
63529- if (TASK_SIZE - len >= addr &&
63530- (!vma || addr + len <= vma->vm_start))
63531+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
63532 return addr;
63533 }
63534
63535 info.flags = 0;
63536 info.length = len;
63537 info.low_limit = TASK_UNMAPPED_BASE;
63538+
63539+#ifdef CONFIG_PAX_RANDMMAP
63540+ if (mm->pax_flags & MF_PAX_RANDMMAP)
63541+ info.low_limit += mm->delta_mmap;
63542+#endif
63543+
63544 info.high_limit = TASK_SIZE;
63545 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
63546 info.align_offset = 0;
63547@@ -919,7 +929,7 @@ static struct file_system_type hugetlbfs_fs_type = {
63548 };
63549 MODULE_ALIAS_FS("hugetlbfs");
63550
63551-static struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
63552+struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
63553
63554 static int can_do_hugetlb_shm(void)
63555 {
63556diff --git a/fs/inode.c b/fs/inode.c
63557index 26753ba..d19eb34 100644
63558--- a/fs/inode.c
63559+++ b/fs/inode.c
63560@@ -840,16 +840,20 @@ unsigned int get_next_ino(void)
63561 unsigned int *p = &get_cpu_var(last_ino);
63562 unsigned int res = *p;
63563
63564+start:
63565+
63566 #ifdef CONFIG_SMP
63567 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
63568- static atomic_t shared_last_ino;
63569- int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
63570+ static atomic_unchecked_t shared_last_ino;
63571+ int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
63572
63573 res = next - LAST_INO_BATCH;
63574 }
63575 #endif
63576
63577- *p = ++res;
63578+ if (unlikely(!++res))
63579+ goto start; /* never zero */
63580+ *p = res;
63581 put_cpu_var(last_ino);
63582 return res;
63583 }
63584diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
63585index 4a6cf28..d3a29d3 100644
63586--- a/fs/jffs2/erase.c
63587+++ b/fs/jffs2/erase.c
63588@@ -452,7 +452,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
63589 struct jffs2_unknown_node marker = {
63590 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
63591 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
63592- .totlen = cpu_to_je32(c->cleanmarker_size)
63593+ .totlen = cpu_to_je32(c->cleanmarker_size),
63594+ .hdr_crc = cpu_to_je32(0)
63595 };
63596
63597 jffs2_prealloc_raw_node_refs(c, jeb, 1);
63598diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
63599index 09ed551..45684f8 100644
63600--- a/fs/jffs2/wbuf.c
63601+++ b/fs/jffs2/wbuf.c
63602@@ -1023,7 +1023,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
63603 {
63604 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
63605 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
63606- .totlen = constant_cpu_to_je32(8)
63607+ .totlen = constant_cpu_to_je32(8),
63608+ .hdr_crc = constant_cpu_to_je32(0)
63609 };
63610
63611 /*
63612diff --git a/fs/jfs/super.c b/fs/jfs/super.c
63613index 93e897e..a863de4 100644
63614--- a/fs/jfs/super.c
63615+++ b/fs/jfs/super.c
63616@@ -893,7 +893,7 @@ static int __init init_jfs_fs(void)
63617
63618 jfs_inode_cachep =
63619 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
63620- SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
63621+ SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
63622 init_once);
63623 if (jfs_inode_cachep == NULL)
63624 return -ENOMEM;
63625diff --git a/fs/kernfs/dir.c b/fs/kernfs/dir.c
63626index 1c77193..ba73e66 100644
63627--- a/fs/kernfs/dir.c
63628+++ b/fs/kernfs/dir.c
63629@@ -182,7 +182,7 @@ struct kernfs_node *kernfs_get_parent(struct kernfs_node *kn)
63630 *
63631 * Returns 31 bit hash of ns + name (so it fits in an off_t )
63632 */
63633-static unsigned int kernfs_name_hash(const char *name, const void *ns)
63634+static unsigned int kernfs_name_hash(const unsigned char *name, const void *ns)
63635 {
63636 unsigned long hash = init_name_hash();
63637 unsigned int len = strlen(name);
63638@@ -829,6 +829,12 @@ static int kernfs_iop_mkdir(struct inode *dir, struct dentry *dentry,
63639 ret = scops->mkdir(parent, dentry->d_name.name, mode);
63640
63641 kernfs_put_active(parent);
63642+
63643+ if (!ret) {
63644+ struct dentry *dentry_ret = kernfs_iop_lookup(dir, dentry, 0);
63645+ ret = PTR_ERR_OR_ZERO(dentry_ret);
63646+ }
63647+
63648 return ret;
63649 }
63650
63651diff --git a/fs/kernfs/file.c b/fs/kernfs/file.c
63652index 4429d6d..9831f52 100644
63653--- a/fs/kernfs/file.c
63654+++ b/fs/kernfs/file.c
63655@@ -34,7 +34,7 @@ static DEFINE_MUTEX(kernfs_open_file_mutex);
63656
63657 struct kernfs_open_node {
63658 atomic_t refcnt;
63659- atomic_t event;
63660+ atomic_unchecked_t event;
63661 wait_queue_head_t poll;
63662 struct list_head files; /* goes through kernfs_open_file.list */
63663 };
63664@@ -163,7 +163,7 @@ static int kernfs_seq_show(struct seq_file *sf, void *v)
63665 {
63666 struct kernfs_open_file *of = sf->private;
63667
63668- of->event = atomic_read(&of->kn->attr.open->event);
63669+ of->event = atomic_read_unchecked(&of->kn->attr.open->event);
63670
63671 return of->kn->attr.ops->seq_show(sf, v);
63672 }
63673@@ -375,12 +375,12 @@ static int kernfs_vma_page_mkwrite(struct vm_area_struct *vma,
63674 return ret;
63675 }
63676
63677-static int kernfs_vma_access(struct vm_area_struct *vma, unsigned long addr,
63678- void *buf, int len, int write)
63679+static ssize_t kernfs_vma_access(struct vm_area_struct *vma, unsigned long addr,
63680+ void *buf, size_t len, int write)
63681 {
63682 struct file *file = vma->vm_file;
63683 struct kernfs_open_file *of = kernfs_of(file);
63684- int ret;
63685+ ssize_t ret;
63686
63687 if (!of->vm_ops)
63688 return -EINVAL;
63689@@ -581,7 +581,7 @@ static int kernfs_get_open_node(struct kernfs_node *kn,
63690 return -ENOMEM;
63691
63692 atomic_set(&new_on->refcnt, 0);
63693- atomic_set(&new_on->event, 1);
63694+ atomic_set_unchecked(&new_on->event, 1);
63695 init_waitqueue_head(&new_on->poll);
63696 INIT_LIST_HEAD(&new_on->files);
63697 goto retry;
63698@@ -787,7 +787,7 @@ static unsigned int kernfs_fop_poll(struct file *filp, poll_table *wait)
63699
63700 kernfs_put_active(kn);
63701
63702- if (of->event != atomic_read(&on->event))
63703+ if (of->event != atomic_read_unchecked(&on->event))
63704 goto trigger;
63705
63706 return DEFAULT_POLLMASK;
63707@@ -818,7 +818,7 @@ repeat:
63708
63709 on = kn->attr.open;
63710 if (on) {
63711- atomic_inc(&on->event);
63712+ atomic_inc_unchecked(&on->event);
63713 wake_up_interruptible(&on->poll);
63714 }
63715
63716diff --git a/fs/kernfs/symlink.c b/fs/kernfs/symlink.c
63717index 8a19889..4c3069a 100644
63718--- a/fs/kernfs/symlink.c
63719+++ b/fs/kernfs/symlink.c
63720@@ -128,7 +128,7 @@ static void *kernfs_iop_follow_link(struct dentry *dentry, struct nameidata *nd)
63721 static void kernfs_iop_put_link(struct dentry *dentry, struct nameidata *nd,
63722 void *cookie)
63723 {
63724- char *page = nd_get_link(nd);
63725+ const char *page = nd_get_link(nd);
63726 if (!IS_ERR(page))
63727 free_page((unsigned long)page);
63728 }
63729diff --git a/fs/libfs.c b/fs/libfs.c
63730index 005843c..06c4191 100644
63731--- a/fs/libfs.c
63732+++ b/fs/libfs.c
63733@@ -160,6 +160,9 @@ int dcache_readdir(struct file *file, struct dir_context *ctx)
63734
63735 for (p = q->next; p != &dentry->d_subdirs; p = p->next) {
63736 struct dentry *next = list_entry(p, struct dentry, d_child);
63737+ char d_name[sizeof(next->d_iname)];
63738+ const unsigned char *name;
63739+
63740 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
63741 if (!simple_positive(next)) {
63742 spin_unlock(&next->d_lock);
63743@@ -168,7 +171,12 @@ int dcache_readdir(struct file *file, struct dir_context *ctx)
63744
63745 spin_unlock(&next->d_lock);
63746 spin_unlock(&dentry->d_lock);
63747- if (!dir_emit(ctx, next->d_name.name, next->d_name.len,
63748+ name = next->d_name.name;
63749+ if (name == next->d_iname) {
63750+ memcpy(d_name, name, next->d_name.len);
63751+ name = d_name;
63752+ }
63753+ if (!dir_emit(ctx, name, next->d_name.len,
63754 next->d_inode->i_ino, dt_type(next->d_inode)))
63755 return 0;
63756 spin_lock(&dentry->d_lock);
63757@@ -1027,7 +1035,7 @@ EXPORT_SYMBOL(noop_fsync);
63758 void kfree_put_link(struct dentry *dentry, struct nameidata *nd,
63759 void *cookie)
63760 {
63761- char *s = nd_get_link(nd);
63762+ const char *s = nd_get_link(nd);
63763 if (!IS_ERR(s))
63764 kfree(s);
63765 }
63766diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
63767index acd3947..1f896e2 100644
63768--- a/fs/lockd/clntproc.c
63769+++ b/fs/lockd/clntproc.c
63770@@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
63771 /*
63772 * Cookie counter for NLM requests
63773 */
63774-static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
63775+static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
63776
63777 void nlmclnt_next_cookie(struct nlm_cookie *c)
63778 {
63779- u32 cookie = atomic_inc_return(&nlm_cookie);
63780+ u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
63781
63782 memcpy(c->data, &cookie, 4);
63783 c->len=4;
63784diff --git a/fs/locks.c b/fs/locks.c
63785index 735b8d3..dfc44a2 100644
63786--- a/fs/locks.c
63787+++ b/fs/locks.c
63788@@ -2374,7 +2374,7 @@ void locks_remove_file(struct file *filp)
63789 locks_remove_posix(filp, filp);
63790
63791 if (filp->f_op->flock) {
63792- struct file_lock fl = {
63793+ struct file_lock flock = {
63794 .fl_owner = filp,
63795 .fl_pid = current->tgid,
63796 .fl_file = filp,
63797@@ -2382,9 +2382,9 @@ void locks_remove_file(struct file *filp)
63798 .fl_type = F_UNLCK,
63799 .fl_end = OFFSET_MAX,
63800 };
63801- filp->f_op->flock(filp, F_SETLKW, &fl);
63802- if (fl.fl_ops && fl.fl_ops->fl_release_private)
63803- fl.fl_ops->fl_release_private(&fl);
63804+ filp->f_op->flock(filp, F_SETLKW, &flock);
63805+ if (flock.fl_ops && flock.fl_ops->fl_release_private)
63806+ flock.fl_ops->fl_release_private(&flock);
63807 }
63808
63809 spin_lock(&inode->i_lock);
63810diff --git a/fs/mount.h b/fs/mount.h
63811index f82c628..9492b99 100644
63812--- a/fs/mount.h
63813+++ b/fs/mount.h
63814@@ -11,7 +11,7 @@ struct mnt_namespace {
63815 u64 seq; /* Sequence number to prevent loops */
63816 wait_queue_head_t poll;
63817 u64 event;
63818-};
63819+} __randomize_layout;
63820
63821 struct mnt_pcp {
63822 int mnt_count;
63823@@ -62,7 +62,7 @@ struct mount {
63824 int mnt_expiry_mark; /* true if marked for expiry */
63825 struct hlist_head mnt_pins;
63826 struct path mnt_ex_mountpoint;
63827-};
63828+} __randomize_layout;
63829
63830 #define MNT_NS_INTERNAL ERR_PTR(-EINVAL) /* distinct from any mnt_namespace */
63831
63832diff --git a/fs/namei.c b/fs/namei.c
63833index db5fe86..d3dcc14 100644
63834--- a/fs/namei.c
63835+++ b/fs/namei.c
63836@@ -331,17 +331,32 @@ int generic_permission(struct inode *inode, int mask)
63837 if (ret != -EACCES)
63838 return ret;
63839
63840+#ifdef CONFIG_GRKERNSEC
63841+ /* we'll block if we have to log due to a denied capability use */
63842+ if (mask & MAY_NOT_BLOCK)
63843+ return -ECHILD;
63844+#endif
63845+
63846 if (S_ISDIR(inode->i_mode)) {
63847 /* DACs are overridable for directories */
63848- if (capable_wrt_inode_uidgid(inode, CAP_DAC_OVERRIDE))
63849- return 0;
63850 if (!(mask & MAY_WRITE))
63851- if (capable_wrt_inode_uidgid(inode,
63852- CAP_DAC_READ_SEARCH))
63853+ if (capable_wrt_inode_uidgid_nolog(inode, CAP_DAC_OVERRIDE) ||
63854+ capable_wrt_inode_uidgid(inode, CAP_DAC_READ_SEARCH))
63855 return 0;
63856+ if (capable_wrt_inode_uidgid(inode, CAP_DAC_OVERRIDE))
63857+ return 0;
63858 return -EACCES;
63859 }
63860 /*
63861+ * Searching includes executable on directories, else just read.
63862+ */
63863+ mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
63864+ if (mask == MAY_READ)
63865+ if (capable_wrt_inode_uidgid_nolog(inode, CAP_DAC_OVERRIDE) ||
63866+ capable_wrt_inode_uidgid(inode, CAP_DAC_READ_SEARCH))
63867+ return 0;
63868+
63869+ /*
63870 * Read/write DACs are always overridable.
63871 * Executable DACs are overridable when there is
63872 * at least one exec bit set.
63873@@ -350,14 +365,6 @@ int generic_permission(struct inode *inode, int mask)
63874 if (capable_wrt_inode_uidgid(inode, CAP_DAC_OVERRIDE))
63875 return 0;
63876
63877- /*
63878- * Searching includes executable on directories, else just read.
63879- */
63880- mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
63881- if (mask == MAY_READ)
63882- if (capable_wrt_inode_uidgid(inode, CAP_DAC_READ_SEARCH))
63883- return 0;
63884-
63885 return -EACCES;
63886 }
63887 EXPORT_SYMBOL(generic_permission);
63888@@ -824,7 +831,7 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
63889 {
63890 struct dentry *dentry = link->dentry;
63891 int error;
63892- char *s;
63893+ const char *s;
63894
63895 BUG_ON(nd->flags & LOOKUP_RCU);
63896
63897@@ -845,6 +852,12 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
63898 if (error)
63899 goto out_put_nd_path;
63900
63901+ if (gr_handle_follow_link(dentry->d_parent->d_inode,
63902+ dentry->d_inode, dentry, nd->path.mnt)) {
63903+ error = -EACCES;
63904+ goto out_put_nd_path;
63905+ }
63906+
63907 nd->last_type = LAST_BIND;
63908 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
63909 error = PTR_ERR(*p);
63910@@ -1608,6 +1621,8 @@ static inline int nested_symlink(struct path *path, struct nameidata *nd)
63911 if (res)
63912 break;
63913 res = walk_component(nd, path, LOOKUP_FOLLOW);
63914+ if (res >= 0 && gr_handle_symlink_owner(&link, nd->inode))
63915+ res = -EACCES;
63916 put_link(nd, &link, cookie);
63917 } while (res > 0);
63918
63919@@ -1680,7 +1695,7 @@ EXPORT_SYMBOL(full_name_hash);
63920 static inline u64 hash_name(const char *name)
63921 {
63922 unsigned long a, b, adata, bdata, mask, hash, len;
63923- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
63924+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
63925
63926 hash = a = 0;
63927 len = -sizeof(unsigned long);
63928@@ -1969,6 +1984,8 @@ static int path_lookupat(int dfd, const char *name,
63929 if (err)
63930 break;
63931 err = lookup_last(nd, &path);
63932+ if (!err && gr_handle_symlink_owner(&link, nd->inode))
63933+ err = -EACCES;
63934 put_link(nd, &link, cookie);
63935 }
63936 }
63937@@ -1976,6 +1993,13 @@ static int path_lookupat(int dfd, const char *name,
63938 if (!err)
63939 err = complete_walk(nd);
63940
63941+ if (!err && !(nd->flags & LOOKUP_PARENT)) {
63942+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
63943+ path_put(&nd->path);
63944+ err = -ENOENT;
63945+ }
63946+ }
63947+
63948 if (!err && nd->flags & LOOKUP_DIRECTORY) {
63949 if (!d_can_lookup(nd->path.dentry)) {
63950 path_put(&nd->path);
63951@@ -2004,8 +2028,15 @@ static int filename_lookup(int dfd, struct filename *name,
63952 retval = path_lookupat(dfd, name->name,
63953 flags | LOOKUP_REVAL, nd);
63954
63955- if (likely(!retval))
63956+ if (likely(!retval)) {
63957 audit_inode(name, nd->path.dentry, flags & LOOKUP_PARENT);
63958+ if (name->name[0] != '/' && nd->path.dentry && nd->inode) {
63959+ if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt)) {
63960+ path_put(&nd->path);
63961+ return -ENOENT;
63962+ }
63963+ }
63964+ }
63965 return retval;
63966 }
63967
63968@@ -2582,6 +2613,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
63969 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
63970 return -EPERM;
63971
63972+ if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
63973+ return -EPERM;
63974+ if (gr_handle_rawio(inode))
63975+ return -EPERM;
63976+ if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
63977+ return -EACCES;
63978+
63979 return 0;
63980 }
63981
63982@@ -2813,7 +2851,7 @@ looked_up:
63983 * cleared otherwise prior to returning.
63984 */
63985 static int lookup_open(struct nameidata *nd, struct path *path,
63986- struct file *file,
63987+ struct path *link, struct file *file,
63988 const struct open_flags *op,
63989 bool got_write, int *opened)
63990 {
63991@@ -2848,6 +2886,17 @@ static int lookup_open(struct nameidata *nd, struct path *path,
63992 /* Negative dentry, just create the file */
63993 if (!dentry->d_inode && (op->open_flag & O_CREAT)) {
63994 umode_t mode = op->mode;
63995+
63996+ if (link && gr_handle_symlink_owner(link, dir->d_inode)) {
63997+ error = -EACCES;
63998+ goto out_dput;
63999+ }
64000+
64001+ if (!gr_acl_handle_creat(dentry, dir, nd->path.mnt, op->open_flag, op->acc_mode, mode)) {
64002+ error = -EACCES;
64003+ goto out_dput;
64004+ }
64005+
64006 if (!IS_POSIXACL(dir->d_inode))
64007 mode &= ~current_umask();
64008 /*
64009@@ -2869,6 +2918,8 @@ static int lookup_open(struct nameidata *nd, struct path *path,
64010 nd->flags & LOOKUP_EXCL);
64011 if (error)
64012 goto out_dput;
64013+ else
64014+ gr_handle_create(dentry, nd->path.mnt);
64015 }
64016 out_no_open:
64017 path->dentry = dentry;
64018@@ -2883,7 +2934,7 @@ out_dput:
64019 /*
64020 * Handle the last step of open()
64021 */
64022-static int do_last(struct nameidata *nd, struct path *path,
64023+static int do_last(struct nameidata *nd, struct path *path, struct path *link,
64024 struct file *file, const struct open_flags *op,
64025 int *opened, struct filename *name)
64026 {
64027@@ -2933,6 +2984,15 @@ static int do_last(struct nameidata *nd, struct path *path,
64028 if (error)
64029 return error;
64030
64031+ if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
64032+ error = -ENOENT;
64033+ goto out;
64034+ }
64035+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
64036+ error = -EACCES;
64037+ goto out;
64038+ }
64039+
64040 audit_inode(name, dir, LOOKUP_PARENT);
64041 error = -EISDIR;
64042 /* trailing slashes? */
64043@@ -2952,7 +3012,7 @@ retry_lookup:
64044 */
64045 }
64046 mutex_lock(&dir->d_inode->i_mutex);
64047- error = lookup_open(nd, path, file, op, got_write, opened);
64048+ error = lookup_open(nd, path, link, file, op, got_write, opened);
64049 mutex_unlock(&dir->d_inode->i_mutex);
64050
64051 if (error <= 0) {
64052@@ -2976,11 +3036,28 @@ retry_lookup:
64053 goto finish_open_created;
64054 }
64055
64056+ if (!gr_acl_handle_hidden_file(path->dentry, nd->path.mnt)) {
64057+ error = -ENOENT;
64058+ goto exit_dput;
64059+ }
64060+ if (link && gr_handle_symlink_owner(link, path->dentry->d_inode)) {
64061+ error = -EACCES;
64062+ goto exit_dput;
64063+ }
64064+
64065 /*
64066 * create/update audit record if it already exists.
64067 */
64068- if (d_is_positive(path->dentry))
64069+ if (d_is_positive(path->dentry)) {
64070+ /* only check if O_CREAT is specified, all other checks need to go
64071+ into may_open */
64072+ if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
64073+ error = -EACCES;
64074+ goto exit_dput;
64075+ }
64076+
64077 audit_inode(name, path->dentry, 0);
64078+ }
64079
64080 /*
64081 * If atomic_open() acquired write access it is dropped now due to
64082@@ -3021,6 +3098,11 @@ finish_lookup:
64083 }
64084 }
64085 BUG_ON(inode != path->dentry->d_inode);
64086+ /* if we're resolving a symlink to another symlink */
64087+ if (link && gr_handle_symlink_owner(link, inode)) {
64088+ error = -EACCES;
64089+ goto out;
64090+ }
64091 return 1;
64092 }
64093
64094@@ -3040,7 +3122,18 @@ finish_open:
64095 path_put(&save_parent);
64096 return error;
64097 }
64098+
64099+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
64100+ error = -ENOENT;
64101+ goto out;
64102+ }
64103+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
64104+ error = -EACCES;
64105+ goto out;
64106+ }
64107+
64108 audit_inode(name, nd->path.dentry, 0);
64109+
64110 error = -EISDIR;
64111 if ((open_flag & O_CREAT) && d_is_dir(nd->path.dentry))
64112 goto out;
64113@@ -3207,7 +3300,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
64114 if (unlikely(error))
64115 goto out;
64116
64117- error = do_last(nd, &path, file, op, &opened, pathname);
64118+ error = do_last(nd, &path, NULL, file, op, &opened, pathname);
64119 while (unlikely(error > 0)) { /* trailing symlink */
64120 struct path link = path;
64121 void *cookie;
64122@@ -3225,7 +3318,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
64123 error = follow_link(&link, nd, &cookie);
64124 if (unlikely(error))
64125 break;
64126- error = do_last(nd, &path, file, op, &opened, pathname);
64127+ error = do_last(nd, &path, &link, file, op, &opened, pathname);
64128 put_link(nd, &link, cookie);
64129 }
64130 out:
64131@@ -3325,9 +3418,11 @@ struct dentry *kern_path_create(int dfd, const char *pathname,
64132 goto unlock;
64133
64134 error = -EEXIST;
64135- if (d_is_positive(dentry))
64136+ if (d_is_positive(dentry)) {
64137+ if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt))
64138+ error = -ENOENT;
64139 goto fail;
64140-
64141+ }
64142 /*
64143 * Special case - lookup gave negative, but... we had foo/bar/
64144 * From the vfs_mknod() POV we just have a negative dentry -
64145@@ -3379,6 +3474,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname,
64146 }
64147 EXPORT_SYMBOL(user_path_create);
64148
64149+static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, struct filename **to, unsigned int lookup_flags)
64150+{
64151+ struct filename *tmp = getname(pathname);
64152+ struct dentry *res;
64153+ if (IS_ERR(tmp))
64154+ return ERR_CAST(tmp);
64155+ res = kern_path_create(dfd, tmp->name, path, lookup_flags);
64156+ if (IS_ERR(res))
64157+ putname(tmp);
64158+ else
64159+ *to = tmp;
64160+ return res;
64161+}
64162+
64163 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
64164 {
64165 int error = may_create(dir, dentry);
64166@@ -3442,6 +3551,17 @@ retry:
64167
64168 if (!IS_POSIXACL(path.dentry->d_inode))
64169 mode &= ~current_umask();
64170+
64171+ if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
64172+ error = -EPERM;
64173+ goto out;
64174+ }
64175+
64176+ if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
64177+ error = -EACCES;
64178+ goto out;
64179+ }
64180+
64181 error = security_path_mknod(&path, dentry, mode, dev);
64182 if (error)
64183 goto out;
64184@@ -3457,6 +3577,8 @@ retry:
64185 error = vfs_mknod(path.dentry->d_inode,dentry,mode,0);
64186 break;
64187 }
64188+ if (!error)
64189+ gr_handle_create(dentry, path.mnt);
64190 out:
64191 done_path_create(&path, dentry);
64192 if (retry_estale(error, lookup_flags)) {
64193@@ -3511,9 +3633,16 @@ retry:
64194
64195 if (!IS_POSIXACL(path.dentry->d_inode))
64196 mode &= ~current_umask();
64197+ if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
64198+ error = -EACCES;
64199+ goto out;
64200+ }
64201 error = security_path_mkdir(&path, dentry, mode);
64202 if (!error)
64203 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
64204+ if (!error)
64205+ gr_handle_create(dentry, path.mnt);
64206+out:
64207 done_path_create(&path, dentry);
64208 if (retry_estale(error, lookup_flags)) {
64209 lookup_flags |= LOOKUP_REVAL;
64210@@ -3597,6 +3726,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
64211 struct filename *name;
64212 struct dentry *dentry;
64213 struct nameidata nd;
64214+ ino_t saved_ino = 0;
64215+ dev_t saved_dev = 0;
64216 unsigned int lookup_flags = 0;
64217 retry:
64218 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
64219@@ -3629,10 +3760,21 @@ retry:
64220 error = -ENOENT;
64221 goto exit3;
64222 }
64223+
64224+ saved_ino = dentry->d_inode->i_ino;
64225+ saved_dev = gr_get_dev_from_dentry(dentry);
64226+
64227+ if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
64228+ error = -EACCES;
64229+ goto exit3;
64230+ }
64231+
64232 error = security_path_rmdir(&nd.path, dentry);
64233 if (error)
64234 goto exit3;
64235 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
64236+ if (!error && (saved_dev || saved_ino))
64237+ gr_handle_delete(saved_ino, saved_dev);
64238 exit3:
64239 dput(dentry);
64240 exit2:
64241@@ -3725,6 +3867,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
64242 struct nameidata nd;
64243 struct inode *inode = NULL;
64244 struct inode *delegated_inode = NULL;
64245+ ino_t saved_ino = 0;
64246+ dev_t saved_dev = 0;
64247 unsigned int lookup_flags = 0;
64248 retry:
64249 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
64250@@ -3751,10 +3895,22 @@ retry_deleg:
64251 if (d_is_negative(dentry))
64252 goto slashes;
64253 ihold(inode);
64254+
64255+ if (inode->i_nlink <= 1) {
64256+ saved_ino = inode->i_ino;
64257+ saved_dev = gr_get_dev_from_dentry(dentry);
64258+ }
64259+ if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
64260+ error = -EACCES;
64261+ goto exit2;
64262+ }
64263+
64264 error = security_path_unlink(&nd.path, dentry);
64265 if (error)
64266 goto exit2;
64267 error = vfs_unlink(nd.path.dentry->d_inode, dentry, &delegated_inode);
64268+ if (!error && (saved_ino || saved_dev))
64269+ gr_handle_delete(saved_ino, saved_dev);
64270 exit2:
64271 dput(dentry);
64272 }
64273@@ -3843,9 +3999,17 @@ retry:
64274 if (IS_ERR(dentry))
64275 goto out_putname;
64276
64277+ if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
64278+ error = -EACCES;
64279+ goto out;
64280+ }
64281+
64282 error = security_path_symlink(&path, dentry, from->name);
64283 if (!error)
64284 error = vfs_symlink(path.dentry->d_inode, dentry, from->name);
64285+ if (!error)
64286+ gr_handle_create(dentry, path.mnt);
64287+out:
64288 done_path_create(&path, dentry);
64289 if (retry_estale(error, lookup_flags)) {
64290 lookup_flags |= LOOKUP_REVAL;
64291@@ -3949,6 +4113,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
64292 struct dentry *new_dentry;
64293 struct path old_path, new_path;
64294 struct inode *delegated_inode = NULL;
64295+ struct filename *to = NULL;
64296 int how = 0;
64297 int error;
64298
64299@@ -3972,7 +4137,7 @@ retry:
64300 if (error)
64301 return error;
64302
64303- new_dentry = user_path_create(newdfd, newname, &new_path,
64304+ new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to,
64305 (how & LOOKUP_REVAL));
64306 error = PTR_ERR(new_dentry);
64307 if (IS_ERR(new_dentry))
64308@@ -3984,11 +4149,28 @@ retry:
64309 error = may_linkat(&old_path);
64310 if (unlikely(error))
64311 goto out_dput;
64312+
64313+ if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
64314+ old_path.dentry->d_inode,
64315+ old_path.dentry->d_inode->i_mode, to)) {
64316+ error = -EACCES;
64317+ goto out_dput;
64318+ }
64319+
64320+ if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
64321+ old_path.dentry, old_path.mnt, to)) {
64322+ error = -EACCES;
64323+ goto out_dput;
64324+ }
64325+
64326 error = security_path_link(old_path.dentry, &new_path, new_dentry);
64327 if (error)
64328 goto out_dput;
64329 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry, &delegated_inode);
64330+ if (!error)
64331+ gr_handle_create(new_dentry, new_path.mnt);
64332 out_dput:
64333+ putname(to);
64334 done_path_create(&new_path, new_dentry);
64335 if (delegated_inode) {
64336 error = break_deleg_wait(&delegated_inode);
64337@@ -4304,6 +4486,12 @@ retry_deleg:
64338 if (new_dentry == trap)
64339 goto exit5;
64340
64341+ error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
64342+ old_dentry, old_dir->d_inode, oldnd.path.mnt,
64343+ to, flags);
64344+ if (error)
64345+ goto exit5;
64346+
64347 error = security_path_rename(&oldnd.path, old_dentry,
64348 &newnd.path, new_dentry, flags);
64349 if (error)
64350@@ -4311,6 +4499,9 @@ retry_deleg:
64351 error = vfs_rename(old_dir->d_inode, old_dentry,
64352 new_dir->d_inode, new_dentry,
64353 &delegated_inode, flags);
64354+ if (!error)
64355+ gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
64356+ new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0, flags);
64357 exit5:
64358 dput(new_dentry);
64359 exit4:
64360@@ -4367,14 +4558,24 @@ EXPORT_SYMBOL(vfs_whiteout);
64361
64362 int readlink_copy(char __user *buffer, int buflen, const char *link)
64363 {
64364+ char tmpbuf[64];
64365+ const char *newlink;
64366 int len = PTR_ERR(link);
64367+
64368 if (IS_ERR(link))
64369 goto out;
64370
64371 len = strlen(link);
64372 if (len > (unsigned) buflen)
64373 len = buflen;
64374- if (copy_to_user(buffer, link, len))
64375+
64376+ if (len < sizeof(tmpbuf)) {
64377+ memcpy(tmpbuf, link, len);
64378+ newlink = tmpbuf;
64379+ } else
64380+ newlink = link;
64381+
64382+ if (copy_to_user(buffer, newlink, len))
64383 len = -EFAULT;
64384 out:
64385 return len;
64386diff --git a/fs/namespace.c b/fs/namespace.c
64387index bbde147..f4deeba 100644
64388--- a/fs/namespace.c
64389+++ b/fs/namespace.c
64390@@ -1447,6 +1447,9 @@ static int do_umount(struct mount *mnt, int flags)
64391 if (!(sb->s_flags & MS_RDONLY))
64392 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
64393 up_write(&sb->s_umount);
64394+
64395+ gr_log_remount(mnt->mnt_devname, retval);
64396+
64397 return retval;
64398 }
64399
64400@@ -1469,6 +1472,9 @@ static int do_umount(struct mount *mnt, int flags)
64401 }
64402 unlock_mount_hash();
64403 namespace_unlock();
64404+
64405+ gr_log_unmount(mnt->mnt_devname, retval);
64406+
64407 return retval;
64408 }
64409
64410@@ -1519,7 +1525,7 @@ static inline bool may_mount(void)
64411 * unixes. Our API is identical to OSF/1 to avoid making a mess of AMD
64412 */
64413
64414-SYSCALL_DEFINE2(umount, char __user *, name, int, flags)
64415+SYSCALL_DEFINE2(umount, const char __user *, name, int, flags)
64416 {
64417 struct path path;
64418 struct mount *mnt;
64419@@ -1564,7 +1570,7 @@ out:
64420 /*
64421 * The 2.0 compatible umount. No flags.
64422 */
64423-SYSCALL_DEFINE1(oldumount, char __user *, name)
64424+SYSCALL_DEFINE1(oldumount, const char __user *, name)
64425 {
64426 return sys_umount(name, 0);
64427 }
64428@@ -2632,6 +2638,16 @@ long do_mount(const char *dev_name, const char __user *dir_name,
64429 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
64430 MS_STRICTATIME);
64431
64432+ if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
64433+ retval = -EPERM;
64434+ goto dput_out;
64435+ }
64436+
64437+ if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
64438+ retval = -EPERM;
64439+ goto dput_out;
64440+ }
64441+
64442 if (flags & MS_REMOUNT)
64443 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
64444 data_page);
64445@@ -2645,7 +2661,10 @@ long do_mount(const char *dev_name, const char __user *dir_name,
64446 retval = do_new_mount(&path, type_page, flags, mnt_flags,
64447 dev_name, data_page);
64448 dput_out:
64449+ gr_log_mount(dev_name, &path, retval);
64450+
64451 path_put(&path);
64452+
64453 return retval;
64454 }
64455
64456@@ -2663,7 +2682,7 @@ static void free_mnt_ns(struct mnt_namespace *ns)
64457 * number incrementing at 10Ghz will take 12,427 years to wrap which
64458 * is effectively never, so we can ignore the possibility.
64459 */
64460-static atomic64_t mnt_ns_seq = ATOMIC64_INIT(1);
64461+static atomic64_unchecked_t mnt_ns_seq = ATOMIC64_INIT(1);
64462
64463 static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
64464 {
64465@@ -2678,7 +2697,7 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
64466 kfree(new_ns);
64467 return ERR_PTR(ret);
64468 }
64469- new_ns->seq = atomic64_add_return(1, &mnt_ns_seq);
64470+ new_ns->seq = atomic64_inc_return_unchecked(&mnt_ns_seq);
64471 atomic_set(&new_ns->count, 1);
64472 new_ns->root = NULL;
64473 INIT_LIST_HEAD(&new_ns->list);
64474@@ -2688,7 +2707,7 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
64475 return new_ns;
64476 }
64477
64478-struct mnt_namespace *copy_mnt_ns(unsigned long flags, struct mnt_namespace *ns,
64479+__latent_entropy struct mnt_namespace *copy_mnt_ns(unsigned long flags, struct mnt_namespace *ns,
64480 struct user_namespace *user_ns, struct fs_struct *new_fs)
64481 {
64482 struct mnt_namespace *new_ns;
64483@@ -2809,8 +2828,8 @@ struct dentry *mount_subtree(struct vfsmount *mnt, const char *name)
64484 }
64485 EXPORT_SYMBOL(mount_subtree);
64486
64487-SYSCALL_DEFINE5(mount, char __user *, dev_name, char __user *, dir_name,
64488- char __user *, type, unsigned long, flags, void __user *, data)
64489+SYSCALL_DEFINE5(mount, const char __user *, dev_name, const char __user *, dir_name,
64490+ const char __user *, type, unsigned long, flags, void __user *, data)
64491 {
64492 int ret;
64493 char *kernel_type;
64494@@ -2916,6 +2935,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
64495 if (error)
64496 goto out2;
64497
64498+ if (gr_handle_chroot_pivot()) {
64499+ error = -EPERM;
64500+ goto out2;
64501+ }
64502+
64503 get_fs_root(current->fs, &root);
64504 old_mp = lock_mount(&old);
64505 error = PTR_ERR(old_mp);
64506@@ -3187,7 +3211,7 @@ static int mntns_install(struct nsproxy *nsproxy, void *ns)
64507 !ns_capable(current_user_ns(), CAP_SYS_ADMIN))
64508 return -EPERM;
64509
64510- if (fs->users != 1)
64511+ if (atomic_read(&fs->users) != 1)
64512 return -EINVAL;
64513
64514 get_mnt_ns(mnt_ns);
64515diff --git a/fs/nfs/callback_xdr.c b/fs/nfs/callback_xdr.c
64516index f4ccfe6..a5cf064 100644
64517--- a/fs/nfs/callback_xdr.c
64518+++ b/fs/nfs/callback_xdr.c
64519@@ -51,7 +51,7 @@ struct callback_op {
64520 callback_decode_arg_t decode_args;
64521 callback_encode_res_t encode_res;
64522 long res_maxsize;
64523-};
64524+} __do_const;
64525
64526 static struct callback_op callback_ops[];
64527
64528diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
64529index 00689a8..b162632 100644
64530--- a/fs/nfs/inode.c
64531+++ b/fs/nfs/inode.c
64532@@ -1232,16 +1232,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
64533 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
64534 }
64535
64536-static atomic_long_t nfs_attr_generation_counter;
64537+static atomic_long_unchecked_t nfs_attr_generation_counter;
64538
64539 static unsigned long nfs_read_attr_generation_counter(void)
64540 {
64541- return atomic_long_read(&nfs_attr_generation_counter);
64542+ return atomic_long_read_unchecked(&nfs_attr_generation_counter);
64543 }
64544
64545 unsigned long nfs_inc_attr_generation_counter(void)
64546 {
64547- return atomic_long_inc_return(&nfs_attr_generation_counter);
64548+ return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
64549 }
64550
64551 void nfs_fattr_init(struct nfs_fattr *fattr)
64552diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c
64553index 0beb023..3f685ec 100644
64554--- a/fs/nfsd/nfs4proc.c
64555+++ b/fs/nfsd/nfs4proc.c
64556@@ -1198,7 +1198,7 @@ struct nfsd4_operation {
64557 nfsd4op_rsize op_rsize_bop;
64558 stateid_getter op_get_currentstateid;
64559 stateid_setter op_set_currentstateid;
64560-};
64561+} __do_const;
64562
64563 static struct nfsd4_operation nfsd4_ops[];
64564
64565diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
64566index 2a77603..68e0e37 100644
64567--- a/fs/nfsd/nfs4xdr.c
64568+++ b/fs/nfsd/nfs4xdr.c
64569@@ -1543,7 +1543,7 @@ nfsd4_decode_notsupp(struct nfsd4_compoundargs *argp, void *p)
64570
64571 typedef __be32(*nfsd4_dec)(struct nfsd4_compoundargs *argp, void *);
64572
64573-static nfsd4_dec nfsd4_dec_ops[] = {
64574+static const nfsd4_dec nfsd4_dec_ops[] = {
64575 [OP_ACCESS] = (nfsd4_dec)nfsd4_decode_access,
64576 [OP_CLOSE] = (nfsd4_dec)nfsd4_decode_close,
64577 [OP_COMMIT] = (nfsd4_dec)nfsd4_decode_commit,
64578diff --git a/fs/nfsd/nfscache.c b/fs/nfsd/nfscache.c
64579index 122f691..a00e2e0 100644
64580--- a/fs/nfsd/nfscache.c
64581+++ b/fs/nfsd/nfscache.c
64582@@ -537,7 +537,7 @@ nfsd_cache_update(struct svc_rqst *rqstp, int cachetype, __be32 *statp)
64583 struct kvec *resv = &rqstp->rq_res.head[0], *cachv;
64584 u32 hash;
64585 struct nfsd_drc_bucket *b;
64586- int len;
64587+ long len;
64588 size_t bufsize = 0;
64589
64590 if (!rp)
64591@@ -546,11 +546,14 @@ nfsd_cache_update(struct svc_rqst *rqstp, int cachetype, __be32 *statp)
64592 hash = nfsd_cache_hash(rp->c_xid);
64593 b = &drc_hashtbl[hash];
64594
64595- len = resv->iov_len - ((char*)statp - (char*)resv->iov_base);
64596- len >>= 2;
64597+ if (statp) {
64598+ len = (char*)statp - (char*)resv->iov_base;
64599+ len = resv->iov_len - len;
64600+ len >>= 2;
64601+ }
64602
64603 /* Don't cache excessive amounts of data and XDR failures */
64604- if (!statp || len > (256 >> 2)) {
64605+ if (!statp || len > (256 >> 2) || len < 0) {
64606 nfsd_reply_cache_free(b, rp);
64607 return;
64608 }
64609@@ -558,7 +561,7 @@ nfsd_cache_update(struct svc_rqst *rqstp, int cachetype, __be32 *statp)
64610 switch (cachetype) {
64611 case RC_REPLSTAT:
64612 if (len != 1)
64613- printk("nfsd: RC_REPLSTAT/reply len %d!\n",len);
64614+ printk("nfsd: RC_REPLSTAT/reply len %ld!\n",len);
64615 rp->c_replstat = *statp;
64616 break;
64617 case RC_REPLBUFF:
64618diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
64619index 989129e..42e019e 100644
64620--- a/fs/nfsd/vfs.c
64621+++ b/fs/nfsd/vfs.c
64622@@ -872,7 +872,7 @@ __be32 nfsd_readv(struct file *file, loff_t offset, struct kvec *vec, int vlen,
64623
64624 oldfs = get_fs();
64625 set_fs(KERNEL_DS);
64626- host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
64627+ host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
64628 set_fs(oldfs);
64629 return nfsd_finish_read(file, count, host_err);
64630 }
64631@@ -960,7 +960,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
64632
64633 /* Write the data. */
64634 oldfs = get_fs(); set_fs(KERNEL_DS);
64635- host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &pos);
64636+ host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &pos);
64637 set_fs(oldfs);
64638 if (host_err < 0)
64639 goto out_nfserr;
64640@@ -1502,7 +1502,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
64641 */
64642
64643 oldfs = get_fs(); set_fs(KERNEL_DS);
64644- host_err = inode->i_op->readlink(path.dentry, (char __user *)buf, *lenp);
64645+ host_err = inode->i_op->readlink(path.dentry, (char __force_user *)buf, *lenp);
64646 set_fs(oldfs);
64647
64648 if (host_err < 0)
64649diff --git a/fs/nls/nls_base.c b/fs/nls/nls_base.c
64650index 52ccd34..7a6b202 100644
64651--- a/fs/nls/nls_base.c
64652+++ b/fs/nls/nls_base.c
64653@@ -234,21 +234,25 @@ EXPORT_SYMBOL(utf16s_to_utf8s);
64654
64655 int __register_nls(struct nls_table *nls, struct module *owner)
64656 {
64657- struct nls_table ** tmp = &tables;
64658+ struct nls_table *tmp = tables;
64659
64660 if (nls->next)
64661 return -EBUSY;
64662
64663- nls->owner = owner;
64664+ pax_open_kernel();
64665+ *(void **)&nls->owner = owner;
64666+ pax_close_kernel();
64667 spin_lock(&nls_lock);
64668- while (*tmp) {
64669- if (nls == *tmp) {
64670+ while (tmp) {
64671+ if (nls == tmp) {
64672 spin_unlock(&nls_lock);
64673 return -EBUSY;
64674 }
64675- tmp = &(*tmp)->next;
64676+ tmp = tmp->next;
64677 }
64678- nls->next = tables;
64679+ pax_open_kernel();
64680+ *(struct nls_table **)&nls->next = tables;
64681+ pax_close_kernel();
64682 tables = nls;
64683 spin_unlock(&nls_lock);
64684 return 0;
64685@@ -257,12 +261,14 @@ EXPORT_SYMBOL(__register_nls);
64686
64687 int unregister_nls(struct nls_table * nls)
64688 {
64689- struct nls_table ** tmp = &tables;
64690+ struct nls_table * const * tmp = &tables;
64691
64692 spin_lock(&nls_lock);
64693 while (*tmp) {
64694 if (nls == *tmp) {
64695- *tmp = nls->next;
64696+ pax_open_kernel();
64697+ *(struct nls_table **)tmp = nls->next;
64698+ pax_close_kernel();
64699 spin_unlock(&nls_lock);
64700 return 0;
64701 }
64702@@ -272,7 +278,7 @@ int unregister_nls(struct nls_table * nls)
64703 return -EINVAL;
64704 }
64705
64706-static struct nls_table *find_nls(char *charset)
64707+static struct nls_table *find_nls(const char *charset)
64708 {
64709 struct nls_table *nls;
64710 spin_lock(&nls_lock);
64711@@ -288,7 +294,7 @@ static struct nls_table *find_nls(char *charset)
64712 return nls;
64713 }
64714
64715-struct nls_table *load_nls(char *charset)
64716+struct nls_table *load_nls(const char *charset)
64717 {
64718 return try_then_request_module(find_nls(charset), "nls_%s", charset);
64719 }
64720diff --git a/fs/nls/nls_euc-jp.c b/fs/nls/nls_euc-jp.c
64721index 162b3f1..6076a7c 100644
64722--- a/fs/nls/nls_euc-jp.c
64723+++ b/fs/nls/nls_euc-jp.c
64724@@ -560,8 +560,10 @@ static int __init init_nls_euc_jp(void)
64725 p_nls = load_nls("cp932");
64726
64727 if (p_nls) {
64728- table.charset2upper = p_nls->charset2upper;
64729- table.charset2lower = p_nls->charset2lower;
64730+ pax_open_kernel();
64731+ *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
64732+ *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
64733+ pax_close_kernel();
64734 return register_nls(&table);
64735 }
64736
64737diff --git a/fs/nls/nls_koi8-ru.c b/fs/nls/nls_koi8-ru.c
64738index a80a741..7b96e1b 100644
64739--- a/fs/nls/nls_koi8-ru.c
64740+++ b/fs/nls/nls_koi8-ru.c
64741@@ -62,8 +62,10 @@ static int __init init_nls_koi8_ru(void)
64742 p_nls = load_nls("koi8-u");
64743
64744 if (p_nls) {
64745- table.charset2upper = p_nls->charset2upper;
64746- table.charset2lower = p_nls->charset2lower;
64747+ pax_open_kernel();
64748+ *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
64749+ *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
64750+ pax_close_kernel();
64751 return register_nls(&table);
64752 }
64753
64754diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
64755index c991616..5ae51af 100644
64756--- a/fs/notify/fanotify/fanotify_user.c
64757+++ b/fs/notify/fanotify/fanotify_user.c
64758@@ -216,8 +216,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
64759
64760 fd = fanotify_event_metadata.fd;
64761 ret = -EFAULT;
64762- if (copy_to_user(buf, &fanotify_event_metadata,
64763- fanotify_event_metadata.event_len))
64764+ if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
64765+ copy_to_user(buf, &fanotify_event_metadata, fanotify_event_metadata.event_len))
64766 goto out_close_fd;
64767
64768 #ifdef CONFIG_FANOTIFY_ACCESS_PERMISSIONS
64769diff --git a/fs/notify/notification.c b/fs/notify/notification.c
64770index a95d8e0..a91a5fd 100644
64771--- a/fs/notify/notification.c
64772+++ b/fs/notify/notification.c
64773@@ -48,7 +48,7 @@
64774 #include <linux/fsnotify_backend.h>
64775 #include "fsnotify.h"
64776
64777-static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
64778+static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
64779
64780 /**
64781 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
64782@@ -56,7 +56,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
64783 */
64784 u32 fsnotify_get_cookie(void)
64785 {
64786- return atomic_inc_return(&fsnotify_sync_cookie);
64787+ return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
64788 }
64789 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
64790
64791diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
64792index 9e38daf..5727cae 100644
64793--- a/fs/ntfs/dir.c
64794+++ b/fs/ntfs/dir.c
64795@@ -1310,7 +1310,7 @@ find_next_index_buffer:
64796 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
64797 ~(s64)(ndir->itype.index.block_size - 1)));
64798 /* Bounds checks. */
64799- if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
64800+ if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
64801 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
64802 "inode 0x%lx or driver bug.", vdir->i_ino);
64803 goto err_out;
64804diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
64805index 643faa4..ef9027e 100644
64806--- a/fs/ntfs/file.c
64807+++ b/fs/ntfs/file.c
64808@@ -1280,7 +1280,7 @@ static inline size_t ntfs_copy_from_user(struct page **pages,
64809 char *addr;
64810 size_t total = 0;
64811 unsigned len;
64812- int left;
64813+ unsigned left;
64814
64815 do {
64816 len = PAGE_CACHE_SIZE - ofs;
64817diff --git a/fs/ntfs/super.c b/fs/ntfs/super.c
64818index 9e1e112..241a52a 100644
64819--- a/fs/ntfs/super.c
64820+++ b/fs/ntfs/super.c
64821@@ -688,7 +688,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
64822 if (!silent)
64823 ntfs_error(sb, "Primary boot sector is invalid.");
64824 } else if (!silent)
64825- ntfs_error(sb, read_err_str, "primary");
64826+ ntfs_error(sb, read_err_str, "%s", "primary");
64827 if (!(NTFS_SB(sb)->on_errors & ON_ERRORS_RECOVER)) {
64828 if (bh_primary)
64829 brelse(bh_primary);
64830@@ -704,7 +704,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
64831 goto hotfix_primary_boot_sector;
64832 brelse(bh_backup);
64833 } else if (!silent)
64834- ntfs_error(sb, read_err_str, "backup");
64835+ ntfs_error(sb, read_err_str, "%s", "backup");
64836 /* Try to read NT3.51- backup boot sector. */
64837 if ((bh_backup = sb_bread(sb, nr_blocks >> 1))) {
64838 if (is_boot_sector_ntfs(sb, (NTFS_BOOT_SECTOR*)
64839@@ -715,7 +715,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
64840 "sector.");
64841 brelse(bh_backup);
64842 } else if (!silent)
64843- ntfs_error(sb, read_err_str, "backup");
64844+ ntfs_error(sb, read_err_str, "%s", "backup");
64845 /* We failed. Cleanup and return. */
64846 if (bh_primary)
64847 brelse(bh_primary);
64848diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
64849index 0440134..d52c93a 100644
64850--- a/fs/ocfs2/localalloc.c
64851+++ b/fs/ocfs2/localalloc.c
64852@@ -1320,7 +1320,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
64853 goto bail;
64854 }
64855
64856- atomic_inc(&osb->alloc_stats.moves);
64857+ atomic_inc_unchecked(&osb->alloc_stats.moves);
64858
64859 bail:
64860 if (handle)
64861diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
64862index bbec539..7b266d5 100644
64863--- a/fs/ocfs2/ocfs2.h
64864+++ b/fs/ocfs2/ocfs2.h
64865@@ -236,11 +236,11 @@ enum ocfs2_vol_state
64866
64867 struct ocfs2_alloc_stats
64868 {
64869- atomic_t moves;
64870- atomic_t local_data;
64871- atomic_t bitmap_data;
64872- atomic_t bg_allocs;
64873- atomic_t bg_extends;
64874+ atomic_unchecked_t moves;
64875+ atomic_unchecked_t local_data;
64876+ atomic_unchecked_t bitmap_data;
64877+ atomic_unchecked_t bg_allocs;
64878+ atomic_unchecked_t bg_extends;
64879 };
64880
64881 enum ocfs2_local_alloc_state
64882diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
64883index 0cb889a..6a26b24 100644
64884--- a/fs/ocfs2/suballoc.c
64885+++ b/fs/ocfs2/suballoc.c
64886@@ -867,7 +867,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
64887 mlog_errno(status);
64888 goto bail;
64889 }
64890- atomic_inc(&osb->alloc_stats.bg_extends);
64891+ atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
64892
64893 /* You should never ask for this much metadata */
64894 BUG_ON(bits_wanted >
64895@@ -2014,7 +2014,7 @@ int ocfs2_claim_metadata(handle_t *handle,
64896 mlog_errno(status);
64897 goto bail;
64898 }
64899- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
64900+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
64901
64902 *suballoc_loc = res.sr_bg_blkno;
64903 *suballoc_bit_start = res.sr_bit_offset;
64904@@ -2180,7 +2180,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
64905 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
64906 res->sr_bits);
64907
64908- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
64909+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
64910
64911 BUG_ON(res->sr_bits != 1);
64912
64913@@ -2222,7 +2222,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
64914 mlog_errno(status);
64915 goto bail;
64916 }
64917- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
64918+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
64919
64920 BUG_ON(res.sr_bits != 1);
64921
64922@@ -2326,7 +2326,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
64923 cluster_start,
64924 num_clusters);
64925 if (!status)
64926- atomic_inc(&osb->alloc_stats.local_data);
64927+ atomic_inc_unchecked(&osb->alloc_stats.local_data);
64928 } else {
64929 if (min_clusters > (osb->bitmap_cpg - 1)) {
64930 /* The only paths asking for contiguousness
64931@@ -2352,7 +2352,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
64932 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
64933 res.sr_bg_blkno,
64934 res.sr_bit_offset);
64935- atomic_inc(&osb->alloc_stats.bitmap_data);
64936+ atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
64937 *num_clusters = res.sr_bits;
64938 }
64939 }
64940diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
64941index 93c85bc..02f68a4 100644
64942--- a/fs/ocfs2/super.c
64943+++ b/fs/ocfs2/super.c
64944@@ -300,11 +300,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
64945 "%10s => GlobalAllocs: %d LocalAllocs: %d "
64946 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
64947 "Stats",
64948- atomic_read(&osb->alloc_stats.bitmap_data),
64949- atomic_read(&osb->alloc_stats.local_data),
64950- atomic_read(&osb->alloc_stats.bg_allocs),
64951- atomic_read(&osb->alloc_stats.moves),
64952- atomic_read(&osb->alloc_stats.bg_extends));
64953+ atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
64954+ atomic_read_unchecked(&osb->alloc_stats.local_data),
64955+ atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
64956+ atomic_read_unchecked(&osb->alloc_stats.moves),
64957+ atomic_read_unchecked(&osb->alloc_stats.bg_extends));
64958
64959 out += snprintf(buf + out, len - out,
64960 "%10s => State: %u Descriptor: %llu Size: %u bits "
64961@@ -2104,11 +2104,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
64962
64963 mutex_init(&osb->system_file_mutex);
64964
64965- atomic_set(&osb->alloc_stats.moves, 0);
64966- atomic_set(&osb->alloc_stats.local_data, 0);
64967- atomic_set(&osb->alloc_stats.bitmap_data, 0);
64968- atomic_set(&osb->alloc_stats.bg_allocs, 0);
64969- atomic_set(&osb->alloc_stats.bg_extends, 0);
64970+ atomic_set_unchecked(&osb->alloc_stats.moves, 0);
64971+ atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
64972+ atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
64973+ atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
64974+ atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
64975
64976 /* Copy the blockcheck stats from the superblock probe */
64977 osb->osb_ecc_stats = *stats;
64978diff --git a/fs/open.c b/fs/open.c
64979index de92c13..52d2a6c 100644
64980--- a/fs/open.c
64981+++ b/fs/open.c
64982@@ -32,6 +32,8 @@
64983 #include <linux/dnotify.h>
64984 #include <linux/compat.h>
64985
64986+#define CREATE_TRACE_POINTS
64987+#include <trace/events/fs.h>
64988 #include "internal.h"
64989
64990 int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
64991@@ -103,6 +105,8 @@ long vfs_truncate(struct path *path, loff_t length)
64992 error = locks_verify_truncate(inode, NULL, length);
64993 if (!error)
64994 error = security_path_truncate(path);
64995+ if (!error && !gr_acl_handle_truncate(path->dentry, path->mnt))
64996+ error = -EACCES;
64997 if (!error)
64998 error = do_truncate(path->dentry, length, 0, NULL);
64999
65000@@ -187,6 +191,8 @@ static long do_sys_ftruncate(unsigned int fd, loff_t length, int small)
65001 error = locks_verify_truncate(inode, f.file, length);
65002 if (!error)
65003 error = security_path_truncate(&f.file->f_path);
65004+ if (!error && !gr_acl_handle_truncate(f.file->f_path.dentry, f.file->f_path.mnt))
65005+ error = -EACCES;
65006 if (!error)
65007 error = do_truncate(dentry, length, ATTR_MTIME|ATTR_CTIME, f.file);
65008 sb_end_write(inode->i_sb);
65009@@ -380,6 +386,9 @@ retry:
65010 if (__mnt_is_readonly(path.mnt))
65011 res = -EROFS;
65012
65013+ if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
65014+ res = -EACCES;
65015+
65016 out_path_release:
65017 path_put(&path);
65018 if (retry_estale(res, lookup_flags)) {
65019@@ -411,6 +420,8 @@ retry:
65020 if (error)
65021 goto dput_and_out;
65022
65023+ gr_log_chdir(path.dentry, path.mnt);
65024+
65025 set_fs_pwd(current->fs, &path);
65026
65027 dput_and_out:
65028@@ -440,6 +451,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
65029 goto out_putf;
65030
65031 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
65032+
65033+ if (!error && !gr_chroot_fchdir(f.file->f_path.dentry, f.file->f_path.mnt))
65034+ error = -EPERM;
65035+
65036+ if (!error)
65037+ gr_log_chdir(f.file->f_path.dentry, f.file->f_path.mnt);
65038+
65039 if (!error)
65040 set_fs_pwd(current->fs, &f.file->f_path);
65041 out_putf:
65042@@ -469,7 +487,13 @@ retry:
65043 if (error)
65044 goto dput_and_out;
65045
65046+ if (gr_handle_chroot_chroot(path.dentry, path.mnt))
65047+ goto dput_and_out;
65048+
65049 set_fs_root(current->fs, &path);
65050+
65051+ gr_handle_chroot_chdir(&path);
65052+
65053 error = 0;
65054 dput_and_out:
65055 path_put(&path);
65056@@ -493,6 +517,16 @@ static int chmod_common(struct path *path, umode_t mode)
65057 return error;
65058 retry_deleg:
65059 mutex_lock(&inode->i_mutex);
65060+
65061+ if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
65062+ error = -EACCES;
65063+ goto out_unlock;
65064+ }
65065+ if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
65066+ error = -EACCES;
65067+ goto out_unlock;
65068+ }
65069+
65070 error = security_path_chmod(path, mode);
65071 if (error)
65072 goto out_unlock;
65073@@ -558,6 +592,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
65074 uid = make_kuid(current_user_ns(), user);
65075 gid = make_kgid(current_user_ns(), group);
65076
65077+ if (!gr_acl_handle_chown(path->dentry, path->mnt))
65078+ return -EACCES;
65079+
65080 newattrs.ia_valid = ATTR_CTIME;
65081 if (user != (uid_t) -1) {
65082 if (!uid_valid(uid))
65083@@ -1002,6 +1039,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
65084 } else {
65085 fsnotify_open(f);
65086 fd_install(fd, f);
65087+ trace_do_sys_open(tmp->name, flags, mode);
65088 }
65089 }
65090 putname(tmp);
65091diff --git a/fs/pipe.c b/fs/pipe.c
65092index 21981e5..3d5f55c 100644
65093--- a/fs/pipe.c
65094+++ b/fs/pipe.c
65095@@ -56,7 +56,7 @@ unsigned int pipe_min_size = PAGE_SIZE;
65096
65097 static void pipe_lock_nested(struct pipe_inode_info *pipe, int subclass)
65098 {
65099- if (pipe->files)
65100+ if (atomic_read(&pipe->files))
65101 mutex_lock_nested(&pipe->mutex, subclass);
65102 }
65103
65104@@ -71,7 +71,7 @@ EXPORT_SYMBOL(pipe_lock);
65105
65106 void pipe_unlock(struct pipe_inode_info *pipe)
65107 {
65108- if (pipe->files)
65109+ if (atomic_read(&pipe->files))
65110 mutex_unlock(&pipe->mutex);
65111 }
65112 EXPORT_SYMBOL(pipe_unlock);
65113@@ -292,9 +292,9 @@ pipe_read(struct kiocb *iocb, struct iov_iter *to)
65114 }
65115 if (bufs) /* More to do? */
65116 continue;
65117- if (!pipe->writers)
65118+ if (!atomic_read(&pipe->writers))
65119 break;
65120- if (!pipe->waiting_writers) {
65121+ if (!atomic_read(&pipe->waiting_writers)) {
65122 /* syscall merging: Usually we must not sleep
65123 * if O_NONBLOCK is set, or if we got some data.
65124 * But if a writer sleeps in kernel space, then
65125@@ -351,7 +351,7 @@ pipe_write(struct kiocb *iocb, struct iov_iter *from)
65126
65127 __pipe_lock(pipe);
65128
65129- if (!pipe->readers) {
65130+ if (!atomic_read(&pipe->readers)) {
65131 send_sig(SIGPIPE, current, 0);
65132 ret = -EPIPE;
65133 goto out;
65134@@ -387,7 +387,7 @@ pipe_write(struct kiocb *iocb, struct iov_iter *from)
65135 for (;;) {
65136 int bufs;
65137
65138- if (!pipe->readers) {
65139+ if (!atomic_read(&pipe->readers)) {
65140 send_sig(SIGPIPE, current, 0);
65141 if (!ret)
65142 ret = -EPIPE;
65143@@ -455,9 +455,9 @@ pipe_write(struct kiocb *iocb, struct iov_iter *from)
65144 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
65145 do_wakeup = 0;
65146 }
65147- pipe->waiting_writers++;
65148+ atomic_inc(&pipe->waiting_writers);
65149 pipe_wait(pipe);
65150- pipe->waiting_writers--;
65151+ atomic_dec(&pipe->waiting_writers);
65152 }
65153 out:
65154 __pipe_unlock(pipe);
65155@@ -512,7 +512,7 @@ pipe_poll(struct file *filp, poll_table *wait)
65156 mask = 0;
65157 if (filp->f_mode & FMODE_READ) {
65158 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
65159- if (!pipe->writers && filp->f_version != pipe->w_counter)
65160+ if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
65161 mask |= POLLHUP;
65162 }
65163
65164@@ -522,7 +522,7 @@ pipe_poll(struct file *filp, poll_table *wait)
65165 * Most Unices do not set POLLERR for FIFOs but on Linux they
65166 * behave exactly like pipes for poll().
65167 */
65168- if (!pipe->readers)
65169+ if (!atomic_read(&pipe->readers))
65170 mask |= POLLERR;
65171 }
65172
65173@@ -534,7 +534,7 @@ static void put_pipe_info(struct inode *inode, struct pipe_inode_info *pipe)
65174 int kill = 0;
65175
65176 spin_lock(&inode->i_lock);
65177- if (!--pipe->files) {
65178+ if (atomic_dec_and_test(&pipe->files)) {
65179 inode->i_pipe = NULL;
65180 kill = 1;
65181 }
65182@@ -551,11 +551,11 @@ pipe_release(struct inode *inode, struct file *file)
65183
65184 __pipe_lock(pipe);
65185 if (file->f_mode & FMODE_READ)
65186- pipe->readers--;
65187+ atomic_dec(&pipe->readers);
65188 if (file->f_mode & FMODE_WRITE)
65189- pipe->writers--;
65190+ atomic_dec(&pipe->writers);
65191
65192- if (pipe->readers || pipe->writers) {
65193+ if (atomic_read(&pipe->readers) || atomic_read(&pipe->writers)) {
65194 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
65195 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
65196 kill_fasync(&pipe->fasync_writers, SIGIO, POLL_OUT);
65197@@ -620,7 +620,7 @@ void free_pipe_info(struct pipe_inode_info *pipe)
65198 kfree(pipe);
65199 }
65200
65201-static struct vfsmount *pipe_mnt __read_mostly;
65202+struct vfsmount *pipe_mnt __read_mostly;
65203
65204 /*
65205 * pipefs_dname() is called from d_path().
65206@@ -650,8 +650,9 @@ static struct inode * get_pipe_inode(void)
65207 goto fail_iput;
65208
65209 inode->i_pipe = pipe;
65210- pipe->files = 2;
65211- pipe->readers = pipe->writers = 1;
65212+ atomic_set(&pipe->files, 2);
65213+ atomic_set(&pipe->readers, 1);
65214+ atomic_set(&pipe->writers, 1);
65215 inode->i_fop = &pipefifo_fops;
65216
65217 /*
65218@@ -830,17 +831,17 @@ static int fifo_open(struct inode *inode, struct file *filp)
65219 spin_lock(&inode->i_lock);
65220 if (inode->i_pipe) {
65221 pipe = inode->i_pipe;
65222- pipe->files++;
65223+ atomic_inc(&pipe->files);
65224 spin_unlock(&inode->i_lock);
65225 } else {
65226 spin_unlock(&inode->i_lock);
65227 pipe = alloc_pipe_info();
65228 if (!pipe)
65229 return -ENOMEM;
65230- pipe->files = 1;
65231+ atomic_set(&pipe->files, 1);
65232 spin_lock(&inode->i_lock);
65233 if (unlikely(inode->i_pipe)) {
65234- inode->i_pipe->files++;
65235+ atomic_inc(&inode->i_pipe->files);
65236 spin_unlock(&inode->i_lock);
65237 free_pipe_info(pipe);
65238 pipe = inode->i_pipe;
65239@@ -865,10 +866,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
65240 * opened, even when there is no process writing the FIFO.
65241 */
65242 pipe->r_counter++;
65243- if (pipe->readers++ == 0)
65244+ if (atomic_inc_return(&pipe->readers) == 1)
65245 wake_up_partner(pipe);
65246
65247- if (!is_pipe && !pipe->writers) {
65248+ if (!is_pipe && !atomic_read(&pipe->writers)) {
65249 if ((filp->f_flags & O_NONBLOCK)) {
65250 /* suppress POLLHUP until we have
65251 * seen a writer */
65252@@ -887,14 +888,14 @@ static int fifo_open(struct inode *inode, struct file *filp)
65253 * errno=ENXIO when there is no process reading the FIFO.
65254 */
65255 ret = -ENXIO;
65256- if (!is_pipe && (filp->f_flags & O_NONBLOCK) && !pipe->readers)
65257+ if (!is_pipe && (filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
65258 goto err;
65259
65260 pipe->w_counter++;
65261- if (!pipe->writers++)
65262+ if (atomic_inc_return(&pipe->writers) == 1)
65263 wake_up_partner(pipe);
65264
65265- if (!is_pipe && !pipe->readers) {
65266+ if (!is_pipe && !atomic_read(&pipe->readers)) {
65267 if (wait_for_partner(pipe, &pipe->r_counter))
65268 goto err_wr;
65269 }
65270@@ -908,11 +909,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
65271 * the process can at least talk to itself.
65272 */
65273
65274- pipe->readers++;
65275- pipe->writers++;
65276+ atomic_inc(&pipe->readers);
65277+ atomic_inc(&pipe->writers);
65278 pipe->r_counter++;
65279 pipe->w_counter++;
65280- if (pipe->readers == 1 || pipe->writers == 1)
65281+ if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
65282 wake_up_partner(pipe);
65283 break;
65284
65285@@ -926,13 +927,13 @@ static int fifo_open(struct inode *inode, struct file *filp)
65286 return 0;
65287
65288 err_rd:
65289- if (!--pipe->readers)
65290+ if (atomic_dec_and_test(&pipe->readers))
65291 wake_up_interruptible(&pipe->wait);
65292 ret = -ERESTARTSYS;
65293 goto err;
65294
65295 err_wr:
65296- if (!--pipe->writers)
65297+ if (atomic_dec_and_test(&pipe->writers))
65298 wake_up_interruptible(&pipe->wait);
65299 ret = -ERESTARTSYS;
65300 goto err;
65301diff --git a/fs/posix_acl.c b/fs/posix_acl.c
65302index 0855f77..6787d50 100644
65303--- a/fs/posix_acl.c
65304+++ b/fs/posix_acl.c
65305@@ -20,6 +20,7 @@
65306 #include <linux/xattr.h>
65307 #include <linux/export.h>
65308 #include <linux/user_namespace.h>
65309+#include <linux/grsecurity.h>
65310
65311 struct posix_acl **acl_by_type(struct inode *inode, int type)
65312 {
65313@@ -277,7 +278,7 @@ posix_acl_equiv_mode(const struct posix_acl *acl, umode_t *mode_p)
65314 }
65315 }
65316 if (mode_p)
65317- *mode_p = (*mode_p & ~S_IRWXUGO) | mode;
65318+ *mode_p = ((*mode_p & ~S_IRWXUGO) | mode) & ~gr_acl_umask();
65319 return not_equiv;
65320 }
65321 EXPORT_SYMBOL(posix_acl_equiv_mode);
65322@@ -427,7 +428,7 @@ static int posix_acl_create_masq(struct posix_acl *acl, umode_t *mode_p)
65323 mode &= (group_obj->e_perm << 3) | ~S_IRWXG;
65324 }
65325
65326- *mode_p = (*mode_p & ~S_IRWXUGO) | mode;
65327+ *mode_p = ((*mode_p & ~S_IRWXUGO) | mode) & ~gr_acl_umask();
65328 return not_equiv;
65329 }
65330
65331@@ -485,6 +486,8 @@ __posix_acl_create(struct posix_acl **acl, gfp_t gfp, umode_t *mode_p)
65332 struct posix_acl *clone = posix_acl_clone(*acl, gfp);
65333 int err = -ENOMEM;
65334 if (clone) {
65335+ *mode_p &= ~gr_acl_umask();
65336+
65337 err = posix_acl_create_masq(clone, mode_p);
65338 if (err < 0) {
65339 posix_acl_release(clone);
65340@@ -659,11 +662,12 @@ struct posix_acl *
65341 posix_acl_from_xattr(struct user_namespace *user_ns,
65342 const void *value, size_t size)
65343 {
65344- posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
65345- posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
65346+ const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
65347+ const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
65348 int count;
65349 struct posix_acl *acl;
65350 struct posix_acl_entry *acl_e;
65351+ umode_t umask = gr_acl_umask();
65352
65353 if (!value)
65354 return NULL;
65355@@ -689,12 +693,18 @@ posix_acl_from_xattr(struct user_namespace *user_ns,
65356
65357 switch(acl_e->e_tag) {
65358 case ACL_USER_OBJ:
65359+ acl_e->e_perm &= ~((umask & S_IRWXU) >> 6);
65360+ break;
65361 case ACL_GROUP_OBJ:
65362 case ACL_MASK:
65363+ acl_e->e_perm &= ~((umask & S_IRWXG) >> 3);
65364+ break;
65365 case ACL_OTHER:
65366+ acl_e->e_perm &= ~(umask & S_IRWXO);
65367 break;
65368
65369 case ACL_USER:
65370+ acl_e->e_perm &= ~((umask & S_IRWXU) >> 6);
65371 acl_e->e_uid =
65372 make_kuid(user_ns,
65373 le32_to_cpu(entry->e_id));
65374@@ -702,6 +712,7 @@ posix_acl_from_xattr(struct user_namespace *user_ns,
65375 goto fail;
65376 break;
65377 case ACL_GROUP:
65378+ acl_e->e_perm &= ~((umask & S_IRWXG) >> 3);
65379 acl_e->e_gid =
65380 make_kgid(user_ns,
65381 le32_to_cpu(entry->e_id));
65382diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
65383index 2183fcf..3c32a98 100644
65384--- a/fs/proc/Kconfig
65385+++ b/fs/proc/Kconfig
65386@@ -30,7 +30,7 @@ config PROC_FS
65387
65388 config PROC_KCORE
65389 bool "/proc/kcore support" if !ARM
65390- depends on PROC_FS && MMU
65391+ depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
65392 help
65393 Provides a virtual ELF core file of the live kernel. This can
65394 be read with gdb and other ELF tools. No modifications can be
65395@@ -38,8 +38,8 @@ config PROC_KCORE
65396
65397 config PROC_VMCORE
65398 bool "/proc/vmcore support"
65399- depends on PROC_FS && CRASH_DUMP
65400- default y
65401+ depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
65402+ default n
65403 help
65404 Exports the dump image of crashed kernel in ELF format.
65405
65406@@ -63,8 +63,8 @@ config PROC_SYSCTL
65407 limited in memory.
65408
65409 config PROC_PAGE_MONITOR
65410- default y
65411- depends on PROC_FS && MMU
65412+ default n
65413+ depends on PROC_FS && MMU && !GRKERNSEC
65414 bool "Enable /proc page monitoring" if EXPERT
65415 help
65416 Various /proc files exist to monitor process memory utilization:
65417diff --git a/fs/proc/array.c b/fs/proc/array.c
65418index cd3653e..9b9b79a 100644
65419--- a/fs/proc/array.c
65420+++ b/fs/proc/array.c
65421@@ -60,6 +60,7 @@
65422 #include <linux/tty.h>
65423 #include <linux/string.h>
65424 #include <linux/mman.h>
65425+#include <linux/grsecurity.h>
65426 #include <linux/proc_fs.h>
65427 #include <linux/ioport.h>
65428 #include <linux/uaccess.h>
65429@@ -347,6 +348,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
65430 seq_putc(m, '\n');
65431 }
65432
65433+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
65434+static inline void task_pax(struct seq_file *m, struct task_struct *p)
65435+{
65436+ if (p->mm)
65437+ seq_printf(m, "PaX:\t%c%c%c%c%c\n",
65438+ p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
65439+ p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
65440+ p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
65441+ p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
65442+ p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
65443+ else
65444+ seq_printf(m, "PaX:\t-----\n");
65445+}
65446+#endif
65447+
65448 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
65449 struct pid *pid, struct task_struct *task)
65450 {
65451@@ -365,9 +381,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
65452 task_cpus_allowed(m, task);
65453 cpuset_task_status_allowed(m, task);
65454 task_context_switch_counts(m, task);
65455+
65456+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
65457+ task_pax(m, task);
65458+#endif
65459+
65460+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
65461+ task_grsec_rbac(m, task);
65462+#endif
65463+
65464 return 0;
65465 }
65466
65467+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65468+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
65469+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
65470+ _mm->pax_flags & MF_PAX_SEGMEXEC))
65471+#endif
65472+
65473 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
65474 struct pid *pid, struct task_struct *task, int whole)
65475 {
65476@@ -389,6 +420,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
65477 char tcomm[sizeof(task->comm)];
65478 unsigned long flags;
65479
65480+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65481+ if (current->exec_id != m->exec_id) {
65482+ gr_log_badprocpid("stat");
65483+ return 0;
65484+ }
65485+#endif
65486+
65487 state = *get_task_state(task);
65488 vsize = eip = esp = 0;
65489 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
65490@@ -459,6 +497,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
65491 gtime = task_gtime(task);
65492 }
65493
65494+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65495+ if (PAX_RAND_FLAGS(mm)) {
65496+ eip = 0;
65497+ esp = 0;
65498+ wchan = 0;
65499+ }
65500+#endif
65501+#ifdef CONFIG_GRKERNSEC_HIDESYM
65502+ wchan = 0;
65503+ eip =0;
65504+ esp =0;
65505+#endif
65506+
65507 /* scale priority and nice values from timeslices to -20..20 */
65508 /* to make it look like a "normal" Unix priority/nice value */
65509 priority = task_prio(task);
65510@@ -490,9 +541,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
65511 seq_put_decimal_ull(m, ' ', vsize);
65512 seq_put_decimal_ull(m, ' ', mm ? get_mm_rss(mm) : 0);
65513 seq_put_decimal_ull(m, ' ', rsslim);
65514+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65515+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0));
65516+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0));
65517+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0));
65518+#else
65519 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->start_code : 1) : 0);
65520 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->end_code : 1) : 0);
65521 seq_put_decimal_ull(m, ' ', (permitted && mm) ? mm->start_stack : 0);
65522+#endif
65523 seq_put_decimal_ull(m, ' ', esp);
65524 seq_put_decimal_ull(m, ' ', eip);
65525 /* The signal information here is obsolete.
65526@@ -514,7 +571,11 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
65527 seq_put_decimal_ull(m, ' ', cputime_to_clock_t(gtime));
65528 seq_put_decimal_ll(m, ' ', cputime_to_clock_t(cgtime));
65529
65530- if (mm && permitted) {
65531+ if (mm && permitted
65532+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65533+ && !PAX_RAND_FLAGS(mm)
65534+#endif
65535+ ) {
65536 seq_put_decimal_ull(m, ' ', mm->start_data);
65537 seq_put_decimal_ull(m, ' ', mm->end_data);
65538 seq_put_decimal_ull(m, ' ', mm->start_brk);
65539@@ -552,8 +613,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
65540 struct pid *pid, struct task_struct *task)
65541 {
65542 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
65543- struct mm_struct *mm = get_task_mm(task);
65544+ struct mm_struct *mm;
65545
65546+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65547+ if (current->exec_id != m->exec_id) {
65548+ gr_log_badprocpid("statm");
65549+ return 0;
65550+ }
65551+#endif
65552+ mm = get_task_mm(task);
65553 if (mm) {
65554 size = task_statm(mm, &shared, &text, &data, &resident);
65555 mmput(mm);
65556@@ -576,6 +644,20 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
65557 return 0;
65558 }
65559
65560+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
65561+int proc_pid_ipaddr(struct seq_file *m, struct pid_namespace *ns, struct pid *pid, struct task_struct *task)
65562+{
65563+ unsigned long flags;
65564+ u32 curr_ip = 0;
65565+
65566+ if (lock_task_sighand(task, &flags)) {
65567+ curr_ip = task->signal->curr_ip;
65568+ unlock_task_sighand(task, &flags);
65569+ }
65570+ return seq_printf(m, "%pI4\n", &curr_ip);
65571+}
65572+#endif
65573+
65574 #ifdef CONFIG_CHECKPOINT_RESTORE
65575 static struct pid *
65576 get_children_pid(struct inode *inode, struct pid *pid_prev, loff_t pos)
65577diff --git a/fs/proc/base.c b/fs/proc/base.c
65578index 7dc3ea8..4cfe92f 100644
65579--- a/fs/proc/base.c
65580+++ b/fs/proc/base.c
65581@@ -113,6 +113,14 @@ struct pid_entry {
65582 union proc_op op;
65583 };
65584
65585+struct getdents_callback {
65586+ struct linux_dirent __user * current_dir;
65587+ struct linux_dirent __user * previous;
65588+ struct file * file;
65589+ int count;
65590+ int error;
65591+};
65592+
65593 #define NOD(NAME, MODE, IOP, FOP, OP) { \
65594 .name = (NAME), \
65595 .len = sizeof(NAME) - 1, \
65596@@ -208,12 +216,28 @@ static int proc_pid_cmdline(struct seq_file *m, struct pid_namespace *ns,
65597 return 0;
65598 }
65599
65600+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65601+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
65602+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
65603+ _mm->pax_flags & MF_PAX_SEGMEXEC))
65604+#endif
65605+
65606 static int proc_pid_auxv(struct seq_file *m, struct pid_namespace *ns,
65607 struct pid *pid, struct task_struct *task)
65608 {
65609 struct mm_struct *mm = mm_access(task, PTRACE_MODE_READ);
65610 if (mm && !IS_ERR(mm)) {
65611 unsigned int nwords = 0;
65612+
65613+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65614+ /* allow if we're currently ptracing this task */
65615+ if (PAX_RAND_FLAGS(mm) &&
65616+ (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
65617+ mmput(mm);
65618+ return 0;
65619+ }
65620+#endif
65621+
65622 do {
65623 nwords += 2;
65624 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
65625@@ -225,7 +249,7 @@ static int proc_pid_auxv(struct seq_file *m, struct pid_namespace *ns,
65626 }
65627
65628
65629-#ifdef CONFIG_KALLSYMS
65630+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
65631 /*
65632 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
65633 * Returns the resolved symbol. If that fails, simply return the address.
65634@@ -265,7 +289,7 @@ static void unlock_trace(struct task_struct *task)
65635 mutex_unlock(&task->signal->cred_guard_mutex);
65636 }
65637
65638-#ifdef CONFIG_STACKTRACE
65639+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
65640
65641 #define MAX_STACK_TRACE_DEPTH 64
65642
65643@@ -456,7 +480,7 @@ static int proc_pid_limits(struct seq_file *m, struct pid_namespace *ns,
65644 return 0;
65645 }
65646
65647-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
65648+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
65649 static int proc_pid_syscall(struct seq_file *m, struct pid_namespace *ns,
65650 struct pid *pid, struct task_struct *task)
65651 {
65652@@ -486,7 +510,7 @@ static int proc_pid_syscall(struct seq_file *m, struct pid_namespace *ns,
65653 /************************************************************************/
65654
65655 /* permission checks */
65656-static int proc_fd_access_allowed(struct inode *inode)
65657+static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
65658 {
65659 struct task_struct *task;
65660 int allowed = 0;
65661@@ -496,7 +520,10 @@ static int proc_fd_access_allowed(struct inode *inode)
65662 */
65663 task = get_proc_task(inode);
65664 if (task) {
65665- allowed = ptrace_may_access(task, PTRACE_MODE_READ);
65666+ if (log)
65667+ allowed = ptrace_may_access(task, PTRACE_MODE_READ);
65668+ else
65669+ allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
65670 put_task_struct(task);
65671 }
65672 return allowed;
65673@@ -527,10 +554,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
65674 struct task_struct *task,
65675 int hide_pid_min)
65676 {
65677+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
65678+ return false;
65679+
65680+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
65681+ rcu_read_lock();
65682+ {
65683+ const struct cred *tmpcred = current_cred();
65684+ const struct cred *cred = __task_cred(task);
65685+
65686+ if (uid_eq(tmpcred->uid, GLOBAL_ROOT_UID) || uid_eq(tmpcred->uid, cred->uid)
65687+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
65688+ || in_group_p(grsec_proc_gid)
65689+#endif
65690+ ) {
65691+ rcu_read_unlock();
65692+ return true;
65693+ }
65694+ }
65695+ rcu_read_unlock();
65696+
65697+ if (!pid->hide_pid)
65698+ return false;
65699+#endif
65700+
65701 if (pid->hide_pid < hide_pid_min)
65702 return true;
65703 if (in_group_p(pid->pid_gid))
65704 return true;
65705+
65706 return ptrace_may_access(task, PTRACE_MODE_READ);
65707 }
65708
65709@@ -548,7 +600,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
65710 put_task_struct(task);
65711
65712 if (!has_perms) {
65713+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
65714+ {
65715+#else
65716 if (pid->hide_pid == 2) {
65717+#endif
65718 /*
65719 * Let's make getdents(), stat(), and open()
65720 * consistent with each other. If a process
65721@@ -609,6 +665,8 @@ struct mm_struct *proc_mem_open(struct inode *inode, unsigned int mode)
65722
65723 if (task) {
65724 mm = mm_access(task, mode);
65725+ if (gr_acl_handle_procpidmem(task))
65726+ mm = ERR_PTR(-EPERM);
65727 put_task_struct(task);
65728
65729 if (!IS_ERR_OR_NULL(mm)) {
65730@@ -630,6 +688,11 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
65731 return PTR_ERR(mm);
65732
65733 file->private_data = mm;
65734+
65735+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65736+ file->f_version = current->exec_id;
65737+#endif
65738+
65739 return 0;
65740 }
65741
65742@@ -651,6 +714,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
65743 ssize_t copied;
65744 char *page;
65745
65746+#ifdef CONFIG_GRKERNSEC
65747+ if (write)
65748+ return -EPERM;
65749+#endif
65750+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65751+ if (file->f_version != current->exec_id) {
65752+ gr_log_badprocpid("mem");
65753+ return 0;
65754+ }
65755+#endif
65756+
65757 if (!mm)
65758 return 0;
65759
65760@@ -663,7 +737,7 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
65761 goto free;
65762
65763 while (count > 0) {
65764- int this_len = min_t(int, count, PAGE_SIZE);
65765+ ssize_t this_len = min_t(ssize_t, count, PAGE_SIZE);
65766
65767 if (write && copy_from_user(page, buf, this_len)) {
65768 copied = -EFAULT;
65769@@ -755,6 +829,13 @@ static ssize_t environ_read(struct file *file, char __user *buf,
65770 if (!mm)
65771 return 0;
65772
65773+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65774+ if (file->f_version != current->exec_id) {
65775+ gr_log_badprocpid("environ");
65776+ return 0;
65777+ }
65778+#endif
65779+
65780 page = (char *)__get_free_page(GFP_TEMPORARY);
65781 if (!page)
65782 return -ENOMEM;
65783@@ -764,7 +845,7 @@ static ssize_t environ_read(struct file *file, char __user *buf,
65784 goto free;
65785 while (count > 0) {
65786 size_t this_len, max_len;
65787- int retval;
65788+ ssize_t retval;
65789
65790 if (src >= (mm->env_end - mm->env_start))
65791 break;
65792@@ -1378,7 +1459,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
65793 int error = -EACCES;
65794
65795 /* Are we allowed to snoop on the tasks file descriptors? */
65796- if (!proc_fd_access_allowed(inode))
65797+ if (!proc_fd_access_allowed(inode, 0))
65798 goto out;
65799
65800 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
65801@@ -1422,8 +1503,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
65802 struct path path;
65803
65804 /* Are we allowed to snoop on the tasks file descriptors? */
65805- if (!proc_fd_access_allowed(inode))
65806- goto out;
65807+ /* logging this is needed for learning on chromium to work properly,
65808+ but we don't want to flood the logs from 'ps' which does a readlink
65809+ on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
65810+ CAP_SYS_PTRACE as it's not necessary for its basic functionality
65811+ */
65812+ if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
65813+ if (!proc_fd_access_allowed(inode,0))
65814+ goto out;
65815+ } else {
65816+ if (!proc_fd_access_allowed(inode,1))
65817+ goto out;
65818+ }
65819
65820 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
65821 if (error)
65822@@ -1473,7 +1564,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
65823 rcu_read_lock();
65824 cred = __task_cred(task);
65825 inode->i_uid = cred->euid;
65826+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
65827+ inode->i_gid = grsec_proc_gid;
65828+#else
65829 inode->i_gid = cred->egid;
65830+#endif
65831 rcu_read_unlock();
65832 }
65833 security_task_to_inode(task, inode);
65834@@ -1509,10 +1604,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
65835 return -ENOENT;
65836 }
65837 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
65838+#ifdef CONFIG_GRKERNSEC_PROC_USER
65839+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
65840+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
65841+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
65842+#endif
65843 task_dumpable(task)) {
65844 cred = __task_cred(task);
65845 stat->uid = cred->euid;
65846+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
65847+ stat->gid = grsec_proc_gid;
65848+#else
65849 stat->gid = cred->egid;
65850+#endif
65851 }
65852 }
65853 rcu_read_unlock();
65854@@ -1550,11 +1654,20 @@ int pid_revalidate(struct dentry *dentry, unsigned int flags)
65855
65856 if (task) {
65857 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
65858+#ifdef CONFIG_GRKERNSEC_PROC_USER
65859+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
65860+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
65861+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
65862+#endif
65863 task_dumpable(task)) {
65864 rcu_read_lock();
65865 cred = __task_cred(task);
65866 inode->i_uid = cred->euid;
65867+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
65868+ inode->i_gid = grsec_proc_gid;
65869+#else
65870 inode->i_gid = cred->egid;
65871+#endif
65872 rcu_read_unlock();
65873 } else {
65874 inode->i_uid = GLOBAL_ROOT_UID;
65875@@ -2085,6 +2198,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
65876 if (!task)
65877 goto out_no_task;
65878
65879+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
65880+ goto out;
65881+
65882 /*
65883 * Yes, it does not scale. And it should not. Don't add
65884 * new entries into /proc/<tgid>/ without very good reasons.
65885@@ -2115,6 +2231,9 @@ static int proc_pident_readdir(struct file *file, struct dir_context *ctx,
65886 if (!task)
65887 return -ENOENT;
65888
65889+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
65890+ goto out;
65891+
65892 if (!dir_emit_dots(file, ctx))
65893 goto out;
65894
65895@@ -2557,7 +2676,7 @@ static const struct pid_entry tgid_base_stuff[] = {
65896 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
65897 #endif
65898 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
65899-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
65900+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
65901 ONE("syscall", S_IRUSR, proc_pid_syscall),
65902 #endif
65903 ONE("cmdline", S_IRUGO, proc_pid_cmdline),
65904@@ -2582,10 +2701,10 @@ static const struct pid_entry tgid_base_stuff[] = {
65905 #ifdef CONFIG_SECURITY
65906 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
65907 #endif
65908-#ifdef CONFIG_KALLSYMS
65909+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
65910 ONE("wchan", S_IRUGO, proc_pid_wchan),
65911 #endif
65912-#ifdef CONFIG_STACKTRACE
65913+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
65914 ONE("stack", S_IRUSR, proc_pid_stack),
65915 #endif
65916 #ifdef CONFIG_SCHEDSTATS
65917@@ -2619,6 +2738,9 @@ static const struct pid_entry tgid_base_stuff[] = {
65918 #ifdef CONFIG_HARDWALL
65919 ONE("hardwall", S_IRUGO, proc_pid_hardwall),
65920 #endif
65921+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
65922+ ONE("ipaddr", S_IRUSR, proc_pid_ipaddr),
65923+#endif
65924 #ifdef CONFIG_USER_NS
65925 REG("uid_map", S_IRUGO|S_IWUSR, proc_uid_map_operations),
65926 REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations),
65927@@ -2748,7 +2870,14 @@ static int proc_pid_instantiate(struct inode *dir,
65928 if (!inode)
65929 goto out;
65930
65931+#ifdef CONFIG_GRKERNSEC_PROC_USER
65932+ inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
65933+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
65934+ inode->i_gid = grsec_proc_gid;
65935+ inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
65936+#else
65937 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
65938+#endif
65939 inode->i_op = &proc_tgid_base_inode_operations;
65940 inode->i_fop = &proc_tgid_base_operations;
65941 inode->i_flags|=S_IMMUTABLE;
65942@@ -2786,7 +2915,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, unsign
65943 if (!task)
65944 goto out;
65945
65946+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
65947+ goto out_put_task;
65948+
65949 result = proc_pid_instantiate(dir, dentry, task, NULL);
65950+out_put_task:
65951 put_task_struct(task);
65952 out:
65953 return ERR_PTR(result);
65954@@ -2900,7 +3033,7 @@ static const struct pid_entry tid_base_stuff[] = {
65955 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
65956 #endif
65957 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
65958-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
65959+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
65960 ONE("syscall", S_IRUSR, proc_pid_syscall),
65961 #endif
65962 ONE("cmdline", S_IRUGO, proc_pid_cmdline),
65963@@ -2927,10 +3060,10 @@ static const struct pid_entry tid_base_stuff[] = {
65964 #ifdef CONFIG_SECURITY
65965 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
65966 #endif
65967-#ifdef CONFIG_KALLSYMS
65968+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
65969 ONE("wchan", S_IRUGO, proc_pid_wchan),
65970 #endif
65971-#ifdef CONFIG_STACKTRACE
65972+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
65973 ONE("stack", S_IRUSR, proc_pid_stack),
65974 #endif
65975 #ifdef CONFIG_SCHEDSTATS
65976diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
65977index cbd82df..c0407d2 100644
65978--- a/fs/proc/cmdline.c
65979+++ b/fs/proc/cmdline.c
65980@@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
65981
65982 static int __init proc_cmdline_init(void)
65983 {
65984+#ifdef CONFIG_GRKERNSEC_PROC_ADD
65985+ proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
65986+#else
65987 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
65988+#endif
65989 return 0;
65990 }
65991 fs_initcall(proc_cmdline_init);
65992diff --git a/fs/proc/devices.c b/fs/proc/devices.c
65993index 50493ed..248166b 100644
65994--- a/fs/proc/devices.c
65995+++ b/fs/proc/devices.c
65996@@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
65997
65998 static int __init proc_devices_init(void)
65999 {
66000+#ifdef CONFIG_GRKERNSEC_PROC_ADD
66001+ proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
66002+#else
66003 proc_create("devices", 0, NULL, &proc_devinfo_operations);
66004+#endif
66005 return 0;
66006 }
66007 fs_initcall(proc_devices_init);
66008diff --git a/fs/proc/fd.c b/fs/proc/fd.c
66009index e11d7c5..9128ce06 100644
66010--- a/fs/proc/fd.c
66011+++ b/fs/proc/fd.c
66012@@ -26,7 +26,8 @@ static int seq_show(struct seq_file *m, void *v)
66013 if (!task)
66014 return -ENOENT;
66015
66016- files = get_files_struct(task);
66017+ if (!gr_acl_handle_procpidmem(task))
66018+ files = get_files_struct(task);
66019 put_task_struct(task);
66020
66021 if (files) {
66022@@ -283,11 +284,21 @@ static struct dentry *proc_lookupfd(struct inode *dir, struct dentry *dentry,
66023 */
66024 int proc_fd_permission(struct inode *inode, int mask)
66025 {
66026+ struct task_struct *task;
66027 int rv = generic_permission(inode, mask);
66028- if (rv == 0)
66029- return 0;
66030+
66031 if (task_tgid(current) == proc_pid(inode))
66032 rv = 0;
66033+
66034+ task = get_proc_task(inode);
66035+ if (task == NULL)
66036+ return rv;
66037+
66038+ if (gr_acl_handle_procpidmem(task))
66039+ rv = -EACCES;
66040+
66041+ put_task_struct(task);
66042+
66043 return rv;
66044 }
66045
66046diff --git a/fs/proc/generic.c b/fs/proc/generic.c
66047index 317b726..e329aed 100644
66048--- a/fs/proc/generic.c
66049+++ b/fs/proc/generic.c
66050@@ -23,6 +23,7 @@
66051 #include <linux/bitops.h>
66052 #include <linux/spinlock.h>
66053 #include <linux/completion.h>
66054+#include <linux/grsecurity.h>
66055 #include <asm/uaccess.h>
66056
66057 #include "internal.h"
66058@@ -207,6 +208,15 @@ struct dentry *proc_lookup(struct inode *dir, struct dentry *dentry,
66059 return proc_lookup_de(PDE(dir), dir, dentry);
66060 }
66061
66062+struct dentry *proc_lookup_restrict(struct inode *dir, struct dentry *dentry,
66063+ unsigned int flags)
66064+{
66065+ if (gr_proc_is_restricted())
66066+ return ERR_PTR(-EACCES);
66067+
66068+ return proc_lookup_de(PDE(dir), dir, dentry);
66069+}
66070+
66071 /*
66072 * This returns non-zero if at EOF, so that the /proc
66073 * root directory can use this and check if it should
66074@@ -264,6 +274,16 @@ int proc_readdir(struct file *file, struct dir_context *ctx)
66075 return proc_readdir_de(PDE(inode), file, ctx);
66076 }
66077
66078+int proc_readdir_restrict(struct file *file, struct dir_context *ctx)
66079+{
66080+ struct inode *inode = file_inode(file);
66081+
66082+ if (gr_proc_is_restricted())
66083+ return -EACCES;
66084+
66085+ return proc_readdir_de(PDE(inode), file, ctx);
66086+}
66087+
66088 /*
66089 * These are the generic /proc directory operations. They
66090 * use the in-memory "struct proc_dir_entry" tree to parse
66091@@ -275,6 +295,12 @@ static const struct file_operations proc_dir_operations = {
66092 .iterate = proc_readdir,
66093 };
66094
66095+static const struct file_operations proc_dir_restricted_operations = {
66096+ .llseek = generic_file_llseek,
66097+ .read = generic_read_dir,
66098+ .iterate = proc_readdir_restrict,
66099+};
66100+
66101 /*
66102 * proc directories can do almost nothing..
66103 */
66104@@ -284,6 +310,12 @@ static const struct inode_operations proc_dir_inode_operations = {
66105 .setattr = proc_notify_change,
66106 };
66107
66108+static const struct inode_operations proc_dir_restricted_inode_operations = {
66109+ .lookup = proc_lookup_restrict,
66110+ .getattr = proc_getattr,
66111+ .setattr = proc_notify_change,
66112+};
66113+
66114 static int proc_register(struct proc_dir_entry * dir, struct proc_dir_entry * dp)
66115 {
66116 struct proc_dir_entry *tmp;
66117@@ -294,8 +326,13 @@ static int proc_register(struct proc_dir_entry * dir, struct proc_dir_entry * dp
66118 return ret;
66119
66120 if (S_ISDIR(dp->mode)) {
66121- dp->proc_fops = &proc_dir_operations;
66122- dp->proc_iops = &proc_dir_inode_operations;
66123+ if (dp->restricted) {
66124+ dp->proc_fops = &proc_dir_restricted_operations;
66125+ dp->proc_iops = &proc_dir_restricted_inode_operations;
66126+ } else {
66127+ dp->proc_fops = &proc_dir_operations;
66128+ dp->proc_iops = &proc_dir_inode_operations;
66129+ }
66130 dir->nlink++;
66131 } else if (S_ISLNK(dp->mode)) {
66132 dp->proc_iops = &proc_link_inode_operations;
66133@@ -407,6 +444,27 @@ struct proc_dir_entry *proc_mkdir_data(const char *name, umode_t mode,
66134 }
66135 EXPORT_SYMBOL_GPL(proc_mkdir_data);
66136
66137+struct proc_dir_entry *proc_mkdir_data_restrict(const char *name, umode_t mode,
66138+ struct proc_dir_entry *parent, void *data)
66139+{
66140+ struct proc_dir_entry *ent;
66141+
66142+ if (mode == 0)
66143+ mode = S_IRUGO | S_IXUGO;
66144+
66145+ ent = __proc_create(&parent, name, S_IFDIR | mode, 2);
66146+ if (ent) {
66147+ ent->data = data;
66148+ ent->restricted = 1;
66149+ if (proc_register(parent, ent) < 0) {
66150+ kfree(ent);
66151+ ent = NULL;
66152+ }
66153+ }
66154+ return ent;
66155+}
66156+EXPORT_SYMBOL_GPL(proc_mkdir_data_restrict);
66157+
66158 struct proc_dir_entry *proc_mkdir_mode(const char *name, umode_t mode,
66159 struct proc_dir_entry *parent)
66160 {
66161@@ -421,6 +479,13 @@ struct proc_dir_entry *proc_mkdir(const char *name,
66162 }
66163 EXPORT_SYMBOL(proc_mkdir);
66164
66165+struct proc_dir_entry *proc_mkdir_restrict(const char *name,
66166+ struct proc_dir_entry *parent)
66167+{
66168+ return proc_mkdir_data_restrict(name, 0, parent, NULL);
66169+}
66170+EXPORT_SYMBOL(proc_mkdir_restrict);
66171+
66172 struct proc_dir_entry *proc_create_data(const char *name, umode_t mode,
66173 struct proc_dir_entry *parent,
66174 const struct file_operations *proc_fops,
66175diff --git a/fs/proc/inode.c b/fs/proc/inode.c
66176index 333080d..0a35ec4 100644
66177--- a/fs/proc/inode.c
66178+++ b/fs/proc/inode.c
66179@@ -23,11 +23,17 @@
66180 #include <linux/slab.h>
66181 #include <linux/mount.h>
66182 #include <linux/magic.h>
66183+#include <linux/grsecurity.h>
66184
66185 #include <asm/uaccess.h>
66186
66187 #include "internal.h"
66188
66189+#ifdef CONFIG_PROC_SYSCTL
66190+extern const struct inode_operations proc_sys_inode_operations;
66191+extern const struct inode_operations proc_sys_dir_operations;
66192+#endif
66193+
66194 static void proc_evict_inode(struct inode *inode)
66195 {
66196 struct proc_dir_entry *de;
66197@@ -55,6 +61,13 @@ static void proc_evict_inode(struct inode *inode)
66198 ns = PROC_I(inode)->ns.ns;
66199 if (ns_ops && ns)
66200 ns_ops->put(ns);
66201+
66202+#ifdef CONFIG_PROC_SYSCTL
66203+ if (inode->i_op == &proc_sys_inode_operations ||
66204+ inode->i_op == &proc_sys_dir_operations)
66205+ gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
66206+#endif
66207+
66208 }
66209
66210 static struct kmem_cache * proc_inode_cachep;
66211@@ -413,7 +426,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
66212 if (de->mode) {
66213 inode->i_mode = de->mode;
66214 inode->i_uid = de->uid;
66215+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
66216+ inode->i_gid = grsec_proc_gid;
66217+#else
66218 inode->i_gid = de->gid;
66219+#endif
66220 }
66221 if (de->size)
66222 inode->i_size = de->size;
66223diff --git a/fs/proc/internal.h b/fs/proc/internal.h
66224index aa7a0ee..f2318df 100644
66225--- a/fs/proc/internal.h
66226+++ b/fs/proc/internal.h
66227@@ -46,9 +46,10 @@ struct proc_dir_entry {
66228 struct completion *pde_unload_completion;
66229 struct list_head pde_openers; /* who did ->open, but not ->release */
66230 spinlock_t pde_unload_lock; /* proc_fops checks and pde_users bumps */
66231+ u8 restricted; /* a directory in /proc/net that should be restricted via GRKERNSEC_PROC */
66232 u8 namelen;
66233 char name[];
66234-};
66235+} __randomize_layout;
66236
66237 union proc_op {
66238 int (*proc_get_link)(struct dentry *, struct path *);
66239@@ -66,7 +67,7 @@ struct proc_inode {
66240 struct ctl_table *sysctl_entry;
66241 struct proc_ns ns;
66242 struct inode vfs_inode;
66243-};
66244+} __randomize_layout;
66245
66246 /*
66247 * General functions
66248@@ -154,6 +155,10 @@ extern int proc_pid_status(struct seq_file *, struct pid_namespace *,
66249 struct pid *, struct task_struct *);
66250 extern int proc_pid_statm(struct seq_file *, struct pid_namespace *,
66251 struct pid *, struct task_struct *);
66252+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
66253+extern int proc_pid_ipaddr(struct seq_file *, struct pid_namespace *,
66254+ struct pid *, struct task_struct *);
66255+#endif
66256
66257 /*
66258 * base.c
66259@@ -178,9 +183,11 @@ extern bool proc_fill_cache(struct file *, struct dir_context *, const char *, i
66260 * generic.c
66261 */
66262 extern struct dentry *proc_lookup(struct inode *, struct dentry *, unsigned int);
66263+extern struct dentry *proc_lookup_restrict(struct inode *, struct dentry *, unsigned int);
66264 extern struct dentry *proc_lookup_de(struct proc_dir_entry *, struct inode *,
66265 struct dentry *);
66266 extern int proc_readdir(struct file *, struct dir_context *);
66267+extern int proc_readdir_restrict(struct file *, struct dir_context *);
66268 extern int proc_readdir_de(struct proc_dir_entry *, struct file *, struct dir_context *);
66269
66270 static inline struct proc_dir_entry *pde_get(struct proc_dir_entry *pde)
66271diff --git a/fs/proc/interrupts.c b/fs/proc/interrupts.c
66272index a352d57..cb94a5c 100644
66273--- a/fs/proc/interrupts.c
66274+++ b/fs/proc/interrupts.c
66275@@ -47,7 +47,11 @@ static const struct file_operations proc_interrupts_operations = {
66276
66277 static int __init proc_interrupts_init(void)
66278 {
66279+#ifdef CONFIG_GRKERNSEC_PROC_ADD
66280+ proc_create_grsec("interrupts", 0, NULL, &proc_interrupts_operations);
66281+#else
66282 proc_create("interrupts", 0, NULL, &proc_interrupts_operations);
66283+#endif
66284 return 0;
66285 }
66286 fs_initcall(proc_interrupts_init);
66287diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
66288index 91a4e64..cb007c0 100644
66289--- a/fs/proc/kcore.c
66290+++ b/fs/proc/kcore.c
66291@@ -483,9 +483,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
66292 * the addresses in the elf_phdr on our list.
66293 */
66294 start = kc_offset_to_vaddr(*fpos - elf_buflen);
66295- if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
66296+ tsz = PAGE_SIZE - (start & ~PAGE_MASK);
66297+ if (tsz > buflen)
66298 tsz = buflen;
66299-
66300+
66301 while (buflen) {
66302 struct kcore_list *m;
66303
66304@@ -514,20 +515,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
66305 kfree(elf_buf);
66306 } else {
66307 if (kern_addr_valid(start)) {
66308- unsigned long n;
66309+ char *elf_buf;
66310+ mm_segment_t oldfs;
66311
66312- n = copy_to_user(buffer, (char *)start, tsz);
66313- /*
66314- * We cannot distinguish between fault on source
66315- * and fault on destination. When this happens
66316- * we clear too and hope it will trigger the
66317- * EFAULT again.
66318- */
66319- if (n) {
66320- if (clear_user(buffer + tsz - n,
66321- n))
66322+ elf_buf = kmalloc(tsz, GFP_KERNEL);
66323+ if (!elf_buf)
66324+ return -ENOMEM;
66325+ oldfs = get_fs();
66326+ set_fs(KERNEL_DS);
66327+ if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
66328+ set_fs(oldfs);
66329+ if (copy_to_user(buffer, elf_buf, tsz)) {
66330+ kfree(elf_buf);
66331 return -EFAULT;
66332+ }
66333 }
66334+ set_fs(oldfs);
66335+ kfree(elf_buf);
66336 } else {
66337 if (clear_user(buffer, tsz))
66338 return -EFAULT;
66339@@ -547,6 +551,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
66340
66341 static int open_kcore(struct inode *inode, struct file *filp)
66342 {
66343+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
66344+ return -EPERM;
66345+#endif
66346 if (!capable(CAP_SYS_RAWIO))
66347 return -EPERM;
66348 if (kcore_need_update)
66349diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
66350index aa1eee0..03dda72 100644
66351--- a/fs/proc/meminfo.c
66352+++ b/fs/proc/meminfo.c
66353@@ -187,7 +187,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
66354 vmi.used >> 10,
66355 vmi.largest_chunk >> 10
66356 #ifdef CONFIG_MEMORY_FAILURE
66357- ,atomic_long_read(&num_poisoned_pages) << (PAGE_SHIFT - 10)
66358+ ,atomic_long_read_unchecked(&num_poisoned_pages) << (PAGE_SHIFT - 10)
66359 #endif
66360 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
66361 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
66362diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
66363index d4a3574..b421ce9 100644
66364--- a/fs/proc/nommu.c
66365+++ b/fs/proc/nommu.c
66366@@ -64,7 +64,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
66367
66368 if (file) {
66369 seq_pad(m, ' ');
66370- seq_path(m, &file->f_path, "");
66371+ seq_path(m, &file->f_path, "\n\\");
66372 }
66373
66374 seq_putc(m, '\n');
66375diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
66376index a63af3e..b4f262a 100644
66377--- a/fs/proc/proc_net.c
66378+++ b/fs/proc/proc_net.c
66379@@ -23,9 +23,27 @@
66380 #include <linux/nsproxy.h>
66381 #include <net/net_namespace.h>
66382 #include <linux/seq_file.h>
66383+#include <linux/grsecurity.h>
66384
66385 #include "internal.h"
66386
66387+#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
66388+static struct seq_operations *ipv6_seq_ops_addr;
66389+
66390+void register_ipv6_seq_ops_addr(struct seq_operations *addr)
66391+{
66392+ ipv6_seq_ops_addr = addr;
66393+}
66394+
66395+void unregister_ipv6_seq_ops_addr(void)
66396+{
66397+ ipv6_seq_ops_addr = NULL;
66398+}
66399+
66400+EXPORT_SYMBOL_GPL(register_ipv6_seq_ops_addr);
66401+EXPORT_SYMBOL_GPL(unregister_ipv6_seq_ops_addr);
66402+#endif
66403+
66404 static inline struct net *PDE_NET(struct proc_dir_entry *pde)
66405 {
66406 return pde->parent->data;
66407@@ -36,6 +54,8 @@ static struct net *get_proc_net(const struct inode *inode)
66408 return maybe_get_net(PDE_NET(PDE(inode)));
66409 }
66410
66411+extern const struct seq_operations dev_seq_ops;
66412+
66413 int seq_open_net(struct inode *ino, struct file *f,
66414 const struct seq_operations *ops, int size)
66415 {
66416@@ -44,6 +64,14 @@ int seq_open_net(struct inode *ino, struct file *f,
66417
66418 BUG_ON(size < sizeof(*p));
66419
66420+ /* only permit access to /proc/net/dev */
66421+ if (
66422+#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
66423+ ops != ipv6_seq_ops_addr &&
66424+#endif
66425+ ops != &dev_seq_ops && gr_proc_is_restricted())
66426+ return -EACCES;
66427+
66428 net = get_proc_net(ino);
66429 if (net == NULL)
66430 return -ENXIO;
66431@@ -66,6 +94,9 @@ int single_open_net(struct inode *inode, struct file *file,
66432 int err;
66433 struct net *net;
66434
66435+ if (gr_proc_is_restricted())
66436+ return -EACCES;
66437+
66438 err = -ENXIO;
66439 net = get_proc_net(inode);
66440 if (net == NULL)
66441diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
66442index f92d5dd..26398ac 100644
66443--- a/fs/proc/proc_sysctl.c
66444+++ b/fs/proc/proc_sysctl.c
66445@@ -11,13 +11,21 @@
66446 #include <linux/namei.h>
66447 #include <linux/mm.h>
66448 #include <linux/module.h>
66449+#include <linux/nsproxy.h>
66450+#ifdef CONFIG_GRKERNSEC
66451+#include <net/net_namespace.h>
66452+#endif
66453 #include "internal.h"
66454
66455+extern int gr_handle_chroot_sysctl(const int op);
66456+extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
66457+ const int op);
66458+
66459 static const struct dentry_operations proc_sys_dentry_operations;
66460 static const struct file_operations proc_sys_file_operations;
66461-static const struct inode_operations proc_sys_inode_operations;
66462+const struct inode_operations proc_sys_inode_operations;
66463 static const struct file_operations proc_sys_dir_file_operations;
66464-static const struct inode_operations proc_sys_dir_operations;
66465+const struct inode_operations proc_sys_dir_operations;
66466
66467 void proc_sys_poll_notify(struct ctl_table_poll *poll)
66468 {
66469@@ -467,6 +475,9 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
66470
66471 err = NULL;
66472 d_set_d_op(dentry, &proc_sys_dentry_operations);
66473+
66474+ gr_handle_proc_create(dentry, inode);
66475+
66476 d_add(dentry, inode);
66477
66478 out:
66479@@ -482,6 +493,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
66480 struct inode *inode = file_inode(filp);
66481 struct ctl_table_header *head = grab_header(inode);
66482 struct ctl_table *table = PROC_I(inode)->sysctl_entry;
66483+ int op = write ? MAY_WRITE : MAY_READ;
66484 ssize_t error;
66485 size_t res;
66486
66487@@ -493,7 +505,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
66488 * and won't be until we finish.
66489 */
66490 error = -EPERM;
66491- if (sysctl_perm(head, table, write ? MAY_WRITE : MAY_READ))
66492+ if (sysctl_perm(head, table, op))
66493 goto out;
66494
66495 /* if that can happen at all, it should be -EINVAL, not -EISDIR */
66496@@ -501,6 +513,27 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
66497 if (!table->proc_handler)
66498 goto out;
66499
66500+#ifdef CONFIG_GRKERNSEC
66501+ error = -EPERM;
66502+ if (gr_handle_chroot_sysctl(op))
66503+ goto out;
66504+ dget(filp->f_path.dentry);
66505+ if (gr_handle_sysctl_mod(filp->f_path.dentry->d_parent->d_name.name, table->procname, op)) {
66506+ dput(filp->f_path.dentry);
66507+ goto out;
66508+ }
66509+ dput(filp->f_path.dentry);
66510+ if (!gr_acl_handle_open(filp->f_path.dentry, filp->f_path.mnt, op))
66511+ goto out;
66512+ if (write) {
66513+ if (current->nsproxy->net_ns != table->extra2) {
66514+ if (!capable(CAP_SYS_ADMIN))
66515+ goto out;
66516+ } else if (!ns_capable(current->nsproxy->net_ns->user_ns, CAP_NET_ADMIN))
66517+ goto out;
66518+ }
66519+#endif
66520+
66521 /* careful: calling conventions are nasty here */
66522 res = count;
66523 error = table->proc_handler(table, write, buf, &res, ppos);
66524@@ -598,6 +631,9 @@ static bool proc_sys_fill_cache(struct file *file,
66525 return false;
66526 } else {
66527 d_set_d_op(child, &proc_sys_dentry_operations);
66528+
66529+ gr_handle_proc_create(child, inode);
66530+
66531 d_add(child, inode);
66532 }
66533 } else {
66534@@ -641,6 +677,9 @@ static int scan(struct ctl_table_header *head, struct ctl_table *table,
66535 if ((*pos)++ < ctx->pos)
66536 return true;
66537
66538+ if (!gr_acl_handle_hidden_file(file->f_path.dentry, file->f_path.mnt))
66539+ return 0;
66540+
66541 if (unlikely(S_ISLNK(table->mode)))
66542 res = proc_sys_link_fill_cache(file, ctx, head, table);
66543 else
66544@@ -734,6 +773,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
66545 if (IS_ERR(head))
66546 return PTR_ERR(head);
66547
66548+ if (table && !gr_acl_handle_hidden_file(dentry, mnt))
66549+ return -ENOENT;
66550+
66551 generic_fillattr(inode, stat);
66552 if (table)
66553 stat->mode = (stat->mode & S_IFMT) | table->mode;
66554@@ -756,13 +798,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
66555 .llseek = generic_file_llseek,
66556 };
66557
66558-static const struct inode_operations proc_sys_inode_operations = {
66559+const struct inode_operations proc_sys_inode_operations = {
66560 .permission = proc_sys_permission,
66561 .setattr = proc_sys_setattr,
66562 .getattr = proc_sys_getattr,
66563 };
66564
66565-static const struct inode_operations proc_sys_dir_operations = {
66566+const struct inode_operations proc_sys_dir_operations = {
66567 .lookup = proc_sys_lookup,
66568 .permission = proc_sys_permission,
66569 .setattr = proc_sys_setattr,
66570@@ -839,7 +881,7 @@ static struct ctl_dir *find_subdir(struct ctl_dir *dir,
66571 static struct ctl_dir *new_dir(struct ctl_table_set *set,
66572 const char *name, int namelen)
66573 {
66574- struct ctl_table *table;
66575+ ctl_table_no_const *table;
66576 struct ctl_dir *new;
66577 struct ctl_node *node;
66578 char *new_name;
66579@@ -851,7 +893,7 @@ static struct ctl_dir *new_dir(struct ctl_table_set *set,
66580 return NULL;
66581
66582 node = (struct ctl_node *)(new + 1);
66583- table = (struct ctl_table *)(node + 1);
66584+ table = (ctl_table_no_const *)(node + 1);
66585 new_name = (char *)(table + 2);
66586 memcpy(new_name, name, namelen);
66587 new_name[namelen] = '\0';
66588@@ -1020,7 +1062,8 @@ static int sysctl_check_table(const char *path, struct ctl_table *table)
66589 static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table *table,
66590 struct ctl_table_root *link_root)
66591 {
66592- struct ctl_table *link_table, *entry, *link;
66593+ ctl_table_no_const *link_table, *link;
66594+ struct ctl_table *entry;
66595 struct ctl_table_header *links;
66596 struct ctl_node *node;
66597 char *link_name;
66598@@ -1043,7 +1086,7 @@ static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table
66599 return NULL;
66600
66601 node = (struct ctl_node *)(links + 1);
66602- link_table = (struct ctl_table *)(node + nr_entries);
66603+ link_table = (ctl_table_no_const *)(node + nr_entries);
66604 link_name = (char *)&link_table[nr_entries + 1];
66605
66606 for (link = link_table, entry = table; entry->procname; link++, entry++) {
66607@@ -1291,8 +1334,8 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
66608 struct ctl_table_header ***subheader, struct ctl_table_set *set,
66609 struct ctl_table *table)
66610 {
66611- struct ctl_table *ctl_table_arg = NULL;
66612- struct ctl_table *entry, *files;
66613+ ctl_table_no_const *ctl_table_arg = NULL, *files = NULL;
66614+ struct ctl_table *entry;
66615 int nr_files = 0;
66616 int nr_dirs = 0;
66617 int err = -ENOMEM;
66618@@ -1304,10 +1347,9 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
66619 nr_files++;
66620 }
66621
66622- files = table;
66623 /* If there are mixed files and directories we need a new table */
66624 if (nr_dirs && nr_files) {
66625- struct ctl_table *new;
66626+ ctl_table_no_const *new;
66627 files = kzalloc(sizeof(struct ctl_table) * (nr_files + 1),
66628 GFP_KERNEL);
66629 if (!files)
66630@@ -1325,7 +1367,7 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
66631 /* Register everything except a directory full of subdirectories */
66632 if (nr_files || !nr_dirs) {
66633 struct ctl_table_header *header;
66634- header = __register_sysctl_table(set, path, files);
66635+ header = __register_sysctl_table(set, path, files ? files : table);
66636 if (!header) {
66637 kfree(ctl_table_arg);
66638 goto out;
66639diff --git a/fs/proc/root.c b/fs/proc/root.c
66640index 094e44d..085a877 100644
66641--- a/fs/proc/root.c
66642+++ b/fs/proc/root.c
66643@@ -188,7 +188,15 @@ void __init proc_root_init(void)
66644 proc_mkdir("openprom", NULL);
66645 #endif
66646 proc_tty_init();
66647+#ifdef CONFIG_GRKERNSEC_PROC_ADD
66648+#ifdef CONFIG_GRKERNSEC_PROC_USER
66649+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
66650+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66651+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
66652+#endif
66653+#else
66654 proc_mkdir("bus", NULL);
66655+#endif
66656 proc_sys_init();
66657 }
66658
66659diff --git a/fs/proc/stat.c b/fs/proc/stat.c
66660index bf2d03f..f058f9c 100644
66661--- a/fs/proc/stat.c
66662+++ b/fs/proc/stat.c
66663@@ -11,6 +11,7 @@
66664 #include <linux/irqnr.h>
66665 #include <linux/cputime.h>
66666 #include <linux/tick.h>
66667+#include <linux/grsecurity.h>
66668
66669 #ifndef arch_irq_stat_cpu
66670 #define arch_irq_stat_cpu(cpu) 0
66671@@ -87,6 +88,18 @@ static int show_stat(struct seq_file *p, void *v)
66672 u64 sum_softirq = 0;
66673 unsigned int per_softirq_sums[NR_SOFTIRQS] = {0};
66674 struct timespec boottime;
66675+ int unrestricted = 1;
66676+
66677+#ifdef CONFIG_GRKERNSEC_PROC_ADD
66678+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66679+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)
66680+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
66681+ && !in_group_p(grsec_proc_gid)
66682+#endif
66683+ )
66684+ unrestricted = 0;
66685+#endif
66686+#endif
66687
66688 user = nice = system = idle = iowait =
66689 irq = softirq = steal = 0;
66690@@ -99,23 +112,25 @@ static int show_stat(struct seq_file *p, void *v)
66691 nice += kcpustat_cpu(i).cpustat[CPUTIME_NICE];
66692 system += kcpustat_cpu(i).cpustat[CPUTIME_SYSTEM];
66693 idle += get_idle_time(i);
66694- iowait += get_iowait_time(i);
66695- irq += kcpustat_cpu(i).cpustat[CPUTIME_IRQ];
66696- softirq += kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ];
66697- steal += kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
66698- guest += kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
66699- guest_nice += kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
66700- sum += kstat_cpu_irqs_sum(i);
66701- sum += arch_irq_stat_cpu(i);
66702+ if (unrestricted) {
66703+ iowait += get_iowait_time(i);
66704+ irq += kcpustat_cpu(i).cpustat[CPUTIME_IRQ];
66705+ softirq += kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ];
66706+ steal += kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
66707+ guest += kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
66708+ guest_nice += kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
66709+ sum += kstat_cpu_irqs_sum(i);
66710+ sum += arch_irq_stat_cpu(i);
66711+ for (j = 0; j < NR_SOFTIRQS; j++) {
66712+ unsigned int softirq_stat = kstat_softirqs_cpu(j, i);
66713
66714- for (j = 0; j < NR_SOFTIRQS; j++) {
66715- unsigned int softirq_stat = kstat_softirqs_cpu(j, i);
66716-
66717- per_softirq_sums[j] += softirq_stat;
66718- sum_softirq += softirq_stat;
66719+ per_softirq_sums[j] += softirq_stat;
66720+ sum_softirq += softirq_stat;
66721+ }
66722 }
66723 }
66724- sum += arch_irq_stat();
66725+ if (unrestricted)
66726+ sum += arch_irq_stat();
66727
66728 seq_puts(p, "cpu ");
66729 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(user));
66730@@ -136,12 +151,14 @@ static int show_stat(struct seq_file *p, void *v)
66731 nice = kcpustat_cpu(i).cpustat[CPUTIME_NICE];
66732 system = kcpustat_cpu(i).cpustat[CPUTIME_SYSTEM];
66733 idle = get_idle_time(i);
66734- iowait = get_iowait_time(i);
66735- irq = kcpustat_cpu(i).cpustat[CPUTIME_IRQ];
66736- softirq = kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ];
66737- steal = kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
66738- guest = kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
66739- guest_nice = kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
66740+ if (unrestricted) {
66741+ iowait = get_iowait_time(i);
66742+ irq = kcpustat_cpu(i).cpustat[CPUTIME_IRQ];
66743+ softirq = kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ];
66744+ steal = kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
66745+ guest = kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
66746+ guest_nice = kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
66747+ }
66748 seq_printf(p, "cpu%d", i);
66749 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(user));
66750 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(nice));
66751@@ -159,7 +176,7 @@ static int show_stat(struct seq_file *p, void *v)
66752
66753 /* sum again ? it could be updated? */
66754 for_each_irq_nr(j)
66755- seq_put_decimal_ull(p, ' ', kstat_irqs(j));
66756+ seq_put_decimal_ull(p, ' ', unrestricted ? kstat_irqs(j) : 0ULL);
66757
66758 seq_printf(p,
66759 "\nctxt %llu\n"
66760@@ -167,11 +184,11 @@ static int show_stat(struct seq_file *p, void *v)
66761 "processes %lu\n"
66762 "procs_running %lu\n"
66763 "procs_blocked %lu\n",
66764- nr_context_switches(),
66765+ unrestricted ? nr_context_switches() : 0ULL,
66766 (unsigned long)jif,
66767- total_forks,
66768- nr_running(),
66769- nr_iowait());
66770+ unrestricted ? total_forks : 0UL,
66771+ unrestricted ? nr_running() : 0UL,
66772+ unrestricted ? nr_iowait() : 0UL);
66773
66774 seq_printf(p, "softirq %llu", (unsigned long long)sum_softirq);
66775
66776diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
66777index 4e0388c..fc6a0e1 100644
66778--- a/fs/proc/task_mmu.c
66779+++ b/fs/proc/task_mmu.c
66780@@ -13,12 +13,19 @@
66781 #include <linux/swap.h>
66782 #include <linux/swapops.h>
66783 #include <linux/mmu_notifier.h>
66784+#include <linux/grsecurity.h>
66785
66786 #include <asm/elf.h>
66787 #include <asm/uaccess.h>
66788 #include <asm/tlbflush.h>
66789 #include "internal.h"
66790
66791+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66792+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
66793+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
66794+ _mm->pax_flags & MF_PAX_SEGMEXEC))
66795+#endif
66796+
66797 void task_mem(struct seq_file *m, struct mm_struct *mm)
66798 {
66799 unsigned long data, text, lib, swap;
66800@@ -54,8 +61,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
66801 "VmExe:\t%8lu kB\n"
66802 "VmLib:\t%8lu kB\n"
66803 "VmPTE:\t%8lu kB\n"
66804- "VmSwap:\t%8lu kB\n",
66805- hiwater_vm << (PAGE_SHIFT-10),
66806+ "VmSwap:\t%8lu kB\n"
66807+
66808+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
66809+ "CsBase:\t%8lx\nCsLim:\t%8lx\n"
66810+#endif
66811+
66812+ ,hiwater_vm << (PAGE_SHIFT-10),
66813 total_vm << (PAGE_SHIFT-10),
66814 mm->locked_vm << (PAGE_SHIFT-10),
66815 mm->pinned_vm << (PAGE_SHIFT-10),
66816@@ -65,7 +77,19 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
66817 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
66818 (PTRS_PER_PTE * sizeof(pte_t) *
66819 atomic_long_read(&mm->nr_ptes)) >> 10,
66820- swap << (PAGE_SHIFT-10));
66821+ swap << (PAGE_SHIFT-10)
66822+
66823+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
66824+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66825+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_base
66826+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_limit
66827+#else
66828+ , mm->context.user_cs_base
66829+ , mm->context.user_cs_limit
66830+#endif
66831+#endif
66832+
66833+ );
66834 }
66835
66836 unsigned long task_vsize(struct mm_struct *mm)
66837@@ -282,13 +306,13 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
66838 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
66839 }
66840
66841- /* We don't show the stack guard page in /proc/maps */
66842+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66843+ start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
66844+ end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
66845+#else
66846 start = vma->vm_start;
66847- if (stack_guard_page_start(vma, start))
66848- start += PAGE_SIZE;
66849 end = vma->vm_end;
66850- if (stack_guard_page_end(vma, end))
66851- end -= PAGE_SIZE;
66852+#endif
66853
66854 seq_setwidth(m, 25 + sizeof(void *) * 6 - 1);
66855 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu ",
66856@@ -298,7 +322,11 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
66857 flags & VM_WRITE ? 'w' : '-',
66858 flags & VM_EXEC ? 'x' : '-',
66859 flags & VM_MAYSHARE ? 's' : 'p',
66860+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66861+ PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
66862+#else
66863 pgoff,
66864+#endif
66865 MAJOR(dev), MINOR(dev), ino);
66866
66867 /*
66868@@ -307,7 +335,7 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
66869 */
66870 if (file) {
66871 seq_pad(m, ' ');
66872- seq_path(m, &file->f_path, "\n");
66873+ seq_path(m, &file->f_path, "\n\\");
66874 goto done;
66875 }
66876
66877@@ -338,8 +366,9 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
66878 * Thread stack in /proc/PID/task/TID/maps or
66879 * the main process stack.
66880 */
66881- if (!is_pid || (vma->vm_start <= mm->start_stack &&
66882- vma->vm_end >= mm->start_stack)) {
66883+ if (!is_pid || (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
66884+ (vma->vm_start <= mm->start_stack &&
66885+ vma->vm_end >= mm->start_stack)) {
66886 name = "[stack]";
66887 } else {
66888 /* Thread stack in /proc/PID/maps */
66889@@ -359,6 +388,12 @@ done:
66890
66891 static int show_map(struct seq_file *m, void *v, int is_pid)
66892 {
66893+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66894+ if (current->exec_id != m->exec_id) {
66895+ gr_log_badprocpid("maps");
66896+ return 0;
66897+ }
66898+#endif
66899 show_map_vma(m, v, is_pid);
66900 m_cache_vma(m, v);
66901 return 0;
66902@@ -594,12 +629,23 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
66903 .private = &mss,
66904 };
66905
66906+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66907+ if (current->exec_id != m->exec_id) {
66908+ gr_log_badprocpid("smaps");
66909+ return 0;
66910+ }
66911+#endif
66912 memset(&mss, 0, sizeof mss);
66913- mss.vma = vma;
66914- /* mmap_sem is held in m_start */
66915- if (vma->vm_mm && !is_vm_hugetlb_page(vma))
66916- walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
66917-
66918+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66919+ if (!PAX_RAND_FLAGS(vma->vm_mm)) {
66920+#endif
66921+ mss.vma = vma;
66922+ /* mmap_sem is held in m_start */
66923+ if (vma->vm_mm && !is_vm_hugetlb_page(vma))
66924+ walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
66925+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66926+ }
66927+#endif
66928 show_map_vma(m, vma, is_pid);
66929
66930 seq_printf(m,
66931@@ -617,7 +663,11 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
66932 "KernelPageSize: %8lu kB\n"
66933 "MMUPageSize: %8lu kB\n"
66934 "Locked: %8lu kB\n",
66935+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66936+ PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
66937+#else
66938 (vma->vm_end - vma->vm_start) >> 10,
66939+#endif
66940 mss.resident >> 10,
66941 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
66942 mss.shared_clean >> 10,
66943@@ -1447,6 +1497,13 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
66944 char buffer[64];
66945 int nid;
66946
66947+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66948+ if (current->exec_id != m->exec_id) {
66949+ gr_log_badprocpid("numa_maps");
66950+ return 0;
66951+ }
66952+#endif
66953+
66954 if (!mm)
66955 return 0;
66956
66957@@ -1468,11 +1525,15 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
66958 mpol_to_str(buffer, sizeof(buffer), proc_priv->task_mempolicy);
66959 }
66960
66961+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66962+ seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
66963+#else
66964 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
66965+#endif
66966
66967 if (file) {
66968 seq_puts(m, " file=");
66969- seq_path(m, &file->f_path, "\n\t= ");
66970+ seq_path(m, &file->f_path, "\n\t\\= ");
66971 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
66972 seq_puts(m, " heap");
66973 } else {
66974diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
66975index 599ec2e..f1413ae 100644
66976--- a/fs/proc/task_nommu.c
66977+++ b/fs/proc/task_nommu.c
66978@@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
66979 else
66980 bytes += kobjsize(mm);
66981
66982- if (current->fs && current->fs->users > 1)
66983+ if (current->fs && atomic_read(&current->fs->users) > 1)
66984 sbytes += kobjsize(current->fs);
66985 else
66986 bytes += kobjsize(current->fs);
66987@@ -180,7 +180,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
66988
66989 if (file) {
66990 seq_pad(m, ' ');
66991- seq_path(m, &file->f_path, "");
66992+ seq_path(m, &file->f_path, "\n\\");
66993 } else if (mm) {
66994 pid_t tid = pid_of_stack(priv, vma, is_pid);
66995
66996diff --git a/fs/proc/vmcore.c b/fs/proc/vmcore.c
66997index a90d6d35..d08047c 100644
66998--- a/fs/proc/vmcore.c
66999+++ b/fs/proc/vmcore.c
67000@@ -105,9 +105,13 @@ static ssize_t read_from_oldmem(char *buf, size_t count,
67001 nr_bytes = count;
67002
67003 /* If pfn is not ram, return zeros for sparse dump files */
67004- if (pfn_is_ram(pfn) == 0)
67005- memset(buf, 0, nr_bytes);
67006- else {
67007+ if (pfn_is_ram(pfn) == 0) {
67008+ if (userbuf) {
67009+ if (clear_user((char __force_user *)buf, nr_bytes))
67010+ return -EFAULT;
67011+ } else
67012+ memset(buf, 0, nr_bytes);
67013+ } else {
67014 tmp = copy_oldmem_page(pfn, buf, nr_bytes,
67015 offset, userbuf);
67016 if (tmp < 0)
67017@@ -170,7 +174,7 @@ int __weak remap_oldmem_pfn_range(struct vm_area_struct *vma,
67018 static int copy_to(void *target, void *src, size_t size, int userbuf)
67019 {
67020 if (userbuf) {
67021- if (copy_to_user((char __user *) target, src, size))
67022+ if (copy_to_user((char __force_user *) target, src, size))
67023 return -EFAULT;
67024 } else {
67025 memcpy(target, src, size);
67026@@ -233,7 +237,7 @@ static ssize_t __read_vmcore(char *buffer, size_t buflen, loff_t *fpos,
67027 if (*fpos < m->offset + m->size) {
67028 tsz = min_t(size_t, m->offset + m->size - *fpos, buflen);
67029 start = m->paddr + *fpos - m->offset;
67030- tmp = read_from_oldmem(buffer, tsz, &start, userbuf);
67031+ tmp = read_from_oldmem((char __force_kernel *)buffer, tsz, &start, userbuf);
67032 if (tmp < 0)
67033 return tmp;
67034 buflen -= tsz;
67035@@ -253,7 +257,7 @@ static ssize_t __read_vmcore(char *buffer, size_t buflen, loff_t *fpos,
67036 static ssize_t read_vmcore(struct file *file, char __user *buffer,
67037 size_t buflen, loff_t *fpos)
67038 {
67039- return __read_vmcore((__force char *) buffer, buflen, fpos, 1);
67040+ return __read_vmcore((__force_kernel char *) buffer, buflen, fpos, 1);
67041 }
67042
67043 /*
67044diff --git a/fs/qnx6/qnx6.h b/fs/qnx6/qnx6.h
67045index d3fb2b6..43a8140 100644
67046--- a/fs/qnx6/qnx6.h
67047+++ b/fs/qnx6/qnx6.h
67048@@ -74,7 +74,7 @@ enum {
67049 BYTESEX_BE,
67050 };
67051
67052-static inline __u64 fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
67053+static inline __u64 __intentional_overflow(-1) fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
67054 {
67055 if (sbi->s_bytesex == BYTESEX_LE)
67056 return le64_to_cpu((__force __le64)n);
67057@@ -90,7 +90,7 @@ static inline __fs64 cpu_to_fs64(struct qnx6_sb_info *sbi, __u64 n)
67058 return (__force __fs64)cpu_to_be64(n);
67059 }
67060
67061-static inline __u32 fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
67062+static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
67063 {
67064 if (sbi->s_bytesex == BYTESEX_LE)
67065 return le32_to_cpu((__force __le32)n);
67066diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
67067index bb2869f..d34ada8 100644
67068--- a/fs/quota/netlink.c
67069+++ b/fs/quota/netlink.c
67070@@ -44,7 +44,7 @@ static struct genl_family quota_genl_family = {
67071 void quota_send_warning(struct kqid qid, dev_t dev,
67072 const char warntype)
67073 {
67074- static atomic_t seq;
67075+ static atomic_unchecked_t seq;
67076 struct sk_buff *skb;
67077 void *msg_head;
67078 int ret;
67079@@ -60,7 +60,7 @@ void quota_send_warning(struct kqid qid, dev_t dev,
67080 "VFS: Not enough memory to send quota warning.\n");
67081 return;
67082 }
67083- msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
67084+ msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
67085 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
67086 if (!msg_head) {
67087 printk(KERN_ERR
67088diff --git a/fs/read_write.c b/fs/read_write.c
67089index 7d9318c..51b336f 100644
67090--- a/fs/read_write.c
67091+++ b/fs/read_write.c
67092@@ -495,7 +495,7 @@ ssize_t __kernel_write(struct file *file, const char *buf, size_t count, loff_t
67093
67094 old_fs = get_fs();
67095 set_fs(get_ds());
67096- p = (__force const char __user *)buf;
67097+ p = (const char __force_user *)buf;
67098 if (count > MAX_RW_COUNT)
67099 count = MAX_RW_COUNT;
67100 if (file->f_op->write)
67101diff --git a/fs/readdir.c b/fs/readdir.c
67102index 33fd922..e0d6094 100644
67103--- a/fs/readdir.c
67104+++ b/fs/readdir.c
67105@@ -18,6 +18,7 @@
67106 #include <linux/security.h>
67107 #include <linux/syscalls.h>
67108 #include <linux/unistd.h>
67109+#include <linux/namei.h>
67110
67111 #include <asm/uaccess.h>
67112
67113@@ -71,6 +72,7 @@ struct old_linux_dirent {
67114 struct readdir_callback {
67115 struct dir_context ctx;
67116 struct old_linux_dirent __user * dirent;
67117+ struct file * file;
67118 int result;
67119 };
67120
67121@@ -88,6 +90,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
67122 buf->result = -EOVERFLOW;
67123 return -EOVERFLOW;
67124 }
67125+
67126+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
67127+ return 0;
67128+
67129 buf->result++;
67130 dirent = buf->dirent;
67131 if (!access_ok(VERIFY_WRITE, dirent,
67132@@ -119,6 +125,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
67133 if (!f.file)
67134 return -EBADF;
67135
67136+ buf.file = f.file;
67137 error = iterate_dir(f.file, &buf.ctx);
67138 if (buf.result)
67139 error = buf.result;
67140@@ -144,6 +151,7 @@ struct getdents_callback {
67141 struct dir_context ctx;
67142 struct linux_dirent __user * current_dir;
67143 struct linux_dirent __user * previous;
67144+ struct file * file;
67145 int count;
67146 int error;
67147 };
67148@@ -165,6 +173,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
67149 buf->error = -EOVERFLOW;
67150 return -EOVERFLOW;
67151 }
67152+
67153+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
67154+ return 0;
67155+
67156 dirent = buf->previous;
67157 if (dirent) {
67158 if (__put_user(offset, &dirent->d_off))
67159@@ -210,6 +222,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
67160 if (!f.file)
67161 return -EBADF;
67162
67163+ buf.file = f.file;
67164 error = iterate_dir(f.file, &buf.ctx);
67165 if (error >= 0)
67166 error = buf.error;
67167@@ -228,6 +241,7 @@ struct getdents_callback64 {
67168 struct dir_context ctx;
67169 struct linux_dirent64 __user * current_dir;
67170 struct linux_dirent64 __user * previous;
67171+ struct file *file;
67172 int count;
67173 int error;
67174 };
67175@@ -243,6 +257,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
67176 buf->error = -EINVAL; /* only used if we fail.. */
67177 if (reclen > buf->count)
67178 return -EINVAL;
67179+
67180+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
67181+ return 0;
67182+
67183 dirent = buf->previous;
67184 if (dirent) {
67185 if (__put_user(offset, &dirent->d_off))
67186@@ -290,6 +308,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
67187 if (!f.file)
67188 return -EBADF;
67189
67190+ buf.file = f.file;
67191 error = iterate_dir(f.file, &buf.ctx);
67192 if (error >= 0)
67193 error = buf.error;
67194diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
67195index 9c02d96..6562c10 100644
67196--- a/fs/reiserfs/do_balan.c
67197+++ b/fs/reiserfs/do_balan.c
67198@@ -1887,7 +1887,7 @@ void do_balance(struct tree_balance *tb, struct item_head *ih,
67199 return;
67200 }
67201
67202- atomic_inc(&fs_generation(tb->tb_sb));
67203+ atomic_inc_unchecked(&fs_generation(tb->tb_sb));
67204 do_balance_starts(tb);
67205
67206 /*
67207diff --git a/fs/reiserfs/item_ops.c b/fs/reiserfs/item_ops.c
67208index aca73dd..e3c558d 100644
67209--- a/fs/reiserfs/item_ops.c
67210+++ b/fs/reiserfs/item_ops.c
67211@@ -724,18 +724,18 @@ static void errcatch_print_vi(struct virtual_item *vi)
67212 }
67213
67214 static struct item_operations errcatch_ops = {
67215- errcatch_bytes_number,
67216- errcatch_decrement_key,
67217- errcatch_is_left_mergeable,
67218- errcatch_print_item,
67219- errcatch_check_item,
67220+ .bytes_number = errcatch_bytes_number,
67221+ .decrement_key = errcatch_decrement_key,
67222+ .is_left_mergeable = errcatch_is_left_mergeable,
67223+ .print_item = errcatch_print_item,
67224+ .check_item = errcatch_check_item,
67225
67226- errcatch_create_vi,
67227- errcatch_check_left,
67228- errcatch_check_right,
67229- errcatch_part_size,
67230- errcatch_unit_num,
67231- errcatch_print_vi
67232+ .create_vi = errcatch_create_vi,
67233+ .check_left = errcatch_check_left,
67234+ .check_right = errcatch_check_right,
67235+ .part_size = errcatch_part_size,
67236+ .unit_num = errcatch_unit_num,
67237+ .print_vi = errcatch_print_vi
67238 };
67239
67240 #if ! (TYPE_STAT_DATA == 0 && TYPE_INDIRECT == 1 && TYPE_DIRECT == 2 && TYPE_DIRENTRY == 3)
67241diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
67242index 621b9f3..af527fd 100644
67243--- a/fs/reiserfs/procfs.c
67244+++ b/fs/reiserfs/procfs.c
67245@@ -114,7 +114,7 @@ static int show_super(struct seq_file *m, void *unused)
67246 "SMALL_TAILS " : "NO_TAILS ",
67247 replay_only(sb) ? "REPLAY_ONLY " : "",
67248 convert_reiserfs(sb) ? "CONV " : "",
67249- atomic_read(&r->s_generation_counter),
67250+ atomic_read_unchecked(&r->s_generation_counter),
67251 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
67252 SF(s_do_balance), SF(s_unneeded_left_neighbor),
67253 SF(s_good_search_by_key_reada), SF(s_bmaps),
67254diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h
67255index 1894d96..1dfd1c2 100644
67256--- a/fs/reiserfs/reiserfs.h
67257+++ b/fs/reiserfs/reiserfs.h
67258@@ -576,7 +576,7 @@ struct reiserfs_sb_info {
67259 /* Comment? -Hans */
67260 wait_queue_head_t s_wait;
67261 /* increased by one every time the tree gets re-balanced */
67262- atomic_t s_generation_counter;
67263+ atomic_unchecked_t s_generation_counter;
67264
67265 /* File system properties. Currently holds on-disk FS format */
67266 unsigned long s_properties;
67267@@ -2297,7 +2297,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
67268 #define REISERFS_USER_MEM 1 /* user memory mode */
67269
67270 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
67271-#define get_generation(s) atomic_read (&fs_generation(s))
67272+#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
67273 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
67274 #define __fs_changed(gen,s) (gen != get_generation (s))
67275 #define fs_changed(gen,s) \
67276diff --git a/fs/reiserfs/super.c b/fs/reiserfs/super.c
67277index b27ef35..d9c6c18 100644
67278--- a/fs/reiserfs/super.c
67279+++ b/fs/reiserfs/super.c
67280@@ -1857,6 +1857,10 @@ static int reiserfs_fill_super(struct super_block *s, void *data, int silent)
67281 sbi->s_mount_opt |= (1 << REISERFS_SMALLTAIL);
67282 sbi->s_mount_opt |= (1 << REISERFS_ERROR_RO);
67283 sbi->s_mount_opt |= (1 << REISERFS_BARRIER_FLUSH);
67284+#ifdef CONFIG_REISERFS_FS_XATTR
67285+ /* turn on user xattrs by default */
67286+ sbi->s_mount_opt |= (1 << REISERFS_XATTRS_USER);
67287+#endif
67288 /* no preallocation minimum, be smart in reiserfs_file_write instead */
67289 sbi->s_alloc_options.preallocmin = 0;
67290 /* Preallocate by 16 blocks (17-1) at once */
67291diff --git a/fs/select.c b/fs/select.c
67292index 467bb1c..cf9d65a 100644
67293--- a/fs/select.c
67294+++ b/fs/select.c
67295@@ -20,6 +20,7 @@
67296 #include <linux/export.h>
67297 #include <linux/slab.h>
67298 #include <linux/poll.h>
67299+#include <linux/security.h>
67300 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
67301 #include <linux/file.h>
67302 #include <linux/fdtable.h>
67303@@ -880,6 +881,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
67304 struct poll_list *walk = head;
67305 unsigned long todo = nfds;
67306
67307+ gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
67308 if (nfds > rlimit(RLIMIT_NOFILE))
67309 return -EINVAL;
67310
67311diff --git a/fs/seq_file.c b/fs/seq_file.c
67312index 3857b72..0b7281e 100644
67313--- a/fs/seq_file.c
67314+++ b/fs/seq_file.c
67315@@ -12,6 +12,8 @@
67316 #include <linux/slab.h>
67317 #include <linux/cred.h>
67318 #include <linux/mm.h>
67319+#include <linux/sched.h>
67320+#include <linux/grsecurity.h>
67321
67322 #include <asm/uaccess.h>
67323 #include <asm/page.h>
67324@@ -34,12 +36,7 @@ static void seq_set_overflow(struct seq_file *m)
67325
67326 static void *seq_buf_alloc(unsigned long size)
67327 {
67328- void *buf;
67329-
67330- buf = kmalloc(size, GFP_KERNEL | __GFP_NOWARN);
67331- if (!buf && size > PAGE_SIZE)
67332- buf = vmalloc(size);
67333- return buf;
67334+ return kmalloc(size, GFP_KERNEL | GFP_USERCOPY);
67335 }
67336
67337 /**
67338@@ -72,6 +69,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
67339 #ifdef CONFIG_USER_NS
67340 p->user_ns = file->f_cred->user_ns;
67341 #endif
67342+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67343+ p->exec_id = current->exec_id;
67344+#endif
67345
67346 /*
67347 * Wrappers around seq_open(e.g. swaps_open) need to be
67348@@ -94,6 +94,16 @@ int seq_open(struct file *file, const struct seq_operations *op)
67349 }
67350 EXPORT_SYMBOL(seq_open);
67351
67352+
67353+int seq_open_restrict(struct file *file, const struct seq_operations *op)
67354+{
67355+ if (gr_proc_is_restricted())
67356+ return -EACCES;
67357+
67358+ return seq_open(file, op);
67359+}
67360+EXPORT_SYMBOL(seq_open_restrict);
67361+
67362 static int traverse(struct seq_file *m, loff_t offset)
67363 {
67364 loff_t pos = 0, index;
67365@@ -165,7 +175,7 @@ Eoverflow:
67366 ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
67367 {
67368 struct seq_file *m = file->private_data;
67369- size_t copied = 0;
67370+ ssize_t copied = 0;
67371 loff_t pos;
67372 size_t n;
67373 void *p;
67374@@ -596,7 +606,7 @@ static void single_stop(struct seq_file *p, void *v)
67375 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
67376 void *data)
67377 {
67378- struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
67379+ seq_operations_no_const *op = kzalloc(sizeof(*op), GFP_KERNEL);
67380 int res = -ENOMEM;
67381
67382 if (op) {
67383@@ -632,6 +642,17 @@ int single_open_size(struct file *file, int (*show)(struct seq_file *, void *),
67384 }
67385 EXPORT_SYMBOL(single_open_size);
67386
67387+int single_open_restrict(struct file *file, int (*show)(struct seq_file *, void *),
67388+ void *data)
67389+{
67390+ if (gr_proc_is_restricted())
67391+ return -EACCES;
67392+
67393+ return single_open(file, show, data);
67394+}
67395+EXPORT_SYMBOL(single_open_restrict);
67396+
67397+
67398 int single_release(struct inode *inode, struct file *file)
67399 {
67400 const struct seq_operations *op = ((struct seq_file *)file->private_data)->op;
67401diff --git a/fs/splice.c b/fs/splice.c
67402index 75c6058..770d40c 100644
67403--- a/fs/splice.c
67404+++ b/fs/splice.c
67405@@ -193,7 +193,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
67406 pipe_lock(pipe);
67407
67408 for (;;) {
67409- if (!pipe->readers) {
67410+ if (!atomic_read(&pipe->readers)) {
67411 send_sig(SIGPIPE, current, 0);
67412 if (!ret)
67413 ret = -EPIPE;
67414@@ -216,7 +216,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
67415 page_nr++;
67416 ret += buf->len;
67417
67418- if (pipe->files)
67419+ if (atomic_read(&pipe->files))
67420 do_wakeup = 1;
67421
67422 if (!--spd->nr_pages)
67423@@ -247,9 +247,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
67424 do_wakeup = 0;
67425 }
67426
67427- pipe->waiting_writers++;
67428+ atomic_inc(&pipe->waiting_writers);
67429 pipe_wait(pipe);
67430- pipe->waiting_writers--;
67431+ atomic_dec(&pipe->waiting_writers);
67432 }
67433
67434 pipe_unlock(pipe);
67435@@ -576,7 +576,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
67436 old_fs = get_fs();
67437 set_fs(get_ds());
67438 /* The cast to a user pointer is valid due to the set_fs() */
67439- res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
67440+ res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
67441 set_fs(old_fs);
67442
67443 return res;
67444@@ -591,7 +591,7 @@ ssize_t kernel_write(struct file *file, const char *buf, size_t count,
67445 old_fs = get_fs();
67446 set_fs(get_ds());
67447 /* The cast to a user pointer is valid due to the set_fs() */
67448- res = vfs_write(file, (__force const char __user *)buf, count, &pos);
67449+ res = vfs_write(file, (const char __force_user *)buf, count, &pos);
67450 set_fs(old_fs);
67451
67452 return res;
67453@@ -644,7 +644,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
67454 goto err;
67455
67456 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
67457- vec[i].iov_base = (void __user *) page_address(page);
67458+ vec[i].iov_base = (void __force_user *) page_address(page);
67459 vec[i].iov_len = this_len;
67460 spd.pages[i] = page;
67461 spd.nr_pages++;
67462@@ -783,7 +783,7 @@ static int splice_from_pipe_feed(struct pipe_inode_info *pipe, struct splice_des
67463 ops->release(pipe, buf);
67464 pipe->curbuf = (pipe->curbuf + 1) & (pipe->buffers - 1);
67465 pipe->nrbufs--;
67466- if (pipe->files)
67467+ if (atomic_read(&pipe->files))
67468 sd->need_wakeup = true;
67469 }
67470
67471@@ -807,10 +807,10 @@ static int splice_from_pipe_feed(struct pipe_inode_info *pipe, struct splice_des
67472 static int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
67473 {
67474 while (!pipe->nrbufs) {
67475- if (!pipe->writers)
67476+ if (!atomic_read(&pipe->writers))
67477 return 0;
67478
67479- if (!pipe->waiting_writers && sd->num_spliced)
67480+ if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
67481 return 0;
67482
67483 if (sd->flags & SPLICE_F_NONBLOCK)
67484@@ -1040,7 +1040,7 @@ iter_file_splice_write(struct pipe_inode_info *pipe, struct file *out,
67485 ops->release(pipe, buf);
67486 pipe->curbuf = (pipe->curbuf + 1) & (pipe->buffers - 1);
67487 pipe->nrbufs--;
67488- if (pipe->files)
67489+ if (atomic_read(&pipe->files))
67490 sd.need_wakeup = true;
67491 } else {
67492 buf->offset += ret;
67493@@ -1200,7 +1200,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
67494 * out of the pipe right after the splice_to_pipe(). So set
67495 * PIPE_READERS appropriately.
67496 */
67497- pipe->readers = 1;
67498+ atomic_set(&pipe->readers, 1);
67499
67500 current->splice_pipe = pipe;
67501 }
67502@@ -1497,6 +1497,7 @@ static int get_iovec_page_array(const struct iovec __user *iov,
67503
67504 partial[buffers].offset = off;
67505 partial[buffers].len = plen;
67506+ partial[buffers].private = 0;
67507
67508 off = 0;
67509 len -= plen;
67510@@ -1733,9 +1734,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
67511 ret = -ERESTARTSYS;
67512 break;
67513 }
67514- if (!pipe->writers)
67515+ if (!atomic_read(&pipe->writers))
67516 break;
67517- if (!pipe->waiting_writers) {
67518+ if (!atomic_read(&pipe->waiting_writers)) {
67519 if (flags & SPLICE_F_NONBLOCK) {
67520 ret = -EAGAIN;
67521 break;
67522@@ -1767,7 +1768,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
67523 pipe_lock(pipe);
67524
67525 while (pipe->nrbufs >= pipe->buffers) {
67526- if (!pipe->readers) {
67527+ if (!atomic_read(&pipe->readers)) {
67528 send_sig(SIGPIPE, current, 0);
67529 ret = -EPIPE;
67530 break;
67531@@ -1780,9 +1781,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
67532 ret = -ERESTARTSYS;
67533 break;
67534 }
67535- pipe->waiting_writers++;
67536+ atomic_inc(&pipe->waiting_writers);
67537 pipe_wait(pipe);
67538- pipe->waiting_writers--;
67539+ atomic_dec(&pipe->waiting_writers);
67540 }
67541
67542 pipe_unlock(pipe);
67543@@ -1818,14 +1819,14 @@ retry:
67544 pipe_double_lock(ipipe, opipe);
67545
67546 do {
67547- if (!opipe->readers) {
67548+ if (!atomic_read(&opipe->readers)) {
67549 send_sig(SIGPIPE, current, 0);
67550 if (!ret)
67551 ret = -EPIPE;
67552 break;
67553 }
67554
67555- if (!ipipe->nrbufs && !ipipe->writers)
67556+ if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
67557 break;
67558
67559 /*
67560@@ -1922,7 +1923,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
67561 pipe_double_lock(ipipe, opipe);
67562
67563 do {
67564- if (!opipe->readers) {
67565+ if (!atomic_read(&opipe->readers)) {
67566 send_sig(SIGPIPE, current, 0);
67567 if (!ret)
67568 ret = -EPIPE;
67569@@ -1967,7 +1968,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
67570 * return EAGAIN if we have the potential of some data in the
67571 * future, otherwise just return 0
67572 */
67573- if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
67574+ if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
67575 ret = -EAGAIN;
67576
67577 pipe_unlock(ipipe);
67578diff --git a/fs/stat.c b/fs/stat.c
67579index ae0c3ce..9ee641c 100644
67580--- a/fs/stat.c
67581+++ b/fs/stat.c
67582@@ -28,8 +28,13 @@ void generic_fillattr(struct inode *inode, struct kstat *stat)
67583 stat->gid = inode->i_gid;
67584 stat->rdev = inode->i_rdev;
67585 stat->size = i_size_read(inode);
67586- stat->atime = inode->i_atime;
67587- stat->mtime = inode->i_mtime;
67588+ if (is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
67589+ stat->atime = inode->i_ctime;
67590+ stat->mtime = inode->i_ctime;
67591+ } else {
67592+ stat->atime = inode->i_atime;
67593+ stat->mtime = inode->i_mtime;
67594+ }
67595 stat->ctime = inode->i_ctime;
67596 stat->blksize = (1 << inode->i_blkbits);
67597 stat->blocks = inode->i_blocks;
67598@@ -52,9 +57,16 @@ EXPORT_SYMBOL(generic_fillattr);
67599 int vfs_getattr_nosec(struct path *path, struct kstat *stat)
67600 {
67601 struct inode *inode = path->dentry->d_inode;
67602+ int retval;
67603
67604- if (inode->i_op->getattr)
67605- return inode->i_op->getattr(path->mnt, path->dentry, stat);
67606+ if (inode->i_op->getattr) {
67607+ retval = inode->i_op->getattr(path->mnt, path->dentry, stat);
67608+ if (!retval && is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
67609+ stat->atime = stat->ctime;
67610+ stat->mtime = stat->ctime;
67611+ }
67612+ return retval;
67613+ }
67614
67615 generic_fillattr(inode, stat);
67616 return 0;
67617diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
67618index 0b45ff4..847de5b 100644
67619--- a/fs/sysfs/dir.c
67620+++ b/fs/sysfs/dir.c
67621@@ -41,9 +41,16 @@ void sysfs_warn_dup(struct kernfs_node *parent, const char *name)
67622 int sysfs_create_dir_ns(struct kobject *kobj, const void *ns)
67623 {
67624 struct kernfs_node *parent, *kn;
67625+ const char *name;
67626+ umode_t mode = S_IRWXU | S_IRUGO | S_IXUGO;
67627+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
67628+ const char *parent_name;
67629+#endif
67630
67631 BUG_ON(!kobj);
67632
67633+ name = kobject_name(kobj);
67634+
67635 if (kobj->parent)
67636 parent = kobj->parent->sd;
67637 else
67638@@ -52,11 +59,22 @@ int sysfs_create_dir_ns(struct kobject *kobj, const void *ns)
67639 if (!parent)
67640 return -ENOENT;
67641
67642- kn = kernfs_create_dir_ns(parent, kobject_name(kobj),
67643- S_IRWXU | S_IRUGO | S_IXUGO, kobj, ns);
67644+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
67645+ parent_name = parent->name;
67646+ mode = S_IRWXU;
67647+
67648+ if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
67649+ (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
67650+ (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse") || !strcmp(name, "ecryptfs"))) ||
67651+ (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
67652+ mode = S_IRWXU | S_IRUGO | S_IXUGO;
67653+#endif
67654+
67655+ kn = kernfs_create_dir_ns(parent, name,
67656+ mode, kobj, ns);
67657 if (IS_ERR(kn)) {
67658 if (PTR_ERR(kn) == -EEXIST)
67659- sysfs_warn_dup(parent, kobject_name(kobj));
67660+ sysfs_warn_dup(parent, name);
67661 return PTR_ERR(kn);
67662 }
67663
67664diff --git a/fs/sysv/sysv.h b/fs/sysv/sysv.h
67665index 69d4889..a810bd4 100644
67666--- a/fs/sysv/sysv.h
67667+++ b/fs/sysv/sysv.h
67668@@ -188,7 +188,7 @@ static inline u32 PDP_swab(u32 x)
67669 #endif
67670 }
67671
67672-static inline __u32 fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
67673+static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
67674 {
67675 if (sbi->s_bytesex == BYTESEX_PDP)
67676 return PDP_swab((__force __u32)n);
67677diff --git a/fs/ubifs/io.c b/fs/ubifs/io.c
67678index fb08b0c..65fcc7e 100644
67679--- a/fs/ubifs/io.c
67680+++ b/fs/ubifs/io.c
67681@@ -155,7 +155,7 @@ int ubifs_leb_change(struct ubifs_info *c, int lnum, const void *buf, int len)
67682 return err;
67683 }
67684
67685-int ubifs_leb_unmap(struct ubifs_info *c, int lnum)
67686+int __intentional_overflow(-1) ubifs_leb_unmap(struct ubifs_info *c, int lnum)
67687 {
67688 int err;
67689
67690diff --git a/fs/udf/misc.c b/fs/udf/misc.c
67691index c175b4d..8f36a16 100644
67692--- a/fs/udf/misc.c
67693+++ b/fs/udf/misc.c
67694@@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
67695
67696 u8 udf_tag_checksum(const struct tag *t)
67697 {
67698- u8 *data = (u8 *)t;
67699+ const u8 *data = (const u8 *)t;
67700 u8 checksum = 0;
67701 int i;
67702 for (i = 0; i < sizeof(struct tag); ++i)
67703diff --git a/fs/ufs/swab.h b/fs/ufs/swab.h
67704index 8d974c4..b82f6ec 100644
67705--- a/fs/ufs/swab.h
67706+++ b/fs/ufs/swab.h
67707@@ -22,7 +22,7 @@ enum {
67708 BYTESEX_BE
67709 };
67710
67711-static inline u64
67712+static inline u64 __intentional_overflow(-1)
67713 fs64_to_cpu(struct super_block *sbp, __fs64 n)
67714 {
67715 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
67716@@ -40,7 +40,7 @@ cpu_to_fs64(struct super_block *sbp, u64 n)
67717 return (__force __fs64)cpu_to_be64(n);
67718 }
67719
67720-static inline u32
67721+static inline u32 __intentional_overflow(-1)
67722 fs32_to_cpu(struct super_block *sbp, __fs32 n)
67723 {
67724 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
67725diff --git a/fs/utimes.c b/fs/utimes.c
67726index aa138d6..5f3a811 100644
67727--- a/fs/utimes.c
67728+++ b/fs/utimes.c
67729@@ -1,6 +1,7 @@
67730 #include <linux/compiler.h>
67731 #include <linux/file.h>
67732 #include <linux/fs.h>
67733+#include <linux/security.h>
67734 #include <linux/linkage.h>
67735 #include <linux/mount.h>
67736 #include <linux/namei.h>
67737@@ -103,6 +104,12 @@ static int utimes_common(struct path *path, struct timespec *times)
67738 }
67739 }
67740 retry_deleg:
67741+
67742+ if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
67743+ error = -EACCES;
67744+ goto mnt_drop_write_and_out;
67745+ }
67746+
67747 mutex_lock(&inode->i_mutex);
67748 error = notify_change(path->dentry, &newattrs, &delegated_inode);
67749 mutex_unlock(&inode->i_mutex);
67750diff --git a/fs/xattr.c b/fs/xattr.c
67751index 64e83ef..b6be154 100644
67752--- a/fs/xattr.c
67753+++ b/fs/xattr.c
67754@@ -227,6 +227,27 @@ int vfs_xattr_cmp(struct dentry *dentry, const char *xattr_name,
67755 return rc;
67756 }
67757
67758+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
67759+ssize_t
67760+pax_getxattr(struct dentry *dentry, void *value, size_t size)
67761+{
67762+ struct inode *inode = dentry->d_inode;
67763+ ssize_t error;
67764+
67765+ error = inode_permission(inode, MAY_EXEC);
67766+ if (error)
67767+ return error;
67768+
67769+ if (inode->i_op->getxattr)
67770+ error = inode->i_op->getxattr(dentry, XATTR_NAME_PAX_FLAGS, value, size);
67771+ else
67772+ error = -EOPNOTSUPP;
67773+
67774+ return error;
67775+}
67776+EXPORT_SYMBOL(pax_getxattr);
67777+#endif
67778+
67779 ssize_t
67780 vfs_getxattr(struct dentry *dentry, const char *name, void *value, size_t size)
67781 {
67782@@ -319,7 +340,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
67783 * Extended attribute SET operations
67784 */
67785 static long
67786-setxattr(struct dentry *d, const char __user *name, const void __user *value,
67787+setxattr(struct path *path, const char __user *name, const void __user *value,
67788 size_t size, int flags)
67789 {
67790 int error;
67791@@ -355,7 +376,12 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
67792 posix_acl_fix_xattr_from_user(kvalue, size);
67793 }
67794
67795- error = vfs_setxattr(d, kname, kvalue, size, flags);
67796+ if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
67797+ error = -EACCES;
67798+ goto out;
67799+ }
67800+
67801+ error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
67802 out:
67803 if (vvalue)
67804 vfree(vvalue);
67805@@ -376,7 +402,7 @@ retry:
67806 return error;
67807 error = mnt_want_write(path.mnt);
67808 if (!error) {
67809- error = setxattr(path.dentry, name, value, size, flags);
67810+ error = setxattr(&path, name, value, size, flags);
67811 mnt_drop_write(path.mnt);
67812 }
67813 path_put(&path);
67814@@ -405,16 +431,14 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
67815 const void __user *,value, size_t, size, int, flags)
67816 {
67817 struct fd f = fdget(fd);
67818- struct dentry *dentry;
67819 int error = -EBADF;
67820
67821 if (!f.file)
67822 return error;
67823- dentry = f.file->f_path.dentry;
67824- audit_inode(NULL, dentry, 0);
67825+ audit_inode(NULL, f.file->f_path.dentry, 0);
67826 error = mnt_want_write_file(f.file);
67827 if (!error) {
67828- error = setxattr(dentry, name, value, size, flags);
67829+ error = setxattr(&f.file->f_path, name, value, size, flags);
67830 mnt_drop_write_file(f.file);
67831 }
67832 fdput(f);
67833@@ -600,7 +624,7 @@ SYSCALL_DEFINE3(flistxattr, int, fd, char __user *, list, size_t, size)
67834 * Extended attribute REMOVE operations
67835 */
67836 static long
67837-removexattr(struct dentry *d, const char __user *name)
67838+removexattr(struct path *path, const char __user *name)
67839 {
67840 int error;
67841 char kname[XATTR_NAME_MAX + 1];
67842@@ -611,7 +635,10 @@ removexattr(struct dentry *d, const char __user *name)
67843 if (error < 0)
67844 return error;
67845
67846- return vfs_removexattr(d, kname);
67847+ if (!gr_acl_handle_removexattr(path->dentry, path->mnt))
67848+ return -EACCES;
67849+
67850+ return vfs_removexattr(path->dentry, kname);
67851 }
67852
67853 static int path_removexattr(const char __user *pathname,
67854@@ -625,7 +652,7 @@ retry:
67855 return error;
67856 error = mnt_want_write(path.mnt);
67857 if (!error) {
67858- error = removexattr(path.dentry, name);
67859+ error = removexattr(&path, name);
67860 mnt_drop_write(path.mnt);
67861 }
67862 path_put(&path);
67863@@ -651,16 +678,16 @@ SYSCALL_DEFINE2(lremovexattr, const char __user *, pathname,
67864 SYSCALL_DEFINE2(fremovexattr, int, fd, const char __user *, name)
67865 {
67866 struct fd f = fdget(fd);
67867- struct dentry *dentry;
67868+ struct path *path;
67869 int error = -EBADF;
67870
67871 if (!f.file)
67872 return error;
67873- dentry = f.file->f_path.dentry;
67874- audit_inode(NULL, dentry, 0);
67875+ path = &f.file->f_path;
67876+ audit_inode(NULL, path->dentry, 0);
67877 error = mnt_want_write_file(f.file);
67878 if (!error) {
67879- error = removexattr(dentry, name);
67880+ error = removexattr(path, name);
67881 mnt_drop_write_file(f.file);
67882 }
67883 fdput(f);
67884diff --git a/fs/xfs/libxfs/xfs_bmap.c b/fs/xfs/libxfs/xfs_bmap.c
67885index 79c9819..22226b4 100644
67886--- a/fs/xfs/libxfs/xfs_bmap.c
67887+++ b/fs/xfs/libxfs/xfs_bmap.c
67888@@ -583,7 +583,7 @@ xfs_bmap_validate_ret(
67889
67890 #else
67891 #define xfs_bmap_check_leaf_extents(cur, ip, whichfork) do { } while (0)
67892-#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
67893+#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do { } while (0)
67894 #endif /* DEBUG */
67895
67896 /*
67897diff --git a/fs/xfs/xfs_dir2_readdir.c b/fs/xfs/xfs_dir2_readdir.c
67898index f1b69ed..3d0222f 100644
67899--- a/fs/xfs/xfs_dir2_readdir.c
67900+++ b/fs/xfs/xfs_dir2_readdir.c
67901@@ -159,7 +159,12 @@ xfs_dir2_sf_getdents(
67902 ino = dp->d_ops->sf_get_ino(sfp, sfep);
67903 filetype = dp->d_ops->sf_get_ftype(sfep);
67904 ctx->pos = off & 0x7fffffff;
67905- if (!dir_emit(ctx, (char *)sfep->name, sfep->namelen, ino,
67906+ if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
67907+ char name[sfep->namelen];
67908+ memcpy(name, sfep->name, sfep->namelen);
67909+ if (!dir_emit(ctx, name, sfep->namelen, ino, xfs_dir3_get_dtype(dp->i_mount, filetype)))
67910+ return 0;
67911+ } else if (!dir_emit(ctx, (char *)sfep->name, sfep->namelen, ino,
67912 xfs_dir3_get_dtype(dp->i_mount, filetype)))
67913 return 0;
67914 sfep = dp->d_ops->sf_nextentry(sfp, sfep);
67915diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
67916index 24c926b6..8726af88 100644
67917--- a/fs/xfs/xfs_ioctl.c
67918+++ b/fs/xfs/xfs_ioctl.c
67919@@ -122,7 +122,7 @@ xfs_find_handle(
67920 }
67921
67922 error = -EFAULT;
67923- if (copy_to_user(hreq->ohandle, &handle, hsize) ||
67924+ if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
67925 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
67926 goto out_put;
67927
67928diff --git a/fs/xfs/xfs_linux.h b/fs/xfs/xfs_linux.h
67929index 6a51619..9592e1b 100644
67930--- a/fs/xfs/xfs_linux.h
67931+++ b/fs/xfs/xfs_linux.h
67932@@ -234,7 +234,7 @@ static inline kgid_t xfs_gid_to_kgid(__uint32_t gid)
67933 * of the compiler which do not like us using do_div in the middle
67934 * of large functions.
67935 */
67936-static inline __u32 xfs_do_div(void *a, __u32 b, int n)
67937+static inline __u32 __intentional_overflow(-1) xfs_do_div(void *a, __u32 b, int n)
67938 {
67939 __u32 mod;
67940
67941@@ -290,7 +290,7 @@ static inline __u32 xfs_do_mod(void *a, __u32 b, int n)
67942 return 0;
67943 }
67944 #else
67945-static inline __u32 xfs_do_div(void *a, __u32 b, int n)
67946+static inline __u32 __intentional_overflow(-1) xfs_do_div(void *a, __u32 b, int n)
67947 {
67948 __u32 mod;
67949
67950diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
67951new file mode 100644
67952index 0000000..f27264e
67953--- /dev/null
67954+++ b/grsecurity/Kconfig
67955@@ -0,0 +1,1166 @@
67956+#
67957+# grecurity configuration
67958+#
67959+menu "Memory Protections"
67960+depends on GRKERNSEC
67961+
67962+config GRKERNSEC_KMEM
67963+ bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
67964+ default y if GRKERNSEC_CONFIG_AUTO
67965+ select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
67966+ help
67967+ If you say Y here, /dev/kmem and /dev/mem won't be allowed to
67968+ be written to or read from to modify or leak the contents of the running
67969+ kernel. /dev/port will also not be allowed to be opened, writing to
67970+ /dev/cpu/*/msr will be prevented, and support for kexec will be removed.
67971+ If you have module support disabled, enabling this will close up several
67972+ ways that are currently used to insert malicious code into the running
67973+ kernel.
67974+
67975+ Even with this feature enabled, we still highly recommend that
67976+ you use the RBAC system, as it is still possible for an attacker to
67977+ modify the running kernel through other more obscure methods.
67978+
67979+ It is highly recommended that you say Y here if you meet all the
67980+ conditions above.
67981+
67982+config GRKERNSEC_VM86
67983+ bool "Restrict VM86 mode"
67984+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
67985+ depends on X86_32
67986+
67987+ help
67988+ If you say Y here, only processes with CAP_SYS_RAWIO will be able to
67989+ make use of a special execution mode on 32bit x86 processors called
67990+ Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
67991+ video cards and will still work with this option enabled. The purpose
67992+ of the option is to prevent exploitation of emulation errors in
67993+ virtualization of vm86 mode like the one discovered in VMWare in 2009.
67994+ Nearly all users should be able to enable this option.
67995+
67996+config GRKERNSEC_IO
67997+ bool "Disable privileged I/O"
67998+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
67999+ depends on X86
68000+ select RTC_CLASS
68001+ select RTC_INTF_DEV
68002+ select RTC_DRV_CMOS
68003+
68004+ help
68005+ If you say Y here, all ioperm and iopl calls will return an error.
68006+ Ioperm and iopl can be used to modify the running kernel.
68007+ Unfortunately, some programs need this access to operate properly,
68008+ the most notable of which are XFree86 and hwclock. hwclock can be
68009+ remedied by having RTC support in the kernel, so real-time
68010+ clock support is enabled if this option is enabled, to ensure
68011+ that hwclock operates correctly. If hwclock still does not work,
68012+ either update udev or symlink /dev/rtc to /dev/rtc0.
68013+
68014+ If you're using XFree86 or a version of Xorg from 2012 or earlier,
68015+ you may not be able to boot into a graphical environment with this
68016+ option enabled. In this case, you should use the RBAC system instead.
68017+
68018+config GRKERNSEC_BPF_HARDEN
68019+ bool "Harden BPF interpreter"
68020+ default y if GRKERNSEC_CONFIG_AUTO
68021+ help
68022+ Unlike previous versions of grsecurity that hardened both the BPF
68023+ interpreted code against corruption at rest as well as the JIT code
68024+ against JIT-spray attacks and attacker-controlled immediate values
68025+ for ROP, this feature will enforce disabling of the new eBPF JIT engine
68026+ and will ensure the interpreted code is read-only at rest. This feature
68027+ may be removed at a later time when eBPF stabilizes to entirely revert
68028+ back to the more secure pre-3.16 BPF interpreter/JIT.
68029+
68030+ If you're using KERNEXEC, it's recommended that you enable this option
68031+ to supplement the hardening of the kernel.
68032+
68033+config GRKERNSEC_PERF_HARDEN
68034+ bool "Disable unprivileged PERF_EVENTS usage by default"
68035+ default y if GRKERNSEC_CONFIG_AUTO
68036+ depends on PERF_EVENTS
68037+ help
68038+ If you say Y here, the range of acceptable values for the
68039+ /proc/sys/kernel/perf_event_paranoid sysctl will be expanded to allow and
68040+ default to a new value: 3. When the sysctl is set to this value, no
68041+ unprivileged use of the PERF_EVENTS syscall interface will be permitted.
68042+
68043+ Though PERF_EVENTS can be used legitimately for performance monitoring
68044+ and low-level application profiling, it is forced on regardless of
68045+ configuration, has been at fault for several vulnerabilities, and
68046+ creates new opportunities for side channels and other information leaks.
68047+
68048+ This feature puts PERF_EVENTS into a secure default state and permits
68049+ the administrator to change out of it temporarily if unprivileged
68050+ application profiling is needed.
68051+
68052+config GRKERNSEC_RAND_THREADSTACK
68053+ bool "Insert random gaps between thread stacks"
68054+ default y if GRKERNSEC_CONFIG_AUTO
68055+ depends on PAX_RANDMMAP && !PPC
68056+ help
68057+ If you say Y here, a random-sized gap will be enforced between allocated
68058+ thread stacks. Glibc's NPTL and other threading libraries that
68059+ pass MAP_STACK to the kernel for thread stack allocation are supported.
68060+ The implementation currently provides 8 bits of entropy for the gap.
68061+
68062+ Many distributions do not compile threaded remote services with the
68063+ -fstack-check argument to GCC, causing the variable-sized stack-based
68064+ allocator, alloca(), to not probe the stack on allocation. This
68065+ permits an unbounded alloca() to skip over any guard page and potentially
68066+ modify another thread's stack reliably. An enforced random gap
68067+ reduces the reliability of such an attack and increases the chance
68068+ that such a read/write to another thread's stack instead lands in
68069+ an unmapped area, causing a crash and triggering grsecurity's
68070+ anti-bruteforcing logic.
68071+
68072+config GRKERNSEC_PROC_MEMMAP
68073+ bool "Harden ASLR against information leaks and entropy reduction"
68074+ default y if (GRKERNSEC_CONFIG_AUTO || PAX_NOEXEC || PAX_ASLR)
68075+ depends on PAX_NOEXEC || PAX_ASLR
68076+ help
68077+ If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
68078+ give no information about the addresses of its mappings if
68079+ PaX features that rely on random addresses are enabled on the task.
68080+ In addition to sanitizing this information and disabling other
68081+ dangerous sources of information, this option causes reads of sensitive
68082+ /proc/<pid> entries where the file descriptor was opened in a different
68083+ task than the one performing the read. Such attempts are logged.
68084+ This option also limits argv/env strings for suid/sgid binaries
68085+ to 512KB to prevent a complete exhaustion of the stack entropy provided
68086+ by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
68087+ binaries to prevent alternative mmap layouts from being abused.
68088+
68089+ If you use PaX it is essential that you say Y here as it closes up
68090+ several holes that make full ASLR useless locally.
68091+
68092+
68093+config GRKERNSEC_KSTACKOVERFLOW
68094+ bool "Prevent kernel stack overflows"
68095+ default y if GRKERNSEC_CONFIG_AUTO
68096+ depends on !IA64 && 64BIT
68097+ help
68098+ If you say Y here, the kernel's process stacks will be allocated
68099+ with vmalloc instead of the kernel's default allocator. This
68100+ introduces guard pages that in combination with the alloca checking
68101+ of the STACKLEAK feature prevents all forms of kernel process stack
68102+ overflow abuse. Note that this is different from kernel stack
68103+ buffer overflows.
68104+
68105+config GRKERNSEC_BRUTE
68106+ bool "Deter exploit bruteforcing"
68107+ default y if GRKERNSEC_CONFIG_AUTO
68108+ help
68109+ If you say Y here, attempts to bruteforce exploits against forking
68110+ daemons such as apache or sshd, as well as against suid/sgid binaries
68111+ will be deterred. When a child of a forking daemon is killed by PaX
68112+ or crashes due to an illegal instruction or other suspicious signal,
68113+ the parent process will be delayed 30 seconds upon every subsequent
68114+ fork until the administrator is able to assess the situation and
68115+ restart the daemon.
68116+ In the suid/sgid case, the attempt is logged, the user has all their
68117+ existing instances of the suid/sgid binary terminated and will
68118+ be unable to execute any suid/sgid binaries for 15 minutes.
68119+
68120+ It is recommended that you also enable signal logging in the auditing
68121+ section so that logs are generated when a process triggers a suspicious
68122+ signal.
68123+ If the sysctl option is enabled, a sysctl option with name
68124+ "deter_bruteforce" is created.
68125+
68126+config GRKERNSEC_MODHARDEN
68127+ bool "Harden module auto-loading"
68128+ default y if GRKERNSEC_CONFIG_AUTO
68129+ depends on MODULES
68130+ help
68131+ If you say Y here, module auto-loading in response to use of some
68132+ feature implemented by an unloaded module will be restricted to
68133+ root users. Enabling this option helps defend against attacks
68134+ by unprivileged users who abuse the auto-loading behavior to
68135+ cause a vulnerable module to load that is then exploited.
68136+
68137+ If this option prevents a legitimate use of auto-loading for a
68138+ non-root user, the administrator can execute modprobe manually
68139+ with the exact name of the module mentioned in the alert log.
68140+ Alternatively, the administrator can add the module to the list
68141+ of modules loaded at boot by modifying init scripts.
68142+
68143+ Modification of init scripts will most likely be needed on
68144+ Ubuntu servers with encrypted home directory support enabled,
68145+ as the first non-root user logging in will cause the ecb(aes),
68146+ ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
68147+
68148+config GRKERNSEC_HIDESYM
68149+ bool "Hide kernel symbols"
68150+ default y if GRKERNSEC_CONFIG_AUTO
68151+ select PAX_USERCOPY_SLABS
68152+ help
68153+ If you say Y here, getting information on loaded modules, and
68154+ displaying all kernel symbols through a syscall will be restricted
68155+ to users with CAP_SYS_MODULE. For software compatibility reasons,
68156+ /proc/kallsyms will be restricted to the root user. The RBAC
68157+ system can hide that entry even from root.
68158+
68159+ This option also prevents leaking of kernel addresses through
68160+ several /proc entries.
68161+
68162+ Note that this option is only effective provided the following
68163+ conditions are met:
68164+ 1) The kernel using grsecurity is not precompiled by some distribution
68165+ 2) You have also enabled GRKERNSEC_DMESG
68166+ 3) You are using the RBAC system and hiding other files such as your
68167+ kernel image and System.map. Alternatively, enabling this option
68168+ causes the permissions on /boot, /lib/modules, and the kernel
68169+ source directory to change at compile time to prevent
68170+ reading by non-root users.
68171+ If the above conditions are met, this option will aid in providing a
68172+ useful protection against local kernel exploitation of overflows
68173+ and arbitrary read/write vulnerabilities.
68174+
68175+ It is highly recommended that you enable GRKERNSEC_PERF_HARDEN
68176+ in addition to this feature.
68177+
68178+config GRKERNSEC_RANDSTRUCT
68179+ bool "Randomize layout of sensitive kernel structures"
68180+ default y if GRKERNSEC_CONFIG_AUTO
68181+ select GRKERNSEC_HIDESYM
68182+ select MODVERSIONS if MODULES
68183+ help
68184+ If you say Y here, the layouts of a number of sensitive kernel
68185+ structures (task, fs, cred, etc) and all structures composed entirely
68186+ of function pointers (aka "ops" structs) will be randomized at compile-time.
68187+ This can introduce the requirement of an additional infoleak
68188+ vulnerability for exploits targeting these structure types.
68189+
68190+ Enabling this feature will introduce some performance impact, slightly
68191+ increase memory usage, and prevent the use of forensic tools like
68192+ Volatility against the system (unless the kernel source tree isn't
68193+ cleaned after kernel installation).
68194+
68195+ The seed used for compilation is located at tools/gcc/randomize_layout_seed.h.
68196+ It remains after a make clean to allow for external modules to be compiled
68197+ with the existing seed and will be removed by a make mrproper or
68198+ make distclean.
68199+
68200+ Note that the implementation requires gcc 4.6.4. or newer. You may need
68201+ to install the supporting headers explicitly in addition to the normal
68202+ gcc package.
68203+
68204+config GRKERNSEC_RANDSTRUCT_PERFORMANCE
68205+ bool "Use cacheline-aware structure randomization"
68206+ depends on GRKERNSEC_RANDSTRUCT
68207+ default y if GRKERNSEC_CONFIG_PRIORITY_PERF
68208+ help
68209+ If you say Y here, the RANDSTRUCT randomization will make a best effort
68210+ at restricting randomization to cacheline-sized groups of elements. It
68211+ will further not randomize bitfields in structures. This reduces the
68212+ performance hit of RANDSTRUCT at the cost of weakened randomization.
68213+
68214+config GRKERNSEC_KERN_LOCKOUT
68215+ bool "Active kernel exploit response"
68216+ default y if GRKERNSEC_CONFIG_AUTO
68217+ depends on X86 || ARM || PPC || SPARC
68218+ help
68219+ If you say Y here, when a PaX alert is triggered due to suspicious
68220+ activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
68221+ or an OOPS occurs due to bad memory accesses, instead of just
68222+ terminating the offending process (and potentially allowing
68223+ a subsequent exploit from the same user), we will take one of two
68224+ actions:
68225+ If the user was root, we will panic the system
68226+ If the user was non-root, we will log the attempt, terminate
68227+ all processes owned by the user, then prevent them from creating
68228+ any new processes until the system is restarted
68229+ This deters repeated kernel exploitation/bruteforcing attempts
68230+ and is useful for later forensics.
68231+
68232+config GRKERNSEC_OLD_ARM_USERLAND
68233+ bool "Old ARM userland compatibility"
68234+ depends on ARM && (CPU_V6 || CPU_V6K || CPU_V7)
68235+ help
68236+ If you say Y here, stubs of executable code to perform such operations
68237+ as "compare-exchange" will be placed at fixed locations in the ARM vector
68238+ table. This is unfortunately needed for old ARM userland meant to run
68239+ across a wide range of processors. Without this option enabled,
68240+ the get_tls and data memory barrier stubs will be emulated by the kernel,
68241+ which is enough for Linaro userlands or other userlands designed for v6
68242+ and newer ARM CPUs. It's recommended that you try without this option enabled
68243+ first, and only enable it if your userland does not boot (it will likely fail
68244+ at init time).
68245+
68246+endmenu
68247+menu "Role Based Access Control Options"
68248+depends on GRKERNSEC
68249+
68250+config GRKERNSEC_RBAC_DEBUG
68251+ bool
68252+
68253+config GRKERNSEC_NO_RBAC
68254+ bool "Disable RBAC system"
68255+ help
68256+ If you say Y here, the /dev/grsec device will be removed from the kernel,
68257+ preventing the RBAC system from being enabled. You should only say Y
68258+ here if you have no intention of using the RBAC system, so as to prevent
68259+ an attacker with root access from misusing the RBAC system to hide files
68260+ and processes when loadable module support and /dev/[k]mem have been
68261+ locked down.
68262+
68263+config GRKERNSEC_ACL_HIDEKERN
68264+ bool "Hide kernel processes"
68265+ help
68266+ If you say Y here, all kernel threads will be hidden to all
68267+ processes but those whose subject has the "view hidden processes"
68268+ flag.
68269+
68270+config GRKERNSEC_ACL_MAXTRIES
68271+ int "Maximum tries before password lockout"
68272+ default 3
68273+ help
68274+ This option enforces the maximum number of times a user can attempt
68275+ to authorize themselves with the grsecurity RBAC system before being
68276+ denied the ability to attempt authorization again for a specified time.
68277+ The lower the number, the harder it will be to brute-force a password.
68278+
68279+config GRKERNSEC_ACL_TIMEOUT
68280+ int "Time to wait after max password tries, in seconds"
68281+ default 30
68282+ help
68283+ This option specifies the time the user must wait after attempting to
68284+ authorize to the RBAC system with the maximum number of invalid
68285+ passwords. The higher the number, the harder it will be to brute-force
68286+ a password.
68287+
68288+endmenu
68289+menu "Filesystem Protections"
68290+depends on GRKERNSEC
68291+
68292+config GRKERNSEC_PROC
68293+ bool "Proc restrictions"
68294+ default y if GRKERNSEC_CONFIG_AUTO
68295+ help
68296+ If you say Y here, the permissions of the /proc filesystem
68297+ will be altered to enhance system security and privacy. You MUST
68298+ choose either a user only restriction or a user and group restriction.
68299+ Depending upon the option you choose, you can either restrict users to
68300+ see only the processes they themselves run, or choose a group that can
68301+ view all processes and files normally restricted to root if you choose
68302+ the "restrict to user only" option. NOTE: If you're running identd or
68303+ ntpd as a non-root user, you will have to run it as the group you
68304+ specify here.
68305+
68306+config GRKERNSEC_PROC_USER
68307+ bool "Restrict /proc to user only"
68308+ depends on GRKERNSEC_PROC
68309+ help
68310+ If you say Y here, non-root users will only be able to view their own
68311+ processes, and restricts them from viewing network-related information,
68312+ and viewing kernel symbol and module information.
68313+
68314+config GRKERNSEC_PROC_USERGROUP
68315+ bool "Allow special group"
68316+ default y if GRKERNSEC_CONFIG_AUTO
68317+ depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
68318+ help
68319+ If you say Y here, you will be able to select a group that will be
68320+ able to view all processes and network-related information. If you've
68321+ enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
68322+ remain hidden. This option is useful if you want to run identd as
68323+ a non-root user. The group you select may also be chosen at boot time
68324+ via "grsec_proc_gid=" on the kernel commandline.
68325+
68326+config GRKERNSEC_PROC_GID
68327+ int "GID for special group"
68328+ depends on GRKERNSEC_PROC_USERGROUP
68329+ default 1001
68330+
68331+config GRKERNSEC_PROC_ADD
68332+ bool "Additional restrictions"
68333+ default y if GRKERNSEC_CONFIG_AUTO
68334+ depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
68335+ help
68336+ If you say Y here, additional restrictions will be placed on
68337+ /proc that keep normal users from viewing device information and
68338+ slabinfo information that could be useful for exploits.
68339+
68340+config GRKERNSEC_LINK
68341+ bool "Linking restrictions"
68342+ default y if GRKERNSEC_CONFIG_AUTO
68343+ help
68344+ If you say Y here, /tmp race exploits will be prevented, since users
68345+ will no longer be able to follow symlinks owned by other users in
68346+ world-writable +t directories (e.g. /tmp), unless the owner of the
68347+ symlink is the owner of the directory. users will also not be
68348+ able to hardlink to files they do not own. If the sysctl option is
68349+ enabled, a sysctl option with name "linking_restrictions" is created.
68350+
68351+config GRKERNSEC_SYMLINKOWN
68352+ bool "Kernel-enforced SymlinksIfOwnerMatch"
68353+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
68354+ help
68355+ Apache's SymlinksIfOwnerMatch option has an inherent race condition
68356+ that prevents it from being used as a security feature. As Apache
68357+ verifies the symlink by performing a stat() against the target of
68358+ the symlink before it is followed, an attacker can setup a symlink
68359+ to point to a same-owned file, then replace the symlink with one
68360+ that targets another user's file just after Apache "validates" the
68361+ symlink -- a classic TOCTOU race. If you say Y here, a complete,
68362+ race-free replacement for Apache's "SymlinksIfOwnerMatch" option
68363+ will be in place for the group you specify. If the sysctl option
68364+ is enabled, a sysctl option with name "enforce_symlinksifowner" is
68365+ created.
68366+
68367+config GRKERNSEC_SYMLINKOWN_GID
68368+ int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
68369+ depends on GRKERNSEC_SYMLINKOWN
68370+ default 1006
68371+ help
68372+ Setting this GID determines what group kernel-enforced
68373+ SymlinksIfOwnerMatch will be enabled for. If the sysctl option
68374+ is enabled, a sysctl option with name "symlinkown_gid" is created.
68375+
68376+config GRKERNSEC_FIFO
68377+ bool "FIFO restrictions"
68378+ default y if GRKERNSEC_CONFIG_AUTO
68379+ help
68380+ If you say Y here, users will not be able to write to FIFOs they don't
68381+ own in world-writable +t directories (e.g. /tmp), unless the owner of
68382+ the FIFO is the same owner of the directory it's held in. If the sysctl
68383+ option is enabled, a sysctl option with name "fifo_restrictions" is
68384+ created.
68385+
68386+config GRKERNSEC_SYSFS_RESTRICT
68387+ bool "Sysfs/debugfs restriction"
68388+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
68389+ depends on SYSFS
68390+ help
68391+ If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
68392+ any filesystem normally mounted under it (e.g. debugfs) will be
68393+ mostly accessible only by root. These filesystems generally provide access
68394+ to hardware and debug information that isn't appropriate for unprivileged
68395+ users of the system. Sysfs and debugfs have also become a large source
68396+ of new vulnerabilities, ranging from infoleaks to local compromise.
68397+ There has been very little oversight with an eye toward security involved
68398+ in adding new exporters of information to these filesystems, so their
68399+ use is discouraged.
68400+ For reasons of compatibility, a few directories have been whitelisted
68401+ for access by non-root users:
68402+ /sys/fs/selinux
68403+ /sys/fs/fuse
68404+ /sys/devices/system/cpu
68405+
68406+config GRKERNSEC_ROFS
68407+ bool "Runtime read-only mount protection"
68408+ depends on SYSCTL
68409+ help
68410+ If you say Y here, a sysctl option with name "romount_protect" will
68411+ be created. By setting this option to 1 at runtime, filesystems
68412+ will be protected in the following ways:
68413+ * No new writable mounts will be allowed
68414+ * Existing read-only mounts won't be able to be remounted read/write
68415+ * Write operations will be denied on all block devices
68416+ This option acts independently of grsec_lock: once it is set to 1,
68417+ it cannot be turned off. Therefore, please be mindful of the resulting
68418+ behavior if this option is enabled in an init script on a read-only
68419+ filesystem.
68420+ Also be aware that as with other root-focused features, GRKERNSEC_KMEM
68421+ and GRKERNSEC_IO should be enabled and module loading disabled via
68422+ config or at runtime.
68423+ This feature is mainly intended for secure embedded systems.
68424+
68425+
68426+config GRKERNSEC_DEVICE_SIDECHANNEL
68427+ bool "Eliminate stat/notify-based device sidechannels"
68428+ default y if GRKERNSEC_CONFIG_AUTO
68429+ help
68430+ If you say Y here, timing analyses on block or character
68431+ devices like /dev/ptmx using stat or inotify/dnotify/fanotify
68432+ will be thwarted for unprivileged users. If a process without
68433+ CAP_MKNOD stats such a device, the last access and last modify times
68434+ will match the device's create time. No access or modify events
68435+ will be triggered through inotify/dnotify/fanotify for such devices.
68436+ This feature will prevent attacks that may at a minimum
68437+ allow an attacker to determine the administrator's password length.
68438+
68439+config GRKERNSEC_CHROOT
68440+ bool "Chroot jail restrictions"
68441+ default y if GRKERNSEC_CONFIG_AUTO
68442+ help
68443+ If you say Y here, you will be able to choose several options that will
68444+ make breaking out of a chrooted jail much more difficult. If you
68445+ encounter no software incompatibilities with the following options, it
68446+ is recommended that you enable each one.
68447+
68448+ Note that the chroot restrictions are not intended to apply to "chroots"
68449+ to directories that are simple bind mounts of the global root filesystem.
68450+ For several other reasons, a user shouldn't expect any significant
68451+ security by performing such a chroot.
68452+
68453+config GRKERNSEC_CHROOT_MOUNT
68454+ bool "Deny mounts"
68455+ default y if GRKERNSEC_CONFIG_AUTO
68456+ depends on GRKERNSEC_CHROOT
68457+ help
68458+ If you say Y here, processes inside a chroot will not be able to
68459+ mount or remount filesystems. If the sysctl option is enabled, a
68460+ sysctl option with name "chroot_deny_mount" is created.
68461+
68462+config GRKERNSEC_CHROOT_DOUBLE
68463+ bool "Deny double-chroots"
68464+ default y if GRKERNSEC_CONFIG_AUTO
68465+ depends on GRKERNSEC_CHROOT
68466+ help
68467+ If you say Y here, processes inside a chroot will not be able to chroot
68468+ again outside the chroot. This is a widely used method of breaking
68469+ out of a chroot jail and should not be allowed. If the sysctl
68470+ option is enabled, a sysctl option with name
68471+ "chroot_deny_chroot" is created.
68472+
68473+config GRKERNSEC_CHROOT_PIVOT
68474+ bool "Deny pivot_root in chroot"
68475+ default y if GRKERNSEC_CONFIG_AUTO
68476+ depends on GRKERNSEC_CHROOT
68477+ help
68478+ If you say Y here, processes inside a chroot will not be able to use
68479+ a function called pivot_root() that was introduced in Linux 2.3.41. It
68480+ works similar to chroot in that it changes the root filesystem. This
68481+ function could be misused in a chrooted process to attempt to break out
68482+ of the chroot, and therefore should not be allowed. If the sysctl
68483+ option is enabled, a sysctl option with name "chroot_deny_pivot" is
68484+ created.
68485+
68486+config GRKERNSEC_CHROOT_CHDIR
68487+ bool "Enforce chdir(\"/\") on all chroots"
68488+ default y if GRKERNSEC_CONFIG_AUTO
68489+ depends on GRKERNSEC_CHROOT
68490+ help
68491+ If you say Y here, the current working directory of all newly-chrooted
68492+ applications will be set to the the root directory of the chroot.
68493+ The man page on chroot(2) states:
68494+ Note that this call does not change the current working
68495+ directory, so that `.' can be outside the tree rooted at
68496+ `/'. In particular, the super-user can escape from a
68497+ `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
68498+
68499+ It is recommended that you say Y here, since it's not known to break
68500+ any software. If the sysctl option is enabled, a sysctl option with
68501+ name "chroot_enforce_chdir" is created.
68502+
68503+config GRKERNSEC_CHROOT_CHMOD
68504+ bool "Deny (f)chmod +s"
68505+ default y if GRKERNSEC_CONFIG_AUTO
68506+ depends on GRKERNSEC_CHROOT
68507+ help
68508+ If you say Y here, processes inside a chroot will not be able to chmod
68509+ or fchmod files to make them have suid or sgid bits. This protects
68510+ against another published method of breaking a chroot. If the sysctl
68511+ option is enabled, a sysctl option with name "chroot_deny_chmod" is
68512+ created.
68513+
68514+config GRKERNSEC_CHROOT_FCHDIR
68515+ bool "Deny fchdir and fhandle out of chroot"
68516+ default y if GRKERNSEC_CONFIG_AUTO
68517+ depends on GRKERNSEC_CHROOT
68518+ help
68519+ If you say Y here, a well-known method of breaking chroots by fchdir'ing
68520+ to a file descriptor of the chrooting process that points to a directory
68521+ outside the filesystem will be stopped. Additionally, this option prevents
68522+ use of the recently-created syscall for opening files by a guessable "file
68523+ handle" inside a chroot. If the sysctl option is enabled, a sysctl option
68524+ with name "chroot_deny_fchdir" is created.
68525+
68526+config GRKERNSEC_CHROOT_MKNOD
68527+ bool "Deny mknod"
68528+ default y if GRKERNSEC_CONFIG_AUTO
68529+ depends on GRKERNSEC_CHROOT
68530+ help
68531+ If you say Y here, processes inside a chroot will not be allowed to
68532+ mknod. The problem with using mknod inside a chroot is that it
68533+ would allow an attacker to create a device entry that is the same
68534+ as one on the physical root of your system, which could range from
68535+ anything from the console device to a device for your harddrive (which
68536+ they could then use to wipe the drive or steal data). It is recommended
68537+ that you say Y here, unless you run into software incompatibilities.
68538+ If the sysctl option is enabled, a sysctl option with name
68539+ "chroot_deny_mknod" is created.
68540+
68541+config GRKERNSEC_CHROOT_SHMAT
68542+ bool "Deny shmat() out of chroot"
68543+ default y if GRKERNSEC_CONFIG_AUTO
68544+ depends on GRKERNSEC_CHROOT
68545+ help
68546+ If you say Y here, processes inside a chroot will not be able to attach
68547+ to shared memory segments that were created outside of the chroot jail.
68548+ It is recommended that you say Y here. If the sysctl option is enabled,
68549+ a sysctl option with name "chroot_deny_shmat" is created.
68550+
68551+config GRKERNSEC_CHROOT_UNIX
68552+ bool "Deny access to abstract AF_UNIX sockets out of chroot"
68553+ default y if GRKERNSEC_CONFIG_AUTO
68554+ depends on GRKERNSEC_CHROOT
68555+ help
68556+ If you say Y here, processes inside a chroot will not be able to
68557+ connect to abstract (meaning not belonging to a filesystem) Unix
68558+ domain sockets that were bound outside of a chroot. It is recommended
68559+ that you say Y here. If the sysctl option is enabled, a sysctl option
68560+ with name "chroot_deny_unix" is created.
68561+
68562+config GRKERNSEC_CHROOT_FINDTASK
68563+ bool "Protect outside processes"
68564+ default y if GRKERNSEC_CONFIG_AUTO
68565+ depends on GRKERNSEC_CHROOT
68566+ help
68567+ If you say Y here, processes inside a chroot will not be able to
68568+ kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
68569+ getsid, or view any process outside of the chroot. If the sysctl
68570+ option is enabled, a sysctl option with name "chroot_findtask" is
68571+ created.
68572+
68573+config GRKERNSEC_CHROOT_NICE
68574+ bool "Restrict priority changes"
68575+ default y if GRKERNSEC_CONFIG_AUTO
68576+ depends on GRKERNSEC_CHROOT
68577+ help
68578+ If you say Y here, processes inside a chroot will not be able to raise
68579+ the priority of processes in the chroot, or alter the priority of
68580+ processes outside the chroot. This provides more security than simply
68581+ removing CAP_SYS_NICE from the process' capability set. If the
68582+ sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
68583+ is created.
68584+
68585+config GRKERNSEC_CHROOT_SYSCTL
68586+ bool "Deny sysctl writes"
68587+ default y if GRKERNSEC_CONFIG_AUTO
68588+ depends on GRKERNSEC_CHROOT
68589+ help
68590+ If you say Y here, an attacker in a chroot will not be able to
68591+ write to sysctl entries, either by sysctl(2) or through a /proc
68592+ interface. It is strongly recommended that you say Y here. If the
68593+ sysctl option is enabled, a sysctl option with name
68594+ "chroot_deny_sysctl" is created.
68595+
68596+config GRKERNSEC_CHROOT_CAPS
68597+ bool "Capability restrictions"
68598+ default y if GRKERNSEC_CONFIG_AUTO
68599+ depends on GRKERNSEC_CHROOT
68600+ help
68601+ If you say Y here, the capabilities on all processes within a
68602+ chroot jail will be lowered to stop module insertion, raw i/o,
68603+ system and net admin tasks, rebooting the system, modifying immutable
68604+ files, modifying IPC owned by another, and changing the system time.
68605+ This is left an option because it can break some apps. Disable this
68606+ if your chrooted apps are having problems performing those kinds of
68607+ tasks. If the sysctl option is enabled, a sysctl option with
68608+ name "chroot_caps" is created.
68609+
68610+config GRKERNSEC_CHROOT_INITRD
68611+ bool "Exempt initrd tasks from restrictions"
68612+ default y if GRKERNSEC_CONFIG_AUTO
68613+ depends on GRKERNSEC_CHROOT && BLK_DEV_INITRD
68614+ help
68615+ If you say Y here, tasks started prior to init will be exempted from
68616+ grsecurity's chroot restrictions. This option is mainly meant to
68617+ resolve Plymouth's performing privileged operations unnecessarily
68618+ in a chroot.
68619+
68620+endmenu
68621+menu "Kernel Auditing"
68622+depends on GRKERNSEC
68623+
68624+config GRKERNSEC_AUDIT_GROUP
68625+ bool "Single group for auditing"
68626+ help
68627+ If you say Y here, the exec and chdir logging features will only operate
68628+ on a group you specify. This option is recommended if you only want to
68629+ watch certain users instead of having a large amount of logs from the
68630+ entire system. If the sysctl option is enabled, a sysctl option with
68631+ name "audit_group" is created.
68632+
68633+config GRKERNSEC_AUDIT_GID
68634+ int "GID for auditing"
68635+ depends on GRKERNSEC_AUDIT_GROUP
68636+ default 1007
68637+
68638+config GRKERNSEC_EXECLOG
68639+ bool "Exec logging"
68640+ help
68641+ If you say Y here, all execve() calls will be logged (since the
68642+ other exec*() calls are frontends to execve(), all execution
68643+ will be logged). Useful for shell-servers that like to keep track
68644+ of their users. If the sysctl option is enabled, a sysctl option with
68645+ name "exec_logging" is created.
68646+ WARNING: This option when enabled will produce a LOT of logs, especially
68647+ on an active system.
68648+
68649+config GRKERNSEC_RESLOG
68650+ bool "Resource logging"
68651+ default y if GRKERNSEC_CONFIG_AUTO
68652+ help
68653+ If you say Y here, all attempts to overstep resource limits will
68654+ be logged with the resource name, the requested size, and the current
68655+ limit. It is highly recommended that you say Y here. If the sysctl
68656+ option is enabled, a sysctl option with name "resource_logging" is
68657+ created. If the RBAC system is enabled, the sysctl value is ignored.
68658+
68659+config GRKERNSEC_CHROOT_EXECLOG
68660+ bool "Log execs within chroot"
68661+ help
68662+ If you say Y here, all executions inside a chroot jail will be logged
68663+ to syslog. This can cause a large amount of logs if certain
68664+ applications (eg. djb's daemontools) are installed on the system, and
68665+ is therefore left as an option. If the sysctl option is enabled, a
68666+ sysctl option with name "chroot_execlog" is created.
68667+
68668+config GRKERNSEC_AUDIT_PTRACE
68669+ bool "Ptrace logging"
68670+ help
68671+ If you say Y here, all attempts to attach to a process via ptrace
68672+ will be logged. If the sysctl option is enabled, a sysctl option
68673+ with name "audit_ptrace" is created.
68674+
68675+config GRKERNSEC_AUDIT_CHDIR
68676+ bool "Chdir logging"
68677+ help
68678+ If you say Y here, all chdir() calls will be logged. If the sysctl
68679+ option is enabled, a sysctl option with name "audit_chdir" is created.
68680+
68681+config GRKERNSEC_AUDIT_MOUNT
68682+ bool "(Un)Mount logging"
68683+ help
68684+ If you say Y here, all mounts and unmounts will be logged. If the
68685+ sysctl option is enabled, a sysctl option with name "audit_mount" is
68686+ created.
68687+
68688+config GRKERNSEC_SIGNAL
68689+ bool "Signal logging"
68690+ default y if GRKERNSEC_CONFIG_AUTO
68691+ help
68692+ If you say Y here, certain important signals will be logged, such as
68693+ SIGSEGV, which will as a result inform you of when a error in a program
68694+ occurred, which in some cases could mean a possible exploit attempt.
68695+ If the sysctl option is enabled, a sysctl option with name
68696+ "signal_logging" is created.
68697+
68698+config GRKERNSEC_FORKFAIL
68699+ bool "Fork failure logging"
68700+ help
68701+ If you say Y here, all failed fork() attempts will be logged.
68702+ This could suggest a fork bomb, or someone attempting to overstep
68703+ their process limit. If the sysctl option is enabled, a sysctl option
68704+ with name "forkfail_logging" is created.
68705+
68706+config GRKERNSEC_TIME
68707+ bool "Time change logging"
68708+ default y if GRKERNSEC_CONFIG_AUTO
68709+ help
68710+ If you say Y here, any changes of the system clock will be logged.
68711+ If the sysctl option is enabled, a sysctl option with name
68712+ "timechange_logging" is created.
68713+
68714+config GRKERNSEC_PROC_IPADDR
68715+ bool "/proc/<pid>/ipaddr support"
68716+ default y if GRKERNSEC_CONFIG_AUTO
68717+ help
68718+ If you say Y here, a new entry will be added to each /proc/<pid>
68719+ directory that contains the IP address of the person using the task.
68720+ The IP is carried across local TCP and AF_UNIX stream sockets.
68721+ This information can be useful for IDS/IPSes to perform remote response
68722+ to a local attack. The entry is readable by only the owner of the
68723+ process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
68724+ the RBAC system), and thus does not create privacy concerns.
68725+
68726+config GRKERNSEC_RWXMAP_LOG
68727+ bool 'Denied RWX mmap/mprotect logging'
68728+ default y if GRKERNSEC_CONFIG_AUTO
68729+ depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
68730+ help
68731+ If you say Y here, calls to mmap() and mprotect() with explicit
68732+ usage of PROT_WRITE and PROT_EXEC together will be logged when
68733+ denied by the PAX_MPROTECT feature. This feature will also
68734+ log other problematic scenarios that can occur when PAX_MPROTECT
68735+ is enabled on a binary, like textrels and PT_GNU_STACK. If the
68736+ sysctl option is enabled, a sysctl option with name "rwxmap_logging"
68737+ is created.
68738+
68739+endmenu
68740+
68741+menu "Executable Protections"
68742+depends on GRKERNSEC
68743+
68744+config GRKERNSEC_DMESG
68745+ bool "Dmesg(8) restriction"
68746+ default y if GRKERNSEC_CONFIG_AUTO
68747+ help
68748+ If you say Y here, non-root users will not be able to use dmesg(8)
68749+ to view the contents of the kernel's circular log buffer.
68750+ The kernel's log buffer often contains kernel addresses and other
68751+ identifying information useful to an attacker in fingerprinting a
68752+ system for a targeted exploit.
68753+ If the sysctl option is enabled, a sysctl option with name "dmesg" is
68754+ created.
68755+
68756+config GRKERNSEC_HARDEN_PTRACE
68757+ bool "Deter ptrace-based process snooping"
68758+ default y if GRKERNSEC_CONFIG_AUTO
68759+ help
68760+ If you say Y here, TTY sniffers and other malicious monitoring
68761+ programs implemented through ptrace will be defeated. If you
68762+ have been using the RBAC system, this option has already been
68763+ enabled for several years for all users, with the ability to make
68764+ fine-grained exceptions.
68765+
68766+ This option only affects the ability of non-root users to ptrace
68767+ processes that are not a descendent of the ptracing process.
68768+ This means that strace ./binary and gdb ./binary will still work,
68769+ but attaching to arbitrary processes will not. If the sysctl
68770+ option is enabled, a sysctl option with name "harden_ptrace" is
68771+ created.
68772+
68773+config GRKERNSEC_PTRACE_READEXEC
68774+ bool "Require read access to ptrace sensitive binaries"
68775+ default y if GRKERNSEC_CONFIG_AUTO
68776+ help
68777+ If you say Y here, unprivileged users will not be able to ptrace unreadable
68778+ binaries. This option is useful in environments that
68779+ remove the read bits (e.g. file mode 4711) from suid binaries to
68780+ prevent infoleaking of their contents. This option adds
68781+ consistency to the use of that file mode, as the binary could normally
68782+ be read out when run without privileges while ptracing.
68783+
68784+ If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
68785+ is created.
68786+
68787+config GRKERNSEC_SETXID
68788+ bool "Enforce consistent multithreaded privileges"
68789+ default y if GRKERNSEC_CONFIG_AUTO
68790+ depends on (X86 || SPARC64 || PPC || ARM || MIPS)
68791+ help
68792+ If you say Y here, a change from a root uid to a non-root uid
68793+ in a multithreaded application will cause the resulting uids,
68794+ gids, supplementary groups, and capabilities in that thread
68795+ to be propagated to the other threads of the process. In most
68796+ cases this is unnecessary, as glibc will emulate this behavior
68797+ on behalf of the application. Other libcs do not act in the
68798+ same way, allowing the other threads of the process to continue
68799+ running with root privileges. If the sysctl option is enabled,
68800+ a sysctl option with name "consistent_setxid" is created.
68801+
68802+config GRKERNSEC_HARDEN_IPC
68803+ bool "Disallow access to overly-permissive IPC objects"
68804+ default y if GRKERNSEC_CONFIG_AUTO
68805+ depends on SYSVIPC
68806+ help
68807+ If you say Y here, access to overly-permissive IPC objects (shared
68808+ memory, message queues, and semaphores) will be denied for processes
68809+ given the following criteria beyond normal permission checks:
68810+ 1) If the IPC object is world-accessible and the euid doesn't match
68811+ that of the creator or current uid for the IPC object
68812+ 2) If the IPC object is group-accessible and the egid doesn't
68813+ match that of the creator or current gid for the IPC object
68814+ It's a common error to grant too much permission to these objects,
68815+ with impact ranging from denial of service and information leaking to
68816+ privilege escalation. This feature was developed in response to
68817+ research by Tim Brown:
68818+ http://labs.portcullis.co.uk/whitepapers/memory-squatting-attacks-on-system-v-shared-memory/
68819+ who found hundreds of such insecure usages. Processes with
68820+ CAP_IPC_OWNER are still permitted to access these IPC objects.
68821+ If the sysctl option is enabled, a sysctl option with name
68822+ "harden_ipc" is created.
68823+
68824+config GRKERNSEC_TPE
68825+ bool "Trusted Path Execution (TPE)"
68826+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
68827+ help
68828+ If you say Y here, you will be able to choose a gid to add to the
68829+ supplementary groups of users you want to mark as "untrusted."
68830+ These users will not be able to execute any files that are not in
68831+ root-owned directories writable only by root. If the sysctl option
68832+ is enabled, a sysctl option with name "tpe" is created.
68833+
68834+config GRKERNSEC_TPE_ALL
68835+ bool "Partially restrict all non-root users"
68836+ depends on GRKERNSEC_TPE
68837+ help
68838+ If you say Y here, all non-root users will be covered under
68839+ a weaker TPE restriction. This is separate from, and in addition to,
68840+ the main TPE options that you have selected elsewhere. Thus, if a
68841+ "trusted" GID is chosen, this restriction applies to even that GID.
68842+ Under this restriction, all non-root users will only be allowed to
68843+ execute files in directories they own that are not group or
68844+ world-writable, or in directories owned by root and writable only by
68845+ root. If the sysctl option is enabled, a sysctl option with name
68846+ "tpe_restrict_all" is created.
68847+
68848+config GRKERNSEC_TPE_INVERT
68849+ bool "Invert GID option"
68850+ depends on GRKERNSEC_TPE
68851+ help
68852+ If you say Y here, the group you specify in the TPE configuration will
68853+ decide what group TPE restrictions will be *disabled* for. This
68854+ option is useful if you want TPE restrictions to be applied to most
68855+ users on the system. If the sysctl option is enabled, a sysctl option
68856+ with name "tpe_invert" is created. Unlike other sysctl options, this
68857+ entry will default to on for backward-compatibility.
68858+
68859+config GRKERNSEC_TPE_GID
68860+ int
68861+ default GRKERNSEC_TPE_UNTRUSTED_GID if (GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT)
68862+ default GRKERNSEC_TPE_TRUSTED_GID if (GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT)
68863+
68864+config GRKERNSEC_TPE_UNTRUSTED_GID
68865+ int "GID for TPE-untrusted users"
68866+ depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
68867+ default 1005
68868+ help
68869+ Setting this GID determines what group TPE restrictions will be
68870+ *enabled* for. If the sysctl option is enabled, a sysctl option
68871+ with name "tpe_gid" is created.
68872+
68873+config GRKERNSEC_TPE_TRUSTED_GID
68874+ int "GID for TPE-trusted users"
68875+ depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
68876+ default 1005
68877+ help
68878+ Setting this GID determines what group TPE restrictions will be
68879+ *disabled* for. If the sysctl option is enabled, a sysctl option
68880+ with name "tpe_gid" is created.
68881+
68882+endmenu
68883+menu "Network Protections"
68884+depends on GRKERNSEC
68885+
68886+config GRKERNSEC_BLACKHOLE
68887+ bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
68888+ default y if GRKERNSEC_CONFIG_AUTO
68889+ depends on NET
68890+ help
68891+ If you say Y here, neither TCP resets nor ICMP
68892+ destination-unreachable packets will be sent in response to packets
68893+ sent to ports for which no associated listening process exists.
68894+ It will also prevent the sending of ICMP protocol unreachable packets
68895+ in response to packets with unknown protocols.
68896+ This feature supports both IPV4 and IPV6 and exempts the
68897+ loopback interface from blackholing. Enabling this feature
68898+ makes a host more resilient to DoS attacks and reduces network
68899+ visibility against scanners.
68900+
68901+ The blackhole feature as-implemented is equivalent to the FreeBSD
68902+ blackhole feature, as it prevents RST responses to all packets, not
68903+ just SYNs. Under most application behavior this causes no
68904+ problems, but applications (like haproxy) may not close certain
68905+ connections in a way that cleanly terminates them on the remote
68906+ end, leaving the remote host in LAST_ACK state. Because of this
68907+ side-effect and to prevent intentional LAST_ACK DoSes, this
68908+ feature also adds automatic mitigation against such attacks.
68909+ The mitigation drastically reduces the amount of time a socket
68910+ can spend in LAST_ACK state. If you're using haproxy and not
68911+ all servers it connects to have this option enabled, consider
68912+ disabling this feature on the haproxy host.
68913+
68914+ If the sysctl option is enabled, two sysctl options with names
68915+ "ip_blackhole" and "lastack_retries" will be created.
68916+ While "ip_blackhole" takes the standard zero/non-zero on/off
68917+ toggle, "lastack_retries" uses the same kinds of values as
68918+ "tcp_retries1" and "tcp_retries2". The default value of 4
68919+ prevents a socket from lasting more than 45 seconds in LAST_ACK
68920+ state.
68921+
68922+config GRKERNSEC_NO_SIMULT_CONNECT
68923+ bool "Disable TCP Simultaneous Connect"
68924+ default y if GRKERNSEC_CONFIG_AUTO
68925+ depends on NET
68926+ help
68927+ If you say Y here, a feature by Willy Tarreau will be enabled that
68928+ removes a weakness in Linux's strict implementation of TCP that
68929+ allows two clients to connect to each other without either entering
68930+ a listening state. The weakness allows an attacker to easily prevent
68931+ a client from connecting to a known server provided the source port
68932+ for the connection is guessed correctly.
68933+
68934+ As the weakness could be used to prevent an antivirus or IPS from
68935+ fetching updates, or prevent an SSL gateway from fetching a CRL,
68936+ it should be eliminated by enabling this option. Though Linux is
68937+ one of few operating systems supporting simultaneous connect, it
68938+ has no legitimate use in practice and is rarely supported by firewalls.
68939+
68940+config GRKERNSEC_SOCKET
68941+ bool "Socket restrictions"
68942+ depends on NET
68943+ help
68944+ If you say Y here, you will be able to choose from several options.
68945+ If you assign a GID on your system and add it to the supplementary
68946+ groups of users you want to restrict socket access to, this patch
68947+ will perform up to three things, based on the option(s) you choose.
68948+
68949+config GRKERNSEC_SOCKET_ALL
68950+ bool "Deny any sockets to group"
68951+ depends on GRKERNSEC_SOCKET
68952+ help
68953+ If you say Y here, you will be able to choose a GID of whose users will
68954+ be unable to connect to other hosts from your machine or run server
68955+ applications from your machine. If the sysctl option is enabled, a
68956+ sysctl option with name "socket_all" is created.
68957+
68958+config GRKERNSEC_SOCKET_ALL_GID
68959+ int "GID to deny all sockets for"
68960+ depends on GRKERNSEC_SOCKET_ALL
68961+ default 1004
68962+ help
68963+ Here you can choose the GID to disable socket access for. Remember to
68964+ add the users you want socket access disabled for to the GID
68965+ specified here. If the sysctl option is enabled, a sysctl option
68966+ with name "socket_all_gid" is created.
68967+
68968+config GRKERNSEC_SOCKET_CLIENT
68969+ bool "Deny client sockets to group"
68970+ depends on GRKERNSEC_SOCKET
68971+ help
68972+ If you say Y here, you will be able to choose a GID of whose users will
68973+ be unable to connect to other hosts from your machine, but will be
68974+ able to run servers. If this option is enabled, all users in the group
68975+ you specify will have to use passive mode when initiating ftp transfers
68976+ from the shell on your machine. If the sysctl option is enabled, a
68977+ sysctl option with name "socket_client" is created.
68978+
68979+config GRKERNSEC_SOCKET_CLIENT_GID
68980+ int "GID to deny client sockets for"
68981+ depends on GRKERNSEC_SOCKET_CLIENT
68982+ default 1003
68983+ help
68984+ Here you can choose the GID to disable client socket access for.
68985+ Remember to add the users you want client socket access disabled for to
68986+ the GID specified here. If the sysctl option is enabled, a sysctl
68987+ option with name "socket_client_gid" is created.
68988+
68989+config GRKERNSEC_SOCKET_SERVER
68990+ bool "Deny server sockets to group"
68991+ depends on GRKERNSEC_SOCKET
68992+ help
68993+ If you say Y here, you will be able to choose a GID of whose users will
68994+ be unable to run server applications from your machine. If the sysctl
68995+ option is enabled, a sysctl option with name "socket_server" is created.
68996+
68997+config GRKERNSEC_SOCKET_SERVER_GID
68998+ int "GID to deny server sockets for"
68999+ depends on GRKERNSEC_SOCKET_SERVER
69000+ default 1002
69001+ help
69002+ Here you can choose the GID to disable server socket access for.
69003+ Remember to add the users you want server socket access disabled for to
69004+ the GID specified here. If the sysctl option is enabled, a sysctl
69005+ option with name "socket_server_gid" is created.
69006+
69007+endmenu
69008+
69009+menu "Physical Protections"
69010+depends on GRKERNSEC
69011+
69012+config GRKERNSEC_DENYUSB
69013+ bool "Deny new USB connections after toggle"
69014+ default y if GRKERNSEC_CONFIG_AUTO
69015+ depends on SYSCTL && USB_SUPPORT
69016+ help
69017+ If you say Y here, a new sysctl option with name "deny_new_usb"
69018+ will be created. Setting its value to 1 will prevent any new
69019+ USB devices from being recognized by the OS. Any attempted USB
69020+ device insertion will be logged. This option is intended to be
69021+ used against custom USB devices designed to exploit vulnerabilities
69022+ in various USB device drivers.
69023+
69024+ For greatest effectiveness, this sysctl should be set after any
69025+ relevant init scripts. This option is safe to enable in distros
69026+ as each user can choose whether or not to toggle the sysctl.
69027+
69028+config GRKERNSEC_DENYUSB_FORCE
69029+ bool "Reject all USB devices not connected at boot"
69030+ select USB
69031+ depends on GRKERNSEC_DENYUSB
69032+ help
69033+ If you say Y here, a variant of GRKERNSEC_DENYUSB will be enabled
69034+ that doesn't involve a sysctl entry. This option should only be
69035+ enabled if you're sure you want to deny all new USB connections
69036+ at runtime and don't want to modify init scripts. This should not
69037+ be enabled by distros. It forces the core USB code to be built
69038+ into the kernel image so that all devices connected at boot time
69039+ can be recognized and new USB device connections can be prevented
69040+ prior to init running.
69041+
69042+endmenu
69043+
69044+menu "Sysctl Support"
69045+depends on GRKERNSEC && SYSCTL
69046+
69047+config GRKERNSEC_SYSCTL
69048+ bool "Sysctl support"
69049+ default y if GRKERNSEC_CONFIG_AUTO
69050+ help
69051+ If you say Y here, you will be able to change the options that
69052+ grsecurity runs with at bootup, without having to recompile your
69053+ kernel. You can echo values to files in /proc/sys/kernel/grsecurity
69054+ to enable (1) or disable (0) various features. All the sysctl entries
69055+ are mutable until the "grsec_lock" entry is set to a non-zero value.
69056+ All features enabled in the kernel configuration are disabled at boot
69057+ if you do not say Y to the "Turn on features by default" option.
69058+ All options should be set at startup, and the grsec_lock entry should
69059+ be set to a non-zero value after all the options are set.
69060+ *THIS IS EXTREMELY IMPORTANT*
69061+
69062+config GRKERNSEC_SYSCTL_DISTRO
69063+ bool "Extra sysctl support for distro makers (READ HELP)"
69064+ depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
69065+ help
69066+ If you say Y here, additional sysctl options will be created
69067+ for features that affect processes running as root. Therefore,
69068+ it is critical when using this option that the grsec_lock entry be
69069+ enabled after boot. Only distros with prebuilt kernel packages
69070+ with this option enabled that can ensure grsec_lock is enabled
69071+ after boot should use this option.
69072+ *Failure to set grsec_lock after boot makes all grsec features
69073+ this option covers useless*
69074+
69075+ Currently this option creates the following sysctl entries:
69076+ "Disable Privileged I/O": "disable_priv_io"
69077+
69078+config GRKERNSEC_SYSCTL_ON
69079+ bool "Turn on features by default"
69080+ default y if GRKERNSEC_CONFIG_AUTO
69081+ depends on GRKERNSEC_SYSCTL
69082+ help
69083+ If you say Y here, instead of having all features enabled in the
69084+ kernel configuration disabled at boot time, the features will be
69085+ enabled at boot time. It is recommended you say Y here unless
69086+ there is some reason you would want all sysctl-tunable features to
69087+ be disabled by default. As mentioned elsewhere, it is important
69088+ to enable the grsec_lock entry once you have finished modifying
69089+ the sysctl entries.
69090+
69091+endmenu
69092+menu "Logging Options"
69093+depends on GRKERNSEC
69094+
69095+config GRKERNSEC_FLOODTIME
69096+ int "Seconds in between log messages (minimum)"
69097+ default 10
69098+ help
69099+ This option allows you to enforce the number of seconds between
69100+ grsecurity log messages. The default should be suitable for most
69101+ people, however, if you choose to change it, choose a value small enough
69102+ to allow informative logs to be produced, but large enough to
69103+ prevent flooding.
69104+
69105+ Setting both this value and GRKERNSEC_FLOODBURST to 0 will disable
69106+ any rate limiting on grsecurity log messages.
69107+
69108+config GRKERNSEC_FLOODBURST
69109+ int "Number of messages in a burst (maximum)"
69110+ default 6
69111+ help
69112+ This option allows you to choose the maximum number of messages allowed
69113+ within the flood time interval you chose in a separate option. The
69114+ default should be suitable for most people, however if you find that
69115+ many of your logs are being interpreted as flooding, you may want to
69116+ raise this value.
69117+
69118+ Setting both this value and GRKERNSEC_FLOODTIME to 0 will disable
69119+ any rate limiting on grsecurity log messages.
69120+
69121+endmenu
69122diff --git a/grsecurity/Makefile b/grsecurity/Makefile
69123new file mode 100644
69124index 0000000..30ababb
69125--- /dev/null
69126+++ b/grsecurity/Makefile
69127@@ -0,0 +1,54 @@
69128+# grsecurity – access control and security hardening for Linux
69129+# All code in this directory and various hooks located throughout the Linux kernel are
69130+# Copyright (C) 2001-2014 Bradley Spengler, Open Source Security, Inc.
69131+# http://www.grsecurity.net spender@grsecurity.net
69132+#
69133+# This program is free software; you can redistribute it and/or
69134+# modify it under the terms of the GNU General Public License version 2
69135+# as published by the Free Software Foundation.
69136+#
69137+# This program is distributed in the hope that it will be useful,
69138+# but WITHOUT ANY WARRANTY; without even the implied warranty of
69139+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
69140+# GNU General Public License for more details.
69141+#
69142+# You should have received a copy of the GNU General Public License
69143+# along with this program; if not, write to the Free Software
69144+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
69145+
69146+KBUILD_CFLAGS += -Werror
69147+
69148+obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
69149+ grsec_mount.o grsec_sig.o grsec_sysctl.o \
69150+ grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o \
69151+ grsec_usb.o grsec_ipc.o grsec_proc.o
69152+
69153+obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
69154+ gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
69155+ gracl_learn.o grsec_log.o gracl_policy.o
69156+ifdef CONFIG_COMPAT
69157+obj-$(CONFIG_GRKERNSEC) += gracl_compat.o
69158+endif
69159+
69160+obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
69161+
69162+ifdef CONFIG_NET
69163+obj-y += grsec_sock.o
69164+obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
69165+endif
69166+
69167+ifndef CONFIG_GRKERNSEC
69168+obj-y += grsec_disabled.o
69169+endif
69170+
69171+ifdef CONFIG_GRKERNSEC_HIDESYM
69172+extra-y := grsec_hidesym.o
69173+$(obj)/grsec_hidesym.o:
69174+ @-chmod -f 500 /boot
69175+ @-chmod -f 500 /lib/modules
69176+ @-chmod -f 500 /lib64/modules
69177+ @-chmod -f 500 /lib32/modules
69178+ @-chmod -f 700 .
69179+ @-chmod -f 700 $(objtree)
69180+ @echo ' grsec: protected kernel image paths'
69181+endif
69182diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
69183new file mode 100644
69184index 0000000..6ae3aa0
69185--- /dev/null
69186+++ b/grsecurity/gracl.c
69187@@ -0,0 +1,2703 @@
69188+#include <linux/kernel.h>
69189+#include <linux/module.h>
69190+#include <linux/sched.h>
69191+#include <linux/mm.h>
69192+#include <linux/file.h>
69193+#include <linux/fs.h>
69194+#include <linux/namei.h>
69195+#include <linux/mount.h>
69196+#include <linux/tty.h>
69197+#include <linux/proc_fs.h>
69198+#include <linux/lglock.h>
69199+#include <linux/slab.h>
69200+#include <linux/vmalloc.h>
69201+#include <linux/types.h>
69202+#include <linux/sysctl.h>
69203+#include <linux/netdevice.h>
69204+#include <linux/ptrace.h>
69205+#include <linux/gracl.h>
69206+#include <linux/gralloc.h>
69207+#include <linux/security.h>
69208+#include <linux/grinternal.h>
69209+#include <linux/pid_namespace.h>
69210+#include <linux/stop_machine.h>
69211+#include <linux/fdtable.h>
69212+#include <linux/percpu.h>
69213+#include <linux/lglock.h>
69214+#include <linux/hugetlb.h>
69215+#include <linux/posix-timers.h>
69216+#include <linux/prefetch.h>
69217+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
69218+#include <linux/magic.h>
69219+#include <linux/pagemap.h>
69220+#include "../fs/btrfs/async-thread.h"
69221+#include "../fs/btrfs/ctree.h"
69222+#include "../fs/btrfs/btrfs_inode.h"
69223+#endif
69224+#include "../fs/mount.h"
69225+
69226+#include <asm/uaccess.h>
69227+#include <asm/errno.h>
69228+#include <asm/mman.h>
69229+
69230+#define FOR_EACH_ROLE_START(role) \
69231+ role = running_polstate.role_list; \
69232+ while (role) {
69233+
69234+#define FOR_EACH_ROLE_END(role) \
69235+ role = role->prev; \
69236+ }
69237+
69238+extern struct path gr_real_root;
69239+
69240+static struct gr_policy_state running_polstate;
69241+struct gr_policy_state *polstate = &running_polstate;
69242+extern struct gr_alloc_state *current_alloc_state;
69243+
69244+extern char *gr_shared_page[4];
69245+DEFINE_RWLOCK(gr_inode_lock);
69246+
69247+static unsigned int gr_status __read_only = GR_STATUS_INIT;
69248+
69249+#ifdef CONFIG_NET
69250+extern struct vfsmount *sock_mnt;
69251+#endif
69252+
69253+extern struct vfsmount *pipe_mnt;
69254+extern struct vfsmount *shm_mnt;
69255+
69256+#ifdef CONFIG_HUGETLBFS
69257+extern struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
69258+#endif
69259+
69260+extern u16 acl_sp_role_value;
69261+extern struct acl_object_label *fakefs_obj_rw;
69262+extern struct acl_object_label *fakefs_obj_rwx;
69263+
69264+int gr_acl_is_enabled(void)
69265+{
69266+ return (gr_status & GR_READY);
69267+}
69268+
69269+void gr_enable_rbac_system(void)
69270+{
69271+ pax_open_kernel();
69272+ gr_status |= GR_READY;
69273+ pax_close_kernel();
69274+}
69275+
69276+int gr_rbac_disable(void *unused)
69277+{
69278+ pax_open_kernel();
69279+ gr_status &= ~GR_READY;
69280+ pax_close_kernel();
69281+
69282+ return 0;
69283+}
69284+
69285+static inline dev_t __get_dev(const struct dentry *dentry)
69286+{
69287+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
69288+ if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
69289+ return BTRFS_I(dentry->d_inode)->root->anon_dev;
69290+ else
69291+#endif
69292+ return dentry->d_sb->s_dev;
69293+}
69294+
69295+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
69296+{
69297+ return __get_dev(dentry);
69298+}
69299+
69300+static char gr_task_roletype_to_char(struct task_struct *task)
69301+{
69302+ switch (task->role->roletype &
69303+ (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
69304+ GR_ROLE_SPECIAL)) {
69305+ case GR_ROLE_DEFAULT:
69306+ return 'D';
69307+ case GR_ROLE_USER:
69308+ return 'U';
69309+ case GR_ROLE_GROUP:
69310+ return 'G';
69311+ case GR_ROLE_SPECIAL:
69312+ return 'S';
69313+ }
69314+
69315+ return 'X';
69316+}
69317+
69318+char gr_roletype_to_char(void)
69319+{
69320+ return gr_task_roletype_to_char(current);
69321+}
69322+
69323+__inline__ int
69324+gr_acl_tpe_check(void)
69325+{
69326+ if (unlikely(!(gr_status & GR_READY)))
69327+ return 0;
69328+ if (current->role->roletype & GR_ROLE_TPE)
69329+ return 1;
69330+ else
69331+ return 0;
69332+}
69333+
69334+int
69335+gr_handle_rawio(const struct inode *inode)
69336+{
69337+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
69338+ if (inode && (S_ISBLK(inode->i_mode) || (S_ISCHR(inode->i_mode) && imajor(inode) == RAW_MAJOR)) &&
69339+ grsec_enable_chroot_caps && proc_is_chrooted(current) &&
69340+ !capable(CAP_SYS_RAWIO))
69341+ return 1;
69342+#endif
69343+ return 0;
69344+}
69345+
69346+int
69347+gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
69348+{
69349+ if (likely(lena != lenb))
69350+ return 0;
69351+
69352+ return !memcmp(a, b, lena);
69353+}
69354+
69355+static int prepend(char **buffer, int *buflen, const char *str, int namelen)
69356+{
69357+ *buflen -= namelen;
69358+ if (*buflen < 0)
69359+ return -ENAMETOOLONG;
69360+ *buffer -= namelen;
69361+ memcpy(*buffer, str, namelen);
69362+ return 0;
69363+}
69364+
69365+static int prepend_name(char **buffer, int *buflen, struct qstr *name)
69366+{
69367+ return prepend(buffer, buflen, name->name, name->len);
69368+}
69369+
69370+static int prepend_path(const struct path *path, struct path *root,
69371+ char **buffer, int *buflen)
69372+{
69373+ struct dentry *dentry = path->dentry;
69374+ struct vfsmount *vfsmnt = path->mnt;
69375+ struct mount *mnt = real_mount(vfsmnt);
69376+ bool slash = false;
69377+ int error = 0;
69378+
69379+ while (dentry != root->dentry || vfsmnt != root->mnt) {
69380+ struct dentry * parent;
69381+
69382+ if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
69383+ /* Global root? */
69384+ if (!mnt_has_parent(mnt)) {
69385+ goto out;
69386+ }
69387+ dentry = mnt->mnt_mountpoint;
69388+ mnt = mnt->mnt_parent;
69389+ vfsmnt = &mnt->mnt;
69390+ continue;
69391+ }
69392+ parent = dentry->d_parent;
69393+ prefetch(parent);
69394+ spin_lock(&dentry->d_lock);
69395+ error = prepend_name(buffer, buflen, &dentry->d_name);
69396+ spin_unlock(&dentry->d_lock);
69397+ if (!error)
69398+ error = prepend(buffer, buflen, "/", 1);
69399+ if (error)
69400+ break;
69401+
69402+ slash = true;
69403+ dentry = parent;
69404+ }
69405+
69406+out:
69407+ if (!error && !slash)
69408+ error = prepend(buffer, buflen, "/", 1);
69409+
69410+ return error;
69411+}
69412+
69413+/* this must be called with mount_lock and rename_lock held */
69414+
69415+static char *__our_d_path(const struct path *path, struct path *root,
69416+ char *buf, int buflen)
69417+{
69418+ char *res = buf + buflen;
69419+ int error;
69420+
69421+ prepend(&res, &buflen, "\0", 1);
69422+ error = prepend_path(path, root, &res, &buflen);
69423+ if (error)
69424+ return ERR_PTR(error);
69425+
69426+ return res;
69427+}
69428+
69429+static char *
69430+gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
69431+{
69432+ char *retval;
69433+
69434+ retval = __our_d_path(path, root, buf, buflen);
69435+ if (unlikely(IS_ERR(retval)))
69436+ retval = strcpy(buf, "<path too long>");
69437+ else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
69438+ retval[1] = '\0';
69439+
69440+ return retval;
69441+}
69442+
69443+static char *
69444+__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
69445+ char *buf, int buflen)
69446+{
69447+ struct path path;
69448+ char *res;
69449+
69450+ path.dentry = (struct dentry *)dentry;
69451+ path.mnt = (struct vfsmount *)vfsmnt;
69452+
69453+ /* we can use gr_real_root.dentry, gr_real_root.mnt, because this is only called
69454+ by the RBAC system */
69455+ res = gen_full_path(&path, &gr_real_root, buf, buflen);
69456+
69457+ return res;
69458+}
69459+
69460+static char *
69461+d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
69462+ char *buf, int buflen)
69463+{
69464+ char *res;
69465+ struct path path;
69466+ struct path root;
69467+ struct task_struct *reaper = init_pid_ns.child_reaper;
69468+
69469+ path.dentry = (struct dentry *)dentry;
69470+ path.mnt = (struct vfsmount *)vfsmnt;
69471+
69472+ /* we can't use gr_real_root.dentry, gr_real_root.mnt, because they belong only to the RBAC system */
69473+ get_fs_root(reaper->fs, &root);
69474+
69475+ read_seqlock_excl(&mount_lock);
69476+ write_seqlock(&rename_lock);
69477+ res = gen_full_path(&path, &root, buf, buflen);
69478+ write_sequnlock(&rename_lock);
69479+ read_sequnlock_excl(&mount_lock);
69480+
69481+ path_put(&root);
69482+ return res;
69483+}
69484+
69485+char *
69486+gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
69487+{
69488+ char *ret;
69489+ read_seqlock_excl(&mount_lock);
69490+ write_seqlock(&rename_lock);
69491+ ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
69492+ PAGE_SIZE);
69493+ write_sequnlock(&rename_lock);
69494+ read_sequnlock_excl(&mount_lock);
69495+ return ret;
69496+}
69497+
69498+static char *
69499+gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
69500+{
69501+ char *ret;
69502+ char *buf;
69503+ int buflen;
69504+
69505+ read_seqlock_excl(&mount_lock);
69506+ write_seqlock(&rename_lock);
69507+ buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
69508+ ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
69509+ buflen = (int)(ret - buf);
69510+ if (buflen >= 5)
69511+ prepend(&ret, &buflen, "/proc", 5);
69512+ else
69513+ ret = strcpy(buf, "<path too long>");
69514+ write_sequnlock(&rename_lock);
69515+ read_sequnlock_excl(&mount_lock);
69516+ return ret;
69517+}
69518+
69519+char *
69520+gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
69521+{
69522+ return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
69523+ PAGE_SIZE);
69524+}
69525+
69526+char *
69527+gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
69528+{
69529+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
69530+ PAGE_SIZE);
69531+}
69532+
69533+char *
69534+gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
69535+{
69536+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
69537+ PAGE_SIZE);
69538+}
69539+
69540+char *
69541+gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
69542+{
69543+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
69544+ PAGE_SIZE);
69545+}
69546+
69547+char *
69548+gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
69549+{
69550+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
69551+ PAGE_SIZE);
69552+}
69553+
69554+__inline__ __u32
69555+to_gr_audit(const __u32 reqmode)
69556+{
69557+ /* masks off auditable permission flags, then shifts them to create
69558+ auditing flags, and adds the special case of append auditing if
69559+ we're requesting write */
69560+ return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
69561+}
69562+
69563+struct acl_role_label *
69564+__lookup_acl_role_label(const struct gr_policy_state *state, const struct task_struct *task, const uid_t uid,
69565+ const gid_t gid)
69566+{
69567+ unsigned int index = gr_rhash(uid, GR_ROLE_USER, state->acl_role_set.r_size);
69568+ struct acl_role_label *match;
69569+ struct role_allowed_ip *ipp;
69570+ unsigned int x;
69571+ u32 curr_ip = task->signal->saved_ip;
69572+
69573+ match = state->acl_role_set.r_hash[index];
69574+
69575+ while (match) {
69576+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
69577+ for (x = 0; x < match->domain_child_num; x++) {
69578+ if (match->domain_children[x] == uid)
69579+ goto found;
69580+ }
69581+ } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
69582+ break;
69583+ match = match->next;
69584+ }
69585+found:
69586+ if (match == NULL) {
69587+ try_group:
69588+ index = gr_rhash(gid, GR_ROLE_GROUP, state->acl_role_set.r_size);
69589+ match = state->acl_role_set.r_hash[index];
69590+
69591+ while (match) {
69592+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
69593+ for (x = 0; x < match->domain_child_num; x++) {
69594+ if (match->domain_children[x] == gid)
69595+ goto found2;
69596+ }
69597+ } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
69598+ break;
69599+ match = match->next;
69600+ }
69601+found2:
69602+ if (match == NULL)
69603+ match = state->default_role;
69604+ if (match->allowed_ips == NULL)
69605+ return match;
69606+ else {
69607+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
69608+ if (likely
69609+ ((ntohl(curr_ip) & ipp->netmask) ==
69610+ (ntohl(ipp->addr) & ipp->netmask)))
69611+ return match;
69612+ }
69613+ match = state->default_role;
69614+ }
69615+ } else if (match->allowed_ips == NULL) {
69616+ return match;
69617+ } else {
69618+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
69619+ if (likely
69620+ ((ntohl(curr_ip) & ipp->netmask) ==
69621+ (ntohl(ipp->addr) & ipp->netmask)))
69622+ return match;
69623+ }
69624+ goto try_group;
69625+ }
69626+
69627+ return match;
69628+}
69629+
69630+static struct acl_role_label *
69631+lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
69632+ const gid_t gid)
69633+{
69634+ return __lookup_acl_role_label(&running_polstate, task, uid, gid);
69635+}
69636+
69637+struct acl_subject_label *
69638+lookup_acl_subj_label(const ino_t ino, const dev_t dev,
69639+ const struct acl_role_label *role)
69640+{
69641+ unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
69642+ struct acl_subject_label *match;
69643+
69644+ match = role->subj_hash[index];
69645+
69646+ while (match && (match->inode != ino || match->device != dev ||
69647+ (match->mode & GR_DELETED))) {
69648+ match = match->next;
69649+ }
69650+
69651+ if (match && !(match->mode & GR_DELETED))
69652+ return match;
69653+ else
69654+ return NULL;
69655+}
69656+
69657+struct acl_subject_label *
69658+lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
69659+ const struct acl_role_label *role)
69660+{
69661+ unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
69662+ struct acl_subject_label *match;
69663+
69664+ match = role->subj_hash[index];
69665+
69666+ while (match && (match->inode != ino || match->device != dev ||
69667+ !(match->mode & GR_DELETED))) {
69668+ match = match->next;
69669+ }
69670+
69671+ if (match && (match->mode & GR_DELETED))
69672+ return match;
69673+ else
69674+ return NULL;
69675+}
69676+
69677+static struct acl_object_label *
69678+lookup_acl_obj_label(const ino_t ino, const dev_t dev,
69679+ const struct acl_subject_label *subj)
69680+{
69681+ unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
69682+ struct acl_object_label *match;
69683+
69684+ match = subj->obj_hash[index];
69685+
69686+ while (match && (match->inode != ino || match->device != dev ||
69687+ (match->mode & GR_DELETED))) {
69688+ match = match->next;
69689+ }
69690+
69691+ if (match && !(match->mode & GR_DELETED))
69692+ return match;
69693+ else
69694+ return NULL;
69695+}
69696+
69697+static struct acl_object_label *
69698+lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
69699+ const struct acl_subject_label *subj)
69700+{
69701+ unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
69702+ struct acl_object_label *match;
69703+
69704+ match = subj->obj_hash[index];
69705+
69706+ while (match && (match->inode != ino || match->device != dev ||
69707+ !(match->mode & GR_DELETED))) {
69708+ match = match->next;
69709+ }
69710+
69711+ if (match && (match->mode & GR_DELETED))
69712+ return match;
69713+
69714+ match = subj->obj_hash[index];
69715+
69716+ while (match && (match->inode != ino || match->device != dev ||
69717+ (match->mode & GR_DELETED))) {
69718+ match = match->next;
69719+ }
69720+
69721+ if (match && !(match->mode & GR_DELETED))
69722+ return match;
69723+ else
69724+ return NULL;
69725+}
69726+
69727+struct name_entry *
69728+__lookup_name_entry(const struct gr_policy_state *state, const char *name)
69729+{
69730+ unsigned int len = strlen(name);
69731+ unsigned int key = full_name_hash(name, len);
69732+ unsigned int index = key % state->name_set.n_size;
69733+ struct name_entry *match;
69734+
69735+ match = state->name_set.n_hash[index];
69736+
69737+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
69738+ match = match->next;
69739+
69740+ return match;
69741+}
69742+
69743+static struct name_entry *
69744+lookup_name_entry(const char *name)
69745+{
69746+ return __lookup_name_entry(&running_polstate, name);
69747+}
69748+
69749+static struct name_entry *
69750+lookup_name_entry_create(const char *name)
69751+{
69752+ unsigned int len = strlen(name);
69753+ unsigned int key = full_name_hash(name, len);
69754+ unsigned int index = key % running_polstate.name_set.n_size;
69755+ struct name_entry *match;
69756+
69757+ match = running_polstate.name_set.n_hash[index];
69758+
69759+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
69760+ !match->deleted))
69761+ match = match->next;
69762+
69763+ if (match && match->deleted)
69764+ return match;
69765+
69766+ match = running_polstate.name_set.n_hash[index];
69767+
69768+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
69769+ match->deleted))
69770+ match = match->next;
69771+
69772+ if (match && !match->deleted)
69773+ return match;
69774+ else
69775+ return NULL;
69776+}
69777+
69778+static struct inodev_entry *
69779+lookup_inodev_entry(const ino_t ino, const dev_t dev)
69780+{
69781+ unsigned int index = gr_fhash(ino, dev, running_polstate.inodev_set.i_size);
69782+ struct inodev_entry *match;
69783+
69784+ match = running_polstate.inodev_set.i_hash[index];
69785+
69786+ while (match && (match->nentry->inode != ino || match->nentry->device != dev))
69787+ match = match->next;
69788+
69789+ return match;
69790+}
69791+
69792+void
69793+__insert_inodev_entry(const struct gr_policy_state *state, struct inodev_entry *entry)
69794+{
69795+ unsigned int index = gr_fhash(entry->nentry->inode, entry->nentry->device,
69796+ state->inodev_set.i_size);
69797+ struct inodev_entry **curr;
69798+
69799+ entry->prev = NULL;
69800+
69801+ curr = &state->inodev_set.i_hash[index];
69802+ if (*curr != NULL)
69803+ (*curr)->prev = entry;
69804+
69805+ entry->next = *curr;
69806+ *curr = entry;
69807+
69808+ return;
69809+}
69810+
69811+static void
69812+insert_inodev_entry(struct inodev_entry *entry)
69813+{
69814+ __insert_inodev_entry(&running_polstate, entry);
69815+}
69816+
69817+void
69818+insert_acl_obj_label(struct acl_object_label *obj,
69819+ struct acl_subject_label *subj)
69820+{
69821+ unsigned int index =
69822+ gr_fhash(obj->inode, obj->device, subj->obj_hash_size);
69823+ struct acl_object_label **curr;
69824+
69825+ obj->prev = NULL;
69826+
69827+ curr = &subj->obj_hash[index];
69828+ if (*curr != NULL)
69829+ (*curr)->prev = obj;
69830+
69831+ obj->next = *curr;
69832+ *curr = obj;
69833+
69834+ return;
69835+}
69836+
69837+void
69838+insert_acl_subj_label(struct acl_subject_label *obj,
69839+ struct acl_role_label *role)
69840+{
69841+ unsigned int index = gr_fhash(obj->inode, obj->device, role->subj_hash_size);
69842+ struct acl_subject_label **curr;
69843+
69844+ obj->prev = NULL;
69845+
69846+ curr = &role->subj_hash[index];
69847+ if (*curr != NULL)
69848+ (*curr)->prev = obj;
69849+
69850+ obj->next = *curr;
69851+ *curr = obj;
69852+
69853+ return;
69854+}
69855+
69856+/* derived from glibc fnmatch() 0: match, 1: no match*/
69857+
69858+static int
69859+glob_match(const char *p, const char *n)
69860+{
69861+ char c;
69862+
69863+ while ((c = *p++) != '\0') {
69864+ switch (c) {
69865+ case '?':
69866+ if (*n == '\0')
69867+ return 1;
69868+ else if (*n == '/')
69869+ return 1;
69870+ break;
69871+ case '\\':
69872+ if (*n != c)
69873+ return 1;
69874+ break;
69875+ case '*':
69876+ for (c = *p++; c == '?' || c == '*'; c = *p++) {
69877+ if (*n == '/')
69878+ return 1;
69879+ else if (c == '?') {
69880+ if (*n == '\0')
69881+ return 1;
69882+ else
69883+ ++n;
69884+ }
69885+ }
69886+ if (c == '\0') {
69887+ return 0;
69888+ } else {
69889+ const char *endp;
69890+
69891+ if ((endp = strchr(n, '/')) == NULL)
69892+ endp = n + strlen(n);
69893+
69894+ if (c == '[') {
69895+ for (--p; n < endp; ++n)
69896+ if (!glob_match(p, n))
69897+ return 0;
69898+ } else if (c == '/') {
69899+ while (*n != '\0' && *n != '/')
69900+ ++n;
69901+ if (*n == '/' && !glob_match(p, n + 1))
69902+ return 0;
69903+ } else {
69904+ for (--p; n < endp; ++n)
69905+ if (*n == c && !glob_match(p, n))
69906+ return 0;
69907+ }
69908+
69909+ return 1;
69910+ }
69911+ case '[':
69912+ {
69913+ int not;
69914+ char cold;
69915+
69916+ if (*n == '\0' || *n == '/')
69917+ return 1;
69918+
69919+ not = (*p == '!' || *p == '^');
69920+ if (not)
69921+ ++p;
69922+
69923+ c = *p++;
69924+ for (;;) {
69925+ unsigned char fn = (unsigned char)*n;
69926+
69927+ if (c == '\0')
69928+ return 1;
69929+ else {
69930+ if (c == fn)
69931+ goto matched;
69932+ cold = c;
69933+ c = *p++;
69934+
69935+ if (c == '-' && *p != ']') {
69936+ unsigned char cend = *p++;
69937+
69938+ if (cend == '\0')
69939+ return 1;
69940+
69941+ if (cold <= fn && fn <= cend)
69942+ goto matched;
69943+
69944+ c = *p++;
69945+ }
69946+ }
69947+
69948+ if (c == ']')
69949+ break;
69950+ }
69951+ if (!not)
69952+ return 1;
69953+ break;
69954+ matched:
69955+ while (c != ']') {
69956+ if (c == '\0')
69957+ return 1;
69958+
69959+ c = *p++;
69960+ }
69961+ if (not)
69962+ return 1;
69963+ }
69964+ break;
69965+ default:
69966+ if (c != *n)
69967+ return 1;
69968+ }
69969+
69970+ ++n;
69971+ }
69972+
69973+ if (*n == '\0')
69974+ return 0;
69975+
69976+ if (*n == '/')
69977+ return 0;
69978+
69979+ return 1;
69980+}
69981+
69982+static struct acl_object_label *
69983+chk_glob_label(struct acl_object_label *globbed,
69984+ const struct dentry *dentry, const struct vfsmount *mnt, char **path)
69985+{
69986+ struct acl_object_label *tmp;
69987+
69988+ if (*path == NULL)
69989+ *path = gr_to_filename_nolock(dentry, mnt);
69990+
69991+ tmp = globbed;
69992+
69993+ while (tmp) {
69994+ if (!glob_match(tmp->filename, *path))
69995+ return tmp;
69996+ tmp = tmp->next;
69997+ }
69998+
69999+ return NULL;
70000+}
70001+
70002+static struct acl_object_label *
70003+__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
70004+ const ino_t curr_ino, const dev_t curr_dev,
70005+ const struct acl_subject_label *subj, char **path, const int checkglob)
70006+{
70007+ struct acl_subject_label *tmpsubj;
70008+ struct acl_object_label *retval;
70009+ struct acl_object_label *retval2;
70010+
70011+ tmpsubj = (struct acl_subject_label *) subj;
70012+ read_lock(&gr_inode_lock);
70013+ do {
70014+ retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
70015+ if (retval) {
70016+ if (checkglob && retval->globbed) {
70017+ retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
70018+ if (retval2)
70019+ retval = retval2;
70020+ }
70021+ break;
70022+ }
70023+ } while ((tmpsubj = tmpsubj->parent_subject));
70024+ read_unlock(&gr_inode_lock);
70025+
70026+ return retval;
70027+}
70028+
70029+static __inline__ struct acl_object_label *
70030+full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
70031+ struct dentry *curr_dentry,
70032+ const struct acl_subject_label *subj, char **path, const int checkglob)
70033+{
70034+ int newglob = checkglob;
70035+ ino_t inode;
70036+ dev_t device;
70037+
70038+ /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
70039+ as we don't want a / * rule to match instead of the / object
70040+ don't do this for create lookups that call this function though, since they're looking up
70041+ on the parent and thus need globbing checks on all paths
70042+ */
70043+ if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
70044+ newglob = GR_NO_GLOB;
70045+
70046+ spin_lock(&curr_dentry->d_lock);
70047+ inode = curr_dentry->d_inode->i_ino;
70048+ device = __get_dev(curr_dentry);
70049+ spin_unlock(&curr_dentry->d_lock);
70050+
70051+ return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
70052+}
70053+
70054+#ifdef CONFIG_HUGETLBFS
70055+static inline bool
70056+is_hugetlbfs_mnt(const struct vfsmount *mnt)
70057+{
70058+ int i;
70059+ for (i = 0; i < HUGE_MAX_HSTATE; i++) {
70060+ if (unlikely(hugetlbfs_vfsmount[i] == mnt))
70061+ return true;
70062+ }
70063+
70064+ return false;
70065+}
70066+#endif
70067+
70068+static struct acl_object_label *
70069+__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
70070+ const struct acl_subject_label *subj, char *path, const int checkglob)
70071+{
70072+ struct dentry *dentry = (struct dentry *) l_dentry;
70073+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
70074+ struct mount *real_mnt = real_mount(mnt);
70075+ struct acl_object_label *retval;
70076+ struct dentry *parent;
70077+
70078+ read_seqlock_excl(&mount_lock);
70079+ write_seqlock(&rename_lock);
70080+
70081+ if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
70082+#ifdef CONFIG_NET
70083+ mnt == sock_mnt ||
70084+#endif
70085+#ifdef CONFIG_HUGETLBFS
70086+ (is_hugetlbfs_mnt(mnt) && dentry->d_inode->i_nlink == 0) ||
70087+#endif
70088+ /* ignore Eric Biederman */
70089+ IS_PRIVATE(l_dentry->d_inode))) {
70090+ retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
70091+ goto out;
70092+ }
70093+
70094+ for (;;) {
70095+ if (dentry == gr_real_root.dentry && mnt == gr_real_root.mnt)
70096+ break;
70097+
70098+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
70099+ if (!mnt_has_parent(real_mnt))
70100+ break;
70101+
70102+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
70103+ if (retval != NULL)
70104+ goto out;
70105+
70106+ dentry = real_mnt->mnt_mountpoint;
70107+ real_mnt = real_mnt->mnt_parent;
70108+ mnt = &real_mnt->mnt;
70109+ continue;
70110+ }
70111+
70112+ parent = dentry->d_parent;
70113+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
70114+ if (retval != NULL)
70115+ goto out;
70116+
70117+ dentry = parent;
70118+ }
70119+
70120+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
70121+
70122+ /* gr_real_root is pinned so we don't have to hold a reference */
70123+ if (retval == NULL)
70124+ retval = full_lookup(l_dentry, l_mnt, gr_real_root.dentry, subj, &path, checkglob);
70125+out:
70126+ write_sequnlock(&rename_lock);
70127+ read_sequnlock_excl(&mount_lock);
70128+
70129+ BUG_ON(retval == NULL);
70130+
70131+ return retval;
70132+}
70133+
70134+static __inline__ struct acl_object_label *
70135+chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
70136+ const struct acl_subject_label *subj)
70137+{
70138+ char *path = NULL;
70139+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
70140+}
70141+
70142+static __inline__ struct acl_object_label *
70143+chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
70144+ const struct acl_subject_label *subj)
70145+{
70146+ char *path = NULL;
70147+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
70148+}
70149+
70150+static __inline__ struct acl_object_label *
70151+chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
70152+ const struct acl_subject_label *subj, char *path)
70153+{
70154+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
70155+}
70156+
70157+struct acl_subject_label *
70158+chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
70159+ const struct acl_role_label *role)
70160+{
70161+ struct dentry *dentry = (struct dentry *) l_dentry;
70162+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
70163+ struct mount *real_mnt = real_mount(mnt);
70164+ struct acl_subject_label *retval;
70165+ struct dentry *parent;
70166+
70167+ read_seqlock_excl(&mount_lock);
70168+ write_seqlock(&rename_lock);
70169+
70170+ for (;;) {
70171+ if (dentry == gr_real_root.dentry && mnt == gr_real_root.mnt)
70172+ break;
70173+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
70174+ if (!mnt_has_parent(real_mnt))
70175+ break;
70176+
70177+ spin_lock(&dentry->d_lock);
70178+ read_lock(&gr_inode_lock);
70179+ retval =
70180+ lookup_acl_subj_label(dentry->d_inode->i_ino,
70181+ __get_dev(dentry), role);
70182+ read_unlock(&gr_inode_lock);
70183+ spin_unlock(&dentry->d_lock);
70184+ if (retval != NULL)
70185+ goto out;
70186+
70187+ dentry = real_mnt->mnt_mountpoint;
70188+ real_mnt = real_mnt->mnt_parent;
70189+ mnt = &real_mnt->mnt;
70190+ continue;
70191+ }
70192+
70193+ spin_lock(&dentry->d_lock);
70194+ read_lock(&gr_inode_lock);
70195+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
70196+ __get_dev(dentry), role);
70197+ read_unlock(&gr_inode_lock);
70198+ parent = dentry->d_parent;
70199+ spin_unlock(&dentry->d_lock);
70200+
70201+ if (retval != NULL)
70202+ goto out;
70203+
70204+ dentry = parent;
70205+ }
70206+
70207+ spin_lock(&dentry->d_lock);
70208+ read_lock(&gr_inode_lock);
70209+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
70210+ __get_dev(dentry), role);
70211+ read_unlock(&gr_inode_lock);
70212+ spin_unlock(&dentry->d_lock);
70213+
70214+ if (unlikely(retval == NULL)) {
70215+ /* gr_real_root is pinned, we don't need to hold a reference */
70216+ read_lock(&gr_inode_lock);
70217+ retval = lookup_acl_subj_label(gr_real_root.dentry->d_inode->i_ino,
70218+ __get_dev(gr_real_root.dentry), role);
70219+ read_unlock(&gr_inode_lock);
70220+ }
70221+out:
70222+ write_sequnlock(&rename_lock);
70223+ read_sequnlock_excl(&mount_lock);
70224+
70225+ BUG_ON(retval == NULL);
70226+
70227+ return retval;
70228+}
70229+
70230+void
70231+assign_special_role(const char *rolename)
70232+{
70233+ struct acl_object_label *obj;
70234+ struct acl_role_label *r;
70235+ struct acl_role_label *assigned = NULL;
70236+ struct task_struct *tsk;
70237+ struct file *filp;
70238+
70239+ FOR_EACH_ROLE_START(r)
70240+ if (!strcmp(rolename, r->rolename) &&
70241+ (r->roletype & GR_ROLE_SPECIAL)) {
70242+ assigned = r;
70243+ break;
70244+ }
70245+ FOR_EACH_ROLE_END(r)
70246+
70247+ if (!assigned)
70248+ return;
70249+
70250+ read_lock(&tasklist_lock);
70251+ read_lock(&grsec_exec_file_lock);
70252+
70253+ tsk = current->real_parent;
70254+ if (tsk == NULL)
70255+ goto out_unlock;
70256+
70257+ filp = tsk->exec_file;
70258+ if (filp == NULL)
70259+ goto out_unlock;
70260+
70261+ tsk->is_writable = 0;
70262+ tsk->inherited = 0;
70263+
70264+ tsk->acl_sp_role = 1;
70265+ tsk->acl_role_id = ++acl_sp_role_value;
70266+ tsk->role = assigned;
70267+ tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
70268+
70269+ /* ignore additional mmap checks for processes that are writable
70270+ by the default ACL */
70271+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
70272+ if (unlikely(obj->mode & GR_WRITE))
70273+ tsk->is_writable = 1;
70274+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
70275+ if (unlikely(obj->mode & GR_WRITE))
70276+ tsk->is_writable = 1;
70277+
70278+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
70279+ printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename,
70280+ tsk->acl->filename, tsk->comm, task_pid_nr(tsk));
70281+#endif
70282+
70283+out_unlock:
70284+ read_unlock(&grsec_exec_file_lock);
70285+ read_unlock(&tasklist_lock);
70286+ return;
70287+}
70288+
70289+
70290+static void
70291+gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
70292+{
70293+ struct task_struct *task = current;
70294+ const struct cred *cred = current_cred();
70295+
70296+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
70297+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
70298+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
70299+ 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
70300+
70301+ return;
70302+}
70303+
70304+static void
70305+gr_log_learn_uid_change(const kuid_t real, const kuid_t effective, const kuid_t fs)
70306+{
70307+ struct task_struct *task = current;
70308+ const struct cred *cred = current_cred();
70309+
70310+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
70311+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
70312+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
70313+ 'u', GR_GLOBAL_UID(real), GR_GLOBAL_UID(effective), GR_GLOBAL_UID(fs), &task->signal->saved_ip);
70314+
70315+ return;
70316+}
70317+
70318+static void
70319+gr_log_learn_gid_change(const kgid_t real, const kgid_t effective, const kgid_t fs)
70320+{
70321+ struct task_struct *task = current;
70322+ const struct cred *cred = current_cred();
70323+
70324+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
70325+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
70326+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
70327+ 'g', GR_GLOBAL_GID(real), GR_GLOBAL_GID(effective), GR_GLOBAL_GID(fs), &task->signal->saved_ip);
70328+
70329+ return;
70330+}
70331+
70332+static void
70333+gr_set_proc_res(struct task_struct *task)
70334+{
70335+ struct acl_subject_label *proc;
70336+ unsigned short i;
70337+
70338+ proc = task->acl;
70339+
70340+ if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
70341+ return;
70342+
70343+ for (i = 0; i < RLIM_NLIMITS; i++) {
70344+ if (!(proc->resmask & (1U << i)))
70345+ continue;
70346+
70347+ task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
70348+ task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
70349+
70350+ if (i == RLIMIT_CPU)
70351+ update_rlimit_cpu(task, proc->res[i].rlim_cur);
70352+ }
70353+
70354+ return;
70355+}
70356+
70357+/* both of the below must be called with
70358+ rcu_read_lock();
70359+ read_lock(&tasklist_lock);
70360+ read_lock(&grsec_exec_file_lock);
70361+*/
70362+
70363+struct acl_subject_label *__gr_get_subject_for_task(const struct gr_policy_state *state, struct task_struct *task, const char *filename)
70364+{
70365+ char *tmpname;
70366+ struct acl_subject_label *tmpsubj;
70367+ struct file *filp;
70368+ struct name_entry *nmatch;
70369+
70370+ filp = task->exec_file;
70371+ if (filp == NULL)
70372+ return NULL;
70373+
70374+ /* the following is to apply the correct subject
70375+ on binaries running when the RBAC system
70376+ is enabled, when the binaries have been
70377+ replaced or deleted since their execution
70378+ -----
70379+ when the RBAC system starts, the inode/dev
70380+ from exec_file will be one the RBAC system
70381+ is unaware of. It only knows the inode/dev
70382+ of the present file on disk, or the absence
70383+ of it.
70384+ */
70385+
70386+ if (filename)
70387+ nmatch = __lookup_name_entry(state, filename);
70388+ else {
70389+ preempt_disable();
70390+ tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
70391+
70392+ nmatch = __lookup_name_entry(state, tmpname);
70393+ preempt_enable();
70394+ }
70395+ tmpsubj = NULL;
70396+ if (nmatch) {
70397+ if (nmatch->deleted)
70398+ tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
70399+ else
70400+ tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
70401+ }
70402+ /* this also works for the reload case -- if we don't match a potentially inherited subject
70403+ then we fall back to a normal lookup based on the binary's ino/dev
70404+ */
70405+ if (tmpsubj == NULL)
70406+ tmpsubj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, task->role);
70407+
70408+ return tmpsubj;
70409+}
70410+
70411+static struct acl_subject_label *gr_get_subject_for_task(struct task_struct *task, const char *filename)
70412+{
70413+ return __gr_get_subject_for_task(&running_polstate, task, filename);
70414+}
70415+
70416+void __gr_apply_subject_to_task(const struct gr_policy_state *state, struct task_struct *task, struct acl_subject_label *subj)
70417+{
70418+ struct acl_object_label *obj;
70419+ struct file *filp;
70420+
70421+ filp = task->exec_file;
70422+
70423+ task->acl = subj;
70424+ task->is_writable = 0;
70425+ /* ignore additional mmap checks for processes that are writable
70426+ by the default ACL */
70427+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, state->default_role->root_label);
70428+ if (unlikely(obj->mode & GR_WRITE))
70429+ task->is_writable = 1;
70430+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
70431+ if (unlikely(obj->mode & GR_WRITE))
70432+ task->is_writable = 1;
70433+
70434+ gr_set_proc_res(task);
70435+
70436+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
70437+ 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);
70438+#endif
70439+}
70440+
70441+static void gr_apply_subject_to_task(struct task_struct *task, struct acl_subject_label *subj)
70442+{
70443+ __gr_apply_subject_to_task(&running_polstate, task, subj);
70444+}
70445+
70446+__u32
70447+gr_search_file(const struct dentry * dentry, const __u32 mode,
70448+ const struct vfsmount * mnt)
70449+{
70450+ __u32 retval = mode;
70451+ struct acl_subject_label *curracl;
70452+ struct acl_object_label *currobj;
70453+
70454+ if (unlikely(!(gr_status & GR_READY)))
70455+ return (mode & ~GR_AUDITS);
70456+
70457+ curracl = current->acl;
70458+
70459+ currobj = chk_obj_label(dentry, mnt, curracl);
70460+ retval = currobj->mode & mode;
70461+
70462+ /* if we're opening a specified transfer file for writing
70463+ (e.g. /dev/initctl), then transfer our role to init
70464+ */
70465+ if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
70466+ current->role->roletype & GR_ROLE_PERSIST)) {
70467+ struct task_struct *task = init_pid_ns.child_reaper;
70468+
70469+ if (task->role != current->role) {
70470+ struct acl_subject_label *subj;
70471+
70472+ task->acl_sp_role = 0;
70473+ task->acl_role_id = current->acl_role_id;
70474+ task->role = current->role;
70475+ rcu_read_lock();
70476+ read_lock(&grsec_exec_file_lock);
70477+ subj = gr_get_subject_for_task(task, NULL);
70478+ gr_apply_subject_to_task(task, subj);
70479+ read_unlock(&grsec_exec_file_lock);
70480+ rcu_read_unlock();
70481+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
70482+ }
70483+ }
70484+
70485+ if (unlikely
70486+ ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
70487+ && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
70488+ __u32 new_mode = mode;
70489+
70490+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
70491+
70492+ retval = new_mode;
70493+
70494+ if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
70495+ new_mode |= GR_INHERIT;
70496+
70497+ if (!(mode & GR_NOLEARN))
70498+ gr_log_learn(dentry, mnt, new_mode);
70499+ }
70500+
70501+ return retval;
70502+}
70503+
70504+struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
70505+ const struct dentry *parent,
70506+ const struct vfsmount *mnt)
70507+{
70508+ struct name_entry *match;
70509+ struct acl_object_label *matchpo;
70510+ struct acl_subject_label *curracl;
70511+ char *path;
70512+
70513+ if (unlikely(!(gr_status & GR_READY)))
70514+ return NULL;
70515+
70516+ preempt_disable();
70517+ path = gr_to_filename_rbac(new_dentry, mnt);
70518+ match = lookup_name_entry_create(path);
70519+
70520+ curracl = current->acl;
70521+
70522+ if (match) {
70523+ read_lock(&gr_inode_lock);
70524+ matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
70525+ read_unlock(&gr_inode_lock);
70526+
70527+ if (matchpo) {
70528+ preempt_enable();
70529+ return matchpo;
70530+ }
70531+ }
70532+
70533+ // lookup parent
70534+
70535+ matchpo = chk_obj_create_label(parent, mnt, curracl, path);
70536+
70537+ preempt_enable();
70538+ return matchpo;
70539+}
70540+
70541+__u32
70542+gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
70543+ const struct vfsmount * mnt, const __u32 mode)
70544+{
70545+ struct acl_object_label *matchpo;
70546+ __u32 retval;
70547+
70548+ if (unlikely(!(gr_status & GR_READY)))
70549+ return (mode & ~GR_AUDITS);
70550+
70551+ matchpo = gr_get_create_object(new_dentry, parent, mnt);
70552+
70553+ retval = matchpo->mode & mode;
70554+
70555+ if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
70556+ && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
70557+ __u32 new_mode = mode;
70558+
70559+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
70560+
70561+ gr_log_learn(new_dentry, mnt, new_mode);
70562+ return new_mode;
70563+ }
70564+
70565+ return retval;
70566+}
70567+
70568+__u32
70569+gr_check_link(const struct dentry * new_dentry,
70570+ const struct dentry * parent_dentry,
70571+ const struct vfsmount * parent_mnt,
70572+ const struct dentry * old_dentry, const struct vfsmount * old_mnt)
70573+{
70574+ struct acl_object_label *obj;
70575+ __u32 oldmode, newmode;
70576+ __u32 needmode;
70577+ __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
70578+ GR_DELETE | GR_INHERIT;
70579+
70580+ if (unlikely(!(gr_status & GR_READY)))
70581+ return (GR_CREATE | GR_LINK);
70582+
70583+ obj = chk_obj_label(old_dentry, old_mnt, current->acl);
70584+ oldmode = obj->mode;
70585+
70586+ obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
70587+ newmode = obj->mode;
70588+
70589+ needmode = newmode & checkmodes;
70590+
70591+ // old name for hardlink must have at least the permissions of the new name
70592+ if ((oldmode & needmode) != needmode)
70593+ goto bad;
70594+
70595+ // if old name had restrictions/auditing, make sure the new name does as well
70596+ needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
70597+
70598+ // don't allow hardlinking of suid/sgid/fcapped files without permission
70599+ if (is_privileged_binary(old_dentry))
70600+ needmode |= GR_SETID;
70601+
70602+ if ((newmode & needmode) != needmode)
70603+ goto bad;
70604+
70605+ // enforce minimum permissions
70606+ if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
70607+ return newmode;
70608+bad:
70609+ needmode = oldmode;
70610+ if (is_privileged_binary(old_dentry))
70611+ needmode |= GR_SETID;
70612+
70613+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
70614+ gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
70615+ return (GR_CREATE | GR_LINK);
70616+ } else if (newmode & GR_SUPPRESS)
70617+ return GR_SUPPRESS;
70618+ else
70619+ return 0;
70620+}
70621+
70622+int
70623+gr_check_hidden_task(const struct task_struct *task)
70624+{
70625+ if (unlikely(!(gr_status & GR_READY)))
70626+ return 0;
70627+
70628+ if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
70629+ return 1;
70630+
70631+ return 0;
70632+}
70633+
70634+int
70635+gr_check_protected_task(const struct task_struct *task)
70636+{
70637+ if (unlikely(!(gr_status & GR_READY) || !task))
70638+ return 0;
70639+
70640+ if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
70641+ task->acl != current->acl)
70642+ return 1;
70643+
70644+ return 0;
70645+}
70646+
70647+int
70648+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
70649+{
70650+ struct task_struct *p;
70651+ int ret = 0;
70652+
70653+ if (unlikely(!(gr_status & GR_READY) || !pid))
70654+ return ret;
70655+
70656+ read_lock(&tasklist_lock);
70657+ do_each_pid_task(pid, type, p) {
70658+ if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
70659+ p->acl != current->acl) {
70660+ ret = 1;
70661+ goto out;
70662+ }
70663+ } while_each_pid_task(pid, type, p);
70664+out:
70665+ read_unlock(&tasklist_lock);
70666+
70667+ return ret;
70668+}
70669+
70670+void
70671+gr_copy_label(struct task_struct *tsk)
70672+{
70673+ struct task_struct *p = current;
70674+
70675+ tsk->inherited = p->inherited;
70676+ tsk->acl_sp_role = 0;
70677+ tsk->acl_role_id = p->acl_role_id;
70678+ tsk->acl = p->acl;
70679+ tsk->role = p->role;
70680+ tsk->signal->used_accept = 0;
70681+ tsk->signal->curr_ip = p->signal->curr_ip;
70682+ tsk->signal->saved_ip = p->signal->saved_ip;
70683+ if (p->exec_file)
70684+ get_file(p->exec_file);
70685+ tsk->exec_file = p->exec_file;
70686+ tsk->is_writable = p->is_writable;
70687+ if (unlikely(p->signal->used_accept)) {
70688+ p->signal->curr_ip = 0;
70689+ p->signal->saved_ip = 0;
70690+ }
70691+
70692+ return;
70693+}
70694+
70695+extern int gr_process_kernel_setuid_ban(struct user_struct *user);
70696+
70697+int
70698+gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
70699+{
70700+ unsigned int i;
70701+ __u16 num;
70702+ uid_t *uidlist;
70703+ uid_t curuid;
70704+ int realok = 0;
70705+ int effectiveok = 0;
70706+ int fsok = 0;
70707+ uid_t globalreal, globaleffective, globalfs;
70708+
70709+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT)
70710+ struct user_struct *user;
70711+
70712+ if (!uid_valid(real))
70713+ goto skipit;
70714+
70715+ /* find user based on global namespace */
70716+
70717+ globalreal = GR_GLOBAL_UID(real);
70718+
70719+ user = find_user(make_kuid(&init_user_ns, globalreal));
70720+ if (user == NULL)
70721+ goto skipit;
70722+
70723+ if (gr_process_kernel_setuid_ban(user)) {
70724+ /* for find_user */
70725+ free_uid(user);
70726+ return 1;
70727+ }
70728+
70729+ /* for find_user */
70730+ free_uid(user);
70731+
70732+skipit:
70733+#endif
70734+
70735+ if (unlikely(!(gr_status & GR_READY)))
70736+ return 0;
70737+
70738+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
70739+ gr_log_learn_uid_change(real, effective, fs);
70740+
70741+ num = current->acl->user_trans_num;
70742+ uidlist = current->acl->user_transitions;
70743+
70744+ if (uidlist == NULL)
70745+ return 0;
70746+
70747+ if (!uid_valid(real)) {
70748+ realok = 1;
70749+ globalreal = (uid_t)-1;
70750+ } else {
70751+ globalreal = GR_GLOBAL_UID(real);
70752+ }
70753+ if (!uid_valid(effective)) {
70754+ effectiveok = 1;
70755+ globaleffective = (uid_t)-1;
70756+ } else {
70757+ globaleffective = GR_GLOBAL_UID(effective);
70758+ }
70759+ if (!uid_valid(fs)) {
70760+ fsok = 1;
70761+ globalfs = (uid_t)-1;
70762+ } else {
70763+ globalfs = GR_GLOBAL_UID(fs);
70764+ }
70765+
70766+ if (current->acl->user_trans_type & GR_ID_ALLOW) {
70767+ for (i = 0; i < num; i++) {
70768+ curuid = uidlist[i];
70769+ if (globalreal == curuid)
70770+ realok = 1;
70771+ if (globaleffective == curuid)
70772+ effectiveok = 1;
70773+ if (globalfs == curuid)
70774+ fsok = 1;
70775+ }
70776+ } else if (current->acl->user_trans_type & GR_ID_DENY) {
70777+ for (i = 0; i < num; i++) {
70778+ curuid = uidlist[i];
70779+ if (globalreal == curuid)
70780+ break;
70781+ if (globaleffective == curuid)
70782+ break;
70783+ if (globalfs == curuid)
70784+ break;
70785+ }
70786+ /* not in deny list */
70787+ if (i == num) {
70788+ realok = 1;
70789+ effectiveok = 1;
70790+ fsok = 1;
70791+ }
70792+ }
70793+
70794+ if (realok && effectiveok && fsok)
70795+ return 0;
70796+ else {
70797+ gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
70798+ return 1;
70799+ }
70800+}
70801+
70802+int
70803+gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
70804+{
70805+ unsigned int i;
70806+ __u16 num;
70807+ gid_t *gidlist;
70808+ gid_t curgid;
70809+ int realok = 0;
70810+ int effectiveok = 0;
70811+ int fsok = 0;
70812+ gid_t globalreal, globaleffective, globalfs;
70813+
70814+ if (unlikely(!(gr_status & GR_READY)))
70815+ return 0;
70816+
70817+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
70818+ gr_log_learn_gid_change(real, effective, fs);
70819+
70820+ num = current->acl->group_trans_num;
70821+ gidlist = current->acl->group_transitions;
70822+
70823+ if (gidlist == NULL)
70824+ return 0;
70825+
70826+ if (!gid_valid(real)) {
70827+ realok = 1;
70828+ globalreal = (gid_t)-1;
70829+ } else {
70830+ globalreal = GR_GLOBAL_GID(real);
70831+ }
70832+ if (!gid_valid(effective)) {
70833+ effectiveok = 1;
70834+ globaleffective = (gid_t)-1;
70835+ } else {
70836+ globaleffective = GR_GLOBAL_GID(effective);
70837+ }
70838+ if (!gid_valid(fs)) {
70839+ fsok = 1;
70840+ globalfs = (gid_t)-1;
70841+ } else {
70842+ globalfs = GR_GLOBAL_GID(fs);
70843+ }
70844+
70845+ if (current->acl->group_trans_type & GR_ID_ALLOW) {
70846+ for (i = 0; i < num; i++) {
70847+ curgid = gidlist[i];
70848+ if (globalreal == curgid)
70849+ realok = 1;
70850+ if (globaleffective == curgid)
70851+ effectiveok = 1;
70852+ if (globalfs == curgid)
70853+ fsok = 1;
70854+ }
70855+ } else if (current->acl->group_trans_type & GR_ID_DENY) {
70856+ for (i = 0; i < num; i++) {
70857+ curgid = gidlist[i];
70858+ if (globalreal == curgid)
70859+ break;
70860+ if (globaleffective == curgid)
70861+ break;
70862+ if (globalfs == curgid)
70863+ break;
70864+ }
70865+ /* not in deny list */
70866+ if (i == num) {
70867+ realok = 1;
70868+ effectiveok = 1;
70869+ fsok = 1;
70870+ }
70871+ }
70872+
70873+ if (realok && effectiveok && fsok)
70874+ return 0;
70875+ else {
70876+ gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
70877+ return 1;
70878+ }
70879+}
70880+
70881+extern int gr_acl_is_capable(const int cap);
70882+
70883+void
70884+gr_set_role_label(struct task_struct *task, const kuid_t kuid, const kgid_t kgid)
70885+{
70886+ struct acl_role_label *role = task->role;
70887+ struct acl_subject_label *subj = NULL;
70888+ struct acl_object_label *obj;
70889+ struct file *filp;
70890+ uid_t uid;
70891+ gid_t gid;
70892+
70893+ if (unlikely(!(gr_status & GR_READY)))
70894+ return;
70895+
70896+ uid = GR_GLOBAL_UID(kuid);
70897+ gid = GR_GLOBAL_GID(kgid);
70898+
70899+ filp = task->exec_file;
70900+
70901+ /* kernel process, we'll give them the kernel role */
70902+ if (unlikely(!filp)) {
70903+ task->role = running_polstate.kernel_role;
70904+ task->acl = running_polstate.kernel_role->root_label;
70905+ return;
70906+ } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL)) {
70907+ /* save the current ip at time of role lookup so that the proper
70908+ IP will be learned for role_allowed_ip */
70909+ task->signal->saved_ip = task->signal->curr_ip;
70910+ role = lookup_acl_role_label(task, uid, gid);
70911+ }
70912+
70913+ /* don't change the role if we're not a privileged process */
70914+ if (role && task->role != role &&
70915+ (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
70916+ ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
70917+ return;
70918+
70919+ /* perform subject lookup in possibly new role
70920+ we can use this result below in the case where role == task->role
70921+ */
70922+ subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
70923+
70924+ /* if we changed uid/gid, but result in the same role
70925+ and are using inheritance, don't lose the inherited subject
70926+ if current subject is other than what normal lookup
70927+ would result in, we arrived via inheritance, don't
70928+ lose subject
70929+ */
70930+ if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
70931+ (subj == task->acl)))
70932+ task->acl = subj;
70933+
70934+ /* leave task->inherited unaffected */
70935+
70936+ task->role = role;
70937+
70938+ task->is_writable = 0;
70939+
70940+ /* ignore additional mmap checks for processes that are writable
70941+ by the default ACL */
70942+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
70943+ if (unlikely(obj->mode & GR_WRITE))
70944+ task->is_writable = 1;
70945+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
70946+ if (unlikely(obj->mode & GR_WRITE))
70947+ task->is_writable = 1;
70948+
70949+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
70950+ 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);
70951+#endif
70952+
70953+ gr_set_proc_res(task);
70954+
70955+ return;
70956+}
70957+
70958+int
70959+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
70960+ const int unsafe_flags)
70961+{
70962+ struct task_struct *task = current;
70963+ struct acl_subject_label *newacl;
70964+ struct acl_object_label *obj;
70965+ __u32 retmode;
70966+
70967+ if (unlikely(!(gr_status & GR_READY)))
70968+ return 0;
70969+
70970+ newacl = chk_subj_label(dentry, mnt, task->role);
70971+
70972+ /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
70973+ did an exec
70974+ */
70975+ rcu_read_lock();
70976+ read_lock(&tasklist_lock);
70977+ if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
70978+ (task->parent->acl->mode & GR_POVERRIDE))) {
70979+ read_unlock(&tasklist_lock);
70980+ rcu_read_unlock();
70981+ goto skip_check;
70982+ }
70983+ read_unlock(&tasklist_lock);
70984+ rcu_read_unlock();
70985+
70986+ if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
70987+ !(task->role->roletype & GR_ROLE_GOD) &&
70988+ !gr_search_file(dentry, GR_PTRACERD, mnt) &&
70989+ !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
70990+ if (unsafe_flags & LSM_UNSAFE_SHARE)
70991+ gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
70992+ else
70993+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
70994+ return -EACCES;
70995+ }
70996+
70997+skip_check:
70998+
70999+ obj = chk_obj_label(dentry, mnt, task->acl);
71000+ retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
71001+
71002+ if (!(task->acl->mode & GR_INHERITLEARN) &&
71003+ ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
71004+ if (obj->nested)
71005+ task->acl = obj->nested;
71006+ else
71007+ task->acl = newacl;
71008+ task->inherited = 0;
71009+ } else {
71010+ task->inherited = 1;
71011+ if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
71012+ gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
71013+ }
71014+
71015+ task->is_writable = 0;
71016+
71017+ /* ignore additional mmap checks for processes that are writable
71018+ by the default ACL */
71019+ obj = chk_obj_label(dentry, mnt, running_polstate.default_role->root_label);
71020+ if (unlikely(obj->mode & GR_WRITE))
71021+ task->is_writable = 1;
71022+ obj = chk_obj_label(dentry, mnt, task->role->root_label);
71023+ if (unlikely(obj->mode & GR_WRITE))
71024+ task->is_writable = 1;
71025+
71026+ gr_set_proc_res(task);
71027+
71028+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
71029+ 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);
71030+#endif
71031+ return 0;
71032+}
71033+
71034+/* always called with valid inodev ptr */
71035+static void
71036+do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
71037+{
71038+ struct acl_object_label *matchpo;
71039+ struct acl_subject_label *matchps;
71040+ struct acl_subject_label *subj;
71041+ struct acl_role_label *role;
71042+ unsigned int x;
71043+
71044+ FOR_EACH_ROLE_START(role)
71045+ FOR_EACH_SUBJECT_START(role, subj, x)
71046+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
71047+ matchpo->mode |= GR_DELETED;
71048+ FOR_EACH_SUBJECT_END(subj,x)
71049+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
71050+ /* nested subjects aren't in the role's subj_hash table */
71051+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
71052+ matchpo->mode |= GR_DELETED;
71053+ FOR_EACH_NESTED_SUBJECT_END(subj)
71054+ if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
71055+ matchps->mode |= GR_DELETED;
71056+ FOR_EACH_ROLE_END(role)
71057+
71058+ inodev->nentry->deleted = 1;
71059+
71060+ return;
71061+}
71062+
71063+void
71064+gr_handle_delete(const ino_t ino, const dev_t dev)
71065+{
71066+ struct inodev_entry *inodev;
71067+
71068+ if (unlikely(!(gr_status & GR_READY)))
71069+ return;
71070+
71071+ write_lock(&gr_inode_lock);
71072+ inodev = lookup_inodev_entry(ino, dev);
71073+ if (inodev != NULL)
71074+ do_handle_delete(inodev, ino, dev);
71075+ write_unlock(&gr_inode_lock);
71076+
71077+ return;
71078+}
71079+
71080+static void
71081+update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
71082+ const ino_t newinode, const dev_t newdevice,
71083+ struct acl_subject_label *subj)
71084+{
71085+ unsigned int index = gr_fhash(oldinode, olddevice, subj->obj_hash_size);
71086+ struct acl_object_label *match;
71087+
71088+ match = subj->obj_hash[index];
71089+
71090+ while (match && (match->inode != oldinode ||
71091+ match->device != olddevice ||
71092+ !(match->mode & GR_DELETED)))
71093+ match = match->next;
71094+
71095+ if (match && (match->inode == oldinode)
71096+ && (match->device == olddevice)
71097+ && (match->mode & GR_DELETED)) {
71098+ if (match->prev == NULL) {
71099+ subj->obj_hash[index] = match->next;
71100+ if (match->next != NULL)
71101+ match->next->prev = NULL;
71102+ } else {
71103+ match->prev->next = match->next;
71104+ if (match->next != NULL)
71105+ match->next->prev = match->prev;
71106+ }
71107+ match->prev = NULL;
71108+ match->next = NULL;
71109+ match->inode = newinode;
71110+ match->device = newdevice;
71111+ match->mode &= ~GR_DELETED;
71112+
71113+ insert_acl_obj_label(match, subj);
71114+ }
71115+
71116+ return;
71117+}
71118+
71119+static void
71120+update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
71121+ const ino_t newinode, const dev_t newdevice,
71122+ struct acl_role_label *role)
71123+{
71124+ unsigned int index = gr_fhash(oldinode, olddevice, role->subj_hash_size);
71125+ struct acl_subject_label *match;
71126+
71127+ match = role->subj_hash[index];
71128+
71129+ while (match && (match->inode != oldinode ||
71130+ match->device != olddevice ||
71131+ !(match->mode & GR_DELETED)))
71132+ match = match->next;
71133+
71134+ if (match && (match->inode == oldinode)
71135+ && (match->device == olddevice)
71136+ && (match->mode & GR_DELETED)) {
71137+ if (match->prev == NULL) {
71138+ role->subj_hash[index] = match->next;
71139+ if (match->next != NULL)
71140+ match->next->prev = NULL;
71141+ } else {
71142+ match->prev->next = match->next;
71143+ if (match->next != NULL)
71144+ match->next->prev = match->prev;
71145+ }
71146+ match->prev = NULL;
71147+ match->next = NULL;
71148+ match->inode = newinode;
71149+ match->device = newdevice;
71150+ match->mode &= ~GR_DELETED;
71151+
71152+ insert_acl_subj_label(match, role);
71153+ }
71154+
71155+ return;
71156+}
71157+
71158+static void
71159+update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
71160+ const ino_t newinode, const dev_t newdevice)
71161+{
71162+ unsigned int index = gr_fhash(oldinode, olddevice, running_polstate.inodev_set.i_size);
71163+ struct inodev_entry *match;
71164+
71165+ match = running_polstate.inodev_set.i_hash[index];
71166+
71167+ while (match && (match->nentry->inode != oldinode ||
71168+ match->nentry->device != olddevice || !match->nentry->deleted))
71169+ match = match->next;
71170+
71171+ if (match && (match->nentry->inode == oldinode)
71172+ && (match->nentry->device == olddevice) &&
71173+ match->nentry->deleted) {
71174+ if (match->prev == NULL) {
71175+ running_polstate.inodev_set.i_hash[index] = match->next;
71176+ if (match->next != NULL)
71177+ match->next->prev = NULL;
71178+ } else {
71179+ match->prev->next = match->next;
71180+ if (match->next != NULL)
71181+ match->next->prev = match->prev;
71182+ }
71183+ match->prev = NULL;
71184+ match->next = NULL;
71185+ match->nentry->inode = newinode;
71186+ match->nentry->device = newdevice;
71187+ match->nentry->deleted = 0;
71188+
71189+ insert_inodev_entry(match);
71190+ }
71191+
71192+ return;
71193+}
71194+
71195+static void
71196+__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
71197+{
71198+ struct acl_subject_label *subj;
71199+ struct acl_role_label *role;
71200+ unsigned int x;
71201+
71202+ FOR_EACH_ROLE_START(role)
71203+ update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
71204+
71205+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
71206+ if ((subj->inode == ino) && (subj->device == dev)) {
71207+ subj->inode = ino;
71208+ subj->device = dev;
71209+ }
71210+ /* nested subjects aren't in the role's subj_hash table */
71211+ update_acl_obj_label(matchn->inode, matchn->device,
71212+ ino, dev, subj);
71213+ FOR_EACH_NESTED_SUBJECT_END(subj)
71214+ FOR_EACH_SUBJECT_START(role, subj, x)
71215+ update_acl_obj_label(matchn->inode, matchn->device,
71216+ ino, dev, subj);
71217+ FOR_EACH_SUBJECT_END(subj,x)
71218+ FOR_EACH_ROLE_END(role)
71219+
71220+ update_inodev_entry(matchn->inode, matchn->device, ino, dev);
71221+
71222+ return;
71223+}
71224+
71225+static void
71226+do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
71227+ const struct vfsmount *mnt)
71228+{
71229+ ino_t ino = dentry->d_inode->i_ino;
71230+ dev_t dev = __get_dev(dentry);
71231+
71232+ __do_handle_create(matchn, ino, dev);
71233+
71234+ return;
71235+}
71236+
71237+void
71238+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
71239+{
71240+ struct name_entry *matchn;
71241+
71242+ if (unlikely(!(gr_status & GR_READY)))
71243+ return;
71244+
71245+ preempt_disable();
71246+ matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
71247+
71248+ if (unlikely((unsigned long)matchn)) {
71249+ write_lock(&gr_inode_lock);
71250+ do_handle_create(matchn, dentry, mnt);
71251+ write_unlock(&gr_inode_lock);
71252+ }
71253+ preempt_enable();
71254+
71255+ return;
71256+}
71257+
71258+void
71259+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
71260+{
71261+ struct name_entry *matchn;
71262+
71263+ if (unlikely(!(gr_status & GR_READY)))
71264+ return;
71265+
71266+ preempt_disable();
71267+ matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
71268+
71269+ if (unlikely((unsigned long)matchn)) {
71270+ write_lock(&gr_inode_lock);
71271+ __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
71272+ write_unlock(&gr_inode_lock);
71273+ }
71274+ preempt_enable();
71275+
71276+ return;
71277+}
71278+
71279+void
71280+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
71281+ struct dentry *old_dentry,
71282+ struct dentry *new_dentry,
71283+ struct vfsmount *mnt, const __u8 replace, unsigned int flags)
71284+{
71285+ struct name_entry *matchn;
71286+ struct name_entry *matchn2 = NULL;
71287+ struct inodev_entry *inodev;
71288+ struct inode *inode = new_dentry->d_inode;
71289+ ino_t old_ino = old_dentry->d_inode->i_ino;
71290+ dev_t old_dev = __get_dev(old_dentry);
71291+ unsigned int exchange = flags & RENAME_EXCHANGE;
71292+
71293+ /* vfs_rename swaps the name and parent link for old_dentry and
71294+ new_dentry
71295+ at this point, old_dentry has the new name, parent link, and inode
71296+ for the renamed file
71297+ if a file is being replaced by a rename, new_dentry has the inode
71298+ and name for the replaced file
71299+ */
71300+
71301+ if (unlikely(!(gr_status & GR_READY)))
71302+ return;
71303+
71304+ preempt_disable();
71305+ matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
71306+
71307+ /* exchange cases:
71308+ a filename exists for the source, but not dest
71309+ do a recreate on source
71310+ a filename exists for the dest, but not source
71311+ do a recreate on dest
71312+ a filename exists for both source and dest
71313+ delete source and dest, then create source and dest
71314+ a filename exists for neither source nor dest
71315+ no updates needed
71316+
71317+ the name entry lookups get us the old inode/dev associated with
71318+ each name, so do the deletes first (if possible) so that when
71319+ we do the create, we pick up on the right entries
71320+ */
71321+
71322+ if (exchange)
71323+ matchn2 = lookup_name_entry(gr_to_filename_rbac(new_dentry, mnt));
71324+
71325+ /* we wouldn't have to check d_inode if it weren't for
71326+ NFS silly-renaming
71327+ */
71328+
71329+ write_lock(&gr_inode_lock);
71330+ if (unlikely((replace || exchange) && inode)) {
71331+ ino_t new_ino = inode->i_ino;
71332+ dev_t new_dev = __get_dev(new_dentry);
71333+
71334+ inodev = lookup_inodev_entry(new_ino, new_dev);
71335+ if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
71336+ do_handle_delete(inodev, new_ino, new_dev);
71337+ }
71338+
71339+ inodev = lookup_inodev_entry(old_ino, old_dev);
71340+ if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
71341+ do_handle_delete(inodev, old_ino, old_dev);
71342+
71343+ if (unlikely(matchn != NULL))
71344+ do_handle_create(matchn, old_dentry, mnt);
71345+
71346+ if (unlikely(matchn2 != NULL))
71347+ do_handle_create(matchn2, new_dentry, mnt);
71348+
71349+ write_unlock(&gr_inode_lock);
71350+ preempt_enable();
71351+
71352+ return;
71353+}
71354+
71355+#if defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC)
71356+static const unsigned long res_learn_bumps[GR_NLIMITS] = {
71357+ [RLIMIT_CPU] = GR_RLIM_CPU_BUMP,
71358+ [RLIMIT_FSIZE] = GR_RLIM_FSIZE_BUMP,
71359+ [RLIMIT_DATA] = GR_RLIM_DATA_BUMP,
71360+ [RLIMIT_STACK] = GR_RLIM_STACK_BUMP,
71361+ [RLIMIT_CORE] = GR_RLIM_CORE_BUMP,
71362+ [RLIMIT_RSS] = GR_RLIM_RSS_BUMP,
71363+ [RLIMIT_NPROC] = GR_RLIM_NPROC_BUMP,
71364+ [RLIMIT_NOFILE] = GR_RLIM_NOFILE_BUMP,
71365+ [RLIMIT_MEMLOCK] = GR_RLIM_MEMLOCK_BUMP,
71366+ [RLIMIT_AS] = GR_RLIM_AS_BUMP,
71367+ [RLIMIT_LOCKS] = GR_RLIM_LOCKS_BUMP,
71368+ [RLIMIT_SIGPENDING] = GR_RLIM_SIGPENDING_BUMP,
71369+ [RLIMIT_MSGQUEUE] = GR_RLIM_MSGQUEUE_BUMP,
71370+ [RLIMIT_NICE] = GR_RLIM_NICE_BUMP,
71371+ [RLIMIT_RTPRIO] = GR_RLIM_RTPRIO_BUMP,
71372+ [RLIMIT_RTTIME] = GR_RLIM_RTTIME_BUMP
71373+};
71374+
71375+void
71376+gr_learn_resource(const struct task_struct *task,
71377+ const int res, const unsigned long wanted, const int gt)
71378+{
71379+ struct acl_subject_label *acl;
71380+ const struct cred *cred;
71381+
71382+ if (unlikely((gr_status & GR_READY) &&
71383+ task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
71384+ goto skip_reslog;
71385+
71386+ gr_log_resource(task, res, wanted, gt);
71387+skip_reslog:
71388+
71389+ if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
71390+ return;
71391+
71392+ acl = task->acl;
71393+
71394+ if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
71395+ !(acl->resmask & (1U << (unsigned short) res))))
71396+ return;
71397+
71398+ if (wanted >= acl->res[res].rlim_cur) {
71399+ unsigned long res_add;
71400+
71401+ res_add = wanted + res_learn_bumps[res];
71402+
71403+ acl->res[res].rlim_cur = res_add;
71404+
71405+ if (wanted > acl->res[res].rlim_max)
71406+ acl->res[res].rlim_max = res_add;
71407+
71408+ /* only log the subject filename, since resource logging is supported for
71409+ single-subject learning only */
71410+ rcu_read_lock();
71411+ cred = __task_cred(task);
71412+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
71413+ task->role->roletype, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), acl->filename,
71414+ acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
71415+ "", (unsigned long) res, &task->signal->saved_ip);
71416+ rcu_read_unlock();
71417+ }
71418+
71419+ return;
71420+}
71421+EXPORT_SYMBOL_GPL(gr_learn_resource);
71422+#endif
71423+
71424+#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
71425+void
71426+pax_set_initial_flags(struct linux_binprm *bprm)
71427+{
71428+ struct task_struct *task = current;
71429+ struct acl_subject_label *proc;
71430+ unsigned long flags;
71431+
71432+ if (unlikely(!(gr_status & GR_READY)))
71433+ return;
71434+
71435+ flags = pax_get_flags(task);
71436+
71437+ proc = task->acl;
71438+
71439+ if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
71440+ flags &= ~MF_PAX_PAGEEXEC;
71441+ if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
71442+ flags &= ~MF_PAX_SEGMEXEC;
71443+ if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
71444+ flags &= ~MF_PAX_RANDMMAP;
71445+ if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
71446+ flags &= ~MF_PAX_EMUTRAMP;
71447+ if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
71448+ flags &= ~MF_PAX_MPROTECT;
71449+
71450+ if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
71451+ flags |= MF_PAX_PAGEEXEC;
71452+ if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
71453+ flags |= MF_PAX_SEGMEXEC;
71454+ if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
71455+ flags |= MF_PAX_RANDMMAP;
71456+ if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
71457+ flags |= MF_PAX_EMUTRAMP;
71458+ if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
71459+ flags |= MF_PAX_MPROTECT;
71460+
71461+ pax_set_flags(task, flags);
71462+
71463+ return;
71464+}
71465+#endif
71466+
71467+int
71468+gr_handle_proc_ptrace(struct task_struct *task)
71469+{
71470+ struct file *filp;
71471+ struct task_struct *tmp = task;
71472+ struct task_struct *curtemp = current;
71473+ __u32 retmode;
71474+
71475+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
71476+ if (unlikely(!(gr_status & GR_READY)))
71477+ return 0;
71478+#endif
71479+
71480+ read_lock(&tasklist_lock);
71481+ read_lock(&grsec_exec_file_lock);
71482+ filp = task->exec_file;
71483+
71484+ while (task_pid_nr(tmp) > 0) {
71485+ if (tmp == curtemp)
71486+ break;
71487+ tmp = tmp->real_parent;
71488+ }
71489+
71490+ if (!filp || (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
71491+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
71492+ read_unlock(&grsec_exec_file_lock);
71493+ read_unlock(&tasklist_lock);
71494+ return 1;
71495+ }
71496+
71497+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
71498+ if (!(gr_status & GR_READY)) {
71499+ read_unlock(&grsec_exec_file_lock);
71500+ read_unlock(&tasklist_lock);
71501+ return 0;
71502+ }
71503+#endif
71504+
71505+ retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
71506+ read_unlock(&grsec_exec_file_lock);
71507+ read_unlock(&tasklist_lock);
71508+
71509+ if (retmode & GR_NOPTRACE)
71510+ return 1;
71511+
71512+ if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
71513+ && (current->acl != task->acl || (current->acl != current->role->root_label
71514+ && task_pid_nr(current) != task_pid_nr(task))))
71515+ return 1;
71516+
71517+ return 0;
71518+}
71519+
71520+void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
71521+{
71522+ if (unlikely(!(gr_status & GR_READY)))
71523+ return;
71524+
71525+ if (!(current->role->roletype & GR_ROLE_GOD))
71526+ return;
71527+
71528+ seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
71529+ p->role->rolename, gr_task_roletype_to_char(p),
71530+ p->acl->filename);
71531+}
71532+
71533+int
71534+gr_handle_ptrace(struct task_struct *task, const long request)
71535+{
71536+ struct task_struct *tmp = task;
71537+ struct task_struct *curtemp = current;
71538+ __u32 retmode;
71539+
71540+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
71541+ if (unlikely(!(gr_status & GR_READY)))
71542+ return 0;
71543+#endif
71544+ if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
71545+ read_lock(&tasklist_lock);
71546+ while (task_pid_nr(tmp) > 0) {
71547+ if (tmp == curtemp)
71548+ break;
71549+ tmp = tmp->real_parent;
71550+ }
71551+
71552+ if (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
71553+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
71554+ read_unlock(&tasklist_lock);
71555+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
71556+ return 1;
71557+ }
71558+ read_unlock(&tasklist_lock);
71559+ }
71560+
71561+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
71562+ if (!(gr_status & GR_READY))
71563+ return 0;
71564+#endif
71565+
71566+ read_lock(&grsec_exec_file_lock);
71567+ if (unlikely(!task->exec_file)) {
71568+ read_unlock(&grsec_exec_file_lock);
71569+ return 0;
71570+ }
71571+
71572+ retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
71573+ read_unlock(&grsec_exec_file_lock);
71574+
71575+ if (retmode & GR_NOPTRACE) {
71576+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
71577+ return 1;
71578+ }
71579+
71580+ if (retmode & GR_PTRACERD) {
71581+ switch (request) {
71582+ case PTRACE_SEIZE:
71583+ case PTRACE_POKETEXT:
71584+ case PTRACE_POKEDATA:
71585+ case PTRACE_POKEUSR:
71586+#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
71587+ case PTRACE_SETREGS:
71588+ case PTRACE_SETFPREGS:
71589+#endif
71590+#ifdef CONFIG_X86
71591+ case PTRACE_SETFPXREGS:
71592+#endif
71593+#ifdef CONFIG_ALTIVEC
71594+ case PTRACE_SETVRREGS:
71595+#endif
71596+ return 1;
71597+ default:
71598+ return 0;
71599+ }
71600+ } else if (!(current->acl->mode & GR_POVERRIDE) &&
71601+ !(current->role->roletype & GR_ROLE_GOD) &&
71602+ (current->acl != task->acl)) {
71603+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
71604+ return 1;
71605+ }
71606+
71607+ return 0;
71608+}
71609+
71610+static int is_writable_mmap(const struct file *filp)
71611+{
71612+ struct task_struct *task = current;
71613+ struct acl_object_label *obj, *obj2;
71614+
71615+ if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
71616+ !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))) {
71617+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
71618+ obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
71619+ task->role->root_label);
71620+ if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
71621+ gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
71622+ return 1;
71623+ }
71624+ }
71625+ return 0;
71626+}
71627+
71628+int
71629+gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
71630+{
71631+ __u32 mode;
71632+
71633+ if (unlikely(!file || !(prot & PROT_EXEC)))
71634+ return 1;
71635+
71636+ if (is_writable_mmap(file))
71637+ return 0;
71638+
71639+ mode =
71640+ gr_search_file(file->f_path.dentry,
71641+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
71642+ file->f_path.mnt);
71643+
71644+ if (!gr_tpe_allow(file))
71645+ return 0;
71646+
71647+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
71648+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
71649+ return 0;
71650+ } else if (unlikely(!(mode & GR_EXEC))) {
71651+ return 0;
71652+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
71653+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
71654+ return 1;
71655+ }
71656+
71657+ return 1;
71658+}
71659+
71660+int
71661+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
71662+{
71663+ __u32 mode;
71664+
71665+ if (unlikely(!file || !(prot & PROT_EXEC)))
71666+ return 1;
71667+
71668+ if (is_writable_mmap(file))
71669+ return 0;
71670+
71671+ mode =
71672+ gr_search_file(file->f_path.dentry,
71673+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
71674+ file->f_path.mnt);
71675+
71676+ if (!gr_tpe_allow(file))
71677+ return 0;
71678+
71679+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
71680+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
71681+ return 0;
71682+ } else if (unlikely(!(mode & GR_EXEC))) {
71683+ return 0;
71684+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
71685+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
71686+ return 1;
71687+ }
71688+
71689+ return 1;
71690+}
71691+
71692+void
71693+gr_acl_handle_psacct(struct task_struct *task, const long code)
71694+{
71695+ unsigned long runtime, cputime;
71696+ cputime_t utime, stime;
71697+ unsigned int wday, cday;
71698+ __u8 whr, chr;
71699+ __u8 wmin, cmin;
71700+ __u8 wsec, csec;
71701+ struct timespec curtime, starttime;
71702+
71703+ if (unlikely(!(gr_status & GR_READY) || !task->acl ||
71704+ !(task->acl->mode & GR_PROCACCT)))
71705+ return;
71706+
71707+ curtime = ns_to_timespec(ktime_get_ns());
71708+ starttime = ns_to_timespec(task->start_time);
71709+ runtime = curtime.tv_sec - starttime.tv_sec;
71710+ wday = runtime / (60 * 60 * 24);
71711+ runtime -= wday * (60 * 60 * 24);
71712+ whr = runtime / (60 * 60);
71713+ runtime -= whr * (60 * 60);
71714+ wmin = runtime / 60;
71715+ runtime -= wmin * 60;
71716+ wsec = runtime;
71717+
71718+ task_cputime(task, &utime, &stime);
71719+ cputime = cputime_to_secs(utime + stime);
71720+ cday = cputime / (60 * 60 * 24);
71721+ cputime -= cday * (60 * 60 * 24);
71722+ chr = cputime / (60 * 60);
71723+ cputime -= chr * (60 * 60);
71724+ cmin = cputime / 60;
71725+ cputime -= cmin * 60;
71726+ csec = cputime;
71727+
71728+ gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
71729+
71730+ return;
71731+}
71732+
71733+#ifdef CONFIG_TASKSTATS
71734+int gr_is_taskstats_denied(int pid)
71735+{
71736+ struct task_struct *task;
71737+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
71738+ const struct cred *cred;
71739+#endif
71740+ int ret = 0;
71741+
71742+ /* restrict taskstats viewing to un-chrooted root users
71743+ who have the 'view' subject flag if the RBAC system is enabled
71744+ */
71745+
71746+ rcu_read_lock();
71747+ read_lock(&tasklist_lock);
71748+ task = find_task_by_vpid(pid);
71749+ if (task) {
71750+#ifdef CONFIG_GRKERNSEC_CHROOT
71751+ if (proc_is_chrooted(task))
71752+ ret = -EACCES;
71753+#endif
71754+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
71755+ cred = __task_cred(task);
71756+#ifdef CONFIG_GRKERNSEC_PROC_USER
71757+ if (gr_is_global_nonroot(cred->uid))
71758+ ret = -EACCES;
71759+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
71760+ if (gr_is_global_nonroot(cred->uid) && !groups_search(cred->group_info, grsec_proc_gid))
71761+ ret = -EACCES;
71762+#endif
71763+#endif
71764+ if (gr_status & GR_READY) {
71765+ if (!(task->acl->mode & GR_VIEW))
71766+ ret = -EACCES;
71767+ }
71768+ } else
71769+ ret = -ENOENT;
71770+
71771+ read_unlock(&tasklist_lock);
71772+ rcu_read_unlock();
71773+
71774+ return ret;
71775+}
71776+#endif
71777+
71778+/* AUXV entries are filled via a descendant of search_binary_handler
71779+ after we've already applied the subject for the target
71780+*/
71781+int gr_acl_enable_at_secure(void)
71782+{
71783+ if (unlikely(!(gr_status & GR_READY)))
71784+ return 0;
71785+
71786+ if (current->acl->mode & GR_ATSECURE)
71787+ return 1;
71788+
71789+ return 0;
71790+}
71791+
71792+int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
71793+{
71794+ struct task_struct *task = current;
71795+ struct dentry *dentry = file->f_path.dentry;
71796+ struct vfsmount *mnt = file->f_path.mnt;
71797+ struct acl_object_label *obj, *tmp;
71798+ struct acl_subject_label *subj;
71799+ unsigned int bufsize;
71800+ int is_not_root;
71801+ char *path;
71802+ dev_t dev = __get_dev(dentry);
71803+
71804+ if (unlikely(!(gr_status & GR_READY)))
71805+ return 1;
71806+
71807+ if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
71808+ return 1;
71809+
71810+ /* ignore Eric Biederman */
71811+ if (IS_PRIVATE(dentry->d_inode))
71812+ return 1;
71813+
71814+ subj = task->acl;
71815+ read_lock(&gr_inode_lock);
71816+ do {
71817+ obj = lookup_acl_obj_label(ino, dev, subj);
71818+ if (obj != NULL) {
71819+ read_unlock(&gr_inode_lock);
71820+ return (obj->mode & GR_FIND) ? 1 : 0;
71821+ }
71822+ } while ((subj = subj->parent_subject));
71823+ read_unlock(&gr_inode_lock);
71824+
71825+ /* this is purely an optimization since we're looking for an object
71826+ for the directory we're doing a readdir on
71827+ if it's possible for any globbed object to match the entry we're
71828+ filling into the directory, then the object we find here will be
71829+ an anchor point with attached globbed objects
71830+ */
71831+ obj = chk_obj_label_noglob(dentry, mnt, task->acl);
71832+ if (obj->globbed == NULL)
71833+ return (obj->mode & GR_FIND) ? 1 : 0;
71834+
71835+ is_not_root = ((obj->filename[0] == '/') &&
71836+ (obj->filename[1] == '\0')) ? 0 : 1;
71837+ bufsize = PAGE_SIZE - namelen - is_not_root;
71838+
71839+ /* check bufsize > PAGE_SIZE || bufsize == 0 */
71840+ if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
71841+ return 1;
71842+
71843+ preempt_disable();
71844+ path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
71845+ bufsize);
71846+
71847+ bufsize = strlen(path);
71848+
71849+ /* if base is "/", don't append an additional slash */
71850+ if (is_not_root)
71851+ *(path + bufsize) = '/';
71852+ memcpy(path + bufsize + is_not_root, name, namelen);
71853+ *(path + bufsize + namelen + is_not_root) = '\0';
71854+
71855+ tmp = obj->globbed;
71856+ while (tmp) {
71857+ if (!glob_match(tmp->filename, path)) {
71858+ preempt_enable();
71859+ return (tmp->mode & GR_FIND) ? 1 : 0;
71860+ }
71861+ tmp = tmp->next;
71862+ }
71863+ preempt_enable();
71864+ return (obj->mode & GR_FIND) ? 1 : 0;
71865+}
71866+
71867+void gr_put_exec_file(struct task_struct *task)
71868+{
71869+ struct file *filp;
71870+
71871+ write_lock(&grsec_exec_file_lock);
71872+ filp = task->exec_file;
71873+ task->exec_file = NULL;
71874+ write_unlock(&grsec_exec_file_lock);
71875+
71876+ if (filp)
71877+ fput(filp);
71878+
71879+ return;
71880+}
71881+
71882+
71883+#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
71884+EXPORT_SYMBOL_GPL(gr_acl_is_enabled);
71885+#endif
71886+#ifdef CONFIG_SECURITY
71887+EXPORT_SYMBOL_GPL(gr_check_user_change);
71888+EXPORT_SYMBOL_GPL(gr_check_group_change);
71889+#endif
71890+
71891diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
71892new file mode 100644
71893index 0000000..18ffbbd
71894--- /dev/null
71895+++ b/grsecurity/gracl_alloc.c
71896@@ -0,0 +1,105 @@
71897+#include <linux/kernel.h>
71898+#include <linux/mm.h>
71899+#include <linux/slab.h>
71900+#include <linux/vmalloc.h>
71901+#include <linux/gracl.h>
71902+#include <linux/grsecurity.h>
71903+
71904+static struct gr_alloc_state __current_alloc_state = { 1, 1, NULL };
71905+struct gr_alloc_state *current_alloc_state = &__current_alloc_state;
71906+
71907+static __inline__ int
71908+alloc_pop(void)
71909+{
71910+ if (current_alloc_state->alloc_stack_next == 1)
71911+ return 0;
71912+
71913+ kfree(current_alloc_state->alloc_stack[current_alloc_state->alloc_stack_next - 2]);
71914+
71915+ current_alloc_state->alloc_stack_next--;
71916+
71917+ return 1;
71918+}
71919+
71920+static __inline__ int
71921+alloc_push(void *buf)
71922+{
71923+ if (current_alloc_state->alloc_stack_next >= current_alloc_state->alloc_stack_size)
71924+ return 1;
71925+
71926+ current_alloc_state->alloc_stack[current_alloc_state->alloc_stack_next - 1] = buf;
71927+
71928+ current_alloc_state->alloc_stack_next++;
71929+
71930+ return 0;
71931+}
71932+
71933+void *
71934+acl_alloc(unsigned long len)
71935+{
71936+ void *ret = NULL;
71937+
71938+ if (!len || len > PAGE_SIZE)
71939+ goto out;
71940+
71941+ ret = kmalloc(len, GFP_KERNEL);
71942+
71943+ if (ret) {
71944+ if (alloc_push(ret)) {
71945+ kfree(ret);
71946+ ret = NULL;
71947+ }
71948+ }
71949+
71950+out:
71951+ return ret;
71952+}
71953+
71954+void *
71955+acl_alloc_num(unsigned long num, unsigned long len)
71956+{
71957+ if (!len || (num > (PAGE_SIZE / len)))
71958+ return NULL;
71959+
71960+ return acl_alloc(num * len);
71961+}
71962+
71963+void
71964+acl_free_all(void)
71965+{
71966+ if (!current_alloc_state->alloc_stack)
71967+ return;
71968+
71969+ while (alloc_pop()) ;
71970+
71971+ if (current_alloc_state->alloc_stack) {
71972+ if ((current_alloc_state->alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
71973+ kfree(current_alloc_state->alloc_stack);
71974+ else
71975+ vfree(current_alloc_state->alloc_stack);
71976+ }
71977+
71978+ current_alloc_state->alloc_stack = NULL;
71979+ current_alloc_state->alloc_stack_size = 1;
71980+ current_alloc_state->alloc_stack_next = 1;
71981+
71982+ return;
71983+}
71984+
71985+int
71986+acl_alloc_stack_init(unsigned long size)
71987+{
71988+ if ((size * sizeof (void *)) <= PAGE_SIZE)
71989+ current_alloc_state->alloc_stack =
71990+ (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
71991+ else
71992+ current_alloc_state->alloc_stack = (void **) vmalloc(size * sizeof (void *));
71993+
71994+ current_alloc_state->alloc_stack_size = size;
71995+ current_alloc_state->alloc_stack_next = 1;
71996+
71997+ if (!current_alloc_state->alloc_stack)
71998+ return 0;
71999+ else
72000+ return 1;
72001+}
72002diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
72003new file mode 100644
72004index 0000000..1a94c11
72005--- /dev/null
72006+++ b/grsecurity/gracl_cap.c
72007@@ -0,0 +1,127 @@
72008+#include <linux/kernel.h>
72009+#include <linux/module.h>
72010+#include <linux/sched.h>
72011+#include <linux/gracl.h>
72012+#include <linux/grsecurity.h>
72013+#include <linux/grinternal.h>
72014+
72015+extern const char *captab_log[];
72016+extern int captab_log_entries;
72017+
72018+int gr_learn_cap(const struct task_struct *task, const struct cred *cred, const int cap)
72019+{
72020+ struct acl_subject_label *curracl;
72021+
72022+ if (!gr_acl_is_enabled())
72023+ return 1;
72024+
72025+ curracl = task->acl;
72026+
72027+ if (curracl->mode & (GR_LEARN | GR_INHERITLEARN)) {
72028+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
72029+ task->role->roletype, GR_GLOBAL_UID(cred->uid),
72030+ GR_GLOBAL_GID(cred->gid), task->exec_file ?
72031+ gr_to_filename(task->exec_file->f_path.dentry,
72032+ task->exec_file->f_path.mnt) : curracl->filename,
72033+ curracl->filename, 0UL,
72034+ 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
72035+ return 1;
72036+ }
72037+
72038+ return 0;
72039+}
72040+
72041+int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
72042+{
72043+ struct acl_subject_label *curracl;
72044+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
72045+ kernel_cap_t cap_audit = __cap_empty_set;
72046+
72047+ if (!gr_acl_is_enabled())
72048+ return 1;
72049+
72050+ curracl = task->acl;
72051+
72052+ cap_drop = curracl->cap_lower;
72053+ cap_mask = curracl->cap_mask;
72054+ cap_audit = curracl->cap_invert_audit;
72055+
72056+ while ((curracl = curracl->parent_subject)) {
72057+ /* if the cap isn't specified in the current computed mask but is specified in the
72058+ current level subject, and is lowered in the current level subject, then add
72059+ it to the set of dropped capabilities
72060+ otherwise, add the current level subject's mask to the current computed mask
72061+ */
72062+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
72063+ cap_raise(cap_mask, cap);
72064+ if (cap_raised(curracl->cap_lower, cap))
72065+ cap_raise(cap_drop, cap);
72066+ if (cap_raised(curracl->cap_invert_audit, cap))
72067+ cap_raise(cap_audit, cap);
72068+ }
72069+ }
72070+
72071+ if (!cap_raised(cap_drop, cap)) {
72072+ if (cap_raised(cap_audit, cap))
72073+ gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
72074+ return 1;
72075+ }
72076+
72077+ /* only learn the capability use if the process has the capability in the
72078+ general case, the two uses in sys.c of gr_learn_cap are an exception
72079+ to this rule to ensure any role transition involves what the full-learned
72080+ policy believes in a privileged process
72081+ */
72082+ if (cap_raised(cred->cap_effective, cap) && gr_learn_cap(task, cred, cap))
72083+ return 1;
72084+
72085+ if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
72086+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
72087+
72088+ return 0;
72089+}
72090+
72091+int
72092+gr_acl_is_capable(const int cap)
72093+{
72094+ return gr_task_acl_is_capable(current, current_cred(), cap);
72095+}
72096+
72097+int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
72098+{
72099+ struct acl_subject_label *curracl;
72100+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
72101+
72102+ if (!gr_acl_is_enabled())
72103+ return 1;
72104+
72105+ curracl = task->acl;
72106+
72107+ cap_drop = curracl->cap_lower;
72108+ cap_mask = curracl->cap_mask;
72109+
72110+ while ((curracl = curracl->parent_subject)) {
72111+ /* if the cap isn't specified in the current computed mask but is specified in the
72112+ current level subject, and is lowered in the current level subject, then add
72113+ it to the set of dropped capabilities
72114+ otherwise, add the current level subject's mask to the current computed mask
72115+ */
72116+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
72117+ cap_raise(cap_mask, cap);
72118+ if (cap_raised(curracl->cap_lower, cap))
72119+ cap_raise(cap_drop, cap);
72120+ }
72121+ }
72122+
72123+ if (!cap_raised(cap_drop, cap))
72124+ return 1;
72125+
72126+ return 0;
72127+}
72128+
72129+int
72130+gr_acl_is_capable_nolog(const int cap)
72131+{
72132+ return gr_task_acl_is_capable_nolog(current, cap);
72133+}
72134+
72135diff --git a/grsecurity/gracl_compat.c b/grsecurity/gracl_compat.c
72136new file mode 100644
72137index 0000000..ca25605
72138--- /dev/null
72139+++ b/grsecurity/gracl_compat.c
72140@@ -0,0 +1,270 @@
72141+#include <linux/kernel.h>
72142+#include <linux/gracl.h>
72143+#include <linux/compat.h>
72144+#include <linux/gracl_compat.h>
72145+
72146+#include <asm/uaccess.h>
72147+
72148+int copy_gr_arg_wrapper_compat(const char *buf, struct gr_arg_wrapper *uwrap)
72149+{
72150+ struct gr_arg_wrapper_compat uwrapcompat;
72151+
72152+ if (copy_from_user(&uwrapcompat, buf, sizeof(uwrapcompat)))
72153+ return -EFAULT;
72154+
72155+ if (((uwrapcompat.version != GRSECURITY_VERSION) &&
72156+ (uwrapcompat.version != 0x2901)) ||
72157+ (uwrapcompat.size != sizeof(struct gr_arg_compat)))
72158+ return -EINVAL;
72159+
72160+ uwrap->arg = compat_ptr(uwrapcompat.arg);
72161+ uwrap->version = uwrapcompat.version;
72162+ uwrap->size = sizeof(struct gr_arg);
72163+
72164+ return 0;
72165+}
72166+
72167+int copy_gr_arg_compat(const struct gr_arg __user *buf, struct gr_arg *arg)
72168+{
72169+ struct gr_arg_compat argcompat;
72170+
72171+ if (copy_from_user(&argcompat, buf, sizeof(argcompat)))
72172+ return -EFAULT;
72173+
72174+ arg->role_db.r_table = compat_ptr(argcompat.role_db.r_table);
72175+ arg->role_db.num_pointers = argcompat.role_db.num_pointers;
72176+ arg->role_db.num_roles = argcompat.role_db.num_roles;
72177+ arg->role_db.num_domain_children = argcompat.role_db.num_domain_children;
72178+ arg->role_db.num_subjects = argcompat.role_db.num_subjects;
72179+ arg->role_db.num_objects = argcompat.role_db.num_objects;
72180+
72181+ memcpy(&arg->pw, &argcompat.pw, sizeof(arg->pw));
72182+ memcpy(&arg->salt, &argcompat.salt, sizeof(arg->salt));
72183+ memcpy(&arg->sum, &argcompat.sum, sizeof(arg->sum));
72184+ memcpy(&arg->sp_role, &argcompat.sp_role, sizeof(arg->sp_role));
72185+ arg->sprole_pws = compat_ptr(argcompat.sprole_pws);
72186+ arg->segv_device = argcompat.segv_device;
72187+ arg->segv_inode = argcompat.segv_inode;
72188+ arg->segv_uid = argcompat.segv_uid;
72189+ arg->num_sprole_pws = argcompat.num_sprole_pws;
72190+ arg->mode = argcompat.mode;
72191+
72192+ return 0;
72193+}
72194+
72195+int copy_acl_object_label_compat(struct acl_object_label *obj, const struct acl_object_label *userp)
72196+{
72197+ struct acl_object_label_compat objcompat;
72198+
72199+ if (copy_from_user(&objcompat, userp, sizeof(objcompat)))
72200+ return -EFAULT;
72201+
72202+ obj->filename = compat_ptr(objcompat.filename);
72203+ obj->inode = objcompat.inode;
72204+ obj->device = objcompat.device;
72205+ obj->mode = objcompat.mode;
72206+
72207+ obj->nested = compat_ptr(objcompat.nested);
72208+ obj->globbed = compat_ptr(objcompat.globbed);
72209+
72210+ obj->prev = compat_ptr(objcompat.prev);
72211+ obj->next = compat_ptr(objcompat.next);
72212+
72213+ return 0;
72214+}
72215+
72216+int copy_acl_subject_label_compat(struct acl_subject_label *subj, const struct acl_subject_label *userp)
72217+{
72218+ unsigned int i;
72219+ struct acl_subject_label_compat subjcompat;
72220+
72221+ if (copy_from_user(&subjcompat, userp, sizeof(subjcompat)))
72222+ return -EFAULT;
72223+
72224+ subj->filename = compat_ptr(subjcompat.filename);
72225+ subj->inode = subjcompat.inode;
72226+ subj->device = subjcompat.device;
72227+ subj->mode = subjcompat.mode;
72228+ subj->cap_mask = subjcompat.cap_mask;
72229+ subj->cap_lower = subjcompat.cap_lower;
72230+ subj->cap_invert_audit = subjcompat.cap_invert_audit;
72231+
72232+ for (i = 0; i < GR_NLIMITS; i++) {
72233+ if (subjcompat.res[i].rlim_cur == COMPAT_RLIM_INFINITY)
72234+ subj->res[i].rlim_cur = RLIM_INFINITY;
72235+ else
72236+ subj->res[i].rlim_cur = subjcompat.res[i].rlim_cur;
72237+ if (subjcompat.res[i].rlim_max == COMPAT_RLIM_INFINITY)
72238+ subj->res[i].rlim_max = RLIM_INFINITY;
72239+ else
72240+ subj->res[i].rlim_max = subjcompat.res[i].rlim_max;
72241+ }
72242+ subj->resmask = subjcompat.resmask;
72243+
72244+ subj->user_trans_type = subjcompat.user_trans_type;
72245+ subj->group_trans_type = subjcompat.group_trans_type;
72246+ subj->user_transitions = compat_ptr(subjcompat.user_transitions);
72247+ subj->group_transitions = compat_ptr(subjcompat.group_transitions);
72248+ subj->user_trans_num = subjcompat.user_trans_num;
72249+ subj->group_trans_num = subjcompat.group_trans_num;
72250+
72251+ memcpy(&subj->sock_families, &subjcompat.sock_families, sizeof(subj->sock_families));
72252+ memcpy(&subj->ip_proto, &subjcompat.ip_proto, sizeof(subj->ip_proto));
72253+ subj->ip_type = subjcompat.ip_type;
72254+ subj->ips = compat_ptr(subjcompat.ips);
72255+ subj->ip_num = subjcompat.ip_num;
72256+ subj->inaddr_any_override = subjcompat.inaddr_any_override;
72257+
72258+ subj->crashes = subjcompat.crashes;
72259+ subj->expires = subjcompat.expires;
72260+
72261+ subj->parent_subject = compat_ptr(subjcompat.parent_subject);
72262+ subj->hash = compat_ptr(subjcompat.hash);
72263+ subj->prev = compat_ptr(subjcompat.prev);
72264+ subj->next = compat_ptr(subjcompat.next);
72265+
72266+ subj->obj_hash = compat_ptr(subjcompat.obj_hash);
72267+ subj->obj_hash_size = subjcompat.obj_hash_size;
72268+ subj->pax_flags = subjcompat.pax_flags;
72269+
72270+ return 0;
72271+}
72272+
72273+int copy_acl_role_label_compat(struct acl_role_label *role, const struct acl_role_label *userp)
72274+{
72275+ struct acl_role_label_compat rolecompat;
72276+
72277+ if (copy_from_user(&rolecompat, userp, sizeof(rolecompat)))
72278+ return -EFAULT;
72279+
72280+ role->rolename = compat_ptr(rolecompat.rolename);
72281+ role->uidgid = rolecompat.uidgid;
72282+ role->roletype = rolecompat.roletype;
72283+
72284+ role->auth_attempts = rolecompat.auth_attempts;
72285+ role->expires = rolecompat.expires;
72286+
72287+ role->root_label = compat_ptr(rolecompat.root_label);
72288+ role->hash = compat_ptr(rolecompat.hash);
72289+
72290+ role->prev = compat_ptr(rolecompat.prev);
72291+ role->next = compat_ptr(rolecompat.next);
72292+
72293+ role->transitions = compat_ptr(rolecompat.transitions);
72294+ role->allowed_ips = compat_ptr(rolecompat.allowed_ips);
72295+ role->domain_children = compat_ptr(rolecompat.domain_children);
72296+ role->domain_child_num = rolecompat.domain_child_num;
72297+
72298+ role->umask = rolecompat.umask;
72299+
72300+ role->subj_hash = compat_ptr(rolecompat.subj_hash);
72301+ role->subj_hash_size = rolecompat.subj_hash_size;
72302+
72303+ return 0;
72304+}
72305+
72306+int copy_role_allowed_ip_compat(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp)
72307+{
72308+ struct role_allowed_ip_compat roleip_compat;
72309+
72310+ if (copy_from_user(&roleip_compat, userp, sizeof(roleip_compat)))
72311+ return -EFAULT;
72312+
72313+ roleip->addr = roleip_compat.addr;
72314+ roleip->netmask = roleip_compat.netmask;
72315+
72316+ roleip->prev = compat_ptr(roleip_compat.prev);
72317+ roleip->next = compat_ptr(roleip_compat.next);
72318+
72319+ return 0;
72320+}
72321+
72322+int copy_role_transition_compat(struct role_transition *trans, const struct role_transition *userp)
72323+{
72324+ struct role_transition_compat trans_compat;
72325+
72326+ if (copy_from_user(&trans_compat, userp, sizeof(trans_compat)))
72327+ return -EFAULT;
72328+
72329+ trans->rolename = compat_ptr(trans_compat.rolename);
72330+
72331+ trans->prev = compat_ptr(trans_compat.prev);
72332+ trans->next = compat_ptr(trans_compat.next);
72333+
72334+ return 0;
72335+
72336+}
72337+
72338+int copy_gr_hash_struct_compat(struct gr_hash_struct *hash, const struct gr_hash_struct *userp)
72339+{
72340+ struct gr_hash_struct_compat hash_compat;
72341+
72342+ if (copy_from_user(&hash_compat, userp, sizeof(hash_compat)))
72343+ return -EFAULT;
72344+
72345+ hash->table = compat_ptr(hash_compat.table);
72346+ hash->nametable = compat_ptr(hash_compat.nametable);
72347+ hash->first = compat_ptr(hash_compat.first);
72348+
72349+ hash->table_size = hash_compat.table_size;
72350+ hash->used_size = hash_compat.used_size;
72351+
72352+ hash->type = hash_compat.type;
72353+
72354+ return 0;
72355+}
72356+
72357+int copy_pointer_from_array_compat(void *ptr, unsigned long idx, const void *userp)
72358+{
72359+ compat_uptr_t ptrcompat;
72360+
72361+ if (copy_from_user(&ptrcompat, userp + (idx * sizeof(ptrcompat)), sizeof(ptrcompat)))
72362+ return -EFAULT;
72363+
72364+ *(void **)ptr = compat_ptr(ptrcompat);
72365+
72366+ return 0;
72367+}
72368+
72369+int copy_acl_ip_label_compat(struct acl_ip_label *ip, const struct acl_ip_label *userp)
72370+{
72371+ struct acl_ip_label_compat ip_compat;
72372+
72373+ if (copy_from_user(&ip_compat, userp, sizeof(ip_compat)))
72374+ return -EFAULT;
72375+
72376+ ip->iface = compat_ptr(ip_compat.iface);
72377+ ip->addr = ip_compat.addr;
72378+ ip->netmask = ip_compat.netmask;
72379+ ip->low = ip_compat.low;
72380+ ip->high = ip_compat.high;
72381+ ip->mode = ip_compat.mode;
72382+ ip->type = ip_compat.type;
72383+
72384+ memcpy(&ip->proto, &ip_compat.proto, sizeof(ip->proto));
72385+
72386+ ip->prev = compat_ptr(ip_compat.prev);
72387+ ip->next = compat_ptr(ip_compat.next);
72388+
72389+ return 0;
72390+}
72391+
72392+int copy_sprole_pw_compat(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp)
72393+{
72394+ struct sprole_pw_compat pw_compat;
72395+
72396+ if (copy_from_user(&pw_compat, (const void *)userp + (sizeof(pw_compat) * idx), sizeof(pw_compat)))
72397+ return -EFAULT;
72398+
72399+ pw->rolename = compat_ptr(pw_compat.rolename);
72400+ memcpy(&pw->salt, pw_compat.salt, sizeof(pw->salt));
72401+ memcpy(&pw->sum, pw_compat.sum, sizeof(pw->sum));
72402+
72403+ return 0;
72404+}
72405+
72406+size_t get_gr_arg_wrapper_size_compat(void)
72407+{
72408+ return sizeof(struct gr_arg_wrapper_compat);
72409+}
72410+
72411diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
72412new file mode 100644
72413index 0000000..8ee8e4f
72414--- /dev/null
72415+++ b/grsecurity/gracl_fs.c
72416@@ -0,0 +1,447 @@
72417+#include <linux/kernel.h>
72418+#include <linux/sched.h>
72419+#include <linux/types.h>
72420+#include <linux/fs.h>
72421+#include <linux/file.h>
72422+#include <linux/stat.h>
72423+#include <linux/grsecurity.h>
72424+#include <linux/grinternal.h>
72425+#include <linux/gracl.h>
72426+
72427+umode_t
72428+gr_acl_umask(void)
72429+{
72430+ if (unlikely(!gr_acl_is_enabled()))
72431+ return 0;
72432+
72433+ return current->role->umask;
72434+}
72435+
72436+__u32
72437+gr_acl_handle_hidden_file(const struct dentry * dentry,
72438+ const struct vfsmount * mnt)
72439+{
72440+ __u32 mode;
72441+
72442+ if (unlikely(d_is_negative(dentry)))
72443+ return GR_FIND;
72444+
72445+ mode =
72446+ gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
72447+
72448+ if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
72449+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
72450+ return mode;
72451+ } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
72452+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
72453+ return 0;
72454+ } else if (unlikely(!(mode & GR_FIND)))
72455+ return 0;
72456+
72457+ return GR_FIND;
72458+}
72459+
72460+__u32
72461+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
72462+ int acc_mode)
72463+{
72464+ __u32 reqmode = GR_FIND;
72465+ __u32 mode;
72466+
72467+ if (unlikely(d_is_negative(dentry)))
72468+ return reqmode;
72469+
72470+ if (acc_mode & MAY_APPEND)
72471+ reqmode |= GR_APPEND;
72472+ else if (acc_mode & MAY_WRITE)
72473+ reqmode |= GR_WRITE;
72474+ if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
72475+ reqmode |= GR_READ;
72476+
72477+ mode =
72478+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
72479+ mnt);
72480+
72481+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
72482+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
72483+ reqmode & GR_READ ? " reading" : "",
72484+ reqmode & GR_WRITE ? " writing" : reqmode &
72485+ GR_APPEND ? " appending" : "");
72486+ return reqmode;
72487+ } else
72488+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
72489+ {
72490+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
72491+ reqmode & GR_READ ? " reading" : "",
72492+ reqmode & GR_WRITE ? " writing" : reqmode &
72493+ GR_APPEND ? " appending" : "");
72494+ return 0;
72495+ } else if (unlikely((mode & reqmode) != reqmode))
72496+ return 0;
72497+
72498+ return reqmode;
72499+}
72500+
72501+__u32
72502+gr_acl_handle_creat(const struct dentry * dentry,
72503+ const struct dentry * p_dentry,
72504+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
72505+ const int imode)
72506+{
72507+ __u32 reqmode = GR_WRITE | GR_CREATE;
72508+ __u32 mode;
72509+
72510+ if (acc_mode & MAY_APPEND)
72511+ reqmode |= GR_APPEND;
72512+ // if a directory was required or the directory already exists, then
72513+ // don't count this open as a read
72514+ if ((acc_mode & MAY_READ) &&
72515+ !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
72516+ reqmode |= GR_READ;
72517+ if ((open_flags & O_CREAT) &&
72518+ ((imode & S_ISUID) || ((imode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
72519+ reqmode |= GR_SETID;
72520+
72521+ mode =
72522+ gr_check_create(dentry, p_dentry, p_mnt,
72523+ reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
72524+
72525+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
72526+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
72527+ reqmode & GR_READ ? " reading" : "",
72528+ reqmode & GR_WRITE ? " writing" : reqmode &
72529+ GR_APPEND ? " appending" : "");
72530+ return reqmode;
72531+ } else
72532+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
72533+ {
72534+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
72535+ reqmode & GR_READ ? " reading" : "",
72536+ reqmode & GR_WRITE ? " writing" : reqmode &
72537+ GR_APPEND ? " appending" : "");
72538+ return 0;
72539+ } else if (unlikely((mode & reqmode) != reqmode))
72540+ return 0;
72541+
72542+ return reqmode;
72543+}
72544+
72545+__u32
72546+gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
72547+ const int fmode)
72548+{
72549+ __u32 mode, reqmode = GR_FIND;
72550+
72551+ if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
72552+ reqmode |= GR_EXEC;
72553+ if (fmode & S_IWOTH)
72554+ reqmode |= GR_WRITE;
72555+ if (fmode & S_IROTH)
72556+ reqmode |= GR_READ;
72557+
72558+ mode =
72559+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
72560+ mnt);
72561+
72562+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
72563+ gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
72564+ reqmode & GR_READ ? " reading" : "",
72565+ reqmode & GR_WRITE ? " writing" : "",
72566+ reqmode & GR_EXEC ? " executing" : "");
72567+ return reqmode;
72568+ } else
72569+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
72570+ {
72571+ gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
72572+ reqmode & GR_READ ? " reading" : "",
72573+ reqmode & GR_WRITE ? " writing" : "",
72574+ reqmode & GR_EXEC ? " executing" : "");
72575+ return 0;
72576+ } else if (unlikely((mode & reqmode) != reqmode))
72577+ return 0;
72578+
72579+ return reqmode;
72580+}
72581+
72582+static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
72583+{
72584+ __u32 mode;
72585+
72586+ mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
72587+
72588+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
72589+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
72590+ return mode;
72591+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
72592+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
72593+ return 0;
72594+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
72595+ return 0;
72596+
72597+ return (reqmode);
72598+}
72599+
72600+__u32
72601+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
72602+{
72603+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
72604+}
72605+
72606+__u32
72607+gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
72608+{
72609+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
72610+}
72611+
72612+__u32
72613+gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
72614+{
72615+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
72616+}
72617+
72618+__u32
72619+gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
72620+{
72621+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
72622+}
72623+
72624+__u32
72625+gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
72626+ umode_t *modeptr)
72627+{
72628+ umode_t mode;
72629+
72630+ *modeptr &= ~gr_acl_umask();
72631+ mode = *modeptr;
72632+
72633+ if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
72634+ return 1;
72635+
72636+ if (unlikely(dentry->d_inode && !S_ISDIR(dentry->d_inode->i_mode) &&
72637+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))) {
72638+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
72639+ GR_CHMOD_ACL_MSG);
72640+ } else {
72641+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
72642+ }
72643+}
72644+
72645+__u32
72646+gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
72647+{
72648+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
72649+}
72650+
72651+__u32
72652+gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
72653+{
72654+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
72655+}
72656+
72657+__u32
72658+gr_acl_handle_removexattr(const struct dentry *dentry, const struct vfsmount *mnt)
72659+{
72660+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_REMOVEXATTR_ACL_MSG);
72661+}
72662+
72663+__u32
72664+gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
72665+{
72666+ return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
72667+}
72668+
72669+__u32
72670+gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
72671+{
72672+ return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
72673+ GR_UNIXCONNECT_ACL_MSG);
72674+}
72675+
72676+/* hardlinks require at minimum create and link permission,
72677+ any additional privilege required is based on the
72678+ privilege of the file being linked to
72679+*/
72680+__u32
72681+gr_acl_handle_link(const struct dentry * new_dentry,
72682+ const struct dentry * parent_dentry,
72683+ const struct vfsmount * parent_mnt,
72684+ const struct dentry * old_dentry,
72685+ const struct vfsmount * old_mnt, const struct filename *to)
72686+{
72687+ __u32 mode;
72688+ __u32 needmode = GR_CREATE | GR_LINK;
72689+ __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
72690+
72691+ mode =
72692+ gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
72693+ old_mnt);
72694+
72695+ if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
72696+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
72697+ return mode;
72698+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
72699+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
72700+ return 0;
72701+ } else if (unlikely((mode & needmode) != needmode))
72702+ return 0;
72703+
72704+ return 1;
72705+}
72706+
72707+__u32
72708+gr_acl_handle_symlink(const struct dentry * new_dentry,
72709+ const struct dentry * parent_dentry,
72710+ const struct vfsmount * parent_mnt, const struct filename *from)
72711+{
72712+ __u32 needmode = GR_WRITE | GR_CREATE;
72713+ __u32 mode;
72714+
72715+ mode =
72716+ gr_check_create(new_dentry, parent_dentry, parent_mnt,
72717+ GR_CREATE | GR_AUDIT_CREATE |
72718+ GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
72719+
72720+ if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
72721+ gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
72722+ return mode;
72723+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
72724+ gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
72725+ return 0;
72726+ } else if (unlikely((mode & needmode) != needmode))
72727+ return 0;
72728+
72729+ return (GR_WRITE | GR_CREATE);
72730+}
72731+
72732+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)
72733+{
72734+ __u32 mode;
72735+
72736+ mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
72737+
72738+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
72739+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
72740+ return mode;
72741+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
72742+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
72743+ return 0;
72744+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
72745+ return 0;
72746+
72747+ return (reqmode);
72748+}
72749+
72750+__u32
72751+gr_acl_handle_mknod(const struct dentry * new_dentry,
72752+ const struct dentry * parent_dentry,
72753+ const struct vfsmount * parent_mnt,
72754+ const int mode)
72755+{
72756+ __u32 reqmode = GR_WRITE | GR_CREATE;
72757+ if (unlikely((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
72758+ reqmode |= GR_SETID;
72759+
72760+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
72761+ reqmode, GR_MKNOD_ACL_MSG);
72762+}
72763+
72764+__u32
72765+gr_acl_handle_mkdir(const struct dentry *new_dentry,
72766+ const struct dentry *parent_dentry,
72767+ const struct vfsmount *parent_mnt)
72768+{
72769+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
72770+ GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
72771+}
72772+
72773+#define RENAME_CHECK_SUCCESS(old, new) \
72774+ (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
72775+ ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
72776+
72777+int
72778+gr_acl_handle_rename(struct dentry *new_dentry,
72779+ struct dentry *parent_dentry,
72780+ const struct vfsmount *parent_mnt,
72781+ struct dentry *old_dentry,
72782+ struct inode *old_parent_inode,
72783+ struct vfsmount *old_mnt, const struct filename *newname, unsigned int flags)
72784+{
72785+ __u32 comp1, comp2;
72786+ int error = 0;
72787+
72788+ if (unlikely(!gr_acl_is_enabled()))
72789+ return 0;
72790+
72791+ if (flags & RENAME_EXCHANGE) {
72792+ comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
72793+ GR_AUDIT_READ | GR_AUDIT_WRITE |
72794+ GR_SUPPRESS, parent_mnt);
72795+ comp2 =
72796+ gr_search_file(old_dentry,
72797+ GR_READ | GR_WRITE | GR_AUDIT_READ |
72798+ GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
72799+ } else if (d_is_negative(new_dentry)) {
72800+ comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
72801+ GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
72802+ GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
72803+ comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
72804+ GR_DELETE | GR_AUDIT_DELETE |
72805+ GR_AUDIT_READ | GR_AUDIT_WRITE |
72806+ GR_SUPPRESS, old_mnt);
72807+ } else {
72808+ comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
72809+ GR_CREATE | GR_DELETE |
72810+ GR_AUDIT_CREATE | GR_AUDIT_DELETE |
72811+ GR_AUDIT_READ | GR_AUDIT_WRITE |
72812+ GR_SUPPRESS, parent_mnt);
72813+ comp2 =
72814+ gr_search_file(old_dentry,
72815+ GR_READ | GR_WRITE | GR_AUDIT_READ |
72816+ GR_DELETE | GR_AUDIT_DELETE |
72817+ GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
72818+ }
72819+
72820+ if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
72821+ ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
72822+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
72823+ else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
72824+ && !(comp2 & GR_SUPPRESS)) {
72825+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
72826+ error = -EACCES;
72827+ } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
72828+ error = -EACCES;
72829+
72830+ return error;
72831+}
72832+
72833+void
72834+gr_acl_handle_exit(void)
72835+{
72836+ u16 id;
72837+ char *rolename;
72838+
72839+ if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
72840+ !(current->role->roletype & GR_ROLE_PERSIST))) {
72841+ id = current->acl_role_id;
72842+ rolename = current->role->rolename;
72843+ gr_set_acls(1);
72844+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
72845+ }
72846+
72847+ gr_put_exec_file(current);
72848+ return;
72849+}
72850+
72851+int
72852+gr_acl_handle_procpidmem(const struct task_struct *task)
72853+{
72854+ if (unlikely(!gr_acl_is_enabled()))
72855+ return 0;
72856+
72857+ if (task != current && (task->acl->mode & GR_PROTPROCFD) &&
72858+ !(current->acl->mode & GR_POVERRIDE) &&
72859+ !(current->role->roletype & GR_ROLE_GOD))
72860+ return -EACCES;
72861+
72862+ return 0;
72863+}
72864diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
72865new file mode 100644
72866index 0000000..f056b81
72867--- /dev/null
72868+++ b/grsecurity/gracl_ip.c
72869@@ -0,0 +1,386 @@
72870+#include <linux/kernel.h>
72871+#include <asm/uaccess.h>
72872+#include <asm/errno.h>
72873+#include <net/sock.h>
72874+#include <linux/file.h>
72875+#include <linux/fs.h>
72876+#include <linux/net.h>
72877+#include <linux/in.h>
72878+#include <linux/skbuff.h>
72879+#include <linux/ip.h>
72880+#include <linux/udp.h>
72881+#include <linux/types.h>
72882+#include <linux/sched.h>
72883+#include <linux/netdevice.h>
72884+#include <linux/inetdevice.h>
72885+#include <linux/gracl.h>
72886+#include <linux/grsecurity.h>
72887+#include <linux/grinternal.h>
72888+
72889+#define GR_BIND 0x01
72890+#define GR_CONNECT 0x02
72891+#define GR_INVERT 0x04
72892+#define GR_BINDOVERRIDE 0x08
72893+#define GR_CONNECTOVERRIDE 0x10
72894+#define GR_SOCK_FAMILY 0x20
72895+
72896+static const char * gr_protocols[IPPROTO_MAX] = {
72897+ "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
72898+ "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
72899+ "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
72900+ "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
72901+ "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
72902+ "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
72903+ "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
72904+ "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
72905+ "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
72906+ "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
72907+ "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
72908+ "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
72909+ "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
72910+ "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
72911+ "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
72912+ "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
72913+ "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
72914+ "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
72915+ "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
72916+ "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
72917+ "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
72918+ "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
72919+ "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
72920+ "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
72921+ "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
72922+ "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
72923+ "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
72924+ "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
72925+ "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
72926+ "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
72927+ "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
72928+ "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
72929+ };
72930+
72931+static const char * gr_socktypes[SOCK_MAX] = {
72932+ "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
72933+ "unknown:7", "unknown:8", "unknown:9", "packet"
72934+ };
72935+
72936+static const char * gr_sockfamilies[AF_MAX+1] = {
72937+ "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
72938+ "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
72939+ "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
72940+ "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
72941+ };
72942+
72943+const char *
72944+gr_proto_to_name(unsigned char proto)
72945+{
72946+ return gr_protocols[proto];
72947+}
72948+
72949+const char *
72950+gr_socktype_to_name(unsigned char type)
72951+{
72952+ return gr_socktypes[type];
72953+}
72954+
72955+const char *
72956+gr_sockfamily_to_name(unsigned char family)
72957+{
72958+ return gr_sockfamilies[family];
72959+}
72960+
72961+extern const struct net_proto_family __rcu *net_families[NPROTO] __read_mostly;
72962+
72963+int
72964+gr_search_socket(const int domain, const int type, const int protocol)
72965+{
72966+ struct acl_subject_label *curr;
72967+ const struct cred *cred = current_cred();
72968+
72969+ if (unlikely(!gr_acl_is_enabled()))
72970+ goto exit;
72971+
72972+ if ((domain < 0) || (type < 0) || (protocol < 0) ||
72973+ (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
72974+ goto exit; // let the kernel handle it
72975+
72976+ curr = current->acl;
72977+
72978+ if (curr->sock_families[domain / 32] & (1U << (domain % 32))) {
72979+ /* the family is allowed, if this is PF_INET allow it only if
72980+ the extra sock type/protocol checks pass */
72981+ if (domain == PF_INET)
72982+ goto inet_check;
72983+ goto exit;
72984+ } else {
72985+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
72986+ __u32 fakeip = 0;
72987+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
72988+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
72989+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
72990+ gr_to_filename(current->exec_file->f_path.dentry,
72991+ current->exec_file->f_path.mnt) :
72992+ curr->filename, curr->filename,
72993+ &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
72994+ &current->signal->saved_ip);
72995+ goto exit;
72996+ }
72997+ goto exit_fail;
72998+ }
72999+
73000+inet_check:
73001+ /* the rest of this checking is for IPv4 only */
73002+ if (!curr->ips)
73003+ goto exit;
73004+
73005+ if ((curr->ip_type & (1U << type)) &&
73006+ (curr->ip_proto[protocol / 32] & (1U << (protocol % 32))))
73007+ goto exit;
73008+
73009+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
73010+ /* we don't place acls on raw sockets , and sometimes
73011+ dgram/ip sockets are opened for ioctl and not
73012+ bind/connect, so we'll fake a bind learn log */
73013+ if (type == SOCK_RAW || type == SOCK_PACKET) {
73014+ __u32 fakeip = 0;
73015+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
73016+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
73017+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
73018+ gr_to_filename(current->exec_file->f_path.dentry,
73019+ current->exec_file->f_path.mnt) :
73020+ curr->filename, curr->filename,
73021+ &fakeip, 0, type,
73022+ protocol, GR_CONNECT, &current->signal->saved_ip);
73023+ } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
73024+ __u32 fakeip = 0;
73025+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
73026+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
73027+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
73028+ gr_to_filename(current->exec_file->f_path.dentry,
73029+ current->exec_file->f_path.mnt) :
73030+ curr->filename, curr->filename,
73031+ &fakeip, 0, type,
73032+ protocol, GR_BIND, &current->signal->saved_ip);
73033+ }
73034+ /* we'll log when they use connect or bind */
73035+ goto exit;
73036+ }
73037+
73038+exit_fail:
73039+ if (domain == PF_INET)
73040+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
73041+ gr_socktype_to_name(type), gr_proto_to_name(protocol));
73042+ else if (rcu_access_pointer(net_families[domain]) != NULL)
73043+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
73044+ gr_socktype_to_name(type), protocol);
73045+
73046+ return 0;
73047+exit:
73048+ return 1;
73049+}
73050+
73051+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)
73052+{
73053+ if ((ip->mode & mode) &&
73054+ (ip_port >= ip->low) &&
73055+ (ip_port <= ip->high) &&
73056+ ((ntohl(ip_addr) & our_netmask) ==
73057+ (ntohl(our_addr) & our_netmask))
73058+ && (ip->proto[protocol / 32] & (1U << (protocol % 32)))
73059+ && (ip->type & (1U << type))) {
73060+ if (ip->mode & GR_INVERT)
73061+ return 2; // specifically denied
73062+ else
73063+ return 1; // allowed
73064+ }
73065+
73066+ return 0; // not specifically allowed, may continue parsing
73067+}
73068+
73069+static int
73070+gr_search_connectbind(const int full_mode, struct sock *sk,
73071+ struct sockaddr_in *addr, const int type)
73072+{
73073+ char iface[IFNAMSIZ] = {0};
73074+ struct acl_subject_label *curr;
73075+ struct acl_ip_label *ip;
73076+ struct inet_sock *isk;
73077+ struct net_device *dev;
73078+ struct in_device *idev;
73079+ unsigned long i;
73080+ int ret;
73081+ int mode = full_mode & (GR_BIND | GR_CONNECT);
73082+ __u32 ip_addr = 0;
73083+ __u32 our_addr;
73084+ __u32 our_netmask;
73085+ char *p;
73086+ __u16 ip_port = 0;
73087+ const struct cred *cred = current_cred();
73088+
73089+ if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
73090+ return 0;
73091+
73092+ curr = current->acl;
73093+ isk = inet_sk(sk);
73094+
73095+ /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
73096+ if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
73097+ addr->sin_addr.s_addr = curr->inaddr_any_override;
73098+ if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
73099+ struct sockaddr_in saddr;
73100+ int err;
73101+
73102+ saddr.sin_family = AF_INET;
73103+ saddr.sin_addr.s_addr = curr->inaddr_any_override;
73104+ saddr.sin_port = isk->inet_sport;
73105+
73106+ err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
73107+ if (err)
73108+ return err;
73109+
73110+ err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
73111+ if (err)
73112+ return err;
73113+ }
73114+
73115+ if (!curr->ips)
73116+ return 0;
73117+
73118+ ip_addr = addr->sin_addr.s_addr;
73119+ ip_port = ntohs(addr->sin_port);
73120+
73121+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
73122+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
73123+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
73124+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
73125+ gr_to_filename(current->exec_file->f_path.dentry,
73126+ current->exec_file->f_path.mnt) :
73127+ curr->filename, curr->filename,
73128+ &ip_addr, ip_port, type,
73129+ sk->sk_protocol, mode, &current->signal->saved_ip);
73130+ return 0;
73131+ }
73132+
73133+ for (i = 0; i < curr->ip_num; i++) {
73134+ ip = *(curr->ips + i);
73135+ if (ip->iface != NULL) {
73136+ strncpy(iface, ip->iface, IFNAMSIZ - 1);
73137+ p = strchr(iface, ':');
73138+ if (p != NULL)
73139+ *p = '\0';
73140+ dev = dev_get_by_name(sock_net(sk), iface);
73141+ if (dev == NULL)
73142+ continue;
73143+ idev = in_dev_get(dev);
73144+ if (idev == NULL) {
73145+ dev_put(dev);
73146+ continue;
73147+ }
73148+ rcu_read_lock();
73149+ for_ifa(idev) {
73150+ if (!strcmp(ip->iface, ifa->ifa_label)) {
73151+ our_addr = ifa->ifa_address;
73152+ our_netmask = 0xffffffff;
73153+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
73154+ if (ret == 1) {
73155+ rcu_read_unlock();
73156+ in_dev_put(idev);
73157+ dev_put(dev);
73158+ return 0;
73159+ } else if (ret == 2) {
73160+ rcu_read_unlock();
73161+ in_dev_put(idev);
73162+ dev_put(dev);
73163+ goto denied;
73164+ }
73165+ }
73166+ } endfor_ifa(idev);
73167+ rcu_read_unlock();
73168+ in_dev_put(idev);
73169+ dev_put(dev);
73170+ } else {
73171+ our_addr = ip->addr;
73172+ our_netmask = ip->netmask;
73173+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
73174+ if (ret == 1)
73175+ return 0;
73176+ else if (ret == 2)
73177+ goto denied;
73178+ }
73179+ }
73180+
73181+denied:
73182+ if (mode == GR_BIND)
73183+ 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));
73184+ else if (mode == GR_CONNECT)
73185+ 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));
73186+
73187+ return -EACCES;
73188+}
73189+
73190+int
73191+gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
73192+{
73193+ /* always allow disconnection of dgram sockets with connect */
73194+ if (addr->sin_family == AF_UNSPEC)
73195+ return 0;
73196+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
73197+}
73198+
73199+int
73200+gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
73201+{
73202+ return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
73203+}
73204+
73205+int gr_search_listen(struct socket *sock)
73206+{
73207+ struct sock *sk = sock->sk;
73208+ struct sockaddr_in addr;
73209+
73210+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
73211+ addr.sin_port = inet_sk(sk)->inet_sport;
73212+
73213+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
73214+}
73215+
73216+int gr_search_accept(struct socket *sock)
73217+{
73218+ struct sock *sk = sock->sk;
73219+ struct sockaddr_in addr;
73220+
73221+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
73222+ addr.sin_port = inet_sk(sk)->inet_sport;
73223+
73224+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
73225+}
73226+
73227+int
73228+gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
73229+{
73230+ if (addr)
73231+ return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
73232+ else {
73233+ struct sockaddr_in sin;
73234+ const struct inet_sock *inet = inet_sk(sk);
73235+
73236+ sin.sin_addr.s_addr = inet->inet_daddr;
73237+ sin.sin_port = inet->inet_dport;
73238+
73239+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
73240+ }
73241+}
73242+
73243+int
73244+gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
73245+{
73246+ struct sockaddr_in sin;
73247+
73248+ if (unlikely(skb->len < sizeof (struct udphdr)))
73249+ return 0; // skip this packet
73250+
73251+ sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
73252+ sin.sin_port = udp_hdr(skb)->source;
73253+
73254+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
73255+}
73256diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
73257new file mode 100644
73258index 0000000..25f54ef
73259--- /dev/null
73260+++ b/grsecurity/gracl_learn.c
73261@@ -0,0 +1,207 @@
73262+#include <linux/kernel.h>
73263+#include <linux/mm.h>
73264+#include <linux/sched.h>
73265+#include <linux/poll.h>
73266+#include <linux/string.h>
73267+#include <linux/file.h>
73268+#include <linux/types.h>
73269+#include <linux/vmalloc.h>
73270+#include <linux/grinternal.h>
73271+
73272+extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
73273+ size_t count, loff_t *ppos);
73274+extern int gr_acl_is_enabled(void);
73275+
73276+static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
73277+static int gr_learn_attached;
73278+
73279+/* use a 512k buffer */
73280+#define LEARN_BUFFER_SIZE (512 * 1024)
73281+
73282+static DEFINE_SPINLOCK(gr_learn_lock);
73283+static DEFINE_MUTEX(gr_learn_user_mutex);
73284+
73285+/* we need to maintain two buffers, so that the kernel context of grlearn
73286+ uses a semaphore around the userspace copying, and the other kernel contexts
73287+ use a spinlock when copying into the buffer, since they cannot sleep
73288+*/
73289+static char *learn_buffer;
73290+static char *learn_buffer_user;
73291+static int learn_buffer_len;
73292+static int learn_buffer_user_len;
73293+
73294+static ssize_t
73295+read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
73296+{
73297+ DECLARE_WAITQUEUE(wait, current);
73298+ ssize_t retval = 0;
73299+
73300+ add_wait_queue(&learn_wait, &wait);
73301+ set_current_state(TASK_INTERRUPTIBLE);
73302+ do {
73303+ mutex_lock(&gr_learn_user_mutex);
73304+ spin_lock(&gr_learn_lock);
73305+ if (learn_buffer_len)
73306+ break;
73307+ spin_unlock(&gr_learn_lock);
73308+ mutex_unlock(&gr_learn_user_mutex);
73309+ if (file->f_flags & O_NONBLOCK) {
73310+ retval = -EAGAIN;
73311+ goto out;
73312+ }
73313+ if (signal_pending(current)) {
73314+ retval = -ERESTARTSYS;
73315+ goto out;
73316+ }
73317+
73318+ schedule();
73319+ } while (1);
73320+
73321+ memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
73322+ learn_buffer_user_len = learn_buffer_len;
73323+ retval = learn_buffer_len;
73324+ learn_buffer_len = 0;
73325+
73326+ spin_unlock(&gr_learn_lock);
73327+
73328+ if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
73329+ retval = -EFAULT;
73330+
73331+ mutex_unlock(&gr_learn_user_mutex);
73332+out:
73333+ set_current_state(TASK_RUNNING);
73334+ remove_wait_queue(&learn_wait, &wait);
73335+ return retval;
73336+}
73337+
73338+static unsigned int
73339+poll_learn(struct file * file, poll_table * wait)
73340+{
73341+ poll_wait(file, &learn_wait, wait);
73342+
73343+ if (learn_buffer_len)
73344+ return (POLLIN | POLLRDNORM);
73345+
73346+ return 0;
73347+}
73348+
73349+void
73350+gr_clear_learn_entries(void)
73351+{
73352+ char *tmp;
73353+
73354+ mutex_lock(&gr_learn_user_mutex);
73355+ spin_lock(&gr_learn_lock);
73356+ tmp = learn_buffer;
73357+ learn_buffer = NULL;
73358+ spin_unlock(&gr_learn_lock);
73359+ if (tmp)
73360+ vfree(tmp);
73361+ if (learn_buffer_user != NULL) {
73362+ vfree(learn_buffer_user);
73363+ learn_buffer_user = NULL;
73364+ }
73365+ learn_buffer_len = 0;
73366+ mutex_unlock(&gr_learn_user_mutex);
73367+
73368+ return;
73369+}
73370+
73371+void
73372+gr_add_learn_entry(const char *fmt, ...)
73373+{
73374+ va_list args;
73375+ unsigned int len;
73376+
73377+ if (!gr_learn_attached)
73378+ return;
73379+
73380+ spin_lock(&gr_learn_lock);
73381+
73382+ /* leave a gap at the end so we know when it's "full" but don't have to
73383+ compute the exact length of the string we're trying to append
73384+ */
73385+ if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
73386+ spin_unlock(&gr_learn_lock);
73387+ wake_up_interruptible(&learn_wait);
73388+ return;
73389+ }
73390+ if (learn_buffer == NULL) {
73391+ spin_unlock(&gr_learn_lock);
73392+ return;
73393+ }
73394+
73395+ va_start(args, fmt);
73396+ len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
73397+ va_end(args);
73398+
73399+ learn_buffer_len += len + 1;
73400+
73401+ spin_unlock(&gr_learn_lock);
73402+ wake_up_interruptible(&learn_wait);
73403+
73404+ return;
73405+}
73406+
73407+static int
73408+open_learn(struct inode *inode, struct file *file)
73409+{
73410+ if (file->f_mode & FMODE_READ && gr_learn_attached)
73411+ return -EBUSY;
73412+ if (file->f_mode & FMODE_READ) {
73413+ int retval = 0;
73414+ mutex_lock(&gr_learn_user_mutex);
73415+ if (learn_buffer == NULL)
73416+ learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
73417+ if (learn_buffer_user == NULL)
73418+ learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
73419+ if (learn_buffer == NULL) {
73420+ retval = -ENOMEM;
73421+ goto out_error;
73422+ }
73423+ if (learn_buffer_user == NULL) {
73424+ retval = -ENOMEM;
73425+ goto out_error;
73426+ }
73427+ learn_buffer_len = 0;
73428+ learn_buffer_user_len = 0;
73429+ gr_learn_attached = 1;
73430+out_error:
73431+ mutex_unlock(&gr_learn_user_mutex);
73432+ return retval;
73433+ }
73434+ return 0;
73435+}
73436+
73437+static int
73438+close_learn(struct inode *inode, struct file *file)
73439+{
73440+ if (file->f_mode & FMODE_READ) {
73441+ char *tmp = NULL;
73442+ mutex_lock(&gr_learn_user_mutex);
73443+ spin_lock(&gr_learn_lock);
73444+ tmp = learn_buffer;
73445+ learn_buffer = NULL;
73446+ spin_unlock(&gr_learn_lock);
73447+ if (tmp)
73448+ vfree(tmp);
73449+ if (learn_buffer_user != NULL) {
73450+ vfree(learn_buffer_user);
73451+ learn_buffer_user = NULL;
73452+ }
73453+ learn_buffer_len = 0;
73454+ learn_buffer_user_len = 0;
73455+ gr_learn_attached = 0;
73456+ mutex_unlock(&gr_learn_user_mutex);
73457+ }
73458+
73459+ return 0;
73460+}
73461+
73462+const struct file_operations grsec_fops = {
73463+ .read = read_learn,
73464+ .write = write_grsec_handler,
73465+ .open = open_learn,
73466+ .release = close_learn,
73467+ .poll = poll_learn,
73468+};
73469diff --git a/grsecurity/gracl_policy.c b/grsecurity/gracl_policy.c
73470new file mode 100644
73471index 0000000..3f8ade0
73472--- /dev/null
73473+++ b/grsecurity/gracl_policy.c
73474@@ -0,0 +1,1782 @@
73475+#include <linux/kernel.h>
73476+#include <linux/module.h>
73477+#include <linux/sched.h>
73478+#include <linux/mm.h>
73479+#include <linux/file.h>
73480+#include <linux/fs.h>
73481+#include <linux/namei.h>
73482+#include <linux/mount.h>
73483+#include <linux/tty.h>
73484+#include <linux/proc_fs.h>
73485+#include <linux/lglock.h>
73486+#include <linux/slab.h>
73487+#include <linux/vmalloc.h>
73488+#include <linux/types.h>
73489+#include <linux/sysctl.h>
73490+#include <linux/netdevice.h>
73491+#include <linux/ptrace.h>
73492+#include <linux/gracl.h>
73493+#include <linux/gralloc.h>
73494+#include <linux/security.h>
73495+#include <linux/grinternal.h>
73496+#include <linux/pid_namespace.h>
73497+#include <linux/stop_machine.h>
73498+#include <linux/fdtable.h>
73499+#include <linux/percpu.h>
73500+#include <linux/lglock.h>
73501+#include <linux/hugetlb.h>
73502+#include <linux/posix-timers.h>
73503+#include "../fs/mount.h"
73504+
73505+#include <asm/uaccess.h>
73506+#include <asm/errno.h>
73507+#include <asm/mman.h>
73508+
73509+extern struct gr_policy_state *polstate;
73510+
73511+#define FOR_EACH_ROLE_START(role) \
73512+ role = polstate->role_list; \
73513+ while (role) {
73514+
73515+#define FOR_EACH_ROLE_END(role) \
73516+ role = role->prev; \
73517+ }
73518+
73519+struct path gr_real_root;
73520+
73521+extern struct gr_alloc_state *current_alloc_state;
73522+
73523+u16 acl_sp_role_value;
73524+
73525+static DEFINE_MUTEX(gr_dev_mutex);
73526+
73527+extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
73528+extern void gr_clear_learn_entries(void);
73529+
73530+struct gr_arg *gr_usermode __read_only;
73531+unsigned char *gr_system_salt __read_only;
73532+unsigned char *gr_system_sum __read_only;
73533+
73534+static unsigned int gr_auth_attempts = 0;
73535+static unsigned long gr_auth_expires = 0UL;
73536+
73537+struct acl_object_label *fakefs_obj_rw;
73538+struct acl_object_label *fakefs_obj_rwx;
73539+
73540+extern int gr_init_uidset(void);
73541+extern void gr_free_uidset(void);
73542+extern void gr_remove_uid(uid_t uid);
73543+extern int gr_find_uid(uid_t uid);
73544+
73545+extern struct acl_subject_label *__gr_get_subject_for_task(const struct gr_policy_state *state, struct task_struct *task, const char *filename);
73546+extern void __gr_apply_subject_to_task(struct gr_policy_state *state, struct task_struct *task, struct acl_subject_label *subj);
73547+extern int gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb);
73548+extern void __insert_inodev_entry(const struct gr_policy_state *state, struct inodev_entry *entry);
73549+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);
73550+extern void insert_acl_obj_label(struct acl_object_label *obj, struct acl_subject_label *subj);
73551+extern void insert_acl_subj_label(struct acl_subject_label *obj, struct acl_role_label *role);
73552+extern struct name_entry * __lookup_name_entry(const struct gr_policy_state *state, const char *name);
73553+extern char *gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt);
73554+extern struct acl_subject_label *lookup_acl_subj_label(const ino_t ino, const dev_t dev, const struct acl_role_label *role);
73555+extern struct acl_subject_label *lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev, const struct acl_role_label *role);
73556+extern void assign_special_role(const char *rolename);
73557+extern struct acl_subject_label *chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt, const struct acl_role_label *role);
73558+extern int gr_rbac_disable(void *unused);
73559+extern void gr_enable_rbac_system(void);
73560+
73561+static int copy_acl_object_label_normal(struct acl_object_label *obj, const struct acl_object_label *userp)
73562+{
73563+ if (copy_from_user(obj, userp, sizeof(struct acl_object_label)))
73564+ return -EFAULT;
73565+
73566+ return 0;
73567+}
73568+
73569+static int copy_acl_ip_label_normal(struct acl_ip_label *ip, const struct acl_ip_label *userp)
73570+{
73571+ if (copy_from_user(ip, userp, sizeof(struct acl_ip_label)))
73572+ return -EFAULT;
73573+
73574+ return 0;
73575+}
73576+
73577+static int copy_acl_subject_label_normal(struct acl_subject_label *subj, const struct acl_subject_label *userp)
73578+{
73579+ if (copy_from_user(subj, userp, sizeof(struct acl_subject_label)))
73580+ return -EFAULT;
73581+
73582+ return 0;
73583+}
73584+
73585+static int copy_acl_role_label_normal(struct acl_role_label *role, const struct acl_role_label *userp)
73586+{
73587+ if (copy_from_user(role, userp, sizeof(struct acl_role_label)))
73588+ return -EFAULT;
73589+
73590+ return 0;
73591+}
73592+
73593+static int copy_role_allowed_ip_normal(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp)
73594+{
73595+ if (copy_from_user(roleip, userp, sizeof(struct role_allowed_ip)))
73596+ return -EFAULT;
73597+
73598+ return 0;
73599+}
73600+
73601+static int copy_sprole_pw_normal(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp)
73602+{
73603+ if (copy_from_user(pw, userp + idx, sizeof(struct sprole_pw)))
73604+ return -EFAULT;
73605+
73606+ return 0;
73607+}
73608+
73609+static int copy_gr_hash_struct_normal(struct gr_hash_struct *hash, const struct gr_hash_struct *userp)
73610+{
73611+ if (copy_from_user(hash, userp, sizeof(struct gr_hash_struct)))
73612+ return -EFAULT;
73613+
73614+ return 0;
73615+}
73616+
73617+static int copy_role_transition_normal(struct role_transition *trans, const struct role_transition *userp)
73618+{
73619+ if (copy_from_user(trans, userp, sizeof(struct role_transition)))
73620+ return -EFAULT;
73621+
73622+ return 0;
73623+}
73624+
73625+int copy_pointer_from_array_normal(void *ptr, unsigned long idx, const void *userp)
73626+{
73627+ if (copy_from_user(ptr, userp + (idx * sizeof(void *)), sizeof(void *)))
73628+ return -EFAULT;
73629+
73630+ return 0;
73631+}
73632+
73633+static int copy_gr_arg_wrapper_normal(const char __user *buf, struct gr_arg_wrapper *uwrap)
73634+{
73635+ if (copy_from_user(uwrap, buf, sizeof (struct gr_arg_wrapper)))
73636+ return -EFAULT;
73637+
73638+ if (((uwrap->version != GRSECURITY_VERSION) &&
73639+ (uwrap->version != 0x2901)) ||
73640+ (uwrap->size != sizeof(struct gr_arg)))
73641+ return -EINVAL;
73642+
73643+ return 0;
73644+}
73645+
73646+static int copy_gr_arg_normal(const struct gr_arg __user *buf, struct gr_arg *arg)
73647+{
73648+ if (copy_from_user(arg, buf, sizeof (struct gr_arg)))
73649+ return -EFAULT;
73650+
73651+ return 0;
73652+}
73653+
73654+static size_t get_gr_arg_wrapper_size_normal(void)
73655+{
73656+ return sizeof(struct gr_arg_wrapper);
73657+}
73658+
73659+#ifdef CONFIG_COMPAT
73660+extern int copy_gr_arg_wrapper_compat(const char *buf, struct gr_arg_wrapper *uwrap);
73661+extern int copy_gr_arg_compat(const struct gr_arg __user *buf, struct gr_arg *arg);
73662+extern int copy_acl_object_label_compat(struct acl_object_label *obj, const struct acl_object_label *userp);
73663+extern int copy_acl_subject_label_compat(struct acl_subject_label *subj, const struct acl_subject_label *userp);
73664+extern int copy_acl_role_label_compat(struct acl_role_label *role, const struct acl_role_label *userp);
73665+extern int copy_role_allowed_ip_compat(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp);
73666+extern int copy_role_transition_compat(struct role_transition *trans, const struct role_transition *userp);
73667+extern int copy_gr_hash_struct_compat(struct gr_hash_struct *hash, const struct gr_hash_struct *userp);
73668+extern int copy_pointer_from_array_compat(void *ptr, unsigned long idx, const void *userp);
73669+extern int copy_acl_ip_label_compat(struct acl_ip_label *ip, const struct acl_ip_label *userp);
73670+extern int copy_sprole_pw_compat(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp);
73671+extern size_t get_gr_arg_wrapper_size_compat(void);
73672+
73673+int (* copy_gr_arg_wrapper)(const char *buf, struct gr_arg_wrapper *uwrap) __read_only;
73674+int (* copy_gr_arg)(const struct gr_arg *buf, struct gr_arg *arg) __read_only;
73675+int (* copy_acl_object_label)(struct acl_object_label *obj, const struct acl_object_label *userp) __read_only;
73676+int (* copy_acl_subject_label)(struct acl_subject_label *subj, const struct acl_subject_label *userp) __read_only;
73677+int (* copy_acl_role_label)(struct acl_role_label *role, const struct acl_role_label *userp) __read_only;
73678+int (* copy_acl_ip_label)(struct acl_ip_label *ip, const struct acl_ip_label *userp) __read_only;
73679+int (* copy_pointer_from_array)(void *ptr, unsigned long idx, const void *userp) __read_only;
73680+int (* copy_sprole_pw)(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp) __read_only;
73681+int (* copy_gr_hash_struct)(struct gr_hash_struct *hash, const struct gr_hash_struct *userp) __read_only;
73682+int (* copy_role_transition)(struct role_transition *trans, const struct role_transition *userp) __read_only;
73683+int (* copy_role_allowed_ip)(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp) __read_only;
73684+size_t (* get_gr_arg_wrapper_size)(void) __read_only;
73685+
73686+#else
73687+#define copy_gr_arg_wrapper copy_gr_arg_wrapper_normal
73688+#define copy_gr_arg copy_gr_arg_normal
73689+#define copy_gr_hash_struct copy_gr_hash_struct_normal
73690+#define copy_acl_object_label copy_acl_object_label_normal
73691+#define copy_acl_subject_label copy_acl_subject_label_normal
73692+#define copy_acl_role_label copy_acl_role_label_normal
73693+#define copy_acl_ip_label copy_acl_ip_label_normal
73694+#define copy_pointer_from_array copy_pointer_from_array_normal
73695+#define copy_sprole_pw copy_sprole_pw_normal
73696+#define copy_role_transition copy_role_transition_normal
73697+#define copy_role_allowed_ip copy_role_allowed_ip_normal
73698+#define get_gr_arg_wrapper_size get_gr_arg_wrapper_size_normal
73699+#endif
73700+
73701+static struct acl_subject_label *
73702+lookup_subject_map(const struct acl_subject_label *userp)
73703+{
73704+ unsigned int index = gr_shash(userp, polstate->subj_map_set.s_size);
73705+ struct subject_map *match;
73706+
73707+ match = polstate->subj_map_set.s_hash[index];
73708+
73709+ while (match && match->user != userp)
73710+ match = match->next;
73711+
73712+ if (match != NULL)
73713+ return match->kernel;
73714+ else
73715+ return NULL;
73716+}
73717+
73718+static void
73719+insert_subj_map_entry(struct subject_map *subjmap)
73720+{
73721+ unsigned int index = gr_shash(subjmap->user, polstate->subj_map_set.s_size);
73722+ struct subject_map **curr;
73723+
73724+ subjmap->prev = NULL;
73725+
73726+ curr = &polstate->subj_map_set.s_hash[index];
73727+ if (*curr != NULL)
73728+ (*curr)->prev = subjmap;
73729+
73730+ subjmap->next = *curr;
73731+ *curr = subjmap;
73732+
73733+ return;
73734+}
73735+
73736+static void
73737+__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
73738+{
73739+ unsigned int index =
73740+ gr_rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), polstate->acl_role_set.r_size);
73741+ struct acl_role_label **curr;
73742+ struct acl_role_label *tmp, *tmp2;
73743+
73744+ curr = &polstate->acl_role_set.r_hash[index];
73745+
73746+ /* simple case, slot is empty, just set it to our role */
73747+ if (*curr == NULL) {
73748+ *curr = role;
73749+ } else {
73750+ /* example:
73751+ 1 -> 2 -> 3 (adding 2 -> 3 to here)
73752+ 2 -> 3
73753+ */
73754+ /* first check to see if we can already be reached via this slot */
73755+ tmp = *curr;
73756+ while (tmp && tmp != role)
73757+ tmp = tmp->next;
73758+ if (tmp == role) {
73759+ /* we don't need to add ourselves to this slot's chain */
73760+ return;
73761+ }
73762+ /* we need to add ourselves to this chain, two cases */
73763+ if (role->next == NULL) {
73764+ /* simple case, append the current chain to our role */
73765+ role->next = *curr;
73766+ *curr = role;
73767+ } else {
73768+ /* 1 -> 2 -> 3 -> 4
73769+ 2 -> 3 -> 4
73770+ 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
73771+ */
73772+ /* trickier case: walk our role's chain until we find
73773+ the role for the start of the current slot's chain */
73774+ tmp = role;
73775+ tmp2 = *curr;
73776+ while (tmp->next && tmp->next != tmp2)
73777+ tmp = tmp->next;
73778+ if (tmp->next == tmp2) {
73779+ /* from example above, we found 3, so just
73780+ replace this slot's chain with ours */
73781+ *curr = role;
73782+ } else {
73783+ /* we didn't find a subset of our role's chain
73784+ in the current slot's chain, so append their
73785+ chain to ours, and set us as the first role in
73786+ the slot's chain
73787+
73788+ we could fold this case with the case above,
73789+ but making it explicit for clarity
73790+ */
73791+ tmp->next = tmp2;
73792+ *curr = role;
73793+ }
73794+ }
73795+ }
73796+
73797+ return;
73798+}
73799+
73800+static void
73801+insert_acl_role_label(struct acl_role_label *role)
73802+{
73803+ int i;
73804+
73805+ if (polstate->role_list == NULL) {
73806+ polstate->role_list = role;
73807+ role->prev = NULL;
73808+ } else {
73809+ role->prev = polstate->role_list;
73810+ polstate->role_list = role;
73811+ }
73812+
73813+ /* used for hash chains */
73814+ role->next = NULL;
73815+
73816+ if (role->roletype & GR_ROLE_DOMAIN) {
73817+ for (i = 0; i < role->domain_child_num; i++)
73818+ __insert_acl_role_label(role, role->domain_children[i]);
73819+ } else
73820+ __insert_acl_role_label(role, role->uidgid);
73821+}
73822+
73823+static int
73824+insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
73825+{
73826+ struct name_entry **curr, *nentry;
73827+ struct inodev_entry *ientry;
73828+ unsigned int len = strlen(name);
73829+ unsigned int key = full_name_hash(name, len);
73830+ unsigned int index = key % polstate->name_set.n_size;
73831+
73832+ curr = &polstate->name_set.n_hash[index];
73833+
73834+ while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
73835+ curr = &((*curr)->next);
73836+
73837+ if (*curr != NULL)
73838+ return 1;
73839+
73840+ nentry = acl_alloc(sizeof (struct name_entry));
73841+ if (nentry == NULL)
73842+ return 0;
73843+ ientry = acl_alloc(sizeof (struct inodev_entry));
73844+ if (ientry == NULL)
73845+ return 0;
73846+ ientry->nentry = nentry;
73847+
73848+ nentry->key = key;
73849+ nentry->name = name;
73850+ nentry->inode = inode;
73851+ nentry->device = device;
73852+ nentry->len = len;
73853+ nentry->deleted = deleted;
73854+
73855+ nentry->prev = NULL;
73856+ curr = &polstate->name_set.n_hash[index];
73857+ if (*curr != NULL)
73858+ (*curr)->prev = nentry;
73859+ nentry->next = *curr;
73860+ *curr = nentry;
73861+
73862+ /* insert us into the table searchable by inode/dev */
73863+ __insert_inodev_entry(polstate, ientry);
73864+
73865+ return 1;
73866+}
73867+
73868+/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
73869+
73870+static void *
73871+create_table(__u32 * len, int elementsize)
73872+{
73873+ unsigned int table_sizes[] = {
73874+ 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
73875+ 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
73876+ 4194301, 8388593, 16777213, 33554393, 67108859
73877+ };
73878+ void *newtable = NULL;
73879+ unsigned int pwr = 0;
73880+
73881+ while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
73882+ table_sizes[pwr] <= *len)
73883+ pwr++;
73884+
73885+ if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
73886+ return newtable;
73887+
73888+ if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
73889+ newtable =
73890+ kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
73891+ else
73892+ newtable = vmalloc(table_sizes[pwr] * elementsize);
73893+
73894+ *len = table_sizes[pwr];
73895+
73896+ return newtable;
73897+}
73898+
73899+static int
73900+init_variables(const struct gr_arg *arg, bool reload)
73901+{
73902+ struct task_struct *reaper = init_pid_ns.child_reaper;
73903+ unsigned int stacksize;
73904+
73905+ polstate->subj_map_set.s_size = arg->role_db.num_subjects;
73906+ polstate->acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
73907+ polstate->name_set.n_size = arg->role_db.num_objects;
73908+ polstate->inodev_set.i_size = arg->role_db.num_objects;
73909+
73910+ if (!polstate->subj_map_set.s_size || !polstate->acl_role_set.r_size ||
73911+ !polstate->name_set.n_size || !polstate->inodev_set.i_size)
73912+ return 1;
73913+
73914+ if (!reload) {
73915+ if (!gr_init_uidset())
73916+ return 1;
73917+ }
73918+
73919+ /* set up the stack that holds allocation info */
73920+
73921+ stacksize = arg->role_db.num_pointers + 5;
73922+
73923+ if (!acl_alloc_stack_init(stacksize))
73924+ return 1;
73925+
73926+ if (!reload) {
73927+ /* grab reference for the real root dentry and vfsmount */
73928+ get_fs_root(reaper->fs, &gr_real_root);
73929+
73930+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
73931+ 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);
73932+#endif
73933+
73934+ fakefs_obj_rw = kzalloc(sizeof(struct acl_object_label), GFP_KERNEL);
73935+ if (fakefs_obj_rw == NULL)
73936+ return 1;
73937+ fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
73938+
73939+ fakefs_obj_rwx = kzalloc(sizeof(struct acl_object_label), GFP_KERNEL);
73940+ if (fakefs_obj_rwx == NULL)
73941+ return 1;
73942+ fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
73943+ }
73944+
73945+ polstate->subj_map_set.s_hash =
73946+ (struct subject_map **) create_table(&polstate->subj_map_set.s_size, sizeof(void *));
73947+ polstate->acl_role_set.r_hash =
73948+ (struct acl_role_label **) create_table(&polstate->acl_role_set.r_size, sizeof(void *));
73949+ polstate->name_set.n_hash = (struct name_entry **) create_table(&polstate->name_set.n_size, sizeof(void *));
73950+ polstate->inodev_set.i_hash =
73951+ (struct inodev_entry **) create_table(&polstate->inodev_set.i_size, sizeof(void *));
73952+
73953+ if (!polstate->subj_map_set.s_hash || !polstate->acl_role_set.r_hash ||
73954+ !polstate->name_set.n_hash || !polstate->inodev_set.i_hash)
73955+ return 1;
73956+
73957+ memset(polstate->subj_map_set.s_hash, 0,
73958+ sizeof(struct subject_map *) * polstate->subj_map_set.s_size);
73959+ memset(polstate->acl_role_set.r_hash, 0,
73960+ sizeof (struct acl_role_label *) * polstate->acl_role_set.r_size);
73961+ memset(polstate->name_set.n_hash, 0,
73962+ sizeof (struct name_entry *) * polstate->name_set.n_size);
73963+ memset(polstate->inodev_set.i_hash, 0,
73964+ sizeof (struct inodev_entry *) * polstate->inodev_set.i_size);
73965+
73966+ return 0;
73967+}
73968+
73969+/* free information not needed after startup
73970+ currently contains user->kernel pointer mappings for subjects
73971+*/
73972+
73973+static void
73974+free_init_variables(void)
73975+{
73976+ __u32 i;
73977+
73978+ if (polstate->subj_map_set.s_hash) {
73979+ for (i = 0; i < polstate->subj_map_set.s_size; i++) {
73980+ if (polstate->subj_map_set.s_hash[i]) {
73981+ kfree(polstate->subj_map_set.s_hash[i]);
73982+ polstate->subj_map_set.s_hash[i] = NULL;
73983+ }
73984+ }
73985+
73986+ if ((polstate->subj_map_set.s_size * sizeof (struct subject_map *)) <=
73987+ PAGE_SIZE)
73988+ kfree(polstate->subj_map_set.s_hash);
73989+ else
73990+ vfree(polstate->subj_map_set.s_hash);
73991+ }
73992+
73993+ return;
73994+}
73995+
73996+static void
73997+free_variables(bool reload)
73998+{
73999+ struct acl_subject_label *s;
74000+ struct acl_role_label *r;
74001+ struct task_struct *task, *task2;
74002+ unsigned int x;
74003+
74004+ if (!reload) {
74005+ gr_clear_learn_entries();
74006+
74007+ read_lock(&tasklist_lock);
74008+ do_each_thread(task2, task) {
74009+ task->acl_sp_role = 0;
74010+ task->acl_role_id = 0;
74011+ task->inherited = 0;
74012+ task->acl = NULL;
74013+ task->role = NULL;
74014+ } while_each_thread(task2, task);
74015+ read_unlock(&tasklist_lock);
74016+
74017+ kfree(fakefs_obj_rw);
74018+ fakefs_obj_rw = NULL;
74019+ kfree(fakefs_obj_rwx);
74020+ fakefs_obj_rwx = NULL;
74021+
74022+ /* release the reference to the real root dentry and vfsmount */
74023+ path_put(&gr_real_root);
74024+ memset(&gr_real_root, 0, sizeof(gr_real_root));
74025+ }
74026+
74027+ /* free all object hash tables */
74028+
74029+ FOR_EACH_ROLE_START(r)
74030+ if (r->subj_hash == NULL)
74031+ goto next_role;
74032+ FOR_EACH_SUBJECT_START(r, s, x)
74033+ if (s->obj_hash == NULL)
74034+ break;
74035+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
74036+ kfree(s->obj_hash);
74037+ else
74038+ vfree(s->obj_hash);
74039+ FOR_EACH_SUBJECT_END(s, x)
74040+ FOR_EACH_NESTED_SUBJECT_START(r, s)
74041+ if (s->obj_hash == NULL)
74042+ break;
74043+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
74044+ kfree(s->obj_hash);
74045+ else
74046+ vfree(s->obj_hash);
74047+ FOR_EACH_NESTED_SUBJECT_END(s)
74048+ if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
74049+ kfree(r->subj_hash);
74050+ else
74051+ vfree(r->subj_hash);
74052+ r->subj_hash = NULL;
74053+next_role:
74054+ FOR_EACH_ROLE_END(r)
74055+
74056+ acl_free_all();
74057+
74058+ if (polstate->acl_role_set.r_hash) {
74059+ if ((polstate->acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
74060+ PAGE_SIZE)
74061+ kfree(polstate->acl_role_set.r_hash);
74062+ else
74063+ vfree(polstate->acl_role_set.r_hash);
74064+ }
74065+ if (polstate->name_set.n_hash) {
74066+ if ((polstate->name_set.n_size * sizeof (struct name_entry *)) <=
74067+ PAGE_SIZE)
74068+ kfree(polstate->name_set.n_hash);
74069+ else
74070+ vfree(polstate->name_set.n_hash);
74071+ }
74072+
74073+ if (polstate->inodev_set.i_hash) {
74074+ if ((polstate->inodev_set.i_size * sizeof (struct inodev_entry *)) <=
74075+ PAGE_SIZE)
74076+ kfree(polstate->inodev_set.i_hash);
74077+ else
74078+ vfree(polstate->inodev_set.i_hash);
74079+ }
74080+
74081+ if (!reload)
74082+ gr_free_uidset();
74083+
74084+ memset(&polstate->name_set, 0, sizeof (struct name_db));
74085+ memset(&polstate->inodev_set, 0, sizeof (struct inodev_db));
74086+ memset(&polstate->acl_role_set, 0, sizeof (struct acl_role_db));
74087+ memset(&polstate->subj_map_set, 0, sizeof (struct acl_subj_map_db));
74088+
74089+ polstate->default_role = NULL;
74090+ polstate->kernel_role = NULL;
74091+ polstate->role_list = NULL;
74092+
74093+ return;
74094+}
74095+
74096+static struct acl_subject_label *
74097+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied);
74098+
74099+static int alloc_and_copy_string(char **name, unsigned int maxlen)
74100+{
74101+ unsigned int len = strnlen_user(*name, maxlen);
74102+ char *tmp;
74103+
74104+ if (!len || len >= maxlen)
74105+ return -EINVAL;
74106+
74107+ if ((tmp = (char *) acl_alloc(len)) == NULL)
74108+ return -ENOMEM;
74109+
74110+ if (copy_from_user(tmp, *name, len))
74111+ return -EFAULT;
74112+
74113+ tmp[len-1] = '\0';
74114+ *name = tmp;
74115+
74116+ return 0;
74117+}
74118+
74119+static int
74120+copy_user_glob(struct acl_object_label *obj)
74121+{
74122+ struct acl_object_label *g_tmp, **guser;
74123+ int error;
74124+
74125+ if (obj->globbed == NULL)
74126+ return 0;
74127+
74128+ guser = &obj->globbed;
74129+ while (*guser) {
74130+ g_tmp = (struct acl_object_label *)
74131+ acl_alloc(sizeof (struct acl_object_label));
74132+ if (g_tmp == NULL)
74133+ return -ENOMEM;
74134+
74135+ if (copy_acl_object_label(g_tmp, *guser))
74136+ return -EFAULT;
74137+
74138+ error = alloc_and_copy_string(&g_tmp->filename, PATH_MAX);
74139+ if (error)
74140+ return error;
74141+
74142+ *guser = g_tmp;
74143+ guser = &(g_tmp->next);
74144+ }
74145+
74146+ return 0;
74147+}
74148+
74149+static int
74150+copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
74151+ struct acl_role_label *role)
74152+{
74153+ struct acl_object_label *o_tmp;
74154+ int ret;
74155+
74156+ while (userp) {
74157+ if ((o_tmp = (struct acl_object_label *)
74158+ acl_alloc(sizeof (struct acl_object_label))) == NULL)
74159+ return -ENOMEM;
74160+
74161+ if (copy_acl_object_label(o_tmp, userp))
74162+ return -EFAULT;
74163+
74164+ userp = o_tmp->prev;
74165+
74166+ ret = alloc_and_copy_string(&o_tmp->filename, PATH_MAX);
74167+ if (ret)
74168+ return ret;
74169+
74170+ insert_acl_obj_label(o_tmp, subj);
74171+ if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
74172+ o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
74173+ return -ENOMEM;
74174+
74175+ ret = copy_user_glob(o_tmp);
74176+ if (ret)
74177+ return ret;
74178+
74179+ if (o_tmp->nested) {
74180+ int already_copied;
74181+
74182+ o_tmp->nested = do_copy_user_subj(o_tmp->nested, role, &already_copied);
74183+ if (IS_ERR(o_tmp->nested))
74184+ return PTR_ERR(o_tmp->nested);
74185+
74186+ /* insert into nested subject list if we haven't copied this one yet
74187+ to prevent duplicate entries */
74188+ if (!already_copied) {
74189+ o_tmp->nested->next = role->hash->first;
74190+ role->hash->first = o_tmp->nested;
74191+ }
74192+ }
74193+ }
74194+
74195+ return 0;
74196+}
74197+
74198+static __u32
74199+count_user_subjs(struct acl_subject_label *userp)
74200+{
74201+ struct acl_subject_label s_tmp;
74202+ __u32 num = 0;
74203+
74204+ while (userp) {
74205+ if (copy_acl_subject_label(&s_tmp, userp))
74206+ break;
74207+
74208+ userp = s_tmp.prev;
74209+ }
74210+
74211+ return num;
74212+}
74213+
74214+static int
74215+copy_user_allowedips(struct acl_role_label *rolep)
74216+{
74217+ struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
74218+
74219+ ruserip = rolep->allowed_ips;
74220+
74221+ while (ruserip) {
74222+ rlast = rtmp;
74223+
74224+ if ((rtmp = (struct role_allowed_ip *)
74225+ acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
74226+ return -ENOMEM;
74227+
74228+ if (copy_role_allowed_ip(rtmp, ruserip))
74229+ return -EFAULT;
74230+
74231+ ruserip = rtmp->prev;
74232+
74233+ if (!rlast) {
74234+ rtmp->prev = NULL;
74235+ rolep->allowed_ips = rtmp;
74236+ } else {
74237+ rlast->next = rtmp;
74238+ rtmp->prev = rlast;
74239+ }
74240+
74241+ if (!ruserip)
74242+ rtmp->next = NULL;
74243+ }
74244+
74245+ return 0;
74246+}
74247+
74248+static int
74249+copy_user_transitions(struct acl_role_label *rolep)
74250+{
74251+ struct role_transition *rusertp, *rtmp = NULL, *rlast;
74252+ int error;
74253+
74254+ rusertp = rolep->transitions;
74255+
74256+ while (rusertp) {
74257+ rlast = rtmp;
74258+
74259+ if ((rtmp = (struct role_transition *)
74260+ acl_alloc(sizeof (struct role_transition))) == NULL)
74261+ return -ENOMEM;
74262+
74263+ if (copy_role_transition(rtmp, rusertp))
74264+ return -EFAULT;
74265+
74266+ rusertp = rtmp->prev;
74267+
74268+ error = alloc_and_copy_string(&rtmp->rolename, GR_SPROLE_LEN);
74269+ if (error)
74270+ return error;
74271+
74272+ if (!rlast) {
74273+ rtmp->prev = NULL;
74274+ rolep->transitions = rtmp;
74275+ } else {
74276+ rlast->next = rtmp;
74277+ rtmp->prev = rlast;
74278+ }
74279+
74280+ if (!rusertp)
74281+ rtmp->next = NULL;
74282+ }
74283+
74284+ return 0;
74285+}
74286+
74287+static __u32 count_user_objs(const struct acl_object_label __user *userp)
74288+{
74289+ struct acl_object_label o_tmp;
74290+ __u32 num = 0;
74291+
74292+ while (userp) {
74293+ if (copy_acl_object_label(&o_tmp, userp))
74294+ break;
74295+
74296+ userp = o_tmp.prev;
74297+ num++;
74298+ }
74299+
74300+ return num;
74301+}
74302+
74303+static struct acl_subject_label *
74304+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied)
74305+{
74306+ struct acl_subject_label *s_tmp = NULL, *s_tmp2;
74307+ __u32 num_objs;
74308+ struct acl_ip_label **i_tmp, *i_utmp2;
74309+ struct gr_hash_struct ghash;
74310+ struct subject_map *subjmap;
74311+ unsigned int i_num;
74312+ int err;
74313+
74314+ if (already_copied != NULL)
74315+ *already_copied = 0;
74316+
74317+ s_tmp = lookup_subject_map(userp);
74318+
74319+ /* we've already copied this subject into the kernel, just return
74320+ the reference to it, and don't copy it over again
74321+ */
74322+ if (s_tmp) {
74323+ if (already_copied != NULL)
74324+ *already_copied = 1;
74325+ return(s_tmp);
74326+ }
74327+
74328+ if ((s_tmp = (struct acl_subject_label *)
74329+ acl_alloc(sizeof (struct acl_subject_label))) == NULL)
74330+ return ERR_PTR(-ENOMEM);
74331+
74332+ subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
74333+ if (subjmap == NULL)
74334+ return ERR_PTR(-ENOMEM);
74335+
74336+ subjmap->user = userp;
74337+ subjmap->kernel = s_tmp;
74338+ insert_subj_map_entry(subjmap);
74339+
74340+ if (copy_acl_subject_label(s_tmp, userp))
74341+ return ERR_PTR(-EFAULT);
74342+
74343+ err = alloc_and_copy_string(&s_tmp->filename, PATH_MAX);
74344+ if (err)
74345+ return ERR_PTR(err);
74346+
74347+ if (!strcmp(s_tmp->filename, "/"))
74348+ role->root_label = s_tmp;
74349+
74350+ if (copy_gr_hash_struct(&ghash, s_tmp->hash))
74351+ return ERR_PTR(-EFAULT);
74352+
74353+ /* copy user and group transition tables */
74354+
74355+ if (s_tmp->user_trans_num) {
74356+ uid_t *uidlist;
74357+
74358+ uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
74359+ if (uidlist == NULL)
74360+ return ERR_PTR(-ENOMEM);
74361+ if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
74362+ return ERR_PTR(-EFAULT);
74363+
74364+ s_tmp->user_transitions = uidlist;
74365+ }
74366+
74367+ if (s_tmp->group_trans_num) {
74368+ gid_t *gidlist;
74369+
74370+ gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
74371+ if (gidlist == NULL)
74372+ return ERR_PTR(-ENOMEM);
74373+ if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
74374+ return ERR_PTR(-EFAULT);
74375+
74376+ s_tmp->group_transitions = gidlist;
74377+ }
74378+
74379+ /* set up object hash table */
74380+ num_objs = count_user_objs(ghash.first);
74381+
74382+ s_tmp->obj_hash_size = num_objs;
74383+ s_tmp->obj_hash =
74384+ (struct acl_object_label **)
74385+ create_table(&(s_tmp->obj_hash_size), sizeof(void *));
74386+
74387+ if (!s_tmp->obj_hash)
74388+ return ERR_PTR(-ENOMEM);
74389+
74390+ memset(s_tmp->obj_hash, 0,
74391+ s_tmp->obj_hash_size *
74392+ sizeof (struct acl_object_label *));
74393+
74394+ /* add in objects */
74395+ err = copy_user_objs(ghash.first, s_tmp, role);
74396+
74397+ if (err)
74398+ return ERR_PTR(err);
74399+
74400+ /* set pointer for parent subject */
74401+ if (s_tmp->parent_subject) {
74402+ s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role, NULL);
74403+
74404+ if (IS_ERR(s_tmp2))
74405+ return s_tmp2;
74406+
74407+ s_tmp->parent_subject = s_tmp2;
74408+ }
74409+
74410+ /* add in ip acls */
74411+
74412+ if (!s_tmp->ip_num) {
74413+ s_tmp->ips = NULL;
74414+ goto insert;
74415+ }
74416+
74417+ i_tmp =
74418+ (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
74419+ sizeof (struct acl_ip_label *));
74420+
74421+ if (!i_tmp)
74422+ return ERR_PTR(-ENOMEM);
74423+
74424+ for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
74425+ *(i_tmp + i_num) =
74426+ (struct acl_ip_label *)
74427+ acl_alloc(sizeof (struct acl_ip_label));
74428+ if (!*(i_tmp + i_num))
74429+ return ERR_PTR(-ENOMEM);
74430+
74431+ if (copy_pointer_from_array(&i_utmp2, i_num, s_tmp->ips))
74432+ return ERR_PTR(-EFAULT);
74433+
74434+ if (copy_acl_ip_label(*(i_tmp + i_num), i_utmp2))
74435+ return ERR_PTR(-EFAULT);
74436+
74437+ if ((*(i_tmp + i_num))->iface == NULL)
74438+ continue;
74439+
74440+ err = alloc_and_copy_string(&(*(i_tmp + i_num))->iface, IFNAMSIZ);
74441+ if (err)
74442+ return ERR_PTR(err);
74443+ }
74444+
74445+ s_tmp->ips = i_tmp;
74446+
74447+insert:
74448+ if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
74449+ s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
74450+ return ERR_PTR(-ENOMEM);
74451+
74452+ return s_tmp;
74453+}
74454+
74455+static int
74456+copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
74457+{
74458+ struct acl_subject_label s_pre;
74459+ struct acl_subject_label * ret;
74460+ int err;
74461+
74462+ while (userp) {
74463+ if (copy_acl_subject_label(&s_pre, userp))
74464+ return -EFAULT;
74465+
74466+ ret = do_copy_user_subj(userp, role, NULL);
74467+
74468+ err = PTR_ERR(ret);
74469+ if (IS_ERR(ret))
74470+ return err;
74471+
74472+ insert_acl_subj_label(ret, role);
74473+
74474+ userp = s_pre.prev;
74475+ }
74476+
74477+ return 0;
74478+}
74479+
74480+static int
74481+copy_user_acl(struct gr_arg *arg)
74482+{
74483+ struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
74484+ struct acl_subject_label *subj_list;
74485+ struct sprole_pw *sptmp;
74486+ struct gr_hash_struct *ghash;
74487+ uid_t *domainlist;
74488+ unsigned int r_num;
74489+ int err = 0;
74490+ __u16 i;
74491+ __u32 num_subjs;
74492+
74493+ /* we need a default and kernel role */
74494+ if (arg->role_db.num_roles < 2)
74495+ return -EINVAL;
74496+
74497+ /* copy special role authentication info from userspace */
74498+
74499+ polstate->num_sprole_pws = arg->num_sprole_pws;
74500+ polstate->acl_special_roles = (struct sprole_pw **) acl_alloc_num(polstate->num_sprole_pws, sizeof(struct sprole_pw *));
74501+
74502+ if (!polstate->acl_special_roles && polstate->num_sprole_pws)
74503+ return -ENOMEM;
74504+
74505+ for (i = 0; i < polstate->num_sprole_pws; i++) {
74506+ sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
74507+ if (!sptmp)
74508+ return -ENOMEM;
74509+ if (copy_sprole_pw(sptmp, i, arg->sprole_pws))
74510+ return -EFAULT;
74511+
74512+ err = alloc_and_copy_string((char **)&sptmp->rolename, GR_SPROLE_LEN);
74513+ if (err)
74514+ return err;
74515+
74516+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
74517+ printk(KERN_ALERT "Copying special role %s\n", sptmp->rolename);
74518+#endif
74519+
74520+ polstate->acl_special_roles[i] = sptmp;
74521+ }
74522+
74523+ r_utmp = (struct acl_role_label **) arg->role_db.r_table;
74524+
74525+ for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
74526+ r_tmp = acl_alloc(sizeof (struct acl_role_label));
74527+
74528+ if (!r_tmp)
74529+ return -ENOMEM;
74530+
74531+ if (copy_pointer_from_array(&r_utmp2, r_num, r_utmp))
74532+ return -EFAULT;
74533+
74534+ if (copy_acl_role_label(r_tmp, r_utmp2))
74535+ return -EFAULT;
74536+
74537+ err = alloc_and_copy_string(&r_tmp->rolename, GR_SPROLE_LEN);
74538+ if (err)
74539+ return err;
74540+
74541+ if (!strcmp(r_tmp->rolename, "default")
74542+ && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
74543+ polstate->default_role = r_tmp;
74544+ } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
74545+ polstate->kernel_role = r_tmp;
74546+ }
74547+
74548+ if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
74549+ return -ENOMEM;
74550+
74551+ if (copy_gr_hash_struct(ghash, r_tmp->hash))
74552+ return -EFAULT;
74553+
74554+ r_tmp->hash = ghash;
74555+
74556+ num_subjs = count_user_subjs(r_tmp->hash->first);
74557+
74558+ r_tmp->subj_hash_size = num_subjs;
74559+ r_tmp->subj_hash =
74560+ (struct acl_subject_label **)
74561+ create_table(&(r_tmp->subj_hash_size), sizeof(void *));
74562+
74563+ if (!r_tmp->subj_hash)
74564+ return -ENOMEM;
74565+
74566+ err = copy_user_allowedips(r_tmp);
74567+ if (err)
74568+ return err;
74569+
74570+ /* copy domain info */
74571+ if (r_tmp->domain_children != NULL) {
74572+ domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
74573+ if (domainlist == NULL)
74574+ return -ENOMEM;
74575+
74576+ if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
74577+ return -EFAULT;
74578+
74579+ r_tmp->domain_children = domainlist;
74580+ }
74581+
74582+ err = copy_user_transitions(r_tmp);
74583+ if (err)
74584+ return err;
74585+
74586+ memset(r_tmp->subj_hash, 0,
74587+ r_tmp->subj_hash_size *
74588+ sizeof (struct acl_subject_label *));
74589+
74590+ /* acquire the list of subjects, then NULL out
74591+ the list prior to parsing the subjects for this role,
74592+ as during this parsing the list is replaced with a list
74593+ of *nested* subjects for the role
74594+ */
74595+ subj_list = r_tmp->hash->first;
74596+
74597+ /* set nested subject list to null */
74598+ r_tmp->hash->first = NULL;
74599+
74600+ err = copy_user_subjs(subj_list, r_tmp);
74601+
74602+ if (err)
74603+ return err;
74604+
74605+ insert_acl_role_label(r_tmp);
74606+ }
74607+
74608+ if (polstate->default_role == NULL || polstate->kernel_role == NULL)
74609+ return -EINVAL;
74610+
74611+ return err;
74612+}
74613+
74614+static int gracl_reload_apply_policies(void *reload)
74615+{
74616+ struct gr_reload_state *reload_state = (struct gr_reload_state *)reload;
74617+ struct task_struct *task, *task2;
74618+ struct acl_role_label *role, *rtmp;
74619+ struct acl_subject_label *subj;
74620+ const struct cred *cred;
74621+ int role_applied;
74622+ int ret = 0;
74623+
74624+ memcpy(&reload_state->oldpolicy, reload_state->oldpolicy_ptr, sizeof(struct gr_policy_state));
74625+ memcpy(&reload_state->oldalloc, reload_state->oldalloc_ptr, sizeof(struct gr_alloc_state));
74626+
74627+ /* first make sure we'll be able to apply the new policy cleanly */
74628+ do_each_thread(task2, task) {
74629+ if (task->exec_file == NULL)
74630+ continue;
74631+ role_applied = 0;
74632+ if (!reload_state->oldmode && task->role->roletype & GR_ROLE_SPECIAL) {
74633+ /* preserve special roles */
74634+ FOR_EACH_ROLE_START(role)
74635+ if ((role->roletype & GR_ROLE_SPECIAL) && !strcmp(task->role->rolename, role->rolename)) {
74636+ rtmp = task->role;
74637+ task->role = role;
74638+ role_applied = 1;
74639+ break;
74640+ }
74641+ FOR_EACH_ROLE_END(role)
74642+ }
74643+ if (!role_applied) {
74644+ cred = __task_cred(task);
74645+ rtmp = task->role;
74646+ task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
74647+ }
74648+ /* this handles non-nested inherited subjects, nested subjects will still
74649+ be dropped currently */
74650+ subj = __gr_get_subject_for_task(polstate, task, task->acl->filename);
74651+ task->tmpacl = __gr_get_subject_for_task(polstate, task, NULL);
74652+ /* change the role back so that we've made no modifications to the policy */
74653+ task->role = rtmp;
74654+
74655+ if (subj == NULL || task->tmpacl == NULL) {
74656+ ret = -EINVAL;
74657+ goto out;
74658+ }
74659+ } while_each_thread(task2, task);
74660+
74661+ /* now actually apply the policy */
74662+
74663+ do_each_thread(task2, task) {
74664+ if (task->exec_file) {
74665+ role_applied = 0;
74666+ if (!reload_state->oldmode && task->role->roletype & GR_ROLE_SPECIAL) {
74667+ /* preserve special roles */
74668+ FOR_EACH_ROLE_START(role)
74669+ if ((role->roletype & GR_ROLE_SPECIAL) && !strcmp(task->role->rolename, role->rolename)) {
74670+ task->role = role;
74671+ role_applied = 1;
74672+ break;
74673+ }
74674+ FOR_EACH_ROLE_END(role)
74675+ }
74676+ if (!role_applied) {
74677+ cred = __task_cred(task);
74678+ task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
74679+ }
74680+ /* this handles non-nested inherited subjects, nested subjects will still
74681+ be dropped currently */
74682+ if (!reload_state->oldmode && task->inherited)
74683+ subj = __gr_get_subject_for_task(polstate, task, task->acl->filename);
74684+ else {
74685+ /* looked up and tagged to the task previously */
74686+ subj = task->tmpacl;
74687+ }
74688+ /* subj will be non-null */
74689+ __gr_apply_subject_to_task(polstate, task, subj);
74690+ if (reload_state->oldmode) {
74691+ task->acl_role_id = 0;
74692+ task->acl_sp_role = 0;
74693+ task->inherited = 0;
74694+ }
74695+ } else {
74696+ // it's a kernel process
74697+ task->role = polstate->kernel_role;
74698+ task->acl = polstate->kernel_role->root_label;
74699+#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
74700+ task->acl->mode &= ~GR_PROCFIND;
74701+#endif
74702+ }
74703+ } while_each_thread(task2, task);
74704+
74705+ memcpy(reload_state->oldpolicy_ptr, &reload_state->newpolicy, sizeof(struct gr_policy_state));
74706+ memcpy(reload_state->oldalloc_ptr, &reload_state->newalloc, sizeof(struct gr_alloc_state));
74707+
74708+out:
74709+
74710+ return ret;
74711+}
74712+
74713+static int gracl_reload(struct gr_arg *args, unsigned char oldmode)
74714+{
74715+ struct gr_reload_state new_reload_state = { };
74716+ int err;
74717+
74718+ new_reload_state.oldpolicy_ptr = polstate;
74719+ new_reload_state.oldalloc_ptr = current_alloc_state;
74720+ new_reload_state.oldmode = oldmode;
74721+
74722+ current_alloc_state = &new_reload_state.newalloc;
74723+ polstate = &new_reload_state.newpolicy;
74724+
74725+ /* everything relevant is now saved off, copy in the new policy */
74726+ if (init_variables(args, true)) {
74727+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
74728+ err = -ENOMEM;
74729+ goto error;
74730+ }
74731+
74732+ err = copy_user_acl(args);
74733+ free_init_variables();
74734+ if (err)
74735+ goto error;
74736+ /* the new policy is copied in, with the old policy available via saved_state
74737+ first go through applying roles, making sure to preserve special roles
74738+ then apply new subjects, making sure to preserve inherited and nested subjects,
74739+ though currently only inherited subjects will be preserved
74740+ */
74741+ err = stop_machine(gracl_reload_apply_policies, &new_reload_state, NULL);
74742+ if (err)
74743+ goto error;
74744+
74745+ /* we've now applied the new policy, so restore the old policy state to free it */
74746+ polstate = &new_reload_state.oldpolicy;
74747+ current_alloc_state = &new_reload_state.oldalloc;
74748+ free_variables(true);
74749+
74750+ /* oldpolicy/oldalloc_ptr point to the new policy/alloc states as they were copied
74751+ to running_polstate/current_alloc_state inside stop_machine
74752+ */
74753+ err = 0;
74754+ goto out;
74755+error:
74756+ /* on error of loading the new policy, we'll just keep the previous
74757+ policy set around
74758+ */
74759+ free_variables(true);
74760+
74761+ /* doesn't affect runtime, but maintains consistent state */
74762+out:
74763+ polstate = new_reload_state.oldpolicy_ptr;
74764+ current_alloc_state = new_reload_state.oldalloc_ptr;
74765+
74766+ return err;
74767+}
74768+
74769+static int
74770+gracl_init(struct gr_arg *args)
74771+{
74772+ int error = 0;
74773+
74774+ memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
74775+ memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
74776+
74777+ if (init_variables(args, false)) {
74778+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
74779+ error = -ENOMEM;
74780+ goto out;
74781+ }
74782+
74783+ error = copy_user_acl(args);
74784+ free_init_variables();
74785+ if (error)
74786+ goto out;
74787+
74788+ error = gr_set_acls(0);
74789+ if (error)
74790+ goto out;
74791+
74792+ gr_enable_rbac_system();
74793+
74794+ return 0;
74795+
74796+out:
74797+ free_variables(false);
74798+ return error;
74799+}
74800+
74801+static int
74802+lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
74803+ unsigned char **sum)
74804+{
74805+ struct acl_role_label *r;
74806+ struct role_allowed_ip *ipp;
74807+ struct role_transition *trans;
74808+ unsigned int i;
74809+ int found = 0;
74810+ u32 curr_ip = current->signal->curr_ip;
74811+
74812+ current->signal->saved_ip = curr_ip;
74813+
74814+ /* check transition table */
74815+
74816+ for (trans = current->role->transitions; trans; trans = trans->next) {
74817+ if (!strcmp(rolename, trans->rolename)) {
74818+ found = 1;
74819+ break;
74820+ }
74821+ }
74822+
74823+ if (!found)
74824+ return 0;
74825+
74826+ /* handle special roles that do not require authentication
74827+ and check ip */
74828+
74829+ FOR_EACH_ROLE_START(r)
74830+ if (!strcmp(rolename, r->rolename) &&
74831+ (r->roletype & GR_ROLE_SPECIAL)) {
74832+ found = 0;
74833+ if (r->allowed_ips != NULL) {
74834+ for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
74835+ if ((ntohl(curr_ip) & ipp->netmask) ==
74836+ (ntohl(ipp->addr) & ipp->netmask))
74837+ found = 1;
74838+ }
74839+ } else
74840+ found = 2;
74841+ if (!found)
74842+ return 0;
74843+
74844+ if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
74845+ ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
74846+ *salt = NULL;
74847+ *sum = NULL;
74848+ return 1;
74849+ }
74850+ }
74851+ FOR_EACH_ROLE_END(r)
74852+
74853+ for (i = 0; i < polstate->num_sprole_pws; i++) {
74854+ if (!strcmp(rolename, polstate->acl_special_roles[i]->rolename)) {
74855+ *salt = polstate->acl_special_roles[i]->salt;
74856+ *sum = polstate->acl_special_roles[i]->sum;
74857+ return 1;
74858+ }
74859+ }
74860+
74861+ return 0;
74862+}
74863+
74864+int gr_check_secure_terminal(struct task_struct *task)
74865+{
74866+ struct task_struct *p, *p2, *p3;
74867+ struct files_struct *files;
74868+ struct fdtable *fdt;
74869+ struct file *our_file = NULL, *file;
74870+ int i;
74871+
74872+ if (task->signal->tty == NULL)
74873+ return 1;
74874+
74875+ files = get_files_struct(task);
74876+ if (files != NULL) {
74877+ rcu_read_lock();
74878+ fdt = files_fdtable(files);
74879+ for (i=0; i < fdt->max_fds; i++) {
74880+ file = fcheck_files(files, i);
74881+ if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
74882+ get_file(file);
74883+ our_file = file;
74884+ }
74885+ }
74886+ rcu_read_unlock();
74887+ put_files_struct(files);
74888+ }
74889+
74890+ if (our_file == NULL)
74891+ return 1;
74892+
74893+ read_lock(&tasklist_lock);
74894+ do_each_thread(p2, p) {
74895+ files = get_files_struct(p);
74896+ if (files == NULL ||
74897+ (p->signal && p->signal->tty == task->signal->tty)) {
74898+ if (files != NULL)
74899+ put_files_struct(files);
74900+ continue;
74901+ }
74902+ rcu_read_lock();
74903+ fdt = files_fdtable(files);
74904+ for (i=0; i < fdt->max_fds; i++) {
74905+ file = fcheck_files(files, i);
74906+ if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
74907+ file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
74908+ p3 = task;
74909+ while (task_pid_nr(p3) > 0) {
74910+ if (p3 == p)
74911+ break;
74912+ p3 = p3->real_parent;
74913+ }
74914+ if (p3 == p)
74915+ break;
74916+ gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
74917+ gr_handle_alertkill(p);
74918+ rcu_read_unlock();
74919+ put_files_struct(files);
74920+ read_unlock(&tasklist_lock);
74921+ fput(our_file);
74922+ return 0;
74923+ }
74924+ }
74925+ rcu_read_unlock();
74926+ put_files_struct(files);
74927+ } while_each_thread(p2, p);
74928+ read_unlock(&tasklist_lock);
74929+
74930+ fput(our_file);
74931+ return 1;
74932+}
74933+
74934+ssize_t
74935+write_grsec_handler(struct file *file, const char __user * buf, size_t count, loff_t *ppos)
74936+{
74937+ struct gr_arg_wrapper uwrap;
74938+ unsigned char *sprole_salt = NULL;
74939+ unsigned char *sprole_sum = NULL;
74940+ int error = 0;
74941+ int error2 = 0;
74942+ size_t req_count = 0;
74943+ unsigned char oldmode = 0;
74944+
74945+ mutex_lock(&gr_dev_mutex);
74946+
74947+ if (gr_acl_is_enabled() && !(current->acl->mode & GR_KERNELAUTH)) {
74948+ error = -EPERM;
74949+ goto out;
74950+ }
74951+
74952+#ifdef CONFIG_COMPAT
74953+ pax_open_kernel();
74954+ if (is_compat_task()) {
74955+ copy_gr_arg_wrapper = &copy_gr_arg_wrapper_compat;
74956+ copy_gr_arg = &copy_gr_arg_compat;
74957+ copy_acl_object_label = &copy_acl_object_label_compat;
74958+ copy_acl_subject_label = &copy_acl_subject_label_compat;
74959+ copy_acl_role_label = &copy_acl_role_label_compat;
74960+ copy_acl_ip_label = &copy_acl_ip_label_compat;
74961+ copy_role_allowed_ip = &copy_role_allowed_ip_compat;
74962+ copy_role_transition = &copy_role_transition_compat;
74963+ copy_sprole_pw = &copy_sprole_pw_compat;
74964+ copy_gr_hash_struct = &copy_gr_hash_struct_compat;
74965+ copy_pointer_from_array = &copy_pointer_from_array_compat;
74966+ get_gr_arg_wrapper_size = &get_gr_arg_wrapper_size_compat;
74967+ } else {
74968+ copy_gr_arg_wrapper = &copy_gr_arg_wrapper_normal;
74969+ copy_gr_arg = &copy_gr_arg_normal;
74970+ copy_acl_object_label = &copy_acl_object_label_normal;
74971+ copy_acl_subject_label = &copy_acl_subject_label_normal;
74972+ copy_acl_role_label = &copy_acl_role_label_normal;
74973+ copy_acl_ip_label = &copy_acl_ip_label_normal;
74974+ copy_role_allowed_ip = &copy_role_allowed_ip_normal;
74975+ copy_role_transition = &copy_role_transition_normal;
74976+ copy_sprole_pw = &copy_sprole_pw_normal;
74977+ copy_gr_hash_struct = &copy_gr_hash_struct_normal;
74978+ copy_pointer_from_array = &copy_pointer_from_array_normal;
74979+ get_gr_arg_wrapper_size = &get_gr_arg_wrapper_size_normal;
74980+ }
74981+ pax_close_kernel();
74982+#endif
74983+
74984+ req_count = get_gr_arg_wrapper_size();
74985+
74986+ if (count != req_count) {
74987+ gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)req_count);
74988+ error = -EINVAL;
74989+ goto out;
74990+ }
74991+
74992+
74993+ if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
74994+ gr_auth_expires = 0;
74995+ gr_auth_attempts = 0;
74996+ }
74997+
74998+ error = copy_gr_arg_wrapper(buf, &uwrap);
74999+ if (error)
75000+ goto out;
75001+
75002+ error = copy_gr_arg(uwrap.arg, gr_usermode);
75003+ if (error)
75004+ goto out;
75005+
75006+ if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_SPROLEPAM &&
75007+ gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
75008+ time_after(gr_auth_expires, get_seconds())) {
75009+ error = -EBUSY;
75010+ goto out;
75011+ }
75012+
75013+ /* if non-root trying to do anything other than use a special role,
75014+ do not attempt authentication, do not count towards authentication
75015+ locking
75016+ */
75017+
75018+ if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_STATUS &&
75019+ gr_usermode->mode != GR_UNSPROLE && gr_usermode->mode != GR_SPROLEPAM &&
75020+ gr_is_global_nonroot(current_uid())) {
75021+ error = -EPERM;
75022+ goto out;
75023+ }
75024+
75025+ /* ensure pw and special role name are null terminated */
75026+
75027+ gr_usermode->pw[GR_PW_LEN - 1] = '\0';
75028+ gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
75029+
75030+ /* Okay.
75031+ * We have our enough of the argument structure..(we have yet
75032+ * to copy_from_user the tables themselves) . Copy the tables
75033+ * only if we need them, i.e. for loading operations. */
75034+
75035+ switch (gr_usermode->mode) {
75036+ case GR_STATUS:
75037+ if (gr_acl_is_enabled()) {
75038+ error = 1;
75039+ if (!gr_check_secure_terminal(current))
75040+ error = 3;
75041+ } else
75042+ error = 2;
75043+ goto out;
75044+ case GR_SHUTDOWN:
75045+ if (gr_acl_is_enabled() && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
75046+ stop_machine(gr_rbac_disable, NULL, NULL);
75047+ free_variables(false);
75048+ memset(gr_usermode, 0, sizeof(struct gr_arg));
75049+ memset(gr_system_salt, 0, GR_SALT_LEN);
75050+ memset(gr_system_sum, 0, GR_SHA_LEN);
75051+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
75052+ } else if (gr_acl_is_enabled()) {
75053+ gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
75054+ error = -EPERM;
75055+ } else {
75056+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
75057+ error = -EAGAIN;
75058+ }
75059+ break;
75060+ case GR_ENABLE:
75061+ if (!gr_acl_is_enabled() && !(error2 = gracl_init(gr_usermode)))
75062+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
75063+ else {
75064+ if (gr_acl_is_enabled())
75065+ error = -EAGAIN;
75066+ else
75067+ error = error2;
75068+ gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
75069+ }
75070+ break;
75071+ case GR_OLDRELOAD:
75072+ oldmode = 1;
75073+ case GR_RELOAD:
75074+ if (!gr_acl_is_enabled()) {
75075+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
75076+ error = -EAGAIN;
75077+ } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
75078+ error2 = gracl_reload(gr_usermode, oldmode);
75079+ if (!error2)
75080+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
75081+ else {
75082+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
75083+ error = error2;
75084+ }
75085+ } else {
75086+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
75087+ error = -EPERM;
75088+ }
75089+ break;
75090+ case GR_SEGVMOD:
75091+ if (unlikely(!gr_acl_is_enabled())) {
75092+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
75093+ error = -EAGAIN;
75094+ break;
75095+ }
75096+
75097+ if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
75098+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
75099+ if (gr_usermode->segv_device && gr_usermode->segv_inode) {
75100+ struct acl_subject_label *segvacl;
75101+ segvacl =
75102+ lookup_acl_subj_label(gr_usermode->segv_inode,
75103+ gr_usermode->segv_device,
75104+ current->role);
75105+ if (segvacl) {
75106+ segvacl->crashes = 0;
75107+ segvacl->expires = 0;
75108+ }
75109+ } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
75110+ gr_remove_uid(gr_usermode->segv_uid);
75111+ }
75112+ } else {
75113+ gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
75114+ error = -EPERM;
75115+ }
75116+ break;
75117+ case GR_SPROLE:
75118+ case GR_SPROLEPAM:
75119+ if (unlikely(!gr_acl_is_enabled())) {
75120+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
75121+ error = -EAGAIN;
75122+ break;
75123+ }
75124+
75125+ if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
75126+ current->role->expires = 0;
75127+ current->role->auth_attempts = 0;
75128+ }
75129+
75130+ if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
75131+ time_after(current->role->expires, get_seconds())) {
75132+ error = -EBUSY;
75133+ goto out;
75134+ }
75135+
75136+ if (lookup_special_role_auth
75137+ (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
75138+ && ((!sprole_salt && !sprole_sum)
75139+ || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
75140+ char *p = "";
75141+ assign_special_role(gr_usermode->sp_role);
75142+ read_lock(&tasklist_lock);
75143+ if (current->real_parent)
75144+ p = current->real_parent->role->rolename;
75145+ read_unlock(&tasklist_lock);
75146+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
75147+ p, acl_sp_role_value);
75148+ } else {
75149+ gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
75150+ error = -EPERM;
75151+ if(!(current->role->auth_attempts++))
75152+ current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
75153+
75154+ goto out;
75155+ }
75156+ break;
75157+ case GR_UNSPROLE:
75158+ if (unlikely(!gr_acl_is_enabled())) {
75159+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
75160+ error = -EAGAIN;
75161+ break;
75162+ }
75163+
75164+ if (current->role->roletype & GR_ROLE_SPECIAL) {
75165+ char *p = "";
75166+ int i = 0;
75167+
75168+ read_lock(&tasklist_lock);
75169+ if (current->real_parent) {
75170+ p = current->real_parent->role->rolename;
75171+ i = current->real_parent->acl_role_id;
75172+ }
75173+ read_unlock(&tasklist_lock);
75174+
75175+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
75176+ gr_set_acls(1);
75177+ } else {
75178+ error = -EPERM;
75179+ goto out;
75180+ }
75181+ break;
75182+ default:
75183+ gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
75184+ error = -EINVAL;
75185+ break;
75186+ }
75187+
75188+ if (error != -EPERM)
75189+ goto out;
75190+
75191+ if(!(gr_auth_attempts++))
75192+ gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
75193+
75194+ out:
75195+ mutex_unlock(&gr_dev_mutex);
75196+
75197+ if (!error)
75198+ error = req_count;
75199+
75200+ return error;
75201+}
75202+
75203+int
75204+gr_set_acls(const int type)
75205+{
75206+ struct task_struct *task, *task2;
75207+ struct acl_role_label *role = current->role;
75208+ struct acl_subject_label *subj;
75209+ __u16 acl_role_id = current->acl_role_id;
75210+ const struct cred *cred;
75211+ int ret;
75212+
75213+ rcu_read_lock();
75214+ read_lock(&tasklist_lock);
75215+ read_lock(&grsec_exec_file_lock);
75216+ do_each_thread(task2, task) {
75217+ /* check to see if we're called from the exit handler,
75218+ if so, only replace ACLs that have inherited the admin
75219+ ACL */
75220+
75221+ if (type && (task->role != role ||
75222+ task->acl_role_id != acl_role_id))
75223+ continue;
75224+
75225+ task->acl_role_id = 0;
75226+ task->acl_sp_role = 0;
75227+ task->inherited = 0;
75228+
75229+ if (task->exec_file) {
75230+ cred = __task_cred(task);
75231+ task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
75232+ subj = __gr_get_subject_for_task(polstate, task, NULL);
75233+ if (subj == NULL) {
75234+ ret = -EINVAL;
75235+ read_unlock(&grsec_exec_file_lock);
75236+ read_unlock(&tasklist_lock);
75237+ rcu_read_unlock();
75238+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task_pid_nr(task));
75239+ return ret;
75240+ }
75241+ __gr_apply_subject_to_task(polstate, task, subj);
75242+ } else {
75243+ // it's a kernel process
75244+ task->role = polstate->kernel_role;
75245+ task->acl = polstate->kernel_role->root_label;
75246+#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
75247+ task->acl->mode &= ~GR_PROCFIND;
75248+#endif
75249+ }
75250+ } while_each_thread(task2, task);
75251+ read_unlock(&grsec_exec_file_lock);
75252+ read_unlock(&tasklist_lock);
75253+ rcu_read_unlock();
75254+
75255+ return 0;
75256+}
75257diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
75258new file mode 100644
75259index 0000000..39645c9
75260--- /dev/null
75261+++ b/grsecurity/gracl_res.c
75262@@ -0,0 +1,68 @@
75263+#include <linux/kernel.h>
75264+#include <linux/sched.h>
75265+#include <linux/gracl.h>
75266+#include <linux/grinternal.h>
75267+
75268+static const char *restab_log[] = {
75269+ [RLIMIT_CPU] = "RLIMIT_CPU",
75270+ [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
75271+ [RLIMIT_DATA] = "RLIMIT_DATA",
75272+ [RLIMIT_STACK] = "RLIMIT_STACK",
75273+ [RLIMIT_CORE] = "RLIMIT_CORE",
75274+ [RLIMIT_RSS] = "RLIMIT_RSS",
75275+ [RLIMIT_NPROC] = "RLIMIT_NPROC",
75276+ [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
75277+ [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
75278+ [RLIMIT_AS] = "RLIMIT_AS",
75279+ [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
75280+ [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
75281+ [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
75282+ [RLIMIT_NICE] = "RLIMIT_NICE",
75283+ [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
75284+ [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
75285+ [GR_CRASH_RES] = "RLIMIT_CRASH"
75286+};
75287+
75288+void
75289+gr_log_resource(const struct task_struct *task,
75290+ const int res, const unsigned long wanted, const int gt)
75291+{
75292+ const struct cred *cred;
75293+ unsigned long rlim;
75294+
75295+ if (!gr_acl_is_enabled() && !grsec_resource_logging)
75296+ return;
75297+
75298+ // not yet supported resource
75299+ if (unlikely(!restab_log[res]))
75300+ return;
75301+
75302+ if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
75303+ rlim = task_rlimit_max(task, res);
75304+ else
75305+ rlim = task_rlimit(task, res);
75306+
75307+ if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
75308+ return;
75309+
75310+ rcu_read_lock();
75311+ cred = __task_cred(task);
75312+
75313+ if (res == RLIMIT_NPROC &&
75314+ (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
75315+ cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
75316+ goto out_rcu_unlock;
75317+ else if (res == RLIMIT_MEMLOCK &&
75318+ cap_raised(cred->cap_effective, CAP_IPC_LOCK))
75319+ goto out_rcu_unlock;
75320+ else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
75321+ goto out_rcu_unlock;
75322+ rcu_read_unlock();
75323+
75324+ gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
75325+
75326+ return;
75327+out_rcu_unlock:
75328+ rcu_read_unlock();
75329+ return;
75330+}
75331diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
75332new file mode 100644
75333index 0000000..2040e61
75334--- /dev/null
75335+++ b/grsecurity/gracl_segv.c
75336@@ -0,0 +1,313 @@
75337+#include <linux/kernel.h>
75338+#include <linux/mm.h>
75339+#include <asm/uaccess.h>
75340+#include <asm/errno.h>
75341+#include <asm/mman.h>
75342+#include <net/sock.h>
75343+#include <linux/file.h>
75344+#include <linux/fs.h>
75345+#include <linux/net.h>
75346+#include <linux/in.h>
75347+#include <linux/slab.h>
75348+#include <linux/types.h>
75349+#include <linux/sched.h>
75350+#include <linux/timer.h>
75351+#include <linux/gracl.h>
75352+#include <linux/grsecurity.h>
75353+#include <linux/grinternal.h>
75354+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
75355+#include <linux/magic.h>
75356+#include <linux/pagemap.h>
75357+#include "../fs/btrfs/async-thread.h"
75358+#include "../fs/btrfs/ctree.h"
75359+#include "../fs/btrfs/btrfs_inode.h"
75360+#endif
75361+
75362+static struct crash_uid *uid_set;
75363+static unsigned short uid_used;
75364+static DEFINE_SPINLOCK(gr_uid_lock);
75365+extern rwlock_t gr_inode_lock;
75366+extern struct acl_subject_label *
75367+ lookup_acl_subj_label(const ino_t inode, const dev_t dev,
75368+ struct acl_role_label *role);
75369+
75370+static inline dev_t __get_dev(const struct dentry *dentry)
75371+{
75372+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
75373+ if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
75374+ return BTRFS_I(dentry->d_inode)->root->anon_dev;
75375+ else
75376+#endif
75377+ return dentry->d_sb->s_dev;
75378+}
75379+
75380+int
75381+gr_init_uidset(void)
75382+{
75383+ uid_set =
75384+ kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
75385+ uid_used = 0;
75386+
75387+ return uid_set ? 1 : 0;
75388+}
75389+
75390+void
75391+gr_free_uidset(void)
75392+{
75393+ if (uid_set) {
75394+ struct crash_uid *tmpset;
75395+ spin_lock(&gr_uid_lock);
75396+ tmpset = uid_set;
75397+ uid_set = NULL;
75398+ uid_used = 0;
75399+ spin_unlock(&gr_uid_lock);
75400+ if (tmpset)
75401+ kfree(tmpset);
75402+ }
75403+
75404+ return;
75405+}
75406+
75407+int
75408+gr_find_uid(const uid_t uid)
75409+{
75410+ struct crash_uid *tmp = uid_set;
75411+ uid_t buid;
75412+ int low = 0, high = uid_used - 1, mid;
75413+
75414+ while (high >= low) {
75415+ mid = (low + high) >> 1;
75416+ buid = tmp[mid].uid;
75417+ if (buid == uid)
75418+ return mid;
75419+ if (buid > uid)
75420+ high = mid - 1;
75421+ if (buid < uid)
75422+ low = mid + 1;
75423+ }
75424+
75425+ return -1;
75426+}
75427+
75428+static __inline__ void
75429+gr_insertsort(void)
75430+{
75431+ unsigned short i, j;
75432+ struct crash_uid index;
75433+
75434+ for (i = 1; i < uid_used; i++) {
75435+ index = uid_set[i];
75436+ j = i;
75437+ while ((j > 0) && uid_set[j - 1].uid > index.uid) {
75438+ uid_set[j] = uid_set[j - 1];
75439+ j--;
75440+ }
75441+ uid_set[j] = index;
75442+ }
75443+
75444+ return;
75445+}
75446+
75447+static __inline__ void
75448+gr_insert_uid(const kuid_t kuid, const unsigned long expires)
75449+{
75450+ int loc;
75451+ uid_t uid = GR_GLOBAL_UID(kuid);
75452+
75453+ if (uid_used == GR_UIDTABLE_MAX)
75454+ return;
75455+
75456+ loc = gr_find_uid(uid);
75457+
75458+ if (loc >= 0) {
75459+ uid_set[loc].expires = expires;
75460+ return;
75461+ }
75462+
75463+ uid_set[uid_used].uid = uid;
75464+ uid_set[uid_used].expires = expires;
75465+ uid_used++;
75466+
75467+ gr_insertsort();
75468+
75469+ return;
75470+}
75471+
75472+void
75473+gr_remove_uid(const unsigned short loc)
75474+{
75475+ unsigned short i;
75476+
75477+ for (i = loc + 1; i < uid_used; i++)
75478+ uid_set[i - 1] = uid_set[i];
75479+
75480+ uid_used--;
75481+
75482+ return;
75483+}
75484+
75485+int
75486+gr_check_crash_uid(const kuid_t kuid)
75487+{
75488+ int loc;
75489+ int ret = 0;
75490+ uid_t uid;
75491+
75492+ if (unlikely(!gr_acl_is_enabled()))
75493+ return 0;
75494+
75495+ uid = GR_GLOBAL_UID(kuid);
75496+
75497+ spin_lock(&gr_uid_lock);
75498+ loc = gr_find_uid(uid);
75499+
75500+ if (loc < 0)
75501+ goto out_unlock;
75502+
75503+ if (time_before_eq(uid_set[loc].expires, get_seconds()))
75504+ gr_remove_uid(loc);
75505+ else
75506+ ret = 1;
75507+
75508+out_unlock:
75509+ spin_unlock(&gr_uid_lock);
75510+ return ret;
75511+}
75512+
75513+static __inline__ int
75514+proc_is_setxid(const struct cred *cred)
75515+{
75516+ if (!uid_eq(cred->uid, cred->euid) || !uid_eq(cred->uid, cred->suid) ||
75517+ !uid_eq(cred->uid, cred->fsuid))
75518+ return 1;
75519+ if (!gid_eq(cred->gid, cred->egid) || !gid_eq(cred->gid, cred->sgid) ||
75520+ !gid_eq(cred->gid, cred->fsgid))
75521+ return 1;
75522+
75523+ return 0;
75524+}
75525+
75526+extern int gr_fake_force_sig(int sig, struct task_struct *t);
75527+
75528+void
75529+gr_handle_crash(struct task_struct *task, const int sig)
75530+{
75531+ struct acl_subject_label *curr;
75532+ struct task_struct *tsk, *tsk2;
75533+ const struct cred *cred;
75534+ const struct cred *cred2;
75535+
75536+ if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
75537+ return;
75538+
75539+ if (unlikely(!gr_acl_is_enabled()))
75540+ return;
75541+
75542+ curr = task->acl;
75543+
75544+ if (!(curr->resmask & (1U << GR_CRASH_RES)))
75545+ return;
75546+
75547+ if (time_before_eq(curr->expires, get_seconds())) {
75548+ curr->expires = 0;
75549+ curr->crashes = 0;
75550+ }
75551+
75552+ curr->crashes++;
75553+
75554+ if (!curr->expires)
75555+ curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
75556+
75557+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
75558+ time_after(curr->expires, get_seconds())) {
75559+ rcu_read_lock();
75560+ cred = __task_cred(task);
75561+ if (gr_is_global_nonroot(cred->uid) && proc_is_setxid(cred)) {
75562+ gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
75563+ spin_lock(&gr_uid_lock);
75564+ gr_insert_uid(cred->uid, curr->expires);
75565+ spin_unlock(&gr_uid_lock);
75566+ curr->expires = 0;
75567+ curr->crashes = 0;
75568+ read_lock(&tasklist_lock);
75569+ do_each_thread(tsk2, tsk) {
75570+ cred2 = __task_cred(tsk);
75571+ if (tsk != task && uid_eq(cred2->uid, cred->uid))
75572+ gr_fake_force_sig(SIGKILL, tsk);
75573+ } while_each_thread(tsk2, tsk);
75574+ read_unlock(&tasklist_lock);
75575+ } else {
75576+ gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
75577+ read_lock(&tasklist_lock);
75578+ read_lock(&grsec_exec_file_lock);
75579+ do_each_thread(tsk2, tsk) {
75580+ if (likely(tsk != task)) {
75581+ // if this thread has the same subject as the one that triggered
75582+ // RES_CRASH and it's the same binary, kill it
75583+ if (tsk->acl == task->acl && gr_is_same_file(tsk->exec_file, task->exec_file))
75584+ gr_fake_force_sig(SIGKILL, tsk);
75585+ }
75586+ } while_each_thread(tsk2, tsk);
75587+ read_unlock(&grsec_exec_file_lock);
75588+ read_unlock(&tasklist_lock);
75589+ }
75590+ rcu_read_unlock();
75591+ }
75592+
75593+ return;
75594+}
75595+
75596+int
75597+gr_check_crash_exec(const struct file *filp)
75598+{
75599+ struct acl_subject_label *curr;
75600+
75601+ if (unlikely(!gr_acl_is_enabled()))
75602+ return 0;
75603+
75604+ read_lock(&gr_inode_lock);
75605+ curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
75606+ __get_dev(filp->f_path.dentry),
75607+ current->role);
75608+ read_unlock(&gr_inode_lock);
75609+
75610+ if (!curr || !(curr->resmask & (1U << GR_CRASH_RES)) ||
75611+ (!curr->crashes && !curr->expires))
75612+ return 0;
75613+
75614+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
75615+ time_after(curr->expires, get_seconds()))
75616+ return 1;
75617+ else if (time_before_eq(curr->expires, get_seconds())) {
75618+ curr->crashes = 0;
75619+ curr->expires = 0;
75620+ }
75621+
75622+ return 0;
75623+}
75624+
75625+void
75626+gr_handle_alertkill(struct task_struct *task)
75627+{
75628+ struct acl_subject_label *curracl;
75629+ __u32 curr_ip;
75630+ struct task_struct *p, *p2;
75631+
75632+ if (unlikely(!gr_acl_is_enabled()))
75633+ return;
75634+
75635+ curracl = task->acl;
75636+ curr_ip = task->signal->curr_ip;
75637+
75638+ if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
75639+ read_lock(&tasklist_lock);
75640+ do_each_thread(p2, p) {
75641+ if (p->signal->curr_ip == curr_ip)
75642+ gr_fake_force_sig(SIGKILL, p);
75643+ } while_each_thread(p2, p);
75644+ read_unlock(&tasklist_lock);
75645+ } else if (curracl->mode & GR_KILLPROC)
75646+ gr_fake_force_sig(SIGKILL, task);
75647+
75648+ return;
75649+}
75650diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
75651new file mode 100644
75652index 0000000..6b0c9cc
75653--- /dev/null
75654+++ b/grsecurity/gracl_shm.c
75655@@ -0,0 +1,40 @@
75656+#include <linux/kernel.h>
75657+#include <linux/mm.h>
75658+#include <linux/sched.h>
75659+#include <linux/file.h>
75660+#include <linux/ipc.h>
75661+#include <linux/gracl.h>
75662+#include <linux/grsecurity.h>
75663+#include <linux/grinternal.h>
75664+
75665+int
75666+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
75667+ const u64 shm_createtime, const kuid_t cuid, const int shmid)
75668+{
75669+ struct task_struct *task;
75670+
75671+ if (!gr_acl_is_enabled())
75672+ return 1;
75673+
75674+ rcu_read_lock();
75675+ read_lock(&tasklist_lock);
75676+
75677+ task = find_task_by_vpid(shm_cprid);
75678+
75679+ if (unlikely(!task))
75680+ task = find_task_by_vpid(shm_lapid);
75681+
75682+ if (unlikely(task && (time_before_eq64(task->start_time, shm_createtime) ||
75683+ (task_pid_nr(task) == shm_lapid)) &&
75684+ (task->acl->mode & GR_PROTSHM) &&
75685+ (task->acl != current->acl))) {
75686+ read_unlock(&tasklist_lock);
75687+ rcu_read_unlock();
75688+ gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, GR_GLOBAL_UID(cuid), shm_cprid, shmid);
75689+ return 0;
75690+ }
75691+ read_unlock(&tasklist_lock);
75692+ rcu_read_unlock();
75693+
75694+ return 1;
75695+}
75696diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
75697new file mode 100644
75698index 0000000..bc0be01
75699--- /dev/null
75700+++ b/grsecurity/grsec_chdir.c
75701@@ -0,0 +1,19 @@
75702+#include <linux/kernel.h>
75703+#include <linux/sched.h>
75704+#include <linux/fs.h>
75705+#include <linux/file.h>
75706+#include <linux/grsecurity.h>
75707+#include <linux/grinternal.h>
75708+
75709+void
75710+gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
75711+{
75712+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
75713+ if ((grsec_enable_chdir && grsec_enable_group &&
75714+ in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
75715+ !grsec_enable_group)) {
75716+ gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
75717+ }
75718+#endif
75719+ return;
75720+}
75721diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
75722new file mode 100644
75723index 0000000..6d99cec
75724--- /dev/null
75725+++ b/grsecurity/grsec_chroot.c
75726@@ -0,0 +1,385 @@
75727+#include <linux/kernel.h>
75728+#include <linux/module.h>
75729+#include <linux/sched.h>
75730+#include <linux/file.h>
75731+#include <linux/fs.h>
75732+#include <linux/mount.h>
75733+#include <linux/types.h>
75734+#include "../fs/mount.h"
75735+#include <linux/grsecurity.h>
75736+#include <linux/grinternal.h>
75737+
75738+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
75739+int gr_init_ran;
75740+#endif
75741+
75742+void gr_set_chroot_entries(struct task_struct *task, const struct path *path)
75743+{
75744+#ifdef CONFIG_GRKERNSEC
75745+ if (task_pid_nr(task) > 1 && path->dentry != init_task.fs->root.dentry &&
75746+ path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root
75747+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
75748+ && gr_init_ran
75749+#endif
75750+ )
75751+ task->gr_is_chrooted = 1;
75752+ else {
75753+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
75754+ if (task_pid_nr(task) == 1 && !gr_init_ran)
75755+ gr_init_ran = 1;
75756+#endif
75757+ task->gr_is_chrooted = 0;
75758+ }
75759+
75760+ task->gr_chroot_dentry = path->dentry;
75761+#endif
75762+ return;
75763+}
75764+
75765+void gr_clear_chroot_entries(struct task_struct *task)
75766+{
75767+#ifdef CONFIG_GRKERNSEC
75768+ task->gr_is_chrooted = 0;
75769+ task->gr_chroot_dentry = NULL;
75770+#endif
75771+ return;
75772+}
75773+
75774+int
75775+gr_handle_chroot_unix(const pid_t pid)
75776+{
75777+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
75778+ struct task_struct *p;
75779+
75780+ if (unlikely(!grsec_enable_chroot_unix))
75781+ return 1;
75782+
75783+ if (likely(!proc_is_chrooted(current)))
75784+ return 1;
75785+
75786+ rcu_read_lock();
75787+ read_lock(&tasklist_lock);
75788+ p = find_task_by_vpid_unrestricted(pid);
75789+ if (unlikely(p && !have_same_root(current, p))) {
75790+ read_unlock(&tasklist_lock);
75791+ rcu_read_unlock();
75792+ gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
75793+ return 0;
75794+ }
75795+ read_unlock(&tasklist_lock);
75796+ rcu_read_unlock();
75797+#endif
75798+ return 1;
75799+}
75800+
75801+int
75802+gr_handle_chroot_nice(void)
75803+{
75804+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
75805+ if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
75806+ gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
75807+ return -EPERM;
75808+ }
75809+#endif
75810+ return 0;
75811+}
75812+
75813+int
75814+gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
75815+{
75816+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
75817+ if (grsec_enable_chroot_nice && (niceval < task_nice(p))
75818+ && proc_is_chrooted(current)) {
75819+ gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, task_pid_nr(p));
75820+ return -EACCES;
75821+ }
75822+#endif
75823+ return 0;
75824+}
75825+
75826+int
75827+gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
75828+{
75829+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
75830+ struct task_struct *p;
75831+ int ret = 0;
75832+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
75833+ return ret;
75834+
75835+ read_lock(&tasklist_lock);
75836+ do_each_pid_task(pid, type, p) {
75837+ if (!have_same_root(current, p)) {
75838+ ret = 1;
75839+ goto out;
75840+ }
75841+ } while_each_pid_task(pid, type, p);
75842+out:
75843+ read_unlock(&tasklist_lock);
75844+ return ret;
75845+#endif
75846+ return 0;
75847+}
75848+
75849+int
75850+gr_pid_is_chrooted(struct task_struct *p)
75851+{
75852+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
75853+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
75854+ return 0;
75855+
75856+ if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
75857+ !have_same_root(current, p)) {
75858+ return 1;
75859+ }
75860+#endif
75861+ return 0;
75862+}
75863+
75864+EXPORT_SYMBOL_GPL(gr_pid_is_chrooted);
75865+
75866+#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
75867+int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
75868+{
75869+ struct path path, currentroot;
75870+ int ret = 0;
75871+
75872+ path.dentry = (struct dentry *)u_dentry;
75873+ path.mnt = (struct vfsmount *)u_mnt;
75874+ get_fs_root(current->fs, &currentroot);
75875+ if (path_is_under(&path, &currentroot))
75876+ ret = 1;
75877+ path_put(&currentroot);
75878+
75879+ return ret;
75880+}
75881+#endif
75882+
75883+int
75884+gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
75885+{
75886+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
75887+ if (!grsec_enable_chroot_fchdir)
75888+ return 1;
75889+
75890+ if (!proc_is_chrooted(current))
75891+ return 1;
75892+ else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
75893+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
75894+ return 0;
75895+ }
75896+#endif
75897+ return 1;
75898+}
75899+
75900+int
75901+gr_chroot_fhandle(void)
75902+{
75903+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
75904+ if (!grsec_enable_chroot_fchdir)
75905+ return 1;
75906+
75907+ if (!proc_is_chrooted(current))
75908+ return 1;
75909+ else {
75910+ gr_log_noargs(GR_DONT_AUDIT, GR_CHROOT_FHANDLE_MSG);
75911+ return 0;
75912+ }
75913+#endif
75914+ return 1;
75915+}
75916+
75917+int
75918+gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
75919+ const u64 shm_createtime)
75920+{
75921+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
75922+ struct task_struct *p;
75923+
75924+ if (unlikely(!grsec_enable_chroot_shmat))
75925+ return 1;
75926+
75927+ if (likely(!proc_is_chrooted(current)))
75928+ return 1;
75929+
75930+ rcu_read_lock();
75931+ read_lock(&tasklist_lock);
75932+
75933+ if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
75934+ if (time_before_eq64(p->start_time, shm_createtime)) {
75935+ if (have_same_root(current, p)) {
75936+ goto allow;
75937+ } else {
75938+ read_unlock(&tasklist_lock);
75939+ rcu_read_unlock();
75940+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
75941+ return 0;
75942+ }
75943+ }
75944+ /* creator exited, pid reuse, fall through to next check */
75945+ }
75946+ if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
75947+ if (unlikely(!have_same_root(current, p))) {
75948+ read_unlock(&tasklist_lock);
75949+ rcu_read_unlock();
75950+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
75951+ return 0;
75952+ }
75953+ }
75954+
75955+allow:
75956+ read_unlock(&tasklist_lock);
75957+ rcu_read_unlock();
75958+#endif
75959+ return 1;
75960+}
75961+
75962+void
75963+gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
75964+{
75965+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
75966+ if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
75967+ gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
75968+#endif
75969+ return;
75970+}
75971+
75972+int
75973+gr_handle_chroot_mknod(const struct dentry *dentry,
75974+ const struct vfsmount *mnt, const int mode)
75975+{
75976+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
75977+ if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
75978+ proc_is_chrooted(current)) {
75979+ gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
75980+ return -EPERM;
75981+ }
75982+#endif
75983+ return 0;
75984+}
75985+
75986+int
75987+gr_handle_chroot_mount(const struct dentry *dentry,
75988+ const struct vfsmount *mnt, const char *dev_name)
75989+{
75990+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
75991+ if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
75992+ gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
75993+ return -EPERM;
75994+ }
75995+#endif
75996+ return 0;
75997+}
75998+
75999+int
76000+gr_handle_chroot_pivot(void)
76001+{
76002+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
76003+ if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
76004+ gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
76005+ return -EPERM;
76006+ }
76007+#endif
76008+ return 0;
76009+}
76010+
76011+int
76012+gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
76013+{
76014+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
76015+ if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
76016+ !gr_is_outside_chroot(dentry, mnt)) {
76017+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
76018+ return -EPERM;
76019+ }
76020+#endif
76021+ return 0;
76022+}
76023+
76024+extern const char *captab_log[];
76025+extern int captab_log_entries;
76026+
76027+int
76028+gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
76029+{
76030+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
76031+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
76032+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
76033+ if (cap_raised(chroot_caps, cap)) {
76034+ if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
76035+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
76036+ }
76037+ return 0;
76038+ }
76039+ }
76040+#endif
76041+ return 1;
76042+}
76043+
76044+int
76045+gr_chroot_is_capable(const int cap)
76046+{
76047+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
76048+ return gr_task_chroot_is_capable(current, current_cred(), cap);
76049+#endif
76050+ return 1;
76051+}
76052+
76053+int
76054+gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
76055+{
76056+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
76057+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
76058+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
76059+ if (cap_raised(chroot_caps, cap)) {
76060+ return 0;
76061+ }
76062+ }
76063+#endif
76064+ return 1;
76065+}
76066+
76067+int
76068+gr_chroot_is_capable_nolog(const int cap)
76069+{
76070+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
76071+ return gr_task_chroot_is_capable_nolog(current, cap);
76072+#endif
76073+ return 1;
76074+}
76075+
76076+int
76077+gr_handle_chroot_sysctl(const int op)
76078+{
76079+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
76080+ if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
76081+ proc_is_chrooted(current))
76082+ return -EACCES;
76083+#endif
76084+ return 0;
76085+}
76086+
76087+void
76088+gr_handle_chroot_chdir(const struct path *path)
76089+{
76090+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
76091+ if (grsec_enable_chroot_chdir)
76092+ set_fs_pwd(current->fs, path);
76093+#endif
76094+ return;
76095+}
76096+
76097+int
76098+gr_handle_chroot_chmod(const struct dentry *dentry,
76099+ const struct vfsmount *mnt, const int mode)
76100+{
76101+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
76102+ /* allow chmod +s on directories, but not files */
76103+ if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
76104+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
76105+ proc_is_chrooted(current)) {
76106+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
76107+ return -EPERM;
76108+ }
76109+#endif
76110+ return 0;
76111+}
76112diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
76113new file mode 100644
76114index 0000000..0f9ac91
76115--- /dev/null
76116+++ b/grsecurity/grsec_disabled.c
76117@@ -0,0 +1,440 @@
76118+#include <linux/kernel.h>
76119+#include <linux/module.h>
76120+#include <linux/sched.h>
76121+#include <linux/file.h>
76122+#include <linux/fs.h>
76123+#include <linux/kdev_t.h>
76124+#include <linux/net.h>
76125+#include <linux/in.h>
76126+#include <linux/ip.h>
76127+#include <linux/skbuff.h>
76128+#include <linux/sysctl.h>
76129+
76130+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
76131+void
76132+pax_set_initial_flags(struct linux_binprm *bprm)
76133+{
76134+ return;
76135+}
76136+#endif
76137+
76138+#ifdef CONFIG_SYSCTL
76139+__u32
76140+gr_handle_sysctl(const struct ctl_table * table, const int op)
76141+{
76142+ return 0;
76143+}
76144+#endif
76145+
76146+#ifdef CONFIG_TASKSTATS
76147+int gr_is_taskstats_denied(int pid)
76148+{
76149+ return 0;
76150+}
76151+#endif
76152+
76153+int
76154+gr_acl_is_enabled(void)
76155+{
76156+ return 0;
76157+}
76158+
76159+int
76160+gr_learn_cap(const struct task_struct *task, const struct cred *cred, const int cap)
76161+{
76162+ return 0;
76163+}
76164+
76165+void
76166+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
76167+{
76168+ return;
76169+}
76170+
76171+int
76172+gr_handle_rawio(const struct inode *inode)
76173+{
76174+ return 0;
76175+}
76176+
76177+void
76178+gr_acl_handle_psacct(struct task_struct *task, const long code)
76179+{
76180+ return;
76181+}
76182+
76183+int
76184+gr_handle_ptrace(struct task_struct *task, const long request)
76185+{
76186+ return 0;
76187+}
76188+
76189+int
76190+gr_handle_proc_ptrace(struct task_struct *task)
76191+{
76192+ return 0;
76193+}
76194+
76195+int
76196+gr_set_acls(const int type)
76197+{
76198+ return 0;
76199+}
76200+
76201+int
76202+gr_check_hidden_task(const struct task_struct *tsk)
76203+{
76204+ return 0;
76205+}
76206+
76207+int
76208+gr_check_protected_task(const struct task_struct *task)
76209+{
76210+ return 0;
76211+}
76212+
76213+int
76214+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
76215+{
76216+ return 0;
76217+}
76218+
76219+void
76220+gr_copy_label(struct task_struct *tsk)
76221+{
76222+ return;
76223+}
76224+
76225+void
76226+gr_set_pax_flags(struct task_struct *task)
76227+{
76228+ return;
76229+}
76230+
76231+int
76232+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
76233+ const int unsafe_share)
76234+{
76235+ return 0;
76236+}
76237+
76238+void
76239+gr_handle_delete(const ino_t ino, const dev_t dev)
76240+{
76241+ return;
76242+}
76243+
76244+void
76245+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
76246+{
76247+ return;
76248+}
76249+
76250+void
76251+gr_handle_crash(struct task_struct *task, const int sig)
76252+{
76253+ return;
76254+}
76255+
76256+int
76257+gr_check_crash_exec(const struct file *filp)
76258+{
76259+ return 0;
76260+}
76261+
76262+int
76263+gr_check_crash_uid(const kuid_t uid)
76264+{
76265+ return 0;
76266+}
76267+
76268+void
76269+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
76270+ struct dentry *old_dentry,
76271+ struct dentry *new_dentry,
76272+ struct vfsmount *mnt, const __u8 replace, unsigned int flags)
76273+{
76274+ return;
76275+}
76276+
76277+int
76278+gr_search_socket(const int family, const int type, const int protocol)
76279+{
76280+ return 1;
76281+}
76282+
76283+int
76284+gr_search_connectbind(const int mode, const struct socket *sock,
76285+ const struct sockaddr_in *addr)
76286+{
76287+ return 0;
76288+}
76289+
76290+void
76291+gr_handle_alertkill(struct task_struct *task)
76292+{
76293+ return;
76294+}
76295+
76296+__u32
76297+gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
76298+{
76299+ return 1;
76300+}
76301+
76302+__u32
76303+gr_acl_handle_hidden_file(const struct dentry * dentry,
76304+ const struct vfsmount * mnt)
76305+{
76306+ return 1;
76307+}
76308+
76309+__u32
76310+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
76311+ int acc_mode)
76312+{
76313+ return 1;
76314+}
76315+
76316+__u32
76317+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
76318+{
76319+ return 1;
76320+}
76321+
76322+__u32
76323+gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
76324+{
76325+ return 1;
76326+}
76327+
76328+int
76329+gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
76330+ unsigned int *vm_flags)
76331+{
76332+ return 1;
76333+}
76334+
76335+__u32
76336+gr_acl_handle_truncate(const struct dentry * dentry,
76337+ const struct vfsmount * mnt)
76338+{
76339+ return 1;
76340+}
76341+
76342+__u32
76343+gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
76344+{
76345+ return 1;
76346+}
76347+
76348+__u32
76349+gr_acl_handle_access(const struct dentry * dentry,
76350+ const struct vfsmount * mnt, const int fmode)
76351+{
76352+ return 1;
76353+}
76354+
76355+__u32
76356+gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
76357+ umode_t *mode)
76358+{
76359+ return 1;
76360+}
76361+
76362+__u32
76363+gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
76364+{
76365+ return 1;
76366+}
76367+
76368+__u32
76369+gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
76370+{
76371+ return 1;
76372+}
76373+
76374+__u32
76375+gr_acl_handle_removexattr(const struct dentry * dentry, const struct vfsmount * mnt)
76376+{
76377+ return 1;
76378+}
76379+
76380+void
76381+grsecurity_init(void)
76382+{
76383+ return;
76384+}
76385+
76386+umode_t gr_acl_umask(void)
76387+{
76388+ return 0;
76389+}
76390+
76391+__u32
76392+gr_acl_handle_mknod(const struct dentry * new_dentry,
76393+ const struct dentry * parent_dentry,
76394+ const struct vfsmount * parent_mnt,
76395+ const int mode)
76396+{
76397+ return 1;
76398+}
76399+
76400+__u32
76401+gr_acl_handle_mkdir(const struct dentry * new_dentry,
76402+ const struct dentry * parent_dentry,
76403+ const struct vfsmount * parent_mnt)
76404+{
76405+ return 1;
76406+}
76407+
76408+__u32
76409+gr_acl_handle_symlink(const struct dentry * new_dentry,
76410+ const struct dentry * parent_dentry,
76411+ const struct vfsmount * parent_mnt, const struct filename *from)
76412+{
76413+ return 1;
76414+}
76415+
76416+__u32
76417+gr_acl_handle_link(const struct dentry * new_dentry,
76418+ const struct dentry * parent_dentry,
76419+ const struct vfsmount * parent_mnt,
76420+ const struct dentry * old_dentry,
76421+ const struct vfsmount * old_mnt, const struct filename *to)
76422+{
76423+ return 1;
76424+}
76425+
76426+int
76427+gr_acl_handle_rename(const struct dentry *new_dentry,
76428+ const struct dentry *parent_dentry,
76429+ const struct vfsmount *parent_mnt,
76430+ const struct dentry *old_dentry,
76431+ const struct inode *old_parent_inode,
76432+ const struct vfsmount *old_mnt, const struct filename *newname,
76433+ unsigned int flags)
76434+{
76435+ return 0;
76436+}
76437+
76438+int
76439+gr_acl_handle_filldir(const struct file *file, const char *name,
76440+ const int namelen, const ino_t ino)
76441+{
76442+ return 1;
76443+}
76444+
76445+int
76446+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
76447+ const u64 shm_createtime, const kuid_t cuid, const int shmid)
76448+{
76449+ return 1;
76450+}
76451+
76452+int
76453+gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
76454+{
76455+ return 0;
76456+}
76457+
76458+int
76459+gr_search_accept(const struct socket *sock)
76460+{
76461+ return 0;
76462+}
76463+
76464+int
76465+gr_search_listen(const struct socket *sock)
76466+{
76467+ return 0;
76468+}
76469+
76470+int
76471+gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
76472+{
76473+ return 0;
76474+}
76475+
76476+__u32
76477+gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
76478+{
76479+ return 1;
76480+}
76481+
76482+__u32
76483+gr_acl_handle_creat(const struct dentry * dentry,
76484+ const struct dentry * p_dentry,
76485+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
76486+ const int imode)
76487+{
76488+ return 1;
76489+}
76490+
76491+void
76492+gr_acl_handle_exit(void)
76493+{
76494+ return;
76495+}
76496+
76497+int
76498+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
76499+{
76500+ return 1;
76501+}
76502+
76503+void
76504+gr_set_role_label(const kuid_t uid, const kgid_t gid)
76505+{
76506+ return;
76507+}
76508+
76509+int
76510+gr_acl_handle_procpidmem(const struct task_struct *task)
76511+{
76512+ return 0;
76513+}
76514+
76515+int
76516+gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
76517+{
76518+ return 0;
76519+}
76520+
76521+int
76522+gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
76523+{
76524+ return 0;
76525+}
76526+
76527+int
76528+gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
76529+{
76530+ return 0;
76531+}
76532+
76533+int
76534+gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
76535+{
76536+ return 0;
76537+}
76538+
76539+int gr_acl_enable_at_secure(void)
76540+{
76541+ return 0;
76542+}
76543+
76544+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
76545+{
76546+ return dentry->d_sb->s_dev;
76547+}
76548+
76549+void gr_put_exec_file(struct task_struct *task)
76550+{
76551+ return;
76552+}
76553+
76554+#ifdef CONFIG_SECURITY
76555+EXPORT_SYMBOL_GPL(gr_check_user_change);
76556+EXPORT_SYMBOL_GPL(gr_check_group_change);
76557+#endif
76558diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
76559new file mode 100644
76560index 0000000..14638ff
76561--- /dev/null
76562+++ b/grsecurity/grsec_exec.c
76563@@ -0,0 +1,188 @@
76564+#include <linux/kernel.h>
76565+#include <linux/sched.h>
76566+#include <linux/file.h>
76567+#include <linux/binfmts.h>
76568+#include <linux/fs.h>
76569+#include <linux/types.h>
76570+#include <linux/grdefs.h>
76571+#include <linux/grsecurity.h>
76572+#include <linux/grinternal.h>
76573+#include <linux/capability.h>
76574+#include <linux/module.h>
76575+#include <linux/compat.h>
76576+
76577+#include <asm/uaccess.h>
76578+
76579+#ifdef CONFIG_GRKERNSEC_EXECLOG
76580+static char gr_exec_arg_buf[132];
76581+static DEFINE_MUTEX(gr_exec_arg_mutex);
76582+#endif
76583+
76584+struct user_arg_ptr {
76585+#ifdef CONFIG_COMPAT
76586+ bool is_compat;
76587+#endif
76588+ union {
76589+ const char __user *const __user *native;
76590+#ifdef CONFIG_COMPAT
76591+ const compat_uptr_t __user *compat;
76592+#endif
76593+ } ptr;
76594+};
76595+
76596+extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
76597+
76598+void
76599+gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
76600+{
76601+#ifdef CONFIG_GRKERNSEC_EXECLOG
76602+ char *grarg = gr_exec_arg_buf;
76603+ unsigned int i, x, execlen = 0;
76604+ char c;
76605+
76606+ if (!((grsec_enable_execlog && grsec_enable_group &&
76607+ in_group_p(grsec_audit_gid))
76608+ || (grsec_enable_execlog && !grsec_enable_group)))
76609+ return;
76610+
76611+ mutex_lock(&gr_exec_arg_mutex);
76612+ memset(grarg, 0, sizeof(gr_exec_arg_buf));
76613+
76614+ for (i = 0; i < bprm->argc && execlen < 128; i++) {
76615+ const char __user *p;
76616+ unsigned int len;
76617+
76618+ p = get_user_arg_ptr(argv, i);
76619+ if (IS_ERR(p))
76620+ goto log;
76621+
76622+ len = strnlen_user(p, 128 - execlen);
76623+ if (len > 128 - execlen)
76624+ len = 128 - execlen;
76625+ else if (len > 0)
76626+ len--;
76627+ if (copy_from_user(grarg + execlen, p, len))
76628+ goto log;
76629+
76630+ /* rewrite unprintable characters */
76631+ for (x = 0; x < len; x++) {
76632+ c = *(grarg + execlen + x);
76633+ if (c < 32 || c > 126)
76634+ *(grarg + execlen + x) = ' ';
76635+ }
76636+
76637+ execlen += len;
76638+ *(grarg + execlen) = ' ';
76639+ *(grarg + execlen + 1) = '\0';
76640+ execlen++;
76641+ }
76642+
76643+ log:
76644+ gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
76645+ bprm->file->f_path.mnt, grarg);
76646+ mutex_unlock(&gr_exec_arg_mutex);
76647+#endif
76648+ return;
76649+}
76650+
76651+#ifdef CONFIG_GRKERNSEC
76652+extern int gr_acl_is_capable(const int cap);
76653+extern int gr_acl_is_capable_nolog(const int cap);
76654+extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
76655+extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
76656+extern int gr_chroot_is_capable(const int cap);
76657+extern int gr_chroot_is_capable_nolog(const int cap);
76658+extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
76659+extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
76660+#endif
76661+
76662+const char *captab_log[] = {
76663+ "CAP_CHOWN",
76664+ "CAP_DAC_OVERRIDE",
76665+ "CAP_DAC_READ_SEARCH",
76666+ "CAP_FOWNER",
76667+ "CAP_FSETID",
76668+ "CAP_KILL",
76669+ "CAP_SETGID",
76670+ "CAP_SETUID",
76671+ "CAP_SETPCAP",
76672+ "CAP_LINUX_IMMUTABLE",
76673+ "CAP_NET_BIND_SERVICE",
76674+ "CAP_NET_BROADCAST",
76675+ "CAP_NET_ADMIN",
76676+ "CAP_NET_RAW",
76677+ "CAP_IPC_LOCK",
76678+ "CAP_IPC_OWNER",
76679+ "CAP_SYS_MODULE",
76680+ "CAP_SYS_RAWIO",
76681+ "CAP_SYS_CHROOT",
76682+ "CAP_SYS_PTRACE",
76683+ "CAP_SYS_PACCT",
76684+ "CAP_SYS_ADMIN",
76685+ "CAP_SYS_BOOT",
76686+ "CAP_SYS_NICE",
76687+ "CAP_SYS_RESOURCE",
76688+ "CAP_SYS_TIME",
76689+ "CAP_SYS_TTY_CONFIG",
76690+ "CAP_MKNOD",
76691+ "CAP_LEASE",
76692+ "CAP_AUDIT_WRITE",
76693+ "CAP_AUDIT_CONTROL",
76694+ "CAP_SETFCAP",
76695+ "CAP_MAC_OVERRIDE",
76696+ "CAP_MAC_ADMIN",
76697+ "CAP_SYSLOG",
76698+ "CAP_WAKE_ALARM",
76699+ "CAP_BLOCK_SUSPEND"
76700+};
76701+
76702+int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
76703+
76704+int gr_is_capable(const int cap)
76705+{
76706+#ifdef CONFIG_GRKERNSEC
76707+ if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
76708+ return 1;
76709+ return 0;
76710+#else
76711+ return 1;
76712+#endif
76713+}
76714+
76715+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
76716+{
76717+#ifdef CONFIG_GRKERNSEC
76718+ if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
76719+ return 1;
76720+ return 0;
76721+#else
76722+ return 1;
76723+#endif
76724+}
76725+
76726+int gr_is_capable_nolog(const int cap)
76727+{
76728+#ifdef CONFIG_GRKERNSEC
76729+ if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
76730+ return 1;
76731+ return 0;
76732+#else
76733+ return 1;
76734+#endif
76735+}
76736+
76737+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
76738+{
76739+#ifdef CONFIG_GRKERNSEC
76740+ if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
76741+ return 1;
76742+ return 0;
76743+#else
76744+ return 1;
76745+#endif
76746+}
76747+
76748+EXPORT_SYMBOL_GPL(gr_is_capable);
76749+EXPORT_SYMBOL_GPL(gr_is_capable_nolog);
76750+EXPORT_SYMBOL_GPL(gr_task_is_capable);
76751+EXPORT_SYMBOL_GPL(gr_task_is_capable_nolog);
76752diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
76753new file mode 100644
76754index 0000000..06cc6ea
76755--- /dev/null
76756+++ b/grsecurity/grsec_fifo.c
76757@@ -0,0 +1,24 @@
76758+#include <linux/kernel.h>
76759+#include <linux/sched.h>
76760+#include <linux/fs.h>
76761+#include <linux/file.h>
76762+#include <linux/grinternal.h>
76763+
76764+int
76765+gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
76766+ const struct dentry *dir, const int flag, const int acc_mode)
76767+{
76768+#ifdef CONFIG_GRKERNSEC_FIFO
76769+ const struct cred *cred = current_cred();
76770+
76771+ if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
76772+ !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
76773+ !uid_eq(dentry->d_inode->i_uid, dir->d_inode->i_uid) &&
76774+ !uid_eq(cred->fsuid, dentry->d_inode->i_uid)) {
76775+ if (!inode_permission(dentry->d_inode, acc_mode))
76776+ 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));
76777+ return -EACCES;
76778+ }
76779+#endif
76780+ return 0;
76781+}
76782diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
76783new file mode 100644
76784index 0000000..8ca18bf
76785--- /dev/null
76786+++ b/grsecurity/grsec_fork.c
76787@@ -0,0 +1,23 @@
76788+#include <linux/kernel.h>
76789+#include <linux/sched.h>
76790+#include <linux/grsecurity.h>
76791+#include <linux/grinternal.h>
76792+#include <linux/errno.h>
76793+
76794+void
76795+gr_log_forkfail(const int retval)
76796+{
76797+#ifdef CONFIG_GRKERNSEC_FORKFAIL
76798+ if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
76799+ switch (retval) {
76800+ case -EAGAIN:
76801+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
76802+ break;
76803+ case -ENOMEM:
76804+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
76805+ break;
76806+ }
76807+ }
76808+#endif
76809+ return;
76810+}
76811diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
76812new file mode 100644
76813index 0000000..b7cb191
76814--- /dev/null
76815+++ b/grsecurity/grsec_init.c
76816@@ -0,0 +1,286 @@
76817+#include <linux/kernel.h>
76818+#include <linux/sched.h>
76819+#include <linux/mm.h>
76820+#include <linux/gracl.h>
76821+#include <linux/slab.h>
76822+#include <linux/vmalloc.h>
76823+#include <linux/percpu.h>
76824+#include <linux/module.h>
76825+
76826+int grsec_enable_ptrace_readexec;
76827+int grsec_enable_setxid;
76828+int grsec_enable_symlinkown;
76829+kgid_t grsec_symlinkown_gid;
76830+int grsec_enable_brute;
76831+int grsec_enable_link;
76832+int grsec_enable_dmesg;
76833+int grsec_enable_harden_ptrace;
76834+int grsec_enable_harden_ipc;
76835+int grsec_enable_fifo;
76836+int grsec_enable_execlog;
76837+int grsec_enable_signal;
76838+int grsec_enable_forkfail;
76839+int grsec_enable_audit_ptrace;
76840+int grsec_enable_time;
76841+int grsec_enable_group;
76842+kgid_t grsec_audit_gid;
76843+int grsec_enable_chdir;
76844+int grsec_enable_mount;
76845+int grsec_enable_rofs;
76846+int grsec_deny_new_usb;
76847+int grsec_enable_chroot_findtask;
76848+int grsec_enable_chroot_mount;
76849+int grsec_enable_chroot_shmat;
76850+int grsec_enable_chroot_fchdir;
76851+int grsec_enable_chroot_double;
76852+int grsec_enable_chroot_pivot;
76853+int grsec_enable_chroot_chdir;
76854+int grsec_enable_chroot_chmod;
76855+int grsec_enable_chroot_mknod;
76856+int grsec_enable_chroot_nice;
76857+int grsec_enable_chroot_execlog;
76858+int grsec_enable_chroot_caps;
76859+int grsec_enable_chroot_sysctl;
76860+int grsec_enable_chroot_unix;
76861+int grsec_enable_tpe;
76862+kgid_t grsec_tpe_gid;
76863+int grsec_enable_blackhole;
76864+#ifdef CONFIG_IPV6_MODULE
76865+EXPORT_SYMBOL_GPL(grsec_enable_blackhole);
76866+#endif
76867+int grsec_lastack_retries;
76868+int grsec_enable_tpe_all;
76869+int grsec_enable_tpe_invert;
76870+int grsec_enable_socket_all;
76871+kgid_t grsec_socket_all_gid;
76872+int grsec_enable_socket_client;
76873+kgid_t grsec_socket_client_gid;
76874+int grsec_enable_socket_server;
76875+kgid_t grsec_socket_server_gid;
76876+int grsec_resource_logging;
76877+int grsec_disable_privio;
76878+int grsec_enable_log_rwxmaps;
76879+int grsec_lock;
76880+
76881+DEFINE_SPINLOCK(grsec_alert_lock);
76882+unsigned long grsec_alert_wtime = 0;
76883+unsigned long grsec_alert_fyet = 0;
76884+
76885+DEFINE_SPINLOCK(grsec_audit_lock);
76886+
76887+DEFINE_RWLOCK(grsec_exec_file_lock);
76888+
76889+char *gr_shared_page[4];
76890+
76891+char *gr_alert_log_fmt;
76892+char *gr_audit_log_fmt;
76893+char *gr_alert_log_buf;
76894+char *gr_audit_log_buf;
76895+
76896+extern struct gr_arg *gr_usermode;
76897+extern unsigned char *gr_system_salt;
76898+extern unsigned char *gr_system_sum;
76899+
76900+void __init
76901+grsecurity_init(void)
76902+{
76903+ int j;
76904+ /* create the per-cpu shared pages */
76905+
76906+#ifdef CONFIG_X86
76907+ memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
76908+#endif
76909+
76910+ for (j = 0; j < 4; j++) {
76911+ gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
76912+ if (gr_shared_page[j] == NULL) {
76913+ panic("Unable to allocate grsecurity shared page");
76914+ return;
76915+ }
76916+ }
76917+
76918+ /* allocate log buffers */
76919+ gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
76920+ if (!gr_alert_log_fmt) {
76921+ panic("Unable to allocate grsecurity alert log format buffer");
76922+ return;
76923+ }
76924+ gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
76925+ if (!gr_audit_log_fmt) {
76926+ panic("Unable to allocate grsecurity audit log format buffer");
76927+ return;
76928+ }
76929+ gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
76930+ if (!gr_alert_log_buf) {
76931+ panic("Unable to allocate grsecurity alert log buffer");
76932+ return;
76933+ }
76934+ gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
76935+ if (!gr_audit_log_buf) {
76936+ panic("Unable to allocate grsecurity audit log buffer");
76937+ return;
76938+ }
76939+
76940+ /* allocate memory for authentication structure */
76941+ gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
76942+ gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
76943+ gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
76944+
76945+ if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
76946+ panic("Unable to allocate grsecurity authentication structure");
76947+ return;
76948+ }
76949+
76950+#ifdef CONFIG_GRKERNSEC_IO
76951+#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
76952+ grsec_disable_privio = 1;
76953+#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
76954+ grsec_disable_privio = 1;
76955+#else
76956+ grsec_disable_privio = 0;
76957+#endif
76958+#endif
76959+
76960+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
76961+ /* for backward compatibility, tpe_invert always defaults to on if
76962+ enabled in the kernel
76963+ */
76964+ grsec_enable_tpe_invert = 1;
76965+#endif
76966+
76967+#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
76968+#ifndef CONFIG_GRKERNSEC_SYSCTL
76969+ grsec_lock = 1;
76970+#endif
76971+
76972+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
76973+ grsec_enable_log_rwxmaps = 1;
76974+#endif
76975+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
76976+ grsec_enable_group = 1;
76977+ grsec_audit_gid = KGIDT_INIT(CONFIG_GRKERNSEC_AUDIT_GID);
76978+#endif
76979+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
76980+ grsec_enable_ptrace_readexec = 1;
76981+#endif
76982+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
76983+ grsec_enable_chdir = 1;
76984+#endif
76985+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
76986+ grsec_enable_harden_ptrace = 1;
76987+#endif
76988+#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
76989+ grsec_enable_harden_ipc = 1;
76990+#endif
76991+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
76992+ grsec_enable_mount = 1;
76993+#endif
76994+#ifdef CONFIG_GRKERNSEC_LINK
76995+ grsec_enable_link = 1;
76996+#endif
76997+#ifdef CONFIG_GRKERNSEC_BRUTE
76998+ grsec_enable_brute = 1;
76999+#endif
77000+#ifdef CONFIG_GRKERNSEC_DMESG
77001+ grsec_enable_dmesg = 1;
77002+#endif
77003+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77004+ grsec_enable_blackhole = 1;
77005+ grsec_lastack_retries = 4;
77006+#endif
77007+#ifdef CONFIG_GRKERNSEC_FIFO
77008+ grsec_enable_fifo = 1;
77009+#endif
77010+#ifdef CONFIG_GRKERNSEC_EXECLOG
77011+ grsec_enable_execlog = 1;
77012+#endif
77013+#ifdef CONFIG_GRKERNSEC_SETXID
77014+ grsec_enable_setxid = 1;
77015+#endif
77016+#ifdef CONFIG_GRKERNSEC_SIGNAL
77017+ grsec_enable_signal = 1;
77018+#endif
77019+#ifdef CONFIG_GRKERNSEC_FORKFAIL
77020+ grsec_enable_forkfail = 1;
77021+#endif
77022+#ifdef CONFIG_GRKERNSEC_TIME
77023+ grsec_enable_time = 1;
77024+#endif
77025+#ifdef CONFIG_GRKERNSEC_RESLOG
77026+ grsec_resource_logging = 1;
77027+#endif
77028+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
77029+ grsec_enable_chroot_findtask = 1;
77030+#endif
77031+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
77032+ grsec_enable_chroot_unix = 1;
77033+#endif
77034+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
77035+ grsec_enable_chroot_mount = 1;
77036+#endif
77037+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
77038+ grsec_enable_chroot_fchdir = 1;
77039+#endif
77040+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
77041+ grsec_enable_chroot_shmat = 1;
77042+#endif
77043+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
77044+ grsec_enable_audit_ptrace = 1;
77045+#endif
77046+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
77047+ grsec_enable_chroot_double = 1;
77048+#endif
77049+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
77050+ grsec_enable_chroot_pivot = 1;
77051+#endif
77052+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
77053+ grsec_enable_chroot_chdir = 1;
77054+#endif
77055+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
77056+ grsec_enable_chroot_chmod = 1;
77057+#endif
77058+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
77059+ grsec_enable_chroot_mknod = 1;
77060+#endif
77061+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
77062+ grsec_enable_chroot_nice = 1;
77063+#endif
77064+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
77065+ grsec_enable_chroot_execlog = 1;
77066+#endif
77067+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
77068+ grsec_enable_chroot_caps = 1;
77069+#endif
77070+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
77071+ grsec_enable_chroot_sysctl = 1;
77072+#endif
77073+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
77074+ grsec_enable_symlinkown = 1;
77075+ grsec_symlinkown_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SYMLINKOWN_GID);
77076+#endif
77077+#ifdef CONFIG_GRKERNSEC_TPE
77078+ grsec_enable_tpe = 1;
77079+ grsec_tpe_gid = KGIDT_INIT(CONFIG_GRKERNSEC_TPE_GID);
77080+#ifdef CONFIG_GRKERNSEC_TPE_ALL
77081+ grsec_enable_tpe_all = 1;
77082+#endif
77083+#endif
77084+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
77085+ grsec_enable_socket_all = 1;
77086+ grsec_socket_all_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_ALL_GID);
77087+#endif
77088+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
77089+ grsec_enable_socket_client = 1;
77090+ grsec_socket_client_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_CLIENT_GID);
77091+#endif
77092+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
77093+ grsec_enable_socket_server = 1;
77094+ grsec_socket_server_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_SERVER_GID);
77095+#endif
77096+#endif
77097+#ifdef CONFIG_GRKERNSEC_DENYUSB_FORCE
77098+ grsec_deny_new_usb = 1;
77099+#endif
77100+
77101+ return;
77102+}
77103diff --git a/grsecurity/grsec_ipc.c b/grsecurity/grsec_ipc.c
77104new file mode 100644
77105index 0000000..1773300
77106--- /dev/null
77107+++ b/grsecurity/grsec_ipc.c
77108@@ -0,0 +1,48 @@
77109+#include <linux/kernel.h>
77110+#include <linux/mm.h>
77111+#include <linux/sched.h>
77112+#include <linux/file.h>
77113+#include <linux/ipc.h>
77114+#include <linux/ipc_namespace.h>
77115+#include <linux/grsecurity.h>
77116+#include <linux/grinternal.h>
77117+
77118+int
77119+gr_ipc_permitted(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, int requested_mode, int granted_mode)
77120+{
77121+#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
77122+ int write;
77123+ int orig_granted_mode;
77124+ kuid_t euid;
77125+ kgid_t egid;
77126+
77127+ if (!grsec_enable_harden_ipc)
77128+ return 1;
77129+
77130+ euid = current_euid();
77131+ egid = current_egid();
77132+
77133+ write = requested_mode & 00002;
77134+ orig_granted_mode = ipcp->mode;
77135+
77136+ if (uid_eq(euid, ipcp->cuid) || uid_eq(euid, ipcp->uid))
77137+ orig_granted_mode >>= 6;
77138+ else {
77139+ /* if likely wrong permissions, lock to user */
77140+ if (orig_granted_mode & 0007)
77141+ orig_granted_mode = 0;
77142+ /* otherwise do a egid-only check */
77143+ else if (gid_eq(egid, ipcp->cgid) || gid_eq(egid, ipcp->gid))
77144+ orig_granted_mode >>= 3;
77145+ /* otherwise, no access */
77146+ else
77147+ orig_granted_mode = 0;
77148+ }
77149+ if (!(requested_mode & ~granted_mode & 0007) && (requested_mode & ~orig_granted_mode & 0007) &&
77150+ !ns_capable_nolog(ns->user_ns, CAP_IPC_OWNER)) {
77151+ gr_log_str_int(GR_DONT_AUDIT, GR_IPC_DENIED_MSG, write ? "write" : "read", GR_GLOBAL_UID(ipcp->cuid));
77152+ return 0;
77153+ }
77154+#endif
77155+ return 1;
77156+}
77157diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
77158new file mode 100644
77159index 0000000..5e05e20
77160--- /dev/null
77161+++ b/grsecurity/grsec_link.c
77162@@ -0,0 +1,58 @@
77163+#include <linux/kernel.h>
77164+#include <linux/sched.h>
77165+#include <linux/fs.h>
77166+#include <linux/file.h>
77167+#include <linux/grinternal.h>
77168+
77169+int gr_handle_symlink_owner(const struct path *link, const struct inode *target)
77170+{
77171+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
77172+ const struct inode *link_inode = link->dentry->d_inode;
77173+
77174+ if (grsec_enable_symlinkown && in_group_p(grsec_symlinkown_gid) &&
77175+ /* ignore root-owned links, e.g. /proc/self */
77176+ gr_is_global_nonroot(link_inode->i_uid) && target &&
77177+ !uid_eq(link_inode->i_uid, target->i_uid)) {
77178+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINKOWNER_MSG, link->dentry, link->mnt, link_inode->i_uid, target->i_uid);
77179+ return 1;
77180+ }
77181+#endif
77182+ return 0;
77183+}
77184+
77185+int
77186+gr_handle_follow_link(const struct inode *parent,
77187+ const struct inode *inode,
77188+ const struct dentry *dentry, const struct vfsmount *mnt)
77189+{
77190+#ifdef CONFIG_GRKERNSEC_LINK
77191+ const struct cred *cred = current_cred();
77192+
77193+ if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
77194+ (parent->i_mode & S_ISVTX) && !uid_eq(parent->i_uid, inode->i_uid) &&
77195+ (parent->i_mode & S_IWOTH) && !uid_eq(cred->fsuid, inode->i_uid)) {
77196+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
77197+ return -EACCES;
77198+ }
77199+#endif
77200+ return 0;
77201+}
77202+
77203+int
77204+gr_handle_hardlink(const struct dentry *dentry,
77205+ const struct vfsmount *mnt,
77206+ struct inode *inode, const int mode, const struct filename *to)
77207+{
77208+#ifdef CONFIG_GRKERNSEC_LINK
77209+ const struct cred *cred = current_cred();
77210+
77211+ if (grsec_enable_link && !uid_eq(cred->fsuid, inode->i_uid) &&
77212+ (!S_ISREG(mode) || is_privileged_binary(dentry) ||
77213+ (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
77214+ !capable(CAP_FOWNER) && gr_is_global_nonroot(cred->uid)) {
77215+ gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to->name);
77216+ return -EPERM;
77217+ }
77218+#endif
77219+ return 0;
77220+}
77221diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
77222new file mode 100644
77223index 0000000..dbe0a6b
77224--- /dev/null
77225+++ b/grsecurity/grsec_log.c
77226@@ -0,0 +1,341 @@
77227+#include <linux/kernel.h>
77228+#include <linux/sched.h>
77229+#include <linux/file.h>
77230+#include <linux/tty.h>
77231+#include <linux/fs.h>
77232+#include <linux/mm.h>
77233+#include <linux/grinternal.h>
77234+
77235+#ifdef CONFIG_TREE_PREEMPT_RCU
77236+#define DISABLE_PREEMPT() preempt_disable()
77237+#define ENABLE_PREEMPT() preempt_enable()
77238+#else
77239+#define DISABLE_PREEMPT()
77240+#define ENABLE_PREEMPT()
77241+#endif
77242+
77243+#define BEGIN_LOCKS(x) \
77244+ DISABLE_PREEMPT(); \
77245+ rcu_read_lock(); \
77246+ read_lock(&tasklist_lock); \
77247+ read_lock(&grsec_exec_file_lock); \
77248+ if (x != GR_DO_AUDIT) \
77249+ spin_lock(&grsec_alert_lock); \
77250+ else \
77251+ spin_lock(&grsec_audit_lock)
77252+
77253+#define END_LOCKS(x) \
77254+ if (x != GR_DO_AUDIT) \
77255+ spin_unlock(&grsec_alert_lock); \
77256+ else \
77257+ spin_unlock(&grsec_audit_lock); \
77258+ read_unlock(&grsec_exec_file_lock); \
77259+ read_unlock(&tasklist_lock); \
77260+ rcu_read_unlock(); \
77261+ ENABLE_PREEMPT(); \
77262+ if (x == GR_DONT_AUDIT) \
77263+ gr_handle_alertkill(current)
77264+
77265+enum {
77266+ FLOODING,
77267+ NO_FLOODING
77268+};
77269+
77270+extern char *gr_alert_log_fmt;
77271+extern char *gr_audit_log_fmt;
77272+extern char *gr_alert_log_buf;
77273+extern char *gr_audit_log_buf;
77274+
77275+static int gr_log_start(int audit)
77276+{
77277+ char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
77278+ char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
77279+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
77280+#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
77281+ unsigned long curr_secs = get_seconds();
77282+
77283+ if (audit == GR_DO_AUDIT)
77284+ goto set_fmt;
77285+
77286+ if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
77287+ grsec_alert_wtime = curr_secs;
77288+ grsec_alert_fyet = 0;
77289+ } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
77290+ && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
77291+ grsec_alert_fyet++;
77292+ } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
77293+ grsec_alert_wtime = curr_secs;
77294+ grsec_alert_fyet++;
77295+ printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
77296+ return FLOODING;
77297+ }
77298+ else return FLOODING;
77299+
77300+set_fmt:
77301+#endif
77302+ memset(buf, 0, PAGE_SIZE);
77303+ if (current->signal->curr_ip && gr_acl_is_enabled()) {
77304+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
77305+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
77306+ } else if (current->signal->curr_ip) {
77307+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
77308+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
77309+ } else if (gr_acl_is_enabled()) {
77310+ sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
77311+ snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
77312+ } else {
77313+ sprintf(fmt, "%s%s", loglevel, "grsec: ");
77314+ strcpy(buf, fmt);
77315+ }
77316+
77317+ return NO_FLOODING;
77318+}
77319+
77320+static void gr_log_middle(int audit, const char *msg, va_list ap)
77321+ __attribute__ ((format (printf, 2, 0)));
77322+
77323+static void gr_log_middle(int audit, const char *msg, va_list ap)
77324+{
77325+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
77326+ unsigned int len = strlen(buf);
77327+
77328+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
77329+
77330+ return;
77331+}
77332+
77333+static void gr_log_middle_varargs(int audit, const char *msg, ...)
77334+ __attribute__ ((format (printf, 2, 3)));
77335+
77336+static void gr_log_middle_varargs(int audit, const char *msg, ...)
77337+{
77338+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
77339+ unsigned int len = strlen(buf);
77340+ va_list ap;
77341+
77342+ va_start(ap, msg);
77343+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
77344+ va_end(ap);
77345+
77346+ return;
77347+}
77348+
77349+static void gr_log_end(int audit, int append_default)
77350+{
77351+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
77352+ if (append_default) {
77353+ struct task_struct *task = current;
77354+ struct task_struct *parent = task->real_parent;
77355+ const struct cred *cred = __task_cred(task);
77356+ const struct cred *pcred = __task_cred(parent);
77357+ unsigned int len = strlen(buf);
77358+
77359+ 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));
77360+ }
77361+
77362+ printk("%s\n", buf);
77363+
77364+ return;
77365+}
77366+
77367+void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
77368+{
77369+ int logtype;
77370+ char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
77371+ char *str1 = NULL, *str2 = NULL, *str3 = NULL;
77372+ void *voidptr = NULL;
77373+ int num1 = 0, num2 = 0;
77374+ unsigned long ulong1 = 0, ulong2 = 0;
77375+ struct dentry *dentry = NULL;
77376+ struct vfsmount *mnt = NULL;
77377+ struct file *file = NULL;
77378+ struct task_struct *task = NULL;
77379+ struct vm_area_struct *vma = NULL;
77380+ const struct cred *cred, *pcred;
77381+ va_list ap;
77382+
77383+ BEGIN_LOCKS(audit);
77384+ logtype = gr_log_start(audit);
77385+ if (logtype == FLOODING) {
77386+ END_LOCKS(audit);
77387+ return;
77388+ }
77389+ va_start(ap, argtypes);
77390+ switch (argtypes) {
77391+ case GR_TTYSNIFF:
77392+ task = va_arg(ap, struct task_struct *);
77393+ 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));
77394+ break;
77395+ case GR_SYSCTL_HIDDEN:
77396+ str1 = va_arg(ap, char *);
77397+ gr_log_middle_varargs(audit, msg, result, str1);
77398+ break;
77399+ case GR_RBAC:
77400+ dentry = va_arg(ap, struct dentry *);
77401+ mnt = va_arg(ap, struct vfsmount *);
77402+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
77403+ break;
77404+ case GR_RBAC_STR:
77405+ dentry = va_arg(ap, struct dentry *);
77406+ mnt = va_arg(ap, struct vfsmount *);
77407+ str1 = va_arg(ap, char *);
77408+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
77409+ break;
77410+ case GR_STR_RBAC:
77411+ str1 = va_arg(ap, char *);
77412+ dentry = va_arg(ap, struct dentry *);
77413+ mnt = va_arg(ap, struct vfsmount *);
77414+ gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
77415+ break;
77416+ case GR_RBAC_MODE2:
77417+ dentry = va_arg(ap, struct dentry *);
77418+ mnt = va_arg(ap, struct vfsmount *);
77419+ str1 = va_arg(ap, char *);
77420+ str2 = va_arg(ap, char *);
77421+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
77422+ break;
77423+ case GR_RBAC_MODE3:
77424+ dentry = va_arg(ap, struct dentry *);
77425+ mnt = va_arg(ap, struct vfsmount *);
77426+ str1 = va_arg(ap, char *);
77427+ str2 = va_arg(ap, char *);
77428+ str3 = va_arg(ap, char *);
77429+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
77430+ break;
77431+ case GR_FILENAME:
77432+ dentry = va_arg(ap, struct dentry *);
77433+ mnt = va_arg(ap, struct vfsmount *);
77434+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
77435+ break;
77436+ case GR_STR_FILENAME:
77437+ str1 = va_arg(ap, char *);
77438+ dentry = va_arg(ap, struct dentry *);
77439+ mnt = va_arg(ap, struct vfsmount *);
77440+ gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
77441+ break;
77442+ case GR_FILENAME_STR:
77443+ dentry = va_arg(ap, struct dentry *);
77444+ mnt = va_arg(ap, struct vfsmount *);
77445+ str1 = va_arg(ap, char *);
77446+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
77447+ break;
77448+ case GR_FILENAME_TWO_INT:
77449+ dentry = va_arg(ap, struct dentry *);
77450+ mnt = va_arg(ap, struct vfsmount *);
77451+ num1 = va_arg(ap, int);
77452+ num2 = va_arg(ap, int);
77453+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
77454+ break;
77455+ case GR_FILENAME_TWO_INT_STR:
77456+ dentry = va_arg(ap, struct dentry *);
77457+ mnt = va_arg(ap, struct vfsmount *);
77458+ num1 = va_arg(ap, int);
77459+ num2 = va_arg(ap, int);
77460+ str1 = va_arg(ap, char *);
77461+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
77462+ break;
77463+ case GR_TEXTREL:
77464+ file = va_arg(ap, struct file *);
77465+ ulong1 = va_arg(ap, unsigned long);
77466+ ulong2 = va_arg(ap, unsigned long);
77467+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
77468+ break;
77469+ case GR_PTRACE:
77470+ task = va_arg(ap, struct task_struct *);
77471+ 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));
77472+ break;
77473+ case GR_RESOURCE:
77474+ task = va_arg(ap, struct task_struct *);
77475+ cred = __task_cred(task);
77476+ pcred = __task_cred(task->real_parent);
77477+ ulong1 = va_arg(ap, unsigned long);
77478+ str1 = va_arg(ap, char *);
77479+ ulong2 = va_arg(ap, unsigned long);
77480+ 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));
77481+ break;
77482+ case GR_CAP:
77483+ task = va_arg(ap, struct task_struct *);
77484+ cred = __task_cred(task);
77485+ pcred = __task_cred(task->real_parent);
77486+ str1 = va_arg(ap, char *);
77487+ 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));
77488+ break;
77489+ case GR_SIG:
77490+ str1 = va_arg(ap, char *);
77491+ voidptr = va_arg(ap, void *);
77492+ gr_log_middle_varargs(audit, msg, str1, voidptr);
77493+ break;
77494+ case GR_SIG2:
77495+ task = va_arg(ap, struct task_struct *);
77496+ cred = __task_cred(task);
77497+ pcred = __task_cred(task->real_parent);
77498+ num1 = va_arg(ap, int);
77499+ 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));
77500+ break;
77501+ case GR_CRASH1:
77502+ task = va_arg(ap, struct task_struct *);
77503+ cred = __task_cred(task);
77504+ pcred = __task_cred(task->real_parent);
77505+ ulong1 = va_arg(ap, unsigned long);
77506+ 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);
77507+ break;
77508+ case GR_CRASH2:
77509+ task = va_arg(ap, struct task_struct *);
77510+ cred = __task_cred(task);
77511+ pcred = __task_cred(task->real_parent);
77512+ ulong1 = va_arg(ap, unsigned long);
77513+ 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);
77514+ break;
77515+ case GR_RWXMAP:
77516+ file = va_arg(ap, struct file *);
77517+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
77518+ break;
77519+ case GR_RWXMAPVMA:
77520+ vma = va_arg(ap, struct vm_area_struct *);
77521+ if (vma->vm_file)
77522+ str1 = gr_to_filename(vma->vm_file->f_path.dentry, vma->vm_file->f_path.mnt);
77523+ else if (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP))
77524+ str1 = "<stack>";
77525+ else if (vma->vm_start <= current->mm->brk &&
77526+ vma->vm_end >= current->mm->start_brk)
77527+ str1 = "<heap>";
77528+ else
77529+ str1 = "<anonymous mapping>";
77530+ gr_log_middle_varargs(audit, msg, str1);
77531+ break;
77532+ case GR_PSACCT:
77533+ {
77534+ unsigned int wday, cday;
77535+ __u8 whr, chr;
77536+ __u8 wmin, cmin;
77537+ __u8 wsec, csec;
77538+ char cur_tty[64] = { 0 };
77539+ char parent_tty[64] = { 0 };
77540+
77541+ task = va_arg(ap, struct task_struct *);
77542+ wday = va_arg(ap, unsigned int);
77543+ cday = va_arg(ap, unsigned int);
77544+ whr = va_arg(ap, int);
77545+ chr = va_arg(ap, int);
77546+ wmin = va_arg(ap, int);
77547+ cmin = va_arg(ap, int);
77548+ wsec = va_arg(ap, int);
77549+ csec = va_arg(ap, int);
77550+ ulong1 = va_arg(ap, unsigned long);
77551+ cred = __task_cred(task);
77552+ pcred = __task_cred(task->real_parent);
77553+
77554+ 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));
77555+ }
77556+ break;
77557+ default:
77558+ gr_log_middle(audit, msg, ap);
77559+ }
77560+ va_end(ap);
77561+ // these don't need DEFAULTSECARGS printed on the end
77562+ if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
77563+ gr_log_end(audit, 0);
77564+ else
77565+ gr_log_end(audit, 1);
77566+ END_LOCKS(audit);
77567+}
77568diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
77569new file mode 100644
77570index 0000000..0e39d8c
77571--- /dev/null
77572+++ b/grsecurity/grsec_mem.c
77573@@ -0,0 +1,48 @@
77574+#include <linux/kernel.h>
77575+#include <linux/sched.h>
77576+#include <linux/mm.h>
77577+#include <linux/mman.h>
77578+#include <linux/module.h>
77579+#include <linux/grinternal.h>
77580+
77581+void gr_handle_msr_write(void)
77582+{
77583+ gr_log_noargs(GR_DONT_AUDIT, GR_MSRWRITE_MSG);
77584+ return;
77585+}
77586+EXPORT_SYMBOL_GPL(gr_handle_msr_write);
77587+
77588+void
77589+gr_handle_ioperm(void)
77590+{
77591+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
77592+ return;
77593+}
77594+
77595+void
77596+gr_handle_iopl(void)
77597+{
77598+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
77599+ return;
77600+}
77601+
77602+void
77603+gr_handle_mem_readwrite(u64 from, u64 to)
77604+{
77605+ gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
77606+ return;
77607+}
77608+
77609+void
77610+gr_handle_vm86(void)
77611+{
77612+ gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
77613+ return;
77614+}
77615+
77616+void
77617+gr_log_badprocpid(const char *entry)
77618+{
77619+ gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
77620+ return;
77621+}
77622diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
77623new file mode 100644
77624index 0000000..6f9eb73
77625--- /dev/null
77626+++ b/grsecurity/grsec_mount.c
77627@@ -0,0 +1,65 @@
77628+#include <linux/kernel.h>
77629+#include <linux/sched.h>
77630+#include <linux/mount.h>
77631+#include <linux/major.h>
77632+#include <linux/grsecurity.h>
77633+#include <linux/grinternal.h>
77634+
77635+void
77636+gr_log_remount(const char *devname, const int retval)
77637+{
77638+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
77639+ if (grsec_enable_mount && (retval >= 0))
77640+ gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
77641+#endif
77642+ return;
77643+}
77644+
77645+void
77646+gr_log_unmount(const char *devname, const int retval)
77647+{
77648+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
77649+ if (grsec_enable_mount && (retval >= 0))
77650+ gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
77651+#endif
77652+ return;
77653+}
77654+
77655+void
77656+gr_log_mount(const char *from, struct path *to, const int retval)
77657+{
77658+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
77659+ if (grsec_enable_mount && (retval >= 0))
77660+ gr_log_str_fs(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to->dentry, to->mnt);
77661+#endif
77662+ return;
77663+}
77664+
77665+int
77666+gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
77667+{
77668+#ifdef CONFIG_GRKERNSEC_ROFS
77669+ if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
77670+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
77671+ return -EPERM;
77672+ } else
77673+ return 0;
77674+#endif
77675+ return 0;
77676+}
77677+
77678+int
77679+gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
77680+{
77681+#ifdef CONFIG_GRKERNSEC_ROFS
77682+ struct inode *inode = dentry->d_inode;
77683+
77684+ if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
77685+ inode && (S_ISBLK(inode->i_mode) || (S_ISCHR(inode->i_mode) && imajor(inode) == RAW_MAJOR))) {
77686+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
77687+ return -EPERM;
77688+ } else
77689+ return 0;
77690+#endif
77691+ return 0;
77692+}
77693diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
77694new file mode 100644
77695index 0000000..6ee9d50
77696--- /dev/null
77697+++ b/grsecurity/grsec_pax.c
77698@@ -0,0 +1,45 @@
77699+#include <linux/kernel.h>
77700+#include <linux/sched.h>
77701+#include <linux/mm.h>
77702+#include <linux/file.h>
77703+#include <linux/grinternal.h>
77704+#include <linux/grsecurity.h>
77705+
77706+void
77707+gr_log_textrel(struct vm_area_struct * vma)
77708+{
77709+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
77710+ if (grsec_enable_log_rwxmaps)
77711+ gr_log_textrel_ulong_ulong(GR_DONT_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
77712+#endif
77713+ return;
77714+}
77715+
77716+void gr_log_ptgnustack(struct file *file)
77717+{
77718+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
77719+ if (grsec_enable_log_rwxmaps)
77720+ gr_log_rwxmap(GR_DONT_AUDIT, GR_PTGNUSTACK_MSG, file);
77721+#endif
77722+ return;
77723+}
77724+
77725+void
77726+gr_log_rwxmmap(struct file *file)
77727+{
77728+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
77729+ if (grsec_enable_log_rwxmaps)
77730+ gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
77731+#endif
77732+ return;
77733+}
77734+
77735+void
77736+gr_log_rwxmprotect(struct vm_area_struct *vma)
77737+{
77738+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
77739+ if (grsec_enable_log_rwxmaps)
77740+ gr_log_rwxmap_vma(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, vma);
77741+#endif
77742+ return;
77743+}
77744diff --git a/grsecurity/grsec_proc.c b/grsecurity/grsec_proc.c
77745new file mode 100644
77746index 0000000..2005a3a
77747--- /dev/null
77748+++ b/grsecurity/grsec_proc.c
77749@@ -0,0 +1,20 @@
77750+#include <linux/kernel.h>
77751+#include <linux/sched.h>
77752+#include <linux/grsecurity.h>
77753+#include <linux/grinternal.h>
77754+
77755+int gr_proc_is_restricted(void)
77756+{
77757+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
77758+ const struct cred *cred = current_cred();
77759+#endif
77760+
77761+#ifdef CONFIG_GRKERNSEC_PROC_USER
77762+ if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID))
77763+ return -EACCES;
77764+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
77765+ if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID) && !in_group_p(grsec_proc_gid))
77766+ return -EACCES;
77767+#endif
77768+ return 0;
77769+}
77770diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
77771new file mode 100644
77772index 0000000..f7f29aa
77773--- /dev/null
77774+++ b/grsecurity/grsec_ptrace.c
77775@@ -0,0 +1,30 @@
77776+#include <linux/kernel.h>
77777+#include <linux/sched.h>
77778+#include <linux/grinternal.h>
77779+#include <linux/security.h>
77780+
77781+void
77782+gr_audit_ptrace(struct task_struct *task)
77783+{
77784+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
77785+ if (grsec_enable_audit_ptrace)
77786+ gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
77787+#endif
77788+ return;
77789+}
77790+
77791+int
77792+gr_ptrace_readexec(struct file *file, int unsafe_flags)
77793+{
77794+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
77795+ const struct dentry *dentry = file->f_path.dentry;
77796+ const struct vfsmount *mnt = file->f_path.mnt;
77797+
77798+ if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
77799+ (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
77800+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
77801+ return -EACCES;
77802+ }
77803+#endif
77804+ return 0;
77805+}
77806diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
77807new file mode 100644
77808index 0000000..3860c7e
77809--- /dev/null
77810+++ b/grsecurity/grsec_sig.c
77811@@ -0,0 +1,236 @@
77812+#include <linux/kernel.h>
77813+#include <linux/sched.h>
77814+#include <linux/fs.h>
77815+#include <linux/delay.h>
77816+#include <linux/grsecurity.h>
77817+#include <linux/grinternal.h>
77818+#include <linux/hardirq.h>
77819+
77820+char *signames[] = {
77821+ [SIGSEGV] = "Segmentation fault",
77822+ [SIGILL] = "Illegal instruction",
77823+ [SIGABRT] = "Abort",
77824+ [SIGBUS] = "Invalid alignment/Bus error"
77825+};
77826+
77827+void
77828+gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
77829+{
77830+#ifdef CONFIG_GRKERNSEC_SIGNAL
77831+ if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
77832+ (sig == SIGABRT) || (sig == SIGBUS))) {
77833+ if (task_pid_nr(t) == task_pid_nr(current)) {
77834+ gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
77835+ } else {
77836+ gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
77837+ }
77838+ }
77839+#endif
77840+ return;
77841+}
77842+
77843+int
77844+gr_handle_signal(const struct task_struct *p, const int sig)
77845+{
77846+#ifdef CONFIG_GRKERNSEC
77847+ /* ignore the 0 signal for protected task checks */
77848+ if (task_pid_nr(current) > 1 && sig && gr_check_protected_task(p)) {
77849+ gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
77850+ return -EPERM;
77851+ } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
77852+ return -EPERM;
77853+ }
77854+#endif
77855+ return 0;
77856+}
77857+
77858+#ifdef CONFIG_GRKERNSEC
77859+extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
77860+
77861+int gr_fake_force_sig(int sig, struct task_struct *t)
77862+{
77863+ unsigned long int flags;
77864+ int ret, blocked, ignored;
77865+ struct k_sigaction *action;
77866+
77867+ spin_lock_irqsave(&t->sighand->siglock, flags);
77868+ action = &t->sighand->action[sig-1];
77869+ ignored = action->sa.sa_handler == SIG_IGN;
77870+ blocked = sigismember(&t->blocked, sig);
77871+ if (blocked || ignored) {
77872+ action->sa.sa_handler = SIG_DFL;
77873+ if (blocked) {
77874+ sigdelset(&t->blocked, sig);
77875+ recalc_sigpending_and_wake(t);
77876+ }
77877+ }
77878+ if (action->sa.sa_handler == SIG_DFL)
77879+ t->signal->flags &= ~SIGNAL_UNKILLABLE;
77880+ ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
77881+
77882+ spin_unlock_irqrestore(&t->sighand->siglock, flags);
77883+
77884+ return ret;
77885+}
77886+#endif
77887+
77888+#define GR_USER_BAN_TIME (15 * 60)
77889+#define GR_DAEMON_BRUTE_TIME (30 * 60)
77890+
77891+void gr_handle_brute_attach(int dumpable)
77892+{
77893+#ifdef CONFIG_GRKERNSEC_BRUTE
77894+ struct task_struct *p = current;
77895+ kuid_t uid = GLOBAL_ROOT_UID;
77896+ int daemon = 0;
77897+
77898+ if (!grsec_enable_brute)
77899+ return;
77900+
77901+ rcu_read_lock();
77902+ read_lock(&tasklist_lock);
77903+ read_lock(&grsec_exec_file_lock);
77904+ if (p->real_parent && gr_is_same_file(p->real_parent->exec_file, p->exec_file)) {
77905+ p->real_parent->brute_expires = get_seconds() + GR_DAEMON_BRUTE_TIME;
77906+ p->real_parent->brute = 1;
77907+ daemon = 1;
77908+ } else {
77909+ const struct cred *cred = __task_cred(p), *cred2;
77910+ struct task_struct *tsk, *tsk2;
77911+
77912+ if (dumpable != SUID_DUMP_USER && gr_is_global_nonroot(cred->uid)) {
77913+ struct user_struct *user;
77914+
77915+ uid = cred->uid;
77916+
77917+ /* this is put upon execution past expiration */
77918+ user = find_user(uid);
77919+ if (user == NULL)
77920+ goto unlock;
77921+ user->suid_banned = 1;
77922+ user->suid_ban_expires = get_seconds() + GR_USER_BAN_TIME;
77923+ if (user->suid_ban_expires == ~0UL)
77924+ user->suid_ban_expires--;
77925+
77926+ /* only kill other threads of the same binary, from the same user */
77927+ do_each_thread(tsk2, tsk) {
77928+ cred2 = __task_cred(tsk);
77929+ if (tsk != p && uid_eq(cred2->uid, uid) && gr_is_same_file(tsk->exec_file, p->exec_file))
77930+ gr_fake_force_sig(SIGKILL, tsk);
77931+ } while_each_thread(tsk2, tsk);
77932+ }
77933+ }
77934+unlock:
77935+ read_unlock(&grsec_exec_file_lock);
77936+ read_unlock(&tasklist_lock);
77937+ rcu_read_unlock();
77938+
77939+ if (gr_is_global_nonroot(uid))
77940+ 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);
77941+ else if (daemon)
77942+ gr_log_noargs(GR_DONT_AUDIT, GR_BRUTE_DAEMON_MSG);
77943+
77944+#endif
77945+ return;
77946+}
77947+
77948+void gr_handle_brute_check(void)
77949+{
77950+#ifdef CONFIG_GRKERNSEC_BRUTE
77951+ struct task_struct *p = current;
77952+
77953+ if (unlikely(p->brute)) {
77954+ if (!grsec_enable_brute)
77955+ p->brute = 0;
77956+ else if (time_before(get_seconds(), p->brute_expires))
77957+ msleep(30 * 1000);
77958+ }
77959+#endif
77960+ return;
77961+}
77962+
77963+void gr_handle_kernel_exploit(void)
77964+{
77965+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
77966+ const struct cred *cred;
77967+ struct task_struct *tsk, *tsk2;
77968+ struct user_struct *user;
77969+ kuid_t uid;
77970+
77971+ if (in_irq() || in_serving_softirq() || in_nmi())
77972+ panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
77973+
77974+ uid = current_uid();
77975+
77976+ if (gr_is_global_root(uid))
77977+ panic("grsec: halting the system due to suspicious kernel crash caused by root");
77978+ else {
77979+ /* kill all the processes of this user, hold a reference
77980+ to their creds struct, and prevent them from creating
77981+ another process until system reset
77982+ */
77983+ printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n",
77984+ GR_GLOBAL_UID(uid));
77985+ /* we intentionally leak this ref */
77986+ user = get_uid(current->cred->user);
77987+ if (user)
77988+ user->kernel_banned = 1;
77989+
77990+ /* kill all processes of this user */
77991+ read_lock(&tasklist_lock);
77992+ do_each_thread(tsk2, tsk) {
77993+ cred = __task_cred(tsk);
77994+ if (uid_eq(cred->uid, uid))
77995+ gr_fake_force_sig(SIGKILL, tsk);
77996+ } while_each_thread(tsk2, tsk);
77997+ read_unlock(&tasklist_lock);
77998+ }
77999+#endif
78000+}
78001+
78002+#ifdef CONFIG_GRKERNSEC_BRUTE
78003+static bool suid_ban_expired(struct user_struct *user)
78004+{
78005+ if (user->suid_ban_expires != ~0UL && time_after_eq(get_seconds(), user->suid_ban_expires)) {
78006+ user->suid_banned = 0;
78007+ user->suid_ban_expires = 0;
78008+ free_uid(user);
78009+ return true;
78010+ }
78011+
78012+ return false;
78013+}
78014+#endif
78015+
78016+int gr_process_kernel_exec_ban(void)
78017+{
78018+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
78019+ if (unlikely(current->cred->user->kernel_banned))
78020+ return -EPERM;
78021+#endif
78022+ return 0;
78023+}
78024+
78025+int gr_process_kernel_setuid_ban(struct user_struct *user)
78026+{
78027+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
78028+ if (unlikely(user->kernel_banned))
78029+ gr_fake_force_sig(SIGKILL, current);
78030+#endif
78031+ return 0;
78032+}
78033+
78034+int gr_process_suid_exec_ban(const struct linux_binprm *bprm)
78035+{
78036+#ifdef CONFIG_GRKERNSEC_BRUTE
78037+ struct user_struct *user = current->cred->user;
78038+ if (unlikely(user->suid_banned)) {
78039+ if (suid_ban_expired(user))
78040+ return 0;
78041+ /* disallow execution of suid binaries only */
78042+ else if (!uid_eq(bprm->cred->euid, current->cred->uid))
78043+ return -EPERM;
78044+ }
78045+#endif
78046+ return 0;
78047+}
78048diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
78049new file mode 100644
78050index 0000000..e3650b6
78051--- /dev/null
78052+++ b/grsecurity/grsec_sock.c
78053@@ -0,0 +1,244 @@
78054+#include <linux/kernel.h>
78055+#include <linux/module.h>
78056+#include <linux/sched.h>
78057+#include <linux/file.h>
78058+#include <linux/net.h>
78059+#include <linux/in.h>
78060+#include <linux/ip.h>
78061+#include <net/sock.h>
78062+#include <net/inet_sock.h>
78063+#include <linux/grsecurity.h>
78064+#include <linux/grinternal.h>
78065+#include <linux/gracl.h>
78066+
78067+extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
78068+extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
78069+
78070+EXPORT_SYMBOL_GPL(gr_search_udp_recvmsg);
78071+EXPORT_SYMBOL_GPL(gr_search_udp_sendmsg);
78072+
78073+#ifdef CONFIG_UNIX_MODULE
78074+EXPORT_SYMBOL_GPL(gr_acl_handle_unix);
78075+EXPORT_SYMBOL_GPL(gr_acl_handle_mknod);
78076+EXPORT_SYMBOL_GPL(gr_handle_chroot_unix);
78077+EXPORT_SYMBOL_GPL(gr_handle_create);
78078+#endif
78079+
78080+#ifdef CONFIG_GRKERNSEC
78081+#define gr_conn_table_size 32749
78082+struct conn_table_entry {
78083+ struct conn_table_entry *next;
78084+ struct signal_struct *sig;
78085+};
78086+
78087+struct conn_table_entry *gr_conn_table[gr_conn_table_size];
78088+DEFINE_SPINLOCK(gr_conn_table_lock);
78089+
78090+extern const char * gr_socktype_to_name(unsigned char type);
78091+extern const char * gr_proto_to_name(unsigned char proto);
78092+extern const char * gr_sockfamily_to_name(unsigned char family);
78093+
78094+static __inline__ int
78095+conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
78096+{
78097+ return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
78098+}
78099+
78100+static __inline__ int
78101+conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
78102+ __u16 sport, __u16 dport)
78103+{
78104+ if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
78105+ sig->gr_sport == sport && sig->gr_dport == dport))
78106+ return 1;
78107+ else
78108+ return 0;
78109+}
78110+
78111+static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
78112+{
78113+ struct conn_table_entry **match;
78114+ unsigned int index;
78115+
78116+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
78117+ sig->gr_sport, sig->gr_dport,
78118+ gr_conn_table_size);
78119+
78120+ newent->sig = sig;
78121+
78122+ match = &gr_conn_table[index];
78123+ newent->next = *match;
78124+ *match = newent;
78125+
78126+ return;
78127+}
78128+
78129+static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
78130+{
78131+ struct conn_table_entry *match, *last = NULL;
78132+ unsigned int index;
78133+
78134+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
78135+ sig->gr_sport, sig->gr_dport,
78136+ gr_conn_table_size);
78137+
78138+ match = gr_conn_table[index];
78139+ while (match && !conn_match(match->sig,
78140+ sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
78141+ sig->gr_dport)) {
78142+ last = match;
78143+ match = match->next;
78144+ }
78145+
78146+ if (match) {
78147+ if (last)
78148+ last->next = match->next;
78149+ else
78150+ gr_conn_table[index] = NULL;
78151+ kfree(match);
78152+ }
78153+
78154+ return;
78155+}
78156+
78157+static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
78158+ __u16 sport, __u16 dport)
78159+{
78160+ struct conn_table_entry *match;
78161+ unsigned int index;
78162+
78163+ index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
78164+
78165+ match = gr_conn_table[index];
78166+ while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
78167+ match = match->next;
78168+
78169+ if (match)
78170+ return match->sig;
78171+ else
78172+ return NULL;
78173+}
78174+
78175+#endif
78176+
78177+void gr_update_task_in_ip_table(const struct inet_sock *inet)
78178+{
78179+#ifdef CONFIG_GRKERNSEC
78180+ struct signal_struct *sig = current->signal;
78181+ struct conn_table_entry *newent;
78182+
78183+ newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
78184+ if (newent == NULL)
78185+ return;
78186+ /* no bh lock needed since we are called with bh disabled */
78187+ spin_lock(&gr_conn_table_lock);
78188+ gr_del_task_from_ip_table_nolock(sig);
78189+ sig->gr_saddr = inet->inet_rcv_saddr;
78190+ sig->gr_daddr = inet->inet_daddr;
78191+ sig->gr_sport = inet->inet_sport;
78192+ sig->gr_dport = inet->inet_dport;
78193+ gr_add_to_task_ip_table_nolock(sig, newent);
78194+ spin_unlock(&gr_conn_table_lock);
78195+#endif
78196+ return;
78197+}
78198+
78199+void gr_del_task_from_ip_table(struct task_struct *task)
78200+{
78201+#ifdef CONFIG_GRKERNSEC
78202+ spin_lock_bh(&gr_conn_table_lock);
78203+ gr_del_task_from_ip_table_nolock(task->signal);
78204+ spin_unlock_bh(&gr_conn_table_lock);
78205+#endif
78206+ return;
78207+}
78208+
78209+void
78210+gr_attach_curr_ip(const struct sock *sk)
78211+{
78212+#ifdef CONFIG_GRKERNSEC
78213+ struct signal_struct *p, *set;
78214+ const struct inet_sock *inet = inet_sk(sk);
78215+
78216+ if (unlikely(sk->sk_protocol != IPPROTO_TCP))
78217+ return;
78218+
78219+ set = current->signal;
78220+
78221+ spin_lock_bh(&gr_conn_table_lock);
78222+ p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
78223+ inet->inet_dport, inet->inet_sport);
78224+ if (unlikely(p != NULL)) {
78225+ set->curr_ip = p->curr_ip;
78226+ set->used_accept = 1;
78227+ gr_del_task_from_ip_table_nolock(p);
78228+ spin_unlock_bh(&gr_conn_table_lock);
78229+ return;
78230+ }
78231+ spin_unlock_bh(&gr_conn_table_lock);
78232+
78233+ set->curr_ip = inet->inet_daddr;
78234+ set->used_accept = 1;
78235+#endif
78236+ return;
78237+}
78238+
78239+int
78240+gr_handle_sock_all(const int family, const int type, const int protocol)
78241+{
78242+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
78243+ if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
78244+ (family != AF_UNIX)) {
78245+ if (family == AF_INET)
78246+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
78247+ else
78248+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
78249+ return -EACCES;
78250+ }
78251+#endif
78252+ return 0;
78253+}
78254+
78255+int
78256+gr_handle_sock_server(const struct sockaddr *sck)
78257+{
78258+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
78259+ if (grsec_enable_socket_server &&
78260+ in_group_p(grsec_socket_server_gid) &&
78261+ sck && (sck->sa_family != AF_UNIX) &&
78262+ (sck->sa_family != AF_LOCAL)) {
78263+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
78264+ return -EACCES;
78265+ }
78266+#endif
78267+ return 0;
78268+}
78269+
78270+int
78271+gr_handle_sock_server_other(const struct sock *sck)
78272+{
78273+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
78274+ if (grsec_enable_socket_server &&
78275+ in_group_p(grsec_socket_server_gid) &&
78276+ sck && (sck->sk_family != AF_UNIX) &&
78277+ (sck->sk_family != AF_LOCAL)) {
78278+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
78279+ return -EACCES;
78280+ }
78281+#endif
78282+ return 0;
78283+}
78284+
78285+int
78286+gr_handle_sock_client(const struct sockaddr *sck)
78287+{
78288+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
78289+ if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
78290+ sck && (sck->sa_family != AF_UNIX) &&
78291+ (sck->sa_family != AF_LOCAL)) {
78292+ gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
78293+ return -EACCES;
78294+ }
78295+#endif
78296+ return 0;
78297+}
78298diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
78299new file mode 100644
78300index 0000000..8159888
78301--- /dev/null
78302+++ b/grsecurity/grsec_sysctl.c
78303@@ -0,0 +1,479 @@
78304+#include <linux/kernel.h>
78305+#include <linux/sched.h>
78306+#include <linux/sysctl.h>
78307+#include <linux/grsecurity.h>
78308+#include <linux/grinternal.h>
78309+
78310+int
78311+gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
78312+{
78313+#ifdef CONFIG_GRKERNSEC_SYSCTL
78314+ if (dirname == NULL || name == NULL)
78315+ return 0;
78316+ if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
78317+ gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
78318+ return -EACCES;
78319+ }
78320+#endif
78321+ return 0;
78322+}
78323+
78324+#if defined(CONFIG_GRKERNSEC_ROFS) || defined(CONFIG_GRKERNSEC_DENYUSB)
78325+static int __maybe_unused __read_only one = 1;
78326+#endif
78327+
78328+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS) || \
78329+ defined(CONFIG_GRKERNSEC_DENYUSB)
78330+struct ctl_table grsecurity_table[] = {
78331+#ifdef CONFIG_GRKERNSEC_SYSCTL
78332+#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
78333+#ifdef CONFIG_GRKERNSEC_IO
78334+ {
78335+ .procname = "disable_priv_io",
78336+ .data = &grsec_disable_privio,
78337+ .maxlen = sizeof(int),
78338+ .mode = 0600,
78339+ .proc_handler = &proc_dointvec,
78340+ },
78341+#endif
78342+#endif
78343+#ifdef CONFIG_GRKERNSEC_LINK
78344+ {
78345+ .procname = "linking_restrictions",
78346+ .data = &grsec_enable_link,
78347+ .maxlen = sizeof(int),
78348+ .mode = 0600,
78349+ .proc_handler = &proc_dointvec,
78350+ },
78351+#endif
78352+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
78353+ {
78354+ .procname = "enforce_symlinksifowner",
78355+ .data = &grsec_enable_symlinkown,
78356+ .maxlen = sizeof(int),
78357+ .mode = 0600,
78358+ .proc_handler = &proc_dointvec,
78359+ },
78360+ {
78361+ .procname = "symlinkown_gid",
78362+ .data = &grsec_symlinkown_gid,
78363+ .maxlen = sizeof(int),
78364+ .mode = 0600,
78365+ .proc_handler = &proc_dointvec,
78366+ },
78367+#endif
78368+#ifdef CONFIG_GRKERNSEC_BRUTE
78369+ {
78370+ .procname = "deter_bruteforce",
78371+ .data = &grsec_enable_brute,
78372+ .maxlen = sizeof(int),
78373+ .mode = 0600,
78374+ .proc_handler = &proc_dointvec,
78375+ },
78376+#endif
78377+#ifdef CONFIG_GRKERNSEC_FIFO
78378+ {
78379+ .procname = "fifo_restrictions",
78380+ .data = &grsec_enable_fifo,
78381+ .maxlen = sizeof(int),
78382+ .mode = 0600,
78383+ .proc_handler = &proc_dointvec,
78384+ },
78385+#endif
78386+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
78387+ {
78388+ .procname = "ptrace_readexec",
78389+ .data = &grsec_enable_ptrace_readexec,
78390+ .maxlen = sizeof(int),
78391+ .mode = 0600,
78392+ .proc_handler = &proc_dointvec,
78393+ },
78394+#endif
78395+#ifdef CONFIG_GRKERNSEC_SETXID
78396+ {
78397+ .procname = "consistent_setxid",
78398+ .data = &grsec_enable_setxid,
78399+ .maxlen = sizeof(int),
78400+ .mode = 0600,
78401+ .proc_handler = &proc_dointvec,
78402+ },
78403+#endif
78404+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
78405+ {
78406+ .procname = "ip_blackhole",
78407+ .data = &grsec_enable_blackhole,
78408+ .maxlen = sizeof(int),
78409+ .mode = 0600,
78410+ .proc_handler = &proc_dointvec,
78411+ },
78412+ {
78413+ .procname = "lastack_retries",
78414+ .data = &grsec_lastack_retries,
78415+ .maxlen = sizeof(int),
78416+ .mode = 0600,
78417+ .proc_handler = &proc_dointvec,
78418+ },
78419+#endif
78420+#ifdef CONFIG_GRKERNSEC_EXECLOG
78421+ {
78422+ .procname = "exec_logging",
78423+ .data = &grsec_enable_execlog,
78424+ .maxlen = sizeof(int),
78425+ .mode = 0600,
78426+ .proc_handler = &proc_dointvec,
78427+ },
78428+#endif
78429+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
78430+ {
78431+ .procname = "rwxmap_logging",
78432+ .data = &grsec_enable_log_rwxmaps,
78433+ .maxlen = sizeof(int),
78434+ .mode = 0600,
78435+ .proc_handler = &proc_dointvec,
78436+ },
78437+#endif
78438+#ifdef CONFIG_GRKERNSEC_SIGNAL
78439+ {
78440+ .procname = "signal_logging",
78441+ .data = &grsec_enable_signal,
78442+ .maxlen = sizeof(int),
78443+ .mode = 0600,
78444+ .proc_handler = &proc_dointvec,
78445+ },
78446+#endif
78447+#ifdef CONFIG_GRKERNSEC_FORKFAIL
78448+ {
78449+ .procname = "forkfail_logging",
78450+ .data = &grsec_enable_forkfail,
78451+ .maxlen = sizeof(int),
78452+ .mode = 0600,
78453+ .proc_handler = &proc_dointvec,
78454+ },
78455+#endif
78456+#ifdef CONFIG_GRKERNSEC_TIME
78457+ {
78458+ .procname = "timechange_logging",
78459+ .data = &grsec_enable_time,
78460+ .maxlen = sizeof(int),
78461+ .mode = 0600,
78462+ .proc_handler = &proc_dointvec,
78463+ },
78464+#endif
78465+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
78466+ {
78467+ .procname = "chroot_deny_shmat",
78468+ .data = &grsec_enable_chroot_shmat,
78469+ .maxlen = sizeof(int),
78470+ .mode = 0600,
78471+ .proc_handler = &proc_dointvec,
78472+ },
78473+#endif
78474+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
78475+ {
78476+ .procname = "chroot_deny_unix",
78477+ .data = &grsec_enable_chroot_unix,
78478+ .maxlen = sizeof(int),
78479+ .mode = 0600,
78480+ .proc_handler = &proc_dointvec,
78481+ },
78482+#endif
78483+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
78484+ {
78485+ .procname = "chroot_deny_mount",
78486+ .data = &grsec_enable_chroot_mount,
78487+ .maxlen = sizeof(int),
78488+ .mode = 0600,
78489+ .proc_handler = &proc_dointvec,
78490+ },
78491+#endif
78492+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
78493+ {
78494+ .procname = "chroot_deny_fchdir",
78495+ .data = &grsec_enable_chroot_fchdir,
78496+ .maxlen = sizeof(int),
78497+ .mode = 0600,
78498+ .proc_handler = &proc_dointvec,
78499+ },
78500+#endif
78501+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
78502+ {
78503+ .procname = "chroot_deny_chroot",
78504+ .data = &grsec_enable_chroot_double,
78505+ .maxlen = sizeof(int),
78506+ .mode = 0600,
78507+ .proc_handler = &proc_dointvec,
78508+ },
78509+#endif
78510+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
78511+ {
78512+ .procname = "chroot_deny_pivot",
78513+ .data = &grsec_enable_chroot_pivot,
78514+ .maxlen = sizeof(int),
78515+ .mode = 0600,
78516+ .proc_handler = &proc_dointvec,
78517+ },
78518+#endif
78519+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
78520+ {
78521+ .procname = "chroot_enforce_chdir",
78522+ .data = &grsec_enable_chroot_chdir,
78523+ .maxlen = sizeof(int),
78524+ .mode = 0600,
78525+ .proc_handler = &proc_dointvec,
78526+ },
78527+#endif
78528+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
78529+ {
78530+ .procname = "chroot_deny_chmod",
78531+ .data = &grsec_enable_chroot_chmod,
78532+ .maxlen = sizeof(int),
78533+ .mode = 0600,
78534+ .proc_handler = &proc_dointvec,
78535+ },
78536+#endif
78537+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
78538+ {
78539+ .procname = "chroot_deny_mknod",
78540+ .data = &grsec_enable_chroot_mknod,
78541+ .maxlen = sizeof(int),
78542+ .mode = 0600,
78543+ .proc_handler = &proc_dointvec,
78544+ },
78545+#endif
78546+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
78547+ {
78548+ .procname = "chroot_restrict_nice",
78549+ .data = &grsec_enable_chroot_nice,
78550+ .maxlen = sizeof(int),
78551+ .mode = 0600,
78552+ .proc_handler = &proc_dointvec,
78553+ },
78554+#endif
78555+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
78556+ {
78557+ .procname = "chroot_execlog",
78558+ .data = &grsec_enable_chroot_execlog,
78559+ .maxlen = sizeof(int),
78560+ .mode = 0600,
78561+ .proc_handler = &proc_dointvec,
78562+ },
78563+#endif
78564+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
78565+ {
78566+ .procname = "chroot_caps",
78567+ .data = &grsec_enable_chroot_caps,
78568+ .maxlen = sizeof(int),
78569+ .mode = 0600,
78570+ .proc_handler = &proc_dointvec,
78571+ },
78572+#endif
78573+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
78574+ {
78575+ .procname = "chroot_deny_sysctl",
78576+ .data = &grsec_enable_chroot_sysctl,
78577+ .maxlen = sizeof(int),
78578+ .mode = 0600,
78579+ .proc_handler = &proc_dointvec,
78580+ },
78581+#endif
78582+#ifdef CONFIG_GRKERNSEC_TPE
78583+ {
78584+ .procname = "tpe",
78585+ .data = &grsec_enable_tpe,
78586+ .maxlen = sizeof(int),
78587+ .mode = 0600,
78588+ .proc_handler = &proc_dointvec,
78589+ },
78590+ {
78591+ .procname = "tpe_gid",
78592+ .data = &grsec_tpe_gid,
78593+ .maxlen = sizeof(int),
78594+ .mode = 0600,
78595+ .proc_handler = &proc_dointvec,
78596+ },
78597+#endif
78598+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
78599+ {
78600+ .procname = "tpe_invert",
78601+ .data = &grsec_enable_tpe_invert,
78602+ .maxlen = sizeof(int),
78603+ .mode = 0600,
78604+ .proc_handler = &proc_dointvec,
78605+ },
78606+#endif
78607+#ifdef CONFIG_GRKERNSEC_TPE_ALL
78608+ {
78609+ .procname = "tpe_restrict_all",
78610+ .data = &grsec_enable_tpe_all,
78611+ .maxlen = sizeof(int),
78612+ .mode = 0600,
78613+ .proc_handler = &proc_dointvec,
78614+ },
78615+#endif
78616+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
78617+ {
78618+ .procname = "socket_all",
78619+ .data = &grsec_enable_socket_all,
78620+ .maxlen = sizeof(int),
78621+ .mode = 0600,
78622+ .proc_handler = &proc_dointvec,
78623+ },
78624+ {
78625+ .procname = "socket_all_gid",
78626+ .data = &grsec_socket_all_gid,
78627+ .maxlen = sizeof(int),
78628+ .mode = 0600,
78629+ .proc_handler = &proc_dointvec,
78630+ },
78631+#endif
78632+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
78633+ {
78634+ .procname = "socket_client",
78635+ .data = &grsec_enable_socket_client,
78636+ .maxlen = sizeof(int),
78637+ .mode = 0600,
78638+ .proc_handler = &proc_dointvec,
78639+ },
78640+ {
78641+ .procname = "socket_client_gid",
78642+ .data = &grsec_socket_client_gid,
78643+ .maxlen = sizeof(int),
78644+ .mode = 0600,
78645+ .proc_handler = &proc_dointvec,
78646+ },
78647+#endif
78648+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
78649+ {
78650+ .procname = "socket_server",
78651+ .data = &grsec_enable_socket_server,
78652+ .maxlen = sizeof(int),
78653+ .mode = 0600,
78654+ .proc_handler = &proc_dointvec,
78655+ },
78656+ {
78657+ .procname = "socket_server_gid",
78658+ .data = &grsec_socket_server_gid,
78659+ .maxlen = sizeof(int),
78660+ .mode = 0600,
78661+ .proc_handler = &proc_dointvec,
78662+ },
78663+#endif
78664+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
78665+ {
78666+ .procname = "audit_group",
78667+ .data = &grsec_enable_group,
78668+ .maxlen = sizeof(int),
78669+ .mode = 0600,
78670+ .proc_handler = &proc_dointvec,
78671+ },
78672+ {
78673+ .procname = "audit_gid",
78674+ .data = &grsec_audit_gid,
78675+ .maxlen = sizeof(int),
78676+ .mode = 0600,
78677+ .proc_handler = &proc_dointvec,
78678+ },
78679+#endif
78680+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
78681+ {
78682+ .procname = "audit_chdir",
78683+ .data = &grsec_enable_chdir,
78684+ .maxlen = sizeof(int),
78685+ .mode = 0600,
78686+ .proc_handler = &proc_dointvec,
78687+ },
78688+#endif
78689+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
78690+ {
78691+ .procname = "audit_mount",
78692+ .data = &grsec_enable_mount,
78693+ .maxlen = sizeof(int),
78694+ .mode = 0600,
78695+ .proc_handler = &proc_dointvec,
78696+ },
78697+#endif
78698+#ifdef CONFIG_GRKERNSEC_DMESG
78699+ {
78700+ .procname = "dmesg",
78701+ .data = &grsec_enable_dmesg,
78702+ .maxlen = sizeof(int),
78703+ .mode = 0600,
78704+ .proc_handler = &proc_dointvec,
78705+ },
78706+#endif
78707+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
78708+ {
78709+ .procname = "chroot_findtask",
78710+ .data = &grsec_enable_chroot_findtask,
78711+ .maxlen = sizeof(int),
78712+ .mode = 0600,
78713+ .proc_handler = &proc_dointvec,
78714+ },
78715+#endif
78716+#ifdef CONFIG_GRKERNSEC_RESLOG
78717+ {
78718+ .procname = "resource_logging",
78719+ .data = &grsec_resource_logging,
78720+ .maxlen = sizeof(int),
78721+ .mode = 0600,
78722+ .proc_handler = &proc_dointvec,
78723+ },
78724+#endif
78725+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
78726+ {
78727+ .procname = "audit_ptrace",
78728+ .data = &grsec_enable_audit_ptrace,
78729+ .maxlen = sizeof(int),
78730+ .mode = 0600,
78731+ .proc_handler = &proc_dointvec,
78732+ },
78733+#endif
78734+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
78735+ {
78736+ .procname = "harden_ptrace",
78737+ .data = &grsec_enable_harden_ptrace,
78738+ .maxlen = sizeof(int),
78739+ .mode = 0600,
78740+ .proc_handler = &proc_dointvec,
78741+ },
78742+#endif
78743+#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
78744+ {
78745+ .procname = "harden_ipc",
78746+ .data = &grsec_enable_harden_ipc,
78747+ .maxlen = sizeof(int),
78748+ .mode = 0600,
78749+ .proc_handler = &proc_dointvec,
78750+ },
78751+#endif
78752+ {
78753+ .procname = "grsec_lock",
78754+ .data = &grsec_lock,
78755+ .maxlen = sizeof(int),
78756+ .mode = 0600,
78757+ .proc_handler = &proc_dointvec,
78758+ },
78759+#endif
78760+#ifdef CONFIG_GRKERNSEC_ROFS
78761+ {
78762+ .procname = "romount_protect",
78763+ .data = &grsec_enable_rofs,
78764+ .maxlen = sizeof(int),
78765+ .mode = 0600,
78766+ .proc_handler = &proc_dointvec_minmax,
78767+ .extra1 = &one,
78768+ .extra2 = &one,
78769+ },
78770+#endif
78771+#if defined(CONFIG_GRKERNSEC_DENYUSB) && !defined(CONFIG_GRKERNSEC_DENYUSB_FORCE)
78772+ {
78773+ .procname = "deny_new_usb",
78774+ .data = &grsec_deny_new_usb,
78775+ .maxlen = sizeof(int),
78776+ .mode = 0600,
78777+ .proc_handler = &proc_dointvec,
78778+ },
78779+#endif
78780+ { }
78781+};
78782+#endif
78783diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
78784new file mode 100644
78785index 0000000..61b514e
78786--- /dev/null
78787+++ b/grsecurity/grsec_time.c
78788@@ -0,0 +1,16 @@
78789+#include <linux/kernel.h>
78790+#include <linux/sched.h>
78791+#include <linux/grinternal.h>
78792+#include <linux/module.h>
78793+
78794+void
78795+gr_log_timechange(void)
78796+{
78797+#ifdef CONFIG_GRKERNSEC_TIME
78798+ if (grsec_enable_time)
78799+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
78800+#endif
78801+ return;
78802+}
78803+
78804+EXPORT_SYMBOL_GPL(gr_log_timechange);
78805diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
78806new file mode 100644
78807index 0000000..d1953de
78808--- /dev/null
78809+++ b/grsecurity/grsec_tpe.c
78810@@ -0,0 +1,78 @@
78811+#include <linux/kernel.h>
78812+#include <linux/sched.h>
78813+#include <linux/file.h>
78814+#include <linux/fs.h>
78815+#include <linux/grinternal.h>
78816+
78817+extern int gr_acl_tpe_check(void);
78818+
78819+int
78820+gr_tpe_allow(const struct file *file)
78821+{
78822+#ifdef CONFIG_GRKERNSEC
78823+ struct inode *inode = file->f_path.dentry->d_parent->d_inode;
78824+ struct inode *file_inode = file->f_path.dentry->d_inode;
78825+ const struct cred *cred = current_cred();
78826+ char *msg = NULL;
78827+ char *msg2 = NULL;
78828+
78829+ // never restrict root
78830+ if (gr_is_global_root(cred->uid))
78831+ return 1;
78832+
78833+ if (grsec_enable_tpe) {
78834+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
78835+ if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
78836+ msg = "not being in trusted group";
78837+ else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
78838+ msg = "being in untrusted group";
78839+#else
78840+ if (in_group_p(grsec_tpe_gid))
78841+ msg = "being in untrusted group";
78842+#endif
78843+ }
78844+ if (!msg && gr_acl_tpe_check())
78845+ msg = "being in untrusted role";
78846+
78847+ // not in any affected group/role
78848+ if (!msg)
78849+ goto next_check;
78850+
78851+ if (gr_is_global_nonroot(inode->i_uid))
78852+ msg2 = "file in non-root-owned directory";
78853+ else if (inode->i_mode & S_IWOTH)
78854+ msg2 = "file in world-writable directory";
78855+ else if (inode->i_mode & S_IWGRP)
78856+ msg2 = "file in group-writable directory";
78857+ else if (file_inode->i_mode & S_IWOTH)
78858+ msg2 = "file is world-writable";
78859+
78860+ if (msg && msg2) {
78861+ char fullmsg[70] = {0};
78862+ snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
78863+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
78864+ return 0;
78865+ }
78866+ msg = NULL;
78867+next_check:
78868+#ifdef CONFIG_GRKERNSEC_TPE_ALL
78869+ if (!grsec_enable_tpe || !grsec_enable_tpe_all)
78870+ return 1;
78871+
78872+ if (gr_is_global_nonroot(inode->i_uid) && !uid_eq(inode->i_uid, cred->uid))
78873+ msg = "directory not owned by user";
78874+ else if (inode->i_mode & S_IWOTH)
78875+ msg = "file in world-writable directory";
78876+ else if (inode->i_mode & S_IWGRP)
78877+ msg = "file in group-writable directory";
78878+ else if (file_inode->i_mode & S_IWOTH)
78879+ msg = "file is world-writable";
78880+
78881+ if (msg) {
78882+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
78883+ return 0;
78884+ }
78885+#endif
78886+#endif
78887+ return 1;
78888+}
78889diff --git a/grsecurity/grsec_usb.c b/grsecurity/grsec_usb.c
78890new file mode 100644
78891index 0000000..ae02d8e
78892--- /dev/null
78893+++ b/grsecurity/grsec_usb.c
78894@@ -0,0 +1,15 @@
78895+#include <linux/kernel.h>
78896+#include <linux/grinternal.h>
78897+#include <linux/module.h>
78898+
78899+int gr_handle_new_usb(void)
78900+{
78901+#ifdef CONFIG_GRKERNSEC_DENYUSB
78902+ if (grsec_deny_new_usb) {
78903+ printk(KERN_ALERT "grsec: denied insert of new USB device\n");
78904+ return 1;
78905+ }
78906+#endif
78907+ return 0;
78908+}
78909+EXPORT_SYMBOL_GPL(gr_handle_new_usb);
78910diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
78911new file mode 100644
78912index 0000000..158b330
78913--- /dev/null
78914+++ b/grsecurity/grsum.c
78915@@ -0,0 +1,64 @@
78916+#include <linux/err.h>
78917+#include <linux/kernel.h>
78918+#include <linux/sched.h>
78919+#include <linux/mm.h>
78920+#include <linux/scatterlist.h>
78921+#include <linux/crypto.h>
78922+#include <linux/gracl.h>
78923+
78924+
78925+#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
78926+#error "crypto and sha256 must be built into the kernel"
78927+#endif
78928+
78929+int
78930+chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
78931+{
78932+ struct crypto_hash *tfm;
78933+ struct hash_desc desc;
78934+ struct scatterlist sg[2];
78935+ unsigned char temp_sum[GR_SHA_LEN] __attribute__((aligned(__alignof__(unsigned long))));
78936+ unsigned long *tmpsumptr = (unsigned long *)temp_sum;
78937+ unsigned long *sumptr = (unsigned long *)sum;
78938+ int cryptres;
78939+ int retval = 1;
78940+ volatile int mismatched = 0;
78941+ volatile int dummy = 0;
78942+ unsigned int i;
78943+
78944+ tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
78945+ if (IS_ERR(tfm)) {
78946+ /* should never happen, since sha256 should be built in */
78947+ memset(entry->pw, 0, GR_PW_LEN);
78948+ return 1;
78949+ }
78950+
78951+ sg_init_table(sg, 2);
78952+ sg_set_buf(&sg[0], salt, GR_SALT_LEN);
78953+ sg_set_buf(&sg[1], entry->pw, strlen(entry->pw));
78954+
78955+ desc.tfm = tfm;
78956+ desc.flags = 0;
78957+
78958+ cryptres = crypto_hash_digest(&desc, sg, GR_SALT_LEN + strlen(entry->pw),
78959+ temp_sum);
78960+
78961+ memset(entry->pw, 0, GR_PW_LEN);
78962+
78963+ if (cryptres)
78964+ goto out;
78965+
78966+ for (i = 0; i < GR_SHA_LEN/sizeof(tmpsumptr[0]); i++)
78967+ if (sumptr[i] != tmpsumptr[i])
78968+ mismatched = 1;
78969+ else
78970+ dummy = 1; // waste a cycle
78971+
78972+ if (!mismatched)
78973+ retval = dummy - 1;
78974+
78975+out:
78976+ crypto_free_hash(tfm);
78977+
78978+ return retval;
78979+}
78980diff --git a/include/asm-generic/4level-fixup.h b/include/asm-generic/4level-fixup.h
78981index 77ff547..181834f 100644
78982--- a/include/asm-generic/4level-fixup.h
78983+++ b/include/asm-generic/4level-fixup.h
78984@@ -13,8 +13,10 @@
78985 #define pmd_alloc(mm, pud, address) \
78986 ((unlikely(pgd_none(*(pud))) && __pmd_alloc(mm, pud, address))? \
78987 NULL: pmd_offset(pud, address))
78988+#define pmd_alloc_kernel(mm, pud, address) pmd_alloc((mm), (pud), (address))
78989
78990 #define pud_alloc(mm, pgd, address) (pgd)
78991+#define pud_alloc_kernel(mm, pgd, address) pud_alloc((mm), (pgd), (address))
78992 #define pud_offset(pgd, start) (pgd)
78993 #define pud_none(pud) 0
78994 #define pud_bad(pud) 0
78995diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
78996index b7babf0..1e4b4f1 100644
78997--- a/include/asm-generic/atomic-long.h
78998+++ b/include/asm-generic/atomic-long.h
78999@@ -22,6 +22,12 @@
79000
79001 typedef atomic64_t atomic_long_t;
79002
79003+#ifdef CONFIG_PAX_REFCOUNT
79004+typedef atomic64_unchecked_t atomic_long_unchecked_t;
79005+#else
79006+typedef atomic64_t atomic_long_unchecked_t;
79007+#endif
79008+
79009 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
79010
79011 static inline long atomic_long_read(atomic_long_t *l)
79012@@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
79013 return (long)atomic64_read(v);
79014 }
79015
79016+#ifdef CONFIG_PAX_REFCOUNT
79017+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
79018+{
79019+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
79020+
79021+ return (long)atomic64_read_unchecked(v);
79022+}
79023+#endif
79024+
79025 static inline void atomic_long_set(atomic_long_t *l, long i)
79026 {
79027 atomic64_t *v = (atomic64_t *)l;
79028@@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
79029 atomic64_set(v, i);
79030 }
79031
79032+#ifdef CONFIG_PAX_REFCOUNT
79033+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
79034+{
79035+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
79036+
79037+ atomic64_set_unchecked(v, i);
79038+}
79039+#endif
79040+
79041 static inline void atomic_long_inc(atomic_long_t *l)
79042 {
79043 atomic64_t *v = (atomic64_t *)l;
79044@@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
79045 atomic64_inc(v);
79046 }
79047
79048+#ifdef CONFIG_PAX_REFCOUNT
79049+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
79050+{
79051+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
79052+
79053+ atomic64_inc_unchecked(v);
79054+}
79055+#endif
79056+
79057 static inline void atomic_long_dec(atomic_long_t *l)
79058 {
79059 atomic64_t *v = (atomic64_t *)l;
79060@@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
79061 atomic64_dec(v);
79062 }
79063
79064+#ifdef CONFIG_PAX_REFCOUNT
79065+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
79066+{
79067+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
79068+
79069+ atomic64_dec_unchecked(v);
79070+}
79071+#endif
79072+
79073 static inline void atomic_long_add(long i, atomic_long_t *l)
79074 {
79075 atomic64_t *v = (atomic64_t *)l;
79076@@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
79077 atomic64_add(i, v);
79078 }
79079
79080+#ifdef CONFIG_PAX_REFCOUNT
79081+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
79082+{
79083+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
79084+
79085+ atomic64_add_unchecked(i, v);
79086+}
79087+#endif
79088+
79089 static inline void atomic_long_sub(long i, atomic_long_t *l)
79090 {
79091 atomic64_t *v = (atomic64_t *)l;
79092@@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
79093 atomic64_sub(i, v);
79094 }
79095
79096+#ifdef CONFIG_PAX_REFCOUNT
79097+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
79098+{
79099+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
79100+
79101+ atomic64_sub_unchecked(i, v);
79102+}
79103+#endif
79104+
79105 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
79106 {
79107 atomic64_t *v = (atomic64_t *)l;
79108@@ -94,13 +154,22 @@ static inline int atomic_long_add_negative(long i, atomic_long_t *l)
79109 return atomic64_add_negative(i, v);
79110 }
79111
79112-static inline long atomic_long_add_return(long i, atomic_long_t *l)
79113+static inline long __intentional_overflow(-1) atomic_long_add_return(long i, atomic_long_t *l)
79114 {
79115 atomic64_t *v = (atomic64_t *)l;
79116
79117 return (long)atomic64_add_return(i, v);
79118 }
79119
79120+#ifdef CONFIG_PAX_REFCOUNT
79121+static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
79122+{
79123+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
79124+
79125+ return (long)atomic64_add_return_unchecked(i, v);
79126+}
79127+#endif
79128+
79129 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
79130 {
79131 atomic64_t *v = (atomic64_t *)l;
79132@@ -115,6 +184,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
79133 return (long)atomic64_inc_return(v);
79134 }
79135
79136+#ifdef CONFIG_PAX_REFCOUNT
79137+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
79138+{
79139+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
79140+
79141+ return (long)atomic64_inc_return_unchecked(v);
79142+}
79143+#endif
79144+
79145 static inline long atomic_long_dec_return(atomic_long_t *l)
79146 {
79147 atomic64_t *v = (atomic64_t *)l;
79148@@ -140,6 +218,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
79149
79150 typedef atomic_t atomic_long_t;
79151
79152+#ifdef CONFIG_PAX_REFCOUNT
79153+typedef atomic_unchecked_t atomic_long_unchecked_t;
79154+#else
79155+typedef atomic_t atomic_long_unchecked_t;
79156+#endif
79157+
79158 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
79159 static inline long atomic_long_read(atomic_long_t *l)
79160 {
79161@@ -148,6 +232,15 @@ static inline long atomic_long_read(atomic_long_t *l)
79162 return (long)atomic_read(v);
79163 }
79164
79165+#ifdef CONFIG_PAX_REFCOUNT
79166+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
79167+{
79168+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
79169+
79170+ return (long)atomic_read_unchecked(v);
79171+}
79172+#endif
79173+
79174 static inline void atomic_long_set(atomic_long_t *l, long i)
79175 {
79176 atomic_t *v = (atomic_t *)l;
79177@@ -155,6 +248,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
79178 atomic_set(v, i);
79179 }
79180
79181+#ifdef CONFIG_PAX_REFCOUNT
79182+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
79183+{
79184+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
79185+
79186+ atomic_set_unchecked(v, i);
79187+}
79188+#endif
79189+
79190 static inline void atomic_long_inc(atomic_long_t *l)
79191 {
79192 atomic_t *v = (atomic_t *)l;
79193@@ -162,6 +264,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
79194 atomic_inc(v);
79195 }
79196
79197+#ifdef CONFIG_PAX_REFCOUNT
79198+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
79199+{
79200+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
79201+
79202+ atomic_inc_unchecked(v);
79203+}
79204+#endif
79205+
79206 static inline void atomic_long_dec(atomic_long_t *l)
79207 {
79208 atomic_t *v = (atomic_t *)l;
79209@@ -169,6 +280,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
79210 atomic_dec(v);
79211 }
79212
79213+#ifdef CONFIG_PAX_REFCOUNT
79214+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
79215+{
79216+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
79217+
79218+ atomic_dec_unchecked(v);
79219+}
79220+#endif
79221+
79222 static inline void atomic_long_add(long i, atomic_long_t *l)
79223 {
79224 atomic_t *v = (atomic_t *)l;
79225@@ -176,6 +296,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
79226 atomic_add(i, v);
79227 }
79228
79229+#ifdef CONFIG_PAX_REFCOUNT
79230+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
79231+{
79232+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
79233+
79234+ atomic_add_unchecked(i, v);
79235+}
79236+#endif
79237+
79238 static inline void atomic_long_sub(long i, atomic_long_t *l)
79239 {
79240 atomic_t *v = (atomic_t *)l;
79241@@ -183,6 +312,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
79242 atomic_sub(i, v);
79243 }
79244
79245+#ifdef CONFIG_PAX_REFCOUNT
79246+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
79247+{
79248+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
79249+
79250+ atomic_sub_unchecked(i, v);
79251+}
79252+#endif
79253+
79254 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
79255 {
79256 atomic_t *v = (atomic_t *)l;
79257@@ -211,13 +349,23 @@ static inline int atomic_long_add_negative(long i, atomic_long_t *l)
79258 return atomic_add_negative(i, v);
79259 }
79260
79261-static inline long atomic_long_add_return(long i, atomic_long_t *l)
79262+static inline long __intentional_overflow(-1) atomic_long_add_return(long i, atomic_long_t *l)
79263 {
79264 atomic_t *v = (atomic_t *)l;
79265
79266 return (long)atomic_add_return(i, v);
79267 }
79268
79269+#ifdef CONFIG_PAX_REFCOUNT
79270+static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
79271+{
79272+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
79273+
79274+ return (long)atomic_add_return_unchecked(i, v);
79275+}
79276+
79277+#endif
79278+
79279 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
79280 {
79281 atomic_t *v = (atomic_t *)l;
79282@@ -232,6 +380,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
79283 return (long)atomic_inc_return(v);
79284 }
79285
79286+#ifdef CONFIG_PAX_REFCOUNT
79287+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
79288+{
79289+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
79290+
79291+ return (long)atomic_inc_return_unchecked(v);
79292+}
79293+#endif
79294+
79295 static inline long atomic_long_dec_return(atomic_long_t *l)
79296 {
79297 atomic_t *v = (atomic_t *)l;
79298@@ -255,4 +412,57 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
79299
79300 #endif /* BITS_PER_LONG == 64 */
79301
79302+#ifdef CONFIG_PAX_REFCOUNT
79303+static inline void pax_refcount_needs_these_functions(void)
79304+{
79305+ atomic_read_unchecked((atomic_unchecked_t *)NULL);
79306+ atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
79307+ atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
79308+ atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
79309+ atomic_inc_unchecked((atomic_unchecked_t *)NULL);
79310+ (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
79311+ atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
79312+ atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
79313+ atomic_dec_unchecked((atomic_unchecked_t *)NULL);
79314+ atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
79315+ (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
79316+#ifdef CONFIG_X86
79317+ atomic_clear_mask_unchecked(0, NULL);
79318+ atomic_set_mask_unchecked(0, NULL);
79319+#endif
79320+
79321+ atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
79322+ atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
79323+ atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
79324+ atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
79325+ atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
79326+ atomic_long_add_return_unchecked(0, (atomic_long_unchecked_t *)NULL);
79327+ atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
79328+ atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
79329+}
79330+#else
79331+#define atomic_read_unchecked(v) atomic_read(v)
79332+#define atomic_set_unchecked(v, i) atomic_set((v), (i))
79333+#define atomic_add_unchecked(i, v) atomic_add((i), (v))
79334+#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
79335+#define atomic_inc_unchecked(v) atomic_inc(v)
79336+#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
79337+#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
79338+#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
79339+#define atomic_dec_unchecked(v) atomic_dec(v)
79340+#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
79341+#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
79342+#define atomic_clear_mask_unchecked(mask, v) atomic_clear_mask((mask), (v))
79343+#define atomic_set_mask_unchecked(mask, v) atomic_set_mask((mask), (v))
79344+
79345+#define atomic_long_read_unchecked(v) atomic_long_read(v)
79346+#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
79347+#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
79348+#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
79349+#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
79350+#define atomic_long_add_return_unchecked(i, v) atomic_long_add_return((i), (v))
79351+#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
79352+#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
79353+#endif
79354+
79355 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
79356diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
79357index 30ad9c8..c70c170 100644
79358--- a/include/asm-generic/atomic64.h
79359+++ b/include/asm-generic/atomic64.h
79360@@ -16,6 +16,8 @@ typedef struct {
79361 long long counter;
79362 } atomic64_t;
79363
79364+typedef atomic64_t atomic64_unchecked_t;
79365+
79366 #define ATOMIC64_INIT(i) { (i) }
79367
79368 extern long long atomic64_read(const atomic64_t *v);
79369@@ -51,4 +53,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
79370 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
79371 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
79372
79373+#define atomic64_read_unchecked(v) atomic64_read(v)
79374+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
79375+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
79376+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
79377+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
79378+#define atomic64_inc_unchecked(v) atomic64_inc(v)
79379+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
79380+#define atomic64_dec_unchecked(v) atomic64_dec(v)
79381+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
79382+
79383 #endif /* _ASM_GENERIC_ATOMIC64_H */
79384diff --git a/include/asm-generic/barrier.h b/include/asm-generic/barrier.h
79385index 1402fa8..025a736 100644
79386--- a/include/asm-generic/barrier.h
79387+++ b/include/asm-generic/barrier.h
79388@@ -74,7 +74,7 @@
79389 do { \
79390 compiletime_assert_atomic_type(*p); \
79391 smp_mb(); \
79392- ACCESS_ONCE(*p) = (v); \
79393+ ACCESS_ONCE_RW(*p) = (v); \
79394 } while (0)
79395
79396 #define smp_load_acquire(p) \
79397diff --git a/include/asm-generic/bitops/__fls.h b/include/asm-generic/bitops/__fls.h
79398index a60a7cc..0fe12f2 100644
79399--- a/include/asm-generic/bitops/__fls.h
79400+++ b/include/asm-generic/bitops/__fls.h
79401@@ -9,7 +9,7 @@
79402 *
79403 * Undefined if no set bit exists, so code should check against 0 first.
79404 */
79405-static __always_inline unsigned long __fls(unsigned long word)
79406+static __always_inline unsigned long __intentional_overflow(-1) __fls(unsigned long word)
79407 {
79408 int num = BITS_PER_LONG - 1;
79409
79410diff --git a/include/asm-generic/bitops/fls.h b/include/asm-generic/bitops/fls.h
79411index 0576d1f..dad6c71 100644
79412--- a/include/asm-generic/bitops/fls.h
79413+++ b/include/asm-generic/bitops/fls.h
79414@@ -9,7 +9,7 @@
79415 * Note fls(0) = 0, fls(1) = 1, fls(0x80000000) = 32.
79416 */
79417
79418-static __always_inline int fls(int x)
79419+static __always_inline int __intentional_overflow(-1) fls(int x)
79420 {
79421 int r = 32;
79422
79423diff --git a/include/asm-generic/bitops/fls64.h b/include/asm-generic/bitops/fls64.h
79424index b097cf8..3d40e14 100644
79425--- a/include/asm-generic/bitops/fls64.h
79426+++ b/include/asm-generic/bitops/fls64.h
79427@@ -15,7 +15,7 @@
79428 * at position 64.
79429 */
79430 #if BITS_PER_LONG == 32
79431-static __always_inline int fls64(__u64 x)
79432+static __always_inline int __intentional_overflow(-1) fls64(__u64 x)
79433 {
79434 __u32 h = x >> 32;
79435 if (h)
79436@@ -23,7 +23,7 @@ static __always_inline int fls64(__u64 x)
79437 return fls(x);
79438 }
79439 #elif BITS_PER_LONG == 64
79440-static __always_inline int fls64(__u64 x)
79441+static __always_inline int __intentional_overflow(-1) fls64(__u64 x)
79442 {
79443 if (x == 0)
79444 return 0;
79445diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
79446index 1bfcfe5..e04c5c9 100644
79447--- a/include/asm-generic/cache.h
79448+++ b/include/asm-generic/cache.h
79449@@ -6,7 +6,7 @@
79450 * cache lines need to provide their own cache.h.
79451 */
79452
79453-#define L1_CACHE_SHIFT 5
79454-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
79455+#define L1_CACHE_SHIFT 5UL
79456+#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
79457
79458 #endif /* __ASM_GENERIC_CACHE_H */
79459diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
79460index 0d68a1e..b74a761 100644
79461--- a/include/asm-generic/emergency-restart.h
79462+++ b/include/asm-generic/emergency-restart.h
79463@@ -1,7 +1,7 @@
79464 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
79465 #define _ASM_GENERIC_EMERGENCY_RESTART_H
79466
79467-static inline void machine_emergency_restart(void)
79468+static inline __noreturn void machine_emergency_restart(void)
79469 {
79470 machine_restart(NULL);
79471 }
79472diff --git a/include/asm-generic/io.h b/include/asm-generic/io.h
79473index b8fdc57..c6d5a5c 100644
79474--- a/include/asm-generic/io.h
79475+++ b/include/asm-generic/io.h
79476@@ -289,7 +289,7 @@ static inline void pci_iounmap(struct pci_dev *dev, void __iomem *p)
79477 * These are pretty trivial
79478 */
79479 #ifndef virt_to_phys
79480-static inline unsigned long virt_to_phys(volatile void *address)
79481+static inline unsigned long __intentional_overflow(-1) virt_to_phys(volatile void *address)
79482 {
79483 return __pa((unsigned long)address);
79484 }
79485diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
79486index 90f99c7..00ce236 100644
79487--- a/include/asm-generic/kmap_types.h
79488+++ b/include/asm-generic/kmap_types.h
79489@@ -2,9 +2,9 @@
79490 #define _ASM_GENERIC_KMAP_TYPES_H
79491
79492 #ifdef __WITH_KM_FENCE
79493-# define KM_TYPE_NR 41
79494+# define KM_TYPE_NR 42
79495 #else
79496-# define KM_TYPE_NR 20
79497+# define KM_TYPE_NR 21
79498 #endif
79499
79500 #endif
79501diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
79502index 9ceb03b..62b0b8f 100644
79503--- a/include/asm-generic/local.h
79504+++ b/include/asm-generic/local.h
79505@@ -23,24 +23,37 @@ typedef struct
79506 atomic_long_t a;
79507 } local_t;
79508
79509+typedef struct {
79510+ atomic_long_unchecked_t a;
79511+} local_unchecked_t;
79512+
79513 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
79514
79515 #define local_read(l) atomic_long_read(&(l)->a)
79516+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
79517 #define local_set(l,i) atomic_long_set((&(l)->a),(i))
79518+#define local_set_unchecked(l,i) atomic_long_set_unchecked((&(l)->a),(i))
79519 #define local_inc(l) atomic_long_inc(&(l)->a)
79520+#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
79521 #define local_dec(l) atomic_long_dec(&(l)->a)
79522+#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
79523 #define local_add(i,l) atomic_long_add((i),(&(l)->a))
79524+#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
79525 #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
79526+#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
79527
79528 #define local_sub_and_test(i, l) atomic_long_sub_and_test((i), (&(l)->a))
79529 #define local_dec_and_test(l) atomic_long_dec_and_test(&(l)->a)
79530 #define local_inc_and_test(l) atomic_long_inc_and_test(&(l)->a)
79531 #define local_add_negative(i, l) atomic_long_add_negative((i), (&(l)->a))
79532 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
79533+#define local_add_return_unchecked(i, l) atomic_long_add_return_unchecked((i), (&(l)->a))
79534 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
79535 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
79536+#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
79537
79538 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
79539+#define local_cmpxchg_unchecked(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
79540 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
79541 #define local_add_unless(l, _a, u) atomic_long_add_unless((&(l)->a), (_a), (u))
79542 #define local_inc_not_zero(l) atomic_long_inc_not_zero(&(l)->a)
79543diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
79544index 725612b..9cc513a 100644
79545--- a/include/asm-generic/pgtable-nopmd.h
79546+++ b/include/asm-generic/pgtable-nopmd.h
79547@@ -1,14 +1,19 @@
79548 #ifndef _PGTABLE_NOPMD_H
79549 #define _PGTABLE_NOPMD_H
79550
79551-#ifndef __ASSEMBLY__
79552-
79553 #include <asm-generic/pgtable-nopud.h>
79554
79555-struct mm_struct;
79556-
79557 #define __PAGETABLE_PMD_FOLDED
79558
79559+#define PMD_SHIFT PUD_SHIFT
79560+#define PTRS_PER_PMD 1
79561+#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
79562+#define PMD_MASK (~(PMD_SIZE-1))
79563+
79564+#ifndef __ASSEMBLY__
79565+
79566+struct mm_struct;
79567+
79568 /*
79569 * Having the pmd type consist of a pud gets the size right, and allows
79570 * us to conceptually access the pud entry that this pmd is folded into
79571@@ -16,11 +21,6 @@ struct mm_struct;
79572 */
79573 typedef struct { pud_t pud; } pmd_t;
79574
79575-#define PMD_SHIFT PUD_SHIFT
79576-#define PTRS_PER_PMD 1
79577-#define PMD_SIZE (1UL << PMD_SHIFT)
79578-#define PMD_MASK (~(PMD_SIZE-1))
79579-
79580 /*
79581 * The "pud_xxx()" functions here are trivial for a folded two-level
79582 * setup: the pmd is never bad, and a pmd always exists (as it's folded
79583diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
79584index 810431d..0ec4804f 100644
79585--- a/include/asm-generic/pgtable-nopud.h
79586+++ b/include/asm-generic/pgtable-nopud.h
79587@@ -1,10 +1,15 @@
79588 #ifndef _PGTABLE_NOPUD_H
79589 #define _PGTABLE_NOPUD_H
79590
79591-#ifndef __ASSEMBLY__
79592-
79593 #define __PAGETABLE_PUD_FOLDED
79594
79595+#define PUD_SHIFT PGDIR_SHIFT
79596+#define PTRS_PER_PUD 1
79597+#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
79598+#define PUD_MASK (~(PUD_SIZE-1))
79599+
79600+#ifndef __ASSEMBLY__
79601+
79602 /*
79603 * Having the pud type consist of a pgd gets the size right, and allows
79604 * us to conceptually access the pgd entry that this pud is folded into
79605@@ -12,11 +17,6 @@
79606 */
79607 typedef struct { pgd_t pgd; } pud_t;
79608
79609-#define PUD_SHIFT PGDIR_SHIFT
79610-#define PTRS_PER_PUD 1
79611-#define PUD_SIZE (1UL << PUD_SHIFT)
79612-#define PUD_MASK (~(PUD_SIZE-1))
79613-
79614 /*
79615 * The "pgd_xxx()" functions here are trivial for a folded two-level
79616 * setup: the pud is never bad, and a pud always exists (as it's folded
79617@@ -29,6 +29,7 @@ static inline void pgd_clear(pgd_t *pgd) { }
79618 #define pud_ERROR(pud) (pgd_ERROR((pud).pgd))
79619
79620 #define pgd_populate(mm, pgd, pud) do { } while (0)
79621+#define pgd_populate_kernel(mm, pgd, pud) do { } while (0)
79622 /*
79623 * (puds are folded into pgds so this doesn't get actually called,
79624 * but the define is needed for a generic inline function.)
79625diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
79626index 752e30d..87f172d 100644
79627--- a/include/asm-generic/pgtable.h
79628+++ b/include/asm-generic/pgtable.h
79629@@ -828,6 +828,22 @@ static inline void pmdp_set_numa(struct mm_struct *mm, unsigned long addr,
79630 }
79631 #endif /* CONFIG_NUMA_BALANCING */
79632
79633+#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
79634+#ifdef CONFIG_PAX_KERNEXEC
79635+#error KERNEXEC requires pax_open_kernel
79636+#else
79637+static inline unsigned long pax_open_kernel(void) { return 0; }
79638+#endif
79639+#endif
79640+
79641+#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
79642+#ifdef CONFIG_PAX_KERNEXEC
79643+#error KERNEXEC requires pax_close_kernel
79644+#else
79645+static inline unsigned long pax_close_kernel(void) { return 0; }
79646+#endif
79647+#endif
79648+
79649 #endif /* CONFIG_MMU */
79650
79651 #endif /* !__ASSEMBLY__ */
79652diff --git a/include/asm-generic/uaccess.h b/include/asm-generic/uaccess.h
79653index 72d8803..cb9749c 100644
79654--- a/include/asm-generic/uaccess.h
79655+++ b/include/asm-generic/uaccess.h
79656@@ -343,4 +343,20 @@ clear_user(void __user *to, unsigned long n)
79657 return __clear_user(to, n);
79658 }
79659
79660+#ifndef __HAVE_ARCH_PAX_OPEN_USERLAND
79661+#ifdef CONFIG_PAX_MEMORY_UDEREF
79662+#error UDEREF requires pax_open_userland
79663+#else
79664+static inline unsigned long pax_open_userland(void) { return 0; }
79665+#endif
79666+#endif
79667+
79668+#ifndef __HAVE_ARCH_PAX_CLOSE_USERLAND
79669+#ifdef CONFIG_PAX_MEMORY_UDEREF
79670+#error UDEREF requires pax_close_userland
79671+#else
79672+static inline unsigned long pax_close_userland(void) { return 0; }
79673+#endif
79674+#endif
79675+
79676 #endif /* __ASM_GENERIC_UACCESS_H */
79677diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
79678index aa70cbd..fd72c7a 100644
79679--- a/include/asm-generic/vmlinux.lds.h
79680+++ b/include/asm-generic/vmlinux.lds.h
79681@@ -233,6 +233,7 @@
79682 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
79683 VMLINUX_SYMBOL(__start_rodata) = .; \
79684 *(.rodata) *(.rodata.*) \
79685+ *(.data..read_only) \
79686 *(__vermagic) /* Kernel version magic */ \
79687 . = ALIGN(8); \
79688 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
79689@@ -724,17 +725,18 @@
79690 * section in the linker script will go there too. @phdr should have
79691 * a leading colon.
79692 *
79693- * Note that this macros defines __per_cpu_load as an absolute symbol.
79694+ * Note that this macros defines per_cpu_load as an absolute symbol.
79695 * If there is no need to put the percpu section at a predetermined
79696 * address, use PERCPU_SECTION.
79697 */
79698 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
79699- VMLINUX_SYMBOL(__per_cpu_load) = .; \
79700- .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
79701+ per_cpu_load = .; \
79702+ .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
79703 - LOAD_OFFSET) { \
79704+ VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
79705 PERCPU_INPUT(cacheline) \
79706 } phdr \
79707- . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
79708+ . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
79709
79710 /**
79711 * PERCPU_SECTION - define output section for percpu area, simple version
79712diff --git a/include/crypto/algapi.h b/include/crypto/algapi.h
79713index 623a59c..1e79ab9 100644
79714--- a/include/crypto/algapi.h
79715+++ b/include/crypto/algapi.h
79716@@ -34,7 +34,7 @@ struct crypto_type {
79717 unsigned int maskclear;
79718 unsigned int maskset;
79719 unsigned int tfmsize;
79720-};
79721+} __do_const;
79722
79723 struct crypto_instance {
79724 struct crypto_alg alg;
79725diff --git a/include/drm/drmP.h b/include/drm/drmP.h
79726index 53ed876..5bb09be 100644
79727--- a/include/drm/drmP.h
79728+++ b/include/drm/drmP.h
79729@@ -59,6 +59,7 @@
79730
79731 #include <asm/mman.h>
79732 #include <asm/pgalloc.h>
79733+#include <asm/local.h>
79734 #include <asm/uaccess.h>
79735
79736 #include <uapi/drm/drm.h>
79737@@ -223,10 +224,12 @@ void drm_err(const char *func, const char *format, ...);
79738 * \param cmd command.
79739 * \param arg argument.
79740 */
79741-typedef int drm_ioctl_t(struct drm_device *dev, void *data,
79742+typedef int (* const drm_ioctl_t)(struct drm_device *dev, void *data,
79743+ struct drm_file *file_priv);
79744+typedef int (* drm_ioctl_no_const_t)(struct drm_device *dev, void *data,
79745 struct drm_file *file_priv);
79746
79747-typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
79748+typedef int (* const drm_ioctl_compat_t)(struct file *filp, unsigned int cmd,
79749 unsigned long arg);
79750
79751 #define DRM_IOCTL_NR(n) _IOC_NR(n)
79752@@ -242,10 +245,10 @@ typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
79753 struct drm_ioctl_desc {
79754 unsigned int cmd;
79755 int flags;
79756- drm_ioctl_t *func;
79757+ drm_ioctl_t func;
79758 unsigned int cmd_drv;
79759 const char *name;
79760-};
79761+} __do_const;
79762
79763 /**
79764 * Creates a driver or general drm_ioctl_desc array entry for the given
79765@@ -629,7 +632,8 @@ struct drm_info_list {
79766 int (*show)(struct seq_file*, void*); /** show callback */
79767 u32 driver_features; /**< Required driver features for this entry */
79768 void *data;
79769-};
79770+} __do_const;
79771+typedef struct drm_info_list __no_const drm_info_list_no_const;
79772
79773 /**
79774 * debugfs node structure. This structure represents a debugfs file.
79775@@ -713,7 +717,7 @@ struct drm_device {
79776
79777 /** \name Usage Counters */
79778 /*@{ */
79779- int open_count; /**< Outstanding files open, protected by drm_global_mutex. */
79780+ local_t open_count; /**< Outstanding files open, protected by drm_global_mutex. */
79781 spinlock_t buf_lock; /**< For drm_device::buf_use and a few other things. */
79782 int buf_use; /**< Buffers in use -- cannot alloc */
79783 atomic_t buf_alloc; /**< Buffer allocation in progress */
79784diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
79785index a3d75fe..6802f9c 100644
79786--- a/include/drm/drm_crtc_helper.h
79787+++ b/include/drm/drm_crtc_helper.h
79788@@ -109,7 +109,7 @@ struct drm_encoder_helper_funcs {
79789 struct drm_connector *connector);
79790 /* disable encoder when not in use - more explicit than dpms off */
79791 void (*disable)(struct drm_encoder *encoder);
79792-};
79793+} __no_const;
79794
79795 /**
79796 * drm_connector_helper_funcs - helper operations for connectors
79797diff --git a/include/drm/i915_pciids.h b/include/drm/i915_pciids.h
79798index a70d456..6ea07cd 100644
79799--- a/include/drm/i915_pciids.h
79800+++ b/include/drm/i915_pciids.h
79801@@ -37,7 +37,7 @@
79802 */
79803 #define INTEL_VGA_DEVICE(id, info) { \
79804 0x8086, id, \
79805- ~0, ~0, \
79806+ PCI_ANY_ID, PCI_ANY_ID, \
79807 0x030000, 0xff0000, \
79808 (unsigned long) info }
79809
79810diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
79811index 72dcbe8..8db58d7 100644
79812--- a/include/drm/ttm/ttm_memory.h
79813+++ b/include/drm/ttm/ttm_memory.h
79814@@ -48,7 +48,7 @@
79815
79816 struct ttm_mem_shrink {
79817 int (*do_shrink) (struct ttm_mem_shrink *);
79818-};
79819+} __no_const;
79820
79821 /**
79822 * struct ttm_mem_global - Global memory accounting structure.
79823diff --git a/include/drm/ttm/ttm_page_alloc.h b/include/drm/ttm/ttm_page_alloc.h
79824index 49a8284..9643967 100644
79825--- a/include/drm/ttm/ttm_page_alloc.h
79826+++ b/include/drm/ttm/ttm_page_alloc.h
79827@@ -80,6 +80,7 @@ void ttm_dma_page_alloc_fini(void);
79828 */
79829 extern int ttm_dma_page_alloc_debugfs(struct seq_file *m, void *data);
79830
79831+struct device;
79832 extern int ttm_dma_populate(struct ttm_dma_tt *ttm_dma, struct device *dev);
79833 extern void ttm_dma_unpopulate(struct ttm_dma_tt *ttm_dma, struct device *dev);
79834
79835diff --git a/include/keys/asymmetric-subtype.h b/include/keys/asymmetric-subtype.h
79836index 4b840e8..155d235 100644
79837--- a/include/keys/asymmetric-subtype.h
79838+++ b/include/keys/asymmetric-subtype.h
79839@@ -37,7 +37,7 @@ struct asymmetric_key_subtype {
79840 /* Verify the signature on a key of this subtype (optional) */
79841 int (*verify_signature)(const struct key *key,
79842 const struct public_key_signature *sig);
79843-};
79844+} __do_const;
79845
79846 /**
79847 * asymmetric_key_subtype - Get the subtype from an asymmetric key
79848diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
79849index c1da539..1dcec55 100644
79850--- a/include/linux/atmdev.h
79851+++ b/include/linux/atmdev.h
79852@@ -28,7 +28,7 @@ struct compat_atm_iobuf {
79853 #endif
79854
79855 struct k_atm_aal_stats {
79856-#define __HANDLE_ITEM(i) atomic_t i
79857+#define __HANDLE_ITEM(i) atomic_unchecked_t i
79858 __AAL_STAT_ITEMS
79859 #undef __HANDLE_ITEM
79860 };
79861@@ -200,7 +200,7 @@ struct atmdev_ops { /* only send is required */
79862 int (*change_qos)(struct atm_vcc *vcc,struct atm_qos *qos,int flags);
79863 int (*proc_read)(struct atm_dev *dev,loff_t *pos,char *page);
79864 struct module *owner;
79865-};
79866+} __do_const ;
79867
79868 struct atmphy_ops {
79869 int (*start)(struct atm_dev *dev);
79870diff --git a/include/linux/audit.h b/include/linux/audit.h
79871index 10f155b..6c73ffe 100644
79872--- a/include/linux/audit.h
79873+++ b/include/linux/audit.h
79874@@ -219,7 +219,7 @@ static inline void audit_ptrace(struct task_struct *t)
79875 extern unsigned int audit_serial(void);
79876 extern int auditsc_get_stamp(struct audit_context *ctx,
79877 struct timespec *t, unsigned int *serial);
79878-extern int audit_set_loginuid(kuid_t loginuid);
79879+extern int __intentional_overflow(-1) audit_set_loginuid(kuid_t loginuid);
79880
79881 static inline kuid_t audit_get_loginuid(struct task_struct *tsk)
79882 {
79883diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
79884index 61f29e5..e67c658 100644
79885--- a/include/linux/binfmts.h
79886+++ b/include/linux/binfmts.h
79887@@ -44,7 +44,7 @@ struct linux_binprm {
79888 unsigned interp_flags;
79889 unsigned interp_data;
79890 unsigned long loader, exec;
79891-};
79892+} __randomize_layout;
79893
79894 #define BINPRM_FLAGS_ENFORCE_NONDUMP_BIT 0
79895 #define BINPRM_FLAGS_ENFORCE_NONDUMP (1 << BINPRM_FLAGS_ENFORCE_NONDUMP_BIT)
79896@@ -73,8 +73,10 @@ struct linux_binfmt {
79897 int (*load_binary)(struct linux_binprm *);
79898 int (*load_shlib)(struct file *);
79899 int (*core_dump)(struct coredump_params *cprm);
79900+ void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
79901+ void (*handle_mmap)(struct file *);
79902 unsigned long min_coredump; /* minimal dump size */
79903-};
79904+} __do_const __randomize_layout;
79905
79906 extern void __register_binfmt(struct linux_binfmt *fmt, int insert);
79907
79908diff --git a/include/linux/bitops.h b/include/linux/bitops.h
79909index 5d858e0..336c1d9 100644
79910--- a/include/linux/bitops.h
79911+++ b/include/linux/bitops.h
79912@@ -105,7 +105,7 @@ static inline __u64 ror64(__u64 word, unsigned int shift)
79913 * @word: value to rotate
79914 * @shift: bits to roll
79915 */
79916-static inline __u32 rol32(__u32 word, unsigned int shift)
79917+static inline __u32 __intentional_overflow(-1) rol32(__u32 word, unsigned int shift)
79918 {
79919 return (word << shift) | (word >> (32 - shift));
79920 }
79921@@ -115,7 +115,7 @@ static inline __u32 rol32(__u32 word, unsigned int shift)
79922 * @word: value to rotate
79923 * @shift: bits to roll
79924 */
79925-static inline __u32 ror32(__u32 word, unsigned int shift)
79926+static inline __u32 __intentional_overflow(-1) ror32(__u32 word, unsigned int shift)
79927 {
79928 return (word >> shift) | (word << (32 - shift));
79929 }
79930@@ -171,7 +171,7 @@ static inline __s32 sign_extend32(__u32 value, int index)
79931 return (__s32)(value << shift) >> shift;
79932 }
79933
79934-static inline unsigned fls_long(unsigned long l)
79935+static inline unsigned __intentional_overflow(-1) fls_long(unsigned long l)
79936 {
79937 if (sizeof(l) == 4)
79938 return fls(l);
79939diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
79940index aac0f9e..73c9869 100644
79941--- a/include/linux/blkdev.h
79942+++ b/include/linux/blkdev.h
79943@@ -1615,7 +1615,7 @@ struct block_device_operations {
79944 /* this callback is with swap_lock and sometimes page table lock held */
79945 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
79946 struct module *owner;
79947-};
79948+} __do_const;
79949
79950 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
79951 unsigned long);
79952diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
79953index afc1343..9735539 100644
79954--- a/include/linux/blktrace_api.h
79955+++ b/include/linux/blktrace_api.h
79956@@ -25,7 +25,7 @@ struct blk_trace {
79957 struct dentry *dropped_file;
79958 struct dentry *msg_file;
79959 struct list_head running_list;
79960- atomic_t dropped;
79961+ atomic_unchecked_t dropped;
79962 };
79963
79964 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
79965diff --git a/include/linux/cache.h b/include/linux/cache.h
79966index 17e7e82..1d7da26 100644
79967--- a/include/linux/cache.h
79968+++ b/include/linux/cache.h
79969@@ -16,6 +16,14 @@
79970 #define __read_mostly
79971 #endif
79972
79973+#ifndef __read_only
79974+#ifdef CONFIG_PAX_KERNEXEC
79975+#error KERNEXEC requires __read_only
79976+#else
79977+#define __read_only __read_mostly
79978+#endif
79979+#endif
79980+
79981 #ifndef ____cacheline_aligned
79982 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
79983 #endif
79984diff --git a/include/linux/capability.h b/include/linux/capability.h
79985index aa93e5e..985a1b0 100644
79986--- a/include/linux/capability.h
79987+++ b/include/linux/capability.h
79988@@ -214,9 +214,14 @@ extern bool has_ns_capability_noaudit(struct task_struct *t,
79989 extern bool capable(int cap);
79990 extern bool ns_capable(struct user_namespace *ns, int cap);
79991 extern bool capable_wrt_inode_uidgid(const struct inode *inode, int cap);
79992+extern bool capable_wrt_inode_uidgid_nolog(const struct inode *inode, int cap);
79993 extern bool file_ns_capable(const struct file *file, struct user_namespace *ns, int cap);
79994+extern bool capable_nolog(int cap);
79995+extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
79996
79997 /* audit system wants to get cap info from files as well */
79998 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
79999
80000+extern int is_privileged_binary(const struct dentry *dentry);
80001+
80002 #endif /* !_LINUX_CAPABILITY_H */
80003diff --git a/include/linux/cdrom.h b/include/linux/cdrom.h
80004index 8609d57..86e4d79 100644
80005--- a/include/linux/cdrom.h
80006+++ b/include/linux/cdrom.h
80007@@ -87,7 +87,6 @@ struct cdrom_device_ops {
80008
80009 /* driver specifications */
80010 const int capability; /* capability flags */
80011- int n_minors; /* number of active minor devices */
80012 /* handle uniform packets for scsi type devices (scsi,atapi) */
80013 int (*generic_packet) (struct cdrom_device_info *,
80014 struct packet_command *);
80015diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
80016index 4ce9056..86caac6 100644
80017--- a/include/linux/cleancache.h
80018+++ b/include/linux/cleancache.h
80019@@ -31,7 +31,7 @@ struct cleancache_ops {
80020 void (*invalidate_page)(int, struct cleancache_filekey, pgoff_t);
80021 void (*invalidate_inode)(int, struct cleancache_filekey);
80022 void (*invalidate_fs)(int);
80023-};
80024+} __no_const;
80025
80026 extern struct cleancache_ops *
80027 cleancache_register_ops(struct cleancache_ops *ops);
80028diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h
80029index 2839c63..5b06b6b 100644
80030--- a/include/linux/clk-provider.h
80031+++ b/include/linux/clk-provider.h
80032@@ -191,6 +191,7 @@ struct clk_ops {
80033 void (*init)(struct clk_hw *hw);
80034 int (*debug_init)(struct clk_hw *hw, struct dentry *dentry);
80035 };
80036+typedef struct clk_ops __no_const clk_ops_no_const;
80037
80038 /**
80039 * struct clk_init_data - holds init data that's common to all clocks and is
80040diff --git a/include/linux/compat.h b/include/linux/compat.h
80041index e649426..a74047b 100644
80042--- a/include/linux/compat.h
80043+++ b/include/linux/compat.h
80044@@ -316,7 +316,7 @@ compat_sys_get_robust_list(int pid, compat_uptr_t __user *head_ptr,
80045 compat_size_t __user *len_ptr);
80046
80047 asmlinkage long compat_sys_ipc(u32, int, int, u32, compat_uptr_t, u32);
80048-asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg);
80049+asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg) __intentional_overflow(0);
80050 asmlinkage long compat_sys_semctl(int semid, int semnum, int cmd, int arg);
80051 asmlinkage long compat_sys_msgsnd(int msqid, compat_uptr_t msgp,
80052 compat_ssize_t msgsz, int msgflg);
80053@@ -436,7 +436,7 @@ extern int compat_ptrace_request(struct task_struct *child,
80054 extern long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
80055 compat_ulong_t addr, compat_ulong_t data);
80056 asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
80057- compat_long_t addr, compat_long_t data);
80058+ compat_ulong_t addr, compat_ulong_t data);
80059
80060 asmlinkage long compat_sys_lookup_dcookie(u32, u32, char __user *, compat_size_t);
80061 /*
80062diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
80063index d1a5582..4424efa 100644
80064--- a/include/linux/compiler-gcc4.h
80065+++ b/include/linux/compiler-gcc4.h
80066@@ -39,9 +39,34 @@
80067 # define __compiletime_warning(message) __attribute__((warning(message)))
80068 # define __compiletime_error(message) __attribute__((error(message)))
80069 #endif /* __CHECKER__ */
80070+
80071+#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
80072+#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
80073+#define __bos0(ptr) __bos((ptr), 0)
80074+#define __bos1(ptr) __bos((ptr), 1)
80075 #endif /* GCC_VERSION >= 40300 */
80076
80077 #if GCC_VERSION >= 40500
80078+
80079+#ifdef RANDSTRUCT_PLUGIN
80080+#define __randomize_layout __attribute__((randomize_layout))
80081+#define __no_randomize_layout __attribute__((no_randomize_layout))
80082+#endif
80083+
80084+#ifdef CONSTIFY_PLUGIN
80085+#define __no_const __attribute__((no_const))
80086+#define __do_const __attribute__((do_const))
80087+#endif
80088+
80089+#ifdef SIZE_OVERFLOW_PLUGIN
80090+#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
80091+#define __intentional_overflow(...) __attribute__((intentional_overflow(__VA_ARGS__)))
80092+#endif
80093+
80094+#ifdef LATENT_ENTROPY_PLUGIN
80095+#define __latent_entropy __attribute__((latent_entropy))
80096+#endif
80097+
80098 /*
80099 * Mark a position in code as unreachable. This can be used to
80100 * suppress control flow warnings after asm blocks that transfer
80101diff --git a/include/linux/compiler.h b/include/linux/compiler.h
80102index d5ad7b1..3b74638 100644
80103--- a/include/linux/compiler.h
80104+++ b/include/linux/compiler.h
80105@@ -5,11 +5,14 @@
80106
80107 #ifdef __CHECKER__
80108 # define __user __attribute__((noderef, address_space(1)))
80109+# define __force_user __force __user
80110 # define __kernel __attribute__((address_space(0)))
80111+# define __force_kernel __force __kernel
80112 # define __safe __attribute__((safe))
80113 # define __force __attribute__((force))
80114 # define __nocast __attribute__((nocast))
80115 # define __iomem __attribute__((noderef, address_space(2)))
80116+# define __force_iomem __force __iomem
80117 # define __must_hold(x) __attribute__((context(x,1,1)))
80118 # define __acquires(x) __attribute__((context(x,0,1)))
80119 # define __releases(x) __attribute__((context(x,1,0)))
80120@@ -17,20 +20,37 @@
80121 # define __release(x) __context__(x,-1)
80122 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
80123 # define __percpu __attribute__((noderef, address_space(3)))
80124+# define __force_percpu __force __percpu
80125 #ifdef CONFIG_SPARSE_RCU_POINTER
80126 # define __rcu __attribute__((noderef, address_space(4)))
80127+# define __force_rcu __force __rcu
80128 #else
80129 # define __rcu
80130+# define __force_rcu
80131 #endif
80132 extern void __chk_user_ptr(const volatile void __user *);
80133 extern void __chk_io_ptr(const volatile void __iomem *);
80134 #else
80135-# define __user
80136-# define __kernel
80137+# ifdef CHECKER_PLUGIN
80138+//# define __user
80139+//# define __force_user
80140+//# define __kernel
80141+//# define __force_kernel
80142+# else
80143+# ifdef STRUCTLEAK_PLUGIN
80144+# define __user __attribute__((user))
80145+# else
80146+# define __user
80147+# endif
80148+# define __force_user
80149+# define __kernel
80150+# define __force_kernel
80151+# endif
80152 # define __safe
80153 # define __force
80154 # define __nocast
80155 # define __iomem
80156+# define __force_iomem
80157 # define __chk_user_ptr(x) (void)0
80158 # define __chk_io_ptr(x) (void)0
80159 # define __builtin_warning(x, y...) (1)
80160@@ -41,7 +61,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
80161 # define __release(x) (void)0
80162 # define __cond_lock(x,c) (c)
80163 # define __percpu
80164+# define __force_percpu
80165 # define __rcu
80166+# define __force_rcu
80167 #endif
80168
80169 /* Indirect macros required for expanded argument pasting, eg. __LINE__. */
80170@@ -286,6 +308,34 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
80171 # define __attribute_const__ /* unimplemented */
80172 #endif
80173
80174+#ifndef __randomize_layout
80175+# define __randomize_layout
80176+#endif
80177+
80178+#ifndef __no_randomize_layout
80179+# define __no_randomize_layout
80180+#endif
80181+
80182+#ifndef __no_const
80183+# define __no_const
80184+#endif
80185+
80186+#ifndef __do_const
80187+# define __do_const
80188+#endif
80189+
80190+#ifndef __size_overflow
80191+# define __size_overflow(...)
80192+#endif
80193+
80194+#ifndef __intentional_overflow
80195+# define __intentional_overflow(...)
80196+#endif
80197+
80198+#ifndef __latent_entropy
80199+# define __latent_entropy
80200+#endif
80201+
80202 /*
80203 * Tell gcc if a function is cold. The compiler will assume any path
80204 * directly leading to the call is unlikely.
80205@@ -295,6 +345,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
80206 #define __cold
80207 #endif
80208
80209+#ifndef __alloc_size
80210+#define __alloc_size(...)
80211+#endif
80212+
80213+#ifndef __bos
80214+#define __bos(ptr, arg)
80215+#endif
80216+
80217+#ifndef __bos0
80218+#define __bos0(ptr)
80219+#endif
80220+
80221+#ifndef __bos1
80222+#define __bos1(ptr)
80223+#endif
80224+
80225 /* Simple shorthand for a section definition */
80226 #ifndef __section
80227 # define __section(S) __attribute__ ((__section__(#S)))
80228@@ -378,7 +444,8 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
80229 * use is to mediate communication between process-level code and irq/NMI
80230 * handlers, all running on the same CPU.
80231 */
80232-#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
80233+#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
80234+#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
80235
80236 /* Ignore/forbid kprobes attach on very low level functions marked by this attribute: */
80237 #ifdef CONFIG_KPROBES
80238diff --git a/include/linux/completion.h b/include/linux/completion.h
80239index 5d5aaae..0ea9b84 100644
80240--- a/include/linux/completion.h
80241+++ b/include/linux/completion.h
80242@@ -90,16 +90,16 @@ static inline void reinit_completion(struct completion *x)
80243
80244 extern void wait_for_completion(struct completion *);
80245 extern void wait_for_completion_io(struct completion *);
80246-extern int wait_for_completion_interruptible(struct completion *x);
80247-extern int wait_for_completion_killable(struct completion *x);
80248+extern int wait_for_completion_interruptible(struct completion *x) __intentional_overflow(-1);
80249+extern int wait_for_completion_killable(struct completion *x) __intentional_overflow(-1);
80250 extern unsigned long wait_for_completion_timeout(struct completion *x,
80251- unsigned long timeout);
80252+ unsigned long timeout) __intentional_overflow(-1);
80253 extern unsigned long wait_for_completion_io_timeout(struct completion *x,
80254- unsigned long timeout);
80255+ unsigned long timeout) __intentional_overflow(-1);
80256 extern long wait_for_completion_interruptible_timeout(
80257- struct completion *x, unsigned long timeout);
80258+ struct completion *x, unsigned long timeout) __intentional_overflow(-1);
80259 extern long wait_for_completion_killable_timeout(
80260- struct completion *x, unsigned long timeout);
80261+ struct completion *x, unsigned long timeout) __intentional_overflow(-1);
80262 extern bool try_wait_for_completion(struct completion *x);
80263 extern bool completion_done(struct completion *x);
80264
80265diff --git a/include/linux/configfs.h b/include/linux/configfs.h
80266index 34025df..d94bbbc 100644
80267--- a/include/linux/configfs.h
80268+++ b/include/linux/configfs.h
80269@@ -125,7 +125,7 @@ struct configfs_attribute {
80270 const char *ca_name;
80271 struct module *ca_owner;
80272 umode_t ca_mode;
80273-};
80274+} __do_const;
80275
80276 /*
80277 * Users often need to create attribute structures for their configurable
80278diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h
80279index 503b085b..1638c9e 100644
80280--- a/include/linux/cpufreq.h
80281+++ b/include/linux/cpufreq.h
80282@@ -206,6 +206,7 @@ struct global_attr {
80283 ssize_t (*store)(struct kobject *a, struct attribute *b,
80284 const char *c, size_t count);
80285 };
80286+typedef struct global_attr __no_const global_attr_no_const;
80287
80288 #define define_one_global_ro(_name) \
80289 static struct global_attr _name = \
80290@@ -273,7 +274,7 @@ struct cpufreq_driver {
80291 bool boost_supported;
80292 bool boost_enabled;
80293 int (*set_boost) (int state);
80294-};
80295+} __do_const;
80296
80297 /* flags */
80298 #define CPUFREQ_STICKY (1 << 0) /* driver isn't removed even if
80299diff --git a/include/linux/cpuidle.h b/include/linux/cpuidle.h
80300index 25e0df6..952dffd 100644
80301--- a/include/linux/cpuidle.h
80302+++ b/include/linux/cpuidle.h
80303@@ -50,7 +50,8 @@ struct cpuidle_state {
80304 int index);
80305
80306 int (*enter_dead) (struct cpuidle_device *dev, int index);
80307-};
80308+} __do_const;
80309+typedef struct cpuidle_state __no_const cpuidle_state_no_const;
80310
80311 /* Idle State Flags */
80312 #define CPUIDLE_FLAG_TIME_VALID (0x01) /* is residency time measurable? */
80313@@ -209,7 +210,7 @@ struct cpuidle_governor {
80314 void (*reflect) (struct cpuidle_device *dev, int index);
80315
80316 struct module *owner;
80317-};
80318+} __do_const;
80319
80320 #ifdef CONFIG_CPU_IDLE
80321 extern int cpuidle_register_governor(struct cpuidle_governor *gov);
80322diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h
80323index 0a9a6da..ea597ca 100644
80324--- a/include/linux/cpumask.h
80325+++ b/include/linux/cpumask.h
80326@@ -118,17 +118,17 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
80327 }
80328
80329 /* Valid inputs for n are -1 and 0. */
80330-static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
80331+static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
80332 {
80333 return n+1;
80334 }
80335
80336-static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
80337+static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
80338 {
80339 return n+1;
80340 }
80341
80342-static inline unsigned int cpumask_next_and(int n,
80343+static inline unsigned int __intentional_overflow(-1) cpumask_next_and(int n,
80344 const struct cpumask *srcp,
80345 const struct cpumask *andp)
80346 {
80347@@ -174,7 +174,7 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
80348 *
80349 * Returns >= nr_cpu_ids if no further cpus set.
80350 */
80351-static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
80352+static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
80353 {
80354 /* -1 is a legal arg here. */
80355 if (n != -1)
80356@@ -189,7 +189,7 @@ static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
80357 *
80358 * Returns >= nr_cpu_ids if no further cpus unset.
80359 */
80360-static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
80361+static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
80362 {
80363 /* -1 is a legal arg here. */
80364 if (n != -1)
80365@@ -197,7 +197,7 @@ static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
80366 return find_next_zero_bit(cpumask_bits(srcp), nr_cpumask_bits, n+1);
80367 }
80368
80369-int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *);
80370+int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *) __intentional_overflow(-1);
80371 int cpumask_any_but(const struct cpumask *mask, unsigned int cpu);
80372 int cpumask_set_cpu_local_first(int i, int numa_node, cpumask_t *dstp);
80373
80374diff --git a/include/linux/cred.h b/include/linux/cred.h
80375index 2fb2ca2..d6a3340 100644
80376--- a/include/linux/cred.h
80377+++ b/include/linux/cred.h
80378@@ -35,7 +35,7 @@ struct group_info {
80379 int nblocks;
80380 kgid_t small_block[NGROUPS_SMALL];
80381 kgid_t *blocks[0];
80382-};
80383+} __randomize_layout;
80384
80385 /**
80386 * get_group_info - Get a reference to a group info structure
80387@@ -137,7 +137,7 @@ struct cred {
80388 struct user_namespace *user_ns; /* user_ns the caps and keyrings are relative to. */
80389 struct group_info *group_info; /* supplementary groups for euid/fsgid */
80390 struct rcu_head rcu; /* RCU deletion hook */
80391-};
80392+} __randomize_layout;
80393
80394 extern void __put_cred(struct cred *);
80395 extern void exit_creds(struct task_struct *);
80396@@ -195,6 +195,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
80397 static inline void validate_process_creds(void)
80398 {
80399 }
80400+static inline void validate_task_creds(struct task_struct *task)
80401+{
80402+}
80403 #endif
80404
80405 /**
80406@@ -332,6 +335,7 @@ static inline void put_cred(const struct cred *_cred)
80407
80408 #define task_uid(task) (task_cred_xxx((task), uid))
80409 #define task_euid(task) (task_cred_xxx((task), euid))
80410+#define task_securebits(task) (task_cred_xxx((task), securebits))
80411
80412 #define current_cred_xxx(xxx) \
80413 ({ \
80414diff --git a/include/linux/crypto.h b/include/linux/crypto.h
80415index d45e949..51cf5ea 100644
80416--- a/include/linux/crypto.h
80417+++ b/include/linux/crypto.h
80418@@ -373,7 +373,7 @@ struct cipher_tfm {
80419 const u8 *key, unsigned int keylen);
80420 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
80421 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
80422-};
80423+} __no_const;
80424
80425 struct hash_tfm {
80426 int (*init)(struct hash_desc *desc);
80427@@ -394,13 +394,13 @@ struct compress_tfm {
80428 int (*cot_decompress)(struct crypto_tfm *tfm,
80429 const u8 *src, unsigned int slen,
80430 u8 *dst, unsigned int *dlen);
80431-};
80432+} __no_const;
80433
80434 struct rng_tfm {
80435 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
80436 unsigned int dlen);
80437 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
80438-};
80439+} __no_const;
80440
80441 #define crt_ablkcipher crt_u.ablkcipher
80442 #define crt_aead crt_u.aead
80443diff --git a/include/linux/ctype.h b/include/linux/ctype.h
80444index 653589e..4ef254a 100644
80445--- a/include/linux/ctype.h
80446+++ b/include/linux/ctype.h
80447@@ -56,7 +56,7 @@ static inline unsigned char __toupper(unsigned char c)
80448 * Fast implementation of tolower() for internal usage. Do not use in your
80449 * code.
80450 */
80451-static inline char _tolower(const char c)
80452+static inline unsigned char _tolower(const unsigned char c)
80453 {
80454 return c | 0x20;
80455 }
80456diff --git a/include/linux/dcache.h b/include/linux/dcache.h
80457index 1c2f1b8..c67151e 100644
80458--- a/include/linux/dcache.h
80459+++ b/include/linux/dcache.h
80460@@ -133,7 +133,7 @@ struct dentry {
80461 struct hlist_node d_alias; /* inode alias list */
80462 struct rcu_head d_rcu;
80463 } d_u;
80464-};
80465+} __randomize_layout;
80466
80467 /*
80468 * dentry->d_lock spinlock nesting subclasses:
80469diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
80470index 7925bf0..d5143d2 100644
80471--- a/include/linux/decompress/mm.h
80472+++ b/include/linux/decompress/mm.h
80473@@ -77,7 +77,7 @@ static void free(void *where)
80474 * warnings when not needed (indeed large_malloc / large_free are not
80475 * needed by inflate */
80476
80477-#define malloc(a) kmalloc(a, GFP_KERNEL)
80478+#define malloc(a) kmalloc((a), GFP_KERNEL)
80479 #define free(a) kfree(a)
80480
80481 #define large_malloc(a) vmalloc(a)
80482diff --git a/include/linux/devfreq.h b/include/linux/devfreq.h
80483index f1863dc..5c26074 100644
80484--- a/include/linux/devfreq.h
80485+++ b/include/linux/devfreq.h
80486@@ -114,7 +114,7 @@ struct devfreq_governor {
80487 int (*get_target_freq)(struct devfreq *this, unsigned long *freq);
80488 int (*event_handler)(struct devfreq *devfreq,
80489 unsigned int event, void *data);
80490-};
80491+} __do_const;
80492
80493 /**
80494 * struct devfreq - Device devfreq structure
80495diff --git a/include/linux/device.h b/include/linux/device.h
80496index ce1f2160..189bc33 100644
80497--- a/include/linux/device.h
80498+++ b/include/linux/device.h
80499@@ -311,7 +311,7 @@ struct subsys_interface {
80500 struct list_head node;
80501 int (*add_dev)(struct device *dev, struct subsys_interface *sif);
80502 int (*remove_dev)(struct device *dev, struct subsys_interface *sif);
80503-};
80504+} __do_const;
80505
80506 int subsys_interface_register(struct subsys_interface *sif);
80507 void subsys_interface_unregister(struct subsys_interface *sif);
80508@@ -507,7 +507,7 @@ struct device_type {
80509 void (*release)(struct device *dev);
80510
80511 const struct dev_pm_ops *pm;
80512-};
80513+} __do_const;
80514
80515 /* interface for exporting device attributes */
80516 struct device_attribute {
80517@@ -517,11 +517,12 @@ struct device_attribute {
80518 ssize_t (*store)(struct device *dev, struct device_attribute *attr,
80519 const char *buf, size_t count);
80520 };
80521+typedef struct device_attribute __no_const device_attribute_no_const;
80522
80523 struct dev_ext_attribute {
80524 struct device_attribute attr;
80525 void *var;
80526-};
80527+} __do_const;
80528
80529 ssize_t device_show_ulong(struct device *dev, struct device_attribute *attr,
80530 char *buf);
80531diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
80532index d5d3881..7ed54af 100644
80533--- a/include/linux/dma-mapping.h
80534+++ b/include/linux/dma-mapping.h
80535@@ -60,7 +60,7 @@ struct dma_map_ops {
80536 u64 (*get_required_mask)(struct device *dev);
80537 #endif
80538 int is_phys;
80539-};
80540+} __do_const;
80541
80542 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
80543
80544diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
80545index 653a1fd..9133cd1 100644
80546--- a/include/linux/dmaengine.h
80547+++ b/include/linux/dmaengine.h
80548@@ -1136,9 +1136,9 @@ struct dma_pinned_list {
80549 struct dma_pinned_list *dma_pin_iovec_pages(struct iovec *iov, size_t len);
80550 void dma_unpin_iovec_pages(struct dma_pinned_list* pinned_list);
80551
80552-dma_cookie_t dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
80553+dma_cookie_t __intentional_overflow(0) dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
80554 struct dma_pinned_list *pinned_list, unsigned char *kdata, size_t len);
80555-dma_cookie_t dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
80556+dma_cookie_t __intentional_overflow(0) dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
80557 struct dma_pinned_list *pinned_list, struct page *page,
80558 unsigned int offset, size_t len);
80559
80560diff --git a/include/linux/efi.h b/include/linux/efi.h
80561index 0949f9c..04cb9a5 100644
80562--- a/include/linux/efi.h
80563+++ b/include/linux/efi.h
80564@@ -1050,6 +1050,7 @@ struct efivar_operations {
80565 efi_set_variable_nonblocking_t *set_variable_nonblocking;
80566 efi_query_variable_store_t *query_variable_store;
80567 };
80568+typedef struct efivar_operations __no_const efivar_operations_no_const;
80569
80570 struct efivars {
80571 /*
80572diff --git a/include/linux/elf.h b/include/linux/elf.h
80573index 67a5fa7..b817372 100644
80574--- a/include/linux/elf.h
80575+++ b/include/linux/elf.h
80576@@ -24,6 +24,7 @@ extern Elf32_Dyn _DYNAMIC [];
80577 #define elf_note elf32_note
80578 #define elf_addr_t Elf32_Off
80579 #define Elf_Half Elf32_Half
80580+#define elf_dyn Elf32_Dyn
80581
80582 #else
80583
80584@@ -34,6 +35,7 @@ extern Elf64_Dyn _DYNAMIC [];
80585 #define elf_note elf64_note
80586 #define elf_addr_t Elf64_Off
80587 #define Elf_Half Elf64_Half
80588+#define elf_dyn Elf64_Dyn
80589
80590 #endif
80591
80592diff --git a/include/linux/err.h b/include/linux/err.h
80593index a729120..6ede2c9 100644
80594--- a/include/linux/err.h
80595+++ b/include/linux/err.h
80596@@ -20,12 +20,12 @@
80597
80598 #define IS_ERR_VALUE(x) unlikely((x) >= (unsigned long)-MAX_ERRNO)
80599
80600-static inline void * __must_check ERR_PTR(long error)
80601+static inline void * __must_check __intentional_overflow(-1) ERR_PTR(long error)
80602 {
80603 return (void *) error;
80604 }
80605
80606-static inline long __must_check PTR_ERR(__force const void *ptr)
80607+static inline long __must_check __intentional_overflow(-1) PTR_ERR(__force const void *ptr)
80608 {
80609 return (long) ptr;
80610 }
80611diff --git a/include/linux/extcon.h b/include/linux/extcon.h
80612index 36f49c4..a2a1f4c 100644
80613--- a/include/linux/extcon.h
80614+++ b/include/linux/extcon.h
80615@@ -135,7 +135,7 @@ struct extcon_dev {
80616 /* /sys/class/extcon/.../mutually_exclusive/... */
80617 struct attribute_group attr_g_muex;
80618 struct attribute **attrs_muex;
80619- struct device_attribute *d_attrs_muex;
80620+ device_attribute_no_const *d_attrs_muex;
80621 };
80622
80623 /**
80624diff --git a/include/linux/fb.h b/include/linux/fb.h
80625index 09bb7a1..d98870a 100644
80626--- a/include/linux/fb.h
80627+++ b/include/linux/fb.h
80628@@ -305,7 +305,7 @@ struct fb_ops {
80629 /* called at KDB enter and leave time to prepare the console */
80630 int (*fb_debug_enter)(struct fb_info *info);
80631 int (*fb_debug_leave)(struct fb_info *info);
80632-};
80633+} __do_const;
80634
80635 #ifdef CONFIG_FB_TILEBLITTING
80636 #define FB_TILE_CURSOR_NONE 0
80637diff --git a/include/linux/fdtable.h b/include/linux/fdtable.h
80638index 230f87b..1fd0485 100644
80639--- a/include/linux/fdtable.h
80640+++ b/include/linux/fdtable.h
80641@@ -100,7 +100,7 @@ struct files_struct *get_files_struct(struct task_struct *);
80642 void put_files_struct(struct files_struct *fs);
80643 void reset_files_struct(struct files_struct *);
80644 int unshare_files(struct files_struct **);
80645-struct files_struct *dup_fd(struct files_struct *, int *);
80646+struct files_struct *dup_fd(struct files_struct *, int *) __latent_entropy;
80647 void do_close_on_exec(struct files_struct *);
80648 int iterate_fd(struct files_struct *, unsigned,
80649 int (*)(const void *, struct file *, unsigned),
80650diff --git a/include/linux/frontswap.h b/include/linux/frontswap.h
80651index 8293262..2b3b8bd 100644
80652--- a/include/linux/frontswap.h
80653+++ b/include/linux/frontswap.h
80654@@ -11,7 +11,7 @@ struct frontswap_ops {
80655 int (*load)(unsigned, pgoff_t, struct page *);
80656 void (*invalidate_page)(unsigned, pgoff_t);
80657 void (*invalidate_area)(unsigned);
80658-};
80659+} __no_const;
80660
80661 extern bool frontswap_enabled;
80662 extern struct frontswap_ops *
80663diff --git a/include/linux/fs.h b/include/linux/fs.h
80664index 9ab779e..0c636f2 100644
80665--- a/include/linux/fs.h
80666+++ b/include/linux/fs.h
80667@@ -412,7 +412,7 @@ struct address_space {
80668 spinlock_t private_lock; /* for use by the address_space */
80669 struct list_head private_list; /* ditto */
80670 void *private_data; /* ditto */
80671-} __attribute__((aligned(sizeof(long))));
80672+} __attribute__((aligned(sizeof(long)))) __randomize_layout;
80673 /*
80674 * On most architectures that alignment is already the case; but
80675 * must be enforced here for CRIS, to let the least significant bit
80676@@ -455,7 +455,7 @@ struct block_device {
80677 int bd_fsfreeze_count;
80678 /* Mutex for freeze */
80679 struct mutex bd_fsfreeze_mutex;
80680-};
80681+} __randomize_layout;
80682
80683 /*
80684 * Radix-tree tags, for tagging dirty and writeback pages within the pagecache
80685@@ -624,7 +624,7 @@ struct inode {
80686 #endif
80687
80688 void *i_private; /* fs or device private pointer */
80689-};
80690+} __randomize_layout;
80691
80692 static inline int inode_unhashed(struct inode *inode)
80693 {
80694@@ -820,7 +820,7 @@ struct file {
80695 struct list_head f_tfile_llink;
80696 #endif /* #ifdef CONFIG_EPOLL */
80697 struct address_space *f_mapping;
80698-} __attribute__((aligned(4))); /* lest something weird decides that 2 is OK */
80699+} __attribute__((aligned(4))) __randomize_layout; /* lest something weird decides that 2 is OK */
80700
80701 struct file_handle {
80702 __u32 handle_bytes;
80703@@ -945,7 +945,7 @@ struct file_lock {
80704 int state; /* state of grant or error if -ve */
80705 } afs;
80706 } fl_u;
80707-};
80708+} __randomize_layout;
80709
80710 /* The following constant reflects the upper bound of the file/locking space */
80711 #ifndef OFFSET_MAX
80712@@ -1287,7 +1287,7 @@ struct super_block {
80713 * Indicates how deep in a filesystem stack this SB is
80714 */
80715 int s_stack_depth;
80716-};
80717+} __randomize_layout;
80718
80719 extern struct timespec current_fs_time(struct super_block *sb);
80720
80721@@ -1514,7 +1514,8 @@ struct file_operations {
80722 long (*fallocate)(struct file *file, int mode, loff_t offset,
80723 loff_t len);
80724 int (*show_fdinfo)(struct seq_file *m, struct file *f);
80725-};
80726+} __do_const __randomize_layout;
80727+typedef struct file_operations __no_const file_operations_no_const;
80728
80729 struct inode_operations {
80730 struct dentry * (*lookup) (struct inode *,struct dentry *, unsigned int);
80731@@ -2823,4 +2824,14 @@ static inline bool dir_relax(struct inode *inode)
80732 return !IS_DEADDIR(inode);
80733 }
80734
80735+static inline bool is_sidechannel_device(const struct inode *inode)
80736+{
80737+#ifdef CONFIG_GRKERNSEC_DEVICE_SIDECHANNEL
80738+ umode_t mode = inode->i_mode;
80739+ return ((S_ISCHR(mode) || S_ISBLK(mode)) && (mode & (S_IROTH | S_IWOTH)));
80740+#else
80741+ return false;
80742+#endif
80743+}
80744+
80745 #endif /* _LINUX_FS_H */
80746diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
80747index 0efc3e6..fd23610 100644
80748--- a/include/linux/fs_struct.h
80749+++ b/include/linux/fs_struct.h
80750@@ -6,13 +6,13 @@
80751 #include <linux/seqlock.h>
80752
80753 struct fs_struct {
80754- int users;
80755+ atomic_t users;
80756 spinlock_t lock;
80757 seqcount_t seq;
80758 int umask;
80759 int in_exec;
80760 struct path root, pwd;
80761-};
80762+} __randomize_layout;
80763
80764 extern struct kmem_cache *fs_cachep;
80765
80766diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
80767index 7714849..a4a5c7a 100644
80768--- a/include/linux/fscache-cache.h
80769+++ b/include/linux/fscache-cache.h
80770@@ -113,7 +113,7 @@ struct fscache_operation {
80771 fscache_operation_release_t release;
80772 };
80773
80774-extern atomic_t fscache_op_debug_id;
80775+extern atomic_unchecked_t fscache_op_debug_id;
80776 extern void fscache_op_work_func(struct work_struct *work);
80777
80778 extern void fscache_enqueue_operation(struct fscache_operation *);
80779@@ -135,7 +135,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
80780 INIT_WORK(&op->work, fscache_op_work_func);
80781 atomic_set(&op->usage, 1);
80782 op->state = FSCACHE_OP_ST_INITIALISED;
80783- op->debug_id = atomic_inc_return(&fscache_op_debug_id);
80784+ op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
80785 op->processor = processor;
80786 op->release = release;
80787 INIT_LIST_HEAD(&op->pend_link);
80788diff --git a/include/linux/fscache.h b/include/linux/fscache.h
80789index 115bb81..e7b812b 100644
80790--- a/include/linux/fscache.h
80791+++ b/include/linux/fscache.h
80792@@ -152,7 +152,7 @@ struct fscache_cookie_def {
80793 * - this is mandatory for any object that may have data
80794 */
80795 void (*now_uncached)(void *cookie_netfs_data);
80796-};
80797+} __do_const;
80798
80799 /*
80800 * fscache cached network filesystem type
80801diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
80802index 1c804b0..1432c2b 100644
80803--- a/include/linux/fsnotify.h
80804+++ b/include/linux/fsnotify.h
80805@@ -195,6 +195,9 @@ static inline void fsnotify_access(struct file *file)
80806 struct inode *inode = file_inode(file);
80807 __u32 mask = FS_ACCESS;
80808
80809+ if (is_sidechannel_device(inode))
80810+ return;
80811+
80812 if (S_ISDIR(inode->i_mode))
80813 mask |= FS_ISDIR;
80814
80815@@ -213,6 +216,9 @@ static inline void fsnotify_modify(struct file *file)
80816 struct inode *inode = file_inode(file);
80817 __u32 mask = FS_MODIFY;
80818
80819+ if (is_sidechannel_device(inode))
80820+ return;
80821+
80822 if (S_ISDIR(inode->i_mode))
80823 mask |= FS_ISDIR;
80824
80825@@ -315,7 +321,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
80826 */
80827 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
80828 {
80829- return kstrdup(name, GFP_KERNEL);
80830+ return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
80831 }
80832
80833 /*
80834diff --git a/include/linux/genhd.h b/include/linux/genhd.h
80835index ec274e0..e678159 100644
80836--- a/include/linux/genhd.h
80837+++ b/include/linux/genhd.h
80838@@ -194,7 +194,7 @@ struct gendisk {
80839 struct kobject *slave_dir;
80840
80841 struct timer_rand_state *random;
80842- atomic_t sync_io; /* RAID */
80843+ atomic_unchecked_t sync_io; /* RAID */
80844 struct disk_events *ev;
80845 #ifdef CONFIG_BLK_DEV_INTEGRITY
80846 struct blk_integrity *integrity;
80847@@ -435,7 +435,7 @@ extern void disk_flush_events(struct gendisk *disk, unsigned int mask);
80848 extern unsigned int disk_clear_events(struct gendisk *disk, unsigned int mask);
80849
80850 /* drivers/char/random.c */
80851-extern void add_disk_randomness(struct gendisk *disk);
80852+extern void add_disk_randomness(struct gendisk *disk) __latent_entropy;
80853 extern void rand_initialize_disk(struct gendisk *disk);
80854
80855 static inline sector_t get_start_sect(struct block_device *bdev)
80856diff --git a/include/linux/genl_magic_func.h b/include/linux/genl_magic_func.h
80857index 667c311..abac2a7 100644
80858--- a/include/linux/genl_magic_func.h
80859+++ b/include/linux/genl_magic_func.h
80860@@ -246,7 +246,7 @@ const char *CONCAT_(GENL_MAGIC_FAMILY, _genl_cmd_to_str)(__u8 cmd)
80861 },
80862
80863 #define ZZZ_genl_ops CONCAT_(GENL_MAGIC_FAMILY, _genl_ops)
80864-static struct genl_ops ZZZ_genl_ops[] __read_mostly = {
80865+static struct genl_ops ZZZ_genl_ops[] = {
80866 #include GENL_MAGIC_INCLUDE_FILE
80867 };
80868
80869diff --git a/include/linux/gfp.h b/include/linux/gfp.h
80870index 41b30fd..a3718cf 100644
80871--- a/include/linux/gfp.h
80872+++ b/include/linux/gfp.h
80873@@ -34,6 +34,13 @@ struct vm_area_struct;
80874 #define ___GFP_NO_KSWAPD 0x400000u
80875 #define ___GFP_OTHER_NODE 0x800000u
80876 #define ___GFP_WRITE 0x1000000u
80877+
80878+#ifdef CONFIG_PAX_USERCOPY_SLABS
80879+#define ___GFP_USERCOPY 0x2000000u
80880+#else
80881+#define ___GFP_USERCOPY 0
80882+#endif
80883+
80884 /* If the above are modified, __GFP_BITS_SHIFT may need updating */
80885
80886 /*
80887@@ -90,6 +97,7 @@ struct vm_area_struct;
80888 #define __GFP_NO_KSWAPD ((__force gfp_t)___GFP_NO_KSWAPD)
80889 #define __GFP_OTHER_NODE ((__force gfp_t)___GFP_OTHER_NODE) /* On behalf of other node */
80890 #define __GFP_WRITE ((__force gfp_t)___GFP_WRITE) /* Allocator intends to dirty page */
80891+#define __GFP_USERCOPY ((__force gfp_t)___GFP_USERCOPY)/* Allocator intends to copy page to/from userland */
80892
80893 /*
80894 * This may seem redundant, but it's a way of annotating false positives vs.
80895@@ -97,7 +105,7 @@ struct vm_area_struct;
80896 */
80897 #define __GFP_NOTRACK_FALSE_POSITIVE (__GFP_NOTRACK)
80898
80899-#define __GFP_BITS_SHIFT 25 /* Room for N __GFP_FOO bits */
80900+#define __GFP_BITS_SHIFT 26 /* Room for N __GFP_FOO bits */
80901 #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))
80902
80903 /* This equals 0, but use constants in case they ever change */
80904@@ -155,6 +163,8 @@ struct vm_area_struct;
80905 /* 4GB DMA on some platforms */
80906 #define GFP_DMA32 __GFP_DMA32
80907
80908+#define GFP_USERCOPY __GFP_USERCOPY
80909+
80910 /* Convert GFP flags to their corresponding migrate type */
80911 static inline int gfpflags_to_migratetype(const gfp_t gfp_flags)
80912 {
80913diff --git a/include/linux/gracl.h b/include/linux/gracl.h
80914new file mode 100644
80915index 0000000..edb2cb6
80916--- /dev/null
80917+++ b/include/linux/gracl.h
80918@@ -0,0 +1,340 @@
80919+#ifndef GR_ACL_H
80920+#define GR_ACL_H
80921+
80922+#include <linux/grdefs.h>
80923+#include <linux/resource.h>
80924+#include <linux/capability.h>
80925+#include <linux/dcache.h>
80926+#include <asm/resource.h>
80927+
80928+/* Major status information */
80929+
80930+#define GR_VERSION "grsecurity 3.0"
80931+#define GRSECURITY_VERSION 0x3000
80932+
80933+enum {
80934+ GR_SHUTDOWN = 0,
80935+ GR_ENABLE = 1,
80936+ GR_SPROLE = 2,
80937+ GR_OLDRELOAD = 3,
80938+ GR_SEGVMOD = 4,
80939+ GR_STATUS = 5,
80940+ GR_UNSPROLE = 6,
80941+ GR_PASSSET = 7,
80942+ GR_SPROLEPAM = 8,
80943+ GR_RELOAD = 9,
80944+};
80945+
80946+/* Password setup definitions
80947+ * kernel/grhash.c */
80948+enum {
80949+ GR_PW_LEN = 128,
80950+ GR_SALT_LEN = 16,
80951+ GR_SHA_LEN = 32,
80952+};
80953+
80954+enum {
80955+ GR_SPROLE_LEN = 64,
80956+};
80957+
80958+enum {
80959+ GR_NO_GLOB = 0,
80960+ GR_REG_GLOB,
80961+ GR_CREATE_GLOB
80962+};
80963+
80964+#define GR_NLIMITS 32
80965+
80966+/* Begin Data Structures */
80967+
80968+struct sprole_pw {
80969+ unsigned char *rolename;
80970+ unsigned char salt[GR_SALT_LEN];
80971+ unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
80972+};
80973+
80974+struct name_entry {
80975+ __u32 key;
80976+ ino_t inode;
80977+ dev_t device;
80978+ char *name;
80979+ __u16 len;
80980+ __u8 deleted;
80981+ struct name_entry *prev;
80982+ struct name_entry *next;
80983+};
80984+
80985+struct inodev_entry {
80986+ struct name_entry *nentry;
80987+ struct inodev_entry *prev;
80988+ struct inodev_entry *next;
80989+};
80990+
80991+struct acl_role_db {
80992+ struct acl_role_label **r_hash;
80993+ __u32 r_size;
80994+};
80995+
80996+struct inodev_db {
80997+ struct inodev_entry **i_hash;
80998+ __u32 i_size;
80999+};
81000+
81001+struct name_db {
81002+ struct name_entry **n_hash;
81003+ __u32 n_size;
81004+};
81005+
81006+struct crash_uid {
81007+ uid_t uid;
81008+ unsigned long expires;
81009+};
81010+
81011+struct gr_hash_struct {
81012+ void **table;
81013+ void **nametable;
81014+ void *first;
81015+ __u32 table_size;
81016+ __u32 used_size;
81017+ int type;
81018+};
81019+
81020+/* Userspace Grsecurity ACL data structures */
81021+
81022+struct acl_subject_label {
81023+ char *filename;
81024+ ino_t inode;
81025+ dev_t device;
81026+ __u32 mode;
81027+ kernel_cap_t cap_mask;
81028+ kernel_cap_t cap_lower;
81029+ kernel_cap_t cap_invert_audit;
81030+
81031+ struct rlimit res[GR_NLIMITS];
81032+ __u32 resmask;
81033+
81034+ __u8 user_trans_type;
81035+ __u8 group_trans_type;
81036+ uid_t *user_transitions;
81037+ gid_t *group_transitions;
81038+ __u16 user_trans_num;
81039+ __u16 group_trans_num;
81040+
81041+ __u32 sock_families[2];
81042+ __u32 ip_proto[8];
81043+ __u32 ip_type;
81044+ struct acl_ip_label **ips;
81045+ __u32 ip_num;
81046+ __u32 inaddr_any_override;
81047+
81048+ __u32 crashes;
81049+ unsigned long expires;
81050+
81051+ struct acl_subject_label *parent_subject;
81052+ struct gr_hash_struct *hash;
81053+ struct acl_subject_label *prev;
81054+ struct acl_subject_label *next;
81055+
81056+ struct acl_object_label **obj_hash;
81057+ __u32 obj_hash_size;
81058+ __u16 pax_flags;
81059+};
81060+
81061+struct role_allowed_ip {
81062+ __u32 addr;
81063+ __u32 netmask;
81064+
81065+ struct role_allowed_ip *prev;
81066+ struct role_allowed_ip *next;
81067+};
81068+
81069+struct role_transition {
81070+ char *rolename;
81071+
81072+ struct role_transition *prev;
81073+ struct role_transition *next;
81074+};
81075+
81076+struct acl_role_label {
81077+ char *rolename;
81078+ uid_t uidgid;
81079+ __u16 roletype;
81080+
81081+ __u16 auth_attempts;
81082+ unsigned long expires;
81083+
81084+ struct acl_subject_label *root_label;
81085+ struct gr_hash_struct *hash;
81086+
81087+ struct acl_role_label *prev;
81088+ struct acl_role_label *next;
81089+
81090+ struct role_transition *transitions;
81091+ struct role_allowed_ip *allowed_ips;
81092+ uid_t *domain_children;
81093+ __u16 domain_child_num;
81094+
81095+ umode_t umask;
81096+
81097+ struct acl_subject_label **subj_hash;
81098+ __u32 subj_hash_size;
81099+};
81100+
81101+struct user_acl_role_db {
81102+ struct acl_role_label **r_table;
81103+ __u32 num_pointers; /* Number of allocations to track */
81104+ __u32 num_roles; /* Number of roles */
81105+ __u32 num_domain_children; /* Number of domain children */
81106+ __u32 num_subjects; /* Number of subjects */
81107+ __u32 num_objects; /* Number of objects */
81108+};
81109+
81110+struct acl_object_label {
81111+ char *filename;
81112+ ino_t inode;
81113+ dev_t device;
81114+ __u32 mode;
81115+
81116+ struct acl_subject_label *nested;
81117+ struct acl_object_label *globbed;
81118+
81119+ /* next two structures not used */
81120+
81121+ struct acl_object_label *prev;
81122+ struct acl_object_label *next;
81123+};
81124+
81125+struct acl_ip_label {
81126+ char *iface;
81127+ __u32 addr;
81128+ __u32 netmask;
81129+ __u16 low, high;
81130+ __u8 mode;
81131+ __u32 type;
81132+ __u32 proto[8];
81133+
81134+ /* next two structures not used */
81135+
81136+ struct acl_ip_label *prev;
81137+ struct acl_ip_label *next;
81138+};
81139+
81140+struct gr_arg {
81141+ struct user_acl_role_db role_db;
81142+ unsigned char pw[GR_PW_LEN];
81143+ unsigned char salt[GR_SALT_LEN];
81144+ unsigned char sum[GR_SHA_LEN];
81145+ unsigned char sp_role[GR_SPROLE_LEN];
81146+ struct sprole_pw *sprole_pws;
81147+ dev_t segv_device;
81148+ ino_t segv_inode;
81149+ uid_t segv_uid;
81150+ __u16 num_sprole_pws;
81151+ __u16 mode;
81152+};
81153+
81154+struct gr_arg_wrapper {
81155+ struct gr_arg *arg;
81156+ __u32 version;
81157+ __u32 size;
81158+};
81159+
81160+struct subject_map {
81161+ struct acl_subject_label *user;
81162+ struct acl_subject_label *kernel;
81163+ struct subject_map *prev;
81164+ struct subject_map *next;
81165+};
81166+
81167+struct acl_subj_map_db {
81168+ struct subject_map **s_hash;
81169+ __u32 s_size;
81170+};
81171+
81172+struct gr_policy_state {
81173+ struct sprole_pw **acl_special_roles;
81174+ __u16 num_sprole_pws;
81175+ struct acl_role_label *kernel_role;
81176+ struct acl_role_label *role_list;
81177+ struct acl_role_label *default_role;
81178+ struct acl_role_db acl_role_set;
81179+ struct acl_subj_map_db subj_map_set;
81180+ struct name_db name_set;
81181+ struct inodev_db inodev_set;
81182+};
81183+
81184+struct gr_alloc_state {
81185+ unsigned long alloc_stack_next;
81186+ unsigned long alloc_stack_size;
81187+ void **alloc_stack;
81188+};
81189+
81190+struct gr_reload_state {
81191+ struct gr_policy_state oldpolicy;
81192+ struct gr_alloc_state oldalloc;
81193+ struct gr_policy_state newpolicy;
81194+ struct gr_alloc_state newalloc;
81195+ struct gr_policy_state *oldpolicy_ptr;
81196+ struct gr_alloc_state *oldalloc_ptr;
81197+ unsigned char oldmode;
81198+};
81199+
81200+/* End Data Structures Section */
81201+
81202+/* Hash functions generated by empirical testing by Brad Spengler
81203+ Makes good use of the low bits of the inode. Generally 0-1 times
81204+ in loop for successful match. 0-3 for unsuccessful match.
81205+ Shift/add algorithm with modulus of table size and an XOR*/
81206+
81207+static __inline__ unsigned int
81208+gr_rhash(const uid_t uid, const __u16 type, const unsigned int sz)
81209+{
81210+ return ((((uid + type) << (16 + type)) ^ uid) % sz);
81211+}
81212+
81213+ static __inline__ unsigned int
81214+gr_shash(const struct acl_subject_label *userp, const unsigned int sz)
81215+{
81216+ return ((const unsigned long)userp % sz);
81217+}
81218+
81219+static __inline__ unsigned int
81220+gr_fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
81221+{
81222+ return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
81223+}
81224+
81225+static __inline__ unsigned int
81226+gr_nhash(const char *name, const __u16 len, const unsigned int sz)
81227+{
81228+ return full_name_hash((const unsigned char *)name, len) % sz;
81229+}
81230+
81231+#define FOR_EACH_SUBJECT_START(role,subj,iter) \
81232+ subj = NULL; \
81233+ iter = 0; \
81234+ while (iter < role->subj_hash_size) { \
81235+ if (subj == NULL) \
81236+ subj = role->subj_hash[iter]; \
81237+ if (subj == NULL) { \
81238+ iter++; \
81239+ continue; \
81240+ }
81241+
81242+#define FOR_EACH_SUBJECT_END(subj,iter) \
81243+ subj = subj->next; \
81244+ if (subj == NULL) \
81245+ iter++; \
81246+ }
81247+
81248+
81249+#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
81250+ subj = role->hash->first; \
81251+ while (subj != NULL) {
81252+
81253+#define FOR_EACH_NESTED_SUBJECT_END(subj) \
81254+ subj = subj->next; \
81255+ }
81256+
81257+#endif
81258+
81259diff --git a/include/linux/gracl_compat.h b/include/linux/gracl_compat.h
81260new file mode 100644
81261index 0000000..33ebd1f
81262--- /dev/null
81263+++ b/include/linux/gracl_compat.h
81264@@ -0,0 +1,156 @@
81265+#ifndef GR_ACL_COMPAT_H
81266+#define GR_ACL_COMPAT_H
81267+
81268+#include <linux/resource.h>
81269+#include <asm/resource.h>
81270+
81271+struct sprole_pw_compat {
81272+ compat_uptr_t rolename;
81273+ unsigned char salt[GR_SALT_LEN];
81274+ unsigned char sum[GR_SHA_LEN];
81275+};
81276+
81277+struct gr_hash_struct_compat {
81278+ compat_uptr_t table;
81279+ compat_uptr_t nametable;
81280+ compat_uptr_t first;
81281+ __u32 table_size;
81282+ __u32 used_size;
81283+ int type;
81284+};
81285+
81286+struct acl_subject_label_compat {
81287+ compat_uptr_t filename;
81288+ compat_ino_t inode;
81289+ __u32 device;
81290+ __u32 mode;
81291+ kernel_cap_t cap_mask;
81292+ kernel_cap_t cap_lower;
81293+ kernel_cap_t cap_invert_audit;
81294+
81295+ struct compat_rlimit res[GR_NLIMITS];
81296+ __u32 resmask;
81297+
81298+ __u8 user_trans_type;
81299+ __u8 group_trans_type;
81300+ compat_uptr_t user_transitions;
81301+ compat_uptr_t group_transitions;
81302+ __u16 user_trans_num;
81303+ __u16 group_trans_num;
81304+
81305+ __u32 sock_families[2];
81306+ __u32 ip_proto[8];
81307+ __u32 ip_type;
81308+ compat_uptr_t ips;
81309+ __u32 ip_num;
81310+ __u32 inaddr_any_override;
81311+
81312+ __u32 crashes;
81313+ compat_ulong_t expires;
81314+
81315+ compat_uptr_t parent_subject;
81316+ compat_uptr_t hash;
81317+ compat_uptr_t prev;
81318+ compat_uptr_t next;
81319+
81320+ compat_uptr_t obj_hash;
81321+ __u32 obj_hash_size;
81322+ __u16 pax_flags;
81323+};
81324+
81325+struct role_allowed_ip_compat {
81326+ __u32 addr;
81327+ __u32 netmask;
81328+
81329+ compat_uptr_t prev;
81330+ compat_uptr_t next;
81331+};
81332+
81333+struct role_transition_compat {
81334+ compat_uptr_t rolename;
81335+
81336+ compat_uptr_t prev;
81337+ compat_uptr_t next;
81338+};
81339+
81340+struct acl_role_label_compat {
81341+ compat_uptr_t rolename;
81342+ uid_t uidgid;
81343+ __u16 roletype;
81344+
81345+ __u16 auth_attempts;
81346+ compat_ulong_t expires;
81347+
81348+ compat_uptr_t root_label;
81349+ compat_uptr_t hash;
81350+
81351+ compat_uptr_t prev;
81352+ compat_uptr_t next;
81353+
81354+ compat_uptr_t transitions;
81355+ compat_uptr_t allowed_ips;
81356+ compat_uptr_t domain_children;
81357+ __u16 domain_child_num;
81358+
81359+ umode_t umask;
81360+
81361+ compat_uptr_t subj_hash;
81362+ __u32 subj_hash_size;
81363+};
81364+
81365+struct user_acl_role_db_compat {
81366+ compat_uptr_t r_table;
81367+ __u32 num_pointers;
81368+ __u32 num_roles;
81369+ __u32 num_domain_children;
81370+ __u32 num_subjects;
81371+ __u32 num_objects;
81372+};
81373+
81374+struct acl_object_label_compat {
81375+ compat_uptr_t filename;
81376+ compat_ino_t inode;
81377+ __u32 device;
81378+ __u32 mode;
81379+
81380+ compat_uptr_t nested;
81381+ compat_uptr_t globbed;
81382+
81383+ compat_uptr_t prev;
81384+ compat_uptr_t next;
81385+};
81386+
81387+struct acl_ip_label_compat {
81388+ compat_uptr_t iface;
81389+ __u32 addr;
81390+ __u32 netmask;
81391+ __u16 low, high;
81392+ __u8 mode;
81393+ __u32 type;
81394+ __u32 proto[8];
81395+
81396+ compat_uptr_t prev;
81397+ compat_uptr_t next;
81398+};
81399+
81400+struct gr_arg_compat {
81401+ struct user_acl_role_db_compat role_db;
81402+ unsigned char pw[GR_PW_LEN];
81403+ unsigned char salt[GR_SALT_LEN];
81404+ unsigned char sum[GR_SHA_LEN];
81405+ unsigned char sp_role[GR_SPROLE_LEN];
81406+ compat_uptr_t sprole_pws;
81407+ __u32 segv_device;
81408+ compat_ino_t segv_inode;
81409+ uid_t segv_uid;
81410+ __u16 num_sprole_pws;
81411+ __u16 mode;
81412+};
81413+
81414+struct gr_arg_wrapper_compat {
81415+ compat_uptr_t arg;
81416+ __u32 version;
81417+ __u32 size;
81418+};
81419+
81420+#endif
81421diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
81422new file mode 100644
81423index 0000000..323ecf2
81424--- /dev/null
81425+++ b/include/linux/gralloc.h
81426@@ -0,0 +1,9 @@
81427+#ifndef __GRALLOC_H
81428+#define __GRALLOC_H
81429+
81430+void acl_free_all(void);
81431+int acl_alloc_stack_init(unsigned long size);
81432+void *acl_alloc(unsigned long len);
81433+void *acl_alloc_num(unsigned long num, unsigned long len);
81434+
81435+#endif
81436diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
81437new file mode 100644
81438index 0000000..be66033
81439--- /dev/null
81440+++ b/include/linux/grdefs.h
81441@@ -0,0 +1,140 @@
81442+#ifndef GRDEFS_H
81443+#define GRDEFS_H
81444+
81445+/* Begin grsecurity status declarations */
81446+
81447+enum {
81448+ GR_READY = 0x01,
81449+ GR_STATUS_INIT = 0x00 // disabled state
81450+};
81451+
81452+/* Begin ACL declarations */
81453+
81454+/* Role flags */
81455+
81456+enum {
81457+ GR_ROLE_USER = 0x0001,
81458+ GR_ROLE_GROUP = 0x0002,
81459+ GR_ROLE_DEFAULT = 0x0004,
81460+ GR_ROLE_SPECIAL = 0x0008,
81461+ GR_ROLE_AUTH = 0x0010,
81462+ GR_ROLE_NOPW = 0x0020,
81463+ GR_ROLE_GOD = 0x0040,
81464+ GR_ROLE_LEARN = 0x0080,
81465+ GR_ROLE_TPE = 0x0100,
81466+ GR_ROLE_DOMAIN = 0x0200,
81467+ GR_ROLE_PAM = 0x0400,
81468+ GR_ROLE_PERSIST = 0x0800
81469+};
81470+
81471+/* ACL Subject and Object mode flags */
81472+enum {
81473+ GR_DELETED = 0x80000000
81474+};
81475+
81476+/* ACL Object-only mode flags */
81477+enum {
81478+ GR_READ = 0x00000001,
81479+ GR_APPEND = 0x00000002,
81480+ GR_WRITE = 0x00000004,
81481+ GR_EXEC = 0x00000008,
81482+ GR_FIND = 0x00000010,
81483+ GR_INHERIT = 0x00000020,
81484+ GR_SETID = 0x00000040,
81485+ GR_CREATE = 0x00000080,
81486+ GR_DELETE = 0x00000100,
81487+ GR_LINK = 0x00000200,
81488+ GR_AUDIT_READ = 0x00000400,
81489+ GR_AUDIT_APPEND = 0x00000800,
81490+ GR_AUDIT_WRITE = 0x00001000,
81491+ GR_AUDIT_EXEC = 0x00002000,
81492+ GR_AUDIT_FIND = 0x00004000,
81493+ GR_AUDIT_INHERIT= 0x00008000,
81494+ GR_AUDIT_SETID = 0x00010000,
81495+ GR_AUDIT_CREATE = 0x00020000,
81496+ GR_AUDIT_DELETE = 0x00040000,
81497+ GR_AUDIT_LINK = 0x00080000,
81498+ GR_PTRACERD = 0x00100000,
81499+ GR_NOPTRACE = 0x00200000,
81500+ GR_SUPPRESS = 0x00400000,
81501+ GR_NOLEARN = 0x00800000,
81502+ GR_INIT_TRANSFER= 0x01000000
81503+};
81504+
81505+#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
81506+ GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
81507+ GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
81508+
81509+/* ACL subject-only mode flags */
81510+enum {
81511+ GR_KILL = 0x00000001,
81512+ GR_VIEW = 0x00000002,
81513+ GR_PROTECTED = 0x00000004,
81514+ GR_LEARN = 0x00000008,
81515+ GR_OVERRIDE = 0x00000010,
81516+ /* just a placeholder, this mode is only used in userspace */
81517+ GR_DUMMY = 0x00000020,
81518+ GR_PROTSHM = 0x00000040,
81519+ GR_KILLPROC = 0x00000080,
81520+ GR_KILLIPPROC = 0x00000100,
81521+ /* just a placeholder, this mode is only used in userspace */
81522+ GR_NOTROJAN = 0x00000200,
81523+ GR_PROTPROCFD = 0x00000400,
81524+ GR_PROCACCT = 0x00000800,
81525+ GR_RELAXPTRACE = 0x00001000,
81526+ //GR_NESTED = 0x00002000,
81527+ GR_INHERITLEARN = 0x00004000,
81528+ GR_PROCFIND = 0x00008000,
81529+ GR_POVERRIDE = 0x00010000,
81530+ GR_KERNELAUTH = 0x00020000,
81531+ GR_ATSECURE = 0x00040000,
81532+ GR_SHMEXEC = 0x00080000
81533+};
81534+
81535+enum {
81536+ GR_PAX_ENABLE_SEGMEXEC = 0x0001,
81537+ GR_PAX_ENABLE_PAGEEXEC = 0x0002,
81538+ GR_PAX_ENABLE_MPROTECT = 0x0004,
81539+ GR_PAX_ENABLE_RANDMMAP = 0x0008,
81540+ GR_PAX_ENABLE_EMUTRAMP = 0x0010,
81541+ GR_PAX_DISABLE_SEGMEXEC = 0x0100,
81542+ GR_PAX_DISABLE_PAGEEXEC = 0x0200,
81543+ GR_PAX_DISABLE_MPROTECT = 0x0400,
81544+ GR_PAX_DISABLE_RANDMMAP = 0x0800,
81545+ GR_PAX_DISABLE_EMUTRAMP = 0x1000,
81546+};
81547+
81548+enum {
81549+ GR_ID_USER = 0x01,
81550+ GR_ID_GROUP = 0x02,
81551+};
81552+
81553+enum {
81554+ GR_ID_ALLOW = 0x01,
81555+ GR_ID_DENY = 0x02,
81556+};
81557+
81558+#define GR_CRASH_RES 31
81559+#define GR_UIDTABLE_MAX 500
81560+
81561+/* begin resource learning section */
81562+enum {
81563+ GR_RLIM_CPU_BUMP = 60,
81564+ GR_RLIM_FSIZE_BUMP = 50000,
81565+ GR_RLIM_DATA_BUMP = 10000,
81566+ GR_RLIM_STACK_BUMP = 1000,
81567+ GR_RLIM_CORE_BUMP = 10000,
81568+ GR_RLIM_RSS_BUMP = 500000,
81569+ GR_RLIM_NPROC_BUMP = 1,
81570+ GR_RLIM_NOFILE_BUMP = 5,
81571+ GR_RLIM_MEMLOCK_BUMP = 50000,
81572+ GR_RLIM_AS_BUMP = 500000,
81573+ GR_RLIM_LOCKS_BUMP = 2,
81574+ GR_RLIM_SIGPENDING_BUMP = 5,
81575+ GR_RLIM_MSGQUEUE_BUMP = 10000,
81576+ GR_RLIM_NICE_BUMP = 1,
81577+ GR_RLIM_RTPRIO_BUMP = 1,
81578+ GR_RLIM_RTTIME_BUMP = 1000000
81579+};
81580+
81581+#endif
81582diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
81583new file mode 100644
81584index 0000000..d25522e
81585--- /dev/null
81586+++ b/include/linux/grinternal.h
81587@@ -0,0 +1,229 @@
81588+#ifndef __GRINTERNAL_H
81589+#define __GRINTERNAL_H
81590+
81591+#ifdef CONFIG_GRKERNSEC
81592+
81593+#include <linux/fs.h>
81594+#include <linux/mnt_namespace.h>
81595+#include <linux/nsproxy.h>
81596+#include <linux/gracl.h>
81597+#include <linux/grdefs.h>
81598+#include <linux/grmsg.h>
81599+
81600+void gr_add_learn_entry(const char *fmt, ...)
81601+ __attribute__ ((format (printf, 1, 2)));
81602+__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
81603+ const struct vfsmount *mnt);
81604+__u32 gr_check_create(const struct dentry *new_dentry,
81605+ const struct dentry *parent,
81606+ const struct vfsmount *mnt, const __u32 mode);
81607+int gr_check_protected_task(const struct task_struct *task);
81608+__u32 to_gr_audit(const __u32 reqmode);
81609+int gr_set_acls(const int type);
81610+int gr_acl_is_enabled(void);
81611+char gr_roletype_to_char(void);
81612+
81613+void gr_handle_alertkill(struct task_struct *task);
81614+char *gr_to_filename(const struct dentry *dentry,
81615+ const struct vfsmount *mnt);
81616+char *gr_to_filename1(const struct dentry *dentry,
81617+ const struct vfsmount *mnt);
81618+char *gr_to_filename2(const struct dentry *dentry,
81619+ const struct vfsmount *mnt);
81620+char *gr_to_filename3(const struct dentry *dentry,
81621+ const struct vfsmount *mnt);
81622+
81623+extern int grsec_enable_ptrace_readexec;
81624+extern int grsec_enable_harden_ptrace;
81625+extern int grsec_enable_link;
81626+extern int grsec_enable_fifo;
81627+extern int grsec_enable_execve;
81628+extern int grsec_enable_shm;
81629+extern int grsec_enable_execlog;
81630+extern int grsec_enable_signal;
81631+extern int grsec_enable_audit_ptrace;
81632+extern int grsec_enable_forkfail;
81633+extern int grsec_enable_time;
81634+extern int grsec_enable_rofs;
81635+extern int grsec_deny_new_usb;
81636+extern int grsec_enable_chroot_shmat;
81637+extern int grsec_enable_chroot_mount;
81638+extern int grsec_enable_chroot_double;
81639+extern int grsec_enable_chroot_pivot;
81640+extern int grsec_enable_chroot_chdir;
81641+extern int grsec_enable_chroot_chmod;
81642+extern int grsec_enable_chroot_mknod;
81643+extern int grsec_enable_chroot_fchdir;
81644+extern int grsec_enable_chroot_nice;
81645+extern int grsec_enable_chroot_execlog;
81646+extern int grsec_enable_chroot_caps;
81647+extern int grsec_enable_chroot_sysctl;
81648+extern int grsec_enable_chroot_unix;
81649+extern int grsec_enable_symlinkown;
81650+extern kgid_t grsec_symlinkown_gid;
81651+extern int grsec_enable_tpe;
81652+extern kgid_t grsec_tpe_gid;
81653+extern int grsec_enable_tpe_all;
81654+extern int grsec_enable_tpe_invert;
81655+extern int grsec_enable_socket_all;
81656+extern kgid_t grsec_socket_all_gid;
81657+extern int grsec_enable_socket_client;
81658+extern kgid_t grsec_socket_client_gid;
81659+extern int grsec_enable_socket_server;
81660+extern kgid_t grsec_socket_server_gid;
81661+extern kgid_t grsec_audit_gid;
81662+extern int grsec_enable_group;
81663+extern int grsec_enable_log_rwxmaps;
81664+extern int grsec_enable_mount;
81665+extern int grsec_enable_chdir;
81666+extern int grsec_resource_logging;
81667+extern int grsec_enable_blackhole;
81668+extern int grsec_lastack_retries;
81669+extern int grsec_enable_brute;
81670+extern int grsec_enable_harden_ipc;
81671+extern int grsec_lock;
81672+
81673+extern spinlock_t grsec_alert_lock;
81674+extern unsigned long grsec_alert_wtime;
81675+extern unsigned long grsec_alert_fyet;
81676+
81677+extern spinlock_t grsec_audit_lock;
81678+
81679+extern rwlock_t grsec_exec_file_lock;
81680+
81681+#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
81682+ gr_to_filename2((tsk)->exec_file->f_path.dentry, \
81683+ (tsk)->exec_file->f_path.mnt) : "/")
81684+
81685+#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
81686+ gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
81687+ (tsk)->real_parent->exec_file->f_path.mnt) : "/")
81688+
81689+#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
81690+ gr_to_filename((tsk)->exec_file->f_path.dentry, \
81691+ (tsk)->exec_file->f_path.mnt) : "/")
81692+
81693+#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
81694+ gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
81695+ (tsk)->real_parent->exec_file->f_path.mnt) : "/")
81696+
81697+#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
81698+
81699+#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
81700+
81701+static inline bool gr_is_same_file(const struct file *file1, const struct file *file2)
81702+{
81703+ if (file1 && file2) {
81704+ const struct inode *inode1 = file1->f_path.dentry->d_inode;
81705+ const struct inode *inode2 = file2->f_path.dentry->d_inode;
81706+ if (inode1->i_ino == inode2->i_ino && inode1->i_sb->s_dev == inode2->i_sb->s_dev)
81707+ return true;
81708+ }
81709+
81710+ return false;
81711+}
81712+
81713+#define GR_CHROOT_CAPS {{ \
81714+ CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
81715+ CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
81716+ CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
81717+ CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
81718+ CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
81719+ CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
81720+ CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
81721+
81722+#define security_learn(normal_msg,args...) \
81723+({ \
81724+ read_lock(&grsec_exec_file_lock); \
81725+ gr_add_learn_entry(normal_msg "\n", ## args); \
81726+ read_unlock(&grsec_exec_file_lock); \
81727+})
81728+
81729+enum {
81730+ GR_DO_AUDIT,
81731+ GR_DONT_AUDIT,
81732+ /* used for non-audit messages that we shouldn't kill the task on */
81733+ GR_DONT_AUDIT_GOOD
81734+};
81735+
81736+enum {
81737+ GR_TTYSNIFF,
81738+ GR_RBAC,
81739+ GR_RBAC_STR,
81740+ GR_STR_RBAC,
81741+ GR_RBAC_MODE2,
81742+ GR_RBAC_MODE3,
81743+ GR_FILENAME,
81744+ GR_SYSCTL_HIDDEN,
81745+ GR_NOARGS,
81746+ GR_ONE_INT,
81747+ GR_ONE_INT_TWO_STR,
81748+ GR_ONE_STR,
81749+ GR_STR_INT,
81750+ GR_TWO_STR_INT,
81751+ GR_TWO_INT,
81752+ GR_TWO_U64,
81753+ GR_THREE_INT,
81754+ GR_FIVE_INT_TWO_STR,
81755+ GR_TWO_STR,
81756+ GR_THREE_STR,
81757+ GR_FOUR_STR,
81758+ GR_STR_FILENAME,
81759+ GR_FILENAME_STR,
81760+ GR_FILENAME_TWO_INT,
81761+ GR_FILENAME_TWO_INT_STR,
81762+ GR_TEXTREL,
81763+ GR_PTRACE,
81764+ GR_RESOURCE,
81765+ GR_CAP,
81766+ GR_SIG,
81767+ GR_SIG2,
81768+ GR_CRASH1,
81769+ GR_CRASH2,
81770+ GR_PSACCT,
81771+ GR_RWXMAP,
81772+ GR_RWXMAPVMA
81773+};
81774+
81775+#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
81776+#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
81777+#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
81778+#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
81779+#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
81780+#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
81781+#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)
81782+#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
81783+#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
81784+#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
81785+#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
81786+#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
81787+#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
81788+#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
81789+#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
81790+#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
81791+#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)
81792+#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
81793+#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
81794+#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
81795+#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
81796+#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
81797+#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
81798+#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
81799+#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)
81800+#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
81801+#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
81802+#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
81803+#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
81804+#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
81805+#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
81806+#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
81807+#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
81808+#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)
81809+#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
81810+#define gr_log_rwxmap_vma(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAPVMA, str)
81811+
81812+void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
81813+
81814+#endif
81815+
81816+#endif
81817diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
81818new file mode 100644
81819index 0000000..b02ba9d
81820--- /dev/null
81821+++ b/include/linux/grmsg.h
81822@@ -0,0 +1,117 @@
81823+#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"
81824+#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"
81825+#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
81826+#define GR_STOPMOD_MSG "denied modification of module state by "
81827+#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
81828+#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
81829+#define GR_IOPERM_MSG "denied use of ioperm() by "
81830+#define GR_IOPL_MSG "denied use of iopl() by "
81831+#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
81832+#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
81833+#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
81834+#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
81835+#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
81836+#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"
81837+#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"
81838+#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
81839+#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
81840+#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
81841+#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
81842+#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
81843+#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
81844+#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
81845+#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
81846+#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
81847+#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
81848+#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
81849+#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
81850+#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
81851+#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
81852+#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
81853+#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
81854+#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
81855+#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
81856+#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
81857+#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
81858+#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
81859+#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
81860+#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
81861+#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
81862+#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
81863+#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
81864+#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
81865+#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
81866+#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
81867+#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
81868+#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
81869+#define GR_CHROOT_FHANDLE_MSG "denied use of file handles inside chroot by "
81870+#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
81871+#define GR_SETXATTR_ACL_MSG "%s setting extended attribute of %.950s by "
81872+#define GR_REMOVEXATTR_ACL_MSG "%s removing extended attribute of %.950s by "
81873+#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
81874+#define GR_INITF_ACL_MSG "init_variables() failed %s by "
81875+#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"
81876+#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
81877+#define GR_SHUTS_ACL_MSG "shutdown auth success for "
81878+#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
81879+#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
81880+#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
81881+#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
81882+#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
81883+#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
81884+#define GR_ENABLEF_ACL_MSG "unable to load %s for "
81885+#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
81886+#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
81887+#define GR_RELOADF_ACL_MSG "failed reload of %s for "
81888+#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
81889+#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
81890+#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
81891+#define GR_SPROLEF_ACL_MSG "special role %s failure for "
81892+#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
81893+#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
81894+#define GR_INVMODE_ACL_MSG "invalid mode %d by "
81895+#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
81896+#define GR_FAILFORK_MSG "failed fork with errno %s by "
81897+#define GR_NICE_CHROOT_MSG "denied priority change by "
81898+#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
81899+#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
81900+#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
81901+#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
81902+#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
81903+#define GR_TIME_MSG "time set by "
81904+#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
81905+#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
81906+#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
81907+#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
81908+#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
81909+#define GR_BIND_MSG "denied bind() by "
81910+#define GR_CONNECT_MSG "denied connect() by "
81911+#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
81912+#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
81913+#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"
81914+#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
81915+#define GR_CAP_ACL_MSG "use of %s denied for "
81916+#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
81917+#define GR_CAP_ACL_MSG2 "use of %s permitted for "
81918+#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
81919+#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
81920+#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
81921+#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
81922+#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
81923+#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
81924+#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
81925+#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
81926+#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
81927+#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
81928+#define GR_TEXTREL_AUDIT_MSG "denied text relocation in %.950s, VMA:0x%08lx 0x%08lx by "
81929+#define GR_PTGNUSTACK_MSG "denied marking stack executable as requested by PT_GNU_STACK marking in %.950s by "
81930+#define GR_VM86_MSG "denied use of vm86 by "
81931+#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
81932+#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
81933+#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
81934+#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
81935+#define GR_SYMLINKOWNER_MSG "denied following symlink %.950s since symlink owner %u does not match target owner %u, by "
81936+#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 "
81937+#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 "
81938+#define GR_IPC_DENIED_MSG "denied %s of overly-permissive IPC object with creator uid %u by "
81939+#define GR_MSRWRITE_MSG "denied write to CPU MSR by "
81940diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
81941new file mode 100644
81942index 0000000..c3b0738
81943--- /dev/null
81944+++ b/include/linux/grsecurity.h
81945@@ -0,0 +1,244 @@
81946+#ifndef GR_SECURITY_H
81947+#define GR_SECURITY_H
81948+#include <linux/fs.h>
81949+#include <linux/fs_struct.h>
81950+#include <linux/binfmts.h>
81951+#include <linux/gracl.h>
81952+
81953+/* notify of brain-dead configs */
81954+#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
81955+#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
81956+#endif
81957+#if defined(CONFIG_GRKERNSEC_PROC) && !defined(CONFIG_GRKERNSEC_PROC_USER) && !defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
81958+#error "CONFIG_GRKERNSEC_PROC enabled, but neither CONFIG_GRKERNSEC_PROC_USER nor CONFIG_GRKERNSEC_PROC_USERGROUP enabled"
81959+#endif
81960+#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
81961+#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
81962+#endif
81963+#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
81964+#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
81965+#endif
81966+#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
81967+#error "CONFIG_PAX enabled, but no PaX options are enabled."
81968+#endif
81969+
81970+int gr_handle_new_usb(void);
81971+
81972+void gr_handle_brute_attach(int dumpable);
81973+void gr_handle_brute_check(void);
81974+void gr_handle_kernel_exploit(void);
81975+
81976+char gr_roletype_to_char(void);
81977+
81978+int gr_proc_is_restricted(void);
81979+
81980+int gr_acl_enable_at_secure(void);
81981+
81982+int gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs);
81983+int gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs);
81984+
81985+int gr_learn_cap(const struct task_struct *task, const struct cred *cred, const int cap);
81986+
81987+void gr_del_task_from_ip_table(struct task_struct *p);
81988+
81989+int gr_pid_is_chrooted(struct task_struct *p);
81990+int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
81991+int gr_handle_chroot_nice(void);
81992+int gr_handle_chroot_sysctl(const int op);
81993+int gr_handle_chroot_setpriority(struct task_struct *p,
81994+ const int niceval);
81995+int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
81996+int gr_chroot_fhandle(void);
81997+int gr_handle_chroot_chroot(const struct dentry *dentry,
81998+ const struct vfsmount *mnt);
81999+void gr_handle_chroot_chdir(const struct path *path);
82000+int gr_handle_chroot_chmod(const struct dentry *dentry,
82001+ const struct vfsmount *mnt, const int mode);
82002+int gr_handle_chroot_mknod(const struct dentry *dentry,
82003+ const struct vfsmount *mnt, const int mode);
82004+int gr_handle_chroot_mount(const struct dentry *dentry,
82005+ const struct vfsmount *mnt,
82006+ const char *dev_name);
82007+int gr_handle_chroot_pivot(void);
82008+int gr_handle_chroot_unix(const pid_t pid);
82009+
82010+int gr_handle_rawio(const struct inode *inode);
82011+
82012+void gr_handle_ioperm(void);
82013+void gr_handle_iopl(void);
82014+void gr_handle_msr_write(void);
82015+
82016+umode_t gr_acl_umask(void);
82017+
82018+int gr_tpe_allow(const struct file *file);
82019+
82020+void gr_set_chroot_entries(struct task_struct *task, const struct path *path);
82021+void gr_clear_chroot_entries(struct task_struct *task);
82022+
82023+void gr_log_forkfail(const int retval);
82024+void gr_log_timechange(void);
82025+void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
82026+void gr_log_chdir(const struct dentry *dentry,
82027+ const struct vfsmount *mnt);
82028+void gr_log_chroot_exec(const struct dentry *dentry,
82029+ const struct vfsmount *mnt);
82030+void gr_log_remount(const char *devname, const int retval);
82031+void gr_log_unmount(const char *devname, const int retval);
82032+void gr_log_mount(const char *from, struct path *to, const int retval);
82033+void gr_log_textrel(struct vm_area_struct *vma);
82034+void gr_log_ptgnustack(struct file *file);
82035+void gr_log_rwxmmap(struct file *file);
82036+void gr_log_rwxmprotect(struct vm_area_struct *vma);
82037+
82038+int gr_handle_follow_link(const struct inode *parent,
82039+ const struct inode *inode,
82040+ const struct dentry *dentry,
82041+ const struct vfsmount *mnt);
82042+int gr_handle_fifo(const struct dentry *dentry,
82043+ const struct vfsmount *mnt,
82044+ const struct dentry *dir, const int flag,
82045+ const int acc_mode);
82046+int gr_handle_hardlink(const struct dentry *dentry,
82047+ const struct vfsmount *mnt,
82048+ struct inode *inode,
82049+ const int mode, const struct filename *to);
82050+
82051+int gr_is_capable(const int cap);
82052+int gr_is_capable_nolog(const int cap);
82053+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
82054+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
82055+
82056+void gr_copy_label(struct task_struct *tsk);
82057+void gr_handle_crash(struct task_struct *task, const int sig);
82058+int gr_handle_signal(const struct task_struct *p, const int sig);
82059+int gr_check_crash_uid(const kuid_t uid);
82060+int gr_check_protected_task(const struct task_struct *task);
82061+int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
82062+int gr_acl_handle_mmap(const struct file *file,
82063+ const unsigned long prot);
82064+int gr_acl_handle_mprotect(const struct file *file,
82065+ const unsigned long prot);
82066+int gr_check_hidden_task(const struct task_struct *tsk);
82067+__u32 gr_acl_handle_truncate(const struct dentry *dentry,
82068+ const struct vfsmount *mnt);
82069+__u32 gr_acl_handle_utime(const struct dentry *dentry,
82070+ const struct vfsmount *mnt);
82071+__u32 gr_acl_handle_access(const struct dentry *dentry,
82072+ const struct vfsmount *mnt, const int fmode);
82073+__u32 gr_acl_handle_chmod(const struct dentry *dentry,
82074+ const struct vfsmount *mnt, umode_t *mode);
82075+__u32 gr_acl_handle_chown(const struct dentry *dentry,
82076+ const struct vfsmount *mnt);
82077+__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
82078+ const struct vfsmount *mnt);
82079+__u32 gr_acl_handle_removexattr(const struct dentry *dentry,
82080+ const struct vfsmount *mnt);
82081+int gr_handle_ptrace(struct task_struct *task, const long request);
82082+int gr_handle_proc_ptrace(struct task_struct *task);
82083+__u32 gr_acl_handle_execve(const struct dentry *dentry,
82084+ const struct vfsmount *mnt);
82085+int gr_check_crash_exec(const struct file *filp);
82086+int gr_acl_is_enabled(void);
82087+void gr_set_role_label(struct task_struct *task, const kuid_t uid,
82088+ const kgid_t gid);
82089+int gr_set_proc_label(const struct dentry *dentry,
82090+ const struct vfsmount *mnt,
82091+ const int unsafe_flags);
82092+__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
82093+ const struct vfsmount *mnt);
82094+__u32 gr_acl_handle_open(const struct dentry *dentry,
82095+ const struct vfsmount *mnt, int acc_mode);
82096+__u32 gr_acl_handle_creat(const struct dentry *dentry,
82097+ const struct dentry *p_dentry,
82098+ const struct vfsmount *p_mnt,
82099+ int open_flags, int acc_mode, const int imode);
82100+void gr_handle_create(const struct dentry *dentry,
82101+ const struct vfsmount *mnt);
82102+void gr_handle_proc_create(const struct dentry *dentry,
82103+ const struct inode *inode);
82104+__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
82105+ const struct dentry *parent_dentry,
82106+ const struct vfsmount *parent_mnt,
82107+ const int mode);
82108+__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
82109+ const struct dentry *parent_dentry,
82110+ const struct vfsmount *parent_mnt);
82111+__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
82112+ const struct vfsmount *mnt);
82113+void gr_handle_delete(const ino_t ino, const dev_t dev);
82114+__u32 gr_acl_handle_unlink(const struct dentry *dentry,
82115+ const struct vfsmount *mnt);
82116+__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
82117+ const struct dentry *parent_dentry,
82118+ const struct vfsmount *parent_mnt,
82119+ const struct filename *from);
82120+__u32 gr_acl_handle_link(const struct dentry *new_dentry,
82121+ const struct dentry *parent_dentry,
82122+ const struct vfsmount *parent_mnt,
82123+ const struct dentry *old_dentry,
82124+ const struct vfsmount *old_mnt, const struct filename *to);
82125+int gr_handle_symlink_owner(const struct path *link, const struct inode *target);
82126+int gr_acl_handle_rename(struct dentry *new_dentry,
82127+ struct dentry *parent_dentry,
82128+ const struct vfsmount *parent_mnt,
82129+ struct dentry *old_dentry,
82130+ struct inode *old_parent_inode,
82131+ struct vfsmount *old_mnt, const struct filename *newname, unsigned int flags);
82132+void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
82133+ struct dentry *old_dentry,
82134+ struct dentry *new_dentry,
82135+ struct vfsmount *mnt, const __u8 replace, unsigned int flags);
82136+__u32 gr_check_link(const struct dentry *new_dentry,
82137+ const struct dentry *parent_dentry,
82138+ const struct vfsmount *parent_mnt,
82139+ const struct dentry *old_dentry,
82140+ const struct vfsmount *old_mnt);
82141+int gr_acl_handle_filldir(const struct file *file, const char *name,
82142+ const unsigned int namelen, const ino_t ino);
82143+
82144+__u32 gr_acl_handle_unix(const struct dentry *dentry,
82145+ const struct vfsmount *mnt);
82146+void gr_acl_handle_exit(void);
82147+void gr_acl_handle_psacct(struct task_struct *task, const long code);
82148+int gr_acl_handle_procpidmem(const struct task_struct *task);
82149+int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
82150+int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
82151+void gr_audit_ptrace(struct task_struct *task);
82152+dev_t gr_get_dev_from_dentry(struct dentry *dentry);
82153+void gr_put_exec_file(struct task_struct *task);
82154+
82155+int gr_ptrace_readexec(struct file *file, int unsafe_flags);
82156+
82157+#ifdef CONFIG_GRKERNSEC_RESLOG
82158+extern void gr_log_resource(const struct task_struct *task, const int res,
82159+ const unsigned long wanted, const int gt);
82160+#else
82161+static inline void gr_log_resource(const struct task_struct *task, const int res,
82162+ const unsigned long wanted, const int gt)
82163+{
82164+}
82165+#endif
82166+
82167+#ifdef CONFIG_GRKERNSEC
82168+void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
82169+void gr_handle_vm86(void);
82170+void gr_handle_mem_readwrite(u64 from, u64 to);
82171+
82172+void gr_log_badprocpid(const char *entry);
82173+
82174+extern int grsec_enable_dmesg;
82175+extern int grsec_disable_privio;
82176+
82177+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
82178+extern kgid_t grsec_proc_gid;
82179+#endif
82180+
82181+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
82182+extern int grsec_enable_chroot_findtask;
82183+#endif
82184+#ifdef CONFIG_GRKERNSEC_SETXID
82185+extern int grsec_enable_setxid;
82186+#endif
82187+#endif
82188+
82189+#endif
82190diff --git a/include/linux/grsock.h b/include/linux/grsock.h
82191new file mode 100644
82192index 0000000..e7ffaaf
82193--- /dev/null
82194+++ b/include/linux/grsock.h
82195@@ -0,0 +1,19 @@
82196+#ifndef __GRSOCK_H
82197+#define __GRSOCK_H
82198+
82199+extern void gr_attach_curr_ip(const struct sock *sk);
82200+extern int gr_handle_sock_all(const int family, const int type,
82201+ const int protocol);
82202+extern int gr_handle_sock_server(const struct sockaddr *sck);
82203+extern int gr_handle_sock_server_other(const struct sock *sck);
82204+extern int gr_handle_sock_client(const struct sockaddr *sck);
82205+extern int gr_search_connect(struct socket * sock,
82206+ struct sockaddr_in * addr);
82207+extern int gr_search_bind(struct socket * sock,
82208+ struct sockaddr_in * addr);
82209+extern int gr_search_listen(struct socket * sock);
82210+extern int gr_search_accept(struct socket * sock);
82211+extern int gr_search_socket(const int domain, const int type,
82212+ const int protocol);
82213+
82214+#endif
82215diff --git a/include/linux/hash.h b/include/linux/hash.h
82216index d0494c3..69b7715 100644
82217--- a/include/linux/hash.h
82218+++ b/include/linux/hash.h
82219@@ -87,7 +87,7 @@ static inline u32 hash32_ptr(const void *ptr)
82220 struct fast_hash_ops {
82221 u32 (*hash)(const void *data, u32 len, u32 seed);
82222 u32 (*hash2)(const u32 *data, u32 len, u32 seed);
82223-};
82224+} __no_const;
82225
82226 /**
82227 * arch_fast_hash - Caclulates a hash over a given buffer that can have
82228diff --git a/include/linux/highmem.h b/include/linux/highmem.h
82229index 9286a46..373f27f 100644
82230--- a/include/linux/highmem.h
82231+++ b/include/linux/highmem.h
82232@@ -189,6 +189,18 @@ static inline void clear_highpage(struct page *page)
82233 kunmap_atomic(kaddr);
82234 }
82235
82236+static inline void sanitize_highpage(struct page *page)
82237+{
82238+ void *kaddr;
82239+ unsigned long flags;
82240+
82241+ local_irq_save(flags);
82242+ kaddr = kmap_atomic(page);
82243+ clear_page(kaddr);
82244+ kunmap_atomic(kaddr);
82245+ local_irq_restore(flags);
82246+}
82247+
82248 static inline void zero_user_segments(struct page *page,
82249 unsigned start1, unsigned end1,
82250 unsigned start2, unsigned end2)
82251diff --git a/include/linux/hwmon-sysfs.h b/include/linux/hwmon-sysfs.h
82252index 1c7b89a..7dda400 100644
82253--- a/include/linux/hwmon-sysfs.h
82254+++ b/include/linux/hwmon-sysfs.h
82255@@ -25,7 +25,8 @@
82256 struct sensor_device_attribute{
82257 struct device_attribute dev_attr;
82258 int index;
82259-};
82260+} __do_const;
82261+typedef struct sensor_device_attribute __no_const sensor_device_attribute_no_const;
82262 #define to_sensor_dev_attr(_dev_attr) \
82263 container_of(_dev_attr, struct sensor_device_attribute, dev_attr)
82264
82265@@ -41,7 +42,8 @@ struct sensor_device_attribute_2 {
82266 struct device_attribute dev_attr;
82267 u8 index;
82268 u8 nr;
82269-};
82270+} __do_const;
82271+typedef struct sensor_device_attribute_2 __no_const sensor_device_attribute_2_no_const;
82272 #define to_sensor_dev_attr_2(_dev_attr) \
82273 container_of(_dev_attr, struct sensor_device_attribute_2, dev_attr)
82274
82275diff --git a/include/linux/i2c.h b/include/linux/i2c.h
82276index b556e0a..c10a515 100644
82277--- a/include/linux/i2c.h
82278+++ b/include/linux/i2c.h
82279@@ -378,6 +378,7 @@ struct i2c_algorithm {
82280 /* To determine what the adapter supports */
82281 u32 (*functionality) (struct i2c_adapter *);
82282 };
82283+typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
82284
82285 /**
82286 * struct i2c_bus_recovery_info - I2C bus recovery information
82287diff --git a/include/linux/i2o.h b/include/linux/i2o.h
82288index d23c3c2..eb63c81 100644
82289--- a/include/linux/i2o.h
82290+++ b/include/linux/i2o.h
82291@@ -565,7 +565,7 @@ struct i2o_controller {
82292 struct i2o_device *exec; /* Executive */
82293 #if BITS_PER_LONG == 64
82294 spinlock_t context_list_lock; /* lock for context_list */
82295- atomic_t context_list_counter; /* needed for unique contexts */
82296+ atomic_unchecked_t context_list_counter; /* needed for unique contexts */
82297 struct list_head context_list; /* list of context id's
82298 and pointers */
82299 #endif
82300diff --git a/include/linux/if_pppox.h b/include/linux/if_pppox.h
82301index aff7ad8..3942bbd 100644
82302--- a/include/linux/if_pppox.h
82303+++ b/include/linux/if_pppox.h
82304@@ -76,7 +76,7 @@ struct pppox_proto {
82305 int (*ioctl)(struct socket *sock, unsigned int cmd,
82306 unsigned long arg);
82307 struct module *owner;
82308-};
82309+} __do_const;
82310
82311 extern int register_pppox_proto(int proto_num, const struct pppox_proto *pp);
82312 extern void unregister_pppox_proto(int proto_num);
82313diff --git a/include/linux/init.h b/include/linux/init.h
82314index 2df8e8d..3e1280d 100644
82315--- a/include/linux/init.h
82316+++ b/include/linux/init.h
82317@@ -37,9 +37,17 @@
82318 * section.
82319 */
82320
82321+#define add_init_latent_entropy __latent_entropy
82322+
82323+#ifdef CONFIG_MEMORY_HOTPLUG
82324+#define add_meminit_latent_entropy
82325+#else
82326+#define add_meminit_latent_entropy __latent_entropy
82327+#endif
82328+
82329 /* These are for everybody (although not all archs will actually
82330 discard it in modules) */
82331-#define __init __section(.init.text) __cold notrace
82332+#define __init __section(.init.text) __cold notrace add_init_latent_entropy
82333 #define __initdata __section(.init.data)
82334 #define __initconst __constsection(.init.rodata)
82335 #define __exitdata __section(.exit.data)
82336@@ -100,7 +108,7 @@
82337 #define __cpuexitconst
82338
82339 /* Used for MEMORY_HOTPLUG */
82340-#define __meminit __section(.meminit.text) __cold notrace
82341+#define __meminit __section(.meminit.text) __cold notrace add_meminit_latent_entropy
82342 #define __meminitdata __section(.meminit.data)
82343 #define __meminitconst __constsection(.meminit.rodata)
82344 #define __memexit __section(.memexit.text) __exitused __cold notrace
82345diff --git a/include/linux/init_task.h b/include/linux/init_task.h
82346index 77fc43f..73caf92 100644
82347--- a/include/linux/init_task.h
82348+++ b/include/linux/init_task.h
82349@@ -158,6 +158,12 @@ extern struct task_group root_task_group;
82350
82351 #define INIT_TASK_COMM "swapper"
82352
82353+#ifdef CONFIG_X86
82354+#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
82355+#else
82356+#define INIT_TASK_THREAD_INFO
82357+#endif
82358+
82359 #ifdef CONFIG_RT_MUTEXES
82360 # define INIT_RT_MUTEXES(tsk) \
82361 .pi_waiters = RB_ROOT, \
82362@@ -205,6 +211,7 @@ extern struct task_group root_task_group;
82363 RCU_POINTER_INITIALIZER(cred, &init_cred), \
82364 .comm = INIT_TASK_COMM, \
82365 .thread = INIT_THREAD, \
82366+ INIT_TASK_THREAD_INFO \
82367 .fs = &init_fs, \
82368 .files = &init_files, \
82369 .signal = &init_signals, \
82370diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
82371index 69517a2..6b12d37 100644
82372--- a/include/linux/interrupt.h
82373+++ b/include/linux/interrupt.h
82374@@ -413,8 +413,8 @@ extern const char * const softirq_to_name[NR_SOFTIRQS];
82375
82376 struct softirq_action
82377 {
82378- void (*action)(struct softirq_action *);
82379-};
82380+ void (*action)(void);
82381+} __no_const;
82382
82383 asmlinkage void do_softirq(void);
82384 asmlinkage void __do_softirq(void);
82385@@ -428,7 +428,7 @@ static inline void do_softirq_own_stack(void)
82386 }
82387 #endif
82388
82389-extern void open_softirq(int nr, void (*action)(struct softirq_action *));
82390+extern void open_softirq(int nr, void (*action)(void));
82391 extern void softirq_init(void);
82392 extern void __raise_softirq_irqoff(unsigned int nr);
82393
82394diff --git a/include/linux/iommu.h b/include/linux/iommu.h
82395index e6a7c9f..5804745 100644
82396--- a/include/linux/iommu.h
82397+++ b/include/linux/iommu.h
82398@@ -133,7 +133,7 @@ struct iommu_ops {
82399 u32 (*domain_get_windows)(struct iommu_domain *domain);
82400
82401 unsigned long pgsize_bitmap;
82402-};
82403+} __do_const;
82404
82405 #define IOMMU_GROUP_NOTIFY_ADD_DEVICE 1 /* Device added */
82406 #define IOMMU_GROUP_NOTIFY_DEL_DEVICE 2 /* Pre Device removed */
82407diff --git a/include/linux/ioport.h b/include/linux/ioport.h
82408index 2c525022..345b106 100644
82409--- a/include/linux/ioport.h
82410+++ b/include/linux/ioport.h
82411@@ -161,7 +161,7 @@ struct resource *lookup_resource(struct resource *root, resource_size_t start);
82412 int adjust_resource(struct resource *res, resource_size_t start,
82413 resource_size_t size);
82414 resource_size_t resource_alignment(struct resource *res);
82415-static inline resource_size_t resource_size(const struct resource *res)
82416+static inline resource_size_t __intentional_overflow(-1) resource_size(const struct resource *res)
82417 {
82418 return res->end - res->start + 1;
82419 }
82420diff --git a/include/linux/ipc_namespace.h b/include/linux/ipc_namespace.h
82421index 35e7eca..6afb7ad 100644
82422--- a/include/linux/ipc_namespace.h
82423+++ b/include/linux/ipc_namespace.h
82424@@ -69,7 +69,7 @@ struct ipc_namespace {
82425 struct user_namespace *user_ns;
82426
82427 unsigned int proc_inum;
82428-};
82429+} __randomize_layout;
82430
82431 extern struct ipc_namespace init_ipc_ns;
82432 extern atomic_t nr_ipc_ns;
82433diff --git a/include/linux/irq.h b/include/linux/irq.h
82434index 03f48d9..e86af0c 100644
82435--- a/include/linux/irq.h
82436+++ b/include/linux/irq.h
82437@@ -352,7 +352,8 @@ struct irq_chip {
82438 void (*irq_release_resources)(struct irq_data *data);
82439
82440 unsigned long flags;
82441-};
82442+} __do_const;
82443+typedef struct irq_chip __no_const irq_chip_no_const;
82444
82445 /*
82446 * irq_chip specific flags
82447diff --git a/include/linux/irqchip/arm-gic.h b/include/linux/irqchip/arm-gic.h
82448index 13eed92..3261c86 100644
82449--- a/include/linux/irqchip/arm-gic.h
82450+++ b/include/linux/irqchip/arm-gic.h
82451@@ -91,9 +91,11 @@
82452
82453 #ifndef __ASSEMBLY__
82454
82455+#include <linux/irq.h>
82456+
82457 struct device_node;
82458
82459-extern struct irq_chip gic_arch_extn;
82460+extern irq_chip_no_const gic_arch_extn;
82461
82462 void gic_init_bases(unsigned int, int, void __iomem *, void __iomem *,
82463 u32 offset, struct device_node *);
82464diff --git a/include/linux/jiffies.h b/include/linux/jiffies.h
82465index c367cbd..c9b79e6 100644
82466--- a/include/linux/jiffies.h
82467+++ b/include/linux/jiffies.h
82468@@ -280,20 +280,20 @@ extern unsigned long preset_lpj;
82469 /*
82470 * Convert various time units to each other:
82471 */
82472-extern unsigned int jiffies_to_msecs(const unsigned long j);
82473-extern unsigned int jiffies_to_usecs(const unsigned long j);
82474+extern unsigned int jiffies_to_msecs(const unsigned long j) __intentional_overflow(-1);
82475+extern unsigned int jiffies_to_usecs(const unsigned long j) __intentional_overflow(-1);
82476
82477-static inline u64 jiffies_to_nsecs(const unsigned long j)
82478+static inline u64 __intentional_overflow(-1) jiffies_to_nsecs(const unsigned long j)
82479 {
82480 return (u64)jiffies_to_usecs(j) * NSEC_PER_USEC;
82481 }
82482
82483-extern unsigned long msecs_to_jiffies(const unsigned int m);
82484-extern unsigned long usecs_to_jiffies(const unsigned int u);
82485+extern unsigned long msecs_to_jiffies(const unsigned int m) __intentional_overflow(-1);
82486+extern unsigned long usecs_to_jiffies(const unsigned int u) __intentional_overflow(-1);
82487 extern unsigned long timespec_to_jiffies(const struct timespec *value);
82488 extern void jiffies_to_timespec(const unsigned long jiffies,
82489- struct timespec *value);
82490-extern unsigned long timeval_to_jiffies(const struct timeval *value);
82491+ struct timespec *value) __intentional_overflow(-1);
82492+extern unsigned long timeval_to_jiffies(const struct timeval *value) __intentional_overflow(-1);
82493 extern void jiffies_to_timeval(const unsigned long jiffies,
82494 struct timeval *value);
82495
82496diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
82497index 6883e19..e854fcb 100644
82498--- a/include/linux/kallsyms.h
82499+++ b/include/linux/kallsyms.h
82500@@ -15,7 +15,8 @@
82501
82502 struct module;
82503
82504-#ifdef CONFIG_KALLSYMS
82505+#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
82506+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
82507 /* Lookup the address for a symbol. Returns 0 if not found. */
82508 unsigned long kallsyms_lookup_name(const char *name);
82509
82510@@ -106,6 +107,21 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
82511 /* Stupid that this does nothing, but I didn't create this mess. */
82512 #define __print_symbol(fmt, addr)
82513 #endif /*CONFIG_KALLSYMS*/
82514+#else /* when included by kallsyms.c, vsnprintf.c, kprobes.c, or
82515+ arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
82516+extern unsigned long kallsyms_lookup_name(const char *name);
82517+extern void __print_symbol(const char *fmt, unsigned long address);
82518+extern int sprint_backtrace(char *buffer, unsigned long address);
82519+extern int sprint_symbol(char *buffer, unsigned long address);
82520+extern int sprint_symbol_no_offset(char *buffer, unsigned long address);
82521+const char *kallsyms_lookup(unsigned long addr,
82522+ unsigned long *symbolsize,
82523+ unsigned long *offset,
82524+ char **modname, char *namebuf);
82525+extern int kallsyms_lookup_size_offset(unsigned long addr,
82526+ unsigned long *symbolsize,
82527+ unsigned long *offset);
82528+#endif
82529
82530 /* This macro allows us to keep printk typechecking */
82531 static __printf(1, 2)
82532diff --git a/include/linux/key-type.h b/include/linux/key-type.h
82533index ff9f1d3..6712be5 100644
82534--- a/include/linux/key-type.h
82535+++ b/include/linux/key-type.h
82536@@ -152,7 +152,7 @@ struct key_type {
82537 /* internal fields */
82538 struct list_head link; /* link in types list */
82539 struct lock_class_key lock_class; /* key->sem lock class */
82540-};
82541+} __do_const;
82542
82543 extern struct key_type key_type_keyring;
82544
82545diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
82546index e465bb1..19f605f 100644
82547--- a/include/linux/kgdb.h
82548+++ b/include/linux/kgdb.h
82549@@ -52,7 +52,7 @@ extern int kgdb_connected;
82550 extern int kgdb_io_module_registered;
82551
82552 extern atomic_t kgdb_setting_breakpoint;
82553-extern atomic_t kgdb_cpu_doing_single_step;
82554+extern atomic_unchecked_t kgdb_cpu_doing_single_step;
82555
82556 extern struct task_struct *kgdb_usethread;
82557 extern struct task_struct *kgdb_contthread;
82558@@ -254,7 +254,7 @@ struct kgdb_arch {
82559 void (*correct_hw_break)(void);
82560
82561 void (*enable_nmi)(bool on);
82562-};
82563+} __do_const;
82564
82565 /**
82566 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
82567@@ -279,7 +279,7 @@ struct kgdb_io {
82568 void (*pre_exception) (void);
82569 void (*post_exception) (void);
82570 int is_console;
82571-};
82572+} __do_const;
82573
82574 extern struct kgdb_arch arch_kgdb_ops;
82575
82576diff --git a/include/linux/kmod.h b/include/linux/kmod.h
82577index 0555cc6..40116ce 100644
82578--- a/include/linux/kmod.h
82579+++ b/include/linux/kmod.h
82580@@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
82581 * usually useless though. */
82582 extern __printf(2, 3)
82583 int __request_module(bool wait, const char *name, ...);
82584+extern __printf(3, 4)
82585+int ___request_module(bool wait, char *param_name, const char *name, ...);
82586 #define request_module(mod...) __request_module(true, mod)
82587 #define request_module_nowait(mod...) __request_module(false, mod)
82588 #define try_then_request_module(x, mod...) \
82589@@ -57,6 +59,9 @@ struct subprocess_info {
82590 struct work_struct work;
82591 struct completion *complete;
82592 char *path;
82593+#ifdef CONFIG_GRKERNSEC
82594+ char *origpath;
82595+#endif
82596 char **argv;
82597 char **envp;
82598 int wait;
82599diff --git a/include/linux/kobject.h b/include/linux/kobject.h
82600index 2d61b90..a1d0a13 100644
82601--- a/include/linux/kobject.h
82602+++ b/include/linux/kobject.h
82603@@ -118,7 +118,7 @@ struct kobj_type {
82604 struct attribute **default_attrs;
82605 const struct kobj_ns_type_operations *(*child_ns_type)(struct kobject *kobj);
82606 const void *(*namespace)(struct kobject *kobj);
82607-};
82608+} __do_const;
82609
82610 struct kobj_uevent_env {
82611 char *argv[3];
82612@@ -142,6 +142,7 @@ struct kobj_attribute {
82613 ssize_t (*store)(struct kobject *kobj, struct kobj_attribute *attr,
82614 const char *buf, size_t count);
82615 };
82616+typedef struct kobj_attribute __no_const kobj_attribute_no_const;
82617
82618 extern const struct sysfs_ops kobj_sysfs_ops;
82619
82620@@ -169,7 +170,7 @@ struct kset {
82621 spinlock_t list_lock;
82622 struct kobject kobj;
82623 const struct kset_uevent_ops *uevent_ops;
82624-};
82625+} __randomize_layout;
82626
82627 extern void kset_init(struct kset *kset);
82628 extern int __must_check kset_register(struct kset *kset);
82629diff --git a/include/linux/kobject_ns.h b/include/linux/kobject_ns.h
82630index df32d25..fb52e27 100644
82631--- a/include/linux/kobject_ns.h
82632+++ b/include/linux/kobject_ns.h
82633@@ -44,7 +44,7 @@ struct kobj_ns_type_operations {
82634 const void *(*netlink_ns)(struct sock *sk);
82635 const void *(*initial_ns)(void);
82636 void (*drop_ns)(void *);
82637-};
82638+} __do_const;
82639
82640 int kobj_ns_type_register(const struct kobj_ns_type_operations *ops);
82641 int kobj_ns_type_registered(enum kobj_ns_type type);
82642diff --git a/include/linux/kref.h b/include/linux/kref.h
82643index 484604d..0f6c5b6 100644
82644--- a/include/linux/kref.h
82645+++ b/include/linux/kref.h
82646@@ -68,7 +68,7 @@ static inline void kref_get(struct kref *kref)
82647 static inline int kref_sub(struct kref *kref, unsigned int count,
82648 void (*release)(struct kref *kref))
82649 {
82650- WARN_ON(release == NULL);
82651+ BUG_ON(release == NULL);
82652
82653 if (atomic_sub_and_test((int) count, &kref->refcount)) {
82654 release(kref);
82655diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
82656index a6059bd..8126d5c 100644
82657--- a/include/linux/kvm_host.h
82658+++ b/include/linux/kvm_host.h
82659@@ -460,7 +460,7 @@ static inline void kvm_irqfd_exit(void)
82660 {
82661 }
82662 #endif
82663-int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
82664+int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
82665 struct module *module);
82666 void kvm_exit(void);
82667
82668@@ -629,7 +629,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
82669 struct kvm_guest_debug *dbg);
82670 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
82671
82672-int kvm_arch_init(void *opaque);
82673+int kvm_arch_init(const void *opaque);
82674 void kvm_arch_exit(void);
82675
82676 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
82677diff --git a/include/linux/libata.h b/include/linux/libata.h
82678index bd5fefe..2a8a8d2 100644
82679--- a/include/linux/libata.h
82680+++ b/include/linux/libata.h
82681@@ -976,7 +976,7 @@ struct ata_port_operations {
82682 * fields must be pointers.
82683 */
82684 const struct ata_port_operations *inherits;
82685-};
82686+} __do_const;
82687
82688 struct ata_port_info {
82689 unsigned long flags;
82690diff --git a/include/linux/linkage.h b/include/linux/linkage.h
82691index a6a42dd..6c5ebce 100644
82692--- a/include/linux/linkage.h
82693+++ b/include/linux/linkage.h
82694@@ -36,6 +36,7 @@
82695 #endif
82696
82697 #define __page_aligned_data __section(.data..page_aligned) __aligned(PAGE_SIZE)
82698+#define __page_aligned_rodata __read_only __aligned(PAGE_SIZE)
82699 #define __page_aligned_bss __section(.bss..page_aligned) __aligned(PAGE_SIZE)
82700
82701 /*
82702diff --git a/include/linux/list.h b/include/linux/list.h
82703index f33f831..1ffe5e2 100644
82704--- a/include/linux/list.h
82705+++ b/include/linux/list.h
82706@@ -113,6 +113,19 @@ extern void __list_del_entry(struct list_head *entry);
82707 extern void list_del(struct list_head *entry);
82708 #endif
82709
82710+extern void __pax_list_add(struct list_head *new,
82711+ struct list_head *prev,
82712+ struct list_head *next);
82713+static inline void pax_list_add(struct list_head *new, struct list_head *head)
82714+{
82715+ __pax_list_add(new, head, head->next);
82716+}
82717+static inline void pax_list_add_tail(struct list_head *new, struct list_head *head)
82718+{
82719+ __pax_list_add(new, head->prev, head);
82720+}
82721+extern void pax_list_del(struct list_head *entry);
82722+
82723 /**
82724 * list_replace - replace old entry by new one
82725 * @old : the element to be replaced
82726@@ -146,6 +159,8 @@ static inline void list_del_init(struct list_head *entry)
82727 INIT_LIST_HEAD(entry);
82728 }
82729
82730+extern void pax_list_del_init(struct list_head *entry);
82731+
82732 /**
82733 * list_move - delete from one list and add as another's head
82734 * @list: the entry to move
82735diff --git a/include/linux/lockref.h b/include/linux/lockref.h
82736index 4bfde0e..d6e2e09 100644
82737--- a/include/linux/lockref.h
82738+++ b/include/linux/lockref.h
82739@@ -47,4 +47,36 @@ static inline int __lockref_is_dead(const struct lockref *l)
82740 return ((int)l->count < 0);
82741 }
82742
82743+static inline unsigned int __lockref_read(struct lockref *lockref)
82744+{
82745+ return lockref->count;
82746+}
82747+
82748+static inline void __lockref_set(struct lockref *lockref, unsigned int count)
82749+{
82750+ lockref->count = count;
82751+}
82752+
82753+static inline void __lockref_inc(struct lockref *lockref)
82754+{
82755+
82756+#ifdef CONFIG_PAX_REFCOUNT
82757+ atomic_inc((atomic_t *)&lockref->count);
82758+#else
82759+ lockref->count++;
82760+#endif
82761+
82762+}
82763+
82764+static inline void __lockref_dec(struct lockref *lockref)
82765+{
82766+
82767+#ifdef CONFIG_PAX_REFCOUNT
82768+ atomic_dec((atomic_t *)&lockref->count);
82769+#else
82770+ lockref->count--;
82771+#endif
82772+
82773+}
82774+
82775 #endif /* __LINUX_LOCKREF_H */
82776diff --git a/include/linux/math64.h b/include/linux/math64.h
82777index c45c089..298841c 100644
82778--- a/include/linux/math64.h
82779+++ b/include/linux/math64.h
82780@@ -15,7 +15,7 @@
82781 * This is commonly provided by 32bit archs to provide an optimized 64bit
82782 * divide.
82783 */
82784-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
82785+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
82786 {
82787 *remainder = dividend % divisor;
82788 return dividend / divisor;
82789@@ -42,7 +42,7 @@ static inline u64 div64_u64_rem(u64 dividend, u64 divisor, u64 *remainder)
82790 /**
82791 * div64_u64 - unsigned 64bit divide with 64bit divisor
82792 */
82793-static inline u64 div64_u64(u64 dividend, u64 divisor)
82794+static inline u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor)
82795 {
82796 return dividend / divisor;
82797 }
82798@@ -61,7 +61,7 @@ static inline s64 div64_s64(s64 dividend, s64 divisor)
82799 #define div64_ul(x, y) div_u64((x), (y))
82800
82801 #ifndef div_u64_rem
82802-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
82803+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
82804 {
82805 *remainder = do_div(dividend, divisor);
82806 return dividend;
82807@@ -77,7 +77,7 @@ extern u64 div64_u64_rem(u64 dividend, u64 divisor, u64 *remainder);
82808 #endif
82809
82810 #ifndef div64_u64
82811-extern u64 div64_u64(u64 dividend, u64 divisor);
82812+extern u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor);
82813 #endif
82814
82815 #ifndef div64_s64
82816@@ -94,7 +94,7 @@ extern s64 div64_s64(s64 dividend, s64 divisor);
82817 * divide.
82818 */
82819 #ifndef div_u64
82820-static inline u64 div_u64(u64 dividend, u32 divisor)
82821+static inline u64 __intentional_overflow(-1) div_u64(u64 dividend, u32 divisor)
82822 {
82823 u32 remainder;
82824 return div_u64_rem(dividend, divisor, &remainder);
82825diff --git a/include/linux/mempolicy.h b/include/linux/mempolicy.h
82826index 3d385c8..deacb6a 100644
82827--- a/include/linux/mempolicy.h
82828+++ b/include/linux/mempolicy.h
82829@@ -91,6 +91,10 @@ static inline struct mempolicy *mpol_dup(struct mempolicy *pol)
82830 }
82831
82832 #define vma_policy(vma) ((vma)->vm_policy)
82833+static inline void set_vma_policy(struct vm_area_struct *vma, struct mempolicy *pol)
82834+{
82835+ vma->vm_policy = pol;
82836+}
82837
82838 static inline void mpol_get(struct mempolicy *pol)
82839 {
82840@@ -229,6 +233,9 @@ static inline void mpol_free_shared_policy(struct shared_policy *p)
82841 }
82842
82843 #define vma_policy(vma) NULL
82844+static inline void set_vma_policy(struct vm_area_struct *vma, struct mempolicy *pol)
82845+{
82846+}
82847
82848 static inline int
82849 vma_dup_policy(struct vm_area_struct *src, struct vm_area_struct *dst)
82850diff --git a/include/linux/mm.h b/include/linux/mm.h
82851index 5ab2da9..5f0b3df 100644
82852--- a/include/linux/mm.h
82853+++ b/include/linux/mm.h
82854@@ -128,6 +128,11 @@ extern unsigned int kobjsize(const void *objp);
82855 #define VM_HUGETLB 0x00400000 /* Huge TLB Page VM */
82856 #define VM_NONLINEAR 0x00800000 /* Is non-linear (remap_file_pages) */
82857 #define VM_ARCH_1 0x01000000 /* Architecture-specific flag */
82858+
82859+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
82860+#define VM_PAGEEXEC 0x02000000 /* vma->vm_page_prot needs special handling */
82861+#endif
82862+
82863 #define VM_DONTDUMP 0x04000000 /* Do not include in the core dump */
82864
82865 #ifdef CONFIG_MEM_SOFT_DIRTY
82866@@ -238,8 +243,8 @@ struct vm_operations_struct {
82867 /* called by access_process_vm when get_user_pages() fails, typically
82868 * for use by special VMAs that can switch between memory and hardware
82869 */
82870- int (*access)(struct vm_area_struct *vma, unsigned long addr,
82871- void *buf, int len, int write);
82872+ ssize_t (*access)(struct vm_area_struct *vma, unsigned long addr,
82873+ void *buf, size_t len, int write);
82874
82875 /* Called by the /proc/PID/maps code to ask the vma whether it
82876 * has a special name. Returning non-NULL will also cause this
82877@@ -275,6 +280,7 @@ struct vm_operations_struct {
82878 int (*remap_pages)(struct vm_area_struct *vma, unsigned long addr,
82879 unsigned long size, pgoff_t pgoff);
82880 };
82881+typedef struct vm_operations_struct __no_const vm_operations_struct_no_const;
82882
82883 struct mmu_gather;
82884 struct inode;
82885@@ -1165,8 +1171,8 @@ int follow_pfn(struct vm_area_struct *vma, unsigned long address,
82886 unsigned long *pfn);
82887 int follow_phys(struct vm_area_struct *vma, unsigned long address,
82888 unsigned int flags, unsigned long *prot, resource_size_t *phys);
82889-int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
82890- void *buf, int len, int write);
82891+ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
82892+ void *buf, size_t len, int write);
82893
82894 static inline void unmap_shared_mapping_range(struct address_space *mapping,
82895 loff_t const holebegin, loff_t const holelen)
82896@@ -1206,9 +1212,9 @@ static inline int fixup_user_fault(struct task_struct *tsk,
82897 }
82898 #endif
82899
82900-extern int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write);
82901-extern int access_remote_vm(struct mm_struct *mm, unsigned long addr,
82902- void *buf, int len, int write);
82903+extern ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write);
82904+extern ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
82905+ void *buf, size_t len, int write);
82906
82907 long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
82908 unsigned long start, unsigned long nr_pages,
82909@@ -1240,34 +1246,6 @@ int set_page_dirty_lock(struct page *page);
82910 int clear_page_dirty_for_io(struct page *page);
82911 int get_cmdline(struct task_struct *task, char *buffer, int buflen);
82912
82913-/* Is the vma a continuation of the stack vma above it? */
82914-static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
82915-{
82916- return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
82917-}
82918-
82919-static inline int stack_guard_page_start(struct vm_area_struct *vma,
82920- unsigned long addr)
82921-{
82922- return (vma->vm_flags & VM_GROWSDOWN) &&
82923- (vma->vm_start == addr) &&
82924- !vma_growsdown(vma->vm_prev, addr);
82925-}
82926-
82927-/* Is the vma a continuation of the stack vma below it? */
82928-static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
82929-{
82930- return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
82931-}
82932-
82933-static inline int stack_guard_page_end(struct vm_area_struct *vma,
82934- unsigned long addr)
82935-{
82936- return (vma->vm_flags & VM_GROWSUP) &&
82937- (vma->vm_end == addr) &&
82938- !vma_growsup(vma->vm_next, addr);
82939-}
82940-
82941 extern struct task_struct *task_of_stack(struct task_struct *task,
82942 struct vm_area_struct *vma, bool in_group);
82943
82944@@ -1385,8 +1363,15 @@ static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
82945 {
82946 return 0;
82947 }
82948+
82949+static inline int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd,
82950+ unsigned long address)
82951+{
82952+ return 0;
82953+}
82954 #else
82955 int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
82956+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
82957 #endif
82958
82959 #ifdef __PAGETABLE_PMD_FOLDED
82960@@ -1395,8 +1380,15 @@ static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
82961 {
82962 return 0;
82963 }
82964+
82965+static inline int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud,
82966+ unsigned long address)
82967+{
82968+ return 0;
82969+}
82970 #else
82971 int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
82972+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address);
82973 #endif
82974
82975 int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
82976@@ -1414,11 +1406,23 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long a
82977 NULL: pud_offset(pgd, address);
82978 }
82979
82980+static inline pud_t *pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
82981+{
82982+ return (unlikely(pgd_none(*pgd)) && __pud_alloc_kernel(mm, pgd, address))?
82983+ NULL: pud_offset(pgd, address);
82984+}
82985+
82986 static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
82987 {
82988 return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
82989 NULL: pmd_offset(pud, address);
82990 }
82991+
82992+static inline pmd_t *pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
82993+{
82994+ return (unlikely(pud_none(*pud)) && __pmd_alloc_kernel(mm, pud, address))?
82995+ NULL: pmd_offset(pud, address);
82996+}
82997 #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
82998
82999 #if USE_SPLIT_PTE_PTLOCKS
83000@@ -1801,12 +1805,23 @@ extern struct vm_area_struct *copy_vma(struct vm_area_struct **,
83001 bool *need_rmap_locks);
83002 extern void exit_mmap(struct mm_struct *);
83003
83004+#if defined(CONFIG_GRKERNSEC) && (defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC))
83005+extern void gr_learn_resource(const struct task_struct *task, const int res,
83006+ const unsigned long wanted, const int gt);
83007+#else
83008+static inline void gr_learn_resource(const struct task_struct *task, const int res,
83009+ const unsigned long wanted, const int gt)
83010+{
83011+}
83012+#endif
83013+
83014 static inline int check_data_rlimit(unsigned long rlim,
83015 unsigned long new,
83016 unsigned long start,
83017 unsigned long end_data,
83018 unsigned long start_data)
83019 {
83020+ gr_learn_resource(current, RLIMIT_DATA, (new - start) + (end_data - start_data), 1);
83021 if (rlim < RLIM_INFINITY) {
83022 if (((new - start) + (end_data - start_data)) > rlim)
83023 return -ENOSPC;
83024@@ -1831,7 +1846,7 @@ extern int install_special_mapping(struct mm_struct *mm,
83025 unsigned long addr, unsigned long len,
83026 unsigned long flags, struct page **pages);
83027
83028-extern unsigned long get_unmapped_area(struct file *, unsigned long, unsigned long, unsigned long, unsigned long);
83029+extern unsigned long get_unmapped_area(struct file *, unsigned long, unsigned long, unsigned long, unsigned long) __intentional_overflow(-1);
83030
83031 extern unsigned long mmap_region(struct file *file, unsigned long addr,
83032 unsigned long len, vm_flags_t vm_flags, unsigned long pgoff);
83033@@ -1839,6 +1854,7 @@ extern unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
83034 unsigned long len, unsigned long prot, unsigned long flags,
83035 unsigned long pgoff, unsigned long *populate);
83036 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
83037+extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
83038
83039 #ifdef CONFIG_MMU
83040 extern int __mm_populate(unsigned long addr, unsigned long len,
83041@@ -1867,10 +1883,11 @@ struct vm_unmapped_area_info {
83042 unsigned long high_limit;
83043 unsigned long align_mask;
83044 unsigned long align_offset;
83045+ unsigned long threadstack_offset;
83046 };
83047
83048-extern unsigned long unmapped_area(struct vm_unmapped_area_info *info);
83049-extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
83050+extern unsigned long unmapped_area(const struct vm_unmapped_area_info *info);
83051+extern unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info);
83052
83053 /*
83054 * Search for an unmapped address range.
83055@@ -1882,7 +1899,7 @@ extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
83056 * - satisfies (begin_addr & align_mask) == (align_offset & align_mask)
83057 */
83058 static inline unsigned long
83059-vm_unmapped_area(struct vm_unmapped_area_info *info)
83060+vm_unmapped_area(const struct vm_unmapped_area_info *info)
83061 {
83062 if (!(info->flags & VM_UNMAPPED_AREA_TOPDOWN))
83063 return unmapped_area(info);
83064@@ -1944,6 +1961,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
83065 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
83066 struct vm_area_struct **pprev);
83067
83068+extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
83069+extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
83070+extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
83071+
83072 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
83073 NULL if none. Assume start_addr < end_addr. */
83074 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
83075@@ -1973,10 +1994,10 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
83076 }
83077
83078 #ifdef CONFIG_MMU
83079-pgprot_t vm_get_page_prot(unsigned long vm_flags);
83080+pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
83081 void vma_set_page_prot(struct vm_area_struct *vma);
83082 #else
83083-static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
83084+static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
83085 {
83086 return __pgprot(0);
83087 }
83088@@ -2038,6 +2059,11 @@ void vm_stat_account(struct mm_struct *, unsigned long, struct file *, long);
83089 static inline void vm_stat_account(struct mm_struct *mm,
83090 unsigned long flags, struct file *file, long pages)
83091 {
83092+
83093+#ifdef CONFIG_PAX_RANDMMAP
83094+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
83095+#endif
83096+
83097 mm->total_vm += pages;
83098 }
83099 #endif /* CONFIG_PROC_FS */
83100@@ -2126,7 +2152,7 @@ extern int unpoison_memory(unsigned long pfn);
83101 extern int sysctl_memory_failure_early_kill;
83102 extern int sysctl_memory_failure_recovery;
83103 extern void shake_page(struct page *p, int access);
83104-extern atomic_long_t num_poisoned_pages;
83105+extern atomic_long_unchecked_t num_poisoned_pages;
83106 extern int soft_offline_page(struct page *page, int flags);
83107
83108 #if defined(CONFIG_TRANSPARENT_HUGEPAGE) || defined(CONFIG_HUGETLBFS)
83109@@ -2161,5 +2187,11 @@ void __init setup_nr_node_ids(void);
83110 static inline void setup_nr_node_ids(void) {}
83111 #endif
83112
83113+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
83114+extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
83115+#else
83116+static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
83117+#endif
83118+
83119 #endif /* __KERNEL__ */
83120 #endif /* _LINUX_MM_H */
83121diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
83122index 6e0b286..90d9c0d 100644
83123--- a/include/linux/mm_types.h
83124+++ b/include/linux/mm_types.h
83125@@ -308,7 +308,9 @@ struct vm_area_struct {
83126 #ifdef CONFIG_NUMA
83127 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
83128 #endif
83129-};
83130+
83131+ struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
83132+} __randomize_layout;
83133
83134 struct core_thread {
83135 struct task_struct *task;
83136@@ -454,7 +456,25 @@ struct mm_struct {
83137 bool tlb_flush_pending;
83138 #endif
83139 struct uprobes_state uprobes_state;
83140-};
83141+
83142+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
83143+ unsigned long pax_flags;
83144+#endif
83145+
83146+#ifdef CONFIG_PAX_DLRESOLVE
83147+ unsigned long call_dl_resolve;
83148+#endif
83149+
83150+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
83151+ unsigned long call_syscall;
83152+#endif
83153+
83154+#ifdef CONFIG_PAX_ASLR
83155+ unsigned long delta_mmap; /* randomized offset */
83156+ unsigned long delta_stack; /* randomized offset */
83157+#endif
83158+
83159+} __randomize_layout;
83160
83161 static inline void mm_init_cpumask(struct mm_struct *mm)
83162 {
83163diff --git a/include/linux/mmiotrace.h b/include/linux/mmiotrace.h
83164index c5d5278..f0b68c8 100644
83165--- a/include/linux/mmiotrace.h
83166+++ b/include/linux/mmiotrace.h
83167@@ -46,7 +46,7 @@ extern int kmmio_handler(struct pt_regs *regs, unsigned long addr);
83168 /* Called from ioremap.c */
83169 extern void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
83170 void __iomem *addr);
83171-extern void mmiotrace_iounmap(volatile void __iomem *addr);
83172+extern void mmiotrace_iounmap(const volatile void __iomem *addr);
83173
83174 /* For anyone to insert markers. Remember trailing newline. */
83175 extern __printf(1, 2) int mmiotrace_printk(const char *fmt, ...);
83176@@ -66,7 +66,7 @@ static inline void mmiotrace_ioremap(resource_size_t offset,
83177 {
83178 }
83179
83180-static inline void mmiotrace_iounmap(volatile void __iomem *addr)
83181+static inline void mmiotrace_iounmap(const volatile void __iomem *addr)
83182 {
83183 }
83184
83185diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
83186index ffe66e3..b310722 100644
83187--- a/include/linux/mmzone.h
83188+++ b/include/linux/mmzone.h
83189@@ -527,7 +527,7 @@ struct zone {
83190
83191 ZONE_PADDING(_pad3_)
83192 /* Zone statistics */
83193- atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
83194+ atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
83195 } ____cacheline_internodealigned_in_smp;
83196
83197 enum zone_flags {
83198diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
83199index 44eeef0..a92d3f9 100644
83200--- a/include/linux/mod_devicetable.h
83201+++ b/include/linux/mod_devicetable.h
83202@@ -139,7 +139,7 @@ struct usb_device_id {
83203 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
83204 #define USB_DEVICE_ID_MATCH_INT_NUMBER 0x0400
83205
83206-#define HID_ANY_ID (~0)
83207+#define HID_ANY_ID (~0U)
83208 #define HID_BUS_ANY 0xffff
83209 #define HID_GROUP_ANY 0x0000
83210
83211@@ -475,7 +475,7 @@ struct dmi_system_id {
83212 const char *ident;
83213 struct dmi_strmatch matches[4];
83214 void *driver_data;
83215-};
83216+} __do_const;
83217 /*
83218 * struct dmi_device_id appears during expansion of
83219 * "MODULE_DEVICE_TABLE(dmi, x)". Compiler doesn't look inside it
83220diff --git a/include/linux/module.h b/include/linux/module.h
83221index 71f282a..b2387e2 100644
83222--- a/include/linux/module.h
83223+++ b/include/linux/module.h
83224@@ -17,9 +17,11 @@
83225 #include <linux/moduleparam.h>
83226 #include <linux/jump_label.h>
83227 #include <linux/export.h>
83228+#include <linux/fs.h>
83229
83230 #include <linux/percpu.h>
83231 #include <asm/module.h>
83232+#include <asm/pgtable.h>
83233
83234 /* In stripped ARM and x86-64 modules, ~ is surprisingly rare. */
83235 #define MODULE_SIG_STRING "~Module signature appended~\n"
83236@@ -42,7 +44,7 @@ struct module_kobject {
83237 struct kobject *drivers_dir;
83238 struct module_param_attrs *mp;
83239 struct completion *kobj_completion;
83240-};
83241+} __randomize_layout;
83242
83243 struct module_attribute {
83244 struct attribute attr;
83245@@ -54,12 +56,13 @@ struct module_attribute {
83246 int (*test)(struct module *);
83247 void (*free)(struct module *);
83248 };
83249+typedef struct module_attribute __no_const module_attribute_no_const;
83250
83251 struct module_version_attribute {
83252 struct module_attribute mattr;
83253 const char *module_name;
83254 const char *version;
83255-} __attribute__ ((__aligned__(sizeof(void *))));
83256+} __do_const __attribute__ ((__aligned__(sizeof(void *))));
83257
83258 extern ssize_t __modver_version_show(struct module_attribute *,
83259 struct module_kobject *, char *);
83260@@ -235,7 +238,7 @@ struct module {
83261
83262 /* Sysfs stuff. */
83263 struct module_kobject mkobj;
83264- struct module_attribute *modinfo_attrs;
83265+ module_attribute_no_const *modinfo_attrs;
83266 const char *version;
83267 const char *srcversion;
83268 struct kobject *holders_dir;
83269@@ -284,19 +287,16 @@ struct module {
83270 int (*init)(void);
83271
83272 /* If this is non-NULL, vfree after init() returns */
83273- void *module_init;
83274+ void *module_init_rx, *module_init_rw;
83275
83276 /* Here is the actual code + data, vfree'd on unload. */
83277- void *module_core;
83278+ void *module_core_rx, *module_core_rw;
83279
83280 /* Here are the sizes of the init and core sections */
83281- unsigned int init_size, core_size;
83282+ unsigned int init_size_rw, core_size_rw;
83283
83284 /* The size of the executable code in each section. */
83285- unsigned int init_text_size, core_text_size;
83286-
83287- /* Size of RO sections of the module (text+rodata) */
83288- unsigned int init_ro_size, core_ro_size;
83289+ unsigned int init_size_rx, core_size_rx;
83290
83291 /* Arch-specific module values */
83292 struct mod_arch_specific arch;
83293@@ -352,6 +352,10 @@ struct module {
83294 #ifdef CONFIG_EVENT_TRACING
83295 struct ftrace_event_call **trace_events;
83296 unsigned int num_trace_events;
83297+ struct file_operations trace_id;
83298+ struct file_operations trace_enable;
83299+ struct file_operations trace_format;
83300+ struct file_operations trace_filter;
83301 #endif
83302 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
83303 unsigned int num_ftrace_callsites;
83304@@ -375,7 +379,7 @@ struct module {
83305 ctor_fn_t *ctors;
83306 unsigned int num_ctors;
83307 #endif
83308-};
83309+} __randomize_layout;
83310 #ifndef MODULE_ARCH_INIT
83311 #define MODULE_ARCH_INIT {}
83312 #endif
83313@@ -396,18 +400,48 @@ bool is_module_address(unsigned long addr);
83314 bool is_module_percpu_address(unsigned long addr);
83315 bool is_module_text_address(unsigned long addr);
83316
83317+static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
83318+{
83319+
83320+#ifdef CONFIG_PAX_KERNEXEC
83321+ if (ktla_ktva(addr) >= (unsigned long)start &&
83322+ ktla_ktva(addr) < (unsigned long)start + size)
83323+ return 1;
83324+#endif
83325+
83326+ return ((void *)addr >= start && (void *)addr < start + size);
83327+}
83328+
83329+static inline int within_module_core_rx(unsigned long addr, const struct module *mod)
83330+{
83331+ return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
83332+}
83333+
83334+static inline int within_module_core_rw(unsigned long addr, const struct module *mod)
83335+{
83336+ return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
83337+}
83338+
83339+static inline int within_module_init_rx(unsigned long addr, const struct module *mod)
83340+{
83341+ return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
83342+}
83343+
83344+static inline int within_module_init_rw(unsigned long addr, const struct module *mod)
83345+{
83346+ return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
83347+}
83348+
83349 static inline bool within_module_core(unsigned long addr,
83350 const struct module *mod)
83351 {
83352- return (unsigned long)mod->module_core <= addr &&
83353- addr < (unsigned long)mod->module_core + mod->core_size;
83354+ return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
83355 }
83356
83357 static inline bool within_module_init(unsigned long addr,
83358 const struct module *mod)
83359 {
83360- return (unsigned long)mod->module_init <= addr &&
83361- addr < (unsigned long)mod->module_init + mod->init_size;
83362+ return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
83363 }
83364
83365 static inline bool within_module(unsigned long addr, const struct module *mod)
83366diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
83367index 7eeb9bb..68f37e0 100644
83368--- a/include/linux/moduleloader.h
83369+++ b/include/linux/moduleloader.h
83370@@ -25,9 +25,21 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
83371 sections. Returns NULL on failure. */
83372 void *module_alloc(unsigned long size);
83373
83374+#ifdef CONFIG_PAX_KERNEXEC
83375+void *module_alloc_exec(unsigned long size);
83376+#else
83377+#define module_alloc_exec(x) module_alloc(x)
83378+#endif
83379+
83380 /* Free memory returned from module_alloc. */
83381 void module_free(struct module *mod, void *module_region);
83382
83383+#ifdef CONFIG_PAX_KERNEXEC
83384+void module_free_exec(struct module *mod, void *module_region);
83385+#else
83386+#define module_free_exec(x, y) module_free((x), (y))
83387+#endif
83388+
83389 /*
83390 * Apply the given relocation to the (simplified) ELF. Return -error
83391 * or 0.
83392@@ -45,8 +57,10 @@ static inline int apply_relocate(Elf_Shdr *sechdrs,
83393 unsigned int relsec,
83394 struct module *me)
83395 {
83396+#ifdef CONFIG_MODULES
83397 printk(KERN_ERR "module %s: REL relocation unsupported\n",
83398 module_name(me));
83399+#endif
83400 return -ENOEXEC;
83401 }
83402 #endif
83403@@ -68,8 +82,10 @@ static inline int apply_relocate_add(Elf_Shdr *sechdrs,
83404 unsigned int relsec,
83405 struct module *me)
83406 {
83407+#ifdef CONFIG_MODULES
83408 printk(KERN_ERR "module %s: REL relocation unsupported\n",
83409 module_name(me));
83410+#endif
83411 return -ENOEXEC;
83412 }
83413 #endif
83414diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
83415index 1c9effa..1160bdd 100644
83416--- a/include/linux/moduleparam.h
83417+++ b/include/linux/moduleparam.h
83418@@ -323,7 +323,7 @@ static inline void __kernel_param_unlock(void)
83419 * @len is usually just sizeof(string).
83420 */
83421 #define module_param_string(name, string, len, perm) \
83422- static const struct kparam_string __param_string_##name \
83423+ static const struct kparam_string __param_string_##name __used \
83424 = { len, string }; \
83425 __module_param_call(MODULE_PARAM_PREFIX, name, \
83426 &param_ops_string, \
83427@@ -467,7 +467,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
83428 */
83429 #define module_param_array_named(name, array, type, nump, perm) \
83430 param_check_##type(name, &(array)[0]); \
83431- static const struct kparam_array __param_arr_##name \
83432+ static const struct kparam_array __param_arr_##name __used \
83433 = { .max = ARRAY_SIZE(array), .num = nump, \
83434 .ops = &param_ops_##type, \
83435 .elemsize = sizeof(array[0]), .elem = array }; \
83436diff --git a/include/linux/mount.h b/include/linux/mount.h
83437index c2c561d..a5f2a8c 100644
83438--- a/include/linux/mount.h
83439+++ b/include/linux/mount.h
83440@@ -66,7 +66,7 @@ struct vfsmount {
83441 struct dentry *mnt_root; /* root of the mounted tree */
83442 struct super_block *mnt_sb; /* pointer to superblock */
83443 int mnt_flags;
83444-};
83445+} __randomize_layout;
83446
83447 struct file; /* forward dec */
83448 struct path;
83449diff --git a/include/linux/namei.h b/include/linux/namei.h
83450index 492de72..1bddcd4 100644
83451--- a/include/linux/namei.h
83452+++ b/include/linux/namei.h
83453@@ -19,7 +19,7 @@ struct nameidata {
83454 unsigned seq, m_seq;
83455 int last_type;
83456 unsigned depth;
83457- char *saved_names[MAX_NESTED_LINKS + 1];
83458+ const char *saved_names[MAX_NESTED_LINKS + 1];
83459 };
83460
83461 /*
83462@@ -83,12 +83,12 @@ extern void unlock_rename(struct dentry *, struct dentry *);
83463
83464 extern void nd_jump_link(struct nameidata *nd, struct path *path);
83465
83466-static inline void nd_set_link(struct nameidata *nd, char *path)
83467+static inline void nd_set_link(struct nameidata *nd, const char *path)
83468 {
83469 nd->saved_names[nd->depth] = path;
83470 }
83471
83472-static inline char *nd_get_link(struct nameidata *nd)
83473+static inline const char *nd_get_link(const struct nameidata *nd)
83474 {
83475 return nd->saved_names[nd->depth];
83476 }
83477diff --git a/include/linux/net.h b/include/linux/net.h
83478index 17d8339..81656c0 100644
83479--- a/include/linux/net.h
83480+++ b/include/linux/net.h
83481@@ -192,7 +192,7 @@ struct net_proto_family {
83482 int (*create)(struct net *net, struct socket *sock,
83483 int protocol, int kern);
83484 struct module *owner;
83485-};
83486+} __do_const;
83487
83488 struct iovec;
83489 struct kvec;
83490diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
83491index 74fd5d3..86a1e4f 100644
83492--- a/include/linux/netdevice.h
83493+++ b/include/linux/netdevice.h
83494@@ -1156,6 +1156,7 @@ struct net_device_ops {
83495 bool (*ndo_gso_check) (struct sk_buff *skb,
83496 struct net_device *dev);
83497 };
83498+typedef struct net_device_ops __no_const net_device_ops_no_const;
83499
83500 /**
83501 * enum net_device_priv_flags - &struct net_device priv_flags
83502@@ -1498,10 +1499,10 @@ struct net_device {
83503
83504 struct net_device_stats stats;
83505
83506- atomic_long_t rx_dropped;
83507- atomic_long_t tx_dropped;
83508+ atomic_long_unchecked_t rx_dropped;
83509+ atomic_long_unchecked_t tx_dropped;
83510
83511- atomic_t carrier_changes;
83512+ atomic_unchecked_t carrier_changes;
83513
83514 #ifdef CONFIG_WIRELESS_EXT
83515 const struct iw_handler_def * wireless_handlers;
83516diff --git a/include/linux/netfilter.h b/include/linux/netfilter.h
83517index 2517ece..0bbfcfb 100644
83518--- a/include/linux/netfilter.h
83519+++ b/include/linux/netfilter.h
83520@@ -85,7 +85,7 @@ struct nf_sockopt_ops {
83521 #endif
83522 /* Use the module struct to lock set/get code in place */
83523 struct module *owner;
83524-};
83525+} __do_const;
83526
83527 /* Function to register/unregister hook points. */
83528 int nf_register_hook(struct nf_hook_ops *reg);
83529diff --git a/include/linux/netfilter/nfnetlink.h b/include/linux/netfilter/nfnetlink.h
83530index e955d47..04a5338 100644
83531--- a/include/linux/netfilter/nfnetlink.h
83532+++ b/include/linux/netfilter/nfnetlink.h
83533@@ -19,7 +19,7 @@ struct nfnl_callback {
83534 const struct nlattr * const cda[]);
83535 const struct nla_policy *policy; /* netlink attribute policy */
83536 const u_int16_t attr_count; /* number of nlattr's */
83537-};
83538+} __do_const;
83539
83540 struct nfnetlink_subsystem {
83541 const char *name;
83542diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
83543new file mode 100644
83544index 0000000..33f4af8
83545--- /dev/null
83546+++ b/include/linux/netfilter/xt_gradm.h
83547@@ -0,0 +1,9 @@
83548+#ifndef _LINUX_NETFILTER_XT_GRADM_H
83549+#define _LINUX_NETFILTER_XT_GRADM_H 1
83550+
83551+struct xt_gradm_mtinfo {
83552+ __u16 flags;
83553+ __u16 invflags;
83554+};
83555+
83556+#endif
83557diff --git a/include/linux/nls.h b/include/linux/nls.h
83558index 520681b..2b7fabb 100644
83559--- a/include/linux/nls.h
83560+++ b/include/linux/nls.h
83561@@ -31,7 +31,7 @@ struct nls_table {
83562 const unsigned char *charset2upper;
83563 struct module *owner;
83564 struct nls_table *next;
83565-};
83566+} __do_const;
83567
83568 /* this value hold the maximum octet of charset */
83569 #define NLS_MAX_CHARSET_SIZE 6 /* for UTF-8 */
83570@@ -46,7 +46,7 @@ enum utf16_endian {
83571 /* nls_base.c */
83572 extern int __register_nls(struct nls_table *, struct module *);
83573 extern int unregister_nls(struct nls_table *);
83574-extern struct nls_table *load_nls(char *);
83575+extern struct nls_table *load_nls(const char *);
83576 extern void unload_nls(struct nls_table *);
83577 extern struct nls_table *load_nls_default(void);
83578 #define register_nls(nls) __register_nls((nls), THIS_MODULE)
83579diff --git a/include/linux/notifier.h b/include/linux/notifier.h
83580index d14a4c3..a078786 100644
83581--- a/include/linux/notifier.h
83582+++ b/include/linux/notifier.h
83583@@ -54,7 +54,8 @@ struct notifier_block {
83584 notifier_fn_t notifier_call;
83585 struct notifier_block __rcu *next;
83586 int priority;
83587-};
83588+} __do_const;
83589+typedef struct notifier_block __no_const notifier_block_no_const;
83590
83591 struct atomic_notifier_head {
83592 spinlock_t lock;
83593diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
83594index b2a0f15..4d7da32 100644
83595--- a/include/linux/oprofile.h
83596+++ b/include/linux/oprofile.h
83597@@ -138,9 +138,9 @@ int oprofilefs_create_ulong(struct dentry * root,
83598 int oprofilefs_create_ro_ulong(struct dentry * root,
83599 char const * name, ulong * val);
83600
83601-/** Create a file for read-only access to an atomic_t. */
83602+/** Create a file for read-only access to an atomic_unchecked_t. */
83603 int oprofilefs_create_ro_atomic(struct dentry * root,
83604- char const * name, atomic_t * val);
83605+ char const * name, atomic_unchecked_t * val);
83606
83607 /** create a directory */
83608 struct dentry *oprofilefs_mkdir(struct dentry *parent, char const *name);
83609diff --git a/include/linux/padata.h b/include/linux/padata.h
83610index 4386946..f50c615 100644
83611--- a/include/linux/padata.h
83612+++ b/include/linux/padata.h
83613@@ -129,7 +129,7 @@ struct parallel_data {
83614 struct padata_serial_queue __percpu *squeue;
83615 atomic_t reorder_objects;
83616 atomic_t refcnt;
83617- atomic_t seq_nr;
83618+ atomic_unchecked_t seq_nr;
83619 struct padata_cpumask cpumask;
83620 spinlock_t lock ____cacheline_aligned;
83621 unsigned int processed;
83622diff --git a/include/linux/path.h b/include/linux/path.h
83623index d137218..be0c176 100644
83624--- a/include/linux/path.h
83625+++ b/include/linux/path.h
83626@@ -1,13 +1,15 @@
83627 #ifndef _LINUX_PATH_H
83628 #define _LINUX_PATH_H
83629
83630+#include <linux/compiler.h>
83631+
83632 struct dentry;
83633 struct vfsmount;
83634
83635 struct path {
83636 struct vfsmount *mnt;
83637 struct dentry *dentry;
83638-};
83639+} __randomize_layout;
83640
83641 extern void path_get(const struct path *);
83642 extern void path_put(const struct path *);
83643diff --git a/include/linux/pci_hotplug.h b/include/linux/pci_hotplug.h
83644index 2706ee9..e691f7c 100644
83645--- a/include/linux/pci_hotplug.h
83646+++ b/include/linux/pci_hotplug.h
83647@@ -71,7 +71,8 @@ struct hotplug_slot_ops {
83648 int (*get_latch_status) (struct hotplug_slot *slot, u8 *value);
83649 int (*get_adapter_status) (struct hotplug_slot *slot, u8 *value);
83650 int (*reset_slot) (struct hotplug_slot *slot, int probe);
83651-};
83652+} __do_const;
83653+typedef struct hotplug_slot_ops __no_const hotplug_slot_ops_no_const;
83654
83655 /**
83656 * struct hotplug_slot_info - used to notify the hotplug pci core of the state of the slot
83657diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
83658index 893a0d0..d5f996e 100644
83659--- a/include/linux/perf_event.h
83660+++ b/include/linux/perf_event.h
83661@@ -341,8 +341,8 @@ struct perf_event {
83662
83663 enum perf_event_active_state state;
83664 unsigned int attach_state;
83665- local64_t count;
83666- atomic64_t child_count;
83667+ local64_t count; /* PaX: fix it one day */
83668+ atomic64_unchecked_t child_count;
83669
83670 /*
83671 * These are the total time in nanoseconds that the event
83672@@ -393,8 +393,8 @@ struct perf_event {
83673 * These accumulate total time (in nanoseconds) that children
83674 * events have been enabled and running, respectively.
83675 */
83676- atomic64_t child_total_time_enabled;
83677- atomic64_t child_total_time_running;
83678+ atomic64_unchecked_t child_total_time_enabled;
83679+ atomic64_unchecked_t child_total_time_running;
83680
83681 /*
83682 * Protect attach/detach and child_list:
83683@@ -734,7 +734,7 @@ static inline void perf_callchain_store(struct perf_callchain_entry *entry, u64
83684 entry->ip[entry->nr++] = ip;
83685 }
83686
83687-extern int sysctl_perf_event_paranoid;
83688+extern int sysctl_perf_event_legitimately_concerned;
83689 extern int sysctl_perf_event_mlock;
83690 extern int sysctl_perf_event_sample_rate;
83691 extern int sysctl_perf_cpu_time_max_percent;
83692@@ -749,19 +749,24 @@ extern int perf_cpu_time_max_percent_handler(struct ctl_table *table, int write,
83693 loff_t *ppos);
83694
83695
83696+static inline bool perf_paranoid_any(void)
83697+{
83698+ return sysctl_perf_event_legitimately_concerned > 2;
83699+}
83700+
83701 static inline bool perf_paranoid_tracepoint_raw(void)
83702 {
83703- return sysctl_perf_event_paranoid > -1;
83704+ return sysctl_perf_event_legitimately_concerned > -1;
83705 }
83706
83707 static inline bool perf_paranoid_cpu(void)
83708 {
83709- return sysctl_perf_event_paranoid > 0;
83710+ return sysctl_perf_event_legitimately_concerned > 0;
83711 }
83712
83713 static inline bool perf_paranoid_kernel(void)
83714 {
83715- return sysctl_perf_event_paranoid > 1;
83716+ return sysctl_perf_event_legitimately_concerned > 1;
83717 }
83718
83719 extern void perf_event_init(void);
83720@@ -892,7 +897,7 @@ struct perf_pmu_events_attr {
83721 struct device_attribute attr;
83722 u64 id;
83723 const char *event_str;
83724-};
83725+} __do_const;
83726
83727 #define PMU_EVENT_ATTR(_name, _var, _id, _show) \
83728 static struct perf_pmu_events_attr _var = { \
83729diff --git a/include/linux/pid_namespace.h b/include/linux/pid_namespace.h
83730index 1997ffc..4f1f44d 100644
83731--- a/include/linux/pid_namespace.h
83732+++ b/include/linux/pid_namespace.h
83733@@ -44,7 +44,7 @@ struct pid_namespace {
83734 int hide_pid;
83735 int reboot; /* group exit code if this pidns was rebooted */
83736 unsigned int proc_inum;
83737-};
83738+} __randomize_layout;
83739
83740 extern struct pid_namespace init_pid_ns;
83741
83742diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
83743index eb8b8ac..62649e1 100644
83744--- a/include/linux/pipe_fs_i.h
83745+++ b/include/linux/pipe_fs_i.h
83746@@ -47,10 +47,10 @@ struct pipe_inode_info {
83747 struct mutex mutex;
83748 wait_queue_head_t wait;
83749 unsigned int nrbufs, curbuf, buffers;
83750- unsigned int readers;
83751- unsigned int writers;
83752- unsigned int files;
83753- unsigned int waiting_writers;
83754+ atomic_t readers;
83755+ atomic_t writers;
83756+ atomic_t files;
83757+ atomic_t waiting_writers;
83758 unsigned int r_counter;
83759 unsigned int w_counter;
83760 struct page *tmp_page;
83761diff --git a/include/linux/pm.h b/include/linux/pm.h
83762index 383fd68..7a11504 100644
83763--- a/include/linux/pm.h
83764+++ b/include/linux/pm.h
83765@@ -621,6 +621,7 @@ struct dev_pm_domain {
83766 struct dev_pm_ops ops;
83767 void (*detach)(struct device *dev, bool power_off);
83768 };
83769+typedef struct dev_pm_domain __no_const dev_pm_domain_no_const;
83770
83771 /*
83772 * The PM_EVENT_ messages are also used by drivers implementing the legacy
83773diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h
83774index 2e0e06d..824cc9b 100644
83775--- a/include/linux/pm_domain.h
83776+++ b/include/linux/pm_domain.h
83777@@ -36,11 +36,11 @@ struct gpd_dev_ops {
83778 int (*save_state)(struct device *dev);
83779 int (*restore_state)(struct device *dev);
83780 bool (*active_wakeup)(struct device *dev);
83781-};
83782+} __no_const;
83783
83784 struct gpd_cpuidle_data {
83785 unsigned int saved_exit_latency;
83786- struct cpuidle_state *idle_state;
83787+ cpuidle_state_no_const *idle_state;
83788 };
83789
83790 struct generic_pm_domain {
83791diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
83792index 367f49b..d2f5a14 100644
83793--- a/include/linux/pm_runtime.h
83794+++ b/include/linux/pm_runtime.h
83795@@ -125,7 +125,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
83796
83797 static inline void pm_runtime_mark_last_busy(struct device *dev)
83798 {
83799- ACCESS_ONCE(dev->power.last_busy) = jiffies;
83800+ ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
83801 }
83802
83803 #else /* !CONFIG_PM_RUNTIME */
83804diff --git a/include/linux/pnp.h b/include/linux/pnp.h
83805index 195aafc..49a7bc2 100644
83806--- a/include/linux/pnp.h
83807+++ b/include/linux/pnp.h
83808@@ -297,7 +297,7 @@ static inline void pnp_set_drvdata(struct pnp_dev *pdev, void *data)
83809 struct pnp_fixup {
83810 char id[7];
83811 void (*quirk_function) (struct pnp_dev * dev); /* fixup function */
83812-};
83813+} __do_const;
83814
83815 /* config parameters */
83816 #define PNP_CONFIG_NORMAL 0x0001
83817diff --git a/include/linux/poison.h b/include/linux/poison.h
83818index 2110a81..13a11bb 100644
83819--- a/include/linux/poison.h
83820+++ b/include/linux/poison.h
83821@@ -19,8 +19,8 @@
83822 * under normal circumstances, used to verify that nobody uses
83823 * non-initialized list entries.
83824 */
83825-#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
83826-#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
83827+#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
83828+#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
83829
83830 /********** include/linux/timer.h **********/
83831 /*
83832diff --git a/include/linux/power/smartreflex.h b/include/linux/power/smartreflex.h
83833index d8b187c3..9a9257a 100644
83834--- a/include/linux/power/smartreflex.h
83835+++ b/include/linux/power/smartreflex.h
83836@@ -238,7 +238,7 @@ struct omap_sr_class_data {
83837 int (*notify)(struct omap_sr *sr, u32 status);
83838 u8 notify_flags;
83839 u8 class_type;
83840-};
83841+} __do_const;
83842
83843 /**
83844 * struct omap_sr_nvalue_table - Smartreflex n-target value info
83845diff --git a/include/linux/ppp-comp.h b/include/linux/ppp-comp.h
83846index 4ea1d37..80f4b33 100644
83847--- a/include/linux/ppp-comp.h
83848+++ b/include/linux/ppp-comp.h
83849@@ -84,7 +84,7 @@ struct compressor {
83850 struct module *owner;
83851 /* Extra skb space needed by the compressor algorithm */
83852 unsigned int comp_extra;
83853-};
83854+} __do_const;
83855
83856 /*
83857 * The return value from decompress routine is the length of the
83858diff --git a/include/linux/preempt.h b/include/linux/preempt.h
83859index de83b4e..c4b997d 100644
83860--- a/include/linux/preempt.h
83861+++ b/include/linux/preempt.h
83862@@ -27,11 +27,16 @@ extern void preempt_count_sub(int val);
83863 #define preempt_count_dec_and_test() __preempt_count_dec_and_test()
83864 #endif
83865
83866+#define raw_preempt_count_add(val) __preempt_count_add(val)
83867+#define raw_preempt_count_sub(val) __preempt_count_sub(val)
83868+
83869 #define __preempt_count_inc() __preempt_count_add(1)
83870 #define __preempt_count_dec() __preempt_count_sub(1)
83871
83872 #define preempt_count_inc() preempt_count_add(1)
83873+#define raw_preempt_count_inc() raw_preempt_count_add(1)
83874 #define preempt_count_dec() preempt_count_sub(1)
83875+#define raw_preempt_count_dec() raw_preempt_count_sub(1)
83876
83877 #ifdef CONFIG_PREEMPT_COUNT
83878
83879@@ -41,6 +46,12 @@ do { \
83880 barrier(); \
83881 } while (0)
83882
83883+#define raw_preempt_disable() \
83884+do { \
83885+ raw_preempt_count_inc(); \
83886+ barrier(); \
83887+} while (0)
83888+
83889 #define sched_preempt_enable_no_resched() \
83890 do { \
83891 barrier(); \
83892@@ -49,6 +60,12 @@ do { \
83893
83894 #define preempt_enable_no_resched() sched_preempt_enable_no_resched()
83895
83896+#define raw_preempt_enable_no_resched() \
83897+do { \
83898+ barrier(); \
83899+ raw_preempt_count_dec(); \
83900+} while (0)
83901+
83902 #ifdef CONFIG_PREEMPT
83903 #define preempt_enable() \
83904 do { \
83905@@ -113,8 +130,10 @@ do { \
83906 * region.
83907 */
83908 #define preempt_disable() barrier()
83909+#define raw_preempt_disable() barrier()
83910 #define sched_preempt_enable_no_resched() barrier()
83911 #define preempt_enable_no_resched() barrier()
83912+#define raw_preempt_enable_no_resched() barrier()
83913 #define preempt_enable() barrier()
83914 #define preempt_check_resched() do { } while (0)
83915
83916@@ -128,11 +147,13 @@ do { \
83917 /*
83918 * Modules have no business playing preemption tricks.
83919 */
83920+#ifndef CONFIG_PAX_KERNEXEC
83921 #undef sched_preempt_enable_no_resched
83922 #undef preempt_enable_no_resched
83923 #undef preempt_enable_no_resched_notrace
83924 #undef preempt_check_resched
83925 #endif
83926+#endif
83927
83928 #define preempt_set_need_resched() \
83929 do { \
83930diff --git a/include/linux/printk.h b/include/linux/printk.h
83931index d78125f..7f36596 100644
83932--- a/include/linux/printk.h
83933+++ b/include/linux/printk.h
83934@@ -124,6 +124,8 @@ static inline __printf(1, 2) __cold
83935 void early_printk(const char *s, ...) { }
83936 #endif
83937
83938+extern int kptr_restrict;
83939+
83940 #ifdef CONFIG_PRINTK
83941 asmlinkage __printf(5, 0)
83942 int vprintk_emit(int facility, int level,
83943@@ -158,7 +160,6 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
83944
83945 extern int printk_delay_msec;
83946 extern int dmesg_restrict;
83947-extern int kptr_restrict;
83948
83949 extern void wake_up_klogd(void);
83950
83951diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
83952index b97bf2e..f14c92d4 100644
83953--- a/include/linux/proc_fs.h
83954+++ b/include/linux/proc_fs.h
83955@@ -17,8 +17,11 @@ extern void proc_flush_task(struct task_struct *);
83956 extern struct proc_dir_entry *proc_symlink(const char *,
83957 struct proc_dir_entry *, const char *);
83958 extern struct proc_dir_entry *proc_mkdir(const char *, struct proc_dir_entry *);
83959+extern struct proc_dir_entry *proc_mkdir_restrict(const char *, struct proc_dir_entry *);
83960 extern struct proc_dir_entry *proc_mkdir_data(const char *, umode_t,
83961 struct proc_dir_entry *, void *);
83962+extern struct proc_dir_entry *proc_mkdir_data_restrict(const char *, umode_t,
83963+ struct proc_dir_entry *, void *);
83964 extern struct proc_dir_entry *proc_mkdir_mode(const char *, umode_t,
83965 struct proc_dir_entry *);
83966
83967@@ -34,6 +37,19 @@ static inline struct proc_dir_entry *proc_create(
83968 return proc_create_data(name, mode, parent, proc_fops, NULL);
83969 }
83970
83971+static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
83972+ struct proc_dir_entry *parent, const struct file_operations *proc_fops)
83973+{
83974+#ifdef CONFIG_GRKERNSEC_PROC_USER
83975+ return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
83976+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
83977+ return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
83978+#else
83979+ return proc_create_data(name, mode, parent, proc_fops, NULL);
83980+#endif
83981+}
83982+
83983+
83984 extern void proc_set_size(struct proc_dir_entry *, loff_t);
83985 extern void proc_set_user(struct proc_dir_entry *, kuid_t, kgid_t);
83986 extern void *PDE_DATA(const struct inode *);
83987@@ -56,8 +72,12 @@ static inline struct proc_dir_entry *proc_symlink(const char *name,
83988 struct proc_dir_entry *parent,const char *dest) { return NULL;}
83989 static inline struct proc_dir_entry *proc_mkdir(const char *name,
83990 struct proc_dir_entry *parent) {return NULL;}
83991+static inline struct proc_dir_entry *proc_mkdir_restrict(const char *name,
83992+ struct proc_dir_entry *parent) { return NULL; }
83993 static inline struct proc_dir_entry *proc_mkdir_data(const char *name,
83994 umode_t mode, struct proc_dir_entry *parent, void *data) { return NULL; }
83995+static inline struct proc_dir_entry *proc_mkdir_data_restrict(const char *name,
83996+ umode_t mode, struct proc_dir_entry *parent, void *data) { return NULL; }
83997 static inline struct proc_dir_entry *proc_mkdir_mode(const char *name,
83998 umode_t mode, struct proc_dir_entry *parent) { return NULL; }
83999 #define proc_create(name, mode, parent, proc_fops) ({NULL;})
84000@@ -79,7 +99,7 @@ struct net;
84001 static inline struct proc_dir_entry *proc_net_mkdir(
84002 struct net *net, const char *name, struct proc_dir_entry *parent)
84003 {
84004- return proc_mkdir_data(name, 0, parent, net);
84005+ return proc_mkdir_data_restrict(name, 0, parent, net);
84006 }
84007
84008 #endif /* _LINUX_PROC_FS_H */
84009diff --git a/include/linux/proc_ns.h b/include/linux/proc_ns.h
84010index 34a1e10..70f6bde 100644
84011--- a/include/linux/proc_ns.h
84012+++ b/include/linux/proc_ns.h
84013@@ -14,7 +14,7 @@ struct proc_ns_operations {
84014 void (*put)(void *ns);
84015 int (*install)(struct nsproxy *nsproxy, void *ns);
84016 unsigned int (*inum)(void *ns);
84017-};
84018+} __do_const __randomize_layout;
84019
84020 struct proc_ns {
84021 void *ns;
84022diff --git a/include/linux/quota.h b/include/linux/quota.h
84023index 80d345a..9e89a9a 100644
84024--- a/include/linux/quota.h
84025+++ b/include/linux/quota.h
84026@@ -70,7 +70,7 @@ struct kqid { /* Type in which we store the quota identifier */
84027
84028 extern bool qid_eq(struct kqid left, struct kqid right);
84029 extern bool qid_lt(struct kqid left, struct kqid right);
84030-extern qid_t from_kqid(struct user_namespace *to, struct kqid qid);
84031+extern qid_t from_kqid(struct user_namespace *to, struct kqid qid) __intentional_overflow(-1);
84032 extern qid_t from_kqid_munged(struct user_namespace *to, struct kqid qid);
84033 extern bool qid_valid(struct kqid qid);
84034
84035diff --git a/include/linux/random.h b/include/linux/random.h
84036index b05856e..0a9f14e 100644
84037--- a/include/linux/random.h
84038+++ b/include/linux/random.h
84039@@ -9,9 +9,19 @@
84040 #include <uapi/linux/random.h>
84041
84042 extern void add_device_randomness(const void *, unsigned int);
84043+
84044+static inline void add_latent_entropy(void)
84045+{
84046+
84047+#ifdef LATENT_ENTROPY_PLUGIN
84048+ add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
84049+#endif
84050+
84051+}
84052+
84053 extern void add_input_randomness(unsigned int type, unsigned int code,
84054- unsigned int value);
84055-extern void add_interrupt_randomness(int irq, int irq_flags);
84056+ unsigned int value) __latent_entropy;
84057+extern void add_interrupt_randomness(int irq, int irq_flags) __latent_entropy;
84058
84059 extern void get_random_bytes(void *buf, int nbytes);
84060 extern void get_random_bytes_arch(void *buf, int nbytes);
84061@@ -22,10 +32,10 @@ extern int random_int_secret_init(void);
84062 extern const struct file_operations random_fops, urandom_fops;
84063 #endif
84064
84065-unsigned int get_random_int(void);
84066+unsigned int __intentional_overflow(-1) get_random_int(void);
84067 unsigned long randomize_range(unsigned long start, unsigned long end, unsigned long len);
84068
84069-u32 prandom_u32(void);
84070+u32 prandom_u32(void) __intentional_overflow(-1);
84071 void prandom_bytes(void *buf, size_t nbytes);
84072 void prandom_seed(u32 seed);
84073 void prandom_reseed_late(void);
84074@@ -37,6 +47,11 @@ struct rnd_state {
84075 u32 prandom_u32_state(struct rnd_state *state);
84076 void prandom_bytes_state(struct rnd_state *state, void *buf, size_t nbytes);
84077
84078+static inline unsigned long __intentional_overflow(-1) pax_get_random_long(void)
84079+{
84080+ return prandom_u32() + (sizeof(long) > 4 ? (unsigned long)prandom_u32() << 32 : 0);
84081+}
84082+
84083 /**
84084 * prandom_u32_max - returns a pseudo-random number in interval [0, ep_ro)
84085 * @ep_ro: right open interval endpoint
84086@@ -49,7 +64,7 @@ void prandom_bytes_state(struct rnd_state *state, void *buf, size_t nbytes);
84087 *
84088 * Returns: pseudo-random number in interval [0, ep_ro)
84089 */
84090-static inline u32 prandom_u32_max(u32 ep_ro)
84091+static inline u32 __intentional_overflow(-1) prandom_u32_max(u32 ep_ro)
84092 {
84093 return (u32)(((u64) prandom_u32() * ep_ro) >> 32);
84094 }
84095diff --git a/include/linux/rbtree_augmented.h b/include/linux/rbtree_augmented.h
84096index 378c5ee..aa84a47 100644
84097--- a/include/linux/rbtree_augmented.h
84098+++ b/include/linux/rbtree_augmented.h
84099@@ -90,7 +90,9 @@ rbname ## _rotate(struct rb_node *rb_old, struct rb_node *rb_new) \
84100 old->rbaugmented = rbcompute(old); \
84101 } \
84102 rbstatic const struct rb_augment_callbacks rbname = { \
84103- rbname ## _propagate, rbname ## _copy, rbname ## _rotate \
84104+ .propagate = rbname ## _propagate, \
84105+ .copy = rbname ## _copy, \
84106+ .rotate = rbname ## _rotate \
84107 };
84108
84109
84110diff --git a/include/linux/rculist.h b/include/linux/rculist.h
84111index 372ad5e..d4373f8 100644
84112--- a/include/linux/rculist.h
84113+++ b/include/linux/rculist.h
84114@@ -29,8 +29,8 @@
84115 */
84116 static inline void INIT_LIST_HEAD_RCU(struct list_head *list)
84117 {
84118- ACCESS_ONCE(list->next) = list;
84119- ACCESS_ONCE(list->prev) = list;
84120+ ACCESS_ONCE_RW(list->next) = list;
84121+ ACCESS_ONCE_RW(list->prev) = list;
84122 }
84123
84124 /*
84125@@ -59,6 +59,9 @@ void __list_add_rcu(struct list_head *new,
84126 struct list_head *prev, struct list_head *next);
84127 #endif
84128
84129+void __pax_list_add_rcu(struct list_head *new,
84130+ struct list_head *prev, struct list_head *next);
84131+
84132 /**
84133 * list_add_rcu - add a new entry to rcu-protected list
84134 * @new: new entry to be added
84135@@ -80,6 +83,11 @@ static inline void list_add_rcu(struct list_head *new, struct list_head *head)
84136 __list_add_rcu(new, head, head->next);
84137 }
84138
84139+static inline void pax_list_add_rcu(struct list_head *new, struct list_head *head)
84140+{
84141+ __pax_list_add_rcu(new, head, head->next);
84142+}
84143+
84144 /**
84145 * list_add_tail_rcu - add a new entry to rcu-protected list
84146 * @new: new entry to be added
84147@@ -102,6 +110,12 @@ static inline void list_add_tail_rcu(struct list_head *new,
84148 __list_add_rcu(new, head->prev, head);
84149 }
84150
84151+static inline void pax_list_add_tail_rcu(struct list_head *new,
84152+ struct list_head *head)
84153+{
84154+ __pax_list_add_rcu(new, head->prev, head);
84155+}
84156+
84157 /**
84158 * list_del_rcu - deletes entry from list without re-initialization
84159 * @entry: the element to delete from the list.
84160@@ -132,6 +146,8 @@ static inline void list_del_rcu(struct list_head *entry)
84161 entry->prev = LIST_POISON2;
84162 }
84163
84164+extern void pax_list_del_rcu(struct list_head *entry);
84165+
84166 /**
84167 * hlist_del_init_rcu - deletes entry from hash list with re-initialization
84168 * @n: the element to delete from the hash list.
84169diff --git a/include/linux/rcupdate.h b/include/linux/rcupdate.h
84170index 53ff1a7..c40f0ab 100644
84171--- a/include/linux/rcupdate.h
84172+++ b/include/linux/rcupdate.h
84173@@ -332,7 +332,7 @@ extern struct srcu_struct tasks_rcu_exit_srcu;
84174 #define rcu_note_voluntary_context_switch(t) \
84175 do { \
84176 if (ACCESS_ONCE((t)->rcu_tasks_holdout)) \
84177- ACCESS_ONCE((t)->rcu_tasks_holdout) = false; \
84178+ ACCESS_ONCE_RW((t)->rcu_tasks_holdout) = false; \
84179 } while (0)
84180 #else /* #ifdef CONFIG_TASKS_RCU */
84181 #define TASKS_RCU(x) do { } while (0)
84182diff --git a/include/linux/reboot.h b/include/linux/reboot.h
84183index 67fc8fc..a90f7d8 100644
84184--- a/include/linux/reboot.h
84185+++ b/include/linux/reboot.h
84186@@ -47,9 +47,9 @@ extern void do_kernel_restart(char *cmd);
84187 */
84188
84189 extern void migrate_to_reboot_cpu(void);
84190-extern void machine_restart(char *cmd);
84191-extern void machine_halt(void);
84192-extern void machine_power_off(void);
84193+extern void machine_restart(char *cmd) __noreturn;
84194+extern void machine_halt(void) __noreturn;
84195+extern void machine_power_off(void) __noreturn;
84196
84197 extern void machine_shutdown(void);
84198 struct pt_regs;
84199@@ -60,9 +60,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
84200 */
84201
84202 extern void kernel_restart_prepare(char *cmd);
84203-extern void kernel_restart(char *cmd);
84204-extern void kernel_halt(void);
84205-extern void kernel_power_off(void);
84206+extern void kernel_restart(char *cmd) __noreturn;
84207+extern void kernel_halt(void) __noreturn;
84208+extern void kernel_power_off(void) __noreturn;
84209
84210 extern int C_A_D; /* for sysctl */
84211 void ctrl_alt_del(void);
84212@@ -76,7 +76,7 @@ extern int orderly_poweroff(bool force);
84213 * Emergency restart, callable from an interrupt handler.
84214 */
84215
84216-extern void emergency_restart(void);
84217+extern void emergency_restart(void) __noreturn;
84218 #include <asm/emergency-restart.h>
84219
84220 #endif /* _LINUX_REBOOT_H */
84221diff --git a/include/linux/regset.h b/include/linux/regset.h
84222index 8e0c9fe..ac4d221 100644
84223--- a/include/linux/regset.h
84224+++ b/include/linux/regset.h
84225@@ -161,7 +161,8 @@ struct user_regset {
84226 unsigned int align;
84227 unsigned int bias;
84228 unsigned int core_note_type;
84229-};
84230+} __do_const;
84231+typedef struct user_regset __no_const user_regset_no_const;
84232
84233 /**
84234 * struct user_regset_view - available regsets
84235diff --git a/include/linux/relay.h b/include/linux/relay.h
84236index d7c8359..818daf5 100644
84237--- a/include/linux/relay.h
84238+++ b/include/linux/relay.h
84239@@ -157,7 +157,7 @@ struct rchan_callbacks
84240 * The callback should return 0 if successful, negative if not.
84241 */
84242 int (*remove_buf_file)(struct dentry *dentry);
84243-};
84244+} __no_const;
84245
84246 /*
84247 * CONFIG_RELAY kernel API, kernel/relay.c
84248diff --git a/include/linux/rio.h b/include/linux/rio.h
84249index 6bda06f..bf39a9b 100644
84250--- a/include/linux/rio.h
84251+++ b/include/linux/rio.h
84252@@ -358,7 +358,7 @@ struct rio_ops {
84253 int (*map_inb)(struct rio_mport *mport, dma_addr_t lstart,
84254 u64 rstart, u32 size, u32 flags);
84255 void (*unmap_inb)(struct rio_mport *mport, dma_addr_t lstart);
84256-};
84257+} __no_const;
84258
84259 #define RIO_RESOURCE_MEM 0x00000100
84260 #define RIO_RESOURCE_DOORBELL 0x00000200
84261diff --git a/include/linux/rmap.h b/include/linux/rmap.h
84262index c0c2bce..4813524 100644
84263--- a/include/linux/rmap.h
84264+++ b/include/linux/rmap.h
84265@@ -144,8 +144,8 @@ static inline void anon_vma_unlock_read(struct anon_vma *anon_vma)
84266 void anon_vma_init(void); /* create anon_vma_cachep */
84267 int anon_vma_prepare(struct vm_area_struct *);
84268 void unlink_anon_vmas(struct vm_area_struct *);
84269-int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
84270-int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
84271+int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
84272+int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
84273
84274 static inline void anon_vma_merge(struct vm_area_struct *vma,
84275 struct vm_area_struct *next)
84276diff --git a/include/linux/scatterlist.h b/include/linux/scatterlist.h
84277index ed8f9e7..999bc96 100644
84278--- a/include/linux/scatterlist.h
84279+++ b/include/linux/scatterlist.h
84280@@ -1,6 +1,7 @@
84281 #ifndef _LINUX_SCATTERLIST_H
84282 #define _LINUX_SCATTERLIST_H
84283
84284+#include <linux/sched.h>
84285 #include <linux/string.h>
84286 #include <linux/bug.h>
84287 #include <linux/mm.h>
84288@@ -114,6 +115,12 @@ static inline void sg_set_buf(struct scatterlist *sg, const void *buf,
84289 #ifdef CONFIG_DEBUG_SG
84290 BUG_ON(!virt_addr_valid(buf));
84291 #endif
84292+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
84293+ if (object_starts_on_stack(buf)) {
84294+ void *adjbuf = buf - current->stack + current->lowmem_stack;
84295+ sg_set_page(sg, virt_to_page(adjbuf), buflen, offset_in_page(adjbuf));
84296+ } else
84297+#endif
84298 sg_set_page(sg, virt_to_page(buf), buflen, offset_in_page(buf));
84299 }
84300
84301diff --git a/include/linux/sched.h b/include/linux/sched.h
84302index 5e344bb..0743255 100644
84303--- a/include/linux/sched.h
84304+++ b/include/linux/sched.h
84305@@ -133,6 +133,7 @@ struct fs_struct;
84306 struct perf_event_context;
84307 struct blk_plug;
84308 struct filename;
84309+struct linux_binprm;
84310
84311 #define VMACACHE_BITS 2
84312 #define VMACACHE_SIZE (1U << VMACACHE_BITS)
84313@@ -376,7 +377,7 @@ extern char __sched_text_start[], __sched_text_end[];
84314 extern int in_sched_functions(unsigned long addr);
84315
84316 #define MAX_SCHEDULE_TIMEOUT LONG_MAX
84317-extern signed long schedule_timeout(signed long timeout);
84318+extern signed long schedule_timeout(signed long timeout) __intentional_overflow(-1);
84319 extern signed long schedule_timeout_interruptible(signed long timeout);
84320 extern signed long schedule_timeout_killable(signed long timeout);
84321 extern signed long schedule_timeout_uninterruptible(signed long timeout);
84322@@ -387,6 +388,19 @@ struct nsproxy;
84323 struct user_namespace;
84324
84325 #ifdef CONFIG_MMU
84326+
84327+#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
84328+extern unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags);
84329+#else
84330+static inline unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
84331+{
84332+ return 0;
84333+}
84334+#endif
84335+
84336+extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset);
84337+extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset);
84338+
84339 extern void arch_pick_mmap_layout(struct mm_struct *mm);
84340 extern unsigned long
84341 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
84342@@ -685,6 +699,17 @@ struct signal_struct {
84343 #ifdef CONFIG_TASKSTATS
84344 struct taskstats *stats;
84345 #endif
84346+
84347+#ifdef CONFIG_GRKERNSEC
84348+ u32 curr_ip;
84349+ u32 saved_ip;
84350+ u32 gr_saddr;
84351+ u32 gr_daddr;
84352+ u16 gr_sport;
84353+ u16 gr_dport;
84354+ u8 used_accept:1;
84355+#endif
84356+
84357 #ifdef CONFIG_AUDIT
84358 unsigned audit_tty;
84359 unsigned audit_tty_log_passwd;
84360@@ -711,7 +736,7 @@ struct signal_struct {
84361 struct mutex cred_guard_mutex; /* guard against foreign influences on
84362 * credential calculations
84363 * (notably. ptrace) */
84364-};
84365+} __randomize_layout;
84366
84367 /*
84368 * Bits in flags field of signal_struct.
84369@@ -764,6 +789,14 @@ struct user_struct {
84370 struct key *session_keyring; /* UID's default session keyring */
84371 #endif
84372
84373+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
84374+ unsigned char kernel_banned;
84375+#endif
84376+#ifdef CONFIG_GRKERNSEC_BRUTE
84377+ unsigned char suid_banned;
84378+ unsigned long suid_ban_expires;
84379+#endif
84380+
84381 /* Hash table maintenance information */
84382 struct hlist_node uidhash_node;
84383 kuid_t uid;
84384@@ -771,7 +804,7 @@ struct user_struct {
84385 #ifdef CONFIG_PERF_EVENTS
84386 atomic_long_t locked_vm;
84387 #endif
84388-};
84389+} __randomize_layout;
84390
84391 extern int uids_sysfs_init(void);
84392
84393@@ -1235,6 +1268,9 @@ enum perf_event_task_context {
84394 struct task_struct {
84395 volatile long state; /* -1 unrunnable, 0 runnable, >0 stopped */
84396 void *stack;
84397+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
84398+ void *lowmem_stack;
84399+#endif
84400 atomic_t usage;
84401 unsigned int flags; /* per process flags, defined below */
84402 unsigned int ptrace;
84403@@ -1362,8 +1398,8 @@ struct task_struct {
84404 struct list_head thread_node;
84405
84406 struct completion *vfork_done; /* for vfork() */
84407- int __user *set_child_tid; /* CLONE_CHILD_SETTID */
84408- int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
84409+ pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
84410+ pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
84411
84412 cputime_t utime, stime, utimescaled, stimescaled;
84413 cputime_t gtime;
84414@@ -1388,11 +1424,6 @@ struct task_struct {
84415 struct task_cputime cputime_expires;
84416 struct list_head cpu_timers[3];
84417
84418-/* process credentials */
84419- const struct cred __rcu *real_cred; /* objective and real subjective task
84420- * credentials (COW) */
84421- const struct cred __rcu *cred; /* effective (overridable) subjective task
84422- * credentials (COW) */
84423 char comm[TASK_COMM_LEN]; /* executable name excluding path
84424 - access with [gs]et_task_comm (which lock
84425 it with task_lock())
84426@@ -1410,6 +1441,10 @@ struct task_struct {
84427 #endif
84428 /* CPU-specific state of this task */
84429 struct thread_struct thread;
84430+/* thread_info moved to task_struct */
84431+#ifdef CONFIG_X86
84432+ struct thread_info tinfo;
84433+#endif
84434 /* filesystem information */
84435 struct fs_struct *fs;
84436 /* open file information */
84437@@ -1484,6 +1519,10 @@ struct task_struct {
84438 gfp_t lockdep_reclaim_gfp;
84439 #endif
84440
84441+/* process credentials */
84442+ const struct cred __rcu *real_cred; /* objective and real subjective task
84443+ * credentials (COW) */
84444+
84445 /* journalling filesystem info */
84446 void *journal_info;
84447
84448@@ -1522,6 +1561,10 @@ struct task_struct {
84449 /* cg_list protected by css_set_lock and tsk->alloc_lock */
84450 struct list_head cg_list;
84451 #endif
84452+
84453+ const struct cred __rcu *cred; /* effective (overridable) subjective task
84454+ * credentials (COW) */
84455+
84456 #ifdef CONFIG_FUTEX
84457 struct robust_list_head __user *robust_list;
84458 #ifdef CONFIG_COMPAT
84459@@ -1635,7 +1678,7 @@ struct task_struct {
84460 * Number of functions that haven't been traced
84461 * because of depth overrun.
84462 */
84463- atomic_t trace_overrun;
84464+ atomic_unchecked_t trace_overrun;
84465 /* Pause for the tracing */
84466 atomic_t tracing_graph_pause;
84467 #endif
84468@@ -1661,7 +1704,78 @@ struct task_struct {
84469 unsigned int sequential_io;
84470 unsigned int sequential_io_avg;
84471 #endif
84472-};
84473+
84474+#ifdef CONFIG_GRKERNSEC
84475+ /* grsecurity */
84476+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
84477+ u64 exec_id;
84478+#endif
84479+#ifdef CONFIG_GRKERNSEC_SETXID
84480+ const struct cred *delayed_cred;
84481+#endif
84482+ struct dentry *gr_chroot_dentry;
84483+ struct acl_subject_label *acl;
84484+ struct acl_subject_label *tmpacl;
84485+ struct acl_role_label *role;
84486+ struct file *exec_file;
84487+ unsigned long brute_expires;
84488+ u16 acl_role_id;
84489+ u8 inherited;
84490+ /* is this the task that authenticated to the special role */
84491+ u8 acl_sp_role;
84492+ u8 is_writable;
84493+ u8 brute;
84494+ u8 gr_is_chrooted;
84495+#endif
84496+
84497+} __randomize_layout;
84498+
84499+#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
84500+#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
84501+#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
84502+#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
84503+/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
84504+#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
84505+
84506+#ifdef CONFIG_PAX_SOFTMODE
84507+extern int pax_softmode;
84508+#endif
84509+
84510+extern int pax_check_flags(unsigned long *);
84511+#define PAX_PARSE_FLAGS_FALLBACK (~0UL)
84512+
84513+/* if tsk != current then task_lock must be held on it */
84514+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
84515+static inline unsigned long pax_get_flags(struct task_struct *tsk)
84516+{
84517+ if (likely(tsk->mm))
84518+ return tsk->mm->pax_flags;
84519+ else
84520+ return 0UL;
84521+}
84522+
84523+/* if tsk != current then task_lock must be held on it */
84524+static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
84525+{
84526+ if (likely(tsk->mm)) {
84527+ tsk->mm->pax_flags = flags;
84528+ return 0;
84529+ }
84530+ return -EINVAL;
84531+}
84532+#endif
84533+
84534+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
84535+extern void pax_set_initial_flags(struct linux_binprm *bprm);
84536+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
84537+extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
84538+#endif
84539+
84540+struct path;
84541+extern char *pax_get_path(const struct path *path, char *buf, int buflen);
84542+extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
84543+extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
84544+extern void pax_report_refcount_overflow(struct pt_regs *regs);
84545
84546 /* Future-safe accessor for struct task_struct's cpus_allowed. */
84547 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
84548@@ -1743,7 +1857,7 @@ struct pid_namespace;
84549 pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
84550 struct pid_namespace *ns);
84551
84552-static inline pid_t task_pid_nr(struct task_struct *tsk)
84553+static inline pid_t task_pid_nr(const struct task_struct *tsk)
84554 {
84555 return tsk->pid;
84556 }
84557@@ -2106,6 +2220,25 @@ extern u64 sched_clock_cpu(int cpu);
84558
84559 extern void sched_clock_init(void);
84560
84561+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
84562+static inline void populate_stack(void)
84563+{
84564+ struct task_struct *curtask = current;
84565+ int c;
84566+ int *ptr = curtask->stack;
84567+ int *end = curtask->stack + THREAD_SIZE;
84568+
84569+ while (ptr < end) {
84570+ c = *(volatile int *)ptr;
84571+ ptr += PAGE_SIZE/sizeof(int);
84572+ }
84573+}
84574+#else
84575+static inline void populate_stack(void)
84576+{
84577+}
84578+#endif
84579+
84580 #ifndef CONFIG_HAVE_UNSTABLE_SCHED_CLOCK
84581 static inline void sched_clock_tick(void)
84582 {
84583@@ -2239,7 +2372,9 @@ void yield(void);
84584 extern struct exec_domain default_exec_domain;
84585
84586 union thread_union {
84587+#ifndef CONFIG_X86
84588 struct thread_info thread_info;
84589+#endif
84590 unsigned long stack[THREAD_SIZE/sizeof(long)];
84591 };
84592
84593@@ -2272,6 +2407,7 @@ extern struct pid_namespace init_pid_ns;
84594 */
84595
84596 extern struct task_struct *find_task_by_vpid(pid_t nr);
84597+extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
84598 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
84599 struct pid_namespace *ns);
84600
84601@@ -2436,7 +2572,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
84602 extern void exit_itimers(struct signal_struct *);
84603 extern void flush_itimer_signals(void);
84604
84605-extern void do_group_exit(int);
84606+extern __noreturn void do_group_exit(int);
84607
84608 extern int do_execve(struct filename *,
84609 const char __user * const __user *,
84610@@ -2653,9 +2789,9 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
84611 #define task_stack_end_corrupted(task) \
84612 (*(end_of_stack(task)) != STACK_END_MAGIC)
84613
84614-static inline int object_is_on_stack(void *obj)
84615+static inline int object_starts_on_stack(const void *obj)
84616 {
84617- void *stack = task_stack_page(current);
84618+ const void *stack = task_stack_page(current);
84619
84620 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
84621 }
84622diff --git a/include/linux/sched/sysctl.h b/include/linux/sched/sysctl.h
84623index 596a0e0..bea77ec 100644
84624--- a/include/linux/sched/sysctl.h
84625+++ b/include/linux/sched/sysctl.h
84626@@ -34,6 +34,7 @@ enum { sysctl_hung_task_timeout_secs = 0 };
84627 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
84628
84629 extern int sysctl_max_map_count;
84630+extern unsigned long sysctl_heap_stack_gap;
84631
84632 extern unsigned int sysctl_sched_latency;
84633 extern unsigned int sysctl_sched_min_granularity;
84634diff --git a/include/linux/security.h b/include/linux/security.h
84635index ba96471..74fb3f6 100644
84636--- a/include/linux/security.h
84637+++ b/include/linux/security.h
84638@@ -27,6 +27,7 @@
84639 #include <linux/slab.h>
84640 #include <linux/err.h>
84641 #include <linux/string.h>
84642+#include <linux/grsecurity.h>
84643
84644 struct linux_binprm;
84645 struct cred;
84646@@ -116,8 +117,6 @@ struct seq_file;
84647
84648 extern int cap_netlink_send(struct sock *sk, struct sk_buff *skb);
84649
84650-void reset_security_ops(void);
84651-
84652 #ifdef CONFIG_MMU
84653 extern unsigned long mmap_min_addr;
84654 extern unsigned long dac_mmap_min_addr;
84655@@ -1729,7 +1728,7 @@ struct security_operations {
84656 struct audit_context *actx);
84657 void (*audit_rule_free) (void *lsmrule);
84658 #endif /* CONFIG_AUDIT */
84659-};
84660+} __randomize_layout;
84661
84662 /* prototypes */
84663 extern int security_init(void);
84664diff --git a/include/linux/semaphore.h b/include/linux/semaphore.h
84665index dc368b8..e895209 100644
84666--- a/include/linux/semaphore.h
84667+++ b/include/linux/semaphore.h
84668@@ -37,7 +37,7 @@ static inline void sema_init(struct semaphore *sem, int val)
84669 }
84670
84671 extern void down(struct semaphore *sem);
84672-extern int __must_check down_interruptible(struct semaphore *sem);
84673+extern int __must_check down_interruptible(struct semaphore *sem) __intentional_overflow(-1);
84674 extern int __must_check down_killable(struct semaphore *sem);
84675 extern int __must_check down_trylock(struct semaphore *sem);
84676 extern int __must_check down_timeout(struct semaphore *sem, long jiffies);
84677diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
84678index 52e0097..383f21d 100644
84679--- a/include/linux/seq_file.h
84680+++ b/include/linux/seq_file.h
84681@@ -27,6 +27,9 @@ struct seq_file {
84682 struct mutex lock;
84683 const struct seq_operations *op;
84684 int poll_event;
84685+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
84686+ u64 exec_id;
84687+#endif
84688 #ifdef CONFIG_USER_NS
84689 struct user_namespace *user_ns;
84690 #endif
84691@@ -39,6 +42,7 @@ struct seq_operations {
84692 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
84693 int (*show) (struct seq_file *m, void *v);
84694 };
84695+typedef struct seq_operations __no_const seq_operations_no_const;
84696
84697 #define SEQ_SKIP 1
84698
84699@@ -96,6 +100,7 @@ void seq_pad(struct seq_file *m, char c);
84700
84701 char *mangle_path(char *s, const char *p, const char *esc);
84702 int seq_open(struct file *, const struct seq_operations *);
84703+int seq_open_restrict(struct file *, const struct seq_operations *);
84704 ssize_t seq_read(struct file *, char __user *, size_t, loff_t *);
84705 loff_t seq_lseek(struct file *, loff_t, int);
84706 int seq_release(struct inode *, struct file *);
84707@@ -138,6 +143,7 @@ static inline int seq_nodemask_list(struct seq_file *m, nodemask_t *mask)
84708 }
84709
84710 int single_open(struct file *, int (*)(struct seq_file *, void *), void *);
84711+int single_open_restrict(struct file *, int (*)(struct seq_file *, void *), void *);
84712 int single_open_size(struct file *, int (*)(struct seq_file *, void *), void *, size_t);
84713 int single_release(struct inode *, struct file *);
84714 void *__seq_open_private(struct file *, const struct seq_operations *, int);
84715diff --git a/include/linux/shm.h b/include/linux/shm.h
84716index 6fb8016..ab4465e 100644
84717--- a/include/linux/shm.h
84718+++ b/include/linux/shm.h
84719@@ -22,6 +22,10 @@ struct shmid_kernel /* private to the kernel */
84720 /* The task created the shm object. NULL if the task is dead. */
84721 struct task_struct *shm_creator;
84722 struct list_head shm_clist; /* list by creator */
84723+#ifdef CONFIG_GRKERNSEC
84724+ u64 shm_createtime;
84725+ pid_t shm_lapid;
84726+#endif
84727 };
84728
84729 /* shm_mode upper byte flags */
84730diff --git a/include/linux/signal.h b/include/linux/signal.h
84731index ab1e039..ad4229e 100644
84732--- a/include/linux/signal.h
84733+++ b/include/linux/signal.h
84734@@ -289,7 +289,7 @@ static inline void allow_signal(int sig)
84735 * know it'll be handled, so that they don't get converted to
84736 * SIGKILL or just silently dropped.
84737 */
84738- kernel_sigaction(sig, (__force __sighandler_t)2);
84739+ kernel_sigaction(sig, (__force_user __sighandler_t)2);
84740 }
84741
84742 static inline void disallow_signal(int sig)
84743diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
84744index 6c8b6f6..5a0f4bd 100644
84745--- a/include/linux/skbuff.h
84746+++ b/include/linux/skbuff.h
84747@@ -773,7 +773,7 @@ bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
84748 struct sk_buff *__alloc_skb(unsigned int size, gfp_t priority, int flags,
84749 int node);
84750 struct sk_buff *build_skb(void *data, unsigned int frag_size);
84751-static inline struct sk_buff *alloc_skb(unsigned int size,
84752+static inline struct sk_buff * __intentional_overflow(0) alloc_skb(unsigned int size,
84753 gfp_t priority)
84754 {
84755 return __alloc_skb(size, priority, 0, NUMA_NO_NODE);
84756@@ -1962,7 +1962,7 @@ static inline u32 skb_inner_network_header_len(const struct sk_buff *skb)
84757 return skb->inner_transport_header - skb->inner_network_header;
84758 }
84759
84760-static inline int skb_network_offset(const struct sk_buff *skb)
84761+static inline int __intentional_overflow(0) skb_network_offset(const struct sk_buff *skb)
84762 {
84763 return skb_network_header(skb) - skb->data;
84764 }
84765@@ -2022,7 +2022,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
84766 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
84767 */
84768 #ifndef NET_SKB_PAD
84769-#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
84770+#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
84771 #endif
84772
84773 int ___pskb_trim(struct sk_buff *skb, unsigned int len);
84774@@ -2629,7 +2629,7 @@ struct sk_buff *skb_recv_datagram(struct sock *sk, unsigned flags, int noblock,
84775 int *err);
84776 unsigned int datagram_poll(struct file *file, struct socket *sock,
84777 struct poll_table_struct *wait);
84778-int skb_copy_datagram_iovec(const struct sk_buff *from, int offset,
84779+int __intentional_overflow(0) skb_copy_datagram_iovec(const struct sk_buff *from, int offset,
84780 struct iovec *to, int size);
84781 int skb_copy_and_csum_datagram_iovec(struct sk_buff *skb, int hlen,
84782 struct iovec *iov);
84783@@ -3091,6 +3091,9 @@ static inline void nf_reset(struct sk_buff *skb)
84784 nf_bridge_put(skb->nf_bridge);
84785 skb->nf_bridge = NULL;
84786 #endif
84787+#if IS_ENABLED(CONFIG_NETFILTER_XT_TARGET_TRACE)
84788+ skb->nf_trace = 0;
84789+#endif
84790 }
84791
84792 static inline void nf_reset_trace(struct sk_buff *skb)
84793diff --git a/include/linux/slab.h b/include/linux/slab.h
84794index c265bec..4867d28 100644
84795--- a/include/linux/slab.h
84796+++ b/include/linux/slab.h
84797@@ -14,15 +14,29 @@
84798 #include <linux/gfp.h>
84799 #include <linux/types.h>
84800 #include <linux/workqueue.h>
84801-
84802+#include <linux/err.h>
84803
84804 /*
84805 * Flags to pass to kmem_cache_create().
84806 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
84807 */
84808 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
84809+
84810+#ifdef CONFIG_PAX_USERCOPY_SLABS
84811+#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
84812+#else
84813+#define SLAB_USERCOPY 0x00000000UL
84814+#endif
84815+
84816 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
84817 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
84818+
84819+#ifdef CONFIG_PAX_MEMORY_SANITIZE
84820+#define SLAB_NO_SANITIZE 0x00001000UL /* PaX: Do not sanitize objs on free */
84821+#else
84822+#define SLAB_NO_SANITIZE 0x00000000UL
84823+#endif
84824+
84825 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
84826 #define SLAB_CACHE_DMA 0x00004000UL /* Use GFP_DMA memory */
84827 #define SLAB_STORE_USER 0x00010000UL /* DEBUG: Store the last owner for bug hunting */
84828@@ -98,10 +112,13 @@
84829 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
84830 * Both make kfree a no-op.
84831 */
84832-#define ZERO_SIZE_PTR ((void *)16)
84833+#define ZERO_SIZE_PTR \
84834+({ \
84835+ BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
84836+ (void *)(-MAX_ERRNO-1L); \
84837+})
84838
84839-#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
84840- (unsigned long)ZERO_SIZE_PTR)
84841+#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
84842
84843 #include <linux/kmemleak.h>
84844
84845@@ -144,6 +161,8 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
84846 void kfree(const void *);
84847 void kzfree(const void *);
84848 size_t ksize(const void *);
84849+const char *check_heap_object(const void *ptr, unsigned long n);
84850+bool is_usercopy_object(const void *ptr);
84851
84852 /*
84853 * Some archs want to perform DMA into kmalloc caches and need a guaranteed
84854@@ -236,6 +255,10 @@ extern struct kmem_cache *kmalloc_caches[KMALLOC_SHIFT_HIGH + 1];
84855 extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
84856 #endif
84857
84858+#ifdef CONFIG_PAX_USERCOPY_SLABS
84859+extern struct kmem_cache *kmalloc_usercopy_caches[KMALLOC_SHIFT_HIGH + 1];
84860+#endif
84861+
84862 /*
84863 * Figure out which kmalloc slab an allocation of a certain size
84864 * belongs to.
84865@@ -244,7 +267,7 @@ extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
84866 * 2 = 120 .. 192 bytes
84867 * n = 2^(n-1) .. 2^n -1
84868 */
84869-static __always_inline int kmalloc_index(size_t size)
84870+static __always_inline __size_overflow(1) int kmalloc_index(size_t size)
84871 {
84872 if (!size)
84873 return 0;
84874@@ -287,11 +310,11 @@ static __always_inline int kmalloc_index(size_t size)
84875 }
84876 #endif /* !CONFIG_SLOB */
84877
84878-void *__kmalloc(size_t size, gfp_t flags);
84879+void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1);
84880 void *kmem_cache_alloc(struct kmem_cache *, gfp_t flags);
84881
84882 #ifdef CONFIG_NUMA
84883-void *__kmalloc_node(size_t size, gfp_t flags, int node);
84884+void *__kmalloc_node(size_t size, gfp_t flags, int node) __alloc_size(1);
84885 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
84886 #else
84887 static __always_inline void *__kmalloc_node(size_t size, gfp_t flags, int node)
84888diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
84889index b869d16..1453c73 100644
84890--- a/include/linux/slab_def.h
84891+++ b/include/linux/slab_def.h
84892@@ -40,7 +40,7 @@ struct kmem_cache {
84893 /* 4) cache creation/removal */
84894 const char *name;
84895 struct list_head list;
84896- int refcount;
84897+ atomic_t refcount;
84898 int object_size;
84899 int align;
84900
84901@@ -56,10 +56,14 @@ struct kmem_cache {
84902 unsigned long node_allocs;
84903 unsigned long node_frees;
84904 unsigned long node_overflow;
84905- atomic_t allochit;
84906- atomic_t allocmiss;
84907- atomic_t freehit;
84908- atomic_t freemiss;
84909+ atomic_unchecked_t allochit;
84910+ atomic_unchecked_t allocmiss;
84911+ atomic_unchecked_t freehit;
84912+ atomic_unchecked_t freemiss;
84913+#ifdef CONFIG_PAX_MEMORY_SANITIZE
84914+ atomic_unchecked_t sanitized;
84915+ atomic_unchecked_t not_sanitized;
84916+#endif
84917
84918 /*
84919 * If debugging is enabled, then the allocator can add additional
84920diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
84921index d82abd4..408c3a0 100644
84922--- a/include/linux/slub_def.h
84923+++ b/include/linux/slub_def.h
84924@@ -74,7 +74,7 @@ struct kmem_cache {
84925 struct kmem_cache_order_objects max;
84926 struct kmem_cache_order_objects min;
84927 gfp_t allocflags; /* gfp flags to use on each alloc */
84928- int refcount; /* Refcount for slab cache destroy */
84929+ atomic_t refcount; /* Refcount for slab cache destroy */
84930 void (*ctor)(void *);
84931 int inuse; /* Offset to metadata */
84932 int align; /* Alignment */
84933diff --git a/include/linux/smp.h b/include/linux/smp.h
84934index 93dff5f..933c561 100644
84935--- a/include/linux/smp.h
84936+++ b/include/linux/smp.h
84937@@ -176,7 +176,9 @@ static inline void wake_up_all_idle_cpus(void) { }
84938 #endif
84939
84940 #define get_cpu() ({ preempt_disable(); smp_processor_id(); })
84941+#define raw_get_cpu() ({ raw_preempt_disable(); raw_smp_processor_id(); })
84942 #define put_cpu() preempt_enable()
84943+#define raw_put_cpu_no_resched() raw_preempt_enable_no_resched()
84944
84945 /*
84946 * Callback to arch code if there's nosmp or maxcpus=0 on the
84947diff --git a/include/linux/sock_diag.h b/include/linux/sock_diag.h
84948index 46cca4c..3323536 100644
84949--- a/include/linux/sock_diag.h
84950+++ b/include/linux/sock_diag.h
84951@@ -11,7 +11,7 @@ struct sock;
84952 struct sock_diag_handler {
84953 __u8 family;
84954 int (*dump)(struct sk_buff *skb, struct nlmsghdr *nlh);
84955-};
84956+} __do_const;
84957
84958 int sock_diag_register(const struct sock_diag_handler *h);
84959 void sock_diag_unregister(const struct sock_diag_handler *h);
84960diff --git a/include/linux/sonet.h b/include/linux/sonet.h
84961index 680f9a3..f13aeb0 100644
84962--- a/include/linux/sonet.h
84963+++ b/include/linux/sonet.h
84964@@ -7,7 +7,7 @@
84965 #include <uapi/linux/sonet.h>
84966
84967 struct k_sonet_stats {
84968-#define __HANDLE_ITEM(i) atomic_t i
84969+#define __HANDLE_ITEM(i) atomic_unchecked_t i
84970 __SONET_ITEMS
84971 #undef __HANDLE_ITEM
84972 };
84973diff --git a/include/linux/sunrpc/addr.h b/include/linux/sunrpc/addr.h
84974index 07d8e53..dc934c9 100644
84975--- a/include/linux/sunrpc/addr.h
84976+++ b/include/linux/sunrpc/addr.h
84977@@ -23,9 +23,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
84978 {
84979 switch (sap->sa_family) {
84980 case AF_INET:
84981- return ntohs(((struct sockaddr_in *)sap)->sin_port);
84982+ return ntohs(((const struct sockaddr_in *)sap)->sin_port);
84983 case AF_INET6:
84984- return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
84985+ return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
84986 }
84987 return 0;
84988 }
84989@@ -58,7 +58,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
84990 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
84991 const struct sockaddr *src)
84992 {
84993- const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
84994+ const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
84995 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
84996
84997 dsin->sin_family = ssin->sin_family;
84998@@ -164,7 +164,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
84999 if (sa->sa_family != AF_INET6)
85000 return 0;
85001
85002- return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
85003+ return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
85004 }
85005
85006 #endif /* _LINUX_SUNRPC_ADDR_H */
85007diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
85008index 70736b9..37f33db 100644
85009--- a/include/linux/sunrpc/clnt.h
85010+++ b/include/linux/sunrpc/clnt.h
85011@@ -97,7 +97,7 @@ struct rpc_procinfo {
85012 unsigned int p_timer; /* Which RTT timer to use */
85013 u32 p_statidx; /* Which procedure to account */
85014 const char * p_name; /* name of procedure */
85015-};
85016+} __do_const;
85017
85018 #ifdef __KERNEL__
85019
85020diff --git a/include/linux/sunrpc/svc.h b/include/linux/sunrpc/svc.h
85021index 2167846..0648fc3 100644
85022--- a/include/linux/sunrpc/svc.h
85023+++ b/include/linux/sunrpc/svc.h
85024@@ -416,7 +416,7 @@ struct svc_procedure {
85025 unsigned int pc_count; /* call count */
85026 unsigned int pc_cachetype; /* cache info (NFS) */
85027 unsigned int pc_xdrressize; /* maximum size of XDR reply */
85028-};
85029+} __do_const;
85030
85031 /*
85032 * Function prototypes.
85033diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
85034index 975da75..318c083 100644
85035--- a/include/linux/sunrpc/svc_rdma.h
85036+++ b/include/linux/sunrpc/svc_rdma.h
85037@@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
85038 extern unsigned int svcrdma_max_requests;
85039 extern unsigned int svcrdma_max_req_size;
85040
85041-extern atomic_t rdma_stat_recv;
85042-extern atomic_t rdma_stat_read;
85043-extern atomic_t rdma_stat_write;
85044-extern atomic_t rdma_stat_sq_starve;
85045-extern atomic_t rdma_stat_rq_starve;
85046-extern atomic_t rdma_stat_rq_poll;
85047-extern atomic_t rdma_stat_rq_prod;
85048-extern atomic_t rdma_stat_sq_poll;
85049-extern atomic_t rdma_stat_sq_prod;
85050+extern atomic_unchecked_t rdma_stat_recv;
85051+extern atomic_unchecked_t rdma_stat_read;
85052+extern atomic_unchecked_t rdma_stat_write;
85053+extern atomic_unchecked_t rdma_stat_sq_starve;
85054+extern atomic_unchecked_t rdma_stat_rq_starve;
85055+extern atomic_unchecked_t rdma_stat_rq_poll;
85056+extern atomic_unchecked_t rdma_stat_rq_prod;
85057+extern atomic_unchecked_t rdma_stat_sq_poll;
85058+extern atomic_unchecked_t rdma_stat_sq_prod;
85059
85060 #define RPCRDMA_VERSION 1
85061
85062diff --git a/include/linux/sunrpc/svcauth.h b/include/linux/sunrpc/svcauth.h
85063index 8d71d65..f79586e 100644
85064--- a/include/linux/sunrpc/svcauth.h
85065+++ b/include/linux/sunrpc/svcauth.h
85066@@ -120,7 +120,7 @@ struct auth_ops {
85067 int (*release)(struct svc_rqst *rq);
85068 void (*domain_release)(struct auth_domain *);
85069 int (*set_client)(struct svc_rqst *rq);
85070-};
85071+} __do_const;
85072
85073 #define SVC_GARBAGE 1
85074 #define SVC_SYSERR 2
85075diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
85076index e7a018e..49f8b17 100644
85077--- a/include/linux/swiotlb.h
85078+++ b/include/linux/swiotlb.h
85079@@ -60,7 +60,8 @@ extern void
85080
85081 extern void
85082 swiotlb_free_coherent(struct device *hwdev, size_t size,
85083- void *vaddr, dma_addr_t dma_handle);
85084+ void *vaddr, dma_addr_t dma_handle,
85085+ struct dma_attrs *attrs);
85086
85087 extern dma_addr_t swiotlb_map_page(struct device *dev, struct page *page,
85088 unsigned long offset, size_t size,
85089diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h
85090index bda9b81..629e06e 100644
85091--- a/include/linux/syscalls.h
85092+++ b/include/linux/syscalls.h
85093@@ -99,10 +99,16 @@ union bpf_attr;
85094 #define __MAP(n,...) __MAP##n(__VA_ARGS__)
85095
85096 #define __SC_DECL(t, a) t a
85097+#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))
85098 #define __TYPE_IS_L(t) (__same_type((t)0, 0L))
85099 #define __TYPE_IS_UL(t) (__same_type((t)0, 0UL))
85100 #define __TYPE_IS_LL(t) (__same_type((t)0, 0LL) || __same_type((t)0, 0ULL))
85101-#define __SC_LONG(t, a) __typeof(__builtin_choose_expr(__TYPE_IS_LL(t), 0LL, 0L)) a
85102+#define __SC_LONG(t, a) __typeof( \
85103+ __builtin_choose_expr( \
85104+ sizeof(t) > sizeof(int), \
85105+ (t) 0, \
85106+ __builtin_choose_expr(__TYPE_IS_U(t), 0UL, 0L) \
85107+ )) a
85108 #define __SC_CAST(t, a) (t) a
85109 #define __SC_ARGS(t, a) a
85110 #define __SC_TEST(t, a) (void)BUILD_BUG_ON_ZERO(!__TYPE_IS_LL(t) && sizeof(t) > sizeof(long))
85111@@ -384,11 +390,11 @@ asmlinkage long sys_sync(void);
85112 asmlinkage long sys_fsync(unsigned int fd);
85113 asmlinkage long sys_fdatasync(unsigned int fd);
85114 asmlinkage long sys_bdflush(int func, long data);
85115-asmlinkage long sys_mount(char __user *dev_name, char __user *dir_name,
85116- char __user *type, unsigned long flags,
85117+asmlinkage long sys_mount(const char __user *dev_name, const char __user *dir_name,
85118+ const char __user *type, unsigned long flags,
85119 void __user *data);
85120-asmlinkage long sys_umount(char __user *name, int flags);
85121-asmlinkage long sys_oldumount(char __user *name);
85122+asmlinkage long sys_umount(const char __user *name, int flags);
85123+asmlinkage long sys_oldumount(const char __user *name);
85124 asmlinkage long sys_truncate(const char __user *path, long length);
85125 asmlinkage long sys_ftruncate(unsigned int fd, unsigned long length);
85126 asmlinkage long sys_stat(const char __user *filename,
85127@@ -600,7 +606,7 @@ asmlinkage long sys_getsockname(int, struct sockaddr __user *, int __user *);
85128 asmlinkage long sys_getpeername(int, struct sockaddr __user *, int __user *);
85129 asmlinkage long sys_send(int, void __user *, size_t, unsigned);
85130 asmlinkage long sys_sendto(int, void __user *, size_t, unsigned,
85131- struct sockaddr __user *, int);
85132+ struct sockaddr __user *, int) __intentional_overflow(0);
85133 asmlinkage long sys_sendmsg(int fd, struct msghdr __user *msg, unsigned flags);
85134 asmlinkage long sys_sendmmsg(int fd, struct mmsghdr __user *msg,
85135 unsigned int vlen, unsigned flags);
85136diff --git a/include/linux/syscore_ops.h b/include/linux/syscore_ops.h
85137index 27b3b0b..e093dd9 100644
85138--- a/include/linux/syscore_ops.h
85139+++ b/include/linux/syscore_ops.h
85140@@ -16,7 +16,7 @@ struct syscore_ops {
85141 int (*suspend)(void);
85142 void (*resume)(void);
85143 void (*shutdown)(void);
85144-};
85145+} __do_const;
85146
85147 extern void register_syscore_ops(struct syscore_ops *ops);
85148 extern void unregister_syscore_ops(struct syscore_ops *ops);
85149diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
85150index b7361f8..341a15a 100644
85151--- a/include/linux/sysctl.h
85152+++ b/include/linux/sysctl.h
85153@@ -39,6 +39,8 @@ typedef int proc_handler (struct ctl_table *ctl, int write,
85154
85155 extern int proc_dostring(struct ctl_table *, int,
85156 void __user *, size_t *, loff_t *);
85157+extern int proc_dostring_modpriv(struct ctl_table *, int,
85158+ void __user *, size_t *, loff_t *);
85159 extern int proc_dointvec(struct ctl_table *, int,
85160 void __user *, size_t *, loff_t *);
85161 extern int proc_dointvec_minmax(struct ctl_table *, int,
85162@@ -113,7 +115,8 @@ struct ctl_table
85163 struct ctl_table_poll *poll;
85164 void *extra1;
85165 void *extra2;
85166-};
85167+} __do_const __randomize_layout;
85168+typedef struct ctl_table __no_const ctl_table_no_const;
85169
85170 struct ctl_node {
85171 struct rb_node node;
85172diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h
85173index f97d0db..c1187dc 100644
85174--- a/include/linux/sysfs.h
85175+++ b/include/linux/sysfs.h
85176@@ -34,7 +34,8 @@ struct attribute {
85177 struct lock_class_key *key;
85178 struct lock_class_key skey;
85179 #endif
85180-};
85181+} __do_const;
85182+typedef struct attribute __no_const attribute_no_const;
85183
85184 /**
85185 * sysfs_attr_init - initialize a dynamically allocated sysfs attribute
85186@@ -63,7 +64,8 @@ struct attribute_group {
85187 struct attribute *, int);
85188 struct attribute **attrs;
85189 struct bin_attribute **bin_attrs;
85190-};
85191+} __do_const;
85192+typedef struct attribute_group __no_const attribute_group_no_const;
85193
85194 /**
85195 * Use these macros to make defining attributes easier. See include/linux/device.h
85196@@ -128,7 +130,8 @@ struct bin_attribute {
85197 char *, loff_t, size_t);
85198 int (*mmap)(struct file *, struct kobject *, struct bin_attribute *attr,
85199 struct vm_area_struct *vma);
85200-};
85201+} __do_const;
85202+typedef struct bin_attribute __no_const bin_attribute_no_const;
85203
85204 /**
85205 * sysfs_bin_attr_init - initialize a dynamically allocated bin_attribute
85206diff --git a/include/linux/sysrq.h b/include/linux/sysrq.h
85207index 387fa7d..3fcde6b 100644
85208--- a/include/linux/sysrq.h
85209+++ b/include/linux/sysrq.h
85210@@ -16,6 +16,7 @@
85211
85212 #include <linux/errno.h>
85213 #include <linux/types.h>
85214+#include <linux/compiler.h>
85215
85216 /* Possible values of bitmask for enabling sysrq functions */
85217 /* 0x0001 is reserved for enable everything */
85218@@ -33,7 +34,7 @@ struct sysrq_key_op {
85219 char *help_msg;
85220 char *action_msg;
85221 int enable_mask;
85222-};
85223+} __do_const;
85224
85225 #ifdef CONFIG_MAGIC_SYSRQ
85226
85227diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h
85228index ff307b5..f1a4468 100644
85229--- a/include/linux/thread_info.h
85230+++ b/include/linux/thread_info.h
85231@@ -145,6 +145,13 @@ static inline bool test_and_clear_restore_sigmask(void)
85232 #error "no set_restore_sigmask() provided and default one won't work"
85233 #endif
85234
85235+extern void __check_object_size(const void *ptr, unsigned long n, bool to_user, bool const_size);
85236+
85237+static inline void check_object_size(const void *ptr, unsigned long n, bool to_user)
85238+{
85239+ __check_object_size(ptr, n, to_user, __builtin_constant_p(n));
85240+}
85241+
85242 #endif /* __KERNEL__ */
85243
85244 #endif /* _LINUX_THREAD_INFO_H */
85245diff --git a/include/linux/tty.h b/include/linux/tty.h
85246index 5171ef8..1048d83e 100644
85247--- a/include/linux/tty.h
85248+++ b/include/linux/tty.h
85249@@ -202,7 +202,7 @@ struct tty_port {
85250 const struct tty_port_operations *ops; /* Port operations */
85251 spinlock_t lock; /* Lock protecting tty field */
85252 int blocked_open; /* Waiting to open */
85253- int count; /* Usage count */
85254+ atomic_t count; /* Usage count */
85255 wait_queue_head_t open_wait; /* Open waiters */
85256 wait_queue_head_t close_wait; /* Close waiters */
85257 wait_queue_head_t delta_msr_wait; /* Modem status change */
85258@@ -290,7 +290,7 @@ struct tty_struct {
85259 /* If the tty has a pending do_SAK, queue it here - akpm */
85260 struct work_struct SAK_work;
85261 struct tty_port *port;
85262-};
85263+} __randomize_layout;
85264
85265 /* Each of a tty's open files has private_data pointing to tty_file_private */
85266 struct tty_file_private {
85267@@ -555,7 +555,7 @@ extern int tty_port_open(struct tty_port *port,
85268 struct tty_struct *tty, struct file *filp);
85269 static inline int tty_port_users(struct tty_port *port)
85270 {
85271- return port->count + port->blocked_open;
85272+ return atomic_read(&port->count) + port->blocked_open;
85273 }
85274
85275 extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc);
85276diff --git a/include/linux/tty_driver.h b/include/linux/tty_driver.h
85277index 92e337c..f46757b 100644
85278--- a/include/linux/tty_driver.h
85279+++ b/include/linux/tty_driver.h
85280@@ -291,7 +291,7 @@ struct tty_operations {
85281 void (*poll_put_char)(struct tty_driver *driver, int line, char ch);
85282 #endif
85283 const struct file_operations *proc_fops;
85284-};
85285+} __do_const __randomize_layout;
85286
85287 struct tty_driver {
85288 int magic; /* magic number for this structure */
85289@@ -325,7 +325,7 @@ struct tty_driver {
85290
85291 const struct tty_operations *ops;
85292 struct list_head tty_drivers;
85293-};
85294+} __randomize_layout;
85295
85296 extern struct list_head tty_drivers;
85297
85298diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
85299index 00c9d68..bc0188b 100644
85300--- a/include/linux/tty_ldisc.h
85301+++ b/include/linux/tty_ldisc.h
85302@@ -215,7 +215,7 @@ struct tty_ldisc_ops {
85303
85304 struct module *owner;
85305
85306- int refcount;
85307+ atomic_t refcount;
85308 };
85309
85310 struct tty_ldisc {
85311diff --git a/include/linux/types.h b/include/linux/types.h
85312index a0bb704..f511c77 100644
85313--- a/include/linux/types.h
85314+++ b/include/linux/types.h
85315@@ -177,10 +177,26 @@ typedef struct {
85316 int counter;
85317 } atomic_t;
85318
85319+#ifdef CONFIG_PAX_REFCOUNT
85320+typedef struct {
85321+ int counter;
85322+} atomic_unchecked_t;
85323+#else
85324+typedef atomic_t atomic_unchecked_t;
85325+#endif
85326+
85327 #ifdef CONFIG_64BIT
85328 typedef struct {
85329 long counter;
85330 } atomic64_t;
85331+
85332+#ifdef CONFIG_PAX_REFCOUNT
85333+typedef struct {
85334+ long counter;
85335+} atomic64_unchecked_t;
85336+#else
85337+typedef atomic64_t atomic64_unchecked_t;
85338+#endif
85339 #endif
85340
85341 struct list_head {
85342diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
85343index ecd3319..8a36ded 100644
85344--- a/include/linux/uaccess.h
85345+++ b/include/linux/uaccess.h
85346@@ -75,11 +75,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
85347 long ret; \
85348 mm_segment_t old_fs = get_fs(); \
85349 \
85350- set_fs(KERNEL_DS); \
85351 pagefault_disable(); \
85352- ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
85353- pagefault_enable(); \
85354+ set_fs(KERNEL_DS); \
85355+ ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
85356 set_fs(old_fs); \
85357+ pagefault_enable(); \
85358 ret; \
85359 })
85360
85361diff --git a/include/linux/uidgid.h b/include/linux/uidgid.h
85362index 2d1f9b6..d7a9fce 100644
85363--- a/include/linux/uidgid.h
85364+++ b/include/linux/uidgid.h
85365@@ -175,4 +175,9 @@ static inline bool kgid_has_mapping(struct user_namespace *ns, kgid_t gid)
85366
85367 #endif /* CONFIG_USER_NS */
85368
85369+#define GR_GLOBAL_UID(x) from_kuid_munged(&init_user_ns, (x))
85370+#define GR_GLOBAL_GID(x) from_kgid_munged(&init_user_ns, (x))
85371+#define gr_is_global_root(x) uid_eq((x), GLOBAL_ROOT_UID)
85372+#define gr_is_global_nonroot(x) (!uid_eq((x), GLOBAL_ROOT_UID))
85373+
85374 #endif /* _LINUX_UIDGID_H */
85375diff --git a/include/linux/uio_driver.h b/include/linux/uio_driver.h
85376index baa8171..9ca98ba 100644
85377--- a/include/linux/uio_driver.h
85378+++ b/include/linux/uio_driver.h
85379@@ -67,7 +67,7 @@ struct uio_device {
85380 struct module *owner;
85381 struct device *dev;
85382 int minor;
85383- atomic_t event;
85384+ atomic_unchecked_t event;
85385 struct fasync_struct *async_queue;
85386 wait_queue_head_t wait;
85387 struct uio_info *info;
85388diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
85389index 99c1b4d..562e6f3 100644
85390--- a/include/linux/unaligned/access_ok.h
85391+++ b/include/linux/unaligned/access_ok.h
85392@@ -4,34 +4,34 @@
85393 #include <linux/kernel.h>
85394 #include <asm/byteorder.h>
85395
85396-static inline u16 get_unaligned_le16(const void *p)
85397+static inline u16 __intentional_overflow(-1) get_unaligned_le16(const void *p)
85398 {
85399- return le16_to_cpup((__le16 *)p);
85400+ return le16_to_cpup((const __le16 *)p);
85401 }
85402
85403-static inline u32 get_unaligned_le32(const void *p)
85404+static inline u32 __intentional_overflow(-1) get_unaligned_le32(const void *p)
85405 {
85406- return le32_to_cpup((__le32 *)p);
85407+ return le32_to_cpup((const __le32 *)p);
85408 }
85409
85410-static inline u64 get_unaligned_le64(const void *p)
85411+static inline u64 __intentional_overflow(-1) get_unaligned_le64(const void *p)
85412 {
85413- return le64_to_cpup((__le64 *)p);
85414+ return le64_to_cpup((const __le64 *)p);
85415 }
85416
85417-static inline u16 get_unaligned_be16(const void *p)
85418+static inline u16 __intentional_overflow(-1) get_unaligned_be16(const void *p)
85419 {
85420- return be16_to_cpup((__be16 *)p);
85421+ return be16_to_cpup((const __be16 *)p);
85422 }
85423
85424-static inline u32 get_unaligned_be32(const void *p)
85425+static inline u32 __intentional_overflow(-1) get_unaligned_be32(const void *p)
85426 {
85427- return be32_to_cpup((__be32 *)p);
85428+ return be32_to_cpup((const __be32 *)p);
85429 }
85430
85431-static inline u64 get_unaligned_be64(const void *p)
85432+static inline u64 __intentional_overflow(-1) get_unaligned_be64(const void *p)
85433 {
85434- return be64_to_cpup((__be64 *)p);
85435+ return be64_to_cpup((const __be64 *)p);
85436 }
85437
85438 static inline void put_unaligned_le16(u16 val, void *p)
85439diff --git a/include/linux/usb.h b/include/linux/usb.h
85440index 447a7e2..9cea7e9 100644
85441--- a/include/linux/usb.h
85442+++ b/include/linux/usb.h
85443@@ -571,7 +571,7 @@ struct usb_device {
85444 int maxchild;
85445
85446 u32 quirks;
85447- atomic_t urbnum;
85448+ atomic_unchecked_t urbnum;
85449
85450 unsigned long active_duration;
85451
85452@@ -1655,7 +1655,7 @@ void usb_buffer_unmap_sg(const struct usb_device *dev, int is_in,
85453
85454 extern int usb_control_msg(struct usb_device *dev, unsigned int pipe,
85455 __u8 request, __u8 requesttype, __u16 value, __u16 index,
85456- void *data, __u16 size, int timeout);
85457+ void *data, __u16 size, int timeout) __intentional_overflow(-1);
85458 extern int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
85459 void *data, int len, int *actual_length, int timeout);
85460 extern int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
85461diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
85462index d5952bb..9a626d4 100644
85463--- a/include/linux/usb/renesas_usbhs.h
85464+++ b/include/linux/usb/renesas_usbhs.h
85465@@ -39,7 +39,7 @@ enum {
85466 */
85467 struct renesas_usbhs_driver_callback {
85468 int (*notify_hotplug)(struct platform_device *pdev);
85469-};
85470+} __no_const;
85471
85472 /*
85473 * callback functions for platform
85474diff --git a/include/linux/user_namespace.h b/include/linux/user_namespace.h
85475index 9f3579f..3b2afa5 100644
85476--- a/include/linux/user_namespace.h
85477+++ b/include/linux/user_namespace.h
85478@@ -38,7 +38,7 @@ struct user_namespace {
85479 struct key *persistent_keyring_register;
85480 struct rw_semaphore persistent_keyring_register_sem;
85481 #endif
85482-};
85483+} __randomize_layout;
85484
85485 extern struct user_namespace init_user_ns;
85486
85487diff --git a/include/linux/utsname.h b/include/linux/utsname.h
85488index 239e277..22a5cf5 100644
85489--- a/include/linux/utsname.h
85490+++ b/include/linux/utsname.h
85491@@ -24,7 +24,7 @@ struct uts_namespace {
85492 struct new_utsname name;
85493 struct user_namespace *user_ns;
85494 unsigned int proc_inum;
85495-};
85496+} __randomize_layout;
85497 extern struct uts_namespace init_uts_ns;
85498
85499 #ifdef CONFIG_UTS_NS
85500diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
85501index 6f8fbcf..4efc177 100644
85502--- a/include/linux/vermagic.h
85503+++ b/include/linux/vermagic.h
85504@@ -25,9 +25,42 @@
85505 #define MODULE_ARCH_VERMAGIC ""
85506 #endif
85507
85508+#ifdef CONFIG_PAX_REFCOUNT
85509+#define MODULE_PAX_REFCOUNT "REFCOUNT "
85510+#else
85511+#define MODULE_PAX_REFCOUNT ""
85512+#endif
85513+
85514+#ifdef CONSTIFY_PLUGIN
85515+#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
85516+#else
85517+#define MODULE_CONSTIFY_PLUGIN ""
85518+#endif
85519+
85520+#ifdef STACKLEAK_PLUGIN
85521+#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
85522+#else
85523+#define MODULE_STACKLEAK_PLUGIN ""
85524+#endif
85525+
85526+#ifdef RANDSTRUCT_PLUGIN
85527+#include <generated/randomize_layout_hash.h>
85528+#define MODULE_RANDSTRUCT_PLUGIN "RANDSTRUCT_PLUGIN_" RANDSTRUCT_HASHED_SEED
85529+#else
85530+#define MODULE_RANDSTRUCT_PLUGIN
85531+#endif
85532+
85533+#ifdef CONFIG_GRKERNSEC
85534+#define MODULE_GRSEC "GRSEC "
85535+#else
85536+#define MODULE_GRSEC ""
85537+#endif
85538+
85539 #define VERMAGIC_STRING \
85540 UTS_RELEASE " " \
85541 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
85542 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
85543- MODULE_ARCH_VERMAGIC
85544+ MODULE_ARCH_VERMAGIC \
85545+ MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
85546+ MODULE_GRSEC MODULE_RANDSTRUCT_PLUGIN
85547
85548diff --git a/include/linux/vga_switcheroo.h b/include/linux/vga_switcheroo.h
85549index b483abd..af305ad 100644
85550--- a/include/linux/vga_switcheroo.h
85551+++ b/include/linux/vga_switcheroo.h
85552@@ -63,9 +63,9 @@ int vga_switcheroo_get_client_state(struct pci_dev *dev);
85553
85554 void vga_switcheroo_set_dynamic_switch(struct pci_dev *pdev, enum vga_switcheroo_state dynamic);
85555
85556-int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain);
85557+int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain);
85558 void vga_switcheroo_fini_domain_pm_ops(struct device *dev);
85559-int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain);
85560+int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain);
85561 #else
85562
85563 static inline void vga_switcheroo_unregister_client(struct pci_dev *dev) {}
85564@@ -82,9 +82,9 @@ static inline int vga_switcheroo_get_client_state(struct pci_dev *dev) { return
85565
85566 static inline void vga_switcheroo_set_dynamic_switch(struct pci_dev *pdev, enum vga_switcheroo_state dynamic) {}
85567
85568-static inline int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain) { return -EINVAL; }
85569+static inline int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain) { return -EINVAL; }
85570 static inline void vga_switcheroo_fini_domain_pm_ops(struct device *dev) {}
85571-static inline int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain) { return -EINVAL; }
85572+static inline int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain) { return -EINVAL; }
85573
85574 #endif
85575 #endif /* _LINUX_VGA_SWITCHEROO_H_ */
85576diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
85577index b87696f..1d11de7 100644
85578--- a/include/linux/vmalloc.h
85579+++ b/include/linux/vmalloc.h
85580@@ -16,6 +16,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
85581 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
85582 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
85583 #define VM_UNINITIALIZED 0x00000020 /* vm_struct is not fully initialized */
85584+
85585+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
85586+#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
85587+#endif
85588+
85589 /* bits [20..32] reserved for arch specific ioremap internals */
85590
85591 /*
85592@@ -82,6 +87,10 @@ extern void *vmap(struct page **pages, unsigned int count,
85593 unsigned long flags, pgprot_t prot);
85594 extern void vunmap(const void *addr);
85595
85596+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
85597+extern void unmap_process_stacks(struct task_struct *task);
85598+#endif
85599+
85600 extern int remap_vmalloc_range_partial(struct vm_area_struct *vma,
85601 unsigned long uaddr, void *kaddr,
85602 unsigned long size);
85603@@ -142,7 +151,7 @@ extern void free_vm_area(struct vm_struct *area);
85604
85605 /* for /dev/kmem */
85606 extern long vread(char *buf, char *addr, unsigned long count);
85607-extern long vwrite(char *buf, char *addr, unsigned long count);
85608+extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
85609
85610 /*
85611 * Internals. Dont't use..
85612diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
85613index 82e7db7..f8ce3d0 100644
85614--- a/include/linux/vmstat.h
85615+++ b/include/linux/vmstat.h
85616@@ -108,18 +108,18 @@ static inline void vm_events_fold_cpu(int cpu)
85617 /*
85618 * Zone based page accounting with per cpu differentials.
85619 */
85620-extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
85621+extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
85622
85623 static inline void zone_page_state_add(long x, struct zone *zone,
85624 enum zone_stat_item item)
85625 {
85626- atomic_long_add(x, &zone->vm_stat[item]);
85627- atomic_long_add(x, &vm_stat[item]);
85628+ atomic_long_add_unchecked(x, &zone->vm_stat[item]);
85629+ atomic_long_add_unchecked(x, &vm_stat[item]);
85630 }
85631
85632-static inline unsigned long global_page_state(enum zone_stat_item item)
85633+static inline unsigned long __intentional_overflow(-1) global_page_state(enum zone_stat_item item)
85634 {
85635- long x = atomic_long_read(&vm_stat[item]);
85636+ long x = atomic_long_read_unchecked(&vm_stat[item]);
85637 #ifdef CONFIG_SMP
85638 if (x < 0)
85639 x = 0;
85640@@ -127,10 +127,10 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
85641 return x;
85642 }
85643
85644-static inline unsigned long zone_page_state(struct zone *zone,
85645+static inline unsigned long __intentional_overflow(-1) zone_page_state(struct zone *zone,
85646 enum zone_stat_item item)
85647 {
85648- long x = atomic_long_read(&zone->vm_stat[item]);
85649+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
85650 #ifdef CONFIG_SMP
85651 if (x < 0)
85652 x = 0;
85653@@ -147,7 +147,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
85654 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
85655 enum zone_stat_item item)
85656 {
85657- long x = atomic_long_read(&zone->vm_stat[item]);
85658+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
85659
85660 #ifdef CONFIG_SMP
85661 int cpu;
85662@@ -234,14 +234,14 @@ static inline void __mod_zone_page_state(struct zone *zone,
85663
85664 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
85665 {
85666- atomic_long_inc(&zone->vm_stat[item]);
85667- atomic_long_inc(&vm_stat[item]);
85668+ atomic_long_inc_unchecked(&zone->vm_stat[item]);
85669+ atomic_long_inc_unchecked(&vm_stat[item]);
85670 }
85671
85672 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
85673 {
85674- atomic_long_dec(&zone->vm_stat[item]);
85675- atomic_long_dec(&vm_stat[item]);
85676+ atomic_long_dec_unchecked(&zone->vm_stat[item]);
85677+ atomic_long_dec_unchecked(&vm_stat[item]);
85678 }
85679
85680 static inline void __inc_zone_page_state(struct page *page,
85681diff --git a/include/linux/xattr.h b/include/linux/xattr.h
85682index 91b0a68..0e9adf6 100644
85683--- a/include/linux/xattr.h
85684+++ b/include/linux/xattr.h
85685@@ -28,7 +28,7 @@ struct xattr_handler {
85686 size_t size, int handler_flags);
85687 int (*set)(struct dentry *dentry, const char *name, const void *buffer,
85688 size_t size, int flags, int handler_flags);
85689-};
85690+} __do_const;
85691
85692 struct xattr {
85693 const char *name;
85694@@ -37,6 +37,9 @@ struct xattr {
85695 };
85696
85697 ssize_t xattr_getsecurity(struct inode *, const char *, void *, size_t);
85698+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
85699+ssize_t pax_getxattr(struct dentry *, void *, size_t);
85700+#endif
85701 ssize_t vfs_getxattr(struct dentry *, const char *, void *, size_t);
85702 ssize_t vfs_listxattr(struct dentry *d, char *list, size_t size);
85703 int __vfs_setxattr_noperm(struct dentry *, const char *, const void *, size_t, int);
85704diff --git a/include/linux/zlib.h b/include/linux/zlib.h
85705index 92dbbd3..13ab0b3 100644
85706--- a/include/linux/zlib.h
85707+++ b/include/linux/zlib.h
85708@@ -31,6 +31,7 @@
85709 #define _ZLIB_H
85710
85711 #include <linux/zconf.h>
85712+#include <linux/compiler.h>
85713
85714 /* zlib deflate based on ZLIB_VERSION "1.1.3" */
85715 /* zlib inflate based on ZLIB_VERSION "1.2.3" */
85716@@ -179,7 +180,7 @@ typedef z_stream *z_streamp;
85717
85718 /* basic functions */
85719
85720-extern int zlib_deflate_workspacesize (int windowBits, int memLevel);
85721+extern int zlib_deflate_workspacesize (int windowBits, int memLevel) __intentional_overflow(0);
85722 /*
85723 Returns the number of bytes that needs to be allocated for a per-
85724 stream workspace with the specified parameters. A pointer to this
85725diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
85726index eb76cfd..9fd0e7c 100644
85727--- a/include/media/v4l2-dev.h
85728+++ b/include/media/v4l2-dev.h
85729@@ -75,7 +75,7 @@ struct v4l2_file_operations {
85730 int (*mmap) (struct file *, struct vm_area_struct *);
85731 int (*open) (struct file *);
85732 int (*release) (struct file *);
85733-};
85734+} __do_const;
85735
85736 /*
85737 * Newer version of video_device, handled by videodev2.c
85738diff --git a/include/media/v4l2-device.h b/include/media/v4l2-device.h
85739index ffb69da..040393e 100644
85740--- a/include/media/v4l2-device.h
85741+++ b/include/media/v4l2-device.h
85742@@ -95,7 +95,7 @@ int __must_check v4l2_device_register(struct device *dev, struct v4l2_device *v4
85743 this function returns 0. If the name ends with a digit (e.g. cx18),
85744 then the name will be set to cx18-0 since cx180 looks really odd. */
85745 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
85746- atomic_t *instance);
85747+ atomic_unchecked_t *instance);
85748
85749 /* Set v4l2_dev->dev to NULL. Call when the USB parent disconnects.
85750 Since the parent disappears this ensures that v4l2_dev doesn't have an
85751diff --git a/include/net/9p/transport.h b/include/net/9p/transport.h
85752index 2a25dec..bf6dd8a 100644
85753--- a/include/net/9p/transport.h
85754+++ b/include/net/9p/transport.h
85755@@ -62,7 +62,7 @@ struct p9_trans_module {
85756 int (*cancelled)(struct p9_client *, struct p9_req_t *req);
85757 int (*zc_request)(struct p9_client *, struct p9_req_t *,
85758 char *, char *, int , int, int, int);
85759-};
85760+} __do_const;
85761
85762 void v9fs_register_trans(struct p9_trans_module *m);
85763 void v9fs_unregister_trans(struct p9_trans_module *m);
85764diff --git a/include/net/af_unix.h b/include/net/af_unix.h
85765index a175ba4..196eb8242 100644
85766--- a/include/net/af_unix.h
85767+++ b/include/net/af_unix.h
85768@@ -36,7 +36,7 @@ struct unix_skb_parms {
85769 u32 secid; /* Security ID */
85770 #endif
85771 u32 consumed;
85772-};
85773+} __randomize_layout;
85774
85775 #define UNIXCB(skb) (*(struct unix_skb_parms *)&((skb)->cb))
85776 #define UNIXSID(skb) (&UNIXCB((skb)).secid)
85777diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h
85778index ead99f0..6263c4b 100644
85779--- a/include/net/bluetooth/l2cap.h
85780+++ b/include/net/bluetooth/l2cap.h
85781@@ -608,7 +608,7 @@ struct l2cap_ops {
85782 unsigned char *kdata,
85783 struct iovec *iov,
85784 int len);
85785-};
85786+} __do_const;
85787
85788 struct l2cap_conn {
85789 struct hci_conn *hcon;
85790diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
85791index f2ae33d..c457cf0 100644
85792--- a/include/net/caif/cfctrl.h
85793+++ b/include/net/caif/cfctrl.h
85794@@ -52,7 +52,7 @@ struct cfctrl_rsp {
85795 void (*radioset_rsp)(void);
85796 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
85797 struct cflayer *client_layer);
85798-};
85799+} __no_const;
85800
85801 /* Link Setup Parameters for CAIF-Links. */
85802 struct cfctrl_link_param {
85803@@ -101,8 +101,8 @@ struct cfctrl_request_info {
85804 struct cfctrl {
85805 struct cfsrvl serv;
85806 struct cfctrl_rsp res;
85807- atomic_t req_seq_no;
85808- atomic_t rsp_seq_no;
85809+ atomic_unchecked_t req_seq_no;
85810+ atomic_unchecked_t rsp_seq_no;
85811 struct list_head list;
85812 /* Protects from simultaneous access to first_req list */
85813 spinlock_t info_list_lock;
85814diff --git a/include/net/flow.h b/include/net/flow.h
85815index 8109a15..504466d 100644
85816--- a/include/net/flow.h
85817+++ b/include/net/flow.h
85818@@ -231,6 +231,6 @@ void flow_cache_fini(struct net *net);
85819
85820 void flow_cache_flush(struct net *net);
85821 void flow_cache_flush_deferred(struct net *net);
85822-extern atomic_t flow_cache_genid;
85823+extern atomic_unchecked_t flow_cache_genid;
85824
85825 #endif
85826diff --git a/include/net/genetlink.h b/include/net/genetlink.h
85827index af10c2c..a431cc5 100644
85828--- a/include/net/genetlink.h
85829+++ b/include/net/genetlink.h
85830@@ -120,7 +120,7 @@ struct genl_ops {
85831 u8 cmd;
85832 u8 internal_flags;
85833 u8 flags;
85834-};
85835+} __do_const;
85836
85837 int __genl_register_family(struct genl_family *family);
85838
85839diff --git a/include/net/gro_cells.h b/include/net/gro_cells.h
85840index 734d9b5..48a9a4b 100644
85841--- a/include/net/gro_cells.h
85842+++ b/include/net/gro_cells.h
85843@@ -29,7 +29,7 @@ static inline void gro_cells_receive(struct gro_cells *gcells, struct sk_buff *s
85844 cell += skb_get_rx_queue(skb) & gcells->gro_cells_mask;
85845
85846 if (skb_queue_len(&cell->napi_skbs) > netdev_max_backlog) {
85847- atomic_long_inc(&dev->rx_dropped);
85848+ atomic_long_inc_unchecked(&dev->rx_dropped);
85849 kfree_skb(skb);
85850 return;
85851 }
85852diff --git a/include/net/inet_connection_sock.h b/include/net/inet_connection_sock.h
85853index 848e85c..051c7de 100644
85854--- a/include/net/inet_connection_sock.h
85855+++ b/include/net/inet_connection_sock.h
85856@@ -63,7 +63,7 @@ struct inet_connection_sock_af_ops {
85857 int (*bind_conflict)(const struct sock *sk,
85858 const struct inet_bind_bucket *tb, bool relax);
85859 void (*mtu_reduced)(struct sock *sk);
85860-};
85861+} __do_const;
85862
85863 /** inet_connection_sock - INET connection oriented sock
85864 *
85865diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
85866index 80479ab..0c3f647 100644
85867--- a/include/net/inetpeer.h
85868+++ b/include/net/inetpeer.h
85869@@ -47,7 +47,7 @@ struct inet_peer {
85870 */
85871 union {
85872 struct {
85873- atomic_t rid; /* Frag reception counter */
85874+ atomic_unchecked_t rid; /* Frag reception counter */
85875 };
85876 struct rcu_head rcu;
85877 struct inet_peer *gc_next;
85878diff --git a/include/net/ip.h b/include/net/ip.h
85879index 0bb6207..a8878af 100644
85880--- a/include/net/ip.h
85881+++ b/include/net/ip.h
85882@@ -316,7 +316,7 @@ static inline unsigned int ip_skb_dst_mtu(const struct sk_buff *skb)
85883 }
85884 }
85885
85886-u32 ip_idents_reserve(u32 hash, int segs);
85887+u32 ip_idents_reserve(u32 hash, int segs) __intentional_overflow(-1);
85888 void __ip_select_ident(struct iphdr *iph, int segs);
85889
85890 static inline void ip_select_ident_segs(struct sk_buff *skb, struct sock *sk, int segs)
85891diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
85892index dc9d2a2..d985691 100644
85893--- a/include/net/ip_fib.h
85894+++ b/include/net/ip_fib.h
85895@@ -170,7 +170,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
85896
85897 #define FIB_RES_SADDR(net, res) \
85898 ((FIB_RES_NH(res).nh_saddr_genid == \
85899- atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
85900+ atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
85901 FIB_RES_NH(res).nh_saddr : \
85902 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
85903 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
85904diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
85905index 615b20b..fd4cbd8 100644
85906--- a/include/net/ip_vs.h
85907+++ b/include/net/ip_vs.h
85908@@ -534,7 +534,7 @@ struct ip_vs_conn {
85909 struct ip_vs_conn *control; /* Master control connection */
85910 atomic_t n_control; /* Number of controlled ones */
85911 struct ip_vs_dest *dest; /* real server */
85912- atomic_t in_pkts; /* incoming packet counter */
85913+ atomic_unchecked_t in_pkts; /* incoming packet counter */
85914
85915 /* Packet transmitter for different forwarding methods. If it
85916 * mangles the packet, it must return NF_DROP or better NF_STOLEN,
85917@@ -682,7 +682,7 @@ struct ip_vs_dest {
85918 __be16 port; /* port number of the server */
85919 union nf_inet_addr addr; /* IP address of the server */
85920 volatile unsigned int flags; /* dest status flags */
85921- atomic_t conn_flags; /* flags to copy to conn */
85922+ atomic_unchecked_t conn_flags; /* flags to copy to conn */
85923 atomic_t weight; /* server weight */
85924
85925 atomic_t refcnt; /* reference counter */
85926@@ -928,11 +928,11 @@ struct netns_ipvs {
85927 /* ip_vs_lblc */
85928 int sysctl_lblc_expiration;
85929 struct ctl_table_header *lblc_ctl_header;
85930- struct ctl_table *lblc_ctl_table;
85931+ ctl_table_no_const *lblc_ctl_table;
85932 /* ip_vs_lblcr */
85933 int sysctl_lblcr_expiration;
85934 struct ctl_table_header *lblcr_ctl_header;
85935- struct ctl_table *lblcr_ctl_table;
85936+ ctl_table_no_const *lblcr_ctl_table;
85937 /* ip_vs_est */
85938 struct list_head est_list; /* estimator list */
85939 spinlock_t est_lock;
85940diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
85941index 8d4f588..2e37ad2 100644
85942--- a/include/net/irda/ircomm_tty.h
85943+++ b/include/net/irda/ircomm_tty.h
85944@@ -33,6 +33,7 @@
85945 #include <linux/termios.h>
85946 #include <linux/timer.h>
85947 #include <linux/tty.h> /* struct tty_struct */
85948+#include <asm/local.h>
85949
85950 #include <net/irda/irias_object.h>
85951 #include <net/irda/ircomm_core.h>
85952diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
85953index 714cc9a..ea05f3e 100644
85954--- a/include/net/iucv/af_iucv.h
85955+++ b/include/net/iucv/af_iucv.h
85956@@ -149,7 +149,7 @@ struct iucv_skb_cb {
85957 struct iucv_sock_list {
85958 struct hlist_head head;
85959 rwlock_t lock;
85960- atomic_t autobind_name;
85961+ atomic_unchecked_t autobind_name;
85962 };
85963
85964 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
85965diff --git a/include/net/llc_c_ac.h b/include/net/llc_c_ac.h
85966index f3be818..bf46196 100644
85967--- a/include/net/llc_c_ac.h
85968+++ b/include/net/llc_c_ac.h
85969@@ -87,7 +87,7 @@
85970 #define LLC_CONN_AC_STOP_SENDACK_TMR 70
85971 #define LLC_CONN_AC_START_SENDACK_TMR_IF_NOT_RUNNING 71
85972
85973-typedef int (*llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
85974+typedef int (* const llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
85975
85976 int llc_conn_ac_clear_remote_busy(struct sock *sk, struct sk_buff *skb);
85977 int llc_conn_ac_conn_ind(struct sock *sk, struct sk_buff *skb);
85978diff --git a/include/net/llc_c_ev.h b/include/net/llc_c_ev.h
85979index 3948cf1..83b28c4 100644
85980--- a/include/net/llc_c_ev.h
85981+++ b/include/net/llc_c_ev.h
85982@@ -125,8 +125,8 @@ static __inline__ struct llc_conn_state_ev *llc_conn_ev(struct sk_buff *skb)
85983 return (struct llc_conn_state_ev *)skb->cb;
85984 }
85985
85986-typedef int (*llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
85987-typedef int (*llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
85988+typedef int (* const llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
85989+typedef int (* const llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
85990
85991 int llc_conn_ev_conn_req(struct sock *sk, struct sk_buff *skb);
85992 int llc_conn_ev_data_req(struct sock *sk, struct sk_buff *skb);
85993diff --git a/include/net/llc_c_st.h b/include/net/llc_c_st.h
85994index 0e79cfb..f46db31 100644
85995--- a/include/net/llc_c_st.h
85996+++ b/include/net/llc_c_st.h
85997@@ -37,7 +37,7 @@ struct llc_conn_state_trans {
85998 u8 next_state;
85999 llc_conn_ev_qfyr_t *ev_qualifiers;
86000 llc_conn_action_t *ev_actions;
86001-};
86002+} __do_const;
86003
86004 struct llc_conn_state {
86005 u8 current_state;
86006diff --git a/include/net/llc_s_ac.h b/include/net/llc_s_ac.h
86007index a61b98c..aade1eb 100644
86008--- a/include/net/llc_s_ac.h
86009+++ b/include/net/llc_s_ac.h
86010@@ -23,7 +23,7 @@
86011 #define SAP_ACT_TEST_IND 9
86012
86013 /* All action functions must look like this */
86014-typedef int (*llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
86015+typedef int (* const llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
86016
86017 int llc_sap_action_unitdata_ind(struct llc_sap *sap, struct sk_buff *skb);
86018 int llc_sap_action_send_ui(struct llc_sap *sap, struct sk_buff *skb);
86019diff --git a/include/net/llc_s_st.h b/include/net/llc_s_st.h
86020index 567c681..cd73ac02 100644
86021--- a/include/net/llc_s_st.h
86022+++ b/include/net/llc_s_st.h
86023@@ -20,7 +20,7 @@ struct llc_sap_state_trans {
86024 llc_sap_ev_t ev;
86025 u8 next_state;
86026 llc_sap_action_t *ev_actions;
86027-};
86028+} __do_const;
86029
86030 struct llc_sap_state {
86031 u8 curr_state;
86032diff --git a/include/net/mac80211.h b/include/net/mac80211.h
86033index a9de1da..df72057 100644
86034--- a/include/net/mac80211.h
86035+++ b/include/net/mac80211.h
86036@@ -4645,7 +4645,7 @@ struct rate_control_ops {
86037 void (*remove_sta_debugfs)(void *priv, void *priv_sta);
86038
86039 u32 (*get_expected_throughput)(void *priv_sta);
86040-};
86041+} __do_const;
86042
86043 static inline int rate_supported(struct ieee80211_sta *sta,
86044 enum ieee80211_band band,
86045diff --git a/include/net/neighbour.h b/include/net/neighbour.h
86046index f60558d..e5ed9bd 100644
86047--- a/include/net/neighbour.h
86048+++ b/include/net/neighbour.h
86049@@ -163,7 +163,7 @@ struct neigh_ops {
86050 void (*error_report)(struct neighbour *, struct sk_buff *);
86051 int (*output)(struct neighbour *, struct sk_buff *);
86052 int (*connected_output)(struct neighbour *, struct sk_buff *);
86053-};
86054+} __do_const;
86055
86056 struct pneigh_entry {
86057 struct pneigh_entry *next;
86058@@ -217,7 +217,7 @@ struct neigh_table {
86059 struct neigh_statistics __percpu *stats;
86060 struct neigh_hash_table __rcu *nht;
86061 struct pneigh_entry **phash_buckets;
86062-};
86063+} __randomize_layout;
86064
86065 static inline int neigh_parms_family(struct neigh_parms *p)
86066 {
86067diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
86068index e0d6466..e2f3003 100644
86069--- a/include/net/net_namespace.h
86070+++ b/include/net/net_namespace.h
86071@@ -129,8 +129,8 @@ struct net {
86072 struct netns_ipvs *ipvs;
86073 #endif
86074 struct sock *diag_nlsk;
86075- atomic_t fnhe_genid;
86076-};
86077+ atomic_unchecked_t fnhe_genid;
86078+} __randomize_layout;
86079
86080 #include <linux/seq_file_net.h>
86081
86082@@ -286,7 +286,11 @@ static inline struct net *read_pnet(struct net * const *pnet)
86083 #define __net_init __init
86084 #define __net_exit __exit_refok
86085 #define __net_initdata __initdata
86086+#ifdef CONSTIFY_PLUGIN
86087 #define __net_initconst __initconst
86088+#else
86089+#define __net_initconst __initdata
86090+#endif
86091 #endif
86092
86093 struct pernet_operations {
86094@@ -296,7 +300,7 @@ struct pernet_operations {
86095 void (*exit_batch)(struct list_head *net_exit_list);
86096 int *id;
86097 size_t size;
86098-};
86099+} __do_const;
86100
86101 /*
86102 * Use these carefully. If you implement a network device and it
86103@@ -344,12 +348,12 @@ static inline void unregister_net_sysctl_table(struct ctl_table_header *header)
86104
86105 static inline int rt_genid_ipv4(struct net *net)
86106 {
86107- return atomic_read(&net->ipv4.rt_genid);
86108+ return atomic_read_unchecked(&net->ipv4.rt_genid);
86109 }
86110
86111 static inline void rt_genid_bump_ipv4(struct net *net)
86112 {
86113- atomic_inc(&net->ipv4.rt_genid);
86114+ atomic_inc_unchecked(&net->ipv4.rt_genid);
86115 }
86116
86117 extern void (*__fib6_flush_trees)(struct net *net);
86118@@ -376,12 +380,12 @@ static inline void rt_genid_bump_all(struct net *net)
86119
86120 static inline int fnhe_genid(struct net *net)
86121 {
86122- return atomic_read(&net->fnhe_genid);
86123+ return atomic_read_unchecked(&net->fnhe_genid);
86124 }
86125
86126 static inline void fnhe_genid_bump(struct net *net)
86127 {
86128- atomic_inc(&net->fnhe_genid);
86129+ atomic_inc_unchecked(&net->fnhe_genid);
86130 }
86131
86132 #endif /* __NET_NET_NAMESPACE_H */
86133diff --git a/include/net/netlink.h b/include/net/netlink.h
86134index 7b903e1..ad9ca4b 100644
86135--- a/include/net/netlink.h
86136+++ b/include/net/netlink.h
86137@@ -521,7 +521,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
86138 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
86139 {
86140 if (mark)
86141- skb_trim(skb, (unsigned char *) mark - skb->data);
86142+ skb_trim(skb, (const unsigned char *) mark - skb->data);
86143 }
86144
86145 /**
86146diff --git a/include/net/netns/conntrack.h b/include/net/netns/conntrack.h
86147index 29d6a94..235d3d84 100644
86148--- a/include/net/netns/conntrack.h
86149+++ b/include/net/netns/conntrack.h
86150@@ -14,10 +14,10 @@ struct nf_conntrack_ecache;
86151 struct nf_proto_net {
86152 #ifdef CONFIG_SYSCTL
86153 struct ctl_table_header *ctl_table_header;
86154- struct ctl_table *ctl_table;
86155+ ctl_table_no_const *ctl_table;
86156 #ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT
86157 struct ctl_table_header *ctl_compat_header;
86158- struct ctl_table *ctl_compat_table;
86159+ ctl_table_no_const *ctl_compat_table;
86160 #endif
86161 #endif
86162 unsigned int users;
86163@@ -60,7 +60,7 @@ struct nf_ip_net {
86164 struct nf_icmp_net icmpv6;
86165 #if defined(CONFIG_SYSCTL) && defined(CONFIG_NF_CONNTRACK_PROC_COMPAT)
86166 struct ctl_table_header *ctl_table_header;
86167- struct ctl_table *ctl_table;
86168+ ctl_table_no_const *ctl_table;
86169 #endif
86170 };
86171
86172diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
86173index 24945ce..f19e42f 100644
86174--- a/include/net/netns/ipv4.h
86175+++ b/include/net/netns/ipv4.h
86176@@ -83,7 +83,7 @@ struct netns_ipv4 {
86177
86178 struct ping_group_range ping_group_range;
86179
86180- atomic_t dev_addr_genid;
86181+ atomic_unchecked_t dev_addr_genid;
86182
86183 #ifdef CONFIG_SYSCTL
86184 unsigned long *sysctl_local_reserved_ports;
86185@@ -97,6 +97,6 @@ struct netns_ipv4 {
86186 struct fib_rules_ops *mr_rules_ops;
86187 #endif
86188 #endif
86189- atomic_t rt_genid;
86190+ atomic_unchecked_t rt_genid;
86191 };
86192 #endif
86193diff --git a/include/net/netns/ipv6.h b/include/net/netns/ipv6.h
86194index 69ae41f..4f94868 100644
86195--- a/include/net/netns/ipv6.h
86196+++ b/include/net/netns/ipv6.h
86197@@ -75,8 +75,8 @@ struct netns_ipv6 {
86198 struct fib_rules_ops *mr6_rules_ops;
86199 #endif
86200 #endif
86201- atomic_t dev_addr_genid;
86202- atomic_t fib6_sernum;
86203+ atomic_unchecked_t dev_addr_genid;
86204+ atomic_unchecked_t fib6_sernum;
86205 };
86206
86207 #if IS_ENABLED(CONFIG_NF_DEFRAG_IPV6)
86208diff --git a/include/net/netns/xfrm.h b/include/net/netns/xfrm.h
86209index 9da7982..099321b9 100644
86210--- a/include/net/netns/xfrm.h
86211+++ b/include/net/netns/xfrm.h
86212@@ -78,7 +78,7 @@ struct netns_xfrm {
86213
86214 /* flow cache part */
86215 struct flow_cache flow_cache_global;
86216- atomic_t flow_cache_genid;
86217+ atomic_unchecked_t flow_cache_genid;
86218 struct list_head flow_cache_gc_list;
86219 spinlock_t flow_cache_gc_lock;
86220 struct work_struct flow_cache_gc_work;
86221diff --git a/include/net/ping.h b/include/net/ping.h
86222index 026479b..d9b2829 100644
86223--- a/include/net/ping.h
86224+++ b/include/net/ping.h
86225@@ -54,7 +54,7 @@ struct ping_iter_state {
86226
86227 extern struct proto ping_prot;
86228 #if IS_ENABLED(CONFIG_IPV6)
86229-extern struct pingv6_ops pingv6_ops;
86230+extern struct pingv6_ops *pingv6_ops;
86231 #endif
86232
86233 struct pingfakehdr {
86234diff --git a/include/net/protocol.h b/include/net/protocol.h
86235index d6fcc1f..ca277058 100644
86236--- a/include/net/protocol.h
86237+++ b/include/net/protocol.h
86238@@ -49,7 +49,7 @@ struct net_protocol {
86239 * socket lookup?
86240 */
86241 icmp_strict_tag_validation:1;
86242-};
86243+} __do_const;
86244
86245 #if IS_ENABLED(CONFIG_IPV6)
86246 struct inet6_protocol {
86247@@ -62,7 +62,7 @@ struct inet6_protocol {
86248 u8 type, u8 code, int offset,
86249 __be32 info);
86250 unsigned int flags; /* INET6_PROTO_xxx */
86251-};
86252+} __do_const;
86253
86254 #define INET6_PROTO_NOPOLICY 0x1
86255 #define INET6_PROTO_FINAL 0x2
86256diff --git a/include/net/rtnetlink.h b/include/net/rtnetlink.h
86257index e21b9f9..0191ef0 100644
86258--- a/include/net/rtnetlink.h
86259+++ b/include/net/rtnetlink.h
86260@@ -93,7 +93,7 @@ struct rtnl_link_ops {
86261 int (*fill_slave_info)(struct sk_buff *skb,
86262 const struct net_device *dev,
86263 const struct net_device *slave_dev);
86264-};
86265+} __do_const;
86266
86267 int __rtnl_link_register(struct rtnl_link_ops *ops);
86268 void __rtnl_link_unregister(struct rtnl_link_ops *ops);
86269diff --git a/include/net/sctp/checksum.h b/include/net/sctp/checksum.h
86270index 4a5b9a3..ca27d73 100644
86271--- a/include/net/sctp/checksum.h
86272+++ b/include/net/sctp/checksum.h
86273@@ -61,8 +61,8 @@ static inline __le32 sctp_compute_cksum(const struct sk_buff *skb,
86274 unsigned int offset)
86275 {
86276 struct sctphdr *sh = sctp_hdr(skb);
86277- __le32 ret, old = sh->checksum;
86278- const struct skb_checksum_ops ops = {
86279+ __le32 ret, old = sh->checksum;
86280+ static const struct skb_checksum_ops ops = {
86281 .update = sctp_csum_update,
86282 .combine = sctp_csum_combine,
86283 };
86284diff --git a/include/net/sctp/sm.h b/include/net/sctp/sm.h
86285index 72a31db..aaa63d9 100644
86286--- a/include/net/sctp/sm.h
86287+++ b/include/net/sctp/sm.h
86288@@ -80,7 +80,7 @@ typedef void (sctp_timer_event_t) (unsigned long);
86289 typedef struct {
86290 sctp_state_fn_t *fn;
86291 const char *name;
86292-} sctp_sm_table_entry_t;
86293+} __do_const sctp_sm_table_entry_t;
86294
86295 /* A naming convention of "sctp_sf_xxx" applies to all the state functions
86296 * currently in use.
86297@@ -292,7 +292,7 @@ __u32 sctp_generate_tag(const struct sctp_endpoint *);
86298 __u32 sctp_generate_tsn(const struct sctp_endpoint *);
86299
86300 /* Extern declarations for major data structures. */
86301-extern sctp_timer_event_t *sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
86302+extern sctp_timer_event_t * const sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
86303
86304
86305 /* Get the size of a DATA chunk payload. */
86306diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
86307index 4ff3f67..89ae38e 100644
86308--- a/include/net/sctp/structs.h
86309+++ b/include/net/sctp/structs.h
86310@@ -509,7 +509,7 @@ struct sctp_pf {
86311 void (*to_sk_saddr)(union sctp_addr *, struct sock *sk);
86312 void (*to_sk_daddr)(union sctp_addr *, struct sock *sk);
86313 struct sctp_af *af;
86314-};
86315+} __do_const;
86316
86317
86318 /* Structure to track chunk fragments that have been acked, but peer
86319diff --git a/include/net/sock.h b/include/net/sock.h
86320index 7db3db1..a915cca 100644
86321--- a/include/net/sock.h
86322+++ b/include/net/sock.h
86323@@ -355,7 +355,7 @@ struct sock {
86324 unsigned int sk_napi_id;
86325 unsigned int sk_ll_usec;
86326 #endif
86327- atomic_t sk_drops;
86328+ atomic_unchecked_t sk_drops;
86329 int sk_rcvbuf;
86330
86331 struct sk_filter __rcu *sk_filter;
86332@@ -1048,7 +1048,7 @@ struct proto {
86333 void (*destroy_cgroup)(struct mem_cgroup *memcg);
86334 struct cg_proto *(*proto_cgroup)(struct mem_cgroup *memcg);
86335 #endif
86336-};
86337+} __randomize_layout;
86338
86339 /*
86340 * Bits in struct cg_proto.flags
86341@@ -1235,7 +1235,7 @@ static inline u64 memcg_memory_allocated_read(struct cg_proto *prot)
86342 return ret >> PAGE_SHIFT;
86343 }
86344
86345-static inline long
86346+static inline long __intentional_overflow(-1)
86347 sk_memory_allocated(const struct sock *sk)
86348 {
86349 struct proto *prot = sk->sk_prot;
86350@@ -1380,7 +1380,7 @@ struct sock_iocb {
86351 struct scm_cookie *scm;
86352 struct msghdr *msg, async_msg;
86353 struct kiocb *kiocb;
86354-};
86355+} __randomize_layout;
86356
86357 static inline struct sock_iocb *kiocb_to_siocb(struct kiocb *iocb)
86358 {
86359@@ -1820,7 +1820,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
86360 }
86361
86362 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
86363- char __user *from, char *to,
86364+ char __user *from, unsigned char *to,
86365 int copy, int offset)
86366 {
86367 if (skb->ip_summed == CHECKSUM_NONE) {
86368@@ -2092,7 +2092,7 @@ static inline void sk_stream_moderate_sndbuf(struct sock *sk)
86369 }
86370 }
86371
86372-struct sk_buff *sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
86373+struct sk_buff * __intentional_overflow(0) sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
86374
86375 /**
86376 * sk_page_frag - return an appropriate page_frag
86377diff --git a/include/net/tcp.h b/include/net/tcp.h
86378index 4062b4f..9ff45e7 100644
86379--- a/include/net/tcp.h
86380+++ b/include/net/tcp.h
86381@@ -519,7 +519,7 @@ void tcp_retransmit_timer(struct sock *sk);
86382 void tcp_xmit_retransmit_queue(struct sock *);
86383 void tcp_simple_retransmit(struct sock *);
86384 int tcp_trim_head(struct sock *, struct sk_buff *, u32);
86385-int tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int, gfp_t);
86386+int __intentional_overflow(3) tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int, gfp_t);
86387
86388 void tcp_send_probe0(struct sock *);
86389 void tcp_send_partial(struct sock *);
86390@@ -692,8 +692,8 @@ static inline u32 tcp_skb_timestamp(const struct sk_buff *skb)
86391 * If this grows please adjust skbuff.h:skbuff->cb[xxx] size appropriately.
86392 */
86393 struct tcp_skb_cb {
86394- __u32 seq; /* Starting sequence number */
86395- __u32 end_seq; /* SEQ + FIN + SYN + datalen */
86396+ __u32 seq __intentional_overflow(0); /* Starting sequence number */
86397+ __u32 end_seq __intentional_overflow(0); /* SEQ + FIN + SYN + datalen */
86398 union {
86399 /* Note : tcp_tw_isn is used in input path only
86400 * (isn chosen by tcp_timewait_state_process())
86401@@ -718,7 +718,7 @@ struct tcp_skb_cb {
86402
86403 __u8 ip_dsfield; /* IPv4 tos or IPv6 dsfield */
86404 /* 1 byte hole */
86405- __u32 ack_seq; /* Sequence number ACK'd */
86406+ __u32 ack_seq __intentional_overflow(0); /* Sequence number ACK'd */
86407 union {
86408 struct inet_skb_parm h4;
86409 #if IS_ENABLED(CONFIG_IPV6)
86410diff --git a/include/net/xfrm.h b/include/net/xfrm.h
86411index dc4865e..152ee4c 100644
86412--- a/include/net/xfrm.h
86413+++ b/include/net/xfrm.h
86414@@ -285,7 +285,6 @@ struct xfrm_dst;
86415 struct xfrm_policy_afinfo {
86416 unsigned short family;
86417 struct dst_ops *dst_ops;
86418- void (*garbage_collect)(struct net *net);
86419 struct dst_entry *(*dst_lookup)(struct net *net, int tos,
86420 const xfrm_address_t *saddr,
86421 const xfrm_address_t *daddr);
86422@@ -303,7 +302,7 @@ struct xfrm_policy_afinfo {
86423 struct net_device *dev,
86424 const struct flowi *fl);
86425 struct dst_entry *(*blackhole_route)(struct net *net, struct dst_entry *orig);
86426-};
86427+} __do_const;
86428
86429 int xfrm_policy_register_afinfo(struct xfrm_policy_afinfo *afinfo);
86430 int xfrm_policy_unregister_afinfo(struct xfrm_policy_afinfo *afinfo);
86431@@ -342,7 +341,7 @@ struct xfrm_state_afinfo {
86432 int (*transport_finish)(struct sk_buff *skb,
86433 int async);
86434 void (*local_error)(struct sk_buff *skb, u32 mtu);
86435-};
86436+} __do_const;
86437
86438 int xfrm_state_register_afinfo(struct xfrm_state_afinfo *afinfo);
86439 int xfrm_state_unregister_afinfo(struct xfrm_state_afinfo *afinfo);
86440@@ -437,7 +436,7 @@ struct xfrm_mode {
86441 struct module *owner;
86442 unsigned int encap;
86443 int flags;
86444-};
86445+} __do_const;
86446
86447 /* Flags for xfrm_mode. */
86448 enum {
86449@@ -534,7 +533,7 @@ struct xfrm_policy {
86450 struct timer_list timer;
86451
86452 struct flow_cache_object flo;
86453- atomic_t genid;
86454+ atomic_unchecked_t genid;
86455 u32 priority;
86456 u32 index;
86457 struct xfrm_mark mark;
86458@@ -1167,6 +1166,7 @@ static inline void xfrm_sk_free_policy(struct sock *sk)
86459 }
86460
86461 void xfrm_garbage_collect(struct net *net);
86462+void xfrm_garbage_collect_deferred(struct net *net);
86463
86464 #else
86465
86466@@ -1205,6 +1205,9 @@ static inline int xfrm6_policy_check_reverse(struct sock *sk, int dir,
86467 static inline void xfrm_garbage_collect(struct net *net)
86468 {
86469 }
86470+static inline void xfrm_garbage_collect_deferred(struct net *net)
86471+{
86472+}
86473 #endif
86474
86475 static __inline__
86476diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
86477index 1017e0b..227aa4d 100644
86478--- a/include/rdma/iw_cm.h
86479+++ b/include/rdma/iw_cm.h
86480@@ -122,7 +122,7 @@ struct iw_cm_verbs {
86481 int backlog);
86482
86483 int (*destroy_listen)(struct iw_cm_id *cm_id);
86484-};
86485+} __no_const;
86486
86487 /**
86488 * iw_create_cm_id - Create an IW CM identifier.
86489diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
86490index 52beadf..598734c 100644
86491--- a/include/scsi/libfc.h
86492+++ b/include/scsi/libfc.h
86493@@ -771,6 +771,7 @@ struct libfc_function_template {
86494 */
86495 void (*disc_stop_final) (struct fc_lport *);
86496 };
86497+typedef struct libfc_function_template __no_const libfc_function_template_no_const;
86498
86499 /**
86500 * struct fc_disc - Discovery context
86501@@ -875,7 +876,7 @@ struct fc_lport {
86502 struct fc_vport *vport;
86503
86504 /* Operational Information */
86505- struct libfc_function_template tt;
86506+ libfc_function_template_no_const tt;
86507 u8 link_up;
86508 u8 qfull;
86509 enum fc_lport_state state;
86510diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
86511index 27ecee7..5f42632 100644
86512--- a/include/scsi/scsi_device.h
86513+++ b/include/scsi/scsi_device.h
86514@@ -186,9 +186,9 @@ struct scsi_device {
86515 unsigned int max_device_blocked; /* what device_blocked counts down from */
86516 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
86517
86518- atomic_t iorequest_cnt;
86519- atomic_t iodone_cnt;
86520- atomic_t ioerr_cnt;
86521+ atomic_unchecked_t iorequest_cnt;
86522+ atomic_unchecked_t iodone_cnt;
86523+ atomic_unchecked_t ioerr_cnt;
86524
86525 struct device sdev_gendev,
86526 sdev_dev;
86527diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
86528index 007a0bc..7188db8 100644
86529--- a/include/scsi/scsi_transport_fc.h
86530+++ b/include/scsi/scsi_transport_fc.h
86531@@ -756,7 +756,8 @@ struct fc_function_template {
86532 unsigned long show_host_system_hostname:1;
86533
86534 unsigned long disable_target_scan:1;
86535-};
86536+} __do_const;
86537+typedef struct fc_function_template __no_const fc_function_template_no_const;
86538
86539
86540 /**
86541diff --git a/include/sound/compress_driver.h b/include/sound/compress_driver.h
86542index ae6c3b8..fd748ac 100644
86543--- a/include/sound/compress_driver.h
86544+++ b/include/sound/compress_driver.h
86545@@ -128,7 +128,7 @@ struct snd_compr_ops {
86546 struct snd_compr_caps *caps);
86547 int (*get_codec_caps) (struct snd_compr_stream *stream,
86548 struct snd_compr_codec_caps *codec);
86549-};
86550+} __no_const;
86551
86552 /**
86553 * struct snd_compr: Compressed device
86554diff --git a/include/sound/soc.h b/include/sound/soc.h
86555index 7ba7130..d46594d 100644
86556--- a/include/sound/soc.h
86557+++ b/include/sound/soc.h
86558@@ -853,7 +853,7 @@ struct snd_soc_codec_driver {
86559 enum snd_soc_dapm_type, int);
86560
86561 bool ignore_pmdown_time; /* Doesn't benefit from pmdown delay */
86562-};
86563+} __do_const;
86564
86565 /* SoC platform interface */
86566 struct snd_soc_platform_driver {
86567@@ -882,7 +882,7 @@ struct snd_soc_platform_driver {
86568 const struct snd_compr_ops *compr_ops;
86569
86570 int (*bespoke_trigger)(struct snd_pcm_substream *, int);
86571-};
86572+} __do_const;
86573
86574 struct snd_soc_dai_link_component {
86575 const char *name;
86576diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
86577index 23c518a..d6ef510 100644
86578--- a/include/target/target_core_base.h
86579+++ b/include/target/target_core_base.h
86580@@ -764,7 +764,7 @@ struct se_device {
86581 atomic_long_t write_bytes;
86582 /* Active commands on this virtual SE device */
86583 atomic_t simple_cmds;
86584- atomic_t dev_ordered_id;
86585+ atomic_unchecked_t dev_ordered_id;
86586 atomic_t dev_ordered_sync;
86587 atomic_t dev_qf_count;
86588 int export_count;
86589diff --git a/include/trace/events/fs.h b/include/trace/events/fs.h
86590new file mode 100644
86591index 0000000..fb634b7
86592--- /dev/null
86593+++ b/include/trace/events/fs.h
86594@@ -0,0 +1,53 @@
86595+#undef TRACE_SYSTEM
86596+#define TRACE_SYSTEM fs
86597+
86598+#if !defined(_TRACE_FS_H) || defined(TRACE_HEADER_MULTI_READ)
86599+#define _TRACE_FS_H
86600+
86601+#include <linux/fs.h>
86602+#include <linux/tracepoint.h>
86603+
86604+TRACE_EVENT(do_sys_open,
86605+
86606+ TP_PROTO(const char *filename, int flags, int mode),
86607+
86608+ TP_ARGS(filename, flags, mode),
86609+
86610+ TP_STRUCT__entry(
86611+ __string( filename, filename )
86612+ __field( int, flags )
86613+ __field( int, mode )
86614+ ),
86615+
86616+ TP_fast_assign(
86617+ __assign_str(filename, filename);
86618+ __entry->flags = flags;
86619+ __entry->mode = mode;
86620+ ),
86621+
86622+ TP_printk("\"%s\" %x %o",
86623+ __get_str(filename), __entry->flags, __entry->mode)
86624+);
86625+
86626+TRACE_EVENT(open_exec,
86627+
86628+ TP_PROTO(const char *filename),
86629+
86630+ TP_ARGS(filename),
86631+
86632+ TP_STRUCT__entry(
86633+ __string( filename, filename )
86634+ ),
86635+
86636+ TP_fast_assign(
86637+ __assign_str(filename, filename);
86638+ ),
86639+
86640+ TP_printk("\"%s\"",
86641+ __get_str(filename))
86642+);
86643+
86644+#endif /* _TRACE_FS_H */
86645+
86646+/* This part must be outside protection */
86647+#include <trace/define_trace.h>
86648diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
86649index 3608beb..df39d8a 100644
86650--- a/include/trace/events/irq.h
86651+++ b/include/trace/events/irq.h
86652@@ -36,7 +36,7 @@ struct softirq_action;
86653 */
86654 TRACE_EVENT(irq_handler_entry,
86655
86656- TP_PROTO(int irq, struct irqaction *action),
86657+ TP_PROTO(int irq, const struct irqaction *action),
86658
86659 TP_ARGS(irq, action),
86660
86661@@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
86662 */
86663 TRACE_EVENT(irq_handler_exit,
86664
86665- TP_PROTO(int irq, struct irqaction *action, int ret),
86666+ TP_PROTO(int irq, const struct irqaction *action, int ret),
86667
86668 TP_ARGS(irq, action, ret),
86669
86670diff --git a/include/uapi/linux/a.out.h b/include/uapi/linux/a.out.h
86671index 7caf44c..23c6f27 100644
86672--- a/include/uapi/linux/a.out.h
86673+++ b/include/uapi/linux/a.out.h
86674@@ -39,6 +39,14 @@ enum machine_type {
86675 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
86676 };
86677
86678+/* Constants for the N_FLAGS field */
86679+#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
86680+#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
86681+#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
86682+#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
86683+/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
86684+#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
86685+
86686 #if !defined (N_MAGIC)
86687 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
86688 #endif
86689diff --git a/include/uapi/linux/bcache.h b/include/uapi/linux/bcache.h
86690index 22b6ad3..aeba37e 100644
86691--- a/include/uapi/linux/bcache.h
86692+++ b/include/uapi/linux/bcache.h
86693@@ -5,6 +5,7 @@
86694 * Bcache on disk data structures
86695 */
86696
86697+#include <linux/compiler.h>
86698 #include <asm/types.h>
86699
86700 #define BITMASK(name, type, field, offset, size) \
86701@@ -20,8 +21,8 @@ static inline void SET_##name(type *k, __u64 v) \
86702 /* Btree keys - all units are in sectors */
86703
86704 struct bkey {
86705- __u64 high;
86706- __u64 low;
86707+ __u64 high __intentional_overflow(-1);
86708+ __u64 low __intentional_overflow(-1);
86709 __u64 ptr[];
86710 };
86711
86712diff --git a/include/uapi/linux/byteorder/little_endian.h b/include/uapi/linux/byteorder/little_endian.h
86713index d876736..ccce5c0 100644
86714--- a/include/uapi/linux/byteorder/little_endian.h
86715+++ b/include/uapi/linux/byteorder/little_endian.h
86716@@ -42,51 +42,51 @@
86717
86718 static inline __le64 __cpu_to_le64p(const __u64 *p)
86719 {
86720- return (__force __le64)*p;
86721+ return (__force const __le64)*p;
86722 }
86723-static inline __u64 __le64_to_cpup(const __le64 *p)
86724+static inline __u64 __intentional_overflow(-1) __le64_to_cpup(const __le64 *p)
86725 {
86726- return (__force __u64)*p;
86727+ return (__force const __u64)*p;
86728 }
86729 static inline __le32 __cpu_to_le32p(const __u32 *p)
86730 {
86731- return (__force __le32)*p;
86732+ return (__force const __le32)*p;
86733 }
86734 static inline __u32 __le32_to_cpup(const __le32 *p)
86735 {
86736- return (__force __u32)*p;
86737+ return (__force const __u32)*p;
86738 }
86739 static inline __le16 __cpu_to_le16p(const __u16 *p)
86740 {
86741- return (__force __le16)*p;
86742+ return (__force const __le16)*p;
86743 }
86744 static inline __u16 __le16_to_cpup(const __le16 *p)
86745 {
86746- return (__force __u16)*p;
86747+ return (__force const __u16)*p;
86748 }
86749 static inline __be64 __cpu_to_be64p(const __u64 *p)
86750 {
86751- return (__force __be64)__swab64p(p);
86752+ return (__force const __be64)__swab64p(p);
86753 }
86754 static inline __u64 __be64_to_cpup(const __be64 *p)
86755 {
86756- return __swab64p((__u64 *)p);
86757+ return __swab64p((const __u64 *)p);
86758 }
86759 static inline __be32 __cpu_to_be32p(const __u32 *p)
86760 {
86761- return (__force __be32)__swab32p(p);
86762+ return (__force const __be32)__swab32p(p);
86763 }
86764-static inline __u32 __be32_to_cpup(const __be32 *p)
86765+static inline __u32 __intentional_overflow(-1) __be32_to_cpup(const __be32 *p)
86766 {
86767- return __swab32p((__u32 *)p);
86768+ return __swab32p((const __u32 *)p);
86769 }
86770 static inline __be16 __cpu_to_be16p(const __u16 *p)
86771 {
86772- return (__force __be16)__swab16p(p);
86773+ return (__force const __be16)__swab16p(p);
86774 }
86775 static inline __u16 __be16_to_cpup(const __be16 *p)
86776 {
86777- return __swab16p((__u16 *)p);
86778+ return __swab16p((const __u16 *)p);
86779 }
86780 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
86781 #define __le64_to_cpus(x) do { (void)(x); } while (0)
86782diff --git a/include/uapi/linux/elf.h b/include/uapi/linux/elf.h
86783index ea9bf25..5140c61 100644
86784--- a/include/uapi/linux/elf.h
86785+++ b/include/uapi/linux/elf.h
86786@@ -37,6 +37,17 @@ typedef __s64 Elf64_Sxword;
86787 #define PT_GNU_EH_FRAME 0x6474e550
86788
86789 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
86790+#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
86791+
86792+#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
86793+
86794+/* Constants for the e_flags field */
86795+#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
86796+#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
86797+#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
86798+#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
86799+/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
86800+#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
86801
86802 /*
86803 * Extended Numbering
86804@@ -94,6 +105,8 @@ typedef __s64 Elf64_Sxword;
86805 #define DT_DEBUG 21
86806 #define DT_TEXTREL 22
86807 #define DT_JMPREL 23
86808+#define DT_FLAGS 30
86809+ #define DF_TEXTREL 0x00000004
86810 #define DT_ENCODING 32
86811 #define OLD_DT_LOOS 0x60000000
86812 #define DT_LOOS 0x6000000d
86813@@ -240,6 +253,19 @@ typedef struct elf64_hdr {
86814 #define PF_W 0x2
86815 #define PF_X 0x1
86816
86817+#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
86818+#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
86819+#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
86820+#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
86821+#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
86822+#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
86823+/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
86824+/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
86825+#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
86826+#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
86827+#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
86828+#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
86829+
86830 typedef struct elf32_phdr{
86831 Elf32_Word p_type;
86832 Elf32_Off p_offset;
86833@@ -332,6 +358,8 @@ typedef struct elf64_shdr {
86834 #define EI_OSABI 7
86835 #define EI_PAD 8
86836
86837+#define EI_PAX 14
86838+
86839 #define ELFMAG0 0x7f /* EI_MAG */
86840 #define ELFMAG1 'E'
86841 #define ELFMAG2 'L'
86842diff --git a/include/uapi/linux/personality.h b/include/uapi/linux/personality.h
86843index aa169c4..6a2771d 100644
86844--- a/include/uapi/linux/personality.h
86845+++ b/include/uapi/linux/personality.h
86846@@ -30,6 +30,7 @@ enum {
86847 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
86848 ADDR_NO_RANDOMIZE | \
86849 ADDR_COMPAT_LAYOUT | \
86850+ ADDR_LIMIT_3GB | \
86851 MMAP_PAGE_ZERO)
86852
86853 /*
86854diff --git a/include/uapi/linux/screen_info.h b/include/uapi/linux/screen_info.h
86855index 7530e74..e714828 100644
86856--- a/include/uapi/linux/screen_info.h
86857+++ b/include/uapi/linux/screen_info.h
86858@@ -43,7 +43,8 @@ struct screen_info {
86859 __u16 pages; /* 0x32 */
86860 __u16 vesa_attributes; /* 0x34 */
86861 __u32 capabilities; /* 0x36 */
86862- __u8 _reserved[6]; /* 0x3a */
86863+ __u16 vesapm_size; /* 0x3a */
86864+ __u8 _reserved[4]; /* 0x3c */
86865 } __attribute__((packed));
86866
86867 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
86868diff --git a/include/uapi/linux/swab.h b/include/uapi/linux/swab.h
86869index 0e011eb..82681b1 100644
86870--- a/include/uapi/linux/swab.h
86871+++ b/include/uapi/linux/swab.h
86872@@ -43,7 +43,7 @@
86873 * ___swab16, ___swab32, ___swab64, ___swahw32, ___swahb32
86874 */
86875
86876-static inline __attribute_const__ __u16 __fswab16(__u16 val)
86877+static inline __intentional_overflow(-1) __attribute_const__ __u16 __fswab16(__u16 val)
86878 {
86879 #ifdef __HAVE_BUILTIN_BSWAP16__
86880 return __builtin_bswap16(val);
86881@@ -54,7 +54,7 @@ static inline __attribute_const__ __u16 __fswab16(__u16 val)
86882 #endif
86883 }
86884
86885-static inline __attribute_const__ __u32 __fswab32(__u32 val)
86886+static inline __intentional_overflow(-1) __attribute_const__ __u32 __fswab32(__u32 val)
86887 {
86888 #ifdef __HAVE_BUILTIN_BSWAP32__
86889 return __builtin_bswap32(val);
86890@@ -65,7 +65,7 @@ static inline __attribute_const__ __u32 __fswab32(__u32 val)
86891 #endif
86892 }
86893
86894-static inline __attribute_const__ __u64 __fswab64(__u64 val)
86895+static inline __intentional_overflow(-1) __attribute_const__ __u64 __fswab64(__u64 val)
86896 {
86897 #ifdef __HAVE_BUILTIN_BSWAP64__
86898 return __builtin_bswap64(val);
86899diff --git a/include/uapi/linux/sysctl.h b/include/uapi/linux/sysctl.h
86900index 43aaba1..1c30b48 100644
86901--- a/include/uapi/linux/sysctl.h
86902+++ b/include/uapi/linux/sysctl.h
86903@@ -155,8 +155,6 @@ enum
86904 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
86905 };
86906
86907-
86908-
86909 /* CTL_VM names: */
86910 enum
86911 {
86912diff --git a/include/uapi/linux/xattr.h b/include/uapi/linux/xattr.h
86913index 1590c49..5eab462 100644
86914--- a/include/uapi/linux/xattr.h
86915+++ b/include/uapi/linux/xattr.h
86916@@ -73,5 +73,9 @@
86917 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
86918 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
86919
86920+/* User namespace */
86921+#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
86922+#define XATTR_PAX_FLAGS_SUFFIX "flags"
86923+#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
86924
86925 #endif /* _UAPI_LINUX_XATTR_H */
86926diff --git a/include/video/udlfb.h b/include/video/udlfb.h
86927index f9466fa..f4e2b81 100644
86928--- a/include/video/udlfb.h
86929+++ b/include/video/udlfb.h
86930@@ -53,10 +53,10 @@ struct dlfb_data {
86931 u32 pseudo_palette[256];
86932 int blank_mode; /*one of FB_BLANK_ */
86933 /* blit-only rendering path metrics, exposed through sysfs */
86934- atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
86935- atomic_t bytes_identical; /* saved effort with backbuffer comparison */
86936- atomic_t bytes_sent; /* to usb, after compression including overhead */
86937- atomic_t cpu_kcycles_used; /* transpired during pixel processing */
86938+ atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
86939+ atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
86940+ atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
86941+ atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
86942 };
86943
86944 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
86945diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
86946index 30f5362..8ed8ac9 100644
86947--- a/include/video/uvesafb.h
86948+++ b/include/video/uvesafb.h
86949@@ -122,6 +122,7 @@ struct uvesafb_par {
86950 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
86951 u8 pmi_setpal; /* PMI for palette changes */
86952 u16 *pmi_base; /* protected mode interface location */
86953+ u8 *pmi_code; /* protected mode code location */
86954 void *pmi_start;
86955 void *pmi_pal;
86956 u8 *vbe_state_orig; /*
86957diff --git a/init/Kconfig b/init/Kconfig
86958index 2081a4d..98d1149 100644
86959--- a/init/Kconfig
86960+++ b/init/Kconfig
86961@@ -1150,6 +1150,7 @@ endif # CGROUPS
86962
86963 config CHECKPOINT_RESTORE
86964 bool "Checkpoint/restore support" if EXPERT
86965+ depends on !GRKERNSEC
86966 default n
86967 help
86968 Enables additional kernel features in a sake of checkpoint/restore.
86969@@ -1659,7 +1660,7 @@ config SLUB_DEBUG
86970
86971 config COMPAT_BRK
86972 bool "Disable heap randomization"
86973- default y
86974+ default n
86975 help
86976 Randomizing heap placement makes heap exploits harder, but it
86977 also breaks ancient binaries (including anything libc5 based).
86978@@ -1990,7 +1991,7 @@ config INIT_ALL_POSSIBLE
86979 config STOP_MACHINE
86980 bool
86981 default y
86982- depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU
86983+ depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU || GRKERNSEC
86984 help
86985 Need stop_machine() primitive.
86986
86987diff --git a/init/Makefile b/init/Makefile
86988index 7bc47ee..6da2dc7 100644
86989--- a/init/Makefile
86990+++ b/init/Makefile
86991@@ -2,6 +2,9 @@
86992 # Makefile for the linux kernel.
86993 #
86994
86995+ccflags-y := $(GCC_PLUGINS_CFLAGS)
86996+asflags-y := $(GCC_PLUGINS_AFLAGS)
86997+
86998 obj-y := main.o version.o mounts.o
86999 ifneq ($(CONFIG_BLK_DEV_INITRD),y)
87000 obj-y += noinitramfs.o
87001diff --git a/init/do_mounts.c b/init/do_mounts.c
87002index 9b3565c..3f90cf9 100644
87003--- a/init/do_mounts.c
87004+++ b/init/do_mounts.c
87005@@ -360,11 +360,11 @@ static void __init get_fs_names(char *page)
87006 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
87007 {
87008 struct super_block *s;
87009- int err = sys_mount(name, "/root", fs, flags, data);
87010+ int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
87011 if (err)
87012 return err;
87013
87014- sys_chdir("/root");
87015+ sys_chdir((const char __force_user *)"/root");
87016 s = current->fs->pwd.dentry->d_sb;
87017 ROOT_DEV = s->s_dev;
87018 printk(KERN_INFO
87019@@ -485,18 +485,18 @@ void __init change_floppy(char *fmt, ...)
87020 va_start(args, fmt);
87021 vsprintf(buf, fmt, args);
87022 va_end(args);
87023- fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
87024+ fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
87025 if (fd >= 0) {
87026 sys_ioctl(fd, FDEJECT, 0);
87027 sys_close(fd);
87028 }
87029 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
87030- fd = sys_open("/dev/console", O_RDWR, 0);
87031+ fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
87032 if (fd >= 0) {
87033 sys_ioctl(fd, TCGETS, (long)&termios);
87034 termios.c_lflag &= ~ICANON;
87035 sys_ioctl(fd, TCSETSF, (long)&termios);
87036- sys_read(fd, &c, 1);
87037+ sys_read(fd, (char __user *)&c, 1);
87038 termios.c_lflag |= ICANON;
87039 sys_ioctl(fd, TCSETSF, (long)&termios);
87040 sys_close(fd);
87041@@ -590,8 +590,8 @@ void __init prepare_namespace(void)
87042 mount_root();
87043 out:
87044 devtmpfs_mount("dev");
87045- sys_mount(".", "/", NULL, MS_MOVE, NULL);
87046- sys_chroot(".");
87047+ sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
87048+ sys_chroot((const char __force_user *)".");
87049 }
87050
87051 static bool is_tmpfs;
87052diff --git a/init/do_mounts.h b/init/do_mounts.h
87053index f5b978a..69dbfe8 100644
87054--- a/init/do_mounts.h
87055+++ b/init/do_mounts.h
87056@@ -15,15 +15,15 @@ extern int root_mountflags;
87057
87058 static inline int create_dev(char *name, dev_t dev)
87059 {
87060- sys_unlink(name);
87061- return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
87062+ sys_unlink((char __force_user *)name);
87063+ return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
87064 }
87065
87066 #if BITS_PER_LONG == 32
87067 static inline u32 bstat(char *name)
87068 {
87069 struct stat64 stat;
87070- if (sys_stat64(name, &stat) != 0)
87071+ if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
87072 return 0;
87073 if (!S_ISBLK(stat.st_mode))
87074 return 0;
87075@@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
87076 static inline u32 bstat(char *name)
87077 {
87078 struct stat stat;
87079- if (sys_newstat(name, &stat) != 0)
87080+ if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
87081 return 0;
87082 if (!S_ISBLK(stat.st_mode))
87083 return 0;
87084diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
87085index 3e0878e..8a9d7a0 100644
87086--- a/init/do_mounts_initrd.c
87087+++ b/init/do_mounts_initrd.c
87088@@ -37,13 +37,13 @@ static int init_linuxrc(struct subprocess_info *info, struct cred *new)
87089 {
87090 sys_unshare(CLONE_FS | CLONE_FILES);
87091 /* stdin/stdout/stderr for /linuxrc */
87092- sys_open("/dev/console", O_RDWR, 0);
87093+ sys_open((const char __force_user *)"/dev/console", O_RDWR, 0);
87094 sys_dup(0);
87095 sys_dup(0);
87096 /* move initrd over / and chdir/chroot in initrd root */
87097- sys_chdir("/root");
87098- sys_mount(".", "/", NULL, MS_MOVE, NULL);
87099- sys_chroot(".");
87100+ sys_chdir((const char __force_user *)"/root");
87101+ sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
87102+ sys_chroot((const char __force_user *)".");
87103 sys_setsid();
87104 return 0;
87105 }
87106@@ -59,8 +59,8 @@ static void __init handle_initrd(void)
87107 create_dev("/dev/root.old", Root_RAM0);
87108 /* mount initrd on rootfs' /root */
87109 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
87110- sys_mkdir("/old", 0700);
87111- sys_chdir("/old");
87112+ sys_mkdir((const char __force_user *)"/old", 0700);
87113+ sys_chdir((const char __force_user *)"/old");
87114
87115 /* try loading default modules from initrd */
87116 load_default_modules();
87117@@ -80,31 +80,31 @@ static void __init handle_initrd(void)
87118 current->flags &= ~PF_FREEZER_SKIP;
87119
87120 /* move initrd to rootfs' /old */
87121- sys_mount("..", ".", NULL, MS_MOVE, NULL);
87122+ sys_mount((char __force_user *)"..", (char __force_user *)".", NULL, MS_MOVE, NULL);
87123 /* switch root and cwd back to / of rootfs */
87124- sys_chroot("..");
87125+ sys_chroot((const char __force_user *)"..");
87126
87127 if (new_decode_dev(real_root_dev) == Root_RAM0) {
87128- sys_chdir("/old");
87129+ sys_chdir((const char __force_user *)"/old");
87130 return;
87131 }
87132
87133- sys_chdir("/");
87134+ sys_chdir((const char __force_user *)"/");
87135 ROOT_DEV = new_decode_dev(real_root_dev);
87136 mount_root();
87137
87138 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
87139- error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
87140+ error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
87141 if (!error)
87142 printk("okay\n");
87143 else {
87144- int fd = sys_open("/dev/root.old", O_RDWR, 0);
87145+ int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
87146 if (error == -ENOENT)
87147 printk("/initrd does not exist. Ignored.\n");
87148 else
87149 printk("failed\n");
87150 printk(KERN_NOTICE "Unmounting old root\n");
87151- sys_umount("/old", MNT_DETACH);
87152+ sys_umount((char __force_user *)"/old", MNT_DETACH);
87153 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
87154 if (fd < 0) {
87155 error = fd;
87156@@ -127,11 +127,11 @@ int __init initrd_load(void)
87157 * mounted in the normal path.
87158 */
87159 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
87160- sys_unlink("/initrd.image");
87161+ sys_unlink((const char __force_user *)"/initrd.image");
87162 handle_initrd();
87163 return 1;
87164 }
87165 }
87166- sys_unlink("/initrd.image");
87167+ sys_unlink((const char __force_user *)"/initrd.image");
87168 return 0;
87169 }
87170diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
87171index 8cb6db5..d729f50 100644
87172--- a/init/do_mounts_md.c
87173+++ b/init/do_mounts_md.c
87174@@ -180,7 +180,7 @@ static void __init md_setup_drive(void)
87175 partitioned ? "_d" : "", minor,
87176 md_setup_args[ent].device_names);
87177
87178- fd = sys_open(name, 0, 0);
87179+ fd = sys_open((char __force_user *)name, 0, 0);
87180 if (fd < 0) {
87181 printk(KERN_ERR "md: open failed - cannot start "
87182 "array %s\n", name);
87183@@ -243,7 +243,7 @@ static void __init md_setup_drive(void)
87184 * array without it
87185 */
87186 sys_close(fd);
87187- fd = sys_open(name, 0, 0);
87188+ fd = sys_open((char __force_user *)name, 0, 0);
87189 sys_ioctl(fd, BLKRRPART, 0);
87190 }
87191 sys_close(fd);
87192@@ -293,7 +293,7 @@ static void __init autodetect_raid(void)
87193
87194 wait_for_device_probe();
87195
87196- fd = sys_open("/dev/md0", 0, 0);
87197+ fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
87198 if (fd >= 0) {
87199 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
87200 sys_close(fd);
87201diff --git a/init/init_task.c b/init/init_task.c
87202index ba0a7f36..2bcf1d5 100644
87203--- a/init/init_task.c
87204+++ b/init/init_task.c
87205@@ -22,5 +22,9 @@ EXPORT_SYMBOL(init_task);
87206 * Initial thread structure. Alignment of this is handled by a special
87207 * linker map entry.
87208 */
87209+#ifdef CONFIG_X86
87210+union thread_union init_thread_union __init_task_data;
87211+#else
87212 union thread_union init_thread_union __init_task_data =
87213 { INIT_THREAD_INFO(init_task) };
87214+#endif
87215diff --git a/init/initramfs.c b/init/initramfs.c
87216index ad1bd77..dca2c1b 100644
87217--- a/init/initramfs.c
87218+++ b/init/initramfs.c
87219@@ -25,7 +25,7 @@ static ssize_t __init xwrite(int fd, const char *p, size_t count)
87220
87221 /* sys_write only can write MAX_RW_COUNT aka 2G-4K bytes at most */
87222 while (count) {
87223- ssize_t rv = sys_write(fd, p, count);
87224+ ssize_t rv = sys_write(fd, (char __force_user *)p, count);
87225
87226 if (rv < 0) {
87227 if (rv == -EINTR || rv == -EAGAIN)
87228@@ -107,7 +107,7 @@ static void __init free_hash(void)
87229 }
87230 }
87231
87232-static long __init do_utime(char *filename, time_t mtime)
87233+static long __init do_utime(char __force_user *filename, time_t mtime)
87234 {
87235 struct timespec t[2];
87236
87237@@ -142,7 +142,7 @@ static void __init dir_utime(void)
87238 struct dir_entry *de, *tmp;
87239 list_for_each_entry_safe(de, tmp, &dir_list, list) {
87240 list_del(&de->list);
87241- do_utime(de->name, de->mtime);
87242+ do_utime((char __force_user *)de->name, de->mtime);
87243 kfree(de->name);
87244 kfree(de);
87245 }
87246@@ -304,7 +304,7 @@ static int __init maybe_link(void)
87247 if (nlink >= 2) {
87248 char *old = find_link(major, minor, ino, mode, collected);
87249 if (old)
87250- return (sys_link(old, collected) < 0) ? -1 : 1;
87251+ return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
87252 }
87253 return 0;
87254 }
87255@@ -313,11 +313,11 @@ static void __init clean_path(char *path, umode_t fmode)
87256 {
87257 struct stat st;
87258
87259- if (!sys_newlstat(path, &st) && (st.st_mode ^ fmode) & S_IFMT) {
87260+ if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode ^ fmode) & S_IFMT) {
87261 if (S_ISDIR(st.st_mode))
87262- sys_rmdir(path);
87263+ sys_rmdir((char __force_user *)path);
87264 else
87265- sys_unlink(path);
87266+ sys_unlink((char __force_user *)path);
87267 }
87268 }
87269
87270@@ -338,7 +338,7 @@ static int __init do_name(void)
87271 int openflags = O_WRONLY|O_CREAT;
87272 if (ml != 1)
87273 openflags |= O_TRUNC;
87274- wfd = sys_open(collected, openflags, mode);
87275+ wfd = sys_open((char __force_user *)collected, openflags, mode);
87276
87277 if (wfd >= 0) {
87278 sys_fchown(wfd, uid, gid);
87279@@ -350,17 +350,17 @@ static int __init do_name(void)
87280 }
87281 }
87282 } else if (S_ISDIR(mode)) {
87283- sys_mkdir(collected, mode);
87284- sys_chown(collected, uid, gid);
87285- sys_chmod(collected, mode);
87286+ sys_mkdir((char __force_user *)collected, mode);
87287+ sys_chown((char __force_user *)collected, uid, gid);
87288+ sys_chmod((char __force_user *)collected, mode);
87289 dir_add(collected, mtime);
87290 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
87291 S_ISFIFO(mode) || S_ISSOCK(mode)) {
87292 if (maybe_link() == 0) {
87293- sys_mknod(collected, mode, rdev);
87294- sys_chown(collected, uid, gid);
87295- sys_chmod(collected, mode);
87296- do_utime(collected, mtime);
87297+ sys_mknod((char __force_user *)collected, mode, rdev);
87298+ sys_chown((char __force_user *)collected, uid, gid);
87299+ sys_chmod((char __force_user *)collected, mode);
87300+ do_utime((char __force_user *)collected, mtime);
87301 }
87302 }
87303 return 0;
87304@@ -372,7 +372,7 @@ static int __init do_copy(void)
87305 if (xwrite(wfd, victim, body_len) != body_len)
87306 error("write error");
87307 sys_close(wfd);
87308- do_utime(vcollected, mtime);
87309+ do_utime((char __force_user *)vcollected, mtime);
87310 kfree(vcollected);
87311 eat(body_len);
87312 state = SkipIt;
87313@@ -390,9 +390,9 @@ static int __init do_symlink(void)
87314 {
87315 collected[N_ALIGN(name_len) + body_len] = '\0';
87316 clean_path(collected, 0);
87317- sys_symlink(collected + N_ALIGN(name_len), collected);
87318- sys_lchown(collected, uid, gid);
87319- do_utime(collected, mtime);
87320+ sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
87321+ sys_lchown((char __force_user *)collected, uid, gid);
87322+ do_utime((char __force_user *)collected, mtime);
87323 state = SkipIt;
87324 next_state = Reset;
87325 return 0;
87326diff --git a/init/main.c b/init/main.c
87327index 321d0ce..91b53e5 100644
87328--- a/init/main.c
87329+++ b/init/main.c
87330@@ -98,6 +98,8 @@ extern void radix_tree_init(void);
87331 static inline void mark_rodata_ro(void) { }
87332 #endif
87333
87334+extern void grsecurity_init(void);
87335+
87336 /*
87337 * Debug helper: via this flag we know that we are in 'early bootup code'
87338 * where only the boot processor is running with IRQ disabled. This means
87339@@ -159,6 +161,75 @@ static int __init set_reset_devices(char *str)
87340
87341 __setup("reset_devices", set_reset_devices);
87342
87343+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
87344+kgid_t grsec_proc_gid = KGIDT_INIT(CONFIG_GRKERNSEC_PROC_GID);
87345+static int __init setup_grsec_proc_gid(char *str)
87346+{
87347+ grsec_proc_gid = KGIDT_INIT(simple_strtol(str, NULL, 0));
87348+ return 1;
87349+}
87350+__setup("grsec_proc_gid=", setup_grsec_proc_gid);
87351+#endif
87352+
87353+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
87354+unsigned long pax_user_shadow_base __read_only;
87355+EXPORT_SYMBOL(pax_user_shadow_base);
87356+extern char pax_enter_kernel_user[];
87357+extern char pax_exit_kernel_user[];
87358+#endif
87359+
87360+#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
87361+static int __init setup_pax_nouderef(char *str)
87362+{
87363+#ifdef CONFIG_X86_32
87364+ unsigned int cpu;
87365+ struct desc_struct *gdt;
87366+
87367+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
87368+ gdt = get_cpu_gdt_table(cpu);
87369+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
87370+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
87371+ gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
87372+ gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
87373+ }
87374+ loadsegment(ds, __KERNEL_DS);
87375+ loadsegment(es, __KERNEL_DS);
87376+ loadsegment(ss, __KERNEL_DS);
87377+#else
87378+ memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
87379+ memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
87380+ clone_pgd_mask = ~(pgdval_t)0UL;
87381+ pax_user_shadow_base = 0UL;
87382+ setup_clear_cpu_cap(X86_FEATURE_PCID);
87383+ setup_clear_cpu_cap(X86_FEATURE_INVPCID);
87384+#endif
87385+
87386+ return 0;
87387+}
87388+early_param("pax_nouderef", setup_pax_nouderef);
87389+
87390+#ifdef CONFIG_X86_64
87391+static int __init setup_pax_weakuderef(char *str)
87392+{
87393+ if (clone_pgd_mask != ~(pgdval_t)0UL)
87394+ pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
87395+ return 1;
87396+}
87397+__setup("pax_weakuderef", setup_pax_weakuderef);
87398+#endif
87399+#endif
87400+
87401+#ifdef CONFIG_PAX_SOFTMODE
87402+int pax_softmode;
87403+
87404+static int __init setup_pax_softmode(char *str)
87405+{
87406+ get_option(&str, &pax_softmode);
87407+ return 1;
87408+}
87409+__setup("pax_softmode=", setup_pax_softmode);
87410+#endif
87411+
87412 static const char *argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
87413 const char *envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
87414 static const char *panic_later, *panic_param;
87415@@ -728,7 +799,7 @@ static bool __init_or_module initcall_blacklisted(initcall_t fn)
87416 struct blacklist_entry *entry;
87417 char *fn_name;
87418
87419- fn_name = kasprintf(GFP_KERNEL, "%pf", fn);
87420+ fn_name = kasprintf(GFP_KERNEL, "%pX", fn);
87421 if (!fn_name)
87422 return false;
87423
87424@@ -780,7 +851,7 @@ int __init_or_module do_one_initcall(initcall_t fn)
87425 {
87426 int count = preempt_count();
87427 int ret;
87428- char msgbuf[64];
87429+ const char *msg1 = "", *msg2 = "";
87430
87431 if (initcall_blacklisted(fn))
87432 return -EPERM;
87433@@ -790,18 +861,17 @@ int __init_or_module do_one_initcall(initcall_t fn)
87434 else
87435 ret = fn();
87436
87437- msgbuf[0] = 0;
87438-
87439 if (preempt_count() != count) {
87440- sprintf(msgbuf, "preemption imbalance ");
87441+ msg1 = " preemption imbalance";
87442 preempt_count_set(count);
87443 }
87444 if (irqs_disabled()) {
87445- strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
87446+ msg2 = " disabled interrupts";
87447 local_irq_enable();
87448 }
87449- WARN(msgbuf[0], "initcall %pF returned with %s\n", fn, msgbuf);
87450+ WARN(*msg1 || *msg2, "initcall %pF returned with%s%s\n", fn, msg1, msg2);
87451
87452+ add_latent_entropy();
87453 return ret;
87454 }
87455
87456@@ -907,8 +977,8 @@ static int run_init_process(const char *init_filename)
87457 {
87458 argv_init[0] = init_filename;
87459 return do_execve(getname_kernel(init_filename),
87460- (const char __user *const __user *)argv_init,
87461- (const char __user *const __user *)envp_init);
87462+ (const char __user *const __force_user *)argv_init,
87463+ (const char __user *const __force_user *)envp_init);
87464 }
87465
87466 static int try_to_run_init_process(const char *init_filename)
87467@@ -925,6 +995,10 @@ static int try_to_run_init_process(const char *init_filename)
87468 return ret;
87469 }
87470
87471+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
87472+extern int gr_init_ran;
87473+#endif
87474+
87475 static noinline void __init kernel_init_freeable(void);
87476
87477 static int __ref kernel_init(void *unused)
87478@@ -949,6 +1023,11 @@ static int __ref kernel_init(void *unused)
87479 ramdisk_execute_command, ret);
87480 }
87481
87482+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
87483+ /* if no initrd was used, be extra sure we enforce chroot restrictions */
87484+ gr_init_ran = 1;
87485+#endif
87486+
87487 /*
87488 * We try each of these until one succeeds.
87489 *
87490@@ -1004,7 +1083,7 @@ static noinline void __init kernel_init_freeable(void)
87491 do_basic_setup();
87492
87493 /* Open the /dev/console on the rootfs, this should never fail */
87494- if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
87495+ if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
87496 pr_err("Warning: unable to open an initial console.\n");
87497
87498 (void) sys_dup(0);
87499@@ -1017,11 +1096,13 @@ static noinline void __init kernel_init_freeable(void)
87500 if (!ramdisk_execute_command)
87501 ramdisk_execute_command = "/init";
87502
87503- if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
87504+ if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
87505 ramdisk_execute_command = NULL;
87506 prepare_namespace();
87507 }
87508
87509+ grsecurity_init();
87510+
87511 /*
87512 * Ok, we have completed the initial bootup, and
87513 * we're essentially up and running. Get rid of the
87514diff --git a/ipc/compat.c b/ipc/compat.c
87515index 9b3c85f..1c4d897 100644
87516--- a/ipc/compat.c
87517+++ b/ipc/compat.c
87518@@ -396,7 +396,7 @@ COMPAT_SYSCALL_DEFINE6(ipc, u32, call, int, first, int, second,
87519 COMPAT_SHMLBA);
87520 if (err < 0)
87521 return err;
87522- return put_user(raddr, (compat_ulong_t *)compat_ptr(third));
87523+ return put_user(raddr, (compat_ulong_t __user *)compat_ptr(third));
87524 }
87525 case SHMDT:
87526 return sys_shmdt(compat_ptr(ptr));
87527diff --git a/ipc/ipc_sysctl.c b/ipc/ipc_sysctl.c
87528index e8075b2..76f2c6a 100644
87529--- a/ipc/ipc_sysctl.c
87530+++ b/ipc/ipc_sysctl.c
87531@@ -30,7 +30,7 @@ static void *get_ipc(struct ctl_table *table)
87532 static int proc_ipc_dointvec(struct ctl_table *table, int write,
87533 void __user *buffer, size_t *lenp, loff_t *ppos)
87534 {
87535- struct ctl_table ipc_table;
87536+ ctl_table_no_const ipc_table;
87537
87538 memcpy(&ipc_table, table, sizeof(ipc_table));
87539 ipc_table.data = get_ipc(table);
87540@@ -41,7 +41,7 @@ static int proc_ipc_dointvec(struct ctl_table *table, int write,
87541 static int proc_ipc_dointvec_minmax(struct ctl_table *table, int write,
87542 void __user *buffer, size_t *lenp, loff_t *ppos)
87543 {
87544- struct ctl_table ipc_table;
87545+ ctl_table_no_const ipc_table;
87546
87547 memcpy(&ipc_table, table, sizeof(ipc_table));
87548 ipc_table.data = get_ipc(table);
87549@@ -65,7 +65,7 @@ static int proc_ipc_dointvec_minmax_orphans(struct ctl_table *table, int write,
87550 static int proc_ipc_callback_dointvec_minmax(struct ctl_table *table, int write,
87551 void __user *buffer, size_t *lenp, loff_t *ppos)
87552 {
87553- struct ctl_table ipc_table;
87554+ ctl_table_no_const ipc_table;
87555 size_t lenp_bef = *lenp;
87556 int rc;
87557
87558@@ -88,7 +88,7 @@ static int proc_ipc_callback_dointvec_minmax(struct ctl_table *table, int write,
87559 static int proc_ipc_doulongvec_minmax(struct ctl_table *table, int write,
87560 void __user *buffer, size_t *lenp, loff_t *ppos)
87561 {
87562- struct ctl_table ipc_table;
87563+ ctl_table_no_const ipc_table;
87564 memcpy(&ipc_table, table, sizeof(ipc_table));
87565 ipc_table.data = get_ipc(table);
87566
87567@@ -122,7 +122,7 @@ static void ipc_auto_callback(int val)
87568 static int proc_ipcauto_dointvec_minmax(struct ctl_table *table, int write,
87569 void __user *buffer, size_t *lenp, loff_t *ppos)
87570 {
87571- struct ctl_table ipc_table;
87572+ ctl_table_no_const ipc_table;
87573 int oldval;
87574 int rc;
87575
87576diff --git a/ipc/mq_sysctl.c b/ipc/mq_sysctl.c
87577index 68d4e95..1477ded 100644
87578--- a/ipc/mq_sysctl.c
87579+++ b/ipc/mq_sysctl.c
87580@@ -25,7 +25,7 @@ static void *get_mq(struct ctl_table *table)
87581 static int proc_mq_dointvec(struct ctl_table *table, int write,
87582 void __user *buffer, size_t *lenp, loff_t *ppos)
87583 {
87584- struct ctl_table mq_table;
87585+ ctl_table_no_const mq_table;
87586 memcpy(&mq_table, table, sizeof(mq_table));
87587 mq_table.data = get_mq(table);
87588
87589@@ -35,7 +35,7 @@ static int proc_mq_dointvec(struct ctl_table *table, int write,
87590 static int proc_mq_dointvec_minmax(struct ctl_table *table, int write,
87591 void __user *buffer, size_t *lenp, loff_t *ppos)
87592 {
87593- struct ctl_table mq_table;
87594+ ctl_table_no_const mq_table;
87595 memcpy(&mq_table, table, sizeof(mq_table));
87596 mq_table.data = get_mq(table);
87597
87598diff --git a/ipc/mqueue.c b/ipc/mqueue.c
87599index 4fcf39a..d3cc2ec 100644
87600--- a/ipc/mqueue.c
87601+++ b/ipc/mqueue.c
87602@@ -278,6 +278,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
87603 mq_bytes = mq_treesize + (info->attr.mq_maxmsg *
87604 info->attr.mq_msgsize);
87605
87606+ gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
87607 spin_lock(&mq_lock);
87608 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
87609 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
87610diff --git a/ipc/shm.c b/ipc/shm.c
87611index 0145479..3d27947 100644
87612--- a/ipc/shm.c
87613+++ b/ipc/shm.c
87614@@ -72,6 +72,14 @@ static void shm_destroy(struct ipc_namespace *ns, struct shmid_kernel *shp);
87615 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
87616 #endif
87617
87618+#ifdef CONFIG_GRKERNSEC
87619+extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
87620+ const u64 shm_createtime, const kuid_t cuid,
87621+ const int shmid);
87622+extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
87623+ const u64 shm_createtime);
87624+#endif
87625+
87626 void shm_init_ns(struct ipc_namespace *ns)
87627 {
87628 ns->shm_ctlmax = SHMMAX;
87629@@ -559,6 +567,9 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
87630 shp->shm_lprid = 0;
87631 shp->shm_atim = shp->shm_dtim = 0;
87632 shp->shm_ctim = get_seconds();
87633+#ifdef CONFIG_GRKERNSEC
87634+ shp->shm_createtime = ktime_get_ns();
87635+#endif
87636 shp->shm_segsz = size;
87637 shp->shm_nattch = 0;
87638 shp->shm_file = file;
87639@@ -1095,6 +1106,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
87640 f_mode = FMODE_READ | FMODE_WRITE;
87641 }
87642 if (shmflg & SHM_EXEC) {
87643+
87644+#ifdef CONFIG_PAX_MPROTECT
87645+ if (current->mm->pax_flags & MF_PAX_MPROTECT)
87646+ goto out;
87647+#endif
87648+
87649 prot |= PROT_EXEC;
87650 acc_mode |= S_IXUGO;
87651 }
87652@@ -1119,6 +1136,15 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
87653 if (err)
87654 goto out_unlock;
87655
87656+#ifdef CONFIG_GRKERNSEC
87657+ if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
87658+ shp->shm_perm.cuid, shmid) ||
87659+ !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
87660+ err = -EACCES;
87661+ goto out_unlock;
87662+ }
87663+#endif
87664+
87665 ipc_lock_object(&shp->shm_perm);
87666
87667 /* check if shm_destroy() is tearing down shp */
87668@@ -1131,6 +1157,9 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
87669 path = shp->shm_file->f_path;
87670 path_get(&path);
87671 shp->shm_nattch++;
87672+#ifdef CONFIG_GRKERNSEC
87673+ shp->shm_lapid = current->pid;
87674+#endif
87675 size = i_size_read(path.dentry->d_inode);
87676 ipc_unlock_object(&shp->shm_perm);
87677 rcu_read_unlock();
87678diff --git a/ipc/util.c b/ipc/util.c
87679index 88adc32..3867c68 100644
87680--- a/ipc/util.c
87681+++ b/ipc/util.c
87682@@ -71,6 +71,8 @@ struct ipc_proc_iface {
87683 int (*show)(struct seq_file *, void *);
87684 };
87685
87686+extern int gr_ipc_permitted(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, int requested_mode, int granted_mode);
87687+
87688 static void ipc_memory_notifier(struct work_struct *work)
87689 {
87690 ipcns_notify(IPCNS_MEMCHANGED);
87691@@ -537,6 +539,10 @@ int ipcperms(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, short flag)
87692 granted_mode >>= 6;
87693 else if (in_group_p(ipcp->cgid) || in_group_p(ipcp->gid))
87694 granted_mode >>= 3;
87695+
87696+ if (!gr_ipc_permitted(ns, ipcp, requested_mode, granted_mode))
87697+ return -1;
87698+
87699 /* is there some bit set in requested_mode but not in granted_mode? */
87700 if ((requested_mode & ~granted_mode & 0007) &&
87701 !ns_capable(ns->user_ns, CAP_IPC_OWNER))
87702diff --git a/kernel/audit.c b/kernel/audit.c
87703index c6df990..fde80b4 100644
87704--- a/kernel/audit.c
87705+++ b/kernel/audit.c
87706@@ -122,7 +122,7 @@ u32 audit_sig_sid = 0;
87707 3) suppressed due to audit_rate_limit
87708 4) suppressed due to audit_backlog_limit
87709 */
87710-static atomic_t audit_lost = ATOMIC_INIT(0);
87711+static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
87712
87713 /* The netlink socket. */
87714 static struct sock *audit_sock;
87715@@ -256,7 +256,7 @@ void audit_log_lost(const char *message)
87716 unsigned long now;
87717 int print;
87718
87719- atomic_inc(&audit_lost);
87720+ atomic_inc_unchecked(&audit_lost);
87721
87722 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
87723
87724@@ -273,7 +273,7 @@ void audit_log_lost(const char *message)
87725 if (print) {
87726 if (printk_ratelimit())
87727 pr_warn("audit_lost=%u audit_rate_limit=%u audit_backlog_limit=%u\n",
87728- atomic_read(&audit_lost),
87729+ atomic_read_unchecked(&audit_lost),
87730 audit_rate_limit,
87731 audit_backlog_limit);
87732 audit_panic(message);
87733@@ -840,7 +840,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
87734 s.pid = audit_pid;
87735 s.rate_limit = audit_rate_limit;
87736 s.backlog_limit = audit_backlog_limit;
87737- s.lost = atomic_read(&audit_lost);
87738+ s.lost = atomic_read_unchecked(&audit_lost);
87739 s.backlog = skb_queue_len(&audit_skb_queue);
87740 s.version = AUDIT_VERSION_LATEST;
87741 s.backlog_wait_time = audit_backlog_wait_time;
87742diff --git a/kernel/auditsc.c b/kernel/auditsc.c
87743index e420a0c..38137fa 100644
87744--- a/kernel/auditsc.c
87745+++ b/kernel/auditsc.c
87746@@ -2014,7 +2014,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
87747 }
87748
87749 /* global counter which is incremented every time something logs in */
87750-static atomic_t session_id = ATOMIC_INIT(0);
87751+static atomic_unchecked_t session_id = ATOMIC_INIT(0);
87752
87753 static int audit_set_loginuid_perm(kuid_t loginuid)
87754 {
87755@@ -2081,7 +2081,7 @@ int audit_set_loginuid(kuid_t loginuid)
87756
87757 /* are we setting or clearing? */
87758 if (uid_valid(loginuid))
87759- sessionid = (unsigned int)atomic_inc_return(&session_id);
87760+ sessionid = (unsigned int)atomic_inc_return_unchecked(&session_id);
87761
87762 task->sessionid = sessionid;
87763 task->loginuid = loginuid;
87764diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c
87765index d6594e4..597264b 100644
87766--- a/kernel/bpf/core.c
87767+++ b/kernel/bpf/core.c
87768@@ -143,14 +143,17 @@ bpf_jit_binary_alloc(unsigned int proglen, u8 **image_ptr,
87769 * random section of illegal instructions.
87770 */
87771 size = round_up(proglen + sizeof(*hdr) + 128, PAGE_SIZE);
87772- hdr = module_alloc(size);
87773+ hdr = module_alloc_exec(size);
87774 if (hdr == NULL)
87775 return NULL;
87776
87777 /* Fill space with illegal/arch-dep instructions. */
87778 bpf_fill_ill_insns(hdr, size);
87779
87780+ pax_open_kernel();
87781 hdr->pages = size / PAGE_SIZE;
87782+ pax_close_kernel();
87783+
87784 hole = min_t(unsigned int, size - (proglen + sizeof(*hdr)),
87785 PAGE_SIZE - sizeof(*hdr));
87786 start = (prandom_u32() % hole) & ~(alignment - 1);
87787@@ -163,7 +166,7 @@ bpf_jit_binary_alloc(unsigned int proglen, u8 **image_ptr,
87788
87789 void bpf_jit_binary_free(struct bpf_binary_header *hdr)
87790 {
87791- module_free(NULL, hdr);
87792+ module_free_exec(NULL, hdr);
87793 }
87794 #endif /* CONFIG_BPF_JIT */
87795
87796diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
87797index ba61c8c..c60c486 100644
87798--- a/kernel/bpf/syscall.c
87799+++ b/kernel/bpf/syscall.c
87800@@ -539,11 +539,15 @@ SYSCALL_DEFINE3(bpf, int, cmd, union bpf_attr __user *, uattr, unsigned int, siz
87801 int err;
87802
87803 /* the syscall is limited to root temporarily. This restriction will be
87804- * lifted when security audit is clean. Note that eBPF+tracing must have
87805- * this restriction, since it may pass kernel data to user space
87806+ * lifted by upstream when a half-assed security audit is clean. Note
87807+ * that eBPF+tracing must have this restriction, since it may pass
87808+ * kernel data to user space
87809 */
87810 if (!capable(CAP_SYS_ADMIN))
87811 return -EPERM;
87812+#ifdef CONFIG_GRKERNSEC
87813+ return -EPERM;
87814+#endif
87815
87816 if (!access_ok(VERIFY_READ, uattr, 1))
87817 return -EFAULT;
87818diff --git a/kernel/capability.c b/kernel/capability.c
87819index 989f5bf..d317ca0 100644
87820--- a/kernel/capability.c
87821+++ b/kernel/capability.c
87822@@ -192,6 +192,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
87823 * before modification is attempted and the application
87824 * fails.
87825 */
87826+ if (tocopy > ARRAY_SIZE(kdata))
87827+ return -EFAULT;
87828+
87829 if (copy_to_user(dataptr, kdata, tocopy
87830 * sizeof(struct __user_cap_data_struct))) {
87831 return -EFAULT;
87832@@ -297,10 +300,11 @@ bool has_ns_capability(struct task_struct *t,
87833 int ret;
87834
87835 rcu_read_lock();
87836- ret = security_capable(__task_cred(t), ns, cap);
87837+ ret = security_capable(__task_cred(t), ns, cap) == 0 &&
87838+ gr_task_is_capable(t, __task_cred(t), cap);
87839 rcu_read_unlock();
87840
87841- return (ret == 0);
87842+ return ret;
87843 }
87844
87845 /**
87846@@ -337,10 +341,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
87847 int ret;
87848
87849 rcu_read_lock();
87850- ret = security_capable_noaudit(__task_cred(t), ns, cap);
87851+ ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
87852 rcu_read_unlock();
87853
87854- return (ret == 0);
87855+ return ret;
87856 }
87857
87858 /**
87859@@ -378,7 +382,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
87860 BUG();
87861 }
87862
87863- if (security_capable(current_cred(), ns, cap) == 0) {
87864+ if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
87865 current->flags |= PF_SUPERPRIV;
87866 return true;
87867 }
87868@@ -386,6 +390,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
87869 }
87870 EXPORT_SYMBOL(ns_capable);
87871
87872+bool ns_capable_nolog(struct user_namespace *ns, int cap)
87873+{
87874+ if (unlikely(!cap_valid(cap))) {
87875+ printk(KERN_CRIT "capable_nolog() called with invalid cap=%u\n", cap);
87876+ BUG();
87877+ }
87878+
87879+ if (security_capable_noaudit(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
87880+ current->flags |= PF_SUPERPRIV;
87881+ return true;
87882+ }
87883+ return false;
87884+}
87885+EXPORT_SYMBOL(ns_capable_nolog);
87886+
87887 /**
87888 * file_ns_capable - Determine if the file's opener had a capability in effect
87889 * @file: The file we want to check
87890@@ -427,6 +446,12 @@ bool capable(int cap)
87891 }
87892 EXPORT_SYMBOL(capable);
87893
87894+bool capable_nolog(int cap)
87895+{
87896+ return ns_capable_nolog(&init_user_ns, cap);
87897+}
87898+EXPORT_SYMBOL(capable_nolog);
87899+
87900 /**
87901 * capable_wrt_inode_uidgid - Check nsown_capable and uid and gid mapped
87902 * @inode: The inode in question
87903@@ -444,3 +469,12 @@ bool capable_wrt_inode_uidgid(const struct inode *inode, int cap)
87904 kgid_has_mapping(ns, inode->i_gid);
87905 }
87906 EXPORT_SYMBOL(capable_wrt_inode_uidgid);
87907+
87908+bool capable_wrt_inode_uidgid_nolog(const struct inode *inode, int cap)
87909+{
87910+ struct user_namespace *ns = current_user_ns();
87911+
87912+ return ns_capable_nolog(ns, cap) && kuid_has_mapping(ns, inode->i_uid) &&
87913+ kgid_has_mapping(ns, inode->i_gid);
87914+}
87915+EXPORT_SYMBOL(capable_wrt_inode_uidgid_nolog);
87916diff --git a/kernel/cgroup.c b/kernel/cgroup.c
87917index 136ecea..45157a6 100644
87918--- a/kernel/cgroup.c
87919+++ b/kernel/cgroup.c
87920@@ -5276,6 +5276,9 @@ static void cgroup_release_agent(struct work_struct *work)
87921 if (!pathbuf || !agentbuf)
87922 goto out;
87923
87924+ if (agentbuf[0] == '\0')
87925+ goto out;
87926+
87927 path = cgroup_path(cgrp, pathbuf, PATH_MAX);
87928 if (!path)
87929 goto out;
87930@@ -5461,7 +5464,7 @@ static int cgroup_css_links_read(struct seq_file *seq, void *v)
87931 struct task_struct *task;
87932 int count = 0;
87933
87934- seq_printf(seq, "css_set %p\n", cset);
87935+ seq_printf(seq, "css_set %pK\n", cset);
87936
87937 list_for_each_entry(task, &cset->tasks, cg_list) {
87938 if (count++ > MAX_TASKS_SHOWN_PER_CSS)
87939diff --git a/kernel/compat.c b/kernel/compat.c
87940index ebb3c36..1df606e 100644
87941--- a/kernel/compat.c
87942+++ b/kernel/compat.c
87943@@ -13,6 +13,7 @@
87944
87945 #include <linux/linkage.h>
87946 #include <linux/compat.h>
87947+#include <linux/module.h>
87948 #include <linux/errno.h>
87949 #include <linux/time.h>
87950 #include <linux/signal.h>
87951@@ -220,7 +221,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
87952 mm_segment_t oldfs;
87953 long ret;
87954
87955- restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
87956+ restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
87957 oldfs = get_fs();
87958 set_fs(KERNEL_DS);
87959 ret = hrtimer_nanosleep_restart(restart);
87960@@ -252,7 +253,7 @@ COMPAT_SYSCALL_DEFINE2(nanosleep, struct compat_timespec __user *, rqtp,
87961 oldfs = get_fs();
87962 set_fs(KERNEL_DS);
87963 ret = hrtimer_nanosleep(&tu,
87964- rmtp ? (struct timespec __user *)&rmt : NULL,
87965+ rmtp ? (struct timespec __force_user *)&rmt : NULL,
87966 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
87967 set_fs(oldfs);
87968
87969@@ -379,7 +380,7 @@ COMPAT_SYSCALL_DEFINE1(sigpending, compat_old_sigset_t __user *, set)
87970 mm_segment_t old_fs = get_fs();
87971
87972 set_fs(KERNEL_DS);
87973- ret = sys_sigpending((old_sigset_t __user *) &s);
87974+ ret = sys_sigpending((old_sigset_t __force_user *) &s);
87975 set_fs(old_fs);
87976 if (ret == 0)
87977 ret = put_user(s, set);
87978@@ -469,7 +470,7 @@ COMPAT_SYSCALL_DEFINE2(old_getrlimit, unsigned int, resource,
87979 mm_segment_t old_fs = get_fs();
87980
87981 set_fs(KERNEL_DS);
87982- ret = sys_old_getrlimit(resource, (struct rlimit __user *)&r);
87983+ ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
87984 set_fs(old_fs);
87985
87986 if (!ret) {
87987@@ -551,8 +552,8 @@ COMPAT_SYSCALL_DEFINE4(wait4,
87988 set_fs (KERNEL_DS);
87989 ret = sys_wait4(pid,
87990 (stat_addr ?
87991- (unsigned int __user *) &status : NULL),
87992- options, (struct rusage __user *) &r);
87993+ (unsigned int __force_user *) &status : NULL),
87994+ options, (struct rusage __force_user *) &r);
87995 set_fs (old_fs);
87996
87997 if (ret > 0) {
87998@@ -578,8 +579,8 @@ COMPAT_SYSCALL_DEFINE5(waitid,
87999 memset(&info, 0, sizeof(info));
88000
88001 set_fs(KERNEL_DS);
88002- ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
88003- uru ? (struct rusage __user *)&ru : NULL);
88004+ ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
88005+ uru ? (struct rusage __force_user *)&ru : NULL);
88006 set_fs(old_fs);
88007
88008 if ((ret < 0) || (info.si_signo == 0))
88009@@ -713,8 +714,8 @@ COMPAT_SYSCALL_DEFINE4(timer_settime, timer_t, timer_id, int, flags,
88010 oldfs = get_fs();
88011 set_fs(KERNEL_DS);
88012 err = sys_timer_settime(timer_id, flags,
88013- (struct itimerspec __user *) &newts,
88014- (struct itimerspec __user *) &oldts);
88015+ (struct itimerspec __force_user *) &newts,
88016+ (struct itimerspec __force_user *) &oldts);
88017 set_fs(oldfs);
88018 if (!err && old && put_compat_itimerspec(old, &oldts))
88019 return -EFAULT;
88020@@ -731,7 +732,7 @@ COMPAT_SYSCALL_DEFINE2(timer_gettime, timer_t, timer_id,
88021 oldfs = get_fs();
88022 set_fs(KERNEL_DS);
88023 err = sys_timer_gettime(timer_id,
88024- (struct itimerspec __user *) &ts);
88025+ (struct itimerspec __force_user *) &ts);
88026 set_fs(oldfs);
88027 if (!err && put_compat_itimerspec(setting, &ts))
88028 return -EFAULT;
88029@@ -750,7 +751,7 @@ COMPAT_SYSCALL_DEFINE2(clock_settime, clockid_t, which_clock,
88030 oldfs = get_fs();
88031 set_fs(KERNEL_DS);
88032 err = sys_clock_settime(which_clock,
88033- (struct timespec __user *) &ts);
88034+ (struct timespec __force_user *) &ts);
88035 set_fs(oldfs);
88036 return err;
88037 }
88038@@ -765,7 +766,7 @@ COMPAT_SYSCALL_DEFINE2(clock_gettime, clockid_t, which_clock,
88039 oldfs = get_fs();
88040 set_fs(KERNEL_DS);
88041 err = sys_clock_gettime(which_clock,
88042- (struct timespec __user *) &ts);
88043+ (struct timespec __force_user *) &ts);
88044 set_fs(oldfs);
88045 if (!err && compat_put_timespec(&ts, tp))
88046 return -EFAULT;
88047@@ -785,7 +786,7 @@ COMPAT_SYSCALL_DEFINE2(clock_adjtime, clockid_t, which_clock,
88048
88049 oldfs = get_fs();
88050 set_fs(KERNEL_DS);
88051- ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
88052+ ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
88053 set_fs(oldfs);
88054
88055 err = compat_put_timex(utp, &txc);
88056@@ -805,7 +806,7 @@ COMPAT_SYSCALL_DEFINE2(clock_getres, clockid_t, which_clock,
88057 oldfs = get_fs();
88058 set_fs(KERNEL_DS);
88059 err = sys_clock_getres(which_clock,
88060- (struct timespec __user *) &ts);
88061+ (struct timespec __force_user *) &ts);
88062 set_fs(oldfs);
88063 if (!err && tp && compat_put_timespec(&ts, tp))
88064 return -EFAULT;
88065@@ -819,7 +820,7 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
88066 struct timespec tu;
88067 struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
88068
88069- restart->nanosleep.rmtp = (struct timespec __user *) &tu;
88070+ restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
88071 oldfs = get_fs();
88072 set_fs(KERNEL_DS);
88073 err = clock_nanosleep_restart(restart);
88074@@ -851,8 +852,8 @@ COMPAT_SYSCALL_DEFINE4(clock_nanosleep, clockid_t, which_clock, int, flags,
88075 oldfs = get_fs();
88076 set_fs(KERNEL_DS);
88077 err = sys_clock_nanosleep(which_clock, flags,
88078- (struct timespec __user *) &in,
88079- (struct timespec __user *) &out);
88080+ (struct timespec __force_user *) &in,
88081+ (struct timespec __force_user *) &out);
88082 set_fs(oldfs);
88083
88084 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
88085@@ -1146,7 +1147,7 @@ COMPAT_SYSCALL_DEFINE2(sched_rr_get_interval,
88086 mm_segment_t old_fs = get_fs();
88087
88088 set_fs(KERNEL_DS);
88089- ret = sys_sched_rr_get_interval(pid, (struct timespec __user *)&t);
88090+ ret = sys_sched_rr_get_interval(pid, (struct timespec __force_user *)&t);
88091 set_fs(old_fs);
88092 if (compat_put_timespec(&t, interval))
88093 return -EFAULT;
88094diff --git a/kernel/configs.c b/kernel/configs.c
88095index c18b1f1..b9a0132 100644
88096--- a/kernel/configs.c
88097+++ b/kernel/configs.c
88098@@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
88099 struct proc_dir_entry *entry;
88100
88101 /* create the current config file */
88102+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
88103+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
88104+ entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
88105+ &ikconfig_file_ops);
88106+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
88107+ entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
88108+ &ikconfig_file_ops);
88109+#endif
88110+#else
88111 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
88112 &ikconfig_file_ops);
88113+#endif
88114+
88115 if (!entry)
88116 return -ENOMEM;
88117
88118diff --git a/kernel/cred.c b/kernel/cred.c
88119index e0573a4..26c0fd3 100644
88120--- a/kernel/cred.c
88121+++ b/kernel/cred.c
88122@@ -164,6 +164,16 @@ void exit_creds(struct task_struct *tsk)
88123 validate_creds(cred);
88124 alter_cred_subscribers(cred, -1);
88125 put_cred(cred);
88126+
88127+#ifdef CONFIG_GRKERNSEC_SETXID
88128+ cred = (struct cred *) tsk->delayed_cred;
88129+ if (cred != NULL) {
88130+ tsk->delayed_cred = NULL;
88131+ validate_creds(cred);
88132+ alter_cred_subscribers(cred, -1);
88133+ put_cred(cred);
88134+ }
88135+#endif
88136 }
88137
88138 /**
88139@@ -411,7 +421,7 @@ static bool cred_cap_issubset(const struct cred *set, const struct cred *subset)
88140 * Always returns 0 thus allowing this function to be tail-called at the end
88141 * of, say, sys_setgid().
88142 */
88143-int commit_creds(struct cred *new)
88144+static int __commit_creds(struct cred *new)
88145 {
88146 struct task_struct *task = current;
88147 const struct cred *old = task->real_cred;
88148@@ -430,6 +440,8 @@ int commit_creds(struct cred *new)
88149
88150 get_cred(new); /* we will require a ref for the subj creds too */
88151
88152+ gr_set_role_label(task, new->uid, new->gid);
88153+
88154 /* dumpability changes */
88155 if (!uid_eq(old->euid, new->euid) ||
88156 !gid_eq(old->egid, new->egid) ||
88157@@ -479,6 +491,105 @@ int commit_creds(struct cred *new)
88158 put_cred(old);
88159 return 0;
88160 }
88161+#ifdef CONFIG_GRKERNSEC_SETXID
88162+extern int set_user(struct cred *new);
88163+
88164+void gr_delayed_cred_worker(void)
88165+{
88166+ const struct cred *new = current->delayed_cred;
88167+ struct cred *ncred;
88168+
88169+ current->delayed_cred = NULL;
88170+
88171+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID) && new != NULL) {
88172+ // from doing get_cred on it when queueing this
88173+ put_cred(new);
88174+ return;
88175+ } else if (new == NULL)
88176+ return;
88177+
88178+ ncred = prepare_creds();
88179+ if (!ncred)
88180+ goto die;
88181+ // uids
88182+ ncred->uid = new->uid;
88183+ ncred->euid = new->euid;
88184+ ncred->suid = new->suid;
88185+ ncred->fsuid = new->fsuid;
88186+ // gids
88187+ ncred->gid = new->gid;
88188+ ncred->egid = new->egid;
88189+ ncred->sgid = new->sgid;
88190+ ncred->fsgid = new->fsgid;
88191+ // groups
88192+ set_groups(ncred, new->group_info);
88193+ // caps
88194+ ncred->securebits = new->securebits;
88195+ ncred->cap_inheritable = new->cap_inheritable;
88196+ ncred->cap_permitted = new->cap_permitted;
88197+ ncred->cap_effective = new->cap_effective;
88198+ ncred->cap_bset = new->cap_bset;
88199+
88200+ if (set_user(ncred)) {
88201+ abort_creds(ncred);
88202+ goto die;
88203+ }
88204+
88205+ // from doing get_cred on it when queueing this
88206+ put_cred(new);
88207+
88208+ __commit_creds(ncred);
88209+ return;
88210+die:
88211+ // from doing get_cred on it when queueing this
88212+ put_cred(new);
88213+ do_group_exit(SIGKILL);
88214+}
88215+#endif
88216+
88217+int commit_creds(struct cred *new)
88218+{
88219+#ifdef CONFIG_GRKERNSEC_SETXID
88220+ int ret;
88221+ int schedule_it = 0;
88222+ struct task_struct *t;
88223+ unsigned oldsecurebits = current_cred()->securebits;
88224+
88225+ /* we won't get called with tasklist_lock held for writing
88226+ and interrupts disabled as the cred struct in that case is
88227+ init_cred
88228+ */
88229+ if (grsec_enable_setxid && !current_is_single_threaded() &&
88230+ uid_eq(current_uid(), GLOBAL_ROOT_UID) &&
88231+ !uid_eq(new->uid, GLOBAL_ROOT_UID)) {
88232+ schedule_it = 1;
88233+ }
88234+ ret = __commit_creds(new);
88235+ if (schedule_it) {
88236+ rcu_read_lock();
88237+ read_lock(&tasklist_lock);
88238+ for (t = next_thread(current); t != current;
88239+ t = next_thread(t)) {
88240+ /* we'll check if the thread has uid 0 in
88241+ * the delayed worker routine
88242+ */
88243+ if (task_securebits(t) == oldsecurebits &&
88244+ t->delayed_cred == NULL) {
88245+ t->delayed_cred = get_cred(new);
88246+ set_tsk_thread_flag(t, TIF_GRSEC_SETXID);
88247+ set_tsk_need_resched(t);
88248+ }
88249+ }
88250+ read_unlock(&tasklist_lock);
88251+ rcu_read_unlock();
88252+ }
88253+
88254+ return ret;
88255+#else
88256+ return __commit_creds(new);
88257+#endif
88258+}
88259+
88260 EXPORT_SYMBOL(commit_creds);
88261
88262 /**
88263diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
88264index 1adf62b..7736e06 100644
88265--- a/kernel/debug/debug_core.c
88266+++ b/kernel/debug/debug_core.c
88267@@ -124,7 +124,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
88268 */
88269 static atomic_t masters_in_kgdb;
88270 static atomic_t slaves_in_kgdb;
88271-static atomic_t kgdb_break_tasklet_var;
88272+static atomic_unchecked_t kgdb_break_tasklet_var;
88273 atomic_t kgdb_setting_breakpoint;
88274
88275 struct task_struct *kgdb_usethread;
88276@@ -134,7 +134,7 @@ int kgdb_single_step;
88277 static pid_t kgdb_sstep_pid;
88278
88279 /* to keep track of the CPU which is doing the single stepping*/
88280-atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
88281+atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
88282
88283 /*
88284 * If you are debugging a problem where roundup (the collection of
88285@@ -549,7 +549,7 @@ return_normal:
88286 * kernel will only try for the value of sstep_tries before
88287 * giving up and continuing on.
88288 */
88289- if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
88290+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
88291 (kgdb_info[cpu].task &&
88292 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
88293 atomic_set(&kgdb_active, -1);
88294@@ -647,8 +647,8 @@ cpu_master_loop:
88295 }
88296
88297 kgdb_restore:
88298- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
88299- int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
88300+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
88301+ int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
88302 if (kgdb_info[sstep_cpu].task)
88303 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
88304 else
88305@@ -925,18 +925,18 @@ static void kgdb_unregister_callbacks(void)
88306 static void kgdb_tasklet_bpt(unsigned long ing)
88307 {
88308 kgdb_breakpoint();
88309- atomic_set(&kgdb_break_tasklet_var, 0);
88310+ atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
88311 }
88312
88313 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
88314
88315 void kgdb_schedule_breakpoint(void)
88316 {
88317- if (atomic_read(&kgdb_break_tasklet_var) ||
88318+ if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
88319 atomic_read(&kgdb_active) != -1 ||
88320 atomic_read(&kgdb_setting_breakpoint))
88321 return;
88322- atomic_inc(&kgdb_break_tasklet_var);
88323+ atomic_inc_unchecked(&kgdb_break_tasklet_var);
88324 tasklet_schedule(&kgdb_tasklet_breakpoint);
88325 }
88326 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
88327diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
88328index 379650b..30c5180 100644
88329--- a/kernel/debug/kdb/kdb_main.c
88330+++ b/kernel/debug/kdb/kdb_main.c
88331@@ -1977,7 +1977,7 @@ static int kdb_lsmod(int argc, const char **argv)
88332 continue;
88333
88334 kdb_printf("%-20s%8u 0x%p ", mod->name,
88335- mod->core_size, (void *)mod);
88336+ mod->core_size_rx + mod->core_size_rw, (void *)mod);
88337 #ifdef CONFIG_MODULE_UNLOAD
88338 kdb_printf("%4ld ", module_refcount(mod));
88339 #endif
88340@@ -1987,7 +1987,7 @@ static int kdb_lsmod(int argc, const char **argv)
88341 kdb_printf(" (Loading)");
88342 else
88343 kdb_printf(" (Live)");
88344- kdb_printf(" 0x%p", mod->module_core);
88345+ kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
88346
88347 #ifdef CONFIG_MODULE_UNLOAD
88348 {
88349diff --git a/kernel/events/core.c b/kernel/events/core.c
88350index 2ab0238..bf89262f5 100644
88351--- a/kernel/events/core.c
88352+++ b/kernel/events/core.c
88353@@ -170,8 +170,15 @@ static struct srcu_struct pmus_srcu;
88354 * 0 - disallow raw tracepoint access for unpriv
88355 * 1 - disallow cpu events for unpriv
88356 * 2 - disallow kernel profiling for unpriv
88357+ * 3 - disallow all unpriv perf event use
88358 */
88359-int sysctl_perf_event_paranoid __read_mostly = 1;
88360+#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
88361+int sysctl_perf_event_legitimately_concerned __read_mostly = 3;
88362+#elif defined(CONFIG_GRKERNSEC_HIDESYM)
88363+int sysctl_perf_event_legitimately_concerned __read_mostly = 2;
88364+#else
88365+int sysctl_perf_event_legitimately_concerned __read_mostly = 1;
88366+#endif
88367
88368 /* Minimum for 512 kiB + 1 user control page */
88369 int sysctl_perf_event_mlock __read_mostly = 512 + (PAGE_SIZE / 1024); /* 'free' kiB per user */
88370@@ -197,7 +204,7 @@ void update_perf_cpu_limits(void)
88371
88372 tmp *= sysctl_perf_cpu_time_max_percent;
88373 do_div(tmp, 100);
88374- ACCESS_ONCE(perf_sample_allowed_ns) = tmp;
88375+ ACCESS_ONCE_RW(perf_sample_allowed_ns) = tmp;
88376 }
88377
88378 static int perf_rotate_context(struct perf_cpu_context *cpuctx);
88379@@ -303,7 +310,7 @@ void perf_sample_event_took(u64 sample_len_ns)
88380 }
88381 }
88382
88383-static atomic64_t perf_event_id;
88384+static atomic64_unchecked_t perf_event_id;
88385
88386 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
88387 enum event_type_t event_type);
88388@@ -3102,7 +3109,7 @@ static void __perf_event_read(void *info)
88389
88390 static inline u64 perf_event_count(struct perf_event *event)
88391 {
88392- return local64_read(&event->count) + atomic64_read(&event->child_count);
88393+ return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
88394 }
88395
88396 static u64 perf_event_read(struct perf_event *event)
88397@@ -3528,9 +3535,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
88398 mutex_lock(&event->child_mutex);
88399 total += perf_event_read(event);
88400 *enabled += event->total_time_enabled +
88401- atomic64_read(&event->child_total_time_enabled);
88402+ atomic64_read_unchecked(&event->child_total_time_enabled);
88403 *running += event->total_time_running +
88404- atomic64_read(&event->child_total_time_running);
88405+ atomic64_read_unchecked(&event->child_total_time_running);
88406
88407 list_for_each_entry(child, &event->child_list, child_list) {
88408 total += perf_event_read(child);
88409@@ -3994,10 +4001,10 @@ void perf_event_update_userpage(struct perf_event *event)
88410 userpg->offset -= local64_read(&event->hw.prev_count);
88411
88412 userpg->time_enabled = enabled +
88413- atomic64_read(&event->child_total_time_enabled);
88414+ atomic64_read_unchecked(&event->child_total_time_enabled);
88415
88416 userpg->time_running = running +
88417- atomic64_read(&event->child_total_time_running);
88418+ atomic64_read_unchecked(&event->child_total_time_running);
88419
88420 arch_perf_update_userpage(userpg, now);
88421
88422@@ -4561,7 +4568,7 @@ perf_output_sample_ustack(struct perf_output_handle *handle, u64 dump_size,
88423
88424 /* Data. */
88425 sp = perf_user_stack_pointer(regs);
88426- rem = __output_copy_user(handle, (void *) sp, dump_size);
88427+ rem = __output_copy_user(handle, (void __user *) sp, dump_size);
88428 dyn_size = dump_size - rem;
88429
88430 perf_output_skip(handle, rem);
88431@@ -4652,11 +4659,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
88432 values[n++] = perf_event_count(event);
88433 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
88434 values[n++] = enabled +
88435- atomic64_read(&event->child_total_time_enabled);
88436+ atomic64_read_unchecked(&event->child_total_time_enabled);
88437 }
88438 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
88439 values[n++] = running +
88440- atomic64_read(&event->child_total_time_running);
88441+ atomic64_read_unchecked(&event->child_total_time_running);
88442 }
88443 if (read_format & PERF_FORMAT_ID)
88444 values[n++] = primary_event_id(event);
88445@@ -6958,7 +6965,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
88446 event->parent = parent_event;
88447
88448 event->ns = get_pid_ns(task_active_pid_ns(current));
88449- event->id = atomic64_inc_return(&perf_event_id);
88450+ event->id = atomic64_inc_return_unchecked(&perf_event_id);
88451
88452 event->state = PERF_EVENT_STATE_INACTIVE;
88453
88454@@ -7237,6 +7244,11 @@ SYSCALL_DEFINE5(perf_event_open,
88455 if (flags & ~PERF_FLAG_ALL)
88456 return -EINVAL;
88457
88458+#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
88459+ if (perf_paranoid_any() && !capable(CAP_SYS_ADMIN))
88460+ return -EACCES;
88461+#endif
88462+
88463 err = perf_copy_attr(attr_uptr, &attr);
88464 if (err)
88465 return err;
88466@@ -7592,10 +7604,10 @@ static void sync_child_event(struct perf_event *child_event,
88467 /*
88468 * Add back the child's count to the parent's count:
88469 */
88470- atomic64_add(child_val, &parent_event->child_count);
88471- atomic64_add(child_event->total_time_enabled,
88472+ atomic64_add_unchecked(child_val, &parent_event->child_count);
88473+ atomic64_add_unchecked(child_event->total_time_enabled,
88474 &parent_event->child_total_time_enabled);
88475- atomic64_add(child_event->total_time_running,
88476+ atomic64_add_unchecked(child_event->total_time_running,
88477 &parent_event->child_total_time_running);
88478
88479 /*
88480diff --git a/kernel/events/internal.h b/kernel/events/internal.h
88481index 569b2187..19940d9 100644
88482--- a/kernel/events/internal.h
88483+++ b/kernel/events/internal.h
88484@@ -81,10 +81,10 @@ static inline unsigned long perf_data_size(struct ring_buffer *rb)
88485 return rb->nr_pages << (PAGE_SHIFT + page_order(rb));
88486 }
88487
88488-#define DEFINE_OUTPUT_COPY(func_name, memcpy_func) \
88489+#define DEFINE_OUTPUT_COPY(func_name, memcpy_func, user) \
88490 static inline unsigned long \
88491 func_name(struct perf_output_handle *handle, \
88492- const void *buf, unsigned long len) \
88493+ const void user *buf, unsigned long len) \
88494 { \
88495 unsigned long size, written; \
88496 \
88497@@ -117,7 +117,7 @@ memcpy_common(void *dst, const void *src, unsigned long n)
88498 return 0;
88499 }
88500
88501-DEFINE_OUTPUT_COPY(__output_copy, memcpy_common)
88502+DEFINE_OUTPUT_COPY(__output_copy, memcpy_common, )
88503
88504 static inline unsigned long
88505 memcpy_skip(void *dst, const void *src, unsigned long n)
88506@@ -125,7 +125,7 @@ memcpy_skip(void *dst, const void *src, unsigned long n)
88507 return 0;
88508 }
88509
88510-DEFINE_OUTPUT_COPY(__output_skip, memcpy_skip)
88511+DEFINE_OUTPUT_COPY(__output_skip, memcpy_skip, )
88512
88513 #ifndef arch_perf_out_copy_user
88514 #define arch_perf_out_copy_user arch_perf_out_copy_user
88515@@ -143,7 +143,7 @@ arch_perf_out_copy_user(void *dst, const void *src, unsigned long n)
88516 }
88517 #endif
88518
88519-DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user)
88520+DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user, __user)
88521
88522 /* Callchain handling */
88523 extern struct perf_callchain_entry *
88524diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
88525index ed8f2cd..fe8030c 100644
88526--- a/kernel/events/uprobes.c
88527+++ b/kernel/events/uprobes.c
88528@@ -1670,7 +1670,7 @@ static int is_trap_at_addr(struct mm_struct *mm, unsigned long vaddr)
88529 {
88530 struct page *page;
88531 uprobe_opcode_t opcode;
88532- int result;
88533+ long result;
88534
88535 pagefault_disable();
88536 result = __copy_from_user_inatomic(&opcode, (void __user*)vaddr,
88537diff --git a/kernel/exit.c b/kernel/exit.c
88538index 2116aac..d95df2a 100644
88539--- a/kernel/exit.c
88540+++ b/kernel/exit.c
88541@@ -174,6 +174,10 @@ void release_task(struct task_struct *p)
88542 struct task_struct *leader;
88543 int zap_leader;
88544 repeat:
88545+#ifdef CONFIG_NET
88546+ gr_del_task_from_ip_table(p);
88547+#endif
88548+
88549 /* don't need to get the RCU readlock here - the process is dead and
88550 * can't be modifying its own credentials. But shut RCU-lockdep up */
88551 rcu_read_lock();
88552@@ -670,6 +674,8 @@ void do_exit(long code)
88553 int group_dead;
88554 TASKS_RCU(int tasks_rcu_i);
88555
88556+ set_fs(USER_DS);
88557+
88558 profile_task_exit(tsk);
88559
88560 WARN_ON(blk_needs_flush_plug(tsk));
88561@@ -686,7 +692,6 @@ void do_exit(long code)
88562 * mm_release()->clear_child_tid() from writing to a user-controlled
88563 * kernel address.
88564 */
88565- set_fs(USER_DS);
88566
88567 ptrace_event(PTRACE_EVENT_EXIT, code);
88568
88569@@ -744,6 +749,9 @@ void do_exit(long code)
88570 tsk->exit_code = code;
88571 taskstats_exit(tsk, group_dead);
88572
88573+ gr_acl_handle_psacct(tsk, code);
88574+ gr_acl_handle_exit();
88575+
88576 exit_mm(tsk);
88577
88578 if (group_dead)
88579@@ -863,7 +871,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
88580 * Take down every thread in the group. This is called by fatal signals
88581 * as well as by sys_exit_group (below).
88582 */
88583-void
88584+__noreturn void
88585 do_group_exit(int exit_code)
88586 {
88587 struct signal_struct *sig = current->signal;
88588diff --git a/kernel/fork.c b/kernel/fork.c
88589index 9b7d746..5b898ab 100644
88590--- a/kernel/fork.c
88591+++ b/kernel/fork.c
88592@@ -183,6 +183,48 @@ void thread_info_cache_init(void)
88593 # endif
88594 #endif
88595
88596+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
88597+static inline struct thread_info *gr_alloc_thread_info_node(struct task_struct *tsk,
88598+ int node, void **lowmem_stack)
88599+{
88600+ struct page *pages[THREAD_SIZE / PAGE_SIZE];
88601+ void *ret = NULL;
88602+ unsigned int i;
88603+
88604+ *lowmem_stack = alloc_thread_info_node(tsk, node);
88605+ if (*lowmem_stack == NULL)
88606+ goto out;
88607+
88608+ for (i = 0; i < THREAD_SIZE / PAGE_SIZE; i++)
88609+ pages[i] = virt_to_page(*lowmem_stack + (i * PAGE_SIZE));
88610+
88611+ /* use VM_IOREMAP to gain THREAD_SIZE alignment */
88612+ ret = vmap(pages, THREAD_SIZE / PAGE_SIZE, VM_IOREMAP, PAGE_KERNEL);
88613+ if (ret == NULL) {
88614+ free_thread_info(*lowmem_stack);
88615+ *lowmem_stack = NULL;
88616+ }
88617+
88618+out:
88619+ return ret;
88620+}
88621+
88622+static inline void gr_free_thread_info(struct task_struct *tsk, struct thread_info *ti)
88623+{
88624+ unmap_process_stacks(tsk);
88625+}
88626+#else
88627+static inline struct thread_info *gr_alloc_thread_info_node(struct task_struct *tsk,
88628+ int node, void **lowmem_stack)
88629+{
88630+ return alloc_thread_info_node(tsk, node);
88631+}
88632+static inline void gr_free_thread_info(struct task_struct *tsk, struct thread_info *ti)
88633+{
88634+ free_thread_info(ti);
88635+}
88636+#endif
88637+
88638 /* SLAB cache for signal_struct structures (tsk->signal) */
88639 static struct kmem_cache *signal_cachep;
88640
88641@@ -201,18 +243,22 @@ struct kmem_cache *vm_area_cachep;
88642 /* SLAB cache for mm_struct structures (tsk->mm) */
88643 static struct kmem_cache *mm_cachep;
88644
88645-static void account_kernel_stack(struct thread_info *ti, int account)
88646+static void account_kernel_stack(struct task_struct *tsk, struct thread_info *ti, int account)
88647 {
88648+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
88649+ struct zone *zone = page_zone(virt_to_page(tsk->lowmem_stack));
88650+#else
88651 struct zone *zone = page_zone(virt_to_page(ti));
88652+#endif
88653
88654 mod_zone_page_state(zone, NR_KERNEL_STACK, account);
88655 }
88656
88657 void free_task(struct task_struct *tsk)
88658 {
88659- account_kernel_stack(tsk->stack, -1);
88660+ account_kernel_stack(tsk, tsk->stack, -1);
88661 arch_release_thread_info(tsk->stack);
88662- free_thread_info(tsk->stack);
88663+ gr_free_thread_info(tsk, tsk->stack);
88664 rt_mutex_debug_task_free(tsk);
88665 ftrace_graph_exit_task(tsk);
88666 put_seccomp_filter(tsk);
88667@@ -306,6 +352,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
88668 {
88669 struct task_struct *tsk;
88670 struct thread_info *ti;
88671+ void *lowmem_stack;
88672 int node = tsk_fork_get_node(orig);
88673 int err;
88674
88675@@ -313,7 +360,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
88676 if (!tsk)
88677 return NULL;
88678
88679- ti = alloc_thread_info_node(tsk, node);
88680+ ti = gr_alloc_thread_info_node(tsk, node, &lowmem_stack);
88681 if (!ti)
88682 goto free_tsk;
88683
88684@@ -322,6 +369,9 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
88685 goto free_ti;
88686
88687 tsk->stack = ti;
88688+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
88689+ tsk->lowmem_stack = lowmem_stack;
88690+#endif
88691 #ifdef CONFIG_SECCOMP
88692 /*
88693 * We must handle setting up seccomp filters once we're under
88694@@ -338,7 +388,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
88695 set_task_stack_end_magic(tsk);
88696
88697 #ifdef CONFIG_CC_STACKPROTECTOR
88698- tsk->stack_canary = get_random_int();
88699+ tsk->stack_canary = pax_get_random_long();
88700 #endif
88701
88702 /*
88703@@ -352,24 +402,92 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
88704 tsk->splice_pipe = NULL;
88705 tsk->task_frag.page = NULL;
88706
88707- account_kernel_stack(ti, 1);
88708+ account_kernel_stack(tsk, ti, 1);
88709
88710 return tsk;
88711
88712 free_ti:
88713- free_thread_info(ti);
88714+ gr_free_thread_info(tsk, ti);
88715 free_tsk:
88716 free_task_struct(tsk);
88717 return NULL;
88718 }
88719
88720 #ifdef CONFIG_MMU
88721-static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
88722+static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct mm_struct *oldmm, struct vm_area_struct *mpnt)
88723+{
88724+ struct vm_area_struct *tmp;
88725+ unsigned long charge;
88726+ struct file *file;
88727+ int retval;
88728+
88729+ charge = 0;
88730+ if (mpnt->vm_flags & VM_ACCOUNT) {
88731+ unsigned long len = vma_pages(mpnt);
88732+
88733+ if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
88734+ goto fail_nomem;
88735+ charge = len;
88736+ }
88737+ tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
88738+ if (!tmp)
88739+ goto fail_nomem;
88740+ *tmp = *mpnt;
88741+ tmp->vm_mm = mm;
88742+ INIT_LIST_HEAD(&tmp->anon_vma_chain);
88743+ retval = vma_dup_policy(mpnt, tmp);
88744+ if (retval)
88745+ goto fail_nomem_policy;
88746+ if (anon_vma_fork(tmp, mpnt))
88747+ goto fail_nomem_anon_vma_fork;
88748+ tmp->vm_flags &= ~VM_LOCKED;
88749+ tmp->vm_next = tmp->vm_prev = NULL;
88750+ tmp->vm_mirror = NULL;
88751+ file = tmp->vm_file;
88752+ if (file) {
88753+ struct inode *inode = file_inode(file);
88754+ struct address_space *mapping = file->f_mapping;
88755+
88756+ get_file(file);
88757+ if (tmp->vm_flags & VM_DENYWRITE)
88758+ atomic_dec(&inode->i_writecount);
88759+ mutex_lock(&mapping->i_mmap_mutex);
88760+ if (tmp->vm_flags & VM_SHARED)
88761+ atomic_inc(&mapping->i_mmap_writable);
88762+ flush_dcache_mmap_lock(mapping);
88763+ /* insert tmp into the share list, just after mpnt */
88764+ if (unlikely(tmp->vm_flags & VM_NONLINEAR))
88765+ vma_nonlinear_insert(tmp, &mapping->i_mmap_nonlinear);
88766+ else
88767+ vma_interval_tree_insert_after(tmp, mpnt, &mapping->i_mmap);
88768+ flush_dcache_mmap_unlock(mapping);
88769+ mutex_unlock(&mapping->i_mmap_mutex);
88770+ }
88771+
88772+ /*
88773+ * Clear hugetlb-related page reserves for children. This only
88774+ * affects MAP_PRIVATE mappings. Faults generated by the child
88775+ * are not guaranteed to succeed, even if read-only
88776+ */
88777+ if (is_vm_hugetlb_page(tmp))
88778+ reset_vma_resv_huge_pages(tmp);
88779+
88780+ return tmp;
88781+
88782+fail_nomem_anon_vma_fork:
88783+ mpol_put(vma_policy(tmp));
88784+fail_nomem_policy:
88785+ kmem_cache_free(vm_area_cachep, tmp);
88786+fail_nomem:
88787+ vm_unacct_memory(charge);
88788+ return NULL;
88789+}
88790+
88791+static __latent_entropy int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
88792 {
88793 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
88794 struct rb_node **rb_link, *rb_parent;
88795 int retval;
88796- unsigned long charge;
88797
88798 uprobe_start_dup_mmap();
88799 down_write(&oldmm->mmap_sem);
88800@@ -397,55 +515,15 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
88801
88802 prev = NULL;
88803 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
88804- struct file *file;
88805-
88806 if (mpnt->vm_flags & VM_DONTCOPY) {
88807 vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
88808 -vma_pages(mpnt));
88809 continue;
88810 }
88811- charge = 0;
88812- if (mpnt->vm_flags & VM_ACCOUNT) {
88813- unsigned long len = vma_pages(mpnt);
88814-
88815- if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
88816- goto fail_nomem;
88817- charge = len;
88818- }
88819- tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
88820- if (!tmp)
88821- goto fail_nomem;
88822- *tmp = *mpnt;
88823- INIT_LIST_HEAD(&tmp->anon_vma_chain);
88824- retval = vma_dup_policy(mpnt, tmp);
88825- if (retval)
88826- goto fail_nomem_policy;
88827- tmp->vm_mm = mm;
88828- if (anon_vma_fork(tmp, mpnt))
88829- goto fail_nomem_anon_vma_fork;
88830- tmp->vm_flags &= ~VM_LOCKED;
88831- tmp->vm_next = tmp->vm_prev = NULL;
88832- file = tmp->vm_file;
88833- if (file) {
88834- struct inode *inode = file_inode(file);
88835- struct address_space *mapping = file->f_mapping;
88836-
88837- get_file(file);
88838- if (tmp->vm_flags & VM_DENYWRITE)
88839- atomic_dec(&inode->i_writecount);
88840- mutex_lock(&mapping->i_mmap_mutex);
88841- if (tmp->vm_flags & VM_SHARED)
88842- atomic_inc(&mapping->i_mmap_writable);
88843- flush_dcache_mmap_lock(mapping);
88844- /* insert tmp into the share list, just after mpnt */
88845- if (unlikely(tmp->vm_flags & VM_NONLINEAR))
88846- vma_nonlinear_insert(tmp,
88847- &mapping->i_mmap_nonlinear);
88848- else
88849- vma_interval_tree_insert_after(tmp, mpnt,
88850- &mapping->i_mmap);
88851- flush_dcache_mmap_unlock(mapping);
88852- mutex_unlock(&mapping->i_mmap_mutex);
88853+ tmp = dup_vma(mm, oldmm, mpnt);
88854+ if (!tmp) {
88855+ retval = -ENOMEM;
88856+ goto out;
88857 }
88858
88859 /*
88860@@ -477,6 +555,31 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
88861 if (retval)
88862 goto out;
88863 }
88864+
88865+#ifdef CONFIG_PAX_SEGMEXEC
88866+ if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
88867+ struct vm_area_struct *mpnt_m;
88868+
88869+ for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
88870+ BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
88871+
88872+ if (!mpnt->vm_mirror)
88873+ continue;
88874+
88875+ if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
88876+ BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
88877+ mpnt->vm_mirror = mpnt_m;
88878+ } else {
88879+ BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
88880+ mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
88881+ mpnt_m->vm_mirror->vm_mirror = mpnt_m;
88882+ mpnt->vm_mirror->vm_mirror = mpnt;
88883+ }
88884+ }
88885+ BUG_ON(mpnt_m);
88886+ }
88887+#endif
88888+
88889 /* a new mm has just been created */
88890 arch_dup_mmap(oldmm, mm);
88891 retval = 0;
88892@@ -486,14 +589,6 @@ out:
88893 up_write(&oldmm->mmap_sem);
88894 uprobe_end_dup_mmap();
88895 return retval;
88896-fail_nomem_anon_vma_fork:
88897- mpol_put(vma_policy(tmp));
88898-fail_nomem_policy:
88899- kmem_cache_free(vm_area_cachep, tmp);
88900-fail_nomem:
88901- retval = -ENOMEM;
88902- vm_unacct_memory(charge);
88903- goto out;
88904 }
88905
88906 static inline int mm_alloc_pgd(struct mm_struct *mm)
88907@@ -734,8 +829,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
88908 return ERR_PTR(err);
88909
88910 mm = get_task_mm(task);
88911- if (mm && mm != current->mm &&
88912- !ptrace_may_access(task, mode)) {
88913+ if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
88914+ (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
88915 mmput(mm);
88916 mm = ERR_PTR(-EACCES);
88917 }
88918@@ -938,13 +1033,20 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
88919 spin_unlock(&fs->lock);
88920 return -EAGAIN;
88921 }
88922- fs->users++;
88923+ atomic_inc(&fs->users);
88924 spin_unlock(&fs->lock);
88925 return 0;
88926 }
88927 tsk->fs = copy_fs_struct(fs);
88928 if (!tsk->fs)
88929 return -ENOMEM;
88930+ /* Carry through gr_chroot_dentry and is_chrooted instead
88931+ of recomputing it here. Already copied when the task struct
88932+ is duplicated. This allows pivot_root to not be treated as
88933+ a chroot
88934+ */
88935+ //gr_set_chroot_entries(tsk, &tsk->fs->root);
88936+
88937 return 0;
88938 }
88939
88940@@ -1179,7 +1281,7 @@ init_task_pid(struct task_struct *task, enum pid_type type, struct pid *pid)
88941 * parts of the process environment (as per the clone
88942 * flags). The actual kick-off is left to the caller.
88943 */
88944-static struct task_struct *copy_process(unsigned long clone_flags,
88945+static __latent_entropy struct task_struct *copy_process(unsigned long clone_flags,
88946 unsigned long stack_start,
88947 unsigned long stack_size,
88948 int __user *child_tidptr,
88949@@ -1250,6 +1352,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
88950 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
88951 #endif
88952 retval = -EAGAIN;
88953+
88954+ gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
88955+
88956 if (atomic_read(&p->real_cred->user->processes) >=
88957 task_rlimit(p, RLIMIT_NPROC)) {
88958 if (p->real_cred->user != INIT_USER &&
88959@@ -1499,6 +1604,11 @@ static struct task_struct *copy_process(unsigned long clone_flags,
88960 goto bad_fork_free_pid;
88961 }
88962
88963+ /* synchronizes with gr_set_acls()
88964+ we need to call this past the point of no return for fork()
88965+ */
88966+ gr_copy_label(p);
88967+
88968 if (likely(p->pid)) {
88969 ptrace_init_task(p, (clone_flags & CLONE_PTRACE) || trace);
88970
88971@@ -1589,6 +1699,8 @@ bad_fork_cleanup_count:
88972 bad_fork_free:
88973 free_task(p);
88974 fork_out:
88975+ gr_log_forkfail(retval);
88976+
88977 return ERR_PTR(retval);
88978 }
88979
88980@@ -1650,6 +1762,7 @@ long do_fork(unsigned long clone_flags,
88981
88982 p = copy_process(clone_flags, stack_start, stack_size,
88983 child_tidptr, NULL, trace);
88984+ add_latent_entropy();
88985 /*
88986 * Do this prior waking up the new thread - the thread pointer
88987 * might get invalid after that point, if the thread exits quickly.
88988@@ -1666,6 +1779,8 @@ long do_fork(unsigned long clone_flags,
88989 if (clone_flags & CLONE_PARENT_SETTID)
88990 put_user(nr, parent_tidptr);
88991
88992+ gr_handle_brute_check();
88993+
88994 if (clone_flags & CLONE_VFORK) {
88995 p->vfork_done = &vfork;
88996 init_completion(&vfork);
88997@@ -1784,7 +1899,7 @@ void __init proc_caches_init(void)
88998 mm_cachep = kmem_cache_create("mm_struct",
88999 sizeof(struct mm_struct), ARCH_MIN_MMSTRUCT_ALIGN,
89000 SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_NOTRACK, NULL);
89001- vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC);
89002+ vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC | SLAB_NO_SANITIZE);
89003 mmap_init();
89004 nsproxy_cache_init();
89005 }
89006@@ -1824,7 +1939,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
89007 return 0;
89008
89009 /* don't need lock here; in the worst case we'll do useless copy */
89010- if (fs->users == 1)
89011+ if (atomic_read(&fs->users) == 1)
89012 return 0;
89013
89014 *new_fsp = copy_fs_struct(fs);
89015@@ -1936,7 +2051,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
89016 fs = current->fs;
89017 spin_lock(&fs->lock);
89018 current->fs = new_fs;
89019- if (--fs->users)
89020+ gr_set_chroot_entries(current, &current->fs->root);
89021+ if (atomic_dec_return(&fs->users))
89022 new_fs = NULL;
89023 else
89024 new_fs = fs;
89025diff --git a/kernel/futex.c b/kernel/futex.c
89026index 63678b5..512f9af 100644
89027--- a/kernel/futex.c
89028+++ b/kernel/futex.c
89029@@ -201,7 +201,7 @@ struct futex_pi_state {
89030 atomic_t refcount;
89031
89032 union futex_key key;
89033-};
89034+} __randomize_layout;
89035
89036 /**
89037 * struct futex_q - The hashed futex queue entry, one per waiting task
89038@@ -235,7 +235,7 @@ struct futex_q {
89039 struct rt_mutex_waiter *rt_waiter;
89040 union futex_key *requeue_pi_key;
89041 u32 bitset;
89042-};
89043+} __randomize_layout;
89044
89045 static const struct futex_q futex_q_init = {
89046 /* list gets initialized in queue_me()*/
89047@@ -402,6 +402,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
89048 struct page *page, *page_head;
89049 int err, ro = 0;
89050
89051+#ifdef CONFIG_PAX_SEGMEXEC
89052+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
89053+ return -EFAULT;
89054+#endif
89055+
89056 /*
89057 * The futex address must be "naturally" aligned.
89058 */
89059@@ -601,7 +606,7 @@ static int cmpxchg_futex_value_locked(u32 *curval, u32 __user *uaddr,
89060
89061 static int get_futex_value_locked(u32 *dest, u32 __user *from)
89062 {
89063- int ret;
89064+ unsigned long ret;
89065
89066 pagefault_disable();
89067 ret = __copy_from_user_inatomic(dest, from, sizeof(u32));
89068@@ -3006,6 +3011,7 @@ static void __init futex_detect_cmpxchg(void)
89069 {
89070 #ifndef CONFIG_HAVE_FUTEX_CMPXCHG
89071 u32 curval;
89072+ mm_segment_t oldfs;
89073
89074 /*
89075 * This will fail and we want it. Some arch implementations do
89076@@ -3017,8 +3023,11 @@ static void __init futex_detect_cmpxchg(void)
89077 * implementation, the non-functional ones will return
89078 * -ENOSYS.
89079 */
89080+ oldfs = get_fs();
89081+ set_fs(USER_DS);
89082 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
89083 futex_cmpxchg_enabled = 1;
89084+ set_fs(oldfs);
89085 #endif
89086 }
89087
89088diff --git a/kernel/futex_compat.c b/kernel/futex_compat.c
89089index 55c8c93..9ba7ad6 100644
89090--- a/kernel/futex_compat.c
89091+++ b/kernel/futex_compat.c
89092@@ -32,7 +32,7 @@ fetch_robust_entry(compat_uptr_t *uentry, struct robust_list __user **entry,
89093 return 0;
89094 }
89095
89096-static void __user *futex_uaddr(struct robust_list __user *entry,
89097+static void __user __intentional_overflow(-1) *futex_uaddr(struct robust_list __user *entry,
89098 compat_long_t futex_offset)
89099 {
89100 compat_uptr_t base = ptr_to_compat(entry);
89101diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
89102index b358a80..fc25240 100644
89103--- a/kernel/gcov/base.c
89104+++ b/kernel/gcov/base.c
89105@@ -114,11 +114,6 @@ void gcov_enable_events(void)
89106 }
89107
89108 #ifdef CONFIG_MODULES
89109-static inline int within(void *addr, void *start, unsigned long size)
89110-{
89111- return ((addr >= start) && (addr < start + size));
89112-}
89113-
89114 /* Update list and generate events when modules are unloaded. */
89115 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
89116 void *data)
89117@@ -133,7 +128,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
89118
89119 /* Remove entries located in module from linked list. */
89120 while ((info = gcov_info_next(info))) {
89121- if (within(info, mod->module_core, mod->core_size)) {
89122+ if (within_module_core_rw((unsigned long)info, mod)) {
89123 gcov_info_unlink(prev, info);
89124 if (gcov_events_enabled)
89125 gcov_event(GCOV_REMOVE, info);
89126diff --git a/kernel/jump_label.c b/kernel/jump_label.c
89127index 9019f15..9a3c42e 100644
89128--- a/kernel/jump_label.c
89129+++ b/kernel/jump_label.c
89130@@ -14,6 +14,7 @@
89131 #include <linux/err.h>
89132 #include <linux/static_key.h>
89133 #include <linux/jump_label_ratelimit.h>
89134+#include <linux/mm.h>
89135
89136 #ifdef HAVE_JUMP_LABEL
89137
89138@@ -51,7 +52,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
89139
89140 size = (((unsigned long)stop - (unsigned long)start)
89141 / sizeof(struct jump_entry));
89142+ pax_open_kernel();
89143 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
89144+ pax_close_kernel();
89145 }
89146
89147 static void jump_label_update(struct static_key *key, int enable);
89148@@ -363,10 +366,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
89149 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
89150 struct jump_entry *iter;
89151
89152+ pax_open_kernel();
89153 for (iter = iter_start; iter < iter_stop; iter++) {
89154 if (within_module_init(iter->code, mod))
89155 iter->code = 0;
89156 }
89157+ pax_close_kernel();
89158 }
89159
89160 static int
89161diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
89162index 5c5987f..bc502b0 100644
89163--- a/kernel/kallsyms.c
89164+++ b/kernel/kallsyms.c
89165@@ -11,6 +11,9 @@
89166 * Changed the compression method from stem compression to "table lookup"
89167 * compression (see scripts/kallsyms.c for a more complete description)
89168 */
89169+#ifdef CONFIG_GRKERNSEC_HIDESYM
89170+#define __INCLUDED_BY_HIDESYM 1
89171+#endif
89172 #include <linux/kallsyms.h>
89173 #include <linux/module.h>
89174 #include <linux/init.h>
89175@@ -54,12 +57,33 @@ extern const unsigned long kallsyms_markers[] __weak;
89176
89177 static inline int is_kernel_inittext(unsigned long addr)
89178 {
89179+ if (system_state != SYSTEM_BOOTING)
89180+ return 0;
89181+
89182 if (addr >= (unsigned long)_sinittext
89183 && addr <= (unsigned long)_einittext)
89184 return 1;
89185 return 0;
89186 }
89187
89188+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
89189+#ifdef CONFIG_MODULES
89190+static inline int is_module_text(unsigned long addr)
89191+{
89192+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
89193+ return 1;
89194+
89195+ addr = ktla_ktva(addr);
89196+ return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
89197+}
89198+#else
89199+static inline int is_module_text(unsigned long addr)
89200+{
89201+ return 0;
89202+}
89203+#endif
89204+#endif
89205+
89206 static inline int is_kernel_text(unsigned long addr)
89207 {
89208 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
89209@@ -70,13 +94,28 @@ static inline int is_kernel_text(unsigned long addr)
89210
89211 static inline int is_kernel(unsigned long addr)
89212 {
89213+
89214+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
89215+ if (is_kernel_text(addr) || is_kernel_inittext(addr))
89216+ return 1;
89217+
89218+ if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
89219+#else
89220 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
89221+#endif
89222+
89223 return 1;
89224 return in_gate_area_no_mm(addr);
89225 }
89226
89227 static int is_ksym_addr(unsigned long addr)
89228 {
89229+
89230+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
89231+ if (is_module_text(addr))
89232+ return 0;
89233+#endif
89234+
89235 if (all_var)
89236 return is_kernel(addr);
89237
89238@@ -481,7 +520,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
89239
89240 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
89241 {
89242- iter->name[0] = '\0';
89243 iter->nameoff = get_symbol_offset(new_pos);
89244 iter->pos = new_pos;
89245 }
89246@@ -529,6 +567,11 @@ static int s_show(struct seq_file *m, void *p)
89247 {
89248 struct kallsym_iter *iter = m->private;
89249
89250+#ifdef CONFIG_GRKERNSEC_HIDESYM
89251+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID))
89252+ return 0;
89253+#endif
89254+
89255 /* Some debugging symbols have no name. Ignore them. */
89256 if (!iter->name[0])
89257 return 0;
89258@@ -542,6 +585,7 @@ static int s_show(struct seq_file *m, void *p)
89259 */
89260 type = iter->exported ? toupper(iter->type) :
89261 tolower(iter->type);
89262+
89263 seq_printf(m, "%pK %c %s\t[%s]\n", (void *)iter->value,
89264 type, iter->name, iter->module_name);
89265 } else
89266diff --git a/kernel/kcmp.c b/kernel/kcmp.c
89267index 0aa69ea..a7fcafb 100644
89268--- a/kernel/kcmp.c
89269+++ b/kernel/kcmp.c
89270@@ -100,6 +100,10 @@ SYSCALL_DEFINE5(kcmp, pid_t, pid1, pid_t, pid2, int, type,
89271 struct task_struct *task1, *task2;
89272 int ret;
89273
89274+#ifdef CONFIG_GRKERNSEC
89275+ return -ENOSYS;
89276+#endif
89277+
89278 rcu_read_lock();
89279
89280 /*
89281diff --git a/kernel/kexec.c b/kernel/kexec.c
89282index 2abf9f6..c40cf85 100644
89283--- a/kernel/kexec.c
89284+++ b/kernel/kexec.c
89285@@ -1349,7 +1349,8 @@ COMPAT_SYSCALL_DEFINE4(kexec_load, compat_ulong_t, entry,
89286 compat_ulong_t, flags)
89287 {
89288 struct compat_kexec_segment in;
89289- struct kexec_segment out, __user *ksegments;
89290+ struct kexec_segment out;
89291+ struct kexec_segment __user *ksegments;
89292 unsigned long i, result;
89293
89294 /* Don't allow clients that don't understand the native
89295diff --git a/kernel/kmod.c b/kernel/kmod.c
89296index 80f7a6d..3c476d3 100644
89297--- a/kernel/kmod.c
89298+++ b/kernel/kmod.c
89299@@ -75,7 +75,7 @@ static void free_modprobe_argv(struct subprocess_info *info)
89300 kfree(info->argv);
89301 }
89302
89303-static int call_modprobe(char *module_name, int wait)
89304+static int call_modprobe(char *module_name, char *module_param, int wait)
89305 {
89306 struct subprocess_info *info;
89307 static char *envp[] = {
89308@@ -85,7 +85,7 @@ static int call_modprobe(char *module_name, int wait)
89309 NULL
89310 };
89311
89312- char **argv = kmalloc(sizeof(char *[5]), GFP_KERNEL);
89313+ char **argv = kmalloc(sizeof(char *[6]), GFP_KERNEL);
89314 if (!argv)
89315 goto out;
89316
89317@@ -97,7 +97,8 @@ static int call_modprobe(char *module_name, int wait)
89318 argv[1] = "-q";
89319 argv[2] = "--";
89320 argv[3] = module_name; /* check free_modprobe_argv() */
89321- argv[4] = NULL;
89322+ argv[4] = module_param;
89323+ argv[5] = NULL;
89324
89325 info = call_usermodehelper_setup(modprobe_path, argv, envp, GFP_KERNEL,
89326 NULL, free_modprobe_argv, NULL);
89327@@ -129,9 +130,8 @@ out:
89328 * If module auto-loading support is disabled then this function
89329 * becomes a no-operation.
89330 */
89331-int __request_module(bool wait, const char *fmt, ...)
89332+static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
89333 {
89334- va_list args;
89335 char module_name[MODULE_NAME_LEN];
89336 unsigned int max_modprobes;
89337 int ret;
89338@@ -150,9 +150,7 @@ int __request_module(bool wait, const char *fmt, ...)
89339 if (!modprobe_path[0])
89340 return 0;
89341
89342- va_start(args, fmt);
89343- ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
89344- va_end(args);
89345+ ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
89346 if (ret >= MODULE_NAME_LEN)
89347 return -ENAMETOOLONG;
89348
89349@@ -160,6 +158,20 @@ int __request_module(bool wait, const char *fmt, ...)
89350 if (ret)
89351 return ret;
89352
89353+#ifdef CONFIG_GRKERNSEC_MODHARDEN
89354+ if (uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
89355+ /* hack to workaround consolekit/udisks stupidity */
89356+ read_lock(&tasklist_lock);
89357+ if (!strcmp(current->comm, "mount") &&
89358+ current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
89359+ read_unlock(&tasklist_lock);
89360+ printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
89361+ return -EPERM;
89362+ }
89363+ read_unlock(&tasklist_lock);
89364+ }
89365+#endif
89366+
89367 /* If modprobe needs a service that is in a module, we get a recursive
89368 * loop. Limit the number of running kmod threads to max_threads/2 or
89369 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
89370@@ -188,16 +200,61 @@ int __request_module(bool wait, const char *fmt, ...)
89371
89372 trace_module_request(module_name, wait, _RET_IP_);
89373
89374- ret = call_modprobe(module_name, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
89375+ ret = call_modprobe(module_name, module_param, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
89376
89377 atomic_dec(&kmod_concurrent);
89378 return ret;
89379 }
89380+
89381+int ___request_module(bool wait, char *module_param, const char *fmt, ...)
89382+{
89383+ va_list args;
89384+ int ret;
89385+
89386+ va_start(args, fmt);
89387+ ret = ____request_module(wait, module_param, fmt, args);
89388+ va_end(args);
89389+
89390+ return ret;
89391+}
89392+
89393+int __request_module(bool wait, const char *fmt, ...)
89394+{
89395+ va_list args;
89396+ int ret;
89397+
89398+#ifdef CONFIG_GRKERNSEC_MODHARDEN
89399+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
89400+ char module_param[MODULE_NAME_LEN];
89401+
89402+ memset(module_param, 0, sizeof(module_param));
89403+
89404+ snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", GR_GLOBAL_UID(current_uid()));
89405+
89406+ va_start(args, fmt);
89407+ ret = ____request_module(wait, module_param, fmt, args);
89408+ va_end(args);
89409+
89410+ return ret;
89411+ }
89412+#endif
89413+
89414+ va_start(args, fmt);
89415+ ret = ____request_module(wait, NULL, fmt, args);
89416+ va_end(args);
89417+
89418+ return ret;
89419+}
89420+
89421 EXPORT_SYMBOL(__request_module);
89422 #endif /* CONFIG_MODULES */
89423
89424 static void call_usermodehelper_freeinfo(struct subprocess_info *info)
89425 {
89426+#ifdef CONFIG_GRKERNSEC
89427+ kfree(info->path);
89428+ info->path = info->origpath;
89429+#endif
89430 if (info->cleanup)
89431 (*info->cleanup)(info);
89432 kfree(info);
89433@@ -240,6 +297,20 @@ static int ____call_usermodehelper(void *data)
89434 */
89435 set_user_nice(current, 0);
89436
89437+#ifdef CONFIG_GRKERNSEC
89438+ /* this is race-free as far as userland is concerned as we copied
89439+ out the path to be used prior to this point and are now operating
89440+ on that copy
89441+ */
89442+ if ((strncmp(sub_info->path, "/sbin/", 6) && strncmp(sub_info->path, "/usr/lib/", 9) &&
89443+ strncmp(sub_info->path, "/lib/", 5) && strncmp(sub_info->path, "/lib64/", 7) &&
89444+ strcmp(sub_info->path, "/usr/share/apport/apport")) || strstr(sub_info->path, "..")) {
89445+ printk(KERN_ALERT "grsec: denied exec of usermode helper binary %.950s located outside of /sbin and system library paths\n", sub_info->path);
89446+ retval = -EPERM;
89447+ goto out;
89448+ }
89449+#endif
89450+
89451 retval = -ENOMEM;
89452 new = prepare_kernel_cred(current);
89453 if (!new)
89454@@ -262,8 +333,8 @@ static int ____call_usermodehelper(void *data)
89455 commit_creds(new);
89456
89457 retval = do_execve(getname_kernel(sub_info->path),
89458- (const char __user *const __user *)sub_info->argv,
89459- (const char __user *const __user *)sub_info->envp);
89460+ (const char __user *const __force_user *)sub_info->argv,
89461+ (const char __user *const __force_user *)sub_info->envp);
89462 out:
89463 sub_info->retval = retval;
89464 /* wait_for_helper() will call umh_complete if UHM_WAIT_PROC. */
89465@@ -303,7 +374,7 @@ static int wait_for_helper(void *data)
89466 *
89467 * Thus the __user pointer cast is valid here.
89468 */
89469- sys_wait4(pid, (int __user *)&ret, 0, NULL);
89470+ sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
89471
89472 /*
89473 * If ret is 0, either ____call_usermodehelper failed and the
89474@@ -532,7 +603,12 @@ struct subprocess_info *call_usermodehelper_setup(char *path, char **argv,
89475 goto out;
89476
89477 INIT_WORK(&sub_info->work, __call_usermodehelper);
89478+#ifdef CONFIG_GRKERNSEC
89479+ sub_info->origpath = path;
89480+ sub_info->path = kstrdup(path, gfp_mask);
89481+#else
89482 sub_info->path = path;
89483+#endif
89484 sub_info->argv = argv;
89485 sub_info->envp = envp;
89486
89487@@ -645,7 +721,7 @@ EXPORT_SYMBOL(call_usermodehelper);
89488 static int proc_cap_handler(struct ctl_table *table, int write,
89489 void __user *buffer, size_t *lenp, loff_t *ppos)
89490 {
89491- struct ctl_table t;
89492+ ctl_table_no_const t;
89493 unsigned long cap_array[_KERNEL_CAPABILITY_U32S];
89494 kernel_cap_t new_cap;
89495 int err, i;
89496diff --git a/kernel/kprobes.c b/kernel/kprobes.c
89497index 3995f54..e247879 100644
89498--- a/kernel/kprobes.c
89499+++ b/kernel/kprobes.c
89500@@ -31,6 +31,9 @@
89501 * <jkenisto@us.ibm.com> and Prasanna S Panchamukhi
89502 * <prasanna@in.ibm.com> added function-return probes.
89503 */
89504+#ifdef CONFIG_GRKERNSEC_HIDESYM
89505+#define __INCLUDED_BY_HIDESYM 1
89506+#endif
89507 #include <linux/kprobes.h>
89508 #include <linux/hash.h>
89509 #include <linux/init.h>
89510@@ -122,12 +125,12 @@ enum kprobe_slot_state {
89511
89512 static void *alloc_insn_page(void)
89513 {
89514- return module_alloc(PAGE_SIZE);
89515+ return module_alloc_exec(PAGE_SIZE);
89516 }
89517
89518 static void free_insn_page(void *page)
89519 {
89520- module_free(NULL, page);
89521+ module_free_exec(NULL, page);
89522 }
89523
89524 struct kprobe_insn_cache kprobe_insn_slots = {
89525@@ -2187,11 +2190,11 @@ static void report_probe(struct seq_file *pi, struct kprobe *p,
89526 kprobe_type = "k";
89527
89528 if (sym)
89529- seq_printf(pi, "%p %s %s+0x%x %s ",
89530+ seq_printf(pi, "%pK %s %s+0x%x %s ",
89531 p->addr, kprobe_type, sym, offset,
89532 (modname ? modname : " "));
89533 else
89534- seq_printf(pi, "%p %s %p ",
89535+ seq_printf(pi, "%pK %s %pK ",
89536 p->addr, kprobe_type, p->addr);
89537
89538 if (!pp)
89539diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
89540index 6683cce..daf8999 100644
89541--- a/kernel/ksysfs.c
89542+++ b/kernel/ksysfs.c
89543@@ -50,6 +50,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
89544 {
89545 if (count+1 > UEVENT_HELPER_PATH_LEN)
89546 return -ENOENT;
89547+ if (!capable(CAP_SYS_ADMIN))
89548+ return -EPERM;
89549 memcpy(uevent_helper, buf, count);
89550 uevent_helper[count] = '\0';
89551 if (count && uevent_helper[count-1] == '\n')
89552@@ -176,7 +178,7 @@ static ssize_t notes_read(struct file *filp, struct kobject *kobj,
89553 return count;
89554 }
89555
89556-static struct bin_attribute notes_attr = {
89557+static bin_attribute_no_const notes_attr __read_only = {
89558 .attr = {
89559 .name = "notes",
89560 .mode = S_IRUGO,
89561diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
89562index 88d0d44..e9ce0ee 100644
89563--- a/kernel/locking/lockdep.c
89564+++ b/kernel/locking/lockdep.c
89565@@ -599,6 +599,10 @@ static int static_obj(void *obj)
89566 end = (unsigned long) &_end,
89567 addr = (unsigned long) obj;
89568
89569+#ifdef CONFIG_PAX_KERNEXEC
89570+ start = ktla_ktva(start);
89571+#endif
89572+
89573 /*
89574 * static variable?
89575 */
89576@@ -740,6 +744,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
89577 if (!static_obj(lock->key)) {
89578 debug_locks_off();
89579 printk("INFO: trying to register non-static key.\n");
89580+ printk("lock:%pS key:%pS.\n", lock, lock->key);
89581 printk("the code is fine but needs lockdep annotation.\n");
89582 printk("turning off the locking correctness validator.\n");
89583 dump_stack();
89584@@ -3081,7 +3086,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
89585 if (!class)
89586 return 0;
89587 }
89588- atomic_inc((atomic_t *)&class->ops);
89589+ atomic_long_inc_unchecked((atomic_long_unchecked_t *)&class->ops);
89590 if (very_verbose(class)) {
89591 printk("\nacquire class [%p] %s", class->key, class->name);
89592 if (class->name_version > 1)
89593diff --git a/kernel/locking/lockdep_proc.c b/kernel/locking/lockdep_proc.c
89594index ef43ac4..2720dfa 100644
89595--- a/kernel/locking/lockdep_proc.c
89596+++ b/kernel/locking/lockdep_proc.c
89597@@ -65,7 +65,7 @@ static int l_show(struct seq_file *m, void *v)
89598 return 0;
89599 }
89600
89601- seq_printf(m, "%p", class->key);
89602+ seq_printf(m, "%pK", class->key);
89603 #ifdef CONFIG_DEBUG_LOCKDEP
89604 seq_printf(m, " OPS:%8ld", class->ops);
89605 #endif
89606@@ -83,7 +83,7 @@ static int l_show(struct seq_file *m, void *v)
89607
89608 list_for_each_entry(entry, &class->locks_after, entry) {
89609 if (entry->distance == 1) {
89610- seq_printf(m, " -> [%p] ", entry->class->key);
89611+ seq_printf(m, " -> [%pK] ", entry->class->key);
89612 print_name(m, entry->class);
89613 seq_puts(m, "\n");
89614 }
89615@@ -152,7 +152,7 @@ static int lc_show(struct seq_file *m, void *v)
89616 if (!class->key)
89617 continue;
89618
89619- seq_printf(m, "[%p] ", class->key);
89620+ seq_printf(m, "[%pK] ", class->key);
89621 print_name(m, class);
89622 seq_puts(m, "\n");
89623 }
89624@@ -496,7 +496,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
89625 if (!i)
89626 seq_line(m, '-', 40-namelen, namelen);
89627
89628- snprintf(ip, sizeof(ip), "[<%p>]",
89629+ snprintf(ip, sizeof(ip), "[<%pK>]",
89630 (void *)class->contention_point[i]);
89631 seq_printf(m, "%40s %14lu %29s %pS\n",
89632 name, stats->contention_point[i],
89633@@ -511,7 +511,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
89634 if (!i)
89635 seq_line(m, '-', 40-namelen, namelen);
89636
89637- snprintf(ip, sizeof(ip), "[<%p>]",
89638+ snprintf(ip, sizeof(ip), "[<%pK>]",
89639 (void *)class->contending_point[i]);
89640 seq_printf(m, "%40s %14lu %29s %pS\n",
89641 name, stats->contending_point[i],
89642diff --git a/kernel/locking/mcs_spinlock.c b/kernel/locking/mcs_spinlock.c
89643index 9887a90..0cd2b1d 100644
89644--- a/kernel/locking/mcs_spinlock.c
89645+++ b/kernel/locking/mcs_spinlock.c
89646@@ -100,7 +100,7 @@ bool osq_lock(struct optimistic_spin_queue *lock)
89647
89648 prev = decode_cpu(old);
89649 node->prev = prev;
89650- ACCESS_ONCE(prev->next) = node;
89651+ ACCESS_ONCE_RW(prev->next) = node;
89652
89653 /*
89654 * Normally @prev is untouchable after the above store; because at that
89655@@ -172,8 +172,8 @@ unqueue:
89656 * it will wait in Step-A.
89657 */
89658
89659- ACCESS_ONCE(next->prev) = prev;
89660- ACCESS_ONCE(prev->next) = next;
89661+ ACCESS_ONCE_RW(next->prev) = prev;
89662+ ACCESS_ONCE_RW(prev->next) = next;
89663
89664 return false;
89665 }
89666@@ -195,13 +195,13 @@ void osq_unlock(struct optimistic_spin_queue *lock)
89667 node = this_cpu_ptr(&osq_node);
89668 next = xchg(&node->next, NULL);
89669 if (next) {
89670- ACCESS_ONCE(next->locked) = 1;
89671+ ACCESS_ONCE_RW(next->locked) = 1;
89672 return;
89673 }
89674
89675 next = osq_wait_next(lock, node, NULL);
89676 if (next)
89677- ACCESS_ONCE(next->locked) = 1;
89678+ ACCESS_ONCE_RW(next->locked) = 1;
89679 }
89680
89681 #endif
89682diff --git a/kernel/locking/mcs_spinlock.h b/kernel/locking/mcs_spinlock.h
89683index 4d60986..5d351c1 100644
89684--- a/kernel/locking/mcs_spinlock.h
89685+++ b/kernel/locking/mcs_spinlock.h
89686@@ -78,7 +78,7 @@ void mcs_spin_lock(struct mcs_spinlock **lock, struct mcs_spinlock *node)
89687 */
89688 return;
89689 }
89690- ACCESS_ONCE(prev->next) = node;
89691+ ACCESS_ONCE_RW(prev->next) = node;
89692
89693 /* Wait until the lock holder passes the lock down. */
89694 arch_mcs_spin_lock_contended(&node->locked);
89695diff --git a/kernel/locking/mutex-debug.c b/kernel/locking/mutex-debug.c
89696index 5cf6731..ce3bc5a 100644
89697--- a/kernel/locking/mutex-debug.c
89698+++ b/kernel/locking/mutex-debug.c
89699@@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
89700 }
89701
89702 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
89703- struct thread_info *ti)
89704+ struct task_struct *task)
89705 {
89706 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
89707
89708 /* Mark the current thread as blocked on the lock: */
89709- ti->task->blocked_on = waiter;
89710+ task->blocked_on = waiter;
89711 }
89712
89713 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
89714- struct thread_info *ti)
89715+ struct task_struct *task)
89716 {
89717 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
89718- DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
89719- DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
89720- ti->task->blocked_on = NULL;
89721+ DEBUG_LOCKS_WARN_ON(waiter->task != task);
89722+ DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
89723+ task->blocked_on = NULL;
89724
89725 list_del_init(&waiter->list);
89726 waiter->task = NULL;
89727diff --git a/kernel/locking/mutex-debug.h b/kernel/locking/mutex-debug.h
89728index 0799fd3..d06ae3b 100644
89729--- a/kernel/locking/mutex-debug.h
89730+++ b/kernel/locking/mutex-debug.h
89731@@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
89732 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
89733 extern void debug_mutex_add_waiter(struct mutex *lock,
89734 struct mutex_waiter *waiter,
89735- struct thread_info *ti);
89736+ struct task_struct *task);
89737 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
89738- struct thread_info *ti);
89739+ struct task_struct *task);
89740 extern void debug_mutex_unlock(struct mutex *lock);
89741 extern void debug_mutex_init(struct mutex *lock, const char *name,
89742 struct lock_class_key *key);
89743diff --git a/kernel/locking/mutex.c b/kernel/locking/mutex.c
89744index dadbf88..4500507 100644
89745--- a/kernel/locking/mutex.c
89746+++ b/kernel/locking/mutex.c
89747@@ -518,7 +518,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
89748 goto skip_wait;
89749
89750 debug_mutex_lock_common(lock, &waiter);
89751- debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
89752+ debug_mutex_add_waiter(lock, &waiter, task);
89753
89754 /* add waiting tasks to the end of the waitqueue (FIFO): */
89755 list_add_tail(&waiter.list, &lock->wait_list);
89756@@ -563,7 +563,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
89757 schedule_preempt_disabled();
89758 spin_lock_mutex(&lock->wait_lock, flags);
89759 }
89760- mutex_remove_waiter(lock, &waiter, current_thread_info());
89761+ mutex_remove_waiter(lock, &waiter, task);
89762 /* set it to 0 if there are no waiters left: */
89763 if (likely(list_empty(&lock->wait_list)))
89764 atomic_set(&lock->count, 0);
89765@@ -600,7 +600,7 @@ skip_wait:
89766 return 0;
89767
89768 err:
89769- mutex_remove_waiter(lock, &waiter, task_thread_info(task));
89770+ mutex_remove_waiter(lock, &waiter, task);
89771 spin_unlock_mutex(&lock->wait_lock, flags);
89772 debug_mutex_free_waiter(&waiter);
89773 mutex_release(&lock->dep_map, 1, ip);
89774diff --git a/kernel/locking/rtmutex-tester.c b/kernel/locking/rtmutex-tester.c
89775index 1d96dd0..994ff19 100644
89776--- a/kernel/locking/rtmutex-tester.c
89777+++ b/kernel/locking/rtmutex-tester.c
89778@@ -22,7 +22,7 @@
89779 #define MAX_RT_TEST_MUTEXES 8
89780
89781 static spinlock_t rttest_lock;
89782-static atomic_t rttest_event;
89783+static atomic_unchecked_t rttest_event;
89784
89785 struct test_thread_data {
89786 int opcode;
89787@@ -63,7 +63,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
89788
89789 case RTTEST_LOCKCONT:
89790 td->mutexes[td->opdata] = 1;
89791- td->event = atomic_add_return(1, &rttest_event);
89792+ td->event = atomic_add_return_unchecked(1, &rttest_event);
89793 return 0;
89794
89795 case RTTEST_RESET:
89796@@ -76,7 +76,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
89797 return 0;
89798
89799 case RTTEST_RESETEVENT:
89800- atomic_set(&rttest_event, 0);
89801+ atomic_set_unchecked(&rttest_event, 0);
89802 return 0;
89803
89804 default:
89805@@ -93,9 +93,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
89806 return ret;
89807
89808 td->mutexes[id] = 1;
89809- td->event = atomic_add_return(1, &rttest_event);
89810+ td->event = atomic_add_return_unchecked(1, &rttest_event);
89811 rt_mutex_lock(&mutexes[id]);
89812- td->event = atomic_add_return(1, &rttest_event);
89813+ td->event = atomic_add_return_unchecked(1, &rttest_event);
89814 td->mutexes[id] = 4;
89815 return 0;
89816
89817@@ -106,9 +106,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
89818 return ret;
89819
89820 td->mutexes[id] = 1;
89821- td->event = atomic_add_return(1, &rttest_event);
89822+ td->event = atomic_add_return_unchecked(1, &rttest_event);
89823 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
89824- td->event = atomic_add_return(1, &rttest_event);
89825+ td->event = atomic_add_return_unchecked(1, &rttest_event);
89826 td->mutexes[id] = ret ? 0 : 4;
89827 return ret ? -EINTR : 0;
89828
89829@@ -117,9 +117,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
89830 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
89831 return ret;
89832
89833- td->event = atomic_add_return(1, &rttest_event);
89834+ td->event = atomic_add_return_unchecked(1, &rttest_event);
89835 rt_mutex_unlock(&mutexes[id]);
89836- td->event = atomic_add_return(1, &rttest_event);
89837+ td->event = atomic_add_return_unchecked(1, &rttest_event);
89838 td->mutexes[id] = 0;
89839 return 0;
89840
89841@@ -166,7 +166,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
89842 break;
89843
89844 td->mutexes[dat] = 2;
89845- td->event = atomic_add_return(1, &rttest_event);
89846+ td->event = atomic_add_return_unchecked(1, &rttest_event);
89847 break;
89848
89849 default:
89850@@ -186,7 +186,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
89851 return;
89852
89853 td->mutexes[dat] = 3;
89854- td->event = atomic_add_return(1, &rttest_event);
89855+ td->event = atomic_add_return_unchecked(1, &rttest_event);
89856 break;
89857
89858 case RTTEST_LOCKNOWAIT:
89859@@ -198,7 +198,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
89860 return;
89861
89862 td->mutexes[dat] = 1;
89863- td->event = atomic_add_return(1, &rttest_event);
89864+ td->event = atomic_add_return_unchecked(1, &rttest_event);
89865 return;
89866
89867 default:
89868diff --git a/kernel/module.c b/kernel/module.c
89869index 88cec1d..d097c28 100644
89870--- a/kernel/module.c
89871+++ b/kernel/module.c
89872@@ -60,6 +60,7 @@
89873 #include <linux/jump_label.h>
89874 #include <linux/pfn.h>
89875 #include <linux/bsearch.h>
89876+#include <linux/grsecurity.h>
89877 #include <uapi/linux/module.h>
89878 #include "module-internal.h"
89879
89880@@ -156,7 +157,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
89881
89882 /* Bounds of module allocation, for speeding __module_address.
89883 * Protected by module_mutex. */
89884-static unsigned long module_addr_min = -1UL, module_addr_max = 0;
89885+static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
89886+static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
89887
89888 int register_module_notifier(struct notifier_block * nb)
89889 {
89890@@ -323,7 +325,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
89891 return true;
89892
89893 list_for_each_entry_rcu(mod, &modules, list) {
89894- struct symsearch arr[] = {
89895+ struct symsearch modarr[] = {
89896 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
89897 NOT_GPL_ONLY, false },
89898 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
89899@@ -348,7 +350,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
89900 if (mod->state == MODULE_STATE_UNFORMED)
89901 continue;
89902
89903- if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
89904+ if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
89905 return true;
89906 }
89907 return false;
89908@@ -488,7 +490,7 @@ static int percpu_modalloc(struct module *mod, struct load_info *info)
89909 if (!pcpusec->sh_size)
89910 return 0;
89911
89912- if (align > PAGE_SIZE) {
89913+ if (align-1 >= PAGE_SIZE) {
89914 pr_warn("%s: per-cpu alignment %li > %li\n",
89915 mod->name, align, PAGE_SIZE);
89916 align = PAGE_SIZE;
89917@@ -1060,7 +1062,7 @@ struct module_attribute module_uevent =
89918 static ssize_t show_coresize(struct module_attribute *mattr,
89919 struct module_kobject *mk, char *buffer)
89920 {
89921- return sprintf(buffer, "%u\n", mk->mod->core_size);
89922+ return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
89923 }
89924
89925 static struct module_attribute modinfo_coresize =
89926@@ -1069,7 +1071,7 @@ static struct module_attribute modinfo_coresize =
89927 static ssize_t show_initsize(struct module_attribute *mattr,
89928 struct module_kobject *mk, char *buffer)
89929 {
89930- return sprintf(buffer, "%u\n", mk->mod->init_size);
89931+ return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
89932 }
89933
89934 static struct module_attribute modinfo_initsize =
89935@@ -1161,12 +1163,29 @@ static int check_version(Elf_Shdr *sechdrs,
89936 goto bad_version;
89937 }
89938
89939+#ifdef CONFIG_GRKERNSEC_RANDSTRUCT
89940+ /*
89941+ * avoid potentially printing jibberish on attempted load
89942+ * of a module randomized with a different seed
89943+ */
89944+ pr_warn("no symbol version for %s\n", symname);
89945+#else
89946 pr_warn("%s: no symbol version for %s\n", mod->name, symname);
89947+#endif
89948 return 0;
89949
89950 bad_version:
89951+#ifdef CONFIG_GRKERNSEC_RANDSTRUCT
89952+ /*
89953+ * avoid potentially printing jibberish on attempted load
89954+ * of a module randomized with a different seed
89955+ */
89956+ printk("attempted module disagrees about version of symbol %s\n",
89957+ symname);
89958+#else
89959 printk("%s: disagrees about version of symbol %s\n",
89960 mod->name, symname);
89961+#endif
89962 return 0;
89963 }
89964
89965@@ -1282,7 +1301,7 @@ resolve_symbol_wait(struct module *mod,
89966 */
89967 #ifdef CONFIG_SYSFS
89968
89969-#ifdef CONFIG_KALLSYMS
89970+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
89971 static inline bool sect_empty(const Elf_Shdr *sect)
89972 {
89973 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
89974@@ -1422,7 +1441,7 @@ static void add_notes_attrs(struct module *mod, const struct load_info *info)
89975 {
89976 unsigned int notes, loaded, i;
89977 struct module_notes_attrs *notes_attrs;
89978- struct bin_attribute *nattr;
89979+ bin_attribute_no_const *nattr;
89980
89981 /* failed to create section attributes, so can't create notes */
89982 if (!mod->sect_attrs)
89983@@ -1534,7 +1553,7 @@ static void del_usage_links(struct module *mod)
89984 static int module_add_modinfo_attrs(struct module *mod)
89985 {
89986 struct module_attribute *attr;
89987- struct module_attribute *temp_attr;
89988+ module_attribute_no_const *temp_attr;
89989 int error = 0;
89990 int i;
89991
89992@@ -1755,21 +1774,21 @@ static void set_section_ro_nx(void *base,
89993
89994 static void unset_module_core_ro_nx(struct module *mod)
89995 {
89996- set_page_attributes(mod->module_core + mod->core_text_size,
89997- mod->module_core + mod->core_size,
89998+ set_page_attributes(mod->module_core_rw,
89999+ mod->module_core_rw + mod->core_size_rw,
90000 set_memory_x);
90001- set_page_attributes(mod->module_core,
90002- mod->module_core + mod->core_ro_size,
90003+ set_page_attributes(mod->module_core_rx,
90004+ mod->module_core_rx + mod->core_size_rx,
90005 set_memory_rw);
90006 }
90007
90008 static void unset_module_init_ro_nx(struct module *mod)
90009 {
90010- set_page_attributes(mod->module_init + mod->init_text_size,
90011- mod->module_init + mod->init_size,
90012+ set_page_attributes(mod->module_init_rw,
90013+ mod->module_init_rw + mod->init_size_rw,
90014 set_memory_x);
90015- set_page_attributes(mod->module_init,
90016- mod->module_init + mod->init_ro_size,
90017+ set_page_attributes(mod->module_init_rx,
90018+ mod->module_init_rx + mod->init_size_rx,
90019 set_memory_rw);
90020 }
90021
90022@@ -1782,14 +1801,14 @@ void set_all_modules_text_rw(void)
90023 list_for_each_entry_rcu(mod, &modules, list) {
90024 if (mod->state == MODULE_STATE_UNFORMED)
90025 continue;
90026- if ((mod->module_core) && (mod->core_text_size)) {
90027- set_page_attributes(mod->module_core,
90028- mod->module_core + mod->core_text_size,
90029+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
90030+ set_page_attributes(mod->module_core_rx,
90031+ mod->module_core_rx + mod->core_size_rx,
90032 set_memory_rw);
90033 }
90034- if ((mod->module_init) && (mod->init_text_size)) {
90035- set_page_attributes(mod->module_init,
90036- mod->module_init + mod->init_text_size,
90037+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
90038+ set_page_attributes(mod->module_init_rx,
90039+ mod->module_init_rx + mod->init_size_rx,
90040 set_memory_rw);
90041 }
90042 }
90043@@ -1805,14 +1824,14 @@ void set_all_modules_text_ro(void)
90044 list_for_each_entry_rcu(mod, &modules, list) {
90045 if (mod->state == MODULE_STATE_UNFORMED)
90046 continue;
90047- if ((mod->module_core) && (mod->core_text_size)) {
90048- set_page_attributes(mod->module_core,
90049- mod->module_core + mod->core_text_size,
90050+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
90051+ set_page_attributes(mod->module_core_rx,
90052+ mod->module_core_rx + mod->core_size_rx,
90053 set_memory_ro);
90054 }
90055- if ((mod->module_init) && (mod->init_text_size)) {
90056- set_page_attributes(mod->module_init,
90057- mod->module_init + mod->init_text_size,
90058+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
90059+ set_page_attributes(mod->module_init_rx,
90060+ mod->module_init_rx + mod->init_size_rx,
90061 set_memory_ro);
90062 }
90063 }
90064@@ -1865,16 +1884,19 @@ static void free_module(struct module *mod)
90065
90066 /* This may be NULL, but that's OK */
90067 unset_module_init_ro_nx(mod);
90068- module_free(mod, mod->module_init);
90069+ module_free(mod, mod->module_init_rw);
90070+ module_free_exec(mod, mod->module_init_rx);
90071 kfree(mod->args);
90072 percpu_modfree(mod);
90073
90074 /* Free lock-classes: */
90075- lockdep_free_key_range(mod->module_core, mod->core_size);
90076+ lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
90077+ lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
90078
90079 /* Finally, free the core (containing the module structure) */
90080 unset_module_core_ro_nx(mod);
90081- module_free(mod, mod->module_core);
90082+ module_free_exec(mod, mod->module_core_rx);
90083+ module_free(mod, mod->module_core_rw);
90084
90085 #ifdef CONFIG_MPU
90086 update_protections(current->mm);
90087@@ -1943,9 +1965,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
90088 int ret = 0;
90089 const struct kernel_symbol *ksym;
90090
90091+#ifdef CONFIG_GRKERNSEC_MODHARDEN
90092+ int is_fs_load = 0;
90093+ int register_filesystem_found = 0;
90094+ char *p;
90095+
90096+ p = strstr(mod->args, "grsec_modharden_fs");
90097+ if (p) {
90098+ char *endptr = p + sizeof("grsec_modharden_fs") - 1;
90099+ /* copy \0 as well */
90100+ memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
90101+ is_fs_load = 1;
90102+ }
90103+#endif
90104+
90105 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
90106 const char *name = info->strtab + sym[i].st_name;
90107
90108+#ifdef CONFIG_GRKERNSEC_MODHARDEN
90109+ /* it's a real shame this will never get ripped and copied
90110+ upstream! ;(
90111+ */
90112+ if (is_fs_load && !strcmp(name, "register_filesystem"))
90113+ register_filesystem_found = 1;
90114+#endif
90115+
90116 switch (sym[i].st_shndx) {
90117 case SHN_COMMON:
90118 /* Ignore common symbols */
90119@@ -1970,7 +2014,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
90120 ksym = resolve_symbol_wait(mod, info, name);
90121 /* Ok if resolved. */
90122 if (ksym && !IS_ERR(ksym)) {
90123+ pax_open_kernel();
90124 sym[i].st_value = ksym->value;
90125+ pax_close_kernel();
90126 break;
90127 }
90128
90129@@ -1989,11 +2035,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
90130 secbase = (unsigned long)mod_percpu(mod);
90131 else
90132 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
90133+ pax_open_kernel();
90134 sym[i].st_value += secbase;
90135+ pax_close_kernel();
90136 break;
90137 }
90138 }
90139
90140+#ifdef CONFIG_GRKERNSEC_MODHARDEN
90141+ if (is_fs_load && !register_filesystem_found) {
90142+ printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
90143+ ret = -EPERM;
90144+ }
90145+#endif
90146+
90147 return ret;
90148 }
90149
90150@@ -2077,22 +2132,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
90151 || s->sh_entsize != ~0UL
90152 || strstarts(sname, ".init"))
90153 continue;
90154- s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
90155+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
90156+ s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
90157+ else
90158+ s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
90159 pr_debug("\t%s\n", sname);
90160 }
90161- switch (m) {
90162- case 0: /* executable */
90163- mod->core_size = debug_align(mod->core_size);
90164- mod->core_text_size = mod->core_size;
90165- break;
90166- case 1: /* RO: text and ro-data */
90167- mod->core_size = debug_align(mod->core_size);
90168- mod->core_ro_size = mod->core_size;
90169- break;
90170- case 3: /* whole core */
90171- mod->core_size = debug_align(mod->core_size);
90172- break;
90173- }
90174 }
90175
90176 pr_debug("Init section allocation order:\n");
90177@@ -2106,23 +2151,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
90178 || s->sh_entsize != ~0UL
90179 || !strstarts(sname, ".init"))
90180 continue;
90181- s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
90182- | INIT_OFFSET_MASK);
90183+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
90184+ s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
90185+ else
90186+ s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
90187+ s->sh_entsize |= INIT_OFFSET_MASK;
90188 pr_debug("\t%s\n", sname);
90189 }
90190- switch (m) {
90191- case 0: /* executable */
90192- mod->init_size = debug_align(mod->init_size);
90193- mod->init_text_size = mod->init_size;
90194- break;
90195- case 1: /* RO: text and ro-data */
90196- mod->init_size = debug_align(mod->init_size);
90197- mod->init_ro_size = mod->init_size;
90198- break;
90199- case 3: /* whole init */
90200- mod->init_size = debug_align(mod->init_size);
90201- break;
90202- }
90203 }
90204 }
90205
90206@@ -2295,7 +2330,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
90207
90208 /* Put symbol section at end of init part of module. */
90209 symsect->sh_flags |= SHF_ALLOC;
90210- symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
90211+ symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
90212 info->index.sym) | INIT_OFFSET_MASK;
90213 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
90214
90215@@ -2312,13 +2347,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
90216 }
90217
90218 /* Append room for core symbols at end of core part. */
90219- info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
90220- info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
90221- mod->core_size += strtab_size;
90222+ info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
90223+ info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
90224+ mod->core_size_rx += strtab_size;
90225
90226 /* Put string table section at end of init part of module. */
90227 strsect->sh_flags |= SHF_ALLOC;
90228- strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
90229+ strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
90230 info->index.str) | INIT_OFFSET_MASK;
90231 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
90232 }
90233@@ -2336,12 +2371,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
90234 /* Make sure we get permanent strtab: don't use info->strtab. */
90235 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
90236
90237+ pax_open_kernel();
90238+
90239 /* Set types up while we still have access to sections. */
90240 for (i = 0; i < mod->num_symtab; i++)
90241 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
90242
90243- mod->core_symtab = dst = mod->module_core + info->symoffs;
90244- mod->core_strtab = s = mod->module_core + info->stroffs;
90245+ mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
90246+ mod->core_strtab = s = mod->module_core_rx + info->stroffs;
90247 src = mod->symtab;
90248 for (ndst = i = 0; i < mod->num_symtab; i++) {
90249 if (i == 0 ||
90250@@ -2353,6 +2390,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
90251 }
90252 }
90253 mod->core_num_syms = ndst;
90254+
90255+ pax_close_kernel();
90256 }
90257 #else
90258 static inline void layout_symtab(struct module *mod, struct load_info *info)
90259@@ -2386,17 +2425,33 @@ void * __weak module_alloc(unsigned long size)
90260 return vmalloc_exec(size);
90261 }
90262
90263-static void *module_alloc_update_bounds(unsigned long size)
90264+static void *module_alloc_update_bounds_rw(unsigned long size)
90265 {
90266 void *ret = module_alloc(size);
90267
90268 if (ret) {
90269 mutex_lock(&module_mutex);
90270 /* Update module bounds. */
90271- if ((unsigned long)ret < module_addr_min)
90272- module_addr_min = (unsigned long)ret;
90273- if ((unsigned long)ret + size > module_addr_max)
90274- module_addr_max = (unsigned long)ret + size;
90275+ if ((unsigned long)ret < module_addr_min_rw)
90276+ module_addr_min_rw = (unsigned long)ret;
90277+ if ((unsigned long)ret + size > module_addr_max_rw)
90278+ module_addr_max_rw = (unsigned long)ret + size;
90279+ mutex_unlock(&module_mutex);
90280+ }
90281+ return ret;
90282+}
90283+
90284+static void *module_alloc_update_bounds_rx(unsigned long size)
90285+{
90286+ void *ret = module_alloc_exec(size);
90287+
90288+ if (ret) {
90289+ mutex_lock(&module_mutex);
90290+ /* Update module bounds. */
90291+ if ((unsigned long)ret < module_addr_min_rx)
90292+ module_addr_min_rx = (unsigned long)ret;
90293+ if ((unsigned long)ret + size > module_addr_max_rx)
90294+ module_addr_max_rx = (unsigned long)ret + size;
90295 mutex_unlock(&module_mutex);
90296 }
90297 return ret;
90298@@ -2650,7 +2705,15 @@ static struct module *setup_load_info(struct load_info *info, int flags)
90299 mod = (void *)info->sechdrs[info->index.mod].sh_addr;
90300
90301 if (info->index.sym == 0) {
90302+#ifdef CONFIG_GRKERNSEC_RANDSTRUCT
90303+ /*
90304+ * avoid potentially printing jibberish on attempted load
90305+ * of a module randomized with a different seed
90306+ */
90307+ pr_warn("module has no symbols (stripped?)\n");
90308+#else
90309 pr_warn("%s: module has no symbols (stripped?)\n", mod->name);
90310+#endif
90311 return ERR_PTR(-ENOEXEC);
90312 }
90313
90314@@ -2666,8 +2729,14 @@ static struct module *setup_load_info(struct load_info *info, int flags)
90315 static int check_modinfo(struct module *mod, struct load_info *info, int flags)
90316 {
90317 const char *modmagic = get_modinfo(info, "vermagic");
90318+ const char *license = get_modinfo(info, "license");
90319 int err;
90320
90321+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
90322+ if (!license || !license_is_gpl_compatible(license))
90323+ return -ENOEXEC;
90324+#endif
90325+
90326 if (flags & MODULE_INIT_IGNORE_VERMAGIC)
90327 modmagic = NULL;
90328
90329@@ -2692,7 +2761,7 @@ static int check_modinfo(struct module *mod, struct load_info *info, int flags)
90330 }
90331
90332 /* Set up license info based on the info section */
90333- set_license(mod, get_modinfo(info, "license"));
90334+ set_license(mod, license);
90335
90336 return 0;
90337 }
90338@@ -2786,7 +2855,7 @@ static int move_module(struct module *mod, struct load_info *info)
90339 void *ptr;
90340
90341 /* Do the allocs. */
90342- ptr = module_alloc_update_bounds(mod->core_size);
90343+ ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
90344 /*
90345 * The pointer to this block is stored in the module structure
90346 * which is inside the block. Just mark it as not being a
90347@@ -2796,11 +2865,11 @@ static int move_module(struct module *mod, struct load_info *info)
90348 if (!ptr)
90349 return -ENOMEM;
90350
90351- memset(ptr, 0, mod->core_size);
90352- mod->module_core = ptr;
90353+ memset(ptr, 0, mod->core_size_rw);
90354+ mod->module_core_rw = ptr;
90355
90356- if (mod->init_size) {
90357- ptr = module_alloc_update_bounds(mod->init_size);
90358+ if (mod->init_size_rw) {
90359+ ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
90360 /*
90361 * The pointer to this block is stored in the module structure
90362 * which is inside the block. This block doesn't need to be
90363@@ -2809,13 +2878,45 @@ static int move_module(struct module *mod, struct load_info *info)
90364 */
90365 kmemleak_ignore(ptr);
90366 if (!ptr) {
90367- module_free(mod, mod->module_core);
90368+ module_free(mod, mod->module_core_rw);
90369 return -ENOMEM;
90370 }
90371- memset(ptr, 0, mod->init_size);
90372- mod->module_init = ptr;
90373+ memset(ptr, 0, mod->init_size_rw);
90374+ mod->module_init_rw = ptr;
90375 } else
90376- mod->module_init = NULL;
90377+ mod->module_init_rw = NULL;
90378+
90379+ ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
90380+ kmemleak_not_leak(ptr);
90381+ if (!ptr) {
90382+ if (mod->module_init_rw)
90383+ module_free(mod, mod->module_init_rw);
90384+ module_free(mod, mod->module_core_rw);
90385+ return -ENOMEM;
90386+ }
90387+
90388+ pax_open_kernel();
90389+ memset(ptr, 0, mod->core_size_rx);
90390+ pax_close_kernel();
90391+ mod->module_core_rx = ptr;
90392+
90393+ if (mod->init_size_rx) {
90394+ ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
90395+ kmemleak_ignore(ptr);
90396+ if (!ptr && mod->init_size_rx) {
90397+ module_free_exec(mod, mod->module_core_rx);
90398+ if (mod->module_init_rw)
90399+ module_free(mod, mod->module_init_rw);
90400+ module_free(mod, mod->module_core_rw);
90401+ return -ENOMEM;
90402+ }
90403+
90404+ pax_open_kernel();
90405+ memset(ptr, 0, mod->init_size_rx);
90406+ pax_close_kernel();
90407+ mod->module_init_rx = ptr;
90408+ } else
90409+ mod->module_init_rx = NULL;
90410
90411 /* Transfer each section which specifies SHF_ALLOC */
90412 pr_debug("final section addresses:\n");
90413@@ -2826,16 +2927,45 @@ static int move_module(struct module *mod, struct load_info *info)
90414 if (!(shdr->sh_flags & SHF_ALLOC))
90415 continue;
90416
90417- if (shdr->sh_entsize & INIT_OFFSET_MASK)
90418- dest = mod->module_init
90419- + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
90420- else
90421- dest = mod->module_core + shdr->sh_entsize;
90422+ if (shdr->sh_entsize & INIT_OFFSET_MASK) {
90423+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
90424+ dest = mod->module_init_rw
90425+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
90426+ else
90427+ dest = mod->module_init_rx
90428+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
90429+ } else {
90430+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
90431+ dest = mod->module_core_rw + shdr->sh_entsize;
90432+ else
90433+ dest = mod->module_core_rx + shdr->sh_entsize;
90434+ }
90435+
90436+ if (shdr->sh_type != SHT_NOBITS) {
90437+
90438+#ifdef CONFIG_PAX_KERNEXEC
90439+#ifdef CONFIG_X86_64
90440+ if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
90441+ set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
90442+#endif
90443+ if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
90444+ pax_open_kernel();
90445+ memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
90446+ pax_close_kernel();
90447+ } else
90448+#endif
90449
90450- if (shdr->sh_type != SHT_NOBITS)
90451 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
90452+ }
90453 /* Update sh_addr to point to copy in image. */
90454- shdr->sh_addr = (unsigned long)dest;
90455+
90456+#ifdef CONFIG_PAX_KERNEXEC
90457+ if (shdr->sh_flags & SHF_EXECINSTR)
90458+ shdr->sh_addr = ktva_ktla((unsigned long)dest);
90459+ else
90460+#endif
90461+
90462+ shdr->sh_addr = (unsigned long)dest;
90463 pr_debug("\t0x%lx %s\n",
90464 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
90465 }
90466@@ -2892,12 +3022,12 @@ static void flush_module_icache(const struct module *mod)
90467 * Do it before processing of module parameters, so the module
90468 * can provide parameter accessor functions of its own.
90469 */
90470- if (mod->module_init)
90471- flush_icache_range((unsigned long)mod->module_init,
90472- (unsigned long)mod->module_init
90473- + mod->init_size);
90474- flush_icache_range((unsigned long)mod->module_core,
90475- (unsigned long)mod->module_core + mod->core_size);
90476+ if (mod->module_init_rx)
90477+ flush_icache_range((unsigned long)mod->module_init_rx,
90478+ (unsigned long)mod->module_init_rx
90479+ + mod->init_size_rx);
90480+ flush_icache_range((unsigned long)mod->module_core_rx,
90481+ (unsigned long)mod->module_core_rx + mod->core_size_rx);
90482
90483 set_fs(old_fs);
90484 }
90485@@ -2954,8 +3084,10 @@ static struct module *layout_and_allocate(struct load_info *info, int flags)
90486 static void module_deallocate(struct module *mod, struct load_info *info)
90487 {
90488 percpu_modfree(mod);
90489- module_free(mod, mod->module_init);
90490- module_free(mod, mod->module_core);
90491+ module_free_exec(mod, mod->module_init_rx);
90492+ module_free_exec(mod, mod->module_core_rx);
90493+ module_free(mod, mod->module_init_rw);
90494+ module_free(mod, mod->module_core_rw);
90495 }
90496
90497 int __weak module_finalize(const Elf_Ehdr *hdr,
90498@@ -2968,7 +3100,9 @@ int __weak module_finalize(const Elf_Ehdr *hdr,
90499 static int post_relocation(struct module *mod, const struct load_info *info)
90500 {
90501 /* Sort exception table now relocations are done. */
90502+ pax_open_kernel();
90503 sort_extable(mod->extable, mod->extable + mod->num_exentries);
90504+ pax_close_kernel();
90505
90506 /* Copy relocated percpu area over. */
90507 percpu_modcopy(mod, (void *)info->sechdrs[info->index.pcpu].sh_addr,
90508@@ -3077,11 +3211,12 @@ static int do_init_module(struct module *mod)
90509 mod->strtab = mod->core_strtab;
90510 #endif
90511 unset_module_init_ro_nx(mod);
90512- module_free(mod, mod->module_init);
90513- mod->module_init = NULL;
90514- mod->init_size = 0;
90515- mod->init_ro_size = 0;
90516- mod->init_text_size = 0;
90517+ module_free(mod, mod->module_init_rw);
90518+ module_free_exec(mod, mod->module_init_rx);
90519+ mod->module_init_rw = NULL;
90520+ mod->module_init_rx = NULL;
90521+ mod->init_size_rw = 0;
90522+ mod->init_size_rx = 0;
90523 mutex_unlock(&module_mutex);
90524 wake_up_all(&module_wq);
90525
90526@@ -3149,16 +3284,16 @@ static int complete_formation(struct module *mod, struct load_info *info)
90527 module_bug_finalize(info->hdr, info->sechdrs, mod);
90528
90529 /* Set RO and NX regions for core */
90530- set_section_ro_nx(mod->module_core,
90531- mod->core_text_size,
90532- mod->core_ro_size,
90533- mod->core_size);
90534+ set_section_ro_nx(mod->module_core_rx,
90535+ mod->core_size_rx,
90536+ mod->core_size_rx,
90537+ mod->core_size_rx);
90538
90539 /* Set RO and NX regions for init */
90540- set_section_ro_nx(mod->module_init,
90541- mod->init_text_size,
90542- mod->init_ro_size,
90543- mod->init_size);
90544+ set_section_ro_nx(mod->module_init_rx,
90545+ mod->init_size_rx,
90546+ mod->init_size_rx,
90547+ mod->init_size_rx);
90548
90549 /* Mark state as coming so strong_try_module_get() ignores us,
90550 * but kallsyms etc. can see us. */
90551@@ -3242,9 +3377,38 @@ static int load_module(struct load_info *info, const char __user *uargs,
90552 if (err)
90553 goto free_unload;
90554
90555+ /* Now copy in args */
90556+ mod->args = strndup_user(uargs, ~0UL >> 1);
90557+ if (IS_ERR(mod->args)) {
90558+ err = PTR_ERR(mod->args);
90559+ goto free_unload;
90560+ }
90561+
90562 /* Set up MODINFO_ATTR fields */
90563 setup_modinfo(mod, info);
90564
90565+#ifdef CONFIG_GRKERNSEC_MODHARDEN
90566+ {
90567+ char *p, *p2;
90568+
90569+ if (strstr(mod->args, "grsec_modharden_netdev")) {
90570+ 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);
90571+ err = -EPERM;
90572+ goto free_modinfo;
90573+ } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
90574+ p += sizeof("grsec_modharden_normal") - 1;
90575+ p2 = strstr(p, "_");
90576+ if (p2) {
90577+ *p2 = '\0';
90578+ printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
90579+ *p2 = '_';
90580+ }
90581+ err = -EPERM;
90582+ goto free_modinfo;
90583+ }
90584+ }
90585+#endif
90586+
90587 /* Fix up syms, so that st_value is a pointer to location. */
90588 err = simplify_symbols(mod, info);
90589 if (err < 0)
90590@@ -3260,13 +3424,6 @@ static int load_module(struct load_info *info, const char __user *uargs,
90591
90592 flush_module_icache(mod);
90593
90594- /* Now copy in args */
90595- mod->args = strndup_user(uargs, ~0UL >> 1);
90596- if (IS_ERR(mod->args)) {
90597- err = PTR_ERR(mod->args);
90598- goto free_arch_cleanup;
90599- }
90600-
90601 dynamic_debug_setup(info->debug, info->num_debug);
90602
90603 /* Ftrace init must be called in the MODULE_STATE_UNFORMED state */
90604@@ -3314,11 +3471,10 @@ static int load_module(struct load_info *info, const char __user *uargs,
90605 ddebug_cleanup:
90606 dynamic_debug_remove(info->debug);
90607 synchronize_sched();
90608- kfree(mod->args);
90609- free_arch_cleanup:
90610 module_arch_cleanup(mod);
90611 free_modinfo:
90612 free_modinfo(mod);
90613+ kfree(mod->args);
90614 free_unload:
90615 module_unload_free(mod);
90616 unlink_mod:
90617@@ -3403,10 +3559,16 @@ static const char *get_ksymbol(struct module *mod,
90618 unsigned long nextval;
90619
90620 /* At worse, next value is at end of module */
90621- if (within_module_init(addr, mod))
90622- nextval = (unsigned long)mod->module_init+mod->init_text_size;
90623+ if (within_module_init_rx(addr, mod))
90624+ nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
90625+ else if (within_module_init_rw(addr, mod))
90626+ nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
90627+ else if (within_module_core_rx(addr, mod))
90628+ nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
90629+ else if (within_module_core_rw(addr, mod))
90630+ nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
90631 else
90632- nextval = (unsigned long)mod->module_core+mod->core_text_size;
90633+ return NULL;
90634
90635 /* Scan for closest preceding symbol, and next symbol. (ELF
90636 starts real symbols at 1). */
90637@@ -3654,7 +3816,7 @@ static int m_show(struct seq_file *m, void *p)
90638 return 0;
90639
90640 seq_printf(m, "%s %u",
90641- mod->name, mod->init_size + mod->core_size);
90642+ mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
90643 print_unload_info(m, mod);
90644
90645 /* Informative for users. */
90646@@ -3663,7 +3825,7 @@ static int m_show(struct seq_file *m, void *p)
90647 mod->state == MODULE_STATE_COMING ? "Loading":
90648 "Live");
90649 /* Used by oprofile and other similar tools. */
90650- seq_printf(m, " 0x%pK", mod->module_core);
90651+ seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
90652
90653 /* Taints info */
90654 if (mod->taints)
90655@@ -3699,7 +3861,17 @@ static const struct file_operations proc_modules_operations = {
90656
90657 static int __init proc_modules_init(void)
90658 {
90659+#ifndef CONFIG_GRKERNSEC_HIDESYM
90660+#ifdef CONFIG_GRKERNSEC_PROC_USER
90661+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
90662+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
90663+ proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
90664+#else
90665 proc_create("modules", 0, NULL, &proc_modules_operations);
90666+#endif
90667+#else
90668+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
90669+#endif
90670 return 0;
90671 }
90672 module_init(proc_modules_init);
90673@@ -3760,7 +3932,8 @@ struct module *__module_address(unsigned long addr)
90674 {
90675 struct module *mod;
90676
90677- if (addr < module_addr_min || addr > module_addr_max)
90678+ if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
90679+ (addr < module_addr_min_rw || addr > module_addr_max_rw))
90680 return NULL;
90681
90682 list_for_each_entry_rcu(mod, &modules, list) {
90683@@ -3801,11 +3974,20 @@ bool is_module_text_address(unsigned long addr)
90684 */
90685 struct module *__module_text_address(unsigned long addr)
90686 {
90687- struct module *mod = __module_address(addr);
90688+ struct module *mod;
90689+
90690+#ifdef CONFIG_X86_32
90691+ addr = ktla_ktva(addr);
90692+#endif
90693+
90694+ if (addr < module_addr_min_rx || addr > module_addr_max_rx)
90695+ return NULL;
90696+
90697+ mod = __module_address(addr);
90698+
90699 if (mod) {
90700 /* Make sure it's within the text section. */
90701- if (!within(addr, mod->module_init, mod->init_text_size)
90702- && !within(addr, mod->module_core, mod->core_text_size))
90703+ if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
90704 mod = NULL;
90705 }
90706 return mod;
90707diff --git a/kernel/notifier.c b/kernel/notifier.c
90708index 4803da6..1c5eea6 100644
90709--- a/kernel/notifier.c
90710+++ b/kernel/notifier.c
90711@@ -5,6 +5,7 @@
90712 #include <linux/rcupdate.h>
90713 #include <linux/vmalloc.h>
90714 #include <linux/reboot.h>
90715+#include <linux/mm.h>
90716
90717 /*
90718 * Notifier list for kernel code which wants to be called
90719@@ -24,10 +25,12 @@ static int notifier_chain_register(struct notifier_block **nl,
90720 while ((*nl) != NULL) {
90721 if (n->priority > (*nl)->priority)
90722 break;
90723- nl = &((*nl)->next);
90724+ nl = (struct notifier_block **)&((*nl)->next);
90725 }
90726- n->next = *nl;
90727+ pax_open_kernel();
90728+ *(const void **)&n->next = *nl;
90729 rcu_assign_pointer(*nl, n);
90730+ pax_close_kernel();
90731 return 0;
90732 }
90733
90734@@ -39,10 +42,12 @@ static int notifier_chain_cond_register(struct notifier_block **nl,
90735 return 0;
90736 if (n->priority > (*nl)->priority)
90737 break;
90738- nl = &((*nl)->next);
90739+ nl = (struct notifier_block **)&((*nl)->next);
90740 }
90741- n->next = *nl;
90742+ pax_open_kernel();
90743+ *(const void **)&n->next = *nl;
90744 rcu_assign_pointer(*nl, n);
90745+ pax_close_kernel();
90746 return 0;
90747 }
90748
90749@@ -51,10 +56,12 @@ static int notifier_chain_unregister(struct notifier_block **nl,
90750 {
90751 while ((*nl) != NULL) {
90752 if ((*nl) == n) {
90753+ pax_open_kernel();
90754 rcu_assign_pointer(*nl, n->next);
90755+ pax_close_kernel();
90756 return 0;
90757 }
90758- nl = &((*nl)->next);
90759+ nl = (struct notifier_block **)&((*nl)->next);
90760 }
90761 return -ENOENT;
90762 }
90763diff --git a/kernel/padata.c b/kernel/padata.c
90764index 161402f..598814c 100644
90765--- a/kernel/padata.c
90766+++ b/kernel/padata.c
90767@@ -54,7 +54,7 @@ static int padata_cpu_hash(struct parallel_data *pd)
90768 * seq_nr mod. number of cpus in use.
90769 */
90770
90771- seq_nr = atomic_inc_return(&pd->seq_nr);
90772+ seq_nr = atomic_inc_return_unchecked(&pd->seq_nr);
90773 cpu_index = seq_nr % cpumask_weight(pd->cpumask.pcpu);
90774
90775 return padata_index_to_cpu(pd, cpu_index);
90776@@ -428,7 +428,7 @@ static struct parallel_data *padata_alloc_pd(struct padata_instance *pinst,
90777 padata_init_pqueues(pd);
90778 padata_init_squeues(pd);
90779 setup_timer(&pd->timer, padata_reorder_timer, (unsigned long)pd);
90780- atomic_set(&pd->seq_nr, -1);
90781+ atomic_set_unchecked(&pd->seq_nr, -1);
90782 atomic_set(&pd->reorder_objects, 0);
90783 atomic_set(&pd->refcnt, 0);
90784 pd->pinst = pinst;
90785diff --git a/kernel/panic.c b/kernel/panic.c
90786index cf80672..f6771b2 100644
90787--- a/kernel/panic.c
90788+++ b/kernel/panic.c
90789@@ -53,7 +53,7 @@ EXPORT_SYMBOL(panic_blink);
90790 /*
90791 * Stop ourself in panic -- architecture code may override this
90792 */
90793-void __weak panic_smp_self_stop(void)
90794+void __weak __noreturn panic_smp_self_stop(void)
90795 {
90796 while (1)
90797 cpu_relax();
90798@@ -422,7 +422,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
90799 disable_trace_on_warning();
90800
90801 pr_warn("------------[ cut here ]------------\n");
90802- pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pS()\n",
90803+ pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pA()\n",
90804 raw_smp_processor_id(), current->pid, file, line, caller);
90805
90806 if (args)
90807@@ -476,7 +476,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
90808 */
90809 __visible void __stack_chk_fail(void)
90810 {
90811- panic("stack-protector: Kernel stack is corrupted in: %p\n",
90812+ dump_stack();
90813+ panic("stack-protector: Kernel stack is corrupted in: %pA\n",
90814 __builtin_return_address(0));
90815 }
90816 EXPORT_SYMBOL(__stack_chk_fail);
90817diff --git a/kernel/pid.c b/kernel/pid.c
90818index 82430c8..53d7793 100644
90819--- a/kernel/pid.c
90820+++ b/kernel/pid.c
90821@@ -33,6 +33,7 @@
90822 #include <linux/rculist.h>
90823 #include <linux/bootmem.h>
90824 #include <linux/hash.h>
90825+#include <linux/security.h>
90826 #include <linux/pid_namespace.h>
90827 #include <linux/init_task.h>
90828 #include <linux/syscalls.h>
90829@@ -47,7 +48,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
90830
90831 int pid_max = PID_MAX_DEFAULT;
90832
90833-#define RESERVED_PIDS 300
90834+#define RESERVED_PIDS 500
90835
90836 int pid_max_min = RESERVED_PIDS + 1;
90837 int pid_max_max = PID_MAX_LIMIT;
90838@@ -447,10 +448,18 @@ EXPORT_SYMBOL(pid_task);
90839 */
90840 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
90841 {
90842+ struct task_struct *task;
90843+
90844 rcu_lockdep_assert(rcu_read_lock_held(),
90845 "find_task_by_pid_ns() needs rcu_read_lock()"
90846 " protection");
90847- return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
90848+
90849+ task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
90850+
90851+ if (gr_pid_is_chrooted(task))
90852+ return NULL;
90853+
90854+ return task;
90855 }
90856
90857 struct task_struct *find_task_by_vpid(pid_t vnr)
90858@@ -458,6 +467,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
90859 return find_task_by_pid_ns(vnr, task_active_pid_ns(current));
90860 }
90861
90862+struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
90863+{
90864+ rcu_lockdep_assert(rcu_read_lock_held(),
90865+ "find_task_by_pid_ns() needs rcu_read_lock()"
90866+ " protection");
90867+ return pid_task(find_pid_ns(vnr, task_active_pid_ns(current)), PIDTYPE_PID);
90868+}
90869+
90870 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
90871 {
90872 struct pid *pid;
90873diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c
90874index db95d8e..a0ca23f 100644
90875--- a/kernel/pid_namespace.c
90876+++ b/kernel/pid_namespace.c
90877@@ -253,7 +253,7 @@ static int pid_ns_ctl_handler(struct ctl_table *table, int write,
90878 void __user *buffer, size_t *lenp, loff_t *ppos)
90879 {
90880 struct pid_namespace *pid_ns = task_active_pid_ns(current);
90881- struct ctl_table tmp = *table;
90882+ ctl_table_no_const tmp = *table;
90883
90884 if (write && !ns_capable(pid_ns->user_ns, CAP_SYS_ADMIN))
90885 return -EPERM;
90886diff --git a/kernel/power/Kconfig b/kernel/power/Kconfig
90887index bbef57f..5f94462 100644
90888--- a/kernel/power/Kconfig
90889+++ b/kernel/power/Kconfig
90890@@ -24,6 +24,8 @@ config HIBERNATE_CALLBACKS
90891 config HIBERNATION
90892 bool "Hibernation (aka 'suspend to disk')"
90893 depends on SWAP && ARCH_HIBERNATION_POSSIBLE
90894+ depends on !GRKERNSEC_KMEM
90895+ depends on !PAX_MEMORY_SANITIZE
90896 select HIBERNATE_CALLBACKS
90897 select LZO_COMPRESS
90898 select LZO_DECOMPRESS
90899diff --git a/kernel/power/process.c b/kernel/power/process.c
90900index 5a6ec86..3a8c884 100644
90901--- a/kernel/power/process.c
90902+++ b/kernel/power/process.c
90903@@ -35,6 +35,7 @@ static int try_to_freeze_tasks(bool user_only)
90904 unsigned int elapsed_msecs;
90905 bool wakeup = false;
90906 int sleep_usecs = USEC_PER_MSEC;
90907+ bool timedout = false;
90908
90909 do_gettimeofday(&start);
90910
90911@@ -45,13 +46,20 @@ static int try_to_freeze_tasks(bool user_only)
90912
90913 while (true) {
90914 todo = 0;
90915+ if (time_after(jiffies, end_time))
90916+ timedout = true;
90917 read_lock(&tasklist_lock);
90918 for_each_process_thread(g, p) {
90919 if (p == current || !freeze_task(p))
90920 continue;
90921
90922- if (!freezer_should_skip(p))
90923+ if (!freezer_should_skip(p)) {
90924 todo++;
90925+ if (timedout) {
90926+ printk(KERN_ERR "Task refusing to freeze:\n");
90927+ sched_show_task(p);
90928+ }
90929+ }
90930 }
90931 read_unlock(&tasklist_lock);
90932
90933@@ -60,7 +68,7 @@ static int try_to_freeze_tasks(bool user_only)
90934 todo += wq_busy;
90935 }
90936
90937- if (!todo || time_after(jiffies, end_time))
90938+ if (!todo || timedout)
90939 break;
90940
90941 if (pm_wakeup_pending()) {
90942diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
90943index ced2b84..ffc4791 100644
90944--- a/kernel/printk/printk.c
90945+++ b/kernel/printk/printk.c
90946@@ -489,6 +489,11 @@ static int check_syslog_permissions(int type, bool from_file)
90947 if (from_file && type != SYSLOG_ACTION_OPEN)
90948 return 0;
90949
90950+#ifdef CONFIG_GRKERNSEC_DMESG
90951+ if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
90952+ return -EPERM;
90953+#endif
90954+
90955 if (syslog_action_restricted(type)) {
90956 if (capable(CAP_SYSLOG))
90957 return 0;
90958diff --git a/kernel/profile.c b/kernel/profile.c
90959index 54bf5ba..df6e0a2 100644
90960--- a/kernel/profile.c
90961+++ b/kernel/profile.c
90962@@ -37,7 +37,7 @@ struct profile_hit {
90963 #define NR_PROFILE_HIT (PAGE_SIZE/sizeof(struct profile_hit))
90964 #define NR_PROFILE_GRP (NR_PROFILE_HIT/PROFILE_GRPSZ)
90965
90966-static atomic_t *prof_buffer;
90967+static atomic_unchecked_t *prof_buffer;
90968 static unsigned long prof_len, prof_shift;
90969
90970 int prof_on __read_mostly;
90971@@ -256,7 +256,7 @@ static void profile_flip_buffers(void)
90972 hits[i].pc = 0;
90973 continue;
90974 }
90975- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
90976+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
90977 hits[i].hits = hits[i].pc = 0;
90978 }
90979 }
90980@@ -317,9 +317,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
90981 * Add the current hit(s) and flush the write-queue out
90982 * to the global buffer:
90983 */
90984- atomic_add(nr_hits, &prof_buffer[pc]);
90985+ atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
90986 for (i = 0; i < NR_PROFILE_HIT; ++i) {
90987- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
90988+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
90989 hits[i].pc = hits[i].hits = 0;
90990 }
90991 out:
90992@@ -394,7 +394,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
90993 {
90994 unsigned long pc;
90995 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
90996- atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
90997+ atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
90998 }
90999 #endif /* !CONFIG_SMP */
91000
91001@@ -490,7 +490,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
91002 return -EFAULT;
91003 buf++; p++; count--; read++;
91004 }
91005- pnt = (char *)prof_buffer + p - sizeof(atomic_t);
91006+ pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
91007 if (copy_to_user(buf, (void *)pnt, count))
91008 return -EFAULT;
91009 read += count;
91010@@ -521,7 +521,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
91011 }
91012 #endif
91013 profile_discard_flip_buffers();
91014- memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
91015+ memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
91016 return count;
91017 }
91018
91019diff --git a/kernel/ptrace.c b/kernel/ptrace.c
91020index 54e7522..5b82dd6 100644
91021--- a/kernel/ptrace.c
91022+++ b/kernel/ptrace.c
91023@@ -321,7 +321,7 @@ static int ptrace_attach(struct task_struct *task, long request,
91024 if (seize)
91025 flags |= PT_SEIZED;
91026 rcu_read_lock();
91027- if (ns_capable(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
91028+ if (ns_capable_nolog(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
91029 flags |= PT_PTRACE_CAP;
91030 rcu_read_unlock();
91031 task->ptrace = flags;
91032@@ -532,7 +532,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
91033 break;
91034 return -EIO;
91035 }
91036- if (copy_to_user(dst, buf, retval))
91037+ if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
91038 return -EFAULT;
91039 copied += retval;
91040 src += retval;
91041@@ -800,7 +800,7 @@ int ptrace_request(struct task_struct *child, long request,
91042 bool seized = child->ptrace & PT_SEIZED;
91043 int ret = -EIO;
91044 siginfo_t siginfo, *si;
91045- void __user *datavp = (void __user *) data;
91046+ void __user *datavp = (__force void __user *) data;
91047 unsigned long __user *datalp = datavp;
91048 unsigned long flags;
91049
91050@@ -1046,14 +1046,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
91051 goto out;
91052 }
91053
91054+ if (gr_handle_ptrace(child, request)) {
91055+ ret = -EPERM;
91056+ goto out_put_task_struct;
91057+ }
91058+
91059 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
91060 ret = ptrace_attach(child, request, addr, data);
91061 /*
91062 * Some architectures need to do book-keeping after
91063 * a ptrace attach.
91064 */
91065- if (!ret)
91066+ if (!ret) {
91067 arch_ptrace_attach(child);
91068+ gr_audit_ptrace(child);
91069+ }
91070 goto out_put_task_struct;
91071 }
91072
91073@@ -1081,7 +1088,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
91074 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
91075 if (copied != sizeof(tmp))
91076 return -EIO;
91077- return put_user(tmp, (unsigned long __user *)data);
91078+ return put_user(tmp, (__force unsigned long __user *)data);
91079 }
91080
91081 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
91082@@ -1175,7 +1182,7 @@ int compat_ptrace_request(struct task_struct *child, compat_long_t request,
91083 }
91084
91085 COMPAT_SYSCALL_DEFINE4(ptrace, compat_long_t, request, compat_long_t, pid,
91086- compat_long_t, addr, compat_long_t, data)
91087+ compat_ulong_t, addr, compat_ulong_t, data)
91088 {
91089 struct task_struct *child;
91090 long ret;
91091@@ -1191,14 +1198,21 @@ COMPAT_SYSCALL_DEFINE4(ptrace, compat_long_t, request, compat_long_t, pid,
91092 goto out;
91093 }
91094
91095+ if (gr_handle_ptrace(child, request)) {
91096+ ret = -EPERM;
91097+ goto out_put_task_struct;
91098+ }
91099+
91100 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
91101 ret = ptrace_attach(child, request, addr, data);
91102 /*
91103 * Some architectures need to do book-keeping after
91104 * a ptrace attach.
91105 */
91106- if (!ret)
91107+ if (!ret) {
91108 arch_ptrace_attach(child);
91109+ gr_audit_ptrace(child);
91110+ }
91111 goto out_put_task_struct;
91112 }
91113
91114diff --git a/kernel/rcu/rcutorture.c b/kernel/rcu/rcutorture.c
91115index 240fa90..5fa56bd 100644
91116--- a/kernel/rcu/rcutorture.c
91117+++ b/kernel/rcu/rcutorture.c
91118@@ -134,12 +134,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1],
91119 rcu_torture_count) = { 0 };
91120 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1],
91121 rcu_torture_batch) = { 0 };
91122-static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
91123-static atomic_t n_rcu_torture_alloc;
91124-static atomic_t n_rcu_torture_alloc_fail;
91125-static atomic_t n_rcu_torture_free;
91126-static atomic_t n_rcu_torture_mberror;
91127-static atomic_t n_rcu_torture_error;
91128+static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
91129+static atomic_unchecked_t n_rcu_torture_alloc;
91130+static atomic_unchecked_t n_rcu_torture_alloc_fail;
91131+static atomic_unchecked_t n_rcu_torture_free;
91132+static atomic_unchecked_t n_rcu_torture_mberror;
91133+static atomic_unchecked_t n_rcu_torture_error;
91134 static long n_rcu_torture_barrier_error;
91135 static long n_rcu_torture_boost_ktrerror;
91136 static long n_rcu_torture_boost_rterror;
91137@@ -148,7 +148,7 @@ static long n_rcu_torture_boosts;
91138 static long n_rcu_torture_timers;
91139 static long n_barrier_attempts;
91140 static long n_barrier_successes;
91141-static atomic_long_t n_cbfloods;
91142+static atomic_long_unchecked_t n_cbfloods;
91143 static struct list_head rcu_torture_removed;
91144
91145 static int rcu_torture_writer_state;
91146@@ -211,11 +211,11 @@ rcu_torture_alloc(void)
91147
91148 spin_lock_bh(&rcu_torture_lock);
91149 if (list_empty(&rcu_torture_freelist)) {
91150- atomic_inc(&n_rcu_torture_alloc_fail);
91151+ atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
91152 spin_unlock_bh(&rcu_torture_lock);
91153 return NULL;
91154 }
91155- atomic_inc(&n_rcu_torture_alloc);
91156+ atomic_inc_unchecked(&n_rcu_torture_alloc);
91157 p = rcu_torture_freelist.next;
91158 list_del_init(p);
91159 spin_unlock_bh(&rcu_torture_lock);
91160@@ -228,7 +228,7 @@ rcu_torture_alloc(void)
91161 static void
91162 rcu_torture_free(struct rcu_torture *p)
91163 {
91164- atomic_inc(&n_rcu_torture_free);
91165+ atomic_inc_unchecked(&n_rcu_torture_free);
91166 spin_lock_bh(&rcu_torture_lock);
91167 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
91168 spin_unlock_bh(&rcu_torture_lock);
91169@@ -312,7 +312,7 @@ rcu_torture_pipe_update_one(struct rcu_torture *rp)
91170 i = rp->rtort_pipe_count;
91171 if (i > RCU_TORTURE_PIPE_LEN)
91172 i = RCU_TORTURE_PIPE_LEN;
91173- atomic_inc(&rcu_torture_wcount[i]);
91174+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
91175 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
91176 rp->rtort_mbtest = 0;
91177 return true;
91178@@ -799,7 +799,7 @@ rcu_torture_cbflood(void *arg)
91179 VERBOSE_TOROUT_STRING("rcu_torture_cbflood task started");
91180 do {
91181 schedule_timeout_interruptible(cbflood_inter_holdoff);
91182- atomic_long_inc(&n_cbfloods);
91183+ atomic_long_inc_unchecked(&n_cbfloods);
91184 WARN_ON(signal_pending(current));
91185 for (i = 0; i < cbflood_n_burst; i++) {
91186 for (j = 0; j < cbflood_n_per_burst; j++) {
91187@@ -917,7 +917,7 @@ rcu_torture_writer(void *arg)
91188 i = old_rp->rtort_pipe_count;
91189 if (i > RCU_TORTURE_PIPE_LEN)
91190 i = RCU_TORTURE_PIPE_LEN;
91191- atomic_inc(&rcu_torture_wcount[i]);
91192+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
91193 old_rp->rtort_pipe_count++;
91194 switch (synctype[torture_random(&rand) % nsynctypes]) {
91195 case RTWS_DEF_FREE:
91196@@ -1035,7 +1035,7 @@ static void rcu_torture_timer(unsigned long unused)
91197 return;
91198 }
91199 if (p->rtort_mbtest == 0)
91200- atomic_inc(&n_rcu_torture_mberror);
91201+ atomic_inc_unchecked(&n_rcu_torture_mberror);
91202 spin_lock(&rand_lock);
91203 cur_ops->read_delay(&rand);
91204 n_rcu_torture_timers++;
91205@@ -1105,7 +1105,7 @@ rcu_torture_reader(void *arg)
91206 continue;
91207 }
91208 if (p->rtort_mbtest == 0)
91209- atomic_inc(&n_rcu_torture_mberror);
91210+ atomic_inc_unchecked(&n_rcu_torture_mberror);
91211 cur_ops->read_delay(&rand);
91212 preempt_disable();
91213 pipe_count = p->rtort_pipe_count;
91214@@ -1172,11 +1172,11 @@ rcu_torture_stats_print(void)
91215 rcu_torture_current,
91216 rcu_torture_current_version,
91217 list_empty(&rcu_torture_freelist),
91218- atomic_read(&n_rcu_torture_alloc),
91219- atomic_read(&n_rcu_torture_alloc_fail),
91220- atomic_read(&n_rcu_torture_free));
91221+ atomic_read_unchecked(&n_rcu_torture_alloc),
91222+ atomic_read_unchecked(&n_rcu_torture_alloc_fail),
91223+ atomic_read_unchecked(&n_rcu_torture_free));
91224 pr_cont("rtmbe: %d rtbke: %ld rtbre: %ld ",
91225- atomic_read(&n_rcu_torture_mberror),
91226+ atomic_read_unchecked(&n_rcu_torture_mberror),
91227 n_rcu_torture_boost_ktrerror,
91228 n_rcu_torture_boost_rterror);
91229 pr_cont("rtbf: %ld rtb: %ld nt: %ld ",
91230@@ -1188,17 +1188,17 @@ rcu_torture_stats_print(void)
91231 n_barrier_successes,
91232 n_barrier_attempts,
91233 n_rcu_torture_barrier_error);
91234- pr_cont("cbflood: %ld\n", atomic_long_read(&n_cbfloods));
91235+ pr_cont("cbflood: %ld\n", atomic_long_read_unchecked(&n_cbfloods));
91236
91237 pr_alert("%s%s ", torture_type, TORTURE_FLAG);
91238- if (atomic_read(&n_rcu_torture_mberror) != 0 ||
91239+ if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
91240 n_rcu_torture_barrier_error != 0 ||
91241 n_rcu_torture_boost_ktrerror != 0 ||
91242 n_rcu_torture_boost_rterror != 0 ||
91243 n_rcu_torture_boost_failure != 0 ||
91244 i > 1) {
91245 pr_cont("%s", "!!! ");
91246- atomic_inc(&n_rcu_torture_error);
91247+ atomic_inc_unchecked(&n_rcu_torture_error);
91248 WARN_ON_ONCE(1);
91249 }
91250 pr_cont("Reader Pipe: ");
91251@@ -1215,7 +1215,7 @@ rcu_torture_stats_print(void)
91252 pr_alert("%s%s ", torture_type, TORTURE_FLAG);
91253 pr_cont("Free-Block Circulation: ");
91254 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
91255- pr_cont(" %d", atomic_read(&rcu_torture_wcount[i]));
91256+ pr_cont(" %d", atomic_read_unchecked(&rcu_torture_wcount[i]));
91257 }
91258 pr_cont("\n");
91259
91260@@ -1559,7 +1559,7 @@ rcu_torture_cleanup(void)
91261
91262 rcu_torture_stats_print(); /* -After- the stats thread is stopped! */
91263
91264- if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
91265+ if (atomic_read_unchecked(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
91266 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
91267 else if (torture_onoff_failures())
91268 rcu_torture_print_module_parms(cur_ops,
91269@@ -1684,18 +1684,18 @@ rcu_torture_init(void)
91270
91271 rcu_torture_current = NULL;
91272 rcu_torture_current_version = 0;
91273- atomic_set(&n_rcu_torture_alloc, 0);
91274- atomic_set(&n_rcu_torture_alloc_fail, 0);
91275- atomic_set(&n_rcu_torture_free, 0);
91276- atomic_set(&n_rcu_torture_mberror, 0);
91277- atomic_set(&n_rcu_torture_error, 0);
91278+ atomic_set_unchecked(&n_rcu_torture_alloc, 0);
91279+ atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
91280+ atomic_set_unchecked(&n_rcu_torture_free, 0);
91281+ atomic_set_unchecked(&n_rcu_torture_mberror, 0);
91282+ atomic_set_unchecked(&n_rcu_torture_error, 0);
91283 n_rcu_torture_barrier_error = 0;
91284 n_rcu_torture_boost_ktrerror = 0;
91285 n_rcu_torture_boost_rterror = 0;
91286 n_rcu_torture_boost_failure = 0;
91287 n_rcu_torture_boosts = 0;
91288 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
91289- atomic_set(&rcu_torture_wcount[i], 0);
91290+ atomic_set_unchecked(&rcu_torture_wcount[i], 0);
91291 for_each_possible_cpu(cpu) {
91292 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
91293 per_cpu(rcu_torture_count, cpu)[i] = 0;
91294diff --git a/kernel/rcu/tiny.c b/kernel/rcu/tiny.c
91295index c0623fc..329c091 100644
91296--- a/kernel/rcu/tiny.c
91297+++ b/kernel/rcu/tiny.c
91298@@ -42,7 +42,7 @@
91299 /* Forward declarations for tiny_plugin.h. */
91300 struct rcu_ctrlblk;
91301 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
91302-static void rcu_process_callbacks(struct softirq_action *unused);
91303+static void rcu_process_callbacks(void);
91304 static void __call_rcu(struct rcu_head *head,
91305 void (*func)(struct rcu_head *rcu),
91306 struct rcu_ctrlblk *rcp);
91307@@ -310,7 +310,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
91308 false));
91309 }
91310
91311-static void rcu_process_callbacks(struct softirq_action *unused)
91312+static __latent_entropy void rcu_process_callbacks(void)
91313 {
91314 __rcu_process_callbacks(&rcu_sched_ctrlblk);
91315 __rcu_process_callbacks(&rcu_bh_ctrlblk);
91316diff --git a/kernel/rcu/tiny_plugin.h b/kernel/rcu/tiny_plugin.h
91317index 858c565..7efd915 100644
91318--- a/kernel/rcu/tiny_plugin.h
91319+++ b/kernel/rcu/tiny_plugin.h
91320@@ -152,17 +152,17 @@ static void check_cpu_stall(struct rcu_ctrlblk *rcp)
91321 dump_stack();
91322 }
91323 if (*rcp->curtail && ULONG_CMP_GE(j, js))
91324- ACCESS_ONCE(rcp->jiffies_stall) = jiffies +
91325+ ACCESS_ONCE_RW(rcp->jiffies_stall) = jiffies +
91326 3 * rcu_jiffies_till_stall_check() + 3;
91327 else if (ULONG_CMP_GE(j, js))
91328- ACCESS_ONCE(rcp->jiffies_stall) = jiffies + rcu_jiffies_till_stall_check();
91329+ ACCESS_ONCE_RW(rcp->jiffies_stall) = jiffies + rcu_jiffies_till_stall_check();
91330 }
91331
91332 static void reset_cpu_stall_ticks(struct rcu_ctrlblk *rcp)
91333 {
91334 rcp->ticks_this_gp = 0;
91335 rcp->gp_start = jiffies;
91336- ACCESS_ONCE(rcp->jiffies_stall) = jiffies + rcu_jiffies_till_stall_check();
91337+ ACCESS_ONCE_RW(rcp->jiffies_stall) = jiffies + rcu_jiffies_till_stall_check();
91338 }
91339
91340 static void check_cpu_stalls(void)
91341diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c
91342index 9815447..2cdf92a 100644
91343--- a/kernel/rcu/tree.c
91344+++ b/kernel/rcu/tree.c
91345@@ -274,7 +274,7 @@ static void rcu_momentary_dyntick_idle(void)
91346 */
91347 rdtp = this_cpu_ptr(&rcu_dynticks);
91348 smp_mb__before_atomic(); /* Earlier stuff before QS. */
91349- atomic_add(2, &rdtp->dynticks); /* QS. */
91350+ atomic_add_unchecked(2, &rdtp->dynticks); /* QS. */
91351 smp_mb__after_atomic(); /* Later stuff after QS. */
91352 break;
91353 }
91354@@ -534,9 +534,9 @@ static void rcu_eqs_enter_common(struct rcu_dynticks *rdtp, long long oldval,
91355 rcu_prepare_for_idle(smp_processor_id());
91356 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
91357 smp_mb__before_atomic(); /* See above. */
91358- atomic_inc(&rdtp->dynticks);
91359+ atomic_inc_unchecked(&rdtp->dynticks);
91360 smp_mb__after_atomic(); /* Force ordering with next sojourn. */
91361- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
91362+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
91363 rcu_dynticks_task_enter();
91364
91365 /*
91366@@ -656,10 +656,10 @@ static void rcu_eqs_exit_common(struct rcu_dynticks *rdtp, long long oldval,
91367 {
91368 rcu_dynticks_task_exit();
91369 smp_mb__before_atomic(); /* Force ordering w/previous sojourn. */
91370- atomic_inc(&rdtp->dynticks);
91371+ atomic_inc_unchecked(&rdtp->dynticks);
91372 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
91373 smp_mb__after_atomic(); /* See above. */
91374- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
91375+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
91376 rcu_cleanup_after_idle(smp_processor_id());
91377 trace_rcu_dyntick(TPS("End"), oldval, rdtp->dynticks_nesting);
91378 if (!user && !is_idle_task(current)) {
91379@@ -780,14 +780,14 @@ void rcu_nmi_enter(void)
91380 struct rcu_dynticks *rdtp = this_cpu_ptr(&rcu_dynticks);
91381
91382 if (rdtp->dynticks_nmi_nesting == 0 &&
91383- (atomic_read(&rdtp->dynticks) & 0x1))
91384+ (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
91385 return;
91386 rdtp->dynticks_nmi_nesting++;
91387 smp_mb__before_atomic(); /* Force delay from prior write. */
91388- atomic_inc(&rdtp->dynticks);
91389+ atomic_inc_unchecked(&rdtp->dynticks);
91390 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
91391 smp_mb__after_atomic(); /* See above. */
91392- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
91393+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
91394 }
91395
91396 /**
91397@@ -806,9 +806,9 @@ void rcu_nmi_exit(void)
91398 return;
91399 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
91400 smp_mb__before_atomic(); /* See above. */
91401- atomic_inc(&rdtp->dynticks);
91402+ atomic_inc_unchecked(&rdtp->dynticks);
91403 smp_mb__after_atomic(); /* Force delay to next write. */
91404- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
91405+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
91406 }
91407
91408 /**
91409@@ -821,7 +821,7 @@ void rcu_nmi_exit(void)
91410 */
91411 bool notrace __rcu_is_watching(void)
91412 {
91413- return atomic_read(this_cpu_ptr(&rcu_dynticks.dynticks)) & 0x1;
91414+ return atomic_read_unchecked(this_cpu_ptr(&rcu_dynticks.dynticks)) & 0x1;
91415 }
91416
91417 /**
91418@@ -904,7 +904,7 @@ static int rcu_is_cpu_rrupt_from_idle(void)
91419 static int dyntick_save_progress_counter(struct rcu_data *rdp,
91420 bool *isidle, unsigned long *maxj)
91421 {
91422- rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
91423+ rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
91424 rcu_sysidle_check_cpu(rdp, isidle, maxj);
91425 if ((rdp->dynticks_snap & 0x1) == 0) {
91426 trace_rcu_fqs(rdp->rsp->name, rdp->gpnum, rdp->cpu, TPS("dti"));
91427@@ -933,7 +933,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp,
91428 int *rcrmp;
91429 unsigned int snap;
91430
91431- curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
91432+ curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
91433 snap = (unsigned int)rdp->dynticks_snap;
91434
91435 /*
91436@@ -996,10 +996,10 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp,
91437 rdp->rsp->gp_start + jiffies_till_sched_qs) ||
91438 ULONG_CMP_GE(jiffies, rdp->rsp->jiffies_resched)) {
91439 if (!(ACCESS_ONCE(*rcrmp) & rdp->rsp->flavor_mask)) {
91440- ACCESS_ONCE(rdp->cond_resched_completed) =
91441+ ACCESS_ONCE_RW(rdp->cond_resched_completed) =
91442 ACCESS_ONCE(rdp->mynode->completed);
91443 smp_mb(); /* ->cond_resched_completed before *rcrmp. */
91444- ACCESS_ONCE(*rcrmp) =
91445+ ACCESS_ONCE_RW(*rcrmp) =
91446 ACCESS_ONCE(*rcrmp) + rdp->rsp->flavor_mask;
91447 resched_cpu(rdp->cpu); /* Force CPU into scheduler. */
91448 rdp->rsp->jiffies_resched += 5; /* Enable beating. */
91449@@ -1021,7 +1021,7 @@ static void record_gp_stall_check_time(struct rcu_state *rsp)
91450 rsp->gp_start = j;
91451 smp_wmb(); /* Record start time before stall time. */
91452 j1 = rcu_jiffies_till_stall_check();
91453- ACCESS_ONCE(rsp->jiffies_stall) = j + j1;
91454+ ACCESS_ONCE_RW(rsp->jiffies_stall) = j + j1;
91455 rsp->jiffies_resched = j + j1 / 2;
91456 }
91457
91458@@ -1062,7 +1062,7 @@ static void print_other_cpu_stall(struct rcu_state *rsp)
91459 raw_spin_unlock_irqrestore(&rnp->lock, flags);
91460 return;
91461 }
91462- ACCESS_ONCE(rsp->jiffies_stall) = jiffies + 3 * rcu_jiffies_till_stall_check() + 3;
91463+ ACCESS_ONCE_RW(rsp->jiffies_stall) = jiffies + 3 * rcu_jiffies_till_stall_check() + 3;
91464 raw_spin_unlock_irqrestore(&rnp->lock, flags);
91465
91466 /*
91467@@ -1139,7 +1139,7 @@ static void print_cpu_stall(struct rcu_state *rsp)
91468
91469 raw_spin_lock_irqsave(&rnp->lock, flags);
91470 if (ULONG_CMP_GE(jiffies, ACCESS_ONCE(rsp->jiffies_stall)))
91471- ACCESS_ONCE(rsp->jiffies_stall) = jiffies +
91472+ ACCESS_ONCE_RW(rsp->jiffies_stall) = jiffies +
91473 3 * rcu_jiffies_till_stall_check() + 3;
91474 raw_spin_unlock_irqrestore(&rnp->lock, flags);
91475
91476@@ -1223,7 +1223,7 @@ void rcu_cpu_stall_reset(void)
91477 struct rcu_state *rsp;
91478
91479 for_each_rcu_flavor(rsp)
91480- ACCESS_ONCE(rsp->jiffies_stall) = jiffies + ULONG_MAX / 2;
91481+ ACCESS_ONCE_RW(rsp->jiffies_stall) = jiffies + ULONG_MAX / 2;
91482 }
91483
91484 /*
91485@@ -1609,7 +1609,7 @@ static int rcu_gp_init(struct rcu_state *rsp)
91486 raw_spin_unlock_irq(&rnp->lock);
91487 return 0;
91488 }
91489- ACCESS_ONCE(rsp->gp_flags) = 0; /* Clear all flags: New grace period. */
91490+ ACCESS_ONCE_RW(rsp->gp_flags) = 0; /* Clear all flags: New grace period. */
91491
91492 if (WARN_ON_ONCE(rcu_gp_in_progress(rsp))) {
91493 /*
91494@@ -1650,9 +1650,9 @@ static int rcu_gp_init(struct rcu_state *rsp)
91495 rdp = this_cpu_ptr(rsp->rda);
91496 rcu_preempt_check_blocked_tasks(rnp);
91497 rnp->qsmask = rnp->qsmaskinit;
91498- ACCESS_ONCE(rnp->gpnum) = rsp->gpnum;
91499+ ACCESS_ONCE_RW(rnp->gpnum) = rsp->gpnum;
91500 WARN_ON_ONCE(rnp->completed != rsp->completed);
91501- ACCESS_ONCE(rnp->completed) = rsp->completed;
91502+ ACCESS_ONCE_RW(rnp->completed) = rsp->completed;
91503 if (rnp == rdp->mynode)
91504 (void)__note_gp_changes(rsp, rnp, rdp);
91505 rcu_preempt_boost_start_gp(rnp);
91506@@ -1697,7 +1697,7 @@ static int rcu_gp_fqs(struct rcu_state *rsp, int fqs_state_in)
91507 if (ACCESS_ONCE(rsp->gp_flags) & RCU_GP_FLAG_FQS) {
91508 raw_spin_lock_irq(&rnp->lock);
91509 smp_mb__after_unlock_lock();
91510- ACCESS_ONCE(rsp->gp_flags) =
91511+ ACCESS_ONCE_RW(rsp->gp_flags) =
91512 ACCESS_ONCE(rsp->gp_flags) & ~RCU_GP_FLAG_FQS;
91513 raw_spin_unlock_irq(&rnp->lock);
91514 }
91515@@ -1743,7 +1743,7 @@ static void rcu_gp_cleanup(struct rcu_state *rsp)
91516 rcu_for_each_node_breadth_first(rsp, rnp) {
91517 raw_spin_lock_irq(&rnp->lock);
91518 smp_mb__after_unlock_lock();
91519- ACCESS_ONCE(rnp->completed) = rsp->gpnum;
91520+ ACCESS_ONCE_RW(rnp->completed) = rsp->gpnum;
91521 rdp = this_cpu_ptr(rsp->rda);
91522 if (rnp == rdp->mynode)
91523 needgp = __note_gp_changes(rsp, rnp, rdp) || needgp;
91524@@ -1758,14 +1758,14 @@ static void rcu_gp_cleanup(struct rcu_state *rsp)
91525 rcu_nocb_gp_set(rnp, nocb);
91526
91527 /* Declare grace period done. */
91528- ACCESS_ONCE(rsp->completed) = rsp->gpnum;
91529+ ACCESS_ONCE_RW(rsp->completed) = rsp->gpnum;
91530 trace_rcu_grace_period(rsp->name, rsp->completed, TPS("end"));
91531 rsp->fqs_state = RCU_GP_IDLE;
91532 rdp = this_cpu_ptr(rsp->rda);
91533 /* Advance CBs to reduce false positives below. */
91534 needgp = rcu_advance_cbs(rsp, rnp, rdp) || needgp;
91535 if (needgp || cpu_needs_another_gp(rsp, rdp)) {
91536- ACCESS_ONCE(rsp->gp_flags) = RCU_GP_FLAG_INIT;
91537+ ACCESS_ONCE_RW(rsp->gp_flags) = RCU_GP_FLAG_INIT;
91538 trace_rcu_grace_period(rsp->name,
91539 ACCESS_ONCE(rsp->gpnum),
91540 TPS("newreq"));
91541@@ -1890,7 +1890,7 @@ rcu_start_gp_advanced(struct rcu_state *rsp, struct rcu_node *rnp,
91542 */
91543 return false;
91544 }
91545- ACCESS_ONCE(rsp->gp_flags) = RCU_GP_FLAG_INIT;
91546+ ACCESS_ONCE_RW(rsp->gp_flags) = RCU_GP_FLAG_INIT;
91547 trace_rcu_grace_period(rsp->name, ACCESS_ONCE(rsp->gpnum),
91548 TPS("newreq"));
91549
91550@@ -2111,7 +2111,7 @@ rcu_send_cbs_to_orphanage(int cpu, struct rcu_state *rsp,
91551 rsp->qlen += rdp->qlen;
91552 rdp->n_cbs_orphaned += rdp->qlen;
91553 rdp->qlen_lazy = 0;
91554- ACCESS_ONCE(rdp->qlen) = 0;
91555+ ACCESS_ONCE_RW(rdp->qlen) = 0;
91556 }
91557
91558 /*
91559@@ -2356,7 +2356,7 @@ static void rcu_do_batch(struct rcu_state *rsp, struct rcu_data *rdp)
91560 }
91561 smp_mb(); /* List handling before counting for rcu_barrier(). */
91562 rdp->qlen_lazy -= count_lazy;
91563- ACCESS_ONCE(rdp->qlen) = rdp->qlen - count;
91564+ ACCESS_ONCE_RW(rdp->qlen) = rdp->qlen - count;
91565 rdp->n_cbs_invoked += count;
91566
91567 /* Reinstate batch limit if we have worked down the excess. */
91568@@ -2519,7 +2519,7 @@ static void force_quiescent_state(struct rcu_state *rsp)
91569 raw_spin_unlock_irqrestore(&rnp_old->lock, flags);
91570 return; /* Someone beat us to it. */
91571 }
91572- ACCESS_ONCE(rsp->gp_flags) =
91573+ ACCESS_ONCE_RW(rsp->gp_flags) =
91574 ACCESS_ONCE(rsp->gp_flags) | RCU_GP_FLAG_FQS;
91575 raw_spin_unlock_irqrestore(&rnp_old->lock, flags);
91576 rcu_gp_kthread_wake(rsp);
91577@@ -2565,7 +2565,7 @@ __rcu_process_callbacks(struct rcu_state *rsp)
91578 /*
91579 * Do RCU core processing for the current CPU.
91580 */
91581-static void rcu_process_callbacks(struct softirq_action *unused)
91582+static void rcu_process_callbacks(void)
91583 {
91584 struct rcu_state *rsp;
91585
91586@@ -2677,7 +2677,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
91587 WARN_ON_ONCE((unsigned long)head & 0x1); /* Misaligned rcu_head! */
91588 if (debug_rcu_head_queue(head)) {
91589 /* Probable double call_rcu(), so leak the callback. */
91590- ACCESS_ONCE(head->func) = rcu_leak_callback;
91591+ ACCESS_ONCE_RW(head->func) = rcu_leak_callback;
91592 WARN_ONCE(1, "__call_rcu(): Leaked duplicate callback\n");
91593 return;
91594 }
91595@@ -2705,7 +2705,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
91596 local_irq_restore(flags);
91597 return;
91598 }
91599- ACCESS_ONCE(rdp->qlen) = rdp->qlen + 1;
91600+ ACCESS_ONCE_RW(rdp->qlen) = rdp->qlen + 1;
91601 if (lazy)
91602 rdp->qlen_lazy++;
91603 else
91604@@ -2975,11 +2975,11 @@ void synchronize_sched_expedited(void)
91605 * counter wrap on a 32-bit system. Quite a few more CPUs would of
91606 * course be required on a 64-bit system.
91607 */
91608- if (ULONG_CMP_GE((ulong)atomic_long_read(&rsp->expedited_start),
91609+ if (ULONG_CMP_GE((ulong)atomic_long_read_unchecked(&rsp->expedited_start),
91610 (ulong)atomic_long_read(&rsp->expedited_done) +
91611 ULONG_MAX / 8)) {
91612 synchronize_sched();
91613- atomic_long_inc(&rsp->expedited_wrap);
91614+ atomic_long_inc_unchecked(&rsp->expedited_wrap);
91615 return;
91616 }
91617
91618@@ -2987,12 +2987,12 @@ void synchronize_sched_expedited(void)
91619 * Take a ticket. Note that atomic_inc_return() implies a
91620 * full memory barrier.
91621 */
91622- snap = atomic_long_inc_return(&rsp->expedited_start);
91623+ snap = atomic_long_inc_return_unchecked(&rsp->expedited_start);
91624 firstsnap = snap;
91625 if (!try_get_online_cpus()) {
91626 /* CPU hotplug operation in flight, fall back to normal GP. */
91627 wait_rcu_gp(call_rcu_sched);
91628- atomic_long_inc(&rsp->expedited_normal);
91629+ atomic_long_inc_unchecked(&rsp->expedited_normal);
91630 return;
91631 }
91632 WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id()));
91633@@ -3005,14 +3005,14 @@ void synchronize_sched_expedited(void)
91634 synchronize_sched_expedited_cpu_stop,
91635 NULL) == -EAGAIN) {
91636 put_online_cpus();
91637- atomic_long_inc(&rsp->expedited_tryfail);
91638+ atomic_long_inc_unchecked(&rsp->expedited_tryfail);
91639
91640 /* Check to see if someone else did our work for us. */
91641 s = atomic_long_read(&rsp->expedited_done);
91642 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
91643 /* ensure test happens before caller kfree */
91644 smp_mb__before_atomic(); /* ^^^ */
91645- atomic_long_inc(&rsp->expedited_workdone1);
91646+ atomic_long_inc_unchecked(&rsp->expedited_workdone1);
91647 return;
91648 }
91649
91650@@ -3021,7 +3021,7 @@ void synchronize_sched_expedited(void)
91651 udelay(trycount * num_online_cpus());
91652 } else {
91653 wait_rcu_gp(call_rcu_sched);
91654- atomic_long_inc(&rsp->expedited_normal);
91655+ atomic_long_inc_unchecked(&rsp->expedited_normal);
91656 return;
91657 }
91658
91659@@ -3030,7 +3030,7 @@ void synchronize_sched_expedited(void)
91660 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
91661 /* ensure test happens before caller kfree */
91662 smp_mb__before_atomic(); /* ^^^ */
91663- atomic_long_inc(&rsp->expedited_workdone2);
91664+ atomic_long_inc_unchecked(&rsp->expedited_workdone2);
91665 return;
91666 }
91667
91668@@ -3044,13 +3044,13 @@ void synchronize_sched_expedited(void)
91669 if (!try_get_online_cpus()) {
91670 /* CPU hotplug operation in flight, use normal GP. */
91671 wait_rcu_gp(call_rcu_sched);
91672- atomic_long_inc(&rsp->expedited_normal);
91673+ atomic_long_inc_unchecked(&rsp->expedited_normal);
91674 return;
91675 }
91676- snap = atomic_long_read(&rsp->expedited_start);
91677+ snap = atomic_long_read_unchecked(&rsp->expedited_start);
91678 smp_mb(); /* ensure read is before try_stop_cpus(). */
91679 }
91680- atomic_long_inc(&rsp->expedited_stoppedcpus);
91681+ atomic_long_inc_unchecked(&rsp->expedited_stoppedcpus);
91682
91683 /*
91684 * Everyone up to our most recent fetch is covered by our grace
91685@@ -3059,16 +3059,16 @@ void synchronize_sched_expedited(void)
91686 * than we did already did their update.
91687 */
91688 do {
91689- atomic_long_inc(&rsp->expedited_done_tries);
91690+ atomic_long_inc_unchecked(&rsp->expedited_done_tries);
91691 s = atomic_long_read(&rsp->expedited_done);
91692 if (ULONG_CMP_GE((ulong)s, (ulong)snap)) {
91693 /* ensure test happens before caller kfree */
91694 smp_mb__before_atomic(); /* ^^^ */
91695- atomic_long_inc(&rsp->expedited_done_lost);
91696+ atomic_long_inc_unchecked(&rsp->expedited_done_lost);
91697 break;
91698 }
91699 } while (atomic_long_cmpxchg(&rsp->expedited_done, s, snap) != s);
91700- atomic_long_inc(&rsp->expedited_done_exit);
91701+ atomic_long_inc_unchecked(&rsp->expedited_done_exit);
91702
91703 put_online_cpus();
91704 }
91705@@ -3274,7 +3274,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
91706 * ACCESS_ONCE() to prevent the compiler from speculating
91707 * the increment to precede the early-exit check.
91708 */
91709- ACCESS_ONCE(rsp->n_barrier_done) = rsp->n_barrier_done + 1;
91710+ ACCESS_ONCE_RW(rsp->n_barrier_done) = rsp->n_barrier_done + 1;
91711 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 1);
91712 _rcu_barrier_trace(rsp, "Inc1", -1, rsp->n_barrier_done);
91713 smp_mb(); /* Order ->n_barrier_done increment with below mechanism. */
91714@@ -3329,7 +3329,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
91715
91716 /* Increment ->n_barrier_done to prevent duplicate work. */
91717 smp_mb(); /* Keep increment after above mechanism. */
91718- ACCESS_ONCE(rsp->n_barrier_done) = rsp->n_barrier_done + 1;
91719+ ACCESS_ONCE_RW(rsp->n_barrier_done) = rsp->n_barrier_done + 1;
91720 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 0);
91721 _rcu_barrier_trace(rsp, "Inc2", -1, rsp->n_barrier_done);
91722 smp_mb(); /* Keep increment before caller's subsequent code. */
91723@@ -3374,10 +3374,10 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
91724 rdp->grpmask = 1UL << (cpu - rdp->mynode->grplo);
91725 init_callback_list(rdp);
91726 rdp->qlen_lazy = 0;
91727- ACCESS_ONCE(rdp->qlen) = 0;
91728+ ACCESS_ONCE_RW(rdp->qlen) = 0;
91729 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
91730 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE);
91731- WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
91732+ WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
91733 rdp->cpu = cpu;
91734 rdp->rsp = rsp;
91735 rcu_boot_init_nocb_percpu_data(rdp);
91736@@ -3410,8 +3410,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp)
91737 init_callback_list(rdp); /* Re-enable callbacks on this CPU. */
91738 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
91739 rcu_sysidle_init_percpu_data(rdp->dynticks);
91740- atomic_set(&rdp->dynticks->dynticks,
91741- (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
91742+ atomic_set_unchecked(&rdp->dynticks->dynticks,
91743+ (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
91744 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
91745
91746 /* Add CPU to rcu_node bitmasks. */
91747diff --git a/kernel/rcu/tree.h b/kernel/rcu/tree.h
91748index bbdc45d..c882ccb 100644
91749--- a/kernel/rcu/tree.h
91750+++ b/kernel/rcu/tree.h
91751@@ -87,11 +87,11 @@ struct rcu_dynticks {
91752 long long dynticks_nesting; /* Track irq/process nesting level. */
91753 /* Process level is worth LLONG_MAX/2. */
91754 int dynticks_nmi_nesting; /* Track NMI nesting level. */
91755- atomic_t dynticks; /* Even value for idle, else odd. */
91756+ atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
91757 #ifdef CONFIG_NO_HZ_FULL_SYSIDLE
91758 long long dynticks_idle_nesting;
91759 /* irq/process nesting level from idle. */
91760- atomic_t dynticks_idle; /* Even value for idle, else odd. */
91761+ atomic_unchecked_t dynticks_idle;/* Even value for idle, else odd. */
91762 /* "Idle" excludes userspace execution. */
91763 unsigned long dynticks_idle_jiffies;
91764 /* End of last non-NMI non-idle period. */
91765@@ -466,17 +466,17 @@ struct rcu_state {
91766 /* _rcu_barrier(). */
91767 /* End of fields guarded by barrier_mutex. */
91768
91769- atomic_long_t expedited_start; /* Starting ticket. */
91770- atomic_long_t expedited_done; /* Done ticket. */
91771- atomic_long_t expedited_wrap; /* # near-wrap incidents. */
91772- atomic_long_t expedited_tryfail; /* # acquisition failures. */
91773- atomic_long_t expedited_workdone1; /* # done by others #1. */
91774- atomic_long_t expedited_workdone2; /* # done by others #2. */
91775- atomic_long_t expedited_normal; /* # fallbacks to normal. */
91776- atomic_long_t expedited_stoppedcpus; /* # successful stop_cpus. */
91777- atomic_long_t expedited_done_tries; /* # tries to update _done. */
91778- atomic_long_t expedited_done_lost; /* # times beaten to _done. */
91779- atomic_long_t expedited_done_exit; /* # times exited _done loop. */
91780+ atomic_long_unchecked_t expedited_start; /* Starting ticket. */
91781+ atomic_long_t expedited_done; /* Done ticket. */
91782+ atomic_long_unchecked_t expedited_wrap; /* # near-wrap incidents. */
91783+ atomic_long_unchecked_t expedited_tryfail; /* # acquisition failures. */
91784+ atomic_long_unchecked_t expedited_workdone1; /* # done by others #1. */
91785+ atomic_long_unchecked_t expedited_workdone2; /* # done by others #2. */
91786+ atomic_long_unchecked_t expedited_normal; /* # fallbacks to normal. */
91787+ atomic_long_unchecked_t expedited_stoppedcpus; /* # successful stop_cpus. */
91788+ atomic_long_unchecked_t expedited_done_tries; /* # tries to update _done. */
91789+ atomic_long_unchecked_t expedited_done_lost; /* # times beaten to _done. */
91790+ atomic_long_unchecked_t expedited_done_exit; /* # times exited _done loop. */
91791
91792 unsigned long jiffies_force_qs; /* Time at which to invoke */
91793 /* force_quiescent_state(). */
91794diff --git a/kernel/rcu/tree_plugin.h b/kernel/rcu/tree_plugin.h
91795index c1d7f27..a64bf49 100644
91796--- a/kernel/rcu/tree_plugin.h
91797+++ b/kernel/rcu/tree_plugin.h
91798@@ -709,7 +709,7 @@ static int rcu_preempted_readers_exp(struct rcu_node *rnp)
91799 static int sync_rcu_preempt_exp_done(struct rcu_node *rnp)
91800 {
91801 return !rcu_preempted_readers_exp(rnp) &&
91802- ACCESS_ONCE(rnp->expmask) == 0;
91803+ ACCESS_ONCE_RW(rnp->expmask) == 0;
91804 }
91805
91806 /*
91807@@ -870,7 +870,7 @@ void synchronize_rcu_expedited(void)
91808
91809 /* Clean up and exit. */
91810 smp_mb(); /* ensure expedited GP seen before counter increment. */
91811- ACCESS_ONCE(sync_rcu_preempt_exp_count) =
91812+ ACCESS_ONCE_RW(sync_rcu_preempt_exp_count) =
91813 sync_rcu_preempt_exp_count + 1;
91814 unlock_mb_ret:
91815 mutex_unlock(&sync_rcu_preempt_exp_mutex);
91816@@ -1426,7 +1426,7 @@ static void rcu_boost_kthread_setaffinity(struct rcu_node *rnp, int outgoingcpu)
91817 free_cpumask_var(cm);
91818 }
91819
91820-static struct smp_hotplug_thread rcu_cpu_thread_spec = {
91821+static struct smp_hotplug_thread rcu_cpu_thread_spec __read_only = {
91822 .store = &rcu_cpu_kthread_task,
91823 .thread_should_run = rcu_cpu_kthread_should_run,
91824 .thread_fn = rcu_cpu_kthread,
91825@@ -1900,7 +1900,7 @@ static void print_cpu_stall_info(struct rcu_state *rsp, int cpu)
91826 print_cpu_stall_fast_no_hz(fast_no_hz, cpu);
91827 pr_err("\t%d: (%lu %s) idle=%03x/%llx/%d softirq=%u/%u %s\n",
91828 cpu, ticks_value, ticks_title,
91829- atomic_read(&rdtp->dynticks) & 0xfff,
91830+ atomic_read_unchecked(&rdtp->dynticks) & 0xfff,
91831 rdtp->dynticks_nesting, rdtp->dynticks_nmi_nesting,
91832 rdp->softirq_snap, kstat_softirqs_cpu(RCU_SOFTIRQ, cpu),
91833 fast_no_hz);
91834@@ -2044,7 +2044,7 @@ static void wake_nocb_leader(struct rcu_data *rdp, bool force)
91835 return;
91836 if (ACCESS_ONCE(rdp_leader->nocb_leader_sleep) || force) {
91837 /* Prior smp_mb__after_atomic() orders against prior enqueue. */
91838- ACCESS_ONCE(rdp_leader->nocb_leader_sleep) = false;
91839+ ACCESS_ONCE_RW(rdp_leader->nocb_leader_sleep) = false;
91840 wake_up(&rdp_leader->nocb_wq);
91841 }
91842 }
91843@@ -2096,7 +2096,7 @@ static void __call_rcu_nocb_enqueue(struct rcu_data *rdp,
91844
91845 /* Enqueue the callback on the nocb list and update counts. */
91846 old_rhpp = xchg(&rdp->nocb_tail, rhtp);
91847- ACCESS_ONCE(*old_rhpp) = rhp;
91848+ ACCESS_ONCE_RW(*old_rhpp) = rhp;
91849 atomic_long_add(rhcount, &rdp->nocb_q_count);
91850 atomic_long_add(rhcount_lazy, &rdp->nocb_q_count_lazy);
91851 smp_mb__after_atomic(); /* Store *old_rhpp before _wake test. */
91852@@ -2286,7 +2286,7 @@ wait_again:
91853 continue; /* No CBs here, try next follower. */
91854
91855 /* Move callbacks to wait-for-GP list, which is empty. */
91856- ACCESS_ONCE(rdp->nocb_head) = NULL;
91857+ ACCESS_ONCE_RW(rdp->nocb_head) = NULL;
91858 rdp->nocb_gp_tail = xchg(&rdp->nocb_tail, &rdp->nocb_head);
91859 rdp->nocb_gp_count = atomic_long_xchg(&rdp->nocb_q_count, 0);
91860 rdp->nocb_gp_count_lazy =
91861@@ -2413,7 +2413,7 @@ static int rcu_nocb_kthread(void *arg)
91862 list = ACCESS_ONCE(rdp->nocb_follower_head);
91863 BUG_ON(!list);
91864 trace_rcu_nocb_wake(rdp->rsp->name, rdp->cpu, "WokeNonEmpty");
91865- ACCESS_ONCE(rdp->nocb_follower_head) = NULL;
91866+ ACCESS_ONCE_RW(rdp->nocb_follower_head) = NULL;
91867 tail = xchg(&rdp->nocb_follower_tail, &rdp->nocb_follower_head);
91868 c = atomic_long_xchg(&rdp->nocb_follower_count, 0);
91869 cl = atomic_long_xchg(&rdp->nocb_follower_count_lazy, 0);
91870@@ -2443,8 +2443,8 @@ static int rcu_nocb_kthread(void *arg)
91871 list = next;
91872 }
91873 trace_rcu_batch_end(rdp->rsp->name, c, !!list, 0, 0, 1);
91874- ACCESS_ONCE(rdp->nocb_p_count) = rdp->nocb_p_count - c;
91875- ACCESS_ONCE(rdp->nocb_p_count_lazy) =
91876+ ACCESS_ONCE_RW(rdp->nocb_p_count) = rdp->nocb_p_count - c;
91877+ ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) =
91878 rdp->nocb_p_count_lazy - cl;
91879 rdp->n_nocbs_invoked += c;
91880 }
91881@@ -2465,7 +2465,7 @@ static void do_nocb_deferred_wakeup(struct rcu_data *rdp)
91882 if (!rcu_nocb_need_deferred_wakeup(rdp))
91883 return;
91884 ndw = ACCESS_ONCE(rdp->nocb_defer_wakeup);
91885- ACCESS_ONCE(rdp->nocb_defer_wakeup) = RCU_NOGP_WAKE_NOT;
91886+ ACCESS_ONCE_RW(rdp->nocb_defer_wakeup) = RCU_NOGP_WAKE_NOT;
91887 wake_nocb_leader(rdp, ndw == RCU_NOGP_WAKE_FORCE);
91888 trace_rcu_nocb_wake(rdp->rsp->name, rdp->cpu, TPS("DeferredWake"));
91889 }
91890@@ -2584,7 +2584,7 @@ static void rcu_spawn_one_nocb_kthread(struct rcu_state *rsp, int cpu)
91891 t = kthread_run(rcu_nocb_kthread, rdp_spawn,
91892 "rcuo%c/%d", rsp->abbr, cpu);
91893 BUG_ON(IS_ERR(t));
91894- ACCESS_ONCE(rdp_spawn->nocb_kthread) = t;
91895+ ACCESS_ONCE_RW(rdp_spawn->nocb_kthread) = t;
91896 }
91897
91898 /*
91899@@ -2788,11 +2788,11 @@ static void rcu_sysidle_enter(struct rcu_dynticks *rdtp, int irq)
91900
91901 /* Record start of fully idle period. */
91902 j = jiffies;
91903- ACCESS_ONCE(rdtp->dynticks_idle_jiffies) = j;
91904+ ACCESS_ONCE_RW(rdtp->dynticks_idle_jiffies) = j;
91905 smp_mb__before_atomic();
91906- atomic_inc(&rdtp->dynticks_idle);
91907+ atomic_inc_unchecked(&rdtp->dynticks_idle);
91908 smp_mb__after_atomic();
91909- WARN_ON_ONCE(atomic_read(&rdtp->dynticks_idle) & 0x1);
91910+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks_idle) & 0x1);
91911 }
91912
91913 /*
91914@@ -2861,9 +2861,9 @@ static void rcu_sysidle_exit(struct rcu_dynticks *rdtp, int irq)
91915
91916 /* Record end of idle period. */
91917 smp_mb__before_atomic();
91918- atomic_inc(&rdtp->dynticks_idle);
91919+ atomic_inc_unchecked(&rdtp->dynticks_idle);
91920 smp_mb__after_atomic();
91921- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks_idle) & 0x1));
91922+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks_idle) & 0x1));
91923
91924 /*
91925 * If we are the timekeeping CPU, we are permitted to be non-idle
91926@@ -2908,7 +2908,7 @@ static void rcu_sysidle_check_cpu(struct rcu_data *rdp, bool *isidle,
91927 WARN_ON_ONCE(smp_processor_id() != tick_do_timer_cpu);
91928
91929 /* Pick up current idle and NMI-nesting counter and check. */
91930- cur = atomic_read(&rdtp->dynticks_idle);
91931+ cur = atomic_read_unchecked(&rdtp->dynticks_idle);
91932 if (cur & 0x1) {
91933 *isidle = false; /* We are not idle! */
91934 return;
91935@@ -2957,7 +2957,7 @@ static void rcu_sysidle(unsigned long j)
91936 case RCU_SYSIDLE_NOT:
91937
91938 /* First time all are idle, so note a short idle period. */
91939- ACCESS_ONCE(full_sysidle_state) = RCU_SYSIDLE_SHORT;
91940+ ACCESS_ONCE_RW(full_sysidle_state) = RCU_SYSIDLE_SHORT;
91941 break;
91942
91943 case RCU_SYSIDLE_SHORT:
91944@@ -2995,7 +2995,7 @@ static void rcu_sysidle_cancel(void)
91945 {
91946 smp_mb();
91947 if (full_sysidle_state > RCU_SYSIDLE_SHORT)
91948- ACCESS_ONCE(full_sysidle_state) = RCU_SYSIDLE_NOT;
91949+ ACCESS_ONCE_RW(full_sysidle_state) = RCU_SYSIDLE_NOT;
91950 }
91951
91952 /*
91953@@ -3047,7 +3047,7 @@ static void rcu_sysidle_cb(struct rcu_head *rhp)
91954 smp_mb(); /* grace period precedes setting inuse. */
91955
91956 rshp = container_of(rhp, struct rcu_sysidle_head, rh);
91957- ACCESS_ONCE(rshp->inuse) = 0;
91958+ ACCESS_ONCE_RW(rshp->inuse) = 0;
91959 }
91960
91961 /*
91962@@ -3200,7 +3200,7 @@ static void rcu_bind_gp_kthread(void)
91963 static void rcu_dynticks_task_enter(void)
91964 {
91965 #if defined(CONFIG_TASKS_RCU) && defined(CONFIG_NO_HZ_FULL)
91966- ACCESS_ONCE(current->rcu_tasks_idle_cpu) = smp_processor_id();
91967+ ACCESS_ONCE_RW(current->rcu_tasks_idle_cpu) = smp_processor_id();
91968 #endif /* #if defined(CONFIG_TASKS_RCU) && defined(CONFIG_NO_HZ_FULL) */
91969 }
91970
91971@@ -3208,6 +3208,6 @@ static void rcu_dynticks_task_enter(void)
91972 static void rcu_dynticks_task_exit(void)
91973 {
91974 #if defined(CONFIG_TASKS_RCU) && defined(CONFIG_NO_HZ_FULL)
91975- ACCESS_ONCE(current->rcu_tasks_idle_cpu) = -1;
91976+ ACCESS_ONCE_RW(current->rcu_tasks_idle_cpu) = -1;
91977 #endif /* #if defined(CONFIG_TASKS_RCU) && defined(CONFIG_NO_HZ_FULL) */
91978 }
91979diff --git a/kernel/rcu/tree_trace.c b/kernel/rcu/tree_trace.c
91980index 5cdc62e..cc52e88 100644
91981--- a/kernel/rcu/tree_trace.c
91982+++ b/kernel/rcu/tree_trace.c
91983@@ -121,7 +121,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
91984 ulong2long(rdp->completed), ulong2long(rdp->gpnum),
91985 rdp->passed_quiesce, rdp->qs_pending);
91986 seq_printf(m, " dt=%d/%llx/%d df=%lu",
91987- atomic_read(&rdp->dynticks->dynticks),
91988+ atomic_read_unchecked(&rdp->dynticks->dynticks),
91989 rdp->dynticks->dynticks_nesting,
91990 rdp->dynticks->dynticks_nmi_nesting,
91991 rdp->dynticks_fqs);
91992@@ -182,17 +182,17 @@ static int show_rcuexp(struct seq_file *m, void *v)
91993 struct rcu_state *rsp = (struct rcu_state *)m->private;
91994
91995 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",
91996- atomic_long_read(&rsp->expedited_start),
91997+ atomic_long_read_unchecked(&rsp->expedited_start),
91998 atomic_long_read(&rsp->expedited_done),
91999- atomic_long_read(&rsp->expedited_wrap),
92000- atomic_long_read(&rsp->expedited_tryfail),
92001- atomic_long_read(&rsp->expedited_workdone1),
92002- atomic_long_read(&rsp->expedited_workdone2),
92003- atomic_long_read(&rsp->expedited_normal),
92004- atomic_long_read(&rsp->expedited_stoppedcpus),
92005- atomic_long_read(&rsp->expedited_done_tries),
92006- atomic_long_read(&rsp->expedited_done_lost),
92007- atomic_long_read(&rsp->expedited_done_exit));
92008+ atomic_long_read_unchecked(&rsp->expedited_wrap),
92009+ atomic_long_read_unchecked(&rsp->expedited_tryfail),
92010+ atomic_long_read_unchecked(&rsp->expedited_workdone1),
92011+ atomic_long_read_unchecked(&rsp->expedited_workdone2),
92012+ atomic_long_read_unchecked(&rsp->expedited_normal),
92013+ atomic_long_read_unchecked(&rsp->expedited_stoppedcpus),
92014+ atomic_long_read_unchecked(&rsp->expedited_done_tries),
92015+ atomic_long_read_unchecked(&rsp->expedited_done_lost),
92016+ atomic_long_read_unchecked(&rsp->expedited_done_exit));
92017 return 0;
92018 }
92019
92020diff --git a/kernel/rcu/update.c b/kernel/rcu/update.c
92021index 3ef8ba5..8c5ebfb6 100644
92022--- a/kernel/rcu/update.c
92023+++ b/kernel/rcu/update.c
92024@@ -342,10 +342,10 @@ int rcu_jiffies_till_stall_check(void)
92025 * for CONFIG_RCU_CPU_STALL_TIMEOUT.
92026 */
92027 if (till_stall_check < 3) {
92028- ACCESS_ONCE(rcu_cpu_stall_timeout) = 3;
92029+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 3;
92030 till_stall_check = 3;
92031 } else if (till_stall_check > 300) {
92032- ACCESS_ONCE(rcu_cpu_stall_timeout) = 300;
92033+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 300;
92034 till_stall_check = 300;
92035 }
92036 return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;
92037@@ -501,7 +501,7 @@ static void check_holdout_task(struct task_struct *t,
92038 !ACCESS_ONCE(t->on_rq) ||
92039 (IS_ENABLED(CONFIG_NO_HZ_FULL) &&
92040 !is_idle_task(t) && t->rcu_tasks_idle_cpu >= 0)) {
92041- ACCESS_ONCE(t->rcu_tasks_holdout) = false;
92042+ ACCESS_ONCE_RW(t->rcu_tasks_holdout) = false;
92043 list_del_init(&t->rcu_tasks_holdout_list);
92044 put_task_struct(t);
92045 return;
92046@@ -588,7 +588,7 @@ static int __noreturn rcu_tasks_kthread(void *arg)
92047 !is_idle_task(t)) {
92048 get_task_struct(t);
92049 t->rcu_tasks_nvcsw = ACCESS_ONCE(t->nvcsw);
92050- ACCESS_ONCE(t->rcu_tasks_holdout) = true;
92051+ ACCESS_ONCE_RW(t->rcu_tasks_holdout) = true;
92052 list_add(&t->rcu_tasks_holdout_list,
92053 &rcu_tasks_holdouts);
92054 }
92055@@ -685,7 +685,7 @@ static void rcu_spawn_tasks_kthread(void)
92056 t = kthread_run(rcu_tasks_kthread, NULL, "rcu_tasks_kthread");
92057 BUG_ON(IS_ERR(t));
92058 smp_mb(); /* Ensure others see full kthread. */
92059- ACCESS_ONCE(rcu_tasks_kthread_ptr) = t;
92060+ ACCESS_ONCE_RW(rcu_tasks_kthread_ptr) = t;
92061 mutex_unlock(&rcu_tasks_kthread_mutex);
92062 }
92063
92064diff --git a/kernel/resource.c b/kernel/resource.c
92065index 0bcebff..e7cd5b2 100644
92066--- a/kernel/resource.c
92067+++ b/kernel/resource.c
92068@@ -161,8 +161,18 @@ static const struct file_operations proc_iomem_operations = {
92069
92070 static int __init ioresources_init(void)
92071 {
92072+#ifdef CONFIG_GRKERNSEC_PROC_ADD
92073+#ifdef CONFIG_GRKERNSEC_PROC_USER
92074+ proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
92075+ proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
92076+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
92077+ proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
92078+ proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
92079+#endif
92080+#else
92081 proc_create("ioports", 0, NULL, &proc_ioports_operations);
92082 proc_create("iomem", 0, NULL, &proc_iomem_operations);
92083+#endif
92084 return 0;
92085 }
92086 __initcall(ioresources_init);
92087diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
92088index 8a2e230..6020954 100644
92089--- a/kernel/sched/auto_group.c
92090+++ b/kernel/sched/auto_group.c
92091@@ -11,7 +11,7 @@
92092
92093 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
92094 static struct autogroup autogroup_default;
92095-static atomic_t autogroup_seq_nr;
92096+static atomic_unchecked_t autogroup_seq_nr;
92097
92098 void __init autogroup_init(struct task_struct *init_task)
92099 {
92100@@ -79,7 +79,7 @@ static inline struct autogroup *autogroup_create(void)
92101
92102 kref_init(&ag->kref);
92103 init_rwsem(&ag->lock);
92104- ag->id = atomic_inc_return(&autogroup_seq_nr);
92105+ ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
92106 ag->tg = tg;
92107 #ifdef CONFIG_RT_GROUP_SCHED
92108 /*
92109diff --git a/kernel/sched/completion.c b/kernel/sched/completion.c
92110index a63f4dc..349bbb0 100644
92111--- a/kernel/sched/completion.c
92112+++ b/kernel/sched/completion.c
92113@@ -204,7 +204,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible);
92114 * Return: -ERESTARTSYS if interrupted, 0 if timed out, positive (at least 1,
92115 * or number of jiffies left till timeout) if completed.
92116 */
92117-long __sched
92118+long __sched __intentional_overflow(-1)
92119 wait_for_completion_interruptible_timeout(struct completion *x,
92120 unsigned long timeout)
92121 {
92122@@ -221,7 +221,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible_timeout);
92123 *
92124 * Return: -ERESTARTSYS if interrupted, 0 if completed.
92125 */
92126-int __sched wait_for_completion_killable(struct completion *x)
92127+int __sched __intentional_overflow(-1) wait_for_completion_killable(struct completion *x)
92128 {
92129 long t = wait_for_common(x, MAX_SCHEDULE_TIMEOUT, TASK_KILLABLE);
92130 if (t == -ERESTARTSYS)
92131@@ -242,7 +242,7 @@ EXPORT_SYMBOL(wait_for_completion_killable);
92132 * Return: -ERESTARTSYS if interrupted, 0 if timed out, positive (at least 1,
92133 * or number of jiffies left till timeout) if completed.
92134 */
92135-long __sched
92136+long __sched __intentional_overflow(-1)
92137 wait_for_completion_killable_timeout(struct completion *x,
92138 unsigned long timeout)
92139 {
92140diff --git a/kernel/sched/core.c b/kernel/sched/core.c
92141index efdca2f..e361dfb 100644
92142--- a/kernel/sched/core.c
92143+++ b/kernel/sched/core.c
92144@@ -1890,7 +1890,7 @@ void set_numabalancing_state(bool enabled)
92145 int sysctl_numa_balancing(struct ctl_table *table, int write,
92146 void __user *buffer, size_t *lenp, loff_t *ppos)
92147 {
92148- struct ctl_table t;
92149+ ctl_table_no_const t;
92150 int err;
92151 int state = numabalancing_enabled;
92152
92153@@ -2353,8 +2353,10 @@ context_switch(struct rq *rq, struct task_struct *prev,
92154 next->active_mm = oldmm;
92155 atomic_inc(&oldmm->mm_count);
92156 enter_lazy_tlb(oldmm, next);
92157- } else
92158+ } else {
92159 switch_mm(oldmm, mm, next);
92160+ populate_stack();
92161+ }
92162
92163 if (!prev->mm) {
92164 prev->active_mm = NULL;
92165@@ -3165,6 +3167,8 @@ int can_nice(const struct task_struct *p, const int nice)
92166 /* convert nice value [19,-20] to rlimit style value [1,40] */
92167 int nice_rlim = nice_to_rlimit(nice);
92168
92169+ gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
92170+
92171 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
92172 capable(CAP_SYS_NICE));
92173 }
92174@@ -3191,7 +3195,8 @@ SYSCALL_DEFINE1(nice, int, increment)
92175 nice = task_nice(current) + increment;
92176
92177 nice = clamp_val(nice, MIN_NICE, MAX_NICE);
92178- if (increment < 0 && !can_nice(current, nice))
92179+ if (increment < 0 && (!can_nice(current, nice) ||
92180+ gr_handle_chroot_nice()))
92181 return -EPERM;
92182
92183 retval = security_task_setnice(current, nice);
92184@@ -3470,6 +3475,7 @@ recheck:
92185 if (policy != p->policy && !rlim_rtprio)
92186 return -EPERM;
92187
92188+ gr_learn_resource(p, RLIMIT_RTPRIO, attr->sched_priority, 1);
92189 /* can't increase priority */
92190 if (attr->sched_priority > p->rt_priority &&
92191 attr->sched_priority > rlim_rtprio)
92192@@ -4890,6 +4896,7 @@ void idle_task_exit(void)
92193
92194 if (mm != &init_mm) {
92195 switch_mm(mm, &init_mm, current);
92196+ populate_stack();
92197 finish_arch_post_lock_switch();
92198 }
92199 mmdrop(mm);
92200@@ -4985,7 +4992,7 @@ static void migrate_tasks(unsigned int dead_cpu)
92201
92202 #if defined(CONFIG_SCHED_DEBUG) && defined(CONFIG_SYSCTL)
92203
92204-static struct ctl_table sd_ctl_dir[] = {
92205+static ctl_table_no_const sd_ctl_dir[] __read_only = {
92206 {
92207 .procname = "sched_domain",
92208 .mode = 0555,
92209@@ -5002,17 +5009,17 @@ static struct ctl_table sd_ctl_root[] = {
92210 {}
92211 };
92212
92213-static struct ctl_table *sd_alloc_ctl_entry(int n)
92214+static ctl_table_no_const *sd_alloc_ctl_entry(int n)
92215 {
92216- struct ctl_table *entry =
92217+ ctl_table_no_const *entry =
92218 kcalloc(n, sizeof(struct ctl_table), GFP_KERNEL);
92219
92220 return entry;
92221 }
92222
92223-static void sd_free_ctl_entry(struct ctl_table **tablep)
92224+static void sd_free_ctl_entry(ctl_table_no_const *tablep)
92225 {
92226- struct ctl_table *entry;
92227+ ctl_table_no_const *entry;
92228
92229 /*
92230 * In the intermediate directories, both the child directory and
92231@@ -5020,22 +5027,25 @@ static void sd_free_ctl_entry(struct ctl_table **tablep)
92232 * will always be set. In the lowest directory the names are
92233 * static strings and all have proc handlers.
92234 */
92235- for (entry = *tablep; entry->mode; entry++) {
92236- if (entry->child)
92237- sd_free_ctl_entry(&entry->child);
92238+ for (entry = tablep; entry->mode; entry++) {
92239+ if (entry->child) {
92240+ sd_free_ctl_entry(entry->child);
92241+ pax_open_kernel();
92242+ entry->child = NULL;
92243+ pax_close_kernel();
92244+ }
92245 if (entry->proc_handler == NULL)
92246 kfree(entry->procname);
92247 }
92248
92249- kfree(*tablep);
92250- *tablep = NULL;
92251+ kfree(tablep);
92252 }
92253
92254 static int min_load_idx = 0;
92255 static int max_load_idx = CPU_LOAD_IDX_MAX-1;
92256
92257 static void
92258-set_table_entry(struct ctl_table *entry,
92259+set_table_entry(ctl_table_no_const *entry,
92260 const char *procname, void *data, int maxlen,
92261 umode_t mode, proc_handler *proc_handler,
92262 bool load_idx)
92263@@ -5055,7 +5065,7 @@ set_table_entry(struct ctl_table *entry,
92264 static struct ctl_table *
92265 sd_alloc_ctl_domain_table(struct sched_domain *sd)
92266 {
92267- struct ctl_table *table = sd_alloc_ctl_entry(14);
92268+ ctl_table_no_const *table = sd_alloc_ctl_entry(14);
92269
92270 if (table == NULL)
92271 return NULL;
92272@@ -5093,9 +5103,9 @@ sd_alloc_ctl_domain_table(struct sched_domain *sd)
92273 return table;
92274 }
92275
92276-static struct ctl_table *sd_alloc_ctl_cpu_table(int cpu)
92277+static ctl_table_no_const *sd_alloc_ctl_cpu_table(int cpu)
92278 {
92279- struct ctl_table *entry, *table;
92280+ ctl_table_no_const *entry, *table;
92281 struct sched_domain *sd;
92282 int domain_num = 0, i;
92283 char buf[32];
92284@@ -5122,11 +5132,13 @@ static struct ctl_table_header *sd_sysctl_header;
92285 static void register_sched_domain_sysctl(void)
92286 {
92287 int i, cpu_num = num_possible_cpus();
92288- struct ctl_table *entry = sd_alloc_ctl_entry(cpu_num + 1);
92289+ ctl_table_no_const *entry = sd_alloc_ctl_entry(cpu_num + 1);
92290 char buf[32];
92291
92292 WARN_ON(sd_ctl_dir[0].child);
92293+ pax_open_kernel();
92294 sd_ctl_dir[0].child = entry;
92295+ pax_close_kernel();
92296
92297 if (entry == NULL)
92298 return;
92299@@ -5149,8 +5161,12 @@ static void unregister_sched_domain_sysctl(void)
92300 if (sd_sysctl_header)
92301 unregister_sysctl_table(sd_sysctl_header);
92302 sd_sysctl_header = NULL;
92303- if (sd_ctl_dir[0].child)
92304- sd_free_ctl_entry(&sd_ctl_dir[0].child);
92305+ if (sd_ctl_dir[0].child) {
92306+ sd_free_ctl_entry(sd_ctl_dir[0].child);
92307+ pax_open_kernel();
92308+ sd_ctl_dir[0].child = NULL;
92309+ pax_close_kernel();
92310+ }
92311 }
92312 #else
92313 static void register_sched_domain_sysctl(void)
92314diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
92315index ef2b104..69961f6 100644
92316--- a/kernel/sched/fair.c
92317+++ b/kernel/sched/fair.c
92318@@ -1906,7 +1906,7 @@ void task_numa_fault(int last_cpupid, int mem_node, int pages, int flags)
92319
92320 static void reset_ptenuma_scan(struct task_struct *p)
92321 {
92322- ACCESS_ONCE(p->mm->numa_scan_seq)++;
92323+ ACCESS_ONCE_RW(p->mm->numa_scan_seq)++;
92324 p->mm->numa_scan_offset = 0;
92325 }
92326
92327@@ -7465,7 +7465,7 @@ static void nohz_idle_balance(struct rq *this_rq, enum cpu_idle_type idle) { }
92328 * run_rebalance_domains is triggered when needed from the scheduler tick.
92329 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
92330 */
92331-static void run_rebalance_domains(struct softirq_action *h)
92332+static __latent_entropy void run_rebalance_domains(void)
92333 {
92334 struct rq *this_rq = this_rq();
92335 enum cpu_idle_type idle = this_rq->idle_balance ?
92336diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
92337index 2df8ef0..aae070f 100644
92338--- a/kernel/sched/sched.h
92339+++ b/kernel/sched/sched.h
92340@@ -1140,7 +1140,7 @@ struct sched_class {
92341 #ifdef CONFIG_FAIR_GROUP_SCHED
92342 void (*task_move_group) (struct task_struct *p, int on_rq);
92343 #endif
92344-};
92345+} __do_const;
92346
92347 static inline void put_prev_task(struct rq *rq, struct task_struct *prev)
92348 {
92349diff --git a/kernel/signal.c b/kernel/signal.c
92350index 8f0876f..1153a5a 100644
92351--- a/kernel/signal.c
92352+++ b/kernel/signal.c
92353@@ -53,12 +53,12 @@ static struct kmem_cache *sigqueue_cachep;
92354
92355 int print_fatal_signals __read_mostly;
92356
92357-static void __user *sig_handler(struct task_struct *t, int sig)
92358+static __sighandler_t sig_handler(struct task_struct *t, int sig)
92359 {
92360 return t->sighand->action[sig - 1].sa.sa_handler;
92361 }
92362
92363-static int sig_handler_ignored(void __user *handler, int sig)
92364+static int sig_handler_ignored(__sighandler_t handler, int sig)
92365 {
92366 /* Is it explicitly or implicitly ignored? */
92367 return handler == SIG_IGN ||
92368@@ -67,7 +67,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
92369
92370 static int sig_task_ignored(struct task_struct *t, int sig, bool force)
92371 {
92372- void __user *handler;
92373+ __sighandler_t handler;
92374
92375 handler = sig_handler(t, sig);
92376
92377@@ -372,6 +372,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
92378 atomic_inc(&user->sigpending);
92379 rcu_read_unlock();
92380
92381+ if (!override_rlimit)
92382+ gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
92383+
92384 if (override_rlimit ||
92385 atomic_read(&user->sigpending) <=
92386 task_rlimit(t, RLIMIT_SIGPENDING)) {
92387@@ -499,7 +502,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
92388
92389 int unhandled_signal(struct task_struct *tsk, int sig)
92390 {
92391- void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
92392+ __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
92393 if (is_global_init(tsk))
92394 return 1;
92395 if (handler != SIG_IGN && handler != SIG_DFL)
92396@@ -793,6 +796,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
92397 }
92398 }
92399
92400+ /* allow glibc communication via tgkill to other threads in our
92401+ thread group */
92402+ if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
92403+ sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
92404+ && gr_handle_signal(t, sig))
92405+ return -EPERM;
92406+
92407 return security_task_kill(t, info, sig, 0);
92408 }
92409
92410@@ -1176,7 +1186,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
92411 return send_signal(sig, info, p, 1);
92412 }
92413
92414-static int
92415+int
92416 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
92417 {
92418 return send_signal(sig, info, t, 0);
92419@@ -1213,6 +1223,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
92420 unsigned long int flags;
92421 int ret, blocked, ignored;
92422 struct k_sigaction *action;
92423+ int is_unhandled = 0;
92424
92425 spin_lock_irqsave(&t->sighand->siglock, flags);
92426 action = &t->sighand->action[sig-1];
92427@@ -1227,9 +1238,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
92428 }
92429 if (action->sa.sa_handler == SIG_DFL)
92430 t->signal->flags &= ~SIGNAL_UNKILLABLE;
92431+ if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
92432+ is_unhandled = 1;
92433 ret = specific_send_sig_info(sig, info, t);
92434 spin_unlock_irqrestore(&t->sighand->siglock, flags);
92435
92436+ /* only deal with unhandled signals, java etc trigger SIGSEGV during
92437+ normal operation */
92438+ if (is_unhandled) {
92439+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
92440+ gr_handle_crash(t, sig);
92441+ }
92442+
92443 return ret;
92444 }
92445
92446@@ -1300,8 +1320,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
92447 ret = check_kill_permission(sig, info, p);
92448 rcu_read_unlock();
92449
92450- if (!ret && sig)
92451+ if (!ret && sig) {
92452 ret = do_send_sig_info(sig, info, p, true);
92453+ if (!ret)
92454+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
92455+ }
92456
92457 return ret;
92458 }
92459@@ -2903,7 +2926,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
92460 int error = -ESRCH;
92461
92462 rcu_read_lock();
92463- p = find_task_by_vpid(pid);
92464+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
92465+ /* allow glibc communication via tgkill to other threads in our
92466+ thread group */
92467+ if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
92468+ sig == (SIGRTMIN+1) && tgid == info->si_pid)
92469+ p = find_task_by_vpid_unrestricted(pid);
92470+ else
92471+#endif
92472+ p = find_task_by_vpid(pid);
92473 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
92474 error = check_kill_permission(sig, info, p);
92475 /*
92476@@ -3236,8 +3267,8 @@ COMPAT_SYSCALL_DEFINE2(sigaltstack,
92477 }
92478 seg = get_fs();
92479 set_fs(KERNEL_DS);
92480- ret = do_sigaltstack((stack_t __force __user *) (uss_ptr ? &uss : NULL),
92481- (stack_t __force __user *) &uoss,
92482+ ret = do_sigaltstack((stack_t __force_user *) (uss_ptr ? &uss : NULL),
92483+ (stack_t __force_user *) &uoss,
92484 compat_user_stack_pointer());
92485 set_fs(seg);
92486 if (ret >= 0 && uoss_ptr) {
92487diff --git a/kernel/smpboot.c b/kernel/smpboot.c
92488index eb89e18..a4e6792 100644
92489--- a/kernel/smpboot.c
92490+++ b/kernel/smpboot.c
92491@@ -288,7 +288,7 @@ int smpboot_register_percpu_thread(struct smp_hotplug_thread *plug_thread)
92492 }
92493 smpboot_unpark_thread(plug_thread, cpu);
92494 }
92495- list_add(&plug_thread->list, &hotplug_threads);
92496+ pax_list_add(&plug_thread->list, &hotplug_threads);
92497 out:
92498 mutex_unlock(&smpboot_threads_lock);
92499 return ret;
92500@@ -305,7 +305,7 @@ void smpboot_unregister_percpu_thread(struct smp_hotplug_thread *plug_thread)
92501 {
92502 get_online_cpus();
92503 mutex_lock(&smpboot_threads_lock);
92504- list_del(&plug_thread->list);
92505+ pax_list_del(&plug_thread->list);
92506 smpboot_destroy_threads(plug_thread);
92507 mutex_unlock(&smpboot_threads_lock);
92508 put_online_cpus();
92509diff --git a/kernel/softirq.c b/kernel/softirq.c
92510index 0699add..d365ad8 100644
92511--- a/kernel/softirq.c
92512+++ b/kernel/softirq.c
92513@@ -53,7 +53,7 @@ irq_cpustat_t irq_stat[NR_CPUS] ____cacheline_aligned;
92514 EXPORT_SYMBOL(irq_stat);
92515 #endif
92516
92517-static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp;
92518+static struct softirq_action softirq_vec[NR_SOFTIRQS] __read_only __aligned(PAGE_SIZE);
92519
92520 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
92521
92522@@ -266,7 +266,7 @@ restart:
92523 kstat_incr_softirqs_this_cpu(vec_nr);
92524
92525 trace_softirq_entry(vec_nr);
92526- h->action(h);
92527+ h->action();
92528 trace_softirq_exit(vec_nr);
92529 if (unlikely(prev_count != preempt_count())) {
92530 pr_err("huh, entered softirq %u %s %p with preempt_count %08x, exited with %08x?\n",
92531@@ -426,7 +426,7 @@ void __raise_softirq_irqoff(unsigned int nr)
92532 or_softirq_pending(1UL << nr);
92533 }
92534
92535-void open_softirq(int nr, void (*action)(struct softirq_action *))
92536+void __init open_softirq(int nr, void (*action)(void))
92537 {
92538 softirq_vec[nr].action = action;
92539 }
92540@@ -478,7 +478,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
92541 }
92542 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
92543
92544-static void tasklet_action(struct softirq_action *a)
92545+static void tasklet_action(void)
92546 {
92547 struct tasklet_struct *list;
92548
92549@@ -514,7 +514,7 @@ static void tasklet_action(struct softirq_action *a)
92550 }
92551 }
92552
92553-static void tasklet_hi_action(struct softirq_action *a)
92554+static __latent_entropy void tasklet_hi_action(void)
92555 {
92556 struct tasklet_struct *list;
92557
92558@@ -741,7 +741,7 @@ static struct notifier_block cpu_nfb = {
92559 .notifier_call = cpu_callback
92560 };
92561
92562-static struct smp_hotplug_thread softirq_threads = {
92563+static struct smp_hotplug_thread softirq_threads __read_only = {
92564 .store = &ksoftirqd,
92565 .thread_should_run = ksoftirqd_should_run,
92566 .thread_fn = run_ksoftirqd,
92567diff --git a/kernel/sys.c b/kernel/sys.c
92568index 1eaa2f0..d80d27c 100644
92569--- a/kernel/sys.c
92570+++ b/kernel/sys.c
92571@@ -148,6 +148,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
92572 error = -EACCES;
92573 goto out;
92574 }
92575+
92576+ if (gr_handle_chroot_setpriority(p, niceval)) {
92577+ error = -EACCES;
92578+ goto out;
92579+ }
92580+
92581 no_nice = security_task_setnice(p, niceval);
92582 if (no_nice) {
92583 error = no_nice;
92584@@ -353,6 +359,20 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
92585 goto error;
92586 }
92587
92588+ if (gr_check_group_change(new->gid, new->egid, INVALID_GID))
92589+ goto error;
92590+
92591+ if (!gid_eq(new->gid, old->gid)) {
92592+ /* make sure we generate a learn log for what will
92593+ end up being a role transition after a full-learning
92594+ policy is generated
92595+ CAP_SETGID is required to perform a transition
92596+ we may not log a CAP_SETGID check above, e.g.
92597+ in the case where new rgid = old egid
92598+ */
92599+ gr_learn_cap(current, new, CAP_SETGID);
92600+ }
92601+
92602 if (rgid != (gid_t) -1 ||
92603 (egid != (gid_t) -1 && !gid_eq(kegid, old->gid)))
92604 new->sgid = new->egid;
92605@@ -388,6 +408,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
92606 old = current_cred();
92607
92608 retval = -EPERM;
92609+
92610+ if (gr_check_group_change(kgid, kgid, kgid))
92611+ goto error;
92612+
92613 if (ns_capable(old->user_ns, CAP_SETGID))
92614 new->gid = new->egid = new->sgid = new->fsgid = kgid;
92615 else if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->sgid))
92616@@ -405,7 +429,7 @@ error:
92617 /*
92618 * change the user struct in a credentials set to match the new UID
92619 */
92620-static int set_user(struct cred *new)
92621+int set_user(struct cred *new)
92622 {
92623 struct user_struct *new_user;
92624
92625@@ -485,7 +509,18 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
92626 goto error;
92627 }
92628
92629+ if (gr_check_user_change(new->uid, new->euid, INVALID_UID))
92630+ goto error;
92631+
92632 if (!uid_eq(new->uid, old->uid)) {
92633+ /* make sure we generate a learn log for what will
92634+ end up being a role transition after a full-learning
92635+ policy is generated
92636+ CAP_SETUID is required to perform a transition
92637+ we may not log a CAP_SETUID check above, e.g.
92638+ in the case where new ruid = old euid
92639+ */
92640+ gr_learn_cap(current, new, CAP_SETUID);
92641 retval = set_user(new);
92642 if (retval < 0)
92643 goto error;
92644@@ -535,6 +570,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
92645 old = current_cred();
92646
92647 retval = -EPERM;
92648+
92649+ if (gr_check_crash_uid(kuid))
92650+ goto error;
92651+ if (gr_check_user_change(kuid, kuid, kuid))
92652+ goto error;
92653+
92654 if (ns_capable(old->user_ns, CAP_SETUID)) {
92655 new->suid = new->uid = kuid;
92656 if (!uid_eq(kuid, old->uid)) {
92657@@ -604,6 +645,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
92658 goto error;
92659 }
92660
92661+ if (gr_check_user_change(kruid, keuid, INVALID_UID))
92662+ goto error;
92663+
92664 if (ruid != (uid_t) -1) {
92665 new->uid = kruid;
92666 if (!uid_eq(kruid, old->uid)) {
92667@@ -688,6 +732,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
92668 goto error;
92669 }
92670
92671+ if (gr_check_group_change(krgid, kegid, INVALID_GID))
92672+ goto error;
92673+
92674 if (rgid != (gid_t) -1)
92675 new->gid = krgid;
92676 if (egid != (gid_t) -1)
92677@@ -752,12 +799,16 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
92678 uid_eq(kuid, old->suid) || uid_eq(kuid, old->fsuid) ||
92679 ns_capable(old->user_ns, CAP_SETUID)) {
92680 if (!uid_eq(kuid, old->fsuid)) {
92681+ if (gr_check_user_change(INVALID_UID, INVALID_UID, kuid))
92682+ goto error;
92683+
92684 new->fsuid = kuid;
92685 if (security_task_fix_setuid(new, old, LSM_SETID_FS) == 0)
92686 goto change_okay;
92687 }
92688 }
92689
92690+error:
92691 abort_creds(new);
92692 return old_fsuid;
92693
92694@@ -790,12 +841,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
92695 if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->egid) ||
92696 gid_eq(kgid, old->sgid) || gid_eq(kgid, old->fsgid) ||
92697 ns_capable(old->user_ns, CAP_SETGID)) {
92698+ if (gr_check_group_change(INVALID_GID, INVALID_GID, kgid))
92699+ goto error;
92700+
92701 if (!gid_eq(kgid, old->fsgid)) {
92702 new->fsgid = kgid;
92703 goto change_okay;
92704 }
92705 }
92706
92707+error:
92708 abort_creds(new);
92709 return old_fsgid;
92710
92711@@ -1172,19 +1227,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
92712 return -EFAULT;
92713
92714 down_read(&uts_sem);
92715- error = __copy_to_user(&name->sysname, &utsname()->sysname,
92716+ error = __copy_to_user(name->sysname, &utsname()->sysname,
92717 __OLD_UTS_LEN);
92718 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
92719- error |= __copy_to_user(&name->nodename, &utsname()->nodename,
92720+ error |= __copy_to_user(name->nodename, &utsname()->nodename,
92721 __OLD_UTS_LEN);
92722 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
92723- error |= __copy_to_user(&name->release, &utsname()->release,
92724+ error |= __copy_to_user(name->release, &utsname()->release,
92725 __OLD_UTS_LEN);
92726 error |= __put_user(0, name->release + __OLD_UTS_LEN);
92727- error |= __copy_to_user(&name->version, &utsname()->version,
92728+ error |= __copy_to_user(name->version, &utsname()->version,
92729 __OLD_UTS_LEN);
92730 error |= __put_user(0, name->version + __OLD_UTS_LEN);
92731- error |= __copy_to_user(&name->machine, &utsname()->machine,
92732+ error |= __copy_to_user(name->machine, &utsname()->machine,
92733 __OLD_UTS_LEN);
92734 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
92735 up_read(&uts_sem);
92736@@ -1385,6 +1440,13 @@ int do_prlimit(struct task_struct *tsk, unsigned int resource,
92737 */
92738 new_rlim->rlim_cur = 1;
92739 }
92740+ /* Handle the case where a fork and setuid occur and then RLIMIT_NPROC
92741+ is changed to a lower value. Since tasks can be created by the same
92742+ user in between this limit change and an execve by this task, force
92743+ a recheck only for this task by setting PF_NPROC_EXCEEDED
92744+ */
92745+ if (resource == RLIMIT_NPROC && tsk->real_cred->user != INIT_USER)
92746+ tsk->flags |= PF_NPROC_EXCEEDED;
92747 }
92748 if (!retval) {
92749 if (old_rlim)
92750diff --git a/kernel/sysctl.c b/kernel/sysctl.c
92751index 15f2511..181b356 100644
92752--- a/kernel/sysctl.c
92753+++ b/kernel/sysctl.c
92754@@ -94,7 +94,6 @@
92755
92756
92757 #if defined(CONFIG_SYSCTL)
92758-
92759 /* External variables not in a header file. */
92760 extern int max_threads;
92761 extern int suid_dumpable;
92762@@ -115,19 +114,20 @@ extern int sysctl_nr_trim_pages;
92763
92764 /* Constants used for minimum and maximum */
92765 #ifdef CONFIG_LOCKUP_DETECTOR
92766-static int sixty = 60;
92767+static int sixty __read_only = 60;
92768 #endif
92769
92770-static int __maybe_unused neg_one = -1;
92771+static int __maybe_unused neg_one __read_only = -1;
92772
92773-static int zero;
92774-static int __maybe_unused one = 1;
92775-static int __maybe_unused two = 2;
92776-static int __maybe_unused four = 4;
92777-static unsigned long one_ul = 1;
92778-static int one_hundred = 100;
92779+static int zero __read_only = 0;
92780+static int __maybe_unused one __read_only = 1;
92781+static int __maybe_unused two __read_only = 2;
92782+static int __maybe_unused three __read_only = 3;
92783+static int __maybe_unused four __read_only = 4;
92784+static unsigned long one_ul __read_only = 1;
92785+static int one_hundred __read_only = 100;
92786 #ifdef CONFIG_PRINTK
92787-static int ten_thousand = 10000;
92788+static int ten_thousand __read_only = 10000;
92789 #endif
92790
92791 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
92792@@ -181,10 +181,8 @@ static int proc_taint(struct ctl_table *table, int write,
92793 void __user *buffer, size_t *lenp, loff_t *ppos);
92794 #endif
92795
92796-#ifdef CONFIG_PRINTK
92797 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
92798 void __user *buffer, size_t *lenp, loff_t *ppos);
92799-#endif
92800
92801 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
92802 void __user *buffer, size_t *lenp, loff_t *ppos);
92803@@ -215,6 +213,8 @@ static int sysrq_sysctl_handler(struct ctl_table *table, int write,
92804
92805 #endif
92806
92807+extern struct ctl_table grsecurity_table[];
92808+
92809 static struct ctl_table kern_table[];
92810 static struct ctl_table vm_table[];
92811 static struct ctl_table fs_table[];
92812@@ -229,6 +229,20 @@ extern struct ctl_table epoll_table[];
92813 int sysctl_legacy_va_layout;
92814 #endif
92815
92816+#ifdef CONFIG_PAX_SOFTMODE
92817+static struct ctl_table pax_table[] = {
92818+ {
92819+ .procname = "softmode",
92820+ .data = &pax_softmode,
92821+ .maxlen = sizeof(unsigned int),
92822+ .mode = 0600,
92823+ .proc_handler = &proc_dointvec,
92824+ },
92825+
92826+ { }
92827+};
92828+#endif
92829+
92830 /* The default sysctl tables: */
92831
92832 static struct ctl_table sysctl_base_table[] = {
92833@@ -277,6 +291,22 @@ static int max_extfrag_threshold = 1000;
92834 #endif
92835
92836 static struct ctl_table kern_table[] = {
92837+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
92838+ {
92839+ .procname = "grsecurity",
92840+ .mode = 0500,
92841+ .child = grsecurity_table,
92842+ },
92843+#endif
92844+
92845+#ifdef CONFIG_PAX_SOFTMODE
92846+ {
92847+ .procname = "pax",
92848+ .mode = 0500,
92849+ .child = pax_table,
92850+ },
92851+#endif
92852+
92853 {
92854 .procname = "sched_child_runs_first",
92855 .data = &sysctl_sched_child_runs_first,
92856@@ -642,7 +672,7 @@ static struct ctl_table kern_table[] = {
92857 .data = &modprobe_path,
92858 .maxlen = KMOD_PATH_LEN,
92859 .mode = 0644,
92860- .proc_handler = proc_dostring,
92861+ .proc_handler = proc_dostring_modpriv,
92862 },
92863 {
92864 .procname = "modules_disabled",
92865@@ -809,16 +839,20 @@ static struct ctl_table kern_table[] = {
92866 .extra1 = &zero,
92867 .extra2 = &one,
92868 },
92869+#endif
92870 {
92871 .procname = "kptr_restrict",
92872 .data = &kptr_restrict,
92873 .maxlen = sizeof(int),
92874 .mode = 0644,
92875 .proc_handler = proc_dointvec_minmax_sysadmin,
92876+#ifdef CONFIG_GRKERNSEC_HIDESYM
92877+ .extra1 = &two,
92878+#else
92879 .extra1 = &zero,
92880+#endif
92881 .extra2 = &two,
92882 },
92883-#endif
92884 {
92885 .procname = "ngroups_max",
92886 .data = &ngroups_max,
92887@@ -1065,10 +1099,17 @@ static struct ctl_table kern_table[] = {
92888 */
92889 {
92890 .procname = "perf_event_paranoid",
92891- .data = &sysctl_perf_event_paranoid,
92892- .maxlen = sizeof(sysctl_perf_event_paranoid),
92893+ .data = &sysctl_perf_event_legitimately_concerned,
92894+ .maxlen = sizeof(sysctl_perf_event_legitimately_concerned),
92895 .mode = 0644,
92896- .proc_handler = proc_dointvec,
92897+ /* go ahead, be a hero */
92898+ .proc_handler = proc_dointvec_minmax_sysadmin,
92899+ .extra1 = &neg_one,
92900+#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
92901+ .extra2 = &three,
92902+#else
92903+ .extra2 = &two,
92904+#endif
92905 },
92906 {
92907 .procname = "perf_event_mlock_kb",
92908@@ -1327,6 +1368,13 @@ static struct ctl_table vm_table[] = {
92909 .proc_handler = proc_dointvec_minmax,
92910 .extra1 = &zero,
92911 },
92912+ {
92913+ .procname = "heap_stack_gap",
92914+ .data = &sysctl_heap_stack_gap,
92915+ .maxlen = sizeof(sysctl_heap_stack_gap),
92916+ .mode = 0644,
92917+ .proc_handler = proc_doulongvec_minmax,
92918+ },
92919 #else
92920 {
92921 .procname = "nr_trim_pages",
92922@@ -1809,6 +1857,16 @@ int proc_dostring(struct ctl_table *table, int write,
92923 (char __user *)buffer, lenp, ppos);
92924 }
92925
92926+int proc_dostring_modpriv(struct ctl_table *table, int write,
92927+ void __user *buffer, size_t *lenp, loff_t *ppos)
92928+{
92929+ if (write && !capable(CAP_SYS_MODULE))
92930+ return -EPERM;
92931+
92932+ return _proc_do_string(table->data, table->maxlen, write,
92933+ buffer, lenp, ppos);
92934+}
92935+
92936 static size_t proc_skip_spaces(char **buf)
92937 {
92938 size_t ret;
92939@@ -1914,6 +1972,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
92940 len = strlen(tmp);
92941 if (len > *size)
92942 len = *size;
92943+ if (len > sizeof(tmp))
92944+ len = sizeof(tmp);
92945 if (copy_to_user(*buf, tmp, len))
92946 return -EFAULT;
92947 *size -= len;
92948@@ -2091,7 +2151,7 @@ int proc_dointvec(struct ctl_table *table, int write,
92949 static int proc_taint(struct ctl_table *table, int write,
92950 void __user *buffer, size_t *lenp, loff_t *ppos)
92951 {
92952- struct ctl_table t;
92953+ ctl_table_no_const t;
92954 unsigned long tmptaint = get_taint();
92955 int err;
92956
92957@@ -2119,7 +2179,6 @@ static int proc_taint(struct ctl_table *table, int write,
92958 return err;
92959 }
92960
92961-#ifdef CONFIG_PRINTK
92962 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
92963 void __user *buffer, size_t *lenp, loff_t *ppos)
92964 {
92965@@ -2128,7 +2187,6 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
92966
92967 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
92968 }
92969-#endif
92970
92971 struct do_proc_dointvec_minmax_conv_param {
92972 int *min;
92973@@ -2688,6 +2746,12 @@ int proc_dostring(struct ctl_table *table, int write,
92974 return -ENOSYS;
92975 }
92976
92977+int proc_dostring_modpriv(struct ctl_table *table, int write,
92978+ void __user *buffer, size_t *lenp, loff_t *ppos)
92979+{
92980+ return -ENOSYS;
92981+}
92982+
92983 int proc_dointvec(struct ctl_table *table, int write,
92984 void __user *buffer, size_t *lenp, loff_t *ppos)
92985 {
92986@@ -2744,5 +2808,6 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
92987 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
92988 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
92989 EXPORT_SYMBOL(proc_dostring);
92990+EXPORT_SYMBOL(proc_dostring_modpriv);
92991 EXPORT_SYMBOL(proc_doulongvec_minmax);
92992 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
92993diff --git a/kernel/taskstats.c b/kernel/taskstats.c
92994index b312fcc7..753d72d 100644
92995--- a/kernel/taskstats.c
92996+++ b/kernel/taskstats.c
92997@@ -28,9 +28,12 @@
92998 #include <linux/fs.h>
92999 #include <linux/file.h>
93000 #include <linux/pid_namespace.h>
93001+#include <linux/grsecurity.h>
93002 #include <net/genetlink.h>
93003 #include <linux/atomic.h>
93004
93005+extern int gr_is_taskstats_denied(int pid);
93006+
93007 /*
93008 * Maximum length of a cpumask that can be specified in
93009 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
93010@@ -576,6 +579,9 @@ err:
93011
93012 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
93013 {
93014+ if (gr_is_taskstats_denied(current->pid))
93015+ return -EACCES;
93016+
93017 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
93018 return cmd_attr_register_cpumask(info);
93019 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
93020diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
93021index a7077d3..dd48a49 100644
93022--- a/kernel/time/alarmtimer.c
93023+++ b/kernel/time/alarmtimer.c
93024@@ -823,7 +823,7 @@ static int __init alarmtimer_init(void)
93025 struct platform_device *pdev;
93026 int error = 0;
93027 int i;
93028- struct k_clock alarm_clock = {
93029+ static struct k_clock alarm_clock = {
93030 .clock_getres = alarm_clock_getres,
93031 .clock_get = alarm_clock_get,
93032 .timer_create = alarm_timer_create,
93033diff --git a/kernel/time/hrtimer.c b/kernel/time/hrtimer.c
93034index 37e50aa..57a9501 100644
93035--- a/kernel/time/hrtimer.c
93036+++ b/kernel/time/hrtimer.c
93037@@ -1399,7 +1399,7 @@ void hrtimer_peek_ahead_timers(void)
93038 local_irq_restore(flags);
93039 }
93040
93041-static void run_hrtimer_softirq(struct softirq_action *h)
93042+static __latent_entropy void run_hrtimer_softirq(void)
93043 {
93044 hrtimer_peek_ahead_timers();
93045 }
93046diff --git a/kernel/time/posix-cpu-timers.c b/kernel/time/posix-cpu-timers.c
93047index a16b678..8c5bd9d 100644
93048--- a/kernel/time/posix-cpu-timers.c
93049+++ b/kernel/time/posix-cpu-timers.c
93050@@ -1450,14 +1450,14 @@ struct k_clock clock_posix_cpu = {
93051
93052 static __init int init_posix_cpu_timers(void)
93053 {
93054- struct k_clock process = {
93055+ static struct k_clock process = {
93056 .clock_getres = process_cpu_clock_getres,
93057 .clock_get = process_cpu_clock_get,
93058 .timer_create = process_cpu_timer_create,
93059 .nsleep = process_cpu_nsleep,
93060 .nsleep_restart = process_cpu_nsleep_restart,
93061 };
93062- struct k_clock thread = {
93063+ static struct k_clock thread = {
93064 .clock_getres = thread_cpu_clock_getres,
93065 .clock_get = thread_cpu_clock_get,
93066 .timer_create = thread_cpu_timer_create,
93067diff --git a/kernel/time/posix-timers.c b/kernel/time/posix-timers.c
93068index 31ea01f..7fc61ef 100644
93069--- a/kernel/time/posix-timers.c
93070+++ b/kernel/time/posix-timers.c
93071@@ -43,6 +43,7 @@
93072 #include <linux/hash.h>
93073 #include <linux/posix-clock.h>
93074 #include <linux/posix-timers.h>
93075+#include <linux/grsecurity.h>
93076 #include <linux/syscalls.h>
93077 #include <linux/wait.h>
93078 #include <linux/workqueue.h>
93079@@ -124,7 +125,7 @@ static DEFINE_SPINLOCK(hash_lock);
93080 * which we beg off on and pass to do_sys_settimeofday().
93081 */
93082
93083-static struct k_clock posix_clocks[MAX_CLOCKS];
93084+static struct k_clock *posix_clocks[MAX_CLOCKS];
93085
93086 /*
93087 * These ones are defined below.
93088@@ -277,7 +278,7 @@ static int posix_get_tai(clockid_t which_clock, struct timespec *tp)
93089 */
93090 static __init int init_posix_timers(void)
93091 {
93092- struct k_clock clock_realtime = {
93093+ static struct k_clock clock_realtime = {
93094 .clock_getres = hrtimer_get_res,
93095 .clock_get = posix_clock_realtime_get,
93096 .clock_set = posix_clock_realtime_set,
93097@@ -289,7 +290,7 @@ static __init int init_posix_timers(void)
93098 .timer_get = common_timer_get,
93099 .timer_del = common_timer_del,
93100 };
93101- struct k_clock clock_monotonic = {
93102+ static struct k_clock clock_monotonic = {
93103 .clock_getres = hrtimer_get_res,
93104 .clock_get = posix_ktime_get_ts,
93105 .nsleep = common_nsleep,
93106@@ -299,19 +300,19 @@ static __init int init_posix_timers(void)
93107 .timer_get = common_timer_get,
93108 .timer_del = common_timer_del,
93109 };
93110- struct k_clock clock_monotonic_raw = {
93111+ static struct k_clock clock_monotonic_raw = {
93112 .clock_getres = hrtimer_get_res,
93113 .clock_get = posix_get_monotonic_raw,
93114 };
93115- struct k_clock clock_realtime_coarse = {
93116+ static struct k_clock clock_realtime_coarse = {
93117 .clock_getres = posix_get_coarse_res,
93118 .clock_get = posix_get_realtime_coarse,
93119 };
93120- struct k_clock clock_monotonic_coarse = {
93121+ static struct k_clock clock_monotonic_coarse = {
93122 .clock_getres = posix_get_coarse_res,
93123 .clock_get = posix_get_monotonic_coarse,
93124 };
93125- struct k_clock clock_tai = {
93126+ static struct k_clock clock_tai = {
93127 .clock_getres = hrtimer_get_res,
93128 .clock_get = posix_get_tai,
93129 .nsleep = common_nsleep,
93130@@ -321,7 +322,7 @@ static __init int init_posix_timers(void)
93131 .timer_get = common_timer_get,
93132 .timer_del = common_timer_del,
93133 };
93134- struct k_clock clock_boottime = {
93135+ static struct k_clock clock_boottime = {
93136 .clock_getres = hrtimer_get_res,
93137 .clock_get = posix_get_boottime,
93138 .nsleep = common_nsleep,
93139@@ -533,7 +534,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
93140 return;
93141 }
93142
93143- posix_clocks[clock_id] = *new_clock;
93144+ posix_clocks[clock_id] = new_clock;
93145 }
93146 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
93147
93148@@ -579,9 +580,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
93149 return (id & CLOCKFD_MASK) == CLOCKFD ?
93150 &clock_posix_dynamic : &clock_posix_cpu;
93151
93152- if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
93153+ if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
93154 return NULL;
93155- return &posix_clocks[id];
93156+ return posix_clocks[id];
93157 }
93158
93159 static int common_timer_create(struct k_itimer *new_timer)
93160@@ -599,7 +600,7 @@ SYSCALL_DEFINE3(timer_create, const clockid_t, which_clock,
93161 struct k_clock *kc = clockid_to_kclock(which_clock);
93162 struct k_itimer *new_timer;
93163 int error, new_timer_id;
93164- sigevent_t event;
93165+ sigevent_t event = { };
93166 int it_id_set = IT_ID_NOT_SET;
93167
93168 if (!kc)
93169@@ -1014,6 +1015,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
93170 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
93171 return -EFAULT;
93172
93173+ /* only the CLOCK_REALTIME clock can be set, all other clocks
93174+ have their clock_set fptr set to a nosettime dummy function
93175+ CLOCK_REALTIME has a NULL clock_set fptr which causes it to
93176+ call common_clock_set, which calls do_sys_settimeofday, which
93177+ we hook
93178+ */
93179+
93180 return kc->clock_set(which_clock, &new_tp);
93181 }
93182
93183diff --git a/kernel/time/time.c b/kernel/time/time.c
93184index a9ae20f..d3fbde7 100644
93185--- a/kernel/time/time.c
93186+++ b/kernel/time/time.c
93187@@ -173,6 +173,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
93188 return error;
93189
93190 if (tz) {
93191+ /* we log in do_settimeofday called below, so don't log twice
93192+ */
93193+ if (!tv)
93194+ gr_log_timechange();
93195+
93196 sys_tz = *tz;
93197 update_vsyscall_tz();
93198 if (firsttime) {
93199diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
93200index ec1791f..6a086cd 100644
93201--- a/kernel/time/timekeeping.c
93202+++ b/kernel/time/timekeeping.c
93203@@ -15,6 +15,7 @@
93204 #include <linux/init.h>
93205 #include <linux/mm.h>
93206 #include <linux/sched.h>
93207+#include <linux/grsecurity.h>
93208 #include <linux/syscore_ops.h>
93209 #include <linux/clocksource.h>
93210 #include <linux/jiffies.h>
93211@@ -717,6 +718,8 @@ int do_settimeofday(const struct timespec *tv)
93212 if (!timespec_valid_strict(tv))
93213 return -EINVAL;
93214
93215+ gr_log_timechange();
93216+
93217 raw_spin_lock_irqsave(&timekeeper_lock, flags);
93218 write_seqcount_begin(&tk_core.seq);
93219
93220diff --git a/kernel/time/timer.c b/kernel/time/timer.c
93221index 3260ffd..c93cd5e 100644
93222--- a/kernel/time/timer.c
93223+++ b/kernel/time/timer.c
93224@@ -1394,7 +1394,7 @@ void update_process_times(int user_tick)
93225 /*
93226 * This function runs timers and the timer-tq in bottom half context.
93227 */
93228-static void run_timer_softirq(struct softirq_action *h)
93229+static __latent_entropy void run_timer_softirq(void)
93230 {
93231 struct tvec_base *base = __this_cpu_read(tvec_bases);
93232
93233@@ -1457,7 +1457,7 @@ static void process_timeout(unsigned long __data)
93234 *
93235 * In all cases the return value is guaranteed to be non-negative.
93236 */
93237-signed long __sched schedule_timeout(signed long timeout)
93238+signed long __sched __intentional_overflow(-1) schedule_timeout(signed long timeout)
93239 {
93240 struct timer_list timer;
93241 unsigned long expire;
93242diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
93243index 61ed862..3b52c65 100644
93244--- a/kernel/time/timer_list.c
93245+++ b/kernel/time/timer_list.c
93246@@ -45,12 +45,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
93247
93248 static void print_name_offset(struct seq_file *m, void *sym)
93249 {
93250+#ifdef CONFIG_GRKERNSEC_HIDESYM
93251+ SEQ_printf(m, "<%p>", NULL);
93252+#else
93253 char symname[KSYM_NAME_LEN];
93254
93255 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
93256 SEQ_printf(m, "<%pK>", sym);
93257 else
93258 SEQ_printf(m, "%s", symname);
93259+#endif
93260 }
93261
93262 static void
93263@@ -119,7 +123,11 @@ next_one:
93264 static void
93265 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
93266 {
93267+#ifdef CONFIG_GRKERNSEC_HIDESYM
93268+ SEQ_printf(m, " .base: %p\n", NULL);
93269+#else
93270 SEQ_printf(m, " .base: %pK\n", base);
93271+#endif
93272 SEQ_printf(m, " .index: %d\n",
93273 base->index);
93274 SEQ_printf(m, " .resolution: %Lu nsecs\n",
93275@@ -362,7 +370,11 @@ static int __init init_timer_list_procfs(void)
93276 {
93277 struct proc_dir_entry *pe;
93278
93279+#ifdef CONFIG_GRKERNSEC_PROC_ADD
93280+ pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
93281+#else
93282 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
93283+#endif
93284 if (!pe)
93285 return -ENOMEM;
93286 return 0;
93287diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
93288index 1fb08f2..ca4bb1e 100644
93289--- a/kernel/time/timer_stats.c
93290+++ b/kernel/time/timer_stats.c
93291@@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
93292 static unsigned long nr_entries;
93293 static struct entry entries[MAX_ENTRIES];
93294
93295-static atomic_t overflow_count;
93296+static atomic_unchecked_t overflow_count;
93297
93298 /*
93299 * The entries are in a hash-table, for fast lookup:
93300@@ -140,7 +140,7 @@ static void reset_entries(void)
93301 nr_entries = 0;
93302 memset(entries, 0, sizeof(entries));
93303 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
93304- atomic_set(&overflow_count, 0);
93305+ atomic_set_unchecked(&overflow_count, 0);
93306 }
93307
93308 static struct entry *alloc_entry(void)
93309@@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
93310 if (likely(entry))
93311 entry->count++;
93312 else
93313- atomic_inc(&overflow_count);
93314+ atomic_inc_unchecked(&overflow_count);
93315
93316 out_unlock:
93317 raw_spin_unlock_irqrestore(lock, flags);
93318@@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
93319
93320 static void print_name_offset(struct seq_file *m, unsigned long addr)
93321 {
93322+#ifdef CONFIG_GRKERNSEC_HIDESYM
93323+ seq_printf(m, "<%p>", NULL);
93324+#else
93325 char symname[KSYM_NAME_LEN];
93326
93327 if (lookup_symbol_name(addr, symname) < 0)
93328- seq_printf(m, "<%p>", (void *)addr);
93329+ seq_printf(m, "<%pK>", (void *)addr);
93330 else
93331 seq_printf(m, "%s", symname);
93332+#endif
93333 }
93334
93335 static int tstats_show(struct seq_file *m, void *v)
93336@@ -300,8 +304,8 @@ static int tstats_show(struct seq_file *m, void *v)
93337
93338 seq_puts(m, "Timer Stats Version: v0.3\n");
93339 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
93340- if (atomic_read(&overflow_count))
93341- seq_printf(m, "Overflow: %d entries\n", atomic_read(&overflow_count));
93342+ if (atomic_read_unchecked(&overflow_count))
93343+ seq_printf(m, "Overflow: %d entries\n", atomic_read_unchecked(&overflow_count));
93344 seq_printf(m, "Collection: %s\n", timer_stats_active ? "active" : "inactive");
93345
93346 for (i = 0; i < nr_entries; i++) {
93347@@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
93348 {
93349 struct proc_dir_entry *pe;
93350
93351+#ifdef CONFIG_GRKERNSEC_PROC_ADD
93352+ pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
93353+#else
93354 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
93355+#endif
93356 if (!pe)
93357 return -ENOMEM;
93358 return 0;
93359diff --git a/kernel/torture.c b/kernel/torture.c
93360index dd70993..0bf694b 100644
93361--- a/kernel/torture.c
93362+++ b/kernel/torture.c
93363@@ -482,7 +482,7 @@ static int torture_shutdown_notify(struct notifier_block *unused1,
93364 mutex_lock(&fullstop_mutex);
93365 if (ACCESS_ONCE(fullstop) == FULLSTOP_DONTSTOP) {
93366 VERBOSE_TOROUT_STRING("Unscheduled system shutdown detected");
93367- ACCESS_ONCE(fullstop) = FULLSTOP_SHUTDOWN;
93368+ ACCESS_ONCE_RW(fullstop) = FULLSTOP_SHUTDOWN;
93369 } else {
93370 pr_warn("Concurrent rmmod and shutdown illegal!\n");
93371 }
93372@@ -549,14 +549,14 @@ static int torture_stutter(void *arg)
93373 if (!torture_must_stop()) {
93374 if (stutter > 1) {
93375 schedule_timeout_interruptible(stutter - 1);
93376- ACCESS_ONCE(stutter_pause_test) = 2;
93377+ ACCESS_ONCE_RW(stutter_pause_test) = 2;
93378 }
93379 schedule_timeout_interruptible(1);
93380- ACCESS_ONCE(stutter_pause_test) = 1;
93381+ ACCESS_ONCE_RW(stutter_pause_test) = 1;
93382 }
93383 if (!torture_must_stop())
93384 schedule_timeout_interruptible(stutter);
93385- ACCESS_ONCE(stutter_pause_test) = 0;
93386+ ACCESS_ONCE_RW(stutter_pause_test) = 0;
93387 torture_shutdown_absorb("torture_stutter");
93388 } while (!torture_must_stop());
93389 torture_kthread_stopping("torture_stutter");
93390@@ -648,7 +648,7 @@ bool torture_cleanup_begin(void)
93391 schedule_timeout_uninterruptible(10);
93392 return true;
93393 }
93394- ACCESS_ONCE(fullstop) = FULLSTOP_RMMOD;
93395+ ACCESS_ONCE_RW(fullstop) = FULLSTOP_RMMOD;
93396 mutex_unlock(&fullstop_mutex);
93397 torture_shutdown_cleanup();
93398 torture_shuffle_cleanup();
93399diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
93400index c1bd4ad..4b861dc 100644
93401--- a/kernel/trace/blktrace.c
93402+++ b/kernel/trace/blktrace.c
93403@@ -328,7 +328,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
93404 struct blk_trace *bt = filp->private_data;
93405 char buf[16];
93406
93407- snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
93408+ snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
93409
93410 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
93411 }
93412@@ -386,7 +386,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
93413 return 1;
93414
93415 bt = buf->chan->private_data;
93416- atomic_inc(&bt->dropped);
93417+ atomic_inc_unchecked(&bt->dropped);
93418 return 0;
93419 }
93420
93421@@ -487,7 +487,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
93422
93423 bt->dir = dir;
93424 bt->dev = dev;
93425- atomic_set(&bt->dropped, 0);
93426+ atomic_set_unchecked(&bt->dropped, 0);
93427 INIT_LIST_HEAD(&bt->running_list);
93428
93429 ret = -EIO;
93430diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
93431index 31c90fe..051ce98 100644
93432--- a/kernel/trace/ftrace.c
93433+++ b/kernel/trace/ftrace.c
93434@@ -2183,12 +2183,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
93435 if (unlikely(ftrace_disabled))
93436 return 0;
93437
93438+ ret = ftrace_arch_code_modify_prepare();
93439+ FTRACE_WARN_ON(ret);
93440+ if (ret)
93441+ return 0;
93442+
93443 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
93444+ FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
93445 if (ret) {
93446 ftrace_bug(ret, ip);
93447- return 0;
93448 }
93449- return 1;
93450+ return ret ? 0 : 1;
93451 }
93452
93453 /*
93454@@ -4492,8 +4497,10 @@ static int ftrace_process_locs(struct module *mod,
93455 if (!count)
93456 return 0;
93457
93458+ pax_open_kernel();
93459 sort(start, count, sizeof(*start),
93460 ftrace_cmp_ips, ftrace_swap_ips);
93461+ pax_close_kernel();
93462
93463 start_pg = ftrace_allocate_pages(count);
93464 if (!start_pg)
93465@@ -5340,7 +5347,7 @@ static int alloc_retstack_tasklist(struct ftrace_ret_stack **ret_stack_list)
93466
93467 if (t->ret_stack == NULL) {
93468 atomic_set(&t->tracing_graph_pause, 0);
93469- atomic_set(&t->trace_overrun, 0);
93470+ atomic_set_unchecked(&t->trace_overrun, 0);
93471 t->curr_ret_stack = -1;
93472 /* Make sure the tasks see the -1 first: */
93473 smp_wmb();
93474@@ -5553,7 +5560,7 @@ static void
93475 graph_init_task(struct task_struct *t, struct ftrace_ret_stack *ret_stack)
93476 {
93477 atomic_set(&t->tracing_graph_pause, 0);
93478- atomic_set(&t->trace_overrun, 0);
93479+ atomic_set_unchecked(&t->trace_overrun, 0);
93480 t->ftrace_timestamp = 0;
93481 /* make curr_ret_stack visible before we add the ret_stack */
93482 smp_wmb();
93483diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
93484index a56e07c..d46f0ba 100644
93485--- a/kernel/trace/ring_buffer.c
93486+++ b/kernel/trace/ring_buffer.c
93487@@ -352,9 +352,9 @@ struct buffer_data_page {
93488 */
93489 struct buffer_page {
93490 struct list_head list; /* list of buffer pages */
93491- local_t write; /* index for next write */
93492+ local_unchecked_t write; /* index for next write */
93493 unsigned read; /* index for next read */
93494- local_t entries; /* entries on this page */
93495+ local_unchecked_t entries; /* entries on this page */
93496 unsigned long real_end; /* real end of data */
93497 struct buffer_data_page *page; /* Actual data page */
93498 };
93499@@ -473,8 +473,8 @@ struct ring_buffer_per_cpu {
93500 unsigned long last_overrun;
93501 local_t entries_bytes;
93502 local_t entries;
93503- local_t overrun;
93504- local_t commit_overrun;
93505+ local_unchecked_t overrun;
93506+ local_unchecked_t commit_overrun;
93507 local_t dropped_events;
93508 local_t committing;
93509 local_t commits;
93510@@ -1032,8 +1032,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
93511 *
93512 * We add a counter to the write field to denote this.
93513 */
93514- old_write = local_add_return(RB_WRITE_INTCNT, &next_page->write);
93515- old_entries = local_add_return(RB_WRITE_INTCNT, &next_page->entries);
93516+ old_write = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->write);
93517+ old_entries = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->entries);
93518
93519 /*
93520 * Just make sure we have seen our old_write and synchronize
93521@@ -1061,8 +1061,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
93522 * cmpxchg to only update if an interrupt did not already
93523 * do it for us. If the cmpxchg fails, we don't care.
93524 */
93525- (void)local_cmpxchg(&next_page->write, old_write, val);
93526- (void)local_cmpxchg(&next_page->entries, old_entries, eval);
93527+ (void)local_cmpxchg_unchecked(&next_page->write, old_write, val);
93528+ (void)local_cmpxchg_unchecked(&next_page->entries, old_entries, eval);
93529
93530 /*
93531 * No need to worry about races with clearing out the commit.
93532@@ -1429,12 +1429,12 @@ static void rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer);
93533
93534 static inline unsigned long rb_page_entries(struct buffer_page *bpage)
93535 {
93536- return local_read(&bpage->entries) & RB_WRITE_MASK;
93537+ return local_read_unchecked(&bpage->entries) & RB_WRITE_MASK;
93538 }
93539
93540 static inline unsigned long rb_page_write(struct buffer_page *bpage)
93541 {
93542- return local_read(&bpage->write) & RB_WRITE_MASK;
93543+ return local_read_unchecked(&bpage->write) & RB_WRITE_MASK;
93544 }
93545
93546 static int
93547@@ -1529,7 +1529,7 @@ rb_remove_pages(struct ring_buffer_per_cpu *cpu_buffer, unsigned int nr_pages)
93548 * bytes consumed in ring buffer from here.
93549 * Increment overrun to account for the lost events.
93550 */
93551- local_add(page_entries, &cpu_buffer->overrun);
93552+ local_add_unchecked(page_entries, &cpu_buffer->overrun);
93553 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
93554 }
93555
93556@@ -2091,7 +2091,7 @@ rb_handle_head_page(struct ring_buffer_per_cpu *cpu_buffer,
93557 * it is our responsibility to update
93558 * the counters.
93559 */
93560- local_add(entries, &cpu_buffer->overrun);
93561+ local_add_unchecked(entries, &cpu_buffer->overrun);
93562 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
93563
93564 /*
93565@@ -2241,7 +2241,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
93566 if (tail == BUF_PAGE_SIZE)
93567 tail_page->real_end = 0;
93568
93569- local_sub(length, &tail_page->write);
93570+ local_sub_unchecked(length, &tail_page->write);
93571 return;
93572 }
93573
93574@@ -2276,7 +2276,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
93575 rb_event_set_padding(event);
93576
93577 /* Set the write back to the previous setting */
93578- local_sub(length, &tail_page->write);
93579+ local_sub_unchecked(length, &tail_page->write);
93580 return;
93581 }
93582
93583@@ -2288,7 +2288,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
93584
93585 /* Set write to end of buffer */
93586 length = (tail + length) - BUF_PAGE_SIZE;
93587- local_sub(length, &tail_page->write);
93588+ local_sub_unchecked(length, &tail_page->write);
93589 }
93590
93591 /*
93592@@ -2314,7 +2314,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
93593 * about it.
93594 */
93595 if (unlikely(next_page == commit_page)) {
93596- local_inc(&cpu_buffer->commit_overrun);
93597+ local_inc_unchecked(&cpu_buffer->commit_overrun);
93598 goto out_reset;
93599 }
93600
93601@@ -2370,7 +2370,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
93602 cpu_buffer->tail_page) &&
93603 (cpu_buffer->commit_page ==
93604 cpu_buffer->reader_page))) {
93605- local_inc(&cpu_buffer->commit_overrun);
93606+ local_inc_unchecked(&cpu_buffer->commit_overrun);
93607 goto out_reset;
93608 }
93609 }
93610@@ -2418,7 +2418,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
93611 length += RB_LEN_TIME_EXTEND;
93612
93613 tail_page = cpu_buffer->tail_page;
93614- write = local_add_return(length, &tail_page->write);
93615+ write = local_add_return_unchecked(length, &tail_page->write);
93616
93617 /* set write to only the index of the write */
93618 write &= RB_WRITE_MASK;
93619@@ -2442,7 +2442,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
93620 kmemcheck_annotate_bitfield(event, bitfield);
93621 rb_update_event(cpu_buffer, event, length, add_timestamp, delta);
93622
93623- local_inc(&tail_page->entries);
93624+ local_inc_unchecked(&tail_page->entries);
93625
93626 /*
93627 * If this is the first commit on the page, then update
93628@@ -2475,7 +2475,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
93629
93630 if (bpage->page == (void *)addr && rb_page_write(bpage) == old_index) {
93631 unsigned long write_mask =
93632- local_read(&bpage->write) & ~RB_WRITE_MASK;
93633+ local_read_unchecked(&bpage->write) & ~RB_WRITE_MASK;
93634 unsigned long event_length = rb_event_length(event);
93635 /*
93636 * This is on the tail page. It is possible that
93637@@ -2485,7 +2485,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
93638 */
93639 old_index += write_mask;
93640 new_index += write_mask;
93641- index = local_cmpxchg(&bpage->write, old_index, new_index);
93642+ index = local_cmpxchg_unchecked(&bpage->write, old_index, new_index);
93643 if (index == old_index) {
93644 /* update counters */
93645 local_sub(event_length, &cpu_buffer->entries_bytes);
93646@@ -2877,7 +2877,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
93647
93648 /* Do the likely case first */
93649 if (likely(bpage->page == (void *)addr)) {
93650- local_dec(&bpage->entries);
93651+ local_dec_unchecked(&bpage->entries);
93652 return;
93653 }
93654
93655@@ -2889,7 +2889,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
93656 start = bpage;
93657 do {
93658 if (bpage->page == (void *)addr) {
93659- local_dec(&bpage->entries);
93660+ local_dec_unchecked(&bpage->entries);
93661 return;
93662 }
93663 rb_inc_page(cpu_buffer, &bpage);
93664@@ -3173,7 +3173,7 @@ static inline unsigned long
93665 rb_num_of_entries(struct ring_buffer_per_cpu *cpu_buffer)
93666 {
93667 return local_read(&cpu_buffer->entries) -
93668- (local_read(&cpu_buffer->overrun) + cpu_buffer->read);
93669+ (local_read_unchecked(&cpu_buffer->overrun) + cpu_buffer->read);
93670 }
93671
93672 /**
93673@@ -3262,7 +3262,7 @@ unsigned long ring_buffer_overrun_cpu(struct ring_buffer *buffer, int cpu)
93674 return 0;
93675
93676 cpu_buffer = buffer->buffers[cpu];
93677- ret = local_read(&cpu_buffer->overrun);
93678+ ret = local_read_unchecked(&cpu_buffer->overrun);
93679
93680 return ret;
93681 }
93682@@ -3285,7 +3285,7 @@ ring_buffer_commit_overrun_cpu(struct ring_buffer *buffer, int cpu)
93683 return 0;
93684
93685 cpu_buffer = buffer->buffers[cpu];
93686- ret = local_read(&cpu_buffer->commit_overrun);
93687+ ret = local_read_unchecked(&cpu_buffer->commit_overrun);
93688
93689 return ret;
93690 }
93691@@ -3370,7 +3370,7 @@ unsigned long ring_buffer_overruns(struct ring_buffer *buffer)
93692 /* if you care about this being correct, lock the buffer */
93693 for_each_buffer_cpu(buffer, cpu) {
93694 cpu_buffer = buffer->buffers[cpu];
93695- overruns += local_read(&cpu_buffer->overrun);
93696+ overruns += local_read_unchecked(&cpu_buffer->overrun);
93697 }
93698
93699 return overruns;
93700@@ -3541,8 +3541,8 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
93701 /*
93702 * Reset the reader page to size zero.
93703 */
93704- local_set(&cpu_buffer->reader_page->write, 0);
93705- local_set(&cpu_buffer->reader_page->entries, 0);
93706+ local_set_unchecked(&cpu_buffer->reader_page->write, 0);
93707+ local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
93708 local_set(&cpu_buffer->reader_page->page->commit, 0);
93709 cpu_buffer->reader_page->real_end = 0;
93710
93711@@ -3576,7 +3576,7 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
93712 * want to compare with the last_overrun.
93713 */
93714 smp_mb();
93715- overwrite = local_read(&(cpu_buffer->overrun));
93716+ overwrite = local_read_unchecked(&(cpu_buffer->overrun));
93717
93718 /*
93719 * Here's the tricky part.
93720@@ -4148,8 +4148,8 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
93721
93722 cpu_buffer->head_page
93723 = list_entry(cpu_buffer->pages, struct buffer_page, list);
93724- local_set(&cpu_buffer->head_page->write, 0);
93725- local_set(&cpu_buffer->head_page->entries, 0);
93726+ local_set_unchecked(&cpu_buffer->head_page->write, 0);
93727+ local_set_unchecked(&cpu_buffer->head_page->entries, 0);
93728 local_set(&cpu_buffer->head_page->page->commit, 0);
93729
93730 cpu_buffer->head_page->read = 0;
93731@@ -4159,14 +4159,14 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
93732
93733 INIT_LIST_HEAD(&cpu_buffer->reader_page->list);
93734 INIT_LIST_HEAD(&cpu_buffer->new_pages);
93735- local_set(&cpu_buffer->reader_page->write, 0);
93736- local_set(&cpu_buffer->reader_page->entries, 0);
93737+ local_set_unchecked(&cpu_buffer->reader_page->write, 0);
93738+ local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
93739 local_set(&cpu_buffer->reader_page->page->commit, 0);
93740 cpu_buffer->reader_page->read = 0;
93741
93742 local_set(&cpu_buffer->entries_bytes, 0);
93743- local_set(&cpu_buffer->overrun, 0);
93744- local_set(&cpu_buffer->commit_overrun, 0);
93745+ local_set_unchecked(&cpu_buffer->overrun, 0);
93746+ local_set_unchecked(&cpu_buffer->commit_overrun, 0);
93747 local_set(&cpu_buffer->dropped_events, 0);
93748 local_set(&cpu_buffer->entries, 0);
93749 local_set(&cpu_buffer->committing, 0);
93750@@ -4571,8 +4571,8 @@ int ring_buffer_read_page(struct ring_buffer *buffer,
93751 rb_init_page(bpage);
93752 bpage = reader->page;
93753 reader->page = *data_page;
93754- local_set(&reader->write, 0);
93755- local_set(&reader->entries, 0);
93756+ local_set_unchecked(&reader->write, 0);
93757+ local_set_unchecked(&reader->entries, 0);
93758 reader->read = 0;
93759 *data_page = bpage;
93760
93761diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
93762index 426962b..e8e2d9a 100644
93763--- a/kernel/trace/trace.c
93764+++ b/kernel/trace/trace.c
93765@@ -3488,7 +3488,7 @@ int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set)
93766 return 0;
93767 }
93768
93769-int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled)
93770+int set_tracer_flag(struct trace_array *tr, unsigned long mask, int enabled)
93771 {
93772 /* do nothing if flag is already set */
93773 if (!!(trace_flags & mask) == !!enabled)
93774diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h
93775index 385391f..8d2250f 100644
93776--- a/kernel/trace/trace.h
93777+++ b/kernel/trace/trace.h
93778@@ -1280,7 +1280,7 @@ extern const char *__stop___tracepoint_str[];
93779 void trace_printk_init_buffers(void);
93780 void trace_printk_start_comm(void);
93781 int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set);
93782-int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled);
93783+int set_tracer_flag(struct trace_array *tr, unsigned long mask, int enabled);
93784
93785 /*
93786 * Normal trace_printk() and friends allocates special buffers
93787diff --git a/kernel/trace/trace_clock.c b/kernel/trace/trace_clock.c
93788index 57b67b1..66082a9 100644
93789--- a/kernel/trace/trace_clock.c
93790+++ b/kernel/trace/trace_clock.c
93791@@ -124,7 +124,7 @@ u64 notrace trace_clock_global(void)
93792 return now;
93793 }
93794
93795-static atomic64_t trace_counter;
93796+static atomic64_unchecked_t trace_counter;
93797
93798 /*
93799 * trace_clock_counter(): simply an atomic counter.
93800@@ -133,5 +133,5 @@ static atomic64_t trace_counter;
93801 */
93802 u64 notrace trace_clock_counter(void)
93803 {
93804- return atomic64_add_return(1, &trace_counter);
93805+ return atomic64_inc_return_unchecked(&trace_counter);
93806 }
93807diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
93808index 1b0df1e..4ebb965 100644
93809--- a/kernel/trace/trace_events.c
93810+++ b/kernel/trace/trace_events.c
93811@@ -1720,7 +1720,6 @@ __trace_early_add_new_event(struct ftrace_event_call *call,
93812 return 0;
93813 }
93814
93815-struct ftrace_module_file_ops;
93816 static void __add_event_to_tracers(struct ftrace_event_call *call);
93817
93818 /* Add an additional event_call dynamically */
93819diff --git a/kernel/trace/trace_functions_graph.c b/kernel/trace/trace_functions_graph.c
93820index f0a0c98..3692dc8 100644
93821--- a/kernel/trace/trace_functions_graph.c
93822+++ b/kernel/trace/trace_functions_graph.c
93823@@ -133,7 +133,7 @@ ftrace_push_return_trace(unsigned long ret, unsigned long func, int *depth,
93824
93825 /* The return trace stack is full */
93826 if (current->curr_ret_stack == FTRACE_RETFUNC_DEPTH - 1) {
93827- atomic_inc(&current->trace_overrun);
93828+ atomic_inc_unchecked(&current->trace_overrun);
93829 return -EBUSY;
93830 }
93831
93832@@ -230,7 +230,7 @@ ftrace_pop_return_trace(struct ftrace_graph_ret *trace, unsigned long *ret,
93833 *ret = current->ret_stack[index].ret;
93834 trace->func = current->ret_stack[index].func;
93835 trace->calltime = current->ret_stack[index].calltime;
93836- trace->overrun = atomic_read(&current->trace_overrun);
93837+ trace->overrun = atomic_read_unchecked(&current->trace_overrun);
93838 trace->depth = index;
93839 }
93840
93841diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
93842index 0abd9b8..6a663a2 100644
93843--- a/kernel/trace/trace_mmiotrace.c
93844+++ b/kernel/trace/trace_mmiotrace.c
93845@@ -24,7 +24,7 @@ struct header_iter {
93846 static struct trace_array *mmio_trace_array;
93847 static bool overrun_detected;
93848 static unsigned long prev_overruns;
93849-static atomic_t dropped_count;
93850+static atomic_unchecked_t dropped_count;
93851
93852 static void mmio_reset_data(struct trace_array *tr)
93853 {
93854@@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
93855
93856 static unsigned long count_overruns(struct trace_iterator *iter)
93857 {
93858- unsigned long cnt = atomic_xchg(&dropped_count, 0);
93859+ unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
93860 unsigned long over = ring_buffer_overruns(iter->trace_buffer->buffer);
93861
93862 if (over > prev_overruns)
93863@@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
93864 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
93865 sizeof(*entry), 0, pc);
93866 if (!event) {
93867- atomic_inc(&dropped_count);
93868+ atomic_inc_unchecked(&dropped_count);
93869 return;
93870 }
93871 entry = ring_buffer_event_data(event);
93872@@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
93873 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
93874 sizeof(*entry), 0, pc);
93875 if (!event) {
93876- atomic_inc(&dropped_count);
93877+ atomic_inc_unchecked(&dropped_count);
93878 return;
93879 }
93880 entry = ring_buffer_event_data(event);
93881diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
93882index c6977d5..d243785 100644
93883--- a/kernel/trace/trace_output.c
93884+++ b/kernel/trace/trace_output.c
93885@@ -712,14 +712,16 @@ int register_ftrace_event(struct trace_event *event)
93886 goto out;
93887 }
93888
93889+ pax_open_kernel();
93890 if (event->funcs->trace == NULL)
93891- event->funcs->trace = trace_nop_print;
93892+ *(void **)&event->funcs->trace = trace_nop_print;
93893 if (event->funcs->raw == NULL)
93894- event->funcs->raw = trace_nop_print;
93895+ *(void **)&event->funcs->raw = trace_nop_print;
93896 if (event->funcs->hex == NULL)
93897- event->funcs->hex = trace_nop_print;
93898+ *(void **)&event->funcs->hex = trace_nop_print;
93899 if (event->funcs->binary == NULL)
93900- event->funcs->binary = trace_nop_print;
93901+ *(void **)&event->funcs->binary = trace_nop_print;
93902+ pax_close_kernel();
93903
93904 key = event->type & (EVENT_HASHSIZE - 1);
93905
93906diff --git a/kernel/trace/trace_seq.c b/kernel/trace/trace_seq.c
93907index 1f24ed9..10407ec 100644
93908--- a/kernel/trace/trace_seq.c
93909+++ b/kernel/trace/trace_seq.c
93910@@ -367,7 +367,7 @@ int trace_seq_path(struct trace_seq *s, const struct path *path)
93911
93912 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
93913 if (!IS_ERR(p)) {
93914- p = mangle_path(s->buffer + s->len, p, "\n");
93915+ p = mangle_path(s->buffer + s->len, p, "\n\\");
93916 if (p) {
93917 s->len = p - s->buffer;
93918 return 1;
93919diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
93920index 16eddb3..758b308 100644
93921--- a/kernel/trace/trace_stack.c
93922+++ b/kernel/trace/trace_stack.c
93923@@ -90,7 +90,7 @@ check_stack(unsigned long ip, unsigned long *stack)
93924 return;
93925
93926 /* we do not handle interrupt stacks yet */
93927- if (!object_is_on_stack(stack))
93928+ if (!object_starts_on_stack(stack))
93929 return;
93930
93931 local_irq_save(flags);
93932diff --git a/kernel/trace/trace_syscalls.c b/kernel/trace/trace_syscalls.c
93933index 29228c4..301bc8c 100644
93934--- a/kernel/trace/trace_syscalls.c
93935+++ b/kernel/trace/trace_syscalls.c
93936@@ -602,6 +602,8 @@ static int perf_sysenter_enable(struct ftrace_event_call *call)
93937 int num;
93938
93939 num = ((struct syscall_metadata *)call->data)->syscall_nr;
93940+ if (WARN_ON_ONCE(num < 0 || num >= NR_syscalls))
93941+ return -EINVAL;
93942
93943 mutex_lock(&syscall_trace_lock);
93944 if (!sys_perf_refcount_enter)
93945@@ -622,6 +624,8 @@ static void perf_sysenter_disable(struct ftrace_event_call *call)
93946 int num;
93947
93948 num = ((struct syscall_metadata *)call->data)->syscall_nr;
93949+ if (WARN_ON_ONCE(num < 0 || num >= NR_syscalls))
93950+ return;
93951
93952 mutex_lock(&syscall_trace_lock);
93953 sys_perf_refcount_enter--;
93954@@ -674,6 +678,8 @@ static int perf_sysexit_enable(struct ftrace_event_call *call)
93955 int num;
93956
93957 num = ((struct syscall_metadata *)call->data)->syscall_nr;
93958+ if (WARN_ON_ONCE(num < 0 || num >= NR_syscalls))
93959+ return -EINVAL;
93960
93961 mutex_lock(&syscall_trace_lock);
93962 if (!sys_perf_refcount_exit)
93963@@ -694,6 +700,8 @@ static void perf_sysexit_disable(struct ftrace_event_call *call)
93964 int num;
93965
93966 num = ((struct syscall_metadata *)call->data)->syscall_nr;
93967+ if (WARN_ON_ONCE(num < 0 || num >= NR_syscalls))
93968+ return;
93969
93970 mutex_lock(&syscall_trace_lock);
93971 sys_perf_refcount_exit--;
93972diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c
93973index a2e37c5..4fa859b 100644
93974--- a/kernel/user_namespace.c
93975+++ b/kernel/user_namespace.c
93976@@ -83,6 +83,21 @@ int create_user_ns(struct cred *new)
93977 !kgid_has_mapping(parent_ns, group))
93978 return -EPERM;
93979
93980+#ifdef CONFIG_GRKERNSEC
93981+ /*
93982+ * This doesn't really inspire confidence:
93983+ * http://marc.info/?l=linux-kernel&m=135543612731939&w=2
93984+ * http://marc.info/?l=linux-kernel&m=135545831607095&w=2
93985+ * Increases kernel attack surface in areas developers
93986+ * previously cared little about ("low importance due
93987+ * to requiring "root" capability")
93988+ * To be removed when this code receives *proper* review
93989+ */
93990+ if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SETUID) ||
93991+ !capable(CAP_SETGID))
93992+ return -EPERM;
93993+#endif
93994+
93995 ns = kmem_cache_zalloc(user_ns_cachep, GFP_KERNEL);
93996 if (!ns)
93997 return -ENOMEM;
93998@@ -974,7 +989,7 @@ static int userns_install(struct nsproxy *nsproxy, void *ns)
93999 if (atomic_read(&current->mm->mm_users) > 1)
94000 return -EINVAL;
94001
94002- if (current->fs->users != 1)
94003+ if (atomic_read(&current->fs->users) != 1)
94004 return -EINVAL;
94005
94006 if (!ns_capable(user_ns, CAP_SYS_ADMIN))
94007diff --git a/kernel/utsname_sysctl.c b/kernel/utsname_sysctl.c
94008index c8eac43..4b5f08f 100644
94009--- a/kernel/utsname_sysctl.c
94010+++ b/kernel/utsname_sysctl.c
94011@@ -47,7 +47,7 @@ static void put_uts(struct ctl_table *table, int write, void *which)
94012 static int proc_do_uts_string(struct ctl_table *table, int write,
94013 void __user *buffer, size_t *lenp, loff_t *ppos)
94014 {
94015- struct ctl_table uts_table;
94016+ ctl_table_no_const uts_table;
94017 int r;
94018 memcpy(&uts_table, table, sizeof(uts_table));
94019 uts_table.data = get_uts(table, write);
94020diff --git a/kernel/watchdog.c b/kernel/watchdog.c
94021index 70bf118..4be3c37 100644
94022--- a/kernel/watchdog.c
94023+++ b/kernel/watchdog.c
94024@@ -572,7 +572,7 @@ static int watchdog_nmi_enable(unsigned int cpu) { return 0; }
94025 static void watchdog_nmi_disable(unsigned int cpu) { return; }
94026 #endif /* CONFIG_HARDLOCKUP_DETECTOR */
94027
94028-static struct smp_hotplug_thread watchdog_threads = {
94029+static struct smp_hotplug_thread watchdog_threads __read_only = {
94030 .store = &softlockup_watchdog,
94031 .thread_should_run = watchdog_should_run,
94032 .thread_fn = watchdog,
94033diff --git a/kernel/workqueue.c b/kernel/workqueue.c
94034index 09b685d..d3565e3 100644
94035--- a/kernel/workqueue.c
94036+++ b/kernel/workqueue.c
94037@@ -4508,7 +4508,7 @@ static void rebind_workers(struct worker_pool *pool)
94038 WARN_ON_ONCE(!(worker_flags & WORKER_UNBOUND));
94039 worker_flags |= WORKER_REBOUND;
94040 worker_flags &= ~WORKER_UNBOUND;
94041- ACCESS_ONCE(worker->flags) = worker_flags;
94042+ ACCESS_ONCE_RW(worker->flags) = worker_flags;
94043 }
94044
94045 spin_unlock_irq(&pool->lock);
94046diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
94047index 4e35a5d..8a1f3f0 100644
94048--- a/lib/Kconfig.debug
94049+++ b/lib/Kconfig.debug
94050@@ -894,7 +894,7 @@ config DEBUG_MUTEXES
94051
94052 config DEBUG_WW_MUTEX_SLOWPATH
94053 bool "Wait/wound mutex debugging: Slowpath testing"
94054- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
94055+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
94056 select DEBUG_LOCK_ALLOC
94057 select DEBUG_SPINLOCK
94058 select DEBUG_MUTEXES
94059@@ -911,7 +911,7 @@ config DEBUG_WW_MUTEX_SLOWPATH
94060
94061 config DEBUG_LOCK_ALLOC
94062 bool "Lock debugging: detect incorrect freeing of live locks"
94063- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
94064+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
94065 select DEBUG_SPINLOCK
94066 select DEBUG_MUTEXES
94067 select LOCKDEP
94068@@ -925,7 +925,7 @@ config DEBUG_LOCK_ALLOC
94069
94070 config PROVE_LOCKING
94071 bool "Lock debugging: prove locking correctness"
94072- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
94073+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
94074 select LOCKDEP
94075 select DEBUG_SPINLOCK
94076 select DEBUG_MUTEXES
94077@@ -976,7 +976,7 @@ config LOCKDEP
94078
94079 config LOCK_STAT
94080 bool "Lock usage statistics"
94081- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
94082+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
94083 select LOCKDEP
94084 select DEBUG_SPINLOCK
94085 select DEBUG_MUTEXES
94086@@ -1449,6 +1449,7 @@ config LATENCYTOP
94087 depends on DEBUG_KERNEL
94088 depends on STACKTRACE_SUPPORT
94089 depends on PROC_FS
94090+ depends on !GRKERNSEC_HIDESYM
94091 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND && !ARC
94092 select KALLSYMS
94093 select KALLSYMS_ALL
94094@@ -1465,7 +1466,7 @@ config ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
94095 config DEBUG_STRICT_USER_COPY_CHECKS
94096 bool "Strict user copy size checks"
94097 depends on ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
94098- depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING
94099+ depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING && !PAX_SIZE_OVERFLOW
94100 help
94101 Enabling this option turns a certain set of sanity checks for user
94102 copy operations into compile time failures.
94103@@ -1593,7 +1594,7 @@ endmenu # runtime tests
94104
94105 config PROVIDE_OHCI1394_DMA_INIT
94106 bool "Remote debugging over FireWire early on boot"
94107- depends on PCI && X86
94108+ depends on PCI && X86 && !GRKERNSEC
94109 help
94110 If you want to debug problems which hang or crash the kernel early
94111 on boot and the crashing machine has a FireWire port, you can use
94112diff --git a/lib/Makefile b/lib/Makefile
94113index 0211d2b..93f5cc3 100644
94114--- a/lib/Makefile
94115+++ b/lib/Makefile
94116@@ -55,7 +55,7 @@ obj-$(CONFIG_BTREE) += btree.o
94117 obj-$(CONFIG_INTERVAL_TREE) += interval_tree.o
94118 obj-$(CONFIG_ASSOCIATIVE_ARRAY) += assoc_array.o
94119 obj-$(CONFIG_DEBUG_PREEMPT) += smp_processor_id.o
94120-obj-$(CONFIG_DEBUG_LIST) += list_debug.o
94121+obj-y += list_debug.o
94122 obj-$(CONFIG_DEBUG_OBJECTS) += debugobjects.o
94123
94124 ifneq ($(CONFIG_HAVE_DEC_LOCK),y)
94125diff --git a/lib/average.c b/lib/average.c
94126index 114d1be..ab0350c 100644
94127--- a/lib/average.c
94128+++ b/lib/average.c
94129@@ -55,7 +55,7 @@ struct ewma *ewma_add(struct ewma *avg, unsigned long val)
94130 {
94131 unsigned long internal = ACCESS_ONCE(avg->internal);
94132
94133- ACCESS_ONCE(avg->internal) = internal ?
94134+ ACCESS_ONCE_RW(avg->internal) = internal ?
94135 (((internal << avg->weight) - internal) +
94136 (val << avg->factor)) >> avg->weight :
94137 (val << avg->factor);
94138diff --git a/lib/bitmap.c b/lib/bitmap.c
94139index b499ab6..fbdb76c 100644
94140--- a/lib/bitmap.c
94141+++ b/lib/bitmap.c
94142@@ -433,7 +433,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
94143 {
94144 int c, old_c, totaldigits, ndigits, nchunks, nbits;
94145 u32 chunk;
94146- const char __user __force *ubuf = (const char __user __force *)buf;
94147+ const char __user *ubuf = (const char __force_user *)buf;
94148
94149 bitmap_zero(maskp, nmaskbits);
94150
94151@@ -518,7 +518,7 @@ int bitmap_parse_user(const char __user *ubuf,
94152 {
94153 if (!access_ok(VERIFY_READ, ubuf, ulen))
94154 return -EFAULT;
94155- return __bitmap_parse((const char __force *)ubuf,
94156+ return __bitmap_parse((const char __force_kernel *)ubuf,
94157 ulen, 1, maskp, nmaskbits);
94158
94159 }
94160@@ -609,7 +609,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
94161 {
94162 unsigned a, b;
94163 int c, old_c, totaldigits;
94164- const char __user __force *ubuf = (const char __user __force *)buf;
94165+ const char __user *ubuf = (const char __force_user *)buf;
94166 int exp_digit, in_range;
94167
94168 totaldigits = c = 0;
94169@@ -704,7 +704,7 @@ int bitmap_parselist_user(const char __user *ubuf,
94170 {
94171 if (!access_ok(VERIFY_READ, ubuf, ulen))
94172 return -EFAULT;
94173- return __bitmap_parselist((const char __force *)ubuf,
94174+ return __bitmap_parselist((const char __force_kernel *)ubuf,
94175 ulen, 1, maskp, nmaskbits);
94176 }
94177 EXPORT_SYMBOL(bitmap_parselist_user);
94178diff --git a/lib/bug.c b/lib/bug.c
94179index d1d7c78..b354235 100644
94180--- a/lib/bug.c
94181+++ b/lib/bug.c
94182@@ -137,6 +137,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
94183 return BUG_TRAP_TYPE_NONE;
94184
94185 bug = find_bug(bugaddr);
94186+ if (!bug)
94187+ return BUG_TRAP_TYPE_NONE;
94188
94189 file = NULL;
94190 line = 0;
94191diff --git a/lib/debugobjects.c b/lib/debugobjects.c
94192index 547f7f9..a6d4ba0 100644
94193--- a/lib/debugobjects.c
94194+++ b/lib/debugobjects.c
94195@@ -289,7 +289,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
94196 if (limit > 4)
94197 return;
94198
94199- is_on_stack = object_is_on_stack(addr);
94200+ is_on_stack = object_starts_on_stack(addr);
94201 if (is_on_stack == onstack)
94202 return;
94203
94204diff --git a/lib/div64.c b/lib/div64.c
94205index 4382ad7..08aa558 100644
94206--- a/lib/div64.c
94207+++ b/lib/div64.c
94208@@ -59,7 +59,7 @@ uint32_t __attribute__((weak)) __div64_32(uint64_t *n, uint32_t base)
94209 EXPORT_SYMBOL(__div64_32);
94210
94211 #ifndef div_s64_rem
94212-s64 div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
94213+s64 __intentional_overflow(-1) div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
94214 {
94215 u64 quotient;
94216
94217@@ -130,7 +130,7 @@ EXPORT_SYMBOL(div64_u64_rem);
94218 * 'http://www.hackersdelight.org/HDcode/newCode/divDouble.c.txt'
94219 */
94220 #ifndef div64_u64
94221-u64 div64_u64(u64 dividend, u64 divisor)
94222+u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor)
94223 {
94224 u32 high = divisor >> 32;
94225 u64 quot;
94226diff --git a/lib/dma-debug.c b/lib/dma-debug.c
94227index add80cc..0d27550 100644
94228--- a/lib/dma-debug.c
94229+++ b/lib/dma-debug.c
94230@@ -971,7 +971,7 @@ static int dma_debug_device_change(struct notifier_block *nb, unsigned long acti
94231
94232 void dma_debug_add_bus(struct bus_type *bus)
94233 {
94234- struct notifier_block *nb;
94235+ notifier_block_no_const *nb;
94236
94237 if (global_disable)
94238 return;
94239@@ -1148,7 +1148,7 @@ static void check_unmap(struct dma_debug_entry *ref)
94240
94241 static void check_for_stack(struct device *dev, void *addr)
94242 {
94243- if (object_is_on_stack(addr))
94244+ if (object_starts_on_stack(addr))
94245 err_printk(dev, NULL, "DMA-API: device driver maps memory from "
94246 "stack [addr=%p]\n", addr);
94247 }
94248diff --git a/lib/hash.c b/lib/hash.c
94249index fea973f..386626f 100644
94250--- a/lib/hash.c
94251+++ b/lib/hash.c
94252@@ -14,7 +14,7 @@
94253 #include <linux/hash.h>
94254 #include <linux/cache.h>
94255
94256-static struct fast_hash_ops arch_hash_ops __read_mostly = {
94257+static struct fast_hash_ops arch_hash_ops __read_only = {
94258 .hash = jhash,
94259 .hash2 = jhash2,
94260 };
94261diff --git a/lib/inflate.c b/lib/inflate.c
94262index 013a761..c28f3fc 100644
94263--- a/lib/inflate.c
94264+++ b/lib/inflate.c
94265@@ -269,7 +269,7 @@ static void free(void *where)
94266 malloc_ptr = free_mem_ptr;
94267 }
94268 #else
94269-#define malloc(a) kmalloc(a, GFP_KERNEL)
94270+#define malloc(a) kmalloc((a), GFP_KERNEL)
94271 #define free(a) kfree(a)
94272 #endif
94273
94274diff --git a/lib/ioremap.c b/lib/ioremap.c
94275index 0c9216c..863bd89 100644
94276--- a/lib/ioremap.c
94277+++ b/lib/ioremap.c
94278@@ -38,7 +38,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
94279 unsigned long next;
94280
94281 phys_addr -= addr;
94282- pmd = pmd_alloc(&init_mm, pud, addr);
94283+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
94284 if (!pmd)
94285 return -ENOMEM;
94286 do {
94287@@ -56,7 +56,7 @@ static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
94288 unsigned long next;
94289
94290 phys_addr -= addr;
94291- pud = pud_alloc(&init_mm, pgd, addr);
94292+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
94293 if (!pud)
94294 return -ENOMEM;
94295 do {
94296diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
94297index bd2bea9..6b3c95e 100644
94298--- a/lib/is_single_threaded.c
94299+++ b/lib/is_single_threaded.c
94300@@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
94301 struct task_struct *p, *t;
94302 bool ret;
94303
94304+ if (!mm)
94305+ return true;
94306+
94307 if (atomic_read(&task->signal->live) != 1)
94308 return false;
94309
94310diff --git a/lib/kobject.c b/lib/kobject.c
94311index 58751bb..93a1853 100644
94312--- a/lib/kobject.c
94313+++ b/lib/kobject.c
94314@@ -931,9 +931,9 @@ EXPORT_SYMBOL_GPL(kset_create_and_add);
94315
94316
94317 static DEFINE_SPINLOCK(kobj_ns_type_lock);
94318-static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES];
94319+static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES] __read_only;
94320
94321-int kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
94322+int __init kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
94323 {
94324 enum kobj_ns_type type = ops->type;
94325 int error;
94326diff --git a/lib/list_debug.c b/lib/list_debug.c
94327index c24c2f7..f0296f4 100644
94328--- a/lib/list_debug.c
94329+++ b/lib/list_debug.c
94330@@ -11,7 +11,9 @@
94331 #include <linux/bug.h>
94332 #include <linux/kernel.h>
94333 #include <linux/rculist.h>
94334+#include <linux/mm.h>
94335
94336+#ifdef CONFIG_DEBUG_LIST
94337 /*
94338 * Insert a new entry between two known consecutive entries.
94339 *
94340@@ -19,21 +21,40 @@
94341 * the prev/next entries already!
94342 */
94343
94344+static bool __list_add_debug(struct list_head *new,
94345+ struct list_head *prev,
94346+ struct list_head *next)
94347+{
94348+ if (unlikely(next->prev != prev)) {
94349+ printk(KERN_ERR "list_add corruption. next->prev should be "
94350+ "prev (%p), but was %p. (next=%p).\n",
94351+ prev, next->prev, next);
94352+ BUG();
94353+ return false;
94354+ }
94355+ if (unlikely(prev->next != next)) {
94356+ printk(KERN_ERR "list_add corruption. prev->next should be "
94357+ "next (%p), but was %p. (prev=%p).\n",
94358+ next, prev->next, prev);
94359+ BUG();
94360+ return false;
94361+ }
94362+ if (unlikely(new == prev || new == next)) {
94363+ printk(KERN_ERR "list_add double add: new=%p, prev=%p, next=%p.\n",
94364+ new, prev, next);
94365+ BUG();
94366+ return false;
94367+ }
94368+ return true;
94369+}
94370+
94371 void __list_add(struct list_head *new,
94372- struct list_head *prev,
94373- struct list_head *next)
94374+ struct list_head *prev,
94375+ struct list_head *next)
94376 {
94377- WARN(next->prev != prev,
94378- "list_add corruption. next->prev should be "
94379- "prev (%p), but was %p. (next=%p).\n",
94380- prev, next->prev, next);
94381- WARN(prev->next != next,
94382- "list_add corruption. prev->next should be "
94383- "next (%p), but was %p. (prev=%p).\n",
94384- next, prev->next, prev);
94385- WARN(new == prev || new == next,
94386- "list_add double add: new=%p, prev=%p, next=%p.\n",
94387- new, prev, next);
94388+ if (!__list_add_debug(new, prev, next))
94389+ return;
94390+
94391 next->prev = new;
94392 new->next = next;
94393 new->prev = prev;
94394@@ -41,28 +62,46 @@ void __list_add(struct list_head *new,
94395 }
94396 EXPORT_SYMBOL(__list_add);
94397
94398-void __list_del_entry(struct list_head *entry)
94399+static bool __list_del_entry_debug(struct list_head *entry)
94400 {
94401 struct list_head *prev, *next;
94402
94403 prev = entry->prev;
94404 next = entry->next;
94405
94406- if (WARN(next == LIST_POISON1,
94407- "list_del corruption, %p->next is LIST_POISON1 (%p)\n",
94408- entry, LIST_POISON1) ||
94409- WARN(prev == LIST_POISON2,
94410- "list_del corruption, %p->prev is LIST_POISON2 (%p)\n",
94411- entry, LIST_POISON2) ||
94412- WARN(prev->next != entry,
94413- "list_del corruption. prev->next should be %p, "
94414- "but was %p\n", entry, prev->next) ||
94415- WARN(next->prev != entry,
94416- "list_del corruption. next->prev should be %p, "
94417- "but was %p\n", entry, next->prev))
94418+ if (unlikely(next == LIST_POISON1)) {
94419+ printk(KERN_ERR "list_del corruption, %p->next is LIST_POISON1 (%p)\n",
94420+ entry, LIST_POISON1);
94421+ BUG();
94422+ return false;
94423+ }
94424+ if (unlikely(prev == LIST_POISON2)) {
94425+ printk(KERN_ERR "list_del corruption, %p->prev is LIST_POISON2 (%p)\n",
94426+ entry, LIST_POISON2);
94427+ BUG();
94428+ return false;
94429+ }
94430+ if (unlikely(entry->prev->next != entry)) {
94431+ printk(KERN_ERR "list_del corruption. prev->next should be %p, "
94432+ "but was %p\n", entry, prev->next);
94433+ BUG();
94434+ return false;
94435+ }
94436+ if (unlikely(entry->next->prev != entry)) {
94437+ printk(KERN_ERR "list_del corruption. next->prev should be %p, "
94438+ "but was %p\n", entry, next->prev);
94439+ BUG();
94440+ return false;
94441+ }
94442+ return true;
94443+}
94444+
94445+void __list_del_entry(struct list_head *entry)
94446+{
94447+ if (!__list_del_entry_debug(entry))
94448 return;
94449
94450- __list_del(prev, next);
94451+ __list_del(entry->prev, entry->next);
94452 }
94453 EXPORT_SYMBOL(__list_del_entry);
94454
94455@@ -86,15 +125,85 @@ EXPORT_SYMBOL(list_del);
94456 void __list_add_rcu(struct list_head *new,
94457 struct list_head *prev, struct list_head *next)
94458 {
94459- WARN(next->prev != prev,
94460- "list_add_rcu corruption. next->prev should be prev (%p), but was %p. (next=%p).\n",
94461- prev, next->prev, next);
94462- WARN(prev->next != next,
94463- "list_add_rcu corruption. prev->next should be next (%p), but was %p. (prev=%p).\n",
94464- next, prev->next, prev);
94465+ if (!__list_add_debug(new, prev, next))
94466+ return;
94467+
94468 new->next = next;
94469 new->prev = prev;
94470 rcu_assign_pointer(list_next_rcu(prev), new);
94471 next->prev = new;
94472 }
94473 EXPORT_SYMBOL(__list_add_rcu);
94474+#endif
94475+
94476+void __pax_list_add(struct list_head *new, struct list_head *prev, struct list_head *next)
94477+{
94478+#ifdef CONFIG_DEBUG_LIST
94479+ if (!__list_add_debug(new, prev, next))
94480+ return;
94481+#endif
94482+
94483+ pax_open_kernel();
94484+ next->prev = new;
94485+ new->next = next;
94486+ new->prev = prev;
94487+ prev->next = new;
94488+ pax_close_kernel();
94489+}
94490+EXPORT_SYMBOL(__pax_list_add);
94491+
94492+void pax_list_del(struct list_head *entry)
94493+{
94494+#ifdef CONFIG_DEBUG_LIST
94495+ if (!__list_del_entry_debug(entry))
94496+ return;
94497+#endif
94498+
94499+ pax_open_kernel();
94500+ __list_del(entry->prev, entry->next);
94501+ entry->next = LIST_POISON1;
94502+ entry->prev = LIST_POISON2;
94503+ pax_close_kernel();
94504+}
94505+EXPORT_SYMBOL(pax_list_del);
94506+
94507+void pax_list_del_init(struct list_head *entry)
94508+{
94509+ pax_open_kernel();
94510+ __list_del(entry->prev, entry->next);
94511+ INIT_LIST_HEAD(entry);
94512+ pax_close_kernel();
94513+}
94514+EXPORT_SYMBOL(pax_list_del_init);
94515+
94516+void __pax_list_add_rcu(struct list_head *new,
94517+ struct list_head *prev, struct list_head *next)
94518+{
94519+#ifdef CONFIG_DEBUG_LIST
94520+ if (!__list_add_debug(new, prev, next))
94521+ return;
94522+#endif
94523+
94524+ pax_open_kernel();
94525+ new->next = next;
94526+ new->prev = prev;
94527+ rcu_assign_pointer(list_next_rcu(prev), new);
94528+ next->prev = new;
94529+ pax_close_kernel();
94530+}
94531+EXPORT_SYMBOL(__pax_list_add_rcu);
94532+
94533+void pax_list_del_rcu(struct list_head *entry)
94534+{
94535+#ifdef CONFIG_DEBUG_LIST
94536+ if (!__list_del_entry_debug(entry))
94537+ return;
94538+#endif
94539+
94540+ pax_open_kernel();
94541+ __list_del(entry->prev, entry->next);
94542+ entry->next = LIST_POISON1;
94543+ entry->prev = LIST_POISON2;
94544+ pax_close_kernel();
94545+}
94546+EXPORT_SYMBOL(pax_list_del_rcu);
94547diff --git a/lib/lockref.c b/lib/lockref.c
94548index d2233de..fa1a2f6 100644
94549--- a/lib/lockref.c
94550+++ b/lib/lockref.c
94551@@ -48,13 +48,13 @@
94552 void lockref_get(struct lockref *lockref)
94553 {
94554 CMPXCHG_LOOP(
94555- new.count++;
94556+ __lockref_inc(&new);
94557 ,
94558 return;
94559 );
94560
94561 spin_lock(&lockref->lock);
94562- lockref->count++;
94563+ __lockref_inc(lockref);
94564 spin_unlock(&lockref->lock);
94565 }
94566 EXPORT_SYMBOL(lockref_get);
94567@@ -69,7 +69,7 @@ int lockref_get_not_zero(struct lockref *lockref)
94568 int retval;
94569
94570 CMPXCHG_LOOP(
94571- new.count++;
94572+ __lockref_inc(&new);
94573 if (!old.count)
94574 return 0;
94575 ,
94576@@ -79,7 +79,7 @@ int lockref_get_not_zero(struct lockref *lockref)
94577 spin_lock(&lockref->lock);
94578 retval = 0;
94579 if (lockref->count) {
94580- lockref->count++;
94581+ __lockref_inc(lockref);
94582 retval = 1;
94583 }
94584 spin_unlock(&lockref->lock);
94585@@ -96,7 +96,7 @@ EXPORT_SYMBOL(lockref_get_not_zero);
94586 int lockref_get_or_lock(struct lockref *lockref)
94587 {
94588 CMPXCHG_LOOP(
94589- new.count++;
94590+ __lockref_inc(&new);
94591 if (!old.count)
94592 break;
94593 ,
94594@@ -106,7 +106,7 @@ int lockref_get_or_lock(struct lockref *lockref)
94595 spin_lock(&lockref->lock);
94596 if (!lockref->count)
94597 return 0;
94598- lockref->count++;
94599+ __lockref_inc(lockref);
94600 spin_unlock(&lockref->lock);
94601 return 1;
94602 }
94603@@ -120,7 +120,7 @@ EXPORT_SYMBOL(lockref_get_or_lock);
94604 int lockref_put_or_lock(struct lockref *lockref)
94605 {
94606 CMPXCHG_LOOP(
94607- new.count--;
94608+ __lockref_dec(&new);
94609 if (old.count <= 1)
94610 break;
94611 ,
94612@@ -130,7 +130,7 @@ int lockref_put_or_lock(struct lockref *lockref)
94613 spin_lock(&lockref->lock);
94614 if (lockref->count <= 1)
94615 return 0;
94616- lockref->count--;
94617+ __lockref_dec(lockref);
94618 spin_unlock(&lockref->lock);
94619 return 1;
94620 }
94621@@ -157,7 +157,7 @@ int lockref_get_not_dead(struct lockref *lockref)
94622 int retval;
94623
94624 CMPXCHG_LOOP(
94625- new.count++;
94626+ __lockref_inc(&new);
94627 if ((int)old.count < 0)
94628 return 0;
94629 ,
94630@@ -167,7 +167,7 @@ int lockref_get_not_dead(struct lockref *lockref)
94631 spin_lock(&lockref->lock);
94632 retval = 0;
94633 if ((int) lockref->count >= 0) {
94634- lockref->count++;
94635+ __lockref_inc(lockref);
94636 retval = 1;
94637 }
94638 spin_unlock(&lockref->lock);
94639diff --git a/lib/percpu-refcount.c b/lib/percpu-refcount.c
94640index 6111bcb..02e816b 100644
94641--- a/lib/percpu-refcount.c
94642+++ b/lib/percpu-refcount.c
94643@@ -31,7 +31,7 @@
94644 * atomic_long_t can't hit 0 before we've added up all the percpu refs.
94645 */
94646
94647-#define PERCPU_COUNT_BIAS (1LU << (BITS_PER_LONG - 1))
94648+#define PERCPU_COUNT_BIAS (1LU << (BITS_PER_LONG - 2))
94649
94650 static DECLARE_WAIT_QUEUE_HEAD(percpu_ref_switch_waitq);
94651
94652diff --git a/lib/radix-tree.c b/lib/radix-tree.c
94653index 3291a8e..346a91e 100644
94654--- a/lib/radix-tree.c
94655+++ b/lib/radix-tree.c
94656@@ -67,7 +67,7 @@ struct radix_tree_preload {
94657 int nr;
94658 struct radix_tree_node *nodes[RADIX_TREE_PRELOAD_SIZE];
94659 };
94660-static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
94661+static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
94662
94663 static inline void *ptr_to_indirect(void *ptr)
94664 {
94665diff --git a/lib/random32.c b/lib/random32.c
94666index 0bee183..526f12f 100644
94667--- a/lib/random32.c
94668+++ b/lib/random32.c
94669@@ -47,7 +47,7 @@ static inline void prandom_state_selftest(void)
94670 }
94671 #endif
94672
94673-static DEFINE_PER_CPU(struct rnd_state, net_rand_state);
94674+static DEFINE_PER_CPU(struct rnd_state, net_rand_state) __latent_entropy;
94675
94676 /**
94677 * prandom_u32_state - seeded pseudo-random number generator.
94678diff --git a/lib/rbtree.c b/lib/rbtree.c
94679index c16c81a..4dcbda1 100644
94680--- a/lib/rbtree.c
94681+++ b/lib/rbtree.c
94682@@ -380,7 +380,9 @@ static inline void dummy_copy(struct rb_node *old, struct rb_node *new) {}
94683 static inline void dummy_rotate(struct rb_node *old, struct rb_node *new) {}
94684
94685 static const struct rb_augment_callbacks dummy_callbacks = {
94686- dummy_propagate, dummy_copy, dummy_rotate
94687+ .propagate = dummy_propagate,
94688+ .copy = dummy_copy,
94689+ .rotate = dummy_rotate
94690 };
94691
94692 void rb_insert_color(struct rb_node *node, struct rb_root *root)
94693diff --git a/lib/show_mem.c b/lib/show_mem.c
94694index 5e25627..3ed9d7f 100644
94695--- a/lib/show_mem.c
94696+++ b/lib/show_mem.c
94697@@ -44,6 +44,6 @@ void show_mem(unsigned int filter)
94698 quicklist_total_size());
94699 #endif
94700 #ifdef CONFIG_MEMORY_FAILURE
94701- printk("%lu pages hwpoisoned\n", atomic_long_read(&num_poisoned_pages));
94702+ printk("%lu pages hwpoisoned\n", atomic_long_read_unchecked(&num_poisoned_pages));
94703 #endif
94704 }
94705diff --git a/lib/strncpy_from_user.c b/lib/strncpy_from_user.c
94706index bb2b201..46abaf9 100644
94707--- a/lib/strncpy_from_user.c
94708+++ b/lib/strncpy_from_user.c
94709@@ -21,7 +21,7 @@
94710 */
94711 static inline long do_strncpy_from_user(char *dst, const char __user *src, long count, unsigned long max)
94712 {
94713- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
94714+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
94715 long res = 0;
94716
94717 /*
94718diff --git a/lib/strnlen_user.c b/lib/strnlen_user.c
94719index a28df52..3d55877 100644
94720--- a/lib/strnlen_user.c
94721+++ b/lib/strnlen_user.c
94722@@ -26,7 +26,7 @@
94723 */
94724 static inline long do_strnlen_user(const char __user *src, unsigned long count, unsigned long max)
94725 {
94726- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
94727+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
94728 long align, res = 0;
94729 unsigned long c;
94730
94731diff --git a/lib/swiotlb.c b/lib/swiotlb.c
94732index 4abda07..b9d3765 100644
94733--- a/lib/swiotlb.c
94734+++ b/lib/swiotlb.c
94735@@ -682,7 +682,7 @@ EXPORT_SYMBOL(swiotlb_alloc_coherent);
94736
94737 void
94738 swiotlb_free_coherent(struct device *hwdev, size_t size, void *vaddr,
94739- dma_addr_t dev_addr)
94740+ dma_addr_t dev_addr, struct dma_attrs *attrs)
94741 {
94742 phys_addr_t paddr = dma_to_phys(hwdev, dev_addr);
94743
94744diff --git a/lib/usercopy.c b/lib/usercopy.c
94745index 4f5b1dd..7cab418 100644
94746--- a/lib/usercopy.c
94747+++ b/lib/usercopy.c
94748@@ -7,3 +7,9 @@ void copy_from_user_overflow(void)
94749 WARN(1, "Buffer overflow detected!\n");
94750 }
94751 EXPORT_SYMBOL(copy_from_user_overflow);
94752+
94753+void copy_to_user_overflow(void)
94754+{
94755+ WARN(1, "Buffer overflow detected!\n");
94756+}
94757+EXPORT_SYMBOL(copy_to_user_overflow);
94758diff --git a/lib/vsprintf.c b/lib/vsprintf.c
94759index ec337f6..8484eb2 100644
94760--- a/lib/vsprintf.c
94761+++ b/lib/vsprintf.c
94762@@ -16,6 +16,9 @@
94763 * - scnprintf and vscnprintf
94764 */
94765
94766+#ifdef CONFIG_GRKERNSEC_HIDESYM
94767+#define __INCLUDED_BY_HIDESYM 1
94768+#endif
94769 #include <stdarg.h>
94770 #include <linux/module.h> /* for KSYM_SYMBOL_LEN */
94771 #include <linux/types.h>
94772@@ -625,7 +628,7 @@ char *symbol_string(char *buf, char *end, void *ptr,
94773 #ifdef CONFIG_KALLSYMS
94774 if (*fmt == 'B')
94775 sprint_backtrace(sym, value);
94776- else if (*fmt != 'f' && *fmt != 's')
94777+ else if (*fmt != 'f' && *fmt != 's' && *fmt != 'X')
94778 sprint_symbol(sym, value);
94779 else
94780 sprint_symbol_no_offset(sym, value);
94781@@ -1240,7 +1243,11 @@ char *address_val(char *buf, char *end, const void *addr,
94782 return number(buf, end, num, spec);
94783 }
94784
94785+#ifdef CONFIG_GRKERNSEC_HIDESYM
94786+int kptr_restrict __read_mostly = 2;
94787+#else
94788 int kptr_restrict __read_mostly;
94789+#endif
94790
94791 /*
94792 * Show a '%p' thing. A kernel extension is that the '%p' is followed
94793@@ -1251,8 +1258,10 @@ int kptr_restrict __read_mostly;
94794 *
94795 * - 'F' For symbolic function descriptor pointers with offset
94796 * - 'f' For simple symbolic function names without offset
94797+ * - 'X' For simple symbolic function names without offset approved for use with GRKERNSEC_HIDESYM
94798 * - 'S' For symbolic direct pointers with offset
94799 * - 's' For symbolic direct pointers without offset
94800+ * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
94801 * - '[FfSs]R' as above with __builtin_extract_return_addr() translation
94802 * - 'B' For backtraced symbolic direct pointers with offset
94803 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
94804@@ -1331,12 +1340,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
94805
94806 if (!ptr && *fmt != 'K') {
94807 /*
94808- * Print (null) with the same width as a pointer so it makes
94809+ * Print (nil) with the same width as a pointer so it makes
94810 * tabular output look nice.
94811 */
94812 if (spec.field_width == -1)
94813 spec.field_width = default_width;
94814- return string(buf, end, "(null)", spec);
94815+ return string(buf, end, "(nil)", spec);
94816 }
94817
94818 switch (*fmt) {
94819@@ -1346,6 +1355,14 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
94820 /* Fallthrough */
94821 case 'S':
94822 case 's':
94823+#ifdef CONFIG_GRKERNSEC_HIDESYM
94824+ break;
94825+#else
94826+ return symbol_string(buf, end, ptr, spec, fmt);
94827+#endif
94828+ case 'X':
94829+ ptr = dereference_function_descriptor(ptr);
94830+ case 'A':
94831 case 'B':
94832 return symbol_string(buf, end, ptr, spec, fmt);
94833 case 'R':
94834@@ -1403,6 +1420,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
94835 va_end(va);
94836 return buf;
94837 }
94838+ case 'P':
94839+ break;
94840 case 'K':
94841 /*
94842 * %pK cannot be used in IRQ context because its test
94843@@ -1460,6 +1479,22 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
94844 ((const struct file *)ptr)->f_path.dentry,
94845 spec, fmt);
94846 }
94847+
94848+#ifdef CONFIG_GRKERNSEC_HIDESYM
94849+ /* 'P' = approved pointers to copy to userland,
94850+ as in the /proc/kallsyms case, as we make it display nothing
94851+ for non-root users, and the real contents for root users
94852+ 'X' = approved simple symbols
94853+ Also ignore 'K' pointers, since we force their NULLing for non-root users
94854+ above
94855+ */
94856+ if ((unsigned long)ptr > TASK_SIZE && *fmt != 'P' && *fmt != 'X' && *fmt != 'K' && is_usercopy_object(buf)) {
94857+ printk(KERN_ALERT "grsec: kernel infoleak detected! Please report this log to spender@grsecurity.net.\n");
94858+ dump_stack();
94859+ ptr = NULL;
94860+ }
94861+#endif
94862+
94863 spec.flags |= SMALL;
94864 if (spec.field_width == -1) {
94865 spec.field_width = default_width;
94866@@ -2160,11 +2195,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
94867 typeof(type) value; \
94868 if (sizeof(type) == 8) { \
94869 args = PTR_ALIGN(args, sizeof(u32)); \
94870- *(u32 *)&value = *(u32 *)args; \
94871- *((u32 *)&value + 1) = *(u32 *)(args + 4); \
94872+ *(u32 *)&value = *(const u32 *)args; \
94873+ *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
94874 } else { \
94875 args = PTR_ALIGN(args, sizeof(type)); \
94876- value = *(typeof(type) *)args; \
94877+ value = *(const typeof(type) *)args; \
94878 } \
94879 args += sizeof(type); \
94880 value; \
94881@@ -2227,7 +2262,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
94882 case FORMAT_TYPE_STR: {
94883 const char *str_arg = args;
94884 args += strlen(str_arg) + 1;
94885- str = string(str, end, (char *)str_arg, spec);
94886+ str = string(str, end, str_arg, spec);
94887 break;
94888 }
94889
94890diff --git a/localversion-grsec b/localversion-grsec
94891new file mode 100644
94892index 0000000..7cd6065
94893--- /dev/null
94894+++ b/localversion-grsec
94895@@ -0,0 +1 @@
94896+-grsec
94897diff --git a/mm/Kconfig b/mm/Kconfig
94898index 1d1ae6b..0f05885 100644
94899--- a/mm/Kconfig
94900+++ b/mm/Kconfig
94901@@ -341,10 +341,11 @@ config KSM
94902 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
94903
94904 config DEFAULT_MMAP_MIN_ADDR
94905- int "Low address space to protect from user allocation"
94906+ int "Low address space to protect from user allocation"
94907 depends on MMU
94908- default 4096
94909- help
94910+ default 32768 if ALPHA || ARM || PARISC || SPARC32
94911+ default 65536
94912+ help
94913 This is the portion of low virtual memory which should be protected
94914 from userspace allocation. Keeping a user from writing to low pages
94915 can help reduce the impact of kernel NULL pointer bugs.
94916@@ -375,7 +376,7 @@ config MEMORY_FAILURE
94917
94918 config HWPOISON_INJECT
94919 tristate "HWPoison pages injector"
94920- depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS
94921+ depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS && !GRKERNSEC
94922 select PROC_PAGE_MONITOR
94923
94924 config NOMMU_INITIAL_TRIM_EXCESS
94925diff --git a/mm/backing-dev.c b/mm/backing-dev.c
94926index 0ae0df5..82ac56b 100644
94927--- a/mm/backing-dev.c
94928+++ b/mm/backing-dev.c
94929@@ -12,7 +12,7 @@
94930 #include <linux/device.h>
94931 #include <trace/events/writeback.h>
94932
94933-static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
94934+static atomic_long_unchecked_t bdi_seq = ATOMIC_LONG_INIT(0);
94935
94936 struct backing_dev_info default_backing_dev_info = {
94937 .name = "default",
94938@@ -525,7 +525,7 @@ int bdi_setup_and_register(struct backing_dev_info *bdi, char *name,
94939 return err;
94940
94941 err = bdi_register(bdi, NULL, "%.28s-%ld", name,
94942- atomic_long_inc_return(&bdi_seq));
94943+ atomic_long_inc_return_unchecked(&bdi_seq));
94944 if (err) {
94945 bdi_destroy(bdi);
94946 return err;
94947diff --git a/mm/filemap.c b/mm/filemap.c
94948index 14b4642..d71ba82 100644
94949--- a/mm/filemap.c
94950+++ b/mm/filemap.c
94951@@ -2101,7 +2101,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
94952 struct address_space *mapping = file->f_mapping;
94953
94954 if (!mapping->a_ops->readpage)
94955- return -ENOEXEC;
94956+ return -ENODEV;
94957 file_accessed(file);
94958 vma->vm_ops = &generic_file_vm_ops;
94959 return 0;
94960@@ -2279,6 +2279,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
94961 *pos = i_size_read(inode);
94962
94963 if (limit != RLIM_INFINITY) {
94964+ gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
94965 if (*pos >= limit) {
94966 send_sig(SIGXFSZ, current, 0);
94967 return -EFBIG;
94968diff --git a/mm/fremap.c b/mm/fremap.c
94969index 72b8fa3..c5b39f1 100644
94970--- a/mm/fremap.c
94971+++ b/mm/fremap.c
94972@@ -180,6 +180,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
94973 retry:
94974 vma = find_vma(mm, start);
94975
94976+#ifdef CONFIG_PAX_SEGMEXEC
94977+ if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
94978+ goto out;
94979+#endif
94980+
94981 /*
94982 * Make sure the vma is shared, that it supports prefaulting,
94983 * and that the remapped range is valid and fully within
94984diff --git a/mm/gup.c b/mm/gup.c
94985index cd62c8c..3bb2053 100644
94986--- a/mm/gup.c
94987+++ b/mm/gup.c
94988@@ -274,11 +274,6 @@ static int faultin_page(struct task_struct *tsk, struct vm_area_struct *vma,
94989 unsigned int fault_flags = 0;
94990 int ret;
94991
94992- /* For mlock, just skip the stack guard page. */
94993- if ((*flags & FOLL_MLOCK) &&
94994- (stack_guard_page_start(vma, address) ||
94995- stack_guard_page_end(vma, address + PAGE_SIZE)))
94996- return -ENOENT;
94997 if (*flags & FOLL_WRITE)
94998 fault_flags |= FAULT_FLAG_WRITE;
94999 if (nonblocking)
95000@@ -444,14 +439,14 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
95001 if (!(gup_flags & FOLL_FORCE))
95002 gup_flags |= FOLL_NUMA;
95003
95004- do {
95005+ while (nr_pages) {
95006 struct page *page;
95007 unsigned int foll_flags = gup_flags;
95008 unsigned int page_increm;
95009
95010 /* first iteration or cross vma bound */
95011 if (!vma || start >= vma->vm_end) {
95012- vma = find_extend_vma(mm, start);
95013+ vma = find_vma(mm, start);
95014 if (!vma && in_gate_area(mm, start)) {
95015 int ret;
95016 ret = get_gate_page(mm, start & PAGE_MASK,
95017@@ -463,7 +458,7 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
95018 goto next_page;
95019 }
95020
95021- if (!vma || check_vma_flags(vma, gup_flags))
95022+ if (!vma || start < vma->vm_start || check_vma_flags(vma, gup_flags))
95023 return i ? : -EFAULT;
95024 if (is_vm_hugetlb_page(vma)) {
95025 i = follow_hugetlb_page(mm, vma, pages, vmas,
95026@@ -518,7 +513,7 @@ next_page:
95027 i += page_increm;
95028 start += page_increm * PAGE_SIZE;
95029 nr_pages -= page_increm;
95030- } while (nr_pages);
95031+ }
95032 return i;
95033 }
95034 EXPORT_SYMBOL(__get_user_pages);
95035diff --git a/mm/highmem.c b/mm/highmem.c
95036index 123bcd3..0de52ba 100644
95037--- a/mm/highmem.c
95038+++ b/mm/highmem.c
95039@@ -195,8 +195,9 @@ static void flush_all_zero_pkmaps(void)
95040 * So no dangers, even with speculative execution.
95041 */
95042 page = pte_page(pkmap_page_table[i]);
95043+ pax_open_kernel();
95044 pte_clear(&init_mm, PKMAP_ADDR(i), &pkmap_page_table[i]);
95045-
95046+ pax_close_kernel();
95047 set_page_address(page, NULL);
95048 need_flush = 1;
95049 }
95050@@ -259,9 +260,11 @@ start:
95051 }
95052 }
95053 vaddr = PKMAP_ADDR(last_pkmap_nr);
95054+
95055+ pax_open_kernel();
95056 set_pte_at(&init_mm, vaddr,
95057 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
95058-
95059+ pax_close_kernel();
95060 pkmap_count[last_pkmap_nr] = 1;
95061 set_page_address(page, (void *)vaddr);
95062
95063diff --git a/mm/hugetlb.c b/mm/hugetlb.c
95064index 9fd7227..5628939 100644
95065--- a/mm/hugetlb.c
95066+++ b/mm/hugetlb.c
95067@@ -2258,6 +2258,7 @@ static int hugetlb_sysctl_handler_common(bool obey_mempolicy,
95068 struct ctl_table *table, int write,
95069 void __user *buffer, size_t *length, loff_t *ppos)
95070 {
95071+ ctl_table_no_const t;
95072 struct hstate *h = &default_hstate;
95073 unsigned long tmp = h->max_huge_pages;
95074 int ret;
95075@@ -2265,9 +2266,10 @@ static int hugetlb_sysctl_handler_common(bool obey_mempolicy,
95076 if (!hugepages_supported())
95077 return -ENOTSUPP;
95078
95079- table->data = &tmp;
95080- table->maxlen = sizeof(unsigned long);
95081- ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
95082+ t = *table;
95083+ t.data = &tmp;
95084+ t.maxlen = sizeof(unsigned long);
95085+ ret = proc_doulongvec_minmax(&t, write, buffer, length, ppos);
95086 if (ret)
95087 goto out;
95088
95089@@ -2302,6 +2304,7 @@ int hugetlb_overcommit_handler(struct ctl_table *table, int write,
95090 struct hstate *h = &default_hstate;
95091 unsigned long tmp;
95092 int ret;
95093+ ctl_table_no_const hugetlb_table;
95094
95095 if (!hugepages_supported())
95096 return -ENOTSUPP;
95097@@ -2311,9 +2314,10 @@ int hugetlb_overcommit_handler(struct ctl_table *table, int write,
95098 if (write && hstate_is_gigantic(h))
95099 return -EINVAL;
95100
95101- table->data = &tmp;
95102- table->maxlen = sizeof(unsigned long);
95103- ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
95104+ hugetlb_table = *table;
95105+ hugetlb_table.data = &tmp;
95106+ hugetlb_table.maxlen = sizeof(unsigned long);
95107+ ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
95108 if (ret)
95109 goto out;
95110
95111@@ -2792,6 +2796,27 @@ static void unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
95112 mutex_unlock(&mapping->i_mmap_mutex);
95113 }
95114
95115+#ifdef CONFIG_PAX_SEGMEXEC
95116+static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
95117+{
95118+ struct mm_struct *mm = vma->vm_mm;
95119+ struct vm_area_struct *vma_m;
95120+ unsigned long address_m;
95121+ pte_t *ptep_m;
95122+
95123+ vma_m = pax_find_mirror_vma(vma);
95124+ if (!vma_m)
95125+ return;
95126+
95127+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
95128+ address_m = address + SEGMEXEC_TASK_SIZE;
95129+ ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
95130+ get_page(page_m);
95131+ hugepage_add_anon_rmap(page_m, vma_m, address_m);
95132+ set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
95133+}
95134+#endif
95135+
95136 /*
95137 * Hugetlb_cow() should be called with page lock of the original hugepage held.
95138 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
95139@@ -2903,6 +2928,11 @@ retry_avoidcopy:
95140 make_huge_pte(vma, new_page, 1));
95141 page_remove_rmap(old_page);
95142 hugepage_add_new_anon_rmap(new_page, vma, address);
95143+
95144+#ifdef CONFIG_PAX_SEGMEXEC
95145+ pax_mirror_huge_pte(vma, address, new_page);
95146+#endif
95147+
95148 /* Make the old page be freed below */
95149 new_page = old_page;
95150 }
95151@@ -3063,6 +3093,10 @@ retry:
95152 && (vma->vm_flags & VM_SHARED)));
95153 set_huge_pte_at(mm, address, ptep, new_pte);
95154
95155+#ifdef CONFIG_PAX_SEGMEXEC
95156+ pax_mirror_huge_pte(vma, address, page);
95157+#endif
95158+
95159 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
95160 /* Optimization, do the COW without a second fault */
95161 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page, ptl);
95162@@ -3129,6 +3163,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
95163 struct hstate *h = hstate_vma(vma);
95164 struct address_space *mapping;
95165
95166+#ifdef CONFIG_PAX_SEGMEXEC
95167+ struct vm_area_struct *vma_m;
95168+#endif
95169+
95170 address &= huge_page_mask(h);
95171
95172 ptep = huge_pte_offset(mm, address);
95173@@ -3142,6 +3180,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
95174 VM_FAULT_SET_HINDEX(hstate_index(h));
95175 }
95176
95177+#ifdef CONFIG_PAX_SEGMEXEC
95178+ vma_m = pax_find_mirror_vma(vma);
95179+ if (vma_m) {
95180+ unsigned long address_m;
95181+
95182+ if (vma->vm_start > vma_m->vm_start) {
95183+ address_m = address;
95184+ address -= SEGMEXEC_TASK_SIZE;
95185+ vma = vma_m;
95186+ h = hstate_vma(vma);
95187+ } else
95188+ address_m = address + SEGMEXEC_TASK_SIZE;
95189+
95190+ if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
95191+ return VM_FAULT_OOM;
95192+ address_m &= HPAGE_MASK;
95193+ unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
95194+ }
95195+#endif
95196+
95197 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
95198 if (!ptep)
95199 return VM_FAULT_OOM;
95200diff --git a/mm/internal.h b/mm/internal.h
95201index a4f90ba..fbdc32b 100644
95202--- a/mm/internal.h
95203+++ b/mm/internal.h
95204@@ -134,6 +134,7 @@ __find_buddy_index(unsigned long page_idx, unsigned int order)
95205
95206 extern int __isolate_free_page(struct page *page, unsigned int order);
95207 extern void __free_pages_bootmem(struct page *page, unsigned int order);
95208+extern void free_compound_page(struct page *page);
95209 extern void prep_compound_page(struct page *page, unsigned long order);
95210 #ifdef CONFIG_MEMORY_FAILURE
95211 extern bool is_free_buddy_page(struct page *page);
95212@@ -390,7 +391,7 @@ extern u32 hwpoison_filter_enable;
95213
95214 extern unsigned long vm_mmap_pgoff(struct file *, unsigned long,
95215 unsigned long, unsigned long,
95216- unsigned long, unsigned long);
95217+ unsigned long, unsigned long) __intentional_overflow(-1);
95218
95219 extern void set_pageblock_order(void);
95220 unsigned long reclaim_clean_pages_from_list(struct zone *zone,
95221diff --git a/mm/iov_iter.c b/mm/iov_iter.c
95222index e34a3cb..a810efe 100644
95223--- a/mm/iov_iter.c
95224+++ b/mm/iov_iter.c
95225@@ -307,7 +307,7 @@ static size_t __iovec_copy_from_user_inatomic(char *vaddr,
95226
95227 while (bytes) {
95228 char __user *buf = iov->iov_base + base;
95229- int copy = min(bytes, iov->iov_len - base);
95230+ size_t copy = min(bytes, iov->iov_len - base);
95231
95232 base = 0;
95233 left = __copy_from_user_inatomic(vaddr, buf, copy);
95234@@ -335,7 +335,7 @@ static size_t copy_from_user_atomic_iovec(struct page *page,
95235
95236 kaddr = kmap_atomic(page);
95237 if (likely(i->nr_segs == 1)) {
95238- int left;
95239+ size_t left;
95240 char __user *buf = i->iov->iov_base + i->iov_offset;
95241 left = __copy_from_user_inatomic(kaddr + offset, buf, bytes);
95242 copied = bytes - left;
95243@@ -365,7 +365,7 @@ static void advance_iovec(struct iov_iter *i, size_t bytes)
95244 * zero-length segments (without overruning the iovec).
95245 */
95246 while (bytes || unlikely(i->count && !iov->iov_len)) {
95247- int copy;
95248+ size_t copy;
95249
95250 copy = min(bytes, iov->iov_len - base);
95251 BUG_ON(!i->count || i->count < copy);
95252diff --git a/mm/kmemleak.c b/mm/kmemleak.c
95253index 3cda50c..032ba634 100644
95254--- a/mm/kmemleak.c
95255+++ b/mm/kmemleak.c
95256@@ -364,7 +364,7 @@ static void print_unreferenced(struct seq_file *seq,
95257
95258 for (i = 0; i < object->trace_len; i++) {
95259 void *ptr = (void *)object->trace[i];
95260- seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
95261+ seq_printf(seq, " [<%pP>] %pA\n", ptr, ptr);
95262 }
95263 }
95264
95265@@ -1905,7 +1905,7 @@ static int __init kmemleak_late_init(void)
95266 return -ENOMEM;
95267 }
95268
95269- dentry = debugfs_create_file("kmemleak", S_IRUGO, NULL, NULL,
95270+ dentry = debugfs_create_file("kmemleak", S_IRUSR, NULL, NULL,
95271 &kmemleak_fops);
95272 if (!dentry)
95273 pr_warning("Failed to create the debugfs kmemleak file\n");
95274diff --git a/mm/maccess.c b/mm/maccess.c
95275index d53adf9..03a24bf 100644
95276--- a/mm/maccess.c
95277+++ b/mm/maccess.c
95278@@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
95279 set_fs(KERNEL_DS);
95280 pagefault_disable();
95281 ret = __copy_from_user_inatomic(dst,
95282- (__force const void __user *)src, size);
95283+ (const void __force_user *)src, size);
95284 pagefault_enable();
95285 set_fs(old_fs);
95286
95287@@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
95288
95289 set_fs(KERNEL_DS);
95290 pagefault_disable();
95291- ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
95292+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
95293 pagefault_enable();
95294 set_fs(old_fs);
95295
95296diff --git a/mm/madvise.c b/mm/madvise.c
95297index 0938b30..199abe8 100644
95298--- a/mm/madvise.c
95299+++ b/mm/madvise.c
95300@@ -51,6 +51,10 @@ static long madvise_behavior(struct vm_area_struct *vma,
95301 pgoff_t pgoff;
95302 unsigned long new_flags = vma->vm_flags;
95303
95304+#ifdef CONFIG_PAX_SEGMEXEC
95305+ struct vm_area_struct *vma_m;
95306+#endif
95307+
95308 switch (behavior) {
95309 case MADV_NORMAL:
95310 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
95311@@ -126,6 +130,13 @@ success:
95312 /*
95313 * vm_flags is protected by the mmap_sem held in write mode.
95314 */
95315+
95316+#ifdef CONFIG_PAX_SEGMEXEC
95317+ vma_m = pax_find_mirror_vma(vma);
95318+ if (vma_m)
95319+ vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
95320+#endif
95321+
95322 vma->vm_flags = new_flags;
95323
95324 out:
95325@@ -274,6 +285,11 @@ static long madvise_dontneed(struct vm_area_struct *vma,
95326 struct vm_area_struct **prev,
95327 unsigned long start, unsigned long end)
95328 {
95329+
95330+#ifdef CONFIG_PAX_SEGMEXEC
95331+ struct vm_area_struct *vma_m;
95332+#endif
95333+
95334 *prev = vma;
95335 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
95336 return -EINVAL;
95337@@ -286,6 +302,21 @@ static long madvise_dontneed(struct vm_area_struct *vma,
95338 zap_page_range(vma, start, end - start, &details);
95339 } else
95340 zap_page_range(vma, start, end - start, NULL);
95341+
95342+#ifdef CONFIG_PAX_SEGMEXEC
95343+ vma_m = pax_find_mirror_vma(vma);
95344+ if (vma_m) {
95345+ if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
95346+ struct zap_details details = {
95347+ .nonlinear_vma = vma_m,
95348+ .last_index = ULONG_MAX,
95349+ };
95350+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
95351+ } else
95352+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
95353+ }
95354+#endif
95355+
95356 return 0;
95357 }
95358
95359@@ -488,6 +519,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
95360 if (end < start)
95361 return error;
95362
95363+#ifdef CONFIG_PAX_SEGMEXEC
95364+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
95365+ if (end > SEGMEXEC_TASK_SIZE)
95366+ return error;
95367+ } else
95368+#endif
95369+
95370+ if (end > TASK_SIZE)
95371+ return error;
95372+
95373 error = 0;
95374 if (end == start)
95375 return error;
95376diff --git a/mm/memory-failure.c b/mm/memory-failure.c
95377index 8639f6b..b623882a 100644
95378--- a/mm/memory-failure.c
95379+++ b/mm/memory-failure.c
95380@@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
95381
95382 int sysctl_memory_failure_recovery __read_mostly = 1;
95383
95384-atomic_long_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
95385+atomic_long_unchecked_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
95386
95387 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
95388
95389@@ -198,7 +198,7 @@ static int kill_proc(struct task_struct *t, unsigned long addr, int trapno,
95390 pfn, t->comm, t->pid);
95391 si.si_signo = SIGBUS;
95392 si.si_errno = 0;
95393- si.si_addr = (void *)addr;
95394+ si.si_addr = (void __user *)addr;
95395 #ifdef __ARCH_SI_TRAPNO
95396 si.si_trapno = trapno;
95397 #endif
95398@@ -791,7 +791,7 @@ static struct page_state {
95399 unsigned long res;
95400 char *msg;
95401 int (*action)(struct page *p, unsigned long pfn);
95402-} error_states[] = {
95403+} __do_const error_states[] = {
95404 { reserved, reserved, "reserved kernel", me_kernel },
95405 /*
95406 * free pages are specially detected outside this table:
95407@@ -1099,7 +1099,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
95408 nr_pages = 1 << compound_order(hpage);
95409 else /* normal page or thp */
95410 nr_pages = 1;
95411- atomic_long_add(nr_pages, &num_poisoned_pages);
95412+ atomic_long_add_unchecked(nr_pages, &num_poisoned_pages);
95413
95414 /*
95415 * We need/can do nothing about count=0 pages.
95416@@ -1128,7 +1128,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
95417 if (PageHWPoison(hpage)) {
95418 if ((hwpoison_filter(p) && TestClearPageHWPoison(p))
95419 || (p != hpage && TestSetPageHWPoison(hpage))) {
95420- atomic_long_sub(nr_pages, &num_poisoned_pages);
95421+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
95422 unlock_page(hpage);
95423 return 0;
95424 }
95425@@ -1196,14 +1196,14 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
95426 */
95427 if (!PageHWPoison(p)) {
95428 printk(KERN_ERR "MCE %#lx: just unpoisoned\n", pfn);
95429- atomic_long_sub(nr_pages, &num_poisoned_pages);
95430+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
95431 put_page(hpage);
95432 res = 0;
95433 goto out;
95434 }
95435 if (hwpoison_filter(p)) {
95436 if (TestClearPageHWPoison(p))
95437- atomic_long_sub(nr_pages, &num_poisoned_pages);
95438+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
95439 unlock_page(hpage);
95440 put_page(hpage);
95441 return 0;
95442@@ -1433,7 +1433,7 @@ int unpoison_memory(unsigned long pfn)
95443 return 0;
95444 }
95445 if (TestClearPageHWPoison(p))
95446- atomic_long_dec(&num_poisoned_pages);
95447+ atomic_long_dec_unchecked(&num_poisoned_pages);
95448 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
95449 return 0;
95450 }
95451@@ -1447,7 +1447,7 @@ int unpoison_memory(unsigned long pfn)
95452 */
95453 if (TestClearPageHWPoison(page)) {
95454 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
95455- atomic_long_sub(nr_pages, &num_poisoned_pages);
95456+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
95457 freeit = 1;
95458 if (PageHuge(page))
95459 clear_page_hwpoison_huge_page(page);
95460@@ -1572,11 +1572,11 @@ static int soft_offline_huge_page(struct page *page, int flags)
95461 if (PageHuge(page)) {
95462 set_page_hwpoison_huge_page(hpage);
95463 dequeue_hwpoisoned_huge_page(hpage);
95464- atomic_long_add(1 << compound_order(hpage),
95465+ atomic_long_add_unchecked(1 << compound_order(hpage),
95466 &num_poisoned_pages);
95467 } else {
95468 SetPageHWPoison(page);
95469- atomic_long_inc(&num_poisoned_pages);
95470+ atomic_long_inc_unchecked(&num_poisoned_pages);
95471 }
95472 }
95473 return ret;
95474@@ -1615,7 +1615,7 @@ static int __soft_offline_page(struct page *page, int flags)
95475 put_page(page);
95476 pr_info("soft_offline: %#lx: invalidated\n", pfn);
95477 SetPageHWPoison(page);
95478- atomic_long_inc(&num_poisoned_pages);
95479+ atomic_long_inc_unchecked(&num_poisoned_pages);
95480 return 0;
95481 }
95482
95483@@ -1666,7 +1666,7 @@ static int __soft_offline_page(struct page *page, int flags)
95484 if (!is_free_buddy_page(page))
95485 pr_info("soft offline: %#lx: page leaked\n",
95486 pfn);
95487- atomic_long_inc(&num_poisoned_pages);
95488+ atomic_long_inc_unchecked(&num_poisoned_pages);
95489 }
95490 } else {
95491 pr_info("soft offline: %#lx: isolation failed: %d, page count %d, type %lx\n",
95492@@ -1736,11 +1736,11 @@ int soft_offline_page(struct page *page, int flags)
95493 if (PageHuge(page)) {
95494 set_page_hwpoison_huge_page(hpage);
95495 dequeue_hwpoisoned_huge_page(hpage);
95496- atomic_long_add(1 << compound_order(hpage),
95497+ atomic_long_add_unchecked(1 << compound_order(hpage),
95498 &num_poisoned_pages);
95499 } else {
95500 SetPageHWPoison(page);
95501- atomic_long_inc(&num_poisoned_pages);
95502+ atomic_long_inc_unchecked(&num_poisoned_pages);
95503 }
95504 }
95505 unset_migratetype_isolate(page, MIGRATE_MOVABLE);
95506diff --git a/mm/memory.c b/mm/memory.c
95507index 7f86cf6..0600e22 100644
95508--- a/mm/memory.c
95509+++ b/mm/memory.c
95510@@ -415,6 +415,7 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
95511 free_pte_range(tlb, pmd, addr);
95512 } while (pmd++, addr = next, addr != end);
95513
95514+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
95515 start &= PUD_MASK;
95516 if (start < floor)
95517 return;
95518@@ -429,6 +430,8 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
95519 pmd = pmd_offset(pud, start);
95520 pud_clear(pud);
95521 pmd_free_tlb(tlb, pmd, start);
95522+#endif
95523+
95524 }
95525
95526 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
95527@@ -448,6 +451,7 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
95528 free_pmd_range(tlb, pud, addr, next, floor, ceiling);
95529 } while (pud++, addr = next, addr != end);
95530
95531+#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
95532 start &= PGDIR_MASK;
95533 if (start < floor)
95534 return;
95535@@ -462,6 +466,8 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
95536 pud = pud_offset(pgd, start);
95537 pgd_clear(pgd);
95538 pud_free_tlb(tlb, pud, start);
95539+#endif
95540+
95541 }
95542
95543 /*
95544@@ -691,10 +697,10 @@ static void print_bad_pte(struct vm_area_struct *vma, unsigned long addr,
95545 * Choose text because data symbols depend on CONFIG_KALLSYMS_ALL=y
95546 */
95547 if (vma->vm_ops)
95548- printk(KERN_ALERT "vma->vm_ops->fault: %pSR\n",
95549+ printk(KERN_ALERT "vma->vm_ops->fault: %pAR\n",
95550 vma->vm_ops->fault);
95551 if (vma->vm_file)
95552- printk(KERN_ALERT "vma->vm_file->f_op->mmap: %pSR\n",
95553+ printk(KERN_ALERT "vma->vm_file->f_op->mmap: %pAR\n",
95554 vma->vm_file->f_op->mmap);
95555 dump_stack();
95556 add_taint(TAINT_BAD_PAGE, LOCKDEP_NOW_UNRELIABLE);
95557@@ -1501,6 +1507,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
95558 page_add_file_rmap(page);
95559 set_pte_at(mm, addr, pte, mk_pte(page, prot));
95560
95561+#ifdef CONFIG_PAX_SEGMEXEC
95562+ pax_mirror_file_pte(vma, addr, page, ptl);
95563+#endif
95564+
95565 retval = 0;
95566 pte_unmap_unlock(pte, ptl);
95567 return retval;
95568@@ -1545,9 +1555,21 @@ int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
95569 if (!page_count(page))
95570 return -EINVAL;
95571 if (!(vma->vm_flags & VM_MIXEDMAP)) {
95572+
95573+#ifdef CONFIG_PAX_SEGMEXEC
95574+ struct vm_area_struct *vma_m;
95575+#endif
95576+
95577 BUG_ON(down_read_trylock(&vma->vm_mm->mmap_sem));
95578 BUG_ON(vma->vm_flags & VM_PFNMAP);
95579 vma->vm_flags |= VM_MIXEDMAP;
95580+
95581+#ifdef CONFIG_PAX_SEGMEXEC
95582+ vma_m = pax_find_mirror_vma(vma);
95583+ if (vma_m)
95584+ vma_m->vm_flags |= VM_MIXEDMAP;
95585+#endif
95586+
95587 }
95588 return insert_page(vma, addr, page, vma->vm_page_prot);
95589 }
95590@@ -1630,6 +1652,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
95591 unsigned long pfn)
95592 {
95593 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
95594+ BUG_ON(vma->vm_mirror);
95595
95596 if (addr < vma->vm_start || addr >= vma->vm_end)
95597 return -EFAULT;
95598@@ -1877,7 +1900,9 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud,
95599
95600 BUG_ON(pud_huge(*pud));
95601
95602- pmd = pmd_alloc(mm, pud, addr);
95603+ pmd = (mm == &init_mm) ?
95604+ pmd_alloc_kernel(mm, pud, addr) :
95605+ pmd_alloc(mm, pud, addr);
95606 if (!pmd)
95607 return -ENOMEM;
95608 do {
95609@@ -1897,7 +1922,9 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,
95610 unsigned long next;
95611 int err;
95612
95613- pud = pud_alloc(mm, pgd, addr);
95614+ pud = (mm == &init_mm) ?
95615+ pud_alloc_kernel(mm, pgd, addr) :
95616+ pud_alloc(mm, pgd, addr);
95617 if (!pud)
95618 return -ENOMEM;
95619 do {
95620@@ -2019,6 +2046,186 @@ static int do_page_mkwrite(struct vm_area_struct *vma, struct page *page,
95621 return ret;
95622 }
95623
95624+#ifdef CONFIG_PAX_SEGMEXEC
95625+static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
95626+{
95627+ struct mm_struct *mm = vma->vm_mm;
95628+ spinlock_t *ptl;
95629+ pte_t *pte, entry;
95630+
95631+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
95632+ entry = *pte;
95633+ if (!pte_present(entry)) {
95634+ if (!pte_none(entry)) {
95635+ BUG_ON(pte_file(entry));
95636+ free_swap_and_cache(pte_to_swp_entry(entry));
95637+ pte_clear_not_present_full(mm, address, pte, 0);
95638+ }
95639+ } else {
95640+ struct page *page;
95641+
95642+ flush_cache_page(vma, address, pte_pfn(entry));
95643+ entry = ptep_clear_flush(vma, address, pte);
95644+ BUG_ON(pte_dirty(entry));
95645+ page = vm_normal_page(vma, address, entry);
95646+ if (page) {
95647+ update_hiwater_rss(mm);
95648+ if (PageAnon(page))
95649+ dec_mm_counter_fast(mm, MM_ANONPAGES);
95650+ else
95651+ dec_mm_counter_fast(mm, MM_FILEPAGES);
95652+ page_remove_rmap(page);
95653+ page_cache_release(page);
95654+ }
95655+ }
95656+ pte_unmap_unlock(pte, ptl);
95657+}
95658+
95659+/* PaX: if vma is mirrored, synchronize the mirror's PTE
95660+ *
95661+ * the ptl of the lower mapped page is held on entry and is not released on exit
95662+ * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
95663+ */
95664+static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
95665+{
95666+ struct mm_struct *mm = vma->vm_mm;
95667+ unsigned long address_m;
95668+ spinlock_t *ptl_m;
95669+ struct vm_area_struct *vma_m;
95670+ pmd_t *pmd_m;
95671+ pte_t *pte_m, entry_m;
95672+
95673+ BUG_ON(!page_m || !PageAnon(page_m));
95674+
95675+ vma_m = pax_find_mirror_vma(vma);
95676+ if (!vma_m)
95677+ return;
95678+
95679+ BUG_ON(!PageLocked(page_m));
95680+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
95681+ address_m = address + SEGMEXEC_TASK_SIZE;
95682+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
95683+ pte_m = pte_offset_map(pmd_m, address_m);
95684+ ptl_m = pte_lockptr(mm, pmd_m);
95685+ if (ptl != ptl_m) {
95686+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
95687+ if (!pte_none(*pte_m))
95688+ goto out;
95689+ }
95690+
95691+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
95692+ page_cache_get(page_m);
95693+ page_add_anon_rmap(page_m, vma_m, address_m);
95694+ inc_mm_counter_fast(mm, MM_ANONPAGES);
95695+ set_pte_at(mm, address_m, pte_m, entry_m);
95696+ update_mmu_cache(vma_m, address_m, pte_m);
95697+out:
95698+ if (ptl != ptl_m)
95699+ spin_unlock(ptl_m);
95700+ pte_unmap(pte_m);
95701+ unlock_page(page_m);
95702+}
95703+
95704+void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
95705+{
95706+ struct mm_struct *mm = vma->vm_mm;
95707+ unsigned long address_m;
95708+ spinlock_t *ptl_m;
95709+ struct vm_area_struct *vma_m;
95710+ pmd_t *pmd_m;
95711+ pte_t *pte_m, entry_m;
95712+
95713+ BUG_ON(!page_m || PageAnon(page_m));
95714+
95715+ vma_m = pax_find_mirror_vma(vma);
95716+ if (!vma_m)
95717+ return;
95718+
95719+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
95720+ address_m = address + SEGMEXEC_TASK_SIZE;
95721+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
95722+ pte_m = pte_offset_map(pmd_m, address_m);
95723+ ptl_m = pte_lockptr(mm, pmd_m);
95724+ if (ptl != ptl_m) {
95725+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
95726+ if (!pte_none(*pte_m))
95727+ goto out;
95728+ }
95729+
95730+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
95731+ page_cache_get(page_m);
95732+ page_add_file_rmap(page_m);
95733+ inc_mm_counter_fast(mm, MM_FILEPAGES);
95734+ set_pte_at(mm, address_m, pte_m, entry_m);
95735+ update_mmu_cache(vma_m, address_m, pte_m);
95736+out:
95737+ if (ptl != ptl_m)
95738+ spin_unlock(ptl_m);
95739+ pte_unmap(pte_m);
95740+}
95741+
95742+static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
95743+{
95744+ struct mm_struct *mm = vma->vm_mm;
95745+ unsigned long address_m;
95746+ spinlock_t *ptl_m;
95747+ struct vm_area_struct *vma_m;
95748+ pmd_t *pmd_m;
95749+ pte_t *pte_m, entry_m;
95750+
95751+ vma_m = pax_find_mirror_vma(vma);
95752+ if (!vma_m)
95753+ return;
95754+
95755+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
95756+ address_m = address + SEGMEXEC_TASK_SIZE;
95757+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
95758+ pte_m = pte_offset_map(pmd_m, address_m);
95759+ ptl_m = pte_lockptr(mm, pmd_m);
95760+ if (ptl != ptl_m) {
95761+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
95762+ if (!pte_none(*pte_m))
95763+ goto out;
95764+ }
95765+
95766+ entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
95767+ set_pte_at(mm, address_m, pte_m, entry_m);
95768+out:
95769+ if (ptl != ptl_m)
95770+ spin_unlock(ptl_m);
95771+ pte_unmap(pte_m);
95772+}
95773+
95774+static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
95775+{
95776+ struct page *page_m;
95777+ pte_t entry;
95778+
95779+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
95780+ goto out;
95781+
95782+ entry = *pte;
95783+ page_m = vm_normal_page(vma, address, entry);
95784+ if (!page_m)
95785+ pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
95786+ else if (PageAnon(page_m)) {
95787+ if (pax_find_mirror_vma(vma)) {
95788+ pte_unmap_unlock(pte, ptl);
95789+ lock_page(page_m);
95790+ pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
95791+ if (pte_same(entry, *pte))
95792+ pax_mirror_anon_pte(vma, address, page_m, ptl);
95793+ else
95794+ unlock_page(page_m);
95795+ }
95796+ } else
95797+ pax_mirror_file_pte(vma, address, page_m, ptl);
95798+
95799+out:
95800+ pte_unmap_unlock(pte, ptl);
95801+}
95802+#endif
95803+
95804 /*
95805 * This routine handles present pages, when users try to write
95806 * to a shared page. It is done by copying the page to a new address
95807@@ -2225,6 +2432,12 @@ gotten:
95808 */
95809 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
95810 if (likely(pte_same(*page_table, orig_pte))) {
95811+
95812+#ifdef CONFIG_PAX_SEGMEXEC
95813+ if (pax_find_mirror_vma(vma))
95814+ BUG_ON(!trylock_page(new_page));
95815+#endif
95816+
95817 if (old_page) {
95818 if (!PageAnon(old_page)) {
95819 dec_mm_counter_fast(mm, MM_FILEPAGES);
95820@@ -2278,6 +2491,10 @@ gotten:
95821 page_remove_rmap(old_page);
95822 }
95823
95824+#ifdef CONFIG_PAX_SEGMEXEC
95825+ pax_mirror_anon_pte(vma, address, new_page, ptl);
95826+#endif
95827+
95828 /* Free the old page.. */
95829 new_page = old_page;
95830 ret |= VM_FAULT_WRITE;
95831@@ -2552,6 +2769,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
95832 swap_free(entry);
95833 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
95834 try_to_free_swap(page);
95835+
95836+#ifdef CONFIG_PAX_SEGMEXEC
95837+ if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
95838+#endif
95839+
95840 unlock_page(page);
95841 if (page != swapcache) {
95842 /*
95843@@ -2575,6 +2797,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
95844
95845 /* No need to invalidate - it was non-present before */
95846 update_mmu_cache(vma, address, page_table);
95847+
95848+#ifdef CONFIG_PAX_SEGMEXEC
95849+ pax_mirror_anon_pte(vma, address, page, ptl);
95850+#endif
95851+
95852 unlock:
95853 pte_unmap_unlock(page_table, ptl);
95854 out:
95855@@ -2594,40 +2821,6 @@ out_release:
95856 }
95857
95858 /*
95859- * This is like a special single-page "expand_{down|up}wards()",
95860- * except we must first make sure that 'address{-|+}PAGE_SIZE'
95861- * doesn't hit another vma.
95862- */
95863-static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
95864-{
95865- address &= PAGE_MASK;
95866- if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
95867- struct vm_area_struct *prev = vma->vm_prev;
95868-
95869- /*
95870- * Is there a mapping abutting this one below?
95871- *
95872- * That's only ok if it's the same stack mapping
95873- * that has gotten split..
95874- */
95875- if (prev && prev->vm_end == address)
95876- return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
95877-
95878- return expand_downwards(vma, address - PAGE_SIZE);
95879- }
95880- if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
95881- struct vm_area_struct *next = vma->vm_next;
95882-
95883- /* As VM_GROWSDOWN but s/below/above/ */
95884- if (next && next->vm_start == address + PAGE_SIZE)
95885- return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
95886-
95887- return expand_upwards(vma, address + PAGE_SIZE);
95888- }
95889- return 0;
95890-}
95891-
95892-/*
95893 * We enter with non-exclusive mmap_sem (to exclude vma changes,
95894 * but allow concurrent faults), and pte mapped but not yet locked.
95895 * We return with mmap_sem still held, but pte unmapped and unlocked.
95896@@ -2637,27 +2830,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
95897 unsigned int flags)
95898 {
95899 struct mem_cgroup *memcg;
95900- struct page *page;
95901+ struct page *page = NULL;
95902 spinlock_t *ptl;
95903 pte_t entry;
95904
95905- pte_unmap(page_table);
95906-
95907- /* Check if we need to add a guard page to the stack */
95908- if (check_stack_guard_page(vma, address) < 0)
95909- return VM_FAULT_SIGBUS;
95910-
95911- /* Use the zero-page for reads */
95912 if (!(flags & FAULT_FLAG_WRITE)) {
95913 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
95914 vma->vm_page_prot));
95915- page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
95916+ ptl = pte_lockptr(mm, pmd);
95917+ spin_lock(ptl);
95918 if (!pte_none(*page_table))
95919 goto unlock;
95920 goto setpte;
95921 }
95922
95923 /* Allocate our own private page. */
95924+ pte_unmap(page_table);
95925+
95926 if (unlikely(anon_vma_prepare(vma)))
95927 goto oom;
95928 page = alloc_zeroed_user_highpage_movable(vma, address);
95929@@ -2681,6 +2870,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
95930 if (!pte_none(*page_table))
95931 goto release;
95932
95933+#ifdef CONFIG_PAX_SEGMEXEC
95934+ if (pax_find_mirror_vma(vma))
95935+ BUG_ON(!trylock_page(page));
95936+#endif
95937+
95938 inc_mm_counter_fast(mm, MM_ANONPAGES);
95939 page_add_new_anon_rmap(page, vma, address);
95940 mem_cgroup_commit_charge(page, memcg, false);
95941@@ -2690,6 +2884,12 @@ setpte:
95942
95943 /* No need to invalidate - it was non-present before */
95944 update_mmu_cache(vma, address, page_table);
95945+
95946+#ifdef CONFIG_PAX_SEGMEXEC
95947+ if (page)
95948+ pax_mirror_anon_pte(vma, address, page, ptl);
95949+#endif
95950+
95951 unlock:
95952 pte_unmap_unlock(page_table, ptl);
95953 return 0;
95954@@ -2920,6 +3120,11 @@ static int do_read_fault(struct mm_struct *mm, struct vm_area_struct *vma,
95955 return ret;
95956 }
95957 do_set_pte(vma, address, fault_page, pte, false, false);
95958+
95959+#ifdef CONFIG_PAX_SEGMEXEC
95960+ pax_mirror_file_pte(vma, address, fault_page, ptl);
95961+#endif
95962+
95963 unlock_page(fault_page);
95964 unlock_out:
95965 pte_unmap_unlock(pte, ptl);
95966@@ -2962,7 +3167,18 @@ static int do_cow_fault(struct mm_struct *mm, struct vm_area_struct *vma,
95967 page_cache_release(fault_page);
95968 goto uncharge_out;
95969 }
95970+
95971+#ifdef CONFIG_PAX_SEGMEXEC
95972+ if (pax_find_mirror_vma(vma))
95973+ BUG_ON(!trylock_page(new_page));
95974+#endif
95975+
95976 do_set_pte(vma, address, new_page, pte, true, true);
95977+
95978+#ifdef CONFIG_PAX_SEGMEXEC
95979+ pax_mirror_anon_pte(vma, address, new_page, ptl);
95980+#endif
95981+
95982 mem_cgroup_commit_charge(new_page, memcg, false);
95983 lru_cache_add_active_or_unevictable(new_page, vma);
95984 pte_unmap_unlock(pte, ptl);
95985@@ -3012,6 +3228,11 @@ static int do_shared_fault(struct mm_struct *mm, struct vm_area_struct *vma,
95986 return ret;
95987 }
95988 do_set_pte(vma, address, fault_page, pte, true, false);
95989+
95990+#ifdef CONFIG_PAX_SEGMEXEC
95991+ pax_mirror_file_pte(vma, address, fault_page, ptl);
95992+#endif
95993+
95994 pte_unmap_unlock(pte, ptl);
95995
95996 if (set_page_dirty(fault_page))
95997@@ -3253,6 +3474,12 @@ static int handle_pte_fault(struct mm_struct *mm,
95998 if (flags & FAULT_FLAG_WRITE)
95999 flush_tlb_fix_spurious_fault(vma, address);
96000 }
96001+
96002+#ifdef CONFIG_PAX_SEGMEXEC
96003+ pax_mirror_pte(vma, address, pte, pmd, ptl);
96004+ return 0;
96005+#endif
96006+
96007 unlock:
96008 pte_unmap_unlock(pte, ptl);
96009 return 0;
96010@@ -3272,9 +3499,41 @@ static int __handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
96011 pmd_t *pmd;
96012 pte_t *pte;
96013
96014+#ifdef CONFIG_PAX_SEGMEXEC
96015+ struct vm_area_struct *vma_m;
96016+#endif
96017+
96018 if (unlikely(is_vm_hugetlb_page(vma)))
96019 return hugetlb_fault(mm, vma, address, flags);
96020
96021+#ifdef CONFIG_PAX_SEGMEXEC
96022+ vma_m = pax_find_mirror_vma(vma);
96023+ if (vma_m) {
96024+ unsigned long address_m;
96025+ pgd_t *pgd_m;
96026+ pud_t *pud_m;
96027+ pmd_t *pmd_m;
96028+
96029+ if (vma->vm_start > vma_m->vm_start) {
96030+ address_m = address;
96031+ address -= SEGMEXEC_TASK_SIZE;
96032+ vma = vma_m;
96033+ } else
96034+ address_m = address + SEGMEXEC_TASK_SIZE;
96035+
96036+ pgd_m = pgd_offset(mm, address_m);
96037+ pud_m = pud_alloc(mm, pgd_m, address_m);
96038+ if (!pud_m)
96039+ return VM_FAULT_OOM;
96040+ pmd_m = pmd_alloc(mm, pud_m, address_m);
96041+ if (!pmd_m)
96042+ return VM_FAULT_OOM;
96043+ if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
96044+ return VM_FAULT_OOM;
96045+ pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
96046+ }
96047+#endif
96048+
96049 pgd = pgd_offset(mm, address);
96050 pud = pud_alloc(mm, pgd, address);
96051 if (!pud)
96052@@ -3408,6 +3667,23 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
96053 spin_unlock(&mm->page_table_lock);
96054 return 0;
96055 }
96056+
96057+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
96058+{
96059+ pud_t *new = pud_alloc_one(mm, address);
96060+ if (!new)
96061+ return -ENOMEM;
96062+
96063+ smp_wmb(); /* See comment in __pte_alloc */
96064+
96065+ spin_lock(&mm->page_table_lock);
96066+ if (pgd_present(*pgd)) /* Another has populated it */
96067+ pud_free(mm, new);
96068+ else
96069+ pgd_populate_kernel(mm, pgd, new);
96070+ spin_unlock(&mm->page_table_lock);
96071+ return 0;
96072+}
96073 #endif /* __PAGETABLE_PUD_FOLDED */
96074
96075 #ifndef __PAGETABLE_PMD_FOLDED
96076@@ -3438,6 +3714,30 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
96077 spin_unlock(&mm->page_table_lock);
96078 return 0;
96079 }
96080+
96081+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
96082+{
96083+ pmd_t *new = pmd_alloc_one(mm, address);
96084+ if (!new)
96085+ return -ENOMEM;
96086+
96087+ smp_wmb(); /* See comment in __pte_alloc */
96088+
96089+ spin_lock(&mm->page_table_lock);
96090+#ifndef __ARCH_HAS_4LEVEL_HACK
96091+ if (pud_present(*pud)) /* Another has populated it */
96092+ pmd_free(mm, new);
96093+ else
96094+ pud_populate_kernel(mm, pud, new);
96095+#else
96096+ if (pgd_present(*pud)) /* Another has populated it */
96097+ pmd_free(mm, new);
96098+ else
96099+ pgd_populate_kernel(mm, pud, new);
96100+#endif /* __ARCH_HAS_4LEVEL_HACK */
96101+ spin_unlock(&mm->page_table_lock);
96102+ return 0;
96103+}
96104 #endif /* __PAGETABLE_PMD_FOLDED */
96105
96106 static int __follow_pte(struct mm_struct *mm, unsigned long address,
96107@@ -3547,8 +3847,8 @@ out:
96108 return ret;
96109 }
96110
96111-int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
96112- void *buf, int len, int write)
96113+ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
96114+ void *buf, size_t len, int write)
96115 {
96116 resource_size_t phys_addr;
96117 unsigned long prot = 0;
96118@@ -3574,8 +3874,8 @@ EXPORT_SYMBOL_GPL(generic_access_phys);
96119 * Access another process' address space as given in mm. If non-NULL, use the
96120 * given task for page fault accounting.
96121 */
96122-static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
96123- unsigned long addr, void *buf, int len, int write)
96124+static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
96125+ unsigned long addr, void *buf, size_t len, int write)
96126 {
96127 struct vm_area_struct *vma;
96128 void *old_buf = buf;
96129@@ -3583,7 +3883,7 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
96130 down_read(&mm->mmap_sem);
96131 /* ignore errors, just check how much was successfully transferred */
96132 while (len) {
96133- int bytes, ret, offset;
96134+ ssize_t bytes, ret, offset;
96135 void *maddr;
96136 struct page *page = NULL;
96137
96138@@ -3644,8 +3944,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
96139 *
96140 * The caller must hold a reference on @mm.
96141 */
96142-int access_remote_vm(struct mm_struct *mm, unsigned long addr,
96143- void *buf, int len, int write)
96144+ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
96145+ void *buf, size_t len, int write)
96146 {
96147 return __access_remote_vm(NULL, mm, addr, buf, len, write);
96148 }
96149@@ -3655,11 +3955,11 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
96150 * Source/target buffer must be kernel space,
96151 * Do not walk the page table directly, use get_user_pages
96152 */
96153-int access_process_vm(struct task_struct *tsk, unsigned long addr,
96154- void *buf, int len, int write)
96155+ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr,
96156+ void *buf, size_t len, int write)
96157 {
96158 struct mm_struct *mm;
96159- int ret;
96160+ ssize_t ret;
96161
96162 mm = get_task_mm(tsk);
96163 if (!mm)
96164diff --git a/mm/mempolicy.c b/mm/mempolicy.c
96165index e58725a..e0be017 100644
96166--- a/mm/mempolicy.c
96167+++ b/mm/mempolicy.c
96168@@ -750,6 +750,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
96169 unsigned long vmstart;
96170 unsigned long vmend;
96171
96172+#ifdef CONFIG_PAX_SEGMEXEC
96173+ struct vm_area_struct *vma_m;
96174+#endif
96175+
96176 vma = find_vma(mm, start);
96177 if (!vma || vma->vm_start > start)
96178 return -EFAULT;
96179@@ -793,6 +797,16 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
96180 err = vma_replace_policy(vma, new_pol);
96181 if (err)
96182 goto out;
96183+
96184+#ifdef CONFIG_PAX_SEGMEXEC
96185+ vma_m = pax_find_mirror_vma(vma);
96186+ if (vma_m) {
96187+ err = vma_replace_policy(vma_m, new_pol);
96188+ if (err)
96189+ goto out;
96190+ }
96191+#endif
96192+
96193 }
96194
96195 out:
96196@@ -1212,6 +1226,17 @@ static long do_mbind(unsigned long start, unsigned long len,
96197
96198 if (end < start)
96199 return -EINVAL;
96200+
96201+#ifdef CONFIG_PAX_SEGMEXEC
96202+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
96203+ if (end > SEGMEXEC_TASK_SIZE)
96204+ return -EINVAL;
96205+ } else
96206+#endif
96207+
96208+ if (end > TASK_SIZE)
96209+ return -EINVAL;
96210+
96211 if (end == start)
96212 return 0;
96213
96214@@ -1437,8 +1462,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
96215 */
96216 tcred = __task_cred(task);
96217 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
96218- !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
96219- !capable(CAP_SYS_NICE)) {
96220+ !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
96221 rcu_read_unlock();
96222 err = -EPERM;
96223 goto out_put;
96224@@ -1469,6 +1493,15 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
96225 goto out;
96226 }
96227
96228+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
96229+ if (mm != current->mm &&
96230+ (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
96231+ mmput(mm);
96232+ err = -EPERM;
96233+ goto out;
96234+ }
96235+#endif
96236+
96237 err = do_migrate_pages(mm, old, new,
96238 capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
96239
96240diff --git a/mm/migrate.c b/mm/migrate.c
96241index 0143995..b294728 100644
96242--- a/mm/migrate.c
96243+++ b/mm/migrate.c
96244@@ -1495,8 +1495,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
96245 */
96246 tcred = __task_cred(task);
96247 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
96248- !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
96249- !capable(CAP_SYS_NICE)) {
96250+ !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
96251 rcu_read_unlock();
96252 err = -EPERM;
96253 goto out;
96254diff --git a/mm/mlock.c b/mm/mlock.c
96255index 73cf098..ab547c7 100644
96256--- a/mm/mlock.c
96257+++ b/mm/mlock.c
96258@@ -14,6 +14,7 @@
96259 #include <linux/pagevec.h>
96260 #include <linux/mempolicy.h>
96261 #include <linux/syscalls.h>
96262+#include <linux/security.h>
96263 #include <linux/sched.h>
96264 #include <linux/export.h>
96265 #include <linux/rmap.h>
96266@@ -613,7 +614,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
96267 {
96268 unsigned long nstart, end, tmp;
96269 struct vm_area_struct * vma, * prev;
96270- int error;
96271+ int error = 0;
96272
96273 VM_BUG_ON(start & ~PAGE_MASK);
96274 VM_BUG_ON(len != PAGE_ALIGN(len));
96275@@ -622,6 +623,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
96276 return -EINVAL;
96277 if (end == start)
96278 return 0;
96279+ if (end > TASK_SIZE)
96280+ return -EINVAL;
96281+
96282 vma = find_vma(current->mm, start);
96283 if (!vma || vma->vm_start > start)
96284 return -ENOMEM;
96285@@ -633,6 +637,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
96286 for (nstart = start ; ; ) {
96287 vm_flags_t newflags;
96288
96289+#ifdef CONFIG_PAX_SEGMEXEC
96290+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
96291+ break;
96292+#endif
96293+
96294 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
96295
96296 newflags = vma->vm_flags & ~VM_LOCKED;
96297@@ -746,6 +755,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
96298 locked += current->mm->locked_vm;
96299
96300 /* check against resource limits */
96301+ gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
96302 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
96303 error = do_mlock(start, len, 1);
96304
96305@@ -783,6 +793,11 @@ static int do_mlockall(int flags)
96306 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
96307 vm_flags_t newflags;
96308
96309+#ifdef CONFIG_PAX_SEGMEXEC
96310+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
96311+ break;
96312+#endif
96313+
96314 newflags = vma->vm_flags & ~VM_LOCKED;
96315 if (flags & MCL_CURRENT)
96316 newflags |= VM_LOCKED;
96317@@ -814,8 +829,10 @@ SYSCALL_DEFINE1(mlockall, int, flags)
96318 lock_limit >>= PAGE_SHIFT;
96319
96320 ret = -ENOMEM;
96321+
96322+ gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
96323+
96324 down_write(&current->mm->mmap_sem);
96325-
96326 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
96327 capable(CAP_IPC_LOCK))
96328 ret = do_mlockall(flags);
96329diff --git a/mm/mmap.c b/mm/mmap.c
96330index 1620adb..348da48 100644
96331--- a/mm/mmap.c
96332+++ b/mm/mmap.c
96333@@ -41,6 +41,7 @@
96334 #include <linux/notifier.h>
96335 #include <linux/memory.h>
96336 #include <linux/printk.h>
96337+#include <linux/random.h>
96338
96339 #include <asm/uaccess.h>
96340 #include <asm/cacheflush.h>
96341@@ -57,6 +58,16 @@
96342 #define arch_rebalance_pgtables(addr, len) (addr)
96343 #endif
96344
96345+static inline void verify_mm_writelocked(struct mm_struct *mm)
96346+{
96347+#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
96348+ if (unlikely(down_read_trylock(&mm->mmap_sem))) {
96349+ up_read(&mm->mmap_sem);
96350+ BUG();
96351+ }
96352+#endif
96353+}
96354+
96355 static void unmap_region(struct mm_struct *mm,
96356 struct vm_area_struct *vma, struct vm_area_struct *prev,
96357 unsigned long start, unsigned long end);
96358@@ -76,16 +87,25 @@ static void unmap_region(struct mm_struct *mm,
96359 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
96360 *
96361 */
96362-pgprot_t protection_map[16] = {
96363+pgprot_t protection_map[16] __read_only = {
96364 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
96365 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
96366 };
96367
96368-pgprot_t vm_get_page_prot(unsigned long vm_flags)
96369+pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
96370 {
96371- return __pgprot(pgprot_val(protection_map[vm_flags &
96372+ pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
96373 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
96374 pgprot_val(arch_vm_get_page_prot(vm_flags)));
96375+
96376+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
96377+ if (!(__supported_pte_mask & _PAGE_NX) &&
96378+ (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
96379+ (vm_flags & (VM_READ | VM_WRITE)))
96380+ prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
96381+#endif
96382+
96383+ return prot;
96384 }
96385 EXPORT_SYMBOL(vm_get_page_prot);
96386
96387@@ -114,6 +134,7 @@ unsigned long sysctl_overcommit_kbytes __read_mostly;
96388 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
96389 unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
96390 unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
96391+unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
96392 /*
96393 * Make sure vm_committed_as in one cacheline and not cacheline shared with
96394 * other variables. It can be updated by several CPUs frequently.
96395@@ -274,6 +295,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
96396 struct vm_area_struct *next = vma->vm_next;
96397
96398 might_sleep();
96399+ BUG_ON(vma->vm_mirror);
96400 if (vma->vm_ops && vma->vm_ops->close)
96401 vma->vm_ops->close(vma);
96402 if (vma->vm_file)
96403@@ -287,6 +309,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len);
96404
96405 SYSCALL_DEFINE1(brk, unsigned long, brk)
96406 {
96407+ unsigned long rlim;
96408 unsigned long retval;
96409 unsigned long newbrk, oldbrk;
96410 struct mm_struct *mm = current->mm;
96411@@ -317,7 +340,13 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
96412 * segment grow beyond its set limit the in case where the limit is
96413 * not page aligned -Ram Gupta
96414 */
96415- if (check_data_rlimit(rlimit(RLIMIT_DATA), brk, mm->start_brk,
96416+ rlim = rlimit(RLIMIT_DATA);
96417+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
96418+ /* force a minimum 16MB brk heap on setuid/setgid binaries */
96419+ if (rlim < PAGE_SIZE && (get_dumpable(mm) != SUID_DUMP_USER) && gr_is_global_nonroot(current_uid()))
96420+ rlim = 4096 * PAGE_SIZE;
96421+#endif
96422+ if (check_data_rlimit(rlim, brk, mm->start_brk,
96423 mm->end_data, mm->start_data))
96424 goto out;
96425
96426@@ -976,6 +1005,12 @@ static int
96427 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
96428 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
96429 {
96430+
96431+#ifdef CONFIG_PAX_SEGMEXEC
96432+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
96433+ return 0;
96434+#endif
96435+
96436 if (is_mergeable_vma(vma, file, vm_flags) &&
96437 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
96438 if (vma->vm_pgoff == vm_pgoff)
96439@@ -995,6 +1030,12 @@ static int
96440 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
96441 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
96442 {
96443+
96444+#ifdef CONFIG_PAX_SEGMEXEC
96445+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
96446+ return 0;
96447+#endif
96448+
96449 if (is_mergeable_vma(vma, file, vm_flags) &&
96450 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
96451 pgoff_t vm_pglen;
96452@@ -1044,6 +1085,13 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
96453 struct vm_area_struct *area, *next;
96454 int err;
96455
96456+#ifdef CONFIG_PAX_SEGMEXEC
96457+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
96458+ struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
96459+
96460+ BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
96461+#endif
96462+
96463 /*
96464 * We later require that vma->vm_flags == vm_flags,
96465 * so this tests vma->vm_flags & VM_SPECIAL, too.
96466@@ -1059,6 +1107,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
96467 if (next && next->vm_end == end) /* cases 6, 7, 8 */
96468 next = next->vm_next;
96469
96470+#ifdef CONFIG_PAX_SEGMEXEC
96471+ if (prev)
96472+ prev_m = pax_find_mirror_vma(prev);
96473+ if (area)
96474+ area_m = pax_find_mirror_vma(area);
96475+ if (next)
96476+ next_m = pax_find_mirror_vma(next);
96477+#endif
96478+
96479 /*
96480 * Can it merge with the predecessor?
96481 */
96482@@ -1078,9 +1135,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
96483 /* cases 1, 6 */
96484 err = vma_adjust(prev, prev->vm_start,
96485 next->vm_end, prev->vm_pgoff, NULL);
96486- } else /* cases 2, 5, 7 */
96487+
96488+#ifdef CONFIG_PAX_SEGMEXEC
96489+ if (!err && prev_m)
96490+ err = vma_adjust(prev_m, prev_m->vm_start,
96491+ next_m->vm_end, prev_m->vm_pgoff, NULL);
96492+#endif
96493+
96494+ } else { /* cases 2, 5, 7 */
96495 err = vma_adjust(prev, prev->vm_start,
96496 end, prev->vm_pgoff, NULL);
96497+
96498+#ifdef CONFIG_PAX_SEGMEXEC
96499+ if (!err && prev_m)
96500+ err = vma_adjust(prev_m, prev_m->vm_start,
96501+ end_m, prev_m->vm_pgoff, NULL);
96502+#endif
96503+
96504+ }
96505 if (err)
96506 return NULL;
96507 khugepaged_enter_vma_merge(prev, vm_flags);
96508@@ -1094,12 +1166,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
96509 mpol_equal(policy, vma_policy(next)) &&
96510 can_vma_merge_before(next, vm_flags,
96511 anon_vma, file, pgoff+pglen)) {
96512- if (prev && addr < prev->vm_end) /* case 4 */
96513+ if (prev && addr < prev->vm_end) { /* case 4 */
96514 err = vma_adjust(prev, prev->vm_start,
96515 addr, prev->vm_pgoff, NULL);
96516- else /* cases 3, 8 */
96517+
96518+#ifdef CONFIG_PAX_SEGMEXEC
96519+ if (!err && prev_m)
96520+ err = vma_adjust(prev_m, prev_m->vm_start,
96521+ addr_m, prev_m->vm_pgoff, NULL);
96522+#endif
96523+
96524+ } else { /* cases 3, 8 */
96525 err = vma_adjust(area, addr, next->vm_end,
96526 next->vm_pgoff - pglen, NULL);
96527+
96528+#ifdef CONFIG_PAX_SEGMEXEC
96529+ if (!err && area_m)
96530+ err = vma_adjust(area_m, addr_m, next_m->vm_end,
96531+ next_m->vm_pgoff - pglen, NULL);
96532+#endif
96533+
96534+ }
96535 if (err)
96536 return NULL;
96537 khugepaged_enter_vma_merge(area, vm_flags);
96538@@ -1208,8 +1295,10 @@ none:
96539 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
96540 struct file *file, long pages)
96541 {
96542- const unsigned long stack_flags
96543- = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
96544+
96545+#ifdef CONFIG_PAX_RANDMMAP
96546+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
96547+#endif
96548
96549 mm->total_vm += pages;
96550
96551@@ -1217,7 +1306,7 @@ void vm_stat_account(struct mm_struct *mm, unsigned long flags,
96552 mm->shared_vm += pages;
96553 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
96554 mm->exec_vm += pages;
96555- } else if (flags & stack_flags)
96556+ } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
96557 mm->stack_vm += pages;
96558 }
96559 #endif /* CONFIG_PROC_FS */
96560@@ -1247,6 +1336,7 @@ static inline int mlock_future_check(struct mm_struct *mm,
96561 locked += mm->locked_vm;
96562 lock_limit = rlimit(RLIMIT_MEMLOCK);
96563 lock_limit >>= PAGE_SHIFT;
96564+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
96565 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
96566 return -EAGAIN;
96567 }
96568@@ -1273,7 +1363,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
96569 * (the exception is when the underlying filesystem is noexec
96570 * mounted, in which case we dont add PROT_EXEC.)
96571 */
96572- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
96573+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
96574 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
96575 prot |= PROT_EXEC;
96576
96577@@ -1299,7 +1389,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
96578 /* Obtain the address to map to. we verify (or select) it and ensure
96579 * that it represents a valid section of the address space.
96580 */
96581- addr = get_unmapped_area(file, addr, len, pgoff, flags);
96582+ addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
96583 if (addr & ~PAGE_MASK)
96584 return addr;
96585
96586@@ -1310,6 +1400,43 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
96587 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
96588 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
96589
96590+#ifdef CONFIG_PAX_MPROTECT
96591+ if (mm->pax_flags & MF_PAX_MPROTECT) {
96592+
96593+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
96594+ if (file && !pgoff && (vm_flags & VM_EXEC) && mm->binfmt &&
96595+ mm->binfmt->handle_mmap)
96596+ mm->binfmt->handle_mmap(file);
96597+#endif
96598+
96599+#ifndef CONFIG_PAX_MPROTECT_COMPAT
96600+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
96601+ gr_log_rwxmmap(file);
96602+
96603+#ifdef CONFIG_PAX_EMUPLT
96604+ vm_flags &= ~VM_EXEC;
96605+#else
96606+ return -EPERM;
96607+#endif
96608+
96609+ }
96610+
96611+ if (!(vm_flags & VM_EXEC))
96612+ vm_flags &= ~VM_MAYEXEC;
96613+#else
96614+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
96615+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
96616+#endif
96617+ else
96618+ vm_flags &= ~VM_MAYWRITE;
96619+ }
96620+#endif
96621+
96622+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
96623+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
96624+ vm_flags &= ~VM_PAGEEXEC;
96625+#endif
96626+
96627 if (flags & MAP_LOCKED)
96628 if (!can_do_mlock())
96629 return -EPERM;
96630@@ -1397,6 +1524,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
96631 vm_flags |= VM_NORESERVE;
96632 }
96633
96634+ if (!gr_acl_handle_mmap(file, prot))
96635+ return -EACCES;
96636+
96637 addr = mmap_region(file, addr, len, vm_flags, pgoff);
96638 if (!IS_ERR_VALUE(addr) &&
96639 ((vm_flags & VM_LOCKED) ||
96640@@ -1490,7 +1620,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
96641 vm_flags_t vm_flags = vma->vm_flags;
96642
96643 /* If it was private or non-writable, the write bit is already clear */
96644- if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
96645+ if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
96646 return 0;
96647
96648 /* The backer wishes to know when pages are first written to? */
96649@@ -1541,7 +1671,22 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
96650 struct rb_node **rb_link, *rb_parent;
96651 unsigned long charged = 0;
96652
96653+#ifdef CONFIG_PAX_SEGMEXEC
96654+ struct vm_area_struct *vma_m = NULL;
96655+#endif
96656+
96657+ /*
96658+ * mm->mmap_sem is required to protect against another thread
96659+ * changing the mappings in case we sleep.
96660+ */
96661+ verify_mm_writelocked(mm);
96662+
96663 /* Check against address space limit. */
96664+
96665+#ifdef CONFIG_PAX_RANDMMAP
96666+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (vm_flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
96667+#endif
96668+
96669 if (!may_expand_vm(mm, len >> PAGE_SHIFT)) {
96670 unsigned long nr_pages;
96671
96672@@ -1560,11 +1705,10 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
96673
96674 /* Clear old maps */
96675 error = -ENOMEM;
96676-munmap_back:
96677 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
96678 if (do_munmap(mm, addr, len))
96679 return -ENOMEM;
96680- goto munmap_back;
96681+ BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
96682 }
96683
96684 /*
96685@@ -1595,6 +1739,16 @@ munmap_back:
96686 goto unacct_error;
96687 }
96688
96689+#ifdef CONFIG_PAX_SEGMEXEC
96690+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
96691+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
96692+ if (!vma_m) {
96693+ error = -ENOMEM;
96694+ goto free_vma;
96695+ }
96696+ }
96697+#endif
96698+
96699 vma->vm_mm = mm;
96700 vma->vm_start = addr;
96701 vma->vm_end = addr + len;
96702@@ -1625,6 +1779,13 @@ munmap_back:
96703 if (error)
96704 goto unmap_and_free_vma;
96705
96706+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
96707+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
96708+ vma->vm_flags |= VM_PAGEEXEC;
96709+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
96710+ }
96711+#endif
96712+
96713 /* Can addr have changed??
96714 *
96715 * Answer: Yes, several device drivers can do it in their
96716@@ -1643,6 +1804,12 @@ munmap_back:
96717 }
96718
96719 vma_link(mm, vma, prev, rb_link, rb_parent);
96720+
96721+#ifdef CONFIG_PAX_SEGMEXEC
96722+ if (vma_m)
96723+ BUG_ON(pax_mirror_vma(vma_m, vma));
96724+#endif
96725+
96726 /* Once vma denies write, undo our temporary denial count */
96727 if (file) {
96728 if (vm_flags & VM_SHARED)
96729@@ -1655,6 +1822,7 @@ out:
96730 perf_event_mmap(vma);
96731
96732 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
96733+ track_exec_limit(mm, addr, addr + len, vm_flags);
96734 if (vm_flags & VM_LOCKED) {
96735 if (!((vm_flags & VM_SPECIAL) || is_vm_hugetlb_page(vma) ||
96736 vma == get_gate_vma(current->mm)))
96737@@ -1692,6 +1860,12 @@ allow_write_and_free_vma:
96738 if (vm_flags & VM_DENYWRITE)
96739 allow_write_access(file);
96740 free_vma:
96741+
96742+#ifdef CONFIG_PAX_SEGMEXEC
96743+ if (vma_m)
96744+ kmem_cache_free(vm_area_cachep, vma_m);
96745+#endif
96746+
96747 kmem_cache_free(vm_area_cachep, vma);
96748 unacct_error:
96749 if (charged)
96750@@ -1699,7 +1873,63 @@ unacct_error:
96751 return error;
96752 }
96753
96754-unsigned long unmapped_area(struct vm_unmapped_area_info *info)
96755+#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
96756+unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
96757+{
96758+ if ((mm->pax_flags & MF_PAX_RANDMMAP) && !filp && (flags & MAP_STACK))
96759+ return ((prandom_u32() & 0xFF) + 1) << PAGE_SHIFT;
96760+
96761+ return 0;
96762+}
96763+#endif
96764+
96765+bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset)
96766+{
96767+ if (!vma) {
96768+#ifdef CONFIG_STACK_GROWSUP
96769+ if (addr > sysctl_heap_stack_gap)
96770+ vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
96771+ else
96772+ vma = find_vma(current->mm, 0);
96773+ if (vma && (vma->vm_flags & VM_GROWSUP))
96774+ return false;
96775+#endif
96776+ return true;
96777+ }
96778+
96779+ if (addr + len > vma->vm_start)
96780+ return false;
96781+
96782+ if (vma->vm_flags & VM_GROWSDOWN)
96783+ return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
96784+#ifdef CONFIG_STACK_GROWSUP
96785+ else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
96786+ return addr - vma->vm_prev->vm_end >= sysctl_heap_stack_gap;
96787+#endif
96788+ else if (offset)
96789+ return offset <= vma->vm_start - addr - len;
96790+
96791+ return true;
96792+}
96793+
96794+unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset)
96795+{
96796+ if (vma->vm_start < len)
96797+ return -ENOMEM;
96798+
96799+ if (!(vma->vm_flags & VM_GROWSDOWN)) {
96800+ if (offset <= vma->vm_start - len)
96801+ return vma->vm_start - len - offset;
96802+ else
96803+ return -ENOMEM;
96804+ }
96805+
96806+ if (sysctl_heap_stack_gap <= vma->vm_start - len)
96807+ return vma->vm_start - len - sysctl_heap_stack_gap;
96808+ return -ENOMEM;
96809+}
96810+
96811+unsigned long unmapped_area(const struct vm_unmapped_area_info *info)
96812 {
96813 /*
96814 * We implement the search by looking for an rbtree node that
96815@@ -1747,11 +1977,29 @@ unsigned long unmapped_area(struct vm_unmapped_area_info *info)
96816 }
96817 }
96818
96819- gap_start = vma->vm_prev ? vma->vm_prev->vm_end : 0;
96820+ gap_start = vma->vm_prev ? vma->vm_prev->vm_end: 0;
96821 check_current:
96822 /* Check if current node has a suitable gap */
96823 if (gap_start > high_limit)
96824 return -ENOMEM;
96825+
96826+ if (gap_end - gap_start > info->threadstack_offset)
96827+ gap_start += info->threadstack_offset;
96828+ else
96829+ gap_start = gap_end;
96830+
96831+ if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
96832+ if (gap_end - gap_start > sysctl_heap_stack_gap)
96833+ gap_start += sysctl_heap_stack_gap;
96834+ else
96835+ gap_start = gap_end;
96836+ }
96837+ if (vma->vm_flags & VM_GROWSDOWN) {
96838+ if (gap_end - gap_start > sysctl_heap_stack_gap)
96839+ gap_end -= sysctl_heap_stack_gap;
96840+ else
96841+ gap_end = gap_start;
96842+ }
96843 if (gap_end >= low_limit && gap_end - gap_start >= length)
96844 goto found;
96845
96846@@ -1801,7 +2049,7 @@ found:
96847 return gap_start;
96848 }
96849
96850-unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info)
96851+unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info)
96852 {
96853 struct mm_struct *mm = current->mm;
96854 struct vm_area_struct *vma;
96855@@ -1855,6 +2103,24 @@ check_current:
96856 gap_end = vma->vm_start;
96857 if (gap_end < low_limit)
96858 return -ENOMEM;
96859+
96860+ if (gap_end - gap_start > info->threadstack_offset)
96861+ gap_end -= info->threadstack_offset;
96862+ else
96863+ gap_end = gap_start;
96864+
96865+ if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
96866+ if (gap_end - gap_start > sysctl_heap_stack_gap)
96867+ gap_start += sysctl_heap_stack_gap;
96868+ else
96869+ gap_start = gap_end;
96870+ }
96871+ if (vma->vm_flags & VM_GROWSDOWN) {
96872+ if (gap_end - gap_start > sysctl_heap_stack_gap)
96873+ gap_end -= sysctl_heap_stack_gap;
96874+ else
96875+ gap_end = gap_start;
96876+ }
96877 if (gap_start <= high_limit && gap_end - gap_start >= length)
96878 goto found;
96879
96880@@ -1918,6 +2184,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
96881 struct mm_struct *mm = current->mm;
96882 struct vm_area_struct *vma;
96883 struct vm_unmapped_area_info info;
96884+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
96885
96886 if (len > TASK_SIZE - mmap_min_addr)
96887 return -ENOMEM;
96888@@ -1925,11 +2192,15 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
96889 if (flags & MAP_FIXED)
96890 return addr;
96891
96892+#ifdef CONFIG_PAX_RANDMMAP
96893+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
96894+#endif
96895+
96896 if (addr) {
96897 addr = PAGE_ALIGN(addr);
96898 vma = find_vma(mm, addr);
96899 if (TASK_SIZE - len >= addr && addr >= mmap_min_addr &&
96900- (!vma || addr + len <= vma->vm_start))
96901+ check_heap_stack_gap(vma, addr, len, offset))
96902 return addr;
96903 }
96904
96905@@ -1938,6 +2209,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
96906 info.low_limit = mm->mmap_base;
96907 info.high_limit = TASK_SIZE;
96908 info.align_mask = 0;
96909+ info.threadstack_offset = offset;
96910 return vm_unmapped_area(&info);
96911 }
96912 #endif
96913@@ -1956,6 +2228,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
96914 struct mm_struct *mm = current->mm;
96915 unsigned long addr = addr0;
96916 struct vm_unmapped_area_info info;
96917+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
96918
96919 /* requested length too big for entire address space */
96920 if (len > TASK_SIZE - mmap_min_addr)
96921@@ -1964,12 +2237,16 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
96922 if (flags & MAP_FIXED)
96923 return addr;
96924
96925+#ifdef CONFIG_PAX_RANDMMAP
96926+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
96927+#endif
96928+
96929 /* requesting a specific address */
96930 if (addr) {
96931 addr = PAGE_ALIGN(addr);
96932 vma = find_vma(mm, addr);
96933 if (TASK_SIZE - len >= addr && addr >= mmap_min_addr &&
96934- (!vma || addr + len <= vma->vm_start))
96935+ check_heap_stack_gap(vma, addr, len, offset))
96936 return addr;
96937 }
96938
96939@@ -1978,6 +2255,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
96940 info.low_limit = max(PAGE_SIZE, mmap_min_addr);
96941 info.high_limit = mm->mmap_base;
96942 info.align_mask = 0;
96943+ info.threadstack_offset = offset;
96944 addr = vm_unmapped_area(&info);
96945
96946 /*
96947@@ -1990,6 +2268,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
96948 VM_BUG_ON(addr != -ENOMEM);
96949 info.flags = 0;
96950 info.low_limit = TASK_UNMAPPED_BASE;
96951+
96952+#ifdef CONFIG_PAX_RANDMMAP
96953+ if (mm->pax_flags & MF_PAX_RANDMMAP)
96954+ info.low_limit += mm->delta_mmap;
96955+#endif
96956+
96957 info.high_limit = TASK_SIZE;
96958 addr = vm_unmapped_area(&info);
96959 }
96960@@ -2090,6 +2374,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
96961 return vma;
96962 }
96963
96964+#ifdef CONFIG_PAX_SEGMEXEC
96965+struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
96966+{
96967+ struct vm_area_struct *vma_m;
96968+
96969+ BUG_ON(!vma || vma->vm_start >= vma->vm_end);
96970+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
96971+ BUG_ON(vma->vm_mirror);
96972+ return NULL;
96973+ }
96974+ BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
96975+ vma_m = vma->vm_mirror;
96976+ BUG_ON(!vma_m || vma_m->vm_mirror != vma);
96977+ BUG_ON(vma->vm_file != vma_m->vm_file);
96978+ BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
96979+ BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
96980+ BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
96981+ BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED));
96982+ return vma_m;
96983+}
96984+#endif
96985+
96986 /*
96987 * Verify that the stack growth is acceptable and
96988 * update accounting. This is shared with both the
96989@@ -2107,8 +2413,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
96990
96991 /* Stack limit test */
96992 actual_size = size;
96993- if (size && (vma->vm_flags & (VM_GROWSUP | VM_GROWSDOWN)))
96994- actual_size -= PAGE_SIZE;
96995+ gr_learn_resource(current, RLIMIT_STACK, actual_size, 1);
96996 if (actual_size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
96997 return -ENOMEM;
96998
96999@@ -2119,6 +2424,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
97000 locked = mm->locked_vm + grow;
97001 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
97002 limit >>= PAGE_SHIFT;
97003+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
97004 if (locked > limit && !capable(CAP_IPC_LOCK))
97005 return -ENOMEM;
97006 }
97007@@ -2148,37 +2454,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
97008 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
97009 * vma is the last one with address > vma->vm_end. Have to extend vma.
97010 */
97011+#ifndef CONFIG_IA64
97012+static
97013+#endif
97014 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
97015 {
97016 int error;
97017+ bool locknext;
97018
97019 if (!(vma->vm_flags & VM_GROWSUP))
97020 return -EFAULT;
97021
97022+ /* Also guard against wrapping around to address 0. */
97023+ if (address < PAGE_ALIGN(address+1))
97024+ address = PAGE_ALIGN(address+1);
97025+ else
97026+ return -ENOMEM;
97027+
97028 /*
97029 * We must make sure the anon_vma is allocated
97030 * so that the anon_vma locking is not a noop.
97031 */
97032 if (unlikely(anon_vma_prepare(vma)))
97033 return -ENOMEM;
97034+ locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
97035+ if (locknext && anon_vma_prepare(vma->vm_next))
97036+ return -ENOMEM;
97037 vma_lock_anon_vma(vma);
97038+ if (locknext)
97039+ vma_lock_anon_vma(vma->vm_next);
97040
97041 /*
97042 * vma->vm_start/vm_end cannot change under us because the caller
97043 * is required to hold the mmap_sem in read mode. We need the
97044- * anon_vma lock to serialize against concurrent expand_stacks.
97045- * Also guard against wrapping around to address 0.
97046+ * anon_vma locks to serialize against concurrent expand_stacks
97047+ * and expand_upwards.
97048 */
97049- if (address < PAGE_ALIGN(address+4))
97050- address = PAGE_ALIGN(address+4);
97051- else {
97052- vma_unlock_anon_vma(vma);
97053- return -ENOMEM;
97054- }
97055 error = 0;
97056
97057 /* Somebody else might have raced and expanded it already */
97058- if (address > vma->vm_end) {
97059+ 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)
97060+ error = -ENOMEM;
97061+ else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
97062 unsigned long size, grow;
97063
97064 size = address - vma->vm_start;
97065@@ -2213,6 +2530,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
97066 }
97067 }
97068 }
97069+ if (locknext)
97070+ vma_unlock_anon_vma(vma->vm_next);
97071 vma_unlock_anon_vma(vma);
97072 khugepaged_enter_vma_merge(vma, vma->vm_flags);
97073 validate_mm(vma->vm_mm);
97074@@ -2227,6 +2546,8 @@ int expand_downwards(struct vm_area_struct *vma,
97075 unsigned long address)
97076 {
97077 int error;
97078+ bool lockprev = false;
97079+ struct vm_area_struct *prev;
97080
97081 /*
97082 * We must make sure the anon_vma is allocated
97083@@ -2240,6 +2561,15 @@ int expand_downwards(struct vm_area_struct *vma,
97084 if (error)
97085 return error;
97086
97087+ prev = vma->vm_prev;
97088+#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
97089+ lockprev = prev && (prev->vm_flags & VM_GROWSUP);
97090+#endif
97091+ if (lockprev && anon_vma_prepare(prev))
97092+ return -ENOMEM;
97093+ if (lockprev)
97094+ vma_lock_anon_vma(prev);
97095+
97096 vma_lock_anon_vma(vma);
97097
97098 /*
97099@@ -2249,9 +2579,17 @@ int expand_downwards(struct vm_area_struct *vma,
97100 */
97101
97102 /* Somebody else might have raced and expanded it already */
97103- if (address < vma->vm_start) {
97104+ if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
97105+ error = -ENOMEM;
97106+ else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
97107 unsigned long size, grow;
97108
97109+#ifdef CONFIG_PAX_SEGMEXEC
97110+ struct vm_area_struct *vma_m;
97111+
97112+ vma_m = pax_find_mirror_vma(vma);
97113+#endif
97114+
97115 size = vma->vm_end - address;
97116 grow = (vma->vm_start - address) >> PAGE_SHIFT;
97117
97118@@ -2276,13 +2614,27 @@ int expand_downwards(struct vm_area_struct *vma,
97119 vma->vm_pgoff -= grow;
97120 anon_vma_interval_tree_post_update_vma(vma);
97121 vma_gap_update(vma);
97122+
97123+#ifdef CONFIG_PAX_SEGMEXEC
97124+ if (vma_m) {
97125+ anon_vma_interval_tree_pre_update_vma(vma_m);
97126+ vma_m->vm_start -= grow << PAGE_SHIFT;
97127+ vma_m->vm_pgoff -= grow;
97128+ anon_vma_interval_tree_post_update_vma(vma_m);
97129+ vma_gap_update(vma_m);
97130+ }
97131+#endif
97132+
97133 spin_unlock(&vma->vm_mm->page_table_lock);
97134
97135+ track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
97136 perf_event_mmap(vma);
97137 }
97138 }
97139 }
97140 vma_unlock_anon_vma(vma);
97141+ if (lockprev)
97142+ vma_unlock_anon_vma(prev);
97143 khugepaged_enter_vma_merge(vma, vma->vm_flags);
97144 validate_mm(vma->vm_mm);
97145 return error;
97146@@ -2380,6 +2732,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
97147 do {
97148 long nrpages = vma_pages(vma);
97149
97150+#ifdef CONFIG_PAX_SEGMEXEC
97151+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
97152+ vma = remove_vma(vma);
97153+ continue;
97154+ }
97155+#endif
97156+
97157 if (vma->vm_flags & VM_ACCOUNT)
97158 nr_accounted += nrpages;
97159 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
97160@@ -2424,6 +2783,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
97161 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
97162 vma->vm_prev = NULL;
97163 do {
97164+
97165+#ifdef CONFIG_PAX_SEGMEXEC
97166+ if (vma->vm_mirror) {
97167+ BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
97168+ vma->vm_mirror->vm_mirror = NULL;
97169+ vma->vm_mirror->vm_flags &= ~VM_EXEC;
97170+ vma->vm_mirror = NULL;
97171+ }
97172+#endif
97173+
97174 vma_rb_erase(vma, &mm->mm_rb);
97175 mm->map_count--;
97176 tail_vma = vma;
97177@@ -2451,14 +2820,33 @@ static int __split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
97178 struct vm_area_struct *new;
97179 int err = -ENOMEM;
97180
97181+#ifdef CONFIG_PAX_SEGMEXEC
97182+ struct vm_area_struct *vma_m, *new_m = NULL;
97183+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
97184+#endif
97185+
97186 if (is_vm_hugetlb_page(vma) && (addr &
97187 ~(huge_page_mask(hstate_vma(vma)))))
97188 return -EINVAL;
97189
97190+#ifdef CONFIG_PAX_SEGMEXEC
97191+ vma_m = pax_find_mirror_vma(vma);
97192+#endif
97193+
97194 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
97195 if (!new)
97196 goto out_err;
97197
97198+#ifdef CONFIG_PAX_SEGMEXEC
97199+ if (vma_m) {
97200+ new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
97201+ if (!new_m) {
97202+ kmem_cache_free(vm_area_cachep, new);
97203+ goto out_err;
97204+ }
97205+ }
97206+#endif
97207+
97208 /* most fields are the same, copy all, and then fixup */
97209 *new = *vma;
97210
97211@@ -2471,6 +2859,22 @@ static int __split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
97212 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
97213 }
97214
97215+#ifdef CONFIG_PAX_SEGMEXEC
97216+ if (vma_m) {
97217+ *new_m = *vma_m;
97218+ INIT_LIST_HEAD(&new_m->anon_vma_chain);
97219+ new_m->vm_mirror = new;
97220+ new->vm_mirror = new_m;
97221+
97222+ if (new_below)
97223+ new_m->vm_end = addr_m;
97224+ else {
97225+ new_m->vm_start = addr_m;
97226+ new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
97227+ }
97228+ }
97229+#endif
97230+
97231 err = vma_dup_policy(vma, new);
97232 if (err)
97233 goto out_free_vma;
97234@@ -2491,6 +2895,38 @@ static int __split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
97235 else
97236 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
97237
97238+#ifdef CONFIG_PAX_SEGMEXEC
97239+ if (!err && vma_m) {
97240+ struct mempolicy *pol = vma_policy(new);
97241+
97242+ if (anon_vma_clone(new_m, vma_m))
97243+ goto out_free_mpol;
97244+
97245+ mpol_get(pol);
97246+ set_vma_policy(new_m, pol);
97247+
97248+ if (new_m->vm_file)
97249+ get_file(new_m->vm_file);
97250+
97251+ if (new_m->vm_ops && new_m->vm_ops->open)
97252+ new_m->vm_ops->open(new_m);
97253+
97254+ if (new_below)
97255+ err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
97256+ ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
97257+ else
97258+ err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
97259+
97260+ if (err) {
97261+ if (new_m->vm_ops && new_m->vm_ops->close)
97262+ new_m->vm_ops->close(new_m);
97263+ if (new_m->vm_file)
97264+ fput(new_m->vm_file);
97265+ mpol_put(pol);
97266+ }
97267+ }
97268+#endif
97269+
97270 /* Success. */
97271 if (!err)
97272 return 0;
97273@@ -2500,10 +2936,18 @@ static int __split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
97274 new->vm_ops->close(new);
97275 if (new->vm_file)
97276 fput(new->vm_file);
97277- unlink_anon_vmas(new);
97278 out_free_mpol:
97279 mpol_put(vma_policy(new));
97280 out_free_vma:
97281+
97282+#ifdef CONFIG_PAX_SEGMEXEC
97283+ if (new_m) {
97284+ unlink_anon_vmas(new_m);
97285+ kmem_cache_free(vm_area_cachep, new_m);
97286+ }
97287+#endif
97288+
97289+ unlink_anon_vmas(new);
97290 kmem_cache_free(vm_area_cachep, new);
97291 out_err:
97292 return err;
97293@@ -2516,6 +2960,15 @@ static int __split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
97294 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
97295 unsigned long addr, int new_below)
97296 {
97297+
97298+#ifdef CONFIG_PAX_SEGMEXEC
97299+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
97300+ BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
97301+ if (mm->map_count >= sysctl_max_map_count-1)
97302+ return -ENOMEM;
97303+ } else
97304+#endif
97305+
97306 if (mm->map_count >= sysctl_max_map_count)
97307 return -ENOMEM;
97308
97309@@ -2527,11 +2980,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
97310 * work. This now handles partial unmappings.
97311 * Jeremy Fitzhardinge <jeremy@goop.org>
97312 */
97313+#ifdef CONFIG_PAX_SEGMEXEC
97314 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
97315 {
97316+ int ret = __do_munmap(mm, start, len);
97317+ if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
97318+ return ret;
97319+
97320+ return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
97321+}
97322+
97323+int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
97324+#else
97325+int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
97326+#endif
97327+{
97328 unsigned long end;
97329 struct vm_area_struct *vma, *prev, *last;
97330
97331+ /*
97332+ * mm->mmap_sem is required to protect against another thread
97333+ * changing the mappings in case we sleep.
97334+ */
97335+ verify_mm_writelocked(mm);
97336+
97337 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
97338 return -EINVAL;
97339
97340@@ -2607,6 +3079,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
97341 /* Fix up all other VM information */
97342 remove_vma_list(mm, vma);
97343
97344+ track_exec_limit(mm, start, end, 0UL);
97345+
97346 return 0;
97347 }
97348
97349@@ -2615,6 +3089,13 @@ int vm_munmap(unsigned long start, size_t len)
97350 int ret;
97351 struct mm_struct *mm = current->mm;
97352
97353+
97354+#ifdef CONFIG_PAX_SEGMEXEC
97355+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
97356+ (len > SEGMEXEC_TASK_SIZE || start > SEGMEXEC_TASK_SIZE-len))
97357+ return -EINVAL;
97358+#endif
97359+
97360 down_write(&mm->mmap_sem);
97361 ret = do_munmap(mm, start, len);
97362 up_write(&mm->mmap_sem);
97363@@ -2628,16 +3109,6 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
97364 return vm_munmap(addr, len);
97365 }
97366
97367-static inline void verify_mm_writelocked(struct mm_struct *mm)
97368-{
97369-#ifdef CONFIG_DEBUG_VM
97370- if (unlikely(down_read_trylock(&mm->mmap_sem))) {
97371- WARN_ON(1);
97372- up_read(&mm->mmap_sem);
97373- }
97374-#endif
97375-}
97376-
97377 /*
97378 * this is really a simplified "do_mmap". it only handles
97379 * anonymous maps. eventually we may be able to do some
97380@@ -2651,6 +3122,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
97381 struct rb_node **rb_link, *rb_parent;
97382 pgoff_t pgoff = addr >> PAGE_SHIFT;
97383 int error;
97384+ unsigned long charged;
97385
97386 len = PAGE_ALIGN(len);
97387 if (!len)
97388@@ -2658,10 +3130,24 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
97389
97390 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
97391
97392+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
97393+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
97394+ flags &= ~VM_EXEC;
97395+
97396+#ifdef CONFIG_PAX_MPROTECT
97397+ if (mm->pax_flags & MF_PAX_MPROTECT)
97398+ flags &= ~VM_MAYEXEC;
97399+#endif
97400+
97401+ }
97402+#endif
97403+
97404 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
97405 if (error & ~PAGE_MASK)
97406 return error;
97407
97408+ charged = len >> PAGE_SHIFT;
97409+
97410 error = mlock_future_check(mm, mm->def_flags, len);
97411 if (error)
97412 return error;
97413@@ -2675,21 +3161,20 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
97414 /*
97415 * Clear old maps. this also does some error checking for us
97416 */
97417- munmap_back:
97418 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
97419 if (do_munmap(mm, addr, len))
97420 return -ENOMEM;
97421- goto munmap_back;
97422+ BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
97423 }
97424
97425 /* Check against address space limits *after* clearing old maps... */
97426- if (!may_expand_vm(mm, len >> PAGE_SHIFT))
97427+ if (!may_expand_vm(mm, charged))
97428 return -ENOMEM;
97429
97430 if (mm->map_count > sysctl_max_map_count)
97431 return -ENOMEM;
97432
97433- if (security_vm_enough_memory_mm(mm, len >> PAGE_SHIFT))
97434+ if (security_vm_enough_memory_mm(mm, charged))
97435 return -ENOMEM;
97436
97437 /* Can we just expand an old private anonymous mapping? */
97438@@ -2703,7 +3188,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
97439 */
97440 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
97441 if (!vma) {
97442- vm_unacct_memory(len >> PAGE_SHIFT);
97443+ vm_unacct_memory(charged);
97444 return -ENOMEM;
97445 }
97446
97447@@ -2717,10 +3202,11 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
97448 vma_link(mm, vma, prev, rb_link, rb_parent);
97449 out:
97450 perf_event_mmap(vma);
97451- mm->total_vm += len >> PAGE_SHIFT;
97452+ mm->total_vm += charged;
97453 if (flags & VM_LOCKED)
97454- mm->locked_vm += (len >> PAGE_SHIFT);
97455+ mm->locked_vm += charged;
97456 vma->vm_flags |= VM_SOFTDIRTY;
97457+ track_exec_limit(mm, addr, addr + len, flags);
97458 return addr;
97459 }
97460
97461@@ -2782,6 +3268,7 @@ void exit_mmap(struct mm_struct *mm)
97462 while (vma) {
97463 if (vma->vm_flags & VM_ACCOUNT)
97464 nr_accounted += vma_pages(vma);
97465+ vma->vm_mirror = NULL;
97466 vma = remove_vma(vma);
97467 }
97468 vm_unacct_memory(nr_accounted);
97469@@ -2799,6 +3286,13 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
97470 struct vm_area_struct *prev;
97471 struct rb_node **rb_link, *rb_parent;
97472
97473+#ifdef CONFIG_PAX_SEGMEXEC
97474+ struct vm_area_struct *vma_m = NULL;
97475+#endif
97476+
97477+ if (security_mmap_addr(vma->vm_start))
97478+ return -EPERM;
97479+
97480 /*
97481 * The vm_pgoff of a purely anonymous vma should be irrelevant
97482 * until its first write fault, when page's anon_vma and index
97483@@ -2822,7 +3316,21 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
97484 security_vm_enough_memory_mm(mm, vma_pages(vma)))
97485 return -ENOMEM;
97486
97487+#ifdef CONFIG_PAX_SEGMEXEC
97488+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
97489+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
97490+ if (!vma_m)
97491+ return -ENOMEM;
97492+ }
97493+#endif
97494+
97495 vma_link(mm, vma, prev, rb_link, rb_parent);
97496+
97497+#ifdef CONFIG_PAX_SEGMEXEC
97498+ if (vma_m)
97499+ BUG_ON(pax_mirror_vma(vma_m, vma));
97500+#endif
97501+
97502 return 0;
97503 }
97504
97505@@ -2841,6 +3349,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
97506 struct rb_node **rb_link, *rb_parent;
97507 bool faulted_in_anon_vma = true;
97508
97509+ BUG_ON(vma->vm_mirror);
97510+
97511 /*
97512 * If anonymous vma has not yet been faulted, update new pgoff
97513 * to match new location, to increase its chance of merging.
97514@@ -2905,6 +3415,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
97515 return NULL;
97516 }
97517
97518+#ifdef CONFIG_PAX_SEGMEXEC
97519+long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
97520+{
97521+ struct vm_area_struct *prev_m;
97522+ struct rb_node **rb_link_m, *rb_parent_m;
97523+ struct mempolicy *pol_m;
97524+
97525+ BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
97526+ BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
97527+ BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
97528+ *vma_m = *vma;
97529+ INIT_LIST_HEAD(&vma_m->anon_vma_chain);
97530+ if (anon_vma_clone(vma_m, vma))
97531+ return -ENOMEM;
97532+ pol_m = vma_policy(vma_m);
97533+ mpol_get(pol_m);
97534+ set_vma_policy(vma_m, pol_m);
97535+ vma_m->vm_start += SEGMEXEC_TASK_SIZE;
97536+ vma_m->vm_end += SEGMEXEC_TASK_SIZE;
97537+ vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
97538+ vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
97539+ if (vma_m->vm_file)
97540+ get_file(vma_m->vm_file);
97541+ if (vma_m->vm_ops && vma_m->vm_ops->open)
97542+ vma_m->vm_ops->open(vma_m);
97543+ BUG_ON(find_vma_links(vma->vm_mm, vma_m->vm_start, vma_m->vm_end, &prev_m, &rb_link_m, &rb_parent_m));
97544+ vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
97545+ vma_m->vm_mirror = vma;
97546+ vma->vm_mirror = vma_m;
97547+ return 0;
97548+}
97549+#endif
97550+
97551 /*
97552 * Return true if the calling process may expand its vm space by the passed
97553 * number of pages
97554@@ -2916,6 +3459,7 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
97555
97556 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
97557
97558+ gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
97559 if (cur + npages > lim)
97560 return 0;
97561 return 1;
97562@@ -2998,6 +3542,22 @@ static struct vm_area_struct *__install_special_mapping(
97563 vma->vm_start = addr;
97564 vma->vm_end = addr + len;
97565
97566+#ifdef CONFIG_PAX_MPROTECT
97567+ if (mm->pax_flags & MF_PAX_MPROTECT) {
97568+#ifndef CONFIG_PAX_MPROTECT_COMPAT
97569+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
97570+ return ERR_PTR(-EPERM);
97571+ if (!(vm_flags & VM_EXEC))
97572+ vm_flags &= ~VM_MAYEXEC;
97573+#else
97574+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
97575+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
97576+#endif
97577+ else
97578+ vm_flags &= ~VM_MAYWRITE;
97579+ }
97580+#endif
97581+
97582 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND | VM_SOFTDIRTY;
97583 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
97584
97585diff --git a/mm/mprotect.c b/mm/mprotect.c
97586index ace9345..63320dc 100644
97587--- a/mm/mprotect.c
97588+++ b/mm/mprotect.c
97589@@ -24,10 +24,18 @@
97590 #include <linux/migrate.h>
97591 #include <linux/perf_event.h>
97592 #include <linux/ksm.h>
97593+#include <linux/sched/sysctl.h>
97594+
97595+#ifdef CONFIG_PAX_MPROTECT
97596+#include <linux/elf.h>
97597+#include <linux/binfmts.h>
97598+#endif
97599+
97600 #include <asm/uaccess.h>
97601 #include <asm/pgtable.h>
97602 #include <asm/cacheflush.h>
97603 #include <asm/tlbflush.h>
97604+#include <asm/mmu_context.h>
97605
97606 /*
97607 * For a prot_numa update we only hold mmap_sem for read so there is a
97608@@ -251,6 +259,48 @@ unsigned long change_protection(struct vm_area_struct *vma, unsigned long start,
97609 return pages;
97610 }
97611
97612+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
97613+/* called while holding the mmap semaphor for writing except stack expansion */
97614+void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
97615+{
97616+ unsigned long oldlimit, newlimit = 0UL;
97617+
97618+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
97619+ return;
97620+
97621+ spin_lock(&mm->page_table_lock);
97622+ oldlimit = mm->context.user_cs_limit;
97623+ if ((prot & VM_EXEC) && oldlimit < end)
97624+ /* USER_CS limit moved up */
97625+ newlimit = end;
97626+ else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
97627+ /* USER_CS limit moved down */
97628+ newlimit = start;
97629+
97630+ if (newlimit) {
97631+ mm->context.user_cs_limit = newlimit;
97632+
97633+#ifdef CONFIG_SMP
97634+ wmb();
97635+ cpus_clear(mm->context.cpu_user_cs_mask);
97636+ cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
97637+#endif
97638+
97639+ set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
97640+ }
97641+ spin_unlock(&mm->page_table_lock);
97642+ if (newlimit == end) {
97643+ struct vm_area_struct *vma = find_vma(mm, oldlimit);
97644+
97645+ for (; vma && vma->vm_start < end; vma = vma->vm_next)
97646+ if (is_vm_hugetlb_page(vma))
97647+ hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
97648+ else
97649+ change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma), 0);
97650+ }
97651+}
97652+#endif
97653+
97654 int
97655 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
97656 unsigned long start, unsigned long end, unsigned long newflags)
97657@@ -263,11 +313,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
97658 int error;
97659 int dirty_accountable = 0;
97660
97661+#ifdef CONFIG_PAX_SEGMEXEC
97662+ struct vm_area_struct *vma_m = NULL;
97663+ unsigned long start_m, end_m;
97664+
97665+ start_m = start + SEGMEXEC_TASK_SIZE;
97666+ end_m = end + SEGMEXEC_TASK_SIZE;
97667+#endif
97668+
97669 if (newflags == oldflags) {
97670 *pprev = vma;
97671 return 0;
97672 }
97673
97674+ if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
97675+ struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
97676+
97677+ if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
97678+ return -ENOMEM;
97679+
97680+ if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
97681+ return -ENOMEM;
97682+ }
97683+
97684 /*
97685 * If we make a private mapping writable we increase our commit;
97686 * but (without finer accounting) cannot reduce our commit if we
97687@@ -284,6 +352,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
97688 }
97689 }
97690
97691+#ifdef CONFIG_PAX_SEGMEXEC
97692+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
97693+ if (start != vma->vm_start) {
97694+ error = split_vma(mm, vma, start, 1);
97695+ if (error)
97696+ goto fail;
97697+ BUG_ON(!*pprev || (*pprev)->vm_next == vma);
97698+ *pprev = (*pprev)->vm_next;
97699+ }
97700+
97701+ if (end != vma->vm_end) {
97702+ error = split_vma(mm, vma, end, 0);
97703+ if (error)
97704+ goto fail;
97705+ }
97706+
97707+ if (pax_find_mirror_vma(vma)) {
97708+ error = __do_munmap(mm, start_m, end_m - start_m);
97709+ if (error)
97710+ goto fail;
97711+ } else {
97712+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
97713+ if (!vma_m) {
97714+ error = -ENOMEM;
97715+ goto fail;
97716+ }
97717+ vma->vm_flags = newflags;
97718+ error = pax_mirror_vma(vma_m, vma);
97719+ if (error) {
97720+ vma->vm_flags = oldflags;
97721+ goto fail;
97722+ }
97723+ }
97724+ }
97725+#endif
97726+
97727 /*
97728 * First try to merge with previous and/or next vma.
97729 */
97730@@ -314,7 +418,19 @@ success:
97731 * vm_flags and vm_page_prot are protected by the mmap_sem
97732 * held in write mode.
97733 */
97734+
97735+#ifdef CONFIG_PAX_SEGMEXEC
97736+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
97737+ pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
97738+#endif
97739+
97740 vma->vm_flags = newflags;
97741+
97742+#ifdef CONFIG_PAX_MPROTECT
97743+ if (mm->binfmt && mm->binfmt->handle_mprotect)
97744+ mm->binfmt->handle_mprotect(vma, newflags);
97745+#endif
97746+
97747 dirty_accountable = vma_wants_writenotify(vma);
97748 vma_set_page_prot(vma);
97749
97750@@ -350,6 +466,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
97751 end = start + len;
97752 if (end <= start)
97753 return -ENOMEM;
97754+
97755+#ifdef CONFIG_PAX_SEGMEXEC
97756+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
97757+ if (end > SEGMEXEC_TASK_SIZE)
97758+ return -EINVAL;
97759+ } else
97760+#endif
97761+
97762+ if (end > TASK_SIZE)
97763+ return -EINVAL;
97764+
97765 if (!arch_validate_prot(prot))
97766 return -EINVAL;
97767
97768@@ -357,7 +484,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
97769 /*
97770 * Does the application expect PROT_READ to imply PROT_EXEC:
97771 */
97772- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
97773+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
97774 prot |= PROT_EXEC;
97775
97776 vm_flags = calc_vm_prot_bits(prot);
97777@@ -389,6 +516,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
97778 if (start > vma->vm_start)
97779 prev = vma;
97780
97781+#ifdef CONFIG_PAX_MPROTECT
97782+ if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
97783+ current->mm->binfmt->handle_mprotect(vma, vm_flags);
97784+#endif
97785+
97786 for (nstart = start ; ; ) {
97787 unsigned long newflags;
97788
97789@@ -399,6 +531,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
97790
97791 /* newflags >> 4 shift VM_MAY% in place of VM_% */
97792 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
97793+ if (prot & (PROT_WRITE | PROT_EXEC))
97794+ gr_log_rwxmprotect(vma);
97795+
97796+ error = -EACCES;
97797+ goto out;
97798+ }
97799+
97800+ if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
97801 error = -EACCES;
97802 goto out;
97803 }
97804@@ -413,6 +553,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
97805 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
97806 if (error)
97807 goto out;
97808+
97809+ track_exec_limit(current->mm, nstart, tmp, vm_flags);
97810+
97811 nstart = tmp;
97812
97813 if (nstart < prev->vm_end)
97814diff --git a/mm/mremap.c b/mm/mremap.c
97815index b147f66..98a695a 100644
97816--- a/mm/mremap.c
97817+++ b/mm/mremap.c
97818@@ -144,6 +144,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
97819 continue;
97820 pte = ptep_get_and_clear(mm, old_addr, old_pte);
97821 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
97822+
97823+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
97824+ if (!(__supported_pte_mask & _PAGE_NX) && pte_present(pte) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
97825+ pte = pte_exprotect(pte);
97826+#endif
97827+
97828 pte = move_soft_dirty_pte(pte);
97829 set_pte_at(mm, new_addr, new_pte, pte);
97830 }
97831@@ -345,6 +351,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
97832 if (is_vm_hugetlb_page(vma))
97833 goto Einval;
97834
97835+#ifdef CONFIG_PAX_SEGMEXEC
97836+ if (pax_find_mirror_vma(vma))
97837+ goto Einval;
97838+#endif
97839+
97840 /* We can't remap across vm area boundaries */
97841 if (old_len > vma->vm_end - addr)
97842 goto Efault;
97843@@ -400,20 +411,25 @@ static unsigned long mremap_to(unsigned long addr, unsigned long old_len,
97844 unsigned long ret = -EINVAL;
97845 unsigned long charged = 0;
97846 unsigned long map_flags;
97847+ unsigned long pax_task_size = TASK_SIZE;
97848
97849 if (new_addr & ~PAGE_MASK)
97850 goto out;
97851
97852- if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
97853+#ifdef CONFIG_PAX_SEGMEXEC
97854+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
97855+ pax_task_size = SEGMEXEC_TASK_SIZE;
97856+#endif
97857+
97858+ pax_task_size -= PAGE_SIZE;
97859+
97860+ if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
97861 goto out;
97862
97863 /* Check if the location we're moving into overlaps the
97864 * old location at all, and fail if it does.
97865 */
97866- if ((new_addr <= addr) && (new_addr+new_len) > addr)
97867- goto out;
97868-
97869- if ((addr <= new_addr) && (addr+old_len) > new_addr)
97870+ if (addr + old_len > new_addr && new_addr + new_len > addr)
97871 goto out;
97872
97873 ret = do_munmap(mm, new_addr, new_len);
97874@@ -482,6 +498,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
97875 unsigned long ret = -EINVAL;
97876 unsigned long charged = 0;
97877 bool locked = false;
97878+ unsigned long pax_task_size = TASK_SIZE;
97879
97880 if (flags & ~(MREMAP_FIXED | MREMAP_MAYMOVE))
97881 return ret;
97882@@ -503,6 +520,17 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
97883 if (!new_len)
97884 return ret;
97885
97886+#ifdef CONFIG_PAX_SEGMEXEC
97887+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
97888+ pax_task_size = SEGMEXEC_TASK_SIZE;
97889+#endif
97890+
97891+ pax_task_size -= PAGE_SIZE;
97892+
97893+ if (new_len > pax_task_size || addr > pax_task_size-new_len ||
97894+ old_len > pax_task_size || addr > pax_task_size-old_len)
97895+ return ret;
97896+
97897 down_write(&current->mm->mmap_sem);
97898
97899 if (flags & MREMAP_FIXED) {
97900@@ -553,6 +581,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
97901 new_addr = addr;
97902 }
97903 ret = addr;
97904+ track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
97905 goto out;
97906 }
97907 }
97908@@ -576,7 +605,12 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
97909 goto out;
97910 }
97911
97912+ map_flags = vma->vm_flags;
97913 ret = move_vma(vma, addr, old_len, new_len, new_addr, &locked);
97914+ if (!(ret & ~PAGE_MASK)) {
97915+ track_exec_limit(current->mm, addr, addr + old_len, 0UL);
97916+ track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
97917+ }
97918 }
97919 out:
97920 if (ret & ~PAGE_MASK)
97921diff --git a/mm/nommu.c b/mm/nommu.c
97922index bd1808e..b63d87c 100644
97923--- a/mm/nommu.c
97924+++ b/mm/nommu.c
97925@@ -70,7 +70,6 @@ int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
97926 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
97927 unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
97928 unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
97929-int heap_stack_gap = 0;
97930
97931 atomic_long_t mmap_pages_allocated;
97932
97933@@ -857,15 +856,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
97934 EXPORT_SYMBOL(find_vma);
97935
97936 /*
97937- * find a VMA
97938- * - we don't extend stack VMAs under NOMMU conditions
97939- */
97940-struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
97941-{
97942- return find_vma(mm, addr);
97943-}
97944-
97945-/*
97946 * expand a stack to a given address
97947 * - not supported under NOMMU conditions
97948 */
97949@@ -1572,6 +1562,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
97950
97951 /* most fields are the same, copy all, and then fixup */
97952 *new = *vma;
97953+ INIT_LIST_HEAD(&new->anon_vma_chain);
97954 *region = *vma->vm_region;
97955 new->vm_region = region;
97956
97957@@ -2002,8 +1993,8 @@ int generic_file_remap_pages(struct vm_area_struct *vma, unsigned long addr,
97958 }
97959 EXPORT_SYMBOL(generic_file_remap_pages);
97960
97961-static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
97962- unsigned long addr, void *buf, int len, int write)
97963+static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
97964+ unsigned long addr, void *buf, size_t len, int write)
97965 {
97966 struct vm_area_struct *vma;
97967
97968@@ -2044,8 +2035,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
97969 *
97970 * The caller must hold a reference on @mm.
97971 */
97972-int access_remote_vm(struct mm_struct *mm, unsigned long addr,
97973- void *buf, int len, int write)
97974+ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
97975+ void *buf, size_t len, int write)
97976 {
97977 return __access_remote_vm(NULL, mm, addr, buf, len, write);
97978 }
97979@@ -2054,7 +2045,7 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
97980 * Access another process' address space.
97981 * - source/target buffer must be kernel space
97982 */
97983-int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write)
97984+ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write)
97985 {
97986 struct mm_struct *mm;
97987
97988diff --git a/mm/page-writeback.c b/mm/page-writeback.c
97989index 437174a..8b86707 100644
97990--- a/mm/page-writeback.c
97991+++ b/mm/page-writeback.c
97992@@ -664,7 +664,7 @@ static long long pos_ratio_polynom(unsigned long setpoint,
97993 * card's bdi_dirty may rush to many times higher than bdi_setpoint.
97994 * - the bdi dirty thresh drops quickly due to change of JBOD workload
97995 */
97996-static unsigned long bdi_position_ratio(struct backing_dev_info *bdi,
97997+static unsigned long __intentional_overflow(-1) bdi_position_ratio(struct backing_dev_info *bdi,
97998 unsigned long thresh,
97999 unsigned long bg_thresh,
98000 unsigned long dirty,
98001diff --git a/mm/page_alloc.c b/mm/page_alloc.c
98002index 616a2c9..0e755f6 100644
98003--- a/mm/page_alloc.c
98004+++ b/mm/page_alloc.c
98005@@ -59,6 +59,7 @@
98006 #include <linux/page-debug-flags.h>
98007 #include <linux/hugetlb.h>
98008 #include <linux/sched/rt.h>
98009+#include <linux/random.h>
98010
98011 #include <asm/sections.h>
98012 #include <asm/tlbflush.h>
98013@@ -356,7 +357,7 @@ out:
98014 * This usage means that zero-order pages may not be compound.
98015 */
98016
98017-static void free_compound_page(struct page *page)
98018+void free_compound_page(struct page *page)
98019 {
98020 __free_pages_ok(page, compound_order(page));
98021 }
98022@@ -741,6 +742,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
98023 int i;
98024 int bad = 0;
98025
98026+#ifdef CONFIG_PAX_MEMORY_SANITIZE
98027+ unsigned long index = 1UL << order;
98028+#endif
98029+
98030 trace_mm_page_free(page, order);
98031 kmemcheck_free_shadow(page, order);
98032
98033@@ -757,6 +762,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
98034 debug_check_no_obj_freed(page_address(page),
98035 PAGE_SIZE << order);
98036 }
98037+
98038+#ifdef CONFIG_PAX_MEMORY_SANITIZE
98039+ for (; index; --index)
98040+ sanitize_highpage(page + index - 1);
98041+#endif
98042+
98043 arch_free_page(page, order);
98044 kernel_map_pages(page, 1 << order, 0);
98045
98046@@ -780,6 +791,20 @@ static void __free_pages_ok(struct page *page, unsigned int order)
98047 local_irq_restore(flags);
98048 }
98049
98050+#ifdef CONFIG_PAX_LATENT_ENTROPY
98051+bool __meminitdata extra_latent_entropy;
98052+
98053+static int __init setup_pax_extra_latent_entropy(char *str)
98054+{
98055+ extra_latent_entropy = true;
98056+ return 0;
98057+}
98058+early_param("pax_extra_latent_entropy", setup_pax_extra_latent_entropy);
98059+
98060+volatile u64 latent_entropy __latent_entropy;
98061+EXPORT_SYMBOL(latent_entropy);
98062+#endif
98063+
98064 void __init __free_pages_bootmem(struct page *page, unsigned int order)
98065 {
98066 unsigned int nr_pages = 1 << order;
98067@@ -795,6 +820,19 @@ void __init __free_pages_bootmem(struct page *page, unsigned int order)
98068 __ClearPageReserved(p);
98069 set_page_count(p, 0);
98070
98071+#ifdef CONFIG_PAX_LATENT_ENTROPY
98072+ if (extra_latent_entropy && !PageHighMem(page) && page_to_pfn(page) < 0x100000) {
98073+ u64 hash = 0;
98074+ size_t index, end = PAGE_SIZE * nr_pages / sizeof hash;
98075+ const u64 *data = lowmem_page_address(page);
98076+
98077+ for (index = 0; index < end; index++)
98078+ hash ^= hash + data[index];
98079+ latent_entropy ^= hash;
98080+ add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
98081+ }
98082+#endif
98083+
98084 page_zone(page)->managed_pages += nr_pages;
98085 set_page_refcounted(page);
98086 __free_pages(page, order);
98087@@ -923,8 +961,10 @@ static int prep_new_page(struct page *page, unsigned int order, gfp_t gfp_flags)
98088 arch_alloc_page(page, order);
98089 kernel_map_pages(page, 1 << order, 1);
98090
98091+#ifndef CONFIG_PAX_MEMORY_SANITIZE
98092 if (gfp_flags & __GFP_ZERO)
98093 prep_zero_page(page, order, gfp_flags);
98094+#endif
98095
98096 if (order && (gfp_flags & __GFP_COMP))
98097 prep_compound_page(page, order);
98098@@ -1602,7 +1642,7 @@ again:
98099 }
98100
98101 __mod_zone_page_state(zone, NR_ALLOC_BATCH, -(1 << order));
98102- if (atomic_long_read(&zone->vm_stat[NR_ALLOC_BATCH]) <= 0 &&
98103+ if (atomic_long_read_unchecked(&zone->vm_stat[NR_ALLOC_BATCH]) <= 0 &&
98104 !test_bit(ZONE_FAIR_DEPLETED, &zone->flags))
98105 set_bit(ZONE_FAIR_DEPLETED, &zone->flags);
98106
98107@@ -1923,7 +1963,7 @@ static void reset_alloc_batches(struct zone *preferred_zone)
98108 do {
98109 mod_zone_page_state(zone, NR_ALLOC_BATCH,
98110 high_wmark_pages(zone) - low_wmark_pages(zone) -
98111- atomic_long_read(&zone->vm_stat[NR_ALLOC_BATCH]));
98112+ atomic_long_read_unchecked(&zone->vm_stat[NR_ALLOC_BATCH]));
98113 clear_bit(ZONE_FAIR_DEPLETED, &zone->flags);
98114 } while (zone++ != preferred_zone);
98115 }
98116@@ -5698,7 +5738,7 @@ static void __setup_per_zone_wmarks(void)
98117
98118 __mod_zone_page_state(zone, NR_ALLOC_BATCH,
98119 high_wmark_pages(zone) - low_wmark_pages(zone) -
98120- atomic_long_read(&zone->vm_stat[NR_ALLOC_BATCH]));
98121+ atomic_long_read_unchecked(&zone->vm_stat[NR_ALLOC_BATCH]));
98122
98123 setup_zone_migrate_reserve(zone);
98124 spin_unlock_irqrestore(&zone->lock, flags);
98125diff --git a/mm/percpu.c b/mm/percpu.c
98126index 014bab6..db5a76f 100644
98127--- a/mm/percpu.c
98128+++ b/mm/percpu.c
98129@@ -131,7 +131,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
98130 static unsigned int pcpu_high_unit_cpu __read_mostly;
98131
98132 /* the address of the first chunk which starts with the kernel static area */
98133-void *pcpu_base_addr __read_mostly;
98134+void *pcpu_base_addr __read_only;
98135 EXPORT_SYMBOL_GPL(pcpu_base_addr);
98136
98137 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
98138diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
98139index 5077afc..846c9ef 100644
98140--- a/mm/process_vm_access.c
98141+++ b/mm/process_vm_access.c
98142@@ -13,6 +13,7 @@
98143 #include <linux/uio.h>
98144 #include <linux/sched.h>
98145 #include <linux/highmem.h>
98146+#include <linux/security.h>
98147 #include <linux/ptrace.h>
98148 #include <linux/slab.h>
98149 #include <linux/syscalls.h>
98150@@ -157,19 +158,19 @@ static ssize_t process_vm_rw_core(pid_t pid, struct iov_iter *iter,
98151 ssize_t iov_len;
98152 size_t total_len = iov_iter_count(iter);
98153
98154+ return -ENOSYS; // PaX: until properly audited
98155+
98156 /*
98157 * Work out how many pages of struct pages we're going to need
98158 * when eventually calling get_user_pages
98159 */
98160 for (i = 0; i < riovcnt; i++) {
98161 iov_len = rvec[i].iov_len;
98162- if (iov_len > 0) {
98163- nr_pages_iov = ((unsigned long)rvec[i].iov_base
98164- + iov_len)
98165- / PAGE_SIZE - (unsigned long)rvec[i].iov_base
98166- / PAGE_SIZE + 1;
98167- nr_pages = max(nr_pages, nr_pages_iov);
98168- }
98169+ if (iov_len <= 0)
98170+ continue;
98171+ nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
98172+ (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
98173+ nr_pages = max(nr_pages, nr_pages_iov);
98174 }
98175
98176 if (nr_pages == 0)
98177@@ -197,6 +198,11 @@ static ssize_t process_vm_rw_core(pid_t pid, struct iov_iter *iter,
98178 goto free_proc_pages;
98179 }
98180
98181+ if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
98182+ rc = -EPERM;
98183+ goto put_task_struct;
98184+ }
98185+
98186 mm = mm_access(task, PTRACE_MODE_ATTACH);
98187 if (!mm || IS_ERR(mm)) {
98188 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
98189diff --git a/mm/rmap.c b/mm/rmap.c
98190index 3e4c721..a5e3e39 100644
98191--- a/mm/rmap.c
98192+++ b/mm/rmap.c
98193@@ -164,6 +164,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
98194 struct anon_vma *anon_vma = vma->anon_vma;
98195 struct anon_vma_chain *avc;
98196
98197+#ifdef CONFIG_PAX_SEGMEXEC
98198+ struct anon_vma_chain *avc_m = NULL;
98199+#endif
98200+
98201 might_sleep();
98202 if (unlikely(!anon_vma)) {
98203 struct mm_struct *mm = vma->vm_mm;
98204@@ -173,6 +177,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
98205 if (!avc)
98206 goto out_enomem;
98207
98208+#ifdef CONFIG_PAX_SEGMEXEC
98209+ avc_m = anon_vma_chain_alloc(GFP_KERNEL);
98210+ if (!avc_m)
98211+ goto out_enomem_free_avc;
98212+#endif
98213+
98214 anon_vma = find_mergeable_anon_vma(vma);
98215 allocated = NULL;
98216 if (!anon_vma) {
98217@@ -186,6 +196,18 @@ int anon_vma_prepare(struct vm_area_struct *vma)
98218 /* page_table_lock to protect against threads */
98219 spin_lock(&mm->page_table_lock);
98220 if (likely(!vma->anon_vma)) {
98221+
98222+#ifdef CONFIG_PAX_SEGMEXEC
98223+ struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
98224+
98225+ if (vma_m) {
98226+ BUG_ON(vma_m->anon_vma);
98227+ vma_m->anon_vma = anon_vma;
98228+ anon_vma_chain_link(vma_m, avc_m, anon_vma);
98229+ avc_m = NULL;
98230+ }
98231+#endif
98232+
98233 vma->anon_vma = anon_vma;
98234 anon_vma_chain_link(vma, avc, anon_vma);
98235 allocated = NULL;
98236@@ -196,12 +218,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
98237
98238 if (unlikely(allocated))
98239 put_anon_vma(allocated);
98240+
98241+#ifdef CONFIG_PAX_SEGMEXEC
98242+ if (unlikely(avc_m))
98243+ anon_vma_chain_free(avc_m);
98244+#endif
98245+
98246 if (unlikely(avc))
98247 anon_vma_chain_free(avc);
98248 }
98249 return 0;
98250
98251 out_enomem_free_avc:
98252+
98253+#ifdef CONFIG_PAX_SEGMEXEC
98254+ if (avc_m)
98255+ anon_vma_chain_free(avc_m);
98256+#endif
98257+
98258 anon_vma_chain_free(avc);
98259 out_enomem:
98260 return -ENOMEM;
98261@@ -237,7 +271,7 @@ static inline void unlock_anon_vma_root(struct anon_vma *root)
98262 * Attach the anon_vmas from src to dst.
98263 * Returns 0 on success, -ENOMEM on failure.
98264 */
98265-int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
98266+int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
98267 {
98268 struct anon_vma_chain *avc, *pavc;
98269 struct anon_vma *root = NULL;
98270@@ -270,7 +304,7 @@ int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
98271 * the corresponding VMA in the parent process is attached to.
98272 * Returns 0 on success, non-zero on failure.
98273 */
98274-int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
98275+int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
98276 {
98277 struct anon_vma_chain *avc;
98278 struct anon_vma *anon_vma;
98279@@ -376,8 +410,10 @@ static void anon_vma_ctor(void *data)
98280 void __init anon_vma_init(void)
98281 {
98282 anon_vma_cachep = kmem_cache_create("anon_vma", sizeof(struct anon_vma),
98283- 0, SLAB_DESTROY_BY_RCU|SLAB_PANIC, anon_vma_ctor);
98284- anon_vma_chain_cachep = KMEM_CACHE(anon_vma_chain, SLAB_PANIC);
98285+ 0, SLAB_DESTROY_BY_RCU|SLAB_PANIC|SLAB_NO_SANITIZE,
98286+ anon_vma_ctor);
98287+ anon_vma_chain_cachep = KMEM_CACHE(anon_vma_chain,
98288+ SLAB_PANIC|SLAB_NO_SANITIZE);
98289 }
98290
98291 /*
98292diff --git a/mm/shmem.c b/mm/shmem.c
98293index 185836b..d7255a1 100644
98294--- a/mm/shmem.c
98295+++ b/mm/shmem.c
98296@@ -33,7 +33,7 @@
98297 #include <linux/swap.h>
98298 #include <linux/aio.h>
98299
98300-static struct vfsmount *shm_mnt;
98301+struct vfsmount *shm_mnt;
98302
98303 #ifdef CONFIG_SHMEM
98304 /*
98305@@ -80,7 +80,7 @@ static struct vfsmount *shm_mnt;
98306 #define BOGO_DIRENT_SIZE 20
98307
98308 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
98309-#define SHORT_SYMLINK_LEN 128
98310+#define SHORT_SYMLINK_LEN 64
98311
98312 /*
98313 * shmem_fallocate communicates with shmem_fault or shmem_writepage via
98314@@ -2558,6 +2558,11 @@ static const struct xattr_handler *shmem_xattr_handlers[] = {
98315 static int shmem_xattr_validate(const char *name)
98316 {
98317 struct { const char *prefix; size_t len; } arr[] = {
98318+
98319+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
98320+ { XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN},
98321+#endif
98322+
98323 { XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN },
98324 { XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN }
98325 };
98326@@ -2613,6 +2618,15 @@ static int shmem_setxattr(struct dentry *dentry, const char *name,
98327 if (err)
98328 return err;
98329
98330+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
98331+ if (!strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN)) {
98332+ if (strcmp(name, XATTR_NAME_PAX_FLAGS))
98333+ return -EOPNOTSUPP;
98334+ if (size > 8)
98335+ return -EINVAL;
98336+ }
98337+#endif
98338+
98339 return simple_xattr_set(&info->xattrs, name, value, size, flags);
98340 }
98341
98342@@ -2996,8 +3010,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
98343 int err = -ENOMEM;
98344
98345 /* Round up to L1_CACHE_BYTES to resist false sharing */
98346- sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
98347- L1_CACHE_BYTES), GFP_KERNEL);
98348+ sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
98349 if (!sbinfo)
98350 return -ENOMEM;
98351
98352diff --git a/mm/slab.c b/mm/slab.c
98353index f34e053..78a3839 100644
98354--- a/mm/slab.c
98355+++ b/mm/slab.c
98356@@ -314,10 +314,12 @@ static void kmem_cache_node_init(struct kmem_cache_node *parent)
98357 if ((x)->max_freeable < i) \
98358 (x)->max_freeable = i; \
98359 } while (0)
98360-#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
98361-#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
98362-#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
98363-#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
98364+#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
98365+#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
98366+#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
98367+#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
98368+#define STATS_INC_SANITIZED(x) atomic_inc_unchecked(&(x)->sanitized)
98369+#define STATS_INC_NOT_SANITIZED(x) atomic_inc_unchecked(&(x)->not_sanitized)
98370 #else
98371 #define STATS_INC_ACTIVE(x) do { } while (0)
98372 #define STATS_DEC_ACTIVE(x) do { } while (0)
98373@@ -334,6 +336,8 @@ static void kmem_cache_node_init(struct kmem_cache_node *parent)
98374 #define STATS_INC_ALLOCMISS(x) do { } while (0)
98375 #define STATS_INC_FREEHIT(x) do { } while (0)
98376 #define STATS_INC_FREEMISS(x) do { } while (0)
98377+#define STATS_INC_SANITIZED(x) do { } while (0)
98378+#define STATS_INC_NOT_SANITIZED(x) do { } while (0)
98379 #endif
98380
98381 #if DEBUG
98382@@ -450,7 +454,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct page *page,
98383 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
98384 */
98385 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
98386- const struct page *page, void *obj)
98387+ const struct page *page, const void *obj)
98388 {
98389 u32 offset = (obj - page->s_mem);
98390 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
98391@@ -1438,7 +1442,7 @@ void __init kmem_cache_init(void)
98392 * structures first. Without this, further allocations will bug.
98393 */
98394 kmalloc_caches[INDEX_NODE] = create_kmalloc_cache("kmalloc-node",
98395- kmalloc_size(INDEX_NODE), ARCH_KMALLOC_FLAGS);
98396+ kmalloc_size(INDEX_NODE), SLAB_USERCOPY | ARCH_KMALLOC_FLAGS);
98397 slab_state = PARTIAL_NODE;
98398
98399 slab_early_init = 0;
98400@@ -2059,7 +2063,7 @@ __kmem_cache_alias(const char *name, size_t size, size_t align,
98401
98402 cachep = find_mergeable(size, align, flags, name, ctor);
98403 if (cachep) {
98404- cachep->refcount++;
98405+ atomic_inc(&cachep->refcount);
98406
98407 /*
98408 * Adjust the object sizes so that we clear
98409@@ -3352,6 +3356,20 @@ static inline void __cache_free(struct kmem_cache *cachep, void *objp,
98410 struct array_cache *ac = cpu_cache_get(cachep);
98411
98412 check_irq_off();
98413+
98414+#ifdef CONFIG_PAX_MEMORY_SANITIZE
98415+ if (cachep->flags & (SLAB_POISON | SLAB_NO_SANITIZE))
98416+ STATS_INC_NOT_SANITIZED(cachep);
98417+ else {
98418+ memset(objp, PAX_MEMORY_SANITIZE_VALUE, cachep->object_size);
98419+
98420+ if (cachep->ctor)
98421+ cachep->ctor(objp);
98422+
98423+ STATS_INC_SANITIZED(cachep);
98424+ }
98425+#endif
98426+
98427 kmemleak_free_recursive(objp, cachep->flags);
98428 objp = cache_free_debugcheck(cachep, objp, caller);
98429
98430@@ -3557,6 +3575,7 @@ void kfree(const void *objp)
98431
98432 if (unlikely(ZERO_OR_NULL_PTR(objp)))
98433 return;
98434+ VM_BUG_ON(!virt_addr_valid(objp));
98435 local_irq_save(flags);
98436 kfree_debugcheck(objp);
98437 c = virt_to_cache(objp);
98438@@ -3979,14 +3998,22 @@ void slabinfo_show_stats(struct seq_file *m, struct kmem_cache *cachep)
98439 }
98440 /* cpu stats */
98441 {
98442- unsigned long allochit = atomic_read(&cachep->allochit);
98443- unsigned long allocmiss = atomic_read(&cachep->allocmiss);
98444- unsigned long freehit = atomic_read(&cachep->freehit);
98445- unsigned long freemiss = atomic_read(&cachep->freemiss);
98446+ unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
98447+ unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
98448+ unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
98449+ unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
98450
98451 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
98452 allochit, allocmiss, freehit, freemiss);
98453 }
98454+#ifdef CONFIG_PAX_MEMORY_SANITIZE
98455+ {
98456+ unsigned long sanitized = atomic_read_unchecked(&cachep->sanitized);
98457+ unsigned long not_sanitized = atomic_read_unchecked(&cachep->not_sanitized);
98458+
98459+ seq_printf(m, " : pax %6lu %6lu", sanitized, not_sanitized);
98460+ }
98461+#endif
98462 #endif
98463 }
98464
98465@@ -4200,13 +4227,69 @@ static const struct file_operations proc_slabstats_operations = {
98466 static int __init slab_proc_init(void)
98467 {
98468 #ifdef CONFIG_DEBUG_SLAB_LEAK
98469- proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
98470+ proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
98471 #endif
98472 return 0;
98473 }
98474 module_init(slab_proc_init);
98475 #endif
98476
98477+bool is_usercopy_object(const void *ptr)
98478+{
98479+ struct page *page;
98480+ struct kmem_cache *cachep;
98481+
98482+ if (ZERO_OR_NULL_PTR(ptr))
98483+ return false;
98484+
98485+ if (!slab_is_available())
98486+ return false;
98487+
98488+ if (!virt_addr_valid(ptr))
98489+ return false;
98490+
98491+ page = virt_to_head_page(ptr);
98492+
98493+ if (!PageSlab(page))
98494+ return false;
98495+
98496+ cachep = page->slab_cache;
98497+ return cachep->flags & SLAB_USERCOPY;
98498+}
98499+
98500+#ifdef CONFIG_PAX_USERCOPY
98501+const char *check_heap_object(const void *ptr, unsigned long n)
98502+{
98503+ struct page *page;
98504+ struct kmem_cache *cachep;
98505+ unsigned int objnr;
98506+ unsigned long offset;
98507+
98508+ if (ZERO_OR_NULL_PTR(ptr))
98509+ return "<null>";
98510+
98511+ if (!virt_addr_valid(ptr))
98512+ return NULL;
98513+
98514+ page = virt_to_head_page(ptr);
98515+
98516+ if (!PageSlab(page))
98517+ return NULL;
98518+
98519+ cachep = page->slab_cache;
98520+ if (!(cachep->flags & SLAB_USERCOPY))
98521+ return cachep->name;
98522+
98523+ objnr = obj_to_index(cachep, page, ptr);
98524+ BUG_ON(objnr >= cachep->num);
98525+ offset = ptr - index_to_obj(cachep, page, objnr) - obj_offset(cachep);
98526+ if (offset <= cachep->object_size && n <= cachep->object_size - offset)
98527+ return NULL;
98528+
98529+ return cachep->name;
98530+}
98531+#endif
98532+
98533 /**
98534 * ksize - get the actual amount of memory allocated for a given object
98535 * @objp: Pointer to the object
98536diff --git a/mm/slab.h b/mm/slab.h
98537index ab019e6..fbcac34 100644
98538--- a/mm/slab.h
98539+++ b/mm/slab.h
98540@@ -22,7 +22,7 @@ struct kmem_cache {
98541 unsigned int align; /* Alignment as calculated */
98542 unsigned long flags; /* Active flags on the slab */
98543 const char *name; /* Slab name for sysfs */
98544- int refcount; /* Use counter */
98545+ atomic_t refcount; /* Use counter */
98546 void (*ctor)(void *); /* Called on object slot creation */
98547 struct list_head list; /* List of all slab caches on the system */
98548 };
98549@@ -66,6 +66,20 @@ extern struct list_head slab_caches;
98550 /* The slab cache that manages slab cache information */
98551 extern struct kmem_cache *kmem_cache;
98552
98553+#ifdef CONFIG_PAX_MEMORY_SANITIZE
98554+#ifdef CONFIG_X86_64
98555+#define PAX_MEMORY_SANITIZE_VALUE '\xfe'
98556+#else
98557+#define PAX_MEMORY_SANITIZE_VALUE '\xff'
98558+#endif
98559+enum pax_sanitize_mode {
98560+ PAX_SANITIZE_SLAB_OFF = 0,
98561+ PAX_SANITIZE_SLAB_FAST,
98562+ PAX_SANITIZE_SLAB_FULL,
98563+};
98564+extern enum pax_sanitize_mode pax_sanitize_slab;
98565+#endif
98566+
98567 unsigned long calculate_alignment(unsigned long flags,
98568 unsigned long align, unsigned long size);
98569
98570@@ -116,7 +130,8 @@ static inline unsigned long kmem_cache_flags(unsigned long object_size,
98571
98572 /* Legal flag mask for kmem_cache_create(), for various configurations */
98573 #define SLAB_CORE_FLAGS (SLAB_HWCACHE_ALIGN | SLAB_CACHE_DMA | SLAB_PANIC | \
98574- SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS )
98575+ SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS | \
98576+ SLAB_USERCOPY | SLAB_NO_SANITIZE)
98577
98578 #if defined(CONFIG_DEBUG_SLAB)
98579 #define SLAB_DEBUG_FLAGS (SLAB_RED_ZONE | SLAB_POISON | SLAB_STORE_USER)
98580@@ -300,6 +315,9 @@ static inline struct kmem_cache *cache_from_obj(struct kmem_cache *s, void *x)
98581 return s;
98582
98583 page = virt_to_head_page(x);
98584+
98585+ BUG_ON(!PageSlab(page));
98586+
98587 cachep = page->slab_cache;
98588 if (slab_equal_or_root(cachep, s))
98589 return cachep;
98590diff --git a/mm/slab_common.c b/mm/slab_common.c
98591index dcdab81..3576646 100644
98592--- a/mm/slab_common.c
98593+++ b/mm/slab_common.c
98594@@ -25,11 +25,35 @@
98595
98596 #include "slab.h"
98597
98598-enum slab_state slab_state;
98599+enum slab_state slab_state __read_only;
98600 LIST_HEAD(slab_caches);
98601 DEFINE_MUTEX(slab_mutex);
98602 struct kmem_cache *kmem_cache;
98603
98604+#ifdef CONFIG_PAX_MEMORY_SANITIZE
98605+enum pax_sanitize_mode pax_sanitize_slab __read_only = PAX_SANITIZE_SLAB_FAST;
98606+static int __init pax_sanitize_slab_setup(char *str)
98607+{
98608+ if (!str)
98609+ return 0;
98610+
98611+ if (!strcmp(str, "0") || !strcmp(str, "off")) {
98612+ pr_info("PaX slab sanitization: %s\n", "disabled");
98613+ pax_sanitize_slab = PAX_SANITIZE_SLAB_OFF;
98614+ } else if (!strcmp(str, "1") || !strcmp(str, "fast")) {
98615+ pr_info("PaX slab sanitization: %s\n", "fast");
98616+ pax_sanitize_slab = PAX_SANITIZE_SLAB_FAST;
98617+ } else if (!strcmp(str, "full")) {
98618+ pr_info("PaX slab sanitization: %s\n", "full");
98619+ pax_sanitize_slab = PAX_SANITIZE_SLAB_FULL;
98620+ } else
98621+ pr_err("PaX slab sanitization: unsupported option '%s'\n", str);
98622+
98623+ return 0;
98624+}
98625+early_param("pax_sanitize_slab", pax_sanitize_slab_setup);
98626+#endif
98627+
98628 /*
98629 * Set of flags that will prevent slab merging
98630 */
98631@@ -44,7 +68,7 @@ struct kmem_cache *kmem_cache;
98632 * Merge control. If this is set then no merging of slab caches will occur.
98633 * (Could be removed. This was introduced to pacify the merge skeptics.)
98634 */
98635-static int slab_nomerge;
98636+static int slab_nomerge = 1;
98637
98638 static int __init setup_slab_nomerge(char *str)
98639 {
98640@@ -218,7 +242,7 @@ int slab_unmergeable(struct kmem_cache *s)
98641 /*
98642 * We may have set a slab to be unmergeable during bootstrap.
98643 */
98644- if (s->refcount < 0)
98645+ if (atomic_read(&s->refcount) < 0)
98646 return 1;
98647
98648 return 0;
98649@@ -322,7 +346,7 @@ do_kmem_cache_create(char *name, size_t object_size, size_t size, size_t align,
98650 if (err)
98651 goto out_free_cache;
98652
98653- s->refcount = 1;
98654+ atomic_set(&s->refcount, 1);
98655 list_add(&s->list, &slab_caches);
98656 out:
98657 if (err)
98658@@ -386,6 +410,13 @@ kmem_cache_create(const char *name, size_t size, size_t align,
98659 */
98660 flags &= CACHE_CREATE_MASK;
98661
98662+#ifdef CONFIG_PAX_MEMORY_SANITIZE
98663+ if (pax_sanitize_slab == PAX_SANITIZE_SLAB_OFF || (flags & SLAB_DESTROY_BY_RCU))
98664+ flags |= SLAB_NO_SANITIZE;
98665+ else if (pax_sanitize_slab == PAX_SANITIZE_SLAB_FULL)
98666+ flags &= ~SLAB_NO_SANITIZE;
98667+#endif
98668+
98669 s = __kmem_cache_alias(name, size, align, flags, ctor);
98670 if (s)
98671 goto out_unlock;
98672@@ -505,8 +536,7 @@ void kmem_cache_destroy(struct kmem_cache *s)
98673
98674 mutex_lock(&slab_mutex);
98675
98676- s->refcount--;
98677- if (s->refcount)
98678+ if (!atomic_dec_and_test(&s->refcount))
98679 goto out_unlock;
98680
98681 if (memcg_cleanup_cache_params(s) != 0)
98682@@ -526,7 +556,7 @@ void kmem_cache_destroy(struct kmem_cache *s)
98683 rcu_barrier();
98684
98685 memcg_free_cache_params(s);
98686-#ifdef SLAB_SUPPORTS_SYSFS
98687+#if defined(SLAB_SUPPORTS_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
98688 sysfs_slab_remove(s);
98689 #else
98690 slab_kmem_cache_release(s);
98691@@ -582,7 +612,7 @@ void __init create_boot_cache(struct kmem_cache *s, const char *name, size_t siz
98692 panic("Creation of kmalloc slab %s size=%zu failed. Reason %d\n",
98693 name, size, err);
98694
98695- s->refcount = -1; /* Exempt from merging for now */
98696+ atomic_set(&s->refcount, -1); /* Exempt from merging for now */
98697 }
98698
98699 struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
98700@@ -595,7 +625,7 @@ struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
98701
98702 create_boot_cache(s, name, size, flags);
98703 list_add(&s->list, &slab_caches);
98704- s->refcount = 1;
98705+ atomic_set(&s->refcount, 1);
98706 return s;
98707 }
98708
98709@@ -607,6 +637,11 @@ struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
98710 EXPORT_SYMBOL(kmalloc_dma_caches);
98711 #endif
98712
98713+#ifdef CONFIG_PAX_USERCOPY_SLABS
98714+struct kmem_cache *kmalloc_usercopy_caches[KMALLOC_SHIFT_HIGH + 1];
98715+EXPORT_SYMBOL(kmalloc_usercopy_caches);
98716+#endif
98717+
98718 /*
98719 * Conversion table for small slabs sizes / 8 to the index in the
98720 * kmalloc array. This is necessary for slabs < 192 since we have non power
98721@@ -671,6 +706,13 @@ struct kmem_cache *kmalloc_slab(size_t size, gfp_t flags)
98722 return kmalloc_dma_caches[index];
98723
98724 #endif
98725+
98726+#ifdef CONFIG_PAX_USERCOPY_SLABS
98727+ if (unlikely((flags & GFP_USERCOPY)))
98728+ return kmalloc_usercopy_caches[index];
98729+
98730+#endif
98731+
98732 return kmalloc_caches[index];
98733 }
98734
98735@@ -727,7 +769,7 @@ void __init create_kmalloc_caches(unsigned long flags)
98736 for (i = KMALLOC_SHIFT_LOW; i <= KMALLOC_SHIFT_HIGH; i++) {
98737 if (!kmalloc_caches[i]) {
98738 kmalloc_caches[i] = create_kmalloc_cache(NULL,
98739- 1 << i, flags);
98740+ 1 << i, SLAB_USERCOPY | flags);
98741 }
98742
98743 /*
98744@@ -736,10 +778,10 @@ void __init create_kmalloc_caches(unsigned long flags)
98745 * earlier power of two caches
98746 */
98747 if (KMALLOC_MIN_SIZE <= 32 && !kmalloc_caches[1] && i == 6)
98748- kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, flags);
98749+ kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, SLAB_USERCOPY | flags);
98750
98751 if (KMALLOC_MIN_SIZE <= 64 && !kmalloc_caches[2] && i == 7)
98752- kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, flags);
98753+ kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, SLAB_USERCOPY | flags);
98754 }
98755
98756 /* Kmalloc array is now usable */
98757@@ -772,6 +814,23 @@ void __init create_kmalloc_caches(unsigned long flags)
98758 }
98759 }
98760 #endif
98761+
98762+#ifdef CONFIG_PAX_USERCOPY_SLABS
98763+ for (i = 0; i <= KMALLOC_SHIFT_HIGH; i++) {
98764+ struct kmem_cache *s = kmalloc_caches[i];
98765+
98766+ if (s) {
98767+ int size = kmalloc_size(i);
98768+ char *n = kasprintf(GFP_NOWAIT,
98769+ "usercopy-kmalloc-%d", size);
98770+
98771+ BUG_ON(!n);
98772+ kmalloc_usercopy_caches[i] = create_kmalloc_cache(n,
98773+ size, SLAB_USERCOPY | flags);
98774+ }
98775+ }
98776+#endif
98777+
98778 }
98779 #endif /* !CONFIG_SLOB */
98780
98781@@ -830,6 +889,9 @@ void print_slabinfo_header(struct seq_file *m)
98782 seq_puts(m, " : globalstat <listallocs> <maxobjs> <grown> <reaped> "
98783 "<error> <maxfreeable> <nodeallocs> <remotefrees> <alienoverflow>");
98784 seq_puts(m, " : cpustat <allochit> <allocmiss> <freehit> <freemiss>");
98785+#ifdef CONFIG_PAX_MEMORY_SANITIZE
98786+ seq_puts(m, " : pax <sanitized> <not_sanitized>");
98787+#endif
98788 #endif
98789 seq_putc(m, '\n');
98790 }
98791diff --git a/mm/slob.c b/mm/slob.c
98792index 96a8620..3e7e663 100644
98793--- a/mm/slob.c
98794+++ b/mm/slob.c
98795@@ -157,7 +157,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
98796 /*
98797 * Return the size of a slob block.
98798 */
98799-static slobidx_t slob_units(slob_t *s)
98800+static slobidx_t slob_units(const slob_t *s)
98801 {
98802 if (s->units > 0)
98803 return s->units;
98804@@ -167,7 +167,7 @@ static slobidx_t slob_units(slob_t *s)
98805 /*
98806 * Return the next free slob block pointer after this one.
98807 */
98808-static slob_t *slob_next(slob_t *s)
98809+static slob_t *slob_next(const slob_t *s)
98810 {
98811 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
98812 slobidx_t next;
98813@@ -182,14 +182,14 @@ static slob_t *slob_next(slob_t *s)
98814 /*
98815 * Returns true if s is the last free block in its page.
98816 */
98817-static int slob_last(slob_t *s)
98818+static int slob_last(const slob_t *s)
98819 {
98820 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
98821 }
98822
98823-static void *slob_new_pages(gfp_t gfp, int order, int node)
98824+static struct page *slob_new_pages(gfp_t gfp, unsigned int order, int node)
98825 {
98826- void *page;
98827+ struct page *page;
98828
98829 #ifdef CONFIG_NUMA
98830 if (node != NUMA_NO_NODE)
98831@@ -201,14 +201,18 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
98832 if (!page)
98833 return NULL;
98834
98835- return page_address(page);
98836+ __SetPageSlab(page);
98837+ return page;
98838 }
98839
98840-static void slob_free_pages(void *b, int order)
98841+static void slob_free_pages(struct page *sp, int order)
98842 {
98843 if (current->reclaim_state)
98844 current->reclaim_state->reclaimed_slab += 1 << order;
98845- free_pages((unsigned long)b, order);
98846+ __ClearPageSlab(sp);
98847+ page_mapcount_reset(sp);
98848+ sp->private = 0;
98849+ __free_pages(sp, order);
98850 }
98851
98852 /*
98853@@ -313,15 +317,15 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
98854
98855 /* Not enough space: must allocate a new page */
98856 if (!b) {
98857- b = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
98858- if (!b)
98859+ sp = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
98860+ if (!sp)
98861 return NULL;
98862- sp = virt_to_page(b);
98863- __SetPageSlab(sp);
98864+ b = page_address(sp);
98865
98866 spin_lock_irqsave(&slob_lock, flags);
98867 sp->units = SLOB_UNITS(PAGE_SIZE);
98868 sp->freelist = b;
98869+ sp->private = 0;
98870 INIT_LIST_HEAD(&sp->lru);
98871 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
98872 set_slob_page_free(sp, slob_list);
98873@@ -337,7 +341,7 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
98874 /*
98875 * slob_free: entry point into the slob allocator.
98876 */
98877-static void slob_free(void *block, int size)
98878+static void slob_free(struct kmem_cache *c, void *block, int size)
98879 {
98880 struct page *sp;
98881 slob_t *prev, *next, *b = (slob_t *)block;
98882@@ -359,12 +363,15 @@ static void slob_free(void *block, int size)
98883 if (slob_page_free(sp))
98884 clear_slob_page_free(sp);
98885 spin_unlock_irqrestore(&slob_lock, flags);
98886- __ClearPageSlab(sp);
98887- page_mapcount_reset(sp);
98888- slob_free_pages(b, 0);
98889+ slob_free_pages(sp, 0);
98890 return;
98891 }
98892
98893+#ifdef CONFIG_PAX_MEMORY_SANITIZE
98894+ if (pax_sanitize_slab && !(c && (c->flags & SLAB_NO_SANITIZE)))
98895+ memset(block, PAX_MEMORY_SANITIZE_VALUE, size);
98896+#endif
98897+
98898 if (!slob_page_free(sp)) {
98899 /* This slob page is about to become partially free. Easy! */
98900 sp->units = units;
98901@@ -424,11 +431,10 @@ out:
98902 */
98903
98904 static __always_inline void *
98905-__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
98906+__do_kmalloc_node_align(size_t size, gfp_t gfp, int node, unsigned long caller, int align)
98907 {
98908- unsigned int *m;
98909- int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
98910- void *ret;
98911+ slob_t *m;
98912+ void *ret = NULL;
98913
98914 gfp &= gfp_allowed_mask;
98915
98916@@ -442,23 +448,41 @@ __do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
98917
98918 if (!m)
98919 return NULL;
98920- *m = size;
98921+ BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
98922+ BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
98923+ m[0].units = size;
98924+ m[1].units = align;
98925 ret = (void *)m + align;
98926
98927 trace_kmalloc_node(caller, ret,
98928 size, size + align, gfp, node);
98929 } else {
98930 unsigned int order = get_order(size);
98931+ struct page *page;
98932
98933 if (likely(order))
98934 gfp |= __GFP_COMP;
98935- ret = slob_new_pages(gfp, order, node);
98936+ page = slob_new_pages(gfp, order, node);
98937+ if (page) {
98938+ ret = page_address(page);
98939+ page->private = size;
98940+ }
98941
98942 trace_kmalloc_node(caller, ret,
98943 size, PAGE_SIZE << order, gfp, node);
98944 }
98945
98946- kmemleak_alloc(ret, size, 1, gfp);
98947+ return ret;
98948+}
98949+
98950+static __always_inline void *
98951+__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
98952+{
98953+ int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
98954+ void *ret = __do_kmalloc_node_align(size, gfp, node, caller, align);
98955+
98956+ if (!ZERO_OR_NULL_PTR(ret))
98957+ kmemleak_alloc(ret, size, 1, gfp);
98958 return ret;
98959 }
98960
98961@@ -491,34 +515,112 @@ void kfree(const void *block)
98962 return;
98963 kmemleak_free(block);
98964
98965+ VM_BUG_ON(!virt_addr_valid(block));
98966 sp = virt_to_page(block);
98967- if (PageSlab(sp)) {
98968+ VM_BUG_ON(!PageSlab(sp));
98969+ if (!sp->private) {
98970 int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
98971- unsigned int *m = (unsigned int *)(block - align);
98972- slob_free(m, *m + align);
98973- } else
98974+ slob_t *m = (slob_t *)(block - align);
98975+ slob_free(NULL, m, m[0].units + align);
98976+ } else {
98977+ __ClearPageSlab(sp);
98978+ page_mapcount_reset(sp);
98979+ sp->private = 0;
98980 __free_pages(sp, compound_order(sp));
98981+ }
98982 }
98983 EXPORT_SYMBOL(kfree);
98984
98985+bool is_usercopy_object(const void *ptr)
98986+{
98987+ if (!slab_is_available())
98988+ return false;
98989+
98990+ // PAX: TODO
98991+
98992+ return false;
98993+}
98994+
98995+#ifdef CONFIG_PAX_USERCOPY
98996+const char *check_heap_object(const void *ptr, unsigned long n)
98997+{
98998+ struct page *page;
98999+ const slob_t *free;
99000+ const void *base;
99001+ unsigned long flags;
99002+
99003+ if (ZERO_OR_NULL_PTR(ptr))
99004+ return "<null>";
99005+
99006+ if (!virt_addr_valid(ptr))
99007+ return NULL;
99008+
99009+ page = virt_to_head_page(ptr);
99010+ if (!PageSlab(page))
99011+ return NULL;
99012+
99013+ if (page->private) {
99014+ base = page;
99015+ if (base <= ptr && n <= page->private - (ptr - base))
99016+ return NULL;
99017+ return "<slob>";
99018+ }
99019+
99020+ /* some tricky double walking to find the chunk */
99021+ spin_lock_irqsave(&slob_lock, flags);
99022+ base = (void *)((unsigned long)ptr & PAGE_MASK);
99023+ free = page->freelist;
99024+
99025+ while (!slob_last(free) && (void *)free <= ptr) {
99026+ base = free + slob_units(free);
99027+ free = slob_next(free);
99028+ }
99029+
99030+ while (base < (void *)free) {
99031+ slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
99032+ int size = SLOB_UNIT * SLOB_UNITS(m + align);
99033+ int offset;
99034+
99035+ if (ptr < base + align)
99036+ break;
99037+
99038+ offset = ptr - base - align;
99039+ if (offset >= m) {
99040+ base += size;
99041+ continue;
99042+ }
99043+
99044+ if (n > m - offset)
99045+ break;
99046+
99047+ spin_unlock_irqrestore(&slob_lock, flags);
99048+ return NULL;
99049+ }
99050+
99051+ spin_unlock_irqrestore(&slob_lock, flags);
99052+ return "<slob>";
99053+}
99054+#endif
99055+
99056 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
99057 size_t ksize(const void *block)
99058 {
99059 struct page *sp;
99060 int align;
99061- unsigned int *m;
99062+ slob_t *m;
99063
99064 BUG_ON(!block);
99065 if (unlikely(block == ZERO_SIZE_PTR))
99066 return 0;
99067
99068 sp = virt_to_page(block);
99069- if (unlikely(!PageSlab(sp)))
99070- return PAGE_SIZE << compound_order(sp);
99071+ VM_BUG_ON(!PageSlab(sp));
99072+ if (sp->private)
99073+ return sp->private;
99074
99075 align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
99076- m = (unsigned int *)(block - align);
99077- return SLOB_UNITS(*m) * SLOB_UNIT;
99078+ m = (slob_t *)(block - align);
99079+ return SLOB_UNITS(m[0].units) * SLOB_UNIT;
99080 }
99081 EXPORT_SYMBOL(ksize);
99082
99083@@ -534,23 +636,33 @@ int __kmem_cache_create(struct kmem_cache *c, unsigned long flags)
99084
99085 void *slob_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
99086 {
99087- void *b;
99088+ void *b = NULL;
99089
99090 flags &= gfp_allowed_mask;
99091
99092 lockdep_trace_alloc(flags);
99093
99094+#ifdef CONFIG_PAX_USERCOPY_SLABS
99095+ b = __do_kmalloc_node_align(c->size, flags, node, _RET_IP_, c->align);
99096+#else
99097 if (c->size < PAGE_SIZE) {
99098 b = slob_alloc(c->size, flags, c->align, node);
99099 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
99100 SLOB_UNITS(c->size) * SLOB_UNIT,
99101 flags, node);
99102 } else {
99103- b = slob_new_pages(flags, get_order(c->size), node);
99104+ struct page *sp;
99105+
99106+ sp = slob_new_pages(flags, get_order(c->size), node);
99107+ if (sp) {
99108+ b = page_address(sp);
99109+ sp->private = c->size;
99110+ }
99111 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
99112 PAGE_SIZE << get_order(c->size),
99113 flags, node);
99114 }
99115+#endif
99116
99117 if (b && c->ctor)
99118 c->ctor(b);
99119@@ -580,12 +692,16 @@ void *kmem_cache_alloc_node(struct kmem_cache *cachep, gfp_t gfp, int node)
99120 EXPORT_SYMBOL(kmem_cache_alloc_node);
99121 #endif
99122
99123-static void __kmem_cache_free(void *b, int size)
99124+static void __kmem_cache_free(struct kmem_cache *c, void *b, int size)
99125 {
99126- if (size < PAGE_SIZE)
99127- slob_free(b, size);
99128+ struct page *sp;
99129+
99130+ sp = virt_to_page(b);
99131+ BUG_ON(!PageSlab(sp));
99132+ if (!sp->private)
99133+ slob_free(c, b, size);
99134 else
99135- slob_free_pages(b, get_order(size));
99136+ slob_free_pages(sp, get_order(size));
99137 }
99138
99139 static void kmem_rcu_free(struct rcu_head *head)
99140@@ -593,22 +709,36 @@ static void kmem_rcu_free(struct rcu_head *head)
99141 struct slob_rcu *slob_rcu = (struct slob_rcu *)head;
99142 void *b = (void *)slob_rcu - (slob_rcu->size - sizeof(struct slob_rcu));
99143
99144- __kmem_cache_free(b, slob_rcu->size);
99145+ __kmem_cache_free(NULL, b, slob_rcu->size);
99146 }
99147
99148 void kmem_cache_free(struct kmem_cache *c, void *b)
99149 {
99150+ int size = c->size;
99151+
99152+#ifdef CONFIG_PAX_USERCOPY_SLABS
99153+ if (size + c->align < PAGE_SIZE) {
99154+ size += c->align;
99155+ b -= c->align;
99156+ }
99157+#endif
99158+
99159 kmemleak_free_recursive(b, c->flags);
99160 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
99161 struct slob_rcu *slob_rcu;
99162- slob_rcu = b + (c->size - sizeof(struct slob_rcu));
99163- slob_rcu->size = c->size;
99164+ slob_rcu = b + (size - sizeof(struct slob_rcu));
99165+ slob_rcu->size = size;
99166 call_rcu(&slob_rcu->head, kmem_rcu_free);
99167 } else {
99168- __kmem_cache_free(b, c->size);
99169+ __kmem_cache_free(c, b, size);
99170 }
99171
99172+#ifdef CONFIG_PAX_USERCOPY_SLABS
99173+ trace_kfree(_RET_IP_, b);
99174+#else
99175 trace_kmem_cache_free(_RET_IP_, b);
99176+#endif
99177+
99178 }
99179 EXPORT_SYMBOL(kmem_cache_free);
99180
99181diff --git a/mm/slub.c b/mm/slub.c
99182index ae7b9f1..7b3fdbe 100644
99183--- a/mm/slub.c
99184+++ b/mm/slub.c
99185@@ -197,7 +197,7 @@ struct track {
99186
99187 enum track_item { TRACK_ALLOC, TRACK_FREE };
99188
99189-#ifdef CONFIG_SYSFS
99190+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
99191 static int sysfs_slab_add(struct kmem_cache *);
99192 static int sysfs_slab_alias(struct kmem_cache *, const char *);
99193 static void memcg_propagate_slab_attrs(struct kmem_cache *s);
99194@@ -535,7 +535,7 @@ static void print_track(const char *s, struct track *t)
99195 if (!t->addr)
99196 return;
99197
99198- pr_err("INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
99199+ pr_err("INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
99200 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
99201 #ifdef CONFIG_STACKTRACE
99202 {
99203@@ -2645,6 +2645,14 @@ static __always_inline void slab_free(struct kmem_cache *s,
99204
99205 slab_free_hook(s, x);
99206
99207+#ifdef CONFIG_PAX_MEMORY_SANITIZE
99208+ if (!(s->flags & SLAB_NO_SANITIZE)) {
99209+ memset(x, PAX_MEMORY_SANITIZE_VALUE, s->object_size);
99210+ if (s->ctor)
99211+ s->ctor(x);
99212+ }
99213+#endif
99214+
99215 redo:
99216 /*
99217 * Determine the currently cpus per cpu slab.
99218@@ -2982,6 +2990,9 @@ static int calculate_sizes(struct kmem_cache *s, int forced_order)
99219 s->inuse = size;
99220
99221 if (((flags & (SLAB_DESTROY_BY_RCU | SLAB_POISON)) ||
99222+#ifdef CONFIG_PAX_MEMORY_SANITIZE
99223+ (!(flags & SLAB_NO_SANITIZE)) ||
99224+#endif
99225 s->ctor)) {
99226 /*
99227 * Relocate free pointer after the object if it is not
99228@@ -3301,6 +3312,59 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
99229 EXPORT_SYMBOL(__kmalloc_node);
99230 #endif
99231
99232+bool is_usercopy_object(const void *ptr)
99233+{
99234+ struct page *page;
99235+ struct kmem_cache *s;
99236+
99237+ if (ZERO_OR_NULL_PTR(ptr))
99238+ return false;
99239+
99240+ if (!slab_is_available())
99241+ return false;
99242+
99243+ if (!virt_addr_valid(ptr))
99244+ return false;
99245+
99246+ page = virt_to_head_page(ptr);
99247+
99248+ if (!PageSlab(page))
99249+ return false;
99250+
99251+ s = page->slab_cache;
99252+ return s->flags & SLAB_USERCOPY;
99253+}
99254+
99255+#ifdef CONFIG_PAX_USERCOPY
99256+const char *check_heap_object(const void *ptr, unsigned long n)
99257+{
99258+ struct page *page;
99259+ struct kmem_cache *s;
99260+ unsigned long offset;
99261+
99262+ if (ZERO_OR_NULL_PTR(ptr))
99263+ return "<null>";
99264+
99265+ if (!virt_addr_valid(ptr))
99266+ return NULL;
99267+
99268+ page = virt_to_head_page(ptr);
99269+
99270+ if (!PageSlab(page))
99271+ return NULL;
99272+
99273+ s = page->slab_cache;
99274+ if (!(s->flags & SLAB_USERCOPY))
99275+ return s->name;
99276+
99277+ offset = (ptr - page_address(page)) % s->size;
99278+ if (offset <= s->object_size && n <= s->object_size - offset)
99279+ return NULL;
99280+
99281+ return s->name;
99282+}
99283+#endif
99284+
99285 size_t ksize(const void *object)
99286 {
99287 struct page *page;
99288@@ -3329,6 +3393,7 @@ void kfree(const void *x)
99289 if (unlikely(ZERO_OR_NULL_PTR(x)))
99290 return;
99291
99292+ VM_BUG_ON(!virt_addr_valid(x));
99293 page = virt_to_head_page(x);
99294 if (unlikely(!PageSlab(page))) {
99295 BUG_ON(!PageCompound(page));
99296@@ -3624,7 +3689,7 @@ __kmem_cache_alias(const char *name, size_t size, size_t align,
99297 int i;
99298 struct kmem_cache *c;
99299
99300- s->refcount++;
99301+ atomic_inc(&s->refcount);
99302
99303 /*
99304 * Adjust the object sizes so that we clear
99305@@ -3643,7 +3708,7 @@ __kmem_cache_alias(const char *name, size_t size, size_t align,
99306 }
99307
99308 if (sysfs_slab_alias(s, name)) {
99309- s->refcount--;
99310+ atomic_dec(&s->refcount);
99311 s = NULL;
99312 }
99313 }
99314@@ -3760,7 +3825,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
99315 }
99316 #endif
99317
99318-#ifdef CONFIG_SYSFS
99319+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
99320 static int count_inuse(struct page *page)
99321 {
99322 return page->inuse;
99323@@ -4041,7 +4106,11 @@ static int list_locations(struct kmem_cache *s, char *buf,
99324 len += sprintf(buf + len, "%7ld ", l->count);
99325
99326 if (l->addr)
99327+#ifdef CONFIG_GRKERNSEC_HIDESYM
99328+ len += sprintf(buf + len, "%pS", NULL);
99329+#else
99330 len += sprintf(buf + len, "%pS", (void *)l->addr);
99331+#endif
99332 else
99333 len += sprintf(buf + len, "<not-available>");
99334
99335@@ -4143,12 +4212,12 @@ static void __init resiliency_test(void)
99336 validate_slab_cache(kmalloc_caches[9]);
99337 }
99338 #else
99339-#ifdef CONFIG_SYSFS
99340+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
99341 static void resiliency_test(void) {};
99342 #endif
99343 #endif
99344
99345-#ifdef CONFIG_SYSFS
99346+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
99347 enum slab_stat_type {
99348 SL_ALL, /* All slabs */
99349 SL_PARTIAL, /* Only partially allocated slabs */
99350@@ -4385,13 +4454,17 @@ static ssize_t ctor_show(struct kmem_cache *s, char *buf)
99351 {
99352 if (!s->ctor)
99353 return 0;
99354+#ifdef CONFIG_GRKERNSEC_HIDESYM
99355+ return sprintf(buf, "%pS\n", NULL);
99356+#else
99357 return sprintf(buf, "%pS\n", s->ctor);
99358+#endif
99359 }
99360 SLAB_ATTR_RO(ctor);
99361
99362 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
99363 {
99364- return sprintf(buf, "%d\n", s->refcount < 0 ? 0 : s->refcount - 1);
99365+ return sprintf(buf, "%d\n", atomic_read(&s->refcount) < 0 ? 0 : atomic_read(&s->refcount) - 1);
99366 }
99367 SLAB_ATTR_RO(aliases);
99368
99369@@ -4479,6 +4552,22 @@ static ssize_t cache_dma_show(struct kmem_cache *s, char *buf)
99370 SLAB_ATTR_RO(cache_dma);
99371 #endif
99372
99373+#ifdef CONFIG_PAX_USERCOPY_SLABS
99374+static ssize_t usercopy_show(struct kmem_cache *s, char *buf)
99375+{
99376+ return sprintf(buf, "%d\n", !!(s->flags & SLAB_USERCOPY));
99377+}
99378+SLAB_ATTR_RO(usercopy);
99379+#endif
99380+
99381+#ifdef CONFIG_PAX_MEMORY_SANITIZE
99382+static ssize_t sanitize_show(struct kmem_cache *s, char *buf)
99383+{
99384+ return sprintf(buf, "%d\n", !(s->flags & SLAB_NO_SANITIZE));
99385+}
99386+SLAB_ATTR_RO(sanitize);
99387+#endif
99388+
99389 static ssize_t destroy_by_rcu_show(struct kmem_cache *s, char *buf)
99390 {
99391 return sprintf(buf, "%d\n", !!(s->flags & SLAB_DESTROY_BY_RCU));
99392@@ -4534,7 +4623,7 @@ static ssize_t trace_store(struct kmem_cache *s, const char *buf,
99393 * as well as cause other issues like converting a mergeable
99394 * cache into an umergeable one.
99395 */
99396- if (s->refcount > 1)
99397+ if (atomic_read(&s->refcount) > 1)
99398 return -EINVAL;
99399
99400 s->flags &= ~SLAB_TRACE;
99401@@ -4654,7 +4743,7 @@ static ssize_t failslab_show(struct kmem_cache *s, char *buf)
99402 static ssize_t failslab_store(struct kmem_cache *s, const char *buf,
99403 size_t length)
99404 {
99405- if (s->refcount > 1)
99406+ if (atomic_read(&s->refcount) > 1)
99407 return -EINVAL;
99408
99409 s->flags &= ~SLAB_FAILSLAB;
99410@@ -4824,6 +4913,12 @@ static struct attribute *slab_attrs[] = {
99411 #ifdef CONFIG_ZONE_DMA
99412 &cache_dma_attr.attr,
99413 #endif
99414+#ifdef CONFIG_PAX_USERCOPY_SLABS
99415+ &usercopy_attr.attr,
99416+#endif
99417+#ifdef CONFIG_PAX_MEMORY_SANITIZE
99418+ &sanitize_attr.attr,
99419+#endif
99420 #ifdef CONFIG_NUMA
99421 &remote_node_defrag_ratio_attr.attr,
99422 #endif
99423@@ -5068,6 +5163,7 @@ static char *create_unique_id(struct kmem_cache *s)
99424 return name;
99425 }
99426
99427+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
99428 static int sysfs_slab_add(struct kmem_cache *s)
99429 {
99430 int err;
99431@@ -5141,6 +5237,7 @@ void sysfs_slab_remove(struct kmem_cache *s)
99432 kobject_del(&s->kobj);
99433 kobject_put(&s->kobj);
99434 }
99435+#endif
99436
99437 /*
99438 * Need to buffer aliases during bootup until sysfs becomes
99439@@ -5154,6 +5251,7 @@ struct saved_alias {
99440
99441 static struct saved_alias *alias_list;
99442
99443+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
99444 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
99445 {
99446 struct saved_alias *al;
99447@@ -5176,6 +5274,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
99448 alias_list = al;
99449 return 0;
99450 }
99451+#endif
99452
99453 static int __init slab_sysfs_init(void)
99454 {
99455diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
99456index 4cba9c2..b4f9fcc 100644
99457--- a/mm/sparse-vmemmap.c
99458+++ b/mm/sparse-vmemmap.c
99459@@ -131,7 +131,7 @@ pud_t * __meminit vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node)
99460 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
99461 if (!p)
99462 return NULL;
99463- pud_populate(&init_mm, pud, p);
99464+ pud_populate_kernel(&init_mm, pud, p);
99465 }
99466 return pud;
99467 }
99468@@ -143,7 +143,7 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
99469 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
99470 if (!p)
99471 return NULL;
99472- pgd_populate(&init_mm, pgd, p);
99473+ pgd_populate_kernel(&init_mm, pgd, p);
99474 }
99475 return pgd;
99476 }
99477diff --git a/mm/sparse.c b/mm/sparse.c
99478index d1b48b6..6e8590e 100644
99479--- a/mm/sparse.c
99480+++ b/mm/sparse.c
99481@@ -750,7 +750,7 @@ static void clear_hwpoisoned_pages(struct page *memmap, int nr_pages)
99482
99483 for (i = 0; i < PAGES_PER_SECTION; i++) {
99484 if (PageHWPoison(&memmap[i])) {
99485- atomic_long_sub(1, &num_poisoned_pages);
99486+ atomic_long_sub_unchecked(1, &num_poisoned_pages);
99487 ClearPageHWPoison(&memmap[i]);
99488 }
99489 }
99490diff --git a/mm/swap.c b/mm/swap.c
99491index 8a12b33..7068e78 100644
99492--- a/mm/swap.c
99493+++ b/mm/swap.c
99494@@ -31,6 +31,7 @@
99495 #include <linux/memcontrol.h>
99496 #include <linux/gfp.h>
99497 #include <linux/uio.h>
99498+#include <linux/hugetlb.h>
99499
99500 #include "internal.h"
99501
99502@@ -77,6 +78,8 @@ static void __put_compound_page(struct page *page)
99503
99504 __page_cache_release(page);
99505 dtor = get_compound_page_dtor(page);
99506+ if (!PageHuge(page))
99507+ BUG_ON(dtor != free_compound_page);
99508 (*dtor)(page);
99509 }
99510
99511diff --git a/mm/swapfile.c b/mm/swapfile.c
99512index 8798b2e..348f9dd 100644
99513--- a/mm/swapfile.c
99514+++ b/mm/swapfile.c
99515@@ -84,7 +84,7 @@ static DEFINE_MUTEX(swapon_mutex);
99516
99517 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
99518 /* Activity counter to indicate that a swapon or swapoff has occurred */
99519-static atomic_t proc_poll_event = ATOMIC_INIT(0);
99520+static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
99521
99522 static inline unsigned char swap_count(unsigned char ent)
99523 {
99524@@ -1944,7 +1944,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
99525 spin_unlock(&swap_lock);
99526
99527 err = 0;
99528- atomic_inc(&proc_poll_event);
99529+ atomic_inc_unchecked(&proc_poll_event);
99530 wake_up_interruptible(&proc_poll_wait);
99531
99532 out_dput:
99533@@ -1961,8 +1961,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
99534
99535 poll_wait(file, &proc_poll_wait, wait);
99536
99537- if (seq->poll_event != atomic_read(&proc_poll_event)) {
99538- seq->poll_event = atomic_read(&proc_poll_event);
99539+ if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
99540+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
99541 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
99542 }
99543
99544@@ -2060,7 +2060,7 @@ static int swaps_open(struct inode *inode, struct file *file)
99545 return ret;
99546
99547 seq = file->private_data;
99548- seq->poll_event = atomic_read(&proc_poll_event);
99549+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
99550 return 0;
99551 }
99552
99553@@ -2520,7 +2520,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
99554 (frontswap_map) ? "FS" : "");
99555
99556 mutex_unlock(&swapon_mutex);
99557- atomic_inc(&proc_poll_event);
99558+ atomic_inc_unchecked(&proc_poll_event);
99559 wake_up_interruptible(&proc_poll_wait);
99560
99561 if (S_ISREG(inode->i_mode))
99562diff --git a/mm/util.c b/mm/util.c
99563index fec39d4..3e60325 100644
99564--- a/mm/util.c
99565+++ b/mm/util.c
99566@@ -195,6 +195,12 @@ struct task_struct *task_of_stack(struct task_struct *task,
99567 void arch_pick_mmap_layout(struct mm_struct *mm)
99568 {
99569 mm->mmap_base = TASK_UNMAPPED_BASE;
99570+
99571+#ifdef CONFIG_PAX_RANDMMAP
99572+ if (mm->pax_flags & MF_PAX_RANDMMAP)
99573+ mm->mmap_base += mm->delta_mmap;
99574+#endif
99575+
99576 mm->get_unmapped_area = arch_get_unmapped_area;
99577 }
99578 #endif
99579@@ -371,6 +377,9 @@ int get_cmdline(struct task_struct *task, char *buffer, int buflen)
99580 if (!mm->arg_end)
99581 goto out_mm; /* Shh! No looking before we're done */
99582
99583+ if (gr_acl_handle_procpidmem(task))
99584+ goto out_mm;
99585+
99586 len = mm->arg_end - mm->arg_start;
99587
99588 if (len > buflen)
99589diff --git a/mm/vmalloc.c b/mm/vmalloc.c
99590index 90520af..24231aa 100644
99591--- a/mm/vmalloc.c
99592+++ b/mm/vmalloc.c
99593@@ -40,6 +40,21 @@ struct vfree_deferred {
99594 };
99595 static DEFINE_PER_CPU(struct vfree_deferred, vfree_deferred);
99596
99597+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
99598+struct stack_deferred_llist {
99599+ struct llist_head list;
99600+ void *stack;
99601+ void *lowmem_stack;
99602+};
99603+
99604+struct stack_deferred {
99605+ struct stack_deferred_llist list;
99606+ struct work_struct wq;
99607+};
99608+
99609+static DEFINE_PER_CPU(struct stack_deferred, stack_deferred);
99610+#endif
99611+
99612 static void __vunmap(const void *, int);
99613
99614 static void free_work(struct work_struct *w)
99615@@ -47,12 +62,30 @@ static void free_work(struct work_struct *w)
99616 struct vfree_deferred *p = container_of(w, struct vfree_deferred, wq);
99617 struct llist_node *llnode = llist_del_all(&p->list);
99618 while (llnode) {
99619- void *p = llnode;
99620+ void *x = llnode;
99621 llnode = llist_next(llnode);
99622- __vunmap(p, 1);
99623+ __vunmap(x, 1);
99624 }
99625 }
99626
99627+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
99628+static void unmap_work(struct work_struct *w)
99629+{
99630+ struct stack_deferred *p = container_of(w, struct stack_deferred, wq);
99631+ struct llist_node *llnode = llist_del_all(&p->list.list);
99632+ while (llnode) {
99633+ struct stack_deferred_llist *x =
99634+ llist_entry((struct llist_head *)llnode,
99635+ struct stack_deferred_llist, list);
99636+ void *stack = ACCESS_ONCE(x->stack);
99637+ void *lowmem_stack = ACCESS_ONCE(x->lowmem_stack);
99638+ llnode = llist_next(llnode);
99639+ __vunmap(stack, 0);
99640+ free_kmem_pages((unsigned long)lowmem_stack, THREAD_SIZE_ORDER);
99641+ }
99642+}
99643+#endif
99644+
99645 /*** Page table manipulation functions ***/
99646
99647 static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
99648@@ -61,8 +94,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
99649
99650 pte = pte_offset_kernel(pmd, addr);
99651 do {
99652- pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
99653- WARN_ON(!pte_none(ptent) && !pte_present(ptent));
99654+
99655+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
99656+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
99657+ BUG_ON(!pte_exec(*pte));
99658+ set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
99659+ continue;
99660+ }
99661+#endif
99662+
99663+ {
99664+ pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
99665+ WARN_ON(!pte_none(ptent) && !pte_present(ptent));
99666+ }
99667 } while (pte++, addr += PAGE_SIZE, addr != end);
99668 }
99669
99670@@ -122,16 +166,29 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
99671 pte = pte_alloc_kernel(pmd, addr);
99672 if (!pte)
99673 return -ENOMEM;
99674+
99675+ pax_open_kernel();
99676 do {
99677 struct page *page = pages[*nr];
99678
99679- if (WARN_ON(!pte_none(*pte)))
99680+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
99681+ if (pgprot_val(prot) & _PAGE_NX)
99682+#endif
99683+
99684+ if (!pte_none(*pte)) {
99685+ pax_close_kernel();
99686+ WARN_ON(1);
99687 return -EBUSY;
99688- if (WARN_ON(!page))
99689+ }
99690+ if (!page) {
99691+ pax_close_kernel();
99692+ WARN_ON(1);
99693 return -ENOMEM;
99694+ }
99695 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
99696 (*nr)++;
99697 } while (pte++, addr += PAGE_SIZE, addr != end);
99698+ pax_close_kernel();
99699 return 0;
99700 }
99701
99702@@ -141,7 +198,7 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
99703 pmd_t *pmd;
99704 unsigned long next;
99705
99706- pmd = pmd_alloc(&init_mm, pud, addr);
99707+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
99708 if (!pmd)
99709 return -ENOMEM;
99710 do {
99711@@ -158,7 +215,7 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
99712 pud_t *pud;
99713 unsigned long next;
99714
99715- pud = pud_alloc(&init_mm, pgd, addr);
99716+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
99717 if (!pud)
99718 return -ENOMEM;
99719 do {
99720@@ -218,6 +275,12 @@ int is_vmalloc_or_module_addr(const void *x)
99721 if (addr >= MODULES_VADDR && addr < MODULES_END)
99722 return 1;
99723 #endif
99724+
99725+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
99726+ if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
99727+ return 1;
99728+#endif
99729+
99730 return is_vmalloc_addr(x);
99731 }
99732
99733@@ -238,8 +301,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
99734
99735 if (!pgd_none(*pgd)) {
99736 pud_t *pud = pud_offset(pgd, addr);
99737+#ifdef CONFIG_X86
99738+ if (!pud_large(*pud))
99739+#endif
99740 if (!pud_none(*pud)) {
99741 pmd_t *pmd = pmd_offset(pud, addr);
99742+#ifdef CONFIG_X86
99743+ if (!pmd_large(*pmd))
99744+#endif
99745 if (!pmd_none(*pmd)) {
99746 pte_t *ptep, pte;
99747
99748@@ -1183,13 +1252,23 @@ void __init vmalloc_init(void)
99749 for_each_possible_cpu(i) {
99750 struct vmap_block_queue *vbq;
99751 struct vfree_deferred *p;
99752+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
99753+ struct stack_deferred *p2;
99754+#endif
99755
99756 vbq = &per_cpu(vmap_block_queue, i);
99757 spin_lock_init(&vbq->lock);
99758 INIT_LIST_HEAD(&vbq->free);
99759+
99760 p = &per_cpu(vfree_deferred, i);
99761 init_llist_head(&p->list);
99762 INIT_WORK(&p->wq, free_work);
99763+
99764+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
99765+ p2 = &per_cpu(stack_deferred, i);
99766+ init_llist_head(&p2->list.list);
99767+ INIT_WORK(&p2->wq, unmap_work);
99768+#endif
99769 }
99770
99771 /* Import existing vmlist entries. */
99772@@ -1314,6 +1393,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
99773 struct vm_struct *area;
99774
99775 BUG_ON(in_interrupt());
99776+
99777+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
99778+ if (flags & VM_KERNEXEC) {
99779+ if (start != VMALLOC_START || end != VMALLOC_END)
99780+ return NULL;
99781+ start = (unsigned long)MODULES_EXEC_VADDR;
99782+ end = (unsigned long)MODULES_EXEC_END;
99783+ }
99784+#endif
99785+
99786 if (flags & VM_IOREMAP)
99787 align = 1ul << clamp(fls(size), PAGE_SHIFT, IOREMAP_MAX_ORDER);
99788
99789@@ -1519,6 +1608,23 @@ void vunmap(const void *addr)
99790 }
99791 EXPORT_SYMBOL(vunmap);
99792
99793+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
99794+void unmap_process_stacks(struct task_struct *task)
99795+{
99796+ if (unlikely(in_interrupt())) {
99797+ struct stack_deferred *p = &__get_cpu_var(stack_deferred);
99798+ struct stack_deferred_llist *list = task->stack;
99799+ list->stack = task->stack;
99800+ list->lowmem_stack = task->lowmem_stack;
99801+ if (llist_add((struct llist_node *)&list->list, &p->list.list))
99802+ schedule_work(&p->wq);
99803+ } else {
99804+ __vunmap(task->stack, 0);
99805+ free_kmem_pages((unsigned long)task->lowmem_stack, THREAD_SIZE_ORDER);
99806+ }
99807+}
99808+#endif
99809+
99810 /**
99811 * vmap - map an array of pages into virtually contiguous space
99812 * @pages: array of page pointers
99813@@ -1539,6 +1645,11 @@ void *vmap(struct page **pages, unsigned int count,
99814 if (count > totalram_pages)
99815 return NULL;
99816
99817+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
99818+ if (!(pgprot_val(prot) & _PAGE_NX))
99819+ flags |= VM_KERNEXEC;
99820+#endif
99821+
99822 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
99823 __builtin_return_address(0));
99824 if (!area)
99825@@ -1641,6 +1752,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
99826 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
99827 goto fail;
99828
99829+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
99830+ if (!(pgprot_val(prot) & _PAGE_NX))
99831+ area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNINITIALIZED | VM_KERNEXEC,
99832+ VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
99833+ else
99834+#endif
99835+
99836 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNINITIALIZED,
99837 start, end, node, gfp_mask, caller);
99838 if (!area)
99839@@ -1817,10 +1935,9 @@ EXPORT_SYMBOL(vzalloc_node);
99840 * For tight control over page level allocator and protection flags
99841 * use __vmalloc() instead.
99842 */
99843-
99844 void *vmalloc_exec(unsigned long size)
99845 {
99846- return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
99847+ return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
99848 NUMA_NO_NODE, __builtin_return_address(0));
99849 }
99850
99851@@ -2127,6 +2244,8 @@ int remap_vmalloc_range_partial(struct vm_area_struct *vma, unsigned long uaddr,
99852 {
99853 struct vm_struct *area;
99854
99855+ BUG_ON(vma->vm_mirror);
99856+
99857 size = PAGE_ALIGN(size);
99858
99859 if (!PAGE_ALIGNED(uaddr) || !PAGE_ALIGNED(kaddr))
99860@@ -2609,7 +2728,11 @@ static int s_show(struct seq_file *m, void *p)
99861 v->addr, v->addr + v->size, v->size);
99862
99863 if (v->caller)
99864+#ifdef CONFIG_GRKERNSEC_HIDESYM
99865+ seq_printf(m, " %pK", v->caller);
99866+#else
99867 seq_printf(m, " %pS", v->caller);
99868+#endif
99869
99870 if (v->nr_pages)
99871 seq_printf(m, " pages=%d", v->nr_pages);
99872diff --git a/mm/vmstat.c b/mm/vmstat.c
99873index 1b12d39..57b29b2 100644
99874--- a/mm/vmstat.c
99875+++ b/mm/vmstat.c
99876@@ -22,6 +22,7 @@
99877 #include <linux/writeback.h>
99878 #include <linux/compaction.h>
99879 #include <linux/mm_inline.h>
99880+#include <linux/grsecurity.h>
99881
99882 #include "internal.h"
99883
99884@@ -81,7 +82,7 @@ void vm_events_fold_cpu(int cpu)
99885 *
99886 * vm_stat contains the global counters
99887 */
99888-atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
99889+atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
99890 EXPORT_SYMBOL(vm_stat);
99891
99892 #ifdef CONFIG_SMP
99893@@ -433,7 +434,7 @@ static int fold_diff(int *diff)
99894
99895 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
99896 if (diff[i]) {
99897- atomic_long_add(diff[i], &vm_stat[i]);
99898+ atomic_long_add_unchecked(diff[i], &vm_stat[i]);
99899 changes++;
99900 }
99901 return changes;
99902@@ -471,7 +472,7 @@ static int refresh_cpu_vm_stats(void)
99903 v = this_cpu_xchg(p->vm_stat_diff[i], 0);
99904 if (v) {
99905
99906- atomic_long_add(v, &zone->vm_stat[i]);
99907+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
99908 global_diff[i] += v;
99909 #ifdef CONFIG_NUMA
99910 /* 3 seconds idle till flush */
99911@@ -535,7 +536,7 @@ void cpu_vm_stats_fold(int cpu)
99912
99913 v = p->vm_stat_diff[i];
99914 p->vm_stat_diff[i] = 0;
99915- atomic_long_add(v, &zone->vm_stat[i]);
99916+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
99917 global_diff[i] += v;
99918 }
99919 }
99920@@ -555,8 +556,8 @@ void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
99921 if (pset->vm_stat_diff[i]) {
99922 int v = pset->vm_stat_diff[i];
99923 pset->vm_stat_diff[i] = 0;
99924- atomic_long_add(v, &zone->vm_stat[i]);
99925- atomic_long_add(v, &vm_stat[i]);
99926+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
99927+ atomic_long_add_unchecked(v, &vm_stat[i]);
99928 }
99929 }
99930 #endif
99931@@ -1189,10 +1190,22 @@ static void *vmstat_start(struct seq_file *m, loff_t *pos)
99932 stat_items_size += sizeof(struct vm_event_state);
99933 #endif
99934
99935- v = kmalloc(stat_items_size, GFP_KERNEL);
99936+ v = kzalloc(stat_items_size, GFP_KERNEL);
99937 m->private = v;
99938 if (!v)
99939 return ERR_PTR(-ENOMEM);
99940+
99941+#ifdef CONFIG_GRKERNSEC_PROC_ADD
99942+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
99943+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)
99944+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
99945+ && !in_group_p(grsec_proc_gid)
99946+#endif
99947+ )
99948+ return (unsigned long *)m->private + *pos;
99949+#endif
99950+#endif
99951+
99952 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
99953 v[i] = global_page_state(i);
99954 v += NR_VM_ZONE_STAT_ITEMS;
99955@@ -1424,10 +1437,16 @@ static int __init setup_vmstat(void)
99956 cpu_notifier_register_done();
99957 #endif
99958 #ifdef CONFIG_PROC_FS
99959- proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
99960- proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
99961- proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
99962- proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
99963+ {
99964+ mode_t gr_mode = S_IRUGO;
99965+#ifdef CONFIG_GRKERNSEC_PROC_ADD
99966+ gr_mode = S_IRUSR;
99967+#endif
99968+ proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
99969+ proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
99970+ proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
99971+ proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
99972+ }
99973 #endif
99974 return 0;
99975 }
99976diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
99977index 64c6bed..b79a5de 100644
99978--- a/net/8021q/vlan.c
99979+++ b/net/8021q/vlan.c
99980@@ -481,7 +481,7 @@ out:
99981 return NOTIFY_DONE;
99982 }
99983
99984-static struct notifier_block vlan_notifier_block __read_mostly = {
99985+static struct notifier_block vlan_notifier_block = {
99986 .notifier_call = vlan_device_event,
99987 };
99988
99989@@ -556,8 +556,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
99990 err = -EPERM;
99991 if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
99992 break;
99993- if ((args.u.name_type >= 0) &&
99994- (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
99995+ if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
99996 struct vlan_net *vn;
99997
99998 vn = net_generic(net, vlan_net_id);
99999diff --git a/net/8021q/vlan_netlink.c b/net/8021q/vlan_netlink.c
100000index 8ac8a5c..991defc 100644
100001--- a/net/8021q/vlan_netlink.c
100002+++ b/net/8021q/vlan_netlink.c
100003@@ -238,7 +238,7 @@ nla_put_failure:
100004 return -EMSGSIZE;
100005 }
100006
100007-struct rtnl_link_ops vlan_link_ops __read_mostly = {
100008+struct rtnl_link_ops vlan_link_ops = {
100009 .kind = "vlan",
100010 .maxtype = IFLA_VLAN_MAX,
100011 .policy = vlan_policy,
100012diff --git a/net/9p/client.c b/net/9p/client.c
100013index e86a9bea..e91f70e 100644
100014--- a/net/9p/client.c
100015+++ b/net/9p/client.c
100016@@ -596,7 +596,7 @@ static int p9_check_zc_errors(struct p9_client *c, struct p9_req_t *req,
100017 len - inline_len);
100018 } else {
100019 err = copy_from_user(ename + inline_len,
100020- uidata, len - inline_len);
100021+ (char __force_user *)uidata, len - inline_len);
100022 if (err) {
100023 err = -EFAULT;
100024 goto out_err;
100025@@ -1570,7 +1570,7 @@ p9_client_read(struct p9_fid *fid, char *data, char __user *udata, u64 offset,
100026 kernel_buf = 1;
100027 indata = data;
100028 } else
100029- indata = (__force char *)udata;
100030+ indata = (__force_kernel char *)udata;
100031 /*
100032 * response header len is 11
100033 * PDU Header(7) + IO Size (4)
100034@@ -1645,7 +1645,7 @@ p9_client_write(struct p9_fid *fid, char *data, const char __user *udata,
100035 kernel_buf = 1;
100036 odata = data;
100037 } else
100038- odata = (char *)udata;
100039+ odata = (char __force_kernel *)udata;
100040 req = p9_client_zc_rpc(clnt, P9_TWRITE, NULL, odata, 0, rsize,
100041 P9_ZC_HDR_SZ, kernel_buf, "dqd",
100042 fid->fid, offset, rsize);
100043diff --git a/net/9p/mod.c b/net/9p/mod.c
100044index 6ab36ae..6f1841b 100644
100045--- a/net/9p/mod.c
100046+++ b/net/9p/mod.c
100047@@ -84,7 +84,7 @@ static LIST_HEAD(v9fs_trans_list);
100048 void v9fs_register_trans(struct p9_trans_module *m)
100049 {
100050 spin_lock(&v9fs_trans_lock);
100051- list_add_tail(&m->list, &v9fs_trans_list);
100052+ pax_list_add_tail((struct list_head *)&m->list, &v9fs_trans_list);
100053 spin_unlock(&v9fs_trans_lock);
100054 }
100055 EXPORT_SYMBOL(v9fs_register_trans);
100056@@ -97,7 +97,7 @@ EXPORT_SYMBOL(v9fs_register_trans);
100057 void v9fs_unregister_trans(struct p9_trans_module *m)
100058 {
100059 spin_lock(&v9fs_trans_lock);
100060- list_del_init(&m->list);
100061+ pax_list_del_init((struct list_head *)&m->list);
100062 spin_unlock(&v9fs_trans_lock);
100063 }
100064 EXPORT_SYMBOL(v9fs_unregister_trans);
100065diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
100066index 80d08f6..de63fd1 100644
100067--- a/net/9p/trans_fd.c
100068+++ b/net/9p/trans_fd.c
100069@@ -428,7 +428,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
100070 oldfs = get_fs();
100071 set_fs(get_ds());
100072 /* The cast to a user pointer is valid due to the set_fs() */
100073- ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
100074+ ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
100075 set_fs(oldfs);
100076
100077 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
100078diff --git a/net/appletalk/atalk_proc.c b/net/appletalk/atalk_proc.c
100079index af46bc4..f9adfcd 100644
100080--- a/net/appletalk/atalk_proc.c
100081+++ b/net/appletalk/atalk_proc.c
100082@@ -256,7 +256,7 @@ int __init atalk_proc_init(void)
100083 struct proc_dir_entry *p;
100084 int rc = -ENOMEM;
100085
100086- atalk_proc_dir = proc_mkdir("atalk", init_net.proc_net);
100087+ atalk_proc_dir = proc_mkdir_restrict("atalk", init_net.proc_net);
100088 if (!atalk_proc_dir)
100089 goto out;
100090
100091diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
100092index 876fbe8..8bbea9f 100644
100093--- a/net/atm/atm_misc.c
100094+++ b/net/atm/atm_misc.c
100095@@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
100096 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
100097 return 1;
100098 atm_return(vcc, truesize);
100099- atomic_inc(&vcc->stats->rx_drop);
100100+ atomic_inc_unchecked(&vcc->stats->rx_drop);
100101 return 0;
100102 }
100103 EXPORT_SYMBOL(atm_charge);
100104@@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
100105 }
100106 }
100107 atm_return(vcc, guess);
100108- atomic_inc(&vcc->stats->rx_drop);
100109+ atomic_inc_unchecked(&vcc->stats->rx_drop);
100110 return NULL;
100111 }
100112 EXPORT_SYMBOL(atm_alloc_charge);
100113@@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
100114
100115 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
100116 {
100117-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
100118+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
100119 __SONET_ITEMS
100120 #undef __HANDLE_ITEM
100121 }
100122@@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
100123
100124 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
100125 {
100126-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
100127+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
100128 __SONET_ITEMS
100129 #undef __HANDLE_ITEM
100130 }
100131diff --git a/net/atm/lec.c b/net/atm/lec.c
100132index 4b98f89..5a2f6cb 100644
100133--- a/net/atm/lec.c
100134+++ b/net/atm/lec.c
100135@@ -111,9 +111,9 @@ static inline void lec_arp_put(struct lec_arp_table *entry)
100136 }
100137
100138 static struct lane2_ops lane2_ops = {
100139- lane2_resolve, /* resolve, spec 3.1.3 */
100140- lane2_associate_req, /* associate_req, spec 3.1.4 */
100141- NULL /* associate indicator, spec 3.1.5 */
100142+ .resolve = lane2_resolve,
100143+ .associate_req = lane2_associate_req,
100144+ .associate_indicator = NULL
100145 };
100146
100147 static unsigned char bus_mac[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
100148diff --git a/net/atm/lec.h b/net/atm/lec.h
100149index 4149db1..f2ab682 100644
100150--- a/net/atm/lec.h
100151+++ b/net/atm/lec.h
100152@@ -48,7 +48,7 @@ struct lane2_ops {
100153 const u8 *tlvs, u32 sizeoftlvs);
100154 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
100155 const u8 *tlvs, u32 sizeoftlvs);
100156-};
100157+} __no_const;
100158
100159 /*
100160 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
100161diff --git a/net/atm/mpoa_caches.c b/net/atm/mpoa_caches.c
100162index d1b2d9a..d549f7f 100644
100163--- a/net/atm/mpoa_caches.c
100164+++ b/net/atm/mpoa_caches.c
100165@@ -535,30 +535,30 @@ static void eg_destroy_cache(struct mpoa_client *mpc)
100166
100167
100168 static struct in_cache_ops ingress_ops = {
100169- in_cache_add_entry, /* add_entry */
100170- in_cache_get, /* get */
100171- in_cache_get_with_mask, /* get_with_mask */
100172- in_cache_get_by_vcc, /* get_by_vcc */
100173- in_cache_put, /* put */
100174- in_cache_remove_entry, /* remove_entry */
100175- cache_hit, /* cache_hit */
100176- clear_count_and_expired, /* clear_count */
100177- check_resolving_entries, /* check_resolving */
100178- refresh_entries, /* refresh */
100179- in_destroy_cache /* destroy_cache */
100180+ .add_entry = in_cache_add_entry,
100181+ .get = in_cache_get,
100182+ .get_with_mask = in_cache_get_with_mask,
100183+ .get_by_vcc = in_cache_get_by_vcc,
100184+ .put = in_cache_put,
100185+ .remove_entry = in_cache_remove_entry,
100186+ .cache_hit = cache_hit,
100187+ .clear_count = clear_count_and_expired,
100188+ .check_resolving = check_resolving_entries,
100189+ .refresh = refresh_entries,
100190+ .destroy_cache = in_destroy_cache
100191 };
100192
100193 static struct eg_cache_ops egress_ops = {
100194- eg_cache_add_entry, /* add_entry */
100195- eg_cache_get_by_cache_id, /* get_by_cache_id */
100196- eg_cache_get_by_tag, /* get_by_tag */
100197- eg_cache_get_by_vcc, /* get_by_vcc */
100198- eg_cache_get_by_src_ip, /* get_by_src_ip */
100199- eg_cache_put, /* put */
100200- eg_cache_remove_entry, /* remove_entry */
100201- update_eg_cache_entry, /* update */
100202- clear_expired, /* clear_expired */
100203- eg_destroy_cache /* destroy_cache */
100204+ .add_entry = eg_cache_add_entry,
100205+ .get_by_cache_id = eg_cache_get_by_cache_id,
100206+ .get_by_tag = eg_cache_get_by_tag,
100207+ .get_by_vcc = eg_cache_get_by_vcc,
100208+ .get_by_src_ip = eg_cache_get_by_src_ip,
100209+ .put = eg_cache_put,
100210+ .remove_entry = eg_cache_remove_entry,
100211+ .update = update_eg_cache_entry,
100212+ .clear_expired = clear_expired,
100213+ .destroy_cache = eg_destroy_cache
100214 };
100215
100216
100217diff --git a/net/atm/proc.c b/net/atm/proc.c
100218index bbb6461..cf04016 100644
100219--- a/net/atm/proc.c
100220+++ b/net/atm/proc.c
100221@@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
100222 const struct k_atm_aal_stats *stats)
100223 {
100224 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
100225- atomic_read(&stats->tx), atomic_read(&stats->tx_err),
100226- atomic_read(&stats->rx), atomic_read(&stats->rx_err),
100227- atomic_read(&stats->rx_drop));
100228+ atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
100229+ atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
100230+ atomic_read_unchecked(&stats->rx_drop));
100231 }
100232
100233 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
100234diff --git a/net/atm/resources.c b/net/atm/resources.c
100235index 0447d5d..3cf4728 100644
100236--- a/net/atm/resources.c
100237+++ b/net/atm/resources.c
100238@@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
100239 static void copy_aal_stats(struct k_atm_aal_stats *from,
100240 struct atm_aal_stats *to)
100241 {
100242-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
100243+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
100244 __AAL_STAT_ITEMS
100245 #undef __HANDLE_ITEM
100246 }
100247@@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
100248 static void subtract_aal_stats(struct k_atm_aal_stats *from,
100249 struct atm_aal_stats *to)
100250 {
100251-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
100252+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
100253 __AAL_STAT_ITEMS
100254 #undef __HANDLE_ITEM
100255 }
100256diff --git a/net/ax25/sysctl_net_ax25.c b/net/ax25/sysctl_net_ax25.c
100257index 919a5ce..cc6b444 100644
100258--- a/net/ax25/sysctl_net_ax25.c
100259+++ b/net/ax25/sysctl_net_ax25.c
100260@@ -152,7 +152,7 @@ int ax25_register_dev_sysctl(ax25_dev *ax25_dev)
100261 {
100262 char path[sizeof("net/ax25/") + IFNAMSIZ];
100263 int k;
100264- struct ctl_table *table;
100265+ ctl_table_no_const *table;
100266
100267 table = kmemdup(ax25_param_table, sizeof(ax25_param_table), GFP_KERNEL);
100268 if (!table)
100269diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
100270index 1e80539..676c37a 100644
100271--- a/net/batman-adv/bat_iv_ogm.c
100272+++ b/net/batman-adv/bat_iv_ogm.c
100273@@ -313,7 +313,7 @@ static int batadv_iv_ogm_iface_enable(struct batadv_hard_iface *hard_iface)
100274
100275 /* randomize initial seqno to avoid collision */
100276 get_random_bytes(&random_seqno, sizeof(random_seqno));
100277- atomic_set(&hard_iface->bat_iv.ogm_seqno, random_seqno);
100278+ atomic_set_unchecked(&hard_iface->bat_iv.ogm_seqno, random_seqno);
100279
100280 hard_iface->bat_iv.ogm_buff_len = BATADV_OGM_HLEN;
100281 ogm_buff = kmalloc(hard_iface->bat_iv.ogm_buff_len, GFP_ATOMIC);
100282@@ -918,9 +918,9 @@ static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
100283 batadv_ogm_packet->tvlv_len = htons(tvlv_len);
100284
100285 /* change sequence number to network order */
100286- seqno = (uint32_t)atomic_read(&hard_iface->bat_iv.ogm_seqno);
100287+ seqno = (uint32_t)atomic_read_unchecked(&hard_iface->bat_iv.ogm_seqno);
100288 batadv_ogm_packet->seqno = htonl(seqno);
100289- atomic_inc(&hard_iface->bat_iv.ogm_seqno);
100290+ atomic_inc_unchecked(&hard_iface->bat_iv.ogm_seqno);
100291
100292 batadv_iv_ogm_slide_own_bcast_window(hard_iface);
100293
100294@@ -1597,7 +1597,7 @@ static void batadv_iv_ogm_process(const struct sk_buff *skb, int ogm_offset,
100295 return;
100296
100297 /* could be changed by schedule_own_packet() */
100298- if_incoming_seqno = atomic_read(&if_incoming->bat_iv.ogm_seqno);
100299+ if_incoming_seqno = atomic_read_unchecked(&if_incoming->bat_iv.ogm_seqno);
100300
100301 if (ogm_packet->flags & BATADV_DIRECTLINK)
100302 has_directlink_flag = true;
100303diff --git a/net/batman-adv/fragmentation.c b/net/batman-adv/fragmentation.c
100304index fc1835c..42f2c2f 100644
100305--- a/net/batman-adv/fragmentation.c
100306+++ b/net/batman-adv/fragmentation.c
100307@@ -251,7 +251,7 @@ batadv_frag_merge_packets(struct hlist_head *chain, struct sk_buff *skb)
100308 kfree(entry);
100309
100310 /* Make room for the rest of the fragments. */
100311- if (pskb_expand_head(skb_out, 0, size - skb->len, GFP_ATOMIC) < 0) {
100312+ if (pskb_expand_head(skb_out, 0, size - skb_out->len, GFP_ATOMIC) < 0) {
100313 kfree_skb(skb_out);
100314 skb_out = NULL;
100315 goto free;
100316@@ -450,7 +450,7 @@ bool batadv_frag_send_packet(struct sk_buff *skb,
100317 frag_header.packet_type = BATADV_UNICAST_FRAG;
100318 frag_header.version = BATADV_COMPAT_VERSION;
100319 frag_header.ttl = BATADV_TTL;
100320- frag_header.seqno = htons(atomic_inc_return(&bat_priv->frag_seqno));
100321+ frag_header.seqno = htons(atomic_inc_return_unchecked(&bat_priv->frag_seqno));
100322 frag_header.reserved = 0;
100323 frag_header.no = 0;
100324 frag_header.total_size = htons(skb->len);
100325diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
100326index 5467955..75ad4e3 100644
100327--- a/net/batman-adv/soft-interface.c
100328+++ b/net/batman-adv/soft-interface.c
100329@@ -296,7 +296,7 @@ send:
100330 primary_if->net_dev->dev_addr);
100331
100332 /* set broadcast sequence number */
100333- seqno = atomic_inc_return(&bat_priv->bcast_seqno);
100334+ seqno = atomic_inc_return_unchecked(&bat_priv->bcast_seqno);
100335 bcast_packet->seqno = htonl(seqno);
100336
100337 batadv_add_bcast_packet_to_list(bat_priv, skb, brd_delay);
100338@@ -761,7 +761,7 @@ static int batadv_softif_init_late(struct net_device *dev)
100339 atomic_set(&bat_priv->batman_queue_left, BATADV_BATMAN_QUEUE_LEN);
100340
100341 atomic_set(&bat_priv->mesh_state, BATADV_MESH_INACTIVE);
100342- atomic_set(&bat_priv->bcast_seqno, 1);
100343+ atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
100344 atomic_set(&bat_priv->tt.vn, 0);
100345 atomic_set(&bat_priv->tt.local_changes, 0);
100346 atomic_set(&bat_priv->tt.ogm_append_cnt, 0);
100347@@ -775,7 +775,7 @@ static int batadv_softif_init_late(struct net_device *dev)
100348
100349 /* randomize initial seqno to avoid collision */
100350 get_random_bytes(&random_seqno, sizeof(random_seqno));
100351- atomic_set(&bat_priv->frag_seqno, random_seqno);
100352+ atomic_set_unchecked(&bat_priv->frag_seqno, random_seqno);
100353
100354 bat_priv->primary_if = NULL;
100355 bat_priv->num_ifaces = 0;
100356@@ -983,7 +983,7 @@ int batadv_softif_is_valid(const struct net_device *net_dev)
100357 return 0;
100358 }
100359
100360-struct rtnl_link_ops batadv_link_ops __read_mostly = {
100361+struct rtnl_link_ops batadv_link_ops = {
100362 .kind = "batadv",
100363 .priv_size = sizeof(struct batadv_priv),
100364 .setup = batadv_softif_init_early,
100365diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
100366index 8854c05..ee5d5497 100644
100367--- a/net/batman-adv/types.h
100368+++ b/net/batman-adv/types.h
100369@@ -67,7 +67,7 @@ enum batadv_dhcp_recipient {
100370 struct batadv_hard_iface_bat_iv {
100371 unsigned char *ogm_buff;
100372 int ogm_buff_len;
100373- atomic_t ogm_seqno;
100374+ atomic_unchecked_t ogm_seqno;
100375 };
100376
100377 /**
100378@@ -768,7 +768,7 @@ struct batadv_priv {
100379 atomic_t bonding;
100380 atomic_t fragmentation;
100381 atomic_t packet_size_max;
100382- atomic_t frag_seqno;
100383+ atomic_unchecked_t frag_seqno;
100384 #ifdef CONFIG_BATMAN_ADV_BLA
100385 atomic_t bridge_loop_avoidance;
100386 #endif
100387@@ -787,7 +787,7 @@ struct batadv_priv {
100388 #endif
100389 uint32_t isolation_mark;
100390 uint32_t isolation_mark_mask;
100391- atomic_t bcast_seqno;
100392+ atomic_unchecked_t bcast_seqno;
100393 atomic_t bcast_queue_left;
100394 atomic_t batman_queue_left;
100395 char num_ifaces;
100396diff --git a/net/bluetooth/6lowpan.c b/net/bluetooth/6lowpan.c
100397index cfbb39e..0bbfc9d 100644
100398--- a/net/bluetooth/6lowpan.c
100399+++ b/net/bluetooth/6lowpan.c
100400@@ -367,7 +367,6 @@ static int recv_pkt(struct sk_buff *skb, struct net_device *dev,
100401
100402 drop:
100403 dev->stats.rx_dropped++;
100404- kfree_skb(skb);
100405 return NET_RX_DROP;
100406 }
100407
100408diff --git a/net/bluetooth/bnep/core.c b/net/bluetooth/bnep/core.c
100409index 85bcc21..ce82722d 100644
100410--- a/net/bluetooth/bnep/core.c
100411+++ b/net/bluetooth/bnep/core.c
100412@@ -533,6 +533,9 @@ int bnep_add_connection(struct bnep_connadd_req *req, struct socket *sock)
100413
100414 BT_DBG("");
100415
100416+ if (!l2cap_is_socket(sock))
100417+ return -EBADFD;
100418+
100419 baswap((void *) dst, &l2cap_pi(sock->sk)->chan->dst);
100420 baswap((void *) src, &l2cap_pi(sock->sk)->chan->src);
100421
100422diff --git a/net/bluetooth/cmtp/core.c b/net/bluetooth/cmtp/core.c
100423index 67fe5e8..278a194 100644
100424--- a/net/bluetooth/cmtp/core.c
100425+++ b/net/bluetooth/cmtp/core.c
100426@@ -334,6 +334,9 @@ int cmtp_add_connection(struct cmtp_connadd_req *req, struct socket *sock)
100427
100428 BT_DBG("");
100429
100430+ if (!l2cap_is_socket(sock))
100431+ return -EBADFD;
100432+
100433 session = kzalloc(sizeof(struct cmtp_session), GFP_KERNEL);
100434 if (!session)
100435 return -ENOMEM;
100436diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
100437index 115f149..f0ba286 100644
100438--- a/net/bluetooth/hci_sock.c
100439+++ b/net/bluetooth/hci_sock.c
100440@@ -1067,7 +1067,7 @@ static int hci_sock_setsockopt(struct socket *sock, int level, int optname,
100441 uf.event_mask[1] = *((u32 *) f->event_mask + 1);
100442 }
100443
100444- len = min_t(unsigned int, len, sizeof(uf));
100445+ len = min((size_t)len, sizeof(uf));
100446 if (copy_from_user(&uf, optval, len)) {
100447 err = -EFAULT;
100448 break;
100449diff --git a/net/bluetooth/hidp/core.c b/net/bluetooth/hidp/core.c
100450index 1b7d605..02ebd10 100644
100451--- a/net/bluetooth/hidp/core.c
100452+++ b/net/bluetooth/hidp/core.c
100453@@ -1318,13 +1318,14 @@ int hidp_connection_add(struct hidp_connadd_req *req,
100454 {
100455 struct hidp_session *session;
100456 struct l2cap_conn *conn;
100457- struct l2cap_chan *chan = l2cap_pi(ctrl_sock->sk)->chan;
100458+ struct l2cap_chan *chan;
100459 int ret;
100460
100461 ret = hidp_verify_sockets(ctrl_sock, intr_sock);
100462 if (ret)
100463 return ret;
100464
100465+ chan = l2cap_pi(ctrl_sock->sk)->chan;
100466 conn = NULL;
100467 l2cap_chan_lock(chan);
100468 if (chan->conn)
100469diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
100470index b6f9777..36d3039 100644
100471--- a/net/bluetooth/l2cap_core.c
100472+++ b/net/bluetooth/l2cap_core.c
100473@@ -3512,8 +3512,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len,
100474 break;
100475
100476 case L2CAP_CONF_RFC:
100477- if (olen == sizeof(rfc))
100478- memcpy(&rfc, (void *)val, olen);
100479+ if (olen != sizeof(rfc))
100480+ break;
100481+
100482+ memcpy(&rfc, (void *)val, olen);
100483
100484 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
100485 rfc.mode != chan->mode)
100486diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
100487index 31f106e..323f606 100644
100488--- a/net/bluetooth/l2cap_sock.c
100489+++ b/net/bluetooth/l2cap_sock.c
100490@@ -628,7 +628,8 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
100491 struct sock *sk = sock->sk;
100492 struct l2cap_chan *chan = l2cap_pi(sk)->chan;
100493 struct l2cap_options opts;
100494- int len, err = 0;
100495+ int err = 0;
100496+ size_t len = optlen;
100497 u32 opt;
100498
100499 BT_DBG("sk %p", sk);
100500@@ -655,7 +656,7 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
100501 opts.max_tx = chan->max_tx;
100502 opts.txwin_size = chan->tx_win;
100503
100504- len = min_t(unsigned int, sizeof(opts), optlen);
100505+ len = min(sizeof(opts), len);
100506 if (copy_from_user((char *) &opts, optval, len)) {
100507 err = -EFAULT;
100508 break;
100509@@ -742,7 +743,8 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
100510 struct bt_security sec;
100511 struct bt_power pwr;
100512 struct l2cap_conn *conn;
100513- int len, err = 0;
100514+ int err = 0;
100515+ size_t len = optlen;
100516 u32 opt;
100517
100518 BT_DBG("sk %p", sk);
100519@@ -766,7 +768,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
100520
100521 sec.level = BT_SECURITY_LOW;
100522
100523- len = min_t(unsigned int, sizeof(sec), optlen);
100524+ len = min(sizeof(sec), len);
100525 if (copy_from_user((char *) &sec, optval, len)) {
100526 err = -EFAULT;
100527 break;
100528@@ -862,7 +864,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
100529
100530 pwr.force_active = BT_POWER_FORCE_ACTIVE_ON;
100531
100532- len = min_t(unsigned int, sizeof(pwr), optlen);
100533+ len = min(sizeof(pwr), len);
100534 if (copy_from_user((char *) &pwr, optval, len)) {
100535 err = -EFAULT;
100536 break;
100537diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
100538index 8bbbb5e..6fc0950 100644
100539--- a/net/bluetooth/rfcomm/sock.c
100540+++ b/net/bluetooth/rfcomm/sock.c
100541@@ -687,7 +687,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
100542 struct sock *sk = sock->sk;
100543 struct bt_security sec;
100544 int err = 0;
100545- size_t len;
100546+ size_t len = optlen;
100547 u32 opt;
100548
100549 BT_DBG("sk %p", sk);
100550@@ -709,7 +709,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
100551
100552 sec.level = BT_SECURITY_LOW;
100553
100554- len = min_t(unsigned int, sizeof(sec), optlen);
100555+ len = min(sizeof(sec), len);
100556 if (copy_from_user((char *) &sec, optval, len)) {
100557 err = -EFAULT;
100558 break;
100559diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
100560index 8e385a0..a5bdd8e 100644
100561--- a/net/bluetooth/rfcomm/tty.c
100562+++ b/net/bluetooth/rfcomm/tty.c
100563@@ -752,7 +752,7 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
100564 BT_DBG("tty %p id %d", tty, tty->index);
100565
100566 BT_DBG("dev %p dst %pMR channel %d opened %d", dev, &dev->dst,
100567- dev->channel, dev->port.count);
100568+ dev->channel, atomic_read(&dev->port.count));
100569
100570 err = tty_port_open(&dev->port, tty, filp);
100571 if (err)
100572@@ -775,7 +775,7 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
100573 struct rfcomm_dev *dev = (struct rfcomm_dev *) tty->driver_data;
100574
100575 BT_DBG("tty %p dev %p dlc %p opened %d", tty, dev, dev->dlc,
100576- dev->port.count);
100577+ atomic_read(&dev->port.count));
100578
100579 tty_port_close(&dev->port, tty, filp);
100580 }
100581diff --git a/net/bridge/br_netlink.c b/net/bridge/br_netlink.c
100582index e5ec470..cbfabd1 100644
100583--- a/net/bridge/br_netlink.c
100584+++ b/net/bridge/br_netlink.c
100585@@ -564,7 +564,7 @@ static struct rtnl_af_ops br_af_ops = {
100586 .get_link_af_size = br_get_link_af_size,
100587 };
100588
100589-struct rtnl_link_ops br_link_ops __read_mostly = {
100590+struct rtnl_link_ops br_link_ops = {
100591 .kind = "bridge",
100592 .priv_size = sizeof(struct net_bridge),
100593 .setup = br_dev_setup,
100594diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
100595index d9a8c05..8dadc6c6 100644
100596--- a/net/bridge/netfilter/ebtables.c
100597+++ b/net/bridge/netfilter/ebtables.c
100598@@ -1533,7 +1533,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
100599 tmp.valid_hooks = t->table->valid_hooks;
100600 }
100601 mutex_unlock(&ebt_mutex);
100602- if (copy_to_user(user, &tmp, *len) != 0) {
100603+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
100604 BUGPRINT("c2u Didn't work\n");
100605 ret = -EFAULT;
100606 break;
100607@@ -2339,7 +2339,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
100608 goto out;
100609 tmp.valid_hooks = t->valid_hooks;
100610
100611- if (copy_to_user(user, &tmp, *len) != 0) {
100612+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
100613 ret = -EFAULT;
100614 break;
100615 }
100616@@ -2350,7 +2350,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
100617 tmp.entries_size = t->table->entries_size;
100618 tmp.valid_hooks = t->table->valid_hooks;
100619
100620- if (copy_to_user(user, &tmp, *len) != 0) {
100621+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
100622 ret = -EFAULT;
100623 break;
100624 }
100625diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
100626index f5afda1..dcf770a 100644
100627--- a/net/caif/cfctrl.c
100628+++ b/net/caif/cfctrl.c
100629@@ -10,6 +10,7 @@
100630 #include <linux/spinlock.h>
100631 #include <linux/slab.h>
100632 #include <linux/pkt_sched.h>
100633+#include <linux/sched.h>
100634 #include <net/caif/caif_layer.h>
100635 #include <net/caif/cfpkt.h>
100636 #include <net/caif/cfctrl.h>
100637@@ -43,8 +44,8 @@ struct cflayer *cfctrl_create(void)
100638 memset(&dev_info, 0, sizeof(dev_info));
100639 dev_info.id = 0xff;
100640 cfsrvl_init(&this->serv, 0, &dev_info, false);
100641- atomic_set(&this->req_seq_no, 1);
100642- atomic_set(&this->rsp_seq_no, 1);
100643+ atomic_set_unchecked(&this->req_seq_no, 1);
100644+ atomic_set_unchecked(&this->rsp_seq_no, 1);
100645 this->serv.layer.receive = cfctrl_recv;
100646 sprintf(this->serv.layer.name, "ctrl");
100647 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
100648@@ -130,8 +131,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
100649 struct cfctrl_request_info *req)
100650 {
100651 spin_lock_bh(&ctrl->info_list_lock);
100652- atomic_inc(&ctrl->req_seq_no);
100653- req->sequence_no = atomic_read(&ctrl->req_seq_no);
100654+ atomic_inc_unchecked(&ctrl->req_seq_no);
100655+ req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
100656 list_add_tail(&req->list, &ctrl->list);
100657 spin_unlock_bh(&ctrl->info_list_lock);
100658 }
100659@@ -149,7 +150,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
100660 if (p != first)
100661 pr_warn("Requests are not received in order\n");
100662
100663- atomic_set(&ctrl->rsp_seq_no,
100664+ atomic_set_unchecked(&ctrl->rsp_seq_no,
100665 p->sequence_no);
100666 list_del(&p->list);
100667 goto out;
100668diff --git a/net/caif/chnl_net.c b/net/caif/chnl_net.c
100669index 4589ff67..46d6b8f 100644
100670--- a/net/caif/chnl_net.c
100671+++ b/net/caif/chnl_net.c
100672@@ -516,7 +516,7 @@ static const struct nla_policy ipcaif_policy[IFLA_CAIF_MAX + 1] = {
100673 };
100674
100675
100676-static struct rtnl_link_ops ipcaif_link_ops __read_mostly = {
100677+static struct rtnl_link_ops ipcaif_link_ops = {
100678 .kind = "caif",
100679 .priv_size = sizeof(struct chnl_net),
100680 .setup = ipcaif_net_setup,
100681diff --git a/net/can/af_can.c b/net/can/af_can.c
100682index ce82337..5d17b4d 100644
100683--- a/net/can/af_can.c
100684+++ b/net/can/af_can.c
100685@@ -884,7 +884,7 @@ static const struct net_proto_family can_family_ops = {
100686 };
100687
100688 /* notifier block for netdevice event */
100689-static struct notifier_block can_netdev_notifier __read_mostly = {
100690+static struct notifier_block can_netdev_notifier = {
100691 .notifier_call = can_notifier,
100692 };
100693
100694diff --git a/net/can/bcm.c b/net/can/bcm.c
100695index dcb75c0..24b1b43 100644
100696--- a/net/can/bcm.c
100697+++ b/net/can/bcm.c
100698@@ -1624,7 +1624,7 @@ static int __init bcm_module_init(void)
100699 }
100700
100701 /* create /proc/net/can-bcm directory */
100702- proc_dir = proc_mkdir("can-bcm", init_net.proc_net);
100703+ proc_dir = proc_mkdir_restrict("can-bcm", init_net.proc_net);
100704 return 0;
100705 }
100706
100707diff --git a/net/can/gw.c b/net/can/gw.c
100708index 050a211..bb9fe33 100644
100709--- a/net/can/gw.c
100710+++ b/net/can/gw.c
100711@@ -80,7 +80,6 @@ MODULE_PARM_DESC(max_hops,
100712 "default: " __stringify(CGW_DEFAULT_HOPS) ")");
100713
100714 static HLIST_HEAD(cgw_list);
100715-static struct notifier_block notifier;
100716
100717 static struct kmem_cache *cgw_cache __read_mostly;
100718
100719@@ -947,6 +946,10 @@ static int cgw_remove_job(struct sk_buff *skb, struct nlmsghdr *nlh)
100720 return err;
100721 }
100722
100723+static struct notifier_block notifier = {
100724+ .notifier_call = cgw_notifier
100725+};
100726+
100727 static __init int cgw_module_init(void)
100728 {
100729 /* sanitize given module parameter */
100730@@ -962,7 +965,6 @@ static __init int cgw_module_init(void)
100731 return -ENOMEM;
100732
100733 /* set notifier */
100734- notifier.notifier_call = cgw_notifier;
100735 register_netdevice_notifier(&notifier);
100736
100737 if (__rtnl_register(PF_CAN, RTM_GETROUTE, NULL, cgw_dump_jobs, NULL)) {
100738diff --git a/net/can/proc.c b/net/can/proc.c
100739index 1a19b98..df2b4ec 100644
100740--- a/net/can/proc.c
100741+++ b/net/can/proc.c
100742@@ -514,7 +514,7 @@ static void can_remove_proc_readentry(const char *name)
100743 void can_init_proc(void)
100744 {
100745 /* create /proc/net/can directory */
100746- can_dir = proc_mkdir("can", init_net.proc_net);
100747+ can_dir = proc_mkdir_restrict("can", init_net.proc_net);
100748
100749 if (!can_dir) {
100750 printk(KERN_INFO "can: failed to create /proc/net/can . "
100751diff --git a/net/ceph/messenger.c b/net/ceph/messenger.c
100752index 8d1653c..77ad145 100644
100753--- a/net/ceph/messenger.c
100754+++ b/net/ceph/messenger.c
100755@@ -188,7 +188,7 @@ static void con_fault(struct ceph_connection *con);
100756 #define MAX_ADDR_STR_LEN 64 /* 54 is enough */
100757
100758 static char addr_str[ADDR_STR_COUNT][MAX_ADDR_STR_LEN];
100759-static atomic_t addr_str_seq = ATOMIC_INIT(0);
100760+static atomic_unchecked_t addr_str_seq = ATOMIC_INIT(0);
100761
100762 static struct page *zero_page; /* used in certain error cases */
100763
100764@@ -199,7 +199,7 @@ const char *ceph_pr_addr(const struct sockaddr_storage *ss)
100765 struct sockaddr_in *in4 = (struct sockaddr_in *) ss;
100766 struct sockaddr_in6 *in6 = (struct sockaddr_in6 *) ss;
100767
100768- i = atomic_inc_return(&addr_str_seq) & ADDR_STR_COUNT_MASK;
100769+ i = atomic_inc_return_unchecked(&addr_str_seq) & ADDR_STR_COUNT_MASK;
100770 s = addr_str[i];
100771
100772 switch (ss->ss_family) {
100773diff --git a/net/compat.c b/net/compat.c
100774index bc8aeef..f9c070c 100644
100775--- a/net/compat.c
100776+++ b/net/compat.c
100777@@ -73,9 +73,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
100778 return -EFAULT;
100779 if (kmsg->msg_namelen > sizeof(struct sockaddr_storage))
100780 kmsg->msg_namelen = sizeof(struct sockaddr_storage);
100781- kmsg->msg_name = compat_ptr(tmp1);
100782- kmsg->msg_iov = compat_ptr(tmp2);
100783- kmsg->msg_control = compat_ptr(tmp3);
100784+ kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
100785+ kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
100786+ kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
100787 return 0;
100788 }
100789
100790@@ -87,7 +87,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
100791
100792 if (kern_msg->msg_name && kern_msg->msg_namelen) {
100793 if (mode == VERIFY_READ) {
100794- int err = move_addr_to_kernel(kern_msg->msg_name,
100795+ int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
100796 kern_msg->msg_namelen,
100797 kern_address);
100798 if (err < 0)
100799@@ -100,7 +100,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
100800 }
100801
100802 tot_len = iov_from_user_compat_to_kern(kern_iov,
100803- (struct compat_iovec __user *)kern_msg->msg_iov,
100804+ (struct compat_iovec __force_user *)kern_msg->msg_iov,
100805 kern_msg->msg_iovlen);
100806 if (tot_len >= 0)
100807 kern_msg->msg_iov = kern_iov;
100808@@ -120,20 +120,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
100809
100810 #define CMSG_COMPAT_FIRSTHDR(msg) \
100811 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
100812- (struct compat_cmsghdr __user *)((msg)->msg_control) : \
100813+ (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
100814 (struct compat_cmsghdr __user *)NULL)
100815
100816 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
100817 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
100818 (ucmlen) <= (unsigned long) \
100819 ((mhdr)->msg_controllen - \
100820- ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
100821+ ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
100822
100823 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
100824 struct compat_cmsghdr __user *cmsg, int cmsg_len)
100825 {
100826 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
100827- if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
100828+ if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
100829 msg->msg_controllen)
100830 return NULL;
100831 return (struct compat_cmsghdr __user *)ptr;
100832@@ -223,7 +223,7 @@ Efault:
100833
100834 int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
100835 {
100836- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
100837+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
100838 struct compat_cmsghdr cmhdr;
100839 struct compat_timeval ctv;
100840 struct compat_timespec cts[3];
100841@@ -279,7 +279,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
100842
100843 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
100844 {
100845- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
100846+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
100847 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
100848 int fdnum = scm->fp->count;
100849 struct file **fp = scm->fp->fp;
100850@@ -367,7 +367,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
100851 return -EFAULT;
100852 old_fs = get_fs();
100853 set_fs(KERNEL_DS);
100854- err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
100855+ err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
100856 set_fs(old_fs);
100857
100858 return err;
100859@@ -428,7 +428,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
100860 len = sizeof(ktime);
100861 old_fs = get_fs();
100862 set_fs(KERNEL_DS);
100863- err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
100864+ err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
100865 set_fs(old_fs);
100866
100867 if (!err) {
100868@@ -571,7 +571,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
100869 case MCAST_JOIN_GROUP:
100870 case MCAST_LEAVE_GROUP:
100871 {
100872- struct compat_group_req __user *gr32 = (void *)optval;
100873+ struct compat_group_req __user *gr32 = (void __user *)optval;
100874 struct group_req __user *kgr =
100875 compat_alloc_user_space(sizeof(struct group_req));
100876 u32 interface;
100877@@ -592,7 +592,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
100878 case MCAST_BLOCK_SOURCE:
100879 case MCAST_UNBLOCK_SOURCE:
100880 {
100881- struct compat_group_source_req __user *gsr32 = (void *)optval;
100882+ struct compat_group_source_req __user *gsr32 = (void __user *)optval;
100883 struct group_source_req __user *kgsr = compat_alloc_user_space(
100884 sizeof(struct group_source_req));
100885 u32 interface;
100886@@ -613,7 +613,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
100887 }
100888 case MCAST_MSFILTER:
100889 {
100890- struct compat_group_filter __user *gf32 = (void *)optval;
100891+ struct compat_group_filter __user *gf32 = (void __user *)optval;
100892 struct group_filter __user *kgf;
100893 u32 interface, fmode, numsrc;
100894
100895@@ -651,7 +651,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
100896 char __user *optval, int __user *optlen,
100897 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
100898 {
100899- struct compat_group_filter __user *gf32 = (void *)optval;
100900+ struct compat_group_filter __user *gf32 = (void __user *)optval;
100901 struct group_filter __user *kgf;
100902 int __user *koptlen;
100903 u32 interface, fmode, numsrc;
100904@@ -804,7 +804,7 @@ COMPAT_SYSCALL_DEFINE2(socketcall, int, call, u32 __user *, args)
100905
100906 if (call < SYS_SOCKET || call > SYS_SENDMMSG)
100907 return -EINVAL;
100908- if (copy_from_user(a, args, nas[call]))
100909+ if (nas[call] > sizeof a || copy_from_user(a, args, nas[call]))
100910 return -EFAULT;
100911 a0 = a[0];
100912 a1 = a[1];
100913diff --git a/net/core/datagram.c b/net/core/datagram.c
100914index fdbc9a8..cd6972c 100644
100915--- a/net/core/datagram.c
100916+++ b/net/core/datagram.c
100917@@ -301,7 +301,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
100918 }
100919
100920 kfree_skb(skb);
100921- atomic_inc(&sk->sk_drops);
100922+ atomic_inc_unchecked(&sk->sk_drops);
100923 sk_mem_reclaim_partial(sk);
100924
100925 return err;
100926diff --git a/net/core/dev.c b/net/core/dev.c
100927index 945bbd0..8b1a370 100644
100928--- a/net/core/dev.c
100929+++ b/net/core/dev.c
100930@@ -1683,14 +1683,14 @@ int __dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
100931 {
100932 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
100933 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
100934- atomic_long_inc(&dev->rx_dropped);
100935+ atomic_long_inc_unchecked(&dev->rx_dropped);
100936 kfree_skb(skb);
100937 return NET_RX_DROP;
100938 }
100939 }
100940
100941 if (unlikely(!is_skb_forwardable(dev, skb))) {
100942- atomic_long_inc(&dev->rx_dropped);
100943+ atomic_long_inc_unchecked(&dev->rx_dropped);
100944 kfree_skb(skb);
100945 return NET_RX_DROP;
100946 }
100947@@ -2985,7 +2985,7 @@ recursion_alert:
100948 drop:
100949 rcu_read_unlock_bh();
100950
100951- atomic_long_inc(&dev->tx_dropped);
100952+ atomic_long_inc_unchecked(&dev->tx_dropped);
100953 kfree_skb_list(skb);
100954 return rc;
100955 out:
100956@@ -3328,7 +3328,7 @@ enqueue:
100957
100958 local_irq_restore(flags);
100959
100960- atomic_long_inc(&skb->dev->rx_dropped);
100961+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
100962 kfree_skb(skb);
100963 return NET_RX_DROP;
100964 }
100965@@ -3405,7 +3405,7 @@ int netif_rx_ni(struct sk_buff *skb)
100966 }
100967 EXPORT_SYMBOL(netif_rx_ni);
100968
100969-static void net_tx_action(struct softirq_action *h)
100970+static __latent_entropy void net_tx_action(void)
100971 {
100972 struct softnet_data *sd = this_cpu_ptr(&softnet_data);
100973
100974@@ -3738,7 +3738,7 @@ ncls:
100975 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
100976 } else {
100977 drop:
100978- atomic_long_inc(&skb->dev->rx_dropped);
100979+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
100980 kfree_skb(skb);
100981 /* Jamal, now you will not able to escape explaining
100982 * me how you were going to use this. :-)
100983@@ -4502,7 +4502,7 @@ void netif_napi_del(struct napi_struct *napi)
100984 }
100985 EXPORT_SYMBOL(netif_napi_del);
100986
100987-static void net_rx_action(struct softirq_action *h)
100988+static __latent_entropy void net_rx_action(void)
100989 {
100990 struct softnet_data *sd = this_cpu_ptr(&softnet_data);
100991 unsigned long time_limit = jiffies + 2;
100992@@ -6548,8 +6548,8 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
100993 } else {
100994 netdev_stats_to_stats64(storage, &dev->stats);
100995 }
100996- storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
100997- storage->tx_dropped += atomic_long_read(&dev->tx_dropped);
100998+ storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
100999+ storage->tx_dropped += atomic_long_read_unchecked(&dev->tx_dropped);
101000 return storage;
101001 }
101002 EXPORT_SYMBOL(dev_get_stats);
101003diff --git a/net/core/dev_ioctl.c b/net/core/dev_ioctl.c
101004index 72e899a..79a9409 100644
101005--- a/net/core/dev_ioctl.c
101006+++ b/net/core/dev_ioctl.c
101007@@ -365,8 +365,13 @@ void dev_load(struct net *net, const char *name)
101008 no_module = !dev;
101009 if (no_module && capable(CAP_NET_ADMIN))
101010 no_module = request_module("netdev-%s", name);
101011- if (no_module && capable(CAP_SYS_MODULE))
101012+ if (no_module && capable(CAP_SYS_MODULE)) {
101013+#ifdef CONFIG_GRKERNSEC_MODHARDEN
101014+ ___request_module(true, "grsec_modharden_netdev", "%s", name);
101015+#else
101016 request_module("%s", name);
101017+#endif
101018+ }
101019 }
101020 EXPORT_SYMBOL(dev_load);
101021
101022diff --git a/net/core/filter.c b/net/core/filter.c
101023index 647b122..18a7ff6 100644
101024--- a/net/core/filter.c
101025+++ b/net/core/filter.c
101026@@ -532,7 +532,11 @@ do_pass:
101027
101028 /* Unkown instruction. */
101029 default:
101030- goto err;
101031+ WARN(1, KERN_ALERT "Unknown sock filter code:%u jt:%u tf:%u k:%u\n",
101032+ fp->code, fp->jt, fp->jf, fp->k);
101033+ kfree(addrs);
101034+ BUG();
101035+ return -EINVAL;
101036 }
101037
101038 insn++;
101039@@ -576,7 +580,7 @@ static int check_load_and_stores(const struct sock_filter *filter, int flen)
101040 u16 *masks, memvalid = 0; /* One bit per cell, 16 cells */
101041 int pc, ret = 0;
101042
101043- BUILD_BUG_ON(BPF_MEMWORDS > 16);
101044+ BUILD_BUG_ON(BPF_MEMWORDS != 16);
101045
101046 masks = kmalloc_array(flen, sizeof(*masks), GFP_KERNEL);
101047 if (!masks)
101048@@ -987,7 +991,7 @@ int bpf_prog_create(struct bpf_prog **pfp, struct sock_fprog_kern *fprog)
101049 if (!fp)
101050 return -ENOMEM;
101051
101052- memcpy(fp->insns, fprog->filter, fsize);
101053+ memcpy(fp->insns, (void __force_kernel *)fprog->filter, fsize);
101054
101055 fp->len = fprog->len;
101056 /* Since unattached filters are not copied back to user
101057diff --git a/net/core/flow.c b/net/core/flow.c
101058index a0348fd..6951c76 100644
101059--- a/net/core/flow.c
101060+++ b/net/core/flow.c
101061@@ -65,7 +65,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
101062 static int flow_entry_valid(struct flow_cache_entry *fle,
101063 struct netns_xfrm *xfrm)
101064 {
101065- if (atomic_read(&xfrm->flow_cache_genid) != fle->genid)
101066+ if (atomic_read_unchecked(&xfrm->flow_cache_genid) != fle->genid)
101067 return 0;
101068 if (fle->object && !fle->object->ops->check(fle->object))
101069 return 0;
101070@@ -242,7 +242,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
101071 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
101072 fcp->hash_count++;
101073 }
101074- } else if (likely(fle->genid == atomic_read(&net->xfrm.flow_cache_genid))) {
101075+ } else if (likely(fle->genid == atomic_read_unchecked(&net->xfrm.flow_cache_genid))) {
101076 flo = fle->object;
101077 if (!flo)
101078 goto ret_object;
101079@@ -263,7 +263,7 @@ nocache:
101080 }
101081 flo = resolver(net, key, family, dir, flo, ctx);
101082 if (fle) {
101083- fle->genid = atomic_read(&net->xfrm.flow_cache_genid);
101084+ fle->genid = atomic_read_unchecked(&net->xfrm.flow_cache_genid);
101085 if (!IS_ERR(flo))
101086 fle->object = flo;
101087 else
101088diff --git a/net/core/iovec.c b/net/core/iovec.c
101089index e1ec45a..e5c6f16 100644
101090--- a/net/core/iovec.c
101091+++ b/net/core/iovec.c
101092@@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
101093 if (m->msg_name && m->msg_namelen) {
101094 if (mode == VERIFY_READ) {
101095 void __user *namep;
101096- namep = (void __user __force *) m->msg_name;
101097+ namep = (void __force_user *) m->msg_name;
101098 err = move_addr_to_kernel(namep, m->msg_namelen,
101099 address);
101100 if (err < 0)
101101@@ -55,7 +55,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
101102 }
101103
101104 size = m->msg_iovlen * sizeof(struct iovec);
101105- if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
101106+ if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
101107 return -EFAULT;
101108
101109 m->msg_iov = iov;
101110diff --git a/net/core/neighbour.c b/net/core/neighbour.c
101111index ef31fef..8be66d9 100644
101112--- a/net/core/neighbour.c
101113+++ b/net/core/neighbour.c
101114@@ -2825,7 +2825,7 @@ static int proc_unres_qlen(struct ctl_table *ctl, int write,
101115 void __user *buffer, size_t *lenp, loff_t *ppos)
101116 {
101117 int size, ret;
101118- struct ctl_table tmp = *ctl;
101119+ ctl_table_no_const tmp = *ctl;
101120
101121 tmp.extra1 = &zero;
101122 tmp.extra2 = &unres_qlen_max;
101123@@ -2887,7 +2887,7 @@ static int neigh_proc_dointvec_zero_intmax(struct ctl_table *ctl, int write,
101124 void __user *buffer,
101125 size_t *lenp, loff_t *ppos)
101126 {
101127- struct ctl_table tmp = *ctl;
101128+ ctl_table_no_const tmp = *ctl;
101129 int ret;
101130
101131 tmp.extra1 = &zero;
101132diff --git a/net/core/net-procfs.c b/net/core/net-procfs.c
101133index 2bf8329..2eb1423 100644
101134--- a/net/core/net-procfs.c
101135+++ b/net/core/net-procfs.c
101136@@ -79,7 +79,13 @@ static void dev_seq_printf_stats(struct seq_file *seq, struct net_device *dev)
101137 struct rtnl_link_stats64 temp;
101138 const struct rtnl_link_stats64 *stats = dev_get_stats(dev, &temp);
101139
101140- seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
101141+ if (gr_proc_is_restricted())
101142+ seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
101143+ "%8llu %7llu %4llu %4llu %4llu %5llu %7llu %10llu\n",
101144+ dev->name, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL,
101145+ 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL);
101146+ else
101147+ seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
101148 "%8llu %7llu %4llu %4llu %4llu %5llu %7llu %10llu\n",
101149 dev->name, stats->rx_bytes, stats->rx_packets,
101150 stats->rx_errors,
101151@@ -166,7 +172,7 @@ static int softnet_seq_show(struct seq_file *seq, void *v)
101152 return 0;
101153 }
101154
101155-static const struct seq_operations dev_seq_ops = {
101156+const struct seq_operations dev_seq_ops = {
101157 .start = dev_seq_start,
101158 .next = dev_seq_next,
101159 .stop = dev_seq_stop,
101160@@ -196,7 +202,7 @@ static const struct seq_operations softnet_seq_ops = {
101161
101162 static int softnet_seq_open(struct inode *inode, struct file *file)
101163 {
101164- return seq_open(file, &softnet_seq_ops);
101165+ return seq_open_restrict(file, &softnet_seq_ops);
101166 }
101167
101168 static const struct file_operations softnet_seq_fops = {
101169@@ -283,8 +289,13 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
101170 else
101171 seq_printf(seq, "%04x", ntohs(pt->type));
101172
101173+#ifdef CONFIG_GRKERNSEC_HIDESYM
101174+ seq_printf(seq, " %-8s %pf\n",
101175+ pt->dev ? pt->dev->name : "", NULL);
101176+#else
101177 seq_printf(seq, " %-8s %pf\n",
101178 pt->dev ? pt->dev->name : "", pt->func);
101179+#endif
101180 }
101181
101182 return 0;
101183diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
101184index 9dd0669..c52fb1b 100644
101185--- a/net/core/net-sysfs.c
101186+++ b/net/core/net-sysfs.c
101187@@ -278,7 +278,7 @@ static ssize_t carrier_changes_show(struct device *dev,
101188 {
101189 struct net_device *netdev = to_net_dev(dev);
101190 return sprintf(buf, fmt_dec,
101191- atomic_read(&netdev->carrier_changes));
101192+ atomic_read_unchecked(&netdev->carrier_changes));
101193 }
101194 static DEVICE_ATTR_RO(carrier_changes);
101195
101196diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
101197index 7f15517..f7d65c0 100644
101198--- a/net/core/net_namespace.c
101199+++ b/net/core/net_namespace.c
101200@@ -445,7 +445,7 @@ static int __register_pernet_operations(struct list_head *list,
101201 int error;
101202 LIST_HEAD(net_exit_list);
101203
101204- list_add_tail(&ops->list, list);
101205+ pax_list_add_tail((struct list_head *)&ops->list, list);
101206 if (ops->init || (ops->id && ops->size)) {
101207 for_each_net(net) {
101208 error = ops_init(ops, net);
101209@@ -458,7 +458,7 @@ static int __register_pernet_operations(struct list_head *list,
101210
101211 out_undo:
101212 /* If I have an error cleanup all namespaces I initialized */
101213- list_del(&ops->list);
101214+ pax_list_del((struct list_head *)&ops->list);
101215 ops_exit_list(ops, &net_exit_list);
101216 ops_free_list(ops, &net_exit_list);
101217 return error;
101218@@ -469,7 +469,7 @@ static void __unregister_pernet_operations(struct pernet_operations *ops)
101219 struct net *net;
101220 LIST_HEAD(net_exit_list);
101221
101222- list_del(&ops->list);
101223+ pax_list_del((struct list_head *)&ops->list);
101224 for_each_net(net)
101225 list_add_tail(&net->exit_list, &net_exit_list);
101226 ops_exit_list(ops, &net_exit_list);
101227@@ -603,7 +603,7 @@ int register_pernet_device(struct pernet_operations *ops)
101228 mutex_lock(&net_mutex);
101229 error = register_pernet_operations(&pernet_list, ops);
101230 if (!error && (first_device == &pernet_list))
101231- first_device = &ops->list;
101232+ first_device = (struct list_head *)&ops->list;
101233 mutex_unlock(&net_mutex);
101234 return error;
101235 }
101236diff --git a/net/core/netpoll.c b/net/core/netpoll.c
101237index e6645b4..43e1af9 100644
101238--- a/net/core/netpoll.c
101239+++ b/net/core/netpoll.c
101240@@ -379,7 +379,7 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len)
101241 struct udphdr *udph;
101242 struct iphdr *iph;
101243 struct ethhdr *eth;
101244- static atomic_t ip_ident;
101245+ static atomic_unchecked_t ip_ident;
101246 struct ipv6hdr *ip6h;
101247
101248 udp_len = len + sizeof(*udph);
101249@@ -450,7 +450,7 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len)
101250 put_unaligned(0x45, (unsigned char *)iph);
101251 iph->tos = 0;
101252 put_unaligned(htons(ip_len), &(iph->tot_len));
101253- iph->id = htons(atomic_inc_return(&ip_ident));
101254+ iph->id = htons(atomic_inc_return_unchecked(&ip_ident));
101255 iph->frag_off = 0;
101256 iph->ttl = 64;
101257 iph->protocol = IPPROTO_UDP;
101258diff --git a/net/core/pktgen.c b/net/core/pktgen.c
101259index 443256b..bbff424 100644
101260--- a/net/core/pktgen.c
101261+++ b/net/core/pktgen.c
101262@@ -3753,7 +3753,7 @@ static int __net_init pg_net_init(struct net *net)
101263 pn->net = net;
101264 INIT_LIST_HEAD(&pn->pktgen_threads);
101265 pn->pktgen_exiting = false;
101266- pn->proc_dir = proc_mkdir(PG_PROC_DIR, pn->net->proc_net);
101267+ pn->proc_dir = proc_mkdir_restrict(PG_PROC_DIR, pn->net->proc_net);
101268 if (!pn->proc_dir) {
101269 pr_warn("cannot create /proc/net/%s\n", PG_PROC_DIR);
101270 return -ENODEV;
101271diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
101272index 76321ea..3129bd6 100644
101273--- a/net/core/rtnetlink.c
101274+++ b/net/core/rtnetlink.c
101275@@ -58,7 +58,7 @@ struct rtnl_link {
101276 rtnl_doit_func doit;
101277 rtnl_dumpit_func dumpit;
101278 rtnl_calcit_func calcit;
101279-};
101280+} __no_const;
101281
101282 static DEFINE_MUTEX(rtnl_mutex);
101283
101284@@ -304,10 +304,13 @@ int __rtnl_link_register(struct rtnl_link_ops *ops)
101285 * to use the ops for creating device. So do not
101286 * fill up dellink as well. That disables rtnl_dellink.
101287 */
101288- if (ops->setup && !ops->dellink)
101289- ops->dellink = unregister_netdevice_queue;
101290+ if (ops->setup && !ops->dellink) {
101291+ pax_open_kernel();
101292+ *(void **)&ops->dellink = unregister_netdevice_queue;
101293+ pax_close_kernel();
101294+ }
101295
101296- list_add_tail(&ops->list, &link_ops);
101297+ pax_list_add_tail((struct list_head *)&ops->list, &link_ops);
101298 return 0;
101299 }
101300 EXPORT_SYMBOL_GPL(__rtnl_link_register);
101301@@ -354,7 +357,7 @@ void __rtnl_link_unregister(struct rtnl_link_ops *ops)
101302 for_each_net(net) {
101303 __rtnl_kill_links(net, ops);
101304 }
101305- list_del(&ops->list);
101306+ pax_list_del((struct list_head *)&ops->list);
101307 }
101308 EXPORT_SYMBOL_GPL(__rtnl_link_unregister);
101309
101310@@ -1014,7 +1017,7 @@ static int rtnl_fill_ifinfo(struct sk_buff *skb, struct net_device *dev,
101311 (dev->ifalias &&
101312 nla_put_string(skb, IFLA_IFALIAS, dev->ifalias)) ||
101313 nla_put_u32(skb, IFLA_CARRIER_CHANGES,
101314- atomic_read(&dev->carrier_changes)))
101315+ atomic_read_unchecked(&dev->carrier_changes)))
101316 goto nla_put_failure;
101317
101318 if (1) {
101319diff --git a/net/core/scm.c b/net/core/scm.c
101320index b442e7e..6f5b5a2 100644
101321--- a/net/core/scm.c
101322+++ b/net/core/scm.c
101323@@ -210,7 +210,7 @@ EXPORT_SYMBOL(__scm_send);
101324 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
101325 {
101326 struct cmsghdr __user *cm
101327- = (__force struct cmsghdr __user *)msg->msg_control;
101328+ = (struct cmsghdr __force_user *)msg->msg_control;
101329 struct cmsghdr cmhdr;
101330 int cmlen = CMSG_LEN(len);
101331 int err;
101332@@ -233,7 +233,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
101333 err = -EFAULT;
101334 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
101335 goto out;
101336- if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
101337+ if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
101338 goto out;
101339 cmlen = CMSG_SPACE(len);
101340 if (msg->msg_controllen < cmlen)
101341@@ -249,7 +249,7 @@ EXPORT_SYMBOL(put_cmsg);
101342 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
101343 {
101344 struct cmsghdr __user *cm
101345- = (__force struct cmsghdr __user*)msg->msg_control;
101346+ = (struct cmsghdr __force_user *)msg->msg_control;
101347
101348 int fdmax = 0;
101349 int fdnum = scm->fp->count;
101350@@ -269,7 +269,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
101351 if (fdnum < fdmax)
101352 fdmax = fdnum;
101353
101354- for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
101355+ for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
101356 i++, cmfptr++)
101357 {
101358 struct socket *sock;
101359diff --git a/net/core/skbuff.c b/net/core/skbuff.c
101360index 32e31c2..e981248 100644
101361--- a/net/core/skbuff.c
101362+++ b/net/core/skbuff.c
101363@@ -2025,7 +2025,7 @@ EXPORT_SYMBOL(__skb_checksum);
101364 __wsum skb_checksum(const struct sk_buff *skb, int offset,
101365 int len, __wsum csum)
101366 {
101367- const struct skb_checksum_ops ops = {
101368+ static const struct skb_checksum_ops ops = {
101369 .update = csum_partial_ext,
101370 .combine = csum_block_add_ext,
101371 };
101372@@ -3255,12 +3255,14 @@ void __init skb_init(void)
101373 skbuff_head_cache = kmem_cache_create("skbuff_head_cache",
101374 sizeof(struct sk_buff),
101375 0,
101376- SLAB_HWCACHE_ALIGN|SLAB_PANIC,
101377+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|
101378+ SLAB_NO_SANITIZE,
101379 NULL);
101380 skbuff_fclone_cache = kmem_cache_create("skbuff_fclone_cache",
101381 sizeof(struct sk_buff_fclones),
101382 0,
101383- SLAB_HWCACHE_ALIGN|SLAB_PANIC,
101384+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|
101385+ SLAB_NO_SANITIZE,
101386 NULL);
101387 }
101388
101389diff --git a/net/core/sock.c b/net/core/sock.c
101390index 15e0c67..0310f4a 100644
101391--- a/net/core/sock.c
101392+++ b/net/core/sock.c
101393@@ -441,7 +441,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
101394 struct sk_buff_head *list = &sk->sk_receive_queue;
101395
101396 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
101397- atomic_inc(&sk->sk_drops);
101398+ atomic_inc_unchecked(&sk->sk_drops);
101399 trace_sock_rcvqueue_full(sk, skb);
101400 return -ENOMEM;
101401 }
101402@@ -451,7 +451,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
101403 return err;
101404
101405 if (!sk_rmem_schedule(sk, skb, skb->truesize)) {
101406- atomic_inc(&sk->sk_drops);
101407+ atomic_inc_unchecked(&sk->sk_drops);
101408 return -ENOBUFS;
101409 }
101410
101411@@ -464,7 +464,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
101412 skb_dst_force(skb);
101413
101414 spin_lock_irqsave(&list->lock, flags);
101415- skb->dropcount = atomic_read(&sk->sk_drops);
101416+ skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
101417 __skb_queue_tail(list, skb);
101418 spin_unlock_irqrestore(&list->lock, flags);
101419
101420@@ -484,7 +484,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
101421 skb->dev = NULL;
101422
101423 if (sk_rcvqueues_full(sk, sk->sk_rcvbuf)) {
101424- atomic_inc(&sk->sk_drops);
101425+ atomic_inc_unchecked(&sk->sk_drops);
101426 goto discard_and_relse;
101427 }
101428 if (nested)
101429@@ -502,7 +502,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
101430 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
101431 } else if (sk_add_backlog(sk, skb, sk->sk_rcvbuf)) {
101432 bh_unlock_sock(sk);
101433- atomic_inc(&sk->sk_drops);
101434+ atomic_inc_unchecked(&sk->sk_drops);
101435 goto discard_and_relse;
101436 }
101437
101438@@ -991,12 +991,12 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
101439 struct timeval tm;
101440 } v;
101441
101442- int lv = sizeof(int);
101443- int len;
101444+ unsigned int lv = sizeof(int);
101445+ unsigned int len;
101446
101447 if (get_user(len, optlen))
101448 return -EFAULT;
101449- if (len < 0)
101450+ if (len > INT_MAX)
101451 return -EINVAL;
101452
101453 memset(&v, 0, sizeof(v));
101454@@ -1134,11 +1134,11 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
101455
101456 case SO_PEERNAME:
101457 {
101458- char address[128];
101459+ char address[_K_SS_MAXSIZE];
101460
101461 if (sock->ops->getname(sock, (struct sockaddr *)address, &lv, 2))
101462 return -ENOTCONN;
101463- if (lv < len)
101464+ if (lv < len || sizeof address < len)
101465 return -EINVAL;
101466 if (copy_to_user(optval, address, len))
101467 return -EFAULT;
101468@@ -1219,7 +1219,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
101469
101470 if (len > lv)
101471 len = lv;
101472- if (copy_to_user(optval, &v, len))
101473+ if (len > sizeof(v) || copy_to_user(optval, &v, len))
101474 return -EFAULT;
101475 lenout:
101476 if (put_user(len, optlen))
101477@@ -2315,7 +2315,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
101478 */
101479 smp_wmb();
101480 atomic_set(&sk->sk_refcnt, 1);
101481- atomic_set(&sk->sk_drops, 0);
101482+ atomic_set_unchecked(&sk->sk_drops, 0);
101483 }
101484 EXPORT_SYMBOL(sock_init_data);
101485
101486@@ -2443,6 +2443,7 @@ void sock_enable_timestamp(struct sock *sk, int flag)
101487 int sock_recv_errqueue(struct sock *sk, struct msghdr *msg, int len,
101488 int level, int type)
101489 {
101490+ struct sock_extended_err ee;
101491 struct sock_exterr_skb *serr;
101492 struct sk_buff *skb;
101493 int copied, err;
101494@@ -2464,7 +2465,8 @@ int sock_recv_errqueue(struct sock *sk, struct msghdr *msg, int len,
101495 sock_recv_timestamp(msg, sk, skb);
101496
101497 serr = SKB_EXT_ERR(skb);
101498- put_cmsg(msg, level, type, sizeof(serr->ee), &serr->ee);
101499+ ee = serr->ee;
101500+ put_cmsg(msg, level, type, sizeof ee, &ee);
101501
101502 msg->msg_flags |= MSG_ERRQUEUE;
101503 err = copied;
101504diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
101505index ad704c7..ca48aff 100644
101506--- a/net/core/sock_diag.c
101507+++ b/net/core/sock_diag.c
101508@@ -9,26 +9,33 @@
101509 #include <linux/inet_diag.h>
101510 #include <linux/sock_diag.h>
101511
101512-static const struct sock_diag_handler *sock_diag_handlers[AF_MAX];
101513+static const struct sock_diag_handler *sock_diag_handlers[AF_MAX] __read_only;
101514 static int (*inet_rcv_compat)(struct sk_buff *skb, struct nlmsghdr *nlh);
101515 static DEFINE_MUTEX(sock_diag_table_mutex);
101516
101517 int sock_diag_check_cookie(void *sk, __u32 *cookie)
101518 {
101519+#ifndef CONFIG_GRKERNSEC_HIDESYM
101520 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
101521 cookie[1] != INET_DIAG_NOCOOKIE) &&
101522 ((u32)(unsigned long)sk != cookie[0] ||
101523 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
101524 return -ESTALE;
101525 else
101526+#endif
101527 return 0;
101528 }
101529 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
101530
101531 void sock_diag_save_cookie(void *sk, __u32 *cookie)
101532 {
101533+#ifdef CONFIG_GRKERNSEC_HIDESYM
101534+ cookie[0] = 0;
101535+ cookie[1] = 0;
101536+#else
101537 cookie[0] = (u32)(unsigned long)sk;
101538 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
101539+#endif
101540 }
101541 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
101542
101543@@ -110,8 +117,11 @@ int sock_diag_register(const struct sock_diag_handler *hndl)
101544 mutex_lock(&sock_diag_table_mutex);
101545 if (sock_diag_handlers[hndl->family])
101546 err = -EBUSY;
101547- else
101548+ else {
101549+ pax_open_kernel();
101550 sock_diag_handlers[hndl->family] = hndl;
101551+ pax_close_kernel();
101552+ }
101553 mutex_unlock(&sock_diag_table_mutex);
101554
101555 return err;
101556@@ -127,7 +137,9 @@ void sock_diag_unregister(const struct sock_diag_handler *hnld)
101557
101558 mutex_lock(&sock_diag_table_mutex);
101559 BUG_ON(sock_diag_handlers[family] != hnld);
101560+ pax_open_kernel();
101561 sock_diag_handlers[family] = NULL;
101562+ pax_close_kernel();
101563 mutex_unlock(&sock_diag_table_mutex);
101564 }
101565 EXPORT_SYMBOL_GPL(sock_diag_unregister);
101566diff --git a/net/core/sysctl_net_core.c b/net/core/sysctl_net_core.c
101567index cf9cd13..50683950 100644
101568--- a/net/core/sysctl_net_core.c
101569+++ b/net/core/sysctl_net_core.c
101570@@ -32,7 +32,7 @@ static int rps_sock_flow_sysctl(struct ctl_table *table, int write,
101571 {
101572 unsigned int orig_size, size;
101573 int ret, i;
101574- struct ctl_table tmp = {
101575+ ctl_table_no_const tmp = {
101576 .data = &size,
101577 .maxlen = sizeof(size),
101578 .mode = table->mode
101579@@ -200,7 +200,7 @@ static int set_default_qdisc(struct ctl_table *table, int write,
101580 void __user *buffer, size_t *lenp, loff_t *ppos)
101581 {
101582 char id[IFNAMSIZ];
101583- struct ctl_table tbl = {
101584+ ctl_table_no_const tbl = {
101585 .data = id,
101586 .maxlen = IFNAMSIZ,
101587 };
101588@@ -263,7 +263,7 @@ static struct ctl_table net_core_table[] = {
101589 .mode = 0644,
101590 .proc_handler = proc_dointvec
101591 },
101592-#ifdef CONFIG_BPF_JIT
101593+#if defined(CONFIG_BPF_JIT) && !defined(CONFIG_GRKERNSEC_BPF_HARDEN)
101594 {
101595 .procname = "bpf_jit_enable",
101596 .data = &bpf_jit_enable,
101597@@ -379,13 +379,12 @@ static struct ctl_table netns_core_table[] = {
101598
101599 static __net_init int sysctl_core_net_init(struct net *net)
101600 {
101601- struct ctl_table *tbl;
101602+ ctl_table_no_const *tbl = NULL;
101603
101604 net->core.sysctl_somaxconn = SOMAXCONN;
101605
101606- tbl = netns_core_table;
101607 if (!net_eq(net, &init_net)) {
101608- tbl = kmemdup(tbl, sizeof(netns_core_table), GFP_KERNEL);
101609+ tbl = kmemdup(netns_core_table, sizeof(netns_core_table), GFP_KERNEL);
101610 if (tbl == NULL)
101611 goto err_dup;
101612
101613@@ -395,17 +394,16 @@ static __net_init int sysctl_core_net_init(struct net *net)
101614 if (net->user_ns != &init_user_ns) {
101615 tbl[0].procname = NULL;
101616 }
101617- }
101618-
101619- net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
101620+ net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
101621+ } else
101622+ net->core.sysctl_hdr = register_net_sysctl(net, "net/core", netns_core_table);
101623 if (net->core.sysctl_hdr == NULL)
101624 goto err_reg;
101625
101626 return 0;
101627
101628 err_reg:
101629- if (tbl != netns_core_table)
101630- kfree(tbl);
101631+ kfree(tbl);
101632 err_dup:
101633 return -ENOMEM;
101634 }
101635@@ -420,7 +418,7 @@ static __net_exit void sysctl_core_net_exit(struct net *net)
101636 kfree(tbl);
101637 }
101638
101639-static __net_initdata struct pernet_operations sysctl_core_ops = {
101640+static __net_initconst struct pernet_operations sysctl_core_ops = {
101641 .init = sysctl_core_net_init,
101642 .exit = sysctl_core_net_exit,
101643 };
101644diff --git a/net/decnet/af_decnet.c b/net/decnet/af_decnet.c
101645index 25733d5..b9360f0 100644
101646--- a/net/decnet/af_decnet.c
101647+++ b/net/decnet/af_decnet.c
101648@@ -466,6 +466,7 @@ static struct proto dn_proto = {
101649 .sysctl_rmem = sysctl_decnet_rmem,
101650 .max_header = DN_MAX_NSP_DATA_HEADER + 64,
101651 .obj_size = sizeof(struct dn_sock),
101652+ .slab_flags = SLAB_USERCOPY,
101653 };
101654
101655 static struct sock *dn_alloc_sock(struct net *net, struct socket *sock, gfp_t gfp)
101656diff --git a/net/decnet/dn_dev.c b/net/decnet/dn_dev.c
101657index 4400da7..3429972 100644
101658--- a/net/decnet/dn_dev.c
101659+++ b/net/decnet/dn_dev.c
101660@@ -201,7 +201,7 @@ static struct dn_dev_sysctl_table {
101661 .extra1 = &min_t3,
101662 .extra2 = &max_t3
101663 },
101664- {0}
101665+ { }
101666 },
101667 };
101668
101669diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
101670index 5325b54..a0d4d69 100644
101671--- a/net/decnet/sysctl_net_decnet.c
101672+++ b/net/decnet/sysctl_net_decnet.c
101673@@ -174,7 +174,7 @@ static int dn_node_address_handler(struct ctl_table *table, int write,
101674
101675 if (len > *lenp) len = *lenp;
101676
101677- if (copy_to_user(buffer, addr, len))
101678+ if (len > sizeof addr || copy_to_user(buffer, addr, len))
101679 return -EFAULT;
101680
101681 *lenp = len;
101682@@ -237,7 +237,7 @@ static int dn_def_dev_handler(struct ctl_table *table, int write,
101683
101684 if (len > *lenp) len = *lenp;
101685
101686- if (copy_to_user(buffer, devname, len))
101687+ if (len > sizeof devname || copy_to_user(buffer, devname, len))
101688 return -EFAULT;
101689
101690 *lenp = len;
101691diff --git a/net/hsr/hsr_netlink.c b/net/hsr/hsr_netlink.c
101692index a2c7e4c..3dc9f67 100644
101693--- a/net/hsr/hsr_netlink.c
101694+++ b/net/hsr/hsr_netlink.c
101695@@ -102,7 +102,7 @@ nla_put_failure:
101696 return -EMSGSIZE;
101697 }
101698
101699-static struct rtnl_link_ops hsr_link_ops __read_mostly = {
101700+static struct rtnl_link_ops hsr_link_ops = {
101701 .kind = "hsr",
101702 .maxtype = IFLA_HSR_MAX,
101703 .policy = hsr_policy,
101704diff --git a/net/ieee802154/6lowpan_rtnl.c b/net/ieee802154/6lowpan_rtnl.c
101705index 4413629..dea596a 100644
101706--- a/net/ieee802154/6lowpan_rtnl.c
101707+++ b/net/ieee802154/6lowpan_rtnl.c
101708@@ -635,7 +635,7 @@ static void lowpan_dellink(struct net_device *dev, struct list_head *head)
101709 dev_put(real_dev);
101710 }
101711
101712-static struct rtnl_link_ops lowpan_link_ops __read_mostly = {
101713+static struct rtnl_link_ops lowpan_link_ops = {
101714 .kind = "lowpan",
101715 .priv_size = sizeof(struct lowpan_dev_info),
101716 .setup = lowpan_setup,
101717diff --git a/net/ieee802154/reassembly.c b/net/ieee802154/reassembly.c
101718index 7cfcd68..84ca5b7 100644
101719--- a/net/ieee802154/reassembly.c
101720+++ b/net/ieee802154/reassembly.c
101721@@ -433,14 +433,13 @@ static struct ctl_table lowpan_frags_ctl_table[] = {
101722
101723 static int __net_init lowpan_frags_ns_sysctl_register(struct net *net)
101724 {
101725- struct ctl_table *table;
101726+ ctl_table_no_const *table = NULL;
101727 struct ctl_table_header *hdr;
101728 struct netns_ieee802154_lowpan *ieee802154_lowpan =
101729 net_ieee802154_lowpan(net);
101730
101731- table = lowpan_frags_ns_ctl_table;
101732 if (!net_eq(net, &init_net)) {
101733- table = kmemdup(table, sizeof(lowpan_frags_ns_ctl_table),
101734+ table = kmemdup(lowpan_frags_ns_ctl_table, sizeof(lowpan_frags_ns_ctl_table),
101735 GFP_KERNEL);
101736 if (table == NULL)
101737 goto err_alloc;
101738@@ -455,9 +454,9 @@ static int __net_init lowpan_frags_ns_sysctl_register(struct net *net)
101739 /* Don't export sysctls to unprivileged users */
101740 if (net->user_ns != &init_user_ns)
101741 table[0].procname = NULL;
101742- }
101743-
101744- hdr = register_net_sysctl(net, "net/ieee802154/6lowpan", table);
101745+ hdr = register_net_sysctl(net, "net/ieee802154/6lowpan", table);
101746+ } else
101747+ hdr = register_net_sysctl(net, "net/ieee802154/6lowpan", lowpan_frags_ns_ctl_table);
101748 if (hdr == NULL)
101749 goto err_reg;
101750
101751@@ -465,8 +464,7 @@ static int __net_init lowpan_frags_ns_sysctl_register(struct net *net)
101752 return 0;
101753
101754 err_reg:
101755- if (!net_eq(net, &init_net))
101756- kfree(table);
101757+ kfree(table);
101758 err_alloc:
101759 return -ENOMEM;
101760 }
101761diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c
101762index e67da4e..da217942 100644
101763--- a/net/ipv4/af_inet.c
101764+++ b/net/ipv4/af_inet.c
101765@@ -1392,7 +1392,7 @@ int inet_recv_error(struct sock *sk, struct msghdr *msg, int len, int *addr_len)
101766 return ip_recv_error(sk, msg, len, addr_len);
101767 #if IS_ENABLED(CONFIG_IPV6)
101768 if (sk->sk_family == AF_INET6)
101769- return pingv6_ops.ipv6_recv_error(sk, msg, len, addr_len);
101770+ return pingv6_ops->ipv6_recv_error(sk, msg, len, addr_len);
101771 #endif
101772 return -EINVAL;
101773 }
101774diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
101775index 214882e..ec032f6 100644
101776--- a/net/ipv4/devinet.c
101777+++ b/net/ipv4/devinet.c
101778@@ -69,7 +69,8 @@
101779
101780 static struct ipv4_devconf ipv4_devconf = {
101781 .data = {
101782- [IPV4_DEVCONF_ACCEPT_REDIRECTS - 1] = 1,
101783+ [IPV4_DEVCONF_ACCEPT_REDIRECTS - 1] = 0,
101784+ [IPV4_DEVCONF_RP_FILTER - 1] = 1,
101785 [IPV4_DEVCONF_SEND_REDIRECTS - 1] = 1,
101786 [IPV4_DEVCONF_SECURE_REDIRECTS - 1] = 1,
101787 [IPV4_DEVCONF_SHARED_MEDIA - 1] = 1,
101788@@ -80,7 +81,8 @@ static struct ipv4_devconf ipv4_devconf = {
101789
101790 static struct ipv4_devconf ipv4_devconf_dflt = {
101791 .data = {
101792- [IPV4_DEVCONF_ACCEPT_REDIRECTS - 1] = 1,
101793+ [IPV4_DEVCONF_ACCEPT_REDIRECTS - 1] = 0,
101794+ [IPV4_DEVCONF_RP_FILTER - 1] = 1,
101795 [IPV4_DEVCONF_SEND_REDIRECTS - 1] = 1,
101796 [IPV4_DEVCONF_SECURE_REDIRECTS - 1] = 1,
101797 [IPV4_DEVCONF_SHARED_MEDIA - 1] = 1,
101798@@ -1548,7 +1550,7 @@ static int inet_dump_ifaddr(struct sk_buff *skb, struct netlink_callback *cb)
101799 idx = 0;
101800 head = &net->dev_index_head[h];
101801 rcu_read_lock();
101802- cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
101803+ cb->seq = atomic_read_unchecked(&net->ipv4.dev_addr_genid) ^
101804 net->dev_base_seq;
101805 hlist_for_each_entry_rcu(dev, head, index_hlist) {
101806 if (idx < s_idx)
101807@@ -1866,7 +1868,7 @@ static int inet_netconf_dump_devconf(struct sk_buff *skb,
101808 idx = 0;
101809 head = &net->dev_index_head[h];
101810 rcu_read_lock();
101811- cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
101812+ cb->seq = atomic_read_unchecked(&net->ipv4.dev_addr_genid) ^
101813 net->dev_base_seq;
101814 hlist_for_each_entry_rcu(dev, head, index_hlist) {
101815 if (idx < s_idx)
101816@@ -2101,7 +2103,7 @@ static int ipv4_doint_and_flush(struct ctl_table *ctl, int write,
101817 #define DEVINET_SYSCTL_FLUSHING_ENTRY(attr, name) \
101818 DEVINET_SYSCTL_COMPLEX_ENTRY(attr, name, ipv4_doint_and_flush)
101819
101820-static struct devinet_sysctl_table {
101821+static const struct devinet_sysctl_table {
101822 struct ctl_table_header *sysctl_header;
101823 struct ctl_table devinet_vars[__IPV4_DEVCONF_MAX];
101824 } devinet_sysctl = {
101825@@ -2233,7 +2235,7 @@ static __net_init int devinet_init_net(struct net *net)
101826 int err;
101827 struct ipv4_devconf *all, *dflt;
101828 #ifdef CONFIG_SYSCTL
101829- struct ctl_table *tbl = ctl_forward_entry;
101830+ ctl_table_no_const *tbl = NULL;
101831 struct ctl_table_header *forw_hdr;
101832 #endif
101833
101834@@ -2251,7 +2253,7 @@ static __net_init int devinet_init_net(struct net *net)
101835 goto err_alloc_dflt;
101836
101837 #ifdef CONFIG_SYSCTL
101838- tbl = kmemdup(tbl, sizeof(ctl_forward_entry), GFP_KERNEL);
101839+ tbl = kmemdup(ctl_forward_entry, sizeof(ctl_forward_entry), GFP_KERNEL);
101840 if (tbl == NULL)
101841 goto err_alloc_ctl;
101842
101843@@ -2271,7 +2273,10 @@ static __net_init int devinet_init_net(struct net *net)
101844 goto err_reg_dflt;
101845
101846 err = -ENOMEM;
101847- forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
101848+ if (!net_eq(net, &init_net))
101849+ forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
101850+ else
101851+ forw_hdr = register_net_sysctl(net, "net/ipv4", ctl_forward_entry);
101852 if (forw_hdr == NULL)
101853 goto err_reg_ctl;
101854 net->ipv4.forw_hdr = forw_hdr;
101855@@ -2287,8 +2292,7 @@ err_reg_ctl:
101856 err_reg_dflt:
101857 __devinet_sysctl_unregister(all);
101858 err_reg_all:
101859- if (tbl != ctl_forward_entry)
101860- kfree(tbl);
101861+ kfree(tbl);
101862 err_alloc_ctl:
101863 #endif
101864 if (dflt != &ipv4_devconf_dflt)
101865diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
101866index 23104a3..9f5570b 100644
101867--- a/net/ipv4/fib_frontend.c
101868+++ b/net/ipv4/fib_frontend.c
101869@@ -1017,12 +1017,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
101870 #ifdef CONFIG_IP_ROUTE_MULTIPATH
101871 fib_sync_up(dev);
101872 #endif
101873- atomic_inc(&net->ipv4.dev_addr_genid);
101874+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
101875 rt_cache_flush(dev_net(dev));
101876 break;
101877 case NETDEV_DOWN:
101878 fib_del_ifaddr(ifa, NULL);
101879- atomic_inc(&net->ipv4.dev_addr_genid);
101880+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
101881 if (ifa->ifa_dev->ifa_list == NULL) {
101882 /* Last address was deleted from this interface.
101883 * Disable IP.
101884@@ -1060,7 +1060,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
101885 #ifdef CONFIG_IP_ROUTE_MULTIPATH
101886 fib_sync_up(dev);
101887 #endif
101888- atomic_inc(&net->ipv4.dev_addr_genid);
101889+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
101890 rt_cache_flush(net);
101891 break;
101892 case NETDEV_DOWN:
101893diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
101894index f99f41b..1879da9 100644
101895--- a/net/ipv4/fib_semantics.c
101896+++ b/net/ipv4/fib_semantics.c
101897@@ -770,7 +770,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
101898 nh->nh_saddr = inet_select_addr(nh->nh_dev,
101899 nh->nh_gw,
101900 nh->nh_parent->fib_scope);
101901- nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
101902+ nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
101903
101904 return nh->nh_saddr;
101905 }
101906diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
101907index 9111a4e..3576905 100644
101908--- a/net/ipv4/inet_hashtables.c
101909+++ b/net/ipv4/inet_hashtables.c
101910@@ -18,6 +18,7 @@
101911 #include <linux/sched.h>
101912 #include <linux/slab.h>
101913 #include <linux/wait.h>
101914+#include <linux/security.h>
101915
101916 #include <net/inet_connection_sock.h>
101917 #include <net/inet_hashtables.h>
101918@@ -49,6 +50,8 @@ static unsigned int inet_sk_ehashfn(const struct sock *sk)
101919 return inet_ehashfn(net, laddr, lport, faddr, fport);
101920 }
101921
101922+extern void gr_update_task_in_ip_table(const struct inet_sock *inet);
101923+
101924 /*
101925 * Allocate and initialize a new local port bind bucket.
101926 * The bindhash mutex for snum's hash chain must be held here.
101927@@ -554,6 +557,8 @@ ok:
101928 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
101929 spin_unlock(&head->lock);
101930
101931+ gr_update_task_in_ip_table(inet_sk(sk));
101932+
101933 if (tw) {
101934 inet_twsk_deschedule(tw, death_row);
101935 while (twrefcnt) {
101936diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
101937index 241afd7..31b95d5 100644
101938--- a/net/ipv4/inetpeer.c
101939+++ b/net/ipv4/inetpeer.c
101940@@ -461,7 +461,7 @@ relookup:
101941 if (p) {
101942 p->daddr = *daddr;
101943 atomic_set(&p->refcnt, 1);
101944- atomic_set(&p->rid, 0);
101945+ atomic_set_unchecked(&p->rid, 0);
101946 p->metrics[RTAX_LOCK-1] = INETPEER_METRICS_NEW;
101947 p->rate_tokens = 0;
101948 /* 60*HZ is arbitrary, but chosen enough high so that the first
101949diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
101950index 2811cc1..ad5a534 100644
101951--- a/net/ipv4/ip_fragment.c
101952+++ b/net/ipv4/ip_fragment.c
101953@@ -268,7 +268,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
101954 return 0;
101955
101956 start = qp->rid;
101957- end = atomic_inc_return(&peer->rid);
101958+ end = atomic_inc_return_unchecked(&peer->rid);
101959 qp->rid = end;
101960
101961 rc = qp->q.fragments && (end - start) > max;
101962@@ -746,12 +746,11 @@ static struct ctl_table ip4_frags_ctl_table[] = {
101963
101964 static int __net_init ip4_frags_ns_ctl_register(struct net *net)
101965 {
101966- struct ctl_table *table;
101967+ ctl_table_no_const *table = NULL;
101968 struct ctl_table_header *hdr;
101969
101970- table = ip4_frags_ns_ctl_table;
101971 if (!net_eq(net, &init_net)) {
101972- table = kmemdup(table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
101973+ table = kmemdup(ip4_frags_ns_ctl_table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
101974 if (table == NULL)
101975 goto err_alloc;
101976
101977@@ -765,9 +764,10 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
101978 /* Don't export sysctls to unprivileged users */
101979 if (net->user_ns != &init_user_ns)
101980 table[0].procname = NULL;
101981- }
101982+ hdr = register_net_sysctl(net, "net/ipv4", table);
101983+ } else
101984+ hdr = register_net_sysctl(net, "net/ipv4", ip4_frags_ns_ctl_table);
101985
101986- hdr = register_net_sysctl(net, "net/ipv4", table);
101987 if (hdr == NULL)
101988 goto err_reg;
101989
101990@@ -775,8 +775,7 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
101991 return 0;
101992
101993 err_reg:
101994- if (!net_eq(net, &init_net))
101995- kfree(table);
101996+ kfree(table);
101997 err_alloc:
101998 return -ENOMEM;
101999 }
102000diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c
102001index 12055fd..df852c4 100644
102002--- a/net/ipv4/ip_gre.c
102003+++ b/net/ipv4/ip_gre.c
102004@@ -115,7 +115,7 @@ static bool log_ecn_error = true;
102005 module_param(log_ecn_error, bool, 0644);
102006 MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
102007
102008-static struct rtnl_link_ops ipgre_link_ops __read_mostly;
102009+static struct rtnl_link_ops ipgre_link_ops;
102010 static int ipgre_tunnel_init(struct net_device *dev);
102011
102012 static int ipgre_net_id __read_mostly;
102013@@ -815,7 +815,7 @@ static const struct nla_policy ipgre_policy[IFLA_GRE_MAX + 1] = {
102014 [IFLA_GRE_ENCAP_DPORT] = { .type = NLA_U16 },
102015 };
102016
102017-static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
102018+static struct rtnl_link_ops ipgre_link_ops = {
102019 .kind = "gre",
102020 .maxtype = IFLA_GRE_MAX,
102021 .policy = ipgre_policy,
102022@@ -829,7 +829,7 @@ static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
102023 .fill_info = ipgre_fill_info,
102024 };
102025
102026-static struct rtnl_link_ops ipgre_tap_ops __read_mostly = {
102027+static struct rtnl_link_ops ipgre_tap_ops = {
102028 .kind = "gretap",
102029 .maxtype = IFLA_GRE_MAX,
102030 .policy = ipgre_policy,
102031diff --git a/net/ipv4/ip_input.c b/net/ipv4/ip_input.c
102032index 3d4da2c..40f9c29 100644
102033--- a/net/ipv4/ip_input.c
102034+++ b/net/ipv4/ip_input.c
102035@@ -147,6 +147,10 @@
102036 #include <linux/mroute.h>
102037 #include <linux/netlink.h>
102038
102039+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
102040+extern int grsec_enable_blackhole;
102041+#endif
102042+
102043 /*
102044 * Process Router Attention IP option (RFC 2113)
102045 */
102046@@ -223,6 +227,9 @@ static int ip_local_deliver_finish(struct sk_buff *skb)
102047 if (!raw) {
102048 if (xfrm4_policy_check(NULL, XFRM_POLICY_IN, skb)) {
102049 IP_INC_STATS_BH(net, IPSTATS_MIB_INUNKNOWNPROTOS);
102050+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
102051+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
102052+#endif
102053 icmp_send(skb, ICMP_DEST_UNREACH,
102054 ICMP_PROT_UNREACH, 0);
102055 }
102056diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
102057index 9daf217..dc6972d 100644
102058--- a/net/ipv4/ip_sockglue.c
102059+++ b/net/ipv4/ip_sockglue.c
102060@@ -1177,7 +1177,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
102061 len = min_t(unsigned int, len, opt->optlen);
102062 if (put_user(len, optlen))
102063 return -EFAULT;
102064- if (copy_to_user(optval, opt->__data, len))
102065+ if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
102066+ copy_to_user(optval, opt->__data, len))
102067 return -EFAULT;
102068 return 0;
102069 }
102070@@ -1308,7 +1309,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
102071 if (sk->sk_type != SOCK_STREAM)
102072 return -ENOPROTOOPT;
102073
102074- msg.msg_control = (__force void *) optval;
102075+ msg.msg_control = (__force_kernel void *) optval;
102076 msg.msg_controllen = len;
102077 msg.msg_flags = flags;
102078
102079diff --git a/net/ipv4/ip_vti.c b/net/ipv4/ip_vti.c
102080index 1a7e979..fd05aa4 100644
102081--- a/net/ipv4/ip_vti.c
102082+++ b/net/ipv4/ip_vti.c
102083@@ -45,7 +45,7 @@
102084 #include <net/net_namespace.h>
102085 #include <net/netns/generic.h>
102086
102087-static struct rtnl_link_ops vti_link_ops __read_mostly;
102088+static struct rtnl_link_ops vti_link_ops;
102089
102090 static int vti_net_id __read_mostly;
102091 static int vti_tunnel_init(struct net_device *dev);
102092@@ -519,7 +519,7 @@ static const struct nla_policy vti_policy[IFLA_VTI_MAX + 1] = {
102093 [IFLA_VTI_REMOTE] = { .len = FIELD_SIZEOF(struct iphdr, daddr) },
102094 };
102095
102096-static struct rtnl_link_ops vti_link_ops __read_mostly = {
102097+static struct rtnl_link_ops vti_link_ops = {
102098 .kind = "vti",
102099 .maxtype = IFLA_VTI_MAX,
102100 .policy = vti_policy,
102101diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
102102index 648fa14..97864d0 100644
102103--- a/net/ipv4/ipconfig.c
102104+++ b/net/ipv4/ipconfig.c
102105@@ -333,7 +333,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
102106
102107 mm_segment_t oldfs = get_fs();
102108 set_fs(get_ds());
102109- res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
102110+ res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
102111 set_fs(oldfs);
102112 return res;
102113 }
102114@@ -344,7 +344,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
102115
102116 mm_segment_t oldfs = get_fs();
102117 set_fs(get_ds());
102118- res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
102119+ res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
102120 set_fs(oldfs);
102121 return res;
102122 }
102123@@ -355,7 +355,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
102124
102125 mm_segment_t oldfs = get_fs();
102126 set_fs(get_ds());
102127- res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
102128+ res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
102129 set_fs(oldfs);
102130 return res;
102131 }
102132diff --git a/net/ipv4/ipip.c b/net/ipv4/ipip.c
102133index 37096d6..86abb03 100644
102134--- a/net/ipv4/ipip.c
102135+++ b/net/ipv4/ipip.c
102136@@ -124,7 +124,7 @@ MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
102137 static int ipip_net_id __read_mostly;
102138
102139 static int ipip_tunnel_init(struct net_device *dev);
102140-static struct rtnl_link_ops ipip_link_ops __read_mostly;
102141+static struct rtnl_link_ops ipip_link_ops;
102142
102143 static int ipip_err(struct sk_buff *skb, u32 info)
102144 {
102145@@ -487,7 +487,7 @@ static const struct nla_policy ipip_policy[IFLA_IPTUN_MAX + 1] = {
102146 [IFLA_IPTUN_ENCAP_DPORT] = { .type = NLA_U16 },
102147 };
102148
102149-static struct rtnl_link_ops ipip_link_ops __read_mostly = {
102150+static struct rtnl_link_ops ipip_link_ops = {
102151 .kind = "ipip",
102152 .maxtype = IFLA_IPTUN_MAX,
102153 .policy = ipip_policy,
102154diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
102155index f95b6f9..2ee2097 100644
102156--- a/net/ipv4/netfilter/arp_tables.c
102157+++ b/net/ipv4/netfilter/arp_tables.c
102158@@ -885,14 +885,14 @@ static int compat_table_info(const struct xt_table_info *info,
102159 #endif
102160
102161 static int get_info(struct net *net, void __user *user,
102162- const int *len, int compat)
102163+ int len, int compat)
102164 {
102165 char name[XT_TABLE_MAXNAMELEN];
102166 struct xt_table *t;
102167 int ret;
102168
102169- if (*len != sizeof(struct arpt_getinfo)) {
102170- duprintf("length %u != %Zu\n", *len,
102171+ if (len != sizeof(struct arpt_getinfo)) {
102172+ duprintf("length %u != %Zu\n", len,
102173 sizeof(struct arpt_getinfo));
102174 return -EINVAL;
102175 }
102176@@ -929,7 +929,7 @@ static int get_info(struct net *net, void __user *user,
102177 info.size = private->size;
102178 strcpy(info.name, name);
102179
102180- if (copy_to_user(user, &info, *len) != 0)
102181+ if (copy_to_user(user, &info, len) != 0)
102182 ret = -EFAULT;
102183 else
102184 ret = 0;
102185@@ -1690,7 +1690,7 @@ static int compat_do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user,
102186
102187 switch (cmd) {
102188 case ARPT_SO_GET_INFO:
102189- ret = get_info(sock_net(sk), user, len, 1);
102190+ ret = get_info(sock_net(sk), user, *len, 1);
102191 break;
102192 case ARPT_SO_GET_ENTRIES:
102193 ret = compat_get_entries(sock_net(sk), user, len);
102194@@ -1735,7 +1735,7 @@ static int do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len
102195
102196 switch (cmd) {
102197 case ARPT_SO_GET_INFO:
102198- ret = get_info(sock_net(sk), user, len, 0);
102199+ ret = get_info(sock_net(sk), user, *len, 0);
102200 break;
102201
102202 case ARPT_SO_GET_ENTRIES:
102203diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
102204index 99e810f..3711b81 100644
102205--- a/net/ipv4/netfilter/ip_tables.c
102206+++ b/net/ipv4/netfilter/ip_tables.c
102207@@ -1073,14 +1073,14 @@ static int compat_table_info(const struct xt_table_info *info,
102208 #endif
102209
102210 static int get_info(struct net *net, void __user *user,
102211- const int *len, int compat)
102212+ int len, int compat)
102213 {
102214 char name[XT_TABLE_MAXNAMELEN];
102215 struct xt_table *t;
102216 int ret;
102217
102218- if (*len != sizeof(struct ipt_getinfo)) {
102219- duprintf("length %u != %zu\n", *len,
102220+ if (len != sizeof(struct ipt_getinfo)) {
102221+ duprintf("length %u != %zu\n", len,
102222 sizeof(struct ipt_getinfo));
102223 return -EINVAL;
102224 }
102225@@ -1117,7 +1117,7 @@ static int get_info(struct net *net, void __user *user,
102226 info.size = private->size;
102227 strcpy(info.name, name);
102228
102229- if (copy_to_user(user, &info, *len) != 0)
102230+ if (copy_to_user(user, &info, len) != 0)
102231 ret = -EFAULT;
102232 else
102233 ret = 0;
102234@@ -1973,7 +1973,7 @@ compat_do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
102235
102236 switch (cmd) {
102237 case IPT_SO_GET_INFO:
102238- ret = get_info(sock_net(sk), user, len, 1);
102239+ ret = get_info(sock_net(sk), user, *len, 1);
102240 break;
102241 case IPT_SO_GET_ENTRIES:
102242 ret = compat_get_entries(sock_net(sk), user, len);
102243@@ -2020,7 +2020,7 @@ do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
102244
102245 switch (cmd) {
102246 case IPT_SO_GET_INFO:
102247- ret = get_info(sock_net(sk), user, len, 0);
102248+ ret = get_info(sock_net(sk), user, *len, 0);
102249 break;
102250
102251 case IPT_SO_GET_ENTRIES:
102252diff --git a/net/ipv4/netfilter/ipt_CLUSTERIP.c b/net/ipv4/netfilter/ipt_CLUSTERIP.c
102253index e90f83a..3e6acca 100644
102254--- a/net/ipv4/netfilter/ipt_CLUSTERIP.c
102255+++ b/net/ipv4/netfilter/ipt_CLUSTERIP.c
102256@@ -720,7 +720,7 @@ static int clusterip_net_init(struct net *net)
102257 spin_lock_init(&cn->lock);
102258
102259 #ifdef CONFIG_PROC_FS
102260- cn->procdir = proc_mkdir("ipt_CLUSTERIP", net->proc_net);
102261+ cn->procdir = proc_mkdir_restrict("ipt_CLUSTERIP", net->proc_net);
102262 if (!cn->procdir) {
102263 pr_err("Unable to proc dir entry\n");
102264 return -ENOMEM;
102265diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
102266index 5d740cc..b2842b9 100644
102267--- a/net/ipv4/ping.c
102268+++ b/net/ipv4/ping.c
102269@@ -59,7 +59,7 @@ struct ping_table {
102270 };
102271
102272 static struct ping_table ping_table;
102273-struct pingv6_ops pingv6_ops;
102274+struct pingv6_ops *pingv6_ops;
102275 EXPORT_SYMBOL_GPL(pingv6_ops);
102276
102277 static u16 ping_port_rover;
102278@@ -350,7 +350,7 @@ static int ping_check_bind_addr(struct sock *sk, struct inet_sock *isk,
102279 return -ENODEV;
102280 }
102281 }
102282- has_addr = pingv6_ops.ipv6_chk_addr(net, &addr->sin6_addr, dev,
102283+ has_addr = pingv6_ops->ipv6_chk_addr(net, &addr->sin6_addr, dev,
102284 scoped);
102285 rcu_read_unlock();
102286
102287@@ -558,7 +558,7 @@ void ping_err(struct sk_buff *skb, int offset, u32 info)
102288 }
102289 #if IS_ENABLED(CONFIG_IPV6)
102290 } else if (skb->protocol == htons(ETH_P_IPV6)) {
102291- harderr = pingv6_ops.icmpv6_err_convert(type, code, &err);
102292+ harderr = pingv6_ops->icmpv6_err_convert(type, code, &err);
102293 #endif
102294 }
102295
102296@@ -576,7 +576,7 @@ void ping_err(struct sk_buff *skb, int offset, u32 info)
102297 info, (u8 *)icmph);
102298 #if IS_ENABLED(CONFIG_IPV6)
102299 } else if (family == AF_INET6) {
102300- pingv6_ops.ipv6_icmp_error(sk, skb, err, 0,
102301+ pingv6_ops->ipv6_icmp_error(sk, skb, err, 0,
102302 info, (u8 *)icmph);
102303 #endif
102304 }
102305@@ -910,10 +910,10 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
102306 }
102307
102308 if (inet6_sk(sk)->rxopt.all)
102309- pingv6_ops.ip6_datagram_recv_common_ctl(sk, msg, skb);
102310+ pingv6_ops->ip6_datagram_recv_common_ctl(sk, msg, skb);
102311 if (skb->protocol == htons(ETH_P_IPV6) &&
102312 inet6_sk(sk)->rxopt.all)
102313- pingv6_ops.ip6_datagram_recv_specific_ctl(sk, msg, skb);
102314+ pingv6_ops->ip6_datagram_recv_specific_ctl(sk, msg, skb);
102315 else if (skb->protocol == htons(ETH_P_IP) && isk->cmsg_flags)
102316 ip_cmsg_recv(msg, skb);
102317 #endif
102318@@ -1105,7 +1105,7 @@ static void ping_v4_format_sock(struct sock *sp, struct seq_file *f,
102319 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
102320 0, sock_i_ino(sp),
102321 atomic_read(&sp->sk_refcnt), sp,
102322- atomic_read(&sp->sk_drops));
102323+ atomic_read_unchecked(&sp->sk_drops));
102324 }
102325
102326 static int ping_v4_seq_show(struct seq_file *seq, void *v)
102327diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
102328index 739db31..74f0210 100644
102329--- a/net/ipv4/raw.c
102330+++ b/net/ipv4/raw.c
102331@@ -314,7 +314,7 @@ static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
102332 int raw_rcv(struct sock *sk, struct sk_buff *skb)
102333 {
102334 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
102335- atomic_inc(&sk->sk_drops);
102336+ atomic_inc_unchecked(&sk->sk_drops);
102337 kfree_skb(skb);
102338 return NET_RX_DROP;
102339 }
102340@@ -755,16 +755,20 @@ static int raw_init(struct sock *sk)
102341
102342 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
102343 {
102344+ struct icmp_filter filter;
102345+
102346 if (optlen > sizeof(struct icmp_filter))
102347 optlen = sizeof(struct icmp_filter);
102348- if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
102349+ if (copy_from_user(&filter, optval, optlen))
102350 return -EFAULT;
102351+ raw_sk(sk)->filter = filter;
102352 return 0;
102353 }
102354
102355 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
102356 {
102357 int len, ret = -EFAULT;
102358+ struct icmp_filter filter;
102359
102360 if (get_user(len, optlen))
102361 goto out;
102362@@ -774,8 +778,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
102363 if (len > sizeof(struct icmp_filter))
102364 len = sizeof(struct icmp_filter);
102365 ret = -EFAULT;
102366- if (put_user(len, optlen) ||
102367- copy_to_user(optval, &raw_sk(sk)->filter, len))
102368+ filter = raw_sk(sk)->filter;
102369+ if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
102370 goto out;
102371 ret = 0;
102372 out: return ret;
102373@@ -1004,7 +1008,7 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
102374 0, 0L, 0,
102375 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
102376 0, sock_i_ino(sp),
102377- atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
102378+ atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
102379 }
102380
102381 static int raw_seq_show(struct seq_file *seq, void *v)
102382diff --git a/net/ipv4/route.c b/net/ipv4/route.c
102383index 6a2155b..d426880 100644
102384--- a/net/ipv4/route.c
102385+++ b/net/ipv4/route.c
102386@@ -228,7 +228,7 @@ static const struct seq_operations rt_cache_seq_ops = {
102387
102388 static int rt_cache_seq_open(struct inode *inode, struct file *file)
102389 {
102390- return seq_open(file, &rt_cache_seq_ops);
102391+ return seq_open_restrict(file, &rt_cache_seq_ops);
102392 }
102393
102394 static const struct file_operations rt_cache_seq_fops = {
102395@@ -319,7 +319,7 @@ static const struct seq_operations rt_cpu_seq_ops = {
102396
102397 static int rt_cpu_seq_open(struct inode *inode, struct file *file)
102398 {
102399- return seq_open(file, &rt_cpu_seq_ops);
102400+ return seq_open_restrict(file, &rt_cpu_seq_ops);
102401 }
102402
102403 static const struct file_operations rt_cpu_seq_fops = {
102404@@ -357,7 +357,7 @@ static int rt_acct_proc_show(struct seq_file *m, void *v)
102405
102406 static int rt_acct_proc_open(struct inode *inode, struct file *file)
102407 {
102408- return single_open(file, rt_acct_proc_show, NULL);
102409+ return single_open_restrict(file, rt_acct_proc_show, NULL);
102410 }
102411
102412 static const struct file_operations rt_acct_proc_fops = {
102413@@ -459,11 +459,11 @@ static struct neighbour *ipv4_neigh_lookup(const struct dst_entry *dst,
102414
102415 #define IP_IDENTS_SZ 2048u
102416 struct ip_ident_bucket {
102417- atomic_t id;
102418+ atomic_unchecked_t id;
102419 u32 stamp32;
102420 };
102421
102422-static struct ip_ident_bucket *ip_idents __read_mostly;
102423+static struct ip_ident_bucket ip_idents[IP_IDENTS_SZ] __read_mostly;
102424
102425 /* In order to protect privacy, we add a perturbation to identifiers
102426 * if one generator is seldom used. This makes hard for an attacker
102427@@ -479,7 +479,7 @@ u32 ip_idents_reserve(u32 hash, int segs)
102428 if (old != now && cmpxchg(&bucket->stamp32, old, now) == old)
102429 delta = prandom_u32_max(now - old);
102430
102431- return atomic_add_return(segs + delta, &bucket->id) - segs;
102432+ return atomic_add_return_unchecked(segs + delta, &bucket->id) - segs;
102433 }
102434 EXPORT_SYMBOL(ip_idents_reserve);
102435
102436@@ -2624,34 +2624,34 @@ static struct ctl_table ipv4_route_flush_table[] = {
102437 .maxlen = sizeof(int),
102438 .mode = 0200,
102439 .proc_handler = ipv4_sysctl_rtcache_flush,
102440+ .extra1 = &init_net,
102441 },
102442 { },
102443 };
102444
102445 static __net_init int sysctl_route_net_init(struct net *net)
102446 {
102447- struct ctl_table *tbl;
102448+ ctl_table_no_const *tbl = NULL;
102449
102450- tbl = ipv4_route_flush_table;
102451 if (!net_eq(net, &init_net)) {
102452- tbl = kmemdup(tbl, sizeof(ipv4_route_flush_table), GFP_KERNEL);
102453+ tbl = kmemdup(ipv4_route_flush_table, sizeof(ipv4_route_flush_table), GFP_KERNEL);
102454 if (tbl == NULL)
102455 goto err_dup;
102456
102457 /* Don't export sysctls to unprivileged users */
102458 if (net->user_ns != &init_user_ns)
102459 tbl[0].procname = NULL;
102460- }
102461- tbl[0].extra1 = net;
102462+ tbl[0].extra1 = net;
102463+ net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
102464+ } else
102465+ net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", ipv4_route_flush_table);
102466
102467- net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
102468 if (net->ipv4.route_hdr == NULL)
102469 goto err_reg;
102470 return 0;
102471
102472 err_reg:
102473- if (tbl != ipv4_route_flush_table)
102474- kfree(tbl);
102475+ kfree(tbl);
102476 err_dup:
102477 return -ENOMEM;
102478 }
102479@@ -2674,8 +2674,8 @@ static __net_initdata struct pernet_operations sysctl_route_ops = {
102480
102481 static __net_init int rt_genid_init(struct net *net)
102482 {
102483- atomic_set(&net->ipv4.rt_genid, 0);
102484- atomic_set(&net->fnhe_genid, 0);
102485+ atomic_set_unchecked(&net->ipv4.rt_genid, 0);
102486+ atomic_set_unchecked(&net->fnhe_genid, 0);
102487 get_random_bytes(&net->ipv4.dev_addr_genid,
102488 sizeof(net->ipv4.dev_addr_genid));
102489 return 0;
102490@@ -2718,11 +2718,7 @@ int __init ip_rt_init(void)
102491 {
102492 int rc = 0;
102493
102494- ip_idents = kmalloc(IP_IDENTS_SZ * sizeof(*ip_idents), GFP_KERNEL);
102495- if (!ip_idents)
102496- panic("IP: failed to allocate ip_idents\n");
102497-
102498- prandom_bytes(ip_idents, IP_IDENTS_SZ * sizeof(*ip_idents));
102499+ prandom_bytes(ip_idents, sizeof(ip_idents));
102500
102501 #ifdef CONFIG_IP_ROUTE_CLASSID
102502 ip_rt_acct = __alloc_percpu(256 * sizeof(struct ip_rt_acct), __alignof__(struct ip_rt_acct));
102503diff --git a/net/ipv4/sysctl_net_ipv4.c b/net/ipv4/sysctl_net_ipv4.c
102504index b3c53c8..35cc18d 100644
102505--- a/net/ipv4/sysctl_net_ipv4.c
102506+++ b/net/ipv4/sysctl_net_ipv4.c
102507@@ -60,7 +60,7 @@ static int ipv4_local_port_range(struct ctl_table *table, int write,
102508 container_of(table->data, struct net, ipv4.ip_local_ports.range);
102509 int ret;
102510 int range[2];
102511- struct ctl_table tmp = {
102512+ ctl_table_no_const tmp = {
102513 .data = &range,
102514 .maxlen = sizeof(range),
102515 .mode = table->mode,
102516@@ -118,7 +118,7 @@ static int ipv4_ping_group_range(struct ctl_table *table, int write,
102517 int ret;
102518 gid_t urange[2];
102519 kgid_t low, high;
102520- struct ctl_table tmp = {
102521+ ctl_table_no_const tmp = {
102522 .data = &urange,
102523 .maxlen = sizeof(urange),
102524 .mode = table->mode,
102525@@ -149,7 +149,7 @@ static int proc_tcp_congestion_control(struct ctl_table *ctl, int write,
102526 void __user *buffer, size_t *lenp, loff_t *ppos)
102527 {
102528 char val[TCP_CA_NAME_MAX];
102529- struct ctl_table tbl = {
102530+ ctl_table_no_const tbl = {
102531 .data = val,
102532 .maxlen = TCP_CA_NAME_MAX,
102533 };
102534@@ -168,7 +168,7 @@ static int proc_tcp_available_congestion_control(struct ctl_table *ctl,
102535 void __user *buffer, size_t *lenp,
102536 loff_t *ppos)
102537 {
102538- struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX, };
102539+ ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX, };
102540 int ret;
102541
102542 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
102543@@ -185,7 +185,7 @@ static int proc_allowed_congestion_control(struct ctl_table *ctl,
102544 void __user *buffer, size_t *lenp,
102545 loff_t *ppos)
102546 {
102547- struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX };
102548+ ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX };
102549 int ret;
102550
102551 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
102552@@ -204,7 +204,7 @@ static int proc_tcp_fastopen_key(struct ctl_table *ctl, int write,
102553 void __user *buffer, size_t *lenp,
102554 loff_t *ppos)
102555 {
102556- struct ctl_table tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
102557+ ctl_table_no_const tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
102558 struct tcp_fastopen_context *ctxt;
102559 int ret;
102560 u32 user_key[4]; /* 16 bytes, matching TCP_FASTOPEN_KEY_LENGTH */
102561@@ -874,13 +874,12 @@ static struct ctl_table ipv4_net_table[] = {
102562
102563 static __net_init int ipv4_sysctl_init_net(struct net *net)
102564 {
102565- struct ctl_table *table;
102566+ ctl_table_no_const *table = NULL;
102567
102568- table = ipv4_net_table;
102569 if (!net_eq(net, &init_net)) {
102570 int i;
102571
102572- table = kmemdup(table, sizeof(ipv4_net_table), GFP_KERNEL);
102573+ table = kmemdup(ipv4_net_table, sizeof(ipv4_net_table), GFP_KERNEL);
102574 if (table == NULL)
102575 goto err_alloc;
102576
102577@@ -889,7 +888,10 @@ static __net_init int ipv4_sysctl_init_net(struct net *net)
102578 table[i].data += (void *)net - (void *)&init_net;
102579 }
102580
102581- net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
102582+ if (!net_eq(net, &init_net))
102583+ net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
102584+ else
102585+ net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", ipv4_net_table);
102586 if (net->ipv4.ipv4_hdr == NULL)
102587 goto err_reg;
102588
102589diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
102590index d107ee2..bcebf11 100644
102591--- a/net/ipv4/tcp_input.c
102592+++ b/net/ipv4/tcp_input.c
102593@@ -765,7 +765,7 @@ static void tcp_update_pacing_rate(struct sock *sk)
102594 * without any lock. We want to make sure compiler wont store
102595 * intermediate values in this location.
102596 */
102597- ACCESS_ONCE(sk->sk_pacing_rate) = min_t(u64, rate,
102598+ ACCESS_ONCE_RW(sk->sk_pacing_rate) = min_t(u64, rate,
102599 sk->sk_max_pacing_rate);
102600 }
102601
102602@@ -4527,7 +4527,7 @@ static struct sk_buff *tcp_collapse_one(struct sock *sk, struct sk_buff *skb,
102603 * simplifies code)
102604 */
102605 static void
102606-tcp_collapse(struct sock *sk, struct sk_buff_head *list,
102607+__intentional_overflow(5,6) tcp_collapse(struct sock *sk, struct sk_buff_head *list,
102608 struct sk_buff *head, struct sk_buff *tail,
102609 u32 start, u32 end)
102610 {
102611@@ -5506,6 +5506,7 @@ discard:
102612 tcp_paws_reject(&tp->rx_opt, 0))
102613 goto discard_and_undo;
102614
102615+#ifndef CONFIG_GRKERNSEC_NO_SIMULT_CONNECT
102616 if (th->syn) {
102617 /* We see SYN without ACK. It is attempt of
102618 * simultaneous connect with crossed SYNs.
102619@@ -5556,6 +5557,7 @@ discard:
102620 goto discard;
102621 #endif
102622 }
102623+#endif
102624 /* "fifth, if neither of the SYN or RST bits is set then
102625 * drop the segment and return."
102626 */
102627@@ -5602,7 +5604,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
102628 goto discard;
102629
102630 if (th->syn) {
102631- if (th->fin)
102632+ if (th->fin || th->urg || th->psh)
102633 goto discard;
102634 if (icsk->icsk_af_ops->conn_request(sk, skb) < 0)
102635 return 1;
102636diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
102637index ef7089c..a3e65fb 100644
102638--- a/net/ipv4/tcp_ipv4.c
102639+++ b/net/ipv4/tcp_ipv4.c
102640@@ -89,6 +89,10 @@ int sysctl_tcp_tw_reuse __read_mostly;
102641 int sysctl_tcp_low_latency __read_mostly;
102642 EXPORT_SYMBOL(sysctl_tcp_low_latency);
102643
102644+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
102645+extern int grsec_enable_blackhole;
102646+#endif
102647+
102648 #ifdef CONFIG_TCP_MD5SIG
102649 static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key,
102650 __be32 daddr, __be32 saddr, const struct tcphdr *th);
102651@@ -1469,6 +1473,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
102652 return 0;
102653
102654 reset:
102655+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
102656+ if (!grsec_enable_blackhole)
102657+#endif
102658 tcp_v4_send_reset(rsk, skb);
102659 discard:
102660 kfree_skb(skb);
102661@@ -1633,12 +1640,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
102662 TCP_SKB_CB(skb)->sacked = 0;
102663
102664 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
102665- if (!sk)
102666+ if (!sk) {
102667+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
102668+ ret = 1;
102669+#endif
102670 goto no_tcp_socket;
102671-
102672+ }
102673 process:
102674- if (sk->sk_state == TCP_TIME_WAIT)
102675+ if (sk->sk_state == TCP_TIME_WAIT) {
102676+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
102677+ ret = 2;
102678+#endif
102679 goto do_time_wait;
102680+ }
102681
102682 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
102683 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
102684@@ -1694,6 +1708,10 @@ csum_error:
102685 bad_packet:
102686 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
102687 } else {
102688+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
102689+ if (!grsec_enable_blackhole || (ret == 1 &&
102690+ (skb->dev->flags & IFF_LOOPBACK)))
102691+#endif
102692 tcp_v4_send_reset(NULL, skb);
102693 }
102694
102695diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
102696index 63d2680..2db9d6b 100644
102697--- a/net/ipv4/tcp_minisocks.c
102698+++ b/net/ipv4/tcp_minisocks.c
102699@@ -27,6 +27,10 @@
102700 #include <net/inet_common.h>
102701 #include <net/xfrm.h>
102702
102703+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
102704+extern int grsec_enable_blackhole;
102705+#endif
102706+
102707 int sysctl_tcp_syncookies __read_mostly = 1;
102708 EXPORT_SYMBOL(sysctl_tcp_syncookies);
102709
102710@@ -739,7 +743,10 @@ embryonic_reset:
102711 * avoid becoming vulnerable to outside attack aiming at
102712 * resetting legit local connections.
102713 */
102714- req->rsk_ops->send_reset(sk, skb);
102715+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
102716+ if (!grsec_enable_blackhole)
102717+#endif
102718+ req->rsk_ops->send_reset(sk, skb);
102719 } else if (fastopen) { /* received a valid RST pkt */
102720 reqsk_fastopen_remove(sk, req, true);
102721 tcp_reset(sk);
102722diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
102723index ebf5ff5..4d1ff32 100644
102724--- a/net/ipv4/tcp_probe.c
102725+++ b/net/ipv4/tcp_probe.c
102726@@ -236,7 +236,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
102727 if (cnt + width >= len)
102728 break;
102729
102730- if (copy_to_user(buf + cnt, tbuf, width))
102731+ if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
102732 return -EFAULT;
102733 cnt += width;
102734 }
102735diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
102736index 9b21ae8..4eb67df 100644
102737--- a/net/ipv4/tcp_timer.c
102738+++ b/net/ipv4/tcp_timer.c
102739@@ -22,6 +22,10 @@
102740 #include <linux/gfp.h>
102741 #include <net/tcp.h>
102742
102743+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
102744+extern int grsec_lastack_retries;
102745+#endif
102746+
102747 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
102748 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
102749 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
102750@@ -191,6 +195,13 @@ static int tcp_write_timeout(struct sock *sk)
102751 }
102752 }
102753
102754+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
102755+ if ((sk->sk_state == TCP_LAST_ACK) &&
102756+ (grsec_lastack_retries > 0) &&
102757+ (grsec_lastack_retries < retry_until))
102758+ retry_until = grsec_lastack_retries;
102759+#endif
102760+
102761 if (retransmits_timed_out(sk, retry_until,
102762 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
102763 /* Has it gone just too far? */
102764diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
102765index cd0db54..93a6518 100644
102766--- a/net/ipv4/udp.c
102767+++ b/net/ipv4/udp.c
102768@@ -87,6 +87,7 @@
102769 #include <linux/types.h>
102770 #include <linux/fcntl.h>
102771 #include <linux/module.h>
102772+#include <linux/security.h>
102773 #include <linux/socket.h>
102774 #include <linux/sockios.h>
102775 #include <linux/igmp.h>
102776@@ -114,6 +115,10 @@
102777 #include <net/busy_poll.h>
102778 #include "udp_impl.h"
102779
102780+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
102781+extern int grsec_enable_blackhole;
102782+#endif
102783+
102784 struct udp_table udp_table __read_mostly;
102785 EXPORT_SYMBOL(udp_table);
102786
102787@@ -595,6 +600,9 @@ static inline bool __udp_is_mcast_sock(struct net *net, struct sock *sk,
102788 return true;
102789 }
102790
102791+extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
102792+extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
102793+
102794 /*
102795 * This routine is called by the ICMP module when it gets some
102796 * sort of error condition. If err < 0 then the socket should
102797@@ -932,9 +940,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
102798 dport = usin->sin_port;
102799 if (dport == 0)
102800 return -EINVAL;
102801+
102802+ err = gr_search_udp_sendmsg(sk, usin);
102803+ if (err)
102804+ return err;
102805 } else {
102806 if (sk->sk_state != TCP_ESTABLISHED)
102807 return -EDESTADDRREQ;
102808+
102809+ err = gr_search_udp_sendmsg(sk, NULL);
102810+ if (err)
102811+ return err;
102812+
102813 daddr = inet->inet_daddr;
102814 dport = inet->inet_dport;
102815 /* Open fast path for connected socket.
102816@@ -1182,7 +1199,7 @@ static unsigned int first_packet_length(struct sock *sk)
102817 IS_UDPLITE(sk));
102818 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
102819 IS_UDPLITE(sk));
102820- atomic_inc(&sk->sk_drops);
102821+ atomic_inc_unchecked(&sk->sk_drops);
102822 __skb_unlink(skb, rcvq);
102823 __skb_queue_tail(&list_kill, skb);
102824 }
102825@@ -1262,6 +1279,10 @@ try_again:
102826 if (!skb)
102827 goto out;
102828
102829+ err = gr_search_udp_recvmsg(sk, skb);
102830+ if (err)
102831+ goto out_free;
102832+
102833 ulen = skb->len - sizeof(struct udphdr);
102834 copied = len;
102835 if (copied > ulen)
102836@@ -1295,7 +1316,7 @@ try_again:
102837 if (unlikely(err)) {
102838 trace_kfree_skb(skb, udp_recvmsg);
102839 if (!peeked) {
102840- atomic_inc(&sk->sk_drops);
102841+ atomic_inc_unchecked(&sk->sk_drops);
102842 UDP_INC_STATS_USER(sock_net(sk),
102843 UDP_MIB_INERRORS, is_udplite);
102844 }
102845@@ -1592,7 +1613,7 @@ csum_error:
102846 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
102847 drop:
102848 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
102849- atomic_inc(&sk->sk_drops);
102850+ atomic_inc_unchecked(&sk->sk_drops);
102851 kfree_skb(skb);
102852 return -1;
102853 }
102854@@ -1611,7 +1632,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
102855 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
102856
102857 if (!skb1) {
102858- atomic_inc(&sk->sk_drops);
102859+ atomic_inc_unchecked(&sk->sk_drops);
102860 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
102861 IS_UDPLITE(sk));
102862 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
102863@@ -1812,6 +1833,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
102864 goto csum_error;
102865
102866 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
102867+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
102868+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
102869+#endif
102870 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
102871
102872 /*
102873@@ -2398,7 +2422,7 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
102874 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
102875 0, sock_i_ino(sp),
102876 atomic_read(&sp->sk_refcnt), sp,
102877- atomic_read(&sp->sk_drops));
102878+ atomic_read_unchecked(&sp->sk_drops));
102879 }
102880
102881 int udp4_seq_show(struct seq_file *seq, void *v)
102882diff --git a/net/ipv4/xfrm4_policy.c b/net/ipv4/xfrm4_policy.c
102883index 6156f68..d6ab46d 100644
102884--- a/net/ipv4/xfrm4_policy.c
102885+++ b/net/ipv4/xfrm4_policy.c
102886@@ -186,11 +186,11 @@ _decode_session4(struct sk_buff *skb, struct flowi *fl, int reverse)
102887 fl4->flowi4_tos = iph->tos;
102888 }
102889
102890-static inline int xfrm4_garbage_collect(struct dst_ops *ops)
102891+static int xfrm4_garbage_collect(struct dst_ops *ops)
102892 {
102893 struct net *net = container_of(ops, struct net, xfrm.xfrm4_dst_ops);
102894
102895- xfrm4_policy_afinfo.garbage_collect(net);
102896+ xfrm_garbage_collect_deferred(net);
102897 return (dst_entries_get_slow(ops) > ops->gc_thresh * 2);
102898 }
102899
102900@@ -269,19 +269,18 @@ static struct ctl_table xfrm4_policy_table[] = {
102901
102902 static int __net_init xfrm4_net_init(struct net *net)
102903 {
102904- struct ctl_table *table;
102905+ ctl_table_no_const *table = NULL;
102906 struct ctl_table_header *hdr;
102907
102908- table = xfrm4_policy_table;
102909 if (!net_eq(net, &init_net)) {
102910- table = kmemdup(table, sizeof(xfrm4_policy_table), GFP_KERNEL);
102911+ table = kmemdup(xfrm4_policy_table, sizeof(xfrm4_policy_table), GFP_KERNEL);
102912 if (!table)
102913 goto err_alloc;
102914
102915 table[0].data = &net->xfrm.xfrm4_dst_ops.gc_thresh;
102916- }
102917-
102918- hdr = register_net_sysctl(net, "net/ipv4", table);
102919+ hdr = register_net_sysctl(net, "net/ipv4", table);
102920+ } else
102921+ hdr = register_net_sysctl(net, "net/ipv4", xfrm4_policy_table);
102922 if (!hdr)
102923 goto err_reg;
102924
102925@@ -289,8 +288,7 @@ static int __net_init xfrm4_net_init(struct net *net)
102926 return 0;
102927
102928 err_reg:
102929- if (!net_eq(net, &init_net))
102930- kfree(table);
102931+ kfree(table);
102932 err_alloc:
102933 return -ENOMEM;
102934 }
102935diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
102936index 0169ccf..50d7b04 100644
102937--- a/net/ipv6/addrconf.c
102938+++ b/net/ipv6/addrconf.c
102939@@ -171,7 +171,7 @@ static struct ipv6_devconf ipv6_devconf __read_mostly = {
102940 .hop_limit = IPV6_DEFAULT_HOPLIMIT,
102941 .mtu6 = IPV6_MIN_MTU,
102942 .accept_ra = 1,
102943- .accept_redirects = 1,
102944+ .accept_redirects = 0,
102945 .autoconf = 1,
102946 .force_mld_version = 0,
102947 .mldv1_unsolicited_report_interval = 10 * HZ,
102948@@ -208,7 +208,7 @@ static struct ipv6_devconf ipv6_devconf_dflt __read_mostly = {
102949 .hop_limit = IPV6_DEFAULT_HOPLIMIT,
102950 .mtu6 = IPV6_MIN_MTU,
102951 .accept_ra = 1,
102952- .accept_redirects = 1,
102953+ .accept_redirects = 0,
102954 .autoconf = 1,
102955 .force_mld_version = 0,
102956 .mldv1_unsolicited_report_interval = 10 * HZ,
102957@@ -604,7 +604,7 @@ static int inet6_netconf_dump_devconf(struct sk_buff *skb,
102958 idx = 0;
102959 head = &net->dev_index_head[h];
102960 rcu_read_lock();
102961- cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^
102962+ cb->seq = atomic_read_unchecked(&net->ipv6.dev_addr_genid) ^
102963 net->dev_base_seq;
102964 hlist_for_each_entry_rcu(dev, head, index_hlist) {
102965 if (idx < s_idx)
102966@@ -2396,7 +2396,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
102967 p.iph.ihl = 5;
102968 p.iph.protocol = IPPROTO_IPV6;
102969 p.iph.ttl = 64;
102970- ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
102971+ ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
102972
102973 if (ops->ndo_do_ioctl) {
102974 mm_segment_t oldfs = get_fs();
102975@@ -3534,16 +3534,23 @@ static const struct file_operations if6_fops = {
102976 .release = seq_release_net,
102977 };
102978
102979+extern void register_ipv6_seq_ops_addr(struct seq_operations *addr);
102980+extern void unregister_ipv6_seq_ops_addr(void);
102981+
102982 static int __net_init if6_proc_net_init(struct net *net)
102983 {
102984- if (!proc_create("if_inet6", S_IRUGO, net->proc_net, &if6_fops))
102985+ register_ipv6_seq_ops_addr(&if6_seq_ops);
102986+ if (!proc_create("if_inet6", S_IRUGO, net->proc_net, &if6_fops)) {
102987+ unregister_ipv6_seq_ops_addr();
102988 return -ENOMEM;
102989+ }
102990 return 0;
102991 }
102992
102993 static void __net_exit if6_proc_net_exit(struct net *net)
102994 {
102995 remove_proc_entry("if_inet6", net->proc_net);
102996+ unregister_ipv6_seq_ops_addr();
102997 }
102998
102999 static struct pernet_operations if6_proc_net_ops = {
103000@@ -4159,7 +4166,7 @@ static int inet6_dump_addr(struct sk_buff *skb, struct netlink_callback *cb,
103001 s_ip_idx = ip_idx = cb->args[2];
103002
103003 rcu_read_lock();
103004- cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
103005+ cb->seq = atomic_read_unchecked(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
103006 for (h = s_h; h < NETDEV_HASHENTRIES; h++, s_idx = 0) {
103007 idx = 0;
103008 head = &net->dev_index_head[h];
103009@@ -4788,7 +4795,7 @@ static void __ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)
103010 rt_genid_bump_ipv6(net);
103011 break;
103012 }
103013- atomic_inc(&net->ipv6.dev_addr_genid);
103014+ atomic_inc_unchecked(&net->ipv6.dev_addr_genid);
103015 }
103016
103017 static void ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)
103018@@ -4808,7 +4815,7 @@ int addrconf_sysctl_forward(struct ctl_table *ctl, int write,
103019 int *valp = ctl->data;
103020 int val = *valp;
103021 loff_t pos = *ppos;
103022- struct ctl_table lctl;
103023+ ctl_table_no_const lctl;
103024 int ret;
103025
103026 /*
103027@@ -4893,7 +4900,7 @@ int addrconf_sysctl_disable(struct ctl_table *ctl, int write,
103028 int *valp = ctl->data;
103029 int val = *valp;
103030 loff_t pos = *ppos;
103031- struct ctl_table lctl;
103032+ ctl_table_no_const lctl;
103033 int ret;
103034
103035 /*
103036diff --git a/net/ipv6/af_inet6.c b/net/ipv6/af_inet6.c
103037index e8c4400..a4cd5da 100644
103038--- a/net/ipv6/af_inet6.c
103039+++ b/net/ipv6/af_inet6.c
103040@@ -766,7 +766,7 @@ static int __net_init inet6_net_init(struct net *net)
103041 net->ipv6.sysctl.icmpv6_time = 1*HZ;
103042 net->ipv6.sysctl.flowlabel_consistency = 1;
103043 net->ipv6.sysctl.auto_flowlabels = 0;
103044- atomic_set(&net->ipv6.fib6_sernum, 1);
103045+ atomic_set_unchecked(&net->ipv6.fib6_sernum, 1);
103046
103047 err = ipv6_init_mibs(net);
103048 if (err)
103049diff --git a/net/ipv6/datagram.c b/net/ipv6/datagram.c
103050index 2cdc383..09cffb8 100644
103051--- a/net/ipv6/datagram.c
103052+++ b/net/ipv6/datagram.c
103053@@ -928,5 +928,5 @@ void ip6_dgram_sock_seq_show(struct seq_file *seq, struct sock *sp,
103054 0,
103055 sock_i_ino(sp),
103056 atomic_read(&sp->sk_refcnt), sp,
103057- atomic_read(&sp->sk_drops));
103058+ atomic_read_unchecked(&sp->sk_drops));
103059 }
103060diff --git a/net/ipv6/icmp.c b/net/ipv6/icmp.c
103061index 97ae700..18dcae0 100644
103062--- a/net/ipv6/icmp.c
103063+++ b/net/ipv6/icmp.c
103064@@ -997,7 +997,7 @@ static struct ctl_table ipv6_icmp_table_template[] = {
103065
103066 struct ctl_table * __net_init ipv6_icmp_sysctl_init(struct net *net)
103067 {
103068- struct ctl_table *table;
103069+ ctl_table_no_const *table;
103070
103071 table = kmemdup(ipv6_icmp_table_template,
103072 sizeof(ipv6_icmp_table_template),
103073diff --git a/net/ipv6/ip6_fib.c b/net/ipv6/ip6_fib.c
103074index b2d1838..0194c04 100644
103075--- a/net/ipv6/ip6_fib.c
103076+++ b/net/ipv6/ip6_fib.c
103077@@ -99,9 +99,9 @@ static int fib6_new_sernum(struct net *net)
103078 int new, old;
103079
103080 do {
103081- old = atomic_read(&net->ipv6.fib6_sernum);
103082+ old = atomic_read_unchecked(&net->ipv6.fib6_sernum);
103083 new = old < INT_MAX ? old + 1 : 1;
103084- } while (atomic_cmpxchg(&net->ipv6.fib6_sernum,
103085+ } while (atomic_cmpxchg_unchecked(&net->ipv6.fib6_sernum,
103086 old, new) != old);
103087 return new;
103088 }
103089diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
103090index 0e32d2e..98cbe65 100644
103091--- a/net/ipv6/ip6_gre.c
103092+++ b/net/ipv6/ip6_gre.c
103093@@ -71,8 +71,8 @@ struct ip6gre_net {
103094 struct net_device *fb_tunnel_dev;
103095 };
103096
103097-static struct rtnl_link_ops ip6gre_link_ops __read_mostly;
103098-static struct rtnl_link_ops ip6gre_tap_ops __read_mostly;
103099+static struct rtnl_link_ops ip6gre_link_ops;
103100+static struct rtnl_link_ops ip6gre_tap_ops;
103101 static int ip6gre_tunnel_init(struct net_device *dev);
103102 static void ip6gre_tunnel_setup(struct net_device *dev);
103103 static void ip6gre_tunnel_link(struct ip6gre_net *ign, struct ip6_tnl *t);
103104@@ -1289,7 +1289,7 @@ static void ip6gre_fb_tunnel_init(struct net_device *dev)
103105 }
103106
103107
103108-static struct inet6_protocol ip6gre_protocol __read_mostly = {
103109+static struct inet6_protocol ip6gre_protocol = {
103110 .handler = ip6gre_rcv,
103111 .err_handler = ip6gre_err,
103112 .flags = INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL,
103113@@ -1650,7 +1650,7 @@ static const struct nla_policy ip6gre_policy[IFLA_GRE_MAX + 1] = {
103114 [IFLA_GRE_FLAGS] = { .type = NLA_U32 },
103115 };
103116
103117-static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
103118+static struct rtnl_link_ops ip6gre_link_ops = {
103119 .kind = "ip6gre",
103120 .maxtype = IFLA_GRE_MAX,
103121 .policy = ip6gre_policy,
103122@@ -1664,7 +1664,7 @@ static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
103123 .fill_info = ip6gre_fill_info,
103124 };
103125
103126-static struct rtnl_link_ops ip6gre_tap_ops __read_mostly = {
103127+static struct rtnl_link_ops ip6gre_tap_ops = {
103128 .kind = "ip6gretap",
103129 .maxtype = IFLA_GRE_MAX,
103130 .policy = ip6gre_policy,
103131diff --git a/net/ipv6/ip6_tunnel.c b/net/ipv6/ip6_tunnel.c
103132index 9cb94cf..5678108 100644
103133--- a/net/ipv6/ip6_tunnel.c
103134+++ b/net/ipv6/ip6_tunnel.c
103135@@ -86,7 +86,7 @@ static u32 HASH(const struct in6_addr *addr1, const struct in6_addr *addr2)
103136
103137 static int ip6_tnl_dev_init(struct net_device *dev);
103138 static void ip6_tnl_dev_setup(struct net_device *dev);
103139-static struct rtnl_link_ops ip6_link_ops __read_mostly;
103140+static struct rtnl_link_ops ip6_link_ops;
103141
103142 static int ip6_tnl_net_id __read_mostly;
103143 struct ip6_tnl_net {
103144@@ -1706,7 +1706,7 @@ static const struct nla_policy ip6_tnl_policy[IFLA_IPTUN_MAX + 1] = {
103145 [IFLA_IPTUN_PROTO] = { .type = NLA_U8 },
103146 };
103147
103148-static struct rtnl_link_ops ip6_link_ops __read_mostly = {
103149+static struct rtnl_link_ops ip6_link_ops = {
103150 .kind = "ip6tnl",
103151 .maxtype = IFLA_IPTUN_MAX,
103152 .policy = ip6_tnl_policy,
103153diff --git a/net/ipv6/ip6_vti.c b/net/ipv6/ip6_vti.c
103154index bcda14d..49378c9 100644
103155--- a/net/ipv6/ip6_vti.c
103156+++ b/net/ipv6/ip6_vti.c
103157@@ -62,7 +62,7 @@ static u32 HASH(const struct in6_addr *addr1, const struct in6_addr *addr2)
103158
103159 static int vti6_dev_init(struct net_device *dev);
103160 static void vti6_dev_setup(struct net_device *dev);
103161-static struct rtnl_link_ops vti6_link_ops __read_mostly;
103162+static struct rtnl_link_ops vti6_link_ops;
103163
103164 static int vti6_net_id __read_mostly;
103165 struct vti6_net {
103166@@ -981,7 +981,7 @@ static const struct nla_policy vti6_policy[IFLA_VTI_MAX + 1] = {
103167 [IFLA_VTI_OKEY] = { .type = NLA_U32 },
103168 };
103169
103170-static struct rtnl_link_ops vti6_link_ops __read_mostly = {
103171+static struct rtnl_link_ops vti6_link_ops = {
103172 .kind = "vti6",
103173 .maxtype = IFLA_VTI_MAX,
103174 .policy = vti6_policy,
103175diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
103176index e1a9583..7dd8f4d 100644
103177--- a/net/ipv6/ipv6_sockglue.c
103178+++ b/net/ipv6/ipv6_sockglue.c
103179@@ -993,7 +993,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
103180 if (sk->sk_type != SOCK_STREAM)
103181 return -ENOPROTOOPT;
103182
103183- msg.msg_control = optval;
103184+ msg.msg_control = (void __force_kernel *)optval;
103185 msg.msg_controllen = len;
103186 msg.msg_flags = flags;
103187
103188diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
103189index e080fbb..412b3cf 100644
103190--- a/net/ipv6/netfilter/ip6_tables.c
103191+++ b/net/ipv6/netfilter/ip6_tables.c
103192@@ -1083,14 +1083,14 @@ static int compat_table_info(const struct xt_table_info *info,
103193 #endif
103194
103195 static int get_info(struct net *net, void __user *user,
103196- const int *len, int compat)
103197+ int len, int compat)
103198 {
103199 char name[XT_TABLE_MAXNAMELEN];
103200 struct xt_table *t;
103201 int ret;
103202
103203- if (*len != sizeof(struct ip6t_getinfo)) {
103204- duprintf("length %u != %zu\n", *len,
103205+ if (len != sizeof(struct ip6t_getinfo)) {
103206+ duprintf("length %u != %zu\n", len,
103207 sizeof(struct ip6t_getinfo));
103208 return -EINVAL;
103209 }
103210@@ -1127,7 +1127,7 @@ static int get_info(struct net *net, void __user *user,
103211 info.size = private->size;
103212 strcpy(info.name, name);
103213
103214- if (copy_to_user(user, &info, *len) != 0)
103215+ if (copy_to_user(user, &info, len) != 0)
103216 ret = -EFAULT;
103217 else
103218 ret = 0;
103219@@ -1983,7 +1983,7 @@ compat_do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
103220
103221 switch (cmd) {
103222 case IP6T_SO_GET_INFO:
103223- ret = get_info(sock_net(sk), user, len, 1);
103224+ ret = get_info(sock_net(sk), user, *len, 1);
103225 break;
103226 case IP6T_SO_GET_ENTRIES:
103227 ret = compat_get_entries(sock_net(sk), user, len);
103228@@ -2030,7 +2030,7 @@ do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
103229
103230 switch (cmd) {
103231 case IP6T_SO_GET_INFO:
103232- ret = get_info(sock_net(sk), user, len, 0);
103233+ ret = get_info(sock_net(sk), user, *len, 0);
103234 break;
103235
103236 case IP6T_SO_GET_ENTRIES:
103237diff --git a/net/ipv6/netfilter/nf_conntrack_reasm.c b/net/ipv6/netfilter/nf_conntrack_reasm.c
103238index 6f187c8..34b367f 100644
103239--- a/net/ipv6/netfilter/nf_conntrack_reasm.c
103240+++ b/net/ipv6/netfilter/nf_conntrack_reasm.c
103241@@ -96,12 +96,11 @@ static struct ctl_table nf_ct_frag6_sysctl_table[] = {
103242
103243 static int nf_ct_frag6_sysctl_register(struct net *net)
103244 {
103245- struct ctl_table *table;
103246+ ctl_table_no_const *table = NULL;
103247 struct ctl_table_header *hdr;
103248
103249- table = nf_ct_frag6_sysctl_table;
103250 if (!net_eq(net, &init_net)) {
103251- table = kmemdup(table, sizeof(nf_ct_frag6_sysctl_table),
103252+ table = kmemdup(nf_ct_frag6_sysctl_table, sizeof(nf_ct_frag6_sysctl_table),
103253 GFP_KERNEL);
103254 if (table == NULL)
103255 goto err_alloc;
103256@@ -112,9 +111,9 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
103257 table[2].data = &net->nf_frag.frags.high_thresh;
103258 table[2].extra1 = &net->nf_frag.frags.low_thresh;
103259 table[2].extra2 = &init_net.nf_frag.frags.high_thresh;
103260- }
103261-
103262- hdr = register_net_sysctl(net, "net/netfilter", table);
103263+ hdr = register_net_sysctl(net, "net/netfilter", table);
103264+ } else
103265+ hdr = register_net_sysctl(net, "net/netfilter", nf_ct_frag6_sysctl_table);
103266 if (hdr == NULL)
103267 goto err_reg;
103268
103269@@ -122,8 +121,7 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
103270 return 0;
103271
103272 err_reg:
103273- if (!net_eq(net, &init_net))
103274- kfree(table);
103275+ kfree(table);
103276 err_alloc:
103277 return -ENOMEM;
103278 }
103279diff --git a/net/ipv6/ping.c b/net/ipv6/ping.c
103280index 5b7a1ed..d9da205 100644
103281--- a/net/ipv6/ping.c
103282+++ b/net/ipv6/ping.c
103283@@ -240,6 +240,24 @@ static struct pernet_operations ping_v6_net_ops = {
103284 };
103285 #endif
103286
103287+static struct pingv6_ops real_pingv6_ops = {
103288+ .ipv6_recv_error = ipv6_recv_error,
103289+ .ip6_datagram_recv_common_ctl = ip6_datagram_recv_common_ctl,
103290+ .ip6_datagram_recv_specific_ctl = ip6_datagram_recv_specific_ctl,
103291+ .icmpv6_err_convert = icmpv6_err_convert,
103292+ .ipv6_icmp_error = ipv6_icmp_error,
103293+ .ipv6_chk_addr = ipv6_chk_addr,
103294+};
103295+
103296+static struct pingv6_ops dummy_pingv6_ops = {
103297+ .ipv6_recv_error = dummy_ipv6_recv_error,
103298+ .ip6_datagram_recv_common_ctl = dummy_ip6_datagram_recv_ctl,
103299+ .ip6_datagram_recv_specific_ctl = dummy_ip6_datagram_recv_ctl,
103300+ .icmpv6_err_convert = dummy_icmpv6_err_convert,
103301+ .ipv6_icmp_error = dummy_ipv6_icmp_error,
103302+ .ipv6_chk_addr = dummy_ipv6_chk_addr,
103303+};
103304+
103305 int __init pingv6_init(void)
103306 {
103307 #ifdef CONFIG_PROC_FS
103308@@ -247,13 +265,7 @@ int __init pingv6_init(void)
103309 if (ret)
103310 return ret;
103311 #endif
103312- pingv6_ops.ipv6_recv_error = ipv6_recv_error;
103313- pingv6_ops.ip6_datagram_recv_common_ctl = ip6_datagram_recv_common_ctl;
103314- pingv6_ops.ip6_datagram_recv_specific_ctl =
103315- ip6_datagram_recv_specific_ctl;
103316- pingv6_ops.icmpv6_err_convert = icmpv6_err_convert;
103317- pingv6_ops.ipv6_icmp_error = ipv6_icmp_error;
103318- pingv6_ops.ipv6_chk_addr = ipv6_chk_addr;
103319+ pingv6_ops = &real_pingv6_ops;
103320 return inet6_register_protosw(&pingv6_protosw);
103321 }
103322
103323@@ -262,14 +274,9 @@ int __init pingv6_init(void)
103324 */
103325 void pingv6_exit(void)
103326 {
103327- pingv6_ops.ipv6_recv_error = dummy_ipv6_recv_error;
103328- pingv6_ops.ip6_datagram_recv_common_ctl = dummy_ip6_datagram_recv_ctl;
103329- pingv6_ops.ip6_datagram_recv_specific_ctl = dummy_ip6_datagram_recv_ctl;
103330- pingv6_ops.icmpv6_err_convert = dummy_icmpv6_err_convert;
103331- pingv6_ops.ipv6_icmp_error = dummy_ipv6_icmp_error;
103332- pingv6_ops.ipv6_chk_addr = dummy_ipv6_chk_addr;
103333 #ifdef CONFIG_PROC_FS
103334 unregister_pernet_subsys(&ping_v6_net_ops);
103335 #endif
103336+ pingv6_ops = &dummy_pingv6_ops;
103337 inet6_unregister_protosw(&pingv6_protosw);
103338 }
103339diff --git a/net/ipv6/proc.c b/net/ipv6/proc.c
103340index 1752cd0..3c6af41 100644
103341--- a/net/ipv6/proc.c
103342+++ b/net/ipv6/proc.c
103343@@ -309,7 +309,7 @@ static int __net_init ipv6_proc_init_net(struct net *net)
103344 if (!proc_create("snmp6", S_IRUGO, net->proc_net, &snmp6_seq_fops))
103345 goto proc_snmp6_fail;
103346
103347- net->mib.proc_net_devsnmp6 = proc_mkdir("dev_snmp6", net->proc_net);
103348+ net->mib.proc_net_devsnmp6 = proc_mkdir_restrict("dev_snmp6", net->proc_net);
103349 if (!net->mib.proc_net_devsnmp6)
103350 goto proc_dev_snmp6_fail;
103351 return 0;
103352diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
103353index 896af88..6e2ba628 100644
103354--- a/net/ipv6/raw.c
103355+++ b/net/ipv6/raw.c
103356@@ -388,7 +388,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
103357 {
103358 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
103359 skb_checksum_complete(skb)) {
103360- atomic_inc(&sk->sk_drops);
103361+ atomic_inc_unchecked(&sk->sk_drops);
103362 kfree_skb(skb);
103363 return NET_RX_DROP;
103364 }
103365@@ -416,7 +416,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
103366 struct raw6_sock *rp = raw6_sk(sk);
103367
103368 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
103369- atomic_inc(&sk->sk_drops);
103370+ atomic_inc_unchecked(&sk->sk_drops);
103371 kfree_skb(skb);
103372 return NET_RX_DROP;
103373 }
103374@@ -440,7 +440,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
103375
103376 if (inet->hdrincl) {
103377 if (skb_checksum_complete(skb)) {
103378- atomic_inc(&sk->sk_drops);
103379+ atomic_inc_unchecked(&sk->sk_drops);
103380 kfree_skb(skb);
103381 return NET_RX_DROP;
103382 }
103383@@ -608,7 +608,7 @@ out:
103384 return err;
103385 }
103386
103387-static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
103388+static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
103389 struct flowi6 *fl6, struct dst_entry **dstp,
103390 unsigned int flags)
103391 {
103392@@ -914,12 +914,15 @@ do_confirm:
103393 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
103394 char __user *optval, int optlen)
103395 {
103396+ struct icmp6_filter filter;
103397+
103398 switch (optname) {
103399 case ICMPV6_FILTER:
103400 if (optlen > sizeof(struct icmp6_filter))
103401 optlen = sizeof(struct icmp6_filter);
103402- if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
103403+ if (copy_from_user(&filter, optval, optlen))
103404 return -EFAULT;
103405+ raw6_sk(sk)->filter = filter;
103406 return 0;
103407 default:
103408 return -ENOPROTOOPT;
103409@@ -932,6 +935,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
103410 char __user *optval, int __user *optlen)
103411 {
103412 int len;
103413+ struct icmp6_filter filter;
103414
103415 switch (optname) {
103416 case ICMPV6_FILTER:
103417@@ -943,7 +947,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
103418 len = sizeof(struct icmp6_filter);
103419 if (put_user(len, optlen))
103420 return -EFAULT;
103421- if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
103422+ filter = raw6_sk(sk)->filter;
103423+ if (len > sizeof filter || copy_to_user(optval, &filter, len))
103424 return -EFAULT;
103425 return 0;
103426 default:
103427diff --git a/net/ipv6/reassembly.c b/net/ipv6/reassembly.c
103428index 1a157ca..9fc05f4 100644
103429--- a/net/ipv6/reassembly.c
103430+++ b/net/ipv6/reassembly.c
103431@@ -625,12 +625,11 @@ static struct ctl_table ip6_frags_ctl_table[] = {
103432
103433 static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
103434 {
103435- struct ctl_table *table;
103436+ ctl_table_no_const *table = NULL;
103437 struct ctl_table_header *hdr;
103438
103439- table = ip6_frags_ns_ctl_table;
103440 if (!net_eq(net, &init_net)) {
103441- table = kmemdup(table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
103442+ table = kmemdup(ip6_frags_ns_ctl_table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
103443 if (table == NULL)
103444 goto err_alloc;
103445
103446@@ -644,9 +643,10 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
103447 /* Don't export sysctls to unprivileged users */
103448 if (net->user_ns != &init_user_ns)
103449 table[0].procname = NULL;
103450- }
103451+ hdr = register_net_sysctl(net, "net/ipv6", table);
103452+ } else
103453+ hdr = register_net_sysctl(net, "net/ipv6", ip6_frags_ns_ctl_table);
103454
103455- hdr = register_net_sysctl(net, "net/ipv6", table);
103456 if (hdr == NULL)
103457 goto err_reg;
103458
103459@@ -654,8 +654,7 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
103460 return 0;
103461
103462 err_reg:
103463- if (!net_eq(net, &init_net))
103464- kfree(table);
103465+ kfree(table);
103466 err_alloc:
103467 return -ENOMEM;
103468 }
103469diff --git a/net/ipv6/route.c b/net/ipv6/route.c
103470index a318dd89..7ecfea6 100644
103471--- a/net/ipv6/route.c
103472+++ b/net/ipv6/route.c
103473@@ -2965,7 +2965,7 @@ struct ctl_table ipv6_route_table_template[] = {
103474
103475 struct ctl_table * __net_init ipv6_route_sysctl_init(struct net *net)
103476 {
103477- struct ctl_table *table;
103478+ ctl_table_no_const *table;
103479
103480 table = kmemdup(ipv6_route_table_template,
103481 sizeof(ipv6_route_table_template),
103482diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c
103483index a24557a..00a9ed1 100644
103484--- a/net/ipv6/sit.c
103485+++ b/net/ipv6/sit.c
103486@@ -74,7 +74,7 @@ static void ipip6_tunnel_setup(struct net_device *dev);
103487 static void ipip6_dev_free(struct net_device *dev);
103488 static bool check_6rd(struct ip_tunnel *tunnel, const struct in6_addr *v6dst,
103489 __be32 *v4dst);
103490-static struct rtnl_link_ops sit_link_ops __read_mostly;
103491+static struct rtnl_link_ops sit_link_ops;
103492
103493 static int sit_net_id __read_mostly;
103494 struct sit_net {
103495@@ -1750,7 +1750,7 @@ static void ipip6_dellink(struct net_device *dev, struct list_head *head)
103496 unregister_netdevice_queue(dev, head);
103497 }
103498
103499-static struct rtnl_link_ops sit_link_ops __read_mostly = {
103500+static struct rtnl_link_ops sit_link_ops = {
103501 .kind = "sit",
103502 .maxtype = IFLA_IPTUN_MAX,
103503 .policy = ipip6_policy,
103504diff --git a/net/ipv6/sysctl_net_ipv6.c b/net/ipv6/sysctl_net_ipv6.c
103505index c5c10fa..2577d51 100644
103506--- a/net/ipv6/sysctl_net_ipv6.c
103507+++ b/net/ipv6/sysctl_net_ipv6.c
103508@@ -78,7 +78,7 @@ static struct ctl_table ipv6_rotable[] = {
103509
103510 static int __net_init ipv6_sysctl_net_init(struct net *net)
103511 {
103512- struct ctl_table *ipv6_table;
103513+ ctl_table_no_const *ipv6_table;
103514 struct ctl_table *ipv6_route_table;
103515 struct ctl_table *ipv6_icmp_table;
103516 int err;
103517diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
103518index c277951..c7ee5bf 100644
103519--- a/net/ipv6/tcp_ipv6.c
103520+++ b/net/ipv6/tcp_ipv6.c
103521@@ -104,6 +104,10 @@ static void inet6_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb)
103522 }
103523 }
103524
103525+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103526+extern int grsec_enable_blackhole;
103527+#endif
103528+
103529 static void tcp_v6_hash(struct sock *sk)
103530 {
103531 if (sk->sk_state != TCP_CLOSE) {
103532@@ -1341,6 +1345,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
103533 return 0;
103534
103535 reset:
103536+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103537+ if (!grsec_enable_blackhole)
103538+#endif
103539 tcp_v6_send_reset(sk, skb);
103540 discard:
103541 if (opt_skb)
103542@@ -1434,12 +1441,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
103543
103544 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest,
103545 tcp_v6_iif(skb));
103546- if (!sk)
103547+ if (!sk) {
103548+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103549+ ret = 1;
103550+#endif
103551 goto no_tcp_socket;
103552+ }
103553
103554 process:
103555- if (sk->sk_state == TCP_TIME_WAIT)
103556+ if (sk->sk_state == TCP_TIME_WAIT) {
103557+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103558+ ret = 2;
103559+#endif
103560 goto do_time_wait;
103561+ }
103562
103563 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
103564 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
103565@@ -1486,6 +1501,10 @@ csum_error:
103566 bad_packet:
103567 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
103568 } else {
103569+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103570+ if (!grsec_enable_blackhole || (ret == 1 &&
103571+ (skb->dev->flags & IFF_LOOPBACK)))
103572+#endif
103573 tcp_v6_send_reset(NULL, skb);
103574 }
103575
103576diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
103577index f6ba535..b41033f 100644
103578--- a/net/ipv6/udp.c
103579+++ b/net/ipv6/udp.c
103580@@ -76,6 +76,10 @@ static unsigned int udp6_ehashfn(struct net *net,
103581 udp_ipv6_hash_secret + net_hash_mix(net));
103582 }
103583
103584+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103585+extern int grsec_enable_blackhole;
103586+#endif
103587+
103588 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
103589 {
103590 const struct in6_addr *sk2_rcv_saddr6 = inet6_rcv_saddr(sk2);
103591@@ -434,7 +438,7 @@ try_again:
103592 if (unlikely(err)) {
103593 trace_kfree_skb(skb, udpv6_recvmsg);
103594 if (!peeked) {
103595- atomic_inc(&sk->sk_drops);
103596+ atomic_inc_unchecked(&sk->sk_drops);
103597 if (is_udp4)
103598 UDP_INC_STATS_USER(sock_net(sk),
103599 UDP_MIB_INERRORS,
103600@@ -701,7 +705,7 @@ csum_error:
103601 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
103602 drop:
103603 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
103604- atomic_inc(&sk->sk_drops);
103605+ atomic_inc_unchecked(&sk->sk_drops);
103606 kfree_skb(skb);
103607 return -1;
103608 }
103609@@ -740,7 +744,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
103610 if (likely(skb1 == NULL))
103611 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
103612 if (!skb1) {
103613- atomic_inc(&sk->sk_drops);
103614+ atomic_inc_unchecked(&sk->sk_drops);
103615 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
103616 IS_UDPLITE(sk));
103617 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
103618@@ -919,6 +923,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
103619 goto csum_error;
103620
103621 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
103622+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103623+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
103624+#endif
103625 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
103626
103627 kfree_skb(skb);
103628diff --git a/net/ipv6/xfrm6_policy.c b/net/ipv6/xfrm6_policy.c
103629index 5f98364..5ca982a 100644
103630--- a/net/ipv6/xfrm6_policy.c
103631+++ b/net/ipv6/xfrm6_policy.c
103632@@ -130,8 +130,8 @@ _decode_session6(struct sk_buff *skb, struct flowi *fl, int reverse)
103633 {
103634 struct flowi6 *fl6 = &fl->u.ip6;
103635 int onlyproto = 0;
103636- u16 offset = skb_network_header_len(skb);
103637 const struct ipv6hdr *hdr = ipv6_hdr(skb);
103638+ u16 offset = sizeof(*hdr);
103639 struct ipv6_opt_hdr *exthdr;
103640 const unsigned char *nh = skb_network_header(skb);
103641 u8 nexthdr = nh[IP6CB(skb)->nhoff];
103642@@ -217,11 +217,11 @@ _decode_session6(struct sk_buff *skb, struct flowi *fl, int reverse)
103643 }
103644 }
103645
103646-static inline int xfrm6_garbage_collect(struct dst_ops *ops)
103647+static int xfrm6_garbage_collect(struct dst_ops *ops)
103648 {
103649 struct net *net = container_of(ops, struct net, xfrm.xfrm6_dst_ops);
103650
103651- xfrm6_policy_afinfo.garbage_collect(net);
103652+ xfrm_garbage_collect_deferred(net);
103653 return dst_entries_get_fast(ops) > ops->gc_thresh * 2;
103654 }
103655
103656@@ -334,19 +334,19 @@ static struct ctl_table xfrm6_policy_table[] = {
103657
103658 static int __net_init xfrm6_net_init(struct net *net)
103659 {
103660- struct ctl_table *table;
103661+ ctl_table_no_const *table = NULL;
103662 struct ctl_table_header *hdr;
103663
103664- table = xfrm6_policy_table;
103665 if (!net_eq(net, &init_net)) {
103666- table = kmemdup(table, sizeof(xfrm6_policy_table), GFP_KERNEL);
103667+ table = kmemdup(xfrm6_policy_table, sizeof(xfrm6_policy_table), GFP_KERNEL);
103668 if (!table)
103669 goto err_alloc;
103670
103671 table[0].data = &net->xfrm.xfrm6_dst_ops.gc_thresh;
103672- }
103673+ hdr = register_net_sysctl(net, "net/ipv6", table);
103674+ } else
103675+ hdr = register_net_sysctl(net, "net/ipv6", xfrm6_policy_table);
103676
103677- hdr = register_net_sysctl(net, "net/ipv6", table);
103678 if (!hdr)
103679 goto err_reg;
103680
103681@@ -354,8 +354,7 @@ static int __net_init xfrm6_net_init(struct net *net)
103682 return 0;
103683
103684 err_reg:
103685- if (!net_eq(net, &init_net))
103686- kfree(table);
103687+ kfree(table);
103688 err_alloc:
103689 return -ENOMEM;
103690 }
103691diff --git a/net/ipx/ipx_proc.c b/net/ipx/ipx_proc.c
103692index e15c16a..7cf07aa 100644
103693--- a/net/ipx/ipx_proc.c
103694+++ b/net/ipx/ipx_proc.c
103695@@ -289,7 +289,7 @@ int __init ipx_proc_init(void)
103696 struct proc_dir_entry *p;
103697 int rc = -ENOMEM;
103698
103699- ipx_proc_dir = proc_mkdir("ipx", init_net.proc_net);
103700+ ipx_proc_dir = proc_mkdir_restrict("ipx", init_net.proc_net);
103701
103702 if (!ipx_proc_dir)
103703 goto out;
103704diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
103705index 61ceb4c..e788eb8 100644
103706--- a/net/irda/ircomm/ircomm_tty.c
103707+++ b/net/irda/ircomm/ircomm_tty.c
103708@@ -317,10 +317,10 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
103709 add_wait_queue(&port->open_wait, &wait);
103710
103711 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
103712- __FILE__, __LINE__, tty->driver->name, port->count);
103713+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
103714
103715 spin_lock_irqsave(&port->lock, flags);
103716- port->count--;
103717+ atomic_dec(&port->count);
103718 port->blocked_open++;
103719 spin_unlock_irqrestore(&port->lock, flags);
103720
103721@@ -355,7 +355,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
103722 }
103723
103724 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
103725- __FILE__, __LINE__, tty->driver->name, port->count);
103726+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
103727
103728 schedule();
103729 }
103730@@ -365,12 +365,12 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
103731
103732 spin_lock_irqsave(&port->lock, flags);
103733 if (!tty_hung_up_p(filp))
103734- port->count++;
103735+ atomic_inc(&port->count);
103736 port->blocked_open--;
103737 spin_unlock_irqrestore(&port->lock, flags);
103738
103739 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
103740- __FILE__, __LINE__, tty->driver->name, port->count);
103741+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
103742
103743 if (!retval)
103744 port->flags |= ASYNC_NORMAL_ACTIVE;
103745@@ -444,12 +444,12 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
103746
103747 /* ++ is not atomic, so this should be protected - Jean II */
103748 spin_lock_irqsave(&self->port.lock, flags);
103749- self->port.count++;
103750+ atomic_inc(&self->port.count);
103751 spin_unlock_irqrestore(&self->port.lock, flags);
103752 tty_port_tty_set(&self->port, tty);
103753
103754 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
103755- self->line, self->port.count);
103756+ self->line, atomic_read(&self->port.count));
103757
103758 /* Not really used by us, but lets do it anyway */
103759 self->port.low_latency = (self->port.flags & ASYNC_LOW_LATENCY) ? 1 : 0;
103760@@ -985,7 +985,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
103761 tty_kref_put(port->tty);
103762 }
103763 port->tty = NULL;
103764- port->count = 0;
103765+ atomic_set(&port->count, 0);
103766 spin_unlock_irqrestore(&port->lock, flags);
103767
103768 wake_up_interruptible(&port->open_wait);
103769@@ -1342,7 +1342,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
103770 seq_putc(m, '\n');
103771
103772 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
103773- seq_printf(m, "Open count: %d\n", self->port.count);
103774+ seq_printf(m, "Open count: %d\n", atomic_read(&self->port.count));
103775 seq_printf(m, "Max data size: %d\n", self->max_data_size);
103776 seq_printf(m, "Max header size: %d\n", self->max_header_size);
103777
103778diff --git a/net/irda/irproc.c b/net/irda/irproc.c
103779index b9ac598..f88cc56 100644
103780--- a/net/irda/irproc.c
103781+++ b/net/irda/irproc.c
103782@@ -66,7 +66,7 @@ void __init irda_proc_register(void)
103783 {
103784 int i;
103785
103786- proc_irda = proc_mkdir("irda", init_net.proc_net);
103787+ proc_irda = proc_mkdir_restrict("irda", init_net.proc_net);
103788 if (proc_irda == NULL)
103789 return;
103790
103791diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
103792index a089b6b..3ca3b60 100644
103793--- a/net/iucv/af_iucv.c
103794+++ b/net/iucv/af_iucv.c
103795@@ -686,10 +686,10 @@ static void __iucv_auto_name(struct iucv_sock *iucv)
103796 {
103797 char name[12];
103798
103799- sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
103800+ sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
103801 while (__iucv_get_sock_by_name(name)) {
103802 sprintf(name, "%08x",
103803- atomic_inc_return(&iucv_sk_list.autobind_name));
103804+ atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
103805 }
103806 memcpy(iucv->src_name, name, 8);
103807 }
103808diff --git a/net/iucv/iucv.c b/net/iucv/iucv.c
103809index 2a6a1fd..6c112b0 100644
103810--- a/net/iucv/iucv.c
103811+++ b/net/iucv/iucv.c
103812@@ -702,7 +702,7 @@ static int iucv_cpu_notify(struct notifier_block *self,
103813 return NOTIFY_OK;
103814 }
103815
103816-static struct notifier_block __refdata iucv_cpu_notifier = {
103817+static struct notifier_block iucv_cpu_notifier = {
103818 .notifier_call = iucv_cpu_notify,
103819 };
103820
103821diff --git a/net/key/af_key.c b/net/key/af_key.c
103822index 1847ec4..26ef732 100644
103823--- a/net/key/af_key.c
103824+++ b/net/key/af_key.c
103825@@ -3049,10 +3049,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
103826 static u32 get_acqseq(void)
103827 {
103828 u32 res;
103829- static atomic_t acqseq;
103830+ static atomic_unchecked_t acqseq;
103831
103832 do {
103833- res = atomic_inc_return(&acqseq);
103834+ res = atomic_inc_return_unchecked(&acqseq);
103835 } while (!res);
103836 return res;
103837 }
103838diff --git a/net/l2tp/l2tp_eth.c b/net/l2tp/l2tp_eth.c
103839index edb78e6..8dc654a 100644
103840--- a/net/l2tp/l2tp_eth.c
103841+++ b/net/l2tp/l2tp_eth.c
103842@@ -42,12 +42,12 @@ struct l2tp_eth {
103843 struct sock *tunnel_sock;
103844 struct l2tp_session *session;
103845 struct list_head list;
103846- atomic_long_t tx_bytes;
103847- atomic_long_t tx_packets;
103848- atomic_long_t tx_dropped;
103849- atomic_long_t rx_bytes;
103850- atomic_long_t rx_packets;
103851- atomic_long_t rx_errors;
103852+ atomic_long_unchecked_t tx_bytes;
103853+ atomic_long_unchecked_t tx_packets;
103854+ atomic_long_unchecked_t tx_dropped;
103855+ atomic_long_unchecked_t rx_bytes;
103856+ atomic_long_unchecked_t rx_packets;
103857+ atomic_long_unchecked_t rx_errors;
103858 };
103859
103860 /* via l2tp_session_priv() */
103861@@ -98,10 +98,10 @@ static int l2tp_eth_dev_xmit(struct sk_buff *skb, struct net_device *dev)
103862 int ret = l2tp_xmit_skb(session, skb, session->hdr_len);
103863
103864 if (likely(ret == NET_XMIT_SUCCESS)) {
103865- atomic_long_add(len, &priv->tx_bytes);
103866- atomic_long_inc(&priv->tx_packets);
103867+ atomic_long_add_unchecked(len, &priv->tx_bytes);
103868+ atomic_long_inc_unchecked(&priv->tx_packets);
103869 } else {
103870- atomic_long_inc(&priv->tx_dropped);
103871+ atomic_long_inc_unchecked(&priv->tx_dropped);
103872 }
103873 return NETDEV_TX_OK;
103874 }
103875@@ -111,12 +111,12 @@ static struct rtnl_link_stats64 *l2tp_eth_get_stats64(struct net_device *dev,
103876 {
103877 struct l2tp_eth *priv = netdev_priv(dev);
103878
103879- stats->tx_bytes = atomic_long_read(&priv->tx_bytes);
103880- stats->tx_packets = atomic_long_read(&priv->tx_packets);
103881- stats->tx_dropped = atomic_long_read(&priv->tx_dropped);
103882- stats->rx_bytes = atomic_long_read(&priv->rx_bytes);
103883- stats->rx_packets = atomic_long_read(&priv->rx_packets);
103884- stats->rx_errors = atomic_long_read(&priv->rx_errors);
103885+ stats->tx_bytes = atomic_long_read_unchecked(&priv->tx_bytes);
103886+ stats->tx_packets = atomic_long_read_unchecked(&priv->tx_packets);
103887+ stats->tx_dropped = atomic_long_read_unchecked(&priv->tx_dropped);
103888+ stats->rx_bytes = atomic_long_read_unchecked(&priv->rx_bytes);
103889+ stats->rx_packets = atomic_long_read_unchecked(&priv->rx_packets);
103890+ stats->rx_errors = atomic_long_read_unchecked(&priv->rx_errors);
103891 return stats;
103892 }
103893
103894@@ -166,15 +166,15 @@ static void l2tp_eth_dev_recv(struct l2tp_session *session, struct sk_buff *skb,
103895 nf_reset(skb);
103896
103897 if (dev_forward_skb(dev, skb) == NET_RX_SUCCESS) {
103898- atomic_long_inc(&priv->rx_packets);
103899- atomic_long_add(data_len, &priv->rx_bytes);
103900+ atomic_long_inc_unchecked(&priv->rx_packets);
103901+ atomic_long_add_unchecked(data_len, &priv->rx_bytes);
103902 } else {
103903- atomic_long_inc(&priv->rx_errors);
103904+ atomic_long_inc_unchecked(&priv->rx_errors);
103905 }
103906 return;
103907
103908 error:
103909- atomic_long_inc(&priv->rx_errors);
103910+ atomic_long_inc_unchecked(&priv->rx_errors);
103911 kfree_skb(skb);
103912 }
103913
103914diff --git a/net/llc/llc_proc.c b/net/llc/llc_proc.c
103915index 1a3c7e0..80f8b0c 100644
103916--- a/net/llc/llc_proc.c
103917+++ b/net/llc/llc_proc.c
103918@@ -247,7 +247,7 @@ int __init llc_proc_init(void)
103919 int rc = -ENOMEM;
103920 struct proc_dir_entry *p;
103921
103922- llc_proc_dir = proc_mkdir("llc", init_net.proc_net);
103923+ llc_proc_dir = proc_mkdir_restrict("llc", init_net.proc_net);
103924 if (!llc_proc_dir)
103925 goto out;
103926
103927diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
103928index 343da1e..509873f 100644
103929--- a/net/mac80211/cfg.c
103930+++ b/net/mac80211/cfg.c
103931@@ -541,7 +541,7 @@ static int ieee80211_set_monitor_channel(struct wiphy *wiphy,
103932 ret = ieee80211_vif_use_channel(sdata, chandef,
103933 IEEE80211_CHANCTX_EXCLUSIVE);
103934 }
103935- } else if (local->open_count == local->monitors) {
103936+ } else if (local_read(&local->open_count) == local->monitors) {
103937 local->_oper_chandef = *chandef;
103938 ieee80211_hw_config(local, 0);
103939 }
103940@@ -3326,7 +3326,7 @@ static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
103941 else
103942 local->probe_req_reg--;
103943
103944- if (!local->open_count)
103945+ if (!local_read(&local->open_count))
103946 break;
103947
103948 ieee80211_queue_work(&local->hw, &local->reconfig_filter);
103949@@ -3460,8 +3460,8 @@ static int ieee80211_cfg_get_channel(struct wiphy *wiphy,
103950 if (chanctx_conf) {
103951 *chandef = sdata->vif.bss_conf.chandef;
103952 ret = 0;
103953- } else if (local->open_count > 0 &&
103954- local->open_count == local->monitors &&
103955+ } else if (local_read(&local->open_count) > 0 &&
103956+ local_read(&local->open_count) == local->monitors &&
103957 sdata->vif.type == NL80211_IFTYPE_MONITOR) {
103958 if (local->use_chanctx)
103959 *chandef = local->monitor_chandef;
103960diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
103961index 8c68da3..0695016 100644
103962--- a/net/mac80211/ieee80211_i.h
103963+++ b/net/mac80211/ieee80211_i.h
103964@@ -29,6 +29,7 @@
103965 #include <net/ieee80211_radiotap.h>
103966 #include <net/cfg80211.h>
103967 #include <net/mac80211.h>
103968+#include <asm/local.h>
103969 #include "key.h"
103970 #include "sta_info.h"
103971 #include "debug.h"
103972@@ -1057,7 +1058,7 @@ struct ieee80211_local {
103973 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
103974 spinlock_t queue_stop_reason_lock;
103975
103976- int open_count;
103977+ local_t open_count;
103978 int monitors, cooked_mntrs;
103979 /* number of interfaces with corresponding FIF_ flags */
103980 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
103981diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
103982index eeae0ab..0f24585 100644
103983--- a/net/mac80211/iface.c
103984+++ b/net/mac80211/iface.c
103985@@ -533,7 +533,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
103986 break;
103987 }
103988
103989- if (local->open_count == 0) {
103990+ if (local_read(&local->open_count) == 0) {
103991 res = drv_start(local);
103992 if (res)
103993 goto err_del_bss;
103994@@ -580,7 +580,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
103995 res = drv_add_interface(local, sdata);
103996 if (res)
103997 goto err_stop;
103998- } else if (local->monitors == 0 && local->open_count == 0) {
103999+ } else if (local->monitors == 0 && local_read(&local->open_count) == 0) {
104000 res = ieee80211_add_virtual_monitor(local);
104001 if (res)
104002 goto err_stop;
104003@@ -689,7 +689,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
104004 atomic_inc(&local->iff_promiscs);
104005
104006 if (coming_up)
104007- local->open_count++;
104008+ local_inc(&local->open_count);
104009
104010 if (hw_reconf_flags)
104011 ieee80211_hw_config(local, hw_reconf_flags);
104012@@ -727,7 +727,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
104013 err_del_interface:
104014 drv_remove_interface(local, sdata);
104015 err_stop:
104016- if (!local->open_count)
104017+ if (!local_read(&local->open_count))
104018 drv_stop(local);
104019 err_del_bss:
104020 sdata->bss = NULL;
104021@@ -893,7 +893,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
104022 }
104023
104024 if (going_down)
104025- local->open_count--;
104026+ local_dec(&local->open_count);
104027
104028 switch (sdata->vif.type) {
104029 case NL80211_IFTYPE_AP_VLAN:
104030@@ -955,7 +955,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
104031 }
104032 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
104033
104034- if (local->open_count == 0)
104035+ if (local_read(&local->open_count) == 0)
104036 ieee80211_clear_tx_pending(local);
104037
104038 /*
104039@@ -998,7 +998,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
104040 if (cancel_scan)
104041 flush_delayed_work(&local->scan_work);
104042
104043- if (local->open_count == 0) {
104044+ if (local_read(&local->open_count) == 0) {
104045 ieee80211_stop_device(local);
104046
104047 /* no reconfiguring after stop! */
104048@@ -1009,7 +1009,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
104049 ieee80211_configure_filter(local);
104050 ieee80211_hw_config(local, hw_reconf_flags);
104051
104052- if (local->monitors == local->open_count)
104053+ if (local->monitors == local_read(&local->open_count))
104054 ieee80211_add_virtual_monitor(local);
104055 }
104056
104057diff --git a/net/mac80211/main.c b/net/mac80211/main.c
104058index 0de7c93..884b2ca 100644
104059--- a/net/mac80211/main.c
104060+++ b/net/mac80211/main.c
104061@@ -175,7 +175,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
104062 changed &= ~(IEEE80211_CONF_CHANGE_CHANNEL |
104063 IEEE80211_CONF_CHANGE_POWER);
104064
104065- if (changed && local->open_count) {
104066+ if (changed && local_read(&local->open_count)) {
104067 ret = drv_config(local, changed);
104068 /*
104069 * Goal:
104070diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
104071index 4c5192e..04cc0d8 100644
104072--- a/net/mac80211/pm.c
104073+++ b/net/mac80211/pm.c
104074@@ -12,7 +12,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
104075 struct ieee80211_sub_if_data *sdata;
104076 struct sta_info *sta;
104077
104078- if (!local->open_count)
104079+ if (!local_read(&local->open_count))
104080 goto suspend;
104081
104082 ieee80211_scan_cancel(local);
104083@@ -59,7 +59,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
104084 cancel_work_sync(&local->dynamic_ps_enable_work);
104085 del_timer_sync(&local->dynamic_ps_timer);
104086
104087- local->wowlan = wowlan && local->open_count;
104088+ local->wowlan = wowlan && local_read(&local->open_count);
104089 if (local->wowlan) {
104090 int err = drv_suspend(local, wowlan);
104091 if (err < 0) {
104092@@ -125,7 +125,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
104093 WARN_ON(!list_empty(&local->chanctx_list));
104094
104095 /* stop hardware - this must stop RX */
104096- if (local->open_count)
104097+ if (local_read(&local->open_count))
104098 ieee80211_stop_device(local);
104099
104100 suspend:
104101diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
104102index 6081329..ab23834 100644
104103--- a/net/mac80211/rate.c
104104+++ b/net/mac80211/rate.c
104105@@ -720,7 +720,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
104106
104107 ASSERT_RTNL();
104108
104109- if (local->open_count)
104110+ if (local_read(&local->open_count))
104111 return -EBUSY;
104112
104113 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
104114diff --git a/net/mac80211/util.c b/net/mac80211/util.c
104115index 3c61060..7bed2e3 100644
104116--- a/net/mac80211/util.c
104117+++ b/net/mac80211/util.c
104118@@ -1669,7 +1669,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
104119 }
104120 #endif
104121 /* everything else happens only if HW was up & running */
104122- if (!local->open_count)
104123+ if (!local_read(&local->open_count))
104124 goto wake_up;
104125
104126 /*
104127@@ -1895,7 +1895,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
104128 local->in_reconfig = false;
104129 barrier();
104130
104131- if (local->monitors == local->open_count && local->monitors > 0)
104132+ if (local->monitors == local_read(&local->open_count) && local->monitors > 0)
104133 ieee80211_add_virtual_monitor(local);
104134
104135 /*
104136diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
104137index ae5096ab..e5aa70a 100644
104138--- a/net/netfilter/Kconfig
104139+++ b/net/netfilter/Kconfig
104140@@ -1105,6 +1105,16 @@ config NETFILTER_XT_MATCH_ESP
104141
104142 To compile it as a module, choose M here. If unsure, say N.
104143
104144+config NETFILTER_XT_MATCH_GRADM
104145+ tristate '"gradm" match support'
104146+ depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
104147+ depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
104148+ ---help---
104149+ The gradm match allows to match on grsecurity RBAC being enabled.
104150+ It is useful when iptables rules are applied early on bootup to
104151+ prevent connections to the machine (except from a trusted host)
104152+ while the RBAC system is disabled.
104153+
104154 config NETFILTER_XT_MATCH_HASHLIMIT
104155 tristate '"hashlimit" match support'
104156 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
104157diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
104158index a9571be..c59e173 100644
104159--- a/net/netfilter/Makefile
104160+++ b/net/netfilter/Makefile
104161@@ -137,6 +137,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
104162 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
104163 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
104164 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
104165+obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
104166 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
104167 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
104168 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
104169diff --git a/net/netfilter/ipset/ip_set_core.c b/net/netfilter/ipset/ip_set_core.c
104170index d259da3..6a32b2c 100644
104171--- a/net/netfilter/ipset/ip_set_core.c
104172+++ b/net/netfilter/ipset/ip_set_core.c
104173@@ -1952,7 +1952,7 @@ done:
104174 return ret;
104175 }
104176
104177-static struct nf_sockopt_ops so_set __read_mostly = {
104178+static struct nf_sockopt_ops so_set = {
104179 .pf = PF_INET,
104180 .get_optmin = SO_IP_SET,
104181 .get_optmax = SO_IP_SET + 1,
104182diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
104183index b0f7b62..0541842 100644
104184--- a/net/netfilter/ipvs/ip_vs_conn.c
104185+++ b/net/netfilter/ipvs/ip_vs_conn.c
104186@@ -572,7 +572,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
104187 /* Increase the refcnt counter of the dest */
104188 ip_vs_dest_hold(dest);
104189
104190- conn_flags = atomic_read(&dest->conn_flags);
104191+ conn_flags = atomic_read_unchecked(&dest->conn_flags);
104192 if (cp->protocol != IPPROTO_UDP)
104193 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
104194 flags = cp->flags;
104195@@ -922,7 +922,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p, int dest_af,
104196
104197 cp->control = NULL;
104198 atomic_set(&cp->n_control, 0);
104199- atomic_set(&cp->in_pkts, 0);
104200+ atomic_set_unchecked(&cp->in_pkts, 0);
104201
104202 cp->packet_xmit = NULL;
104203 cp->app = NULL;
104204@@ -1229,7 +1229,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
104205
104206 /* Don't drop the entry if its number of incoming packets is not
104207 located in [0, 8] */
104208- i = atomic_read(&cp->in_pkts);
104209+ i = atomic_read_unchecked(&cp->in_pkts);
104210 if (i > 8 || i < 0) return 0;
104211
104212 if (!todrop_rate[i]) return 0;
104213diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
104214index 990decb..5075248 100644
104215--- a/net/netfilter/ipvs/ip_vs_core.c
104216+++ b/net/netfilter/ipvs/ip_vs_core.c
104217@@ -568,7 +568,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
104218 ret = cp->packet_xmit(skb, cp, pd->pp, iph);
104219 /* do not touch skb anymore */
104220
104221- atomic_inc(&cp->in_pkts);
104222+ atomic_inc_unchecked(&cp->in_pkts);
104223 ip_vs_conn_put(cp);
104224 return ret;
104225 }
104226@@ -1712,7 +1712,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
104227 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
104228 pkts = sysctl_sync_threshold(ipvs);
104229 else
104230- pkts = atomic_add_return(1, &cp->in_pkts);
104231+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
104232
104233 if (ipvs->sync_state & IP_VS_STATE_MASTER)
104234 ip_vs_sync_conn(net, cp, pkts);
104235diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
104236index ac7ba68..9735acb9 100644
104237--- a/net/netfilter/ipvs/ip_vs_ctl.c
104238+++ b/net/netfilter/ipvs/ip_vs_ctl.c
104239@@ -800,7 +800,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
104240 */
104241 ip_vs_rs_hash(ipvs, dest);
104242 }
104243- atomic_set(&dest->conn_flags, conn_flags);
104244+ atomic_set_unchecked(&dest->conn_flags, conn_flags);
104245
104246 /* bind the service */
104247 old_svc = rcu_dereference_protected(dest->svc, 1);
104248@@ -1665,7 +1665,7 @@ proc_do_sync_ports(struct ctl_table *table, int write,
104249 * align with netns init in ip_vs_control_net_init()
104250 */
104251
104252-static struct ctl_table vs_vars[] = {
104253+static ctl_table_no_const vs_vars[] __read_only = {
104254 {
104255 .procname = "amemthresh",
104256 .maxlen = sizeof(int),
104257@@ -2000,7 +2000,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
104258 " %-7s %-6d %-10d %-10d\n",
104259 &dest->addr.in6,
104260 ntohs(dest->port),
104261- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
104262+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
104263 atomic_read(&dest->weight),
104264 atomic_read(&dest->activeconns),
104265 atomic_read(&dest->inactconns));
104266@@ -2011,7 +2011,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
104267 "%-7s %-6d %-10d %-10d\n",
104268 ntohl(dest->addr.ip),
104269 ntohs(dest->port),
104270- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
104271+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
104272 atomic_read(&dest->weight),
104273 atomic_read(&dest->activeconns),
104274 atomic_read(&dest->inactconns));
104275@@ -2500,7 +2500,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
104276
104277 entry.addr = dest->addr.ip;
104278 entry.port = dest->port;
104279- entry.conn_flags = atomic_read(&dest->conn_flags);
104280+ entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
104281 entry.weight = atomic_read(&dest->weight);
104282 entry.u_threshold = dest->u_threshold;
104283 entry.l_threshold = dest->l_threshold;
104284@@ -3040,7 +3040,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
104285 if (nla_put(skb, IPVS_DEST_ATTR_ADDR, sizeof(dest->addr), &dest->addr) ||
104286 nla_put_be16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
104287 nla_put_u32(skb, IPVS_DEST_ATTR_FWD_METHOD,
104288- (atomic_read(&dest->conn_flags) &
104289+ (atomic_read_unchecked(&dest->conn_flags) &
104290 IP_VS_CONN_F_FWD_MASK)) ||
104291 nla_put_u32(skb, IPVS_DEST_ATTR_WEIGHT,
104292 atomic_read(&dest->weight)) ||
104293@@ -3673,7 +3673,7 @@ static int __net_init ip_vs_control_net_init_sysctl(struct net *net)
104294 {
104295 int idx;
104296 struct netns_ipvs *ipvs = net_ipvs(net);
104297- struct ctl_table *tbl;
104298+ ctl_table_no_const *tbl;
104299
104300 atomic_set(&ipvs->dropentry, 0);
104301 spin_lock_init(&ipvs->dropentry_lock);
104302diff --git a/net/netfilter/ipvs/ip_vs_lblc.c b/net/netfilter/ipvs/ip_vs_lblc.c
104303index 127f140..553d652 100644
104304--- a/net/netfilter/ipvs/ip_vs_lblc.c
104305+++ b/net/netfilter/ipvs/ip_vs_lblc.c
104306@@ -118,7 +118,7 @@ struct ip_vs_lblc_table {
104307 * IPVS LBLC sysctl table
104308 */
104309 #ifdef CONFIG_SYSCTL
104310-static struct ctl_table vs_vars_table[] = {
104311+static ctl_table_no_const vs_vars_table[] __read_only = {
104312 {
104313 .procname = "lblc_expiration",
104314 .data = NULL,
104315diff --git a/net/netfilter/ipvs/ip_vs_lblcr.c b/net/netfilter/ipvs/ip_vs_lblcr.c
104316index 2229d2d..b32b785 100644
104317--- a/net/netfilter/ipvs/ip_vs_lblcr.c
104318+++ b/net/netfilter/ipvs/ip_vs_lblcr.c
104319@@ -289,7 +289,7 @@ struct ip_vs_lblcr_table {
104320 * IPVS LBLCR sysctl table
104321 */
104322
104323-static struct ctl_table vs_vars_table[] = {
104324+static ctl_table_no_const vs_vars_table[] __read_only = {
104325 {
104326 .procname = "lblcr_expiration",
104327 .data = NULL,
104328diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
104329index 7162c86..9eeb60e 100644
104330--- a/net/netfilter/ipvs/ip_vs_sync.c
104331+++ b/net/netfilter/ipvs/ip_vs_sync.c
104332@@ -609,7 +609,7 @@ static void ip_vs_sync_conn_v0(struct net *net, struct ip_vs_conn *cp,
104333 cp = cp->control;
104334 if (cp) {
104335 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
104336- pkts = atomic_add_return(1, &cp->in_pkts);
104337+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
104338 else
104339 pkts = sysctl_sync_threshold(ipvs);
104340 ip_vs_sync_conn(net, cp->control, pkts);
104341@@ -771,7 +771,7 @@ control:
104342 if (!cp)
104343 return;
104344 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
104345- pkts = atomic_add_return(1, &cp->in_pkts);
104346+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
104347 else
104348 pkts = sysctl_sync_threshold(ipvs);
104349 goto sloop;
104350@@ -901,7 +901,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
104351
104352 if (opt)
104353 memcpy(&cp->in_seq, opt, sizeof(*opt));
104354- atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
104355+ atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
104356 cp->state = state;
104357 cp->old_state = cp->state;
104358 /*
104359diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
104360index bd90bf8..816a020d 100644
104361--- a/net/netfilter/ipvs/ip_vs_xmit.c
104362+++ b/net/netfilter/ipvs/ip_vs_xmit.c
104363@@ -1215,7 +1215,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
104364 else
104365 rc = NF_ACCEPT;
104366 /* do not touch skb anymore */
104367- atomic_inc(&cp->in_pkts);
104368+ atomic_inc_unchecked(&cp->in_pkts);
104369 goto out;
104370 }
104371
104372@@ -1308,7 +1308,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
104373 else
104374 rc = NF_ACCEPT;
104375 /* do not touch skb anymore */
104376- atomic_inc(&cp->in_pkts);
104377+ atomic_inc_unchecked(&cp->in_pkts);
104378 goto out;
104379 }
104380
104381diff --git a/net/netfilter/nf_conntrack_acct.c b/net/netfilter/nf_conntrack_acct.c
104382index a4b5e2a..13b1de3 100644
104383--- a/net/netfilter/nf_conntrack_acct.c
104384+++ b/net/netfilter/nf_conntrack_acct.c
104385@@ -62,7 +62,7 @@ static struct nf_ct_ext_type acct_extend __read_mostly = {
104386 #ifdef CONFIG_SYSCTL
104387 static int nf_conntrack_acct_init_sysctl(struct net *net)
104388 {
104389- struct ctl_table *table;
104390+ ctl_table_no_const *table;
104391
104392 table = kmemdup(acct_sysctl_table, sizeof(acct_sysctl_table),
104393 GFP_KERNEL);
104394diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
104395index 5016a69..594f8e9 100644
104396--- a/net/netfilter/nf_conntrack_core.c
104397+++ b/net/netfilter/nf_conntrack_core.c
104398@@ -1739,6 +1739,10 @@ void nf_conntrack_init_end(void)
104399 #define DYING_NULLS_VAL ((1<<30)+1)
104400 #define TEMPLATE_NULLS_VAL ((1<<30)+2)
104401
104402+#ifdef CONFIG_GRKERNSEC_HIDESYM
104403+static atomic_unchecked_t conntrack_cache_id = ATOMIC_INIT(0);
104404+#endif
104405+
104406 int nf_conntrack_init_net(struct net *net)
104407 {
104408 int ret = -ENOMEM;
104409@@ -1764,7 +1768,11 @@ int nf_conntrack_init_net(struct net *net)
104410 if (!net->ct.stat)
104411 goto err_pcpu_lists;
104412
104413+#ifdef CONFIG_GRKERNSEC_HIDESYM
104414+ net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%08x", atomic_inc_return_unchecked(&conntrack_cache_id));
104415+#else
104416 net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%p", net);
104417+#endif
104418 if (!net->ct.slabname)
104419 goto err_slabname;
104420
104421diff --git a/net/netfilter/nf_conntrack_ecache.c b/net/netfilter/nf_conntrack_ecache.c
104422index 4e78c57..ec8fb74 100644
104423--- a/net/netfilter/nf_conntrack_ecache.c
104424+++ b/net/netfilter/nf_conntrack_ecache.c
104425@@ -264,7 +264,7 @@ static struct nf_ct_ext_type event_extend __read_mostly = {
104426 #ifdef CONFIG_SYSCTL
104427 static int nf_conntrack_event_init_sysctl(struct net *net)
104428 {
104429- struct ctl_table *table;
104430+ ctl_table_no_const *table;
104431
104432 table = kmemdup(event_sysctl_table, sizeof(event_sysctl_table),
104433 GFP_KERNEL);
104434diff --git a/net/netfilter/nf_conntrack_helper.c b/net/netfilter/nf_conntrack_helper.c
104435index 5b3eae7..dd4b8fe 100644
104436--- a/net/netfilter/nf_conntrack_helper.c
104437+++ b/net/netfilter/nf_conntrack_helper.c
104438@@ -57,7 +57,7 @@ static struct ctl_table helper_sysctl_table[] = {
104439
104440 static int nf_conntrack_helper_init_sysctl(struct net *net)
104441 {
104442- struct ctl_table *table;
104443+ ctl_table_no_const *table;
104444
104445 table = kmemdup(helper_sysctl_table, sizeof(helper_sysctl_table),
104446 GFP_KERNEL);
104447diff --git a/net/netfilter/nf_conntrack_proto.c b/net/netfilter/nf_conntrack_proto.c
104448index b65d586..beec902 100644
104449--- a/net/netfilter/nf_conntrack_proto.c
104450+++ b/net/netfilter/nf_conntrack_proto.c
104451@@ -52,7 +52,7 @@ nf_ct_register_sysctl(struct net *net,
104452
104453 static void
104454 nf_ct_unregister_sysctl(struct ctl_table_header **header,
104455- struct ctl_table **table,
104456+ ctl_table_no_const **table,
104457 unsigned int users)
104458 {
104459 if (users > 0)
104460diff --git a/net/netfilter/nf_conntrack_standalone.c b/net/netfilter/nf_conntrack_standalone.c
104461index cf65a1e..2f291e9 100644
104462--- a/net/netfilter/nf_conntrack_standalone.c
104463+++ b/net/netfilter/nf_conntrack_standalone.c
104464@@ -471,7 +471,7 @@ static struct ctl_table nf_ct_netfilter_table[] = {
104465
104466 static int nf_conntrack_standalone_init_sysctl(struct net *net)
104467 {
104468- struct ctl_table *table;
104469+ ctl_table_no_const *table;
104470
104471 table = kmemdup(nf_ct_sysctl_table, sizeof(nf_ct_sysctl_table),
104472 GFP_KERNEL);
104473diff --git a/net/netfilter/nf_conntrack_timestamp.c b/net/netfilter/nf_conntrack_timestamp.c
104474index 7a394df..bd91a8a 100644
104475--- a/net/netfilter/nf_conntrack_timestamp.c
104476+++ b/net/netfilter/nf_conntrack_timestamp.c
104477@@ -42,7 +42,7 @@ static struct nf_ct_ext_type tstamp_extend __read_mostly = {
104478 #ifdef CONFIG_SYSCTL
104479 static int nf_conntrack_tstamp_init_sysctl(struct net *net)
104480 {
104481- struct ctl_table *table;
104482+ ctl_table_no_const *table;
104483
104484 table = kmemdup(tstamp_sysctl_table, sizeof(tstamp_sysctl_table),
104485 GFP_KERNEL);
104486diff --git a/net/netfilter/nf_log.c b/net/netfilter/nf_log.c
104487index d719764..311bc60 100644
104488--- a/net/netfilter/nf_log.c
104489+++ b/net/netfilter/nf_log.c
104490@@ -353,7 +353,7 @@ static const struct file_operations nflog_file_ops = {
104491
104492 #ifdef CONFIG_SYSCTL
104493 static char nf_log_sysctl_fnames[NFPROTO_NUMPROTO-NFPROTO_UNSPEC][3];
104494-static struct ctl_table nf_log_sysctl_table[NFPROTO_NUMPROTO+1];
104495+static ctl_table_no_const nf_log_sysctl_table[NFPROTO_NUMPROTO+1] __read_only;
104496
104497 static int nf_log_proc_dostring(struct ctl_table *table, int write,
104498 void __user *buffer, size_t *lenp, loff_t *ppos)
104499@@ -384,14 +384,16 @@ static int nf_log_proc_dostring(struct ctl_table *table, int write,
104500 rcu_assign_pointer(net->nf.nf_loggers[tindex], logger);
104501 mutex_unlock(&nf_log_mutex);
104502 } else {
104503+ ctl_table_no_const nf_log_table = *table;
104504+
104505 mutex_lock(&nf_log_mutex);
104506 logger = rcu_dereference_protected(net->nf.nf_loggers[tindex],
104507 lockdep_is_held(&nf_log_mutex));
104508 if (!logger)
104509- table->data = "NONE";
104510+ nf_log_table.data = "NONE";
104511 else
104512- table->data = logger->name;
104513- r = proc_dostring(table, write, buffer, lenp, ppos);
104514+ nf_log_table.data = logger->name;
104515+ r = proc_dostring(&nf_log_table, write, buffer, lenp, ppos);
104516 mutex_unlock(&nf_log_mutex);
104517 }
104518
104519diff --git a/net/netfilter/nf_sockopt.c b/net/netfilter/nf_sockopt.c
104520index c68c1e5..8b5d670 100644
104521--- a/net/netfilter/nf_sockopt.c
104522+++ b/net/netfilter/nf_sockopt.c
104523@@ -43,7 +43,7 @@ int nf_register_sockopt(struct nf_sockopt_ops *reg)
104524 }
104525 }
104526
104527- list_add(&reg->list, &nf_sockopts);
104528+ pax_list_add((struct list_head *)&reg->list, &nf_sockopts);
104529 out:
104530 mutex_unlock(&nf_sockopt_mutex);
104531 return ret;
104532@@ -53,7 +53,7 @@ EXPORT_SYMBOL(nf_register_sockopt);
104533 void nf_unregister_sockopt(struct nf_sockopt_ops *reg)
104534 {
104535 mutex_lock(&nf_sockopt_mutex);
104536- list_del(&reg->list);
104537+ pax_list_del((struct list_head *)&reg->list);
104538 mutex_unlock(&nf_sockopt_mutex);
104539 }
104540 EXPORT_SYMBOL(nf_unregister_sockopt);
104541diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
104542index 5f1be5b..2cba8cd 100644
104543--- a/net/netfilter/nfnetlink_log.c
104544+++ b/net/netfilter/nfnetlink_log.c
104545@@ -80,7 +80,7 @@ static int nfnl_log_net_id __read_mostly;
104546 struct nfnl_log_net {
104547 spinlock_t instances_lock;
104548 struct hlist_head instance_table[INSTANCE_BUCKETS];
104549- atomic_t global_seq;
104550+ atomic_unchecked_t global_seq;
104551 };
104552
104553 static struct nfnl_log_net *nfnl_log_pernet(struct net *net)
104554@@ -563,7 +563,7 @@ __build_packet_message(struct nfnl_log_net *log,
104555 /* global sequence number */
104556 if ((inst->flags & NFULNL_CFG_F_SEQ_GLOBAL) &&
104557 nla_put_be32(inst->skb, NFULA_SEQ_GLOBAL,
104558- htonl(atomic_inc_return(&log->global_seq))))
104559+ htonl(atomic_inc_return_unchecked(&log->global_seq))))
104560 goto nla_put_failure;
104561
104562 if (data_len) {
104563diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
104564new file mode 100644
104565index 0000000..c566332
104566--- /dev/null
104567+++ b/net/netfilter/xt_gradm.c
104568@@ -0,0 +1,51 @@
104569+/*
104570+ * gradm match for netfilter
104571