]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blame - test/grsecurity-3.0-3.18.1-201501011219.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-3.0-3.18.1-201501011219.patch
CommitLineData
02bbe1bc
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 3f84029..3c5b65e 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..7c807f0 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,6 +196,28 @@ 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@@ -175,6 +262,11 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1152 return ret;
1153 }
1154
1155+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
1156+{
1157+ return atomic_cmpxchg(v, old, new);
1158+}
1159+
1160 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1161 {
1162 int c, old;
1163@@ -196,16 +288,38 @@ ATOMIC_OPS(sub, -=, sub)
1164
1165 #undef ATOMIC_OPS
1166 #undef ATOMIC_OP_RETURN
1167+#undef __ATOMIC_OP_RETURN
1168 #undef ATOMIC_OP
1169+#undef __ATOMIC_OP
1170
1171 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
1172+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
1173+{
1174+ return xchg(&v->counter, new);
1175+}
1176
1177 #define atomic_inc(v) atomic_add(1, v)
1178+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
1179+{
1180+ atomic_add_unchecked(1, v);
1181+}
1182 #define atomic_dec(v) atomic_sub(1, v)
1183+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
1184+{
1185+ atomic_sub_unchecked(1, v);
1186+}
1187
1188 #define atomic_inc_and_test(v) (atomic_add_return(1, v) == 0)
1189+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
1190+{
1191+ return atomic_add_return_unchecked(1, v) == 0;
1192+}
1193 #define atomic_dec_and_test(v) (atomic_sub_return(1, v) == 0)
1194 #define atomic_inc_return(v) (atomic_add_return(1, v))
1195+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
1196+{
1197+ return atomic_add_return_unchecked(1, v);
1198+}
1199 #define atomic_dec_return(v) (atomic_sub_return(1, v))
1200 #define atomic_sub_and_test(i, v) (atomic_sub_return(i, v) == 0)
1201
1202@@ -216,6 +330,14 @@ typedef struct {
1203 long long counter;
1204 } atomic64_t;
1205
1206+#ifdef CONFIG_PAX_REFCOUNT
1207+typedef struct {
1208+ long long counter;
1209+} atomic64_unchecked_t;
1210+#else
1211+typedef atomic64_t atomic64_unchecked_t;
1212+#endif
1213+
1214 #define ATOMIC64_INIT(i) { (i) }
1215
1216 #ifdef CONFIG_ARM_LPAE
1217@@ -232,6 +354,19 @@ static inline long long atomic64_read(const atomic64_t *v)
1218 return result;
1219 }
1220
1221+static inline long long atomic64_read_unchecked(const atomic64_unchecked_t *v)
1222+{
1223+ long long result;
1224+
1225+ __asm__ __volatile__("@ atomic64_read_unchecked\n"
1226+" ldrd %0, %H0, [%1]"
1227+ : "=&r" (result)
1228+ : "r" (&v->counter), "Qo" (v->counter)
1229+ );
1230+
1231+ return result;
1232+}
1233+
1234 static inline void atomic64_set(atomic64_t *v, long long i)
1235 {
1236 __asm__ __volatile__("@ atomic64_set\n"
1237@@ -240,6 +375,15 @@ static inline void atomic64_set(atomic64_t *v, long long i)
1238 : "r" (&v->counter), "r" (i)
1239 );
1240 }
1241+
1242+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
1243+{
1244+ __asm__ __volatile__("@ atomic64_set_unchecked\n"
1245+" strd %2, %H2, [%1]"
1246+ : "=Qo" (v->counter)
1247+ : "r" (&v->counter), "r" (i)
1248+ );
1249+}
1250 #else
1251 static inline long long atomic64_read(const atomic64_t *v)
1252 {
1253@@ -254,6 +398,19 @@ static inline long long atomic64_read(const atomic64_t *v)
1254 return result;
1255 }
1256
1257+static inline long long atomic64_read_unchecked(const atomic64_unchecked_t *v)
1258+{
1259+ long long result;
1260+
1261+ __asm__ __volatile__("@ atomic64_read_unchecked\n"
1262+" ldrexd %0, %H0, [%1]"
1263+ : "=&r" (result)
1264+ : "r" (&v->counter), "Qo" (v->counter)
1265+ );
1266+
1267+ return result;
1268+}
1269+
1270 static inline void atomic64_set(atomic64_t *v, long long i)
1271 {
1272 long long tmp;
1273@@ -268,29 +425,57 @@ static inline void atomic64_set(atomic64_t *v, long long i)
1274 : "r" (&v->counter), "r" (i)
1275 : "cc");
1276 }
1277+
1278+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
1279+{
1280+ long long tmp;
1281+
1282+ prefetchw(&v->counter);
1283+ __asm__ __volatile__("@ atomic64_set_unchecked\n"
1284+"1: ldrexd %0, %H0, [%2]\n"
1285+" strexd %0, %3, %H3, [%2]\n"
1286+" teq %0, #0\n"
1287+" bne 1b"
1288+ : "=&r" (tmp), "=Qo" (v->counter)
1289+ : "r" (&v->counter), "r" (i)
1290+ : "cc");
1291+}
1292 #endif
1293
1294-#define ATOMIC64_OP(op, op1, op2) \
1295-static inline void atomic64_##op(long long i, atomic64_t *v) \
1296+#undef __OVERFLOW_POST_RETURN
1297+#define __OVERFLOW_POST_RETURN \
1298+ " bvc 3f\n" \
1299+" mov %0, %1\n" \
1300+" mov %H0, %H1\n" \
1301+ "2: " REFCOUNT_TRAP_INSN "\n"\
1302+ "3:\n"
1303+
1304+#define __ATOMIC64_OP(op, suffix, op1, op2, post_op, extable) \
1305+static inline void atomic64_##op##suffix(long long i, atomic64##suffix##_t *v)\
1306 { \
1307 long long result; \
1308 unsigned long tmp; \
1309 \
1310 prefetchw(&v->counter); \
1311- __asm__ __volatile__("@ atomic64_" #op "\n" \
1312+ __asm__ __volatile__("@ atomic64_" #op #suffix "\n" \
1313 "1: ldrexd %0, %H0, [%3]\n" \
1314 " " #op1 " %Q0, %Q0, %Q4\n" \
1315 " " #op2 " %R0, %R0, %R4\n" \
1316+ post_op \
1317 " strexd %1, %0, %H0, [%3]\n" \
1318 " teq %1, #0\n" \
1319-" bne 1b" \
1320+" bne 1b\n" \
1321+ extable \
1322 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter) \
1323 : "r" (&v->counter), "r" (i) \
1324 : "cc"); \
1325 } \
1326
1327-#define ATOMIC64_OP_RETURN(op, op1, op2) \
1328-static inline long long atomic64_##op##_return(long long i, atomic64_t *v) \
1329+#define ATOMIC64_OP(op, op1, op2) __ATOMIC64_OP(op, , op1, op2, , ) \
1330+ __ATOMIC64_OP(op, _unchecked, op1, op2##s, __OVERFLOW_POST, __OVERFLOW_EXTABLE)
1331+
1332+#define __ATOMIC64_OP_RETURN(op, op1, op2, post_op, extable) \
1333+static inline long long atomic64_##op##_return##suffix(long long i, atomic64##suffix##_t *v) \
1334 { \
1335 long long result; \
1336 unsigned long tmp; \
1337@@ -298,13 +483,15 @@ static inline long long atomic64_##op##_return(long long i, atomic64_t *v) \
1338 smp_mb(); \
1339 prefetchw(&v->counter); \
1340 \
1341- __asm__ __volatile__("@ atomic64_" #op "_return\n" \
1342+ __asm__ __volatile__("@ atomic64_" #op "_return" #suffix "\n" \
1343 "1: ldrexd %0, %H0, [%3]\n" \
1344 " " #op1 " %Q0, %Q0, %Q4\n" \
1345 " " #op2 " %R0, %R0, %R4\n" \
1346+ post_op \
1347 " strexd %1, %0, %H0, [%3]\n" \
1348 " teq %1, #0\n" \
1349-" bne 1b" \
1350+" bne 1b\n" \
1351+ extable \
1352 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter) \
1353 : "r" (&v->counter), "r" (i) \
1354 : "cc"); \
1355@@ -314,6 +501,9 @@ static inline long long atomic64_##op##_return(long long i, atomic64_t *v) \
1356 return result; \
1357 }
1358
1359+#define ATOMIC64_OP_RETURN(op, op1, op2) __ATOMIC64_OP_RETURN(op, , op1, op2, , ) \
1360+ __ATOMIC64_OP_RETURN(op, _unchecked, op1, op2##s, __OVERFLOW_POST_RETURN, __OVERFLOW_EXTABLE)
1361+
1362 #define ATOMIC64_OPS(op, op1, op2) \
1363 ATOMIC64_OP(op, op1, op2) \
1364 ATOMIC64_OP_RETURN(op, op1, op2)
1365@@ -323,7 +513,12 @@ ATOMIC64_OPS(sub, subs, sbc)
1366
1367 #undef ATOMIC64_OPS
1368 #undef ATOMIC64_OP_RETURN
1369+#undef __ATOMIC64_OP_RETURN
1370 #undef ATOMIC64_OP
1371+#undef __ATOMIC64_OP
1372+#undef __OVERFLOW_EXTABLE
1373+#undef __OVERFLOW_POST_RETURN
1374+#undef __OVERFLOW_POST
1375
1376 static inline long long atomic64_cmpxchg(atomic64_t *ptr, long long old,
1377 long long new)
1378@@ -351,6 +546,31 @@ static inline long long atomic64_cmpxchg(atomic64_t *ptr, long long old,
1379 return oldval;
1380 }
1381
1382+static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *ptr, long long old,
1383+ long long new)
1384+{
1385+ long long oldval;
1386+ unsigned long res;
1387+
1388+ smp_mb();
1389+
1390+ do {
1391+ __asm__ __volatile__("@ atomic64_cmpxchg_unchecked\n"
1392+ "ldrexd %1, %H1, [%3]\n"
1393+ "mov %0, #0\n"
1394+ "teq %1, %4\n"
1395+ "teqeq %H1, %H4\n"
1396+ "strexdeq %0, %5, %H5, [%3]"
1397+ : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1398+ : "r" (&ptr->counter), "r" (old), "r" (new)
1399+ : "cc");
1400+ } while (res);
1401+
1402+ smp_mb();
1403+
1404+ return oldval;
1405+}
1406+
1407 static inline long long atomic64_xchg(atomic64_t *ptr, long long new)
1408 {
1409 long long result;
1410@@ -376,21 +596,35 @@ static inline long long atomic64_xchg(atomic64_t *ptr, long long new)
1411 static inline long long atomic64_dec_if_positive(atomic64_t *v)
1412 {
1413 long long result;
1414- unsigned long tmp;
1415+ u64 tmp;
1416
1417 smp_mb();
1418 prefetchw(&v->counter);
1419
1420 __asm__ __volatile__("@ atomic64_dec_if_positive\n"
1421-"1: ldrexd %0, %H0, [%3]\n"
1422-" subs %Q0, %Q0, #1\n"
1423-" sbc %R0, %R0, #0\n"
1424+"1: ldrexd %1, %H1, [%3]\n"
1425+" subs %Q0, %Q1, #1\n"
1426+" sbcs %R0, %R1, #0\n"
1427+
1428+#ifdef CONFIG_PAX_REFCOUNT
1429+" bvc 3f\n"
1430+" mov %Q0, %Q1\n"
1431+" mov %R0, %R1\n"
1432+"2: " REFCOUNT_TRAP_INSN "\n"
1433+"3:\n"
1434+#endif
1435+
1436 " teq %R0, #0\n"
1437-" bmi 2f\n"
1438+" bmi 4f\n"
1439 " strexd %1, %0, %H0, [%3]\n"
1440 " teq %1, #0\n"
1441 " bne 1b\n"
1442-"2:"
1443+"4:\n"
1444+
1445+#ifdef CONFIG_PAX_REFCOUNT
1446+ _ASM_EXTABLE(2b, 4b)
1447+#endif
1448+
1449 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1450 : "r" (&v->counter)
1451 : "cc");
1452@@ -414,13 +648,25 @@ static inline int atomic64_add_unless(atomic64_t *v, long long a, long long u)
1453 " teq %0, %5\n"
1454 " teqeq %H0, %H5\n"
1455 " moveq %1, #0\n"
1456-" beq 2f\n"
1457+" beq 4f\n"
1458 " adds %Q0, %Q0, %Q6\n"
1459-" adc %R0, %R0, %R6\n"
1460+" adcs %R0, %R0, %R6\n"
1461+
1462+#ifdef CONFIG_PAX_REFCOUNT
1463+" bvc 3f\n"
1464+"2: " REFCOUNT_TRAP_INSN "\n"
1465+"3:\n"
1466+#endif
1467+
1468 " strexd %2, %0, %H0, [%4]\n"
1469 " teq %2, #0\n"
1470 " bne 1b\n"
1471-"2:"
1472+"4:\n"
1473+
1474+#ifdef CONFIG_PAX_REFCOUNT
1475+ _ASM_EXTABLE(2b, 4b)
1476+#endif
1477+
1478 : "=&r" (val), "+r" (ret), "=&r" (tmp), "+Qo" (v->counter)
1479 : "r" (&v->counter), "r" (u), "r" (a)
1480 : "cc");
1481@@ -433,10 +679,13 @@ static inline int atomic64_add_unless(atomic64_t *v, long long a, long long u)
1482
1483 #define atomic64_add_negative(a, v) (atomic64_add_return((a), (v)) < 0)
1484 #define atomic64_inc(v) atomic64_add(1LL, (v))
1485+#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1LL, (v))
1486 #define atomic64_inc_return(v) atomic64_add_return(1LL, (v))
1487+#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1LL, (v))
1488 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
1489 #define atomic64_sub_and_test(a, v) (atomic64_sub_return((a), (v)) == 0)
1490 #define atomic64_dec(v) atomic64_sub(1LL, (v))
1491+#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1LL, (v))
1492 #define atomic64_dec_return(v) atomic64_sub_return(1LL, (v))
1493 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
1494 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
1495diff --git a/arch/arm/include/asm/barrier.h b/arch/arm/include/asm/barrier.h
1496index c6a3e73..35cca85 100644
1497--- a/arch/arm/include/asm/barrier.h
1498+++ b/arch/arm/include/asm/barrier.h
1499@@ -63,7 +63,7 @@
1500 do { \
1501 compiletime_assert_atomic_type(*p); \
1502 smp_mb(); \
1503- ACCESS_ONCE(*p) = (v); \
1504+ ACCESS_ONCE_RW(*p) = (v); \
1505 } while (0)
1506
1507 #define smp_load_acquire(p) \
1508diff --git a/arch/arm/include/asm/cache.h b/arch/arm/include/asm/cache.h
1509index 75fe66b..ba3dee4 100644
1510--- a/arch/arm/include/asm/cache.h
1511+++ b/arch/arm/include/asm/cache.h
1512@@ -4,8 +4,10 @@
1513 #ifndef __ASMARM_CACHE_H
1514 #define __ASMARM_CACHE_H
1515
1516+#include <linux/const.h>
1517+
1518 #define L1_CACHE_SHIFT CONFIG_ARM_L1_CACHE_SHIFT
1519-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
1520+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
1521
1522 /*
1523 * Memory returned by kmalloc() may be used for DMA, so we must make
1524@@ -24,5 +26,6 @@
1525 #endif
1526
1527 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
1528+#define __read_only __attribute__ ((__section__(".data..read_only")))
1529
1530 #endif
1531diff --git a/arch/arm/include/asm/cacheflush.h b/arch/arm/include/asm/cacheflush.h
1532index 10e78d0..dc8505d 100644
1533--- a/arch/arm/include/asm/cacheflush.h
1534+++ b/arch/arm/include/asm/cacheflush.h
1535@@ -116,7 +116,7 @@ struct cpu_cache_fns {
1536 void (*dma_unmap_area)(const void *, size_t, int);
1537
1538 void (*dma_flush_range)(const void *, const void *);
1539-};
1540+} __no_const;
1541
1542 /*
1543 * Select the calling method
1544diff --git a/arch/arm/include/asm/checksum.h b/arch/arm/include/asm/checksum.h
1545index 5233151..87a71fa 100644
1546--- a/arch/arm/include/asm/checksum.h
1547+++ b/arch/arm/include/asm/checksum.h
1548@@ -37,7 +37,19 @@ __wsum
1549 csum_partial_copy_nocheck(const void *src, void *dst, int len, __wsum sum);
1550
1551 __wsum
1552-csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr);
1553+__csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr);
1554+
1555+static inline __wsum
1556+csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr)
1557+{
1558+ __wsum ret;
1559+ pax_open_userland();
1560+ ret = __csum_partial_copy_from_user(src, dst, len, sum, err_ptr);
1561+ pax_close_userland();
1562+ return ret;
1563+}
1564+
1565+
1566
1567 /*
1568 * Fold a partial checksum without adding pseudo headers
1569diff --git a/arch/arm/include/asm/cmpxchg.h b/arch/arm/include/asm/cmpxchg.h
1570index abb2c37..96db950 100644
1571--- a/arch/arm/include/asm/cmpxchg.h
1572+++ b/arch/arm/include/asm/cmpxchg.h
1573@@ -104,6 +104,8 @@ static inline unsigned long __xchg(unsigned long x, volatile void *ptr, int size
1574
1575 #define xchg(ptr,x) \
1576 ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1577+#define xchg_unchecked(ptr,x) \
1578+ ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1579
1580 #include <asm-generic/cmpxchg-local.h>
1581
1582diff --git a/arch/arm/include/asm/domain.h b/arch/arm/include/asm/domain.h
1583index 6ddbe44..b5e38b1 100644
1584--- a/arch/arm/include/asm/domain.h
1585+++ b/arch/arm/include/asm/domain.h
1586@@ -48,18 +48,37 @@
1587 * Domain types
1588 */
1589 #define DOMAIN_NOACCESS 0
1590-#define DOMAIN_CLIENT 1
1591 #ifdef CONFIG_CPU_USE_DOMAINS
1592+#define DOMAIN_USERCLIENT 1
1593+#define DOMAIN_KERNELCLIENT 1
1594 #define DOMAIN_MANAGER 3
1595+#define DOMAIN_VECTORS DOMAIN_USER
1596 #else
1597+
1598+#ifdef CONFIG_PAX_KERNEXEC
1599 #define DOMAIN_MANAGER 1
1600+#define DOMAIN_KERNEXEC 3
1601+#else
1602+#define DOMAIN_MANAGER 1
1603+#endif
1604+
1605+#ifdef CONFIG_PAX_MEMORY_UDEREF
1606+#define DOMAIN_USERCLIENT 0
1607+#define DOMAIN_UDEREF 1
1608+#define DOMAIN_VECTORS DOMAIN_KERNEL
1609+#else
1610+#define DOMAIN_USERCLIENT 1
1611+#define DOMAIN_VECTORS DOMAIN_USER
1612+#endif
1613+#define DOMAIN_KERNELCLIENT 1
1614+
1615 #endif
1616
1617 #define domain_val(dom,type) ((type) << (2*(dom)))
1618
1619 #ifndef __ASSEMBLY__
1620
1621-#ifdef CONFIG_CPU_USE_DOMAINS
1622+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
1623 static inline void set_domain(unsigned val)
1624 {
1625 asm volatile(
1626@@ -68,15 +87,7 @@ static inline void set_domain(unsigned val)
1627 isb();
1628 }
1629
1630-#define modify_domain(dom,type) \
1631- do { \
1632- struct thread_info *thread = current_thread_info(); \
1633- unsigned int domain = thread->cpu_domain; \
1634- domain &= ~domain_val(dom, DOMAIN_MANAGER); \
1635- thread->cpu_domain = domain | domain_val(dom, type); \
1636- set_domain(thread->cpu_domain); \
1637- } while (0)
1638-
1639+extern void modify_domain(unsigned int dom, unsigned int type);
1640 #else
1641 static inline void set_domain(unsigned val) { }
1642 static inline void modify_domain(unsigned dom, unsigned type) { }
1643diff --git a/arch/arm/include/asm/elf.h b/arch/arm/include/asm/elf.h
1644index afb9caf..9a0bac0 100644
1645--- a/arch/arm/include/asm/elf.h
1646+++ b/arch/arm/include/asm/elf.h
1647@@ -115,7 +115,14 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1648 the loader. We need to make sure that it is out of the way of the program
1649 that it will "exec", and that there is sufficient room for the brk. */
1650
1651-#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
1652+#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
1653+
1654+#ifdef CONFIG_PAX_ASLR
1655+#define PAX_ELF_ET_DYN_BASE 0x00008000UL
1656+
1657+#define PAX_DELTA_MMAP_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1658+#define PAX_DELTA_STACK_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1659+#endif
1660
1661 /* When the program starts, a1 contains a pointer to a function to be
1662 registered with atexit, as per the SVR4 ABI. A value of 0 means we
1663@@ -125,10 +132,6 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1664 extern void elf_set_personality(const struct elf32_hdr *);
1665 #define SET_PERSONALITY(ex) elf_set_personality(&(ex))
1666
1667-struct mm_struct;
1668-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
1669-#define arch_randomize_brk arch_randomize_brk
1670-
1671 #ifdef CONFIG_MMU
1672 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
1673 struct linux_binprm;
1674diff --git a/arch/arm/include/asm/fncpy.h b/arch/arm/include/asm/fncpy.h
1675index de53547..52b9a28 100644
1676--- a/arch/arm/include/asm/fncpy.h
1677+++ b/arch/arm/include/asm/fncpy.h
1678@@ -81,7 +81,9 @@
1679 BUG_ON((uintptr_t)(dest_buf) & (FNCPY_ALIGN - 1) || \
1680 (__funcp_address & ~(uintptr_t)1 & (FNCPY_ALIGN - 1))); \
1681 \
1682+ pax_open_kernel(); \
1683 memcpy(dest_buf, (void const *)(__funcp_address & ~1), size); \
1684+ pax_close_kernel(); \
1685 flush_icache_range((unsigned long)(dest_buf), \
1686 (unsigned long)(dest_buf) + (size)); \
1687 \
1688diff --git a/arch/arm/include/asm/futex.h b/arch/arm/include/asm/futex.h
1689index 53e69da..3fdc896 100644
1690--- a/arch/arm/include/asm/futex.h
1691+++ b/arch/arm/include/asm/futex.h
1692@@ -46,6 +46,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1693 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
1694 return -EFAULT;
1695
1696+ pax_open_userland();
1697+
1698 smp_mb();
1699 /* Prefetching cannot fault */
1700 prefetchw(uaddr);
1701@@ -63,6 +65,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1702 : "cc", "memory");
1703 smp_mb();
1704
1705+ pax_close_userland();
1706+
1707 *uval = val;
1708 return ret;
1709 }
1710@@ -93,6 +97,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1711 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
1712 return -EFAULT;
1713
1714+ pax_open_userland();
1715+
1716 __asm__ __volatile__("@futex_atomic_cmpxchg_inatomic\n"
1717 "1: " TUSER(ldr) " %1, [%4]\n"
1718 " teq %1, %2\n"
1719@@ -103,6 +109,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1720 : "r" (oldval), "r" (newval), "r" (uaddr), "Ir" (-EFAULT)
1721 : "cc", "memory");
1722
1723+ pax_close_userland();
1724+
1725 *uval = val;
1726 return ret;
1727 }
1728@@ -125,6 +133,7 @@ futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
1729 return -EFAULT;
1730
1731 pagefault_disable(); /* implies preempt_disable() */
1732+ pax_open_userland();
1733
1734 switch (op) {
1735 case FUTEX_OP_SET:
1736@@ -146,6 +155,7 @@ futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
1737 ret = -ENOSYS;
1738 }
1739
1740+ pax_close_userland();
1741 pagefault_enable(); /* subsumes preempt_enable() */
1742
1743 if (!ret) {
1744diff --git a/arch/arm/include/asm/kmap_types.h b/arch/arm/include/asm/kmap_types.h
1745index 83eb2f7..ed77159 100644
1746--- a/arch/arm/include/asm/kmap_types.h
1747+++ b/arch/arm/include/asm/kmap_types.h
1748@@ -4,6 +4,6 @@
1749 /*
1750 * This is the "bare minimum". AIO seems to require this.
1751 */
1752-#define KM_TYPE_NR 16
1753+#define KM_TYPE_NR 17
1754
1755 #endif
1756diff --git a/arch/arm/include/asm/mach/dma.h b/arch/arm/include/asm/mach/dma.h
1757index 9e614a1..3302cca 100644
1758--- a/arch/arm/include/asm/mach/dma.h
1759+++ b/arch/arm/include/asm/mach/dma.h
1760@@ -22,7 +22,7 @@ struct dma_ops {
1761 int (*residue)(unsigned int, dma_t *); /* optional */
1762 int (*setspeed)(unsigned int, dma_t *, int); /* optional */
1763 const char *type;
1764-};
1765+} __do_const;
1766
1767 struct dma_struct {
1768 void *addr; /* single DMA address */
1769diff --git a/arch/arm/include/asm/mach/map.h b/arch/arm/include/asm/mach/map.h
1770index f98c7f3..e5c626d 100644
1771--- a/arch/arm/include/asm/mach/map.h
1772+++ b/arch/arm/include/asm/mach/map.h
1773@@ -23,17 +23,19 @@ struct map_desc {
1774
1775 /* types 0-3 are defined in asm/io.h */
1776 enum {
1777- MT_UNCACHED = 4,
1778- MT_CACHECLEAN,
1779- MT_MINICLEAN,
1780+ MT_UNCACHED_RW = 4,
1781+ MT_CACHECLEAN_RO,
1782+ MT_MINICLEAN_RO,
1783 MT_LOW_VECTORS,
1784 MT_HIGH_VECTORS,
1785- MT_MEMORY_RWX,
1786+ __MT_MEMORY_RWX,
1787 MT_MEMORY_RW,
1788- MT_ROM,
1789- MT_MEMORY_RWX_NONCACHED,
1790+ MT_MEMORY_RX,
1791+ MT_ROM_RX,
1792+ MT_MEMORY_RW_NONCACHED,
1793+ MT_MEMORY_RX_NONCACHED,
1794 MT_MEMORY_RW_DTCM,
1795- MT_MEMORY_RWX_ITCM,
1796+ MT_MEMORY_RX_ITCM,
1797 MT_MEMORY_RW_SO,
1798 MT_MEMORY_DMA_READY,
1799 };
1800diff --git a/arch/arm/include/asm/outercache.h b/arch/arm/include/asm/outercache.h
1801index 891a56b..48f337e 100644
1802--- a/arch/arm/include/asm/outercache.h
1803+++ b/arch/arm/include/asm/outercache.h
1804@@ -36,7 +36,7 @@ struct outer_cache_fns {
1805
1806 /* This is an ARM L2C thing */
1807 void (*write_sec)(unsigned long, unsigned);
1808-};
1809+} __no_const;
1810
1811 extern struct outer_cache_fns outer_cache;
1812
1813diff --git a/arch/arm/include/asm/page.h b/arch/arm/include/asm/page.h
1814index 4355f0e..cd9168e 100644
1815--- a/arch/arm/include/asm/page.h
1816+++ b/arch/arm/include/asm/page.h
1817@@ -23,6 +23,7 @@
1818
1819 #else
1820
1821+#include <linux/compiler.h>
1822 #include <asm/glue.h>
1823
1824 /*
1825@@ -114,7 +115,7 @@ struct cpu_user_fns {
1826 void (*cpu_clear_user_highpage)(struct page *page, unsigned long vaddr);
1827 void (*cpu_copy_user_highpage)(struct page *to, struct page *from,
1828 unsigned long vaddr, struct vm_area_struct *vma);
1829-};
1830+} __no_const;
1831
1832 #ifdef MULTI_USER
1833 extern struct cpu_user_fns cpu_user;
1834diff --git a/arch/arm/include/asm/pgalloc.h b/arch/arm/include/asm/pgalloc.h
1835index 78a7793..e3dc06c 100644
1836--- a/arch/arm/include/asm/pgalloc.h
1837+++ b/arch/arm/include/asm/pgalloc.h
1838@@ -17,6 +17,7 @@
1839 #include <asm/processor.h>
1840 #include <asm/cacheflush.h>
1841 #include <asm/tlbflush.h>
1842+#include <asm/system_info.h>
1843
1844 #define check_pgt_cache() do { } while (0)
1845
1846@@ -43,6 +44,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1847 set_pud(pud, __pud(__pa(pmd) | PMD_TYPE_TABLE));
1848 }
1849
1850+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1851+{
1852+ pud_populate(mm, pud, pmd);
1853+}
1854+
1855 #else /* !CONFIG_ARM_LPAE */
1856
1857 /*
1858@@ -51,6 +57,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1859 #define pmd_alloc_one(mm,addr) ({ BUG(); ((pmd_t *)2); })
1860 #define pmd_free(mm, pmd) do { } while (0)
1861 #define pud_populate(mm,pmd,pte) BUG()
1862+#define pud_populate_kernel(mm,pmd,pte) BUG()
1863
1864 #endif /* CONFIG_ARM_LPAE */
1865
1866@@ -128,6 +135,19 @@ static inline void pte_free(struct mm_struct *mm, pgtable_t pte)
1867 __free_page(pte);
1868 }
1869
1870+static inline void __section_update(pmd_t *pmdp, unsigned long addr, pmdval_t prot)
1871+{
1872+#ifdef CONFIG_ARM_LPAE
1873+ pmdp[0] = __pmd(pmd_val(pmdp[0]) | prot);
1874+#else
1875+ if (addr & SECTION_SIZE)
1876+ pmdp[1] = __pmd(pmd_val(pmdp[1]) | prot);
1877+ else
1878+ pmdp[0] = __pmd(pmd_val(pmdp[0]) | prot);
1879+#endif
1880+ flush_pmd_entry(pmdp);
1881+}
1882+
1883 static inline void __pmd_populate(pmd_t *pmdp, phys_addr_t pte,
1884 pmdval_t prot)
1885 {
1886@@ -157,7 +177,7 @@ pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmdp, pte_t *ptep)
1887 static inline void
1888 pmd_populate(struct mm_struct *mm, pmd_t *pmdp, pgtable_t ptep)
1889 {
1890- __pmd_populate(pmdp, page_to_phys(ptep), _PAGE_USER_TABLE);
1891+ __pmd_populate(pmdp, page_to_phys(ptep), _PAGE_USER_TABLE | __supported_pmd_mask);
1892 }
1893 #define pmd_pgtable(pmd) pmd_page(pmd)
1894
1895diff --git a/arch/arm/include/asm/pgtable-2level-hwdef.h b/arch/arm/include/asm/pgtable-2level-hwdef.h
1896index 5cfba15..f415e1a 100644
1897--- a/arch/arm/include/asm/pgtable-2level-hwdef.h
1898+++ b/arch/arm/include/asm/pgtable-2level-hwdef.h
1899@@ -20,12 +20,15 @@
1900 #define PMD_TYPE_FAULT (_AT(pmdval_t, 0) << 0)
1901 #define PMD_TYPE_TABLE (_AT(pmdval_t, 1) << 0)
1902 #define PMD_TYPE_SECT (_AT(pmdval_t, 2) << 0)
1903+#define PMD_PXNTABLE (_AT(pmdval_t, 1) << 2) /* v7 */
1904 #define PMD_BIT4 (_AT(pmdval_t, 1) << 4)
1905 #define PMD_DOMAIN(x) (_AT(pmdval_t, (x)) << 5)
1906 #define PMD_PROTECTION (_AT(pmdval_t, 1) << 9) /* v5 */
1907+
1908 /*
1909 * - section
1910 */
1911+#define PMD_SECT_PXN (_AT(pmdval_t, 1) << 0) /* v7 */
1912 #define PMD_SECT_BUFFERABLE (_AT(pmdval_t, 1) << 2)
1913 #define PMD_SECT_CACHEABLE (_AT(pmdval_t, 1) << 3)
1914 #define PMD_SECT_XN (_AT(pmdval_t, 1) << 4) /* v6 */
1915@@ -37,6 +40,7 @@
1916 #define PMD_SECT_nG (_AT(pmdval_t, 1) << 17) /* v6 */
1917 #define PMD_SECT_SUPER (_AT(pmdval_t, 1) << 18) /* v6 */
1918 #define PMD_SECT_AF (_AT(pmdval_t, 0))
1919+#define PMD_SECT_RDONLY (_AT(pmdval_t, 0))
1920
1921 #define PMD_SECT_UNCACHED (_AT(pmdval_t, 0))
1922 #define PMD_SECT_BUFFERED (PMD_SECT_BUFFERABLE)
1923@@ -66,6 +70,7 @@
1924 * - extended small page/tiny page
1925 */
1926 #define PTE_EXT_XN (_AT(pteval_t, 1) << 0) /* v6 */
1927+#define PTE_EXT_PXN (_AT(pteval_t, 1) << 2) /* v7 */
1928 #define PTE_EXT_AP_MASK (_AT(pteval_t, 3) << 4)
1929 #define PTE_EXT_AP0 (_AT(pteval_t, 1) << 4)
1930 #define PTE_EXT_AP1 (_AT(pteval_t, 2) << 4)
1931diff --git a/arch/arm/include/asm/pgtable-2level.h b/arch/arm/include/asm/pgtable-2level.h
1932index f027941..f36ce30 100644
1933--- a/arch/arm/include/asm/pgtable-2level.h
1934+++ b/arch/arm/include/asm/pgtable-2level.h
1935@@ -126,6 +126,9 @@
1936 #define L_PTE_SHARED (_AT(pteval_t, 1) << 10) /* shared(v6), coherent(xsc3) */
1937 #define L_PTE_NONE (_AT(pteval_t, 1) << 11)
1938
1939+/* Two-level page tables only have PXN in the PGD, not in the PTE. */
1940+#define L_PTE_PXN (_AT(pteval_t, 0))
1941+
1942 /*
1943 * These are the memory types, defined to be compatible with
1944 * pre-ARMv6 CPUs cacheable and bufferable bits: XXCB
1945diff --git a/arch/arm/include/asm/pgtable-3level-hwdef.h b/arch/arm/include/asm/pgtable-3level-hwdef.h
1946index 9fd61c7..f8f1cff 100644
1947--- a/arch/arm/include/asm/pgtable-3level-hwdef.h
1948+++ b/arch/arm/include/asm/pgtable-3level-hwdef.h
1949@@ -76,6 +76,7 @@
1950 #define PTE_EXT_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
1951 #define PTE_EXT_AF (_AT(pteval_t, 1) << 10) /* Access Flag */
1952 #define PTE_EXT_NG (_AT(pteval_t, 1) << 11) /* nG */
1953+#define PTE_EXT_PXN (_AT(pteval_t, 1) << 53) /* PXN */
1954 #define PTE_EXT_XN (_AT(pteval_t, 1) << 54) /* XN */
1955
1956 /*
1957diff --git a/arch/arm/include/asm/pgtable-3level.h b/arch/arm/include/asm/pgtable-3level.h
1958index a31ecdad..95e98d4 100644
1959--- a/arch/arm/include/asm/pgtable-3level.h
1960+++ b/arch/arm/include/asm/pgtable-3level.h
1961@@ -81,6 +81,7 @@
1962 #define L_PTE_USER (_AT(pteval_t, 1) << 6) /* AP[1] */
1963 #define L_PTE_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
1964 #define L_PTE_YOUNG (_AT(pteval_t, 1) << 10) /* AF */
1965+#define L_PTE_PXN (_AT(pteval_t, 1) << 53) /* PXN */
1966 #define L_PTE_XN (_AT(pteval_t, 1) << 54) /* XN */
1967 #define L_PTE_DIRTY (_AT(pteval_t, 1) << 55)
1968 #define L_PTE_SPECIAL (_AT(pteval_t, 1) << 56)
1969@@ -92,10 +93,12 @@
1970 #define L_PMD_SECT_SPLITTING (_AT(pmdval_t, 1) << 56)
1971 #define L_PMD_SECT_NONE (_AT(pmdval_t, 1) << 57)
1972 #define L_PMD_SECT_RDONLY (_AT(pteval_t, 1) << 58)
1973+#define PMD_SECT_RDONLY PMD_SECT_AP2
1974
1975 /*
1976 * To be used in assembly code with the upper page attributes.
1977 */
1978+#define L_PTE_PXN_HIGH (1 << (53 - 32))
1979 #define L_PTE_XN_HIGH (1 << (54 - 32))
1980 #define L_PTE_DIRTY_HIGH (1 << (55 - 32))
1981
1982diff --git a/arch/arm/include/asm/pgtable.h b/arch/arm/include/asm/pgtable.h
1983index 3b30062..01a5f9d 100644
1984--- a/arch/arm/include/asm/pgtable.h
1985+++ b/arch/arm/include/asm/pgtable.h
1986@@ -33,6 +33,9 @@
1987 #include <asm/pgtable-2level.h>
1988 #endif
1989
1990+#define ktla_ktva(addr) (addr)
1991+#define ktva_ktla(addr) (addr)
1992+
1993 /*
1994 * Just any arbitrary offset to the start of the vmalloc VM area: the
1995 * current 8MB value just means that there will be a 8MB "hole" after the
1996@@ -48,6 +51,9 @@
1997 #define LIBRARY_TEXT_START 0x0c000000
1998
1999 #ifndef __ASSEMBLY__
2000+extern pteval_t __supported_pte_mask;
2001+extern pmdval_t __supported_pmd_mask;
2002+
2003 extern void __pte_error(const char *file, int line, pte_t);
2004 extern void __pmd_error(const char *file, int line, pmd_t);
2005 extern void __pgd_error(const char *file, int line, pgd_t);
2006@@ -56,6 +62,48 @@ extern void __pgd_error(const char *file, int line, pgd_t);
2007 #define pmd_ERROR(pmd) __pmd_error(__FILE__, __LINE__, pmd)
2008 #define pgd_ERROR(pgd) __pgd_error(__FILE__, __LINE__, pgd)
2009
2010+#define __HAVE_ARCH_PAX_OPEN_KERNEL
2011+#define __HAVE_ARCH_PAX_CLOSE_KERNEL
2012+
2013+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2014+#include <asm/domain.h>
2015+#include <linux/thread_info.h>
2016+#include <linux/preempt.h>
2017+
2018+static inline int test_domain(int domain, int domaintype)
2019+{
2020+ return ((current_thread_info()->cpu_domain) & domain_val(domain, 3)) == domain_val(domain, domaintype);
2021+}
2022+#endif
2023+
2024+#ifdef CONFIG_PAX_KERNEXEC
2025+static inline unsigned long pax_open_kernel(void) {
2026+#ifdef CONFIG_ARM_LPAE
2027+ /* TODO */
2028+#else
2029+ preempt_disable();
2030+ BUG_ON(test_domain(DOMAIN_KERNEL, DOMAIN_KERNEXEC));
2031+ modify_domain(DOMAIN_KERNEL, DOMAIN_KERNEXEC);
2032+#endif
2033+ return 0;
2034+}
2035+
2036+static inline unsigned long pax_close_kernel(void) {
2037+#ifdef CONFIG_ARM_LPAE
2038+ /* TODO */
2039+#else
2040+ BUG_ON(test_domain(DOMAIN_KERNEL, DOMAIN_MANAGER));
2041+ /* DOMAIN_MANAGER = "client" under KERNEXEC */
2042+ modify_domain(DOMAIN_KERNEL, DOMAIN_MANAGER);
2043+ preempt_enable_no_resched();
2044+#endif
2045+ return 0;
2046+}
2047+#else
2048+static inline unsigned long pax_open_kernel(void) { return 0; }
2049+static inline unsigned long pax_close_kernel(void) { return 0; }
2050+#endif
2051+
2052 /*
2053 * This is the lowest virtual address we can permit any user space
2054 * mapping to be mapped at. This is particularly important for
2055@@ -75,8 +123,8 @@ extern void __pgd_error(const char *file, int line, pgd_t);
2056 /*
2057 * The pgprot_* and protection_map entries will be fixed up in runtime
2058 * to include the cachable and bufferable bits based on memory policy,
2059- * as well as any architecture dependent bits like global/ASID and SMP
2060- * shared mapping bits.
2061+ * as well as any architecture dependent bits like global/ASID, PXN,
2062+ * and SMP shared mapping bits.
2063 */
2064 #define _L_PTE_DEFAULT L_PTE_PRESENT | L_PTE_YOUNG
2065
2066@@ -267,7 +315,7 @@ PTE_BIT_FUNC(mknexec, |= L_PTE_XN);
2067 static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
2068 {
2069 const pteval_t mask = L_PTE_XN | L_PTE_RDONLY | L_PTE_USER |
2070- L_PTE_NONE | L_PTE_VALID;
2071+ L_PTE_NONE | L_PTE_VALID | __supported_pte_mask;
2072 pte_val(pte) = (pte_val(pte) & ~mask) | (pgprot_val(newprot) & mask);
2073 return pte;
2074 }
2075diff --git a/arch/arm/include/asm/psci.h b/arch/arm/include/asm/psci.h
2076index c25ef3e..735f14b 100644
2077--- a/arch/arm/include/asm/psci.h
2078+++ b/arch/arm/include/asm/psci.h
2079@@ -32,7 +32,7 @@ struct psci_operations {
2080 int (*affinity_info)(unsigned long target_affinity,
2081 unsigned long lowest_affinity_level);
2082 int (*migrate_info_type)(void);
2083-};
2084+} __no_const;
2085
2086 extern struct psci_operations psci_ops;
2087 extern struct smp_operations psci_smp_ops;
2088diff --git a/arch/arm/include/asm/smp.h b/arch/arm/include/asm/smp.h
2089index 18f5a55..5072a40 100644
2090--- a/arch/arm/include/asm/smp.h
2091+++ b/arch/arm/include/asm/smp.h
2092@@ -107,7 +107,7 @@ struct smp_operations {
2093 int (*cpu_disable)(unsigned int cpu);
2094 #endif
2095 #endif
2096-};
2097+} __no_const;
2098
2099 struct of_cpu_method {
2100 const char *method;
2101diff --git a/arch/arm/include/asm/thread_info.h b/arch/arm/include/asm/thread_info.h
2102index ce73ab6..7310f8a 100644
2103--- a/arch/arm/include/asm/thread_info.h
2104+++ b/arch/arm/include/asm/thread_info.h
2105@@ -78,9 +78,9 @@ struct thread_info {
2106 .flags = 0, \
2107 .preempt_count = INIT_PREEMPT_COUNT, \
2108 .addr_limit = KERNEL_DS, \
2109- .cpu_domain = domain_val(DOMAIN_USER, DOMAIN_MANAGER) | \
2110- domain_val(DOMAIN_KERNEL, DOMAIN_MANAGER) | \
2111- domain_val(DOMAIN_IO, DOMAIN_CLIENT), \
2112+ .cpu_domain = domain_val(DOMAIN_USER, DOMAIN_USERCLIENT) | \
2113+ domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT) | \
2114+ domain_val(DOMAIN_IO, DOMAIN_KERNELCLIENT), \
2115 .restart_block = { \
2116 .fn = do_no_restart_syscall, \
2117 }, \
2118@@ -154,7 +154,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
2119 #define TIF_SYSCALL_AUDIT 9
2120 #define TIF_SYSCALL_TRACEPOINT 10
2121 #define TIF_SECCOMP 11 /* seccomp syscall filtering active */
2122-#define TIF_NOHZ 12 /* in adaptive nohz mode */
2123+/* within 8 bits of TIF_SYSCALL_TRACE
2124+ * to meet flexible second operand requirements
2125+ */
2126+#define TIF_GRSEC_SETXID 12
2127+#define TIF_NOHZ 13 /* in adaptive nohz mode */
2128 #define TIF_USING_IWMMXT 17
2129 #define TIF_MEMDIE 18 /* is terminating due to OOM killer */
2130 #define TIF_RESTORE_SIGMASK 20
2131@@ -168,10 +172,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
2132 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
2133 #define _TIF_SECCOMP (1 << TIF_SECCOMP)
2134 #define _TIF_USING_IWMMXT (1 << TIF_USING_IWMMXT)
2135+#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
2136
2137 /* Checks for any syscall work in entry-common.S */
2138 #define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
2139- _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP)
2140+ _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP | _TIF_GRSEC_SETXID)
2141
2142 /*
2143 * Change these and you break ASM code in entry-common.S
2144diff --git a/arch/arm/include/asm/tls.h b/arch/arm/include/asm/tls.h
2145index 5f833f7..76e6644 100644
2146--- a/arch/arm/include/asm/tls.h
2147+++ b/arch/arm/include/asm/tls.h
2148@@ -3,6 +3,7 @@
2149
2150 #include <linux/compiler.h>
2151 #include <asm/thread_info.h>
2152+#include <asm/pgtable.h>
2153
2154 #ifdef __ASSEMBLY__
2155 #include <asm/asm-offsets.h>
2156@@ -89,7 +90,9 @@ static inline void set_tls(unsigned long val)
2157 * at 0xffff0fe0 must be used instead. (see
2158 * entry-armv.S for details)
2159 */
2160+ pax_open_kernel();
2161 *((unsigned int *)0xffff0ff0) = val;
2162+ pax_close_kernel();
2163 #endif
2164 }
2165
2166diff --git a/arch/arm/include/asm/uaccess.h b/arch/arm/include/asm/uaccess.h
2167index 4767eb9..bf00668 100644
2168--- a/arch/arm/include/asm/uaccess.h
2169+++ b/arch/arm/include/asm/uaccess.h
2170@@ -18,6 +18,7 @@
2171 #include <asm/domain.h>
2172 #include <asm/unified.h>
2173 #include <asm/compiler.h>
2174+#include <asm/pgtable.h>
2175
2176 #ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
2177 #include <asm-generic/uaccess-unaligned.h>
2178@@ -70,11 +71,38 @@ extern int __put_user_bad(void);
2179 static inline void set_fs(mm_segment_t fs)
2180 {
2181 current_thread_info()->addr_limit = fs;
2182- modify_domain(DOMAIN_KERNEL, fs ? DOMAIN_CLIENT : DOMAIN_MANAGER);
2183+ modify_domain(DOMAIN_KERNEL, fs ? DOMAIN_KERNELCLIENT : DOMAIN_MANAGER);
2184 }
2185
2186 #define segment_eq(a,b) ((a) == (b))
2187
2188+#define __HAVE_ARCH_PAX_OPEN_USERLAND
2189+#define __HAVE_ARCH_PAX_CLOSE_USERLAND
2190+
2191+static inline void pax_open_userland(void)
2192+{
2193+
2194+#ifdef CONFIG_PAX_MEMORY_UDEREF
2195+ if (segment_eq(get_fs(), USER_DS)) {
2196+ BUG_ON(test_domain(DOMAIN_USER, DOMAIN_UDEREF));
2197+ modify_domain(DOMAIN_USER, DOMAIN_UDEREF);
2198+ }
2199+#endif
2200+
2201+}
2202+
2203+static inline void pax_close_userland(void)
2204+{
2205+
2206+#ifdef CONFIG_PAX_MEMORY_UDEREF
2207+ if (segment_eq(get_fs(), USER_DS)) {
2208+ BUG_ON(test_domain(DOMAIN_USER, DOMAIN_NOACCESS));
2209+ modify_domain(DOMAIN_USER, DOMAIN_NOACCESS);
2210+ }
2211+#endif
2212+
2213+}
2214+
2215 #define __addr_ok(addr) ({ \
2216 unsigned long flag; \
2217 __asm__("cmp %2, %0; movlo %0, #0" \
2218@@ -198,8 +226,12 @@ extern int __get_user_64t_4(void *);
2219
2220 #define get_user(x,p) \
2221 ({ \
2222+ int __e; \
2223 might_fault(); \
2224- __get_user_check(x,p); \
2225+ pax_open_userland(); \
2226+ __e = __get_user_check(x,p); \
2227+ pax_close_userland(); \
2228+ __e; \
2229 })
2230
2231 extern int __put_user_1(void *, unsigned int);
2232@@ -244,8 +276,12 @@ extern int __put_user_8(void *, unsigned long long);
2233
2234 #define put_user(x,p) \
2235 ({ \
2236+ int __e; \
2237 might_fault(); \
2238- __put_user_check(x,p); \
2239+ pax_open_userland(); \
2240+ __e = __put_user_check(x,p); \
2241+ pax_close_userland(); \
2242+ __e; \
2243 })
2244
2245 #else /* CONFIG_MMU */
2246@@ -269,6 +305,7 @@ static inline void set_fs(mm_segment_t fs)
2247
2248 #endif /* CONFIG_MMU */
2249
2250+#define access_ok_noprefault(type,addr,size) access_ok((type),(addr),(size))
2251 #define access_ok(type,addr,size) (__range_ok(addr,size) == 0)
2252
2253 #define user_addr_max() \
2254@@ -286,13 +323,17 @@ static inline void set_fs(mm_segment_t fs)
2255 #define __get_user(x,ptr) \
2256 ({ \
2257 long __gu_err = 0; \
2258+ pax_open_userland(); \
2259 __get_user_err((x),(ptr),__gu_err); \
2260+ pax_close_userland(); \
2261 __gu_err; \
2262 })
2263
2264 #define __get_user_error(x,ptr,err) \
2265 ({ \
2266+ pax_open_userland(); \
2267 __get_user_err((x),(ptr),err); \
2268+ pax_close_userland(); \
2269 (void) 0; \
2270 })
2271
2272@@ -368,13 +409,17 @@ do { \
2273 #define __put_user(x,ptr) \
2274 ({ \
2275 long __pu_err = 0; \
2276+ pax_open_userland(); \
2277 __put_user_err((x),(ptr),__pu_err); \
2278+ pax_close_userland(); \
2279 __pu_err; \
2280 })
2281
2282 #define __put_user_error(x,ptr,err) \
2283 ({ \
2284+ pax_open_userland(); \
2285 __put_user_err((x),(ptr),err); \
2286+ pax_close_userland(); \
2287 (void) 0; \
2288 })
2289
2290@@ -474,11 +519,44 @@ do { \
2291
2292
2293 #ifdef CONFIG_MMU
2294-extern unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n);
2295-extern unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n);
2296+extern unsigned long __must_check ___copy_from_user(void *to, const void __user *from, unsigned long n);
2297+extern unsigned long __must_check ___copy_to_user(void __user *to, const void *from, unsigned long n);
2298+
2299+static inline unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n)
2300+{
2301+ unsigned long ret;
2302+
2303+ check_object_size(to, n, false);
2304+ pax_open_userland();
2305+ ret = ___copy_from_user(to, from, n);
2306+ pax_close_userland();
2307+ return ret;
2308+}
2309+
2310+static inline unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n)
2311+{
2312+ unsigned long ret;
2313+
2314+ check_object_size(from, n, true);
2315+ pax_open_userland();
2316+ ret = ___copy_to_user(to, from, n);
2317+ pax_close_userland();
2318+ return ret;
2319+}
2320+
2321 extern unsigned long __must_check __copy_to_user_std(void __user *to, const void *from, unsigned long n);
2322-extern unsigned long __must_check __clear_user(void __user *addr, unsigned long n);
2323+extern unsigned long __must_check ___clear_user(void __user *addr, unsigned long n);
2324 extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned long n);
2325+
2326+static inline unsigned long __must_check __clear_user(void __user *addr, unsigned long n)
2327+{
2328+ unsigned long ret;
2329+ pax_open_userland();
2330+ ret = ___clear_user(addr, n);
2331+ pax_close_userland();
2332+ return ret;
2333+}
2334+
2335 #else
2336 #define __copy_from_user(to,from,n) (memcpy(to, (void __force *)from, n), 0)
2337 #define __copy_to_user(to,from,n) (memcpy((void __force *)to, from, n), 0)
2338@@ -487,6 +565,9 @@ extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned l
2339
2340 static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
2341 {
2342+ if ((long)n < 0)
2343+ return n;
2344+
2345 if (access_ok(VERIFY_READ, from, n))
2346 n = __copy_from_user(to, from, n);
2347 else /* security hole - plug it */
2348@@ -496,6 +577,9 @@ static inline unsigned long __must_check copy_from_user(void *to, const void __u
2349
2350 static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
2351 {
2352+ if ((long)n < 0)
2353+ return n;
2354+
2355 if (access_ok(VERIFY_WRITE, to, n))
2356 n = __copy_to_user(to, from, n);
2357 return n;
2358diff --git a/arch/arm/include/uapi/asm/ptrace.h b/arch/arm/include/uapi/asm/ptrace.h
2359index 5af0ed1..cea83883 100644
2360--- a/arch/arm/include/uapi/asm/ptrace.h
2361+++ b/arch/arm/include/uapi/asm/ptrace.h
2362@@ -92,7 +92,7 @@
2363 * ARMv7 groups of PSR bits
2364 */
2365 #define APSR_MASK 0xf80f0000 /* N, Z, C, V, Q and GE flags */
2366-#define PSR_ISET_MASK 0x01000010 /* ISA state (J, T) mask */
2367+#define PSR_ISET_MASK 0x01000020 /* ISA state (J, T) mask */
2368 #define PSR_IT_MASK 0x0600fc00 /* If-Then execution state mask */
2369 #define PSR_ENDIAN_MASK 0x00000200 /* Endianness state mask */
2370
2371diff --git a/arch/arm/kernel/armksyms.c b/arch/arm/kernel/armksyms.c
2372index a88671c..1cc895e 100644
2373--- a/arch/arm/kernel/armksyms.c
2374+++ b/arch/arm/kernel/armksyms.c
2375@@ -55,7 +55,7 @@ EXPORT_SYMBOL(arm_delay_ops);
2376
2377 /* networking */
2378 EXPORT_SYMBOL(csum_partial);
2379-EXPORT_SYMBOL(csum_partial_copy_from_user);
2380+EXPORT_SYMBOL(__csum_partial_copy_from_user);
2381 EXPORT_SYMBOL(csum_partial_copy_nocheck);
2382 EXPORT_SYMBOL(__csum_ipv6_magic);
2383
2384@@ -91,9 +91,9 @@ EXPORT_SYMBOL(__memzero);
2385 #ifdef CONFIG_MMU
2386 EXPORT_SYMBOL(copy_page);
2387
2388-EXPORT_SYMBOL(__copy_from_user);
2389-EXPORT_SYMBOL(__copy_to_user);
2390-EXPORT_SYMBOL(__clear_user);
2391+EXPORT_SYMBOL(___copy_from_user);
2392+EXPORT_SYMBOL(___copy_to_user);
2393+EXPORT_SYMBOL(___clear_user);
2394
2395 EXPORT_SYMBOL(__get_user_1);
2396 EXPORT_SYMBOL(__get_user_2);
2397diff --git a/arch/arm/kernel/entry-armv.S b/arch/arm/kernel/entry-armv.S
2398index 2f5555d..d493c91 100644
2399--- a/arch/arm/kernel/entry-armv.S
2400+++ b/arch/arm/kernel/entry-armv.S
2401@@ -47,6 +47,87 @@
2402 9997:
2403 .endm
2404
2405+ .macro pax_enter_kernel
2406+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2407+ @ make aligned space for saved DACR
2408+ sub sp, sp, #8
2409+ @ save regs
2410+ stmdb sp!, {r1, r2}
2411+ @ read DACR from cpu_domain into r1
2412+ mov r2, sp
2413+ @ assume 8K pages, since we have to split the immediate in two
2414+ bic r2, r2, #(0x1fc0)
2415+ bic r2, r2, #(0x3f)
2416+ ldr r1, [r2, #TI_CPU_DOMAIN]
2417+ @ store old DACR on stack
2418+ str r1, [sp, #8]
2419+#ifdef CONFIG_PAX_KERNEXEC
2420+ @ set type of DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2421+ bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2422+ orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2423+#endif
2424+#ifdef CONFIG_PAX_MEMORY_UDEREF
2425+ @ set current DOMAIN_USER to DOMAIN_NOACCESS
2426+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2427+#endif
2428+ @ write r1 to current_thread_info()->cpu_domain
2429+ str r1, [r2, #TI_CPU_DOMAIN]
2430+ @ write r1 to DACR
2431+ mcr p15, 0, r1, c3, c0, 0
2432+ @ instruction sync
2433+ instr_sync
2434+ @ restore regs
2435+ ldmia sp!, {r1, r2}
2436+#endif
2437+ .endm
2438+
2439+ .macro pax_open_userland
2440+#ifdef CONFIG_PAX_MEMORY_UDEREF
2441+ @ save regs
2442+ stmdb sp!, {r0, r1}
2443+ @ read DACR from cpu_domain into r1
2444+ mov r0, sp
2445+ @ assume 8K pages, since we have to split the immediate in two
2446+ bic r0, r0, #(0x1fc0)
2447+ bic r0, r0, #(0x3f)
2448+ ldr r1, [r0, #TI_CPU_DOMAIN]
2449+ @ set current DOMAIN_USER to DOMAIN_CLIENT
2450+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2451+ orr r1, r1, #(domain_val(DOMAIN_USER, DOMAIN_UDEREF))
2452+ @ write r1 to current_thread_info()->cpu_domain
2453+ str r1, [r0, #TI_CPU_DOMAIN]
2454+ @ write r1 to DACR
2455+ mcr p15, 0, r1, c3, c0, 0
2456+ @ instruction sync
2457+ instr_sync
2458+ @ restore regs
2459+ ldmia sp!, {r0, r1}
2460+#endif
2461+ .endm
2462+
2463+ .macro pax_close_userland
2464+#ifdef CONFIG_PAX_MEMORY_UDEREF
2465+ @ save regs
2466+ stmdb sp!, {r0, r1}
2467+ @ read DACR from cpu_domain into r1
2468+ mov r0, sp
2469+ @ assume 8K pages, since we have to split the immediate in two
2470+ bic r0, r0, #(0x1fc0)
2471+ bic r0, r0, #(0x3f)
2472+ ldr r1, [r0, #TI_CPU_DOMAIN]
2473+ @ set current DOMAIN_USER to DOMAIN_NOACCESS
2474+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2475+ @ write r1 to current_thread_info()->cpu_domain
2476+ str r1, [r0, #TI_CPU_DOMAIN]
2477+ @ write r1 to DACR
2478+ mcr p15, 0, r1, c3, c0, 0
2479+ @ instruction sync
2480+ instr_sync
2481+ @ restore regs
2482+ ldmia sp!, {r0, r1}
2483+#endif
2484+ .endm
2485+
2486 .macro pabt_helper
2487 @ PABORT handler takes pt_regs in r2, fault address in r4 and psr in r5
2488 #ifdef MULTI_PABORT
2489@@ -89,11 +170,15 @@
2490 * Invalid mode handlers
2491 */
2492 .macro inv_entry, reason
2493+
2494+ pax_enter_kernel
2495+
2496 sub sp, sp, #S_FRAME_SIZE
2497 ARM( stmib sp, {r1 - lr} )
2498 THUMB( stmia sp, {r0 - r12} )
2499 THUMB( str sp, [sp, #S_SP] )
2500 THUMB( str lr, [sp, #S_LR] )
2501+
2502 mov r1, #\reason
2503 .endm
2504
2505@@ -149,7 +234,11 @@ ENDPROC(__und_invalid)
2506 .macro svc_entry, stack_hole=0, trace=1
2507 UNWIND(.fnstart )
2508 UNWIND(.save {r0 - pc} )
2509+
2510+ pax_enter_kernel
2511+
2512 sub sp, sp, #(S_FRAME_SIZE + \stack_hole - 4)
2513+
2514 #ifdef CONFIG_THUMB2_KERNEL
2515 SPFIX( str r0, [sp] ) @ temporarily saved
2516 SPFIX( mov r0, sp )
2517@@ -164,7 +253,12 @@ ENDPROC(__und_invalid)
2518 ldmia r0, {r3 - r5}
2519 add r7, sp, #S_SP - 4 @ here for interlock avoidance
2520 mov r6, #-1 @ "" "" "" ""
2521+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2522+ @ offset sp by 8 as done in pax_enter_kernel
2523+ add r2, sp, #(S_FRAME_SIZE + \stack_hole + 4)
2524+#else
2525 add r2, sp, #(S_FRAME_SIZE + \stack_hole - 4)
2526+#endif
2527 SPFIX( addeq r2, r2, #4 )
2528 str r3, [sp, #-4]! @ save the "real" r0 copied
2529 @ from the exception stack
2530@@ -368,6 +462,9 @@ ENDPROC(__fiq_abt)
2531 .macro usr_entry, trace=1
2532 UNWIND(.fnstart )
2533 UNWIND(.cantunwind ) @ don't unwind the user space
2534+
2535+ pax_enter_kernel_user
2536+
2537 sub sp, sp, #S_FRAME_SIZE
2538 ARM( stmib sp, {r1 - r12} )
2539 THUMB( stmia sp, {r0 - r12} )
2540@@ -478,7 +575,9 @@ __und_usr:
2541 tst r3, #PSR_T_BIT @ Thumb mode?
2542 bne __und_usr_thumb
2543 sub r4, r2, #4 @ ARM instr at LR - 4
2544+ pax_open_userland
2545 1: ldrt r0, [r4]
2546+ pax_close_userland
2547 ARM_BE8(rev r0, r0) @ little endian instruction
2548
2549 @ r0 = 32-bit ARM instruction which caused the exception
2550@@ -512,11 +611,15 @@ __und_usr_thumb:
2551 */
2552 .arch armv6t2
2553 #endif
2554+ pax_open_userland
2555 2: ldrht r5, [r4]
2556+ pax_close_userland
2557 ARM_BE8(rev16 r5, r5) @ little endian instruction
2558 cmp r5, #0xe800 @ 32bit instruction if xx != 0
2559 blo __und_usr_fault_16 @ 16bit undefined instruction
2560+ pax_open_userland
2561 3: ldrht r0, [r2]
2562+ pax_close_userland
2563 ARM_BE8(rev16 r0, r0) @ little endian instruction
2564 add r2, r2, #2 @ r2 is PC + 2, make it PC + 4
2565 str r2, [sp, #S_PC] @ it's a 2x16bit instr, update
2566@@ -546,7 +649,8 @@ ENDPROC(__und_usr)
2567 */
2568 .pushsection .fixup, "ax"
2569 .align 2
2570-4: str r4, [sp, #S_PC] @ retry current instruction
2571+4: pax_close_userland
2572+ str r4, [sp, #S_PC] @ retry current instruction
2573 ret r9
2574 .popsection
2575 .pushsection __ex_table,"a"
2576@@ -766,7 +870,7 @@ ENTRY(__switch_to)
2577 THUMB( str lr, [ip], #4 )
2578 ldr r4, [r2, #TI_TP_VALUE]
2579 ldr r5, [r2, #TI_TP_VALUE + 4]
2580-#ifdef CONFIG_CPU_USE_DOMAINS
2581+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2582 ldr r6, [r2, #TI_CPU_DOMAIN]
2583 #endif
2584 switch_tls r1, r4, r5, r3, r7
2585@@ -775,7 +879,7 @@ ENTRY(__switch_to)
2586 ldr r8, =__stack_chk_guard
2587 ldr r7, [r7, #TSK_STACK_CANARY]
2588 #endif
2589-#ifdef CONFIG_CPU_USE_DOMAINS
2590+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2591 mcr p15, 0, r6, c3, c0, 0 @ Set domain register
2592 #endif
2593 mov r5, r0
2594diff --git a/arch/arm/kernel/entry-common.S b/arch/arm/kernel/entry-common.S
2595index 6bb09d4..113e875 100644
2596--- a/arch/arm/kernel/entry-common.S
2597+++ b/arch/arm/kernel/entry-common.S
2598@@ -11,18 +11,46 @@
2599 #include <asm/assembler.h>
2600 #include <asm/unistd.h>
2601 #include <asm/ftrace.h>
2602+#include <asm/domain.h>
2603 #include <asm/unwind.h>
2604
2605+#include "entry-header.S"
2606+
2607 #ifdef CONFIG_NEED_RET_TO_USER
2608 #include <mach/entry-macro.S>
2609 #else
2610 .macro arch_ret_to_user, tmp1, tmp2
2611+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2612+ @ save regs
2613+ stmdb sp!, {r1, r2}
2614+ @ read DACR from cpu_domain into r1
2615+ mov r2, sp
2616+ @ assume 8K pages, since we have to split the immediate in two
2617+ bic r2, r2, #(0x1fc0)
2618+ bic r2, r2, #(0x3f)
2619+ ldr r1, [r2, #TI_CPU_DOMAIN]
2620+#ifdef CONFIG_PAX_KERNEXEC
2621+ @ set type of DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2622+ bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2623+ orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2624+#endif
2625+#ifdef CONFIG_PAX_MEMORY_UDEREF
2626+ @ set current DOMAIN_USER to DOMAIN_UDEREF
2627+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2628+ orr r1, r1, #(domain_val(DOMAIN_USER, DOMAIN_UDEREF))
2629+#endif
2630+ @ write r1 to current_thread_info()->cpu_domain
2631+ str r1, [r2, #TI_CPU_DOMAIN]
2632+ @ write r1 to DACR
2633+ mcr p15, 0, r1, c3, c0, 0
2634+ @ instruction sync
2635+ instr_sync
2636+ @ restore regs
2637+ ldmia sp!, {r1, r2}
2638+#endif
2639 .endm
2640 #endif
2641
2642-#include "entry-header.S"
2643-
2644-
2645 .align 5
2646 /*
2647 * This is the fast syscall return path. We do as little as
2648@@ -406,6 +434,12 @@ ENTRY(vector_swi)
2649 USER( ldr scno, [lr, #-4] ) @ get SWI instruction
2650 #endif
2651
2652+ /*
2653+ * do this here to avoid a performance hit of wrapping the code above
2654+ * that directly dereferences userland to parse the SWI instruction
2655+ */
2656+ pax_enter_kernel_user
2657+
2658 adr tbl, sys_call_table @ load syscall table pointer
2659
2660 #if defined(CONFIG_OABI_COMPAT)
2661diff --git a/arch/arm/kernel/entry-header.S b/arch/arm/kernel/entry-header.S
2662index 4176df7..a901f8d 100644
2663--- a/arch/arm/kernel/entry-header.S
2664+++ b/arch/arm/kernel/entry-header.S
2665@@ -196,6 +196,60 @@
2666 msr cpsr_c, \rtemp @ switch back to the SVC mode
2667 .endm
2668
2669+ .macro pax_enter_kernel_user
2670+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2671+ @ save regs
2672+ stmdb sp!, {r0, r1}
2673+ @ read DACR from cpu_domain into r1
2674+ mov r0, sp
2675+ @ assume 8K pages, since we have to split the immediate in two
2676+ bic r0, r0, #(0x1fc0)
2677+ bic r0, r0, #(0x3f)
2678+ ldr r1, [r0, #TI_CPU_DOMAIN]
2679+#ifdef CONFIG_PAX_MEMORY_UDEREF
2680+ @ set current DOMAIN_USER to DOMAIN_NOACCESS
2681+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2682+#endif
2683+#ifdef CONFIG_PAX_KERNEXEC
2684+ @ set current DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2685+ bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2686+ orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2687+#endif
2688+ @ write r1 to current_thread_info()->cpu_domain
2689+ str r1, [r0, #TI_CPU_DOMAIN]
2690+ @ write r1 to DACR
2691+ mcr p15, 0, r1, c3, c0, 0
2692+ @ instruction sync
2693+ instr_sync
2694+ @ restore regs
2695+ ldmia sp!, {r0, r1}
2696+#endif
2697+ .endm
2698+
2699+ .macro pax_exit_kernel
2700+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2701+ @ save regs
2702+ stmdb sp!, {r0, r1}
2703+ @ read old DACR from stack into r1
2704+ ldr r1, [sp, #(8 + S_SP)]
2705+ sub r1, r1, #8
2706+ ldr r1, [r1]
2707+
2708+ @ write r1 to current_thread_info()->cpu_domain
2709+ mov r0, sp
2710+ @ assume 8K pages, since we have to split the immediate in two
2711+ bic r0, r0, #(0x1fc0)
2712+ bic r0, r0, #(0x3f)
2713+ str r1, [r0, #TI_CPU_DOMAIN]
2714+ @ write r1 to DACR
2715+ mcr p15, 0, r1, c3, c0, 0
2716+ @ instruction sync
2717+ instr_sync
2718+ @ restore regs
2719+ ldmia sp!, {r0, r1}
2720+#endif
2721+ .endm
2722+
2723 #ifndef CONFIG_THUMB2_KERNEL
2724 .macro svc_exit, rpsr, irq = 0
2725 .if \irq != 0
2726@@ -215,6 +269,9 @@
2727 blne trace_hardirqs_off
2728 #endif
2729 .endif
2730+
2731+ pax_exit_kernel
2732+
2733 msr spsr_cxsf, \rpsr
2734 #if defined(CONFIG_CPU_V6) || defined(CONFIG_CPU_32v6K)
2735 @ We must avoid clrex due to Cortex-A15 erratum #830321
2736@@ -290,6 +347,9 @@
2737 blne trace_hardirqs_off
2738 #endif
2739 .endif
2740+
2741+ pax_exit_kernel
2742+
2743 ldr lr, [sp, #S_SP] @ top of the stack
2744 ldrd r0, r1, [sp, #S_LR] @ calling lr and pc
2745
2746diff --git a/arch/arm/kernel/fiq.c b/arch/arm/kernel/fiq.c
2747index b37752a..ff5cb72 100644
2748--- a/arch/arm/kernel/fiq.c
2749+++ b/arch/arm/kernel/fiq.c
2750@@ -95,7 +95,10 @@ void set_fiq_handler(void *start, unsigned int length)
2751 void *base = vectors_page;
2752 unsigned offset = FIQ_OFFSET;
2753
2754+ pax_open_kernel();
2755 memcpy(base + offset, start, length);
2756+ pax_close_kernel();
2757+
2758 if (!cache_is_vipt_nonaliasing())
2759 flush_icache_range((unsigned long)base + offset, offset +
2760 length);
2761diff --git a/arch/arm/kernel/head.S b/arch/arm/kernel/head.S
2762index 664eee8..f470938 100644
2763--- a/arch/arm/kernel/head.S
2764+++ b/arch/arm/kernel/head.S
2765@@ -437,7 +437,7 @@ __enable_mmu:
2766 mov r5, #(domain_val(DOMAIN_USER, DOMAIN_MANAGER) | \
2767 domain_val(DOMAIN_KERNEL, DOMAIN_MANAGER) | \
2768 domain_val(DOMAIN_TABLE, DOMAIN_MANAGER) | \
2769- domain_val(DOMAIN_IO, DOMAIN_CLIENT))
2770+ domain_val(DOMAIN_IO, DOMAIN_KERNELCLIENT))
2771 mcr p15, 0, r5, c3, c0, 0 @ load domain access register
2772 mcr p15, 0, r4, c2, c0, 0 @ load page table pointer
2773 #endif
2774diff --git a/arch/arm/kernel/module.c b/arch/arm/kernel/module.c
2775index 6a4dffe..4a86a70 100644
2776--- a/arch/arm/kernel/module.c
2777+++ b/arch/arm/kernel/module.c
2778@@ -38,12 +38,39 @@
2779 #endif
2780
2781 #ifdef CONFIG_MMU
2782-void *module_alloc(unsigned long size)
2783+static inline void *__module_alloc(unsigned long size, pgprot_t prot)
2784 {
2785+ if (!size || PAGE_ALIGN(size) > MODULES_END - MODULES_VADDR)
2786+ return NULL;
2787 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
2788- GFP_KERNEL, PAGE_KERNEL_EXEC, NUMA_NO_NODE,
2789+ GFP_KERNEL, prot, NUMA_NO_NODE,
2790 __builtin_return_address(0));
2791 }
2792+
2793+void *module_alloc(unsigned long size)
2794+{
2795+
2796+#ifdef CONFIG_PAX_KERNEXEC
2797+ return __module_alloc(size, PAGE_KERNEL);
2798+#else
2799+ return __module_alloc(size, PAGE_KERNEL_EXEC);
2800+#endif
2801+
2802+}
2803+
2804+#ifdef CONFIG_PAX_KERNEXEC
2805+void module_free_exec(struct module *mod, void *module_region)
2806+{
2807+ module_free(mod, module_region);
2808+}
2809+EXPORT_SYMBOL(module_free_exec);
2810+
2811+void *module_alloc_exec(unsigned long size)
2812+{
2813+ return __module_alloc(size, PAGE_KERNEL_EXEC);
2814+}
2815+EXPORT_SYMBOL(module_alloc_exec);
2816+#endif
2817 #endif
2818
2819 int
2820diff --git a/arch/arm/kernel/patch.c b/arch/arm/kernel/patch.c
2821index 07314af..c46655c 100644
2822--- a/arch/arm/kernel/patch.c
2823+++ b/arch/arm/kernel/patch.c
2824@@ -18,6 +18,7 @@ void __kprobes __patch_text(void *addr, unsigned int insn)
2825 bool thumb2 = IS_ENABLED(CONFIG_THUMB2_KERNEL);
2826 int size;
2827
2828+ pax_open_kernel();
2829 if (thumb2 && __opcode_is_thumb16(insn)) {
2830 *(u16 *)addr = __opcode_to_mem_thumb16(insn);
2831 size = sizeof(u16);
2832@@ -39,6 +40,7 @@ void __kprobes __patch_text(void *addr, unsigned int insn)
2833 *(u32 *)addr = insn;
2834 size = sizeof(u32);
2835 }
2836+ pax_close_kernel();
2837
2838 flush_icache_range((uintptr_t)(addr),
2839 (uintptr_t)(addr) + size);
2840diff --git a/arch/arm/kernel/process.c b/arch/arm/kernel/process.c
2841index fe972a2..a772d83 100644
2842--- a/arch/arm/kernel/process.c
2843+++ b/arch/arm/kernel/process.c
2844@@ -207,6 +207,7 @@ void machine_power_off(void)
2845
2846 if (pm_power_off)
2847 pm_power_off();
2848+ BUG();
2849 }
2850
2851 /*
2852@@ -220,7 +221,7 @@ void machine_power_off(void)
2853 * executing pre-reset code, and using RAM that the primary CPU's code wishes
2854 * to use. Implementing such co-ordination would be essentially impossible.
2855 */
2856-void machine_restart(char *cmd)
2857+__noreturn void machine_restart(char *cmd)
2858 {
2859 local_irq_disable();
2860 smp_send_stop();
2861@@ -246,8 +247,8 @@ void __show_regs(struct pt_regs *regs)
2862
2863 show_regs_print_info(KERN_DEFAULT);
2864
2865- print_symbol("PC is at %s\n", instruction_pointer(regs));
2866- print_symbol("LR is at %s\n", regs->ARM_lr);
2867+ printk("PC is at %pA\n", (void *)instruction_pointer(regs));
2868+ printk("LR is at %pA\n", (void *)regs->ARM_lr);
2869 printk("pc : [<%08lx>] lr : [<%08lx>] psr: %08lx\n"
2870 "sp : %08lx ip : %08lx fp : %08lx\n",
2871 regs->ARM_pc, regs->ARM_lr, regs->ARM_cpsr,
2872@@ -424,12 +425,6 @@ unsigned long get_wchan(struct task_struct *p)
2873 return 0;
2874 }
2875
2876-unsigned long arch_randomize_brk(struct mm_struct *mm)
2877-{
2878- unsigned long range_end = mm->brk + 0x02000000;
2879- return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
2880-}
2881-
2882 #ifdef CONFIG_MMU
2883 #ifdef CONFIG_KUSER_HELPERS
2884 /*
2885@@ -445,7 +440,7 @@ static struct vm_area_struct gate_vma = {
2886
2887 static int __init gate_vma_init(void)
2888 {
2889- gate_vma.vm_page_prot = PAGE_READONLY_EXEC;
2890+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
2891 return 0;
2892 }
2893 arch_initcall(gate_vma_init);
2894@@ -474,81 +469,13 @@ const char *arch_vma_name(struct vm_area_struct *vma)
2895 return is_gate_vma(vma) ? "[vectors]" : NULL;
2896 }
2897
2898-/* If possible, provide a placement hint at a random offset from the
2899- * stack for the signal page.
2900- */
2901-static unsigned long sigpage_addr(const struct mm_struct *mm,
2902- unsigned int npages)
2903-{
2904- unsigned long offset;
2905- unsigned long first;
2906- unsigned long last;
2907- unsigned long addr;
2908- unsigned int slots;
2909-
2910- first = PAGE_ALIGN(mm->start_stack);
2911-
2912- last = TASK_SIZE - (npages << PAGE_SHIFT);
2913-
2914- /* No room after stack? */
2915- if (first > last)
2916- return 0;
2917-
2918- /* Just enough room? */
2919- if (first == last)
2920- return first;
2921-
2922- slots = ((last - first) >> PAGE_SHIFT) + 1;
2923-
2924- offset = get_random_int() % slots;
2925-
2926- addr = first + (offset << PAGE_SHIFT);
2927-
2928- return addr;
2929-}
2930-
2931-static struct page *signal_page;
2932-extern struct page *get_signal_page(void);
2933-
2934-static const struct vm_special_mapping sigpage_mapping = {
2935- .name = "[sigpage]",
2936- .pages = &signal_page,
2937-};
2938-
2939 int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
2940 {
2941 struct mm_struct *mm = current->mm;
2942- struct vm_area_struct *vma;
2943- unsigned long addr;
2944- unsigned long hint;
2945- int ret = 0;
2946-
2947- if (!signal_page)
2948- signal_page = get_signal_page();
2949- if (!signal_page)
2950- return -ENOMEM;
2951
2952 down_write(&mm->mmap_sem);
2953- hint = sigpage_addr(mm, 1);
2954- addr = get_unmapped_area(NULL, hint, PAGE_SIZE, 0, 0);
2955- if (IS_ERR_VALUE(addr)) {
2956- ret = addr;
2957- goto up_fail;
2958- }
2959-
2960- vma = _install_special_mapping(mm, addr, PAGE_SIZE,
2961- VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC,
2962- &sigpage_mapping);
2963-
2964- if (IS_ERR(vma)) {
2965- ret = PTR_ERR(vma);
2966- goto up_fail;
2967- }
2968-
2969- mm->context.sigpage = addr;
2970-
2971- up_fail:
2972+ mm->context.sigpage = (PAGE_OFFSET + (get_random_int() % 0x3FFEFFE0)) & 0xFFFFFFFC;
2973 up_write(&mm->mmap_sem);
2974- return ret;
2975+ return 0;
2976 }
2977 #endif
2978diff --git a/arch/arm/kernel/psci.c b/arch/arm/kernel/psci.c
2979index f73891b..cf3004e 100644
2980--- a/arch/arm/kernel/psci.c
2981+++ b/arch/arm/kernel/psci.c
2982@@ -28,7 +28,7 @@
2983 #include <asm/psci.h>
2984 #include <asm/system_misc.h>
2985
2986-struct psci_operations psci_ops;
2987+struct psci_operations psci_ops __read_only;
2988
2989 static int (*invoke_psci_fn)(u32, u32, u32, u32);
2990 typedef int (*psci_initcall_t)(const struct device_node *);
2991diff --git a/arch/arm/kernel/ptrace.c b/arch/arm/kernel/ptrace.c
2992index ef9119f..31995a3 100644
2993--- a/arch/arm/kernel/ptrace.c
2994+++ b/arch/arm/kernel/ptrace.c
2995@@ -928,10 +928,19 @@ static void tracehook_report_syscall(struct pt_regs *regs,
2996 regs->ARM_ip = ip;
2997 }
2998
2999+#ifdef CONFIG_GRKERNSEC_SETXID
3000+extern void gr_delayed_cred_worker(void);
3001+#endif
3002+
3003 asmlinkage int syscall_trace_enter(struct pt_regs *regs, int scno)
3004 {
3005 current_thread_info()->syscall = scno;
3006
3007+#ifdef CONFIG_GRKERNSEC_SETXID
3008+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
3009+ gr_delayed_cred_worker();
3010+#endif
3011+
3012 /* Do the secure computing check first; failures should be fast. */
3013 #ifdef CONFIG_HAVE_ARCH_SECCOMP_FILTER
3014 if (secure_computing() == -1)
3015diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c
3016index c031063..e277ab8 100644
3017--- a/arch/arm/kernel/setup.c
3018+++ b/arch/arm/kernel/setup.c
3019@@ -104,21 +104,23 @@ EXPORT_SYMBOL(elf_hwcap);
3020 unsigned int elf_hwcap2 __read_mostly;
3021 EXPORT_SYMBOL(elf_hwcap2);
3022
3023+pteval_t __supported_pte_mask __read_only;
3024+pmdval_t __supported_pmd_mask __read_only;
3025
3026 #ifdef MULTI_CPU
3027-struct processor processor __read_mostly;
3028+struct processor processor __read_only;
3029 #endif
3030 #ifdef MULTI_TLB
3031-struct cpu_tlb_fns cpu_tlb __read_mostly;
3032+struct cpu_tlb_fns cpu_tlb __read_only;
3033 #endif
3034 #ifdef MULTI_USER
3035-struct cpu_user_fns cpu_user __read_mostly;
3036+struct cpu_user_fns cpu_user __read_only;
3037 #endif
3038 #ifdef MULTI_CACHE
3039-struct cpu_cache_fns cpu_cache __read_mostly;
3040+struct cpu_cache_fns cpu_cache __read_only;
3041 #endif
3042 #ifdef CONFIG_OUTER_CACHE
3043-struct outer_cache_fns outer_cache __read_mostly;
3044+struct outer_cache_fns outer_cache __read_only;
3045 EXPORT_SYMBOL(outer_cache);
3046 #endif
3047
3048@@ -252,9 +254,13 @@ static int __get_cpu_architecture(void)
3049 asm("mrc p15, 0, %0, c0, c1, 4"
3050 : "=r" (mmfr0));
3051 if ((mmfr0 & 0x0000000f) >= 0x00000003 ||
3052- (mmfr0 & 0x000000f0) >= 0x00000030)
3053+ (mmfr0 & 0x000000f0) >= 0x00000030) {
3054 cpu_arch = CPU_ARCH_ARMv7;
3055- else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
3056+ if ((mmfr0 & 0x0000000f) == 0x00000005 || (mmfr0 & 0x0000000f) == 0x00000004) {
3057+ __supported_pte_mask |= L_PTE_PXN;
3058+ __supported_pmd_mask |= PMD_PXNTABLE;
3059+ }
3060+ } else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
3061 (mmfr0 & 0x000000f0) == 0x00000020)
3062 cpu_arch = CPU_ARCH_ARMv6;
3063 else
3064diff --git a/arch/arm/kernel/signal.c b/arch/arm/kernel/signal.c
3065index bd19834..e4d8c66 100644
3066--- a/arch/arm/kernel/signal.c
3067+++ b/arch/arm/kernel/signal.c
3068@@ -24,8 +24,6 @@
3069
3070 extern const unsigned long sigreturn_codes[7];
3071
3072-static unsigned long signal_return_offset;
3073-
3074 #ifdef CONFIG_CRUNCH
3075 static int preserve_crunch_context(struct crunch_sigframe __user *frame)
3076 {
3077@@ -396,8 +394,7 @@ setup_return(struct pt_regs *regs, struct ksignal *ksig,
3078 * except when the MPU has protected the vectors
3079 * page from PL0
3080 */
3081- retcode = mm->context.sigpage + signal_return_offset +
3082- (idx << 2) + thumb;
3083+ retcode = mm->context.sigpage + (idx << 2) + thumb;
3084 } else
3085 #endif
3086 {
3087@@ -604,33 +601,3 @@ do_work_pending(struct pt_regs *regs, unsigned int thread_flags, int syscall)
3088 } while (thread_flags & _TIF_WORK_MASK);
3089 return 0;
3090 }
3091-
3092-struct page *get_signal_page(void)
3093-{
3094- unsigned long ptr;
3095- unsigned offset;
3096- struct page *page;
3097- void *addr;
3098-
3099- page = alloc_pages(GFP_KERNEL, 0);
3100-
3101- if (!page)
3102- return NULL;
3103-
3104- addr = page_address(page);
3105-
3106- /* Give the signal return code some randomness */
3107- offset = 0x200 + (get_random_int() & 0x7fc);
3108- signal_return_offset = offset;
3109-
3110- /*
3111- * Copy signal return handlers into the vector page, and
3112- * set sigreturn to be a pointer to these.
3113- */
3114- memcpy(addr + offset, sigreturn_codes, sizeof(sigreturn_codes));
3115-
3116- ptr = (unsigned long)addr + offset;
3117- flush_icache_range(ptr, ptr + sizeof(sigreturn_codes));
3118-
3119- return page;
3120-}
3121diff --git a/arch/arm/kernel/smp.c b/arch/arm/kernel/smp.c
3122index 13396d3..589d615 100644
3123--- a/arch/arm/kernel/smp.c
3124+++ b/arch/arm/kernel/smp.c
3125@@ -76,7 +76,7 @@ enum ipi_msg_type {
3126
3127 static DECLARE_COMPLETION(cpu_running);
3128
3129-static struct smp_operations smp_ops;
3130+static struct smp_operations smp_ops __read_only;
3131
3132 void __init smp_set_ops(struct smp_operations *ops)
3133 {
3134diff --git a/arch/arm/kernel/tcm.c b/arch/arm/kernel/tcm.c
3135index 7a3be1d..b00c7de 100644
3136--- a/arch/arm/kernel/tcm.c
3137+++ b/arch/arm/kernel/tcm.c
3138@@ -61,7 +61,7 @@ static struct map_desc itcm_iomap[] __initdata = {
3139 .virtual = ITCM_OFFSET,
3140 .pfn = __phys_to_pfn(ITCM_OFFSET),
3141 .length = 0,
3142- .type = MT_MEMORY_RWX_ITCM,
3143+ .type = MT_MEMORY_RX_ITCM,
3144 }
3145 };
3146
3147@@ -267,7 +267,9 @@ no_dtcm:
3148 start = &__sitcm_text;
3149 end = &__eitcm_text;
3150 ram = &__itcm_start;
3151+ pax_open_kernel();
3152 memcpy(start, ram, itcm_code_sz);
3153+ pax_close_kernel();
3154 pr_debug("CPU ITCM: copied code from %p - %p\n",
3155 start, end);
3156 itcm_present = true;
3157diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c
3158index 9f5d818..e013427 100644
3159--- a/arch/arm/kernel/traps.c
3160+++ b/arch/arm/kernel/traps.c
3161@@ -65,7 +65,7 @@ static void dump_mem(const char *, const char *, unsigned long, unsigned long);
3162 void dump_backtrace_entry(unsigned long where, unsigned long from, unsigned long frame)
3163 {
3164 #ifdef CONFIG_KALLSYMS
3165- printk("[<%08lx>] (%ps) from [<%08lx>] (%pS)\n", where, (void *)where, from, (void *)from);
3166+ printk("[<%08lx>] (%pA) from [<%08lx>] (%pA)\n", where, (void *)where, from, (void *)from);
3167 #else
3168 printk("Function entered at [<%08lx>] from [<%08lx>]\n", where, from);
3169 #endif
3170@@ -267,6 +267,8 @@ static arch_spinlock_t die_lock = __ARCH_SPIN_LOCK_UNLOCKED;
3171 static int die_owner = -1;
3172 static unsigned int die_nest_count;
3173
3174+extern void gr_handle_kernel_exploit(void);
3175+
3176 static unsigned long oops_begin(void)
3177 {
3178 int cpu;
3179@@ -309,6 +311,9 @@ static void oops_end(unsigned long flags, struct pt_regs *regs, int signr)
3180 panic("Fatal exception in interrupt");
3181 if (panic_on_oops)
3182 panic("Fatal exception");
3183+
3184+ gr_handle_kernel_exploit();
3185+
3186 if (signr)
3187 do_exit(signr);
3188 }
3189@@ -880,7 +885,11 @@ void __init early_trap_init(void *vectors_base)
3190 kuser_init(vectors_base);
3191
3192 flush_icache_range(vectors, vectors + PAGE_SIZE * 2);
3193- modify_domain(DOMAIN_USER, DOMAIN_CLIENT);
3194+
3195+#ifndef CONFIG_PAX_MEMORY_UDEREF
3196+ modify_domain(DOMAIN_USER, DOMAIN_USERCLIENT);
3197+#endif
3198+
3199 #else /* ifndef CONFIG_CPU_V7M */
3200 /*
3201 * on V7-M there is no need to copy the vector table to a dedicated
3202diff --git a/arch/arm/kernel/vmlinux.lds.S b/arch/arm/kernel/vmlinux.lds.S
3203index 8e95aa4..595dfc8 100644
3204--- a/arch/arm/kernel/vmlinux.lds.S
3205+++ b/arch/arm/kernel/vmlinux.lds.S
3206@@ -8,7 +8,11 @@
3207 #include <asm/thread_info.h>
3208 #include <asm/memory.h>
3209 #include <asm/page.h>
3210-
3211+
3212+#ifdef CONFIG_PAX_KERNEXEC
3213+#include <asm/pgtable.h>
3214+#endif
3215+
3216 #define PROC_INFO \
3217 . = ALIGN(4); \
3218 VMLINUX_SYMBOL(__proc_info_begin) = .; \
3219@@ -34,7 +38,7 @@
3220 #endif
3221
3222 #if (defined(CONFIG_SMP_ON_UP) && !defined(CONFIG_DEBUG_SPINLOCK)) || \
3223- defined(CONFIG_GENERIC_BUG)
3224+ defined(CONFIG_GENERIC_BUG) || defined(CONFIG_PAX_REFCOUNT)
3225 #define ARM_EXIT_KEEP(x) x
3226 #define ARM_EXIT_DISCARD(x)
3227 #else
3228@@ -90,6 +94,11 @@ SECTIONS
3229 _text = .;
3230 HEAD_TEXT
3231 }
3232+
3233+#ifdef CONFIG_PAX_KERNEXEC
3234+ . = ALIGN(1<<SECTION_SHIFT);
3235+#endif
3236+
3237 .text : { /* Real text segment */
3238 _stext = .; /* Text and read-only data */
3239 __exception_text_start = .;
3240@@ -112,6 +121,8 @@ SECTIONS
3241 ARM_CPU_KEEP(PROC_INFO)
3242 }
3243
3244+ _etext = .; /* End of text section */
3245+
3246 RO_DATA(PAGE_SIZE)
3247
3248 . = ALIGN(4);
3249@@ -142,7 +153,9 @@ SECTIONS
3250
3251 NOTES
3252
3253- _etext = .; /* End of text and rodata section */
3254+#ifdef CONFIG_PAX_KERNEXEC
3255+ . = ALIGN(1<<SECTION_SHIFT);
3256+#endif
3257
3258 #ifndef CONFIG_XIP_KERNEL
3259 . = ALIGN(PAGE_SIZE);
3260@@ -221,6 +234,11 @@ SECTIONS
3261 #else
3262 . = ALIGN(THREAD_SIZE);
3263 __init_end = .;
3264+
3265+#ifdef CONFIG_PAX_KERNEXEC
3266+ . = ALIGN(1<<SECTION_SHIFT);
3267+#endif
3268+
3269 __data_loc = .;
3270 #endif
3271
3272diff --git a/arch/arm/kvm/arm.c b/arch/arm/kvm/arm.c
3273index 9e193c8..3560fe6 100644
3274--- a/arch/arm/kvm/arm.c
3275+++ b/arch/arm/kvm/arm.c
3276@@ -57,7 +57,7 @@ static unsigned long hyp_default_vectors;
3277 static DEFINE_PER_CPU(struct kvm_vcpu *, kvm_arm_running_vcpu);
3278
3279 /* The VMID used in the VTTBR */
3280-static atomic64_t kvm_vmid_gen = ATOMIC64_INIT(1);
3281+static atomic64_unchecked_t kvm_vmid_gen = ATOMIC64_INIT(1);
3282 static u8 kvm_next_vmid;
3283 static DEFINE_SPINLOCK(kvm_vmid_lock);
3284
3285@@ -354,7 +354,7 @@ void force_vm_exit(const cpumask_t *mask)
3286 */
3287 static bool need_new_vmid_gen(struct kvm *kvm)
3288 {
3289- return unlikely(kvm->arch.vmid_gen != atomic64_read(&kvm_vmid_gen));
3290+ return unlikely(kvm->arch.vmid_gen != atomic64_read_unchecked(&kvm_vmid_gen));
3291 }
3292
3293 /**
3294@@ -387,7 +387,7 @@ static void update_vttbr(struct kvm *kvm)
3295
3296 /* First user of a new VMID generation? */
3297 if (unlikely(kvm_next_vmid == 0)) {
3298- atomic64_inc(&kvm_vmid_gen);
3299+ atomic64_inc_unchecked(&kvm_vmid_gen);
3300 kvm_next_vmid = 1;
3301
3302 /*
3303@@ -404,7 +404,7 @@ static void update_vttbr(struct kvm *kvm)
3304 kvm_call_hyp(__kvm_flush_vm_context);
3305 }
3306
3307- kvm->arch.vmid_gen = atomic64_read(&kvm_vmid_gen);
3308+ kvm->arch.vmid_gen = atomic64_read_unchecked(&kvm_vmid_gen);
3309 kvm->arch.vmid = kvm_next_vmid;
3310 kvm_next_vmid++;
3311
3312@@ -980,7 +980,7 @@ static void check_kvm_target_cpu(void *ret)
3313 /**
3314 * Initialize Hyp-mode and memory mappings on all CPUs.
3315 */
3316-int kvm_arch_init(void *opaque)
3317+int kvm_arch_init(const void *opaque)
3318 {
3319 int err;
3320 int ret, cpu;
3321diff --git a/arch/arm/lib/clear_user.S b/arch/arm/lib/clear_user.S
3322index 14a0d98..7771a7d 100644
3323--- a/arch/arm/lib/clear_user.S
3324+++ b/arch/arm/lib/clear_user.S
3325@@ -12,14 +12,14 @@
3326
3327 .text
3328
3329-/* Prototype: int __clear_user(void *addr, size_t sz)
3330+/* Prototype: int ___clear_user(void *addr, size_t sz)
3331 * Purpose : clear some user memory
3332 * Params : addr - user memory address to clear
3333 * : sz - number of bytes to clear
3334 * Returns : number of bytes NOT cleared
3335 */
3336 ENTRY(__clear_user_std)
3337-WEAK(__clear_user)
3338+WEAK(___clear_user)
3339 stmfd sp!, {r1, lr}
3340 mov r2, #0
3341 cmp r1, #4
3342@@ -44,7 +44,7 @@ WEAK(__clear_user)
3343 USER( strnebt r2, [r0])
3344 mov r0, #0
3345 ldmfd sp!, {r1, pc}
3346-ENDPROC(__clear_user)
3347+ENDPROC(___clear_user)
3348 ENDPROC(__clear_user_std)
3349
3350 .pushsection .fixup,"ax"
3351diff --git a/arch/arm/lib/copy_from_user.S b/arch/arm/lib/copy_from_user.S
3352index 66a477a..bee61d3 100644
3353--- a/arch/arm/lib/copy_from_user.S
3354+++ b/arch/arm/lib/copy_from_user.S
3355@@ -16,7 +16,7 @@
3356 /*
3357 * Prototype:
3358 *
3359- * size_t __copy_from_user(void *to, const void *from, size_t n)
3360+ * size_t ___copy_from_user(void *to, const void *from, size_t n)
3361 *
3362 * Purpose:
3363 *
3364@@ -84,11 +84,11 @@
3365
3366 .text
3367
3368-ENTRY(__copy_from_user)
3369+ENTRY(___copy_from_user)
3370
3371 #include "copy_template.S"
3372
3373-ENDPROC(__copy_from_user)
3374+ENDPROC(___copy_from_user)
3375
3376 .pushsection .fixup,"ax"
3377 .align 0
3378diff --git a/arch/arm/lib/copy_page.S b/arch/arm/lib/copy_page.S
3379index 6ee2f67..d1cce76 100644
3380--- a/arch/arm/lib/copy_page.S
3381+++ b/arch/arm/lib/copy_page.S
3382@@ -10,6 +10,7 @@
3383 * ASM optimised string functions
3384 */
3385 #include <linux/linkage.h>
3386+#include <linux/const.h>
3387 #include <asm/assembler.h>
3388 #include <asm/asm-offsets.h>
3389 #include <asm/cache.h>
3390diff --git a/arch/arm/lib/copy_to_user.S b/arch/arm/lib/copy_to_user.S
3391index d066df6..df28194 100644
3392--- a/arch/arm/lib/copy_to_user.S
3393+++ b/arch/arm/lib/copy_to_user.S
3394@@ -16,7 +16,7 @@
3395 /*
3396 * Prototype:
3397 *
3398- * size_t __copy_to_user(void *to, const void *from, size_t n)
3399+ * size_t ___copy_to_user(void *to, const void *from, size_t n)
3400 *
3401 * Purpose:
3402 *
3403@@ -88,11 +88,11 @@
3404 .text
3405
3406 ENTRY(__copy_to_user_std)
3407-WEAK(__copy_to_user)
3408+WEAK(___copy_to_user)
3409
3410 #include "copy_template.S"
3411
3412-ENDPROC(__copy_to_user)
3413+ENDPROC(___copy_to_user)
3414 ENDPROC(__copy_to_user_std)
3415
3416 .pushsection .fixup,"ax"
3417diff --git a/arch/arm/lib/csumpartialcopyuser.S b/arch/arm/lib/csumpartialcopyuser.S
3418index 7d08b43..f7ca7ea 100644
3419--- a/arch/arm/lib/csumpartialcopyuser.S
3420+++ b/arch/arm/lib/csumpartialcopyuser.S
3421@@ -57,8 +57,8 @@
3422 * Returns : r0 = checksum, [[sp, #0], #0] = 0 or -EFAULT
3423 */
3424
3425-#define FN_ENTRY ENTRY(csum_partial_copy_from_user)
3426-#define FN_EXIT ENDPROC(csum_partial_copy_from_user)
3427+#define FN_ENTRY ENTRY(__csum_partial_copy_from_user)
3428+#define FN_EXIT ENDPROC(__csum_partial_copy_from_user)
3429
3430 #include "csumpartialcopygeneric.S"
3431
3432diff --git a/arch/arm/lib/delay.c b/arch/arm/lib/delay.c
3433index 312d43e..21d2322 100644
3434--- a/arch/arm/lib/delay.c
3435+++ b/arch/arm/lib/delay.c
3436@@ -29,7 +29,7 @@
3437 /*
3438 * Default to the loop-based delay implementation.
3439 */
3440-struct arm_delay_ops arm_delay_ops = {
3441+struct arm_delay_ops arm_delay_ops __read_only = {
3442 .delay = __loop_delay,
3443 .const_udelay = __loop_const_udelay,
3444 .udelay = __loop_udelay,
3445diff --git a/arch/arm/lib/uaccess_with_memcpy.c b/arch/arm/lib/uaccess_with_memcpy.c
3446index 3e58d71..029817c 100644
3447--- a/arch/arm/lib/uaccess_with_memcpy.c
3448+++ b/arch/arm/lib/uaccess_with_memcpy.c
3449@@ -136,7 +136,7 @@ out:
3450 }
3451
3452 unsigned long
3453-__copy_to_user(void __user *to, const void *from, unsigned long n)
3454+___copy_to_user(void __user *to, const void *from, unsigned long n)
3455 {
3456 /*
3457 * This test is stubbed out of the main function above to keep
3458@@ -190,7 +190,7 @@ out:
3459 return n;
3460 }
3461
3462-unsigned long __clear_user(void __user *addr, unsigned long n)
3463+unsigned long ___clear_user(void __user *addr, unsigned long n)
3464 {
3465 /* See rational for this in __copy_to_user() above. */
3466 if (n < 64)
3467diff --git a/arch/arm/mach-at91/setup.c b/arch/arm/mach-at91/setup.c
3468index 9610792..4dfb851 100644
3469--- a/arch/arm/mach-at91/setup.c
3470+++ b/arch/arm/mach-at91/setup.c
3471@@ -83,7 +83,7 @@ void __init at91_init_sram(int bank, unsigned long base, unsigned int length)
3472
3473 desc->pfn = __phys_to_pfn(base);
3474 desc->length = length;
3475- desc->type = MT_MEMORY_RWX_NONCACHED;
3476+ desc->type = MT_MEMORY_RW_NONCACHED;
3477
3478 pr_info("sram at 0x%lx of 0x%x mapped at 0x%lx\n",
3479 base, length, desc->virtual);
3480diff --git a/arch/arm/mach-keystone/keystone.c b/arch/arm/mach-keystone/keystone.c
3481index 7f352de..6dc0929 100644
3482--- a/arch/arm/mach-keystone/keystone.c
3483+++ b/arch/arm/mach-keystone/keystone.c
3484@@ -27,7 +27,7 @@
3485
3486 #include "keystone.h"
3487
3488-static struct notifier_block platform_nb;
3489+static notifier_block_no_const platform_nb;
3490 static unsigned long keystone_dma_pfn_offset __read_mostly;
3491
3492 static int keystone_platform_notifier(struct notifier_block *nb,
3493diff --git a/arch/arm/mach-mvebu/coherency.c b/arch/arm/mach-mvebu/coherency.c
3494index 044b511..afd1da8 100644
3495--- a/arch/arm/mach-mvebu/coherency.c
3496+++ b/arch/arm/mach-mvebu/coherency.c
3497@@ -316,7 +316,7 @@ static void __init armada_370_coherency_init(struct device_node *np)
3498
3499 /*
3500 * This ioremap hook is used on Armada 375/38x to ensure that PCIe
3501- * memory areas are mapped as MT_UNCACHED instead of MT_DEVICE. This
3502+ * memory areas are mapped as MT_UNCACHED_RW instead of MT_DEVICE. This
3503 * is needed as a workaround for a deadlock issue between the PCIe
3504 * interface and the cache controller.
3505 */
3506@@ -329,7 +329,7 @@ armada_pcie_wa_ioremap_caller(phys_addr_t phys_addr, size_t size,
3507 mvebu_mbus_get_pcie_mem_aperture(&pcie_mem);
3508
3509 if (pcie_mem.start <= phys_addr && (phys_addr + size) <= pcie_mem.end)
3510- mtype = MT_UNCACHED;
3511+ mtype = MT_UNCACHED_RW;
3512
3513 return __arm_ioremap_caller(phys_addr, size, mtype, caller);
3514 }
3515diff --git a/arch/arm/mach-omap2/board-n8x0.c b/arch/arm/mach-omap2/board-n8x0.c
3516index 97767a2..9233746 100644
3517--- a/arch/arm/mach-omap2/board-n8x0.c
3518+++ b/arch/arm/mach-omap2/board-n8x0.c
3519@@ -569,7 +569,7 @@ static int n8x0_menelaus_late_init(struct device *dev)
3520 }
3521 #endif
3522
3523-struct menelaus_platform_data n8x0_menelaus_platform_data __initdata = {
3524+struct menelaus_platform_data n8x0_menelaus_platform_data __initconst = {
3525 .late_init = n8x0_menelaus_late_init,
3526 };
3527
3528diff --git a/arch/arm/mach-omap2/gpmc.c b/arch/arm/mach-omap2/gpmc.c
3529index 5fa3755..1e8c247 100644
3530--- a/arch/arm/mach-omap2/gpmc.c
3531+++ b/arch/arm/mach-omap2/gpmc.c
3532@@ -151,7 +151,6 @@ struct omap3_gpmc_regs {
3533 };
3534
3535 static struct gpmc_client_irq gpmc_client_irq[GPMC_NR_IRQ];
3536-static struct irq_chip gpmc_irq_chip;
3537 static int gpmc_irq_start;
3538
3539 static struct resource gpmc_mem_root;
3540@@ -736,6 +735,18 @@ static void gpmc_irq_noop(struct irq_data *data) { }
3541
3542 static unsigned int gpmc_irq_noop_ret(struct irq_data *data) { return 0; }
3543
3544+static struct irq_chip gpmc_irq_chip = {
3545+ .name = "gpmc",
3546+ .irq_startup = gpmc_irq_noop_ret,
3547+ .irq_enable = gpmc_irq_enable,
3548+ .irq_disable = gpmc_irq_disable,
3549+ .irq_shutdown = gpmc_irq_noop,
3550+ .irq_ack = gpmc_irq_noop,
3551+ .irq_mask = gpmc_irq_noop,
3552+ .irq_unmask = gpmc_irq_noop,
3553+
3554+};
3555+
3556 static int gpmc_setup_irq(void)
3557 {
3558 int i;
3559@@ -750,15 +761,6 @@ static int gpmc_setup_irq(void)
3560 return gpmc_irq_start;
3561 }
3562
3563- gpmc_irq_chip.name = "gpmc";
3564- gpmc_irq_chip.irq_startup = gpmc_irq_noop_ret;
3565- gpmc_irq_chip.irq_enable = gpmc_irq_enable;
3566- gpmc_irq_chip.irq_disable = gpmc_irq_disable;
3567- gpmc_irq_chip.irq_shutdown = gpmc_irq_noop;
3568- gpmc_irq_chip.irq_ack = gpmc_irq_noop;
3569- gpmc_irq_chip.irq_mask = gpmc_irq_noop;
3570- gpmc_irq_chip.irq_unmask = gpmc_irq_noop;
3571-
3572 gpmc_client_irq[0].bitmask = GPMC_IRQ_FIFOEVENTENABLE;
3573 gpmc_client_irq[1].bitmask = GPMC_IRQ_COUNT_EVENT;
3574
3575diff --git a/arch/arm/mach-omap2/omap-mpuss-lowpower.c b/arch/arm/mach-omap2/omap-mpuss-lowpower.c
3576index 6944ae3..bc587ca 100644
3577--- a/arch/arm/mach-omap2/omap-mpuss-lowpower.c
3578+++ b/arch/arm/mach-omap2/omap-mpuss-lowpower.c
3579@@ -86,7 +86,7 @@ struct cpu_pm_ops {
3580 void (*resume)(void);
3581 void (*scu_prepare)(unsigned int cpu_id, unsigned int cpu_state);
3582 void (*hotplug_restart)(void);
3583-};
3584+} __no_const;
3585
3586 static DEFINE_PER_CPU(struct omap4_cpu_pm_info, omap4_pm_info);
3587 static struct powerdomain *mpuss_pd;
3588@@ -105,7 +105,7 @@ static void dummy_cpu_resume(void)
3589 static void dummy_scu_prepare(unsigned int cpu_id, unsigned int cpu_state)
3590 {}
3591
3592-struct cpu_pm_ops omap_pm_ops = {
3593+static struct cpu_pm_ops omap_pm_ops __read_only = {
3594 .finish_suspend = default_finish_suspend,
3595 .resume = dummy_cpu_resume,
3596 .scu_prepare = dummy_scu_prepare,
3597diff --git a/arch/arm/mach-omap2/omap-wakeupgen.c b/arch/arm/mach-omap2/omap-wakeupgen.c
3598index f961c46..4a453dc 100644
3599--- a/arch/arm/mach-omap2/omap-wakeupgen.c
3600+++ b/arch/arm/mach-omap2/omap-wakeupgen.c
3601@@ -344,7 +344,7 @@ static int irq_cpu_hotplug_notify(struct notifier_block *self,
3602 return NOTIFY_OK;
3603 }
3604
3605-static struct notifier_block __refdata irq_hotplug_notifier = {
3606+static struct notifier_block irq_hotplug_notifier = {
3607 .notifier_call = irq_cpu_hotplug_notify,
3608 };
3609
3610diff --git a/arch/arm/mach-omap2/omap_device.c b/arch/arm/mach-omap2/omap_device.c
3611index 8c58b71..95b655f 100644
3612--- a/arch/arm/mach-omap2/omap_device.c
3613+++ b/arch/arm/mach-omap2/omap_device.c
3614@@ -510,7 +510,7 @@ void omap_device_delete(struct omap_device *od)
3615 struct platform_device __init *omap_device_build(const char *pdev_name,
3616 int pdev_id,
3617 struct omap_hwmod *oh,
3618- void *pdata, int pdata_len)
3619+ const void *pdata, int pdata_len)
3620 {
3621 struct omap_hwmod *ohs[] = { oh };
3622
3623@@ -538,7 +538,7 @@ struct platform_device __init *omap_device_build(const char *pdev_name,
3624 struct platform_device __init *omap_device_build_ss(const char *pdev_name,
3625 int pdev_id,
3626 struct omap_hwmod **ohs,
3627- int oh_cnt, void *pdata,
3628+ int oh_cnt, const void *pdata,
3629 int pdata_len)
3630 {
3631 int ret = -ENOMEM;
3632diff --git a/arch/arm/mach-omap2/omap_device.h b/arch/arm/mach-omap2/omap_device.h
3633index 78c02b3..c94109a 100644
3634--- a/arch/arm/mach-omap2/omap_device.h
3635+++ b/arch/arm/mach-omap2/omap_device.h
3636@@ -72,12 +72,12 @@ int omap_device_idle(struct platform_device *pdev);
3637 /* Core code interface */
3638
3639 struct platform_device *omap_device_build(const char *pdev_name, int pdev_id,
3640- struct omap_hwmod *oh, void *pdata,
3641+ struct omap_hwmod *oh, const void *pdata,
3642 int pdata_len);
3643
3644 struct platform_device *omap_device_build_ss(const char *pdev_name, int pdev_id,
3645 struct omap_hwmod **oh, int oh_cnt,
3646- void *pdata, int pdata_len);
3647+ const void *pdata, int pdata_len);
3648
3649 struct omap_device *omap_device_alloc(struct platform_device *pdev,
3650 struct omap_hwmod **ohs, int oh_cnt);
3651diff --git a/arch/arm/mach-omap2/omap_hwmod.c b/arch/arm/mach-omap2/omap_hwmod.c
3652index 716247e..8df346d 100644
3653--- a/arch/arm/mach-omap2/omap_hwmod.c
3654+++ b/arch/arm/mach-omap2/omap_hwmod.c
3655@@ -194,10 +194,10 @@ struct omap_hwmod_soc_ops {
3656 int (*init_clkdm)(struct omap_hwmod *oh);
3657 void (*update_context_lost)(struct omap_hwmod *oh);
3658 int (*get_context_lost)(struct omap_hwmod *oh);
3659-};
3660+} __no_const;
3661
3662 /* soc_ops: adapts the omap_hwmod code to the currently-booted SoC */
3663-static struct omap_hwmod_soc_ops soc_ops;
3664+static struct omap_hwmod_soc_ops soc_ops __read_only;
3665
3666 /* omap_hwmod_list contains all registered struct omap_hwmods */
3667 static LIST_HEAD(omap_hwmod_list);
3668diff --git a/arch/arm/mach-omap2/powerdomains43xx_data.c b/arch/arm/mach-omap2/powerdomains43xx_data.c
3669index 95fee54..cfa9cf1 100644
3670--- a/arch/arm/mach-omap2/powerdomains43xx_data.c
3671+++ b/arch/arm/mach-omap2/powerdomains43xx_data.c
3672@@ -10,6 +10,7 @@
3673
3674 #include <linux/kernel.h>
3675 #include <linux/init.h>
3676+#include <asm/pgtable.h>
3677
3678 #include "powerdomain.h"
3679
3680@@ -129,7 +130,9 @@ static int am43xx_check_vcvp(void)
3681
3682 void __init am43xx_powerdomains_init(void)
3683 {
3684- omap4_pwrdm_operations.pwrdm_has_voltdm = am43xx_check_vcvp;
3685+ pax_open_kernel();
3686+ *(void **)&omap4_pwrdm_operations.pwrdm_has_voltdm = am43xx_check_vcvp;
3687+ pax_close_kernel();
3688 pwrdm_register_platform_funcs(&omap4_pwrdm_operations);
3689 pwrdm_register_pwrdms(powerdomains_am43xx);
3690 pwrdm_complete_init();
3691diff --git a/arch/arm/mach-omap2/wd_timer.c b/arch/arm/mach-omap2/wd_timer.c
3692index ff0a68c..b312aa0 100644
3693--- a/arch/arm/mach-omap2/wd_timer.c
3694+++ b/arch/arm/mach-omap2/wd_timer.c
3695@@ -110,7 +110,9 @@ static int __init omap_init_wdt(void)
3696 struct omap_hwmod *oh;
3697 char *oh_name = "wd_timer2";
3698 char *dev_name = "omap_wdt";
3699- struct omap_wd_timer_platform_data pdata;
3700+ static struct omap_wd_timer_platform_data pdata = {
3701+ .read_reset_sources = prm_read_reset_sources
3702+ };
3703
3704 if (!cpu_class_is_omap2() || of_have_populated_dt())
3705 return 0;
3706@@ -121,8 +123,6 @@ static int __init omap_init_wdt(void)
3707 return -EINVAL;
3708 }
3709
3710- pdata.read_reset_sources = prm_read_reset_sources;
3711-
3712 pdev = omap_device_build(dev_name, id, oh, &pdata,
3713 sizeof(struct omap_wd_timer_platform_data));
3714 WARN(IS_ERR(pdev), "Can't build omap_device for %s:%s.\n",
3715diff --git a/arch/arm/mach-tegra/cpuidle-tegra20.c b/arch/arm/mach-tegra/cpuidle-tegra20.c
3716index b30bf5c..d0825bf 100644
3717--- a/arch/arm/mach-tegra/cpuidle-tegra20.c
3718+++ b/arch/arm/mach-tegra/cpuidle-tegra20.c
3719@@ -180,7 +180,7 @@ static int tegra20_idle_lp2_coupled(struct cpuidle_device *dev,
3720 bool entered_lp2 = false;
3721
3722 if (tegra_pending_sgi())
3723- ACCESS_ONCE(abort_flag) = true;
3724+ ACCESS_ONCE_RW(abort_flag) = true;
3725
3726 cpuidle_coupled_parallel_barrier(dev, &abort_barrier);
3727
3728diff --git a/arch/arm/mach-ux500/setup.h b/arch/arm/mach-ux500/setup.h
3729index 2dea8b5..6499da2 100644
3730--- a/arch/arm/mach-ux500/setup.h
3731+++ b/arch/arm/mach-ux500/setup.h
3732@@ -33,13 +33,6 @@ extern void ux500_timer_init(void);
3733 .type = MT_DEVICE, \
3734 }
3735
3736-#define __MEM_DEV_DESC(x, sz) { \
3737- .virtual = IO_ADDRESS(x), \
3738- .pfn = __phys_to_pfn(x), \
3739- .length = sz, \
3740- .type = MT_MEMORY_RWX, \
3741-}
3742-
3743 extern struct smp_operations ux500_smp_ops;
3744 extern void ux500_cpu_die(unsigned int cpu);
3745
3746diff --git a/arch/arm/mm/Kconfig b/arch/arm/mm/Kconfig
3747index 7eb94e6..799ad3e 100644
3748--- a/arch/arm/mm/Kconfig
3749+++ b/arch/arm/mm/Kconfig
3750@@ -446,6 +446,7 @@ config CPU_32v5
3751
3752 config CPU_32v6
3753 bool
3754+ select CPU_USE_DOMAINS if CPU_V6 && MMU && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
3755 select TLS_REG_EMUL if !CPU_32v6K && !MMU
3756
3757 config CPU_32v6K
3758@@ -600,6 +601,7 @@ config CPU_CP15_MPU
3759
3760 config CPU_USE_DOMAINS
3761 bool
3762+ depends on !ARM_LPAE && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
3763 help
3764 This option enables or disables the use of domain switching
3765 via the set_fs() function.
3766@@ -798,7 +800,7 @@ config NEED_KUSER_HELPERS
3767
3768 config KUSER_HELPERS
3769 bool "Enable kuser helpers in vector page" if !NEED_KUSER_HELPERS
3770- depends on MMU
3771+ depends on MMU && (!(CPU_V6 || CPU_V6K || CPU_V7) || GRKERNSEC_OLD_ARM_USERLAND)
3772 default y
3773 help
3774 Warning: disabling this option may break user programs.
3775@@ -812,7 +814,7 @@ config KUSER_HELPERS
3776 See Documentation/arm/kernel_user_helpers.txt for details.
3777
3778 However, the fixed address nature of these helpers can be used
3779- by ROP (return orientated programming) authors when creating
3780+ by ROP (Return Oriented Programming) authors when creating
3781 exploits.
3782
3783 If all of the binaries and libraries which run on your platform
3784diff --git a/arch/arm/mm/alignment.c b/arch/arm/mm/alignment.c
3785index 83792f4..c25d36b 100644
3786--- a/arch/arm/mm/alignment.c
3787+++ b/arch/arm/mm/alignment.c
3788@@ -216,10 +216,12 @@ union offset_union {
3789 #define __get16_unaligned_check(ins,val,addr) \
3790 do { \
3791 unsigned int err = 0, v, a = addr; \
3792+ pax_open_userland(); \
3793 __get8_unaligned_check(ins,v,a,err); \
3794 val = v << ((BE) ? 8 : 0); \
3795 __get8_unaligned_check(ins,v,a,err); \
3796 val |= v << ((BE) ? 0 : 8); \
3797+ pax_close_userland(); \
3798 if (err) \
3799 goto fault; \
3800 } while (0)
3801@@ -233,6 +235,7 @@ union offset_union {
3802 #define __get32_unaligned_check(ins,val,addr) \
3803 do { \
3804 unsigned int err = 0, v, a = addr; \
3805+ pax_open_userland(); \
3806 __get8_unaligned_check(ins,v,a,err); \
3807 val = v << ((BE) ? 24 : 0); \
3808 __get8_unaligned_check(ins,v,a,err); \
3809@@ -241,6 +244,7 @@ union offset_union {
3810 val |= v << ((BE) ? 8 : 16); \
3811 __get8_unaligned_check(ins,v,a,err); \
3812 val |= v << ((BE) ? 0 : 24); \
3813+ pax_close_userland(); \
3814 if (err) \
3815 goto fault; \
3816 } while (0)
3817@@ -254,6 +258,7 @@ union offset_union {
3818 #define __put16_unaligned_check(ins,val,addr) \
3819 do { \
3820 unsigned int err = 0, v = val, a = addr; \
3821+ pax_open_userland(); \
3822 __asm__( FIRST_BYTE_16 \
3823 ARM( "1: "ins" %1, [%2], #1\n" ) \
3824 THUMB( "1: "ins" %1, [%2]\n" ) \
3825@@ -273,6 +278,7 @@ union offset_union {
3826 " .popsection\n" \
3827 : "=r" (err), "=&r" (v), "=&r" (a) \
3828 : "0" (err), "1" (v), "2" (a)); \
3829+ pax_close_userland(); \
3830 if (err) \
3831 goto fault; \
3832 } while (0)
3833@@ -286,6 +292,7 @@ union offset_union {
3834 #define __put32_unaligned_check(ins,val,addr) \
3835 do { \
3836 unsigned int err = 0, v = val, a = addr; \
3837+ pax_open_userland(); \
3838 __asm__( FIRST_BYTE_32 \
3839 ARM( "1: "ins" %1, [%2], #1\n" ) \
3840 THUMB( "1: "ins" %1, [%2]\n" ) \
3841@@ -315,6 +322,7 @@ union offset_union {
3842 " .popsection\n" \
3843 : "=r" (err), "=&r" (v), "=&r" (a) \
3844 : "0" (err), "1" (v), "2" (a)); \
3845+ pax_close_userland(); \
3846 if (err) \
3847 goto fault; \
3848 } while (0)
3849diff --git a/arch/arm/mm/cache-l2x0.c b/arch/arm/mm/cache-l2x0.c
3850index 5e65ca8..879e7b3 100644
3851--- a/arch/arm/mm/cache-l2x0.c
3852+++ b/arch/arm/mm/cache-l2x0.c
3853@@ -42,7 +42,7 @@ struct l2c_init_data {
3854 void (*fixup)(void __iomem *, u32, struct outer_cache_fns *);
3855 void (*save)(void __iomem *);
3856 struct outer_cache_fns outer_cache;
3857-};
3858+} __do_const;
3859
3860 #define CACHE_LINE_SIZE 32
3861
3862diff --git a/arch/arm/mm/context.c b/arch/arm/mm/context.c
3863index 6eb97b3..ac509f6 100644
3864--- a/arch/arm/mm/context.c
3865+++ b/arch/arm/mm/context.c
3866@@ -43,7 +43,7 @@
3867 #define NUM_USER_ASIDS ASID_FIRST_VERSION
3868
3869 static DEFINE_RAW_SPINLOCK(cpu_asid_lock);
3870-static atomic64_t asid_generation = ATOMIC64_INIT(ASID_FIRST_VERSION);
3871+static atomic64_unchecked_t asid_generation = ATOMIC64_INIT(ASID_FIRST_VERSION);
3872 static DECLARE_BITMAP(asid_map, NUM_USER_ASIDS);
3873
3874 static DEFINE_PER_CPU(atomic64_t, active_asids);
3875@@ -182,7 +182,7 @@ static u64 new_context(struct mm_struct *mm, unsigned int cpu)
3876 {
3877 static u32 cur_idx = 1;
3878 u64 asid = atomic64_read(&mm->context.id);
3879- u64 generation = atomic64_read(&asid_generation);
3880+ u64 generation = atomic64_read_unchecked(&asid_generation);
3881
3882 if (asid != 0 && is_reserved_asid(asid)) {
3883 /*
3884@@ -203,7 +203,7 @@ static u64 new_context(struct mm_struct *mm, unsigned int cpu)
3885 */
3886 asid = find_next_zero_bit(asid_map, NUM_USER_ASIDS, cur_idx);
3887 if (asid == NUM_USER_ASIDS) {
3888- generation = atomic64_add_return(ASID_FIRST_VERSION,
3889+ generation = atomic64_add_return_unchecked(ASID_FIRST_VERSION,
3890 &asid_generation);
3891 flush_context(cpu);
3892 asid = find_next_zero_bit(asid_map, NUM_USER_ASIDS, 1);
3893@@ -234,14 +234,14 @@ void check_and_switch_context(struct mm_struct *mm, struct task_struct *tsk)
3894 cpu_set_reserved_ttbr0();
3895
3896 asid = atomic64_read(&mm->context.id);
3897- if (!((asid ^ atomic64_read(&asid_generation)) >> ASID_BITS)
3898+ if (!((asid ^ atomic64_read_unchecked(&asid_generation)) >> ASID_BITS)
3899 && atomic64_xchg(&per_cpu(active_asids, cpu), asid))
3900 goto switch_mm_fastpath;
3901
3902 raw_spin_lock_irqsave(&cpu_asid_lock, flags);
3903 /* Check that our ASID belongs to the current generation. */
3904 asid = atomic64_read(&mm->context.id);
3905- if ((asid ^ atomic64_read(&asid_generation)) >> ASID_BITS) {
3906+ if ((asid ^ atomic64_read_unchecked(&asid_generation)) >> ASID_BITS) {
3907 asid = new_context(mm, cpu);
3908 atomic64_set(&mm->context.id, asid);
3909 }
3910diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c
3911index eb8830a..e8ff52e 100644
3912--- a/arch/arm/mm/fault.c
3913+++ b/arch/arm/mm/fault.c
3914@@ -25,6 +25,7 @@
3915 #include <asm/system_misc.h>
3916 #include <asm/system_info.h>
3917 #include <asm/tlbflush.h>
3918+#include <asm/sections.h>
3919
3920 #include "fault.h"
3921
3922@@ -138,6 +139,31 @@ __do_kernel_fault(struct mm_struct *mm, unsigned long addr, unsigned int fsr,
3923 if (fixup_exception(regs))
3924 return;
3925
3926+#ifdef CONFIG_PAX_MEMORY_UDEREF
3927+ if (addr < TASK_SIZE) {
3928+ if (current->signal->curr_ip)
3929+ 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),
3930+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3931+ else
3932+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", current->comm, task_pid_nr(current),
3933+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3934+ }
3935+#endif
3936+
3937+#ifdef CONFIG_PAX_KERNEXEC
3938+ if ((fsr & FSR_WRITE) &&
3939+ (((unsigned long)_stext <= addr && addr < init_mm.end_code) ||
3940+ (MODULES_VADDR <= addr && addr < MODULES_END)))
3941+ {
3942+ if (current->signal->curr_ip)
3943+ 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),
3944+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
3945+ else
3946+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
3947+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
3948+ }
3949+#endif
3950+
3951 /*
3952 * No handler, we'll have to terminate things with extreme prejudice.
3953 */
3954@@ -174,6 +200,13 @@ __do_user_fault(struct task_struct *tsk, unsigned long addr,
3955 }
3956 #endif
3957
3958+#ifdef CONFIG_PAX_PAGEEXEC
3959+ if (fsr & FSR_LNX_PF) {
3960+ pax_report_fault(regs, (void *)regs->ARM_pc, (void *)regs->ARM_sp);
3961+ do_group_exit(SIGKILL);
3962+ }
3963+#endif
3964+
3965 tsk->thread.address = addr;
3966 tsk->thread.error_code = fsr;
3967 tsk->thread.trap_no = 14;
3968@@ -401,6 +434,33 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
3969 }
3970 #endif /* CONFIG_MMU */
3971
3972+#ifdef CONFIG_PAX_PAGEEXEC
3973+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
3974+{
3975+ long i;
3976+
3977+ printk(KERN_ERR "PAX: bytes at PC: ");
3978+ for (i = 0; i < 20; i++) {
3979+ unsigned char c;
3980+ if (get_user(c, (__force unsigned char __user *)pc+i))
3981+ printk(KERN_CONT "?? ");
3982+ else
3983+ printk(KERN_CONT "%02x ", c);
3984+ }
3985+ printk("\n");
3986+
3987+ printk(KERN_ERR "PAX: bytes at SP-4: ");
3988+ for (i = -1; i < 20; i++) {
3989+ unsigned long c;
3990+ if (get_user(c, (__force unsigned long __user *)sp+i))
3991+ printk(KERN_CONT "???????? ");
3992+ else
3993+ printk(KERN_CONT "%08lx ", c);
3994+ }
3995+ printk("\n");
3996+}
3997+#endif
3998+
3999 /*
4000 * First Level Translation Fault Handler
4001 *
4002@@ -548,9 +608,22 @@ do_DataAbort(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
4003 const struct fsr_info *inf = fsr_info + fsr_fs(fsr);
4004 struct siginfo info;
4005
4006+#ifdef CONFIG_PAX_MEMORY_UDEREF
4007+ if (addr < TASK_SIZE && is_domain_fault(fsr)) {
4008+ if (current->signal->curr_ip)
4009+ 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),
4010+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
4011+ else
4012+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", current->comm, task_pid_nr(current),
4013+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
4014+ goto die;
4015+ }
4016+#endif
4017+
4018 if (!inf->fn(addr, fsr & ~FSR_LNX_PF, regs))
4019 return;
4020
4021+die:
4022 printk(KERN_ALERT "Unhandled fault: %s (0x%03x) at 0x%08lx\n",
4023 inf->name, fsr, addr);
4024
4025@@ -574,15 +647,104 @@ hook_ifault_code(int nr, int (*fn)(unsigned long, unsigned int, struct pt_regs *
4026 ifsr_info[nr].name = name;
4027 }
4028
4029+asmlinkage int sys_sigreturn(struct pt_regs *regs);
4030+asmlinkage int sys_rt_sigreturn(struct pt_regs *regs);
4031+
4032 asmlinkage void __exception
4033 do_PrefetchAbort(unsigned long addr, unsigned int ifsr, struct pt_regs *regs)
4034 {
4035 const struct fsr_info *inf = ifsr_info + fsr_fs(ifsr);
4036 struct siginfo info;
4037+ unsigned long pc = instruction_pointer(regs);
4038+
4039+ if (user_mode(regs)) {
4040+ unsigned long sigpage = current->mm->context.sigpage;
4041+
4042+ if (sigpage <= pc && pc < sigpage + 7*4) {
4043+ if (pc < sigpage + 3*4)
4044+ sys_sigreturn(regs);
4045+ else
4046+ sys_rt_sigreturn(regs);
4047+ return;
4048+ }
4049+ if (pc == 0xffff0f60UL) {
4050+ /*
4051+ * PaX: __kuser_cmpxchg64 emulation
4052+ */
4053+ // TODO
4054+ //regs->ARM_pc = regs->ARM_lr;
4055+ //return;
4056+ }
4057+ if (pc == 0xffff0fa0UL) {
4058+ /*
4059+ * PaX: __kuser_memory_barrier emulation
4060+ */
4061+ // dmb(); implied by the exception
4062+ regs->ARM_pc = regs->ARM_lr;
4063+ return;
4064+ }
4065+ if (pc == 0xffff0fc0UL) {
4066+ /*
4067+ * PaX: __kuser_cmpxchg emulation
4068+ */
4069+ // TODO
4070+ //long new;
4071+ //int op;
4072+
4073+ //op = FUTEX_OP_SET << 28;
4074+ //new = futex_atomic_op_inuser(op, regs->ARM_r2);
4075+ //regs->ARM_r0 = old != new;
4076+ //regs->ARM_pc = regs->ARM_lr;
4077+ //return;
4078+ }
4079+ if (pc == 0xffff0fe0UL) {
4080+ /*
4081+ * PaX: __kuser_get_tls emulation
4082+ */
4083+ regs->ARM_r0 = current_thread_info()->tp_value[0];
4084+ regs->ARM_pc = regs->ARM_lr;
4085+ return;
4086+ }
4087+ }
4088+
4089+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
4090+ else if (is_domain_fault(ifsr) || is_xn_fault(ifsr)) {
4091+ if (current->signal->curr_ip)
4092+ 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),
4093+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()),
4094+ pc >= TASK_SIZE ? "non-executable kernel" : "userland", pc);
4095+ else
4096+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to execute %s memory at %08lx\n", current->comm, task_pid_nr(current),
4097+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()),
4098+ pc >= TASK_SIZE ? "non-executable kernel" : "userland", pc);
4099+ goto die;
4100+ }
4101+#endif
4102+
4103+#ifdef CONFIG_PAX_REFCOUNT
4104+ if (fsr_fs(ifsr) == FAULT_CODE_DEBUG) {
4105+#ifdef CONFIG_THUMB2_KERNEL
4106+ unsigned short bkpt;
4107+
4108+ if (!probe_kernel_address(pc, bkpt) && cpu_to_le16(bkpt) == 0xbef1) {
4109+#else
4110+ unsigned int bkpt;
4111+
4112+ if (!probe_kernel_address(pc, bkpt) && cpu_to_le32(bkpt) == 0xe12f1073) {
4113+#endif
4114+ current->thread.error_code = ifsr;
4115+ current->thread.trap_no = 0;
4116+ pax_report_refcount_overflow(regs);
4117+ fixup_exception(regs);
4118+ return;
4119+ }
4120+ }
4121+#endif
4122
4123 if (!inf->fn(addr, ifsr | FSR_LNX_PF, regs))
4124 return;
4125
4126+die:
4127 printk(KERN_ALERT "Unhandled prefetch abort: %s (0x%03x) at 0x%08lx\n",
4128 inf->name, ifsr, addr);
4129
4130diff --git a/arch/arm/mm/fault.h b/arch/arm/mm/fault.h
4131index cf08bdf..772656c 100644
4132--- a/arch/arm/mm/fault.h
4133+++ b/arch/arm/mm/fault.h
4134@@ -3,6 +3,7 @@
4135
4136 /*
4137 * Fault status register encodings. We steal bit 31 for our own purposes.
4138+ * Set when the FSR value is from an instruction fault.
4139 */
4140 #define FSR_LNX_PF (1 << 31)
4141 #define FSR_WRITE (1 << 11)
4142@@ -22,6 +23,17 @@ static inline int fsr_fs(unsigned int fsr)
4143 }
4144 #endif
4145
4146+/* valid for LPAE and !LPAE */
4147+static inline int is_xn_fault(unsigned int fsr)
4148+{
4149+ return ((fsr_fs(fsr) & 0x3c) == 0xc);
4150+}
4151+
4152+static inline int is_domain_fault(unsigned int fsr)
4153+{
4154+ return ((fsr_fs(fsr) & 0xD) == 0x9);
4155+}
4156+
4157 void do_bad_area(unsigned long addr, unsigned int fsr, struct pt_regs *regs);
4158 unsigned long search_exception_table(unsigned long addr);
4159
4160diff --git a/arch/arm/mm/init.c b/arch/arm/mm/init.c
4161index 9481f85..6dae261 100644
4162--- a/arch/arm/mm/init.c
4163+++ b/arch/arm/mm/init.c
4164@@ -31,6 +31,8 @@
4165 #include <asm/setup.h>
4166 #include <asm/tlb.h>
4167 #include <asm/fixmap.h>
4168+#include <asm/system_info.h>
4169+#include <asm/cp15.h>
4170
4171 #include <asm/mach/arch.h>
4172 #include <asm/mach/map.h>
4173@@ -619,7 +621,46 @@ void free_initmem(void)
4174 {
4175 #ifdef CONFIG_HAVE_TCM
4176 extern char __tcm_start, __tcm_end;
4177+#endif
4178
4179+#ifdef CONFIG_PAX_KERNEXEC
4180+ unsigned long addr;
4181+ pgd_t *pgd;
4182+ pud_t *pud;
4183+ pmd_t *pmd;
4184+ int cpu_arch = cpu_architecture();
4185+ unsigned int cr = get_cr();
4186+
4187+ if (cpu_arch >= CPU_ARCH_ARMv6 && (cr & CR_XP)) {
4188+ /* make pages tables, etc before .text NX */
4189+ for (addr = PAGE_OFFSET; addr < (unsigned long)_stext; addr += SECTION_SIZE) {
4190+ pgd = pgd_offset_k(addr);
4191+ pud = pud_offset(pgd, addr);
4192+ pmd = pmd_offset(pud, addr);
4193+ __section_update(pmd, addr, PMD_SECT_XN);
4194+ }
4195+ /* make init NX */
4196+ for (addr = (unsigned long)__init_begin; addr < (unsigned long)_sdata; addr += SECTION_SIZE) {
4197+ pgd = pgd_offset_k(addr);
4198+ pud = pud_offset(pgd, addr);
4199+ pmd = pmd_offset(pud, addr);
4200+ __section_update(pmd, addr, PMD_SECT_XN);
4201+ }
4202+ /* make kernel code/rodata RX */
4203+ for (addr = (unsigned long)_stext; addr < (unsigned long)__init_begin; addr += SECTION_SIZE) {
4204+ pgd = pgd_offset_k(addr);
4205+ pud = pud_offset(pgd, addr);
4206+ pmd = pmd_offset(pud, addr);
4207+#ifdef CONFIG_ARM_LPAE
4208+ __section_update(pmd, addr, PMD_SECT_RDONLY);
4209+#else
4210+ __section_update(pmd, addr, PMD_SECT_APX|PMD_SECT_AP_WRITE);
4211+#endif
4212+ }
4213+ }
4214+#endif
4215+
4216+#ifdef CONFIG_HAVE_TCM
4217 poison_init_mem(&__tcm_start, &__tcm_end - &__tcm_start);
4218 free_reserved_area(&__tcm_start, &__tcm_end, -1, "TCM link");
4219 #endif
4220diff --git a/arch/arm/mm/ioremap.c b/arch/arm/mm/ioremap.c
4221index d1e5ad7..84dcbf2 100644
4222--- a/arch/arm/mm/ioremap.c
4223+++ b/arch/arm/mm/ioremap.c
4224@@ -392,9 +392,9 @@ __arm_ioremap_exec(phys_addr_t phys_addr, size_t size, bool cached)
4225 unsigned int mtype;
4226
4227 if (cached)
4228- mtype = MT_MEMORY_RWX;
4229+ mtype = MT_MEMORY_RX;
4230 else
4231- mtype = MT_MEMORY_RWX_NONCACHED;
4232+ mtype = MT_MEMORY_RX_NONCACHED;
4233
4234 return __arm_ioremap_caller(phys_addr, size, mtype,
4235 __builtin_return_address(0));
4236diff --git a/arch/arm/mm/mmap.c b/arch/arm/mm/mmap.c
4237index 5e85ed3..b10a7ed 100644
4238--- a/arch/arm/mm/mmap.c
4239+++ b/arch/arm/mm/mmap.c
4240@@ -59,6 +59,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4241 struct vm_area_struct *vma;
4242 int do_align = 0;
4243 int aliasing = cache_is_vipt_aliasing();
4244+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
4245 struct vm_unmapped_area_info info;
4246
4247 /*
4248@@ -81,6 +82,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4249 if (len > TASK_SIZE)
4250 return -ENOMEM;
4251
4252+#ifdef CONFIG_PAX_RANDMMAP
4253+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4254+#endif
4255+
4256 if (addr) {
4257 if (do_align)
4258 addr = COLOUR_ALIGN(addr, pgoff);
4259@@ -88,8 +93,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4260 addr = PAGE_ALIGN(addr);
4261
4262 vma = find_vma(mm, addr);
4263- if (TASK_SIZE - len >= addr &&
4264- (!vma || addr + len <= vma->vm_start))
4265+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4266 return addr;
4267 }
4268
4269@@ -99,6 +103,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4270 info.high_limit = TASK_SIZE;
4271 info.align_mask = do_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
4272 info.align_offset = pgoff << PAGE_SHIFT;
4273+ info.threadstack_offset = offset;
4274 return vm_unmapped_area(&info);
4275 }
4276
4277@@ -112,6 +117,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4278 unsigned long addr = addr0;
4279 int do_align = 0;
4280 int aliasing = cache_is_vipt_aliasing();
4281+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
4282 struct vm_unmapped_area_info info;
4283
4284 /*
4285@@ -132,6 +138,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4286 return addr;
4287 }
4288
4289+#ifdef CONFIG_PAX_RANDMMAP
4290+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4291+#endif
4292+
4293 /* requesting a specific address */
4294 if (addr) {
4295 if (do_align)
4296@@ -139,8 +149,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4297 else
4298 addr = PAGE_ALIGN(addr);
4299 vma = find_vma(mm, addr);
4300- if (TASK_SIZE - len >= addr &&
4301- (!vma || addr + len <= vma->vm_start))
4302+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4303 return addr;
4304 }
4305
4306@@ -150,6 +159,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4307 info.high_limit = mm->mmap_base;
4308 info.align_mask = do_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
4309 info.align_offset = pgoff << PAGE_SHIFT;
4310+ info.threadstack_offset = offset;
4311 addr = vm_unmapped_area(&info);
4312
4313 /*
4314@@ -173,6 +183,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4315 {
4316 unsigned long random_factor = 0UL;
4317
4318+#ifdef CONFIG_PAX_RANDMMAP
4319+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4320+#endif
4321+
4322 /* 8 bits of randomness in 20 address space bits */
4323 if ((current->flags & PF_RANDOMIZE) &&
4324 !(current->personality & ADDR_NO_RANDOMIZE))
4325@@ -180,9 +194,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4326
4327 if (mmap_is_legacy()) {
4328 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
4329+
4330+#ifdef CONFIG_PAX_RANDMMAP
4331+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4332+ mm->mmap_base += mm->delta_mmap;
4333+#endif
4334+
4335 mm->get_unmapped_area = arch_get_unmapped_area;
4336 } else {
4337 mm->mmap_base = mmap_base(random_factor);
4338+
4339+#ifdef CONFIG_PAX_RANDMMAP
4340+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4341+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4342+#endif
4343+
4344 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4345 }
4346 }
4347diff --git a/arch/arm/mm/mmu.c b/arch/arm/mm/mmu.c
4348index 9f98cec..115fcb6 100644
4349--- a/arch/arm/mm/mmu.c
4350+++ b/arch/arm/mm/mmu.c
4351@@ -40,6 +40,22 @@
4352 #include "mm.h"
4353 #include "tcm.h"
4354
4355+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
4356+void modify_domain(unsigned int dom, unsigned int type)
4357+{
4358+ struct thread_info *thread = current_thread_info();
4359+ unsigned int domain = thread->cpu_domain;
4360+ /*
4361+ * DOMAIN_MANAGER might be defined to some other value,
4362+ * use the arch-defined constant
4363+ */
4364+ domain &= ~domain_val(dom, 3);
4365+ thread->cpu_domain = domain | domain_val(dom, type);
4366+ set_domain(thread->cpu_domain);
4367+}
4368+EXPORT_SYMBOL(modify_domain);
4369+#endif
4370+
4371 /*
4372 * empty_zero_page is a special page that is used for
4373 * zero-initialized data and COW.
4374@@ -239,7 +255,15 @@ __setup("noalign", noalign_setup);
4375 #define PROT_PTE_S2_DEVICE PROT_PTE_DEVICE
4376 #define PROT_SECT_DEVICE PMD_TYPE_SECT|PMD_SECT_AP_WRITE
4377
4378-static struct mem_type mem_types[] = {
4379+#ifdef CONFIG_PAX_KERNEXEC
4380+#define L_PTE_KERNEXEC L_PTE_RDONLY
4381+#define PMD_SECT_KERNEXEC PMD_SECT_RDONLY
4382+#else
4383+#define L_PTE_KERNEXEC L_PTE_DIRTY
4384+#define PMD_SECT_KERNEXEC PMD_SECT_AP_WRITE
4385+#endif
4386+
4387+static struct mem_type mem_types[] __read_only = {
4388 [MT_DEVICE] = { /* Strongly ordered / ARMv6 shared device */
4389 .prot_pte = PROT_PTE_DEVICE | L_PTE_MT_DEV_SHARED |
4390 L_PTE_SHARED,
4391@@ -268,19 +292,19 @@ static struct mem_type mem_types[] = {
4392 .prot_sect = PROT_SECT_DEVICE,
4393 .domain = DOMAIN_IO,
4394 },
4395- [MT_UNCACHED] = {
4396+ [MT_UNCACHED_RW] = {
4397 .prot_pte = PROT_PTE_DEVICE,
4398 .prot_l1 = PMD_TYPE_TABLE,
4399 .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4400 .domain = DOMAIN_IO,
4401 },
4402- [MT_CACHECLEAN] = {
4403- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4404+ [MT_CACHECLEAN_RO] = {
4405+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_RDONLY,
4406 .domain = DOMAIN_KERNEL,
4407 },
4408 #ifndef CONFIG_ARM_LPAE
4409- [MT_MINICLEAN] = {
4410- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_MINICACHE,
4411+ [MT_MINICLEAN_RO] = {
4412+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_MINICACHE | PMD_SECT_XN | PMD_SECT_RDONLY,
4413 .domain = DOMAIN_KERNEL,
4414 },
4415 #endif
4416@@ -288,15 +312,15 @@ static struct mem_type mem_types[] = {
4417 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4418 L_PTE_RDONLY,
4419 .prot_l1 = PMD_TYPE_TABLE,
4420- .domain = DOMAIN_USER,
4421+ .domain = DOMAIN_VECTORS,
4422 },
4423 [MT_HIGH_VECTORS] = {
4424 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4425 L_PTE_USER | L_PTE_RDONLY,
4426 .prot_l1 = PMD_TYPE_TABLE,
4427- .domain = DOMAIN_USER,
4428+ .domain = DOMAIN_VECTORS,
4429 },
4430- [MT_MEMORY_RWX] = {
4431+ [__MT_MEMORY_RWX] = {
4432 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4433 .prot_l1 = PMD_TYPE_TABLE,
4434 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4435@@ -309,17 +333,30 @@ static struct mem_type mem_types[] = {
4436 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4437 .domain = DOMAIN_KERNEL,
4438 },
4439- [MT_ROM] = {
4440- .prot_sect = PMD_TYPE_SECT,
4441+ [MT_MEMORY_RX] = {
4442+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC,
4443+ .prot_l1 = PMD_TYPE_TABLE,
4444+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4445+ .domain = DOMAIN_KERNEL,
4446+ },
4447+ [MT_ROM_RX] = {
4448+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
4449 .domain = DOMAIN_KERNEL,
4450 },
4451- [MT_MEMORY_RWX_NONCACHED] = {
4452+ [MT_MEMORY_RW_NONCACHED] = {
4453 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4454 L_PTE_MT_BUFFERABLE,
4455 .prot_l1 = PMD_TYPE_TABLE,
4456 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4457 .domain = DOMAIN_KERNEL,
4458 },
4459+ [MT_MEMORY_RX_NONCACHED] = {
4460+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC |
4461+ L_PTE_MT_BUFFERABLE,
4462+ .prot_l1 = PMD_TYPE_TABLE,
4463+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4464+ .domain = DOMAIN_KERNEL,
4465+ },
4466 [MT_MEMORY_RW_DTCM] = {
4467 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4468 L_PTE_XN,
4469@@ -327,9 +364,10 @@ static struct mem_type mem_types[] = {
4470 .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4471 .domain = DOMAIN_KERNEL,
4472 },
4473- [MT_MEMORY_RWX_ITCM] = {
4474- .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4475+ [MT_MEMORY_RX_ITCM] = {
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_MEMORY_RW_SO] = {
4482@@ -547,9 +585,14 @@ static void __init build_mem_type_table(void)
4483 * Mark cache clean areas and XIP ROM read only
4484 * from SVC mode and no access from userspace.
4485 */
4486- mem_types[MT_ROM].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4487- mem_types[MT_MINICLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4488- mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4489+ mem_types[MT_ROM_RX].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4490+#ifdef CONFIG_PAX_KERNEXEC
4491+ mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4492+ mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4493+ mem_types[MT_MEMORY_RX_ITCM].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4494+#endif
4495+ mem_types[MT_MINICLEAN_RO].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4496+ mem_types[MT_CACHECLEAN_RO].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4497 #endif
4498
4499 /*
4500@@ -566,13 +609,17 @@ static void __init build_mem_type_table(void)
4501 mem_types[MT_DEVICE_WC].prot_pte |= L_PTE_SHARED;
4502 mem_types[MT_DEVICE_CACHED].prot_sect |= PMD_SECT_S;
4503 mem_types[MT_DEVICE_CACHED].prot_pte |= L_PTE_SHARED;
4504- mem_types[MT_MEMORY_RWX].prot_sect |= PMD_SECT_S;
4505- mem_types[MT_MEMORY_RWX].prot_pte |= L_PTE_SHARED;
4506+ mem_types[__MT_MEMORY_RWX].prot_sect |= PMD_SECT_S;
4507+ mem_types[__MT_MEMORY_RWX].prot_pte |= L_PTE_SHARED;
4508 mem_types[MT_MEMORY_RW].prot_sect |= PMD_SECT_S;
4509 mem_types[MT_MEMORY_RW].prot_pte |= L_PTE_SHARED;
4510+ mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_S;
4511+ mem_types[MT_MEMORY_RX].prot_pte |= L_PTE_SHARED;
4512 mem_types[MT_MEMORY_DMA_READY].prot_pte |= L_PTE_SHARED;
4513- mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |= PMD_SECT_S;
4514- mem_types[MT_MEMORY_RWX_NONCACHED].prot_pte |= L_PTE_SHARED;
4515+ mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |= PMD_SECT_S;
4516+ mem_types[MT_MEMORY_RW_NONCACHED].prot_pte |= L_PTE_SHARED;
4517+ mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |= PMD_SECT_S;
4518+ mem_types[MT_MEMORY_RX_NONCACHED].prot_pte |= L_PTE_SHARED;
4519 }
4520 }
4521
4522@@ -583,15 +630,20 @@ static void __init build_mem_type_table(void)
4523 if (cpu_arch >= CPU_ARCH_ARMv6) {
4524 if (cpu_arch >= CPU_ARCH_ARMv7 && (cr & CR_TRE)) {
4525 /* Non-cacheable Normal is XCB = 001 */
4526- mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |=
4527+ mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |=
4528+ PMD_SECT_BUFFERED;
4529+ mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |=
4530 PMD_SECT_BUFFERED;
4531 } else {
4532 /* For both ARMv6 and non-TEX-remapping ARMv7 */
4533- mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |=
4534+ mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |=
4535+ PMD_SECT_TEX(1);
4536+ mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |=
4537 PMD_SECT_TEX(1);
4538 }
4539 } else {
4540- mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |= PMD_SECT_BUFFERABLE;
4541+ mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |= PMD_SECT_BUFFERABLE;
4542+ mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |= PMD_SECT_BUFFERABLE;
4543 }
4544
4545 #ifdef CONFIG_ARM_LPAE
4546@@ -607,6 +659,8 @@ static void __init build_mem_type_table(void)
4547 vecs_pgprot |= PTE_EXT_AF;
4548 #endif
4549
4550+ user_pgprot |= __supported_pte_mask;
4551+
4552 for (i = 0; i < 16; i++) {
4553 pteval_t v = pgprot_val(protection_map[i]);
4554 protection_map[i] = __pgprot(v | user_pgprot);
4555@@ -624,21 +678,24 @@ static void __init build_mem_type_table(void)
4556
4557 mem_types[MT_LOW_VECTORS].prot_l1 |= ecc_mask;
4558 mem_types[MT_HIGH_VECTORS].prot_l1 |= ecc_mask;
4559- mem_types[MT_MEMORY_RWX].prot_sect |= ecc_mask | cp->pmd;
4560- mem_types[MT_MEMORY_RWX].prot_pte |= kern_pgprot;
4561+ mem_types[__MT_MEMORY_RWX].prot_sect |= ecc_mask | cp->pmd;
4562+ mem_types[__MT_MEMORY_RWX].prot_pte |= kern_pgprot;
4563 mem_types[MT_MEMORY_RW].prot_sect |= ecc_mask | cp->pmd;
4564 mem_types[MT_MEMORY_RW].prot_pte |= kern_pgprot;
4565+ mem_types[MT_MEMORY_RX].prot_sect |= ecc_mask | cp->pmd;
4566+ mem_types[MT_MEMORY_RX].prot_pte |= kern_pgprot;
4567 mem_types[MT_MEMORY_DMA_READY].prot_pte |= kern_pgprot;
4568- mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |= ecc_mask;
4569- mem_types[MT_ROM].prot_sect |= cp->pmd;
4570+ mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |= ecc_mask;
4571+ mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |= ecc_mask;
4572+ mem_types[MT_ROM_RX].prot_sect |= cp->pmd;
4573
4574 switch (cp->pmd) {
4575 case PMD_SECT_WT:
4576- mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_WT;
4577+ mem_types[MT_CACHECLEAN_RO].prot_sect |= PMD_SECT_WT;
4578 break;
4579 case PMD_SECT_WB:
4580 case PMD_SECT_WBWA:
4581- mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_WB;
4582+ mem_types[MT_CACHECLEAN_RO].prot_sect |= PMD_SECT_WB;
4583 break;
4584 }
4585 pr_info("Memory policy: %sData cache %s\n",
4586@@ -856,7 +913,7 @@ static void __init create_mapping(struct map_desc *md)
4587 return;
4588 }
4589
4590- if ((md->type == MT_DEVICE || md->type == MT_ROM) &&
4591+ if ((md->type == MT_DEVICE || md->type == MT_ROM_RX) &&
4592 md->virtual >= PAGE_OFFSET &&
4593 (md->virtual < VMALLOC_START || md->virtual >= VMALLOC_END)) {
4594 printk(KERN_WARNING "BUG: mapping for 0x%08llx"
4595@@ -1224,18 +1281,15 @@ void __init arm_mm_memblock_reserve(void)
4596 * called function. This means you can't use any function or debugging
4597 * method which may touch any device, otherwise the kernel _will_ crash.
4598 */
4599+
4600+static char vectors[PAGE_SIZE * 2] __read_only __aligned(PAGE_SIZE);
4601+
4602 static void __init devicemaps_init(const struct machine_desc *mdesc)
4603 {
4604 struct map_desc map;
4605 unsigned long addr;
4606- void *vectors;
4607
4608- /*
4609- * Allocate the vector page early.
4610- */
4611- vectors = early_alloc(PAGE_SIZE * 2);
4612-
4613- early_trap_init(vectors);
4614+ early_trap_init(&vectors);
4615
4616 for (addr = VMALLOC_START; addr; addr += PMD_SIZE)
4617 pmd_clear(pmd_off_k(addr));
4618@@ -1248,7 +1302,7 @@ static void __init devicemaps_init(const struct machine_desc *mdesc)
4619 map.pfn = __phys_to_pfn(CONFIG_XIP_PHYS_ADDR & SECTION_MASK);
4620 map.virtual = MODULES_VADDR;
4621 map.length = ((unsigned long)_etext - map.virtual + ~SECTION_MASK) & SECTION_MASK;
4622- map.type = MT_ROM;
4623+ map.type = MT_ROM_RX;
4624 create_mapping(&map);
4625 #endif
4626
4627@@ -1259,14 +1313,14 @@ static void __init devicemaps_init(const struct machine_desc *mdesc)
4628 map.pfn = __phys_to_pfn(FLUSH_BASE_PHYS);
4629 map.virtual = FLUSH_BASE;
4630 map.length = SZ_1M;
4631- map.type = MT_CACHECLEAN;
4632+ map.type = MT_CACHECLEAN_RO;
4633 create_mapping(&map);
4634 #endif
4635 #ifdef FLUSH_BASE_MINICACHE
4636 map.pfn = __phys_to_pfn(FLUSH_BASE_PHYS + SZ_1M);
4637 map.virtual = FLUSH_BASE_MINICACHE;
4638 map.length = SZ_1M;
4639- map.type = MT_MINICLEAN;
4640+ map.type = MT_MINICLEAN_RO;
4641 create_mapping(&map);
4642 #endif
4643
4644@@ -1275,7 +1329,7 @@ static void __init devicemaps_init(const struct machine_desc *mdesc)
4645 * location (0xffff0000). If we aren't using high-vectors, also
4646 * create a mapping at the low-vectors virtual address.
4647 */
4648- map.pfn = __phys_to_pfn(virt_to_phys(vectors));
4649+ map.pfn = __phys_to_pfn(virt_to_phys(&vectors));
4650 map.virtual = 0xffff0000;
4651 map.length = PAGE_SIZE;
4652 #ifdef CONFIG_KUSER_HELPERS
4653@@ -1335,8 +1389,10 @@ static void __init kmap_init(void)
4654 static void __init map_lowmem(void)
4655 {
4656 struct memblock_region *reg;
4657+#ifndef CONFIG_PAX_KERNEXEC
4658 unsigned long kernel_x_start = round_down(__pa(_stext), SECTION_SIZE);
4659 unsigned long kernel_x_end = round_up(__pa(__init_end), SECTION_SIZE);
4660+#endif
4661
4662 /* Map all the lowmem memory banks. */
4663 for_each_memblock(memory, reg) {
4664@@ -1349,11 +1405,48 @@ static void __init map_lowmem(void)
4665 if (start >= end)
4666 break;
4667
4668+#ifdef CONFIG_PAX_KERNEXEC
4669+ map.pfn = __phys_to_pfn(start);
4670+ map.virtual = __phys_to_virt(start);
4671+ map.length = end - start;
4672+
4673+ if (map.virtual <= (unsigned long)_stext && ((unsigned long)_end < (map.virtual + map.length))) {
4674+ struct map_desc kernel;
4675+ struct map_desc initmap;
4676+
4677+ /* when freeing initmem we will make this RW */
4678+ initmap.pfn = __phys_to_pfn(__pa(__init_begin));
4679+ initmap.virtual = (unsigned long)__init_begin;
4680+ initmap.length = _sdata - __init_begin;
4681+ initmap.type = __MT_MEMORY_RWX;
4682+ create_mapping(&initmap);
4683+
4684+ /* when freeing initmem we will make this RX */
4685+ kernel.pfn = __phys_to_pfn(__pa(_stext));
4686+ kernel.virtual = (unsigned long)_stext;
4687+ kernel.length = __init_begin - _stext;
4688+ kernel.type = __MT_MEMORY_RWX;
4689+ create_mapping(&kernel);
4690+
4691+ if (map.virtual < (unsigned long)_stext) {
4692+ map.length = (unsigned long)_stext - map.virtual;
4693+ map.type = __MT_MEMORY_RWX;
4694+ create_mapping(&map);
4695+ }
4696+
4697+ map.pfn = __phys_to_pfn(__pa(_sdata));
4698+ map.virtual = (unsigned long)_sdata;
4699+ map.length = end - __pa(_sdata);
4700+ }
4701+
4702+ map.type = MT_MEMORY_RW;
4703+ create_mapping(&map);
4704+#else
4705 if (end < kernel_x_start || start >= kernel_x_end) {
4706 map.pfn = __phys_to_pfn(start);
4707 map.virtual = __phys_to_virt(start);
4708 map.length = end - start;
4709- map.type = MT_MEMORY_RWX;
4710+ map.type = __MT_MEMORY_RWX;
4711
4712 create_mapping(&map);
4713 } else {
4714@@ -1370,7 +1463,7 @@ static void __init map_lowmem(void)
4715 map.pfn = __phys_to_pfn(kernel_x_start);
4716 map.virtual = __phys_to_virt(kernel_x_start);
4717 map.length = kernel_x_end - kernel_x_start;
4718- map.type = MT_MEMORY_RWX;
4719+ map.type = __MT_MEMORY_RWX;
4720
4721 create_mapping(&map);
4722
4723@@ -1383,6 +1476,7 @@ static void __init map_lowmem(void)
4724 create_mapping(&map);
4725 }
4726 }
4727+#endif
4728 }
4729 }
4730
4731diff --git a/arch/arm/net/bpf_jit_32.c b/arch/arm/net/bpf_jit_32.c
4732index e1268f9..a9755a7 100644
4733--- a/arch/arm/net/bpf_jit_32.c
4734+++ b/arch/arm/net/bpf_jit_32.c
4735@@ -20,6 +20,7 @@
4736 #include <asm/cacheflush.h>
4737 #include <asm/hwcap.h>
4738 #include <asm/opcodes.h>
4739+#include <asm/pgtable.h>
4740
4741 #include "bpf_jit_32.h"
4742
4743@@ -71,7 +72,11 @@ struct jit_ctx {
4744 #endif
4745 };
4746
4747+#ifdef CONFIG_GRKERNSEC_BPF_HARDEN
4748+int bpf_jit_enable __read_only;
4749+#else
4750 int bpf_jit_enable __read_mostly;
4751+#endif
4752
4753 static u64 jit_get_skb_b(struct sk_buff *skb, unsigned offset)
4754 {
4755@@ -178,8 +183,10 @@ static void jit_fill_hole(void *area, unsigned int size)
4756 {
4757 u32 *ptr;
4758 /* We are guaranteed to have aligned memory. */
4759+ pax_open_kernel();
4760 for (ptr = area; size >= sizeof(u32); size -= sizeof(u32))
4761 *ptr++ = __opcode_to_mem_arm(ARM_INST_UDF);
4762+ pax_close_kernel();
4763 }
4764
4765 static void build_prologue(struct jit_ctx *ctx)
4766diff --git a/arch/arm/plat-iop/setup.c b/arch/arm/plat-iop/setup.c
4767index 5b217f4..c23f40e 100644
4768--- a/arch/arm/plat-iop/setup.c
4769+++ b/arch/arm/plat-iop/setup.c
4770@@ -24,7 +24,7 @@ static struct map_desc iop3xx_std_desc[] __initdata = {
4771 .virtual = IOP3XX_PERIPHERAL_VIRT_BASE,
4772 .pfn = __phys_to_pfn(IOP3XX_PERIPHERAL_PHYS_BASE),
4773 .length = IOP3XX_PERIPHERAL_SIZE,
4774- .type = MT_UNCACHED,
4775+ .type = MT_UNCACHED_RW,
4776 },
4777 };
4778
4779diff --git a/arch/arm/plat-omap/sram.c b/arch/arm/plat-omap/sram.c
4780index a5bc92d..0bb4730 100644
4781--- a/arch/arm/plat-omap/sram.c
4782+++ b/arch/arm/plat-omap/sram.c
4783@@ -93,6 +93,8 @@ void __init omap_map_sram(unsigned long start, unsigned long size,
4784 * Looks like we need to preserve some bootloader code at the
4785 * beginning of SRAM for jumping to flash for reboot to work...
4786 */
4787+ pax_open_kernel();
4788 memset_io(omap_sram_base + omap_sram_skip, 0,
4789 omap_sram_size - omap_sram_skip);
4790+ pax_close_kernel();
4791 }
4792diff --git a/arch/arm/plat-samsung/include/plat/dma-ops.h b/arch/arm/plat-samsung/include/plat/dma-ops.h
4793index ce6d763..cfea917 100644
4794--- a/arch/arm/plat-samsung/include/plat/dma-ops.h
4795+++ b/arch/arm/plat-samsung/include/plat/dma-ops.h
4796@@ -47,7 +47,7 @@ struct samsung_dma_ops {
4797 int (*started)(unsigned ch);
4798 int (*flush)(unsigned ch);
4799 int (*stop)(unsigned ch);
4800-};
4801+} __no_const;
4802
4803 extern void *samsung_dmadev_get_ops(void);
4804 extern void *s3c_dma_get_ops(void);
4805diff --git a/arch/arm64/include/asm/barrier.h b/arch/arm64/include/asm/barrier.h
4806index 6389d60..b5d3bdd 100644
4807--- a/arch/arm64/include/asm/barrier.h
4808+++ b/arch/arm64/include/asm/barrier.h
4809@@ -41,7 +41,7 @@
4810 do { \
4811 compiletime_assert_atomic_type(*p); \
4812 barrier(); \
4813- ACCESS_ONCE(*p) = (v); \
4814+ ACCESS_ONCE_RW(*p) = (v); \
4815 } while (0)
4816
4817 #define smp_load_acquire(p) \
4818diff --git a/arch/arm64/include/asm/uaccess.h b/arch/arm64/include/asm/uaccess.h
4819index 3bf8f4e..5dd5491 100644
4820--- a/arch/arm64/include/asm/uaccess.h
4821+++ b/arch/arm64/include/asm/uaccess.h
4822@@ -99,6 +99,7 @@ static inline void set_fs(mm_segment_t fs)
4823 flag; \
4824 })
4825
4826+#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
4827 #define access_ok(type, addr, size) __range_ok(addr, size)
4828 #define user_addr_max get_fs
4829
4830diff --git a/arch/avr32/include/asm/cache.h b/arch/avr32/include/asm/cache.h
4831index c3a58a1..78fbf54 100644
4832--- a/arch/avr32/include/asm/cache.h
4833+++ b/arch/avr32/include/asm/cache.h
4834@@ -1,8 +1,10 @@
4835 #ifndef __ASM_AVR32_CACHE_H
4836 #define __ASM_AVR32_CACHE_H
4837
4838+#include <linux/const.h>
4839+
4840 #define L1_CACHE_SHIFT 5
4841-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4842+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4843
4844 /*
4845 * Memory returned by kmalloc() may be used for DMA, so we must make
4846diff --git a/arch/avr32/include/asm/elf.h b/arch/avr32/include/asm/elf.h
4847index d232888..87c8df1 100644
4848--- a/arch/avr32/include/asm/elf.h
4849+++ b/arch/avr32/include/asm/elf.h
4850@@ -84,8 +84,14 @@ typedef struct user_fpu_struct elf_fpregset_t;
4851 the loader. We need to make sure that it is out of the way of the program
4852 that it will "exec", and that there is sufficient room for the brk. */
4853
4854-#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
4855+#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
4856
4857+#ifdef CONFIG_PAX_ASLR
4858+#define PAX_ELF_ET_DYN_BASE 0x00001000UL
4859+
4860+#define PAX_DELTA_MMAP_LEN 15
4861+#define PAX_DELTA_STACK_LEN 15
4862+#endif
4863
4864 /* This yields a mask that user programs can use to figure out what
4865 instruction set this CPU supports. This could be done in user space,
4866diff --git a/arch/avr32/include/asm/kmap_types.h b/arch/avr32/include/asm/kmap_types.h
4867index 479330b..53717a8 100644
4868--- a/arch/avr32/include/asm/kmap_types.h
4869+++ b/arch/avr32/include/asm/kmap_types.h
4870@@ -2,9 +2,9 @@
4871 #define __ASM_AVR32_KMAP_TYPES_H
4872
4873 #ifdef CONFIG_DEBUG_HIGHMEM
4874-# define KM_TYPE_NR 29
4875+# define KM_TYPE_NR 30
4876 #else
4877-# define KM_TYPE_NR 14
4878+# define KM_TYPE_NR 15
4879 #endif
4880
4881 #endif /* __ASM_AVR32_KMAP_TYPES_H */
4882diff --git a/arch/avr32/mm/fault.c b/arch/avr32/mm/fault.c
4883index 0eca933..eb78c7b 100644
4884--- a/arch/avr32/mm/fault.c
4885+++ b/arch/avr32/mm/fault.c
4886@@ -41,6 +41,23 @@ static inline int notify_page_fault(struct pt_regs *regs, int trap)
4887
4888 int exception_trace = 1;
4889
4890+#ifdef CONFIG_PAX_PAGEEXEC
4891+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
4892+{
4893+ unsigned long i;
4894+
4895+ printk(KERN_ERR "PAX: bytes at PC: ");
4896+ for (i = 0; i < 20; i++) {
4897+ unsigned char c;
4898+ if (get_user(c, (unsigned char *)pc+i))
4899+ printk(KERN_CONT "???????? ");
4900+ else
4901+ printk(KERN_CONT "%02x ", c);
4902+ }
4903+ printk("\n");
4904+}
4905+#endif
4906+
4907 /*
4908 * This routine handles page faults. It determines the address and the
4909 * problem, and then passes it off to one of the appropriate routines.
4910@@ -176,6 +193,16 @@ bad_area:
4911 up_read(&mm->mmap_sem);
4912
4913 if (user_mode(regs)) {
4914+
4915+#ifdef CONFIG_PAX_PAGEEXEC
4916+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
4917+ if (ecr == ECR_PROTECTION_X || ecr == ECR_TLB_MISS_X) {
4918+ pax_report_fault(regs, (void *)regs->pc, (void *)regs->sp);
4919+ do_group_exit(SIGKILL);
4920+ }
4921+ }
4922+#endif
4923+
4924 if (exception_trace && printk_ratelimit())
4925 printk("%s%s[%d]: segfault at %08lx pc %08lx "
4926 "sp %08lx ecr %lu\n",
4927diff --git a/arch/blackfin/include/asm/cache.h b/arch/blackfin/include/asm/cache.h
4928index 568885a..f8008df 100644
4929--- a/arch/blackfin/include/asm/cache.h
4930+++ b/arch/blackfin/include/asm/cache.h
4931@@ -7,6 +7,7 @@
4932 #ifndef __ARCH_BLACKFIN_CACHE_H
4933 #define __ARCH_BLACKFIN_CACHE_H
4934
4935+#include <linux/const.h>
4936 #include <linux/linkage.h> /* for asmlinkage */
4937
4938 /*
4939@@ -14,7 +15,7 @@
4940 * Blackfin loads 32 bytes for cache
4941 */
4942 #define L1_CACHE_SHIFT 5
4943-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4944+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4945 #define SMP_CACHE_BYTES L1_CACHE_BYTES
4946
4947 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
4948diff --git a/arch/cris/include/arch-v10/arch/cache.h b/arch/cris/include/arch-v10/arch/cache.h
4949index aea2718..3639a60 100644
4950--- a/arch/cris/include/arch-v10/arch/cache.h
4951+++ b/arch/cris/include/arch-v10/arch/cache.h
4952@@ -1,8 +1,9 @@
4953 #ifndef _ASM_ARCH_CACHE_H
4954 #define _ASM_ARCH_CACHE_H
4955
4956+#include <linux/const.h>
4957 /* Etrax 100LX have 32-byte cache-lines. */
4958-#define L1_CACHE_BYTES 32
4959 #define L1_CACHE_SHIFT 5
4960+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4961
4962 #endif /* _ASM_ARCH_CACHE_H */
4963diff --git a/arch/cris/include/arch-v32/arch/cache.h b/arch/cris/include/arch-v32/arch/cache.h
4964index 7caf25d..ee65ac5 100644
4965--- a/arch/cris/include/arch-v32/arch/cache.h
4966+++ b/arch/cris/include/arch-v32/arch/cache.h
4967@@ -1,11 +1,12 @@
4968 #ifndef _ASM_CRIS_ARCH_CACHE_H
4969 #define _ASM_CRIS_ARCH_CACHE_H
4970
4971+#include <linux/const.h>
4972 #include <arch/hwregs/dma.h>
4973
4974 /* A cache-line is 32 bytes. */
4975-#define L1_CACHE_BYTES 32
4976 #define L1_CACHE_SHIFT 5
4977+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4978
4979 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
4980
4981diff --git a/arch/frv/include/asm/atomic.h b/arch/frv/include/asm/atomic.h
4982index 102190a..5334cea 100644
4983--- a/arch/frv/include/asm/atomic.h
4984+++ b/arch/frv/include/asm/atomic.h
4985@@ -181,6 +181,16 @@ static inline void atomic64_dec(atomic64_t *v)
4986 #define atomic64_cmpxchg(v, old, new) (__cmpxchg_64(old, new, &(v)->counter))
4987 #define atomic64_xchg(v, new) (__xchg_64(new, &(v)->counter))
4988
4989+#define atomic64_read_unchecked(v) atomic64_read(v)
4990+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4991+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4992+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4993+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4994+#define atomic64_inc_unchecked(v) atomic64_inc(v)
4995+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4996+#define atomic64_dec_unchecked(v) atomic64_dec(v)
4997+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4998+
4999 static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5000 {
5001 int c, old;
5002diff --git a/arch/frv/include/asm/cache.h b/arch/frv/include/asm/cache.h
5003index 2797163..c2a401df9 100644
5004--- a/arch/frv/include/asm/cache.h
5005+++ b/arch/frv/include/asm/cache.h
5006@@ -12,10 +12,11 @@
5007 #ifndef __ASM_CACHE_H
5008 #define __ASM_CACHE_H
5009
5010+#include <linux/const.h>
5011
5012 /* bytes per L1 cache line */
5013 #define L1_CACHE_SHIFT (CONFIG_FRV_L1_CACHE_SHIFT)
5014-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5015+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5016
5017 #define __cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
5018 #define ____cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
5019diff --git a/arch/frv/include/asm/kmap_types.h b/arch/frv/include/asm/kmap_types.h
5020index 43901f2..0d8b865 100644
5021--- a/arch/frv/include/asm/kmap_types.h
5022+++ b/arch/frv/include/asm/kmap_types.h
5023@@ -2,6 +2,6 @@
5024 #ifndef _ASM_KMAP_TYPES_H
5025 #define _ASM_KMAP_TYPES_H
5026
5027-#define KM_TYPE_NR 17
5028+#define KM_TYPE_NR 18
5029
5030 #endif
5031diff --git a/arch/frv/mm/elf-fdpic.c b/arch/frv/mm/elf-fdpic.c
5032index 836f147..4cf23f5 100644
5033--- a/arch/frv/mm/elf-fdpic.c
5034+++ b/arch/frv/mm/elf-fdpic.c
5035@@ -61,6 +61,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5036 {
5037 struct vm_area_struct *vma;
5038 struct vm_unmapped_area_info info;
5039+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
5040
5041 if (len > TASK_SIZE)
5042 return -ENOMEM;
5043@@ -73,8 +74,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5044 if (addr) {
5045 addr = PAGE_ALIGN(addr);
5046 vma = find_vma(current->mm, addr);
5047- if (TASK_SIZE - len >= addr &&
5048- (!vma || addr + len <= vma->vm_start))
5049+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
5050 goto success;
5051 }
5052
5053@@ -85,6 +85,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5054 info.high_limit = (current->mm->start_stack - 0x00200000);
5055 info.align_mask = 0;
5056 info.align_offset = 0;
5057+ info.threadstack_offset = offset;
5058 addr = vm_unmapped_area(&info);
5059 if (!(addr & ~PAGE_MASK))
5060 goto success;
5061diff --git a/arch/hexagon/include/asm/cache.h b/arch/hexagon/include/asm/cache.h
5062index 2635117..fa223cb 100644
5063--- a/arch/hexagon/include/asm/cache.h
5064+++ b/arch/hexagon/include/asm/cache.h
5065@@ -21,9 +21,11 @@
5066 #ifndef __ASM_CACHE_H
5067 #define __ASM_CACHE_H
5068
5069+#include <linux/const.h>
5070+
5071 /* Bytes per L1 cache line */
5072-#define L1_CACHE_SHIFT (5)
5073-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5074+#define L1_CACHE_SHIFT 5
5075+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5076
5077 #define __cacheline_aligned __aligned(L1_CACHE_BYTES)
5078 #define ____cacheline_aligned __aligned(L1_CACHE_BYTES)
5079diff --git a/arch/ia64/Kconfig b/arch/ia64/Kconfig
5080index c84c88b..2a6e1ba 100644
5081--- a/arch/ia64/Kconfig
5082+++ b/arch/ia64/Kconfig
5083@@ -549,6 +549,7 @@ source "drivers/sn/Kconfig"
5084 config KEXEC
5085 bool "kexec system call"
5086 depends on !IA64_HP_SIM && (!SMP || HOTPLUG_CPU)
5087+ depends on !GRKERNSEC_KMEM
5088 help
5089 kexec is a system call that implements the ability to shutdown your
5090 current kernel, and to start another kernel. It is like a reboot
5091diff --git a/arch/ia64/Makefile b/arch/ia64/Makefile
5092index 5441b14..039a446 100644
5093--- a/arch/ia64/Makefile
5094+++ b/arch/ia64/Makefile
5095@@ -99,5 +99,6 @@ endef
5096 archprepare: make_nr_irqs_h FORCE
5097 PHONY += make_nr_irqs_h FORCE
5098
5099+make_nr_irqs_h: KBUILD_CFLAGS := $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS))
5100 make_nr_irqs_h: FORCE
5101 $(Q)$(MAKE) $(build)=arch/ia64/kernel include/generated/nr-irqs.h
5102diff --git a/arch/ia64/include/asm/atomic.h b/arch/ia64/include/asm/atomic.h
5103index 0bf0350..2ad1957 100644
5104--- a/arch/ia64/include/asm/atomic.h
5105+++ b/arch/ia64/include/asm/atomic.h
5106@@ -193,4 +193,14 @@ atomic64_add_negative (__s64 i, atomic64_t *v)
5107 #define atomic64_inc(v) atomic64_add(1, (v))
5108 #define atomic64_dec(v) atomic64_sub(1, (v))
5109
5110+#define atomic64_read_unchecked(v) atomic64_read(v)
5111+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
5112+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
5113+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
5114+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
5115+#define atomic64_inc_unchecked(v) atomic64_inc(v)
5116+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
5117+#define atomic64_dec_unchecked(v) atomic64_dec(v)
5118+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
5119+
5120 #endif /* _ASM_IA64_ATOMIC_H */
5121diff --git a/arch/ia64/include/asm/barrier.h b/arch/ia64/include/asm/barrier.h
5122index a48957c..e097b56 100644
5123--- a/arch/ia64/include/asm/barrier.h
5124+++ b/arch/ia64/include/asm/barrier.h
5125@@ -67,7 +67,7 @@
5126 do { \
5127 compiletime_assert_atomic_type(*p); \
5128 barrier(); \
5129- ACCESS_ONCE(*p) = (v); \
5130+ ACCESS_ONCE_RW(*p) = (v); \
5131 } while (0)
5132
5133 #define smp_load_acquire(p) \
5134diff --git a/arch/ia64/include/asm/cache.h b/arch/ia64/include/asm/cache.h
5135index 988254a..e1ee885 100644
5136--- a/arch/ia64/include/asm/cache.h
5137+++ b/arch/ia64/include/asm/cache.h
5138@@ -1,6 +1,7 @@
5139 #ifndef _ASM_IA64_CACHE_H
5140 #define _ASM_IA64_CACHE_H
5141
5142+#include <linux/const.h>
5143
5144 /*
5145 * Copyright (C) 1998-2000 Hewlett-Packard Co
5146@@ -9,7 +10,7 @@
5147
5148 /* Bytes per L1 (data) cache line. */
5149 #define L1_CACHE_SHIFT CONFIG_IA64_L1_CACHE_SHIFT
5150-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5151+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5152
5153 #ifdef CONFIG_SMP
5154 # define SMP_CACHE_SHIFT L1_CACHE_SHIFT
5155diff --git a/arch/ia64/include/asm/elf.h b/arch/ia64/include/asm/elf.h
5156index 5a83c5c..4d7f553 100644
5157--- a/arch/ia64/include/asm/elf.h
5158+++ b/arch/ia64/include/asm/elf.h
5159@@ -42,6 +42,13 @@
5160 */
5161 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x800000000UL)
5162
5163+#ifdef CONFIG_PAX_ASLR
5164+#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
5165+
5166+#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
5167+#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
5168+#endif
5169+
5170 #define PT_IA_64_UNWIND 0x70000001
5171
5172 /* IA-64 relocations: */
5173diff --git a/arch/ia64/include/asm/pgalloc.h b/arch/ia64/include/asm/pgalloc.h
5174index 5767cdf..7462574 100644
5175--- a/arch/ia64/include/asm/pgalloc.h
5176+++ b/arch/ia64/include/asm/pgalloc.h
5177@@ -39,6 +39,12 @@ pgd_populate(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
5178 pgd_val(*pgd_entry) = __pa(pud);
5179 }
5180
5181+static inline void
5182+pgd_populate_kernel(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
5183+{
5184+ pgd_populate(mm, pgd_entry, pud);
5185+}
5186+
5187 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
5188 {
5189 return quicklist_alloc(0, GFP_KERNEL, NULL);
5190@@ -57,6 +63,12 @@ pud_populate(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
5191 pud_val(*pud_entry) = __pa(pmd);
5192 }
5193
5194+static inline void
5195+pud_populate_kernel(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
5196+{
5197+ pud_populate(mm, pud_entry, pmd);
5198+}
5199+
5200 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
5201 {
5202 return quicklist_alloc(0, GFP_KERNEL, NULL);
5203diff --git a/arch/ia64/include/asm/pgtable.h b/arch/ia64/include/asm/pgtable.h
5204index 7935115..c0eca6a 100644
5205--- a/arch/ia64/include/asm/pgtable.h
5206+++ b/arch/ia64/include/asm/pgtable.h
5207@@ -12,7 +12,7 @@
5208 * David Mosberger-Tang <davidm@hpl.hp.com>
5209 */
5210
5211-
5212+#include <linux/const.h>
5213 #include <asm/mman.h>
5214 #include <asm/page.h>
5215 #include <asm/processor.h>
5216@@ -142,6 +142,17 @@
5217 #define PAGE_READONLY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5218 #define PAGE_COPY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5219 #define PAGE_COPY_EXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RX)
5220+
5221+#ifdef CONFIG_PAX_PAGEEXEC
5222+# define PAGE_SHARED_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RW)
5223+# define PAGE_READONLY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5224+# define PAGE_COPY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5225+#else
5226+# define PAGE_SHARED_NOEXEC PAGE_SHARED
5227+# define PAGE_READONLY_NOEXEC PAGE_READONLY
5228+# define PAGE_COPY_NOEXEC PAGE_COPY
5229+#endif
5230+
5231 #define PAGE_GATE __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_X_RX)
5232 #define PAGE_KERNEL __pgprot(__DIRTY_BITS | _PAGE_PL_0 | _PAGE_AR_RWX)
5233 #define PAGE_KERNELRX __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_RX)
5234diff --git a/arch/ia64/include/asm/spinlock.h b/arch/ia64/include/asm/spinlock.h
5235index 45698cd..e8e2dbc 100644
5236--- a/arch/ia64/include/asm/spinlock.h
5237+++ b/arch/ia64/include/asm/spinlock.h
5238@@ -71,7 +71,7 @@ static __always_inline void __ticket_spin_unlock(arch_spinlock_t *lock)
5239 unsigned short *p = (unsigned short *)&lock->lock + 1, tmp;
5240
5241 asm volatile ("ld2.bias %0=[%1]" : "=r"(tmp) : "r"(p));
5242- ACCESS_ONCE(*p) = (tmp + 2) & ~1;
5243+ ACCESS_ONCE_RW(*p) = (tmp + 2) & ~1;
5244 }
5245
5246 static __always_inline void __ticket_spin_unlock_wait(arch_spinlock_t *lock)
5247diff --git a/arch/ia64/include/asm/uaccess.h b/arch/ia64/include/asm/uaccess.h
5248index 449c8c0..3d4b1e9 100644
5249--- a/arch/ia64/include/asm/uaccess.h
5250+++ b/arch/ia64/include/asm/uaccess.h
5251@@ -70,6 +70,7 @@
5252 && ((segment).seg == KERNEL_DS.seg \
5253 || likely(REGION_OFFSET((unsigned long) (addr)) < RGN_MAP_LIMIT))); \
5254 })
5255+#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
5256 #define access_ok(type, addr, size) __access_ok((addr), (size), get_fs())
5257
5258 /*
5259@@ -240,12 +241,24 @@ extern unsigned long __must_check __copy_user (void __user *to, const void __use
5260 static inline unsigned long
5261 __copy_to_user (void __user *to, const void *from, unsigned long count)
5262 {
5263+ if (count > INT_MAX)
5264+ return count;
5265+
5266+ if (!__builtin_constant_p(count))
5267+ check_object_size(from, count, true);
5268+
5269 return __copy_user(to, (__force void __user *) from, count);
5270 }
5271
5272 static inline unsigned long
5273 __copy_from_user (void *to, const void __user *from, unsigned long count)
5274 {
5275+ if (count > INT_MAX)
5276+ return count;
5277+
5278+ if (!__builtin_constant_p(count))
5279+ check_object_size(to, count, false);
5280+
5281 return __copy_user((__force void __user *) to, from, count);
5282 }
5283
5284@@ -255,10 +268,13 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
5285 ({ \
5286 void __user *__cu_to = (to); \
5287 const void *__cu_from = (from); \
5288- long __cu_len = (n); \
5289+ unsigned long __cu_len = (n); \
5290 \
5291- if (__access_ok(__cu_to, __cu_len, get_fs())) \
5292+ if (__cu_len <= INT_MAX && __access_ok(__cu_to, __cu_len, get_fs())) { \
5293+ if (!__builtin_constant_p(n)) \
5294+ check_object_size(__cu_from, __cu_len, true); \
5295 __cu_len = __copy_user(__cu_to, (__force void __user *) __cu_from, __cu_len); \
5296+ } \
5297 __cu_len; \
5298 })
5299
5300@@ -266,11 +282,14 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
5301 ({ \
5302 void *__cu_to = (to); \
5303 const void __user *__cu_from = (from); \
5304- long __cu_len = (n); \
5305+ unsigned long __cu_len = (n); \
5306 \
5307 __chk_user_ptr(__cu_from); \
5308- if (__access_ok(__cu_from, __cu_len, get_fs())) \
5309+ if (__cu_len <= INT_MAX && __access_ok(__cu_from, __cu_len, get_fs())) { \
5310+ if (!__builtin_constant_p(n)) \
5311+ check_object_size(__cu_to, __cu_len, false); \
5312 __cu_len = __copy_user((__force void __user *) __cu_to, __cu_from, __cu_len); \
5313+ } \
5314 __cu_len; \
5315 })
5316
5317diff --git a/arch/ia64/kernel/module.c b/arch/ia64/kernel/module.c
5318index 24603be..948052d 100644
5319--- a/arch/ia64/kernel/module.c
5320+++ b/arch/ia64/kernel/module.c
5321@@ -307,8 +307,7 @@ plt_target (struct plt_entry *plt)
5322 void
5323 module_free (struct module *mod, void *module_region)
5324 {
5325- if (mod && mod->arch.init_unw_table &&
5326- module_region == mod->module_init) {
5327+ if (mod && mod->arch.init_unw_table && module_region == mod->module_init_rx) {
5328 unw_remove_unwind_table(mod->arch.init_unw_table);
5329 mod->arch.init_unw_table = NULL;
5330 }
5331@@ -494,15 +493,39 @@ module_frob_arch_sections (Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, char *secstrings,
5332 }
5333
5334 static inline int
5335+in_init_rx (const struct module *mod, uint64_t addr)
5336+{
5337+ return addr - (uint64_t) mod->module_init_rx < mod->init_size_rx;
5338+}
5339+
5340+static inline int
5341+in_init_rw (const struct module *mod, uint64_t addr)
5342+{
5343+ return addr - (uint64_t) mod->module_init_rw < mod->init_size_rw;
5344+}
5345+
5346+static inline int
5347 in_init (const struct module *mod, uint64_t addr)
5348 {
5349- return addr - (uint64_t) mod->module_init < mod->init_size;
5350+ return in_init_rx(mod, addr) || in_init_rw(mod, addr);
5351+}
5352+
5353+static inline int
5354+in_core_rx (const struct module *mod, uint64_t addr)
5355+{
5356+ return addr - (uint64_t) mod->module_core_rx < mod->core_size_rx;
5357+}
5358+
5359+static inline int
5360+in_core_rw (const struct module *mod, uint64_t addr)
5361+{
5362+ return addr - (uint64_t) mod->module_core_rw < mod->core_size_rw;
5363 }
5364
5365 static inline int
5366 in_core (const struct module *mod, uint64_t addr)
5367 {
5368- return addr - (uint64_t) mod->module_core < mod->core_size;
5369+ return in_core_rx(mod, addr) || in_core_rw(mod, addr);
5370 }
5371
5372 static inline int
5373@@ -685,7 +708,14 @@ do_reloc (struct module *mod, uint8_t r_type, Elf64_Sym *sym, uint64_t addend,
5374 break;
5375
5376 case RV_BDREL:
5377- val -= (uint64_t) (in_init(mod, val) ? mod->module_init : mod->module_core);
5378+ if (in_init_rx(mod, val))
5379+ val -= (uint64_t) mod->module_init_rx;
5380+ else if (in_init_rw(mod, val))
5381+ val -= (uint64_t) mod->module_init_rw;
5382+ else if (in_core_rx(mod, val))
5383+ val -= (uint64_t) mod->module_core_rx;
5384+ else if (in_core_rw(mod, val))
5385+ val -= (uint64_t) mod->module_core_rw;
5386 break;
5387
5388 case RV_LTV:
5389@@ -820,15 +850,15 @@ apply_relocate_add (Elf64_Shdr *sechdrs, const char *strtab, unsigned int symind
5390 * addresses have been selected...
5391 */
5392 uint64_t gp;
5393- if (mod->core_size > MAX_LTOFF)
5394+ if (mod->core_size_rx + mod->core_size_rw > MAX_LTOFF)
5395 /*
5396 * This takes advantage of fact that SHF_ARCH_SMALL gets allocated
5397 * at the end of the module.
5398 */
5399- gp = mod->core_size - MAX_LTOFF / 2;
5400+ gp = mod->core_size_rx + mod->core_size_rw - MAX_LTOFF / 2;
5401 else
5402- gp = mod->core_size / 2;
5403- gp = (uint64_t) mod->module_core + ((gp + 7) & -8);
5404+ gp = (mod->core_size_rx + mod->core_size_rw) / 2;
5405+ gp = (uint64_t) mod->module_core_rx + ((gp + 7) & -8);
5406 mod->arch.gp = gp;
5407 DEBUGP("%s: placing gp at 0x%lx\n", __func__, gp);
5408 }
5409diff --git a/arch/ia64/kernel/palinfo.c b/arch/ia64/kernel/palinfo.c
5410index c39c3cd..3c77738 100644
5411--- a/arch/ia64/kernel/palinfo.c
5412+++ b/arch/ia64/kernel/palinfo.c
5413@@ -980,7 +980,7 @@ static int palinfo_cpu_callback(struct notifier_block *nfb,
5414 return NOTIFY_OK;
5415 }
5416
5417-static struct notifier_block __refdata palinfo_cpu_notifier =
5418+static struct notifier_block palinfo_cpu_notifier =
5419 {
5420 .notifier_call = palinfo_cpu_callback,
5421 .priority = 0,
5422diff --git a/arch/ia64/kernel/sys_ia64.c b/arch/ia64/kernel/sys_ia64.c
5423index 41e33f8..65180b2a 100644
5424--- a/arch/ia64/kernel/sys_ia64.c
5425+++ b/arch/ia64/kernel/sys_ia64.c
5426@@ -28,6 +28,7 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5427 unsigned long align_mask = 0;
5428 struct mm_struct *mm = current->mm;
5429 struct vm_unmapped_area_info info;
5430+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
5431
5432 if (len > RGN_MAP_LIMIT)
5433 return -ENOMEM;
5434@@ -43,6 +44,13 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5435 if (REGION_NUMBER(addr) == RGN_HPAGE)
5436 addr = 0;
5437 #endif
5438+
5439+#ifdef CONFIG_PAX_RANDMMAP
5440+ if (mm->pax_flags & MF_PAX_RANDMMAP)
5441+ addr = mm->free_area_cache;
5442+ else
5443+#endif
5444+
5445 if (!addr)
5446 addr = TASK_UNMAPPED_BASE;
5447
5448@@ -61,6 +69,7 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5449 info.high_limit = TASK_SIZE;
5450 info.align_mask = align_mask;
5451 info.align_offset = 0;
5452+ info.threadstack_offset = offset;
5453 return vm_unmapped_area(&info);
5454 }
5455
5456diff --git a/arch/ia64/kernel/vmlinux.lds.S b/arch/ia64/kernel/vmlinux.lds.S
5457index 84f8a52..7c76178 100644
5458--- a/arch/ia64/kernel/vmlinux.lds.S
5459+++ b/arch/ia64/kernel/vmlinux.lds.S
5460@@ -192,7 +192,7 @@ SECTIONS {
5461 /* Per-cpu data: */
5462 . = ALIGN(PERCPU_PAGE_SIZE);
5463 PERCPU_VADDR(SMP_CACHE_BYTES, PERCPU_ADDR, :percpu)
5464- __phys_per_cpu_start = __per_cpu_load;
5465+ __phys_per_cpu_start = per_cpu_load;
5466 /*
5467 * ensure percpu data fits
5468 * into percpu page size
5469diff --git a/arch/ia64/mm/fault.c b/arch/ia64/mm/fault.c
5470index 7225dad..2a7c8256 100644
5471--- a/arch/ia64/mm/fault.c
5472+++ b/arch/ia64/mm/fault.c
5473@@ -72,6 +72,23 @@ mapped_kernel_page_is_present (unsigned long address)
5474 return pte_present(pte);
5475 }
5476
5477+#ifdef CONFIG_PAX_PAGEEXEC
5478+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
5479+{
5480+ unsigned long i;
5481+
5482+ printk(KERN_ERR "PAX: bytes at PC: ");
5483+ for (i = 0; i < 8; i++) {
5484+ unsigned int c;
5485+ if (get_user(c, (unsigned int *)pc+i))
5486+ printk(KERN_CONT "???????? ");
5487+ else
5488+ printk(KERN_CONT "%08x ", c);
5489+ }
5490+ printk("\n");
5491+}
5492+#endif
5493+
5494 # define VM_READ_BIT 0
5495 # define VM_WRITE_BIT 1
5496 # define VM_EXEC_BIT 2
5497@@ -151,8 +168,21 @@ retry:
5498 if (((isr >> IA64_ISR_R_BIT) & 1UL) && (!(vma->vm_flags & (VM_READ | VM_WRITE))))
5499 goto bad_area;
5500
5501- if ((vma->vm_flags & mask) != mask)
5502+ if ((vma->vm_flags & mask) != mask) {
5503+
5504+#ifdef CONFIG_PAX_PAGEEXEC
5505+ if (!(vma->vm_flags & VM_EXEC) && (mask & VM_EXEC)) {
5506+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->cr_iip)
5507+ goto bad_area;
5508+
5509+ up_read(&mm->mmap_sem);
5510+ pax_report_fault(regs, (void *)regs->cr_iip, (void *)regs->r12);
5511+ do_group_exit(SIGKILL);
5512+ }
5513+#endif
5514+
5515 goto bad_area;
5516+ }
5517
5518 /*
5519 * If for any reason at all we couldn't handle the fault, make
5520diff --git a/arch/ia64/mm/hugetlbpage.c b/arch/ia64/mm/hugetlbpage.c
5521index 76069c1..c2aa816 100644
5522--- a/arch/ia64/mm/hugetlbpage.c
5523+++ b/arch/ia64/mm/hugetlbpage.c
5524@@ -149,6 +149,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
5525 unsigned long pgoff, unsigned long flags)
5526 {
5527 struct vm_unmapped_area_info info;
5528+ unsigned long offset = gr_rand_threadstack_offset(current->mm, file, flags);
5529
5530 if (len > RGN_MAP_LIMIT)
5531 return -ENOMEM;
5532@@ -172,6 +173,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
5533 info.high_limit = HPAGE_REGION_BASE + RGN_MAP_LIMIT;
5534 info.align_mask = PAGE_MASK & (HPAGE_SIZE - 1);
5535 info.align_offset = 0;
5536+ info.threadstack_offset = offset;
5537 return vm_unmapped_area(&info);
5538 }
5539
5540diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c
5541index 6b33457..88b5124 100644
5542--- a/arch/ia64/mm/init.c
5543+++ b/arch/ia64/mm/init.c
5544@@ -120,6 +120,19 @@ ia64_init_addr_space (void)
5545 vma->vm_start = current->thread.rbs_bot & PAGE_MASK;
5546 vma->vm_end = vma->vm_start + PAGE_SIZE;
5547 vma->vm_flags = VM_DATA_DEFAULT_FLAGS|VM_GROWSUP|VM_ACCOUNT;
5548+
5549+#ifdef CONFIG_PAX_PAGEEXEC
5550+ if (current->mm->pax_flags & MF_PAX_PAGEEXEC) {
5551+ vma->vm_flags &= ~VM_EXEC;
5552+
5553+#ifdef CONFIG_PAX_MPROTECT
5554+ if (current->mm->pax_flags & MF_PAX_MPROTECT)
5555+ vma->vm_flags &= ~VM_MAYEXEC;
5556+#endif
5557+
5558+ }
5559+#endif
5560+
5561 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
5562 down_write(&current->mm->mmap_sem);
5563 if (insert_vm_struct(current->mm, vma)) {
5564@@ -286,7 +299,7 @@ static int __init gate_vma_init(void)
5565 gate_vma.vm_start = FIXADDR_USER_START;
5566 gate_vma.vm_end = FIXADDR_USER_END;
5567 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
5568- gate_vma.vm_page_prot = __P101;
5569+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
5570
5571 return 0;
5572 }
5573diff --git a/arch/m32r/include/asm/cache.h b/arch/m32r/include/asm/cache.h
5574index 40b3ee9..8c2c112 100644
5575--- a/arch/m32r/include/asm/cache.h
5576+++ b/arch/m32r/include/asm/cache.h
5577@@ -1,8 +1,10 @@
5578 #ifndef _ASM_M32R_CACHE_H
5579 #define _ASM_M32R_CACHE_H
5580
5581+#include <linux/const.h>
5582+
5583 /* L1 cache line size */
5584 #define L1_CACHE_SHIFT 4
5585-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5586+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5587
5588 #endif /* _ASM_M32R_CACHE_H */
5589diff --git a/arch/m32r/lib/usercopy.c b/arch/m32r/lib/usercopy.c
5590index 82abd15..d95ae5d 100644
5591--- a/arch/m32r/lib/usercopy.c
5592+++ b/arch/m32r/lib/usercopy.c
5593@@ -14,6 +14,9 @@
5594 unsigned long
5595 __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
5596 {
5597+ if ((long)n < 0)
5598+ return n;
5599+
5600 prefetch(from);
5601 if (access_ok(VERIFY_WRITE, to, n))
5602 __copy_user(to,from,n);
5603@@ -23,6 +26,9 @@ __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
5604 unsigned long
5605 __generic_copy_from_user(void *to, const void __user *from, unsigned long n)
5606 {
5607+ if ((long)n < 0)
5608+ return n;
5609+
5610 prefetchw(to);
5611 if (access_ok(VERIFY_READ, from, n))
5612 __copy_user_zeroing(to,from,n);
5613diff --git a/arch/m68k/include/asm/cache.h b/arch/m68k/include/asm/cache.h
5614index 0395c51..5f26031 100644
5615--- a/arch/m68k/include/asm/cache.h
5616+++ b/arch/m68k/include/asm/cache.h
5617@@ -4,9 +4,11 @@
5618 #ifndef __ARCH_M68K_CACHE_H
5619 #define __ARCH_M68K_CACHE_H
5620
5621+#include <linux/const.h>
5622+
5623 /* bytes per L1 cache line */
5624 #define L1_CACHE_SHIFT 4
5625-#define L1_CACHE_BYTES (1<< L1_CACHE_SHIFT)
5626+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5627
5628 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
5629
5630diff --git a/arch/metag/include/asm/barrier.h b/arch/metag/include/asm/barrier.h
5631index c7591e8..ecef036 100644
5632--- a/arch/metag/include/asm/barrier.h
5633+++ b/arch/metag/include/asm/barrier.h
5634@@ -89,7 +89,7 @@ static inline void fence(void)
5635 do { \
5636 compiletime_assert_atomic_type(*p); \
5637 smp_mb(); \
5638- ACCESS_ONCE(*p) = (v); \
5639+ ACCESS_ONCE_RW(*p) = (v); \
5640 } while (0)
5641
5642 #define smp_load_acquire(p) \
5643diff --git a/arch/metag/mm/hugetlbpage.c b/arch/metag/mm/hugetlbpage.c
5644index 3c32075..ae0ae75 100644
5645--- a/arch/metag/mm/hugetlbpage.c
5646+++ b/arch/metag/mm/hugetlbpage.c
5647@@ -200,6 +200,7 @@ hugetlb_get_unmapped_area_new_pmd(unsigned long len)
5648 info.high_limit = TASK_SIZE;
5649 info.align_mask = PAGE_MASK & HUGEPT_MASK;
5650 info.align_offset = 0;
5651+ info.threadstack_offset = 0;
5652 return vm_unmapped_area(&info);
5653 }
5654
5655diff --git a/arch/microblaze/include/asm/cache.h b/arch/microblaze/include/asm/cache.h
5656index 4efe96a..60e8699 100644
5657--- a/arch/microblaze/include/asm/cache.h
5658+++ b/arch/microblaze/include/asm/cache.h
5659@@ -13,11 +13,12 @@
5660 #ifndef _ASM_MICROBLAZE_CACHE_H
5661 #define _ASM_MICROBLAZE_CACHE_H
5662
5663+#include <linux/const.h>
5664 #include <asm/registers.h>
5665
5666 #define L1_CACHE_SHIFT 5
5667 /* word-granular cache in microblaze */
5668-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5669+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5670
5671 #define SMP_CACHE_BYTES L1_CACHE_BYTES
5672
5673diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig
5674index 9536ef9..9333776 100644
5675--- a/arch/mips/Kconfig
5676+++ b/arch/mips/Kconfig
5677@@ -2413,6 +2413,7 @@ source "kernel/Kconfig.preempt"
5678
5679 config KEXEC
5680 bool "Kexec system call"
5681+ depends on !GRKERNSEC_KMEM
5682 help
5683 kexec is a system call that implements the ability to shutdown your
5684 current kernel, and to start another kernel. It is like a reboot
5685diff --git a/arch/mips/cavium-octeon/dma-octeon.c b/arch/mips/cavium-octeon/dma-octeon.c
5686index 02f2444..506969c 100644
5687--- a/arch/mips/cavium-octeon/dma-octeon.c
5688+++ b/arch/mips/cavium-octeon/dma-octeon.c
5689@@ -199,7 +199,7 @@ static void octeon_dma_free_coherent(struct device *dev, size_t size,
5690 if (dma_release_from_coherent(dev, order, vaddr))
5691 return;
5692
5693- swiotlb_free_coherent(dev, size, vaddr, dma_handle);
5694+ swiotlb_free_coherent(dev, size, vaddr, dma_handle, attrs);
5695 }
5696
5697 static dma_addr_t octeon_unity_phys_to_dma(struct device *dev, phys_addr_t paddr)
5698diff --git a/arch/mips/include/asm/atomic.h b/arch/mips/include/asm/atomic.h
5699index 6dd6bfc..903b0d6 100644
5700--- a/arch/mips/include/asm/atomic.h
5701+++ b/arch/mips/include/asm/atomic.h
5702@@ -21,15 +21,39 @@
5703 #include <asm/cmpxchg.h>
5704 #include <asm/war.h>
5705
5706+#ifdef CONFIG_GENERIC_ATOMIC64
5707+#include <asm-generic/atomic64.h>
5708+#endif
5709+
5710 #define ATOMIC_INIT(i) { (i) }
5711
5712+#ifdef CONFIG_64BIT
5713+#define _ASM_EXTABLE(from, to) \
5714+" .section __ex_table,\"a\"\n" \
5715+" .dword " #from ", " #to"\n" \
5716+" .previous\n"
5717+#else
5718+#define _ASM_EXTABLE(from, to) \
5719+" .section __ex_table,\"a\"\n" \
5720+" .word " #from ", " #to"\n" \
5721+" .previous\n"
5722+#endif
5723+
5724 /*
5725 * atomic_read - read atomic variable
5726 * @v: pointer of type atomic_t
5727 *
5728 * Atomically reads the value of @v.
5729 */
5730-#define atomic_read(v) ACCESS_ONCE((v)->counter)
5731+static inline int atomic_read(const atomic_t *v)
5732+{
5733+ return ACCESS_ONCE(v->counter);
5734+}
5735+
5736+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
5737+{
5738+ return ACCESS_ONCE(v->counter);
5739+}
5740
5741 /*
5742 * atomic_set - set atomic variable
5743@@ -38,47 +62,77 @@
5744 *
5745 * Atomically sets the value of @v to @i.
5746 */
5747-#define atomic_set(v, i) ((v)->counter = (i))
5748+static inline void atomic_set(atomic_t *v, int i)
5749+{
5750+ v->counter = i;
5751+}
5752
5753-#define ATOMIC_OP(op, c_op, asm_op) \
5754-static __inline__ void atomic_##op(int i, atomic_t * v) \
5755+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
5756+{
5757+ v->counter = i;
5758+}
5759+
5760+#ifdef CONFIG_PAX_REFCOUNT
5761+#define __OVERFLOW_POST \
5762+ " b 4f \n" \
5763+ " .set noreorder \n" \
5764+ "3: b 5f \n" \
5765+ " move %0, %1 \n" \
5766+ " .set reorder \n"
5767+#define __OVERFLOW_EXTABLE \
5768+ "3:\n" \
5769+ _ASM_EXTABLE(2b, 3b)
5770+#else
5771+#define __OVERFLOW_POST
5772+#define __OVERFLOW_EXTABLE
5773+#endif
5774+
5775+#define __ATOMIC_OP(op, suffix, asm_op, extable) \
5776+static inline void atomic_##op##suffix(int i, atomic##suffix##_t * v) \
5777 { \
5778 if (kernel_uses_llsc && R10000_LLSC_WAR) { \
5779 int temp; \
5780 \
5781 __asm__ __volatile__( \
5782- " .set arch=r4000 \n" \
5783- "1: ll %0, %1 # atomic_" #op " \n" \
5784- " " #asm_op " %0, %2 \n" \
5785+ " .set mips3 \n" \
5786+ "1: ll %0, %1 # atomic_" #op #suffix "\n" \
5787+ "2: " #asm_op " %0, %2 \n" \
5788 " sc %0, %1 \n" \
5789 " beqzl %0, 1b \n" \
5790+ extable \
5791 " .set mips0 \n" \
5792 : "=&r" (temp), "+m" (v->counter) \
5793 : "Ir" (i)); \
5794 } else if (kernel_uses_llsc) { \
5795 int temp; \
5796 \
5797- do { \
5798- __asm__ __volatile__( \
5799- " .set arch=r4000 \n" \
5800- " ll %0, %1 # atomic_" #op "\n" \
5801- " " #asm_op " %0, %2 \n" \
5802- " sc %0, %1 \n" \
5803- " .set mips0 \n" \
5804- : "=&r" (temp), "+m" (v->counter) \
5805- : "Ir" (i)); \
5806- } while (unlikely(!temp)); \
5807+ __asm__ __volatile__( \
5808+ " .set mips3 \n" \
5809+ " ll %0, %1 # atomic_" #op #suffix "\n" \
5810+ "2: " #asm_op " %0, %2 \n" \
5811+ " sc %0, %1 \n" \
5812+ " beqz %0, 1b \n" \
5813+ extable \
5814+ " .set mips0 \n" \
5815+ : "=&r" (temp), "+m" (v->counter) \
5816+ : "Ir" (i)); \
5817 } else { \
5818 unsigned long flags; \
5819 \
5820 raw_local_irq_save(flags); \
5821- v->counter c_op i; \
5822+ __asm__ __volatile__( \
5823+ "2: " #asm_op " %0, %1 \n" \
5824+ extable \
5825+ : "+r" (v->counter) : "Ir" (i)); \
5826 raw_local_irq_restore(flags); \
5827 } \
5828 } \
5829
5830-#define ATOMIC_OP_RETURN(op, c_op, asm_op) \
5831-static __inline__ int atomic_##op##_return(int i, atomic_t * v) \
5832+#define ATOMIC_OP(op, asm_op) __ATOMIC_OP(op, , asm_op##u) \
5833+ __ATOMIC_OP(op, _unchecked, asm_op)
5834+
5835+#define __ATOMIC_OP_RETURN(op, suffix, asm_op, post_op, extable) \
5836+static inline int atomic_##op##_return##suffix(int i, atomic##suffix##_t * v) \
5837 { \
5838 int result; \
5839 \
5840@@ -88,37 +142,47 @@ static __inline__ int atomic_##op##_return(int i, atomic_t * v) \
5841 int temp; \
5842 \
5843 __asm__ __volatile__( \
5844- " .set arch=r4000 \n" \
5845- "1: ll %1, %2 # atomic_" #op "_return \n" \
5846- " " #asm_op " %0, %1, %3 \n" \
5847+ " .set mips3 \n" \
5848+ "1: ll %1, %2 # atomic_" #op "_return" #suffix "\n" \
5849+ "2: " #asm_op " %0, %1, %3 \n" \
5850 " sc %0, %2 \n" \
5851 " beqzl %0, 1b \n" \
5852- " " #asm_op " %0, %1, %3 \n" \
5853+ post_op \
5854+ extable \
5855+ "4: " #asm_op " %0, %1, %3 \n" \
5856+ "5: \n" \
5857 " .set mips0 \n" \
5858 : "=&r" (result), "=&r" (temp), "+m" (v->counter) \
5859 : "Ir" (i)); \
5860 } else if (kernel_uses_llsc) { \
5861 int temp; \
5862 \
5863- do { \
5864- __asm__ __volatile__( \
5865- " .set arch=r4000 \n" \
5866- " ll %1, %2 # atomic_" #op "_return \n" \
5867- " " #asm_op " %0, %1, %3 \n" \
5868- " sc %0, %2 \n" \
5869- " .set mips0 \n" \
5870- : "=&r" (result), "=&r" (temp), "+m" (v->counter) \
5871- : "Ir" (i)); \
5872- } while (unlikely(!result)); \
5873+ __asm__ __volatile__( \
5874+ " .set mips3 \n" \
5875+ "1: ll %1, %2 # atomic_" #op "_return" #suffix "\n" \
5876+ "2: " #asm_op " %0, %1, %3 \n" \
5877+ " sc %0, %2 \n" \
5878+ " beqz %0, 1b \n" \
5879+ post_op \
5880+ extable \
5881+ "4: " #asm_op " %0, %1, %3 \n" \
5882+ "5: \n" \
5883+ " .set mips0 \n" \
5884+ : "=&r" (result), "=&r" (temp), "+m" (v->counter) \
5885+ : "Ir" (i)); \
5886 \
5887 result = temp; result c_op i; \
5888 } else { \
5889 unsigned long flags; \
5890 \
5891 raw_local_irq_save(flags); \
5892- result = v->counter; \
5893- result c_op i; \
5894- v->counter = result; \
5895+ __asm__ __volatile__( \
5896+ " lw %0, %1 \n" \
5897+ "2: " #asm_op " %0, %1, %2 \n" \
5898+ " sw %0, %1 \n" \
5899+ "3: \n" \
5900+ extable \
5901+ : "=&r" (result), "+m" (v->counter) : "Ir" (i)); \
5902 raw_local_irq_restore(flags); \
5903 } \
5904 \
5905@@ -127,16 +191,21 @@ static __inline__ int atomic_##op##_return(int i, atomic_t * v) \
5906 return result; \
5907 }
5908
5909-#define ATOMIC_OPS(op, c_op, asm_op) \
5910- ATOMIC_OP(op, c_op, asm_op) \
5911- ATOMIC_OP_RETURN(op, c_op, asm_op)
5912+#define ATOMIC_OP_RETURN(op, asm_op) __ATOMIC_OP_RETURN(op, , asm_op##u, , __OVERFLOW_EXTABLE) \
5913+ __ATOMIC_OP_RETURN(op, _unchecked, asm_op, __OVERFLOW_POST, __OVERFLOW_EXTABLE)
5914
5915-ATOMIC_OPS(add, +=, addu)
5916-ATOMIC_OPS(sub, -=, subu)
5917+#define ATOMIC_OPS(op, asm_op) \
5918+ ATOMIC_OP(op, asm_op) \
5919+ ATOMIC_OP_RETURN(op, asm_op)
5920+
5921+ATOMIC_OPS(add, add)
5922+ATOMIC_OPS(sub, sub)
5923
5924 #undef ATOMIC_OPS
5925 #undef ATOMIC_OP_RETURN
5926+#undef __ATOMIC_OP_RETURN
5927 #undef ATOMIC_OP
5928+#undef __ATOMIC_OP
5929
5930 /*
5931 * atomic_sub_if_positive - conditionally subtract integer from atomic variable
5932@@ -146,7 +215,7 @@ ATOMIC_OPS(sub, -=, subu)
5933 * Atomically test @v and subtract @i if @v is greater or equal than @i.
5934 * The function returns the old value of @v minus @i.
5935 */
5936-static __inline__ int atomic_sub_if_positive(int i, atomic_t * v)
5937+static __inline__ int atomic_sub_if_positive(int i, atomic_t *v)
5938 {
5939 int result;
5940
5941@@ -203,8 +272,26 @@ static __inline__ int atomic_sub_if_positive(int i, atomic_t * v)
5942 return result;
5943 }
5944
5945-#define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
5946-#define atomic_xchg(v, new) (xchg(&((v)->counter), (new)))
5947+static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
5948+{
5949+ return cmpxchg(&v->counter, old, new);
5950+}
5951+
5952+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old,
5953+ int new)
5954+{
5955+ return cmpxchg(&(v->counter), old, new);
5956+}
5957+
5958+static inline int atomic_xchg(atomic_t *v, int new)
5959+{
5960+ return xchg(&v->counter, new);
5961+}
5962+
5963+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
5964+{
5965+ return xchg(&(v->counter), new);
5966+}
5967
5968 /**
5969 * __atomic_add_unless - add unless the number is a given value
5970@@ -232,6 +319,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5971
5972 #define atomic_dec_return(v) atomic_sub_return(1, (v))
5973 #define atomic_inc_return(v) atomic_add_return(1, (v))
5974+static __inline__ int atomic_inc_return_unchecked(atomic_unchecked_t *v)
5975+{
5976+ return atomic_add_return_unchecked(1, v);
5977+}
5978
5979 /*
5980 * atomic_sub_and_test - subtract value from variable and test result
5981@@ -253,6 +344,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5982 * other cases.
5983 */
5984 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
5985+static __inline__ int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
5986+{
5987+ return atomic_add_return_unchecked(1, v) == 0;
5988+}
5989
5990 /*
5991 * atomic_dec_and_test - decrement by 1 and test
5992@@ -277,6 +372,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5993 * Atomically increments @v by 1.
5994 */
5995 #define atomic_inc(v) atomic_add(1, (v))
5996+static __inline__ void atomic_inc_unchecked(atomic_unchecked_t *v)
5997+{
5998+ atomic_add_unchecked(1, v);
5999+}
6000
6001 /*
6002 * atomic_dec - decrement and test
6003@@ -285,6 +384,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6004 * Atomically decrements @v by 1.
6005 */
6006 #define atomic_dec(v) atomic_sub(1, (v))
6007+static __inline__ void atomic_dec_unchecked(atomic_unchecked_t *v)
6008+{
6009+ atomic_sub_unchecked(1, v);
6010+}
6011
6012 /*
6013 * atomic_add_negative - add and test if negative
6014@@ -306,54 +409,77 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6015 * @v: pointer of type atomic64_t
6016 *
6017 */
6018-#define atomic64_read(v) ACCESS_ONCE((v)->counter)
6019+static inline long atomic64_read(const atomic64_t *v)
6020+{
6021+ return ACCESS_ONCE(v->counter);
6022+}
6023+
6024+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
6025+{
6026+ return ACCESS_ONCE(v->counter);
6027+}
6028
6029 /*
6030 * atomic64_set - set atomic variable
6031 * @v: pointer of type atomic64_t
6032 * @i: required value
6033 */
6034-#define atomic64_set(v, i) ((v)->counter = (i))
6035+static inline void atomic64_set(atomic64_t *v, long i)
6036+{
6037+ v->counter = i;
6038+}
6039
6040-#define ATOMIC64_OP(op, c_op, asm_op) \
6041-static __inline__ void atomic64_##op(long i, atomic64_t * v) \
6042+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
6043+{
6044+ v->counter = i;
6045+}
6046+
6047+#define __ATOMIC64_OP(op, suffix, asm_op, extable) \
6048+static inline void atomic64_##op##suffix(long i, atomic64##suffix##_t * v) \
6049 { \
6050 if (kernel_uses_llsc && R10000_LLSC_WAR) { \
6051 long temp; \
6052 \
6053 __asm__ __volatile__( \
6054- " .set arch=r4000 \n" \
6055- "1: lld %0, %1 # atomic64_" #op " \n" \
6056- " " #asm_op " %0, %2 \n" \
6057+ " .set mips3 \n" \
6058+ "1: lld %0, %1 # atomic64_" #op #suffix "\n" \
6059+ "2: " #asm_op " %0, %2 \n" \
6060 " scd %0, %1 \n" \
6061 " beqzl %0, 1b \n" \
6062+ extable \
6063 " .set mips0 \n" \
6064 : "=&r" (temp), "+m" (v->counter) \
6065 : "Ir" (i)); \
6066 } else if (kernel_uses_llsc) { \
6067 long temp; \
6068 \
6069- do { \
6070- __asm__ __volatile__( \
6071- " .set arch=r4000 \n" \
6072- " lld %0, %1 # atomic64_" #op "\n" \
6073- " " #asm_op " %0, %2 \n" \
6074- " scd %0, %1 \n" \
6075- " .set mips0 \n" \
6076- : "=&r" (temp), "+m" (v->counter) \
6077- : "Ir" (i)); \
6078- } while (unlikely(!temp)); \
6079+ __asm__ __volatile__( \
6080+ " .set mips3 \n" \
6081+ " lld %0, %1 # atomic64_" #op #suffix "\n" \
6082+ "2: " #asm_op " %0, %2 \n" \
6083+ " scd %0, %1 \n" \
6084+ " beqz %0, 1b \n" \
6085+ extable \
6086+ " .set mips0 \n" \
6087+ : "=&r" (temp), "+m" (v->counter) \
6088+ : "Ir" (i)); \
6089 } else { \
6090 unsigned long flags; \
6091 \
6092 raw_local_irq_save(flags); \
6093- v->counter c_op i; \
6094+ __asm__ __volatile__( \
6095+ "2: " #asm_op " %0, %1 \n" \
6096+ extable \
6097+ : "+r" (v->counter) : "Ir" (i)); \
6098 raw_local_irq_restore(flags); \
6099 } \
6100 } \
6101
6102-#define ATOMIC64_OP_RETURN(op, c_op, asm_op) \
6103-static __inline__ long atomic64_##op##_return(long i, atomic64_t * v) \
6104+#define ATOMIC64_OP(op, asm_op) __ATOMIC64_OP(op, , asm_op##u) \
6105+ __ATOMIC64_OP(op, _unchecked, asm_op)
6106+
6107+#define __ATOMIC64_OP_RETURN(op, suffix, asm_op, post_op, extable) \
6108+static inline long atomic64_##op##_return##suffix(long i, atomic64##suffix##_t * v)\
6109 { \
6110 long result; \
6111 \
6112@@ -363,38 +489,48 @@ static __inline__ long atomic64_##op##_return(long i, atomic64_t * v) \
6113 long temp; \
6114 \
6115 __asm__ __volatile__( \
6116- " .set arch=r4000 \n" \
6117+ " .set mips3 \n" \
6118 "1: lld %1, %2 # atomic64_" #op "_return\n" \
6119- " " #asm_op " %0, %1, %3 \n" \
6120+ "2: " #asm_op " %0, %1, %3 \n" \
6121 " scd %0, %2 \n" \
6122 " beqzl %0, 1b \n" \
6123- " " #asm_op " %0, %1, %3 \n" \
6124+ post_op \
6125+ extable \
6126+ "4: " #asm_op " %0, %1, %3 \n" \
6127+ "5: \n" \
6128 " .set mips0 \n" \
6129 : "=&r" (result), "=&r" (temp), "+m" (v->counter) \
6130 : "Ir" (i)); \
6131 } else if (kernel_uses_llsc) { \
6132 long temp; \
6133 \
6134- do { \
6135- __asm__ __volatile__( \
6136- " .set arch=r4000 \n" \
6137- " lld %1, %2 # atomic64_" #op "_return\n" \
6138- " " #asm_op " %0, %1, %3 \n" \
6139- " scd %0, %2 \n" \
6140- " .set mips0 \n" \
6141- : "=&r" (result), "=&r" (temp), "=m" (v->counter) \
6142- : "Ir" (i), "m" (v->counter) \
6143- : "memory"); \
6144- } while (unlikely(!result)); \
6145+ __asm__ __volatile__( \
6146+ " .set mips3 \n" \
6147+ "1: lld %1, %2 # atomic64_" #op "_return" #suffix "\n" \
6148+ "2: " #asm_op " %0, %1, %3 \n" \
6149+ " scd %0, %2 \n" \
6150+ " beqz %0, 1b \n" \
6151+ post_op \
6152+ extable \
6153+ "4: " #asm_op " %0, %1, %3 \n" \
6154+ "5: \n" \
6155+ " .set mips0 \n" \
6156+ : "=&r" (result), "=&r" (temp), "=m" (v->counter) \
6157+ : "Ir" (i), "m" (v->counter) \
6158+ : "memory"); \
6159 \
6160 result = temp; result c_op i; \
6161 } else { \
6162 unsigned long flags; \
6163 \
6164 raw_local_irq_save(flags); \
6165- result = v->counter; \
6166- result c_op i; \
6167- v->counter = result; \
6168+ __asm__ __volatile__( \
6169+ " ld %0, %1 \n" \
6170+ "2: " #asm_op " %0, %1, %2 \n" \
6171+ " sd %0, %1 \n" \
6172+ "3: \n" \
6173+ extable \
6174+ : "=&r" (result), "+m" (v->counter) : "Ir" (i)); \
6175 raw_local_irq_restore(flags); \
6176 } \
6177 \
6178@@ -403,16 +539,23 @@ static __inline__ long atomic64_##op##_return(long i, atomic64_t * v) \
6179 return result; \
6180 }
6181
6182-#define ATOMIC64_OPS(op, c_op, asm_op) \
6183- ATOMIC64_OP(op, c_op, asm_op) \
6184- ATOMIC64_OP_RETURN(op, c_op, asm_op)
6185+#define ATOMIC64_OP_RETURN(op, asm_op) __ATOMIC64_OP_RETURN(op, , asm_op##u, , __OVERFLOW_EXTABLE) \
6186+ __ATOMIC64_OP_RETURN(op, _unchecked, asm_op, __OVERFLOW_POST, __OVERFLOW_EXTABLE)
6187
6188-ATOMIC64_OPS(add, +=, daddu)
6189-ATOMIC64_OPS(sub, -=, dsubu)
6190+#define ATOMIC64_OPS(op, asm_op) \
6191+ ATOMIC64_OP(op, asm_op) \
6192+ ATOMIC64_OP_RETURN(op, asm_op)
6193+
6194+ATOMIC64_OPS(add, dadd)
6195+ATOMIC64_OPS(sub, dsub)
6196
6197 #undef ATOMIC64_OPS
6198 #undef ATOMIC64_OP_RETURN
6199+#undef __ATOMIC64_OP_RETURN
6200 #undef ATOMIC64_OP
6201+#undef __ATOMIC64_OP
6202+#undef __OVERFLOW_EXTABLE
6203+#undef __OVERFLOW_POST
6204
6205 /*
6206 * atomic64_sub_if_positive - conditionally subtract integer from atomic variable
6207@@ -422,7 +565,7 @@ ATOMIC64_OPS(sub, -=, dsubu)
6208 * Atomically test @v and subtract @i if @v is greater or equal than @i.
6209 * The function returns the old value of @v minus @i.
6210 */
6211-static __inline__ long atomic64_sub_if_positive(long i, atomic64_t * v)
6212+static __inline__ long atomic64_sub_if_positive(long i, atomic64_t *v)
6213 {
6214 long result;
6215
6216@@ -479,9 +622,26 @@ static __inline__ long atomic64_sub_if_positive(long i, atomic64_t * v)
6217 return result;
6218 }
6219
6220-#define atomic64_cmpxchg(v, o, n) \
6221- ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
6222-#define atomic64_xchg(v, new) (xchg(&((v)->counter), (new)))
6223+static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
6224+{
6225+ return cmpxchg(&v->counter, old, new);
6226+}
6227+
6228+static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old,
6229+ long new)
6230+{
6231+ return cmpxchg(&(v->counter), old, new);
6232+}
6233+
6234+static inline long atomic64_xchg(atomic64_t *v, long new)
6235+{
6236+ return xchg(&v->counter, new);
6237+}
6238+
6239+static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
6240+{
6241+ return xchg(&(v->counter), new);
6242+}
6243
6244 /**
6245 * atomic64_add_unless - add unless the number is a given value
6246@@ -511,6 +671,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6247
6248 #define atomic64_dec_return(v) atomic64_sub_return(1, (v))
6249 #define atomic64_inc_return(v) atomic64_add_return(1, (v))
6250+#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1, (v))
6251
6252 /*
6253 * atomic64_sub_and_test - subtract value from variable and test result
6254@@ -532,6 +693,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6255 * other cases.
6256 */
6257 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
6258+#define atomic64_inc_and_test_unchecked(v) atomic64_add_return_unchecked(1, (v)) == 0)
6259
6260 /*
6261 * atomic64_dec_and_test - decrement by 1 and test
6262@@ -556,6 +718,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6263 * Atomically increments @v by 1.
6264 */
6265 #define atomic64_inc(v) atomic64_add(1, (v))
6266+#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1, (v))
6267
6268 /*
6269 * atomic64_dec - decrement and test
6270@@ -564,6 +727,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6271 * Atomically decrements @v by 1.
6272 */
6273 #define atomic64_dec(v) atomic64_sub(1, (v))
6274+#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1, (v))
6275
6276 /*
6277 * atomic64_add_negative - add and test if negative
6278diff --git a/arch/mips/include/asm/barrier.h b/arch/mips/include/asm/barrier.h
6279index d0101dd..266982c 100644
6280--- a/arch/mips/include/asm/barrier.h
6281+++ b/arch/mips/include/asm/barrier.h
6282@@ -184,7 +184,7 @@
6283 do { \
6284 compiletime_assert_atomic_type(*p); \
6285 smp_mb(); \
6286- ACCESS_ONCE(*p) = (v); \
6287+ ACCESS_ONCE_RW(*p) = (v); \
6288 } while (0)
6289
6290 #define smp_load_acquire(p) \
6291diff --git a/arch/mips/include/asm/cache.h b/arch/mips/include/asm/cache.h
6292index b4db69f..8f3b093 100644
6293--- a/arch/mips/include/asm/cache.h
6294+++ b/arch/mips/include/asm/cache.h
6295@@ -9,10 +9,11 @@
6296 #ifndef _ASM_CACHE_H
6297 #define _ASM_CACHE_H
6298
6299+#include <linux/const.h>
6300 #include <kmalloc.h>
6301
6302 #define L1_CACHE_SHIFT CONFIG_MIPS_L1_CACHE_SHIFT
6303-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
6304+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
6305
6306 #define SMP_CACHE_SHIFT L1_CACHE_SHIFT
6307 #define SMP_CACHE_BYTES L1_CACHE_BYTES
6308diff --git a/arch/mips/include/asm/elf.h b/arch/mips/include/asm/elf.h
6309index 1d38fe0..9beabc9 100644
6310--- a/arch/mips/include/asm/elf.h
6311+++ b/arch/mips/include/asm/elf.h
6312@@ -381,13 +381,16 @@ extern const char *__elf_platform;
6313 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
6314 #endif
6315
6316+#ifdef CONFIG_PAX_ASLR
6317+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
6318+
6319+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6320+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6321+#endif
6322+
6323 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
6324 struct linux_binprm;
6325 extern int arch_setup_additional_pages(struct linux_binprm *bprm,
6326 int uses_interp);
6327
6328-struct mm_struct;
6329-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
6330-#define arch_randomize_brk arch_randomize_brk
6331-
6332 #endif /* _ASM_ELF_H */
6333diff --git a/arch/mips/include/asm/exec.h b/arch/mips/include/asm/exec.h
6334index c1f6afa..38cc6e9 100644
6335--- a/arch/mips/include/asm/exec.h
6336+++ b/arch/mips/include/asm/exec.h
6337@@ -12,6 +12,6 @@
6338 #ifndef _ASM_EXEC_H
6339 #define _ASM_EXEC_H
6340
6341-extern unsigned long arch_align_stack(unsigned long sp);
6342+#define arch_align_stack(x) ((x) & ~0xfUL)
6343
6344 #endif /* _ASM_EXEC_H */
6345diff --git a/arch/mips/include/asm/hw_irq.h b/arch/mips/include/asm/hw_irq.h
6346index 9e8ef59..1139d6b 100644
6347--- a/arch/mips/include/asm/hw_irq.h
6348+++ b/arch/mips/include/asm/hw_irq.h
6349@@ -10,7 +10,7 @@
6350
6351 #include <linux/atomic.h>
6352
6353-extern atomic_t irq_err_count;
6354+extern atomic_unchecked_t irq_err_count;
6355
6356 /*
6357 * interrupt-retrigger: NOP for now. This may not be appropriate for all
6358diff --git a/arch/mips/include/asm/local.h b/arch/mips/include/asm/local.h
6359index 46dfc3c..a16b13a 100644
6360--- a/arch/mips/include/asm/local.h
6361+++ b/arch/mips/include/asm/local.h
6362@@ -12,15 +12,25 @@ typedef struct
6363 atomic_long_t a;
6364 } local_t;
6365
6366+typedef struct {
6367+ atomic_long_unchecked_t a;
6368+} local_unchecked_t;
6369+
6370 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
6371
6372 #define local_read(l) atomic_long_read(&(l)->a)
6373+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
6374 #define local_set(l, i) atomic_long_set(&(l)->a, (i))
6375+#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
6376
6377 #define local_add(i, l) atomic_long_add((i), (&(l)->a))
6378+#define local_add_unchecked(i, l) atomic_long_add_unchecked((i), (&(l)->a))
6379 #define local_sub(i, l) atomic_long_sub((i), (&(l)->a))
6380+#define local_sub_unchecked(i, l) atomic_long_sub_unchecked((i), (&(l)->a))
6381 #define local_inc(l) atomic_long_inc(&(l)->a)
6382+#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
6383 #define local_dec(l) atomic_long_dec(&(l)->a)
6384+#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
6385
6386 /*
6387 * Same as above, but return the result value
6388@@ -70,6 +80,51 @@ static __inline__ long local_add_return(long i, local_t * l)
6389 return result;
6390 }
6391
6392+static __inline__ long local_add_return_unchecked(long i, local_unchecked_t * l)
6393+{
6394+ unsigned long result;
6395+
6396+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
6397+ unsigned long temp;
6398+
6399+ __asm__ __volatile__(
6400+ " .set mips3 \n"
6401+ "1:" __LL "%1, %2 # local_add_return \n"
6402+ " addu %0, %1, %3 \n"
6403+ __SC "%0, %2 \n"
6404+ " beqzl %0, 1b \n"
6405+ " addu %0, %1, %3 \n"
6406+ " .set mips0 \n"
6407+ : "=&r" (result), "=&r" (temp), "=m" (l->a.counter)
6408+ : "Ir" (i), "m" (l->a.counter)
6409+ : "memory");
6410+ } else if (kernel_uses_llsc) {
6411+ unsigned long temp;
6412+
6413+ __asm__ __volatile__(
6414+ " .set mips3 \n"
6415+ "1:" __LL "%1, %2 # local_add_return \n"
6416+ " addu %0, %1, %3 \n"
6417+ __SC "%0, %2 \n"
6418+ " beqz %0, 1b \n"
6419+ " addu %0, %1, %3 \n"
6420+ " .set mips0 \n"
6421+ : "=&r" (result), "=&r" (temp), "=m" (l->a.counter)
6422+ : "Ir" (i), "m" (l->a.counter)
6423+ : "memory");
6424+ } else {
6425+ unsigned long flags;
6426+
6427+ local_irq_save(flags);
6428+ result = l->a.counter;
6429+ result += i;
6430+ l->a.counter = result;
6431+ local_irq_restore(flags);
6432+ }
6433+
6434+ return result;
6435+}
6436+
6437 static __inline__ long local_sub_return(long i, local_t * l)
6438 {
6439 unsigned long result;
6440@@ -117,6 +172,8 @@ static __inline__ long local_sub_return(long i, local_t * l)
6441
6442 #define local_cmpxchg(l, o, n) \
6443 ((long)cmpxchg_local(&((l)->a.counter), (o), (n)))
6444+#define local_cmpxchg_unchecked(l, o, n) \
6445+ ((long)cmpxchg_local(&((l)->a.counter), (o), (n)))
6446 #define local_xchg(l, n) (atomic_long_xchg((&(l)->a), (n)))
6447
6448 /**
6449diff --git a/arch/mips/include/asm/page.h b/arch/mips/include/asm/page.h
6450index 3be8180..c4798d5 100644
6451--- a/arch/mips/include/asm/page.h
6452+++ b/arch/mips/include/asm/page.h
6453@@ -120,7 +120,7 @@ extern void copy_user_highpage(struct page *to, struct page *from,
6454 #ifdef CONFIG_CPU_MIPS32
6455 typedef struct { unsigned long pte_low, pte_high; } pte_t;
6456 #define pte_val(x) ((x).pte_low | ((unsigned long long)(x).pte_high << 32))
6457- #define __pte(x) ({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; })
6458+ #define __pte(x) ({ pte_t __pte = {(x), (x) >> 32}; __pte; })
6459 #else
6460 typedef struct { unsigned long long pte; } pte_t;
6461 #define pte_val(x) ((x).pte)
6462diff --git a/arch/mips/include/asm/pgalloc.h b/arch/mips/include/asm/pgalloc.h
6463index b336037..5b874cc 100644
6464--- a/arch/mips/include/asm/pgalloc.h
6465+++ b/arch/mips/include/asm/pgalloc.h
6466@@ -37,6 +37,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6467 {
6468 set_pud(pud, __pud((unsigned long)pmd));
6469 }
6470+
6471+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6472+{
6473+ pud_populate(mm, pud, pmd);
6474+}
6475 #endif
6476
6477 /*
6478diff --git a/arch/mips/include/asm/pgtable.h b/arch/mips/include/asm/pgtable.h
6479index d6d1928..ce4f822 100644
6480--- a/arch/mips/include/asm/pgtable.h
6481+++ b/arch/mips/include/asm/pgtable.h
6482@@ -20,6 +20,9 @@
6483 #include <asm/io.h>
6484 #include <asm/pgtable-bits.h>
6485
6486+#define ktla_ktva(addr) (addr)
6487+#define ktva_ktla(addr) (addr)
6488+
6489 struct mm_struct;
6490 struct vm_area_struct;
6491
6492diff --git a/arch/mips/include/asm/thread_info.h b/arch/mips/include/asm/thread_info.h
6493index 7de8658..c109224 100644
6494--- a/arch/mips/include/asm/thread_info.h
6495+++ b/arch/mips/include/asm/thread_info.h
6496@@ -105,6 +105,9 @@ static inline struct thread_info *current_thread_info(void)
6497 #define TIF_SECCOMP 4 /* secure computing */
6498 #define TIF_NOTIFY_RESUME 5 /* callback before returning to user */
6499 #define TIF_RESTORE_SIGMASK 9 /* restore signal mask in do_signal() */
6500+/* li takes a 32bit immediate */
6501+#define TIF_GRSEC_SETXID 10 /* update credentials on syscall entry/exit */
6502+
6503 #define TIF_USEDFPU 16 /* FPU was used by this task this quantum (SMP) */
6504 #define TIF_MEMDIE 18 /* is terminating due to OOM killer */
6505 #define TIF_NOHZ 19 /* in adaptive nohz mode */
6506@@ -138,14 +141,16 @@ static inline struct thread_info *current_thread_info(void)
6507 #define _TIF_USEDMSA (1<<TIF_USEDMSA)
6508 #define _TIF_MSA_CTX_LIVE (1<<TIF_MSA_CTX_LIVE)
6509 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
6510+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
6511
6512 #define _TIF_WORK_SYSCALL_ENTRY (_TIF_NOHZ | _TIF_SYSCALL_TRACE | \
6513 _TIF_SYSCALL_AUDIT | \
6514- _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP)
6515+ _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP | \
6516+ _TIF_GRSEC_SETXID)
6517
6518 /* work to do in syscall_trace_leave() */
6519 #define _TIF_WORK_SYSCALL_EXIT (_TIF_NOHZ | _TIF_SYSCALL_TRACE | \
6520- _TIF_SYSCALL_AUDIT | _TIF_SYSCALL_TRACEPOINT)
6521+ _TIF_SYSCALL_AUDIT | _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
6522
6523 /* work to do on interrupt/exception return */
6524 #define _TIF_WORK_MASK \
6525@@ -153,7 +158,7 @@ static inline struct thread_info *current_thread_info(void)
6526 /* work to do on any return to u-space */
6527 #define _TIF_ALLWORK_MASK (_TIF_NOHZ | _TIF_WORK_MASK | \
6528 _TIF_WORK_SYSCALL_EXIT | \
6529- _TIF_SYSCALL_TRACEPOINT)
6530+ _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
6531
6532 /*
6533 * We stash processor id into a COP0 register to retrieve it fast
6534diff --git a/arch/mips/include/asm/uaccess.h b/arch/mips/include/asm/uaccess.h
6535index 22a5624..7c96295 100644
6536--- a/arch/mips/include/asm/uaccess.h
6537+++ b/arch/mips/include/asm/uaccess.h
6538@@ -130,6 +130,7 @@ extern u64 __ua_limit;
6539 __ok == 0; \
6540 })
6541
6542+#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
6543 #define access_ok(type, addr, size) \
6544 likely(__access_ok((addr), (size), __access_mask))
6545
6546diff --git a/arch/mips/kernel/binfmt_elfn32.c b/arch/mips/kernel/binfmt_elfn32.c
6547index 1188e00..41cf144 100644
6548--- a/arch/mips/kernel/binfmt_elfn32.c
6549+++ b/arch/mips/kernel/binfmt_elfn32.c
6550@@ -50,6 +50,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
6551 #undef ELF_ET_DYN_BASE
6552 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
6553
6554+#ifdef CONFIG_PAX_ASLR
6555+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
6556+
6557+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6558+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6559+#endif
6560+
6561 #include <asm/processor.h>
6562 #include <linux/module.h>
6563 #include <linux/elfcore.h>
6564diff --git a/arch/mips/kernel/binfmt_elfo32.c b/arch/mips/kernel/binfmt_elfo32.c
6565index 9287678..f870e47 100644
6566--- a/arch/mips/kernel/binfmt_elfo32.c
6567+++ b/arch/mips/kernel/binfmt_elfo32.c
6568@@ -70,6 +70,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
6569 #undef ELF_ET_DYN_BASE
6570 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
6571
6572+#ifdef CONFIG_PAX_ASLR
6573+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
6574+
6575+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6576+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6577+#endif
6578+
6579 #include <asm/processor.h>
6580
6581 #include <linux/module.h>
6582diff --git a/arch/mips/kernel/i8259.c b/arch/mips/kernel/i8259.c
6583index 50b3648..c2f3cec 100644
6584--- a/arch/mips/kernel/i8259.c
6585+++ b/arch/mips/kernel/i8259.c
6586@@ -201,7 +201,7 @@ spurious_8259A_irq:
6587 printk(KERN_DEBUG "spurious 8259A interrupt: IRQ%d.\n", irq);
6588 spurious_irq_mask |= irqmask;
6589 }
6590- atomic_inc(&irq_err_count);
6591+ atomic_inc_unchecked(&irq_err_count);
6592 /*
6593 * Theoretically we do not have to handle this IRQ,
6594 * but in Linux this does not cause problems and is
6595diff --git a/arch/mips/kernel/irq-gt641xx.c b/arch/mips/kernel/irq-gt641xx.c
6596index 44a1f79..2bd6aa3 100644
6597--- a/arch/mips/kernel/irq-gt641xx.c
6598+++ b/arch/mips/kernel/irq-gt641xx.c
6599@@ -110,7 +110,7 @@ void gt641xx_irq_dispatch(void)
6600 }
6601 }
6602
6603- atomic_inc(&irq_err_count);
6604+ atomic_inc_unchecked(&irq_err_count);
6605 }
6606
6607 void __init gt641xx_irq_init(void)
6608diff --git a/arch/mips/kernel/irq.c b/arch/mips/kernel/irq.c
6609index d2bfbc2..a8eacd2 100644
6610--- a/arch/mips/kernel/irq.c
6611+++ b/arch/mips/kernel/irq.c
6612@@ -76,17 +76,17 @@ void ack_bad_irq(unsigned int irq)
6613 printk("unexpected IRQ # %d\n", irq);
6614 }
6615
6616-atomic_t irq_err_count;
6617+atomic_unchecked_t irq_err_count;
6618
6619 int arch_show_interrupts(struct seq_file *p, int prec)
6620 {
6621- seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
6622+ seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
6623 return 0;
6624 }
6625
6626 asmlinkage void spurious_interrupt(void)
6627 {
6628- atomic_inc(&irq_err_count);
6629+ atomic_inc_unchecked(&irq_err_count);
6630 }
6631
6632 void __init init_IRQ(void)
6633@@ -109,7 +109,10 @@ void __init init_IRQ(void)
6634 #endif
6635 }
6636
6637+
6638 #ifdef DEBUG_STACKOVERFLOW
6639+extern void gr_handle_kernel_exploit(void);
6640+
6641 static inline void check_stack_overflow(void)
6642 {
6643 unsigned long sp;
6644@@ -125,6 +128,7 @@ static inline void check_stack_overflow(void)
6645 printk("do_IRQ: stack overflow: %ld\n",
6646 sp - sizeof(struct thread_info));
6647 dump_stack();
6648+ gr_handle_kernel_exploit();
6649 }
6650 }
6651 #else
6652diff --git a/arch/mips/kernel/pm-cps.c b/arch/mips/kernel/pm-cps.c
6653index 0614717..002fa43 100644
6654--- a/arch/mips/kernel/pm-cps.c
6655+++ b/arch/mips/kernel/pm-cps.c
6656@@ -172,7 +172,7 @@ int cps_pm_enter_state(enum cps_pm_state state)
6657 nc_core_ready_count = nc_addr;
6658
6659 /* Ensure ready_count is zero-initialised before the assembly runs */
6660- ACCESS_ONCE(*nc_core_ready_count) = 0;
6661+ ACCESS_ONCE_RW(*nc_core_ready_count) = 0;
6662 coupled_barrier(&per_cpu(pm_barrier, core), online);
6663
6664 /* Run the generated entry code */
6665diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
6666index 636b074..8fbb91f 100644
6667--- a/arch/mips/kernel/process.c
6668+++ b/arch/mips/kernel/process.c
6669@@ -520,15 +520,3 @@ unsigned long get_wchan(struct task_struct *task)
6670 out:
6671 return pc;
6672 }
6673-
6674-/*
6675- * Don't forget that the stack pointer must be aligned on a 8 bytes
6676- * boundary for 32-bits ABI and 16 bytes for 64-bits ABI.
6677- */
6678-unsigned long arch_align_stack(unsigned long sp)
6679-{
6680- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
6681- sp -= get_random_int() & ~PAGE_MASK;
6682-
6683- return sp & ALMASK;
6684-}
6685diff --git a/arch/mips/kernel/ptrace.c b/arch/mips/kernel/ptrace.c
6686index 9d1487d..10c5da5 100644
6687--- a/arch/mips/kernel/ptrace.c
6688+++ b/arch/mips/kernel/ptrace.c
6689@@ -761,6 +761,10 @@ long arch_ptrace(struct task_struct *child, long request,
6690 return ret;
6691 }
6692
6693+#ifdef CONFIG_GRKERNSEC_SETXID
6694+extern void gr_delayed_cred_worker(void);
6695+#endif
6696+
6697 /*
6698 * Notification of system call entry/exit
6699 * - triggered by current->work.syscall_trace
6700@@ -777,6 +781,11 @@ asmlinkage long syscall_trace_enter(struct pt_regs *regs, long syscall)
6701 tracehook_report_syscall_entry(regs))
6702 ret = -1;
6703
6704+#ifdef CONFIG_GRKERNSEC_SETXID
6705+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
6706+ gr_delayed_cred_worker();
6707+#endif
6708+
6709 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
6710 trace_sys_enter(regs, regs->regs[2]);
6711
6712diff --git a/arch/mips/kernel/reset.c b/arch/mips/kernel/reset.c
6713index 07fc524..b9d7f28 100644
6714--- a/arch/mips/kernel/reset.c
6715+++ b/arch/mips/kernel/reset.c
6716@@ -13,6 +13,7 @@
6717 #include <linux/reboot.h>
6718
6719 #include <asm/reboot.h>
6720+#include <asm/bug.h>
6721
6722 /*
6723 * Urgs ... Too many MIPS machines to handle this in a generic way.
6724@@ -29,16 +30,19 @@ void machine_restart(char *command)
6725 {
6726 if (_machine_restart)
6727 _machine_restart(command);
6728+ BUG();
6729 }
6730
6731 void machine_halt(void)
6732 {
6733 if (_machine_halt)
6734 _machine_halt();
6735+ BUG();
6736 }
6737
6738 void machine_power_off(void)
6739 {
6740 if (pm_power_off)
6741 pm_power_off();
6742+ BUG();
6743 }
6744diff --git a/arch/mips/kernel/sync-r4k.c b/arch/mips/kernel/sync-r4k.c
6745index 2242bdd..b284048 100644
6746--- a/arch/mips/kernel/sync-r4k.c
6747+++ b/arch/mips/kernel/sync-r4k.c
6748@@ -18,8 +18,8 @@
6749 #include <asm/mipsregs.h>
6750
6751 static atomic_t count_start_flag = ATOMIC_INIT(0);
6752-static atomic_t count_count_start = ATOMIC_INIT(0);
6753-static atomic_t count_count_stop = ATOMIC_INIT(0);
6754+static atomic_unchecked_t count_count_start = ATOMIC_INIT(0);
6755+static atomic_unchecked_t count_count_stop = ATOMIC_INIT(0);
6756 static atomic_t count_reference = ATOMIC_INIT(0);
6757
6758 #define COUNTON 100
6759@@ -58,13 +58,13 @@ void synchronise_count_master(int cpu)
6760
6761 for (i = 0; i < NR_LOOPS; i++) {
6762 /* slaves loop on '!= 2' */
6763- while (atomic_read(&count_count_start) != 1)
6764+ while (atomic_read_unchecked(&count_count_start) != 1)
6765 mb();
6766- atomic_set(&count_count_stop, 0);
6767+ atomic_set_unchecked(&count_count_stop, 0);
6768 smp_wmb();
6769
6770 /* this lets the slaves write their count register */
6771- atomic_inc(&count_count_start);
6772+ atomic_inc_unchecked(&count_count_start);
6773
6774 /*
6775 * Everyone initialises count in the last loop:
6776@@ -75,11 +75,11 @@ void synchronise_count_master(int cpu)
6777 /*
6778 * Wait for all slaves to leave the synchronization point:
6779 */
6780- while (atomic_read(&count_count_stop) != 1)
6781+ while (atomic_read_unchecked(&count_count_stop) != 1)
6782 mb();
6783- atomic_set(&count_count_start, 0);
6784+ atomic_set_unchecked(&count_count_start, 0);
6785 smp_wmb();
6786- atomic_inc(&count_count_stop);
6787+ atomic_inc_unchecked(&count_count_stop);
6788 }
6789 /* Arrange for an interrupt in a short while */
6790 write_c0_compare(read_c0_count() + COUNTON);
6791@@ -112,8 +112,8 @@ void synchronise_count_slave(int cpu)
6792 initcount = atomic_read(&count_reference);
6793
6794 for (i = 0; i < NR_LOOPS; i++) {
6795- atomic_inc(&count_count_start);
6796- while (atomic_read(&count_count_start) != 2)
6797+ atomic_inc_unchecked(&count_count_start);
6798+ while (atomic_read_unchecked(&count_count_start) != 2)
6799 mb();
6800
6801 /*
6802@@ -122,8 +122,8 @@ void synchronise_count_slave(int cpu)
6803 if (i == NR_LOOPS-1)
6804 write_c0_count(initcount);
6805
6806- atomic_inc(&count_count_stop);
6807- while (atomic_read(&count_count_stop) != 2)
6808+ atomic_inc_unchecked(&count_count_stop);
6809+ while (atomic_read_unchecked(&count_count_stop) != 2)
6810 mb();
6811 }
6812 /* Arrange for an interrupt in a short while */
6813diff --git a/arch/mips/kernel/traps.c b/arch/mips/kernel/traps.c
6814index 22b19c2..c5cc8c4 100644
6815--- a/arch/mips/kernel/traps.c
6816+++ b/arch/mips/kernel/traps.c
6817@@ -688,7 +688,18 @@ asmlinkage void do_ov(struct pt_regs *regs)
6818 siginfo_t info;
6819
6820 prev_state = exception_enter();
6821- die_if_kernel("Integer overflow", regs);
6822+ if (unlikely(!user_mode(regs))) {
6823+
6824+#ifdef CONFIG_PAX_REFCOUNT
6825+ if (fixup_exception(regs)) {
6826+ pax_report_refcount_overflow(regs);
6827+ exception_exit(prev_state);
6828+ return;
6829+ }
6830+#endif
6831+
6832+ die("Integer overflow", regs);
6833+ }
6834
6835 info.si_code = FPE_INTOVF;
6836 info.si_signo = SIGFPE;
6837diff --git a/arch/mips/kvm/mips.c b/arch/mips/kvm/mips.c
6838index e3b21e5..ea5ff7c 100644
6839--- a/arch/mips/kvm/mips.c
6840+++ b/arch/mips/kvm/mips.c
6841@@ -805,7 +805,7 @@ long kvm_arch_vm_ioctl(struct file *filp, unsigned int ioctl, unsigned long arg)
6842 return r;
6843 }
6844
6845-int kvm_arch_init(void *opaque)
6846+int kvm_arch_init(const void *opaque)
6847 {
6848 if (kvm_mips_callbacks) {
6849 kvm_err("kvm: module already exists\n");
6850diff --git a/arch/mips/mm/fault.c b/arch/mips/mm/fault.c
6851index becc42b..9e43d4b 100644
6852--- a/arch/mips/mm/fault.c
6853+++ b/arch/mips/mm/fault.c
6854@@ -28,6 +28,23 @@
6855 #include <asm/highmem.h> /* For VMALLOC_END */
6856 #include <linux/kdebug.h>
6857
6858+#ifdef CONFIG_PAX_PAGEEXEC
6859+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
6860+{
6861+ unsigned long i;
6862+
6863+ printk(KERN_ERR "PAX: bytes at PC: ");
6864+ for (i = 0; i < 5; i++) {
6865+ unsigned int c;
6866+ if (get_user(c, (unsigned int *)pc+i))
6867+ printk(KERN_CONT "???????? ");
6868+ else
6869+ printk(KERN_CONT "%08x ", c);
6870+ }
6871+ printk("\n");
6872+}
6873+#endif
6874+
6875 /*
6876 * This routine handles page faults. It determines the address,
6877 * and the problem, and then passes it off to one of the appropriate
6878@@ -199,6 +216,14 @@ bad_area:
6879 bad_area_nosemaphore:
6880 /* User mode accesses just cause a SIGSEGV */
6881 if (user_mode(regs)) {
6882+
6883+#ifdef CONFIG_PAX_PAGEEXEC
6884+ if (cpu_has_rixi && (mm->pax_flags & MF_PAX_PAGEEXEC) && !write && address == instruction_pointer(regs)) {
6885+ pax_report_fault(regs, (void *)address, (void *)user_stack_pointer(regs));
6886+ do_group_exit(SIGKILL);
6887+ }
6888+#endif
6889+
6890 tsk->thread.cp0_badvaddr = address;
6891 tsk->thread.error_code = write;
6892 #if 0
6893diff --git a/arch/mips/mm/mmap.c b/arch/mips/mm/mmap.c
6894index f1baadd..5472dca 100644
6895--- a/arch/mips/mm/mmap.c
6896+++ b/arch/mips/mm/mmap.c
6897@@ -59,6 +59,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
6898 struct vm_area_struct *vma;
6899 unsigned long addr = addr0;
6900 int do_color_align;
6901+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
6902 struct vm_unmapped_area_info info;
6903
6904 if (unlikely(len > TASK_SIZE))
6905@@ -84,6 +85,11 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
6906 do_color_align = 1;
6907
6908 /* requesting a specific address */
6909+
6910+#ifdef CONFIG_PAX_RANDMMAP
6911+ if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
6912+#endif
6913+
6914 if (addr) {
6915 if (do_color_align)
6916 addr = COLOUR_ALIGN(addr, pgoff);
6917@@ -91,14 +97,14 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
6918 addr = PAGE_ALIGN(addr);
6919
6920 vma = find_vma(mm, addr);
6921- if (TASK_SIZE - len >= addr &&
6922- (!vma || addr + len <= vma->vm_start))
6923+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
6924 return addr;
6925 }
6926
6927 info.length = len;
6928 info.align_mask = do_color_align ? (PAGE_MASK & shm_align_mask) : 0;
6929 info.align_offset = pgoff << PAGE_SHIFT;
6930+ info.threadstack_offset = offset;
6931
6932 if (dir == DOWN) {
6933 info.flags = VM_UNMAPPED_AREA_TOPDOWN;
6934@@ -146,6 +152,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
6935 {
6936 unsigned long random_factor = 0UL;
6937
6938+#ifdef CONFIG_PAX_RANDMMAP
6939+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
6940+#endif
6941+
6942 if (current->flags & PF_RANDOMIZE) {
6943 random_factor = get_random_int();
6944 random_factor = random_factor << PAGE_SHIFT;
6945@@ -157,40 +167,25 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
6946
6947 if (mmap_is_legacy()) {
6948 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
6949+
6950+#ifdef CONFIG_PAX_RANDMMAP
6951+ if (mm->pax_flags & MF_PAX_RANDMMAP)
6952+ mm->mmap_base += mm->delta_mmap;
6953+#endif
6954+
6955 mm->get_unmapped_area = arch_get_unmapped_area;
6956 } else {
6957 mm->mmap_base = mmap_base(random_factor);
6958+
6959+#ifdef CONFIG_PAX_RANDMMAP
6960+ if (mm->pax_flags & MF_PAX_RANDMMAP)
6961+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
6962+#endif
6963+
6964 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
6965 }
6966 }
6967
6968-static inline unsigned long brk_rnd(void)
6969-{
6970- unsigned long rnd = get_random_int();
6971-
6972- rnd = rnd << PAGE_SHIFT;
6973- /* 8MB for 32bit, 256MB for 64bit */
6974- if (TASK_IS_32BIT_ADDR)
6975- rnd = rnd & 0x7ffffful;
6976- else
6977- rnd = rnd & 0xffffffful;
6978-
6979- return rnd;
6980-}
6981-
6982-unsigned long arch_randomize_brk(struct mm_struct *mm)
6983-{
6984- unsigned long base = mm->brk;
6985- unsigned long ret;
6986-
6987- ret = PAGE_ALIGN(base + brk_rnd());
6988-
6989- if (ret < mm->brk)
6990- return mm->brk;
6991-
6992- return ret;
6993-}
6994-
6995 int __virt_addr_valid(const volatile void *kaddr)
6996 {
6997 return pfn_valid(PFN_DOWN(virt_to_phys(kaddr)));
6998diff --git a/arch/mips/pci/pci-octeon.c b/arch/mips/pci/pci-octeon.c
6999index 59cccd9..f39ac2f 100644
7000--- a/arch/mips/pci/pci-octeon.c
7001+++ b/arch/mips/pci/pci-octeon.c
7002@@ -327,8 +327,8 @@ static int octeon_write_config(struct pci_bus *bus, unsigned int devfn,
7003
7004
7005 static struct pci_ops octeon_pci_ops = {
7006- octeon_read_config,
7007- octeon_write_config,
7008+ .read = octeon_read_config,
7009+ .write = octeon_write_config,
7010 };
7011
7012 static struct resource octeon_pci_mem_resource = {
7013diff --git a/arch/mips/pci/pcie-octeon.c b/arch/mips/pci/pcie-octeon.c
7014index 5e36c33..eb4a17b 100644
7015--- a/arch/mips/pci/pcie-octeon.c
7016+++ b/arch/mips/pci/pcie-octeon.c
7017@@ -1792,8 +1792,8 @@ static int octeon_dummy_write_config(struct pci_bus *bus, unsigned int devfn,
7018 }
7019
7020 static struct pci_ops octeon_pcie0_ops = {
7021- octeon_pcie0_read_config,
7022- octeon_pcie0_write_config,
7023+ .read = octeon_pcie0_read_config,
7024+ .write = octeon_pcie0_write_config,
7025 };
7026
7027 static struct resource octeon_pcie0_mem_resource = {
7028@@ -1813,8 +1813,8 @@ static struct pci_controller octeon_pcie0_controller = {
7029 };
7030
7031 static struct pci_ops octeon_pcie1_ops = {
7032- octeon_pcie1_read_config,
7033- octeon_pcie1_write_config,
7034+ .read = octeon_pcie1_read_config,
7035+ .write = octeon_pcie1_write_config,
7036 };
7037
7038 static struct resource octeon_pcie1_mem_resource = {
7039@@ -1834,8 +1834,8 @@ static struct pci_controller octeon_pcie1_controller = {
7040 };
7041
7042 static struct pci_ops octeon_dummy_ops = {
7043- octeon_dummy_read_config,
7044- octeon_dummy_write_config,
7045+ .read = octeon_dummy_read_config,
7046+ .write = octeon_dummy_write_config,
7047 };
7048
7049 static struct resource octeon_dummy_mem_resource = {
7050diff --git a/arch/mips/sgi-ip27/ip27-nmi.c b/arch/mips/sgi-ip27/ip27-nmi.c
7051index a2358b4..7cead4f 100644
7052--- a/arch/mips/sgi-ip27/ip27-nmi.c
7053+++ b/arch/mips/sgi-ip27/ip27-nmi.c
7054@@ -187,9 +187,9 @@ void
7055 cont_nmi_dump(void)
7056 {
7057 #ifndef REAL_NMI_SIGNAL
7058- static atomic_t nmied_cpus = ATOMIC_INIT(0);
7059+ static atomic_unchecked_t nmied_cpus = ATOMIC_INIT(0);
7060
7061- atomic_inc(&nmied_cpus);
7062+ atomic_inc_unchecked(&nmied_cpus);
7063 #endif
7064 /*
7065 * Only allow 1 cpu to proceed
7066@@ -233,7 +233,7 @@ cont_nmi_dump(void)
7067 udelay(10000);
7068 }
7069 #else
7070- while (atomic_read(&nmied_cpus) != num_online_cpus());
7071+ while (atomic_read_unchecked(&nmied_cpus) != num_online_cpus());
7072 #endif
7073
7074 /*
7075diff --git a/arch/mips/sni/rm200.c b/arch/mips/sni/rm200.c
7076index a046b30..6799527 100644
7077--- a/arch/mips/sni/rm200.c
7078+++ b/arch/mips/sni/rm200.c
7079@@ -270,7 +270,7 @@ spurious_8259A_irq:
7080 "spurious RM200 8259A interrupt: IRQ%d.\n", irq);
7081 spurious_irq_mask |= irqmask;
7082 }
7083- atomic_inc(&irq_err_count);
7084+ atomic_inc_unchecked(&irq_err_count);
7085 /*
7086 * Theoretically we do not have to handle this IRQ,
7087 * but in Linux this does not cause problems and is
7088diff --git a/arch/mips/vr41xx/common/icu.c b/arch/mips/vr41xx/common/icu.c
7089index 41e873b..34d33a7 100644
7090--- a/arch/mips/vr41xx/common/icu.c
7091+++ b/arch/mips/vr41xx/common/icu.c
7092@@ -653,7 +653,7 @@ static int icu_get_irq(unsigned int irq)
7093
7094 printk(KERN_ERR "spurious ICU interrupt: %04x,%04x\n", pend1, pend2);
7095
7096- atomic_inc(&irq_err_count);
7097+ atomic_inc_unchecked(&irq_err_count);
7098
7099 return -1;
7100 }
7101diff --git a/arch/mips/vr41xx/common/irq.c b/arch/mips/vr41xx/common/irq.c
7102index ae0e4ee..e8f0692 100644
7103--- a/arch/mips/vr41xx/common/irq.c
7104+++ b/arch/mips/vr41xx/common/irq.c
7105@@ -64,7 +64,7 @@ static void irq_dispatch(unsigned int irq)
7106 irq_cascade_t *cascade;
7107
7108 if (irq >= NR_IRQS) {
7109- atomic_inc(&irq_err_count);
7110+ atomic_inc_unchecked(&irq_err_count);
7111 return;
7112 }
7113
7114@@ -84,7 +84,7 @@ static void irq_dispatch(unsigned int irq)
7115 ret = cascade->get_irq(irq);
7116 irq = ret;
7117 if (ret < 0)
7118- atomic_inc(&irq_err_count);
7119+ atomic_inc_unchecked(&irq_err_count);
7120 else
7121 irq_dispatch(irq);
7122 if (!irqd_irq_disabled(idata) && chip->irq_unmask)
7123diff --git a/arch/mn10300/proc-mn103e010/include/proc/cache.h b/arch/mn10300/proc-mn103e010/include/proc/cache.h
7124index 967d144..db12197 100644
7125--- a/arch/mn10300/proc-mn103e010/include/proc/cache.h
7126+++ b/arch/mn10300/proc-mn103e010/include/proc/cache.h
7127@@ -11,12 +11,14 @@
7128 #ifndef _ASM_PROC_CACHE_H
7129 #define _ASM_PROC_CACHE_H
7130
7131+#include <linux/const.h>
7132+
7133 /* L1 cache */
7134
7135 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
7136 #define L1_CACHE_NENTRIES 256 /* number of entries in each way */
7137-#define L1_CACHE_BYTES 16 /* bytes per entry */
7138 #define L1_CACHE_SHIFT 4 /* shift for bytes per entry */
7139+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
7140 #define L1_CACHE_WAYDISP 0x1000 /* displacement of one way from the next */
7141
7142 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
7143diff --git a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
7144index bcb5df2..84fabd2 100644
7145--- a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
7146+++ b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
7147@@ -16,13 +16,15 @@
7148 #ifndef _ASM_PROC_CACHE_H
7149 #define _ASM_PROC_CACHE_H
7150
7151+#include <linux/const.h>
7152+
7153 /*
7154 * L1 cache
7155 */
7156 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
7157 #define L1_CACHE_NENTRIES 128 /* number of entries in each way */
7158-#define L1_CACHE_BYTES 32 /* bytes per entry */
7159 #define L1_CACHE_SHIFT 5 /* shift for bytes per entry */
7160+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
7161 #define L1_CACHE_WAYDISP 0x1000 /* distance from one way to the next */
7162
7163 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
7164diff --git a/arch/openrisc/include/asm/cache.h b/arch/openrisc/include/asm/cache.h
7165index 4ce7a01..449202a 100644
7166--- a/arch/openrisc/include/asm/cache.h
7167+++ b/arch/openrisc/include/asm/cache.h
7168@@ -19,11 +19,13 @@
7169 #ifndef __ASM_OPENRISC_CACHE_H
7170 #define __ASM_OPENRISC_CACHE_H
7171
7172+#include <linux/const.h>
7173+
7174 /* FIXME: How can we replace these with values from the CPU...
7175 * they shouldn't be hard-coded!
7176 */
7177
7178-#define L1_CACHE_BYTES 16
7179 #define L1_CACHE_SHIFT 4
7180+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7181
7182 #endif /* __ASM_OPENRISC_CACHE_H */
7183diff --git a/arch/parisc/include/asm/atomic.h b/arch/parisc/include/asm/atomic.h
7184index 226f8ca..9d9b87d 100644
7185--- a/arch/parisc/include/asm/atomic.h
7186+++ b/arch/parisc/include/asm/atomic.h
7187@@ -273,6 +273,16 @@ static inline long atomic64_dec_if_positive(atomic64_t *v)
7188 return dec;
7189 }
7190
7191+#define atomic64_read_unchecked(v) atomic64_read(v)
7192+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
7193+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
7194+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
7195+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
7196+#define atomic64_inc_unchecked(v) atomic64_inc(v)
7197+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
7198+#define atomic64_dec_unchecked(v) atomic64_dec(v)
7199+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
7200+
7201 #endif /* !CONFIG_64BIT */
7202
7203
7204diff --git a/arch/parisc/include/asm/cache.h b/arch/parisc/include/asm/cache.h
7205index 47f11c7..3420df2 100644
7206--- a/arch/parisc/include/asm/cache.h
7207+++ b/arch/parisc/include/asm/cache.h
7208@@ -5,6 +5,7 @@
7209 #ifndef __ARCH_PARISC_CACHE_H
7210 #define __ARCH_PARISC_CACHE_H
7211
7212+#include <linux/const.h>
7213
7214 /*
7215 * PA 2.0 processors have 64-byte cachelines; PA 1.1 processors have
7216@@ -15,13 +16,13 @@
7217 * just ruin performance.
7218 */
7219 #ifdef CONFIG_PA20
7220-#define L1_CACHE_BYTES 64
7221 #define L1_CACHE_SHIFT 6
7222 #else
7223-#define L1_CACHE_BYTES 32
7224 #define L1_CACHE_SHIFT 5
7225 #endif
7226
7227+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7228+
7229 #ifndef __ASSEMBLY__
7230
7231 #define SMP_CACHE_BYTES L1_CACHE_BYTES
7232diff --git a/arch/parisc/include/asm/elf.h b/arch/parisc/include/asm/elf.h
7233index 3391d06..c23a2cc 100644
7234--- a/arch/parisc/include/asm/elf.h
7235+++ b/arch/parisc/include/asm/elf.h
7236@@ -342,6 +342,13 @@ struct pt_regs; /* forward declaration... */
7237
7238 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000)
7239
7240+#ifdef CONFIG_PAX_ASLR
7241+#define PAX_ELF_ET_DYN_BASE 0x10000UL
7242+
7243+#define PAX_DELTA_MMAP_LEN 16
7244+#define PAX_DELTA_STACK_LEN 16
7245+#endif
7246+
7247 /* This yields a mask that user programs can use to figure out what
7248 instruction set this CPU supports. This could be done in user space,
7249 but it's not easy, and we've already done it here. */
7250diff --git a/arch/parisc/include/asm/pgalloc.h b/arch/parisc/include/asm/pgalloc.h
7251index f213f5b..0af3e8e 100644
7252--- a/arch/parisc/include/asm/pgalloc.h
7253+++ b/arch/parisc/include/asm/pgalloc.h
7254@@ -61,6 +61,11 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
7255 (__u32)(__pa((unsigned long)pmd) >> PxD_VALUE_SHIFT));
7256 }
7257
7258+static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
7259+{
7260+ pgd_populate(mm, pgd, pmd);
7261+}
7262+
7263 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
7264 {
7265 pmd_t *pmd = (pmd_t *)__get_free_pages(GFP_KERNEL|__GFP_REPEAT,
7266@@ -93,6 +98,7 @@ static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
7267 #define pmd_alloc_one(mm, addr) ({ BUG(); ((pmd_t *)2); })
7268 #define pmd_free(mm, x) do { } while (0)
7269 #define pgd_populate(mm, pmd, pte) BUG()
7270+#define pgd_populate_kernel(mm, pmd, pte) BUG()
7271
7272 #endif
7273
7274diff --git a/arch/parisc/include/asm/pgtable.h b/arch/parisc/include/asm/pgtable.h
7275index 22b89d1..ce34230 100644
7276--- a/arch/parisc/include/asm/pgtable.h
7277+++ b/arch/parisc/include/asm/pgtable.h
7278@@ -223,6 +223,17 @@ extern void purge_tlb_entries(struct mm_struct *, unsigned long);
7279 #define PAGE_EXECREAD __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_EXEC |_PAGE_ACCESSED)
7280 #define PAGE_COPY PAGE_EXECREAD
7281 #define PAGE_RWX __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC |_PAGE_ACCESSED)
7282+
7283+#ifdef CONFIG_PAX_PAGEEXEC
7284+# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_ACCESSED)
7285+# define PAGE_COPY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
7286+# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
7287+#else
7288+# define PAGE_SHARED_NOEXEC PAGE_SHARED
7289+# define PAGE_COPY_NOEXEC PAGE_COPY
7290+# define PAGE_READONLY_NOEXEC PAGE_READONLY
7291+#endif
7292+
7293 #define PAGE_KERNEL __pgprot(_PAGE_KERNEL)
7294 #define PAGE_KERNEL_EXEC __pgprot(_PAGE_KERNEL_EXEC)
7295 #define PAGE_KERNEL_RWX __pgprot(_PAGE_KERNEL_RWX)
7296diff --git a/arch/parisc/include/asm/uaccess.h b/arch/parisc/include/asm/uaccess.h
7297index a5cb070..8604ddc 100644
7298--- a/arch/parisc/include/asm/uaccess.h
7299+++ b/arch/parisc/include/asm/uaccess.h
7300@@ -243,10 +243,10 @@ static inline unsigned long __must_check copy_from_user(void *to,
7301 const void __user *from,
7302 unsigned long n)
7303 {
7304- int sz = __compiletime_object_size(to);
7305+ size_t sz = __compiletime_object_size(to);
7306 int ret = -EFAULT;
7307
7308- if (likely(sz == -1 || !__builtin_constant_p(n) || sz >= n))
7309+ if (likely(sz == (size_t)-1 || !__builtin_constant_p(n) || sz >= n))
7310 ret = __copy_from_user(to, from, n);
7311 else
7312 copy_from_user_overflow();
7313diff --git a/arch/parisc/kernel/module.c b/arch/parisc/kernel/module.c
7314index 50dfafc..b9fc230 100644
7315--- a/arch/parisc/kernel/module.c
7316+++ b/arch/parisc/kernel/module.c
7317@@ -98,16 +98,38 @@
7318
7319 /* three functions to determine where in the module core
7320 * or init pieces the location is */
7321+static inline int in_init_rx(struct module *me, void *loc)
7322+{
7323+ return (loc >= me->module_init_rx &&
7324+ loc < (me->module_init_rx + me->init_size_rx));
7325+}
7326+
7327+static inline int in_init_rw(struct module *me, void *loc)
7328+{
7329+ return (loc >= me->module_init_rw &&
7330+ loc < (me->module_init_rw + me->init_size_rw));
7331+}
7332+
7333 static inline int in_init(struct module *me, void *loc)
7334 {
7335- return (loc >= me->module_init &&
7336- loc <= (me->module_init + me->init_size));
7337+ return in_init_rx(me, loc) || in_init_rw(me, loc);
7338+}
7339+
7340+static inline int in_core_rx(struct module *me, void *loc)
7341+{
7342+ return (loc >= me->module_core_rx &&
7343+ loc < (me->module_core_rx + me->core_size_rx));
7344+}
7345+
7346+static inline int in_core_rw(struct module *me, void *loc)
7347+{
7348+ return (loc >= me->module_core_rw &&
7349+ loc < (me->module_core_rw + me->core_size_rw));
7350 }
7351
7352 static inline int in_core(struct module *me, void *loc)
7353 {
7354- return (loc >= me->module_core &&
7355- loc <= (me->module_core + me->core_size));
7356+ return in_core_rx(me, loc) || in_core_rw(me, loc);
7357 }
7358
7359 static inline int in_local(struct module *me, void *loc)
7360@@ -371,13 +393,13 @@ int module_frob_arch_sections(CONST Elf_Ehdr *hdr,
7361 }
7362
7363 /* align things a bit */
7364- me->core_size = ALIGN(me->core_size, 16);
7365- me->arch.got_offset = me->core_size;
7366- me->core_size += gots * sizeof(struct got_entry);
7367+ me->core_size_rw = ALIGN(me->core_size_rw, 16);
7368+ me->arch.got_offset = me->core_size_rw;
7369+ me->core_size_rw += gots * sizeof(struct got_entry);
7370
7371- me->core_size = ALIGN(me->core_size, 16);
7372- me->arch.fdesc_offset = me->core_size;
7373- me->core_size += fdescs * sizeof(Elf_Fdesc);
7374+ me->core_size_rw = ALIGN(me->core_size_rw, 16);
7375+ me->arch.fdesc_offset = me->core_size_rw;
7376+ me->core_size_rw += fdescs * sizeof(Elf_Fdesc);
7377
7378 me->arch.got_max = gots;
7379 me->arch.fdesc_max = fdescs;
7380@@ -395,7 +417,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
7381
7382 BUG_ON(value == 0);
7383
7384- got = me->module_core + me->arch.got_offset;
7385+ got = me->module_core_rw + me->arch.got_offset;
7386 for (i = 0; got[i].addr; i++)
7387 if (got[i].addr == value)
7388 goto out;
7389@@ -413,7 +435,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
7390 #ifdef CONFIG_64BIT
7391 static Elf_Addr get_fdesc(struct module *me, unsigned long value)
7392 {
7393- Elf_Fdesc *fdesc = me->module_core + me->arch.fdesc_offset;
7394+ Elf_Fdesc *fdesc = me->module_core_rw + me->arch.fdesc_offset;
7395
7396 if (!value) {
7397 printk(KERN_ERR "%s: zero OPD requested!\n", me->name);
7398@@ -431,7 +453,7 @@ static Elf_Addr get_fdesc(struct module *me, unsigned long value)
7399
7400 /* Create new one */
7401 fdesc->addr = value;
7402- fdesc->gp = (Elf_Addr)me->module_core + me->arch.got_offset;
7403+ fdesc->gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
7404 return (Elf_Addr)fdesc;
7405 }
7406 #endif /* CONFIG_64BIT */
7407@@ -843,7 +865,7 @@ register_unwind_table(struct module *me,
7408
7409 table = (unsigned char *)sechdrs[me->arch.unwind_section].sh_addr;
7410 end = table + sechdrs[me->arch.unwind_section].sh_size;
7411- gp = (Elf_Addr)me->module_core + me->arch.got_offset;
7412+ gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
7413
7414 DEBUGP("register_unwind_table(), sect = %d at 0x%p - 0x%p (gp=0x%lx)\n",
7415 me->arch.unwind_section, table, end, gp);
7416diff --git a/arch/parisc/kernel/sys_parisc.c b/arch/parisc/kernel/sys_parisc.c
7417index e1ffea2..46ed66e 100644
7418--- a/arch/parisc/kernel/sys_parisc.c
7419+++ b/arch/parisc/kernel/sys_parisc.c
7420@@ -89,6 +89,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7421 unsigned long task_size = TASK_SIZE;
7422 int do_color_align, last_mmap;
7423 struct vm_unmapped_area_info info;
7424+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
7425
7426 if (len > task_size)
7427 return -ENOMEM;
7428@@ -106,6 +107,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7429 goto found_addr;
7430 }
7431
7432+#ifdef CONFIG_PAX_RANDMMAP
7433+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
7434+#endif
7435+
7436 if (addr) {
7437 if (do_color_align && last_mmap)
7438 addr = COLOR_ALIGN(addr, last_mmap, pgoff);
7439@@ -124,6 +129,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7440 info.high_limit = mmap_upper_limit();
7441 info.align_mask = last_mmap ? (PAGE_MASK & (SHM_COLOUR - 1)) : 0;
7442 info.align_offset = shared_align_offset(last_mmap, pgoff);
7443+ info.threadstack_offset = offset;
7444 addr = vm_unmapped_area(&info);
7445
7446 found_addr:
7447@@ -143,6 +149,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7448 unsigned long addr = addr0;
7449 int do_color_align, last_mmap;
7450 struct vm_unmapped_area_info info;
7451+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
7452
7453 #ifdef CONFIG_64BIT
7454 /* This should only ever run for 32-bit processes. */
7455@@ -167,6 +174,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7456 }
7457
7458 /* requesting a specific address */
7459+#ifdef CONFIG_PAX_RANDMMAP
7460+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
7461+#endif
7462+
7463 if (addr) {
7464 if (do_color_align && last_mmap)
7465 addr = COLOR_ALIGN(addr, last_mmap, pgoff);
7466@@ -184,6 +195,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7467 info.high_limit = mm->mmap_base;
7468 info.align_mask = last_mmap ? (PAGE_MASK & (SHM_COLOUR - 1)) : 0;
7469 info.align_offset = shared_align_offset(last_mmap, pgoff);
7470+ info.threadstack_offset = offset;
7471 addr = vm_unmapped_area(&info);
7472 if (!(addr & ~PAGE_MASK))
7473 goto found_addr;
7474@@ -249,6 +261,13 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7475 mm->mmap_legacy_base = mmap_legacy_base();
7476 mm->mmap_base = mmap_upper_limit();
7477
7478+#ifdef CONFIG_PAX_RANDMMAP
7479+ if (mm->pax_flags & MF_PAX_RANDMMAP) {
7480+ mm->mmap_legacy_base += mm->delta_mmap;
7481+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
7482+ }
7483+#endif
7484+
7485 if (mmap_is_legacy()) {
7486 mm->mmap_base = mm->mmap_legacy_base;
7487 mm->get_unmapped_area = arch_get_unmapped_area;
7488diff --git a/arch/parisc/kernel/traps.c b/arch/parisc/kernel/traps.c
7489index 47ee620..1107387 100644
7490--- a/arch/parisc/kernel/traps.c
7491+++ b/arch/parisc/kernel/traps.c
7492@@ -726,9 +726,7 @@ void notrace handle_interruption(int code, struct pt_regs *regs)
7493
7494 down_read(&current->mm->mmap_sem);
7495 vma = find_vma(current->mm,regs->iaoq[0]);
7496- if (vma && (regs->iaoq[0] >= vma->vm_start)
7497- && (vma->vm_flags & VM_EXEC)) {
7498-
7499+ if (vma && (regs->iaoq[0] >= vma->vm_start)) {
7500 fault_address = regs->iaoq[0];
7501 fault_space = regs->iasq[0];
7502
7503diff --git a/arch/parisc/mm/fault.c b/arch/parisc/mm/fault.c
7504index 3ca9c11..d163ef7 100644
7505--- a/arch/parisc/mm/fault.c
7506+++ b/arch/parisc/mm/fault.c
7507@@ -15,6 +15,7 @@
7508 #include <linux/sched.h>
7509 #include <linux/interrupt.h>
7510 #include <linux/module.h>
7511+#include <linux/unistd.h>
7512
7513 #include <asm/uaccess.h>
7514 #include <asm/traps.h>
7515@@ -50,7 +51,7 @@ int show_unhandled_signals = 1;
7516 static unsigned long
7517 parisc_acctyp(unsigned long code, unsigned int inst)
7518 {
7519- if (code == 6 || code == 16)
7520+ if (code == 6 || code == 7 || code == 16)
7521 return VM_EXEC;
7522
7523 switch (inst & 0xf0000000) {
7524@@ -136,6 +137,116 @@ parisc_acctyp(unsigned long code, unsigned int inst)
7525 }
7526 #endif
7527
7528+#ifdef CONFIG_PAX_PAGEEXEC
7529+/*
7530+ * PaX: decide what to do with offenders (instruction_pointer(regs) = fault address)
7531+ *
7532+ * returns 1 when task should be killed
7533+ * 2 when rt_sigreturn trampoline was detected
7534+ * 3 when unpatched PLT trampoline was detected
7535+ */
7536+static int pax_handle_fetch_fault(struct pt_regs *regs)
7537+{
7538+
7539+#ifdef CONFIG_PAX_EMUPLT
7540+ int err;
7541+
7542+ do { /* PaX: unpatched PLT emulation */
7543+ unsigned int bl, depwi;
7544+
7545+ err = get_user(bl, (unsigned int *)instruction_pointer(regs));
7546+ err |= get_user(depwi, (unsigned int *)(instruction_pointer(regs)+4));
7547+
7548+ if (err)
7549+ break;
7550+
7551+ if (bl == 0xEA9F1FDDU && depwi == 0xD6801C1EU) {
7552+ unsigned int ldw, bv, ldw2, addr = instruction_pointer(regs)-12;
7553+
7554+ err = get_user(ldw, (unsigned int *)addr);
7555+ err |= get_user(bv, (unsigned int *)(addr+4));
7556+ err |= get_user(ldw2, (unsigned int *)(addr+8));
7557+
7558+ if (err)
7559+ break;
7560+
7561+ if (ldw == 0x0E801096U &&
7562+ bv == 0xEAC0C000U &&
7563+ ldw2 == 0x0E881095U)
7564+ {
7565+ unsigned int resolver, map;
7566+
7567+ err = get_user(resolver, (unsigned int *)(instruction_pointer(regs)+8));
7568+ err |= get_user(map, (unsigned int *)(instruction_pointer(regs)+12));
7569+ if (err)
7570+ break;
7571+
7572+ regs->gr[20] = instruction_pointer(regs)+8;
7573+ regs->gr[21] = map;
7574+ regs->gr[22] = resolver;
7575+ regs->iaoq[0] = resolver | 3UL;
7576+ regs->iaoq[1] = regs->iaoq[0] + 4;
7577+ return 3;
7578+ }
7579+ }
7580+ } while (0);
7581+#endif
7582+
7583+#ifdef CONFIG_PAX_EMUTRAMP
7584+
7585+#ifndef CONFIG_PAX_EMUSIGRT
7586+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
7587+ return 1;
7588+#endif
7589+
7590+ do { /* PaX: rt_sigreturn emulation */
7591+ unsigned int ldi1, ldi2, bel, nop;
7592+
7593+ err = get_user(ldi1, (unsigned int *)instruction_pointer(regs));
7594+ err |= get_user(ldi2, (unsigned int *)(instruction_pointer(regs)+4));
7595+ err |= get_user(bel, (unsigned int *)(instruction_pointer(regs)+8));
7596+ err |= get_user(nop, (unsigned int *)(instruction_pointer(regs)+12));
7597+
7598+ if (err)
7599+ break;
7600+
7601+ if ((ldi1 == 0x34190000U || ldi1 == 0x34190002U) &&
7602+ ldi2 == 0x3414015AU &&
7603+ bel == 0xE4008200U &&
7604+ nop == 0x08000240U)
7605+ {
7606+ regs->gr[25] = (ldi1 & 2) >> 1;
7607+ regs->gr[20] = __NR_rt_sigreturn;
7608+ regs->gr[31] = regs->iaoq[1] + 16;
7609+ regs->sr[0] = regs->iasq[1];
7610+ regs->iaoq[0] = 0x100UL;
7611+ regs->iaoq[1] = regs->iaoq[0] + 4;
7612+ regs->iasq[0] = regs->sr[2];
7613+ regs->iasq[1] = regs->sr[2];
7614+ return 2;
7615+ }
7616+ } while (0);
7617+#endif
7618+
7619+ return 1;
7620+}
7621+
7622+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
7623+{
7624+ unsigned long i;
7625+
7626+ printk(KERN_ERR "PAX: bytes at PC: ");
7627+ for (i = 0; i < 5; i++) {
7628+ unsigned int c;
7629+ if (get_user(c, (unsigned int *)pc+i))
7630+ printk(KERN_CONT "???????? ");
7631+ else
7632+ printk(KERN_CONT "%08x ", c);
7633+ }
7634+ printk("\n");
7635+}
7636+#endif
7637+
7638 int fixup_exception(struct pt_regs *regs)
7639 {
7640 const struct exception_table_entry *fix;
7641@@ -234,8 +345,33 @@ retry:
7642
7643 good_area:
7644
7645- if ((vma->vm_flags & acc_type) != acc_type)
7646+ if ((vma->vm_flags & acc_type) != acc_type) {
7647+
7648+#ifdef CONFIG_PAX_PAGEEXEC
7649+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && (acc_type & VM_EXEC) &&
7650+ (address & ~3UL) == instruction_pointer(regs))
7651+ {
7652+ up_read(&mm->mmap_sem);
7653+ switch (pax_handle_fetch_fault(regs)) {
7654+
7655+#ifdef CONFIG_PAX_EMUPLT
7656+ case 3:
7657+ return;
7658+#endif
7659+
7660+#ifdef CONFIG_PAX_EMUTRAMP
7661+ case 2:
7662+ return;
7663+#endif
7664+
7665+ }
7666+ pax_report_fault(regs, (void *)instruction_pointer(regs), (void *)regs->gr[30]);
7667+ do_group_exit(SIGKILL);
7668+ }
7669+#endif
7670+
7671 goto bad_area;
7672+ }
7673
7674 /*
7675 * If for any reason at all we couldn't handle the fault, make
7676diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
7677index 88eace4..4ba2591 100644
7678--- a/arch/powerpc/Kconfig
7679+++ b/arch/powerpc/Kconfig
7680@@ -404,6 +404,7 @@ config PPC64_SUPPORTS_MEMORY_FAILURE
7681 config KEXEC
7682 bool "kexec system call"
7683 depends on (PPC_BOOK3S || FSL_BOOKE || (44x && !SMP))
7684+ depends on !GRKERNSEC_KMEM
7685 help
7686 kexec is a system call that implements the ability to shutdown your
7687 current kernel, and to start another kernel. It is like a reboot
7688diff --git a/arch/powerpc/include/asm/atomic.h b/arch/powerpc/include/asm/atomic.h
7689index 512d278..d31fadd 100644
7690--- a/arch/powerpc/include/asm/atomic.h
7691+++ b/arch/powerpc/include/asm/atomic.h
7692@@ -12,6 +12,11 @@
7693
7694 #define ATOMIC_INIT(i) { (i) }
7695
7696+#define _ASM_EXTABLE(from, to) \
7697+" .section __ex_table,\"a\"\n" \
7698+ PPC_LONG" " #from ", " #to"\n" \
7699+" .previous\n"
7700+
7701 static __inline__ int atomic_read(const atomic_t *v)
7702 {
7703 int t;
7704@@ -21,39 +26,80 @@ static __inline__ int atomic_read(const atomic_t *v)
7705 return t;
7706 }
7707
7708+static __inline__ int atomic_read_unchecked(const atomic_unchecked_t *v)
7709+{
7710+ int t;
7711+
7712+ __asm__ __volatile__("lwz%U1%X1 %0,%1" : "=r"(t) : "m"(v->counter));
7713+
7714+ return t;
7715+}
7716+
7717 static __inline__ void atomic_set(atomic_t *v, int i)
7718 {
7719 __asm__ __volatile__("stw%U0%X0 %1,%0" : "=m"(v->counter) : "r"(i));
7720 }
7721
7722-#define ATOMIC_OP(op, asm_op) \
7723-static __inline__ void atomic_##op(int a, atomic_t *v) \
7724+static __inline__ void atomic_set_unchecked(atomic_unchecked_t *v, int i)
7725+{
7726+ __asm__ __volatile__("stw%U0%X0 %1,%0" : "=m"(v->counter) : "r"(i));
7727+}
7728+
7729+#ifdef CONFIG_PAX_REFCOUNT
7730+#define __REFCOUNT_OP(op) op##o.
7731+#define __OVERFLOW_PRE \
7732+ " mcrxr cr0\n"
7733+#define __OVERFLOW_POST \
7734+ " bf 4*cr0+so, 3f\n" \
7735+ "2: .long 0x00c00b00\n" \
7736+ "3:\n"
7737+#define __OVERFLOW_EXTABLE \
7738+ "\n4:\n"
7739+ _ASM_EXTABLE(2b, 4b)
7740+#else
7741+#define __REFCOUNT_OP(op) op
7742+#define __OVERFLOW_PRE
7743+#define __OVERFLOW_POST
7744+#define __OVERFLOW_EXTABLE
7745+#endif
7746+
7747+#define __ATOMIC_OP(op, suffix, pre_op, asm_op, post_op, extable) \
7748+static inline void atomic_##op##suffix(int a, atomic##suffix##_t *v) \
7749 { \
7750 int t; \
7751 \
7752 __asm__ __volatile__( \
7753-"1: lwarx %0,0,%3 # atomic_" #op "\n" \
7754+"1: lwarx %0,0,%3 # atomic_" #op #suffix "\n" \
7755+ pre_op \
7756 #asm_op " %0,%2,%0\n" \
7757+ post_op \
7758 PPC405_ERR77(0,%3) \
7759 " stwcx. %0,0,%3 \n" \
7760 " bne- 1b\n" \
7761+ extable \
7762 : "=&r" (t), "+m" (v->counter) \
7763 : "r" (a), "r" (&v->counter) \
7764 : "cc"); \
7765 } \
7766
7767-#define ATOMIC_OP_RETURN(op, asm_op) \
7768-static __inline__ int atomic_##op##_return(int a, atomic_t *v) \
7769+#define ATOMIC_OP(op, asm_op) __ATOMIC_OP(op, , , asm_op, , ) \
7770+ __ATOMIC_OP(op, _unchecked, __OVERFLOW_PRE, __REFCOUNT_OP(asm_op), __OVERFLOW_POST, __OVERFLOW_EXTABLE)
7771+
7772+#define __ATOMIC_OP_RETURN(op, suffix, pre_op, asm_op, post_op, extable)\
7773+static inline int atomic_##op##_return##suffix(int a, atomic##suffix##_t *v)\
7774 { \
7775 int t; \
7776 \
7777 __asm__ __volatile__( \
7778 PPC_ATOMIC_ENTRY_BARRIER \
7779-"1: lwarx %0,0,%2 # atomic_" #op "_return\n" \
7780+"1: lwarx %0,0,%2 # atomic_" #op "_return" #suffix "\n" \
7781+ pre_op \
7782 #asm_op " %0,%1,%0\n" \
7783+ post_op \
7784 PPC405_ERR77(0,%2) \
7785 " stwcx. %0,0,%2 \n" \
7786 " bne- 1b\n" \
7787+ extable \
7788 PPC_ATOMIC_EXIT_BARRIER \
7789 : "=&r" (t) \
7790 : "r" (a), "r" (&v->counter) \
7791@@ -62,6 +108,9 @@ static __inline__ int atomic_##op##_return(int a, atomic_t *v) \
7792 return t; \
7793 }
7794
7795+#define ATOMIC_OP_RETURN(op, asm_op) __ATOMIC_OP_RETURN(op, , , asm_op, , )\
7796+ __ATOMIC_OP_RETURN(op, _unchecked, __OVERFLOW_PRE, __REFCOUNT_OP(asm_op), __OVERFLOW_POST, __OVERFLOW_EXTABLE)
7797+
7798 #define ATOMIC_OPS(op, asm_op) ATOMIC_OP(op, asm_op) ATOMIC_OP_RETURN(op, asm_op)
7799
7800 ATOMIC_OPS(add, add)
7801@@ -69,42 +118,29 @@ ATOMIC_OPS(sub, subf)
7802
7803 #undef ATOMIC_OPS
7804 #undef ATOMIC_OP_RETURN
7805+#undef __ATOMIC_OP_RETURN
7806 #undef ATOMIC_OP
7807+#undef __ATOMIC_OP
7808
7809 #define atomic_add_negative(a, v) (atomic_add_return((a), (v)) < 0)
7810
7811-static __inline__ void atomic_inc(atomic_t *v)
7812-{
7813- int t;
7814+/*
7815+ * atomic_inc - increment atomic variable
7816+ * @v: pointer of type atomic_t
7817+ *
7818+ * Automatically increments @v by 1
7819+ */
7820+#define atomic_inc(v) atomic_add(1, (v))
7821+#define atomic_inc_return(v) atomic_add_return(1, (v))
7822
7823- __asm__ __volatile__(
7824-"1: lwarx %0,0,%2 # atomic_inc\n\
7825- addic %0,%0,1\n"
7826- PPC405_ERR77(0,%2)
7827-" stwcx. %0,0,%2 \n\
7828- bne- 1b"
7829- : "=&r" (t), "+m" (v->counter)
7830- : "r" (&v->counter)
7831- : "cc", "xer");
7832+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
7833+{
7834+ atomic_add_unchecked(1, v);
7835 }
7836
7837-static __inline__ int atomic_inc_return(atomic_t *v)
7838+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
7839 {
7840- int t;
7841-
7842- __asm__ __volatile__(
7843- PPC_ATOMIC_ENTRY_BARRIER
7844-"1: lwarx %0,0,%1 # atomic_inc_return\n\
7845- addic %0,%0,1\n"
7846- PPC405_ERR77(0,%1)
7847-" stwcx. %0,0,%1 \n\
7848- bne- 1b"
7849- PPC_ATOMIC_EXIT_BARRIER
7850- : "=&r" (t)
7851- : "r" (&v->counter)
7852- : "cc", "xer", "memory");
7853-
7854- return t;
7855+ return atomic_add_return_unchecked(1, v);
7856 }
7857
7858 /*
7859@@ -117,43 +153,38 @@ static __inline__ int atomic_inc_return(atomic_t *v)
7860 */
7861 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
7862
7863-static __inline__ void atomic_dec(atomic_t *v)
7864+static __inline__ int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
7865 {
7866- int t;
7867-
7868- __asm__ __volatile__(
7869-"1: lwarx %0,0,%2 # atomic_dec\n\
7870- addic %0,%0,-1\n"
7871- PPC405_ERR77(0,%2)\
7872-" stwcx. %0,0,%2\n\
7873- bne- 1b"
7874- : "=&r" (t), "+m" (v->counter)
7875- : "r" (&v->counter)
7876- : "cc", "xer");
7877+ return atomic_add_return_unchecked(1, v) == 0;
7878 }
7879
7880-static __inline__ int atomic_dec_return(atomic_t *v)
7881+/*
7882+ * atomic_dec - decrement atomic variable
7883+ * @v: pointer of type atomic_t
7884+ *
7885+ * Atomically decrements @v by 1
7886+ */
7887+#define atomic_dec(v) atomic_sub(1, (v))
7888+#define atomic_dec_return(v) atomic_sub_return(1, (v))
7889+
7890+static __inline__ void atomic_dec_unchecked(atomic_unchecked_t *v)
7891 {
7892- int t;
7893-
7894- __asm__ __volatile__(
7895- PPC_ATOMIC_ENTRY_BARRIER
7896-"1: lwarx %0,0,%1 # atomic_dec_return\n\
7897- addic %0,%0,-1\n"
7898- PPC405_ERR77(0,%1)
7899-" stwcx. %0,0,%1\n\
7900- bne- 1b"
7901- PPC_ATOMIC_EXIT_BARRIER
7902- : "=&r" (t)
7903- : "r" (&v->counter)
7904- : "cc", "xer", "memory");
7905-
7906- return t;
7907+ atomic_sub_unchecked(1, v);
7908 }
7909
7910 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
7911 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
7912
7913+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
7914+{
7915+ return cmpxchg(&(v->counter), old, new);
7916+}
7917+
7918+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
7919+{
7920+ return xchg(&(v->counter), new);
7921+}
7922+
7923 /**
7924 * __atomic_add_unless - add unless the number is a given value
7925 * @v: pointer of type atomic_t
7926@@ -171,11 +202,27 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
7927 PPC_ATOMIC_ENTRY_BARRIER
7928 "1: lwarx %0,0,%1 # __atomic_add_unless\n\
7929 cmpw 0,%0,%3 \n\
7930- beq- 2f \n\
7931- add %0,%2,%0 \n"
7932+ beq- 2f \n"
7933+
7934+#ifdef CONFIG_PAX_REFCOUNT
7935+" mcrxr cr0\n"
7936+" addo. %0,%2,%0\n"
7937+" bf 4*cr0+so, 4f\n"
7938+"3:.long " "0x00c00b00""\n"
7939+"4:\n"
7940+#else
7941+ "add %0,%2,%0 \n"
7942+#endif
7943+
7944 PPC405_ERR77(0,%2)
7945 " stwcx. %0,0,%1 \n\
7946 bne- 1b \n"
7947+"5:"
7948+
7949+#ifdef CONFIG_PAX_REFCOUNT
7950+ _ASM_EXTABLE(3b, 5b)
7951+#endif
7952+
7953 PPC_ATOMIC_EXIT_BARRIER
7954 " subf %0,%2,%0 \n\
7955 2:"
7956@@ -248,6 +295,11 @@ static __inline__ int atomic_dec_if_positive(atomic_t *v)
7957 }
7958 #define atomic_dec_if_positive atomic_dec_if_positive
7959
7960+#define smp_mb__before_atomic_dec() smp_mb()
7961+#define smp_mb__after_atomic_dec() smp_mb()
7962+#define smp_mb__before_atomic_inc() smp_mb()
7963+#define smp_mb__after_atomic_inc() smp_mb()
7964+
7965 #ifdef __powerpc64__
7966
7967 #define ATOMIC64_INIT(i) { (i) }
7968@@ -261,37 +313,60 @@ static __inline__ long atomic64_read(const atomic64_t *v)
7969 return t;
7970 }
7971
7972+static __inline__ long atomic64_read_unchecked(const atomic64_unchecked_t *v)
7973+{
7974+ long t;
7975+
7976+ __asm__ __volatile__("ld%U1%X1 %0,%1" : "=r"(t) : "m"(v->counter));
7977+
7978+ return t;
7979+}
7980+
7981 static __inline__ void atomic64_set(atomic64_t *v, long i)
7982 {
7983 __asm__ __volatile__("std%U0%X0 %1,%0" : "=m"(v->counter) : "r"(i));
7984 }
7985
7986-#define ATOMIC64_OP(op, asm_op) \
7987-static __inline__ void atomic64_##op(long a, atomic64_t *v) \
7988+static __inline__ void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
7989+{
7990+ __asm__ __volatile__("std%U0%X0 %1,%0" : "=m"(v->counter) : "r"(i));
7991+}
7992+
7993+#define __ATOMIC64_OP(op, suffix, pre_op, asm_op, post_op, extable) \
7994+static inline void atomic64_##op##suffix(long a, atomic64##suffix##_t *v)\
7995 { \
7996 long t; \
7997 \
7998 __asm__ __volatile__( \
7999 "1: ldarx %0,0,%3 # atomic64_" #op "\n" \
8000+ pre_op \
8001 #asm_op " %0,%2,%0\n" \
8002+ post_op \
8003 " stdcx. %0,0,%3 \n" \
8004 " bne- 1b\n" \
8005+ extable \
8006 : "=&r" (t), "+m" (v->counter) \
8007 : "r" (a), "r" (&v->counter) \
8008 : "cc"); \
8009 }
8010
8011-#define ATOMIC64_OP_RETURN(op, asm_op) \
8012-static __inline__ long atomic64_##op##_return(long a, atomic64_t *v) \
8013+#define ATOMIC64_OP(op, asm_op) __ATOMIC64_OP(op, , , asm_op, , ) \
8014+ __ATOMIC64_OP(op, _unchecked, __OVERFLOW_PRE, __REFCOUNT_OP(asm_op), __OVERFLOW_POST, __OVERFLOW_EXTABLE)
8015+
8016+#define __ATOMIC64_OP_RETURN(op, suffix, pre_op, asm_op, post_op, extable)\
8017+static inline long atomic64_##op##_return##suffix(long a, atomic64##suffix##_t *v)\
8018 { \
8019 long t; \
8020 \
8021 __asm__ __volatile__( \
8022 PPC_ATOMIC_ENTRY_BARRIER \
8023 "1: ldarx %0,0,%2 # atomic64_" #op "_return\n" \
8024+ pre_op \
8025 #asm_op " %0,%1,%0\n" \
8026+ post_op \
8027 " stdcx. %0,0,%2 \n" \
8028 " bne- 1b\n" \
8029+ extable \
8030 PPC_ATOMIC_EXIT_BARRIER \
8031 : "=&r" (t) \
8032 : "r" (a), "r" (&v->counter) \
8033@@ -300,6 +375,9 @@ static __inline__ long atomic64_##op##_return(long a, atomic64_t *v) \
8034 return t; \
8035 }
8036
8037+#define ATOMIC64_OP_RETURN(op, asm_op) __ATOMIC64_OP_RETURN(op, , , asm_op, , )\
8038+ __ATOMIC64_OP_RETURN(op, _unchecked, __OVERFLOW_PRE, __REFCOUNT_OP(asm_op), __OVERFLOW_POST, __OVERFLOW_EXTABLE)
8039+
8040 #define ATOMIC64_OPS(op, asm_op) ATOMIC64_OP(op, asm_op) ATOMIC64_OP_RETURN(op, asm_op)
8041
8042 ATOMIC64_OPS(add, add)
8043@@ -307,40 +385,33 @@ ATOMIC64_OPS(sub, subf)
8044
8045 #undef ATOMIC64_OPS
8046 #undef ATOMIC64_OP_RETURN
8047+#undef __ATOMIC64_OP_RETURN
8048 #undef ATOMIC64_OP
8049+#undef __ATOMIC64_OP
8050+#undef __OVERFLOW_EXTABLE
8051+#undef __OVERFLOW_POST
8052+#undef __OVERFLOW_PRE
8053+#undef __REFCOUNT_OP
8054
8055 #define atomic64_add_negative(a, v) (atomic64_add_return((a), (v)) < 0)
8056
8057-static __inline__ void atomic64_inc(atomic64_t *v)
8058-{
8059- long t;
8060+/*
8061+ * atomic64_inc - increment atomic variable
8062+ * @v: pointer of type atomic64_t
8063+ *
8064+ * Automatically increments @v by 1
8065+ */
8066+#define atomic64_inc(v) atomic64_add(1, (v))
8067+#define atomic64_inc_return(v) atomic64_add_return(1, (v))
8068
8069- __asm__ __volatile__(
8070-"1: ldarx %0,0,%2 # atomic64_inc\n\
8071- addic %0,%0,1\n\
8072- stdcx. %0,0,%2 \n\
8073- bne- 1b"
8074- : "=&r" (t), "+m" (v->counter)
8075- : "r" (&v->counter)
8076- : "cc", "xer");
8077+static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
8078+{
8079+ atomic64_add_unchecked(1, v);
8080 }
8081
8082-static __inline__ long atomic64_inc_return(atomic64_t *v)
8083+static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
8084 {
8085- long t;
8086-
8087- __asm__ __volatile__(
8088- PPC_ATOMIC_ENTRY_BARRIER
8089-"1: ldarx %0,0,%1 # atomic64_inc_return\n\
8090- addic %0,%0,1\n\
8091- stdcx. %0,0,%1 \n\
8092- bne- 1b"
8093- PPC_ATOMIC_EXIT_BARRIER
8094- : "=&r" (t)
8095- : "r" (&v->counter)
8096- : "cc", "xer", "memory");
8097-
8098- return t;
8099+ return atomic64_add_return_unchecked(1, v);
8100 }
8101
8102 /*
8103@@ -353,36 +424,18 @@ static __inline__ long atomic64_inc_return(atomic64_t *v)
8104 */
8105 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
8106
8107-static __inline__ void atomic64_dec(atomic64_t *v)
8108+/*
8109+ * atomic64_dec - decrement atomic variable
8110+ * @v: pointer of type atomic64_t
8111+ *
8112+ * Atomically decrements @v by 1
8113+ */
8114+#define atomic64_dec(v) atomic64_sub(1, (v))
8115+#define atomic64_dec_return(v) atomic64_sub_return(1, (v))
8116+
8117+static __inline__ void atomic64_dec_unchecked(atomic64_unchecked_t *v)
8118 {
8119- long t;
8120-
8121- __asm__ __volatile__(
8122-"1: ldarx %0,0,%2 # atomic64_dec\n\
8123- addic %0,%0,-1\n\
8124- stdcx. %0,0,%2\n\
8125- bne- 1b"
8126- : "=&r" (t), "+m" (v->counter)
8127- : "r" (&v->counter)
8128- : "cc", "xer");
8129-}
8130-
8131-static __inline__ long atomic64_dec_return(atomic64_t *v)
8132-{
8133- long t;
8134-
8135- __asm__ __volatile__(
8136- PPC_ATOMIC_ENTRY_BARRIER
8137-"1: ldarx %0,0,%1 # atomic64_dec_return\n\
8138- addic %0,%0,-1\n\
8139- stdcx. %0,0,%1\n\
8140- bne- 1b"
8141- PPC_ATOMIC_EXIT_BARRIER
8142- : "=&r" (t)
8143- : "r" (&v->counter)
8144- : "cc", "xer", "memory");
8145-
8146- return t;
8147+ atomic64_sub_unchecked(1, v);
8148 }
8149
8150 #define atomic64_sub_and_test(a, v) (atomic64_sub_return((a), (v)) == 0)
8151@@ -415,6 +468,16 @@ static __inline__ long atomic64_dec_if_positive(atomic64_t *v)
8152 #define atomic64_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
8153 #define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
8154
8155+static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
8156+{
8157+ return cmpxchg(&(v->counter), old, new);
8158+}
8159+
8160+static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
8161+{
8162+ return xchg(&(v->counter), new);
8163+}
8164+
8165 /**
8166 * atomic64_add_unless - add unless the number is a given value
8167 * @v: pointer of type atomic64_t
8168@@ -430,13 +493,29 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
8169
8170 __asm__ __volatile__ (
8171 PPC_ATOMIC_ENTRY_BARRIER
8172-"1: ldarx %0,0,%1 # __atomic_add_unless\n\
8173+"1: ldarx %0,0,%1 # atomic64_add_unless\n\
8174 cmpd 0,%0,%3 \n\
8175- beq- 2f \n\
8176- add %0,%2,%0 \n"
8177+ beq- 2f \n"
8178+
8179+#ifdef CONFIG_PAX_REFCOUNT
8180+" mcrxr cr0\n"
8181+" addo. %0,%2,%0\n"
8182+" bf 4*cr0+so, 4f\n"
8183+"3:.long " "0x00c00b00""\n"
8184+"4:\n"
8185+#else
8186+ "add %0,%2,%0 \n"
8187+#endif
8188+
8189 " stdcx. %0,0,%1 \n\
8190 bne- 1b \n"
8191 PPC_ATOMIC_EXIT_BARRIER
8192+"5:"
8193+
8194+#ifdef CONFIG_PAX_REFCOUNT
8195+ _ASM_EXTABLE(3b, 5b)
8196+#endif
8197+
8198 " subf %0,%2,%0 \n\
8199 2:"
8200 : "=&r" (t)
8201diff --git a/arch/powerpc/include/asm/barrier.h b/arch/powerpc/include/asm/barrier.h
8202index bab79a1..4a3eabc 100644
8203--- a/arch/powerpc/include/asm/barrier.h
8204+++ b/arch/powerpc/include/asm/barrier.h
8205@@ -73,7 +73,7 @@
8206 do { \
8207 compiletime_assert_atomic_type(*p); \
8208 __lwsync(); \
8209- ACCESS_ONCE(*p) = (v); \
8210+ ACCESS_ONCE_RW(*p) = (v); \
8211 } while (0)
8212
8213 #define smp_load_acquire(p) \
8214diff --git a/arch/powerpc/include/asm/cache.h b/arch/powerpc/include/asm/cache.h
8215index 34a05a1..a1f2c67 100644
8216--- a/arch/powerpc/include/asm/cache.h
8217+++ b/arch/powerpc/include/asm/cache.h
8218@@ -4,6 +4,7 @@
8219 #ifdef __KERNEL__
8220
8221 #include <asm/reg.h>
8222+#include <linux/const.h>
8223
8224 /* bytes per L1 cache line */
8225 #if defined(CONFIG_8xx) || defined(CONFIG_403GCX)
8226@@ -23,7 +24,7 @@
8227 #define L1_CACHE_SHIFT 7
8228 #endif
8229
8230-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
8231+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
8232
8233 #define SMP_CACHE_BYTES L1_CACHE_BYTES
8234
8235diff --git a/arch/powerpc/include/asm/elf.h b/arch/powerpc/include/asm/elf.h
8236index 888d8f3..66f581c 100644
8237--- a/arch/powerpc/include/asm/elf.h
8238+++ b/arch/powerpc/include/asm/elf.h
8239@@ -28,8 +28,19 @@
8240 the loader. We need to make sure that it is out of the way of the program
8241 that it will "exec", and that there is sufficient room for the brk. */
8242
8243-extern unsigned long randomize_et_dyn(unsigned long base);
8244-#define ELF_ET_DYN_BASE (randomize_et_dyn(0x20000000))
8245+#define ELF_ET_DYN_BASE (0x20000000)
8246+
8247+#ifdef CONFIG_PAX_ASLR
8248+#define PAX_ELF_ET_DYN_BASE (0x10000000UL)
8249+
8250+#ifdef __powerpc64__
8251+#define PAX_DELTA_MMAP_LEN (is_32bit_task() ? 16 : 28)
8252+#define PAX_DELTA_STACK_LEN (is_32bit_task() ? 16 : 28)
8253+#else
8254+#define PAX_DELTA_MMAP_LEN 15
8255+#define PAX_DELTA_STACK_LEN 15
8256+#endif
8257+#endif
8258
8259 #define ELF_CORE_EFLAGS (is_elf2_task() ? 2 : 0)
8260
8261@@ -129,10 +140,6 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
8262 (0x7ff >> (PAGE_SHIFT - 12)) : \
8263 (0x3ffff >> (PAGE_SHIFT - 12)))
8264
8265-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
8266-#define arch_randomize_brk arch_randomize_brk
8267-
8268-
8269 #ifdef CONFIG_SPU_BASE
8270 /* Notes used in ET_CORE. Note name is "SPU/<fd>/<filename>". */
8271 #define NT_SPU 1
8272diff --git a/arch/powerpc/include/asm/exec.h b/arch/powerpc/include/asm/exec.h
8273index 8196e9c..d83a9f3 100644
8274--- a/arch/powerpc/include/asm/exec.h
8275+++ b/arch/powerpc/include/asm/exec.h
8276@@ -4,6 +4,6 @@
8277 #ifndef _ASM_POWERPC_EXEC_H
8278 #define _ASM_POWERPC_EXEC_H
8279
8280-extern unsigned long arch_align_stack(unsigned long sp);
8281+#define arch_align_stack(x) ((x) & ~0xfUL)
8282
8283 #endif /* _ASM_POWERPC_EXEC_H */
8284diff --git a/arch/powerpc/include/asm/kmap_types.h b/arch/powerpc/include/asm/kmap_types.h
8285index 5acabbd..7ea14fa 100644
8286--- a/arch/powerpc/include/asm/kmap_types.h
8287+++ b/arch/powerpc/include/asm/kmap_types.h
8288@@ -10,7 +10,7 @@
8289 * 2 of the License, or (at your option) any later version.
8290 */
8291
8292-#define KM_TYPE_NR 16
8293+#define KM_TYPE_NR 17
8294
8295 #endif /* __KERNEL__ */
8296 #endif /* _ASM_POWERPC_KMAP_TYPES_H */
8297diff --git a/arch/powerpc/include/asm/local.h b/arch/powerpc/include/asm/local.h
8298index b8da913..c02b593 100644
8299--- a/arch/powerpc/include/asm/local.h
8300+++ b/arch/powerpc/include/asm/local.h
8301@@ -9,21 +9,65 @@ typedef struct
8302 atomic_long_t a;
8303 } local_t;
8304
8305+typedef struct
8306+{
8307+ atomic_long_unchecked_t a;
8308+} local_unchecked_t;
8309+
8310 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
8311
8312 #define local_read(l) atomic_long_read(&(l)->a)
8313+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
8314 #define local_set(l,i) atomic_long_set(&(l)->a, (i))
8315+#define local_set_unchecked(l,i) atomic_long_set_unchecked(&(l)->a, (i))
8316
8317 #define local_add(i,l) atomic_long_add((i),(&(l)->a))
8318+#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
8319 #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
8320+#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
8321 #define local_inc(l) atomic_long_inc(&(l)->a)
8322+#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
8323 #define local_dec(l) atomic_long_dec(&(l)->a)
8324+#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
8325
8326 static __inline__ long local_add_return(long a, local_t *l)
8327 {
8328 long t;
8329
8330 __asm__ __volatile__(
8331+"1:" PPC_LLARX(%0,0,%2,0) " # local_add_return\n"
8332+
8333+#ifdef CONFIG_PAX_REFCOUNT
8334+" mcrxr cr0\n"
8335+" addo. %0,%1,%0\n"
8336+" bf 4*cr0+so, 3f\n"
8337+"2:.long " "0x00c00b00""\n"
8338+#else
8339+" add %0,%1,%0\n"
8340+#endif
8341+
8342+"3:\n"
8343+ PPC405_ERR77(0,%2)
8344+ PPC_STLCX "%0,0,%2 \n\
8345+ bne- 1b"
8346+
8347+#ifdef CONFIG_PAX_REFCOUNT
8348+"\n4:\n"
8349+ _ASM_EXTABLE(2b, 4b)
8350+#endif
8351+
8352+ : "=&r" (t)
8353+ : "r" (a), "r" (&(l->a.counter))
8354+ : "cc", "memory");
8355+
8356+ return t;
8357+}
8358+
8359+static __inline__ long local_add_return_unchecked(long a, local_unchecked_t *l)
8360+{
8361+ long t;
8362+
8363+ __asm__ __volatile__(
8364 "1:" PPC_LLARX(%0,0,%2,0) " # local_add_return\n\
8365 add %0,%1,%0\n"
8366 PPC405_ERR77(0,%2)
8367@@ -101,6 +145,8 @@ static __inline__ long local_dec_return(local_t *l)
8368
8369 #define local_cmpxchg(l, o, n) \
8370 (cmpxchg_local(&((l)->a.counter), (o), (n)))
8371+#define local_cmpxchg_unchecked(l, o, n) \
8372+ (cmpxchg_local(&((l)->a.counter), (o), (n)))
8373 #define local_xchg(l, n) (xchg_local(&((l)->a.counter), (n)))
8374
8375 /**
8376diff --git a/arch/powerpc/include/asm/mman.h b/arch/powerpc/include/asm/mman.h
8377index 8565c25..2865190 100644
8378--- a/arch/powerpc/include/asm/mman.h
8379+++ b/arch/powerpc/include/asm/mman.h
8380@@ -24,7 +24,7 @@ static inline unsigned long arch_calc_vm_prot_bits(unsigned long prot)
8381 }
8382 #define arch_calc_vm_prot_bits(prot) arch_calc_vm_prot_bits(prot)
8383
8384-static inline pgprot_t arch_vm_get_page_prot(unsigned long vm_flags)
8385+static inline pgprot_t arch_vm_get_page_prot(vm_flags_t vm_flags)
8386 {
8387 return (vm_flags & VM_SAO) ? __pgprot(_PAGE_SAO) : __pgprot(0);
8388 }
8389diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h
8390index 26fe1ae..987ffc5 100644
8391--- a/arch/powerpc/include/asm/page.h
8392+++ b/arch/powerpc/include/asm/page.h
8393@@ -227,8 +227,9 @@ extern long long virt_phys_offset;
8394 * and needs to be executable. This means the whole heap ends
8395 * up being executable.
8396 */
8397-#define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
8398- VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8399+#define VM_DATA_DEFAULT_FLAGS32 \
8400+ (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
8401+ VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8402
8403 #define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
8404 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8405@@ -256,6 +257,9 @@ extern long long virt_phys_offset;
8406 #define is_kernel_addr(x) ((x) >= PAGE_OFFSET)
8407 #endif
8408
8409+#define ktla_ktva(addr) (addr)
8410+#define ktva_ktla(addr) (addr)
8411+
8412 #ifndef CONFIG_PPC_BOOK3S_64
8413 /*
8414 * Use the top bit of the higher-level page table entries to indicate whether
8415diff --git a/arch/powerpc/include/asm/page_64.h b/arch/powerpc/include/asm/page_64.h
8416index d908a46..3753f71 100644
8417--- a/arch/powerpc/include/asm/page_64.h
8418+++ b/arch/powerpc/include/asm/page_64.h
8419@@ -172,15 +172,18 @@ do { \
8420 * stack by default, so in the absence of a PT_GNU_STACK program header
8421 * we turn execute permission off.
8422 */
8423-#define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
8424- VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8425+#define VM_STACK_DEFAULT_FLAGS32 \
8426+ (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
8427+ VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8428
8429 #define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
8430 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8431
8432+#ifndef CONFIG_PAX_PAGEEXEC
8433 #define VM_STACK_DEFAULT_FLAGS \
8434 (is_32bit_task() ? \
8435 VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
8436+#endif
8437
8438 #include <asm-generic/getorder.h>
8439
8440diff --git a/arch/powerpc/include/asm/pgalloc-64.h b/arch/powerpc/include/asm/pgalloc-64.h
8441index 4b0be20..c15a27d 100644
8442--- a/arch/powerpc/include/asm/pgalloc-64.h
8443+++ b/arch/powerpc/include/asm/pgalloc-64.h
8444@@ -54,6 +54,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
8445 #ifndef CONFIG_PPC_64K_PAGES
8446
8447 #define pgd_populate(MM, PGD, PUD) pgd_set(PGD, PUD)
8448+#define pgd_populate_kernel(MM, PGD, PUD) pgd_populate((MM), (PGD), (PUD))
8449
8450 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
8451 {
8452@@ -71,6 +72,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
8453 pud_set(pud, (unsigned long)pmd);
8454 }
8455
8456+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
8457+{
8458+ pud_populate(mm, pud, pmd);
8459+}
8460+
8461 #define pmd_populate(mm, pmd, pte_page) \
8462 pmd_populate_kernel(mm, pmd, page_address(pte_page))
8463 #define pmd_populate_kernel(mm, pmd, pte) pmd_set(pmd, (unsigned long)(pte))
8464@@ -173,6 +179,7 @@ extern void __tlb_remove_table(void *_table);
8465 #endif
8466
8467 #define pud_populate(mm, pud, pmd) pud_set(pud, (unsigned long)pmd)
8468+#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
8469
8470 static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,
8471 pte_t *pte)
8472diff --git a/arch/powerpc/include/asm/pgtable.h b/arch/powerpc/include/asm/pgtable.h
8473index 316f9a5..ba05c77 100644
8474--- a/arch/powerpc/include/asm/pgtable.h
8475+++ b/arch/powerpc/include/asm/pgtable.h
8476@@ -2,6 +2,7 @@
8477 #define _ASM_POWERPC_PGTABLE_H
8478 #ifdef __KERNEL__
8479
8480+#include <linux/const.h>
8481 #ifndef __ASSEMBLY__
8482 #include <linux/mmdebug.h>
8483 #include <linux/mmzone.h>
8484diff --git a/arch/powerpc/include/asm/pte-hash32.h b/arch/powerpc/include/asm/pte-hash32.h
8485index 4aad413..85d86bf 100644
8486--- a/arch/powerpc/include/asm/pte-hash32.h
8487+++ b/arch/powerpc/include/asm/pte-hash32.h
8488@@ -21,6 +21,7 @@
8489 #define _PAGE_FILE 0x004 /* when !present: nonlinear file mapping */
8490 #define _PAGE_USER 0x004 /* usermode access allowed */
8491 #define _PAGE_GUARDED 0x008 /* G: prohibit speculative access */
8492+#define _PAGE_EXEC _PAGE_GUARDED
8493 #define _PAGE_COHERENT 0x010 /* M: enforce memory coherence (SMP systems) */
8494 #define _PAGE_NO_CACHE 0x020 /* I: cache inhibit */
8495 #define _PAGE_WRITETHRU 0x040 /* W: cache write-through */
8496diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h
8497index c998279..d13a9f8 100644
8498--- a/arch/powerpc/include/asm/reg.h
8499+++ b/arch/powerpc/include/asm/reg.h
8500@@ -251,6 +251,7 @@
8501 #define SPRN_DBCR 0x136 /* e300 Data Breakpoint Control Reg */
8502 #define SPRN_DSISR 0x012 /* Data Storage Interrupt Status Register */
8503 #define DSISR_NOHPTE 0x40000000 /* no translation found */
8504+#define DSISR_GUARDED 0x10000000 /* fetch from guarded storage */
8505 #define DSISR_PROTFAULT 0x08000000 /* protection fault */
8506 #define DSISR_ISSTORE 0x02000000 /* access was a store */
8507 #define DSISR_DABRMATCH 0x00400000 /* hit data breakpoint */
8508diff --git a/arch/powerpc/include/asm/smp.h b/arch/powerpc/include/asm/smp.h
8509index 5a6614a..d89995d1 100644
8510--- a/arch/powerpc/include/asm/smp.h
8511+++ b/arch/powerpc/include/asm/smp.h
8512@@ -51,7 +51,7 @@ struct smp_ops_t {
8513 int (*cpu_disable)(void);
8514 void (*cpu_die)(unsigned int nr);
8515 int (*cpu_bootable)(unsigned int nr);
8516-};
8517+} __no_const;
8518
8519 extern void smp_send_debugger_break(void);
8520 extern void start_secondary_resume(void);
8521diff --git a/arch/powerpc/include/asm/spinlock.h b/arch/powerpc/include/asm/spinlock.h
8522index 4dbe072..b803275 100644
8523--- a/arch/powerpc/include/asm/spinlock.h
8524+++ b/arch/powerpc/include/asm/spinlock.h
8525@@ -204,13 +204,29 @@ static inline long __arch_read_trylock(arch_rwlock_t *rw)
8526 __asm__ __volatile__(
8527 "1: " PPC_LWARX(%0,0,%1,1) "\n"
8528 __DO_SIGN_EXTEND
8529-" addic. %0,%0,1\n\
8530- ble- 2f\n"
8531+
8532+#ifdef CONFIG_PAX_REFCOUNT
8533+" mcrxr cr0\n"
8534+" addico. %0,%0,1\n"
8535+" bf 4*cr0+so, 3f\n"
8536+"2:.long " "0x00c00b00""\n"
8537+#else
8538+" addic. %0,%0,1\n"
8539+#endif
8540+
8541+"3:\n"
8542+ "ble- 4f\n"
8543 PPC405_ERR77(0,%1)
8544 " stwcx. %0,0,%1\n\
8545 bne- 1b\n"
8546 PPC_ACQUIRE_BARRIER
8547-"2:" : "=&r" (tmp)
8548+"4:"
8549+
8550+#ifdef CONFIG_PAX_REFCOUNT
8551+ _ASM_EXTABLE(2b,4b)
8552+#endif
8553+
8554+ : "=&r" (tmp)
8555 : "r" (&rw->lock)
8556 : "cr0", "xer", "memory");
8557
8558@@ -286,11 +302,27 @@ static inline void arch_read_unlock(arch_rwlock_t *rw)
8559 __asm__ __volatile__(
8560 "# read_unlock\n\t"
8561 PPC_RELEASE_BARRIER
8562-"1: lwarx %0,0,%1\n\
8563- addic %0,%0,-1\n"
8564+"1: lwarx %0,0,%1\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 PPC405_ERR77(0,%1)
8577 " stwcx. %0,0,%1\n\
8578 bne- 1b"
8579+
8580+#ifdef CONFIG_PAX_REFCOUNT
8581+"\n4:\n"
8582+ _ASM_EXTABLE(2b, 4b)
8583+#endif
8584+
8585 : "=&r"(tmp)
8586 : "r"(&rw->lock)
8587 : "cr0", "xer", "memory");
8588diff --git a/arch/powerpc/include/asm/thread_info.h b/arch/powerpc/include/asm/thread_info.h
8589index b034ecd..af7e31f 100644
8590--- a/arch/powerpc/include/asm/thread_info.h
8591+++ b/arch/powerpc/include/asm/thread_info.h
8592@@ -107,6 +107,8 @@ static inline struct thread_info *current_thread_info(void)
8593 #if defined(CONFIG_PPC64)
8594 #define TIF_ELF2ABI 18 /* function descriptors must die! */
8595 #endif
8596+/* mask must be expressable within 16 bits to satisfy 'andi' instruction reqs */
8597+#define TIF_GRSEC_SETXID 6 /* update credentials on syscall entry/exit */
8598
8599 /* as above, but as bit values */
8600 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
8601@@ -125,9 +127,10 @@ static inline struct thread_info *current_thread_info(void)
8602 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
8603 #define _TIF_EMULATE_STACK_STORE (1<<TIF_EMULATE_STACK_STORE)
8604 #define _TIF_NOHZ (1<<TIF_NOHZ)
8605+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
8606 #define _TIF_SYSCALL_T_OR_A (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
8607 _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT | \
8608- _TIF_NOHZ)
8609+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
8610
8611 #define _TIF_USER_WORK_MASK (_TIF_SIGPENDING | _TIF_NEED_RESCHED | \
8612 _TIF_NOTIFY_RESUME | _TIF_UPROBE | \
8613diff --git a/arch/powerpc/include/asm/uaccess.h b/arch/powerpc/include/asm/uaccess.h
8614index 9485b43..3bd3c16 100644
8615--- a/arch/powerpc/include/asm/uaccess.h
8616+++ b/arch/powerpc/include/asm/uaccess.h
8617@@ -58,6 +58,7 @@
8618
8619 #endif
8620
8621+#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
8622 #define access_ok(type, addr, size) \
8623 (__chk_user_ptr(addr), \
8624 __access_ok((__force unsigned long)(addr), (size), get_fs()))
8625@@ -318,52 +319,6 @@ do { \
8626 extern unsigned long __copy_tofrom_user(void __user *to,
8627 const void __user *from, unsigned long size);
8628
8629-#ifndef __powerpc64__
8630-
8631-static inline unsigned long copy_from_user(void *to,
8632- const void __user *from, unsigned long n)
8633-{
8634- unsigned long over;
8635-
8636- if (access_ok(VERIFY_READ, from, n))
8637- return __copy_tofrom_user((__force void __user *)to, from, n);
8638- if ((unsigned long)from < TASK_SIZE) {
8639- over = (unsigned long)from + n - TASK_SIZE;
8640- return __copy_tofrom_user((__force void __user *)to, from,
8641- n - over) + over;
8642- }
8643- return n;
8644-}
8645-
8646-static inline unsigned long copy_to_user(void __user *to,
8647- const void *from, unsigned long n)
8648-{
8649- unsigned long over;
8650-
8651- if (access_ok(VERIFY_WRITE, to, n))
8652- return __copy_tofrom_user(to, (__force void __user *)from, n);
8653- if ((unsigned long)to < TASK_SIZE) {
8654- over = (unsigned long)to + n - TASK_SIZE;
8655- return __copy_tofrom_user(to, (__force void __user *)from,
8656- n - over) + over;
8657- }
8658- return n;
8659-}
8660-
8661-#else /* __powerpc64__ */
8662-
8663-#define __copy_in_user(to, from, size) \
8664- __copy_tofrom_user((to), (from), (size))
8665-
8666-extern unsigned long copy_from_user(void *to, const void __user *from,
8667- unsigned long n);
8668-extern unsigned long copy_to_user(void __user *to, const void *from,
8669- unsigned long n);
8670-extern unsigned long copy_in_user(void __user *to, const void __user *from,
8671- unsigned long n);
8672-
8673-#endif /* __powerpc64__ */
8674-
8675 static inline unsigned long __copy_from_user_inatomic(void *to,
8676 const void __user *from, unsigned long n)
8677 {
8678@@ -387,6 +342,10 @@ static inline unsigned long __copy_from_user_inatomic(void *to,
8679 if (ret == 0)
8680 return 0;
8681 }
8682+
8683+ if (!__builtin_constant_p(n))
8684+ check_object_size(to, n, false);
8685+
8686 return __copy_tofrom_user((__force void __user *)to, from, n);
8687 }
8688
8689@@ -413,6 +372,10 @@ static inline unsigned long __copy_to_user_inatomic(void __user *to,
8690 if (ret == 0)
8691 return 0;
8692 }
8693+
8694+ if (!__builtin_constant_p(n))
8695+ check_object_size(from, n, true);
8696+
8697 return __copy_tofrom_user(to, (__force const void __user *)from, n);
8698 }
8699
8700@@ -430,6 +393,92 @@ static inline unsigned long __copy_to_user(void __user *to,
8701 return __copy_to_user_inatomic(to, from, size);
8702 }
8703
8704+#ifndef __powerpc64__
8705+
8706+static inline unsigned long __must_check copy_from_user(void *to,
8707+ const void __user *from, unsigned long n)
8708+{
8709+ unsigned long over;
8710+
8711+ if ((long)n < 0)
8712+ return n;
8713+
8714+ if (access_ok(VERIFY_READ, from, n)) {
8715+ if (!__builtin_constant_p(n))
8716+ check_object_size(to, n, false);
8717+ return __copy_tofrom_user((__force void __user *)to, from, n);
8718+ }
8719+ if ((unsigned long)from < TASK_SIZE) {
8720+ over = (unsigned long)from + n - TASK_SIZE;
8721+ if (!__builtin_constant_p(n - over))
8722+ check_object_size(to, n - over, false);
8723+ return __copy_tofrom_user((__force void __user *)to, from,
8724+ n - over) + over;
8725+ }
8726+ return n;
8727+}
8728+
8729+static inline unsigned long __must_check copy_to_user(void __user *to,
8730+ const void *from, unsigned long n)
8731+{
8732+ unsigned long over;
8733+
8734+ if ((long)n < 0)
8735+ return n;
8736+
8737+ if (access_ok(VERIFY_WRITE, to, n)) {
8738+ if (!__builtin_constant_p(n))
8739+ check_object_size(from, n, true);
8740+ return __copy_tofrom_user(to, (__force void __user *)from, n);
8741+ }
8742+ if ((unsigned long)to < TASK_SIZE) {
8743+ over = (unsigned long)to + n - TASK_SIZE;
8744+ if (!__builtin_constant_p(n))
8745+ check_object_size(from, n - over, true);
8746+ return __copy_tofrom_user(to, (__force void __user *)from,
8747+ n - over) + over;
8748+ }
8749+ return n;
8750+}
8751+
8752+#else /* __powerpc64__ */
8753+
8754+#define __copy_in_user(to, from, size) \
8755+ __copy_tofrom_user((to), (from), (size))
8756+
8757+static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
8758+{
8759+ if ((long)n < 0 || n > INT_MAX)
8760+ return n;
8761+
8762+ if (!__builtin_constant_p(n))
8763+ check_object_size(to, n, false);
8764+
8765+ if (likely(access_ok(VERIFY_READ, from, n)))
8766+ n = __copy_from_user(to, from, n);
8767+ else
8768+ memset(to, 0, n);
8769+ return n;
8770+}
8771+
8772+static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
8773+{
8774+ if ((long)n < 0 || n > INT_MAX)
8775+ return n;
8776+
8777+ if (likely(access_ok(VERIFY_WRITE, to, n))) {
8778+ if (!__builtin_constant_p(n))
8779+ check_object_size(from, n, true);
8780+ n = __copy_to_user(to, from, n);
8781+ }
8782+ return n;
8783+}
8784+
8785+extern unsigned long copy_in_user(void __user *to, const void __user *from,
8786+ unsigned long n);
8787+
8788+#endif /* __powerpc64__ */
8789+
8790 extern unsigned long __clear_user(void __user *addr, unsigned long size);
8791
8792 static inline unsigned long clear_user(void __user *addr, unsigned long size)
8793diff --git a/arch/powerpc/kernel/Makefile b/arch/powerpc/kernel/Makefile
8794index 502cf69..822e63b 100644
8795--- a/arch/powerpc/kernel/Makefile
8796+++ b/arch/powerpc/kernel/Makefile
8797@@ -27,6 +27,8 @@ CFLAGS_REMOVE_ftrace.o = -pg -mno-sched-epilog
8798 CFLAGS_REMOVE_time.o = -pg -mno-sched-epilog
8799 endif
8800
8801+CFLAGS_REMOVE_prom_init.o += $(LATENT_ENTROPY_PLUGIN_CFLAGS)
8802+
8803 obj-y := cputable.o ptrace.o syscalls.o \
8804 irq.o align.o signal_32.o pmc.o vdso.o \
8805 process.o systbl.o idle.o \
8806diff --git a/arch/powerpc/kernel/exceptions-64e.S b/arch/powerpc/kernel/exceptions-64e.S
8807index 3e68d1c..72a5ee6 100644
8808--- a/arch/powerpc/kernel/exceptions-64e.S
8809+++ b/arch/powerpc/kernel/exceptions-64e.S
8810@@ -1010,6 +1010,7 @@ storage_fault_common:
8811 std r14,_DAR(r1)
8812 std r15,_DSISR(r1)
8813 addi r3,r1,STACK_FRAME_OVERHEAD
8814+ bl save_nvgprs
8815 mr r4,r14
8816 mr r5,r15
8817 ld r14,PACA_EXGEN+EX_R14(r13)
8818@@ -1018,8 +1019,7 @@ storage_fault_common:
8819 cmpdi r3,0
8820 bne- 1f
8821 b ret_from_except_lite
8822-1: bl save_nvgprs
8823- mr r5,r3
8824+1: mr r5,r3
8825 addi r3,r1,STACK_FRAME_OVERHEAD
8826 ld r4,_DAR(r1)
8827 bl bad_page_fault
8828diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
8829index 72e783e..fe058e2 100644
8830--- a/arch/powerpc/kernel/exceptions-64s.S
8831+++ b/arch/powerpc/kernel/exceptions-64s.S
8832@@ -1588,10 +1588,10 @@ handle_page_fault:
8833 11: ld r4,_DAR(r1)
8834 ld r5,_DSISR(r1)
8835 addi r3,r1,STACK_FRAME_OVERHEAD
8836+ bl save_nvgprs
8837 bl do_page_fault
8838 cmpdi r3,0
8839 beq+ 12f
8840- bl save_nvgprs
8841 mr r5,r3
8842 addi r3,r1,STACK_FRAME_OVERHEAD
8843 lwz r4,_DAR(r1)
8844diff --git a/arch/powerpc/kernel/irq.c b/arch/powerpc/kernel/irq.c
8845index c143835..5a9697f 100644
8846--- a/arch/powerpc/kernel/irq.c
8847+++ b/arch/powerpc/kernel/irq.c
8848@@ -461,6 +461,8 @@ void migrate_irqs(void)
8849 }
8850 #endif
8851
8852+extern void gr_handle_kernel_exploit(void);
8853+
8854 static inline void check_stack_overflow(void)
8855 {
8856 #ifdef CONFIG_DEBUG_STACKOVERFLOW
8857@@ -473,6 +475,7 @@ static inline void check_stack_overflow(void)
8858 pr_err("do_IRQ: stack overflow: %ld\n",
8859 sp - sizeof(struct thread_info));
8860 dump_stack();
8861+ gr_handle_kernel_exploit();
8862 }
8863 #endif
8864 }
8865diff --git a/arch/powerpc/kernel/module_32.c b/arch/powerpc/kernel/module_32.c
8866index c94d2e0..992a9ce 100644
8867--- a/arch/powerpc/kernel/module_32.c
8868+++ b/arch/powerpc/kernel/module_32.c
8869@@ -158,7 +158,7 @@ int module_frob_arch_sections(Elf32_Ehdr *hdr,
8870 me->arch.core_plt_section = i;
8871 }
8872 if (!me->arch.core_plt_section || !me->arch.init_plt_section) {
8873- pr_err("Module doesn't contain .plt or .init.plt sections.\n");
8874+ pr_err("Module $s doesn't contain .plt or .init.plt sections.\n", me->name);
8875 return -ENOEXEC;
8876 }
8877
8878@@ -188,11 +188,16 @@ static uint32_t do_plt_call(void *location,
8879
8880 pr_debug("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location);
8881 /* Init, or core PLT? */
8882- if (location >= mod->module_core
8883- && location < mod->module_core + mod->core_size)
8884+ if ((location >= mod->module_core_rx && location < mod->module_core_rx + mod->core_size_rx) ||
8885+ (location >= mod->module_core_rw && location < mod->module_core_rw + mod->core_size_rw))
8886 entry = (void *)sechdrs[mod->arch.core_plt_section].sh_addr;
8887- else
8888+ else if ((location >= mod->module_init_rx && location < mod->module_init_rx + mod->init_size_rx) ||
8889+ (location >= mod->module_init_rw && location < mod->module_init_rw + mod->init_size_rw))
8890 entry = (void *)sechdrs[mod->arch.init_plt_section].sh_addr;
8891+ else {
8892+ printk(KERN_ERR "%s: invalid R_PPC_REL24 entry found\n", mod->name);
8893+ return ~0UL;
8894+ }
8895
8896 /* Find this entry, or if that fails, the next avail. entry */
8897 while (entry->jump[0]) {
8898@@ -296,7 +301,7 @@ int apply_relocate_add(Elf32_Shdr *sechdrs,
8899 }
8900 #ifdef CONFIG_DYNAMIC_FTRACE
8901 module->arch.tramp =
8902- do_plt_call(module->module_core,
8903+ do_plt_call(module->module_core_rx,
8904 (unsigned long)ftrace_caller,
8905 sechdrs, module);
8906 #endif
8907diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
8908index 923cd2d..ae782a9 100644
8909--- a/arch/powerpc/kernel/process.c
8910+++ b/arch/powerpc/kernel/process.c
8911@@ -1040,8 +1040,8 @@ void show_regs(struct pt_regs * regs)
8912 * Lookup NIP late so we have the best change of getting the
8913 * above info out without failing
8914 */
8915- printk("NIP ["REG"] %pS\n", regs->nip, (void *)regs->nip);
8916- printk("LR ["REG"] %pS\n", regs->link, (void *)regs->link);
8917+ printk("NIP ["REG"] %pA\n", regs->nip, (void *)regs->nip);
8918+ printk("LR ["REG"] %pA\n", regs->link, (void *)regs->link);
8919 #endif
8920 show_stack(current, (unsigned long *) regs->gpr[1]);
8921 if (!user_mode(regs))
8922@@ -1560,10 +1560,10 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
8923 newsp = stack[0];
8924 ip = stack[STACK_FRAME_LR_SAVE];
8925 if (!firstframe || ip != lr) {
8926- printk("["REG"] ["REG"] %pS", sp, ip, (void *)ip);
8927+ printk("["REG"] ["REG"] %pA", sp, ip, (void *)ip);
8928 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
8929 if ((ip == rth || ip == mrth) && curr_frame >= 0) {
8930- printk(" (%pS)",
8931+ printk(" (%pA)",
8932 (void *)current->ret_stack[curr_frame].ret);
8933 curr_frame--;
8934 }
8935@@ -1583,7 +1583,7 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
8936 struct pt_regs *regs = (struct pt_regs *)
8937 (sp + STACK_FRAME_OVERHEAD);
8938 lr = regs->link;
8939- printk("--- interrupt: %lx at %pS\n LR = %pS\n",
8940+ printk("--- interrupt: %lx at %pA\n LR = %pA\n",
8941 regs->trap, (void *)regs->nip, (void *)lr);
8942 firstframe = 1;
8943 }
8944@@ -1619,58 +1619,3 @@ void notrace __ppc64_runlatch_off(void)
8945 mtspr(SPRN_CTRLT, ctrl);
8946 }
8947 #endif /* CONFIG_PPC64 */
8948-
8949-unsigned long arch_align_stack(unsigned long sp)
8950-{
8951- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
8952- sp -= get_random_int() & ~PAGE_MASK;
8953- return sp & ~0xf;
8954-}
8955-
8956-static inline unsigned long brk_rnd(void)
8957-{
8958- unsigned long rnd = 0;
8959-
8960- /* 8MB for 32bit, 1GB for 64bit */
8961- if (is_32bit_task())
8962- rnd = (long)(get_random_int() % (1<<(23-PAGE_SHIFT)));
8963- else
8964- rnd = (long)(get_random_int() % (1<<(30-PAGE_SHIFT)));
8965-
8966- return rnd << PAGE_SHIFT;
8967-}
8968-
8969-unsigned long arch_randomize_brk(struct mm_struct *mm)
8970-{
8971- unsigned long base = mm->brk;
8972- unsigned long ret;
8973-
8974-#ifdef CONFIG_PPC_STD_MMU_64
8975- /*
8976- * If we are using 1TB segments and we are allowed to randomise
8977- * the heap, we can put it above 1TB so it is backed by a 1TB
8978- * segment. Otherwise the heap will be in the bottom 1TB
8979- * which always uses 256MB segments and this may result in a
8980- * performance penalty.
8981- */
8982- if (!is_32bit_task() && (mmu_highuser_ssize == MMU_SEGSIZE_1T))
8983- base = max_t(unsigned long, mm->brk, 1UL << SID_SHIFT_1T);
8984-#endif
8985-
8986- ret = PAGE_ALIGN(base + brk_rnd());
8987-
8988- if (ret < mm->brk)
8989- return mm->brk;
8990-
8991- return ret;
8992-}
8993-
8994-unsigned long randomize_et_dyn(unsigned long base)
8995-{
8996- unsigned long ret = PAGE_ALIGN(base + brk_rnd());
8997-
8998- if (ret < base)
8999- return base;
9000-
9001- return ret;
9002-}
9003diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c
9004index f21897b..28c0428 100644
9005--- a/arch/powerpc/kernel/ptrace.c
9006+++ b/arch/powerpc/kernel/ptrace.c
9007@@ -1762,6 +1762,10 @@ long arch_ptrace(struct task_struct *child, long request,
9008 return ret;
9009 }
9010
9011+#ifdef CONFIG_GRKERNSEC_SETXID
9012+extern void gr_delayed_cred_worker(void);
9013+#endif
9014+
9015 /*
9016 * We must return the syscall number to actually look up in the table.
9017 * This can be -1L to skip running any syscall at all.
9018@@ -1774,6 +1778,11 @@ long do_syscall_trace_enter(struct pt_regs *regs)
9019
9020 secure_computing_strict(regs->gpr[0]);
9021
9022+#ifdef CONFIG_GRKERNSEC_SETXID
9023+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
9024+ gr_delayed_cred_worker();
9025+#endif
9026+
9027 if (test_thread_flag(TIF_SYSCALL_TRACE) &&
9028 tracehook_report_syscall_entry(regs))
9029 /*
9030@@ -1805,6 +1814,11 @@ void do_syscall_trace_leave(struct pt_regs *regs)
9031 {
9032 int step;
9033
9034+#ifdef CONFIG_GRKERNSEC_SETXID
9035+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
9036+ gr_delayed_cred_worker();
9037+#endif
9038+
9039 audit_syscall_exit(regs);
9040
9041 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
9042diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c
9043index b171001..4ac7ac5 100644
9044--- a/arch/powerpc/kernel/signal_32.c
9045+++ b/arch/powerpc/kernel/signal_32.c
9046@@ -1011,7 +1011,7 @@ int handle_rt_signal32(struct ksignal *ksig, sigset_t *oldset,
9047 /* Save user registers on the stack */
9048 frame = &rt_sf->uc.uc_mcontext;
9049 addr = frame;
9050- if (vdso32_rt_sigtramp && current->mm->context.vdso_base) {
9051+ if (vdso32_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
9052 sigret = 0;
9053 tramp = current->mm->context.vdso_base + vdso32_rt_sigtramp;
9054 } else {
9055diff --git a/arch/powerpc/kernel/signal_64.c b/arch/powerpc/kernel/signal_64.c
9056index 2cb0c94..c0c0bc9 100644
9057--- a/arch/powerpc/kernel/signal_64.c
9058+++ b/arch/powerpc/kernel/signal_64.c
9059@@ -754,7 +754,7 @@ int handle_rt_signal64(struct ksignal *ksig, sigset_t *set, struct pt_regs *regs
9060 current->thread.fp_state.fpscr = 0;
9061
9062 /* Set up to return from userspace. */
9063- if (vdso64_rt_sigtramp && current->mm->context.vdso_base) {
9064+ if (vdso64_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
9065 regs->link = current->mm->context.vdso_base + vdso64_rt_sigtramp;
9066 } else {
9067 err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]);
9068diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
9069index 0dc43f9..a885d33 100644
9070--- a/arch/powerpc/kernel/traps.c
9071+++ b/arch/powerpc/kernel/traps.c
9072@@ -36,6 +36,7 @@
9073 #include <linux/debugfs.h>
9074 #include <linux/ratelimit.h>
9075 #include <linux/context_tracking.h>
9076+#include <linux/uaccess.h>
9077
9078 #include <asm/emulated_ops.h>
9079 #include <asm/pgtable.h>
9080@@ -142,6 +143,8 @@ static unsigned __kprobes long oops_begin(struct pt_regs *regs)
9081 return flags;
9082 }
9083
9084+extern void gr_handle_kernel_exploit(void);
9085+
9086 static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
9087 int signr)
9088 {
9089@@ -191,6 +194,9 @@ static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
9090 panic("Fatal exception in interrupt");
9091 if (panic_on_oops)
9092 panic("Fatal exception");
9093+
9094+ gr_handle_kernel_exploit();
9095+
9096 do_exit(signr);
9097 }
9098
9099@@ -1137,6 +1143,26 @@ void __kprobes program_check_exception(struct pt_regs *regs)
9100 enum ctx_state prev_state = exception_enter();
9101 unsigned int reason = get_reason(regs);
9102
9103+#ifdef CONFIG_PAX_REFCOUNT
9104+ unsigned int bkpt;
9105+ const struct exception_table_entry *entry;
9106+
9107+ if (reason & REASON_ILLEGAL) {
9108+ /* Check if PaX bad instruction */
9109+ if (!probe_kernel_address(regs->nip, bkpt) && bkpt == 0xc00b00) {
9110+ current->thread.trap_nr = 0;
9111+ pax_report_refcount_overflow(regs);
9112+ /* fixup_exception() for PowerPC does not exist, simulate its job */
9113+ if ((entry = search_exception_tables(regs->nip)) != NULL) {
9114+ regs->nip = entry->fixup;
9115+ return;
9116+ }
9117+ /* fixup_exception() could not handle */
9118+ goto bail;
9119+ }
9120+ }
9121+#endif
9122+
9123 /* We can now get here via a FP Unavailable exception if the core
9124 * has no FPU, in that case the reason flags will be 0 */
9125
9126diff --git a/arch/powerpc/kernel/vdso.c b/arch/powerpc/kernel/vdso.c
9127index f174351..5722009 100644
9128--- a/arch/powerpc/kernel/vdso.c
9129+++ b/arch/powerpc/kernel/vdso.c
9130@@ -35,6 +35,7 @@
9131 #include <asm/vdso.h>
9132 #include <asm/vdso_datapage.h>
9133 #include <asm/setup.h>
9134+#include <asm/mman.h>
9135
9136 #undef DEBUG
9137
9138@@ -221,7 +222,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
9139 vdso_base = VDSO32_MBASE;
9140 #endif
9141
9142- current->mm->context.vdso_base = 0;
9143+ current->mm->context.vdso_base = ~0UL;
9144
9145 /* vDSO has a problem and was disabled, just don't "enable" it for the
9146 * process
9147@@ -241,7 +242,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
9148 vdso_base = get_unmapped_area(NULL, vdso_base,
9149 (vdso_pages << PAGE_SHIFT) +
9150 ((VDSO_ALIGNMENT - 1) & PAGE_MASK),
9151- 0, 0);
9152+ 0, MAP_PRIVATE | MAP_EXECUTABLE);
9153 if (IS_ERR_VALUE(vdso_base)) {
9154 rc = vdso_base;
9155 goto fail_mmapsem;
9156diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c
9157index c1f8f53..71a3b96 100644
9158--- a/arch/powerpc/kvm/powerpc.c
9159+++ b/arch/powerpc/kvm/powerpc.c
9160@@ -1409,7 +1409,7 @@ void kvmppc_init_lpid(unsigned long nr_lpids_param)
9161 }
9162 EXPORT_SYMBOL_GPL(kvmppc_init_lpid);
9163
9164-int kvm_arch_init(void *opaque)
9165+int kvm_arch_init(const void *opaque)
9166 {
9167 return 0;
9168 }
9169diff --git a/arch/powerpc/lib/usercopy_64.c b/arch/powerpc/lib/usercopy_64.c
9170index 5eea6f3..5d10396 100644
9171--- a/arch/powerpc/lib/usercopy_64.c
9172+++ b/arch/powerpc/lib/usercopy_64.c
9173@@ -9,22 +9,6 @@
9174 #include <linux/module.h>
9175 #include <asm/uaccess.h>
9176
9177-unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
9178-{
9179- if (likely(access_ok(VERIFY_READ, from, n)))
9180- n = __copy_from_user(to, from, n);
9181- else
9182- memset(to, 0, n);
9183- return n;
9184-}
9185-
9186-unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
9187-{
9188- if (likely(access_ok(VERIFY_WRITE, to, n)))
9189- n = __copy_to_user(to, from, n);
9190- return n;
9191-}
9192-
9193 unsigned long copy_in_user(void __user *to, const void __user *from,
9194 unsigned long n)
9195 {
9196@@ -35,7 +19,5 @@ unsigned long copy_in_user(void __user *to, const void __user *from,
9197 return n;
9198 }
9199
9200-EXPORT_SYMBOL(copy_from_user);
9201-EXPORT_SYMBOL(copy_to_user);
9202 EXPORT_SYMBOL(copy_in_user);
9203
9204diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
9205index 08d659a..ab329f4 100644
9206--- a/arch/powerpc/mm/fault.c
9207+++ b/arch/powerpc/mm/fault.c
9208@@ -33,6 +33,10 @@
9209 #include <linux/ratelimit.h>
9210 #include <linux/context_tracking.h>
9211 #include <linux/hugetlb.h>
9212+#include <linux/slab.h>
9213+#include <linux/pagemap.h>
9214+#include <linux/compiler.h>
9215+#include <linux/unistd.h>
9216
9217 #include <asm/firmware.h>
9218 #include <asm/page.h>
9219@@ -69,6 +73,33 @@ static inline int notify_page_fault(struct pt_regs *regs)
9220 }
9221 #endif
9222
9223+#ifdef CONFIG_PAX_PAGEEXEC
9224+/*
9225+ * PaX: decide what to do with offenders (regs->nip = fault address)
9226+ *
9227+ * returns 1 when task should be killed
9228+ */
9229+static int pax_handle_fetch_fault(struct pt_regs *regs)
9230+{
9231+ return 1;
9232+}
9233+
9234+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
9235+{
9236+ unsigned long i;
9237+
9238+ printk(KERN_ERR "PAX: bytes at PC: ");
9239+ for (i = 0; i < 5; i++) {
9240+ unsigned int c;
9241+ if (get_user(c, (unsigned int __user *)pc+i))
9242+ printk(KERN_CONT "???????? ");
9243+ else
9244+ printk(KERN_CONT "%08x ", c);
9245+ }
9246+ printk("\n");
9247+}
9248+#endif
9249+
9250 /*
9251 * Check whether the instruction at regs->nip is a store using
9252 * an update addressing form which will update r1.
9253@@ -228,7 +259,7 @@ int __kprobes do_page_fault(struct pt_regs *regs, unsigned long address,
9254 * indicate errors in DSISR but can validly be set in SRR1.
9255 */
9256 if (trap == 0x400)
9257- error_code &= 0x48200000;
9258+ error_code &= 0x58200000;
9259 else
9260 is_write = error_code & DSISR_ISSTORE;
9261 #else
9262@@ -390,7 +421,7 @@ good_area:
9263 * "undefined". Of those that can be set, this is the only
9264 * one which seems bad.
9265 */
9266- if (error_code & 0x10000000)
9267+ if (error_code & DSISR_GUARDED)
9268 /* Guarded storage error. */
9269 goto bad_area;
9270 #endif /* CONFIG_8xx */
9271@@ -405,7 +436,7 @@ good_area:
9272 * processors use the same I/D cache coherency mechanism
9273 * as embedded.
9274 */
9275- if (error_code & DSISR_PROTFAULT)
9276+ if (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))
9277 goto bad_area;
9278 #endif /* CONFIG_PPC_STD_MMU */
9279
9280@@ -495,6 +526,23 @@ bad_area:
9281 bad_area_nosemaphore:
9282 /* User mode accesses cause a SIGSEGV */
9283 if (user_mode(regs)) {
9284+
9285+#ifdef CONFIG_PAX_PAGEEXEC
9286+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
9287+#ifdef CONFIG_PPC_STD_MMU
9288+ if (is_exec && (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))) {
9289+#else
9290+ if (is_exec && regs->nip == address) {
9291+#endif
9292+ switch (pax_handle_fetch_fault(regs)) {
9293+ }
9294+
9295+ pax_report_fault(regs, (void *)regs->nip, (void *)regs->gpr[PT_R1]);
9296+ do_group_exit(SIGKILL);
9297+ }
9298+ }
9299+#endif
9300+
9301 _exception(SIGSEGV, regs, code, address);
9302 goto bail;
9303 }
9304diff --git a/arch/powerpc/mm/mmap.c b/arch/powerpc/mm/mmap.c
9305index cb8bdbe..cde4bc7 100644
9306--- a/arch/powerpc/mm/mmap.c
9307+++ b/arch/powerpc/mm/mmap.c
9308@@ -53,10 +53,14 @@ static inline int mmap_is_legacy(void)
9309 return sysctl_legacy_va_layout;
9310 }
9311
9312-static unsigned long mmap_rnd(void)
9313+static unsigned long mmap_rnd(struct mm_struct *mm)
9314 {
9315 unsigned long rnd = 0;
9316
9317+#ifdef CONFIG_PAX_RANDMMAP
9318+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9319+#endif
9320+
9321 if (current->flags & PF_RANDOMIZE) {
9322 /* 8MB for 32bit, 1GB for 64bit */
9323 if (is_32bit_task())
9324@@ -67,7 +71,7 @@ static unsigned long mmap_rnd(void)
9325 return rnd << PAGE_SHIFT;
9326 }
9327
9328-static inline unsigned long mmap_base(void)
9329+static inline unsigned long mmap_base(struct mm_struct *mm)
9330 {
9331 unsigned long gap = rlimit(RLIMIT_STACK);
9332
9333@@ -76,7 +80,7 @@ static inline unsigned long mmap_base(void)
9334 else if (gap > MAX_GAP)
9335 gap = MAX_GAP;
9336
9337- return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
9338+ return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd(mm));
9339 }
9340
9341 /*
9342@@ -91,9 +95,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
9343 */
9344 if (mmap_is_legacy()) {
9345 mm->mmap_base = TASK_UNMAPPED_BASE;
9346+
9347+#ifdef CONFIG_PAX_RANDMMAP
9348+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9349+ mm->mmap_base += mm->delta_mmap;
9350+#endif
9351+
9352 mm->get_unmapped_area = arch_get_unmapped_area;
9353 } else {
9354- mm->mmap_base = mmap_base();
9355+ mm->mmap_base = mmap_base(mm);
9356+
9357+#ifdef CONFIG_PAX_RANDMMAP
9358+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9359+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
9360+#endif
9361+
9362 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
9363 }
9364 }
9365diff --git a/arch/powerpc/mm/slice.c b/arch/powerpc/mm/slice.c
9366index ded0ea1..f213a9b 100644
9367--- a/arch/powerpc/mm/slice.c
9368+++ b/arch/powerpc/mm/slice.c
9369@@ -105,7 +105,7 @@ static int slice_area_is_free(struct mm_struct *mm, unsigned long addr,
9370 if ((mm->task_size - len) < addr)
9371 return 0;
9372 vma = find_vma(mm, addr);
9373- return (!vma || (addr + len) <= vma->vm_start);
9374+ return check_heap_stack_gap(vma, addr, len, 0);
9375 }
9376
9377 static int slice_low_has_vma(struct mm_struct *mm, unsigned long slice)
9378@@ -277,6 +277,12 @@ static unsigned long slice_find_area_bottomup(struct mm_struct *mm,
9379 info.align_offset = 0;
9380
9381 addr = TASK_UNMAPPED_BASE;
9382+
9383+#ifdef CONFIG_PAX_RANDMMAP
9384+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9385+ addr += mm->delta_mmap;
9386+#endif
9387+
9388 while (addr < TASK_SIZE) {
9389 info.low_limit = addr;
9390 if (!slice_scan_available(addr, available, 1, &addr))
9391@@ -410,6 +416,11 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len,
9392 if (fixed && addr > (mm->task_size - len))
9393 return -ENOMEM;
9394
9395+#ifdef CONFIG_PAX_RANDMMAP
9396+ if (!fixed && (mm->pax_flags & MF_PAX_RANDMMAP))
9397+ addr = 0;
9398+#endif
9399+
9400 /* If hint, make sure it matches our alignment restrictions */
9401 if (!fixed && addr) {
9402 addr = _ALIGN_UP(addr, 1ul << pshift);
9403diff --git a/arch/powerpc/platforms/cell/celleb_scc_pciex.c b/arch/powerpc/platforms/cell/celleb_scc_pciex.c
9404index 4278acf..67fd0e6 100644
9405--- a/arch/powerpc/platforms/cell/celleb_scc_pciex.c
9406+++ b/arch/powerpc/platforms/cell/celleb_scc_pciex.c
9407@@ -400,8 +400,8 @@ static int scc_pciex_write_config(struct pci_bus *bus, unsigned int devfn,
9408 }
9409
9410 static struct pci_ops scc_pciex_pci_ops = {
9411- scc_pciex_read_config,
9412- scc_pciex_write_config,
9413+ .read = scc_pciex_read_config,
9414+ .write = scc_pciex_write_config,
9415 };
9416
9417 static void pciex_clear_intr_all(unsigned int __iomem *base)
9418diff --git a/arch/powerpc/platforms/cell/spufs/file.c b/arch/powerpc/platforms/cell/spufs/file.c
9419index d966bbe..372124a 100644
9420--- a/arch/powerpc/platforms/cell/spufs/file.c
9421+++ b/arch/powerpc/platforms/cell/spufs/file.c
9422@@ -280,9 +280,9 @@ spufs_mem_mmap_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
9423 return VM_FAULT_NOPAGE;
9424 }
9425
9426-static int spufs_mem_mmap_access(struct vm_area_struct *vma,
9427+static ssize_t spufs_mem_mmap_access(struct vm_area_struct *vma,
9428 unsigned long address,
9429- void *buf, int len, int write)
9430+ void *buf, size_t len, int write)
9431 {
9432 struct spu_context *ctx = vma->vm_file->private_data;
9433 unsigned long offset = address - vma->vm_start;
9434diff --git a/arch/s390/include/asm/atomic.h b/arch/s390/include/asm/atomic.h
9435index fa934fe..c296056 100644
9436--- a/arch/s390/include/asm/atomic.h
9437+++ b/arch/s390/include/asm/atomic.h
9438@@ -412,4 +412,14 @@ static inline long long atomic64_dec_if_positive(atomic64_t *v)
9439 #define atomic64_dec_and_test(_v) (atomic64_sub_return(1, _v) == 0)
9440 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
9441
9442+#define atomic64_read_unchecked(v) atomic64_read(v)
9443+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
9444+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
9445+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
9446+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
9447+#define atomic64_inc_unchecked(v) atomic64_inc(v)
9448+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
9449+#define atomic64_dec_unchecked(v) atomic64_dec(v)
9450+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
9451+
9452 #endif /* __ARCH_S390_ATOMIC__ */
9453diff --git a/arch/s390/include/asm/barrier.h b/arch/s390/include/asm/barrier.h
9454index b5dce65..8aca09a 100644
9455--- a/arch/s390/include/asm/barrier.h
9456+++ b/arch/s390/include/asm/barrier.h
9457@@ -39,7 +39,7 @@
9458 do { \
9459 compiletime_assert_atomic_type(*p); \
9460 barrier(); \
9461- ACCESS_ONCE(*p) = (v); \
9462+ ACCESS_ONCE_RW(*p) = (v); \
9463 } while (0)
9464
9465 #define smp_load_acquire(p) \
9466diff --git a/arch/s390/include/asm/cache.h b/arch/s390/include/asm/cache.h
9467index 4d7ccac..d03d0ad 100644
9468--- a/arch/s390/include/asm/cache.h
9469+++ b/arch/s390/include/asm/cache.h
9470@@ -9,8 +9,10 @@
9471 #ifndef __ARCH_S390_CACHE_H
9472 #define __ARCH_S390_CACHE_H
9473
9474-#define L1_CACHE_BYTES 256
9475+#include <linux/const.h>
9476+
9477 #define L1_CACHE_SHIFT 8
9478+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9479 #define NET_SKB_PAD 32
9480
9481 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
9482diff --git a/arch/s390/include/asm/elf.h b/arch/s390/include/asm/elf.h
9483index f6e43d3..5f57681 100644
9484--- a/arch/s390/include/asm/elf.h
9485+++ b/arch/s390/include/asm/elf.h
9486@@ -163,8 +163,14 @@ extern unsigned int vdso_enabled;
9487 the loader. We need to make sure that it is out of the way of the program
9488 that it will "exec", and that there is sufficient room for the brk. */
9489
9490-extern unsigned long randomize_et_dyn(unsigned long base);
9491-#define ELF_ET_DYN_BASE (randomize_et_dyn(STACK_TOP / 3 * 2))
9492+#define ELF_ET_DYN_BASE (STACK_TOP / 3 * 2)
9493+
9494+#ifdef CONFIG_PAX_ASLR
9495+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_31BIT) ? 0x10000UL : 0x80000000UL)
9496+
9497+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
9498+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
9499+#endif
9500
9501 /* This yields a mask that user programs can use to figure out what
9502 instruction set this CPU supports. */
9503@@ -223,9 +229,6 @@ struct linux_binprm;
9504 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
9505 int arch_setup_additional_pages(struct linux_binprm *, int);
9506
9507-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
9508-#define arch_randomize_brk arch_randomize_brk
9509-
9510 void *fill_cpu_elf_notes(void *ptr, struct save_area *sa, __vector128 *vxrs);
9511
9512 #endif
9513diff --git a/arch/s390/include/asm/exec.h b/arch/s390/include/asm/exec.h
9514index c4a93d6..4d2a9b4 100644
9515--- a/arch/s390/include/asm/exec.h
9516+++ b/arch/s390/include/asm/exec.h
9517@@ -7,6 +7,6 @@
9518 #ifndef __ASM_EXEC_H
9519 #define __ASM_EXEC_H
9520
9521-extern unsigned long arch_align_stack(unsigned long sp);
9522+#define arch_align_stack(x) ((x) & ~0xfUL)
9523
9524 #endif /* __ASM_EXEC_H */
9525diff --git a/arch/s390/include/asm/uaccess.h b/arch/s390/include/asm/uaccess.h
9526index cd4c68e..6764641 100644
9527--- a/arch/s390/include/asm/uaccess.h
9528+++ b/arch/s390/include/asm/uaccess.h
9529@@ -59,6 +59,7 @@ static inline int __range_ok(unsigned long addr, unsigned long size)
9530 __range_ok((unsigned long)(addr), (size)); \
9531 })
9532
9533+#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
9534 #define access_ok(type, addr, size) __access_ok(addr, size)
9535
9536 /*
9537@@ -275,6 +276,10 @@ static inline unsigned long __must_check
9538 copy_to_user(void __user *to, const void *from, unsigned long n)
9539 {
9540 might_fault();
9541+
9542+ if ((long)n < 0)
9543+ return n;
9544+
9545 return __copy_to_user(to, from, n);
9546 }
9547
9548@@ -303,10 +308,14 @@ __compiletime_warning("copy_from_user() buffer size is not provably correct")
9549 static inline unsigned long __must_check
9550 copy_from_user(void *to, const void __user *from, unsigned long n)
9551 {
9552- unsigned int sz = __compiletime_object_size(to);
9553+ size_t sz = __compiletime_object_size(to);
9554
9555 might_fault();
9556- if (unlikely(sz != -1 && sz < n)) {
9557+
9558+ if ((long)n < 0)
9559+ return n;
9560+
9561+ if (unlikely(sz != (size_t)-1 && sz < n)) {
9562 copy_from_user_overflow();
9563 return n;
9564 }
9565diff --git a/arch/s390/kernel/module.c b/arch/s390/kernel/module.c
9566index b89b591..fd9609d 100644
9567--- a/arch/s390/kernel/module.c
9568+++ b/arch/s390/kernel/module.c
9569@@ -169,11 +169,11 @@ int module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
9570
9571 /* Increase core size by size of got & plt and set start
9572 offsets for got and plt. */
9573- me->core_size = ALIGN(me->core_size, 4);
9574- me->arch.got_offset = me->core_size;
9575- me->core_size += me->arch.got_size;
9576- me->arch.plt_offset = me->core_size;
9577- me->core_size += me->arch.plt_size;
9578+ me->core_size_rw = ALIGN(me->core_size_rw, 4);
9579+ me->arch.got_offset = me->core_size_rw;
9580+ me->core_size_rw += me->arch.got_size;
9581+ me->arch.plt_offset = me->core_size_rx;
9582+ me->core_size_rx += me->arch.plt_size;
9583 return 0;
9584 }
9585
9586@@ -289,7 +289,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9587 if (info->got_initialized == 0) {
9588 Elf_Addr *gotent;
9589
9590- gotent = me->module_core + me->arch.got_offset +
9591+ gotent = me->module_core_rw + me->arch.got_offset +
9592 info->got_offset;
9593 *gotent = val;
9594 info->got_initialized = 1;
9595@@ -312,7 +312,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9596 rc = apply_rela_bits(loc, val, 0, 64, 0);
9597 else if (r_type == R_390_GOTENT ||
9598 r_type == R_390_GOTPLTENT) {
9599- val += (Elf_Addr) me->module_core - loc;
9600+ val += (Elf_Addr) me->module_core_rw - loc;
9601 rc = apply_rela_bits(loc, val, 1, 32, 1);
9602 }
9603 break;
9604@@ -325,7 +325,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9605 case R_390_PLTOFF64: /* 16 bit offset from GOT to PLT. */
9606 if (info->plt_initialized == 0) {
9607 unsigned int *ip;
9608- ip = me->module_core + me->arch.plt_offset +
9609+ ip = me->module_core_rx + me->arch.plt_offset +
9610 info->plt_offset;
9611 #ifndef CONFIG_64BIT
9612 ip[0] = 0x0d105810; /* basr 1,0; l 1,6(1); br 1 */
9613@@ -350,7 +350,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9614 val - loc + 0xffffUL < 0x1ffffeUL) ||
9615 (r_type == R_390_PLT32DBL &&
9616 val - loc + 0xffffffffULL < 0x1fffffffeULL)))
9617- val = (Elf_Addr) me->module_core +
9618+ val = (Elf_Addr) me->module_core_rx +
9619 me->arch.plt_offset +
9620 info->plt_offset;
9621 val += rela->r_addend - loc;
9622@@ -372,7 +372,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9623 case R_390_GOTOFF32: /* 32 bit offset to GOT. */
9624 case R_390_GOTOFF64: /* 64 bit offset to GOT. */
9625 val = val + rela->r_addend -
9626- ((Elf_Addr) me->module_core + me->arch.got_offset);
9627+ ((Elf_Addr) me->module_core_rw + me->arch.got_offset);
9628 if (r_type == R_390_GOTOFF16)
9629 rc = apply_rela_bits(loc, val, 0, 16, 0);
9630 else if (r_type == R_390_GOTOFF32)
9631@@ -382,7 +382,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9632 break;
9633 case R_390_GOTPC: /* 32 bit PC relative offset to GOT. */
9634 case R_390_GOTPCDBL: /* 32 bit PC rel. off. to GOT shifted by 1. */
9635- val = (Elf_Addr) me->module_core + me->arch.got_offset +
9636+ val = (Elf_Addr) me->module_core_rw + me->arch.got_offset +
9637 rela->r_addend - loc;
9638 if (r_type == R_390_GOTPC)
9639 rc = apply_rela_bits(loc, val, 1, 32, 0);
9640diff --git a/arch/s390/kernel/process.c b/arch/s390/kernel/process.c
9641index ed84cc2..c05a9d2 100644
9642--- a/arch/s390/kernel/process.c
9643+++ b/arch/s390/kernel/process.c
9644@@ -218,37 +218,3 @@ unsigned long get_wchan(struct task_struct *p)
9645 }
9646 return 0;
9647 }
9648-
9649-unsigned long arch_align_stack(unsigned long sp)
9650-{
9651- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
9652- sp -= get_random_int() & ~PAGE_MASK;
9653- return sp & ~0xf;
9654-}
9655-
9656-static inline unsigned long brk_rnd(void)
9657-{
9658- /* 8MB for 32bit, 1GB for 64bit */
9659- if (is_32bit_task())
9660- return (get_random_int() & 0x7ffUL) << PAGE_SHIFT;
9661- else
9662- return (get_random_int() & 0x3ffffUL) << PAGE_SHIFT;
9663-}
9664-
9665-unsigned long arch_randomize_brk(struct mm_struct *mm)
9666-{
9667- unsigned long ret;
9668-
9669- ret = PAGE_ALIGN(mm->brk + brk_rnd());
9670- return (ret > mm->brk) ? ret : mm->brk;
9671-}
9672-
9673-unsigned long randomize_et_dyn(unsigned long base)
9674-{
9675- unsigned long ret;
9676-
9677- if (!(current->flags & PF_RANDOMIZE))
9678- return base;
9679- ret = PAGE_ALIGN(base + brk_rnd());
9680- return (ret > base) ? ret : base;
9681-}
9682diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c
9683index 9b436c2..54fbf0a 100644
9684--- a/arch/s390/mm/mmap.c
9685+++ b/arch/s390/mm/mmap.c
9686@@ -95,9 +95,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
9687 */
9688 if (mmap_is_legacy()) {
9689 mm->mmap_base = mmap_base_legacy();
9690+
9691+#ifdef CONFIG_PAX_RANDMMAP
9692+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9693+ mm->mmap_base += mm->delta_mmap;
9694+#endif
9695+
9696 mm->get_unmapped_area = arch_get_unmapped_area;
9697 } else {
9698 mm->mmap_base = mmap_base();
9699+
9700+#ifdef CONFIG_PAX_RANDMMAP
9701+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9702+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
9703+#endif
9704+
9705 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
9706 }
9707 }
9708@@ -170,9 +182,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
9709 */
9710 if (mmap_is_legacy()) {
9711 mm->mmap_base = mmap_base_legacy();
9712+
9713+#ifdef CONFIG_PAX_RANDMMAP
9714+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9715+ mm->mmap_base += mm->delta_mmap;
9716+#endif
9717+
9718 mm->get_unmapped_area = s390_get_unmapped_area;
9719 } else {
9720 mm->mmap_base = mmap_base();
9721+
9722+#ifdef CONFIG_PAX_RANDMMAP
9723+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9724+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
9725+#endif
9726+
9727 mm->get_unmapped_area = s390_get_unmapped_area_topdown;
9728 }
9729 }
9730diff --git a/arch/score/include/asm/cache.h b/arch/score/include/asm/cache.h
9731index ae3d59f..f65f075 100644
9732--- a/arch/score/include/asm/cache.h
9733+++ b/arch/score/include/asm/cache.h
9734@@ -1,7 +1,9 @@
9735 #ifndef _ASM_SCORE_CACHE_H
9736 #define _ASM_SCORE_CACHE_H
9737
9738+#include <linux/const.h>
9739+
9740 #define L1_CACHE_SHIFT 4
9741-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
9742+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9743
9744 #endif /* _ASM_SCORE_CACHE_H */
9745diff --git a/arch/score/include/asm/exec.h b/arch/score/include/asm/exec.h
9746index f9f3cd5..58ff438 100644
9747--- a/arch/score/include/asm/exec.h
9748+++ b/arch/score/include/asm/exec.h
9749@@ -1,6 +1,6 @@
9750 #ifndef _ASM_SCORE_EXEC_H
9751 #define _ASM_SCORE_EXEC_H
9752
9753-extern unsigned long arch_align_stack(unsigned long sp);
9754+#define arch_align_stack(x) (x)
9755
9756 #endif /* _ASM_SCORE_EXEC_H */
9757diff --git a/arch/score/kernel/process.c b/arch/score/kernel/process.c
9758index a1519ad3..e8ac1ff 100644
9759--- a/arch/score/kernel/process.c
9760+++ b/arch/score/kernel/process.c
9761@@ -116,8 +116,3 @@ unsigned long get_wchan(struct task_struct *task)
9762
9763 return task_pt_regs(task)->cp0_epc;
9764 }
9765-
9766-unsigned long arch_align_stack(unsigned long sp)
9767-{
9768- return sp;
9769-}
9770diff --git a/arch/sh/include/asm/cache.h b/arch/sh/include/asm/cache.h
9771index ef9e555..331bd29 100644
9772--- a/arch/sh/include/asm/cache.h
9773+++ b/arch/sh/include/asm/cache.h
9774@@ -9,10 +9,11 @@
9775 #define __ASM_SH_CACHE_H
9776 #ifdef __KERNEL__
9777
9778+#include <linux/const.h>
9779 #include <linux/init.h>
9780 #include <cpu/cache.h>
9781
9782-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
9783+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9784
9785 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
9786
9787diff --git a/arch/sh/mm/mmap.c b/arch/sh/mm/mmap.c
9788index 6777177..cb5e44f 100644
9789--- a/arch/sh/mm/mmap.c
9790+++ b/arch/sh/mm/mmap.c
9791@@ -36,6 +36,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
9792 struct mm_struct *mm = current->mm;
9793 struct vm_area_struct *vma;
9794 int do_colour_align;
9795+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
9796 struct vm_unmapped_area_info info;
9797
9798 if (flags & MAP_FIXED) {
9799@@ -55,6 +56,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
9800 if (filp || (flags & MAP_SHARED))
9801 do_colour_align = 1;
9802
9803+#ifdef CONFIG_PAX_RANDMMAP
9804+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9805+#endif
9806+
9807 if (addr) {
9808 if (do_colour_align)
9809 addr = COLOUR_ALIGN(addr, pgoff);
9810@@ -62,14 +67,13 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
9811 addr = PAGE_ALIGN(addr);
9812
9813 vma = find_vma(mm, addr);
9814- if (TASK_SIZE - len >= addr &&
9815- (!vma || addr + len <= vma->vm_start))
9816+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
9817 return addr;
9818 }
9819
9820 info.flags = 0;
9821 info.length = len;
9822- info.low_limit = TASK_UNMAPPED_BASE;
9823+ info.low_limit = mm->mmap_base;
9824 info.high_limit = TASK_SIZE;
9825 info.align_mask = do_colour_align ? (PAGE_MASK & shm_align_mask) : 0;
9826 info.align_offset = pgoff << PAGE_SHIFT;
9827@@ -85,6 +89,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9828 struct mm_struct *mm = current->mm;
9829 unsigned long addr = addr0;
9830 int do_colour_align;
9831+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
9832 struct vm_unmapped_area_info info;
9833
9834 if (flags & MAP_FIXED) {
9835@@ -104,6 +109,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9836 if (filp || (flags & MAP_SHARED))
9837 do_colour_align = 1;
9838
9839+#ifdef CONFIG_PAX_RANDMMAP
9840+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9841+#endif
9842+
9843 /* requesting a specific address */
9844 if (addr) {
9845 if (do_colour_align)
9846@@ -112,8 +121,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9847 addr = PAGE_ALIGN(addr);
9848
9849 vma = find_vma(mm, addr);
9850- if (TASK_SIZE - len >= addr &&
9851- (!vma || addr + len <= vma->vm_start))
9852+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
9853 return addr;
9854 }
9855
9856@@ -135,6 +143,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9857 VM_BUG_ON(addr != -ENOMEM);
9858 info.flags = 0;
9859 info.low_limit = TASK_UNMAPPED_BASE;
9860+
9861+#ifdef CONFIG_PAX_RANDMMAP
9862+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9863+ info.low_limit += mm->delta_mmap;
9864+#endif
9865+
9866 info.high_limit = TASK_SIZE;
9867 addr = vm_unmapped_area(&info);
9868 }
9869diff --git a/arch/sparc/include/asm/atomic_64.h b/arch/sparc/include/asm/atomic_64.h
9870index 4082749..fd97781 100644
9871--- a/arch/sparc/include/asm/atomic_64.h
9872+++ b/arch/sparc/include/asm/atomic_64.h
9873@@ -15,18 +15,38 @@
9874 #define ATOMIC64_INIT(i) { (i) }
9875
9876 #define atomic_read(v) ACCESS_ONCE((v)->counter)
9877+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
9878+{
9879+ return ACCESS_ONCE(v->counter);
9880+}
9881 #define atomic64_read(v) ACCESS_ONCE((v)->counter)
9882+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
9883+{
9884+ return ACCESS_ONCE(v->counter);
9885+}
9886
9887 #define atomic_set(v, i) (((v)->counter) = i)
9888+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
9889+{
9890+ v->counter = i;
9891+}
9892 #define atomic64_set(v, i) (((v)->counter) = i)
9893+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
9894+{
9895+ v->counter = i;
9896+}
9897
9898-#define ATOMIC_OP(op) \
9899-void atomic_##op(int, atomic_t *); \
9900-void atomic64_##op(long, atomic64_t *);
9901+#define __ATOMIC_OP(op, suffix) \
9902+void atomic_##op##suffix(int, atomic##suffix##_t *); \
9903+void atomic64_##op##suffix(long, atomic64##suffix##_t *);
9904
9905-#define ATOMIC_OP_RETURN(op) \
9906-int atomic_##op##_return(int, atomic_t *); \
9907-long atomic64_##op##_return(long, atomic64_t *);
9908+#define ATOMIC_OP(op) __ATOMIC_OP(op, ) __ATOMIC_OP(op, _unchecked)
9909+
9910+#define __ATOMIC_OP_RETURN(op, suffix) \
9911+int atomic_##op##_return##suffix(int, atomic##suffix##_t *); \
9912+long atomic64_##op##_return##suffix(long, atomic64##suffix##_t *);
9913+
9914+#define ATOMIC_OP_RETURN(op) __ATOMIC_OP_RETURN(op, ) __ATOMIC_OP_RETURN(op, _unchecked)
9915
9916 #define ATOMIC_OPS(op) ATOMIC_OP(op) ATOMIC_OP_RETURN(op)
9917
9918@@ -35,13 +55,23 @@ ATOMIC_OPS(sub)
9919
9920 #undef ATOMIC_OPS
9921 #undef ATOMIC_OP_RETURN
9922+#undef __ATOMIC_OP_RETURN
9923 #undef ATOMIC_OP
9924+#undef __ATOMIC_OP
9925
9926 #define atomic_dec_return(v) atomic_sub_return(1, v)
9927 #define atomic64_dec_return(v) atomic64_sub_return(1, v)
9928
9929 #define atomic_inc_return(v) atomic_add_return(1, v)
9930+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
9931+{
9932+ return atomic_add_return_unchecked(1, v);
9933+}
9934 #define atomic64_inc_return(v) atomic64_add_return(1, v)
9935+static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
9936+{
9937+ return atomic64_add_return_unchecked(1, v);
9938+}
9939
9940 /*
9941 * atomic_inc_and_test - increment and test
9942@@ -52,6 +82,10 @@ ATOMIC_OPS(sub)
9943 * other cases.
9944 */
9945 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
9946+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
9947+{
9948+ return atomic_inc_return_unchecked(v) == 0;
9949+}
9950 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
9951
9952 #define atomic_sub_and_test(i, v) (atomic_sub_return(i, v) == 0)
9953@@ -61,25 +95,60 @@ ATOMIC_OPS(sub)
9954 #define atomic64_dec_and_test(v) (atomic64_sub_return(1, v) == 0)
9955
9956 #define atomic_inc(v) atomic_add(1, v)
9957+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
9958+{
9959+ atomic_add_unchecked(1, v);
9960+}
9961 #define atomic64_inc(v) atomic64_add(1, v)
9962+static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
9963+{
9964+ atomic64_add_unchecked(1, v);
9965+}
9966
9967 #define atomic_dec(v) atomic_sub(1, v)
9968+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
9969+{
9970+ atomic_sub_unchecked(1, v);
9971+}
9972 #define atomic64_dec(v) atomic64_sub(1, v)
9973+static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
9974+{
9975+ atomic64_sub_unchecked(1, v);
9976+}
9977
9978 #define atomic_add_negative(i, v) (atomic_add_return(i, v) < 0)
9979 #define atomic64_add_negative(i, v) (atomic64_add_return(i, v) < 0)
9980
9981 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
9982+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
9983+{
9984+ return cmpxchg(&v->counter, old, new);
9985+}
9986 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
9987+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
9988+{
9989+ return xchg(&v->counter, new);
9990+}
9991
9992 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
9993 {
9994- int c, old;
9995+ int c, old, new;
9996 c = atomic_read(v);
9997 for (;;) {
9998- if (unlikely(c == (u)))
9999+ if (unlikely(c == u))
10000 break;
10001- old = atomic_cmpxchg((v), c, c + (a));
10002+
10003+ asm volatile("addcc %2, %0, %0\n"
10004+
10005+#ifdef CONFIG_PAX_REFCOUNT
10006+ "tvs %%icc, 6\n"
10007+#endif
10008+
10009+ : "=r" (new)
10010+ : "0" (c), "ir" (a)
10011+ : "cc");
10012+
10013+ old = atomic_cmpxchg(v, c, new);
10014 if (likely(old == c))
10015 break;
10016 c = old;
10017@@ -90,20 +159,35 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
10018 #define atomic64_cmpxchg(v, o, n) \
10019 ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
10020 #define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
10021+static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
10022+{
10023+ return xchg(&v->counter, new);
10024+}
10025
10026 static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
10027 {
10028- long c, old;
10029+ long c, old, new;
10030 c = atomic64_read(v);
10031 for (;;) {
10032- if (unlikely(c == (u)))
10033+ if (unlikely(c == u))
10034 break;
10035- old = atomic64_cmpxchg((v), c, c + (a));
10036+
10037+ asm volatile("addcc %2, %0, %0\n"
10038+
10039+#ifdef CONFIG_PAX_REFCOUNT
10040+ "tvs %%xcc, 6\n"
10041+#endif
10042+
10043+ : "=r" (new)
10044+ : "0" (c), "ir" (a)
10045+ : "cc");
10046+
10047+ old = atomic64_cmpxchg(v, c, new);
10048 if (likely(old == c))
10049 break;
10050 c = old;
10051 }
10052- return c != (u);
10053+ return c != u;
10054 }
10055
10056 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
10057diff --git a/arch/sparc/include/asm/barrier_64.h b/arch/sparc/include/asm/barrier_64.h
10058index 305dcc3..7835030 100644
10059--- a/arch/sparc/include/asm/barrier_64.h
10060+++ b/arch/sparc/include/asm/barrier_64.h
10061@@ -57,7 +57,7 @@ do { __asm__ __volatile__("ba,pt %%xcc, 1f\n\t" \
10062 do { \
10063 compiletime_assert_atomic_type(*p); \
10064 barrier(); \
10065- ACCESS_ONCE(*p) = (v); \
10066+ ACCESS_ONCE_RW(*p) = (v); \
10067 } while (0)
10068
10069 #define smp_load_acquire(p) \
10070diff --git a/arch/sparc/include/asm/cache.h b/arch/sparc/include/asm/cache.h
10071index 5bb6991..5c2132e 100644
10072--- a/arch/sparc/include/asm/cache.h
10073+++ b/arch/sparc/include/asm/cache.h
10074@@ -7,10 +7,12 @@
10075 #ifndef _SPARC_CACHE_H
10076 #define _SPARC_CACHE_H
10077
10078+#include <linux/const.h>
10079+
10080 #define ARCH_SLAB_MINALIGN __alignof__(unsigned long long)
10081
10082 #define L1_CACHE_SHIFT 5
10083-#define L1_CACHE_BYTES 32
10084+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
10085
10086 #ifdef CONFIG_SPARC32
10087 #define SMP_CACHE_BYTES_SHIFT 5
10088diff --git a/arch/sparc/include/asm/elf_32.h b/arch/sparc/include/asm/elf_32.h
10089index a24e41f..47677ff 100644
10090--- a/arch/sparc/include/asm/elf_32.h
10091+++ b/arch/sparc/include/asm/elf_32.h
10092@@ -114,6 +114,13 @@ typedef struct {
10093
10094 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE)
10095
10096+#ifdef CONFIG_PAX_ASLR
10097+#define PAX_ELF_ET_DYN_BASE 0x10000UL
10098+
10099+#define PAX_DELTA_MMAP_LEN 16
10100+#define PAX_DELTA_STACK_LEN 16
10101+#endif
10102+
10103 /* This yields a mask that user programs can use to figure out what
10104 instruction set this cpu supports. This can NOT be done in userspace
10105 on Sparc. */
10106diff --git a/arch/sparc/include/asm/elf_64.h b/arch/sparc/include/asm/elf_64.h
10107index 370ca1e..d4f4a98 100644
10108--- a/arch/sparc/include/asm/elf_64.h
10109+++ b/arch/sparc/include/asm/elf_64.h
10110@@ -189,6 +189,13 @@ typedef struct {
10111 #define ELF_ET_DYN_BASE 0x0000010000000000UL
10112 #define COMPAT_ELF_ET_DYN_BASE 0x0000000070000000UL
10113
10114+#ifdef CONFIG_PAX_ASLR
10115+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT) ? 0x10000UL : 0x100000UL)
10116+
10117+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 14 : 28)
10118+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 15 : 29)
10119+#endif
10120+
10121 extern unsigned long sparc64_elf_hwcap;
10122 #define ELF_HWCAP sparc64_elf_hwcap
10123
10124diff --git a/arch/sparc/include/asm/pgalloc_32.h b/arch/sparc/include/asm/pgalloc_32.h
10125index a3890da..f6a408e 100644
10126--- a/arch/sparc/include/asm/pgalloc_32.h
10127+++ b/arch/sparc/include/asm/pgalloc_32.h
10128@@ -35,6 +35,7 @@ static inline void pgd_set(pgd_t * pgdp, pmd_t * pmdp)
10129 }
10130
10131 #define pgd_populate(MM, PGD, PMD) pgd_set(PGD, PMD)
10132+#define pgd_populate_kernel(MM, PGD, PMD) pgd_populate((MM), (PGD), (PMD))
10133
10134 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm,
10135 unsigned long address)
10136diff --git a/arch/sparc/include/asm/pgalloc_64.h b/arch/sparc/include/asm/pgalloc_64.h
10137index 5e31871..13469c6 100644
10138--- a/arch/sparc/include/asm/pgalloc_64.h
10139+++ b/arch/sparc/include/asm/pgalloc_64.h
10140@@ -21,6 +21,7 @@ static inline void __pgd_populate(pgd_t *pgd, pud_t *pud)
10141 }
10142
10143 #define pgd_populate(MM, PGD, PUD) __pgd_populate(PGD, PUD)
10144+#define pgd_populate_kernel(MM, PGD, PMD) pgd_populate((MM), (PGD), (PMD))
10145
10146 static inline pgd_t *pgd_alloc(struct mm_struct *mm)
10147 {
10148@@ -38,6 +39,7 @@ static inline void __pud_populate(pud_t *pud, pmd_t *pmd)
10149 }
10150
10151 #define pud_populate(MM, PUD, PMD) __pud_populate(PUD, PMD)
10152+#define pud_populate_kernel(MM, PUD, PMD) pud_populate((MM), (PUD), (PMD))
10153
10154 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
10155 {
10156diff --git a/arch/sparc/include/asm/pgtable.h b/arch/sparc/include/asm/pgtable.h
10157index 59ba6f6..4518128 100644
10158--- a/arch/sparc/include/asm/pgtable.h
10159+++ b/arch/sparc/include/asm/pgtable.h
10160@@ -5,4 +5,8 @@
10161 #else
10162 #include <asm/pgtable_32.h>
10163 #endif
10164+
10165+#define ktla_ktva(addr) (addr)
10166+#define ktva_ktla(addr) (addr)
10167+
10168 #endif
10169diff --git a/arch/sparc/include/asm/pgtable_32.h b/arch/sparc/include/asm/pgtable_32.h
10170index b9b91ae..950b91e 100644
10171--- a/arch/sparc/include/asm/pgtable_32.h
10172+++ b/arch/sparc/include/asm/pgtable_32.h
10173@@ -51,6 +51,9 @@ unsigned long __init bootmem_init(unsigned long *pages_avail);
10174 #define PAGE_SHARED SRMMU_PAGE_SHARED
10175 #define PAGE_COPY SRMMU_PAGE_COPY
10176 #define PAGE_READONLY SRMMU_PAGE_RDONLY
10177+#define PAGE_SHARED_NOEXEC SRMMU_PAGE_SHARED_NOEXEC
10178+#define PAGE_COPY_NOEXEC SRMMU_PAGE_COPY_NOEXEC
10179+#define PAGE_READONLY_NOEXEC SRMMU_PAGE_RDONLY_NOEXEC
10180 #define PAGE_KERNEL SRMMU_PAGE_KERNEL
10181
10182 /* Top-level page directory - dummy used by init-mm.
10183@@ -63,18 +66,18 @@ extern unsigned long ptr_in_current_pgd;
10184
10185 /* xwr */
10186 #define __P000 PAGE_NONE
10187-#define __P001 PAGE_READONLY
10188-#define __P010 PAGE_COPY
10189-#define __P011 PAGE_COPY
10190+#define __P001 PAGE_READONLY_NOEXEC
10191+#define __P010 PAGE_COPY_NOEXEC
10192+#define __P011 PAGE_COPY_NOEXEC
10193 #define __P100 PAGE_READONLY
10194 #define __P101 PAGE_READONLY
10195 #define __P110 PAGE_COPY
10196 #define __P111 PAGE_COPY
10197
10198 #define __S000 PAGE_NONE
10199-#define __S001 PAGE_READONLY
10200-#define __S010 PAGE_SHARED
10201-#define __S011 PAGE_SHARED
10202+#define __S001 PAGE_READONLY_NOEXEC
10203+#define __S010 PAGE_SHARED_NOEXEC
10204+#define __S011 PAGE_SHARED_NOEXEC
10205 #define __S100 PAGE_READONLY
10206 #define __S101 PAGE_READONLY
10207 #define __S110 PAGE_SHARED
10208diff --git a/arch/sparc/include/asm/pgtsrmmu.h b/arch/sparc/include/asm/pgtsrmmu.h
10209index 79da178..c2eede8 100644
10210--- a/arch/sparc/include/asm/pgtsrmmu.h
10211+++ b/arch/sparc/include/asm/pgtsrmmu.h
10212@@ -115,6 +115,11 @@
10213 SRMMU_EXEC | SRMMU_REF)
10214 #define SRMMU_PAGE_RDONLY __pgprot(SRMMU_VALID | SRMMU_CACHE | \
10215 SRMMU_EXEC | SRMMU_REF)
10216+
10217+#define SRMMU_PAGE_SHARED_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_WRITE | SRMMU_REF)
10218+#define SRMMU_PAGE_COPY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
10219+#define SRMMU_PAGE_RDONLY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
10220+
10221 #define SRMMU_PAGE_KERNEL __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
10222 SRMMU_DIRTY | SRMMU_REF)
10223
10224diff --git a/arch/sparc/include/asm/setup.h b/arch/sparc/include/asm/setup.h
10225index 29d64b1..4272fe8 100644
10226--- a/arch/sparc/include/asm/setup.h
10227+++ b/arch/sparc/include/asm/setup.h
10228@@ -55,8 +55,8 @@ int handle_ldf_stq(u32 insn, struct pt_regs *regs);
10229 void handle_ld_nf(u32 insn, struct pt_regs *regs);
10230
10231 /* init_64.c */
10232-extern atomic_t dcpage_flushes;
10233-extern atomic_t dcpage_flushes_xcall;
10234+extern atomic_unchecked_t dcpage_flushes;
10235+extern atomic_unchecked_t dcpage_flushes_xcall;
10236
10237 extern int sysctl_tsb_ratio;
10238 #endif
10239diff --git a/arch/sparc/include/asm/spinlock_64.h b/arch/sparc/include/asm/spinlock_64.h
10240index 9689176..63c18ea 100644
10241--- a/arch/sparc/include/asm/spinlock_64.h
10242+++ b/arch/sparc/include/asm/spinlock_64.h
10243@@ -92,14 +92,19 @@ static inline void arch_spin_lock_flags(arch_spinlock_t *lock, unsigned long fla
10244
10245 /* Multi-reader locks, these are much saner than the 32-bit Sparc ones... */
10246
10247-static void inline arch_read_lock(arch_rwlock_t *lock)
10248+static inline void arch_read_lock(arch_rwlock_t *lock)
10249 {
10250 unsigned long tmp1, tmp2;
10251
10252 __asm__ __volatile__ (
10253 "1: ldsw [%2], %0\n"
10254 " brlz,pn %0, 2f\n"
10255-"4: add %0, 1, %1\n"
10256+"4: addcc %0, 1, %1\n"
10257+
10258+#ifdef CONFIG_PAX_REFCOUNT
10259+" tvs %%icc, 6\n"
10260+#endif
10261+
10262 " cas [%2], %0, %1\n"
10263 " cmp %0, %1\n"
10264 " bne,pn %%icc, 1b\n"
10265@@ -112,10 +117,10 @@ static void inline arch_read_lock(arch_rwlock_t *lock)
10266 " .previous"
10267 : "=&r" (tmp1), "=&r" (tmp2)
10268 : "r" (lock)
10269- : "memory");
10270+ : "memory", "cc");
10271 }
10272
10273-static int inline arch_read_trylock(arch_rwlock_t *lock)
10274+static inline int arch_read_trylock(arch_rwlock_t *lock)
10275 {
10276 int tmp1, tmp2;
10277
10278@@ -123,7 +128,12 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
10279 "1: ldsw [%2], %0\n"
10280 " brlz,a,pn %0, 2f\n"
10281 " mov 0, %0\n"
10282-" add %0, 1, %1\n"
10283+" addcc %0, 1, %1\n"
10284+
10285+#ifdef CONFIG_PAX_REFCOUNT
10286+" tvs %%icc, 6\n"
10287+#endif
10288+
10289 " cas [%2], %0, %1\n"
10290 " cmp %0, %1\n"
10291 " bne,pn %%icc, 1b\n"
10292@@ -136,13 +146,18 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
10293 return tmp1;
10294 }
10295
10296-static void inline arch_read_unlock(arch_rwlock_t *lock)
10297+static inline void arch_read_unlock(arch_rwlock_t *lock)
10298 {
10299 unsigned long tmp1, tmp2;
10300
10301 __asm__ __volatile__(
10302 "1: lduw [%2], %0\n"
10303-" sub %0, 1, %1\n"
10304+" subcc %0, 1, %1\n"
10305+
10306+#ifdef CONFIG_PAX_REFCOUNT
10307+" tvs %%icc, 6\n"
10308+#endif
10309+
10310 " cas [%2], %0, %1\n"
10311 " cmp %0, %1\n"
10312 " bne,pn %%xcc, 1b\n"
10313@@ -152,7 +167,7 @@ static void inline arch_read_unlock(arch_rwlock_t *lock)
10314 : "memory");
10315 }
10316
10317-static void inline arch_write_lock(arch_rwlock_t *lock)
10318+static inline void arch_write_lock(arch_rwlock_t *lock)
10319 {
10320 unsigned long mask, tmp1, tmp2;
10321
10322@@ -177,7 +192,7 @@ static void inline arch_write_lock(arch_rwlock_t *lock)
10323 : "memory");
10324 }
10325
10326-static void inline arch_write_unlock(arch_rwlock_t *lock)
10327+static inline void arch_write_unlock(arch_rwlock_t *lock)
10328 {
10329 __asm__ __volatile__(
10330 " stw %%g0, [%0]"
10331@@ -186,7 +201,7 @@ static void inline arch_write_unlock(arch_rwlock_t *lock)
10332 : "memory");
10333 }
10334
10335-static int inline arch_write_trylock(arch_rwlock_t *lock)
10336+static inline int arch_write_trylock(arch_rwlock_t *lock)
10337 {
10338 unsigned long mask, tmp1, tmp2, result;
10339
10340diff --git a/arch/sparc/include/asm/thread_info_32.h b/arch/sparc/include/asm/thread_info_32.h
10341index 025c984..a216504 100644
10342--- a/arch/sparc/include/asm/thread_info_32.h
10343+++ b/arch/sparc/include/asm/thread_info_32.h
10344@@ -49,6 +49,8 @@ struct thread_info {
10345 unsigned long w_saved;
10346
10347 struct restart_block restart_block;
10348+
10349+ unsigned long lowest_stack;
10350 };
10351
10352 /*
10353diff --git a/arch/sparc/include/asm/thread_info_64.h b/arch/sparc/include/asm/thread_info_64.h
10354index 798f027..b009941 100644
10355--- a/arch/sparc/include/asm/thread_info_64.h
10356+++ b/arch/sparc/include/asm/thread_info_64.h
10357@@ -63,6 +63,8 @@ struct thread_info {
10358 struct pt_regs *kern_una_regs;
10359 unsigned int kern_una_insn;
10360
10361+ unsigned long lowest_stack;
10362+
10363 unsigned long fpregs[(7 * 256) / sizeof(unsigned long)]
10364 __attribute__ ((aligned(64)));
10365 };
10366@@ -190,12 +192,13 @@ register struct thread_info *current_thread_info_reg asm("g6");
10367 #define TIF_NEED_RESCHED 3 /* rescheduling necessary */
10368 /* flag bit 4 is available */
10369 #define TIF_UNALIGNED 5 /* allowed to do unaligned accesses */
10370-/* flag bit 6 is available */
10371+#define TIF_GRSEC_SETXID 6 /* update credentials on syscall entry/exit */
10372 #define TIF_32BIT 7 /* 32-bit binary */
10373 #define TIF_NOHZ 8 /* in adaptive nohz mode */
10374 #define TIF_SECCOMP 9 /* secure computing */
10375 #define TIF_SYSCALL_AUDIT 10 /* syscall auditing active */
10376 #define TIF_SYSCALL_TRACEPOINT 11 /* syscall tracepoint instrumentation */
10377+
10378 /* NOTE: Thread flags >= 12 should be ones we have no interest
10379 * in using in assembly, else we can't use the mask as
10380 * an immediate value in instructions such as andcc.
10381@@ -215,12 +218,17 @@ register struct thread_info *current_thread_info_reg asm("g6");
10382 #define _TIF_SYSCALL_AUDIT (1<<TIF_SYSCALL_AUDIT)
10383 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
10384 #define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG)
10385+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
10386
10387 #define _TIF_USER_WORK_MASK ((0xff << TI_FLAG_WSAVED_SHIFT) | \
10388 _TIF_DO_NOTIFY_RESUME_MASK | \
10389 _TIF_NEED_RESCHED)
10390 #define _TIF_DO_NOTIFY_RESUME_MASK (_TIF_NOTIFY_RESUME | _TIF_SIGPENDING)
10391
10392+#define _TIF_WORK_SYSCALL \
10393+ (_TIF_SYSCALL_TRACE | _TIF_SECCOMP | _TIF_SYSCALL_AUDIT | \
10394+ _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ | _TIF_GRSEC_SETXID)
10395+
10396 #define is_32bit_task() (test_thread_flag(TIF_32BIT))
10397
10398 /*
10399diff --git a/arch/sparc/include/asm/uaccess.h b/arch/sparc/include/asm/uaccess.h
10400index bd56c28..4b63d83 100644
10401--- a/arch/sparc/include/asm/uaccess.h
10402+++ b/arch/sparc/include/asm/uaccess.h
10403@@ -1,5 +1,6 @@
10404 #ifndef ___ASM_SPARC_UACCESS_H
10405 #define ___ASM_SPARC_UACCESS_H
10406+
10407 #if defined(__sparc__) && defined(__arch64__)
10408 #include <asm/uaccess_64.h>
10409 #else
10410diff --git a/arch/sparc/include/asm/uaccess_32.h b/arch/sparc/include/asm/uaccess_32.h
10411index 9634d08..f55fe4f 100644
10412--- a/arch/sparc/include/asm/uaccess_32.h
10413+++ b/arch/sparc/include/asm/uaccess_32.h
10414@@ -250,27 +250,46 @@ unsigned long __copy_user(void __user *to, const void __user *from, unsigned lon
10415
10416 static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
10417 {
10418- if (n && __access_ok((unsigned long) to, n))
10419+ if ((long)n < 0)
10420+ return n;
10421+
10422+ if (n && __access_ok((unsigned long) to, n)) {
10423+ if (!__builtin_constant_p(n))
10424+ check_object_size(from, n, true);
10425 return __copy_user(to, (__force void __user *) from, n);
10426- else
10427+ } else
10428 return n;
10429 }
10430
10431 static inline unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n)
10432 {
10433+ if ((long)n < 0)
10434+ return n;
10435+
10436+ if (!__builtin_constant_p(n))
10437+ check_object_size(from, n, true);
10438+
10439 return __copy_user(to, (__force void __user *) from, n);
10440 }
10441
10442 static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
10443 {
10444- if (n && __access_ok((unsigned long) from, n))
10445+ if ((long)n < 0)
10446+ return n;
10447+
10448+ if (n && __access_ok((unsigned long) from, n)) {
10449+ if (!__builtin_constant_p(n))
10450+ check_object_size(to, n, false);
10451 return __copy_user((__force void __user *) to, from, n);
10452- else
10453+ } else
10454 return n;
10455 }
10456
10457 static inline unsigned long __copy_from_user(void *to, const void __user *from, unsigned long n)
10458 {
10459+ if ((long)n < 0)
10460+ return n;
10461+
10462 return __copy_user((__force void __user *) to, from, n);
10463 }
10464
10465diff --git a/arch/sparc/include/asm/uaccess_64.h b/arch/sparc/include/asm/uaccess_64.h
10466index c990a5e..f17b9c1 100644
10467--- a/arch/sparc/include/asm/uaccess_64.h
10468+++ b/arch/sparc/include/asm/uaccess_64.h
10469@@ -10,6 +10,7 @@
10470 #include <linux/compiler.h>
10471 #include <linux/string.h>
10472 #include <linux/thread_info.h>
10473+#include <linux/kernel.h>
10474 #include <asm/asi.h>
10475 #include <asm/spitfire.h>
10476 #include <asm-generic/uaccess-unaligned.h>
10477@@ -214,8 +215,15 @@ unsigned long copy_from_user_fixup(void *to, const void __user *from,
10478 static inline unsigned long __must_check
10479 copy_from_user(void *to, const void __user *from, unsigned long size)
10480 {
10481- unsigned long ret = ___copy_from_user(to, from, size);
10482+ unsigned long ret;
10483
10484+ if ((long)size < 0 || size > INT_MAX)
10485+ return size;
10486+
10487+ if (!__builtin_constant_p(size))
10488+ check_object_size(to, size, false);
10489+
10490+ ret = ___copy_from_user(to, from, size);
10491 if (unlikely(ret))
10492 ret = copy_from_user_fixup(to, from, size);
10493
10494@@ -231,8 +239,15 @@ unsigned long copy_to_user_fixup(void __user *to, const void *from,
10495 static inline unsigned long __must_check
10496 copy_to_user(void __user *to, const void *from, unsigned long size)
10497 {
10498- unsigned long ret = ___copy_to_user(to, from, size);
10499+ unsigned long ret;
10500
10501+ if ((long)size < 0 || size > INT_MAX)
10502+ return size;
10503+
10504+ if (!__builtin_constant_p(size))
10505+ check_object_size(from, size, true);
10506+
10507+ ret = ___copy_to_user(to, from, size);
10508 if (unlikely(ret))
10509 ret = copy_to_user_fixup(to, from, size);
10510 return ret;
10511diff --git a/arch/sparc/kernel/Makefile b/arch/sparc/kernel/Makefile
10512index 7cf9c6e..6206648 100644
10513--- a/arch/sparc/kernel/Makefile
10514+++ b/arch/sparc/kernel/Makefile
10515@@ -4,7 +4,7 @@
10516 #
10517
10518 asflags-y := -ansi
10519-ccflags-y := -Werror
10520+#ccflags-y := -Werror
10521
10522 extra-y := head_$(BITS).o
10523
10524diff --git a/arch/sparc/kernel/process_32.c b/arch/sparc/kernel/process_32.c
10525index 50e7b62..79fae35 100644
10526--- a/arch/sparc/kernel/process_32.c
10527+++ b/arch/sparc/kernel/process_32.c
10528@@ -123,14 +123,14 @@ void show_regs(struct pt_regs *r)
10529
10530 printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx %s\n",
10531 r->psr, r->pc, r->npc, r->y, print_tainted());
10532- printk("PC: <%pS>\n", (void *) r->pc);
10533+ printk("PC: <%pA>\n", (void *) r->pc);
10534 printk("%%G: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
10535 r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3],
10536 r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]);
10537 printk("%%O: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
10538 r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11],
10539 r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]);
10540- printk("RPC: <%pS>\n", (void *) r->u_regs[15]);
10541+ printk("RPC: <%pA>\n", (void *) r->u_regs[15]);
10542
10543 printk("%%L: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
10544 rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
10545@@ -167,7 +167,7 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
10546 rw = (struct reg_window32 *) fp;
10547 pc = rw->ins[7];
10548 printk("[%08lx : ", pc);
10549- printk("%pS ] ", (void *) pc);
10550+ printk("%pA ] ", (void *) pc);
10551 fp = rw->ins[6];
10552 } while (++count < 16);
10553 printk("\n");
10554diff --git a/arch/sparc/kernel/process_64.c b/arch/sparc/kernel/process_64.c
10555index 0be7bf9..2b1cba8 100644
10556--- a/arch/sparc/kernel/process_64.c
10557+++ b/arch/sparc/kernel/process_64.c
10558@@ -161,7 +161,7 @@ static void show_regwindow(struct pt_regs *regs)
10559 printk("i4: %016lx i5: %016lx i6: %016lx i7: %016lx\n",
10560 rwk->ins[4], rwk->ins[5], rwk->ins[6], rwk->ins[7]);
10561 if (regs->tstate & TSTATE_PRIV)
10562- printk("I7: <%pS>\n", (void *) rwk->ins[7]);
10563+ printk("I7: <%pA>\n", (void *) rwk->ins[7]);
10564 }
10565
10566 void show_regs(struct pt_regs *regs)
10567@@ -170,7 +170,7 @@ void show_regs(struct pt_regs *regs)
10568
10569 printk("TSTATE: %016lx TPC: %016lx TNPC: %016lx Y: %08x %s\n", regs->tstate,
10570 regs->tpc, regs->tnpc, regs->y, print_tainted());
10571- printk("TPC: <%pS>\n", (void *) regs->tpc);
10572+ printk("TPC: <%pA>\n", (void *) regs->tpc);
10573 printk("g0: %016lx g1: %016lx g2: %016lx g3: %016lx\n",
10574 regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
10575 regs->u_regs[3]);
10576@@ -183,7 +183,7 @@ void show_regs(struct pt_regs *regs)
10577 printk("o4: %016lx o5: %016lx sp: %016lx ret_pc: %016lx\n",
10578 regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
10579 regs->u_regs[15]);
10580- printk("RPC: <%pS>\n", (void *) regs->u_regs[15]);
10581+ printk("RPC: <%pA>\n", (void *) regs->u_regs[15]);
10582 show_regwindow(regs);
10583 show_stack(current, (unsigned long *) regs->u_regs[UREG_FP]);
10584 }
10585@@ -278,7 +278,7 @@ void arch_trigger_all_cpu_backtrace(bool include_self)
10586 ((tp && tp->task) ? tp->task->pid : -1));
10587
10588 if (gp->tstate & TSTATE_PRIV) {
10589- printk(" TPC[%pS] O7[%pS] I7[%pS] RPC[%pS]\n",
10590+ printk(" TPC[%pA] O7[%pA] I7[%pA] RPC[%pA]\n",
10591 (void *) gp->tpc,
10592 (void *) gp->o7,
10593 (void *) gp->i7,
10594diff --git a/arch/sparc/kernel/prom_common.c b/arch/sparc/kernel/prom_common.c
10595index 79cc0d1..ec62734 100644
10596--- a/arch/sparc/kernel/prom_common.c
10597+++ b/arch/sparc/kernel/prom_common.c
10598@@ -144,7 +144,7 @@ static int __init prom_common_nextprop(phandle node, char *prev, char *buf)
10599
10600 unsigned int prom_early_allocated __initdata;
10601
10602-static struct of_pdt_ops prom_sparc_ops __initdata = {
10603+static struct of_pdt_ops prom_sparc_ops __initconst = {
10604 .nextprop = prom_common_nextprop,
10605 .getproplen = prom_getproplen,
10606 .getproperty = prom_getproperty,
10607diff --git a/arch/sparc/kernel/ptrace_64.c b/arch/sparc/kernel/ptrace_64.c
10608index 9ddc492..27a5619 100644
10609--- a/arch/sparc/kernel/ptrace_64.c
10610+++ b/arch/sparc/kernel/ptrace_64.c
10611@@ -1060,6 +1060,10 @@ long arch_ptrace(struct task_struct *child, long request,
10612 return ret;
10613 }
10614
10615+#ifdef CONFIG_GRKERNSEC_SETXID
10616+extern void gr_delayed_cred_worker(void);
10617+#endif
10618+
10619 asmlinkage int syscall_trace_enter(struct pt_regs *regs)
10620 {
10621 int ret = 0;
10622@@ -1070,6 +1074,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
10623 if (test_thread_flag(TIF_NOHZ))
10624 user_exit();
10625
10626+#ifdef CONFIG_GRKERNSEC_SETXID
10627+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
10628+ gr_delayed_cred_worker();
10629+#endif
10630+
10631 if (test_thread_flag(TIF_SYSCALL_TRACE))
10632 ret = tracehook_report_syscall_entry(regs);
10633
10634@@ -1088,6 +1097,11 @@ asmlinkage void syscall_trace_leave(struct pt_regs *regs)
10635 if (test_thread_flag(TIF_NOHZ))
10636 user_exit();
10637
10638+#ifdef CONFIG_GRKERNSEC_SETXID
10639+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
10640+ gr_delayed_cred_worker();
10641+#endif
10642+
10643 audit_syscall_exit(regs);
10644
10645 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
10646diff --git a/arch/sparc/kernel/smp_64.c b/arch/sparc/kernel/smp_64.c
10647index da6f1a7..e5dea8f 100644
10648--- a/arch/sparc/kernel/smp_64.c
10649+++ b/arch/sparc/kernel/smp_64.c
10650@@ -887,7 +887,7 @@ void smp_flush_dcache_page_impl(struct page *page, int cpu)
10651 return;
10652
10653 #ifdef CONFIG_DEBUG_DCFLUSH
10654- atomic_inc(&dcpage_flushes);
10655+ atomic_inc_unchecked(&dcpage_flushes);
10656 #endif
10657
10658 this_cpu = get_cpu();
10659@@ -911,7 +911,7 @@ void smp_flush_dcache_page_impl(struct page *page, int cpu)
10660 xcall_deliver(data0, __pa(pg_addr),
10661 (u64) pg_addr, cpumask_of(cpu));
10662 #ifdef CONFIG_DEBUG_DCFLUSH
10663- atomic_inc(&dcpage_flushes_xcall);
10664+ atomic_inc_unchecked(&dcpage_flushes_xcall);
10665 #endif
10666 }
10667 }
10668@@ -930,7 +930,7 @@ void flush_dcache_page_all(struct mm_struct *mm, struct page *page)
10669 preempt_disable();
10670
10671 #ifdef CONFIG_DEBUG_DCFLUSH
10672- atomic_inc(&dcpage_flushes);
10673+ atomic_inc_unchecked(&dcpage_flushes);
10674 #endif
10675 data0 = 0;
10676 pg_addr = page_address(page);
10677@@ -947,7 +947,7 @@ void flush_dcache_page_all(struct mm_struct *mm, struct page *page)
10678 xcall_deliver(data0, __pa(pg_addr),
10679 (u64) pg_addr, cpu_online_mask);
10680 #ifdef CONFIG_DEBUG_DCFLUSH
10681- atomic_inc(&dcpage_flushes_xcall);
10682+ atomic_inc_unchecked(&dcpage_flushes_xcall);
10683 #endif
10684 }
10685 __local_flush_dcache_page(page);
10686diff --git a/arch/sparc/kernel/sys_sparc_32.c b/arch/sparc/kernel/sys_sparc_32.c
10687index 646988d..b88905f 100644
10688--- a/arch/sparc/kernel/sys_sparc_32.c
10689+++ b/arch/sparc/kernel/sys_sparc_32.c
10690@@ -54,7 +54,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
10691 if (len > TASK_SIZE - PAGE_SIZE)
10692 return -ENOMEM;
10693 if (!addr)
10694- addr = TASK_UNMAPPED_BASE;
10695+ addr = current->mm->mmap_base;
10696
10697 info.flags = 0;
10698 info.length = len;
10699diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
10700index c85403d..6af95c9 100644
10701--- a/arch/sparc/kernel/sys_sparc_64.c
10702+++ b/arch/sparc/kernel/sys_sparc_64.c
10703@@ -89,13 +89,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
10704 struct vm_area_struct * vma;
10705 unsigned long task_size = TASK_SIZE;
10706 int do_color_align;
10707+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
10708 struct vm_unmapped_area_info info;
10709
10710 if (flags & MAP_FIXED) {
10711 /* We do not accept a shared mapping if it would violate
10712 * cache aliasing constraints.
10713 */
10714- if ((flags & MAP_SHARED) &&
10715+ if ((filp || (flags & MAP_SHARED)) &&
10716 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
10717 return -EINVAL;
10718 return addr;
10719@@ -110,6 +111,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
10720 if (filp || (flags & MAP_SHARED))
10721 do_color_align = 1;
10722
10723+#ifdef CONFIG_PAX_RANDMMAP
10724+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
10725+#endif
10726+
10727 if (addr) {
10728 if (do_color_align)
10729 addr = COLOR_ALIGN(addr, pgoff);
10730@@ -117,22 +122,28 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
10731 addr = PAGE_ALIGN(addr);
10732
10733 vma = find_vma(mm, addr);
10734- if (task_size - len >= addr &&
10735- (!vma || addr + len <= vma->vm_start))
10736+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
10737 return addr;
10738 }
10739
10740 info.flags = 0;
10741 info.length = len;
10742- info.low_limit = TASK_UNMAPPED_BASE;
10743+ info.low_limit = mm->mmap_base;
10744 info.high_limit = min(task_size, VA_EXCLUDE_START);
10745 info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
10746 info.align_offset = pgoff << PAGE_SHIFT;
10747+ info.threadstack_offset = offset;
10748 addr = vm_unmapped_area(&info);
10749
10750 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
10751 VM_BUG_ON(addr != -ENOMEM);
10752 info.low_limit = VA_EXCLUDE_END;
10753+
10754+#ifdef CONFIG_PAX_RANDMMAP
10755+ if (mm->pax_flags & MF_PAX_RANDMMAP)
10756+ info.low_limit += mm->delta_mmap;
10757+#endif
10758+
10759 info.high_limit = task_size;
10760 addr = vm_unmapped_area(&info);
10761 }
10762@@ -150,6 +161,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10763 unsigned long task_size = STACK_TOP32;
10764 unsigned long addr = addr0;
10765 int do_color_align;
10766+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
10767 struct vm_unmapped_area_info info;
10768
10769 /* This should only ever run for 32-bit processes. */
10770@@ -159,7 +171,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10771 /* We do not accept a shared mapping if it would violate
10772 * cache aliasing constraints.
10773 */
10774- if ((flags & MAP_SHARED) &&
10775+ if ((filp || (flags & MAP_SHARED)) &&
10776 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
10777 return -EINVAL;
10778 return addr;
10779@@ -172,6 +184,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10780 if (filp || (flags & MAP_SHARED))
10781 do_color_align = 1;
10782
10783+#ifdef CONFIG_PAX_RANDMMAP
10784+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
10785+#endif
10786+
10787 /* requesting a specific address */
10788 if (addr) {
10789 if (do_color_align)
10790@@ -180,8 +196,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10791 addr = PAGE_ALIGN(addr);
10792
10793 vma = find_vma(mm, addr);
10794- if (task_size - len >= addr &&
10795- (!vma || addr + len <= vma->vm_start))
10796+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
10797 return addr;
10798 }
10799
10800@@ -191,6 +206,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10801 info.high_limit = mm->mmap_base;
10802 info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
10803 info.align_offset = pgoff << PAGE_SHIFT;
10804+ info.threadstack_offset = offset;
10805 addr = vm_unmapped_area(&info);
10806
10807 /*
10808@@ -203,6 +219,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10809 VM_BUG_ON(addr != -ENOMEM);
10810 info.flags = 0;
10811 info.low_limit = TASK_UNMAPPED_BASE;
10812+
10813+#ifdef CONFIG_PAX_RANDMMAP
10814+ if (mm->pax_flags & MF_PAX_RANDMMAP)
10815+ info.low_limit += mm->delta_mmap;
10816+#endif
10817+
10818 info.high_limit = STACK_TOP32;
10819 addr = vm_unmapped_area(&info);
10820 }
10821@@ -259,10 +281,14 @@ unsigned long get_fb_unmapped_area(struct file *filp, unsigned long orig_addr, u
10822 EXPORT_SYMBOL(get_fb_unmapped_area);
10823
10824 /* Essentially the same as PowerPC. */
10825-static unsigned long mmap_rnd(void)
10826+static unsigned long mmap_rnd(struct mm_struct *mm)
10827 {
10828 unsigned long rnd = 0UL;
10829
10830+#ifdef CONFIG_PAX_RANDMMAP
10831+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
10832+#endif
10833+
10834 if (current->flags & PF_RANDOMIZE) {
10835 unsigned long val = get_random_int();
10836 if (test_thread_flag(TIF_32BIT))
10837@@ -275,7 +301,7 @@ static unsigned long mmap_rnd(void)
10838
10839 void arch_pick_mmap_layout(struct mm_struct *mm)
10840 {
10841- unsigned long random_factor = mmap_rnd();
10842+ unsigned long random_factor = mmap_rnd(mm);
10843 unsigned long gap;
10844
10845 /*
10846@@ -288,6 +314,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
10847 gap == RLIM_INFINITY ||
10848 sysctl_legacy_va_layout) {
10849 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
10850+
10851+#ifdef CONFIG_PAX_RANDMMAP
10852+ if (mm->pax_flags & MF_PAX_RANDMMAP)
10853+ mm->mmap_base += mm->delta_mmap;
10854+#endif
10855+
10856 mm->get_unmapped_area = arch_get_unmapped_area;
10857 } else {
10858 /* We know it's 32-bit */
10859@@ -299,6 +331,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
10860 gap = (task_size / 6 * 5);
10861
10862 mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
10863+
10864+#ifdef CONFIG_PAX_RANDMMAP
10865+ if (mm->pax_flags & MF_PAX_RANDMMAP)
10866+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
10867+#endif
10868+
10869 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
10870 }
10871 }
10872diff --git a/arch/sparc/kernel/syscalls.S b/arch/sparc/kernel/syscalls.S
10873index 33a17e7..d87fb1f 100644
10874--- a/arch/sparc/kernel/syscalls.S
10875+++ b/arch/sparc/kernel/syscalls.S
10876@@ -52,7 +52,7 @@ sys32_rt_sigreturn:
10877 #endif
10878 .align 32
10879 1: ldx [%g6 + TI_FLAGS], %l5
10880- andcc %l5, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
10881+ andcc %l5, _TIF_WORK_SYSCALL, %g0
10882 be,pt %icc, rtrap
10883 nop
10884 call syscall_trace_leave
10885@@ -184,7 +184,7 @@ linux_sparc_syscall32:
10886
10887 srl %i3, 0, %o3 ! IEU0
10888 srl %i2, 0, %o2 ! IEU0 Group
10889- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
10890+ andcc %l0, _TIF_WORK_SYSCALL, %g0
10891 bne,pn %icc, linux_syscall_trace32 ! CTI
10892 mov %i0, %l5 ! IEU1
10893 5: call %l7 ! CTI Group brk forced
10894@@ -208,7 +208,7 @@ linux_sparc_syscall:
10895
10896 mov %i3, %o3 ! IEU1
10897 mov %i4, %o4 ! IEU0 Group
10898- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
10899+ andcc %l0, _TIF_WORK_SYSCALL, %g0
10900 bne,pn %icc, linux_syscall_trace ! CTI Group
10901 mov %i0, %l5 ! IEU0
10902 2: call %l7 ! CTI Group brk forced
10903@@ -223,7 +223,7 @@ ret_sys_call:
10904
10905 cmp %o0, -ERESTART_RESTARTBLOCK
10906 bgeu,pn %xcc, 1f
10907- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
10908+ andcc %l0, _TIF_WORK_SYSCALL, %g0
10909 ldx [%sp + PTREGS_OFF + PT_V9_TNPC], %l1 ! pc = npc
10910
10911 2:
10912diff --git a/arch/sparc/kernel/traps_32.c b/arch/sparc/kernel/traps_32.c
10913index 6fd386c5..6907d81 100644
10914--- a/arch/sparc/kernel/traps_32.c
10915+++ b/arch/sparc/kernel/traps_32.c
10916@@ -44,6 +44,8 @@ static void instruction_dump(unsigned long *pc)
10917 #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
10918 #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
10919
10920+extern void gr_handle_kernel_exploit(void);
10921+
10922 void __noreturn die_if_kernel(char *str, struct pt_regs *regs)
10923 {
10924 static int die_counter;
10925@@ -76,15 +78,17 @@ void __noreturn die_if_kernel(char *str, struct pt_regs *regs)
10926 count++ < 30 &&
10927 (((unsigned long) rw) >= PAGE_OFFSET) &&
10928 !(((unsigned long) rw) & 0x7)) {
10929- printk("Caller[%08lx]: %pS\n", rw->ins[7],
10930+ printk("Caller[%08lx]: %pA\n", rw->ins[7],
10931 (void *) rw->ins[7]);
10932 rw = (struct reg_window32 *)rw->ins[6];
10933 }
10934 }
10935 printk("Instruction DUMP:");
10936 instruction_dump ((unsigned long *) regs->pc);
10937- if(regs->psr & PSR_PS)
10938+ if(regs->psr & PSR_PS) {
10939+ gr_handle_kernel_exploit();
10940 do_exit(SIGKILL);
10941+ }
10942 do_exit(SIGSEGV);
10943 }
10944
10945diff --git a/arch/sparc/kernel/traps_64.c b/arch/sparc/kernel/traps_64.c
10946index 981a769..d906eda 100644
10947--- a/arch/sparc/kernel/traps_64.c
10948+++ b/arch/sparc/kernel/traps_64.c
10949@@ -79,7 +79,7 @@ static void dump_tl1_traplog(struct tl1_traplog *p)
10950 i + 1,
10951 p->trapstack[i].tstate, p->trapstack[i].tpc,
10952 p->trapstack[i].tnpc, p->trapstack[i].tt);
10953- printk("TRAPLOG: TPC<%pS>\n", (void *) p->trapstack[i].tpc);
10954+ printk("TRAPLOG: TPC<%pA>\n", (void *) p->trapstack[i].tpc);
10955 }
10956 }
10957
10958@@ -99,6 +99,12 @@ void bad_trap(struct pt_regs *regs, long lvl)
10959
10960 lvl -= 0x100;
10961 if (regs->tstate & TSTATE_PRIV) {
10962+
10963+#ifdef CONFIG_PAX_REFCOUNT
10964+ if (lvl == 6)
10965+ pax_report_refcount_overflow(regs);
10966+#endif
10967+
10968 sprintf(buffer, "Kernel bad sw trap %lx", lvl);
10969 die_if_kernel(buffer, regs);
10970 }
10971@@ -117,11 +123,16 @@ void bad_trap(struct pt_regs *regs, long lvl)
10972 void bad_trap_tl1(struct pt_regs *regs, long lvl)
10973 {
10974 char buffer[32];
10975-
10976+
10977 if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
10978 0, lvl, SIGTRAP) == NOTIFY_STOP)
10979 return;
10980
10981+#ifdef CONFIG_PAX_REFCOUNT
10982+ if (lvl == 6)
10983+ pax_report_refcount_overflow(regs);
10984+#endif
10985+
10986 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
10987
10988 sprintf (buffer, "Bad trap %lx at tl>0", lvl);
10989@@ -1151,7 +1162,7 @@ static void cheetah_log_errors(struct pt_regs *regs, struct cheetah_err_info *in
10990 regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate);
10991 printk("%s" "ERROR(%d): ",
10992 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id());
10993- printk("TPC<%pS>\n", (void *) regs->tpc);
10994+ printk("TPC<%pA>\n", (void *) regs->tpc);
10995 printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
10996 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
10997 (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
10998@@ -1758,7 +1769,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
10999 smp_processor_id(),
11000 (type & 0x1) ? 'I' : 'D',
11001 regs->tpc);
11002- printk(KERN_EMERG "TPC<%pS>\n", (void *) regs->tpc);
11003+ printk(KERN_EMERG "TPC<%pA>\n", (void *) regs->tpc);
11004 panic("Irrecoverable Cheetah+ parity error.");
11005 }
11006
11007@@ -1766,7 +1777,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
11008 smp_processor_id(),
11009 (type & 0x1) ? 'I' : 'D',
11010 regs->tpc);
11011- printk(KERN_WARNING "TPC<%pS>\n", (void *) regs->tpc);
11012+ printk(KERN_WARNING "TPC<%pA>\n", (void *) regs->tpc);
11013 }
11014
11015 struct sun4v_error_entry {
11016@@ -1839,8 +1850,8 @@ struct sun4v_error_entry {
11017 /*0x38*/u64 reserved_5;
11018 };
11019
11020-static atomic_t sun4v_resum_oflow_cnt = ATOMIC_INIT(0);
11021-static atomic_t sun4v_nonresum_oflow_cnt = ATOMIC_INIT(0);
11022+static atomic_unchecked_t sun4v_resum_oflow_cnt = ATOMIC_INIT(0);
11023+static atomic_unchecked_t sun4v_nonresum_oflow_cnt = ATOMIC_INIT(0);
11024
11025 static const char *sun4v_err_type_to_str(u8 type)
11026 {
11027@@ -1932,7 +1943,7 @@ static void sun4v_report_real_raddr(const char *pfx, struct pt_regs *regs)
11028 }
11029
11030 static void sun4v_log_error(struct pt_regs *regs, struct sun4v_error_entry *ent,
11031- int cpu, const char *pfx, atomic_t *ocnt)
11032+ int cpu, const char *pfx, atomic_unchecked_t *ocnt)
11033 {
11034 u64 *raw_ptr = (u64 *) ent;
11035 u32 attrs;
11036@@ -1990,8 +2001,8 @@ static void sun4v_log_error(struct pt_regs *regs, struct sun4v_error_entry *ent,
11037
11038 show_regs(regs);
11039
11040- if ((cnt = atomic_read(ocnt)) != 0) {
11041- atomic_set(ocnt, 0);
11042+ if ((cnt = atomic_read_unchecked(ocnt)) != 0) {
11043+ atomic_set_unchecked(ocnt, 0);
11044 wmb();
11045 printk("%s: Queue overflowed %d times.\n",
11046 pfx, cnt);
11047@@ -2048,7 +2059,7 @@ out:
11048 */
11049 void sun4v_resum_overflow(struct pt_regs *regs)
11050 {
11051- atomic_inc(&sun4v_resum_oflow_cnt);
11052+ atomic_inc_unchecked(&sun4v_resum_oflow_cnt);
11053 }
11054
11055 /* We run with %pil set to PIL_NORMAL_MAX and PSTATE_IE enabled in %pstate.
11056@@ -2101,7 +2112,7 @@ void sun4v_nonresum_overflow(struct pt_regs *regs)
11057 /* XXX Actually even this can make not that much sense. Perhaps
11058 * XXX we should just pull the plug and panic directly from here?
11059 */
11060- atomic_inc(&sun4v_nonresum_oflow_cnt);
11061+ atomic_inc_unchecked(&sun4v_nonresum_oflow_cnt);
11062 }
11063
11064 static void sun4v_tlb_error(struct pt_regs *regs)
11065@@ -2120,9 +2131,9 @@ void sun4v_itlb_error_report(struct pt_regs *regs, int tl)
11066
11067 printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
11068 regs->tpc, tl);
11069- printk(KERN_EMERG "SUN4V-ITLB: TPC<%pS>\n", (void *) regs->tpc);
11070+ printk(KERN_EMERG "SUN4V-ITLB: TPC<%pA>\n", (void *) regs->tpc);
11071 printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
11072- printk(KERN_EMERG "SUN4V-ITLB: O7<%pS>\n",
11073+ printk(KERN_EMERG "SUN4V-ITLB: O7<%pA>\n",
11074 (void *) regs->u_regs[UREG_I7]);
11075 printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] "
11076 "pte[%lx] error[%lx]\n",
11077@@ -2143,9 +2154,9 @@ void sun4v_dtlb_error_report(struct pt_regs *regs, int tl)
11078
11079 printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
11080 regs->tpc, tl);
11081- printk(KERN_EMERG "SUN4V-DTLB: TPC<%pS>\n", (void *) regs->tpc);
11082+ printk(KERN_EMERG "SUN4V-DTLB: TPC<%pA>\n", (void *) regs->tpc);
11083 printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
11084- printk(KERN_EMERG "SUN4V-DTLB: O7<%pS>\n",
11085+ printk(KERN_EMERG "SUN4V-DTLB: O7<%pA>\n",
11086 (void *) regs->u_regs[UREG_I7]);
11087 printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] "
11088 "pte[%lx] error[%lx]\n",
11089@@ -2362,13 +2373,13 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
11090 fp = (unsigned long)sf->fp + STACK_BIAS;
11091 }
11092
11093- printk(" [%016lx] %pS\n", pc, (void *) pc);
11094+ printk(" [%016lx] %pA\n", pc, (void *) pc);
11095 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
11096 if ((pc + 8UL) == (unsigned long) &return_to_handler) {
11097 int index = tsk->curr_ret_stack;
11098 if (tsk->ret_stack && index >= graph) {
11099 pc = tsk->ret_stack[index - graph].ret;
11100- printk(" [%016lx] %pS\n", pc, (void *) pc);
11101+ printk(" [%016lx] %pA\n", pc, (void *) pc);
11102 graph++;
11103 }
11104 }
11105@@ -2386,6 +2397,8 @@ static inline struct reg_window *kernel_stack_up(struct reg_window *rw)
11106 return (struct reg_window *) (fp + STACK_BIAS);
11107 }
11108
11109+extern void gr_handle_kernel_exploit(void);
11110+
11111 void __noreturn die_if_kernel(char *str, struct pt_regs *regs)
11112 {
11113 static int die_counter;
11114@@ -2414,7 +2427,7 @@ void __noreturn die_if_kernel(char *str, struct pt_regs *regs)
11115 while (rw &&
11116 count++ < 30 &&
11117 kstack_valid(tp, (unsigned long) rw)) {
11118- printk("Caller[%016lx]: %pS\n", rw->ins[7],
11119+ printk("Caller[%016lx]: %pA\n", rw->ins[7],
11120 (void *) rw->ins[7]);
11121
11122 rw = kernel_stack_up(rw);
11123@@ -2427,8 +2440,10 @@ void __noreturn die_if_kernel(char *str, struct pt_regs *regs)
11124 }
11125 user_instruction_dump ((unsigned int __user *) regs->tpc);
11126 }
11127- if (regs->tstate & TSTATE_PRIV)
11128+ if (regs->tstate & TSTATE_PRIV) {
11129+ gr_handle_kernel_exploit();
11130 do_exit(SIGKILL);
11131+ }
11132 do_exit(SIGSEGV);
11133 }
11134 EXPORT_SYMBOL(die_if_kernel);
11135diff --git a/arch/sparc/kernel/unaligned_64.c b/arch/sparc/kernel/unaligned_64.c
11136index 62098a8..547ab2c 100644
11137--- a/arch/sparc/kernel/unaligned_64.c
11138+++ b/arch/sparc/kernel/unaligned_64.c
11139@@ -297,7 +297,7 @@ static void log_unaligned(struct pt_regs *regs)
11140 static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);
11141
11142 if (__ratelimit(&ratelimit)) {
11143- printk("Kernel unaligned access at TPC[%lx] %pS\n",
11144+ printk("Kernel unaligned access at TPC[%lx] %pA\n",
11145 regs->tpc, (void *) regs->tpc);
11146 }
11147 }
11148diff --git a/arch/sparc/lib/Makefile b/arch/sparc/lib/Makefile
11149index 3269b02..64f5231 100644
11150--- a/arch/sparc/lib/Makefile
11151+++ b/arch/sparc/lib/Makefile
11152@@ -2,7 +2,7 @@
11153 #
11154
11155 asflags-y := -ansi -DST_DIV0=0x02
11156-ccflags-y := -Werror
11157+#ccflags-y := -Werror
11158
11159 lib-$(CONFIG_SPARC32) += ashrdi3.o
11160 lib-$(CONFIG_SPARC32) += memcpy.o memset.o
11161diff --git a/arch/sparc/lib/atomic_64.S b/arch/sparc/lib/atomic_64.S
11162index 05dac43..76f8ed4 100644
11163--- a/arch/sparc/lib/atomic_64.S
11164+++ b/arch/sparc/lib/atomic_64.S
11165@@ -15,11 +15,22 @@
11166 * a value and does the barriers.
11167 */
11168
11169-#define ATOMIC_OP(op) \
11170-ENTRY(atomic_##op) /* %o0 = increment, %o1 = atomic_ptr */ \
11171+#ifdef CONFIG_PAX_REFCOUNT
11172+#define __REFCOUNT_OP(op) op##cc
11173+#define __OVERFLOW_IOP tvs %icc, 6;
11174+#define __OVERFLOW_XOP tvs %xcc, 6;
11175+#else
11176+#define __REFCOUNT_OP(op) op
11177+#define __OVERFLOW_IOP
11178+#define __OVERFLOW_XOP
11179+#endif
11180+
11181+#define __ATOMIC_OP(op, suffix, asm_op, post_op) \
11182+ENTRY(atomic_##op##suffix) /* %o0 = increment, %o1 = atomic_ptr */ \
11183 BACKOFF_SETUP(%o2); \
11184 1: lduw [%o1], %g1; \
11185- op %g1, %o0, %g7; \
11186+ asm_op %g1, %o0, %g7; \
11187+ post_op \
11188 cas [%o1], %g1, %g7; \
11189 cmp %g1, %g7; \
11190 bne,pn %icc, BACKOFF_LABEL(2f, 1b); \
11191@@ -29,11 +40,15 @@ ENTRY(atomic_##op) /* %o0 = increment, %o1 = atomic_ptr */ \
11192 2: BACKOFF_SPIN(%o2, %o3, 1b); \
11193 ENDPROC(atomic_##op); \
11194
11195-#define ATOMIC_OP_RETURN(op) \
11196-ENTRY(atomic_##op##_return) /* %o0 = increment, %o1 = atomic_ptr */ \
11197+#define ATOMIC_OP(op) __ATOMIC_OP(op, , op, ) \
11198+ __ATOMIC_OP(op, _unchecked, __REFCOUNT_OP(op), __OVERFLOW_IOP)
11199+
11200+#define __ATOMIC_OP_RETURN(op, suffix, asm_op, post_op) \
11201+ENTRY(atomic_##op##_return##suffix) /* %o0 = increment, %o1 = atomic_ptr */\
11202 BACKOFF_SETUP(%o2); \
11203 1: lduw [%o1], %g1; \
11204- op %g1, %o0, %g7; \
11205+ asm_op %g1, %o0, %g7; \
11206+ post_op \
11207 cas [%o1], %g1, %g7; \
11208 cmp %g1, %g7; \
11209 bne,pn %icc, BACKOFF_LABEL(2f, 1b); \
11210@@ -43,6 +58,9 @@ ENTRY(atomic_##op##_return) /* %o0 = increment, %o1 = atomic_ptr */ \
11211 2: BACKOFF_SPIN(%o2, %o3, 1b); \
11212 ENDPROC(atomic_##op##_return);
11213
11214+#define ATOMIC_OP_RETURN(op) __ATOMIC_OP_RETURN(op, , op, ) \
11215+ __ATOMIC_OP_RETURN(op, _unchecked, __REFCOUNT_OP(op), __OVERFLOW_IOP)
11216+
11217 #define ATOMIC_OPS(op) ATOMIC_OP(op) ATOMIC_OP_RETURN(op)
11218
11219 ATOMIC_OPS(add)
11220@@ -50,13 +68,16 @@ ATOMIC_OPS(sub)
11221
11222 #undef ATOMIC_OPS
11223 #undef ATOMIC_OP_RETURN
11224+#undef __ATOMIC_OP_RETURN
11225 #undef ATOMIC_OP
11226+#undef __ATOMIC_OP
11227
11228-#define ATOMIC64_OP(op) \
11229-ENTRY(atomic64_##op) /* %o0 = increment, %o1 = atomic_ptr */ \
11230+#define __ATOMIC64_OP(op, suffix, asm_op, post_op) \
11231+ENTRY(atomic64_##op##suffix) /* %o0 = increment, %o1 = atomic_ptr */ \
11232 BACKOFF_SETUP(%o2); \
11233 1: ldx [%o1], %g1; \
11234- op %g1, %o0, %g7; \
11235+ asm_op %g1, %o0, %g7; \
11236+ post_op \
11237 casx [%o1], %g1, %g7; \
11238 cmp %g1, %g7; \
11239 bne,pn %xcc, BACKOFF_LABEL(2f, 1b); \
11240@@ -66,11 +87,15 @@ ENTRY(atomic64_##op) /* %o0 = increment, %o1 = atomic_ptr */ \
11241 2: BACKOFF_SPIN(%o2, %o3, 1b); \
11242 ENDPROC(atomic64_##op); \
11243
11244-#define ATOMIC64_OP_RETURN(op) \
11245-ENTRY(atomic64_##op##_return) /* %o0 = increment, %o1 = atomic_ptr */ \
11246+#define ATOMIC64_OP(op) __ATOMIC64_OP(op, , op, ) \
11247+ __ATOMIC64_OP(op, _unchecked, __REFCOUNT_OP(op), __OVERFLOW_XOP)
11248+
11249+#define __ATOMIC64_OP_RETURN(op, suffix, asm_op, post_op) \
11250+ENTRY(atomic64_##op##_return##suffix) /* %o0 = increment, %o1 = atomic_ptr */\
11251 BACKOFF_SETUP(%o2); \
11252 1: ldx [%o1], %g1; \
11253- op %g1, %o0, %g7; \
11254+ asm_op %g1, %o0, %g7; \
11255+ post_op \
11256 casx [%o1], %g1, %g7; \
11257 cmp %g1, %g7; \
11258 bne,pn %xcc, BACKOFF_LABEL(2f, 1b); \
11259@@ -80,6 +105,9 @@ ENTRY(atomic64_##op##_return) /* %o0 = increment, %o1 = atomic_ptr */ \
11260 2: BACKOFF_SPIN(%o2, %o3, 1b); \
11261 ENDPROC(atomic64_##op##_return);
11262
11263+#define ATOMIC64_OP_RETURN(op) __ATOMIC64_OP_RETURN(op, , op, ) \
11264+i __ATOMIC64_OP_RETURN(op, _unchecked, __REFCOUNT_OP(op), __OVERFLOW_XOP)
11265+
11266 #define ATOMIC64_OPS(op) ATOMIC64_OP(op) ATOMIC64_OP_RETURN(op)
11267
11268 ATOMIC64_OPS(add)
11269@@ -87,7 +115,12 @@ ATOMIC64_OPS(sub)
11270
11271 #undef ATOMIC64_OPS
11272 #undef ATOMIC64_OP_RETURN
11273+#undef __ATOMIC64_OP_RETURN
11274 #undef ATOMIC64_OP
11275+#undef __ATOMIC64_OP
11276+#undef __OVERFLOW_XOP
11277+#undef __OVERFLOW_IOP
11278+#undef __REFCOUNT_OP
11279
11280 ENTRY(atomic64_dec_if_positive) /* %o0 = atomic_ptr */
11281 BACKOFF_SETUP(%o2)
11282diff --git a/arch/sparc/lib/ksyms.c b/arch/sparc/lib/ksyms.c
11283index 1d649a9..fbc5bfc 100644
11284--- a/arch/sparc/lib/ksyms.c
11285+++ b/arch/sparc/lib/ksyms.c
11286@@ -101,7 +101,9 @@ EXPORT_SYMBOL(__clear_user);
11287 /* Atomic counter implementation. */
11288 #define ATOMIC_OP(op) \
11289 EXPORT_SYMBOL(atomic_##op); \
11290-EXPORT_SYMBOL(atomic64_##op);
11291+EXPORT_SYMBOL(atomic_##op##_unchecked); \
11292+EXPORT_SYMBOL(atomic64_##op); \
11293+EXPORT_SYMBOL(atomic64_##op##_unchecked);
11294
11295 #define ATOMIC_OP_RETURN(op) \
11296 EXPORT_SYMBOL(atomic_##op##_return); \
11297@@ -110,6 +112,8 @@ EXPORT_SYMBOL(atomic64_##op##_return);
11298 #define ATOMIC_OPS(op) ATOMIC_OP(op) ATOMIC_OP_RETURN(op)
11299
11300 ATOMIC_OPS(add)
11301+EXPORT_SYMBOL(atomic_add_ret_unchecked);
11302+EXPORT_SYMBOL(atomic64_add_ret_unchecked);
11303 ATOMIC_OPS(sub)
11304
11305 #undef ATOMIC_OPS
11306diff --git a/arch/sparc/mm/Makefile b/arch/sparc/mm/Makefile
11307index 30c3ecc..736f015 100644
11308--- a/arch/sparc/mm/Makefile
11309+++ b/arch/sparc/mm/Makefile
11310@@ -2,7 +2,7 @@
11311 #
11312
11313 asflags-y := -ansi
11314-ccflags-y := -Werror
11315+#ccflags-y := -Werror
11316
11317 obj-$(CONFIG_SPARC64) += ultra.o tlb.o tsb.o gup.o
11318 obj-y += fault_$(BITS).o
11319diff --git a/arch/sparc/mm/fault_32.c b/arch/sparc/mm/fault_32.c
11320index 908e8c1..1524793 100644
11321--- a/arch/sparc/mm/fault_32.c
11322+++ b/arch/sparc/mm/fault_32.c
11323@@ -21,6 +21,9 @@
11324 #include <linux/perf_event.h>
11325 #include <linux/interrupt.h>
11326 #include <linux/kdebug.h>
11327+#include <linux/slab.h>
11328+#include <linux/pagemap.h>
11329+#include <linux/compiler.h>
11330
11331 #include <asm/page.h>
11332 #include <asm/pgtable.h>
11333@@ -156,6 +159,277 @@ static unsigned long compute_si_addr(struct pt_regs *regs, int text_fault)
11334 return safe_compute_effective_address(regs, insn);
11335 }
11336
11337+#ifdef CONFIG_PAX_PAGEEXEC
11338+#ifdef CONFIG_PAX_DLRESOLVE
11339+static void pax_emuplt_close(struct vm_area_struct *vma)
11340+{
11341+ vma->vm_mm->call_dl_resolve = 0UL;
11342+}
11343+
11344+static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
11345+{
11346+ unsigned int *kaddr;
11347+
11348+ vmf->page = alloc_page(GFP_HIGHUSER);
11349+ if (!vmf->page)
11350+ return VM_FAULT_OOM;
11351+
11352+ kaddr = kmap(vmf->page);
11353+ memset(kaddr, 0, PAGE_SIZE);
11354+ kaddr[0] = 0x9DE3BFA8U; /* save */
11355+ flush_dcache_page(vmf->page);
11356+ kunmap(vmf->page);
11357+ return VM_FAULT_MAJOR;
11358+}
11359+
11360+static const struct vm_operations_struct pax_vm_ops = {
11361+ .close = pax_emuplt_close,
11362+ .fault = pax_emuplt_fault
11363+};
11364+
11365+static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
11366+{
11367+ int ret;
11368+
11369+ INIT_LIST_HEAD(&vma->anon_vma_chain);
11370+ vma->vm_mm = current->mm;
11371+ vma->vm_start = addr;
11372+ vma->vm_end = addr + PAGE_SIZE;
11373+ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
11374+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
11375+ vma->vm_ops = &pax_vm_ops;
11376+
11377+ ret = insert_vm_struct(current->mm, vma);
11378+ if (ret)
11379+ return ret;
11380+
11381+ ++current->mm->total_vm;
11382+ return 0;
11383+}
11384+#endif
11385+
11386+/*
11387+ * PaX: decide what to do with offenders (regs->pc = fault address)
11388+ *
11389+ * returns 1 when task should be killed
11390+ * 2 when patched PLT trampoline was detected
11391+ * 3 when unpatched PLT trampoline was detected
11392+ */
11393+static int pax_handle_fetch_fault(struct pt_regs *regs)
11394+{
11395+
11396+#ifdef CONFIG_PAX_EMUPLT
11397+ int err;
11398+
11399+ do { /* PaX: patched PLT emulation #1 */
11400+ unsigned int sethi1, sethi2, jmpl;
11401+
11402+ err = get_user(sethi1, (unsigned int *)regs->pc);
11403+ err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
11404+ err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
11405+
11406+ if (err)
11407+ break;
11408+
11409+ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
11410+ (sethi2 & 0xFFC00000U) == 0x03000000U &&
11411+ (jmpl & 0xFFFFE000U) == 0x81C06000U)
11412+ {
11413+ unsigned int addr;
11414+
11415+ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
11416+ addr = regs->u_regs[UREG_G1];
11417+ addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
11418+ regs->pc = addr;
11419+ regs->npc = addr+4;
11420+ return 2;
11421+ }
11422+ } while (0);
11423+
11424+ do { /* PaX: patched PLT emulation #2 */
11425+ unsigned int ba;
11426+
11427+ err = get_user(ba, (unsigned int *)regs->pc);
11428+
11429+ if (err)
11430+ break;
11431+
11432+ if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
11433+ unsigned int addr;
11434+
11435+ if ((ba & 0xFFC00000U) == 0x30800000U)
11436+ addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
11437+ else
11438+ addr = regs->pc + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
11439+ regs->pc = addr;
11440+ regs->npc = addr+4;
11441+ return 2;
11442+ }
11443+ } while (0);
11444+
11445+ do { /* PaX: patched PLT emulation #3 */
11446+ unsigned int sethi, bajmpl, nop;
11447+
11448+ err = get_user(sethi, (unsigned int *)regs->pc);
11449+ err |= get_user(bajmpl, (unsigned int *)(regs->pc+4));
11450+ err |= get_user(nop, (unsigned int *)(regs->pc+8));
11451+
11452+ if (err)
11453+ break;
11454+
11455+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
11456+ ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
11457+ nop == 0x01000000U)
11458+ {
11459+ unsigned int addr;
11460+
11461+ addr = (sethi & 0x003FFFFFU) << 10;
11462+ regs->u_regs[UREG_G1] = addr;
11463+ if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
11464+ addr += (((bajmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
11465+ else
11466+ addr = regs->pc + ((((bajmpl | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
11467+ regs->pc = addr;
11468+ regs->npc = addr+4;
11469+ return 2;
11470+ }
11471+ } while (0);
11472+
11473+ do { /* PaX: unpatched PLT emulation step 1 */
11474+ unsigned int sethi, ba, nop;
11475+
11476+ err = get_user(sethi, (unsigned int *)regs->pc);
11477+ err |= get_user(ba, (unsigned int *)(regs->pc+4));
11478+ err |= get_user(nop, (unsigned int *)(regs->pc+8));
11479+
11480+ if (err)
11481+ break;
11482+
11483+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
11484+ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
11485+ nop == 0x01000000U)
11486+ {
11487+ unsigned int addr, save, call;
11488+
11489+ if ((ba & 0xFFC00000U) == 0x30800000U)
11490+ addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
11491+ else
11492+ addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
11493+
11494+ err = get_user(save, (unsigned int *)addr);
11495+ err |= get_user(call, (unsigned int *)(addr+4));
11496+ err |= get_user(nop, (unsigned int *)(addr+8));
11497+ if (err)
11498+ break;
11499+
11500+#ifdef CONFIG_PAX_DLRESOLVE
11501+ if (save == 0x9DE3BFA8U &&
11502+ (call & 0xC0000000U) == 0x40000000U &&
11503+ nop == 0x01000000U)
11504+ {
11505+ struct vm_area_struct *vma;
11506+ unsigned long call_dl_resolve;
11507+
11508+ down_read(&current->mm->mmap_sem);
11509+ call_dl_resolve = current->mm->call_dl_resolve;
11510+ up_read(&current->mm->mmap_sem);
11511+ if (likely(call_dl_resolve))
11512+ goto emulate;
11513+
11514+ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
11515+
11516+ down_write(&current->mm->mmap_sem);
11517+ if (current->mm->call_dl_resolve) {
11518+ call_dl_resolve = current->mm->call_dl_resolve;
11519+ up_write(&current->mm->mmap_sem);
11520+ if (vma)
11521+ kmem_cache_free(vm_area_cachep, vma);
11522+ goto emulate;
11523+ }
11524+
11525+ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
11526+ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
11527+ up_write(&current->mm->mmap_sem);
11528+ if (vma)
11529+ kmem_cache_free(vm_area_cachep, vma);
11530+ return 1;
11531+ }
11532+
11533+ if (pax_insert_vma(vma, call_dl_resolve)) {
11534+ up_write(&current->mm->mmap_sem);
11535+ kmem_cache_free(vm_area_cachep, vma);
11536+ return 1;
11537+ }
11538+
11539+ current->mm->call_dl_resolve = call_dl_resolve;
11540+ up_write(&current->mm->mmap_sem);
11541+
11542+emulate:
11543+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11544+ regs->pc = call_dl_resolve;
11545+ regs->npc = addr+4;
11546+ return 3;
11547+ }
11548+#endif
11549+
11550+ /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
11551+ if ((save & 0xFFC00000U) == 0x05000000U &&
11552+ (call & 0xFFFFE000U) == 0x85C0A000U &&
11553+ nop == 0x01000000U)
11554+ {
11555+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11556+ regs->u_regs[UREG_G2] = addr + 4;
11557+ addr = (save & 0x003FFFFFU) << 10;
11558+ addr += (((call | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
11559+ regs->pc = addr;
11560+ regs->npc = addr+4;
11561+ return 3;
11562+ }
11563+ }
11564+ } while (0);
11565+
11566+ do { /* PaX: unpatched PLT emulation step 2 */
11567+ unsigned int save, call, nop;
11568+
11569+ err = get_user(save, (unsigned int *)(regs->pc-4));
11570+ err |= get_user(call, (unsigned int *)regs->pc);
11571+ err |= get_user(nop, (unsigned int *)(regs->pc+4));
11572+ if (err)
11573+ break;
11574+
11575+ if (save == 0x9DE3BFA8U &&
11576+ (call & 0xC0000000U) == 0x40000000U &&
11577+ nop == 0x01000000U)
11578+ {
11579+ unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
11580+
11581+ regs->u_regs[UREG_RETPC] = regs->pc;
11582+ regs->pc = dl_resolve;
11583+ regs->npc = dl_resolve+4;
11584+ return 3;
11585+ }
11586+ } while (0);
11587+#endif
11588+
11589+ return 1;
11590+}
11591+
11592+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
11593+{
11594+ unsigned long i;
11595+
11596+ printk(KERN_ERR "PAX: bytes at PC: ");
11597+ for (i = 0; i < 8; i++) {
11598+ unsigned int c;
11599+ if (get_user(c, (unsigned int *)pc+i))
11600+ printk(KERN_CONT "???????? ");
11601+ else
11602+ printk(KERN_CONT "%08x ", c);
11603+ }
11604+ printk("\n");
11605+}
11606+#endif
11607+
11608 static noinline void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
11609 int text_fault)
11610 {
11611@@ -226,6 +500,24 @@ good_area:
11612 if (!(vma->vm_flags & VM_WRITE))
11613 goto bad_area;
11614 } else {
11615+
11616+#ifdef CONFIG_PAX_PAGEEXEC
11617+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
11618+ up_read(&mm->mmap_sem);
11619+ switch (pax_handle_fetch_fault(regs)) {
11620+
11621+#ifdef CONFIG_PAX_EMUPLT
11622+ case 2:
11623+ case 3:
11624+ return;
11625+#endif
11626+
11627+ }
11628+ pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
11629+ do_group_exit(SIGKILL);
11630+ }
11631+#endif
11632+
11633 /* Allow reads even for write-only mappings */
11634 if (!(vma->vm_flags & (VM_READ | VM_EXEC)))
11635 goto bad_area;
11636diff --git a/arch/sparc/mm/fault_64.c b/arch/sparc/mm/fault_64.c
11637index 18fcd71..e4fe821 100644
11638--- a/arch/sparc/mm/fault_64.c
11639+++ b/arch/sparc/mm/fault_64.c
11640@@ -22,6 +22,9 @@
11641 #include <linux/kdebug.h>
11642 #include <linux/percpu.h>
11643 #include <linux/context_tracking.h>
11644+#include <linux/slab.h>
11645+#include <linux/pagemap.h>
11646+#include <linux/compiler.h>
11647
11648 #include <asm/page.h>
11649 #include <asm/pgtable.h>
11650@@ -76,7 +79,7 @@ static void __kprobes bad_kernel_pc(struct pt_regs *regs, unsigned long vaddr)
11651 printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n",
11652 regs->tpc);
11653 printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]);
11654- printk("OOPS: RPC <%pS>\n", (void *) regs->u_regs[15]);
11655+ printk("OOPS: RPC <%pA>\n", (void *) regs->u_regs[15]);
11656 printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr);
11657 dump_stack();
11658 unhandled_fault(regs->tpc, current, regs);
11659@@ -279,6 +282,466 @@ static void noinline __kprobes bogus_32bit_fault_tpc(struct pt_regs *regs)
11660 show_regs(regs);
11661 }
11662
11663+#ifdef CONFIG_PAX_PAGEEXEC
11664+#ifdef CONFIG_PAX_DLRESOLVE
11665+static void pax_emuplt_close(struct vm_area_struct *vma)
11666+{
11667+ vma->vm_mm->call_dl_resolve = 0UL;
11668+}
11669+
11670+static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
11671+{
11672+ unsigned int *kaddr;
11673+
11674+ vmf->page = alloc_page(GFP_HIGHUSER);
11675+ if (!vmf->page)
11676+ return VM_FAULT_OOM;
11677+
11678+ kaddr = kmap(vmf->page);
11679+ memset(kaddr, 0, PAGE_SIZE);
11680+ kaddr[0] = 0x9DE3BFA8U; /* save */
11681+ flush_dcache_page(vmf->page);
11682+ kunmap(vmf->page);
11683+ return VM_FAULT_MAJOR;
11684+}
11685+
11686+static const struct vm_operations_struct pax_vm_ops = {
11687+ .close = pax_emuplt_close,
11688+ .fault = pax_emuplt_fault
11689+};
11690+
11691+static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
11692+{
11693+ int ret;
11694+
11695+ INIT_LIST_HEAD(&vma->anon_vma_chain);
11696+ vma->vm_mm = current->mm;
11697+ vma->vm_start = addr;
11698+ vma->vm_end = addr + PAGE_SIZE;
11699+ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
11700+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
11701+ vma->vm_ops = &pax_vm_ops;
11702+
11703+ ret = insert_vm_struct(current->mm, vma);
11704+ if (ret)
11705+ return ret;
11706+
11707+ ++current->mm->total_vm;
11708+ return 0;
11709+}
11710+#endif
11711+
11712+/*
11713+ * PaX: decide what to do with offenders (regs->tpc = fault address)
11714+ *
11715+ * returns 1 when task should be killed
11716+ * 2 when patched PLT trampoline was detected
11717+ * 3 when unpatched PLT trampoline was detected
11718+ */
11719+static int pax_handle_fetch_fault(struct pt_regs *regs)
11720+{
11721+
11722+#ifdef CONFIG_PAX_EMUPLT
11723+ int err;
11724+
11725+ do { /* PaX: patched PLT emulation #1 */
11726+ unsigned int sethi1, sethi2, jmpl;
11727+
11728+ err = get_user(sethi1, (unsigned int *)regs->tpc);
11729+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
11730+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
11731+
11732+ if (err)
11733+ break;
11734+
11735+ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
11736+ (sethi2 & 0xFFC00000U) == 0x03000000U &&
11737+ (jmpl & 0xFFFFE000U) == 0x81C06000U)
11738+ {
11739+ unsigned long addr;
11740+
11741+ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
11742+ addr = regs->u_regs[UREG_G1];
11743+ addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
11744+
11745+ if (test_thread_flag(TIF_32BIT))
11746+ addr &= 0xFFFFFFFFUL;
11747+
11748+ regs->tpc = addr;
11749+ regs->tnpc = addr+4;
11750+ return 2;
11751+ }
11752+ } while (0);
11753+
11754+ do { /* PaX: patched PLT emulation #2 */
11755+ unsigned int ba;
11756+
11757+ err = get_user(ba, (unsigned int *)regs->tpc);
11758+
11759+ if (err)
11760+ break;
11761+
11762+ if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
11763+ unsigned long addr;
11764+
11765+ if ((ba & 0xFFC00000U) == 0x30800000U)
11766+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
11767+ else
11768+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
11769+
11770+ if (test_thread_flag(TIF_32BIT))
11771+ addr &= 0xFFFFFFFFUL;
11772+
11773+ regs->tpc = addr;
11774+ regs->tnpc = addr+4;
11775+ return 2;
11776+ }
11777+ } while (0);
11778+
11779+ do { /* PaX: patched PLT emulation #3 */
11780+ unsigned int sethi, bajmpl, nop;
11781+
11782+ err = get_user(sethi, (unsigned int *)regs->tpc);
11783+ err |= get_user(bajmpl, (unsigned int *)(regs->tpc+4));
11784+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
11785+
11786+ if (err)
11787+ break;
11788+
11789+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
11790+ ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
11791+ nop == 0x01000000U)
11792+ {
11793+ unsigned long addr;
11794+
11795+ addr = (sethi & 0x003FFFFFU) << 10;
11796+ regs->u_regs[UREG_G1] = addr;
11797+ if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
11798+ addr += (((bajmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
11799+ else
11800+ addr = regs->tpc + ((((bajmpl | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
11801+
11802+ if (test_thread_flag(TIF_32BIT))
11803+ addr &= 0xFFFFFFFFUL;
11804+
11805+ regs->tpc = addr;
11806+ regs->tnpc = addr+4;
11807+ return 2;
11808+ }
11809+ } while (0);
11810+
11811+ do { /* PaX: patched PLT emulation #4 */
11812+ unsigned int sethi, mov1, call, mov2;
11813+
11814+ err = get_user(sethi, (unsigned int *)regs->tpc);
11815+ err |= get_user(mov1, (unsigned int *)(regs->tpc+4));
11816+ err |= get_user(call, (unsigned int *)(regs->tpc+8));
11817+ err |= get_user(mov2, (unsigned int *)(regs->tpc+12));
11818+
11819+ if (err)
11820+ break;
11821+
11822+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
11823+ mov1 == 0x8210000FU &&
11824+ (call & 0xC0000000U) == 0x40000000U &&
11825+ mov2 == 0x9E100001U)
11826+ {
11827+ unsigned long addr;
11828+
11829+ regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
11830+ addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
11831+
11832+ if (test_thread_flag(TIF_32BIT))
11833+ addr &= 0xFFFFFFFFUL;
11834+
11835+ regs->tpc = addr;
11836+ regs->tnpc = addr+4;
11837+ return 2;
11838+ }
11839+ } while (0);
11840+
11841+ do { /* PaX: patched PLT emulation #5 */
11842+ unsigned int sethi, sethi1, sethi2, or1, or2, sllx, jmpl, nop;
11843+
11844+ err = get_user(sethi, (unsigned int *)regs->tpc);
11845+ err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
11846+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
11847+ err |= get_user(or1, (unsigned int *)(regs->tpc+12));
11848+ err |= get_user(or2, (unsigned int *)(regs->tpc+16));
11849+ err |= get_user(sllx, (unsigned int *)(regs->tpc+20));
11850+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+24));
11851+ err |= get_user(nop, (unsigned int *)(regs->tpc+28));
11852+
11853+ if (err)
11854+ break;
11855+
11856+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
11857+ (sethi1 & 0xFFC00000U) == 0x03000000U &&
11858+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
11859+ (or1 & 0xFFFFE000U) == 0x82106000U &&
11860+ (or2 & 0xFFFFE000U) == 0x8A116000U &&
11861+ sllx == 0x83287020U &&
11862+ jmpl == 0x81C04005U &&
11863+ nop == 0x01000000U)
11864+ {
11865+ unsigned long addr;
11866+
11867+ regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
11868+ regs->u_regs[UREG_G1] <<= 32;
11869+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
11870+ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
11871+ regs->tpc = addr;
11872+ regs->tnpc = addr+4;
11873+ return 2;
11874+ }
11875+ } while (0);
11876+
11877+ do { /* PaX: patched PLT emulation #6 */
11878+ unsigned int sethi, sethi1, sethi2, sllx, or, jmpl, nop;
11879+
11880+ err = get_user(sethi, (unsigned int *)regs->tpc);
11881+ err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
11882+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
11883+ err |= get_user(sllx, (unsigned int *)(regs->tpc+12));
11884+ err |= get_user(or, (unsigned int *)(regs->tpc+16));
11885+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
11886+ err |= get_user(nop, (unsigned int *)(regs->tpc+24));
11887+
11888+ if (err)
11889+ break;
11890+
11891+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
11892+ (sethi1 & 0xFFC00000U) == 0x03000000U &&
11893+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
11894+ sllx == 0x83287020U &&
11895+ (or & 0xFFFFE000U) == 0x8A116000U &&
11896+ jmpl == 0x81C04005U &&
11897+ nop == 0x01000000U)
11898+ {
11899+ unsigned long addr;
11900+
11901+ regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
11902+ regs->u_regs[UREG_G1] <<= 32;
11903+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
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: unpatched PLT emulation step 1 */
11912+ unsigned int sethi, ba, nop;
11913+
11914+ err = get_user(sethi, (unsigned int *)regs->tpc);
11915+ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
11916+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
11917+
11918+ if (err)
11919+ break;
11920+
11921+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
11922+ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
11923+ nop == 0x01000000U)
11924+ {
11925+ unsigned long addr;
11926+ unsigned int save, call;
11927+ unsigned int sethi1, sethi2, or1, or2, sllx, add, jmpl;
11928+
11929+ if ((ba & 0xFFC00000U) == 0x30800000U)
11930+ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
11931+ else
11932+ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
11933+
11934+ if (test_thread_flag(TIF_32BIT))
11935+ addr &= 0xFFFFFFFFUL;
11936+
11937+ err = get_user(save, (unsigned int *)addr);
11938+ err |= get_user(call, (unsigned int *)(addr+4));
11939+ err |= get_user(nop, (unsigned int *)(addr+8));
11940+ if (err)
11941+ break;
11942+
11943+#ifdef CONFIG_PAX_DLRESOLVE
11944+ if (save == 0x9DE3BFA8U &&
11945+ (call & 0xC0000000U) == 0x40000000U &&
11946+ nop == 0x01000000U)
11947+ {
11948+ struct vm_area_struct *vma;
11949+ unsigned long call_dl_resolve;
11950+
11951+ down_read(&current->mm->mmap_sem);
11952+ call_dl_resolve = current->mm->call_dl_resolve;
11953+ up_read(&current->mm->mmap_sem);
11954+ if (likely(call_dl_resolve))
11955+ goto emulate;
11956+
11957+ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
11958+
11959+ down_write(&current->mm->mmap_sem);
11960+ if (current->mm->call_dl_resolve) {
11961+ call_dl_resolve = current->mm->call_dl_resolve;
11962+ up_write(&current->mm->mmap_sem);
11963+ if (vma)
11964+ kmem_cache_free(vm_area_cachep, vma);
11965+ goto emulate;
11966+ }
11967+
11968+ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
11969+ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
11970+ up_write(&current->mm->mmap_sem);
11971+ if (vma)
11972+ kmem_cache_free(vm_area_cachep, vma);
11973+ return 1;
11974+ }
11975+
11976+ if (pax_insert_vma(vma, call_dl_resolve)) {
11977+ up_write(&current->mm->mmap_sem);
11978+ kmem_cache_free(vm_area_cachep, vma);
11979+ return 1;
11980+ }
11981+
11982+ current->mm->call_dl_resolve = call_dl_resolve;
11983+ up_write(&current->mm->mmap_sem);
11984+
11985+emulate:
11986+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11987+ regs->tpc = call_dl_resolve;
11988+ regs->tnpc = addr+4;
11989+ return 3;
11990+ }
11991+#endif
11992+
11993+ /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
11994+ if ((save & 0xFFC00000U) == 0x05000000U &&
11995+ (call & 0xFFFFE000U) == 0x85C0A000U &&
11996+ nop == 0x01000000U)
11997+ {
11998+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11999+ regs->u_regs[UREG_G2] = addr + 4;
12000+ addr = (save & 0x003FFFFFU) << 10;
12001+ addr += (((call | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
12002+
12003+ if (test_thread_flag(TIF_32BIT))
12004+ addr &= 0xFFFFFFFFUL;
12005+
12006+ regs->tpc = addr;
12007+ regs->tnpc = addr+4;
12008+ return 3;
12009+ }
12010+
12011+ /* PaX: 64-bit PLT stub */
12012+ err = get_user(sethi1, (unsigned int *)addr);
12013+ err |= get_user(sethi2, (unsigned int *)(addr+4));
12014+ err |= get_user(or1, (unsigned int *)(addr+8));
12015+ err |= get_user(or2, (unsigned int *)(addr+12));
12016+ err |= get_user(sllx, (unsigned int *)(addr+16));
12017+ err |= get_user(add, (unsigned int *)(addr+20));
12018+ err |= get_user(jmpl, (unsigned int *)(addr+24));
12019+ err |= get_user(nop, (unsigned int *)(addr+28));
12020+ if (err)
12021+ break;
12022+
12023+ if ((sethi1 & 0xFFC00000U) == 0x09000000U &&
12024+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
12025+ (or1 & 0xFFFFE000U) == 0x88112000U &&
12026+ (or2 & 0xFFFFE000U) == 0x8A116000U &&
12027+ sllx == 0x89293020U &&
12028+ add == 0x8A010005U &&
12029+ jmpl == 0x89C14000U &&
12030+ nop == 0x01000000U)
12031+ {
12032+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
12033+ regs->u_regs[UREG_G4] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
12034+ regs->u_regs[UREG_G4] <<= 32;
12035+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
12036+ regs->u_regs[UREG_G5] += regs->u_regs[UREG_G4];
12037+ regs->u_regs[UREG_G4] = addr + 24;
12038+ addr = regs->u_regs[UREG_G5];
12039+ regs->tpc = addr;
12040+ regs->tnpc = addr+4;
12041+ return 3;
12042+ }
12043+ }
12044+ } while (0);
12045+
12046+#ifdef CONFIG_PAX_DLRESOLVE
12047+ do { /* PaX: unpatched PLT emulation step 2 */
12048+ unsigned int save, call, nop;
12049+
12050+ err = get_user(save, (unsigned int *)(regs->tpc-4));
12051+ err |= get_user(call, (unsigned int *)regs->tpc);
12052+ err |= get_user(nop, (unsigned int *)(regs->tpc+4));
12053+ if (err)
12054+ break;
12055+
12056+ if (save == 0x9DE3BFA8U &&
12057+ (call & 0xC0000000U) == 0x40000000U &&
12058+ nop == 0x01000000U)
12059+ {
12060+ unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
12061+
12062+ if (test_thread_flag(TIF_32BIT))
12063+ dl_resolve &= 0xFFFFFFFFUL;
12064+
12065+ regs->u_regs[UREG_RETPC] = regs->tpc;
12066+ regs->tpc = dl_resolve;
12067+ regs->tnpc = dl_resolve+4;
12068+ return 3;
12069+ }
12070+ } while (0);
12071+#endif
12072+
12073+ do { /* PaX: patched PLT emulation #7, must be AFTER the unpatched PLT emulation */
12074+ unsigned int sethi, ba, nop;
12075+
12076+ err = get_user(sethi, (unsigned int *)regs->tpc);
12077+ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
12078+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
12079+
12080+ if (err)
12081+ break;
12082+
12083+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
12084+ (ba & 0xFFF00000U) == 0x30600000U &&
12085+ nop == 0x01000000U)
12086+ {
12087+ unsigned long addr;
12088+
12089+ addr = (sethi & 0x003FFFFFU) << 10;
12090+ regs->u_regs[UREG_G1] = addr;
12091+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
12092+
12093+ if (test_thread_flag(TIF_32BIT))
12094+ addr &= 0xFFFFFFFFUL;
12095+
12096+ regs->tpc = addr;
12097+ regs->tnpc = addr+4;
12098+ return 2;
12099+ }
12100+ } while (0);
12101+
12102+#endif
12103+
12104+ return 1;
12105+}
12106+
12107+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
12108+{
12109+ unsigned long i;
12110+
12111+ printk(KERN_ERR "PAX: bytes at PC: ");
12112+ for (i = 0; i < 8; i++) {
12113+ unsigned int c;
12114+ if (get_user(c, (unsigned int *)pc+i))
12115+ printk(KERN_CONT "???????? ");
12116+ else
12117+ printk(KERN_CONT "%08x ", c);
12118+ }
12119+ printk("\n");
12120+}
12121+#endif
12122+
12123 asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
12124 {
12125 enum ctx_state prev_state = exception_enter();
12126@@ -353,6 +816,29 @@ retry:
12127 if (!vma)
12128 goto bad_area;
12129
12130+#ifdef CONFIG_PAX_PAGEEXEC
12131+ /* PaX: detect ITLB misses on non-exec pages */
12132+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
12133+ !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
12134+ {
12135+ if (address != regs->tpc)
12136+ goto good_area;
12137+
12138+ up_read(&mm->mmap_sem);
12139+ switch (pax_handle_fetch_fault(regs)) {
12140+
12141+#ifdef CONFIG_PAX_EMUPLT
12142+ case 2:
12143+ case 3:
12144+ return;
12145+#endif
12146+
12147+ }
12148+ pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
12149+ do_group_exit(SIGKILL);
12150+ }
12151+#endif
12152+
12153 /* Pure DTLB misses do not tell us whether the fault causing
12154 * load/store/atomic was a write or not, it only says that there
12155 * was no match. So in such a case we (carefully) read the
12156diff --git a/arch/sparc/mm/hugetlbpage.c b/arch/sparc/mm/hugetlbpage.c
12157index d329537..2c3746a 100644
12158--- a/arch/sparc/mm/hugetlbpage.c
12159+++ b/arch/sparc/mm/hugetlbpage.c
12160@@ -25,8 +25,10 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
12161 unsigned long addr,
12162 unsigned long len,
12163 unsigned long pgoff,
12164- unsigned long flags)
12165+ unsigned long flags,
12166+ unsigned long offset)
12167 {
12168+ struct mm_struct *mm = current->mm;
12169 unsigned long task_size = TASK_SIZE;
12170 struct vm_unmapped_area_info info;
12171
12172@@ -35,15 +37,22 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
12173
12174 info.flags = 0;
12175 info.length = len;
12176- info.low_limit = TASK_UNMAPPED_BASE;
12177+ info.low_limit = mm->mmap_base;
12178 info.high_limit = min(task_size, VA_EXCLUDE_START);
12179 info.align_mask = PAGE_MASK & ~HPAGE_MASK;
12180 info.align_offset = 0;
12181+ info.threadstack_offset = offset;
12182 addr = vm_unmapped_area(&info);
12183
12184 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
12185 VM_BUG_ON(addr != -ENOMEM);
12186 info.low_limit = VA_EXCLUDE_END;
12187+
12188+#ifdef CONFIG_PAX_RANDMMAP
12189+ if (mm->pax_flags & MF_PAX_RANDMMAP)
12190+ info.low_limit += mm->delta_mmap;
12191+#endif
12192+
12193 info.high_limit = task_size;
12194 addr = vm_unmapped_area(&info);
12195 }
12196@@ -55,7 +64,8 @@ static unsigned long
12197 hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
12198 const unsigned long len,
12199 const unsigned long pgoff,
12200- const unsigned long flags)
12201+ const unsigned long flags,
12202+ const unsigned long offset)
12203 {
12204 struct mm_struct *mm = current->mm;
12205 unsigned long addr = addr0;
12206@@ -70,6 +80,7 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
12207 info.high_limit = mm->mmap_base;
12208 info.align_mask = PAGE_MASK & ~HPAGE_MASK;
12209 info.align_offset = 0;
12210+ info.threadstack_offset = offset;
12211 addr = vm_unmapped_area(&info);
12212
12213 /*
12214@@ -82,6 +93,12 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
12215 VM_BUG_ON(addr != -ENOMEM);
12216 info.flags = 0;
12217 info.low_limit = TASK_UNMAPPED_BASE;
12218+
12219+#ifdef CONFIG_PAX_RANDMMAP
12220+ if (mm->pax_flags & MF_PAX_RANDMMAP)
12221+ info.low_limit += mm->delta_mmap;
12222+#endif
12223+
12224 info.high_limit = STACK_TOP32;
12225 addr = vm_unmapped_area(&info);
12226 }
12227@@ -96,6 +113,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
12228 struct mm_struct *mm = current->mm;
12229 struct vm_area_struct *vma;
12230 unsigned long task_size = TASK_SIZE;
12231+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
12232
12233 if (test_thread_flag(TIF_32BIT))
12234 task_size = STACK_TOP32;
12235@@ -111,19 +129,22 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
12236 return addr;
12237 }
12238
12239+#ifdef CONFIG_PAX_RANDMMAP
12240+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
12241+#endif
12242+
12243 if (addr) {
12244 addr = ALIGN(addr, HPAGE_SIZE);
12245 vma = find_vma(mm, addr);
12246- if (task_size - len >= addr &&
12247- (!vma || addr + len <= vma->vm_start))
12248+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
12249 return addr;
12250 }
12251 if (mm->get_unmapped_area == arch_get_unmapped_area)
12252 return hugetlb_get_unmapped_area_bottomup(file, addr, len,
12253- pgoff, flags);
12254+ pgoff, flags, offset);
12255 else
12256 return hugetlb_get_unmapped_area_topdown(file, addr, len,
12257- pgoff, flags);
12258+ pgoff, flags, offset);
12259 }
12260
12261 pte_t *huge_pte_alloc(struct mm_struct *mm,
12262diff --git a/arch/sparc/mm/init_64.c b/arch/sparc/mm/init_64.c
12263index 2d91c62..17a8fff 100644
12264--- a/arch/sparc/mm/init_64.c
12265+++ b/arch/sparc/mm/init_64.c
12266@@ -186,9 +186,9 @@ unsigned long sparc64_kern_sec_context __read_mostly;
12267 int num_kernel_image_mappings;
12268
12269 #ifdef CONFIG_DEBUG_DCFLUSH
12270-atomic_t dcpage_flushes = ATOMIC_INIT(0);
12271+atomic_unchecked_t dcpage_flushes = ATOMIC_INIT(0);
12272 #ifdef CONFIG_SMP
12273-atomic_t dcpage_flushes_xcall = ATOMIC_INIT(0);
12274+atomic_unchecked_t dcpage_flushes_xcall = ATOMIC_INIT(0);
12275 #endif
12276 #endif
12277
12278@@ -196,7 +196,7 @@ inline void flush_dcache_page_impl(struct page *page)
12279 {
12280 BUG_ON(tlb_type == hypervisor);
12281 #ifdef CONFIG_DEBUG_DCFLUSH
12282- atomic_inc(&dcpage_flushes);
12283+ atomic_inc_unchecked(&dcpage_flushes);
12284 #endif
12285
12286 #ifdef DCACHE_ALIASING_POSSIBLE
12287@@ -468,10 +468,10 @@ void mmu_info(struct seq_file *m)
12288
12289 #ifdef CONFIG_DEBUG_DCFLUSH
12290 seq_printf(m, "DCPageFlushes\t: %d\n",
12291- atomic_read(&dcpage_flushes));
12292+ atomic_read_unchecked(&dcpage_flushes));
12293 #ifdef CONFIG_SMP
12294 seq_printf(m, "DCPageFlushesXC\t: %d\n",
12295- atomic_read(&dcpage_flushes_xcall));
12296+ atomic_read_unchecked(&dcpage_flushes_xcall));
12297 #endif /* CONFIG_SMP */
12298 #endif /* CONFIG_DEBUG_DCFLUSH */
12299 }
12300diff --git a/arch/tile/Kconfig b/arch/tile/Kconfig
12301index 7cca418..53fc030 100644
12302--- a/arch/tile/Kconfig
12303+++ b/arch/tile/Kconfig
12304@@ -192,6 +192,7 @@ source "kernel/Kconfig.hz"
12305
12306 config KEXEC
12307 bool "kexec system call"
12308+ depends on !GRKERNSEC_KMEM
12309 ---help---
12310 kexec is a system call that implements the ability to shutdown your
12311 current kernel, and to start another kernel. It is like a reboot
12312diff --git a/arch/tile/include/asm/atomic_64.h b/arch/tile/include/asm/atomic_64.h
12313index 7b11c5f..755a026 100644
12314--- a/arch/tile/include/asm/atomic_64.h
12315+++ b/arch/tile/include/asm/atomic_64.h
12316@@ -105,6 +105,16 @@ static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
12317
12318 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
12319
12320+#define atomic64_read_unchecked(v) atomic64_read(v)
12321+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
12322+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
12323+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
12324+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
12325+#define atomic64_inc_unchecked(v) atomic64_inc(v)
12326+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
12327+#define atomic64_dec_unchecked(v) atomic64_dec(v)
12328+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
12329+
12330 /* Define this to indicate that cmpxchg is an efficient operation. */
12331 #define __HAVE_ARCH_CMPXCHG
12332
12333diff --git a/arch/tile/include/asm/cache.h b/arch/tile/include/asm/cache.h
12334index 6160761..00cac88 100644
12335--- a/arch/tile/include/asm/cache.h
12336+++ b/arch/tile/include/asm/cache.h
12337@@ -15,11 +15,12 @@
12338 #ifndef _ASM_TILE_CACHE_H
12339 #define _ASM_TILE_CACHE_H
12340
12341+#include <linux/const.h>
12342 #include <arch/chip.h>
12343
12344 /* bytes per L1 data cache line */
12345 #define L1_CACHE_SHIFT CHIP_L1D_LOG_LINE_SIZE()
12346-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
12347+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
12348
12349 /* bytes per L2 cache line */
12350 #define L2_CACHE_SHIFT CHIP_L2_LOG_LINE_SIZE()
12351diff --git a/arch/tile/include/asm/uaccess.h b/arch/tile/include/asm/uaccess.h
12352index b6cde32..c0cb736 100644
12353--- a/arch/tile/include/asm/uaccess.h
12354+++ b/arch/tile/include/asm/uaccess.h
12355@@ -414,9 +414,9 @@ static inline unsigned long __must_check copy_from_user(void *to,
12356 const void __user *from,
12357 unsigned long n)
12358 {
12359- int sz = __compiletime_object_size(to);
12360+ size_t sz = __compiletime_object_size(to);
12361
12362- if (likely(sz == -1 || sz >= n))
12363+ if (likely(sz == (size_t)-1 || sz >= n))
12364 n = _copy_from_user(to, from, n);
12365 else
12366 copy_from_user_overflow();
12367diff --git a/arch/tile/mm/hugetlbpage.c b/arch/tile/mm/hugetlbpage.c
12368index e514899..f8743c4 100644
12369--- a/arch/tile/mm/hugetlbpage.c
12370+++ b/arch/tile/mm/hugetlbpage.c
12371@@ -207,6 +207,7 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
12372 info.high_limit = TASK_SIZE;
12373 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
12374 info.align_offset = 0;
12375+ info.threadstack_offset = 0;
12376 return vm_unmapped_area(&info);
12377 }
12378
12379@@ -224,6 +225,7 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
12380 info.high_limit = current->mm->mmap_base;
12381 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
12382 info.align_offset = 0;
12383+ info.threadstack_offset = 0;
12384 addr = vm_unmapped_area(&info);
12385
12386 /*
12387diff --git a/arch/um/Makefile b/arch/um/Makefile
12388index e4b1a96..16162f8 100644
12389--- a/arch/um/Makefile
12390+++ b/arch/um/Makefile
12391@@ -72,6 +72,10 @@ USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -D__KERNEL__,,\
12392 $(patsubst -I%,,$(KBUILD_CFLAGS)))) $(ARCH_INCLUDE) $(MODE_INCLUDE) \
12393 $(filter -I%,$(CFLAGS)) -D_FILE_OFFSET_BITS=64 -idirafter include
12394
12395+ifdef CONSTIFY_PLUGIN
12396+USER_CFLAGS += -fplugin-arg-constify_plugin-no-constify
12397+endif
12398+
12399 #This will adjust *FLAGS accordingly to the platform.
12400 include $(srctree)/$(ARCH_DIR)/Makefile-os-$(OS)
12401
12402diff --git a/arch/um/include/asm/cache.h b/arch/um/include/asm/cache.h
12403index 19e1bdd..3665b77 100644
12404--- a/arch/um/include/asm/cache.h
12405+++ b/arch/um/include/asm/cache.h
12406@@ -1,6 +1,7 @@
12407 #ifndef __UM_CACHE_H
12408 #define __UM_CACHE_H
12409
12410+#include <linux/const.h>
12411
12412 #if defined(CONFIG_UML_X86) && !defined(CONFIG_64BIT)
12413 # define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
12414@@ -12,6 +13,6 @@
12415 # define L1_CACHE_SHIFT 5
12416 #endif
12417
12418-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
12419+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
12420
12421 #endif
12422diff --git a/arch/um/include/asm/kmap_types.h b/arch/um/include/asm/kmap_types.h
12423index 2e0a6b1..a64d0f5 100644
12424--- a/arch/um/include/asm/kmap_types.h
12425+++ b/arch/um/include/asm/kmap_types.h
12426@@ -8,6 +8,6 @@
12427
12428 /* No more #include "asm/arch/kmap_types.h" ! */
12429
12430-#define KM_TYPE_NR 14
12431+#define KM_TYPE_NR 15
12432
12433 #endif
12434diff --git a/arch/um/include/asm/page.h b/arch/um/include/asm/page.h
12435index 71c5d13..4c7b9f1 100644
12436--- a/arch/um/include/asm/page.h
12437+++ b/arch/um/include/asm/page.h
12438@@ -14,6 +14,9 @@
12439 #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
12440 #define PAGE_MASK (~(PAGE_SIZE-1))
12441
12442+#define ktla_ktva(addr) (addr)
12443+#define ktva_ktla(addr) (addr)
12444+
12445 #ifndef __ASSEMBLY__
12446
12447 struct page;
12448diff --git a/arch/um/include/asm/pgtable-3level.h b/arch/um/include/asm/pgtable-3level.h
12449index 0032f92..cd151e0 100644
12450--- a/arch/um/include/asm/pgtable-3level.h
12451+++ b/arch/um/include/asm/pgtable-3level.h
12452@@ -58,6 +58,7 @@
12453 #define pud_present(x) (pud_val(x) & _PAGE_PRESENT)
12454 #define pud_populate(mm, pud, pmd) \
12455 set_pud(pud, __pud(_PAGE_TABLE + __pa(pmd)))
12456+#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
12457
12458 #ifdef CONFIG_64BIT
12459 #define set_pud(pudptr, pudval) set_64bit((u64 *) (pudptr), pud_val(pudval))
12460diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c
12461index f17bca8..48adb87 100644
12462--- a/arch/um/kernel/process.c
12463+++ b/arch/um/kernel/process.c
12464@@ -356,22 +356,6 @@ int singlestepping(void * t)
12465 return 2;
12466 }
12467
12468-/*
12469- * Only x86 and x86_64 have an arch_align_stack().
12470- * All other arches have "#define arch_align_stack(x) (x)"
12471- * in their asm/exec.h
12472- * As this is included in UML from asm-um/system-generic.h,
12473- * we can use it to behave as the subarch does.
12474- */
12475-#ifndef arch_align_stack
12476-unsigned long arch_align_stack(unsigned long sp)
12477-{
12478- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
12479- sp -= get_random_int() % 8192;
12480- return sp & ~0xf;
12481-}
12482-#endif
12483-
12484 unsigned long get_wchan(struct task_struct *p)
12485 {
12486 unsigned long stack_page, sp, ip;
12487diff --git a/arch/unicore32/include/asm/cache.h b/arch/unicore32/include/asm/cache.h
12488index ad8f795..2c7eec6 100644
12489--- a/arch/unicore32/include/asm/cache.h
12490+++ b/arch/unicore32/include/asm/cache.h
12491@@ -12,8 +12,10 @@
12492 #ifndef __UNICORE_CACHE_H__
12493 #define __UNICORE_CACHE_H__
12494
12495-#define L1_CACHE_SHIFT (5)
12496-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
12497+#include <linux/const.h>
12498+
12499+#define L1_CACHE_SHIFT 5
12500+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
12501
12502 /*
12503 * Memory returned by kmalloc() may be used for DMA, so we must make
12504diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
12505index 41a503c..cf98b04 100644
12506--- a/arch/x86/Kconfig
12507+++ b/arch/x86/Kconfig
12508@@ -129,7 +129,7 @@ config X86
12509 select RTC_LIB
12510 select HAVE_DEBUG_STACKOVERFLOW
12511 select HAVE_IRQ_EXIT_ON_IRQ_STACK if X86_64
12512- select HAVE_CC_STACKPROTECTOR
12513+ select HAVE_CC_STACKPROTECTOR if X86_64 || !PAX_MEMORY_UDEREF
12514 select GENERIC_CPU_AUTOPROBE
12515 select HAVE_ARCH_AUDITSYSCALL
12516 select ARCH_SUPPORTS_ATOMIC_RMW
12517@@ -262,7 +262,7 @@ config X86_HT
12518
12519 config X86_32_LAZY_GS
12520 def_bool y
12521- depends on X86_32 && !CC_STACKPROTECTOR
12522+ depends on X86_32 && !CC_STACKPROTECTOR && !PAX_MEMORY_UDEREF
12523
12524 config ARCH_HWEIGHT_CFLAGS
12525 string
12526@@ -600,6 +600,7 @@ config SCHED_OMIT_FRAME_POINTER
12527
12528 menuconfig HYPERVISOR_GUEST
12529 bool "Linux guest support"
12530+ depends on !GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_VIRT_GUEST || (GRKERNSEC_CONFIG_VIRT_HOST && GRKERNSEC_CONFIG_VIRT_XEN)
12531 ---help---
12532 Say Y here to enable options for running Linux under various hyper-
12533 visors. This option enables basic hypervisor detection and platform
12534@@ -973,6 +974,7 @@ config VM86
12535
12536 config X86_16BIT
12537 bool "Enable support for 16-bit segments" if EXPERT
12538+ depends on !GRKERNSEC
12539 default y
12540 ---help---
12541 This option is required by programs like Wine to run 16-bit
12542@@ -1128,6 +1130,7 @@ choice
12543
12544 config NOHIGHMEM
12545 bool "off"
12546+ depends on !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
12547 ---help---
12548 Linux can use up to 64 Gigabytes of physical memory on x86 systems.
12549 However, the address space of 32-bit x86 processors is only 4
12550@@ -1164,6 +1167,7 @@ config NOHIGHMEM
12551
12552 config HIGHMEM4G
12553 bool "4GB"
12554+ depends on !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
12555 ---help---
12556 Select this if you have a 32-bit processor and between 1 and 4
12557 gigabytes of physical RAM.
12558@@ -1216,7 +1220,7 @@ config PAGE_OFFSET
12559 hex
12560 default 0xB0000000 if VMSPLIT_3G_OPT
12561 default 0x80000000 if VMSPLIT_2G
12562- default 0x78000000 if VMSPLIT_2G_OPT
12563+ default 0x70000000 if VMSPLIT_2G_OPT
12564 default 0x40000000 if VMSPLIT_1G
12565 default 0xC0000000
12566 depends on X86_32
12567@@ -1631,6 +1635,7 @@ source kernel/Kconfig.hz
12568
12569 config KEXEC
12570 bool "kexec system call"
12571+ depends on !GRKERNSEC_KMEM
12572 ---help---
12573 kexec is a system call that implements the ability to shutdown your
12574 current kernel, and to start another kernel. It is like a reboot
12575@@ -1816,7 +1821,9 @@ config X86_NEED_RELOCS
12576
12577 config PHYSICAL_ALIGN
12578 hex "Alignment value to which kernel should be aligned"
12579- default "0x200000"
12580+ default "0x1000000"
12581+ range 0x200000 0x1000000 if PAX_KERNEXEC && X86_PAE
12582+ range 0x400000 0x1000000 if PAX_KERNEXEC && !X86_PAE
12583 range 0x2000 0x1000000 if X86_32
12584 range 0x200000 0x1000000 if X86_64
12585 ---help---
12586@@ -1899,6 +1906,7 @@ config COMPAT_VDSO
12587 def_bool n
12588 prompt "Disable the 32-bit vDSO (needed for glibc 2.3.3)"
12589 depends on X86_32 || IA32_EMULATION
12590+ depends on !PAX_PAGEEXEC && !PAX_SEGMEXEC && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
12591 ---help---
12592 Certain buggy versions of glibc will crash if they are
12593 presented with a 32-bit vDSO that is not mapped at the address
12594diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
12595index 6983314..54ad7e8 100644
12596--- a/arch/x86/Kconfig.cpu
12597+++ b/arch/x86/Kconfig.cpu
12598@@ -319,7 +319,7 @@ config X86_PPRO_FENCE
12599
12600 config X86_F00F_BUG
12601 def_bool y
12602- depends on M586MMX || M586TSC || M586 || M486
12603+ depends on (M586MMX || M586TSC || M586 || M486) && !PAX_KERNEXEC
12604
12605 config X86_INVD_BUG
12606 def_bool y
12607@@ -327,7 +327,7 @@ config X86_INVD_BUG
12608
12609 config X86_ALIGNMENT_16
12610 def_bool y
12611- depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || MELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
12612+ depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
12613
12614 config X86_INTEL_USERCOPY
12615 def_bool y
12616@@ -369,7 +369,7 @@ config X86_CMPXCHG64
12617 # generates cmov.
12618 config X86_CMOV
12619 def_bool y
12620- depends on (MK8 || MK7 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
12621+ depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
12622
12623 config X86_MINIMUM_CPU_FAMILY
12624 int
12625diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug
12626index 61bd2ad..50b625d 100644
12627--- a/arch/x86/Kconfig.debug
12628+++ b/arch/x86/Kconfig.debug
12629@@ -93,7 +93,7 @@ config EFI_PGT_DUMP
12630 config DEBUG_RODATA
12631 bool "Write protect kernel read-only data structures"
12632 default y
12633- depends on DEBUG_KERNEL
12634+ depends on DEBUG_KERNEL && BROKEN
12635 ---help---
12636 Mark the kernel read-only data as write-protected in the pagetables,
12637 in order to catch accidental (and incorrect) writes to such const
12638@@ -111,7 +111,7 @@ config DEBUG_RODATA_TEST
12639
12640 config DEBUG_SET_MODULE_RONX
12641 bool "Set loadable kernel module data as NX and text as RO"
12642- depends on MODULES
12643+ depends on MODULES && BROKEN
12644 ---help---
12645 This option helps catch unintended modifications to loadable
12646 kernel module's text and read-only data. It also prevents execution
12647diff --git a/arch/x86/Makefile b/arch/x86/Makefile
12648index 920e616..ac3d4df 100644
12649--- a/arch/x86/Makefile
12650+++ b/arch/x86/Makefile
12651@@ -65,9 +65,6 @@ ifeq ($(CONFIG_X86_32),y)
12652 # CPU-specific tuning. Anything which can be shared with UML should go here.
12653 include $(srctree)/arch/x86/Makefile_32.cpu
12654 KBUILD_CFLAGS += $(cflags-y)
12655-
12656- # temporary until string.h is fixed
12657- KBUILD_CFLAGS += -ffreestanding
12658 else
12659 BITS := 64
12660 UTS_MACHINE := x86_64
12661@@ -107,6 +104,9 @@ else
12662 KBUILD_CFLAGS += $(call cc-option,-maccumulate-outgoing-args)
12663 endif
12664
12665+# temporary until string.h is fixed
12666+KBUILD_CFLAGS += -ffreestanding
12667+
12668 # Make sure compiler does not have buggy stack-protector support.
12669 ifdef CONFIG_CC_STACKPROTECTOR
12670 cc_has_sp := $(srctree)/scripts/gcc-x86_$(BITS)-has-stack-protector.sh
12671@@ -180,6 +180,7 @@ archheaders:
12672 $(Q)$(MAKE) $(build)=arch/x86/syscalls all
12673
12674 archprepare:
12675+ $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
12676 ifeq ($(CONFIG_KEXEC_FILE),y)
12677 $(Q)$(MAKE) $(build)=arch/x86/purgatory arch/x86/purgatory/kexec-purgatory.c
12678 endif
12679@@ -263,3 +264,9 @@ define archhelp
12680 echo ' FDARGS="..." arguments for the booted kernel'
12681 echo ' FDINITRD=file initrd for the booted kernel'
12682 endef
12683+
12684+define OLD_LD
12685+
12686+*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
12687+*** Please upgrade your binutils to 2.18 or newer
12688+endef
12689diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
12690index 5b016e2..04ef69c 100644
12691--- a/arch/x86/boot/Makefile
12692+++ b/arch/x86/boot/Makefile
12693@@ -55,6 +55,9 @@ endif
12694 # ---------------------------------------------------------------------------
12695
12696 KBUILD_CFLAGS := $(USERINCLUDE) $(REALMODE_CFLAGS) -D_SETUP
12697+ifdef CONSTIFY_PLUGIN
12698+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
12699+endif
12700 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
12701 GCOV_PROFILE := n
12702
12703diff --git a/arch/x86/boot/bitops.h b/arch/x86/boot/bitops.h
12704index 878e4b9..20537ab 100644
12705--- a/arch/x86/boot/bitops.h
12706+++ b/arch/x86/boot/bitops.h
12707@@ -26,7 +26,7 @@ static inline int variable_test_bit(int nr, const void *addr)
12708 u8 v;
12709 const u32 *p = (const u32 *)addr;
12710
12711- asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
12712+ asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
12713 return v;
12714 }
12715
12716@@ -37,7 +37,7 @@ static inline int variable_test_bit(int nr, const void *addr)
12717
12718 static inline void set_bit(int nr, void *addr)
12719 {
12720- asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
12721+ asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
12722 }
12723
12724 #endif /* BOOT_BITOPS_H */
12725diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h
12726index bd49ec6..94c7f58 100644
12727--- a/arch/x86/boot/boot.h
12728+++ b/arch/x86/boot/boot.h
12729@@ -84,7 +84,7 @@ static inline void io_delay(void)
12730 static inline u16 ds(void)
12731 {
12732 u16 seg;
12733- asm("movw %%ds,%0" : "=rm" (seg));
12734+ asm volatile("movw %%ds,%0" : "=rm" (seg));
12735 return seg;
12736 }
12737
12738diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
12739index 45abc36..97bea2d 100644
12740--- a/arch/x86/boot/compressed/Makefile
12741+++ b/arch/x86/boot/compressed/Makefile
12742@@ -16,6 +16,9 @@ KBUILD_CFLAGS += $(cflags-y)
12743 KBUILD_CFLAGS += -mno-mmx -mno-sse
12744 KBUILD_CFLAGS += $(call cc-option,-ffreestanding)
12745 KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
12746+ifdef CONSTIFY_PLUGIN
12747+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
12748+endif
12749
12750 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
12751 GCOV_PROFILE := n
12752diff --git a/arch/x86/boot/compressed/efi_stub_32.S b/arch/x86/boot/compressed/efi_stub_32.S
12753index a53440e..c3dbf1e 100644
12754--- a/arch/x86/boot/compressed/efi_stub_32.S
12755+++ b/arch/x86/boot/compressed/efi_stub_32.S
12756@@ -46,16 +46,13 @@ ENTRY(efi_call_phys)
12757 * parameter 2, ..., param n. To make things easy, we save the return
12758 * address of efi_call_phys in a global variable.
12759 */
12760- popl %ecx
12761- movl %ecx, saved_return_addr(%edx)
12762- /* get the function pointer into ECX*/
12763- popl %ecx
12764- movl %ecx, efi_rt_function_ptr(%edx)
12765+ popl saved_return_addr(%edx)
12766+ popl efi_rt_function_ptr(%edx)
12767
12768 /*
12769 * 3. Call the physical function.
12770 */
12771- call *%ecx
12772+ call *efi_rt_function_ptr(%edx)
12773
12774 /*
12775 * 4. Balance the stack. And because EAX contain the return value,
12776@@ -67,15 +64,12 @@ ENTRY(efi_call_phys)
12777 1: popl %edx
12778 subl $1b, %edx
12779
12780- movl efi_rt_function_ptr(%edx), %ecx
12781- pushl %ecx
12782+ pushl efi_rt_function_ptr(%edx)
12783
12784 /*
12785 * 10. Push the saved return address onto the stack and return.
12786 */
12787- movl saved_return_addr(%edx), %ecx
12788- pushl %ecx
12789- ret
12790+ jmpl *saved_return_addr(%edx)
12791 ENDPROC(efi_call_phys)
12792 .previous
12793
12794diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
12795index 1d7fbbc..36ecd58 100644
12796--- a/arch/x86/boot/compressed/head_32.S
12797+++ b/arch/x86/boot/compressed/head_32.S
12798@@ -140,10 +140,10 @@ preferred_addr:
12799 addl %eax, %ebx
12800 notl %eax
12801 andl %eax, %ebx
12802- cmpl $LOAD_PHYSICAL_ADDR, %ebx
12803+ cmpl $____LOAD_PHYSICAL_ADDR, %ebx
12804 jge 1f
12805 #endif
12806- movl $LOAD_PHYSICAL_ADDR, %ebx
12807+ movl $____LOAD_PHYSICAL_ADDR, %ebx
12808 1:
12809
12810 /* Target address to relocate to for decompression */
12811diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
12812index 6b1766c..ad465c9 100644
12813--- a/arch/x86/boot/compressed/head_64.S
12814+++ b/arch/x86/boot/compressed/head_64.S
12815@@ -94,10 +94,10 @@ ENTRY(startup_32)
12816 addl %eax, %ebx
12817 notl %eax
12818 andl %eax, %ebx
12819- cmpl $LOAD_PHYSICAL_ADDR, %ebx
12820+ cmpl $____LOAD_PHYSICAL_ADDR, %ebx
12821 jge 1f
12822 #endif
12823- movl $LOAD_PHYSICAL_ADDR, %ebx
12824+ movl $____LOAD_PHYSICAL_ADDR, %ebx
12825 1:
12826
12827 /* Target address to relocate to for decompression */
12828@@ -322,10 +322,10 @@ preferred_addr:
12829 addq %rax, %rbp
12830 notq %rax
12831 andq %rax, %rbp
12832- cmpq $LOAD_PHYSICAL_ADDR, %rbp
12833+ cmpq $____LOAD_PHYSICAL_ADDR, %rbp
12834 jge 1f
12835 #endif
12836- movq $LOAD_PHYSICAL_ADDR, %rbp
12837+ movq $____LOAD_PHYSICAL_ADDR, %rbp
12838 1:
12839
12840 /* Target address to relocate to for decompression */
12841@@ -434,8 +434,8 @@ gdt:
12842 .long gdt
12843 .word 0
12844 .quad 0x0000000000000000 /* NULL descriptor */
12845- .quad 0x00af9a000000ffff /* __KERNEL_CS */
12846- .quad 0x00cf92000000ffff /* __KERNEL_DS */
12847+ .quad 0x00af9b000000ffff /* __KERNEL_CS */
12848+ .quad 0x00cf93000000ffff /* __KERNEL_DS */
12849 .quad 0x0080890000000000 /* TS descriptor */
12850 .quad 0x0000000000000000 /* TS continued */
12851 gdt_end:
12852diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
12853index 30dd59a..cd9edc3 100644
12854--- a/arch/x86/boot/compressed/misc.c
12855+++ b/arch/x86/boot/compressed/misc.c
12856@@ -242,7 +242,7 @@ static void handle_relocations(void *output, unsigned long output_len)
12857 * Calculate the delta between where vmlinux was linked to load
12858 * and where it was actually loaded.
12859 */
12860- delta = min_addr - LOAD_PHYSICAL_ADDR;
12861+ delta = min_addr - ____LOAD_PHYSICAL_ADDR;
12862 if (!delta) {
12863 debug_putstr("No relocation needed... ");
12864 return;
12865@@ -312,7 +312,7 @@ static void parse_elf(void *output)
12866 Elf32_Ehdr ehdr;
12867 Elf32_Phdr *phdrs, *phdr;
12868 #endif
12869- void *dest;
12870+ void *dest, *prev;
12871 int i;
12872
12873 memcpy(&ehdr, output, sizeof(ehdr));
12874@@ -339,13 +339,16 @@ static void parse_elf(void *output)
12875 case PT_LOAD:
12876 #ifdef CONFIG_RELOCATABLE
12877 dest = output;
12878- dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
12879+ dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
12880 #else
12881 dest = (void *)(phdr->p_paddr);
12882 #endif
12883 memcpy(dest,
12884 output + phdr->p_offset,
12885 phdr->p_filesz);
12886+ if (i)
12887+ memset(prev, 0xff, dest - prev);
12888+ prev = dest + phdr->p_filesz;
12889 break;
12890 default: /* Ignore other PT_* */ break;
12891 }
12892@@ -402,7 +405,7 @@ asmlinkage __visible void *decompress_kernel(void *rmode, memptr heap,
12893 error("Destination address too large");
12894 #endif
12895 #ifndef CONFIG_RELOCATABLE
12896- if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
12897+ if ((unsigned long)output != ____LOAD_PHYSICAL_ADDR)
12898 error("Wrong destination address");
12899 #endif
12900
12901diff --git a/arch/x86/boot/cpucheck.c b/arch/x86/boot/cpucheck.c
12902index 1fd7d57..0f7d096 100644
12903--- a/arch/x86/boot/cpucheck.c
12904+++ b/arch/x86/boot/cpucheck.c
12905@@ -125,9 +125,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
12906 u32 ecx = MSR_K7_HWCR;
12907 u32 eax, edx;
12908
12909- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12910+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12911 eax &= ~(1 << 15);
12912- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12913+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12914
12915 get_cpuflags(); /* Make sure it really did something */
12916 err = check_cpuflags();
12917@@ -140,9 +140,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
12918 u32 ecx = MSR_VIA_FCR;
12919 u32 eax, edx;
12920
12921- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12922+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12923 eax |= (1<<1)|(1<<7);
12924- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12925+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12926
12927 set_bit(X86_FEATURE_CX8, cpu.flags);
12928 err = check_cpuflags();
12929@@ -153,12 +153,12 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
12930 u32 eax, edx;
12931 u32 level = 1;
12932
12933- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12934- asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
12935- asm("cpuid"
12936+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12937+ asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
12938+ asm volatile("cpuid"
12939 : "+a" (level), "=d" (cpu.flags[0])
12940 : : "ecx", "ebx");
12941- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12942+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12943
12944 err = check_cpuflags();
12945 } else if (err == 0x01 &&
12946diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S
12947index 16ef025..91e033b 100644
12948--- a/arch/x86/boot/header.S
12949+++ b/arch/x86/boot/header.S
12950@@ -438,10 +438,14 @@ setup_data: .quad 0 # 64-bit physical pointer to
12951 # single linked list of
12952 # struct setup_data
12953
12954-pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
12955+pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
12956
12957 #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset)
12958+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
12959+#define VO_INIT_SIZE (VO__end - VO__text - __PAGE_OFFSET - ____LOAD_PHYSICAL_ADDR)
12960+#else
12961 #define VO_INIT_SIZE (VO__end - VO__text)
12962+#endif
12963 #if ZO_INIT_SIZE > VO_INIT_SIZE
12964 #define INIT_SIZE ZO_INIT_SIZE
12965 #else
12966diff --git a/arch/x86/boot/memory.c b/arch/x86/boot/memory.c
12967index db75d07..8e6d0af 100644
12968--- a/arch/x86/boot/memory.c
12969+++ b/arch/x86/boot/memory.c
12970@@ -19,7 +19,7 @@
12971
12972 static int detect_memory_e820(void)
12973 {
12974- int count = 0;
12975+ unsigned int count = 0;
12976 struct biosregs ireg, oreg;
12977 struct e820entry *desc = boot_params.e820_map;
12978 static struct e820entry buf; /* static so it is zeroed */
12979diff --git a/arch/x86/boot/video-vesa.c b/arch/x86/boot/video-vesa.c
12980index ba3e100..6501b8f 100644
12981--- a/arch/x86/boot/video-vesa.c
12982+++ b/arch/x86/boot/video-vesa.c
12983@@ -201,6 +201,7 @@ static void vesa_store_pm_info(void)
12984
12985 boot_params.screen_info.vesapm_seg = oreg.es;
12986 boot_params.screen_info.vesapm_off = oreg.di;
12987+ boot_params.screen_info.vesapm_size = oreg.cx;
12988 }
12989
12990 /*
12991diff --git a/arch/x86/boot/video.c b/arch/x86/boot/video.c
12992index 43eda28..5ab5fdb 100644
12993--- a/arch/x86/boot/video.c
12994+++ b/arch/x86/boot/video.c
12995@@ -96,7 +96,7 @@ static void store_mode_params(void)
12996 static unsigned int get_entry(void)
12997 {
12998 char entry_buf[4];
12999- int i, len = 0;
13000+ unsigned int i, len = 0;
13001 int key;
13002 unsigned int v;
13003
13004diff --git a/arch/x86/crypto/aes-x86_64-asm_64.S b/arch/x86/crypto/aes-x86_64-asm_64.S
13005index 9105655..41779c1 100644
13006--- a/arch/x86/crypto/aes-x86_64-asm_64.S
13007+++ b/arch/x86/crypto/aes-x86_64-asm_64.S
13008@@ -8,6 +8,8 @@
13009 * including this sentence is retained in full.
13010 */
13011
13012+#include <asm/alternative-asm.h>
13013+
13014 .extern crypto_ft_tab
13015 .extern crypto_it_tab
13016 .extern crypto_fl_tab
13017@@ -70,6 +72,8 @@
13018 je B192; \
13019 leaq 32(r9),r9;
13020
13021+#define ret pax_force_retaddr; ret
13022+
13023 #define epilogue(FUNC,r1,r2,r3,r4,r5,r6,r7,r8,r9) \
13024 movq r1,r2; \
13025 movq r3,r4; \
13026diff --git a/arch/x86/crypto/aesni-intel_asm.S b/arch/x86/crypto/aesni-intel_asm.S
13027index 477e9d7..c92c7d8 100644
13028--- a/arch/x86/crypto/aesni-intel_asm.S
13029+++ b/arch/x86/crypto/aesni-intel_asm.S
13030@@ -31,6 +31,7 @@
13031
13032 #include <linux/linkage.h>
13033 #include <asm/inst.h>
13034+#include <asm/alternative-asm.h>
13035
13036 #ifdef __x86_64__
13037 .data
13038@@ -205,7 +206,7 @@ enc: .octa 0x2
13039 * num_initial_blocks = b mod 4
13040 * encrypt the initial num_initial_blocks blocks and apply ghash on
13041 * the ciphertext
13042-* %r10, %r11, %r12, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
13043+* %r10, %r11, %r15, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
13044 * are clobbered
13045 * arg1, %arg2, %arg3, %r14 are used as a pointer only, not modified
13046 */
13047@@ -214,8 +215,8 @@ enc: .octa 0x2
13048 .macro INITIAL_BLOCKS_DEC num_initial_blocks TMP1 TMP2 TMP3 TMP4 TMP5 XMM0 XMM1 \
13049 XMM2 XMM3 XMM4 XMMDst TMP6 TMP7 i i_seq operation
13050 mov arg7, %r10 # %r10 = AAD
13051- mov arg8, %r12 # %r12 = aadLen
13052- mov %r12, %r11
13053+ mov arg8, %r15 # %r15 = aadLen
13054+ mov %r15, %r11
13055 pxor %xmm\i, %xmm\i
13056 _get_AAD_loop\num_initial_blocks\operation:
13057 movd (%r10), \TMP1
13058@@ -223,15 +224,15 @@ _get_AAD_loop\num_initial_blocks\operation:
13059 psrldq $4, %xmm\i
13060 pxor \TMP1, %xmm\i
13061 add $4, %r10
13062- sub $4, %r12
13063+ sub $4, %r15
13064 jne _get_AAD_loop\num_initial_blocks\operation
13065 cmp $16, %r11
13066 je _get_AAD_loop2_done\num_initial_blocks\operation
13067- mov $16, %r12
13068+ mov $16, %r15
13069 _get_AAD_loop2\num_initial_blocks\operation:
13070 psrldq $4, %xmm\i
13071- sub $4, %r12
13072- cmp %r11, %r12
13073+ sub $4, %r15
13074+ cmp %r11, %r15
13075 jne _get_AAD_loop2\num_initial_blocks\operation
13076 _get_AAD_loop2_done\num_initial_blocks\operation:
13077 movdqa SHUF_MASK(%rip), %xmm14
13078@@ -443,7 +444,7 @@ _initial_blocks_done\num_initial_blocks\operation:
13079 * num_initial_blocks = b mod 4
13080 * encrypt the initial num_initial_blocks blocks and apply ghash on
13081 * the ciphertext
13082-* %r10, %r11, %r12, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
13083+* %r10, %r11, %r15, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
13084 * are clobbered
13085 * arg1, %arg2, %arg3, %r14 are used as a pointer only, not modified
13086 */
13087@@ -452,8 +453,8 @@ _initial_blocks_done\num_initial_blocks\operation:
13088 .macro INITIAL_BLOCKS_ENC num_initial_blocks TMP1 TMP2 TMP3 TMP4 TMP5 XMM0 XMM1 \
13089 XMM2 XMM3 XMM4 XMMDst TMP6 TMP7 i i_seq operation
13090 mov arg7, %r10 # %r10 = AAD
13091- mov arg8, %r12 # %r12 = aadLen
13092- mov %r12, %r11
13093+ mov arg8, %r15 # %r15 = aadLen
13094+ mov %r15, %r11
13095 pxor %xmm\i, %xmm\i
13096 _get_AAD_loop\num_initial_blocks\operation:
13097 movd (%r10), \TMP1
13098@@ -461,15 +462,15 @@ _get_AAD_loop\num_initial_blocks\operation:
13099 psrldq $4, %xmm\i
13100 pxor \TMP1, %xmm\i
13101 add $4, %r10
13102- sub $4, %r12
13103+ sub $4, %r15
13104 jne _get_AAD_loop\num_initial_blocks\operation
13105 cmp $16, %r11
13106 je _get_AAD_loop2_done\num_initial_blocks\operation
13107- mov $16, %r12
13108+ mov $16, %r15
13109 _get_AAD_loop2\num_initial_blocks\operation:
13110 psrldq $4, %xmm\i
13111- sub $4, %r12
13112- cmp %r11, %r12
13113+ sub $4, %r15
13114+ cmp %r11, %r15
13115 jne _get_AAD_loop2\num_initial_blocks\operation
13116 _get_AAD_loop2_done\num_initial_blocks\operation:
13117 movdqa SHUF_MASK(%rip), %xmm14
13118@@ -1269,7 +1270,7 @@ TMP7 XMM1 XMM2 XMM3 XMM4 XMMDst
13119 *
13120 *****************************************************************************/
13121 ENTRY(aesni_gcm_dec)
13122- push %r12
13123+ push %r15
13124 push %r13
13125 push %r14
13126 mov %rsp, %r14
13127@@ -1279,8 +1280,8 @@ ENTRY(aesni_gcm_dec)
13128 */
13129 sub $VARIABLE_OFFSET, %rsp
13130 and $~63, %rsp # align rsp to 64 bytes
13131- mov %arg6, %r12
13132- movdqu (%r12), %xmm13 # %xmm13 = HashKey
13133+ mov %arg6, %r15
13134+ movdqu (%r15), %xmm13 # %xmm13 = HashKey
13135 movdqa SHUF_MASK(%rip), %xmm2
13136 PSHUFB_XMM %xmm2, %xmm13
13137
13138@@ -1308,10 +1309,10 @@ ENTRY(aesni_gcm_dec)
13139 movdqa %xmm13, HashKey(%rsp) # store HashKey<<1 (mod poly)
13140 mov %arg4, %r13 # save the number of bytes of plaintext/ciphertext
13141 and $-16, %r13 # %r13 = %r13 - (%r13 mod 16)
13142- mov %r13, %r12
13143- and $(3<<4), %r12
13144+ mov %r13, %r15
13145+ and $(3<<4), %r15
13146 jz _initial_num_blocks_is_0_decrypt
13147- cmp $(2<<4), %r12
13148+ cmp $(2<<4), %r15
13149 jb _initial_num_blocks_is_1_decrypt
13150 je _initial_num_blocks_is_2_decrypt
13151 _initial_num_blocks_is_3_decrypt:
13152@@ -1361,16 +1362,16 @@ _zero_cipher_left_decrypt:
13153 sub $16, %r11
13154 add %r13, %r11
13155 movdqu (%arg3,%r11,1), %xmm1 # receive the last <16 byte block
13156- lea SHIFT_MASK+16(%rip), %r12
13157- sub %r13, %r12
13158+ lea SHIFT_MASK+16(%rip), %r15
13159+ sub %r13, %r15
13160 # adjust the shuffle mask pointer to be able to shift 16-%r13 bytes
13161 # (%r13 is the number of bytes in plaintext mod 16)
13162- movdqu (%r12), %xmm2 # get the appropriate shuffle mask
13163+ movdqu (%r15), %xmm2 # get the appropriate shuffle mask
13164 PSHUFB_XMM %xmm2, %xmm1 # right shift 16-%r13 butes
13165
13166 movdqa %xmm1, %xmm2
13167 pxor %xmm1, %xmm0 # Ciphertext XOR E(K, Yn)
13168- movdqu ALL_F-SHIFT_MASK(%r12), %xmm1
13169+ movdqu ALL_F-SHIFT_MASK(%r15), %xmm1
13170 # get the appropriate mask to mask out top 16-%r13 bytes of %xmm0
13171 pand %xmm1, %xmm0 # mask out top 16-%r13 bytes of %xmm0
13172 pand %xmm1, %xmm2
13173@@ -1399,9 +1400,9 @@ _less_than_8_bytes_left_decrypt:
13174 sub $1, %r13
13175 jne _less_than_8_bytes_left_decrypt
13176 _multiple_of_16_bytes_decrypt:
13177- mov arg8, %r12 # %r13 = aadLen (number of bytes)
13178- shl $3, %r12 # convert into number of bits
13179- movd %r12d, %xmm15 # len(A) in %xmm15
13180+ mov arg8, %r15 # %r13 = aadLen (number of bytes)
13181+ shl $3, %r15 # convert into number of bits
13182+ movd %r15d, %xmm15 # len(A) in %xmm15
13183 shl $3, %arg4 # len(C) in bits (*128)
13184 MOVQ_R64_XMM %arg4, %xmm1
13185 pslldq $8, %xmm15 # %xmm15 = len(A)||0x0000000000000000
13186@@ -1440,7 +1441,8 @@ _return_T_done_decrypt:
13187 mov %r14, %rsp
13188 pop %r14
13189 pop %r13
13190- pop %r12
13191+ pop %r15
13192+ pax_force_retaddr
13193 ret
13194 ENDPROC(aesni_gcm_dec)
13195
13196@@ -1529,7 +1531,7 @@ ENDPROC(aesni_gcm_dec)
13197 * poly = x^128 + x^127 + x^126 + x^121 + 1
13198 ***************************************************************************/
13199 ENTRY(aesni_gcm_enc)
13200- push %r12
13201+ push %r15
13202 push %r13
13203 push %r14
13204 mov %rsp, %r14
13205@@ -1539,8 +1541,8 @@ ENTRY(aesni_gcm_enc)
13206 #
13207 sub $VARIABLE_OFFSET, %rsp
13208 and $~63, %rsp
13209- mov %arg6, %r12
13210- movdqu (%r12), %xmm13
13211+ mov %arg6, %r15
13212+ movdqu (%r15), %xmm13
13213 movdqa SHUF_MASK(%rip), %xmm2
13214 PSHUFB_XMM %xmm2, %xmm13
13215
13216@@ -1564,13 +1566,13 @@ ENTRY(aesni_gcm_enc)
13217 movdqa %xmm13, HashKey(%rsp)
13218 mov %arg4, %r13 # %xmm13 holds HashKey<<1 (mod poly)
13219 and $-16, %r13
13220- mov %r13, %r12
13221+ mov %r13, %r15
13222
13223 # Encrypt first few blocks
13224
13225- and $(3<<4), %r12
13226+ and $(3<<4), %r15
13227 jz _initial_num_blocks_is_0_encrypt
13228- cmp $(2<<4), %r12
13229+ cmp $(2<<4), %r15
13230 jb _initial_num_blocks_is_1_encrypt
13231 je _initial_num_blocks_is_2_encrypt
13232 _initial_num_blocks_is_3_encrypt:
13233@@ -1623,14 +1625,14 @@ _zero_cipher_left_encrypt:
13234 sub $16, %r11
13235 add %r13, %r11
13236 movdqu (%arg3,%r11,1), %xmm1 # receive the last <16 byte blocks
13237- lea SHIFT_MASK+16(%rip), %r12
13238- sub %r13, %r12
13239+ lea SHIFT_MASK+16(%rip), %r15
13240+ sub %r13, %r15
13241 # adjust the shuffle mask pointer to be able to shift 16-r13 bytes
13242 # (%r13 is the number of bytes in plaintext mod 16)
13243- movdqu (%r12), %xmm2 # get the appropriate shuffle mask
13244+ movdqu (%r15), %xmm2 # get the appropriate shuffle mask
13245 PSHUFB_XMM %xmm2, %xmm1 # shift right 16-r13 byte
13246 pxor %xmm1, %xmm0 # Plaintext XOR Encrypt(K, Yn)
13247- movdqu ALL_F-SHIFT_MASK(%r12), %xmm1
13248+ movdqu ALL_F-SHIFT_MASK(%r15), %xmm1
13249 # get the appropriate mask to mask out top 16-r13 bytes of xmm0
13250 pand %xmm1, %xmm0 # mask out top 16-r13 bytes of xmm0
13251 movdqa SHUF_MASK(%rip), %xmm10
13252@@ -1663,9 +1665,9 @@ _less_than_8_bytes_left_encrypt:
13253 sub $1, %r13
13254 jne _less_than_8_bytes_left_encrypt
13255 _multiple_of_16_bytes_encrypt:
13256- mov arg8, %r12 # %r12 = addLen (number of bytes)
13257- shl $3, %r12
13258- movd %r12d, %xmm15 # len(A) in %xmm15
13259+ mov arg8, %r15 # %r15 = addLen (number of bytes)
13260+ shl $3, %r15
13261+ movd %r15d, %xmm15 # len(A) in %xmm15
13262 shl $3, %arg4 # len(C) in bits (*128)
13263 MOVQ_R64_XMM %arg4, %xmm1
13264 pslldq $8, %xmm15 # %xmm15 = len(A)||0x0000000000000000
13265@@ -1704,7 +1706,8 @@ _return_T_done_encrypt:
13266 mov %r14, %rsp
13267 pop %r14
13268 pop %r13
13269- pop %r12
13270+ pop %r15
13271+ pax_force_retaddr
13272 ret
13273 ENDPROC(aesni_gcm_enc)
13274
13275@@ -1722,6 +1725,7 @@ _key_expansion_256a:
13276 pxor %xmm1, %xmm0
13277 movaps %xmm0, (TKEYP)
13278 add $0x10, TKEYP
13279+ pax_force_retaddr
13280 ret
13281 ENDPROC(_key_expansion_128)
13282 ENDPROC(_key_expansion_256a)
13283@@ -1748,6 +1752,7 @@ _key_expansion_192a:
13284 shufps $0b01001110, %xmm2, %xmm1
13285 movaps %xmm1, 0x10(TKEYP)
13286 add $0x20, TKEYP
13287+ pax_force_retaddr
13288 ret
13289 ENDPROC(_key_expansion_192a)
13290
13291@@ -1768,6 +1773,7 @@ _key_expansion_192b:
13292
13293 movaps %xmm0, (TKEYP)
13294 add $0x10, TKEYP
13295+ pax_force_retaddr
13296 ret
13297 ENDPROC(_key_expansion_192b)
13298
13299@@ -1781,6 +1787,7 @@ _key_expansion_256b:
13300 pxor %xmm1, %xmm2
13301 movaps %xmm2, (TKEYP)
13302 add $0x10, TKEYP
13303+ pax_force_retaddr
13304 ret
13305 ENDPROC(_key_expansion_256b)
13306
13307@@ -1894,6 +1901,7 @@ ENTRY(aesni_set_key)
13308 #ifndef __x86_64__
13309 popl KEYP
13310 #endif
13311+ pax_force_retaddr
13312 ret
13313 ENDPROC(aesni_set_key)
13314
13315@@ -1916,6 +1924,7 @@ ENTRY(aesni_enc)
13316 popl KLEN
13317 popl KEYP
13318 #endif
13319+ pax_force_retaddr
13320 ret
13321 ENDPROC(aesni_enc)
13322
13323@@ -1974,6 +1983,7 @@ _aesni_enc1:
13324 AESENC KEY STATE
13325 movaps 0x70(TKEYP), KEY
13326 AESENCLAST KEY STATE
13327+ pax_force_retaddr
13328 ret
13329 ENDPROC(_aesni_enc1)
13330
13331@@ -2083,6 +2093,7 @@ _aesni_enc4:
13332 AESENCLAST KEY STATE2
13333 AESENCLAST KEY STATE3
13334 AESENCLAST KEY STATE4
13335+ pax_force_retaddr
13336 ret
13337 ENDPROC(_aesni_enc4)
13338
13339@@ -2106,6 +2117,7 @@ ENTRY(aesni_dec)
13340 popl KLEN
13341 popl KEYP
13342 #endif
13343+ pax_force_retaddr
13344 ret
13345 ENDPROC(aesni_dec)
13346
13347@@ -2164,6 +2176,7 @@ _aesni_dec1:
13348 AESDEC KEY STATE
13349 movaps 0x70(TKEYP), KEY
13350 AESDECLAST KEY STATE
13351+ pax_force_retaddr
13352 ret
13353 ENDPROC(_aesni_dec1)
13354
13355@@ -2273,6 +2286,7 @@ _aesni_dec4:
13356 AESDECLAST KEY STATE2
13357 AESDECLAST KEY STATE3
13358 AESDECLAST KEY STATE4
13359+ pax_force_retaddr
13360 ret
13361 ENDPROC(_aesni_dec4)
13362
13363@@ -2331,6 +2345,7 @@ ENTRY(aesni_ecb_enc)
13364 popl KEYP
13365 popl LEN
13366 #endif
13367+ pax_force_retaddr
13368 ret
13369 ENDPROC(aesni_ecb_enc)
13370
13371@@ -2390,6 +2405,7 @@ ENTRY(aesni_ecb_dec)
13372 popl KEYP
13373 popl LEN
13374 #endif
13375+ pax_force_retaddr
13376 ret
13377 ENDPROC(aesni_ecb_dec)
13378
13379@@ -2432,6 +2448,7 @@ ENTRY(aesni_cbc_enc)
13380 popl LEN
13381 popl IVP
13382 #endif
13383+ pax_force_retaddr
13384 ret
13385 ENDPROC(aesni_cbc_enc)
13386
13387@@ -2523,6 +2540,7 @@ ENTRY(aesni_cbc_dec)
13388 popl LEN
13389 popl IVP
13390 #endif
13391+ pax_force_retaddr
13392 ret
13393 ENDPROC(aesni_cbc_dec)
13394
13395@@ -2550,6 +2568,7 @@ _aesni_inc_init:
13396 mov $1, TCTR_LOW
13397 MOVQ_R64_XMM TCTR_LOW INC
13398 MOVQ_R64_XMM CTR TCTR_LOW
13399+ pax_force_retaddr
13400 ret
13401 ENDPROC(_aesni_inc_init)
13402
13403@@ -2579,6 +2598,7 @@ _aesni_inc:
13404 .Linc_low:
13405 movaps CTR, IV
13406 PSHUFB_XMM BSWAP_MASK IV
13407+ pax_force_retaddr
13408 ret
13409 ENDPROC(_aesni_inc)
13410
13411@@ -2640,6 +2660,7 @@ ENTRY(aesni_ctr_enc)
13412 .Lctr_enc_ret:
13413 movups IV, (IVP)
13414 .Lctr_enc_just_ret:
13415+ pax_force_retaddr
13416 ret
13417 ENDPROC(aesni_ctr_enc)
13418
13419@@ -2766,6 +2787,7 @@ ENTRY(aesni_xts_crypt8)
13420 pxor INC, STATE4
13421 movdqu STATE4, 0x70(OUTP)
13422
13423+ pax_force_retaddr
13424 ret
13425 ENDPROC(aesni_xts_crypt8)
13426
13427diff --git a/arch/x86/crypto/blowfish-x86_64-asm_64.S b/arch/x86/crypto/blowfish-x86_64-asm_64.S
13428index 246c670..466e2d6 100644
13429--- a/arch/x86/crypto/blowfish-x86_64-asm_64.S
13430+++ b/arch/x86/crypto/blowfish-x86_64-asm_64.S
13431@@ -21,6 +21,7 @@
13432 */
13433
13434 #include <linux/linkage.h>
13435+#include <asm/alternative-asm.h>
13436
13437 .file "blowfish-x86_64-asm.S"
13438 .text
13439@@ -149,9 +150,11 @@ ENTRY(__blowfish_enc_blk)
13440 jnz .L__enc_xor;
13441
13442 write_block();
13443+ pax_force_retaddr
13444 ret;
13445 .L__enc_xor:
13446 xor_block();
13447+ pax_force_retaddr
13448 ret;
13449 ENDPROC(__blowfish_enc_blk)
13450
13451@@ -183,6 +186,7 @@ ENTRY(blowfish_dec_blk)
13452
13453 movq %r11, %rbp;
13454
13455+ pax_force_retaddr
13456 ret;
13457 ENDPROC(blowfish_dec_blk)
13458
13459@@ -334,6 +338,7 @@ ENTRY(__blowfish_enc_blk_4way)
13460
13461 popq %rbx;
13462 popq %rbp;
13463+ pax_force_retaddr
13464 ret;
13465
13466 .L__enc_xor4:
13467@@ -341,6 +346,7 @@ ENTRY(__blowfish_enc_blk_4way)
13468
13469 popq %rbx;
13470 popq %rbp;
13471+ pax_force_retaddr
13472 ret;
13473 ENDPROC(__blowfish_enc_blk_4way)
13474
13475@@ -375,5 +381,6 @@ ENTRY(blowfish_dec_blk_4way)
13476 popq %rbx;
13477 popq %rbp;
13478
13479+ pax_force_retaddr
13480 ret;
13481 ENDPROC(blowfish_dec_blk_4way)
13482diff --git a/arch/x86/crypto/camellia-aesni-avx-asm_64.S b/arch/x86/crypto/camellia-aesni-avx-asm_64.S
13483index ce71f92..1dce7ec 100644
13484--- a/arch/x86/crypto/camellia-aesni-avx-asm_64.S
13485+++ b/arch/x86/crypto/camellia-aesni-avx-asm_64.S
13486@@ -16,6 +16,7 @@
13487 */
13488
13489 #include <linux/linkage.h>
13490+#include <asm/alternative-asm.h>
13491
13492 #define CAMELLIA_TABLE_BYTE_LEN 272
13493
13494@@ -191,6 +192,7 @@ roundsm16_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd:
13495 roundsm16(%xmm0, %xmm1, %xmm2, %xmm3, %xmm4, %xmm5, %xmm6, %xmm7,
13496 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14, %xmm15,
13497 %rcx, (%r9));
13498+ pax_force_retaddr
13499 ret;
13500 ENDPROC(roundsm16_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd)
13501
13502@@ -199,6 +201,7 @@ roundsm16_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab:
13503 roundsm16(%xmm4, %xmm5, %xmm6, %xmm7, %xmm0, %xmm1, %xmm2, %xmm3,
13504 %xmm12, %xmm13, %xmm14, %xmm15, %xmm8, %xmm9, %xmm10, %xmm11,
13505 %rax, (%r9));
13506+ pax_force_retaddr
13507 ret;
13508 ENDPROC(roundsm16_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab)
13509
13510@@ -780,6 +783,7 @@ __camellia_enc_blk16:
13511 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14,
13512 %xmm15, (key_table)(CTX, %r8, 8), (%rax), 1 * 16(%rax));
13513
13514+ pax_force_retaddr
13515 ret;
13516
13517 .align 8
13518@@ -865,6 +869,7 @@ __camellia_dec_blk16:
13519 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14,
13520 %xmm15, (key_table)(CTX), (%rax), 1 * 16(%rax));
13521
13522+ pax_force_retaddr
13523 ret;
13524
13525 .align 8
13526@@ -904,6 +909,7 @@ ENTRY(camellia_ecb_enc_16way)
13527 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13528 %xmm8, %rsi);
13529
13530+ pax_force_retaddr
13531 ret;
13532 ENDPROC(camellia_ecb_enc_16way)
13533
13534@@ -932,6 +938,7 @@ ENTRY(camellia_ecb_dec_16way)
13535 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13536 %xmm8, %rsi);
13537
13538+ pax_force_retaddr
13539 ret;
13540 ENDPROC(camellia_ecb_dec_16way)
13541
13542@@ -981,6 +988,7 @@ ENTRY(camellia_cbc_dec_16way)
13543 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13544 %xmm8, %rsi);
13545
13546+ pax_force_retaddr
13547 ret;
13548 ENDPROC(camellia_cbc_dec_16way)
13549
13550@@ -1092,6 +1100,7 @@ ENTRY(camellia_ctr_16way)
13551 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13552 %xmm8, %rsi);
13553
13554+ pax_force_retaddr
13555 ret;
13556 ENDPROC(camellia_ctr_16way)
13557
13558@@ -1234,6 +1243,7 @@ camellia_xts_crypt_16way:
13559 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13560 %xmm8, %rsi);
13561
13562+ pax_force_retaddr
13563 ret;
13564 ENDPROC(camellia_xts_crypt_16way)
13565
13566diff --git a/arch/x86/crypto/camellia-aesni-avx2-asm_64.S b/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
13567index 0e0b886..5a3123c 100644
13568--- a/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
13569+++ b/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
13570@@ -11,6 +11,7 @@
13571 */
13572
13573 #include <linux/linkage.h>
13574+#include <asm/alternative-asm.h>
13575
13576 #define CAMELLIA_TABLE_BYTE_LEN 272
13577
13578@@ -230,6 +231,7 @@ roundsm32_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd:
13579 roundsm32(%ymm0, %ymm1, %ymm2, %ymm3, %ymm4, %ymm5, %ymm6, %ymm7,
13580 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14, %ymm15,
13581 %rcx, (%r9));
13582+ pax_force_retaddr
13583 ret;
13584 ENDPROC(roundsm32_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd)
13585
13586@@ -238,6 +240,7 @@ roundsm32_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab:
13587 roundsm32(%ymm4, %ymm5, %ymm6, %ymm7, %ymm0, %ymm1, %ymm2, %ymm3,
13588 %ymm12, %ymm13, %ymm14, %ymm15, %ymm8, %ymm9, %ymm10, %ymm11,
13589 %rax, (%r9));
13590+ pax_force_retaddr
13591 ret;
13592 ENDPROC(roundsm32_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab)
13593
13594@@ -820,6 +823,7 @@ __camellia_enc_blk32:
13595 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14,
13596 %ymm15, (key_table)(CTX, %r8, 8), (%rax), 1 * 32(%rax));
13597
13598+ pax_force_retaddr
13599 ret;
13600
13601 .align 8
13602@@ -905,6 +909,7 @@ __camellia_dec_blk32:
13603 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14,
13604 %ymm15, (key_table)(CTX), (%rax), 1 * 32(%rax));
13605
13606+ pax_force_retaddr
13607 ret;
13608
13609 .align 8
13610@@ -948,6 +953,7 @@ ENTRY(camellia_ecb_enc_32way)
13611
13612 vzeroupper;
13613
13614+ pax_force_retaddr
13615 ret;
13616 ENDPROC(camellia_ecb_enc_32way)
13617
13618@@ -980,6 +986,7 @@ ENTRY(camellia_ecb_dec_32way)
13619
13620 vzeroupper;
13621
13622+ pax_force_retaddr
13623 ret;
13624 ENDPROC(camellia_ecb_dec_32way)
13625
13626@@ -1046,6 +1053,7 @@ ENTRY(camellia_cbc_dec_32way)
13627
13628 vzeroupper;
13629
13630+ pax_force_retaddr
13631 ret;
13632 ENDPROC(camellia_cbc_dec_32way)
13633
13634@@ -1184,6 +1192,7 @@ ENTRY(camellia_ctr_32way)
13635
13636 vzeroupper;
13637
13638+ pax_force_retaddr
13639 ret;
13640 ENDPROC(camellia_ctr_32way)
13641
13642@@ -1349,6 +1358,7 @@ camellia_xts_crypt_32way:
13643
13644 vzeroupper;
13645
13646+ pax_force_retaddr
13647 ret;
13648 ENDPROC(camellia_xts_crypt_32way)
13649
13650diff --git a/arch/x86/crypto/camellia-x86_64-asm_64.S b/arch/x86/crypto/camellia-x86_64-asm_64.S
13651index 310319c..db3d7b5 100644
13652--- a/arch/x86/crypto/camellia-x86_64-asm_64.S
13653+++ b/arch/x86/crypto/camellia-x86_64-asm_64.S
13654@@ -21,6 +21,7 @@
13655 */
13656
13657 #include <linux/linkage.h>
13658+#include <asm/alternative-asm.h>
13659
13660 .file "camellia-x86_64-asm_64.S"
13661 .text
13662@@ -228,12 +229,14 @@ ENTRY(__camellia_enc_blk)
13663 enc_outunpack(mov, RT1);
13664
13665 movq RRBP, %rbp;
13666+ pax_force_retaddr
13667 ret;
13668
13669 .L__enc_xor:
13670 enc_outunpack(xor, RT1);
13671
13672 movq RRBP, %rbp;
13673+ pax_force_retaddr
13674 ret;
13675 ENDPROC(__camellia_enc_blk)
13676
13677@@ -272,6 +275,7 @@ ENTRY(camellia_dec_blk)
13678 dec_outunpack();
13679
13680 movq RRBP, %rbp;
13681+ pax_force_retaddr
13682 ret;
13683 ENDPROC(camellia_dec_blk)
13684
13685@@ -463,6 +467,7 @@ ENTRY(__camellia_enc_blk_2way)
13686
13687 movq RRBP, %rbp;
13688 popq %rbx;
13689+ pax_force_retaddr
13690 ret;
13691
13692 .L__enc2_xor:
13693@@ -470,6 +475,7 @@ ENTRY(__camellia_enc_blk_2way)
13694
13695 movq RRBP, %rbp;
13696 popq %rbx;
13697+ pax_force_retaddr
13698 ret;
13699 ENDPROC(__camellia_enc_blk_2way)
13700
13701@@ -510,5 +516,6 @@ ENTRY(camellia_dec_blk_2way)
13702
13703 movq RRBP, %rbp;
13704 movq RXOR, %rbx;
13705+ pax_force_retaddr
13706 ret;
13707 ENDPROC(camellia_dec_blk_2way)
13708diff --git a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
13709index c35fd5d..2d8c7db 100644
13710--- a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
13711+++ b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
13712@@ -24,6 +24,7 @@
13713 */
13714
13715 #include <linux/linkage.h>
13716+#include <asm/alternative-asm.h>
13717
13718 .file "cast5-avx-x86_64-asm_64.S"
13719
13720@@ -281,6 +282,7 @@ __cast5_enc_blk16:
13721 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
13722 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
13723
13724+ pax_force_retaddr
13725 ret;
13726 ENDPROC(__cast5_enc_blk16)
13727
13728@@ -352,6 +354,7 @@ __cast5_dec_blk16:
13729 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
13730 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
13731
13732+ pax_force_retaddr
13733 ret;
13734
13735 .L__skip_dec:
13736@@ -388,6 +391,7 @@ ENTRY(cast5_ecb_enc_16way)
13737 vmovdqu RR4, (6*4*4)(%r11);
13738 vmovdqu RL4, (7*4*4)(%r11);
13739
13740+ pax_force_retaddr
13741 ret;
13742 ENDPROC(cast5_ecb_enc_16way)
13743
13744@@ -420,6 +424,7 @@ ENTRY(cast5_ecb_dec_16way)
13745 vmovdqu RR4, (6*4*4)(%r11);
13746 vmovdqu RL4, (7*4*4)(%r11);
13747
13748+ pax_force_retaddr
13749 ret;
13750 ENDPROC(cast5_ecb_dec_16way)
13751
13752@@ -430,10 +435,10 @@ ENTRY(cast5_cbc_dec_16way)
13753 * %rdx: src
13754 */
13755
13756- pushq %r12;
13757+ pushq %r14;
13758
13759 movq %rsi, %r11;
13760- movq %rdx, %r12;
13761+ movq %rdx, %r14;
13762
13763 vmovdqu (0*16)(%rdx), RL1;
13764 vmovdqu (1*16)(%rdx), RR1;
13765@@ -447,16 +452,16 @@ ENTRY(cast5_cbc_dec_16way)
13766 call __cast5_dec_blk16;
13767
13768 /* xor with src */
13769- vmovq (%r12), RX;
13770+ vmovq (%r14), RX;
13771 vpshufd $0x4f, RX, RX;
13772 vpxor RX, RR1, RR1;
13773- vpxor 0*16+8(%r12), RL1, RL1;
13774- vpxor 1*16+8(%r12), RR2, RR2;
13775- vpxor 2*16+8(%r12), RL2, RL2;
13776- vpxor 3*16+8(%r12), RR3, RR3;
13777- vpxor 4*16+8(%r12), RL3, RL3;
13778- vpxor 5*16+8(%r12), RR4, RR4;
13779- vpxor 6*16+8(%r12), RL4, RL4;
13780+ vpxor 0*16+8(%r14), RL1, RL1;
13781+ vpxor 1*16+8(%r14), RR2, RR2;
13782+ vpxor 2*16+8(%r14), RL2, RL2;
13783+ vpxor 3*16+8(%r14), RR3, RR3;
13784+ vpxor 4*16+8(%r14), RL3, RL3;
13785+ vpxor 5*16+8(%r14), RR4, RR4;
13786+ vpxor 6*16+8(%r14), RL4, RL4;
13787
13788 vmovdqu RR1, (0*16)(%r11);
13789 vmovdqu RL1, (1*16)(%r11);
13790@@ -467,8 +472,9 @@ ENTRY(cast5_cbc_dec_16way)
13791 vmovdqu RR4, (6*16)(%r11);
13792 vmovdqu RL4, (7*16)(%r11);
13793
13794- popq %r12;
13795+ popq %r14;
13796
13797+ pax_force_retaddr
13798 ret;
13799 ENDPROC(cast5_cbc_dec_16way)
13800
13801@@ -480,10 +486,10 @@ ENTRY(cast5_ctr_16way)
13802 * %rcx: iv (big endian, 64bit)
13803 */
13804
13805- pushq %r12;
13806+ pushq %r14;
13807
13808 movq %rsi, %r11;
13809- movq %rdx, %r12;
13810+ movq %rdx, %r14;
13811
13812 vpcmpeqd RTMP, RTMP, RTMP;
13813 vpsrldq $8, RTMP, RTMP; /* low: -1, high: 0 */
13814@@ -523,14 +529,14 @@ ENTRY(cast5_ctr_16way)
13815 call __cast5_enc_blk16;
13816
13817 /* dst = src ^ iv */
13818- vpxor (0*16)(%r12), RR1, RR1;
13819- vpxor (1*16)(%r12), RL1, RL1;
13820- vpxor (2*16)(%r12), RR2, RR2;
13821- vpxor (3*16)(%r12), RL2, RL2;
13822- vpxor (4*16)(%r12), RR3, RR3;
13823- vpxor (5*16)(%r12), RL3, RL3;
13824- vpxor (6*16)(%r12), RR4, RR4;
13825- vpxor (7*16)(%r12), RL4, RL4;
13826+ vpxor (0*16)(%r14), RR1, RR1;
13827+ vpxor (1*16)(%r14), RL1, RL1;
13828+ vpxor (2*16)(%r14), RR2, RR2;
13829+ vpxor (3*16)(%r14), RL2, RL2;
13830+ vpxor (4*16)(%r14), RR3, RR3;
13831+ vpxor (5*16)(%r14), RL3, RL3;
13832+ vpxor (6*16)(%r14), RR4, RR4;
13833+ vpxor (7*16)(%r14), RL4, RL4;
13834 vmovdqu RR1, (0*16)(%r11);
13835 vmovdqu RL1, (1*16)(%r11);
13836 vmovdqu RR2, (2*16)(%r11);
13837@@ -540,7 +546,8 @@ ENTRY(cast5_ctr_16way)
13838 vmovdqu RR4, (6*16)(%r11);
13839 vmovdqu RL4, (7*16)(%r11);
13840
13841- popq %r12;
13842+ popq %r14;
13843
13844+ pax_force_retaddr
13845 ret;
13846 ENDPROC(cast5_ctr_16way)
13847diff --git a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
13848index e3531f8..e123f35 100644
13849--- a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
13850+++ b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
13851@@ -24,6 +24,7 @@
13852 */
13853
13854 #include <linux/linkage.h>
13855+#include <asm/alternative-asm.h>
13856 #include "glue_helper-asm-avx.S"
13857
13858 .file "cast6-avx-x86_64-asm_64.S"
13859@@ -295,6 +296,7 @@ __cast6_enc_blk8:
13860 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
13861 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
13862
13863+ pax_force_retaddr
13864 ret;
13865 ENDPROC(__cast6_enc_blk8)
13866
13867@@ -340,6 +342,7 @@ __cast6_dec_blk8:
13868 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
13869 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
13870
13871+ pax_force_retaddr
13872 ret;
13873 ENDPROC(__cast6_dec_blk8)
13874
13875@@ -358,6 +361,7 @@ ENTRY(cast6_ecb_enc_8way)
13876
13877 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13878
13879+ pax_force_retaddr
13880 ret;
13881 ENDPROC(cast6_ecb_enc_8way)
13882
13883@@ -376,6 +380,7 @@ ENTRY(cast6_ecb_dec_8way)
13884
13885 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13886
13887+ pax_force_retaddr
13888 ret;
13889 ENDPROC(cast6_ecb_dec_8way)
13890
13891@@ -386,19 +391,20 @@ ENTRY(cast6_cbc_dec_8way)
13892 * %rdx: src
13893 */
13894
13895- pushq %r12;
13896+ pushq %r14;
13897
13898 movq %rsi, %r11;
13899- movq %rdx, %r12;
13900+ movq %rdx, %r14;
13901
13902 load_8way(%rdx, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13903
13904 call __cast6_dec_blk8;
13905
13906- store_cbc_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13907+ store_cbc_8way(%r14, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13908
13909- popq %r12;
13910+ popq %r14;
13911
13912+ pax_force_retaddr
13913 ret;
13914 ENDPROC(cast6_cbc_dec_8way)
13915
13916@@ -410,20 +416,21 @@ ENTRY(cast6_ctr_8way)
13917 * %rcx: iv (little endian, 128bit)
13918 */
13919
13920- pushq %r12;
13921+ pushq %r14;
13922
13923 movq %rsi, %r11;
13924- movq %rdx, %r12;
13925+ movq %rdx, %r14;
13926
13927 load_ctr_8way(%rcx, .Lbswap128_mask, RA1, RB1, RC1, RD1, RA2, RB2, RC2,
13928 RD2, RX, RKR, RKM);
13929
13930 call __cast6_enc_blk8;
13931
13932- store_ctr_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13933+ store_ctr_8way(%r14, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13934
13935- popq %r12;
13936+ popq %r14;
13937
13938+ pax_force_retaddr
13939 ret;
13940 ENDPROC(cast6_ctr_8way)
13941
13942@@ -446,6 +453,7 @@ ENTRY(cast6_xts_enc_8way)
13943 /* dst <= regs xor IVs(in dst) */
13944 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13945
13946+ pax_force_retaddr
13947 ret;
13948 ENDPROC(cast6_xts_enc_8way)
13949
13950@@ -468,5 +476,6 @@ ENTRY(cast6_xts_dec_8way)
13951 /* dst <= regs xor IVs(in dst) */
13952 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13953
13954+ pax_force_retaddr
13955 ret;
13956 ENDPROC(cast6_xts_dec_8way)
13957diff --git a/arch/x86/crypto/crc32c-pcl-intel-asm_64.S b/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
13958index 26d49eb..c0a8c84 100644
13959--- a/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
13960+++ b/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
13961@@ -45,6 +45,7 @@
13962
13963 #include <asm/inst.h>
13964 #include <linux/linkage.h>
13965+#include <asm/alternative-asm.h>
13966
13967 ## ISCSI CRC 32 Implementation with crc32 and pclmulqdq Instruction
13968
13969@@ -309,6 +310,7 @@ do_return:
13970 popq %rsi
13971 popq %rdi
13972 popq %rbx
13973+ pax_force_retaddr
13974 ret
13975
13976 ################################################################
13977diff --git a/arch/x86/crypto/ghash-clmulni-intel_asm.S b/arch/x86/crypto/ghash-clmulni-intel_asm.S
13978index 5d1e007..098cb4f 100644
13979--- a/arch/x86/crypto/ghash-clmulni-intel_asm.S
13980+++ b/arch/x86/crypto/ghash-clmulni-intel_asm.S
13981@@ -18,6 +18,7 @@
13982
13983 #include <linux/linkage.h>
13984 #include <asm/inst.h>
13985+#include <asm/alternative-asm.h>
13986
13987 .data
13988
13989@@ -89,6 +90,7 @@ __clmul_gf128mul_ble:
13990 psrlq $1, T2
13991 pxor T2, T1
13992 pxor T1, DATA
13993+ pax_force_retaddr
13994 ret
13995 ENDPROC(__clmul_gf128mul_ble)
13996
13997@@ -101,6 +103,7 @@ ENTRY(clmul_ghash_mul)
13998 call __clmul_gf128mul_ble
13999 PSHUFB_XMM BSWAP DATA
14000 movups DATA, (%rdi)
14001+ pax_force_retaddr
14002 ret
14003 ENDPROC(clmul_ghash_mul)
14004
14005@@ -128,5 +131,6 @@ ENTRY(clmul_ghash_update)
14006 PSHUFB_XMM BSWAP DATA
14007 movups DATA, (%rdi)
14008 .Lupdate_just_ret:
14009+ pax_force_retaddr
14010 ret
14011 ENDPROC(clmul_ghash_update)
14012diff --git a/arch/x86/crypto/salsa20-x86_64-asm_64.S b/arch/x86/crypto/salsa20-x86_64-asm_64.S
14013index 9279e0b..c4b3d2c 100644
14014--- a/arch/x86/crypto/salsa20-x86_64-asm_64.S
14015+++ b/arch/x86/crypto/salsa20-x86_64-asm_64.S
14016@@ -1,4 +1,5 @@
14017 #include <linux/linkage.h>
14018+#include <asm/alternative-asm.h>
14019
14020 # enter salsa20_encrypt_bytes
14021 ENTRY(salsa20_encrypt_bytes)
14022@@ -789,6 +790,7 @@ ENTRY(salsa20_encrypt_bytes)
14023 add %r11,%rsp
14024 mov %rdi,%rax
14025 mov %rsi,%rdx
14026+ pax_force_retaddr
14027 ret
14028 # bytesatleast65:
14029 ._bytesatleast65:
14030@@ -889,6 +891,7 @@ ENTRY(salsa20_keysetup)
14031 add %r11,%rsp
14032 mov %rdi,%rax
14033 mov %rsi,%rdx
14034+ pax_force_retaddr
14035 ret
14036 ENDPROC(salsa20_keysetup)
14037
14038@@ -914,5 +917,6 @@ ENTRY(salsa20_ivsetup)
14039 add %r11,%rsp
14040 mov %rdi,%rax
14041 mov %rsi,%rdx
14042+ pax_force_retaddr
14043 ret
14044 ENDPROC(salsa20_ivsetup)
14045diff --git a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
14046index 2f202f4..d9164d6 100644
14047--- a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
14048+++ b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
14049@@ -24,6 +24,7 @@
14050 */
14051
14052 #include <linux/linkage.h>
14053+#include <asm/alternative-asm.h>
14054 #include "glue_helper-asm-avx.S"
14055
14056 .file "serpent-avx-x86_64-asm_64.S"
14057@@ -618,6 +619,7 @@ __serpent_enc_blk8_avx:
14058 write_blocks(RA1, RB1, RC1, RD1, RK0, RK1, RK2);
14059 write_blocks(RA2, RB2, RC2, RD2, RK0, RK1, RK2);
14060
14061+ pax_force_retaddr
14062 ret;
14063 ENDPROC(__serpent_enc_blk8_avx)
14064
14065@@ -672,6 +674,7 @@ __serpent_dec_blk8_avx:
14066 write_blocks(RC1, RD1, RB1, RE1, RK0, RK1, RK2);
14067 write_blocks(RC2, RD2, RB2, RE2, RK0, RK1, RK2);
14068
14069+ pax_force_retaddr
14070 ret;
14071 ENDPROC(__serpent_dec_blk8_avx)
14072
14073@@ -688,6 +691,7 @@ ENTRY(serpent_ecb_enc_8way_avx)
14074
14075 store_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14076
14077+ pax_force_retaddr
14078 ret;
14079 ENDPROC(serpent_ecb_enc_8way_avx)
14080
14081@@ -704,6 +708,7 @@ ENTRY(serpent_ecb_dec_8way_avx)
14082
14083 store_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
14084
14085+ pax_force_retaddr
14086 ret;
14087 ENDPROC(serpent_ecb_dec_8way_avx)
14088
14089@@ -720,6 +725,7 @@ ENTRY(serpent_cbc_dec_8way_avx)
14090
14091 store_cbc_8way(%rdx, %rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
14092
14093+ pax_force_retaddr
14094 ret;
14095 ENDPROC(serpent_cbc_dec_8way_avx)
14096
14097@@ -738,6 +744,7 @@ ENTRY(serpent_ctr_8way_avx)
14098
14099 store_ctr_8way(%rdx, %rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14100
14101+ pax_force_retaddr
14102 ret;
14103 ENDPROC(serpent_ctr_8way_avx)
14104
14105@@ -758,6 +765,7 @@ ENTRY(serpent_xts_enc_8way_avx)
14106 /* dst <= regs xor IVs(in dst) */
14107 store_xts_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14108
14109+ pax_force_retaddr
14110 ret;
14111 ENDPROC(serpent_xts_enc_8way_avx)
14112
14113@@ -778,5 +786,6 @@ ENTRY(serpent_xts_dec_8way_avx)
14114 /* dst <= regs xor IVs(in dst) */
14115 store_xts_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
14116
14117+ pax_force_retaddr
14118 ret;
14119 ENDPROC(serpent_xts_dec_8way_avx)
14120diff --git a/arch/x86/crypto/serpent-avx2-asm_64.S b/arch/x86/crypto/serpent-avx2-asm_64.S
14121index b222085..abd483c 100644
14122--- a/arch/x86/crypto/serpent-avx2-asm_64.S
14123+++ b/arch/x86/crypto/serpent-avx2-asm_64.S
14124@@ -15,6 +15,7 @@
14125 */
14126
14127 #include <linux/linkage.h>
14128+#include <asm/alternative-asm.h>
14129 #include "glue_helper-asm-avx2.S"
14130
14131 .file "serpent-avx2-asm_64.S"
14132@@ -610,6 +611,7 @@ __serpent_enc_blk16:
14133 write_blocks(RA1, RB1, RC1, RD1, RK0, RK1, RK2);
14134 write_blocks(RA2, RB2, RC2, RD2, RK0, RK1, RK2);
14135
14136+ pax_force_retaddr
14137 ret;
14138 ENDPROC(__serpent_enc_blk16)
14139
14140@@ -664,6 +666,7 @@ __serpent_dec_blk16:
14141 write_blocks(RC1, RD1, RB1, RE1, RK0, RK1, RK2);
14142 write_blocks(RC2, RD2, RB2, RE2, RK0, RK1, RK2);
14143
14144+ pax_force_retaddr
14145 ret;
14146 ENDPROC(__serpent_dec_blk16)
14147
14148@@ -684,6 +687,7 @@ ENTRY(serpent_ecb_enc_16way)
14149
14150 vzeroupper;
14151
14152+ pax_force_retaddr
14153 ret;
14154 ENDPROC(serpent_ecb_enc_16way)
14155
14156@@ -704,6 +708,7 @@ ENTRY(serpent_ecb_dec_16way)
14157
14158 vzeroupper;
14159
14160+ pax_force_retaddr
14161 ret;
14162 ENDPROC(serpent_ecb_dec_16way)
14163
14164@@ -725,6 +730,7 @@ ENTRY(serpent_cbc_dec_16way)
14165
14166 vzeroupper;
14167
14168+ pax_force_retaddr
14169 ret;
14170 ENDPROC(serpent_cbc_dec_16way)
14171
14172@@ -748,6 +754,7 @@ ENTRY(serpent_ctr_16way)
14173
14174 vzeroupper;
14175
14176+ pax_force_retaddr
14177 ret;
14178 ENDPROC(serpent_ctr_16way)
14179
14180@@ -772,6 +779,7 @@ ENTRY(serpent_xts_enc_16way)
14181
14182 vzeroupper;
14183
14184+ pax_force_retaddr
14185 ret;
14186 ENDPROC(serpent_xts_enc_16way)
14187
14188@@ -796,5 +804,6 @@ ENTRY(serpent_xts_dec_16way)
14189
14190 vzeroupper;
14191
14192+ pax_force_retaddr
14193 ret;
14194 ENDPROC(serpent_xts_dec_16way)
14195diff --git a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
14196index acc066c..1559cc4 100644
14197--- a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
14198+++ b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
14199@@ -25,6 +25,7 @@
14200 */
14201
14202 #include <linux/linkage.h>
14203+#include <asm/alternative-asm.h>
14204
14205 .file "serpent-sse2-x86_64-asm_64.S"
14206 .text
14207@@ -690,12 +691,14 @@ ENTRY(__serpent_enc_blk_8way)
14208 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
14209 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
14210
14211+ pax_force_retaddr
14212 ret;
14213
14214 .L__enc_xor8:
14215 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
14216 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
14217
14218+ pax_force_retaddr
14219 ret;
14220 ENDPROC(__serpent_enc_blk_8way)
14221
14222@@ -750,5 +753,6 @@ ENTRY(serpent_dec_blk_8way)
14223 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
14224 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
14225
14226+ pax_force_retaddr
14227 ret;
14228 ENDPROC(serpent_dec_blk_8way)
14229diff --git a/arch/x86/crypto/sha1_ssse3_asm.S b/arch/x86/crypto/sha1_ssse3_asm.S
14230index a410950..9dfe7ad 100644
14231--- a/arch/x86/crypto/sha1_ssse3_asm.S
14232+++ b/arch/x86/crypto/sha1_ssse3_asm.S
14233@@ -29,6 +29,7 @@
14234 */
14235
14236 #include <linux/linkage.h>
14237+#include <asm/alternative-asm.h>
14238
14239 #define CTX %rdi // arg1
14240 #define BUF %rsi // arg2
14241@@ -75,9 +76,9 @@
14242
14243 push %rbx
14244 push %rbp
14245- push %r12
14246+ push %r14
14247
14248- mov %rsp, %r12
14249+ mov %rsp, %r14
14250 sub $64, %rsp # allocate workspace
14251 and $~15, %rsp # align stack
14252
14253@@ -99,11 +100,12 @@
14254 xor %rax, %rax
14255 rep stosq
14256
14257- mov %r12, %rsp # deallocate workspace
14258+ mov %r14, %rsp # deallocate workspace
14259
14260- pop %r12
14261+ pop %r14
14262 pop %rbp
14263 pop %rbx
14264+ pax_force_retaddr
14265 ret
14266
14267 ENDPROC(\name)
14268diff --git a/arch/x86/crypto/sha256-avx-asm.S b/arch/x86/crypto/sha256-avx-asm.S
14269index 642f156..51a513c 100644
14270--- a/arch/x86/crypto/sha256-avx-asm.S
14271+++ b/arch/x86/crypto/sha256-avx-asm.S
14272@@ -49,6 +49,7 @@
14273
14274 #ifdef CONFIG_AS_AVX
14275 #include <linux/linkage.h>
14276+#include <asm/alternative-asm.h>
14277
14278 ## assume buffers not aligned
14279 #define VMOVDQ vmovdqu
14280@@ -460,6 +461,7 @@ done_hash:
14281 popq %r13
14282 popq %rbp
14283 popq %rbx
14284+ pax_force_retaddr
14285 ret
14286 ENDPROC(sha256_transform_avx)
14287
14288diff --git a/arch/x86/crypto/sha256-avx2-asm.S b/arch/x86/crypto/sha256-avx2-asm.S
14289index 9e86944..3795e6a 100644
14290--- a/arch/x86/crypto/sha256-avx2-asm.S
14291+++ b/arch/x86/crypto/sha256-avx2-asm.S
14292@@ -50,6 +50,7 @@
14293
14294 #ifdef CONFIG_AS_AVX2
14295 #include <linux/linkage.h>
14296+#include <asm/alternative-asm.h>
14297
14298 ## assume buffers not aligned
14299 #define VMOVDQ vmovdqu
14300@@ -720,6 +721,7 @@ done_hash:
14301 popq %r12
14302 popq %rbp
14303 popq %rbx
14304+ pax_force_retaddr
14305 ret
14306 ENDPROC(sha256_transform_rorx)
14307
14308diff --git a/arch/x86/crypto/sha256-ssse3-asm.S b/arch/x86/crypto/sha256-ssse3-asm.S
14309index f833b74..8c62a9e 100644
14310--- a/arch/x86/crypto/sha256-ssse3-asm.S
14311+++ b/arch/x86/crypto/sha256-ssse3-asm.S
14312@@ -47,6 +47,7 @@
14313 ########################################################################
14314
14315 #include <linux/linkage.h>
14316+#include <asm/alternative-asm.h>
14317
14318 ## assume buffers not aligned
14319 #define MOVDQ movdqu
14320@@ -471,6 +472,7 @@ done_hash:
14321 popq %rbp
14322 popq %rbx
14323
14324+ pax_force_retaddr
14325 ret
14326 ENDPROC(sha256_transform_ssse3)
14327
14328diff --git a/arch/x86/crypto/sha512-avx-asm.S b/arch/x86/crypto/sha512-avx-asm.S
14329index 974dde9..a823ff9 100644
14330--- a/arch/x86/crypto/sha512-avx-asm.S
14331+++ b/arch/x86/crypto/sha512-avx-asm.S
14332@@ -49,6 +49,7 @@
14333
14334 #ifdef CONFIG_AS_AVX
14335 #include <linux/linkage.h>
14336+#include <asm/alternative-asm.h>
14337
14338 .text
14339
14340@@ -364,6 +365,7 @@ updateblock:
14341 mov frame_RSPSAVE(%rsp), %rsp
14342
14343 nowork:
14344+ pax_force_retaddr
14345 ret
14346 ENDPROC(sha512_transform_avx)
14347
14348diff --git a/arch/x86/crypto/sha512-avx2-asm.S b/arch/x86/crypto/sha512-avx2-asm.S
14349index 568b961..ed20c37 100644
14350--- a/arch/x86/crypto/sha512-avx2-asm.S
14351+++ b/arch/x86/crypto/sha512-avx2-asm.S
14352@@ -51,6 +51,7 @@
14353
14354 #ifdef CONFIG_AS_AVX2
14355 #include <linux/linkage.h>
14356+#include <asm/alternative-asm.h>
14357
14358 .text
14359
14360@@ -678,6 +679,7 @@ done_hash:
14361
14362 # Restore Stack Pointer
14363 mov frame_RSPSAVE(%rsp), %rsp
14364+ pax_force_retaddr
14365 ret
14366 ENDPROC(sha512_transform_rorx)
14367
14368diff --git a/arch/x86/crypto/sha512-ssse3-asm.S b/arch/x86/crypto/sha512-ssse3-asm.S
14369index fb56855..6edd768 100644
14370--- a/arch/x86/crypto/sha512-ssse3-asm.S
14371+++ b/arch/x86/crypto/sha512-ssse3-asm.S
14372@@ -48,6 +48,7 @@
14373 ########################################################################
14374
14375 #include <linux/linkage.h>
14376+#include <asm/alternative-asm.h>
14377
14378 .text
14379
14380@@ -363,6 +364,7 @@ updateblock:
14381 mov frame_RSPSAVE(%rsp), %rsp
14382
14383 nowork:
14384+ pax_force_retaddr
14385 ret
14386 ENDPROC(sha512_transform_ssse3)
14387
14388diff --git a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
14389index 0505813..b067311 100644
14390--- a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
14391+++ b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
14392@@ -24,6 +24,7 @@
14393 */
14394
14395 #include <linux/linkage.h>
14396+#include <asm/alternative-asm.h>
14397 #include "glue_helper-asm-avx.S"
14398
14399 .file "twofish-avx-x86_64-asm_64.S"
14400@@ -284,6 +285,7 @@ __twofish_enc_blk8:
14401 outunpack_blocks(RC1, RD1, RA1, RB1, RK1, RX0, RY0, RK2);
14402 outunpack_blocks(RC2, RD2, RA2, RB2, RK1, RX0, RY0, RK2);
14403
14404+ pax_force_retaddr
14405 ret;
14406 ENDPROC(__twofish_enc_blk8)
14407
14408@@ -324,6 +326,7 @@ __twofish_dec_blk8:
14409 outunpack_blocks(RA1, RB1, RC1, RD1, RK1, RX0, RY0, RK2);
14410 outunpack_blocks(RA2, RB2, RC2, RD2, RK1, RX0, RY0, RK2);
14411
14412+ pax_force_retaddr
14413 ret;
14414 ENDPROC(__twofish_dec_blk8)
14415
14416@@ -342,6 +345,7 @@ ENTRY(twofish_ecb_enc_8way)
14417
14418 store_8way(%r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14419
14420+ pax_force_retaddr
14421 ret;
14422 ENDPROC(twofish_ecb_enc_8way)
14423
14424@@ -360,6 +364,7 @@ ENTRY(twofish_ecb_dec_8way)
14425
14426 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14427
14428+ pax_force_retaddr
14429 ret;
14430 ENDPROC(twofish_ecb_dec_8way)
14431
14432@@ -370,19 +375,20 @@ ENTRY(twofish_cbc_dec_8way)
14433 * %rdx: src
14434 */
14435
14436- pushq %r12;
14437+ pushq %r14;
14438
14439 movq %rsi, %r11;
14440- movq %rdx, %r12;
14441+ movq %rdx, %r14;
14442
14443 load_8way(%rdx, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14444
14445 call __twofish_dec_blk8;
14446
14447- store_cbc_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14448+ store_cbc_8way(%r14, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14449
14450- popq %r12;
14451+ popq %r14;
14452
14453+ pax_force_retaddr
14454 ret;
14455 ENDPROC(twofish_cbc_dec_8way)
14456
14457@@ -394,20 +400,21 @@ ENTRY(twofish_ctr_8way)
14458 * %rcx: iv (little endian, 128bit)
14459 */
14460
14461- pushq %r12;
14462+ pushq %r14;
14463
14464 movq %rsi, %r11;
14465- movq %rdx, %r12;
14466+ movq %rdx, %r14;
14467
14468 load_ctr_8way(%rcx, .Lbswap128_mask, RA1, RB1, RC1, RD1, RA2, RB2, RC2,
14469 RD2, RX0, RX1, RY0);
14470
14471 call __twofish_enc_blk8;
14472
14473- store_ctr_8way(%r12, %r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14474+ store_ctr_8way(%r14, %r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14475
14476- popq %r12;
14477+ popq %r14;
14478
14479+ pax_force_retaddr
14480 ret;
14481 ENDPROC(twofish_ctr_8way)
14482
14483@@ -430,6 +437,7 @@ ENTRY(twofish_xts_enc_8way)
14484 /* dst <= regs xor IVs(in dst) */
14485 store_xts_8way(%r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14486
14487+ pax_force_retaddr
14488 ret;
14489 ENDPROC(twofish_xts_enc_8way)
14490
14491@@ -452,5 +460,6 @@ ENTRY(twofish_xts_dec_8way)
14492 /* dst <= regs xor IVs(in dst) */
14493 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14494
14495+ pax_force_retaddr
14496 ret;
14497 ENDPROC(twofish_xts_dec_8way)
14498diff --git a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
14499index 1c3b7ce..02f578d 100644
14500--- a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
14501+++ b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
14502@@ -21,6 +21,7 @@
14503 */
14504
14505 #include <linux/linkage.h>
14506+#include <asm/alternative-asm.h>
14507
14508 .file "twofish-x86_64-asm-3way.S"
14509 .text
14510@@ -258,6 +259,7 @@ ENTRY(__twofish_enc_blk_3way)
14511 popq %r13;
14512 popq %r14;
14513 popq %r15;
14514+ pax_force_retaddr
14515 ret;
14516
14517 .L__enc_xor3:
14518@@ -269,6 +271,7 @@ ENTRY(__twofish_enc_blk_3way)
14519 popq %r13;
14520 popq %r14;
14521 popq %r15;
14522+ pax_force_retaddr
14523 ret;
14524 ENDPROC(__twofish_enc_blk_3way)
14525
14526@@ -308,5 +311,6 @@ ENTRY(twofish_dec_blk_3way)
14527 popq %r13;
14528 popq %r14;
14529 popq %r15;
14530+ pax_force_retaddr
14531 ret;
14532 ENDPROC(twofish_dec_blk_3way)
14533diff --git a/arch/x86/crypto/twofish-x86_64-asm_64.S b/arch/x86/crypto/twofish-x86_64-asm_64.S
14534index a039d21..524b8b2 100644
14535--- a/arch/x86/crypto/twofish-x86_64-asm_64.S
14536+++ b/arch/x86/crypto/twofish-x86_64-asm_64.S
14537@@ -22,6 +22,7 @@
14538
14539 #include <linux/linkage.h>
14540 #include <asm/asm-offsets.h>
14541+#include <asm/alternative-asm.h>
14542
14543 #define a_offset 0
14544 #define b_offset 4
14545@@ -265,6 +266,7 @@ ENTRY(twofish_enc_blk)
14546
14547 popq R1
14548 movq $1,%rax
14549+ pax_force_retaddr
14550 ret
14551 ENDPROC(twofish_enc_blk)
14552
14553@@ -317,5 +319,6 @@ ENTRY(twofish_dec_blk)
14554
14555 popq R1
14556 movq $1,%rax
14557+ pax_force_retaddr
14558 ret
14559 ENDPROC(twofish_dec_blk)
14560diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
14561index df91466..74b31cb 100644
14562--- a/arch/x86/ia32/ia32_aout.c
14563+++ b/arch/x86/ia32/ia32_aout.c
14564@@ -153,6 +153,8 @@ static int aout_core_dump(struct coredump_params *cprm)
14565 unsigned long dump_start, dump_size;
14566 struct user32 dump;
14567
14568+ memset(&dump, 0, sizeof(dump));
14569+
14570 fs = get_fs();
14571 set_fs(KERNEL_DS);
14572 has_dumped = 1;
14573diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
14574index f9e181a..300544c 100644
14575--- a/arch/x86/ia32/ia32_signal.c
14576+++ b/arch/x86/ia32/ia32_signal.c
14577@@ -218,7 +218,7 @@ asmlinkage long sys32_sigreturn(void)
14578 if (__get_user(set.sig[0], &frame->sc.oldmask)
14579 || (_COMPAT_NSIG_WORDS > 1
14580 && __copy_from_user((((char *) &set.sig) + 4),
14581- &frame->extramask,
14582+ frame->extramask,
14583 sizeof(frame->extramask))))
14584 goto badframe;
14585
14586@@ -338,7 +338,7 @@ static void __user *get_sigframe(struct ksignal *ksig, struct pt_regs *regs,
14587 sp -= frame_size;
14588 /* Align the stack pointer according to the i386 ABI,
14589 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
14590- sp = ((sp + 4) & -16ul) - 4;
14591+ sp = ((sp - 12) & -16ul) - 4;
14592 return (void __user *) sp;
14593 }
14594
14595@@ -383,10 +383,10 @@ int ia32_setup_frame(int sig, struct ksignal *ksig,
14596 } else {
14597 /* Return stub is in 32bit vsyscall page */
14598 if (current->mm->context.vdso)
14599- restorer = current->mm->context.vdso +
14600- selected_vdso32->sym___kernel_sigreturn;
14601+ restorer = (void __force_user *)(current->mm->context.vdso +
14602+ selected_vdso32->sym___kernel_sigreturn);
14603 else
14604- restorer = &frame->retcode;
14605+ restorer = frame->retcode;
14606 }
14607
14608 put_user_try {
14609@@ -396,7 +396,7 @@ int ia32_setup_frame(int sig, struct ksignal *ksig,
14610 * These are actually not used anymore, but left because some
14611 * gdb versions depend on them as a marker.
14612 */
14613- put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
14614+ put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
14615 } put_user_catch(err);
14616
14617 if (err)
14618@@ -438,7 +438,7 @@ int ia32_setup_rt_frame(int sig, struct ksignal *ksig,
14619 0xb8,
14620 __NR_ia32_rt_sigreturn,
14621 0x80cd,
14622- 0,
14623+ 0
14624 };
14625
14626 frame = get_sigframe(ksig, regs, sizeof(*frame), &fpstate);
14627@@ -461,16 +461,19 @@ int ia32_setup_rt_frame(int sig, struct ksignal *ksig,
14628
14629 if (ksig->ka.sa.sa_flags & SA_RESTORER)
14630 restorer = ksig->ka.sa.sa_restorer;
14631+ else if (current->mm->context.vdso)
14632+ /* Return stub is in 32bit vsyscall page */
14633+ restorer = (void __force_user *)(current->mm->context.vdso +
14634+ selected_vdso32->sym___kernel_rt_sigreturn);
14635 else
14636- restorer = current->mm->context.vdso +
14637- selected_vdso32->sym___kernel_rt_sigreturn;
14638+ restorer = frame->retcode;
14639 put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
14640
14641 /*
14642 * Not actually used anymore, but left because some gdb
14643 * versions need it.
14644 */
14645- put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
14646+ put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
14647 } put_user_catch(err);
14648
14649 err |= copy_siginfo_to_user32(&frame->info, &ksig->info);
14650diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
14651index ffe7122..899bad3 100644
14652--- a/arch/x86/ia32/ia32entry.S
14653+++ b/arch/x86/ia32/ia32entry.S
14654@@ -15,8 +15,10 @@
14655 #include <asm/irqflags.h>
14656 #include <asm/asm.h>
14657 #include <asm/smap.h>
14658+#include <asm/pgtable.h>
14659 #include <linux/linkage.h>
14660 #include <linux/err.h>
14661+#include <asm/alternative-asm.h>
14662
14663 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
14664 #include <linux/elf-em.h>
14665@@ -62,12 +64,12 @@
14666 */
14667 .macro LOAD_ARGS32 offset, _r9=0
14668 .if \_r9
14669- movl \offset+16(%rsp),%r9d
14670+ movl \offset+R9(%rsp),%r9d
14671 .endif
14672- movl \offset+40(%rsp),%ecx
14673- movl \offset+48(%rsp),%edx
14674- movl \offset+56(%rsp),%esi
14675- movl \offset+64(%rsp),%edi
14676+ movl \offset+RCX(%rsp),%ecx
14677+ movl \offset+RDX(%rsp),%edx
14678+ movl \offset+RSI(%rsp),%esi
14679+ movl \offset+RDI(%rsp),%edi
14680 movl %eax,%eax /* zero extension */
14681 .endm
14682
14683@@ -96,6 +98,32 @@ ENTRY(native_irq_enable_sysexit)
14684 ENDPROC(native_irq_enable_sysexit)
14685 #endif
14686
14687+ .macro pax_enter_kernel_user
14688+ pax_set_fptr_mask
14689+#ifdef CONFIG_PAX_MEMORY_UDEREF
14690+ call pax_enter_kernel_user
14691+#endif
14692+ .endm
14693+
14694+ .macro pax_exit_kernel_user
14695+#ifdef CONFIG_PAX_MEMORY_UDEREF
14696+ call pax_exit_kernel_user
14697+#endif
14698+#ifdef CONFIG_PAX_RANDKSTACK
14699+ pushq %rax
14700+ pushq %r11
14701+ call pax_randomize_kstack
14702+ popq %r11
14703+ popq %rax
14704+#endif
14705+ .endm
14706+
14707+ .macro pax_erase_kstack
14708+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14709+ call pax_erase_kstack
14710+#endif
14711+ .endm
14712+
14713 /*
14714 * 32bit SYSENTER instruction entry.
14715 *
14716@@ -122,12 +150,6 @@ ENTRY(ia32_sysenter_target)
14717 CFI_REGISTER rsp,rbp
14718 SWAPGS_UNSAFE_STACK
14719 movq PER_CPU_VAR(kernel_stack), %rsp
14720- addq $(KERNEL_STACK_OFFSET),%rsp
14721- /*
14722- * No need to follow this irqs on/off section: the syscall
14723- * disabled irqs, here we enable it straight after entry:
14724- */
14725- ENABLE_INTERRUPTS(CLBR_NONE)
14726 movl %ebp,%ebp /* zero extension */
14727 pushq_cfi $__USER32_DS
14728 /*CFI_REL_OFFSET ss,0*/
14729@@ -135,23 +157,46 @@ ENTRY(ia32_sysenter_target)
14730 CFI_REL_OFFSET rsp,0
14731 pushfq_cfi
14732 /*CFI_REL_OFFSET rflags,0*/
14733- movl TI_sysenter_return+THREAD_INFO(%rsp,3*8-KERNEL_STACK_OFFSET),%r10d
14734- CFI_REGISTER rip,r10
14735+ orl $X86_EFLAGS_IF,(%rsp)
14736+ GET_THREAD_INFO(%r11)
14737+ movl TI_sysenter_return(%r11), %r11d
14738+ CFI_REGISTER rip,r11
14739 pushq_cfi $__USER32_CS
14740 /*CFI_REL_OFFSET cs,0*/
14741 movl %eax, %eax
14742- pushq_cfi %r10
14743+ pushq_cfi %r11
14744 CFI_REL_OFFSET rip,0
14745 pushq_cfi %rax
14746 cld
14747 SAVE_ARGS 0,1,0
14748+ pax_enter_kernel_user
14749+
14750+#ifdef CONFIG_PAX_RANDKSTACK
14751+ pax_erase_kstack
14752+#endif
14753+
14754+ /*
14755+ * No need to follow this irqs on/off section: the syscall
14756+ * disabled irqs, here we enable it straight after entry:
14757+ */
14758+ ENABLE_INTERRUPTS(CLBR_NONE)
14759 /* no need to do an access_ok check here because rbp has been
14760 32bit zero extended */
14761+
14762+#ifdef CONFIG_PAX_MEMORY_UDEREF
14763+ addq pax_user_shadow_base,%rbp
14764+ ASM_PAX_OPEN_USERLAND
14765+#endif
14766+
14767 ASM_STAC
14768 1: movl (%rbp),%ebp
14769 _ASM_EXTABLE(1b,ia32_badarg)
14770 ASM_CLAC
14771
14772+#ifdef CONFIG_PAX_MEMORY_UDEREF
14773+ ASM_PAX_CLOSE_USERLAND
14774+#endif
14775+
14776 /*
14777 * Sysenter doesn't filter flags, so we need to clear NT
14778 * ourselves. To save a few cycles, we can check whether
14779@@ -161,8 +206,9 @@ ENTRY(ia32_sysenter_target)
14780 jnz sysenter_fix_flags
14781 sysenter_flags_fixed:
14782
14783- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14784- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14785+ GET_THREAD_INFO(%r11)
14786+ orl $TS_COMPAT,TI_status(%r11)
14787+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
14788 CFI_REMEMBER_STATE
14789 jnz sysenter_tracesys
14790 cmpq $(IA32_NR_syscalls-1),%rax
14791@@ -172,15 +218,18 @@ sysenter_do_call:
14792 sysenter_dispatch:
14793 call *ia32_sys_call_table(,%rax,8)
14794 movq %rax,RAX-ARGOFFSET(%rsp)
14795+ GET_THREAD_INFO(%r11)
14796 DISABLE_INTERRUPTS(CLBR_NONE)
14797 TRACE_IRQS_OFF
14798- testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14799+ testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
14800 jnz sysexit_audit
14801 sysexit_from_sys_call:
14802- andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14803+ pax_exit_kernel_user
14804+ pax_erase_kstack
14805+ andl $~TS_COMPAT,TI_status(%r11)
14806 /* clear IF, that popfq doesn't enable interrupts early */
14807- andl $~0x200,EFLAGS-R11(%rsp)
14808- movl RIP-R11(%rsp),%edx /* User %eip */
14809+ andl $~X86_EFLAGS_IF,EFLAGS(%rsp)
14810+ movl RIP(%rsp),%edx /* User %eip */
14811 CFI_REGISTER rip,rdx
14812 RESTORE_ARGS 0,24,0,0,0,0
14813 xorq %r8,%r8
14814@@ -205,6 +254,9 @@ sysexit_from_sys_call:
14815 movl %ebx,%esi /* 2nd arg: 1st syscall arg */
14816 movl %eax,%edi /* 1st arg: syscall number */
14817 call __audit_syscall_entry
14818+
14819+ pax_erase_kstack
14820+
14821 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
14822 cmpq $(IA32_NR_syscalls-1),%rax
14823 ja ia32_badsys
14824@@ -216,7 +268,7 @@ sysexit_from_sys_call:
14825 .endm
14826
14827 .macro auditsys_exit exit
14828- testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14829+ testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
14830 jnz ia32_ret_from_sys_call
14831 TRACE_IRQS_ON
14832 ENABLE_INTERRUPTS(CLBR_NONE)
14833@@ -227,11 +279,12 @@ sysexit_from_sys_call:
14834 1: setbe %al /* 1 if error, 0 if not */
14835 movzbl %al,%edi /* zero-extend that into %edi */
14836 call __audit_syscall_exit
14837+ GET_THREAD_INFO(%r11)
14838 movq RAX-ARGOFFSET(%rsp),%rax /* reload syscall return value */
14839 movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi
14840 DISABLE_INTERRUPTS(CLBR_NONE)
14841 TRACE_IRQS_OFF
14842- testl %edi,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14843+ testl %edi,TI_flags(%r11)
14844 jz \exit
14845 CLEAR_RREGS -ARGOFFSET
14846 jmp int_with_check
14847@@ -253,7 +306,7 @@ sysenter_fix_flags:
14848
14849 sysenter_tracesys:
14850 #ifdef CONFIG_AUDITSYSCALL
14851- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14852+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
14853 jz sysenter_auditsys
14854 #endif
14855 SAVE_REST
14856@@ -265,6 +318,9 @@ sysenter_tracesys:
14857 RESTORE_REST
14858 cmpq $(IA32_NR_syscalls-1),%rax
14859 ja int_ret_from_sys_call /* sysenter_tracesys has set RAX(%rsp) */
14860+
14861+ pax_erase_kstack
14862+
14863 jmp sysenter_do_call
14864 CFI_ENDPROC
14865 ENDPROC(ia32_sysenter_target)
14866@@ -292,19 +348,25 @@ ENDPROC(ia32_sysenter_target)
14867 ENTRY(ia32_cstar_target)
14868 CFI_STARTPROC32 simple
14869 CFI_SIGNAL_FRAME
14870- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
14871+ CFI_DEF_CFA rsp,0
14872 CFI_REGISTER rip,rcx
14873 /*CFI_REGISTER rflags,r11*/
14874 SWAPGS_UNSAFE_STACK
14875 movl %esp,%r8d
14876 CFI_REGISTER rsp,r8
14877 movq PER_CPU_VAR(kernel_stack),%rsp
14878+ SAVE_ARGS 8*6,0,0
14879+ pax_enter_kernel_user
14880+
14881+#ifdef CONFIG_PAX_RANDKSTACK
14882+ pax_erase_kstack
14883+#endif
14884+
14885 /*
14886 * No need to follow this irqs on/off section: the syscall
14887 * disabled irqs and here we enable it straight after entry:
14888 */
14889 ENABLE_INTERRUPTS(CLBR_NONE)
14890- SAVE_ARGS 8,0,0
14891 movl %eax,%eax /* zero extension */
14892 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
14893 movq %rcx,RIP-ARGOFFSET(%rsp)
14894@@ -320,12 +382,25 @@ ENTRY(ia32_cstar_target)
14895 /* no need to do an access_ok check here because r8 has been
14896 32bit zero extended */
14897 /* hardware stack frame is complete now */
14898+
14899+#ifdef CONFIG_PAX_MEMORY_UDEREF
14900+ ASM_PAX_OPEN_USERLAND
14901+ movq pax_user_shadow_base,%r8
14902+ addq RSP-ARGOFFSET(%rsp),%r8
14903+#endif
14904+
14905 ASM_STAC
14906 1: movl (%r8),%r9d
14907 _ASM_EXTABLE(1b,ia32_badarg)
14908 ASM_CLAC
14909- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14910- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14911+
14912+#ifdef CONFIG_PAX_MEMORY_UDEREF
14913+ ASM_PAX_CLOSE_USERLAND
14914+#endif
14915+
14916+ GET_THREAD_INFO(%r11)
14917+ orl $TS_COMPAT,TI_status(%r11)
14918+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
14919 CFI_REMEMBER_STATE
14920 jnz cstar_tracesys
14921 cmpq $IA32_NR_syscalls-1,%rax
14922@@ -335,13 +410,16 @@ cstar_do_call:
14923 cstar_dispatch:
14924 call *ia32_sys_call_table(,%rax,8)
14925 movq %rax,RAX-ARGOFFSET(%rsp)
14926+ GET_THREAD_INFO(%r11)
14927 DISABLE_INTERRUPTS(CLBR_NONE)
14928 TRACE_IRQS_OFF
14929- testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14930+ testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
14931 jnz sysretl_audit
14932 sysretl_from_sys_call:
14933- andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14934- RESTORE_ARGS 0,-ARG_SKIP,0,0,0
14935+ pax_exit_kernel_user
14936+ pax_erase_kstack
14937+ andl $~TS_COMPAT,TI_status(%r11)
14938+ RESTORE_ARGS 0,-ORIG_RAX,0,0,0
14939 movl RIP-ARGOFFSET(%rsp),%ecx
14940 CFI_REGISTER rip,rcx
14941 movl EFLAGS-ARGOFFSET(%rsp),%r11d
14942@@ -368,7 +446,7 @@ sysretl_audit:
14943
14944 cstar_tracesys:
14945 #ifdef CONFIG_AUDITSYSCALL
14946- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14947+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
14948 jz cstar_auditsys
14949 #endif
14950 xchgl %r9d,%ebp
14951@@ -382,11 +460,19 @@ cstar_tracesys:
14952 xchgl %ebp,%r9d
14953 cmpq $(IA32_NR_syscalls-1),%rax
14954 ja int_ret_from_sys_call /* cstar_tracesys has set RAX(%rsp) */
14955+
14956+ pax_erase_kstack
14957+
14958 jmp cstar_do_call
14959 END(ia32_cstar_target)
14960
14961 ia32_badarg:
14962 ASM_CLAC
14963+
14964+#ifdef CONFIG_PAX_MEMORY_UDEREF
14965+ ASM_PAX_CLOSE_USERLAND
14966+#endif
14967+
14968 movq $-EFAULT,%rax
14969 jmp ia32_sysret
14970 CFI_ENDPROC
14971@@ -423,19 +509,26 @@ ENTRY(ia32_syscall)
14972 CFI_REL_OFFSET rip,RIP-RIP
14973 PARAVIRT_ADJUST_EXCEPTION_FRAME
14974 SWAPGS
14975- /*
14976- * No need to follow this irqs on/off section: the syscall
14977- * disabled irqs and here we enable it straight after entry:
14978- */
14979- ENABLE_INTERRUPTS(CLBR_NONE)
14980 movl %eax,%eax
14981 pushq_cfi %rax
14982 cld
14983 /* note the registers are not zero extended to the sf.
14984 this could be a problem. */
14985 SAVE_ARGS 0,1,0
14986- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14987- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14988+ pax_enter_kernel_user
14989+
14990+#ifdef CONFIG_PAX_RANDKSTACK
14991+ pax_erase_kstack
14992+#endif
14993+
14994+ /*
14995+ * No need to follow this irqs on/off section: the syscall
14996+ * disabled irqs and here we enable it straight after entry:
14997+ */
14998+ ENABLE_INTERRUPTS(CLBR_NONE)
14999+ GET_THREAD_INFO(%r11)
15000+ orl $TS_COMPAT,TI_status(%r11)
15001+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
15002 jnz ia32_tracesys
15003 cmpq $(IA32_NR_syscalls-1),%rax
15004 ja ia32_badsys
15005@@ -458,6 +551,9 @@ ia32_tracesys:
15006 RESTORE_REST
15007 cmpq $(IA32_NR_syscalls-1),%rax
15008 ja int_ret_from_sys_call /* ia32_tracesys has set RAX(%rsp) */
15009+
15010+ pax_erase_kstack
15011+
15012 jmp ia32_do_call
15013 END(ia32_syscall)
15014
15015diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c
15016index 8e0ceec..af13504 100644
15017--- a/arch/x86/ia32/sys_ia32.c
15018+++ b/arch/x86/ia32/sys_ia32.c
15019@@ -69,8 +69,8 @@ asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long offset_low,
15020 */
15021 static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
15022 {
15023- typeof(ubuf->st_uid) uid = 0;
15024- typeof(ubuf->st_gid) gid = 0;
15025+ typeof(((struct stat64 *)0)->st_uid) uid = 0;
15026+ typeof(((struct stat64 *)0)->st_gid) gid = 0;
15027 SET_UID(uid, from_kuid_munged(current_user_ns(), stat->uid));
15028 SET_GID(gid, from_kgid_munged(current_user_ns(), stat->gid));
15029 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
15030diff --git a/arch/x86/include/asm/alternative-asm.h b/arch/x86/include/asm/alternative-asm.h
15031index 372231c..51b537d 100644
15032--- a/arch/x86/include/asm/alternative-asm.h
15033+++ b/arch/x86/include/asm/alternative-asm.h
15034@@ -18,6 +18,45 @@
15035 .endm
15036 #endif
15037
15038+#ifdef KERNEXEC_PLUGIN
15039+ .macro pax_force_retaddr_bts rip=0
15040+ btsq $63,\rip(%rsp)
15041+ .endm
15042+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
15043+ .macro pax_force_retaddr rip=0, reload=0
15044+ btsq $63,\rip(%rsp)
15045+ .endm
15046+ .macro pax_force_fptr ptr
15047+ btsq $63,\ptr
15048+ .endm
15049+ .macro pax_set_fptr_mask
15050+ .endm
15051+#endif
15052+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
15053+ .macro pax_force_retaddr rip=0, reload=0
15054+ .if \reload
15055+ pax_set_fptr_mask
15056+ .endif
15057+ orq %r12,\rip(%rsp)
15058+ .endm
15059+ .macro pax_force_fptr ptr
15060+ orq %r12,\ptr
15061+ .endm
15062+ .macro pax_set_fptr_mask
15063+ movabs $0x8000000000000000,%r12
15064+ .endm
15065+#endif
15066+#else
15067+ .macro pax_force_retaddr rip=0, reload=0
15068+ .endm
15069+ .macro pax_force_fptr ptr
15070+ .endm
15071+ .macro pax_force_retaddr_bts rip=0
15072+ .endm
15073+ .macro pax_set_fptr_mask
15074+ .endm
15075+#endif
15076+
15077 .macro altinstruction_entry orig alt feature orig_len alt_len
15078 .long \orig - .
15079 .long \alt - .
15080diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h
15081index 473bdbe..b1e3377 100644
15082--- a/arch/x86/include/asm/alternative.h
15083+++ b/arch/x86/include/asm/alternative.h
15084@@ -106,7 +106,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
15085 ".pushsection .discard,\"aw\",@progbits\n" \
15086 DISCARD_ENTRY(1) \
15087 ".popsection\n" \
15088- ".pushsection .altinstr_replacement, \"ax\"\n" \
15089+ ".pushsection .altinstr_replacement, \"a\"\n" \
15090 ALTINSTR_REPLACEMENT(newinstr, feature, 1) \
15091 ".popsection"
15092
15093@@ -120,7 +120,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
15094 DISCARD_ENTRY(1) \
15095 DISCARD_ENTRY(2) \
15096 ".popsection\n" \
15097- ".pushsection .altinstr_replacement, \"ax\"\n" \
15098+ ".pushsection .altinstr_replacement, \"a\"\n" \
15099 ALTINSTR_REPLACEMENT(newinstr1, feature1, 1) \
15100 ALTINSTR_REPLACEMENT(newinstr2, feature2, 2) \
15101 ".popsection"
15102diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
15103index 465b309..ab7e51f 100644
15104--- a/arch/x86/include/asm/apic.h
15105+++ b/arch/x86/include/asm/apic.h
15106@@ -45,7 +45,7 @@ static inline void generic_apic_probe(void)
15107
15108 #ifdef CONFIG_X86_LOCAL_APIC
15109
15110-extern unsigned int apic_verbosity;
15111+extern int apic_verbosity;
15112 extern int local_apic_timer_c2_ok;
15113
15114 extern int disable_apic;
15115diff --git a/arch/x86/include/asm/apm.h b/arch/x86/include/asm/apm.h
15116index 20370c6..a2eb9b0 100644
15117--- a/arch/x86/include/asm/apm.h
15118+++ b/arch/x86/include/asm/apm.h
15119@@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32 func, u32 ebx_in, u32 ecx_in,
15120 __asm__ __volatile__(APM_DO_ZERO_SEGS
15121 "pushl %%edi\n\t"
15122 "pushl %%ebp\n\t"
15123- "lcall *%%cs:apm_bios_entry\n\t"
15124+ "lcall *%%ss:apm_bios_entry\n\t"
15125 "setc %%al\n\t"
15126 "popl %%ebp\n\t"
15127 "popl %%edi\n\t"
15128@@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_asm(u32 func, u32 ebx_in,
15129 __asm__ __volatile__(APM_DO_ZERO_SEGS
15130 "pushl %%edi\n\t"
15131 "pushl %%ebp\n\t"
15132- "lcall *%%cs:apm_bios_entry\n\t"
15133+ "lcall *%%ss:apm_bios_entry\n\t"
15134 "setc %%bl\n\t"
15135 "popl %%ebp\n\t"
15136 "popl %%edi\n\t"
15137diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h
15138index 5e5cd12..3d18208 100644
15139--- a/arch/x86/include/asm/atomic.h
15140+++ b/arch/x86/include/asm/atomic.h
15141@@ -28,6 +28,17 @@ static inline int atomic_read(const atomic_t *v)
15142 }
15143
15144 /**
15145+ * atomic_read_unchecked - read atomic variable
15146+ * @v: pointer of type atomic_unchecked_t
15147+ *
15148+ * Atomically reads the value of @v.
15149+ */
15150+static inline int __intentional_overflow(-1) atomic_read_unchecked(const atomic_unchecked_t *v)
15151+{
15152+ return ACCESS_ONCE((v)->counter);
15153+}
15154+
15155+/**
15156 * atomic_set - set atomic variable
15157 * @v: pointer of type atomic_t
15158 * @i: required value
15159@@ -40,6 +51,18 @@ static inline void atomic_set(atomic_t *v, int i)
15160 }
15161
15162 /**
15163+ * atomic_set_unchecked - set atomic variable
15164+ * @v: pointer of type atomic_unchecked_t
15165+ * @i: required value
15166+ *
15167+ * Atomically sets the value of @v to @i.
15168+ */
15169+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
15170+{
15171+ v->counter = i;
15172+}
15173+
15174+/**
15175 * atomic_add - add integer to atomic variable
15176 * @i: integer value to add
15177 * @v: pointer of type atomic_t
15178@@ -48,7 +71,29 @@ static inline void atomic_set(atomic_t *v, int i)
15179 */
15180 static inline void atomic_add(int i, atomic_t *v)
15181 {
15182- asm volatile(LOCK_PREFIX "addl %1,%0"
15183+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
15184+
15185+#ifdef CONFIG_PAX_REFCOUNT
15186+ "jno 0f\n"
15187+ LOCK_PREFIX "subl %1,%0\n"
15188+ "int $4\n0:\n"
15189+ _ASM_EXTABLE(0b, 0b)
15190+#endif
15191+
15192+ : "+m" (v->counter)
15193+ : "ir" (i));
15194+}
15195+
15196+/**
15197+ * atomic_add_unchecked - add integer to atomic variable
15198+ * @i: integer value to add
15199+ * @v: pointer of type atomic_unchecked_t
15200+ *
15201+ * Atomically adds @i to @v.
15202+ */
15203+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
15204+{
15205+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
15206 : "+m" (v->counter)
15207 : "ir" (i));
15208 }
15209@@ -62,7 +107,29 @@ static inline void atomic_add(int i, atomic_t *v)
15210 */
15211 static inline void atomic_sub(int i, atomic_t *v)
15212 {
15213- asm volatile(LOCK_PREFIX "subl %1,%0"
15214+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
15215+
15216+#ifdef CONFIG_PAX_REFCOUNT
15217+ "jno 0f\n"
15218+ LOCK_PREFIX "addl %1,%0\n"
15219+ "int $4\n0:\n"
15220+ _ASM_EXTABLE(0b, 0b)
15221+#endif
15222+
15223+ : "+m" (v->counter)
15224+ : "ir" (i));
15225+}
15226+
15227+/**
15228+ * atomic_sub_unchecked - subtract integer from atomic variable
15229+ * @i: integer value to subtract
15230+ * @v: pointer of type atomic_unchecked_t
15231+ *
15232+ * Atomically subtracts @i from @v.
15233+ */
15234+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
15235+{
15236+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
15237 : "+m" (v->counter)
15238 : "ir" (i));
15239 }
15240@@ -78,7 +145,7 @@ static inline void atomic_sub(int i, atomic_t *v)
15241 */
15242 static inline int atomic_sub_and_test(int i, atomic_t *v)
15243 {
15244- GEN_BINARY_RMWcc(LOCK_PREFIX "subl", v->counter, "er", i, "%0", "e");
15245+ GEN_BINARY_RMWcc(LOCK_PREFIX "subl", LOCK_PREFIX "addl", v->counter, "er", i, "%0", "e");
15246 }
15247
15248 /**
15249@@ -89,7 +156,27 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
15250 */
15251 static inline void atomic_inc(atomic_t *v)
15252 {
15253- asm volatile(LOCK_PREFIX "incl %0"
15254+ asm volatile(LOCK_PREFIX "incl %0\n"
15255+
15256+#ifdef CONFIG_PAX_REFCOUNT
15257+ "jno 0f\n"
15258+ LOCK_PREFIX "decl %0\n"
15259+ "int $4\n0:\n"
15260+ _ASM_EXTABLE(0b, 0b)
15261+#endif
15262+
15263+ : "+m" (v->counter));
15264+}
15265+
15266+/**
15267+ * atomic_inc_unchecked - increment atomic variable
15268+ * @v: pointer of type atomic_unchecked_t
15269+ *
15270+ * Atomically increments @v by 1.
15271+ */
15272+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
15273+{
15274+ asm volatile(LOCK_PREFIX "incl %0\n"
15275 : "+m" (v->counter));
15276 }
15277
15278@@ -101,7 +188,27 @@ static inline void atomic_inc(atomic_t *v)
15279 */
15280 static inline void atomic_dec(atomic_t *v)
15281 {
15282- asm volatile(LOCK_PREFIX "decl %0"
15283+ asm volatile(LOCK_PREFIX "decl %0\n"
15284+
15285+#ifdef CONFIG_PAX_REFCOUNT
15286+ "jno 0f\n"
15287+ LOCK_PREFIX "incl %0\n"
15288+ "int $4\n0:\n"
15289+ _ASM_EXTABLE(0b, 0b)
15290+#endif
15291+
15292+ : "+m" (v->counter));
15293+}
15294+
15295+/**
15296+ * atomic_dec_unchecked - decrement atomic variable
15297+ * @v: pointer of type atomic_unchecked_t
15298+ *
15299+ * Atomically decrements @v by 1.
15300+ */
15301+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
15302+{
15303+ asm volatile(LOCK_PREFIX "decl %0\n"
15304 : "+m" (v->counter));
15305 }
15306
15307@@ -115,7 +222,7 @@ static inline void atomic_dec(atomic_t *v)
15308 */
15309 static inline int atomic_dec_and_test(atomic_t *v)
15310 {
15311- GEN_UNARY_RMWcc(LOCK_PREFIX "decl", v->counter, "%0", "e");
15312+ GEN_UNARY_RMWcc(LOCK_PREFIX "decl", LOCK_PREFIX "incl", v->counter, "%0", "e");
15313 }
15314
15315 /**
15316@@ -128,7 +235,20 @@ static inline int atomic_dec_and_test(atomic_t *v)
15317 */
15318 static inline int atomic_inc_and_test(atomic_t *v)
15319 {
15320- GEN_UNARY_RMWcc(LOCK_PREFIX "incl", v->counter, "%0", "e");
15321+ GEN_UNARY_RMWcc(LOCK_PREFIX "incl", LOCK_PREFIX "decl", v->counter, "%0", "e");
15322+}
15323+
15324+/**
15325+ * atomic_inc_and_test_unchecked - increment and test
15326+ * @v: pointer of type atomic_unchecked_t
15327+ *
15328+ * Atomically increments @v by 1
15329+ * and returns true if the result is zero, or false for all
15330+ * other cases.
15331+ */
15332+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
15333+{
15334+ GEN_UNARY_RMWcc_unchecked(LOCK_PREFIX "incl", v->counter, "%0", "e");
15335 }
15336
15337 /**
15338@@ -142,7 +262,7 @@ static inline int atomic_inc_and_test(atomic_t *v)
15339 */
15340 static inline int atomic_add_negative(int i, atomic_t *v)
15341 {
15342- GEN_BINARY_RMWcc(LOCK_PREFIX "addl", v->counter, "er", i, "%0", "s");
15343+ GEN_BINARY_RMWcc(LOCK_PREFIX "addl", LOCK_PREFIX "subl", v->counter, "er", i, "%0", "s");
15344 }
15345
15346 /**
15347@@ -152,7 +272,19 @@ static inline int atomic_add_negative(int i, atomic_t *v)
15348 *
15349 * Atomically adds @i to @v and returns @i + @v
15350 */
15351-static inline int atomic_add_return(int i, atomic_t *v)
15352+static inline int __intentional_overflow(-1) atomic_add_return(int i, atomic_t *v)
15353+{
15354+ return i + xadd_check_overflow(&v->counter, i);
15355+}
15356+
15357+/**
15358+ * atomic_add_return_unchecked - add integer and return
15359+ * @i: integer value to add
15360+ * @v: pointer of type atomic_unchecked_t
15361+ *
15362+ * Atomically adds @i to @v and returns @i + @v
15363+ */
15364+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
15365 {
15366 return i + xadd(&v->counter, i);
15367 }
15368@@ -164,15 +296,24 @@ static inline int atomic_add_return(int i, atomic_t *v)
15369 *
15370 * Atomically subtracts @i from @v and returns @v - @i
15371 */
15372-static inline int atomic_sub_return(int i, atomic_t *v)
15373+static inline int __intentional_overflow(-1) atomic_sub_return(int i, atomic_t *v)
15374 {
15375 return atomic_add_return(-i, v);
15376 }
15377
15378 #define atomic_inc_return(v) (atomic_add_return(1, v))
15379+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
15380+{
15381+ return atomic_add_return_unchecked(1, v);
15382+}
15383 #define atomic_dec_return(v) (atomic_sub_return(1, v))
15384
15385-static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
15386+static inline int __intentional_overflow(-1) atomic_cmpxchg(atomic_t *v, int old, int new)
15387+{
15388+ return cmpxchg(&v->counter, old, new);
15389+}
15390+
15391+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
15392 {
15393 return cmpxchg(&v->counter, old, new);
15394 }
15395@@ -182,6 +323,11 @@ static inline int atomic_xchg(atomic_t *v, int new)
15396 return xchg(&v->counter, new);
15397 }
15398
15399+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
15400+{
15401+ return xchg(&v->counter, new);
15402+}
15403+
15404 /**
15405 * __atomic_add_unless - add unless the number is already a given value
15406 * @v: pointer of type atomic_t
15407@@ -191,14 +337,27 @@ static inline int atomic_xchg(atomic_t *v, int new)
15408 * Atomically adds @a to @v, so long as @v was not already @u.
15409 * Returns the old value of @v.
15410 */
15411-static inline int __atomic_add_unless(atomic_t *v, int a, int u)
15412+static inline int __intentional_overflow(-1) __atomic_add_unless(atomic_t *v, int a, int u)
15413 {
15414- int c, old;
15415+ int c, old, new;
15416 c = atomic_read(v);
15417 for (;;) {
15418- if (unlikely(c == (u)))
15419+ if (unlikely(c == u))
15420 break;
15421- old = atomic_cmpxchg((v), c, c + (a));
15422+
15423+ asm volatile("addl %2,%0\n"
15424+
15425+#ifdef CONFIG_PAX_REFCOUNT
15426+ "jno 0f\n"
15427+ "subl %2,%0\n"
15428+ "int $4\n0:\n"
15429+ _ASM_EXTABLE(0b, 0b)
15430+#endif
15431+
15432+ : "=r" (new)
15433+ : "0" (c), "ir" (a));
15434+
15435+ old = atomic_cmpxchg(v, c, new);
15436 if (likely(old == c))
15437 break;
15438 c = old;
15439@@ -207,6 +366,49 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
15440 }
15441
15442 /**
15443+ * atomic_inc_not_zero_hint - increment if not null
15444+ * @v: pointer of type atomic_t
15445+ * @hint: probable value of the atomic before the increment
15446+ *
15447+ * This version of atomic_inc_not_zero() gives a hint of probable
15448+ * value of the atomic. This helps processor to not read the memory
15449+ * before doing the atomic read/modify/write cycle, lowering
15450+ * number of bus transactions on some arches.
15451+ *
15452+ * Returns: 0 if increment was not done, 1 otherwise.
15453+ */
15454+#define atomic_inc_not_zero_hint atomic_inc_not_zero_hint
15455+static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint)
15456+{
15457+ int val, c = hint, new;
15458+
15459+ /* sanity test, should be removed by compiler if hint is a constant */
15460+ if (!hint)
15461+ return __atomic_add_unless(v, 1, 0);
15462+
15463+ do {
15464+ asm volatile("incl %0\n"
15465+
15466+#ifdef CONFIG_PAX_REFCOUNT
15467+ "jno 0f\n"
15468+ "decl %0\n"
15469+ "int $4\n0:\n"
15470+ _ASM_EXTABLE(0b, 0b)
15471+#endif
15472+
15473+ : "=r" (new)
15474+ : "0" (c));
15475+
15476+ val = atomic_cmpxchg(v, c, new);
15477+ if (val == c)
15478+ return 1;
15479+ c = val;
15480+ } while (c);
15481+
15482+ return 0;
15483+}
15484+
15485+/**
15486 * atomic_inc_short - increment of a short integer
15487 * @v: pointer to type int
15488 *
15489@@ -220,14 +422,37 @@ static inline short int atomic_inc_short(short int *v)
15490 }
15491
15492 /* These are x86-specific, used by some header files */
15493-#define atomic_clear_mask(mask, addr) \
15494- asm volatile(LOCK_PREFIX "andl %0,%1" \
15495- : : "r" (~(mask)), "m" (*(addr)) : "memory")
15496+static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
15497+{
15498+ asm volatile(LOCK_PREFIX "andl %1,%0"
15499+ : "+m" (v->counter)
15500+ : "r" (~(mask))
15501+ : "memory");
15502+}
15503
15504-#define atomic_set_mask(mask, addr) \
15505- asm volatile(LOCK_PREFIX "orl %0,%1" \
15506- : : "r" ((unsigned)(mask)), "m" (*(addr)) \
15507- : "memory")
15508+static inline void atomic_clear_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
15509+{
15510+ asm volatile(LOCK_PREFIX "andl %1,%0"
15511+ : "+m" (v->counter)
15512+ : "r" (~(mask))
15513+ : "memory");
15514+}
15515+
15516+static inline void atomic_set_mask(unsigned int mask, atomic_t *v)
15517+{
15518+ asm volatile(LOCK_PREFIX "orl %1,%0"
15519+ : "+m" (v->counter)
15520+ : "r" (mask)
15521+ : "memory");
15522+}
15523+
15524+static inline void atomic_set_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
15525+{
15526+ asm volatile(LOCK_PREFIX "orl %1,%0"
15527+ : "+m" (v->counter)
15528+ : "r" (mask)
15529+ : "memory");
15530+}
15531
15532 #ifdef CONFIG_X86_32
15533 # include <asm/atomic64_32.h>
15534diff --git a/arch/x86/include/asm/atomic64_32.h b/arch/x86/include/asm/atomic64_32.h
15535index b154de7..bf18a5a 100644
15536--- a/arch/x86/include/asm/atomic64_32.h
15537+++ b/arch/x86/include/asm/atomic64_32.h
15538@@ -12,6 +12,14 @@ typedef struct {
15539 u64 __aligned(8) counter;
15540 } atomic64_t;
15541
15542+#ifdef CONFIG_PAX_REFCOUNT
15543+typedef struct {
15544+ u64 __aligned(8) counter;
15545+} atomic64_unchecked_t;
15546+#else
15547+typedef atomic64_t atomic64_unchecked_t;
15548+#endif
15549+
15550 #define ATOMIC64_INIT(val) { (val) }
15551
15552 #define __ATOMIC64_DECL(sym) void atomic64_##sym(atomic64_t *, ...)
15553@@ -37,21 +45,31 @@ typedef struct {
15554 ATOMIC64_DECL_ONE(sym##_386)
15555
15556 ATOMIC64_DECL_ONE(add_386);
15557+ATOMIC64_DECL_ONE(add_unchecked_386);
15558 ATOMIC64_DECL_ONE(sub_386);
15559+ATOMIC64_DECL_ONE(sub_unchecked_386);
15560 ATOMIC64_DECL_ONE(inc_386);
15561+ATOMIC64_DECL_ONE(inc_unchecked_386);
15562 ATOMIC64_DECL_ONE(dec_386);
15563+ATOMIC64_DECL_ONE(dec_unchecked_386);
15564 #endif
15565
15566 #define alternative_atomic64(f, out, in...) \
15567 __alternative_atomic64(f, f, ASM_OUTPUT2(out), ## in)
15568
15569 ATOMIC64_DECL(read);
15570+ATOMIC64_DECL(read_unchecked);
15571 ATOMIC64_DECL(set);
15572+ATOMIC64_DECL(set_unchecked);
15573 ATOMIC64_DECL(xchg);
15574 ATOMIC64_DECL(add_return);
15575+ATOMIC64_DECL(add_return_unchecked);
15576 ATOMIC64_DECL(sub_return);
15577+ATOMIC64_DECL(sub_return_unchecked);
15578 ATOMIC64_DECL(inc_return);
15579+ATOMIC64_DECL(inc_return_unchecked);
15580 ATOMIC64_DECL(dec_return);
15581+ATOMIC64_DECL(dec_return_unchecked);
15582 ATOMIC64_DECL(dec_if_positive);
15583 ATOMIC64_DECL(inc_not_zero);
15584 ATOMIC64_DECL(add_unless);
15585@@ -77,6 +95,21 @@ static inline long long atomic64_cmpxchg(atomic64_t *v, long long o, long long n
15586 }
15587
15588 /**
15589+ * atomic64_cmpxchg_unchecked - cmpxchg atomic64 variable
15590+ * @p: pointer to type atomic64_unchecked_t
15591+ * @o: expected value
15592+ * @n: new value
15593+ *
15594+ * Atomically sets @v to @n if it was equal to @o and returns
15595+ * the old value.
15596+ */
15597+
15598+static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long long o, long long n)
15599+{
15600+ return cmpxchg64(&v->counter, o, n);
15601+}
15602+
15603+/**
15604 * atomic64_xchg - xchg atomic64 variable
15605 * @v: pointer to type atomic64_t
15606 * @n: value to assign
15607@@ -112,6 +145,22 @@ static inline void atomic64_set(atomic64_t *v, long long i)
15608 }
15609
15610 /**
15611+ * atomic64_set_unchecked - set atomic64 variable
15612+ * @v: pointer to type atomic64_unchecked_t
15613+ * @n: value to assign
15614+ *
15615+ * Atomically sets the value of @v to @n.
15616+ */
15617+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
15618+{
15619+ unsigned high = (unsigned)(i >> 32);
15620+ unsigned low = (unsigned)i;
15621+ alternative_atomic64(set, /* no output */,
15622+ "S" (v), "b" (low), "c" (high)
15623+ : "eax", "edx", "memory");
15624+}
15625+
15626+/**
15627 * atomic64_read - read atomic64 variable
15628 * @v: pointer to type atomic64_t
15629 *
15630@@ -125,6 +174,19 @@ static inline long long atomic64_read(const atomic64_t *v)
15631 }
15632
15633 /**
15634+ * atomic64_read_unchecked - read atomic64 variable
15635+ * @v: pointer to type atomic64_unchecked_t
15636+ *
15637+ * Atomically reads the value of @v and returns it.
15638+ */
15639+static inline long long __intentional_overflow(-1) atomic64_read_unchecked(atomic64_unchecked_t *v)
15640+{
15641+ long long r;
15642+ alternative_atomic64(read, "=&A" (r), "c" (v) : "memory");
15643+ return r;
15644+ }
15645+
15646+/**
15647 * atomic64_add_return - add and return
15648 * @i: integer value to add
15649 * @v: pointer to type atomic64_t
15650@@ -139,6 +201,21 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
15651 return i;
15652 }
15653
15654+/**
15655+ * atomic64_add_return_unchecked - add and return
15656+ * @i: integer value to add
15657+ * @v: pointer to type atomic64_unchecked_t
15658+ *
15659+ * Atomically adds @i to @v and returns @i + *@v
15660+ */
15661+static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
15662+{
15663+ alternative_atomic64(add_return_unchecked,
15664+ ASM_OUTPUT2("+A" (i), "+c" (v)),
15665+ ASM_NO_INPUT_CLOBBER("memory"));
15666+ return i;
15667+}
15668+
15669 /*
15670 * Other variants with different arithmetic operators:
15671 */
15672@@ -158,6 +235,14 @@ static inline long long atomic64_inc_return(atomic64_t *v)
15673 return a;
15674 }
15675
15676+static inline long long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
15677+{
15678+ long long a;
15679+ alternative_atomic64(inc_return_unchecked, "=&A" (a),
15680+ "S" (v) : "memory", "ecx");
15681+ return a;
15682+}
15683+
15684 static inline long long atomic64_dec_return(atomic64_t *v)
15685 {
15686 long long a;
15687@@ -182,6 +267,21 @@ static inline long long atomic64_add(long long i, atomic64_t *v)
15688 }
15689
15690 /**
15691+ * atomic64_add_unchecked - add integer to atomic64 variable
15692+ * @i: integer value to add
15693+ * @v: pointer to type atomic64_unchecked_t
15694+ *
15695+ * Atomically adds @i to @v.
15696+ */
15697+static inline long long atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
15698+{
15699+ __alternative_atomic64(add_unchecked, add_return_unchecked,
15700+ ASM_OUTPUT2("+A" (i), "+c" (v)),
15701+ ASM_NO_INPUT_CLOBBER("memory"));
15702+ return i;
15703+}
15704+
15705+/**
15706 * atomic64_sub - subtract the atomic64 variable
15707 * @i: integer value to subtract
15708 * @v: pointer to type atomic64_t
15709diff --git a/arch/x86/include/asm/atomic64_64.h b/arch/x86/include/asm/atomic64_64.h
15710index f8d273e..02f39f3 100644
15711--- a/arch/x86/include/asm/atomic64_64.h
15712+++ b/arch/x86/include/asm/atomic64_64.h
15713@@ -22,6 +22,18 @@ static inline long atomic64_read(const atomic64_t *v)
15714 }
15715
15716 /**
15717+ * atomic64_read_unchecked - read atomic64 variable
15718+ * @v: pointer of type atomic64_unchecked_t
15719+ *
15720+ * Atomically reads the value of @v.
15721+ * Doesn't imply a read memory barrier.
15722+ */
15723+static inline long __intentional_overflow(-1) atomic64_read_unchecked(const atomic64_unchecked_t *v)
15724+{
15725+ return ACCESS_ONCE((v)->counter);
15726+}
15727+
15728+/**
15729 * atomic64_set - set atomic64 variable
15730 * @v: pointer to type atomic64_t
15731 * @i: required value
15732@@ -34,6 +46,18 @@ static inline void atomic64_set(atomic64_t *v, long i)
15733 }
15734
15735 /**
15736+ * atomic64_set_unchecked - set atomic64 variable
15737+ * @v: pointer to type atomic64_unchecked_t
15738+ * @i: required value
15739+ *
15740+ * Atomically sets the value of @v to @i.
15741+ */
15742+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
15743+{
15744+ v->counter = i;
15745+}
15746+
15747+/**
15748 * atomic64_add - add integer to atomic64 variable
15749 * @i: integer value to add
15750 * @v: pointer to type atomic64_t
15751@@ -42,6 +66,28 @@ static inline void atomic64_set(atomic64_t *v, long i)
15752 */
15753 static inline void atomic64_add(long i, atomic64_t *v)
15754 {
15755+ asm volatile(LOCK_PREFIX "addq %1,%0\n"
15756+
15757+#ifdef CONFIG_PAX_REFCOUNT
15758+ "jno 0f\n"
15759+ LOCK_PREFIX "subq %1,%0\n"
15760+ "int $4\n0:\n"
15761+ _ASM_EXTABLE(0b, 0b)
15762+#endif
15763+
15764+ : "=m" (v->counter)
15765+ : "er" (i), "m" (v->counter));
15766+}
15767+
15768+/**
15769+ * atomic64_add_unchecked - add integer to atomic64 variable
15770+ * @i: integer value to add
15771+ * @v: pointer to type atomic64_unchecked_t
15772+ *
15773+ * Atomically adds @i to @v.
15774+ */
15775+static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
15776+{
15777 asm volatile(LOCK_PREFIX "addq %1,%0"
15778 : "=m" (v->counter)
15779 : "er" (i), "m" (v->counter));
15780@@ -56,7 +102,29 @@ static inline void atomic64_add(long i, atomic64_t *v)
15781 */
15782 static inline void atomic64_sub(long i, atomic64_t *v)
15783 {
15784- asm volatile(LOCK_PREFIX "subq %1,%0"
15785+ asm volatile(LOCK_PREFIX "subq %1,%0\n"
15786+
15787+#ifdef CONFIG_PAX_REFCOUNT
15788+ "jno 0f\n"
15789+ LOCK_PREFIX "addq %1,%0\n"
15790+ "int $4\n0:\n"
15791+ _ASM_EXTABLE(0b, 0b)
15792+#endif
15793+
15794+ : "=m" (v->counter)
15795+ : "er" (i), "m" (v->counter));
15796+}
15797+
15798+/**
15799+ * atomic64_sub_unchecked - subtract the atomic64 variable
15800+ * @i: integer value to subtract
15801+ * @v: pointer to type atomic64_unchecked_t
15802+ *
15803+ * Atomically subtracts @i from @v.
15804+ */
15805+static inline void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
15806+{
15807+ asm volatile(LOCK_PREFIX "subq %1,%0\n"
15808 : "=m" (v->counter)
15809 : "er" (i), "m" (v->counter));
15810 }
15811@@ -72,7 +140,7 @@ static inline void atomic64_sub(long i, atomic64_t *v)
15812 */
15813 static inline int atomic64_sub_and_test(long i, atomic64_t *v)
15814 {
15815- GEN_BINARY_RMWcc(LOCK_PREFIX "subq", v->counter, "er", i, "%0", "e");
15816+ GEN_BINARY_RMWcc(LOCK_PREFIX "subq", LOCK_PREFIX "addq", v->counter, "er", i, "%0", "e");
15817 }
15818
15819 /**
15820@@ -83,6 +151,27 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
15821 */
15822 static inline void atomic64_inc(atomic64_t *v)
15823 {
15824+ asm volatile(LOCK_PREFIX "incq %0\n"
15825+
15826+#ifdef CONFIG_PAX_REFCOUNT
15827+ "jno 0f\n"
15828+ LOCK_PREFIX "decq %0\n"
15829+ "int $4\n0:\n"
15830+ _ASM_EXTABLE(0b, 0b)
15831+#endif
15832+
15833+ : "=m" (v->counter)
15834+ : "m" (v->counter));
15835+}
15836+
15837+/**
15838+ * atomic64_inc_unchecked - increment atomic64 variable
15839+ * @v: pointer to type atomic64_unchecked_t
15840+ *
15841+ * Atomically increments @v by 1.
15842+ */
15843+static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
15844+{
15845 asm volatile(LOCK_PREFIX "incq %0"
15846 : "=m" (v->counter)
15847 : "m" (v->counter));
15848@@ -96,7 +185,28 @@ static inline void atomic64_inc(atomic64_t *v)
15849 */
15850 static inline void atomic64_dec(atomic64_t *v)
15851 {
15852- asm volatile(LOCK_PREFIX "decq %0"
15853+ asm volatile(LOCK_PREFIX "decq %0\n"
15854+
15855+#ifdef CONFIG_PAX_REFCOUNT
15856+ "jno 0f\n"
15857+ LOCK_PREFIX "incq %0\n"
15858+ "int $4\n0:\n"
15859+ _ASM_EXTABLE(0b, 0b)
15860+#endif
15861+
15862+ : "=m" (v->counter)
15863+ : "m" (v->counter));
15864+}
15865+
15866+/**
15867+ * atomic64_dec_unchecked - decrement atomic64 variable
15868+ * @v: pointer to type atomic64_t
15869+ *
15870+ * Atomically decrements @v by 1.
15871+ */
15872+static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
15873+{
15874+ asm volatile(LOCK_PREFIX "decq %0\n"
15875 : "=m" (v->counter)
15876 : "m" (v->counter));
15877 }
15878@@ -111,7 +221,7 @@ static inline void atomic64_dec(atomic64_t *v)
15879 */
15880 static inline int atomic64_dec_and_test(atomic64_t *v)
15881 {
15882- GEN_UNARY_RMWcc(LOCK_PREFIX "decq", v->counter, "%0", "e");
15883+ GEN_UNARY_RMWcc(LOCK_PREFIX "decq", LOCK_PREFIX "incq", v->counter, "%0", "e");
15884 }
15885
15886 /**
15887@@ -124,7 +234,7 @@ static inline int atomic64_dec_and_test(atomic64_t *v)
15888 */
15889 static inline int atomic64_inc_and_test(atomic64_t *v)
15890 {
15891- GEN_UNARY_RMWcc(LOCK_PREFIX "incq", v->counter, "%0", "e");
15892+ GEN_UNARY_RMWcc(LOCK_PREFIX "incq", LOCK_PREFIX "decq", v->counter, "%0", "e");
15893 }
15894
15895 /**
15896@@ -138,7 +248,7 @@ static inline int atomic64_inc_and_test(atomic64_t *v)
15897 */
15898 static inline int atomic64_add_negative(long i, atomic64_t *v)
15899 {
15900- GEN_BINARY_RMWcc(LOCK_PREFIX "addq", v->counter, "er", i, "%0", "s");
15901+ GEN_BINARY_RMWcc(LOCK_PREFIX "addq", LOCK_PREFIX "subq", v->counter, "er", i, "%0", "s");
15902 }
15903
15904 /**
15905@@ -150,6 +260,18 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
15906 */
15907 static inline long atomic64_add_return(long i, atomic64_t *v)
15908 {
15909+ return i + xadd_check_overflow(&v->counter, i);
15910+}
15911+
15912+/**
15913+ * atomic64_add_return_unchecked - add and return
15914+ * @i: integer value to add
15915+ * @v: pointer to type atomic64_unchecked_t
15916+ *
15917+ * Atomically adds @i to @v and returns @i + @v
15918+ */
15919+static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
15920+{
15921 return i + xadd(&v->counter, i);
15922 }
15923
15924@@ -159,6 +281,10 @@ static inline long atomic64_sub_return(long i, atomic64_t *v)
15925 }
15926
15927 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
15928+static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
15929+{
15930+ return atomic64_add_return_unchecked(1, v);
15931+}
15932 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
15933
15934 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
15935@@ -166,6 +292,11 @@ static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
15936 return cmpxchg(&v->counter, old, new);
15937 }
15938
15939+static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
15940+{
15941+ return cmpxchg(&v->counter, old, new);
15942+}
15943+
15944 static inline long atomic64_xchg(atomic64_t *v, long new)
15945 {
15946 return xchg(&v->counter, new);
15947@@ -182,17 +313,30 @@ static inline long atomic64_xchg(atomic64_t *v, long new)
15948 */
15949 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
15950 {
15951- long c, old;
15952+ long c, old, new;
15953 c = atomic64_read(v);
15954 for (;;) {
15955- if (unlikely(c == (u)))
15956+ if (unlikely(c == u))
15957 break;
15958- old = atomic64_cmpxchg((v), c, c + (a));
15959+
15960+ asm volatile("add %2,%0\n"
15961+
15962+#ifdef CONFIG_PAX_REFCOUNT
15963+ "jno 0f\n"
15964+ "sub %2,%0\n"
15965+ "int $4\n0:\n"
15966+ _ASM_EXTABLE(0b, 0b)
15967+#endif
15968+
15969+ : "=r" (new)
15970+ : "0" (c), "ir" (a));
15971+
15972+ old = atomic64_cmpxchg(v, c, new);
15973 if (likely(old == c))
15974 break;
15975 c = old;
15976 }
15977- return c != (u);
15978+ return c != u;
15979 }
15980
15981 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
15982diff --git a/arch/x86/include/asm/barrier.h b/arch/x86/include/asm/barrier.h
15983index 0f4460b..fa1ee19 100644
15984--- a/arch/x86/include/asm/barrier.h
15985+++ b/arch/x86/include/asm/barrier.h
15986@@ -107,7 +107,7 @@
15987 do { \
15988 compiletime_assert_atomic_type(*p); \
15989 smp_mb(); \
15990- ACCESS_ONCE(*p) = (v); \
15991+ ACCESS_ONCE_RW(*p) = (v); \
15992 } while (0)
15993
15994 #define smp_load_acquire(p) \
15995@@ -124,7 +124,7 @@ do { \
15996 do { \
15997 compiletime_assert_atomic_type(*p); \
15998 barrier(); \
15999- ACCESS_ONCE(*p) = (v); \
16000+ ACCESS_ONCE_RW(*p) = (v); \
16001 } while (0)
16002
16003 #define smp_load_acquire(p) \
16004diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
16005index cfe3b95..d01b118 100644
16006--- a/arch/x86/include/asm/bitops.h
16007+++ b/arch/x86/include/asm/bitops.h
16008@@ -50,7 +50,7 @@
16009 * a mask operation on a byte.
16010 */
16011 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
16012-#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
16013+#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
16014 #define CONST_MASK(nr) (1 << ((nr) & 7))
16015
16016 /**
16017@@ -203,7 +203,7 @@ static inline void change_bit(long nr, volatile unsigned long *addr)
16018 */
16019 static inline int test_and_set_bit(long nr, volatile unsigned long *addr)
16020 {
16021- GEN_BINARY_RMWcc(LOCK_PREFIX "bts", *addr, "Ir", nr, "%0", "c");
16022+ GEN_BINARY_RMWcc_unchecked(LOCK_PREFIX "bts", *addr, "Ir", nr, "%0", "c");
16023 }
16024
16025 /**
16026@@ -249,7 +249,7 @@ static inline int __test_and_set_bit(long nr, volatile unsigned long *addr)
16027 */
16028 static inline int test_and_clear_bit(long nr, volatile unsigned long *addr)
16029 {
16030- GEN_BINARY_RMWcc(LOCK_PREFIX "btr", *addr, "Ir", nr, "%0", "c");
16031+ GEN_BINARY_RMWcc_unchecked(LOCK_PREFIX "btr", *addr, "Ir", nr, "%0", "c");
16032 }
16033
16034 /**
16035@@ -302,7 +302,7 @@ static inline int __test_and_change_bit(long nr, volatile unsigned long *addr)
16036 */
16037 static inline int test_and_change_bit(long nr, volatile unsigned long *addr)
16038 {
16039- GEN_BINARY_RMWcc(LOCK_PREFIX "btc", *addr, "Ir", nr, "%0", "c");
16040+ GEN_BINARY_RMWcc_unchecked(LOCK_PREFIX "btc", *addr, "Ir", nr, "%0", "c");
16041 }
16042
16043 static __always_inline int constant_test_bit(long nr, const volatile unsigned long *addr)
16044@@ -343,7 +343,7 @@ static int test_bit(int nr, const volatile unsigned long *addr);
16045 *
16046 * Undefined if no bit exists, so code should check against 0 first.
16047 */
16048-static inline unsigned long __ffs(unsigned long word)
16049+static inline unsigned long __intentional_overflow(-1) __ffs(unsigned long word)
16050 {
16051 asm("rep; bsf %1,%0"
16052 : "=r" (word)
16053@@ -357,7 +357,7 @@ static inline unsigned long __ffs(unsigned long word)
16054 *
16055 * Undefined if no zero exists, so code should check against ~0UL first.
16056 */
16057-static inline unsigned long ffz(unsigned long word)
16058+static inline unsigned long __intentional_overflow(-1) ffz(unsigned long word)
16059 {
16060 asm("rep; bsf %1,%0"
16061 : "=r" (word)
16062@@ -371,7 +371,7 @@ static inline unsigned long ffz(unsigned long word)
16063 *
16064 * Undefined if no set bit exists, so code should check against 0 first.
16065 */
16066-static inline unsigned long __fls(unsigned long word)
16067+static inline unsigned long __intentional_overflow(-1) __fls(unsigned long word)
16068 {
16069 asm("bsr %1,%0"
16070 : "=r" (word)
16071@@ -434,7 +434,7 @@ static inline int ffs(int x)
16072 * set bit if value is nonzero. The last (most significant) bit is
16073 * at position 32.
16074 */
16075-static inline int fls(int x)
16076+static inline int __intentional_overflow(-1) fls(int x)
16077 {
16078 int r;
16079
16080@@ -476,7 +476,7 @@ static inline int fls(int x)
16081 * at position 64.
16082 */
16083 #ifdef CONFIG_X86_64
16084-static __always_inline int fls64(__u64 x)
16085+static __always_inline __intentional_overflow(-1) int fls64(__u64 x)
16086 {
16087 int bitpos = -1;
16088 /*
16089diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h
16090index 4fa687a..60f2d39 100644
16091--- a/arch/x86/include/asm/boot.h
16092+++ b/arch/x86/include/asm/boot.h
16093@@ -6,10 +6,15 @@
16094 #include <uapi/asm/boot.h>
16095
16096 /* Physical address where kernel should be loaded. */
16097-#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
16098+#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
16099 + (CONFIG_PHYSICAL_ALIGN - 1)) \
16100 & ~(CONFIG_PHYSICAL_ALIGN - 1))
16101
16102+#ifndef __ASSEMBLY__
16103+extern unsigned char __LOAD_PHYSICAL_ADDR[];
16104+#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
16105+#endif
16106+
16107 /* Minimum kernel alignment, as a power of two */
16108 #ifdef CONFIG_X86_64
16109 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
16110diff --git a/arch/x86/include/asm/cache.h b/arch/x86/include/asm/cache.h
16111index 48f99f1..d78ebf9 100644
16112--- a/arch/x86/include/asm/cache.h
16113+++ b/arch/x86/include/asm/cache.h
16114@@ -5,12 +5,13 @@
16115
16116 /* L1 cache line size */
16117 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
16118-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
16119+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
16120
16121 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
16122+#define __read_only __attribute__((__section__(".data..read_only")))
16123
16124 #define INTERNODE_CACHE_SHIFT CONFIG_X86_INTERNODE_CACHE_SHIFT
16125-#define INTERNODE_CACHE_BYTES (1 << INTERNODE_CACHE_SHIFT)
16126+#define INTERNODE_CACHE_BYTES (_AC(1,UL) << INTERNODE_CACHE_SHIFT)
16127
16128 #ifdef CONFIG_X86_VSMP
16129 #ifdef CONFIG_SMP
16130diff --git a/arch/x86/include/asm/cacheflush.h b/arch/x86/include/asm/cacheflush.h
16131index 9863ee3..4a1f8e1 100644
16132--- a/arch/x86/include/asm/cacheflush.h
16133+++ b/arch/x86/include/asm/cacheflush.h
16134@@ -27,7 +27,7 @@ static inline unsigned long get_page_memtype(struct page *pg)
16135 unsigned long pg_flags = pg->flags & _PGMT_MASK;
16136
16137 if (pg_flags == _PGMT_DEFAULT)
16138- return -1;
16139+ return ~0UL;
16140 else if (pg_flags == _PGMT_WC)
16141 return _PAGE_CACHE_WC;
16142 else if (pg_flags == _PGMT_UC_MINUS)
16143diff --git a/arch/x86/include/asm/calling.h b/arch/x86/include/asm/calling.h
16144index 76659b6..72b8439 100644
16145--- a/arch/x86/include/asm/calling.h
16146+++ b/arch/x86/include/asm/calling.h
16147@@ -82,107 +82,117 @@ For 32-bit we have the following conventions - kernel is built with
16148 #define RSP 152
16149 #define SS 160
16150
16151-#define ARGOFFSET R11
16152-#define SWFRAME ORIG_RAX
16153+#define ARGOFFSET R15
16154
16155 .macro SAVE_ARGS addskip=0, save_rcx=1, save_r891011=1, rax_enosys=0
16156- subq $9*8+\addskip, %rsp
16157- CFI_ADJUST_CFA_OFFSET 9*8+\addskip
16158- movq_cfi rdi, 8*8
16159- movq_cfi rsi, 7*8
16160- movq_cfi rdx, 6*8
16161+ subq $ORIG_RAX-ARGOFFSET+\addskip, %rsp
16162+ CFI_ADJUST_CFA_OFFSET ORIG_RAX-ARGOFFSET+\addskip
16163+ movq_cfi rdi, RDI
16164+ movq_cfi rsi, RSI
16165+ movq_cfi rdx, RDX
16166
16167 .if \save_rcx
16168- movq_cfi rcx, 5*8
16169+ movq_cfi rcx, RCX
16170 .endif
16171
16172 .if \rax_enosys
16173- movq $-ENOSYS, 4*8(%rsp)
16174+ movq $-ENOSYS, RAX(%rsp)
16175 .else
16176- movq_cfi rax, 4*8
16177+ movq_cfi rax, RAX
16178 .endif
16179
16180 .if \save_r891011
16181- movq_cfi r8, 3*8
16182- movq_cfi r9, 2*8
16183- movq_cfi r10, 1*8
16184- movq_cfi r11, 0*8
16185+ movq_cfi r8, R8
16186+ movq_cfi r9, R9
16187+ movq_cfi r10, R10
16188+ movq_cfi r11, R11
16189 .endif
16190
16191+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
16192+ movq_cfi r12, R12
16193+#endif
16194+
16195 .endm
16196
16197-#define ARG_SKIP (9*8)
16198+#define ARG_SKIP ORIG_RAX
16199
16200 .macro RESTORE_ARGS rstor_rax=1, addskip=0, rstor_rcx=1, rstor_r11=1, \
16201 rstor_r8910=1, rstor_rdx=1
16202+
16203+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
16204+ movq_cfi_restore R12, r12
16205+#endif
16206+
16207 .if \rstor_r11
16208- movq_cfi_restore 0*8, r11
16209+ movq_cfi_restore R11, r11
16210 .endif
16211
16212 .if \rstor_r8910
16213- movq_cfi_restore 1*8, r10
16214- movq_cfi_restore 2*8, r9
16215- movq_cfi_restore 3*8, r8
16216+ movq_cfi_restore R10, r10
16217+ movq_cfi_restore R9, r9
16218+ movq_cfi_restore R8, r8
16219 .endif
16220
16221 .if \rstor_rax
16222- movq_cfi_restore 4*8, rax
16223+ movq_cfi_restore RAX, rax
16224 .endif
16225
16226 .if \rstor_rcx
16227- movq_cfi_restore 5*8, rcx
16228+ movq_cfi_restore RCX, rcx
16229 .endif
16230
16231 .if \rstor_rdx
16232- movq_cfi_restore 6*8, rdx
16233+ movq_cfi_restore RDX, rdx
16234 .endif
16235
16236- movq_cfi_restore 7*8, rsi
16237- movq_cfi_restore 8*8, rdi
16238+ movq_cfi_restore RSI, rsi
16239+ movq_cfi_restore RDI, rdi
16240
16241- .if ARG_SKIP+\addskip > 0
16242- addq $ARG_SKIP+\addskip, %rsp
16243- CFI_ADJUST_CFA_OFFSET -(ARG_SKIP+\addskip)
16244+ .if ORIG_RAX+\addskip > 0
16245+ addq $ORIG_RAX+\addskip, %rsp
16246+ CFI_ADJUST_CFA_OFFSET -(ORIG_RAX+\addskip)
16247 .endif
16248 .endm
16249
16250- .macro LOAD_ARGS offset, skiprax=0
16251- movq \offset(%rsp), %r11
16252- movq \offset+8(%rsp), %r10
16253- movq \offset+16(%rsp), %r9
16254- movq \offset+24(%rsp), %r8
16255- movq \offset+40(%rsp), %rcx
16256- movq \offset+48(%rsp), %rdx
16257- movq \offset+56(%rsp), %rsi
16258- movq \offset+64(%rsp), %rdi
16259+ .macro LOAD_ARGS skiprax=0
16260+ movq R11(%rsp), %r11
16261+ movq R10(%rsp), %r10
16262+ movq R9(%rsp), %r9
16263+ movq R8(%rsp), %r8
16264+ movq RCX(%rsp), %rcx
16265+ movq RDX(%rsp), %rdx
16266+ movq RSI(%rsp), %rsi
16267+ movq RDI(%rsp), %rdi
16268 .if \skiprax
16269 .else
16270- movq \offset+72(%rsp), %rax
16271+ movq ORIG_RAX(%rsp), %rax
16272 .endif
16273 .endm
16274
16275-#define REST_SKIP (6*8)
16276-
16277 .macro SAVE_REST
16278- subq $REST_SKIP, %rsp
16279- CFI_ADJUST_CFA_OFFSET REST_SKIP
16280- movq_cfi rbx, 5*8
16281- movq_cfi rbp, 4*8
16282- movq_cfi r12, 3*8
16283- movq_cfi r13, 2*8
16284- movq_cfi r14, 1*8
16285- movq_cfi r15, 0*8
16286+ movq_cfi rbx, RBX
16287+ movq_cfi rbp, RBP
16288+
16289+#ifndef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
16290+ movq_cfi r12, R12
16291+#endif
16292+
16293+ movq_cfi r13, R13
16294+ movq_cfi r14, R14
16295+ movq_cfi r15, R15
16296 .endm
16297
16298 .macro RESTORE_REST
16299- movq_cfi_restore 0*8, r15
16300- movq_cfi_restore 1*8, r14
16301- movq_cfi_restore 2*8, r13
16302- movq_cfi_restore 3*8, r12
16303- movq_cfi_restore 4*8, rbp
16304- movq_cfi_restore 5*8, rbx
16305- addq $REST_SKIP, %rsp
16306- CFI_ADJUST_CFA_OFFSET -(REST_SKIP)
16307+ movq_cfi_restore R15, r15
16308+ movq_cfi_restore R14, r14
16309+ movq_cfi_restore R13, r13
16310+
16311+#ifndef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
16312+ movq_cfi_restore R12, r12
16313+#endif
16314+
16315+ movq_cfi_restore RBP, rbp
16316+ movq_cfi_restore RBX, rbx
16317 .endm
16318
16319 .macro SAVE_ALL
16320diff --git a/arch/x86/include/asm/checksum_32.h b/arch/x86/include/asm/checksum_32.h
16321index f50de69..2b0a458 100644
16322--- a/arch/x86/include/asm/checksum_32.h
16323+++ b/arch/x86/include/asm/checksum_32.h
16324@@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_generic(const void *src, void *dst,
16325 int len, __wsum sum,
16326 int *src_err_ptr, int *dst_err_ptr);
16327
16328+asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
16329+ int len, __wsum sum,
16330+ int *src_err_ptr, int *dst_err_ptr);
16331+
16332+asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
16333+ int len, __wsum sum,
16334+ int *src_err_ptr, int *dst_err_ptr);
16335+
16336 /*
16337 * Note: when you get a NULL pointer exception here this means someone
16338 * passed in an incorrect kernel address to one of these functions.
16339@@ -53,7 +61,7 @@ static inline __wsum csum_partial_copy_from_user(const void __user *src,
16340
16341 might_sleep();
16342 stac();
16343- ret = csum_partial_copy_generic((__force void *)src, dst,
16344+ ret = csum_partial_copy_generic_from_user((__force void *)src, dst,
16345 len, sum, err_ptr, NULL);
16346 clac();
16347
16348@@ -187,7 +195,7 @@ static inline __wsum csum_and_copy_to_user(const void *src,
16349 might_sleep();
16350 if (access_ok(VERIFY_WRITE, dst, len)) {
16351 stac();
16352- ret = csum_partial_copy_generic(src, (__force void *)dst,
16353+ ret = csum_partial_copy_generic_to_user(src, (__force void *)dst,
16354 len, sum, NULL, err_ptr);
16355 clac();
16356 return ret;
16357diff --git a/arch/x86/include/asm/cmpxchg.h b/arch/x86/include/asm/cmpxchg.h
16358index 99c105d7..2f667ac 100644
16359--- a/arch/x86/include/asm/cmpxchg.h
16360+++ b/arch/x86/include/asm/cmpxchg.h
16361@@ -16,8 +16,12 @@ extern void __cmpxchg_wrong_size(void)
16362 __compiletime_error("Bad argument size for cmpxchg");
16363 extern void __xadd_wrong_size(void)
16364 __compiletime_error("Bad argument size for xadd");
16365+extern void __xadd_check_overflow_wrong_size(void)
16366+ __compiletime_error("Bad argument size for xadd_check_overflow");
16367 extern void __add_wrong_size(void)
16368 __compiletime_error("Bad argument size for add");
16369+extern void __add_check_overflow_wrong_size(void)
16370+ __compiletime_error("Bad argument size for add_check_overflow");
16371
16372 /*
16373 * Constants for operation sizes. On 32-bit, the 64-bit size it set to
16374@@ -69,6 +73,38 @@ extern void __add_wrong_size(void)
16375 __ret; \
16376 })
16377
16378+#ifdef CONFIG_PAX_REFCOUNT
16379+#define __xchg_op_check_overflow(ptr, arg, op, lock) \
16380+ ({ \
16381+ __typeof__ (*(ptr)) __ret = (arg); \
16382+ switch (sizeof(*(ptr))) { \
16383+ case __X86_CASE_L: \
16384+ asm volatile (lock #op "l %0, %1\n" \
16385+ "jno 0f\n" \
16386+ "mov %0,%1\n" \
16387+ "int $4\n0:\n" \
16388+ _ASM_EXTABLE(0b, 0b) \
16389+ : "+r" (__ret), "+m" (*(ptr)) \
16390+ : : "memory", "cc"); \
16391+ break; \
16392+ case __X86_CASE_Q: \
16393+ asm volatile (lock #op "q %q0, %1\n" \
16394+ "jno 0f\n" \
16395+ "mov %0,%1\n" \
16396+ "int $4\n0:\n" \
16397+ _ASM_EXTABLE(0b, 0b) \
16398+ : "+r" (__ret), "+m" (*(ptr)) \
16399+ : : "memory", "cc"); \
16400+ break; \
16401+ default: \
16402+ __ ## op ## _check_overflow_wrong_size(); \
16403+ } \
16404+ __ret; \
16405+ })
16406+#else
16407+#define __xchg_op_check_overflow(ptr, arg, op, lock) __xchg_op(ptr, arg, op, lock)
16408+#endif
16409+
16410 /*
16411 * Note: no "lock" prefix even on SMP: xchg always implies lock anyway.
16412 * Since this is generally used to protect other memory information, we
16413@@ -167,6 +203,9 @@ extern void __add_wrong_size(void)
16414 #define xadd_sync(ptr, inc) __xadd((ptr), (inc), "lock; ")
16415 #define xadd_local(ptr, inc) __xadd((ptr), (inc), "")
16416
16417+#define __xadd_check_overflow(ptr, inc, lock) __xchg_op_check_overflow((ptr), (inc), xadd, lock)
16418+#define xadd_check_overflow(ptr, inc) __xadd_check_overflow((ptr), (inc), LOCK_PREFIX)
16419+
16420 #define __add(ptr, inc, lock) \
16421 ({ \
16422 __typeof__ (*(ptr)) __ret = (inc); \
16423diff --git a/arch/x86/include/asm/compat.h b/arch/x86/include/asm/compat.h
16424index 59c6c40..5e0b22c 100644
16425--- a/arch/x86/include/asm/compat.h
16426+++ b/arch/x86/include/asm/compat.h
16427@@ -41,7 +41,7 @@ typedef s64 __attribute__((aligned(4))) compat_s64;
16428 typedef u32 compat_uint_t;
16429 typedef u32 compat_ulong_t;
16430 typedef u64 __attribute__((aligned(4))) compat_u64;
16431-typedef u32 compat_uptr_t;
16432+typedef u32 __user compat_uptr_t;
16433
16434 struct compat_timespec {
16435 compat_time_t tv_sec;
16436diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
16437index 0bb1335..8f1aec7 100644
16438--- a/arch/x86/include/asm/cpufeature.h
16439+++ b/arch/x86/include/asm/cpufeature.h
16440@@ -207,7 +207,7 @@
16441 #define X86_FEATURE_PAUSEFILTER ( 8*32+13) /* AMD filtered pause intercept */
16442 #define X86_FEATURE_PFTHRESHOLD ( 8*32+14) /* AMD pause filter threshold */
16443 #define X86_FEATURE_VMMCALL ( 8*32+15) /* Prefer vmmcall to vmcall */
16444-
16445+#define X86_FEATURE_STRONGUDEREF (8*32+31) /* PaX PCID based strong UDEREF */
16446
16447 /* Intel-defined CPU features, CPUID level 0x00000007:0 (ebx), word 9 */
16448 #define X86_FEATURE_FSGSBASE ( 9*32+ 0) /* {RD/WR}{FS/GS}BASE instructions*/
16449@@ -215,7 +215,7 @@
16450 #define X86_FEATURE_BMI1 ( 9*32+ 3) /* 1st group bit manipulation extensions */
16451 #define X86_FEATURE_HLE ( 9*32+ 4) /* Hardware Lock Elision */
16452 #define X86_FEATURE_AVX2 ( 9*32+ 5) /* AVX2 instructions */
16453-#define X86_FEATURE_SMEP ( 9*32+ 7) /* Supervisor Mode Execution Protection */
16454+#define X86_FEATURE_SMEP ( 9*32+ 7) /* Supervisor Mode Execution Prevention */
16455 #define X86_FEATURE_BMI2 ( 9*32+ 8) /* 2nd group bit manipulation extensions */
16456 #define X86_FEATURE_ERMS ( 9*32+ 9) /* Enhanced REP MOVSB/STOSB */
16457 #define X86_FEATURE_INVPCID ( 9*32+10) /* Invalidate Processor Context ID */
16458@@ -383,6 +383,7 @@ extern const char * const x86_bug_flags[NBUGINTS*32];
16459 #define cpu_has_cx16 boot_cpu_has(X86_FEATURE_CX16)
16460 #define cpu_has_eager_fpu boot_cpu_has(X86_FEATURE_EAGER_FPU)
16461 #define cpu_has_topoext boot_cpu_has(X86_FEATURE_TOPOEXT)
16462+#define cpu_has_pcid boot_cpu_has(X86_FEATURE_PCID)
16463
16464 #if __GNUC__ >= 4
16465 extern void warn_pre_alternatives(void);
16466@@ -434,7 +435,8 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
16467
16468 #ifdef CONFIG_X86_DEBUG_STATIC_CPU_HAS
16469 t_warn:
16470- warn_pre_alternatives();
16471+ if (bit != X86_FEATURE_PCID && bit != X86_FEATURE_INVPCID)
16472+ warn_pre_alternatives();
16473 return false;
16474 #endif
16475
16476@@ -454,7 +456,7 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
16477 ".section .discard,\"aw\",@progbits\n"
16478 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
16479 ".previous\n"
16480- ".section .altinstr_replacement,\"ax\"\n"
16481+ ".section .altinstr_replacement,\"a\"\n"
16482 "3: movb $1,%0\n"
16483 "4:\n"
16484 ".previous\n"
16485@@ -491,7 +493,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
16486 " .byte 2b - 1b\n" /* src len */
16487 " .byte 4f - 3f\n" /* repl len */
16488 ".previous\n"
16489- ".section .altinstr_replacement,\"ax\"\n"
16490+ ".section .altinstr_replacement,\"a\"\n"
16491 "3: .byte 0xe9\n .long %l[t_no] - 2b\n"
16492 "4:\n"
16493 ".previous\n"
16494@@ -524,7 +526,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
16495 ".section .discard,\"aw\",@progbits\n"
16496 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
16497 ".previous\n"
16498- ".section .altinstr_replacement,\"ax\"\n"
16499+ ".section .altinstr_replacement,\"a\"\n"
16500 "3: movb $0,%0\n"
16501 "4:\n"
16502 ".previous\n"
16503@@ -538,7 +540,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
16504 ".section .discard,\"aw\",@progbits\n"
16505 " .byte 0xff + (6f-5f) - (4b-3b)\n" /* size check */
16506 ".previous\n"
16507- ".section .altinstr_replacement,\"ax\"\n"
16508+ ".section .altinstr_replacement,\"a\"\n"
16509 "5: movb $1,%0\n"
16510 "6:\n"
16511 ".previous\n"
16512diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
16513index 50d033a..37deb26 100644
16514--- a/arch/x86/include/asm/desc.h
16515+++ b/arch/x86/include/asm/desc.h
16516@@ -4,6 +4,7 @@
16517 #include <asm/desc_defs.h>
16518 #include <asm/ldt.h>
16519 #include <asm/mmu.h>
16520+#include <asm/pgtable.h>
16521
16522 #include <linux/smp.h>
16523 #include <linux/percpu.h>
16524@@ -17,6 +18,7 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
16525
16526 desc->type = (info->read_exec_only ^ 1) << 1;
16527 desc->type |= info->contents << 2;
16528+ desc->type |= info->seg_not_present ^ 1;
16529
16530 desc->s = 1;
16531 desc->dpl = 0x3;
16532@@ -35,19 +37,14 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
16533 }
16534
16535 extern struct desc_ptr idt_descr;
16536-extern gate_desc idt_table[];
16537-extern struct desc_ptr debug_idt_descr;
16538-extern gate_desc debug_idt_table[];
16539-
16540-struct gdt_page {
16541- struct desc_struct gdt[GDT_ENTRIES];
16542-} __attribute__((aligned(PAGE_SIZE)));
16543-
16544-DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
16545+extern gate_desc idt_table[IDT_ENTRIES];
16546+extern const struct desc_ptr debug_idt_descr;
16547+extern gate_desc debug_idt_table[IDT_ENTRIES];
16548
16549+extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
16550 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
16551 {
16552- return per_cpu(gdt_page, cpu).gdt;
16553+ return cpu_gdt_table[cpu];
16554 }
16555
16556 #ifdef CONFIG_X86_64
16557@@ -72,8 +69,14 @@ static inline void pack_gate(gate_desc *gate, unsigned char type,
16558 unsigned long base, unsigned dpl, unsigned flags,
16559 unsigned short seg)
16560 {
16561- gate->a = (seg << 16) | (base & 0xffff);
16562- gate->b = (base & 0xffff0000) | (((0x80 | type | (dpl << 5)) & 0xff) << 8);
16563+ gate->gate.offset_low = base;
16564+ gate->gate.seg = seg;
16565+ gate->gate.reserved = 0;
16566+ gate->gate.type = type;
16567+ gate->gate.s = 0;
16568+ gate->gate.dpl = dpl;
16569+ gate->gate.p = 1;
16570+ gate->gate.offset_high = base >> 16;
16571 }
16572
16573 #endif
16574@@ -118,12 +121,16 @@ static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
16575
16576 static inline void native_write_idt_entry(gate_desc *idt, int entry, const gate_desc *gate)
16577 {
16578+ pax_open_kernel();
16579 memcpy(&idt[entry], gate, sizeof(*gate));
16580+ pax_close_kernel();
16581 }
16582
16583 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry, const void *desc)
16584 {
16585+ pax_open_kernel();
16586 memcpy(&ldt[entry], desc, 8);
16587+ pax_close_kernel();
16588 }
16589
16590 static inline void
16591@@ -137,7 +144,9 @@ native_write_gdt_entry(struct desc_struct *gdt, int entry, const void *desc, int
16592 default: size = sizeof(*gdt); break;
16593 }
16594
16595+ pax_open_kernel();
16596 memcpy(&gdt[entry], desc, size);
16597+ pax_close_kernel();
16598 }
16599
16600 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
16601@@ -210,7 +219,9 @@ static inline void native_set_ldt(const void *addr, unsigned int entries)
16602
16603 static inline void native_load_tr_desc(void)
16604 {
16605+ pax_open_kernel();
16606 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
16607+ pax_close_kernel();
16608 }
16609
16610 static inline void native_load_gdt(const struct desc_ptr *dtr)
16611@@ -247,8 +258,10 @@ static inline void native_load_tls(struct thread_struct *t, unsigned int cpu)
16612 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
16613 unsigned int i;
16614
16615+ pax_open_kernel();
16616 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
16617 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
16618+ pax_close_kernel();
16619 }
16620
16621 #define _LDT_empty(info) \
16622@@ -287,7 +300,7 @@ static inline void load_LDT(mm_context_t *pc)
16623 preempt_enable();
16624 }
16625
16626-static inline unsigned long get_desc_base(const struct desc_struct *desc)
16627+static inline unsigned long __intentional_overflow(-1) get_desc_base(const struct desc_struct *desc)
16628 {
16629 return (unsigned)(desc->base0 | ((desc->base1) << 16) | ((desc->base2) << 24));
16630 }
16631@@ -311,7 +324,7 @@ static inline void set_desc_limit(struct desc_struct *desc, unsigned long limit)
16632 }
16633
16634 #ifdef CONFIG_X86_64
16635-static inline void set_nmi_gate(int gate, void *addr)
16636+static inline void set_nmi_gate(int gate, const void *addr)
16637 {
16638 gate_desc s;
16639
16640@@ -321,14 +334,14 @@ static inline void set_nmi_gate(int gate, void *addr)
16641 #endif
16642
16643 #ifdef CONFIG_TRACING
16644-extern struct desc_ptr trace_idt_descr;
16645-extern gate_desc trace_idt_table[];
16646+extern const struct desc_ptr trace_idt_descr;
16647+extern gate_desc trace_idt_table[IDT_ENTRIES];
16648 static inline void write_trace_idt_entry(int entry, const gate_desc *gate)
16649 {
16650 write_idt_entry(trace_idt_table, entry, gate);
16651 }
16652
16653-static inline void _trace_set_gate(int gate, unsigned type, void *addr,
16654+static inline void _trace_set_gate(int gate, unsigned type, const void *addr,
16655 unsigned dpl, unsigned ist, unsigned seg)
16656 {
16657 gate_desc s;
16658@@ -348,7 +361,7 @@ static inline void write_trace_idt_entry(int entry, const gate_desc *gate)
16659 #define _trace_set_gate(gate, type, addr, dpl, ist, seg)
16660 #endif
16661
16662-static inline void _set_gate(int gate, unsigned type, void *addr,
16663+static inline void _set_gate(int gate, unsigned type, const void *addr,
16664 unsigned dpl, unsigned ist, unsigned seg)
16665 {
16666 gate_desc s;
16667@@ -371,9 +384,9 @@ static inline void _set_gate(int gate, unsigned type, void *addr,
16668 #define set_intr_gate(n, addr) \
16669 do { \
16670 BUG_ON((unsigned)n > 0xFF); \
16671- _set_gate(n, GATE_INTERRUPT, (void *)addr, 0, 0, \
16672+ _set_gate(n, GATE_INTERRUPT, (const void *)addr, 0, 0, \
16673 __KERNEL_CS); \
16674- _trace_set_gate(n, GATE_INTERRUPT, (void *)trace_##addr,\
16675+ _trace_set_gate(n, GATE_INTERRUPT, (const void *)trace_##addr,\
16676 0, 0, __KERNEL_CS); \
16677 } while (0)
16678
16679@@ -401,19 +414,19 @@ static inline void alloc_system_vector(int vector)
16680 /*
16681 * This routine sets up an interrupt gate at directory privilege level 3.
16682 */
16683-static inline void set_system_intr_gate(unsigned int n, void *addr)
16684+static inline void set_system_intr_gate(unsigned int n, const void *addr)
16685 {
16686 BUG_ON((unsigned)n > 0xFF);
16687 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
16688 }
16689
16690-static inline void set_system_trap_gate(unsigned int n, void *addr)
16691+static inline void set_system_trap_gate(unsigned int n, const void *addr)
16692 {
16693 BUG_ON((unsigned)n > 0xFF);
16694 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
16695 }
16696
16697-static inline void set_trap_gate(unsigned int n, void *addr)
16698+static inline void set_trap_gate(unsigned int n, const void *addr)
16699 {
16700 BUG_ON((unsigned)n > 0xFF);
16701 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
16702@@ -422,16 +435,16 @@ static inline void set_trap_gate(unsigned int n, void *addr)
16703 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
16704 {
16705 BUG_ON((unsigned)n > 0xFF);
16706- _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
16707+ _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
16708 }
16709
16710-static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
16711+static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
16712 {
16713 BUG_ON((unsigned)n > 0xFF);
16714 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
16715 }
16716
16717-static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
16718+static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
16719 {
16720 BUG_ON((unsigned)n > 0xFF);
16721 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
16722@@ -503,4 +516,17 @@ static inline void load_current_idt(void)
16723 else
16724 load_idt((const struct desc_ptr *)&idt_descr);
16725 }
16726+
16727+#ifdef CONFIG_X86_32
16728+static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
16729+{
16730+ struct desc_struct d;
16731+
16732+ if (likely(limit))
16733+ limit = (limit - 1UL) >> PAGE_SHIFT;
16734+ pack_descriptor(&d, base, limit, 0xFB, 0xC);
16735+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
16736+}
16737+#endif
16738+
16739 #endif /* _ASM_X86_DESC_H */
16740diff --git a/arch/x86/include/asm/desc_defs.h b/arch/x86/include/asm/desc_defs.h
16741index 278441f..b95a174 100644
16742--- a/arch/x86/include/asm/desc_defs.h
16743+++ b/arch/x86/include/asm/desc_defs.h
16744@@ -31,6 +31,12 @@ struct desc_struct {
16745 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
16746 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
16747 };
16748+ struct {
16749+ u16 offset_low;
16750+ u16 seg;
16751+ unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
16752+ unsigned offset_high: 16;
16753+ } gate;
16754 };
16755 } __attribute__((packed));
16756
16757diff --git a/arch/x86/include/asm/div64.h b/arch/x86/include/asm/div64.h
16758index ced283a..ffe04cc 100644
16759--- a/arch/x86/include/asm/div64.h
16760+++ b/arch/x86/include/asm/div64.h
16761@@ -39,7 +39,7 @@
16762 __mod; \
16763 })
16764
16765-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
16766+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
16767 {
16768 union {
16769 u64 v64;
16770diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
16771index ca3347a..1a5082a 100644
16772--- a/arch/x86/include/asm/elf.h
16773+++ b/arch/x86/include/asm/elf.h
16774@@ -75,9 +75,6 @@ typedef struct user_fxsr_struct elf_fpxregset_t;
16775
16776 #include <asm/vdso.h>
16777
16778-#ifdef CONFIG_X86_64
16779-extern unsigned int vdso64_enabled;
16780-#endif
16781 #if defined(CONFIG_X86_32) || defined(CONFIG_COMPAT)
16782 extern unsigned int vdso32_enabled;
16783 #endif
16784@@ -249,7 +246,25 @@ extern int force_personality32;
16785 the loader. We need to make sure that it is out of the way of the program
16786 that it will "exec", and that there is sufficient room for the brk. */
16787
16788+#ifdef CONFIG_PAX_SEGMEXEC
16789+#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
16790+#else
16791 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
16792+#endif
16793+
16794+#ifdef CONFIG_PAX_ASLR
16795+#ifdef CONFIG_X86_32
16796+#define PAX_ELF_ET_DYN_BASE 0x10000000UL
16797+
16798+#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
16799+#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
16800+#else
16801+#define PAX_ELF_ET_DYN_BASE 0x400000UL
16802+
16803+#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
16804+#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
16805+#endif
16806+#endif
16807
16808 /* This yields a mask that user programs can use to figure out what
16809 instruction set this CPU supports. This could be done in user space,
16810@@ -298,17 +313,13 @@ do { \
16811
16812 #define ARCH_DLINFO \
16813 do { \
16814- if (vdso64_enabled) \
16815- NEW_AUX_ENT(AT_SYSINFO_EHDR, \
16816- (unsigned long __force)current->mm->context.vdso); \
16817+ NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
16818 } while (0)
16819
16820 /* As a historical oddity, the x32 and x86_64 vDSOs are controlled together. */
16821 #define ARCH_DLINFO_X32 \
16822 do { \
16823- if (vdso64_enabled) \
16824- NEW_AUX_ENT(AT_SYSINFO_EHDR, \
16825- (unsigned long __force)current->mm->context.vdso); \
16826+ NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
16827 } while (0)
16828
16829 #define AT_SYSINFO 32
16830@@ -323,10 +334,10 @@ else \
16831
16832 #endif /* !CONFIG_X86_32 */
16833
16834-#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
16835+#define VDSO_CURRENT_BASE (current->mm->context.vdso)
16836
16837 #define VDSO_ENTRY \
16838- ((unsigned long)current->mm->context.vdso + \
16839+ (current->mm->context.vdso + \
16840 selected_vdso32->sym___kernel_vsyscall)
16841
16842 struct linux_binprm;
16843@@ -338,9 +349,6 @@ extern int compat_arch_setup_additional_pages(struct linux_binprm *bprm,
16844 int uses_interp);
16845 #define compat_arch_setup_additional_pages compat_arch_setup_additional_pages
16846
16847-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
16848-#define arch_randomize_brk arch_randomize_brk
16849-
16850 /*
16851 * True on X86_32 or when emulating IA32 on X86_64
16852 */
16853diff --git a/arch/x86/include/asm/emergency-restart.h b/arch/x86/include/asm/emergency-restart.h
16854index 77a99ac..39ff7f5 100644
16855--- a/arch/x86/include/asm/emergency-restart.h
16856+++ b/arch/x86/include/asm/emergency-restart.h
16857@@ -1,6 +1,6 @@
16858 #ifndef _ASM_X86_EMERGENCY_RESTART_H
16859 #define _ASM_X86_EMERGENCY_RESTART_H
16860
16861-extern void machine_emergency_restart(void);
16862+extern void machine_emergency_restart(void) __noreturn;
16863
16864 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
16865diff --git a/arch/x86/include/asm/floppy.h b/arch/x86/include/asm/floppy.h
16866index 1c7eefe..d0e4702 100644
16867--- a/arch/x86/include/asm/floppy.h
16868+++ b/arch/x86/include/asm/floppy.h
16869@@ -229,18 +229,18 @@ static struct fd_routine_l {
16870 int (*_dma_setup)(char *addr, unsigned long size, int mode, int io);
16871 } fd_routine[] = {
16872 {
16873- request_dma,
16874- free_dma,
16875- get_dma_residue,
16876- dma_mem_alloc,
16877- hard_dma_setup
16878+ ._request_dma = request_dma,
16879+ ._free_dma = free_dma,
16880+ ._get_dma_residue = get_dma_residue,
16881+ ._dma_mem_alloc = dma_mem_alloc,
16882+ ._dma_setup = hard_dma_setup
16883 },
16884 {
16885- vdma_request_dma,
16886- vdma_nop,
16887- vdma_get_dma_residue,
16888- vdma_mem_alloc,
16889- vdma_dma_setup
16890+ ._request_dma = vdma_request_dma,
16891+ ._free_dma = vdma_nop,
16892+ ._get_dma_residue = vdma_get_dma_residue,
16893+ ._dma_mem_alloc = vdma_mem_alloc,
16894+ ._dma_setup = vdma_dma_setup
16895 }
16896 };
16897
16898diff --git a/arch/x86/include/asm/fpu-internal.h b/arch/x86/include/asm/fpu-internal.h
16899index e97622f..d0ba77a 100644
16900--- a/arch/x86/include/asm/fpu-internal.h
16901+++ b/arch/x86/include/asm/fpu-internal.h
16902@@ -124,8 +124,11 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
16903 #define user_insn(insn, output, input...) \
16904 ({ \
16905 int err; \
16906+ pax_open_userland(); \
16907 asm volatile(ASM_STAC "\n" \
16908- "1:" #insn "\n\t" \
16909+ "1:" \
16910+ __copyuser_seg \
16911+ #insn "\n\t" \
16912 "2: " ASM_CLAC "\n" \
16913 ".section .fixup,\"ax\"\n" \
16914 "3: movl $-1,%[err]\n" \
16915@@ -134,6 +137,7 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
16916 _ASM_EXTABLE(1b, 3b) \
16917 : [err] "=r" (err), output \
16918 : "0"(0), input); \
16919+ pax_close_userland(); \
16920 err; \
16921 })
16922
16923@@ -298,7 +302,7 @@ static inline int restore_fpu_checking(struct task_struct *tsk)
16924 "fnclex\n\t"
16925 "emms\n\t"
16926 "fildl %P[addr]" /* set F?P to defined value */
16927- : : [addr] "m" (tsk->thread.fpu.has_fpu));
16928+ : : [addr] "m" (init_tss[raw_smp_processor_id()].x86_tss.sp0));
16929 }
16930
16931 return fpu_restore_checking(&tsk->thread.fpu);
16932diff --git a/arch/x86/include/asm/futex.h b/arch/x86/include/asm/futex.h
16933index b4c1f54..e290c08 100644
16934--- a/arch/x86/include/asm/futex.h
16935+++ b/arch/x86/include/asm/futex.h
16936@@ -12,6 +12,7 @@
16937 #include <asm/smap.h>
16938
16939 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
16940+ typecheck(u32 __user *, uaddr); \
16941 asm volatile("\t" ASM_STAC "\n" \
16942 "1:\t" insn "\n" \
16943 "2:\t" ASM_CLAC "\n" \
16944@@ -20,15 +21,16 @@
16945 "\tjmp\t2b\n" \
16946 "\t.previous\n" \
16947 _ASM_EXTABLE(1b, 3b) \
16948- : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
16949+ : "=r" (oldval), "=r" (ret), "+m" (*(u32 __user *)____m(uaddr)) \
16950 : "i" (-EFAULT), "0" (oparg), "1" (0))
16951
16952 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
16953+ typecheck(u32 __user *, uaddr); \
16954 asm volatile("\t" ASM_STAC "\n" \
16955 "1:\tmovl %2, %0\n" \
16956 "\tmovl\t%0, %3\n" \
16957 "\t" insn "\n" \
16958- "2:\t" LOCK_PREFIX "cmpxchgl %3, %2\n" \
16959+ "2:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %3, %2\n" \
16960 "\tjnz\t1b\n" \
16961 "3:\t" ASM_CLAC "\n" \
16962 "\t.section .fixup,\"ax\"\n" \
16963@@ -38,7 +40,7 @@
16964 _ASM_EXTABLE(1b, 4b) \
16965 _ASM_EXTABLE(2b, 4b) \
16966 : "=&a" (oldval), "=&r" (ret), \
16967- "+m" (*uaddr), "=&r" (tem) \
16968+ "+m" (*(u32 __user *)____m(uaddr)), "=&r" (tem) \
16969 : "r" (oparg), "i" (-EFAULT), "1" (0))
16970
16971 static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
16972@@ -57,12 +59,13 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
16973
16974 pagefault_disable();
16975
16976+ pax_open_userland();
16977 switch (op) {
16978 case FUTEX_OP_SET:
16979- __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
16980+ __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
16981 break;
16982 case FUTEX_OP_ADD:
16983- __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
16984+ __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
16985 uaddr, oparg);
16986 break;
16987 case FUTEX_OP_OR:
16988@@ -77,6 +80,7 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
16989 default:
16990 ret = -ENOSYS;
16991 }
16992+ pax_close_userland();
16993
16994 pagefault_enable();
16995
16996diff --git a/arch/x86/include/asm/hw_irq.h b/arch/x86/include/asm/hw_irq.h
16997index 4615906..788c817 100644
16998--- a/arch/x86/include/asm/hw_irq.h
16999+++ b/arch/x86/include/asm/hw_irq.h
17000@@ -164,8 +164,8 @@ extern void setup_ioapic_dest(void);
17001 extern void enable_IO_APIC(void);
17002
17003 /* Statistics */
17004-extern atomic_t irq_err_count;
17005-extern atomic_t irq_mis_count;
17006+extern atomic_unchecked_t irq_err_count;
17007+extern atomic_unchecked_t irq_mis_count;
17008
17009 /* EISA */
17010 extern void eisa_set_level_irq(unsigned int irq);
17011diff --git a/arch/x86/include/asm/i8259.h b/arch/x86/include/asm/i8259.h
17012index ccffa53..3c90c87 100644
17013--- a/arch/x86/include/asm/i8259.h
17014+++ b/arch/x86/include/asm/i8259.h
17015@@ -62,7 +62,7 @@ struct legacy_pic {
17016 void (*init)(int auto_eoi);
17017 int (*irq_pending)(unsigned int irq);
17018 void (*make_irq)(unsigned int irq);
17019-};
17020+} __do_const;
17021
17022 extern struct legacy_pic *legacy_pic;
17023 extern struct legacy_pic null_legacy_pic;
17024diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
17025index b8237d8..3e8864e 100644
17026--- a/arch/x86/include/asm/io.h
17027+++ b/arch/x86/include/asm/io.h
17028@@ -52,12 +52,12 @@ static inline void name(type val, volatile void __iomem *addr) \
17029 "m" (*(volatile type __force *)addr) barrier); }
17030
17031 build_mmio_read(readb, "b", unsigned char, "=q", :"memory")
17032-build_mmio_read(readw, "w", unsigned short, "=r", :"memory")
17033-build_mmio_read(readl, "l", unsigned int, "=r", :"memory")
17034+build_mmio_read(__intentional_overflow(-1) readw, "w", unsigned short, "=r", :"memory")
17035+build_mmio_read(__intentional_overflow(-1) readl, "l", unsigned int, "=r", :"memory")
17036
17037 build_mmio_read(__readb, "b", unsigned char, "=q", )
17038-build_mmio_read(__readw, "w", unsigned short, "=r", )
17039-build_mmio_read(__readl, "l", unsigned int, "=r", )
17040+build_mmio_read(__intentional_overflow(-1) __readw, "w", unsigned short, "=r", )
17041+build_mmio_read(__intentional_overflow(-1) __readl, "l", unsigned int, "=r", )
17042
17043 build_mmio_write(writeb, "b", unsigned char, "q", :"memory")
17044 build_mmio_write(writew, "w", unsigned short, "r", :"memory")
17045@@ -109,7 +109,7 @@ build_mmio_write(writeq, "q", unsigned long, "r", :"memory")
17046 * this function
17047 */
17048
17049-static inline phys_addr_t virt_to_phys(volatile void *address)
17050+static inline phys_addr_t __intentional_overflow(-1) virt_to_phys(volatile void *address)
17051 {
17052 return __pa(address);
17053 }
17054@@ -185,7 +185,7 @@ static inline void __iomem *ioremap(resource_size_t offset, unsigned long size)
17055 return ioremap_nocache(offset, size);
17056 }
17057
17058-extern void iounmap(volatile void __iomem *addr);
17059+extern void iounmap(const volatile void __iomem *addr);
17060
17061 extern void set_iounmap_nonlazy(void);
17062
17063@@ -195,6 +195,17 @@ extern void set_iounmap_nonlazy(void);
17064
17065 #include <linux/vmalloc.h>
17066
17067+#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
17068+static inline int valid_phys_addr_range(unsigned long addr, size_t count)
17069+{
17070+ return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
17071+}
17072+
17073+static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
17074+{
17075+ return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
17076+}
17077+
17078 /*
17079 * Convert a virtual cached pointer to an uncached pointer
17080 */
17081diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
17082index 0a8b519..80e7d5b 100644
17083--- a/arch/x86/include/asm/irqflags.h
17084+++ b/arch/x86/include/asm/irqflags.h
17085@@ -141,6 +141,11 @@ static inline notrace unsigned long arch_local_irq_save(void)
17086 sti; \
17087 sysexit
17088
17089+#define GET_CR0_INTO_RDI mov %cr0, %rdi
17090+#define SET_RDI_INTO_CR0 mov %rdi, %cr0
17091+#define GET_CR3_INTO_RDI mov %cr3, %rdi
17092+#define SET_RDI_INTO_CR3 mov %rdi, %cr3
17093+
17094 #else
17095 #define INTERRUPT_RETURN iret
17096 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
17097diff --git a/arch/x86/include/asm/kprobes.h b/arch/x86/include/asm/kprobes.h
17098index 4421b5d..8543006 100644
17099--- a/arch/x86/include/asm/kprobes.h
17100+++ b/arch/x86/include/asm/kprobes.h
17101@@ -37,13 +37,8 @@ typedef u8 kprobe_opcode_t;
17102 #define RELATIVEJUMP_SIZE 5
17103 #define RELATIVECALL_OPCODE 0xe8
17104 #define RELATIVE_ADDR_SIZE 4
17105-#define MAX_STACK_SIZE 64
17106-#define MIN_STACK_SIZE(ADDR) \
17107- (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
17108- THREAD_SIZE - (unsigned long)(ADDR))) \
17109- ? (MAX_STACK_SIZE) \
17110- : (((unsigned long)current_thread_info()) + \
17111- THREAD_SIZE - (unsigned long)(ADDR)))
17112+#define MAX_STACK_SIZE 64UL
17113+#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
17114
17115 #define flush_insn_slot(p) do { } while (0)
17116
17117diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
17118index 6ed0c30..74fb6c3 100644
17119--- a/arch/x86/include/asm/kvm_host.h
17120+++ b/arch/x86/include/asm/kvm_host.h
17121@@ -51,6 +51,7 @@
17122 | X86_CR0_NW | X86_CR0_CD | X86_CR0_PG))
17123
17124 #define CR3_L_MODE_RESERVED_BITS 0xFFFFFF0000000000ULL
17125+#define CR3_PCID_INVD (1UL << 63)
17126 #define CR4_RESERVED_BITS \
17127 (~(unsigned long)(X86_CR4_VME | X86_CR4_PVI | X86_CR4_TSD | X86_CR4_DE\
17128 | X86_CR4_PSE | X86_CR4_PAE | X86_CR4_MCE \
17129diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
17130index 4ad6560..75c7bdd 100644
17131--- a/arch/x86/include/asm/local.h
17132+++ b/arch/x86/include/asm/local.h
17133@@ -10,33 +10,97 @@ typedef struct {
17134 atomic_long_t a;
17135 } local_t;
17136
17137+typedef struct {
17138+ atomic_long_unchecked_t a;
17139+} local_unchecked_t;
17140+
17141 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
17142
17143 #define local_read(l) atomic_long_read(&(l)->a)
17144+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
17145 #define local_set(l, i) atomic_long_set(&(l)->a, (i))
17146+#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
17147
17148 static inline void local_inc(local_t *l)
17149 {
17150- asm volatile(_ASM_INC "%0"
17151+ asm volatile(_ASM_INC "%0\n"
17152+
17153+#ifdef CONFIG_PAX_REFCOUNT
17154+ "jno 0f\n"
17155+ _ASM_DEC "%0\n"
17156+ "int $4\n0:\n"
17157+ _ASM_EXTABLE(0b, 0b)
17158+#endif
17159+
17160+ : "+m" (l->a.counter));
17161+}
17162+
17163+static inline void local_inc_unchecked(local_unchecked_t *l)
17164+{
17165+ asm volatile(_ASM_INC "%0\n"
17166 : "+m" (l->a.counter));
17167 }
17168
17169 static inline void local_dec(local_t *l)
17170 {
17171- asm volatile(_ASM_DEC "%0"
17172+ asm volatile(_ASM_DEC "%0\n"
17173+
17174+#ifdef CONFIG_PAX_REFCOUNT
17175+ "jno 0f\n"
17176+ _ASM_INC "%0\n"
17177+ "int $4\n0:\n"
17178+ _ASM_EXTABLE(0b, 0b)
17179+#endif
17180+
17181+ : "+m" (l->a.counter));
17182+}
17183+
17184+static inline void local_dec_unchecked(local_unchecked_t *l)
17185+{
17186+ asm volatile(_ASM_DEC "%0\n"
17187 : "+m" (l->a.counter));
17188 }
17189
17190 static inline void local_add(long i, local_t *l)
17191 {
17192- asm volatile(_ASM_ADD "%1,%0"
17193+ asm volatile(_ASM_ADD "%1,%0\n"
17194+
17195+#ifdef CONFIG_PAX_REFCOUNT
17196+ "jno 0f\n"
17197+ _ASM_SUB "%1,%0\n"
17198+ "int $4\n0:\n"
17199+ _ASM_EXTABLE(0b, 0b)
17200+#endif
17201+
17202+ : "+m" (l->a.counter)
17203+ : "ir" (i));
17204+}
17205+
17206+static inline void local_add_unchecked(long i, local_unchecked_t *l)
17207+{
17208+ asm volatile(_ASM_ADD "%1,%0\n"
17209 : "+m" (l->a.counter)
17210 : "ir" (i));
17211 }
17212
17213 static inline void local_sub(long i, local_t *l)
17214 {
17215- asm volatile(_ASM_SUB "%1,%0"
17216+ asm volatile(_ASM_SUB "%1,%0\n"
17217+
17218+#ifdef CONFIG_PAX_REFCOUNT
17219+ "jno 0f\n"
17220+ _ASM_ADD "%1,%0\n"
17221+ "int $4\n0:\n"
17222+ _ASM_EXTABLE(0b, 0b)
17223+#endif
17224+
17225+ : "+m" (l->a.counter)
17226+ : "ir" (i));
17227+}
17228+
17229+static inline void local_sub_unchecked(long i, local_unchecked_t *l)
17230+{
17231+ asm volatile(_ASM_SUB "%1,%0\n"
17232 : "+m" (l->a.counter)
17233 : "ir" (i));
17234 }
17235@@ -52,7 +116,7 @@ static inline void local_sub(long i, local_t *l)
17236 */
17237 static inline int local_sub_and_test(long i, local_t *l)
17238 {
17239- GEN_BINARY_RMWcc(_ASM_SUB, l->a.counter, "er", i, "%0", "e");
17240+ GEN_BINARY_RMWcc(_ASM_SUB, _ASM_ADD, l->a.counter, "er", i, "%0", "e");
17241 }
17242
17243 /**
17244@@ -65,7 +129,7 @@ static inline int local_sub_and_test(long i, local_t *l)
17245 */
17246 static inline int local_dec_and_test(local_t *l)
17247 {
17248- GEN_UNARY_RMWcc(_ASM_DEC, l->a.counter, "%0", "e");
17249+ GEN_UNARY_RMWcc(_ASM_DEC, _ASM_INC, l->a.counter, "%0", "e");
17250 }
17251
17252 /**
17253@@ -78,7 +142,7 @@ static inline int local_dec_and_test(local_t *l)
17254 */
17255 static inline int local_inc_and_test(local_t *l)
17256 {
17257- GEN_UNARY_RMWcc(_ASM_INC, l->a.counter, "%0", "e");
17258+ GEN_UNARY_RMWcc(_ASM_INC, _ASM_DEC, l->a.counter, "%0", "e");
17259 }
17260
17261 /**
17262@@ -92,7 +156,7 @@ static inline int local_inc_and_test(local_t *l)
17263 */
17264 static inline int local_add_negative(long i, local_t *l)
17265 {
17266- GEN_BINARY_RMWcc(_ASM_ADD, l->a.counter, "er", i, "%0", "s");
17267+ GEN_BINARY_RMWcc(_ASM_ADD, _ASM_SUB, l->a.counter, "er", i, "%0", "s");
17268 }
17269
17270 /**
17271@@ -105,6 +169,30 @@ static inline int local_add_negative(long i, local_t *l)
17272 static inline long local_add_return(long i, local_t *l)
17273 {
17274 long __i = i;
17275+ asm volatile(_ASM_XADD "%0, %1\n"
17276+
17277+#ifdef CONFIG_PAX_REFCOUNT
17278+ "jno 0f\n"
17279+ _ASM_MOV "%0,%1\n"
17280+ "int $4\n0:\n"
17281+ _ASM_EXTABLE(0b, 0b)
17282+#endif
17283+
17284+ : "+r" (i), "+m" (l->a.counter)
17285+ : : "memory");
17286+ return i + __i;
17287+}
17288+
17289+/**
17290+ * local_add_return_unchecked - add and return
17291+ * @i: integer value to add
17292+ * @l: pointer to type local_unchecked_t
17293+ *
17294+ * Atomically adds @i to @l and returns @i + @l
17295+ */
17296+static inline long local_add_return_unchecked(long i, local_unchecked_t *l)
17297+{
17298+ long __i = i;
17299 asm volatile(_ASM_XADD "%0, %1;"
17300 : "+r" (i), "+m" (l->a.counter)
17301 : : "memory");
17302@@ -121,6 +209,8 @@ static inline long local_sub_return(long i, local_t *l)
17303
17304 #define local_cmpxchg(l, o, n) \
17305 (cmpxchg_local(&((l)->a.counter), (o), (n)))
17306+#define local_cmpxchg_unchecked(l, o, n) \
17307+ (cmpxchg_local(&((l)->a.counter), (o), (n)))
17308 /* Always has a lock prefix */
17309 #define local_xchg(l, n) (xchg(&((l)->a.counter), (n)))
17310
17311diff --git a/arch/x86/include/asm/mman.h b/arch/x86/include/asm/mman.h
17312new file mode 100644
17313index 0000000..2bfd3ba
17314--- /dev/null
17315+++ b/arch/x86/include/asm/mman.h
17316@@ -0,0 +1,15 @@
17317+#ifndef _X86_MMAN_H
17318+#define _X86_MMAN_H
17319+
17320+#include <uapi/asm/mman.h>
17321+
17322+#ifdef __KERNEL__
17323+#ifndef __ASSEMBLY__
17324+#ifdef CONFIG_X86_32
17325+#define arch_mmap_check i386_mmap_check
17326+int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags);
17327+#endif
17328+#endif
17329+#endif
17330+
17331+#endif /* X86_MMAN_H */
17332diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
17333index 876e74e..e20bfb1 100644
17334--- a/arch/x86/include/asm/mmu.h
17335+++ b/arch/x86/include/asm/mmu.h
17336@@ -9,7 +9,7 @@
17337 * we put the segment information here.
17338 */
17339 typedef struct {
17340- void *ldt;
17341+ struct desc_struct *ldt;
17342 int size;
17343
17344 #ifdef CONFIG_X86_64
17345@@ -18,7 +18,19 @@ typedef struct {
17346 #endif
17347
17348 struct mutex lock;
17349- void __user *vdso;
17350+ unsigned long vdso;
17351+
17352+#ifdef CONFIG_X86_32
17353+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
17354+ unsigned long user_cs_base;
17355+ unsigned long user_cs_limit;
17356+
17357+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
17358+ cpumask_t cpu_user_cs_mask;
17359+#endif
17360+
17361+#endif
17362+#endif
17363 } mm_context_t;
17364
17365 #ifdef CONFIG_SMP
17366diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
17367index 166af2a..648c200 100644
17368--- a/arch/x86/include/asm/mmu_context.h
17369+++ b/arch/x86/include/asm/mmu_context.h
17370@@ -28,6 +28,20 @@ void destroy_context(struct mm_struct *mm);
17371
17372 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
17373 {
17374+
17375+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17376+ if (!(static_cpu_has(X86_FEATURE_PCID))) {
17377+ unsigned int i;
17378+ pgd_t *pgd;
17379+
17380+ pax_open_kernel();
17381+ pgd = get_cpu_pgd(smp_processor_id(), kernel);
17382+ for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
17383+ set_pgd_batched(pgd+i, native_make_pgd(0));
17384+ pax_close_kernel();
17385+ }
17386+#endif
17387+
17388 #ifdef CONFIG_SMP
17389 if (this_cpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
17390 this_cpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
17391@@ -38,16 +52,59 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
17392 struct task_struct *tsk)
17393 {
17394 unsigned cpu = smp_processor_id();
17395+#if defined(CONFIG_X86_32) && defined(CONFIG_SMP) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
17396+ int tlbstate = TLBSTATE_OK;
17397+#endif
17398
17399 if (likely(prev != next)) {
17400 #ifdef CONFIG_SMP
17401+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
17402+ tlbstate = this_cpu_read(cpu_tlbstate.state);
17403+#endif
17404 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
17405 this_cpu_write(cpu_tlbstate.active_mm, next);
17406 #endif
17407 cpumask_set_cpu(cpu, mm_cpumask(next));
17408
17409 /* Re-load page tables */
17410+#ifdef CONFIG_PAX_PER_CPU_PGD
17411+ pax_open_kernel();
17412+
17413+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17414+ if (static_cpu_has(X86_FEATURE_PCID))
17415+ __clone_user_pgds(get_cpu_pgd(cpu, user), next->pgd);
17416+ else
17417+#endif
17418+
17419+ __clone_user_pgds(get_cpu_pgd(cpu, kernel), next->pgd);
17420+ __shadow_user_pgds(get_cpu_pgd(cpu, kernel) + USER_PGD_PTRS, next->pgd);
17421+ pax_close_kernel();
17422+ 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));
17423+
17424+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17425+ if (static_cpu_has(X86_FEATURE_PCID)) {
17426+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
17427+ u64 descriptor[2];
17428+ descriptor[0] = PCID_USER;
17429+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
17430+ if (!static_cpu_has(X86_FEATURE_STRONGUDEREF)) {
17431+ descriptor[0] = PCID_KERNEL;
17432+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
17433+ }
17434+ } else {
17435+ write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
17436+ if (static_cpu_has(X86_FEATURE_STRONGUDEREF))
17437+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
17438+ else
17439+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
17440+ }
17441+ } else
17442+#endif
17443+
17444+ load_cr3(get_cpu_pgd(cpu, kernel));
17445+#else
17446 load_cr3(next->pgd);
17447+#endif
17448 trace_tlb_flush(TLB_FLUSH_ON_TASK_SWITCH, TLB_FLUSH_ALL);
17449
17450 /* Stop flush ipis for the previous mm */
17451@@ -56,9 +113,67 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
17452 /* Load the LDT, if the LDT is different: */
17453 if (unlikely(prev->context.ldt != next->context.ldt))
17454 load_LDT_nolock(&next->context);
17455+
17456+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
17457+ if (!(__supported_pte_mask & _PAGE_NX)) {
17458+ smp_mb__before_atomic();
17459+ cpu_clear(cpu, prev->context.cpu_user_cs_mask);
17460+ smp_mb__after_atomic();
17461+ cpu_set(cpu, next->context.cpu_user_cs_mask);
17462+ }
17463+#endif
17464+
17465+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
17466+ if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
17467+ prev->context.user_cs_limit != next->context.user_cs_limit))
17468+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
17469+#ifdef CONFIG_SMP
17470+ else if (unlikely(tlbstate != TLBSTATE_OK))
17471+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
17472+#endif
17473+#endif
17474+
17475 }
17476+ else {
17477+
17478+#ifdef CONFIG_PAX_PER_CPU_PGD
17479+ pax_open_kernel();
17480+
17481+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17482+ if (static_cpu_has(X86_FEATURE_PCID))
17483+ __clone_user_pgds(get_cpu_pgd(cpu, user), next->pgd);
17484+ else
17485+#endif
17486+
17487+ __clone_user_pgds(get_cpu_pgd(cpu, kernel), next->pgd);
17488+ __shadow_user_pgds(get_cpu_pgd(cpu, kernel) + USER_PGD_PTRS, next->pgd);
17489+ pax_close_kernel();
17490+ 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));
17491+
17492+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17493+ if (static_cpu_has(X86_FEATURE_PCID)) {
17494+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
17495+ u64 descriptor[2];
17496+ descriptor[0] = PCID_USER;
17497+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
17498+ if (!static_cpu_has(X86_FEATURE_STRONGUDEREF)) {
17499+ descriptor[0] = PCID_KERNEL;
17500+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
17501+ }
17502+ } else {
17503+ write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
17504+ if (static_cpu_has(X86_FEATURE_STRONGUDEREF))
17505+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
17506+ else
17507+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
17508+ }
17509+ } else
17510+#endif
17511+
17512+ load_cr3(get_cpu_pgd(cpu, kernel));
17513+#endif
17514+
17515 #ifdef CONFIG_SMP
17516- else {
17517 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
17518 BUG_ON(this_cpu_read(cpu_tlbstate.active_mm) != next);
17519
17520@@ -75,12 +190,29 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
17521 * tlb flush IPI delivery. We must reload CR3
17522 * to make sure to use no freed page tables.
17523 */
17524+
17525+#ifndef CONFIG_PAX_PER_CPU_PGD
17526 load_cr3(next->pgd);
17527 trace_tlb_flush(TLB_FLUSH_ON_TASK_SWITCH, TLB_FLUSH_ALL);
17528+#endif
17529+
17530 load_LDT_nolock(&next->context);
17531+
17532+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
17533+ if (!(__supported_pte_mask & _PAGE_NX))
17534+ cpu_set(cpu, next->context.cpu_user_cs_mask);
17535+#endif
17536+
17537+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
17538+#ifdef CONFIG_PAX_PAGEEXEC
17539+ if (!((next->pax_flags & MF_PAX_PAGEEXEC) && (__supported_pte_mask & _PAGE_NX)))
17540+#endif
17541+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
17542+#endif
17543+
17544 }
17545+#endif
17546 }
17547-#endif
17548 }
17549
17550 #define activate_mm(prev, next) \
17551diff --git a/arch/x86/include/asm/module.h b/arch/x86/include/asm/module.h
17552index e3b7819..b257c64 100644
17553--- a/arch/x86/include/asm/module.h
17554+++ b/arch/x86/include/asm/module.h
17555@@ -5,6 +5,7 @@
17556
17557 #ifdef CONFIG_X86_64
17558 /* X86_64 does not define MODULE_PROC_FAMILY */
17559+#define MODULE_PROC_FAMILY ""
17560 #elif defined CONFIG_M486
17561 #define MODULE_PROC_FAMILY "486 "
17562 #elif defined CONFIG_M586
17563@@ -57,8 +58,20 @@
17564 #error unknown processor family
17565 #endif
17566
17567-#ifdef CONFIG_X86_32
17568-# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
17569+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
17570+#define MODULE_PAX_KERNEXEC "KERNEXEC_BTS "
17571+#elif defined(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR)
17572+#define MODULE_PAX_KERNEXEC "KERNEXEC_OR "
17573+#else
17574+#define MODULE_PAX_KERNEXEC ""
17575 #endif
17576
17577+#ifdef CONFIG_PAX_MEMORY_UDEREF
17578+#define MODULE_PAX_UDEREF "UDEREF "
17579+#else
17580+#define MODULE_PAX_UDEREF ""
17581+#endif
17582+
17583+#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF
17584+
17585 #endif /* _ASM_X86_MODULE_H */
17586diff --git a/arch/x86/include/asm/nmi.h b/arch/x86/include/asm/nmi.h
17587index 5f2fc44..106caa6 100644
17588--- a/arch/x86/include/asm/nmi.h
17589+++ b/arch/x86/include/asm/nmi.h
17590@@ -36,26 +36,35 @@ enum {
17591
17592 typedef int (*nmi_handler_t)(unsigned int, struct pt_regs *);
17593
17594+struct nmiaction;
17595+
17596+struct nmiwork {
17597+ const struct nmiaction *action;
17598+ u64 max_duration;
17599+ struct irq_work irq_work;
17600+};
17601+
17602 struct nmiaction {
17603 struct list_head list;
17604 nmi_handler_t handler;
17605- u64 max_duration;
17606- struct irq_work irq_work;
17607 unsigned long flags;
17608 const char *name;
17609-};
17610+ struct nmiwork *work;
17611+} __do_const;
17612
17613 #define register_nmi_handler(t, fn, fg, n, init...) \
17614 ({ \
17615- static struct nmiaction init fn##_na = { \
17616+ static struct nmiwork fn##_nw; \
17617+ static const struct nmiaction init fn##_na = { \
17618 .handler = (fn), \
17619 .name = (n), \
17620 .flags = (fg), \
17621+ .work = &fn##_nw, \
17622 }; \
17623 __register_nmi_handler((t), &fn##_na); \
17624 })
17625
17626-int __register_nmi_handler(unsigned int, struct nmiaction *);
17627+int __register_nmi_handler(unsigned int, const struct nmiaction *);
17628
17629 void unregister_nmi_handler(unsigned int, const char *);
17630
17631diff --git a/arch/x86/include/asm/page.h b/arch/x86/include/asm/page.h
17632index 802dde3..9183e68 100644
17633--- a/arch/x86/include/asm/page.h
17634+++ b/arch/x86/include/asm/page.h
17635@@ -52,6 +52,7 @@ static inline void copy_user_page(void *to, void *from, unsigned long vaddr,
17636 __phys_addr_symbol(__phys_reloc_hide((unsigned long)(x)))
17637
17638 #define __va(x) ((void *)((unsigned long)(x)+PAGE_OFFSET))
17639+#define __early_va(x) ((void *)((unsigned long)(x)+__START_KERNEL_map - phys_base))
17640
17641 #define __boot_va(x) __va(x)
17642 #define __boot_pa(x) __pa(x)
17643@@ -60,11 +61,21 @@ static inline void copy_user_page(void *to, void *from, unsigned long vaddr,
17644 * virt_to_page(kaddr) returns a valid pointer if and only if
17645 * virt_addr_valid(kaddr) returns true.
17646 */
17647-#define virt_to_page(kaddr) pfn_to_page(__pa(kaddr) >> PAGE_SHIFT)
17648 #define pfn_to_kaddr(pfn) __va((pfn) << PAGE_SHIFT)
17649 extern bool __virt_addr_valid(unsigned long kaddr);
17650 #define virt_addr_valid(kaddr) __virt_addr_valid((unsigned long) (kaddr))
17651
17652+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
17653+#define virt_to_page(kaddr) \
17654+ ({ \
17655+ const void *__kaddr = (const void *)(kaddr); \
17656+ BUG_ON(!virt_addr_valid(__kaddr)); \
17657+ pfn_to_page(__pa(__kaddr) >> PAGE_SHIFT); \
17658+ })
17659+#else
17660+#define virt_to_page(kaddr) pfn_to_page(__pa(kaddr) >> PAGE_SHIFT)
17661+#endif
17662+
17663 #endif /* __ASSEMBLY__ */
17664
17665 #include <asm-generic/memory_model.h>
17666diff --git a/arch/x86/include/asm/page_64.h b/arch/x86/include/asm/page_64.h
17667index f408caf..4a0455e 100644
17668--- a/arch/x86/include/asm/page_64.h
17669+++ b/arch/x86/include/asm/page_64.h
17670@@ -7,9 +7,9 @@
17671
17672 /* duplicated to the one in bootmem.h */
17673 extern unsigned long max_pfn;
17674-extern unsigned long phys_base;
17675+extern const unsigned long phys_base;
17676
17677-static inline unsigned long __phys_addr_nodebug(unsigned long x)
17678+static inline unsigned long __intentional_overflow(-1) __phys_addr_nodebug(unsigned long x)
17679 {
17680 unsigned long y = x - __START_KERNEL_map;
17681
17682diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
17683index cd6e1610..70f4418 100644
17684--- a/arch/x86/include/asm/paravirt.h
17685+++ b/arch/x86/include/asm/paravirt.h
17686@@ -560,7 +560,7 @@ static inline pmd_t __pmd(pmdval_t val)
17687 return (pmd_t) { ret };
17688 }
17689
17690-static inline pmdval_t pmd_val(pmd_t pmd)
17691+static inline __intentional_overflow(-1) pmdval_t pmd_val(pmd_t pmd)
17692 {
17693 pmdval_t ret;
17694
17695@@ -626,6 +626,18 @@ static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
17696 val);
17697 }
17698
17699+static inline void set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
17700+{
17701+ pgdval_t val = native_pgd_val(pgd);
17702+
17703+ if (sizeof(pgdval_t) > sizeof(long))
17704+ PVOP_VCALL3(pv_mmu_ops.set_pgd_batched, pgdp,
17705+ val, (u64)val >> 32);
17706+ else
17707+ PVOP_VCALL2(pv_mmu_ops.set_pgd_batched, pgdp,
17708+ val);
17709+}
17710+
17711 static inline void pgd_clear(pgd_t *pgdp)
17712 {
17713 set_pgd(pgdp, __pgd(0));
17714@@ -710,6 +722,21 @@ static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
17715 pv_mmu_ops.set_fixmap(idx, phys, flags);
17716 }
17717
17718+#ifdef CONFIG_PAX_KERNEXEC
17719+static inline unsigned long pax_open_kernel(void)
17720+{
17721+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
17722+}
17723+
17724+static inline unsigned long pax_close_kernel(void)
17725+{
17726+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
17727+}
17728+#else
17729+static inline unsigned long pax_open_kernel(void) { return 0; }
17730+static inline unsigned long pax_close_kernel(void) { return 0; }
17731+#endif
17732+
17733 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
17734
17735 static __always_inline void __ticket_lock_spinning(struct arch_spinlock *lock,
17736@@ -906,7 +933,7 @@ extern void default_banner(void);
17737
17738 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
17739 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
17740-#define PARA_INDIRECT(addr) *%cs:addr
17741+#define PARA_INDIRECT(addr) *%ss:addr
17742 #endif
17743
17744 #define INTERRUPT_RETURN \
17745@@ -981,6 +1008,21 @@ extern void default_banner(void);
17746 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
17747 CLBR_NONE, \
17748 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
17749+
17750+#define GET_CR0_INTO_RDI \
17751+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
17752+ mov %rax,%rdi
17753+
17754+#define SET_RDI_INTO_CR0 \
17755+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
17756+
17757+#define GET_CR3_INTO_RDI \
17758+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
17759+ mov %rax,%rdi
17760+
17761+#define SET_RDI_INTO_CR3 \
17762+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
17763+
17764 #endif /* CONFIG_X86_32 */
17765
17766 #endif /* __ASSEMBLY__ */
17767diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h
17768index 7549b8b..f0edfda 100644
17769--- a/arch/x86/include/asm/paravirt_types.h
17770+++ b/arch/x86/include/asm/paravirt_types.h
17771@@ -84,7 +84,7 @@ struct pv_init_ops {
17772 */
17773 unsigned (*patch)(u8 type, u16 clobber, void *insnbuf,
17774 unsigned long addr, unsigned len);
17775-};
17776+} __no_const __no_randomize_layout;
17777
17778
17779 struct pv_lazy_ops {
17780@@ -92,13 +92,13 @@ struct pv_lazy_ops {
17781 void (*enter)(void);
17782 void (*leave)(void);
17783 void (*flush)(void);
17784-};
17785+} __no_randomize_layout;
17786
17787 struct pv_time_ops {
17788 unsigned long long (*sched_clock)(void);
17789 unsigned long long (*steal_clock)(int cpu);
17790 unsigned long (*get_tsc_khz)(void);
17791-};
17792+} __no_const __no_randomize_layout;
17793
17794 struct pv_cpu_ops {
17795 /* hooks for various privileged instructions */
17796@@ -192,7 +192,7 @@ struct pv_cpu_ops {
17797
17798 void (*start_context_switch)(struct task_struct *prev);
17799 void (*end_context_switch)(struct task_struct *next);
17800-};
17801+} __no_const __no_randomize_layout;
17802
17803 struct pv_irq_ops {
17804 /*
17805@@ -215,7 +215,7 @@ struct pv_irq_ops {
17806 #ifdef CONFIG_X86_64
17807 void (*adjust_exception_frame)(void);
17808 #endif
17809-};
17810+} __no_randomize_layout;
17811
17812 struct pv_apic_ops {
17813 #ifdef CONFIG_X86_LOCAL_APIC
17814@@ -223,7 +223,7 @@ struct pv_apic_ops {
17815 unsigned long start_eip,
17816 unsigned long start_esp);
17817 #endif
17818-};
17819+} __no_const __no_randomize_layout;
17820
17821 struct pv_mmu_ops {
17822 unsigned long (*read_cr2)(void);
17823@@ -313,6 +313,7 @@ struct pv_mmu_ops {
17824 struct paravirt_callee_save make_pud;
17825
17826 void (*set_pgd)(pgd_t *pudp, pgd_t pgdval);
17827+ void (*set_pgd_batched)(pgd_t *pudp, pgd_t pgdval);
17828 #endif /* PAGETABLE_LEVELS == 4 */
17829 #endif /* PAGETABLE_LEVELS >= 3 */
17830
17831@@ -324,7 +325,13 @@ struct pv_mmu_ops {
17832 an mfn. We can tell which is which from the index. */
17833 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
17834 phys_addr_t phys, pgprot_t flags);
17835-};
17836+
17837+#ifdef CONFIG_PAX_KERNEXEC
17838+ unsigned long (*pax_open_kernel)(void);
17839+ unsigned long (*pax_close_kernel)(void);
17840+#endif
17841+
17842+} __no_randomize_layout;
17843
17844 struct arch_spinlock;
17845 #ifdef CONFIG_SMP
17846@@ -336,11 +343,14 @@ typedef u16 __ticket_t;
17847 struct pv_lock_ops {
17848 struct paravirt_callee_save lock_spinning;
17849 void (*unlock_kick)(struct arch_spinlock *lock, __ticket_t ticket);
17850-};
17851+} __no_randomize_layout;
17852
17853 /* This contains all the paravirt structures: we get a convenient
17854 * number for each function using the offset which we use to indicate
17855- * what to patch. */
17856+ * what to patch.
17857+ * shouldn't be randomized due to the "NEAT TRICK" in paravirt.c
17858+ */
17859+
17860 struct paravirt_patch_template {
17861 struct pv_init_ops pv_init_ops;
17862 struct pv_time_ops pv_time_ops;
17863@@ -349,7 +359,7 @@ struct paravirt_patch_template {
17864 struct pv_apic_ops pv_apic_ops;
17865 struct pv_mmu_ops pv_mmu_ops;
17866 struct pv_lock_ops pv_lock_ops;
17867-};
17868+} __no_randomize_layout;
17869
17870 extern struct pv_info pv_info;
17871 extern struct pv_init_ops pv_init_ops;
17872diff --git a/arch/x86/include/asm/pgalloc.h b/arch/x86/include/asm/pgalloc.h
17873index c4412e9..90e88c5 100644
17874--- a/arch/x86/include/asm/pgalloc.h
17875+++ b/arch/x86/include/asm/pgalloc.h
17876@@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(struct mm_struct *mm,
17877 pmd_t *pmd, pte_t *pte)
17878 {
17879 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
17880+ set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
17881+}
17882+
17883+static inline void pmd_populate_user(struct mm_struct *mm,
17884+ pmd_t *pmd, pte_t *pte)
17885+{
17886+ paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
17887 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
17888 }
17889
17890@@ -108,12 +115,22 @@ static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd,
17891
17892 #ifdef CONFIG_X86_PAE
17893 extern void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd);
17894+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
17895+{
17896+ pud_populate(mm, pudp, pmd);
17897+}
17898 #else /* !CONFIG_X86_PAE */
17899 static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
17900 {
17901 paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
17902 set_pud(pud, __pud(_PAGE_TABLE | __pa(pmd)));
17903 }
17904+
17905+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
17906+{
17907+ paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
17908+ set_pud(pud, __pud(_KERNPG_TABLE | __pa(pmd)));
17909+}
17910 #endif /* CONFIG_X86_PAE */
17911
17912 #if PAGETABLE_LEVELS > 3
17913@@ -123,6 +140,12 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
17914 set_pgd(pgd, __pgd(_PAGE_TABLE | __pa(pud)));
17915 }
17916
17917+static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
17918+{
17919+ paravirt_alloc_pud(mm, __pa(pud) >> PAGE_SHIFT);
17920+ set_pgd(pgd, __pgd(_KERNPG_TABLE | __pa(pud)));
17921+}
17922+
17923 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
17924 {
17925 return (pud_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
17926diff --git a/arch/x86/include/asm/pgtable-2level.h b/arch/x86/include/asm/pgtable-2level.h
17927index 206a87f..1623b06 100644
17928--- a/arch/x86/include/asm/pgtable-2level.h
17929+++ b/arch/x86/include/asm/pgtable-2level.h
17930@@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t *ptep , pte_t pte)
17931
17932 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
17933 {
17934+ pax_open_kernel();
17935 *pmdp = pmd;
17936+ pax_close_kernel();
17937 }
17938
17939 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
17940diff --git a/arch/x86/include/asm/pgtable-3level.h b/arch/x86/include/asm/pgtable-3level.h
17941index 81bb91b..9392125 100644
17942--- a/arch/x86/include/asm/pgtable-3level.h
17943+++ b/arch/x86/include/asm/pgtable-3level.h
17944@@ -92,12 +92,16 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
17945
17946 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
17947 {
17948+ pax_open_kernel();
17949 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
17950+ pax_close_kernel();
17951 }
17952
17953 static inline void native_set_pud(pud_t *pudp, pud_t pud)
17954 {
17955+ pax_open_kernel();
17956 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
17957+ pax_close_kernel();
17958 }
17959
17960 /*
17961diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
17962index aa97a07..5c53c32 100644
17963--- a/arch/x86/include/asm/pgtable.h
17964+++ b/arch/x86/include/asm/pgtable.h
17965@@ -46,6 +46,7 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
17966
17967 #ifndef __PAGETABLE_PUD_FOLDED
17968 #define set_pgd(pgdp, pgd) native_set_pgd(pgdp, pgd)
17969+#define set_pgd_batched(pgdp, pgd) native_set_pgd_batched(pgdp, pgd)
17970 #define pgd_clear(pgd) native_pgd_clear(pgd)
17971 #endif
17972
17973@@ -83,12 +84,53 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
17974
17975 #define arch_end_context_switch(prev) do {} while(0)
17976
17977+#define pax_open_kernel() native_pax_open_kernel()
17978+#define pax_close_kernel() native_pax_close_kernel()
17979 #endif /* CONFIG_PARAVIRT */
17980
17981+#define __HAVE_ARCH_PAX_OPEN_KERNEL
17982+#define __HAVE_ARCH_PAX_CLOSE_KERNEL
17983+
17984+#ifdef CONFIG_PAX_KERNEXEC
17985+static inline unsigned long native_pax_open_kernel(void)
17986+{
17987+ unsigned long cr0;
17988+
17989+ preempt_disable();
17990+ barrier();
17991+ cr0 = read_cr0() ^ X86_CR0_WP;
17992+ BUG_ON(cr0 & X86_CR0_WP);
17993+ write_cr0(cr0);
17994+ barrier();
17995+ return cr0 ^ X86_CR0_WP;
17996+}
17997+
17998+static inline unsigned long native_pax_close_kernel(void)
17999+{
18000+ unsigned long cr0;
18001+
18002+ barrier();
18003+ cr0 = read_cr0() ^ X86_CR0_WP;
18004+ BUG_ON(!(cr0 & X86_CR0_WP));
18005+ write_cr0(cr0);
18006+ barrier();
18007+ preempt_enable_no_resched();
18008+ return cr0 ^ X86_CR0_WP;
18009+}
18010+#else
18011+static inline unsigned long native_pax_open_kernel(void) { return 0; }
18012+static inline unsigned long native_pax_close_kernel(void) { return 0; }
18013+#endif
18014+
18015 /*
18016 * The following only work if pte_present() is true.
18017 * Undefined behaviour if not..
18018 */
18019+static inline int pte_user(pte_t pte)
18020+{
18021+ return pte_val(pte) & _PAGE_USER;
18022+}
18023+
18024 static inline int pte_dirty(pte_t pte)
18025 {
18026 return pte_flags(pte) & _PAGE_DIRTY;
18027@@ -155,6 +197,11 @@ static inline unsigned long pud_pfn(pud_t pud)
18028 return (pud_val(pud) & PTE_PFN_MASK) >> PAGE_SHIFT;
18029 }
18030
18031+static inline unsigned long pgd_pfn(pgd_t pgd)
18032+{
18033+ return (pgd_val(pgd) & PTE_PFN_MASK) >> PAGE_SHIFT;
18034+}
18035+
18036 #define pte_page(pte) pfn_to_page(pte_pfn(pte))
18037
18038 static inline int pmd_large(pmd_t pte)
18039@@ -208,9 +255,29 @@ static inline pte_t pte_wrprotect(pte_t pte)
18040 return pte_clear_flags(pte, _PAGE_RW);
18041 }
18042
18043+static inline pte_t pte_mkread(pte_t pte)
18044+{
18045+ return __pte(pte_val(pte) | _PAGE_USER);
18046+}
18047+
18048 static inline pte_t pte_mkexec(pte_t pte)
18049 {
18050- return pte_clear_flags(pte, _PAGE_NX);
18051+#ifdef CONFIG_X86_PAE
18052+ if (__supported_pte_mask & _PAGE_NX)
18053+ return pte_clear_flags(pte, _PAGE_NX);
18054+ else
18055+#endif
18056+ return pte_set_flags(pte, _PAGE_USER);
18057+}
18058+
18059+static inline pte_t pte_exprotect(pte_t pte)
18060+{
18061+#ifdef CONFIG_X86_PAE
18062+ if (__supported_pte_mask & _PAGE_NX)
18063+ return pte_set_flags(pte, _PAGE_NX);
18064+ else
18065+#endif
18066+ return pte_clear_flags(pte, _PAGE_USER);
18067 }
18068
18069 static inline pte_t pte_mkdirty(pte_t pte)
18070@@ -440,6 +507,16 @@ pte_t *populate_extra_pte(unsigned long vaddr);
18071 #endif
18072
18073 #ifndef __ASSEMBLY__
18074+
18075+#ifdef CONFIG_PAX_PER_CPU_PGD
18076+extern pgd_t cpu_pgd[NR_CPUS][2][PTRS_PER_PGD];
18077+enum cpu_pgd_type {kernel = 0, user = 1};
18078+static inline pgd_t *get_cpu_pgd(unsigned int cpu, enum cpu_pgd_type type)
18079+{
18080+ return cpu_pgd[cpu][type];
18081+}
18082+#endif
18083+
18084 #include <linux/mm_types.h>
18085 #include <linux/mmdebug.h>
18086 #include <linux/log2.h>
18087@@ -586,7 +663,7 @@ static inline unsigned long pud_page_vaddr(pud_t pud)
18088 * Currently stuck as a macro due to indirect forward reference to
18089 * linux/mmzone.h's __section_mem_map_addr() definition:
18090 */
18091-#define pud_page(pud) pfn_to_page(pud_val(pud) >> PAGE_SHIFT)
18092+#define pud_page(pud) pfn_to_page((pud_val(pud) & PTE_PFN_MASK) >> PAGE_SHIFT)
18093
18094 /* Find an entry in the second-level page table.. */
18095 static inline pmd_t *pmd_offset(pud_t *pud, unsigned long address)
18096@@ -626,7 +703,7 @@ static inline unsigned long pgd_page_vaddr(pgd_t pgd)
18097 * Currently stuck as a macro due to indirect forward reference to
18098 * linux/mmzone.h's __section_mem_map_addr() definition:
18099 */
18100-#define pgd_page(pgd) pfn_to_page(pgd_val(pgd) >> PAGE_SHIFT)
18101+#define pgd_page(pgd) pfn_to_page((pgd_val(pgd) & PTE_PFN_MASK) >> PAGE_SHIFT)
18102
18103 /* to find an entry in a page-table-directory. */
18104 static inline unsigned long pud_index(unsigned long address)
18105@@ -641,7 +718,7 @@ static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
18106
18107 static inline int pgd_bad(pgd_t pgd)
18108 {
18109- return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
18110+ return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
18111 }
18112
18113 static inline int pgd_none(pgd_t pgd)
18114@@ -664,7 +741,12 @@ static inline int pgd_none(pgd_t pgd)
18115 * pgd_offset() returns a (pgd_t *)
18116 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
18117 */
18118-#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
18119+#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
18120+
18121+#ifdef CONFIG_PAX_PER_CPU_PGD
18122+#define pgd_offset_cpu(cpu, type, address) (get_cpu_pgd(cpu, type) + pgd_index(address))
18123+#endif
18124+
18125 /*
18126 * a shortcut which implies the use of the kernel's pgd, instead
18127 * of a process's
18128@@ -675,6 +757,23 @@ static inline int pgd_none(pgd_t pgd)
18129 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
18130 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
18131
18132+#ifdef CONFIG_X86_32
18133+#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
18134+#else
18135+#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
18136+#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
18137+
18138+#ifdef CONFIG_PAX_MEMORY_UDEREF
18139+#ifdef __ASSEMBLY__
18140+#define pax_user_shadow_base pax_user_shadow_base(%rip)
18141+#else
18142+extern unsigned long pax_user_shadow_base;
18143+extern pgdval_t clone_pgd_mask;
18144+#endif
18145+#endif
18146+
18147+#endif
18148+
18149 #ifndef __ASSEMBLY__
18150
18151 extern int direct_gbpages;
18152@@ -841,11 +940,24 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,
18153 * dst and src can be on the same page, but the range must not overlap,
18154 * and must not cross a page boundary.
18155 */
18156-static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
18157+static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
18158 {
18159- memcpy(dst, src, count * sizeof(pgd_t));
18160+ pax_open_kernel();
18161+ while (count--)
18162+ *dst++ = *src++;
18163+ pax_close_kernel();
18164 }
18165
18166+#ifdef CONFIG_PAX_PER_CPU_PGD
18167+extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src);
18168+#endif
18169+
18170+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18171+extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src);
18172+#else
18173+static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src) {}
18174+#endif
18175+
18176 #define PTE_SHIFT ilog2(PTRS_PER_PTE)
18177 static inline int page_level_shift(enum pg_level level)
18178 {
18179diff --git a/arch/x86/include/asm/pgtable_32.h b/arch/x86/include/asm/pgtable_32.h
18180index b6c0b40..3535d47 100644
18181--- a/arch/x86/include/asm/pgtable_32.h
18182+++ b/arch/x86/include/asm/pgtable_32.h
18183@@ -25,9 +25,6 @@
18184 struct mm_struct;
18185 struct vm_area_struct;
18186
18187-extern pgd_t swapper_pg_dir[1024];
18188-extern pgd_t initial_page_table[1024];
18189-
18190 static inline void pgtable_cache_init(void) { }
18191 static inline void check_pgt_cache(void) { }
18192 void paging_init(void);
18193@@ -45,6 +42,12 @@ void paging_init(void);
18194 # include <asm/pgtable-2level.h>
18195 #endif
18196
18197+extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
18198+extern pgd_t initial_page_table[PTRS_PER_PGD];
18199+#ifdef CONFIG_X86_PAE
18200+extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
18201+#endif
18202+
18203 #if defined(CONFIG_HIGHPTE)
18204 #define pte_offset_map(dir, address) \
18205 ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
18206@@ -59,12 +62,17 @@ void paging_init(void);
18207 /* Clear a kernel PTE and flush it from the TLB */
18208 #define kpte_clear_flush(ptep, vaddr) \
18209 do { \
18210+ pax_open_kernel(); \
18211 pte_clear(&init_mm, (vaddr), (ptep)); \
18212+ pax_close_kernel(); \
18213 __flush_tlb_one((vaddr)); \
18214 } while (0)
18215
18216 #endif /* !__ASSEMBLY__ */
18217
18218+#define HAVE_ARCH_UNMAPPED_AREA
18219+#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
18220+
18221 /*
18222 * kern_addr_valid() is (1) for FLATMEM and (0) for
18223 * SPARSEMEM and DISCONTIGMEM
18224diff --git a/arch/x86/include/asm/pgtable_32_types.h b/arch/x86/include/asm/pgtable_32_types.h
18225index ed5903b..c7fe163 100644
18226--- a/arch/x86/include/asm/pgtable_32_types.h
18227+++ b/arch/x86/include/asm/pgtable_32_types.h
18228@@ -8,7 +8,7 @@
18229 */
18230 #ifdef CONFIG_X86_PAE
18231 # include <asm/pgtable-3level_types.h>
18232-# define PMD_SIZE (1UL << PMD_SHIFT)
18233+# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
18234 # define PMD_MASK (~(PMD_SIZE - 1))
18235 #else
18236 # include <asm/pgtable-2level_types.h>
18237@@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set once high_memory is set */
18238 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
18239 #endif
18240
18241+#ifdef CONFIG_PAX_KERNEXEC
18242+#ifndef __ASSEMBLY__
18243+extern unsigned char MODULES_EXEC_VADDR[];
18244+extern unsigned char MODULES_EXEC_END[];
18245+#endif
18246+#include <asm/boot.h>
18247+#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
18248+#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
18249+#else
18250+#define ktla_ktva(addr) (addr)
18251+#define ktva_ktla(addr) (addr)
18252+#endif
18253+
18254 #define MODULES_VADDR VMALLOC_START
18255 #define MODULES_END VMALLOC_END
18256 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
18257diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
18258index 4572b2f..4430113 100644
18259--- a/arch/x86/include/asm/pgtable_64.h
18260+++ b/arch/x86/include/asm/pgtable_64.h
18261@@ -16,11 +16,16 @@
18262
18263 extern pud_t level3_kernel_pgt[512];
18264 extern pud_t level3_ident_pgt[512];
18265+extern pud_t level3_vmalloc_start_pgt[512];
18266+extern pud_t level3_vmalloc_end_pgt[512];
18267+extern pud_t level3_vmemmap_pgt[512];
18268+extern pud_t level2_vmemmap_pgt[512];
18269 extern pmd_t level2_kernel_pgt[512];
18270 extern pmd_t level2_fixmap_pgt[512];
18271-extern pmd_t level2_ident_pgt[512];
18272+extern pmd_t level2_ident_pgt[512*2];
18273 extern pte_t level1_fixmap_pgt[512];
18274-extern pgd_t init_level4_pgt[];
18275+extern pte_t level1_vsyscall_pgt[512];
18276+extern pgd_t init_level4_pgt[512];
18277
18278 #define swapper_pg_dir init_level4_pgt
18279
18280@@ -62,7 +67,9 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
18281
18282 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
18283 {
18284+ pax_open_kernel();
18285 *pmdp = pmd;
18286+ pax_close_kernel();
18287 }
18288
18289 static inline void native_pmd_clear(pmd_t *pmd)
18290@@ -98,7 +105,9 @@ static inline pmd_t native_pmdp_get_and_clear(pmd_t *xp)
18291
18292 static inline void native_set_pud(pud_t *pudp, pud_t pud)
18293 {
18294+ pax_open_kernel();
18295 *pudp = pud;
18296+ pax_close_kernel();
18297 }
18298
18299 static inline void native_pud_clear(pud_t *pud)
18300@@ -108,6 +117,13 @@ static inline void native_pud_clear(pud_t *pud)
18301
18302 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
18303 {
18304+ pax_open_kernel();
18305+ *pgdp = pgd;
18306+ pax_close_kernel();
18307+}
18308+
18309+static inline void native_set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
18310+{
18311 *pgdp = pgd;
18312 }
18313
18314diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h
18315index 7166e25..baaa6fe 100644
18316--- a/arch/x86/include/asm/pgtable_64_types.h
18317+++ b/arch/x86/include/asm/pgtable_64_types.h
18318@@ -61,9 +61,14 @@ typedef struct { pteval_t pte; } pte_t;
18319 #define MODULES_VADDR (__START_KERNEL_map + KERNEL_IMAGE_SIZE)
18320 #define MODULES_END _AC(0xffffffffff000000, UL)
18321 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
18322+#define MODULES_EXEC_VADDR MODULES_VADDR
18323+#define MODULES_EXEC_END MODULES_END
18324 #define ESPFIX_PGD_ENTRY _AC(-2, UL)
18325 #define ESPFIX_BASE_ADDR (ESPFIX_PGD_ENTRY << PGDIR_SHIFT)
18326
18327+#define ktla_ktva(addr) (addr)
18328+#define ktva_ktla(addr) (addr)
18329+
18330 #define EARLY_DYNAMIC_PAGE_TABLES 64
18331
18332 #endif /* _ASM_X86_PGTABLE_64_DEFS_H */
18333diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
18334index 0778964..0e94758 100644
18335--- a/arch/x86/include/asm/pgtable_types.h
18336+++ b/arch/x86/include/asm/pgtable_types.h
18337@@ -110,8 +110,10 @@
18338
18339 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
18340 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
18341-#else
18342+#elif defined(CONFIG_KMEMCHECK) || defined(CONFIG_MEM_SOFT_DIRTY)
18343 #define _PAGE_NX (_AT(pteval_t, 0))
18344+#else
18345+#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
18346 #endif
18347
18348 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
18349@@ -150,6 +152,9 @@
18350 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
18351 _PAGE_ACCESSED)
18352
18353+#define PAGE_READONLY_NOEXEC PAGE_READONLY
18354+#define PAGE_SHARED_NOEXEC PAGE_SHARED
18355+
18356 #define __PAGE_KERNEL_EXEC \
18357 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
18358 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
18359@@ -160,7 +165,7 @@
18360 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
18361 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
18362 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
18363-#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
18364+#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
18365 #define __PAGE_KERNEL_VVAR (__PAGE_KERNEL_RO | _PAGE_USER)
18366 #define __PAGE_KERNEL_VVAR_NOCACHE (__PAGE_KERNEL_VVAR | _PAGE_PCD | _PAGE_PWT)
18367 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
18368@@ -217,7 +222,7 @@
18369 #ifdef CONFIG_X86_64
18370 #define __PAGE_KERNEL_IDENT_LARGE_EXEC __PAGE_KERNEL_LARGE_EXEC
18371 #else
18372-#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
18373+#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
18374 #define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
18375 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
18376 #endif
18377@@ -256,7 +261,17 @@ static inline pgdval_t pgd_flags(pgd_t pgd)
18378 {
18379 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
18380 }
18381+#endif
18382
18383+#if PAGETABLE_LEVELS == 3
18384+#include <asm-generic/pgtable-nopud.h>
18385+#endif
18386+
18387+#if PAGETABLE_LEVELS == 2
18388+#include <asm-generic/pgtable-nopmd.h>
18389+#endif
18390+
18391+#ifndef __ASSEMBLY__
18392 #if PAGETABLE_LEVELS > 3
18393 typedef struct { pudval_t pud; } pud_t;
18394
18395@@ -270,8 +285,6 @@ static inline pudval_t native_pud_val(pud_t pud)
18396 return pud.pud;
18397 }
18398 #else
18399-#include <asm-generic/pgtable-nopud.h>
18400-
18401 static inline pudval_t native_pud_val(pud_t pud)
18402 {
18403 return native_pgd_val(pud.pgd);
18404@@ -291,8 +304,6 @@ static inline pmdval_t native_pmd_val(pmd_t pmd)
18405 return pmd.pmd;
18406 }
18407 #else
18408-#include <asm-generic/pgtable-nopmd.h>
18409-
18410 static inline pmdval_t native_pmd_val(pmd_t pmd)
18411 {
18412 return native_pgd_val(pmd.pud.pgd);
18413@@ -346,7 +357,6 @@ typedef struct page *pgtable_t;
18414
18415 extern pteval_t __supported_pte_mask;
18416 extern void set_nx(void);
18417-extern int nx_enabled;
18418
18419 #define pgprot_writecombine pgprot_writecombine
18420 extern pgprot_t pgprot_writecombine(pgprot_t prot);
18421diff --git a/arch/x86/include/asm/preempt.h b/arch/x86/include/asm/preempt.h
18422index 4008734..48f0d81 100644
18423--- a/arch/x86/include/asm/preempt.h
18424+++ b/arch/x86/include/asm/preempt.h
18425@@ -87,7 +87,7 @@ static __always_inline void __preempt_count_sub(int val)
18426 */
18427 static __always_inline bool __preempt_count_dec_and_test(void)
18428 {
18429- GEN_UNARY_RMWcc("decl", __preempt_count, __percpu_arg(0), "e");
18430+ GEN_UNARY_RMWcc("decl", "incl", __preempt_count, __percpu_arg(0), "e");
18431 }
18432
18433 /*
18434diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
18435index eb71ec7..f06532a 100644
18436--- a/arch/x86/include/asm/processor.h
18437+++ b/arch/x86/include/asm/processor.h
18438@@ -127,7 +127,7 @@ struct cpuinfo_x86 {
18439 /* Index into per_cpu list: */
18440 u16 cpu_index;
18441 u32 microcode;
18442-} __attribute__((__aligned__(SMP_CACHE_BYTES)));
18443+} __attribute__((__aligned__(SMP_CACHE_BYTES))) __randomize_layout;
18444
18445 #define X86_VENDOR_INTEL 0
18446 #define X86_VENDOR_CYRIX 1
18447@@ -198,9 +198,21 @@ static inline void native_cpuid(unsigned int *eax, unsigned int *ebx,
18448 : "memory");
18449 }
18450
18451+/* invpcid (%rdx),%rax */
18452+#define __ASM_INVPCID ".byte 0x66,0x0f,0x38,0x82,0x02"
18453+
18454+#define INVPCID_SINGLE_ADDRESS 0UL
18455+#define INVPCID_SINGLE_CONTEXT 1UL
18456+#define INVPCID_ALL_GLOBAL 2UL
18457+#define INVPCID_ALL_NONGLOBAL 3UL
18458+
18459+#define PCID_KERNEL 0UL
18460+#define PCID_USER 1UL
18461+#define PCID_NOFLUSH (1UL << 63)
18462+
18463 static inline void load_cr3(pgd_t *pgdir)
18464 {
18465- write_cr3(__pa(pgdir));
18466+ write_cr3(__pa(pgdir) | PCID_KERNEL);
18467 }
18468
18469 #ifdef CONFIG_X86_32
18470@@ -282,7 +294,7 @@ struct tss_struct {
18471
18472 } ____cacheline_aligned;
18473
18474-DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
18475+extern struct tss_struct init_tss[NR_CPUS];
18476
18477 /*
18478 * Save the original ist values for checking stack pointers during debugging
18479@@ -478,6 +490,7 @@ struct thread_struct {
18480 unsigned short ds;
18481 unsigned short fsindex;
18482 unsigned short gsindex;
18483+ unsigned short ss;
18484 #endif
18485 #ifdef CONFIG_X86_32
18486 unsigned long ip;
18487@@ -587,29 +600,8 @@ static inline void load_sp0(struct tss_struct *tss,
18488 extern unsigned long mmu_cr4_features;
18489 extern u32 *trampoline_cr4_features;
18490
18491-static inline void set_in_cr4(unsigned long mask)
18492-{
18493- unsigned long cr4;
18494-
18495- mmu_cr4_features |= mask;
18496- if (trampoline_cr4_features)
18497- *trampoline_cr4_features = mmu_cr4_features;
18498- cr4 = read_cr4();
18499- cr4 |= mask;
18500- write_cr4(cr4);
18501-}
18502-
18503-static inline void clear_in_cr4(unsigned long mask)
18504-{
18505- unsigned long cr4;
18506-
18507- mmu_cr4_features &= ~mask;
18508- if (trampoline_cr4_features)
18509- *trampoline_cr4_features = mmu_cr4_features;
18510- cr4 = read_cr4();
18511- cr4 &= ~mask;
18512- write_cr4(cr4);
18513-}
18514+extern void set_in_cr4(unsigned long mask);
18515+extern void clear_in_cr4(unsigned long mask);
18516
18517 typedef struct {
18518 unsigned long seg;
18519@@ -837,11 +829,18 @@ static inline void spin_lock_prefetch(const void *x)
18520 */
18521 #define TASK_SIZE PAGE_OFFSET
18522 #define TASK_SIZE_MAX TASK_SIZE
18523+
18524+#ifdef CONFIG_PAX_SEGMEXEC
18525+#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
18526+#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
18527+#else
18528 #define STACK_TOP TASK_SIZE
18529-#define STACK_TOP_MAX STACK_TOP
18530+#endif
18531+
18532+#define STACK_TOP_MAX TASK_SIZE
18533
18534 #define INIT_THREAD { \
18535- .sp0 = sizeof(init_stack) + (long)&init_stack, \
18536+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
18537 .vm86_info = NULL, \
18538 .sysenter_cs = __KERNEL_CS, \
18539 .io_bitmap_ptr = NULL, \
18540@@ -855,7 +854,7 @@ static inline void spin_lock_prefetch(const void *x)
18541 */
18542 #define INIT_TSS { \
18543 .x86_tss = { \
18544- .sp0 = sizeof(init_stack) + (long)&init_stack, \
18545+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
18546 .ss0 = __KERNEL_DS, \
18547 .ss1 = __KERNEL_CS, \
18548 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
18549@@ -866,11 +865,7 @@ static inline void spin_lock_prefetch(const void *x)
18550 extern unsigned long thread_saved_pc(struct task_struct *tsk);
18551
18552 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
18553-#define KSTK_TOP(info) \
18554-({ \
18555- unsigned long *__ptr = (unsigned long *)(info); \
18556- (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
18557-})
18558+#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
18559
18560 /*
18561 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
18562@@ -885,7 +880,7 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
18563 #define task_pt_regs(task) \
18564 ({ \
18565 struct pt_regs *__regs__; \
18566- __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
18567+ __regs__ = (struct pt_regs *)((task)->thread.sp0); \
18568 __regs__ - 1; \
18569 })
18570
18571@@ -895,13 +890,13 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
18572 /*
18573 * User space process size. 47bits minus one guard page.
18574 */
18575-#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
18576+#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
18577
18578 /* This decides where the kernel will search for a free chunk of vm
18579 * space during mmap's.
18580 */
18581 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
18582- 0xc0000000 : 0xFFFFe000)
18583+ 0xc0000000 : 0xFFFFf000)
18584
18585 #define TASK_SIZE (test_thread_flag(TIF_ADDR32) ? \
18586 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
18587@@ -912,11 +907,11 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
18588 #define STACK_TOP_MAX TASK_SIZE_MAX
18589
18590 #define INIT_THREAD { \
18591- .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
18592+ .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
18593 }
18594
18595 #define INIT_TSS { \
18596- .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
18597+ .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
18598 }
18599
18600 /*
18601@@ -944,6 +939,10 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
18602 */
18603 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
18604
18605+#ifdef CONFIG_PAX_SEGMEXEC
18606+#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
18607+#endif
18608+
18609 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
18610
18611 /* Get/set a process' ability to use the timestamp counter instruction */
18612@@ -970,7 +969,7 @@ static inline uint32_t hypervisor_cpuid_base(const char *sig, uint32_t leaves)
18613 return 0;
18614 }
18615
18616-extern unsigned long arch_align_stack(unsigned long sp);
18617+#define arch_align_stack(x) ((x) & ~0xfUL)
18618 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
18619
18620 void default_idle(void);
18621@@ -980,6 +979,6 @@ bool xen_set_default_idle(void);
18622 #define xen_set_default_idle 0
18623 #endif
18624
18625-void stop_this_cpu(void *dummy);
18626+void stop_this_cpu(void *dummy) __noreturn;
18627 void df_debug(struct pt_regs *regs, long error_code);
18628 #endif /* _ASM_X86_PROCESSOR_H */
18629diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
18630index 86fc2bb..bd5049a 100644
18631--- a/arch/x86/include/asm/ptrace.h
18632+++ b/arch/x86/include/asm/ptrace.h
18633@@ -89,28 +89,29 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
18634 }
18635
18636 /*
18637- * user_mode_vm(regs) determines whether a register set came from user mode.
18638+ * user_mode(regs) determines whether a register set came from user mode.
18639 * This is true if V8086 mode was enabled OR if the register set was from
18640 * protected mode with RPL-3 CS value. This tricky test checks that with
18641 * one comparison. Many places in the kernel can bypass this full check
18642- * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
18643+ * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
18644+ * be used.
18645 */
18646-static inline int user_mode(struct pt_regs *regs)
18647+static inline int user_mode_novm(struct pt_regs *regs)
18648 {
18649 #ifdef CONFIG_X86_32
18650 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
18651 #else
18652- return !!(regs->cs & 3);
18653+ return !!(regs->cs & SEGMENT_RPL_MASK);
18654 #endif
18655 }
18656
18657-static inline int user_mode_vm(struct pt_regs *regs)
18658+static inline int user_mode(struct pt_regs *regs)
18659 {
18660 #ifdef CONFIG_X86_32
18661 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
18662 USER_RPL;
18663 #else
18664- return user_mode(regs);
18665+ return user_mode_novm(regs);
18666 #endif
18667 }
18668
18669@@ -126,15 +127,16 @@ static inline int v8086_mode(struct pt_regs *regs)
18670 #ifdef CONFIG_X86_64
18671 static inline bool user_64bit_mode(struct pt_regs *regs)
18672 {
18673+ unsigned long cs = regs->cs & 0xffff;
18674 #ifndef CONFIG_PARAVIRT
18675 /*
18676 * On non-paravirt systems, this is the only long mode CPL 3
18677 * selector. We do not allow long mode selectors in the LDT.
18678 */
18679- return regs->cs == __USER_CS;
18680+ return cs == __USER_CS;
18681 #else
18682 /* Headers are too twisted for this to go in paravirt.h. */
18683- return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs;
18684+ return cs == __USER_CS || cs == pv_info.extra_user_64bit_cs;
18685 #endif
18686 }
18687
18688@@ -185,9 +187,11 @@ static inline unsigned long regs_get_register(struct pt_regs *regs,
18689 * Traps from the kernel do not save sp and ss.
18690 * Use the helper function to retrieve sp.
18691 */
18692- if (offset == offsetof(struct pt_regs, sp) &&
18693- regs->cs == __KERNEL_CS)
18694- return kernel_stack_pointer(regs);
18695+ if (offset == offsetof(struct pt_regs, sp)) {
18696+ unsigned long cs = regs->cs & 0xffff;
18697+ if (cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS)
18698+ return kernel_stack_pointer(regs);
18699+ }
18700 #endif
18701 return *(unsigned long *)((unsigned long)regs + offset);
18702 }
18703diff --git a/arch/x86/include/asm/qrwlock.h b/arch/x86/include/asm/qrwlock.h
18704index ae0e241..e80b10b 100644
18705--- a/arch/x86/include/asm/qrwlock.h
18706+++ b/arch/x86/include/asm/qrwlock.h
18707@@ -7,8 +7,8 @@
18708 #define queue_write_unlock queue_write_unlock
18709 static inline void queue_write_unlock(struct qrwlock *lock)
18710 {
18711- barrier();
18712- ACCESS_ONCE(*(u8 *)&lock->cnts) = 0;
18713+ barrier();
18714+ ACCESS_ONCE_RW(*(u8 *)&lock->cnts) = 0;
18715 }
18716 #endif
18717
18718diff --git a/arch/x86/include/asm/realmode.h b/arch/x86/include/asm/realmode.h
18719index 9c6b890..5305f53 100644
18720--- a/arch/x86/include/asm/realmode.h
18721+++ b/arch/x86/include/asm/realmode.h
18722@@ -22,16 +22,14 @@ struct real_mode_header {
18723 #endif
18724 /* APM/BIOS reboot */
18725 u32 machine_real_restart_asm;
18726-#ifdef CONFIG_X86_64
18727 u32 machine_real_restart_seg;
18728-#endif
18729 };
18730
18731 /* This must match data at trampoline_32/64.S */
18732 struct trampoline_header {
18733 #ifdef CONFIG_X86_32
18734 u32 start;
18735- u16 gdt_pad;
18736+ u16 boot_cs;
18737 u16 gdt_limit;
18738 u32 gdt_base;
18739 #else
18740diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h
18741index a82c4f1..ac45053 100644
18742--- a/arch/x86/include/asm/reboot.h
18743+++ b/arch/x86/include/asm/reboot.h
18744@@ -6,13 +6,13 @@
18745 struct pt_regs;
18746
18747 struct machine_ops {
18748- void (*restart)(char *cmd);
18749- void (*halt)(void);
18750- void (*power_off)(void);
18751+ void (* __noreturn restart)(char *cmd);
18752+ void (* __noreturn halt)(void);
18753+ void (* __noreturn power_off)(void);
18754 void (*shutdown)(void);
18755 void (*crash_shutdown)(struct pt_regs *);
18756- void (*emergency_restart)(void);
18757-};
18758+ void (* __noreturn emergency_restart)(void);
18759+} __no_const;
18760
18761 extern struct machine_ops machine_ops;
18762
18763diff --git a/arch/x86/include/asm/rmwcc.h b/arch/x86/include/asm/rmwcc.h
18764index 8f7866a..e442f20 100644
18765--- a/arch/x86/include/asm/rmwcc.h
18766+++ b/arch/x86/include/asm/rmwcc.h
18767@@ -3,7 +3,34 @@
18768
18769 #ifdef CC_HAVE_ASM_GOTO
18770
18771-#define __GEN_RMWcc(fullop, var, cc, ...) \
18772+#ifdef CONFIG_PAX_REFCOUNT
18773+#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
18774+do { \
18775+ asm_volatile_goto (fullop \
18776+ ";jno 0f\n" \
18777+ fullantiop \
18778+ ";int $4\n0:\n" \
18779+ _ASM_EXTABLE(0b, 0b) \
18780+ ";j" cc " %l[cc_label]" \
18781+ : : "m" (var), ## __VA_ARGS__ \
18782+ : "memory" : cc_label); \
18783+ return 0; \
18784+cc_label: \
18785+ return 1; \
18786+} while (0)
18787+#else
18788+#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
18789+do { \
18790+ asm_volatile_goto (fullop ";j" cc " %l[cc_label]" \
18791+ : : "m" (var), ## __VA_ARGS__ \
18792+ : "memory" : cc_label); \
18793+ return 0; \
18794+cc_label: \
18795+ return 1; \
18796+} while (0)
18797+#endif
18798+
18799+#define __GEN_RMWcc_unchecked(fullop, var, cc, ...) \
18800 do { \
18801 asm_volatile_goto (fullop "; j" cc " %l[cc_label]" \
18802 : : "m" (var), ## __VA_ARGS__ \
18803@@ -13,15 +40,46 @@ cc_label: \
18804 return 1; \
18805 } while (0)
18806
18807-#define GEN_UNARY_RMWcc(op, var, arg0, cc) \
18808- __GEN_RMWcc(op " " arg0, var, cc)
18809+#define GEN_UNARY_RMWcc(op, antiop, var, arg0, cc) \
18810+ __GEN_RMWcc(op " " arg0, antiop " " arg0, var, cc)
18811
18812-#define GEN_BINARY_RMWcc(op, var, vcon, val, arg0, cc) \
18813- __GEN_RMWcc(op " %1, " arg0, var, cc, vcon (val))
18814+#define GEN_UNARY_RMWcc_unchecked(op, var, arg0, cc) \
18815+ __GEN_RMWcc_unchecked(op " " arg0, var, cc)
18816+
18817+#define GEN_BINARY_RMWcc(op, antiop, var, vcon, val, arg0, cc) \
18818+ __GEN_RMWcc(op " %1, " arg0, antiop " %1, " arg0, var, cc, vcon (val))
18819+
18820+#define GEN_BINARY_RMWcc_unchecked(op, var, vcon, val, arg0, cc) \
18821+ __GEN_RMWcc_unchecked(op " %1, " arg0, var, cc, vcon (val))
18822
18823 #else /* !CC_HAVE_ASM_GOTO */
18824
18825-#define __GEN_RMWcc(fullop, var, cc, ...) \
18826+#ifdef CONFIG_PAX_REFCOUNT
18827+#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
18828+do { \
18829+ char c; \
18830+ asm volatile (fullop \
18831+ ";jno 0f\n" \
18832+ fullantiop \
18833+ ";int $4\n0:\n" \
18834+ _ASM_EXTABLE(0b, 0b) \
18835+ "; set" cc " %1" \
18836+ : "+m" (var), "=qm" (c) \
18837+ : __VA_ARGS__ : "memory"); \
18838+ return c != 0; \
18839+} while (0)
18840+#else
18841+#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
18842+do { \
18843+ char c; \
18844+ asm volatile (fullop "; set" cc " %1" \
18845+ : "+m" (var), "=qm" (c) \
18846+ : __VA_ARGS__ : "memory"); \
18847+ return c != 0; \
18848+} while (0)
18849+#endif
18850+
18851+#define __GEN_RMWcc_unchecked(fullop, var, cc, ...) \
18852 do { \
18853 char c; \
18854 asm volatile (fullop "; set" cc " %1" \
18855@@ -30,11 +88,17 @@ do { \
18856 return c != 0; \
18857 } while (0)
18858
18859-#define GEN_UNARY_RMWcc(op, var, arg0, cc) \
18860- __GEN_RMWcc(op " " arg0, var, cc)
18861+#define GEN_UNARY_RMWcc(op, antiop, var, arg0, cc) \
18862+ __GEN_RMWcc(op " " arg0, antiop " " arg0, var, cc)
18863+
18864+#define GEN_UNARY_RMWcc_unchecked(op, var, arg0, cc) \
18865+ __GEN_RMWcc_unchecked(op " " arg0, var, cc)
18866+
18867+#define GEN_BINARY_RMWcc(op, antiop, var, vcon, val, arg0, cc) \
18868+ __GEN_RMWcc(op " %2, " arg0, antiop " %2, " arg0, var, cc, vcon (val))
18869
18870-#define GEN_BINARY_RMWcc(op, var, vcon, val, arg0, cc) \
18871- __GEN_RMWcc(op " %2, " arg0, var, cc, vcon (val))
18872+#define GEN_BINARY_RMWcc_unchecked(op, var, vcon, val, arg0, cc) \
18873+ __GEN_RMWcc_unchecked(op " %2, " arg0, var, cc, vcon (val))
18874
18875 #endif /* CC_HAVE_ASM_GOTO */
18876
18877diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h
18878index cad82c9..2e5c5c1 100644
18879--- a/arch/x86/include/asm/rwsem.h
18880+++ b/arch/x86/include/asm/rwsem.h
18881@@ -64,6 +64,14 @@ static inline void __down_read(struct rw_semaphore *sem)
18882 {
18883 asm volatile("# beginning down_read\n\t"
18884 LOCK_PREFIX _ASM_INC "(%1)\n\t"
18885+
18886+#ifdef CONFIG_PAX_REFCOUNT
18887+ "jno 0f\n"
18888+ LOCK_PREFIX _ASM_DEC "(%1)\n"
18889+ "int $4\n0:\n"
18890+ _ASM_EXTABLE(0b, 0b)
18891+#endif
18892+
18893 /* adds 0x00000001 */
18894 " jns 1f\n"
18895 " call call_rwsem_down_read_failed\n"
18896@@ -85,6 +93,14 @@ static inline int __down_read_trylock(struct rw_semaphore *sem)
18897 "1:\n\t"
18898 " mov %1,%2\n\t"
18899 " add %3,%2\n\t"
18900+
18901+#ifdef CONFIG_PAX_REFCOUNT
18902+ "jno 0f\n"
18903+ "sub %3,%2\n"
18904+ "int $4\n0:\n"
18905+ _ASM_EXTABLE(0b, 0b)
18906+#endif
18907+
18908 " jle 2f\n\t"
18909 LOCK_PREFIX " cmpxchg %2,%0\n\t"
18910 " jnz 1b\n\t"
18911@@ -104,6 +120,14 @@ static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
18912 long tmp;
18913 asm volatile("# beginning down_write\n\t"
18914 LOCK_PREFIX " xadd %1,(%2)\n\t"
18915+
18916+#ifdef CONFIG_PAX_REFCOUNT
18917+ "jno 0f\n"
18918+ "mov %1,(%2)\n"
18919+ "int $4\n0:\n"
18920+ _ASM_EXTABLE(0b, 0b)
18921+#endif
18922+
18923 /* adds 0xffff0001, returns the old value */
18924 " test " __ASM_SEL(%w1,%k1) "," __ASM_SEL(%w1,%k1) "\n\t"
18925 /* was the active mask 0 before? */
18926@@ -155,6 +179,14 @@ static inline void __up_read(struct rw_semaphore *sem)
18927 long tmp;
18928 asm volatile("# beginning __up_read\n\t"
18929 LOCK_PREFIX " xadd %1,(%2)\n\t"
18930+
18931+#ifdef CONFIG_PAX_REFCOUNT
18932+ "jno 0f\n"
18933+ "mov %1,(%2)\n"
18934+ "int $4\n0:\n"
18935+ _ASM_EXTABLE(0b, 0b)
18936+#endif
18937+
18938 /* subtracts 1, returns the old value */
18939 " jns 1f\n\t"
18940 " call call_rwsem_wake\n" /* expects old value in %edx */
18941@@ -173,6 +205,14 @@ static inline void __up_write(struct rw_semaphore *sem)
18942 long tmp;
18943 asm volatile("# beginning __up_write\n\t"
18944 LOCK_PREFIX " xadd %1,(%2)\n\t"
18945+
18946+#ifdef CONFIG_PAX_REFCOUNT
18947+ "jno 0f\n"
18948+ "mov %1,(%2)\n"
18949+ "int $4\n0:\n"
18950+ _ASM_EXTABLE(0b, 0b)
18951+#endif
18952+
18953 /* subtracts 0xffff0001, returns the old value */
18954 " jns 1f\n\t"
18955 " call call_rwsem_wake\n" /* expects old value in %edx */
18956@@ -190,6 +230,14 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
18957 {
18958 asm volatile("# beginning __downgrade_write\n\t"
18959 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
18960+
18961+#ifdef CONFIG_PAX_REFCOUNT
18962+ "jno 0f\n"
18963+ LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
18964+ "int $4\n0:\n"
18965+ _ASM_EXTABLE(0b, 0b)
18966+#endif
18967+
18968 /*
18969 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
18970 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
18971@@ -208,7 +256,15 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
18972 */
18973 static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
18974 {
18975- asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
18976+ asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
18977+
18978+#ifdef CONFIG_PAX_REFCOUNT
18979+ "jno 0f\n"
18980+ LOCK_PREFIX _ASM_SUB "%1,%0\n"
18981+ "int $4\n0:\n"
18982+ _ASM_EXTABLE(0b, 0b)
18983+#endif
18984+
18985 : "+m" (sem->count)
18986 : "er" (delta));
18987 }
18988@@ -218,7 +274,7 @@ static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
18989 */
18990 static inline long rwsem_atomic_update(long delta, struct rw_semaphore *sem)
18991 {
18992- return delta + xadd(&sem->count, delta);
18993+ return delta + xadd_check_overflow(&sem->count, delta);
18994 }
18995
18996 #endif /* __KERNEL__ */
18997diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
18998index 6f1c3a8..7744f19 100644
18999--- a/arch/x86/include/asm/segment.h
19000+++ b/arch/x86/include/asm/segment.h
19001@@ -64,10 +64,15 @@
19002 * 26 - ESPFIX small SS
19003 * 27 - per-cpu [ offset to per-cpu data area ]
19004 * 28 - stack_canary-20 [ for stack protector ]
19005- * 29 - unused
19006- * 30 - unused
19007+ * 29 - PCI BIOS CS
19008+ * 30 - PCI BIOS DS
19009 * 31 - TSS for double fault handler
19010 */
19011+#define GDT_ENTRY_KERNEXEC_EFI_CS (1)
19012+#define GDT_ENTRY_KERNEXEC_EFI_DS (2)
19013+#define __KERNEXEC_EFI_CS (GDT_ENTRY_KERNEXEC_EFI_CS*8)
19014+#define __KERNEXEC_EFI_DS (GDT_ENTRY_KERNEXEC_EFI_DS*8)
19015+
19016 #define GDT_ENTRY_TLS_MIN 6
19017 #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
19018
19019@@ -79,6 +84,8 @@
19020
19021 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
19022
19023+#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
19024+
19025 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
19026
19027 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
19028@@ -104,6 +111,12 @@
19029 #define __KERNEL_STACK_CANARY 0
19030 #endif
19031
19032+#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
19033+#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
19034+
19035+#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
19036+#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
19037+
19038 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
19039
19040 /*
19041@@ -141,7 +154,7 @@
19042 */
19043
19044 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
19045-#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
19046+#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
19047
19048
19049 #else
19050@@ -165,6 +178,8 @@
19051 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS*8+3)
19052 #define __USER32_DS __USER_DS
19053
19054+#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
19055+
19056 #define GDT_ENTRY_TSS 8 /* needs two entries */
19057 #define GDT_ENTRY_LDT 10 /* needs two entries */
19058 #define GDT_ENTRY_TLS_MIN 12
19059@@ -173,6 +188,8 @@
19060 #define GDT_ENTRY_PER_CPU 15 /* Abused to load per CPU data from limit */
19061 #define __PER_CPU_SEG (GDT_ENTRY_PER_CPU * 8 + 3)
19062
19063+#define GDT_ENTRY_UDEREF_KERNEL_DS 16
19064+
19065 /* TLS indexes for 64bit - hardcoded in arch_prctl */
19066 #define FS_TLS 0
19067 #define GS_TLS 1
19068@@ -180,12 +197,14 @@
19069 #define GS_TLS_SEL ((GDT_ENTRY_TLS_MIN+GS_TLS)*8 + 3)
19070 #define FS_TLS_SEL ((GDT_ENTRY_TLS_MIN+FS_TLS)*8 + 3)
19071
19072-#define GDT_ENTRIES 16
19073+#define GDT_ENTRIES 17
19074
19075 #endif
19076
19077 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
19078+#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
19079 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
19080+#define __UDEREF_KERNEL_DS (GDT_ENTRY_UDEREF_KERNEL_DS*8)
19081 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
19082 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
19083 #ifndef CONFIG_PARAVIRT
19084@@ -268,7 +287,7 @@ static inline unsigned long get_limit(unsigned long segment)
19085 {
19086 unsigned long __limit;
19087 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
19088- return __limit + 1;
19089+ return __limit;
19090 }
19091
19092 #endif /* !__ASSEMBLY__ */
19093diff --git a/arch/x86/include/asm/smap.h b/arch/x86/include/asm/smap.h
19094index 8d3120f..352b440 100644
19095--- a/arch/x86/include/asm/smap.h
19096+++ b/arch/x86/include/asm/smap.h
19097@@ -25,11 +25,40 @@
19098
19099 #include <asm/alternative-asm.h>
19100
19101+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19102+#define ASM_PAX_OPEN_USERLAND \
19103+ 661: jmp 663f; \
19104+ .pushsection .altinstr_replacement, "a" ; \
19105+ 662: pushq %rax; nop; \
19106+ .popsection ; \
19107+ .pushsection .altinstructions, "a" ; \
19108+ altinstruction_entry 661b, 662b, X86_FEATURE_STRONGUDEREF, 2, 2;\
19109+ .popsection ; \
19110+ call __pax_open_userland; \
19111+ popq %rax; \
19112+ 663:
19113+
19114+#define ASM_PAX_CLOSE_USERLAND \
19115+ 661: jmp 663f; \
19116+ .pushsection .altinstr_replacement, "a" ; \
19117+ 662: pushq %rax; nop; \
19118+ .popsection; \
19119+ .pushsection .altinstructions, "a" ; \
19120+ altinstruction_entry 661b, 662b, X86_FEATURE_STRONGUDEREF, 2, 2;\
19121+ .popsection; \
19122+ call __pax_close_userland; \
19123+ popq %rax; \
19124+ 663:
19125+#else
19126+#define ASM_PAX_OPEN_USERLAND
19127+#define ASM_PAX_CLOSE_USERLAND
19128+#endif
19129+
19130 #ifdef CONFIG_X86_SMAP
19131
19132 #define ASM_CLAC \
19133 661: ASM_NOP3 ; \
19134- .pushsection .altinstr_replacement, "ax" ; \
19135+ .pushsection .altinstr_replacement, "a" ; \
19136 662: __ASM_CLAC ; \
19137 .popsection ; \
19138 .pushsection .altinstructions, "a" ; \
19139@@ -38,7 +67,7 @@
19140
19141 #define ASM_STAC \
19142 661: ASM_NOP3 ; \
19143- .pushsection .altinstr_replacement, "ax" ; \
19144+ .pushsection .altinstr_replacement, "a" ; \
19145 662: __ASM_STAC ; \
19146 .popsection ; \
19147 .pushsection .altinstructions, "a" ; \
19148@@ -56,6 +85,37 @@
19149
19150 #include <asm/alternative.h>
19151
19152+#define __HAVE_ARCH_PAX_OPEN_USERLAND
19153+#define __HAVE_ARCH_PAX_CLOSE_USERLAND
19154+
19155+extern void __pax_open_userland(void);
19156+static __always_inline unsigned long pax_open_userland(void)
19157+{
19158+
19159+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19160+ asm volatile(ALTERNATIVE(ASM_NOP5, "call %P[open]", X86_FEATURE_STRONGUDEREF)
19161+ :
19162+ : [open] "i" (__pax_open_userland)
19163+ : "memory", "rax");
19164+#endif
19165+
19166+ return 0;
19167+}
19168+
19169+extern void __pax_close_userland(void);
19170+static __always_inline unsigned long pax_close_userland(void)
19171+{
19172+
19173+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19174+ asm volatile(ALTERNATIVE(ASM_NOP5, "call %P[close]", X86_FEATURE_STRONGUDEREF)
19175+ :
19176+ : [close] "i" (__pax_close_userland)
19177+ : "memory", "rax");
19178+#endif
19179+
19180+ return 0;
19181+}
19182+
19183 #ifdef CONFIG_X86_SMAP
19184
19185 static __always_inline void clac(void)
19186diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
19187index 8cd1cc3..827e09e 100644
19188--- a/arch/x86/include/asm/smp.h
19189+++ b/arch/x86/include/asm/smp.h
19190@@ -35,7 +35,7 @@ DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_core_map);
19191 /* cpus sharing the last level cache: */
19192 DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_llc_shared_map);
19193 DECLARE_PER_CPU_READ_MOSTLY(u16, cpu_llc_id);
19194-DECLARE_PER_CPU_READ_MOSTLY(int, cpu_number);
19195+DECLARE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
19196
19197 static inline struct cpumask *cpu_sibling_mask(int cpu)
19198 {
19199@@ -78,7 +78,7 @@ struct smp_ops {
19200
19201 void (*send_call_func_ipi)(const struct cpumask *mask);
19202 void (*send_call_func_single_ipi)(int cpu);
19203-};
19204+} __no_const;
19205
19206 /* Globals due to paravirt */
19207 extern void set_cpu_sibling_map(int cpu);
19208@@ -191,14 +191,8 @@ extern unsigned disabled_cpus;
19209 extern int safe_smp_processor_id(void);
19210
19211 #elif defined(CONFIG_X86_64_SMP)
19212-#define raw_smp_processor_id() (this_cpu_read(cpu_number))
19213-
19214-#define stack_smp_processor_id() \
19215-({ \
19216- struct thread_info *ti; \
19217- __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
19218- ti->cpu; \
19219-})
19220+#define raw_smp_processor_id() (this_cpu_read(cpu_number))
19221+#define stack_smp_processor_id() raw_smp_processor_id()
19222 #define safe_smp_processor_id() smp_processor_id()
19223
19224 #endif
19225diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
19226index 6a99859..03cb807 100644
19227--- a/arch/x86/include/asm/stackprotector.h
19228+++ b/arch/x86/include/asm/stackprotector.h
19229@@ -47,7 +47,7 @@
19230 * head_32 for boot CPU and setup_per_cpu_areas() for others.
19231 */
19232 #define GDT_STACK_CANARY_INIT \
19233- [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
19234+ [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
19235
19236 /*
19237 * Initialize the stackprotector canary value.
19238@@ -112,7 +112,7 @@ static inline void setup_stack_canary_segment(int cpu)
19239
19240 static inline void load_stack_canary_segment(void)
19241 {
19242-#ifdef CONFIG_X86_32
19243+#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
19244 asm volatile ("mov %0, %%gs" : : "r" (0));
19245 #endif
19246 }
19247diff --git a/arch/x86/include/asm/stacktrace.h b/arch/x86/include/asm/stacktrace.h
19248index 70bbe39..4ae2bd4 100644
19249--- a/arch/x86/include/asm/stacktrace.h
19250+++ b/arch/x86/include/asm/stacktrace.h
19251@@ -11,28 +11,20 @@
19252
19253 extern int kstack_depth_to_print;
19254
19255-struct thread_info;
19256+struct task_struct;
19257 struct stacktrace_ops;
19258
19259-typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
19260- unsigned long *stack,
19261- unsigned long bp,
19262- const struct stacktrace_ops *ops,
19263- void *data,
19264- unsigned long *end,
19265- int *graph);
19266+typedef unsigned long walk_stack_t(struct task_struct *task,
19267+ void *stack_start,
19268+ unsigned long *stack,
19269+ unsigned long bp,
19270+ const struct stacktrace_ops *ops,
19271+ void *data,
19272+ unsigned long *end,
19273+ int *graph);
19274
19275-extern unsigned long
19276-print_context_stack(struct thread_info *tinfo,
19277- unsigned long *stack, unsigned long bp,
19278- const struct stacktrace_ops *ops, void *data,
19279- unsigned long *end, int *graph);
19280-
19281-extern unsigned long
19282-print_context_stack_bp(struct thread_info *tinfo,
19283- unsigned long *stack, unsigned long bp,
19284- const struct stacktrace_ops *ops, void *data,
19285- unsigned long *end, int *graph);
19286+extern walk_stack_t print_context_stack;
19287+extern walk_stack_t print_context_stack_bp;
19288
19289 /* Generic stack tracer with callbacks */
19290
19291@@ -40,7 +32,7 @@ struct stacktrace_ops {
19292 void (*address)(void *data, unsigned long address, int reliable);
19293 /* On negative return stop dumping */
19294 int (*stack)(void *data, char *name);
19295- walk_stack_t walk_stack;
19296+ walk_stack_t *walk_stack;
19297 };
19298
19299 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
19300diff --git a/arch/x86/include/asm/switch_to.h b/arch/x86/include/asm/switch_to.h
19301index d7f3b3b..3cc39f1 100644
19302--- a/arch/x86/include/asm/switch_to.h
19303+++ b/arch/x86/include/asm/switch_to.h
19304@@ -108,7 +108,7 @@ do { \
19305 "call __switch_to\n\t" \
19306 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
19307 __switch_canary \
19308- "movq %P[thread_info](%%rsi),%%r8\n\t" \
19309+ "movq "__percpu_arg([thread_info])",%%r8\n\t" \
19310 "movq %%rax,%%rdi\n\t" \
19311 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
19312 "jnz ret_from_fork\n\t" \
19313@@ -119,7 +119,7 @@ do { \
19314 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
19315 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
19316 [_tif_fork] "i" (_TIF_FORK), \
19317- [thread_info] "i" (offsetof(struct task_struct, stack)), \
19318+ [thread_info] "m" (current_tinfo), \
19319 [current_task] "m" (current_task) \
19320 __switch_canary_iparam \
19321 : "memory", "cc" __EXTRA_CLOBBER)
19322diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
19323index 547e344..6be1175 100644
19324--- a/arch/x86/include/asm/thread_info.h
19325+++ b/arch/x86/include/asm/thread_info.h
19326@@ -24,7 +24,6 @@ struct exec_domain;
19327 #include <linux/atomic.h>
19328
19329 struct thread_info {
19330- struct task_struct *task; /* main task structure */
19331 struct exec_domain *exec_domain; /* execution domain */
19332 __u32 flags; /* low level flags */
19333 __u32 status; /* thread synchronous flags */
19334@@ -33,13 +32,13 @@ struct thread_info {
19335 mm_segment_t addr_limit;
19336 struct restart_block restart_block;
19337 void __user *sysenter_return;
19338+ unsigned long lowest_stack;
19339 unsigned int sig_on_uaccess_error:1;
19340 unsigned int uaccess_err:1; /* uaccess failed */
19341 };
19342
19343-#define INIT_THREAD_INFO(tsk) \
19344+#define INIT_THREAD_INFO \
19345 { \
19346- .task = &tsk, \
19347 .exec_domain = &default_exec_domain, \
19348 .flags = 0, \
19349 .cpu = 0, \
19350@@ -50,7 +49,7 @@ struct thread_info {
19351 }, \
19352 }
19353
19354-#define init_thread_info (init_thread_union.thread_info)
19355+#define init_thread_info (init_thread_union.stack)
19356 #define init_stack (init_thread_union.stack)
19357
19358 #else /* !__ASSEMBLY__ */
19359@@ -91,6 +90,7 @@ struct thread_info {
19360 #define TIF_SYSCALL_TRACEPOINT 28 /* syscall tracepoint instrumentation */
19361 #define TIF_ADDR32 29 /* 32-bit address space on 64 bits */
19362 #define TIF_X32 30 /* 32-bit native x86-64 binary */
19363+#define TIF_GRSEC_SETXID 31 /* update credentials on syscall entry/exit */
19364
19365 #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
19366 #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
19367@@ -115,17 +115,18 @@ struct thread_info {
19368 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
19369 #define _TIF_ADDR32 (1 << TIF_ADDR32)
19370 #define _TIF_X32 (1 << TIF_X32)
19371+#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
19372
19373 /* work to do in syscall_trace_enter() */
19374 #define _TIF_WORK_SYSCALL_ENTRY \
19375 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_EMU | _TIF_SYSCALL_AUDIT | \
19376 _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT | \
19377- _TIF_NOHZ)
19378+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
19379
19380 /* work to do in syscall_trace_leave() */
19381 #define _TIF_WORK_SYSCALL_EXIT \
19382 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SINGLESTEP | \
19383- _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ)
19384+ _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ | _TIF_GRSEC_SETXID)
19385
19386 /* work to do on interrupt/exception return */
19387 #define _TIF_WORK_MASK \
19388@@ -136,7 +137,7 @@ struct thread_info {
19389 /* work to do on any return to user space */
19390 #define _TIF_ALLWORK_MASK \
19391 ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT | \
19392- _TIF_NOHZ)
19393+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
19394
19395 /* Only used for 64 bit */
19396 #define _TIF_DO_NOTIFY_MASK \
19397@@ -151,7 +152,6 @@ struct thread_info {
19398 #define _TIF_WORK_CTXSW_NEXT (_TIF_WORK_CTXSW)
19399
19400 #define STACK_WARN (THREAD_SIZE/8)
19401-#define KERNEL_STACK_OFFSET (5*(BITS_PER_LONG/8))
19402
19403 /*
19404 * macros/functions for gaining access to the thread information structure
19405@@ -162,26 +162,18 @@ struct thread_info {
19406
19407 DECLARE_PER_CPU(unsigned long, kernel_stack);
19408
19409+DECLARE_PER_CPU(struct thread_info *, current_tinfo);
19410+
19411 static inline struct thread_info *current_thread_info(void)
19412 {
19413- struct thread_info *ti;
19414- ti = (void *)(this_cpu_read_stable(kernel_stack) +
19415- KERNEL_STACK_OFFSET - THREAD_SIZE);
19416- return ti;
19417+ return this_cpu_read_stable(current_tinfo);
19418 }
19419
19420 #else /* !__ASSEMBLY__ */
19421
19422 /* how to get the thread information struct from ASM */
19423 #define GET_THREAD_INFO(reg) \
19424- _ASM_MOV PER_CPU_VAR(kernel_stack),reg ; \
19425- _ASM_SUB $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg ;
19426-
19427-/*
19428- * Same if PER_CPU_VAR(kernel_stack) is, perhaps with some offset, already in
19429- * a certain register (to be used in assembler memory operands).
19430- */
19431-#define THREAD_INFO(reg, off) KERNEL_STACK_OFFSET+(off)-THREAD_SIZE(reg)
19432+ _ASM_MOV PER_CPU_VAR(current_tinfo),reg ;
19433
19434 #endif
19435
19436@@ -237,5 +229,12 @@ static inline bool is_ia32_task(void)
19437 extern void arch_task_cache_init(void);
19438 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
19439 extern void arch_release_task_struct(struct task_struct *tsk);
19440+
19441+#define __HAVE_THREAD_FUNCTIONS
19442+#define task_thread_info(task) (&(task)->tinfo)
19443+#define task_stack_page(task) ((task)->stack)
19444+#define setup_thread_stack(p, org) do {} while (0)
19445+#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
19446+
19447 #endif
19448 #endif /* _ASM_X86_THREAD_INFO_H */
19449diff --git a/arch/x86/include/asm/tlbflush.h b/arch/x86/include/asm/tlbflush.h
19450index 04905bf..1178cdf 100644
19451--- a/arch/x86/include/asm/tlbflush.h
19452+++ b/arch/x86/include/asm/tlbflush.h
19453@@ -17,18 +17,44 @@
19454
19455 static inline void __native_flush_tlb(void)
19456 {
19457+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
19458+ u64 descriptor[2];
19459+
19460+ descriptor[0] = PCID_KERNEL;
19461+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_ALL_NONGLOBAL) : "memory");
19462+ return;
19463+ }
19464+
19465+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19466+ if (static_cpu_has(X86_FEATURE_PCID)) {
19467+ unsigned int cpu = raw_get_cpu();
19468+
19469+ native_write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
19470+ native_write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
19471+ raw_put_cpu_no_resched();
19472+ return;
19473+ }
19474+#endif
19475+
19476 native_write_cr3(native_read_cr3());
19477 }
19478
19479 static inline void __native_flush_tlb_global_irq_disabled(void)
19480 {
19481- unsigned long cr4;
19482+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
19483+ u64 descriptor[2];
19484
19485- cr4 = native_read_cr4();
19486- /* clear PGE */
19487- native_write_cr4(cr4 & ~X86_CR4_PGE);
19488- /* write old PGE again and flush TLBs */
19489- native_write_cr4(cr4);
19490+ descriptor[0] = PCID_KERNEL;
19491+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_ALL_GLOBAL) : "memory");
19492+ } else {
19493+ unsigned long cr4;
19494+
19495+ cr4 = native_read_cr4();
19496+ /* clear PGE */
19497+ native_write_cr4(cr4 & ~X86_CR4_PGE);
19498+ /* write old PGE again and flush TLBs */
19499+ native_write_cr4(cr4);
19500+ }
19501 }
19502
19503 static inline void __native_flush_tlb_global(void)
19504@@ -49,6 +75,41 @@ static inline void __native_flush_tlb_global(void)
19505
19506 static inline void __native_flush_tlb_single(unsigned long addr)
19507 {
19508+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
19509+ u64 descriptor[2];
19510+
19511+ descriptor[0] = PCID_KERNEL;
19512+ descriptor[1] = addr;
19513+
19514+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19515+ if (!static_cpu_has(X86_FEATURE_STRONGUDEREF) || addr >= TASK_SIZE_MAX) {
19516+ if (addr < TASK_SIZE_MAX)
19517+ descriptor[1] += pax_user_shadow_base;
19518+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_ADDRESS) : "memory");
19519+ }
19520+
19521+ descriptor[0] = PCID_USER;
19522+ descriptor[1] = addr;
19523+#endif
19524+
19525+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_ADDRESS) : "memory");
19526+ return;
19527+ }
19528+
19529+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19530+ if (static_cpu_has(X86_FEATURE_PCID)) {
19531+ unsigned int cpu = raw_get_cpu();
19532+
19533+ native_write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER | PCID_NOFLUSH);
19534+ asm volatile("invlpg (%0)" ::"r" (addr) : "memory");
19535+ native_write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
19536+ raw_put_cpu_no_resched();
19537+
19538+ if (!static_cpu_has(X86_FEATURE_STRONGUDEREF) && addr < TASK_SIZE_MAX)
19539+ addr += pax_user_shadow_base;
19540+ }
19541+#endif
19542+
19543 asm volatile("invlpg (%0)" ::"r" (addr) : "memory");
19544 }
19545
19546diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
19547index 0d592e0..526f797 100644
19548--- a/arch/x86/include/asm/uaccess.h
19549+++ b/arch/x86/include/asm/uaccess.h
19550@@ -7,6 +7,7 @@
19551 #include <linux/compiler.h>
19552 #include <linux/thread_info.h>
19553 #include <linux/string.h>
19554+#include <linux/spinlock.h>
19555 #include <asm/asm.h>
19556 #include <asm/page.h>
19557 #include <asm/smap.h>
19558@@ -29,7 +30,12 @@
19559
19560 #define get_ds() (KERNEL_DS)
19561 #define get_fs() (current_thread_info()->addr_limit)
19562+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
19563+void __set_fs(mm_segment_t x);
19564+void set_fs(mm_segment_t x);
19565+#else
19566 #define set_fs(x) (current_thread_info()->addr_limit = (x))
19567+#endif
19568
19569 #define segment_eq(a, b) ((a).seg == (b).seg)
19570
19571@@ -85,8 +91,36 @@ static inline bool __chk_range_not_ok(unsigned long addr, unsigned long size, un
19572 * checks that the pointer is in the user space range - after calling
19573 * this function, memory access functions may still return -EFAULT.
19574 */
19575-#define access_ok(type, addr, size) \
19576- likely(!__range_not_ok(addr, size, user_addr_max()))
19577+extern int _cond_resched(void);
19578+#define access_ok_noprefault(type, addr, size) (likely(!__range_not_ok(addr, size, user_addr_max())))
19579+#define access_ok(type, addr, size) \
19580+({ \
19581+ unsigned long __size = size; \
19582+ unsigned long __addr = (unsigned long)addr; \
19583+ bool __ret_ao = __range_not_ok(__addr, __size, user_addr_max()) == 0;\
19584+ if (__ret_ao && __size) { \
19585+ unsigned long __addr_ao = __addr & PAGE_MASK; \
19586+ unsigned long __end_ao = __addr + __size - 1; \
19587+ if (unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
19588+ while (__addr_ao <= __end_ao) { \
19589+ char __c_ao; \
19590+ __addr_ao += PAGE_SIZE; \
19591+ if (__size > PAGE_SIZE) \
19592+ _cond_resched(); \
19593+ if (__get_user(__c_ao, (char __user *)__addr)) \
19594+ break; \
19595+ if (type != VERIFY_WRITE) { \
19596+ __addr = __addr_ao; \
19597+ continue; \
19598+ } \
19599+ if (__put_user(__c_ao, (char __user *)__addr)) \
19600+ break; \
19601+ __addr = __addr_ao; \
19602+ } \
19603+ } \
19604+ } \
19605+ __ret_ao; \
19606+})
19607
19608 /*
19609 * The exception table consists of pairs of addresses relative to the
19610@@ -176,10 +210,12 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
19611 register __inttype(*(ptr)) __val_gu asm("%"_ASM_DX); \
19612 __chk_user_ptr(ptr); \
19613 might_fault(); \
19614+ pax_open_userland(); \
19615 asm volatile("call __get_user_%P3" \
19616 : "=a" (__ret_gu), "=r" (__val_gu) \
19617 : "0" (ptr), "i" (sizeof(*(ptr)))); \
19618 (x) = (__typeof__(*(ptr))) __val_gu; \
19619+ pax_close_userland(); \
19620 __ret_gu; \
19621 })
19622
19623@@ -187,13 +223,21 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
19624 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
19625 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
19626
19627-
19628+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
19629+#define __copyuser_seg "gs;"
19630+#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
19631+#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
19632+#else
19633+#define __copyuser_seg
19634+#define __COPYUSER_SET_ES
19635+#define __COPYUSER_RESTORE_ES
19636+#endif
19637
19638 #ifdef CONFIG_X86_32
19639 #define __put_user_asm_u64(x, addr, err, errret) \
19640 asm volatile(ASM_STAC "\n" \
19641- "1: movl %%eax,0(%2)\n" \
19642- "2: movl %%edx,4(%2)\n" \
19643+ "1: "__copyuser_seg"movl %%eax,0(%2)\n" \
19644+ "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
19645 "3: " ASM_CLAC "\n" \
19646 ".section .fixup,\"ax\"\n" \
19647 "4: movl %3,%0\n" \
19648@@ -206,8 +250,8 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
19649
19650 #define __put_user_asm_ex_u64(x, addr) \
19651 asm volatile(ASM_STAC "\n" \
19652- "1: movl %%eax,0(%1)\n" \
19653- "2: movl %%edx,4(%1)\n" \
19654+ "1: "__copyuser_seg"movl %%eax,0(%1)\n" \
19655+ "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
19656 "3: " ASM_CLAC "\n" \
19657 _ASM_EXTABLE_EX(1b, 2b) \
19658 _ASM_EXTABLE_EX(2b, 3b) \
19659@@ -257,7 +301,8 @@ extern void __put_user_8(void);
19660 __typeof__(*(ptr)) __pu_val; \
19661 __chk_user_ptr(ptr); \
19662 might_fault(); \
19663- __pu_val = x; \
19664+ __pu_val = (x); \
19665+ pax_open_userland(); \
19666 switch (sizeof(*(ptr))) { \
19667 case 1: \
19668 __put_user_x(1, __pu_val, ptr, __ret_pu); \
19669@@ -275,6 +320,7 @@ extern void __put_user_8(void);
19670 __put_user_x(X, __pu_val, ptr, __ret_pu); \
19671 break; \
19672 } \
19673+ pax_close_userland(); \
19674 __ret_pu; \
19675 })
19676
19677@@ -355,8 +401,10 @@ do { \
19678 } while (0)
19679
19680 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
19681+do { \
19682+ pax_open_userland(); \
19683 asm volatile(ASM_STAC "\n" \
19684- "1: mov"itype" %2,%"rtype"1\n" \
19685+ "1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
19686 "2: " ASM_CLAC "\n" \
19687 ".section .fixup,\"ax\"\n" \
19688 "3: mov %3,%0\n" \
19689@@ -364,8 +412,10 @@ do { \
19690 " jmp 2b\n" \
19691 ".previous\n" \
19692 _ASM_EXTABLE(1b, 3b) \
19693- : "=r" (err), ltype(x) \
19694- : "m" (__m(addr)), "i" (errret), "0" (err))
19695+ : "=r" (err), ltype (x) \
19696+ : "m" (__m(addr)), "i" (errret), "0" (err)); \
19697+ pax_close_userland(); \
19698+} while (0)
19699
19700 #define __get_user_size_ex(x, ptr, size) \
19701 do { \
19702@@ -389,7 +439,7 @@ do { \
19703 } while (0)
19704
19705 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
19706- asm volatile("1: mov"itype" %1,%"rtype"0\n" \
19707+ asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
19708 "2:\n" \
19709 _ASM_EXTABLE_EX(1b, 2b) \
19710 : ltype(x) : "m" (__m(addr)))
19711@@ -406,13 +456,24 @@ do { \
19712 int __gu_err; \
19713 unsigned long __gu_val; \
19714 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
19715- (x) = (__force __typeof__(*(ptr)))__gu_val; \
19716+ (x) = (__typeof__(*(ptr)))__gu_val; \
19717 __gu_err; \
19718 })
19719
19720 /* FIXME: this hack is definitely wrong -AK */
19721 struct __large_struct { unsigned long buf[100]; };
19722-#define __m(x) (*(struct __large_struct __user *)(x))
19723+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19724+#define ____m(x) \
19725+({ \
19726+ unsigned long ____x = (unsigned long)(x); \
19727+ if (____x < pax_user_shadow_base) \
19728+ ____x += pax_user_shadow_base; \
19729+ (typeof(x))____x; \
19730+})
19731+#else
19732+#define ____m(x) (x)
19733+#endif
19734+#define __m(x) (*(struct __large_struct __user *)____m(x))
19735
19736 /*
19737 * Tell gcc we read from memory instead of writing: this is because
19738@@ -420,8 +481,10 @@ struct __large_struct { unsigned long buf[100]; };
19739 * aliasing issues.
19740 */
19741 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
19742+do { \
19743+ pax_open_userland(); \
19744 asm volatile(ASM_STAC "\n" \
19745- "1: mov"itype" %"rtype"1,%2\n" \
19746+ "1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
19747 "2: " ASM_CLAC "\n" \
19748 ".section .fixup,\"ax\"\n" \
19749 "3: mov %3,%0\n" \
19750@@ -429,10 +492,12 @@ struct __large_struct { unsigned long buf[100]; };
19751 ".previous\n" \
19752 _ASM_EXTABLE(1b, 3b) \
19753 : "=r"(err) \
19754- : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
19755+ : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err));\
19756+ pax_close_userland(); \
19757+} while (0)
19758
19759 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
19760- asm volatile("1: mov"itype" %"rtype"0,%1\n" \
19761+ asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
19762 "2:\n" \
19763 _ASM_EXTABLE_EX(1b, 2b) \
19764 : : ltype(x), "m" (__m(addr)))
19765@@ -442,11 +507,13 @@ struct __large_struct { unsigned long buf[100]; };
19766 */
19767 #define uaccess_try do { \
19768 current_thread_info()->uaccess_err = 0; \
19769+ pax_open_userland(); \
19770 stac(); \
19771 barrier();
19772
19773 #define uaccess_catch(err) \
19774 clac(); \
19775+ pax_close_userland(); \
19776 (err) |= (current_thread_info()->uaccess_err ? -EFAULT : 0); \
19777 } while (0)
19778
19779@@ -471,8 +538,12 @@ struct __large_struct { unsigned long buf[100]; };
19780 * On error, the variable @x is set to zero.
19781 */
19782
19783+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19784+#define __get_user(x, ptr) get_user((x), (ptr))
19785+#else
19786 #define __get_user(x, ptr) \
19787 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
19788+#endif
19789
19790 /**
19791 * __put_user: - Write a simple value into user space, with less checking.
19792@@ -494,8 +565,12 @@ struct __large_struct { unsigned long buf[100]; };
19793 * Returns zero on success, or -EFAULT on error.
19794 */
19795
19796+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19797+#define __put_user(x, ptr) put_user((x), (ptr))
19798+#else
19799 #define __put_user(x, ptr) \
19800 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
19801+#endif
19802
19803 #define __get_user_unaligned __get_user
19804 #define __put_user_unaligned __put_user
19805@@ -513,7 +588,7 @@ struct __large_struct { unsigned long buf[100]; };
19806 #define get_user_ex(x, ptr) do { \
19807 unsigned long __gue_val; \
19808 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
19809- (x) = (__force __typeof__(*(ptr)))__gue_val; \
19810+ (x) = (__typeof__(*(ptr)))__gue_val; \
19811 } while (0)
19812
19813 #define put_user_try uaccess_try
19814@@ -542,18 +617,19 @@ extern void __cmpxchg_wrong_size(void)
19815 __typeof__(ptr) __uval = (uval); \
19816 __typeof__(*(ptr)) __old = (old); \
19817 __typeof__(*(ptr)) __new = (new); \
19818+ pax_open_userland(); \
19819 switch (size) { \
19820 case 1: \
19821 { \
19822 asm volatile("\t" ASM_STAC "\n" \
19823- "1:\t" LOCK_PREFIX "cmpxchgb %4, %2\n" \
19824+ "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgb %4, %2\n"\
19825 "2:\t" ASM_CLAC "\n" \
19826 "\t.section .fixup, \"ax\"\n" \
19827 "3:\tmov %3, %0\n" \
19828 "\tjmp 2b\n" \
19829 "\t.previous\n" \
19830 _ASM_EXTABLE(1b, 3b) \
19831- : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
19832+ : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
19833 : "i" (-EFAULT), "q" (__new), "1" (__old) \
19834 : "memory" \
19835 ); \
19836@@ -562,14 +638,14 @@ extern void __cmpxchg_wrong_size(void)
19837 case 2: \
19838 { \
19839 asm volatile("\t" ASM_STAC "\n" \
19840- "1:\t" LOCK_PREFIX "cmpxchgw %4, %2\n" \
19841+ "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgw %4, %2\n"\
19842 "2:\t" ASM_CLAC "\n" \
19843 "\t.section .fixup, \"ax\"\n" \
19844 "3:\tmov %3, %0\n" \
19845 "\tjmp 2b\n" \
19846 "\t.previous\n" \
19847 _ASM_EXTABLE(1b, 3b) \
19848- : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
19849+ : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
19850 : "i" (-EFAULT), "r" (__new), "1" (__old) \
19851 : "memory" \
19852 ); \
19853@@ -578,14 +654,14 @@ extern void __cmpxchg_wrong_size(void)
19854 case 4: \
19855 { \
19856 asm volatile("\t" ASM_STAC "\n" \
19857- "1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n" \
19858+ "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %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), "r" (__new), "1" (__old) \
19868 : "memory" \
19869 ); \
19870@@ -597,14 +673,14 @@ extern void __cmpxchg_wrong_size(void)
19871 __cmpxchg_wrong_size(); \
19872 \
19873 asm volatile("\t" ASM_STAC "\n" \
19874- "1:\t" LOCK_PREFIX "cmpxchgq %4, %2\n" \
19875+ "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgq %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@@ -613,6 +689,7 @@ extern void __cmpxchg_wrong_size(void)
19888 default: \
19889 __cmpxchg_wrong_size(); \
19890 } \
19891+ pax_close_userland(); \
19892 *__uval = __old; \
19893 __ret; \
19894 })
19895@@ -636,17 +713,6 @@ extern struct movsl_mask {
19896
19897 #define ARCH_HAS_NOCACHE_UACCESS 1
19898
19899-#ifdef CONFIG_X86_32
19900-# include <asm/uaccess_32.h>
19901-#else
19902-# include <asm/uaccess_64.h>
19903-#endif
19904-
19905-unsigned long __must_check _copy_from_user(void *to, const void __user *from,
19906- unsigned n);
19907-unsigned long __must_check _copy_to_user(void __user *to, const void *from,
19908- unsigned n);
19909-
19910 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
19911 # define copy_user_diag __compiletime_error
19912 #else
19913@@ -656,7 +722,7 @@ unsigned long __must_check _copy_to_user(void __user *to, const void *from,
19914 extern void copy_user_diag("copy_from_user() buffer size is too small")
19915 copy_from_user_overflow(void);
19916 extern void copy_user_diag("copy_to_user() buffer size is too small")
19917-copy_to_user_overflow(void) __asm__("copy_from_user_overflow");
19918+copy_to_user_overflow(void);
19919
19920 #undef copy_user_diag
19921
19922@@ -669,7 +735,7 @@ __copy_from_user_overflow(void) __asm__("copy_from_user_overflow");
19923
19924 extern void
19925 __compiletime_warning("copy_to_user() buffer size is not provably correct")
19926-__copy_to_user_overflow(void) __asm__("copy_from_user_overflow");
19927+__copy_to_user_overflow(void) __asm__("copy_to_user_overflow");
19928 #define __copy_to_user_overflow(size, count) __copy_to_user_overflow()
19929
19930 #else
19931@@ -684,10 +750,16 @@ __copy_from_user_overflow(int size, unsigned long count)
19932
19933 #endif
19934
19935+#ifdef CONFIG_X86_32
19936+# include <asm/uaccess_32.h>
19937+#else
19938+# include <asm/uaccess_64.h>
19939+#endif
19940+
19941 static inline unsigned long __must_check
19942 copy_from_user(void *to, const void __user *from, unsigned long n)
19943 {
19944- int sz = __compiletime_object_size(to);
19945+ size_t sz = __compiletime_object_size(to);
19946
19947 might_fault();
19948
19949@@ -709,12 +781,15 @@ copy_from_user(void *to, const void __user *from, unsigned long n)
19950 * case, and do only runtime checking for non-constant sizes.
19951 */
19952
19953- if (likely(sz < 0 || sz >= n))
19954- n = _copy_from_user(to, from, n);
19955- else if(__builtin_constant_p(n))
19956- copy_from_user_overflow();
19957- else
19958- __copy_from_user_overflow(sz, n);
19959+ if (likely(sz != (size_t)-1 && sz < n)) {
19960+ if(__builtin_constant_p(n))
19961+ copy_from_user_overflow();
19962+ else
19963+ __copy_from_user_overflow(sz, n);
19964+ } else if (access_ok(VERIFY_READ, from, n))
19965+ n = __copy_from_user(to, from, n);
19966+ else if ((long)n > 0)
19967+ memset(to, 0, n);
19968
19969 return n;
19970 }
19971@@ -722,17 +797,18 @@ copy_from_user(void *to, const void __user *from, unsigned long n)
19972 static inline unsigned long __must_check
19973 copy_to_user(void __user *to, const void *from, unsigned long n)
19974 {
19975- int sz = __compiletime_object_size(from);
19976+ size_t sz = __compiletime_object_size(from);
19977
19978 might_fault();
19979
19980 /* See the comment in copy_from_user() above. */
19981- if (likely(sz < 0 || sz >= n))
19982- n = _copy_to_user(to, from, n);
19983- else if(__builtin_constant_p(n))
19984- copy_to_user_overflow();
19985- else
19986- __copy_to_user_overflow(sz, n);
19987+ if (likely(sz != (size_t)-1 && sz < n)) {
19988+ if(__builtin_constant_p(n))
19989+ copy_to_user_overflow();
19990+ else
19991+ __copy_to_user_overflow(sz, n);
19992+ } else if (access_ok(VERIFY_WRITE, to, n))
19993+ n = __copy_to_user(to, from, n);
19994
19995 return n;
19996 }
19997diff --git a/arch/x86/include/asm/uaccess_32.h b/arch/x86/include/asm/uaccess_32.h
19998index 3c03a5d..1071638 100644
19999--- a/arch/x86/include/asm/uaccess_32.h
20000+++ b/arch/x86/include/asm/uaccess_32.h
20001@@ -43,6 +43,11 @@ unsigned long __must_check __copy_from_user_ll_nocache_nozero
20002 static __always_inline unsigned long __must_check
20003 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
20004 {
20005+ if ((long)n < 0)
20006+ return n;
20007+
20008+ check_object_size(from, n, true);
20009+
20010 if (__builtin_constant_p(n)) {
20011 unsigned long ret;
20012
20013@@ -82,12 +87,16 @@ static __always_inline unsigned long __must_check
20014 __copy_to_user(void __user *to, const void *from, unsigned long n)
20015 {
20016 might_fault();
20017+
20018 return __copy_to_user_inatomic(to, from, n);
20019 }
20020
20021 static __always_inline unsigned long
20022 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
20023 {
20024+ if ((long)n < 0)
20025+ return n;
20026+
20027 /* Avoid zeroing the tail if the copy fails..
20028 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
20029 * but as the zeroing behaviour is only significant when n is not
20030@@ -137,6 +146,12 @@ static __always_inline unsigned long
20031 __copy_from_user(void *to, const void __user *from, unsigned long n)
20032 {
20033 might_fault();
20034+
20035+ if ((long)n < 0)
20036+ return n;
20037+
20038+ check_object_size(to, n, false);
20039+
20040 if (__builtin_constant_p(n)) {
20041 unsigned long ret;
20042
20043@@ -159,6 +174,10 @@ static __always_inline unsigned long __copy_from_user_nocache(void *to,
20044 const void __user *from, unsigned long n)
20045 {
20046 might_fault();
20047+
20048+ if ((long)n < 0)
20049+ return n;
20050+
20051 if (__builtin_constant_p(n)) {
20052 unsigned long ret;
20053
20054@@ -181,7 +200,10 @@ static __always_inline unsigned long
20055 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
20056 unsigned long n)
20057 {
20058- return __copy_from_user_ll_nocache_nozero(to, from, n);
20059+ if ((long)n < 0)
20060+ return n;
20061+
20062+ return __copy_from_user_ll_nocache_nozero(to, from, n);
20063 }
20064
20065 #endif /* _ASM_X86_UACCESS_32_H */
20066diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
20067index 12a26b9..206c200 100644
20068--- a/arch/x86/include/asm/uaccess_64.h
20069+++ b/arch/x86/include/asm/uaccess_64.h
20070@@ -10,6 +10,9 @@
20071 #include <asm/alternative.h>
20072 #include <asm/cpufeature.h>
20073 #include <asm/page.h>
20074+#include <asm/pgtable.h>
20075+
20076+#define set_fs(x) (current_thread_info()->addr_limit = (x))
20077
20078 /*
20079 * Copy To/From Userspace
20080@@ -17,14 +20,14 @@
20081
20082 /* Handles exceptions in both to and from, but doesn't do access_ok */
20083 __must_check unsigned long
20084-copy_user_enhanced_fast_string(void *to, const void *from, unsigned len);
20085+copy_user_enhanced_fast_string(void *to, const void *from, unsigned len) __size_overflow(3);
20086 __must_check unsigned long
20087-copy_user_generic_string(void *to, const void *from, unsigned len);
20088+copy_user_generic_string(void *to, const void *from, unsigned len) __size_overflow(3);
20089 __must_check unsigned long
20090-copy_user_generic_unrolled(void *to, const void *from, unsigned len);
20091+copy_user_generic_unrolled(void *to, const void *from, unsigned len) __size_overflow(3);
20092
20093 static __always_inline __must_check unsigned long
20094-copy_user_generic(void *to, const void *from, unsigned len)
20095+copy_user_generic(void *to, const void *from, unsigned long len)
20096 {
20097 unsigned ret;
20098
20099@@ -46,121 +49,170 @@ copy_user_generic(void *to, const void *from, unsigned len)
20100 }
20101
20102 __must_check unsigned long
20103-copy_in_user(void __user *to, const void __user *from, unsigned len);
20104+copy_in_user(void __user *to, const void __user *from, unsigned long len);
20105
20106 static __always_inline __must_check
20107-int __copy_from_user_nocheck(void *dst, const void __user *src, unsigned size)
20108+unsigned long __copy_from_user_nocheck(void *dst, const void __user *src, unsigned long size)
20109 {
20110- int ret = 0;
20111+ size_t sz = __compiletime_object_size(dst);
20112+ unsigned ret = 0;
20113+
20114+ if (size > INT_MAX)
20115+ return size;
20116+
20117+ check_object_size(dst, size, false);
20118+
20119+#ifdef CONFIG_PAX_MEMORY_UDEREF
20120+ if (!access_ok_noprefault(VERIFY_READ, src, size))
20121+ return size;
20122+#endif
20123+
20124+ if (unlikely(sz != (size_t)-1 && sz < size)) {
20125+ if(__builtin_constant_p(size))
20126+ copy_from_user_overflow();
20127+ else
20128+ __copy_from_user_overflow(sz, size);
20129+ return size;
20130+ }
20131
20132 if (!__builtin_constant_p(size))
20133- return copy_user_generic(dst, (__force void *)src, size);
20134+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
20135 switch (size) {
20136- case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
20137+ case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
20138 ret, "b", "b", "=q", 1);
20139 return ret;
20140- case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
20141+ case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
20142 ret, "w", "w", "=r", 2);
20143 return ret;
20144- case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
20145+ case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
20146 ret, "l", "k", "=r", 4);
20147 return ret;
20148- case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
20149+ case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
20150 ret, "q", "", "=r", 8);
20151 return ret;
20152 case 10:
20153- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
20154+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
20155 ret, "q", "", "=r", 10);
20156 if (unlikely(ret))
20157 return ret;
20158 __get_user_asm(*(u16 *)(8 + (char *)dst),
20159- (u16 __user *)(8 + (char __user *)src),
20160+ (const u16 __user *)(8 + (const char __user *)src),
20161 ret, "w", "w", "=r", 2);
20162 return ret;
20163 case 16:
20164- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
20165+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
20166 ret, "q", "", "=r", 16);
20167 if (unlikely(ret))
20168 return ret;
20169 __get_user_asm(*(u64 *)(8 + (char *)dst),
20170- (u64 __user *)(8 + (char __user *)src),
20171+ (const u64 __user *)(8 + (const char __user *)src),
20172 ret, "q", "", "=r", 8);
20173 return ret;
20174 default:
20175- return copy_user_generic(dst, (__force void *)src, size);
20176+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
20177 }
20178 }
20179
20180 static __always_inline __must_check
20181-int __copy_from_user(void *dst, const void __user *src, unsigned size)
20182+unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size)
20183 {
20184 might_fault();
20185 return __copy_from_user_nocheck(dst, src, size);
20186 }
20187
20188 static __always_inline __must_check
20189-int __copy_to_user_nocheck(void __user *dst, const void *src, unsigned size)
20190+unsigned long __copy_to_user_nocheck(void __user *dst, const void *src, unsigned long size)
20191 {
20192- int ret = 0;
20193+ size_t sz = __compiletime_object_size(src);
20194+ unsigned ret = 0;
20195+
20196+ if (size > INT_MAX)
20197+ return size;
20198+
20199+ check_object_size(src, size, true);
20200+
20201+#ifdef CONFIG_PAX_MEMORY_UDEREF
20202+ if (!access_ok_noprefault(VERIFY_WRITE, dst, size))
20203+ return size;
20204+#endif
20205+
20206+ if (unlikely(sz != (size_t)-1 && sz < size)) {
20207+ if(__builtin_constant_p(size))
20208+ copy_to_user_overflow();
20209+ else
20210+ __copy_to_user_overflow(sz, size);
20211+ return size;
20212+ }
20213
20214 if (!__builtin_constant_p(size))
20215- return copy_user_generic((__force void *)dst, src, size);
20216+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
20217 switch (size) {
20218- case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
20219+ case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
20220 ret, "b", "b", "iq", 1);
20221 return ret;
20222- case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
20223+ case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
20224 ret, "w", "w", "ir", 2);
20225 return ret;
20226- case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
20227+ case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
20228 ret, "l", "k", "ir", 4);
20229 return ret;
20230- case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
20231+ case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
20232 ret, "q", "", "er", 8);
20233 return ret;
20234 case 10:
20235- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
20236+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
20237 ret, "q", "", "er", 10);
20238 if (unlikely(ret))
20239 return ret;
20240 asm("":::"memory");
20241- __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
20242+ __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
20243 ret, "w", "w", "ir", 2);
20244 return ret;
20245 case 16:
20246- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
20247+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
20248 ret, "q", "", "er", 16);
20249 if (unlikely(ret))
20250 return ret;
20251 asm("":::"memory");
20252- __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
20253+ __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
20254 ret, "q", "", "er", 8);
20255 return ret;
20256 default:
20257- return copy_user_generic((__force void *)dst, src, size);
20258+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
20259 }
20260 }
20261
20262 static __always_inline __must_check
20263-int __copy_to_user(void __user *dst, const void *src, unsigned size)
20264+unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size)
20265 {
20266 might_fault();
20267 return __copy_to_user_nocheck(dst, src, size);
20268 }
20269
20270 static __always_inline __must_check
20271-int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20272+unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20273 {
20274- int ret = 0;
20275+ unsigned ret = 0;
20276
20277 might_fault();
20278+
20279+ if (size > INT_MAX)
20280+ return size;
20281+
20282+#ifdef CONFIG_PAX_MEMORY_UDEREF
20283+ if (!access_ok_noprefault(VERIFY_READ, src, size))
20284+ return size;
20285+ if (!access_ok_noprefault(VERIFY_WRITE, dst, size))
20286+ return size;
20287+#endif
20288+
20289 if (!__builtin_constant_p(size))
20290- return copy_user_generic((__force void *)dst,
20291- (__force void *)src, size);
20292+ return copy_user_generic((__force_kernel void *)____m(dst),
20293+ (__force_kernel const void *)____m(src), size);
20294 switch (size) {
20295 case 1: {
20296 u8 tmp;
20297- __get_user_asm(tmp, (u8 __user *)src,
20298+ __get_user_asm(tmp, (const u8 __user *)src,
20299 ret, "b", "b", "=q", 1);
20300 if (likely(!ret))
20301 __put_user_asm(tmp, (u8 __user *)dst,
20302@@ -169,7 +221,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20303 }
20304 case 2: {
20305 u16 tmp;
20306- __get_user_asm(tmp, (u16 __user *)src,
20307+ __get_user_asm(tmp, (const u16 __user *)src,
20308 ret, "w", "w", "=r", 2);
20309 if (likely(!ret))
20310 __put_user_asm(tmp, (u16 __user *)dst,
20311@@ -179,7 +231,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20312
20313 case 4: {
20314 u32 tmp;
20315- __get_user_asm(tmp, (u32 __user *)src,
20316+ __get_user_asm(tmp, (const u32 __user *)src,
20317 ret, "l", "k", "=r", 4);
20318 if (likely(!ret))
20319 __put_user_asm(tmp, (u32 __user *)dst,
20320@@ -188,7 +240,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20321 }
20322 case 8: {
20323 u64 tmp;
20324- __get_user_asm(tmp, (u64 __user *)src,
20325+ __get_user_asm(tmp, (const u64 __user *)src,
20326 ret, "q", "", "=r", 8);
20327 if (likely(!ret))
20328 __put_user_asm(tmp, (u64 __user *)dst,
20329@@ -196,41 +248,58 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20330 return ret;
20331 }
20332 default:
20333- return copy_user_generic((__force void *)dst,
20334- (__force void *)src, size);
20335+ return copy_user_generic((__force_kernel void *)____m(dst),
20336+ (__force_kernel const void *)____m(src), size);
20337 }
20338 }
20339
20340-static __must_check __always_inline int
20341-__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
20342+static __must_check __always_inline unsigned long
20343+__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size)
20344 {
20345 return __copy_from_user_nocheck(dst, src, size);
20346 }
20347
20348-static __must_check __always_inline int
20349-__copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
20350+static __must_check __always_inline unsigned long
20351+__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size)
20352 {
20353 return __copy_to_user_nocheck(dst, src, size);
20354 }
20355
20356-extern long __copy_user_nocache(void *dst, const void __user *src,
20357- unsigned size, int zerorest);
20358+extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
20359+ unsigned long size, int zerorest);
20360
20361-static inline int
20362-__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
20363+static inline unsigned long
20364+__copy_from_user_nocache(void *dst, const void __user *src, unsigned long size)
20365 {
20366 might_fault();
20367+
20368+ if (size > INT_MAX)
20369+ return size;
20370+
20371+#ifdef CONFIG_PAX_MEMORY_UDEREF
20372+ if (!access_ok_noprefault(VERIFY_READ, src, size))
20373+ return size;
20374+#endif
20375+
20376 return __copy_user_nocache(dst, src, size, 1);
20377 }
20378
20379-static inline int
20380+static inline unsigned long
20381 __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
20382- unsigned size)
20383+ unsigned long size)
20384 {
20385+ if (size > INT_MAX)
20386+ return size;
20387+
20388+#ifdef CONFIG_PAX_MEMORY_UDEREF
20389+ if (!access_ok_noprefault(VERIFY_READ, src, size))
20390+ return size;
20391+#endif
20392+
20393 return __copy_user_nocache(dst, src, size, 0);
20394 }
20395
20396 unsigned long
20397-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
20398+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest) __size_overflow(3);
20399
20400 #endif /* _ASM_X86_UACCESS_64_H */
20401diff --git a/arch/x86/include/asm/word-at-a-time.h b/arch/x86/include/asm/word-at-a-time.h
20402index 5b238981..77fdd78 100644
20403--- a/arch/x86/include/asm/word-at-a-time.h
20404+++ b/arch/x86/include/asm/word-at-a-time.h
20405@@ -11,7 +11,7 @@
20406 * and shift, for example.
20407 */
20408 struct word_at_a_time {
20409- const unsigned long one_bits, high_bits;
20410+ unsigned long one_bits, high_bits;
20411 };
20412
20413 #define WORD_AT_A_TIME_CONSTANTS { REPEAT_BYTE(0x01), REPEAT_BYTE(0x80) }
20414diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h
20415index e45e4da..44e8572 100644
20416--- a/arch/x86/include/asm/x86_init.h
20417+++ b/arch/x86/include/asm/x86_init.h
20418@@ -129,7 +129,7 @@ struct x86_init_ops {
20419 struct x86_init_timers timers;
20420 struct x86_init_iommu iommu;
20421 struct x86_init_pci pci;
20422-};
20423+} __no_const;
20424
20425 /**
20426 * struct x86_cpuinit_ops - platform specific cpu hotplug setups
20427@@ -140,7 +140,7 @@ struct x86_cpuinit_ops {
20428 void (*setup_percpu_clockev)(void);
20429 void (*early_percpu_clock_init)(void);
20430 void (*fixup_cpu_id)(struct cpuinfo_x86 *c, int node);
20431-};
20432+} __no_const;
20433
20434 struct timespec;
20435
20436@@ -168,7 +168,7 @@ struct x86_platform_ops {
20437 void (*save_sched_clock_state)(void);
20438 void (*restore_sched_clock_state)(void);
20439 void (*apic_post_init)(void);
20440-};
20441+} __no_const;
20442
20443 struct pci_dev;
20444 struct msi_msg;
20445@@ -185,7 +185,7 @@ struct x86_msi_ops {
20446 int (*setup_hpet_msi)(unsigned int irq, unsigned int id);
20447 u32 (*msi_mask_irq)(struct msi_desc *desc, u32 mask, u32 flag);
20448 u32 (*msix_mask_irq)(struct msi_desc *desc, u32 flag);
20449-};
20450+} __no_const;
20451
20452 struct IO_APIC_route_entry;
20453 struct io_apic_irq_attr;
20454@@ -206,7 +206,7 @@ struct x86_io_apic_ops {
20455 unsigned int destination, int vector,
20456 struct io_apic_irq_attr *attr);
20457 void (*eoi_ioapic_pin)(int apic, int pin, int vector);
20458-};
20459+} __no_const;
20460
20461 extern struct x86_init_ops x86_init;
20462 extern struct x86_cpuinit_ops x86_cpuinit;
20463diff --git a/arch/x86/include/asm/xen/page.h b/arch/x86/include/asm/xen/page.h
20464index c949923..c22bfa4 100644
20465--- a/arch/x86/include/asm/xen/page.h
20466+++ b/arch/x86/include/asm/xen/page.h
20467@@ -63,7 +63,7 @@ extern int m2p_remove_override(struct page *page,
20468 extern struct page *m2p_find_override(unsigned long mfn);
20469 extern unsigned long m2p_find_override_pfn(unsigned long mfn, unsigned long pfn);
20470
20471-static inline unsigned long pfn_to_mfn(unsigned long pfn)
20472+static inline unsigned long __intentional_overflow(-1) pfn_to_mfn(unsigned long pfn)
20473 {
20474 unsigned long mfn;
20475
20476diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
20477index 7e7a79a..0824666 100644
20478--- a/arch/x86/include/asm/xsave.h
20479+++ b/arch/x86/include/asm/xsave.h
20480@@ -228,12 +228,16 @@ static inline int xsave_user(struct xsave_struct __user *buf)
20481 if (unlikely(err))
20482 return -EFAULT;
20483
20484+ pax_open_userland();
20485 __asm__ __volatile__(ASM_STAC "\n"
20486- "1:"XSAVE"\n"
20487+ "1:"
20488+ __copyuser_seg
20489+ XSAVE"\n"
20490 "2: " ASM_CLAC "\n"
20491 xstate_fault
20492 : "D" (buf), "a" (-1), "d" (-1), "0" (0)
20493 : "memory");
20494+ pax_close_userland();
20495 return err;
20496 }
20497
20498@@ -243,16 +247,20 @@ static inline int xsave_user(struct xsave_struct __user *buf)
20499 static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
20500 {
20501 int err = 0;
20502- struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
20503+ struct xsave_struct *xstate = ((__force_kernel struct xsave_struct *)buf);
20504 u32 lmask = mask;
20505 u32 hmask = mask >> 32;
20506
20507+ pax_open_userland();
20508 __asm__ __volatile__(ASM_STAC "\n"
20509- "1:"XRSTOR"\n"
20510+ "1:"
20511+ __copyuser_seg
20512+ XRSTOR"\n"
20513 "2: " ASM_CLAC "\n"
20514 xstate_fault
20515 : "D" (xstate), "a" (lmask), "d" (hmask), "0" (0)
20516 : "memory"); /* memory required? */
20517+ pax_close_userland();
20518 return err;
20519 }
20520
20521diff --git a/arch/x86/include/uapi/asm/e820.h b/arch/x86/include/uapi/asm/e820.h
20522index d993e33..8db1b18 100644
20523--- a/arch/x86/include/uapi/asm/e820.h
20524+++ b/arch/x86/include/uapi/asm/e820.h
20525@@ -58,7 +58,7 @@ struct e820map {
20526 #define ISA_START_ADDRESS 0xa0000
20527 #define ISA_END_ADDRESS 0x100000
20528
20529-#define BIOS_BEGIN 0x000a0000
20530+#define BIOS_BEGIN 0x000c0000
20531 #define BIOS_END 0x00100000
20532
20533 #define BIOS_ROM_BASE 0xffe00000
20534diff --git a/arch/x86/include/uapi/asm/ldt.h b/arch/x86/include/uapi/asm/ldt.h
20535index 46727eb..6e1aaf7 100644
20536--- a/arch/x86/include/uapi/asm/ldt.h
20537+++ b/arch/x86/include/uapi/asm/ldt.h
20538@@ -28,6 +28,13 @@ struct user_desc {
20539 unsigned int seg_not_present:1;
20540 unsigned int useable:1;
20541 #ifdef __x86_64__
20542+ /*
20543+ * Because this bit is not present in 32-bit user code, user
20544+ * programs can pass uninitialized values here. Therefore, in
20545+ * any context in which a user_desc comes from a 32-bit program,
20546+ * the kernel must act as though lm == 0, regardless of the
20547+ * actual value.
20548+ */
20549 unsigned int lm:1;
20550 #endif
20551 };
20552diff --git a/arch/x86/include/uapi/asm/ptrace-abi.h b/arch/x86/include/uapi/asm/ptrace-abi.h
20553index 7b0a55a..ad115bf 100644
20554--- a/arch/x86/include/uapi/asm/ptrace-abi.h
20555+++ b/arch/x86/include/uapi/asm/ptrace-abi.h
20556@@ -49,7 +49,6 @@
20557 #define EFLAGS 144
20558 #define RSP 152
20559 #define SS 160
20560-#define ARGOFFSET R11
20561 #endif /* __ASSEMBLY__ */
20562
20563 /* top of stack page */
20564diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile
20565index 8f1e774..9b4c381 100644
20566--- a/arch/x86/kernel/Makefile
20567+++ b/arch/x86/kernel/Makefile
20568@@ -24,7 +24,7 @@ obj-y += time.o ioport.o ldt.o dumpstack.o nmi.o
20569 obj-y += setup.o x86_init.o i8259.o irqinit.o jump_label.o
20570 obj-$(CONFIG_IRQ_WORK) += irq_work.o
20571 obj-y += probe_roms.o
20572-obj-$(CONFIG_X86_32) += i386_ksyms_32.o
20573+obj-$(CONFIG_X86_32) += sys_i386_32.o i386_ksyms_32.o
20574 obj-$(CONFIG_X86_64) += sys_x86_64.o x8664_ksyms_64.o
20575 obj-$(CONFIG_X86_64) += mcount_64.o
20576 obj-y += syscall_$(BITS).o vsyscall_gtod.o
20577diff --git a/arch/x86/kernel/acpi/boot.c b/arch/x86/kernel/acpi/boot.c
20578index a142e77..6222cdd 100644
20579--- a/arch/x86/kernel/acpi/boot.c
20580+++ b/arch/x86/kernel/acpi/boot.c
20581@@ -1276,7 +1276,7 @@ static int __init dmi_ignore_irq0_timer_override(const struct dmi_system_id *d)
20582 * If your system is blacklisted here, but you find that acpi=force
20583 * works for you, please contact linux-acpi@vger.kernel.org
20584 */
20585-static struct dmi_system_id __initdata acpi_dmi_table[] = {
20586+static const struct dmi_system_id __initconst acpi_dmi_table[] = {
20587 /*
20588 * Boxes that need ACPI disabled
20589 */
20590@@ -1351,7 +1351,7 @@ static struct dmi_system_id __initdata acpi_dmi_table[] = {
20591 };
20592
20593 /* second table for DMI checks that should run after early-quirks */
20594-static struct dmi_system_id __initdata acpi_dmi_table_late[] = {
20595+static const struct dmi_system_id __initconst acpi_dmi_table_late[] = {
20596 /*
20597 * HP laptops which use a DSDT reporting as HP/SB400/10000,
20598 * which includes some code which overrides all temperature
20599diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
20600index 3136820..e2c6577 100644
20601--- a/arch/x86/kernel/acpi/sleep.c
20602+++ b/arch/x86/kernel/acpi/sleep.c
20603@@ -99,8 +99,12 @@ int x86_acpi_suspend_lowlevel(void)
20604 #else /* CONFIG_64BIT */
20605 #ifdef CONFIG_SMP
20606 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
20607+
20608+ pax_open_kernel();
20609 early_gdt_descr.address =
20610 (unsigned long)get_cpu_gdt_table(smp_processor_id());
20611+ pax_close_kernel();
20612+
20613 initial_gs = per_cpu_offset(smp_processor_id());
20614 #endif
20615 initial_code = (unsigned long)wakeup_long64;
20616diff --git a/arch/x86/kernel/acpi/wakeup_32.S b/arch/x86/kernel/acpi/wakeup_32.S
20617index 665c6b7..eae4d56 100644
20618--- a/arch/x86/kernel/acpi/wakeup_32.S
20619+++ b/arch/x86/kernel/acpi/wakeup_32.S
20620@@ -29,13 +29,11 @@ wakeup_pmode_return:
20621 # and restore the stack ... but you need gdt for this to work
20622 movl saved_context_esp, %esp
20623
20624- movl %cs:saved_magic, %eax
20625- cmpl $0x12345678, %eax
20626+ cmpl $0x12345678, saved_magic
20627 jne bogus_magic
20628
20629 # jump to place where we left off
20630- movl saved_eip, %eax
20631- jmp *%eax
20632+ jmp *(saved_eip)
20633
20634 bogus_magic:
20635 jmp bogus_magic
20636diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
20637index 703130f..27a155d 100644
20638--- a/arch/x86/kernel/alternative.c
20639+++ b/arch/x86/kernel/alternative.c
20640@@ -268,6 +268,13 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
20641 */
20642 for (a = start; a < end; a++) {
20643 instr = (u8 *)&a->instr_offset + a->instr_offset;
20644+
20645+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20646+ instr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20647+ if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
20648+ instr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20649+#endif
20650+
20651 replacement = (u8 *)&a->repl_offset + a->repl_offset;
20652 BUG_ON(a->replacementlen > a->instrlen);
20653 BUG_ON(a->instrlen > sizeof(insnbuf));
20654@@ -284,6 +291,11 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
20655 add_nops(insnbuf + a->replacementlen,
20656 a->instrlen - a->replacementlen);
20657
20658+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20659+ if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
20660+ instr = ktva_ktla(instr);
20661+#endif
20662+
20663 text_poke_early(instr, insnbuf, a->instrlen);
20664 }
20665 }
20666@@ -299,10 +311,16 @@ static void alternatives_smp_lock(const s32 *start, const s32 *end,
20667 for (poff = start; poff < end; poff++) {
20668 u8 *ptr = (u8 *)poff + *poff;
20669
20670+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20671+ ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20672+ if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
20673+ ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20674+#endif
20675+
20676 if (!*poff || ptr < text || ptr >= text_end)
20677 continue;
20678 /* turn DS segment override prefix into lock prefix */
20679- if (*ptr == 0x3e)
20680+ if (*ktla_ktva(ptr) == 0x3e)
20681 text_poke(ptr, ((unsigned char []){0xf0}), 1);
20682 }
20683 mutex_unlock(&text_mutex);
20684@@ -317,10 +335,16 @@ static void alternatives_smp_unlock(const s32 *start, const s32 *end,
20685 for (poff = start; poff < end; poff++) {
20686 u8 *ptr = (u8 *)poff + *poff;
20687
20688+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20689+ ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20690+ if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
20691+ ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20692+#endif
20693+
20694 if (!*poff || ptr < text || ptr >= text_end)
20695 continue;
20696 /* turn lock prefix into DS segment override prefix */
20697- if (*ptr == 0xf0)
20698+ if (*ktla_ktva(ptr) == 0xf0)
20699 text_poke(ptr, ((unsigned char []){0x3E}), 1);
20700 }
20701 mutex_unlock(&text_mutex);
20702@@ -457,7 +481,7 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
20703
20704 BUG_ON(p->len > MAX_PATCH_LEN);
20705 /* prep the buffer with the original instructions */
20706- memcpy(insnbuf, p->instr, p->len);
20707+ memcpy(insnbuf, ktla_ktva(p->instr), p->len);
20708 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
20709 (unsigned long)p->instr, p->len);
20710
20711@@ -504,7 +528,7 @@ void __init alternative_instructions(void)
20712 if (!uniproc_patched || num_possible_cpus() == 1)
20713 free_init_pages("SMP alternatives",
20714 (unsigned long)__smp_locks,
20715- (unsigned long)__smp_locks_end);
20716+ PAGE_ALIGN((unsigned long)__smp_locks_end));
20717 #endif
20718
20719 apply_paravirt(__parainstructions, __parainstructions_end);
20720@@ -524,13 +548,17 @@ void __init alternative_instructions(void)
20721 * instructions. And on the local CPU you need to be protected again NMI or MCE
20722 * handlers seeing an inconsistent instruction while you patch.
20723 */
20724-void *__init_or_module text_poke_early(void *addr, const void *opcode,
20725+void *__kprobes text_poke_early(void *addr, const void *opcode,
20726 size_t len)
20727 {
20728 unsigned long flags;
20729 local_irq_save(flags);
20730- memcpy(addr, opcode, len);
20731+
20732+ pax_open_kernel();
20733+ memcpy(ktla_ktva(addr), opcode, len);
20734 sync_core();
20735+ pax_close_kernel();
20736+
20737 local_irq_restore(flags);
20738 /* Could also do a CLFLUSH here to speed up CPU recovery; but
20739 that causes hangs on some VIA CPUs. */
20740@@ -552,36 +580,22 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode,
20741 */
20742 void *text_poke(void *addr, const void *opcode, size_t len)
20743 {
20744- unsigned long flags;
20745- char *vaddr;
20746+ unsigned char *vaddr = ktla_ktva(addr);
20747 struct page *pages[2];
20748- int i;
20749+ size_t i;
20750
20751 if (!core_kernel_text((unsigned long)addr)) {
20752- pages[0] = vmalloc_to_page(addr);
20753- pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
20754+ pages[0] = vmalloc_to_page(vaddr);
20755+ pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
20756 } else {
20757- pages[0] = virt_to_page(addr);
20758+ pages[0] = virt_to_page(vaddr);
20759 WARN_ON(!PageReserved(pages[0]));
20760- pages[1] = virt_to_page(addr + PAGE_SIZE);
20761+ pages[1] = virt_to_page(vaddr + PAGE_SIZE);
20762 }
20763 BUG_ON(!pages[0]);
20764- local_irq_save(flags);
20765- set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
20766- if (pages[1])
20767- set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
20768- vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
20769- memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
20770- clear_fixmap(FIX_TEXT_POKE0);
20771- if (pages[1])
20772- clear_fixmap(FIX_TEXT_POKE1);
20773- local_flush_tlb();
20774- sync_core();
20775- /* Could also do a CLFLUSH here to speed up CPU recovery; but
20776- that causes hangs on some VIA CPUs. */
20777+ text_poke_early(addr, opcode, len);
20778 for (i = 0; i < len; i++)
20779- BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
20780- local_irq_restore(flags);
20781+ BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
20782 return addr;
20783 }
20784
20785@@ -601,7 +615,7 @@ int poke_int3_handler(struct pt_regs *regs)
20786 if (likely(!bp_patching_in_progress))
20787 return 0;
20788
20789- if (user_mode_vm(regs) || regs->ip != (unsigned long)bp_int3_addr)
20790+ if (user_mode(regs) || regs->ip != (unsigned long)bp_int3_addr)
20791 return 0;
20792
20793 /* set up the specified breakpoint handler */
20794@@ -635,7 +649,7 @@ int poke_int3_handler(struct pt_regs *regs)
20795 */
20796 void *text_poke_bp(void *addr, const void *opcode, size_t len, void *handler)
20797 {
20798- unsigned char int3 = 0xcc;
20799+ const unsigned char int3 = 0xcc;
20800
20801 bp_int3_handler = handler;
20802 bp_int3_addr = (u8 *)addr + sizeof(int3);
20803diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
20804index ba6cc04..06fd971 100644
20805--- a/arch/x86/kernel/apic/apic.c
20806+++ b/arch/x86/kernel/apic/apic.c
20807@@ -201,7 +201,7 @@ int first_system_vector = 0xfe;
20808 /*
20809 * Debug level, exported for io_apic.c
20810 */
20811-unsigned int apic_verbosity;
20812+int apic_verbosity;
20813
20814 int pic_mode;
20815
20816@@ -1989,7 +1989,7 @@ static inline void __smp_error_interrupt(struct pt_regs *regs)
20817 apic_write(APIC_ESR, 0);
20818 v = apic_read(APIC_ESR);
20819 ack_APIC_irq();
20820- atomic_inc(&irq_err_count);
20821+ atomic_inc_unchecked(&irq_err_count);
20822
20823 apic_printk(APIC_DEBUG, KERN_DEBUG "APIC error on CPU%d: %02x",
20824 smp_processor_id(), v);
20825diff --git a/arch/x86/kernel/apic/apic_flat_64.c b/arch/x86/kernel/apic/apic_flat_64.c
20826index de918c4..32eed23 100644
20827--- a/arch/x86/kernel/apic/apic_flat_64.c
20828+++ b/arch/x86/kernel/apic/apic_flat_64.c
20829@@ -154,7 +154,7 @@ static int flat_probe(void)
20830 return 1;
20831 }
20832
20833-static struct apic apic_flat = {
20834+static struct apic apic_flat __read_only = {
20835 .name = "flat",
20836 .probe = flat_probe,
20837 .acpi_madt_oem_check = flat_acpi_madt_oem_check,
20838@@ -260,7 +260,7 @@ static int physflat_probe(void)
20839 return 0;
20840 }
20841
20842-static struct apic apic_physflat = {
20843+static struct apic apic_physflat __read_only = {
20844
20845 .name = "physical flat",
20846 .probe = physflat_probe,
20847diff --git a/arch/x86/kernel/apic/apic_noop.c b/arch/x86/kernel/apic/apic_noop.c
20848index b205cdb..d8503ff 100644
20849--- a/arch/x86/kernel/apic/apic_noop.c
20850+++ b/arch/x86/kernel/apic/apic_noop.c
20851@@ -108,7 +108,7 @@ static void noop_apic_write(u32 reg, u32 v)
20852 WARN_ON_ONCE(cpu_has_apic && !disable_apic);
20853 }
20854
20855-struct apic apic_noop = {
20856+struct apic apic_noop __read_only = {
20857 .name = "noop",
20858 .probe = noop_probe,
20859 .acpi_madt_oem_check = NULL,
20860diff --git a/arch/x86/kernel/apic/bigsmp_32.c b/arch/x86/kernel/apic/bigsmp_32.c
20861index c4a8d63..fe893ac 100644
20862--- a/arch/x86/kernel/apic/bigsmp_32.c
20863+++ b/arch/x86/kernel/apic/bigsmp_32.c
20864@@ -147,7 +147,7 @@ static int probe_bigsmp(void)
20865 return dmi_bigsmp;
20866 }
20867
20868-static struct apic apic_bigsmp = {
20869+static struct apic apic_bigsmp __read_only = {
20870
20871 .name = "bigsmp",
20872 .probe = probe_bigsmp,
20873diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
20874index 1183d54..6158e47 100644
20875--- a/arch/x86/kernel/apic/io_apic.c
20876+++ b/arch/x86/kernel/apic/io_apic.c
20877@@ -1230,7 +1230,7 @@ out:
20878 }
20879 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
20880
20881-void lock_vector_lock(void)
20882+void lock_vector_lock(void) __acquires(vector_lock)
20883 {
20884 /* Used to the online set of cpus does not change
20885 * during assign_irq_vector.
20886@@ -1238,7 +1238,7 @@ void lock_vector_lock(void)
20887 raw_spin_lock(&vector_lock);
20888 }
20889
20890-void unlock_vector_lock(void)
20891+void unlock_vector_lock(void) __releases(vector_lock)
20892 {
20893 raw_spin_unlock(&vector_lock);
20894 }
20895@@ -2465,7 +2465,7 @@ static void ack_apic_edge(struct irq_data *data)
20896 ack_APIC_irq();
20897 }
20898
20899-atomic_t irq_mis_count;
20900+atomic_unchecked_t irq_mis_count;
20901
20902 #ifdef CONFIG_GENERIC_PENDING_IRQ
20903 static bool io_apic_level_ack_pending(struct irq_cfg *cfg)
20904@@ -2606,7 +2606,7 @@ static void ack_apic_level(struct irq_data *data)
20905 * at the cpu.
20906 */
20907 if (!(v & (1 << (i & 0x1f)))) {
20908- atomic_inc(&irq_mis_count);
20909+ atomic_inc_unchecked(&irq_mis_count);
20910
20911 eoi_ioapic_irq(irq, cfg);
20912 }
20913diff --git a/arch/x86/kernel/apic/probe_32.c b/arch/x86/kernel/apic/probe_32.c
20914index bda4886..f9c7195 100644
20915--- a/arch/x86/kernel/apic/probe_32.c
20916+++ b/arch/x86/kernel/apic/probe_32.c
20917@@ -72,7 +72,7 @@ static int probe_default(void)
20918 return 1;
20919 }
20920
20921-static struct apic apic_default = {
20922+static struct apic apic_default __read_only = {
20923
20924 .name = "default",
20925 .probe = probe_default,
20926diff --git a/arch/x86/kernel/apic/x2apic_cluster.c b/arch/x86/kernel/apic/x2apic_cluster.c
20927index e658f21..b695a1a 100644
20928--- a/arch/x86/kernel/apic/x2apic_cluster.c
20929+++ b/arch/x86/kernel/apic/x2apic_cluster.c
20930@@ -182,7 +182,7 @@ update_clusterinfo(struct notifier_block *nfb, unsigned long action, void *hcpu)
20931 return notifier_from_errno(err);
20932 }
20933
20934-static struct notifier_block __refdata x2apic_cpu_notifier = {
20935+static struct notifier_block x2apic_cpu_notifier = {
20936 .notifier_call = update_clusterinfo,
20937 };
20938
20939@@ -234,7 +234,7 @@ static void cluster_vector_allocation_domain(int cpu, struct cpumask *retmask,
20940 cpumask_and(retmask, mask, per_cpu(cpus_in_cluster, cpu));
20941 }
20942
20943-static struct apic apic_x2apic_cluster = {
20944+static struct apic apic_x2apic_cluster __read_only = {
20945
20946 .name = "cluster x2apic",
20947 .probe = x2apic_cluster_probe,
20948diff --git a/arch/x86/kernel/apic/x2apic_phys.c b/arch/x86/kernel/apic/x2apic_phys.c
20949index 6fae733..5ca17af 100644
20950--- a/arch/x86/kernel/apic/x2apic_phys.c
20951+++ b/arch/x86/kernel/apic/x2apic_phys.c
20952@@ -88,7 +88,7 @@ static int x2apic_phys_probe(void)
20953 return apic == &apic_x2apic_phys;
20954 }
20955
20956-static struct apic apic_x2apic_phys = {
20957+static struct apic apic_x2apic_phys __read_only = {
20958
20959 .name = "physical x2apic",
20960 .probe = x2apic_phys_probe,
20961diff --git a/arch/x86/kernel/apic/x2apic_uv_x.c b/arch/x86/kernel/apic/x2apic_uv_x.c
20962index 8e9dcfd..c61b3e4 100644
20963--- a/arch/x86/kernel/apic/x2apic_uv_x.c
20964+++ b/arch/x86/kernel/apic/x2apic_uv_x.c
20965@@ -348,7 +348,7 @@ static int uv_probe(void)
20966 return apic == &apic_x2apic_uv_x;
20967 }
20968
20969-static struct apic __refdata apic_x2apic_uv_x = {
20970+static struct apic apic_x2apic_uv_x __read_only = {
20971
20972 .name = "UV large system",
20973 .probe = uv_probe,
20974diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
20975index 5848744..56cb598 100644
20976--- a/arch/x86/kernel/apm_32.c
20977+++ b/arch/x86/kernel/apm_32.c
20978@@ -433,7 +433,7 @@ static DEFINE_MUTEX(apm_mutex);
20979 * This is for buggy BIOS's that refer to (real mode) segment 0x40
20980 * even though they are called in protected mode.
20981 */
20982-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
20983+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
20984 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
20985
20986 static const char driver_version[] = "1.16ac"; /* no spaces */
20987@@ -611,7 +611,10 @@ static long __apm_bios_call(void *_call)
20988 BUG_ON(cpu != 0);
20989 gdt = get_cpu_gdt_table(cpu);
20990 save_desc_40 = gdt[0x40 / 8];
20991+
20992+ pax_open_kernel();
20993 gdt[0x40 / 8] = bad_bios_desc;
20994+ pax_close_kernel();
20995
20996 apm_irq_save(flags);
20997 APM_DO_SAVE_SEGS;
20998@@ -620,7 +623,11 @@ static long __apm_bios_call(void *_call)
20999 &call->esi);
21000 APM_DO_RESTORE_SEGS;
21001 apm_irq_restore(flags);
21002+
21003+ pax_open_kernel();
21004 gdt[0x40 / 8] = save_desc_40;
21005+ pax_close_kernel();
21006+
21007 put_cpu();
21008
21009 return call->eax & 0xff;
21010@@ -687,7 +694,10 @@ static long __apm_bios_call_simple(void *_call)
21011 BUG_ON(cpu != 0);
21012 gdt = get_cpu_gdt_table(cpu);
21013 save_desc_40 = gdt[0x40 / 8];
21014+
21015+ pax_open_kernel();
21016 gdt[0x40 / 8] = bad_bios_desc;
21017+ pax_close_kernel();
21018
21019 apm_irq_save(flags);
21020 APM_DO_SAVE_SEGS;
21021@@ -695,7 +705,11 @@ static long __apm_bios_call_simple(void *_call)
21022 &call->eax);
21023 APM_DO_RESTORE_SEGS;
21024 apm_irq_restore(flags);
21025+
21026+ pax_open_kernel();
21027 gdt[0x40 / 8] = save_desc_40;
21028+ pax_close_kernel();
21029+
21030 put_cpu();
21031 return error;
21032 }
21033@@ -2350,12 +2364,15 @@ static int __init apm_init(void)
21034 * code to that CPU.
21035 */
21036 gdt = get_cpu_gdt_table(0);
21037+
21038+ pax_open_kernel();
21039 set_desc_base(&gdt[APM_CS >> 3],
21040 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
21041 set_desc_base(&gdt[APM_CS_16 >> 3],
21042 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
21043 set_desc_base(&gdt[APM_DS >> 3],
21044 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
21045+ pax_close_kernel();
21046
21047 proc_create("apm", 0, NULL, &apm_file_ops);
21048
21049diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
21050index 9f6b934..cf5ffb3 100644
21051--- a/arch/x86/kernel/asm-offsets.c
21052+++ b/arch/x86/kernel/asm-offsets.c
21053@@ -32,6 +32,8 @@ void common(void) {
21054 OFFSET(TI_flags, thread_info, flags);
21055 OFFSET(TI_status, thread_info, status);
21056 OFFSET(TI_addr_limit, thread_info, addr_limit);
21057+ OFFSET(TI_lowest_stack, thread_info, lowest_stack);
21058+ DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
21059
21060 BLANK();
21061 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
21062@@ -52,8 +54,26 @@ void common(void) {
21063 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
21064 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
21065 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
21066+
21067+#ifdef CONFIG_PAX_KERNEXEC
21068+ OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
21069 #endif
21070
21071+#ifdef CONFIG_PAX_MEMORY_UDEREF
21072+ OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
21073+ OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
21074+#ifdef CONFIG_X86_64
21075+ OFFSET(PV_MMU_set_pgd_batched, pv_mmu_ops, set_pgd_batched);
21076+#endif
21077+#endif
21078+
21079+#endif
21080+
21081+ BLANK();
21082+ DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
21083+ DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
21084+ DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
21085+
21086 #ifdef CONFIG_XEN
21087 BLANK();
21088 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
21089diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
21090index e7c798b..2b2019b 100644
21091--- a/arch/x86/kernel/asm-offsets_64.c
21092+++ b/arch/x86/kernel/asm-offsets_64.c
21093@@ -77,6 +77,7 @@ int main(void)
21094 BLANK();
21095 #undef ENTRY
21096
21097+ DEFINE(TSS_size, sizeof(struct tss_struct));
21098 OFFSET(TSS_ist, tss_struct, x86_tss.ist);
21099 BLANK();
21100
21101diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
21102index e27b49d..85b106c 100644
21103--- a/arch/x86/kernel/cpu/Makefile
21104+++ b/arch/x86/kernel/cpu/Makefile
21105@@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
21106 CFLAGS_REMOVE_perf_event.o = -pg
21107 endif
21108
21109-# Make sure load_percpu_segment has no stackprotector
21110-nostackp := $(call cc-option, -fno-stack-protector)
21111-CFLAGS_common.o := $(nostackp)
21112-
21113 obj-y := intel_cacheinfo.o scattered.o topology.o
21114 obj-y += common.o
21115 obj-y += rdrand.o
21116diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
21117index 813d29d..6e542d4 100644
21118--- a/arch/x86/kernel/cpu/amd.c
21119+++ b/arch/x86/kernel/cpu/amd.c
21120@@ -718,7 +718,7 @@ static void init_amd(struct cpuinfo_x86 *c)
21121 static unsigned int amd_size_cache(struct cpuinfo_x86 *c, unsigned int size)
21122 {
21123 /* AMD errata T13 (order #21922) */
21124- if ((c->x86 == 6)) {
21125+ if (c->x86 == 6) {
21126 /* Duron Rev A0 */
21127 if (c->x86_model == 3 && c->x86_mask == 0)
21128 size = 64;
21129diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
21130index cfa9b5b..19b5084 100644
21131--- a/arch/x86/kernel/cpu/common.c
21132+++ b/arch/x86/kernel/cpu/common.c
21133@@ -90,60 +90,6 @@ static const struct cpu_dev default_cpu = {
21134
21135 static const struct cpu_dev *this_cpu = &default_cpu;
21136
21137-DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
21138-#ifdef CONFIG_X86_64
21139- /*
21140- * We need valid kernel segments for data and code in long mode too
21141- * IRET will check the segment types kkeil 2000/10/28
21142- * Also sysret mandates a special GDT layout
21143- *
21144- * TLS descriptors are currently at a different place compared to i386.
21145- * Hopefully nobody expects them at a fixed place (Wine?)
21146- */
21147- [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
21148- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
21149- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
21150- [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
21151- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
21152- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
21153-#else
21154- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
21155- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
21156- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
21157- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
21158- /*
21159- * Segments used for calling PnP BIOS have byte granularity.
21160- * They code segments and data segments have fixed 64k limits,
21161- * the transfer segment sizes are set at run time.
21162- */
21163- /* 32-bit code */
21164- [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
21165- /* 16-bit code */
21166- [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
21167- /* 16-bit data */
21168- [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
21169- /* 16-bit data */
21170- [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
21171- /* 16-bit data */
21172- [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
21173- /*
21174- * The APM segments have byte granularity and their bases
21175- * are set at run time. All have 64k limits.
21176- */
21177- /* 32-bit code */
21178- [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
21179- /* 16-bit code */
21180- [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
21181- /* data */
21182- [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
21183-
21184- [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
21185- [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
21186- GDT_STACK_CANARY_INIT
21187-#endif
21188-} };
21189-EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
21190-
21191 static int __init x86_xsave_setup(char *s)
21192 {
21193 if (strlen(s))
21194@@ -305,6 +251,59 @@ static __always_inline void setup_smap(struct cpuinfo_x86 *c)
21195 }
21196 }
21197
21198+#ifdef CONFIG_X86_64
21199+static __init int setup_disable_pcid(char *arg)
21200+{
21201+ setup_clear_cpu_cap(X86_FEATURE_PCID);
21202+ setup_clear_cpu_cap(X86_FEATURE_INVPCID);
21203+
21204+#ifdef CONFIG_PAX_MEMORY_UDEREF
21205+ if (clone_pgd_mask != ~(pgdval_t)0UL)
21206+ pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
21207+#endif
21208+
21209+ return 1;
21210+}
21211+__setup("nopcid", setup_disable_pcid);
21212+
21213+static void setup_pcid(struct cpuinfo_x86 *c)
21214+{
21215+ if (!cpu_has(c, X86_FEATURE_PCID)) {
21216+ clear_cpu_cap(c, X86_FEATURE_INVPCID);
21217+
21218+#ifdef CONFIG_PAX_MEMORY_UDEREF
21219+ if (clone_pgd_mask != ~(pgdval_t)0UL) {
21220+ pax_open_kernel();
21221+ pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
21222+ pax_close_kernel();
21223+ printk("PAX: slow and weak UDEREF enabled\n");
21224+ } else
21225+ printk("PAX: UDEREF disabled\n");
21226+#endif
21227+
21228+ return;
21229+ }
21230+
21231+ printk("PAX: PCID detected\n");
21232+ set_in_cr4(X86_CR4_PCIDE);
21233+
21234+#ifdef CONFIG_PAX_MEMORY_UDEREF
21235+ pax_open_kernel();
21236+ clone_pgd_mask = ~(pgdval_t)0UL;
21237+ pax_close_kernel();
21238+ if (pax_user_shadow_base)
21239+ printk("PAX: weak UDEREF enabled\n");
21240+ else {
21241+ set_cpu_cap(c, X86_FEATURE_STRONGUDEREF);
21242+ printk("PAX: strong UDEREF enabled\n");
21243+ }
21244+#endif
21245+
21246+ if (cpu_has(c, X86_FEATURE_INVPCID))
21247+ printk("PAX: INVPCID detected\n");
21248+}
21249+#endif
21250+
21251 /*
21252 * Some CPU features depend on higher CPUID levels, which may not always
21253 * be available due to CPUID level capping or broken virtualization
21254@@ -405,7 +404,7 @@ void switch_to_new_gdt(int cpu)
21255 {
21256 struct desc_ptr gdt_descr;
21257
21258- gdt_descr.address = (long)get_cpu_gdt_table(cpu);
21259+ gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
21260 gdt_descr.size = GDT_SIZE - 1;
21261 load_gdt(&gdt_descr);
21262 /* Reload the per-cpu base */
21263@@ -895,6 +894,10 @@ static void identify_cpu(struct cpuinfo_x86 *c)
21264 setup_smep(c);
21265 setup_smap(c);
21266
21267+#ifdef CONFIG_X86_64
21268+ setup_pcid(c);
21269+#endif
21270+
21271 /*
21272 * The vendor-specific functions might have changed features.
21273 * Now we do "generic changes."
21274@@ -903,6 +906,10 @@ static void identify_cpu(struct cpuinfo_x86 *c)
21275 /* Filter out anything that depends on CPUID levels we don't have */
21276 filter_cpuid_features(c, true);
21277
21278+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
21279+ setup_clear_cpu_cap(X86_FEATURE_SEP);
21280+#endif
21281+
21282 /* If the model name is still unset, do table lookup. */
21283 if (!c->x86_model_id[0]) {
21284 const char *p;
21285@@ -985,7 +992,7 @@ static void syscall32_cpu_init(void)
21286 void enable_sep_cpu(void)
21287 {
21288 int cpu = get_cpu();
21289- struct tss_struct *tss = &per_cpu(init_tss, cpu);
21290+ struct tss_struct *tss = init_tss + cpu;
21291
21292 if (!boot_cpu_has(X86_FEATURE_SEP)) {
21293 put_cpu();
21294@@ -1125,14 +1132,16 @@ static __init int setup_disablecpuid(char *arg)
21295 }
21296 __setup("clearcpuid=", setup_disablecpuid);
21297
21298+DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
21299+EXPORT_PER_CPU_SYMBOL(current_tinfo);
21300+
21301 DEFINE_PER_CPU(unsigned long, kernel_stack) =
21302- (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
21303+ (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
21304 EXPORT_PER_CPU_SYMBOL(kernel_stack);
21305
21306 #ifdef CONFIG_X86_64
21307-struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
21308-struct desc_ptr debug_idt_descr = { NR_VECTORS * 16 - 1,
21309- (unsigned long) debug_idt_table };
21310+struct desc_ptr idt_descr __read_only = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
21311+const struct desc_ptr debug_idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) debug_idt_table };
21312
21313 DEFINE_PER_CPU_FIRST(union irq_stack_union,
21314 irq_stack_union) __aligned(PAGE_SIZE) __visible;
21315@@ -1309,7 +1318,7 @@ void cpu_init(void)
21316 */
21317 load_ucode_ap();
21318
21319- t = &per_cpu(init_tss, cpu);
21320+ t = init_tss + cpu;
21321 oist = &per_cpu(orig_ist, cpu);
21322
21323 #ifdef CONFIG_NUMA
21324@@ -1341,7 +1350,6 @@ void cpu_init(void)
21325 wrmsrl(MSR_KERNEL_GS_BASE, 0);
21326 barrier();
21327
21328- x86_configure_nx();
21329 enable_x2apic();
21330
21331 /*
21332@@ -1393,7 +1401,7 @@ void cpu_init(void)
21333 {
21334 int cpu = smp_processor_id();
21335 struct task_struct *curr = current;
21336- struct tss_struct *t = &per_cpu(init_tss, cpu);
21337+ struct tss_struct *t = init_tss + cpu;
21338 struct thread_struct *thread = &curr->thread;
21339
21340 wait_for_master_cpu(cpu);
21341diff --git a/arch/x86/kernel/cpu/intel_cacheinfo.c b/arch/x86/kernel/cpu/intel_cacheinfo.c
21342index c703507..28535e3 100644
21343--- a/arch/x86/kernel/cpu/intel_cacheinfo.c
21344+++ b/arch/x86/kernel/cpu/intel_cacheinfo.c
21345@@ -1026,6 +1026,22 @@ static struct attribute *default_attrs[] = {
21346 };
21347
21348 #ifdef CONFIG_AMD_NB
21349+static struct attribute *default_attrs_amd_nb[] = {
21350+ &type.attr,
21351+ &level.attr,
21352+ &coherency_line_size.attr,
21353+ &physical_line_partition.attr,
21354+ &ways_of_associativity.attr,
21355+ &number_of_sets.attr,
21356+ &size.attr,
21357+ &shared_cpu_map.attr,
21358+ &shared_cpu_list.attr,
21359+ NULL,
21360+ NULL,
21361+ NULL,
21362+ NULL
21363+};
21364+
21365 static struct attribute **amd_l3_attrs(void)
21366 {
21367 static struct attribute **attrs;
21368@@ -1036,18 +1052,7 @@ static struct attribute **amd_l3_attrs(void)
21369
21370 n = ARRAY_SIZE(default_attrs);
21371
21372- if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE))
21373- n += 2;
21374-
21375- if (amd_nb_has_feature(AMD_NB_L3_PARTITIONING))
21376- n += 1;
21377-
21378- attrs = kzalloc(n * sizeof (struct attribute *), GFP_KERNEL);
21379- if (attrs == NULL)
21380- return attrs = default_attrs;
21381-
21382- for (n = 0; default_attrs[n]; n++)
21383- attrs[n] = default_attrs[n];
21384+ attrs = default_attrs_amd_nb;
21385
21386 if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE)) {
21387 attrs[n++] = &cache_disable_0.attr;
21388@@ -1098,6 +1103,13 @@ static struct kobj_type ktype_cache = {
21389 .default_attrs = default_attrs,
21390 };
21391
21392+#ifdef CONFIG_AMD_NB
21393+static struct kobj_type ktype_cache_amd_nb = {
21394+ .sysfs_ops = &sysfs_ops,
21395+ .default_attrs = default_attrs_amd_nb,
21396+};
21397+#endif
21398+
21399 static struct kobj_type ktype_percpu_entry = {
21400 .sysfs_ops = &sysfs_ops,
21401 };
21402@@ -1163,20 +1175,26 @@ static int cache_add_dev(struct device *dev)
21403 return retval;
21404 }
21405
21406+#ifdef CONFIG_AMD_NB
21407+ amd_l3_attrs();
21408+#endif
21409+
21410 for (i = 0; i < num_cache_leaves; i++) {
21411+ struct kobj_type *ktype;
21412+
21413 this_object = INDEX_KOBJECT_PTR(cpu, i);
21414 this_object->cpu = cpu;
21415 this_object->index = i;
21416
21417 this_leaf = CPUID4_INFO_IDX(cpu, i);
21418
21419- ktype_cache.default_attrs = default_attrs;
21420+ ktype = &ktype_cache;
21421 #ifdef CONFIG_AMD_NB
21422 if (this_leaf->base.nb)
21423- ktype_cache.default_attrs = amd_l3_attrs();
21424+ ktype = &ktype_cache_amd_nb;
21425 #endif
21426 retval = kobject_init_and_add(&(this_object->kobj),
21427- &ktype_cache,
21428+ ktype,
21429 per_cpu(ici_cache_kobject, cpu),
21430 "index%1lu", i);
21431 if (unlikely(retval)) {
21432diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
21433index 61a9668ce..b446a37 100644
21434--- a/arch/x86/kernel/cpu/mcheck/mce.c
21435+++ b/arch/x86/kernel/cpu/mcheck/mce.c
21436@@ -45,6 +45,7 @@
21437 #include <asm/processor.h>
21438 #include <asm/mce.h>
21439 #include <asm/msr.h>
21440+#include <asm/local.h>
21441
21442 #include "mce-internal.h"
21443
21444@@ -259,7 +260,7 @@ static void print_mce(struct mce *m)
21445 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
21446 m->cs, m->ip);
21447
21448- if (m->cs == __KERNEL_CS)
21449+ if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
21450 print_symbol("{%s}", m->ip);
21451 pr_cont("\n");
21452 }
21453@@ -292,10 +293,10 @@ static void print_mce(struct mce *m)
21454
21455 #define PANIC_TIMEOUT 5 /* 5 seconds */
21456
21457-static atomic_t mce_paniced;
21458+static atomic_unchecked_t mce_paniced;
21459
21460 static int fake_panic;
21461-static atomic_t mce_fake_paniced;
21462+static atomic_unchecked_t mce_fake_paniced;
21463
21464 /* Panic in progress. Enable interrupts and wait for final IPI */
21465 static void wait_for_panic(void)
21466@@ -319,7 +320,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
21467 /*
21468 * Make sure only one CPU runs in machine check panic
21469 */
21470- if (atomic_inc_return(&mce_paniced) > 1)
21471+ if (atomic_inc_return_unchecked(&mce_paniced) > 1)
21472 wait_for_panic();
21473 barrier();
21474
21475@@ -327,7 +328,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
21476 console_verbose();
21477 } else {
21478 /* Don't log too much for fake panic */
21479- if (atomic_inc_return(&mce_fake_paniced) > 1)
21480+ if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
21481 return;
21482 }
21483 /* First print corrected ones that are still unlogged */
21484@@ -366,7 +367,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
21485 if (!fake_panic) {
21486 if (panic_timeout == 0)
21487 panic_timeout = mca_cfg.panic_timeout;
21488- panic(msg);
21489+ panic("%s", msg);
21490 } else
21491 pr_emerg(HW_ERR "Fake kernel panic: %s\n", msg);
21492 }
21493@@ -697,7 +698,7 @@ static int mce_timed_out(u64 *t)
21494 * might have been modified by someone else.
21495 */
21496 rmb();
21497- if (atomic_read(&mce_paniced))
21498+ if (atomic_read_unchecked(&mce_paniced))
21499 wait_for_panic();
21500 if (!mca_cfg.monarch_timeout)
21501 goto out;
21502@@ -1674,7 +1675,7 @@ static void unexpected_machine_check(struct pt_regs *regs, long error_code)
21503 }
21504
21505 /* Call the installed machine check handler for this CPU setup. */
21506-void (*machine_check_vector)(struct pt_regs *, long error_code) =
21507+void (*machine_check_vector)(struct pt_regs *, long error_code) __read_only =
21508 unexpected_machine_check;
21509
21510 /*
21511@@ -1697,7 +1698,9 @@ void mcheck_cpu_init(struct cpuinfo_x86 *c)
21512 return;
21513 }
21514
21515+ pax_open_kernel();
21516 machine_check_vector = do_machine_check;
21517+ pax_close_kernel();
21518
21519 __mcheck_cpu_init_generic();
21520 __mcheck_cpu_init_vendor(c);
21521@@ -1711,7 +1714,7 @@ void mcheck_cpu_init(struct cpuinfo_x86 *c)
21522 */
21523
21524 static DEFINE_SPINLOCK(mce_chrdev_state_lock);
21525-static int mce_chrdev_open_count; /* #times opened */
21526+static local_t mce_chrdev_open_count; /* #times opened */
21527 static int mce_chrdev_open_exclu; /* already open exclusive? */
21528
21529 static int mce_chrdev_open(struct inode *inode, struct file *file)
21530@@ -1719,7 +1722,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
21531 spin_lock(&mce_chrdev_state_lock);
21532
21533 if (mce_chrdev_open_exclu ||
21534- (mce_chrdev_open_count && (file->f_flags & O_EXCL))) {
21535+ (local_read(&mce_chrdev_open_count) && (file->f_flags & O_EXCL))) {
21536 spin_unlock(&mce_chrdev_state_lock);
21537
21538 return -EBUSY;
21539@@ -1727,7 +1730,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
21540
21541 if (file->f_flags & O_EXCL)
21542 mce_chrdev_open_exclu = 1;
21543- mce_chrdev_open_count++;
21544+ local_inc(&mce_chrdev_open_count);
21545
21546 spin_unlock(&mce_chrdev_state_lock);
21547
21548@@ -1738,7 +1741,7 @@ static int mce_chrdev_release(struct inode *inode, struct file *file)
21549 {
21550 spin_lock(&mce_chrdev_state_lock);
21551
21552- mce_chrdev_open_count--;
21553+ local_dec(&mce_chrdev_open_count);
21554 mce_chrdev_open_exclu = 0;
21555
21556 spin_unlock(&mce_chrdev_state_lock);
21557@@ -2413,7 +2416,7 @@ static __init void mce_init_banks(void)
21558
21559 for (i = 0; i < mca_cfg.banks; i++) {
21560 struct mce_bank *b = &mce_banks[i];
21561- struct device_attribute *a = &b->attr;
21562+ device_attribute_no_const *a = &b->attr;
21563
21564 sysfs_attr_init(&a->attr);
21565 a->attr.name = b->attrname;
21566@@ -2520,7 +2523,7 @@ struct dentry *mce_get_debugfs_dir(void)
21567 static void mce_reset(void)
21568 {
21569 cpu_missing = 0;
21570- atomic_set(&mce_fake_paniced, 0);
21571+ atomic_set_unchecked(&mce_fake_paniced, 0);
21572 atomic_set(&mce_executing, 0);
21573 atomic_set(&mce_callin, 0);
21574 atomic_set(&global_nwo, 0);
21575diff --git a/arch/x86/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
21576index a304298..49b6d06 100644
21577--- a/arch/x86/kernel/cpu/mcheck/p5.c
21578+++ b/arch/x86/kernel/cpu/mcheck/p5.c
21579@@ -10,6 +10,7 @@
21580 #include <asm/processor.h>
21581 #include <asm/mce.h>
21582 #include <asm/msr.h>
21583+#include <asm/pgtable.h>
21584
21585 /* By default disabled */
21586 int mce_p5_enabled __read_mostly;
21587@@ -48,7 +49,9 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
21588 if (!cpu_has(c, X86_FEATURE_MCE))
21589 return;
21590
21591+ pax_open_kernel();
21592 machine_check_vector = pentium_machine_check;
21593+ pax_close_kernel();
21594 /* Make sure the vector pointer is visible before we enable MCEs: */
21595 wmb();
21596
21597diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
21598index 7dc5564..1273569 100644
21599--- a/arch/x86/kernel/cpu/mcheck/winchip.c
21600+++ b/arch/x86/kernel/cpu/mcheck/winchip.c
21601@@ -9,6 +9,7 @@
21602 #include <asm/processor.h>
21603 #include <asm/mce.h>
21604 #include <asm/msr.h>
21605+#include <asm/pgtable.h>
21606
21607 /* Machine check handler for WinChip C6: */
21608 static void winchip_machine_check(struct pt_regs *regs, long error_code)
21609@@ -22,7 +23,9 @@ void winchip_mcheck_init(struct cpuinfo_x86 *c)
21610 {
21611 u32 lo, hi;
21612
21613+ pax_open_kernel();
21614 machine_check_vector = winchip_machine_check;
21615+ pax_close_kernel();
21616 /* Make sure the vector pointer is visible before we enable MCEs: */
21617 wmb();
21618
21619diff --git a/arch/x86/kernel/cpu/microcode/core.c b/arch/x86/kernel/cpu/microcode/core.c
21620index 08fe6e8..35885b0 100644
21621--- a/arch/x86/kernel/cpu/microcode/core.c
21622+++ b/arch/x86/kernel/cpu/microcode/core.c
21623@@ -526,7 +526,7 @@ mc_cpu_callback(struct notifier_block *nb, unsigned long action, void *hcpu)
21624 return NOTIFY_OK;
21625 }
21626
21627-static struct notifier_block __refdata mc_cpu_notifier = {
21628+static struct notifier_block mc_cpu_notifier = {
21629 .notifier_call = mc_cpu_callback,
21630 };
21631
21632diff --git a/arch/x86/kernel/cpu/microcode/intel.c b/arch/x86/kernel/cpu/microcode/intel.c
21633index c6826d1..ad18e14a 100644
21634--- a/arch/x86/kernel/cpu/microcode/intel.c
21635+++ b/arch/x86/kernel/cpu/microcode/intel.c
21636@@ -293,13 +293,13 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device,
21637
21638 static int get_ucode_user(void *to, const void *from, size_t n)
21639 {
21640- return copy_from_user(to, from, n);
21641+ return copy_from_user(to, (const void __force_user *)from, n);
21642 }
21643
21644 static enum ucode_state
21645 request_microcode_user(int cpu, const void __user *buf, size_t size)
21646 {
21647- return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
21648+ return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
21649 }
21650
21651 static void microcode_fini_cpu(int cpu)
21652diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
21653index ea5f363..cb0e905 100644
21654--- a/arch/x86/kernel/cpu/mtrr/main.c
21655+++ b/arch/x86/kernel/cpu/mtrr/main.c
21656@@ -66,7 +66,7 @@ static DEFINE_MUTEX(mtrr_mutex);
21657 u64 size_or_mask, size_and_mask;
21658 static bool mtrr_aps_delayed_init;
21659
21660-static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
21661+static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
21662
21663 const struct mtrr_ops *mtrr_if;
21664
21665diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
21666index df5e41f..816c719 100644
21667--- a/arch/x86/kernel/cpu/mtrr/mtrr.h
21668+++ b/arch/x86/kernel/cpu/mtrr/mtrr.h
21669@@ -25,7 +25,7 @@ struct mtrr_ops {
21670 int (*validate_add_page)(unsigned long base, unsigned long size,
21671 unsigned int type);
21672 int (*have_wrcomb)(void);
21673-};
21674+} __do_const;
21675
21676 extern int generic_get_free_region(unsigned long base, unsigned long size,
21677 int replace_reg);
21678diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
21679index 143e5f5..5825081 100644
21680--- a/arch/x86/kernel/cpu/perf_event.c
21681+++ b/arch/x86/kernel/cpu/perf_event.c
21682@@ -1374,7 +1374,7 @@ static void __init pmu_check_apic(void)
21683
21684 }
21685
21686-static struct attribute_group x86_pmu_format_group = {
21687+static attribute_group_no_const x86_pmu_format_group = {
21688 .name = "format",
21689 .attrs = NULL,
21690 };
21691@@ -1473,7 +1473,7 @@ static struct attribute *events_attr[] = {
21692 NULL,
21693 };
21694
21695-static struct attribute_group x86_pmu_events_group = {
21696+static attribute_group_no_const x86_pmu_events_group = {
21697 .name = "events",
21698 .attrs = events_attr,
21699 };
21700@@ -1997,7 +1997,7 @@ static unsigned long get_segment_base(unsigned int segment)
21701 if (idx > GDT_ENTRIES)
21702 return 0;
21703
21704- desc = raw_cpu_ptr(gdt_page.gdt);
21705+ desc = get_cpu_gdt_table(smp_processor_id());
21706 }
21707
21708 return get_desc_base(desc + idx);
21709@@ -2087,7 +2087,7 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
21710 break;
21711
21712 perf_callchain_store(entry, frame.return_address);
21713- fp = frame.next_frame;
21714+ fp = (const void __force_user *)frame.next_frame;
21715 }
21716 }
21717
21718diff --git a/arch/x86/kernel/cpu/perf_event_amd_iommu.c b/arch/x86/kernel/cpu/perf_event_amd_iommu.c
21719index 639d128..e92d7e5 100644
21720--- a/arch/x86/kernel/cpu/perf_event_amd_iommu.c
21721+++ b/arch/x86/kernel/cpu/perf_event_amd_iommu.c
21722@@ -405,7 +405,7 @@ static void perf_iommu_del(struct perf_event *event, int flags)
21723 static __init int _init_events_attrs(struct perf_amd_iommu *perf_iommu)
21724 {
21725 struct attribute **attrs;
21726- struct attribute_group *attr_group;
21727+ attribute_group_no_const *attr_group;
21728 int i = 0, j;
21729
21730 while (amd_iommu_v2_event_descs[i].attr.attr.name)
21731diff --git a/arch/x86/kernel/cpu/perf_event_intel.c b/arch/x86/kernel/cpu/perf_event_intel.c
21732index 944bf01..4a4392f 100644
21733--- a/arch/x86/kernel/cpu/perf_event_intel.c
21734+++ b/arch/x86/kernel/cpu/perf_event_intel.c
21735@@ -2353,10 +2353,10 @@ __init int intel_pmu_init(void)
21736 x86_pmu.num_counters_fixed = max((int)edx.split.num_counters_fixed, 3);
21737
21738 if (boot_cpu_has(X86_FEATURE_PDCM)) {
21739- u64 capabilities;
21740+ u64 capabilities = x86_pmu.intel_cap.capabilities;
21741
21742- rdmsrl(MSR_IA32_PERF_CAPABILITIES, capabilities);
21743- x86_pmu.intel_cap.capabilities = capabilities;
21744+ if (rdmsrl_safe(MSR_IA32_PERF_CAPABILITIES, &x86_pmu.intel_cap.capabilities))
21745+ x86_pmu.intel_cap.capabilities = capabilities;
21746 }
21747
21748 intel_ds_init();
21749diff --git a/arch/x86/kernel/cpu/perf_event_intel_rapl.c b/arch/x86/kernel/cpu/perf_event_intel_rapl.c
21750index d64f275..26522ff 100644
21751--- a/arch/x86/kernel/cpu/perf_event_intel_rapl.c
21752+++ b/arch/x86/kernel/cpu/perf_event_intel_rapl.c
21753@@ -449,7 +449,7 @@ static struct attribute *rapl_events_hsw_attr[] = {
21754 NULL,
21755 };
21756
21757-static struct attribute_group rapl_pmu_events_group = {
21758+static attribute_group_no_const rapl_pmu_events_group __read_only = {
21759 .name = "events",
21760 .attrs = NULL, /* patched at runtime */
21761 };
21762diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.c b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
21763index 9762dbd..53d5d21 100644
21764--- a/arch/x86/kernel/cpu/perf_event_intel_uncore.c
21765+++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
21766@@ -721,7 +721,7 @@ static void __init uncore_types_exit(struct intel_uncore_type **types)
21767 static int __init uncore_type_init(struct intel_uncore_type *type)
21768 {
21769 struct intel_uncore_pmu *pmus;
21770- struct attribute_group *attr_group;
21771+ attribute_group_no_const *attr_group;
21772 struct attribute **attrs;
21773 int i, j;
21774
21775diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.h b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
21776index 18eb78b..18747cc 100644
21777--- a/arch/x86/kernel/cpu/perf_event_intel_uncore.h
21778+++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
21779@@ -114,7 +114,7 @@ struct intel_uncore_box {
21780 struct uncore_event_desc {
21781 struct kobj_attribute attr;
21782 const char *config;
21783-};
21784+} __do_const;
21785
21786 ssize_t uncore_event_show(struct kobject *kobj,
21787 struct kobj_attribute *attr, char *buf);
21788diff --git a/arch/x86/kernel/cpuid.c b/arch/x86/kernel/cpuid.c
21789index 3225ae6c..ee3c6db 100644
21790--- a/arch/x86/kernel/cpuid.c
21791+++ b/arch/x86/kernel/cpuid.c
21792@@ -170,7 +170,7 @@ static int cpuid_class_cpu_callback(struct notifier_block *nfb,
21793 return notifier_from_errno(err);
21794 }
21795
21796-static struct notifier_block __refdata cpuid_class_cpu_notifier =
21797+static struct notifier_block cpuid_class_cpu_notifier =
21798 {
21799 .notifier_call = cpuid_class_cpu_callback,
21800 };
21801diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
21802index f5ab56d..d3b201a 100644
21803--- a/arch/x86/kernel/crash.c
21804+++ b/arch/x86/kernel/crash.c
21805@@ -104,7 +104,7 @@ static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
21806 #ifdef CONFIG_X86_32
21807 struct pt_regs fixed_regs;
21808
21809- if (!user_mode_vm(regs)) {
21810+ if (!user_mode(regs)) {
21811 crash_fixup_ss_esp(&fixed_regs, regs);
21812 regs = &fixed_regs;
21813 }
21814diff --git a/arch/x86/kernel/crash_dump_64.c b/arch/x86/kernel/crash_dump_64.c
21815index afa64ad..dce67dd 100644
21816--- a/arch/x86/kernel/crash_dump_64.c
21817+++ b/arch/x86/kernel/crash_dump_64.c
21818@@ -36,7 +36,7 @@ ssize_t copy_oldmem_page(unsigned long pfn, char *buf,
21819 return -ENOMEM;
21820
21821 if (userbuf) {
21822- if (copy_to_user(buf, vaddr + offset, csize)) {
21823+ if (copy_to_user((char __force_user *)buf, vaddr + offset, csize)) {
21824 iounmap(vaddr);
21825 return -EFAULT;
21826 }
21827diff --git a/arch/x86/kernel/doublefault.c b/arch/x86/kernel/doublefault.c
21828index f6dfd93..892ade4 100644
21829--- a/arch/x86/kernel/doublefault.c
21830+++ b/arch/x86/kernel/doublefault.c
21831@@ -12,7 +12,7 @@
21832
21833 #define DOUBLEFAULT_STACKSIZE (1024)
21834 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
21835-#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
21836+#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
21837
21838 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
21839
21840@@ -22,7 +22,7 @@ static void doublefault_fn(void)
21841 unsigned long gdt, tss;
21842
21843 native_store_gdt(&gdt_desc);
21844- gdt = gdt_desc.address;
21845+ gdt = (unsigned long)gdt_desc.address;
21846
21847 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
21848
21849@@ -59,10 +59,10 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
21850 /* 0x2 bit is always set */
21851 .flags = X86_EFLAGS_SF | 0x2,
21852 .sp = STACK_START,
21853- .es = __USER_DS,
21854+ .es = __KERNEL_DS,
21855 .cs = __KERNEL_CS,
21856 .ss = __KERNEL_DS,
21857- .ds = __USER_DS,
21858+ .ds = __KERNEL_DS,
21859 .fs = __KERNEL_PERCPU,
21860
21861 .__cr3 = __pa_nodebug(swapper_pg_dir),
21862diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
21863index b74ebc7..2c95874 100644
21864--- a/arch/x86/kernel/dumpstack.c
21865+++ b/arch/x86/kernel/dumpstack.c
21866@@ -2,6 +2,9 @@
21867 * Copyright (C) 1991, 1992 Linus Torvalds
21868 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
21869 */
21870+#ifdef CONFIG_GRKERNSEC_HIDESYM
21871+#define __INCLUDED_BY_HIDESYM 1
21872+#endif
21873 #include <linux/kallsyms.h>
21874 #include <linux/kprobes.h>
21875 #include <linux/uaccess.h>
21876@@ -33,23 +36,21 @@ static void printk_stack_address(unsigned long address, int reliable)
21877
21878 void printk_address(unsigned long address)
21879 {
21880- pr_cont(" [<%p>] %pS\n", (void *)address, (void *)address);
21881+ pr_cont(" [<%p>] %pA\n", (void *)address, (void *)address);
21882 }
21883
21884 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
21885 static void
21886 print_ftrace_graph_addr(unsigned long addr, void *data,
21887 const struct stacktrace_ops *ops,
21888- struct thread_info *tinfo, int *graph)
21889+ struct task_struct *task, int *graph)
21890 {
21891- struct task_struct *task;
21892 unsigned long ret_addr;
21893 int index;
21894
21895 if (addr != (unsigned long)return_to_handler)
21896 return;
21897
21898- task = tinfo->task;
21899 index = task->curr_ret_stack;
21900
21901 if (!task->ret_stack || index < *graph)
21902@@ -66,7 +67,7 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
21903 static inline void
21904 print_ftrace_graph_addr(unsigned long addr, void *data,
21905 const struct stacktrace_ops *ops,
21906- struct thread_info *tinfo, int *graph)
21907+ struct task_struct *task, int *graph)
21908 { }
21909 #endif
21910
21911@@ -77,10 +78,8 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
21912 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
21913 */
21914
21915-static inline int valid_stack_ptr(struct thread_info *tinfo,
21916- void *p, unsigned int size, void *end)
21917+static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
21918 {
21919- void *t = tinfo;
21920 if (end) {
21921 if (p < end && p >= (end-THREAD_SIZE))
21922 return 1;
21923@@ -91,14 +90,14 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
21924 }
21925
21926 unsigned long
21927-print_context_stack(struct thread_info *tinfo,
21928+print_context_stack(struct task_struct *task, void *stack_start,
21929 unsigned long *stack, unsigned long bp,
21930 const struct stacktrace_ops *ops, void *data,
21931 unsigned long *end, int *graph)
21932 {
21933 struct stack_frame *frame = (struct stack_frame *)bp;
21934
21935- while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
21936+ while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
21937 unsigned long addr;
21938
21939 addr = *stack;
21940@@ -110,7 +109,7 @@ print_context_stack(struct thread_info *tinfo,
21941 } else {
21942 ops->address(data, addr, 0);
21943 }
21944- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
21945+ print_ftrace_graph_addr(addr, data, ops, task, graph);
21946 }
21947 stack++;
21948 }
21949@@ -119,7 +118,7 @@ print_context_stack(struct thread_info *tinfo,
21950 EXPORT_SYMBOL_GPL(print_context_stack);
21951
21952 unsigned long
21953-print_context_stack_bp(struct thread_info *tinfo,
21954+print_context_stack_bp(struct task_struct *task, void *stack_start,
21955 unsigned long *stack, unsigned long bp,
21956 const struct stacktrace_ops *ops, void *data,
21957 unsigned long *end, int *graph)
21958@@ -127,7 +126,7 @@ print_context_stack_bp(struct thread_info *tinfo,
21959 struct stack_frame *frame = (struct stack_frame *)bp;
21960 unsigned long *ret_addr = &frame->return_address;
21961
21962- while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
21963+ while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
21964 unsigned long addr = *ret_addr;
21965
21966 if (!__kernel_text_address(addr))
21967@@ -136,7 +135,7 @@ print_context_stack_bp(struct thread_info *tinfo,
21968 ops->address(data, addr, 1);
21969 frame = frame->next_frame;
21970 ret_addr = &frame->return_address;
21971- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
21972+ print_ftrace_graph_addr(addr, data, ops, task, graph);
21973 }
21974
21975 return (unsigned long)frame;
21976@@ -155,7 +154,7 @@ static int print_trace_stack(void *data, char *name)
21977 static void print_trace_address(void *data, unsigned long addr, int reliable)
21978 {
21979 touch_nmi_watchdog();
21980- printk(data);
21981+ printk("%s", (char *)data);
21982 printk_stack_address(addr, reliable);
21983 }
21984
21985@@ -225,6 +224,8 @@ unsigned long oops_begin(void)
21986 EXPORT_SYMBOL_GPL(oops_begin);
21987 NOKPROBE_SYMBOL(oops_begin);
21988
21989+extern void gr_handle_kernel_exploit(void);
21990+
21991 void oops_end(unsigned long flags, struct pt_regs *regs, int signr)
21992 {
21993 if (regs && kexec_should_crash(current))
21994@@ -246,7 +247,10 @@ void oops_end(unsigned long flags, struct pt_regs *regs, int signr)
21995 panic("Fatal exception in interrupt");
21996 if (panic_on_oops)
21997 panic("Fatal exception");
21998- do_exit(signr);
21999+
22000+ gr_handle_kernel_exploit();
22001+
22002+ do_group_exit(signr);
22003 }
22004 NOKPROBE_SYMBOL(oops_end);
22005
22006@@ -275,7 +279,7 @@ int __die(const char *str, struct pt_regs *regs, long err)
22007 print_modules();
22008 show_regs(regs);
22009 #ifdef CONFIG_X86_32
22010- if (user_mode_vm(regs)) {
22011+ if (user_mode(regs)) {
22012 sp = regs->sp;
22013 ss = regs->ss & 0xffff;
22014 } else {
22015@@ -304,7 +308,7 @@ void die(const char *str, struct pt_regs *regs, long err)
22016 unsigned long flags = oops_begin();
22017 int sig = SIGSEGV;
22018
22019- if (!user_mode_vm(regs))
22020+ if (!user_mode(regs))
22021 report_bug(regs->ip, regs);
22022
22023 if (__die(str, regs, err))
22024diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
22025index 5abd4cd..c65733b 100644
22026--- a/arch/x86/kernel/dumpstack_32.c
22027+++ b/arch/x86/kernel/dumpstack_32.c
22028@@ -61,15 +61,14 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22029 bp = stack_frame(task, regs);
22030
22031 for (;;) {
22032- struct thread_info *context;
22033+ void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
22034 void *end_stack;
22035
22036 end_stack = is_hardirq_stack(stack, cpu);
22037 if (!end_stack)
22038 end_stack = is_softirq_stack(stack, cpu);
22039
22040- context = task_thread_info(task);
22041- bp = ops->walk_stack(context, stack, bp, ops, data,
22042+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data,
22043 end_stack, &graph);
22044
22045 /* Stop if not on irq stack */
22046@@ -123,27 +122,28 @@ void show_regs(struct pt_regs *regs)
22047 int i;
22048
22049 show_regs_print_info(KERN_EMERG);
22050- __show_regs(regs, !user_mode_vm(regs));
22051+ __show_regs(regs, !user_mode(regs));
22052
22053 /*
22054 * When in-kernel, we also print out the stack and code at the
22055 * time of the fault..
22056 */
22057- if (!user_mode_vm(regs)) {
22058+ if (!user_mode(regs)) {
22059 unsigned int code_prologue = code_bytes * 43 / 64;
22060 unsigned int code_len = code_bytes;
22061 unsigned char c;
22062 u8 *ip;
22063+ unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(0)[(0xffff & regs->cs) >> 3]);
22064
22065 pr_emerg("Stack:\n");
22066 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
22067
22068 pr_emerg("Code:");
22069
22070- ip = (u8 *)regs->ip - code_prologue;
22071+ ip = (u8 *)regs->ip - code_prologue + cs_base;
22072 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
22073 /* try starting at IP */
22074- ip = (u8 *)regs->ip;
22075+ ip = (u8 *)regs->ip + cs_base;
22076 code_len = code_len - code_prologue + 1;
22077 }
22078 for (i = 0; i < code_len; i++, ip++) {
22079@@ -152,7 +152,7 @@ void show_regs(struct pt_regs *regs)
22080 pr_cont(" Bad EIP value.");
22081 break;
22082 }
22083- if (ip == (u8 *)regs->ip)
22084+ if (ip == (u8 *)regs->ip + cs_base)
22085 pr_cont(" <%02x>", c);
22086 else
22087 pr_cont(" %02x", c);
22088@@ -165,6 +165,7 @@ int is_valid_bugaddr(unsigned long ip)
22089 {
22090 unsigned short ud2;
22091
22092+ ip = ktla_ktva(ip);
22093 if (ip < PAGE_OFFSET)
22094 return 0;
22095 if (probe_kernel_address((unsigned short *)ip, ud2))
22096@@ -172,3 +173,15 @@ int is_valid_bugaddr(unsigned long ip)
22097
22098 return ud2 == 0x0b0f;
22099 }
22100+
22101+#if defined(CONFIG_PAX_MEMORY_STACKLEAK) || defined(CONFIG_PAX_USERCOPY)
22102+void pax_check_alloca(unsigned long size)
22103+{
22104+ unsigned long sp = (unsigned long)&sp, stack_left;
22105+
22106+ /* all kernel stacks are of the same size */
22107+ stack_left = sp & (THREAD_SIZE - 1);
22108+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
22109+}
22110+EXPORT_SYMBOL(pax_check_alloca);
22111+#endif
22112diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
22113index ff86f19..a20c62c 100644
22114--- a/arch/x86/kernel/dumpstack_64.c
22115+++ b/arch/x86/kernel/dumpstack_64.c
22116@@ -153,12 +153,12 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22117 const struct stacktrace_ops *ops, void *data)
22118 {
22119 const unsigned cpu = get_cpu();
22120- struct thread_info *tinfo;
22121 unsigned long *irq_stack = (unsigned long *)per_cpu(irq_stack_ptr, cpu);
22122 unsigned long dummy;
22123 unsigned used = 0;
22124 int graph = 0;
22125 int done = 0;
22126+ void *stack_start;
22127
22128 if (!task)
22129 task = current;
22130@@ -179,7 +179,6 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22131 * current stack address. If the stacks consist of nested
22132 * exceptions
22133 */
22134- tinfo = task_thread_info(task);
22135 while (!done) {
22136 unsigned long *stack_end;
22137 enum stack_type stype;
22138@@ -202,7 +201,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22139 if (ops->stack(data, id) < 0)
22140 break;
22141
22142- bp = ops->walk_stack(tinfo, stack, bp, ops,
22143+ bp = ops->walk_stack(task, stack_end - EXCEPTION_STKSZ, stack, bp, ops,
22144 data, stack_end, &graph);
22145 ops->stack(data, "<EOE>");
22146 /*
22147@@ -210,6 +209,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22148 * second-to-last pointer (index -2 to end) in the
22149 * exception stack:
22150 */
22151+ if ((u16)stack_end[-1] != __KERNEL_DS)
22152+ goto out;
22153 stack = (unsigned long *) stack_end[-2];
22154 done = 0;
22155 break;
22156@@ -218,7 +219,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22157
22158 if (ops->stack(data, "IRQ") < 0)
22159 break;
22160- bp = ops->walk_stack(tinfo, stack, bp,
22161+ bp = ops->walk_stack(task, irq_stack, stack, bp,
22162 ops, data, stack_end, &graph);
22163 /*
22164 * We link to the next stack (which would be
22165@@ -240,7 +241,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22166 /*
22167 * This handles the process stack:
22168 */
22169- bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
22170+ stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
22171+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
22172+out:
22173 put_cpu();
22174 }
22175 EXPORT_SYMBOL(dump_trace);
22176@@ -349,3 +352,50 @@ int is_valid_bugaddr(unsigned long ip)
22177
22178 return ud2 == 0x0b0f;
22179 }
22180+
22181+#if defined(CONFIG_PAX_MEMORY_STACKLEAK) || defined(CONFIG_PAX_USERCOPY)
22182+void pax_check_alloca(unsigned long size)
22183+{
22184+ unsigned long sp = (unsigned long)&sp, stack_start, stack_end;
22185+ unsigned cpu, used;
22186+ char *id;
22187+
22188+ /* check the process stack first */
22189+ stack_start = (unsigned long)task_stack_page(current);
22190+ stack_end = stack_start + THREAD_SIZE;
22191+ if (likely(stack_start <= sp && sp < stack_end)) {
22192+ unsigned long stack_left = sp & (THREAD_SIZE - 1);
22193+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
22194+ return;
22195+ }
22196+
22197+ cpu = get_cpu();
22198+
22199+ /* check the irq stacks */
22200+ stack_end = (unsigned long)per_cpu(irq_stack_ptr, cpu);
22201+ stack_start = stack_end - IRQ_STACK_SIZE;
22202+ if (stack_start <= sp && sp < stack_end) {
22203+ unsigned long stack_left = sp & (IRQ_STACK_SIZE - 1);
22204+ put_cpu();
22205+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
22206+ return;
22207+ }
22208+
22209+ /* check the exception stacks */
22210+ used = 0;
22211+ stack_end = (unsigned long)in_exception_stack(cpu, sp, &used, &id);
22212+ stack_start = stack_end - EXCEPTION_STKSZ;
22213+ if (stack_end && stack_start <= sp && sp < stack_end) {
22214+ unsigned long stack_left = sp & (EXCEPTION_STKSZ - 1);
22215+ put_cpu();
22216+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
22217+ return;
22218+ }
22219+
22220+ put_cpu();
22221+
22222+ /* unknown stack */
22223+ BUG();
22224+}
22225+EXPORT_SYMBOL(pax_check_alloca);
22226+#endif
22227diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c
22228index 49f8864..1cc6d07 100644
22229--- a/arch/x86/kernel/e820.c
22230+++ b/arch/x86/kernel/e820.c
22231@@ -802,8 +802,8 @@ unsigned long __init e820_end_of_low_ram_pfn(void)
22232
22233 static void early_panic(char *msg)
22234 {
22235- early_printk(msg);
22236- panic(msg);
22237+ early_printk("%s", msg);
22238+ panic("%s", msg);
22239 }
22240
22241 static int userdef __initdata;
22242diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
22243index 01d1c18..8073693 100644
22244--- a/arch/x86/kernel/early_printk.c
22245+++ b/arch/x86/kernel/early_printk.c
22246@@ -7,6 +7,7 @@
22247 #include <linux/pci_regs.h>
22248 #include <linux/pci_ids.h>
22249 #include <linux/errno.h>
22250+#include <linux/sched.h>
22251 #include <asm/io.h>
22252 #include <asm/processor.h>
22253 #include <asm/fcntl.h>
22254diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
22255index 344b63f..ccdac7a 100644
22256--- a/arch/x86/kernel/entry_32.S
22257+++ b/arch/x86/kernel/entry_32.S
22258@@ -177,13 +177,153 @@
22259 /*CFI_REL_OFFSET gs, PT_GS*/
22260 .endm
22261 .macro SET_KERNEL_GS reg
22262+
22263+#ifdef CONFIG_CC_STACKPROTECTOR
22264 movl $(__KERNEL_STACK_CANARY), \reg
22265+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
22266+ movl $(__USER_DS), \reg
22267+#else
22268+ xorl \reg, \reg
22269+#endif
22270+
22271 movl \reg, %gs
22272 .endm
22273
22274 #endif /* CONFIG_X86_32_LAZY_GS */
22275
22276-.macro SAVE_ALL
22277+.macro pax_enter_kernel
22278+#ifdef CONFIG_PAX_KERNEXEC
22279+ call pax_enter_kernel
22280+#endif
22281+.endm
22282+
22283+.macro pax_exit_kernel
22284+#ifdef CONFIG_PAX_KERNEXEC
22285+ call pax_exit_kernel
22286+#endif
22287+.endm
22288+
22289+#ifdef CONFIG_PAX_KERNEXEC
22290+ENTRY(pax_enter_kernel)
22291+#ifdef CONFIG_PARAVIRT
22292+ pushl %eax
22293+ pushl %ecx
22294+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
22295+ mov %eax, %esi
22296+#else
22297+ mov %cr0, %esi
22298+#endif
22299+ bts $16, %esi
22300+ jnc 1f
22301+ mov %cs, %esi
22302+ cmp $__KERNEL_CS, %esi
22303+ jz 3f
22304+ ljmp $__KERNEL_CS, $3f
22305+1: ljmp $__KERNEXEC_KERNEL_CS, $2f
22306+2:
22307+#ifdef CONFIG_PARAVIRT
22308+ mov %esi, %eax
22309+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
22310+#else
22311+ mov %esi, %cr0
22312+#endif
22313+3:
22314+#ifdef CONFIG_PARAVIRT
22315+ popl %ecx
22316+ popl %eax
22317+#endif
22318+ ret
22319+ENDPROC(pax_enter_kernel)
22320+
22321+ENTRY(pax_exit_kernel)
22322+#ifdef CONFIG_PARAVIRT
22323+ pushl %eax
22324+ pushl %ecx
22325+#endif
22326+ mov %cs, %esi
22327+ cmp $__KERNEXEC_KERNEL_CS, %esi
22328+ jnz 2f
22329+#ifdef CONFIG_PARAVIRT
22330+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
22331+ mov %eax, %esi
22332+#else
22333+ mov %cr0, %esi
22334+#endif
22335+ btr $16, %esi
22336+ ljmp $__KERNEL_CS, $1f
22337+1:
22338+#ifdef CONFIG_PARAVIRT
22339+ mov %esi, %eax
22340+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
22341+#else
22342+ mov %esi, %cr0
22343+#endif
22344+2:
22345+#ifdef CONFIG_PARAVIRT
22346+ popl %ecx
22347+ popl %eax
22348+#endif
22349+ ret
22350+ENDPROC(pax_exit_kernel)
22351+#endif
22352+
22353+ .macro pax_erase_kstack
22354+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
22355+ call pax_erase_kstack
22356+#endif
22357+ .endm
22358+
22359+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
22360+/*
22361+ * ebp: thread_info
22362+ */
22363+ENTRY(pax_erase_kstack)
22364+ pushl %edi
22365+ pushl %ecx
22366+ pushl %eax
22367+
22368+ mov TI_lowest_stack(%ebp), %edi
22369+ mov $-0xBEEF, %eax
22370+ std
22371+
22372+1: mov %edi, %ecx
22373+ and $THREAD_SIZE_asm - 1, %ecx
22374+ shr $2, %ecx
22375+ repne scasl
22376+ jecxz 2f
22377+
22378+ cmp $2*16, %ecx
22379+ jc 2f
22380+
22381+ mov $2*16, %ecx
22382+ repe scasl
22383+ jecxz 2f
22384+ jne 1b
22385+
22386+2: cld
22387+ mov %esp, %ecx
22388+ sub %edi, %ecx
22389+
22390+ cmp $THREAD_SIZE_asm, %ecx
22391+ jb 3f
22392+ ud2
22393+3:
22394+
22395+ shr $2, %ecx
22396+ rep stosl
22397+
22398+ mov TI_task_thread_sp0(%ebp), %edi
22399+ sub $128, %edi
22400+ mov %edi, TI_lowest_stack(%ebp)
22401+
22402+ popl %eax
22403+ popl %ecx
22404+ popl %edi
22405+ ret
22406+ENDPROC(pax_erase_kstack)
22407+#endif
22408+
22409+.macro __SAVE_ALL _DS
22410 cld
22411 PUSH_GS
22412 pushl_cfi %fs
22413@@ -206,7 +346,7 @@
22414 CFI_REL_OFFSET ecx, 0
22415 pushl_cfi %ebx
22416 CFI_REL_OFFSET ebx, 0
22417- movl $(__USER_DS), %edx
22418+ movl $\_DS, %edx
22419 movl %edx, %ds
22420 movl %edx, %es
22421 movl $(__KERNEL_PERCPU), %edx
22422@@ -214,6 +354,15 @@
22423 SET_KERNEL_GS %edx
22424 .endm
22425
22426+.macro SAVE_ALL
22427+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
22428+ __SAVE_ALL __KERNEL_DS
22429+ pax_enter_kernel
22430+#else
22431+ __SAVE_ALL __USER_DS
22432+#endif
22433+.endm
22434+
22435 .macro RESTORE_INT_REGS
22436 popl_cfi %ebx
22437 CFI_RESTORE ebx
22438@@ -297,7 +446,7 @@ ENTRY(ret_from_fork)
22439 popfl_cfi
22440 jmp syscall_exit
22441 CFI_ENDPROC
22442-END(ret_from_fork)
22443+ENDPROC(ret_from_fork)
22444
22445 ENTRY(ret_from_kernel_thread)
22446 CFI_STARTPROC
22447@@ -340,7 +489,15 @@ ret_from_intr:
22448 andl $SEGMENT_RPL_MASK, %eax
22449 #endif
22450 cmpl $USER_RPL, %eax
22451+
22452+#ifdef CONFIG_PAX_KERNEXEC
22453+ jae resume_userspace
22454+
22455+ pax_exit_kernel
22456+ jmp resume_kernel
22457+#else
22458 jb resume_kernel # not returning to v8086 or userspace
22459+#endif
22460
22461 ENTRY(resume_userspace)
22462 LOCKDEP_SYS_EXIT
22463@@ -352,8 +509,8 @@ ENTRY(resume_userspace)
22464 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
22465 # int/exception return?
22466 jne work_pending
22467- jmp restore_all
22468-END(ret_from_exception)
22469+ jmp restore_all_pax
22470+ENDPROC(ret_from_exception)
22471
22472 #ifdef CONFIG_PREEMPT
22473 ENTRY(resume_kernel)
22474@@ -365,7 +522,7 @@ need_resched:
22475 jz restore_all
22476 call preempt_schedule_irq
22477 jmp need_resched
22478-END(resume_kernel)
22479+ENDPROC(resume_kernel)
22480 #endif
22481 CFI_ENDPROC
22482
22483@@ -395,30 +552,45 @@ sysenter_past_esp:
22484 /*CFI_REL_OFFSET cs, 0*/
22485 /*
22486 * Push current_thread_info()->sysenter_return to the stack.
22487- * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
22488- * pushed above; +8 corresponds to copy_thread's esp0 setting.
22489 */
22490- pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
22491+ pushl_cfi $0
22492 CFI_REL_OFFSET eip, 0
22493
22494 pushl_cfi %eax
22495 SAVE_ALL
22496+ GET_THREAD_INFO(%ebp)
22497+ movl TI_sysenter_return(%ebp),%ebp
22498+ movl %ebp,PT_EIP(%esp)
22499 ENABLE_INTERRUPTS(CLBR_NONE)
22500
22501 /*
22502 * Load the potential sixth argument from user stack.
22503 * Careful about security.
22504 */
22505+ movl PT_OLDESP(%esp),%ebp
22506+
22507+#ifdef CONFIG_PAX_MEMORY_UDEREF
22508+ mov PT_OLDSS(%esp),%ds
22509+1: movl %ds:(%ebp),%ebp
22510+ push %ss
22511+ pop %ds
22512+#else
22513 cmpl $__PAGE_OFFSET-3,%ebp
22514 jae syscall_fault
22515 ASM_STAC
22516 1: movl (%ebp),%ebp
22517 ASM_CLAC
22518+#endif
22519+
22520 movl %ebp,PT_EBP(%esp)
22521 _ASM_EXTABLE(1b,syscall_fault)
22522
22523 GET_THREAD_INFO(%ebp)
22524
22525+#ifdef CONFIG_PAX_RANDKSTACK
22526+ pax_erase_kstack
22527+#endif
22528+
22529 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
22530 jnz sysenter_audit
22531 sysenter_do_call:
22532@@ -434,12 +606,24 @@ sysenter_after_call:
22533 testl $_TIF_ALLWORK_MASK, %ecx
22534 jne sysexit_audit
22535 sysenter_exit:
22536+
22537+#ifdef CONFIG_PAX_RANDKSTACK
22538+ pushl_cfi %eax
22539+ movl %esp, %eax
22540+ call pax_randomize_kstack
22541+ popl_cfi %eax
22542+#endif
22543+
22544+ pax_erase_kstack
22545+
22546 /* if something modifies registers it must also disable sysexit */
22547 movl PT_EIP(%esp), %edx
22548 movl PT_OLDESP(%esp), %ecx
22549 xorl %ebp,%ebp
22550 TRACE_IRQS_ON
22551 1: mov PT_FS(%esp), %fs
22552+2: mov PT_DS(%esp), %ds
22553+3: mov PT_ES(%esp), %es
22554 PTGS_TO_GS
22555 ENABLE_INTERRUPTS_SYSEXIT
22556
22557@@ -453,6 +637,9 @@ sysenter_audit:
22558 pushl_cfi PT_ESI(%esp) /* a3: 5th arg */
22559 pushl_cfi PT_EDX+4(%esp) /* a2: 4th arg */
22560 call __audit_syscall_entry
22561+
22562+ pax_erase_kstack
22563+
22564 popl_cfi %ecx /* get that remapped edx off the stack */
22565 popl_cfi %ecx /* get that remapped esi off the stack */
22566 movl PT_EAX(%esp),%eax /* reload syscall number */
22567@@ -479,10 +666,16 @@ sysexit_audit:
22568
22569 CFI_ENDPROC
22570 .pushsection .fixup,"ax"
22571-2: movl $0,PT_FS(%esp)
22572+4: movl $0,PT_FS(%esp)
22573+ jmp 1b
22574+5: movl $0,PT_DS(%esp)
22575+ jmp 1b
22576+6: movl $0,PT_ES(%esp)
22577 jmp 1b
22578 .popsection
22579- _ASM_EXTABLE(1b,2b)
22580+ _ASM_EXTABLE(1b,4b)
22581+ _ASM_EXTABLE(2b,5b)
22582+ _ASM_EXTABLE(3b,6b)
22583 PTGS_TO_GS_EX
22584 ENDPROC(ia32_sysenter_target)
22585
22586@@ -493,6 +686,11 @@ ENTRY(system_call)
22587 pushl_cfi %eax # save orig_eax
22588 SAVE_ALL
22589 GET_THREAD_INFO(%ebp)
22590+
22591+#ifdef CONFIG_PAX_RANDKSTACK
22592+ pax_erase_kstack
22593+#endif
22594+
22595 # system call tracing in operation / emulation
22596 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
22597 jnz syscall_trace_entry
22598@@ -512,6 +710,15 @@ syscall_exit:
22599 testl $_TIF_ALLWORK_MASK, %ecx # current->work
22600 jne syscall_exit_work
22601
22602+restore_all_pax:
22603+
22604+#ifdef CONFIG_PAX_RANDKSTACK
22605+ movl %esp, %eax
22606+ call pax_randomize_kstack
22607+#endif
22608+
22609+ pax_erase_kstack
22610+
22611 restore_all:
22612 TRACE_IRQS_IRET
22613 restore_all_notrace:
22614@@ -566,14 +773,34 @@ ldt_ss:
22615 * compensating for the offset by changing to the ESPFIX segment with
22616 * a base address that matches for the difference.
22617 */
22618-#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
22619+#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
22620 mov %esp, %edx /* load kernel esp */
22621 mov PT_OLDESP(%esp), %eax /* load userspace esp */
22622 mov %dx, %ax /* eax: new kernel esp */
22623 sub %eax, %edx /* offset (low word is 0) */
22624+#ifdef CONFIG_SMP
22625+ movl PER_CPU_VAR(cpu_number), %ebx
22626+ shll $PAGE_SHIFT_asm, %ebx
22627+ addl $cpu_gdt_table, %ebx
22628+#else
22629+ movl $cpu_gdt_table, %ebx
22630+#endif
22631 shr $16, %edx
22632- mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
22633- mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
22634+
22635+#ifdef CONFIG_PAX_KERNEXEC
22636+ mov %cr0, %esi
22637+ btr $16, %esi
22638+ mov %esi, %cr0
22639+#endif
22640+
22641+ mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
22642+ mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
22643+
22644+#ifdef CONFIG_PAX_KERNEXEC
22645+ bts $16, %esi
22646+ mov %esi, %cr0
22647+#endif
22648+
22649 pushl_cfi $__ESPFIX_SS
22650 pushl_cfi %eax /* new kernel esp */
22651 /* Disable interrupts, but do not irqtrace this section: we
22652@@ -603,20 +830,18 @@ work_resched:
22653 movl TI_flags(%ebp), %ecx
22654 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
22655 # than syscall tracing?
22656- jz restore_all
22657+ jz restore_all_pax
22658 testb $_TIF_NEED_RESCHED, %cl
22659 jnz work_resched
22660
22661 work_notifysig: # deal with pending signals and
22662 # notify-resume requests
22663+ movl %esp, %eax
22664 #ifdef CONFIG_VM86
22665 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
22666- movl %esp, %eax
22667 jne work_notifysig_v86 # returning to kernel-space or
22668 # vm86-space
22669 1:
22670-#else
22671- movl %esp, %eax
22672 #endif
22673 TRACE_IRQS_ON
22674 ENABLE_INTERRUPTS(CLBR_NONE)
22675@@ -637,7 +862,7 @@ work_notifysig_v86:
22676 movl %eax, %esp
22677 jmp 1b
22678 #endif
22679-END(work_pending)
22680+ENDPROC(work_pending)
22681
22682 # perform syscall exit tracing
22683 ALIGN
22684@@ -645,11 +870,14 @@ syscall_trace_entry:
22685 movl $-ENOSYS,PT_EAX(%esp)
22686 movl %esp, %eax
22687 call syscall_trace_enter
22688+
22689+ pax_erase_kstack
22690+
22691 /* What it returned is what we'll actually use. */
22692 cmpl $(NR_syscalls), %eax
22693 jnae syscall_call
22694 jmp syscall_exit
22695-END(syscall_trace_entry)
22696+ENDPROC(syscall_trace_entry)
22697
22698 # perform syscall exit tracing
22699 ALIGN
22700@@ -662,26 +890,30 @@ syscall_exit_work:
22701 movl %esp, %eax
22702 call syscall_trace_leave
22703 jmp resume_userspace
22704-END(syscall_exit_work)
22705+ENDPROC(syscall_exit_work)
22706 CFI_ENDPROC
22707
22708 RING0_INT_FRAME # can't unwind into user space anyway
22709 syscall_fault:
22710+#ifdef CONFIG_PAX_MEMORY_UDEREF
22711+ push %ss
22712+ pop %ds
22713+#endif
22714 ASM_CLAC
22715 GET_THREAD_INFO(%ebp)
22716 movl $-EFAULT,PT_EAX(%esp)
22717 jmp resume_userspace
22718-END(syscall_fault)
22719+ENDPROC(syscall_fault)
22720
22721 syscall_badsys:
22722 movl $-ENOSYS,%eax
22723 jmp syscall_after_call
22724-END(syscall_badsys)
22725+ENDPROC(syscall_badsys)
22726
22727 sysenter_badsys:
22728 movl $-ENOSYS,%eax
22729 jmp sysenter_after_call
22730-END(sysenter_badsys)
22731+ENDPROC(sysenter_badsys)
22732 CFI_ENDPROC
22733
22734 .macro FIXUP_ESPFIX_STACK
22735@@ -694,8 +926,15 @@ END(sysenter_badsys)
22736 */
22737 #ifdef CONFIG_X86_ESPFIX32
22738 /* fixup the stack */
22739- mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
22740- mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
22741+#ifdef CONFIG_SMP
22742+ movl PER_CPU_VAR(cpu_number), %ebx
22743+ shll $PAGE_SHIFT_asm, %ebx
22744+ addl $cpu_gdt_table, %ebx
22745+#else
22746+ movl $cpu_gdt_table, %ebx
22747+#endif
22748+ mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
22749+ mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
22750 shl $16, %eax
22751 addl %esp, %eax /* the adjusted stack pointer */
22752 pushl_cfi $__KERNEL_DS
22753@@ -751,7 +990,7 @@ vector=vector+1
22754 .endr
22755 2: jmp common_interrupt
22756 .endr
22757-END(irq_entries_start)
22758+ENDPROC(irq_entries_start)
22759
22760 .previous
22761 END(interrupt)
22762@@ -808,7 +1047,7 @@ ENTRY(coprocessor_error)
22763 pushl_cfi $do_coprocessor_error
22764 jmp error_code
22765 CFI_ENDPROC
22766-END(coprocessor_error)
22767+ENDPROC(coprocessor_error)
22768
22769 ENTRY(simd_coprocessor_error)
22770 RING0_INT_FRAME
22771@@ -821,7 +1060,7 @@ ENTRY(simd_coprocessor_error)
22772 .section .altinstructions,"a"
22773 altinstruction_entry 661b, 663f, X86_FEATURE_XMM, 662b-661b, 664f-663f
22774 .previous
22775-.section .altinstr_replacement,"ax"
22776+.section .altinstr_replacement,"a"
22777 663: pushl $do_simd_coprocessor_error
22778 664:
22779 .previous
22780@@ -830,7 +1069,7 @@ ENTRY(simd_coprocessor_error)
22781 #endif
22782 jmp error_code
22783 CFI_ENDPROC
22784-END(simd_coprocessor_error)
22785+ENDPROC(simd_coprocessor_error)
22786
22787 ENTRY(device_not_available)
22788 RING0_INT_FRAME
22789@@ -839,18 +1078,18 @@ ENTRY(device_not_available)
22790 pushl_cfi $do_device_not_available
22791 jmp error_code
22792 CFI_ENDPROC
22793-END(device_not_available)
22794+ENDPROC(device_not_available)
22795
22796 #ifdef CONFIG_PARAVIRT
22797 ENTRY(native_iret)
22798 iret
22799 _ASM_EXTABLE(native_iret, iret_exc)
22800-END(native_iret)
22801+ENDPROC(native_iret)
22802
22803 ENTRY(native_irq_enable_sysexit)
22804 sti
22805 sysexit
22806-END(native_irq_enable_sysexit)
22807+ENDPROC(native_irq_enable_sysexit)
22808 #endif
22809
22810 ENTRY(overflow)
22811@@ -860,7 +1099,7 @@ ENTRY(overflow)
22812 pushl_cfi $do_overflow
22813 jmp error_code
22814 CFI_ENDPROC
22815-END(overflow)
22816+ENDPROC(overflow)
22817
22818 ENTRY(bounds)
22819 RING0_INT_FRAME
22820@@ -869,7 +1108,7 @@ ENTRY(bounds)
22821 pushl_cfi $do_bounds
22822 jmp error_code
22823 CFI_ENDPROC
22824-END(bounds)
22825+ENDPROC(bounds)
22826
22827 ENTRY(invalid_op)
22828 RING0_INT_FRAME
22829@@ -878,7 +1117,7 @@ ENTRY(invalid_op)
22830 pushl_cfi $do_invalid_op
22831 jmp error_code
22832 CFI_ENDPROC
22833-END(invalid_op)
22834+ENDPROC(invalid_op)
22835
22836 ENTRY(coprocessor_segment_overrun)
22837 RING0_INT_FRAME
22838@@ -887,7 +1126,7 @@ ENTRY(coprocessor_segment_overrun)
22839 pushl_cfi $do_coprocessor_segment_overrun
22840 jmp error_code
22841 CFI_ENDPROC
22842-END(coprocessor_segment_overrun)
22843+ENDPROC(coprocessor_segment_overrun)
22844
22845 ENTRY(invalid_TSS)
22846 RING0_EC_FRAME
22847@@ -895,7 +1134,7 @@ ENTRY(invalid_TSS)
22848 pushl_cfi $do_invalid_TSS
22849 jmp error_code
22850 CFI_ENDPROC
22851-END(invalid_TSS)
22852+ENDPROC(invalid_TSS)
22853
22854 ENTRY(segment_not_present)
22855 RING0_EC_FRAME
22856@@ -903,7 +1142,7 @@ ENTRY(segment_not_present)
22857 pushl_cfi $do_segment_not_present
22858 jmp error_code
22859 CFI_ENDPROC
22860-END(segment_not_present)
22861+ENDPROC(segment_not_present)
22862
22863 ENTRY(stack_segment)
22864 RING0_EC_FRAME
22865@@ -911,7 +1150,7 @@ ENTRY(stack_segment)
22866 pushl_cfi $do_stack_segment
22867 jmp error_code
22868 CFI_ENDPROC
22869-END(stack_segment)
22870+ENDPROC(stack_segment)
22871
22872 ENTRY(alignment_check)
22873 RING0_EC_FRAME
22874@@ -919,7 +1158,7 @@ ENTRY(alignment_check)
22875 pushl_cfi $do_alignment_check
22876 jmp error_code
22877 CFI_ENDPROC
22878-END(alignment_check)
22879+ENDPROC(alignment_check)
22880
22881 ENTRY(divide_error)
22882 RING0_INT_FRAME
22883@@ -928,7 +1167,7 @@ ENTRY(divide_error)
22884 pushl_cfi $do_divide_error
22885 jmp error_code
22886 CFI_ENDPROC
22887-END(divide_error)
22888+ENDPROC(divide_error)
22889
22890 #ifdef CONFIG_X86_MCE
22891 ENTRY(machine_check)
22892@@ -938,7 +1177,7 @@ ENTRY(machine_check)
22893 pushl_cfi machine_check_vector
22894 jmp error_code
22895 CFI_ENDPROC
22896-END(machine_check)
22897+ENDPROC(machine_check)
22898 #endif
22899
22900 ENTRY(spurious_interrupt_bug)
22901@@ -948,7 +1187,7 @@ ENTRY(spurious_interrupt_bug)
22902 pushl_cfi $do_spurious_interrupt_bug
22903 jmp error_code
22904 CFI_ENDPROC
22905-END(spurious_interrupt_bug)
22906+ENDPROC(spurious_interrupt_bug)
22907
22908 #ifdef CONFIG_XEN
22909 /* Xen doesn't set %esp to be precisely what the normal sysenter
22910@@ -1054,7 +1293,7 @@ BUILD_INTERRUPT3(hyperv_callback_vector, HYPERVISOR_CALLBACK_VECTOR,
22911
22912 ENTRY(mcount)
22913 ret
22914-END(mcount)
22915+ENDPROC(mcount)
22916
22917 ENTRY(ftrace_caller)
22918 pushl %eax
22919@@ -1084,7 +1323,7 @@ ftrace_graph_call:
22920 .globl ftrace_stub
22921 ftrace_stub:
22922 ret
22923-END(ftrace_caller)
22924+ENDPROC(ftrace_caller)
22925
22926 ENTRY(ftrace_regs_caller)
22927 pushf /* push flags before compare (in cs location) */
22928@@ -1182,7 +1421,7 @@ trace:
22929 popl %ecx
22930 popl %eax
22931 jmp ftrace_stub
22932-END(mcount)
22933+ENDPROC(mcount)
22934 #endif /* CONFIG_DYNAMIC_FTRACE */
22935 #endif /* CONFIG_FUNCTION_TRACER */
22936
22937@@ -1200,7 +1439,7 @@ ENTRY(ftrace_graph_caller)
22938 popl %ecx
22939 popl %eax
22940 ret
22941-END(ftrace_graph_caller)
22942+ENDPROC(ftrace_graph_caller)
22943
22944 .globl return_to_handler
22945 return_to_handler:
22946@@ -1261,15 +1500,18 @@ error_code:
22947 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
22948 REG_TO_PTGS %ecx
22949 SET_KERNEL_GS %ecx
22950- movl $(__USER_DS), %ecx
22951+ movl $(__KERNEL_DS), %ecx
22952 movl %ecx, %ds
22953 movl %ecx, %es
22954+
22955+ pax_enter_kernel
22956+
22957 TRACE_IRQS_OFF
22958 movl %esp,%eax # pt_regs pointer
22959 call *%edi
22960 jmp ret_from_exception
22961 CFI_ENDPROC
22962-END(page_fault)
22963+ENDPROC(page_fault)
22964
22965 /*
22966 * Debug traps and NMI can happen at the one SYSENTER instruction
22967@@ -1312,7 +1554,7 @@ debug_stack_correct:
22968 call do_debug
22969 jmp ret_from_exception
22970 CFI_ENDPROC
22971-END(debug)
22972+ENDPROC(debug)
22973
22974 /*
22975 * NMI is doubly nasty. It can happen _while_ we're handling
22976@@ -1352,6 +1594,9 @@ nmi_stack_correct:
22977 xorl %edx,%edx # zero error code
22978 movl %esp,%eax # pt_regs pointer
22979 call do_nmi
22980+
22981+ pax_exit_kernel
22982+
22983 jmp restore_all_notrace
22984 CFI_ENDPROC
22985
22986@@ -1389,13 +1634,16 @@ nmi_espfix_stack:
22987 FIXUP_ESPFIX_STACK # %eax == %esp
22988 xorl %edx,%edx # zero error code
22989 call do_nmi
22990+
22991+ pax_exit_kernel
22992+
22993 RESTORE_REGS
22994 lss 12+4(%esp), %esp # back to espfix stack
22995 CFI_ADJUST_CFA_OFFSET -24
22996 jmp irq_return
22997 #endif
22998 CFI_ENDPROC
22999-END(nmi)
23000+ENDPROC(nmi)
23001
23002 ENTRY(int3)
23003 RING0_INT_FRAME
23004@@ -1408,14 +1656,14 @@ ENTRY(int3)
23005 call do_int3
23006 jmp ret_from_exception
23007 CFI_ENDPROC
23008-END(int3)
23009+ENDPROC(int3)
23010
23011 ENTRY(general_protection)
23012 RING0_EC_FRAME
23013 pushl_cfi $do_general_protection
23014 jmp error_code
23015 CFI_ENDPROC
23016-END(general_protection)
23017+ENDPROC(general_protection)
23018
23019 #ifdef CONFIG_KVM_GUEST
23020 ENTRY(async_page_fault)
23021@@ -1424,6 +1672,6 @@ ENTRY(async_page_fault)
23022 pushl_cfi $do_async_page_fault
23023 jmp error_code
23024 CFI_ENDPROC
23025-END(async_page_fault)
23026+ENDPROC(async_page_fault)
23027 #endif
23028
23029diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
23030index c0226ab..96a8ab7 100644
23031--- a/arch/x86/kernel/entry_64.S
23032+++ b/arch/x86/kernel/entry_64.S
23033@@ -59,6 +59,8 @@
23034 #include <asm/smap.h>
23035 #include <asm/pgtable_types.h>
23036 #include <linux/err.h>
23037+#include <asm/pgtable.h>
23038+#include <asm/alternative-asm.h>
23039
23040 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
23041 #include <linux/elf-em.h>
23042@@ -81,6 +83,430 @@ ENTRY(native_usergs_sysret64)
23043 ENDPROC(native_usergs_sysret64)
23044 #endif /* CONFIG_PARAVIRT */
23045
23046+ .macro ljmpq sel, off
23047+#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
23048+ .byte 0x48; ljmp *1234f(%rip)
23049+ .pushsection .rodata
23050+ .align 16
23051+ 1234: .quad \off; .word \sel
23052+ .popsection
23053+#else
23054+ pushq $\sel
23055+ pushq $\off
23056+ lretq
23057+#endif
23058+ .endm
23059+
23060+ .macro pax_enter_kernel
23061+ pax_set_fptr_mask
23062+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
23063+ call pax_enter_kernel
23064+#endif
23065+ .endm
23066+
23067+ .macro pax_exit_kernel
23068+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
23069+ call pax_exit_kernel
23070+#endif
23071+
23072+ .endm
23073+
23074+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
23075+ENTRY(pax_enter_kernel)
23076+ pushq %rdi
23077+
23078+#ifdef CONFIG_PARAVIRT
23079+ PV_SAVE_REGS(CLBR_RDI)
23080+#endif
23081+
23082+#ifdef CONFIG_PAX_KERNEXEC
23083+ GET_CR0_INTO_RDI
23084+ bts $16,%rdi
23085+ jnc 3f
23086+ mov %cs,%edi
23087+ cmp $__KERNEL_CS,%edi
23088+ jnz 2f
23089+1:
23090+#endif
23091+
23092+#ifdef CONFIG_PAX_MEMORY_UDEREF
23093+ 661: jmp 111f
23094+ .pushsection .altinstr_replacement, "a"
23095+ 662: ASM_NOP2
23096+ .popsection
23097+ .pushsection .altinstructions, "a"
23098+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23099+ .popsection
23100+ GET_CR3_INTO_RDI
23101+ cmp $0,%dil
23102+ jnz 112f
23103+ mov $__KERNEL_DS,%edi
23104+ mov %edi,%ss
23105+ jmp 111f
23106+112: cmp $1,%dil
23107+ jz 113f
23108+ ud2
23109+113: sub $4097,%rdi
23110+ bts $63,%rdi
23111+ SET_RDI_INTO_CR3
23112+ mov $__UDEREF_KERNEL_DS,%edi
23113+ mov %edi,%ss
23114+111:
23115+#endif
23116+
23117+#ifdef CONFIG_PARAVIRT
23118+ PV_RESTORE_REGS(CLBR_RDI)
23119+#endif
23120+
23121+ popq %rdi
23122+ pax_force_retaddr
23123+ retq
23124+
23125+#ifdef CONFIG_PAX_KERNEXEC
23126+2: ljmpq __KERNEL_CS,1b
23127+3: ljmpq __KERNEXEC_KERNEL_CS,4f
23128+4: SET_RDI_INTO_CR0
23129+ jmp 1b
23130+#endif
23131+ENDPROC(pax_enter_kernel)
23132+
23133+ENTRY(pax_exit_kernel)
23134+ pushq %rdi
23135+
23136+#ifdef CONFIG_PARAVIRT
23137+ PV_SAVE_REGS(CLBR_RDI)
23138+#endif
23139+
23140+#ifdef CONFIG_PAX_KERNEXEC
23141+ mov %cs,%rdi
23142+ cmp $__KERNEXEC_KERNEL_CS,%edi
23143+ jz 2f
23144+ GET_CR0_INTO_RDI
23145+ bts $16,%rdi
23146+ jnc 4f
23147+1:
23148+#endif
23149+
23150+#ifdef CONFIG_PAX_MEMORY_UDEREF
23151+ 661: jmp 111f
23152+ .pushsection .altinstr_replacement, "a"
23153+ 662: ASM_NOP2
23154+ .popsection
23155+ .pushsection .altinstructions, "a"
23156+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23157+ .popsection
23158+ mov %ss,%edi
23159+ cmp $__UDEREF_KERNEL_DS,%edi
23160+ jnz 111f
23161+ GET_CR3_INTO_RDI
23162+ cmp $0,%dil
23163+ jz 112f
23164+ ud2
23165+112: add $4097,%rdi
23166+ bts $63,%rdi
23167+ SET_RDI_INTO_CR3
23168+ mov $__KERNEL_DS,%edi
23169+ mov %edi,%ss
23170+111:
23171+#endif
23172+
23173+#ifdef CONFIG_PARAVIRT
23174+ PV_RESTORE_REGS(CLBR_RDI);
23175+#endif
23176+
23177+ popq %rdi
23178+ pax_force_retaddr
23179+ retq
23180+
23181+#ifdef CONFIG_PAX_KERNEXEC
23182+2: GET_CR0_INTO_RDI
23183+ btr $16,%rdi
23184+ jnc 4f
23185+ ljmpq __KERNEL_CS,3f
23186+3: SET_RDI_INTO_CR0
23187+ jmp 1b
23188+4: ud2
23189+ jmp 4b
23190+#endif
23191+ENDPROC(pax_exit_kernel)
23192+#endif
23193+
23194+ .macro pax_enter_kernel_user
23195+ pax_set_fptr_mask
23196+#ifdef CONFIG_PAX_MEMORY_UDEREF
23197+ call pax_enter_kernel_user
23198+#endif
23199+ .endm
23200+
23201+ .macro pax_exit_kernel_user
23202+#ifdef CONFIG_PAX_MEMORY_UDEREF
23203+ call pax_exit_kernel_user
23204+#endif
23205+#ifdef CONFIG_PAX_RANDKSTACK
23206+ pushq %rax
23207+ pushq %r11
23208+ call pax_randomize_kstack
23209+ popq %r11
23210+ popq %rax
23211+#endif
23212+ .endm
23213+
23214+#ifdef CONFIG_PAX_MEMORY_UDEREF
23215+ENTRY(pax_enter_kernel_user)
23216+ pushq %rdi
23217+ pushq %rbx
23218+
23219+#ifdef CONFIG_PARAVIRT
23220+ PV_SAVE_REGS(CLBR_RDI)
23221+#endif
23222+
23223+ 661: jmp 111f
23224+ .pushsection .altinstr_replacement, "a"
23225+ 662: ASM_NOP2
23226+ .popsection
23227+ .pushsection .altinstructions, "a"
23228+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23229+ .popsection
23230+ GET_CR3_INTO_RDI
23231+ cmp $1,%dil
23232+ jnz 4f
23233+ sub $4097,%rdi
23234+ bts $63,%rdi
23235+ SET_RDI_INTO_CR3
23236+ jmp 3f
23237+111:
23238+
23239+ GET_CR3_INTO_RDI
23240+ mov %rdi,%rbx
23241+ add $__START_KERNEL_map,%rbx
23242+ sub phys_base(%rip),%rbx
23243+
23244+#ifdef CONFIG_PARAVIRT
23245+ cmpl $0, pv_info+PARAVIRT_enabled
23246+ jz 1f
23247+ pushq %rdi
23248+ i = 0
23249+ .rept USER_PGD_PTRS
23250+ mov i*8(%rbx),%rsi
23251+ mov $0,%sil
23252+ lea i*8(%rbx),%rdi
23253+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
23254+ i = i + 1
23255+ .endr
23256+ popq %rdi
23257+ jmp 2f
23258+1:
23259+#endif
23260+
23261+ i = 0
23262+ .rept USER_PGD_PTRS
23263+ movb $0,i*8(%rbx)
23264+ i = i + 1
23265+ .endr
23266+
23267+2: SET_RDI_INTO_CR3
23268+
23269+#ifdef CONFIG_PAX_KERNEXEC
23270+ GET_CR0_INTO_RDI
23271+ bts $16,%rdi
23272+ SET_RDI_INTO_CR0
23273+#endif
23274+
23275+3:
23276+
23277+#ifdef CONFIG_PARAVIRT
23278+ PV_RESTORE_REGS(CLBR_RDI)
23279+#endif
23280+
23281+ popq %rbx
23282+ popq %rdi
23283+ pax_force_retaddr
23284+ retq
23285+4: ud2
23286+ENDPROC(pax_enter_kernel_user)
23287+
23288+ENTRY(pax_exit_kernel_user)
23289+ pushq %rdi
23290+ pushq %rbx
23291+
23292+#ifdef CONFIG_PARAVIRT
23293+ PV_SAVE_REGS(CLBR_RDI)
23294+#endif
23295+
23296+ GET_CR3_INTO_RDI
23297+ 661: jmp 1f
23298+ .pushsection .altinstr_replacement, "a"
23299+ 662: ASM_NOP2
23300+ .popsection
23301+ .pushsection .altinstructions, "a"
23302+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23303+ .popsection
23304+ cmp $0,%dil
23305+ jnz 3f
23306+ add $4097,%rdi
23307+ bts $63,%rdi
23308+ SET_RDI_INTO_CR3
23309+ jmp 2f
23310+1:
23311+
23312+ mov %rdi,%rbx
23313+
23314+#ifdef CONFIG_PAX_KERNEXEC
23315+ GET_CR0_INTO_RDI
23316+ btr $16,%rdi
23317+ jnc 3f
23318+ SET_RDI_INTO_CR0
23319+#endif
23320+
23321+ add $__START_KERNEL_map,%rbx
23322+ sub phys_base(%rip),%rbx
23323+
23324+#ifdef CONFIG_PARAVIRT
23325+ cmpl $0, pv_info+PARAVIRT_enabled
23326+ jz 1f
23327+ i = 0
23328+ .rept USER_PGD_PTRS
23329+ mov i*8(%rbx),%rsi
23330+ mov $0x67,%sil
23331+ lea i*8(%rbx),%rdi
23332+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
23333+ i = i + 1
23334+ .endr
23335+ jmp 2f
23336+1:
23337+#endif
23338+
23339+ i = 0
23340+ .rept USER_PGD_PTRS
23341+ movb $0x67,i*8(%rbx)
23342+ i = i + 1
23343+ .endr
23344+2:
23345+
23346+#ifdef CONFIG_PARAVIRT
23347+ PV_RESTORE_REGS(CLBR_RDI)
23348+#endif
23349+
23350+ popq %rbx
23351+ popq %rdi
23352+ pax_force_retaddr
23353+ retq
23354+3: ud2
23355+ENDPROC(pax_exit_kernel_user)
23356+#endif
23357+
23358+ .macro pax_enter_kernel_nmi
23359+ pax_set_fptr_mask
23360+
23361+#ifdef CONFIG_PAX_KERNEXEC
23362+ GET_CR0_INTO_RDI
23363+ bts $16,%rdi
23364+ jc 110f
23365+ SET_RDI_INTO_CR0
23366+ or $2,%ebx
23367+110:
23368+#endif
23369+
23370+#ifdef CONFIG_PAX_MEMORY_UDEREF
23371+ 661: jmp 111f
23372+ .pushsection .altinstr_replacement, "a"
23373+ 662: ASM_NOP2
23374+ .popsection
23375+ .pushsection .altinstructions, "a"
23376+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23377+ .popsection
23378+ GET_CR3_INTO_RDI
23379+ cmp $0,%dil
23380+ jz 111f
23381+ sub $4097,%rdi
23382+ or $4,%ebx
23383+ bts $63,%rdi
23384+ SET_RDI_INTO_CR3
23385+ mov $__UDEREF_KERNEL_DS,%edi
23386+ mov %edi,%ss
23387+111:
23388+#endif
23389+ .endm
23390+
23391+ .macro pax_exit_kernel_nmi
23392+#ifdef CONFIG_PAX_KERNEXEC
23393+ btr $1,%ebx
23394+ jnc 110f
23395+ GET_CR0_INTO_RDI
23396+ btr $16,%rdi
23397+ SET_RDI_INTO_CR0
23398+110:
23399+#endif
23400+
23401+#ifdef CONFIG_PAX_MEMORY_UDEREF
23402+ btr $2,%ebx
23403+ jnc 111f
23404+ GET_CR3_INTO_RDI
23405+ add $4097,%rdi
23406+ bts $63,%rdi
23407+ SET_RDI_INTO_CR3
23408+ mov $__KERNEL_DS,%edi
23409+ mov %edi,%ss
23410+111:
23411+#endif
23412+ .endm
23413+
23414+ .macro pax_erase_kstack
23415+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
23416+ call pax_erase_kstack
23417+#endif
23418+ .endm
23419+
23420+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
23421+ENTRY(pax_erase_kstack)
23422+ pushq %rdi
23423+ pushq %rcx
23424+ pushq %rax
23425+ pushq %r11
23426+
23427+ GET_THREAD_INFO(%r11)
23428+ mov TI_lowest_stack(%r11), %rdi
23429+ mov $-0xBEEF, %rax
23430+ std
23431+
23432+1: mov %edi, %ecx
23433+ and $THREAD_SIZE_asm - 1, %ecx
23434+ shr $3, %ecx
23435+ repne scasq
23436+ jecxz 2f
23437+
23438+ cmp $2*8, %ecx
23439+ jc 2f
23440+
23441+ mov $2*8, %ecx
23442+ repe scasq
23443+ jecxz 2f
23444+ jne 1b
23445+
23446+2: cld
23447+ mov %esp, %ecx
23448+ sub %edi, %ecx
23449+
23450+ cmp $THREAD_SIZE_asm, %rcx
23451+ jb 3f
23452+ ud2
23453+3:
23454+
23455+ shr $3, %ecx
23456+ rep stosq
23457+
23458+ mov TI_task_thread_sp0(%r11), %rdi
23459+ sub $256, %rdi
23460+ mov %rdi, TI_lowest_stack(%r11)
23461+
23462+ popq %r11
23463+ popq %rax
23464+ popq %rcx
23465+ popq %rdi
23466+ pax_force_retaddr
23467+ ret
23468+ENDPROC(pax_erase_kstack)
23469+#endif
23470
23471 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
23472 #ifdef CONFIG_TRACE_IRQFLAGS
23473@@ -117,7 +543,7 @@ ENDPROC(native_usergs_sysret64)
23474 .endm
23475
23476 .macro TRACE_IRQS_IRETQ_DEBUG offset=ARGOFFSET
23477- bt $9,EFLAGS-\offset(%rsp) /* interrupts off? */
23478+ bt $X86_EFLAGS_IF_BIT,EFLAGS-\offset(%rsp) /* interrupts off? */
23479 jnc 1f
23480 TRACE_IRQS_ON_DEBUG
23481 1:
23482@@ -155,27 +581,6 @@ ENDPROC(native_usergs_sysret64)
23483 movq \tmp,R11+\offset(%rsp)
23484 .endm
23485
23486- .macro FAKE_STACK_FRAME child_rip
23487- /* push in order ss, rsp, eflags, cs, rip */
23488- xorl %eax, %eax
23489- pushq_cfi $__KERNEL_DS /* ss */
23490- /*CFI_REL_OFFSET ss,0*/
23491- pushq_cfi %rax /* rsp */
23492- CFI_REL_OFFSET rsp,0
23493- pushq_cfi $(X86_EFLAGS_IF|X86_EFLAGS_FIXED) /* eflags - interrupts on */
23494- /*CFI_REL_OFFSET rflags,0*/
23495- pushq_cfi $__KERNEL_CS /* cs */
23496- /*CFI_REL_OFFSET cs,0*/
23497- pushq_cfi \child_rip /* rip */
23498- CFI_REL_OFFSET rip,0
23499- pushq_cfi %rax /* orig rax */
23500- .endm
23501-
23502- .macro UNFAKE_STACK_FRAME
23503- addq $8*6, %rsp
23504- CFI_ADJUST_CFA_OFFSET -(6*8)
23505- .endm
23506-
23507 /*
23508 * initial frame state for interrupts (and exceptions without error code)
23509 */
23510@@ -241,25 +646,26 @@ ENDPROC(native_usergs_sysret64)
23511 /* save partial stack frame */
23512 .macro SAVE_ARGS_IRQ
23513 cld
23514- /* start from rbp in pt_regs and jump over */
23515- movq_cfi rdi, (RDI-RBP)
23516- movq_cfi rsi, (RSI-RBP)
23517- movq_cfi rdx, (RDX-RBP)
23518- movq_cfi rcx, (RCX-RBP)
23519- movq_cfi rax, (RAX-RBP)
23520- movq_cfi r8, (R8-RBP)
23521- movq_cfi r9, (R9-RBP)
23522- movq_cfi r10, (R10-RBP)
23523- movq_cfi r11, (R11-RBP)
23524+ /* start from r15 in pt_regs and jump over */
23525+ movq_cfi rdi, RDI
23526+ movq_cfi rsi, RSI
23527+ movq_cfi rdx, RDX
23528+ movq_cfi rcx, RCX
23529+ movq_cfi rax, RAX
23530+ movq_cfi r8, R8
23531+ movq_cfi r9, R9
23532+ movq_cfi r10, R10
23533+ movq_cfi r11, R11
23534+ movq_cfi r12, R12
23535
23536 /* Save rbp so that we can unwind from get_irq_regs() */
23537- movq_cfi rbp, 0
23538+ movq_cfi rbp, RBP
23539
23540 /* Save previous stack value */
23541 movq %rsp, %rsi
23542
23543- leaq -RBP(%rsp),%rdi /* arg1 for handler */
23544- testl $3, CS-RBP(%rsi)
23545+ movq %rsp,%rdi /* arg1 for handler */
23546+ testb $3, CS(%rsi)
23547 je 1f
23548 SWAPGS
23549 /*
23550@@ -279,6 +685,18 @@ ENDPROC(native_usergs_sysret64)
23551 0x06 /* DW_OP_deref */, \
23552 0x08 /* DW_OP_const1u */, SS+8-RBP, \
23553 0x22 /* DW_OP_plus */
23554+
23555+#ifdef CONFIG_PAX_MEMORY_UDEREF
23556+ testb $3, CS(%rdi)
23557+ jnz 1f
23558+ pax_enter_kernel
23559+ jmp 2f
23560+1: pax_enter_kernel_user
23561+2:
23562+#else
23563+ pax_enter_kernel
23564+#endif
23565+
23566 /* We entered an interrupt context - irqs are off: */
23567 TRACE_IRQS_OFF
23568 .endm
23569@@ -308,9 +726,52 @@ ENTRY(save_paranoid)
23570 js 1f /* negative -> in kernel */
23571 SWAPGS
23572 xorl %ebx,%ebx
23573-1: ret
23574+1:
23575+#ifdef CONFIG_PAX_MEMORY_UDEREF
23576+ testb $3, CS+8(%rsp)
23577+ jnz 1f
23578+ pax_enter_kernel
23579+ jmp 2f
23580+1: pax_enter_kernel_user
23581+2:
23582+#else
23583+ pax_enter_kernel
23584+#endif
23585+ pax_force_retaddr
23586+ ret
23587 CFI_ENDPROC
23588-END(save_paranoid)
23589+ENDPROC(save_paranoid)
23590+
23591+ENTRY(save_paranoid_nmi)
23592+ XCPT_FRAME 1 RDI+8
23593+ cld
23594+ movq_cfi rdi, RDI+8
23595+ movq_cfi rsi, RSI+8
23596+ movq_cfi rdx, RDX+8
23597+ movq_cfi rcx, RCX+8
23598+ movq_cfi rax, RAX+8
23599+ movq_cfi r8, R8+8
23600+ movq_cfi r9, R9+8
23601+ movq_cfi r10, R10+8
23602+ movq_cfi r11, R11+8
23603+ movq_cfi rbx, RBX+8
23604+ movq_cfi rbp, RBP+8
23605+ movq_cfi r12, R12+8
23606+ movq_cfi r13, R13+8
23607+ movq_cfi r14, R14+8
23608+ movq_cfi r15, R15+8
23609+ movl $1,%ebx
23610+ movl $MSR_GS_BASE,%ecx
23611+ rdmsr
23612+ testl %edx,%edx
23613+ js 1f /* negative -> in kernel */
23614+ SWAPGS
23615+ xorl %ebx,%ebx
23616+1: pax_enter_kernel_nmi
23617+ pax_force_retaddr
23618+ ret
23619+ CFI_ENDPROC
23620+ENDPROC(save_paranoid_nmi)
23621
23622 /*
23623 * A newly forked process directly context switches into this address.
23624@@ -331,7 +792,7 @@ ENTRY(ret_from_fork)
23625
23626 RESTORE_REST
23627
23628- testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
23629+ testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
23630 jz 1f
23631
23632 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
23633@@ -341,15 +802,13 @@ ENTRY(ret_from_fork)
23634 jmp ret_from_sys_call # go to the SYSRET fastpath
23635
23636 1:
23637- subq $REST_SKIP, %rsp # leave space for volatiles
23638- CFI_ADJUST_CFA_OFFSET REST_SKIP
23639 movq %rbp, %rdi
23640 call *%rbx
23641 movl $0, RAX(%rsp)
23642 RESTORE_REST
23643 jmp int_ret_from_sys_call
23644 CFI_ENDPROC
23645-END(ret_from_fork)
23646+ENDPROC(ret_from_fork)
23647
23648 /*
23649 * System call entry. Up to 6 arguments in registers are supported.
23650@@ -386,7 +845,7 @@ END(ret_from_fork)
23651 ENTRY(system_call)
23652 CFI_STARTPROC simple
23653 CFI_SIGNAL_FRAME
23654- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
23655+ CFI_DEF_CFA rsp,0
23656 CFI_REGISTER rip,rcx
23657 /*CFI_REGISTER rflags,r11*/
23658 SWAPGS_UNSAFE_STACK
23659@@ -399,16 +858,23 @@ GLOBAL(system_call_after_swapgs)
23660
23661 movq %rsp,PER_CPU_VAR(old_rsp)
23662 movq PER_CPU_VAR(kernel_stack),%rsp
23663+ SAVE_ARGS 8*6, 0, rax_enosys=1
23664+ pax_enter_kernel_user
23665+
23666+#ifdef CONFIG_PAX_RANDKSTACK
23667+ pax_erase_kstack
23668+#endif
23669+
23670 /*
23671 * No need to follow this irqs off/on section - it's straight
23672 * and short:
23673 */
23674 ENABLE_INTERRUPTS(CLBR_NONE)
23675- SAVE_ARGS 8, 0, rax_enosys=1
23676 movq_cfi rax,(ORIG_RAX-ARGOFFSET)
23677 movq %rcx,RIP-ARGOFFSET(%rsp)
23678 CFI_REL_OFFSET rip,RIP-ARGOFFSET
23679- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
23680+ GET_THREAD_INFO(%rcx)
23681+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%rcx)
23682 jnz tracesys
23683 system_call_fastpath:
23684 #if __SYSCALL_MASK == ~0
23685@@ -432,10 +898,13 @@ sysret_check:
23686 LOCKDEP_SYS_EXIT
23687 DISABLE_INTERRUPTS(CLBR_NONE)
23688 TRACE_IRQS_OFF
23689- movl TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET),%edx
23690+ GET_THREAD_INFO(%rcx)
23691+ movl TI_flags(%rcx),%edx
23692 andl %edi,%edx
23693 jnz sysret_careful
23694 CFI_REMEMBER_STATE
23695+ pax_exit_kernel_user
23696+ pax_erase_kstack
23697 /*
23698 * sysretq will re-enable interrupts:
23699 */
23700@@ -494,12 +963,15 @@ sysret_audit:
23701
23702 /* Do syscall tracing */
23703 tracesys:
23704- leaq -REST_SKIP(%rsp), %rdi
23705+ movq %rsp, %rdi
23706 movq $AUDIT_ARCH_X86_64, %rsi
23707 call syscall_trace_enter_phase1
23708 test %rax, %rax
23709 jnz tracesys_phase2 /* if needed, run the slow path */
23710- LOAD_ARGS 0 /* else restore clobbered regs */
23711+
23712+ pax_erase_kstack
23713+
23714+ LOAD_ARGS /* else restore clobbered regs */
23715 jmp system_call_fastpath /* and return to the fast path */
23716
23717 tracesys_phase2:
23718@@ -510,12 +982,14 @@ tracesys_phase2:
23719 movq %rax,%rdx
23720 call syscall_trace_enter_phase2
23721
23722+ pax_erase_kstack
23723+
23724 /*
23725 * Reload arg registers from stack in case ptrace changed them.
23726 * We don't reload %rax because syscall_trace_entry_phase2() returned
23727 * the value it wants us to use in the table lookup.
23728 */
23729- LOAD_ARGS ARGOFFSET, 1
23730+ LOAD_ARGS 1
23731 RESTORE_REST
23732 #if __SYSCALL_MASK == ~0
23733 cmpq $__NR_syscall_max,%rax
23734@@ -545,7 +1019,9 @@ GLOBAL(int_with_check)
23735 andl %edi,%edx
23736 jnz int_careful
23737 andl $~TS_COMPAT,TI_status(%rcx)
23738- jmp retint_swapgs
23739+ pax_exit_kernel_user
23740+ pax_erase_kstack
23741+ jmp retint_swapgs_pax
23742
23743 /* Either reschedule or signal or syscall exit tracking needed. */
23744 /* First do a reschedule test. */
23745@@ -591,7 +1067,7 @@ int_restore_rest:
23746 TRACE_IRQS_OFF
23747 jmp int_with_check
23748 CFI_ENDPROC
23749-END(system_call)
23750+ENDPROC(system_call)
23751
23752 .macro FORK_LIKE func
23753 ENTRY(stub_\func)
23754@@ -604,9 +1080,10 @@ ENTRY(stub_\func)
23755 DEFAULT_FRAME 0 8 /* offset 8: return address */
23756 call sys_\func
23757 RESTORE_TOP_OF_STACK %r11, 8
23758- ret $REST_SKIP /* pop extended registers */
23759+ pax_force_retaddr
23760+ ret
23761 CFI_ENDPROC
23762-END(stub_\func)
23763+ENDPROC(stub_\func)
23764 .endm
23765
23766 .macro FIXED_FRAME label,func
23767@@ -616,9 +1093,10 @@ ENTRY(\label)
23768 FIXUP_TOP_OF_STACK %r11, 8-ARGOFFSET
23769 call \func
23770 RESTORE_TOP_OF_STACK %r11, 8-ARGOFFSET
23771+ pax_force_retaddr
23772 ret
23773 CFI_ENDPROC
23774-END(\label)
23775+ENDPROC(\label)
23776 .endm
23777
23778 FORK_LIKE clone
23779@@ -626,19 +1104,6 @@ END(\label)
23780 FORK_LIKE vfork
23781 FIXED_FRAME stub_iopl, sys_iopl
23782
23783-ENTRY(ptregscall_common)
23784- DEFAULT_FRAME 1 8 /* offset 8: return address */
23785- RESTORE_TOP_OF_STACK %r11, 8
23786- movq_cfi_restore R15+8, r15
23787- movq_cfi_restore R14+8, r14
23788- movq_cfi_restore R13+8, r13
23789- movq_cfi_restore R12+8, r12
23790- movq_cfi_restore RBP+8, rbp
23791- movq_cfi_restore RBX+8, rbx
23792- ret $REST_SKIP /* pop extended registers */
23793- CFI_ENDPROC
23794-END(ptregscall_common)
23795-
23796 ENTRY(stub_execve)
23797 CFI_STARTPROC
23798 addq $8, %rsp
23799@@ -650,7 +1115,7 @@ ENTRY(stub_execve)
23800 RESTORE_REST
23801 jmp int_ret_from_sys_call
23802 CFI_ENDPROC
23803-END(stub_execve)
23804+ENDPROC(stub_execve)
23805
23806 /*
23807 * sigreturn is special because it needs to restore all registers on return.
23808@@ -667,7 +1132,7 @@ ENTRY(stub_rt_sigreturn)
23809 RESTORE_REST
23810 jmp int_ret_from_sys_call
23811 CFI_ENDPROC
23812-END(stub_rt_sigreturn)
23813+ENDPROC(stub_rt_sigreturn)
23814
23815 #ifdef CONFIG_X86_X32_ABI
23816 ENTRY(stub_x32_rt_sigreturn)
23817@@ -681,7 +1146,7 @@ ENTRY(stub_x32_rt_sigreturn)
23818 RESTORE_REST
23819 jmp int_ret_from_sys_call
23820 CFI_ENDPROC
23821-END(stub_x32_rt_sigreturn)
23822+ENDPROC(stub_x32_rt_sigreturn)
23823
23824 ENTRY(stub_x32_execve)
23825 CFI_STARTPROC
23826@@ -695,7 +1160,7 @@ ENTRY(stub_x32_execve)
23827 RESTORE_REST
23828 jmp int_ret_from_sys_call
23829 CFI_ENDPROC
23830-END(stub_x32_execve)
23831+ENDPROC(stub_x32_execve)
23832
23833 #endif
23834
23835@@ -732,7 +1197,7 @@ vector=vector+1
23836 2: jmp common_interrupt
23837 .endr
23838 CFI_ENDPROC
23839-END(irq_entries_start)
23840+ENDPROC(irq_entries_start)
23841
23842 .previous
23843 END(interrupt)
23844@@ -749,8 +1214,8 @@ END(interrupt)
23845 /* 0(%rsp): ~(interrupt number) */
23846 .macro interrupt func
23847 /* reserve pt_regs for scratch regs and rbp */
23848- subq $ORIG_RAX-RBP, %rsp
23849- CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
23850+ subq $ORIG_RAX, %rsp
23851+ CFI_ADJUST_CFA_OFFSET ORIG_RAX
23852 SAVE_ARGS_IRQ
23853 call \func
23854 .endm
23855@@ -773,14 +1238,14 @@ ret_from_intr:
23856
23857 /* Restore saved previous stack */
23858 popq %rsi
23859- CFI_DEF_CFA rsi,SS+8-RBP /* reg/off reset after def_cfa_expr */
23860- leaq ARGOFFSET-RBP(%rsi), %rsp
23861+ CFI_DEF_CFA rsi,SS+8 /* reg/off reset after def_cfa_expr */
23862+ movq %rsi, %rsp
23863 CFI_DEF_CFA_REGISTER rsp
23864- CFI_ADJUST_CFA_OFFSET RBP-ARGOFFSET
23865+ CFI_ADJUST_CFA_OFFSET -ARGOFFSET
23866
23867 exit_intr:
23868 GET_THREAD_INFO(%rcx)
23869- testl $3,CS-ARGOFFSET(%rsp)
23870+ testb $3,CS-ARGOFFSET(%rsp)
23871 je retint_kernel
23872
23873 /* Interrupt came from user space */
23874@@ -802,12 +1267,35 @@ retint_swapgs: /* return to user-space */
23875 * The iretq could re-enable interrupts:
23876 */
23877 DISABLE_INTERRUPTS(CLBR_ANY)
23878+ pax_exit_kernel_user
23879+retint_swapgs_pax:
23880 TRACE_IRQS_IRETQ
23881 SWAPGS
23882 jmp restore_args
23883
23884 retint_restore_args: /* return to kernel space */
23885 DISABLE_INTERRUPTS(CLBR_ANY)
23886+ pax_exit_kernel
23887+
23888+#if defined(CONFIG_EFI) && defined(CONFIG_PAX_KERNEXEC)
23889+ /* This is a quirk to allow IRQs/NMIs/MCEs during early EFI setup,
23890+ * namely calling EFI runtime services with a phys mapping. We're
23891+ * starting off with NOPs and patch in the real instrumentation
23892+ * (BTS/OR) before starting any userland process; even before starting
23893+ * up the APs.
23894+ */
23895+ .pushsection .altinstr_replacement, "a"
23896+ 601: pax_force_retaddr (RIP-ARGOFFSET)
23897+ 602:
23898+ .popsection
23899+ 603: .fill 602b-601b, 1, 0x90
23900+ .pushsection .altinstructions, "a"
23901+ altinstruction_entry 603b, 601b, X86_FEATURE_ALWAYS, 602b-601b, 602b-601b
23902+ .popsection
23903+#else
23904+ pax_force_retaddr (RIP-ARGOFFSET)
23905+#endif
23906+
23907 /*
23908 * The iretq could re-enable interrupts:
23909 */
23910@@ -845,15 +1333,15 @@ native_irq_return_ldt:
23911 SWAPGS
23912 movq PER_CPU_VAR(espfix_waddr),%rdi
23913 movq %rax,(0*8)(%rdi) /* RAX */
23914- movq (2*8)(%rsp),%rax /* RIP */
23915+ movq (2*8 + RIP-RIP)(%rsp),%rax /* RIP */
23916 movq %rax,(1*8)(%rdi)
23917- movq (3*8)(%rsp),%rax /* CS */
23918+ movq (2*8 + CS-RIP)(%rsp),%rax /* CS */
23919 movq %rax,(2*8)(%rdi)
23920- movq (4*8)(%rsp),%rax /* RFLAGS */
23921+ movq (2*8 + EFLAGS-RIP)(%rsp),%rax /* RFLAGS */
23922 movq %rax,(3*8)(%rdi)
23923- movq (6*8)(%rsp),%rax /* SS */
23924+ movq (2*8 + SS-RIP)(%rsp),%rax /* SS */
23925 movq %rax,(5*8)(%rdi)
23926- movq (5*8)(%rsp),%rax /* RSP */
23927+ movq (2*8 + RSP-RIP)(%rsp),%rax /* RSP */
23928 movq %rax,(4*8)(%rdi)
23929 andl $0xffff0000,%eax
23930 popq_cfi %rdi
23931@@ -907,7 +1395,7 @@ ENTRY(retint_kernel)
23932 jmp exit_intr
23933 #endif
23934 CFI_ENDPROC
23935-END(common_interrupt)
23936+ENDPROC(common_interrupt)
23937
23938 /*
23939 * APIC interrupts.
23940@@ -921,7 +1409,7 @@ ENTRY(\sym)
23941 interrupt \do_sym
23942 jmp ret_from_intr
23943 CFI_ENDPROC
23944-END(\sym)
23945+ENDPROC(\sym)
23946 .endm
23947
23948 #ifdef CONFIG_TRACING
23949@@ -994,7 +1482,7 @@ apicinterrupt IRQ_WORK_VECTOR \
23950 /*
23951 * Exception entry points.
23952 */
23953-#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
23954+#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r13)
23955
23956 .macro idtentry sym do_sym has_error_code:req paranoid=0 shift_ist=-1
23957 ENTRY(\sym)
23958@@ -1045,6 +1533,12 @@ ENTRY(\sym)
23959 .endif
23960
23961 .if \shift_ist != -1
23962+#ifdef CONFIG_SMP
23963+ imul $TSS_size, PER_CPU_VAR(cpu_number), %r13d
23964+ lea init_tss(%r13), %r13
23965+#else
23966+ lea init_tss(%rip), %r13
23967+#endif
23968 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\shift_ist)
23969 .endif
23970
23971@@ -1061,7 +1555,7 @@ ENTRY(\sym)
23972 .endif
23973
23974 CFI_ENDPROC
23975-END(\sym)
23976+ENDPROC(\sym)
23977 .endm
23978
23979 #ifdef CONFIG_TRACING
23980@@ -1102,9 +1596,10 @@ gs_change:
23981 2: mfence /* workaround */
23982 SWAPGS
23983 popfq_cfi
23984+ pax_force_retaddr
23985 ret
23986 CFI_ENDPROC
23987-END(native_load_gs_index)
23988+ENDPROC(native_load_gs_index)
23989
23990 _ASM_EXTABLE(gs_change,bad_gs)
23991 .section .fixup,"ax"
23992@@ -1132,9 +1627,10 @@ ENTRY(do_softirq_own_stack)
23993 CFI_DEF_CFA_REGISTER rsp
23994 CFI_ADJUST_CFA_OFFSET -8
23995 decl PER_CPU_VAR(irq_count)
23996+ pax_force_retaddr
23997 ret
23998 CFI_ENDPROC
23999-END(do_softirq_own_stack)
24000+ENDPROC(do_softirq_own_stack)
24001
24002 #ifdef CONFIG_XEN
24003 idtentry xen_hypervisor_callback xen_do_hypervisor_callback has_error_code=0
24004@@ -1172,7 +1668,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
24005 decl PER_CPU_VAR(irq_count)
24006 jmp error_exit
24007 CFI_ENDPROC
24008-END(xen_do_hypervisor_callback)
24009+ENDPROC(xen_do_hypervisor_callback)
24010
24011 /*
24012 * Hypervisor uses this for application faults while it executes.
24013@@ -1231,7 +1727,7 @@ ENTRY(xen_failsafe_callback)
24014 SAVE_ALL
24015 jmp error_exit
24016 CFI_ENDPROC
24017-END(xen_failsafe_callback)
24018+ENDPROC(xen_failsafe_callback)
24019
24020 apicinterrupt3 HYPERVISOR_CALLBACK_VECTOR \
24021 xen_hvm_callback_vector xen_evtchn_do_upcall
24022@@ -1278,18 +1774,33 @@ ENTRY(paranoid_exit)
24023 DEFAULT_FRAME
24024 DISABLE_INTERRUPTS(CLBR_NONE)
24025 TRACE_IRQS_OFF_DEBUG
24026- testl %ebx,%ebx /* swapgs needed? */
24027+ testl $1,%ebx /* swapgs needed? */
24028 jnz paranoid_restore
24029- testl $3,CS(%rsp)
24030+ testb $3,CS(%rsp)
24031 jnz paranoid_userspace
24032+#ifdef CONFIG_PAX_MEMORY_UDEREF
24033+ pax_exit_kernel
24034+ TRACE_IRQS_IRETQ 0
24035+ SWAPGS_UNSAFE_STACK
24036+ RESTORE_ALL 8
24037+ pax_force_retaddr_bts
24038+ jmp irq_return
24039+#endif
24040 paranoid_swapgs:
24041+#ifdef CONFIG_PAX_MEMORY_UDEREF
24042+ pax_exit_kernel_user
24043+#else
24044+ pax_exit_kernel
24045+#endif
24046 TRACE_IRQS_IRETQ 0
24047 SWAPGS_UNSAFE_STACK
24048 RESTORE_ALL 8
24049 jmp irq_return
24050 paranoid_restore:
24051+ pax_exit_kernel
24052 TRACE_IRQS_IRETQ_DEBUG 0
24053 RESTORE_ALL 8
24054+ pax_force_retaddr_bts
24055 jmp irq_return
24056 paranoid_userspace:
24057 GET_THREAD_INFO(%rcx)
24058@@ -1318,7 +1829,7 @@ paranoid_schedule:
24059 TRACE_IRQS_OFF
24060 jmp paranoid_userspace
24061 CFI_ENDPROC
24062-END(paranoid_exit)
24063+ENDPROC(paranoid_exit)
24064
24065 /*
24066 * Exception entry point. This expects an error code/orig_rax on the stack.
24067@@ -1345,12 +1856,23 @@ ENTRY(error_entry)
24068 movq %r14, R14+8(%rsp)
24069 movq %r15, R15+8(%rsp)
24070 xorl %ebx,%ebx
24071- testl $3,CS+8(%rsp)
24072+ testb $3,CS+8(%rsp)
24073 je error_kernelspace
24074 error_swapgs:
24075 SWAPGS
24076 error_sti:
24077+#ifdef CONFIG_PAX_MEMORY_UDEREF
24078+ testb $3, CS+8(%rsp)
24079+ jnz 1f
24080+ pax_enter_kernel
24081+ jmp 2f
24082+1: pax_enter_kernel_user
24083+2:
24084+#else
24085+ pax_enter_kernel
24086+#endif
24087 TRACE_IRQS_OFF
24088+ pax_force_retaddr
24089 ret
24090
24091 /*
24092@@ -1385,7 +1907,7 @@ error_bad_iret:
24093 decl %ebx /* Return to usergs */
24094 jmp error_sti
24095 CFI_ENDPROC
24096-END(error_entry)
24097+ENDPROC(error_entry)
24098
24099
24100 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
24101@@ -1396,7 +1918,7 @@ ENTRY(error_exit)
24102 DISABLE_INTERRUPTS(CLBR_NONE)
24103 TRACE_IRQS_OFF
24104 GET_THREAD_INFO(%rcx)
24105- testl %eax,%eax
24106+ testl $1,%eax
24107 jne retint_kernel
24108 LOCKDEP_SYS_EXIT_IRQ
24109 movl TI_flags(%rcx),%edx
24110@@ -1405,7 +1927,7 @@ ENTRY(error_exit)
24111 jnz retint_careful
24112 jmp retint_swapgs
24113 CFI_ENDPROC
24114-END(error_exit)
24115+ENDPROC(error_exit)
24116
24117 /*
24118 * Test if a given stack is an NMI stack or not.
24119@@ -1463,9 +1985,11 @@ ENTRY(nmi)
24120 * If %cs was not the kernel segment, then the NMI triggered in user
24121 * space, which means it is definitely not nested.
24122 */
24123+ cmpl $__KERNEXEC_KERNEL_CS, 16(%rsp)
24124+ je 1f
24125 cmpl $__KERNEL_CS, 16(%rsp)
24126 jne first_nmi
24127-
24128+1:
24129 /*
24130 * Check the special variable on the stack to see if NMIs are
24131 * executing.
24132@@ -1499,8 +2023,7 @@ nested_nmi:
24133
24134 1:
24135 /* Set up the interrupted NMIs stack to jump to repeat_nmi */
24136- leaq -1*8(%rsp), %rdx
24137- movq %rdx, %rsp
24138+ subq $8, %rsp
24139 CFI_ADJUST_CFA_OFFSET 1*8
24140 leaq -10*8(%rsp), %rdx
24141 pushq_cfi $__KERNEL_DS
24142@@ -1518,6 +2041,7 @@ nested_nmi_out:
24143 CFI_RESTORE rdx
24144
24145 /* No need to check faults here */
24146+# pax_force_retaddr_bts
24147 INTERRUPT_RETURN
24148
24149 CFI_RESTORE_STATE
24150@@ -1614,13 +2138,13 @@ end_repeat_nmi:
24151 subq $ORIG_RAX-R15, %rsp
24152 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
24153 /*
24154- * Use save_paranoid to handle SWAPGS, but no need to use paranoid_exit
24155+ * Use save_paranoid_nmi to handle SWAPGS, but no need to use paranoid_exit
24156 * as we should not be calling schedule in NMI context.
24157 * Even with normal interrupts enabled. An NMI should not be
24158 * setting NEED_RESCHED or anything that normal interrupts and
24159 * exceptions might do.
24160 */
24161- call save_paranoid
24162+ call save_paranoid_nmi
24163 DEFAULT_FRAME 0
24164
24165 /*
24166@@ -1630,9 +2154,9 @@ end_repeat_nmi:
24167 * NMI itself takes a page fault, the page fault that was preempted
24168 * will read the information from the NMI page fault and not the
24169 * origin fault. Save it off and restore it if it changes.
24170- * Use the r12 callee-saved register.
24171+ * Use the r13 callee-saved register.
24172 */
24173- movq %cr2, %r12
24174+ movq %cr2, %r13
24175
24176 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
24177 movq %rsp,%rdi
24178@@ -1641,29 +2165,34 @@ end_repeat_nmi:
24179
24180 /* Did the NMI take a page fault? Restore cr2 if it did */
24181 movq %cr2, %rcx
24182- cmpq %rcx, %r12
24183+ cmpq %rcx, %r13
24184 je 1f
24185- movq %r12, %cr2
24186+ movq %r13, %cr2
24187 1:
24188
24189- testl %ebx,%ebx /* swapgs needed? */
24190+ testl $1,%ebx /* swapgs needed? */
24191 jnz nmi_restore
24192 nmi_swapgs:
24193 SWAPGS_UNSAFE_STACK
24194 nmi_restore:
24195+ pax_exit_kernel_nmi
24196 /* Pop the extra iret frame at once */
24197 RESTORE_ALL 6*8
24198+ testb $3, 8(%rsp)
24199+ jnz 1f
24200+ pax_force_retaddr_bts
24201+1:
24202
24203 /* Clear the NMI executing stack variable */
24204 movq $0, 5*8(%rsp)
24205 jmp irq_return
24206 CFI_ENDPROC
24207-END(nmi)
24208+ENDPROC(nmi)
24209
24210 ENTRY(ignore_sysret)
24211 CFI_STARTPROC
24212 mov $-ENOSYS,%eax
24213 sysret
24214 CFI_ENDPROC
24215-END(ignore_sysret)
24216+ENDPROC(ignore_sysret)
24217
24218diff --git a/arch/x86/kernel/espfix_64.c b/arch/x86/kernel/espfix_64.c
24219index 94d857f..5bce89c 100644
24220--- a/arch/x86/kernel/espfix_64.c
24221+++ b/arch/x86/kernel/espfix_64.c
24222@@ -70,8 +70,7 @@ static DEFINE_MUTEX(espfix_init_mutex);
24223 #define ESPFIX_MAX_PAGES DIV_ROUND_UP(CONFIG_NR_CPUS, ESPFIX_STACKS_PER_PAGE)
24224 static void *espfix_pages[ESPFIX_MAX_PAGES];
24225
24226-static __page_aligned_bss pud_t espfix_pud_page[PTRS_PER_PUD]
24227- __aligned(PAGE_SIZE);
24228+static pud_t espfix_pud_page[PTRS_PER_PUD] __page_aligned_rodata;
24229
24230 static unsigned int page_random, slot_random;
24231
24232@@ -122,14 +121,17 @@ static void init_espfix_random(void)
24233 void __init init_espfix_bsp(void)
24234 {
24235 pgd_t *pgd_p;
24236- pteval_t ptemask;
24237-
24238- ptemask = __supported_pte_mask;
24239+ unsigned long index = pgd_index(ESPFIX_BASE_ADDR);
24240
24241 /* Install the espfix pud into the kernel page directory */
24242- pgd_p = &init_level4_pgt[pgd_index(ESPFIX_BASE_ADDR)];
24243+ pgd_p = &init_level4_pgt[index];
24244 pgd_populate(&init_mm, pgd_p, (pud_t *)espfix_pud_page);
24245
24246+#ifdef CONFIG_PAX_PER_CPU_PGD
24247+ clone_pgd_range(get_cpu_pgd(0, kernel) + index, swapper_pg_dir + index, 1);
24248+ clone_pgd_range(get_cpu_pgd(0, user) + index, swapper_pg_dir + index, 1);
24249+#endif
24250+
24251 /* Randomize the locations */
24252 init_espfix_random();
24253
24254@@ -197,7 +199,7 @@ void init_espfix_ap(void)
24255 set_pte(&pte_p[n*PTE_STRIDE], pte);
24256
24257 /* Job is done for this CPU and any CPU which shares this page */
24258- ACCESS_ONCE(espfix_pages[page]) = stack_page;
24259+ ACCESS_ONCE_RW(espfix_pages[page]) = stack_page;
24260
24261 unlock_done:
24262 mutex_unlock(&espfix_init_mutex);
24263diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
24264index 3386dc9..28bdf81 100644
24265--- a/arch/x86/kernel/ftrace.c
24266+++ b/arch/x86/kernel/ftrace.c
24267@@ -88,7 +88,7 @@ static unsigned long text_ip_addr(unsigned long ip)
24268 * kernel identity mapping to modify code.
24269 */
24270 if (within(ip, (unsigned long)_text, (unsigned long)_etext))
24271- ip = (unsigned long)__va(__pa_symbol(ip));
24272+ ip = (unsigned long)__va(__pa_symbol(ktla_ktva(ip)));
24273
24274 return ip;
24275 }
24276@@ -104,6 +104,8 @@ ftrace_modify_code_direct(unsigned long ip, unsigned const char *old_code,
24277 {
24278 unsigned char replaced[MCOUNT_INSN_SIZE];
24279
24280+ ip = ktla_ktva(ip);
24281+
24282 /*
24283 * Note: Due to modules and __init, code can
24284 * disappear and change, we need to protect against faulting
24285@@ -229,7 +231,7 @@ static int update_ftrace_func(unsigned long ip, void *new)
24286 unsigned char old[MCOUNT_INSN_SIZE];
24287 int ret;
24288
24289- memcpy(old, (void *)ip, MCOUNT_INSN_SIZE);
24290+ memcpy(old, (void *)ktla_ktva(ip), MCOUNT_INSN_SIZE);
24291
24292 ftrace_update_func = ip;
24293 /* Make sure the breakpoints see the ftrace_update_func update */
24294@@ -310,7 +312,7 @@ static int add_break(unsigned long ip, const char *old)
24295 unsigned char replaced[MCOUNT_INSN_SIZE];
24296 unsigned char brk = BREAKPOINT_INSTRUCTION;
24297
24298- if (probe_kernel_read(replaced, (void *)ip, MCOUNT_INSN_SIZE))
24299+ if (probe_kernel_read(replaced, (void *)ktla_ktva(ip), MCOUNT_INSN_SIZE))
24300 return -EFAULT;
24301
24302 /* Make sure it is what we expect it to be */
24303diff --git a/arch/x86/kernel/head64.c b/arch/x86/kernel/head64.c
24304index eda1a86..8f6df48 100644
24305--- a/arch/x86/kernel/head64.c
24306+++ b/arch/x86/kernel/head64.c
24307@@ -67,12 +67,12 @@ again:
24308 pgd = *pgd_p;
24309
24310 /*
24311- * The use of __START_KERNEL_map rather than __PAGE_OFFSET here is
24312- * critical -- __PAGE_OFFSET would point us back into the dynamic
24313+ * The use of __early_va rather than __va here is critical:
24314+ * __va would point us back into the dynamic
24315 * range and we might end up looping forever...
24316 */
24317 if (pgd)
24318- pud_p = (pudval_t *)((pgd & PTE_PFN_MASK) + __START_KERNEL_map - phys_base);
24319+ pud_p = (pudval_t *)(__early_va(pgd & PTE_PFN_MASK));
24320 else {
24321 if (next_early_pgt >= EARLY_DYNAMIC_PAGE_TABLES) {
24322 reset_early_page_tables();
24323@@ -82,13 +82,13 @@ again:
24324 pud_p = (pudval_t *)early_dynamic_pgts[next_early_pgt++];
24325 for (i = 0; i < PTRS_PER_PUD; i++)
24326 pud_p[i] = 0;
24327- *pgd_p = (pgdval_t)pud_p - __START_KERNEL_map + phys_base + _KERNPG_TABLE;
24328+ *pgd_p = (pgdval_t)__pa(pud_p) + _KERNPG_TABLE;
24329 }
24330 pud_p += pud_index(address);
24331 pud = *pud_p;
24332
24333 if (pud)
24334- pmd_p = (pmdval_t *)((pud & PTE_PFN_MASK) + __START_KERNEL_map - phys_base);
24335+ pmd_p = (pmdval_t *)(__early_va(pud & PTE_PFN_MASK));
24336 else {
24337 if (next_early_pgt >= EARLY_DYNAMIC_PAGE_TABLES) {
24338 reset_early_page_tables();
24339@@ -98,7 +98,7 @@ again:
24340 pmd_p = (pmdval_t *)early_dynamic_pgts[next_early_pgt++];
24341 for (i = 0; i < PTRS_PER_PMD; i++)
24342 pmd_p[i] = 0;
24343- *pud_p = (pudval_t)pmd_p - __START_KERNEL_map + phys_base + _KERNPG_TABLE;
24344+ *pud_p = (pudval_t)__pa(pmd_p) + _KERNPG_TABLE;
24345 }
24346 pmd = (physaddr & PMD_MASK) + early_pmd_flags;
24347 pmd_p[pmd_index(address)] = pmd;
24348@@ -175,7 +175,6 @@ asmlinkage __visible void __init x86_64_start_kernel(char * real_mode_data)
24349 if (console_loglevel >= CONSOLE_LOGLEVEL_DEBUG)
24350 early_printk("Kernel alive\n");
24351
24352- clear_page(init_level4_pgt);
24353 /* set init_level4_pgt kernel high mapping*/
24354 init_level4_pgt[511] = early_level4_pgt[511];
24355
24356diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
24357index f36bd42..0ab4474 100644
24358--- a/arch/x86/kernel/head_32.S
24359+++ b/arch/x86/kernel/head_32.S
24360@@ -26,6 +26,12 @@
24361 /* Physical address */
24362 #define pa(X) ((X) - __PAGE_OFFSET)
24363
24364+#ifdef CONFIG_PAX_KERNEXEC
24365+#define ta(X) (X)
24366+#else
24367+#define ta(X) ((X) - __PAGE_OFFSET)
24368+#endif
24369+
24370 /*
24371 * References to members of the new_cpu_data structure.
24372 */
24373@@ -55,11 +61,7 @@
24374 * and small than max_low_pfn, otherwise will waste some page table entries
24375 */
24376
24377-#if PTRS_PER_PMD > 1
24378-#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
24379-#else
24380-#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
24381-#endif
24382+#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
24383
24384 /* Number of possible pages in the lowmem region */
24385 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
24386@@ -78,6 +80,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE
24387 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
24388
24389 /*
24390+ * Real beginning of normal "text" segment
24391+ */
24392+ENTRY(stext)
24393+ENTRY(_stext)
24394+
24395+/*
24396 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
24397 * %esi points to the real-mode code as a 32-bit pointer.
24398 * CS and DS must be 4 GB flat segments, but we don't depend on
24399@@ -85,6 +93,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
24400 * can.
24401 */
24402 __HEAD
24403+
24404+#ifdef CONFIG_PAX_KERNEXEC
24405+ jmp startup_32
24406+/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
24407+.fill PAGE_SIZE-5,1,0xcc
24408+#endif
24409+
24410 ENTRY(startup_32)
24411 movl pa(stack_start),%ecx
24412
24413@@ -106,6 +121,59 @@ ENTRY(startup_32)
24414 2:
24415 leal -__PAGE_OFFSET(%ecx),%esp
24416
24417+#ifdef CONFIG_SMP
24418+ movl $pa(cpu_gdt_table),%edi
24419+ movl $__per_cpu_load,%eax
24420+ movw %ax,GDT_ENTRY_PERCPU * 8 + 2(%edi)
24421+ rorl $16,%eax
24422+ movb %al,GDT_ENTRY_PERCPU * 8 + 4(%edi)
24423+ movb %ah,GDT_ENTRY_PERCPU * 8 + 7(%edi)
24424+ movl $__per_cpu_end - 1,%eax
24425+ subl $__per_cpu_start,%eax
24426+ movw %ax,GDT_ENTRY_PERCPU * 8 + 0(%edi)
24427+#endif
24428+
24429+#ifdef CONFIG_PAX_MEMORY_UDEREF
24430+ movl $NR_CPUS,%ecx
24431+ movl $pa(cpu_gdt_table),%edi
24432+1:
24433+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
24434+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
24435+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
24436+ addl $PAGE_SIZE_asm,%edi
24437+ loop 1b
24438+#endif
24439+
24440+#ifdef CONFIG_PAX_KERNEXEC
24441+ movl $pa(boot_gdt),%edi
24442+ movl $__LOAD_PHYSICAL_ADDR,%eax
24443+ movw %ax,GDT_ENTRY_BOOT_CS * 8 + 2(%edi)
24444+ rorl $16,%eax
24445+ movb %al,GDT_ENTRY_BOOT_CS * 8 + 4(%edi)
24446+ movb %ah,GDT_ENTRY_BOOT_CS * 8 + 7(%edi)
24447+ rorl $16,%eax
24448+
24449+ ljmp $(__BOOT_CS),$1f
24450+1:
24451+
24452+ movl $NR_CPUS,%ecx
24453+ movl $pa(cpu_gdt_table),%edi
24454+ addl $__PAGE_OFFSET,%eax
24455+1:
24456+ movb $0xc0,GDT_ENTRY_KERNEL_CS * 8 + 6(%edi)
24457+ movb $0xc0,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 6(%edi)
24458+ movw %ax,GDT_ENTRY_KERNEL_CS * 8 + 2(%edi)
24459+ movw %ax,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 2(%edi)
24460+ rorl $16,%eax
24461+ movb %al,GDT_ENTRY_KERNEL_CS * 8 + 4(%edi)
24462+ movb %al,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 4(%edi)
24463+ movb %ah,GDT_ENTRY_KERNEL_CS * 8 + 7(%edi)
24464+ movb %ah,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 7(%edi)
24465+ rorl $16,%eax
24466+ addl $PAGE_SIZE_asm,%edi
24467+ loop 1b
24468+#endif
24469+
24470 /*
24471 * Clear BSS first so that there are no surprises...
24472 */
24473@@ -201,8 +269,11 @@ ENTRY(startup_32)
24474 movl %eax, pa(max_pfn_mapped)
24475
24476 /* Do early initialization of the fixmap area */
24477- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
24478- movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
24479+#ifdef CONFIG_COMPAT_VDSO
24480+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
24481+#else
24482+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
24483+#endif
24484 #else /* Not PAE */
24485
24486 page_pde_offset = (__PAGE_OFFSET >> 20);
24487@@ -232,8 +303,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
24488 movl %eax, pa(max_pfn_mapped)
24489
24490 /* Do early initialization of the fixmap area */
24491- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
24492- movl %eax,pa(initial_page_table+0xffc)
24493+#ifdef CONFIG_COMPAT_VDSO
24494+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
24495+#else
24496+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
24497+#endif
24498 #endif
24499
24500 #ifdef CONFIG_PARAVIRT
24501@@ -247,9 +321,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
24502 cmpl $num_subarch_entries, %eax
24503 jae bad_subarch
24504
24505- movl pa(subarch_entries)(,%eax,4), %eax
24506- subl $__PAGE_OFFSET, %eax
24507- jmp *%eax
24508+ jmp *pa(subarch_entries)(,%eax,4)
24509
24510 bad_subarch:
24511 WEAK(lguest_entry)
24512@@ -261,10 +333,10 @@ WEAK(xen_entry)
24513 __INITDATA
24514
24515 subarch_entries:
24516- .long default_entry /* normal x86/PC */
24517- .long lguest_entry /* lguest hypervisor */
24518- .long xen_entry /* Xen hypervisor */
24519- .long default_entry /* Moorestown MID */
24520+ .long ta(default_entry) /* normal x86/PC */
24521+ .long ta(lguest_entry) /* lguest hypervisor */
24522+ .long ta(xen_entry) /* Xen hypervisor */
24523+ .long ta(default_entry) /* Moorestown MID */
24524 num_subarch_entries = (. - subarch_entries) / 4
24525 .previous
24526 #else
24527@@ -354,6 +426,7 @@ default_entry:
24528 movl pa(mmu_cr4_features),%eax
24529 movl %eax,%cr4
24530
24531+#ifdef CONFIG_X86_PAE
24532 testb $X86_CR4_PAE, %al # check if PAE is enabled
24533 jz enable_paging
24534
24535@@ -382,6 +455,9 @@ default_entry:
24536 /* Make changes effective */
24537 wrmsr
24538
24539+ btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
24540+#endif
24541+
24542 enable_paging:
24543
24544 /*
24545@@ -449,14 +525,20 @@ is486:
24546 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
24547 movl %eax,%ss # after changing gdt.
24548
24549- movl $(__USER_DS),%eax # DS/ES contains default USER segment
24550+# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
24551 movl %eax,%ds
24552 movl %eax,%es
24553
24554 movl $(__KERNEL_PERCPU), %eax
24555 movl %eax,%fs # set this cpu's percpu
24556
24557+#ifdef CONFIG_CC_STACKPROTECTOR
24558 movl $(__KERNEL_STACK_CANARY),%eax
24559+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
24560+ movl $(__USER_DS),%eax
24561+#else
24562+ xorl %eax,%eax
24563+#endif
24564 movl %eax,%gs
24565
24566 xorl %eax,%eax # Clear LDT
24567@@ -512,8 +594,11 @@ setup_once:
24568 * relocation. Manually set base address in stack canary
24569 * segment descriptor.
24570 */
24571- movl $gdt_page,%eax
24572+ movl $cpu_gdt_table,%eax
24573 movl $stack_canary,%ecx
24574+#ifdef CONFIG_SMP
24575+ addl $__per_cpu_load,%ecx
24576+#endif
24577 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
24578 shrl $16, %ecx
24579 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
24580@@ -548,7 +633,7 @@ ENTRY(early_idt_handler)
24581 cmpl $2,(%esp) # X86_TRAP_NMI
24582 je is_nmi # Ignore NMI
24583
24584- cmpl $2,%ss:early_recursion_flag
24585+ cmpl $1,%ss:early_recursion_flag
24586 je hlt_loop
24587 incl %ss:early_recursion_flag
24588
24589@@ -586,8 +671,8 @@ ENTRY(early_idt_handler)
24590 pushl (20+6*4)(%esp) /* trapno */
24591 pushl $fault_msg
24592 call printk
24593-#endif
24594 call dump_stack
24595+#endif
24596 hlt_loop:
24597 hlt
24598 jmp hlt_loop
24599@@ -607,8 +692,11 @@ ENDPROC(early_idt_handler)
24600 /* This is the default interrupt "handler" :-) */
24601 ALIGN
24602 ignore_int:
24603- cld
24604 #ifdef CONFIG_PRINTK
24605+ cmpl $2,%ss:early_recursion_flag
24606+ je hlt_loop
24607+ incl %ss:early_recursion_flag
24608+ cld
24609 pushl %eax
24610 pushl %ecx
24611 pushl %edx
24612@@ -617,9 +705,6 @@ ignore_int:
24613 movl $(__KERNEL_DS),%eax
24614 movl %eax,%ds
24615 movl %eax,%es
24616- cmpl $2,early_recursion_flag
24617- je hlt_loop
24618- incl early_recursion_flag
24619 pushl 16(%esp)
24620 pushl 24(%esp)
24621 pushl 32(%esp)
24622@@ -653,29 +738,34 @@ ENTRY(setup_once_ref)
24623 /*
24624 * BSS section
24625 */
24626-__PAGE_ALIGNED_BSS
24627- .align PAGE_SIZE
24628 #ifdef CONFIG_X86_PAE
24629+.section .initial_pg_pmd,"a",@progbits
24630 initial_pg_pmd:
24631 .fill 1024*KPMDS,4,0
24632 #else
24633+.section .initial_page_table,"a",@progbits
24634 ENTRY(initial_page_table)
24635 .fill 1024,4,0
24636 #endif
24637+.section .initial_pg_fixmap,"a",@progbits
24638 initial_pg_fixmap:
24639 .fill 1024,4,0
24640+.section .empty_zero_page,"a",@progbits
24641 ENTRY(empty_zero_page)
24642 .fill 4096,1,0
24643+.section .swapper_pg_dir,"a",@progbits
24644 ENTRY(swapper_pg_dir)
24645+#ifdef CONFIG_X86_PAE
24646+ .fill 4,8,0
24647+#else
24648 .fill 1024,4,0
24649+#endif
24650
24651 /*
24652 * This starts the data section.
24653 */
24654 #ifdef CONFIG_X86_PAE
24655-__PAGE_ALIGNED_DATA
24656- /* Page-aligned for the benefit of paravirt? */
24657- .align PAGE_SIZE
24658+.section .initial_page_table,"a",@progbits
24659 ENTRY(initial_page_table)
24660 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
24661 # if KPMDS == 3
24662@@ -694,12 +784,20 @@ ENTRY(initial_page_table)
24663 # error "Kernel PMDs should be 1, 2 or 3"
24664 # endif
24665 .align PAGE_SIZE /* needs to be page-sized too */
24666+
24667+#ifdef CONFIG_PAX_PER_CPU_PGD
24668+ENTRY(cpu_pgd)
24669+ .rept 2*NR_CPUS
24670+ .fill 4,8,0
24671+ .endr
24672+#endif
24673+
24674 #endif
24675
24676 .data
24677 .balign 4
24678 ENTRY(stack_start)
24679- .long init_thread_union+THREAD_SIZE
24680+ .long init_thread_union+THREAD_SIZE-8
24681
24682 __INITRODATA
24683 int_msg:
24684@@ -727,7 +825,7 @@ fault_msg:
24685 * segment size, and 32-bit linear address value:
24686 */
24687
24688- .data
24689+.section .rodata,"a",@progbits
24690 .globl boot_gdt_descr
24691 .globl idt_descr
24692
24693@@ -736,7 +834,7 @@ fault_msg:
24694 .word 0 # 32 bit align gdt_desc.address
24695 boot_gdt_descr:
24696 .word __BOOT_DS+7
24697- .long boot_gdt - __PAGE_OFFSET
24698+ .long pa(boot_gdt)
24699
24700 .word 0 # 32-bit align idt_desc.address
24701 idt_descr:
24702@@ -747,7 +845,7 @@ idt_descr:
24703 .word 0 # 32 bit align gdt_desc.address
24704 ENTRY(early_gdt_descr)
24705 .word GDT_ENTRIES*8-1
24706- .long gdt_page /* Overwritten for secondary CPUs */
24707+ .long cpu_gdt_table /* Overwritten for secondary CPUs */
24708
24709 /*
24710 * The boot_gdt must mirror the equivalent in setup.S and is
24711@@ -756,5 +854,65 @@ ENTRY(early_gdt_descr)
24712 .align L1_CACHE_BYTES
24713 ENTRY(boot_gdt)
24714 .fill GDT_ENTRY_BOOT_CS,8,0
24715- .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
24716- .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
24717+ .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
24718+ .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
24719+
24720+ .align PAGE_SIZE_asm
24721+ENTRY(cpu_gdt_table)
24722+ .rept NR_CPUS
24723+ .quad 0x0000000000000000 /* NULL descriptor */
24724+ .quad 0x0000000000000000 /* 0x0b reserved */
24725+ .quad 0x0000000000000000 /* 0x13 reserved */
24726+ .quad 0x0000000000000000 /* 0x1b reserved */
24727+
24728+#ifdef CONFIG_PAX_KERNEXEC
24729+ .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
24730+#else
24731+ .quad 0x0000000000000000 /* 0x20 unused */
24732+#endif
24733+
24734+ .quad 0x0000000000000000 /* 0x28 unused */
24735+ .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
24736+ .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
24737+ .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
24738+ .quad 0x0000000000000000 /* 0x4b reserved */
24739+ .quad 0x0000000000000000 /* 0x53 reserved */
24740+ .quad 0x0000000000000000 /* 0x5b reserved */
24741+
24742+ .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
24743+ .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
24744+ .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
24745+ .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
24746+
24747+ .quad 0x0000000000000000 /* 0x80 TSS descriptor */
24748+ .quad 0x0000000000000000 /* 0x88 LDT descriptor */
24749+
24750+ /*
24751+ * Segments used for calling PnP BIOS have byte granularity.
24752+ * The code segments and data segments have fixed 64k limits,
24753+ * the transfer segment sizes are set at run time.
24754+ */
24755+ .quad 0x00409b000000ffff /* 0x90 32-bit code */
24756+ .quad 0x00009b000000ffff /* 0x98 16-bit code */
24757+ .quad 0x000093000000ffff /* 0xa0 16-bit data */
24758+ .quad 0x0000930000000000 /* 0xa8 16-bit data */
24759+ .quad 0x0000930000000000 /* 0xb0 16-bit data */
24760+
24761+ /*
24762+ * The APM segments have byte granularity and their bases
24763+ * are set at run time. All have 64k limits.
24764+ */
24765+ .quad 0x00409b000000ffff /* 0xb8 APM CS code */
24766+ .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
24767+ .quad 0x004093000000ffff /* 0xc8 APM DS data */
24768+
24769+ .quad 0x00c093000000ffff /* 0xd0 - ESPFIX SS */
24770+ .quad 0x0040930000000000 /* 0xd8 - PERCPU */
24771+ .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
24772+ .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
24773+ .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
24774+ .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
24775+
24776+ /* Be sure this is zeroed to avoid false validations in Xen */
24777+ .fill PAGE_SIZE_asm - GDT_SIZE,1,0
24778+ .endr
24779diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
24780index a468c0a..8b5a879 100644
24781--- a/arch/x86/kernel/head_64.S
24782+++ b/arch/x86/kernel/head_64.S
24783@@ -20,6 +20,8 @@
24784 #include <asm/processor-flags.h>
24785 #include <asm/percpu.h>
24786 #include <asm/nops.h>
24787+#include <asm/cpufeature.h>
24788+#include <asm/alternative-asm.h>
24789
24790 #ifdef CONFIG_PARAVIRT
24791 #include <asm/asm-offsets.h>
24792@@ -41,6 +43,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
24793 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
24794 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
24795 L3_START_KERNEL = pud_index(__START_KERNEL_map)
24796+L4_VMALLOC_START = pgd_index(VMALLOC_START)
24797+L3_VMALLOC_START = pud_index(VMALLOC_START)
24798+L4_VMALLOC_END = pgd_index(VMALLOC_END)
24799+L3_VMALLOC_END = pud_index(VMALLOC_END)
24800+L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
24801+L3_VMEMMAP_START = pud_index(VMEMMAP_START)
24802
24803 .text
24804 __HEAD
24805@@ -89,11 +97,24 @@ startup_64:
24806 * Fixup the physical addresses in the page table
24807 */
24808 addq %rbp, early_level4_pgt + (L4_START_KERNEL*8)(%rip)
24809+ addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
24810+ addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
24811+ addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
24812+ addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
24813+ addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
24814
24815- addq %rbp, level3_kernel_pgt + (510*8)(%rip)
24816- addq %rbp, level3_kernel_pgt + (511*8)(%rip)
24817+ addq %rbp, level3_ident_pgt + (0*8)(%rip)
24818+#ifndef CONFIG_XEN
24819+ addq %rbp, level3_ident_pgt + (1*8)(%rip)
24820+#endif
24821+
24822+ addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
24823+
24824+ addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
24825+ addq %rbp, level3_kernel_pgt + ((L3_START_KERNEL+1)*8)(%rip)
24826
24827 addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
24828+ addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
24829
24830 /*
24831 * Set up the identity mapping for the switchover. These
24832@@ -174,11 +195,12 @@ ENTRY(secondary_startup_64)
24833 * after the boot processor executes this code.
24834 */
24835
24836+ orq $-1, %rbp
24837 movq $(init_level4_pgt - __START_KERNEL_map), %rax
24838 1:
24839
24840- /* Enable PAE mode and PGE */
24841- movl $(X86_CR4_PAE | X86_CR4_PGE), %ecx
24842+ /* Enable PAE mode and PSE/PGE */
24843+ movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %ecx
24844 movq %rcx, %cr4
24845
24846 /* Setup early boot stage 4 level pagetables. */
24847@@ -199,10 +221,19 @@ ENTRY(secondary_startup_64)
24848 movl $MSR_EFER, %ecx
24849 rdmsr
24850 btsl $_EFER_SCE, %eax /* Enable System Call */
24851- btl $20,%edi /* No Execute supported? */
24852+ btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
24853 jnc 1f
24854 btsl $_EFER_NX, %eax
24855+ cmpq $-1, %rbp
24856+ je 1f
24857 btsq $_PAGE_BIT_NX,early_pmd_flags(%rip)
24858+ btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_PAGE_OFFSET(%rip)
24859+ btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMALLOC_START(%rip)
24860+ btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMALLOC_END(%rip)
24861+ btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMEMMAP_START(%rip)
24862+ btsq $_PAGE_BIT_NX, level2_fixmap_pgt + 8*506(%rip)
24863+ btsq $_PAGE_BIT_NX, level2_fixmap_pgt + 8*507(%rip)
24864+ btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
24865 1: wrmsr /* Make changes effective */
24866
24867 /* Setup cr0 */
24868@@ -282,6 +313,7 @@ ENTRY(secondary_startup_64)
24869 * REX.W + FF /5 JMP m16:64 Jump far, absolute indirect,
24870 * address given in m16:64.
24871 */
24872+ pax_set_fptr_mask
24873 movq initial_code(%rip),%rax
24874 pushq $0 # fake return address to stop unwinder
24875 pushq $__KERNEL_CS # set correct cs
24876@@ -313,7 +345,7 @@ ENDPROC(start_cpu0)
24877 .quad INIT_PER_CPU_VAR(irq_stack_union)
24878
24879 GLOBAL(stack_start)
24880- .quad init_thread_union+THREAD_SIZE-8
24881+ .quad init_thread_union+THREAD_SIZE-16
24882 .word 0
24883 __FINITDATA
24884
24885@@ -391,7 +423,7 @@ ENTRY(early_idt_handler)
24886 call dump_stack
24887 #ifdef CONFIG_KALLSYMS
24888 leaq early_idt_ripmsg(%rip),%rdi
24889- movq 40(%rsp),%rsi # %rip again
24890+ movq 88(%rsp),%rsi # %rip again
24891 call __print_symbol
24892 #endif
24893 #endif /* EARLY_PRINTK */
24894@@ -420,6 +452,7 @@ ENDPROC(early_idt_handler)
24895 early_recursion_flag:
24896 .long 0
24897
24898+ .section .rodata,"a",@progbits
24899 #ifdef CONFIG_EARLY_PRINTK
24900 early_idt_msg:
24901 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
24902@@ -447,29 +480,52 @@ NEXT_PAGE(early_level4_pgt)
24903 NEXT_PAGE(early_dynamic_pgts)
24904 .fill 512*EARLY_DYNAMIC_PAGE_TABLES,8,0
24905
24906- .data
24907+ .section .rodata,"a",@progbits
24908
24909-#ifndef CONFIG_XEN
24910 NEXT_PAGE(init_level4_pgt)
24911- .fill 512,8,0
24912-#else
24913-NEXT_PAGE(init_level4_pgt)
24914- .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
24915 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
24916 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
24917+ .org init_level4_pgt + L4_VMALLOC_START*8, 0
24918+ .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
24919+ .org init_level4_pgt + L4_VMALLOC_END*8, 0
24920+ .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
24921+ .org init_level4_pgt + L4_VMEMMAP_START*8, 0
24922+ .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
24923 .org init_level4_pgt + L4_START_KERNEL*8, 0
24924 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
24925 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
24926
24927+#ifdef CONFIG_PAX_PER_CPU_PGD
24928+NEXT_PAGE(cpu_pgd)
24929+ .rept 2*NR_CPUS
24930+ .fill 512,8,0
24931+ .endr
24932+#endif
24933+
24934 NEXT_PAGE(level3_ident_pgt)
24935 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
24936+#ifdef CONFIG_XEN
24937 .fill 511, 8, 0
24938+#else
24939+ .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
24940+ .fill 510,8,0
24941+#endif
24942+
24943+NEXT_PAGE(level3_vmalloc_start_pgt)
24944+ .fill 512,8,0
24945+
24946+NEXT_PAGE(level3_vmalloc_end_pgt)
24947+ .fill 512,8,0
24948+
24949+NEXT_PAGE(level3_vmemmap_pgt)
24950+ .fill L3_VMEMMAP_START,8,0
24951+ .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
24952+
24953 NEXT_PAGE(level2_ident_pgt)
24954- /* Since I easily can, map the first 1G.
24955+ /* Since I easily can, map the first 2G.
24956 * Don't set NX because code runs from these pages.
24957 */
24958- PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
24959-#endif
24960+ PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
24961
24962 NEXT_PAGE(level3_kernel_pgt)
24963 .fill L3_START_KERNEL,8,0
24964@@ -477,6 +533,9 @@ NEXT_PAGE(level3_kernel_pgt)
24965 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
24966 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
24967
24968+NEXT_PAGE(level2_vmemmap_pgt)
24969+ .fill 512,8,0
24970+
24971 NEXT_PAGE(level2_kernel_pgt)
24972 /*
24973 * 512 MB kernel mapping. We spend a full page on this pagetable
24974@@ -494,28 +553,64 @@ NEXT_PAGE(level2_kernel_pgt)
24975 NEXT_PAGE(level2_fixmap_pgt)
24976 .fill 506,8,0
24977 .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
24978- /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
24979- .fill 5,8,0
24980+ .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
24981+ /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
24982+ .fill 4,8,0
24983
24984 NEXT_PAGE(level1_fixmap_pgt)
24985 .fill 512,8,0
24986
24987+NEXT_PAGE(level1_vsyscall_pgt)
24988+ .fill 512,8,0
24989+
24990 #undef PMDS
24991
24992- .data
24993+ .align PAGE_SIZE
24994+ENTRY(cpu_gdt_table)
24995+ .rept NR_CPUS
24996+ .quad 0x0000000000000000 /* NULL descriptor */
24997+ .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
24998+ .quad 0x00af9b000000ffff /* __KERNEL_CS */
24999+ .quad 0x00cf93000000ffff /* __KERNEL_DS */
25000+ .quad 0x00cffb000000ffff /* __USER32_CS */
25001+ .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
25002+ .quad 0x00affb000000ffff /* __USER_CS */
25003+
25004+#ifdef CONFIG_PAX_KERNEXEC
25005+ .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
25006+#else
25007+ .quad 0x0 /* unused */
25008+#endif
25009+
25010+ .quad 0,0 /* TSS */
25011+ .quad 0,0 /* LDT */
25012+ .quad 0,0,0 /* three TLS descriptors */
25013+ .quad 0x0000f40000000000 /* node/CPU stored in limit */
25014+ /* asm/segment.h:GDT_ENTRIES must match this */
25015+
25016+#ifdef CONFIG_PAX_MEMORY_UDEREF
25017+ .quad 0x00cf93000000ffff /* __UDEREF_KERNEL_DS */
25018+#else
25019+ .quad 0x0 /* unused */
25020+#endif
25021+
25022+ /* zero the remaining page */
25023+ .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
25024+ .endr
25025+
25026 .align 16
25027 .globl early_gdt_descr
25028 early_gdt_descr:
25029 .word GDT_ENTRIES*8-1
25030 early_gdt_descr_base:
25031- .quad INIT_PER_CPU_VAR(gdt_page)
25032+ .quad cpu_gdt_table
25033
25034 ENTRY(phys_base)
25035 /* This must match the first entry in level2_kernel_pgt */
25036 .quad 0x0000000000000000
25037
25038 #include "../../x86/xen/xen-head.S"
25039-
25040- __PAGE_ALIGNED_BSS
25041+
25042+ .section .rodata,"a",@progbits
25043 NEXT_PAGE(empty_zero_page)
25044 .skip PAGE_SIZE
25045diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
25046index 05fd74f..c3548b1 100644
25047--- a/arch/x86/kernel/i386_ksyms_32.c
25048+++ b/arch/x86/kernel/i386_ksyms_32.c
25049@@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
25050 EXPORT_SYMBOL(cmpxchg8b_emu);
25051 #endif
25052
25053+EXPORT_SYMBOL_GPL(cpu_gdt_table);
25054+
25055 /* Networking helper routines. */
25056 EXPORT_SYMBOL(csum_partial_copy_generic);
25057+EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
25058+EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
25059
25060 EXPORT_SYMBOL(__get_user_1);
25061 EXPORT_SYMBOL(__get_user_2);
25062@@ -44,3 +48,11 @@ EXPORT_SYMBOL(___preempt_schedule);
25063 EXPORT_SYMBOL(___preempt_schedule_context);
25064 #endif
25065 #endif
25066+
25067+#ifdef CONFIG_PAX_KERNEXEC
25068+EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
25069+#endif
25070+
25071+#ifdef CONFIG_PAX_PER_CPU_PGD
25072+EXPORT_SYMBOL(cpu_pgd);
25073+#endif
25074diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
25075index a9a4229..6f4d476 100644
25076--- a/arch/x86/kernel/i387.c
25077+++ b/arch/x86/kernel/i387.c
25078@@ -51,7 +51,7 @@ static inline bool interrupted_kernel_fpu_idle(void)
25079 static inline bool interrupted_user_mode(void)
25080 {
25081 struct pt_regs *regs = get_irq_regs();
25082- return regs && user_mode_vm(regs);
25083+ return regs && user_mode(regs);
25084 }
25085
25086 /*
25087diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
25088index e7cc537..67d7372 100644
25089--- a/arch/x86/kernel/i8259.c
25090+++ b/arch/x86/kernel/i8259.c
25091@@ -110,7 +110,7 @@ static int i8259A_irq_pending(unsigned int irq)
25092 static void make_8259A_irq(unsigned int irq)
25093 {
25094 disable_irq_nosync(irq);
25095- io_apic_irqs &= ~(1<<irq);
25096+ io_apic_irqs &= ~(1UL<<irq);
25097 irq_set_chip_and_handler(irq, &i8259A_chip, handle_level_irq);
25098 enable_irq(irq);
25099 }
25100@@ -208,7 +208,7 @@ spurious_8259A_irq:
25101 "spurious 8259A interrupt: IRQ%d.\n", irq);
25102 spurious_irq_mask |= irqmask;
25103 }
25104- atomic_inc(&irq_err_count);
25105+ atomic_inc_unchecked(&irq_err_count);
25106 /*
25107 * Theoretically we do not have to handle this IRQ,
25108 * but in Linux this does not cause problems and is
25109@@ -349,14 +349,16 @@ static void init_8259A(int auto_eoi)
25110 /* (slave's support for AEOI in flat mode is to be investigated) */
25111 outb_pic(SLAVE_ICW4_DEFAULT, PIC_SLAVE_IMR);
25112
25113+ pax_open_kernel();
25114 if (auto_eoi)
25115 /*
25116 * In AEOI mode we just have to mask the interrupt
25117 * when acking.
25118 */
25119- i8259A_chip.irq_mask_ack = disable_8259A_irq;
25120+ *(void **)&i8259A_chip.irq_mask_ack = disable_8259A_irq;
25121 else
25122- i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
25123+ *(void **)&i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
25124+ pax_close_kernel();
25125
25126 udelay(100); /* wait for 8259A to initialize */
25127
25128diff --git a/arch/x86/kernel/io_delay.c b/arch/x86/kernel/io_delay.c
25129index a979b5b..1d6db75 100644
25130--- a/arch/x86/kernel/io_delay.c
25131+++ b/arch/x86/kernel/io_delay.c
25132@@ -58,7 +58,7 @@ static int __init dmi_io_delay_0xed_port(const struct dmi_system_id *id)
25133 * Quirk table for systems that misbehave (lock up, etc.) if port
25134 * 0x80 is used:
25135 */
25136-static struct dmi_system_id __initdata io_delay_0xed_port_dmi_table[] = {
25137+static const struct dmi_system_id __initconst io_delay_0xed_port_dmi_table[] = {
25138 {
25139 .callback = dmi_io_delay_0xed_port,
25140 .ident = "Compaq Presario V6000",
25141diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
25142index 4ddaf66..49d5c18 100644
25143--- a/arch/x86/kernel/ioport.c
25144+++ b/arch/x86/kernel/ioport.c
25145@@ -6,6 +6,7 @@
25146 #include <linux/sched.h>
25147 #include <linux/kernel.h>
25148 #include <linux/capability.h>
25149+#include <linux/security.h>
25150 #include <linux/errno.h>
25151 #include <linux/types.h>
25152 #include <linux/ioport.h>
25153@@ -30,6 +31,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
25154 return -EINVAL;
25155 if (turn_on && !capable(CAP_SYS_RAWIO))
25156 return -EPERM;
25157+#ifdef CONFIG_GRKERNSEC_IO
25158+ if (turn_on && grsec_disable_privio) {
25159+ gr_handle_ioperm();
25160+ return -ENODEV;
25161+ }
25162+#endif
25163
25164 /*
25165 * If it's the first ioperm() call in this thread's lifetime, set the
25166@@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
25167 * because the ->io_bitmap_max value must match the bitmap
25168 * contents:
25169 */
25170- tss = &per_cpu(init_tss, get_cpu());
25171+ tss = init_tss + get_cpu();
25172
25173 if (turn_on)
25174 bitmap_clear(t->io_bitmap_ptr, from, num);
25175@@ -105,6 +112,12 @@ SYSCALL_DEFINE1(iopl, unsigned int, level)
25176 if (level > old) {
25177 if (!capable(CAP_SYS_RAWIO))
25178 return -EPERM;
25179+#ifdef CONFIG_GRKERNSEC_IO
25180+ if (grsec_disable_privio) {
25181+ gr_handle_iopl();
25182+ return -ENODEV;
25183+ }
25184+#endif
25185 }
25186 regs->flags = (regs->flags & ~X86_EFLAGS_IOPL) | (level << 12);
25187 t->iopl = level << 12;
25188diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
25189index 922d285..6d20692 100644
25190--- a/arch/x86/kernel/irq.c
25191+++ b/arch/x86/kernel/irq.c
25192@@ -22,7 +22,7 @@
25193 #define CREATE_TRACE_POINTS
25194 #include <asm/trace/irq_vectors.h>
25195
25196-atomic_t irq_err_count;
25197+atomic_unchecked_t irq_err_count;
25198
25199 /* Function pointer for generic interrupt vector handling */
25200 void (*x86_platform_ipi_callback)(void) = NULL;
25201@@ -132,9 +132,9 @@ int arch_show_interrupts(struct seq_file *p, int prec)
25202 seq_printf(p, "%10u ", irq_stats(j)->irq_hv_callback_count);
25203 seq_printf(p, " Hypervisor callback interrupts\n");
25204 #endif
25205- seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
25206+ seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
25207 #if defined(CONFIG_X86_IO_APIC)
25208- seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
25209+ seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
25210 #endif
25211 return 0;
25212 }
25213@@ -174,7 +174,7 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
25214
25215 u64 arch_irq_stat(void)
25216 {
25217- u64 sum = atomic_read(&irq_err_count);
25218+ u64 sum = atomic_read_unchecked(&irq_err_count);
25219 return sum;
25220 }
25221
25222diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
25223index 63ce838..2ea3e06 100644
25224--- a/arch/x86/kernel/irq_32.c
25225+++ b/arch/x86/kernel/irq_32.c
25226@@ -29,6 +29,8 @@ EXPORT_PER_CPU_SYMBOL(irq_regs);
25227
25228 #ifdef CONFIG_DEBUG_STACKOVERFLOW
25229
25230+extern void gr_handle_kernel_exploit(void);
25231+
25232 int sysctl_panic_on_stackoverflow __read_mostly;
25233
25234 /* Debugging check for stack overflow: is there less than 1KB free? */
25235@@ -39,13 +41,14 @@ static int check_stack_overflow(void)
25236 __asm__ __volatile__("andl %%esp,%0" :
25237 "=r" (sp) : "0" (THREAD_SIZE - 1));
25238
25239- return sp < (sizeof(struct thread_info) + STACK_WARN);
25240+ return sp < STACK_WARN;
25241 }
25242
25243 static void print_stack_overflow(void)
25244 {
25245 printk(KERN_WARNING "low stack detected by irq handler\n");
25246 dump_stack();
25247+ gr_handle_kernel_exploit();
25248 if (sysctl_panic_on_stackoverflow)
25249 panic("low stack detected by irq handler - check messages\n");
25250 }
25251@@ -84,10 +87,9 @@ static inline void *current_stack(void)
25252 static inline int
25253 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
25254 {
25255- struct irq_stack *curstk, *irqstk;
25256+ struct irq_stack *irqstk;
25257 u32 *isp, *prev_esp, arg1, arg2;
25258
25259- curstk = (struct irq_stack *) current_stack();
25260 irqstk = __this_cpu_read(hardirq_stack);
25261
25262 /*
25263@@ -96,15 +98,19 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
25264 * handler) we can't do that and just have to keep using the
25265 * current stack (which is the irq stack already after all)
25266 */
25267- if (unlikely(curstk == irqstk))
25268+ if (unlikely((void *)current_stack_pointer - (void *)irqstk < THREAD_SIZE))
25269 return 0;
25270
25271- isp = (u32 *) ((char *)irqstk + sizeof(*irqstk));
25272+ isp = (u32 *) ((char *)irqstk + sizeof(*irqstk) - 8);
25273
25274 /* Save the next esp at the bottom of the stack */
25275 prev_esp = (u32 *)irqstk;
25276 *prev_esp = current_stack_pointer;
25277
25278+#ifdef CONFIG_PAX_MEMORY_UDEREF
25279+ __set_fs(MAKE_MM_SEG(0));
25280+#endif
25281+
25282 if (unlikely(overflow))
25283 call_on_stack(print_stack_overflow, isp);
25284
25285@@ -115,6 +121,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
25286 : "0" (irq), "1" (desc), "2" (isp),
25287 "D" (desc->handle_irq)
25288 : "memory", "cc", "ecx");
25289+
25290+#ifdef CONFIG_PAX_MEMORY_UDEREF
25291+ __set_fs(current_thread_info()->addr_limit);
25292+#endif
25293+
25294 return 1;
25295 }
25296
25297@@ -123,32 +134,18 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
25298 */
25299 void irq_ctx_init(int cpu)
25300 {
25301- struct irq_stack *irqstk;
25302-
25303 if (per_cpu(hardirq_stack, cpu))
25304 return;
25305
25306- irqstk = page_address(alloc_pages_node(cpu_to_node(cpu),
25307- THREADINFO_GFP,
25308- THREAD_SIZE_ORDER));
25309- per_cpu(hardirq_stack, cpu) = irqstk;
25310-
25311- irqstk = page_address(alloc_pages_node(cpu_to_node(cpu),
25312- THREADINFO_GFP,
25313- THREAD_SIZE_ORDER));
25314- per_cpu(softirq_stack, cpu) = irqstk;
25315-
25316- printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
25317- cpu, per_cpu(hardirq_stack, cpu), per_cpu(softirq_stack, cpu));
25318+ per_cpu(hardirq_stack, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
25319+ per_cpu(softirq_stack, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
25320 }
25321
25322 void do_softirq_own_stack(void)
25323 {
25324- struct thread_info *curstk;
25325 struct irq_stack *irqstk;
25326 u32 *isp, *prev_esp;
25327
25328- curstk = current_stack();
25329 irqstk = __this_cpu_read(softirq_stack);
25330
25331 /* build the stack frame on the softirq stack */
25332@@ -158,7 +155,16 @@ void do_softirq_own_stack(void)
25333 prev_esp = (u32 *)irqstk;
25334 *prev_esp = current_stack_pointer;
25335
25336+#ifdef CONFIG_PAX_MEMORY_UDEREF
25337+ __set_fs(MAKE_MM_SEG(0));
25338+#endif
25339+
25340 call_on_stack(__do_softirq, isp);
25341+
25342+#ifdef CONFIG_PAX_MEMORY_UDEREF
25343+ __set_fs(current_thread_info()->addr_limit);
25344+#endif
25345+
25346 }
25347
25348 bool handle_irq(unsigned irq, struct pt_regs *regs)
25349@@ -172,7 +178,7 @@ bool handle_irq(unsigned irq, struct pt_regs *regs)
25350 if (unlikely(!desc))
25351 return false;
25352
25353- if (user_mode_vm(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
25354+ if (user_mode(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
25355 if (unlikely(overflow))
25356 print_stack_overflow();
25357 desc->handle_irq(irq, desc);
25358diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
25359index e4b503d..824fce8 100644
25360--- a/arch/x86/kernel/irq_64.c
25361+++ b/arch/x86/kernel/irq_64.c
25362@@ -26,6 +26,8 @@ EXPORT_PER_CPU_SYMBOL(irq_stat);
25363 DEFINE_PER_CPU(struct pt_regs *, irq_regs);
25364 EXPORT_PER_CPU_SYMBOL(irq_regs);
25365
25366+extern void gr_handle_kernel_exploit(void);
25367+
25368 int sysctl_panic_on_stackoverflow;
25369
25370 /*
25371@@ -44,7 +46,7 @@ static inline void stack_overflow_check(struct pt_regs *regs)
25372 u64 estack_top, estack_bottom;
25373 u64 curbase = (u64)task_stack_page(current);
25374
25375- if (user_mode_vm(regs))
25376+ if (user_mode(regs))
25377 return;
25378
25379 if (regs->sp >= curbase + sizeof(struct thread_info) +
25380@@ -69,6 +71,8 @@ static inline void stack_overflow_check(struct pt_regs *regs)
25381 irq_stack_top, irq_stack_bottom,
25382 estack_top, estack_bottom);
25383
25384+ gr_handle_kernel_exploit();
25385+
25386 if (sysctl_panic_on_stackoverflow)
25387 panic("low stack detected by irq handler - check messages\n");
25388 #endif
25389diff --git a/arch/x86/kernel/jump_label.c b/arch/x86/kernel/jump_label.c
25390index 26d5a55..a01160a 100644
25391--- a/arch/x86/kernel/jump_label.c
25392+++ b/arch/x86/kernel/jump_label.c
25393@@ -51,7 +51,7 @@ static void __jump_label_transform(struct jump_entry *entry,
25394 * Jump label is enabled for the first time.
25395 * So we expect a default_nop...
25396 */
25397- if (unlikely(memcmp((void *)entry->code, default_nop, 5)
25398+ if (unlikely(memcmp((void *)ktla_ktva(entry->code), default_nop, 5)
25399 != 0))
25400 bug_at((void *)entry->code, __LINE__);
25401 } else {
25402@@ -59,7 +59,7 @@ static void __jump_label_transform(struct jump_entry *entry,
25403 * ...otherwise expect an ideal_nop. Otherwise
25404 * something went horribly wrong.
25405 */
25406- if (unlikely(memcmp((void *)entry->code, ideal_nop, 5)
25407+ if (unlikely(memcmp((void *)ktla_ktva(entry->code), ideal_nop, 5)
25408 != 0))
25409 bug_at((void *)entry->code, __LINE__);
25410 }
25411@@ -75,13 +75,13 @@ static void __jump_label_transform(struct jump_entry *entry,
25412 * are converting the default nop to the ideal nop.
25413 */
25414 if (init) {
25415- if (unlikely(memcmp((void *)entry->code, default_nop, 5) != 0))
25416+ if (unlikely(memcmp((void *)ktla_ktva(entry->code), default_nop, 5) != 0))
25417 bug_at((void *)entry->code, __LINE__);
25418 } else {
25419 code.jump = 0xe9;
25420 code.offset = entry->target -
25421 (entry->code + JUMP_LABEL_NOP_SIZE);
25422- if (unlikely(memcmp((void *)entry->code, &code, 5) != 0))
25423+ if (unlikely(memcmp((void *)ktla_ktva(entry->code), &code, 5) != 0))
25424 bug_at((void *)entry->code, __LINE__);
25425 }
25426 memcpy(&code, ideal_nops[NOP_ATOMIC5], JUMP_LABEL_NOP_SIZE);
25427diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
25428index 7ec1d5f..5a7d130 100644
25429--- a/arch/x86/kernel/kgdb.c
25430+++ b/arch/x86/kernel/kgdb.c
25431@@ -126,11 +126,11 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
25432 #ifdef CONFIG_X86_32
25433 switch (regno) {
25434 case GDB_SS:
25435- if (!user_mode_vm(regs))
25436+ if (!user_mode(regs))
25437 *(unsigned long *)mem = __KERNEL_DS;
25438 break;
25439 case GDB_SP:
25440- if (!user_mode_vm(regs))
25441+ if (!user_mode(regs))
25442 *(unsigned long *)mem = kernel_stack_pointer(regs);
25443 break;
25444 case GDB_GS:
25445@@ -228,7 +228,10 @@ static void kgdb_correct_hw_break(void)
25446 bp->attr.bp_addr = breakinfo[breakno].addr;
25447 bp->attr.bp_len = breakinfo[breakno].len;
25448 bp->attr.bp_type = breakinfo[breakno].type;
25449- info->address = breakinfo[breakno].addr;
25450+ if (breakinfo[breakno].type == X86_BREAKPOINT_EXECUTE)
25451+ info->address = ktla_ktva(breakinfo[breakno].addr);
25452+ else
25453+ info->address = breakinfo[breakno].addr;
25454 info->len = breakinfo[breakno].len;
25455 info->type = breakinfo[breakno].type;
25456 val = arch_install_hw_breakpoint(bp);
25457@@ -475,12 +478,12 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
25458 case 'k':
25459 /* clear the trace bit */
25460 linux_regs->flags &= ~X86_EFLAGS_TF;
25461- atomic_set(&kgdb_cpu_doing_single_step, -1);
25462+ atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
25463
25464 /* set the trace bit if we're stepping */
25465 if (remcomInBuffer[0] == 's') {
25466 linux_regs->flags |= X86_EFLAGS_TF;
25467- atomic_set(&kgdb_cpu_doing_single_step,
25468+ atomic_set_unchecked(&kgdb_cpu_doing_single_step,
25469 raw_smp_processor_id());
25470 }
25471
25472@@ -545,7 +548,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
25473
25474 switch (cmd) {
25475 case DIE_DEBUG:
25476- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
25477+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
25478 if (user_mode(regs))
25479 return single_step_cont(regs, args);
25480 break;
25481@@ -750,11 +753,11 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
25482 #endif /* CONFIG_DEBUG_RODATA */
25483
25484 bpt->type = BP_BREAKPOINT;
25485- err = probe_kernel_read(bpt->saved_instr, (char *)bpt->bpt_addr,
25486+ err = probe_kernel_read(bpt->saved_instr, ktla_ktva((char *)bpt->bpt_addr),
25487 BREAK_INSTR_SIZE);
25488 if (err)
25489 return err;
25490- err = probe_kernel_write((char *)bpt->bpt_addr,
25491+ err = probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
25492 arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE);
25493 #ifdef CONFIG_DEBUG_RODATA
25494 if (!err)
25495@@ -767,7 +770,7 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
25496 return -EBUSY;
25497 text_poke((void *)bpt->bpt_addr, arch_kgdb_ops.gdb_bpt_instr,
25498 BREAK_INSTR_SIZE);
25499- err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
25500+ err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
25501 if (err)
25502 return err;
25503 if (memcmp(opc, arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE))
25504@@ -792,13 +795,13 @@ int kgdb_arch_remove_breakpoint(struct kgdb_bkpt *bpt)
25505 if (mutex_is_locked(&text_mutex))
25506 goto knl_write;
25507 text_poke((void *)bpt->bpt_addr, bpt->saved_instr, BREAK_INSTR_SIZE);
25508- err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
25509+ err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
25510 if (err || memcmp(opc, bpt->saved_instr, BREAK_INSTR_SIZE))
25511 goto knl_write;
25512 return err;
25513 knl_write:
25514 #endif /* CONFIG_DEBUG_RODATA */
25515- return probe_kernel_write((char *)bpt->bpt_addr,
25516+ return probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
25517 (char *)bpt->saved_instr, BREAK_INSTR_SIZE);
25518 }
25519
25520diff --git a/arch/x86/kernel/kprobes/core.c b/arch/x86/kernel/kprobes/core.c
25521index 67e6d19..731ed28 100644
25522--- a/arch/x86/kernel/kprobes/core.c
25523+++ b/arch/x86/kernel/kprobes/core.c
25524@@ -120,9 +120,12 @@ __synthesize_relative_insn(void *from, void *to, u8 op)
25525 s32 raddr;
25526 } __packed *insn;
25527
25528- insn = (struct __arch_relative_insn *)from;
25529+ insn = (struct __arch_relative_insn *)ktla_ktva(from);
25530+
25531+ pax_open_kernel();
25532 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
25533 insn->op = op;
25534+ pax_close_kernel();
25535 }
25536
25537 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
25538@@ -168,7 +171,7 @@ int can_boost(kprobe_opcode_t *opcodes)
25539 kprobe_opcode_t opcode;
25540 kprobe_opcode_t *orig_opcodes = opcodes;
25541
25542- if (search_exception_tables((unsigned long)opcodes))
25543+ if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
25544 return 0; /* Page fault may occur on this address. */
25545
25546 retry:
25547@@ -242,9 +245,9 @@ __recover_probed_insn(kprobe_opcode_t *buf, unsigned long addr)
25548 * for the first byte, we can recover the original instruction
25549 * from it and kp->opcode.
25550 */
25551- memcpy(buf, kp->addr, MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
25552+ memcpy(buf, ktla_ktva(kp->addr), MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
25553 buf[0] = kp->opcode;
25554- return (unsigned long)buf;
25555+ return ktva_ktla((unsigned long)buf);
25556 }
25557
25558 /*
25559@@ -336,7 +339,9 @@ int __copy_instruction(u8 *dest, u8 *src)
25560 /* Another subsystem puts a breakpoint, failed to recover */
25561 if (insn.opcode.bytes[0] == BREAKPOINT_INSTRUCTION)
25562 return 0;
25563+ pax_open_kernel();
25564 memcpy(dest, insn.kaddr, insn.length);
25565+ pax_close_kernel();
25566
25567 #ifdef CONFIG_X86_64
25568 if (insn_rip_relative(&insn)) {
25569@@ -363,7 +368,9 @@ int __copy_instruction(u8 *dest, u8 *src)
25570 return 0;
25571 }
25572 disp = (u8 *) dest + insn_offset_displacement(&insn);
25573+ pax_open_kernel();
25574 *(s32 *) disp = (s32) newdisp;
25575+ pax_close_kernel();
25576 }
25577 #endif
25578 return insn.length;
25579@@ -505,7 +512,7 @@ static void setup_singlestep(struct kprobe *p, struct pt_regs *regs,
25580 * nor set current_kprobe, because it doesn't use single
25581 * stepping.
25582 */
25583- regs->ip = (unsigned long)p->ainsn.insn;
25584+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
25585 preempt_enable_no_resched();
25586 return;
25587 }
25588@@ -522,9 +529,9 @@ static void setup_singlestep(struct kprobe *p, struct pt_regs *regs,
25589 regs->flags &= ~X86_EFLAGS_IF;
25590 /* single step inline if the instruction is an int3 */
25591 if (p->opcode == BREAKPOINT_INSTRUCTION)
25592- regs->ip = (unsigned long)p->addr;
25593+ regs->ip = ktla_ktva((unsigned long)p->addr);
25594 else
25595- regs->ip = (unsigned long)p->ainsn.insn;
25596+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
25597 }
25598 NOKPROBE_SYMBOL(setup_singlestep);
25599
25600@@ -574,7 +581,7 @@ int kprobe_int3_handler(struct pt_regs *regs)
25601 struct kprobe *p;
25602 struct kprobe_ctlblk *kcb;
25603
25604- if (user_mode_vm(regs))
25605+ if (user_mode(regs))
25606 return 0;
25607
25608 addr = (kprobe_opcode_t *)(regs->ip - sizeof(kprobe_opcode_t));
25609@@ -609,7 +616,7 @@ int kprobe_int3_handler(struct pt_regs *regs)
25610 setup_singlestep(p, regs, kcb, 0);
25611 return 1;
25612 }
25613- } else if (*addr != BREAKPOINT_INSTRUCTION) {
25614+ } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
25615 /*
25616 * The breakpoint instruction was removed right
25617 * after we hit it. Another cpu has removed
25618@@ -656,6 +663,9 @@ static void __used kretprobe_trampoline_holder(void)
25619 " movq %rax, 152(%rsp)\n"
25620 RESTORE_REGS_STRING
25621 " popfq\n"
25622+#ifdef KERNEXEC_PLUGIN
25623+ " btsq $63,(%rsp)\n"
25624+#endif
25625 #else
25626 " pushf\n"
25627 SAVE_REGS_STRING
25628@@ -796,7 +806,7 @@ static void resume_execution(struct kprobe *p, struct pt_regs *regs,
25629 struct kprobe_ctlblk *kcb)
25630 {
25631 unsigned long *tos = stack_addr(regs);
25632- unsigned long copy_ip = (unsigned long)p->ainsn.insn;
25633+ unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
25634 unsigned long orig_ip = (unsigned long)p->addr;
25635 kprobe_opcode_t *insn = p->ainsn.insn;
25636
25637@@ -979,7 +989,7 @@ int kprobe_exceptions_notify(struct notifier_block *self, unsigned long val,
25638 struct die_args *args = data;
25639 int ret = NOTIFY_DONE;
25640
25641- if (args->regs && user_mode_vm(args->regs))
25642+ if (args->regs && user_mode(args->regs))
25643 return ret;
25644
25645 if (val == DIE_GPF) {
25646diff --git a/arch/x86/kernel/kprobes/opt.c b/arch/x86/kernel/kprobes/opt.c
25647index f1314d0..15f3154 100644
25648--- a/arch/x86/kernel/kprobes/opt.c
25649+++ b/arch/x86/kernel/kprobes/opt.c
25650@@ -79,6 +79,7 @@ found:
25651 /* Insert a move instruction which sets a pointer to eax/rdi (1st arg). */
25652 static void synthesize_set_arg1(kprobe_opcode_t *addr, unsigned long val)
25653 {
25654+ pax_open_kernel();
25655 #ifdef CONFIG_X86_64
25656 *addr++ = 0x48;
25657 *addr++ = 0xbf;
25658@@ -86,6 +87,7 @@ static void synthesize_set_arg1(kprobe_opcode_t *addr, unsigned long val)
25659 *addr++ = 0xb8;
25660 #endif
25661 *(unsigned long *)addr = val;
25662+ pax_close_kernel();
25663 }
25664
25665 asm (
25666@@ -337,7 +339,7 @@ int arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
25667 * Verify if the address gap is in 2GB range, because this uses
25668 * a relative jump.
25669 */
25670- rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
25671+ rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
25672 if (abs(rel) > 0x7fffffff) {
25673 __arch_remove_optimized_kprobe(op, 0);
25674 return -ERANGE;
25675@@ -354,16 +356,18 @@ int arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
25676 op->optinsn.size = ret;
25677
25678 /* Copy arch-dep-instance from template */
25679- memcpy(buf, &optprobe_template_entry, TMPL_END_IDX);
25680+ pax_open_kernel();
25681+ memcpy(buf, ktla_ktva(&optprobe_template_entry), TMPL_END_IDX);
25682+ pax_close_kernel();
25683
25684 /* Set probe information */
25685 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
25686
25687 /* Set probe function call */
25688- synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
25689+ synthesize_relcall(ktva_ktla(buf) + TMPL_CALL_IDX, optimized_callback);
25690
25691 /* Set returning jmp instruction at the tail of out-of-line buffer */
25692- synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
25693+ synthesize_reljump(ktva_ktla(buf) + TMPL_END_IDX + op->optinsn.size,
25694 (u8 *)op->kp.addr + op->optinsn.size);
25695
25696 flush_icache_range((unsigned long) buf,
25697@@ -388,7 +392,7 @@ void arch_optimize_kprobes(struct list_head *oplist)
25698 WARN_ON(kprobe_disabled(&op->kp));
25699
25700 /* Backup instructions which will be replaced by jump address */
25701- memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
25702+ memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
25703 RELATIVE_ADDR_SIZE);
25704
25705 insn_buf[0] = RELATIVEJUMP_OPCODE;
25706@@ -436,7 +440,7 @@ int setup_detour_execution(struct kprobe *p, struct pt_regs *regs, int reenter)
25707 /* This kprobe is really able to run optimized path. */
25708 op = container_of(p, struct optimized_kprobe, kp);
25709 /* Detour through copied instructions */
25710- regs->ip = (unsigned long)op->optinsn.insn + TMPL_END_IDX;
25711+ regs->ip = ktva_ktla((unsigned long)op->optinsn.insn) + TMPL_END_IDX;
25712 if (!reenter)
25713 reset_current_kprobe();
25714 preempt_enable_no_resched();
25715diff --git a/arch/x86/kernel/ksysfs.c b/arch/x86/kernel/ksysfs.c
25716index c2bedae..25e7ab60 100644
25717--- a/arch/x86/kernel/ksysfs.c
25718+++ b/arch/x86/kernel/ksysfs.c
25719@@ -184,7 +184,7 @@ out:
25720
25721 static struct kobj_attribute type_attr = __ATTR_RO(type);
25722
25723-static struct bin_attribute data_attr = {
25724+static bin_attribute_no_const data_attr __read_only = {
25725 .attr = {
25726 .name = "data",
25727 .mode = S_IRUGO,
25728diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c
25729index f6945bef..94f6434 100644
25730--- a/arch/x86/kernel/kvm.c
25731+++ b/arch/x86/kernel/kvm.c
25732@@ -283,7 +283,14 @@ NOKPROBE_SYMBOL(do_async_page_fault);
25733 static void __init paravirt_ops_setup(void)
25734 {
25735 pv_info.name = "KVM";
25736- pv_info.paravirt_enabled = 1;
25737+
25738+ /*
25739+ * KVM isn't paravirt in the sense of paravirt_enabled. A KVM
25740+ * guest kernel works like a bare metal kernel with additional
25741+ * features, and paravirt_enabled is about features that are
25742+ * missing.
25743+ */
25744+ pv_info.paravirt_enabled = 0;
25745
25746 if (kvm_para_has_feature(KVM_FEATURE_NOP_IO_DELAY))
25747 pv_cpu_ops.io_delay = kvm_io_delay;
25748diff --git a/arch/x86/kernel/kvmclock.c b/arch/x86/kernel/kvmclock.c
25749index d9156ce..a2de9bc 100644
25750--- a/arch/x86/kernel/kvmclock.c
25751+++ b/arch/x86/kernel/kvmclock.c
25752@@ -263,7 +263,6 @@ void __init kvmclock_init(void)
25753 #endif
25754 kvm_get_preset_lpj();
25755 clocksource_register_hz(&kvm_clock, NSEC_PER_SEC);
25756- pv_info.paravirt_enabled = 1;
25757 pv_info.name = "KVM";
25758
25759 if (kvm_para_has_feature(KVM_FEATURE_CLOCKSOURCE_STABLE_BIT))
25760diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
25761index c37886d..d851d32 100644
25762--- a/arch/x86/kernel/ldt.c
25763+++ b/arch/x86/kernel/ldt.c
25764@@ -66,13 +66,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
25765 if (reload) {
25766 #ifdef CONFIG_SMP
25767 preempt_disable();
25768- load_LDT(pc);
25769+ load_LDT_nolock(pc);
25770 if (!cpumask_equal(mm_cpumask(current->mm),
25771 cpumask_of(smp_processor_id())))
25772 smp_call_function(flush_ldt, current->mm, 1);
25773 preempt_enable();
25774 #else
25775- load_LDT(pc);
25776+ load_LDT_nolock(pc);
25777 #endif
25778 }
25779 if (oldsize) {
25780@@ -94,7 +94,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
25781 return err;
25782
25783 for (i = 0; i < old->size; i++)
25784- write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
25785+ write_ldt_entry(new->ldt, i, old->ldt + i);
25786 return 0;
25787 }
25788
25789@@ -115,6 +115,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
25790 retval = copy_ldt(&mm->context, &old_mm->context);
25791 mutex_unlock(&old_mm->context.lock);
25792 }
25793+
25794+ if (tsk == current) {
25795+ mm->context.vdso = 0;
25796+
25797+#ifdef CONFIG_X86_32
25798+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
25799+ mm->context.user_cs_base = 0UL;
25800+ mm->context.user_cs_limit = ~0UL;
25801+
25802+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
25803+ cpus_clear(mm->context.cpu_user_cs_mask);
25804+#endif
25805+
25806+#endif
25807+#endif
25808+
25809+ }
25810+
25811 return retval;
25812 }
25813
25814@@ -229,6 +247,13 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
25815 }
25816 }
25817
25818+#ifdef CONFIG_PAX_SEGMEXEC
25819+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
25820+ error = -EINVAL;
25821+ goto out_unlock;
25822+ }
25823+#endif
25824+
25825 if (!IS_ENABLED(CONFIG_X86_16BIT) && !ldt_info.seg_32bit) {
25826 error = -EINVAL;
25827 goto out_unlock;
25828diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
25829index 72e8e31..f2f1605 100644
25830--- a/arch/x86/kernel/machine_kexec_32.c
25831+++ b/arch/x86/kernel/machine_kexec_32.c
25832@@ -25,7 +25,7 @@
25833 #include <asm/cacheflush.h>
25834 #include <asm/debugreg.h>
25835
25836-static void set_idt(void *newidt, __u16 limit)
25837+static void set_idt(struct desc_struct *newidt, __u16 limit)
25838 {
25839 struct desc_ptr curidt;
25840
25841@@ -37,7 +37,7 @@ static void set_idt(void *newidt, __u16 limit)
25842 }
25843
25844
25845-static void set_gdt(void *newgdt, __u16 limit)
25846+static void set_gdt(struct desc_struct *newgdt, __u16 limit)
25847 {
25848 struct desc_ptr curgdt;
25849
25850@@ -215,7 +215,7 @@ void machine_kexec(struct kimage *image)
25851 }
25852
25853 control_page = page_address(image->control_code_page);
25854- memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
25855+ memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
25856
25857 relocate_kernel_ptr = control_page;
25858 page_list[PA_CONTROL_PAGE] = __pa(control_page);
25859diff --git a/arch/x86/kernel/mcount_64.S b/arch/x86/kernel/mcount_64.S
25860index c73aecf..4c63630 100644
25861--- a/arch/x86/kernel/mcount_64.S
25862+++ b/arch/x86/kernel/mcount_64.S
25863@@ -7,7 +7,7 @@
25864 #include <linux/linkage.h>
25865 #include <asm/ptrace.h>
25866 #include <asm/ftrace.h>
25867-
25868+#include <asm/alternative-asm.h>
25869
25870 .code64
25871 .section .entry.text, "ax"
25872@@ -24,8 +24,9 @@
25873 #ifdef CONFIG_DYNAMIC_FTRACE
25874
25875 ENTRY(function_hook)
25876+ pax_force_retaddr
25877 retq
25878-END(function_hook)
25879+ENDPROC(function_hook)
25880
25881 /* skip is set if stack has been adjusted */
25882 .macro ftrace_caller_setup skip=0
25883@@ -62,8 +63,9 @@ GLOBAL(ftrace_graph_call)
25884 #endif
25885
25886 GLOBAL(ftrace_stub)
25887+ pax_force_retaddr
25888 retq
25889-END(ftrace_caller)
25890+ENDPROC(ftrace_caller)
25891
25892 ENTRY(ftrace_regs_caller)
25893 /* Save the current flags before compare (in SS location)*/
25894@@ -127,7 +129,7 @@ GLOBAL(ftrace_regs_call)
25895 popfq
25896 jmp ftrace_stub
25897
25898-END(ftrace_regs_caller)
25899+ENDPROC(ftrace_regs_caller)
25900
25901
25902 #else /* ! CONFIG_DYNAMIC_FTRACE */
25903@@ -145,6 +147,7 @@ ENTRY(function_hook)
25904 #endif
25905
25906 GLOBAL(ftrace_stub)
25907+ pax_force_retaddr
25908 retq
25909
25910 trace:
25911@@ -158,12 +161,13 @@ trace:
25912 #endif
25913 subq $MCOUNT_INSN_SIZE, %rdi
25914
25915+ pax_force_fptr ftrace_trace_function
25916 call *ftrace_trace_function
25917
25918 MCOUNT_RESTORE_FRAME
25919
25920 jmp ftrace_stub
25921-END(function_hook)
25922+ENDPROC(function_hook)
25923 #endif /* CONFIG_DYNAMIC_FTRACE */
25924 #endif /* CONFIG_FUNCTION_TRACER */
25925
25926@@ -185,8 +189,9 @@ ENTRY(ftrace_graph_caller)
25927
25928 MCOUNT_RESTORE_FRAME
25929
25930+ pax_force_retaddr
25931 retq
25932-END(ftrace_graph_caller)
25933+ENDPROC(ftrace_graph_caller)
25934
25935 GLOBAL(return_to_handler)
25936 subq $24, %rsp
25937@@ -202,5 +207,7 @@ GLOBAL(return_to_handler)
25938 movq 8(%rsp), %rdx
25939 movq (%rsp), %rax
25940 addq $24, %rsp
25941+ pax_force_fptr %rdi
25942 jmp *%rdi
25943+ENDPROC(return_to_handler)
25944 #endif
25945diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
25946index e69f988..da078ea 100644
25947--- a/arch/x86/kernel/module.c
25948+++ b/arch/x86/kernel/module.c
25949@@ -81,17 +81,62 @@ static unsigned long int get_module_load_offset(void)
25950 }
25951 #endif
25952
25953-void *module_alloc(unsigned long size)
25954+static inline void *__module_alloc(unsigned long size, pgprot_t prot)
25955 {
25956- if (PAGE_ALIGN(size) > MODULES_LEN)
25957+ if (!size || PAGE_ALIGN(size) > MODULES_LEN)
25958 return NULL;
25959 return __vmalloc_node_range(size, 1,
25960 MODULES_VADDR + get_module_load_offset(),
25961- MODULES_END, GFP_KERNEL | __GFP_HIGHMEM,
25962- PAGE_KERNEL_EXEC, NUMA_NO_NODE,
25963+ MODULES_END, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO,
25964+ prot, NUMA_NO_NODE,
25965 __builtin_return_address(0));
25966 }
25967
25968+void *module_alloc(unsigned long size)
25969+{
25970+
25971+#ifdef CONFIG_PAX_KERNEXEC
25972+ return __module_alloc(size, PAGE_KERNEL);
25973+#else
25974+ return __module_alloc(size, PAGE_KERNEL_EXEC);
25975+#endif
25976+
25977+}
25978+
25979+#ifdef CONFIG_PAX_KERNEXEC
25980+#ifdef CONFIG_X86_32
25981+void *module_alloc_exec(unsigned long size)
25982+{
25983+ struct vm_struct *area;
25984+
25985+ if (size == 0)
25986+ return NULL;
25987+
25988+ area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
25989+return area ? area->addr : NULL;
25990+}
25991+EXPORT_SYMBOL(module_alloc_exec);
25992+
25993+void module_free_exec(struct module *mod, void *module_region)
25994+{
25995+ vunmap(module_region);
25996+}
25997+EXPORT_SYMBOL(module_free_exec);
25998+#else
25999+void module_free_exec(struct module *mod, void *module_region)
26000+{
26001+ module_free(mod, module_region);
26002+}
26003+EXPORT_SYMBOL(module_free_exec);
26004+
26005+void *module_alloc_exec(unsigned long size)
26006+{
26007+ return __module_alloc(size, PAGE_KERNEL_RX);
26008+}
26009+EXPORT_SYMBOL(module_alloc_exec);
26010+#endif
26011+#endif
26012+
26013 #ifdef CONFIG_X86_32
26014 int apply_relocate(Elf32_Shdr *sechdrs,
26015 const char *strtab,
26016@@ -102,14 +147,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
26017 unsigned int i;
26018 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
26019 Elf32_Sym *sym;
26020- uint32_t *location;
26021+ uint32_t *plocation, location;
26022
26023 DEBUGP("Applying relocate section %u to %u\n",
26024 relsec, sechdrs[relsec].sh_info);
26025 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
26026 /* This is where to make the change */
26027- location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
26028- + rel[i].r_offset;
26029+ plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
26030+ location = (uint32_t)plocation;
26031+ if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
26032+ plocation = ktla_ktva((void *)plocation);
26033 /* This is the symbol it is referring to. Note that all
26034 undefined symbols have been resolved. */
26035 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
26036@@ -118,11 +165,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
26037 switch (ELF32_R_TYPE(rel[i].r_info)) {
26038 case R_386_32:
26039 /* We add the value into the location given */
26040- *location += sym->st_value;
26041+ pax_open_kernel();
26042+ *plocation += sym->st_value;
26043+ pax_close_kernel();
26044 break;
26045 case R_386_PC32:
26046 /* Add the value, subtract its position */
26047- *location += sym->st_value - (uint32_t)location;
26048+ pax_open_kernel();
26049+ *plocation += sym->st_value - location;
26050+ pax_close_kernel();
26051 break;
26052 default:
26053 pr_err("%s: Unknown relocation: %u\n",
26054@@ -167,21 +218,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
26055 case R_X86_64_NONE:
26056 break;
26057 case R_X86_64_64:
26058+ pax_open_kernel();
26059 *(u64 *)loc = val;
26060+ pax_close_kernel();
26061 break;
26062 case R_X86_64_32:
26063+ pax_open_kernel();
26064 *(u32 *)loc = val;
26065+ pax_close_kernel();
26066 if (val != *(u32 *)loc)
26067 goto overflow;
26068 break;
26069 case R_X86_64_32S:
26070+ pax_open_kernel();
26071 *(s32 *)loc = val;
26072+ pax_close_kernel();
26073 if ((s64)val != *(s32 *)loc)
26074 goto overflow;
26075 break;
26076 case R_X86_64_PC32:
26077 val -= (u64)loc;
26078+ pax_open_kernel();
26079 *(u32 *)loc = val;
26080+ pax_close_kernel();
26081+
26082 #if 0
26083 if ((s64)val != *(s32 *)loc)
26084 goto overflow;
26085diff --git a/arch/x86/kernel/msr.c b/arch/x86/kernel/msr.c
26086index c9603ac..9f88728 100644
26087--- a/arch/x86/kernel/msr.c
26088+++ b/arch/x86/kernel/msr.c
26089@@ -37,6 +37,7 @@
26090 #include <linux/notifier.h>
26091 #include <linux/uaccess.h>
26092 #include <linux/gfp.h>
26093+#include <linux/grsecurity.h>
26094
26095 #include <asm/processor.h>
26096 #include <asm/msr.h>
26097@@ -103,6 +104,11 @@ static ssize_t msr_write(struct file *file, const char __user *buf,
26098 int err = 0;
26099 ssize_t bytes = 0;
26100
26101+#ifdef CONFIG_GRKERNSEC_KMEM
26102+ gr_handle_msr_write();
26103+ return -EPERM;
26104+#endif
26105+
26106 if (count % 8)
26107 return -EINVAL; /* Invalid chunk size */
26108
26109@@ -150,6 +156,10 @@ static long msr_ioctl(struct file *file, unsigned int ioc, unsigned long arg)
26110 err = -EBADF;
26111 break;
26112 }
26113+#ifdef CONFIG_GRKERNSEC_KMEM
26114+ gr_handle_msr_write();
26115+ return -EPERM;
26116+#endif
26117 if (copy_from_user(&regs, uregs, sizeof regs)) {
26118 err = -EFAULT;
26119 break;
26120@@ -233,7 +243,7 @@ static int msr_class_cpu_callback(struct notifier_block *nfb,
26121 return notifier_from_errno(err);
26122 }
26123
26124-static struct notifier_block __refdata msr_class_cpu_notifier = {
26125+static struct notifier_block msr_class_cpu_notifier = {
26126 .notifier_call = msr_class_cpu_callback,
26127 };
26128
26129diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
26130index c3e985d..110a36a 100644
26131--- a/arch/x86/kernel/nmi.c
26132+++ b/arch/x86/kernel/nmi.c
26133@@ -98,16 +98,16 @@ fs_initcall(nmi_warning_debugfs);
26134
26135 static void nmi_max_handler(struct irq_work *w)
26136 {
26137- struct nmiaction *a = container_of(w, struct nmiaction, irq_work);
26138+ struct nmiwork *n = container_of(w, struct nmiwork, irq_work);
26139 int remainder_ns, decimal_msecs;
26140- u64 whole_msecs = ACCESS_ONCE(a->max_duration);
26141+ u64 whole_msecs = ACCESS_ONCE(n->max_duration);
26142
26143 remainder_ns = do_div(whole_msecs, (1000 * 1000));
26144 decimal_msecs = remainder_ns / 1000;
26145
26146 printk_ratelimited(KERN_INFO
26147 "INFO: NMI handler (%ps) took too long to run: %lld.%03d msecs\n",
26148- a->handler, whole_msecs, decimal_msecs);
26149+ n->action->handler, whole_msecs, decimal_msecs);
26150 }
26151
26152 static int nmi_handle(unsigned int type, struct pt_regs *regs, bool b2b)
26153@@ -134,11 +134,11 @@ static int nmi_handle(unsigned int type, struct pt_regs *regs, bool b2b)
26154 delta = sched_clock() - delta;
26155 trace_nmi_handler(a->handler, (int)delta, thishandled);
26156
26157- if (delta < nmi_longest_ns || delta < a->max_duration)
26158+ if (delta < nmi_longest_ns || delta < a->work->max_duration)
26159 continue;
26160
26161- a->max_duration = delta;
26162- irq_work_queue(&a->irq_work);
26163+ a->work->max_duration = delta;
26164+ irq_work_queue(&a->work->irq_work);
26165 }
26166
26167 rcu_read_unlock();
26168@@ -148,7 +148,7 @@ static int nmi_handle(unsigned int type, struct pt_regs *regs, bool b2b)
26169 }
26170 NOKPROBE_SYMBOL(nmi_handle);
26171
26172-int __register_nmi_handler(unsigned int type, struct nmiaction *action)
26173+int __register_nmi_handler(unsigned int type, const struct nmiaction *action)
26174 {
26175 struct nmi_desc *desc = nmi_to_desc(type);
26176 unsigned long flags;
26177@@ -156,7 +156,8 @@ int __register_nmi_handler(unsigned int type, struct nmiaction *action)
26178 if (!action->handler)
26179 return -EINVAL;
26180
26181- init_irq_work(&action->irq_work, nmi_max_handler);
26182+ action->work->action = action;
26183+ init_irq_work(&action->work->irq_work, nmi_max_handler);
26184
26185 spin_lock_irqsave(&desc->lock, flags);
26186
26187@@ -174,9 +175,9 @@ int __register_nmi_handler(unsigned int type, struct nmiaction *action)
26188 * event confuses some handlers (kdump uses this flag)
26189 */
26190 if (action->flags & NMI_FLAG_FIRST)
26191- list_add_rcu(&action->list, &desc->head);
26192+ pax_list_add_rcu((struct list_head *)&action->list, &desc->head);
26193 else
26194- list_add_tail_rcu(&action->list, &desc->head);
26195+ pax_list_add_tail_rcu((struct list_head *)&action->list, &desc->head);
26196
26197 spin_unlock_irqrestore(&desc->lock, flags);
26198 return 0;
26199@@ -199,7 +200,7 @@ void unregister_nmi_handler(unsigned int type, const char *name)
26200 if (!strcmp(n->name, name)) {
26201 WARN(in_nmi(),
26202 "Trying to free NMI (%s) from NMI context!\n", n->name);
26203- list_del_rcu(&n->list);
26204+ pax_list_del_rcu((struct list_head *)&n->list);
26205 break;
26206 }
26207 }
26208@@ -528,6 +529,17 @@ static inline void nmi_nesting_postprocess(void)
26209 dotraplinkage notrace void
26210 do_nmi(struct pt_regs *regs, long error_code)
26211 {
26212+
26213+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
26214+ if (!user_mode(regs)) {
26215+ unsigned long cs = regs->cs & 0xFFFF;
26216+ unsigned long ip = ktva_ktla(regs->ip);
26217+
26218+ if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
26219+ regs->ip = ip;
26220+ }
26221+#endif
26222+
26223 nmi_nesting_preprocess(regs);
26224
26225 nmi_enter();
26226diff --git a/arch/x86/kernel/nmi_selftest.c b/arch/x86/kernel/nmi_selftest.c
26227index 6d9582e..f746287 100644
26228--- a/arch/x86/kernel/nmi_selftest.c
26229+++ b/arch/x86/kernel/nmi_selftest.c
26230@@ -43,7 +43,7 @@ static void __init init_nmi_testsuite(void)
26231 {
26232 /* trap all the unknown NMIs we may generate */
26233 register_nmi_handler(NMI_UNKNOWN, nmi_unk_cb, 0, "nmi_selftest_unk",
26234- __initdata);
26235+ __initconst);
26236 }
26237
26238 static void __init cleanup_nmi_testsuite(void)
26239@@ -66,7 +66,7 @@ static void __init test_nmi_ipi(struct cpumask *mask)
26240 unsigned long timeout;
26241
26242 if (register_nmi_handler(NMI_LOCAL, test_nmi_ipi_callback,
26243- NMI_FLAG_FIRST, "nmi_selftest", __initdata)) {
26244+ NMI_FLAG_FIRST, "nmi_selftest", __initconst)) {
26245 nmi_fail = FAILURE;
26246 return;
26247 }
26248diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
26249index bbb6c73..24a58ef 100644
26250--- a/arch/x86/kernel/paravirt-spinlocks.c
26251+++ b/arch/x86/kernel/paravirt-spinlocks.c
26252@@ -8,7 +8,7 @@
26253
26254 #include <asm/paravirt.h>
26255
26256-struct pv_lock_ops pv_lock_ops = {
26257+struct pv_lock_ops pv_lock_ops __read_only = {
26258 #ifdef CONFIG_SMP
26259 .lock_spinning = __PV_IS_CALLEE_SAVE(paravirt_nop),
26260 .unlock_kick = paravirt_nop,
26261diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
26262index 548d25f..f8fb99c 100644
26263--- a/arch/x86/kernel/paravirt.c
26264+++ b/arch/x86/kernel/paravirt.c
26265@@ -56,6 +56,9 @@ u64 _paravirt_ident_64(u64 x)
26266 {
26267 return x;
26268 }
26269+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
26270+PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
26271+#endif
26272
26273 void __init default_banner(void)
26274 {
26275@@ -142,16 +145,20 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
26276
26277 if (opfunc == NULL)
26278 /* If there's no function, patch it with a ud2a (BUG) */
26279- ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
26280- else if (opfunc == _paravirt_nop)
26281+ ret = paravirt_patch_insns(insnbuf, len, ktva_ktla(ud2a), ud2a+sizeof(ud2a));
26282+ else if (opfunc == (void *)_paravirt_nop)
26283 /* If the operation is a nop, then nop the callsite */
26284 ret = paravirt_patch_nop();
26285
26286 /* identity functions just return their single argument */
26287- else if (opfunc == _paravirt_ident_32)
26288+ else if (opfunc == (void *)_paravirt_ident_32)
26289 ret = paravirt_patch_ident_32(insnbuf, len);
26290- else if (opfunc == _paravirt_ident_64)
26291+ else if (opfunc == (void *)_paravirt_ident_64)
26292 ret = paravirt_patch_ident_64(insnbuf, len);
26293+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
26294+ else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
26295+ ret = paravirt_patch_ident_64(insnbuf, len);
26296+#endif
26297
26298 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
26299 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
26300@@ -176,7 +183,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
26301 if (insn_len > len || start == NULL)
26302 insn_len = len;
26303 else
26304- memcpy(insnbuf, start, insn_len);
26305+ memcpy(insnbuf, ktla_ktva(start), insn_len);
26306
26307 return insn_len;
26308 }
26309@@ -300,7 +307,7 @@ enum paravirt_lazy_mode paravirt_get_lazy_mode(void)
26310 return this_cpu_read(paravirt_lazy_mode);
26311 }
26312
26313-struct pv_info pv_info = {
26314+struct pv_info pv_info __read_only = {
26315 .name = "bare hardware",
26316 .paravirt_enabled = 0,
26317 .kernel_rpl = 0,
26318@@ -311,16 +318,16 @@ struct pv_info pv_info = {
26319 #endif
26320 };
26321
26322-struct pv_init_ops pv_init_ops = {
26323+struct pv_init_ops pv_init_ops __read_only = {
26324 .patch = native_patch,
26325 };
26326
26327-struct pv_time_ops pv_time_ops = {
26328+struct pv_time_ops pv_time_ops __read_only = {
26329 .sched_clock = native_sched_clock,
26330 .steal_clock = native_steal_clock,
26331 };
26332
26333-__visible struct pv_irq_ops pv_irq_ops = {
26334+__visible struct pv_irq_ops pv_irq_ops __read_only = {
26335 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
26336 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
26337 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
26338@@ -332,7 +339,7 @@ __visible struct pv_irq_ops pv_irq_ops = {
26339 #endif
26340 };
26341
26342-__visible struct pv_cpu_ops pv_cpu_ops = {
26343+__visible struct pv_cpu_ops pv_cpu_ops __read_only = {
26344 .cpuid = native_cpuid,
26345 .get_debugreg = native_get_debugreg,
26346 .set_debugreg = native_set_debugreg,
26347@@ -395,21 +402,26 @@ NOKPROBE_SYMBOL(native_get_debugreg);
26348 NOKPROBE_SYMBOL(native_set_debugreg);
26349 NOKPROBE_SYMBOL(native_load_idt);
26350
26351-struct pv_apic_ops pv_apic_ops = {
26352+struct pv_apic_ops pv_apic_ops __read_only= {
26353 #ifdef CONFIG_X86_LOCAL_APIC
26354 .startup_ipi_hook = paravirt_nop,
26355 #endif
26356 };
26357
26358-#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
26359+#ifdef CONFIG_X86_32
26360+#ifdef CONFIG_X86_PAE
26361+/* 64-bit pagetable entries */
26362+#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
26363+#else
26364 /* 32-bit pagetable entries */
26365 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
26366+#endif
26367 #else
26368 /* 64-bit pagetable entries */
26369 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
26370 #endif
26371
26372-struct pv_mmu_ops pv_mmu_ops = {
26373+struct pv_mmu_ops pv_mmu_ops __read_only = {
26374
26375 .read_cr2 = native_read_cr2,
26376 .write_cr2 = native_write_cr2,
26377@@ -459,6 +471,7 @@ struct pv_mmu_ops pv_mmu_ops = {
26378 .make_pud = PTE_IDENT,
26379
26380 .set_pgd = native_set_pgd,
26381+ .set_pgd_batched = native_set_pgd_batched,
26382 #endif
26383 #endif /* PAGETABLE_LEVELS >= 3 */
26384
26385@@ -479,6 +492,12 @@ struct pv_mmu_ops pv_mmu_ops = {
26386 },
26387
26388 .set_fixmap = native_set_fixmap,
26389+
26390+#ifdef CONFIG_PAX_KERNEXEC
26391+ .pax_open_kernel = native_pax_open_kernel,
26392+ .pax_close_kernel = native_pax_close_kernel,
26393+#endif
26394+
26395 };
26396
26397 EXPORT_SYMBOL_GPL(pv_time_ops);
26398diff --git a/arch/x86/kernel/paravirt_patch_64.c b/arch/x86/kernel/paravirt_patch_64.c
26399index a1da673..b6f5831 100644
26400--- a/arch/x86/kernel/paravirt_patch_64.c
26401+++ b/arch/x86/kernel/paravirt_patch_64.c
26402@@ -9,7 +9,11 @@ DEF_NATIVE(pv_irq_ops, save_fl, "pushfq; popq %rax");
26403 DEF_NATIVE(pv_mmu_ops, read_cr2, "movq %cr2, %rax");
26404 DEF_NATIVE(pv_mmu_ops, read_cr3, "movq %cr3, %rax");
26405 DEF_NATIVE(pv_mmu_ops, write_cr3, "movq %rdi, %cr3");
26406+
26407+#ifndef CONFIG_PAX_MEMORY_UDEREF
26408 DEF_NATIVE(pv_mmu_ops, flush_tlb_single, "invlpg (%rdi)");
26409+#endif
26410+
26411 DEF_NATIVE(pv_cpu_ops, clts, "clts");
26412 DEF_NATIVE(pv_cpu_ops, wbinvd, "wbinvd");
26413
26414@@ -57,7 +61,11 @@ unsigned native_patch(u8 type, u16 clobbers, void *ibuf,
26415 PATCH_SITE(pv_mmu_ops, read_cr3);
26416 PATCH_SITE(pv_mmu_ops, write_cr3);
26417 PATCH_SITE(pv_cpu_ops, clts);
26418+
26419+#ifndef CONFIG_PAX_MEMORY_UDEREF
26420 PATCH_SITE(pv_mmu_ops, flush_tlb_single);
26421+#endif
26422+
26423 PATCH_SITE(pv_cpu_ops, wbinvd);
26424
26425 patch_site:
26426diff --git a/arch/x86/kernel/pci-calgary_64.c b/arch/x86/kernel/pci-calgary_64.c
26427index 0497f71..7186c0d 100644
26428--- a/arch/x86/kernel/pci-calgary_64.c
26429+++ b/arch/x86/kernel/pci-calgary_64.c
26430@@ -1347,7 +1347,7 @@ static void __init get_tce_space_from_tar(void)
26431 tce_space = be64_to_cpu(readq(target));
26432 tce_space = tce_space & TAR_SW_BITS;
26433
26434- tce_space = tce_space & (~specified_table_size);
26435+ tce_space = tce_space & (~(unsigned long)specified_table_size);
26436 info->tce_space = (u64 *)__va(tce_space);
26437 }
26438 }
26439diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
26440index 35ccf75..7a15747 100644
26441--- a/arch/x86/kernel/pci-iommu_table.c
26442+++ b/arch/x86/kernel/pci-iommu_table.c
26443@@ -2,7 +2,7 @@
26444 #include <asm/iommu_table.h>
26445 #include <linux/string.h>
26446 #include <linux/kallsyms.h>
26447-
26448+#include <linux/sched.h>
26449
26450 #define DEBUG 1
26451
26452diff --git a/arch/x86/kernel/pci-swiotlb.c b/arch/x86/kernel/pci-swiotlb.c
26453index 77dd0ad..9ec4723 100644
26454--- a/arch/x86/kernel/pci-swiotlb.c
26455+++ b/arch/x86/kernel/pci-swiotlb.c
26456@@ -33,7 +33,7 @@ void x86_swiotlb_free_coherent(struct device *dev, size_t size,
26457 struct dma_attrs *attrs)
26458 {
26459 if (is_swiotlb_buffer(dma_to_phys(dev, dma_addr)))
26460- swiotlb_free_coherent(dev, size, vaddr, dma_addr);
26461+ swiotlb_free_coherent(dev, size, vaddr, dma_addr, attrs);
26462 else
26463 dma_generic_free_coherent(dev, size, vaddr, dma_addr, attrs);
26464 }
26465diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
26466index e127dda..94e384d 100644
26467--- a/arch/x86/kernel/process.c
26468+++ b/arch/x86/kernel/process.c
26469@@ -36,7 +36,8 @@
26470 * section. Since TSS's are completely CPU-local, we want them
26471 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
26472 */
26473-__visible DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
26474+struct tss_struct init_tss[NR_CPUS] __visible ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
26475+EXPORT_SYMBOL(init_tss);
26476
26477 #ifdef CONFIG_X86_64
26478 static DEFINE_PER_CPU(unsigned char, is_idle);
26479@@ -94,7 +95,7 @@ void arch_task_cache_init(void)
26480 task_xstate_cachep =
26481 kmem_cache_create("task_xstate", xstate_size,
26482 __alignof__(union thread_xstate),
26483- SLAB_PANIC | SLAB_NOTRACK, NULL);
26484+ SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
26485 setup_xstate_comp();
26486 }
26487
26488@@ -108,7 +109,7 @@ void exit_thread(void)
26489 unsigned long *bp = t->io_bitmap_ptr;
26490
26491 if (bp) {
26492- struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
26493+ struct tss_struct *tss = init_tss + get_cpu();
26494
26495 t->io_bitmap_ptr = NULL;
26496 clear_thread_flag(TIF_IO_BITMAP);
26497@@ -128,6 +129,9 @@ void flush_thread(void)
26498 {
26499 struct task_struct *tsk = current;
26500
26501+#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
26502+ loadsegment(gs, 0);
26503+#endif
26504 flush_ptrace_hw_breakpoint(tsk);
26505 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
26506 drop_init_fpu(tsk);
26507@@ -274,7 +278,7 @@ static void __exit_idle(void)
26508 void exit_idle(void)
26509 {
26510 /* idle loop has pid 0 */
26511- if (current->pid)
26512+ if (task_pid_nr(current))
26513 return;
26514 __exit_idle();
26515 }
26516@@ -327,7 +331,7 @@ bool xen_set_default_idle(void)
26517 return ret;
26518 }
26519 #endif
26520-void stop_this_cpu(void *dummy)
26521+__noreturn void stop_this_cpu(void *dummy)
26522 {
26523 local_irq_disable();
26524 /*
26525@@ -456,16 +460,37 @@ static int __init idle_setup(char *str)
26526 }
26527 early_param("idle", idle_setup);
26528
26529-unsigned long arch_align_stack(unsigned long sp)
26530+#ifdef CONFIG_PAX_RANDKSTACK
26531+void pax_randomize_kstack(struct pt_regs *regs)
26532 {
26533- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
26534- sp -= get_random_int() % 8192;
26535- return sp & ~0xf;
26536-}
26537+ struct thread_struct *thread = &current->thread;
26538+ unsigned long time;
26539
26540-unsigned long arch_randomize_brk(struct mm_struct *mm)
26541-{
26542- unsigned long range_end = mm->brk + 0x02000000;
26543- return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
26544-}
26545+ if (!randomize_va_space)
26546+ return;
26547+
26548+ if (v8086_mode(regs))
26549+ return;
26550
26551+ rdtscl(time);
26552+
26553+ /* P4 seems to return a 0 LSB, ignore it */
26554+#ifdef CONFIG_MPENTIUM4
26555+ time &= 0x3EUL;
26556+ time <<= 2;
26557+#elif defined(CONFIG_X86_64)
26558+ time &= 0xFUL;
26559+ time <<= 4;
26560+#else
26561+ time &= 0x1FUL;
26562+ time <<= 3;
26563+#endif
26564+
26565+ thread->sp0 ^= time;
26566+ load_sp0(init_tss + smp_processor_id(), thread);
26567+
26568+#ifdef CONFIG_X86_64
26569+ this_cpu_write(kernel_stack, thread->sp0);
26570+#endif
26571+}
26572+#endif
26573diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
26574index 8f3ebfe..e6ced5a 100644
26575--- a/arch/x86/kernel/process_32.c
26576+++ b/arch/x86/kernel/process_32.c
26577@@ -64,6 +64,7 @@ asmlinkage void ret_from_kernel_thread(void) __asm__("ret_from_kernel_thread");
26578 unsigned long thread_saved_pc(struct task_struct *tsk)
26579 {
26580 return ((unsigned long *)tsk->thread.sp)[3];
26581+//XXX return tsk->thread.eip;
26582 }
26583
26584 void __show_regs(struct pt_regs *regs, int all)
26585@@ -73,19 +74,18 @@ void __show_regs(struct pt_regs *regs, int all)
26586 unsigned long sp;
26587 unsigned short ss, gs;
26588
26589- if (user_mode_vm(regs)) {
26590+ if (user_mode(regs)) {
26591 sp = regs->sp;
26592 ss = regs->ss & 0xffff;
26593- gs = get_user_gs(regs);
26594 } else {
26595 sp = kernel_stack_pointer(regs);
26596 savesegment(ss, ss);
26597- savesegment(gs, gs);
26598 }
26599+ gs = get_user_gs(regs);
26600
26601 printk(KERN_DEFAULT "EIP: %04x:[<%08lx>] EFLAGS: %08lx CPU: %d\n",
26602 (u16)regs->cs, regs->ip, regs->flags,
26603- smp_processor_id());
26604+ raw_smp_processor_id());
26605 print_symbol("EIP is at %s\n", regs->ip);
26606
26607 printk(KERN_DEFAULT "EAX: %08lx EBX: %08lx ECX: %08lx EDX: %08lx\n",
26608@@ -132,21 +132,22 @@ void release_thread(struct task_struct *dead_task)
26609 int copy_thread(unsigned long clone_flags, unsigned long sp,
26610 unsigned long arg, struct task_struct *p)
26611 {
26612- struct pt_regs *childregs = task_pt_regs(p);
26613+ struct pt_regs *childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
26614 struct task_struct *tsk;
26615 int err;
26616
26617 p->thread.sp = (unsigned long) childregs;
26618 p->thread.sp0 = (unsigned long) (childregs+1);
26619+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
26620 memset(p->thread.ptrace_bps, 0, sizeof(p->thread.ptrace_bps));
26621
26622 if (unlikely(p->flags & PF_KTHREAD)) {
26623 /* kernel thread */
26624 memset(childregs, 0, sizeof(struct pt_regs));
26625 p->thread.ip = (unsigned long) ret_from_kernel_thread;
26626- task_user_gs(p) = __KERNEL_STACK_CANARY;
26627- childregs->ds = __USER_DS;
26628- childregs->es = __USER_DS;
26629+ savesegment(gs, childregs->gs);
26630+ childregs->ds = __KERNEL_DS;
26631+ childregs->es = __KERNEL_DS;
26632 childregs->fs = __KERNEL_PERCPU;
26633 childregs->bx = sp; /* function */
26634 childregs->bp = arg;
26635@@ -248,7 +249,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26636 struct thread_struct *prev = &prev_p->thread,
26637 *next = &next_p->thread;
26638 int cpu = smp_processor_id();
26639- struct tss_struct *tss = &per_cpu(init_tss, cpu);
26640+ struct tss_struct *tss = init_tss + cpu;
26641 fpu_switch_t fpu;
26642
26643 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
26644@@ -272,6 +273,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26645 */
26646 lazy_save_gs(prev->gs);
26647
26648+#ifdef CONFIG_PAX_MEMORY_UDEREF
26649+ __set_fs(task_thread_info(next_p)->addr_limit);
26650+#endif
26651+
26652 /*
26653 * Load the per-thread Thread-Local Storage descriptor.
26654 */
26655@@ -310,9 +315,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26656 */
26657 arch_end_context_switch(next_p);
26658
26659- this_cpu_write(kernel_stack,
26660- (unsigned long)task_stack_page(next_p) +
26661- THREAD_SIZE - KERNEL_STACK_OFFSET);
26662+ this_cpu_write(current_task, next_p);
26663+ this_cpu_write(current_tinfo, &next_p->tinfo);
26664+ this_cpu_write(kernel_stack, next->sp0);
26665
26666 /*
26667 * Restore %gs if needed (which is common)
26668@@ -322,8 +327,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26669
26670 switch_fpu_finish(next_p, fpu);
26671
26672- this_cpu_write(current_task, next_p);
26673-
26674 return prev_p;
26675 }
26676
26677@@ -353,4 +356,3 @@ unsigned long get_wchan(struct task_struct *p)
26678 } while (count++ < 16);
26679 return 0;
26680 }
26681-
26682diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
26683index 3ed4a68..ee8f337 100644
26684--- a/arch/x86/kernel/process_64.c
26685+++ b/arch/x86/kernel/process_64.c
26686@@ -158,10 +158,11 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
26687 struct pt_regs *childregs;
26688 struct task_struct *me = current;
26689
26690- p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE;
26691+ p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE - 16;
26692 childregs = task_pt_regs(p);
26693 p->thread.sp = (unsigned long) childregs;
26694 p->thread.usersp = me->thread.usersp;
26695+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
26696 set_tsk_thread_flag(p, TIF_FORK);
26697 p->thread.io_bitmap_ptr = NULL;
26698
26699@@ -171,6 +172,8 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
26700 p->thread.fs = p->thread.fsindex ? 0 : me->thread.fs;
26701 savesegment(es, p->thread.es);
26702 savesegment(ds, p->thread.ds);
26703+ savesegment(ss, p->thread.ss);
26704+ BUG_ON(p->thread.ss == __UDEREF_KERNEL_DS);
26705 memset(p->thread.ptrace_bps, 0, sizeof(p->thread.ptrace_bps));
26706
26707 if (unlikely(p->flags & PF_KTHREAD)) {
26708@@ -277,7 +280,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26709 struct thread_struct *prev = &prev_p->thread;
26710 struct thread_struct *next = &next_p->thread;
26711 int cpu = smp_processor_id();
26712- struct tss_struct *tss = &per_cpu(init_tss, cpu);
26713+ struct tss_struct *tss = init_tss + cpu;
26714 unsigned fsindex, gsindex;
26715 fpu_switch_t fpu;
26716
26717@@ -300,6 +303,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26718 if (unlikely(next->ds | prev->ds))
26719 loadsegment(ds, next->ds);
26720
26721+ savesegment(ss, prev->ss);
26722+ if (unlikely(next->ss != prev->ss))
26723+ loadsegment(ss, next->ss);
26724
26725 /* We must save %fs and %gs before load_TLS() because
26726 * %fs and %gs may be cleared by load_TLS().
26727@@ -359,6 +365,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26728 prev->usersp = this_cpu_read(old_rsp);
26729 this_cpu_write(old_rsp, next->usersp);
26730 this_cpu_write(current_task, next_p);
26731+ this_cpu_write(current_tinfo, &next_p->tinfo);
26732
26733 /*
26734 * If it were not for PREEMPT_ACTIVE we could guarantee that the
26735@@ -368,9 +375,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26736 task_thread_info(prev_p)->saved_preempt_count = this_cpu_read(__preempt_count);
26737 this_cpu_write(__preempt_count, task_thread_info(next_p)->saved_preempt_count);
26738
26739- this_cpu_write(kernel_stack,
26740- (unsigned long)task_stack_page(next_p) +
26741- THREAD_SIZE - KERNEL_STACK_OFFSET);
26742+ this_cpu_write(kernel_stack, next->sp0);
26743
26744 /*
26745 * Now maybe reload the debug registers and handle I/O bitmaps
26746@@ -440,12 +445,11 @@ unsigned long get_wchan(struct task_struct *p)
26747 if (!p || p == current || p->state == TASK_RUNNING)
26748 return 0;
26749 stack = (unsigned long)task_stack_page(p);
26750- if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
26751+ if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
26752 return 0;
26753 fp = *(u64 *)(p->thread.sp);
26754 do {
26755- if (fp < (unsigned long)stack ||
26756- fp >= (unsigned long)stack+THREAD_SIZE)
26757+ if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
26758 return 0;
26759 ip = *(u64 *)(fp+8);
26760 if (!in_sched_functions(ip))
26761diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
26762index e510618..5165ac0 100644
26763--- a/arch/x86/kernel/ptrace.c
26764+++ b/arch/x86/kernel/ptrace.c
26765@@ -186,10 +186,10 @@ unsigned long kernel_stack_pointer(struct pt_regs *regs)
26766 unsigned long sp = (unsigned long)&regs->sp;
26767 u32 *prev_esp;
26768
26769- if (context == (sp & ~(THREAD_SIZE - 1)))
26770+ if (context == ((sp + 8) & ~(THREAD_SIZE - 1)))
26771 return sp;
26772
26773- prev_esp = (u32 *)(context);
26774+ prev_esp = *(u32 **)(context);
26775 if (prev_esp)
26776 return (unsigned long)prev_esp;
26777
26778@@ -452,6 +452,20 @@ static int putreg(struct task_struct *child,
26779 if (child->thread.gs != value)
26780 return do_arch_prctl(child, ARCH_SET_GS, value);
26781 return 0;
26782+
26783+ case offsetof(struct user_regs_struct,ip):
26784+ /*
26785+ * Protect against any attempt to set ip to an
26786+ * impossible address. There are dragons lurking if the
26787+ * address is noncanonical. (This explicitly allows
26788+ * setting ip to TASK_SIZE_MAX, because user code can do
26789+ * that all by itself by running off the end of its
26790+ * address space.
26791+ */
26792+ if (value > TASK_SIZE_MAX)
26793+ return -EIO;
26794+ break;
26795+
26796 #endif
26797 }
26798
26799@@ -588,7 +602,7 @@ static void ptrace_triggered(struct perf_event *bp,
26800 static unsigned long ptrace_get_dr7(struct perf_event *bp[])
26801 {
26802 int i;
26803- int dr7 = 0;
26804+ unsigned long dr7 = 0;
26805 struct arch_hw_breakpoint *info;
26806
26807 for (i = 0; i < HBP_NUM; i++) {
26808@@ -822,7 +836,7 @@ long arch_ptrace(struct task_struct *child, long request,
26809 unsigned long addr, unsigned long data)
26810 {
26811 int ret;
26812- unsigned long __user *datap = (unsigned long __user *)data;
26813+ unsigned long __user *datap = (__force unsigned long __user *)data;
26814
26815 switch (request) {
26816 /* read the word at location addr in the USER area. */
26817@@ -907,14 +921,14 @@ long arch_ptrace(struct task_struct *child, long request,
26818 if ((int) addr < 0)
26819 return -EIO;
26820 ret = do_get_thread_area(child, addr,
26821- (struct user_desc __user *)data);
26822+ (__force struct user_desc __user *) data);
26823 break;
26824
26825 case PTRACE_SET_THREAD_AREA:
26826 if ((int) addr < 0)
26827 return -EIO;
26828 ret = do_set_thread_area(child, addr,
26829- (struct user_desc __user *)data, 0);
26830+ (__force struct user_desc __user *) data, 0);
26831 break;
26832 #endif
26833
26834@@ -1292,7 +1306,7 @@ long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
26835
26836 #ifdef CONFIG_X86_64
26837
26838-static struct user_regset x86_64_regsets[] __read_mostly = {
26839+static user_regset_no_const x86_64_regsets[] __read_only = {
26840 [REGSET_GENERAL] = {
26841 .core_note_type = NT_PRSTATUS,
26842 .n = sizeof(struct user_regs_struct) / sizeof(long),
26843@@ -1333,7 +1347,7 @@ static const struct user_regset_view user_x86_64_view = {
26844 #endif /* CONFIG_X86_64 */
26845
26846 #if defined CONFIG_X86_32 || defined CONFIG_IA32_EMULATION
26847-static struct user_regset x86_32_regsets[] __read_mostly = {
26848+static user_regset_no_const x86_32_regsets[] __read_only = {
26849 [REGSET_GENERAL] = {
26850 .core_note_type = NT_PRSTATUS,
26851 .n = sizeof(struct user_regs_struct32) / sizeof(u32),
26852@@ -1386,7 +1400,7 @@ static const struct user_regset_view user_x86_32_view = {
26853 */
26854 u64 xstate_fx_sw_bytes[USER_XSTATE_FX_SW_WORDS];
26855
26856-void update_regset_xstate_info(unsigned int size, u64 xstate_mask)
26857+void __init update_regset_xstate_info(unsigned int size, u64 xstate_mask)
26858 {
26859 #ifdef CONFIG_X86_64
26860 x86_64_regsets[REGSET_XSTATE].n = size / sizeof(u64);
26861@@ -1421,7 +1435,7 @@ static void fill_sigtrap_info(struct task_struct *tsk,
26862 memset(info, 0, sizeof(*info));
26863 info->si_signo = SIGTRAP;
26864 info->si_code = si_code;
26865- info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
26866+ info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
26867 }
26868
26869 void user_single_step_siginfo(struct task_struct *tsk,
26870@@ -1455,6 +1469,10 @@ static void do_audit_syscall_entry(struct pt_regs *regs, u32 arch)
26871 }
26872 }
26873
26874+#ifdef CONFIG_GRKERNSEC_SETXID
26875+extern void gr_delayed_cred_worker(void);
26876+#endif
26877+
26878 /*
26879 * We can return 0 to resume the syscall or anything else to go to phase
26880 * 2. If we resume the syscall, we need to put something appropriate in
26881@@ -1562,6 +1580,11 @@ long syscall_trace_enter_phase2(struct pt_regs *regs, u32 arch,
26882
26883 BUG_ON(regs != task_pt_regs(current));
26884
26885+#ifdef CONFIG_GRKERNSEC_SETXID
26886+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
26887+ gr_delayed_cred_worker();
26888+#endif
26889+
26890 /*
26891 * If we stepped into a sysenter/syscall insn, it trapped in
26892 * kernel mode; do_debug() cleared TF and set TIF_SINGLESTEP.
26893@@ -1620,6 +1643,11 @@ void syscall_trace_leave(struct pt_regs *regs)
26894 */
26895 user_exit();
26896
26897+#ifdef CONFIG_GRKERNSEC_SETXID
26898+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
26899+ gr_delayed_cred_worker();
26900+#endif
26901+
26902 audit_syscall_exit(regs);
26903
26904 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
26905diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
26906index 2f355d2..e75ed0a 100644
26907--- a/arch/x86/kernel/pvclock.c
26908+++ b/arch/x86/kernel/pvclock.c
26909@@ -51,11 +51,11 @@ void pvclock_touch_watchdogs(void)
26910 reset_hung_task_detector();
26911 }
26912
26913-static atomic64_t last_value = ATOMIC64_INIT(0);
26914+static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
26915
26916 void pvclock_resume(void)
26917 {
26918- atomic64_set(&last_value, 0);
26919+ atomic64_set_unchecked(&last_value, 0);
26920 }
26921
26922 u8 pvclock_read_flags(struct pvclock_vcpu_time_info *src)
26923@@ -105,11 +105,11 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
26924 * updating at the same time, and one of them could be slightly behind,
26925 * making the assumption that last_value always go forward fail to hold.
26926 */
26927- last = atomic64_read(&last_value);
26928+ last = atomic64_read_unchecked(&last_value);
26929 do {
26930 if (ret < last)
26931 return last;
26932- last = atomic64_cmpxchg(&last_value, last, ret);
26933+ last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
26934 } while (unlikely(last != ret));
26935
26936 return ret;
26937diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
26938index 17962e6..47f55db 100644
26939--- a/arch/x86/kernel/reboot.c
26940+++ b/arch/x86/kernel/reboot.c
26941@@ -69,6 +69,11 @@ static int __init set_bios_reboot(const struct dmi_system_id *d)
26942
26943 void __noreturn machine_real_restart(unsigned int type)
26944 {
26945+
26946+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
26947+ struct desc_struct *gdt;
26948+#endif
26949+
26950 local_irq_disable();
26951
26952 /*
26953@@ -96,7 +101,29 @@ void __noreturn machine_real_restart(unsigned int type)
26954
26955 /* Jump to the identity-mapped low memory code */
26956 #ifdef CONFIG_X86_32
26957- asm volatile("jmpl *%0" : :
26958+
26959+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
26960+ gdt = get_cpu_gdt_table(smp_processor_id());
26961+ pax_open_kernel();
26962+#ifdef CONFIG_PAX_MEMORY_UDEREF
26963+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
26964+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
26965+ loadsegment(ds, __KERNEL_DS);
26966+ loadsegment(es, __KERNEL_DS);
26967+ loadsegment(ss, __KERNEL_DS);
26968+#endif
26969+#ifdef CONFIG_PAX_KERNEXEC
26970+ gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
26971+ gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
26972+ gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
26973+ gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
26974+ gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
26975+ gdt[GDT_ENTRY_KERNEL_CS].g = 1;
26976+#endif
26977+ pax_close_kernel();
26978+#endif
26979+
26980+ asm volatile("ljmpl *%0" : :
26981 "rm" (real_mode_header->machine_real_restart_asm),
26982 "a" (type));
26983 #else
26984@@ -500,7 +527,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
26985 * This means that this function can never return, it can misbehave
26986 * by not rebooting properly and hanging.
26987 */
26988-static void native_machine_emergency_restart(void)
26989+static void __noreturn native_machine_emergency_restart(void)
26990 {
26991 int i;
26992 int attempt = 0;
26993@@ -620,13 +647,13 @@ void native_machine_shutdown(void)
26994 #endif
26995 }
26996
26997-static void __machine_emergency_restart(int emergency)
26998+static void __noreturn __machine_emergency_restart(int emergency)
26999 {
27000 reboot_emergency = emergency;
27001 machine_ops.emergency_restart();
27002 }
27003
27004-static void native_machine_restart(char *__unused)
27005+static void __noreturn native_machine_restart(char *__unused)
27006 {
27007 pr_notice("machine restart\n");
27008
27009@@ -635,7 +662,7 @@ static void native_machine_restart(char *__unused)
27010 __machine_emergency_restart(0);
27011 }
27012
27013-static void native_machine_halt(void)
27014+static void __noreturn native_machine_halt(void)
27015 {
27016 /* Stop other cpus and apics */
27017 machine_shutdown();
27018@@ -645,7 +672,7 @@ static void native_machine_halt(void)
27019 stop_this_cpu(NULL);
27020 }
27021
27022-static void native_machine_power_off(void)
27023+static void __noreturn native_machine_power_off(void)
27024 {
27025 if (pm_power_off) {
27026 if (!reboot_force)
27027@@ -654,9 +681,10 @@ static void native_machine_power_off(void)
27028 }
27029 /* A fallback in case there is no PM info available */
27030 tboot_shutdown(TB_SHUTDOWN_HALT);
27031+ unreachable();
27032 }
27033
27034-struct machine_ops machine_ops = {
27035+struct machine_ops machine_ops __read_only = {
27036 .power_off = native_machine_power_off,
27037 .shutdown = native_machine_shutdown,
27038 .emergency_restart = native_machine_emergency_restart,
27039diff --git a/arch/x86/kernel/reboot_fixups_32.c b/arch/x86/kernel/reboot_fixups_32.c
27040index c8e41e9..64049ef 100644
27041--- a/arch/x86/kernel/reboot_fixups_32.c
27042+++ b/arch/x86/kernel/reboot_fixups_32.c
27043@@ -57,7 +57,7 @@ struct device_fixup {
27044 unsigned int vendor;
27045 unsigned int device;
27046 void (*reboot_fixup)(struct pci_dev *);
27047-};
27048+} __do_const;
27049
27050 /*
27051 * PCI ids solely used for fixups_table go here
27052diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
27053index 3fd2c69..a444264 100644
27054--- a/arch/x86/kernel/relocate_kernel_64.S
27055+++ b/arch/x86/kernel/relocate_kernel_64.S
27056@@ -96,8 +96,7 @@ relocate_kernel:
27057
27058 /* jump to identity mapped page */
27059 addq $(identity_mapped - relocate_kernel), %r8
27060- pushq %r8
27061- ret
27062+ jmp *%r8
27063
27064 identity_mapped:
27065 /* set return address to 0 if not preserving context */
27066diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
27067index ab08aa2..6d74a3a 100644
27068--- a/arch/x86/kernel/setup.c
27069+++ b/arch/x86/kernel/setup.c
27070@@ -110,6 +110,7 @@
27071 #include <asm/mce.h>
27072 #include <asm/alternative.h>
27073 #include <asm/prom.h>
27074+#include <asm/boot.h>
27075
27076 /*
27077 * max_low_pfn_mapped: highest direct mapped pfn under 4GB
27078@@ -205,12 +206,50 @@ EXPORT_SYMBOL(boot_cpu_data);
27079 #endif
27080
27081
27082-#if !defined(CONFIG_X86_PAE) || defined(CONFIG_X86_64)
27083-__visible unsigned long mmu_cr4_features;
27084+#ifdef CONFIG_X86_64
27085+__visible unsigned long mmu_cr4_features __read_only = X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE;
27086+#elif defined(CONFIG_X86_PAE)
27087+__visible unsigned long mmu_cr4_features __read_only = X86_CR4_PAE;
27088 #else
27089-__visible unsigned long mmu_cr4_features = X86_CR4_PAE;
27090+__visible unsigned long mmu_cr4_features __read_only;
27091 #endif
27092
27093+void set_in_cr4(unsigned long mask)
27094+{
27095+ unsigned long cr4 = read_cr4();
27096+
27097+ if ((cr4 & mask) == mask && cr4 == mmu_cr4_features)
27098+ return;
27099+
27100+ pax_open_kernel();
27101+ mmu_cr4_features |= mask;
27102+ pax_close_kernel();
27103+
27104+ if (trampoline_cr4_features)
27105+ *trampoline_cr4_features = mmu_cr4_features;
27106+ cr4 |= mask;
27107+ write_cr4(cr4);
27108+}
27109+EXPORT_SYMBOL(set_in_cr4);
27110+
27111+void clear_in_cr4(unsigned long mask)
27112+{
27113+ unsigned long cr4 = read_cr4();
27114+
27115+ if (!(cr4 & mask) && cr4 == mmu_cr4_features)
27116+ return;
27117+
27118+ pax_open_kernel();
27119+ mmu_cr4_features &= ~mask;
27120+ pax_close_kernel();
27121+
27122+ if (trampoline_cr4_features)
27123+ *trampoline_cr4_features = mmu_cr4_features;
27124+ cr4 &= ~mask;
27125+ write_cr4(cr4);
27126+}
27127+EXPORT_SYMBOL(clear_in_cr4);
27128+
27129 /* Boot loader ID and version as integers, for the benefit of proc_dointvec */
27130 int bootloader_type, bootloader_version;
27131
27132@@ -772,7 +811,7 @@ static void __init trim_bios_range(void)
27133 * area (640->1Mb) as ram even though it is not.
27134 * take them out.
27135 */
27136- e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
27137+ e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
27138
27139 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
27140 }
27141@@ -780,7 +819,7 @@ static void __init trim_bios_range(void)
27142 /* called before trim_bios_range() to spare extra sanitize */
27143 static void __init e820_add_kernel_range(void)
27144 {
27145- u64 start = __pa_symbol(_text);
27146+ u64 start = __pa_symbol(ktla_ktva(_text));
27147 u64 size = __pa_symbol(_end) - start;
27148
27149 /*
27150@@ -856,8 +895,12 @@ dump_kernel_offset(struct notifier_block *self, unsigned long v, void *p)
27151
27152 void __init setup_arch(char **cmdline_p)
27153 {
27154+#ifdef CONFIG_X86_32
27155+ memblock_reserve(LOAD_PHYSICAL_ADDR, __pa_symbol(__bss_stop) - LOAD_PHYSICAL_ADDR);
27156+#else
27157 memblock_reserve(__pa_symbol(_text),
27158 (unsigned long)__bss_stop - (unsigned long)_text);
27159+#endif
27160
27161 early_reserve_initrd();
27162
27163@@ -955,14 +998,14 @@ void __init setup_arch(char **cmdline_p)
27164
27165 if (!boot_params.hdr.root_flags)
27166 root_mountflags &= ~MS_RDONLY;
27167- init_mm.start_code = (unsigned long) _text;
27168- init_mm.end_code = (unsigned long) _etext;
27169+ init_mm.start_code = ktla_ktva((unsigned long) _text);
27170+ init_mm.end_code = ktla_ktva((unsigned long) _etext);
27171 init_mm.end_data = (unsigned long) _edata;
27172 init_mm.brk = _brk_end;
27173
27174- code_resource.start = __pa_symbol(_text);
27175- code_resource.end = __pa_symbol(_etext)-1;
27176- data_resource.start = __pa_symbol(_etext);
27177+ code_resource.start = __pa_symbol(ktla_ktva(_text));
27178+ code_resource.end = __pa_symbol(ktla_ktva(_etext))-1;
27179+ data_resource.start = __pa_symbol(_sdata);
27180 data_resource.end = __pa_symbol(_edata)-1;
27181 bss_resource.start = __pa_symbol(__bss_start);
27182 bss_resource.end = __pa_symbol(__bss_stop)-1;
27183diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
27184index 5cdff03..80fa283 100644
27185--- a/arch/x86/kernel/setup_percpu.c
27186+++ b/arch/x86/kernel/setup_percpu.c
27187@@ -21,19 +21,17 @@
27188 #include <asm/cpu.h>
27189 #include <asm/stackprotector.h>
27190
27191-DEFINE_PER_CPU_READ_MOSTLY(int, cpu_number);
27192+#ifdef CONFIG_SMP
27193+DEFINE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
27194 EXPORT_PER_CPU_SYMBOL(cpu_number);
27195+#endif
27196
27197-#ifdef CONFIG_X86_64
27198 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
27199-#else
27200-#define BOOT_PERCPU_OFFSET 0
27201-#endif
27202
27203 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
27204 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
27205
27206-unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
27207+unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
27208 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
27209 };
27210 EXPORT_SYMBOL(__per_cpu_offset);
27211@@ -66,7 +64,7 @@ static bool __init pcpu_need_numa(void)
27212 {
27213 #ifdef CONFIG_NEED_MULTIPLE_NODES
27214 pg_data_t *last = NULL;
27215- unsigned int cpu;
27216+ int cpu;
27217
27218 for_each_possible_cpu(cpu) {
27219 int node = early_cpu_to_node(cpu);
27220@@ -155,10 +153,10 @@ static inline void setup_percpu_segment(int cpu)
27221 {
27222 #ifdef CONFIG_X86_32
27223 struct desc_struct gdt;
27224+ unsigned long base = per_cpu_offset(cpu);
27225
27226- pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
27227- 0x2 | DESCTYPE_S, 0x8);
27228- gdt.s = 1;
27229+ pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
27230+ 0x83 | DESCTYPE_S, 0xC);
27231 write_gdt_entry(get_cpu_gdt_table(cpu),
27232 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
27233 #endif
27234@@ -219,6 +217,11 @@ void __init setup_per_cpu_areas(void)
27235 /* alrighty, percpu areas up and running */
27236 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
27237 for_each_possible_cpu(cpu) {
27238+#ifdef CONFIG_CC_STACKPROTECTOR
27239+#ifdef CONFIG_X86_32
27240+ unsigned long canary = per_cpu(stack_canary.canary, cpu);
27241+#endif
27242+#endif
27243 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
27244 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
27245 per_cpu(cpu_number, cpu) = cpu;
27246@@ -259,6 +262,12 @@ void __init setup_per_cpu_areas(void)
27247 */
27248 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
27249 #endif
27250+#ifdef CONFIG_CC_STACKPROTECTOR
27251+#ifdef CONFIG_X86_32
27252+ if (!cpu)
27253+ per_cpu(stack_canary.canary, cpu) = canary;
27254+#endif
27255+#endif
27256 /*
27257 * Up to this point, the boot CPU has been using .init.data
27258 * area. Reload any changed state for the boot CPU.
27259diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
27260index ed37a76..39f936e 100644
27261--- a/arch/x86/kernel/signal.c
27262+++ b/arch/x86/kernel/signal.c
27263@@ -190,7 +190,7 @@ static unsigned long align_sigframe(unsigned long sp)
27264 * Align the stack pointer according to the i386 ABI,
27265 * i.e. so that on function entry ((sp + 4) & 15) == 0.
27266 */
27267- sp = ((sp + 4) & -16ul) - 4;
27268+ sp = ((sp - 12) & -16ul) - 4;
27269 #else /* !CONFIG_X86_32 */
27270 sp = round_down(sp, 16) - 8;
27271 #endif
27272@@ -298,10 +298,9 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
27273 }
27274
27275 if (current->mm->context.vdso)
27276- restorer = current->mm->context.vdso +
27277- selected_vdso32->sym___kernel_sigreturn;
27278+ restorer = (void __force_user *)(current->mm->context.vdso + selected_vdso32->sym___kernel_sigreturn);
27279 else
27280- restorer = &frame->retcode;
27281+ restorer = (void __user *)&frame->retcode;
27282 if (ksig->ka.sa.sa_flags & SA_RESTORER)
27283 restorer = ksig->ka.sa.sa_restorer;
27284
27285@@ -315,7 +314,7 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
27286 * reasons and because gdb uses it as a signature to notice
27287 * signal handler stack frames.
27288 */
27289- err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
27290+ err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
27291
27292 if (err)
27293 return -EFAULT;
27294@@ -362,8 +361,10 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
27295 save_altstack_ex(&frame->uc.uc_stack, regs->sp);
27296
27297 /* Set up to return from userspace. */
27298- restorer = current->mm->context.vdso +
27299- selected_vdso32->sym___kernel_rt_sigreturn;
27300+ if (current->mm->context.vdso)
27301+ restorer = (void __force_user *)(current->mm->context.vdso + selected_vdso32->sym___kernel_rt_sigreturn);
27302+ else
27303+ restorer = (void __user *)&frame->retcode;
27304 if (ksig->ka.sa.sa_flags & SA_RESTORER)
27305 restorer = ksig->ka.sa.sa_restorer;
27306 put_user_ex(restorer, &frame->pretcode);
27307@@ -375,7 +376,7 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
27308 * reasons and because gdb uses it as a signature to notice
27309 * signal handler stack frames.
27310 */
27311- put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
27312+ put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
27313 } put_user_catch(err);
27314
27315 err |= copy_siginfo_to_user(&frame->info, &ksig->info);
27316@@ -611,7 +612,12 @@ setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
27317 {
27318 int usig = signr_convert(ksig->sig);
27319 sigset_t *set = sigmask_to_save();
27320- compat_sigset_t *cset = (compat_sigset_t *) set;
27321+ sigset_t sigcopy;
27322+ compat_sigset_t *cset;
27323+
27324+ sigcopy = *set;
27325+
27326+ cset = (compat_sigset_t *) &sigcopy;
27327
27328 /* Set up the stack frame */
27329 if (is_ia32_frame()) {
27330@@ -622,7 +628,7 @@ setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
27331 } else if (is_x32_frame()) {
27332 return x32_setup_rt_frame(ksig, cset, regs);
27333 } else {
27334- return __setup_rt_frame(ksig->sig, ksig, set, regs);
27335+ return __setup_rt_frame(ksig->sig, ksig, &sigcopy, regs);
27336 }
27337 }
27338
27339diff --git a/arch/x86/kernel/smp.c b/arch/x86/kernel/smp.c
27340index be8e1bd..a3d93fa 100644
27341--- a/arch/x86/kernel/smp.c
27342+++ b/arch/x86/kernel/smp.c
27343@@ -341,7 +341,7 @@ static int __init nonmi_ipi_setup(char *str)
27344
27345 __setup("nonmi_ipi", nonmi_ipi_setup);
27346
27347-struct smp_ops smp_ops = {
27348+struct smp_ops smp_ops __read_only = {
27349 .smp_prepare_boot_cpu = native_smp_prepare_boot_cpu,
27350 .smp_prepare_cpus = native_smp_prepare_cpus,
27351 .smp_cpus_done = native_smp_cpus_done,
27352diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
27353index 668d8f2..84a9d54 100644
27354--- a/arch/x86/kernel/smpboot.c
27355+++ b/arch/x86/kernel/smpboot.c
27356@@ -194,14 +194,17 @@ static void notrace start_secondary(void *unused)
27357
27358 enable_start_cpu0 = 0;
27359
27360-#ifdef CONFIG_X86_32
27361+ /* otherwise gcc will move up smp_processor_id before the cpu_init */
27362+ barrier();
27363+
27364 /* switch away from the initial page table */
27365+#ifdef CONFIG_PAX_PER_CPU_PGD
27366+ load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
27367+#else
27368 load_cr3(swapper_pg_dir);
27369+#endif
27370 __flush_tlb_all();
27371-#endif
27372
27373- /* otherwise gcc will move up smp_processor_id before the cpu_init */
27374- barrier();
27375 /*
27376 * Check TSC synchronization with the BP:
27377 */
27378@@ -765,8 +768,9 @@ static int do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
27379 alternatives_enable_smp();
27380
27381 idle->thread.sp = (unsigned long) (((struct pt_regs *)
27382- (THREAD_SIZE + task_stack_page(idle))) - 1);
27383+ (THREAD_SIZE - 16 + task_stack_page(idle))) - 1);
27384 per_cpu(current_task, cpu) = idle;
27385+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
27386
27387 #ifdef CONFIG_X86_32
27388 /* Stack for startup_32 can be just as for start_secondary onwards */
27389@@ -775,10 +779,10 @@ static int do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
27390 clear_tsk_thread_flag(idle, TIF_FORK);
27391 initial_gs = per_cpu_offset(cpu);
27392 #endif
27393- per_cpu(kernel_stack, cpu) =
27394- (unsigned long)task_stack_page(idle) -
27395- KERNEL_STACK_OFFSET + THREAD_SIZE;
27396+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
27397+ pax_open_kernel();
27398 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
27399+ pax_close_kernel();
27400 initial_code = (unsigned long)start_secondary;
27401 stack_start = idle->thread.sp;
27402
27403@@ -918,6 +922,15 @@ int native_cpu_up(unsigned int cpu, struct task_struct *tidle)
27404 /* the FPU context is blank, nobody can own it */
27405 __cpu_disable_lazy_restore(cpu);
27406
27407+#ifdef CONFIG_PAX_PER_CPU_PGD
27408+ clone_pgd_range(get_cpu_pgd(cpu, kernel) + KERNEL_PGD_BOUNDARY,
27409+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
27410+ KERNEL_PGD_PTRS);
27411+ clone_pgd_range(get_cpu_pgd(cpu, user) + KERNEL_PGD_BOUNDARY,
27412+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
27413+ KERNEL_PGD_PTRS);
27414+#endif
27415+
27416 err = do_boot_cpu(apicid, cpu, tidle);
27417 if (err) {
27418 pr_err("do_boot_cpu failed(%d) to wakeup CPU#%u\n", err, cpu);
27419diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
27420index 9b4d51d..5d28b58 100644
27421--- a/arch/x86/kernel/step.c
27422+++ b/arch/x86/kernel/step.c
27423@@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
27424 struct desc_struct *desc;
27425 unsigned long base;
27426
27427- seg &= ~7UL;
27428+ seg >>= 3;
27429
27430 mutex_lock(&child->mm->context.lock);
27431- if (unlikely((seg >> 3) >= child->mm->context.size))
27432+ if (unlikely(seg >= child->mm->context.size))
27433 addr = -1L; /* bogus selector, access would fault */
27434 else {
27435 desc = child->mm->context.ldt + seg;
27436@@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
27437 addr += base;
27438 }
27439 mutex_unlock(&child->mm->context.lock);
27440- }
27441+ } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
27442+ addr = ktla_ktva(addr);
27443
27444 return addr;
27445 }
27446@@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
27447 unsigned char opcode[15];
27448 unsigned long addr = convert_ip_to_linear(child, regs);
27449
27450+ if (addr == -EINVAL)
27451+ return 0;
27452+
27453 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
27454 for (i = 0; i < copied; i++) {
27455 switch (opcode[i]) {
27456diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
27457new file mode 100644
27458index 0000000..5877189
27459--- /dev/null
27460+++ b/arch/x86/kernel/sys_i386_32.c
27461@@ -0,0 +1,189 @@
27462+/*
27463+ * This file contains various random system calls that
27464+ * have a non-standard calling sequence on the Linux/i386
27465+ * platform.
27466+ */
27467+
27468+#include <linux/errno.h>
27469+#include <linux/sched.h>
27470+#include <linux/mm.h>
27471+#include <linux/fs.h>
27472+#include <linux/smp.h>
27473+#include <linux/sem.h>
27474+#include <linux/msg.h>
27475+#include <linux/shm.h>
27476+#include <linux/stat.h>
27477+#include <linux/syscalls.h>
27478+#include <linux/mman.h>
27479+#include <linux/file.h>
27480+#include <linux/utsname.h>
27481+#include <linux/ipc.h>
27482+#include <linux/elf.h>
27483+
27484+#include <linux/uaccess.h>
27485+#include <linux/unistd.h>
27486+
27487+#include <asm/syscalls.h>
27488+
27489+int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
27490+{
27491+ unsigned long pax_task_size = TASK_SIZE;
27492+
27493+#ifdef CONFIG_PAX_SEGMEXEC
27494+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
27495+ pax_task_size = SEGMEXEC_TASK_SIZE;
27496+#endif
27497+
27498+ if (flags & MAP_FIXED)
27499+ if (len > pax_task_size || addr > pax_task_size - len)
27500+ return -EINVAL;
27501+
27502+ return 0;
27503+}
27504+
27505+/*
27506+ * Align a virtual address to avoid aliasing in the I$ on AMD F15h.
27507+ */
27508+static unsigned long get_align_mask(void)
27509+{
27510+ if (va_align.flags < 0 || !(va_align.flags & ALIGN_VA_32))
27511+ return 0;
27512+
27513+ if (!(current->flags & PF_RANDOMIZE))
27514+ return 0;
27515+
27516+ return va_align.mask;
27517+}
27518+
27519+unsigned long
27520+arch_get_unmapped_area(struct file *filp, unsigned long addr,
27521+ unsigned long len, unsigned long pgoff, unsigned long flags)
27522+{
27523+ struct mm_struct *mm = current->mm;
27524+ struct vm_area_struct *vma;
27525+ unsigned long pax_task_size = TASK_SIZE;
27526+ struct vm_unmapped_area_info info;
27527+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
27528+
27529+#ifdef CONFIG_PAX_SEGMEXEC
27530+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
27531+ pax_task_size = SEGMEXEC_TASK_SIZE;
27532+#endif
27533+
27534+ pax_task_size -= PAGE_SIZE;
27535+
27536+ if (len > pax_task_size)
27537+ return -ENOMEM;
27538+
27539+ if (flags & MAP_FIXED)
27540+ return addr;
27541+
27542+#ifdef CONFIG_PAX_RANDMMAP
27543+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27544+#endif
27545+
27546+ if (addr) {
27547+ addr = PAGE_ALIGN(addr);
27548+ if (pax_task_size - len >= addr) {
27549+ vma = find_vma(mm, addr);
27550+ if (check_heap_stack_gap(vma, addr, len, offset))
27551+ return addr;
27552+ }
27553+ }
27554+
27555+ info.flags = 0;
27556+ info.length = len;
27557+ info.align_mask = filp ? get_align_mask() : 0;
27558+ info.align_offset = pgoff << PAGE_SHIFT;
27559+ info.threadstack_offset = offset;
27560+
27561+#ifdef CONFIG_PAX_PAGEEXEC
27562+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE)) {
27563+ info.low_limit = 0x00110000UL;
27564+ info.high_limit = mm->start_code;
27565+
27566+#ifdef CONFIG_PAX_RANDMMAP
27567+ if (mm->pax_flags & MF_PAX_RANDMMAP)
27568+ info.low_limit += mm->delta_mmap & 0x03FFF000UL;
27569+#endif
27570+
27571+ if (info.low_limit < info.high_limit) {
27572+ addr = vm_unmapped_area(&info);
27573+ if (!IS_ERR_VALUE(addr))
27574+ return addr;
27575+ }
27576+ } else
27577+#endif
27578+
27579+ info.low_limit = mm->mmap_base;
27580+ info.high_limit = pax_task_size;
27581+
27582+ return vm_unmapped_area(&info);
27583+}
27584+
27585+unsigned long
27586+arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27587+ const unsigned long len, const unsigned long pgoff,
27588+ const unsigned long flags)
27589+{
27590+ struct vm_area_struct *vma;
27591+ struct mm_struct *mm = current->mm;
27592+ unsigned long addr = addr0, pax_task_size = TASK_SIZE;
27593+ struct vm_unmapped_area_info info;
27594+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
27595+
27596+#ifdef CONFIG_PAX_SEGMEXEC
27597+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
27598+ pax_task_size = SEGMEXEC_TASK_SIZE;
27599+#endif
27600+
27601+ pax_task_size -= PAGE_SIZE;
27602+
27603+ /* requested length too big for entire address space */
27604+ if (len > pax_task_size)
27605+ return -ENOMEM;
27606+
27607+ if (flags & MAP_FIXED)
27608+ return addr;
27609+
27610+#ifdef CONFIG_PAX_PAGEEXEC
27611+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
27612+ goto bottomup;
27613+#endif
27614+
27615+#ifdef CONFIG_PAX_RANDMMAP
27616+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27617+#endif
27618+
27619+ /* requesting a specific address */
27620+ if (addr) {
27621+ addr = PAGE_ALIGN(addr);
27622+ if (pax_task_size - len >= addr) {
27623+ vma = find_vma(mm, addr);
27624+ if (check_heap_stack_gap(vma, addr, len, offset))
27625+ return addr;
27626+ }
27627+ }
27628+
27629+ info.flags = VM_UNMAPPED_AREA_TOPDOWN;
27630+ info.length = len;
27631+ info.low_limit = PAGE_SIZE;
27632+ info.high_limit = mm->mmap_base;
27633+ info.align_mask = filp ? get_align_mask() : 0;
27634+ info.align_offset = pgoff << PAGE_SHIFT;
27635+ info.threadstack_offset = offset;
27636+
27637+ addr = vm_unmapped_area(&info);
27638+ if (!(addr & ~PAGE_MASK))
27639+ return addr;
27640+ VM_BUG_ON(addr != -ENOMEM);
27641+
27642+bottomup:
27643+ /*
27644+ * A failed mmap() very likely causes application failure,
27645+ * so fall back to the bottom-up function here. This scenario
27646+ * can happen with large stack limits and large mmap()
27647+ * allocations.
27648+ */
27649+ return arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
27650+}
27651diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
27652index 30277e2..5664a29 100644
27653--- a/arch/x86/kernel/sys_x86_64.c
27654+++ b/arch/x86/kernel/sys_x86_64.c
27655@@ -81,8 +81,8 @@ out:
27656 return error;
27657 }
27658
27659-static void find_start_end(unsigned long flags, unsigned long *begin,
27660- unsigned long *end)
27661+static void find_start_end(struct mm_struct *mm, unsigned long flags,
27662+ unsigned long *begin, unsigned long *end)
27663 {
27664 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT)) {
27665 unsigned long new_begin;
27666@@ -101,7 +101,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
27667 *begin = new_begin;
27668 }
27669 } else {
27670- *begin = current->mm->mmap_legacy_base;
27671+ *begin = mm->mmap_legacy_base;
27672 *end = TASK_SIZE;
27673 }
27674 }
27675@@ -114,20 +114,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
27676 struct vm_area_struct *vma;
27677 struct vm_unmapped_area_info info;
27678 unsigned long begin, end;
27679+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
27680
27681 if (flags & MAP_FIXED)
27682 return addr;
27683
27684- find_start_end(flags, &begin, &end);
27685+ find_start_end(mm, flags, &begin, &end);
27686
27687 if (len > end)
27688 return -ENOMEM;
27689
27690+#ifdef CONFIG_PAX_RANDMMAP
27691+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27692+#endif
27693+
27694 if (addr) {
27695 addr = PAGE_ALIGN(addr);
27696 vma = find_vma(mm, addr);
27697- if (end - len >= addr &&
27698- (!vma || addr + len <= vma->vm_start))
27699+ if (end - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
27700 return addr;
27701 }
27702
27703@@ -137,6 +141,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
27704 info.high_limit = end;
27705 info.align_mask = filp ? get_align_mask() : 0;
27706 info.align_offset = pgoff << PAGE_SHIFT;
27707+ info.threadstack_offset = offset;
27708 return vm_unmapped_area(&info);
27709 }
27710
27711@@ -149,6 +154,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27712 struct mm_struct *mm = current->mm;
27713 unsigned long addr = addr0;
27714 struct vm_unmapped_area_info info;
27715+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
27716
27717 /* requested length too big for entire address space */
27718 if (len > TASK_SIZE)
27719@@ -161,12 +167,15 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27720 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT))
27721 goto bottomup;
27722
27723+#ifdef CONFIG_PAX_RANDMMAP
27724+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27725+#endif
27726+
27727 /* requesting a specific address */
27728 if (addr) {
27729 addr = PAGE_ALIGN(addr);
27730 vma = find_vma(mm, addr);
27731- if (TASK_SIZE - len >= addr &&
27732- (!vma || addr + len <= vma->vm_start))
27733+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
27734 return addr;
27735 }
27736
27737@@ -176,6 +185,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27738 info.high_limit = mm->mmap_base;
27739 info.align_mask = filp ? get_align_mask() : 0;
27740 info.align_offset = pgoff << PAGE_SHIFT;
27741+ info.threadstack_offset = offset;
27742 addr = vm_unmapped_area(&info);
27743 if (!(addr & ~PAGE_MASK))
27744 return addr;
27745diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
27746index 91a4496..bb87552 100644
27747--- a/arch/x86/kernel/tboot.c
27748+++ b/arch/x86/kernel/tboot.c
27749@@ -221,7 +221,7 @@ static int tboot_setup_sleep(void)
27750
27751 void tboot_shutdown(u32 shutdown_type)
27752 {
27753- void (*shutdown)(void);
27754+ void (* __noreturn shutdown)(void);
27755
27756 if (!tboot_enabled())
27757 return;
27758@@ -243,7 +243,7 @@ void tboot_shutdown(u32 shutdown_type)
27759
27760 switch_to_tboot_pt();
27761
27762- shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
27763+ shutdown = (void *)(unsigned long)tboot->shutdown_entry;
27764 shutdown();
27765
27766 /* should not reach here */
27767@@ -310,7 +310,7 @@ static int tboot_extended_sleep(u8 sleep_state, u32 val_a, u32 val_b)
27768 return -ENODEV;
27769 }
27770
27771-static atomic_t ap_wfs_count;
27772+static atomic_unchecked_t ap_wfs_count;
27773
27774 static int tboot_wait_for_aps(int num_aps)
27775 {
27776@@ -334,9 +334,9 @@ static int tboot_cpu_callback(struct notifier_block *nfb, unsigned long action,
27777 {
27778 switch (action) {
27779 case CPU_DYING:
27780- atomic_inc(&ap_wfs_count);
27781+ atomic_inc_unchecked(&ap_wfs_count);
27782 if (num_online_cpus() == 1)
27783- if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
27784+ if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
27785 return NOTIFY_BAD;
27786 break;
27787 }
27788@@ -422,7 +422,7 @@ static __init int tboot_late_init(void)
27789
27790 tboot_create_trampoline();
27791
27792- atomic_set(&ap_wfs_count, 0);
27793+ atomic_set_unchecked(&ap_wfs_count, 0);
27794 register_hotcpu_notifier(&tboot_cpu_notifier);
27795
27796 #ifdef CONFIG_DEBUG_FS
27797diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
27798index 0fa2960..91eabbe 100644
27799--- a/arch/x86/kernel/time.c
27800+++ b/arch/x86/kernel/time.c
27801@@ -30,9 +30,9 @@ unsigned long profile_pc(struct pt_regs *regs)
27802 {
27803 unsigned long pc = instruction_pointer(regs);
27804
27805- if (!user_mode_vm(regs) && in_lock_functions(pc)) {
27806+ if (!user_mode(regs) && in_lock_functions(pc)) {
27807 #ifdef CONFIG_FRAME_POINTER
27808- return *(unsigned long *)(regs->bp + sizeof(long));
27809+ return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
27810 #else
27811 unsigned long *sp =
27812 (unsigned long *)kernel_stack_pointer(regs);
27813@@ -41,11 +41,17 @@ unsigned long profile_pc(struct pt_regs *regs)
27814 * or above a saved flags. Eflags has bits 22-31 zero,
27815 * kernel addresses don't.
27816 */
27817+
27818+#ifdef CONFIG_PAX_KERNEXEC
27819+ return ktla_ktva(sp[0]);
27820+#else
27821 if (sp[0] >> 22)
27822 return sp[0];
27823 if (sp[1] >> 22)
27824 return sp[1];
27825 #endif
27826+
27827+#endif
27828 }
27829 return pc;
27830 }
27831diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
27832index f7fec09..d0f623f 100644
27833--- a/arch/x86/kernel/tls.c
27834+++ b/arch/x86/kernel/tls.c
27835@@ -27,6 +27,37 @@ static int get_free_idx(void)
27836 return -ESRCH;
27837 }
27838
27839+static bool tls_desc_okay(const struct user_desc *info)
27840+{
27841+ if (LDT_empty(info))
27842+ return true;
27843+
27844+ /*
27845+ * espfix is required for 16-bit data segments, but espfix
27846+ * only works for LDT segments.
27847+ */
27848+ if (!info->seg_32bit)
27849+ return false;
27850+
27851+ /* Only allow data segments in the TLS array. */
27852+ if (info->contents > 1)
27853+ return false;
27854+
27855+ /*
27856+ * Non-present segments with DPL 3 present an interesting attack
27857+ * surface. The kernel should handle such segments correctly,
27858+ * but TLS is very difficult to protect in a sandbox, so prevent
27859+ * such segments from being created.
27860+ *
27861+ * If userspace needs to remove a TLS entry, it can still delete
27862+ * it outright.
27863+ */
27864+ if (info->seg_not_present)
27865+ return false;
27866+
27867+ return true;
27868+}
27869+
27870 static void set_tls_desc(struct task_struct *p, int idx,
27871 const struct user_desc *info, int n)
27872 {
27873@@ -66,6 +97,9 @@ int do_set_thread_area(struct task_struct *p, int idx,
27874 if (copy_from_user(&info, u_info, sizeof(info)))
27875 return -EFAULT;
27876
27877+ if (!tls_desc_okay(&info))
27878+ return -EINVAL;
27879+
27880 if (idx == -1)
27881 idx = info.entry_number;
27882
27883@@ -84,6 +118,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
27884 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
27885 return -EINVAL;
27886
27887+#ifdef CONFIG_PAX_SEGMEXEC
27888+ if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
27889+ return -EINVAL;
27890+#endif
27891+
27892 set_tls_desc(p, idx, &info, 1);
27893
27894 return 0;
27895@@ -192,6 +231,7 @@ int regset_tls_set(struct task_struct *target, const struct user_regset *regset,
27896 {
27897 struct user_desc infobuf[GDT_ENTRY_TLS_ENTRIES];
27898 const struct user_desc *info;
27899+ int i;
27900
27901 if (pos >= GDT_ENTRY_TLS_ENTRIES * sizeof(struct user_desc) ||
27902 (pos % sizeof(struct user_desc)) != 0 ||
27903@@ -200,11 +240,15 @@ int regset_tls_set(struct task_struct *target, const struct user_regset *regset,
27904
27905 if (kbuf)
27906 info = kbuf;
27907- else if (__copy_from_user(infobuf, ubuf, count))
27908+ else if (count > sizeof infobuf || __copy_from_user(infobuf, ubuf, count))
27909 return -EFAULT;
27910 else
27911 info = infobuf;
27912
27913+ for (i = 0; i < count / sizeof(struct user_desc); i++)
27914+ if (!tls_desc_okay(info + i))
27915+ return -EINVAL;
27916+
27917 set_tls_desc(target,
27918 GDT_ENTRY_TLS_MIN + (pos / sizeof(struct user_desc)),
27919 info, count / sizeof(struct user_desc));
27920diff --git a/arch/x86/kernel/tracepoint.c b/arch/x86/kernel/tracepoint.c
27921index 1c113db..287b42e 100644
27922--- a/arch/x86/kernel/tracepoint.c
27923+++ b/arch/x86/kernel/tracepoint.c
27924@@ -9,11 +9,11 @@
27925 #include <linux/atomic.h>
27926
27927 atomic_t trace_idt_ctr = ATOMIC_INIT(0);
27928-struct desc_ptr trace_idt_descr = { NR_VECTORS * 16 - 1,
27929+const struct desc_ptr trace_idt_descr = { NR_VECTORS * 16 - 1,
27930 (unsigned long) trace_idt_table };
27931
27932 /* No need to be aligned, but done to keep all IDTs defined the same way. */
27933-gate_desc trace_idt_table[NR_VECTORS] __page_aligned_bss;
27934+gate_desc trace_idt_table[NR_VECTORS] __page_aligned_rodata;
27935
27936 static int trace_irq_vector_refcount;
27937 static DEFINE_MUTEX(irq_vector_mutex);
27938diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
27939index de801f2..f189dcf 100644
27940--- a/arch/x86/kernel/traps.c
27941+++ b/arch/x86/kernel/traps.c
27942@@ -67,7 +67,7 @@
27943 #include <asm/proto.h>
27944
27945 /* No need to be aligned, but done to keep all IDTs defined the same way. */
27946-gate_desc debug_idt_table[NR_VECTORS] __page_aligned_bss;
27947+gate_desc debug_idt_table[NR_VECTORS] __page_aligned_rodata;
27948 #else
27949 #include <asm/processor-flags.h>
27950 #include <asm/setup.h>
27951@@ -76,7 +76,7 @@ asmlinkage int system_call(void);
27952 #endif
27953
27954 /* Must be page-aligned because the real IDT is used in a fixmap. */
27955-gate_desc idt_table[NR_VECTORS] __page_aligned_bss;
27956+gate_desc idt_table[NR_VECTORS] __page_aligned_rodata;
27957
27958 DECLARE_BITMAP(used_vectors, NR_VECTORS);
27959 EXPORT_SYMBOL_GPL(used_vectors);
27960@@ -108,11 +108,11 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
27961 }
27962
27963 static nokprobe_inline int
27964-do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
27965+do_trap_no_signal(struct task_struct *tsk, int trapnr, const char *str,
27966 struct pt_regs *regs, long error_code)
27967 {
27968 #ifdef CONFIG_X86_32
27969- if (regs->flags & X86_VM_MASK) {
27970+ if (v8086_mode(regs)) {
27971 /*
27972 * Traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
27973 * On nmi (interrupt 2), do_trap should not be called.
27974@@ -125,12 +125,24 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
27975 return -1;
27976 }
27977 #endif
27978- if (!user_mode(regs)) {
27979+ if (!user_mode_novm(regs)) {
27980 if (!fixup_exception(regs)) {
27981 tsk->thread.error_code = error_code;
27982 tsk->thread.trap_nr = trapnr;
27983+
27984+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
27985+ if (trapnr == X86_TRAP_SS && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
27986+ str = "PAX: suspicious stack segment fault";
27987+#endif
27988+
27989 die(str, regs, error_code);
27990 }
27991+
27992+#ifdef CONFIG_PAX_REFCOUNT
27993+ if (trapnr == X86_TRAP_OF)
27994+ pax_report_refcount_overflow(regs);
27995+#endif
27996+
27997 return 0;
27998 }
27999
28000@@ -169,7 +181,7 @@ static siginfo_t *fill_trap_info(struct pt_regs *regs, int signr, int trapnr,
28001 }
28002
28003 static void
28004-do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
28005+do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
28006 long error_code, siginfo_t *info)
28007 {
28008 struct task_struct *tsk = current;
28009@@ -193,7 +205,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
28010 if (show_unhandled_signals && unhandled_signal(tsk, signr) &&
28011 printk_ratelimit()) {
28012 pr_info("%s[%d] trap %s ip:%lx sp:%lx error:%lx",
28013- tsk->comm, tsk->pid, str,
28014+ tsk->comm, task_pid_nr(tsk), str,
28015 regs->ip, regs->sp, error_code);
28016 print_vma_addr(" in ", regs->ip);
28017 pr_cont("\n");
28018@@ -274,6 +286,11 @@ dotraplinkage void do_double_fault(struct pt_regs *regs, long error_code)
28019 tsk->thread.error_code = error_code;
28020 tsk->thread.trap_nr = X86_TRAP_DF;
28021
28022+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
28023+ if ((unsigned long)tsk->stack - regs->sp <= PAGE_SIZE)
28024+ die("grsec: kernel stack overflow detected", regs, error_code);
28025+#endif
28026+
28027 #ifdef CONFIG_DOUBLEFAULT
28028 df_debug(regs, error_code);
28029 #endif
28030@@ -296,7 +313,7 @@ do_general_protection(struct pt_regs *regs, long error_code)
28031 conditional_sti(regs);
28032
28033 #ifdef CONFIG_X86_32
28034- if (regs->flags & X86_VM_MASK) {
28035+ if (v8086_mode(regs)) {
28036 local_irq_enable();
28037 handle_vm86_fault((struct kernel_vm86_regs *) regs, error_code);
28038 goto exit;
28039@@ -304,18 +321,42 @@ do_general_protection(struct pt_regs *regs, long error_code)
28040 #endif
28041
28042 tsk = current;
28043- if (!user_mode(regs)) {
28044+ if (!user_mode_novm(regs)) {
28045 if (fixup_exception(regs))
28046 goto exit;
28047
28048 tsk->thread.error_code = error_code;
28049 tsk->thread.trap_nr = X86_TRAP_GP;
28050 if (notify_die(DIE_GPF, "general protection fault", regs, error_code,
28051- X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP)
28052+ X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP) {
28053+
28054+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
28055+ if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
28056+ die("PAX: suspicious general protection fault", regs, error_code);
28057+ else
28058+#endif
28059+
28060 die("general protection fault", regs, error_code);
28061+ }
28062 goto exit;
28063 }
28064
28065+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
28066+ if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
28067+ struct mm_struct *mm = tsk->mm;
28068+ unsigned long limit;
28069+
28070+ down_write(&mm->mmap_sem);
28071+ limit = mm->context.user_cs_limit;
28072+ if (limit < TASK_SIZE) {
28073+ track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
28074+ up_write(&mm->mmap_sem);
28075+ return;
28076+ }
28077+ up_write(&mm->mmap_sem);
28078+ }
28079+#endif
28080+
28081 tsk->thread.error_code = error_code;
28082 tsk->thread.trap_nr = X86_TRAP_GP;
28083
28084@@ -433,7 +474,7 @@ struct bad_iret_stack *fixup_bad_iret(struct bad_iret_stack *s)
28085 /* Copy the remainder of the stack from the current stack. */
28086 memmove(new_stack, s, offsetof(struct bad_iret_stack, regs.ip));
28087
28088- BUG_ON(!user_mode_vm(&new_stack->regs));
28089+ BUG_ON(!user_mode(&new_stack->regs));
28090 return new_stack;
28091 }
28092 #endif
28093@@ -518,7 +559,7 @@ dotraplinkage void do_debug(struct pt_regs *regs, long error_code)
28094 /* It's safe to allow irq's after DR6 has been saved */
28095 preempt_conditional_sti(regs);
28096
28097- if (regs->flags & X86_VM_MASK) {
28098+ if (v8086_mode(regs)) {
28099 handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code,
28100 X86_TRAP_DB);
28101 preempt_conditional_cli(regs);
28102@@ -533,7 +574,7 @@ dotraplinkage void do_debug(struct pt_regs *regs, long error_code)
28103 * We already checked v86 mode above, so we can check for kernel mode
28104 * by just checking the CPL of CS.
28105 */
28106- if ((dr6 & DR_STEP) && !user_mode(regs)) {
28107+ if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
28108 tsk->thread.debugreg6 &= ~DR_STEP;
28109 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
28110 regs->flags &= ~X86_EFLAGS_TF;
28111@@ -566,7 +607,7 @@ static void math_error(struct pt_regs *regs, int error_code, int trapnr)
28112 return;
28113 conditional_sti(regs);
28114
28115- if (!user_mode_vm(regs))
28116+ if (!user_mode(regs))
28117 {
28118 if (!fixup_exception(regs)) {
28119 task->thread.error_code = error_code;
28120diff --git a/arch/x86/kernel/tsc.c b/arch/x86/kernel/tsc.c
28121index b7e50bb..f4a93ae 100644
28122--- a/arch/x86/kernel/tsc.c
28123+++ b/arch/x86/kernel/tsc.c
28124@@ -150,7 +150,7 @@ static void cyc2ns_write_end(int cpu, struct cyc2ns_data *data)
28125 */
28126 smp_wmb();
28127
28128- ACCESS_ONCE(c2n->head) = data;
28129+ ACCESS_ONCE_RW(c2n->head) = data;
28130 }
28131
28132 /*
28133diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c
28134index 5d1cbfe..2a21feb 100644
28135--- a/arch/x86/kernel/uprobes.c
28136+++ b/arch/x86/kernel/uprobes.c
28137@@ -845,7 +845,7 @@ int arch_uprobe_exception_notify(struct notifier_block *self, unsigned long val,
28138 int ret = NOTIFY_DONE;
28139
28140 /* We are only interested in userspace traps */
28141- if (regs && !user_mode_vm(regs))
28142+ if (regs && !user_mode(regs))
28143 return NOTIFY_DONE;
28144
28145 switch (val) {
28146@@ -919,7 +919,7 @@ arch_uretprobe_hijack_return_addr(unsigned long trampoline_vaddr, struct pt_regs
28147
28148 if (nleft != rasize) {
28149 pr_err("uprobe: return address clobbered: pid=%d, %%sp=%#lx, "
28150- "%%ip=%#lx\n", current->pid, regs->sp, regs->ip);
28151+ "%%ip=%#lx\n", task_pid_nr(current), regs->sp, regs->ip);
28152
28153 force_sig_info(SIGSEGV, SEND_SIG_FORCED, current);
28154 }
28155diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
28156index b9242ba..50c5edd 100644
28157--- a/arch/x86/kernel/verify_cpu.S
28158+++ b/arch/x86/kernel/verify_cpu.S
28159@@ -20,6 +20,7 @@
28160 * arch/x86/boot/compressed/head_64.S: Boot cpu verification
28161 * arch/x86/kernel/trampoline_64.S: secondary processor verification
28162 * arch/x86/kernel/head_32.S: processor startup
28163+ * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
28164 *
28165 * verify_cpu, returns the status of longmode and SSE in register %eax.
28166 * 0: Success 1: Failure
28167diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
28168index e8edcf5..27f9344 100644
28169--- a/arch/x86/kernel/vm86_32.c
28170+++ b/arch/x86/kernel/vm86_32.c
28171@@ -44,6 +44,7 @@
28172 #include <linux/ptrace.h>
28173 #include <linux/audit.h>
28174 #include <linux/stddef.h>
28175+#include <linux/grsecurity.h>
28176
28177 #include <asm/uaccess.h>
28178 #include <asm/io.h>
28179@@ -150,7 +151,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
28180 do_exit(SIGSEGV);
28181 }
28182
28183- tss = &per_cpu(init_tss, get_cpu());
28184+ tss = init_tss + get_cpu();
28185 current->thread.sp0 = current->thread.saved_sp0;
28186 current->thread.sysenter_cs = __KERNEL_CS;
28187 load_sp0(tss, &current->thread);
28188@@ -214,6 +215,14 @@ SYSCALL_DEFINE1(vm86old, struct vm86_struct __user *, v86)
28189
28190 if (tsk->thread.saved_sp0)
28191 return -EPERM;
28192+
28193+#ifdef CONFIG_GRKERNSEC_VM86
28194+ if (!capable(CAP_SYS_RAWIO)) {
28195+ gr_handle_vm86();
28196+ return -EPERM;
28197+ }
28198+#endif
28199+
28200 tmp = copy_vm86_regs_from_user(&info.regs, &v86->regs,
28201 offsetof(struct kernel_vm86_struct, vm86plus) -
28202 sizeof(info.regs));
28203@@ -238,6 +247,13 @@ SYSCALL_DEFINE2(vm86, unsigned long, cmd, unsigned long, arg)
28204 int tmp;
28205 struct vm86plus_struct __user *v86;
28206
28207+#ifdef CONFIG_GRKERNSEC_VM86
28208+ if (!capable(CAP_SYS_RAWIO)) {
28209+ gr_handle_vm86();
28210+ return -EPERM;
28211+ }
28212+#endif
28213+
28214 tsk = current;
28215 switch (cmd) {
28216 case VM86_REQUEST_IRQ:
28217@@ -318,7 +334,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
28218 tsk->thread.saved_fs = info->regs32->fs;
28219 tsk->thread.saved_gs = get_user_gs(info->regs32);
28220
28221- tss = &per_cpu(init_tss, get_cpu());
28222+ tss = init_tss + get_cpu();
28223 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
28224 if (cpu_has_sep)
28225 tsk->thread.sysenter_cs = 0;
28226@@ -525,7 +541,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
28227 goto cannot_handle;
28228 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
28229 goto cannot_handle;
28230- intr_ptr = (unsigned long __user *) (i << 2);
28231+ intr_ptr = (__force unsigned long __user *) (i << 2);
28232 if (get_user(segoffs, intr_ptr))
28233 goto cannot_handle;
28234 if ((segoffs >> 16) == BIOSSEG)
28235diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
28236index 49edf2d..c0d1362 100644
28237--- a/arch/x86/kernel/vmlinux.lds.S
28238+++ b/arch/x86/kernel/vmlinux.lds.S
28239@@ -26,6 +26,13 @@
28240 #include <asm/page_types.h>
28241 #include <asm/cache.h>
28242 #include <asm/boot.h>
28243+#include <asm/segment.h>
28244+
28245+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
28246+#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
28247+#else
28248+#define __KERNEL_TEXT_OFFSET 0
28249+#endif
28250
28251 #undef i386 /* in case the preprocessor is a 32bit one */
28252
28253@@ -69,30 +76,43 @@ jiffies_64 = jiffies;
28254
28255 PHDRS {
28256 text PT_LOAD FLAGS(5); /* R_E */
28257+#ifdef CONFIG_X86_32
28258+ module PT_LOAD FLAGS(5); /* R_E */
28259+#endif
28260+#ifdef CONFIG_XEN
28261+ rodata PT_LOAD FLAGS(5); /* R_E */
28262+#else
28263+ rodata PT_LOAD FLAGS(4); /* R__ */
28264+#endif
28265 data PT_LOAD FLAGS(6); /* RW_ */
28266-#ifdef CONFIG_X86_64
28267+ init.begin PT_LOAD FLAGS(6); /* RW_ */
28268 #ifdef CONFIG_SMP
28269 percpu PT_LOAD FLAGS(6); /* RW_ */
28270 #endif
28271+ text.init PT_LOAD FLAGS(5); /* R_E */
28272+ text.exit PT_LOAD FLAGS(5); /* R_E */
28273 init PT_LOAD FLAGS(7); /* RWE */
28274-#endif
28275 note PT_NOTE FLAGS(0); /* ___ */
28276 }
28277
28278 SECTIONS
28279 {
28280 #ifdef CONFIG_X86_32
28281- . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
28282- phys_startup_32 = startup_32 - LOAD_OFFSET;
28283+ . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
28284 #else
28285- . = __START_KERNEL;
28286- phys_startup_64 = startup_64 - LOAD_OFFSET;
28287+ . = __START_KERNEL;
28288 #endif
28289
28290 /* Text and read-only data */
28291- .text : AT(ADDR(.text) - LOAD_OFFSET) {
28292- _text = .;
28293+ .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
28294 /* bootstrapping code */
28295+#ifdef CONFIG_X86_32
28296+ phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
28297+#else
28298+ phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
28299+#endif
28300+ __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
28301+ _text = .;
28302 HEAD_TEXT
28303 . = ALIGN(8);
28304 _stext = .;
28305@@ -104,13 +124,47 @@ SECTIONS
28306 IRQENTRY_TEXT
28307 *(.fixup)
28308 *(.gnu.warning)
28309- /* End of text section */
28310- _etext = .;
28311 } :text = 0x9090
28312
28313- NOTES :text :note
28314+ . += __KERNEL_TEXT_OFFSET;
28315
28316- EXCEPTION_TABLE(16) :text = 0x9090
28317+#ifdef CONFIG_X86_32
28318+ . = ALIGN(PAGE_SIZE);
28319+ .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
28320+
28321+#ifdef CONFIG_PAX_KERNEXEC
28322+ MODULES_EXEC_VADDR = .;
28323+ BYTE(0)
28324+ . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
28325+ . = ALIGN(HPAGE_SIZE) - 1;
28326+ MODULES_EXEC_END = .;
28327+#endif
28328+
28329+ } :module
28330+#endif
28331+
28332+ .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
28333+ /* End of text section */
28334+ BYTE(0)
28335+ _etext = . - __KERNEL_TEXT_OFFSET;
28336+ }
28337+
28338+#ifdef CONFIG_X86_32
28339+ . = ALIGN(PAGE_SIZE);
28340+ .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
28341+ . = ALIGN(PAGE_SIZE);
28342+ *(.empty_zero_page)
28343+ *(.initial_pg_fixmap)
28344+ *(.initial_pg_pmd)
28345+ *(.initial_page_table)
28346+ *(.swapper_pg_dir)
28347+ } :rodata
28348+#endif
28349+
28350+ . = ALIGN(PAGE_SIZE);
28351+ NOTES :rodata :note
28352+
28353+ EXCEPTION_TABLE(16) :rodata
28354
28355 #if defined(CONFIG_DEBUG_RODATA)
28356 /* .text should occupy whole number of pages */
28357@@ -122,16 +176,20 @@ SECTIONS
28358
28359 /* Data */
28360 .data : AT(ADDR(.data) - LOAD_OFFSET) {
28361+
28362+#ifdef CONFIG_PAX_KERNEXEC
28363+ . = ALIGN(HPAGE_SIZE);
28364+#else
28365+ . = ALIGN(PAGE_SIZE);
28366+#endif
28367+
28368 /* Start of data section */
28369 _sdata = .;
28370
28371 /* init_task */
28372 INIT_TASK_DATA(THREAD_SIZE)
28373
28374-#ifdef CONFIG_X86_32
28375- /* 32 bit has nosave before _edata */
28376 NOSAVE_DATA
28377-#endif
28378
28379 PAGE_ALIGNED_DATA(PAGE_SIZE)
28380
28381@@ -174,12 +232,19 @@ SECTIONS
28382 . = ALIGN(__vvar_page + PAGE_SIZE, PAGE_SIZE);
28383
28384 /* Init code and data - will be freed after init */
28385- . = ALIGN(PAGE_SIZE);
28386 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
28387+ BYTE(0)
28388+
28389+#ifdef CONFIG_PAX_KERNEXEC
28390+ . = ALIGN(HPAGE_SIZE);
28391+#else
28392+ . = ALIGN(PAGE_SIZE);
28393+#endif
28394+
28395 __init_begin = .; /* paired with __init_end */
28396- }
28397+ } :init.begin
28398
28399-#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
28400+#ifdef CONFIG_SMP
28401 /*
28402 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
28403 * output PHDR, so the next output section - .init.text - should
28404@@ -188,12 +253,27 @@ SECTIONS
28405 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
28406 #endif
28407
28408- INIT_TEXT_SECTION(PAGE_SIZE)
28409-#ifdef CONFIG_X86_64
28410- :init
28411-#endif
28412+ . = ALIGN(PAGE_SIZE);
28413+ init_begin = .;
28414+ .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
28415+ VMLINUX_SYMBOL(_sinittext) = .;
28416+ INIT_TEXT
28417+ VMLINUX_SYMBOL(_einittext) = .;
28418+ . = ALIGN(PAGE_SIZE);
28419+ } :text.init
28420
28421- INIT_DATA_SECTION(16)
28422+ /*
28423+ * .exit.text is discard at runtime, not link time, to deal with
28424+ * references from .altinstructions and .eh_frame
28425+ */
28426+ .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
28427+ EXIT_TEXT
28428+ . = ALIGN(16);
28429+ } :text.exit
28430+ . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
28431+
28432+ . = ALIGN(PAGE_SIZE);
28433+ INIT_DATA_SECTION(16) :init
28434
28435 .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
28436 __x86_cpu_dev_start = .;
28437@@ -264,19 +344,12 @@ SECTIONS
28438 }
28439
28440 . = ALIGN(8);
28441- /*
28442- * .exit.text is discard at runtime, not link time, to deal with
28443- * references from .altinstructions and .eh_frame
28444- */
28445- .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
28446- EXIT_TEXT
28447- }
28448
28449 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
28450 EXIT_DATA
28451 }
28452
28453-#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
28454+#ifndef CONFIG_SMP
28455 PERCPU_SECTION(INTERNODE_CACHE_BYTES)
28456 #endif
28457
28458@@ -295,16 +368,10 @@ SECTIONS
28459 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
28460 __smp_locks = .;
28461 *(.smp_locks)
28462- . = ALIGN(PAGE_SIZE);
28463 __smp_locks_end = .;
28464+ . = ALIGN(PAGE_SIZE);
28465 }
28466
28467-#ifdef CONFIG_X86_64
28468- .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
28469- NOSAVE_DATA
28470- }
28471-#endif
28472-
28473 /* BSS */
28474 . = ALIGN(PAGE_SIZE);
28475 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
28476@@ -320,6 +387,7 @@ SECTIONS
28477 __brk_base = .;
28478 . += 64 * 1024; /* 64k alignment slop space */
28479 *(.brk_reservation) /* areas brk users have reserved */
28480+ . = ALIGN(HPAGE_SIZE);
28481 __brk_limit = .;
28482 }
28483
28484@@ -346,13 +414,12 @@ SECTIONS
28485 * for the boot processor.
28486 */
28487 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
28488-INIT_PER_CPU(gdt_page);
28489 INIT_PER_CPU(irq_stack_union);
28490
28491 /*
28492 * Build-time check on the image size:
28493 */
28494-. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
28495+. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
28496 "kernel image bigger than KERNEL_IMAGE_SIZE");
28497
28498 #ifdef CONFIG_SMP
28499diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
28500index 957779f..74e405c 100644
28501--- a/arch/x86/kernel/vsyscall_64.c
28502+++ b/arch/x86/kernel/vsyscall_64.c
28503@@ -54,15 +54,13 @@
28504
28505 DEFINE_VVAR(int, vgetcpu_mode);
28506
28507-static enum { EMULATE, NATIVE, NONE } vsyscall_mode = EMULATE;
28508+static enum { EMULATE, NONE } vsyscall_mode = EMULATE;
28509
28510 static int __init vsyscall_setup(char *str)
28511 {
28512 if (str) {
28513 if (!strcmp("emulate", str))
28514 vsyscall_mode = EMULATE;
28515- else if (!strcmp("native", str))
28516- vsyscall_mode = NATIVE;
28517 else if (!strcmp("none", str))
28518 vsyscall_mode = NONE;
28519 else
28520@@ -279,8 +277,7 @@ do_ret:
28521 return true;
28522
28523 sigsegv:
28524- force_sig(SIGSEGV, current);
28525- return true;
28526+ do_group_exit(SIGKILL);
28527 }
28528
28529 /*
28530@@ -331,10 +328,7 @@ void __init map_vsyscall(void)
28531 extern char __vsyscall_page;
28532 unsigned long physaddr_vsyscall = __pa_symbol(&__vsyscall_page);
28533
28534- __set_fixmap(VSYSCALL_PAGE, physaddr_vsyscall,
28535- vsyscall_mode == NATIVE
28536- ? PAGE_KERNEL_VSYSCALL
28537- : PAGE_KERNEL_VVAR);
28538+ __set_fixmap(VSYSCALL_PAGE, physaddr_vsyscall, PAGE_KERNEL_VVAR);
28539 BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_PAGE) !=
28540 (unsigned long)VSYSCALL_ADDR);
28541 }
28542diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
28543index 04068192..4d75aa6 100644
28544--- a/arch/x86/kernel/x8664_ksyms_64.c
28545+++ b/arch/x86/kernel/x8664_ksyms_64.c
28546@@ -34,8 +34,6 @@ EXPORT_SYMBOL(copy_user_generic_string);
28547 EXPORT_SYMBOL(copy_user_generic_unrolled);
28548 EXPORT_SYMBOL(copy_user_enhanced_fast_string);
28549 EXPORT_SYMBOL(__copy_user_nocache);
28550-EXPORT_SYMBOL(_copy_from_user);
28551-EXPORT_SYMBOL(_copy_to_user);
28552
28553 EXPORT_SYMBOL(copy_page);
28554 EXPORT_SYMBOL(clear_page);
28555@@ -73,3 +71,7 @@ EXPORT_SYMBOL(___preempt_schedule);
28556 EXPORT_SYMBOL(___preempt_schedule_context);
28557 #endif
28558 #endif
28559+
28560+#ifdef CONFIG_PAX_PER_CPU_PGD
28561+EXPORT_SYMBOL(cpu_pgd);
28562+#endif
28563diff --git a/arch/x86/kernel/x86_init.c b/arch/x86/kernel/x86_init.c
28564index e48b674..a451dd9 100644
28565--- a/arch/x86/kernel/x86_init.c
28566+++ b/arch/x86/kernel/x86_init.c
28567@@ -93,7 +93,7 @@ struct x86_cpuinit_ops x86_cpuinit = {
28568 static void default_nmi_init(void) { };
28569 static int default_i8042_detect(void) { return 1; };
28570
28571-struct x86_platform_ops x86_platform = {
28572+struct x86_platform_ops x86_platform __read_only = {
28573 .calibrate_tsc = native_calibrate_tsc,
28574 .get_wallclock = mach_get_cmos_time,
28575 .set_wallclock = mach_set_rtc_mmss,
28576@@ -109,7 +109,7 @@ struct x86_platform_ops x86_platform = {
28577 EXPORT_SYMBOL_GPL(x86_platform);
28578
28579 #if defined(CONFIG_PCI_MSI)
28580-struct x86_msi_ops x86_msi = {
28581+struct x86_msi_ops x86_msi __read_only = {
28582 .setup_msi_irqs = native_setup_msi_irqs,
28583 .compose_msi_msg = native_compose_msi_msg,
28584 .teardown_msi_irq = native_teardown_msi_irq,
28585@@ -150,7 +150,7 @@ u32 arch_msix_mask_irq(struct msi_desc *desc, u32 flag)
28586 }
28587 #endif
28588
28589-struct x86_io_apic_ops x86_io_apic_ops = {
28590+struct x86_io_apic_ops x86_io_apic_ops __read_only = {
28591 .init = native_io_apic_init_mappings,
28592 .read = native_io_apic_read,
28593 .write = native_io_apic_write,
28594diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
28595index 4c540c4..0b985b0 100644
28596--- a/arch/x86/kernel/xsave.c
28597+++ b/arch/x86/kernel/xsave.c
28598@@ -167,18 +167,18 @@ static inline int save_xstate_epilog(void __user *buf, int ia32_frame)
28599
28600 /* Setup the bytes not touched by the [f]xsave and reserved for SW. */
28601 sw_bytes = ia32_frame ? &fx_sw_reserved_ia32 : &fx_sw_reserved;
28602- err = __copy_to_user(&x->i387.sw_reserved, sw_bytes, sizeof(*sw_bytes));
28603+ err = __copy_to_user(x->i387.sw_reserved, sw_bytes, sizeof(*sw_bytes));
28604
28605 if (!use_xsave())
28606 return err;
28607
28608- err |= __put_user(FP_XSTATE_MAGIC2, (__u32 *)(buf + xstate_size));
28609+ err |= __put_user(FP_XSTATE_MAGIC2, (__u32 __user *)(buf + xstate_size));
28610
28611 /*
28612 * Read the xstate_bv which we copied (directly from the cpu or
28613 * from the state in task struct) to the user buffers.
28614 */
28615- err |= __get_user(xstate_bv, (__u32 *)&x->xsave_hdr.xstate_bv);
28616+ err |= __get_user(xstate_bv, (__u32 __user *)&x->xsave_hdr.xstate_bv);
28617
28618 /*
28619 * For legacy compatible, we always set FP/SSE bits in the bit
28620@@ -193,7 +193,7 @@ static inline int save_xstate_epilog(void __user *buf, int ia32_frame)
28621 */
28622 xstate_bv |= XSTATE_FPSSE;
28623
28624- err |= __put_user(xstate_bv, (__u32 *)&x->xsave_hdr.xstate_bv);
28625+ err |= __put_user(xstate_bv, (__u32 __user *)&x->xsave_hdr.xstate_bv);
28626
28627 return err;
28628 }
28629@@ -202,6 +202,7 @@ static inline int save_user_xstate(struct xsave_struct __user *buf)
28630 {
28631 int err;
28632
28633+ buf = (struct xsave_struct __user *)____m(buf);
28634 if (use_xsave())
28635 err = xsave_user(buf);
28636 else if (use_fxsr())
28637@@ -312,6 +313,7 @@ sanitize_restored_xstate(struct task_struct *tsk,
28638 */
28639 static inline int restore_user_xstate(void __user *buf, u64 xbv, int fx_only)
28640 {
28641+ buf = (void __user *)____m(buf);
28642 if (use_xsave()) {
28643 if ((unsigned long)buf % 64 || fx_only) {
28644 u64 init_bv = pcntxt_mask & ~XSTATE_FPSSE;
28645diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
28646index 976e3a5..8bb998c 100644
28647--- a/arch/x86/kvm/cpuid.c
28648+++ b/arch/x86/kvm/cpuid.c
28649@@ -175,15 +175,20 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
28650 struct kvm_cpuid2 *cpuid,
28651 struct kvm_cpuid_entry2 __user *entries)
28652 {
28653- int r;
28654+ int r, i;
28655
28656 r = -E2BIG;
28657 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
28658 goto out;
28659 r = -EFAULT;
28660- if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
28661- cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
28662+ if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
28663 goto out;
28664+ for (i = 0; i < cpuid->nent; ++i) {
28665+ struct kvm_cpuid_entry2 cpuid_entry;
28666+ if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
28667+ goto out;
28668+ vcpu->arch.cpuid_entries[i] = cpuid_entry;
28669+ }
28670 vcpu->arch.cpuid_nent = cpuid->nent;
28671 kvm_apic_set_version(vcpu);
28672 kvm_x86_ops->cpuid_update(vcpu);
28673@@ -196,15 +201,19 @@ int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
28674 struct kvm_cpuid2 *cpuid,
28675 struct kvm_cpuid_entry2 __user *entries)
28676 {
28677- int r;
28678+ int r, i;
28679
28680 r = -E2BIG;
28681 if (cpuid->nent < vcpu->arch.cpuid_nent)
28682 goto out;
28683 r = -EFAULT;
28684- if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
28685- vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
28686+ if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
28687 goto out;
28688+ for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
28689+ struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
28690+ if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
28691+ goto out;
28692+ }
28693 return 0;
28694
28695 out:
28696diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
28697index 9f8a2fa..2df3c3f 100644
28698--- a/arch/x86/kvm/emulate.c
28699+++ b/arch/x86/kvm/emulate.c
28700@@ -3519,7 +3519,7 @@ static int check_cr_write(struct x86_emulate_ctxt *ctxt)
28701 int cr = ctxt->modrm_reg;
28702 u64 efer = 0;
28703
28704- static u64 cr_reserved_bits[] = {
28705+ static const u64 cr_reserved_bits[] = {
28706 0xffffffff00000000ULL,
28707 0, 0, 0, /* CR3 checked later */
28708 CR4_RESERVED_BITS,
28709@@ -3554,7 +3554,7 @@ static int check_cr_write(struct x86_emulate_ctxt *ctxt)
28710
28711 ctxt->ops->get_msr(ctxt, MSR_EFER, &efer);
28712 if (efer & EFER_LMA)
28713- rsvd = CR3_L_MODE_RESERVED_BITS;
28714+ rsvd = CR3_L_MODE_RESERVED_BITS & ~CR3_PCID_INVD;
28715
28716 if (new_val & rsvd)
28717 return emulate_gp(ctxt, 0);
28718diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
28719index b8345dd..f225d71 100644
28720--- a/arch/x86/kvm/lapic.c
28721+++ b/arch/x86/kvm/lapic.c
28722@@ -55,7 +55,7 @@
28723 #define APIC_BUS_CYCLE_NS 1
28724
28725 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
28726-#define apic_debug(fmt, arg...)
28727+#define apic_debug(fmt, arg...) do {} while (0)
28728
28729 #define APIC_LVT_NUM 6
28730 /* 14 is the version for Xeon and Pentium 8.4.8*/
28731diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
28732index fd49c86..77e1aa0 100644
28733--- a/arch/x86/kvm/paging_tmpl.h
28734+++ b/arch/x86/kvm/paging_tmpl.h
28735@@ -343,7 +343,7 @@ retry_walk:
28736 if (unlikely(kvm_is_error_hva(host_addr)))
28737 goto error;
28738
28739- ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
28740+ ptep_user = (pt_element_t __force_user *)((void *)host_addr + offset);
28741 if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte))))
28742 goto error;
28743 walker->ptep_user[walker->level - 1] = ptep_user;
28744diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
28745index 7527cef..c63a838e 100644
28746--- a/arch/x86/kvm/svm.c
28747+++ b/arch/x86/kvm/svm.c
28748@@ -3564,7 +3564,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
28749 int cpu = raw_smp_processor_id();
28750
28751 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
28752+
28753+ pax_open_kernel();
28754 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
28755+ pax_close_kernel();
28756+
28757 load_TR_desc();
28758 }
28759
28760@@ -3965,6 +3969,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
28761 #endif
28762 #endif
28763
28764+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
28765+ __set_fs(current_thread_info()->addr_limit);
28766+#endif
28767+
28768 reload_tss(vcpu);
28769
28770 local_irq_disable();
28771diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
28772index 3e556c6..08bbf7f 100644
28773--- a/arch/x86/kvm/vmx.c
28774+++ b/arch/x86/kvm/vmx.c
28775@@ -1366,12 +1366,12 @@ static void vmcs_write64(unsigned long field, u64 value)
28776 #endif
28777 }
28778
28779-static void vmcs_clear_bits(unsigned long field, u32 mask)
28780+static void vmcs_clear_bits(unsigned long field, unsigned long mask)
28781 {
28782 vmcs_writel(field, vmcs_readl(field) & ~mask);
28783 }
28784
28785-static void vmcs_set_bits(unsigned long field, u32 mask)
28786+static void vmcs_set_bits(unsigned long field, unsigned long mask)
28787 {
28788 vmcs_writel(field, vmcs_readl(field) | mask);
28789 }
28790@@ -1631,7 +1631,11 @@ static void reload_tss(void)
28791 struct desc_struct *descs;
28792
28793 descs = (void *)gdt->address;
28794+
28795+ pax_open_kernel();
28796 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
28797+ pax_close_kernel();
28798+
28799 load_TR_desc();
28800 }
28801
28802@@ -1859,6 +1863,10 @@ static void vmx_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
28803 vmcs_writel(HOST_TR_BASE, kvm_read_tr_base()); /* 22.2.4 */
28804 vmcs_writel(HOST_GDTR_BASE, gdt->address); /* 22.2.4 */
28805
28806+#ifdef CONFIG_PAX_PER_CPU_PGD
28807+ vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
28808+#endif
28809+
28810 rdmsrl(MSR_IA32_SYSENTER_ESP, sysenter_esp);
28811 vmcs_writel(HOST_IA32_SYSENTER_ESP, sysenter_esp); /* 22.2.3 */
28812 vmx->loaded_vmcs->cpu = cpu;
28813@@ -2148,7 +2156,7 @@ static void setup_msrs(struct vcpu_vmx *vmx)
28814 * reads and returns guest's timestamp counter "register"
28815 * guest_tsc = host_tsc + tsc_offset -- 21.3
28816 */
28817-static u64 guest_read_tsc(void)
28818+static u64 __intentional_overflow(-1) guest_read_tsc(void)
28819 {
28820 u64 host_tsc, tsc_offset;
28821
28822@@ -3146,11 +3154,16 @@ static __init int hardware_setup(void)
28823 * page upon invalidation. No need to do anything if the
28824 * processor does not have the APIC_ACCESS_ADDR VMCS field.
28825 */
28826- kvm_x86_ops->set_apic_access_page_addr = NULL;
28827+ pax_open_kernel();
28828+ *(void **)&kvm_x86_ops->set_apic_access_page_addr = NULL;
28829+ pax_close_kernel();
28830 }
28831
28832- if (!cpu_has_vmx_tpr_shadow())
28833- kvm_x86_ops->update_cr8_intercept = NULL;
28834+ if (!cpu_has_vmx_tpr_shadow()) {
28835+ pax_open_kernel();
28836+ *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
28837+ pax_close_kernel();
28838+ }
28839
28840 if (enable_ept && !cpu_has_vmx_ept_2m_page())
28841 kvm_disable_largepages();
28842@@ -3161,13 +3174,15 @@ static __init int hardware_setup(void)
28843 if (!cpu_has_vmx_apicv())
28844 enable_apicv = 0;
28845
28846+ pax_open_kernel();
28847 if (enable_apicv)
28848- kvm_x86_ops->update_cr8_intercept = NULL;
28849+ *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
28850 else {
28851- kvm_x86_ops->hwapic_irr_update = NULL;
28852- kvm_x86_ops->deliver_posted_interrupt = NULL;
28853- kvm_x86_ops->sync_pir_to_irr = vmx_sync_pir_to_irr_dummy;
28854+ *(void **)&kvm_x86_ops->hwapic_irr_update = NULL;
28855+ *(void **)&kvm_x86_ops->deliver_posted_interrupt = NULL;
28856+ *(void **)&kvm_x86_ops->sync_pir_to_irr = vmx_sync_pir_to_irr_dummy;
28857 }
28858+ pax_close_kernel();
28859
28860 if (nested)
28861 nested_vmx_setup_ctls_msrs();
28862@@ -4274,7 +4289,10 @@ static void vmx_set_constant_host_state(struct vcpu_vmx *vmx)
28863 unsigned long cr4;
28864
28865 vmcs_writel(HOST_CR0, read_cr0() & ~X86_CR0_TS); /* 22.2.3 */
28866+
28867+#ifndef CONFIG_PAX_PER_CPU_PGD
28868 vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
28869+#endif
28870
28871 /* Save the most likely value for this task's CR4 in the VMCS. */
28872 cr4 = read_cr4();
28873@@ -4301,7 +4319,7 @@ static void vmx_set_constant_host_state(struct vcpu_vmx *vmx)
28874 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
28875 vmx->host_idt_base = dt.address;
28876
28877- vmcs_writel(HOST_RIP, vmx_return); /* 22.2.5 */
28878+ vmcs_writel(HOST_RIP, ktla_ktva(vmx_return)); /* 22.2.5 */
28879
28880 rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
28881 vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
28882@@ -7622,6 +7640,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
28883 "jmp 2f \n\t"
28884 "1: " __ex(ASM_VMX_VMRESUME) "\n\t"
28885 "2: "
28886+
28887+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
28888+ "ljmp %[cs],$3f\n\t"
28889+ "3: "
28890+#endif
28891+
28892 /* Save guest registers, load host registers, keep flags */
28893 "mov %0, %c[wordsize](%%" _ASM_SP ") \n\t"
28894 "pop %0 \n\t"
28895@@ -7674,6 +7698,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
28896 #endif
28897 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
28898 [wordsize]"i"(sizeof(ulong))
28899+
28900+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
28901+ ,[cs]"i"(__KERNEL_CS)
28902+#endif
28903+
28904 : "cc", "memory"
28905 #ifdef CONFIG_X86_64
28906 , "rax", "rbx", "rdi", "rsi"
28907@@ -7687,7 +7716,7 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
28908 if (debugctlmsr)
28909 update_debugctlmsr(debugctlmsr);
28910
28911-#ifndef CONFIG_X86_64
28912+#ifdef CONFIG_X86_32
28913 /*
28914 * The sysexit path does not restore ds/es, so we must set them to
28915 * a reasonable value ourselves.
28916@@ -7696,8 +7725,18 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
28917 * may be executed in interrupt context, which saves and restore segments
28918 * around it, nullifying its effect.
28919 */
28920- loadsegment(ds, __USER_DS);
28921- loadsegment(es, __USER_DS);
28922+ loadsegment(ds, __KERNEL_DS);
28923+ loadsegment(es, __KERNEL_DS);
28924+ loadsegment(ss, __KERNEL_DS);
28925+
28926+#ifdef CONFIG_PAX_KERNEXEC
28927+ loadsegment(fs, __KERNEL_PERCPU);
28928+#endif
28929+
28930+#ifdef CONFIG_PAX_MEMORY_UDEREF
28931+ __set_fs(current_thread_info()->addr_limit);
28932+#endif
28933+
28934 #endif
28935
28936 vcpu->arch.regs_avail = ~((1 << VCPU_REGS_RIP) | (1 << VCPU_REGS_RSP)
28937diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
28938index 0033df3..db6236d 100644
28939--- a/arch/x86/kvm/x86.c
28940+++ b/arch/x86/kvm/x86.c
28941@@ -732,6 +732,8 @@ EXPORT_SYMBOL_GPL(kvm_set_cr4);
28942
28943 int kvm_set_cr3(struct kvm_vcpu *vcpu, unsigned long cr3)
28944 {
28945+ cr3 &= ~CR3_PCID_INVD;
28946+
28947 if (cr3 == kvm_read_cr3(vcpu) && !pdptrs_changed(vcpu)) {
28948 kvm_mmu_sync_roots(vcpu);
28949 kvm_make_request(KVM_REQ_TLB_FLUSH, vcpu);
28950@@ -1878,8 +1880,8 @@ static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
28951 {
28952 struct kvm *kvm = vcpu->kvm;
28953 int lm = is_long_mode(vcpu);
28954- u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64
28955- : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
28956+ u8 __user *blob_addr = lm ? (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_64
28957+ : (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
28958 u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
28959 : kvm->arch.xen_hvm_config.blob_size_32;
28960 u32 page_num = data & ~PAGE_MASK;
28961@@ -2806,6 +2808,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
28962 if (n < msr_list.nmsrs)
28963 goto out;
28964 r = -EFAULT;
28965+ if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
28966+ goto out;
28967 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
28968 num_msrs_to_save * sizeof(u32)))
28969 goto out;
28970@@ -5670,7 +5674,7 @@ static struct notifier_block pvclock_gtod_notifier = {
28971 };
28972 #endif
28973
28974-int kvm_arch_init(void *opaque)
28975+int kvm_arch_init(const void *opaque)
28976 {
28977 int r;
28978 struct kvm_x86_ops *ops = opaque;
28979diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
28980index aae9413..d11e829 100644
28981--- a/arch/x86/lguest/boot.c
28982+++ b/arch/x86/lguest/boot.c
28983@@ -1206,9 +1206,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
28984 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
28985 * Launcher to reboot us.
28986 */
28987-static void lguest_restart(char *reason)
28988+static __noreturn void lguest_restart(char *reason)
28989 {
28990 hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
28991+ BUG();
28992 }
28993
28994 /*G:050
28995diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
28996index 00933d5..3a64af9 100644
28997--- a/arch/x86/lib/atomic64_386_32.S
28998+++ b/arch/x86/lib/atomic64_386_32.S
28999@@ -48,6 +48,10 @@ BEGIN(read)
29000 movl (v), %eax
29001 movl 4(v), %edx
29002 RET_ENDP
29003+BEGIN(read_unchecked)
29004+ movl (v), %eax
29005+ movl 4(v), %edx
29006+RET_ENDP
29007 #undef v
29008
29009 #define v %esi
29010@@ -55,6 +59,10 @@ BEGIN(set)
29011 movl %ebx, (v)
29012 movl %ecx, 4(v)
29013 RET_ENDP
29014+BEGIN(set_unchecked)
29015+ movl %ebx, (v)
29016+ movl %ecx, 4(v)
29017+RET_ENDP
29018 #undef v
29019
29020 #define v %esi
29021@@ -70,6 +78,20 @@ RET_ENDP
29022 BEGIN(add)
29023 addl %eax, (v)
29024 adcl %edx, 4(v)
29025+
29026+#ifdef CONFIG_PAX_REFCOUNT
29027+ jno 0f
29028+ subl %eax, (v)
29029+ sbbl %edx, 4(v)
29030+ int $4
29031+0:
29032+ _ASM_EXTABLE(0b, 0b)
29033+#endif
29034+
29035+RET_ENDP
29036+BEGIN(add_unchecked)
29037+ addl %eax, (v)
29038+ adcl %edx, 4(v)
29039 RET_ENDP
29040 #undef v
29041
29042@@ -77,6 +99,24 @@ RET_ENDP
29043 BEGIN(add_return)
29044 addl (v), %eax
29045 adcl 4(v), %edx
29046+
29047+#ifdef CONFIG_PAX_REFCOUNT
29048+ into
29049+1234:
29050+ _ASM_EXTABLE(1234b, 2f)
29051+#endif
29052+
29053+ movl %eax, (v)
29054+ movl %edx, 4(v)
29055+
29056+#ifdef CONFIG_PAX_REFCOUNT
29057+2:
29058+#endif
29059+
29060+RET_ENDP
29061+BEGIN(add_return_unchecked)
29062+ addl (v), %eax
29063+ adcl 4(v), %edx
29064 movl %eax, (v)
29065 movl %edx, 4(v)
29066 RET_ENDP
29067@@ -86,6 +126,20 @@ RET_ENDP
29068 BEGIN(sub)
29069 subl %eax, (v)
29070 sbbl %edx, 4(v)
29071+
29072+#ifdef CONFIG_PAX_REFCOUNT
29073+ jno 0f
29074+ addl %eax, (v)
29075+ adcl %edx, 4(v)
29076+ int $4
29077+0:
29078+ _ASM_EXTABLE(0b, 0b)
29079+#endif
29080+
29081+RET_ENDP
29082+BEGIN(sub_unchecked)
29083+ subl %eax, (v)
29084+ sbbl %edx, 4(v)
29085 RET_ENDP
29086 #undef v
29087
29088@@ -96,6 +150,27 @@ BEGIN(sub_return)
29089 sbbl $0, %edx
29090 addl (v), %eax
29091 adcl 4(v), %edx
29092+
29093+#ifdef CONFIG_PAX_REFCOUNT
29094+ into
29095+1234:
29096+ _ASM_EXTABLE(1234b, 2f)
29097+#endif
29098+
29099+ movl %eax, (v)
29100+ movl %edx, 4(v)
29101+
29102+#ifdef CONFIG_PAX_REFCOUNT
29103+2:
29104+#endif
29105+
29106+RET_ENDP
29107+BEGIN(sub_return_unchecked)
29108+ negl %edx
29109+ negl %eax
29110+ sbbl $0, %edx
29111+ addl (v), %eax
29112+ adcl 4(v), %edx
29113 movl %eax, (v)
29114 movl %edx, 4(v)
29115 RET_ENDP
29116@@ -105,6 +180,20 @@ RET_ENDP
29117 BEGIN(inc)
29118 addl $1, (v)
29119 adcl $0, 4(v)
29120+
29121+#ifdef CONFIG_PAX_REFCOUNT
29122+ jno 0f
29123+ subl $1, (v)
29124+ sbbl $0, 4(v)
29125+ int $4
29126+0:
29127+ _ASM_EXTABLE(0b, 0b)
29128+#endif
29129+
29130+RET_ENDP
29131+BEGIN(inc_unchecked)
29132+ addl $1, (v)
29133+ adcl $0, 4(v)
29134 RET_ENDP
29135 #undef v
29136
29137@@ -114,6 +203,26 @@ BEGIN(inc_return)
29138 movl 4(v), %edx
29139 addl $1, %eax
29140 adcl $0, %edx
29141+
29142+#ifdef CONFIG_PAX_REFCOUNT
29143+ into
29144+1234:
29145+ _ASM_EXTABLE(1234b, 2f)
29146+#endif
29147+
29148+ movl %eax, (v)
29149+ movl %edx, 4(v)
29150+
29151+#ifdef CONFIG_PAX_REFCOUNT
29152+2:
29153+#endif
29154+
29155+RET_ENDP
29156+BEGIN(inc_return_unchecked)
29157+ movl (v), %eax
29158+ movl 4(v), %edx
29159+ addl $1, %eax
29160+ adcl $0, %edx
29161 movl %eax, (v)
29162 movl %edx, 4(v)
29163 RET_ENDP
29164@@ -123,6 +232,20 @@ RET_ENDP
29165 BEGIN(dec)
29166 subl $1, (v)
29167 sbbl $0, 4(v)
29168+
29169+#ifdef CONFIG_PAX_REFCOUNT
29170+ jno 0f
29171+ addl $1, (v)
29172+ adcl $0, 4(v)
29173+ int $4
29174+0:
29175+ _ASM_EXTABLE(0b, 0b)
29176+#endif
29177+
29178+RET_ENDP
29179+BEGIN(dec_unchecked)
29180+ subl $1, (v)
29181+ sbbl $0, 4(v)
29182 RET_ENDP
29183 #undef v
29184
29185@@ -132,6 +255,26 @@ BEGIN(dec_return)
29186 movl 4(v), %edx
29187 subl $1, %eax
29188 sbbl $0, %edx
29189+
29190+#ifdef CONFIG_PAX_REFCOUNT
29191+ into
29192+1234:
29193+ _ASM_EXTABLE(1234b, 2f)
29194+#endif
29195+
29196+ movl %eax, (v)
29197+ movl %edx, 4(v)
29198+
29199+#ifdef CONFIG_PAX_REFCOUNT
29200+2:
29201+#endif
29202+
29203+RET_ENDP
29204+BEGIN(dec_return_unchecked)
29205+ movl (v), %eax
29206+ movl 4(v), %edx
29207+ subl $1, %eax
29208+ sbbl $0, %edx
29209 movl %eax, (v)
29210 movl %edx, 4(v)
29211 RET_ENDP
29212@@ -143,6 +286,13 @@ BEGIN(add_unless)
29213 adcl %edx, %edi
29214 addl (v), %eax
29215 adcl 4(v), %edx
29216+
29217+#ifdef CONFIG_PAX_REFCOUNT
29218+ into
29219+1234:
29220+ _ASM_EXTABLE(1234b, 2f)
29221+#endif
29222+
29223 cmpl %eax, %ecx
29224 je 3f
29225 1:
29226@@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
29227 1:
29228 addl $1, %eax
29229 adcl $0, %edx
29230+
29231+#ifdef CONFIG_PAX_REFCOUNT
29232+ into
29233+1234:
29234+ _ASM_EXTABLE(1234b, 2f)
29235+#endif
29236+
29237 movl %eax, (v)
29238 movl %edx, 4(v)
29239 movl $1, %eax
29240@@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
29241 movl 4(v), %edx
29242 subl $1, %eax
29243 sbbl $0, %edx
29244+
29245+#ifdef CONFIG_PAX_REFCOUNT
29246+ into
29247+1234:
29248+ _ASM_EXTABLE(1234b, 1f)
29249+#endif
29250+
29251 js 1f
29252 movl %eax, (v)
29253 movl %edx, 4(v)
29254diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
29255index f5cc9eb..51fa319 100644
29256--- a/arch/x86/lib/atomic64_cx8_32.S
29257+++ b/arch/x86/lib/atomic64_cx8_32.S
29258@@ -35,10 +35,20 @@ ENTRY(atomic64_read_cx8)
29259 CFI_STARTPROC
29260
29261 read64 %ecx
29262+ pax_force_retaddr
29263 ret
29264 CFI_ENDPROC
29265 ENDPROC(atomic64_read_cx8)
29266
29267+ENTRY(atomic64_read_unchecked_cx8)
29268+ CFI_STARTPROC
29269+
29270+ read64 %ecx
29271+ pax_force_retaddr
29272+ ret
29273+ CFI_ENDPROC
29274+ENDPROC(atomic64_read_unchecked_cx8)
29275+
29276 ENTRY(atomic64_set_cx8)
29277 CFI_STARTPROC
29278
29279@@ -48,10 +58,25 @@ ENTRY(atomic64_set_cx8)
29280 cmpxchg8b (%esi)
29281 jne 1b
29282
29283+ pax_force_retaddr
29284 ret
29285 CFI_ENDPROC
29286 ENDPROC(atomic64_set_cx8)
29287
29288+ENTRY(atomic64_set_unchecked_cx8)
29289+ CFI_STARTPROC
29290+
29291+1:
29292+/* we don't need LOCK_PREFIX since aligned 64-bit writes
29293+ * are atomic on 586 and newer */
29294+ cmpxchg8b (%esi)
29295+ jne 1b
29296+
29297+ pax_force_retaddr
29298+ ret
29299+ CFI_ENDPROC
29300+ENDPROC(atomic64_set_unchecked_cx8)
29301+
29302 ENTRY(atomic64_xchg_cx8)
29303 CFI_STARTPROC
29304
29305@@ -60,12 +85,13 @@ ENTRY(atomic64_xchg_cx8)
29306 cmpxchg8b (%esi)
29307 jne 1b
29308
29309+ pax_force_retaddr
29310 ret
29311 CFI_ENDPROC
29312 ENDPROC(atomic64_xchg_cx8)
29313
29314-.macro addsub_return func ins insc
29315-ENTRY(atomic64_\func\()_return_cx8)
29316+.macro addsub_return func ins insc unchecked=""
29317+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
29318 CFI_STARTPROC
29319 SAVE ebp
29320 SAVE ebx
29321@@ -82,27 +108,44 @@ ENTRY(atomic64_\func\()_return_cx8)
29322 movl %edx, %ecx
29323 \ins\()l %esi, %ebx
29324 \insc\()l %edi, %ecx
29325+
29326+.ifb \unchecked
29327+#ifdef CONFIG_PAX_REFCOUNT
29328+ into
29329+2:
29330+ _ASM_EXTABLE(2b, 3f)
29331+#endif
29332+.endif
29333+
29334 LOCK_PREFIX
29335 cmpxchg8b (%ebp)
29336 jne 1b
29337-
29338-10:
29339 movl %ebx, %eax
29340 movl %ecx, %edx
29341+
29342+.ifb \unchecked
29343+#ifdef CONFIG_PAX_REFCOUNT
29344+3:
29345+#endif
29346+.endif
29347+
29348 RESTORE edi
29349 RESTORE esi
29350 RESTORE ebx
29351 RESTORE ebp
29352+ pax_force_retaddr
29353 ret
29354 CFI_ENDPROC
29355-ENDPROC(atomic64_\func\()_return_cx8)
29356+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
29357 .endm
29358
29359 addsub_return add add adc
29360 addsub_return sub sub sbb
29361+addsub_return add add adc _unchecked
29362+addsub_return sub sub sbb _unchecked
29363
29364-.macro incdec_return func ins insc
29365-ENTRY(atomic64_\func\()_return_cx8)
29366+.macro incdec_return func ins insc unchecked=""
29367+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
29368 CFI_STARTPROC
29369 SAVE ebx
29370
29371@@ -112,21 +155,39 @@ ENTRY(atomic64_\func\()_return_cx8)
29372 movl %edx, %ecx
29373 \ins\()l $1, %ebx
29374 \insc\()l $0, %ecx
29375+
29376+.ifb \unchecked
29377+#ifdef CONFIG_PAX_REFCOUNT
29378+ into
29379+2:
29380+ _ASM_EXTABLE(2b, 3f)
29381+#endif
29382+.endif
29383+
29384 LOCK_PREFIX
29385 cmpxchg8b (%esi)
29386 jne 1b
29387
29388-10:
29389 movl %ebx, %eax
29390 movl %ecx, %edx
29391+
29392+.ifb \unchecked
29393+#ifdef CONFIG_PAX_REFCOUNT
29394+3:
29395+#endif
29396+.endif
29397+
29398 RESTORE ebx
29399+ pax_force_retaddr
29400 ret
29401 CFI_ENDPROC
29402-ENDPROC(atomic64_\func\()_return_cx8)
29403+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
29404 .endm
29405
29406 incdec_return inc add adc
29407 incdec_return dec sub sbb
29408+incdec_return inc add adc _unchecked
29409+incdec_return dec sub sbb _unchecked
29410
29411 ENTRY(atomic64_dec_if_positive_cx8)
29412 CFI_STARTPROC
29413@@ -138,6 +199,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
29414 movl %edx, %ecx
29415 subl $1, %ebx
29416 sbb $0, %ecx
29417+
29418+#ifdef CONFIG_PAX_REFCOUNT
29419+ into
29420+1234:
29421+ _ASM_EXTABLE(1234b, 2f)
29422+#endif
29423+
29424 js 2f
29425 LOCK_PREFIX
29426 cmpxchg8b (%esi)
29427@@ -147,6 +215,7 @@ ENTRY(atomic64_dec_if_positive_cx8)
29428 movl %ebx, %eax
29429 movl %ecx, %edx
29430 RESTORE ebx
29431+ pax_force_retaddr
29432 ret
29433 CFI_ENDPROC
29434 ENDPROC(atomic64_dec_if_positive_cx8)
29435@@ -171,6 +240,13 @@ ENTRY(atomic64_add_unless_cx8)
29436 movl %edx, %ecx
29437 addl %ebp, %ebx
29438 adcl %edi, %ecx
29439+
29440+#ifdef CONFIG_PAX_REFCOUNT
29441+ into
29442+1234:
29443+ _ASM_EXTABLE(1234b, 3f)
29444+#endif
29445+
29446 LOCK_PREFIX
29447 cmpxchg8b (%esi)
29448 jne 1b
29449@@ -181,6 +257,7 @@ ENTRY(atomic64_add_unless_cx8)
29450 CFI_ADJUST_CFA_OFFSET -8
29451 RESTORE ebx
29452 RESTORE ebp
29453+ pax_force_retaddr
29454 ret
29455 4:
29456 cmpl %edx, 4(%esp)
29457@@ -203,6 +280,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
29458 xorl %ecx, %ecx
29459 addl $1, %ebx
29460 adcl %edx, %ecx
29461+
29462+#ifdef CONFIG_PAX_REFCOUNT
29463+ into
29464+1234:
29465+ _ASM_EXTABLE(1234b, 3f)
29466+#endif
29467+
29468 LOCK_PREFIX
29469 cmpxchg8b (%esi)
29470 jne 1b
29471@@ -210,6 +294,7 @@ ENTRY(atomic64_inc_not_zero_cx8)
29472 movl $1, %eax
29473 3:
29474 RESTORE ebx
29475+ pax_force_retaddr
29476 ret
29477 CFI_ENDPROC
29478 ENDPROC(atomic64_inc_not_zero_cx8)
29479diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
29480index e78b8eee..7e173a8 100644
29481--- a/arch/x86/lib/checksum_32.S
29482+++ b/arch/x86/lib/checksum_32.S
29483@@ -29,7 +29,8 @@
29484 #include <asm/dwarf2.h>
29485 #include <asm/errno.h>
29486 #include <asm/asm.h>
29487-
29488+#include <asm/segment.h>
29489+
29490 /*
29491 * computes a partial checksum, e.g. for TCP/UDP fragments
29492 */
29493@@ -293,9 +294,24 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
29494
29495 #define ARGBASE 16
29496 #define FP 12
29497-
29498-ENTRY(csum_partial_copy_generic)
29499+
29500+ENTRY(csum_partial_copy_generic_to_user)
29501 CFI_STARTPROC
29502+
29503+#ifdef CONFIG_PAX_MEMORY_UDEREF
29504+ pushl_cfi %gs
29505+ popl_cfi %es
29506+ jmp csum_partial_copy_generic
29507+#endif
29508+
29509+ENTRY(csum_partial_copy_generic_from_user)
29510+
29511+#ifdef CONFIG_PAX_MEMORY_UDEREF
29512+ pushl_cfi %gs
29513+ popl_cfi %ds
29514+#endif
29515+
29516+ENTRY(csum_partial_copy_generic)
29517 subl $4,%esp
29518 CFI_ADJUST_CFA_OFFSET 4
29519 pushl_cfi %edi
29520@@ -317,7 +333,7 @@ ENTRY(csum_partial_copy_generic)
29521 jmp 4f
29522 SRC(1: movw (%esi), %bx )
29523 addl $2, %esi
29524-DST( movw %bx, (%edi) )
29525+DST( movw %bx, %es:(%edi) )
29526 addl $2, %edi
29527 addw %bx, %ax
29528 adcl $0, %eax
29529@@ -329,30 +345,30 @@ DST( movw %bx, (%edi) )
29530 SRC(1: movl (%esi), %ebx )
29531 SRC( movl 4(%esi), %edx )
29532 adcl %ebx, %eax
29533-DST( movl %ebx, (%edi) )
29534+DST( movl %ebx, %es:(%edi) )
29535 adcl %edx, %eax
29536-DST( movl %edx, 4(%edi) )
29537+DST( movl %edx, %es:4(%edi) )
29538
29539 SRC( movl 8(%esi), %ebx )
29540 SRC( movl 12(%esi), %edx )
29541 adcl %ebx, %eax
29542-DST( movl %ebx, 8(%edi) )
29543+DST( movl %ebx, %es:8(%edi) )
29544 adcl %edx, %eax
29545-DST( movl %edx, 12(%edi) )
29546+DST( movl %edx, %es:12(%edi) )
29547
29548 SRC( movl 16(%esi), %ebx )
29549 SRC( movl 20(%esi), %edx )
29550 adcl %ebx, %eax
29551-DST( movl %ebx, 16(%edi) )
29552+DST( movl %ebx, %es:16(%edi) )
29553 adcl %edx, %eax
29554-DST( movl %edx, 20(%edi) )
29555+DST( movl %edx, %es:20(%edi) )
29556
29557 SRC( movl 24(%esi), %ebx )
29558 SRC( movl 28(%esi), %edx )
29559 adcl %ebx, %eax
29560-DST( movl %ebx, 24(%edi) )
29561+DST( movl %ebx, %es:24(%edi) )
29562 adcl %edx, %eax
29563-DST( movl %edx, 28(%edi) )
29564+DST( movl %edx, %es:28(%edi) )
29565
29566 lea 32(%esi), %esi
29567 lea 32(%edi), %edi
29568@@ -366,7 +382,7 @@ DST( movl %edx, 28(%edi) )
29569 shrl $2, %edx # This clears CF
29570 SRC(3: movl (%esi), %ebx )
29571 adcl %ebx, %eax
29572-DST( movl %ebx, (%edi) )
29573+DST( movl %ebx, %es:(%edi) )
29574 lea 4(%esi), %esi
29575 lea 4(%edi), %edi
29576 dec %edx
29577@@ -378,12 +394,12 @@ DST( movl %ebx, (%edi) )
29578 jb 5f
29579 SRC( movw (%esi), %cx )
29580 leal 2(%esi), %esi
29581-DST( movw %cx, (%edi) )
29582+DST( movw %cx, %es:(%edi) )
29583 leal 2(%edi), %edi
29584 je 6f
29585 shll $16,%ecx
29586 SRC(5: movb (%esi), %cl )
29587-DST( movb %cl, (%edi) )
29588+DST( movb %cl, %es:(%edi) )
29589 6: addl %ecx, %eax
29590 adcl $0, %eax
29591 7:
29592@@ -394,7 +410,7 @@ DST( movb %cl, (%edi) )
29593
29594 6001:
29595 movl ARGBASE+20(%esp), %ebx # src_err_ptr
29596- movl $-EFAULT, (%ebx)
29597+ movl $-EFAULT, %ss:(%ebx)
29598
29599 # zero the complete destination - computing the rest
29600 # is too much work
29601@@ -407,11 +423,15 @@ DST( movb %cl, (%edi) )
29602
29603 6002:
29604 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
29605- movl $-EFAULT,(%ebx)
29606+ movl $-EFAULT,%ss:(%ebx)
29607 jmp 5000b
29608
29609 .previous
29610
29611+ pushl_cfi %ss
29612+ popl_cfi %ds
29613+ pushl_cfi %ss
29614+ popl_cfi %es
29615 popl_cfi %ebx
29616 CFI_RESTORE ebx
29617 popl_cfi %esi
29618@@ -421,26 +441,43 @@ DST( movb %cl, (%edi) )
29619 popl_cfi %ecx # equivalent to addl $4,%esp
29620 ret
29621 CFI_ENDPROC
29622-ENDPROC(csum_partial_copy_generic)
29623+ENDPROC(csum_partial_copy_generic_to_user)
29624
29625 #else
29626
29627 /* Version for PentiumII/PPro */
29628
29629 #define ROUND1(x) \
29630+ nop; nop; nop; \
29631 SRC(movl x(%esi), %ebx ) ; \
29632 addl %ebx, %eax ; \
29633- DST(movl %ebx, x(%edi) ) ;
29634+ DST(movl %ebx, %es:x(%edi)) ;
29635
29636 #define ROUND(x) \
29637+ nop; nop; nop; \
29638 SRC(movl x(%esi), %ebx ) ; \
29639 adcl %ebx, %eax ; \
29640- DST(movl %ebx, x(%edi) ) ;
29641+ DST(movl %ebx, %es:x(%edi)) ;
29642
29643 #define ARGBASE 12
29644-
29645-ENTRY(csum_partial_copy_generic)
29646+
29647+ENTRY(csum_partial_copy_generic_to_user)
29648 CFI_STARTPROC
29649+
29650+#ifdef CONFIG_PAX_MEMORY_UDEREF
29651+ pushl_cfi %gs
29652+ popl_cfi %es
29653+ jmp csum_partial_copy_generic
29654+#endif
29655+
29656+ENTRY(csum_partial_copy_generic_from_user)
29657+
29658+#ifdef CONFIG_PAX_MEMORY_UDEREF
29659+ pushl_cfi %gs
29660+ popl_cfi %ds
29661+#endif
29662+
29663+ENTRY(csum_partial_copy_generic)
29664 pushl_cfi %ebx
29665 CFI_REL_OFFSET ebx, 0
29666 pushl_cfi %edi
29667@@ -461,7 +498,7 @@ ENTRY(csum_partial_copy_generic)
29668 subl %ebx, %edi
29669 lea -1(%esi),%edx
29670 andl $-32,%edx
29671- lea 3f(%ebx,%ebx), %ebx
29672+ lea 3f(%ebx,%ebx,2), %ebx
29673 testl %esi, %esi
29674 jmp *%ebx
29675 1: addl $64,%esi
29676@@ -482,19 +519,19 @@ ENTRY(csum_partial_copy_generic)
29677 jb 5f
29678 SRC( movw (%esi), %dx )
29679 leal 2(%esi), %esi
29680-DST( movw %dx, (%edi) )
29681+DST( movw %dx, %es:(%edi) )
29682 leal 2(%edi), %edi
29683 je 6f
29684 shll $16,%edx
29685 5:
29686 SRC( movb (%esi), %dl )
29687-DST( movb %dl, (%edi) )
29688+DST( movb %dl, %es:(%edi) )
29689 6: addl %edx, %eax
29690 adcl $0, %eax
29691 7:
29692 .section .fixup, "ax"
29693 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
29694- movl $-EFAULT, (%ebx)
29695+ movl $-EFAULT, %ss:(%ebx)
29696 # zero the complete destination (computing the rest is too much work)
29697 movl ARGBASE+8(%esp),%edi # dst
29698 movl ARGBASE+12(%esp),%ecx # len
29699@@ -502,10 +539,17 @@ DST( movb %dl, (%edi) )
29700 rep; stosb
29701 jmp 7b
29702 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
29703- movl $-EFAULT, (%ebx)
29704+ movl $-EFAULT, %ss:(%ebx)
29705 jmp 7b
29706 .previous
29707
29708+#ifdef CONFIG_PAX_MEMORY_UDEREF
29709+ pushl_cfi %ss
29710+ popl_cfi %ds
29711+ pushl_cfi %ss
29712+ popl_cfi %es
29713+#endif
29714+
29715 popl_cfi %esi
29716 CFI_RESTORE esi
29717 popl_cfi %edi
29718@@ -514,7 +558,7 @@ DST( movb %dl, (%edi) )
29719 CFI_RESTORE ebx
29720 ret
29721 CFI_ENDPROC
29722-ENDPROC(csum_partial_copy_generic)
29723+ENDPROC(csum_partial_copy_generic_to_user)
29724
29725 #undef ROUND
29726 #undef ROUND1
29727diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
29728index f2145cf..cea889d 100644
29729--- a/arch/x86/lib/clear_page_64.S
29730+++ b/arch/x86/lib/clear_page_64.S
29731@@ -11,6 +11,7 @@ ENTRY(clear_page_c)
29732 movl $4096/8,%ecx
29733 xorl %eax,%eax
29734 rep stosq
29735+ pax_force_retaddr
29736 ret
29737 CFI_ENDPROC
29738 ENDPROC(clear_page_c)
29739@@ -20,6 +21,7 @@ ENTRY(clear_page_c_e)
29740 movl $4096,%ecx
29741 xorl %eax,%eax
29742 rep stosb
29743+ pax_force_retaddr
29744 ret
29745 CFI_ENDPROC
29746 ENDPROC(clear_page_c_e)
29747@@ -43,6 +45,7 @@ ENTRY(clear_page)
29748 leaq 64(%rdi),%rdi
29749 jnz .Lloop
29750 nop
29751+ pax_force_retaddr
29752 ret
29753 CFI_ENDPROC
29754 .Lclear_page_end:
29755@@ -58,7 +61,7 @@ ENDPROC(clear_page)
29756
29757 #include <asm/cpufeature.h>
29758
29759- .section .altinstr_replacement,"ax"
29760+ .section .altinstr_replacement,"a"
29761 1: .byte 0xeb /* jmp <disp8> */
29762 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
29763 2: .byte 0xeb /* jmp <disp8> */
29764diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S
29765index 40a1725..5d12ac4 100644
29766--- a/arch/x86/lib/cmpxchg16b_emu.S
29767+++ b/arch/x86/lib/cmpxchg16b_emu.S
29768@@ -8,6 +8,7 @@
29769 #include <linux/linkage.h>
29770 #include <asm/dwarf2.h>
29771 #include <asm/percpu.h>
29772+#include <asm/alternative-asm.h>
29773
29774 .text
29775
29776@@ -46,12 +47,14 @@ CFI_STARTPROC
29777 CFI_REMEMBER_STATE
29778 popfq_cfi
29779 mov $1, %al
29780+ pax_force_retaddr
29781 ret
29782
29783 CFI_RESTORE_STATE
29784 .Lnot_same:
29785 popfq_cfi
29786 xor %al,%al
29787+ pax_force_retaddr
29788 ret
29789
29790 CFI_ENDPROC
29791diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
29792index 176cca6..e0d658e 100644
29793--- a/arch/x86/lib/copy_page_64.S
29794+++ b/arch/x86/lib/copy_page_64.S
29795@@ -9,6 +9,7 @@ copy_page_rep:
29796 CFI_STARTPROC
29797 movl $4096/8, %ecx
29798 rep movsq
29799+ pax_force_retaddr
29800 ret
29801 CFI_ENDPROC
29802 ENDPROC(copy_page_rep)
29803@@ -24,8 +25,8 @@ ENTRY(copy_page)
29804 CFI_ADJUST_CFA_OFFSET 2*8
29805 movq %rbx, (%rsp)
29806 CFI_REL_OFFSET rbx, 0
29807- movq %r12, 1*8(%rsp)
29808- CFI_REL_OFFSET r12, 1*8
29809+ movq %r13, 1*8(%rsp)
29810+ CFI_REL_OFFSET r13, 1*8
29811
29812 movl $(4096/64)-5, %ecx
29813 .p2align 4
29814@@ -38,7 +39,7 @@ ENTRY(copy_page)
29815 movq 0x8*4(%rsi), %r9
29816 movq 0x8*5(%rsi), %r10
29817 movq 0x8*6(%rsi), %r11
29818- movq 0x8*7(%rsi), %r12
29819+ movq 0x8*7(%rsi), %r13
29820
29821 prefetcht0 5*64(%rsi)
29822
29823@@ -49,7 +50,7 @@ ENTRY(copy_page)
29824 movq %r9, 0x8*4(%rdi)
29825 movq %r10, 0x8*5(%rdi)
29826 movq %r11, 0x8*6(%rdi)
29827- movq %r12, 0x8*7(%rdi)
29828+ movq %r13, 0x8*7(%rdi)
29829
29830 leaq 64 (%rsi), %rsi
29831 leaq 64 (%rdi), %rdi
29832@@ -68,7 +69,7 @@ ENTRY(copy_page)
29833 movq 0x8*4(%rsi), %r9
29834 movq 0x8*5(%rsi), %r10
29835 movq 0x8*6(%rsi), %r11
29836- movq 0x8*7(%rsi), %r12
29837+ movq 0x8*7(%rsi), %r13
29838
29839 movq %rax, 0x8*0(%rdi)
29840 movq %rbx, 0x8*1(%rdi)
29841@@ -77,7 +78,7 @@ ENTRY(copy_page)
29842 movq %r9, 0x8*4(%rdi)
29843 movq %r10, 0x8*5(%rdi)
29844 movq %r11, 0x8*6(%rdi)
29845- movq %r12, 0x8*7(%rdi)
29846+ movq %r13, 0x8*7(%rdi)
29847
29848 leaq 64(%rdi), %rdi
29849 leaq 64(%rsi), %rsi
29850@@ -85,10 +86,11 @@ ENTRY(copy_page)
29851
29852 movq (%rsp), %rbx
29853 CFI_RESTORE rbx
29854- movq 1*8(%rsp), %r12
29855- CFI_RESTORE r12
29856+ movq 1*8(%rsp), %r13
29857+ CFI_RESTORE r13
29858 addq $2*8, %rsp
29859 CFI_ADJUST_CFA_OFFSET -2*8
29860+ pax_force_retaddr
29861 ret
29862 .Lcopy_page_end:
29863 CFI_ENDPROC
29864@@ -99,7 +101,7 @@ ENDPROC(copy_page)
29865
29866 #include <asm/cpufeature.h>
29867
29868- .section .altinstr_replacement,"ax"
29869+ .section .altinstr_replacement,"a"
29870 1: .byte 0xeb /* jmp <disp8> */
29871 .byte (copy_page_rep - copy_page) - (2f - 1b) /* offset */
29872 2:
29873diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
29874index dee945d..a84067b 100644
29875--- a/arch/x86/lib/copy_user_64.S
29876+++ b/arch/x86/lib/copy_user_64.S
29877@@ -18,31 +18,7 @@
29878 #include <asm/alternative-asm.h>
29879 #include <asm/asm.h>
29880 #include <asm/smap.h>
29881-
29882-/*
29883- * By placing feature2 after feature1 in altinstructions section, we logically
29884- * implement:
29885- * If CPU has feature2, jmp to alt2 is used
29886- * else if CPU has feature1, jmp to alt1 is used
29887- * else jmp to orig is used.
29888- */
29889- .macro ALTERNATIVE_JUMP feature1,feature2,orig,alt1,alt2
29890-0:
29891- .byte 0xe9 /* 32bit jump */
29892- .long \orig-1f /* by default jump to orig */
29893-1:
29894- .section .altinstr_replacement,"ax"
29895-2: .byte 0xe9 /* near jump with 32bit immediate */
29896- .long \alt1-1b /* offset */ /* or alternatively to alt1 */
29897-3: .byte 0xe9 /* near jump with 32bit immediate */
29898- .long \alt2-1b /* offset */ /* or alternatively to alt2 */
29899- .previous
29900-
29901- .section .altinstructions,"a"
29902- altinstruction_entry 0b,2b,\feature1,5,5
29903- altinstruction_entry 0b,3b,\feature2,5,5
29904- .previous
29905- .endm
29906+#include <asm/pgtable.h>
29907
29908 .macro ALIGN_DESTINATION
29909 #ifdef FIX_ALIGNMENT
29910@@ -70,52 +46,6 @@
29911 #endif
29912 .endm
29913
29914-/* Standard copy_to_user with segment limit checking */
29915-ENTRY(_copy_to_user)
29916- CFI_STARTPROC
29917- GET_THREAD_INFO(%rax)
29918- movq %rdi,%rcx
29919- addq %rdx,%rcx
29920- jc bad_to_user
29921- cmpq TI_addr_limit(%rax),%rcx
29922- ja bad_to_user
29923- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
29924- copy_user_generic_unrolled,copy_user_generic_string, \
29925- copy_user_enhanced_fast_string
29926- CFI_ENDPROC
29927-ENDPROC(_copy_to_user)
29928-
29929-/* Standard copy_from_user with segment limit checking */
29930-ENTRY(_copy_from_user)
29931- CFI_STARTPROC
29932- GET_THREAD_INFO(%rax)
29933- movq %rsi,%rcx
29934- addq %rdx,%rcx
29935- jc bad_from_user
29936- cmpq TI_addr_limit(%rax),%rcx
29937- ja bad_from_user
29938- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
29939- copy_user_generic_unrolled,copy_user_generic_string, \
29940- copy_user_enhanced_fast_string
29941- CFI_ENDPROC
29942-ENDPROC(_copy_from_user)
29943-
29944- .section .fixup,"ax"
29945- /* must zero dest */
29946-ENTRY(bad_from_user)
29947-bad_from_user:
29948- CFI_STARTPROC
29949- movl %edx,%ecx
29950- xorl %eax,%eax
29951- rep
29952- stosb
29953-bad_to_user:
29954- movl %edx,%eax
29955- ret
29956- CFI_ENDPROC
29957-ENDPROC(bad_from_user)
29958- .previous
29959-
29960 /*
29961 * copy_user_generic_unrolled - memory copy with exception handling.
29962 * This version is for CPUs like P4 that don't have efficient micro
29963@@ -131,6 +61,7 @@ ENDPROC(bad_from_user)
29964 */
29965 ENTRY(copy_user_generic_unrolled)
29966 CFI_STARTPROC
29967+ ASM_PAX_OPEN_USERLAND
29968 ASM_STAC
29969 cmpl $8,%edx
29970 jb 20f /* less then 8 bytes, go to byte copy loop */
29971@@ -180,6 +111,8 @@ ENTRY(copy_user_generic_unrolled)
29972 jnz 21b
29973 23: xor %eax,%eax
29974 ASM_CLAC
29975+ ASM_PAX_CLOSE_USERLAND
29976+ pax_force_retaddr
29977 ret
29978
29979 .section .fixup,"ax"
29980@@ -235,6 +168,7 @@ ENDPROC(copy_user_generic_unrolled)
29981 */
29982 ENTRY(copy_user_generic_string)
29983 CFI_STARTPROC
29984+ ASM_PAX_OPEN_USERLAND
29985 ASM_STAC
29986 cmpl $8,%edx
29987 jb 2f /* less than 8 bytes, go to byte copy loop */
29988@@ -249,6 +183,8 @@ ENTRY(copy_user_generic_string)
29989 movsb
29990 xorl %eax,%eax
29991 ASM_CLAC
29992+ ASM_PAX_CLOSE_USERLAND
29993+ pax_force_retaddr
29994 ret
29995
29996 .section .fixup,"ax"
29997@@ -276,12 +212,15 @@ ENDPROC(copy_user_generic_string)
29998 */
29999 ENTRY(copy_user_enhanced_fast_string)
30000 CFI_STARTPROC
30001+ ASM_PAX_OPEN_USERLAND
30002 ASM_STAC
30003 movl %edx,%ecx
30004 1: rep
30005 movsb
30006 xorl %eax,%eax
30007 ASM_CLAC
30008+ ASM_PAX_CLOSE_USERLAND
30009+ pax_force_retaddr
30010 ret
30011
30012 .section .fixup,"ax"
30013diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
30014index 6a4f43c..c70fb52 100644
30015--- a/arch/x86/lib/copy_user_nocache_64.S
30016+++ b/arch/x86/lib/copy_user_nocache_64.S
30017@@ -8,6 +8,7 @@
30018
30019 #include <linux/linkage.h>
30020 #include <asm/dwarf2.h>
30021+#include <asm/alternative-asm.h>
30022
30023 #define FIX_ALIGNMENT 1
30024
30025@@ -16,6 +17,7 @@
30026 #include <asm/thread_info.h>
30027 #include <asm/asm.h>
30028 #include <asm/smap.h>
30029+#include <asm/pgtable.h>
30030
30031 .macro ALIGN_DESTINATION
30032 #ifdef FIX_ALIGNMENT
30033@@ -49,6 +51,16 @@
30034 */
30035 ENTRY(__copy_user_nocache)
30036 CFI_STARTPROC
30037+
30038+#ifdef CONFIG_PAX_MEMORY_UDEREF
30039+ mov pax_user_shadow_base,%rcx
30040+ cmp %rcx,%rsi
30041+ jae 1f
30042+ add %rcx,%rsi
30043+1:
30044+#endif
30045+
30046+ ASM_PAX_OPEN_USERLAND
30047 ASM_STAC
30048 cmpl $8,%edx
30049 jb 20f /* less then 8 bytes, go to byte copy loop */
30050@@ -98,7 +110,9 @@ ENTRY(__copy_user_nocache)
30051 jnz 21b
30052 23: xorl %eax,%eax
30053 ASM_CLAC
30054+ ASM_PAX_CLOSE_USERLAND
30055 sfence
30056+ pax_force_retaddr
30057 ret
30058
30059 .section .fixup,"ax"
30060diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
30061index 2419d5f..fe52d0e 100644
30062--- a/arch/x86/lib/csum-copy_64.S
30063+++ b/arch/x86/lib/csum-copy_64.S
30064@@ -9,6 +9,7 @@
30065 #include <asm/dwarf2.h>
30066 #include <asm/errno.h>
30067 #include <asm/asm.h>
30068+#include <asm/alternative-asm.h>
30069
30070 /*
30071 * Checksum copy with exception handling.
30072@@ -56,8 +57,8 @@ ENTRY(csum_partial_copy_generic)
30073 CFI_ADJUST_CFA_OFFSET 7*8
30074 movq %rbx, 2*8(%rsp)
30075 CFI_REL_OFFSET rbx, 2*8
30076- movq %r12, 3*8(%rsp)
30077- CFI_REL_OFFSET r12, 3*8
30078+ movq %r15, 3*8(%rsp)
30079+ CFI_REL_OFFSET r15, 3*8
30080 movq %r14, 4*8(%rsp)
30081 CFI_REL_OFFSET r14, 4*8
30082 movq %r13, 5*8(%rsp)
30083@@ -72,16 +73,16 @@ ENTRY(csum_partial_copy_generic)
30084 movl %edx, %ecx
30085
30086 xorl %r9d, %r9d
30087- movq %rcx, %r12
30088+ movq %rcx, %r15
30089
30090- shrq $6, %r12
30091+ shrq $6, %r15
30092 jz .Lhandle_tail /* < 64 */
30093
30094 clc
30095
30096 /* main loop. clear in 64 byte blocks */
30097 /* r9: zero, r8: temp2, rbx: temp1, rax: sum, rcx: saved length */
30098- /* r11: temp3, rdx: temp4, r12 loopcnt */
30099+ /* r11: temp3, rdx: temp4, r15 loopcnt */
30100 /* r10: temp5, rbp: temp6, r14 temp7, r13 temp8 */
30101 .p2align 4
30102 .Lloop:
30103@@ -115,7 +116,7 @@ ENTRY(csum_partial_copy_generic)
30104 adcq %r14, %rax
30105 adcq %r13, %rax
30106
30107- decl %r12d
30108+ decl %r15d
30109
30110 dest
30111 movq %rbx, (%rsi)
30112@@ -210,8 +211,8 @@ ENTRY(csum_partial_copy_generic)
30113 .Lende:
30114 movq 2*8(%rsp), %rbx
30115 CFI_RESTORE rbx
30116- movq 3*8(%rsp), %r12
30117- CFI_RESTORE r12
30118+ movq 3*8(%rsp), %r15
30119+ CFI_RESTORE r15
30120 movq 4*8(%rsp), %r14
30121 CFI_RESTORE r14
30122 movq 5*8(%rsp), %r13
30123@@ -220,6 +221,7 @@ ENTRY(csum_partial_copy_generic)
30124 CFI_RESTORE rbp
30125 addq $7*8, %rsp
30126 CFI_ADJUST_CFA_OFFSET -7*8
30127+ pax_force_retaddr
30128 ret
30129 CFI_RESTORE_STATE
30130
30131diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
30132index 1318f75..44c30fd 100644
30133--- a/arch/x86/lib/csum-wrappers_64.c
30134+++ b/arch/x86/lib/csum-wrappers_64.c
30135@@ -52,10 +52,12 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
30136 len -= 2;
30137 }
30138 }
30139+ pax_open_userland();
30140 stac();
30141- isum = csum_partial_copy_generic((__force const void *)src,
30142+ isum = csum_partial_copy_generic((const void __force_kernel *)____m(src),
30143 dst, len, isum, errp, NULL);
30144 clac();
30145+ pax_close_userland();
30146 if (unlikely(*errp))
30147 goto out_err;
30148
30149@@ -109,10 +111,12 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
30150 }
30151
30152 *errp = 0;
30153+ pax_open_userland();
30154 stac();
30155- ret = csum_partial_copy_generic(src, (void __force *)dst,
30156+ ret = csum_partial_copy_generic(src, (void __force_kernel *)____m(dst),
30157 len, isum, NULL, errp);
30158 clac();
30159+ pax_close_userland();
30160 return ret;
30161 }
30162 EXPORT_SYMBOL(csum_partial_copy_to_user);
30163diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
30164index a451235..1daa956 100644
30165--- a/arch/x86/lib/getuser.S
30166+++ b/arch/x86/lib/getuser.S
30167@@ -33,17 +33,40 @@
30168 #include <asm/thread_info.h>
30169 #include <asm/asm.h>
30170 #include <asm/smap.h>
30171+#include <asm/segment.h>
30172+#include <asm/pgtable.h>
30173+#include <asm/alternative-asm.h>
30174+
30175+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
30176+#define __copyuser_seg gs;
30177+#else
30178+#define __copyuser_seg
30179+#endif
30180
30181 .text
30182 ENTRY(__get_user_1)
30183 CFI_STARTPROC
30184+
30185+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30186 GET_THREAD_INFO(%_ASM_DX)
30187 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
30188 jae bad_get_user
30189 ASM_STAC
30190-1: movzbl (%_ASM_AX),%edx
30191+
30192+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30193+ mov pax_user_shadow_base,%_ASM_DX
30194+ cmp %_ASM_DX,%_ASM_AX
30195+ jae 1234f
30196+ add %_ASM_DX,%_ASM_AX
30197+1234:
30198+#endif
30199+
30200+#endif
30201+
30202+1: __copyuser_seg movzbl (%_ASM_AX),%edx
30203 xor %eax,%eax
30204 ASM_CLAC
30205+ pax_force_retaddr
30206 ret
30207 CFI_ENDPROC
30208 ENDPROC(__get_user_1)
30209@@ -51,14 +74,28 @@ ENDPROC(__get_user_1)
30210 ENTRY(__get_user_2)
30211 CFI_STARTPROC
30212 add $1,%_ASM_AX
30213+
30214+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30215 jc bad_get_user
30216 GET_THREAD_INFO(%_ASM_DX)
30217 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
30218 jae bad_get_user
30219 ASM_STAC
30220-2: movzwl -1(%_ASM_AX),%edx
30221+
30222+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30223+ mov pax_user_shadow_base,%_ASM_DX
30224+ cmp %_ASM_DX,%_ASM_AX
30225+ jae 1234f
30226+ add %_ASM_DX,%_ASM_AX
30227+1234:
30228+#endif
30229+
30230+#endif
30231+
30232+2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
30233 xor %eax,%eax
30234 ASM_CLAC
30235+ pax_force_retaddr
30236 ret
30237 CFI_ENDPROC
30238 ENDPROC(__get_user_2)
30239@@ -66,14 +103,28 @@ ENDPROC(__get_user_2)
30240 ENTRY(__get_user_4)
30241 CFI_STARTPROC
30242 add $3,%_ASM_AX
30243+
30244+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30245 jc bad_get_user
30246 GET_THREAD_INFO(%_ASM_DX)
30247 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
30248 jae bad_get_user
30249 ASM_STAC
30250-3: movl -3(%_ASM_AX),%edx
30251+
30252+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30253+ mov pax_user_shadow_base,%_ASM_DX
30254+ cmp %_ASM_DX,%_ASM_AX
30255+ jae 1234f
30256+ add %_ASM_DX,%_ASM_AX
30257+1234:
30258+#endif
30259+
30260+#endif
30261+
30262+3: __copyuser_seg movl -3(%_ASM_AX),%edx
30263 xor %eax,%eax
30264 ASM_CLAC
30265+ pax_force_retaddr
30266 ret
30267 CFI_ENDPROC
30268 ENDPROC(__get_user_4)
30269@@ -86,10 +137,20 @@ ENTRY(__get_user_8)
30270 GET_THREAD_INFO(%_ASM_DX)
30271 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
30272 jae bad_get_user
30273+
30274+#ifdef CONFIG_PAX_MEMORY_UDEREF
30275+ mov pax_user_shadow_base,%_ASM_DX
30276+ cmp %_ASM_DX,%_ASM_AX
30277+ jae 1234f
30278+ add %_ASM_DX,%_ASM_AX
30279+1234:
30280+#endif
30281+
30282 ASM_STAC
30283 4: movq -7(%_ASM_AX),%rdx
30284 xor %eax,%eax
30285 ASM_CLAC
30286+ pax_force_retaddr
30287 ret
30288 #else
30289 add $7,%_ASM_AX
30290@@ -98,10 +159,11 @@ ENTRY(__get_user_8)
30291 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
30292 jae bad_get_user_8
30293 ASM_STAC
30294-4: movl -7(%_ASM_AX),%edx
30295-5: movl -3(%_ASM_AX),%ecx
30296+4: __copyuser_seg movl -7(%_ASM_AX),%edx
30297+5: __copyuser_seg movl -3(%_ASM_AX),%ecx
30298 xor %eax,%eax
30299 ASM_CLAC
30300+ pax_force_retaddr
30301 ret
30302 #endif
30303 CFI_ENDPROC
30304@@ -113,6 +175,7 @@ bad_get_user:
30305 xor %edx,%edx
30306 mov $(-EFAULT),%_ASM_AX
30307 ASM_CLAC
30308+ pax_force_retaddr
30309 ret
30310 CFI_ENDPROC
30311 END(bad_get_user)
30312@@ -124,6 +187,7 @@ bad_get_user_8:
30313 xor %ecx,%ecx
30314 mov $(-EFAULT),%_ASM_AX
30315 ASM_CLAC
30316+ pax_force_retaddr
30317 ret
30318 CFI_ENDPROC
30319 END(bad_get_user_8)
30320diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
30321index 54fcffe..7be149e 100644
30322--- a/arch/x86/lib/insn.c
30323+++ b/arch/x86/lib/insn.c
30324@@ -20,8 +20,10 @@
30325
30326 #ifdef __KERNEL__
30327 #include <linux/string.h>
30328+#include <asm/pgtable_types.h>
30329 #else
30330 #include <string.h>
30331+#define ktla_ktva(addr) addr
30332 #endif
30333 #include <asm/inat.h>
30334 #include <asm/insn.h>
30335@@ -53,8 +55,8 @@
30336 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
30337 {
30338 memset(insn, 0, sizeof(*insn));
30339- insn->kaddr = kaddr;
30340- insn->next_byte = kaddr;
30341+ insn->kaddr = ktla_ktva(kaddr);
30342+ insn->next_byte = ktla_ktva(kaddr);
30343 insn->x86_64 = x86_64 ? 1 : 0;
30344 insn->opnd_bytes = 4;
30345 if (x86_64)
30346diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
30347index 05a95e7..326f2fa 100644
30348--- a/arch/x86/lib/iomap_copy_64.S
30349+++ b/arch/x86/lib/iomap_copy_64.S
30350@@ -17,6 +17,7 @@
30351
30352 #include <linux/linkage.h>
30353 #include <asm/dwarf2.h>
30354+#include <asm/alternative-asm.h>
30355
30356 /*
30357 * override generic version in lib/iomap_copy.c
30358@@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
30359 CFI_STARTPROC
30360 movl %edx,%ecx
30361 rep movsd
30362+ pax_force_retaddr
30363 ret
30364 CFI_ENDPROC
30365 ENDPROC(__iowrite32_copy)
30366diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
30367index 56313a3..0db417e 100644
30368--- a/arch/x86/lib/memcpy_64.S
30369+++ b/arch/x86/lib/memcpy_64.S
30370@@ -24,7 +24,7 @@
30371 * This gets patched over the unrolled variant (below) via the
30372 * alternative instructions framework:
30373 */
30374- .section .altinstr_replacement, "ax", @progbits
30375+ .section .altinstr_replacement, "a", @progbits
30376 .Lmemcpy_c:
30377 movq %rdi, %rax
30378 movq %rdx, %rcx
30379@@ -33,6 +33,7 @@
30380 rep movsq
30381 movl %edx, %ecx
30382 rep movsb
30383+ pax_force_retaddr
30384 ret
30385 .Lmemcpy_e:
30386 .previous
30387@@ -44,11 +45,12 @@
30388 * This gets patched over the unrolled variant (below) via the
30389 * alternative instructions framework:
30390 */
30391- .section .altinstr_replacement, "ax", @progbits
30392+ .section .altinstr_replacement, "a", @progbits
30393 .Lmemcpy_c_e:
30394 movq %rdi, %rax
30395 movq %rdx, %rcx
30396 rep movsb
30397+ pax_force_retaddr
30398 ret
30399 .Lmemcpy_e_e:
30400 .previous
30401@@ -136,6 +138,7 @@ ENTRY(memcpy)
30402 movq %r9, 1*8(%rdi)
30403 movq %r10, -2*8(%rdi, %rdx)
30404 movq %r11, -1*8(%rdi, %rdx)
30405+ pax_force_retaddr
30406 retq
30407 .p2align 4
30408 .Lless_16bytes:
30409@@ -148,6 +151,7 @@ ENTRY(memcpy)
30410 movq -1*8(%rsi, %rdx), %r9
30411 movq %r8, 0*8(%rdi)
30412 movq %r9, -1*8(%rdi, %rdx)
30413+ pax_force_retaddr
30414 retq
30415 .p2align 4
30416 .Lless_8bytes:
30417@@ -161,6 +165,7 @@ ENTRY(memcpy)
30418 movl -4(%rsi, %rdx), %r8d
30419 movl %ecx, (%rdi)
30420 movl %r8d, -4(%rdi, %rdx)
30421+ pax_force_retaddr
30422 retq
30423 .p2align 4
30424 .Lless_3bytes:
30425@@ -179,6 +184,7 @@ ENTRY(memcpy)
30426 movb %cl, (%rdi)
30427
30428 .Lend:
30429+ pax_force_retaddr
30430 retq
30431 CFI_ENDPROC
30432 ENDPROC(memcpy)
30433diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
30434index 65268a6..dd1de11 100644
30435--- a/arch/x86/lib/memmove_64.S
30436+++ b/arch/x86/lib/memmove_64.S
30437@@ -202,14 +202,16 @@ ENTRY(memmove)
30438 movb (%rsi), %r11b
30439 movb %r11b, (%rdi)
30440 13:
30441+ pax_force_retaddr
30442 retq
30443 CFI_ENDPROC
30444
30445- .section .altinstr_replacement,"ax"
30446+ .section .altinstr_replacement,"a"
30447 .Lmemmove_begin_forward_efs:
30448 /* Forward moving data. */
30449 movq %rdx, %rcx
30450 rep movsb
30451+ pax_force_retaddr
30452 retq
30453 .Lmemmove_end_forward_efs:
30454 .previous
30455diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
30456index 2dcb380..2eb79fe 100644
30457--- a/arch/x86/lib/memset_64.S
30458+++ b/arch/x86/lib/memset_64.S
30459@@ -16,7 +16,7 @@
30460 *
30461 * rax original destination
30462 */
30463- .section .altinstr_replacement, "ax", @progbits
30464+ .section .altinstr_replacement, "a", @progbits
30465 .Lmemset_c:
30466 movq %rdi,%r9
30467 movq %rdx,%rcx
30468@@ -30,6 +30,7 @@
30469 movl %edx,%ecx
30470 rep stosb
30471 movq %r9,%rax
30472+ pax_force_retaddr
30473 ret
30474 .Lmemset_e:
30475 .previous
30476@@ -45,13 +46,14 @@
30477 *
30478 * rax original destination
30479 */
30480- .section .altinstr_replacement, "ax", @progbits
30481+ .section .altinstr_replacement, "a", @progbits
30482 .Lmemset_c_e:
30483 movq %rdi,%r9
30484 movb %sil,%al
30485 movq %rdx,%rcx
30486 rep stosb
30487 movq %r9,%rax
30488+ pax_force_retaddr
30489 ret
30490 .Lmemset_e_e:
30491 .previous
30492@@ -118,6 +120,7 @@ ENTRY(__memset)
30493
30494 .Lende:
30495 movq %r10,%rax
30496+ pax_force_retaddr
30497 ret
30498
30499 CFI_RESTORE_STATE
30500diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
30501index c9f2d9b..e7fd2c0 100644
30502--- a/arch/x86/lib/mmx_32.c
30503+++ b/arch/x86/lib/mmx_32.c
30504@@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
30505 {
30506 void *p;
30507 int i;
30508+ unsigned long cr0;
30509
30510 if (unlikely(in_interrupt()))
30511 return __memcpy(to, from, len);
30512@@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
30513 kernel_fpu_begin();
30514
30515 __asm__ __volatile__ (
30516- "1: prefetch (%0)\n" /* This set is 28 bytes */
30517- " prefetch 64(%0)\n"
30518- " prefetch 128(%0)\n"
30519- " prefetch 192(%0)\n"
30520- " prefetch 256(%0)\n"
30521+ "1: prefetch (%1)\n" /* This set is 28 bytes */
30522+ " prefetch 64(%1)\n"
30523+ " prefetch 128(%1)\n"
30524+ " prefetch 192(%1)\n"
30525+ " prefetch 256(%1)\n"
30526 "2: \n"
30527 ".section .fixup, \"ax\"\n"
30528- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30529+ "3: \n"
30530+
30531+#ifdef CONFIG_PAX_KERNEXEC
30532+ " movl %%cr0, %0\n"
30533+ " movl %0, %%eax\n"
30534+ " andl $0xFFFEFFFF, %%eax\n"
30535+ " movl %%eax, %%cr0\n"
30536+#endif
30537+
30538+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30539+
30540+#ifdef CONFIG_PAX_KERNEXEC
30541+ " movl %0, %%cr0\n"
30542+#endif
30543+
30544 " jmp 2b\n"
30545 ".previous\n"
30546 _ASM_EXTABLE(1b, 3b)
30547- : : "r" (from));
30548+ : "=&r" (cr0) : "r" (from) : "ax");
30549
30550 for ( ; i > 5; i--) {
30551 __asm__ __volatile__ (
30552- "1: prefetch 320(%0)\n"
30553- "2: movq (%0), %%mm0\n"
30554- " movq 8(%0), %%mm1\n"
30555- " movq 16(%0), %%mm2\n"
30556- " movq 24(%0), %%mm3\n"
30557- " movq %%mm0, (%1)\n"
30558- " movq %%mm1, 8(%1)\n"
30559- " movq %%mm2, 16(%1)\n"
30560- " movq %%mm3, 24(%1)\n"
30561- " movq 32(%0), %%mm0\n"
30562- " movq 40(%0), %%mm1\n"
30563- " movq 48(%0), %%mm2\n"
30564- " movq 56(%0), %%mm3\n"
30565- " movq %%mm0, 32(%1)\n"
30566- " movq %%mm1, 40(%1)\n"
30567- " movq %%mm2, 48(%1)\n"
30568- " movq %%mm3, 56(%1)\n"
30569+ "1: prefetch 320(%1)\n"
30570+ "2: movq (%1), %%mm0\n"
30571+ " movq 8(%1), %%mm1\n"
30572+ " movq 16(%1), %%mm2\n"
30573+ " movq 24(%1), %%mm3\n"
30574+ " movq %%mm0, (%2)\n"
30575+ " movq %%mm1, 8(%2)\n"
30576+ " movq %%mm2, 16(%2)\n"
30577+ " movq %%mm3, 24(%2)\n"
30578+ " movq 32(%1), %%mm0\n"
30579+ " movq 40(%1), %%mm1\n"
30580+ " movq 48(%1), %%mm2\n"
30581+ " movq 56(%1), %%mm3\n"
30582+ " movq %%mm0, 32(%2)\n"
30583+ " movq %%mm1, 40(%2)\n"
30584+ " movq %%mm2, 48(%2)\n"
30585+ " movq %%mm3, 56(%2)\n"
30586 ".section .fixup, \"ax\"\n"
30587- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30588+ "3:\n"
30589+
30590+#ifdef CONFIG_PAX_KERNEXEC
30591+ " movl %%cr0, %0\n"
30592+ " movl %0, %%eax\n"
30593+ " andl $0xFFFEFFFF, %%eax\n"
30594+ " movl %%eax, %%cr0\n"
30595+#endif
30596+
30597+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30598+
30599+#ifdef CONFIG_PAX_KERNEXEC
30600+ " movl %0, %%cr0\n"
30601+#endif
30602+
30603 " jmp 2b\n"
30604 ".previous\n"
30605 _ASM_EXTABLE(1b, 3b)
30606- : : "r" (from), "r" (to) : "memory");
30607+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
30608
30609 from += 64;
30610 to += 64;
30611@@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
30612 static void fast_copy_page(void *to, void *from)
30613 {
30614 int i;
30615+ unsigned long cr0;
30616
30617 kernel_fpu_begin();
30618
30619@@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
30620 * but that is for later. -AV
30621 */
30622 __asm__ __volatile__(
30623- "1: prefetch (%0)\n"
30624- " prefetch 64(%0)\n"
30625- " prefetch 128(%0)\n"
30626- " prefetch 192(%0)\n"
30627- " prefetch 256(%0)\n"
30628+ "1: prefetch (%1)\n"
30629+ " prefetch 64(%1)\n"
30630+ " prefetch 128(%1)\n"
30631+ " prefetch 192(%1)\n"
30632+ " prefetch 256(%1)\n"
30633 "2: \n"
30634 ".section .fixup, \"ax\"\n"
30635- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30636+ "3: \n"
30637+
30638+#ifdef CONFIG_PAX_KERNEXEC
30639+ " movl %%cr0, %0\n"
30640+ " movl %0, %%eax\n"
30641+ " andl $0xFFFEFFFF, %%eax\n"
30642+ " movl %%eax, %%cr0\n"
30643+#endif
30644+
30645+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30646+
30647+#ifdef CONFIG_PAX_KERNEXEC
30648+ " movl %0, %%cr0\n"
30649+#endif
30650+
30651 " jmp 2b\n"
30652 ".previous\n"
30653- _ASM_EXTABLE(1b, 3b) : : "r" (from));
30654+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
30655
30656 for (i = 0; i < (4096-320)/64; i++) {
30657 __asm__ __volatile__ (
30658- "1: prefetch 320(%0)\n"
30659- "2: movq (%0), %%mm0\n"
30660- " movntq %%mm0, (%1)\n"
30661- " movq 8(%0), %%mm1\n"
30662- " movntq %%mm1, 8(%1)\n"
30663- " movq 16(%0), %%mm2\n"
30664- " movntq %%mm2, 16(%1)\n"
30665- " movq 24(%0), %%mm3\n"
30666- " movntq %%mm3, 24(%1)\n"
30667- " movq 32(%0), %%mm4\n"
30668- " movntq %%mm4, 32(%1)\n"
30669- " movq 40(%0), %%mm5\n"
30670- " movntq %%mm5, 40(%1)\n"
30671- " movq 48(%0), %%mm6\n"
30672- " movntq %%mm6, 48(%1)\n"
30673- " movq 56(%0), %%mm7\n"
30674- " movntq %%mm7, 56(%1)\n"
30675+ "1: prefetch 320(%1)\n"
30676+ "2: movq (%1), %%mm0\n"
30677+ " movntq %%mm0, (%2)\n"
30678+ " movq 8(%1), %%mm1\n"
30679+ " movntq %%mm1, 8(%2)\n"
30680+ " movq 16(%1), %%mm2\n"
30681+ " movntq %%mm2, 16(%2)\n"
30682+ " movq 24(%1), %%mm3\n"
30683+ " movntq %%mm3, 24(%2)\n"
30684+ " movq 32(%1), %%mm4\n"
30685+ " movntq %%mm4, 32(%2)\n"
30686+ " movq 40(%1), %%mm5\n"
30687+ " movntq %%mm5, 40(%2)\n"
30688+ " movq 48(%1), %%mm6\n"
30689+ " movntq %%mm6, 48(%2)\n"
30690+ " movq 56(%1), %%mm7\n"
30691+ " movntq %%mm7, 56(%2)\n"
30692 ".section .fixup, \"ax\"\n"
30693- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30694+ "3:\n"
30695+
30696+#ifdef CONFIG_PAX_KERNEXEC
30697+ " movl %%cr0, %0\n"
30698+ " movl %0, %%eax\n"
30699+ " andl $0xFFFEFFFF, %%eax\n"
30700+ " movl %%eax, %%cr0\n"
30701+#endif
30702+
30703+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30704+
30705+#ifdef CONFIG_PAX_KERNEXEC
30706+ " movl %0, %%cr0\n"
30707+#endif
30708+
30709 " jmp 2b\n"
30710 ".previous\n"
30711- _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
30712+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
30713
30714 from += 64;
30715 to += 64;
30716@@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
30717 static void fast_copy_page(void *to, void *from)
30718 {
30719 int i;
30720+ unsigned long cr0;
30721
30722 kernel_fpu_begin();
30723
30724 __asm__ __volatile__ (
30725- "1: prefetch (%0)\n"
30726- " prefetch 64(%0)\n"
30727- " prefetch 128(%0)\n"
30728- " prefetch 192(%0)\n"
30729- " prefetch 256(%0)\n"
30730+ "1: prefetch (%1)\n"
30731+ " prefetch 64(%1)\n"
30732+ " prefetch 128(%1)\n"
30733+ " prefetch 192(%1)\n"
30734+ " prefetch 256(%1)\n"
30735 "2: \n"
30736 ".section .fixup, \"ax\"\n"
30737- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30738+ "3: \n"
30739+
30740+#ifdef CONFIG_PAX_KERNEXEC
30741+ " movl %%cr0, %0\n"
30742+ " movl %0, %%eax\n"
30743+ " andl $0xFFFEFFFF, %%eax\n"
30744+ " movl %%eax, %%cr0\n"
30745+#endif
30746+
30747+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30748+
30749+#ifdef CONFIG_PAX_KERNEXEC
30750+ " movl %0, %%cr0\n"
30751+#endif
30752+
30753 " jmp 2b\n"
30754 ".previous\n"
30755- _ASM_EXTABLE(1b, 3b) : : "r" (from));
30756+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
30757
30758 for (i = 0; i < 4096/64; i++) {
30759 __asm__ __volatile__ (
30760- "1: prefetch 320(%0)\n"
30761- "2: movq (%0), %%mm0\n"
30762- " movq 8(%0), %%mm1\n"
30763- " movq 16(%0), %%mm2\n"
30764- " movq 24(%0), %%mm3\n"
30765- " movq %%mm0, (%1)\n"
30766- " movq %%mm1, 8(%1)\n"
30767- " movq %%mm2, 16(%1)\n"
30768- " movq %%mm3, 24(%1)\n"
30769- " movq 32(%0), %%mm0\n"
30770- " movq 40(%0), %%mm1\n"
30771- " movq 48(%0), %%mm2\n"
30772- " movq 56(%0), %%mm3\n"
30773- " movq %%mm0, 32(%1)\n"
30774- " movq %%mm1, 40(%1)\n"
30775- " movq %%mm2, 48(%1)\n"
30776- " movq %%mm3, 56(%1)\n"
30777+ "1: prefetch 320(%1)\n"
30778+ "2: movq (%1), %%mm0\n"
30779+ " movq 8(%1), %%mm1\n"
30780+ " movq 16(%1), %%mm2\n"
30781+ " movq 24(%1), %%mm3\n"
30782+ " movq %%mm0, (%2)\n"
30783+ " movq %%mm1, 8(%2)\n"
30784+ " movq %%mm2, 16(%2)\n"
30785+ " movq %%mm3, 24(%2)\n"
30786+ " movq 32(%1), %%mm0\n"
30787+ " movq 40(%1), %%mm1\n"
30788+ " movq 48(%1), %%mm2\n"
30789+ " movq 56(%1), %%mm3\n"
30790+ " movq %%mm0, 32(%2)\n"
30791+ " movq %%mm1, 40(%2)\n"
30792+ " movq %%mm2, 48(%2)\n"
30793+ " movq %%mm3, 56(%2)\n"
30794 ".section .fixup, \"ax\"\n"
30795- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30796+ "3:\n"
30797+
30798+#ifdef CONFIG_PAX_KERNEXEC
30799+ " movl %%cr0, %0\n"
30800+ " movl %0, %%eax\n"
30801+ " andl $0xFFFEFFFF, %%eax\n"
30802+ " movl %%eax, %%cr0\n"
30803+#endif
30804+
30805+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30806+
30807+#ifdef CONFIG_PAX_KERNEXEC
30808+ " movl %0, %%cr0\n"
30809+#endif
30810+
30811 " jmp 2b\n"
30812 ".previous\n"
30813 _ASM_EXTABLE(1b, 3b)
30814- : : "r" (from), "r" (to) : "memory");
30815+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
30816
30817 from += 64;
30818 to += 64;
30819diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
30820index f6d13ee..d789440 100644
30821--- a/arch/x86/lib/msr-reg.S
30822+++ b/arch/x86/lib/msr-reg.S
30823@@ -3,6 +3,7 @@
30824 #include <asm/dwarf2.h>
30825 #include <asm/asm.h>
30826 #include <asm/msr.h>
30827+#include <asm/alternative-asm.h>
30828
30829 #ifdef CONFIG_X86_64
30830 /*
30831@@ -37,6 +38,7 @@ ENTRY(\op\()_safe_regs)
30832 movl %edi, 28(%r10)
30833 popq_cfi %rbp
30834 popq_cfi %rbx
30835+ pax_force_retaddr
30836 ret
30837 3:
30838 CFI_RESTORE_STATE
30839diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
30840index fc6ba17..d4d989d 100644
30841--- a/arch/x86/lib/putuser.S
30842+++ b/arch/x86/lib/putuser.S
30843@@ -16,7 +16,9 @@
30844 #include <asm/errno.h>
30845 #include <asm/asm.h>
30846 #include <asm/smap.h>
30847-
30848+#include <asm/segment.h>
30849+#include <asm/pgtable.h>
30850+#include <asm/alternative-asm.h>
30851
30852 /*
30853 * __put_user_X
30854@@ -30,57 +32,125 @@
30855 * as they get called from within inline assembly.
30856 */
30857
30858-#define ENTER CFI_STARTPROC ; \
30859- GET_THREAD_INFO(%_ASM_BX)
30860-#define EXIT ASM_CLAC ; \
30861- ret ; \
30862+#define ENTER CFI_STARTPROC
30863+#define EXIT ASM_CLAC ; \
30864+ pax_force_retaddr ; \
30865+ ret ; \
30866 CFI_ENDPROC
30867
30868+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30869+#define _DEST %_ASM_CX,%_ASM_BX
30870+#else
30871+#define _DEST %_ASM_CX
30872+#endif
30873+
30874+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
30875+#define __copyuser_seg gs;
30876+#else
30877+#define __copyuser_seg
30878+#endif
30879+
30880 .text
30881 ENTRY(__put_user_1)
30882 ENTER
30883+
30884+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30885+ GET_THREAD_INFO(%_ASM_BX)
30886 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
30887 jae bad_put_user
30888 ASM_STAC
30889-1: movb %al,(%_ASM_CX)
30890+
30891+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30892+ mov pax_user_shadow_base,%_ASM_BX
30893+ cmp %_ASM_BX,%_ASM_CX
30894+ jb 1234f
30895+ xor %ebx,%ebx
30896+1234:
30897+#endif
30898+
30899+#endif
30900+
30901+1: __copyuser_seg movb %al,(_DEST)
30902 xor %eax,%eax
30903 EXIT
30904 ENDPROC(__put_user_1)
30905
30906 ENTRY(__put_user_2)
30907 ENTER
30908+
30909+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30910+ GET_THREAD_INFO(%_ASM_BX)
30911 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
30912 sub $1,%_ASM_BX
30913 cmp %_ASM_BX,%_ASM_CX
30914 jae bad_put_user
30915 ASM_STAC
30916-2: movw %ax,(%_ASM_CX)
30917+
30918+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30919+ mov pax_user_shadow_base,%_ASM_BX
30920+ cmp %_ASM_BX,%_ASM_CX
30921+ jb 1234f
30922+ xor %ebx,%ebx
30923+1234:
30924+#endif
30925+
30926+#endif
30927+
30928+2: __copyuser_seg movw %ax,(_DEST)
30929 xor %eax,%eax
30930 EXIT
30931 ENDPROC(__put_user_2)
30932
30933 ENTRY(__put_user_4)
30934 ENTER
30935+
30936+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30937+ GET_THREAD_INFO(%_ASM_BX)
30938 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
30939 sub $3,%_ASM_BX
30940 cmp %_ASM_BX,%_ASM_CX
30941 jae bad_put_user
30942 ASM_STAC
30943-3: movl %eax,(%_ASM_CX)
30944+
30945+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30946+ mov pax_user_shadow_base,%_ASM_BX
30947+ cmp %_ASM_BX,%_ASM_CX
30948+ jb 1234f
30949+ xor %ebx,%ebx
30950+1234:
30951+#endif
30952+
30953+#endif
30954+
30955+3: __copyuser_seg movl %eax,(_DEST)
30956 xor %eax,%eax
30957 EXIT
30958 ENDPROC(__put_user_4)
30959
30960 ENTRY(__put_user_8)
30961 ENTER
30962+
30963+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30964+ GET_THREAD_INFO(%_ASM_BX)
30965 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
30966 sub $7,%_ASM_BX
30967 cmp %_ASM_BX,%_ASM_CX
30968 jae bad_put_user
30969 ASM_STAC
30970-4: mov %_ASM_AX,(%_ASM_CX)
30971+
30972+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30973+ mov pax_user_shadow_base,%_ASM_BX
30974+ cmp %_ASM_BX,%_ASM_CX
30975+ jb 1234f
30976+ xor %ebx,%ebx
30977+1234:
30978+#endif
30979+
30980+#endif
30981+
30982+4: __copyuser_seg mov %_ASM_AX,(_DEST)
30983 #ifdef CONFIG_X86_32
30984-5: movl %edx,4(%_ASM_CX)
30985+5: __copyuser_seg movl %edx,4(_DEST)
30986 #endif
30987 xor %eax,%eax
30988 EXIT
30989diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
30990index 5dff5f0..cadebf4 100644
30991--- a/arch/x86/lib/rwsem.S
30992+++ b/arch/x86/lib/rwsem.S
30993@@ -94,6 +94,7 @@ ENTRY(call_rwsem_down_read_failed)
30994 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
30995 CFI_RESTORE __ASM_REG(dx)
30996 restore_common_regs
30997+ pax_force_retaddr
30998 ret
30999 CFI_ENDPROC
31000 ENDPROC(call_rwsem_down_read_failed)
31001@@ -104,6 +105,7 @@ ENTRY(call_rwsem_down_write_failed)
31002 movq %rax,%rdi
31003 call rwsem_down_write_failed
31004 restore_common_regs
31005+ pax_force_retaddr
31006 ret
31007 CFI_ENDPROC
31008 ENDPROC(call_rwsem_down_write_failed)
31009@@ -117,7 +119,8 @@ ENTRY(call_rwsem_wake)
31010 movq %rax,%rdi
31011 call rwsem_wake
31012 restore_common_regs
31013-1: ret
31014+1: pax_force_retaddr
31015+ ret
31016 CFI_ENDPROC
31017 ENDPROC(call_rwsem_wake)
31018
31019@@ -131,6 +134,7 @@ ENTRY(call_rwsem_downgrade_wake)
31020 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
31021 CFI_RESTORE __ASM_REG(dx)
31022 restore_common_regs
31023+ pax_force_retaddr
31024 ret
31025 CFI_ENDPROC
31026 ENDPROC(call_rwsem_downgrade_wake)
31027diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
31028index b30b5eb..2b57052 100644
31029--- a/arch/x86/lib/thunk_64.S
31030+++ b/arch/x86/lib/thunk_64.S
31031@@ -9,6 +9,7 @@
31032 #include <asm/dwarf2.h>
31033 #include <asm/calling.h>
31034 #include <asm/asm.h>
31035+#include <asm/alternative-asm.h>
31036
31037 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
31038 .macro THUNK name, func, put_ret_addr_in_rdi=0
31039@@ -16,11 +17,11 @@
31040 \name:
31041 CFI_STARTPROC
31042
31043- /* this one pushes 9 elems, the next one would be %rIP */
31044- SAVE_ARGS
31045+ /* this one pushes 15+1 elems, the next one would be %rIP */
31046+ SAVE_ARGS 8
31047
31048 .if \put_ret_addr_in_rdi
31049- movq_cfi_restore 9*8, rdi
31050+ movq_cfi_restore RIP, rdi
31051 .endif
31052
31053 call \func
31054@@ -47,9 +48,10 @@
31055
31056 /* SAVE_ARGS below is used only for the .cfi directives it contains. */
31057 CFI_STARTPROC
31058- SAVE_ARGS
31059+ SAVE_ARGS 8
31060 restore:
31061- RESTORE_ARGS
31062+ RESTORE_ARGS 1,8
31063+ pax_force_retaddr
31064 ret
31065 CFI_ENDPROC
31066 _ASM_NOKPROBE(restore)
31067diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
31068index e2f5e21..4b22130 100644
31069--- a/arch/x86/lib/usercopy_32.c
31070+++ b/arch/x86/lib/usercopy_32.c
31071@@ -42,11 +42,13 @@ do { \
31072 int __d0; \
31073 might_fault(); \
31074 __asm__ __volatile__( \
31075+ __COPYUSER_SET_ES \
31076 ASM_STAC "\n" \
31077 "0: rep; stosl\n" \
31078 " movl %2,%0\n" \
31079 "1: rep; stosb\n" \
31080 "2: " ASM_CLAC "\n" \
31081+ __COPYUSER_RESTORE_ES \
31082 ".section .fixup,\"ax\"\n" \
31083 "3: lea 0(%2,%0,4),%0\n" \
31084 " jmp 2b\n" \
31085@@ -98,7 +100,7 @@ EXPORT_SYMBOL(__clear_user);
31086
31087 #ifdef CONFIG_X86_INTEL_USERCOPY
31088 static unsigned long
31089-__copy_user_intel(void __user *to, const void *from, unsigned long size)
31090+__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
31091 {
31092 int d0, d1;
31093 __asm__ __volatile__(
31094@@ -110,36 +112,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
31095 " .align 2,0x90\n"
31096 "3: movl 0(%4), %%eax\n"
31097 "4: movl 4(%4), %%edx\n"
31098- "5: movl %%eax, 0(%3)\n"
31099- "6: movl %%edx, 4(%3)\n"
31100+ "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
31101+ "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
31102 "7: movl 8(%4), %%eax\n"
31103 "8: movl 12(%4),%%edx\n"
31104- "9: movl %%eax, 8(%3)\n"
31105- "10: movl %%edx, 12(%3)\n"
31106+ "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
31107+ "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
31108 "11: movl 16(%4), %%eax\n"
31109 "12: movl 20(%4), %%edx\n"
31110- "13: movl %%eax, 16(%3)\n"
31111- "14: movl %%edx, 20(%3)\n"
31112+ "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
31113+ "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
31114 "15: movl 24(%4), %%eax\n"
31115 "16: movl 28(%4), %%edx\n"
31116- "17: movl %%eax, 24(%3)\n"
31117- "18: movl %%edx, 28(%3)\n"
31118+ "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
31119+ "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
31120 "19: movl 32(%4), %%eax\n"
31121 "20: movl 36(%4), %%edx\n"
31122- "21: movl %%eax, 32(%3)\n"
31123- "22: movl %%edx, 36(%3)\n"
31124+ "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
31125+ "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
31126 "23: movl 40(%4), %%eax\n"
31127 "24: movl 44(%4), %%edx\n"
31128- "25: movl %%eax, 40(%3)\n"
31129- "26: movl %%edx, 44(%3)\n"
31130+ "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
31131+ "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
31132 "27: movl 48(%4), %%eax\n"
31133 "28: movl 52(%4), %%edx\n"
31134- "29: movl %%eax, 48(%3)\n"
31135- "30: movl %%edx, 52(%3)\n"
31136+ "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
31137+ "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
31138 "31: movl 56(%4), %%eax\n"
31139 "32: movl 60(%4), %%edx\n"
31140- "33: movl %%eax, 56(%3)\n"
31141- "34: movl %%edx, 60(%3)\n"
31142+ "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
31143+ "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
31144 " addl $-64, %0\n"
31145 " addl $64, %4\n"
31146 " addl $64, %3\n"
31147@@ -149,10 +151,116 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
31148 " shrl $2, %0\n"
31149 " andl $3, %%eax\n"
31150 " cld\n"
31151+ __COPYUSER_SET_ES
31152 "99: rep; movsl\n"
31153 "36: movl %%eax, %0\n"
31154 "37: rep; movsb\n"
31155 "100:\n"
31156+ __COPYUSER_RESTORE_ES
31157+ ".section .fixup,\"ax\"\n"
31158+ "101: lea 0(%%eax,%0,4),%0\n"
31159+ " jmp 100b\n"
31160+ ".previous\n"
31161+ _ASM_EXTABLE(1b,100b)
31162+ _ASM_EXTABLE(2b,100b)
31163+ _ASM_EXTABLE(3b,100b)
31164+ _ASM_EXTABLE(4b,100b)
31165+ _ASM_EXTABLE(5b,100b)
31166+ _ASM_EXTABLE(6b,100b)
31167+ _ASM_EXTABLE(7b,100b)
31168+ _ASM_EXTABLE(8b,100b)
31169+ _ASM_EXTABLE(9b,100b)
31170+ _ASM_EXTABLE(10b,100b)
31171+ _ASM_EXTABLE(11b,100b)
31172+ _ASM_EXTABLE(12b,100b)
31173+ _ASM_EXTABLE(13b,100b)
31174+ _ASM_EXTABLE(14b,100b)
31175+ _ASM_EXTABLE(15b,100b)
31176+ _ASM_EXTABLE(16b,100b)
31177+ _ASM_EXTABLE(17b,100b)
31178+ _ASM_EXTABLE(18b,100b)
31179+ _ASM_EXTABLE(19b,100b)
31180+ _ASM_EXTABLE(20b,100b)
31181+ _ASM_EXTABLE(21b,100b)
31182+ _ASM_EXTABLE(22b,100b)
31183+ _ASM_EXTABLE(23b,100b)
31184+ _ASM_EXTABLE(24b,100b)
31185+ _ASM_EXTABLE(25b,100b)
31186+ _ASM_EXTABLE(26b,100b)
31187+ _ASM_EXTABLE(27b,100b)
31188+ _ASM_EXTABLE(28b,100b)
31189+ _ASM_EXTABLE(29b,100b)
31190+ _ASM_EXTABLE(30b,100b)
31191+ _ASM_EXTABLE(31b,100b)
31192+ _ASM_EXTABLE(32b,100b)
31193+ _ASM_EXTABLE(33b,100b)
31194+ _ASM_EXTABLE(34b,100b)
31195+ _ASM_EXTABLE(35b,100b)
31196+ _ASM_EXTABLE(36b,100b)
31197+ _ASM_EXTABLE(37b,100b)
31198+ _ASM_EXTABLE(99b,101b)
31199+ : "=&c"(size), "=&D" (d0), "=&S" (d1)
31200+ : "1"(to), "2"(from), "0"(size)
31201+ : "eax", "edx", "memory");
31202+ return size;
31203+}
31204+
31205+static unsigned long
31206+__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
31207+{
31208+ int d0, d1;
31209+ __asm__ __volatile__(
31210+ " .align 2,0x90\n"
31211+ "1: "__copyuser_seg" movl 32(%4), %%eax\n"
31212+ " cmpl $67, %0\n"
31213+ " jbe 3f\n"
31214+ "2: "__copyuser_seg" movl 64(%4), %%eax\n"
31215+ " .align 2,0x90\n"
31216+ "3: "__copyuser_seg" movl 0(%4), %%eax\n"
31217+ "4: "__copyuser_seg" movl 4(%4), %%edx\n"
31218+ "5: movl %%eax, 0(%3)\n"
31219+ "6: movl %%edx, 4(%3)\n"
31220+ "7: "__copyuser_seg" movl 8(%4), %%eax\n"
31221+ "8: "__copyuser_seg" movl 12(%4),%%edx\n"
31222+ "9: movl %%eax, 8(%3)\n"
31223+ "10: movl %%edx, 12(%3)\n"
31224+ "11: "__copyuser_seg" movl 16(%4), %%eax\n"
31225+ "12: "__copyuser_seg" movl 20(%4), %%edx\n"
31226+ "13: movl %%eax, 16(%3)\n"
31227+ "14: movl %%edx, 20(%3)\n"
31228+ "15: "__copyuser_seg" movl 24(%4), %%eax\n"
31229+ "16: "__copyuser_seg" movl 28(%4), %%edx\n"
31230+ "17: movl %%eax, 24(%3)\n"
31231+ "18: movl %%edx, 28(%3)\n"
31232+ "19: "__copyuser_seg" movl 32(%4), %%eax\n"
31233+ "20: "__copyuser_seg" movl 36(%4), %%edx\n"
31234+ "21: movl %%eax, 32(%3)\n"
31235+ "22: movl %%edx, 36(%3)\n"
31236+ "23: "__copyuser_seg" movl 40(%4), %%eax\n"
31237+ "24: "__copyuser_seg" movl 44(%4), %%edx\n"
31238+ "25: movl %%eax, 40(%3)\n"
31239+ "26: movl %%edx, 44(%3)\n"
31240+ "27: "__copyuser_seg" movl 48(%4), %%eax\n"
31241+ "28: "__copyuser_seg" movl 52(%4), %%edx\n"
31242+ "29: movl %%eax, 48(%3)\n"
31243+ "30: movl %%edx, 52(%3)\n"
31244+ "31: "__copyuser_seg" movl 56(%4), %%eax\n"
31245+ "32: "__copyuser_seg" movl 60(%4), %%edx\n"
31246+ "33: movl %%eax, 56(%3)\n"
31247+ "34: movl %%edx, 60(%3)\n"
31248+ " addl $-64, %0\n"
31249+ " addl $64, %4\n"
31250+ " addl $64, %3\n"
31251+ " cmpl $63, %0\n"
31252+ " ja 1b\n"
31253+ "35: movl %0, %%eax\n"
31254+ " shrl $2, %0\n"
31255+ " andl $3, %%eax\n"
31256+ " cld\n"
31257+ "99: rep; "__copyuser_seg" movsl\n"
31258+ "36: movl %%eax, %0\n"
31259+ "37: rep; "__copyuser_seg" movsb\n"
31260+ "100:\n"
31261 ".section .fixup,\"ax\"\n"
31262 "101: lea 0(%%eax,%0,4),%0\n"
31263 " jmp 100b\n"
31264@@ -207,41 +315,41 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
31265 int d0, d1;
31266 __asm__ __volatile__(
31267 " .align 2,0x90\n"
31268- "0: movl 32(%4), %%eax\n"
31269+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
31270 " cmpl $67, %0\n"
31271 " jbe 2f\n"
31272- "1: movl 64(%4), %%eax\n"
31273+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
31274 " .align 2,0x90\n"
31275- "2: movl 0(%4), %%eax\n"
31276- "21: movl 4(%4), %%edx\n"
31277+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
31278+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
31279 " movl %%eax, 0(%3)\n"
31280 " movl %%edx, 4(%3)\n"
31281- "3: movl 8(%4), %%eax\n"
31282- "31: movl 12(%4),%%edx\n"
31283+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
31284+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
31285 " movl %%eax, 8(%3)\n"
31286 " movl %%edx, 12(%3)\n"
31287- "4: movl 16(%4), %%eax\n"
31288- "41: movl 20(%4), %%edx\n"
31289+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
31290+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
31291 " movl %%eax, 16(%3)\n"
31292 " movl %%edx, 20(%3)\n"
31293- "10: movl 24(%4), %%eax\n"
31294- "51: movl 28(%4), %%edx\n"
31295+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
31296+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
31297 " movl %%eax, 24(%3)\n"
31298 " movl %%edx, 28(%3)\n"
31299- "11: movl 32(%4), %%eax\n"
31300- "61: movl 36(%4), %%edx\n"
31301+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
31302+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
31303 " movl %%eax, 32(%3)\n"
31304 " movl %%edx, 36(%3)\n"
31305- "12: movl 40(%4), %%eax\n"
31306- "71: movl 44(%4), %%edx\n"
31307+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
31308+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
31309 " movl %%eax, 40(%3)\n"
31310 " movl %%edx, 44(%3)\n"
31311- "13: movl 48(%4), %%eax\n"
31312- "81: movl 52(%4), %%edx\n"
31313+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
31314+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
31315 " movl %%eax, 48(%3)\n"
31316 " movl %%edx, 52(%3)\n"
31317- "14: movl 56(%4), %%eax\n"
31318- "91: movl 60(%4), %%edx\n"
31319+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
31320+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
31321 " movl %%eax, 56(%3)\n"
31322 " movl %%edx, 60(%3)\n"
31323 " addl $-64, %0\n"
31324@@ -253,9 +361,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
31325 " shrl $2, %0\n"
31326 " andl $3, %%eax\n"
31327 " cld\n"
31328- "6: rep; movsl\n"
31329+ "6: rep; "__copyuser_seg" movsl\n"
31330 " movl %%eax,%0\n"
31331- "7: rep; movsb\n"
31332+ "7: rep; "__copyuser_seg" movsb\n"
31333 "8:\n"
31334 ".section .fixup,\"ax\"\n"
31335 "9: lea 0(%%eax,%0,4),%0\n"
31336@@ -305,41 +413,41 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
31337
31338 __asm__ __volatile__(
31339 " .align 2,0x90\n"
31340- "0: movl 32(%4), %%eax\n"
31341+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
31342 " cmpl $67, %0\n"
31343 " jbe 2f\n"
31344- "1: movl 64(%4), %%eax\n"
31345+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
31346 " .align 2,0x90\n"
31347- "2: movl 0(%4), %%eax\n"
31348- "21: movl 4(%4), %%edx\n"
31349+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
31350+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
31351 " movnti %%eax, 0(%3)\n"
31352 " movnti %%edx, 4(%3)\n"
31353- "3: movl 8(%4), %%eax\n"
31354- "31: movl 12(%4),%%edx\n"
31355+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
31356+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
31357 " movnti %%eax, 8(%3)\n"
31358 " movnti %%edx, 12(%3)\n"
31359- "4: movl 16(%4), %%eax\n"
31360- "41: movl 20(%4), %%edx\n"
31361+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
31362+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
31363 " movnti %%eax, 16(%3)\n"
31364 " movnti %%edx, 20(%3)\n"
31365- "10: movl 24(%4), %%eax\n"
31366- "51: movl 28(%4), %%edx\n"
31367+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
31368+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
31369 " movnti %%eax, 24(%3)\n"
31370 " movnti %%edx, 28(%3)\n"
31371- "11: movl 32(%4), %%eax\n"
31372- "61: movl 36(%4), %%edx\n"
31373+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
31374+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
31375 " movnti %%eax, 32(%3)\n"
31376 " movnti %%edx, 36(%3)\n"
31377- "12: movl 40(%4), %%eax\n"
31378- "71: movl 44(%4), %%edx\n"
31379+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
31380+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
31381 " movnti %%eax, 40(%3)\n"
31382 " movnti %%edx, 44(%3)\n"
31383- "13: movl 48(%4), %%eax\n"
31384- "81: movl 52(%4), %%edx\n"
31385+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
31386+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
31387 " movnti %%eax, 48(%3)\n"
31388 " movnti %%edx, 52(%3)\n"
31389- "14: movl 56(%4), %%eax\n"
31390- "91: movl 60(%4), %%edx\n"
31391+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
31392+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
31393 " movnti %%eax, 56(%3)\n"
31394 " movnti %%edx, 60(%3)\n"
31395 " addl $-64, %0\n"
31396@@ -352,9 +460,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
31397 " shrl $2, %0\n"
31398 " andl $3, %%eax\n"
31399 " cld\n"
31400- "6: rep; movsl\n"
31401+ "6: rep; "__copyuser_seg" movsl\n"
31402 " movl %%eax,%0\n"
31403- "7: rep; movsb\n"
31404+ "7: rep; "__copyuser_seg" movsb\n"
31405 "8:\n"
31406 ".section .fixup,\"ax\"\n"
31407 "9: lea 0(%%eax,%0,4),%0\n"
31408@@ -399,41 +507,41 @@ static unsigned long __copy_user_intel_nocache(void *to,
31409
31410 __asm__ __volatile__(
31411 " .align 2,0x90\n"
31412- "0: movl 32(%4), %%eax\n"
31413+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
31414 " cmpl $67, %0\n"
31415 " jbe 2f\n"
31416- "1: movl 64(%4), %%eax\n"
31417+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
31418 " .align 2,0x90\n"
31419- "2: movl 0(%4), %%eax\n"
31420- "21: movl 4(%4), %%edx\n"
31421+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
31422+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
31423 " movnti %%eax, 0(%3)\n"
31424 " movnti %%edx, 4(%3)\n"
31425- "3: movl 8(%4), %%eax\n"
31426- "31: movl 12(%4),%%edx\n"
31427+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
31428+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
31429 " movnti %%eax, 8(%3)\n"
31430 " movnti %%edx, 12(%3)\n"
31431- "4: movl 16(%4), %%eax\n"
31432- "41: movl 20(%4), %%edx\n"
31433+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
31434+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
31435 " movnti %%eax, 16(%3)\n"
31436 " movnti %%edx, 20(%3)\n"
31437- "10: movl 24(%4), %%eax\n"
31438- "51: movl 28(%4), %%edx\n"
31439+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
31440+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
31441 " movnti %%eax, 24(%3)\n"
31442 " movnti %%edx, 28(%3)\n"
31443- "11: movl 32(%4), %%eax\n"
31444- "61: movl 36(%4), %%edx\n"
31445+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
31446+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
31447 " movnti %%eax, 32(%3)\n"
31448 " movnti %%edx, 36(%3)\n"
31449- "12: movl 40(%4), %%eax\n"
31450- "71: movl 44(%4), %%edx\n"
31451+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
31452+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
31453 " movnti %%eax, 40(%3)\n"
31454 " movnti %%edx, 44(%3)\n"
31455- "13: movl 48(%4), %%eax\n"
31456- "81: movl 52(%4), %%edx\n"
31457+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
31458+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
31459 " movnti %%eax, 48(%3)\n"
31460 " movnti %%edx, 52(%3)\n"
31461- "14: movl 56(%4), %%eax\n"
31462- "91: movl 60(%4), %%edx\n"
31463+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
31464+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
31465 " movnti %%eax, 56(%3)\n"
31466 " movnti %%edx, 60(%3)\n"
31467 " addl $-64, %0\n"
31468@@ -446,9 +554,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
31469 " shrl $2, %0\n"
31470 " andl $3, %%eax\n"
31471 " cld\n"
31472- "6: rep; movsl\n"
31473+ "6: rep; "__copyuser_seg" movsl\n"
31474 " movl %%eax,%0\n"
31475- "7: rep; movsb\n"
31476+ "7: rep; "__copyuser_seg" movsb\n"
31477 "8:\n"
31478 ".section .fixup,\"ax\"\n"
31479 "9: lea 0(%%eax,%0,4),%0\n"
31480@@ -488,32 +596,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
31481 */
31482 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
31483 unsigned long size);
31484-unsigned long __copy_user_intel(void __user *to, const void *from,
31485+unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
31486+ unsigned long size);
31487+unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
31488 unsigned long size);
31489 unsigned long __copy_user_zeroing_intel_nocache(void *to,
31490 const void __user *from, unsigned long size);
31491 #endif /* CONFIG_X86_INTEL_USERCOPY */
31492
31493 /* Generic arbitrary sized copy. */
31494-#define __copy_user(to, from, size) \
31495+#define __copy_user(to, from, size, prefix, set, restore) \
31496 do { \
31497 int __d0, __d1, __d2; \
31498 __asm__ __volatile__( \
31499+ set \
31500 " cmp $7,%0\n" \
31501 " jbe 1f\n" \
31502 " movl %1,%0\n" \
31503 " negl %0\n" \
31504 " andl $7,%0\n" \
31505 " subl %0,%3\n" \
31506- "4: rep; movsb\n" \
31507+ "4: rep; "prefix"movsb\n" \
31508 " movl %3,%0\n" \
31509 " shrl $2,%0\n" \
31510 " andl $3,%3\n" \
31511 " .align 2,0x90\n" \
31512- "0: rep; movsl\n" \
31513+ "0: rep; "prefix"movsl\n" \
31514 " movl %3,%0\n" \
31515- "1: rep; movsb\n" \
31516+ "1: rep; "prefix"movsb\n" \
31517 "2:\n" \
31518+ restore \
31519 ".section .fixup,\"ax\"\n" \
31520 "5: addl %3,%0\n" \
31521 " jmp 2b\n" \
31522@@ -538,14 +650,14 @@ do { \
31523 " negl %0\n" \
31524 " andl $7,%0\n" \
31525 " subl %0,%3\n" \
31526- "4: rep; movsb\n" \
31527+ "4: rep; "__copyuser_seg"movsb\n" \
31528 " movl %3,%0\n" \
31529 " shrl $2,%0\n" \
31530 " andl $3,%3\n" \
31531 " .align 2,0x90\n" \
31532- "0: rep; movsl\n" \
31533+ "0: rep; "__copyuser_seg"movsl\n" \
31534 " movl %3,%0\n" \
31535- "1: rep; movsb\n" \
31536+ "1: rep; "__copyuser_seg"movsb\n" \
31537 "2:\n" \
31538 ".section .fixup,\"ax\"\n" \
31539 "5: addl %3,%0\n" \
31540@@ -572,9 +684,9 @@ unsigned long __copy_to_user_ll(void __user *to, const void *from,
31541 {
31542 stac();
31543 if (movsl_is_ok(to, from, n))
31544- __copy_user(to, from, n);
31545+ __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
31546 else
31547- n = __copy_user_intel(to, from, n);
31548+ n = __generic_copy_to_user_intel(to, from, n);
31549 clac();
31550 return n;
31551 }
31552@@ -598,10 +710,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
31553 {
31554 stac();
31555 if (movsl_is_ok(to, from, n))
31556- __copy_user(to, from, n);
31557+ __copy_user(to, from, n, __copyuser_seg, "", "");
31558 else
31559- n = __copy_user_intel((void __user *)to,
31560- (const void *)from, n);
31561+ n = __generic_copy_from_user_intel(to, from, n);
31562 clac();
31563 return n;
31564 }
31565@@ -632,58 +743,38 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
31566 if (n > 64 && cpu_has_xmm2)
31567 n = __copy_user_intel_nocache(to, from, n);
31568 else
31569- __copy_user(to, from, n);
31570+ __copy_user(to, from, n, __copyuser_seg, "", "");
31571 #else
31572- __copy_user(to, from, n);
31573+ __copy_user(to, from, n, __copyuser_seg, "", "");
31574 #endif
31575 clac();
31576 return n;
31577 }
31578 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
31579
31580-/**
31581- * copy_to_user: - Copy a block of data into user space.
31582- * @to: Destination address, in user space.
31583- * @from: Source address, in kernel space.
31584- * @n: Number of bytes to copy.
31585- *
31586- * Context: User context only. This function may sleep.
31587- *
31588- * Copy data from kernel space to user space.
31589- *
31590- * Returns number of bytes that could not be copied.
31591- * On success, this will be zero.
31592- */
31593-unsigned long _copy_to_user(void __user *to, const void *from, unsigned n)
31594+#ifdef CONFIG_PAX_MEMORY_UDEREF
31595+void __set_fs(mm_segment_t x)
31596 {
31597- if (access_ok(VERIFY_WRITE, to, n))
31598- n = __copy_to_user(to, from, n);
31599- return n;
31600+ switch (x.seg) {
31601+ case 0:
31602+ loadsegment(gs, 0);
31603+ break;
31604+ case TASK_SIZE_MAX:
31605+ loadsegment(gs, __USER_DS);
31606+ break;
31607+ case -1UL:
31608+ loadsegment(gs, __KERNEL_DS);
31609+ break;
31610+ default:
31611+ BUG();
31612+ }
31613 }
31614-EXPORT_SYMBOL(_copy_to_user);
31615+EXPORT_SYMBOL(__set_fs);
31616
31617-/**
31618- * copy_from_user: - Copy a block of data from user space.
31619- * @to: Destination address, in kernel space.
31620- * @from: Source address, in user space.
31621- * @n: Number of bytes to copy.
31622- *
31623- * Context: User context only. This function may sleep.
31624- *
31625- * Copy data from user space to kernel space.
31626- *
31627- * Returns number of bytes that could not be copied.
31628- * On success, this will be zero.
31629- *
31630- * If some data could not be copied, this function will pad the copied
31631- * data to the requested size using zero bytes.
31632- */
31633-unsigned long _copy_from_user(void *to, const void __user *from, unsigned n)
31634+void set_fs(mm_segment_t x)
31635 {
31636- if (access_ok(VERIFY_READ, from, n))
31637- n = __copy_from_user(to, from, n);
31638- else
31639- memset(to, 0, n);
31640- return n;
31641+ current_thread_info()->addr_limit = x;
31642+ __set_fs(x);
31643 }
31644-EXPORT_SYMBOL(_copy_from_user);
31645+EXPORT_SYMBOL(set_fs);
31646+#endif
31647diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
31648index c905e89..01ab928 100644
31649--- a/arch/x86/lib/usercopy_64.c
31650+++ b/arch/x86/lib/usercopy_64.c
31651@@ -18,6 +18,7 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
31652 might_fault();
31653 /* no memory constraint because it doesn't change any memory gcc knows
31654 about */
31655+ pax_open_userland();
31656 stac();
31657 asm volatile(
31658 " testq %[size8],%[size8]\n"
31659@@ -39,9 +40,10 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
31660 _ASM_EXTABLE(0b,3b)
31661 _ASM_EXTABLE(1b,2b)
31662 : [size8] "=&c"(size), [dst] "=&D" (__d0)
31663- : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(addr),
31664+ : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(____m(addr)),
31665 [zero] "r" (0UL), [eight] "r" (8UL));
31666 clac();
31667+ pax_close_userland();
31668 return size;
31669 }
31670 EXPORT_SYMBOL(__clear_user);
31671@@ -54,12 +56,11 @@ unsigned long clear_user(void __user *to, unsigned long n)
31672 }
31673 EXPORT_SYMBOL(clear_user);
31674
31675-unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
31676+unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
31677 {
31678- if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
31679- return copy_user_generic((__force void *)to, (__force void *)from, len);
31680- }
31681- return len;
31682+ if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len))
31683+ return copy_user_generic((void __force_kernel *)____m(to), (void __force_kernel *)____m(from), len);
31684+ return len;
31685 }
31686 EXPORT_SYMBOL(copy_in_user);
31687
31688@@ -69,11 +70,13 @@ EXPORT_SYMBOL(copy_in_user);
31689 * it is not necessary to optimize tail handling.
31690 */
31691 __visible unsigned long
31692-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
31693+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
31694 {
31695 char c;
31696 unsigned zero_len;
31697
31698+ clac();
31699+ pax_close_userland();
31700 for (; len; --len, to++) {
31701 if (__get_user_nocheck(c, from++, sizeof(char)))
31702 break;
31703@@ -84,6 +87,5 @@ copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
31704 for (c = 0, zero_len = len; zerorest && zero_len; --zero_len)
31705 if (__put_user_nocheck(c, to++, sizeof(char)))
31706 break;
31707- clac();
31708 return len;
31709 }
31710diff --git a/arch/x86/mm/Makefile b/arch/x86/mm/Makefile
31711index 6a19ad9..1c48f9a 100644
31712--- a/arch/x86/mm/Makefile
31713+++ b/arch/x86/mm/Makefile
31714@@ -30,3 +30,7 @@ obj-$(CONFIG_ACPI_NUMA) += srat.o
31715 obj-$(CONFIG_NUMA_EMU) += numa_emulation.o
31716
31717 obj-$(CONFIG_MEMTEST) += memtest.o
31718+
31719+quote:="
31720+obj-$(CONFIG_X86_64) += uderef_64.o
31721+CFLAGS_uderef_64.o := $(subst $(quote),,$(CONFIG_ARCH_HWEIGHT_CFLAGS))
31722diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
31723index 903ec1e..c4166b2 100644
31724--- a/arch/x86/mm/extable.c
31725+++ b/arch/x86/mm/extable.c
31726@@ -6,12 +6,24 @@
31727 static inline unsigned long
31728 ex_insn_addr(const struct exception_table_entry *x)
31729 {
31730- return (unsigned long)&x->insn + x->insn;
31731+ unsigned long reloc = 0;
31732+
31733+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
31734+ reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
31735+#endif
31736+
31737+ return (unsigned long)&x->insn + x->insn + reloc;
31738 }
31739 static inline unsigned long
31740 ex_fixup_addr(const struct exception_table_entry *x)
31741 {
31742- return (unsigned long)&x->fixup + x->fixup;
31743+ unsigned long reloc = 0;
31744+
31745+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
31746+ reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
31747+#endif
31748+
31749+ return (unsigned long)&x->fixup + x->fixup + reloc;
31750 }
31751
31752 int fixup_exception(struct pt_regs *regs)
31753@@ -20,7 +32,7 @@ int fixup_exception(struct pt_regs *regs)
31754 unsigned long new_ip;
31755
31756 #ifdef CONFIG_PNPBIOS
31757- if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
31758+ if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
31759 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
31760 extern u32 pnp_bios_is_utter_crap;
31761 pnp_bios_is_utter_crap = 1;
31762@@ -145,6 +157,13 @@ void sort_extable(struct exception_table_entry *start,
31763 i += 4;
31764 p->fixup -= i;
31765 i += 4;
31766+
31767+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
31768+ BUILD_BUG_ON(!IS_ENABLED(CONFIG_BUILDTIME_EXTABLE_SORT));
31769+ p->insn -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
31770+ p->fixup -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
31771+#endif
31772+
31773 }
31774 }
31775
31776diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
31777index d973e61..fb868e9 100644
31778--- a/arch/x86/mm/fault.c
31779+++ b/arch/x86/mm/fault.c
31780@@ -13,12 +13,19 @@
31781 #include <linux/hugetlb.h> /* hstate_index_to_shift */
31782 #include <linux/prefetch.h> /* prefetchw */
31783 #include <linux/context_tracking.h> /* exception_enter(), ... */
31784+#include <linux/unistd.h>
31785+#include <linux/compiler.h>
31786
31787 #include <asm/traps.h> /* dotraplinkage, ... */
31788 #include <asm/pgalloc.h> /* pgd_*(), ... */
31789 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
31790 #include <asm/fixmap.h> /* VSYSCALL_ADDR */
31791 #include <asm/vsyscall.h> /* emulate_vsyscall */
31792+#include <asm/tlbflush.h>
31793+
31794+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
31795+#include <asm/stacktrace.h>
31796+#endif
31797
31798 #define CREATE_TRACE_POINTS
31799 #include <asm/trace/exceptions.h>
31800@@ -59,7 +66,7 @@ static nokprobe_inline int kprobes_fault(struct pt_regs *regs)
31801 int ret = 0;
31802
31803 /* kprobe_running() needs smp_processor_id() */
31804- if (kprobes_built_in() && !user_mode_vm(regs)) {
31805+ if (kprobes_built_in() && !user_mode(regs)) {
31806 preempt_disable();
31807 if (kprobe_running() && kprobe_fault_handler(regs, 14))
31808 ret = 1;
31809@@ -120,7 +127,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
31810 return !instr_lo || (instr_lo>>1) == 1;
31811 case 0x00:
31812 /* Prefetch instruction is 0x0F0D or 0x0F18 */
31813- if (probe_kernel_address(instr, opcode))
31814+ if (user_mode(regs)) {
31815+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
31816+ return 0;
31817+ } else if (probe_kernel_address(instr, opcode))
31818 return 0;
31819
31820 *prefetch = (instr_lo == 0xF) &&
31821@@ -154,7 +164,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
31822 while (instr < max_instr) {
31823 unsigned char opcode;
31824
31825- if (probe_kernel_address(instr, opcode))
31826+ if (user_mode(regs)) {
31827+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
31828+ break;
31829+ } else if (probe_kernel_address(instr, opcode))
31830 break;
31831
31832 instr++;
31833@@ -185,6 +198,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
31834 force_sig_info(si_signo, &info, tsk);
31835 }
31836
31837+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
31838+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
31839+#endif
31840+
31841+#ifdef CONFIG_PAX_EMUTRAMP
31842+static int pax_handle_fetch_fault(struct pt_regs *regs);
31843+#endif
31844+
31845+#ifdef CONFIG_PAX_PAGEEXEC
31846+static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
31847+{
31848+ pgd_t *pgd;
31849+ pud_t *pud;
31850+ pmd_t *pmd;
31851+
31852+ pgd = pgd_offset(mm, address);
31853+ if (!pgd_present(*pgd))
31854+ return NULL;
31855+ pud = pud_offset(pgd, address);
31856+ if (!pud_present(*pud))
31857+ return NULL;
31858+ pmd = pmd_offset(pud, address);
31859+ if (!pmd_present(*pmd))
31860+ return NULL;
31861+ return pmd;
31862+}
31863+#endif
31864+
31865 DEFINE_SPINLOCK(pgd_lock);
31866 LIST_HEAD(pgd_list);
31867
31868@@ -235,10 +276,27 @@ void vmalloc_sync_all(void)
31869 for (address = VMALLOC_START & PMD_MASK;
31870 address >= TASK_SIZE && address < FIXADDR_TOP;
31871 address += PMD_SIZE) {
31872+
31873+#ifdef CONFIG_PAX_PER_CPU_PGD
31874+ unsigned long cpu;
31875+#else
31876 struct page *page;
31877+#endif
31878
31879 spin_lock(&pgd_lock);
31880+
31881+#ifdef CONFIG_PAX_PER_CPU_PGD
31882+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
31883+ pgd_t *pgd = get_cpu_pgd(cpu, user);
31884+ pmd_t *ret;
31885+
31886+ ret = vmalloc_sync_one(pgd, address);
31887+ if (!ret)
31888+ break;
31889+ pgd = get_cpu_pgd(cpu, kernel);
31890+#else
31891 list_for_each_entry(page, &pgd_list, lru) {
31892+ pgd_t *pgd;
31893 spinlock_t *pgt_lock;
31894 pmd_t *ret;
31895
31896@@ -246,8 +304,14 @@ void vmalloc_sync_all(void)
31897 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
31898
31899 spin_lock(pgt_lock);
31900- ret = vmalloc_sync_one(page_address(page), address);
31901+ pgd = page_address(page);
31902+#endif
31903+
31904+ ret = vmalloc_sync_one(pgd, address);
31905+
31906+#ifndef CONFIG_PAX_PER_CPU_PGD
31907 spin_unlock(pgt_lock);
31908+#endif
31909
31910 if (!ret)
31911 break;
31912@@ -281,6 +345,12 @@ static noinline int vmalloc_fault(unsigned long address)
31913 * an interrupt in the middle of a task switch..
31914 */
31915 pgd_paddr = read_cr3();
31916+
31917+#ifdef CONFIG_PAX_PER_CPU_PGD
31918+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id(), kernel)) != (pgd_paddr & __PHYSICAL_MASK));
31919+ vmalloc_sync_one(__va(pgd_paddr + PAGE_SIZE), address);
31920+#endif
31921+
31922 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
31923 if (!pmd_k)
31924 return -1;
31925@@ -377,11 +447,25 @@ static noinline int vmalloc_fault(unsigned long address)
31926 * happen within a race in page table update. In the later
31927 * case just flush:
31928 */
31929- pgd = pgd_offset(current->active_mm, address);
31930+
31931 pgd_ref = pgd_offset_k(address);
31932 if (pgd_none(*pgd_ref))
31933 return -1;
31934
31935+#ifdef CONFIG_PAX_PER_CPU_PGD
31936+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id(), kernel)) != (read_cr3() & __PHYSICAL_MASK));
31937+ pgd = pgd_offset_cpu(smp_processor_id(), user, address);
31938+ if (pgd_none(*pgd)) {
31939+ set_pgd(pgd, *pgd_ref);
31940+ arch_flush_lazy_mmu_mode();
31941+ } else {
31942+ BUG_ON(pgd_page_vaddr(*pgd) != pgd_page_vaddr(*pgd_ref));
31943+ }
31944+ pgd = pgd_offset_cpu(smp_processor_id(), kernel, address);
31945+#else
31946+ pgd = pgd_offset(current->active_mm, address);
31947+#endif
31948+
31949 if (pgd_none(*pgd)) {
31950 set_pgd(pgd, *pgd_ref);
31951 arch_flush_lazy_mmu_mode();
31952@@ -548,7 +632,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
31953 static int is_errata100(struct pt_regs *regs, unsigned long address)
31954 {
31955 #ifdef CONFIG_X86_64
31956- if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
31957+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
31958 return 1;
31959 #endif
31960 return 0;
31961@@ -575,9 +659,9 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
31962 }
31963
31964 static const char nx_warning[] = KERN_CRIT
31965-"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
31966+"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
31967 static const char smep_warning[] = KERN_CRIT
31968-"unable to execute userspace code (SMEP?) (uid: %d)\n";
31969+"unable to execute userspace code (SMEP?) (uid: %d, task: %s, pid: %d)\n";
31970
31971 static void
31972 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
31973@@ -586,7 +670,7 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
31974 if (!oops_may_print())
31975 return;
31976
31977- if (error_code & PF_INSTR) {
31978+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
31979 unsigned int level;
31980 pgd_t *pgd;
31981 pte_t *pte;
31982@@ -597,13 +681,25 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
31983 pte = lookup_address_in_pgd(pgd, address, &level);
31984
31985 if (pte && pte_present(*pte) && !pte_exec(*pte))
31986- printk(nx_warning, from_kuid(&init_user_ns, current_uid()));
31987+ printk(nx_warning, from_kuid_munged(&init_user_ns, current_uid()), current->comm, task_pid_nr(current));
31988 if (pte && pte_present(*pte) && pte_exec(*pte) &&
31989 (pgd_flags(*pgd) & _PAGE_USER) &&
31990 (read_cr4() & X86_CR4_SMEP))
31991- printk(smep_warning, from_kuid(&init_user_ns, current_uid()));
31992+ printk(smep_warning, from_kuid(&init_user_ns, current_uid()), current->comm, task_pid_nr(current));
31993 }
31994
31995+#ifdef CONFIG_PAX_KERNEXEC
31996+ if (init_mm.start_code <= address && address < init_mm.end_code) {
31997+ if (current->signal->curr_ip)
31998+ printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
31999+ &current->signal->curr_ip, current->comm, task_pid_nr(current),
32000+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
32001+ else
32002+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
32003+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
32004+ }
32005+#endif
32006+
32007 printk(KERN_ALERT "BUG: unable to handle kernel ");
32008 if (address < PAGE_SIZE)
32009 printk(KERN_CONT "NULL pointer dereference");
32010@@ -782,6 +878,22 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
32011 return;
32012 }
32013 #endif
32014+
32015+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
32016+ if (pax_is_fetch_fault(regs, error_code, address)) {
32017+
32018+#ifdef CONFIG_PAX_EMUTRAMP
32019+ switch (pax_handle_fetch_fault(regs)) {
32020+ case 2:
32021+ return;
32022+ }
32023+#endif
32024+
32025+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
32026+ do_group_exit(SIGKILL);
32027+ }
32028+#endif
32029+
32030 /* Kernel addresses are always protection faults: */
32031 if (address >= TASK_SIZE)
32032 error_code |= PF_PROT;
32033@@ -867,7 +979,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
32034 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
32035 printk(KERN_ERR
32036 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
32037- tsk->comm, tsk->pid, address);
32038+ tsk->comm, task_pid_nr(tsk), address);
32039 code = BUS_MCEERR_AR;
32040 }
32041 #endif
32042@@ -921,6 +1033,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
32043 return 1;
32044 }
32045
32046+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
32047+static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
32048+{
32049+ pte_t *pte;
32050+ pmd_t *pmd;
32051+ spinlock_t *ptl;
32052+ unsigned char pte_mask;
32053+
32054+ if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
32055+ !(mm->pax_flags & MF_PAX_PAGEEXEC))
32056+ return 0;
32057+
32058+ /* PaX: it's our fault, let's handle it if we can */
32059+
32060+ /* PaX: take a look at read faults before acquiring any locks */
32061+ if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
32062+ /* instruction fetch attempt from a protected page in user mode */
32063+ up_read(&mm->mmap_sem);
32064+
32065+#ifdef CONFIG_PAX_EMUTRAMP
32066+ switch (pax_handle_fetch_fault(regs)) {
32067+ case 2:
32068+ return 1;
32069+ }
32070+#endif
32071+
32072+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
32073+ do_group_exit(SIGKILL);
32074+ }
32075+
32076+ pmd = pax_get_pmd(mm, address);
32077+ if (unlikely(!pmd))
32078+ return 0;
32079+
32080+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
32081+ if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
32082+ pte_unmap_unlock(pte, ptl);
32083+ return 0;
32084+ }
32085+
32086+ if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
32087+ /* write attempt to a protected page in user mode */
32088+ pte_unmap_unlock(pte, ptl);
32089+ return 0;
32090+ }
32091+
32092+#ifdef CONFIG_SMP
32093+ if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
32094+#else
32095+ if (likely(address > get_limit(regs->cs)))
32096+#endif
32097+ {
32098+ set_pte(pte, pte_mkread(*pte));
32099+ __flush_tlb_one(address);
32100+ pte_unmap_unlock(pte, ptl);
32101+ up_read(&mm->mmap_sem);
32102+ return 1;
32103+ }
32104+
32105+ pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
32106+
32107+ /*
32108+ * PaX: fill DTLB with user rights and retry
32109+ */
32110+ __asm__ __volatile__ (
32111+ "orb %2,(%1)\n"
32112+#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
32113+/*
32114+ * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
32115+ * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
32116+ * page fault when examined during a TLB load attempt. this is true not only
32117+ * for PTEs holding a non-present entry but also present entries that will
32118+ * raise a page fault (such as those set up by PaX, or the copy-on-write
32119+ * mechanism). in effect it means that we do *not* need to flush the TLBs
32120+ * for our target pages since their PTEs are simply not in the TLBs at all.
32121+
32122+ * the best thing in omitting it is that we gain around 15-20% speed in the
32123+ * fast path of the page fault handler and can get rid of tracing since we
32124+ * can no longer flush unintended entries.
32125+ */
32126+ "invlpg (%0)\n"
32127+#endif
32128+ __copyuser_seg"testb $0,(%0)\n"
32129+ "xorb %3,(%1)\n"
32130+ :
32131+ : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
32132+ : "memory", "cc");
32133+ pte_unmap_unlock(pte, ptl);
32134+ up_read(&mm->mmap_sem);
32135+ return 1;
32136+}
32137+#endif
32138+
32139 /*
32140 * Handle a spurious fault caused by a stale TLB entry.
32141 *
32142@@ -1006,6 +1211,9 @@ int show_unhandled_signals = 1;
32143 static inline int
32144 access_error(unsigned long error_code, struct vm_area_struct *vma)
32145 {
32146+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
32147+ return 1;
32148+
32149 if (error_code & PF_WRITE) {
32150 /* write, present and write, not present: */
32151 if (unlikely(!(vma->vm_flags & VM_WRITE)))
32152@@ -1040,7 +1248,7 @@ static inline bool smap_violation(int error_code, struct pt_regs *regs)
32153 if (error_code & PF_USER)
32154 return false;
32155
32156- if (!user_mode_vm(regs) && (regs->flags & X86_EFLAGS_AC))
32157+ if (!user_mode(regs) && (regs->flags & X86_EFLAGS_AC))
32158 return false;
32159
32160 return true;
32161@@ -1068,6 +1276,22 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code,
32162 tsk = current;
32163 mm = tsk->mm;
32164
32165+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
32166+ if (!user_mode(regs) && address < 2 * pax_user_shadow_base) {
32167+ if (!search_exception_tables(regs->ip)) {
32168+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
32169+ bad_area_nosemaphore(regs, error_code, address);
32170+ return;
32171+ }
32172+ if (address < pax_user_shadow_base) {
32173+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
32174+ printk(KERN_ERR "PAX: faulting IP: %pS\n", (void *)regs->ip);
32175+ show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
32176+ } else
32177+ address -= pax_user_shadow_base;
32178+ }
32179+#endif
32180+
32181 /*
32182 * Detect and handle instructions that would cause a page fault for
32183 * both a tracked kernel page and a userspace page.
32184@@ -1145,7 +1369,7 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code,
32185 * User-mode registers count as a user access even for any
32186 * potential system fault or CPU buglet:
32187 */
32188- if (user_mode_vm(regs)) {
32189+ if (user_mode(regs)) {
32190 local_irq_enable();
32191 error_code |= PF_USER;
32192 flags |= FAULT_FLAG_USER;
32193@@ -1192,6 +1416,11 @@ retry:
32194 might_sleep();
32195 }
32196
32197+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
32198+ if (pax_handle_pageexec_fault(regs, mm, address, error_code))
32199+ return;
32200+#endif
32201+
32202 vma = find_vma(mm, address);
32203 if (unlikely(!vma)) {
32204 bad_area(regs, error_code, address);
32205@@ -1203,18 +1432,24 @@ retry:
32206 bad_area(regs, error_code, address);
32207 return;
32208 }
32209- if (error_code & PF_USER) {
32210- /*
32211- * Accessing the stack below %sp is always a bug.
32212- * The large cushion allows instructions like enter
32213- * and pusha to work. ("enter $65535, $31" pushes
32214- * 32 pointers and then decrements %sp by 65535.)
32215- */
32216- if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
32217- bad_area(regs, error_code, address);
32218- return;
32219- }
32220+ /*
32221+ * Accessing the stack below %sp is always a bug.
32222+ * The large cushion allows instructions like enter
32223+ * and pusha to work. ("enter $65535, $31" pushes
32224+ * 32 pointers and then decrements %sp by 65535.)
32225+ */
32226+ if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
32227+ bad_area(regs, error_code, address);
32228+ return;
32229 }
32230+
32231+#ifdef CONFIG_PAX_SEGMEXEC
32232+ if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
32233+ bad_area(regs, error_code, address);
32234+ return;
32235+ }
32236+#endif
32237+
32238 if (unlikely(expand_stack(vma, address))) {
32239 bad_area(regs, error_code, address);
32240 return;
32241@@ -1331,3 +1566,292 @@ trace_do_page_fault(struct pt_regs *regs, unsigned long error_code)
32242 }
32243 NOKPROBE_SYMBOL(trace_do_page_fault);
32244 #endif /* CONFIG_TRACING */
32245+
32246+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
32247+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
32248+{
32249+ struct mm_struct *mm = current->mm;
32250+ unsigned long ip = regs->ip;
32251+
32252+ if (v8086_mode(regs))
32253+ ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
32254+
32255+#ifdef CONFIG_PAX_PAGEEXEC
32256+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
32257+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
32258+ return true;
32259+ if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
32260+ return true;
32261+ return false;
32262+ }
32263+#endif
32264+
32265+#ifdef CONFIG_PAX_SEGMEXEC
32266+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
32267+ if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
32268+ return true;
32269+ return false;
32270+ }
32271+#endif
32272+
32273+ return false;
32274+}
32275+#endif
32276+
32277+#ifdef CONFIG_PAX_EMUTRAMP
32278+static int pax_handle_fetch_fault_32(struct pt_regs *regs)
32279+{
32280+ int err;
32281+
32282+ do { /* PaX: libffi trampoline emulation */
32283+ unsigned char mov, jmp;
32284+ unsigned int addr1, addr2;
32285+
32286+#ifdef CONFIG_X86_64
32287+ if ((regs->ip + 9) >> 32)
32288+ break;
32289+#endif
32290+
32291+ err = get_user(mov, (unsigned char __user *)regs->ip);
32292+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
32293+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
32294+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
32295+
32296+ if (err)
32297+ break;
32298+
32299+ if (mov == 0xB8 && jmp == 0xE9) {
32300+ regs->ax = addr1;
32301+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
32302+ return 2;
32303+ }
32304+ } while (0);
32305+
32306+ do { /* PaX: gcc trampoline emulation #1 */
32307+ unsigned char mov1, mov2;
32308+ unsigned short jmp;
32309+ unsigned int addr1, addr2;
32310+
32311+#ifdef CONFIG_X86_64
32312+ if ((regs->ip + 11) >> 32)
32313+ break;
32314+#endif
32315+
32316+ err = get_user(mov1, (unsigned char __user *)regs->ip);
32317+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
32318+ err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
32319+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
32320+ err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
32321+
32322+ if (err)
32323+ break;
32324+
32325+ if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
32326+ regs->cx = addr1;
32327+ regs->ax = addr2;
32328+ regs->ip = addr2;
32329+ return 2;
32330+ }
32331+ } while (0);
32332+
32333+ do { /* PaX: gcc trampoline emulation #2 */
32334+ unsigned char mov, jmp;
32335+ unsigned int addr1, addr2;
32336+
32337+#ifdef CONFIG_X86_64
32338+ if ((regs->ip + 9) >> 32)
32339+ break;
32340+#endif
32341+
32342+ err = get_user(mov, (unsigned char __user *)regs->ip);
32343+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
32344+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
32345+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
32346+
32347+ if (err)
32348+ break;
32349+
32350+ if (mov == 0xB9 && jmp == 0xE9) {
32351+ regs->cx = addr1;
32352+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
32353+ return 2;
32354+ }
32355+ } while (0);
32356+
32357+ return 1; /* PaX in action */
32358+}
32359+
32360+#ifdef CONFIG_X86_64
32361+static int pax_handle_fetch_fault_64(struct pt_regs *regs)
32362+{
32363+ int err;
32364+
32365+ do { /* PaX: libffi trampoline emulation */
32366+ unsigned short mov1, mov2, jmp1;
32367+ unsigned char stcclc, jmp2;
32368+ unsigned long addr1, addr2;
32369+
32370+ err = get_user(mov1, (unsigned short __user *)regs->ip);
32371+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
32372+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
32373+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
32374+ err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
32375+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
32376+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
32377+
32378+ if (err)
32379+ break;
32380+
32381+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
32382+ regs->r11 = addr1;
32383+ regs->r10 = addr2;
32384+ if (stcclc == 0xF8)
32385+ regs->flags &= ~X86_EFLAGS_CF;
32386+ else
32387+ regs->flags |= X86_EFLAGS_CF;
32388+ regs->ip = addr1;
32389+ return 2;
32390+ }
32391+ } while (0);
32392+
32393+ do { /* PaX: gcc trampoline emulation #1 */
32394+ unsigned short mov1, mov2, jmp1;
32395+ unsigned char jmp2;
32396+ unsigned int addr1;
32397+ unsigned long addr2;
32398+
32399+ err = get_user(mov1, (unsigned short __user *)regs->ip);
32400+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
32401+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
32402+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
32403+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
32404+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
32405+
32406+ if (err)
32407+ break;
32408+
32409+ if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
32410+ regs->r11 = addr1;
32411+ regs->r10 = addr2;
32412+ regs->ip = addr1;
32413+ return 2;
32414+ }
32415+ } while (0);
32416+
32417+ do { /* PaX: gcc trampoline emulation #2 */
32418+ unsigned short mov1, mov2, jmp1;
32419+ unsigned char jmp2;
32420+ unsigned long addr1, addr2;
32421+
32422+ err = get_user(mov1, (unsigned short __user *)regs->ip);
32423+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
32424+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
32425+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
32426+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
32427+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
32428+
32429+ if (err)
32430+ break;
32431+
32432+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
32433+ regs->r11 = addr1;
32434+ regs->r10 = addr2;
32435+ regs->ip = addr1;
32436+ return 2;
32437+ }
32438+ } while (0);
32439+
32440+ return 1; /* PaX in action */
32441+}
32442+#endif
32443+
32444+/*
32445+ * PaX: decide what to do with offenders (regs->ip = fault address)
32446+ *
32447+ * returns 1 when task should be killed
32448+ * 2 when gcc trampoline was detected
32449+ */
32450+static int pax_handle_fetch_fault(struct pt_regs *regs)
32451+{
32452+ if (v8086_mode(regs))
32453+ return 1;
32454+
32455+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
32456+ return 1;
32457+
32458+#ifdef CONFIG_X86_32
32459+ return pax_handle_fetch_fault_32(regs);
32460+#else
32461+ if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
32462+ return pax_handle_fetch_fault_32(regs);
32463+ else
32464+ return pax_handle_fetch_fault_64(regs);
32465+#endif
32466+}
32467+#endif
32468+
32469+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
32470+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
32471+{
32472+ long i;
32473+
32474+ printk(KERN_ERR "PAX: bytes at PC: ");
32475+ for (i = 0; i < 20; i++) {
32476+ unsigned char c;
32477+ if (get_user(c, (unsigned char __force_user *)pc+i))
32478+ printk(KERN_CONT "?? ");
32479+ else
32480+ printk(KERN_CONT "%02x ", c);
32481+ }
32482+ printk("\n");
32483+
32484+ printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
32485+ for (i = -1; i < 80 / (long)sizeof(long); i++) {
32486+ unsigned long c;
32487+ if (get_user(c, (unsigned long __force_user *)sp+i)) {
32488+#ifdef CONFIG_X86_32
32489+ printk(KERN_CONT "???????? ");
32490+#else
32491+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
32492+ printk(KERN_CONT "???????? ???????? ");
32493+ else
32494+ printk(KERN_CONT "???????????????? ");
32495+#endif
32496+ } else {
32497+#ifdef CONFIG_X86_64
32498+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
32499+ printk(KERN_CONT "%08x ", (unsigned int)c);
32500+ printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
32501+ } else
32502+#endif
32503+ printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
32504+ }
32505+ }
32506+ printk("\n");
32507+}
32508+#endif
32509+
32510+/**
32511+ * probe_kernel_write(): safely attempt to write to a location
32512+ * @dst: address to write to
32513+ * @src: pointer to the data that shall be written
32514+ * @size: size of the data chunk
32515+ *
32516+ * Safely write to address @dst from the buffer at @src. If a kernel fault
32517+ * happens, handle that and return -EFAULT.
32518+ */
32519+long notrace probe_kernel_write(void *dst, const void *src, size_t size)
32520+{
32521+ long ret;
32522+ mm_segment_t old_fs = get_fs();
32523+
32524+ set_fs(KERNEL_DS);
32525+ pagefault_disable();
32526+ pax_open_kernel();
32527+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
32528+ pax_close_kernel();
32529+ pagefault_enable();
32530+ set_fs(old_fs);
32531+
32532+ return ret ? -EFAULT : 0;
32533+}
32534diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
32535index 207d9aef..69030980 100644
32536--- a/arch/x86/mm/gup.c
32537+++ b/arch/x86/mm/gup.c
32538@@ -268,7 +268,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
32539 addr = start;
32540 len = (unsigned long) nr_pages << PAGE_SHIFT;
32541 end = start + len;
32542- if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
32543+ if (unlikely(!access_ok_noprefault(write ? VERIFY_WRITE : VERIFY_READ,
32544 (void __user *)start, len)))
32545 return 0;
32546
32547@@ -344,6 +344,10 @@ int get_user_pages_fast(unsigned long start, int nr_pages, int write,
32548 goto slow_irqon;
32549 #endif
32550
32551+ if (unlikely(!access_ok_noprefault(write ? VERIFY_WRITE : VERIFY_READ,
32552+ (void __user *)start, len)))
32553+ return 0;
32554+
32555 /*
32556 * XXX: batch / limit 'nr', to avoid large irq off latency
32557 * needs some instrumenting to determine the common sizes used by
32558diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
32559index 4500142..53a363c 100644
32560--- a/arch/x86/mm/highmem_32.c
32561+++ b/arch/x86/mm/highmem_32.c
32562@@ -45,7 +45,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot)
32563 idx = type + KM_TYPE_NR*smp_processor_id();
32564 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
32565 BUG_ON(!pte_none(*(kmap_pte-idx)));
32566+
32567+ pax_open_kernel();
32568 set_pte(kmap_pte-idx, mk_pte(page, prot));
32569+ pax_close_kernel();
32570+
32571 arch_flush_lazy_mmu_mode();
32572
32573 return (void *)vaddr;
32574diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
32575index 8b977eb..4732c33 100644
32576--- a/arch/x86/mm/hugetlbpage.c
32577+++ b/arch/x86/mm/hugetlbpage.c
32578@@ -80,23 +80,24 @@ int pud_huge(pud_t pud)
32579 #ifdef CONFIG_HUGETLB_PAGE
32580 static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
32581 unsigned long addr, unsigned long len,
32582- unsigned long pgoff, unsigned long flags)
32583+ unsigned long pgoff, unsigned long flags, unsigned long offset)
32584 {
32585 struct hstate *h = hstate_file(file);
32586 struct vm_unmapped_area_info info;
32587-
32588+
32589 info.flags = 0;
32590 info.length = len;
32591 info.low_limit = current->mm->mmap_legacy_base;
32592 info.high_limit = TASK_SIZE;
32593 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
32594 info.align_offset = 0;
32595+ info.threadstack_offset = offset;
32596 return vm_unmapped_area(&info);
32597 }
32598
32599 static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
32600 unsigned long addr0, unsigned long len,
32601- unsigned long pgoff, unsigned long flags)
32602+ unsigned long pgoff, unsigned long flags, unsigned long offset)
32603 {
32604 struct hstate *h = hstate_file(file);
32605 struct vm_unmapped_area_info info;
32606@@ -108,6 +109,7 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
32607 info.high_limit = current->mm->mmap_base;
32608 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
32609 info.align_offset = 0;
32610+ info.threadstack_offset = offset;
32611 addr = vm_unmapped_area(&info);
32612
32613 /*
32614@@ -120,6 +122,12 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
32615 VM_BUG_ON(addr != -ENOMEM);
32616 info.flags = 0;
32617 info.low_limit = TASK_UNMAPPED_BASE;
32618+
32619+#ifdef CONFIG_PAX_RANDMMAP
32620+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
32621+ info.low_limit += current->mm->delta_mmap;
32622+#endif
32623+
32624 info.high_limit = TASK_SIZE;
32625 addr = vm_unmapped_area(&info);
32626 }
32627@@ -134,10 +142,20 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
32628 struct hstate *h = hstate_file(file);
32629 struct mm_struct *mm = current->mm;
32630 struct vm_area_struct *vma;
32631+ unsigned long pax_task_size = TASK_SIZE;
32632+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
32633
32634 if (len & ~huge_page_mask(h))
32635 return -EINVAL;
32636- if (len > TASK_SIZE)
32637+
32638+#ifdef CONFIG_PAX_SEGMEXEC
32639+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
32640+ pax_task_size = SEGMEXEC_TASK_SIZE;
32641+#endif
32642+
32643+ pax_task_size -= PAGE_SIZE;
32644+
32645+ if (len > pax_task_size)
32646 return -ENOMEM;
32647
32648 if (flags & MAP_FIXED) {
32649@@ -146,19 +164,22 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
32650 return addr;
32651 }
32652
32653+#ifdef CONFIG_PAX_RANDMMAP
32654+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
32655+#endif
32656+
32657 if (addr) {
32658 addr = ALIGN(addr, huge_page_size(h));
32659 vma = find_vma(mm, addr);
32660- if (TASK_SIZE - len >= addr &&
32661- (!vma || addr + len <= vma->vm_start))
32662+ if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
32663 return addr;
32664 }
32665 if (mm->get_unmapped_area == arch_get_unmapped_area)
32666 return hugetlb_get_unmapped_area_bottomup(file, addr, len,
32667- pgoff, flags);
32668+ pgoff, flags, offset);
32669 else
32670 return hugetlb_get_unmapped_area_topdown(file, addr, len,
32671- pgoff, flags);
32672+ pgoff, flags, offset);
32673 }
32674 #endif /* CONFIG_HUGETLB_PAGE */
32675
32676diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
32677index 66dba36..f8082ec 100644
32678--- a/arch/x86/mm/init.c
32679+++ b/arch/x86/mm/init.c
32680@@ -4,6 +4,7 @@
32681 #include <linux/swap.h>
32682 #include <linux/memblock.h>
32683 #include <linux/bootmem.h> /* for max_low_pfn */
32684+#include <linux/tboot.h>
32685
32686 #include <asm/cacheflush.h>
32687 #include <asm/e820.h>
32688@@ -17,6 +18,8 @@
32689 #include <asm/proto.h>
32690 #include <asm/dma.h> /* for MAX_DMA_PFN */
32691 #include <asm/microcode.h>
32692+#include <asm/desc.h>
32693+#include <asm/bios_ebda.h>
32694
32695 /*
32696 * We need to define the tracepoints somewhere, and tlb.c
32697@@ -570,7 +573,18 @@ void __init init_mem_mapping(void)
32698 early_ioremap_page_table_range_init();
32699 #endif
32700
32701+#ifdef CONFIG_PAX_PER_CPU_PGD
32702+ clone_pgd_range(get_cpu_pgd(0, kernel) + KERNEL_PGD_BOUNDARY,
32703+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
32704+ KERNEL_PGD_PTRS);
32705+ clone_pgd_range(get_cpu_pgd(0, user) + KERNEL_PGD_BOUNDARY,
32706+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
32707+ KERNEL_PGD_PTRS);
32708+ load_cr3(get_cpu_pgd(0, kernel));
32709+#else
32710 load_cr3(swapper_pg_dir);
32711+#endif
32712+
32713 __flush_tlb_all();
32714
32715 early_memtest(0, max_pfn_mapped << PAGE_SHIFT);
32716@@ -586,10 +600,40 @@ void __init init_mem_mapping(void)
32717 * Access has to be given to non-kernel-ram areas as well, these contain the PCI
32718 * mmio resources as well as potential bios/acpi data regions.
32719 */
32720+
32721+#ifdef CONFIG_GRKERNSEC_KMEM
32722+static unsigned int ebda_start __read_only;
32723+static unsigned int ebda_end __read_only;
32724+#endif
32725+
32726 int devmem_is_allowed(unsigned long pagenr)
32727 {
32728- if (pagenr < 256)
32729+#ifdef CONFIG_GRKERNSEC_KMEM
32730+ /* allow BDA */
32731+ if (!pagenr)
32732 return 1;
32733+ /* allow EBDA */
32734+ if (pagenr >= ebda_start && pagenr < ebda_end)
32735+ return 1;
32736+ /* if tboot is in use, allow access to its hardcoded serial log range */
32737+ if (tboot_enabled() && ((0x60000 >> PAGE_SHIFT) <= pagenr) && (pagenr < (0x68000 >> PAGE_SHIFT)))
32738+ return 1;
32739+#else
32740+ if (!pagenr)
32741+ return 1;
32742+#ifdef CONFIG_VM86
32743+ if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
32744+ return 1;
32745+#endif
32746+#endif
32747+
32748+ if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
32749+ return 1;
32750+#ifdef CONFIG_GRKERNSEC_KMEM
32751+ /* throw out everything else below 1MB */
32752+ if (pagenr <= 256)
32753+ return 0;
32754+#endif
32755 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
32756 return 0;
32757 if (!page_is_ram(pagenr))
32758@@ -635,8 +679,117 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
32759 #endif
32760 }
32761
32762+#ifdef CONFIG_GRKERNSEC_KMEM
32763+static inline void gr_init_ebda(void)
32764+{
32765+ unsigned int ebda_addr;
32766+ unsigned int ebda_size = 0;
32767+
32768+ ebda_addr = get_bios_ebda();
32769+ if (ebda_addr) {
32770+ ebda_size = *(unsigned char *)phys_to_virt(ebda_addr);
32771+ ebda_size <<= 10;
32772+ }
32773+ if (ebda_addr && ebda_size) {
32774+ ebda_start = ebda_addr >> PAGE_SHIFT;
32775+ ebda_end = min((unsigned int)PAGE_ALIGN(ebda_addr + ebda_size), (unsigned int)0xa0000) >> PAGE_SHIFT;
32776+ } else {
32777+ ebda_start = 0x9f000 >> PAGE_SHIFT;
32778+ ebda_end = 0xa0000 >> PAGE_SHIFT;
32779+ }
32780+}
32781+#else
32782+static inline void gr_init_ebda(void) { }
32783+#endif
32784+
32785 void free_initmem(void)
32786 {
32787+#ifdef CONFIG_PAX_KERNEXEC
32788+#ifdef CONFIG_X86_32
32789+ /* PaX: limit KERNEL_CS to actual size */
32790+ unsigned long addr, limit;
32791+ struct desc_struct d;
32792+ int cpu;
32793+#else
32794+ pgd_t *pgd;
32795+ pud_t *pud;
32796+ pmd_t *pmd;
32797+ unsigned long addr, end;
32798+#endif
32799+#endif
32800+
32801+ gr_init_ebda();
32802+
32803+#ifdef CONFIG_PAX_KERNEXEC
32804+#ifdef CONFIG_X86_32
32805+ limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
32806+ limit = (limit - 1UL) >> PAGE_SHIFT;
32807+
32808+ memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
32809+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
32810+ pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
32811+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
32812+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEXEC_KERNEL_CS, &d, DESCTYPE_S);
32813+ }
32814+
32815+ /* PaX: make KERNEL_CS read-only */
32816+ addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
32817+ if (!paravirt_enabled())
32818+ set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
32819+/*
32820+ for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
32821+ pgd = pgd_offset_k(addr);
32822+ pud = pud_offset(pgd, addr);
32823+ pmd = pmd_offset(pud, addr);
32824+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
32825+ }
32826+*/
32827+#ifdef CONFIG_X86_PAE
32828+ set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
32829+/*
32830+ for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
32831+ pgd = pgd_offset_k(addr);
32832+ pud = pud_offset(pgd, addr);
32833+ pmd = pmd_offset(pud, addr);
32834+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
32835+ }
32836+*/
32837+#endif
32838+
32839+#ifdef CONFIG_MODULES
32840+ set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
32841+#endif
32842+
32843+#else
32844+ /* PaX: make kernel code/rodata read-only, rest non-executable */
32845+ for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
32846+ pgd = pgd_offset_k(addr);
32847+ pud = pud_offset(pgd, addr);
32848+ pmd = pmd_offset(pud, addr);
32849+ if (!pmd_present(*pmd))
32850+ continue;
32851+ if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
32852+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
32853+ else
32854+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
32855+ }
32856+
32857+ addr = (unsigned long)__va(__pa(__START_KERNEL_map));
32858+ end = addr + KERNEL_IMAGE_SIZE;
32859+ for (; addr < end; addr += PMD_SIZE) {
32860+ pgd = pgd_offset_k(addr);
32861+ pud = pud_offset(pgd, addr);
32862+ pmd = pmd_offset(pud, addr);
32863+ if (!pmd_present(*pmd))
32864+ continue;
32865+ if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
32866+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
32867+ }
32868+#endif
32869+
32870+ flush_tlb_all();
32871+#endif
32872+
32873 free_init_pages("unused kernel",
32874 (unsigned long)(&__init_begin),
32875 (unsigned long)(&__init_end));
32876diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
32877index c8140e1..59257fc 100644
32878--- a/arch/x86/mm/init_32.c
32879+++ b/arch/x86/mm/init_32.c
32880@@ -62,33 +62,6 @@ static noinline int do_test_wp_bit(void);
32881 bool __read_mostly __vmalloc_start_set = false;
32882
32883 /*
32884- * Creates a middle page table and puts a pointer to it in the
32885- * given global directory entry. This only returns the gd entry
32886- * in non-PAE compilation mode, since the middle layer is folded.
32887- */
32888-static pmd_t * __init one_md_table_init(pgd_t *pgd)
32889-{
32890- pud_t *pud;
32891- pmd_t *pmd_table;
32892-
32893-#ifdef CONFIG_X86_PAE
32894- if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
32895- pmd_table = (pmd_t *)alloc_low_page();
32896- paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
32897- set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
32898- pud = pud_offset(pgd, 0);
32899- BUG_ON(pmd_table != pmd_offset(pud, 0));
32900-
32901- return pmd_table;
32902- }
32903-#endif
32904- pud = pud_offset(pgd, 0);
32905- pmd_table = pmd_offset(pud, 0);
32906-
32907- return pmd_table;
32908-}
32909-
32910-/*
32911 * Create a page table and place a pointer to it in a middle page
32912 * directory entry:
32913 */
32914@@ -98,13 +71,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
32915 pte_t *page_table = (pte_t *)alloc_low_page();
32916
32917 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
32918+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
32919+ set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
32920+#else
32921 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
32922+#endif
32923 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
32924 }
32925
32926 return pte_offset_kernel(pmd, 0);
32927 }
32928
32929+static pmd_t * __init one_md_table_init(pgd_t *pgd)
32930+{
32931+ pud_t *pud;
32932+ pmd_t *pmd_table;
32933+
32934+ pud = pud_offset(pgd, 0);
32935+ pmd_table = pmd_offset(pud, 0);
32936+
32937+ return pmd_table;
32938+}
32939+
32940 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
32941 {
32942 int pgd_idx = pgd_index(vaddr);
32943@@ -208,6 +196,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
32944 int pgd_idx, pmd_idx;
32945 unsigned long vaddr;
32946 pgd_t *pgd;
32947+ pud_t *pud;
32948 pmd_t *pmd;
32949 pte_t *pte = NULL;
32950 unsigned long count = page_table_range_init_count(start, end);
32951@@ -222,8 +211,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
32952 pgd = pgd_base + pgd_idx;
32953
32954 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
32955- pmd = one_md_table_init(pgd);
32956- pmd = pmd + pmd_index(vaddr);
32957+ pud = pud_offset(pgd, vaddr);
32958+ pmd = pmd_offset(pud, vaddr);
32959+
32960+#ifdef CONFIG_X86_PAE
32961+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
32962+#endif
32963+
32964 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
32965 pmd++, pmd_idx++) {
32966 pte = page_table_kmap_check(one_page_table_init(pmd),
32967@@ -235,11 +229,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
32968 }
32969 }
32970
32971-static inline int is_kernel_text(unsigned long addr)
32972+static inline int is_kernel_text(unsigned long start, unsigned long end)
32973 {
32974- if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
32975- return 1;
32976- return 0;
32977+ if ((start >= ktla_ktva((unsigned long)_etext) ||
32978+ end <= ktla_ktva((unsigned long)_stext)) &&
32979+ (start >= ktla_ktva((unsigned long)_einittext) ||
32980+ end <= ktla_ktva((unsigned long)_sinittext)) &&
32981+
32982+#ifdef CONFIG_ACPI_SLEEP
32983+ (start >= (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
32984+#endif
32985+
32986+ (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
32987+ return 0;
32988+ return 1;
32989 }
32990
32991 /*
32992@@ -256,9 +259,10 @@ kernel_physical_mapping_init(unsigned long start,
32993 unsigned long last_map_addr = end;
32994 unsigned long start_pfn, end_pfn;
32995 pgd_t *pgd_base = swapper_pg_dir;
32996- int pgd_idx, pmd_idx, pte_ofs;
32997+ unsigned int pgd_idx, pmd_idx, pte_ofs;
32998 unsigned long pfn;
32999 pgd_t *pgd;
33000+ pud_t *pud;
33001 pmd_t *pmd;
33002 pte_t *pte;
33003 unsigned pages_2m, pages_4k;
33004@@ -291,8 +295,13 @@ repeat:
33005 pfn = start_pfn;
33006 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
33007 pgd = pgd_base + pgd_idx;
33008- for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
33009- pmd = one_md_table_init(pgd);
33010+ for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
33011+ pud = pud_offset(pgd, 0);
33012+ pmd = pmd_offset(pud, 0);
33013+
33014+#ifdef CONFIG_X86_PAE
33015+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
33016+#endif
33017
33018 if (pfn >= end_pfn)
33019 continue;
33020@@ -304,14 +313,13 @@ repeat:
33021 #endif
33022 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
33023 pmd++, pmd_idx++) {
33024- unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
33025+ unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
33026
33027 /*
33028 * Map with big pages if possible, otherwise
33029 * create normal page tables:
33030 */
33031 if (use_pse) {
33032- unsigned int addr2;
33033 pgprot_t prot = PAGE_KERNEL_LARGE;
33034 /*
33035 * first pass will use the same initial
33036@@ -322,11 +330,7 @@ repeat:
33037 _PAGE_PSE);
33038
33039 pfn &= PMD_MASK >> PAGE_SHIFT;
33040- addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
33041- PAGE_OFFSET + PAGE_SIZE-1;
33042-
33043- if (is_kernel_text(addr) ||
33044- is_kernel_text(addr2))
33045+ if (is_kernel_text(address, address + PMD_SIZE))
33046 prot = PAGE_KERNEL_LARGE_EXEC;
33047
33048 pages_2m++;
33049@@ -343,7 +347,7 @@ repeat:
33050 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
33051 pte += pte_ofs;
33052 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
33053- pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
33054+ pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
33055 pgprot_t prot = PAGE_KERNEL;
33056 /*
33057 * first pass will use the same initial
33058@@ -351,7 +355,7 @@ repeat:
33059 */
33060 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
33061
33062- if (is_kernel_text(addr))
33063+ if (is_kernel_text(address, address + PAGE_SIZE))
33064 prot = PAGE_KERNEL_EXEC;
33065
33066 pages_4k++;
33067@@ -474,7 +478,7 @@ void __init native_pagetable_init(void)
33068
33069 pud = pud_offset(pgd, va);
33070 pmd = pmd_offset(pud, va);
33071- if (!pmd_present(*pmd))
33072+ if (!pmd_present(*pmd)) // PAX TODO || pmd_large(*pmd))
33073 break;
33074
33075 /* should not be large page here */
33076@@ -532,12 +536,10 @@ void __init early_ioremap_page_table_range_init(void)
33077
33078 static void __init pagetable_init(void)
33079 {
33080- pgd_t *pgd_base = swapper_pg_dir;
33081-
33082- permanent_kmaps_init(pgd_base);
33083+ permanent_kmaps_init(swapper_pg_dir);
33084 }
33085
33086-pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL);
33087+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL);
33088 EXPORT_SYMBOL_GPL(__supported_pte_mask);
33089
33090 /* user-defined highmem size */
33091@@ -787,10 +789,10 @@ void __init mem_init(void)
33092 ((unsigned long)&__init_end -
33093 (unsigned long)&__init_begin) >> 10,
33094
33095- (unsigned long)&_etext, (unsigned long)&_edata,
33096- ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
33097+ (unsigned long)&_sdata, (unsigned long)&_edata,
33098+ ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
33099
33100- (unsigned long)&_text, (unsigned long)&_etext,
33101+ ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
33102 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
33103
33104 /*
33105@@ -884,6 +886,7 @@ void set_kernel_text_rw(void)
33106 if (!kernel_set_to_readonly)
33107 return;
33108
33109+ start = ktla_ktva(start);
33110 pr_debug("Set kernel text: %lx - %lx for read write\n",
33111 start, start+size);
33112
33113@@ -898,6 +901,7 @@ void set_kernel_text_ro(void)
33114 if (!kernel_set_to_readonly)
33115 return;
33116
33117+ start = ktla_ktva(start);
33118 pr_debug("Set kernel text: %lx - %lx for read only\n",
33119 start, start+size);
33120
33121@@ -926,6 +930,7 @@ void mark_rodata_ro(void)
33122 unsigned long start = PFN_ALIGN(_text);
33123 unsigned long size = PFN_ALIGN(_etext) - start;
33124
33125+ start = ktla_ktva(start);
33126 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
33127 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
33128 size >> 10);
33129diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
33130index 4e5dfec..6fd6dc5 100644
33131--- a/arch/x86/mm/init_64.c
33132+++ b/arch/x86/mm/init_64.c
33133@@ -151,7 +151,7 @@ early_param("gbpages", parse_direct_gbpages_on);
33134 * around without checking the pgd every time.
33135 */
33136
33137-pteval_t __supported_pte_mask __read_mostly = ~0;
33138+pteval_t __supported_pte_mask __read_only = ~_PAGE_NX;
33139 EXPORT_SYMBOL_GPL(__supported_pte_mask);
33140
33141 int force_personality32;
33142@@ -184,7 +184,12 @@ void sync_global_pgds(unsigned long start, unsigned long end, int removed)
33143
33144 for (address = start; address <= end; address += PGDIR_SIZE) {
33145 const pgd_t *pgd_ref = pgd_offset_k(address);
33146+
33147+#ifdef CONFIG_PAX_PER_CPU_PGD
33148+ unsigned long cpu;
33149+#else
33150 struct page *page;
33151+#endif
33152
33153 /*
33154 * When it is called after memory hot remove, pgd_none()
33155@@ -195,6 +200,25 @@ void sync_global_pgds(unsigned long start, unsigned long end, int removed)
33156 continue;
33157
33158 spin_lock(&pgd_lock);
33159+
33160+#ifdef CONFIG_PAX_PER_CPU_PGD
33161+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
33162+ pgd_t *pgd = pgd_offset_cpu(cpu, user, address);
33163+
33164+ if (!pgd_none(*pgd_ref) && !pgd_none(*pgd))
33165+ BUG_ON(pgd_page_vaddr(*pgd)
33166+ != pgd_page_vaddr(*pgd_ref));
33167+
33168+ if (removed) {
33169+ if (pgd_none(*pgd_ref) && !pgd_none(*pgd))
33170+ pgd_clear(pgd);
33171+ } else {
33172+ if (pgd_none(*pgd))
33173+ set_pgd(pgd, *pgd_ref);
33174+ }
33175+
33176+ pgd = pgd_offset_cpu(cpu, kernel, address);
33177+#else
33178 list_for_each_entry(page, &pgd_list, lru) {
33179 pgd_t *pgd;
33180 spinlock_t *pgt_lock;
33181@@ -203,6 +227,7 @@ void sync_global_pgds(unsigned long start, unsigned long end, int removed)
33182 /* the pgt_lock only for Xen */
33183 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
33184 spin_lock(pgt_lock);
33185+#endif
33186
33187 if (!pgd_none(*pgd_ref) && !pgd_none(*pgd))
33188 BUG_ON(pgd_page_vaddr(*pgd)
33189@@ -216,7 +241,10 @@ void sync_global_pgds(unsigned long start, unsigned long end, int removed)
33190 set_pgd(pgd, *pgd_ref);
33191 }
33192
33193+#ifndef CONFIG_PAX_PER_CPU_PGD
33194 spin_unlock(pgt_lock);
33195+#endif
33196+
33197 }
33198 spin_unlock(&pgd_lock);
33199 }
33200@@ -249,7 +277,7 @@ static pud_t *fill_pud(pgd_t *pgd, unsigned long vaddr)
33201 {
33202 if (pgd_none(*pgd)) {
33203 pud_t *pud = (pud_t *)spp_getpage();
33204- pgd_populate(&init_mm, pgd, pud);
33205+ pgd_populate_kernel(&init_mm, pgd, pud);
33206 if (pud != pud_offset(pgd, 0))
33207 printk(KERN_ERR "PAGETABLE BUG #00! %p <-> %p\n",
33208 pud, pud_offset(pgd, 0));
33209@@ -261,7 +289,7 @@ static pmd_t *fill_pmd(pud_t *pud, unsigned long vaddr)
33210 {
33211 if (pud_none(*pud)) {
33212 pmd_t *pmd = (pmd_t *) spp_getpage();
33213- pud_populate(&init_mm, pud, pmd);
33214+ pud_populate_kernel(&init_mm, pud, pmd);
33215 if (pmd != pmd_offset(pud, 0))
33216 printk(KERN_ERR "PAGETABLE BUG #01! %p <-> %p\n",
33217 pmd, pmd_offset(pud, 0));
33218@@ -290,7 +318,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
33219 pmd = fill_pmd(pud, vaddr);
33220 pte = fill_pte(pmd, vaddr);
33221
33222+ pax_open_kernel();
33223 set_pte(pte, new_pte);
33224+ pax_close_kernel();
33225
33226 /*
33227 * It's enough to flush this one mapping.
33228@@ -349,14 +379,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
33229 pgd = pgd_offset_k((unsigned long)__va(phys));
33230 if (pgd_none(*pgd)) {
33231 pud = (pud_t *) spp_getpage();
33232- set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
33233- _PAGE_USER));
33234+ set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
33235 }
33236 pud = pud_offset(pgd, (unsigned long)__va(phys));
33237 if (pud_none(*pud)) {
33238 pmd = (pmd_t *) spp_getpage();
33239- set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
33240- _PAGE_USER));
33241+ set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
33242 }
33243 pmd = pmd_offset(pud, phys);
33244 BUG_ON(!pmd_none(*pmd));
33245@@ -597,7 +625,7 @@ phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end,
33246 prot);
33247
33248 spin_lock(&init_mm.page_table_lock);
33249- pud_populate(&init_mm, pud, pmd);
33250+ pud_populate_kernel(&init_mm, pud, pmd);
33251 spin_unlock(&init_mm.page_table_lock);
33252 }
33253 __flush_tlb_all();
33254@@ -638,7 +666,7 @@ kernel_physical_mapping_init(unsigned long start,
33255 page_size_mask);
33256
33257 spin_lock(&init_mm.page_table_lock);
33258- pgd_populate(&init_mm, pgd, pud);
33259+ pgd_populate_kernel(&init_mm, pgd, pud);
33260 spin_unlock(&init_mm.page_table_lock);
33261 pgd_changed = true;
33262 }
33263@@ -1217,8 +1245,8 @@ static struct vm_operations_struct gate_vma_ops = {
33264 static struct vm_area_struct gate_vma = {
33265 .vm_start = VSYSCALL_ADDR,
33266 .vm_end = VSYSCALL_ADDR + PAGE_SIZE,
33267- .vm_page_prot = PAGE_READONLY_EXEC,
33268- .vm_flags = VM_READ | VM_EXEC,
33269+ .vm_page_prot = PAGE_READONLY,
33270+ .vm_flags = VM_READ,
33271 .vm_ops = &gate_vma_ops,
33272 };
33273
33274diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
33275index 7b179b49..6bd17777 100644
33276--- a/arch/x86/mm/iomap_32.c
33277+++ b/arch/x86/mm/iomap_32.c
33278@@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
33279 type = kmap_atomic_idx_push();
33280 idx = type + KM_TYPE_NR * smp_processor_id();
33281 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
33282+
33283+ pax_open_kernel();
33284 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
33285+ pax_close_kernel();
33286+
33287 arch_flush_lazy_mmu_mode();
33288
33289 return (void *)vaddr;
33290diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
33291index af78e50..0790b03 100644
33292--- a/arch/x86/mm/ioremap.c
33293+++ b/arch/x86/mm/ioremap.c
33294@@ -56,8 +56,8 @@ static int __ioremap_check_ram(unsigned long start_pfn, unsigned long nr_pages,
33295 unsigned long i;
33296
33297 for (i = 0; i < nr_pages; ++i)
33298- if (pfn_valid(start_pfn + i) &&
33299- !PageReserved(pfn_to_page(start_pfn + i)))
33300+ if (pfn_valid(start_pfn + i) && (start_pfn + i >= 0x100 ||
33301+ !PageReserved(pfn_to_page(start_pfn + i))))
33302 return 1;
33303
33304 WARN_ONCE(1, "ioremap on RAM pfn 0x%lx\n", start_pfn);
33305@@ -280,7 +280,7 @@ EXPORT_SYMBOL(ioremap_prot);
33306 *
33307 * Caller must ensure there is only one unmapping for the same pointer.
33308 */
33309-void iounmap(volatile void __iomem *addr)
33310+void iounmap(const volatile void __iomem *addr)
33311 {
33312 struct vm_struct *p, *o;
33313
33314@@ -334,6 +334,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
33315
33316 /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
33317 if (page_is_ram(start >> PAGE_SHIFT))
33318+#ifdef CONFIG_HIGHMEM
33319+ if ((start >> PAGE_SHIFT) < max_low_pfn)
33320+#endif
33321 return __va(phys);
33322
33323 addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
33324@@ -346,13 +349,16 @@ void *xlate_dev_mem_ptr(unsigned long phys)
33325 void unxlate_dev_mem_ptr(unsigned long phys, void *addr)
33326 {
33327 if (page_is_ram(phys >> PAGE_SHIFT))
33328+#ifdef CONFIG_HIGHMEM
33329+ if ((phys >> PAGE_SHIFT) < max_low_pfn)
33330+#endif
33331 return;
33332
33333 iounmap((void __iomem *)((unsigned long)addr & PAGE_MASK));
33334 return;
33335 }
33336
33337-static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
33338+static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
33339
33340 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
33341 {
33342@@ -388,8 +394,7 @@ void __init early_ioremap_init(void)
33343 early_ioremap_setup();
33344
33345 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
33346- memset(bm_pte, 0, sizeof(bm_pte));
33347- pmd_populate_kernel(&init_mm, pmd, bm_pte);
33348+ pmd_populate_user(&init_mm, pmd, bm_pte);
33349
33350 /*
33351 * The boot-ioremap range spans multiple pmds, for which
33352diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
33353index b4f2e7e..96c9c3e 100644
33354--- a/arch/x86/mm/kmemcheck/kmemcheck.c
33355+++ b/arch/x86/mm/kmemcheck/kmemcheck.c
33356@@ -628,9 +628,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
33357 * memory (e.g. tracked pages)? For now, we need this to avoid
33358 * invoking kmemcheck for PnP BIOS calls.
33359 */
33360- if (regs->flags & X86_VM_MASK)
33361+ if (v8086_mode(regs))
33362 return false;
33363- if (regs->cs != __KERNEL_CS)
33364+ if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
33365 return false;
33366
33367 pte = kmemcheck_pte_lookup(address);
33368diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
33369index 919b912..9267313 100644
33370--- a/arch/x86/mm/mmap.c
33371+++ b/arch/x86/mm/mmap.c
33372@@ -52,7 +52,7 @@ static unsigned int stack_maxrandom_size(void)
33373 * Leave an at least ~128 MB hole with possible stack randomization.
33374 */
33375 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
33376-#define MAX_GAP (TASK_SIZE/6*5)
33377+#define MAX_GAP (pax_task_size/6*5)
33378
33379 static int mmap_is_legacy(void)
33380 {
33381@@ -82,27 +82,40 @@ static unsigned long mmap_rnd(void)
33382 return rnd << PAGE_SHIFT;
33383 }
33384
33385-static unsigned long mmap_base(void)
33386+static unsigned long mmap_base(struct mm_struct *mm)
33387 {
33388 unsigned long gap = rlimit(RLIMIT_STACK);
33389+ unsigned long pax_task_size = TASK_SIZE;
33390+
33391+#ifdef CONFIG_PAX_SEGMEXEC
33392+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
33393+ pax_task_size = SEGMEXEC_TASK_SIZE;
33394+#endif
33395
33396 if (gap < MIN_GAP)
33397 gap = MIN_GAP;
33398 else if (gap > MAX_GAP)
33399 gap = MAX_GAP;
33400
33401- return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
33402+ return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
33403 }
33404
33405 /*
33406 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
33407 * does, but not when emulating X86_32
33408 */
33409-static unsigned long mmap_legacy_base(void)
33410+static unsigned long mmap_legacy_base(struct mm_struct *mm)
33411 {
33412- if (mmap_is_ia32())
33413+ if (mmap_is_ia32()) {
33414+
33415+#ifdef CONFIG_PAX_SEGMEXEC
33416+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
33417+ return SEGMEXEC_TASK_UNMAPPED_BASE;
33418+ else
33419+#endif
33420+
33421 return TASK_UNMAPPED_BASE;
33422- else
33423+ } else
33424 return TASK_UNMAPPED_BASE + mmap_rnd();
33425 }
33426
33427@@ -112,8 +125,15 @@ static unsigned long mmap_legacy_base(void)
33428 */
33429 void arch_pick_mmap_layout(struct mm_struct *mm)
33430 {
33431- mm->mmap_legacy_base = mmap_legacy_base();
33432- mm->mmap_base = mmap_base();
33433+ mm->mmap_legacy_base = mmap_legacy_base(mm);
33434+ mm->mmap_base = mmap_base(mm);
33435+
33436+#ifdef CONFIG_PAX_RANDMMAP
33437+ if (mm->pax_flags & MF_PAX_RANDMMAP) {
33438+ mm->mmap_legacy_base += mm->delta_mmap;
33439+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
33440+ }
33441+#endif
33442
33443 if (mmap_is_legacy()) {
33444 mm->mmap_base = mm->mmap_legacy_base;
33445diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
33446index 0057a7a..95c7edd 100644
33447--- a/arch/x86/mm/mmio-mod.c
33448+++ b/arch/x86/mm/mmio-mod.c
33449@@ -194,7 +194,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
33450 break;
33451 default:
33452 {
33453- unsigned char *ip = (unsigned char *)instptr;
33454+ unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
33455 my_trace->opcode = MMIO_UNKNOWN_OP;
33456 my_trace->width = 0;
33457 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
33458@@ -234,7 +234,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
33459 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
33460 void __iomem *addr)
33461 {
33462- static atomic_t next_id;
33463+ static atomic_unchecked_t next_id;
33464 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
33465 /* These are page-unaligned. */
33466 struct mmiotrace_map map = {
33467@@ -258,7 +258,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
33468 .private = trace
33469 },
33470 .phys = offset,
33471- .id = atomic_inc_return(&next_id)
33472+ .id = atomic_inc_return_unchecked(&next_id)
33473 };
33474 map.map_id = trace->id;
33475
33476@@ -290,7 +290,7 @@ void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
33477 ioremap_trace_core(offset, size, addr);
33478 }
33479
33480-static void iounmap_trace_core(volatile void __iomem *addr)
33481+static void iounmap_trace_core(const volatile void __iomem *addr)
33482 {
33483 struct mmiotrace_map map = {
33484 .phys = 0,
33485@@ -328,7 +328,7 @@ not_enabled:
33486 }
33487 }
33488
33489-void mmiotrace_iounmap(volatile void __iomem *addr)
33490+void mmiotrace_iounmap(const volatile void __iomem *addr)
33491 {
33492 might_sleep();
33493 if (is_enabled()) /* recheck and proper locking in *_core() */
33494diff --git a/arch/x86/mm/numa.c b/arch/x86/mm/numa.c
33495index 1a88370..3f598b5 100644
33496--- a/arch/x86/mm/numa.c
33497+++ b/arch/x86/mm/numa.c
33498@@ -499,7 +499,7 @@ static void __init numa_clear_kernel_node_hotplug(void)
33499 }
33500 }
33501
33502-static int __init numa_register_memblks(struct numa_meminfo *mi)
33503+static int __init __intentional_overflow(-1) numa_register_memblks(struct numa_meminfo *mi)
33504 {
33505 unsigned long uninitialized_var(pfn_align);
33506 int i, nid;
33507diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
33508index 36de293..b820ddc 100644
33509--- a/arch/x86/mm/pageattr.c
33510+++ b/arch/x86/mm/pageattr.c
33511@@ -262,7 +262,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
33512 */
33513 #ifdef CONFIG_PCI_BIOS
33514 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
33515- pgprot_val(forbidden) |= _PAGE_NX;
33516+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
33517 #endif
33518
33519 /*
33520@@ -270,9 +270,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
33521 * Does not cover __inittext since that is gone later on. On
33522 * 64bit we do not enforce !NX on the low mapping
33523 */
33524- if (within(address, (unsigned long)_text, (unsigned long)_etext))
33525- pgprot_val(forbidden) |= _PAGE_NX;
33526+ if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
33527+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
33528
33529+#ifdef CONFIG_DEBUG_RODATA
33530 /*
33531 * The .rodata section needs to be read-only. Using the pfn
33532 * catches all aliases.
33533@@ -280,6 +281,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
33534 if (within(pfn, __pa_symbol(__start_rodata) >> PAGE_SHIFT,
33535 __pa_symbol(__end_rodata) >> PAGE_SHIFT))
33536 pgprot_val(forbidden) |= _PAGE_RW;
33537+#endif
33538
33539 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
33540 /*
33541@@ -318,6 +320,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
33542 }
33543 #endif
33544
33545+#ifdef CONFIG_PAX_KERNEXEC
33546+ if (within(pfn, __pa(ktla_ktva((unsigned long)&_text)), __pa((unsigned long)&_sdata))) {
33547+ pgprot_val(forbidden) |= _PAGE_RW;
33548+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
33549+ }
33550+#endif
33551+
33552 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
33553
33554 return prot;
33555@@ -420,23 +429,37 @@ EXPORT_SYMBOL_GPL(slow_virt_to_phys);
33556 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
33557 {
33558 /* change init_mm */
33559+ pax_open_kernel();
33560 set_pte_atomic(kpte, pte);
33561+
33562 #ifdef CONFIG_X86_32
33563 if (!SHARED_KERNEL_PMD) {
33564+
33565+#ifdef CONFIG_PAX_PER_CPU_PGD
33566+ unsigned long cpu;
33567+#else
33568 struct page *page;
33569+#endif
33570
33571+#ifdef CONFIG_PAX_PER_CPU_PGD
33572+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
33573+ pgd_t *pgd = get_cpu_pgd(cpu, kernel);
33574+#else
33575 list_for_each_entry(page, &pgd_list, lru) {
33576- pgd_t *pgd;
33577+ pgd_t *pgd = (pgd_t *)page_address(page);
33578+#endif
33579+
33580 pud_t *pud;
33581 pmd_t *pmd;
33582
33583- pgd = (pgd_t *)page_address(page) + pgd_index(address);
33584+ pgd += pgd_index(address);
33585 pud = pud_offset(pgd, address);
33586 pmd = pmd_offset(pud, address);
33587 set_pte_atomic((pte_t *)pmd, pte);
33588 }
33589 }
33590 #endif
33591+ pax_close_kernel();
33592 }
33593
33594 static int
33595diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
33596index 6574388..87e9bef 100644
33597--- a/arch/x86/mm/pat.c
33598+++ b/arch/x86/mm/pat.c
33599@@ -376,7 +376,7 @@ int free_memtype(u64 start, u64 end)
33600
33601 if (!entry) {
33602 printk(KERN_INFO "%s:%d freeing invalid memtype [mem %#010Lx-%#010Lx]\n",
33603- current->comm, current->pid, start, end - 1);
33604+ current->comm, task_pid_nr(current), start, end - 1);
33605 return -EINVAL;
33606 }
33607
33608@@ -506,8 +506,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
33609
33610 while (cursor < to) {
33611 if (!devmem_is_allowed(pfn)) {
33612- printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx]\n",
33613- current->comm, from, to - 1);
33614+ printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx] (%#010Lx)\n",
33615+ current->comm, from, to - 1, cursor);
33616 return 0;
33617 }
33618 cursor += PAGE_SIZE;
33619@@ -577,7 +577,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
33620 if (ioremap_change_attr((unsigned long)__va(base), id_sz, flags) < 0) {
33621 printk(KERN_INFO "%s:%d ioremap_change_attr failed %s "
33622 "for [mem %#010Lx-%#010Lx]\n",
33623- current->comm, current->pid,
33624+ current->comm, task_pid_nr(current),
33625 cattr_name(flags),
33626 base, (unsigned long long)(base + size-1));
33627 return -EINVAL;
33628@@ -612,7 +612,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
33629 flags = lookup_memtype(paddr);
33630 if (want_flags != flags) {
33631 printk(KERN_WARNING "%s:%d map pfn RAM range req %s for [mem %#010Lx-%#010Lx], got %s\n",
33632- current->comm, current->pid,
33633+ current->comm, task_pid_nr(current),
33634 cattr_name(want_flags),
33635 (unsigned long long)paddr,
33636 (unsigned long long)(paddr + size - 1),
33637@@ -634,7 +634,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
33638 free_memtype(paddr, paddr + size);
33639 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
33640 " for [mem %#010Lx-%#010Lx], got %s\n",
33641- current->comm, current->pid,
33642+ current->comm, task_pid_nr(current),
33643 cattr_name(want_flags),
33644 (unsigned long long)paddr,
33645 (unsigned long long)(paddr + size - 1),
33646diff --git a/arch/x86/mm/pat_rbtree.c b/arch/x86/mm/pat_rbtree.c
33647index 415f6c4..d319983 100644
33648--- a/arch/x86/mm/pat_rbtree.c
33649+++ b/arch/x86/mm/pat_rbtree.c
33650@@ -160,7 +160,7 @@ success:
33651
33652 failure:
33653 printk(KERN_INFO "%s:%d conflicting memory types "
33654- "%Lx-%Lx %s<->%s\n", current->comm, current->pid, start,
33655+ "%Lx-%Lx %s<->%s\n", current->comm, task_pid_nr(current), start,
33656 end, cattr_name(found_type), cattr_name(match->type));
33657 return -EBUSY;
33658 }
33659diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
33660index 9f0614d..92ae64a 100644
33661--- a/arch/x86/mm/pf_in.c
33662+++ b/arch/x86/mm/pf_in.c
33663@@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
33664 int i;
33665 enum reason_type rv = OTHERS;
33666
33667- p = (unsigned char *)ins_addr;
33668+ p = (unsigned char *)ktla_ktva(ins_addr);
33669 p += skip_prefix(p, &prf);
33670 p += get_opcode(p, &opcode);
33671
33672@@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
33673 struct prefix_bits prf;
33674 int i;
33675
33676- p = (unsigned char *)ins_addr;
33677+ p = (unsigned char *)ktla_ktva(ins_addr);
33678 p += skip_prefix(p, &prf);
33679 p += get_opcode(p, &opcode);
33680
33681@@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
33682 struct prefix_bits prf;
33683 int i;
33684
33685- p = (unsigned char *)ins_addr;
33686+ p = (unsigned char *)ktla_ktva(ins_addr);
33687 p += skip_prefix(p, &prf);
33688 p += get_opcode(p, &opcode);
33689
33690@@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
33691 struct prefix_bits prf;
33692 int i;
33693
33694- p = (unsigned char *)ins_addr;
33695+ p = (unsigned char *)ktla_ktva(ins_addr);
33696 p += skip_prefix(p, &prf);
33697 p += get_opcode(p, &opcode);
33698 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
33699@@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
33700 struct prefix_bits prf;
33701 int i;
33702
33703- p = (unsigned char *)ins_addr;
33704+ p = (unsigned char *)ktla_ktva(ins_addr);
33705 p += skip_prefix(p, &prf);
33706 p += get_opcode(p, &opcode);
33707 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
33708diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
33709index 6fb6927..4fc13c0 100644
33710--- a/arch/x86/mm/pgtable.c
33711+++ b/arch/x86/mm/pgtable.c
33712@@ -97,10 +97,71 @@ static inline void pgd_list_del(pgd_t *pgd)
33713 list_del(&page->lru);
33714 }
33715
33716-#define UNSHARED_PTRS_PER_PGD \
33717- (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
33718+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
33719+pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
33720
33721+void __shadow_user_pgds(pgd_t *dst, const pgd_t *src)
33722+{
33723+ unsigned int count = USER_PGD_PTRS;
33724
33725+ if (!pax_user_shadow_base)
33726+ return;
33727+
33728+ while (count--)
33729+ *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
33730+}
33731+#endif
33732+
33733+#ifdef CONFIG_PAX_PER_CPU_PGD
33734+void __clone_user_pgds(pgd_t *dst, const pgd_t *src)
33735+{
33736+ unsigned int count = USER_PGD_PTRS;
33737+
33738+ while (count--) {
33739+ pgd_t pgd;
33740+
33741+#ifdef CONFIG_X86_64
33742+ pgd = __pgd(pgd_val(*src++) | _PAGE_USER);
33743+#else
33744+ pgd = *src++;
33745+#endif
33746+
33747+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
33748+ pgd = __pgd(pgd_val(pgd) & clone_pgd_mask);
33749+#endif
33750+
33751+ *dst++ = pgd;
33752+ }
33753+
33754+}
33755+#endif
33756+
33757+#ifdef CONFIG_X86_64
33758+#define pxd_t pud_t
33759+#define pyd_t pgd_t
33760+#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
33761+#define pgtable_pxd_page_ctor(page) true
33762+#define pgtable_pxd_page_dtor(page)
33763+#define pxd_free(mm, pud) pud_free((mm), (pud))
33764+#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
33765+#define pyd_offset(mm, address) pgd_offset((mm), (address))
33766+#define PYD_SIZE PGDIR_SIZE
33767+#else
33768+#define pxd_t pmd_t
33769+#define pyd_t pud_t
33770+#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
33771+#define pgtable_pxd_page_ctor(page) pgtable_pmd_page_ctor(page)
33772+#define pgtable_pxd_page_dtor(page) pgtable_pmd_page_dtor(page)
33773+#define pxd_free(mm, pud) pmd_free((mm), (pud))
33774+#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
33775+#define pyd_offset(mm, address) pud_offset((mm), (address))
33776+#define PYD_SIZE PUD_SIZE
33777+#endif
33778+
33779+#ifdef CONFIG_PAX_PER_CPU_PGD
33780+static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
33781+static inline void pgd_dtor(pgd_t *pgd) {}
33782+#else
33783 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
33784 {
33785 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
33786@@ -141,6 +202,7 @@ static void pgd_dtor(pgd_t *pgd)
33787 pgd_list_del(pgd);
33788 spin_unlock(&pgd_lock);
33789 }
33790+#endif
33791
33792 /*
33793 * List of all pgd's needed for non-PAE so it can invalidate entries
33794@@ -153,7 +215,7 @@ static void pgd_dtor(pgd_t *pgd)
33795 * -- nyc
33796 */
33797
33798-#ifdef CONFIG_X86_PAE
33799+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
33800 /*
33801 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
33802 * updating the top-level pagetable entries to guarantee the
33803@@ -165,7 +227,7 @@ static void pgd_dtor(pgd_t *pgd)
33804 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
33805 * and initialize the kernel pmds here.
33806 */
33807-#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
33808+#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
33809
33810 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
33811 {
33812@@ -183,43 +245,45 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
33813 */
33814 flush_tlb_mm(mm);
33815 }
33816+#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
33817+#define PREALLOCATED_PXDS USER_PGD_PTRS
33818 #else /* !CONFIG_X86_PAE */
33819
33820 /* No need to prepopulate any pagetable entries in non-PAE modes. */
33821-#define PREALLOCATED_PMDS 0
33822+#define PREALLOCATED_PXDS 0
33823
33824 #endif /* CONFIG_X86_PAE */
33825
33826-static void free_pmds(pmd_t *pmds[])
33827+static void free_pxds(pxd_t *pxds[])
33828 {
33829 int i;
33830
33831- for(i = 0; i < PREALLOCATED_PMDS; i++)
33832- if (pmds[i]) {
33833- pgtable_pmd_page_dtor(virt_to_page(pmds[i]));
33834- free_page((unsigned long)pmds[i]);
33835+ for(i = 0; i < PREALLOCATED_PXDS; i++)
33836+ if (pxds[i]) {
33837+ pgtable_pxd_page_dtor(virt_to_page(pxds[i]));
33838+ free_page((unsigned long)pxds[i]);
33839 }
33840 }
33841
33842-static int preallocate_pmds(pmd_t *pmds[])
33843+static int preallocate_pxds(pxd_t *pxds[])
33844 {
33845 int i;
33846 bool failed = false;
33847
33848- for(i = 0; i < PREALLOCATED_PMDS; i++) {
33849- pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
33850- if (!pmd)
33851+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
33852+ pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
33853+ if (!pxd)
33854 failed = true;
33855- if (pmd && !pgtable_pmd_page_ctor(virt_to_page(pmd))) {
33856- free_page((unsigned long)pmd);
33857- pmd = NULL;
33858+ if (pxd && !pgtable_pxd_page_ctor(virt_to_page(pxd))) {
33859+ free_page((unsigned long)pxd);
33860+ pxd = NULL;
33861 failed = true;
33862 }
33863- pmds[i] = pmd;
33864+ pxds[i] = pxd;
33865 }
33866
33867 if (failed) {
33868- free_pmds(pmds);
33869+ free_pxds(pxds);
33870 return -ENOMEM;
33871 }
33872
33873@@ -232,49 +296,52 @@ static int preallocate_pmds(pmd_t *pmds[])
33874 * preallocate which never got a corresponding vma will need to be
33875 * freed manually.
33876 */
33877-static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
33878+static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
33879 {
33880 int i;
33881
33882- for(i = 0; i < PREALLOCATED_PMDS; i++) {
33883+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
33884 pgd_t pgd = pgdp[i];
33885
33886 if (pgd_val(pgd) != 0) {
33887- pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
33888+ pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
33889
33890- pgdp[i] = native_make_pgd(0);
33891+ set_pgd(pgdp + i, native_make_pgd(0));
33892
33893- paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
33894- pmd_free(mm, pmd);
33895+ paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
33896+ pxd_free(mm, pxd);
33897 }
33898 }
33899 }
33900
33901-static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
33902+static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
33903 {
33904- pud_t *pud;
33905+ pyd_t *pyd;
33906 int i;
33907
33908- if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
33909+ if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
33910 return;
33911
33912- pud = pud_offset(pgd, 0);
33913-
33914- for (i = 0; i < PREALLOCATED_PMDS; i++, pud++) {
33915- pmd_t *pmd = pmds[i];
33916+#ifdef CONFIG_X86_64
33917+ pyd = pyd_offset(mm, 0L);
33918+#else
33919+ pyd = pyd_offset(pgd, 0L);
33920+#endif
33921
33922+ for (i = 0; i < PREALLOCATED_PXDS; i++, pyd++) {
33923+ pxd_t *pxd = pxds[i];
33924 if (i >= KERNEL_PGD_BOUNDARY)
33925- memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
33926- sizeof(pmd_t) * PTRS_PER_PMD);
33927+ memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
33928+ sizeof(pxd_t) * PTRS_PER_PMD);
33929
33930- pud_populate(mm, pud, pmd);
33931+ pyd_populate(mm, pyd, pxd);
33932 }
33933 }
33934
33935 pgd_t *pgd_alloc(struct mm_struct *mm)
33936 {
33937 pgd_t *pgd;
33938- pmd_t *pmds[PREALLOCATED_PMDS];
33939+ pxd_t *pxds[PREALLOCATED_PXDS];
33940
33941 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
33942
33943@@ -283,11 +350,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
33944
33945 mm->pgd = pgd;
33946
33947- if (preallocate_pmds(pmds) != 0)
33948+ if (preallocate_pxds(pxds) != 0)
33949 goto out_free_pgd;
33950
33951 if (paravirt_pgd_alloc(mm) != 0)
33952- goto out_free_pmds;
33953+ goto out_free_pxds;
33954
33955 /*
33956 * Make sure that pre-populating the pmds is atomic with
33957@@ -297,14 +364,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
33958 spin_lock(&pgd_lock);
33959
33960 pgd_ctor(mm, pgd);
33961- pgd_prepopulate_pmd(mm, pgd, pmds);
33962+ pgd_prepopulate_pxd(mm, pgd, pxds);
33963
33964 spin_unlock(&pgd_lock);
33965
33966 return pgd;
33967
33968-out_free_pmds:
33969- free_pmds(pmds);
33970+out_free_pxds:
33971+ free_pxds(pxds);
33972 out_free_pgd:
33973 free_page((unsigned long)pgd);
33974 out:
33975@@ -313,7 +380,7 @@ out:
33976
33977 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
33978 {
33979- pgd_mop_up_pmds(mm, pgd);
33980+ pgd_mop_up_pxds(mm, pgd);
33981 pgd_dtor(pgd);
33982 paravirt_pgd_free(mm, pgd);
33983 free_page((unsigned long)pgd);
33984diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
33985index 75cc097..79a097f 100644
33986--- a/arch/x86/mm/pgtable_32.c
33987+++ b/arch/x86/mm/pgtable_32.c
33988@@ -47,10 +47,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
33989 return;
33990 }
33991 pte = pte_offset_kernel(pmd, vaddr);
33992+
33993+ pax_open_kernel();
33994 if (pte_val(pteval))
33995 set_pte_at(&init_mm, vaddr, pte, pteval);
33996 else
33997 pte_clear(&init_mm, vaddr, pte);
33998+ pax_close_kernel();
33999
34000 /*
34001 * It's enough to flush this one mapping.
34002diff --git a/arch/x86/mm/physaddr.c b/arch/x86/mm/physaddr.c
34003index e666cbb..61788c45 100644
34004--- a/arch/x86/mm/physaddr.c
34005+++ b/arch/x86/mm/physaddr.c
34006@@ -10,7 +10,7 @@
34007 #ifdef CONFIG_X86_64
34008
34009 #ifdef CONFIG_DEBUG_VIRTUAL
34010-unsigned long __phys_addr(unsigned long x)
34011+unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
34012 {
34013 unsigned long y = x - __START_KERNEL_map;
34014
34015@@ -67,7 +67,7 @@ EXPORT_SYMBOL(__virt_addr_valid);
34016 #else
34017
34018 #ifdef CONFIG_DEBUG_VIRTUAL
34019-unsigned long __phys_addr(unsigned long x)
34020+unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
34021 {
34022 unsigned long phys_addr = x - PAGE_OFFSET;
34023 /* VMALLOC_* aren't constants */
34024diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
34025index 90555bf..f5f1828 100644
34026--- a/arch/x86/mm/setup_nx.c
34027+++ b/arch/x86/mm/setup_nx.c
34028@@ -5,8 +5,10 @@
34029 #include <asm/pgtable.h>
34030 #include <asm/proto.h>
34031
34032+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
34033 static int disable_nx;
34034
34035+#ifndef CONFIG_PAX_PAGEEXEC
34036 /*
34037 * noexec = on|off
34038 *
34039@@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
34040 return 0;
34041 }
34042 early_param("noexec", noexec_setup);
34043+#endif
34044+
34045+#endif
34046
34047 void x86_configure_nx(void)
34048 {
34049+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
34050 if (cpu_has_nx && !disable_nx)
34051 __supported_pte_mask |= _PAGE_NX;
34052 else
34053+#endif
34054 __supported_pte_mask &= ~_PAGE_NX;
34055 }
34056
34057diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
34058index ee61c36..e6fedeb 100644
34059--- a/arch/x86/mm/tlb.c
34060+++ b/arch/x86/mm/tlb.c
34061@@ -48,7 +48,11 @@ void leave_mm(int cpu)
34062 BUG();
34063 if (cpumask_test_cpu(cpu, mm_cpumask(active_mm))) {
34064 cpumask_clear_cpu(cpu, mm_cpumask(active_mm));
34065+
34066+#ifndef CONFIG_PAX_PER_CPU_PGD
34067 load_cr3(swapper_pg_dir);
34068+#endif
34069+
34070 /*
34071 * This gets called in the idle path where RCU
34072 * functions differently. Tracing normally
34073diff --git a/arch/x86/mm/uderef_64.c b/arch/x86/mm/uderef_64.c
34074new file mode 100644
34075index 0000000..dace51c
34076--- /dev/null
34077+++ b/arch/x86/mm/uderef_64.c
34078@@ -0,0 +1,37 @@
34079+#include <linux/mm.h>
34080+#include <asm/pgtable.h>
34081+#include <asm/uaccess.h>
34082+
34083+#ifdef CONFIG_PAX_MEMORY_UDEREF
34084+/* PaX: due to the special call convention these functions must
34085+ * - remain leaf functions under all configurations,
34086+ * - never be called directly, only dereferenced from the wrappers.
34087+ */
34088+void __pax_open_userland(void)
34089+{
34090+ unsigned int cpu;
34091+
34092+ if (unlikely(!segment_eq(get_fs(), USER_DS)))
34093+ return;
34094+
34095+ cpu = raw_get_cpu();
34096+ BUG_ON((read_cr3() & ~PAGE_MASK) != PCID_KERNEL);
34097+ write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER | PCID_NOFLUSH);
34098+ raw_put_cpu_no_resched();
34099+}
34100+EXPORT_SYMBOL(__pax_open_userland);
34101+
34102+void __pax_close_userland(void)
34103+{
34104+ unsigned int cpu;
34105+
34106+ if (unlikely(!segment_eq(get_fs(), USER_DS)))
34107+ return;
34108+
34109+ cpu = raw_get_cpu();
34110+ BUG_ON((read_cr3() & ~PAGE_MASK) != PCID_USER);
34111+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
34112+ raw_put_cpu_no_resched();
34113+}
34114+EXPORT_SYMBOL(__pax_close_userland);
34115+#endif
34116diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
34117index 6440221..f84b5c7 100644
34118--- a/arch/x86/net/bpf_jit.S
34119+++ b/arch/x86/net/bpf_jit.S
34120@@ -9,6 +9,7 @@
34121 */
34122 #include <linux/linkage.h>
34123 #include <asm/dwarf2.h>
34124+#include <asm/alternative-asm.h>
34125
34126 /*
34127 * Calling convention :
34128@@ -38,6 +39,7 @@ sk_load_word_positive_offset:
34129 jle bpf_slow_path_word
34130 mov (SKBDATA,%rsi),%eax
34131 bswap %eax /* ntohl() */
34132+ pax_force_retaddr
34133 ret
34134
34135 sk_load_half:
34136@@ -55,6 +57,7 @@ sk_load_half_positive_offset:
34137 jle bpf_slow_path_half
34138 movzwl (SKBDATA,%rsi),%eax
34139 rol $8,%ax # ntohs()
34140+ pax_force_retaddr
34141 ret
34142
34143 sk_load_byte:
34144@@ -69,6 +72,7 @@ sk_load_byte_positive_offset:
34145 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
34146 jle bpf_slow_path_byte
34147 movzbl (SKBDATA,%rsi),%eax
34148+ pax_force_retaddr
34149 ret
34150
34151 /* rsi contains offset and can be scratched */
34152@@ -90,6 +94,7 @@ bpf_slow_path_word:
34153 js bpf_error
34154 mov - MAX_BPF_STACK + 32(%rbp),%eax
34155 bswap %eax
34156+ pax_force_retaddr
34157 ret
34158
34159 bpf_slow_path_half:
34160@@ -98,12 +103,14 @@ bpf_slow_path_half:
34161 mov - MAX_BPF_STACK + 32(%rbp),%ax
34162 rol $8,%ax
34163 movzwl %ax,%eax
34164+ pax_force_retaddr
34165 ret
34166
34167 bpf_slow_path_byte:
34168 bpf_slow_path_common(1)
34169 js bpf_error
34170 movzbl - MAX_BPF_STACK + 32(%rbp),%eax
34171+ pax_force_retaddr
34172 ret
34173
34174 #define sk_negative_common(SIZE) \
34175@@ -126,6 +133,7 @@ sk_load_word_negative_offset:
34176 sk_negative_common(4)
34177 mov (%rax), %eax
34178 bswap %eax
34179+ pax_force_retaddr
34180 ret
34181
34182 bpf_slow_path_half_neg:
34183@@ -137,6 +145,7 @@ sk_load_half_negative_offset:
34184 mov (%rax),%ax
34185 rol $8,%ax
34186 movzwl %ax,%eax
34187+ pax_force_retaddr
34188 ret
34189
34190 bpf_slow_path_byte_neg:
34191@@ -146,6 +155,7 @@ sk_load_byte_negative_offset:
34192 .globl sk_load_byte_negative_offset
34193 sk_negative_common(1)
34194 movzbl (%rax), %eax
34195+ pax_force_retaddr
34196 ret
34197
34198 bpf_error:
34199@@ -156,4 +166,5 @@ bpf_error:
34200 mov - MAX_BPF_STACK + 16(%rbp),%r14
34201 mov - MAX_BPF_STACK + 24(%rbp),%r15
34202 leaveq
34203+ pax_force_retaddr
34204 ret
34205diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
34206index 3f62734..a57894f 100644
34207--- a/arch/x86/net/bpf_jit_comp.c
34208+++ b/arch/x86/net/bpf_jit_comp.c
34209@@ -13,7 +13,11 @@
34210 #include <linux/if_vlan.h>
34211 #include <asm/cacheflush.h>
34212
34213+#ifdef CONFIG_GRKERNSEC_BPF_HARDEN
34214+int bpf_jit_enable __read_only;
34215+#else
34216 int bpf_jit_enable __read_mostly;
34217+#endif
34218
34219 /*
34220 * assembly code in arch/x86/net/bpf_jit.S
34221@@ -174,7 +178,9 @@ static inline u8 add_2reg(u8 byte, u32 dst_reg, u32 src_reg)
34222 static void jit_fill_hole(void *area, unsigned int size)
34223 {
34224 /* fill whole space with int3 instructions */
34225+ pax_open_kernel();
34226 memset(area, 0xcc, size);
34227+ pax_close_kernel();
34228 }
34229
34230 struct jit_context {
34231@@ -894,7 +900,9 @@ common_load:
34232 pr_err("bpf_jit_compile fatal error\n");
34233 return -EFAULT;
34234 }
34235+ pax_open_kernel();
34236 memcpy(image + proglen, temp, ilen);
34237+ pax_close_kernel();
34238 }
34239 proglen += ilen;
34240 addrs[i] = proglen;
34241@@ -966,7 +974,6 @@ void bpf_int_jit_compile(struct bpf_prog *prog)
34242
34243 if (image) {
34244 bpf_flush_icache(header, image + proglen);
34245- set_memory_ro((unsigned long)header, header->pages);
34246 prog->bpf_func = (void *)image;
34247 prog->jited = true;
34248 }
34249@@ -979,12 +986,8 @@ void bpf_jit_free(struct bpf_prog *fp)
34250 unsigned long addr = (unsigned long)fp->bpf_func & PAGE_MASK;
34251 struct bpf_binary_header *header = (void *)addr;
34252
34253- if (!fp->jited)
34254- goto free_filter;
34255+ if (fp->jited)
34256+ bpf_jit_binary_free(header);
34257
34258- set_memory_rw(addr, header->pages);
34259- bpf_jit_binary_free(header);
34260-
34261-free_filter:
34262 bpf_prog_unlock_free(fp);
34263 }
34264diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
34265index 5d04be5..2beeaa2 100644
34266--- a/arch/x86/oprofile/backtrace.c
34267+++ b/arch/x86/oprofile/backtrace.c
34268@@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
34269 struct stack_frame_ia32 *fp;
34270 unsigned long bytes;
34271
34272- bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
34273+ bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
34274 if (bytes != 0)
34275 return NULL;
34276
34277- fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
34278+ fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
34279
34280 oprofile_add_trace(bufhead[0].return_address);
34281
34282@@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
34283 struct stack_frame bufhead[2];
34284 unsigned long bytes;
34285
34286- bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
34287+ bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
34288 if (bytes != 0)
34289 return NULL;
34290
34291@@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
34292 {
34293 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
34294
34295- if (!user_mode_vm(regs)) {
34296+ if (!user_mode(regs)) {
34297 unsigned long stack = kernel_stack_pointer(regs);
34298 if (depth)
34299 dump_trace(NULL, regs, (unsigned long *)stack, 0,
34300diff --git a/arch/x86/oprofile/nmi_int.c b/arch/x86/oprofile/nmi_int.c
34301index 1d2e639..f6ef82a 100644
34302--- a/arch/x86/oprofile/nmi_int.c
34303+++ b/arch/x86/oprofile/nmi_int.c
34304@@ -23,6 +23,7 @@
34305 #include <asm/nmi.h>
34306 #include <asm/msr.h>
34307 #include <asm/apic.h>
34308+#include <asm/pgtable.h>
34309
34310 #include "op_counter.h"
34311 #include "op_x86_model.h"
34312@@ -785,8 +786,11 @@ int __init op_nmi_init(struct oprofile_operations *ops)
34313 if (ret)
34314 return ret;
34315
34316- if (!model->num_virt_counters)
34317- model->num_virt_counters = model->num_counters;
34318+ if (!model->num_virt_counters) {
34319+ pax_open_kernel();
34320+ *(unsigned int *)&model->num_virt_counters = model->num_counters;
34321+ pax_close_kernel();
34322+ }
34323
34324 mux_init(ops);
34325
34326diff --git a/arch/x86/oprofile/op_model_amd.c b/arch/x86/oprofile/op_model_amd.c
34327index 50d86c0..7985318 100644
34328--- a/arch/x86/oprofile/op_model_amd.c
34329+++ b/arch/x86/oprofile/op_model_amd.c
34330@@ -519,9 +519,11 @@ static int op_amd_init(struct oprofile_operations *ops)
34331 num_counters = AMD64_NUM_COUNTERS;
34332 }
34333
34334- op_amd_spec.num_counters = num_counters;
34335- op_amd_spec.num_controls = num_counters;
34336- op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
34337+ pax_open_kernel();
34338+ *(unsigned int *)&op_amd_spec.num_counters = num_counters;
34339+ *(unsigned int *)&op_amd_spec.num_controls = num_counters;
34340+ *(unsigned int *)&op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
34341+ pax_close_kernel();
34342
34343 return 0;
34344 }
34345diff --git a/arch/x86/oprofile/op_model_ppro.c b/arch/x86/oprofile/op_model_ppro.c
34346index d90528e..0127e2b 100644
34347--- a/arch/x86/oprofile/op_model_ppro.c
34348+++ b/arch/x86/oprofile/op_model_ppro.c
34349@@ -19,6 +19,7 @@
34350 #include <asm/msr.h>
34351 #include <asm/apic.h>
34352 #include <asm/nmi.h>
34353+#include <asm/pgtable.h>
34354
34355 #include "op_x86_model.h"
34356 #include "op_counter.h"
34357@@ -221,8 +222,10 @@ static void arch_perfmon_setup_counters(void)
34358
34359 num_counters = min((int)eax.split.num_counters, OP_MAX_COUNTER);
34360
34361- op_arch_perfmon_spec.num_counters = num_counters;
34362- op_arch_perfmon_spec.num_controls = num_counters;
34363+ pax_open_kernel();
34364+ *(unsigned int *)&op_arch_perfmon_spec.num_counters = num_counters;
34365+ *(unsigned int *)&op_arch_perfmon_spec.num_controls = num_counters;
34366+ pax_close_kernel();
34367 }
34368
34369 static int arch_perfmon_init(struct oprofile_operations *ignore)
34370diff --git a/arch/x86/oprofile/op_x86_model.h b/arch/x86/oprofile/op_x86_model.h
34371index 71e8a67..6a313bb 100644
34372--- a/arch/x86/oprofile/op_x86_model.h
34373+++ b/arch/x86/oprofile/op_x86_model.h
34374@@ -52,7 +52,7 @@ struct op_x86_model_spec {
34375 void (*switch_ctrl)(struct op_x86_model_spec const *model,
34376 struct op_msrs const * const msrs);
34377 #endif
34378-};
34379+} __do_const;
34380
34381 struct op_counter_config;
34382
34383diff --git a/arch/x86/pci/intel_mid_pci.c b/arch/x86/pci/intel_mid_pci.c
34384index b9958c3..24229ab 100644
34385--- a/arch/x86/pci/intel_mid_pci.c
34386+++ b/arch/x86/pci/intel_mid_pci.c
34387@@ -250,7 +250,7 @@ int __init intel_mid_pci_init(void)
34388 pci_mmcfg_late_init();
34389 pcibios_enable_irq = intel_mid_pci_irq_enable;
34390 pcibios_disable_irq = intel_mid_pci_irq_disable;
34391- pci_root_ops = intel_mid_pci_ops;
34392+ memcpy((void *)&pci_root_ops, &intel_mid_pci_ops, sizeof pci_root_ops);
34393 pci_soc_mode = 1;
34394 /* Continue with standard init */
34395 return 1;
34396diff --git a/arch/x86/pci/irq.c b/arch/x86/pci/irq.c
34397index eb500c2..eab9e70 100644
34398--- a/arch/x86/pci/irq.c
34399+++ b/arch/x86/pci/irq.c
34400@@ -51,7 +51,7 @@ struct irq_router {
34401 struct irq_router_handler {
34402 u16 vendor;
34403 int (*probe)(struct irq_router *r, struct pci_dev *router, u16 device);
34404-};
34405+} __do_const;
34406
34407 int (*pcibios_enable_irq)(struct pci_dev *dev) = pirq_enable_irq;
34408 void (*pcibios_disable_irq)(struct pci_dev *dev) = pirq_disable_irq;
34409@@ -791,7 +791,7 @@ static __init int pico_router_probe(struct irq_router *r, struct pci_dev *router
34410 return 0;
34411 }
34412
34413-static __initdata struct irq_router_handler pirq_routers[] = {
34414+static __initconst const struct irq_router_handler pirq_routers[] = {
34415 { PCI_VENDOR_ID_INTEL, intel_router_probe },
34416 { PCI_VENDOR_ID_AL, ali_router_probe },
34417 { PCI_VENDOR_ID_ITE, ite_router_probe },
34418@@ -818,7 +818,7 @@ static struct pci_dev *pirq_router_dev;
34419 static void __init pirq_find_router(struct irq_router *r)
34420 {
34421 struct irq_routing_table *rt = pirq_table;
34422- struct irq_router_handler *h;
34423+ const struct irq_router_handler *h;
34424
34425 #ifdef CONFIG_PCI_BIOS
34426 if (!rt->signature) {
34427@@ -1091,7 +1091,7 @@ static int __init fix_acer_tm360_irqrouting(const struct dmi_system_id *d)
34428 return 0;
34429 }
34430
34431-static struct dmi_system_id __initdata pciirq_dmi_table[] = {
34432+static const struct dmi_system_id __initconst pciirq_dmi_table[] = {
34433 {
34434 .callback = fix_broken_hp_bios_irq9,
34435 .ident = "HP Pavilion N5400 Series Laptop",
34436diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
34437index 9b83b90..4112152 100644
34438--- a/arch/x86/pci/pcbios.c
34439+++ b/arch/x86/pci/pcbios.c
34440@@ -79,7 +79,7 @@ union bios32 {
34441 static struct {
34442 unsigned long address;
34443 unsigned short segment;
34444-} bios32_indirect __initdata = { 0, __KERNEL_CS };
34445+} bios32_indirect __initconst = { 0, __PCIBIOS_CS };
34446
34447 /*
34448 * Returns the entry point for the given service, NULL on error
34449@@ -92,37 +92,80 @@ static unsigned long __init bios32_service(unsigned long service)
34450 unsigned long length; /* %ecx */
34451 unsigned long entry; /* %edx */
34452 unsigned long flags;
34453+ struct desc_struct d, *gdt;
34454
34455 local_irq_save(flags);
34456- __asm__("lcall *(%%edi); cld"
34457+
34458+ gdt = get_cpu_gdt_table(smp_processor_id());
34459+
34460+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
34461+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
34462+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
34463+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
34464+
34465+ __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
34466 : "=a" (return_code),
34467 "=b" (address),
34468 "=c" (length),
34469 "=d" (entry)
34470 : "0" (service),
34471 "1" (0),
34472- "D" (&bios32_indirect));
34473+ "D" (&bios32_indirect),
34474+ "r"(__PCIBIOS_DS)
34475+ : "memory");
34476+
34477+ pax_open_kernel();
34478+ gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
34479+ gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
34480+ gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
34481+ gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
34482+ pax_close_kernel();
34483+
34484 local_irq_restore(flags);
34485
34486 switch (return_code) {
34487- case 0:
34488- return address + entry;
34489- case 0x80: /* Not present */
34490- printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
34491- return 0;
34492- default: /* Shouldn't happen */
34493- printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
34494- service, return_code);
34495+ case 0: {
34496+ int cpu;
34497+ unsigned char flags;
34498+
34499+ printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
34500+ if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
34501+ printk(KERN_WARNING "bios32_service: not valid\n");
34502 return 0;
34503+ }
34504+ address = address + PAGE_OFFSET;
34505+ length += 16UL; /* some BIOSs underreport this... */
34506+ flags = 4;
34507+ if (length >= 64*1024*1024) {
34508+ length >>= PAGE_SHIFT;
34509+ flags |= 8;
34510+ }
34511+
34512+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
34513+ gdt = get_cpu_gdt_table(cpu);
34514+ pack_descriptor(&d, address, length, 0x9b, flags);
34515+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
34516+ pack_descriptor(&d, address, length, 0x93, flags);
34517+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
34518+ }
34519+ return entry;
34520+ }
34521+ case 0x80: /* Not present */
34522+ printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
34523+ return 0;
34524+ default: /* Shouldn't happen */
34525+ printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
34526+ service, return_code);
34527+ return 0;
34528 }
34529 }
34530
34531 static struct {
34532 unsigned long address;
34533 unsigned short segment;
34534-} pci_indirect = { 0, __KERNEL_CS };
34535+} pci_indirect __read_only = { 0, __PCIBIOS_CS };
34536
34537-static int pci_bios_present;
34538+static int pci_bios_present __read_only;
34539
34540 static int __init check_pcibios(void)
34541 {
34542@@ -131,11 +174,13 @@ static int __init check_pcibios(void)
34543 unsigned long flags, pcibios_entry;
34544
34545 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
34546- pci_indirect.address = pcibios_entry + PAGE_OFFSET;
34547+ pci_indirect.address = pcibios_entry;
34548
34549 local_irq_save(flags);
34550- __asm__(
34551- "lcall *(%%edi); cld\n\t"
34552+ __asm__("movw %w6, %%ds\n\t"
34553+ "lcall *%%ss:(%%edi); cld\n\t"
34554+ "push %%ss\n\t"
34555+ "pop %%ds\n\t"
34556 "jc 1f\n\t"
34557 "xor %%ah, %%ah\n"
34558 "1:"
34559@@ -144,7 +189,8 @@ static int __init check_pcibios(void)
34560 "=b" (ebx),
34561 "=c" (ecx)
34562 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
34563- "D" (&pci_indirect)
34564+ "D" (&pci_indirect),
34565+ "r" (__PCIBIOS_DS)
34566 : "memory");
34567 local_irq_restore(flags);
34568
34569@@ -189,7 +235,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34570
34571 switch (len) {
34572 case 1:
34573- __asm__("lcall *(%%esi); cld\n\t"
34574+ __asm__("movw %w6, %%ds\n\t"
34575+ "lcall *%%ss:(%%esi); cld\n\t"
34576+ "push %%ss\n\t"
34577+ "pop %%ds\n\t"
34578 "jc 1f\n\t"
34579 "xor %%ah, %%ah\n"
34580 "1:"
34581@@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34582 : "1" (PCIBIOS_READ_CONFIG_BYTE),
34583 "b" (bx),
34584 "D" ((long)reg),
34585- "S" (&pci_indirect));
34586+ "S" (&pci_indirect),
34587+ "r" (__PCIBIOS_DS));
34588 /*
34589 * Zero-extend the result beyond 8 bits, do not trust the
34590 * BIOS having done it:
34591@@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34592 *value &= 0xff;
34593 break;
34594 case 2:
34595- __asm__("lcall *(%%esi); cld\n\t"
34596+ __asm__("movw %w6, %%ds\n\t"
34597+ "lcall *%%ss:(%%esi); cld\n\t"
34598+ "push %%ss\n\t"
34599+ "pop %%ds\n\t"
34600 "jc 1f\n\t"
34601 "xor %%ah, %%ah\n"
34602 "1:"
34603@@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34604 : "1" (PCIBIOS_READ_CONFIG_WORD),
34605 "b" (bx),
34606 "D" ((long)reg),
34607- "S" (&pci_indirect));
34608+ "S" (&pci_indirect),
34609+ "r" (__PCIBIOS_DS));
34610 /*
34611 * Zero-extend the result beyond 16 bits, do not trust the
34612 * BIOS having done it:
34613@@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34614 *value &= 0xffff;
34615 break;
34616 case 4:
34617- __asm__("lcall *(%%esi); cld\n\t"
34618+ __asm__("movw %w6, %%ds\n\t"
34619+ "lcall *%%ss:(%%esi); cld\n\t"
34620+ "push %%ss\n\t"
34621+ "pop %%ds\n\t"
34622 "jc 1f\n\t"
34623 "xor %%ah, %%ah\n"
34624 "1:"
34625@@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34626 : "1" (PCIBIOS_READ_CONFIG_DWORD),
34627 "b" (bx),
34628 "D" ((long)reg),
34629- "S" (&pci_indirect));
34630+ "S" (&pci_indirect),
34631+ "r" (__PCIBIOS_DS));
34632 break;
34633 }
34634
34635@@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
34636
34637 switch (len) {
34638 case 1:
34639- __asm__("lcall *(%%esi); cld\n\t"
34640+ __asm__("movw %w6, %%ds\n\t"
34641+ "lcall *%%ss:(%%esi); cld\n\t"
34642+ "push %%ss\n\t"
34643+ "pop %%ds\n\t"
34644 "jc 1f\n\t"
34645 "xor %%ah, %%ah\n"
34646 "1:"
34647@@ -265,10 +326,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
34648 "c" (value),
34649 "b" (bx),
34650 "D" ((long)reg),
34651- "S" (&pci_indirect));
34652+ "S" (&pci_indirect),
34653+ "r" (__PCIBIOS_DS));
34654 break;
34655 case 2:
34656- __asm__("lcall *(%%esi); cld\n\t"
34657+ __asm__("movw %w6, %%ds\n\t"
34658+ "lcall *%%ss:(%%esi); cld\n\t"
34659+ "push %%ss\n\t"
34660+ "pop %%ds\n\t"
34661 "jc 1f\n\t"
34662 "xor %%ah, %%ah\n"
34663 "1:"
34664@@ -277,10 +342,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
34665 "c" (value),
34666 "b" (bx),
34667 "D" ((long)reg),
34668- "S" (&pci_indirect));
34669+ "S" (&pci_indirect),
34670+ "r" (__PCIBIOS_DS));
34671 break;
34672 case 4:
34673- __asm__("lcall *(%%esi); cld\n\t"
34674+ __asm__("movw %w6, %%ds\n\t"
34675+ "lcall *%%ss:(%%esi); cld\n\t"
34676+ "push %%ss\n\t"
34677+ "pop %%ds\n\t"
34678 "jc 1f\n\t"
34679 "xor %%ah, %%ah\n"
34680 "1:"
34681@@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
34682 "c" (value),
34683 "b" (bx),
34684 "D" ((long)reg),
34685- "S" (&pci_indirect));
34686+ "S" (&pci_indirect),
34687+ "r" (__PCIBIOS_DS));
34688 break;
34689 }
34690
34691@@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
34692
34693 DBG("PCI: Fetching IRQ routing table... ");
34694 __asm__("push %%es\n\t"
34695+ "movw %w8, %%ds\n\t"
34696 "push %%ds\n\t"
34697 "pop %%es\n\t"
34698- "lcall *(%%esi); cld\n\t"
34699+ "lcall *%%ss:(%%esi); cld\n\t"
34700 "pop %%es\n\t"
34701+ "push %%ss\n\t"
34702+ "pop %%ds\n"
34703 "jc 1f\n\t"
34704 "xor %%ah, %%ah\n"
34705 "1:"
34706@@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
34707 "1" (0),
34708 "D" ((long) &opt),
34709 "S" (&pci_indirect),
34710- "m" (opt)
34711+ "m" (opt),
34712+ "r" (__PCIBIOS_DS)
34713 : "memory");
34714 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
34715 if (ret & 0xff00)
34716@@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
34717 {
34718 int ret;
34719
34720- __asm__("lcall *(%%esi); cld\n\t"
34721+ __asm__("movw %w5, %%ds\n\t"
34722+ "lcall *%%ss:(%%esi); cld\n\t"
34723+ "push %%ss\n\t"
34724+ "pop %%ds\n"
34725 "jc 1f\n\t"
34726 "xor %%ah, %%ah\n"
34727 "1:"
34728@@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
34729 : "0" (PCIBIOS_SET_PCI_HW_INT),
34730 "b" ((dev->bus->number << 8) | dev->devfn),
34731 "c" ((irq << 8) | (pin + 10)),
34732- "S" (&pci_indirect));
34733+ "S" (&pci_indirect),
34734+ "r" (__PCIBIOS_DS));
34735 return !(ret & 0xff00);
34736 }
34737 EXPORT_SYMBOL(pcibios_set_irq_routing);
34738diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
34739index 40e7cda..c7e6672 100644
34740--- a/arch/x86/platform/efi/efi_32.c
34741+++ b/arch/x86/platform/efi/efi_32.c
34742@@ -61,11 +61,22 @@ void __init efi_call_phys_prolog(void)
34743 {
34744 struct desc_ptr gdt_descr;
34745
34746+#ifdef CONFIG_PAX_KERNEXEC
34747+ struct desc_struct d;
34748+#endif
34749+
34750 local_irq_save(efi_rt_eflags);
34751
34752 load_cr3(initial_page_table);
34753 __flush_tlb_all();
34754
34755+#ifdef CONFIG_PAX_KERNEXEC
34756+ pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
34757+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
34758+ pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
34759+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
34760+#endif
34761+
34762 gdt_descr.address = __pa(get_cpu_gdt_table(0));
34763 gdt_descr.size = GDT_SIZE - 1;
34764 load_gdt(&gdt_descr);
34765@@ -75,11 +86,24 @@ void __init efi_call_phys_epilog(void)
34766 {
34767 struct desc_ptr gdt_descr;
34768
34769+#ifdef CONFIG_PAX_KERNEXEC
34770+ struct desc_struct d;
34771+
34772+ memset(&d, 0, sizeof d);
34773+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
34774+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
34775+#endif
34776+
34777 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
34778 gdt_descr.size = GDT_SIZE - 1;
34779 load_gdt(&gdt_descr);
34780
34781+#ifdef CONFIG_PAX_PER_CPU_PGD
34782+ load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
34783+#else
34784 load_cr3(swapper_pg_dir);
34785+#endif
34786+
34787 __flush_tlb_all();
34788
34789 local_irq_restore(efi_rt_eflags);
34790diff --git a/arch/x86/platform/efi/efi_64.c b/arch/x86/platform/efi/efi_64.c
34791index 35aecb6..46177db 100644
34792--- a/arch/x86/platform/efi/efi_64.c
34793+++ b/arch/x86/platform/efi/efi_64.c
34794@@ -99,6 +99,11 @@ void __init efi_call_phys_prolog(void)
34795 vaddress = (unsigned long)__va(pgd * PGDIR_SIZE);
34796 set_pgd(pgd_offset_k(pgd * PGDIR_SIZE), *pgd_offset_k(vaddress));
34797 }
34798+
34799+#ifdef CONFIG_PAX_PER_CPU_PGD
34800+ load_cr3(swapper_pg_dir);
34801+#endif
34802+
34803 __flush_tlb_all();
34804 }
34805
34806@@ -116,6 +121,11 @@ void __init efi_call_phys_epilog(void)
34807 for (pgd = 0; pgd < n_pgds; pgd++)
34808 set_pgd(pgd_offset_k(pgd * PGDIR_SIZE), save_pgd[pgd]);
34809 kfree(save_pgd);
34810+
34811+#ifdef CONFIG_PAX_PER_CPU_PGD
34812+ load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
34813+#endif
34814+
34815 __flush_tlb_all();
34816 local_irq_restore(efi_flags);
34817 early_code_mapping_set_exec(0);
34818@@ -146,8 +156,23 @@ int __init efi_setup_page_tables(unsigned long pa_memmap, unsigned num_pages)
34819 unsigned npages;
34820 pgd_t *pgd;
34821
34822- if (efi_enabled(EFI_OLD_MEMMAP))
34823+ if (efi_enabled(EFI_OLD_MEMMAP)) {
34824+ /* PaX: We need to disable the NX bit in the PGD, otherwise we won't be
34825+ * able to execute the EFI services.
34826+ */
34827+ if (__supported_pte_mask & _PAGE_NX) {
34828+ unsigned long addr = (unsigned long) __va(0);
34829+ pgd_t pe = __pgd(pgd_val(*pgd_offset_k(addr)) & ~_PAGE_NX);
34830+
34831+ pr_alert("PAX: Disabling NX protection for low memory map. Try booting without \"efi=old_map\"\n");
34832+#ifdef CONFIG_PAX_PER_CPU_PGD
34833+ set_pgd(pgd_offset_cpu(0, kernel, addr), pe);
34834+#endif
34835+ set_pgd(pgd_offset_k(addr), pe);
34836+ }
34837+
34838 return 0;
34839+ }
34840
34841 efi_scratch.efi_pgt = (pgd_t *)(unsigned long)real_mode_header->trampoline_pgd;
34842 pgd = __va(efi_scratch.efi_pgt);
34843diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
34844index 040192b..7d3300f 100644
34845--- a/arch/x86/platform/efi/efi_stub_32.S
34846+++ b/arch/x86/platform/efi/efi_stub_32.S
34847@@ -6,7 +6,9 @@
34848 */
34849
34850 #include <linux/linkage.h>
34851+#include <linux/init.h>
34852 #include <asm/page_types.h>
34853+#include <asm/segment.h>
34854
34855 /*
34856 * efi_call_phys(void *, ...) is a function with variable parameters.
34857@@ -20,7 +22,7 @@
34858 * service functions will comply with gcc calling convention, too.
34859 */
34860
34861-.text
34862+__INIT
34863 ENTRY(efi_call_phys)
34864 /*
34865 * 0. The function can only be called in Linux kernel. So CS has been
34866@@ -36,10 +38,24 @@ ENTRY(efi_call_phys)
34867 * The mapping of lower virtual memory has been created in prolog and
34868 * epilog.
34869 */
34870- movl $1f, %edx
34871- subl $__PAGE_OFFSET, %edx
34872- jmp *%edx
34873+#ifdef CONFIG_PAX_KERNEXEC
34874+ movl $(__KERNEXEC_EFI_DS), %edx
34875+ mov %edx, %ds
34876+ mov %edx, %es
34877+ mov %edx, %ss
34878+ addl $2f,(1f)
34879+ ljmp *(1f)
34880+
34881+__INITDATA
34882+1: .long __LOAD_PHYSICAL_ADDR, __KERNEXEC_EFI_CS
34883+.previous
34884+
34885+2:
34886+ subl $2b,(1b)
34887+#else
34888+ jmp 1f-__PAGE_OFFSET
34889 1:
34890+#endif
34891
34892 /*
34893 * 2. Now on the top of stack is the return
34894@@ -47,14 +63,8 @@ ENTRY(efi_call_phys)
34895 * parameter 2, ..., param n. To make things easy, we save the return
34896 * address of efi_call_phys in a global variable.
34897 */
34898- popl %edx
34899- movl %edx, saved_return_addr
34900- /* get the function pointer into ECX*/
34901- popl %ecx
34902- movl %ecx, efi_rt_function_ptr
34903- movl $2f, %edx
34904- subl $__PAGE_OFFSET, %edx
34905- pushl %edx
34906+ popl (saved_return_addr)
34907+ popl (efi_rt_function_ptr)
34908
34909 /*
34910 * 3. Clear PG bit in %CR0.
34911@@ -73,9 +83,8 @@ ENTRY(efi_call_phys)
34912 /*
34913 * 5. Call the physical function.
34914 */
34915- jmp *%ecx
34916+ call *(efi_rt_function_ptr-__PAGE_OFFSET)
34917
34918-2:
34919 /*
34920 * 6. After EFI runtime service returns, control will return to
34921 * following instruction. We'd better readjust stack pointer first.
34922@@ -88,35 +97,36 @@ ENTRY(efi_call_phys)
34923 movl %cr0, %edx
34924 orl $0x80000000, %edx
34925 movl %edx, %cr0
34926- jmp 1f
34927-1:
34928+
34929 /*
34930 * 8. Now restore the virtual mode from flat mode by
34931 * adding EIP with PAGE_OFFSET.
34932 */
34933- movl $1f, %edx
34934- jmp *%edx
34935+#ifdef CONFIG_PAX_KERNEXEC
34936+ movl $(__KERNEL_DS), %edx
34937+ mov %edx, %ds
34938+ mov %edx, %es
34939+ mov %edx, %ss
34940+ ljmp $(__KERNEL_CS),$1f
34941+#else
34942+ jmp 1f+__PAGE_OFFSET
34943+#endif
34944 1:
34945
34946 /*
34947 * 9. Balance the stack. And because EAX contain the return value,
34948 * we'd better not clobber it.
34949 */
34950- leal efi_rt_function_ptr, %edx
34951- movl (%edx), %ecx
34952- pushl %ecx
34953+ pushl (efi_rt_function_ptr)
34954
34955 /*
34956- * 10. Push the saved return address onto the stack and return.
34957+ * 10. Return to the saved return address.
34958 */
34959- leal saved_return_addr, %edx
34960- movl (%edx), %ecx
34961- pushl %ecx
34962- ret
34963+ jmpl *(saved_return_addr)
34964 ENDPROC(efi_call_phys)
34965 .previous
34966
34967-.data
34968+__INITDATA
34969 saved_return_addr:
34970 .long 0
34971 efi_rt_function_ptr:
34972diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
34973index 5fcda72..cd4dc41 100644
34974--- a/arch/x86/platform/efi/efi_stub_64.S
34975+++ b/arch/x86/platform/efi/efi_stub_64.S
34976@@ -11,6 +11,7 @@
34977 #include <asm/msr.h>
34978 #include <asm/processor-flags.h>
34979 #include <asm/page_types.h>
34980+#include <asm/alternative-asm.h>
34981
34982 #define SAVE_XMM \
34983 mov %rsp, %rax; \
34984@@ -88,6 +89,7 @@ ENTRY(efi_call)
34985 RESTORE_PGT
34986 addq $48, %rsp
34987 RESTORE_XMM
34988+ pax_force_retaddr 0, 1
34989 ret
34990 ENDPROC(efi_call)
34991
34992@@ -245,8 +247,8 @@ efi_gdt64:
34993 .long 0 /* Filled out by user */
34994 .word 0
34995 .quad 0x0000000000000000 /* NULL descriptor */
34996- .quad 0x00af9a000000ffff /* __KERNEL_CS */
34997- .quad 0x00cf92000000ffff /* __KERNEL_DS */
34998+ .quad 0x00af9b000000ffff /* __KERNEL_CS */
34999+ .quad 0x00cf93000000ffff /* __KERNEL_DS */
35000 .quad 0x0080890000000000 /* TS descriptor */
35001 .quad 0x0000000000000000 /* TS continued */
35002 efi_gdt64_end:
35003diff --git a/arch/x86/platform/intel-mid/intel-mid.c b/arch/x86/platform/intel-mid/intel-mid.c
35004index 1bbedc4..eb795b5 100644
35005--- a/arch/x86/platform/intel-mid/intel-mid.c
35006+++ b/arch/x86/platform/intel-mid/intel-mid.c
35007@@ -71,9 +71,10 @@ static void intel_mid_power_off(void)
35008 {
35009 };
35010
35011-static void intel_mid_reboot(void)
35012+static void __noreturn intel_mid_reboot(void)
35013 {
35014 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
35015+ BUG();
35016 }
35017
35018 static unsigned long __init intel_mid_calibrate_tsc(void)
35019diff --git a/arch/x86/platform/intel-mid/intel_mid_weak_decls.h b/arch/x86/platform/intel-mid/intel_mid_weak_decls.h
35020index 3c1c386..59a68ed 100644
35021--- a/arch/x86/platform/intel-mid/intel_mid_weak_decls.h
35022+++ b/arch/x86/platform/intel-mid/intel_mid_weak_decls.h
35023@@ -13,6 +13,6 @@
35024 /* For every CPU addition a new get_<cpuname>_ops interface needs
35025 * to be added.
35026 */
35027-extern void *get_penwell_ops(void);
35028-extern void *get_cloverview_ops(void);
35029-extern void *get_tangier_ops(void);
35030+extern const void *get_penwell_ops(void);
35031+extern const void *get_cloverview_ops(void);
35032+extern const void *get_tangier_ops(void);
35033diff --git a/arch/x86/platform/intel-mid/mfld.c b/arch/x86/platform/intel-mid/mfld.c
35034index 23381d2..8ddc10e 100644
35035--- a/arch/x86/platform/intel-mid/mfld.c
35036+++ b/arch/x86/platform/intel-mid/mfld.c
35037@@ -64,12 +64,12 @@ static void __init penwell_arch_setup(void)
35038 pm_power_off = mfld_power_off;
35039 }
35040
35041-void *get_penwell_ops(void)
35042+const void *get_penwell_ops(void)
35043 {
35044 return &penwell_ops;
35045 }
35046
35047-void *get_cloverview_ops(void)
35048+const void *get_cloverview_ops(void)
35049 {
35050 return &penwell_ops;
35051 }
35052diff --git a/arch/x86/platform/intel-mid/mrfl.c b/arch/x86/platform/intel-mid/mrfl.c
35053index aaca917..66eadbc 100644
35054--- a/arch/x86/platform/intel-mid/mrfl.c
35055+++ b/arch/x86/platform/intel-mid/mrfl.c
35056@@ -97,7 +97,7 @@ static struct intel_mid_ops tangier_ops = {
35057 .arch_setup = tangier_arch_setup,
35058 };
35059
35060-void *get_tangier_ops(void)
35061+const void *get_tangier_ops(void)
35062 {
35063 return &tangier_ops;
35064 }
35065diff --git a/arch/x86/platform/olpc/olpc_dt.c b/arch/x86/platform/olpc/olpc_dt.c
35066index d6ee929..3637cb5 100644
35067--- a/arch/x86/platform/olpc/olpc_dt.c
35068+++ b/arch/x86/platform/olpc/olpc_dt.c
35069@@ -156,7 +156,7 @@ void * __init prom_early_alloc(unsigned long size)
35070 return res;
35071 }
35072
35073-static struct of_pdt_ops prom_olpc_ops __initdata = {
35074+static struct of_pdt_ops prom_olpc_ops __initconst = {
35075 .nextprop = olpc_dt_nextprop,
35076 .getproplen = olpc_dt_getproplen,
35077 .getproperty = olpc_dt_getproperty,
35078diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
35079index 6ec7910..ecdbb11 100644
35080--- a/arch/x86/power/cpu.c
35081+++ b/arch/x86/power/cpu.c
35082@@ -137,11 +137,8 @@ static void do_fpu_end(void)
35083 static void fix_processor_context(void)
35084 {
35085 int cpu = smp_processor_id();
35086- struct tss_struct *t = &per_cpu(init_tss, cpu);
35087-#ifdef CONFIG_X86_64
35088- struct desc_struct *desc = get_cpu_gdt_table(cpu);
35089- tss_desc tss;
35090-#endif
35091+ struct tss_struct *t = init_tss + cpu;
35092+
35093 set_tss_desc(cpu, t); /*
35094 * This just modifies memory; should not be
35095 * necessary. But... This is necessary, because
35096@@ -150,10 +147,6 @@ static void fix_processor_context(void)
35097 */
35098
35099 #ifdef CONFIG_X86_64
35100- memcpy(&tss, &desc[GDT_ENTRY_TSS], sizeof(tss_desc));
35101- tss.type = 0x9; /* The available 64-bit TSS (see AMD vol 2, pg 91 */
35102- write_gdt_entry(desc, GDT_ENTRY_TSS, &tss, DESC_TSS);
35103-
35104 syscall_init(); /* This sets MSR_*STAR and related */
35105 #endif
35106 load_TR_desc(); /* This does ltr */
35107diff --git a/arch/x86/realmode/init.c b/arch/x86/realmode/init.c
35108index bad628a..a102610 100644
35109--- a/arch/x86/realmode/init.c
35110+++ b/arch/x86/realmode/init.c
35111@@ -68,7 +68,13 @@ void __init setup_real_mode(void)
35112 __va(real_mode_header->trampoline_header);
35113
35114 #ifdef CONFIG_X86_32
35115- trampoline_header->start = __pa_symbol(startup_32_smp);
35116+ trampoline_header->start = __pa_symbol(ktla_ktva(startup_32_smp));
35117+
35118+#ifdef CONFIG_PAX_KERNEXEC
35119+ trampoline_header->start -= LOAD_PHYSICAL_ADDR;
35120+#endif
35121+
35122+ trampoline_header->boot_cs = __BOOT_CS;
35123 trampoline_header->gdt_limit = __BOOT_DS + 7;
35124 trampoline_header->gdt_base = __pa_symbol(boot_gdt);
35125 #else
35126@@ -84,7 +90,7 @@ void __init setup_real_mode(void)
35127 *trampoline_cr4_features = read_cr4();
35128
35129 trampoline_pgd = (u64 *) __va(real_mode_header->trampoline_pgd);
35130- trampoline_pgd[0] = init_level4_pgt[pgd_index(__PAGE_OFFSET)].pgd;
35131+ trampoline_pgd[0] = init_level4_pgt[pgd_index(__PAGE_OFFSET)].pgd & ~_PAGE_NX;
35132 trampoline_pgd[511] = init_level4_pgt[511].pgd;
35133 #endif
35134 }
35135diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile
35136index 7c0d7be..d24dc88 100644
35137--- a/arch/x86/realmode/rm/Makefile
35138+++ b/arch/x86/realmode/rm/Makefile
35139@@ -67,5 +67,8 @@ $(obj)/realmode.relocs: $(obj)/realmode.elf FORCE
35140
35141 KBUILD_CFLAGS := $(LINUXINCLUDE) $(REALMODE_CFLAGS) -D_SETUP -D_WAKEUP \
35142 -I$(srctree)/arch/x86/boot
35143+ifdef CONSTIFY_PLUGIN
35144+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
35145+endif
35146 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
35147 GCOV_PROFILE := n
35148diff --git a/arch/x86/realmode/rm/header.S b/arch/x86/realmode/rm/header.S
35149index a28221d..93c40f1 100644
35150--- a/arch/x86/realmode/rm/header.S
35151+++ b/arch/x86/realmode/rm/header.S
35152@@ -30,7 +30,9 @@ GLOBAL(real_mode_header)
35153 #endif
35154 /* APM/BIOS reboot */
35155 .long pa_machine_real_restart_asm
35156-#ifdef CONFIG_X86_64
35157+#ifdef CONFIG_X86_32
35158+ .long __KERNEL_CS
35159+#else
35160 .long __KERNEL32_CS
35161 #endif
35162 END(real_mode_header)
35163diff --git a/arch/x86/realmode/rm/trampoline_32.S b/arch/x86/realmode/rm/trampoline_32.S
35164index 48ddd76..c26749f 100644
35165--- a/arch/x86/realmode/rm/trampoline_32.S
35166+++ b/arch/x86/realmode/rm/trampoline_32.S
35167@@ -24,6 +24,12 @@
35168 #include <asm/page_types.h>
35169 #include "realmode.h"
35170
35171+#ifdef CONFIG_PAX_KERNEXEC
35172+#define ta(X) (X)
35173+#else
35174+#define ta(X) (pa_ ## X)
35175+#endif
35176+
35177 .text
35178 .code16
35179
35180@@ -38,8 +44,6 @@ ENTRY(trampoline_start)
35181
35182 cli # We should be safe anyway
35183
35184- movl tr_start, %eax # where we need to go
35185-
35186 movl $0xA5A5A5A5, trampoline_status
35187 # write marker for master knows we're running
35188
35189@@ -55,7 +59,7 @@ ENTRY(trampoline_start)
35190 movw $1, %dx # protected mode (PE) bit
35191 lmsw %dx # into protected mode
35192
35193- ljmpl $__BOOT_CS, $pa_startup_32
35194+ ljmpl *(trampoline_header)
35195
35196 .section ".text32","ax"
35197 .code32
35198@@ -66,7 +70,7 @@ ENTRY(startup_32) # note: also used from wakeup_asm.S
35199 .balign 8
35200 GLOBAL(trampoline_header)
35201 tr_start: .space 4
35202- tr_gdt_pad: .space 2
35203+ tr_boot_cs: .space 2
35204 tr_gdt: .space 6
35205 END(trampoline_header)
35206
35207diff --git a/arch/x86/realmode/rm/trampoline_64.S b/arch/x86/realmode/rm/trampoline_64.S
35208index dac7b20..72dbaca 100644
35209--- a/arch/x86/realmode/rm/trampoline_64.S
35210+++ b/arch/x86/realmode/rm/trampoline_64.S
35211@@ -93,6 +93,7 @@ ENTRY(startup_32)
35212 movl %edx, %gs
35213
35214 movl pa_tr_cr4, %eax
35215+ andl $~X86_CR4_PCIDE, %eax
35216 movl %eax, %cr4 # Enable PAE mode
35217
35218 # Setup trampoline 4 level pagetables
35219@@ -106,7 +107,7 @@ ENTRY(startup_32)
35220 wrmsr
35221
35222 # Enable paging and in turn activate Long Mode
35223- movl $(X86_CR0_PG | X86_CR0_WP | X86_CR0_PE), %eax
35224+ movl $(X86_CR0_PG | X86_CR0_PE), %eax
35225 movl %eax, %cr0
35226
35227 /*
35228diff --git a/arch/x86/realmode/rm/wakeup_asm.S b/arch/x86/realmode/rm/wakeup_asm.S
35229index 9e7e147..25a4158 100644
35230--- a/arch/x86/realmode/rm/wakeup_asm.S
35231+++ b/arch/x86/realmode/rm/wakeup_asm.S
35232@@ -126,11 +126,10 @@ ENTRY(wakeup_start)
35233 lgdtl pmode_gdt
35234
35235 /* This really couldn't... */
35236- movl pmode_entry, %eax
35237 movl pmode_cr0, %ecx
35238 movl %ecx, %cr0
35239- ljmpl $__KERNEL_CS, $pa_startup_32
35240- /* -> jmp *%eax in trampoline_32.S */
35241+
35242+ ljmpl *pmode_entry
35243 #else
35244 jmp trampoline_start
35245 #endif
35246diff --git a/arch/x86/tools/Makefile b/arch/x86/tools/Makefile
35247index 604a37e..e49702a 100644
35248--- a/arch/x86/tools/Makefile
35249+++ b/arch/x86/tools/Makefile
35250@@ -37,7 +37,7 @@ $(obj)/test_get_len.o: $(srctree)/arch/x86/lib/insn.c $(srctree)/arch/x86/lib/in
35251
35252 $(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
35253
35254-HOST_EXTRACFLAGS += -I$(srctree)/tools/include
35255+HOST_EXTRACFLAGS += -I$(srctree)/tools/include -ggdb
35256 hostprogs-y += relocs
35257 relocs-objs := relocs_32.o relocs_64.o relocs_common.o
35258 PHONY += relocs
35259diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c
35260index a5efb21..97490e9 100644
35261--- a/arch/x86/tools/relocs.c
35262+++ b/arch/x86/tools/relocs.c
35263@@ -1,5 +1,7 @@
35264 /* This is included from relocs_32/64.c */
35265
35266+#include "../../../include/generated/autoconf.h"
35267+
35268 #define ElfW(type) _ElfW(ELF_BITS, type)
35269 #define _ElfW(bits, type) __ElfW(bits, type)
35270 #define __ElfW(bits, type) Elf##bits##_##type
35271@@ -11,6 +13,7 @@
35272 #define Elf_Sym ElfW(Sym)
35273
35274 static Elf_Ehdr ehdr;
35275+static Elf_Phdr *phdr;
35276
35277 struct relocs {
35278 uint32_t *offset;
35279@@ -383,9 +386,39 @@ static void read_ehdr(FILE *fp)
35280 }
35281 }
35282
35283+static void read_phdrs(FILE *fp)
35284+{
35285+ unsigned int i;
35286+
35287+ phdr = calloc(ehdr.e_phnum, sizeof(Elf_Phdr));
35288+ if (!phdr) {
35289+ die("Unable to allocate %d program headers\n",
35290+ ehdr.e_phnum);
35291+ }
35292+ if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
35293+ die("Seek to %d failed: %s\n",
35294+ ehdr.e_phoff, strerror(errno));
35295+ }
35296+ if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
35297+ die("Cannot read ELF program headers: %s\n",
35298+ strerror(errno));
35299+ }
35300+ for(i = 0; i < ehdr.e_phnum; i++) {
35301+ phdr[i].p_type = elf_word_to_cpu(phdr[i].p_type);
35302+ phdr[i].p_offset = elf_off_to_cpu(phdr[i].p_offset);
35303+ phdr[i].p_vaddr = elf_addr_to_cpu(phdr[i].p_vaddr);
35304+ phdr[i].p_paddr = elf_addr_to_cpu(phdr[i].p_paddr);
35305+ phdr[i].p_filesz = elf_word_to_cpu(phdr[i].p_filesz);
35306+ phdr[i].p_memsz = elf_word_to_cpu(phdr[i].p_memsz);
35307+ phdr[i].p_flags = elf_word_to_cpu(phdr[i].p_flags);
35308+ phdr[i].p_align = elf_word_to_cpu(phdr[i].p_align);
35309+ }
35310+
35311+}
35312+
35313 static void read_shdrs(FILE *fp)
35314 {
35315- int i;
35316+ unsigned int i;
35317 Elf_Shdr shdr;
35318
35319 secs = calloc(ehdr.e_shnum, sizeof(struct section));
35320@@ -420,7 +453,7 @@ static void read_shdrs(FILE *fp)
35321
35322 static void read_strtabs(FILE *fp)
35323 {
35324- int i;
35325+ unsigned int i;
35326 for (i = 0; i < ehdr.e_shnum; i++) {
35327 struct section *sec = &secs[i];
35328 if (sec->shdr.sh_type != SHT_STRTAB) {
35329@@ -445,7 +478,7 @@ static void read_strtabs(FILE *fp)
35330
35331 static void read_symtabs(FILE *fp)
35332 {
35333- int i,j;
35334+ unsigned int i,j;
35335 for (i = 0; i < ehdr.e_shnum; i++) {
35336 struct section *sec = &secs[i];
35337 if (sec->shdr.sh_type != SHT_SYMTAB) {
35338@@ -476,9 +509,11 @@ static void read_symtabs(FILE *fp)
35339 }
35340
35341
35342-static void read_relocs(FILE *fp)
35343+static void read_relocs(FILE *fp, int use_real_mode)
35344 {
35345- int i,j;
35346+ unsigned int i,j;
35347+ uint32_t base;
35348+
35349 for (i = 0; i < ehdr.e_shnum; i++) {
35350 struct section *sec = &secs[i];
35351 if (sec->shdr.sh_type != SHT_REL_TYPE) {
35352@@ -498,9 +533,22 @@ static void read_relocs(FILE *fp)
35353 die("Cannot read symbol table: %s\n",
35354 strerror(errno));
35355 }
35356+ base = 0;
35357+
35358+#ifdef CONFIG_X86_32
35359+ for (j = 0; !use_real_mode && j < ehdr.e_phnum; j++) {
35360+ if (phdr[j].p_type != PT_LOAD )
35361+ continue;
35362+ 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)
35363+ continue;
35364+ base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
35365+ break;
35366+ }
35367+#endif
35368+
35369 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf_Rel); j++) {
35370 Elf_Rel *rel = &sec->reltab[j];
35371- rel->r_offset = elf_addr_to_cpu(rel->r_offset);
35372+ rel->r_offset = elf_addr_to_cpu(rel->r_offset) + base;
35373 rel->r_info = elf_xword_to_cpu(rel->r_info);
35374 #if (SHT_REL_TYPE == SHT_RELA)
35375 rel->r_addend = elf_xword_to_cpu(rel->r_addend);
35376@@ -512,7 +560,7 @@ static void read_relocs(FILE *fp)
35377
35378 static void print_absolute_symbols(void)
35379 {
35380- int i;
35381+ unsigned int i;
35382 const char *format;
35383
35384 if (ELF_BITS == 64)
35385@@ -525,7 +573,7 @@ static void print_absolute_symbols(void)
35386 for (i = 0; i < ehdr.e_shnum; i++) {
35387 struct section *sec = &secs[i];
35388 char *sym_strtab;
35389- int j;
35390+ unsigned int j;
35391
35392 if (sec->shdr.sh_type != SHT_SYMTAB) {
35393 continue;
35394@@ -552,7 +600,7 @@ static void print_absolute_symbols(void)
35395
35396 static void print_absolute_relocs(void)
35397 {
35398- int i, printed = 0;
35399+ unsigned int i, printed = 0;
35400 const char *format;
35401
35402 if (ELF_BITS == 64)
35403@@ -565,7 +613,7 @@ static void print_absolute_relocs(void)
35404 struct section *sec_applies, *sec_symtab;
35405 char *sym_strtab;
35406 Elf_Sym *sh_symtab;
35407- int j;
35408+ unsigned int j;
35409 if (sec->shdr.sh_type != SHT_REL_TYPE) {
35410 continue;
35411 }
35412@@ -642,13 +690,13 @@ static void add_reloc(struct relocs *r, uint32_t offset)
35413 static void walk_relocs(int (*process)(struct section *sec, Elf_Rel *rel,
35414 Elf_Sym *sym, const char *symname))
35415 {
35416- int i;
35417+ unsigned int i;
35418 /* Walk through the relocations */
35419 for (i = 0; i < ehdr.e_shnum; i++) {
35420 char *sym_strtab;
35421 Elf_Sym *sh_symtab;
35422 struct section *sec_applies, *sec_symtab;
35423- int j;
35424+ unsigned int j;
35425 struct section *sec = &secs[i];
35426
35427 if (sec->shdr.sh_type != SHT_REL_TYPE) {
35428@@ -822,6 +870,23 @@ static int do_reloc32(struct section *sec, Elf_Rel *rel, Elf_Sym *sym,
35429 {
35430 unsigned r_type = ELF32_R_TYPE(rel->r_info);
35431 int shn_abs = (sym->st_shndx == SHN_ABS) && !is_reloc(S_REL, symname);
35432+ char *sym_strtab = sec->link->link->strtab;
35433+
35434+ /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
35435+ if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
35436+ return 0;
35437+
35438+#ifdef CONFIG_PAX_KERNEXEC
35439+ /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
35440+ if (!strcmp(sec_name(sym->st_shndx), ".text.end") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
35441+ return 0;
35442+ if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
35443+ return 0;
35444+ if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
35445+ return 0;
35446+ if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
35447+ return 0;
35448+#endif
35449
35450 switch (r_type) {
35451 case R_386_NONE:
35452@@ -960,7 +1025,7 @@ static int write32_as_text(uint32_t v, FILE *f)
35453
35454 static void emit_relocs(int as_text, int use_real_mode)
35455 {
35456- int i;
35457+ unsigned int i;
35458 int (*write_reloc)(uint32_t, FILE *) = write32;
35459 int (*do_reloc)(struct section *sec, Elf_Rel *rel, Elf_Sym *sym,
35460 const char *symname);
35461@@ -1060,10 +1125,11 @@ void process(FILE *fp, int use_real_mode, int as_text,
35462 {
35463 regex_init(use_real_mode);
35464 read_ehdr(fp);
35465+ read_phdrs(fp);
35466 read_shdrs(fp);
35467 read_strtabs(fp);
35468 read_symtabs(fp);
35469- read_relocs(fp);
35470+ read_relocs(fp, use_real_mode);
35471 if (ELF_BITS == 64)
35472 percpu_init();
35473 if (show_absolute_syms) {
35474diff --git a/arch/x86/um/mem_32.c b/arch/x86/um/mem_32.c
35475index f40281e..92728c9 100644
35476--- a/arch/x86/um/mem_32.c
35477+++ b/arch/x86/um/mem_32.c
35478@@ -21,7 +21,7 @@ static int __init gate_vma_init(void)
35479 gate_vma.vm_start = FIXADDR_USER_START;
35480 gate_vma.vm_end = FIXADDR_USER_END;
35481 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
35482- gate_vma.vm_page_prot = __P101;
35483+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
35484
35485 return 0;
35486 }
35487diff --git a/arch/x86/um/tls_32.c b/arch/x86/um/tls_32.c
35488index 80ffa5b..a33bd15 100644
35489--- a/arch/x86/um/tls_32.c
35490+++ b/arch/x86/um/tls_32.c
35491@@ -260,7 +260,7 @@ out:
35492 if (unlikely(task == current &&
35493 !t->arch.tls_array[idx - GDT_ENTRY_TLS_MIN].flushed)) {
35494 printk(KERN_ERR "get_tls_entry: task with pid %d got here "
35495- "without flushed TLS.", current->pid);
35496+ "without flushed TLS.", task_pid_nr(current));
35497 }
35498
35499 return 0;
35500diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
35501index 5a4affe..9e2d522 100644
35502--- a/arch/x86/vdso/Makefile
35503+++ b/arch/x86/vdso/Makefile
35504@@ -174,7 +174,7 @@ quiet_cmd_vdso = VDSO $@
35505 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
35506 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
35507
35508-VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv) \
35509+VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv) \
35510 $(call cc-ldoption, -Wl$(comma)--build-id) -Wl,-Bsymbolic $(LTO_CFLAGS)
35511 GCOV_PROFILE := n
35512
35513diff --git a/arch/x86/vdso/vdso2c.h b/arch/x86/vdso/vdso2c.h
35514index 0224987..c7d65a5 100644
35515--- a/arch/x86/vdso/vdso2c.h
35516+++ b/arch/x86/vdso/vdso2c.h
35517@@ -12,7 +12,7 @@ static void BITSFUNC(go)(void *raw_addr, size_t raw_len,
35518 unsigned long load_size = -1; /* Work around bogus warning */
35519 unsigned long mapping_size;
35520 ELF(Ehdr) *hdr = (ELF(Ehdr) *)raw_addr;
35521- int i;
35522+ unsigned int i;
35523 unsigned long j;
35524 ELF(Shdr) *symtab_hdr = NULL, *strtab_hdr, *secstrings_hdr,
35525 *alt_sec = NULL;
35526diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
35527index e904c27..b9eaa03 100644
35528--- a/arch/x86/vdso/vdso32-setup.c
35529+++ b/arch/x86/vdso/vdso32-setup.c
35530@@ -14,6 +14,7 @@
35531 #include <asm/cpufeature.h>
35532 #include <asm/processor.h>
35533 #include <asm/vdso.h>
35534+#include <asm/mman.h>
35535
35536 #ifdef CONFIG_COMPAT_VDSO
35537 #define VDSO_DEFAULT 0
35538diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
35539index 970463b..da82d3e 100644
35540--- a/arch/x86/vdso/vma.c
35541+++ b/arch/x86/vdso/vma.c
35542@@ -16,10 +16,9 @@
35543 #include <asm/vdso.h>
35544 #include <asm/page.h>
35545 #include <asm/hpet.h>
35546+#include <asm/mman.h>
35547
35548 #if defined(CONFIG_X86_64)
35549-unsigned int __read_mostly vdso64_enabled = 1;
35550-
35551 extern unsigned short vdso_sync_cpuid;
35552 #endif
35553
35554@@ -101,6 +100,11 @@ static int map_vdso(const struct vdso_image *image, bool calculate_addr)
35555 .pages = no_pages,
35556 };
35557
35558+#ifdef CONFIG_PAX_RANDMMAP
35559+ if (mm->pax_flags & MF_PAX_RANDMMAP)
35560+ calculate_addr = false;
35561+#endif
35562+
35563 if (calculate_addr) {
35564 addr = vdso_addr(current->mm->start_stack,
35565 image->size - image->sym_vvar_start);
35566@@ -111,14 +115,14 @@ static int map_vdso(const struct vdso_image *image, bool calculate_addr)
35567 down_write(&mm->mmap_sem);
35568
35569 addr = get_unmapped_area(NULL, addr,
35570- image->size - image->sym_vvar_start, 0, 0);
35571+ image->size - image->sym_vvar_start, 0, MAP_EXECUTABLE);
35572 if (IS_ERR_VALUE(addr)) {
35573 ret = addr;
35574 goto up_fail;
35575 }
35576
35577 text_start = addr - image->sym_vvar_start;
35578- current->mm->context.vdso = (void __user *)text_start;
35579+ mm->context.vdso = text_start;
35580
35581 /*
35582 * MAYWRITE to allow gdb to COW and set breakpoints
35583@@ -163,15 +167,12 @@ static int map_vdso(const struct vdso_image *image, bool calculate_addr)
35584 hpet_address >> PAGE_SHIFT,
35585 PAGE_SIZE,
35586 pgprot_noncached(PAGE_READONLY));
35587-
35588- if (ret)
35589- goto up_fail;
35590 }
35591 #endif
35592
35593 up_fail:
35594 if (ret)
35595- current->mm->context.vdso = NULL;
35596+ current->mm->context.vdso = 0;
35597
35598 up_write(&mm->mmap_sem);
35599 return ret;
35600@@ -191,8 +192,8 @@ static int load_vdso32(void)
35601
35602 if (selected_vdso32->sym_VDSO32_SYSENTER_RETURN)
35603 current_thread_info()->sysenter_return =
35604- current->mm->context.vdso +
35605- selected_vdso32->sym_VDSO32_SYSENTER_RETURN;
35606+ (void __force_user *)(current->mm->context.vdso +
35607+ selected_vdso32->sym_VDSO32_SYSENTER_RETURN);
35608
35609 return 0;
35610 }
35611@@ -201,9 +202,6 @@ static int load_vdso32(void)
35612 #ifdef CONFIG_X86_64
35613 int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
35614 {
35615- if (!vdso64_enabled)
35616- return 0;
35617-
35618 return map_vdso(&vdso_image_64, true);
35619 }
35620
35621@@ -212,12 +210,8 @@ int compat_arch_setup_additional_pages(struct linux_binprm *bprm,
35622 int uses_interp)
35623 {
35624 #ifdef CONFIG_X86_X32_ABI
35625- if (test_thread_flag(TIF_X32)) {
35626- if (!vdso64_enabled)
35627- return 0;
35628-
35629+ if (test_thread_flag(TIF_X32))
35630 return map_vdso(&vdso_image_x32, true);
35631- }
35632 #endif
35633
35634 return load_vdso32();
35635@@ -229,12 +223,3 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
35636 return load_vdso32();
35637 }
35638 #endif
35639-
35640-#ifdef CONFIG_X86_64
35641-static __init int vdso_setup(char *s)
35642-{
35643- vdso64_enabled = simple_strtoul(s, NULL, 0);
35644- return 0;
35645-}
35646-__setup("vdso=", vdso_setup);
35647-#endif
35648diff --git a/arch/x86/xen/Kconfig b/arch/x86/xen/Kconfig
35649index e88fda8..76ce7ce 100644
35650--- a/arch/x86/xen/Kconfig
35651+++ b/arch/x86/xen/Kconfig
35652@@ -9,6 +9,7 @@ config XEN
35653 select XEN_HAVE_PVMMU
35654 depends on X86_64 || (X86_32 && X86_PAE)
35655 depends on X86_TSC
35656+ depends on !GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_VIRT_XEN
35657 help
35658 This is the Linux Xen port. Enabling this will allow the
35659 kernel to boot in a paravirtualized environment under the
35660diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
35661index fac5e4f..5b5cf4f 100644
35662--- a/arch/x86/xen/enlighten.c
35663+++ b/arch/x86/xen/enlighten.c
35664@@ -123,8 +123,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
35665
35666 struct shared_info xen_dummy_shared_info;
35667
35668-void *xen_initial_gdt;
35669-
35670 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
35671 __read_mostly int xen_have_vector_callback;
35672 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
35673@@ -542,8 +540,7 @@ static void xen_load_gdt(const struct desc_ptr *dtr)
35674 {
35675 unsigned long va = dtr->address;
35676 unsigned int size = dtr->size + 1;
35677- unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
35678- unsigned long frames[pages];
35679+ unsigned long frames[65536 / PAGE_SIZE];
35680 int f;
35681
35682 /*
35683@@ -591,8 +588,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
35684 {
35685 unsigned long va = dtr->address;
35686 unsigned int size = dtr->size + 1;
35687- unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
35688- unsigned long frames[pages];
35689+ unsigned long frames[(GDT_SIZE + PAGE_SIZE - 1) / PAGE_SIZE];
35690 int f;
35691
35692 /*
35693@@ -600,7 +596,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
35694 * 8-byte entries, or 16 4k pages..
35695 */
35696
35697- BUG_ON(size > 65536);
35698+ BUG_ON(size > GDT_SIZE);
35699 BUG_ON(va & ~PAGE_MASK);
35700
35701 for (f = 0; va < dtr->address + size; va += PAGE_SIZE, f++) {
35702@@ -989,7 +985,7 @@ static u32 xen_safe_apic_wait_icr_idle(void)
35703 return 0;
35704 }
35705
35706-static void set_xen_basic_apic_ops(void)
35707+static void __init set_xen_basic_apic_ops(void)
35708 {
35709 apic->read = xen_apic_read;
35710 apic->write = xen_apic_write;
35711@@ -1295,30 +1291,30 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
35712 #endif
35713 };
35714
35715-static void xen_reboot(int reason)
35716+static __noreturn void xen_reboot(int reason)
35717 {
35718 struct sched_shutdown r = { .reason = reason };
35719
35720- if (HYPERVISOR_sched_op(SCHEDOP_shutdown, &r))
35721- BUG();
35722+ HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
35723+ BUG();
35724 }
35725
35726-static void xen_restart(char *msg)
35727+static __noreturn void xen_restart(char *msg)
35728 {
35729 xen_reboot(SHUTDOWN_reboot);
35730 }
35731
35732-static void xen_emergency_restart(void)
35733+static __noreturn void xen_emergency_restart(void)
35734 {
35735 xen_reboot(SHUTDOWN_reboot);
35736 }
35737
35738-static void xen_machine_halt(void)
35739+static __noreturn void xen_machine_halt(void)
35740 {
35741 xen_reboot(SHUTDOWN_poweroff);
35742 }
35743
35744-static void xen_machine_power_off(void)
35745+static __noreturn void xen_machine_power_off(void)
35746 {
35747 if (pm_power_off)
35748 pm_power_off();
35749@@ -1573,7 +1569,17 @@ asmlinkage __visible void __init xen_start_kernel(void)
35750 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
35751
35752 /* Work out if we support NX */
35753- x86_configure_nx();
35754+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
35755+ if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
35756+ (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
35757+ unsigned l, h;
35758+
35759+ __supported_pte_mask |= _PAGE_NX;
35760+ rdmsr(MSR_EFER, l, h);
35761+ l |= EFER_NX;
35762+ wrmsr(MSR_EFER, l, h);
35763+ }
35764+#endif
35765
35766 /* Get mfn list */
35767 xen_build_dynamic_phys_to_machine();
35768@@ -1601,13 +1607,6 @@ asmlinkage __visible void __init xen_start_kernel(void)
35769
35770 machine_ops = xen_machine_ops;
35771
35772- /*
35773- * The only reliable way to retain the initial address of the
35774- * percpu gdt_page is to remember it here, so we can go and
35775- * mark it RW later, when the initial percpu area is freed.
35776- */
35777- xen_initial_gdt = &per_cpu(gdt_page, 0);
35778-
35779 xen_smp_init();
35780
35781 #ifdef CONFIG_ACPI_NUMA
35782diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
35783index a8a1a3d..8216142 100644
35784--- a/arch/x86/xen/mmu.c
35785+++ b/arch/x86/xen/mmu.c
35786@@ -379,7 +379,7 @@ static pteval_t pte_mfn_to_pfn(pteval_t val)
35787 return val;
35788 }
35789
35790-static pteval_t pte_pfn_to_mfn(pteval_t val)
35791+static pteval_t __intentional_overflow(-1) pte_pfn_to_mfn(pteval_t val)
35792 {
35793 if (val & _PAGE_PRESENT) {
35794 unsigned long pfn = (val & PTE_PFN_MASK) >> PAGE_SHIFT;
35795@@ -1867,7 +1867,11 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
35796 * L3_k[511] -> level2_fixmap_pgt */
35797 convert_pfn_mfn(level3_kernel_pgt);
35798
35799+ convert_pfn_mfn(level3_vmalloc_start_pgt);
35800+ convert_pfn_mfn(level3_vmalloc_end_pgt);
35801+ convert_pfn_mfn(level3_vmemmap_pgt);
35802 /* L3_k[511][506] -> level1_fixmap_pgt */
35803+ /* L3_k[511][507] -> level1_vsyscall_pgt */
35804 convert_pfn_mfn(level2_fixmap_pgt);
35805 }
35806 /* We get [511][511] and have Xen's version of level2_kernel_pgt */
35807@@ -1892,11 +1896,16 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
35808 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
35809 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
35810 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
35811+ set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
35812+ set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
35813+ set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
35814 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
35815 set_page_prot(level2_ident_pgt, PAGE_KERNEL_RO);
35816+ set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
35817 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
35818 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
35819 set_page_prot(level1_fixmap_pgt, PAGE_KERNEL_RO);
35820+ set_page_prot(level1_vsyscall_pgt, PAGE_KERNEL_RO);
35821
35822 /* Pin down new L4 */
35823 pin_pagetable_pfn(MMUEXT_PIN_L4_TABLE,
35824@@ -2080,6 +2089,7 @@ static void __init xen_post_allocator_init(void)
35825 pv_mmu_ops.set_pud = xen_set_pud;
35826 #if PAGETABLE_LEVELS == 4
35827 pv_mmu_ops.set_pgd = xen_set_pgd;
35828+ pv_mmu_ops.set_pgd_batched = xen_set_pgd;
35829 #endif
35830
35831 /* This will work as long as patching hasn't happened yet
35832@@ -2158,6 +2168,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
35833 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
35834 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
35835 .set_pgd = xen_set_pgd_hyper,
35836+ .set_pgd_batched = xen_set_pgd_hyper,
35837
35838 .alloc_pud = xen_alloc_pmd_init,
35839 .release_pud = xen_release_pmd_init,
35840diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
35841index 4c071ae..00e7049 100644
35842--- a/arch/x86/xen/smp.c
35843+++ b/arch/x86/xen/smp.c
35844@@ -288,17 +288,13 @@ static void __init xen_smp_prepare_boot_cpu(void)
35845
35846 if (xen_pv_domain()) {
35847 if (!xen_feature(XENFEAT_writable_page_tables))
35848- /* We've switched to the "real" per-cpu gdt, so make
35849- * sure the old memory can be recycled. */
35850- make_lowmem_page_readwrite(xen_initial_gdt);
35851-
35852 #ifdef CONFIG_X86_32
35853 /*
35854 * Xen starts us with XEN_FLAT_RING1_DS, but linux code
35855 * expects __USER_DS
35856 */
35857- loadsegment(ds, __USER_DS);
35858- loadsegment(es, __USER_DS);
35859+ loadsegment(ds, __KERNEL_DS);
35860+ loadsegment(es, __KERNEL_DS);
35861 #endif
35862
35863 xen_filter_cpu_maps();
35864@@ -379,7 +375,7 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
35865 #ifdef CONFIG_X86_32
35866 /* Note: PVH is not yet supported on x86_32. */
35867 ctxt->user_regs.fs = __KERNEL_PERCPU;
35868- ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
35869+ savesegment(gs, ctxt->user_regs.gs);
35870 #endif
35871 memset(&ctxt->fpu_ctxt, 0, sizeof(ctxt->fpu_ctxt));
35872
35873@@ -387,8 +383,8 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
35874 ctxt->user_regs.eip = (unsigned long)cpu_bringup_and_idle;
35875 ctxt->flags = VGCF_IN_KERNEL;
35876 ctxt->user_regs.eflags = 0x1000; /* IOPL_RING1 */
35877- ctxt->user_regs.ds = __USER_DS;
35878- ctxt->user_regs.es = __USER_DS;
35879+ ctxt->user_regs.ds = __KERNEL_DS;
35880+ ctxt->user_regs.es = __KERNEL_DS;
35881 ctxt->user_regs.ss = __KERNEL_DS;
35882
35883 xen_copy_trap_info(ctxt->trap_ctxt);
35884@@ -446,14 +442,13 @@ static int xen_cpu_up(unsigned int cpu, struct task_struct *idle)
35885 int rc;
35886
35887 per_cpu(current_task, cpu) = idle;
35888+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
35889 #ifdef CONFIG_X86_32
35890 irq_ctx_init(cpu);
35891 #else
35892 clear_tsk_thread_flag(idle, TIF_FORK);
35893 #endif
35894- per_cpu(kernel_stack, cpu) =
35895- (unsigned long)task_stack_page(idle) -
35896- KERNEL_STACK_OFFSET + THREAD_SIZE;
35897+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
35898
35899 xen_setup_runstate_info(cpu);
35900 xen_setup_timer(cpu);
35901@@ -732,7 +727,7 @@ static const struct smp_ops xen_smp_ops __initconst = {
35902
35903 void __init xen_smp_init(void)
35904 {
35905- smp_ops = xen_smp_ops;
35906+ memcpy((void *)&smp_ops, &xen_smp_ops, sizeof smp_ops);
35907 xen_fill_possible_map();
35908 }
35909
35910diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
35911index fd92a64..1f72641 100644
35912--- a/arch/x86/xen/xen-asm_32.S
35913+++ b/arch/x86/xen/xen-asm_32.S
35914@@ -99,7 +99,7 @@ ENTRY(xen_iret)
35915 pushw %fs
35916 movl $(__KERNEL_PERCPU), %eax
35917 movl %eax, %fs
35918- movl %fs:xen_vcpu, %eax
35919+ mov PER_CPU_VAR(xen_vcpu), %eax
35920 POP_FS
35921 #else
35922 movl %ss:xen_vcpu, %eax
35923diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
35924index 674b2225..f1f5dc1 100644
35925--- a/arch/x86/xen/xen-head.S
35926+++ b/arch/x86/xen/xen-head.S
35927@@ -39,6 +39,17 @@ ENTRY(startup_xen)
35928 #ifdef CONFIG_X86_32
35929 mov %esi,xen_start_info
35930 mov $init_thread_union+THREAD_SIZE,%esp
35931+#ifdef CONFIG_SMP
35932+ movl $cpu_gdt_table,%edi
35933+ movl $__per_cpu_load,%eax
35934+ movw %ax,__KERNEL_PERCPU + 2(%edi)
35935+ rorl $16,%eax
35936+ movb %al,__KERNEL_PERCPU + 4(%edi)
35937+ movb %ah,__KERNEL_PERCPU + 7(%edi)
35938+ movl $__per_cpu_end - 1,%eax
35939+ subl $__per_cpu_start,%eax
35940+ movw %ax,__KERNEL_PERCPU + 0(%edi)
35941+#endif
35942 #else
35943 mov %rsi,xen_start_info
35944 mov $init_thread_union+THREAD_SIZE,%rsp
35945diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
35946index 28c7e0b..2acfec7 100644
35947--- a/arch/x86/xen/xen-ops.h
35948+++ b/arch/x86/xen/xen-ops.h
35949@@ -10,8 +10,6 @@
35950 extern const char xen_hypervisor_callback[];
35951 extern const char xen_failsafe_callback[];
35952
35953-extern void *xen_initial_gdt;
35954-
35955 struct trap_info;
35956 void xen_copy_trap_info(struct trap_info *traps);
35957
35958diff --git a/arch/xtensa/variants/dc232b/include/variant/core.h b/arch/xtensa/variants/dc232b/include/variant/core.h
35959index 525bd3d..ef888b1 100644
35960--- a/arch/xtensa/variants/dc232b/include/variant/core.h
35961+++ b/arch/xtensa/variants/dc232b/include/variant/core.h
35962@@ -119,9 +119,9 @@
35963 ----------------------------------------------------------------------*/
35964
35965 #define XCHAL_ICACHE_LINESIZE 32 /* I-cache line size in bytes */
35966-#define XCHAL_DCACHE_LINESIZE 32 /* D-cache line size in bytes */
35967 #define XCHAL_ICACHE_LINEWIDTH 5 /* log2(I line size in bytes) */
35968 #define XCHAL_DCACHE_LINEWIDTH 5 /* log2(D line size in bytes) */
35969+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
35970
35971 #define XCHAL_ICACHE_SIZE 16384 /* I-cache size in bytes or 0 */
35972 #define XCHAL_DCACHE_SIZE 16384 /* D-cache size in bytes or 0 */
35973diff --git a/arch/xtensa/variants/fsf/include/variant/core.h b/arch/xtensa/variants/fsf/include/variant/core.h
35974index 2f33760..835e50a 100644
35975--- a/arch/xtensa/variants/fsf/include/variant/core.h
35976+++ b/arch/xtensa/variants/fsf/include/variant/core.h
35977@@ -11,6 +11,7 @@
35978 #ifndef _XTENSA_CORE_H
35979 #define _XTENSA_CORE_H
35980
35981+#include <linux/const.h>
35982
35983 /****************************************************************************
35984 Parameters Useful for Any Code, USER or PRIVILEGED
35985@@ -112,9 +113,9 @@
35986 ----------------------------------------------------------------------*/
35987
35988 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
35989-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
35990 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
35991 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
35992+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
35993
35994 #define XCHAL_ICACHE_SIZE 8192 /* I-cache size in bytes or 0 */
35995 #define XCHAL_DCACHE_SIZE 8192 /* D-cache size in bytes or 0 */
35996diff --git a/arch/xtensa/variants/s6000/include/variant/core.h b/arch/xtensa/variants/s6000/include/variant/core.h
35997index af00795..2bb8105 100644
35998--- a/arch/xtensa/variants/s6000/include/variant/core.h
35999+++ b/arch/xtensa/variants/s6000/include/variant/core.h
36000@@ -11,6 +11,7 @@
36001 #ifndef _XTENSA_CORE_CONFIGURATION_H
36002 #define _XTENSA_CORE_CONFIGURATION_H
36003
36004+#include <linux/const.h>
36005
36006 /****************************************************************************
36007 Parameters Useful for Any Code, USER or PRIVILEGED
36008@@ -118,9 +119,9 @@
36009 ----------------------------------------------------------------------*/
36010
36011 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
36012-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
36013 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
36014 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
36015+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
36016
36017 #define XCHAL_ICACHE_SIZE 32768 /* I-cache size in bytes or 0 */
36018 #define XCHAL_DCACHE_SIZE 32768 /* D-cache size in bytes or 0 */
36019diff --git a/block/bio.c b/block/bio.c
36020index 3e6e198..5c65199 100644
36021--- a/block/bio.c
36022+++ b/block/bio.c
36023@@ -1163,7 +1163,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
36024 /*
36025 * Overflow, abort
36026 */
36027- if (end < start)
36028+ if (end < start || end - start > INT_MAX - nr_pages)
36029 return ERR_PTR(-EINVAL);
36030
36031 nr_pages += end - start;
36032@@ -1297,7 +1297,7 @@ static struct bio *__bio_map_user_iov(struct request_queue *q,
36033 /*
36034 * Overflow, abort
36035 */
36036- if (end < start)
36037+ if (end < start || end - start > INT_MAX - nr_pages)
36038 return ERR_PTR(-EINVAL);
36039
36040 nr_pages += end - start;
36041@@ -1559,7 +1559,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
36042 const int read = bio_data_dir(bio) == READ;
36043 struct bio_map_data *bmd = bio->bi_private;
36044 int i;
36045- char *p = bmd->sgvecs[0].iov_base;
36046+ char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
36047
36048 bio_for_each_segment_all(bvec, bio, i) {
36049 char *addr = page_address(bvec->bv_page);
36050diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
36051index 0736729..2ec3b48 100644
36052--- a/block/blk-iopoll.c
36053+++ b/block/blk-iopoll.c
36054@@ -74,7 +74,7 @@ void blk_iopoll_complete(struct blk_iopoll *iop)
36055 }
36056 EXPORT_SYMBOL(blk_iopoll_complete);
36057
36058-static void blk_iopoll_softirq(struct softirq_action *h)
36059+static __latent_entropy void blk_iopoll_softirq(void)
36060 {
36061 struct list_head *list = this_cpu_ptr(&blk_cpu_iopoll);
36062 int rearm = 0, budget = blk_iopoll_budget;
36063diff --git a/block/blk-map.c b/block/blk-map.c
36064index f890d43..97b0482 100644
36065--- a/block/blk-map.c
36066+++ b/block/blk-map.c
36067@@ -300,7 +300,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
36068 if (!len || !kbuf)
36069 return -EINVAL;
36070
36071- do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
36072+ do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
36073 if (do_copy)
36074 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
36075 else
36076diff --git a/block/blk-softirq.c b/block/blk-softirq.c
36077index 53b1737..08177d2e 100644
36078--- a/block/blk-softirq.c
36079+++ b/block/blk-softirq.c
36080@@ -18,7 +18,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
36081 * Softirq action handler - move entries to local list and loop over them
36082 * while passing them to the queue registered handler.
36083 */
36084-static void blk_done_softirq(struct softirq_action *h)
36085+static __latent_entropy void blk_done_softirq(void)
36086 {
36087 struct list_head *cpu_list, local_list;
36088
36089diff --git a/block/bsg.c b/block/bsg.c
36090index 276e869..6fe4c61 100644
36091--- a/block/bsg.c
36092+++ b/block/bsg.c
36093@@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
36094 struct sg_io_v4 *hdr, struct bsg_device *bd,
36095 fmode_t has_write_perm)
36096 {
36097+ unsigned char tmpcmd[sizeof(rq->__cmd)];
36098+ unsigned char *cmdptr;
36099+
36100 if (hdr->request_len > BLK_MAX_CDB) {
36101 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
36102 if (!rq->cmd)
36103 return -ENOMEM;
36104- }
36105+ cmdptr = rq->cmd;
36106+ } else
36107+ cmdptr = tmpcmd;
36108
36109- if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
36110+ if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
36111 hdr->request_len))
36112 return -EFAULT;
36113
36114+ if (cmdptr != rq->cmd)
36115+ memcpy(rq->cmd, cmdptr, hdr->request_len);
36116+
36117 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
36118 if (blk_verify_command(rq->cmd, has_write_perm))
36119 return -EPERM;
36120diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
36121index f678c73..f35aa18 100644
36122--- a/block/compat_ioctl.c
36123+++ b/block/compat_ioctl.c
36124@@ -156,7 +156,7 @@ static int compat_cdrom_generic_command(struct block_device *bdev, fmode_t mode,
36125 cgc = compat_alloc_user_space(sizeof(*cgc));
36126 cgc32 = compat_ptr(arg);
36127
36128- if (copy_in_user(&cgc->cmd, &cgc32->cmd, sizeof(cgc->cmd)) ||
36129+ if (copy_in_user(cgc->cmd, cgc32->cmd, sizeof(cgc->cmd)) ||
36130 get_user(data, &cgc32->buffer) ||
36131 put_user(compat_ptr(data), &cgc->buffer) ||
36132 copy_in_user(&cgc->buflen, &cgc32->buflen,
36133@@ -341,7 +341,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
36134 err |= __get_user(f->spec1, &uf->spec1);
36135 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
36136 err |= __get_user(name, &uf->name);
36137- f->name = compat_ptr(name);
36138+ f->name = (void __force_kernel *)compat_ptr(name);
36139 if (err) {
36140 err = -EFAULT;
36141 goto out;
36142diff --git a/block/genhd.c b/block/genhd.c
36143index bd30606..bbc9b90 100644
36144--- a/block/genhd.c
36145+++ b/block/genhd.c
36146@@ -469,21 +469,24 @@ static char *bdevt_str(dev_t devt, char *buf)
36147
36148 /*
36149 * Register device numbers dev..(dev+range-1)
36150- * range must be nonzero
36151+ * Noop if @range is zero.
36152 * The hash chain is sorted on range, so that subranges can override.
36153 */
36154 void blk_register_region(dev_t devt, unsigned long range, struct module *module,
36155 struct kobject *(*probe)(dev_t, int *, void *),
36156 int (*lock)(dev_t, void *), void *data)
36157 {
36158- kobj_map(bdev_map, devt, range, module, probe, lock, data);
36159+ if (range)
36160+ kobj_map(bdev_map, devt, range, module, probe, lock, data);
36161 }
36162
36163 EXPORT_SYMBOL(blk_register_region);
36164
36165+/* undo blk_register_region(), noop if @range is zero */
36166 void blk_unregister_region(dev_t devt, unsigned long range)
36167 {
36168- kobj_unmap(bdev_map, devt, range);
36169+ if (range)
36170+ kobj_unmap(bdev_map, devt, range);
36171 }
36172
36173 EXPORT_SYMBOL(blk_unregister_region);
36174diff --git a/block/partitions/efi.c b/block/partitions/efi.c
36175index 56d08fd..2e07090 100644
36176--- a/block/partitions/efi.c
36177+++ b/block/partitions/efi.c
36178@@ -293,14 +293,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
36179 if (!gpt)
36180 return NULL;
36181
36182+ if (!le32_to_cpu(gpt->num_partition_entries))
36183+ return NULL;
36184+ pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
36185+ if (!pte)
36186+ return NULL;
36187+
36188 count = le32_to_cpu(gpt->num_partition_entries) *
36189 le32_to_cpu(gpt->sizeof_partition_entry);
36190- if (!count)
36191- return NULL;
36192- pte = kmalloc(count, GFP_KERNEL);
36193- if (!pte)
36194- return NULL;
36195-
36196 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
36197 (u8 *) pte, count) < count) {
36198 kfree(pte);
36199diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
36200index b0c2a61..10bb6ec 100644
36201--- a/block/scsi_ioctl.c
36202+++ b/block/scsi_ioctl.c
36203@@ -67,7 +67,7 @@ static int scsi_get_bus(struct request_queue *q, int __user *p)
36204 return put_user(0, p);
36205 }
36206
36207-static int sg_get_timeout(struct request_queue *q)
36208+static int __intentional_overflow(-1) sg_get_timeout(struct request_queue *q)
36209 {
36210 return jiffies_to_clock_t(q->sg_timeout);
36211 }
36212@@ -227,8 +227,20 @@ EXPORT_SYMBOL(blk_verify_command);
36213 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
36214 struct sg_io_hdr *hdr, fmode_t mode)
36215 {
36216- if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
36217+ unsigned char tmpcmd[sizeof(rq->__cmd)];
36218+ unsigned char *cmdptr;
36219+
36220+ if (rq->cmd != rq->__cmd)
36221+ cmdptr = rq->cmd;
36222+ else
36223+ cmdptr = tmpcmd;
36224+
36225+ if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
36226 return -EFAULT;
36227+
36228+ if (cmdptr != rq->cmd)
36229+ memcpy(rq->cmd, cmdptr, hdr->cmd_len);
36230+
36231 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
36232 return -EPERM;
36233
36234@@ -431,6 +443,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
36235 int err;
36236 unsigned int in_len, out_len, bytes, opcode, cmdlen;
36237 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
36238+ unsigned char tmpcmd[sizeof(rq->__cmd)];
36239+ unsigned char *cmdptr;
36240
36241 if (!sic)
36242 return -EINVAL;
36243@@ -469,9 +483,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
36244 */
36245 err = -EFAULT;
36246 rq->cmd_len = cmdlen;
36247- if (copy_from_user(rq->cmd, sic->data, cmdlen))
36248+
36249+ if (rq->cmd != rq->__cmd)
36250+ cmdptr = rq->cmd;
36251+ else
36252+ cmdptr = tmpcmd;
36253+
36254+ if (copy_from_user(cmdptr, sic->data, cmdlen))
36255 goto error;
36256
36257+ if (rq->cmd != cmdptr)
36258+ memcpy(rq->cmd, cmdptr, cmdlen);
36259+
36260 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
36261 goto error;
36262
36263diff --git a/crypto/cryptd.c b/crypto/cryptd.c
36264index e592c90..c566114 100644
36265--- a/crypto/cryptd.c
36266+++ b/crypto/cryptd.c
36267@@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
36268
36269 struct cryptd_blkcipher_request_ctx {
36270 crypto_completion_t complete;
36271-};
36272+} __no_const;
36273
36274 struct cryptd_hash_ctx {
36275 struct crypto_shash *child;
36276@@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
36277
36278 struct cryptd_aead_request_ctx {
36279 crypto_completion_t complete;
36280-};
36281+} __no_const;
36282
36283 static void cryptd_queue_worker(struct work_struct *work);
36284
36285diff --git a/crypto/pcrypt.c b/crypto/pcrypt.c
36286index 309d345..1632720 100644
36287--- a/crypto/pcrypt.c
36288+++ b/crypto/pcrypt.c
36289@@ -440,7 +440,7 @@ static int pcrypt_sysfs_add(struct padata_instance *pinst, const char *name)
36290 int ret;
36291
36292 pinst->kobj.kset = pcrypt_kset;
36293- ret = kobject_add(&pinst->kobj, NULL, name);
36294+ ret = kobject_add(&pinst->kobj, NULL, "%s", name);
36295 if (!ret)
36296 kobject_uevent(&pinst->kobj, KOBJ_ADD);
36297
36298diff --git a/drivers/acpi/acpica/hwxfsleep.c b/drivers/acpi/acpica/hwxfsleep.c
36299index 6921c7f..78e1af7 100644
36300--- a/drivers/acpi/acpica/hwxfsleep.c
36301+++ b/drivers/acpi/acpica/hwxfsleep.c
36302@@ -63,11 +63,12 @@ static acpi_status acpi_hw_sleep_dispatch(u8 sleep_state, u32 function_id);
36303 /* Legacy functions are optional, based upon ACPI_REDUCED_HARDWARE */
36304
36305 static struct acpi_sleep_functions acpi_sleep_dispatch[] = {
36306- {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_sleep),
36307- acpi_hw_extended_sleep},
36308- {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake_prep),
36309- acpi_hw_extended_wake_prep},
36310- {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake), acpi_hw_extended_wake}
36311+ {.legacy_function = ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_sleep),
36312+ .extended_function = acpi_hw_extended_sleep},
36313+ {.legacy_function = ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake_prep),
36314+ .extended_function = acpi_hw_extended_wake_prep},
36315+ {.legacy_function = ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake),
36316+ .extended_function = acpi_hw_extended_wake}
36317 };
36318
36319 /*
36320diff --git a/drivers/acpi/apei/apei-internal.h b/drivers/acpi/apei/apei-internal.h
36321index 16129c7..8b675cd 100644
36322--- a/drivers/acpi/apei/apei-internal.h
36323+++ b/drivers/acpi/apei/apei-internal.h
36324@@ -19,7 +19,7 @@ typedef int (*apei_exec_ins_func_t)(struct apei_exec_context *ctx,
36325 struct apei_exec_ins_type {
36326 u32 flags;
36327 apei_exec_ins_func_t run;
36328-};
36329+} __do_const;
36330
36331 struct apei_exec_context {
36332 u32 ip;
36333diff --git a/drivers/acpi/apei/ghes.c b/drivers/acpi/apei/ghes.c
36334index fc5f780..e5ac91a 100644
36335--- a/drivers/acpi/apei/ghes.c
36336+++ b/drivers/acpi/apei/ghes.c
36337@@ -478,7 +478,7 @@ static void __ghes_print_estatus(const char *pfx,
36338 const struct acpi_hest_generic *generic,
36339 const struct acpi_hest_generic_status *estatus)
36340 {
36341- static atomic_t seqno;
36342+ static atomic_unchecked_t seqno;
36343 unsigned int curr_seqno;
36344 char pfx_seq[64];
36345
36346@@ -489,7 +489,7 @@ static void __ghes_print_estatus(const char *pfx,
36347 else
36348 pfx = KERN_ERR;
36349 }
36350- curr_seqno = atomic_inc_return(&seqno);
36351+ curr_seqno = atomic_inc_return_unchecked(&seqno);
36352 snprintf(pfx_seq, sizeof(pfx_seq), "%s{%u}" HW_ERR, pfx, curr_seqno);
36353 printk("%s""Hardware error from APEI Generic Hardware Error Source: %d\n",
36354 pfx_seq, generic->header.source_id);
36355diff --git a/drivers/acpi/bgrt.c b/drivers/acpi/bgrt.c
36356index a83e3c6..c3d617f 100644
36357--- a/drivers/acpi/bgrt.c
36358+++ b/drivers/acpi/bgrt.c
36359@@ -86,8 +86,10 @@ static int __init bgrt_init(void)
36360 if (!bgrt_image)
36361 return -ENODEV;
36362
36363- bin_attr_image.private = bgrt_image;
36364- bin_attr_image.size = bgrt_image_size;
36365+ pax_open_kernel();
36366+ *(void **)&bin_attr_image.private = bgrt_image;
36367+ *(size_t *)&bin_attr_image.size = bgrt_image_size;
36368+ pax_close_kernel();
36369
36370 bgrt_kobj = kobject_create_and_add("bgrt", acpi_kobj);
36371 if (!bgrt_kobj)
36372diff --git a/drivers/acpi/blacklist.c b/drivers/acpi/blacklist.c
36373index 7556e7c..89a96bd 100644
36374--- a/drivers/acpi/blacklist.c
36375+++ b/drivers/acpi/blacklist.c
36376@@ -51,7 +51,7 @@ struct acpi_blacklist_item {
36377 u32 is_critical_error;
36378 };
36379
36380-static struct dmi_system_id acpi_osi_dmi_table[] __initdata;
36381+static const struct dmi_system_id acpi_osi_dmi_table[] __initconst;
36382
36383 /*
36384 * POLICY: If *anything* doesn't work, put it on the blacklist.
36385@@ -163,7 +163,7 @@ static int __init dmi_disable_osi_win8(const struct dmi_system_id *d)
36386 return 0;
36387 }
36388
36389-static struct dmi_system_id acpi_osi_dmi_table[] __initdata = {
36390+static const struct dmi_system_id acpi_osi_dmi_table[] __initconst = {
36391 {
36392 .callback = dmi_disable_osi_vista,
36393 .ident = "Fujitsu Siemens",
36394diff --git a/drivers/acpi/custom_method.c b/drivers/acpi/custom_method.c
36395index c68e724..e863008 100644
36396--- a/drivers/acpi/custom_method.c
36397+++ b/drivers/acpi/custom_method.c
36398@@ -29,6 +29,10 @@ static ssize_t cm_write(struct file *file, const char __user * user_buf,
36399 struct acpi_table_header table;
36400 acpi_status status;
36401
36402+#ifdef CONFIG_GRKERNSEC_KMEM
36403+ return -EPERM;
36404+#endif
36405+
36406 if (!(*ppos)) {
36407 /* parse the table header to get the table length */
36408 if (count <= sizeof(struct acpi_table_header))
36409diff --git a/drivers/acpi/device_pm.c b/drivers/acpi/device_pm.c
36410index 7db1931..302dd5f 100644
36411--- a/drivers/acpi/device_pm.c
36412+++ b/drivers/acpi/device_pm.c
36413@@ -1021,6 +1021,8 @@ EXPORT_SYMBOL_GPL(acpi_subsys_freeze);
36414
36415 #endif /* CONFIG_PM_SLEEP */
36416
36417+static void acpi_dev_pm_detach(struct device *dev, bool power_off);
36418+
36419 static struct dev_pm_domain acpi_general_pm_domain = {
36420 .ops = {
36421 #ifdef CONFIG_PM_RUNTIME
36422@@ -1039,6 +1041,7 @@ static struct dev_pm_domain acpi_general_pm_domain = {
36423 .restore_early = acpi_subsys_resume_early,
36424 #endif
36425 },
36426+ .detach = acpi_dev_pm_detach
36427 };
36428
36429 /**
36430@@ -1108,7 +1111,6 @@ int acpi_dev_pm_attach(struct device *dev, bool power_on)
36431 acpi_device_wakeup(adev, ACPI_STATE_S0, false);
36432 }
36433
36434- dev->pm_domain->detach = acpi_dev_pm_detach;
36435 return 0;
36436 }
36437 EXPORT_SYMBOL_GPL(acpi_dev_pm_attach);
36438diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c
36439index 17f9ec5..d9a455e 100644
36440--- a/drivers/acpi/processor_idle.c
36441+++ b/drivers/acpi/processor_idle.c
36442@@ -952,7 +952,7 @@ static int acpi_processor_setup_cpuidle_states(struct acpi_processor *pr)
36443 {
36444 int i, count = CPUIDLE_DRIVER_STATE_START;
36445 struct acpi_processor_cx *cx;
36446- struct cpuidle_state *state;
36447+ cpuidle_state_no_const *state;
36448 struct cpuidle_driver *drv = &acpi_idle_driver;
36449
36450 if (!pr->flags.power_setup_done)
36451diff --git a/drivers/acpi/sysfs.c b/drivers/acpi/sysfs.c
36452index 13e577c..cef11ee 100644
36453--- a/drivers/acpi/sysfs.c
36454+++ b/drivers/acpi/sysfs.c
36455@@ -423,11 +423,11 @@ static u32 num_counters;
36456 static struct attribute **all_attrs;
36457 static u32 acpi_gpe_count;
36458
36459-static struct attribute_group interrupt_stats_attr_group = {
36460+static attribute_group_no_const interrupt_stats_attr_group = {
36461 .name = "interrupts",
36462 };
36463
36464-static struct kobj_attribute *counter_attrs;
36465+static kobj_attribute_no_const *counter_attrs;
36466
36467 static void delete_gpe_attr_array(void)
36468 {
36469diff --git a/drivers/ata/libahci.c b/drivers/ata/libahci.c
36470index 97683e4..655f6ba 100644
36471--- a/drivers/ata/libahci.c
36472+++ b/drivers/ata/libahci.c
36473@@ -1252,7 +1252,7 @@ int ahci_kick_engine(struct ata_port *ap)
36474 }
36475 EXPORT_SYMBOL_GPL(ahci_kick_engine);
36476
36477-static int ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
36478+static int __intentional_overflow(-1) ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
36479 struct ata_taskfile *tf, int is_cmd, u16 flags,
36480 unsigned long timeout_msec)
36481 {
36482diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
36483index c5ba15a..75ec7a8 100644
36484--- a/drivers/ata/libata-core.c
36485+++ b/drivers/ata/libata-core.c
36486@@ -99,7 +99,7 @@ static unsigned int ata_dev_set_xfermode(struct ata_device *dev);
36487 static void ata_dev_xfermask(struct ata_device *dev);
36488 static unsigned long ata_dev_blacklisted(const struct ata_device *dev);
36489
36490-atomic_t ata_print_id = ATOMIC_INIT(0);
36491+atomic_unchecked_t ata_print_id = ATOMIC_INIT(0);
36492
36493 struct ata_force_param {
36494 const char *name;
36495@@ -4797,7 +4797,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
36496 struct ata_port *ap;
36497 unsigned int tag;
36498
36499- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
36500+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
36501 ap = qc->ap;
36502
36503 qc->flags = 0;
36504@@ -4813,7 +4813,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
36505 struct ata_port *ap;
36506 struct ata_link *link;
36507
36508- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
36509+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
36510 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
36511 ap = qc->ap;
36512 link = qc->dev->link;
36513@@ -5917,6 +5917,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
36514 return;
36515
36516 spin_lock(&lock);
36517+ pax_open_kernel();
36518
36519 for (cur = ops->inherits; cur; cur = cur->inherits) {
36520 void **inherit = (void **)cur;
36521@@ -5930,8 +5931,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
36522 if (IS_ERR(*pp))
36523 *pp = NULL;
36524
36525- ops->inherits = NULL;
36526+ *(struct ata_port_operations **)&ops->inherits = NULL;
36527
36528+ pax_close_kernel();
36529 spin_unlock(&lock);
36530 }
36531
36532@@ -6127,7 +6129,7 @@ int ata_host_register(struct ata_host *host, struct scsi_host_template *sht)
36533
36534 /* give ports names and add SCSI hosts */
36535 for (i = 0; i < host->n_ports; i++) {
36536- host->ports[i]->print_id = atomic_inc_return(&ata_print_id);
36537+ host->ports[i]->print_id = atomic_inc_return_unchecked(&ata_print_id);
36538 host->ports[i]->local_port_no = i + 1;
36539 }
36540
36541diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
36542index 0586f66..1a8f74a 100644
36543--- a/drivers/ata/libata-scsi.c
36544+++ b/drivers/ata/libata-scsi.c
36545@@ -4151,7 +4151,7 @@ int ata_sas_port_init(struct ata_port *ap)
36546
36547 if (rc)
36548 return rc;
36549- ap->print_id = atomic_inc_return(&ata_print_id);
36550+ ap->print_id = atomic_inc_return_unchecked(&ata_print_id);
36551 return 0;
36552 }
36553 EXPORT_SYMBOL_GPL(ata_sas_port_init);
36554diff --git a/drivers/ata/libata.h b/drivers/ata/libata.h
36555index 5f4e0cc..ff2c347 100644
36556--- a/drivers/ata/libata.h
36557+++ b/drivers/ata/libata.h
36558@@ -53,7 +53,7 @@ enum {
36559 ATA_DNXFER_QUIET = (1 << 31),
36560 };
36561
36562-extern atomic_t ata_print_id;
36563+extern atomic_unchecked_t ata_print_id;
36564 extern int atapi_passthru16;
36565 extern int libata_fua;
36566 extern int libata_noacpi;
36567diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
36568index 38216b9..4ec6aeb 100644
36569--- a/drivers/ata/pata_arasan_cf.c
36570+++ b/drivers/ata/pata_arasan_cf.c
36571@@ -865,7 +865,9 @@ static int arasan_cf_probe(struct platform_device *pdev)
36572 /* Handle platform specific quirks */
36573 if (quirk) {
36574 if (quirk & CF_BROKEN_PIO) {
36575- ap->ops->set_piomode = NULL;
36576+ pax_open_kernel();
36577+ *(void **)&ap->ops->set_piomode = NULL;
36578+ pax_close_kernel();
36579 ap->pio_mask = 0;
36580 }
36581 if (quirk & CF_BROKEN_MWDMA)
36582diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
36583index f9b983a..887b9d8 100644
36584--- a/drivers/atm/adummy.c
36585+++ b/drivers/atm/adummy.c
36586@@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
36587 vcc->pop(vcc, skb);
36588 else
36589 dev_kfree_skb_any(skb);
36590- atomic_inc(&vcc->stats->tx);
36591+ atomic_inc_unchecked(&vcc->stats->tx);
36592
36593 return 0;
36594 }
36595diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
36596index f1a9198..f466a4a 100644
36597--- a/drivers/atm/ambassador.c
36598+++ b/drivers/atm/ambassador.c
36599@@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
36600 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
36601
36602 // VC layer stats
36603- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
36604+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
36605
36606 // free the descriptor
36607 kfree (tx_descr);
36608@@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
36609 dump_skb ("<<<", vc, skb);
36610
36611 // VC layer stats
36612- atomic_inc(&atm_vcc->stats->rx);
36613+ atomic_inc_unchecked(&atm_vcc->stats->rx);
36614 __net_timestamp(skb);
36615 // end of our responsibility
36616 atm_vcc->push (atm_vcc, skb);
36617@@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
36618 } else {
36619 PRINTK (KERN_INFO, "dropped over-size frame");
36620 // should we count this?
36621- atomic_inc(&atm_vcc->stats->rx_drop);
36622+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
36623 }
36624
36625 } else {
36626@@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
36627 }
36628
36629 if (check_area (skb->data, skb->len)) {
36630- atomic_inc(&atm_vcc->stats->tx_err);
36631+ atomic_inc_unchecked(&atm_vcc->stats->tx_err);
36632 return -ENOMEM; // ?
36633 }
36634
36635diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
36636index 480fa6f..947067c 100644
36637--- a/drivers/atm/atmtcp.c
36638+++ b/drivers/atm/atmtcp.c
36639@@ -206,7 +206,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
36640 if (vcc->pop) vcc->pop(vcc,skb);
36641 else dev_kfree_skb(skb);
36642 if (dev_data) return 0;
36643- atomic_inc(&vcc->stats->tx_err);
36644+ atomic_inc_unchecked(&vcc->stats->tx_err);
36645 return -ENOLINK;
36646 }
36647 size = skb->len+sizeof(struct atmtcp_hdr);
36648@@ -214,7 +214,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
36649 if (!new_skb) {
36650 if (vcc->pop) vcc->pop(vcc,skb);
36651 else dev_kfree_skb(skb);
36652- atomic_inc(&vcc->stats->tx_err);
36653+ atomic_inc_unchecked(&vcc->stats->tx_err);
36654 return -ENOBUFS;
36655 }
36656 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
36657@@ -225,8 +225,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
36658 if (vcc->pop) vcc->pop(vcc,skb);
36659 else dev_kfree_skb(skb);
36660 out_vcc->push(out_vcc,new_skb);
36661- atomic_inc(&vcc->stats->tx);
36662- atomic_inc(&out_vcc->stats->rx);
36663+ atomic_inc_unchecked(&vcc->stats->tx);
36664+ atomic_inc_unchecked(&out_vcc->stats->rx);
36665 return 0;
36666 }
36667
36668@@ -300,7 +300,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
36669 read_unlock(&vcc_sklist_lock);
36670 if (!out_vcc) {
36671 result = -EUNATCH;
36672- atomic_inc(&vcc->stats->tx_err);
36673+ atomic_inc_unchecked(&vcc->stats->tx_err);
36674 goto done;
36675 }
36676 skb_pull(skb,sizeof(struct atmtcp_hdr));
36677@@ -312,8 +312,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
36678 __net_timestamp(new_skb);
36679 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
36680 out_vcc->push(out_vcc,new_skb);
36681- atomic_inc(&vcc->stats->tx);
36682- atomic_inc(&out_vcc->stats->rx);
36683+ atomic_inc_unchecked(&vcc->stats->tx);
36684+ atomic_inc_unchecked(&out_vcc->stats->rx);
36685 done:
36686 if (vcc->pop) vcc->pop(vcc,skb);
36687 else dev_kfree_skb(skb);
36688diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
36689index d65975a..0b87e20 100644
36690--- a/drivers/atm/eni.c
36691+++ b/drivers/atm/eni.c
36692@@ -522,7 +522,7 @@ static int rx_aal0(struct atm_vcc *vcc)
36693 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
36694 vcc->dev->number);
36695 length = 0;
36696- atomic_inc(&vcc->stats->rx_err);
36697+ atomic_inc_unchecked(&vcc->stats->rx_err);
36698 }
36699 else {
36700 length = ATM_CELL_SIZE-1; /* no HEC */
36701@@ -577,7 +577,7 @@ static int rx_aal5(struct atm_vcc *vcc)
36702 size);
36703 }
36704 eff = length = 0;
36705- atomic_inc(&vcc->stats->rx_err);
36706+ atomic_inc_unchecked(&vcc->stats->rx_err);
36707 }
36708 else {
36709 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
36710@@ -594,7 +594,7 @@ static int rx_aal5(struct atm_vcc *vcc)
36711 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
36712 vcc->dev->number,vcc->vci,length,size << 2,descr);
36713 length = eff = 0;
36714- atomic_inc(&vcc->stats->rx_err);
36715+ atomic_inc_unchecked(&vcc->stats->rx_err);
36716 }
36717 }
36718 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
36719@@ -767,7 +767,7 @@ rx_dequeued++;
36720 vcc->push(vcc,skb);
36721 pushed++;
36722 }
36723- atomic_inc(&vcc->stats->rx);
36724+ atomic_inc_unchecked(&vcc->stats->rx);
36725 }
36726 wake_up(&eni_dev->rx_wait);
36727 }
36728@@ -1227,7 +1227,7 @@ static void dequeue_tx(struct atm_dev *dev)
36729 PCI_DMA_TODEVICE);
36730 if (vcc->pop) vcc->pop(vcc,skb);
36731 else dev_kfree_skb_irq(skb);
36732- atomic_inc(&vcc->stats->tx);
36733+ atomic_inc_unchecked(&vcc->stats->tx);
36734 wake_up(&eni_dev->tx_wait);
36735 dma_complete++;
36736 }
36737diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
36738index 82f2ae0..f205c02 100644
36739--- a/drivers/atm/firestream.c
36740+++ b/drivers/atm/firestream.c
36741@@ -749,7 +749,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
36742 }
36743 }
36744
36745- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
36746+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
36747
36748 fs_dprintk (FS_DEBUG_TXMEM, "i");
36749 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
36750@@ -816,7 +816,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
36751 #endif
36752 skb_put (skb, qe->p1 & 0xffff);
36753 ATM_SKB(skb)->vcc = atm_vcc;
36754- atomic_inc(&atm_vcc->stats->rx);
36755+ atomic_inc_unchecked(&atm_vcc->stats->rx);
36756 __net_timestamp(skb);
36757 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
36758 atm_vcc->push (atm_vcc, skb);
36759@@ -837,12 +837,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
36760 kfree (pe);
36761 }
36762 if (atm_vcc)
36763- atomic_inc(&atm_vcc->stats->rx_drop);
36764+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
36765 break;
36766 case 0x1f: /* Reassembly abort: no buffers. */
36767 /* Silently increment error counter. */
36768 if (atm_vcc)
36769- atomic_inc(&atm_vcc->stats->rx_drop);
36770+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
36771 break;
36772 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
36773 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
36774diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
36775index d4725fc..2d4ea65 100644
36776--- a/drivers/atm/fore200e.c
36777+++ b/drivers/atm/fore200e.c
36778@@ -931,9 +931,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
36779 #endif
36780 /* check error condition */
36781 if (*entry->status & STATUS_ERROR)
36782- atomic_inc(&vcc->stats->tx_err);
36783+ atomic_inc_unchecked(&vcc->stats->tx_err);
36784 else
36785- atomic_inc(&vcc->stats->tx);
36786+ atomic_inc_unchecked(&vcc->stats->tx);
36787 }
36788 }
36789
36790@@ -1082,7 +1082,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
36791 if (skb == NULL) {
36792 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
36793
36794- atomic_inc(&vcc->stats->rx_drop);
36795+ atomic_inc_unchecked(&vcc->stats->rx_drop);
36796 return -ENOMEM;
36797 }
36798
36799@@ -1125,14 +1125,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
36800
36801 dev_kfree_skb_any(skb);
36802
36803- atomic_inc(&vcc->stats->rx_drop);
36804+ atomic_inc_unchecked(&vcc->stats->rx_drop);
36805 return -ENOMEM;
36806 }
36807
36808 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
36809
36810 vcc->push(vcc, skb);
36811- atomic_inc(&vcc->stats->rx);
36812+ atomic_inc_unchecked(&vcc->stats->rx);
36813
36814 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
36815
36816@@ -1210,7 +1210,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
36817 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
36818 fore200e->atm_dev->number,
36819 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
36820- atomic_inc(&vcc->stats->rx_err);
36821+ atomic_inc_unchecked(&vcc->stats->rx_err);
36822 }
36823 }
36824
36825@@ -1655,7 +1655,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
36826 goto retry_here;
36827 }
36828
36829- atomic_inc(&vcc->stats->tx_err);
36830+ atomic_inc_unchecked(&vcc->stats->tx_err);
36831
36832 fore200e->tx_sat++;
36833 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
36834diff --git a/drivers/atm/he.c b/drivers/atm/he.c
36835index c39702b..785b73b 100644
36836--- a/drivers/atm/he.c
36837+++ b/drivers/atm/he.c
36838@@ -1689,7 +1689,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
36839
36840 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
36841 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
36842- atomic_inc(&vcc->stats->rx_drop);
36843+ atomic_inc_unchecked(&vcc->stats->rx_drop);
36844 goto return_host_buffers;
36845 }
36846
36847@@ -1716,7 +1716,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
36848 RBRQ_LEN_ERR(he_dev->rbrq_head)
36849 ? "LEN_ERR" : "",
36850 vcc->vpi, vcc->vci);
36851- atomic_inc(&vcc->stats->rx_err);
36852+ atomic_inc_unchecked(&vcc->stats->rx_err);
36853 goto return_host_buffers;
36854 }
36855
36856@@ -1768,7 +1768,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
36857 vcc->push(vcc, skb);
36858 spin_lock(&he_dev->global_lock);
36859
36860- atomic_inc(&vcc->stats->rx);
36861+ atomic_inc_unchecked(&vcc->stats->rx);
36862
36863 return_host_buffers:
36864 ++pdus_assembled;
36865@@ -2094,7 +2094,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
36866 tpd->vcc->pop(tpd->vcc, tpd->skb);
36867 else
36868 dev_kfree_skb_any(tpd->skb);
36869- atomic_inc(&tpd->vcc->stats->tx_err);
36870+ atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
36871 }
36872 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
36873 return;
36874@@ -2506,7 +2506,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36875 vcc->pop(vcc, skb);
36876 else
36877 dev_kfree_skb_any(skb);
36878- atomic_inc(&vcc->stats->tx_err);
36879+ atomic_inc_unchecked(&vcc->stats->tx_err);
36880 return -EINVAL;
36881 }
36882
36883@@ -2517,7 +2517,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36884 vcc->pop(vcc, skb);
36885 else
36886 dev_kfree_skb_any(skb);
36887- atomic_inc(&vcc->stats->tx_err);
36888+ atomic_inc_unchecked(&vcc->stats->tx_err);
36889 return -EINVAL;
36890 }
36891 #endif
36892@@ -2529,7 +2529,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36893 vcc->pop(vcc, skb);
36894 else
36895 dev_kfree_skb_any(skb);
36896- atomic_inc(&vcc->stats->tx_err);
36897+ atomic_inc_unchecked(&vcc->stats->tx_err);
36898 spin_unlock_irqrestore(&he_dev->global_lock, flags);
36899 return -ENOMEM;
36900 }
36901@@ -2571,7 +2571,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36902 vcc->pop(vcc, skb);
36903 else
36904 dev_kfree_skb_any(skb);
36905- atomic_inc(&vcc->stats->tx_err);
36906+ atomic_inc_unchecked(&vcc->stats->tx_err);
36907 spin_unlock_irqrestore(&he_dev->global_lock, flags);
36908 return -ENOMEM;
36909 }
36910@@ -2602,7 +2602,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36911 __enqueue_tpd(he_dev, tpd, cid);
36912 spin_unlock_irqrestore(&he_dev->global_lock, flags);
36913
36914- atomic_inc(&vcc->stats->tx);
36915+ atomic_inc_unchecked(&vcc->stats->tx);
36916
36917 return 0;
36918 }
36919diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
36920index 1dc0519..1aadaf7 100644
36921--- a/drivers/atm/horizon.c
36922+++ b/drivers/atm/horizon.c
36923@@ -1034,7 +1034,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
36924 {
36925 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
36926 // VC layer stats
36927- atomic_inc(&vcc->stats->rx);
36928+ atomic_inc_unchecked(&vcc->stats->rx);
36929 __net_timestamp(skb);
36930 // end of our responsibility
36931 vcc->push (vcc, skb);
36932@@ -1186,7 +1186,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
36933 dev->tx_iovec = NULL;
36934
36935 // VC layer stats
36936- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
36937+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
36938
36939 // free the skb
36940 hrz_kfree_skb (skb);
36941diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
36942index 2b24ed0..b3d6acc 100644
36943--- a/drivers/atm/idt77252.c
36944+++ b/drivers/atm/idt77252.c
36945@@ -810,7 +810,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
36946 else
36947 dev_kfree_skb(skb);
36948
36949- atomic_inc(&vcc->stats->tx);
36950+ atomic_inc_unchecked(&vcc->stats->tx);
36951 }
36952
36953 atomic_dec(&scq->used);
36954@@ -1072,13 +1072,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36955 if ((sb = dev_alloc_skb(64)) == NULL) {
36956 printk("%s: Can't allocate buffers for aal0.\n",
36957 card->name);
36958- atomic_add(i, &vcc->stats->rx_drop);
36959+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
36960 break;
36961 }
36962 if (!atm_charge(vcc, sb->truesize)) {
36963 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
36964 card->name);
36965- atomic_add(i - 1, &vcc->stats->rx_drop);
36966+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
36967 dev_kfree_skb(sb);
36968 break;
36969 }
36970@@ -1095,7 +1095,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36971 ATM_SKB(sb)->vcc = vcc;
36972 __net_timestamp(sb);
36973 vcc->push(vcc, sb);
36974- atomic_inc(&vcc->stats->rx);
36975+ atomic_inc_unchecked(&vcc->stats->rx);
36976
36977 cell += ATM_CELL_PAYLOAD;
36978 }
36979@@ -1132,13 +1132,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36980 "(CDC: %08x)\n",
36981 card->name, len, rpp->len, readl(SAR_REG_CDC));
36982 recycle_rx_pool_skb(card, rpp);
36983- atomic_inc(&vcc->stats->rx_err);
36984+ atomic_inc_unchecked(&vcc->stats->rx_err);
36985 return;
36986 }
36987 if (stat & SAR_RSQE_CRC) {
36988 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
36989 recycle_rx_pool_skb(card, rpp);
36990- atomic_inc(&vcc->stats->rx_err);
36991+ atomic_inc_unchecked(&vcc->stats->rx_err);
36992 return;
36993 }
36994 if (skb_queue_len(&rpp->queue) > 1) {
36995@@ -1149,7 +1149,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36996 RXPRINTK("%s: Can't alloc RX skb.\n",
36997 card->name);
36998 recycle_rx_pool_skb(card, rpp);
36999- atomic_inc(&vcc->stats->rx_err);
37000+ atomic_inc_unchecked(&vcc->stats->rx_err);
37001 return;
37002 }
37003 if (!atm_charge(vcc, skb->truesize)) {
37004@@ -1168,7 +1168,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
37005 __net_timestamp(skb);
37006
37007 vcc->push(vcc, skb);
37008- atomic_inc(&vcc->stats->rx);
37009+ atomic_inc_unchecked(&vcc->stats->rx);
37010
37011 return;
37012 }
37013@@ -1190,7 +1190,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
37014 __net_timestamp(skb);
37015
37016 vcc->push(vcc, skb);
37017- atomic_inc(&vcc->stats->rx);
37018+ atomic_inc_unchecked(&vcc->stats->rx);
37019
37020 if (skb->truesize > SAR_FB_SIZE_3)
37021 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
37022@@ -1301,14 +1301,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
37023 if (vcc->qos.aal != ATM_AAL0) {
37024 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
37025 card->name, vpi, vci);
37026- atomic_inc(&vcc->stats->rx_drop);
37027+ atomic_inc_unchecked(&vcc->stats->rx_drop);
37028 goto drop;
37029 }
37030
37031 if ((sb = dev_alloc_skb(64)) == NULL) {
37032 printk("%s: Can't allocate buffers for AAL0.\n",
37033 card->name);
37034- atomic_inc(&vcc->stats->rx_err);
37035+ atomic_inc_unchecked(&vcc->stats->rx_err);
37036 goto drop;
37037 }
37038
37039@@ -1327,7 +1327,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
37040 ATM_SKB(sb)->vcc = vcc;
37041 __net_timestamp(sb);
37042 vcc->push(vcc, sb);
37043- atomic_inc(&vcc->stats->rx);
37044+ atomic_inc_unchecked(&vcc->stats->rx);
37045
37046 drop:
37047 skb_pull(queue, 64);
37048@@ -1952,13 +1952,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
37049
37050 if (vc == NULL) {
37051 printk("%s: NULL connection in send().\n", card->name);
37052- atomic_inc(&vcc->stats->tx_err);
37053+ atomic_inc_unchecked(&vcc->stats->tx_err);
37054 dev_kfree_skb(skb);
37055 return -EINVAL;
37056 }
37057 if (!test_bit(VCF_TX, &vc->flags)) {
37058 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
37059- atomic_inc(&vcc->stats->tx_err);
37060+ atomic_inc_unchecked(&vcc->stats->tx_err);
37061 dev_kfree_skb(skb);
37062 return -EINVAL;
37063 }
37064@@ -1970,14 +1970,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
37065 break;
37066 default:
37067 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
37068- atomic_inc(&vcc->stats->tx_err);
37069+ atomic_inc_unchecked(&vcc->stats->tx_err);
37070 dev_kfree_skb(skb);
37071 return -EINVAL;
37072 }
37073
37074 if (skb_shinfo(skb)->nr_frags != 0) {
37075 printk("%s: No scatter-gather yet.\n", card->name);
37076- atomic_inc(&vcc->stats->tx_err);
37077+ atomic_inc_unchecked(&vcc->stats->tx_err);
37078 dev_kfree_skb(skb);
37079 return -EINVAL;
37080 }
37081@@ -1985,7 +1985,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
37082
37083 err = queue_skb(card, vc, skb, oam);
37084 if (err) {
37085- atomic_inc(&vcc->stats->tx_err);
37086+ atomic_inc_unchecked(&vcc->stats->tx_err);
37087 dev_kfree_skb(skb);
37088 return err;
37089 }
37090@@ -2008,7 +2008,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
37091 skb = dev_alloc_skb(64);
37092 if (!skb) {
37093 printk("%s: Out of memory in send_oam().\n", card->name);
37094- atomic_inc(&vcc->stats->tx_err);
37095+ atomic_inc_unchecked(&vcc->stats->tx_err);
37096 return -ENOMEM;
37097 }
37098 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
37099diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
37100index 4217f29..88f547a 100644
37101--- a/drivers/atm/iphase.c
37102+++ b/drivers/atm/iphase.c
37103@@ -1145,7 +1145,7 @@ static int rx_pkt(struct atm_dev *dev)
37104 status = (u_short) (buf_desc_ptr->desc_mode);
37105 if (status & (RX_CER | RX_PTE | RX_OFL))
37106 {
37107- atomic_inc(&vcc->stats->rx_err);
37108+ atomic_inc_unchecked(&vcc->stats->rx_err);
37109 IF_ERR(printk("IA: bad packet, dropping it");)
37110 if (status & RX_CER) {
37111 IF_ERR(printk(" cause: packet CRC error\n");)
37112@@ -1168,7 +1168,7 @@ static int rx_pkt(struct atm_dev *dev)
37113 len = dma_addr - buf_addr;
37114 if (len > iadev->rx_buf_sz) {
37115 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
37116- atomic_inc(&vcc->stats->rx_err);
37117+ atomic_inc_unchecked(&vcc->stats->rx_err);
37118 goto out_free_desc;
37119 }
37120
37121@@ -1318,7 +1318,7 @@ static void rx_dle_intr(struct atm_dev *dev)
37122 ia_vcc = INPH_IA_VCC(vcc);
37123 if (ia_vcc == NULL)
37124 {
37125- atomic_inc(&vcc->stats->rx_err);
37126+ atomic_inc_unchecked(&vcc->stats->rx_err);
37127 atm_return(vcc, skb->truesize);
37128 dev_kfree_skb_any(skb);
37129 goto INCR_DLE;
37130@@ -1330,7 +1330,7 @@ static void rx_dle_intr(struct atm_dev *dev)
37131 if ((length > iadev->rx_buf_sz) || (length >
37132 (skb->len - sizeof(struct cpcs_trailer))))
37133 {
37134- atomic_inc(&vcc->stats->rx_err);
37135+ atomic_inc_unchecked(&vcc->stats->rx_err);
37136 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
37137 length, skb->len);)
37138 atm_return(vcc, skb->truesize);
37139@@ -1346,7 +1346,7 @@ static void rx_dle_intr(struct atm_dev *dev)
37140
37141 IF_RX(printk("rx_dle_intr: skb push");)
37142 vcc->push(vcc,skb);
37143- atomic_inc(&vcc->stats->rx);
37144+ atomic_inc_unchecked(&vcc->stats->rx);
37145 iadev->rx_pkt_cnt++;
37146 }
37147 INCR_DLE:
37148@@ -2826,15 +2826,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
37149 {
37150 struct k_sonet_stats *stats;
37151 stats = &PRIV(_ia_dev[board])->sonet_stats;
37152- printk("section_bip: %d\n", atomic_read(&stats->section_bip));
37153- printk("line_bip : %d\n", atomic_read(&stats->line_bip));
37154- printk("path_bip : %d\n", atomic_read(&stats->path_bip));
37155- printk("line_febe : %d\n", atomic_read(&stats->line_febe));
37156- printk("path_febe : %d\n", atomic_read(&stats->path_febe));
37157- printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
37158- printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
37159- printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
37160- printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
37161+ printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
37162+ printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
37163+ printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
37164+ printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
37165+ printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
37166+ printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
37167+ printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
37168+ printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
37169+ printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
37170 }
37171 ia_cmds.status = 0;
37172 break;
37173@@ -2939,7 +2939,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
37174 if ((desc == 0) || (desc > iadev->num_tx_desc))
37175 {
37176 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
37177- atomic_inc(&vcc->stats->tx);
37178+ atomic_inc_unchecked(&vcc->stats->tx);
37179 if (vcc->pop)
37180 vcc->pop(vcc, skb);
37181 else
37182@@ -3044,14 +3044,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
37183 ATM_DESC(skb) = vcc->vci;
37184 skb_queue_tail(&iadev->tx_dma_q, skb);
37185
37186- atomic_inc(&vcc->stats->tx);
37187+ atomic_inc_unchecked(&vcc->stats->tx);
37188 iadev->tx_pkt_cnt++;
37189 /* Increment transaction counter */
37190 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
37191
37192 #if 0
37193 /* add flow control logic */
37194- if (atomic_read(&vcc->stats->tx) % 20 == 0) {
37195+ if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
37196 if (iavcc->vc_desc_cnt > 10) {
37197 vcc->tx_quota = vcc->tx_quota * 3 / 4;
37198 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
37199diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
37200index 93eaf8d..b4ca7da 100644
37201--- a/drivers/atm/lanai.c
37202+++ b/drivers/atm/lanai.c
37203@@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
37204 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
37205 lanai_endtx(lanai, lvcc);
37206 lanai_free_skb(lvcc->tx.atmvcc, skb);
37207- atomic_inc(&lvcc->tx.atmvcc->stats->tx);
37208+ atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
37209 }
37210
37211 /* Try to fill the buffer - don't call unless there is backlog */
37212@@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
37213 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
37214 __net_timestamp(skb);
37215 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
37216- atomic_inc(&lvcc->rx.atmvcc->stats->rx);
37217+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
37218 out:
37219 lvcc->rx.buf.ptr = end;
37220 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
37221@@ -1667,7 +1667,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
37222 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
37223 "vcc %d\n", lanai->number, (unsigned int) s, vci);
37224 lanai->stats.service_rxnotaal5++;
37225- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
37226+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
37227 return 0;
37228 }
37229 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
37230@@ -1679,7 +1679,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
37231 int bytes;
37232 read_unlock(&vcc_sklist_lock);
37233 DPRINTK("got trashed rx pdu on vci %d\n", vci);
37234- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
37235+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
37236 lvcc->stats.x.aal5.service_trash++;
37237 bytes = (SERVICE_GET_END(s) * 16) -
37238 (((unsigned long) lvcc->rx.buf.ptr) -
37239@@ -1691,7 +1691,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
37240 }
37241 if (s & SERVICE_STREAM) {
37242 read_unlock(&vcc_sklist_lock);
37243- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
37244+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
37245 lvcc->stats.x.aal5.service_stream++;
37246 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
37247 "PDU on VCI %d!\n", lanai->number, vci);
37248@@ -1699,7 +1699,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
37249 return 0;
37250 }
37251 DPRINTK("got rx crc error on vci %d\n", vci);
37252- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
37253+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
37254 lvcc->stats.x.aal5.service_rxcrc++;
37255 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
37256 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
37257diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
37258index 9988ac9..7c52585 100644
37259--- a/drivers/atm/nicstar.c
37260+++ b/drivers/atm/nicstar.c
37261@@ -1640,7 +1640,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
37262 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
37263 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
37264 card->index);
37265- atomic_inc(&vcc->stats->tx_err);
37266+ atomic_inc_unchecked(&vcc->stats->tx_err);
37267 dev_kfree_skb_any(skb);
37268 return -EINVAL;
37269 }
37270@@ -1648,7 +1648,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
37271 if (!vc->tx) {
37272 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
37273 card->index);
37274- atomic_inc(&vcc->stats->tx_err);
37275+ atomic_inc_unchecked(&vcc->stats->tx_err);
37276 dev_kfree_skb_any(skb);
37277 return -EINVAL;
37278 }
37279@@ -1656,14 +1656,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
37280 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
37281 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
37282 card->index);
37283- atomic_inc(&vcc->stats->tx_err);
37284+ atomic_inc_unchecked(&vcc->stats->tx_err);
37285 dev_kfree_skb_any(skb);
37286 return -EINVAL;
37287 }
37288
37289 if (skb_shinfo(skb)->nr_frags != 0) {
37290 printk("nicstar%d: No scatter-gather yet.\n", card->index);
37291- atomic_inc(&vcc->stats->tx_err);
37292+ atomic_inc_unchecked(&vcc->stats->tx_err);
37293 dev_kfree_skb_any(skb);
37294 return -EINVAL;
37295 }
37296@@ -1711,11 +1711,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
37297 }
37298
37299 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
37300- atomic_inc(&vcc->stats->tx_err);
37301+ atomic_inc_unchecked(&vcc->stats->tx_err);
37302 dev_kfree_skb_any(skb);
37303 return -EIO;
37304 }
37305- atomic_inc(&vcc->stats->tx);
37306+ atomic_inc_unchecked(&vcc->stats->tx);
37307
37308 return 0;
37309 }
37310@@ -2032,14 +2032,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37311 printk
37312 ("nicstar%d: Can't allocate buffers for aal0.\n",
37313 card->index);
37314- atomic_add(i, &vcc->stats->rx_drop);
37315+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
37316 break;
37317 }
37318 if (!atm_charge(vcc, sb->truesize)) {
37319 RXPRINTK
37320 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
37321 card->index);
37322- atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
37323+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
37324 dev_kfree_skb_any(sb);
37325 break;
37326 }
37327@@ -2054,7 +2054,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37328 ATM_SKB(sb)->vcc = vcc;
37329 __net_timestamp(sb);
37330 vcc->push(vcc, sb);
37331- atomic_inc(&vcc->stats->rx);
37332+ atomic_inc_unchecked(&vcc->stats->rx);
37333 cell += ATM_CELL_PAYLOAD;
37334 }
37335
37336@@ -2071,7 +2071,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37337 if (iovb == NULL) {
37338 printk("nicstar%d: Out of iovec buffers.\n",
37339 card->index);
37340- atomic_inc(&vcc->stats->rx_drop);
37341+ atomic_inc_unchecked(&vcc->stats->rx_drop);
37342 recycle_rx_buf(card, skb);
37343 return;
37344 }
37345@@ -2095,7 +2095,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37346 small or large buffer itself. */
37347 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
37348 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
37349- atomic_inc(&vcc->stats->rx_err);
37350+ atomic_inc_unchecked(&vcc->stats->rx_err);
37351 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
37352 NS_MAX_IOVECS);
37353 NS_PRV_IOVCNT(iovb) = 0;
37354@@ -2115,7 +2115,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37355 ("nicstar%d: Expected a small buffer, and this is not one.\n",
37356 card->index);
37357 which_list(card, skb);
37358- atomic_inc(&vcc->stats->rx_err);
37359+ atomic_inc_unchecked(&vcc->stats->rx_err);
37360 recycle_rx_buf(card, skb);
37361 vc->rx_iov = NULL;
37362 recycle_iov_buf(card, iovb);
37363@@ -2128,7 +2128,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37364 ("nicstar%d: Expected a large buffer, and this is not one.\n",
37365 card->index);
37366 which_list(card, skb);
37367- atomic_inc(&vcc->stats->rx_err);
37368+ atomic_inc_unchecked(&vcc->stats->rx_err);
37369 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
37370 NS_PRV_IOVCNT(iovb));
37371 vc->rx_iov = NULL;
37372@@ -2151,7 +2151,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37373 printk(" - PDU size mismatch.\n");
37374 else
37375 printk(".\n");
37376- atomic_inc(&vcc->stats->rx_err);
37377+ atomic_inc_unchecked(&vcc->stats->rx_err);
37378 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
37379 NS_PRV_IOVCNT(iovb));
37380 vc->rx_iov = NULL;
37381@@ -2165,7 +2165,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37382 /* skb points to a small buffer */
37383 if (!atm_charge(vcc, skb->truesize)) {
37384 push_rxbufs(card, skb);
37385- atomic_inc(&vcc->stats->rx_drop);
37386+ atomic_inc_unchecked(&vcc->stats->rx_drop);
37387 } else {
37388 skb_put(skb, len);
37389 dequeue_sm_buf(card, skb);
37390@@ -2175,7 +2175,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37391 ATM_SKB(skb)->vcc = vcc;
37392 __net_timestamp(skb);
37393 vcc->push(vcc, skb);
37394- atomic_inc(&vcc->stats->rx);
37395+ atomic_inc_unchecked(&vcc->stats->rx);
37396 }
37397 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
37398 struct sk_buff *sb;
37399@@ -2186,7 +2186,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37400 if (len <= NS_SMBUFSIZE) {
37401 if (!atm_charge(vcc, sb->truesize)) {
37402 push_rxbufs(card, sb);
37403- atomic_inc(&vcc->stats->rx_drop);
37404+ atomic_inc_unchecked(&vcc->stats->rx_drop);
37405 } else {
37406 skb_put(sb, len);
37407 dequeue_sm_buf(card, sb);
37408@@ -2196,7 +2196,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37409 ATM_SKB(sb)->vcc = vcc;
37410 __net_timestamp(sb);
37411 vcc->push(vcc, sb);
37412- atomic_inc(&vcc->stats->rx);
37413+ atomic_inc_unchecked(&vcc->stats->rx);
37414 }
37415
37416 push_rxbufs(card, skb);
37417@@ -2205,7 +2205,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37418
37419 if (!atm_charge(vcc, skb->truesize)) {
37420 push_rxbufs(card, skb);
37421- atomic_inc(&vcc->stats->rx_drop);
37422+ atomic_inc_unchecked(&vcc->stats->rx_drop);
37423 } else {
37424 dequeue_lg_buf(card, skb);
37425 #ifdef NS_USE_DESTRUCTORS
37426@@ -2218,7 +2218,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37427 ATM_SKB(skb)->vcc = vcc;
37428 __net_timestamp(skb);
37429 vcc->push(vcc, skb);
37430- atomic_inc(&vcc->stats->rx);
37431+ atomic_inc_unchecked(&vcc->stats->rx);
37432 }
37433
37434 push_rxbufs(card, sb);
37435@@ -2239,7 +2239,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37436 printk
37437 ("nicstar%d: Out of huge buffers.\n",
37438 card->index);
37439- atomic_inc(&vcc->stats->rx_drop);
37440+ atomic_inc_unchecked(&vcc->stats->rx_drop);
37441 recycle_iovec_rx_bufs(card,
37442 (struct iovec *)
37443 iovb->data,
37444@@ -2290,7 +2290,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37445 card->hbpool.count++;
37446 } else
37447 dev_kfree_skb_any(hb);
37448- atomic_inc(&vcc->stats->rx_drop);
37449+ atomic_inc_unchecked(&vcc->stats->rx_drop);
37450 } else {
37451 /* Copy the small buffer to the huge buffer */
37452 sb = (struct sk_buff *)iov->iov_base;
37453@@ -2327,7 +2327,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37454 #endif /* NS_USE_DESTRUCTORS */
37455 __net_timestamp(hb);
37456 vcc->push(vcc, hb);
37457- atomic_inc(&vcc->stats->rx);
37458+ atomic_inc_unchecked(&vcc->stats->rx);
37459 }
37460 }
37461
37462diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
37463index 21b0bc6..b5f40ba 100644
37464--- a/drivers/atm/solos-pci.c
37465+++ b/drivers/atm/solos-pci.c
37466@@ -838,7 +838,7 @@ static void solos_bh(unsigned long card_arg)
37467 }
37468 atm_charge(vcc, skb->truesize);
37469 vcc->push(vcc, skb);
37470- atomic_inc(&vcc->stats->rx);
37471+ atomic_inc_unchecked(&vcc->stats->rx);
37472 break;
37473
37474 case PKT_STATUS:
37475@@ -1116,7 +1116,7 @@ static uint32_t fpga_tx(struct solos_card *card)
37476 vcc = SKB_CB(oldskb)->vcc;
37477
37478 if (vcc) {
37479- atomic_inc(&vcc->stats->tx);
37480+ atomic_inc_unchecked(&vcc->stats->tx);
37481 solos_pop(vcc, oldskb);
37482 } else {
37483 dev_kfree_skb_irq(oldskb);
37484diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
37485index 0215934..ce9f5b1 100644
37486--- a/drivers/atm/suni.c
37487+++ b/drivers/atm/suni.c
37488@@ -49,8 +49,8 @@ static DEFINE_SPINLOCK(sunis_lock);
37489
37490
37491 #define ADD_LIMITED(s,v) \
37492- atomic_add((v),&stats->s); \
37493- if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
37494+ atomic_add_unchecked((v),&stats->s); \
37495+ if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
37496
37497
37498 static void suni_hz(unsigned long from_timer)
37499diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
37500index 5120a96..e2572bd 100644
37501--- a/drivers/atm/uPD98402.c
37502+++ b/drivers/atm/uPD98402.c
37503@@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
37504 struct sonet_stats tmp;
37505 int error = 0;
37506
37507- atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
37508+ atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
37509 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
37510 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
37511 if (zero && !error) {
37512@@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
37513
37514
37515 #define ADD_LIMITED(s,v) \
37516- { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
37517- if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
37518- atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
37519+ { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
37520+ if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
37521+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
37522
37523
37524 static void stat_event(struct atm_dev *dev)
37525@@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
37526 if (reason & uPD98402_INT_PFM) stat_event(dev);
37527 if (reason & uPD98402_INT_PCO) {
37528 (void) GET(PCOCR); /* clear interrupt cause */
37529- atomic_add(GET(HECCT),
37530+ atomic_add_unchecked(GET(HECCT),
37531 &PRIV(dev)->sonet_stats.uncorr_hcs);
37532 }
37533 if ((reason & uPD98402_INT_RFO) &&
37534@@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
37535 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
37536 uPD98402_INT_LOS),PIMR); /* enable them */
37537 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
37538- atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
37539- atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
37540- atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
37541+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
37542+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
37543+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
37544 return 0;
37545 }
37546
37547diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
37548index 969c3c2..9b72956 100644
37549--- a/drivers/atm/zatm.c
37550+++ b/drivers/atm/zatm.c
37551@@ -459,7 +459,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
37552 }
37553 if (!size) {
37554 dev_kfree_skb_irq(skb);
37555- if (vcc) atomic_inc(&vcc->stats->rx_err);
37556+ if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
37557 continue;
37558 }
37559 if (!atm_charge(vcc,skb->truesize)) {
37560@@ -469,7 +469,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
37561 skb->len = size;
37562 ATM_SKB(skb)->vcc = vcc;
37563 vcc->push(vcc,skb);
37564- atomic_inc(&vcc->stats->rx);
37565+ atomic_inc_unchecked(&vcc->stats->rx);
37566 }
37567 zout(pos & 0xffff,MTA(mbx));
37568 #if 0 /* probably a stupid idea */
37569@@ -733,7 +733,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
37570 skb_queue_head(&zatm_vcc->backlog,skb);
37571 break;
37572 }
37573- atomic_inc(&vcc->stats->tx);
37574+ atomic_inc_unchecked(&vcc->stats->tx);
37575 wake_up(&zatm_vcc->tx_wait);
37576 }
37577
37578diff --git a/drivers/base/bus.c b/drivers/base/bus.c
37579index 83e910a..b224a73 100644
37580--- a/drivers/base/bus.c
37581+++ b/drivers/base/bus.c
37582@@ -1124,7 +1124,7 @@ int subsys_interface_register(struct subsys_interface *sif)
37583 return -EINVAL;
37584
37585 mutex_lock(&subsys->p->mutex);
37586- list_add_tail(&sif->node, &subsys->p->interfaces);
37587+ pax_list_add_tail((struct list_head *)&sif->node, &subsys->p->interfaces);
37588 if (sif->add_dev) {
37589 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
37590 while ((dev = subsys_dev_iter_next(&iter)))
37591@@ -1149,7 +1149,7 @@ void subsys_interface_unregister(struct subsys_interface *sif)
37592 subsys = sif->subsys;
37593
37594 mutex_lock(&subsys->p->mutex);
37595- list_del_init(&sif->node);
37596+ pax_list_del_init((struct list_head *)&sif->node);
37597 if (sif->remove_dev) {
37598 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
37599 while ((dev = subsys_dev_iter_next(&iter)))
37600diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
37601index 25798db..15f130e 100644
37602--- a/drivers/base/devtmpfs.c
37603+++ b/drivers/base/devtmpfs.c
37604@@ -354,7 +354,7 @@ int devtmpfs_mount(const char *mntdir)
37605 if (!thread)
37606 return 0;
37607
37608- err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
37609+ err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
37610 if (err)
37611 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
37612 else
37613@@ -380,11 +380,11 @@ static int devtmpfsd(void *p)
37614 *err = sys_unshare(CLONE_NEWNS);
37615 if (*err)
37616 goto out;
37617- *err = sys_mount("devtmpfs", "/", "devtmpfs", MS_SILENT, options);
37618+ *err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)"/", (char __force_user *)"devtmpfs", MS_SILENT, (char __force_user *)options);
37619 if (*err)
37620 goto out;
37621- sys_chdir("/.."); /* will traverse into overmounted root */
37622- sys_chroot(".");
37623+ sys_chdir((char __force_user *)"/.."); /* will traverse into overmounted root */
37624+ sys_chroot((char __force_user *)".");
37625 complete(&setup_done);
37626 while (1) {
37627 spin_lock(&req_lock);
37628diff --git a/drivers/base/node.c b/drivers/base/node.c
37629index 472168c..4af587e 100644
37630--- a/drivers/base/node.c
37631+++ b/drivers/base/node.c
37632@@ -620,7 +620,7 @@ static ssize_t print_nodes_state(enum node_states state, char *buf)
37633 struct node_attr {
37634 struct device_attribute attr;
37635 enum node_states state;
37636-};
37637+} __do_const;
37638
37639 static ssize_t show_node_state(struct device *dev,
37640 struct device_attribute *attr, char *buf)
37641diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c
37642index fb83d4a..4aa50ec 100644
37643--- a/drivers/base/power/domain.c
37644+++ b/drivers/base/power/domain.c
37645@@ -1725,7 +1725,7 @@ int pm_genpd_attach_cpuidle(struct generic_pm_domain *genpd, int state)
37646 {
37647 struct cpuidle_driver *cpuidle_drv;
37648 struct gpd_cpuidle_data *cpuidle_data;
37649- struct cpuidle_state *idle_state;
37650+ cpuidle_state_no_const *idle_state;
37651 int ret = 0;
37652
37653 if (IS_ERR_OR_NULL(genpd) || state < 0)
37654@@ -1793,7 +1793,7 @@ int pm_genpd_name_attach_cpuidle(const char *name, int state)
37655 int pm_genpd_detach_cpuidle(struct generic_pm_domain *genpd)
37656 {
37657 struct gpd_cpuidle_data *cpuidle_data;
37658- struct cpuidle_state *idle_state;
37659+ cpuidle_state_no_const *idle_state;
37660 int ret = 0;
37661
37662 if (IS_ERR_OR_NULL(genpd))
37663diff --git a/drivers/base/power/sysfs.c b/drivers/base/power/sysfs.c
37664index a9d26ed..74b8405 100644
37665--- a/drivers/base/power/sysfs.c
37666+++ b/drivers/base/power/sysfs.c
37667@@ -182,7 +182,7 @@ static ssize_t rtpm_status_show(struct device *dev,
37668 return -EIO;
37669 }
37670 }
37671- return sprintf(buf, p);
37672+ return sprintf(buf, "%s", p);
37673 }
37674
37675 static DEVICE_ATTR(runtime_status, 0444, rtpm_status_show, NULL);
37676diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
37677index c2744b3..08fac19 100644
37678--- a/drivers/base/power/wakeup.c
37679+++ b/drivers/base/power/wakeup.c
37680@@ -32,14 +32,14 @@ static bool pm_abort_suspend __read_mostly;
37681 * They need to be modified together atomically, so it's better to use one
37682 * atomic variable to hold them both.
37683 */
37684-static atomic_t combined_event_count = ATOMIC_INIT(0);
37685+static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
37686
37687 #define IN_PROGRESS_BITS (sizeof(int) * 4)
37688 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
37689
37690 static void split_counters(unsigned int *cnt, unsigned int *inpr)
37691 {
37692- unsigned int comb = atomic_read(&combined_event_count);
37693+ unsigned int comb = atomic_read_unchecked(&combined_event_count);
37694
37695 *cnt = (comb >> IN_PROGRESS_BITS);
37696 *inpr = comb & MAX_IN_PROGRESS;
37697@@ -404,7 +404,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
37698 ws->start_prevent_time = ws->last_time;
37699
37700 /* Increment the counter of events in progress. */
37701- cec = atomic_inc_return(&combined_event_count);
37702+ cec = atomic_inc_return_unchecked(&combined_event_count);
37703
37704 trace_wakeup_source_activate(ws->name, cec);
37705 }
37706@@ -530,7 +530,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
37707 * Increment the counter of registered wakeup events and decrement the
37708 * couter of wakeup events in progress simultaneously.
37709 */
37710- cec = atomic_add_return(MAX_IN_PROGRESS, &combined_event_count);
37711+ cec = atomic_add_return_unchecked(MAX_IN_PROGRESS, &combined_event_count);
37712 trace_wakeup_source_deactivate(ws->name, cec);
37713
37714 split_counters(&cnt, &inpr);
37715diff --git a/drivers/base/syscore.c b/drivers/base/syscore.c
37716index 8d98a32..61d3165 100644
37717--- a/drivers/base/syscore.c
37718+++ b/drivers/base/syscore.c
37719@@ -22,7 +22,7 @@ static DEFINE_MUTEX(syscore_ops_lock);
37720 void register_syscore_ops(struct syscore_ops *ops)
37721 {
37722 mutex_lock(&syscore_ops_lock);
37723- list_add_tail(&ops->node, &syscore_ops_list);
37724+ pax_list_add_tail((struct list_head *)&ops->node, &syscore_ops_list);
37725 mutex_unlock(&syscore_ops_lock);
37726 }
37727 EXPORT_SYMBOL_GPL(register_syscore_ops);
37728@@ -34,7 +34,7 @@ EXPORT_SYMBOL_GPL(register_syscore_ops);
37729 void unregister_syscore_ops(struct syscore_ops *ops)
37730 {
37731 mutex_lock(&syscore_ops_lock);
37732- list_del(&ops->node);
37733+ pax_list_del((struct list_head *)&ops->node);
37734 mutex_unlock(&syscore_ops_lock);
37735 }
37736 EXPORT_SYMBOL_GPL(unregister_syscore_ops);
37737diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
37738index ff20f19..018f1da 100644
37739--- a/drivers/block/cciss.c
37740+++ b/drivers/block/cciss.c
37741@@ -3008,7 +3008,7 @@ static void start_io(ctlr_info_t *h)
37742 while (!list_empty(&h->reqQ)) {
37743 c = list_entry(h->reqQ.next, CommandList_struct, list);
37744 /* can't do anything if fifo is full */
37745- if ((h->access.fifo_full(h))) {
37746+ if ((h->access->fifo_full(h))) {
37747 dev_warn(&h->pdev->dev, "fifo full\n");
37748 break;
37749 }
37750@@ -3018,7 +3018,7 @@ static void start_io(ctlr_info_t *h)
37751 h->Qdepth--;
37752
37753 /* Tell the controller execute command */
37754- h->access.submit_command(h, c);
37755+ h->access->submit_command(h, c);
37756
37757 /* Put job onto the completed Q */
37758 addQ(&h->cmpQ, c);
37759@@ -3444,17 +3444,17 @@ startio:
37760
37761 static inline unsigned long get_next_completion(ctlr_info_t *h)
37762 {
37763- return h->access.command_completed(h);
37764+ return h->access->command_completed(h);
37765 }
37766
37767 static inline int interrupt_pending(ctlr_info_t *h)
37768 {
37769- return h->access.intr_pending(h);
37770+ return h->access->intr_pending(h);
37771 }
37772
37773 static inline long interrupt_not_for_us(ctlr_info_t *h)
37774 {
37775- return ((h->access.intr_pending(h) == 0) ||
37776+ return ((h->access->intr_pending(h) == 0) ||
37777 (h->interrupts_enabled == 0));
37778 }
37779
37780@@ -3487,7 +3487,7 @@ static inline u32 next_command(ctlr_info_t *h)
37781 u32 a;
37782
37783 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
37784- return h->access.command_completed(h);
37785+ return h->access->command_completed(h);
37786
37787 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
37788 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
37789@@ -4044,7 +4044,7 @@ static void cciss_put_controller_into_performant_mode(ctlr_info_t *h)
37790 trans_support & CFGTBL_Trans_use_short_tags);
37791
37792 /* Change the access methods to the performant access methods */
37793- h->access = SA5_performant_access;
37794+ h->access = &SA5_performant_access;
37795 h->transMethod = CFGTBL_Trans_Performant;
37796
37797 return;
37798@@ -4318,7 +4318,7 @@ static int cciss_pci_init(ctlr_info_t *h)
37799 if (prod_index < 0)
37800 return -ENODEV;
37801 h->product_name = products[prod_index].product_name;
37802- h->access = *(products[prod_index].access);
37803+ h->access = products[prod_index].access;
37804
37805 if (cciss_board_disabled(h)) {
37806 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
37807@@ -5050,7 +5050,7 @@ reinit_after_soft_reset:
37808 }
37809
37810 /* make sure the board interrupts are off */
37811- h->access.set_intr_mask(h, CCISS_INTR_OFF);
37812+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
37813 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
37814 if (rc)
37815 goto clean2;
37816@@ -5100,7 +5100,7 @@ reinit_after_soft_reset:
37817 * fake ones to scoop up any residual completions.
37818 */
37819 spin_lock_irqsave(&h->lock, flags);
37820- h->access.set_intr_mask(h, CCISS_INTR_OFF);
37821+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
37822 spin_unlock_irqrestore(&h->lock, flags);
37823 free_irq(h->intr[h->intr_mode], h);
37824 rc = cciss_request_irq(h, cciss_msix_discard_completions,
37825@@ -5120,9 +5120,9 @@ reinit_after_soft_reset:
37826 dev_info(&h->pdev->dev, "Board READY.\n");
37827 dev_info(&h->pdev->dev,
37828 "Waiting for stale completions to drain.\n");
37829- h->access.set_intr_mask(h, CCISS_INTR_ON);
37830+ h->access->set_intr_mask(h, CCISS_INTR_ON);
37831 msleep(10000);
37832- h->access.set_intr_mask(h, CCISS_INTR_OFF);
37833+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
37834
37835 rc = controller_reset_failed(h->cfgtable);
37836 if (rc)
37837@@ -5145,7 +5145,7 @@ reinit_after_soft_reset:
37838 cciss_scsi_setup(h);
37839
37840 /* Turn the interrupts on so we can service requests */
37841- h->access.set_intr_mask(h, CCISS_INTR_ON);
37842+ h->access->set_intr_mask(h, CCISS_INTR_ON);
37843
37844 /* Get the firmware version */
37845 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
37846@@ -5217,7 +5217,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
37847 kfree(flush_buf);
37848 if (return_code != IO_OK)
37849 dev_warn(&h->pdev->dev, "Error flushing cache\n");
37850- h->access.set_intr_mask(h, CCISS_INTR_OFF);
37851+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
37852 free_irq(h->intr[h->intr_mode], h);
37853 }
37854
37855diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
37856index 7fda30e..2f27946 100644
37857--- a/drivers/block/cciss.h
37858+++ b/drivers/block/cciss.h
37859@@ -101,7 +101,7 @@ struct ctlr_info
37860 /* information about each logical volume */
37861 drive_info_struct *drv[CISS_MAX_LUN];
37862
37863- struct access_method access;
37864+ struct access_method *access;
37865
37866 /* queue and queue Info */
37867 struct list_head reqQ;
37868@@ -402,27 +402,27 @@ static bool SA5_performant_intr_pending(ctlr_info_t *h)
37869 }
37870
37871 static struct access_method SA5_access = {
37872- SA5_submit_command,
37873- SA5_intr_mask,
37874- SA5_fifo_full,
37875- SA5_intr_pending,
37876- SA5_completed,
37877+ .submit_command = SA5_submit_command,
37878+ .set_intr_mask = SA5_intr_mask,
37879+ .fifo_full = SA5_fifo_full,
37880+ .intr_pending = SA5_intr_pending,
37881+ .command_completed = SA5_completed,
37882 };
37883
37884 static struct access_method SA5B_access = {
37885- SA5_submit_command,
37886- SA5B_intr_mask,
37887- SA5_fifo_full,
37888- SA5B_intr_pending,
37889- SA5_completed,
37890+ .submit_command = SA5_submit_command,
37891+ .set_intr_mask = SA5B_intr_mask,
37892+ .fifo_full = SA5_fifo_full,
37893+ .intr_pending = SA5B_intr_pending,
37894+ .command_completed = SA5_completed,
37895 };
37896
37897 static struct access_method SA5_performant_access = {
37898- SA5_submit_command,
37899- SA5_performant_intr_mask,
37900- SA5_fifo_full,
37901- SA5_performant_intr_pending,
37902- SA5_performant_completed,
37903+ .submit_command = SA5_submit_command,
37904+ .set_intr_mask = SA5_performant_intr_mask,
37905+ .fifo_full = SA5_fifo_full,
37906+ .intr_pending = SA5_performant_intr_pending,
37907+ .command_completed = SA5_performant_completed,
37908 };
37909
37910 struct board_type {
37911diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
37912index 2b94403..fd6ad1f 100644
37913--- a/drivers/block/cpqarray.c
37914+++ b/drivers/block/cpqarray.c
37915@@ -404,7 +404,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
37916 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
37917 goto Enomem4;
37918 }
37919- hba[i]->access.set_intr_mask(hba[i], 0);
37920+ hba[i]->access->set_intr_mask(hba[i], 0);
37921 if (request_irq(hba[i]->intr, do_ida_intr,
37922 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
37923 {
37924@@ -459,7 +459,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
37925 add_timer(&hba[i]->timer);
37926
37927 /* Enable IRQ now that spinlock and rate limit timer are set up */
37928- hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
37929+ hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
37930
37931 for(j=0; j<NWD; j++) {
37932 struct gendisk *disk = ida_gendisk[i][j];
37933@@ -694,7 +694,7 @@ DBGINFO(
37934 for(i=0; i<NR_PRODUCTS; i++) {
37935 if (board_id == products[i].board_id) {
37936 c->product_name = products[i].product_name;
37937- c->access = *(products[i].access);
37938+ c->access = products[i].access;
37939 break;
37940 }
37941 }
37942@@ -792,7 +792,7 @@ static int cpqarray_eisa_detect(void)
37943 hba[ctlr]->intr = intr;
37944 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
37945 hba[ctlr]->product_name = products[j].product_name;
37946- hba[ctlr]->access = *(products[j].access);
37947+ hba[ctlr]->access = products[j].access;
37948 hba[ctlr]->ctlr = ctlr;
37949 hba[ctlr]->board_id = board_id;
37950 hba[ctlr]->pci_dev = NULL; /* not PCI */
37951@@ -978,7 +978,7 @@ static void start_io(ctlr_info_t *h)
37952
37953 while((c = h->reqQ) != NULL) {
37954 /* Can't do anything if we're busy */
37955- if (h->access.fifo_full(h) == 0)
37956+ if (h->access->fifo_full(h) == 0)
37957 return;
37958
37959 /* Get the first entry from the request Q */
37960@@ -986,7 +986,7 @@ static void start_io(ctlr_info_t *h)
37961 h->Qdepth--;
37962
37963 /* Tell the controller to do our bidding */
37964- h->access.submit_command(h, c);
37965+ h->access->submit_command(h, c);
37966
37967 /* Get onto the completion Q */
37968 addQ(&h->cmpQ, c);
37969@@ -1048,7 +1048,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
37970 unsigned long flags;
37971 __u32 a,a1;
37972
37973- istat = h->access.intr_pending(h);
37974+ istat = h->access->intr_pending(h);
37975 /* Is this interrupt for us? */
37976 if (istat == 0)
37977 return IRQ_NONE;
37978@@ -1059,7 +1059,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
37979 */
37980 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
37981 if (istat & FIFO_NOT_EMPTY) {
37982- while((a = h->access.command_completed(h))) {
37983+ while((a = h->access->command_completed(h))) {
37984 a1 = a; a &= ~3;
37985 if ((c = h->cmpQ) == NULL)
37986 {
37987@@ -1448,11 +1448,11 @@ static int sendcmd(
37988 /*
37989 * Disable interrupt
37990 */
37991- info_p->access.set_intr_mask(info_p, 0);
37992+ info_p->access->set_intr_mask(info_p, 0);
37993 /* Make sure there is room in the command FIFO */
37994 /* Actually it should be completely empty at this time. */
37995 for (i = 200000; i > 0; i--) {
37996- temp = info_p->access.fifo_full(info_p);
37997+ temp = info_p->access->fifo_full(info_p);
37998 if (temp != 0) {
37999 break;
38000 }
38001@@ -1465,7 +1465,7 @@ DBG(
38002 /*
38003 * Send the cmd
38004 */
38005- info_p->access.submit_command(info_p, c);
38006+ info_p->access->submit_command(info_p, c);
38007 complete = pollcomplete(ctlr);
38008
38009 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
38010@@ -1548,9 +1548,9 @@ static int revalidate_allvol(ctlr_info_t *host)
38011 * we check the new geometry. Then turn interrupts back on when
38012 * we're done.
38013 */
38014- host->access.set_intr_mask(host, 0);
38015+ host->access->set_intr_mask(host, 0);
38016 getgeometry(ctlr);
38017- host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
38018+ host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
38019
38020 for(i=0; i<NWD; i++) {
38021 struct gendisk *disk = ida_gendisk[ctlr][i];
38022@@ -1590,7 +1590,7 @@ static int pollcomplete(int ctlr)
38023 /* Wait (up to 2 seconds) for a command to complete */
38024
38025 for (i = 200000; i > 0; i--) {
38026- done = hba[ctlr]->access.command_completed(hba[ctlr]);
38027+ done = hba[ctlr]->access->command_completed(hba[ctlr]);
38028 if (done == 0) {
38029 udelay(10); /* a short fixed delay */
38030 } else
38031diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
38032index be73e9d..7fbf140 100644
38033--- a/drivers/block/cpqarray.h
38034+++ b/drivers/block/cpqarray.h
38035@@ -99,7 +99,7 @@ struct ctlr_info {
38036 drv_info_t drv[NWD];
38037 struct proc_dir_entry *proc;
38038
38039- struct access_method access;
38040+ struct access_method *access;
38041
38042 cmdlist_t *reqQ;
38043 cmdlist_t *cmpQ;
38044diff --git a/drivers/block/drbd/drbd_bitmap.c b/drivers/block/drbd/drbd_bitmap.c
38045index 434c77d..6d3219a 100644
38046--- a/drivers/block/drbd/drbd_bitmap.c
38047+++ b/drivers/block/drbd/drbd_bitmap.c
38048@@ -1036,7 +1036,7 @@ static void bm_page_io_async(struct drbd_bm_aio_ctx *ctx, int page_nr) __must_ho
38049 submit_bio(rw, bio);
38050 /* this should not count as user activity and cause the
38051 * resync to throttle -- see drbd_rs_should_slow_down(). */
38052- atomic_add(len >> 9, &device->rs_sect_ev);
38053+ atomic_add_unchecked(len >> 9, &device->rs_sect_ev);
38054 }
38055 }
38056
38057diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
38058index 9b22f8f..f2932af 100644
38059--- a/drivers/block/drbd/drbd_int.h
38060+++ b/drivers/block/drbd/drbd_int.h
38061@@ -385,7 +385,7 @@ struct drbd_epoch {
38062 struct drbd_connection *connection;
38063 struct list_head list;
38064 unsigned int barrier_nr;
38065- atomic_t epoch_size; /* increased on every request added. */
38066+ atomic_unchecked_t epoch_size; /* increased on every request added. */
38067 atomic_t active; /* increased on every req. added, and dec on every finished. */
38068 unsigned long flags;
38069 };
38070@@ -946,7 +946,7 @@ struct drbd_device {
38071 unsigned int al_tr_number;
38072 int al_tr_cycle;
38073 wait_queue_head_t seq_wait;
38074- atomic_t packet_seq;
38075+ atomic_unchecked_t packet_seq;
38076 unsigned int peer_seq;
38077 spinlock_t peer_seq_lock;
38078 unsigned long comm_bm_set; /* communicated number of set bits. */
38079@@ -955,8 +955,8 @@ struct drbd_device {
38080 struct mutex own_state_mutex;
38081 struct mutex *state_mutex; /* either own_state_mutex or first_peer_device(device)->connection->cstate_mutex */
38082 char congestion_reason; /* Why we where congested... */
38083- atomic_t rs_sect_in; /* for incoming resync data rate, SyncTarget */
38084- atomic_t rs_sect_ev; /* for submitted resync data rate, both */
38085+ atomic_unchecked_t rs_sect_in; /* for incoming resync data rate, SyncTarget */
38086+ atomic_unchecked_t rs_sect_ev; /* for submitted resync data rate, both */
38087 int rs_last_sect_ev; /* counter to compare with */
38088 int rs_last_events; /* counter of read or write "events" (unit sectors)
38089 * on the lower level device when we last looked. */
38090@@ -1567,7 +1567,7 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
38091 char __user *uoptval;
38092 int err;
38093
38094- uoptval = (char __user __force *)optval;
38095+ uoptval = (char __force_user *)optval;
38096
38097 set_fs(KERNEL_DS);
38098 if (level == SOL_SOCKET)
38099diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
38100index 973c185..05d8b1a 100644
38101--- a/drivers/block/drbd/drbd_main.c
38102+++ b/drivers/block/drbd/drbd_main.c
38103@@ -1328,7 +1328,7 @@ static int _drbd_send_ack(struct drbd_peer_device *peer_device, enum drbd_packet
38104 p->sector = sector;
38105 p->block_id = block_id;
38106 p->blksize = blksize;
38107- p->seq_num = cpu_to_be32(atomic_inc_return(&peer_device->device->packet_seq));
38108+ p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&peer_device->device->packet_seq));
38109 return drbd_send_command(peer_device, sock, cmd, sizeof(*p), NULL, 0);
38110 }
38111
38112@@ -1634,7 +1634,7 @@ int drbd_send_dblock(struct drbd_peer_device *peer_device, struct drbd_request *
38113 return -EIO;
38114 p->sector = cpu_to_be64(req->i.sector);
38115 p->block_id = (unsigned long)req;
38116- p->seq_num = cpu_to_be32(atomic_inc_return(&device->packet_seq));
38117+ p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&device->packet_seq));
38118 dp_flags = bio_flags_to_wire(peer_device->connection, req->master_bio->bi_rw);
38119 if (device->state.conn >= C_SYNC_SOURCE &&
38120 device->state.conn <= C_PAUSED_SYNC_T)
38121@@ -1915,8 +1915,8 @@ void drbd_init_set_defaults(struct drbd_device *device)
38122 atomic_set(&device->unacked_cnt, 0);
38123 atomic_set(&device->local_cnt, 0);
38124 atomic_set(&device->pp_in_use_by_net, 0);
38125- atomic_set(&device->rs_sect_in, 0);
38126- atomic_set(&device->rs_sect_ev, 0);
38127+ atomic_set_unchecked(&device->rs_sect_in, 0);
38128+ atomic_set_unchecked(&device->rs_sect_ev, 0);
38129 atomic_set(&device->ap_in_flight, 0);
38130 atomic_set(&device->md_io.in_use, 0);
38131
38132@@ -2688,8 +2688,8 @@ void drbd_destroy_connection(struct kref *kref)
38133 struct drbd_connection *connection = container_of(kref, struct drbd_connection, kref);
38134 struct drbd_resource *resource = connection->resource;
38135
38136- if (atomic_read(&connection->current_epoch->epoch_size) != 0)
38137- drbd_err(connection, "epoch_size:%d\n", atomic_read(&connection->current_epoch->epoch_size));
38138+ if (atomic_read_unchecked(&connection->current_epoch->epoch_size) != 0)
38139+ drbd_err(connection, "epoch_size:%d\n", atomic_read_unchecked(&connection->current_epoch->epoch_size));
38140 kfree(connection->current_epoch);
38141
38142 idr_destroy(&connection->peer_devices);
38143diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
38144index 1cd47df..57c53c0 100644
38145--- a/drivers/block/drbd/drbd_nl.c
38146+++ b/drivers/block/drbd/drbd_nl.c
38147@@ -3645,13 +3645,13 @@ finish:
38148
38149 void drbd_bcast_event(struct drbd_device *device, const struct sib_info *sib)
38150 {
38151- static atomic_t drbd_genl_seq = ATOMIC_INIT(2); /* two. */
38152+ static atomic_unchecked_t drbd_genl_seq = ATOMIC_INIT(2); /* two. */
38153 struct sk_buff *msg;
38154 struct drbd_genlmsghdr *d_out;
38155 unsigned seq;
38156 int err = -ENOMEM;
38157
38158- seq = atomic_inc_return(&drbd_genl_seq);
38159+ seq = atomic_inc_return_unchecked(&drbd_genl_seq);
38160 msg = genlmsg_new(NLMSG_GOODSIZE, GFP_NOIO);
38161 if (!msg)
38162 goto failed;
38163diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
38164index 6960fb0..215d76b 100644
38165--- a/drivers/block/drbd/drbd_receiver.c
38166+++ b/drivers/block/drbd/drbd_receiver.c
38167@@ -870,7 +870,7 @@ int drbd_connected(struct drbd_peer_device *peer_device)
38168 struct drbd_device *device = peer_device->device;
38169 int err;
38170
38171- atomic_set(&device->packet_seq, 0);
38172+ atomic_set_unchecked(&device->packet_seq, 0);
38173 device->peer_seq = 0;
38174
38175 device->state_mutex = peer_device->connection->agreed_pro_version < 100 ?
38176@@ -1233,7 +1233,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_connection *connectio
38177 do {
38178 next_epoch = NULL;
38179
38180- epoch_size = atomic_read(&epoch->epoch_size);
38181+ epoch_size = atomic_read_unchecked(&epoch->epoch_size);
38182
38183 switch (ev & ~EV_CLEANUP) {
38184 case EV_PUT:
38185@@ -1273,7 +1273,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_connection *connectio
38186 rv = FE_DESTROYED;
38187 } else {
38188 epoch->flags = 0;
38189- atomic_set(&epoch->epoch_size, 0);
38190+ atomic_set_unchecked(&epoch->epoch_size, 0);
38191 /* atomic_set(&epoch->active, 0); is already zero */
38192 if (rv == FE_STILL_LIVE)
38193 rv = FE_RECYCLED;
38194@@ -1550,7 +1550,7 @@ static int receive_Barrier(struct drbd_connection *connection, struct packet_inf
38195 conn_wait_active_ee_empty(connection);
38196 drbd_flush(connection);
38197
38198- if (atomic_read(&connection->current_epoch->epoch_size)) {
38199+ if (atomic_read_unchecked(&connection->current_epoch->epoch_size)) {
38200 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
38201 if (epoch)
38202 break;
38203@@ -1564,11 +1564,11 @@ static int receive_Barrier(struct drbd_connection *connection, struct packet_inf
38204 }
38205
38206 epoch->flags = 0;
38207- atomic_set(&epoch->epoch_size, 0);
38208+ atomic_set_unchecked(&epoch->epoch_size, 0);
38209 atomic_set(&epoch->active, 0);
38210
38211 spin_lock(&connection->epoch_lock);
38212- if (atomic_read(&connection->current_epoch->epoch_size)) {
38213+ if (atomic_read_unchecked(&connection->current_epoch->epoch_size)) {
38214 list_add(&epoch->list, &connection->current_epoch->list);
38215 connection->current_epoch = epoch;
38216 connection->epochs++;
38217@@ -1802,7 +1802,7 @@ static int recv_resync_read(struct drbd_peer_device *peer_device, sector_t secto
38218 list_add_tail(&peer_req->w.list, &device->sync_ee);
38219 spin_unlock_irq(&device->resource->req_lock);
38220
38221- atomic_add(pi->size >> 9, &device->rs_sect_ev);
38222+ atomic_add_unchecked(pi->size >> 9, &device->rs_sect_ev);
38223 if (drbd_submit_peer_request(device, peer_req, WRITE, DRBD_FAULT_RS_WR) == 0)
38224 return 0;
38225
38226@@ -1900,7 +1900,7 @@ static int receive_RSDataReply(struct drbd_connection *connection, struct packet
38227 drbd_send_ack_dp(peer_device, P_NEG_ACK, p, pi->size);
38228 }
38229
38230- atomic_add(pi->size >> 9, &device->rs_sect_in);
38231+ atomic_add_unchecked(pi->size >> 9, &device->rs_sect_in);
38232
38233 return err;
38234 }
38235@@ -2290,7 +2290,7 @@ static int receive_Data(struct drbd_connection *connection, struct packet_info *
38236
38237 err = wait_for_and_update_peer_seq(peer_device, peer_seq);
38238 drbd_send_ack_dp(peer_device, P_NEG_ACK, p, pi->size);
38239- atomic_inc(&connection->current_epoch->epoch_size);
38240+ atomic_inc_unchecked(&connection->current_epoch->epoch_size);
38241 err2 = drbd_drain_block(peer_device, pi->size);
38242 if (!err)
38243 err = err2;
38244@@ -2334,7 +2334,7 @@ static int receive_Data(struct drbd_connection *connection, struct packet_info *
38245
38246 spin_lock(&connection->epoch_lock);
38247 peer_req->epoch = connection->current_epoch;
38248- atomic_inc(&peer_req->epoch->epoch_size);
38249+ atomic_inc_unchecked(&peer_req->epoch->epoch_size);
38250 atomic_inc(&peer_req->epoch->active);
38251 spin_unlock(&connection->epoch_lock);
38252
38253@@ -2479,7 +2479,7 @@ bool drbd_rs_c_min_rate_throttle(struct drbd_device *device)
38254
38255 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
38256 (int)part_stat_read(&disk->part0, sectors[1]) -
38257- atomic_read(&device->rs_sect_ev);
38258+ atomic_read_unchecked(&device->rs_sect_ev);
38259
38260 if (atomic_read(&device->ap_actlog_cnt)
38261 || !device->rs_last_events || curr_events - device->rs_last_events > 64) {
38262@@ -2618,7 +2618,7 @@ static int receive_DataRequest(struct drbd_connection *connection, struct packet
38263 device->use_csums = true;
38264 } else if (pi->cmd == P_OV_REPLY) {
38265 /* track progress, we may need to throttle */
38266- atomic_add(size >> 9, &device->rs_sect_in);
38267+ atomic_add_unchecked(size >> 9, &device->rs_sect_in);
38268 peer_req->w.cb = w_e_end_ov_reply;
38269 dec_rs_pending(device);
38270 /* drbd_rs_begin_io done when we sent this request,
38271@@ -2691,7 +2691,7 @@ static int receive_DataRequest(struct drbd_connection *connection, struct packet
38272 goto out_free_e;
38273
38274 submit_for_resync:
38275- atomic_add(size >> 9, &device->rs_sect_ev);
38276+ atomic_add_unchecked(size >> 9, &device->rs_sect_ev);
38277
38278 submit:
38279 update_receiver_timing_details(connection, drbd_submit_peer_request);
38280@@ -4564,7 +4564,7 @@ struct data_cmd {
38281 int expect_payload;
38282 size_t pkt_size;
38283 int (*fn)(struct drbd_connection *, struct packet_info *);
38284-};
38285+} __do_const;
38286
38287 static struct data_cmd drbd_cmd_handler[] = {
38288 [P_DATA] = { 1, sizeof(struct p_data), receive_Data },
38289@@ -4678,7 +4678,7 @@ static void conn_disconnect(struct drbd_connection *connection)
38290 if (!list_empty(&connection->current_epoch->list))
38291 drbd_err(connection, "ASSERTION FAILED: connection->current_epoch->list not empty\n");
38292 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
38293- atomic_set(&connection->current_epoch->epoch_size, 0);
38294+ atomic_set_unchecked(&connection->current_epoch->epoch_size, 0);
38295 connection->send.seen_any_write_yet = false;
38296
38297 drbd_info(connection, "Connection closed\n");
38298@@ -5182,7 +5182,7 @@ static int got_IsInSync(struct drbd_connection *connection, struct packet_info *
38299 put_ldev(device);
38300 }
38301 dec_rs_pending(device);
38302- atomic_add(blksize >> 9, &device->rs_sect_in);
38303+ atomic_add_unchecked(blksize >> 9, &device->rs_sect_in);
38304
38305 return 0;
38306 }
38307@@ -5470,7 +5470,7 @@ static int connection_finish_peer_reqs(struct drbd_connection *connection)
38308 struct asender_cmd {
38309 size_t pkt_size;
38310 int (*fn)(struct drbd_connection *connection, struct packet_info *);
38311-};
38312+} __do_const;
38313
38314 static struct asender_cmd asender_tbl[] = {
38315 [P_PING] = { 0, got_Ping },
38316diff --git a/drivers/block/drbd/drbd_worker.c b/drivers/block/drbd/drbd_worker.c
38317index d2d1f97..6a1188f 100644
38318--- a/drivers/block/drbd/drbd_worker.c
38319+++ b/drivers/block/drbd/drbd_worker.c
38320@@ -408,7 +408,7 @@ static int read_for_csum(struct drbd_peer_device *peer_device, sector_t sector,
38321 list_add_tail(&peer_req->w.list, &device->read_ee);
38322 spin_unlock_irq(&device->resource->req_lock);
38323
38324- atomic_add(size >> 9, &device->rs_sect_ev);
38325+ atomic_add_unchecked(size >> 9, &device->rs_sect_ev);
38326 if (drbd_submit_peer_request(device, peer_req, READ, DRBD_FAULT_RS_RD) == 0)
38327 return 0;
38328
38329@@ -553,7 +553,7 @@ static int drbd_rs_number_requests(struct drbd_device *device)
38330 unsigned int sect_in; /* Number of sectors that came in since the last turn */
38331 int number, mxb;
38332
38333- sect_in = atomic_xchg(&device->rs_sect_in, 0);
38334+ sect_in = atomic_xchg_unchecked(&device->rs_sect_in, 0);
38335 device->rs_in_flight -= sect_in;
38336
38337 rcu_read_lock();
38338@@ -1594,8 +1594,8 @@ void drbd_rs_controller_reset(struct drbd_device *device)
38339 {
38340 struct fifo_buffer *plan;
38341
38342- atomic_set(&device->rs_sect_in, 0);
38343- atomic_set(&device->rs_sect_ev, 0);
38344+ atomic_set_unchecked(&device->rs_sect_in, 0);
38345+ atomic_set_unchecked(&device->rs_sect_ev, 0);
38346 device->rs_in_flight = 0;
38347
38348 /* Updating the RCU protected object in place is necessary since
38349diff --git a/drivers/block/loop.c b/drivers/block/loop.c
38350index 6cb1beb..bf490f7 100644
38351--- a/drivers/block/loop.c
38352+++ b/drivers/block/loop.c
38353@@ -232,7 +232,7 @@ static int __do_lo_send_write(struct file *file,
38354
38355 file_start_write(file);
38356 set_fs(get_ds());
38357- bw = file->f_op->write(file, buf, len, &pos);
38358+ bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
38359 set_fs(old_fs);
38360 file_end_write(file);
38361 if (likely(bw == len))
38362diff --git a/drivers/block/nvme-core.c b/drivers/block/nvme-core.c
38363index e2bb8af..44b8aef 100644
38364--- a/drivers/block/nvme-core.c
38365+++ b/drivers/block/nvme-core.c
38366@@ -73,7 +73,6 @@ static LIST_HEAD(dev_list);
38367 static struct task_struct *nvme_thread;
38368 static struct workqueue_struct *nvme_workq;
38369 static wait_queue_head_t nvme_kthread_wait;
38370-static struct notifier_block nvme_nb;
38371
38372 static void nvme_reset_failed_dev(struct work_struct *ws);
38373
38374@@ -2926,6 +2925,10 @@ static struct pci_driver nvme_driver = {
38375 .err_handler = &nvme_err_handler,
38376 };
38377
38378+static struct notifier_block nvme_nb = {
38379+ .notifier_call = &nvme_cpu_notify,
38380+};
38381+
38382 static int __init nvme_init(void)
38383 {
38384 int result;
38385@@ -2942,7 +2945,6 @@ static int __init nvme_init(void)
38386 else if (result > 0)
38387 nvme_major = result;
38388
38389- nvme_nb.notifier_call = &nvme_cpu_notify;
38390 result = register_hotcpu_notifier(&nvme_nb);
38391 if (result)
38392 goto unregister_blkdev;
38393diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c
38394index 09e628da..7607aaa 100644
38395--- a/drivers/block/pktcdvd.c
38396+++ b/drivers/block/pktcdvd.c
38397@@ -108,7 +108,7 @@ static int pkt_seq_show(struct seq_file *m, void *p);
38398
38399 static sector_t get_zone(sector_t sector, struct pktcdvd_device *pd)
38400 {
38401- return (sector + pd->offset) & ~(sector_t)(pd->settings.size - 1);
38402+ return (sector + pd->offset) & ~(sector_t)(pd->settings.size - 1UL);
38403 }
38404
38405 /*
38406@@ -1890,7 +1890,7 @@ static noinline_for_stack int pkt_probe_settings(struct pktcdvd_device *pd)
38407 return -EROFS;
38408 }
38409 pd->settings.fp = ti.fp;
38410- pd->offset = (be32_to_cpu(ti.track_start) << 2) & (pd->settings.size - 1);
38411+ pd->offset = (be32_to_cpu(ti.track_start) << 2) & (pd->settings.size - 1UL);
38412
38413 if (ti.nwa_v) {
38414 pd->nwa = be32_to_cpu(ti.next_writable);
38415diff --git a/drivers/block/smart1,2.h b/drivers/block/smart1,2.h
38416index e5565fb..71be10b4 100644
38417--- a/drivers/block/smart1,2.h
38418+++ b/drivers/block/smart1,2.h
38419@@ -108,11 +108,11 @@ static unsigned long smart4_intr_pending(ctlr_info_t *h)
38420 }
38421
38422 static struct access_method smart4_access = {
38423- smart4_submit_command,
38424- smart4_intr_mask,
38425- smart4_fifo_full,
38426- smart4_intr_pending,
38427- smart4_completed,
38428+ .submit_command = smart4_submit_command,
38429+ .set_intr_mask = smart4_intr_mask,
38430+ .fifo_full = smart4_fifo_full,
38431+ .intr_pending = smart4_intr_pending,
38432+ .command_completed = smart4_completed,
38433 };
38434
38435 /*
38436@@ -144,11 +144,11 @@ static unsigned long smart2_intr_pending(ctlr_info_t *h)
38437 }
38438
38439 static struct access_method smart2_access = {
38440- smart2_submit_command,
38441- smart2_intr_mask,
38442- smart2_fifo_full,
38443- smart2_intr_pending,
38444- smart2_completed,
38445+ .submit_command = smart2_submit_command,
38446+ .set_intr_mask = smart2_intr_mask,
38447+ .fifo_full = smart2_fifo_full,
38448+ .intr_pending = smart2_intr_pending,
38449+ .command_completed = smart2_completed,
38450 };
38451
38452 /*
38453@@ -180,11 +180,11 @@ static unsigned long smart2e_intr_pending(ctlr_info_t *h)
38454 }
38455
38456 static struct access_method smart2e_access = {
38457- smart2e_submit_command,
38458- smart2e_intr_mask,
38459- smart2e_fifo_full,
38460- smart2e_intr_pending,
38461- smart2e_completed,
38462+ .submit_command = smart2e_submit_command,
38463+ .set_intr_mask = smart2e_intr_mask,
38464+ .fifo_full = smart2e_fifo_full,
38465+ .intr_pending = smart2e_intr_pending,
38466+ .command_completed = smart2e_completed,
38467 };
38468
38469 /*
38470@@ -270,9 +270,9 @@ static unsigned long smart1_intr_pending(ctlr_info_t *h)
38471 }
38472
38473 static struct access_method smart1_access = {
38474- smart1_submit_command,
38475- smart1_intr_mask,
38476- smart1_fifo_full,
38477- smart1_intr_pending,
38478- smart1_completed,
38479+ .submit_command = smart1_submit_command,
38480+ .set_intr_mask = smart1_intr_mask,
38481+ .fifo_full = smart1_fifo_full,
38482+ .intr_pending = smart1_intr_pending,
38483+ .command_completed = smart1_completed,
38484 };
38485diff --git a/drivers/bluetooth/btwilink.c b/drivers/bluetooth/btwilink.c
38486index f038dba..bb74c08 100644
38487--- a/drivers/bluetooth/btwilink.c
38488+++ b/drivers/bluetooth/btwilink.c
38489@@ -288,7 +288,7 @@ static int ti_st_send_frame(struct hci_dev *hdev, struct sk_buff *skb)
38490
38491 static int bt_ti_probe(struct platform_device *pdev)
38492 {
38493- static struct ti_st *hst;
38494+ struct ti_st *hst;
38495 struct hci_dev *hdev;
38496 int err;
38497
38498diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c
38499index 5d28a45..a538f90 100644
38500--- a/drivers/cdrom/cdrom.c
38501+++ b/drivers/cdrom/cdrom.c
38502@@ -610,7 +610,6 @@ int register_cdrom(struct cdrom_device_info *cdi)
38503 ENSURE(reset, CDC_RESET);
38504 ENSURE(generic_packet, CDC_GENERIC_PACKET);
38505 cdi->mc_flags = 0;
38506- cdo->n_minors = 0;
38507 cdi->options = CDO_USE_FFLAGS;
38508
38509 if (autoclose == 1 && CDROM_CAN(CDC_CLOSE_TRAY))
38510@@ -630,8 +629,11 @@ int register_cdrom(struct cdrom_device_info *cdi)
38511 else
38512 cdi->cdda_method = CDDA_OLD;
38513
38514- if (!cdo->generic_packet)
38515- cdo->generic_packet = cdrom_dummy_generic_packet;
38516+ if (!cdo->generic_packet) {
38517+ pax_open_kernel();
38518+ *(void **)&cdo->generic_packet = cdrom_dummy_generic_packet;
38519+ pax_close_kernel();
38520+ }
38521
38522 cd_dbg(CD_REG_UNREG, "drive \"/dev/%s\" registered\n", cdi->name);
38523 mutex_lock(&cdrom_mutex);
38524@@ -652,7 +654,6 @@ void unregister_cdrom(struct cdrom_device_info *cdi)
38525 if (cdi->exit)
38526 cdi->exit(cdi);
38527
38528- cdi->ops->n_minors--;
38529 cd_dbg(CD_REG_UNREG, "drive \"/dev/%s\" unregistered\n", cdi->name);
38530 }
38531
38532@@ -2126,7 +2127,7 @@ static int cdrom_read_cdda_old(struct cdrom_device_info *cdi, __u8 __user *ubuf,
38533 */
38534 nr = nframes;
38535 do {
38536- cgc.buffer = kmalloc(CD_FRAMESIZE_RAW * nr, GFP_KERNEL);
38537+ cgc.buffer = kzalloc(CD_FRAMESIZE_RAW * nr, GFP_KERNEL);
38538 if (cgc.buffer)
38539 break;
38540
38541@@ -3434,7 +3435,7 @@ static int cdrom_print_info(const char *header, int val, char *info,
38542 struct cdrom_device_info *cdi;
38543 int ret;
38544
38545- ret = scnprintf(info + *pos, max_size - *pos, header);
38546+ ret = scnprintf(info + *pos, max_size - *pos, "%s", header);
38547 if (!ret)
38548 return 1;
38549
38550diff --git a/drivers/cdrom/gdrom.c b/drivers/cdrom/gdrom.c
38551index 584bc31..e64a12c 100644
38552--- a/drivers/cdrom/gdrom.c
38553+++ b/drivers/cdrom/gdrom.c
38554@@ -491,7 +491,6 @@ static struct cdrom_device_ops gdrom_ops = {
38555 .audio_ioctl = gdrom_audio_ioctl,
38556 .capability = CDC_MULTI_SESSION | CDC_MEDIA_CHANGED |
38557 CDC_RESET | CDC_DRIVE_STATUS | CDC_CD_R,
38558- .n_minors = 1,
38559 };
38560
38561 static int gdrom_bdops_open(struct block_device *bdev, fmode_t mode)
38562diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
38563index efefd12..4f1d494 100644
38564--- a/drivers/char/Kconfig
38565+++ b/drivers/char/Kconfig
38566@@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
38567
38568 config DEVKMEM
38569 bool "/dev/kmem virtual device support"
38570- default y
38571+ default n
38572+ depends on !GRKERNSEC_KMEM
38573 help
38574 Say Y here if you want to support the /dev/kmem device. The
38575 /dev/kmem device is rarely used, but can be used for certain
38576@@ -577,6 +578,7 @@ config DEVPORT
38577 bool
38578 depends on !M68K
38579 depends on ISA || PCI
38580+ depends on !GRKERNSEC_KMEM
38581 default y
38582
38583 source "drivers/s390/char/Kconfig"
38584diff --git a/drivers/char/agp/compat_ioctl.c b/drivers/char/agp/compat_ioctl.c
38585index a48e05b..6bac831 100644
38586--- a/drivers/char/agp/compat_ioctl.c
38587+++ b/drivers/char/agp/compat_ioctl.c
38588@@ -108,7 +108,7 @@ static int compat_agpioc_reserve_wrap(struct agp_file_private *priv, void __user
38589 return -ENOMEM;
38590 }
38591
38592- if (copy_from_user(usegment, (void __user *) ureserve.seg_list,
38593+ if (copy_from_user(usegment, (void __force_user *) ureserve.seg_list,
38594 sizeof(*usegment) * ureserve.seg_count)) {
38595 kfree(usegment);
38596 kfree(ksegment);
38597diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
38598index 09f17eb..8531d2f 100644
38599--- a/drivers/char/agp/frontend.c
38600+++ b/drivers/char/agp/frontend.c
38601@@ -806,7 +806,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
38602 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
38603 return -EFAULT;
38604
38605- if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
38606+ if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
38607 return -EFAULT;
38608
38609 client = agp_find_client_by_pid(reserve.pid);
38610@@ -836,7 +836,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
38611 if (segment == NULL)
38612 return -ENOMEM;
38613
38614- if (copy_from_user(segment, (void __user *) reserve.seg_list,
38615+ if (copy_from_user(segment, (void __force_user *) reserve.seg_list,
38616 sizeof(struct agp_segment) * reserve.seg_count)) {
38617 kfree(segment);
38618 return -EFAULT;
38619diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
38620index 4f94375..413694e 100644
38621--- a/drivers/char/genrtc.c
38622+++ b/drivers/char/genrtc.c
38623@@ -273,6 +273,7 @@ static int gen_rtc_ioctl(struct file *file,
38624 switch (cmd) {
38625
38626 case RTC_PLL_GET:
38627+ memset(&pll, 0, sizeof(pll));
38628 if (get_rtc_pll(&pll))
38629 return -EINVAL;
38630 else
38631diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
38632index d5d4cd8..22d561d 100644
38633--- a/drivers/char/hpet.c
38634+++ b/drivers/char/hpet.c
38635@@ -575,7 +575,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
38636 }
38637
38638 static int
38639-hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
38640+hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
38641 struct hpet_info *info)
38642 {
38643 struct hpet_timer __iomem *timer;
38644diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
38645index f816211..89eadea 100644
38646--- a/drivers/char/ipmi/ipmi_msghandler.c
38647+++ b/drivers/char/ipmi/ipmi_msghandler.c
38648@@ -438,7 +438,7 @@ struct ipmi_smi {
38649 struct proc_dir_entry *proc_dir;
38650 char proc_dir_name[10];
38651
38652- atomic_t stats[IPMI_NUM_STATS];
38653+ atomic_unchecked_t stats[IPMI_NUM_STATS];
38654
38655 /*
38656 * run_to_completion duplicate of smb_info, smi_info
38657@@ -470,9 +470,9 @@ static LIST_HEAD(smi_watchers);
38658 static DEFINE_MUTEX(smi_watchers_mutex);
38659
38660 #define ipmi_inc_stat(intf, stat) \
38661- atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
38662+ atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
38663 #define ipmi_get_stat(intf, stat) \
38664- ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
38665+ ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
38666
38667 static int is_lan_addr(struct ipmi_addr *addr)
38668 {
38669@@ -2925,7 +2925,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
38670 INIT_LIST_HEAD(&intf->cmd_rcvrs);
38671 init_waitqueue_head(&intf->waitq);
38672 for (i = 0; i < IPMI_NUM_STATS; i++)
38673- atomic_set(&intf->stats[i], 0);
38674+ atomic_set_unchecked(&intf->stats[i], 0);
38675
38676 intf->proc_dir = NULL;
38677
38678diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
38679index 5c4e1f6..0ea58f9 100644
38680--- a/drivers/char/ipmi/ipmi_si_intf.c
38681+++ b/drivers/char/ipmi/ipmi_si_intf.c
38682@@ -285,7 +285,7 @@ struct smi_info {
38683 unsigned char slave_addr;
38684
38685 /* Counters and things for the proc filesystem. */
38686- atomic_t stats[SI_NUM_STATS];
38687+ atomic_unchecked_t stats[SI_NUM_STATS];
38688
38689 struct task_struct *thread;
38690
38691@@ -294,9 +294,9 @@ struct smi_info {
38692 };
38693
38694 #define smi_inc_stat(smi, stat) \
38695- atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
38696+ atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
38697 #define smi_get_stat(smi, stat) \
38698- ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
38699+ ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
38700
38701 #define SI_MAX_PARMS 4
38702
38703@@ -3377,7 +3377,7 @@ static int try_smi_init(struct smi_info *new_smi)
38704 atomic_set(&new_smi->req_events, 0);
38705 new_smi->run_to_completion = false;
38706 for (i = 0; i < SI_NUM_STATS; i++)
38707- atomic_set(&new_smi->stats[i], 0);
38708+ atomic_set_unchecked(&new_smi->stats[i], 0);
38709
38710 new_smi->interrupt_disabled = true;
38711 atomic_set(&new_smi->stop_operation, 0);
38712diff --git a/drivers/char/mem.c b/drivers/char/mem.c
38713index 524b707..29d07c1 100644
38714--- a/drivers/char/mem.c
38715+++ b/drivers/char/mem.c
38716@@ -18,6 +18,7 @@
38717 #include <linux/raw.h>
38718 #include <linux/tty.h>
38719 #include <linux/capability.h>
38720+#include <linux/security.h>
38721 #include <linux/ptrace.h>
38722 #include <linux/device.h>
38723 #include <linux/highmem.h>
38724@@ -36,6 +37,10 @@
38725
38726 #define DEVPORT_MINOR 4
38727
38728+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
38729+extern const struct file_operations grsec_fops;
38730+#endif
38731+
38732 static inline unsigned long size_inside_page(unsigned long start,
38733 unsigned long size)
38734 {
38735@@ -67,9 +72,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
38736
38737 while (cursor < to) {
38738 if (!devmem_is_allowed(pfn)) {
38739+#ifdef CONFIG_GRKERNSEC_KMEM
38740+ gr_handle_mem_readwrite(from, to);
38741+#else
38742 printk(KERN_INFO
38743 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
38744 current->comm, from, to);
38745+#endif
38746 return 0;
38747 }
38748 cursor += PAGE_SIZE;
38749@@ -77,6 +86,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
38750 }
38751 return 1;
38752 }
38753+#elif defined(CONFIG_GRKERNSEC_KMEM)
38754+static inline int range_is_allowed(unsigned long pfn, unsigned long size)
38755+{
38756+ return 0;
38757+}
38758 #else
38759 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
38760 {
38761@@ -122,6 +136,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,
38762
38763 while (count > 0) {
38764 unsigned long remaining;
38765+ char *temp;
38766
38767 sz = size_inside_page(p, count);
38768
38769@@ -137,7 +152,23 @@ static ssize_t read_mem(struct file *file, char __user *buf,
38770 if (!ptr)
38771 return -EFAULT;
38772
38773- remaining = copy_to_user(buf, ptr, sz);
38774+#ifdef CONFIG_PAX_USERCOPY
38775+ temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
38776+ if (!temp) {
38777+ unxlate_dev_mem_ptr(p, ptr);
38778+ return -ENOMEM;
38779+ }
38780+ memcpy(temp, ptr, sz);
38781+#else
38782+ temp = ptr;
38783+#endif
38784+
38785+ remaining = copy_to_user(buf, temp, sz);
38786+
38787+#ifdef CONFIG_PAX_USERCOPY
38788+ kfree(temp);
38789+#endif
38790+
38791 unxlate_dev_mem_ptr(p, ptr);
38792 if (remaining)
38793 return -EFAULT;
38794@@ -369,9 +400,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
38795 size_t count, loff_t *ppos)
38796 {
38797 unsigned long p = *ppos;
38798- ssize_t low_count, read, sz;
38799+ ssize_t low_count, read, sz, err = 0;
38800 char *kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
38801- int err = 0;
38802
38803 read = 0;
38804 if (p < (unsigned long) high_memory) {
38805@@ -393,6 +423,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
38806 }
38807 #endif
38808 while (low_count > 0) {
38809+ char *temp;
38810+
38811 sz = size_inside_page(p, low_count);
38812
38813 /*
38814@@ -402,7 +434,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
38815 */
38816 kbuf = xlate_dev_kmem_ptr((char *)p);
38817
38818- if (copy_to_user(buf, kbuf, sz))
38819+#ifdef CONFIG_PAX_USERCOPY
38820+ temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
38821+ if (!temp)
38822+ return -ENOMEM;
38823+ memcpy(temp, kbuf, sz);
38824+#else
38825+ temp = kbuf;
38826+#endif
38827+
38828+ err = copy_to_user(buf, temp, sz);
38829+
38830+#ifdef CONFIG_PAX_USERCOPY
38831+ kfree(temp);
38832+#endif
38833+
38834+ if (err)
38835 return -EFAULT;
38836 buf += sz;
38837 p += sz;
38838@@ -797,6 +844,9 @@ static const struct memdev {
38839 #ifdef CONFIG_PRINTK
38840 [11] = { "kmsg", 0644, &kmsg_fops, NULL },
38841 #endif
38842+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
38843+ [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
38844+#endif
38845 };
38846
38847 static int memory_open(struct inode *inode, struct file *filp)
38848@@ -868,7 +918,7 @@ static int __init chr_dev_init(void)
38849 continue;
38850
38851 device_create(mem_class, NULL, MKDEV(MEM_MAJOR, minor),
38852- NULL, devlist[minor].name);
38853+ NULL, "%s", devlist[minor].name);
38854 }
38855
38856 return tty_init();
38857diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
38858index 9df78e2..01ba9ae 100644
38859--- a/drivers/char/nvram.c
38860+++ b/drivers/char/nvram.c
38861@@ -247,7 +247,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
38862
38863 spin_unlock_irq(&rtc_lock);
38864
38865- if (copy_to_user(buf, contents, tmp - contents))
38866+ if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
38867 return -EFAULT;
38868
38869 *ppos = i;
38870diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
38871index 0ea9986..e7b07e4 100644
38872--- a/drivers/char/pcmcia/synclink_cs.c
38873+++ b/drivers/char/pcmcia/synclink_cs.c
38874@@ -2345,7 +2345,7 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
38875
38876 if (debug_level >= DEBUG_LEVEL_INFO)
38877 printk("%s(%d):mgslpc_close(%s) entry, count=%d\n",
38878- __FILE__, __LINE__, info->device_name, port->count);
38879+ __FILE__, __LINE__, info->device_name, atomic_read(&port->count));
38880
38881 if (tty_port_close_start(port, tty, filp) == 0)
38882 goto cleanup;
38883@@ -2363,7 +2363,7 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
38884 cleanup:
38885 if (debug_level >= DEBUG_LEVEL_INFO)
38886 printk("%s(%d):mgslpc_close(%s) exit, count=%d\n", __FILE__, __LINE__,
38887- tty->driver->name, port->count);
38888+ tty->driver->name, atomic_read(&port->count));
38889 }
38890
38891 /* Wait until the transmitter is empty.
38892@@ -2505,7 +2505,7 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
38893
38894 if (debug_level >= DEBUG_LEVEL_INFO)
38895 printk("%s(%d):mgslpc_open(%s), old ref count = %d\n",
38896- __FILE__, __LINE__, tty->driver->name, port->count);
38897+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
38898
38899 /* If port is closing, signal caller to try again */
38900 if (port->flags & ASYNC_CLOSING){
38901@@ -2525,11 +2525,11 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
38902 goto cleanup;
38903 }
38904 spin_lock(&port->lock);
38905- port->count++;
38906+ atomic_inc(&port->count);
38907 spin_unlock(&port->lock);
38908 spin_unlock_irqrestore(&info->netlock, flags);
38909
38910- if (port->count == 1) {
38911+ if (atomic_read(&port->count) == 1) {
38912 /* 1st open on this device, init hardware */
38913 retval = startup(info, tty);
38914 if (retval < 0)
38915@@ -3918,7 +3918,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
38916 unsigned short new_crctype;
38917
38918 /* return error if TTY interface open */
38919- if (info->port.count)
38920+ if (atomic_read(&info->port.count))
38921 return -EBUSY;
38922
38923 switch (encoding)
38924@@ -4022,7 +4022,7 @@ static int hdlcdev_open(struct net_device *dev)
38925
38926 /* arbitrate between network and tty opens */
38927 spin_lock_irqsave(&info->netlock, flags);
38928- if (info->port.count != 0 || info->netcount != 0) {
38929+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
38930 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
38931 spin_unlock_irqrestore(&info->netlock, flags);
38932 return -EBUSY;
38933@@ -4112,7 +4112,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
38934 printk("%s:hdlcdev_ioctl(%s)\n", __FILE__, dev->name);
38935
38936 /* return error if TTY interface open */
38937- if (info->port.count)
38938+ if (atomic_read(&info->port.count))
38939 return -EBUSY;
38940
38941 if (cmd != SIOCWANDEV)
38942diff --git a/drivers/char/random.c b/drivers/char/random.c
38943index 04645c0..560e350 100644
38944--- a/drivers/char/random.c
38945+++ b/drivers/char/random.c
38946@@ -289,9 +289,6 @@
38947 /*
38948 * To allow fractional bits to be tracked, the entropy_count field is
38949 * denominated in units of 1/8th bits.
38950- *
38951- * 2*(ENTROPY_SHIFT + log2(poolbits)) must <= 31, or the multiply in
38952- * credit_entropy_bits() needs to be 64 bits wide.
38953 */
38954 #define ENTROPY_SHIFT 3
38955 #define ENTROPY_BITS(r) ((r)->entropy_count >> ENTROPY_SHIFT)
38956@@ -439,9 +436,9 @@ struct entropy_store {
38957 };
38958
38959 static void push_to_pool(struct work_struct *work);
38960-static __u32 input_pool_data[INPUT_POOL_WORDS];
38961-static __u32 blocking_pool_data[OUTPUT_POOL_WORDS];
38962-static __u32 nonblocking_pool_data[OUTPUT_POOL_WORDS];
38963+static __u32 input_pool_data[INPUT_POOL_WORDS] __latent_entropy;
38964+static __u32 blocking_pool_data[OUTPUT_POOL_WORDS] __latent_entropy;
38965+static __u32 nonblocking_pool_data[OUTPUT_POOL_WORDS] __latent_entropy;
38966
38967 static struct entropy_store input_pool = {
38968 .poolinfo = &poolinfo_table[0],
38969@@ -635,7 +632,7 @@ retry:
38970 /* The +2 corresponds to the /4 in the denominator */
38971
38972 do {
38973- unsigned int anfrac = min(pnfrac, pool_size/2);
38974+ u64 anfrac = min(pnfrac, pool_size/2);
38975 unsigned int add =
38976 ((pool_size - entropy_count)*anfrac*3) >> s;
38977
38978@@ -1207,7 +1204,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
38979
38980 extract_buf(r, tmp);
38981 i = min_t(int, nbytes, EXTRACT_SIZE);
38982- if (copy_to_user(buf, tmp, i)) {
38983+ if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
38984 ret = -EFAULT;
38985 break;
38986 }
38987@@ -1590,7 +1587,7 @@ static char sysctl_bootid[16];
38988 static int proc_do_uuid(struct ctl_table *table, int write,
38989 void __user *buffer, size_t *lenp, loff_t *ppos)
38990 {
38991- struct ctl_table fake_table;
38992+ ctl_table_no_const fake_table;
38993 unsigned char buf[64], tmp_uuid[16], *uuid;
38994
38995 uuid = table->data;
38996@@ -1620,7 +1617,7 @@ static int proc_do_uuid(struct ctl_table *table, int write,
38997 static int proc_do_entropy(struct ctl_table *table, int write,
38998 void __user *buffer, size_t *lenp, loff_t *ppos)
38999 {
39000- struct ctl_table fake_table;
39001+ ctl_table_no_const fake_table;
39002 int entropy_count;
39003
39004 entropy_count = *(int *)table->data >> ENTROPY_SHIFT;
39005diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
39006index 7cc1fe22..b602d6b 100644
39007--- a/drivers/char/sonypi.c
39008+++ b/drivers/char/sonypi.c
39009@@ -54,6 +54,7 @@
39010
39011 #include <asm/uaccess.h>
39012 #include <asm/io.h>
39013+#include <asm/local.h>
39014
39015 #include <linux/sonypi.h>
39016
39017@@ -490,7 +491,7 @@ static struct sonypi_device {
39018 spinlock_t fifo_lock;
39019 wait_queue_head_t fifo_proc_list;
39020 struct fasync_struct *fifo_async;
39021- int open_count;
39022+ local_t open_count;
39023 int model;
39024 struct input_dev *input_jog_dev;
39025 struct input_dev *input_key_dev;
39026@@ -892,7 +893,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
39027 static int sonypi_misc_release(struct inode *inode, struct file *file)
39028 {
39029 mutex_lock(&sonypi_device.lock);
39030- sonypi_device.open_count--;
39031+ local_dec(&sonypi_device.open_count);
39032 mutex_unlock(&sonypi_device.lock);
39033 return 0;
39034 }
39035@@ -901,9 +902,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
39036 {
39037 mutex_lock(&sonypi_device.lock);
39038 /* Flush input queue on first open */
39039- if (!sonypi_device.open_count)
39040+ if (!local_read(&sonypi_device.open_count))
39041 kfifo_reset(&sonypi_device.fifo);
39042- sonypi_device.open_count++;
39043+ local_inc(&sonypi_device.open_count);
39044 mutex_unlock(&sonypi_device.lock);
39045
39046 return 0;
39047diff --git a/drivers/char/tpm/tpm_acpi.c b/drivers/char/tpm/tpm_acpi.c
39048index 565a947..dcdc06e 100644
39049--- a/drivers/char/tpm/tpm_acpi.c
39050+++ b/drivers/char/tpm/tpm_acpi.c
39051@@ -98,11 +98,12 @@ int read_log(struct tpm_bios_log *log)
39052 virt = acpi_os_map_iomem(start, len);
39053 if (!virt) {
39054 kfree(log->bios_event_log);
39055+ log->bios_event_log = NULL;
39056 printk("%s: ERROR - Unable to map memory\n", __func__);
39057 return -EIO;
39058 }
39059
39060- memcpy_fromio(log->bios_event_log, virt, len);
39061+ memcpy_fromio(log->bios_event_log, (const char __force_kernel *)virt, len);
39062
39063 acpi_os_unmap_iomem(virt, len);
39064 return 0;
39065diff --git a/drivers/char/tpm/tpm_eventlog.c b/drivers/char/tpm/tpm_eventlog.c
39066index 3a56a13..f8cbd25 100644
39067--- a/drivers/char/tpm/tpm_eventlog.c
39068+++ b/drivers/char/tpm/tpm_eventlog.c
39069@@ -95,7 +95,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
39070 event = addr;
39071
39072 if ((event->event_type == 0 && event->event_size == 0) ||
39073- ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
39074+ (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
39075 return NULL;
39076
39077 return addr;
39078@@ -120,7 +120,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
39079 return NULL;
39080
39081 if ((event->event_type == 0 && event->event_size == 0) ||
39082- ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
39083+ (event->event_size >= limit - v - sizeof(struct tcpa_event)))
39084 return NULL;
39085
39086 (*pos)++;
39087@@ -213,7 +213,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
39088 int i;
39089
39090 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
39091- seq_putc(m, data[i]);
39092+ if (!seq_putc(m, data[i]))
39093+ return -EFAULT;
39094
39095 return 0;
39096 }
39097diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
39098index cf7a561..c319ce0 100644
39099--- a/drivers/char/virtio_console.c
39100+++ b/drivers/char/virtio_console.c
39101@@ -684,7 +684,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
39102 if (to_user) {
39103 ssize_t ret;
39104
39105- ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
39106+ ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
39107 if (ret)
39108 return -EFAULT;
39109 } else {
39110@@ -787,7 +787,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
39111 if (!port_has_data(port) && !port->host_connected)
39112 return 0;
39113
39114- return fill_readbuf(port, ubuf, count, true);
39115+ return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
39116 }
39117
39118 static int wait_port_writable(struct port *port, bool nonblock)
39119diff --git a/drivers/clk/clk-composite.c b/drivers/clk/clk-composite.c
39120index b9355da..9611f4e 100644
39121--- a/drivers/clk/clk-composite.c
39122+++ b/drivers/clk/clk-composite.c
39123@@ -191,7 +191,7 @@ struct clk *clk_register_composite(struct device *dev, const char *name,
39124 struct clk *clk;
39125 struct clk_init_data init;
39126 struct clk_composite *composite;
39127- struct clk_ops *clk_composite_ops;
39128+ clk_ops_no_const *clk_composite_ops;
39129
39130 composite = kzalloc(sizeof(*composite), GFP_KERNEL);
39131 if (!composite) {
39132diff --git a/drivers/clk/socfpga/clk-gate.c b/drivers/clk/socfpga/clk-gate.c
39133index dd3a78c..386d49c 100644
39134--- a/drivers/clk/socfpga/clk-gate.c
39135+++ b/drivers/clk/socfpga/clk-gate.c
39136@@ -22,6 +22,7 @@
39137 #include <linux/mfd/syscon.h>
39138 #include <linux/of.h>
39139 #include <linux/regmap.h>
39140+#include <asm/pgtable.h>
39141
39142 #include "clk.h"
39143
39144@@ -174,7 +175,7 @@ static int socfpga_clk_prepare(struct clk_hw *hwclk)
39145 return 0;
39146 }
39147
39148-static struct clk_ops gateclk_ops = {
39149+static clk_ops_no_const gateclk_ops __read_only = {
39150 .prepare = socfpga_clk_prepare,
39151 .recalc_rate = socfpga_clk_recalc_rate,
39152 .get_parent = socfpga_clk_get_parent,
39153@@ -208,8 +209,10 @@ static void __init __socfpga_gate_init(struct device_node *node,
39154 socfpga_clk->hw.reg = clk_mgr_base_addr + clk_gate[0];
39155 socfpga_clk->hw.bit_idx = clk_gate[1];
39156
39157- gateclk_ops.enable = clk_gate_ops.enable;
39158- gateclk_ops.disable = clk_gate_ops.disable;
39159+ pax_open_kernel();
39160+ *(void **)&gateclk_ops.enable = clk_gate_ops.enable;
39161+ *(void **)&gateclk_ops.disable = clk_gate_ops.disable;
39162+ pax_close_kernel();
39163 }
39164
39165 rc = of_property_read_u32(node, "fixed-divider", &fixed_div);
39166diff --git a/drivers/clk/socfpga/clk-pll.c b/drivers/clk/socfpga/clk-pll.c
39167index de6da95..c98278b 100644
39168--- a/drivers/clk/socfpga/clk-pll.c
39169+++ b/drivers/clk/socfpga/clk-pll.c
39170@@ -21,6 +21,7 @@
39171 #include <linux/io.h>
39172 #include <linux/of.h>
39173 #include <linux/of_address.h>
39174+#include <asm/pgtable.h>
39175
39176 #include "clk.h"
39177
39178@@ -76,7 +77,7 @@ static u8 clk_pll_get_parent(struct clk_hw *hwclk)
39179 CLK_MGR_PLL_CLK_SRC_MASK;
39180 }
39181
39182-static struct clk_ops clk_pll_ops = {
39183+static clk_ops_no_const clk_pll_ops __read_only = {
39184 .recalc_rate = clk_pll_recalc_rate,
39185 .get_parent = clk_pll_get_parent,
39186 };
39187@@ -120,8 +121,10 @@ static __init struct clk *__socfpga_pll_init(struct device_node *node,
39188 pll_clk->hw.hw.init = &init;
39189
39190 pll_clk->hw.bit_idx = SOCFPGA_PLL_EXT_ENA;
39191- clk_pll_ops.enable = clk_gate_ops.enable;
39192- clk_pll_ops.disable = clk_gate_ops.disable;
39193+ pax_open_kernel();
39194+ *(void **)&clk_pll_ops.enable = clk_gate_ops.enable;
39195+ *(void **)&clk_pll_ops.disable = clk_gate_ops.disable;
39196+ pax_close_kernel();
39197
39198 clk = clk_register(NULL, &pll_clk->hw.hw);
39199 if (WARN_ON(IS_ERR(clk))) {
39200diff --git a/drivers/cpufreq/acpi-cpufreq.c b/drivers/cpufreq/acpi-cpufreq.c
39201index b0c18ed..1713a80 100644
39202--- a/drivers/cpufreq/acpi-cpufreq.c
39203+++ b/drivers/cpufreq/acpi-cpufreq.c
39204@@ -675,8 +675,11 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
39205 data->acpi_data = per_cpu_ptr(acpi_perf_data, cpu);
39206 per_cpu(acfreq_data, cpu) = data;
39207
39208- if (cpu_has(c, X86_FEATURE_CONSTANT_TSC))
39209- acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
39210+ if (cpu_has(c, X86_FEATURE_CONSTANT_TSC)) {
39211+ pax_open_kernel();
39212+ *(u8 *)&acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
39213+ pax_close_kernel();
39214+ }
39215
39216 result = acpi_processor_register_performance(data->acpi_data, cpu);
39217 if (result)
39218@@ -809,7 +812,9 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
39219 policy->cur = acpi_cpufreq_guess_freq(data, policy->cpu);
39220 break;
39221 case ACPI_ADR_SPACE_FIXED_HARDWARE:
39222- acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
39223+ pax_open_kernel();
39224+ *(void **)&acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
39225+ pax_close_kernel();
39226 break;
39227 default:
39228 break;
39229@@ -903,8 +908,10 @@ static void __init acpi_cpufreq_boost_init(void)
39230 if (!msrs)
39231 return;
39232
39233- acpi_cpufreq_driver.boost_supported = true;
39234- acpi_cpufreq_driver.boost_enabled = boost_state(0);
39235+ pax_open_kernel();
39236+ *(bool *)&acpi_cpufreq_driver.boost_supported = true;
39237+ *(bool *)&acpi_cpufreq_driver.boost_enabled = boost_state(0);
39238+ pax_close_kernel();
39239
39240 cpu_notifier_register_begin();
39241
39242diff --git a/drivers/cpufreq/cpufreq-dt.c b/drivers/cpufreq/cpufreq-dt.c
39243index f657c57..31d97ae 100644
39244--- a/drivers/cpufreq/cpufreq-dt.c
39245+++ b/drivers/cpufreq/cpufreq-dt.c
39246@@ -362,7 +362,9 @@ static int dt_cpufreq_probe(struct platform_device *pdev)
39247 if (!IS_ERR(cpu_reg))
39248 regulator_put(cpu_reg);
39249
39250- dt_cpufreq_driver.driver_data = dev_get_platdata(&pdev->dev);
39251+ pax_open_kernel();
39252+ *(void **)&dt_cpufreq_driver.driver_data = dev_get_platdata(&pdev->dev);
39253+ pax_close_kernel();
39254
39255 ret = cpufreq_register_driver(&dt_cpufreq_driver);
39256 if (ret)
39257diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
39258index 4473eba..a4c9dc2 100644
39259--- a/drivers/cpufreq/cpufreq.c
39260+++ b/drivers/cpufreq/cpufreq.c
39261@@ -2122,7 +2122,7 @@ void cpufreq_unregister_governor(struct cpufreq_governor *governor)
39262 }
39263
39264 mutex_lock(&cpufreq_governor_mutex);
39265- list_del(&governor->governor_list);
39266+ pax_list_del(&governor->governor_list);
39267 mutex_unlock(&cpufreq_governor_mutex);
39268 return;
39269 }
39270@@ -2338,7 +2338,7 @@ static int cpufreq_cpu_callback(struct notifier_block *nfb,
39271 return NOTIFY_OK;
39272 }
39273
39274-static struct notifier_block __refdata cpufreq_cpu_notifier = {
39275+static struct notifier_block cpufreq_cpu_notifier = {
39276 .notifier_call = cpufreq_cpu_callback,
39277 };
39278
39279@@ -2378,13 +2378,17 @@ int cpufreq_boost_trigger_state(int state)
39280 return 0;
39281
39282 write_lock_irqsave(&cpufreq_driver_lock, flags);
39283- cpufreq_driver->boost_enabled = state;
39284+ pax_open_kernel();
39285+ *(bool *)&cpufreq_driver->boost_enabled = state;
39286+ pax_close_kernel();
39287 write_unlock_irqrestore(&cpufreq_driver_lock, flags);
39288
39289 ret = cpufreq_driver->set_boost(state);
39290 if (ret) {
39291 write_lock_irqsave(&cpufreq_driver_lock, flags);
39292- cpufreq_driver->boost_enabled = !state;
39293+ pax_open_kernel();
39294+ *(bool *)&cpufreq_driver->boost_enabled = !state;
39295+ pax_close_kernel();
39296 write_unlock_irqrestore(&cpufreq_driver_lock, flags);
39297
39298 pr_err("%s: Cannot %s BOOST\n",
39299@@ -2441,8 +2445,11 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data)
39300
39301 pr_debug("trying to register driver %s\n", driver_data->name);
39302
39303- if (driver_data->setpolicy)
39304- driver_data->flags |= CPUFREQ_CONST_LOOPS;
39305+ if (driver_data->setpolicy) {
39306+ pax_open_kernel();
39307+ *(u8 *)&driver_data->flags |= CPUFREQ_CONST_LOOPS;
39308+ pax_close_kernel();
39309+ }
39310
39311 write_lock_irqsave(&cpufreq_driver_lock, flags);
39312 if (cpufreq_driver) {
39313@@ -2457,8 +2464,11 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data)
39314 * Check if driver provides function to enable boost -
39315 * if not, use cpufreq_boost_set_sw as default
39316 */
39317- if (!cpufreq_driver->set_boost)
39318- cpufreq_driver->set_boost = cpufreq_boost_set_sw;
39319+ if (!cpufreq_driver->set_boost) {
39320+ pax_open_kernel();
39321+ *(void **)&cpufreq_driver->set_boost = cpufreq_boost_set_sw;
39322+ pax_close_kernel();
39323+ }
39324
39325 ret = cpufreq_sysfs_create_file(&boost.attr);
39326 if (ret) {
39327diff --git a/drivers/cpufreq/cpufreq_governor.c b/drivers/cpufreq/cpufreq_governor.c
39328index 1b44496..b80ff5e 100644
39329--- a/drivers/cpufreq/cpufreq_governor.c
39330+++ b/drivers/cpufreq/cpufreq_governor.c
39331@@ -245,7 +245,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
39332 struct dbs_data *dbs_data;
39333 struct od_cpu_dbs_info_s *od_dbs_info = NULL;
39334 struct cs_cpu_dbs_info_s *cs_dbs_info = NULL;
39335- struct od_ops *od_ops = NULL;
39336+ const struct od_ops *od_ops = NULL;
39337 struct od_dbs_tuners *od_tuners = NULL;
39338 struct cs_dbs_tuners *cs_tuners = NULL;
39339 struct cpu_dbs_common_info *cpu_cdbs;
39340@@ -311,7 +311,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
39341
39342 if ((cdata->governor == GOV_CONSERVATIVE) &&
39343 (!policy->governor->initialized)) {
39344- struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
39345+ const struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
39346
39347 cpufreq_register_notifier(cs_ops->notifier_block,
39348 CPUFREQ_TRANSITION_NOTIFIER);
39349@@ -331,7 +331,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
39350
39351 if ((dbs_data->cdata->governor == GOV_CONSERVATIVE) &&
39352 (policy->governor->initialized == 1)) {
39353- struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
39354+ const struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
39355
39356 cpufreq_unregister_notifier(cs_ops->notifier_block,
39357 CPUFREQ_TRANSITION_NOTIFIER);
39358diff --git a/drivers/cpufreq/cpufreq_governor.h b/drivers/cpufreq/cpufreq_governor.h
39359index cc401d1..8197340 100644
39360--- a/drivers/cpufreq/cpufreq_governor.h
39361+++ b/drivers/cpufreq/cpufreq_governor.h
39362@@ -212,7 +212,7 @@ struct common_dbs_data {
39363 void (*exit)(struct dbs_data *dbs_data);
39364
39365 /* Governor specific ops, see below */
39366- void *gov_ops;
39367+ const void *gov_ops;
39368 };
39369
39370 /* Governor Per policy data */
39371@@ -232,7 +232,7 @@ struct od_ops {
39372 unsigned int (*powersave_bias_target)(struct cpufreq_policy *policy,
39373 unsigned int freq_next, unsigned int relation);
39374 void (*freq_increase)(struct cpufreq_policy *policy, unsigned int freq);
39375-};
39376+} __no_const;
39377
39378 struct cs_ops {
39379 struct notifier_block *notifier_block;
39380diff --git a/drivers/cpufreq/cpufreq_ondemand.c b/drivers/cpufreq/cpufreq_ondemand.c
39381index ad3f38f..8f086cd 100644
39382--- a/drivers/cpufreq/cpufreq_ondemand.c
39383+++ b/drivers/cpufreq/cpufreq_ondemand.c
39384@@ -524,7 +524,7 @@ static void od_exit(struct dbs_data *dbs_data)
39385
39386 define_get_cpu_dbs_routines(od_cpu_dbs_info);
39387
39388-static struct od_ops od_ops = {
39389+static struct od_ops od_ops __read_only = {
39390 .powersave_bias_init_cpu = ondemand_powersave_bias_init_cpu,
39391 .powersave_bias_target = generic_powersave_bias_target,
39392 .freq_increase = dbs_freq_increase,
39393@@ -579,14 +579,18 @@ void od_register_powersave_bias_handler(unsigned int (*f)
39394 (struct cpufreq_policy *, unsigned int, unsigned int),
39395 unsigned int powersave_bias)
39396 {
39397- od_ops.powersave_bias_target = f;
39398+ pax_open_kernel();
39399+ *(void **)&od_ops.powersave_bias_target = f;
39400+ pax_close_kernel();
39401 od_set_powersave_bias(powersave_bias);
39402 }
39403 EXPORT_SYMBOL_GPL(od_register_powersave_bias_handler);
39404
39405 void od_unregister_powersave_bias_handler(void)
39406 {
39407- od_ops.powersave_bias_target = generic_powersave_bias_target;
39408+ pax_open_kernel();
39409+ *(void **)&od_ops.powersave_bias_target = generic_powersave_bias_target;
39410+ pax_close_kernel();
39411 od_set_powersave_bias(0);
39412 }
39413 EXPORT_SYMBOL_GPL(od_unregister_powersave_bias_handler);
39414diff --git a/drivers/cpufreq/intel_pstate.c b/drivers/cpufreq/intel_pstate.c
39415index 27bb6d3..4cf595c 100644
39416--- a/drivers/cpufreq/intel_pstate.c
39417+++ b/drivers/cpufreq/intel_pstate.c
39418@@ -133,10 +133,10 @@ struct pstate_funcs {
39419 struct cpu_defaults {
39420 struct pstate_adjust_policy pid_policy;
39421 struct pstate_funcs funcs;
39422-};
39423+} __do_const;
39424
39425 static struct pstate_adjust_policy pid_params;
39426-static struct pstate_funcs pstate_funcs;
39427+static struct pstate_funcs *pstate_funcs;
39428
39429 struct perf_limits {
39430 int no_turbo;
39431@@ -594,18 +594,18 @@ static void intel_pstate_set_pstate(struct cpudata *cpu, int pstate)
39432
39433 cpu->pstate.current_pstate = pstate;
39434
39435- pstate_funcs.set(cpu, pstate);
39436+ pstate_funcs->set(cpu, pstate);
39437 }
39438
39439 static void intel_pstate_get_cpu_pstates(struct cpudata *cpu)
39440 {
39441- cpu->pstate.min_pstate = pstate_funcs.get_min();
39442- cpu->pstate.max_pstate = pstate_funcs.get_max();
39443- cpu->pstate.turbo_pstate = pstate_funcs.get_turbo();
39444- cpu->pstate.scaling = pstate_funcs.get_scaling();
39445+ cpu->pstate.min_pstate = pstate_funcs->get_min();
39446+ cpu->pstate.max_pstate = pstate_funcs->get_max();
39447+ cpu->pstate.turbo_pstate = pstate_funcs->get_turbo();
39448+ cpu->pstate.scaling = pstate_funcs->get_scaling();
39449
39450- if (pstate_funcs.get_vid)
39451- pstate_funcs.get_vid(cpu);
39452+ if (pstate_funcs->get_vid)
39453+ pstate_funcs->get_vid(cpu);
39454 intel_pstate_set_pstate(cpu, cpu->pstate.min_pstate);
39455 }
39456
39457@@ -875,9 +875,9 @@ static int intel_pstate_msrs_not_valid(void)
39458 rdmsrl(MSR_IA32_APERF, aperf);
39459 rdmsrl(MSR_IA32_MPERF, mperf);
39460
39461- if (!pstate_funcs.get_max() ||
39462- !pstate_funcs.get_min() ||
39463- !pstate_funcs.get_turbo())
39464+ if (!pstate_funcs->get_max() ||
39465+ !pstate_funcs->get_min() ||
39466+ !pstate_funcs->get_turbo())
39467 return -ENODEV;
39468
39469 rdmsrl(MSR_IA32_APERF, tmp);
39470@@ -891,7 +891,7 @@ static int intel_pstate_msrs_not_valid(void)
39471 return 0;
39472 }
39473
39474-static void copy_pid_params(struct pstate_adjust_policy *policy)
39475+static void copy_pid_params(const struct pstate_adjust_policy *policy)
39476 {
39477 pid_params.sample_rate_ms = policy->sample_rate_ms;
39478 pid_params.p_gain_pct = policy->p_gain_pct;
39479@@ -903,12 +903,7 @@ static void copy_pid_params(struct pstate_adjust_policy *policy)
39480
39481 static void copy_cpu_funcs(struct pstate_funcs *funcs)
39482 {
39483- pstate_funcs.get_max = funcs->get_max;
39484- pstate_funcs.get_min = funcs->get_min;
39485- pstate_funcs.get_turbo = funcs->get_turbo;
39486- pstate_funcs.get_scaling = funcs->get_scaling;
39487- pstate_funcs.set = funcs->set;
39488- pstate_funcs.get_vid = funcs->get_vid;
39489+ pstate_funcs = funcs;
39490 }
39491
39492 #if IS_ENABLED(CONFIG_ACPI)
39493diff --git a/drivers/cpufreq/p4-clockmod.c b/drivers/cpufreq/p4-clockmod.c
39494index 529cfd9..0e28fff 100644
39495--- a/drivers/cpufreq/p4-clockmod.c
39496+++ b/drivers/cpufreq/p4-clockmod.c
39497@@ -134,10 +134,14 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
39498 case 0x0F: /* Core Duo */
39499 case 0x16: /* Celeron Core */
39500 case 0x1C: /* Atom */
39501- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39502+ pax_open_kernel();
39503+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39504+ pax_close_kernel();
39505 return speedstep_get_frequency(SPEEDSTEP_CPU_PCORE);
39506 case 0x0D: /* Pentium M (Dothan) */
39507- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39508+ pax_open_kernel();
39509+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39510+ pax_close_kernel();
39511 /* fall through */
39512 case 0x09: /* Pentium M (Banias) */
39513 return speedstep_get_frequency(SPEEDSTEP_CPU_PM);
39514@@ -149,7 +153,9 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
39515
39516 /* on P-4s, the TSC runs with constant frequency independent whether
39517 * throttling is active or not. */
39518- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39519+ pax_open_kernel();
39520+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39521+ pax_close_kernel();
39522
39523 if (speedstep_detect_processor() == SPEEDSTEP_CPU_P4M) {
39524 printk(KERN_WARNING PFX "Warning: Pentium 4-M detected. "
39525diff --git a/drivers/cpufreq/sparc-us3-cpufreq.c b/drivers/cpufreq/sparc-us3-cpufreq.c
39526index 9bb42ba..b01b4a2 100644
39527--- a/drivers/cpufreq/sparc-us3-cpufreq.c
39528+++ b/drivers/cpufreq/sparc-us3-cpufreq.c
39529@@ -18,14 +18,12 @@
39530 #include <asm/head.h>
39531 #include <asm/timer.h>
39532
39533-static struct cpufreq_driver *cpufreq_us3_driver;
39534-
39535 struct us3_freq_percpu_info {
39536 struct cpufreq_frequency_table table[4];
39537 };
39538
39539 /* Indexed by cpu number. */
39540-static struct us3_freq_percpu_info *us3_freq_table;
39541+static struct us3_freq_percpu_info us3_freq_table[NR_CPUS];
39542
39543 /* UltraSPARC-III has three dividers: 1, 2, and 32. These are controlled
39544 * in the Safari config register.
39545@@ -156,16 +154,27 @@ static int __init us3_freq_cpu_init(struct cpufreq_policy *policy)
39546
39547 static int us3_freq_cpu_exit(struct cpufreq_policy *policy)
39548 {
39549- if (cpufreq_us3_driver)
39550- us3_freq_target(policy, 0);
39551+ us3_freq_target(policy, 0);
39552
39553 return 0;
39554 }
39555
39556+static int __init us3_freq_init(void);
39557+static void __exit us3_freq_exit(void);
39558+
39559+static struct cpufreq_driver cpufreq_us3_driver = {
39560+ .init = us3_freq_cpu_init,
39561+ .verify = cpufreq_generic_frequency_table_verify,
39562+ .target_index = us3_freq_target,
39563+ .get = us3_freq_get,
39564+ .exit = us3_freq_cpu_exit,
39565+ .name = "UltraSPARC-III",
39566+
39567+};
39568+
39569 static int __init us3_freq_init(void)
39570 {
39571 unsigned long manuf, impl, ver;
39572- int ret;
39573
39574 if (tlb_type != cheetah && tlb_type != cheetah_plus)
39575 return -ENODEV;
39576@@ -178,55 +187,15 @@ static int __init us3_freq_init(void)
39577 (impl == CHEETAH_IMPL ||
39578 impl == CHEETAH_PLUS_IMPL ||
39579 impl == JAGUAR_IMPL ||
39580- impl == PANTHER_IMPL)) {
39581- struct cpufreq_driver *driver;
39582-
39583- ret = -ENOMEM;
39584- driver = kzalloc(sizeof(*driver), GFP_KERNEL);
39585- if (!driver)
39586- goto err_out;
39587-
39588- us3_freq_table = kzalloc((NR_CPUS * sizeof(*us3_freq_table)),
39589- GFP_KERNEL);
39590- if (!us3_freq_table)
39591- goto err_out;
39592-
39593- driver->init = us3_freq_cpu_init;
39594- driver->verify = cpufreq_generic_frequency_table_verify;
39595- driver->target_index = us3_freq_target;
39596- driver->get = us3_freq_get;
39597- driver->exit = us3_freq_cpu_exit;
39598- strcpy(driver->name, "UltraSPARC-III");
39599-
39600- cpufreq_us3_driver = driver;
39601- ret = cpufreq_register_driver(driver);
39602- if (ret)
39603- goto err_out;
39604-
39605- return 0;
39606-
39607-err_out:
39608- if (driver) {
39609- kfree(driver);
39610- cpufreq_us3_driver = NULL;
39611- }
39612- kfree(us3_freq_table);
39613- us3_freq_table = NULL;
39614- return ret;
39615- }
39616+ impl == PANTHER_IMPL))
39617+ return cpufreq_register_driver(&cpufreq_us3_driver);
39618
39619 return -ENODEV;
39620 }
39621
39622 static void __exit us3_freq_exit(void)
39623 {
39624- if (cpufreq_us3_driver) {
39625- cpufreq_unregister_driver(cpufreq_us3_driver);
39626- kfree(cpufreq_us3_driver);
39627- cpufreq_us3_driver = NULL;
39628- kfree(us3_freq_table);
39629- us3_freq_table = NULL;
39630- }
39631+ cpufreq_unregister_driver(&cpufreq_us3_driver);
39632 }
39633
39634 MODULE_AUTHOR("David S. Miller <davem@redhat.com>");
39635diff --git a/drivers/cpufreq/speedstep-centrino.c b/drivers/cpufreq/speedstep-centrino.c
39636index 7d4a315..21bb886 100644
39637--- a/drivers/cpufreq/speedstep-centrino.c
39638+++ b/drivers/cpufreq/speedstep-centrino.c
39639@@ -351,8 +351,11 @@ static int centrino_cpu_init(struct cpufreq_policy *policy)
39640 !cpu_has(cpu, X86_FEATURE_EST))
39641 return -ENODEV;
39642
39643- if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC))
39644- centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
39645+ if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC)) {
39646+ pax_open_kernel();
39647+ *(u8 *)&centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
39648+ pax_close_kernel();
39649+ }
39650
39651 if (policy->cpu != 0)
39652 return -ENODEV;
39653diff --git a/drivers/cpuidle/driver.c b/drivers/cpuidle/driver.c
39654index e431d11..d0b997e 100644
39655--- a/drivers/cpuidle/driver.c
39656+++ b/drivers/cpuidle/driver.c
39657@@ -194,7 +194,7 @@ static int poll_idle(struct cpuidle_device *dev,
39658
39659 static void poll_idle_init(struct cpuidle_driver *drv)
39660 {
39661- struct cpuidle_state *state = &drv->states[0];
39662+ cpuidle_state_no_const *state = &drv->states[0];
39663
39664 snprintf(state->name, CPUIDLE_NAME_LEN, "POLL");
39665 snprintf(state->desc, CPUIDLE_DESC_LEN, "CPUIDLE CORE POLL IDLE");
39666diff --git a/drivers/cpuidle/governor.c b/drivers/cpuidle/governor.c
39667index fb9f511..213e6cc 100644
39668--- a/drivers/cpuidle/governor.c
39669+++ b/drivers/cpuidle/governor.c
39670@@ -87,7 +87,7 @@ int cpuidle_register_governor(struct cpuidle_governor *gov)
39671 mutex_lock(&cpuidle_lock);
39672 if (__cpuidle_find_governor(gov->name) == NULL) {
39673 ret = 0;
39674- list_add_tail(&gov->governor_list, &cpuidle_governors);
39675+ pax_list_add_tail((struct list_head *)&gov->governor_list, &cpuidle_governors);
39676 if (!cpuidle_curr_governor ||
39677 cpuidle_curr_governor->rating < gov->rating)
39678 cpuidle_switch_governor(gov);
39679diff --git a/drivers/cpuidle/sysfs.c b/drivers/cpuidle/sysfs.c
39680index 97c5903..023ad23 100644
39681--- a/drivers/cpuidle/sysfs.c
39682+++ b/drivers/cpuidle/sysfs.c
39683@@ -135,7 +135,7 @@ static struct attribute *cpuidle_switch_attrs[] = {
39684 NULL
39685 };
39686
39687-static struct attribute_group cpuidle_attr_group = {
39688+static attribute_group_no_const cpuidle_attr_group = {
39689 .attrs = cpuidle_default_attrs,
39690 .name = "cpuidle",
39691 };
39692diff --git a/drivers/crypto/hifn_795x.c b/drivers/crypto/hifn_795x.c
39693index 8d2a772..33826c9 100644
39694--- a/drivers/crypto/hifn_795x.c
39695+++ b/drivers/crypto/hifn_795x.c
39696@@ -51,7 +51,7 @@ module_param_string(hifn_pll_ref, hifn_pll_ref, sizeof(hifn_pll_ref), 0444);
39697 MODULE_PARM_DESC(hifn_pll_ref,
39698 "PLL reference clock (pci[freq] or ext[freq], default ext)");
39699
39700-static atomic_t hifn_dev_number;
39701+static atomic_unchecked_t hifn_dev_number;
39702
39703 #define ACRYPTO_OP_DECRYPT 0
39704 #define ACRYPTO_OP_ENCRYPT 1
39705@@ -2577,7 +2577,7 @@ static int hifn_probe(struct pci_dev *pdev, const struct pci_device_id *id)
39706 goto err_out_disable_pci_device;
39707
39708 snprintf(name, sizeof(name), "hifn%d",
39709- atomic_inc_return(&hifn_dev_number)-1);
39710+ atomic_inc_return_unchecked(&hifn_dev_number)-1);
39711
39712 err = pci_request_regions(pdev, name);
39713 if (err)
39714diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
39715index 30b538d8..1610d75 100644
39716--- a/drivers/devfreq/devfreq.c
39717+++ b/drivers/devfreq/devfreq.c
39718@@ -673,7 +673,7 @@ int devfreq_add_governor(struct devfreq_governor *governor)
39719 goto err_out;
39720 }
39721
39722- list_add(&governor->node, &devfreq_governor_list);
39723+ pax_list_add((struct list_head *)&governor->node, &devfreq_governor_list);
39724
39725 list_for_each_entry(devfreq, &devfreq_list, node) {
39726 int ret = 0;
39727@@ -761,7 +761,7 @@ int devfreq_remove_governor(struct devfreq_governor *governor)
39728 }
39729 }
39730
39731- list_del(&governor->node);
39732+ pax_list_del((struct list_head *)&governor->node);
39733 err_out:
39734 mutex_unlock(&devfreq_list_lock);
39735
39736diff --git a/drivers/dma/sh/shdma-base.c b/drivers/dma/sh/shdma-base.c
39737index 42d4974..2714f36 100644
39738--- a/drivers/dma/sh/shdma-base.c
39739+++ b/drivers/dma/sh/shdma-base.c
39740@@ -228,8 +228,8 @@ static int shdma_alloc_chan_resources(struct dma_chan *chan)
39741 schan->slave_id = -EINVAL;
39742 }
39743
39744- schan->desc = kcalloc(NR_DESCS_PER_CHANNEL,
39745- sdev->desc_size, GFP_KERNEL);
39746+ schan->desc = kcalloc(sdev->desc_size,
39747+ NR_DESCS_PER_CHANNEL, GFP_KERNEL);
39748 if (!schan->desc) {
39749 ret = -ENOMEM;
39750 goto edescalloc;
39751diff --git a/drivers/dma/sh/shdmac.c b/drivers/dma/sh/shdmac.c
39752index 58eb857..d7e42c8 100644
39753--- a/drivers/dma/sh/shdmac.c
39754+++ b/drivers/dma/sh/shdmac.c
39755@@ -513,7 +513,7 @@ static int sh_dmae_nmi_handler(struct notifier_block *self,
39756 return ret;
39757 }
39758
39759-static struct notifier_block sh_dmae_nmi_notifier __read_mostly = {
39760+static struct notifier_block sh_dmae_nmi_notifier = {
39761 .notifier_call = sh_dmae_nmi_handler,
39762
39763 /* Run before NMI debug handler and KGDB */
39764diff --git a/drivers/edac/edac_device.c b/drivers/edac/edac_device.c
39765index 592af5f..bb1d583 100644
39766--- a/drivers/edac/edac_device.c
39767+++ b/drivers/edac/edac_device.c
39768@@ -477,9 +477,9 @@ void edac_device_reset_delay_period(struct edac_device_ctl_info *edac_dev,
39769 */
39770 int edac_device_alloc_index(void)
39771 {
39772- static atomic_t device_indexes = ATOMIC_INIT(0);
39773+ static atomic_unchecked_t device_indexes = ATOMIC_INIT(0);
39774
39775- return atomic_inc_return(&device_indexes) - 1;
39776+ return atomic_inc_return_unchecked(&device_indexes) - 1;
39777 }
39778 EXPORT_SYMBOL_GPL(edac_device_alloc_index);
39779
39780diff --git a/drivers/edac/edac_mc_sysfs.c b/drivers/edac/edac_mc_sysfs.c
39781index a6cd361..7bdbf53 100644
39782--- a/drivers/edac/edac_mc_sysfs.c
39783+++ b/drivers/edac/edac_mc_sysfs.c
39784@@ -154,7 +154,7 @@ static const char * const edac_caps[] = {
39785 struct dev_ch_attribute {
39786 struct device_attribute attr;
39787 int channel;
39788-};
39789+} __do_const;
39790
39791 #define DEVICE_CHANNEL(_name, _mode, _show, _store, _var) \
39792 struct dev_ch_attribute dev_attr_legacy_##_name = \
39793@@ -1011,14 +1011,16 @@ int edac_create_sysfs_mci_device(struct mem_ctl_info *mci)
39794 }
39795
39796 if (mci->set_sdram_scrub_rate || mci->get_sdram_scrub_rate) {
39797+ pax_open_kernel();
39798 if (mci->get_sdram_scrub_rate) {
39799- dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO;
39800- dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show;
39801+ *(umode_t *)&dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO;
39802+ *(void **)&dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show;
39803 }
39804 if (mci->set_sdram_scrub_rate) {
39805- dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR;
39806- dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store;
39807+ *(umode_t *)&dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR;
39808+ *(void **)&dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store;
39809 }
39810+ pax_close_kernel();
39811 err = device_create_file(&mci->dev,
39812 &dev_attr_sdram_scrub_rate);
39813 if (err) {
39814diff --git a/drivers/edac/edac_pci.c b/drivers/edac/edac_pci.c
39815index 2cf44b4d..6dd2dc7 100644
39816--- a/drivers/edac/edac_pci.c
39817+++ b/drivers/edac/edac_pci.c
39818@@ -29,7 +29,7 @@
39819
39820 static DEFINE_MUTEX(edac_pci_ctls_mutex);
39821 static LIST_HEAD(edac_pci_list);
39822-static atomic_t pci_indexes = ATOMIC_INIT(0);
39823+static atomic_unchecked_t pci_indexes = ATOMIC_INIT(0);
39824
39825 /*
39826 * edac_pci_alloc_ctl_info
39827@@ -315,7 +315,7 @@ EXPORT_SYMBOL_GPL(edac_pci_reset_delay_period);
39828 */
39829 int edac_pci_alloc_index(void)
39830 {
39831- return atomic_inc_return(&pci_indexes) - 1;
39832+ return atomic_inc_return_unchecked(&pci_indexes) - 1;
39833 }
39834 EXPORT_SYMBOL_GPL(edac_pci_alloc_index);
39835
39836diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
39837index e8658e4..22746d6 100644
39838--- a/drivers/edac/edac_pci_sysfs.c
39839+++ b/drivers/edac/edac_pci_sysfs.c
39840@@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
39841 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
39842 static int edac_pci_poll_msec = 1000; /* one second workq period */
39843
39844-static atomic_t pci_parity_count = ATOMIC_INIT(0);
39845-static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
39846+static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
39847+static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
39848
39849 static struct kobject *edac_pci_top_main_kobj;
39850 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
39851@@ -235,7 +235,7 @@ struct edac_pci_dev_attribute {
39852 void *value;
39853 ssize_t(*show) (void *, char *);
39854 ssize_t(*store) (void *, const char *, size_t);
39855-};
39856+} __do_const;
39857
39858 /* Set of show/store abstract level functions for PCI Parity object */
39859 static ssize_t edac_pci_dev_show(struct kobject *kobj, struct attribute *attr,
39860@@ -579,7 +579,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39861 edac_printk(KERN_CRIT, EDAC_PCI,
39862 "Signaled System Error on %s\n",
39863 pci_name(dev));
39864- atomic_inc(&pci_nonparity_count);
39865+ atomic_inc_unchecked(&pci_nonparity_count);
39866 }
39867
39868 if (status & (PCI_STATUS_PARITY)) {
39869@@ -587,7 +587,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39870 "Master Data Parity Error on %s\n",
39871 pci_name(dev));
39872
39873- atomic_inc(&pci_parity_count);
39874+ atomic_inc_unchecked(&pci_parity_count);
39875 }
39876
39877 if (status & (PCI_STATUS_DETECTED_PARITY)) {
39878@@ -595,7 +595,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39879 "Detected Parity Error on %s\n",
39880 pci_name(dev));
39881
39882- atomic_inc(&pci_parity_count);
39883+ atomic_inc_unchecked(&pci_parity_count);
39884 }
39885 }
39886
39887@@ -618,7 +618,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39888 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
39889 "Signaled System Error on %s\n",
39890 pci_name(dev));
39891- atomic_inc(&pci_nonparity_count);
39892+ atomic_inc_unchecked(&pci_nonparity_count);
39893 }
39894
39895 if (status & (PCI_STATUS_PARITY)) {
39896@@ -626,7 +626,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39897 "Master Data Parity Error on "
39898 "%s\n", pci_name(dev));
39899
39900- atomic_inc(&pci_parity_count);
39901+ atomic_inc_unchecked(&pci_parity_count);
39902 }
39903
39904 if (status & (PCI_STATUS_DETECTED_PARITY)) {
39905@@ -634,7 +634,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39906 "Detected Parity Error on %s\n",
39907 pci_name(dev));
39908
39909- atomic_inc(&pci_parity_count);
39910+ atomic_inc_unchecked(&pci_parity_count);
39911 }
39912 }
39913 }
39914@@ -672,7 +672,7 @@ void edac_pci_do_parity_check(void)
39915 if (!check_pci_errors)
39916 return;
39917
39918- before_count = atomic_read(&pci_parity_count);
39919+ before_count = atomic_read_unchecked(&pci_parity_count);
39920
39921 /* scan all PCI devices looking for a Parity Error on devices and
39922 * bridges.
39923@@ -684,7 +684,7 @@ void edac_pci_do_parity_check(void)
39924 /* Only if operator has selected panic on PCI Error */
39925 if (edac_pci_get_panic_on_pe()) {
39926 /* If the count is different 'after' from 'before' */
39927- if (before_count != atomic_read(&pci_parity_count))
39928+ if (before_count != atomic_read_unchecked(&pci_parity_count))
39929 panic("EDAC: PCI Parity Error");
39930 }
39931 }
39932diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
39933index 51b7e3a..aa8a3e8 100644
39934--- a/drivers/edac/mce_amd.h
39935+++ b/drivers/edac/mce_amd.h
39936@@ -77,7 +77,7 @@ struct amd_decoder_ops {
39937 bool (*mc0_mce)(u16, u8);
39938 bool (*mc1_mce)(u16, u8);
39939 bool (*mc2_mce)(u16, u8);
39940-};
39941+} __no_const;
39942
39943 void amd_report_gart_errors(bool);
39944 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
39945diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
39946index 57ea7f4..af06b76 100644
39947--- a/drivers/firewire/core-card.c
39948+++ b/drivers/firewire/core-card.c
39949@@ -528,9 +528,9 @@ void fw_card_initialize(struct fw_card *card,
39950 const struct fw_card_driver *driver,
39951 struct device *device)
39952 {
39953- static atomic_t index = ATOMIC_INIT(-1);
39954+ static atomic_unchecked_t index = ATOMIC_INIT(-1);
39955
39956- card->index = atomic_inc_return(&index);
39957+ card->index = atomic_inc_return_unchecked(&index);
39958 card->driver = driver;
39959 card->device = device;
39960 card->current_tlabel = 0;
39961@@ -680,7 +680,7 @@ EXPORT_SYMBOL_GPL(fw_card_release);
39962
39963 void fw_core_remove_card(struct fw_card *card)
39964 {
39965- struct fw_card_driver dummy_driver = dummy_driver_template;
39966+ fw_card_driver_no_const dummy_driver = dummy_driver_template;
39967
39968 card->driver->update_phy_reg(card, 4,
39969 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
39970diff --git a/drivers/firewire/core-device.c b/drivers/firewire/core-device.c
39971index 2c6d5e1..a2cca6b 100644
39972--- a/drivers/firewire/core-device.c
39973+++ b/drivers/firewire/core-device.c
39974@@ -253,7 +253,7 @@ EXPORT_SYMBOL(fw_device_enable_phys_dma);
39975 struct config_rom_attribute {
39976 struct device_attribute attr;
39977 u32 key;
39978-};
39979+} __do_const;
39980
39981 static ssize_t show_immediate(struct device *dev,
39982 struct device_attribute *dattr, char *buf)
39983diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
39984index eb6935c..3cc2bfa 100644
39985--- a/drivers/firewire/core-transaction.c
39986+++ b/drivers/firewire/core-transaction.c
39987@@ -38,6 +38,7 @@
39988 #include <linux/timer.h>
39989 #include <linux/types.h>
39990 #include <linux/workqueue.h>
39991+#include <linux/sched.h>
39992
39993 #include <asm/byteorder.h>
39994
39995diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
39996index e1480ff6..1a429bd 100644
39997--- a/drivers/firewire/core.h
39998+++ b/drivers/firewire/core.h
39999@@ -111,6 +111,7 @@ struct fw_card_driver {
40000
40001 int (*stop_iso)(struct fw_iso_context *ctx);
40002 };
40003+typedef struct fw_card_driver __no_const fw_card_driver_no_const;
40004
40005 void fw_card_initialize(struct fw_card *card,
40006 const struct fw_card_driver *driver, struct device *device);
40007diff --git a/drivers/firewire/ohci.c b/drivers/firewire/ohci.c
40008index a66a321..f6caf20 100644
40009--- a/drivers/firewire/ohci.c
40010+++ b/drivers/firewire/ohci.c
40011@@ -2056,10 +2056,12 @@ static void bus_reset_work(struct work_struct *work)
40012 be32_to_cpu(ohci->next_header));
40013 }
40014
40015+#ifndef CONFIG_GRKERNSEC
40016 if (param_remote_dma) {
40017 reg_write(ohci, OHCI1394_PhyReqFilterHiSet, ~0);
40018 reg_write(ohci, OHCI1394_PhyReqFilterLoSet, ~0);
40019 }
40020+#endif
40021
40022 spin_unlock_irq(&ohci->lock);
40023
40024@@ -2591,8 +2593,10 @@ static int ohci_enable_phys_dma(struct fw_card *card,
40025 unsigned long flags;
40026 int n, ret = 0;
40027
40028+#ifndef CONFIG_GRKERNSEC
40029 if (param_remote_dma)
40030 return 0;
40031+#endif
40032
40033 /*
40034 * FIXME: Make sure this bitmask is cleared when we clear the busReset
40035diff --git a/drivers/firmware/dmi-id.c b/drivers/firmware/dmi-id.c
40036index 94a58a0..f5eba42 100644
40037--- a/drivers/firmware/dmi-id.c
40038+++ b/drivers/firmware/dmi-id.c
40039@@ -16,7 +16,7 @@
40040 struct dmi_device_attribute{
40041 struct device_attribute dev_attr;
40042 int field;
40043-};
40044+} __do_const;
40045 #define to_dmi_dev_attr(_dev_attr) \
40046 container_of(_dev_attr, struct dmi_device_attribute, dev_attr)
40047
40048diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
40049index 17afc51..0ef90cd 100644
40050--- a/drivers/firmware/dmi_scan.c
40051+++ b/drivers/firmware/dmi_scan.c
40052@@ -835,7 +835,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
40053 if (buf == NULL)
40054 return -1;
40055
40056- dmi_table(buf, dmi_len, dmi_num, decode, private_data);
40057+ dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
40058
40059 dmi_unmap(buf);
40060 return 0;
40061diff --git a/drivers/firmware/efi/cper.c b/drivers/firmware/efi/cper.c
40062index 5b53d61..72cee96 100644
40063--- a/drivers/firmware/efi/cper.c
40064+++ b/drivers/firmware/efi/cper.c
40065@@ -44,12 +44,12 @@ static char rcd_decode_str[CPER_REC_LEN];
40066 */
40067 u64 cper_next_record_id(void)
40068 {
40069- static atomic64_t seq;
40070+ static atomic64_unchecked_t seq;
40071
40072- if (!atomic64_read(&seq))
40073- atomic64_set(&seq, ((u64)get_seconds()) << 32);
40074+ if (!atomic64_read_unchecked(&seq))
40075+ atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
40076
40077- return atomic64_inc_return(&seq);
40078+ return atomic64_inc_return_unchecked(&seq);
40079 }
40080 EXPORT_SYMBOL_GPL(cper_next_record_id);
40081
40082diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c
40083index 8590099..d83627a 100644
40084--- a/drivers/firmware/efi/efi.c
40085+++ b/drivers/firmware/efi/efi.c
40086@@ -148,14 +148,16 @@ static struct attribute_group efi_subsys_attr_group = {
40087 };
40088
40089 static struct efivars generic_efivars;
40090-static struct efivar_operations generic_ops;
40091+static efivar_operations_no_const generic_ops __read_only;
40092
40093 static int generic_ops_register(void)
40094 {
40095- generic_ops.get_variable = efi.get_variable;
40096- generic_ops.set_variable = efi.set_variable;
40097- generic_ops.get_next_variable = efi.get_next_variable;
40098- generic_ops.query_variable_store = efi_query_variable_store;
40099+ pax_open_kernel();
40100+ *(void **)&generic_ops.get_variable = efi.get_variable;
40101+ *(void **)&generic_ops.set_variable = efi.set_variable;
40102+ *(void **)&generic_ops.get_next_variable = efi.get_next_variable;
40103+ *(void **)&generic_ops.query_variable_store = efi_query_variable_store;
40104+ pax_close_kernel();
40105
40106 return efivars_register(&generic_efivars, &generic_ops, efi_kobj);
40107 }
40108diff --git a/drivers/firmware/efi/efivars.c b/drivers/firmware/efi/efivars.c
40109index f256ecd..387dcb1 100644
40110--- a/drivers/firmware/efi/efivars.c
40111+++ b/drivers/firmware/efi/efivars.c
40112@@ -589,7 +589,7 @@ efivar_create_sysfs_entry(struct efivar_entry *new_var)
40113 static int
40114 create_efivars_bin_attributes(void)
40115 {
40116- struct bin_attribute *attr;
40117+ bin_attribute_no_const *attr;
40118 int error;
40119
40120 /* new_var */
40121diff --git a/drivers/firmware/google/memconsole.c b/drivers/firmware/google/memconsole.c
40122index 2f569aa..c95f4fb 100644
40123--- a/drivers/firmware/google/memconsole.c
40124+++ b/drivers/firmware/google/memconsole.c
40125@@ -155,7 +155,10 @@ static int __init memconsole_init(void)
40126 if (!found_memconsole())
40127 return -ENODEV;
40128
40129- memconsole_bin_attr.size = memconsole_length;
40130+ pax_open_kernel();
40131+ *(size_t *)&memconsole_bin_attr.size = memconsole_length;
40132+ pax_close_kernel();
40133+
40134 return sysfs_create_bin_file(firmware_kobj, &memconsole_bin_attr);
40135 }
40136
40137diff --git a/drivers/gpio/gpio-em.c b/drivers/gpio/gpio-em.c
40138index fe49ec3..1ade794 100644
40139--- a/drivers/gpio/gpio-em.c
40140+++ b/drivers/gpio/gpio-em.c
40141@@ -278,7 +278,7 @@ static int em_gio_probe(struct platform_device *pdev)
40142 struct em_gio_priv *p;
40143 struct resource *io[2], *irq[2];
40144 struct gpio_chip *gpio_chip;
40145- struct irq_chip *irq_chip;
40146+ irq_chip_no_const *irq_chip;
40147 const char *name = dev_name(&pdev->dev);
40148 int ret;
40149
40150diff --git a/drivers/gpio/gpio-ich.c b/drivers/gpio/gpio-ich.c
40151index 3784e81..73637b5 100644
40152--- a/drivers/gpio/gpio-ich.c
40153+++ b/drivers/gpio/gpio-ich.c
40154@@ -94,7 +94,7 @@ struct ichx_desc {
40155 * this option allows driver caching written output values
40156 */
40157 bool use_outlvl_cache;
40158-};
40159+} __do_const;
40160
40161 static struct {
40162 spinlock_t lock;
40163diff --git a/drivers/gpio/gpio-rcar.c b/drivers/gpio/gpio-rcar.c
40164index bf6c094..6573caf 100644
40165--- a/drivers/gpio/gpio-rcar.c
40166+++ b/drivers/gpio/gpio-rcar.c
40167@@ -357,7 +357,7 @@ static int gpio_rcar_probe(struct platform_device *pdev)
40168 struct gpio_rcar_priv *p;
40169 struct resource *io, *irq;
40170 struct gpio_chip *gpio_chip;
40171- struct irq_chip *irq_chip;
40172+ irq_chip_no_const *irq_chip;
40173 struct device *dev = &pdev->dev;
40174 const char *name = dev_name(dev);
40175 int ret;
40176diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
40177index dbf28fa..04dad4e 100644
40178--- a/drivers/gpio/gpio-vr41xx.c
40179+++ b/drivers/gpio/gpio-vr41xx.c
40180@@ -224,7 +224,7 @@ static int giu_get_irq(unsigned int irq)
40181 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
40182 maskl, pendl, maskh, pendh);
40183
40184- atomic_inc(&irq_err_count);
40185+ atomic_inc_unchecked(&irq_err_count);
40186
40187 return -EINVAL;
40188 }
40189diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
40190index e8e98ca..10f416e 100644
40191--- a/drivers/gpio/gpiolib.c
40192+++ b/drivers/gpio/gpiolib.c
40193@@ -537,8 +537,10 @@ static void gpiochip_irqchip_remove(struct gpio_chip *gpiochip)
40194 }
40195
40196 if (gpiochip->irqchip) {
40197- gpiochip->irqchip->irq_request_resources = NULL;
40198- gpiochip->irqchip->irq_release_resources = NULL;
40199+ pax_open_kernel();
40200+ *(void **)&gpiochip->irqchip->irq_request_resources = NULL;
40201+ *(void **)&gpiochip->irqchip->irq_release_resources = NULL;
40202+ pax_close_kernel();
40203 gpiochip->irqchip = NULL;
40204 }
40205 }
40206@@ -604,8 +606,11 @@ int gpiochip_irqchip_add(struct gpio_chip *gpiochip,
40207 gpiochip->irqchip = NULL;
40208 return -EINVAL;
40209 }
40210- irqchip->irq_request_resources = gpiochip_irq_reqres;
40211- irqchip->irq_release_resources = gpiochip_irq_relres;
40212+
40213+ pax_open_kernel();
40214+ *(void **)&irqchip->irq_request_resources = gpiochip_irq_reqres;
40215+ *(void **)&irqchip->irq_release_resources = gpiochip_irq_relres;
40216+ pax_close_kernel();
40217
40218 /*
40219 * Prepare the mapping since the irqchip shall be orthogonal to
40220diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c
40221index e79c8d3..a9370bc 100644
40222--- a/drivers/gpu/drm/drm_crtc.c
40223+++ b/drivers/gpu/drm/drm_crtc.c
40224@@ -3900,7 +3900,7 @@ int drm_mode_getproperty_ioctl(struct drm_device *dev,
40225 goto done;
40226 }
40227
40228- if (copy_to_user(&enum_ptr[copied].name,
40229+ if (copy_to_user(enum_ptr[copied].name,
40230 &prop_enum->name, DRM_PROP_NAME_LEN)) {
40231 ret = -EFAULT;
40232 goto done;
40233diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
40234index bc3da32..7289357 100644
40235--- a/drivers/gpu/drm/drm_drv.c
40236+++ b/drivers/gpu/drm/drm_drv.c
40237@@ -443,7 +443,7 @@ void drm_unplug_dev(struct drm_device *dev)
40238
40239 drm_device_set_unplugged(dev);
40240
40241- if (dev->open_count == 0) {
40242+ if (local_read(&dev->open_count) == 0) {
40243 drm_put_dev(dev);
40244 }
40245 mutex_unlock(&drm_global_mutex);
40246diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
40247index ed7bc68..0d536af 100644
40248--- a/drivers/gpu/drm/drm_fops.c
40249+++ b/drivers/gpu/drm/drm_fops.c
40250@@ -89,7 +89,7 @@ int drm_open(struct inode *inode, struct file *filp)
40251 return PTR_ERR(minor);
40252
40253 dev = minor->dev;
40254- if (!dev->open_count++)
40255+ if (local_inc_return(&dev->open_count) == 1)
40256 need_setup = 1;
40257
40258 /* share address_space across all char-devs of a single device */
40259@@ -106,7 +106,7 @@ int drm_open(struct inode *inode, struct file *filp)
40260 return 0;
40261
40262 err_undo:
40263- dev->open_count--;
40264+ local_dec(&dev->open_count);
40265 drm_minor_release(minor);
40266 return retcode;
40267 }
40268@@ -376,7 +376,7 @@ int drm_release(struct inode *inode, struct file *filp)
40269
40270 mutex_lock(&drm_global_mutex);
40271
40272- DRM_DEBUG("open_count = %d\n", dev->open_count);
40273+ DRM_DEBUG("open_count = %ld\n", local_read(&dev->open_count));
40274
40275 mutex_lock(&dev->struct_mutex);
40276 list_del(&file_priv->lhead);
40277@@ -389,10 +389,10 @@ int drm_release(struct inode *inode, struct file *filp)
40278 * Begin inline drm_release
40279 */
40280
40281- DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
40282+ DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %ld\n",
40283 task_pid_nr(current),
40284 (long)old_encode_dev(file_priv->minor->kdev->devt),
40285- dev->open_count);
40286+ local_read(&dev->open_count));
40287
40288 /* Release any auth tokens that might point to this file_priv,
40289 (do that under the drm_global_mutex) */
40290@@ -465,7 +465,7 @@ int drm_release(struct inode *inode, struct file *filp)
40291 * End inline drm_release
40292 */
40293
40294- if (!--dev->open_count) {
40295+ if (local_dec_and_test(&dev->open_count)) {
40296 retcode = drm_lastclose(dev);
40297 if (drm_device_is_unplugged(dev))
40298 drm_put_dev(dev);
40299diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
40300index 3d2e91c..d31c4c9 100644
40301--- a/drivers/gpu/drm/drm_global.c
40302+++ b/drivers/gpu/drm/drm_global.c
40303@@ -36,7 +36,7 @@
40304 struct drm_global_item {
40305 struct mutex mutex;
40306 void *object;
40307- int refcount;
40308+ atomic_t refcount;
40309 };
40310
40311 static struct drm_global_item glob[DRM_GLOBAL_NUM];
40312@@ -49,7 +49,7 @@ void drm_global_init(void)
40313 struct drm_global_item *item = &glob[i];
40314 mutex_init(&item->mutex);
40315 item->object = NULL;
40316- item->refcount = 0;
40317+ atomic_set(&item->refcount, 0);
40318 }
40319 }
40320
40321@@ -59,7 +59,7 @@ void drm_global_release(void)
40322 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
40323 struct drm_global_item *item = &glob[i];
40324 BUG_ON(item->object != NULL);
40325- BUG_ON(item->refcount != 0);
40326+ BUG_ON(atomic_read(&item->refcount) != 0);
40327 }
40328 }
40329
40330@@ -69,7 +69,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
40331 struct drm_global_item *item = &glob[ref->global_type];
40332
40333 mutex_lock(&item->mutex);
40334- if (item->refcount == 0) {
40335+ if (atomic_read(&item->refcount) == 0) {
40336 item->object = kzalloc(ref->size, GFP_KERNEL);
40337 if (unlikely(item->object == NULL)) {
40338 ret = -ENOMEM;
40339@@ -82,7 +82,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
40340 goto out_err;
40341
40342 }
40343- ++item->refcount;
40344+ atomic_inc(&item->refcount);
40345 ref->object = item->object;
40346 mutex_unlock(&item->mutex);
40347 return 0;
40348@@ -98,9 +98,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
40349 struct drm_global_item *item = &glob[ref->global_type];
40350
40351 mutex_lock(&item->mutex);
40352- BUG_ON(item->refcount == 0);
40353+ BUG_ON(atomic_read(&item->refcount) == 0);
40354 BUG_ON(ref->object != item->object);
40355- if (--item->refcount == 0) {
40356+ if (atomic_dec_and_test(&item->refcount)) {
40357 ref->release(ref);
40358 item->object = NULL;
40359 }
40360diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
40361index 51efebd..2b70935 100644
40362--- a/drivers/gpu/drm/drm_info.c
40363+++ b/drivers/gpu/drm/drm_info.c
40364@@ -76,10 +76,13 @@ int drm_vm_info(struct seq_file *m, void *data)
40365 struct drm_local_map *map;
40366 struct drm_map_list *r_list;
40367
40368- /* Hardcoded from _DRM_FRAME_BUFFER,
40369- _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
40370- _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
40371- const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
40372+ static const char * const types[] = {
40373+ [_DRM_FRAME_BUFFER] = "FB",
40374+ [_DRM_REGISTERS] = "REG",
40375+ [_DRM_SHM] = "SHM",
40376+ [_DRM_AGP] = "AGP",
40377+ [_DRM_SCATTER_GATHER] = "SG",
40378+ [_DRM_CONSISTENT] = "PCI"};
40379 const char *type;
40380 int i;
40381
40382@@ -90,7 +93,7 @@ int drm_vm_info(struct seq_file *m, void *data)
40383 map = r_list->map;
40384 if (!map)
40385 continue;
40386- if (map->type < 0 || map->type > 5)
40387+ if (map->type >= ARRAY_SIZE(types))
40388 type = "??";
40389 else
40390 type = types[map->type];
40391diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
40392index 2f4c4343..dd12cd2 100644
40393--- a/drivers/gpu/drm/drm_ioc32.c
40394+++ b/drivers/gpu/drm/drm_ioc32.c
40395@@ -457,7 +457,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
40396 request = compat_alloc_user_space(nbytes);
40397 if (!access_ok(VERIFY_WRITE, request, nbytes))
40398 return -EFAULT;
40399- list = (struct drm_buf_desc *) (request + 1);
40400+ list = (struct drm_buf_desc __user *) (request + 1);
40401
40402 if (__put_user(count, &request->count)
40403 || __put_user(list, &request->list))
40404@@ -518,7 +518,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
40405 request = compat_alloc_user_space(nbytes);
40406 if (!access_ok(VERIFY_WRITE, request, nbytes))
40407 return -EFAULT;
40408- list = (struct drm_buf_pub *) (request + 1);
40409+ list = (struct drm_buf_pub __user *) (request + 1);
40410
40411 if (__put_user(count, &request->count)
40412 || __put_user(list, &request->list))
40413@@ -1016,7 +1016,7 @@ static int compat_drm_wait_vblank(struct file *file, unsigned int cmd,
40414 return 0;
40415 }
40416
40417-drm_ioctl_compat_t *drm_compat_ioctls[] = {
40418+drm_ioctl_compat_t drm_compat_ioctls[] = {
40419 [DRM_IOCTL_NR(DRM_IOCTL_VERSION32)] = compat_drm_version,
40420 [DRM_IOCTL_NR(DRM_IOCTL_GET_UNIQUE32)] = compat_drm_getunique,
40421 [DRM_IOCTL_NR(DRM_IOCTL_GET_MAP32)] = compat_drm_getmap,
40422@@ -1062,7 +1062,6 @@ drm_ioctl_compat_t *drm_compat_ioctls[] = {
40423 long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40424 {
40425 unsigned int nr = DRM_IOCTL_NR(cmd);
40426- drm_ioctl_compat_t *fn;
40427 int ret;
40428
40429 /* Assume that ioctls without an explicit compat routine will just
40430@@ -1072,10 +1071,8 @@ long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40431 if (nr >= ARRAY_SIZE(drm_compat_ioctls))
40432 return drm_ioctl(filp, cmd, arg);
40433
40434- fn = drm_compat_ioctls[nr];
40435-
40436- if (fn != NULL)
40437- ret = (*fn) (filp, cmd, arg);
40438+ if (drm_compat_ioctls[nr] != NULL)
40439+ ret = (*drm_compat_ioctls[nr]) (filp, cmd, arg);
40440 else
40441 ret = drm_ioctl(filp, cmd, arg);
40442
40443diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
40444index 00587a1..57a65ca 100644
40445--- a/drivers/gpu/drm/drm_ioctl.c
40446+++ b/drivers/gpu/drm/drm_ioctl.c
40447@@ -642,7 +642,7 @@ long drm_ioctl(struct file *filp,
40448 struct drm_file *file_priv = filp->private_data;
40449 struct drm_device *dev;
40450 const struct drm_ioctl_desc *ioctl = NULL;
40451- drm_ioctl_t *func;
40452+ drm_ioctl_no_const_t func;
40453 unsigned int nr = DRM_IOCTL_NR(cmd);
40454 int retcode = -EINVAL;
40455 char stack_kdata[128];
40456diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
40457index 93ec5dc..82acbaf 100644
40458--- a/drivers/gpu/drm/i810/i810_drv.h
40459+++ b/drivers/gpu/drm/i810/i810_drv.h
40460@@ -110,8 +110,8 @@ typedef struct drm_i810_private {
40461 int page_flipping;
40462
40463 wait_queue_head_t irq_queue;
40464- atomic_t irq_received;
40465- atomic_t irq_emitted;
40466+ atomic_unchecked_t irq_received;
40467+ atomic_unchecked_t irq_emitted;
40468
40469 int front_offset;
40470 } drm_i810_private_t;
40471diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
40472index 318ade9..1f5de55 100644
40473--- a/drivers/gpu/drm/i915/i915_dma.c
40474+++ b/drivers/gpu/drm/i915/i915_dma.c
40475@@ -1294,7 +1294,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
40476 * locking inversion with the driver load path. And the access here is
40477 * completely racy anyway. So don't bother with locking for now.
40478 */
40479- return dev->open_count == 0;
40480+ return local_read(&dev->open_count) == 0;
40481 }
40482
40483 static const struct vga_switcheroo_client_ops i915_switcheroo_ops = {
40484diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
40485index 1a0611b..dd1fbfc 100644
40486--- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
40487+++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
40488@@ -866,12 +866,12 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
40489 static int
40490 validate_exec_list(struct drm_device *dev,
40491 struct drm_i915_gem_exec_object2 *exec,
40492- int count)
40493+ unsigned int count)
40494 {
40495 unsigned relocs_total = 0;
40496 unsigned relocs_max = UINT_MAX / sizeof(struct drm_i915_gem_relocation_entry);
40497 unsigned invalid_flags;
40498- int i;
40499+ unsigned int i;
40500
40501 invalid_flags = __EXEC_OBJECT_UNKNOWN_FLAGS;
40502 if (USES_FULL_PPGTT(dev))
40503diff --git a/drivers/gpu/drm/i915/i915_ioc32.c b/drivers/gpu/drm/i915/i915_ioc32.c
40504index 2e0613e..a8b94d9 100644
40505--- a/drivers/gpu/drm/i915/i915_ioc32.c
40506+++ b/drivers/gpu/drm/i915/i915_ioc32.c
40507@@ -181,7 +181,7 @@ static int compat_i915_alloc(struct file *file, unsigned int cmd,
40508 (unsigned long)request);
40509 }
40510
40511-static drm_ioctl_compat_t *i915_compat_ioctls[] = {
40512+static drm_ioctl_compat_t i915_compat_ioctls[] = {
40513 [DRM_I915_BATCHBUFFER] = compat_i915_batchbuffer,
40514 [DRM_I915_CMDBUFFER] = compat_i915_cmdbuffer,
40515 [DRM_I915_GETPARAM] = compat_i915_getparam,
40516@@ -202,18 +202,15 @@ static drm_ioctl_compat_t *i915_compat_ioctls[] = {
40517 long i915_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40518 {
40519 unsigned int nr = DRM_IOCTL_NR(cmd);
40520- drm_ioctl_compat_t *fn = NULL;
40521 int ret;
40522
40523 if (nr < DRM_COMMAND_BASE)
40524 return drm_compat_ioctl(filp, cmd, arg);
40525
40526- if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(i915_compat_ioctls))
40527- fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
40528-
40529- if (fn != NULL)
40530+ if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(i915_compat_ioctls)) {
40531+ drm_ioctl_compat_t fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
40532 ret = (*fn) (filp, cmd, arg);
40533- else
40534+ } else
40535 ret = drm_ioctl(filp, cmd, arg);
40536
40537 return ret;
40538diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
40539index 9cb5c95..9228666 100644
40540--- a/drivers/gpu/drm/i915/intel_display.c
40541+++ b/drivers/gpu/drm/i915/intel_display.c
40542@@ -12811,13 +12811,13 @@ struct intel_quirk {
40543 int subsystem_vendor;
40544 int subsystem_device;
40545 void (*hook)(struct drm_device *dev);
40546-};
40547+} __do_const;
40548
40549 /* For systems that don't have a meaningful PCI subdevice/subvendor ID */
40550 struct intel_dmi_quirk {
40551 void (*hook)(struct drm_device *dev);
40552 const struct dmi_system_id (*dmi_id_list)[];
40553-};
40554+} __do_const;
40555
40556 static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
40557 {
40558@@ -12825,18 +12825,20 @@ static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
40559 return 1;
40560 }
40561
40562-static const struct intel_dmi_quirk intel_dmi_quirks[] = {
40563+static const struct dmi_system_id intel_dmi_quirks_table[] = {
40564 {
40565- .dmi_id_list = &(const struct dmi_system_id[]) {
40566- {
40567- .callback = intel_dmi_reverse_brightness,
40568- .ident = "NCR Corporation",
40569- .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
40570- DMI_MATCH(DMI_PRODUCT_NAME, ""),
40571- },
40572- },
40573- { } /* terminating entry */
40574+ .callback = intel_dmi_reverse_brightness,
40575+ .ident = "NCR Corporation",
40576+ .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
40577+ DMI_MATCH(DMI_PRODUCT_NAME, ""),
40578 },
40579+ },
40580+ { } /* terminating entry */
40581+};
40582+
40583+static const struct intel_dmi_quirk intel_dmi_quirks[] = {
40584+ {
40585+ .dmi_id_list = &intel_dmi_quirks_table,
40586 .hook = quirk_invert_brightness,
40587 },
40588 };
40589diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
40590index b4a2014..219ab78 100644
40591--- a/drivers/gpu/drm/mga/mga_drv.h
40592+++ b/drivers/gpu/drm/mga/mga_drv.h
40593@@ -122,9 +122,9 @@ typedef struct drm_mga_private {
40594 u32 clear_cmd;
40595 u32 maccess;
40596
40597- atomic_t vbl_received; /**< Number of vblanks received. */
40598+ atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
40599 wait_queue_head_t fence_queue;
40600- atomic_t last_fence_retired;
40601+ atomic_unchecked_t last_fence_retired;
40602 u32 next_fence_to_post;
40603
40604 unsigned int fb_cpp;
40605diff --git a/drivers/gpu/drm/mga/mga_ioc32.c b/drivers/gpu/drm/mga/mga_ioc32.c
40606index 729bfd5..ead8823 100644
40607--- a/drivers/gpu/drm/mga/mga_ioc32.c
40608+++ b/drivers/gpu/drm/mga/mga_ioc32.c
40609@@ -190,7 +190,7 @@ static int compat_mga_dma_bootstrap(struct file *file, unsigned int cmd,
40610 return 0;
40611 }
40612
40613-drm_ioctl_compat_t *mga_compat_ioctls[] = {
40614+drm_ioctl_compat_t mga_compat_ioctls[] = {
40615 [DRM_MGA_INIT] = compat_mga_init,
40616 [DRM_MGA_GETPARAM] = compat_mga_getparam,
40617 [DRM_MGA_DMA_BOOTSTRAP] = compat_mga_dma_bootstrap,
40618@@ -208,18 +208,15 @@ drm_ioctl_compat_t *mga_compat_ioctls[] = {
40619 long mga_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40620 {
40621 unsigned int nr = DRM_IOCTL_NR(cmd);
40622- drm_ioctl_compat_t *fn = NULL;
40623 int ret;
40624
40625 if (nr < DRM_COMMAND_BASE)
40626 return drm_compat_ioctl(filp, cmd, arg);
40627
40628- if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(mga_compat_ioctls))
40629- fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
40630-
40631- if (fn != NULL)
40632+ if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(mga_compat_ioctls)) {
40633+ drm_ioctl_compat_t fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
40634 ret = (*fn) (filp, cmd, arg);
40635- else
40636+ } else
40637 ret = drm_ioctl(filp, cmd, arg);
40638
40639 return ret;
40640diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
40641index 1b071b8..de8601a 100644
40642--- a/drivers/gpu/drm/mga/mga_irq.c
40643+++ b/drivers/gpu/drm/mga/mga_irq.c
40644@@ -43,7 +43,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
40645 if (crtc != 0)
40646 return 0;
40647
40648- return atomic_read(&dev_priv->vbl_received);
40649+ return atomic_read_unchecked(&dev_priv->vbl_received);
40650 }
40651
40652
40653@@ -59,7 +59,7 @@ irqreturn_t mga_driver_irq_handler(int irq, void *arg)
40654 /* VBLANK interrupt */
40655 if (status & MGA_VLINEPEN) {
40656 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
40657- atomic_inc(&dev_priv->vbl_received);
40658+ atomic_inc_unchecked(&dev_priv->vbl_received);
40659 drm_handle_vblank(dev, 0);
40660 handled = 1;
40661 }
40662@@ -78,7 +78,7 @@ irqreturn_t mga_driver_irq_handler(int irq, void *arg)
40663 if ((prim_start & ~0x03) != (prim_end & ~0x03))
40664 MGA_WRITE(MGA_PRIMEND, prim_end);
40665
40666- atomic_inc(&dev_priv->last_fence_retired);
40667+ atomic_inc_unchecked(&dev_priv->last_fence_retired);
40668 wake_up(&dev_priv->fence_queue);
40669 handled = 1;
40670 }
40671@@ -129,7 +129,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
40672 * using fences.
40673 */
40674 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * HZ,
40675- (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
40676+ (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
40677 - *sequence) <= (1 << 23)));
40678
40679 *sequence = cur_fence;
40680diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
40681index dae2c96..324dbe4 100644
40682--- a/drivers/gpu/drm/nouveau/nouveau_bios.c
40683+++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
40684@@ -963,7 +963,7 @@ static int parse_bit_tmds_tbl_entry(struct drm_device *dev, struct nvbios *bios,
40685 struct bit_table {
40686 const char id;
40687 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
40688-};
40689+} __no_const;
40690
40691 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
40692
40693diff --git a/drivers/gpu/drm/nouveau/nouveau_drm.h b/drivers/gpu/drm/nouveau/nouveau_drm.h
40694index 8ae36f2..1147a30 100644
40695--- a/drivers/gpu/drm/nouveau/nouveau_drm.h
40696+++ b/drivers/gpu/drm/nouveau/nouveau_drm.h
40697@@ -121,7 +121,6 @@ struct nouveau_drm {
40698 struct drm_global_reference mem_global_ref;
40699 struct ttm_bo_global_ref bo_global_ref;
40700 struct ttm_bo_device bdev;
40701- atomic_t validate_sequence;
40702 int (*move)(struct nouveau_channel *,
40703 struct ttm_buffer_object *,
40704 struct ttm_mem_reg *, struct ttm_mem_reg *);
40705diff --git a/drivers/gpu/drm/nouveau/nouveau_ioc32.c b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
40706index 462679a..88e32a7 100644
40707--- a/drivers/gpu/drm/nouveau/nouveau_ioc32.c
40708+++ b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
40709@@ -50,7 +50,7 @@ long nouveau_compat_ioctl(struct file *filp, unsigned int cmd,
40710 unsigned long arg)
40711 {
40712 unsigned int nr = DRM_IOCTL_NR(cmd);
40713- drm_ioctl_compat_t *fn = NULL;
40714+ drm_ioctl_compat_t fn = NULL;
40715 int ret;
40716
40717 if (nr < DRM_COMMAND_BASE)
40718diff --git a/drivers/gpu/drm/nouveau/nouveau_ttm.c b/drivers/gpu/drm/nouveau/nouveau_ttm.c
40719index 753a6de..dd66b98 100644
40720--- a/drivers/gpu/drm/nouveau/nouveau_ttm.c
40721+++ b/drivers/gpu/drm/nouveau/nouveau_ttm.c
40722@@ -126,11 +126,11 @@ nouveau_vram_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
40723 }
40724
40725 const struct ttm_mem_type_manager_func nouveau_vram_manager = {
40726- nouveau_vram_manager_init,
40727- nouveau_vram_manager_fini,
40728- nouveau_vram_manager_new,
40729- nouveau_vram_manager_del,
40730- nouveau_vram_manager_debug
40731+ .init = nouveau_vram_manager_init,
40732+ .takedown = nouveau_vram_manager_fini,
40733+ .get_node = nouveau_vram_manager_new,
40734+ .put_node = nouveau_vram_manager_del,
40735+ .debug = nouveau_vram_manager_debug
40736 };
40737
40738 static int
40739@@ -194,11 +194,11 @@ nouveau_gart_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
40740 }
40741
40742 const struct ttm_mem_type_manager_func nouveau_gart_manager = {
40743- nouveau_gart_manager_init,
40744- nouveau_gart_manager_fini,
40745- nouveau_gart_manager_new,
40746- nouveau_gart_manager_del,
40747- nouveau_gart_manager_debug
40748+ .init = nouveau_gart_manager_init,
40749+ .takedown = nouveau_gart_manager_fini,
40750+ .get_node = nouveau_gart_manager_new,
40751+ .put_node = nouveau_gart_manager_del,
40752+ .debug = nouveau_gart_manager_debug
40753 };
40754
40755 /*XXX*/
40756@@ -267,11 +267,11 @@ nv04_gart_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
40757 }
40758
40759 const struct ttm_mem_type_manager_func nv04_gart_manager = {
40760- nv04_gart_manager_init,
40761- nv04_gart_manager_fini,
40762- nv04_gart_manager_new,
40763- nv04_gart_manager_del,
40764- nv04_gart_manager_debug
40765+ .init = nv04_gart_manager_init,
40766+ .takedown = nv04_gart_manager_fini,
40767+ .get_node = nv04_gart_manager_new,
40768+ .put_node = nv04_gart_manager_del,
40769+ .debug = nv04_gart_manager_debug
40770 };
40771
40772 int
40773diff --git a/drivers/gpu/drm/nouveau/nouveau_vga.c b/drivers/gpu/drm/nouveau/nouveau_vga.c
40774index c7592ec..dd45ebc 100644
40775--- a/drivers/gpu/drm/nouveau/nouveau_vga.c
40776+++ b/drivers/gpu/drm/nouveau/nouveau_vga.c
40777@@ -72,7 +72,7 @@ nouveau_switcheroo_can_switch(struct pci_dev *pdev)
40778 * locking inversion with the driver load path. And the access here is
40779 * completely racy anyway. So don't bother with locking for now.
40780 */
40781- return dev->open_count == 0;
40782+ return local_read(&dev->open_count) == 0;
40783 }
40784
40785 static const struct vga_switcheroo_client_ops
40786diff --git a/drivers/gpu/drm/qxl/qxl_cmd.c b/drivers/gpu/drm/qxl/qxl_cmd.c
40787index 9782364..89bd954 100644
40788--- a/drivers/gpu/drm/qxl/qxl_cmd.c
40789+++ b/drivers/gpu/drm/qxl/qxl_cmd.c
40790@@ -285,27 +285,27 @@ static int wait_for_io_cmd_user(struct qxl_device *qdev, uint8_t val, long port,
40791 int ret;
40792
40793 mutex_lock(&qdev->async_io_mutex);
40794- irq_num = atomic_read(&qdev->irq_received_io_cmd);
40795+ irq_num = atomic_read_unchecked(&qdev->irq_received_io_cmd);
40796 if (qdev->last_sent_io_cmd > irq_num) {
40797 if (intr)
40798 ret = wait_event_interruptible_timeout(qdev->io_cmd_event,
40799- atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40800+ atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40801 else
40802 ret = wait_event_timeout(qdev->io_cmd_event,
40803- atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40804+ atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40805 /* 0 is timeout, just bail the "hw" has gone away */
40806 if (ret <= 0)
40807 goto out;
40808- irq_num = atomic_read(&qdev->irq_received_io_cmd);
40809+ irq_num = atomic_read_unchecked(&qdev->irq_received_io_cmd);
40810 }
40811 outb(val, addr);
40812 qdev->last_sent_io_cmd = irq_num + 1;
40813 if (intr)
40814 ret = wait_event_interruptible_timeout(qdev->io_cmd_event,
40815- atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40816+ atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40817 else
40818 ret = wait_event_timeout(qdev->io_cmd_event,
40819- atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40820+ atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40821 out:
40822 if (ret > 0)
40823 ret = 0;
40824diff --git a/drivers/gpu/drm/qxl/qxl_debugfs.c b/drivers/gpu/drm/qxl/qxl_debugfs.c
40825index 6911b8c..89d6867 100644
40826--- a/drivers/gpu/drm/qxl/qxl_debugfs.c
40827+++ b/drivers/gpu/drm/qxl/qxl_debugfs.c
40828@@ -42,10 +42,10 @@ qxl_debugfs_irq_received(struct seq_file *m, void *data)
40829 struct drm_info_node *node = (struct drm_info_node *) m->private;
40830 struct qxl_device *qdev = node->minor->dev->dev_private;
40831
40832- seq_printf(m, "%d\n", atomic_read(&qdev->irq_received));
40833- seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_display));
40834- seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_cursor));
40835- seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_io_cmd));
40836+ seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received));
40837+ seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_display));
40838+ seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_cursor));
40839+ seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_io_cmd));
40840 seq_printf(m, "%d\n", qdev->irq_received_error);
40841 return 0;
40842 }
40843diff --git a/drivers/gpu/drm/qxl/qxl_drv.h b/drivers/gpu/drm/qxl/qxl_drv.h
40844index 7c6cafe..460f542 100644
40845--- a/drivers/gpu/drm/qxl/qxl_drv.h
40846+++ b/drivers/gpu/drm/qxl/qxl_drv.h
40847@@ -290,10 +290,10 @@ struct qxl_device {
40848 unsigned int last_sent_io_cmd;
40849
40850 /* interrupt handling */
40851- atomic_t irq_received;
40852- atomic_t irq_received_display;
40853- atomic_t irq_received_cursor;
40854- atomic_t irq_received_io_cmd;
40855+ atomic_unchecked_t irq_received;
40856+ atomic_unchecked_t irq_received_display;
40857+ atomic_unchecked_t irq_received_cursor;
40858+ atomic_unchecked_t irq_received_io_cmd;
40859 unsigned irq_received_error;
40860 wait_queue_head_t display_event;
40861 wait_queue_head_t cursor_event;
40862diff --git a/drivers/gpu/drm/qxl/qxl_ioctl.c b/drivers/gpu/drm/qxl/qxl_ioctl.c
40863index b110883..dd06418 100644
40864--- a/drivers/gpu/drm/qxl/qxl_ioctl.c
40865+++ b/drivers/gpu/drm/qxl/qxl_ioctl.c
40866@@ -181,7 +181,7 @@ static int qxl_process_single_command(struct qxl_device *qdev,
40867
40868 /* TODO copy slow path code from i915 */
40869 fb_cmd = qxl_bo_kmap_atomic_page(qdev, cmd_bo, (release->release_offset & PAGE_SIZE));
40870- 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);
40871+ 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);
40872
40873 {
40874 struct qxl_drawable *draw = fb_cmd;
40875@@ -201,7 +201,7 @@ static int qxl_process_single_command(struct qxl_device *qdev,
40876 struct drm_qxl_reloc reloc;
40877
40878 if (copy_from_user(&reloc,
40879- &((struct drm_qxl_reloc *)(uintptr_t)cmd->relocs)[i],
40880+ &((struct drm_qxl_reloc __force_user *)(uintptr_t)cmd->relocs)[i],
40881 sizeof(reloc))) {
40882 ret = -EFAULT;
40883 goto out_free_bos;
40884@@ -294,10 +294,10 @@ static int qxl_execbuffer_ioctl(struct drm_device *dev, void *data,
40885
40886 for (cmd_num = 0; cmd_num < execbuffer->commands_num; ++cmd_num) {
40887
40888- struct drm_qxl_command *commands =
40889- (struct drm_qxl_command *)(uintptr_t)execbuffer->commands;
40890+ struct drm_qxl_command __user *commands =
40891+ (struct drm_qxl_command __user *)(uintptr_t)execbuffer->commands;
40892
40893- if (copy_from_user(&user_cmd, &commands[cmd_num],
40894+ if (copy_from_user(&user_cmd, (struct drm_qxl_command __force_user *)&commands[cmd_num],
40895 sizeof(user_cmd)))
40896 return -EFAULT;
40897
40898diff --git a/drivers/gpu/drm/qxl/qxl_irq.c b/drivers/gpu/drm/qxl/qxl_irq.c
40899index 0bf1e20..42a7310 100644
40900--- a/drivers/gpu/drm/qxl/qxl_irq.c
40901+++ b/drivers/gpu/drm/qxl/qxl_irq.c
40902@@ -36,19 +36,19 @@ irqreturn_t qxl_irq_handler(int irq, void *arg)
40903 if (!pending)
40904 return IRQ_NONE;
40905
40906- atomic_inc(&qdev->irq_received);
40907+ atomic_inc_unchecked(&qdev->irq_received);
40908
40909 if (pending & QXL_INTERRUPT_DISPLAY) {
40910- atomic_inc(&qdev->irq_received_display);
40911+ atomic_inc_unchecked(&qdev->irq_received_display);
40912 wake_up_all(&qdev->display_event);
40913 qxl_queue_garbage_collect(qdev, false);
40914 }
40915 if (pending & QXL_INTERRUPT_CURSOR) {
40916- atomic_inc(&qdev->irq_received_cursor);
40917+ atomic_inc_unchecked(&qdev->irq_received_cursor);
40918 wake_up_all(&qdev->cursor_event);
40919 }
40920 if (pending & QXL_INTERRUPT_IO_CMD) {
40921- atomic_inc(&qdev->irq_received_io_cmd);
40922+ atomic_inc_unchecked(&qdev->irq_received_io_cmd);
40923 wake_up_all(&qdev->io_cmd_event);
40924 }
40925 if (pending & QXL_INTERRUPT_ERROR) {
40926@@ -85,10 +85,10 @@ int qxl_irq_init(struct qxl_device *qdev)
40927 init_waitqueue_head(&qdev->io_cmd_event);
40928 INIT_WORK(&qdev->client_monitors_config_work,
40929 qxl_client_monitors_config_work_func);
40930- atomic_set(&qdev->irq_received, 0);
40931- atomic_set(&qdev->irq_received_display, 0);
40932- atomic_set(&qdev->irq_received_cursor, 0);
40933- atomic_set(&qdev->irq_received_io_cmd, 0);
40934+ atomic_set_unchecked(&qdev->irq_received, 0);
40935+ atomic_set_unchecked(&qdev->irq_received_display, 0);
40936+ atomic_set_unchecked(&qdev->irq_received_cursor, 0);
40937+ atomic_set_unchecked(&qdev->irq_received_io_cmd, 0);
40938 qdev->irq_received_error = 0;
40939 ret = drm_irq_install(qdev->ddev, qdev->ddev->pdev->irq);
40940 qdev->ram_header->int_mask = QXL_INTERRUPT_MASK;
40941diff --git a/drivers/gpu/drm/qxl/qxl_ttm.c b/drivers/gpu/drm/qxl/qxl_ttm.c
40942index 0cbc4c9..0e46686 100644
40943--- a/drivers/gpu/drm/qxl/qxl_ttm.c
40944+++ b/drivers/gpu/drm/qxl/qxl_ttm.c
40945@@ -103,7 +103,7 @@ static void qxl_ttm_global_fini(struct qxl_device *qdev)
40946 }
40947 }
40948
40949-static struct vm_operations_struct qxl_ttm_vm_ops;
40950+static vm_operations_struct_no_const qxl_ttm_vm_ops __read_only;
40951 static const struct vm_operations_struct *ttm_vm_ops;
40952
40953 static int qxl_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
40954@@ -145,8 +145,10 @@ int qxl_mmap(struct file *filp, struct vm_area_struct *vma)
40955 return r;
40956 if (unlikely(ttm_vm_ops == NULL)) {
40957 ttm_vm_ops = vma->vm_ops;
40958+ pax_open_kernel();
40959 qxl_ttm_vm_ops = *ttm_vm_ops;
40960 qxl_ttm_vm_ops.fault = &qxl_ttm_fault;
40961+ pax_close_kernel();
40962 }
40963 vma->vm_ops = &qxl_ttm_vm_ops;
40964 return 0;
40965@@ -464,25 +466,23 @@ static int qxl_mm_dump_table(struct seq_file *m, void *data)
40966 static int qxl_ttm_debugfs_init(struct qxl_device *qdev)
40967 {
40968 #if defined(CONFIG_DEBUG_FS)
40969- static struct drm_info_list qxl_mem_types_list[QXL_DEBUGFS_MEM_TYPES];
40970- static char qxl_mem_types_names[QXL_DEBUGFS_MEM_TYPES][32];
40971- unsigned i;
40972+ static struct drm_info_list qxl_mem_types_list[QXL_DEBUGFS_MEM_TYPES] = {
40973+ {
40974+ .name = "qxl_mem_mm",
40975+ .show = &qxl_mm_dump_table,
40976+ },
40977+ {
40978+ .name = "qxl_surf_mm",
40979+ .show = &qxl_mm_dump_table,
40980+ }
40981+ };
40982
40983- for (i = 0; i < QXL_DEBUGFS_MEM_TYPES; i++) {
40984- if (i == 0)
40985- sprintf(qxl_mem_types_names[i], "qxl_mem_mm");
40986- else
40987- sprintf(qxl_mem_types_names[i], "qxl_surf_mm");
40988- qxl_mem_types_list[i].name = qxl_mem_types_names[i];
40989- qxl_mem_types_list[i].show = &qxl_mm_dump_table;
40990- qxl_mem_types_list[i].driver_features = 0;
40991- if (i == 0)
40992- qxl_mem_types_list[i].data = qdev->mman.bdev.man[TTM_PL_VRAM].priv;
40993- else
40994- qxl_mem_types_list[i].data = qdev->mman.bdev.man[TTM_PL_PRIV0].priv;
40995+ pax_open_kernel();
40996+ *(void **)&qxl_mem_types_list[0].data = qdev->mman.bdev.man[TTM_PL_VRAM].priv;
40997+ *(void **)&qxl_mem_types_list[1].data = qdev->mman.bdev.man[TTM_PL_PRIV0].priv;
40998+ pax_close_kernel();
40999
41000- }
41001- return qxl_debugfs_add_files(qdev, qxl_mem_types_list, i);
41002+ return qxl_debugfs_add_files(qdev, qxl_mem_types_list, QXL_DEBUGFS_MEM_TYPES);
41003 #else
41004 return 0;
41005 #endif
41006diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
41007index 2c45ac9..5d740f8 100644
41008--- a/drivers/gpu/drm/r128/r128_cce.c
41009+++ b/drivers/gpu/drm/r128/r128_cce.c
41010@@ -377,7 +377,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
41011
41012 /* GH: Simple idle check.
41013 */
41014- atomic_set(&dev_priv->idle_count, 0);
41015+ atomic_set_unchecked(&dev_priv->idle_count, 0);
41016
41017 /* We don't support anything other than bus-mastering ring mode,
41018 * but the ring can be in either AGP or PCI space for the ring
41019diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
41020index 723e5d6..102dbaf 100644
41021--- a/drivers/gpu/drm/r128/r128_drv.h
41022+++ b/drivers/gpu/drm/r128/r128_drv.h
41023@@ -93,14 +93,14 @@ typedef struct drm_r128_private {
41024 int is_pci;
41025 unsigned long cce_buffers_offset;
41026
41027- atomic_t idle_count;
41028+ atomic_unchecked_t idle_count;
41029
41030 int page_flipping;
41031 int current_page;
41032 u32 crtc_offset;
41033 u32 crtc_offset_cntl;
41034
41035- atomic_t vbl_received;
41036+ atomic_unchecked_t vbl_received;
41037
41038 u32 color_fmt;
41039 unsigned int front_offset;
41040diff --git a/drivers/gpu/drm/r128/r128_ioc32.c b/drivers/gpu/drm/r128/r128_ioc32.c
41041index 663f38c..c689495 100644
41042--- a/drivers/gpu/drm/r128/r128_ioc32.c
41043+++ b/drivers/gpu/drm/r128/r128_ioc32.c
41044@@ -178,7 +178,7 @@ static int compat_r128_getparam(struct file *file, unsigned int cmd,
41045 return drm_ioctl(file, DRM_IOCTL_R128_GETPARAM, (unsigned long)getparam);
41046 }
41047
41048-drm_ioctl_compat_t *r128_compat_ioctls[] = {
41049+drm_ioctl_compat_t r128_compat_ioctls[] = {
41050 [DRM_R128_INIT] = compat_r128_init,
41051 [DRM_R128_DEPTH] = compat_r128_depth,
41052 [DRM_R128_STIPPLE] = compat_r128_stipple,
41053@@ -197,18 +197,15 @@ drm_ioctl_compat_t *r128_compat_ioctls[] = {
41054 long r128_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
41055 {
41056 unsigned int nr = DRM_IOCTL_NR(cmd);
41057- drm_ioctl_compat_t *fn = NULL;
41058 int ret;
41059
41060 if (nr < DRM_COMMAND_BASE)
41061 return drm_compat_ioctl(filp, cmd, arg);
41062
41063- if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(r128_compat_ioctls))
41064- fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
41065-
41066- if (fn != NULL)
41067+ if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(r128_compat_ioctls)) {
41068+ drm_ioctl_compat_t fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
41069 ret = (*fn) (filp, cmd, arg);
41070- else
41071+ } else
41072 ret = drm_ioctl(filp, cmd, arg);
41073
41074 return ret;
41075diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
41076index c2ae496..30b5993 100644
41077--- a/drivers/gpu/drm/r128/r128_irq.c
41078+++ b/drivers/gpu/drm/r128/r128_irq.c
41079@@ -41,7 +41,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
41080 if (crtc != 0)
41081 return 0;
41082
41083- return atomic_read(&dev_priv->vbl_received);
41084+ return atomic_read_unchecked(&dev_priv->vbl_received);
41085 }
41086
41087 irqreturn_t r128_driver_irq_handler(int irq, void *arg)
41088@@ -55,7 +55,7 @@ irqreturn_t r128_driver_irq_handler(int irq, void *arg)
41089 /* VBLANK interrupt */
41090 if (status & R128_CRTC_VBLANK_INT) {
41091 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
41092- atomic_inc(&dev_priv->vbl_received);
41093+ atomic_inc_unchecked(&dev_priv->vbl_received);
41094 drm_handle_vblank(dev, 0);
41095 return IRQ_HANDLED;
41096 }
41097diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
41098index 575e986..66e62ca 100644
41099--- a/drivers/gpu/drm/r128/r128_state.c
41100+++ b/drivers/gpu/drm/r128/r128_state.c
41101@@ -320,10 +320,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
41102
41103 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
41104 {
41105- if (atomic_read(&dev_priv->idle_count) == 0)
41106+ if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
41107 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
41108 else
41109- atomic_set(&dev_priv->idle_count, 0);
41110+ atomic_set_unchecked(&dev_priv->idle_count, 0);
41111 }
41112
41113 #endif
41114diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
41115index 4a85bb6..aaea819 100644
41116--- a/drivers/gpu/drm/radeon/mkregtable.c
41117+++ b/drivers/gpu/drm/radeon/mkregtable.c
41118@@ -624,14 +624,14 @@ static int parser_auth(struct table *t, const char *filename)
41119 regex_t mask_rex;
41120 regmatch_t match[4];
41121 char buf[1024];
41122- size_t end;
41123+ long end;
41124 int len;
41125 int done = 0;
41126 int r;
41127 unsigned o;
41128 struct offset *offset;
41129 char last_reg_s[10];
41130- int last_reg;
41131+ unsigned long last_reg;
41132
41133 if (regcomp
41134 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
41135diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
41136index 995a8b1..b7cb898 100644
41137--- a/drivers/gpu/drm/radeon/radeon_device.c
41138+++ b/drivers/gpu/drm/radeon/radeon_device.c
41139@@ -1214,7 +1214,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
41140 * locking inversion with the driver load path. And the access here is
41141 * completely racy anyway. So don't bother with locking for now.
41142 */
41143- return dev->open_count == 0;
41144+ return local_read(&dev->open_count) == 0;
41145 }
41146
41147 static const struct vga_switcheroo_client_ops radeon_switcheroo_ops = {
41148diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
41149index 46bd393..6ae4719 100644
41150--- a/drivers/gpu/drm/radeon/radeon_drv.h
41151+++ b/drivers/gpu/drm/radeon/radeon_drv.h
41152@@ -264,7 +264,7 @@ typedef struct drm_radeon_private {
41153
41154 /* SW interrupt */
41155 wait_queue_head_t swi_queue;
41156- atomic_t swi_emitted;
41157+ atomic_unchecked_t swi_emitted;
41158 int vblank_crtc;
41159 uint32_t irq_enable_reg;
41160 uint32_t r500_disp_irq_reg;
41161diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
41162index 0b98ea1..0881827 100644
41163--- a/drivers/gpu/drm/radeon/radeon_ioc32.c
41164+++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
41165@@ -358,7 +358,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
41166 request = compat_alloc_user_space(sizeof(*request));
41167 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
41168 || __put_user(req32.param, &request->param)
41169- || __put_user((void __user *)(unsigned long)req32.value,
41170+ || __put_user((unsigned long)req32.value,
41171 &request->value))
41172 return -EFAULT;
41173
41174@@ -368,7 +368,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
41175 #define compat_radeon_cp_setparam NULL
41176 #endif /* X86_64 || IA64 */
41177
41178-static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
41179+static drm_ioctl_compat_t radeon_compat_ioctls[] = {
41180 [DRM_RADEON_CP_INIT] = compat_radeon_cp_init,
41181 [DRM_RADEON_CLEAR] = compat_radeon_cp_clear,
41182 [DRM_RADEON_STIPPLE] = compat_radeon_cp_stipple,
41183@@ -393,18 +393,15 @@ static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
41184 long radeon_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
41185 {
41186 unsigned int nr = DRM_IOCTL_NR(cmd);
41187- drm_ioctl_compat_t *fn = NULL;
41188 int ret;
41189
41190 if (nr < DRM_COMMAND_BASE)
41191 return drm_compat_ioctl(filp, cmd, arg);
41192
41193- if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(radeon_compat_ioctls))
41194- fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
41195-
41196- if (fn != NULL)
41197+ if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(radeon_compat_ioctls)) {
41198+ drm_ioctl_compat_t fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
41199 ret = (*fn) (filp, cmd, arg);
41200- else
41201+ } else
41202 ret = drm_ioctl(filp, cmd, arg);
41203
41204 return ret;
41205diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
41206index 244b19b..c19226d 100644
41207--- a/drivers/gpu/drm/radeon/radeon_irq.c
41208+++ b/drivers/gpu/drm/radeon/radeon_irq.c
41209@@ -226,8 +226,8 @@ static int radeon_emit_irq(struct drm_device * dev)
41210 unsigned int ret;
41211 RING_LOCALS;
41212
41213- atomic_inc(&dev_priv->swi_emitted);
41214- ret = atomic_read(&dev_priv->swi_emitted);
41215+ atomic_inc_unchecked(&dev_priv->swi_emitted);
41216+ ret = atomic_read_unchecked(&dev_priv->swi_emitted);
41217
41218 BEGIN_RING(4);
41219 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
41220@@ -353,7 +353,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
41221 drm_radeon_private_t *dev_priv =
41222 (drm_radeon_private_t *) dev->dev_private;
41223
41224- atomic_set(&dev_priv->swi_emitted, 0);
41225+ atomic_set_unchecked(&dev_priv->swi_emitted, 0);
41226 init_waitqueue_head(&dev_priv->swi_queue);
41227
41228 dev->max_vblank_count = 0x001fffff;
41229diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
41230index 535403e..5dd655b 100644
41231--- a/drivers/gpu/drm/radeon/radeon_state.c
41232+++ b/drivers/gpu/drm/radeon/radeon_state.c
41233@@ -2168,7 +2168,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
41234 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
41235 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
41236
41237- if (copy_from_user(&depth_boxes, clear->depth_boxes,
41238+ if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || copy_from_user(&depth_boxes, clear->depth_boxes,
41239 sarea_priv->nbox * sizeof(depth_boxes[0])))
41240 return -EFAULT;
41241
41242@@ -3031,7 +3031,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
41243 {
41244 drm_radeon_private_t *dev_priv = dev->dev_private;
41245 drm_radeon_getparam_t *param = data;
41246- int value;
41247+ int value = 0;
41248
41249 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
41250
41251diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
41252index 8624979..65e5243 100644
41253--- a/drivers/gpu/drm/radeon/radeon_ttm.c
41254+++ b/drivers/gpu/drm/radeon/radeon_ttm.c
41255@@ -936,7 +936,7 @@ void radeon_ttm_set_active_vram_size(struct radeon_device *rdev, u64 size)
41256 man->size = size >> PAGE_SHIFT;
41257 }
41258
41259-static struct vm_operations_struct radeon_ttm_vm_ops;
41260+static vm_operations_struct_no_const radeon_ttm_vm_ops __read_only;
41261 static const struct vm_operations_struct *ttm_vm_ops = NULL;
41262
41263 static int radeon_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
41264@@ -977,8 +977,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
41265 }
41266 if (unlikely(ttm_vm_ops == NULL)) {
41267 ttm_vm_ops = vma->vm_ops;
41268+ pax_open_kernel();
41269 radeon_ttm_vm_ops = *ttm_vm_ops;
41270 radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
41271+ pax_close_kernel();
41272 }
41273 vma->vm_ops = &radeon_ttm_vm_ops;
41274 return 0;
41275diff --git a/drivers/gpu/drm/tegra/dc.c b/drivers/gpu/drm/tegra/dc.c
41276index 054a79f..30d9ac4 100644
41277--- a/drivers/gpu/drm/tegra/dc.c
41278+++ b/drivers/gpu/drm/tegra/dc.c
41279@@ -1242,7 +1242,7 @@ static int tegra_dc_debugfs_init(struct tegra_dc *dc, struct drm_minor *minor)
41280 }
41281
41282 for (i = 0; i < ARRAY_SIZE(debugfs_files); i++)
41283- dc->debugfs_files[i].data = dc;
41284+ *(void **)&dc->debugfs_files[i].data = dc;
41285
41286 err = drm_debugfs_create_files(dc->debugfs_files,
41287 ARRAY_SIZE(debugfs_files),
41288diff --git a/drivers/gpu/drm/tegra/dsi.c b/drivers/gpu/drm/tegra/dsi.c
41289index f787445..2df2c65 100644
41290--- a/drivers/gpu/drm/tegra/dsi.c
41291+++ b/drivers/gpu/drm/tegra/dsi.c
41292@@ -41,7 +41,7 @@ struct tegra_dsi {
41293 struct clk *clk_lp;
41294 struct clk *clk;
41295
41296- struct drm_info_list *debugfs_files;
41297+ drm_info_list_no_const *debugfs_files;
41298 struct drm_minor *minor;
41299 struct dentry *debugfs;
41300
41301diff --git a/drivers/gpu/drm/tegra/hdmi.c b/drivers/gpu/drm/tegra/hdmi.c
41302index ffe2654..03c7b1c 100644
41303--- a/drivers/gpu/drm/tegra/hdmi.c
41304+++ b/drivers/gpu/drm/tegra/hdmi.c
41305@@ -60,7 +60,7 @@ struct tegra_hdmi {
41306 bool stereo;
41307 bool dvi;
41308
41309- struct drm_info_list *debugfs_files;
41310+ drm_info_list_no_const *debugfs_files;
41311 struct drm_minor *minor;
41312 struct dentry *debugfs;
41313 };
41314diff --git a/drivers/gpu/drm/ttm/ttm_bo_manager.c b/drivers/gpu/drm/ttm/ttm_bo_manager.c
41315index 964387f..4eafc00 100644
41316--- a/drivers/gpu/drm/ttm/ttm_bo_manager.c
41317+++ b/drivers/gpu/drm/ttm/ttm_bo_manager.c
41318@@ -146,10 +146,10 @@ static void ttm_bo_man_debug(struct ttm_mem_type_manager *man,
41319 }
41320
41321 const struct ttm_mem_type_manager_func ttm_bo_manager_func = {
41322- ttm_bo_man_init,
41323- ttm_bo_man_takedown,
41324- ttm_bo_man_get_node,
41325- ttm_bo_man_put_node,
41326- ttm_bo_man_debug
41327+ .init = ttm_bo_man_init,
41328+ .takedown = ttm_bo_man_takedown,
41329+ .get_node = ttm_bo_man_get_node,
41330+ .put_node = ttm_bo_man_put_node,
41331+ .debug = ttm_bo_man_debug
41332 };
41333 EXPORT_SYMBOL(ttm_bo_manager_func);
41334diff --git a/drivers/gpu/drm/ttm/ttm_memory.c b/drivers/gpu/drm/ttm/ttm_memory.c
41335index a1803fb..c53f6b0 100644
41336--- a/drivers/gpu/drm/ttm/ttm_memory.c
41337+++ b/drivers/gpu/drm/ttm/ttm_memory.c
41338@@ -264,7 +264,7 @@ static int ttm_mem_init_kernel_zone(struct ttm_mem_global *glob,
41339 zone->glob = glob;
41340 glob->zone_kernel = zone;
41341 ret = kobject_init_and_add(
41342- &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, zone->name);
41343+ &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, "%s", zone->name);
41344 if (unlikely(ret != 0)) {
41345 kobject_put(&zone->kobj);
41346 return ret;
41347@@ -348,7 +348,7 @@ static int ttm_mem_init_dma32_zone(struct ttm_mem_global *glob,
41348 zone->glob = glob;
41349 glob->zone_dma32 = zone;
41350 ret = kobject_init_and_add(
41351- &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, zone->name);
41352+ &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, "%s", zone->name);
41353 if (unlikely(ret != 0)) {
41354 kobject_put(&zone->kobj);
41355 return ret;
41356diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
41357index 09874d6..d6da1de 100644
41358--- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
41359+++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
41360@@ -54,7 +54,7 @@
41361
41362 #define NUM_PAGES_TO_ALLOC (PAGE_SIZE/sizeof(struct page *))
41363 #define SMALL_ALLOCATION 16
41364-#define FREE_ALL_PAGES (~0U)
41365+#define FREE_ALL_PAGES (~0UL)
41366 /* times are in msecs */
41367 #define PAGE_FREE_INTERVAL 1000
41368
41369@@ -299,14 +299,13 @@ static void ttm_pool_update_free_locked(struct ttm_page_pool *pool,
41370 * @free_all: If set to true will free all pages in pool
41371 * @gfp: GFP flags.
41372 **/
41373-static int ttm_page_pool_free(struct ttm_page_pool *pool, unsigned nr_free,
41374+static unsigned long ttm_page_pool_free(struct ttm_page_pool *pool, unsigned long nr_free,
41375 gfp_t gfp)
41376 {
41377 unsigned long irq_flags;
41378 struct page *p;
41379 struct page **pages_to_free;
41380- unsigned freed_pages = 0,
41381- npages_to_free = nr_free;
41382+ unsigned long freed_pages = 0, npages_to_free = nr_free;
41383
41384 if (NUM_PAGES_TO_ALLOC < nr_free)
41385 npages_to_free = NUM_PAGES_TO_ALLOC;
41386@@ -366,7 +365,8 @@ restart:
41387 __list_del(&p->lru, &pool->list);
41388
41389 ttm_pool_update_free_locked(pool, freed_pages);
41390- nr_free -= freed_pages;
41391+ if (likely(nr_free != FREE_ALL_PAGES))
41392+ nr_free -= freed_pages;
41393 }
41394
41395 spin_unlock_irqrestore(&pool->lock, irq_flags);
41396@@ -395,7 +395,7 @@ ttm_pool_shrink_scan(struct shrinker *shrink, struct shrink_control *sc)
41397 unsigned i;
41398 unsigned pool_offset;
41399 struct ttm_page_pool *pool;
41400- int shrink_pages = sc->nr_to_scan;
41401+ unsigned long shrink_pages = sc->nr_to_scan;
41402 unsigned long freed = 0;
41403
41404 if (!mutex_trylock(&lock))
41405@@ -403,7 +403,7 @@ ttm_pool_shrink_scan(struct shrinker *shrink, struct shrink_control *sc)
41406 pool_offset = ++start_pool % NUM_POOLS;
41407 /* select start pool in round robin fashion */
41408 for (i = 0; i < NUM_POOLS; ++i) {
41409- unsigned nr_free = shrink_pages;
41410+ unsigned long nr_free = shrink_pages;
41411 if (shrink_pages == 0)
41412 break;
41413 pool = &_manager->pools[(i + pool_offset)%NUM_POOLS];
41414@@ -669,7 +669,7 @@ out:
41415 }
41416
41417 /* Put all pages in pages list to correct pool to wait for reuse */
41418-static void ttm_put_pages(struct page **pages, unsigned npages, int flags,
41419+static void ttm_put_pages(struct page **pages, unsigned long npages, int flags,
41420 enum ttm_caching_state cstate)
41421 {
41422 unsigned long irq_flags;
41423@@ -724,7 +724,7 @@ static int ttm_get_pages(struct page **pages, unsigned npages, int flags,
41424 struct list_head plist;
41425 struct page *p = NULL;
41426 gfp_t gfp_flags = GFP_USER;
41427- unsigned count;
41428+ unsigned long count;
41429 int r;
41430
41431 /* set zero flag for page allocation if required */
41432diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc_dma.c b/drivers/gpu/drm/ttm/ttm_page_alloc_dma.c
41433index c96db43..c367557 100644
41434--- a/drivers/gpu/drm/ttm/ttm_page_alloc_dma.c
41435+++ b/drivers/gpu/drm/ttm/ttm_page_alloc_dma.c
41436@@ -56,7 +56,7 @@
41437
41438 #define NUM_PAGES_TO_ALLOC (PAGE_SIZE/sizeof(struct page *))
41439 #define SMALL_ALLOCATION 4
41440-#define FREE_ALL_PAGES (~0U)
41441+#define FREE_ALL_PAGES (~0UL)
41442 /* times are in msecs */
41443 #define IS_UNDEFINED (0)
41444 #define IS_WC (1<<1)
41445@@ -413,15 +413,14 @@ static void ttm_dma_page_put(struct dma_pool *pool, struct dma_page *d_page)
41446 * @nr_free: If set to true will free all pages in pool
41447 * @gfp: GFP flags.
41448 **/
41449-static unsigned ttm_dma_page_pool_free(struct dma_pool *pool, unsigned nr_free,
41450+static unsigned long ttm_dma_page_pool_free(struct dma_pool *pool, unsigned long nr_free,
41451 gfp_t gfp)
41452 {
41453 unsigned long irq_flags;
41454 struct dma_page *dma_p, *tmp;
41455 struct page **pages_to_free;
41456 struct list_head d_pages;
41457- unsigned freed_pages = 0,
41458- npages_to_free = nr_free;
41459+ unsigned long freed_pages = 0, npages_to_free = nr_free;
41460
41461 if (NUM_PAGES_TO_ALLOC < nr_free)
41462 npages_to_free = NUM_PAGES_TO_ALLOC;
41463@@ -494,7 +493,8 @@ restart:
41464 /* remove range of pages from the pool */
41465 if (freed_pages) {
41466 ttm_pool_update_free_locked(pool, freed_pages);
41467- nr_free -= freed_pages;
41468+ if (likely(nr_free != FREE_ALL_PAGES))
41469+ nr_free -= freed_pages;
41470 }
41471
41472 spin_unlock_irqrestore(&pool->lock, irq_flags);
41473@@ -929,7 +929,7 @@ void ttm_dma_unpopulate(struct ttm_dma_tt *ttm_dma, struct device *dev)
41474 struct dma_page *d_page, *next;
41475 enum pool_type type;
41476 bool is_cached = false;
41477- unsigned count = 0, i, npages = 0;
41478+ unsigned long count = 0, i, npages = 0;
41479 unsigned long irq_flags;
41480
41481 type = ttm_to_type(ttm->page_flags, ttm->caching_state);
41482@@ -1007,7 +1007,7 @@ ttm_dma_pool_shrink_scan(struct shrinker *shrink, struct shrink_control *sc)
41483 static unsigned start_pool;
41484 unsigned idx = 0;
41485 unsigned pool_offset;
41486- unsigned shrink_pages = sc->nr_to_scan;
41487+ unsigned long shrink_pages = sc->nr_to_scan;
41488 struct device_pools *p;
41489 unsigned long freed = 0;
41490
41491@@ -1020,7 +1020,7 @@ ttm_dma_pool_shrink_scan(struct shrinker *shrink, struct shrink_control *sc)
41492 goto out;
41493 pool_offset = ++start_pool % _manager->npools;
41494 list_for_each_entry(p, &_manager->pools, pools) {
41495- unsigned nr_free;
41496+ unsigned long nr_free;
41497
41498 if (!p->dev)
41499 continue;
41500@@ -1034,7 +1034,7 @@ ttm_dma_pool_shrink_scan(struct shrinker *shrink, struct shrink_control *sc)
41501 sc->gfp_mask);
41502 freed += nr_free - shrink_pages;
41503
41504- pr_debug("%s: (%s:%d) Asked to shrink %d, have %d more to go\n",
41505+ pr_debug("%s: (%s:%d) Asked to shrink %lu, have %lu more to go\n",
41506 p->pool->dev_name, p->pool->name, current->pid,
41507 nr_free, shrink_pages);
41508 }
41509diff --git a/drivers/gpu/drm/udl/udl_fb.c b/drivers/gpu/drm/udl/udl_fb.c
41510index 8cbcb45..a4d9cf7 100644
41511--- a/drivers/gpu/drm/udl/udl_fb.c
41512+++ b/drivers/gpu/drm/udl/udl_fb.c
41513@@ -367,7 +367,6 @@ static int udl_fb_release(struct fb_info *info, int user)
41514 fb_deferred_io_cleanup(info);
41515 kfree(info->fbdefio);
41516 info->fbdefio = NULL;
41517- info->fbops->fb_mmap = udl_fb_mmap;
41518 }
41519
41520 pr_warn("released /dev/fb%d user=%d count=%d\n",
41521diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
41522index ef8c500..01030c8 100644
41523--- a/drivers/gpu/drm/via/via_drv.h
41524+++ b/drivers/gpu/drm/via/via_drv.h
41525@@ -53,7 +53,7 @@ typedef struct drm_via_ring_buffer {
41526 typedef uint32_t maskarray_t[5];
41527
41528 typedef struct drm_via_irq {
41529- atomic_t irq_received;
41530+ atomic_unchecked_t irq_received;
41531 uint32_t pending_mask;
41532 uint32_t enable_mask;
41533 wait_queue_head_t irq_queue;
41534@@ -77,7 +77,7 @@ typedef struct drm_via_private {
41535 struct timeval last_vblank;
41536 int last_vblank_valid;
41537 unsigned usec_per_vblank;
41538- atomic_t vbl_received;
41539+ atomic_unchecked_t vbl_received;
41540 drm_via_state_t hc_state;
41541 char pci_buf[VIA_PCI_BUF_SIZE];
41542 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
41543diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
41544index 1319433..a993b0c 100644
41545--- a/drivers/gpu/drm/via/via_irq.c
41546+++ b/drivers/gpu/drm/via/via_irq.c
41547@@ -101,7 +101,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
41548 if (crtc != 0)
41549 return 0;
41550
41551- return atomic_read(&dev_priv->vbl_received);
41552+ return atomic_read_unchecked(&dev_priv->vbl_received);
41553 }
41554
41555 irqreturn_t via_driver_irq_handler(int irq, void *arg)
41556@@ -116,8 +116,8 @@ irqreturn_t via_driver_irq_handler(int irq, void *arg)
41557
41558 status = VIA_READ(VIA_REG_INTERRUPT);
41559 if (status & VIA_IRQ_VBLANK_PENDING) {
41560- atomic_inc(&dev_priv->vbl_received);
41561- if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
41562+ atomic_inc_unchecked(&dev_priv->vbl_received);
41563+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
41564 do_gettimeofday(&cur_vblank);
41565 if (dev_priv->last_vblank_valid) {
41566 dev_priv->usec_per_vblank =
41567@@ -127,7 +127,7 @@ irqreturn_t via_driver_irq_handler(int irq, void *arg)
41568 dev_priv->last_vblank = cur_vblank;
41569 dev_priv->last_vblank_valid = 1;
41570 }
41571- if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
41572+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
41573 DRM_DEBUG("US per vblank is: %u\n",
41574 dev_priv->usec_per_vblank);
41575 }
41576@@ -137,7 +137,7 @@ irqreturn_t via_driver_irq_handler(int irq, void *arg)
41577
41578 for (i = 0; i < dev_priv->num_irqs; ++i) {
41579 if (status & cur_irq->pending_mask) {
41580- atomic_inc(&cur_irq->irq_received);
41581+ atomic_inc_unchecked(&cur_irq->irq_received);
41582 wake_up(&cur_irq->irq_queue);
41583 handled = 1;
41584 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
41585@@ -242,11 +242,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
41586 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * HZ,
41587 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
41588 masks[irq][4]));
41589- cur_irq_sequence = atomic_read(&cur_irq->irq_received);
41590+ cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
41591 } else {
41592 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * HZ,
41593 (((cur_irq_sequence =
41594- atomic_read(&cur_irq->irq_received)) -
41595+ atomic_read_unchecked(&cur_irq->irq_received)) -
41596 *sequence) <= (1 << 23)));
41597 }
41598 *sequence = cur_irq_sequence;
41599@@ -284,7 +284,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
41600 }
41601
41602 for (i = 0; i < dev_priv->num_irqs; ++i) {
41603- atomic_set(&cur_irq->irq_received, 0);
41604+ atomic_set_unchecked(&cur_irq->irq_received, 0);
41605 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
41606 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
41607 init_waitqueue_head(&cur_irq->irq_queue);
41608@@ -366,7 +366,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
41609 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
41610 case VIA_IRQ_RELATIVE:
41611 irqwait->request.sequence +=
41612- atomic_read(&cur_irq->irq_received);
41613+ atomic_read_unchecked(&cur_irq->irq_received);
41614 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
41615 case VIA_IRQ_ABSOLUTE:
41616 break;
41617diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
41618index 4ee799b..69fc0d1 100644
41619--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
41620+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
41621@@ -446,7 +446,7 @@ struct vmw_private {
41622 * Fencing and IRQs.
41623 */
41624
41625- atomic_t marker_seq;
41626+ atomic_unchecked_t marker_seq;
41627 wait_queue_head_t fence_queue;
41628 wait_queue_head_t fifo_queue;
41629 int fence_queue_waiters; /* Protected by hw_mutex */
41630diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
41631index 09e10ae..cb76c60 100644
41632--- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
41633+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
41634@@ -154,7 +154,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
41635 (unsigned int) min,
41636 (unsigned int) fifo->capabilities);
41637
41638- atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
41639+ atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
41640 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
41641 vmw_marker_queue_init(&fifo->marker_queue);
41642 return vmw_fifo_send_fence(dev_priv, &dummy);
41643@@ -378,7 +378,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
41644 if (reserveable)
41645 iowrite32(bytes, fifo_mem +
41646 SVGA_FIFO_RESERVED);
41647- return fifo_mem + (next_cmd >> 2);
41648+ return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
41649 } else {
41650 need_bounce = true;
41651 }
41652@@ -498,7 +498,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
41653
41654 fm = vmw_fifo_reserve(dev_priv, bytes);
41655 if (unlikely(fm == NULL)) {
41656- *seqno = atomic_read(&dev_priv->marker_seq);
41657+ *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
41658 ret = -ENOMEM;
41659 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
41660 false, 3*HZ);
41661@@ -506,7 +506,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
41662 }
41663
41664 do {
41665- *seqno = atomic_add_return(1, &dev_priv->marker_seq);
41666+ *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
41667 } while (*seqno == 0);
41668
41669 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
41670diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c b/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
41671index 170b61b..fec7348 100644
41672--- a/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
41673+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
41674@@ -164,9 +164,9 @@ static void vmw_gmrid_man_debug(struct ttm_mem_type_manager *man,
41675 }
41676
41677 const struct ttm_mem_type_manager_func vmw_gmrid_manager_func = {
41678- vmw_gmrid_man_init,
41679- vmw_gmrid_man_takedown,
41680- vmw_gmrid_man_get_node,
41681- vmw_gmrid_man_put_node,
41682- vmw_gmrid_man_debug
41683+ .init = vmw_gmrid_man_init,
41684+ .takedown = vmw_gmrid_man_takedown,
41685+ .get_node = vmw_gmrid_man_get_node,
41686+ .put_node = vmw_gmrid_man_put_node,
41687+ .debug = vmw_gmrid_man_debug
41688 };
41689diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
41690index 37881ec..319065d 100644
41691--- a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
41692+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
41693@@ -235,7 +235,7 @@ int vmw_present_ioctl(struct drm_device *dev, void *data,
41694 int ret;
41695
41696 num_clips = arg->num_clips;
41697- clips_ptr = (struct drm_vmw_rect *)(unsigned long)arg->clips_ptr;
41698+ clips_ptr = (struct drm_vmw_rect __user *)(unsigned long)arg->clips_ptr;
41699
41700 if (unlikely(num_clips == 0))
41701 return 0;
41702@@ -318,7 +318,7 @@ int vmw_present_readback_ioctl(struct drm_device *dev, void *data,
41703 int ret;
41704
41705 num_clips = arg->num_clips;
41706- clips_ptr = (struct drm_vmw_rect *)(unsigned long)arg->clips_ptr;
41707+ clips_ptr = (struct drm_vmw_rect __user *)(unsigned long)arg->clips_ptr;
41708
41709 if (unlikely(num_clips == 0))
41710 return 0;
41711diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
41712index 0c42376..6febe77 100644
41713--- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
41714+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
41715@@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
41716 * emitted. Then the fence is stale and signaled.
41717 */
41718
41719- ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
41720+ ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
41721 > VMW_FENCE_WRAP);
41722
41723 return ret;
41724@@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
41725
41726 if (fifo_idle)
41727 down_read(&fifo_state->rwsem);
41728- signal_seq = atomic_read(&dev_priv->marker_seq);
41729+ signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
41730 ret = 0;
41731
41732 for (;;) {
41733diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
41734index efd1ffd..0ae13ca 100644
41735--- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
41736+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
41737@@ -135,7 +135,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
41738 while (!vmw_lag_lt(queue, us)) {
41739 spin_lock(&queue->lock);
41740 if (list_empty(&queue->head))
41741- seqno = atomic_read(&dev_priv->marker_seq);
41742+ seqno = atomic_read_unchecked(&dev_priv->marker_seq);
41743 else {
41744 marker = list_first_entry(&queue->head,
41745 struct vmw_marker, head);
41746diff --git a/drivers/gpu/vga/vga_switcheroo.c b/drivers/gpu/vga/vga_switcheroo.c
41747index 37ac7b5..d52a5c9 100644
41748--- a/drivers/gpu/vga/vga_switcheroo.c
41749+++ b/drivers/gpu/vga/vga_switcheroo.c
41750@@ -644,7 +644,7 @@ static int vga_switcheroo_runtime_resume(struct device *dev)
41751
41752 /* this version is for the case where the power switch is separate
41753 to the device being powered down. */
41754-int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain)
41755+int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain)
41756 {
41757 /* copy over all the bus versions */
41758 if (dev->bus && dev->bus->pm) {
41759@@ -695,7 +695,7 @@ static int vga_switcheroo_runtime_resume_hdmi_audio(struct device *dev)
41760 return ret;
41761 }
41762
41763-int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain)
41764+int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain)
41765 {
41766 /* copy over all the bus versions */
41767 if (dev->bus && dev->bus->pm) {
41768diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
41769index 3402033..50b562c 100644
41770--- a/drivers/hid/hid-core.c
41771+++ b/drivers/hid/hid-core.c
41772@@ -2506,7 +2506,7 @@ EXPORT_SYMBOL_GPL(hid_ignore);
41773
41774 int hid_add_device(struct hid_device *hdev)
41775 {
41776- static atomic_t id = ATOMIC_INIT(0);
41777+ static atomic_unchecked_t id = ATOMIC_INIT(0);
41778 int ret;
41779
41780 if (WARN_ON(hdev->status & HID_STAT_ADDED))
41781@@ -2548,7 +2548,7 @@ int hid_add_device(struct hid_device *hdev)
41782 /* XXX hack, any other cleaner solution after the driver core
41783 * is converted to allow more than 20 bytes as the device name? */
41784 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
41785- hdev->vendor, hdev->product, atomic_inc_return(&id));
41786+ hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
41787
41788 hid_debug_register(hdev, dev_name(&hdev->dev));
41789 ret = device_add(&hdev->dev);
41790diff --git a/drivers/hid/hid-logitech-dj.c b/drivers/hid/hid-logitech-dj.c
41791index 71f5692..147d3da 100644
41792--- a/drivers/hid/hid-logitech-dj.c
41793+++ b/drivers/hid/hid-logitech-dj.c
41794@@ -658,6 +658,12 @@ static int logi_dj_raw_event(struct hid_device *hdev,
41795 * device (via hid_input_report() ) and return 1 so hid-core does not do
41796 * anything else with it.
41797 */
41798+ if ((dj_report->device_index < DJ_DEVICE_INDEX_MIN) ||
41799+ (dj_report->device_index > DJ_DEVICE_INDEX_MAX)) {
41800+ dev_err(&hdev->dev, "%s: invalid device index:%d\n",
41801+ __func__, dj_report->device_index);
41802+ return false;
41803+ }
41804
41805 /* case 1) */
41806 if (data[0] != REPORT_ID_DJ_SHORT)
41807diff --git a/drivers/hid/hid-sony.c b/drivers/hid/hid-sony.c
41808index bc4269e..b6e6102 100644
41809--- a/drivers/hid/hid-sony.c
41810+++ b/drivers/hid/hid-sony.c
41811@@ -798,6 +798,12 @@ union sixaxis_output_report_01 {
41812 __u8 buf[36];
41813 };
41814
41815+#define DS4_REPORT_0x02_SIZE 37
41816+#define DS4_REPORT_0x05_SIZE 32
41817+#define DS4_REPORT_0x11_SIZE 78
41818+#define DS4_REPORT_0x81_SIZE 7
41819+#define SIXAXIS_REPORT_0xF2_SIZE 18
41820+
41821 static spinlock_t sony_dev_list_lock;
41822 static LIST_HEAD(sony_device_list);
41823 static DEFINE_IDA(sony_device_id_allocator);
41824@@ -811,6 +817,7 @@ struct sony_sc {
41825 struct work_struct state_worker;
41826 struct power_supply battery;
41827 int device_id;
41828+ __u8 *output_report_dmabuf;
41829
41830 #ifdef CONFIG_SONY_FF
41831 __u8 left;
41832@@ -1142,9 +1149,20 @@ static int sixaxis_set_operational_usb(struct hid_device *hdev)
41833
41834 static int sixaxis_set_operational_bt(struct hid_device *hdev)
41835 {
41836- unsigned char buf[] = { 0xf4, 0x42, 0x03, 0x00, 0x00 };
41837- return hid_hw_raw_request(hdev, buf[0], buf, sizeof(buf),
41838+ static const __u8 report[] = { 0xf4, 0x42, 0x03, 0x00, 0x00 };
41839+ __u8 *buf;
41840+ int ret;
41841+
41842+ buf = kmemdup(report, sizeof(report), GFP_KERNEL);
41843+ if (!buf)
41844+ return -ENOMEM;
41845+
41846+ ret = hid_hw_raw_request(hdev, buf[0], buf, sizeof(report),
41847 HID_FEATURE_REPORT, HID_REQ_SET_REPORT);
41848+
41849+ kfree(buf);
41850+
41851+ return ret;
41852 }
41853
41854 /*
41855@@ -1153,10 +1171,19 @@ static int sixaxis_set_operational_bt(struct hid_device *hdev)
41856 */
41857 static int dualshock4_set_operational_bt(struct hid_device *hdev)
41858 {
41859- __u8 buf[37] = { 0 };
41860+ __u8 *buf;
41861+ int ret;
41862
41863- return hid_hw_raw_request(hdev, 0x02, buf, sizeof(buf),
41864+ buf = kmalloc(DS4_REPORT_0x02_SIZE, GFP_KERNEL);
41865+ if (!buf)
41866+ return -ENOMEM;
41867+
41868+ ret = hid_hw_raw_request(hdev, 0x02, buf, DS4_REPORT_0x02_SIZE,
41869 HID_FEATURE_REPORT, HID_REQ_GET_REPORT);
41870+
41871+ kfree(buf);
41872+
41873+ return ret;
41874 }
41875
41876 static void sixaxis_set_leds_from_id(int id, __u8 values[MAX_LEDS])
41877@@ -1471,9 +1498,7 @@ error_leds:
41878
41879 static void sixaxis_state_worker(struct work_struct *work)
41880 {
41881- struct sony_sc *sc = container_of(work, struct sony_sc, state_worker);
41882- int n;
41883- union sixaxis_output_report_01 report = {
41884+ static const union sixaxis_output_report_01 default_report = {
41885 .buf = {
41886 0x01,
41887 0x00, 0xff, 0x00, 0xff, 0x00,
41888@@ -1485,20 +1510,27 @@ static void sixaxis_state_worker(struct work_struct *work)
41889 0x00, 0x00, 0x00, 0x00, 0x00
41890 }
41891 };
41892+ struct sony_sc *sc = container_of(work, struct sony_sc, state_worker);
41893+ struct sixaxis_output_report *report =
41894+ (struct sixaxis_output_report *)sc->output_report_dmabuf;
41895+ int n;
41896+
41897+ /* Initialize the report with default values */
41898+ memcpy(report, &default_report, sizeof(struct sixaxis_output_report));
41899
41900 #ifdef CONFIG_SONY_FF
41901- report.data.rumble.right_motor_on = sc->right ? 1 : 0;
41902- report.data.rumble.left_motor_force = sc->left;
41903+ report->rumble.right_motor_on = sc->right ? 1 : 0;
41904+ report->rumble.left_motor_force = sc->left;
41905 #endif
41906
41907- report.data.leds_bitmap |= sc->led_state[0] << 1;
41908- report.data.leds_bitmap |= sc->led_state[1] << 2;
41909- report.data.leds_bitmap |= sc->led_state[2] << 3;
41910- report.data.leds_bitmap |= sc->led_state[3] << 4;
41911+ report->leds_bitmap |= sc->led_state[0] << 1;
41912+ report->leds_bitmap |= sc->led_state[1] << 2;
41913+ report->leds_bitmap |= sc->led_state[2] << 3;
41914+ report->leds_bitmap |= sc->led_state[3] << 4;
41915
41916 /* Set flag for all leds off, required for 3rd party INTEC controller */
41917- if ((report.data.leds_bitmap & 0x1E) == 0)
41918- report.data.leds_bitmap |= 0x20;
41919+ if ((report->leds_bitmap & 0x1E) == 0)
41920+ report->leds_bitmap |= 0x20;
41921
41922 /*
41923 * The LEDs in the report are indexed in reverse order to their
41924@@ -1511,28 +1543,30 @@ static void sixaxis_state_worker(struct work_struct *work)
41925 */
41926 for (n = 0; n < 4; n++) {
41927 if (sc->led_delay_on[n] || sc->led_delay_off[n]) {
41928- report.data.led[3 - n].duty_off = sc->led_delay_off[n];
41929- report.data.led[3 - n].duty_on = sc->led_delay_on[n];
41930+ report->led[3 - n].duty_off = sc->led_delay_off[n];
41931+ report->led[3 - n].duty_on = sc->led_delay_on[n];
41932 }
41933 }
41934
41935- hid_hw_raw_request(sc->hdev, report.data.report_id, report.buf,
41936- sizeof(report), HID_OUTPUT_REPORT, HID_REQ_SET_REPORT);
41937+ hid_hw_raw_request(sc->hdev, report->report_id, (__u8 *)report,
41938+ sizeof(struct sixaxis_output_report),
41939+ HID_OUTPUT_REPORT, HID_REQ_SET_REPORT);
41940 }
41941
41942 static void dualshock4_state_worker(struct work_struct *work)
41943 {
41944 struct sony_sc *sc = container_of(work, struct sony_sc, state_worker);
41945 struct hid_device *hdev = sc->hdev;
41946+ __u8 *buf = sc->output_report_dmabuf;
41947 int offset;
41948
41949- __u8 buf[78] = { 0 };
41950-
41951 if (sc->quirks & DUALSHOCK4_CONTROLLER_USB) {
41952+ memset(buf, 0, DS4_REPORT_0x05_SIZE);
41953 buf[0] = 0x05;
41954 buf[1] = 0xFF;
41955 offset = 4;
41956 } else {
41957+ memset(buf, 0, DS4_REPORT_0x11_SIZE);
41958 buf[0] = 0x11;
41959 buf[1] = 0xB0;
41960 buf[3] = 0x0F;
41961@@ -1560,12 +1594,33 @@ static void dualshock4_state_worker(struct work_struct *work)
41962 buf[offset++] = sc->led_delay_off[3];
41963
41964 if (sc->quirks & DUALSHOCK4_CONTROLLER_USB)
41965- hid_hw_output_report(hdev, buf, 32);
41966+ hid_hw_output_report(hdev, buf, DS4_REPORT_0x05_SIZE);
41967 else
41968- hid_hw_raw_request(hdev, 0x11, buf, 78,
41969+ hid_hw_raw_request(hdev, 0x11, buf, DS4_REPORT_0x11_SIZE,
41970 HID_OUTPUT_REPORT, HID_REQ_SET_REPORT);
41971 }
41972
41973+static int sony_allocate_output_report(struct sony_sc *sc)
41974+{
41975+ if (sc->quirks & SIXAXIS_CONTROLLER)
41976+ sc->output_report_dmabuf =
41977+ kmalloc(sizeof(union sixaxis_output_report_01),
41978+ GFP_KERNEL);
41979+ else if (sc->quirks & DUALSHOCK4_CONTROLLER_BT)
41980+ sc->output_report_dmabuf = kmalloc(DS4_REPORT_0x11_SIZE,
41981+ GFP_KERNEL);
41982+ else if (sc->quirks & DUALSHOCK4_CONTROLLER_USB)
41983+ sc->output_report_dmabuf = kmalloc(DS4_REPORT_0x05_SIZE,
41984+ GFP_KERNEL);
41985+ else
41986+ return 0;
41987+
41988+ if (!sc->output_report_dmabuf)
41989+ return -ENOMEM;
41990+
41991+ return 0;
41992+}
41993+
41994 #ifdef CONFIG_SONY_FF
41995 static int sony_play_effect(struct input_dev *dev, void *data,
41996 struct ff_effect *effect)
41997@@ -1754,6 +1809,7 @@ static int sony_get_bt_devaddr(struct sony_sc *sc)
41998
41999 static int sony_check_add(struct sony_sc *sc)
42000 {
42001+ __u8 *buf = NULL;
42002 int n, ret;
42003
42004 if ((sc->quirks & DUALSHOCK4_CONTROLLER_BT) ||
42005@@ -1769,36 +1825,44 @@ static int sony_check_add(struct sony_sc *sc)
42006 return 0;
42007 }
42008 } else if (sc->quirks & DUALSHOCK4_CONTROLLER_USB) {
42009- __u8 buf[7];
42010+ buf = kmalloc(DS4_REPORT_0x81_SIZE, GFP_KERNEL);
42011+ if (!buf)
42012+ return -ENOMEM;
42013
42014 /*
42015 * The MAC address of a DS4 controller connected via USB can be
42016 * retrieved with feature report 0x81. The address begins at
42017 * offset 1.
42018 */
42019- ret = hid_hw_raw_request(sc->hdev, 0x81, buf, sizeof(buf),
42020- HID_FEATURE_REPORT, HID_REQ_GET_REPORT);
42021+ ret = hid_hw_raw_request(sc->hdev, 0x81, buf,
42022+ DS4_REPORT_0x81_SIZE, HID_FEATURE_REPORT,
42023+ HID_REQ_GET_REPORT);
42024
42025- if (ret != 7) {
42026+ if (ret != DS4_REPORT_0x81_SIZE) {
42027 hid_err(sc->hdev, "failed to retrieve feature report 0x81 with the DualShock 4 MAC address\n");
42028- return ret < 0 ? ret : -EINVAL;
42029+ ret = ret < 0 ? ret : -EINVAL;
42030+ goto out_free;
42031 }
42032
42033 memcpy(sc->mac_address, &buf[1], sizeof(sc->mac_address));
42034 } else if (sc->quirks & SIXAXIS_CONTROLLER_USB) {
42035- __u8 buf[18];
42036+ buf = kmalloc(SIXAXIS_REPORT_0xF2_SIZE, GFP_KERNEL);
42037+ if (!buf)
42038+ return -ENOMEM;
42039
42040 /*
42041 * The MAC address of a Sixaxis controller connected via USB can
42042 * be retrieved with feature report 0xf2. The address begins at
42043 * offset 4.
42044 */
42045- ret = hid_hw_raw_request(sc->hdev, 0xf2, buf, sizeof(buf),
42046- HID_FEATURE_REPORT, HID_REQ_GET_REPORT);
42047+ ret = hid_hw_raw_request(sc->hdev, 0xf2, buf,
42048+ SIXAXIS_REPORT_0xF2_SIZE, HID_FEATURE_REPORT,
42049+ HID_REQ_GET_REPORT);
42050
42051- if (ret != 18) {
42052+ if (ret != SIXAXIS_REPORT_0xF2_SIZE) {
42053 hid_err(sc->hdev, "failed to retrieve feature report 0xf2 with the Sixaxis MAC address\n");
42054- return ret < 0 ? ret : -EINVAL;
42055+ ret = ret < 0 ? ret : -EINVAL;
42056+ goto out_free;
42057 }
42058
42059 /*
42060@@ -1811,7 +1875,13 @@ static int sony_check_add(struct sony_sc *sc)
42061 return 0;
42062 }
42063
42064- return sony_check_add_dev_list(sc);
42065+ ret = sony_check_add_dev_list(sc);
42066+
42067+out_free:
42068+
42069+ kfree(buf);
42070+
42071+ return ret;
42072 }
42073
42074 static int sony_set_device_id(struct sony_sc *sc)
42075@@ -1895,6 +1965,12 @@ static int sony_probe(struct hid_device *hdev, const struct hid_device_id *id)
42076 return ret;
42077 }
42078
42079+ ret = sony_allocate_output_report(sc);
42080+ if (ret < 0) {
42081+ hid_err(hdev, "failed to allocate the output report buffer\n");
42082+ goto err_stop;
42083+ }
42084+
42085 ret = sony_set_device_id(sc);
42086 if (ret < 0) {
42087 hid_err(hdev, "failed to allocate the device id\n");
42088@@ -1984,6 +2060,7 @@ err_stop:
42089 if (sc->quirks & SONY_BATTERY_SUPPORT)
42090 sony_battery_remove(sc);
42091 sony_cancel_work_sync(sc);
42092+ kfree(sc->output_report_dmabuf);
42093 sony_remove_dev_list(sc);
42094 sony_release_device_id(sc);
42095 hid_hw_stop(hdev);
42096@@ -2004,6 +2081,8 @@ static void sony_remove(struct hid_device *hdev)
42097
42098 sony_cancel_work_sync(sc);
42099
42100+ kfree(sc->output_report_dmabuf);
42101+
42102 sony_remove_dev_list(sc);
42103
42104 sony_release_device_id(sc);
42105diff --git a/drivers/hid/hid-wiimote-debug.c b/drivers/hid/hid-wiimote-debug.c
42106index c13fb5b..55a3802 100644
42107--- a/drivers/hid/hid-wiimote-debug.c
42108+++ b/drivers/hid/hid-wiimote-debug.c
42109@@ -66,7 +66,7 @@ static ssize_t wiidebug_eeprom_read(struct file *f, char __user *u, size_t s,
42110 else if (size == 0)
42111 return -EIO;
42112
42113- if (copy_to_user(u, buf, size))
42114+ if (size > sizeof(buf) || copy_to_user(u, buf, size))
42115 return -EFAULT;
42116
42117 *off += size;
42118diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
42119index 433f72a..2926005 100644
42120--- a/drivers/hv/channel.c
42121+++ b/drivers/hv/channel.c
42122@@ -366,8 +366,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
42123 unsigned long flags;
42124 int ret = 0;
42125
42126- next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
42127- atomic_inc(&vmbus_connection.next_gpadl_handle);
42128+ next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
42129+ atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
42130
42131 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
42132 if (ret)
42133diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
42134index 3e4235c..877d0e5 100644
42135--- a/drivers/hv/hv.c
42136+++ b/drivers/hv/hv.c
42137@@ -112,7 +112,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
42138 u64 output_address = (output) ? virt_to_phys(output) : 0;
42139 u32 output_address_hi = output_address >> 32;
42140 u32 output_address_lo = output_address & 0xFFFFFFFF;
42141- void *hypercall_page = hv_context.hypercall_page;
42142+ void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
42143
42144 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
42145 "=a"(hv_status_lo) : "d" (control_hi),
42146@@ -156,7 +156,7 @@ int hv_init(void)
42147 /* See if the hypercall page is already set */
42148 rdmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64);
42149
42150- virtaddr = __vmalloc(PAGE_SIZE, GFP_KERNEL, PAGE_KERNEL_EXEC);
42151+ virtaddr = __vmalloc(PAGE_SIZE, GFP_KERNEL, PAGE_KERNEL_RX);
42152
42153 if (!virtaddr)
42154 goto cleanup;
42155diff --git a/drivers/hv/hv_balloon.c b/drivers/hv/hv_balloon.c
42156index 5e90c5d..d8fcefb 100644
42157--- a/drivers/hv/hv_balloon.c
42158+++ b/drivers/hv/hv_balloon.c
42159@@ -470,7 +470,7 @@ MODULE_PARM_DESC(hot_add, "If set attempt memory hot_add");
42160
42161 module_param(pressure_report_delay, uint, (S_IRUGO | S_IWUSR));
42162 MODULE_PARM_DESC(pressure_report_delay, "Delay in secs in reporting pressure");
42163-static atomic_t trans_id = ATOMIC_INIT(0);
42164+static atomic_unchecked_t trans_id = ATOMIC_INIT(0);
42165
42166 static int dm_ring_size = (5 * PAGE_SIZE);
42167
42168@@ -893,7 +893,7 @@ static void hot_add_req(struct work_struct *dummy)
42169 pr_info("Memory hot add failed\n");
42170
42171 dm->state = DM_INITIALIZED;
42172- resp.hdr.trans_id = atomic_inc_return(&trans_id);
42173+ resp.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
42174 vmbus_sendpacket(dm->dev->channel, &resp,
42175 sizeof(struct dm_hot_add_response),
42176 (unsigned long)NULL,
42177@@ -973,7 +973,7 @@ static void post_status(struct hv_dynmem_device *dm)
42178 memset(&status, 0, sizeof(struct dm_status));
42179 status.hdr.type = DM_STATUS_REPORT;
42180 status.hdr.size = sizeof(struct dm_status);
42181- status.hdr.trans_id = atomic_inc_return(&trans_id);
42182+ status.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
42183
42184 /*
42185 * The host expects the guest to report free memory.
42186@@ -993,7 +993,7 @@ static void post_status(struct hv_dynmem_device *dm)
42187 * send the status. This can happen if we were interrupted
42188 * after we picked our transaction ID.
42189 */
42190- if (status.hdr.trans_id != atomic_read(&trans_id))
42191+ if (status.hdr.trans_id != atomic_read_unchecked(&trans_id))
42192 return;
42193
42194 /*
42195@@ -1129,7 +1129,7 @@ static void balloon_up(struct work_struct *dummy)
42196 */
42197
42198 do {
42199- bl_resp->hdr.trans_id = atomic_inc_return(&trans_id);
42200+ bl_resp->hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
42201 ret = vmbus_sendpacket(dm_device.dev->channel,
42202 bl_resp,
42203 bl_resp->hdr.size,
42204@@ -1175,7 +1175,7 @@ static void balloon_down(struct hv_dynmem_device *dm,
42205
42206 memset(&resp, 0, sizeof(struct dm_unballoon_response));
42207 resp.hdr.type = DM_UNBALLOON_RESPONSE;
42208- resp.hdr.trans_id = atomic_inc_return(&trans_id);
42209+ resp.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
42210 resp.hdr.size = sizeof(struct dm_unballoon_response);
42211
42212 vmbus_sendpacket(dm_device.dev->channel, &resp,
42213@@ -1239,7 +1239,7 @@ static void version_resp(struct hv_dynmem_device *dm,
42214 memset(&version_req, 0, sizeof(struct dm_version_request));
42215 version_req.hdr.type = DM_VERSION_REQUEST;
42216 version_req.hdr.size = sizeof(struct dm_version_request);
42217- version_req.hdr.trans_id = atomic_inc_return(&trans_id);
42218+ version_req.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
42219 version_req.version.version = DYNMEM_PROTOCOL_VERSION_WIN7;
42220 version_req.is_last_attempt = 1;
42221
42222@@ -1409,7 +1409,7 @@ static int balloon_probe(struct hv_device *dev,
42223 memset(&version_req, 0, sizeof(struct dm_version_request));
42224 version_req.hdr.type = DM_VERSION_REQUEST;
42225 version_req.hdr.size = sizeof(struct dm_version_request);
42226- version_req.hdr.trans_id = atomic_inc_return(&trans_id);
42227+ version_req.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
42228 version_req.version.version = DYNMEM_PROTOCOL_VERSION_WIN8;
42229 version_req.is_last_attempt = 0;
42230
42231@@ -1440,7 +1440,7 @@ static int balloon_probe(struct hv_device *dev,
42232 memset(&cap_msg, 0, sizeof(struct dm_capabilities));
42233 cap_msg.hdr.type = DM_CAPABILITIES_REPORT;
42234 cap_msg.hdr.size = sizeof(struct dm_capabilities);
42235- cap_msg.hdr.trans_id = atomic_inc_return(&trans_id);
42236+ cap_msg.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
42237
42238 cap_msg.caps.cap_bits.balloon = 1;
42239 cap_msg.caps.cap_bits.hot_add = 1;
42240diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
42241index c386d8d..d6004c4 100644
42242--- a/drivers/hv/hyperv_vmbus.h
42243+++ b/drivers/hv/hyperv_vmbus.h
42244@@ -611,7 +611,7 @@ enum vmbus_connect_state {
42245 struct vmbus_connection {
42246 enum vmbus_connect_state conn_state;
42247
42248- atomic_t next_gpadl_handle;
42249+ atomic_unchecked_t next_gpadl_handle;
42250
42251 /*
42252 * Represents channel interrupts. Each bit position represents a
42253diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
42254index 4d6b269..2e23b86 100644
42255--- a/drivers/hv/vmbus_drv.c
42256+++ b/drivers/hv/vmbus_drv.c
42257@@ -807,10 +807,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
42258 {
42259 int ret = 0;
42260
42261- static atomic_t device_num = ATOMIC_INIT(0);
42262+ static atomic_unchecked_t device_num = ATOMIC_INIT(0);
42263
42264 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
42265- atomic_inc_return(&device_num));
42266+ atomic_inc_return_unchecked(&device_num));
42267
42268 child_device_obj->device.bus = &hv_bus;
42269 child_device_obj->device.parent = &hv_acpi_dev->dev;
42270diff --git a/drivers/hwmon/acpi_power_meter.c b/drivers/hwmon/acpi_power_meter.c
42271index 579bdf9..75118b5 100644
42272--- a/drivers/hwmon/acpi_power_meter.c
42273+++ b/drivers/hwmon/acpi_power_meter.c
42274@@ -116,7 +116,7 @@ struct sensor_template {
42275 struct device_attribute *devattr,
42276 const char *buf, size_t count);
42277 int index;
42278-};
42279+} __do_const;
42280
42281 /* Averaging interval */
42282 static int update_avg_interval(struct acpi_power_meter_resource *resource)
42283@@ -631,7 +631,7 @@ static int register_attrs(struct acpi_power_meter_resource *resource,
42284 struct sensor_template *attrs)
42285 {
42286 struct device *dev = &resource->acpi_dev->dev;
42287- struct sensor_device_attribute *sensors =
42288+ sensor_device_attribute_no_const *sensors =
42289 &resource->sensors[resource->num_sensors];
42290 int res = 0;
42291
42292diff --git a/drivers/hwmon/applesmc.c b/drivers/hwmon/applesmc.c
42293index 3288f13..71cfb4e 100644
42294--- a/drivers/hwmon/applesmc.c
42295+++ b/drivers/hwmon/applesmc.c
42296@@ -1106,7 +1106,7 @@ static int applesmc_create_nodes(struct applesmc_node_group *groups, int num)
42297 {
42298 struct applesmc_node_group *grp;
42299 struct applesmc_dev_attr *node;
42300- struct attribute *attr;
42301+ attribute_no_const *attr;
42302 int ret, i;
42303
42304 for (grp = groups; grp->format; grp++) {
42305diff --git a/drivers/hwmon/asus_atk0110.c b/drivers/hwmon/asus_atk0110.c
42306index cccef87..06ce8ec 100644
42307--- a/drivers/hwmon/asus_atk0110.c
42308+++ b/drivers/hwmon/asus_atk0110.c
42309@@ -147,10 +147,10 @@ MODULE_DEVICE_TABLE(acpi, atk_ids);
42310 struct atk_sensor_data {
42311 struct list_head list;
42312 struct atk_data *data;
42313- struct device_attribute label_attr;
42314- struct device_attribute input_attr;
42315- struct device_attribute limit1_attr;
42316- struct device_attribute limit2_attr;
42317+ device_attribute_no_const label_attr;
42318+ device_attribute_no_const input_attr;
42319+ device_attribute_no_const limit1_attr;
42320+ device_attribute_no_const limit2_attr;
42321 char label_attr_name[ATTR_NAME_SIZE];
42322 char input_attr_name[ATTR_NAME_SIZE];
42323 char limit1_attr_name[ATTR_NAME_SIZE];
42324@@ -270,7 +270,7 @@ static ssize_t atk_name_show(struct device *dev,
42325 static struct device_attribute atk_name_attr =
42326 __ATTR(name, 0444, atk_name_show, NULL);
42327
42328-static void atk_init_attribute(struct device_attribute *attr, char *name,
42329+static void atk_init_attribute(device_attribute_no_const *attr, char *name,
42330 sysfs_show_func show)
42331 {
42332 sysfs_attr_init(&attr->attr);
42333diff --git a/drivers/hwmon/coretemp.c b/drivers/hwmon/coretemp.c
42334index d76f0b7..55ae976 100644
42335--- a/drivers/hwmon/coretemp.c
42336+++ b/drivers/hwmon/coretemp.c
42337@@ -784,7 +784,7 @@ static int coretemp_cpu_callback(struct notifier_block *nfb,
42338 return NOTIFY_OK;
42339 }
42340
42341-static struct notifier_block coretemp_cpu_notifier __refdata = {
42342+static struct notifier_block coretemp_cpu_notifier = {
42343 .notifier_call = coretemp_cpu_callback,
42344 };
42345
42346diff --git a/drivers/hwmon/ibmaem.c b/drivers/hwmon/ibmaem.c
42347index 7a8a6fb..015c1fd 100644
42348--- a/drivers/hwmon/ibmaem.c
42349+++ b/drivers/hwmon/ibmaem.c
42350@@ -924,7 +924,7 @@ static int aem_register_sensors(struct aem_data *data,
42351 struct aem_rw_sensor_template *rw)
42352 {
42353 struct device *dev = &data->pdev->dev;
42354- struct sensor_device_attribute *sensors = data->sensors;
42355+ sensor_device_attribute_no_const *sensors = data->sensors;
42356 int err;
42357
42358 /* Set up read-only sensors */
42359diff --git a/drivers/hwmon/iio_hwmon.c b/drivers/hwmon/iio_hwmon.c
42360index 14c82da..09b25d7 100644
42361--- a/drivers/hwmon/iio_hwmon.c
42362+++ b/drivers/hwmon/iio_hwmon.c
42363@@ -61,7 +61,7 @@ static int iio_hwmon_probe(struct platform_device *pdev)
42364 {
42365 struct device *dev = &pdev->dev;
42366 struct iio_hwmon_state *st;
42367- struct sensor_device_attribute *a;
42368+ sensor_device_attribute_no_const *a;
42369 int ret, i;
42370 int in_i = 1, temp_i = 1, curr_i = 1;
42371 enum iio_chan_type type;
42372diff --git a/drivers/hwmon/nct6683.c b/drivers/hwmon/nct6683.c
42373index 7710f46..427a28d 100644
42374--- a/drivers/hwmon/nct6683.c
42375+++ b/drivers/hwmon/nct6683.c
42376@@ -397,11 +397,11 @@ static struct attribute_group *
42377 nct6683_create_attr_group(struct device *dev, struct sensor_template_group *tg,
42378 int repeat)
42379 {
42380- struct sensor_device_attribute_2 *a2;
42381- struct sensor_device_attribute *a;
42382+ sensor_device_attribute_2_no_const *a2;
42383+ sensor_device_attribute_no_const *a;
42384 struct sensor_device_template **t;
42385 struct sensor_device_attr_u *su;
42386- struct attribute_group *group;
42387+ attribute_group_no_const *group;
42388 struct attribute **attrs;
42389 int i, j, count;
42390
42391diff --git a/drivers/hwmon/nct6775.c b/drivers/hwmon/nct6775.c
42392index 504cbdd..35d6f25 100644
42393--- a/drivers/hwmon/nct6775.c
42394+++ b/drivers/hwmon/nct6775.c
42395@@ -943,10 +943,10 @@ static struct attribute_group *
42396 nct6775_create_attr_group(struct device *dev, struct sensor_template_group *tg,
42397 int repeat)
42398 {
42399- struct attribute_group *group;
42400+ attribute_group_no_const *group;
42401 struct sensor_device_attr_u *su;
42402- struct sensor_device_attribute *a;
42403- struct sensor_device_attribute_2 *a2;
42404+ sensor_device_attribute_no_const *a;
42405+ sensor_device_attribute_2_no_const *a2;
42406 struct attribute **attrs;
42407 struct sensor_device_template **t;
42408 int i, count;
42409diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
42410index 291d11f..3f0dbbd 100644
42411--- a/drivers/hwmon/pmbus/pmbus_core.c
42412+++ b/drivers/hwmon/pmbus/pmbus_core.c
42413@@ -783,7 +783,7 @@ static int pmbus_add_attribute(struct pmbus_data *data, struct attribute *attr)
42414 return 0;
42415 }
42416
42417-static void pmbus_dev_attr_init(struct device_attribute *dev_attr,
42418+static void pmbus_dev_attr_init(device_attribute_no_const *dev_attr,
42419 const char *name,
42420 umode_t mode,
42421 ssize_t (*show)(struct device *dev,
42422@@ -800,7 +800,7 @@ static void pmbus_dev_attr_init(struct device_attribute *dev_attr,
42423 dev_attr->store = store;
42424 }
42425
42426-static void pmbus_attr_init(struct sensor_device_attribute *a,
42427+static void pmbus_attr_init(sensor_device_attribute_no_const *a,
42428 const char *name,
42429 umode_t mode,
42430 ssize_t (*show)(struct device *dev,
42431@@ -822,7 +822,7 @@ static int pmbus_add_boolean(struct pmbus_data *data,
42432 u16 reg, u8 mask)
42433 {
42434 struct pmbus_boolean *boolean;
42435- struct sensor_device_attribute *a;
42436+ sensor_device_attribute_no_const *a;
42437
42438 boolean = devm_kzalloc(data->dev, sizeof(*boolean), GFP_KERNEL);
42439 if (!boolean)
42440@@ -847,7 +847,7 @@ static struct pmbus_sensor *pmbus_add_sensor(struct pmbus_data *data,
42441 bool update, bool readonly)
42442 {
42443 struct pmbus_sensor *sensor;
42444- struct device_attribute *a;
42445+ device_attribute_no_const *a;
42446
42447 sensor = devm_kzalloc(data->dev, sizeof(*sensor), GFP_KERNEL);
42448 if (!sensor)
42449@@ -878,7 +878,7 @@ static int pmbus_add_label(struct pmbus_data *data,
42450 const char *lstring, int index)
42451 {
42452 struct pmbus_label *label;
42453- struct device_attribute *a;
42454+ device_attribute_no_const *a;
42455
42456 label = devm_kzalloc(data->dev, sizeof(*label), GFP_KERNEL);
42457 if (!label)
42458diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
42459index 97cd45a..ac54d8b 100644
42460--- a/drivers/hwmon/sht15.c
42461+++ b/drivers/hwmon/sht15.c
42462@@ -169,7 +169,7 @@ struct sht15_data {
42463 int supply_uv;
42464 bool supply_uv_valid;
42465 struct work_struct update_supply_work;
42466- atomic_t interrupt_handled;
42467+ atomic_unchecked_t interrupt_handled;
42468 };
42469
42470 /**
42471@@ -542,13 +542,13 @@ static int sht15_measurement(struct sht15_data *data,
42472 ret = gpio_direction_input(data->pdata->gpio_data);
42473 if (ret)
42474 return ret;
42475- atomic_set(&data->interrupt_handled, 0);
42476+ atomic_set_unchecked(&data->interrupt_handled, 0);
42477
42478 enable_irq(gpio_to_irq(data->pdata->gpio_data));
42479 if (gpio_get_value(data->pdata->gpio_data) == 0) {
42480 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
42481 /* Only relevant if the interrupt hasn't occurred. */
42482- if (!atomic_read(&data->interrupt_handled))
42483+ if (!atomic_read_unchecked(&data->interrupt_handled))
42484 schedule_work(&data->read_work);
42485 }
42486 ret = wait_event_timeout(data->wait_queue,
42487@@ -820,7 +820,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
42488
42489 /* First disable the interrupt */
42490 disable_irq_nosync(irq);
42491- atomic_inc(&data->interrupt_handled);
42492+ atomic_inc_unchecked(&data->interrupt_handled);
42493 /* Then schedule a reading work struct */
42494 if (data->state != SHT15_READING_NOTHING)
42495 schedule_work(&data->read_work);
42496@@ -842,11 +842,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
42497 * If not, then start the interrupt again - care here as could
42498 * have gone low in meantime so verify it hasn't!
42499 */
42500- atomic_set(&data->interrupt_handled, 0);
42501+ atomic_set_unchecked(&data->interrupt_handled, 0);
42502 enable_irq(gpio_to_irq(data->pdata->gpio_data));
42503 /* If still not occurred or another handler was scheduled */
42504 if (gpio_get_value(data->pdata->gpio_data)
42505- || atomic_read(&data->interrupt_handled))
42506+ || atomic_read_unchecked(&data->interrupt_handled))
42507 return;
42508 }
42509
42510diff --git a/drivers/hwmon/via-cputemp.c b/drivers/hwmon/via-cputemp.c
42511index 8df43c5..b07b91d 100644
42512--- a/drivers/hwmon/via-cputemp.c
42513+++ b/drivers/hwmon/via-cputemp.c
42514@@ -296,7 +296,7 @@ static int via_cputemp_cpu_callback(struct notifier_block *nfb,
42515 return NOTIFY_OK;
42516 }
42517
42518-static struct notifier_block via_cputemp_cpu_notifier __refdata = {
42519+static struct notifier_block via_cputemp_cpu_notifier = {
42520 .notifier_call = via_cputemp_cpu_callback,
42521 };
42522
42523diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
42524index 65e3240..e6c511d 100644
42525--- a/drivers/i2c/busses/i2c-amd756-s4882.c
42526+++ b/drivers/i2c/busses/i2c-amd756-s4882.c
42527@@ -39,7 +39,7 @@
42528 extern struct i2c_adapter amd756_smbus;
42529
42530 static struct i2c_adapter *s4882_adapter;
42531-static struct i2c_algorithm *s4882_algo;
42532+static i2c_algorithm_no_const *s4882_algo;
42533
42534 /* Wrapper access functions for multiplexed SMBus */
42535 static DEFINE_MUTEX(amd756_lock);
42536diff --git a/drivers/i2c/busses/i2c-diolan-u2c.c b/drivers/i2c/busses/i2c-diolan-u2c.c
42537index b19a310..d6eece0 100644
42538--- a/drivers/i2c/busses/i2c-diolan-u2c.c
42539+++ b/drivers/i2c/busses/i2c-diolan-u2c.c
42540@@ -98,7 +98,7 @@ MODULE_PARM_DESC(frequency, "I2C clock frequency in hertz");
42541 /* usb layer */
42542
42543 /* Send command to device, and get response. */
42544-static int diolan_usb_transfer(struct i2c_diolan_u2c *dev)
42545+static int __intentional_overflow(-1) diolan_usb_transfer(struct i2c_diolan_u2c *dev)
42546 {
42547 int ret = 0;
42548 int actual;
42549diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
42550index 88eda09..cf40434 100644
42551--- a/drivers/i2c/busses/i2c-nforce2-s4985.c
42552+++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
42553@@ -37,7 +37,7 @@
42554 extern struct i2c_adapter *nforce2_smbus;
42555
42556 static struct i2c_adapter *s4985_adapter;
42557-static struct i2c_algorithm *s4985_algo;
42558+static i2c_algorithm_no_const *s4985_algo;
42559
42560 /* Wrapper access functions for multiplexed SMBus */
42561 static DEFINE_MUTEX(nforce2_lock);
42562diff --git a/drivers/i2c/i2c-dev.c b/drivers/i2c/i2c-dev.c
42563index 71c7a39..71dd3e0 100644
42564--- a/drivers/i2c/i2c-dev.c
42565+++ b/drivers/i2c/i2c-dev.c
42566@@ -272,7 +272,7 @@ static noinline int i2cdev_ioctl_rdrw(struct i2c_client *client,
42567 break;
42568 }
42569
42570- data_ptrs[i] = (u8 __user *)rdwr_pa[i].buf;
42571+ data_ptrs[i] = (u8 __force_user *)rdwr_pa[i].buf;
42572 rdwr_pa[i].buf = memdup_user(data_ptrs[i], rdwr_pa[i].len);
42573 if (IS_ERR(rdwr_pa[i].buf)) {
42574 res = PTR_ERR(rdwr_pa[i].buf);
42575diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
42576index 0b510ba..4fbb5085 100644
42577--- a/drivers/ide/ide-cd.c
42578+++ b/drivers/ide/ide-cd.c
42579@@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
42580 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
42581 if ((unsigned long)buf & alignment
42582 || blk_rq_bytes(rq) & q->dma_pad_mask
42583- || object_is_on_stack(buf))
42584+ || object_starts_on_stack(buf))
42585 drive->dma = 0;
42586 }
42587 }
42588diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
42589index af3e76d..96dfe5e 100644
42590--- a/drivers/iio/industrialio-core.c
42591+++ b/drivers/iio/industrialio-core.c
42592@@ -555,7 +555,7 @@ static ssize_t iio_write_channel_info(struct device *dev,
42593 }
42594
42595 static
42596-int __iio_device_attr_init(struct device_attribute *dev_attr,
42597+int __iio_device_attr_init(device_attribute_no_const *dev_attr,
42598 const char *postfix,
42599 struct iio_chan_spec const *chan,
42600 ssize_t (*readfunc)(struct device *dev,
42601diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
42602index e28a494..f7c2671 100644
42603--- a/drivers/infiniband/core/cm.c
42604+++ b/drivers/infiniband/core/cm.c
42605@@ -115,7 +115,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
42606
42607 struct cm_counter_group {
42608 struct kobject obj;
42609- atomic_long_t counter[CM_ATTR_COUNT];
42610+ atomic_long_unchecked_t counter[CM_ATTR_COUNT];
42611 };
42612
42613 struct cm_counter_attribute {
42614@@ -1398,7 +1398,7 @@ static void cm_dup_req_handler(struct cm_work *work,
42615 struct ib_mad_send_buf *msg = NULL;
42616 int ret;
42617
42618- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42619+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42620 counter[CM_REQ_COUNTER]);
42621
42622 /* Quick state check to discard duplicate REQs. */
42623@@ -1785,7 +1785,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
42624 if (!cm_id_priv)
42625 return;
42626
42627- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42628+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42629 counter[CM_REP_COUNTER]);
42630 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
42631 if (ret)
42632@@ -1952,7 +1952,7 @@ static int cm_rtu_handler(struct cm_work *work)
42633 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
42634 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
42635 spin_unlock_irq(&cm_id_priv->lock);
42636- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42637+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42638 counter[CM_RTU_COUNTER]);
42639 goto out;
42640 }
42641@@ -2135,7 +2135,7 @@ static int cm_dreq_handler(struct cm_work *work)
42642 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
42643 dreq_msg->local_comm_id);
42644 if (!cm_id_priv) {
42645- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42646+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42647 counter[CM_DREQ_COUNTER]);
42648 cm_issue_drep(work->port, work->mad_recv_wc);
42649 return -EINVAL;
42650@@ -2160,7 +2160,7 @@ static int cm_dreq_handler(struct cm_work *work)
42651 case IB_CM_MRA_REP_RCVD:
42652 break;
42653 case IB_CM_TIMEWAIT:
42654- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42655+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42656 counter[CM_DREQ_COUNTER]);
42657 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
42658 goto unlock;
42659@@ -2174,7 +2174,7 @@ static int cm_dreq_handler(struct cm_work *work)
42660 cm_free_msg(msg);
42661 goto deref;
42662 case IB_CM_DREQ_RCVD:
42663- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42664+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42665 counter[CM_DREQ_COUNTER]);
42666 goto unlock;
42667 default:
42668@@ -2541,7 +2541,7 @@ static int cm_mra_handler(struct cm_work *work)
42669 ib_modify_mad(cm_id_priv->av.port->mad_agent,
42670 cm_id_priv->msg, timeout)) {
42671 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
42672- atomic_long_inc(&work->port->
42673+ atomic_long_inc_unchecked(&work->port->
42674 counter_group[CM_RECV_DUPLICATES].
42675 counter[CM_MRA_COUNTER]);
42676 goto out;
42677@@ -2550,7 +2550,7 @@ static int cm_mra_handler(struct cm_work *work)
42678 break;
42679 case IB_CM_MRA_REQ_RCVD:
42680 case IB_CM_MRA_REP_RCVD:
42681- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42682+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42683 counter[CM_MRA_COUNTER]);
42684 /* fall through */
42685 default:
42686@@ -2712,7 +2712,7 @@ static int cm_lap_handler(struct cm_work *work)
42687 case IB_CM_LAP_IDLE:
42688 break;
42689 case IB_CM_MRA_LAP_SENT:
42690- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42691+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42692 counter[CM_LAP_COUNTER]);
42693 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
42694 goto unlock;
42695@@ -2728,7 +2728,7 @@ static int cm_lap_handler(struct cm_work *work)
42696 cm_free_msg(msg);
42697 goto deref;
42698 case IB_CM_LAP_RCVD:
42699- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42700+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42701 counter[CM_LAP_COUNTER]);
42702 goto unlock;
42703 default:
42704@@ -3012,7 +3012,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
42705 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
42706 if (cur_cm_id_priv) {
42707 spin_unlock_irq(&cm.lock);
42708- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42709+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42710 counter[CM_SIDR_REQ_COUNTER]);
42711 goto out; /* Duplicate message. */
42712 }
42713@@ -3224,10 +3224,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
42714 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
42715 msg->retries = 1;
42716
42717- atomic_long_add(1 + msg->retries,
42718+ atomic_long_add_unchecked(1 + msg->retries,
42719 &port->counter_group[CM_XMIT].counter[attr_index]);
42720 if (msg->retries)
42721- atomic_long_add(msg->retries,
42722+ atomic_long_add_unchecked(msg->retries,
42723 &port->counter_group[CM_XMIT_RETRIES].
42724 counter[attr_index]);
42725
42726@@ -3437,7 +3437,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
42727 }
42728
42729 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
42730- atomic_long_inc(&port->counter_group[CM_RECV].
42731+ atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
42732 counter[attr_id - CM_ATTR_ID_OFFSET]);
42733
42734 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
42735@@ -3668,7 +3668,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
42736 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
42737
42738 return sprintf(buf, "%ld\n",
42739- atomic_long_read(&group->counter[cm_attr->index]));
42740+ atomic_long_read_unchecked(&group->counter[cm_attr->index]));
42741 }
42742
42743 static const struct sysfs_ops cm_counter_ops = {
42744diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
42745index 9f5ad7c..588cd84 100644
42746--- a/drivers/infiniband/core/fmr_pool.c
42747+++ b/drivers/infiniband/core/fmr_pool.c
42748@@ -98,8 +98,8 @@ struct ib_fmr_pool {
42749
42750 struct task_struct *thread;
42751
42752- atomic_t req_ser;
42753- atomic_t flush_ser;
42754+ atomic_unchecked_t req_ser;
42755+ atomic_unchecked_t flush_ser;
42756
42757 wait_queue_head_t force_wait;
42758 };
42759@@ -179,10 +179,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
42760 struct ib_fmr_pool *pool = pool_ptr;
42761
42762 do {
42763- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
42764+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
42765 ib_fmr_batch_release(pool);
42766
42767- atomic_inc(&pool->flush_ser);
42768+ atomic_inc_unchecked(&pool->flush_ser);
42769 wake_up_interruptible(&pool->force_wait);
42770
42771 if (pool->flush_function)
42772@@ -190,7 +190,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
42773 }
42774
42775 set_current_state(TASK_INTERRUPTIBLE);
42776- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
42777+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
42778 !kthread_should_stop())
42779 schedule();
42780 __set_current_state(TASK_RUNNING);
42781@@ -282,8 +282,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
42782 pool->dirty_watermark = params->dirty_watermark;
42783 pool->dirty_len = 0;
42784 spin_lock_init(&pool->pool_lock);
42785- atomic_set(&pool->req_ser, 0);
42786- atomic_set(&pool->flush_ser, 0);
42787+ atomic_set_unchecked(&pool->req_ser, 0);
42788+ atomic_set_unchecked(&pool->flush_ser, 0);
42789 init_waitqueue_head(&pool->force_wait);
42790
42791 pool->thread = kthread_run(ib_fmr_cleanup_thread,
42792@@ -411,11 +411,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
42793 }
42794 spin_unlock_irq(&pool->pool_lock);
42795
42796- serial = atomic_inc_return(&pool->req_ser);
42797+ serial = atomic_inc_return_unchecked(&pool->req_ser);
42798 wake_up_process(pool->thread);
42799
42800 if (wait_event_interruptible(pool->force_wait,
42801- atomic_read(&pool->flush_ser) - serial >= 0))
42802+ atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
42803 return -EINTR;
42804
42805 return 0;
42806@@ -525,7 +525,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
42807 } else {
42808 list_add_tail(&fmr->list, &pool->dirty_list);
42809 if (++pool->dirty_len >= pool->dirty_watermark) {
42810- atomic_inc(&pool->req_ser);
42811+ atomic_inc_unchecked(&pool->req_ser);
42812 wake_up_process(pool->thread);
42813 }
42814 }
42815diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
42816index ec7a298..8742e59 100644
42817--- a/drivers/infiniband/hw/cxgb4/mem.c
42818+++ b/drivers/infiniband/hw/cxgb4/mem.c
42819@@ -249,7 +249,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
42820 int err;
42821 struct fw_ri_tpte tpt;
42822 u32 stag_idx;
42823- static atomic_t key;
42824+ static atomic_unchecked_t key;
42825
42826 if (c4iw_fatal_error(rdev))
42827 return -EIO;
42828@@ -270,7 +270,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
42829 if (rdev->stats.stag.cur > rdev->stats.stag.max)
42830 rdev->stats.stag.max = rdev->stats.stag.cur;
42831 mutex_unlock(&rdev->stats.lock);
42832- *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
42833+ *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
42834 }
42835 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
42836 __func__, stag_state, type, pdid, stag_idx);
42837diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
42838index 79b3dbc..96e5fcc 100644
42839--- a/drivers/infiniband/hw/ipath/ipath_rc.c
42840+++ b/drivers/infiniband/hw/ipath/ipath_rc.c
42841@@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
42842 struct ib_atomic_eth *ateth;
42843 struct ipath_ack_entry *e;
42844 u64 vaddr;
42845- atomic64_t *maddr;
42846+ atomic64_unchecked_t *maddr;
42847 u64 sdata;
42848 u32 rkey;
42849 u8 next;
42850@@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
42851 IB_ACCESS_REMOTE_ATOMIC)))
42852 goto nack_acc_unlck;
42853 /* Perform atomic OP and save result. */
42854- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
42855+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
42856 sdata = be64_to_cpu(ateth->swap_data);
42857 e = &qp->s_ack_queue[qp->r_head_ack_queue];
42858 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
42859- (u64) atomic64_add_return(sdata, maddr) - sdata :
42860+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
42861 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
42862 be64_to_cpu(ateth->compare_data),
42863 sdata);
42864diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
42865index 1f95bba..9530f87 100644
42866--- a/drivers/infiniband/hw/ipath/ipath_ruc.c
42867+++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
42868@@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
42869 unsigned long flags;
42870 struct ib_wc wc;
42871 u64 sdata;
42872- atomic64_t *maddr;
42873+ atomic64_unchecked_t *maddr;
42874 enum ib_wc_status send_status;
42875
42876 /*
42877@@ -382,11 +382,11 @@ again:
42878 IB_ACCESS_REMOTE_ATOMIC)))
42879 goto acc_err;
42880 /* Perform atomic OP and save result. */
42881- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
42882+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
42883 sdata = wqe->wr.wr.atomic.compare_add;
42884 *(u64 *) sqp->s_sge.sge.vaddr =
42885 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
42886- (u64) atomic64_add_return(sdata, maddr) - sdata :
42887+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
42888 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
42889 sdata, wqe->wr.wr.atomic.swap);
42890 goto send_comp;
42891diff --git a/drivers/infiniband/hw/mlx4/mad.c b/drivers/infiniband/hw/mlx4/mad.c
42892index 82a7dd8..8fb6ba6 100644
42893--- a/drivers/infiniband/hw/mlx4/mad.c
42894+++ b/drivers/infiniband/hw/mlx4/mad.c
42895@@ -98,7 +98,7 @@ __be64 mlx4_ib_gen_node_guid(void)
42896
42897 __be64 mlx4_ib_get_new_demux_tid(struct mlx4_ib_demux_ctx *ctx)
42898 {
42899- return cpu_to_be64(atomic_inc_return(&ctx->tid)) |
42900+ return cpu_to_be64(atomic_inc_return_unchecked(&ctx->tid)) |
42901 cpu_to_be64(0xff00000000000000LL);
42902 }
42903
42904diff --git a/drivers/infiniband/hw/mlx4/mcg.c b/drivers/infiniband/hw/mlx4/mcg.c
42905index ed327e6..ca1739e0 100644
42906--- a/drivers/infiniband/hw/mlx4/mcg.c
42907+++ b/drivers/infiniband/hw/mlx4/mcg.c
42908@@ -1041,7 +1041,7 @@ int mlx4_ib_mcg_port_init(struct mlx4_ib_demux_ctx *ctx)
42909 {
42910 char name[20];
42911
42912- atomic_set(&ctx->tid, 0);
42913+ atomic_set_unchecked(&ctx->tid, 0);
42914 sprintf(name, "mlx4_ib_mcg%d", ctx->port);
42915 ctx->mcg_wq = create_singlethread_workqueue(name);
42916 if (!ctx->mcg_wq)
42917diff --git a/drivers/infiniband/hw/mlx4/mlx4_ib.h b/drivers/infiniband/hw/mlx4/mlx4_ib.h
42918index 6eb743f..a7b0f6d 100644
42919--- a/drivers/infiniband/hw/mlx4/mlx4_ib.h
42920+++ b/drivers/infiniband/hw/mlx4/mlx4_ib.h
42921@@ -426,7 +426,7 @@ struct mlx4_ib_demux_ctx {
42922 struct list_head mcg_mgid0_list;
42923 struct workqueue_struct *mcg_wq;
42924 struct mlx4_ib_demux_pv_ctx **tun;
42925- atomic_t tid;
42926+ atomic_unchecked_t tid;
42927 int flushing; /* flushing the work queue */
42928 };
42929
42930diff --git a/drivers/infiniband/hw/mthca/mthca_cmd.c b/drivers/infiniband/hw/mthca/mthca_cmd.c
42931index 9d3e5c1..6f166df 100644
42932--- a/drivers/infiniband/hw/mthca/mthca_cmd.c
42933+++ b/drivers/infiniband/hw/mthca/mthca_cmd.c
42934@@ -772,7 +772,7 @@ static void mthca_setup_cmd_doorbells(struct mthca_dev *dev, u64 base)
42935 mthca_dbg(dev, "Mapped doorbell page for posting FW commands\n");
42936 }
42937
42938-int mthca_QUERY_FW(struct mthca_dev *dev)
42939+int __intentional_overflow(-1) mthca_QUERY_FW(struct mthca_dev *dev)
42940 {
42941 struct mthca_mailbox *mailbox;
42942 u32 *outbox;
42943@@ -1612,7 +1612,7 @@ int mthca_HW2SW_MPT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42944 CMD_TIME_CLASS_B);
42945 }
42946
42947-int mthca_WRITE_MTT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42948+int __intentional_overflow(-1) mthca_WRITE_MTT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42949 int num_mtt)
42950 {
42951 return mthca_cmd(dev, mailbox->dma, num_mtt, 0, CMD_WRITE_MTT,
42952@@ -1634,7 +1634,7 @@ int mthca_MAP_EQ(struct mthca_dev *dev, u64 event_mask, int unmap,
42953 0, CMD_MAP_EQ, CMD_TIME_CLASS_B);
42954 }
42955
42956-int mthca_SW2HW_EQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42957+int __intentional_overflow(-1) mthca_SW2HW_EQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42958 int eq_num)
42959 {
42960 return mthca_cmd(dev, mailbox->dma, eq_num, 0, CMD_SW2HW_EQ,
42961@@ -1857,7 +1857,7 @@ int mthca_CONF_SPECIAL_QP(struct mthca_dev *dev, int type, u32 qpn)
42962 CMD_TIME_CLASS_B);
42963 }
42964
42965-int mthca_MAD_IFC(struct mthca_dev *dev, int ignore_mkey, int ignore_bkey,
42966+int __intentional_overflow(-1) mthca_MAD_IFC(struct mthca_dev *dev, int ignore_mkey, int ignore_bkey,
42967 int port, struct ib_wc *in_wc, struct ib_grh *in_grh,
42968 void *in_mad, void *response_mad)
42969 {
42970diff --git a/drivers/infiniband/hw/mthca/mthca_main.c b/drivers/infiniband/hw/mthca/mthca_main.c
42971index ded76c1..0cf0a08 100644
42972--- a/drivers/infiniband/hw/mthca/mthca_main.c
42973+++ b/drivers/infiniband/hw/mthca/mthca_main.c
42974@@ -692,7 +692,7 @@ err_close:
42975 return err;
42976 }
42977
42978-static int mthca_setup_hca(struct mthca_dev *dev)
42979+static int __intentional_overflow(-1) mthca_setup_hca(struct mthca_dev *dev)
42980 {
42981 int err;
42982
42983diff --git a/drivers/infiniband/hw/mthca/mthca_mr.c b/drivers/infiniband/hw/mthca/mthca_mr.c
42984index ed9a989..6aa5dc2 100644
42985--- a/drivers/infiniband/hw/mthca/mthca_mr.c
42986+++ b/drivers/infiniband/hw/mthca/mthca_mr.c
42987@@ -81,7 +81,7 @@ struct mthca_mpt_entry {
42988 * through the bitmaps)
42989 */
42990
42991-static u32 mthca_buddy_alloc(struct mthca_buddy *buddy, int order)
42992+static u32 __intentional_overflow(-1) mthca_buddy_alloc(struct mthca_buddy *buddy, int order)
42993 {
42994 int o;
42995 int m;
42996@@ -426,7 +426,7 @@ static inline u32 adjust_key(struct mthca_dev *dev, u32 key)
42997 return key;
42998 }
42999
43000-int mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
43001+int __intentional_overflow(-1) mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
43002 u64 iova, u64 total_size, u32 access, struct mthca_mr *mr)
43003 {
43004 struct mthca_mailbox *mailbox;
43005@@ -516,7 +516,7 @@ int mthca_mr_alloc_notrans(struct mthca_dev *dev, u32 pd,
43006 return mthca_mr_alloc(dev, pd, 12, 0, ~0ULL, access, mr);
43007 }
43008
43009-int mthca_mr_alloc_phys(struct mthca_dev *dev, u32 pd,
43010+int __intentional_overflow(-1) mthca_mr_alloc_phys(struct mthca_dev *dev, u32 pd,
43011 u64 *buffer_list, int buffer_size_shift,
43012 int list_len, u64 iova, u64 total_size,
43013 u32 access, struct mthca_mr *mr)
43014diff --git a/drivers/infiniband/hw/mthca/mthca_provider.c b/drivers/infiniband/hw/mthca/mthca_provider.c
43015index 415f8e1..e34214e 100644
43016--- a/drivers/infiniband/hw/mthca/mthca_provider.c
43017+++ b/drivers/infiniband/hw/mthca/mthca_provider.c
43018@@ -764,7 +764,7 @@ unlock:
43019 return 0;
43020 }
43021
43022-static int mthca_resize_cq(struct ib_cq *ibcq, int entries, struct ib_udata *udata)
43023+static int __intentional_overflow(-1) mthca_resize_cq(struct ib_cq *ibcq, int entries, struct ib_udata *udata)
43024 {
43025 struct mthca_dev *dev = to_mdev(ibcq->device);
43026 struct mthca_cq *cq = to_mcq(ibcq);
43027diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
43028index 3b2a6dc..bce26ff 100644
43029--- a/drivers/infiniband/hw/nes/nes.c
43030+++ b/drivers/infiniband/hw/nes/nes.c
43031@@ -97,7 +97,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
43032 LIST_HEAD(nes_adapter_list);
43033 static LIST_HEAD(nes_dev_list);
43034
43035-atomic_t qps_destroyed;
43036+atomic_unchecked_t qps_destroyed;
43037
43038 static unsigned int ee_flsh_adapter;
43039 static unsigned int sysfs_nonidx_addr;
43040@@ -278,7 +278,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
43041 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
43042 struct nes_adapter *nesadapter = nesdev->nesadapter;
43043
43044- atomic_inc(&qps_destroyed);
43045+ atomic_inc_unchecked(&qps_destroyed);
43046
43047 /* Free the control structures */
43048
43049diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
43050index bd9d132..70d84f4 100644
43051--- a/drivers/infiniband/hw/nes/nes.h
43052+++ b/drivers/infiniband/hw/nes/nes.h
43053@@ -180,17 +180,17 @@ extern unsigned int nes_debug_level;
43054 extern unsigned int wqm_quanta;
43055 extern struct list_head nes_adapter_list;
43056
43057-extern atomic_t cm_connects;
43058-extern atomic_t cm_accepts;
43059-extern atomic_t cm_disconnects;
43060-extern atomic_t cm_closes;
43061-extern atomic_t cm_connecteds;
43062-extern atomic_t cm_connect_reqs;
43063-extern atomic_t cm_rejects;
43064-extern atomic_t mod_qp_timouts;
43065-extern atomic_t qps_created;
43066-extern atomic_t qps_destroyed;
43067-extern atomic_t sw_qps_destroyed;
43068+extern atomic_unchecked_t cm_connects;
43069+extern atomic_unchecked_t cm_accepts;
43070+extern atomic_unchecked_t cm_disconnects;
43071+extern atomic_unchecked_t cm_closes;
43072+extern atomic_unchecked_t cm_connecteds;
43073+extern atomic_unchecked_t cm_connect_reqs;
43074+extern atomic_unchecked_t cm_rejects;
43075+extern atomic_unchecked_t mod_qp_timouts;
43076+extern atomic_unchecked_t qps_created;
43077+extern atomic_unchecked_t qps_destroyed;
43078+extern atomic_unchecked_t sw_qps_destroyed;
43079 extern u32 mh_detected;
43080 extern u32 mh_pauses_sent;
43081 extern u32 cm_packets_sent;
43082@@ -199,16 +199,16 @@ extern u32 cm_packets_created;
43083 extern u32 cm_packets_received;
43084 extern u32 cm_packets_dropped;
43085 extern u32 cm_packets_retrans;
43086-extern atomic_t cm_listens_created;
43087-extern atomic_t cm_listens_destroyed;
43088+extern atomic_unchecked_t cm_listens_created;
43089+extern atomic_unchecked_t cm_listens_destroyed;
43090 extern u32 cm_backlog_drops;
43091-extern atomic_t cm_loopbacks;
43092-extern atomic_t cm_nodes_created;
43093-extern atomic_t cm_nodes_destroyed;
43094-extern atomic_t cm_accel_dropped_pkts;
43095-extern atomic_t cm_resets_recvd;
43096-extern atomic_t pau_qps_created;
43097-extern atomic_t pau_qps_destroyed;
43098+extern atomic_unchecked_t cm_loopbacks;
43099+extern atomic_unchecked_t cm_nodes_created;
43100+extern atomic_unchecked_t cm_nodes_destroyed;
43101+extern atomic_unchecked_t cm_accel_dropped_pkts;
43102+extern atomic_unchecked_t cm_resets_recvd;
43103+extern atomic_unchecked_t pau_qps_created;
43104+extern atomic_unchecked_t pau_qps_destroyed;
43105
43106 extern u32 int_mod_timer_init;
43107 extern u32 int_mod_cq_depth_256;
43108diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
43109index 6f09a72..cf4399d 100644
43110--- a/drivers/infiniband/hw/nes/nes_cm.c
43111+++ b/drivers/infiniband/hw/nes/nes_cm.c
43112@@ -69,14 +69,14 @@ u32 cm_packets_dropped;
43113 u32 cm_packets_retrans;
43114 u32 cm_packets_created;
43115 u32 cm_packets_received;
43116-atomic_t cm_listens_created;
43117-atomic_t cm_listens_destroyed;
43118+atomic_unchecked_t cm_listens_created;
43119+atomic_unchecked_t cm_listens_destroyed;
43120 u32 cm_backlog_drops;
43121-atomic_t cm_loopbacks;
43122-atomic_t cm_nodes_created;
43123-atomic_t cm_nodes_destroyed;
43124-atomic_t cm_accel_dropped_pkts;
43125-atomic_t cm_resets_recvd;
43126+atomic_unchecked_t cm_loopbacks;
43127+atomic_unchecked_t cm_nodes_created;
43128+atomic_unchecked_t cm_nodes_destroyed;
43129+atomic_unchecked_t cm_accel_dropped_pkts;
43130+atomic_unchecked_t cm_resets_recvd;
43131
43132 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
43133 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
43134@@ -135,28 +135,28 @@ static void record_ird_ord(struct nes_cm_node *, u16, u16);
43135 /* instance of function pointers for client API */
43136 /* set address of this instance to cm_core->cm_ops at cm_core alloc */
43137 static struct nes_cm_ops nes_cm_api = {
43138- mini_cm_accelerated,
43139- mini_cm_listen,
43140- mini_cm_del_listen,
43141- mini_cm_connect,
43142- mini_cm_close,
43143- mini_cm_accept,
43144- mini_cm_reject,
43145- mini_cm_recv_pkt,
43146- mini_cm_dealloc_core,
43147- mini_cm_get,
43148- mini_cm_set
43149+ .accelerated = mini_cm_accelerated,
43150+ .listen = mini_cm_listen,
43151+ .stop_listener = mini_cm_del_listen,
43152+ .connect = mini_cm_connect,
43153+ .close = mini_cm_close,
43154+ .accept = mini_cm_accept,
43155+ .reject = mini_cm_reject,
43156+ .recv_pkt = mini_cm_recv_pkt,
43157+ .destroy_cm_core = mini_cm_dealloc_core,
43158+ .get = mini_cm_get,
43159+ .set = mini_cm_set
43160 };
43161
43162 static struct nes_cm_core *g_cm_core;
43163
43164-atomic_t cm_connects;
43165-atomic_t cm_accepts;
43166-atomic_t cm_disconnects;
43167-atomic_t cm_closes;
43168-atomic_t cm_connecteds;
43169-atomic_t cm_connect_reqs;
43170-atomic_t cm_rejects;
43171+atomic_unchecked_t cm_connects;
43172+atomic_unchecked_t cm_accepts;
43173+atomic_unchecked_t cm_disconnects;
43174+atomic_unchecked_t cm_closes;
43175+atomic_unchecked_t cm_connecteds;
43176+atomic_unchecked_t cm_connect_reqs;
43177+atomic_unchecked_t cm_rejects;
43178
43179 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
43180 {
43181@@ -1436,7 +1436,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
43182 kfree(listener);
43183 listener = NULL;
43184 ret = 0;
43185- atomic_inc(&cm_listens_destroyed);
43186+ atomic_inc_unchecked(&cm_listens_destroyed);
43187 } else {
43188 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
43189 }
43190@@ -1637,7 +1637,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
43191 cm_node->rem_mac);
43192
43193 add_hte_node(cm_core, cm_node);
43194- atomic_inc(&cm_nodes_created);
43195+ atomic_inc_unchecked(&cm_nodes_created);
43196
43197 return cm_node;
43198 }
43199@@ -1698,7 +1698,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
43200 }
43201
43202 atomic_dec(&cm_core->node_cnt);
43203- atomic_inc(&cm_nodes_destroyed);
43204+ atomic_inc_unchecked(&cm_nodes_destroyed);
43205 nesqp = cm_node->nesqp;
43206 if (nesqp) {
43207 nesqp->cm_node = NULL;
43208@@ -1762,7 +1762,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
43209
43210 static void drop_packet(struct sk_buff *skb)
43211 {
43212- atomic_inc(&cm_accel_dropped_pkts);
43213+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
43214 dev_kfree_skb_any(skb);
43215 }
43216
43217@@ -1825,7 +1825,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
43218 {
43219
43220 int reset = 0; /* whether to send reset in case of err.. */
43221- atomic_inc(&cm_resets_recvd);
43222+ atomic_inc_unchecked(&cm_resets_recvd);
43223 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
43224 " refcnt=%d\n", cm_node, cm_node->state,
43225 atomic_read(&cm_node->ref_count));
43226@@ -2492,7 +2492,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
43227 rem_ref_cm_node(cm_node->cm_core, cm_node);
43228 return NULL;
43229 }
43230- atomic_inc(&cm_loopbacks);
43231+ atomic_inc_unchecked(&cm_loopbacks);
43232 loopbackremotenode->loopbackpartner = cm_node;
43233 loopbackremotenode->tcp_cntxt.rcv_wscale =
43234 NES_CM_DEFAULT_RCV_WND_SCALE;
43235@@ -2773,7 +2773,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
43236 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
43237 else {
43238 rem_ref_cm_node(cm_core, cm_node);
43239- atomic_inc(&cm_accel_dropped_pkts);
43240+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
43241 dev_kfree_skb_any(skb);
43242 }
43243 break;
43244@@ -3081,7 +3081,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
43245
43246 if ((cm_id) && (cm_id->event_handler)) {
43247 if (issue_disconn) {
43248- atomic_inc(&cm_disconnects);
43249+ atomic_inc_unchecked(&cm_disconnects);
43250 cm_event.event = IW_CM_EVENT_DISCONNECT;
43251 cm_event.status = disconn_status;
43252 cm_event.local_addr = cm_id->local_addr;
43253@@ -3103,7 +3103,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
43254 }
43255
43256 if (issue_close) {
43257- atomic_inc(&cm_closes);
43258+ atomic_inc_unchecked(&cm_closes);
43259 nes_disconnect(nesqp, 1);
43260
43261 cm_id->provider_data = nesqp;
43262@@ -3241,7 +3241,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
43263
43264 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
43265 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
43266- atomic_inc(&cm_accepts);
43267+ atomic_inc_unchecked(&cm_accepts);
43268
43269 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
43270 netdev_refcnt_read(nesvnic->netdev));
43271@@ -3439,7 +3439,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
43272 struct nes_cm_core *cm_core;
43273 u8 *start_buff;
43274
43275- atomic_inc(&cm_rejects);
43276+ atomic_inc_unchecked(&cm_rejects);
43277 cm_node = (struct nes_cm_node *)cm_id->provider_data;
43278 loopback = cm_node->loopbackpartner;
43279 cm_core = cm_node->cm_core;
43280@@ -3504,7 +3504,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
43281 ntohs(raddr->sin_port), ntohl(laddr->sin_addr.s_addr),
43282 ntohs(laddr->sin_port));
43283
43284- atomic_inc(&cm_connects);
43285+ atomic_inc_unchecked(&cm_connects);
43286 nesqp->active_conn = 1;
43287
43288 /* cache the cm_id in the qp */
43289@@ -3649,7 +3649,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
43290 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
43291 return err;
43292 }
43293- atomic_inc(&cm_listens_created);
43294+ atomic_inc_unchecked(&cm_listens_created);
43295 }
43296
43297 cm_id->add_ref(cm_id);
43298@@ -3756,7 +3756,7 @@ static void cm_event_connected(struct nes_cm_event *event)
43299
43300 if (nesqp->destroyed)
43301 return;
43302- atomic_inc(&cm_connecteds);
43303+ atomic_inc_unchecked(&cm_connecteds);
43304 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
43305 " local port 0x%04X. jiffies = %lu.\n",
43306 nesqp->hwqp.qp_id, ntohl(raddr->sin_addr.s_addr),
43307@@ -3941,7 +3941,7 @@ static void cm_event_reset(struct nes_cm_event *event)
43308
43309 cm_id->add_ref(cm_id);
43310 ret = cm_id->event_handler(cm_id, &cm_event);
43311- atomic_inc(&cm_closes);
43312+ atomic_inc_unchecked(&cm_closes);
43313 cm_event.event = IW_CM_EVENT_CLOSE;
43314 cm_event.status = 0;
43315 cm_event.provider_data = cm_id->provider_data;
43316@@ -3981,7 +3981,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
43317 return;
43318 cm_id = cm_node->cm_id;
43319
43320- atomic_inc(&cm_connect_reqs);
43321+ atomic_inc_unchecked(&cm_connect_reqs);
43322 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
43323 cm_node, cm_id, jiffies);
43324
43325@@ -4030,7 +4030,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
43326 return;
43327 cm_id = cm_node->cm_id;
43328
43329- atomic_inc(&cm_connect_reqs);
43330+ atomic_inc_unchecked(&cm_connect_reqs);
43331 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
43332 cm_node, cm_id, jiffies);
43333
43334diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
43335index 4166452..fc952c3 100644
43336--- a/drivers/infiniband/hw/nes/nes_mgt.c
43337+++ b/drivers/infiniband/hw/nes/nes_mgt.c
43338@@ -40,8 +40,8 @@
43339 #include "nes.h"
43340 #include "nes_mgt.h"
43341
43342-atomic_t pau_qps_created;
43343-atomic_t pau_qps_destroyed;
43344+atomic_unchecked_t pau_qps_created;
43345+atomic_unchecked_t pau_qps_destroyed;
43346
43347 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
43348 {
43349@@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
43350 {
43351 struct sk_buff *skb;
43352 unsigned long flags;
43353- atomic_inc(&pau_qps_destroyed);
43354+ atomic_inc_unchecked(&pau_qps_destroyed);
43355
43356 /* Free packets that have not yet been forwarded */
43357 /* Lock is acquired by skb_dequeue when removing the skb */
43358@@ -810,7 +810,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
43359 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
43360 skb_queue_head_init(&nesqp->pau_list);
43361 spin_lock_init(&nesqp->pau_lock);
43362- atomic_inc(&pau_qps_created);
43363+ atomic_inc_unchecked(&pau_qps_created);
43364 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
43365 }
43366
43367diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
43368index 49eb511..a774366 100644
43369--- a/drivers/infiniband/hw/nes/nes_nic.c
43370+++ b/drivers/infiniband/hw/nes/nes_nic.c
43371@@ -1273,39 +1273,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
43372 target_stat_values[++index] = mh_detected;
43373 target_stat_values[++index] = mh_pauses_sent;
43374 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
43375- target_stat_values[++index] = atomic_read(&cm_connects);
43376- target_stat_values[++index] = atomic_read(&cm_accepts);
43377- target_stat_values[++index] = atomic_read(&cm_disconnects);
43378- target_stat_values[++index] = atomic_read(&cm_connecteds);
43379- target_stat_values[++index] = atomic_read(&cm_connect_reqs);
43380- target_stat_values[++index] = atomic_read(&cm_rejects);
43381- target_stat_values[++index] = atomic_read(&mod_qp_timouts);
43382- target_stat_values[++index] = atomic_read(&qps_created);
43383- target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
43384- target_stat_values[++index] = atomic_read(&qps_destroyed);
43385- target_stat_values[++index] = atomic_read(&cm_closes);
43386+ target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
43387+ target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
43388+ target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
43389+ target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
43390+ target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
43391+ target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
43392+ target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
43393+ target_stat_values[++index] = atomic_read_unchecked(&qps_created);
43394+ target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
43395+ target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
43396+ target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
43397 target_stat_values[++index] = cm_packets_sent;
43398 target_stat_values[++index] = cm_packets_bounced;
43399 target_stat_values[++index] = cm_packets_created;
43400 target_stat_values[++index] = cm_packets_received;
43401 target_stat_values[++index] = cm_packets_dropped;
43402 target_stat_values[++index] = cm_packets_retrans;
43403- target_stat_values[++index] = atomic_read(&cm_listens_created);
43404- target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
43405+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
43406+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
43407 target_stat_values[++index] = cm_backlog_drops;
43408- target_stat_values[++index] = atomic_read(&cm_loopbacks);
43409- target_stat_values[++index] = atomic_read(&cm_nodes_created);
43410- target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
43411- target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
43412- target_stat_values[++index] = atomic_read(&cm_resets_recvd);
43413+ target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
43414+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
43415+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
43416+ target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
43417+ target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
43418 target_stat_values[++index] = nesadapter->free_4kpbl;
43419 target_stat_values[++index] = nesadapter->free_256pbl;
43420 target_stat_values[++index] = int_mod_timer_init;
43421 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
43422 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
43423 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
43424- target_stat_values[++index] = atomic_read(&pau_qps_created);
43425- target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
43426+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
43427+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
43428 }
43429
43430 /**
43431diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
43432index fef067c..6a25ccd 100644
43433--- a/drivers/infiniband/hw/nes/nes_verbs.c
43434+++ b/drivers/infiniband/hw/nes/nes_verbs.c
43435@@ -46,9 +46,9 @@
43436
43437 #include <rdma/ib_umem.h>
43438
43439-atomic_t mod_qp_timouts;
43440-atomic_t qps_created;
43441-atomic_t sw_qps_destroyed;
43442+atomic_unchecked_t mod_qp_timouts;
43443+atomic_unchecked_t qps_created;
43444+atomic_unchecked_t sw_qps_destroyed;
43445
43446 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
43447
43448@@ -1134,7 +1134,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
43449 if (init_attr->create_flags)
43450 return ERR_PTR(-EINVAL);
43451
43452- atomic_inc(&qps_created);
43453+ atomic_inc_unchecked(&qps_created);
43454 switch (init_attr->qp_type) {
43455 case IB_QPT_RC:
43456 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
43457@@ -1468,7 +1468,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
43458 struct iw_cm_event cm_event;
43459 int ret = 0;
43460
43461- atomic_inc(&sw_qps_destroyed);
43462+ atomic_inc_unchecked(&sw_qps_destroyed);
43463 nesqp->destroyed = 1;
43464
43465 /* Blow away the connection if it exists. */
43466diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
43467index c00ae09..04e91be 100644
43468--- a/drivers/infiniband/hw/qib/qib.h
43469+++ b/drivers/infiniband/hw/qib/qib.h
43470@@ -52,6 +52,7 @@
43471 #include <linux/kref.h>
43472 #include <linux/sched.h>
43473 #include <linux/kthread.h>
43474+#include <linux/slab.h>
43475
43476 #include "qib_common.h"
43477 #include "qib_verbs.h"
43478diff --git a/drivers/infiniband/ulp/ipoib/ipoib_netlink.c b/drivers/infiniband/ulp/ipoib/ipoib_netlink.c
43479index cdc7df4..a2fdfdb 100644
43480--- a/drivers/infiniband/ulp/ipoib/ipoib_netlink.c
43481+++ b/drivers/infiniband/ulp/ipoib/ipoib_netlink.c
43482@@ -156,7 +156,7 @@ static size_t ipoib_get_size(const struct net_device *dev)
43483 nla_total_size(2); /* IFLA_IPOIB_UMCAST */
43484 }
43485
43486-static struct rtnl_link_ops ipoib_link_ops __read_mostly = {
43487+static struct rtnl_link_ops ipoib_link_ops = {
43488 .kind = "ipoib",
43489 .maxtype = IFLA_IPOIB_MAX,
43490 .policy = ipoib_policy,
43491diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
43492index e29c04e..adbf68c 100644
43493--- a/drivers/input/gameport/gameport.c
43494+++ b/drivers/input/gameport/gameport.c
43495@@ -527,14 +527,14 @@ EXPORT_SYMBOL(gameport_set_phys);
43496 */
43497 static void gameport_init_port(struct gameport *gameport)
43498 {
43499- static atomic_t gameport_no = ATOMIC_INIT(0);
43500+ static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
43501
43502 __module_get(THIS_MODULE);
43503
43504 mutex_init(&gameport->drv_mutex);
43505 device_initialize(&gameport->dev);
43506 dev_set_name(&gameport->dev, "gameport%lu",
43507- (unsigned long)atomic_inc_return(&gameport_no) - 1);
43508+ (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
43509 gameport->dev.bus = &gameport_bus;
43510 gameport->dev.release = gameport_release_port;
43511 if (gameport->parent)
43512diff --git a/drivers/input/input.c b/drivers/input/input.c
43513index 0f175f5..4c481c0 100644
43514--- a/drivers/input/input.c
43515+++ b/drivers/input/input.c
43516@@ -1775,7 +1775,7 @@ EXPORT_SYMBOL_GPL(input_class);
43517 */
43518 struct input_dev *input_allocate_device(void)
43519 {
43520- static atomic_t input_no = ATOMIC_INIT(0);
43521+ static atomic_unchecked_t input_no = ATOMIC_INIT(0);
43522 struct input_dev *dev;
43523
43524 dev = kzalloc(sizeof(struct input_dev), GFP_KERNEL);
43525@@ -1790,7 +1790,7 @@ struct input_dev *input_allocate_device(void)
43526 INIT_LIST_HEAD(&dev->node);
43527
43528 dev_set_name(&dev->dev, "input%lu",
43529- (unsigned long) atomic_inc_return(&input_no) - 1);
43530+ (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
43531
43532 __module_get(THIS_MODULE);
43533 }
43534diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
43535index 4a95b22..874c182 100644
43536--- a/drivers/input/joystick/sidewinder.c
43537+++ b/drivers/input/joystick/sidewinder.c
43538@@ -30,6 +30,7 @@
43539 #include <linux/kernel.h>
43540 #include <linux/module.h>
43541 #include <linux/slab.h>
43542+#include <linux/sched.h>
43543 #include <linux/input.h>
43544 #include <linux/gameport.h>
43545 #include <linux/jiffies.h>
43546diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
43547index fc55f0d..11e2aa6 100644
43548--- a/drivers/input/joystick/xpad.c
43549+++ b/drivers/input/joystick/xpad.c
43550@@ -886,7 +886,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
43551
43552 static int xpad_led_probe(struct usb_xpad *xpad)
43553 {
43554- static atomic_t led_seq = ATOMIC_INIT(0);
43555+ static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
43556 long led_no;
43557 struct xpad_led *led;
43558 struct led_classdev *led_cdev;
43559@@ -899,7 +899,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
43560 if (!led)
43561 return -ENOMEM;
43562
43563- led_no = (long)atomic_inc_return(&led_seq) - 1;
43564+ led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
43565
43566 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
43567 led->xpad = xpad;
43568diff --git a/drivers/input/misc/ims-pcu.c b/drivers/input/misc/ims-pcu.c
43569index afed8e2..3aa8a18 100644
43570--- a/drivers/input/misc/ims-pcu.c
43571+++ b/drivers/input/misc/ims-pcu.c
43572@@ -1851,7 +1851,7 @@ static int ims_pcu_identify_type(struct ims_pcu *pcu, u8 *device_id)
43573
43574 static int ims_pcu_init_application_mode(struct ims_pcu *pcu)
43575 {
43576- static atomic_t device_no = ATOMIC_INIT(0);
43577+ static atomic_unchecked_t device_no = ATOMIC_INIT(0);
43578
43579 const struct ims_pcu_device_info *info;
43580 int error;
43581@@ -1882,7 +1882,7 @@ static int ims_pcu_init_application_mode(struct ims_pcu *pcu)
43582 }
43583
43584 /* Device appears to be operable, complete initialization */
43585- pcu->device_no = atomic_inc_return(&device_no) - 1;
43586+ pcu->device_no = atomic_inc_return_unchecked(&device_no) - 1;
43587
43588 /*
43589 * PCU-B devices, both GEN_1 and GEN_2 do not have OFN sensor
43590diff --git a/drivers/input/mouse/psmouse.h b/drivers/input/mouse/psmouse.h
43591index f4cf664..3204fda 100644
43592--- a/drivers/input/mouse/psmouse.h
43593+++ b/drivers/input/mouse/psmouse.h
43594@@ -117,7 +117,7 @@ struct psmouse_attribute {
43595 ssize_t (*set)(struct psmouse *psmouse, void *data,
43596 const char *buf, size_t count);
43597 bool protect;
43598-};
43599+} __do_const;
43600 #define to_psmouse_attr(a) container_of((a), struct psmouse_attribute, dattr)
43601
43602 ssize_t psmouse_attr_show_helper(struct device *dev, struct device_attribute *attr,
43603diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
43604index b604564..3f14ae4 100644
43605--- a/drivers/input/mousedev.c
43606+++ b/drivers/input/mousedev.c
43607@@ -744,7 +744,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
43608
43609 spin_unlock_irq(&client->packet_lock);
43610
43611- if (copy_to_user(buffer, data, count))
43612+ if (count > sizeof(data) || copy_to_user(buffer, data, count))
43613 return -EFAULT;
43614
43615 return count;
43616diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
43617index d399b8b..4913ede 100644
43618--- a/drivers/input/serio/serio.c
43619+++ b/drivers/input/serio/serio.c
43620@@ -514,7 +514,7 @@ static void serio_release_port(struct device *dev)
43621 */
43622 static void serio_init_port(struct serio *serio)
43623 {
43624- static atomic_t serio_no = ATOMIC_INIT(0);
43625+ static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
43626
43627 __module_get(THIS_MODULE);
43628
43629@@ -525,7 +525,7 @@ static void serio_init_port(struct serio *serio)
43630 mutex_init(&serio->drv_mutex);
43631 device_initialize(&serio->dev);
43632 dev_set_name(&serio->dev, "serio%lu",
43633- (unsigned long)atomic_inc_return(&serio_no) - 1);
43634+ (unsigned long)atomic_inc_return_unchecked(&serio_no) - 1);
43635 serio->dev.bus = &serio_bus;
43636 serio->dev.release = serio_release_port;
43637 serio->dev.groups = serio_device_attr_groups;
43638diff --git a/drivers/input/serio/serio_raw.c b/drivers/input/serio/serio_raw.c
43639index c9a02fe..0debc75 100644
43640--- a/drivers/input/serio/serio_raw.c
43641+++ b/drivers/input/serio/serio_raw.c
43642@@ -292,7 +292,7 @@ static irqreturn_t serio_raw_interrupt(struct serio *serio, unsigned char data,
43643
43644 static int serio_raw_connect(struct serio *serio, struct serio_driver *drv)
43645 {
43646- static atomic_t serio_raw_no = ATOMIC_INIT(0);
43647+ static atomic_unchecked_t serio_raw_no = ATOMIC_INIT(0);
43648 struct serio_raw *serio_raw;
43649 int err;
43650
43651@@ -303,7 +303,7 @@ static int serio_raw_connect(struct serio *serio, struct serio_driver *drv)
43652 }
43653
43654 snprintf(serio_raw->name, sizeof(serio_raw->name),
43655- "serio_raw%ld", (long)atomic_inc_return(&serio_raw_no) - 1);
43656+ "serio_raw%ld", (long)atomic_inc_return_unchecked(&serio_raw_no) - 1);
43657 kref_init(&serio_raw->kref);
43658 INIT_LIST_HEAD(&serio_raw->client_list);
43659 init_waitqueue_head(&serio_raw->wait);
43660diff --git a/drivers/iommu/amd_iommu.c b/drivers/iommu/amd_iommu.c
43661index 505a9ad..f0b1b6e 100644
43662--- a/drivers/iommu/amd_iommu.c
43663+++ b/drivers/iommu/amd_iommu.c
43664@@ -823,11 +823,21 @@ static void copy_cmd_to_buffer(struct amd_iommu *iommu,
43665
43666 static void build_completion_wait(struct iommu_cmd *cmd, u64 address)
43667 {
43668+ phys_addr_t physaddr;
43669 WARN_ON(address & 0x7ULL);
43670
43671 memset(cmd, 0, sizeof(*cmd));
43672- cmd->data[0] = lower_32_bits(__pa(address)) | CMD_COMPL_WAIT_STORE_MASK;
43673- cmd->data[1] = upper_32_bits(__pa(address));
43674+
43675+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
43676+ if (object_starts_on_stack(address)) {
43677+ void *adjbuf = (void *)address - current->stack + current->lowmem_stack;
43678+ physaddr = __pa((u64)adjbuf);
43679+ } else
43680+#endif
43681+ physaddr = __pa(address);
43682+
43683+ cmd->data[0] = lower_32_bits(physaddr) | CMD_COMPL_WAIT_STORE_MASK;
43684+ cmd->data[1] = upper_32_bits(physaddr);
43685 cmd->data[2] = 1;
43686 CMD_SET_TYPE(cmd, CMD_COMPL_WAIT);
43687 }
43688diff --git a/drivers/iommu/arm-smmu.c b/drivers/iommu/arm-smmu.c
43689index 60558f7..5a02369 100644
43690--- a/drivers/iommu/arm-smmu.c
43691+++ b/drivers/iommu/arm-smmu.c
43692@@ -934,7 +934,7 @@ static int arm_smmu_init_domain_context(struct iommu_domain *domain,
43693 cfg->irptndx = cfg->cbndx;
43694 }
43695
43696- ACCESS_ONCE(smmu_domain->smmu) = smmu;
43697+ ACCESS_ONCE_RW(smmu_domain->smmu) = smmu;
43698 arm_smmu_init_context_bank(smmu_domain);
43699 spin_unlock_irqrestore(&smmu_domain->lock, flags);
43700
43701diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
43702index ed8b048..7fbcc01 100644
43703--- a/drivers/iommu/iommu.c
43704+++ b/drivers/iommu/iommu.c
43705@@ -802,7 +802,7 @@ static int iommu_bus_notifier(struct notifier_block *nb,
43706 static int iommu_bus_init(struct bus_type *bus, const struct iommu_ops *ops)
43707 {
43708 int err;
43709- struct notifier_block *nb;
43710+ notifier_block_no_const *nb;
43711 struct iommu_callback_data cb = {
43712 .ops = ops,
43713 };
43714diff --git a/drivers/iommu/irq_remapping.c b/drivers/iommu/irq_remapping.c
43715index 74a1767..5a359e8 100644
43716--- a/drivers/iommu/irq_remapping.c
43717+++ b/drivers/iommu/irq_remapping.c
43718@@ -361,7 +361,7 @@ int setup_hpet_msi_remapped(unsigned int irq, unsigned int id)
43719 void panic_if_irq_remap(const char *msg)
43720 {
43721 if (irq_remapping_enabled)
43722- panic(msg);
43723+ panic("%s", msg);
43724 }
43725
43726 static void ir_ack_apic_edge(struct irq_data *data)
43727@@ -382,10 +382,12 @@ static void ir_print_prefix(struct irq_data *data, struct seq_file *p)
43728
43729 void irq_remap_modify_chip_defaults(struct irq_chip *chip)
43730 {
43731- chip->irq_print_chip = ir_print_prefix;
43732- chip->irq_ack = ir_ack_apic_edge;
43733- chip->irq_eoi = ir_ack_apic_level;
43734- chip->irq_set_affinity = x86_io_apic_ops.set_affinity;
43735+ pax_open_kernel();
43736+ *(void **)&chip->irq_print_chip = ir_print_prefix;
43737+ *(void **)&chip->irq_ack = ir_ack_apic_edge;
43738+ *(void **)&chip->irq_eoi = ir_ack_apic_level;
43739+ *(void **)&chip->irq_set_affinity = x86_io_apic_ops.set_affinity;
43740+ pax_close_kernel();
43741 }
43742
43743 bool setup_remapped_irq(int irq, struct irq_cfg *cfg, struct irq_chip *chip)
43744diff --git a/drivers/irqchip/irq-gic.c b/drivers/irqchip/irq-gic.c
43745index 38493ff..001538b 100644
43746--- a/drivers/irqchip/irq-gic.c
43747+++ b/drivers/irqchip/irq-gic.c
43748@@ -84,7 +84,7 @@ static u8 gic_cpu_map[NR_GIC_CPU_IF] __read_mostly;
43749 * Supported arch specific GIC irq extension.
43750 * Default make them NULL.
43751 */
43752-struct irq_chip gic_arch_extn = {
43753+irq_chip_no_const gic_arch_extn = {
43754 .irq_eoi = NULL,
43755 .irq_mask = NULL,
43756 .irq_unmask = NULL,
43757@@ -311,7 +311,7 @@ static void gic_handle_cascade_irq(unsigned int irq, struct irq_desc *desc)
43758 chained_irq_exit(chip, desc);
43759 }
43760
43761-static struct irq_chip gic_chip = {
43762+static irq_chip_no_const gic_chip __read_only = {
43763 .name = "GIC",
43764 .irq_mask = gic_mask_irq,
43765 .irq_unmask = gic_unmask_irq,
43766diff --git a/drivers/irqchip/irq-renesas-irqc.c b/drivers/irqchip/irq-renesas-irqc.c
43767index 8777065..a4a9967 100644
43768--- a/drivers/irqchip/irq-renesas-irqc.c
43769+++ b/drivers/irqchip/irq-renesas-irqc.c
43770@@ -151,7 +151,7 @@ static int irqc_probe(struct platform_device *pdev)
43771 struct irqc_priv *p;
43772 struct resource *io;
43773 struct resource *irq;
43774- struct irq_chip *irq_chip;
43775+ irq_chip_no_const *irq_chip;
43776 const char *name = dev_name(&pdev->dev);
43777 int ret;
43778 int k;
43779diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
43780index 6a2df32..dc962f1 100644
43781--- a/drivers/isdn/capi/capi.c
43782+++ b/drivers/isdn/capi/capi.c
43783@@ -81,8 +81,8 @@ struct capiminor {
43784
43785 struct capi20_appl *ap;
43786 u32 ncci;
43787- atomic_t datahandle;
43788- atomic_t msgid;
43789+ atomic_unchecked_t datahandle;
43790+ atomic_unchecked_t msgid;
43791
43792 struct tty_port port;
43793 int ttyinstop;
43794@@ -391,7 +391,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
43795 capimsg_setu16(s, 2, mp->ap->applid);
43796 capimsg_setu8 (s, 4, CAPI_DATA_B3);
43797 capimsg_setu8 (s, 5, CAPI_RESP);
43798- capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
43799+ capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
43800 capimsg_setu32(s, 8, mp->ncci);
43801 capimsg_setu16(s, 12, datahandle);
43802 }
43803@@ -512,14 +512,14 @@ static void handle_minor_send(struct capiminor *mp)
43804 mp->outbytes -= len;
43805 spin_unlock_bh(&mp->outlock);
43806
43807- datahandle = atomic_inc_return(&mp->datahandle);
43808+ datahandle = atomic_inc_return_unchecked(&mp->datahandle);
43809 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
43810 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
43811 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
43812 capimsg_setu16(skb->data, 2, mp->ap->applid);
43813 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
43814 capimsg_setu8 (skb->data, 5, CAPI_REQ);
43815- capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
43816+ capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
43817 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
43818 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
43819 capimsg_setu16(skb->data, 16, len); /* Data length */
43820diff --git a/drivers/isdn/gigaset/bas-gigaset.c b/drivers/isdn/gigaset/bas-gigaset.c
43821index aecec6d..11e13c5 100644
43822--- a/drivers/isdn/gigaset/bas-gigaset.c
43823+++ b/drivers/isdn/gigaset/bas-gigaset.c
43824@@ -2565,22 +2565,22 @@ static int gigaset_post_reset(struct usb_interface *intf)
43825
43826
43827 static const struct gigaset_ops gigops = {
43828- gigaset_write_cmd,
43829- gigaset_write_room,
43830- gigaset_chars_in_buffer,
43831- gigaset_brkchars,
43832- gigaset_init_bchannel,
43833- gigaset_close_bchannel,
43834- gigaset_initbcshw,
43835- gigaset_freebcshw,
43836- gigaset_reinitbcshw,
43837- gigaset_initcshw,
43838- gigaset_freecshw,
43839- gigaset_set_modem_ctrl,
43840- gigaset_baud_rate,
43841- gigaset_set_line_ctrl,
43842- gigaset_isoc_send_skb,
43843- gigaset_isoc_input,
43844+ .write_cmd = gigaset_write_cmd,
43845+ .write_room = gigaset_write_room,
43846+ .chars_in_buffer = gigaset_chars_in_buffer,
43847+ .brkchars = gigaset_brkchars,
43848+ .init_bchannel = gigaset_init_bchannel,
43849+ .close_bchannel = gigaset_close_bchannel,
43850+ .initbcshw = gigaset_initbcshw,
43851+ .freebcshw = gigaset_freebcshw,
43852+ .reinitbcshw = gigaset_reinitbcshw,
43853+ .initcshw = gigaset_initcshw,
43854+ .freecshw = gigaset_freecshw,
43855+ .set_modem_ctrl = gigaset_set_modem_ctrl,
43856+ .baud_rate = gigaset_baud_rate,
43857+ .set_line_ctrl = gigaset_set_line_ctrl,
43858+ .send_skb = gigaset_isoc_send_skb,
43859+ .handle_input = gigaset_isoc_input,
43860 };
43861
43862 /* bas_gigaset_init
43863diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
43864index 600c79b..3752bab 100644
43865--- a/drivers/isdn/gigaset/interface.c
43866+++ b/drivers/isdn/gigaset/interface.c
43867@@ -130,9 +130,9 @@ static int if_open(struct tty_struct *tty, struct file *filp)
43868 }
43869 tty->driver_data = cs;
43870
43871- ++cs->port.count;
43872+ atomic_inc(&cs->port.count);
43873
43874- if (cs->port.count == 1) {
43875+ if (atomic_read(&cs->port.count) == 1) {
43876 tty_port_tty_set(&cs->port, tty);
43877 cs->port.low_latency = 1;
43878 }
43879@@ -156,9 +156,9 @@ static void if_close(struct tty_struct *tty, struct file *filp)
43880
43881 if (!cs->connected)
43882 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
43883- else if (!cs->port.count)
43884+ else if (!atomic_read(&cs->port.count))
43885 dev_warn(cs->dev, "%s: device not opened\n", __func__);
43886- else if (!--cs->port.count)
43887+ else if (!atomic_dec_return(&cs->port.count))
43888 tty_port_tty_set(&cs->port, NULL);
43889
43890 mutex_unlock(&cs->mutex);
43891diff --git a/drivers/isdn/gigaset/ser-gigaset.c b/drivers/isdn/gigaset/ser-gigaset.c
43892index 8c91fd5..14f13ce 100644
43893--- a/drivers/isdn/gigaset/ser-gigaset.c
43894+++ b/drivers/isdn/gigaset/ser-gigaset.c
43895@@ -453,22 +453,22 @@ static int gigaset_set_line_ctrl(struct cardstate *cs, unsigned cflag)
43896 }
43897
43898 static const struct gigaset_ops ops = {
43899- gigaset_write_cmd,
43900- gigaset_write_room,
43901- gigaset_chars_in_buffer,
43902- gigaset_brkchars,
43903- gigaset_init_bchannel,
43904- gigaset_close_bchannel,
43905- gigaset_initbcshw,
43906- gigaset_freebcshw,
43907- gigaset_reinitbcshw,
43908- gigaset_initcshw,
43909- gigaset_freecshw,
43910- gigaset_set_modem_ctrl,
43911- gigaset_baud_rate,
43912- gigaset_set_line_ctrl,
43913- gigaset_m10x_send_skb, /* asyncdata.c */
43914- gigaset_m10x_input, /* asyncdata.c */
43915+ .write_cmd = gigaset_write_cmd,
43916+ .write_room = gigaset_write_room,
43917+ .chars_in_buffer = gigaset_chars_in_buffer,
43918+ .brkchars = gigaset_brkchars,
43919+ .init_bchannel = gigaset_init_bchannel,
43920+ .close_bchannel = gigaset_close_bchannel,
43921+ .initbcshw = gigaset_initbcshw,
43922+ .freebcshw = gigaset_freebcshw,
43923+ .reinitbcshw = gigaset_reinitbcshw,
43924+ .initcshw = gigaset_initcshw,
43925+ .freecshw = gigaset_freecshw,
43926+ .set_modem_ctrl = gigaset_set_modem_ctrl,
43927+ .baud_rate = gigaset_baud_rate,
43928+ .set_line_ctrl = gigaset_set_line_ctrl,
43929+ .send_skb = gigaset_m10x_send_skb, /* asyncdata.c */
43930+ .handle_input = gigaset_m10x_input, /* asyncdata.c */
43931 };
43932
43933
43934diff --git a/drivers/isdn/gigaset/usb-gigaset.c b/drivers/isdn/gigaset/usb-gigaset.c
43935index a8e652d..edadaa4 100644
43936--- a/drivers/isdn/gigaset/usb-gigaset.c
43937+++ b/drivers/isdn/gigaset/usb-gigaset.c
43938@@ -548,7 +548,7 @@ static int gigaset_brkchars(struct cardstate *cs, const unsigned char buf[6])
43939 gigaset_dbg_buffer(DEBUG_USBREQ, "brkchars", 6, buf);
43940 memcpy(cs->hw.usb->bchars, buf, 6);
43941 return usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0x19, 0x41,
43942- 0, 0, &buf, 6, 2000);
43943+ 0, 0, buf, 6, 2000);
43944 }
43945
43946 static void gigaset_freebcshw(struct bc_state *bcs)
43947@@ -867,22 +867,22 @@ static int gigaset_pre_reset(struct usb_interface *intf)
43948 }
43949
43950 static const struct gigaset_ops ops = {
43951- gigaset_write_cmd,
43952- gigaset_write_room,
43953- gigaset_chars_in_buffer,
43954- gigaset_brkchars,
43955- gigaset_init_bchannel,
43956- gigaset_close_bchannel,
43957- gigaset_initbcshw,
43958- gigaset_freebcshw,
43959- gigaset_reinitbcshw,
43960- gigaset_initcshw,
43961- gigaset_freecshw,
43962- gigaset_set_modem_ctrl,
43963- gigaset_baud_rate,
43964- gigaset_set_line_ctrl,
43965- gigaset_m10x_send_skb,
43966- gigaset_m10x_input,
43967+ .write_cmd = gigaset_write_cmd,
43968+ .write_room = gigaset_write_room,
43969+ .chars_in_buffer = gigaset_chars_in_buffer,
43970+ .brkchars = gigaset_brkchars,
43971+ .init_bchannel = gigaset_init_bchannel,
43972+ .close_bchannel = gigaset_close_bchannel,
43973+ .initbcshw = gigaset_initbcshw,
43974+ .freebcshw = gigaset_freebcshw,
43975+ .reinitbcshw = gigaset_reinitbcshw,
43976+ .initcshw = gigaset_initcshw,
43977+ .freecshw = gigaset_freecshw,
43978+ .set_modem_ctrl = gigaset_set_modem_ctrl,
43979+ .baud_rate = gigaset_baud_rate,
43980+ .set_line_ctrl = gigaset_set_line_ctrl,
43981+ .send_skb = gigaset_m10x_send_skb,
43982+ .handle_input = gigaset_m10x_input,
43983 };
43984
43985 /*
43986diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
43987index 4d9b195..455075c 100644
43988--- a/drivers/isdn/hardware/avm/b1.c
43989+++ b/drivers/isdn/hardware/avm/b1.c
43990@@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart *t4file)
43991 }
43992 if (left) {
43993 if (t4file->user) {
43994- if (copy_from_user(buf, dp, left))
43995+ if (left > sizeof buf || copy_from_user(buf, dp, left))
43996 return -EFAULT;
43997 } else {
43998 memcpy(buf, dp, left);
43999@@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart *config)
44000 }
44001 if (left) {
44002 if (config->user) {
44003- if (copy_from_user(buf, dp, left))
44004+ if (left > sizeof buf || copy_from_user(buf, dp, left))
44005 return -EFAULT;
44006 } else {
44007 memcpy(buf, dp, left);
44008diff --git a/drivers/isdn/i4l/isdn_common.c b/drivers/isdn/i4l/isdn_common.c
44009index 9b856e1..fa03c92 100644
44010--- a/drivers/isdn/i4l/isdn_common.c
44011+++ b/drivers/isdn/i4l/isdn_common.c
44012@@ -1654,6 +1654,8 @@ isdn_ioctl(struct file *file, uint cmd, ulong arg)
44013 } else
44014 return -EINVAL;
44015 case IIOCDBGVAR:
44016+ if (!capable(CAP_SYS_RAWIO))
44017+ return -EPERM;
44018 if (arg) {
44019 if (copy_to_user(argp, &dev, sizeof(ulong)))
44020 return -EFAULT;
44021diff --git a/drivers/isdn/i4l/isdn_concap.c b/drivers/isdn/i4l/isdn_concap.c
44022index 91d5730..336523e 100644
44023--- a/drivers/isdn/i4l/isdn_concap.c
44024+++ b/drivers/isdn/i4l/isdn_concap.c
44025@@ -80,9 +80,9 @@ static int isdn_concap_dl_disconn_req(struct concap_proto *concap)
44026 }
44027
44028 struct concap_device_ops isdn_concap_reliable_dl_dops = {
44029- &isdn_concap_dl_data_req,
44030- &isdn_concap_dl_connect_req,
44031- &isdn_concap_dl_disconn_req
44032+ .data_req = &isdn_concap_dl_data_req,
44033+ .connect_req = &isdn_concap_dl_connect_req,
44034+ .disconn_req = &isdn_concap_dl_disconn_req
44035 };
44036
44037 /* The following should better go into a dedicated source file such that
44038diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
44039index bc91261..2ef7e36 100644
44040--- a/drivers/isdn/i4l/isdn_tty.c
44041+++ b/drivers/isdn/i4l/isdn_tty.c
44042@@ -1503,9 +1503,9 @@ isdn_tty_open(struct tty_struct *tty, struct file *filp)
44043
44044 #ifdef ISDN_DEBUG_MODEM_OPEN
44045 printk(KERN_DEBUG "isdn_tty_open %s, count = %d\n", tty->name,
44046- port->count);
44047+ atomic_read(&port->count));
44048 #endif
44049- port->count++;
44050+ atomic_inc(&port->count);
44051 port->tty = tty;
44052 /*
44053 * Start up serial port
44054@@ -1549,7 +1549,7 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
44055 #endif
44056 return;
44057 }
44058- if ((tty->count == 1) && (port->count != 1)) {
44059+ if ((tty->count == 1) && (atomic_read(&port->count) != 1)) {
44060 /*
44061 * Uh, oh. tty->count is 1, which means that the tty
44062 * structure will be freed. Info->count should always
44063@@ -1558,15 +1558,15 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
44064 * serial port won't be shutdown.
44065 */
44066 printk(KERN_ERR "isdn_tty_close: bad port count; tty->count is 1, "
44067- "info->count is %d\n", port->count);
44068- port->count = 1;
44069+ "info->count is %d\n", atomic_read(&port->count));
44070+ atomic_set(&port->count, 1);
44071 }
44072- if (--port->count < 0) {
44073+ if (atomic_dec_return(&port->count) < 0) {
44074 printk(KERN_ERR "isdn_tty_close: bad port count for ttyi%d: %d\n",
44075- info->line, port->count);
44076- port->count = 0;
44077+ info->line, atomic_read(&port->count));
44078+ atomic_set(&port->count, 0);
44079 }
44080- if (port->count) {
44081+ if (atomic_read(&port->count)) {
44082 #ifdef ISDN_DEBUG_MODEM_OPEN
44083 printk(KERN_DEBUG "isdn_tty_close after info->count != 0\n");
44084 #endif
44085@@ -1620,7 +1620,7 @@ isdn_tty_hangup(struct tty_struct *tty)
44086 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_hangup"))
44087 return;
44088 isdn_tty_shutdown(info);
44089- port->count = 0;
44090+ atomic_set(&port->count, 0);
44091 port->flags &= ~ASYNC_NORMAL_ACTIVE;
44092 port->tty = NULL;
44093 wake_up_interruptible(&port->open_wait);
44094@@ -1965,7 +1965,7 @@ isdn_tty_find_icall(int di, int ch, setup_parm *setup)
44095 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
44096 modem_info *info = &dev->mdm.info[i];
44097
44098- if (info->port.count == 0)
44099+ if (atomic_read(&info->port.count) == 0)
44100 continue;
44101 if ((info->emu.mdmreg[REG_SI1] & si2bit[si1]) && /* SI1 is matching */
44102 (info->emu.mdmreg[REG_SI2] == si2)) { /* SI2 is matching */
44103diff --git a/drivers/isdn/i4l/isdn_x25iface.c b/drivers/isdn/i4l/isdn_x25iface.c
44104index e2d4e58..40cd045 100644
44105--- a/drivers/isdn/i4l/isdn_x25iface.c
44106+++ b/drivers/isdn/i4l/isdn_x25iface.c
44107@@ -53,14 +53,14 @@ static int isdn_x25iface_disconn_ind(struct concap_proto *);
44108
44109
44110 static struct concap_proto_ops ix25_pops = {
44111- &isdn_x25iface_proto_new,
44112- &isdn_x25iface_proto_del,
44113- &isdn_x25iface_proto_restart,
44114- &isdn_x25iface_proto_close,
44115- &isdn_x25iface_xmit,
44116- &isdn_x25iface_receive,
44117- &isdn_x25iface_connect_ind,
44118- &isdn_x25iface_disconn_ind
44119+ .proto_new = &isdn_x25iface_proto_new,
44120+ .proto_del = &isdn_x25iface_proto_del,
44121+ .restart = &isdn_x25iface_proto_restart,
44122+ .close = &isdn_x25iface_proto_close,
44123+ .encap_and_xmit = &isdn_x25iface_xmit,
44124+ .data_ind = &isdn_x25iface_receive,
44125+ .connect_ind = &isdn_x25iface_connect_ind,
44126+ .disconn_ind = &isdn_x25iface_disconn_ind
44127 };
44128
44129 /* error message helper function */
44130diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
44131index 6a7447c..cae33fe 100644
44132--- a/drivers/isdn/icn/icn.c
44133+++ b/drivers/isdn/icn/icn.c
44134@@ -1045,7 +1045,7 @@ icn_writecmd(const u_char *buf, int len, int user, icn_card *card)
44135 if (count > len)
44136 count = len;
44137 if (user) {
44138- if (copy_from_user(msg, buf, count))
44139+ if (count > sizeof msg || copy_from_user(msg, buf, count))
44140 return -EFAULT;
44141 } else
44142 memcpy(msg, buf, count);
44143diff --git a/drivers/isdn/mISDN/dsp_cmx.c b/drivers/isdn/mISDN/dsp_cmx.c
44144index 87f7dff..7300125 100644
44145--- a/drivers/isdn/mISDN/dsp_cmx.c
44146+++ b/drivers/isdn/mISDN/dsp_cmx.c
44147@@ -1625,7 +1625,7 @@ unsigned long dsp_spl_jiffies; /* calculate the next time to fire */
44148 static u16 dsp_count; /* last sample count */
44149 static int dsp_count_valid; /* if we have last sample count */
44150
44151-void
44152+void __intentional_overflow(-1)
44153 dsp_cmx_send(void *arg)
44154 {
44155 struct dsp_conf *conf;
44156diff --git a/drivers/leds/leds-clevo-mail.c b/drivers/leds/leds-clevo-mail.c
44157index f58a354..fbae176 100644
44158--- a/drivers/leds/leds-clevo-mail.c
44159+++ b/drivers/leds/leds-clevo-mail.c
44160@@ -40,7 +40,7 @@ static int __init clevo_mail_led_dmi_callback(const struct dmi_system_id *id)
44161 * detected as working, but in reality it is not) as low as
44162 * possible.
44163 */
44164-static struct dmi_system_id clevo_mail_led_dmi_table[] __initdata = {
44165+static struct dmi_system_id clevo_mail_led_dmi_table[] __initconst = {
44166 {
44167 .callback = clevo_mail_led_dmi_callback,
44168 .ident = "Clevo D410J",
44169diff --git a/drivers/leds/leds-ss4200.c b/drivers/leds/leds-ss4200.c
44170index 046cb70..6b20d39 100644
44171--- a/drivers/leds/leds-ss4200.c
44172+++ b/drivers/leds/leds-ss4200.c
44173@@ -91,7 +91,7 @@ MODULE_PARM_DESC(nodetect, "Skip DMI-based hardware detection");
44174 * detected as working, but in reality it is not) as low as
44175 * possible.
44176 */
44177-static struct dmi_system_id nas_led_whitelist[] __initdata = {
44178+static struct dmi_system_id nas_led_whitelist[] __initconst = {
44179 {
44180 .callback = ss4200_led_dmi_callback,
44181 .ident = "Intel SS4200-E",
44182diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
44183index 6590558..a74c5dd 100644
44184--- a/drivers/lguest/core.c
44185+++ b/drivers/lguest/core.c
44186@@ -96,9 +96,17 @@ static __init int map_switcher(void)
44187 * The end address needs +1 because __get_vm_area allocates an
44188 * extra guard page, so we need space for that.
44189 */
44190+
44191+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
44192+ switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
44193+ VM_ALLOC | VM_KERNEXEC, switcher_addr, switcher_addr
44194+ + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
44195+#else
44196 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
44197 VM_ALLOC, switcher_addr, switcher_addr
44198 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
44199+#endif
44200+
44201 if (!switcher_vma) {
44202 err = -ENOMEM;
44203 printk("lguest: could not map switcher pages high\n");
44204@@ -121,7 +129,7 @@ static __init int map_switcher(void)
44205 * Now the Switcher is mapped at the right address, we can't fail!
44206 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
44207 */
44208- memcpy(switcher_vma->addr, start_switcher_text,
44209+ memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
44210 end_switcher_text - start_switcher_text);
44211
44212 printk(KERN_INFO "lguest: mapped switcher at %p\n",
44213diff --git a/drivers/lguest/page_tables.c b/drivers/lguest/page_tables.c
44214index e8b55c3..3514c37 100644
44215--- a/drivers/lguest/page_tables.c
44216+++ b/drivers/lguest/page_tables.c
44217@@ -559,7 +559,7 @@ void pin_page(struct lg_cpu *cpu, unsigned long vaddr)
44218 /*:*/
44219
44220 #ifdef CONFIG_X86_PAE
44221-static void release_pmd(pmd_t *spmd)
44222+static void __intentional_overflow(-1) release_pmd(pmd_t *spmd)
44223 {
44224 /* If the entry's not present, there's nothing to release. */
44225 if (pmd_flags(*spmd) & _PAGE_PRESENT) {
44226diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
44227index 922a1ac..9dd0c2a 100644
44228--- a/drivers/lguest/x86/core.c
44229+++ b/drivers/lguest/x86/core.c
44230@@ -59,7 +59,7 @@ static struct {
44231 /* Offset from where switcher.S was compiled to where we've copied it */
44232 static unsigned long switcher_offset(void)
44233 {
44234- return switcher_addr - (unsigned long)start_switcher_text;
44235+ return switcher_addr - (unsigned long)ktla_ktva(start_switcher_text);
44236 }
44237
44238 /* This cpu's struct lguest_pages (after the Switcher text page) */
44239@@ -99,7 +99,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
44240 * These copies are pretty cheap, so we do them unconditionally: */
44241 /* Save the current Host top-level page directory.
44242 */
44243+
44244+#ifdef CONFIG_PAX_PER_CPU_PGD
44245+ pages->state.host_cr3 = read_cr3();
44246+#else
44247 pages->state.host_cr3 = __pa(current->mm->pgd);
44248+#endif
44249+
44250 /*
44251 * Set up the Guest's page tables to see this CPU's pages (and no
44252 * other CPU's pages).
44253@@ -477,7 +483,7 @@ void __init lguest_arch_host_init(void)
44254 * compiled-in switcher code and the high-mapped copy we just made.
44255 */
44256 for (i = 0; i < IDT_ENTRIES; i++)
44257- default_idt_entries[i] += switcher_offset();
44258+ default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
44259
44260 /*
44261 * Set up the Switcher's per-cpu areas.
44262@@ -560,7 +566,7 @@ void __init lguest_arch_host_init(void)
44263 * it will be undisturbed when we switch. To change %cs and jump we
44264 * need this structure to feed to Intel's "lcall" instruction.
44265 */
44266- lguest_entry.offset = (long)switch_to_guest + switcher_offset();
44267+ lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
44268 lguest_entry.segment = LGUEST_CS;
44269
44270 /*
44271diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
44272index 40634b0..4f5855e 100644
44273--- a/drivers/lguest/x86/switcher_32.S
44274+++ b/drivers/lguest/x86/switcher_32.S
44275@@ -87,6 +87,7 @@
44276 #include <asm/page.h>
44277 #include <asm/segment.h>
44278 #include <asm/lguest.h>
44279+#include <asm/processor-flags.h>
44280
44281 // We mark the start of the code to copy
44282 // It's placed in .text tho it's never run here
44283@@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
44284 // Changes type when we load it: damn Intel!
44285 // For after we switch over our page tables
44286 // That entry will be read-only: we'd crash.
44287+
44288+#ifdef CONFIG_PAX_KERNEXEC
44289+ mov %cr0, %edx
44290+ xor $X86_CR0_WP, %edx
44291+ mov %edx, %cr0
44292+#endif
44293+
44294 movl $(GDT_ENTRY_TSS*8), %edx
44295 ltr %dx
44296
44297@@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
44298 // Let's clear it again for our return.
44299 // The GDT descriptor of the Host
44300 // Points to the table after two "size" bytes
44301- movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
44302+ movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
44303 // Clear "used" from type field (byte 5, bit 2)
44304- andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
44305+ andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
44306+
44307+#ifdef CONFIG_PAX_KERNEXEC
44308+ mov %cr0, %eax
44309+ xor $X86_CR0_WP, %eax
44310+ mov %eax, %cr0
44311+#endif
44312
44313 // Once our page table's switched, the Guest is live!
44314 // The Host fades as we run this final step.
44315@@ -295,13 +309,12 @@ deliver_to_host:
44316 // I consulted gcc, and it gave
44317 // These instructions, which I gladly credit:
44318 leal (%edx,%ebx,8), %eax
44319- movzwl (%eax),%edx
44320- movl 4(%eax), %eax
44321- xorw %ax, %ax
44322- orl %eax, %edx
44323+ movl 4(%eax), %edx
44324+ movw (%eax), %dx
44325 // Now the address of the handler's in %edx
44326 // We call it now: its "iret" drops us home.
44327- jmp *%edx
44328+ ljmp $__KERNEL_CS, $1f
44329+1: jmp *%edx
44330
44331 // Every interrupt can come to us here
44332 // But we must truly tell each apart.
44333diff --git a/drivers/md/bcache/closure.h b/drivers/md/bcache/closure.h
44334index a08e3ee..df8ade2 100644
44335--- a/drivers/md/bcache/closure.h
44336+++ b/drivers/md/bcache/closure.h
44337@@ -238,7 +238,7 @@ static inline void closure_set_stopped(struct closure *cl)
44338 static inline void set_closure_fn(struct closure *cl, closure_fn *fn,
44339 struct workqueue_struct *wq)
44340 {
44341- BUG_ON(object_is_on_stack(cl));
44342+ BUG_ON(object_starts_on_stack(cl));
44343 closure_set_ip(cl);
44344 cl->fn = fn;
44345 cl->wq = wq;
44346diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
44347index da3604e..7789cb4c 100644
44348--- a/drivers/md/bitmap.c
44349+++ b/drivers/md/bitmap.c
44350@@ -1771,7 +1771,7 @@ void bitmap_status(struct seq_file *seq, struct bitmap *bitmap)
44351 chunk_kb ? "KB" : "B");
44352 if (bitmap->storage.file) {
44353 seq_printf(seq, ", file: ");
44354- seq_path(seq, &bitmap->storage.file->f_path, " \t\n");
44355+ seq_path(seq, &bitmap->storage.file->f_path, " \t\n\\");
44356 }
44357
44358 seq_printf(seq, "\n");
44359diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
44360index 0be9381..114262b 100644
44361--- a/drivers/md/dm-ioctl.c
44362+++ b/drivers/md/dm-ioctl.c
44363@@ -1769,7 +1769,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
44364 cmd == DM_LIST_VERSIONS_CMD)
44365 return 0;
44366
44367- if ((cmd == DM_DEV_CREATE_CMD)) {
44368+ if (cmd == DM_DEV_CREATE_CMD) {
44369 if (!*param->name) {
44370 DMWARN("name not supplied when creating device");
44371 return -EINVAL;
44372diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
44373index 7dfdb5c..4caada6 100644
44374--- a/drivers/md/dm-raid1.c
44375+++ b/drivers/md/dm-raid1.c
44376@@ -40,7 +40,7 @@ enum dm_raid1_error {
44377
44378 struct mirror {
44379 struct mirror_set *ms;
44380- atomic_t error_count;
44381+ atomic_unchecked_t error_count;
44382 unsigned long error_type;
44383 struct dm_dev *dev;
44384 sector_t offset;
44385@@ -186,7 +186,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
44386 struct mirror *m;
44387
44388 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
44389- if (!atomic_read(&m->error_count))
44390+ if (!atomic_read_unchecked(&m->error_count))
44391 return m;
44392
44393 return NULL;
44394@@ -218,7 +218,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
44395 * simple way to tell if a device has encountered
44396 * errors.
44397 */
44398- atomic_inc(&m->error_count);
44399+ atomic_inc_unchecked(&m->error_count);
44400
44401 if (test_and_set_bit(error_type, &m->error_type))
44402 return;
44403@@ -409,7 +409,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
44404 struct mirror *m = get_default_mirror(ms);
44405
44406 do {
44407- if (likely(!atomic_read(&m->error_count)))
44408+ if (likely(!atomic_read_unchecked(&m->error_count)))
44409 return m;
44410
44411 if (m-- == ms->mirror)
44412@@ -423,7 +423,7 @@ static int default_ok(struct mirror *m)
44413 {
44414 struct mirror *default_mirror = get_default_mirror(m->ms);
44415
44416- return !atomic_read(&default_mirror->error_count);
44417+ return !atomic_read_unchecked(&default_mirror->error_count);
44418 }
44419
44420 static int mirror_available(struct mirror_set *ms, struct bio *bio)
44421@@ -560,7 +560,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
44422 */
44423 if (likely(region_in_sync(ms, region, 1)))
44424 m = choose_mirror(ms, bio->bi_iter.bi_sector);
44425- else if (m && atomic_read(&m->error_count))
44426+ else if (m && atomic_read_unchecked(&m->error_count))
44427 m = NULL;
44428
44429 if (likely(m))
44430@@ -927,7 +927,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
44431 }
44432
44433 ms->mirror[mirror].ms = ms;
44434- atomic_set(&(ms->mirror[mirror].error_count), 0);
44435+ atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
44436 ms->mirror[mirror].error_type = 0;
44437 ms->mirror[mirror].offset = offset;
44438
44439@@ -1342,7 +1342,7 @@ static void mirror_resume(struct dm_target *ti)
44440 */
44441 static char device_status_char(struct mirror *m)
44442 {
44443- if (!atomic_read(&(m->error_count)))
44444+ if (!atomic_read_unchecked(&(m->error_count)))
44445 return 'A';
44446
44447 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
44448diff --git a/drivers/md/dm-stats.c b/drivers/md/dm-stats.c
44449index 87f86c7..a1a4100 100644
44450--- a/drivers/md/dm-stats.c
44451+++ b/drivers/md/dm-stats.c
44452@@ -382,7 +382,7 @@ do_sync_free:
44453 synchronize_rcu_expedited();
44454 dm_stat_free(&s->rcu_head);
44455 } else {
44456- ACCESS_ONCE(dm_stat_need_rcu_barrier) = 1;
44457+ ACCESS_ONCE_RW(dm_stat_need_rcu_barrier) = 1;
44458 call_rcu(&s->rcu_head, dm_stat_free);
44459 }
44460 return 0;
44461@@ -554,8 +554,8 @@ void dm_stats_account_io(struct dm_stats *stats, unsigned long bi_rw,
44462 ((bi_rw & (REQ_WRITE | REQ_DISCARD)) ==
44463 (ACCESS_ONCE(last->last_rw) & (REQ_WRITE | REQ_DISCARD)))
44464 ));
44465- ACCESS_ONCE(last->last_sector) = end_sector;
44466- ACCESS_ONCE(last->last_rw) = bi_rw;
44467+ ACCESS_ONCE_RW(last->last_sector) = end_sector;
44468+ ACCESS_ONCE_RW(last->last_rw) = bi_rw;
44469 }
44470
44471 rcu_read_lock();
44472diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
44473index f8b37d4..5c5cafd 100644
44474--- a/drivers/md/dm-stripe.c
44475+++ b/drivers/md/dm-stripe.c
44476@@ -21,7 +21,7 @@ struct stripe {
44477 struct dm_dev *dev;
44478 sector_t physical_start;
44479
44480- atomic_t error_count;
44481+ atomic_unchecked_t error_count;
44482 };
44483
44484 struct stripe_c {
44485@@ -188,7 +188,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
44486 kfree(sc);
44487 return r;
44488 }
44489- atomic_set(&(sc->stripe[i].error_count), 0);
44490+ atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
44491 }
44492
44493 ti->private = sc;
44494@@ -332,7 +332,7 @@ static void stripe_status(struct dm_target *ti, status_type_t type,
44495 DMEMIT("%d ", sc->stripes);
44496 for (i = 0; i < sc->stripes; i++) {
44497 DMEMIT("%s ", sc->stripe[i].dev->name);
44498- buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
44499+ buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
44500 'D' : 'A';
44501 }
44502 buffer[i] = '\0';
44503@@ -377,8 +377,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio, int error)
44504 */
44505 for (i = 0; i < sc->stripes; i++)
44506 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
44507- atomic_inc(&(sc->stripe[i].error_count));
44508- if (atomic_read(&(sc->stripe[i].error_count)) <
44509+ atomic_inc_unchecked(&(sc->stripe[i].error_count));
44510+ if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
44511 DM_IO_ERROR_THRESHOLD)
44512 schedule_work(&sc->trigger_event);
44513 }
44514diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
44515index b2bd1eb..38f7a44 100644
44516--- a/drivers/md/dm-table.c
44517+++ b/drivers/md/dm-table.c
44518@@ -303,7 +303,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
44519 if (!dev_size)
44520 return 0;
44521
44522- if ((start >= dev_size) || (start + len > dev_size)) {
44523+ if ((start >= dev_size) || (len > dev_size - start)) {
44524 DMWARN("%s: %s too small for target: "
44525 "start=%llu, len=%llu, dev_size=%llu",
44526 dm_device_name(ti->table->md), bdevname(bdev, b),
44527diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
44528index e9d33ad..dae9880d 100644
44529--- a/drivers/md/dm-thin-metadata.c
44530+++ b/drivers/md/dm-thin-metadata.c
44531@@ -404,7 +404,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
44532 {
44533 pmd->info.tm = pmd->tm;
44534 pmd->info.levels = 2;
44535- pmd->info.value_type.context = pmd->data_sm;
44536+ pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
44537 pmd->info.value_type.size = sizeof(__le64);
44538 pmd->info.value_type.inc = data_block_inc;
44539 pmd->info.value_type.dec = data_block_dec;
44540@@ -423,7 +423,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
44541
44542 pmd->bl_info.tm = pmd->tm;
44543 pmd->bl_info.levels = 1;
44544- pmd->bl_info.value_type.context = pmd->data_sm;
44545+ pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
44546 pmd->bl_info.value_type.size = sizeof(__le64);
44547 pmd->bl_info.value_type.inc = data_block_inc;
44548 pmd->bl_info.value_type.dec = data_block_dec;
44549diff --git a/drivers/md/dm.c b/drivers/md/dm.c
44550index 58f3927..bfbad3e 100644
44551--- a/drivers/md/dm.c
44552+++ b/drivers/md/dm.c
44553@@ -183,9 +183,9 @@ struct mapped_device {
44554 /*
44555 * Event handling.
44556 */
44557- atomic_t event_nr;
44558+ atomic_unchecked_t event_nr;
44559 wait_queue_head_t eventq;
44560- atomic_t uevent_seq;
44561+ atomic_unchecked_t uevent_seq;
44562 struct list_head uevent_list;
44563 spinlock_t uevent_lock; /* Protect access to uevent_list */
44564
44565@@ -2071,8 +2071,8 @@ static struct mapped_device *alloc_dev(int minor)
44566 spin_lock_init(&md->deferred_lock);
44567 atomic_set(&md->holders, 1);
44568 atomic_set(&md->open_count, 0);
44569- atomic_set(&md->event_nr, 0);
44570- atomic_set(&md->uevent_seq, 0);
44571+ atomic_set_unchecked(&md->event_nr, 0);
44572+ atomic_set_unchecked(&md->uevent_seq, 0);
44573 INIT_LIST_HEAD(&md->uevent_list);
44574 INIT_LIST_HEAD(&md->table_devices);
44575 spin_lock_init(&md->uevent_lock);
44576@@ -2228,7 +2228,7 @@ static void event_callback(void *context)
44577
44578 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
44579
44580- atomic_inc(&md->event_nr);
44581+ atomic_inc_unchecked(&md->event_nr);
44582 wake_up(&md->eventq);
44583 }
44584
44585@@ -2921,18 +2921,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
44586
44587 uint32_t dm_next_uevent_seq(struct mapped_device *md)
44588 {
44589- return atomic_add_return(1, &md->uevent_seq);
44590+ return atomic_add_return_unchecked(1, &md->uevent_seq);
44591 }
44592
44593 uint32_t dm_get_event_nr(struct mapped_device *md)
44594 {
44595- return atomic_read(&md->event_nr);
44596+ return atomic_read_unchecked(&md->event_nr);
44597 }
44598
44599 int dm_wait_event(struct mapped_device *md, int event_nr)
44600 {
44601 return wait_event_interruptible(md->eventq,
44602- (event_nr != atomic_read(&md->event_nr)));
44603+ (event_nr != atomic_read_unchecked(&md->event_nr)));
44604 }
44605
44606 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
44607diff --git a/drivers/md/md.c b/drivers/md/md.c
44608index 9233c71..ed5243a 100644
44609--- a/drivers/md/md.c
44610+++ b/drivers/md/md.c
44611@@ -190,10 +190,10 @@ EXPORT_SYMBOL_GPL(bio_clone_mddev);
44612 * start build, activate spare
44613 */
44614 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
44615-static atomic_t md_event_count;
44616+static atomic_unchecked_t md_event_count;
44617 void md_new_event(struct mddev *mddev)
44618 {
44619- atomic_inc(&md_event_count);
44620+ atomic_inc_unchecked(&md_event_count);
44621 wake_up(&md_event_waiters);
44622 }
44623 EXPORT_SYMBOL_GPL(md_new_event);
44624@@ -203,7 +203,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
44625 */
44626 static void md_new_event_inintr(struct mddev *mddev)
44627 {
44628- atomic_inc(&md_event_count);
44629+ atomic_inc_unchecked(&md_event_count);
44630 wake_up(&md_event_waiters);
44631 }
44632
44633@@ -1426,7 +1426,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
44634 if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_RESHAPE_ACTIVE) &&
44635 (le32_to_cpu(sb->feature_map) & MD_FEATURE_NEW_OFFSET))
44636 rdev->new_data_offset += (s32)le32_to_cpu(sb->new_offset);
44637- atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
44638+ atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
44639
44640 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
44641 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
44642@@ -1677,7 +1677,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
44643 else
44644 sb->resync_offset = cpu_to_le64(0);
44645
44646- sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
44647+ sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
44648
44649 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
44650 sb->size = cpu_to_le64(mddev->dev_sectors);
44651@@ -2547,7 +2547,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
44652 static ssize_t
44653 errors_show(struct md_rdev *rdev, char *page)
44654 {
44655- return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
44656+ return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
44657 }
44658
44659 static ssize_t
44660@@ -2556,7 +2556,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
44661 char *e;
44662 unsigned long n = simple_strtoul(buf, &e, 10);
44663 if (*buf && (*e == 0 || *e == '\n')) {
44664- atomic_set(&rdev->corrected_errors, n);
44665+ atomic_set_unchecked(&rdev->corrected_errors, n);
44666 return len;
44667 }
44668 return -EINVAL;
44669@@ -3000,8 +3000,8 @@ int md_rdev_init(struct md_rdev *rdev)
44670 rdev->sb_loaded = 0;
44671 rdev->bb_page = NULL;
44672 atomic_set(&rdev->nr_pending, 0);
44673- atomic_set(&rdev->read_errors, 0);
44674- atomic_set(&rdev->corrected_errors, 0);
44675+ atomic_set_unchecked(&rdev->read_errors, 0);
44676+ atomic_set_unchecked(&rdev->corrected_errors, 0);
44677
44678 INIT_LIST_HEAD(&rdev->same_set);
44679 init_waitqueue_head(&rdev->blocked_wait);
44680@@ -6855,7 +6855,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
44681
44682 spin_unlock(&pers_lock);
44683 seq_printf(seq, "\n");
44684- seq->poll_event = atomic_read(&md_event_count);
44685+ seq->poll_event = atomic_read_unchecked(&md_event_count);
44686 return 0;
44687 }
44688 if (v == (void*)2) {
44689@@ -6958,7 +6958,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
44690 return error;
44691
44692 seq = file->private_data;
44693- seq->poll_event = atomic_read(&md_event_count);
44694+ seq->poll_event = atomic_read_unchecked(&md_event_count);
44695 return error;
44696 }
44697
44698@@ -6975,7 +6975,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
44699 /* always allow read */
44700 mask = POLLIN | POLLRDNORM;
44701
44702- if (seq->poll_event != atomic_read(&md_event_count))
44703+ if (seq->poll_event != atomic_read_unchecked(&md_event_count))
44704 mask |= POLLERR | POLLPRI;
44705 return mask;
44706 }
44707@@ -7022,7 +7022,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
44708 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
44709 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
44710 (int)part_stat_read(&disk->part0, sectors[1]) -
44711- atomic_read(&disk->sync_io);
44712+ atomic_read_unchecked(&disk->sync_io);
44713 /* sync IO will cause sync_io to increase before the disk_stats
44714 * as sync_io is counted when a request starts, and
44715 * disk_stats is counted when it completes.
44716diff --git a/drivers/md/md.h b/drivers/md/md.h
44717index 03cec5b..0a658c1 100644
44718--- a/drivers/md/md.h
44719+++ b/drivers/md/md.h
44720@@ -94,13 +94,13 @@ struct md_rdev {
44721 * only maintained for arrays that
44722 * support hot removal
44723 */
44724- atomic_t read_errors; /* number of consecutive read errors that
44725+ atomic_unchecked_t read_errors; /* number of consecutive read errors that
44726 * we have tried to ignore.
44727 */
44728 struct timespec last_read_error; /* monotonic time since our
44729 * last read error
44730 */
44731- atomic_t corrected_errors; /* number of corrected read errors,
44732+ atomic_unchecked_t corrected_errors; /* number of corrected read errors,
44733 * for reporting to userspace and storing
44734 * in superblock.
44735 */
44736@@ -448,7 +448,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
44737
44738 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
44739 {
44740- atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
44741+ atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
44742 }
44743
44744 struct md_personality
44745diff --git a/drivers/md/persistent-data/dm-space-map-metadata.c b/drivers/md/persistent-data/dm-space-map-metadata.c
44746index 786b689..ea8c956 100644
44747--- a/drivers/md/persistent-data/dm-space-map-metadata.c
44748+++ b/drivers/md/persistent-data/dm-space-map-metadata.c
44749@@ -679,7 +679,7 @@ static int sm_metadata_extend(struct dm_space_map *sm, dm_block_t extra_blocks)
44750 * Flick into a mode where all blocks get allocated in the new area.
44751 */
44752 smm->begin = old_len;
44753- memcpy(sm, &bootstrap_ops, sizeof(*sm));
44754+ memcpy((void *)sm, &bootstrap_ops, sizeof(*sm));
44755
44756 /*
44757 * Extend.
44758@@ -710,7 +710,7 @@ out:
44759 /*
44760 * Switch back to normal behaviour.
44761 */
44762- memcpy(sm, &ops, sizeof(*sm));
44763+ memcpy((void *)sm, &ops, sizeof(*sm));
44764 return r;
44765 }
44766
44767diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
44768index 3e6d115..ffecdeb 100644
44769--- a/drivers/md/persistent-data/dm-space-map.h
44770+++ b/drivers/md/persistent-data/dm-space-map.h
44771@@ -71,6 +71,7 @@ struct dm_space_map {
44772 dm_sm_threshold_fn fn,
44773 void *context);
44774 };
44775+typedef struct dm_space_map __no_const dm_space_map_no_const;
44776
44777 /*----------------------------------------------------------------*/
44778
44779diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
44780index 40b35be..a327e11 100644
44781--- a/drivers/md/raid1.c
44782+++ b/drivers/md/raid1.c
44783@@ -1931,7 +1931,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
44784 if (r1_sync_page_io(rdev, sect, s,
44785 bio->bi_io_vec[idx].bv_page,
44786 READ) != 0)
44787- atomic_add(s, &rdev->corrected_errors);
44788+ atomic_add_unchecked(s, &rdev->corrected_errors);
44789 }
44790 sectors -= s;
44791 sect += s;
44792@@ -2164,7 +2164,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
44793 !test_bit(Faulty, &rdev->flags)) {
44794 if (r1_sync_page_io(rdev, sect, s,
44795 conf->tmppage, READ)) {
44796- atomic_add(s, &rdev->corrected_errors);
44797+ atomic_add_unchecked(s, &rdev->corrected_errors);
44798 printk(KERN_INFO
44799 "md/raid1:%s: read error corrected "
44800 "(%d sectors at %llu on %s)\n",
44801diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
44802index 32e282f..5cec803 100644
44803--- a/drivers/md/raid10.c
44804+++ b/drivers/md/raid10.c
44805@@ -1944,7 +1944,7 @@ static void end_sync_read(struct bio *bio, int error)
44806 /* The write handler will notice the lack of
44807 * R10BIO_Uptodate and record any errors etc
44808 */
44809- atomic_add(r10_bio->sectors,
44810+ atomic_add_unchecked(r10_bio->sectors,
44811 &conf->mirrors[d].rdev->corrected_errors);
44812
44813 /* for reconstruct, we always reschedule after a read.
44814@@ -2301,7 +2301,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
44815 {
44816 struct timespec cur_time_mon;
44817 unsigned long hours_since_last;
44818- unsigned int read_errors = atomic_read(&rdev->read_errors);
44819+ unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
44820
44821 ktime_get_ts(&cur_time_mon);
44822
44823@@ -2323,9 +2323,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
44824 * overflowing the shift of read_errors by hours_since_last.
44825 */
44826 if (hours_since_last >= 8 * sizeof(read_errors))
44827- atomic_set(&rdev->read_errors, 0);
44828+ atomic_set_unchecked(&rdev->read_errors, 0);
44829 else
44830- atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
44831+ atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
44832 }
44833
44834 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
44835@@ -2379,8 +2379,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
44836 return;
44837
44838 check_decay_read_errors(mddev, rdev);
44839- atomic_inc(&rdev->read_errors);
44840- if (atomic_read(&rdev->read_errors) > max_read_errors) {
44841+ atomic_inc_unchecked(&rdev->read_errors);
44842+ if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
44843 char b[BDEVNAME_SIZE];
44844 bdevname(rdev->bdev, b);
44845
44846@@ -2388,7 +2388,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
44847 "md/raid10:%s: %s: Raid device exceeded "
44848 "read_error threshold [cur %d:max %d]\n",
44849 mdname(mddev), b,
44850- atomic_read(&rdev->read_errors), max_read_errors);
44851+ atomic_read_unchecked(&rdev->read_errors), max_read_errors);
44852 printk(KERN_NOTICE
44853 "md/raid10:%s: %s: Failing raid device\n",
44854 mdname(mddev), b);
44855@@ -2543,7 +2543,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
44856 sect +
44857 choose_data_offset(r10_bio, rdev)),
44858 bdevname(rdev->bdev, b));
44859- atomic_add(s, &rdev->corrected_errors);
44860+ atomic_add_unchecked(s, &rdev->corrected_errors);
44861 }
44862
44863 rdev_dec_pending(rdev, mddev);
44864diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
44865index 9c66e59..42a8eac 100644
44866--- a/drivers/md/raid5.c
44867+++ b/drivers/md/raid5.c
44868@@ -1730,6 +1730,10 @@ static int grow_one_stripe(struct r5conf *conf, int hash)
44869 return 1;
44870 }
44871
44872+#ifdef CONFIG_GRKERNSEC_HIDESYM
44873+static atomic_unchecked_t raid5_cache_id = ATOMIC_INIT(0);
44874+#endif
44875+
44876 static int grow_stripes(struct r5conf *conf, int num)
44877 {
44878 struct kmem_cache *sc;
44879@@ -1741,7 +1745,11 @@ static int grow_stripes(struct r5conf *conf, int num)
44880 "raid%d-%s", conf->level, mdname(conf->mddev));
44881 else
44882 sprintf(conf->cache_name[0],
44883+#ifdef CONFIG_GRKERNSEC_HIDESYM
44884+ "raid%d-%08lx", conf->level, atomic_inc_return_unchecked(&raid5_cache_id));
44885+#else
44886 "raid%d-%p", conf->level, conf->mddev);
44887+#endif
44888 sprintf(conf->cache_name[1], "%s-alt", conf->cache_name[0]);
44889
44890 conf->active_name = 0;
44891@@ -2017,21 +2025,21 @@ static void raid5_end_read_request(struct bio * bi, int error)
44892 mdname(conf->mddev), STRIPE_SECTORS,
44893 (unsigned long long)s,
44894 bdevname(rdev->bdev, b));
44895- atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
44896+ atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
44897 clear_bit(R5_ReadError, &sh->dev[i].flags);
44898 clear_bit(R5_ReWrite, &sh->dev[i].flags);
44899 } else if (test_bit(R5_ReadNoMerge, &sh->dev[i].flags))
44900 clear_bit(R5_ReadNoMerge, &sh->dev[i].flags);
44901
44902- if (atomic_read(&rdev->read_errors))
44903- atomic_set(&rdev->read_errors, 0);
44904+ if (atomic_read_unchecked(&rdev->read_errors))
44905+ atomic_set_unchecked(&rdev->read_errors, 0);
44906 } else {
44907 const char *bdn = bdevname(rdev->bdev, b);
44908 int retry = 0;
44909 int set_bad = 0;
44910
44911 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
44912- atomic_inc(&rdev->read_errors);
44913+ atomic_inc_unchecked(&rdev->read_errors);
44914 if (test_bit(R5_ReadRepl, &sh->dev[i].flags))
44915 printk_ratelimited(
44916 KERN_WARNING
44917@@ -2059,7 +2067,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
44918 mdname(conf->mddev),
44919 (unsigned long long)s,
44920 bdn);
44921- } else if (atomic_read(&rdev->read_errors)
44922+ } else if (atomic_read_unchecked(&rdev->read_errors)
44923 > conf->max_nr_stripes)
44924 printk(KERN_WARNING
44925 "md/raid:%s: Too many read errors, failing device %s.\n",
44926diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
44927index 983db75..ef9248c 100644
44928--- a/drivers/media/dvb-core/dvbdev.c
44929+++ b/drivers/media/dvb-core/dvbdev.c
44930@@ -185,7 +185,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
44931 const struct dvb_device *template, void *priv, int type)
44932 {
44933 struct dvb_device *dvbdev;
44934- struct file_operations *dvbdevfops;
44935+ file_operations_no_const *dvbdevfops;
44936 struct device *clsdev;
44937 int minor;
44938 int id;
44939diff --git a/drivers/media/dvb-frontends/af9033.h b/drivers/media/dvb-frontends/af9033.h
44940index 6ad22b6..6e90e2a 100644
44941--- a/drivers/media/dvb-frontends/af9033.h
44942+++ b/drivers/media/dvb-frontends/af9033.h
44943@@ -96,6 +96,6 @@ struct af9033_ops {
44944 int (*pid_filter_ctrl)(struct dvb_frontend *fe, int onoff);
44945 int (*pid_filter)(struct dvb_frontend *fe, int index, u16 pid,
44946 int onoff);
44947-};
44948+} __no_const;
44949
44950 #endif /* AF9033_H */
44951diff --git a/drivers/media/dvb-frontends/dib3000.h b/drivers/media/dvb-frontends/dib3000.h
44952index 9b6c3bb..baeb5c7 100644
44953--- a/drivers/media/dvb-frontends/dib3000.h
44954+++ b/drivers/media/dvb-frontends/dib3000.h
44955@@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
44956 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
44957 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
44958 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
44959-};
44960+} __no_const;
44961
44962 #if IS_ENABLED(CONFIG_DVB_DIB3000MB)
44963 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
44964diff --git a/drivers/media/dvb-frontends/dib7000p.h b/drivers/media/dvb-frontends/dib7000p.h
44965index 1fea0e9..321ce8f 100644
44966--- a/drivers/media/dvb-frontends/dib7000p.h
44967+++ b/drivers/media/dvb-frontends/dib7000p.h
44968@@ -64,7 +64,7 @@ struct dib7000p_ops {
44969 int (*get_adc_power)(struct dvb_frontend *fe);
44970 int (*slave_reset)(struct dvb_frontend *fe);
44971 struct dvb_frontend *(*init)(struct i2c_adapter *i2c_adap, u8 i2c_addr, struct dib7000p_config *cfg);
44972-};
44973+} __no_const;
44974
44975 #if IS_ENABLED(CONFIG_DVB_DIB7000P)
44976 void *dib7000p_attach(struct dib7000p_ops *ops);
44977diff --git a/drivers/media/dvb-frontends/dib8000.h b/drivers/media/dvb-frontends/dib8000.h
44978index 84cc103..5780c54 100644
44979--- a/drivers/media/dvb-frontends/dib8000.h
44980+++ b/drivers/media/dvb-frontends/dib8000.h
44981@@ -61,7 +61,7 @@ struct dib8000_ops {
44982 int (*pid_filter_ctrl)(struct dvb_frontend *fe, u8 onoff);
44983 int (*pid_filter)(struct dvb_frontend *fe, u8 id, u16 pid, u8 onoff);
44984 struct dvb_frontend *(*init)(struct i2c_adapter *i2c_adap, u8 i2c_addr, struct dib8000_config *cfg);
44985-};
44986+} __no_const;
44987
44988 #if IS_ENABLED(CONFIG_DVB_DIB8000)
44989 void *dib8000_attach(struct dib8000_ops *ops);
44990diff --git a/drivers/media/pci/cx88/cx88-video.c b/drivers/media/pci/cx88/cx88-video.c
44991index ce27e6d..b70435a 100644
44992--- a/drivers/media/pci/cx88/cx88-video.c
44993+++ b/drivers/media/pci/cx88/cx88-video.c
44994@@ -50,9 +50,9 @@ MODULE_VERSION(CX88_VERSION);
44995
44996 /* ------------------------------------------------------------------ */
44997
44998-static unsigned int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44999-static unsigned int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
45000-static unsigned int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
45001+static int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
45002+static int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
45003+static int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
45004
45005 module_param_array(video_nr, int, NULL, 0444);
45006 module_param_array(vbi_nr, int, NULL, 0444);
45007diff --git a/drivers/media/pci/ivtv/ivtv-driver.c b/drivers/media/pci/ivtv/ivtv-driver.c
45008index 802642d..5534900 100644
45009--- a/drivers/media/pci/ivtv/ivtv-driver.c
45010+++ b/drivers/media/pci/ivtv/ivtv-driver.c
45011@@ -83,7 +83,7 @@ static struct pci_device_id ivtv_pci_tbl[] = {
45012 MODULE_DEVICE_TABLE(pci,ivtv_pci_tbl);
45013
45014 /* ivtv instance counter */
45015-static atomic_t ivtv_instance = ATOMIC_INIT(0);
45016+static atomic_unchecked_t ivtv_instance = ATOMIC_INIT(0);
45017
45018 /* Parameter declarations */
45019 static int cardtype[IVTV_MAX_CARDS];
45020diff --git a/drivers/media/pci/solo6x10/solo6x10-core.c b/drivers/media/pci/solo6x10/solo6x10-core.c
45021index 8cbe6b4..ea3601c 100644
45022--- a/drivers/media/pci/solo6x10/solo6x10-core.c
45023+++ b/drivers/media/pci/solo6x10/solo6x10-core.c
45024@@ -424,7 +424,7 @@ static void solo_device_release(struct device *dev)
45025
45026 static int solo_sysfs_init(struct solo_dev *solo_dev)
45027 {
45028- struct bin_attribute *sdram_attr = &solo_dev->sdram_attr;
45029+ bin_attribute_no_const *sdram_attr = &solo_dev->sdram_attr;
45030 struct device *dev = &solo_dev->dev;
45031 const char *driver;
45032 int i;
45033diff --git a/drivers/media/pci/solo6x10/solo6x10-g723.c b/drivers/media/pci/solo6x10/solo6x10-g723.c
45034index c7141f2..5301fec 100644
45035--- a/drivers/media/pci/solo6x10/solo6x10-g723.c
45036+++ b/drivers/media/pci/solo6x10/solo6x10-g723.c
45037@@ -351,7 +351,7 @@ static int solo_snd_pcm_init(struct solo_dev *solo_dev)
45038
45039 int solo_g723_init(struct solo_dev *solo_dev)
45040 {
45041- static struct snd_device_ops ops = { NULL };
45042+ static struct snd_device_ops ops = { };
45043 struct snd_card *card;
45044 struct snd_kcontrol_new kctl;
45045 char name[32];
45046diff --git a/drivers/media/pci/solo6x10/solo6x10-p2m.c b/drivers/media/pci/solo6x10/solo6x10-p2m.c
45047index 8c84846..27b4f83 100644
45048--- a/drivers/media/pci/solo6x10/solo6x10-p2m.c
45049+++ b/drivers/media/pci/solo6x10/solo6x10-p2m.c
45050@@ -73,7 +73,7 @@ int solo_p2m_dma_desc(struct solo_dev *solo_dev,
45051
45052 /* Get next ID. According to Softlogic, 6110 has problems on !=0 P2M */
45053 if (solo_dev->type != SOLO_DEV_6110 && multi_p2m) {
45054- p2m_id = atomic_inc_return(&solo_dev->p2m_count) % SOLO_NR_P2M;
45055+ p2m_id = atomic_inc_return_unchecked(&solo_dev->p2m_count) % SOLO_NR_P2M;
45056 if (p2m_id < 0)
45057 p2m_id = -p2m_id;
45058 }
45059diff --git a/drivers/media/pci/solo6x10/solo6x10.h b/drivers/media/pci/solo6x10/solo6x10.h
45060index 72017b7..dd37ae6 100644
45061--- a/drivers/media/pci/solo6x10/solo6x10.h
45062+++ b/drivers/media/pci/solo6x10/solo6x10.h
45063@@ -219,7 +219,7 @@ struct solo_dev {
45064
45065 /* P2M DMA Engine */
45066 struct solo_p2m_dev p2m_dev[SOLO_NR_P2M];
45067- atomic_t p2m_count;
45068+ atomic_unchecked_t p2m_count;
45069 int p2m_jiffies;
45070 unsigned int p2m_timeouts;
45071
45072diff --git a/drivers/media/pci/tw68/tw68-core.c b/drivers/media/pci/tw68/tw68-core.c
45073index 63f0b64..a017c1c 100644
45074--- a/drivers/media/pci/tw68/tw68-core.c
45075+++ b/drivers/media/pci/tw68/tw68-core.c
45076@@ -60,7 +60,7 @@ static unsigned int card[] = {[0 ... (TW68_MAXBOARDS - 1)] = UNSET };
45077 module_param_array(card, int, NULL, 0444);
45078 MODULE_PARM_DESC(card, "card type");
45079
45080-static atomic_t tw68_instance = ATOMIC_INIT(0);
45081+static atomic_unchecked_t tw68_instance = ATOMIC_INIT(0);
45082
45083 /* ------------------------------------------------------------------ */
45084
45085diff --git a/drivers/media/platform/omap/omap_vout.c b/drivers/media/platform/omap/omap_vout.c
45086index 64ab6fb..ef4a8b9 100644
45087--- a/drivers/media/platform/omap/omap_vout.c
45088+++ b/drivers/media/platform/omap/omap_vout.c
45089@@ -63,7 +63,6 @@ enum omap_vout_channels {
45090 OMAP_VIDEO2,
45091 };
45092
45093-static struct videobuf_queue_ops video_vbq_ops;
45094 /* Variables configurable through module params*/
45095 static u32 video1_numbuffers = 3;
45096 static u32 video2_numbuffers = 3;
45097@@ -1012,6 +1011,12 @@ static int omap_vout_open(struct file *file)
45098 {
45099 struct videobuf_queue *q;
45100 struct omap_vout_device *vout = NULL;
45101+ static struct videobuf_queue_ops video_vbq_ops = {
45102+ .buf_setup = omap_vout_buffer_setup,
45103+ .buf_prepare = omap_vout_buffer_prepare,
45104+ .buf_release = omap_vout_buffer_release,
45105+ .buf_queue = omap_vout_buffer_queue,
45106+ };
45107
45108 vout = video_drvdata(file);
45109 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
45110@@ -1029,10 +1034,6 @@ static int omap_vout_open(struct file *file)
45111 vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
45112
45113 q = &vout->vbq;
45114- video_vbq_ops.buf_setup = omap_vout_buffer_setup;
45115- video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
45116- video_vbq_ops.buf_release = omap_vout_buffer_release;
45117- video_vbq_ops.buf_queue = omap_vout_buffer_queue;
45118 spin_lock_init(&vout->vbq_lock);
45119
45120 videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
45121diff --git a/drivers/media/platform/s5p-tv/mixer.h b/drivers/media/platform/s5p-tv/mixer.h
45122index fb2acc5..a2fcbdc4 100644
45123--- a/drivers/media/platform/s5p-tv/mixer.h
45124+++ b/drivers/media/platform/s5p-tv/mixer.h
45125@@ -156,7 +156,7 @@ struct mxr_layer {
45126 /** layer index (unique identifier) */
45127 int idx;
45128 /** callbacks for layer methods */
45129- struct mxr_layer_ops ops;
45130+ struct mxr_layer_ops *ops;
45131 /** format array */
45132 const struct mxr_format **fmt_array;
45133 /** size of format array */
45134diff --git a/drivers/media/platform/s5p-tv/mixer_grp_layer.c b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
45135index 74344c7..a39e70e 100644
45136--- a/drivers/media/platform/s5p-tv/mixer_grp_layer.c
45137+++ b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
45138@@ -235,7 +235,7 @@ struct mxr_layer *mxr_graph_layer_create(struct mxr_device *mdev, int idx)
45139 {
45140 struct mxr_layer *layer;
45141 int ret;
45142- struct mxr_layer_ops ops = {
45143+ static struct mxr_layer_ops ops = {
45144 .release = mxr_graph_layer_release,
45145 .buffer_set = mxr_graph_buffer_set,
45146 .stream_set = mxr_graph_stream_set,
45147diff --git a/drivers/media/platform/s5p-tv/mixer_reg.c b/drivers/media/platform/s5p-tv/mixer_reg.c
45148index b713403..53cb5ad 100644
45149--- a/drivers/media/platform/s5p-tv/mixer_reg.c
45150+++ b/drivers/media/platform/s5p-tv/mixer_reg.c
45151@@ -276,7 +276,7 @@ static void mxr_irq_layer_handle(struct mxr_layer *layer)
45152 layer->update_buf = next;
45153 }
45154
45155- layer->ops.buffer_set(layer, layer->update_buf);
45156+ layer->ops->buffer_set(layer, layer->update_buf);
45157
45158 if (done && done != layer->shadow_buf)
45159 vb2_buffer_done(&done->vb, VB2_BUF_STATE_DONE);
45160diff --git a/drivers/media/platform/s5p-tv/mixer_video.c b/drivers/media/platform/s5p-tv/mixer_video.c
45161index b4d2696..91df48e 100644
45162--- a/drivers/media/platform/s5p-tv/mixer_video.c
45163+++ b/drivers/media/platform/s5p-tv/mixer_video.c
45164@@ -210,7 +210,7 @@ static void mxr_layer_default_geo(struct mxr_layer *layer)
45165 layer->geo.src.height = layer->geo.src.full_height;
45166
45167 mxr_geometry_dump(mdev, &layer->geo);
45168- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
45169+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
45170 mxr_geometry_dump(mdev, &layer->geo);
45171 }
45172
45173@@ -228,7 +228,7 @@ static void mxr_layer_update_output(struct mxr_layer *layer)
45174 layer->geo.dst.full_width = mbus_fmt.width;
45175 layer->geo.dst.full_height = mbus_fmt.height;
45176 layer->geo.dst.field = mbus_fmt.field;
45177- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
45178+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
45179
45180 mxr_geometry_dump(mdev, &layer->geo);
45181 }
45182@@ -334,7 +334,7 @@ static int mxr_s_fmt(struct file *file, void *priv,
45183 /* set source size to highest accepted value */
45184 geo->src.full_width = max(geo->dst.full_width, pix->width);
45185 geo->src.full_height = max(geo->dst.full_height, pix->height);
45186- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
45187+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
45188 mxr_geometry_dump(mdev, &layer->geo);
45189 /* set cropping to total visible screen */
45190 geo->src.width = pix->width;
45191@@ -342,12 +342,12 @@ static int mxr_s_fmt(struct file *file, void *priv,
45192 geo->src.x_offset = 0;
45193 geo->src.y_offset = 0;
45194 /* assure consistency of geometry */
45195- layer->ops.fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
45196+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
45197 mxr_geometry_dump(mdev, &layer->geo);
45198 /* set full size to lowest possible value */
45199 geo->src.full_width = 0;
45200 geo->src.full_height = 0;
45201- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
45202+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
45203 mxr_geometry_dump(mdev, &layer->geo);
45204
45205 /* returning results */
45206@@ -474,7 +474,7 @@ static int mxr_s_selection(struct file *file, void *fh,
45207 target->width = s->r.width;
45208 target->height = s->r.height;
45209
45210- layer->ops.fix_geometry(layer, stage, s->flags);
45211+ layer->ops->fix_geometry(layer, stage, s->flags);
45212
45213 /* retrieve update selection rectangle */
45214 res.left = target->x_offset;
45215@@ -954,13 +954,13 @@ static int start_streaming(struct vb2_queue *vq, unsigned int count)
45216 mxr_output_get(mdev);
45217
45218 mxr_layer_update_output(layer);
45219- layer->ops.format_set(layer);
45220+ layer->ops->format_set(layer);
45221 /* enabling layer in hardware */
45222 spin_lock_irqsave(&layer->enq_slock, flags);
45223 layer->state = MXR_LAYER_STREAMING;
45224 spin_unlock_irqrestore(&layer->enq_slock, flags);
45225
45226- layer->ops.stream_set(layer, MXR_ENABLE);
45227+ layer->ops->stream_set(layer, MXR_ENABLE);
45228 mxr_streamer_get(mdev);
45229
45230 return 0;
45231@@ -1030,7 +1030,7 @@ static void stop_streaming(struct vb2_queue *vq)
45232 spin_unlock_irqrestore(&layer->enq_slock, flags);
45233
45234 /* disabling layer in hardware */
45235- layer->ops.stream_set(layer, MXR_DISABLE);
45236+ layer->ops->stream_set(layer, MXR_DISABLE);
45237 /* remove one streamer */
45238 mxr_streamer_put(mdev);
45239 /* allow changes in output configuration */
45240@@ -1068,8 +1068,8 @@ void mxr_base_layer_unregister(struct mxr_layer *layer)
45241
45242 void mxr_layer_release(struct mxr_layer *layer)
45243 {
45244- if (layer->ops.release)
45245- layer->ops.release(layer);
45246+ if (layer->ops->release)
45247+ layer->ops->release(layer);
45248 }
45249
45250 void mxr_base_layer_release(struct mxr_layer *layer)
45251@@ -1095,7 +1095,7 @@ struct mxr_layer *mxr_base_layer_create(struct mxr_device *mdev,
45252
45253 layer->mdev = mdev;
45254 layer->idx = idx;
45255- layer->ops = *ops;
45256+ layer->ops = ops;
45257
45258 spin_lock_init(&layer->enq_slock);
45259 INIT_LIST_HEAD(&layer->enq_list);
45260diff --git a/drivers/media/platform/s5p-tv/mixer_vp_layer.c b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
45261index c9388c4..ce71ece 100644
45262--- a/drivers/media/platform/s5p-tv/mixer_vp_layer.c
45263+++ b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
45264@@ -206,7 +206,7 @@ struct mxr_layer *mxr_vp_layer_create(struct mxr_device *mdev, int idx)
45265 {
45266 struct mxr_layer *layer;
45267 int ret;
45268- struct mxr_layer_ops ops = {
45269+ static struct mxr_layer_ops ops = {
45270 .release = mxr_vp_layer_release,
45271 .buffer_set = mxr_vp_buffer_set,
45272 .stream_set = mxr_vp_stream_set,
45273diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
45274index 82affae..42833ec 100644
45275--- a/drivers/media/radio/radio-cadet.c
45276+++ b/drivers/media/radio/radio-cadet.c
45277@@ -333,6 +333,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
45278 unsigned char readbuf[RDS_BUFFER];
45279 int i = 0;
45280
45281+ if (count > RDS_BUFFER)
45282+ return -EFAULT;
45283 mutex_lock(&dev->lock);
45284 if (dev->rdsstat == 0)
45285 cadet_start_rds(dev);
45286@@ -349,8 +351,9 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
45287 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
45288 mutex_unlock(&dev->lock);
45289
45290- if (i && copy_to_user(data, readbuf, i))
45291- return -EFAULT;
45292+ if (i > sizeof(readbuf) || (i && copy_to_user(data, readbuf, i)))
45293+ i = -EFAULT;
45294+
45295 return i;
45296 }
45297
45298diff --git a/drivers/media/radio/radio-maxiradio.c b/drivers/media/radio/radio-maxiradio.c
45299index 5236035..c622c74 100644
45300--- a/drivers/media/radio/radio-maxiradio.c
45301+++ b/drivers/media/radio/radio-maxiradio.c
45302@@ -61,7 +61,7 @@ MODULE_PARM_DESC(radio_nr, "Radio device number");
45303 /* TEA5757 pin mappings */
45304 static const int clk = 1, data = 2, wren = 4, mo_st = 8, power = 16;
45305
45306-static atomic_t maxiradio_instance = ATOMIC_INIT(0);
45307+static atomic_unchecked_t maxiradio_instance = ATOMIC_INIT(0);
45308
45309 #define PCI_VENDOR_ID_GUILLEMOT 0x5046
45310 #define PCI_DEVICE_ID_GUILLEMOT_MAXIRADIO 0x1001
45311diff --git a/drivers/media/radio/radio-shark.c b/drivers/media/radio/radio-shark.c
45312index 050b3bb..79f62b9 100644
45313--- a/drivers/media/radio/radio-shark.c
45314+++ b/drivers/media/radio/radio-shark.c
45315@@ -79,7 +79,7 @@ struct shark_device {
45316 u32 last_val;
45317 };
45318
45319-static atomic_t shark_instance = ATOMIC_INIT(0);
45320+static atomic_unchecked_t shark_instance = ATOMIC_INIT(0);
45321
45322 static void shark_write_val(struct snd_tea575x *tea, u32 val)
45323 {
45324diff --git a/drivers/media/radio/radio-shark2.c b/drivers/media/radio/radio-shark2.c
45325index 8654e0d..0608a64 100644
45326--- a/drivers/media/radio/radio-shark2.c
45327+++ b/drivers/media/radio/radio-shark2.c
45328@@ -74,7 +74,7 @@ struct shark_device {
45329 u8 *transfer_buffer;
45330 };
45331
45332-static atomic_t shark_instance = ATOMIC_INIT(0);
45333+static atomic_unchecked_t shark_instance = ATOMIC_INIT(0);
45334
45335 static int shark_write_reg(struct radio_tea5777 *tea, u64 reg)
45336 {
45337diff --git a/drivers/media/radio/radio-si476x.c b/drivers/media/radio/radio-si476x.c
45338index 633022b..7f10754 100644
45339--- a/drivers/media/radio/radio-si476x.c
45340+++ b/drivers/media/radio/radio-si476x.c
45341@@ -1445,7 +1445,7 @@ static int si476x_radio_probe(struct platform_device *pdev)
45342 struct si476x_radio *radio;
45343 struct v4l2_ctrl *ctrl;
45344
45345- static atomic_t instance = ATOMIC_INIT(0);
45346+ static atomic_unchecked_t instance = ATOMIC_INIT(0);
45347
45348 radio = devm_kzalloc(&pdev->dev, sizeof(*radio), GFP_KERNEL);
45349 if (!radio)
45350diff --git a/drivers/media/usb/dvb-usb/cinergyT2-core.c b/drivers/media/usb/dvb-usb/cinergyT2-core.c
45351index 9fd1527..8927230 100644
45352--- a/drivers/media/usb/dvb-usb/cinergyT2-core.c
45353+++ b/drivers/media/usb/dvb-usb/cinergyT2-core.c
45354@@ -50,29 +50,73 @@ static struct dvb_usb_device_properties cinergyt2_properties;
45355
45356 static int cinergyt2_streaming_ctrl(struct dvb_usb_adapter *adap, int enable)
45357 {
45358- char buf[] = { CINERGYT2_EP1_CONTROL_STREAM_TRANSFER, enable ? 1 : 0 };
45359- char result[64];
45360- return dvb_usb_generic_rw(adap->dev, buf, sizeof(buf), result,
45361- sizeof(result), 0);
45362+ char *buf;
45363+ char *result;
45364+ int retval;
45365+
45366+ buf = kmalloc(2, GFP_KERNEL);
45367+ if (buf == NULL)
45368+ return -ENOMEM;
45369+ result = kmalloc(64, GFP_KERNEL);
45370+ if (result == NULL) {
45371+ kfree(buf);
45372+ return -ENOMEM;
45373+ }
45374+
45375+ buf[0] = CINERGYT2_EP1_CONTROL_STREAM_TRANSFER;
45376+ buf[1] = enable ? 1 : 0;
45377+
45378+ retval = dvb_usb_generic_rw(adap->dev, buf, 2, result, 64, 0);
45379+
45380+ kfree(buf);
45381+ kfree(result);
45382+ return retval;
45383 }
45384
45385 static int cinergyt2_power_ctrl(struct dvb_usb_device *d, int enable)
45386 {
45387- char buf[] = { CINERGYT2_EP1_SLEEP_MODE, enable ? 0 : 1 };
45388- char state[3];
45389- return dvb_usb_generic_rw(d, buf, sizeof(buf), state, sizeof(state), 0);
45390+ char *buf;
45391+ char *state;
45392+ int retval;
45393+
45394+ buf = kmalloc(2, GFP_KERNEL);
45395+ if (buf == NULL)
45396+ return -ENOMEM;
45397+ state = kmalloc(3, GFP_KERNEL);
45398+ if (state == NULL) {
45399+ kfree(buf);
45400+ return -ENOMEM;
45401+ }
45402+
45403+ buf[0] = CINERGYT2_EP1_SLEEP_MODE;
45404+ buf[1] = enable ? 1 : 0;
45405+
45406+ retval = dvb_usb_generic_rw(d, buf, 2, state, 3, 0);
45407+
45408+ kfree(buf);
45409+ kfree(state);
45410+ return retval;
45411 }
45412
45413 static int cinergyt2_frontend_attach(struct dvb_usb_adapter *adap)
45414 {
45415- char query[] = { CINERGYT2_EP1_GET_FIRMWARE_VERSION };
45416- char state[3];
45417+ char *query;
45418+ char *state;
45419 int ret;
45420+ query = kmalloc(1, GFP_KERNEL);
45421+ if (query == NULL)
45422+ return -ENOMEM;
45423+ state = kmalloc(3, GFP_KERNEL);
45424+ if (state == NULL) {
45425+ kfree(query);
45426+ return -ENOMEM;
45427+ }
45428+
45429+ query[0] = CINERGYT2_EP1_GET_FIRMWARE_VERSION;
45430
45431 adap->fe_adap[0].fe = cinergyt2_fe_attach(adap->dev);
45432
45433- ret = dvb_usb_generic_rw(adap->dev, query, sizeof(query), state,
45434- sizeof(state), 0);
45435+ ret = dvb_usb_generic_rw(adap->dev, query, 1, state, 3, 0);
45436 if (ret < 0) {
45437 deb_rc("cinergyt2_power_ctrl() Failed to retrieve sleep "
45438 "state info\n");
45439@@ -80,7 +124,8 @@ static int cinergyt2_frontend_attach(struct dvb_usb_adapter *adap)
45440
45441 /* Copy this pointer as we are gonna need it in the release phase */
45442 cinergyt2_usb_device = adap->dev;
45443-
45444+ kfree(query);
45445+ kfree(state);
45446 return 0;
45447 }
45448
45449@@ -141,12 +186,23 @@ static int repeatable_keys[] = {
45450 static int cinergyt2_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
45451 {
45452 struct cinergyt2_state *st = d->priv;
45453- u8 key[5] = {0, 0, 0, 0, 0}, cmd = CINERGYT2_EP1_GET_RC_EVENTS;
45454+ u8 *key, *cmd;
45455 int i;
45456
45457+ cmd = kmalloc(1, GFP_KERNEL);
45458+ if (cmd == NULL)
45459+ return -EINVAL;
45460+ key = kzalloc(5, GFP_KERNEL);
45461+ if (key == NULL) {
45462+ kfree(cmd);
45463+ return -EINVAL;
45464+ }
45465+
45466+ cmd[0] = CINERGYT2_EP1_GET_RC_EVENTS;
45467+
45468 *state = REMOTE_NO_KEY_PRESSED;
45469
45470- dvb_usb_generic_rw(d, &cmd, 1, key, sizeof(key), 0);
45471+ dvb_usb_generic_rw(d, cmd, 1, key, 5, 0);
45472 if (key[4] == 0xff) {
45473 /* key repeat */
45474 st->rc_counter++;
45475@@ -157,12 +213,12 @@ static int cinergyt2_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
45476 *event = d->last_event;
45477 deb_rc("repeat key, event %x\n",
45478 *event);
45479- return 0;
45480+ goto out;
45481 }
45482 }
45483 deb_rc("repeated key (non repeatable)\n");
45484 }
45485- return 0;
45486+ goto out;
45487 }
45488
45489 /* hack to pass checksum on the custom field */
45490@@ -174,6 +230,9 @@ static int cinergyt2_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
45491
45492 deb_rc("key: %*ph\n", 5, key);
45493 }
45494+out:
45495+ kfree(cmd);
45496+ kfree(key);
45497 return 0;
45498 }
45499
45500diff --git a/drivers/media/usb/dvb-usb/cinergyT2-fe.c b/drivers/media/usb/dvb-usb/cinergyT2-fe.c
45501index c890fe4..f9b2ae6 100644
45502--- a/drivers/media/usb/dvb-usb/cinergyT2-fe.c
45503+++ b/drivers/media/usb/dvb-usb/cinergyT2-fe.c
45504@@ -145,103 +145,176 @@ static int cinergyt2_fe_read_status(struct dvb_frontend *fe,
45505 fe_status_t *status)
45506 {
45507 struct cinergyt2_fe_state *state = fe->demodulator_priv;
45508- struct dvbt_get_status_msg result;
45509- u8 cmd[] = { CINERGYT2_EP1_GET_TUNER_STATUS };
45510+ struct dvbt_get_status_msg *result;
45511+ u8 *cmd;
45512 int ret;
45513
45514- ret = dvb_usb_generic_rw(state->d, cmd, sizeof(cmd), (u8 *)&result,
45515- sizeof(result), 0);
45516+ cmd = kmalloc(1, GFP_KERNEL);
45517+ if (cmd == NULL)
45518+ return -ENOMEM;
45519+ result = kmalloc(sizeof(*result), GFP_KERNEL);
45520+ if (result == NULL) {
45521+ kfree(cmd);
45522+ return -ENOMEM;
45523+ }
45524+
45525+ cmd[0] = CINERGYT2_EP1_GET_TUNER_STATUS;
45526+
45527+ ret = dvb_usb_generic_rw(state->d, cmd, 1, (u8 *)result,
45528+ sizeof(*result), 0);
45529 if (ret < 0)
45530- return ret;
45531+ goto out;
45532
45533 *status = 0;
45534
45535- if (0xffff - le16_to_cpu(result.gain) > 30)
45536+ if (0xffff - le16_to_cpu(result->gain) > 30)
45537 *status |= FE_HAS_SIGNAL;
45538- if (result.lock_bits & (1 << 6))
45539+ if (result->lock_bits & (1 << 6))
45540 *status |= FE_HAS_LOCK;
45541- if (result.lock_bits & (1 << 5))
45542+ if (result->lock_bits & (1 << 5))
45543 *status |= FE_HAS_SYNC;
45544- if (result.lock_bits & (1 << 4))
45545+ if (result->lock_bits & (1 << 4))
45546 *status |= FE_HAS_CARRIER;
45547- if (result.lock_bits & (1 << 1))
45548+ if (result->lock_bits & (1 << 1))
45549 *status |= FE_HAS_VITERBI;
45550
45551 if ((*status & (FE_HAS_CARRIER | FE_HAS_VITERBI | FE_HAS_SYNC)) !=
45552 (FE_HAS_CARRIER | FE_HAS_VITERBI | FE_HAS_SYNC))
45553 *status &= ~FE_HAS_LOCK;
45554
45555- return 0;
45556+out:
45557+ kfree(cmd);
45558+ kfree(result);
45559+ return ret;
45560 }
45561
45562 static int cinergyt2_fe_read_ber(struct dvb_frontend *fe, u32 *ber)
45563 {
45564 struct cinergyt2_fe_state *state = fe->demodulator_priv;
45565- struct dvbt_get_status_msg status;
45566- char cmd[] = { CINERGYT2_EP1_GET_TUNER_STATUS };
45567+ struct dvbt_get_status_msg *status;
45568+ char *cmd;
45569 int ret;
45570
45571- ret = dvb_usb_generic_rw(state->d, cmd, sizeof(cmd), (char *)&status,
45572- sizeof(status), 0);
45573+ cmd = kmalloc(1, GFP_KERNEL);
45574+ if (cmd == NULL)
45575+ return -ENOMEM;
45576+ status = kmalloc(sizeof(*status), GFP_KERNEL);
45577+ if (status == NULL) {
45578+ kfree(cmd);
45579+ return -ENOMEM;
45580+ }
45581+
45582+ cmd[0] = CINERGYT2_EP1_GET_TUNER_STATUS;
45583+
45584+ ret = dvb_usb_generic_rw(state->d, cmd, 1, (char *)status,
45585+ sizeof(*status), 0);
45586 if (ret < 0)
45587- return ret;
45588+ goto out;
45589
45590- *ber = le32_to_cpu(status.viterbi_error_rate);
45591+ *ber = le32_to_cpu(status->viterbi_error_rate);
45592+out:
45593+ kfree(cmd);
45594+ kfree(status);
45595 return 0;
45596 }
45597
45598 static int cinergyt2_fe_read_unc_blocks(struct dvb_frontend *fe, u32 *unc)
45599 {
45600 struct cinergyt2_fe_state *state = fe->demodulator_priv;
45601- struct dvbt_get_status_msg status;
45602- u8 cmd[] = { CINERGYT2_EP1_GET_TUNER_STATUS };
45603+ struct dvbt_get_status_msg *status;
45604+ u8 *cmd;
45605 int ret;
45606
45607- ret = dvb_usb_generic_rw(state->d, cmd, sizeof(cmd), (u8 *)&status,
45608- sizeof(status), 0);
45609+ cmd = kmalloc(1, GFP_KERNEL);
45610+ if (cmd == NULL)
45611+ return -ENOMEM;
45612+ status = kmalloc(sizeof(*status), GFP_KERNEL);
45613+ if (status == NULL) {
45614+ kfree(cmd);
45615+ return -ENOMEM;
45616+ }
45617+
45618+ cmd[0] = CINERGYT2_EP1_GET_TUNER_STATUS;
45619+
45620+ ret = dvb_usb_generic_rw(state->d, cmd, 1, (u8 *)status,
45621+ sizeof(*status), 0);
45622 if (ret < 0) {
45623 err("cinergyt2_fe_read_unc_blocks() Failed! (Error=%d)\n",
45624 ret);
45625- return ret;
45626+ goto out;
45627 }
45628- *unc = le32_to_cpu(status.uncorrected_block_count);
45629- return 0;
45630+ *unc = le32_to_cpu(status->uncorrected_block_count);
45631+
45632+out:
45633+ kfree(cmd);
45634+ kfree(status);
45635+ return ret;
45636 }
45637
45638 static int cinergyt2_fe_read_signal_strength(struct dvb_frontend *fe,
45639 u16 *strength)
45640 {
45641 struct cinergyt2_fe_state *state = fe->demodulator_priv;
45642- struct dvbt_get_status_msg status;
45643- char cmd[] = { CINERGYT2_EP1_GET_TUNER_STATUS };
45644+ struct dvbt_get_status_msg *status;
45645+ char *cmd;
45646 int ret;
45647
45648- ret = dvb_usb_generic_rw(state->d, cmd, sizeof(cmd), (char *)&status,
45649- sizeof(status), 0);
45650+ cmd = kmalloc(1, GFP_KERNEL);
45651+ if (cmd == NULL)
45652+ return -ENOMEM;
45653+ status = kmalloc(sizeof(*status), GFP_KERNEL);
45654+ if (status == NULL) {
45655+ kfree(cmd);
45656+ return -ENOMEM;
45657+ }
45658+
45659+ cmd[0] = CINERGYT2_EP1_GET_TUNER_STATUS;
45660+
45661+ ret = dvb_usb_generic_rw(state->d, cmd, 1, (char *)status,
45662+ sizeof(*status), 0);
45663 if (ret < 0) {
45664 err("cinergyt2_fe_read_signal_strength() Failed!"
45665 " (Error=%d)\n", ret);
45666- return ret;
45667+ goto out;
45668 }
45669- *strength = (0xffff - le16_to_cpu(status.gain));
45670+ *strength = (0xffff - le16_to_cpu(status->gain));
45671+
45672+out:
45673+ kfree(cmd);
45674+ kfree(status);
45675 return 0;
45676 }
45677
45678 static int cinergyt2_fe_read_snr(struct dvb_frontend *fe, u16 *snr)
45679 {
45680 struct cinergyt2_fe_state *state = fe->demodulator_priv;
45681- struct dvbt_get_status_msg status;
45682- char cmd[] = { CINERGYT2_EP1_GET_TUNER_STATUS };
45683+ struct dvbt_get_status_msg *status;
45684+ char *cmd;
45685 int ret;
45686
45687- ret = dvb_usb_generic_rw(state->d, cmd, sizeof(cmd), (char *)&status,
45688- sizeof(status), 0);
45689+ cmd = kmalloc(1, GFP_KERNEL);
45690+ if (cmd == NULL)
45691+ return -ENOMEM;
45692+ status = kmalloc(sizeof(*status), GFP_KERNEL);
45693+ if (status == NULL) {
45694+ kfree(cmd);
45695+ return -ENOMEM;
45696+ }
45697+
45698+ cmd[0] = CINERGYT2_EP1_GET_TUNER_STATUS;
45699+
45700+ ret = dvb_usb_generic_rw(state->d, cmd, 1, (char *)status,
45701+ sizeof(*status), 0);
45702 if (ret < 0) {
45703 err("cinergyt2_fe_read_snr() Failed! (Error=%d)\n", ret);
45704- return ret;
45705+ goto out;
45706 }
45707- *snr = (status.snr << 8) | status.snr;
45708- return 0;
45709+ *snr = (status->snr << 8) | status->snr;
45710+
45711+out:
45712+ kfree(cmd);
45713+ kfree(status);
45714+ return ret;
45715 }
45716
45717 static int cinergyt2_fe_init(struct dvb_frontend *fe)
45718@@ -266,35 +339,46 @@ static int cinergyt2_fe_set_frontend(struct dvb_frontend *fe)
45719 {
45720 struct dtv_frontend_properties *fep = &fe->dtv_property_cache;
45721 struct cinergyt2_fe_state *state = fe->demodulator_priv;
45722- struct dvbt_set_parameters_msg param;
45723- char result[2];
45724+ struct dvbt_set_parameters_msg *param;
45725+ char *result;
45726 int err;
45727
45728- param.cmd = CINERGYT2_EP1_SET_TUNER_PARAMETERS;
45729- param.tps = cpu_to_le16(compute_tps(fep));
45730- param.freq = cpu_to_le32(fep->frequency / 1000);
45731- param.flags = 0;
45732+ result = kmalloc(2, GFP_KERNEL);
45733+ if (result == NULL)
45734+ return -ENOMEM;
45735+ param = kmalloc(sizeof(*param), GFP_KERNEL);
45736+ if (param == NULL) {
45737+ kfree(result);
45738+ return -ENOMEM;
45739+ }
45740+
45741+ param->cmd = CINERGYT2_EP1_SET_TUNER_PARAMETERS;
45742+ param->tps = cpu_to_le16(compute_tps(fep));
45743+ param->freq = cpu_to_le32(fep->frequency / 1000);
45744+ param->flags = 0;
45745
45746 switch (fep->bandwidth_hz) {
45747 default:
45748 case 8000000:
45749- param.bandwidth = 8;
45750+ param->bandwidth = 8;
45751 break;
45752 case 7000000:
45753- param.bandwidth = 7;
45754+ param->bandwidth = 7;
45755 break;
45756 case 6000000:
45757- param.bandwidth = 6;
45758+ param->bandwidth = 6;
45759 break;
45760 }
45761
45762 err = dvb_usb_generic_rw(state->d,
45763- (char *)&param, sizeof(param),
45764- result, sizeof(result), 0);
45765+ (char *)param, sizeof(*param),
45766+ result, 2, 0);
45767 if (err < 0)
45768 err("cinergyt2_fe_set_frontend() Failed! err=%d\n", err);
45769
45770- return (err < 0) ? err : 0;
45771+ kfree(result);
45772+ kfree(param);
45773+ return err;
45774 }
45775
45776 static void cinergyt2_fe_release(struct dvb_frontend *fe)
45777diff --git a/drivers/media/usb/dvb-usb/dvb-usb-firmware.c b/drivers/media/usb/dvb-usb/dvb-usb-firmware.c
45778index 733a7ff..f8b52e3 100644
45779--- a/drivers/media/usb/dvb-usb/dvb-usb-firmware.c
45780+++ b/drivers/media/usb/dvb-usb/dvb-usb-firmware.c
45781@@ -35,42 +35,57 @@ static int usb_cypress_writemem(struct usb_device *udev,u16 addr,u8 *data, u8 le
45782
45783 int usb_cypress_load_firmware(struct usb_device *udev, const struct firmware *fw, int type)
45784 {
45785- struct hexline hx;
45786- u8 reset;
45787+ struct hexline *hx;
45788+ u8 *reset;
45789 int ret,pos=0;
45790
45791+ reset = kmalloc(1, GFP_KERNEL);
45792+ if (reset == NULL)
45793+ return -ENOMEM;
45794+
45795+ hx = kmalloc(sizeof(struct hexline), GFP_KERNEL);
45796+ if (hx == NULL) {
45797+ kfree(reset);
45798+ return -ENOMEM;
45799+ }
45800+
45801 /* stop the CPU */
45802- reset = 1;
45803- if ((ret = usb_cypress_writemem(udev,cypress[type].cpu_cs_register,&reset,1)) != 1)
45804+ reset[0] = 1;
45805+ if ((ret = usb_cypress_writemem(udev,cypress[type].cpu_cs_register,reset,1)) != 1)
45806 err("could not stop the USB controller CPU.");
45807
45808- while ((ret = dvb_usb_get_hexline(fw,&hx,&pos)) > 0) {
45809- deb_fw("writing to address 0x%04x (buffer: 0x%02x %02x)\n",hx.addr,hx.len,hx.chk);
45810- ret = usb_cypress_writemem(udev,hx.addr,hx.data,hx.len);
45811+ while ((ret = dvb_usb_get_hexline(fw,hx,&pos)) > 0) {
45812+ deb_fw("writing to address 0x%04x (buffer: 0x%02x %02x)\n",hx->addr,hx->len,hx->chk);
45813+ ret = usb_cypress_writemem(udev,hx->addr,hx->data,hx->len);
45814
45815- if (ret != hx.len) {
45816+ if (ret != hx->len) {
45817 err("error while transferring firmware "
45818 "(transferred size: %d, block size: %d)",
45819- ret,hx.len);
45820+ ret,hx->len);
45821 ret = -EINVAL;
45822 break;
45823 }
45824 }
45825 if (ret < 0) {
45826 err("firmware download failed at %d with %d",pos,ret);
45827+ kfree(reset);
45828+ kfree(hx);
45829 return ret;
45830 }
45831
45832 if (ret == 0) {
45833 /* restart the CPU */
45834- reset = 0;
45835- if (ret || usb_cypress_writemem(udev,cypress[type].cpu_cs_register,&reset,1) != 1) {
45836+ reset[0] = 0;
45837+ if (ret || usb_cypress_writemem(udev,cypress[type].cpu_cs_register,reset,1) != 1) {
45838 err("could not restart the USB controller CPU.");
45839 ret = -EINVAL;
45840 }
45841 } else
45842 ret = -EIO;
45843
45844+ kfree(reset);
45845+ kfree(hx);
45846+
45847 return ret;
45848 }
45849 EXPORT_SYMBOL(usb_cypress_load_firmware);
45850diff --git a/drivers/media/usb/dvb-usb/dw2102.c b/drivers/media/usb/dvb-usb/dw2102.c
45851index 1a3df10..57997a5 100644
45852--- a/drivers/media/usb/dvb-usb/dw2102.c
45853+++ b/drivers/media/usb/dvb-usb/dw2102.c
45854@@ -118,7 +118,7 @@ struct su3000_state {
45855
45856 struct s6x0_state {
45857 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
45858-};
45859+} __no_const;
45860
45861 /* debug */
45862 static int dvb_usb_dw2102_debug;
45863diff --git a/drivers/media/usb/dvb-usb/technisat-usb2.c b/drivers/media/usb/dvb-usb/technisat-usb2.c
45864index 6b0b8b6b..4038398 100644
45865--- a/drivers/media/usb/dvb-usb/technisat-usb2.c
45866+++ b/drivers/media/usb/dvb-usb/technisat-usb2.c
45867@@ -87,8 +87,11 @@ struct technisat_usb2_state {
45868 static int technisat_usb2_i2c_access(struct usb_device *udev,
45869 u8 device_addr, u8 *tx, u8 txlen, u8 *rx, u8 rxlen)
45870 {
45871- u8 b[64];
45872- int ret, actual_length;
45873+ u8 *b = kmalloc(64, GFP_KERNEL);
45874+ int ret, actual_length, error = 0;
45875+
45876+ if (b == NULL)
45877+ return -ENOMEM;
45878
45879 deb_i2c("i2c-access: %02x, tx: ", device_addr);
45880 debug_dump(tx, txlen, deb_i2c);
45881@@ -121,7 +124,8 @@ static int technisat_usb2_i2c_access(struct usb_device *udev,
45882
45883 if (ret < 0) {
45884 err("i2c-error: out failed %02x = %d", device_addr, ret);
45885- return -ENODEV;
45886+ error = -ENODEV;
45887+ goto out;
45888 }
45889
45890 ret = usb_bulk_msg(udev,
45891@@ -129,7 +133,8 @@ static int technisat_usb2_i2c_access(struct usb_device *udev,
45892 b, 64, &actual_length, 1000);
45893 if (ret < 0) {
45894 err("i2c-error: in failed %02x = %d", device_addr, ret);
45895- return -ENODEV;
45896+ error = -ENODEV;
45897+ goto out;
45898 }
45899
45900 if (b[0] != I2C_STATUS_OK) {
45901@@ -137,8 +142,10 @@ static int technisat_usb2_i2c_access(struct usb_device *udev,
45902 /* handle tuner-i2c-nak */
45903 if (!(b[0] == I2C_STATUS_NAK &&
45904 device_addr == 0x60
45905- /* && device_is_technisat_usb2 */))
45906- return -ENODEV;
45907+ /* && device_is_technisat_usb2 */)) {
45908+ error = -ENODEV;
45909+ goto out;
45910+ }
45911 }
45912
45913 deb_i2c("status: %d, ", b[0]);
45914@@ -152,7 +159,9 @@ static int technisat_usb2_i2c_access(struct usb_device *udev,
45915
45916 deb_i2c("\n");
45917
45918- return 0;
45919+out:
45920+ kfree(b);
45921+ return error;
45922 }
45923
45924 static int technisat_usb2_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg *msg,
45925@@ -224,14 +233,16 @@ static int technisat_usb2_set_led(struct dvb_usb_device *d, int red, enum techni
45926 {
45927 int ret;
45928
45929- u8 led[8] = {
45930- red ? SET_RED_LED_VENDOR_REQUEST : SET_GREEN_LED_VENDOR_REQUEST,
45931- 0
45932- };
45933+ u8 *led = kzalloc(8, GFP_KERNEL);
45934+
45935+ if (led == NULL)
45936+ return -ENOMEM;
45937
45938 if (disable_led_control && state != TECH_LED_OFF)
45939 return 0;
45940
45941+ led[0] = red ? SET_RED_LED_VENDOR_REQUEST : SET_GREEN_LED_VENDOR_REQUEST;
45942+
45943 switch (state) {
45944 case TECH_LED_ON:
45945 led[1] = 0x82;
45946@@ -263,16 +274,22 @@ static int technisat_usb2_set_led(struct dvb_usb_device *d, int red, enum techni
45947 red ? SET_RED_LED_VENDOR_REQUEST : SET_GREEN_LED_VENDOR_REQUEST,
45948 USB_TYPE_VENDOR | USB_DIR_OUT,
45949 0, 0,
45950- led, sizeof(led), 500);
45951+ led, 8, 500);
45952
45953 mutex_unlock(&d->i2c_mutex);
45954+
45955+ kfree(led);
45956+
45957 return ret;
45958 }
45959
45960 static int technisat_usb2_set_led_timer(struct dvb_usb_device *d, u8 red, u8 green)
45961 {
45962 int ret;
45963- u8 b = 0;
45964+ u8 *b = kzalloc(1, GFP_KERNEL);
45965+
45966+ if (b == NULL)
45967+ return -ENOMEM;
45968
45969 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
45970 return -EAGAIN;
45971@@ -281,10 +298,12 @@ static int technisat_usb2_set_led_timer(struct dvb_usb_device *d, u8 red, u8 gre
45972 SET_LED_TIMER_DIVIDER_VENDOR_REQUEST,
45973 USB_TYPE_VENDOR | USB_DIR_OUT,
45974 (red << 8) | green, 0,
45975- &b, 1, 500);
45976+ b, 1, 500);
45977
45978 mutex_unlock(&d->i2c_mutex);
45979
45980+ kfree(b);
45981+
45982 return ret;
45983 }
45984
45985@@ -328,7 +347,7 @@ static int technisat_usb2_identify_state(struct usb_device *udev,
45986 struct dvb_usb_device_description **desc, int *cold)
45987 {
45988 int ret;
45989- u8 version[3];
45990+ u8 *version = kmalloc(3, GFP_KERNEL);
45991
45992 /* first select the interface */
45993 if (usb_set_interface(udev, 0, 1) != 0)
45994@@ -338,11 +357,14 @@ static int technisat_usb2_identify_state(struct usb_device *udev,
45995
45996 *cold = 0; /* by default do not download a firmware - just in case something is wrong */
45997
45998+ if (version == NULL)
45999+ return 0;
46000+
46001 ret = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
46002 GET_VERSION_INFO_VENDOR_REQUEST,
46003 USB_TYPE_VENDOR | USB_DIR_IN,
46004 0, 0,
46005- version, sizeof(version), 500);
46006+ version, 3, 500);
46007
46008 if (ret < 0)
46009 *cold = 1;
46010@@ -351,6 +373,8 @@ static int technisat_usb2_identify_state(struct usb_device *udev,
46011 *cold = 0;
46012 }
46013
46014+ kfree(version);
46015+
46016 return 0;
46017 }
46018
46019@@ -591,10 +615,15 @@ static int technisat_usb2_frontend_attach(struct dvb_usb_adapter *a)
46020
46021 static int technisat_usb2_get_ir(struct dvb_usb_device *d)
46022 {
46023- u8 buf[62], *b;
46024+ u8 *buf, *b;
46025 int ret;
46026 struct ir_raw_event ev;
46027
46028+ buf = kmalloc(62, GFP_KERNEL);
46029+
46030+ if (buf == NULL)
46031+ return -ENOMEM;
46032+
46033 buf[0] = GET_IR_DATA_VENDOR_REQUEST;
46034 buf[1] = 0x08;
46035 buf[2] = 0x8f;
46036@@ -617,16 +646,20 @@ static int technisat_usb2_get_ir(struct dvb_usb_device *d)
46037 GET_IR_DATA_VENDOR_REQUEST,
46038 USB_TYPE_VENDOR | USB_DIR_IN,
46039 0x8080, 0,
46040- buf, sizeof(buf), 500);
46041+ buf, 62, 500);
46042
46043 unlock:
46044 mutex_unlock(&d->i2c_mutex);
46045
46046- if (ret < 0)
46047+ if (ret < 0) {
46048+ kfree(buf);
46049 return ret;
46050+ }
46051
46052- if (ret == 1)
46053+ if (ret == 1) {
46054+ kfree(buf);
46055 return 0; /* no key pressed */
46056+ }
46057
46058 /* decoding */
46059 b = buf+1;
46060@@ -653,6 +686,8 @@ unlock:
46061
46062 ir_raw_event_handle(d->rc_dev);
46063
46064+ kfree(buf);
46065+
46066 return 1;
46067 }
46068
46069diff --git a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
46070index e502a5f..2a27f40 100644
46071--- a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
46072+++ b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
46073@@ -427,7 +427,7 @@ static int get_v4l2_buffer32(struct v4l2_buffer *kp, struct v4l2_buffer32 __user
46074 * by passing a very big num_planes value */
46075 uplane = compat_alloc_user_space(num_planes *
46076 sizeof(struct v4l2_plane));
46077- kp->m.planes = (__force struct v4l2_plane *)uplane;
46078+ kp->m.planes = (__force_kernel struct v4l2_plane *)uplane;
46079
46080 while (--num_planes >= 0) {
46081 ret = get_v4l2_plane32(uplane, uplane32, kp->memory);
46082@@ -498,7 +498,7 @@ static int put_v4l2_buffer32(struct v4l2_buffer *kp, struct v4l2_buffer32 __user
46083 if (num_planes == 0)
46084 return 0;
46085
46086- uplane = (__force struct v4l2_plane __user *)kp->m.planes;
46087+ uplane = (struct v4l2_plane __force_user *)kp->m.planes;
46088 if (get_user(p, &up->m.planes))
46089 return -EFAULT;
46090 uplane32 = compat_ptr(p);
46091@@ -562,7 +562,7 @@ static int get_v4l2_framebuffer32(struct v4l2_framebuffer *kp, struct v4l2_frame
46092 get_user(kp->flags, &up->flags) ||
46093 copy_from_user(&kp->fmt, &up->fmt, sizeof(up->fmt)))
46094 return -EFAULT;
46095- kp->base = (__force void *)compat_ptr(tmp);
46096+ kp->base = (__force_kernel void *)compat_ptr(tmp);
46097 return 0;
46098 }
46099
46100@@ -667,7 +667,7 @@ static int get_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext
46101 n * sizeof(struct v4l2_ext_control32)))
46102 return -EFAULT;
46103 kcontrols = compat_alloc_user_space(n * sizeof(struct v4l2_ext_control));
46104- kp->controls = (__force struct v4l2_ext_control *)kcontrols;
46105+ kp->controls = (__force_kernel struct v4l2_ext_control *)kcontrols;
46106 while (--n >= 0) {
46107 u32 id;
46108
46109@@ -694,7 +694,7 @@ static int put_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext
46110 {
46111 struct v4l2_ext_control32 __user *ucontrols;
46112 struct v4l2_ext_control __user *kcontrols =
46113- (__force struct v4l2_ext_control __user *)kp->controls;
46114+ (struct v4l2_ext_control __force_user *)kp->controls;
46115 int n = kp->count;
46116 compat_caddr_t p;
46117
46118@@ -778,7 +778,7 @@ static int get_v4l2_edid32(struct v4l2_edid *kp, struct v4l2_edid32 __user *up)
46119 get_user(tmp, &up->edid) ||
46120 copy_from_user(kp->reserved, up->reserved, sizeof(kp->reserved)))
46121 return -EFAULT;
46122- kp->edid = (__force u8 *)compat_ptr(tmp);
46123+ kp->edid = (__force_kernel u8 *)compat_ptr(tmp);
46124 return 0;
46125 }
46126
46127diff --git a/drivers/media/v4l2-core/v4l2-device.c b/drivers/media/v4l2-core/v4l2-device.c
46128index 015f92a..59e311e 100644
46129--- a/drivers/media/v4l2-core/v4l2-device.c
46130+++ b/drivers/media/v4l2-core/v4l2-device.c
46131@@ -75,9 +75,9 @@ int v4l2_device_put(struct v4l2_device *v4l2_dev)
46132 EXPORT_SYMBOL_GPL(v4l2_device_put);
46133
46134 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
46135- atomic_t *instance)
46136+ atomic_unchecked_t *instance)
46137 {
46138- int num = atomic_inc_return(instance) - 1;
46139+ int num = atomic_inc_return_unchecked(instance) - 1;
46140 int len = strlen(basename);
46141
46142 if (basename[len - 1] >= '0' && basename[len - 1] <= '9')
46143diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c
46144index 9ccb19a..d131468 100644
46145--- a/drivers/media/v4l2-core/v4l2-ioctl.c
46146+++ b/drivers/media/v4l2-core/v4l2-ioctl.c
46147@@ -2142,7 +2142,8 @@ struct v4l2_ioctl_info {
46148 struct file *file, void *fh, void *p);
46149 } u;
46150 void (*debug)(const void *arg, bool write_only);
46151-};
46152+} __do_const;
46153+typedef struct v4l2_ioctl_info __no_const v4l2_ioctl_info_no_const;
46154
46155 /* This control needs a priority check */
46156 #define INFO_FL_PRIO (1 << 0)
46157@@ -2326,7 +2327,7 @@ static long __video_do_ioctl(struct file *file,
46158 struct video_device *vfd = video_devdata(file);
46159 const struct v4l2_ioctl_ops *ops = vfd->ioctl_ops;
46160 bool write_only = false;
46161- struct v4l2_ioctl_info default_info;
46162+ v4l2_ioctl_info_no_const default_info;
46163 const struct v4l2_ioctl_info *info;
46164 void *fh = file->private_data;
46165 struct v4l2_fh *vfh = NULL;
46166@@ -2413,7 +2414,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
46167 ret = -EINVAL;
46168 break;
46169 }
46170- *user_ptr = (void __user *)buf->m.planes;
46171+ *user_ptr = (void __force_user *)buf->m.planes;
46172 *kernel_ptr = (void **)&buf->m.planes;
46173 *array_size = sizeof(struct v4l2_plane) * buf->length;
46174 ret = 1;
46175@@ -2430,7 +2431,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
46176 ret = -EINVAL;
46177 break;
46178 }
46179- *user_ptr = (void __user *)edid->edid;
46180+ *user_ptr = (void __force_user *)edid->edid;
46181 *kernel_ptr = (void **)&edid->edid;
46182 *array_size = edid->blocks * 128;
46183 ret = 1;
46184@@ -2448,7 +2449,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
46185 ret = -EINVAL;
46186 break;
46187 }
46188- *user_ptr = (void __user *)ctrls->controls;
46189+ *user_ptr = (void __force_user *)ctrls->controls;
46190 *kernel_ptr = (void **)&ctrls->controls;
46191 *array_size = sizeof(struct v4l2_ext_control)
46192 * ctrls->count;
46193@@ -2549,7 +2550,7 @@ video_usercopy(struct file *file, unsigned int cmd, unsigned long arg,
46194 }
46195
46196 if (has_array_args) {
46197- *kernel_ptr = (void __force *)user_ptr;
46198+ *kernel_ptr = (void __force_kernel *)user_ptr;
46199 if (copy_to_user(user_ptr, mbuf, array_size))
46200 err = -EFAULT;
46201 goto out_array_args;
46202diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
46203index 187f836..679544b 100644
46204--- a/drivers/message/fusion/mptbase.c
46205+++ b/drivers/message/fusion/mptbase.c
46206@@ -6746,8 +6746,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
46207 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
46208 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
46209
46210+#ifdef CONFIG_GRKERNSEC_HIDESYM
46211+ seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
46212+#else
46213 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
46214 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
46215+#endif
46216+
46217 /*
46218 * Rounding UP to nearest 4-kB boundary here...
46219 */
46220@@ -6760,7 +6765,11 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
46221 ioc->facts.GlobalCredits);
46222
46223 seq_printf(m, " Frames @ 0x%p (Dma @ 0x%p)\n",
46224+#ifdef CONFIG_GRKERNSEC_HIDESYM
46225+ NULL, NULL);
46226+#else
46227 (void *)ioc->alloc, (void *)(ulong)ioc->alloc_dma);
46228+#endif
46229 sz = (ioc->reply_sz * ioc->reply_depth) + 128;
46230 seq_printf(m, " {CurRepSz=%d} x {CurRepDepth=%d} = %d bytes ^= 0x%x\n",
46231 ioc->reply_sz, ioc->reply_depth, ioc->reply_sz*ioc->reply_depth, sz);
46232diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
46233index 0707fa2..70ca794 100644
46234--- a/drivers/message/fusion/mptsas.c
46235+++ b/drivers/message/fusion/mptsas.c
46236@@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
46237 return 0;
46238 }
46239
46240+static inline void
46241+mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
46242+{
46243+ if (phy_info->port_details) {
46244+ phy_info->port_details->rphy = rphy;
46245+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
46246+ ioc->name, rphy));
46247+ }
46248+
46249+ if (rphy) {
46250+ dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
46251+ &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
46252+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
46253+ ioc->name, rphy, rphy->dev.release));
46254+ }
46255+}
46256+
46257 /* no mutex */
46258 static void
46259 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
46260@@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
46261 return NULL;
46262 }
46263
46264-static inline void
46265-mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
46266-{
46267- if (phy_info->port_details) {
46268- phy_info->port_details->rphy = rphy;
46269- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
46270- ioc->name, rphy));
46271- }
46272-
46273- if (rphy) {
46274- dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
46275- &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
46276- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
46277- ioc->name, rphy, rphy->dev.release));
46278- }
46279-}
46280-
46281 static inline struct sas_port *
46282 mptsas_get_port(struct mptsas_phyinfo *phy_info)
46283 {
46284diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
46285index b7d87cd..3fb36da 100644
46286--- a/drivers/message/i2o/i2o_proc.c
46287+++ b/drivers/message/i2o/i2o_proc.c
46288@@ -255,12 +255,6 @@ static char *scsi_devices[] = {
46289 "Array Controller Device"
46290 };
46291
46292-static char *chtostr(char *tmp, u8 *chars, int n)
46293-{
46294- tmp[0] = 0;
46295- return strncat(tmp, (char *)chars, n);
46296-}
46297-
46298 static int i2o_report_query_status(struct seq_file *seq, int block_status,
46299 char *group)
46300 {
46301@@ -707,9 +701,9 @@ static int i2o_seq_show_status(struct seq_file *seq, void *v)
46302 static int i2o_seq_show_hw(struct seq_file *seq, void *v)
46303 {
46304 struct i2o_controller *c = (struct i2o_controller *)seq->private;
46305- static u32 work32[5];
46306- static u8 *work8 = (u8 *) work32;
46307- static u16 *work16 = (u16 *) work32;
46308+ u32 work32[5];
46309+ u8 *work8 = (u8 *) work32;
46310+ u16 *work16 = (u16 *) work32;
46311 int token;
46312 u32 hwcap;
46313
46314@@ -790,7 +784,6 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
46315 } *result;
46316
46317 i2o_exec_execute_ddm_table ddm_table;
46318- char tmp[28 + 1];
46319
46320 result = kmalloc(sizeof(*result), GFP_KERNEL);
46321 if (!result)
46322@@ -825,8 +818,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
46323
46324 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
46325 seq_printf(seq, "%-#8x", ddm_table.module_id);
46326- seq_printf(seq, "%-29s",
46327- chtostr(tmp, ddm_table.module_name_version, 28));
46328+ seq_printf(seq, "%-.28s", ddm_table.module_name_version);
46329 seq_printf(seq, "%9d ", ddm_table.data_size);
46330 seq_printf(seq, "%8d", ddm_table.code_size);
46331
46332@@ -893,7 +885,6 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
46333
46334 i2o_driver_result_table *result;
46335 i2o_driver_store_table *dst;
46336- char tmp[28 + 1];
46337
46338 result = kmalloc(sizeof(i2o_driver_result_table), GFP_KERNEL);
46339 if (result == NULL)
46340@@ -928,9 +919,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
46341
46342 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
46343 seq_printf(seq, "%-#8x", dst->module_id);
46344- seq_printf(seq, "%-29s",
46345- chtostr(tmp, dst->module_name_version, 28));
46346- seq_printf(seq, "%-9s", chtostr(tmp, dst->date, 8));
46347+ seq_printf(seq, "%-.28s", dst->module_name_version);
46348+ seq_printf(seq, "%-.8s", dst->date);
46349 seq_printf(seq, "%8d ", dst->module_size);
46350 seq_printf(seq, "%8d ", dst->mpb_size);
46351 seq_printf(seq, "0x%04x", dst->module_flags);
46352@@ -1246,11 +1236,10 @@ static int i2o_seq_show_authorized_users(struct seq_file *seq, void *v)
46353 static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
46354 {
46355 struct i2o_device *d = (struct i2o_device *)seq->private;
46356- static u32 work32[128]; // allow for "stuff" + up to 256 byte (max) serial number
46357+ u32 work32[128]; // allow for "stuff" + up to 256 byte (max) serial number
46358 // == (allow) 512d bytes (max)
46359- static u16 *work16 = (u16 *) work32;
46360+ u16 *work16 = (u16 *) work32;
46361 int token;
46362- char tmp[16 + 1];
46363
46364 token = i2o_parm_field_get(d, 0xF100, -1, &work32, sizeof(work32));
46365
46366@@ -1262,14 +1251,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
46367 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
46368 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
46369 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
46370- seq_printf(seq, "Vendor info : %s\n",
46371- chtostr(tmp, (u8 *) (work32 + 2), 16));
46372- seq_printf(seq, "Product info : %s\n",
46373- chtostr(tmp, (u8 *) (work32 + 6), 16));
46374- seq_printf(seq, "Description : %s\n",
46375- chtostr(tmp, (u8 *) (work32 + 10), 16));
46376- seq_printf(seq, "Product rev. : %s\n",
46377- chtostr(tmp, (u8 *) (work32 + 14), 8));
46378+ seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
46379+ seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
46380+ seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
46381+ seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
46382
46383 seq_printf(seq, "Serial number : ");
46384 print_serial_number(seq, (u8 *) (work32 + 16),
46385@@ -1306,8 +1291,6 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
46386 u8 pad[256]; // allow up to 256 byte (max) serial number
46387 } result;
46388
46389- char tmp[24 + 1];
46390-
46391 token = i2o_parm_field_get(d, 0xF101, -1, &result, sizeof(result));
46392
46393 if (token < 0) {
46394@@ -1316,10 +1299,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
46395 }
46396
46397 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
46398- seq_printf(seq, "Module name : %s\n",
46399- chtostr(tmp, result.module_name, 24));
46400- seq_printf(seq, "Module revision : %s\n",
46401- chtostr(tmp, result.module_rev, 8));
46402+ seq_printf(seq, "Module name : %.24s\n", result.module_name);
46403+ seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
46404
46405 seq_printf(seq, "Serial number : ");
46406 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
46407@@ -1343,8 +1324,6 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
46408 u8 instance_number[4];
46409 } result;
46410
46411- char tmp[64 + 1];
46412-
46413 token = i2o_parm_field_get(d, 0xF102, -1, &result, sizeof(result));
46414
46415 if (token < 0) {
46416@@ -1352,14 +1331,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
46417 return 0;
46418 }
46419
46420- seq_printf(seq, "Device name : %s\n",
46421- chtostr(tmp, result.device_name, 64));
46422- seq_printf(seq, "Service name : %s\n",
46423- chtostr(tmp, result.service_name, 64));
46424- seq_printf(seq, "Physical name : %s\n",
46425- chtostr(tmp, result.physical_location, 64));
46426- seq_printf(seq, "Instance number : %s\n",
46427- chtostr(tmp, result.instance_number, 4));
46428+ seq_printf(seq, "Device name : %.64s\n", result.device_name);
46429+ seq_printf(seq, "Service name : %.64s\n", result.service_name);
46430+ seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
46431+ seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
46432
46433 return 0;
46434 }
46435@@ -1368,9 +1343,9 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
46436 static int i2o_seq_show_sgl_limits(struct seq_file *seq, void *v)
46437 {
46438 struct i2o_device *d = (struct i2o_device *)seq->private;
46439- static u32 work32[12];
46440- static u16 *work16 = (u16 *) work32;
46441- static u8 *work8 = (u8 *) work32;
46442+ u32 work32[12];
46443+ u16 *work16 = (u16 *) work32;
46444+ u8 *work8 = (u8 *) work32;
46445 int token;
46446
46447 token = i2o_parm_field_get(d, 0xF103, -1, &work32, sizeof(work32));
46448diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
46449index 92752fb..a7494f6 100644
46450--- a/drivers/message/i2o/iop.c
46451+++ b/drivers/message/i2o/iop.c
46452@@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
46453
46454 spin_lock_irqsave(&c->context_list_lock, flags);
46455
46456- if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
46457- atomic_inc(&c->context_list_counter);
46458+ if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
46459+ atomic_inc_unchecked(&c->context_list_counter);
46460
46461- entry->context = atomic_read(&c->context_list_counter);
46462+ entry->context = atomic_read_unchecked(&c->context_list_counter);
46463
46464 list_add(&entry->list, &c->context_list);
46465
46466@@ -1076,7 +1076,7 @@ struct i2o_controller *i2o_iop_alloc(void)
46467
46468 #if BITS_PER_LONG == 64
46469 spin_lock_init(&c->context_list_lock);
46470- atomic_set(&c->context_list_counter, 0);
46471+ atomic_set_unchecked(&c->context_list_counter, 0);
46472 INIT_LIST_HEAD(&c->context_list);
46473 #endif
46474
46475diff --git a/drivers/mfd/ab8500-debugfs.c b/drivers/mfd/ab8500-debugfs.c
46476index b2c7e3b..85aa4764 100644
46477--- a/drivers/mfd/ab8500-debugfs.c
46478+++ b/drivers/mfd/ab8500-debugfs.c
46479@@ -100,7 +100,7 @@ static int irq_last;
46480 static u32 *irq_count;
46481 static int num_irqs;
46482
46483-static struct device_attribute **dev_attr;
46484+static device_attribute_no_const **dev_attr;
46485 static char **event_name;
46486
46487 static u8 avg_sample = SAMPLE_16;
46488diff --git a/drivers/mfd/max8925-i2c.c b/drivers/mfd/max8925-i2c.c
46489index c880c89..45a7c68 100644
46490--- a/drivers/mfd/max8925-i2c.c
46491+++ b/drivers/mfd/max8925-i2c.c
46492@@ -152,7 +152,7 @@ static int max8925_probe(struct i2c_client *client,
46493 const struct i2c_device_id *id)
46494 {
46495 struct max8925_platform_data *pdata = dev_get_platdata(&client->dev);
46496- static struct max8925_chip *chip;
46497+ struct max8925_chip *chip;
46498 struct device_node *node = client->dev.of_node;
46499
46500 if (node && !pdata) {
46501diff --git a/drivers/mfd/tps65910.c b/drivers/mfd/tps65910.c
46502index 7612d89..70549c2 100644
46503--- a/drivers/mfd/tps65910.c
46504+++ b/drivers/mfd/tps65910.c
46505@@ -230,7 +230,7 @@ static int tps65910_irq_init(struct tps65910 *tps65910, int irq,
46506 struct tps65910_platform_data *pdata)
46507 {
46508 int ret = 0;
46509- static struct regmap_irq_chip *tps6591x_irqs_chip;
46510+ struct regmap_irq_chip *tps6591x_irqs_chip;
46511
46512 if (!irq) {
46513 dev_warn(tps65910->dev, "No interrupt support, no core IRQ\n");
46514diff --git a/drivers/mfd/twl4030-irq.c b/drivers/mfd/twl4030-irq.c
46515index 1b772ef..01e77d33 100644
46516--- a/drivers/mfd/twl4030-irq.c
46517+++ b/drivers/mfd/twl4030-irq.c
46518@@ -34,6 +34,7 @@
46519 #include <linux/of.h>
46520 #include <linux/irqdomain.h>
46521 #include <linux/i2c/twl.h>
46522+#include <asm/pgtable.h>
46523
46524 #include "twl-core.h"
46525
46526@@ -729,10 +730,12 @@ int twl4030_init_irq(struct device *dev, int irq_num)
46527 * Install an irq handler for each of the SIH modules;
46528 * clone dummy irq_chip since PIH can't *do* anything
46529 */
46530- twl4030_irq_chip = dummy_irq_chip;
46531- twl4030_irq_chip.name = "twl4030";
46532+ pax_open_kernel();
46533+ memcpy((void *)&twl4030_irq_chip, &dummy_irq_chip, sizeof twl4030_irq_chip);
46534+ *(const char **)&twl4030_irq_chip.name = "twl4030";
46535
46536- twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
46537+ *(void **)&twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
46538+ pax_close_kernel();
46539
46540 for (i = irq_base; i < irq_end; i++) {
46541 irq_set_chip_and_handler(i, &twl4030_irq_chip,
46542diff --git a/drivers/misc/c2port/core.c b/drivers/misc/c2port/core.c
46543index 464419b..64bae8d 100644
46544--- a/drivers/misc/c2port/core.c
46545+++ b/drivers/misc/c2port/core.c
46546@@ -922,7 +922,9 @@ struct c2port_device *c2port_device_register(char *name,
46547 goto error_idr_alloc;
46548 c2dev->id = ret;
46549
46550- bin_attr_flash_data.size = ops->blocks_num * ops->block_size;
46551+ pax_open_kernel();
46552+ *(size_t *)&bin_attr_flash_data.size = ops->blocks_num * ops->block_size;
46553+ pax_close_kernel();
46554
46555 c2dev->dev = device_create(c2port_class, NULL, 0, c2dev,
46556 "c2port%d", c2dev->id);
46557diff --git a/drivers/misc/eeprom/sunxi_sid.c b/drivers/misc/eeprom/sunxi_sid.c
46558index 3f2b625..945e179 100644
46559--- a/drivers/misc/eeprom/sunxi_sid.c
46560+++ b/drivers/misc/eeprom/sunxi_sid.c
46561@@ -126,7 +126,9 @@ static int sunxi_sid_probe(struct platform_device *pdev)
46562
46563 platform_set_drvdata(pdev, sid_data);
46564
46565- sid_bin_attr.size = sid_data->keysize;
46566+ pax_open_kernel();
46567+ *(size_t *)&sid_bin_attr.size = sid_data->keysize;
46568+ pax_close_kernel();
46569 if (device_create_bin_file(&pdev->dev, &sid_bin_attr))
46570 return -ENODEV;
46571
46572diff --git a/drivers/misc/kgdbts.c b/drivers/misc/kgdbts.c
46573index 36f5d52..32311c3 100644
46574--- a/drivers/misc/kgdbts.c
46575+++ b/drivers/misc/kgdbts.c
46576@@ -834,7 +834,7 @@ static void run_plant_and_detach_test(int is_early)
46577 char before[BREAK_INSTR_SIZE];
46578 char after[BREAK_INSTR_SIZE];
46579
46580- probe_kernel_read(before, (char *)kgdbts_break_test,
46581+ probe_kernel_read(before, ktla_ktva((char *)kgdbts_break_test),
46582 BREAK_INSTR_SIZE);
46583 init_simple_test();
46584 ts.tst = plant_and_detach_test;
46585@@ -842,7 +842,7 @@ static void run_plant_and_detach_test(int is_early)
46586 /* Activate test with initial breakpoint */
46587 if (!is_early)
46588 kgdb_breakpoint();
46589- probe_kernel_read(after, (char *)kgdbts_break_test,
46590+ probe_kernel_read(after, ktla_ktva((char *)kgdbts_break_test),
46591 BREAK_INSTR_SIZE);
46592 if (memcmp(before, after, BREAK_INSTR_SIZE)) {
46593 printk(KERN_CRIT "kgdbts: ERROR kgdb corrupted memory\n");
46594diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
46595index 3ef4627..8d00486 100644
46596--- a/drivers/misc/lis3lv02d/lis3lv02d.c
46597+++ b/drivers/misc/lis3lv02d/lis3lv02d.c
46598@@ -497,7 +497,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
46599 * the lid is closed. This leads to interrupts as soon as a little move
46600 * is done.
46601 */
46602- atomic_inc(&lis3->count);
46603+ atomic_inc_unchecked(&lis3->count);
46604
46605 wake_up_interruptible(&lis3->misc_wait);
46606 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
46607@@ -583,7 +583,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
46608 if (lis3->pm_dev)
46609 pm_runtime_get_sync(lis3->pm_dev);
46610
46611- atomic_set(&lis3->count, 0);
46612+ atomic_set_unchecked(&lis3->count, 0);
46613 return 0;
46614 }
46615
46616@@ -615,7 +615,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
46617 add_wait_queue(&lis3->misc_wait, &wait);
46618 while (true) {
46619 set_current_state(TASK_INTERRUPTIBLE);
46620- data = atomic_xchg(&lis3->count, 0);
46621+ data = atomic_xchg_unchecked(&lis3->count, 0);
46622 if (data)
46623 break;
46624
46625@@ -656,7 +656,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
46626 struct lis3lv02d, miscdev);
46627
46628 poll_wait(file, &lis3->misc_wait, wait);
46629- if (atomic_read(&lis3->count))
46630+ if (atomic_read_unchecked(&lis3->count))
46631 return POLLIN | POLLRDNORM;
46632 return 0;
46633 }
46634diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
46635index c439c82..1f20f57 100644
46636--- a/drivers/misc/lis3lv02d/lis3lv02d.h
46637+++ b/drivers/misc/lis3lv02d/lis3lv02d.h
46638@@ -297,7 +297,7 @@ struct lis3lv02d {
46639 struct input_polled_dev *idev; /* input device */
46640 struct platform_device *pdev; /* platform device */
46641 struct regulator_bulk_data regulators[2];
46642- atomic_t count; /* interrupt count after last read */
46643+ atomic_unchecked_t count; /* interrupt count after last read */
46644 union axis_conversion ac; /* hw -> logical axis */
46645 int mapped_btns[3];
46646
46647diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
46648index 2f30bad..c4c13d0 100644
46649--- a/drivers/misc/sgi-gru/gruhandles.c
46650+++ b/drivers/misc/sgi-gru/gruhandles.c
46651@@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
46652 unsigned long nsec;
46653
46654 nsec = CLKS2NSEC(clks);
46655- atomic_long_inc(&mcs_op_statistics[op].count);
46656- atomic_long_add(nsec, &mcs_op_statistics[op].total);
46657+ atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
46658+ atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
46659 if (mcs_op_statistics[op].max < nsec)
46660 mcs_op_statistics[op].max = nsec;
46661 }
46662diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
46663index 4f76359..cdfcb2e 100644
46664--- a/drivers/misc/sgi-gru/gruprocfs.c
46665+++ b/drivers/misc/sgi-gru/gruprocfs.c
46666@@ -32,9 +32,9 @@
46667
46668 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
46669
46670-static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
46671+static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
46672 {
46673- unsigned long val = atomic_long_read(v);
46674+ unsigned long val = atomic_long_read_unchecked(v);
46675
46676 seq_printf(s, "%16lu %s\n", val, id);
46677 }
46678@@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
46679
46680 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
46681 for (op = 0; op < mcsop_last; op++) {
46682- count = atomic_long_read(&mcs_op_statistics[op].count);
46683- total = atomic_long_read(&mcs_op_statistics[op].total);
46684+ count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
46685+ total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
46686 max = mcs_op_statistics[op].max;
46687 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
46688 count ? total / count : 0, max);
46689diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
46690index 5c3ce24..4915ccb 100644
46691--- a/drivers/misc/sgi-gru/grutables.h
46692+++ b/drivers/misc/sgi-gru/grutables.h
46693@@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
46694 * GRU statistics.
46695 */
46696 struct gru_stats_s {
46697- atomic_long_t vdata_alloc;
46698- atomic_long_t vdata_free;
46699- atomic_long_t gts_alloc;
46700- atomic_long_t gts_free;
46701- atomic_long_t gms_alloc;
46702- atomic_long_t gms_free;
46703- atomic_long_t gts_double_allocate;
46704- atomic_long_t assign_context;
46705- atomic_long_t assign_context_failed;
46706- atomic_long_t free_context;
46707- atomic_long_t load_user_context;
46708- atomic_long_t load_kernel_context;
46709- atomic_long_t lock_kernel_context;
46710- atomic_long_t unlock_kernel_context;
46711- atomic_long_t steal_user_context;
46712- atomic_long_t steal_kernel_context;
46713- atomic_long_t steal_context_failed;
46714- atomic_long_t nopfn;
46715- atomic_long_t asid_new;
46716- atomic_long_t asid_next;
46717- atomic_long_t asid_wrap;
46718- atomic_long_t asid_reuse;
46719- atomic_long_t intr;
46720- atomic_long_t intr_cbr;
46721- atomic_long_t intr_tfh;
46722- atomic_long_t intr_spurious;
46723- atomic_long_t intr_mm_lock_failed;
46724- atomic_long_t call_os;
46725- atomic_long_t call_os_wait_queue;
46726- atomic_long_t user_flush_tlb;
46727- atomic_long_t user_unload_context;
46728- atomic_long_t user_exception;
46729- atomic_long_t set_context_option;
46730- atomic_long_t check_context_retarget_intr;
46731- atomic_long_t check_context_unload;
46732- atomic_long_t tlb_dropin;
46733- atomic_long_t tlb_preload_page;
46734- atomic_long_t tlb_dropin_fail_no_asid;
46735- atomic_long_t tlb_dropin_fail_upm;
46736- atomic_long_t tlb_dropin_fail_invalid;
46737- atomic_long_t tlb_dropin_fail_range_active;
46738- atomic_long_t tlb_dropin_fail_idle;
46739- atomic_long_t tlb_dropin_fail_fmm;
46740- atomic_long_t tlb_dropin_fail_no_exception;
46741- atomic_long_t tfh_stale_on_fault;
46742- atomic_long_t mmu_invalidate_range;
46743- atomic_long_t mmu_invalidate_page;
46744- atomic_long_t flush_tlb;
46745- atomic_long_t flush_tlb_gru;
46746- atomic_long_t flush_tlb_gru_tgh;
46747- atomic_long_t flush_tlb_gru_zero_asid;
46748+ atomic_long_unchecked_t vdata_alloc;
46749+ atomic_long_unchecked_t vdata_free;
46750+ atomic_long_unchecked_t gts_alloc;
46751+ atomic_long_unchecked_t gts_free;
46752+ atomic_long_unchecked_t gms_alloc;
46753+ atomic_long_unchecked_t gms_free;
46754+ atomic_long_unchecked_t gts_double_allocate;
46755+ atomic_long_unchecked_t assign_context;
46756+ atomic_long_unchecked_t assign_context_failed;
46757+ atomic_long_unchecked_t free_context;
46758+ atomic_long_unchecked_t load_user_context;
46759+ atomic_long_unchecked_t load_kernel_context;
46760+ atomic_long_unchecked_t lock_kernel_context;
46761+ atomic_long_unchecked_t unlock_kernel_context;
46762+ atomic_long_unchecked_t steal_user_context;
46763+ atomic_long_unchecked_t steal_kernel_context;
46764+ atomic_long_unchecked_t steal_context_failed;
46765+ atomic_long_unchecked_t nopfn;
46766+ atomic_long_unchecked_t asid_new;
46767+ atomic_long_unchecked_t asid_next;
46768+ atomic_long_unchecked_t asid_wrap;
46769+ atomic_long_unchecked_t asid_reuse;
46770+ atomic_long_unchecked_t intr;
46771+ atomic_long_unchecked_t intr_cbr;
46772+ atomic_long_unchecked_t intr_tfh;
46773+ atomic_long_unchecked_t intr_spurious;
46774+ atomic_long_unchecked_t intr_mm_lock_failed;
46775+ atomic_long_unchecked_t call_os;
46776+ atomic_long_unchecked_t call_os_wait_queue;
46777+ atomic_long_unchecked_t user_flush_tlb;
46778+ atomic_long_unchecked_t user_unload_context;
46779+ atomic_long_unchecked_t user_exception;
46780+ atomic_long_unchecked_t set_context_option;
46781+ atomic_long_unchecked_t check_context_retarget_intr;
46782+ atomic_long_unchecked_t check_context_unload;
46783+ atomic_long_unchecked_t tlb_dropin;
46784+ atomic_long_unchecked_t tlb_preload_page;
46785+ atomic_long_unchecked_t tlb_dropin_fail_no_asid;
46786+ atomic_long_unchecked_t tlb_dropin_fail_upm;
46787+ atomic_long_unchecked_t tlb_dropin_fail_invalid;
46788+ atomic_long_unchecked_t tlb_dropin_fail_range_active;
46789+ atomic_long_unchecked_t tlb_dropin_fail_idle;
46790+ atomic_long_unchecked_t tlb_dropin_fail_fmm;
46791+ atomic_long_unchecked_t tlb_dropin_fail_no_exception;
46792+ atomic_long_unchecked_t tfh_stale_on_fault;
46793+ atomic_long_unchecked_t mmu_invalidate_range;
46794+ atomic_long_unchecked_t mmu_invalidate_page;
46795+ atomic_long_unchecked_t flush_tlb;
46796+ atomic_long_unchecked_t flush_tlb_gru;
46797+ atomic_long_unchecked_t flush_tlb_gru_tgh;
46798+ atomic_long_unchecked_t flush_tlb_gru_zero_asid;
46799
46800- atomic_long_t copy_gpa;
46801- atomic_long_t read_gpa;
46802+ atomic_long_unchecked_t copy_gpa;
46803+ atomic_long_unchecked_t read_gpa;
46804
46805- atomic_long_t mesq_receive;
46806- atomic_long_t mesq_receive_none;
46807- atomic_long_t mesq_send;
46808- atomic_long_t mesq_send_failed;
46809- atomic_long_t mesq_noop;
46810- atomic_long_t mesq_send_unexpected_error;
46811- atomic_long_t mesq_send_lb_overflow;
46812- atomic_long_t mesq_send_qlimit_reached;
46813- atomic_long_t mesq_send_amo_nacked;
46814- atomic_long_t mesq_send_put_nacked;
46815- atomic_long_t mesq_page_overflow;
46816- atomic_long_t mesq_qf_locked;
46817- atomic_long_t mesq_qf_noop_not_full;
46818- atomic_long_t mesq_qf_switch_head_failed;
46819- atomic_long_t mesq_qf_unexpected_error;
46820- atomic_long_t mesq_noop_unexpected_error;
46821- atomic_long_t mesq_noop_lb_overflow;
46822- atomic_long_t mesq_noop_qlimit_reached;
46823- atomic_long_t mesq_noop_amo_nacked;
46824- atomic_long_t mesq_noop_put_nacked;
46825- atomic_long_t mesq_noop_page_overflow;
46826+ atomic_long_unchecked_t mesq_receive;
46827+ atomic_long_unchecked_t mesq_receive_none;
46828+ atomic_long_unchecked_t mesq_send;
46829+ atomic_long_unchecked_t mesq_send_failed;
46830+ atomic_long_unchecked_t mesq_noop;
46831+ atomic_long_unchecked_t mesq_send_unexpected_error;
46832+ atomic_long_unchecked_t mesq_send_lb_overflow;
46833+ atomic_long_unchecked_t mesq_send_qlimit_reached;
46834+ atomic_long_unchecked_t mesq_send_amo_nacked;
46835+ atomic_long_unchecked_t mesq_send_put_nacked;
46836+ atomic_long_unchecked_t mesq_page_overflow;
46837+ atomic_long_unchecked_t mesq_qf_locked;
46838+ atomic_long_unchecked_t mesq_qf_noop_not_full;
46839+ atomic_long_unchecked_t mesq_qf_switch_head_failed;
46840+ atomic_long_unchecked_t mesq_qf_unexpected_error;
46841+ atomic_long_unchecked_t mesq_noop_unexpected_error;
46842+ atomic_long_unchecked_t mesq_noop_lb_overflow;
46843+ atomic_long_unchecked_t mesq_noop_qlimit_reached;
46844+ atomic_long_unchecked_t mesq_noop_amo_nacked;
46845+ atomic_long_unchecked_t mesq_noop_put_nacked;
46846+ atomic_long_unchecked_t mesq_noop_page_overflow;
46847
46848 };
46849
46850@@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
46851 tghop_invalidate, mcsop_last};
46852
46853 struct mcs_op_statistic {
46854- atomic_long_t count;
46855- atomic_long_t total;
46856+ atomic_long_unchecked_t count;
46857+ atomic_long_unchecked_t total;
46858 unsigned long max;
46859 };
46860
46861@@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
46862
46863 #define STAT(id) do { \
46864 if (gru_options & OPT_STATS) \
46865- atomic_long_inc(&gru_stats.id); \
46866+ atomic_long_inc_unchecked(&gru_stats.id); \
46867 } while (0)
46868
46869 #ifdef CONFIG_SGI_GRU_DEBUG
46870diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
46871index c862cd4..0d176fe 100644
46872--- a/drivers/misc/sgi-xp/xp.h
46873+++ b/drivers/misc/sgi-xp/xp.h
46874@@ -288,7 +288,7 @@ struct xpc_interface {
46875 xpc_notify_func, void *);
46876 void (*received) (short, int, void *);
46877 enum xp_retval (*partid_to_nasids) (short, void *);
46878-};
46879+} __no_const;
46880
46881 extern struct xpc_interface xpc_interface;
46882
46883diff --git a/drivers/misc/sgi-xp/xp_main.c b/drivers/misc/sgi-xp/xp_main.c
46884index 01be66d..e3a0c7e 100644
46885--- a/drivers/misc/sgi-xp/xp_main.c
46886+++ b/drivers/misc/sgi-xp/xp_main.c
46887@@ -78,13 +78,13 @@ xpc_notloaded(void)
46888 }
46889
46890 struct xpc_interface xpc_interface = {
46891- (void (*)(int))xpc_notloaded,
46892- (void (*)(int))xpc_notloaded,
46893- (enum xp_retval(*)(short, int, u32, void *, u16))xpc_notloaded,
46894- (enum xp_retval(*)(short, int, u32, void *, u16, xpc_notify_func,
46895+ .connect = (void (*)(int))xpc_notloaded,
46896+ .disconnect = (void (*)(int))xpc_notloaded,
46897+ .send = (enum xp_retval(*)(short, int, u32, void *, u16))xpc_notloaded,
46898+ .send_notify = (enum xp_retval(*)(short, int, u32, void *, u16, xpc_notify_func,
46899 void *))xpc_notloaded,
46900- (void (*)(short, int, void *))xpc_notloaded,
46901- (enum xp_retval(*)(short, void *))xpc_notloaded
46902+ .received = (void (*)(short, int, void *))xpc_notloaded,
46903+ .partid_to_nasids = (enum xp_retval(*)(short, void *))xpc_notloaded
46904 };
46905 EXPORT_SYMBOL_GPL(xpc_interface);
46906
46907diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
46908index b94d5f7..7f494c5 100644
46909--- a/drivers/misc/sgi-xp/xpc.h
46910+++ b/drivers/misc/sgi-xp/xpc.h
46911@@ -835,6 +835,7 @@ struct xpc_arch_operations {
46912 void (*received_payload) (struct xpc_channel *, void *);
46913 void (*notify_senders_of_disconnect) (struct xpc_channel *);
46914 };
46915+typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
46916
46917 /* struct xpc_partition act_state values (for XPC HB) */
46918
46919@@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
46920 /* found in xpc_main.c */
46921 extern struct device *xpc_part;
46922 extern struct device *xpc_chan;
46923-extern struct xpc_arch_operations xpc_arch_ops;
46924+extern xpc_arch_operations_no_const xpc_arch_ops;
46925 extern int xpc_disengage_timelimit;
46926 extern int xpc_disengage_timedout;
46927 extern int xpc_activate_IRQ_rcvd;
46928diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
46929index 82dc574..8539ab2 100644
46930--- a/drivers/misc/sgi-xp/xpc_main.c
46931+++ b/drivers/misc/sgi-xp/xpc_main.c
46932@@ -166,7 +166,7 @@ static struct notifier_block xpc_die_notifier = {
46933 .notifier_call = xpc_system_die,
46934 };
46935
46936-struct xpc_arch_operations xpc_arch_ops;
46937+xpc_arch_operations_no_const xpc_arch_ops;
46938
46939 /*
46940 * Timer function to enforce the timelimit on the partition disengage.
46941@@ -1210,7 +1210,7 @@ xpc_system_die(struct notifier_block *nb, unsigned long event, void *_die_args)
46942
46943 if (((die_args->trapnr == X86_TRAP_MF) ||
46944 (die_args->trapnr == X86_TRAP_XF)) &&
46945- !user_mode_vm(die_args->regs))
46946+ !user_mode(die_args->regs))
46947 xpc_die_deactivate();
46948
46949 break;
46950diff --git a/drivers/mmc/card/block.c b/drivers/mmc/card/block.c
46951index 1fa4c80..59447c9 100644
46952--- a/drivers/mmc/card/block.c
46953+++ b/drivers/mmc/card/block.c
46954@@ -574,7 +574,7 @@ static int mmc_blk_ioctl_cmd(struct block_device *bdev,
46955 if (idata->ic.postsleep_min_us)
46956 usleep_range(idata->ic.postsleep_min_us, idata->ic.postsleep_max_us);
46957
46958- if (copy_to_user(&(ic_ptr->response), cmd.resp, sizeof(cmd.resp))) {
46959+ if (copy_to_user(ic_ptr->response, cmd.resp, sizeof(cmd.resp))) {
46960 err = -EFAULT;
46961 goto cmd_rel_host;
46962 }
46963diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c
46964index 7911e05..d0f9dda 100644
46965--- a/drivers/mmc/core/mmc_ops.c
46966+++ b/drivers/mmc/core/mmc_ops.c
46967@@ -267,7 +267,7 @@ mmc_send_cxd_data(struct mmc_card *card, struct mmc_host *host,
46968 void *data_buf;
46969 int is_on_stack;
46970
46971- is_on_stack = object_is_on_stack(buf);
46972+ is_on_stack = object_starts_on_stack(buf);
46973 if (is_on_stack) {
46974 /*
46975 * dma onto stack is unsafe/nonportable, but callers to this
46976diff --git a/drivers/mmc/host/dw_mmc.h b/drivers/mmc/host/dw_mmc.h
46977index 01b99e8..5c325e3 100644
46978--- a/drivers/mmc/host/dw_mmc.h
46979+++ b/drivers/mmc/host/dw_mmc.h
46980@@ -265,5 +265,5 @@ struct dw_mci_drv_data {
46981 int (*parse_dt)(struct dw_mci *host);
46982 int (*execute_tuning)(struct dw_mci_slot *slot, u32 opcode,
46983 struct dw_mci_tuning_data *tuning_data);
46984-};
46985+} __do_const;
46986 #endif /* _DW_MMC_H_ */
46987diff --git a/drivers/mmc/host/mmci.c b/drivers/mmc/host/mmci.c
46988index 43af791..86f4c48 100644
46989--- a/drivers/mmc/host/mmci.c
46990+++ b/drivers/mmc/host/mmci.c
46991@@ -1628,7 +1628,9 @@ static int mmci_probe(struct amba_device *dev,
46992 mmc->caps |= MMC_CAP_CMD23;
46993
46994 if (variant->busy_detect) {
46995- mmci_ops.card_busy = mmci_card_busy;
46996+ pax_open_kernel();
46997+ *(void **)&mmci_ops.card_busy = mmci_card_busy;
46998+ pax_close_kernel();
46999 mmci_write_datactrlreg(host, MCI_ST_DPSM_BUSYMODE);
47000 mmc->caps |= MMC_CAP_WAIT_WHILE_BUSY;
47001 mmc->max_busy_timeout = 0;
47002diff --git a/drivers/mmc/host/omap_hsmmc.c b/drivers/mmc/host/omap_hsmmc.c
47003index df27bb4..2085f0b 100644
47004--- a/drivers/mmc/host/omap_hsmmc.c
47005+++ b/drivers/mmc/host/omap_hsmmc.c
47006@@ -2111,7 +2111,9 @@ static int omap_hsmmc_probe(struct platform_device *pdev)
47007
47008 if (host->pdata->controller_flags & OMAP_HSMMC_BROKEN_MULTIBLOCK_READ) {
47009 dev_info(&pdev->dev, "multiblock reads disabled due to 35xx erratum 2.1.1.128; MMC read performance may suffer\n");
47010- omap_hsmmc_ops.multi_io_quirk = omap_hsmmc_multi_io_quirk;
47011+ pax_open_kernel();
47012+ *(void **)&omap_hsmmc_ops.multi_io_quirk = omap_hsmmc_multi_io_quirk;
47013+ pax_close_kernel();
47014 }
47015
47016 pm_runtime_enable(host->dev);
47017diff --git a/drivers/mmc/host/sdhci-esdhc-imx.c b/drivers/mmc/host/sdhci-esdhc-imx.c
47018index 587ee0e..b3bbcab 100644
47019--- a/drivers/mmc/host/sdhci-esdhc-imx.c
47020+++ b/drivers/mmc/host/sdhci-esdhc-imx.c
47021@@ -1054,9 +1054,12 @@ static int sdhci_esdhc_imx_probe(struct platform_device *pdev)
47022 host->mmc->caps |= MMC_CAP_1_8V_DDR;
47023 }
47024
47025- if (imx_data->socdata->flags & ESDHC_FLAG_MAN_TUNING)
47026- sdhci_esdhc_ops.platform_execute_tuning =
47027+ if (imx_data->socdata->flags & ESDHC_FLAG_MAN_TUNING) {
47028+ pax_open_kernel();
47029+ *(void **)&sdhci_esdhc_ops.platform_execute_tuning =
47030 esdhc_executing_tuning;
47031+ pax_close_kernel();
47032+ }
47033
47034 if (imx_data->socdata->flags & ESDHC_FLAG_STD_TUNING)
47035 writel(readl(host->ioaddr + ESDHC_TUNING_CTRL) |
47036diff --git a/drivers/mmc/host/sdhci-s3c.c b/drivers/mmc/host/sdhci-s3c.c
47037index 0ce6eb1..8dcce1b 100644
47038--- a/drivers/mmc/host/sdhci-s3c.c
47039+++ b/drivers/mmc/host/sdhci-s3c.c
47040@@ -584,9 +584,11 @@ static int sdhci_s3c_probe(struct platform_device *pdev)
47041 * we can use overriding functions instead of default.
47042 */
47043 if (sc->no_divider) {
47044- sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
47045- sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
47046- sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
47047+ pax_open_kernel();
47048+ *(void **)&sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
47049+ *(void **)&sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
47050+ *(void **)&sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
47051+ pax_close_kernel();
47052 }
47053
47054 /* It supports additional host capabilities if needed */
47055diff --git a/drivers/mtd/chips/cfi_cmdset_0020.c b/drivers/mtd/chips/cfi_cmdset_0020.c
47056index 423666b..81ff5eb 100644
47057--- a/drivers/mtd/chips/cfi_cmdset_0020.c
47058+++ b/drivers/mtd/chips/cfi_cmdset_0020.c
47059@@ -666,7 +666,7 @@ cfi_staa_writev(struct mtd_info *mtd, const struct kvec *vecs,
47060 size_t totlen = 0, thislen;
47061 int ret = 0;
47062 size_t buflen = 0;
47063- static char *buffer;
47064+ char *buffer;
47065
47066 if (!ECCBUF_SIZE) {
47067 /* We should fall back to a general writev implementation.
47068diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
47069index b3b7ca1..5dd4634 100644
47070--- a/drivers/mtd/nand/denali.c
47071+++ b/drivers/mtd/nand/denali.c
47072@@ -24,6 +24,7 @@
47073 #include <linux/slab.h>
47074 #include <linux/mtd/mtd.h>
47075 #include <linux/module.h>
47076+#include <linux/slab.h>
47077
47078 #include "denali.h"
47079
47080diff --git a/drivers/mtd/nand/gpmi-nand/gpmi-nand.c b/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
47081index 959cb9b..8520fe5 100644
47082--- a/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
47083+++ b/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
47084@@ -386,7 +386,7 @@ void prepare_data_dma(struct gpmi_nand_data *this, enum dma_data_direction dr)
47085
47086 /* first try to map the upper buffer directly */
47087 if (virt_addr_valid(this->upper_buf) &&
47088- !object_is_on_stack(this->upper_buf)) {
47089+ !object_starts_on_stack(this->upper_buf)) {
47090 sg_init_one(sgl, this->upper_buf, this->upper_len);
47091 ret = dma_map_sg(this->dev, sgl, 1, dr);
47092 if (ret == 0)
47093diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
47094index 51b9d6a..52af9a7 100644
47095--- a/drivers/mtd/nftlmount.c
47096+++ b/drivers/mtd/nftlmount.c
47097@@ -24,6 +24,7 @@
47098 #include <asm/errno.h>
47099 #include <linux/delay.h>
47100 #include <linux/slab.h>
47101+#include <linux/sched.h>
47102 #include <linux/mtd/mtd.h>
47103 #include <linux/mtd/nand.h>
47104 #include <linux/mtd/nftl.h>
47105diff --git a/drivers/mtd/sm_ftl.c b/drivers/mtd/sm_ftl.c
47106index c23184a..4115c41 100644
47107--- a/drivers/mtd/sm_ftl.c
47108+++ b/drivers/mtd/sm_ftl.c
47109@@ -56,7 +56,7 @@ static ssize_t sm_attr_show(struct device *dev, struct device_attribute *attr,
47110 #define SM_CIS_VENDOR_OFFSET 0x59
47111 static struct attribute_group *sm_create_sysfs_attributes(struct sm_ftl *ftl)
47112 {
47113- struct attribute_group *attr_group;
47114+ attribute_group_no_const *attr_group;
47115 struct attribute **attributes;
47116 struct sm_sysfs_attribute *vendor_attribute;
47117 char *vendor;
47118diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
47119index a5115fb..81b03f6 100644
47120--- a/drivers/net/bonding/bond_main.c
47121+++ b/drivers/net/bonding/bond_main.c
47122@@ -3749,7 +3749,7 @@ int bond_3ad_xor_xmit(struct sk_buff *skb, struct net_device *dev)
47123 bond_dev_queue_xmit(bond, skb, slave->dev);
47124 } else {
47125 dev_kfree_skb_any(skb);
47126- atomic_long_inc(&dev->tx_dropped);
47127+ atomic_long_inc_unchecked(&dev->tx_dropped);
47128 }
47129
47130 return NETDEV_TX_OK;
47131diff --git a/drivers/net/bonding/bond_netlink.c b/drivers/net/bonding/bond_netlink.c
47132index 45f09a6..f154f8d 100644
47133--- a/drivers/net/bonding/bond_netlink.c
47134+++ b/drivers/net/bonding/bond_netlink.c
47135@@ -585,7 +585,7 @@ nla_put_failure:
47136 return -EMSGSIZE;
47137 }
47138
47139-struct rtnl_link_ops bond_link_ops __read_mostly = {
47140+struct rtnl_link_ops bond_link_ops = {
47141 .kind = "bond",
47142 .priv_size = sizeof(struct bonding),
47143 .setup = bond_setup,
47144diff --git a/drivers/net/caif/caif_hsi.c b/drivers/net/caif/caif_hsi.c
47145index 5e40a8b..126bfda 100644
47146--- a/drivers/net/caif/caif_hsi.c
47147+++ b/drivers/net/caif/caif_hsi.c
47148@@ -1445,7 +1445,7 @@ err:
47149 return -ENODEV;
47150 }
47151
47152-static struct rtnl_link_ops caif_hsi_link_ops __read_mostly = {
47153+static struct rtnl_link_ops caif_hsi_link_ops = {
47154 .kind = "cfhsi",
47155 .priv_size = sizeof(struct cfhsi),
47156 .setup = cfhsi_setup,
47157diff --git a/drivers/net/can/Kconfig b/drivers/net/can/Kconfig
47158index 98d73aa..63ef9da 100644
47159--- a/drivers/net/can/Kconfig
47160+++ b/drivers/net/can/Kconfig
47161@@ -98,7 +98,7 @@ config CAN_JANZ_ICAN3
47162
47163 config CAN_FLEXCAN
47164 tristate "Support for Freescale FLEXCAN based chips"
47165- depends on ARM || PPC
47166+ depends on (ARM && CPU_LITTLE_ENDIAN) || PPC
47167 ---help---
47168 Say Y here if you want to support for Freescale FlexCAN.
47169
47170diff --git a/drivers/net/can/dev.c b/drivers/net/can/dev.c
47171index 2cfe501..477d4b5 100644
47172--- a/drivers/net/can/dev.c
47173+++ b/drivers/net/can/dev.c
47174@@ -868,7 +868,7 @@ static int can_newlink(struct net *src_net, struct net_device *dev,
47175 return -EOPNOTSUPP;
47176 }
47177
47178-static struct rtnl_link_ops can_link_ops __read_mostly = {
47179+static struct rtnl_link_ops can_link_ops = {
47180 .kind = "can",
47181 .maxtype = IFLA_CAN_MAX,
47182 .policy = can_policy,
47183diff --git a/drivers/net/can/vcan.c b/drivers/net/can/vcan.c
47184index 4e94057..32032ff 100644
47185--- a/drivers/net/can/vcan.c
47186+++ b/drivers/net/can/vcan.c
47187@@ -166,7 +166,7 @@ static void vcan_setup(struct net_device *dev)
47188 dev->destructor = free_netdev;
47189 }
47190
47191-static struct rtnl_link_ops vcan_link_ops __read_mostly = {
47192+static struct rtnl_link_ops vcan_link_ops = {
47193 .kind = "vcan",
47194 .setup = vcan_setup,
47195 };
47196diff --git a/drivers/net/dummy.c b/drivers/net/dummy.c
47197index ff435fb..d408b1f 100644
47198--- a/drivers/net/dummy.c
47199+++ b/drivers/net/dummy.c
47200@@ -149,7 +149,7 @@ static int dummy_validate(struct nlattr *tb[], struct nlattr *data[])
47201 return 0;
47202 }
47203
47204-static struct rtnl_link_ops dummy_link_ops __read_mostly = {
47205+static struct rtnl_link_ops dummy_link_ops = {
47206 .kind = "dummy",
47207 .setup = dummy_setup,
47208 .validate = dummy_validate,
47209diff --git a/drivers/net/ethernet/8390/ax88796.c b/drivers/net/ethernet/8390/ax88796.c
47210index 1d162cc..b546a75 100644
47211--- a/drivers/net/ethernet/8390/ax88796.c
47212+++ b/drivers/net/ethernet/8390/ax88796.c
47213@@ -889,9 +889,11 @@ static int ax_probe(struct platform_device *pdev)
47214 if (ax->plat->reg_offsets)
47215 ei_local->reg_offset = ax->plat->reg_offsets;
47216 else {
47217+ resource_size_t _mem_size = mem_size;
47218+ do_div(_mem_size, 0x18);
47219 ei_local->reg_offset = ax->reg_offsets;
47220 for (ret = 0; ret < 0x18; ret++)
47221- ax->reg_offsets[ret] = (mem_size / 0x18) * ret;
47222+ ax->reg_offsets[ret] = _mem_size * ret;
47223 }
47224
47225 if (!request_mem_region(mem->start, mem_size, pdev->name)) {
47226diff --git a/drivers/net/ethernet/altera/altera_tse_main.c b/drivers/net/ethernet/altera/altera_tse_main.c
47227index 4efc435..4ab9e14 100644
47228--- a/drivers/net/ethernet/altera/altera_tse_main.c
47229+++ b/drivers/net/ethernet/altera/altera_tse_main.c
47230@@ -1224,7 +1224,7 @@ static int tse_shutdown(struct net_device *dev)
47231 return 0;
47232 }
47233
47234-static struct net_device_ops altera_tse_netdev_ops = {
47235+static net_device_ops_no_const altera_tse_netdev_ops __read_only = {
47236 .ndo_open = tse_open,
47237 .ndo_stop = tse_shutdown,
47238 .ndo_start_xmit = tse_start_xmit,
47239@@ -1461,11 +1461,13 @@ static int altera_tse_probe(struct platform_device *pdev)
47240 ndev->netdev_ops = &altera_tse_netdev_ops;
47241 altera_tse_set_ethtool_ops(ndev);
47242
47243+ pax_open_kernel();
47244 altera_tse_netdev_ops.ndo_set_rx_mode = tse_set_rx_mode;
47245
47246 if (priv->hash_filter)
47247 altera_tse_netdev_ops.ndo_set_rx_mode =
47248 tse_set_rx_mode_hashfilter;
47249+ pax_close_kernel();
47250
47251 /* Scatter/gather IO is not supported,
47252 * so it is turned off
47253diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-common.h b/drivers/net/ethernet/amd/xgbe/xgbe-common.h
47254index caade30..3e257d9 100644
47255--- a/drivers/net/ethernet/amd/xgbe/xgbe-common.h
47256+++ b/drivers/net/ethernet/amd/xgbe/xgbe-common.h
47257@@ -1072,14 +1072,14 @@ do { \
47258 * operations, everything works on mask values.
47259 */
47260 #define XMDIO_READ(_pdata, _mmd, _reg) \
47261- ((_pdata)->hw_if.read_mmd_regs((_pdata), 0, \
47262+ ((_pdata)->hw_if->read_mmd_regs((_pdata), 0, \
47263 MII_ADDR_C45 | (_mmd << 16) | ((_reg) & 0xffff)))
47264
47265 #define XMDIO_READ_BITS(_pdata, _mmd, _reg, _mask) \
47266 (XMDIO_READ((_pdata), _mmd, _reg) & _mask)
47267
47268 #define XMDIO_WRITE(_pdata, _mmd, _reg, _val) \
47269- ((_pdata)->hw_if.write_mmd_regs((_pdata), 0, \
47270+ ((_pdata)->hw_if->write_mmd_regs((_pdata), 0, \
47271 MII_ADDR_C45 | (_mmd << 16) | ((_reg) & 0xffff), (_val)))
47272
47273 #define XMDIO_WRITE_BITS(_pdata, _mmd, _reg, _mask, _val) \
47274diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-dcb.c b/drivers/net/ethernet/amd/xgbe/xgbe-dcb.c
47275index 8a50b01..39c1ad0 100644
47276--- a/drivers/net/ethernet/amd/xgbe/xgbe-dcb.c
47277+++ b/drivers/net/ethernet/amd/xgbe/xgbe-dcb.c
47278@@ -187,7 +187,7 @@ static int xgbe_dcb_ieee_setets(struct net_device *netdev,
47279
47280 memcpy(pdata->ets, ets, sizeof(*pdata->ets));
47281
47282- pdata->hw_if.config_dcb_tc(pdata);
47283+ pdata->hw_if->config_dcb_tc(pdata);
47284
47285 return 0;
47286 }
47287@@ -226,7 +226,7 @@ static int xgbe_dcb_ieee_setpfc(struct net_device *netdev,
47288
47289 memcpy(pdata->pfc, pfc, sizeof(*pdata->pfc));
47290
47291- pdata->hw_if.config_dcb_pfc(pdata);
47292+ pdata->hw_if->config_dcb_pfc(pdata);
47293
47294 return 0;
47295 }
47296diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-desc.c b/drivers/net/ethernet/amd/xgbe/xgbe-desc.c
47297index 6fc5da0..61ac2cb 100644
47298--- a/drivers/net/ethernet/amd/xgbe/xgbe-desc.c
47299+++ b/drivers/net/ethernet/amd/xgbe/xgbe-desc.c
47300@@ -235,7 +235,7 @@ err_ring:
47301
47302 static void xgbe_wrapper_tx_descriptor_init(struct xgbe_prv_data *pdata)
47303 {
47304- struct xgbe_hw_if *hw_if = &pdata->hw_if;
47305+ struct xgbe_hw_if *hw_if = pdata->hw_if;
47306 struct xgbe_channel *channel;
47307 struct xgbe_ring *ring;
47308 struct xgbe_ring_data *rdata;
47309@@ -276,7 +276,7 @@ static void xgbe_wrapper_tx_descriptor_init(struct xgbe_prv_data *pdata)
47310
47311 static void xgbe_wrapper_rx_descriptor_init(struct xgbe_prv_data *pdata)
47312 {
47313- struct xgbe_hw_if *hw_if = &pdata->hw_if;
47314+ struct xgbe_hw_if *hw_if = pdata->hw_if;
47315 struct xgbe_channel *channel;
47316 struct xgbe_ring *ring;
47317 struct xgbe_ring_desc *rdesc;
47318@@ -505,7 +505,7 @@ err_out:
47319 static void xgbe_realloc_skb(struct xgbe_channel *channel)
47320 {
47321 struct xgbe_prv_data *pdata = channel->pdata;
47322- struct xgbe_hw_if *hw_if = &pdata->hw_if;
47323+ struct xgbe_hw_if *hw_if = pdata->hw_if;
47324 struct xgbe_ring *ring = channel->rx_ring;
47325 struct xgbe_ring_data *rdata;
47326 struct sk_buff *skb = NULL;
47327@@ -546,17 +546,12 @@ static void xgbe_realloc_skb(struct xgbe_channel *channel)
47328 DBGPR("<--xgbe_realloc_skb\n");
47329 }
47330
47331-void xgbe_init_function_ptrs_desc(struct xgbe_desc_if *desc_if)
47332-{
47333- DBGPR("-->xgbe_init_function_ptrs_desc\n");
47334-
47335- desc_if->alloc_ring_resources = xgbe_alloc_ring_resources;
47336- desc_if->free_ring_resources = xgbe_free_ring_resources;
47337- desc_if->map_tx_skb = xgbe_map_tx_skb;
47338- desc_if->realloc_skb = xgbe_realloc_skb;
47339- desc_if->unmap_skb = xgbe_unmap_skb;
47340- desc_if->wrapper_tx_desc_init = xgbe_wrapper_tx_descriptor_init;
47341- desc_if->wrapper_rx_desc_init = xgbe_wrapper_rx_descriptor_init;
47342-
47343- DBGPR("<--xgbe_init_function_ptrs_desc\n");
47344-}
47345+const struct xgbe_desc_if default_xgbe_desc_if = {
47346+ .alloc_ring_resources = xgbe_alloc_ring_resources,
47347+ .free_ring_resources = xgbe_free_ring_resources,
47348+ .map_tx_skb = xgbe_map_tx_skb,
47349+ .realloc_skb = xgbe_realloc_skb,
47350+ .unmap_skb = xgbe_unmap_skb,
47351+ .wrapper_tx_desc_init = xgbe_wrapper_tx_descriptor_init,
47352+ .wrapper_rx_desc_init = xgbe_wrapper_rx_descriptor_init,
47353+};
47354diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-dev.c b/drivers/net/ethernet/amd/xgbe/xgbe-dev.c
47355index 9da3a03..022f15c 100644
47356--- a/drivers/net/ethernet/amd/xgbe/xgbe-dev.c
47357+++ b/drivers/net/ethernet/amd/xgbe/xgbe-dev.c
47358@@ -2462,7 +2462,7 @@ static void xgbe_powerdown_rx(struct xgbe_prv_data *pdata)
47359
47360 static int xgbe_init(struct xgbe_prv_data *pdata)
47361 {
47362- struct xgbe_desc_if *desc_if = &pdata->desc_if;
47363+ struct xgbe_desc_if *desc_if = pdata->desc_if;
47364 int ret;
47365
47366 DBGPR("-->xgbe_init\n");
47367@@ -2524,101 +2524,96 @@ static int xgbe_init(struct xgbe_prv_data *pdata)
47368 return 0;
47369 }
47370
47371-void xgbe_init_function_ptrs_dev(struct xgbe_hw_if *hw_if)
47372-{
47373- DBGPR("-->xgbe_init_function_ptrs\n");
47374-
47375- hw_if->tx_complete = xgbe_tx_complete;
47376-
47377- hw_if->set_promiscuous_mode = xgbe_set_promiscuous_mode;
47378- hw_if->set_all_multicast_mode = xgbe_set_all_multicast_mode;
47379- hw_if->add_mac_addresses = xgbe_add_mac_addresses;
47380- hw_if->set_mac_address = xgbe_set_mac_address;
47381-
47382- hw_if->enable_rx_csum = xgbe_enable_rx_csum;
47383- hw_if->disable_rx_csum = xgbe_disable_rx_csum;
47384-
47385- hw_if->enable_rx_vlan_stripping = xgbe_enable_rx_vlan_stripping;
47386- hw_if->disable_rx_vlan_stripping = xgbe_disable_rx_vlan_stripping;
47387- hw_if->enable_rx_vlan_filtering = xgbe_enable_rx_vlan_filtering;
47388- hw_if->disable_rx_vlan_filtering = xgbe_disable_rx_vlan_filtering;
47389- hw_if->update_vlan_hash_table = xgbe_update_vlan_hash_table;
47390-
47391- hw_if->read_mmd_regs = xgbe_read_mmd_regs;
47392- hw_if->write_mmd_regs = xgbe_write_mmd_regs;
47393-
47394- hw_if->set_gmii_speed = xgbe_set_gmii_speed;
47395- hw_if->set_gmii_2500_speed = xgbe_set_gmii_2500_speed;
47396- hw_if->set_xgmii_speed = xgbe_set_xgmii_speed;
47397-
47398- hw_if->enable_tx = xgbe_enable_tx;
47399- hw_if->disable_tx = xgbe_disable_tx;
47400- hw_if->enable_rx = xgbe_enable_rx;
47401- hw_if->disable_rx = xgbe_disable_rx;
47402-
47403- hw_if->powerup_tx = xgbe_powerup_tx;
47404- hw_if->powerdown_tx = xgbe_powerdown_tx;
47405- hw_if->powerup_rx = xgbe_powerup_rx;
47406- hw_if->powerdown_rx = xgbe_powerdown_rx;
47407-
47408- hw_if->pre_xmit = xgbe_pre_xmit;
47409- hw_if->dev_read = xgbe_dev_read;
47410- hw_if->enable_int = xgbe_enable_int;
47411- hw_if->disable_int = xgbe_disable_int;
47412- hw_if->init = xgbe_init;
47413- hw_if->exit = xgbe_exit;
47414+const struct xgbe_hw_if default_xgbe_hw_if = {
47415+ .tx_complete = xgbe_tx_complete,
47416+
47417+ .set_promiscuous_mode = xgbe_set_promiscuous_mode,
47418+ .set_all_multicast_mode = xgbe_set_all_multicast_mode,
47419+ .add_mac_addresses = xgbe_add_mac_addresses,
47420+ .set_mac_address = xgbe_set_mac_address,
47421+
47422+ .enable_rx_csum = xgbe_enable_rx_csum,
47423+ .disable_rx_csum = xgbe_disable_rx_csum,
47424+
47425+ .enable_rx_vlan_stripping = xgbe_enable_rx_vlan_stripping,
47426+ .disable_rx_vlan_stripping = xgbe_disable_rx_vlan_stripping,
47427+ .enable_rx_vlan_filtering = xgbe_enable_rx_vlan_filtering,
47428+ .disable_rx_vlan_filtering = xgbe_disable_rx_vlan_filtering,
47429+ .update_vlan_hash_table = xgbe_update_vlan_hash_table,
47430+
47431+ .read_mmd_regs = xgbe_read_mmd_regs,
47432+ .write_mmd_regs = xgbe_write_mmd_regs,
47433+
47434+ .set_gmii_speed = xgbe_set_gmii_speed,
47435+ .set_gmii_2500_speed = xgbe_set_gmii_2500_speed,
47436+ .set_xgmii_speed = xgbe_set_xgmii_speed,
47437+
47438+ .enable_tx = xgbe_enable_tx,
47439+ .disable_tx = xgbe_disable_tx,
47440+ .enable_rx = xgbe_enable_rx,
47441+ .disable_rx = xgbe_disable_rx,
47442+
47443+ .powerup_tx = xgbe_powerup_tx,
47444+ .powerdown_tx = xgbe_powerdown_tx,
47445+ .powerup_rx = xgbe_powerup_rx,
47446+ .powerdown_rx = xgbe_powerdown_rx,
47447+
47448+ .pre_xmit = xgbe_pre_xmit,
47449+ .dev_read = xgbe_dev_read,
47450+ .enable_int = xgbe_enable_int,
47451+ .disable_int = xgbe_disable_int,
47452+ .init = xgbe_init,
47453+ .exit = xgbe_exit,
47454
47455 /* Descriptor related Sequences have to be initialized here */
47456- hw_if->tx_desc_init = xgbe_tx_desc_init;
47457- hw_if->rx_desc_init = xgbe_rx_desc_init;
47458- hw_if->tx_desc_reset = xgbe_tx_desc_reset;
47459- hw_if->rx_desc_reset = xgbe_rx_desc_reset;
47460- hw_if->is_last_desc = xgbe_is_last_desc;
47461- hw_if->is_context_desc = xgbe_is_context_desc;
47462+ .tx_desc_init = xgbe_tx_desc_init,
47463+ .rx_desc_init = xgbe_rx_desc_init,
47464+ .tx_desc_reset = xgbe_tx_desc_reset,
47465+ .rx_desc_reset = xgbe_rx_desc_reset,
47466+ .is_last_desc = xgbe_is_last_desc,
47467+ .is_context_desc = xgbe_is_context_desc,
47468
47469 /* For FLOW ctrl */
47470- hw_if->config_tx_flow_control = xgbe_config_tx_flow_control;
47471- hw_if->config_rx_flow_control = xgbe_config_rx_flow_control;
47472+ .config_tx_flow_control = xgbe_config_tx_flow_control,
47473+ .config_rx_flow_control = xgbe_config_rx_flow_control,
47474
47475 /* For RX coalescing */
47476- hw_if->config_rx_coalesce = xgbe_config_rx_coalesce;
47477- hw_if->config_tx_coalesce = xgbe_config_tx_coalesce;
47478- hw_if->usec_to_riwt = xgbe_usec_to_riwt;
47479- hw_if->riwt_to_usec = xgbe_riwt_to_usec;
47480+ .config_rx_coalesce = xgbe_config_rx_coalesce,
47481+ .config_tx_coalesce = xgbe_config_tx_coalesce,
47482+ .usec_to_riwt = xgbe_usec_to_riwt,
47483+ .riwt_to_usec = xgbe_riwt_to_usec,
47484
47485 /* For RX and TX threshold config */
47486- hw_if->config_rx_threshold = xgbe_config_rx_threshold;
47487- hw_if->config_tx_threshold = xgbe_config_tx_threshold;
47488+ .config_rx_threshold = xgbe_config_rx_threshold,
47489+ .config_tx_threshold = xgbe_config_tx_threshold,
47490
47491 /* For RX and TX Store and Forward Mode config */
47492- hw_if->config_rsf_mode = xgbe_config_rsf_mode;
47493- hw_if->config_tsf_mode = xgbe_config_tsf_mode;
47494+ .config_rsf_mode = xgbe_config_rsf_mode,
47495+ .config_tsf_mode = xgbe_config_tsf_mode,
47496
47497 /* For TX DMA Operating on Second Frame config */
47498- hw_if->config_osp_mode = xgbe_config_osp_mode;
47499+ .config_osp_mode = xgbe_config_osp_mode,
47500
47501 /* For RX and TX PBL config */
47502- hw_if->config_rx_pbl_val = xgbe_config_rx_pbl_val;
47503- hw_if->get_rx_pbl_val = xgbe_get_rx_pbl_val;
47504- hw_if->config_tx_pbl_val = xgbe_config_tx_pbl_val;
47505- hw_if->get_tx_pbl_val = xgbe_get_tx_pbl_val;
47506- hw_if->config_pblx8 = xgbe_config_pblx8;
47507+ .config_rx_pbl_val = xgbe_config_rx_pbl_val,
47508+ .get_rx_pbl_val = xgbe_get_rx_pbl_val,
47509+ .config_tx_pbl_val = xgbe_config_tx_pbl_val,
47510+ .get_tx_pbl_val = xgbe_get_tx_pbl_val,
47511+ .config_pblx8 = xgbe_config_pblx8,
47512
47513 /* For MMC statistics support */
47514- hw_if->tx_mmc_int = xgbe_tx_mmc_int;
47515- hw_if->rx_mmc_int = xgbe_rx_mmc_int;
47516- hw_if->read_mmc_stats = xgbe_read_mmc_stats;
47517+ .tx_mmc_int = xgbe_tx_mmc_int,
47518+ .rx_mmc_int = xgbe_rx_mmc_int,
47519+ .read_mmc_stats = xgbe_read_mmc_stats,
47520
47521 /* For PTP config */
47522- hw_if->config_tstamp = xgbe_config_tstamp;
47523- hw_if->update_tstamp_addend = xgbe_update_tstamp_addend;
47524- hw_if->set_tstamp_time = xgbe_set_tstamp_time;
47525- hw_if->get_tstamp_time = xgbe_get_tstamp_time;
47526- hw_if->get_tx_tstamp = xgbe_get_tx_tstamp;
47527+ .config_tstamp = xgbe_config_tstamp,
47528+ .update_tstamp_addend = xgbe_update_tstamp_addend,
47529+ .set_tstamp_time = xgbe_set_tstamp_time,
47530+ .get_tstamp_time = xgbe_get_tstamp_time,
47531+ .get_tx_tstamp = xgbe_get_tx_tstamp,
47532
47533 /* For Data Center Bridging config */
47534- hw_if->config_dcb_tc = xgbe_config_dcb_tc;
47535- hw_if->config_dcb_pfc = xgbe_config_dcb_pfc;
47536-
47537- DBGPR("<--xgbe_init_function_ptrs\n");
47538-}
47539+ .config_dcb_tc = xgbe_config_dcb_tc,
47540+ .config_dcb_pfc = xgbe_config_dcb_pfc,
47541+};
47542diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-drv.c b/drivers/net/ethernet/amd/xgbe/xgbe-drv.c
47543index 2349ea9..a83a677 100644
47544--- a/drivers/net/ethernet/amd/xgbe/xgbe-drv.c
47545+++ b/drivers/net/ethernet/amd/xgbe/xgbe-drv.c
47546@@ -154,7 +154,7 @@ static int xgbe_calc_rx_buf_size(struct net_device *netdev, unsigned int mtu)
47547
47548 static void xgbe_enable_rx_tx_ints(struct xgbe_prv_data *pdata)
47549 {
47550- struct xgbe_hw_if *hw_if = &pdata->hw_if;
47551+ struct xgbe_hw_if *hw_if = pdata->hw_if;
47552 struct xgbe_channel *channel;
47553 enum xgbe_int int_id;
47554 unsigned int i;
47555@@ -176,7 +176,7 @@ static void xgbe_enable_rx_tx_ints(struct xgbe_prv_data *pdata)
47556
47557 static void xgbe_disable_rx_tx_ints(struct xgbe_prv_data *pdata)
47558 {
47559- struct xgbe_hw_if *hw_if = &pdata->hw_if;
47560+ struct xgbe_hw_if *hw_if = pdata->hw_if;
47561 struct xgbe_channel *channel;
47562 enum xgbe_int int_id;
47563 unsigned int i;
47564@@ -199,7 +199,7 @@ static void xgbe_disable_rx_tx_ints(struct xgbe_prv_data *pdata)
47565 static irqreturn_t xgbe_isr(int irq, void *data)
47566 {
47567 struct xgbe_prv_data *pdata = data;
47568- struct xgbe_hw_if *hw_if = &pdata->hw_if;
47569+ struct xgbe_hw_if *hw_if = pdata->hw_if;
47570 struct xgbe_channel *channel;
47571 unsigned int dma_isr, dma_ch_isr;
47572 unsigned int mac_isr, mac_tssr;
47573@@ -446,7 +446,7 @@ static void xgbe_napi_disable(struct xgbe_prv_data *pdata, unsigned int del)
47574
47575 void xgbe_init_tx_coalesce(struct xgbe_prv_data *pdata)
47576 {
47577- struct xgbe_hw_if *hw_if = &pdata->hw_if;
47578+ struct xgbe_hw_if *hw_if = pdata->hw_if;
47579
47580 DBGPR("-->xgbe_init_tx_coalesce\n");
47581
47582@@ -460,7 +460,7 @@ void xgbe_init_tx_coalesce(struct xgbe_prv_data *pdata)
47583
47584 void xgbe_init_rx_coalesce(struct xgbe_prv_data *pdata)
47585 {
47586- struct xgbe_hw_if *hw_if = &pdata->hw_if;
47587+ struct xgbe_hw_if *hw_if = pdata->hw_if;
47588
47589 DBGPR("-->xgbe_init_rx_coalesce\n");
47590
47591@@ -474,7 +474,7 @@ void xgbe_init_rx_coalesce(struct xgbe_prv_data *pdata)
47592
47593 static void xgbe_free_tx_skbuff(struct xgbe_prv_data *pdata)
47594 {
47595- struct xgbe_desc_if *desc_if = &pdata->desc_if;
47596+ struct xgbe_desc_if *desc_if = pdata->desc_if;
47597 struct xgbe_channel *channel;
47598 struct xgbe_ring *ring;
47599 struct xgbe_ring_data *rdata;
47600@@ -499,7 +499,7 @@ static void xgbe_free_tx_skbuff(struct xgbe_prv_data *pdata)
47601
47602 static void xgbe_free_rx_skbuff(struct xgbe_prv_data *pdata)
47603 {
47604- struct xgbe_desc_if *desc_if = &pdata->desc_if;
47605+ struct xgbe_desc_if *desc_if = pdata->desc_if;
47606 struct xgbe_channel *channel;
47607 struct xgbe_ring *ring;
47608 struct xgbe_ring_data *rdata;
47609@@ -525,7 +525,7 @@ static void xgbe_free_rx_skbuff(struct xgbe_prv_data *pdata)
47610 static void xgbe_adjust_link(struct net_device *netdev)
47611 {
47612 struct xgbe_prv_data *pdata = netdev_priv(netdev);
47613- struct xgbe_hw_if *hw_if = &pdata->hw_if;
47614+ struct xgbe_hw_if *hw_if = pdata->hw_if;
47615 struct phy_device *phydev = pdata->phydev;
47616 int new_state = 0;
47617
47618@@ -633,7 +633,7 @@ static void xgbe_phy_exit(struct xgbe_prv_data *pdata)
47619 int xgbe_powerdown(struct net_device *netdev, unsigned int caller)
47620 {
47621 struct xgbe_prv_data *pdata = netdev_priv(netdev);
47622- struct xgbe_hw_if *hw_if = &pdata->hw_if;
47623+ struct xgbe_hw_if *hw_if = pdata->hw_if;
47624 unsigned long flags;
47625
47626 DBGPR("-->xgbe_powerdown\n");
47627@@ -671,7 +671,7 @@ int xgbe_powerdown(struct net_device *netdev, unsigned int caller)
47628 int xgbe_powerup(struct net_device *netdev, unsigned int caller)
47629 {
47630 struct xgbe_prv_data *pdata = netdev_priv(netdev);
47631- struct xgbe_hw_if *hw_if = &pdata->hw_if;
47632+ struct xgbe_hw_if *hw_if = pdata->hw_if;
47633 unsigned long flags;
47634
47635 DBGPR("-->xgbe_powerup\n");
47636@@ -708,7 +708,7 @@ int xgbe_powerup(struct net_device *netdev, unsigned int caller)
47637
47638 static int xgbe_start(struct xgbe_prv_data *pdata)
47639 {
47640- struct xgbe_hw_if *hw_if = &pdata->hw_if;
47641+ struct xgbe_hw_if *hw_if = pdata->hw_if;
47642 struct net_device *netdev = pdata->netdev;
47643
47644 DBGPR("-->xgbe_start\n");
47645@@ -734,7 +734,7 @@ static int xgbe_start(struct xgbe_prv_data *pdata)
47646
47647 static void xgbe_stop(struct xgbe_prv_data *pdata)
47648 {
47649- struct xgbe_hw_if *hw_if = &pdata->hw_if;
47650+ struct xgbe_hw_if *hw_if = pdata->hw_if;
47651 struct net_device *netdev = pdata->netdev;
47652
47653 DBGPR("-->xgbe_stop\n");
47654@@ -754,7 +754,7 @@ static void xgbe_stop(struct xgbe_prv_data *pdata)
47655
47656 static void xgbe_restart_dev(struct xgbe_prv_data *pdata, unsigned int reset)
47657 {
47658- struct xgbe_hw_if *hw_if = &pdata->hw_if;
47659+ struct xgbe_hw_if *hw_if = pdata->hw_if;
47660
47661 DBGPR("-->xgbe_restart_dev\n");
47662
47663@@ -951,7 +951,7 @@ static int xgbe_set_hwtstamp_settings(struct xgbe_prv_data *pdata,
47664 return -ERANGE;
47665 }
47666
47667- pdata->hw_if.config_tstamp(pdata, mac_tscr);
47668+ pdata->hw_if->config_tstamp(pdata, mac_tscr);
47669
47670 memcpy(&pdata->tstamp_config, &config, sizeof(config));
47671
47672@@ -1089,8 +1089,8 @@ static void xgbe_packet_info(struct xgbe_prv_data *pdata,
47673 static int xgbe_open(struct net_device *netdev)
47674 {
47675 struct xgbe_prv_data *pdata = netdev_priv(netdev);
47676- struct xgbe_hw_if *hw_if = &pdata->hw_if;
47677- struct xgbe_desc_if *desc_if = &pdata->desc_if;
47678+ struct xgbe_hw_if *hw_if = pdata->hw_if;
47679+ struct xgbe_desc_if *desc_if = pdata->desc_if;
47680 int ret;
47681
47682 DBGPR("-->xgbe_open\n");
47683@@ -1170,8 +1170,8 @@ err_phy_init:
47684 static int xgbe_close(struct net_device *netdev)
47685 {
47686 struct xgbe_prv_data *pdata = netdev_priv(netdev);
47687- struct xgbe_hw_if *hw_if = &pdata->hw_if;
47688- struct xgbe_desc_if *desc_if = &pdata->desc_if;
47689+ struct xgbe_hw_if *hw_if = pdata->hw_if;
47690+ struct xgbe_desc_if *desc_if = pdata->desc_if;
47691
47692 DBGPR("-->xgbe_close\n");
47693
47694@@ -1205,8 +1205,8 @@ static int xgbe_close(struct net_device *netdev)
47695 static int xgbe_xmit(struct sk_buff *skb, struct net_device *netdev)
47696 {
47697 struct xgbe_prv_data *pdata = netdev_priv(netdev);
47698- struct xgbe_hw_if *hw_if = &pdata->hw_if;
47699- struct xgbe_desc_if *desc_if = &pdata->desc_if;
47700+ struct xgbe_hw_if *hw_if = pdata->hw_if;
47701+ struct xgbe_desc_if *desc_if = pdata->desc_if;
47702 struct xgbe_channel *channel;
47703 struct xgbe_ring *ring;
47704 struct xgbe_packet_data *packet;
47705@@ -1275,7 +1275,7 @@ tx_netdev_return:
47706 static void xgbe_set_rx_mode(struct net_device *netdev)
47707 {
47708 struct xgbe_prv_data *pdata = netdev_priv(netdev);
47709- struct xgbe_hw_if *hw_if = &pdata->hw_if;
47710+ struct xgbe_hw_if *hw_if = pdata->hw_if;
47711 unsigned int pr_mode, am_mode;
47712
47713 DBGPR("-->xgbe_set_rx_mode\n");
47714@@ -1294,7 +1294,7 @@ static void xgbe_set_rx_mode(struct net_device *netdev)
47715 static int xgbe_set_mac_address(struct net_device *netdev, void *addr)
47716 {
47717 struct xgbe_prv_data *pdata = netdev_priv(netdev);
47718- struct xgbe_hw_if *hw_if = &pdata->hw_if;
47719+ struct xgbe_hw_if *hw_if = pdata->hw_if;
47720 struct sockaddr *saddr = addr;
47721
47722 DBGPR("-->xgbe_set_mac_address\n");
47723@@ -1361,7 +1361,7 @@ static struct rtnl_link_stats64 *xgbe_get_stats64(struct net_device *netdev,
47724
47725 DBGPR("-->%s\n", __func__);
47726
47727- pdata->hw_if.read_mmc_stats(pdata);
47728+ pdata->hw_if->read_mmc_stats(pdata);
47729
47730 s->rx_packets = pstats->rxframecount_gb;
47731 s->rx_bytes = pstats->rxoctetcount_gb;
47732@@ -1388,7 +1388,7 @@ static int xgbe_vlan_rx_add_vid(struct net_device *netdev, __be16 proto,
47733 u16 vid)
47734 {
47735 struct xgbe_prv_data *pdata = netdev_priv(netdev);
47736- struct xgbe_hw_if *hw_if = &pdata->hw_if;
47737+ struct xgbe_hw_if *hw_if = pdata->hw_if;
47738
47739 DBGPR("-->%s\n", __func__);
47740
47741@@ -1404,7 +1404,7 @@ static int xgbe_vlan_rx_kill_vid(struct net_device *netdev, __be16 proto,
47742 u16 vid)
47743 {
47744 struct xgbe_prv_data *pdata = netdev_priv(netdev);
47745- struct xgbe_hw_if *hw_if = &pdata->hw_if;
47746+ struct xgbe_hw_if *hw_if = pdata->hw_if;
47747
47748 DBGPR("-->%s\n", __func__);
47749
47750@@ -1464,7 +1464,7 @@ static int xgbe_set_features(struct net_device *netdev,
47751 netdev_features_t features)
47752 {
47753 struct xgbe_prv_data *pdata = netdev_priv(netdev);
47754- struct xgbe_hw_if *hw_if = &pdata->hw_if;
47755+ struct xgbe_hw_if *hw_if = pdata->hw_if;
47756 netdev_features_t rxcsum, rxvlan, rxvlan_filter;
47757
47758 rxcsum = pdata->netdev_features & NETIF_F_RXCSUM;
47759@@ -1520,7 +1520,7 @@ struct net_device_ops *xgbe_get_netdev_ops(void)
47760 static void xgbe_rx_refresh(struct xgbe_channel *channel)
47761 {
47762 struct xgbe_prv_data *pdata = channel->pdata;
47763- struct xgbe_desc_if *desc_if = &pdata->desc_if;
47764+ struct xgbe_desc_if *desc_if = pdata->desc_if;
47765 struct xgbe_ring *ring = channel->rx_ring;
47766 struct xgbe_ring_data *rdata;
47767
47768@@ -1536,8 +1536,8 @@ static void xgbe_rx_refresh(struct xgbe_channel *channel)
47769 static int xgbe_tx_poll(struct xgbe_channel *channel)
47770 {
47771 struct xgbe_prv_data *pdata = channel->pdata;
47772- struct xgbe_hw_if *hw_if = &pdata->hw_if;
47773- struct xgbe_desc_if *desc_if = &pdata->desc_if;
47774+ struct xgbe_hw_if *hw_if = pdata->hw_if;
47775+ struct xgbe_desc_if *desc_if = pdata->desc_if;
47776 struct xgbe_ring *ring = channel->tx_ring;
47777 struct xgbe_ring_data *rdata;
47778 struct xgbe_ring_desc *rdesc;
47779@@ -1589,7 +1589,7 @@ static int xgbe_tx_poll(struct xgbe_channel *channel)
47780 static int xgbe_rx_poll(struct xgbe_channel *channel, int budget)
47781 {
47782 struct xgbe_prv_data *pdata = channel->pdata;
47783- struct xgbe_hw_if *hw_if = &pdata->hw_if;
47784+ struct xgbe_hw_if *hw_if = pdata->hw_if;
47785 struct xgbe_ring *ring = channel->rx_ring;
47786 struct xgbe_ring_data *rdata;
47787 struct xgbe_packet_data *packet;
47788diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-ethtool.c b/drivers/net/ethernet/amd/xgbe/xgbe-ethtool.c
47789index 49508ec..2617cca 100644
47790--- a/drivers/net/ethernet/amd/xgbe/xgbe-ethtool.c
47791+++ b/drivers/net/ethernet/amd/xgbe/xgbe-ethtool.c
47792@@ -203,7 +203,7 @@ static void xgbe_get_ethtool_stats(struct net_device *netdev,
47793
47794 DBGPR("-->%s\n", __func__);
47795
47796- pdata->hw_if.read_mmc_stats(pdata);
47797+ pdata->hw_if->read_mmc_stats(pdata);
47798 for (i = 0; i < XGBE_STATS_COUNT; i++) {
47799 stat = (u8 *)pdata + xgbe_gstring_stats[i].stat_offset;
47800 *data++ = *(u64 *)stat;
47801@@ -378,7 +378,7 @@ static int xgbe_get_coalesce(struct net_device *netdev,
47802 struct ethtool_coalesce *ec)
47803 {
47804 struct xgbe_prv_data *pdata = netdev_priv(netdev);
47805- struct xgbe_hw_if *hw_if = &pdata->hw_if;
47806+ struct xgbe_hw_if *hw_if = pdata->hw_if;
47807 unsigned int riwt;
47808
47809 DBGPR("-->xgbe_get_coalesce\n");
47810@@ -401,7 +401,7 @@ static int xgbe_set_coalesce(struct net_device *netdev,
47811 struct ethtool_coalesce *ec)
47812 {
47813 struct xgbe_prv_data *pdata = netdev_priv(netdev);
47814- struct xgbe_hw_if *hw_if = &pdata->hw_if;
47815+ struct xgbe_hw_if *hw_if = pdata->hw_if;
47816 unsigned int rx_frames, rx_riwt, rx_usecs;
47817 unsigned int tx_frames, tx_usecs;
47818
47819diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-main.c b/drivers/net/ethernet/amd/xgbe/xgbe-main.c
47820index f5a8fa0..0bb58ff 100644
47821--- a/drivers/net/ethernet/amd/xgbe/xgbe-main.c
47822+++ b/drivers/net/ethernet/amd/xgbe/xgbe-main.c
47823@@ -209,12 +209,6 @@ static void xgbe_default_config(struct xgbe_prv_data *pdata)
47824 DBGPR("<--xgbe_default_config\n");
47825 }
47826
47827-static void xgbe_init_all_fptrs(struct xgbe_prv_data *pdata)
47828-{
47829- xgbe_init_function_ptrs_dev(&pdata->hw_if);
47830- xgbe_init_function_ptrs_desc(&pdata->desc_if);
47831-}
47832-
47833 static int xgbe_probe(struct platform_device *pdev)
47834 {
47835 struct xgbe_prv_data *pdata;
47836@@ -327,9 +321,8 @@ static int xgbe_probe(struct platform_device *pdev)
47837 netdev->base_addr = (unsigned long)pdata->xgmac_regs;
47838
47839 /* Set all the function pointers */
47840- xgbe_init_all_fptrs(pdata);
47841- hw_if = &pdata->hw_if;
47842- desc_if = &pdata->desc_if;
47843+ hw_if = pdata->hw_if = &default_xgbe_hw_if;
47844+ desc_if = pdata->desc_if = &default_xgbe_desc_if;
47845
47846 /* Issue software reset to device */
47847 hw_if->exit(pdata);
47848diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-mdio.c b/drivers/net/ethernet/amd/xgbe/xgbe-mdio.c
47849index 363b210..b241389 100644
47850--- a/drivers/net/ethernet/amd/xgbe/xgbe-mdio.c
47851+++ b/drivers/net/ethernet/amd/xgbe/xgbe-mdio.c
47852@@ -126,7 +126,7 @@
47853 static int xgbe_mdio_read(struct mii_bus *mii, int prtad, int mmd_reg)
47854 {
47855 struct xgbe_prv_data *pdata = mii->priv;
47856- struct xgbe_hw_if *hw_if = &pdata->hw_if;
47857+ struct xgbe_hw_if *hw_if = pdata->hw_if;
47858 int mmd_data;
47859
47860 DBGPR_MDIO("-->xgbe_mdio_read: prtad=%#x mmd_reg=%#x\n",
47861@@ -143,7 +143,7 @@ static int xgbe_mdio_write(struct mii_bus *mii, int prtad, int mmd_reg,
47862 u16 mmd_val)
47863 {
47864 struct xgbe_prv_data *pdata = mii->priv;
47865- struct xgbe_hw_if *hw_if = &pdata->hw_if;
47866+ struct xgbe_hw_if *hw_if = pdata->hw_if;
47867 int mmd_data = mmd_val;
47868
47869 DBGPR_MDIO("-->xgbe_mdio_write: prtad=%#x mmd_reg=%#x mmd_data=%#x\n",
47870diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-ptp.c b/drivers/net/ethernet/amd/xgbe/xgbe-ptp.c
47871index a1bf9d1c..84adcab 100644
47872--- a/drivers/net/ethernet/amd/xgbe/xgbe-ptp.c
47873+++ b/drivers/net/ethernet/amd/xgbe/xgbe-ptp.c
47874@@ -129,7 +129,7 @@ static cycle_t xgbe_cc_read(const struct cyclecounter *cc)
47875 tstamp_cc);
47876 u64 nsec;
47877
47878- nsec = pdata->hw_if.get_tstamp_time(pdata);
47879+ nsec = pdata->hw_if->get_tstamp_time(pdata);
47880
47881 return nsec;
47882 }
47883@@ -158,7 +158,7 @@ static int xgbe_adjfreq(struct ptp_clock_info *info, s32 delta)
47884
47885 spin_lock_irqsave(&pdata->tstamp_lock, flags);
47886
47887- pdata->hw_if.update_tstamp_addend(pdata, addend);
47888+ pdata->hw_if->update_tstamp_addend(pdata, addend);
47889
47890 spin_unlock_irqrestore(&pdata->tstamp_lock, flags);
47891
47892diff --git a/drivers/net/ethernet/amd/xgbe/xgbe.h b/drivers/net/ethernet/amd/xgbe/xgbe.h
47893index 789957d..d7d0245 100644
47894--- a/drivers/net/ethernet/amd/xgbe/xgbe.h
47895+++ b/drivers/net/ethernet/amd/xgbe/xgbe.h
47896@@ -583,8 +583,8 @@ struct xgbe_prv_data {
47897
47898 int irq_number;
47899
47900- struct xgbe_hw_if hw_if;
47901- struct xgbe_desc_if desc_if;
47902+ const struct xgbe_hw_if *hw_if;
47903+ const struct xgbe_desc_if *desc_if;
47904
47905 /* AXI DMA settings */
47906 unsigned int axdomain;
47907@@ -697,6 +697,9 @@ struct xgbe_prv_data {
47908 #endif
47909 };
47910
47911+extern const struct xgbe_hw_if default_xgbe_hw_if;
47912+extern const struct xgbe_desc_if default_xgbe_desc_if;
47913+
47914 /* Function prototypes*/
47915
47916 void xgbe_init_function_ptrs_dev(struct xgbe_hw_if *);
47917diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
47918index adcacda..fa6e0ae 100644
47919--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
47920+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
47921@@ -1065,7 +1065,7 @@ static inline u8 bnx2x_get_path_func_num(struct bnx2x *bp)
47922 static inline void bnx2x_init_bp_objs(struct bnx2x *bp)
47923 {
47924 /* RX_MODE controlling object */
47925- bnx2x_init_rx_mode_obj(bp, &bp->rx_mode_obj);
47926+ bnx2x_init_rx_mode_obj(bp);
47927
47928 /* multicast configuration controlling object */
47929 bnx2x_init_mcast_obj(bp, &bp->mcast_obj, bp->fp->cl_id, bp->fp->cid,
47930diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
47931index 7bc2924..2112002 100644
47932--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
47933+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
47934@@ -2329,15 +2329,14 @@ int bnx2x_config_rx_mode(struct bnx2x *bp,
47935 return rc;
47936 }
47937
47938-void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
47939- struct bnx2x_rx_mode_obj *o)
47940+void bnx2x_init_rx_mode_obj(struct bnx2x *bp)
47941 {
47942 if (CHIP_IS_E1x(bp)) {
47943- o->wait_comp = bnx2x_empty_rx_mode_wait;
47944- o->config_rx_mode = bnx2x_set_rx_mode_e1x;
47945+ bp->rx_mode_obj.wait_comp = bnx2x_empty_rx_mode_wait;
47946+ bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e1x;
47947 } else {
47948- o->wait_comp = bnx2x_wait_rx_mode_comp_e2;
47949- o->config_rx_mode = bnx2x_set_rx_mode_e2;
47950+ bp->rx_mode_obj.wait_comp = bnx2x_wait_rx_mode_comp_e2;
47951+ bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e2;
47952 }
47953 }
47954
47955diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
47956index e97275f..52e28bc 100644
47957--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
47958+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
47959@@ -1409,8 +1409,7 @@ int bnx2x_vlan_mac_move(struct bnx2x *bp,
47960
47961 /********************* RX MODE ****************/
47962
47963-void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
47964- struct bnx2x_rx_mode_obj *o);
47965+void bnx2x_init_rx_mode_obj(struct bnx2x *bp);
47966
47967 /**
47968 * bnx2x_config_rx_mode - Send and RX_MODE ramrod according to the provided parameters.
47969diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
47970index 31c9f82..e65e986 100644
47971--- a/drivers/net/ethernet/broadcom/tg3.h
47972+++ b/drivers/net/ethernet/broadcom/tg3.h
47973@@ -150,6 +150,7 @@
47974 #define CHIPREV_ID_5750_A0 0x4000
47975 #define CHIPREV_ID_5750_A1 0x4001
47976 #define CHIPREV_ID_5750_A3 0x4003
47977+#define CHIPREV_ID_5750_C1 0x4201
47978 #define CHIPREV_ID_5750_C2 0x4202
47979 #define CHIPREV_ID_5752_A0_HW 0x5000
47980 #define CHIPREV_ID_5752_A0 0x6000
47981diff --git a/drivers/net/ethernet/brocade/bna/bna_enet.c b/drivers/net/ethernet/brocade/bna/bna_enet.c
47982index 903466e..b285864 100644
47983--- a/drivers/net/ethernet/brocade/bna/bna_enet.c
47984+++ b/drivers/net/ethernet/brocade/bna/bna_enet.c
47985@@ -1693,10 +1693,10 @@ bna_cb_ioceth_reset(void *arg)
47986 }
47987
47988 static struct bfa_ioc_cbfn bna_ioceth_cbfn = {
47989- bna_cb_ioceth_enable,
47990- bna_cb_ioceth_disable,
47991- bna_cb_ioceth_hbfail,
47992- bna_cb_ioceth_reset
47993+ .enable_cbfn = bna_cb_ioceth_enable,
47994+ .disable_cbfn = bna_cb_ioceth_disable,
47995+ .hbfail_cbfn = bna_cb_ioceth_hbfail,
47996+ .reset_cbfn = bna_cb_ioceth_reset
47997 };
47998
47999 static void bna_attr_init(struct bna_ioceth *ioceth)
48000diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
48001index 8cffcdf..aadf043 100644
48002--- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
48003+++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
48004@@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
48005 */
48006 struct l2t_skb_cb {
48007 arp_failure_handler_func arp_failure_handler;
48008-};
48009+} __no_const;
48010
48011 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
48012
48013diff --git a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
48014index 279873c..11e1921 100644
48015--- a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
48016+++ b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
48017@@ -2365,7 +2365,7 @@ static void get_regs(struct net_device *dev, struct ethtool_regs *regs,
48018
48019 int i;
48020 struct adapter *ap = netdev2adap(dev);
48021- static const unsigned int *reg_ranges;
48022+ const unsigned int *reg_ranges;
48023 int arr_size = 0, buf_size = 0;
48024
48025 if (is_t4(ap->params.chip)) {
48026diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
48027index cf8b6ff..274271e 100644
48028--- a/drivers/net/ethernet/dec/tulip/de4x5.c
48029+++ b/drivers/net/ethernet/dec/tulip/de4x5.c
48030@@ -5387,7 +5387,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
48031 for (i=0; i<ETH_ALEN; i++) {
48032 tmp.addr[i] = dev->dev_addr[i];
48033 }
48034- if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
48035+ if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
48036 break;
48037
48038 case DE4X5_SET_HWADDR: /* Set the hardware address */
48039@@ -5427,7 +5427,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
48040 spin_lock_irqsave(&lp->lock, flags);
48041 memcpy(&statbuf, &lp->pktStats, ioc->len);
48042 spin_unlock_irqrestore(&lp->lock, flags);
48043- if (copy_to_user(ioc->data, &statbuf, ioc->len))
48044+ if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
48045 return -EFAULT;
48046 break;
48047 }
48048diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
48049index 597c463..5cc1a7f 100644
48050--- a/drivers/net/ethernet/emulex/benet/be_main.c
48051+++ b/drivers/net/ethernet/emulex/benet/be_main.c
48052@@ -537,7 +537,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
48053
48054 if (wrapped)
48055 newacc += 65536;
48056- ACCESS_ONCE(*acc) = newacc;
48057+ ACCESS_ONCE_RW(*acc) = newacc;
48058 }
48059
48060 static void populate_erx_stats(struct be_adapter *adapter,
48061diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
48062index c77fa4a..7fd42fc 100644
48063--- a/drivers/net/ethernet/faraday/ftgmac100.c
48064+++ b/drivers/net/ethernet/faraday/ftgmac100.c
48065@@ -30,6 +30,8 @@
48066 #include <linux/netdevice.h>
48067 #include <linux/phy.h>
48068 #include <linux/platform_device.h>
48069+#include <linux/interrupt.h>
48070+#include <linux/irqreturn.h>
48071 #include <net/ip.h>
48072
48073 #include "ftgmac100.h"
48074diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
48075index 4ff1adc..0ea6bf4 100644
48076--- a/drivers/net/ethernet/faraday/ftmac100.c
48077+++ b/drivers/net/ethernet/faraday/ftmac100.c
48078@@ -31,6 +31,8 @@
48079 #include <linux/module.h>
48080 #include <linux/netdevice.h>
48081 #include <linux/platform_device.h>
48082+#include <linux/interrupt.h>
48083+#include <linux/irqreturn.h>
48084
48085 #include "ftmac100.h"
48086
48087diff --git a/drivers/net/ethernet/intel/i40e/i40e_ptp.c b/drivers/net/ethernet/intel/i40e/i40e_ptp.c
48088index 537b621..07f87ce 100644
48089--- a/drivers/net/ethernet/intel/i40e/i40e_ptp.c
48090+++ b/drivers/net/ethernet/intel/i40e/i40e_ptp.c
48091@@ -401,7 +401,7 @@ void i40e_ptp_set_increment(struct i40e_pf *pf)
48092 wr32(hw, I40E_PRTTSYN_INC_H, incval >> 32);
48093
48094 /* Update the base adjustement value. */
48095- ACCESS_ONCE(pf->ptp_base_adj) = incval;
48096+ ACCESS_ONCE_RW(pf->ptp_base_adj) = incval;
48097 smp_mb(); /* Force the above update. */
48098 }
48099
48100diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
48101index 5fd4b52..87aa34b 100644
48102--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
48103+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
48104@@ -794,7 +794,7 @@ void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
48105 }
48106
48107 /* update the base incval used to calculate frequency adjustment */
48108- ACCESS_ONCE(adapter->base_incval) = incval;
48109+ ACCESS_ONCE_RW(adapter->base_incval) = incval;
48110 smp_mb();
48111
48112 /* need lock to prevent incorrect read while modifying cyclecounter */
48113diff --git a/drivers/net/ethernet/mellanox/mlx4/en_tx.c b/drivers/net/ethernet/mellanox/mlx4/en_tx.c
48114index 454d9fe..59f0f0b 100644
48115--- a/drivers/net/ethernet/mellanox/mlx4/en_tx.c
48116+++ b/drivers/net/ethernet/mellanox/mlx4/en_tx.c
48117@@ -458,8 +458,8 @@ static bool mlx4_en_process_tx_cq(struct net_device *dev,
48118 wmb();
48119
48120 /* we want to dirty this cache line once */
48121- ACCESS_ONCE(ring->last_nr_txbb) = last_nr_txbb;
48122- ACCESS_ONCE(ring->cons) = ring_cons + txbbs_skipped;
48123+ ACCESS_ONCE_RW(ring->last_nr_txbb) = last_nr_txbb;
48124+ ACCESS_ONCE_RW(ring->cons) = ring_cons + txbbs_skipped;
48125
48126 netdev_tx_completed_queue(ring->tx_queue, packets, bytes);
48127
48128diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.c b/drivers/net/ethernet/neterion/vxge/vxge-config.c
48129index 2bbd01f..e8baa64 100644
48130--- a/drivers/net/ethernet/neterion/vxge/vxge-config.c
48131+++ b/drivers/net/ethernet/neterion/vxge/vxge-config.c
48132@@ -3457,7 +3457,10 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
48133 struct __vxge_hw_fifo *fifo;
48134 struct vxge_hw_fifo_config *config;
48135 u32 txdl_size, txdl_per_memblock;
48136- struct vxge_hw_mempool_cbs fifo_mp_callback;
48137+ static struct vxge_hw_mempool_cbs fifo_mp_callback = {
48138+ .item_func_alloc = __vxge_hw_fifo_mempool_item_alloc,
48139+ };
48140+
48141 struct __vxge_hw_virtualpath *vpath;
48142
48143 if ((vp == NULL) || (attr == NULL)) {
48144@@ -3540,8 +3543,6 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
48145 goto exit;
48146 }
48147
48148- fifo_mp_callback.item_func_alloc = __vxge_hw_fifo_mempool_item_alloc;
48149-
48150 fifo->mempool =
48151 __vxge_hw_mempool_create(vpath->hldev,
48152 fifo->config->memblock_size,
48153diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
48154index 2bb48d5..d1a865d 100644
48155--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
48156+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
48157@@ -2324,7 +2324,9 @@ int qlcnic_83xx_configure_opmode(struct qlcnic_adapter *adapter)
48158 max_tx_rings = QLCNIC_MAX_VNIC_TX_RINGS;
48159 } else if (ret == QLC_83XX_DEFAULT_OPMODE) {
48160 ahw->nic_mode = QLCNIC_DEFAULT_MODE;
48161- adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
48162+ pax_open_kernel();
48163+ *(void **)&adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
48164+ pax_close_kernel();
48165 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
48166 max_sds_rings = QLCNIC_MAX_SDS_RINGS;
48167 max_tx_rings = QLCNIC_MAX_TX_RINGS;
48168diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
48169index be7d7a6..a8983f8 100644
48170--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
48171+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
48172@@ -207,17 +207,23 @@ int qlcnic_83xx_config_vnic_opmode(struct qlcnic_adapter *adapter)
48173 case QLCNIC_NON_PRIV_FUNC:
48174 ahw->op_mode = QLCNIC_NON_PRIV_FUNC;
48175 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
48176- nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
48177+ pax_open_kernel();
48178+ *(void **)&nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
48179+ pax_close_kernel();
48180 break;
48181 case QLCNIC_PRIV_FUNC:
48182 ahw->op_mode = QLCNIC_PRIV_FUNC;
48183 ahw->idc.state_entry = qlcnic_83xx_idc_vnic_pf_entry;
48184- nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
48185+ pax_open_kernel();
48186+ *(void **)&nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
48187+ pax_close_kernel();
48188 break;
48189 case QLCNIC_MGMT_FUNC:
48190 ahw->op_mode = QLCNIC_MGMT_FUNC;
48191 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
48192- nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
48193+ pax_open_kernel();
48194+ *(void **)&nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
48195+ pax_close_kernel();
48196 break;
48197 default:
48198 dev_err(&adapter->pdev->dev, "Invalid Virtual NIC opmode\n");
48199diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
48200index c9f57fb..208bdc1 100644
48201--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
48202+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
48203@@ -1285,7 +1285,7 @@ flash_temp:
48204 int qlcnic_dump_fw(struct qlcnic_adapter *adapter)
48205 {
48206 struct qlcnic_fw_dump *fw_dump = &adapter->ahw->fw_dump;
48207- static const struct qlcnic_dump_operations *fw_dump_ops;
48208+ const struct qlcnic_dump_operations *fw_dump_ops;
48209 struct qlcnic_83xx_dump_template_hdr *hdr_83xx;
48210 u32 entry_offset, dump, no_entries, buf_offset = 0;
48211 int i, k, ops_cnt, ops_index, dump_size = 0;
48212diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
48213index cf154f7..c948d1b 100644
48214--- a/drivers/net/ethernet/realtek/r8169.c
48215+++ b/drivers/net/ethernet/realtek/r8169.c
48216@@ -788,22 +788,22 @@ struct rtl8169_private {
48217 struct mdio_ops {
48218 void (*write)(struct rtl8169_private *, int, int);
48219 int (*read)(struct rtl8169_private *, int);
48220- } mdio_ops;
48221+ } __no_const mdio_ops;
48222
48223 struct pll_power_ops {
48224 void (*down)(struct rtl8169_private *);
48225 void (*up)(struct rtl8169_private *);
48226- } pll_power_ops;
48227+ } __no_const pll_power_ops;
48228
48229 struct jumbo_ops {
48230 void (*enable)(struct rtl8169_private *);
48231 void (*disable)(struct rtl8169_private *);
48232- } jumbo_ops;
48233+ } __no_const jumbo_ops;
48234
48235 struct csi_ops {
48236 void (*write)(struct rtl8169_private *, int, int);
48237 u32 (*read)(struct rtl8169_private *, int);
48238- } csi_ops;
48239+ } __no_const csi_ops;
48240
48241 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
48242 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
48243diff --git a/drivers/net/ethernet/sfc/ptp.c b/drivers/net/ethernet/sfc/ptp.c
48244index 6b861e3..204ac86 100644
48245--- a/drivers/net/ethernet/sfc/ptp.c
48246+++ b/drivers/net/ethernet/sfc/ptp.c
48247@@ -822,7 +822,7 @@ static int efx_ptp_synchronize(struct efx_nic *efx, unsigned int num_readings)
48248 ptp->start.dma_addr);
48249
48250 /* Clear flag that signals MC ready */
48251- ACCESS_ONCE(*start) = 0;
48252+ ACCESS_ONCE_RW(*start) = 0;
48253 rc = efx_mcdi_rpc_start(efx, MC_CMD_PTP, synch_buf,
48254 MC_CMD_PTP_IN_SYNCHRONIZE_LEN);
48255 EFX_BUG_ON_PARANOID(rc);
48256diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
48257index 08c483b..2c4a553 100644
48258--- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
48259+++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
48260@@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
48261
48262 writel(value, ioaddr + MMC_CNTRL);
48263
48264- pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
48265- MMC_CNTRL, value);
48266+// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
48267+// MMC_CNTRL, value);
48268 }
48269
48270 /* To mask all all interrupts.*/
48271diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
48272index 2f48f79..8ae1a1a 100644
48273--- a/drivers/net/hyperv/hyperv_net.h
48274+++ b/drivers/net/hyperv/hyperv_net.h
48275@@ -171,7 +171,7 @@ struct rndis_device {
48276 enum rndis_device_state state;
48277 bool link_state;
48278 bool link_change;
48279- atomic_t new_req_id;
48280+ atomic_unchecked_t new_req_id;
48281
48282 spinlock_t request_lock;
48283 struct list_head req_list;
48284diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
48285index 2b86f0b..ecc996f 100644
48286--- a/drivers/net/hyperv/rndis_filter.c
48287+++ b/drivers/net/hyperv/rndis_filter.c
48288@@ -102,7 +102,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
48289 * template
48290 */
48291 set = &rndis_msg->msg.set_req;
48292- set->req_id = atomic_inc_return(&dev->new_req_id);
48293+ set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
48294
48295 /* Add to the request list */
48296 spin_lock_irqsave(&dev->request_lock, flags);
48297@@ -911,7 +911,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
48298
48299 /* Setup the rndis set */
48300 halt = &request->request_msg.msg.halt_req;
48301- halt->req_id = atomic_inc_return(&dev->new_req_id);
48302+ halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
48303
48304 /* Ignore return since this msg is optional. */
48305 rndis_filter_send_request(dev, request);
48306diff --git a/drivers/net/ieee802154/fakehard.c b/drivers/net/ieee802154/fakehard.c
48307index 6cbc56a..5f7e6c8 100644
48308--- a/drivers/net/ieee802154/fakehard.c
48309+++ b/drivers/net/ieee802154/fakehard.c
48310@@ -365,7 +365,7 @@ static int ieee802154fake_probe(struct platform_device *pdev)
48311 phy->transmit_power = 0xbf;
48312
48313 dev->netdev_ops = &fake_ops;
48314- dev->ml_priv = &fake_mlme;
48315+ dev->ml_priv = (void *)&fake_mlme;
48316
48317 priv = netdev_priv(dev);
48318 priv->phy = phy;
48319diff --git a/drivers/net/ifb.c b/drivers/net/ifb.c
48320index 34f846b..4a0d5b1 100644
48321--- a/drivers/net/ifb.c
48322+++ b/drivers/net/ifb.c
48323@@ -253,7 +253,7 @@ static int ifb_validate(struct nlattr *tb[], struct nlattr *data[])
48324 return 0;
48325 }
48326
48327-static struct rtnl_link_ops ifb_link_ops __read_mostly = {
48328+static struct rtnl_link_ops ifb_link_ops = {
48329 .kind = "ifb",
48330 .priv_size = sizeof(struct ifb_private),
48331 .setup = ifb_setup,
48332diff --git a/drivers/net/macvlan.c b/drivers/net/macvlan.c
48333index bfb0b6e..5c396ce 100644
48334--- a/drivers/net/macvlan.c
48335+++ b/drivers/net/macvlan.c
48336@@ -335,7 +335,7 @@ static void macvlan_broadcast_enqueue(struct macvlan_port *port,
48337 free_nskb:
48338 kfree_skb(nskb);
48339 err:
48340- atomic_long_inc(&skb->dev->rx_dropped);
48341+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
48342 }
48343
48344 static void macvlan_flush_sources(struct macvlan_port *port,
48345@@ -1454,13 +1454,15 @@ static const struct nla_policy macvlan_policy[IFLA_MACVLAN_MAX + 1] = {
48346 int macvlan_link_register(struct rtnl_link_ops *ops)
48347 {
48348 /* common fields */
48349- ops->priv_size = sizeof(struct macvlan_dev);
48350- ops->validate = macvlan_validate;
48351- ops->maxtype = IFLA_MACVLAN_MAX;
48352- ops->policy = macvlan_policy;
48353- ops->changelink = macvlan_changelink;
48354- ops->get_size = macvlan_get_size;
48355- ops->fill_info = macvlan_fill_info;
48356+ pax_open_kernel();
48357+ *(size_t *)&ops->priv_size = sizeof(struct macvlan_dev);
48358+ *(void **)&ops->validate = macvlan_validate;
48359+ *(int *)&ops->maxtype = IFLA_MACVLAN_MAX;
48360+ *(const void **)&ops->policy = macvlan_policy;
48361+ *(void **)&ops->changelink = macvlan_changelink;
48362+ *(void **)&ops->get_size = macvlan_get_size;
48363+ *(void **)&ops->fill_info = macvlan_fill_info;
48364+ pax_close_kernel();
48365
48366 return rtnl_link_register(ops);
48367 };
48368@@ -1540,7 +1542,7 @@ static int macvlan_device_event(struct notifier_block *unused,
48369 return NOTIFY_DONE;
48370 }
48371
48372-static struct notifier_block macvlan_notifier_block __read_mostly = {
48373+static struct notifier_block macvlan_notifier_block = {
48374 .notifier_call = macvlan_device_event,
48375 };
48376
48377diff --git a/drivers/net/macvtap.c b/drivers/net/macvtap.c
48378index 880cc09..6a68ba6 100644
48379--- a/drivers/net/macvtap.c
48380+++ b/drivers/net/macvtap.c
48381@@ -422,7 +422,7 @@ static void macvtap_setup(struct net_device *dev)
48382 dev->tx_queue_len = TUN_READQ_SIZE;
48383 }
48384
48385-static struct rtnl_link_ops macvtap_link_ops __read_mostly = {
48386+static struct rtnl_link_ops macvtap_link_ops = {
48387 .kind = "macvtap",
48388 .setup = macvtap_setup,
48389 .newlink = macvtap_newlink,
48390@@ -1020,7 +1020,7 @@ static long macvtap_ioctl(struct file *file, unsigned int cmd,
48391 }
48392
48393 ret = 0;
48394- if (copy_to_user(&ifr->ifr_name, vlan->dev->name, IFNAMSIZ) ||
48395+ if (copy_to_user(ifr->ifr_name, vlan->dev->name, IFNAMSIZ) ||
48396 put_user(q->flags, &ifr->ifr_flags))
48397 ret = -EFAULT;
48398 macvtap_put_vlan(vlan);
48399@@ -1190,7 +1190,7 @@ static int macvtap_device_event(struct notifier_block *unused,
48400 return NOTIFY_DONE;
48401 }
48402
48403-static struct notifier_block macvtap_notifier_block __read_mostly = {
48404+static struct notifier_block macvtap_notifier_block = {
48405 .notifier_call = macvtap_device_event,
48406 };
48407
48408diff --git a/drivers/net/nlmon.c b/drivers/net/nlmon.c
48409index 34924df..a747360 100644
48410--- a/drivers/net/nlmon.c
48411+++ b/drivers/net/nlmon.c
48412@@ -154,7 +154,7 @@ static int nlmon_validate(struct nlattr *tb[], struct nlattr *data[])
48413 return 0;
48414 }
48415
48416-static struct rtnl_link_ops nlmon_link_ops __read_mostly = {
48417+static struct rtnl_link_ops nlmon_link_ops = {
48418 .kind = "nlmon",
48419 .priv_size = sizeof(struct nlmon),
48420 .setup = nlmon_setup,
48421diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
48422index 794a473..9fd437b 100644
48423--- a/drivers/net/ppp/ppp_generic.c
48424+++ b/drivers/net/ppp/ppp_generic.c
48425@@ -1020,7 +1020,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
48426 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
48427 struct ppp_stats stats;
48428 struct ppp_comp_stats cstats;
48429- char *vers;
48430
48431 switch (cmd) {
48432 case SIOCGPPPSTATS:
48433@@ -1042,8 +1041,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
48434 break;
48435
48436 case SIOCGPPPVER:
48437- vers = PPP_VERSION;
48438- if (copy_to_user(addr, vers, strlen(vers) + 1))
48439+ if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
48440 break;
48441 err = 0;
48442 break;
48443diff --git a/drivers/net/slip/slhc.c b/drivers/net/slip/slhc.c
48444index 079f7ad..b2a2bfa7 100644
48445--- a/drivers/net/slip/slhc.c
48446+++ b/drivers/net/slip/slhc.c
48447@@ -487,7 +487,7 @@ slhc_uncompress(struct slcompress *comp, unsigned char *icp, int isize)
48448 register struct tcphdr *thp;
48449 register struct iphdr *ip;
48450 register struct cstate *cs;
48451- int len, hdrlen;
48452+ long len, hdrlen;
48453 unsigned char *cp = icp;
48454
48455 /* We've got a compressed packet; read the change byte */
48456diff --git a/drivers/net/team/team.c b/drivers/net/team/team.c
48457index 2368395..bf6fe96 100644
48458--- a/drivers/net/team/team.c
48459+++ b/drivers/net/team/team.c
48460@@ -2090,7 +2090,7 @@ static unsigned int team_get_num_rx_queues(void)
48461 return TEAM_DEFAULT_NUM_RX_QUEUES;
48462 }
48463
48464-static struct rtnl_link_ops team_link_ops __read_mostly = {
48465+static struct rtnl_link_ops team_link_ops = {
48466 .kind = DRV_NAME,
48467 .priv_size = sizeof(struct team),
48468 .setup = team_setup,
48469@@ -2880,7 +2880,7 @@ static int team_device_event(struct notifier_block *unused,
48470 return NOTIFY_DONE;
48471 }
48472
48473-static struct notifier_block team_notifier_block __read_mostly = {
48474+static struct notifier_block team_notifier_block = {
48475 .notifier_call = team_device_event,
48476 };
48477
48478diff --git a/drivers/net/tun.c b/drivers/net/tun.c
48479index 9dd3746..74f191e 100644
48480--- a/drivers/net/tun.c
48481+++ b/drivers/net/tun.c
48482@@ -1426,7 +1426,7 @@ static int tun_validate(struct nlattr *tb[], struct nlattr *data[])
48483 return -EINVAL;
48484 }
48485
48486-static struct rtnl_link_ops tun_link_ops __read_mostly = {
48487+static struct rtnl_link_ops tun_link_ops = {
48488 .kind = DRV_NAME,
48489 .priv_size = sizeof(struct tun_struct),
48490 .setup = tun_setup,
48491@@ -1868,7 +1868,7 @@ unlock:
48492 }
48493
48494 static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
48495- unsigned long arg, int ifreq_len)
48496+ unsigned long arg, size_t ifreq_len)
48497 {
48498 struct tun_file *tfile = file->private_data;
48499 struct tun_struct *tun;
48500@@ -1881,6 +1881,9 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
48501 unsigned int ifindex;
48502 int ret;
48503
48504+ if (ifreq_len > sizeof ifr)
48505+ return -EFAULT;
48506+
48507 if (cmd == TUNSETIFF || cmd == TUNSETQUEUE || _IOC_TYPE(cmd) == 0x89) {
48508 if (copy_from_user(&ifr, argp, ifreq_len))
48509 return -EFAULT;
48510diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
48511index babda7d..e40c90a 100644
48512--- a/drivers/net/usb/hso.c
48513+++ b/drivers/net/usb/hso.c
48514@@ -71,7 +71,7 @@
48515 #include <asm/byteorder.h>
48516 #include <linux/serial_core.h>
48517 #include <linux/serial.h>
48518-
48519+#include <asm/local.h>
48520
48521 #define MOD_AUTHOR "Option Wireless"
48522 #define MOD_DESCRIPTION "USB High Speed Option driver"
48523@@ -1178,7 +1178,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
48524 struct urb *urb;
48525
48526 urb = serial->rx_urb[0];
48527- if (serial->port.count > 0) {
48528+ if (atomic_read(&serial->port.count) > 0) {
48529 count = put_rxbuf_data(urb, serial);
48530 if (count == -1)
48531 return;
48532@@ -1216,7 +1216,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
48533 DUMP1(urb->transfer_buffer, urb->actual_length);
48534
48535 /* Anyone listening? */
48536- if (serial->port.count == 0)
48537+ if (atomic_read(&serial->port.count) == 0)
48538 return;
48539
48540 if (serial->parent->port_spec & HSO_INFO_CRC_BUG)
48541@@ -1278,8 +1278,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
48542 tty_port_tty_set(&serial->port, tty);
48543
48544 /* check for port already opened, if not set the termios */
48545- serial->port.count++;
48546- if (serial->port.count == 1) {
48547+ if (atomic_inc_return(&serial->port.count) == 1) {
48548 serial->rx_state = RX_IDLE;
48549 /* Force default termio settings */
48550 _hso_serial_set_termios(tty, NULL);
48551@@ -1289,7 +1288,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
48552 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
48553 if (result) {
48554 hso_stop_serial_device(serial->parent);
48555- serial->port.count--;
48556+ atomic_dec(&serial->port.count);
48557 kref_put(&serial->parent->ref, hso_serial_ref_free);
48558 }
48559 } else {
48560@@ -1326,10 +1325,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
48561
48562 /* reset the rts and dtr */
48563 /* do the actual close */
48564- serial->port.count--;
48565+ atomic_dec(&serial->port.count);
48566
48567- if (serial->port.count <= 0) {
48568- serial->port.count = 0;
48569+ if (atomic_read(&serial->port.count) <= 0) {
48570+ atomic_set(&serial->port.count, 0);
48571 tty_port_tty_set(&serial->port, NULL);
48572 if (!usb_gone)
48573 hso_stop_serial_device(serial->parent);
48574@@ -1404,7 +1403,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
48575
48576 /* the actual setup */
48577 spin_lock_irqsave(&serial->serial_lock, flags);
48578- if (serial->port.count)
48579+ if (atomic_read(&serial->port.count))
48580 _hso_serial_set_termios(tty, old);
48581 else
48582 tty->termios = *old;
48583@@ -1873,7 +1872,7 @@ static void intr_callback(struct urb *urb)
48584 D1("Pending read interrupt on port %d\n", i);
48585 spin_lock(&serial->serial_lock);
48586 if (serial->rx_state == RX_IDLE &&
48587- serial->port.count > 0) {
48588+ atomic_read(&serial->port.count) > 0) {
48589 /* Setup and send a ctrl req read on
48590 * port i */
48591 if (!serial->rx_urb_filled[0]) {
48592@@ -3047,7 +3046,7 @@ static int hso_resume(struct usb_interface *iface)
48593 /* Start all serial ports */
48594 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
48595 if (serial_table[i] && (serial_table[i]->interface == iface)) {
48596- if (dev2ser(serial_table[i])->port.count) {
48597+ if (atomic_read(&dev2ser(serial_table[i])->port.count)) {
48598 result =
48599 hso_start_serial_device(serial_table[i], GFP_NOIO);
48600 hso_kick_transmit(dev2ser(serial_table[i]));
48601diff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c
48602index c6554c7..7e2ebd7 100644
48603--- a/drivers/net/usb/r8152.c
48604+++ b/drivers/net/usb/r8152.c
48605@@ -577,7 +577,7 @@ struct r8152 {
48606 void (*unload)(struct r8152 *);
48607 int (*eee_get)(struct r8152 *, struct ethtool_eee *);
48608 int (*eee_set)(struct r8152 *, struct ethtool_eee *);
48609- } rtl_ops;
48610+ } __no_const rtl_ops;
48611
48612 int intr_interval;
48613 u32 saved_wolopts;
48614diff --git a/drivers/net/usb/sierra_net.c b/drivers/net/usb/sierra_net.c
48615index a2515887..6d13233 100644
48616--- a/drivers/net/usb/sierra_net.c
48617+++ b/drivers/net/usb/sierra_net.c
48618@@ -51,7 +51,7 @@ static const char driver_name[] = "sierra_net";
48619 /* atomic counter partially included in MAC address to make sure 2 devices
48620 * do not end up with the same MAC - concept breaks in case of > 255 ifaces
48621 */
48622-static atomic_t iface_counter = ATOMIC_INIT(0);
48623+static atomic_unchecked_t iface_counter = ATOMIC_INIT(0);
48624
48625 /*
48626 * SYNC Timer Delay definition used to set the expiry time
48627@@ -697,7 +697,7 @@ static int sierra_net_bind(struct usbnet *dev, struct usb_interface *intf)
48628 dev->net->netdev_ops = &sierra_net_device_ops;
48629
48630 /* change MAC addr to include, ifacenum, and to be unique */
48631- dev->net->dev_addr[ETH_ALEN-2] = atomic_inc_return(&iface_counter);
48632+ dev->net->dev_addr[ETH_ALEN-2] = atomic_inc_return_unchecked(&iface_counter);
48633 dev->net->dev_addr[ETH_ALEN-1] = ifacenum;
48634
48635 /* we will have to manufacture ethernet headers, prepare template */
48636diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
48637index b0bc8ea..3af931b5 100644
48638--- a/drivers/net/virtio_net.c
48639+++ b/drivers/net/virtio_net.c
48640@@ -48,7 +48,7 @@ module_param(gso, bool, 0444);
48641 #define RECEIVE_AVG_WEIGHT 64
48642
48643 /* Minimum alignment for mergeable packet buffers. */
48644-#define MERGEABLE_BUFFER_ALIGN max(L1_CACHE_BYTES, 256)
48645+#define MERGEABLE_BUFFER_ALIGN max(L1_CACHE_BYTES, 256UL)
48646
48647 #define VIRTNET_DRIVER_VERSION "1.0.0"
48648
48649diff --git a/drivers/net/vxlan.c b/drivers/net/vxlan.c
48650index 42b2d6a5..2a2cb41 100644
48651--- a/drivers/net/vxlan.c
48652+++ b/drivers/net/vxlan.c
48653@@ -2695,7 +2695,7 @@ nla_put_failure:
48654 return -EMSGSIZE;
48655 }
48656
48657-static struct rtnl_link_ops vxlan_link_ops __read_mostly = {
48658+static struct rtnl_link_ops vxlan_link_ops = {
48659 .kind = "vxlan",
48660 .maxtype = IFLA_VXLAN_MAX,
48661 .policy = vxlan_policy,
48662@@ -2742,7 +2742,7 @@ static int vxlan_lowerdev_event(struct notifier_block *unused,
48663 return NOTIFY_DONE;
48664 }
48665
48666-static struct notifier_block vxlan_notifier_block __read_mostly = {
48667+static struct notifier_block vxlan_notifier_block = {
48668 .notifier_call = vxlan_lowerdev_event,
48669 };
48670
48671diff --git a/drivers/net/wan/lmc/lmc_media.c b/drivers/net/wan/lmc/lmc_media.c
48672index 5920c99..ff2e4a5 100644
48673--- a/drivers/net/wan/lmc/lmc_media.c
48674+++ b/drivers/net/wan/lmc/lmc_media.c
48675@@ -95,62 +95,63 @@ static inline void write_av9110_bit (lmc_softc_t *, int);
48676 static void write_av9110(lmc_softc_t *, u32, u32, u32, u32, u32);
48677
48678 lmc_media_t lmc_ds3_media = {
48679- lmc_ds3_init, /* special media init stuff */
48680- lmc_ds3_default, /* reset to default state */
48681- lmc_ds3_set_status, /* reset status to state provided */
48682- lmc_dummy_set_1, /* set clock source */
48683- lmc_dummy_set2_1, /* set line speed */
48684- lmc_ds3_set_100ft, /* set cable length */
48685- lmc_ds3_set_scram, /* set scrambler */
48686- lmc_ds3_get_link_status, /* get link status */
48687- lmc_dummy_set_1, /* set link status */
48688- lmc_ds3_set_crc_length, /* set CRC length */
48689- lmc_dummy_set_1, /* set T1 or E1 circuit type */
48690- lmc_ds3_watchdog
48691+ .init = lmc_ds3_init, /* special media init stuff */
48692+ .defaults = lmc_ds3_default, /* reset to default state */
48693+ .set_status = lmc_ds3_set_status, /* reset status to state provided */
48694+ .set_clock_source = lmc_dummy_set_1, /* set clock source */
48695+ .set_speed = lmc_dummy_set2_1, /* set line speed */
48696+ .set_cable_length = lmc_ds3_set_100ft, /* set cable length */
48697+ .set_scrambler = lmc_ds3_set_scram, /* set scrambler */
48698+ .get_link_status = lmc_ds3_get_link_status, /* get link status */
48699+ .set_link_status = lmc_dummy_set_1, /* set link status */
48700+ .set_crc_length = lmc_ds3_set_crc_length, /* set CRC length */
48701+ .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
48702+ .watchdog = lmc_ds3_watchdog
48703 };
48704
48705 lmc_media_t lmc_hssi_media = {
48706- lmc_hssi_init, /* special media init stuff */
48707- lmc_hssi_default, /* reset to default state */
48708- lmc_hssi_set_status, /* reset status to state provided */
48709- lmc_hssi_set_clock, /* set clock source */
48710- lmc_dummy_set2_1, /* set line speed */
48711- lmc_dummy_set_1, /* set cable length */
48712- lmc_dummy_set_1, /* set scrambler */
48713- lmc_hssi_get_link_status, /* get link status */
48714- lmc_hssi_set_link_status, /* set link status */
48715- lmc_hssi_set_crc_length, /* set CRC length */
48716- lmc_dummy_set_1, /* set T1 or E1 circuit type */
48717- lmc_hssi_watchdog
48718+ .init = lmc_hssi_init, /* special media init stuff */
48719+ .defaults = lmc_hssi_default, /* reset to default state */
48720+ .set_status = lmc_hssi_set_status, /* reset status to state provided */
48721+ .set_clock_source = lmc_hssi_set_clock, /* set clock source */
48722+ .set_speed = lmc_dummy_set2_1, /* set line speed */
48723+ .set_cable_length = lmc_dummy_set_1, /* set cable length */
48724+ .set_scrambler = lmc_dummy_set_1, /* set scrambler */
48725+ .get_link_status = lmc_hssi_get_link_status, /* get link status */
48726+ .set_link_status = lmc_hssi_set_link_status, /* set link status */
48727+ .set_crc_length = lmc_hssi_set_crc_length, /* set CRC length */
48728+ .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
48729+ .watchdog = lmc_hssi_watchdog
48730 };
48731
48732-lmc_media_t lmc_ssi_media = { lmc_ssi_init, /* special media init stuff */
48733- lmc_ssi_default, /* reset to default state */
48734- lmc_ssi_set_status, /* reset status to state provided */
48735- lmc_ssi_set_clock, /* set clock source */
48736- lmc_ssi_set_speed, /* set line speed */
48737- lmc_dummy_set_1, /* set cable length */
48738- lmc_dummy_set_1, /* set scrambler */
48739- lmc_ssi_get_link_status, /* get link status */
48740- lmc_ssi_set_link_status, /* set link status */
48741- lmc_ssi_set_crc_length, /* set CRC length */
48742- lmc_dummy_set_1, /* set T1 or E1 circuit type */
48743- lmc_ssi_watchdog
48744+lmc_media_t lmc_ssi_media = {
48745+ .init = lmc_ssi_init, /* special media init stuff */
48746+ .defaults = lmc_ssi_default, /* reset to default state */
48747+ .set_status = lmc_ssi_set_status, /* reset status to state provided */
48748+ .set_clock_source = lmc_ssi_set_clock, /* set clock source */
48749+ .set_speed = lmc_ssi_set_speed, /* set line speed */
48750+ .set_cable_length = lmc_dummy_set_1, /* set cable length */
48751+ .set_scrambler = lmc_dummy_set_1, /* set scrambler */
48752+ .get_link_status = lmc_ssi_get_link_status, /* get link status */
48753+ .set_link_status = lmc_ssi_set_link_status, /* set link status */
48754+ .set_crc_length = lmc_ssi_set_crc_length, /* set CRC length */
48755+ .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
48756+ .watchdog = lmc_ssi_watchdog
48757 };
48758
48759 lmc_media_t lmc_t1_media = {
48760- lmc_t1_init, /* special media init stuff */
48761- lmc_t1_default, /* reset to default state */
48762- lmc_t1_set_status, /* reset status to state provided */
48763- lmc_t1_set_clock, /* set clock source */
48764- lmc_dummy_set2_1, /* set line speed */
48765- lmc_dummy_set_1, /* set cable length */
48766- lmc_dummy_set_1, /* set scrambler */
48767- lmc_t1_get_link_status, /* get link status */
48768- lmc_dummy_set_1, /* set link status */
48769- lmc_t1_set_crc_length, /* set CRC length */
48770- lmc_t1_set_circuit_type, /* set T1 or E1 circuit type */
48771- lmc_t1_watchdog
48772+ .init = lmc_t1_init, /* special media init stuff */
48773+ .defaults = lmc_t1_default, /* reset to default state */
48774+ .set_status = lmc_t1_set_status, /* reset status to state provided */
48775+ .set_clock_source = lmc_t1_set_clock, /* set clock source */
48776+ .set_speed = lmc_dummy_set2_1, /* set line speed */
48777+ .set_cable_length = lmc_dummy_set_1, /* set cable length */
48778+ .set_scrambler = lmc_dummy_set_1, /* set scrambler */
48779+ .get_link_status = lmc_t1_get_link_status, /* get link status */
48780+ .set_link_status = lmc_dummy_set_1, /* set link status */
48781+ .set_crc_length = lmc_t1_set_crc_length, /* set CRC length */
48782+ .set_circuit_type = lmc_t1_set_circuit_type, /* set T1 or E1 circuit type */
48783+ .watchdog = lmc_t1_watchdog
48784 };
48785
48786 static void
48787diff --git a/drivers/net/wan/z85230.c b/drivers/net/wan/z85230.c
48788index feacc3b..5bac0de 100644
48789--- a/drivers/net/wan/z85230.c
48790+++ b/drivers/net/wan/z85230.c
48791@@ -485,9 +485,9 @@ static void z8530_status(struct z8530_channel *chan)
48792
48793 struct z8530_irqhandler z8530_sync =
48794 {
48795- z8530_rx,
48796- z8530_tx,
48797- z8530_status
48798+ .rx = z8530_rx,
48799+ .tx = z8530_tx,
48800+ .status = z8530_status
48801 };
48802
48803 EXPORT_SYMBOL(z8530_sync);
48804@@ -605,15 +605,15 @@ static void z8530_dma_status(struct z8530_channel *chan)
48805 }
48806
48807 static struct z8530_irqhandler z8530_dma_sync = {
48808- z8530_dma_rx,
48809- z8530_dma_tx,
48810- z8530_dma_status
48811+ .rx = z8530_dma_rx,
48812+ .tx = z8530_dma_tx,
48813+ .status = z8530_dma_status
48814 };
48815
48816 static struct z8530_irqhandler z8530_txdma_sync = {
48817- z8530_rx,
48818- z8530_dma_tx,
48819- z8530_dma_status
48820+ .rx = z8530_rx,
48821+ .tx = z8530_dma_tx,
48822+ .status = z8530_dma_status
48823 };
48824
48825 /**
48826@@ -680,9 +680,9 @@ static void z8530_status_clear(struct z8530_channel *chan)
48827
48828 struct z8530_irqhandler z8530_nop=
48829 {
48830- z8530_rx_clear,
48831- z8530_tx_clear,
48832- z8530_status_clear
48833+ .rx = z8530_rx_clear,
48834+ .tx = z8530_tx_clear,
48835+ .status = z8530_status_clear
48836 };
48837
48838
48839diff --git a/drivers/net/wimax/i2400m/rx.c b/drivers/net/wimax/i2400m/rx.c
48840index 0b60295..b8bfa5b 100644
48841--- a/drivers/net/wimax/i2400m/rx.c
48842+++ b/drivers/net/wimax/i2400m/rx.c
48843@@ -1359,7 +1359,7 @@ int i2400m_rx_setup(struct i2400m *i2400m)
48844 if (i2400m->rx_roq == NULL)
48845 goto error_roq_alloc;
48846
48847- rd = kcalloc(I2400M_RO_CIN + 1, sizeof(*i2400m->rx_roq[0].log),
48848+ rd = kcalloc(sizeof(*i2400m->rx_roq[0].log), I2400M_RO_CIN + 1,
48849 GFP_KERNEL);
48850 if (rd == NULL) {
48851 result = -ENOMEM;
48852diff --git a/drivers/net/wireless/airo.c b/drivers/net/wireless/airo.c
48853index e71a2ce..2268d61 100644
48854--- a/drivers/net/wireless/airo.c
48855+++ b/drivers/net/wireless/airo.c
48856@@ -7846,7 +7846,7 @@ static int writerids(struct net_device *dev, aironet_ioctl *comp) {
48857 struct airo_info *ai = dev->ml_priv;
48858 int ridcode;
48859 int enabled;
48860- static int (* writer)(struct airo_info *, u16 rid, const void *, int, int);
48861+ int (* writer)(struct airo_info *, u16 rid, const void *, int, int);
48862 unsigned char *iobuf;
48863
48864 /* Only super-user can write RIDs */
48865diff --git a/drivers/net/wireless/at76c50x-usb.c b/drivers/net/wireless/at76c50x-usb.c
48866index da92bfa..5a9001a 100644
48867--- a/drivers/net/wireless/at76c50x-usb.c
48868+++ b/drivers/net/wireless/at76c50x-usb.c
48869@@ -353,7 +353,7 @@ static int at76_dfu_get_state(struct usb_device *udev, u8 *state)
48870 }
48871
48872 /* Convert timeout from the DFU status to jiffies */
48873-static inline unsigned long at76_get_timeout(struct dfu_status *s)
48874+static inline unsigned long __intentional_overflow(-1) at76_get_timeout(struct dfu_status *s)
48875 {
48876 return msecs_to_jiffies((s->poll_timeout[2] << 16)
48877 | (s->poll_timeout[1] << 8)
48878diff --git a/drivers/net/wireless/ath/ath10k/htc.c b/drivers/net/wireless/ath/ath10k/htc.c
48879index 676bd4e..0b807a3 100644
48880--- a/drivers/net/wireless/ath/ath10k/htc.c
48881+++ b/drivers/net/wireless/ath/ath10k/htc.c
48882@@ -848,7 +848,10 @@ int ath10k_htc_start(struct ath10k_htc *htc)
48883 /* registered target arrival callback from the HIF layer */
48884 int ath10k_htc_init(struct ath10k *ar)
48885 {
48886- struct ath10k_hif_cb htc_callbacks;
48887+ static struct ath10k_hif_cb htc_callbacks = {
48888+ .rx_completion = ath10k_htc_rx_completion_handler,
48889+ .tx_completion = ath10k_htc_tx_completion_handler,
48890+ };
48891 struct ath10k_htc_ep *ep = NULL;
48892 struct ath10k_htc *htc = &ar->htc;
48893
48894@@ -857,8 +860,6 @@ int ath10k_htc_init(struct ath10k *ar)
48895 ath10k_htc_reset_endpoint_states(htc);
48896
48897 /* setup HIF layer callbacks */
48898- htc_callbacks.rx_completion = ath10k_htc_rx_completion_handler;
48899- htc_callbacks.tx_completion = ath10k_htc_tx_completion_handler;
48900 htc->ar = ar;
48901
48902 /* Get HIF default pipe for HTC message exchange */
48903diff --git a/drivers/net/wireless/ath/ath10k/htc.h b/drivers/net/wireless/ath/ath10k/htc.h
48904index 527179c..a890150 100644
48905--- a/drivers/net/wireless/ath/ath10k/htc.h
48906+++ b/drivers/net/wireless/ath/ath10k/htc.h
48907@@ -270,13 +270,13 @@ enum ath10k_htc_ep_id {
48908
48909 struct ath10k_htc_ops {
48910 void (*target_send_suspend_complete)(struct ath10k *ar);
48911-};
48912+} __no_const;
48913
48914 struct ath10k_htc_ep_ops {
48915 void (*ep_tx_complete)(struct ath10k *, struct sk_buff *);
48916 void (*ep_rx_complete)(struct ath10k *, struct sk_buff *);
48917 void (*ep_tx_credits)(struct ath10k *);
48918-};
48919+} __no_const;
48920
48921 /* service connection information */
48922 struct ath10k_htc_svc_conn_req {
48923diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
48924index 2a93519..7052786 100644
48925--- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
48926+++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
48927@@ -220,8 +220,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
48928 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
48929 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
48930
48931- ACCESS_ONCE(ads->ds_link) = i->link;
48932- ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
48933+ ACCESS_ONCE_RW(ads->ds_link) = i->link;
48934+ ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
48935
48936 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
48937 ctl6 = SM(i->keytype, AR_EncrType);
48938@@ -235,26 +235,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
48939
48940 if ((i->is_first || i->is_last) &&
48941 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
48942- ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
48943+ ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
48944 | set11nTries(i->rates, 1)
48945 | set11nTries(i->rates, 2)
48946 | set11nTries(i->rates, 3)
48947 | (i->dur_update ? AR_DurUpdateEna : 0)
48948 | SM(0, AR_BurstDur);
48949
48950- ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
48951+ ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
48952 | set11nRate(i->rates, 1)
48953 | set11nRate(i->rates, 2)
48954 | set11nRate(i->rates, 3);
48955 } else {
48956- ACCESS_ONCE(ads->ds_ctl2) = 0;
48957- ACCESS_ONCE(ads->ds_ctl3) = 0;
48958+ ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
48959+ ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
48960 }
48961
48962 if (!i->is_first) {
48963- ACCESS_ONCE(ads->ds_ctl0) = 0;
48964- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
48965- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
48966+ ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
48967+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
48968+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
48969 return;
48970 }
48971
48972@@ -279,7 +279,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
48973 break;
48974 }
48975
48976- ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
48977+ ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
48978 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
48979 | SM(i->txpower, AR_XmitPower0)
48980 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
48981@@ -289,27 +289,27 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
48982 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
48983 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
48984
48985- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
48986- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
48987+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
48988+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
48989
48990 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
48991 return;
48992
48993- ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
48994+ ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
48995 | set11nPktDurRTSCTS(i->rates, 1);
48996
48997- ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
48998+ ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
48999 | set11nPktDurRTSCTS(i->rates, 3);
49000
49001- ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
49002+ ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
49003 | set11nRateFlags(i->rates, 1)
49004 | set11nRateFlags(i->rates, 2)
49005 | set11nRateFlags(i->rates, 3)
49006 | SM(i->rtscts_rate, AR_RTSCTSRate);
49007
49008- ACCESS_ONCE(ads->ds_ctl9) = SM(i->txpower, AR_XmitPower1);
49009- ACCESS_ONCE(ads->ds_ctl10) = SM(i->txpower, AR_XmitPower2);
49010- ACCESS_ONCE(ads->ds_ctl11) = SM(i->txpower, AR_XmitPower3);
49011+ ACCESS_ONCE_RW(ads->ds_ctl9) = SM(i->txpower, AR_XmitPower1);
49012+ ACCESS_ONCE_RW(ads->ds_ctl10) = SM(i->txpower, AR_XmitPower2);
49013+ ACCESS_ONCE_RW(ads->ds_ctl11) = SM(i->txpower, AR_XmitPower3);
49014 }
49015
49016 static int ar9002_hw_proc_txdesc(struct ath_hw *ah, void *ds,
49017diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
49018index 057b165..98ae88f 100644
49019--- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
49020+++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
49021@@ -39,47 +39,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
49022 (i->qcu << AR_TxQcuNum_S) | desc_len;
49023
49024 checksum += val;
49025- ACCESS_ONCE(ads->info) = val;
49026+ ACCESS_ONCE_RW(ads->info) = val;
49027
49028 checksum += i->link;
49029- ACCESS_ONCE(ads->link) = i->link;
49030+ ACCESS_ONCE_RW(ads->link) = i->link;
49031
49032 checksum += i->buf_addr[0];
49033- ACCESS_ONCE(ads->data0) = i->buf_addr[0];
49034+ ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
49035 checksum += i->buf_addr[1];
49036- ACCESS_ONCE(ads->data1) = i->buf_addr[1];
49037+ ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
49038 checksum += i->buf_addr[2];
49039- ACCESS_ONCE(ads->data2) = i->buf_addr[2];
49040+ ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
49041 checksum += i->buf_addr[3];
49042- ACCESS_ONCE(ads->data3) = i->buf_addr[3];
49043+ ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
49044
49045 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
49046- ACCESS_ONCE(ads->ctl3) = val;
49047+ ACCESS_ONCE_RW(ads->ctl3) = val;
49048 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
49049- ACCESS_ONCE(ads->ctl5) = val;
49050+ ACCESS_ONCE_RW(ads->ctl5) = val;
49051 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
49052- ACCESS_ONCE(ads->ctl7) = val;
49053+ ACCESS_ONCE_RW(ads->ctl7) = val;
49054 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
49055- ACCESS_ONCE(ads->ctl9) = val;
49056+ ACCESS_ONCE_RW(ads->ctl9) = val;
49057
49058 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
49059- ACCESS_ONCE(ads->ctl10) = checksum;
49060+ ACCESS_ONCE_RW(ads->ctl10) = checksum;
49061
49062 if (i->is_first || i->is_last) {
49063- ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
49064+ ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
49065 | set11nTries(i->rates, 1)
49066 | set11nTries(i->rates, 2)
49067 | set11nTries(i->rates, 3)
49068 | (i->dur_update ? AR_DurUpdateEna : 0)
49069 | SM(0, AR_BurstDur);
49070
49071- ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
49072+ ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
49073 | set11nRate(i->rates, 1)
49074 | set11nRate(i->rates, 2)
49075 | set11nRate(i->rates, 3);
49076 } else {
49077- ACCESS_ONCE(ads->ctl13) = 0;
49078- ACCESS_ONCE(ads->ctl14) = 0;
49079+ ACCESS_ONCE_RW(ads->ctl13) = 0;
49080+ ACCESS_ONCE_RW(ads->ctl14) = 0;
49081 }
49082
49083 ads->ctl20 = 0;
49084@@ -89,17 +89,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
49085
49086 ctl17 = SM(i->keytype, AR_EncrType);
49087 if (!i->is_first) {
49088- ACCESS_ONCE(ads->ctl11) = 0;
49089- ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
49090- ACCESS_ONCE(ads->ctl15) = 0;
49091- ACCESS_ONCE(ads->ctl16) = 0;
49092- ACCESS_ONCE(ads->ctl17) = ctl17;
49093- ACCESS_ONCE(ads->ctl18) = 0;
49094- ACCESS_ONCE(ads->ctl19) = 0;
49095+ ACCESS_ONCE_RW(ads->ctl11) = 0;
49096+ ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
49097+ ACCESS_ONCE_RW(ads->ctl15) = 0;
49098+ ACCESS_ONCE_RW(ads->ctl16) = 0;
49099+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
49100+ ACCESS_ONCE_RW(ads->ctl18) = 0;
49101+ ACCESS_ONCE_RW(ads->ctl19) = 0;
49102 return;
49103 }
49104
49105- ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
49106+ ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
49107 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
49108 | SM(i->txpower, AR_XmitPower0)
49109 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
49110@@ -135,26 +135,26 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
49111 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
49112 ctl12 |= SM(val, AR_PAPRDChainMask);
49113
49114- ACCESS_ONCE(ads->ctl12) = ctl12;
49115- ACCESS_ONCE(ads->ctl17) = ctl17;
49116+ ACCESS_ONCE_RW(ads->ctl12) = ctl12;
49117+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
49118
49119- ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
49120+ ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
49121 | set11nPktDurRTSCTS(i->rates, 1);
49122
49123- ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
49124+ ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
49125 | set11nPktDurRTSCTS(i->rates, 3);
49126
49127- ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
49128+ ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
49129 | set11nRateFlags(i->rates, 1)
49130 | set11nRateFlags(i->rates, 2)
49131 | set11nRateFlags(i->rates, 3)
49132 | SM(i->rtscts_rate, AR_RTSCTSRate);
49133
49134- ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
49135+ ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
49136
49137- ACCESS_ONCE(ads->ctl20) = SM(i->txpower, AR_XmitPower1);
49138- ACCESS_ONCE(ads->ctl21) = SM(i->txpower, AR_XmitPower2);
49139- ACCESS_ONCE(ads->ctl22) = SM(i->txpower, AR_XmitPower3);
49140+ ACCESS_ONCE_RW(ads->ctl20) = SM(i->txpower, AR_XmitPower1);
49141+ ACCESS_ONCE_RW(ads->ctl21) = SM(i->txpower, AR_XmitPower2);
49142+ ACCESS_ONCE_RW(ads->ctl22) = SM(i->txpower, AR_XmitPower3);
49143 }
49144
49145 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
49146diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
49147index 975074f..e9440da 100644
49148--- a/drivers/net/wireless/ath/ath9k/hw.h
49149+++ b/drivers/net/wireless/ath/ath9k/hw.h
49150@@ -630,7 +630,7 @@ struct ath_hw_private_ops {
49151
49152 /* ANI */
49153 void (*ani_cache_ini_regs)(struct ath_hw *ah);
49154-};
49155+} __no_const;
49156
49157 /**
49158 * struct ath_spec_scan - parameters for Atheros spectral scan
49159@@ -708,7 +708,7 @@ struct ath_hw_ops {
49160 #ifdef CONFIG_ATH9K_BTCOEX_SUPPORT
49161 void (*set_bt_ant_diversity)(struct ath_hw *hw, bool enable);
49162 #endif
49163-};
49164+} __no_const;
49165
49166 struct ath_nf_limits {
49167 s16 max;
49168diff --git a/drivers/net/wireless/ath/ath9k/main.c b/drivers/net/wireless/ath/ath9k/main.c
49169index 4f18a6b..b07d92f 100644
49170--- a/drivers/net/wireless/ath/ath9k/main.c
49171+++ b/drivers/net/wireless/ath/ath9k/main.c
49172@@ -2454,16 +2454,18 @@ void ath9k_fill_chanctx_ops(void)
49173 if (!ath9k_is_chanctx_enabled())
49174 return;
49175
49176- ath9k_ops.hw_scan = ath9k_hw_scan;
49177- ath9k_ops.cancel_hw_scan = ath9k_cancel_hw_scan;
49178- ath9k_ops.remain_on_channel = ath9k_remain_on_channel;
49179- ath9k_ops.cancel_remain_on_channel = ath9k_cancel_remain_on_channel;
49180- ath9k_ops.add_chanctx = ath9k_add_chanctx;
49181- ath9k_ops.remove_chanctx = ath9k_remove_chanctx;
49182- ath9k_ops.change_chanctx = ath9k_change_chanctx;
49183- ath9k_ops.assign_vif_chanctx = ath9k_assign_vif_chanctx;
49184- ath9k_ops.unassign_vif_chanctx = ath9k_unassign_vif_chanctx;
49185- ath9k_ops.mgd_prepare_tx = ath9k_mgd_prepare_tx;
49186+ pax_open_kernel();
49187+ *(void **)&ath9k_ops.hw_scan = ath9k_hw_scan;
49188+ *(void **)&ath9k_ops.cancel_hw_scan = ath9k_cancel_hw_scan;
49189+ *(void **)&ath9k_ops.remain_on_channel = ath9k_remain_on_channel;
49190+ *(void **)&ath9k_ops.cancel_remain_on_channel = ath9k_cancel_remain_on_channel;
49191+ *(void **)&ath9k_ops.add_chanctx = ath9k_add_chanctx;
49192+ *(void **)&ath9k_ops.remove_chanctx = ath9k_remove_chanctx;
49193+ *(void **)&ath9k_ops.change_chanctx = ath9k_change_chanctx;
49194+ *(void **)&ath9k_ops.assign_vif_chanctx = ath9k_assign_vif_chanctx;
49195+ *(void **)&ath9k_ops.unassign_vif_chanctx = ath9k_unassign_vif_chanctx;
49196+ *(void **)&ath9k_ops.mgd_prepare_tx = ath9k_mgd_prepare_tx;
49197+ pax_close_kernel();
49198 }
49199
49200 #endif
49201diff --git a/drivers/net/wireless/b43/phy_lp.c b/drivers/net/wireless/b43/phy_lp.c
49202index 058a9f2..d5cb1ba 100644
49203--- a/drivers/net/wireless/b43/phy_lp.c
49204+++ b/drivers/net/wireless/b43/phy_lp.c
49205@@ -2502,7 +2502,7 @@ static int lpphy_b2063_tune(struct b43_wldev *dev,
49206 {
49207 struct ssb_bus *bus = dev->dev->sdev->bus;
49208
49209- static const struct b206x_channel *chandata = NULL;
49210+ const struct b206x_channel *chandata = NULL;
49211 u32 crystal_freq = bus->chipco.pmu.crystalfreq * 1000;
49212 u32 freqref, vco_freq, val1, val2, val3, timeout, timeoutref, count;
49213 u16 old_comm15, scale;
49214diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
49215index dc1d20c..f7a4f06 100644
49216--- a/drivers/net/wireless/iwlegacy/3945-mac.c
49217+++ b/drivers/net/wireless/iwlegacy/3945-mac.c
49218@@ -3633,7 +3633,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
49219 */
49220 if (il3945_mod_params.disable_hw_scan) {
49221 D_INFO("Disabling hw_scan\n");
49222- il3945_mac_ops.hw_scan = NULL;
49223+ pax_open_kernel();
49224+ *(void **)&il3945_mac_ops.hw_scan = NULL;
49225+ pax_close_kernel();
49226 }
49227
49228 D_INFO("*** LOAD DRIVER ***\n");
49229diff --git a/drivers/net/wireless/iwlwifi/dvm/debugfs.c b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
49230index 0ffb6ff..c0b7f0e 100644
49231--- a/drivers/net/wireless/iwlwifi/dvm/debugfs.c
49232+++ b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
49233@@ -188,7 +188,7 @@ static ssize_t iwl_dbgfs_sram_write(struct file *file,
49234 {
49235 struct iwl_priv *priv = file->private_data;
49236 char buf[64];
49237- int buf_size;
49238+ size_t buf_size;
49239 u32 offset, len;
49240
49241 memset(buf, 0, sizeof(buf));
49242@@ -458,7 +458,7 @@ static ssize_t iwl_dbgfs_rx_handlers_write(struct file *file,
49243 struct iwl_priv *priv = file->private_data;
49244
49245 char buf[8];
49246- int buf_size;
49247+ size_t buf_size;
49248 u32 reset_flag;
49249
49250 memset(buf, 0, sizeof(buf));
49251@@ -539,7 +539,7 @@ static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
49252 {
49253 struct iwl_priv *priv = file->private_data;
49254 char buf[8];
49255- int buf_size;
49256+ size_t buf_size;
49257 int ht40;
49258
49259 memset(buf, 0, sizeof(buf));
49260@@ -591,7 +591,7 @@ static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file,
49261 {
49262 struct iwl_priv *priv = file->private_data;
49263 char buf[8];
49264- int buf_size;
49265+ size_t buf_size;
49266 int value;
49267
49268 memset(buf, 0, sizeof(buf));
49269@@ -683,10 +683,10 @@ DEBUGFS_READ_FILE_OPS(temperature);
49270 DEBUGFS_READ_WRITE_FILE_OPS(sleep_level_override);
49271 DEBUGFS_READ_FILE_OPS(current_sleep_command);
49272
49273-static const char *fmt_value = " %-30s %10u\n";
49274-static const char *fmt_hex = " %-30s 0x%02X\n";
49275-static const char *fmt_table = " %-30s %10u %10u %10u %10u\n";
49276-static const char *fmt_header =
49277+static const char fmt_value[] = " %-30s %10u\n";
49278+static const char fmt_hex[] = " %-30s 0x%02X\n";
49279+static const char fmt_table[] = " %-30s %10u %10u %10u %10u\n";
49280+static const char fmt_header[] =
49281 "%-32s current cumulative delta max\n";
49282
49283 static int iwl_statistics_flag(struct iwl_priv *priv, char *buf, int bufsz)
49284@@ -1856,7 +1856,7 @@ static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
49285 {
49286 struct iwl_priv *priv = file->private_data;
49287 char buf[8];
49288- int buf_size;
49289+ size_t buf_size;
49290 int clear;
49291
49292 memset(buf, 0, sizeof(buf));
49293@@ -1901,7 +1901,7 @@ static ssize_t iwl_dbgfs_ucode_tracing_write(struct file *file,
49294 {
49295 struct iwl_priv *priv = file->private_data;
49296 char buf[8];
49297- int buf_size;
49298+ size_t buf_size;
49299 int trace;
49300
49301 memset(buf, 0, sizeof(buf));
49302@@ -1972,7 +1972,7 @@ static ssize_t iwl_dbgfs_missed_beacon_write(struct file *file,
49303 {
49304 struct iwl_priv *priv = file->private_data;
49305 char buf[8];
49306- int buf_size;
49307+ size_t buf_size;
49308 int missed;
49309
49310 memset(buf, 0, sizeof(buf));
49311@@ -2013,7 +2013,7 @@ static ssize_t iwl_dbgfs_plcp_delta_write(struct file *file,
49312
49313 struct iwl_priv *priv = file->private_data;
49314 char buf[8];
49315- int buf_size;
49316+ size_t buf_size;
49317 int plcp;
49318
49319 memset(buf, 0, sizeof(buf));
49320@@ -2073,7 +2073,7 @@ static ssize_t iwl_dbgfs_txfifo_flush_write(struct file *file,
49321
49322 struct iwl_priv *priv = file->private_data;
49323 char buf[8];
49324- int buf_size;
49325+ size_t buf_size;
49326 int flush;
49327
49328 memset(buf, 0, sizeof(buf));
49329@@ -2163,7 +2163,7 @@ static ssize_t iwl_dbgfs_protection_mode_write(struct file *file,
49330
49331 struct iwl_priv *priv = file->private_data;
49332 char buf[8];
49333- int buf_size;
49334+ size_t buf_size;
49335 int rts;
49336
49337 if (!priv->cfg->ht_params)
49338@@ -2204,7 +2204,7 @@ static ssize_t iwl_dbgfs_echo_test_write(struct file *file,
49339 {
49340 struct iwl_priv *priv = file->private_data;
49341 char buf[8];
49342- int buf_size;
49343+ size_t buf_size;
49344
49345 memset(buf, 0, sizeof(buf));
49346 buf_size = min(count, sizeof(buf) - 1);
49347@@ -2238,7 +2238,7 @@ static ssize_t iwl_dbgfs_log_event_write(struct file *file,
49348 struct iwl_priv *priv = file->private_data;
49349 u32 event_log_flag;
49350 char buf[8];
49351- int buf_size;
49352+ size_t buf_size;
49353
49354 /* check that the interface is up */
49355 if (!iwl_is_ready(priv))
49356@@ -2292,7 +2292,7 @@ static ssize_t iwl_dbgfs_calib_disabled_write(struct file *file,
49357 struct iwl_priv *priv = file->private_data;
49358 char buf[8];
49359 u32 calib_disabled;
49360- int buf_size;
49361+ size_t buf_size;
49362
49363 memset(buf, 0, sizeof(buf));
49364 buf_size = min(count, sizeof(buf) - 1);
49365diff --git a/drivers/net/wireless/iwlwifi/pcie/trans.c b/drivers/net/wireless/iwlwifi/pcie/trans.c
49366index dd2f3f8..fb1ae88 100644
49367--- a/drivers/net/wireless/iwlwifi/pcie/trans.c
49368+++ b/drivers/net/wireless/iwlwifi/pcie/trans.c
49369@@ -1689,7 +1689,7 @@ static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
49370 struct isr_statistics *isr_stats = &trans_pcie->isr_stats;
49371
49372 char buf[8];
49373- int buf_size;
49374+ size_t buf_size;
49375 u32 reset_flag;
49376
49377 memset(buf, 0, sizeof(buf));
49378@@ -1710,7 +1710,7 @@ static ssize_t iwl_dbgfs_csr_write(struct file *file,
49379 {
49380 struct iwl_trans *trans = file->private_data;
49381 char buf[8];
49382- int buf_size;
49383+ size_t buf_size;
49384 int csr;
49385
49386 memset(buf, 0, sizeof(buf));
49387diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
49388index c9ad4cf..49a2fa0 100644
49389--- a/drivers/net/wireless/mac80211_hwsim.c
49390+++ b/drivers/net/wireless/mac80211_hwsim.c
49391@@ -2577,20 +2577,20 @@ static int __init init_mac80211_hwsim(void)
49392 if (channels < 1)
49393 return -EINVAL;
49394
49395- mac80211_hwsim_mchan_ops = mac80211_hwsim_ops;
49396- mac80211_hwsim_mchan_ops.hw_scan = mac80211_hwsim_hw_scan;
49397- mac80211_hwsim_mchan_ops.cancel_hw_scan = mac80211_hwsim_cancel_hw_scan;
49398- mac80211_hwsim_mchan_ops.sw_scan_start = NULL;
49399- mac80211_hwsim_mchan_ops.sw_scan_complete = NULL;
49400- mac80211_hwsim_mchan_ops.remain_on_channel = mac80211_hwsim_roc;
49401- mac80211_hwsim_mchan_ops.cancel_remain_on_channel = mac80211_hwsim_croc;
49402- mac80211_hwsim_mchan_ops.add_chanctx = mac80211_hwsim_add_chanctx;
49403- mac80211_hwsim_mchan_ops.remove_chanctx = mac80211_hwsim_remove_chanctx;
49404- mac80211_hwsim_mchan_ops.change_chanctx = mac80211_hwsim_change_chanctx;
49405- mac80211_hwsim_mchan_ops.assign_vif_chanctx =
49406- mac80211_hwsim_assign_vif_chanctx;
49407- mac80211_hwsim_mchan_ops.unassign_vif_chanctx =
49408- mac80211_hwsim_unassign_vif_chanctx;
49409+ pax_open_kernel();
49410+ memcpy((void *)&mac80211_hwsim_mchan_ops, &mac80211_hwsim_ops, sizeof mac80211_hwsim_mchan_ops);
49411+ *(void **)&mac80211_hwsim_mchan_ops.hw_scan = mac80211_hwsim_hw_scan;
49412+ *(void **)&mac80211_hwsim_mchan_ops.cancel_hw_scan = mac80211_hwsim_cancel_hw_scan;
49413+ *(void **)&mac80211_hwsim_mchan_ops.sw_scan_start = NULL;
49414+ *(void **)&mac80211_hwsim_mchan_ops.sw_scan_complete = NULL;
49415+ *(void **)&mac80211_hwsim_mchan_ops.remain_on_channel = mac80211_hwsim_roc;
49416+ *(void **)&mac80211_hwsim_mchan_ops.cancel_remain_on_channel = mac80211_hwsim_croc;
49417+ *(void **)&mac80211_hwsim_mchan_ops.add_chanctx = mac80211_hwsim_add_chanctx;
49418+ *(void **)&mac80211_hwsim_mchan_ops.remove_chanctx = mac80211_hwsim_remove_chanctx;
49419+ *(void **)&mac80211_hwsim_mchan_ops.change_chanctx = mac80211_hwsim_change_chanctx;
49420+ *(void **)&mac80211_hwsim_mchan_ops.assign_vif_chanctx = mac80211_hwsim_assign_vif_chanctx;
49421+ *(void **)&mac80211_hwsim_mchan_ops.unassign_vif_chanctx = mac80211_hwsim_unassign_vif_chanctx;
49422+ pax_close_kernel();
49423
49424 spin_lock_init(&hwsim_radio_lock);
49425 INIT_LIST_HEAD(&hwsim_radios);
49426diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
49427index 1a4facd..a2ecbbd 100644
49428--- a/drivers/net/wireless/rndis_wlan.c
49429+++ b/drivers/net/wireless/rndis_wlan.c
49430@@ -1236,7 +1236,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
49431
49432 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
49433
49434- if (rts_threshold < 0 || rts_threshold > 2347)
49435+ if (rts_threshold > 2347)
49436 rts_threshold = 2347;
49437
49438 tmp = cpu_to_le32(rts_threshold);
49439diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
49440index d13f25c..2573994 100644
49441--- a/drivers/net/wireless/rt2x00/rt2x00.h
49442+++ b/drivers/net/wireless/rt2x00/rt2x00.h
49443@@ -375,7 +375,7 @@ struct rt2x00_intf {
49444 * for hardware which doesn't support hardware
49445 * sequence counting.
49446 */
49447- atomic_t seqno;
49448+ atomic_unchecked_t seqno;
49449 };
49450
49451 static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
49452diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.c b/drivers/net/wireless/rt2x00/rt2x00queue.c
49453index 66ff364..3ce34f7 100644
49454--- a/drivers/net/wireless/rt2x00/rt2x00queue.c
49455+++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
49456@@ -224,9 +224,9 @@ static void rt2x00queue_create_tx_descriptor_seq(struct rt2x00_dev *rt2x00dev,
49457 * sequence counter given by mac80211.
49458 */
49459 if (test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags))
49460- seqno = atomic_add_return(0x10, &intf->seqno);
49461+ seqno = atomic_add_return_unchecked(0x10, &intf->seqno);
49462 else
49463- seqno = atomic_read(&intf->seqno);
49464+ seqno = atomic_read_unchecked(&intf->seqno);
49465
49466 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
49467 hdr->seq_ctrl |= cpu_to_le16(seqno);
49468diff --git a/drivers/net/wireless/ti/wl1251/sdio.c b/drivers/net/wireless/ti/wl1251/sdio.c
49469index b661f896..ddf7d2b 100644
49470--- a/drivers/net/wireless/ti/wl1251/sdio.c
49471+++ b/drivers/net/wireless/ti/wl1251/sdio.c
49472@@ -282,13 +282,17 @@ static int wl1251_sdio_probe(struct sdio_func *func,
49473
49474 irq_set_irq_type(wl->irq, IRQ_TYPE_EDGE_RISING);
49475
49476- wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
49477- wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
49478+ pax_open_kernel();
49479+ *(void **)&wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
49480+ *(void **)&wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
49481+ pax_close_kernel();
49482
49483 wl1251_info("using dedicated interrupt line");
49484 } else {
49485- wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
49486- wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
49487+ pax_open_kernel();
49488+ *(void **)&wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
49489+ *(void **)&wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
49490+ pax_close_kernel();
49491
49492 wl1251_info("using SDIO interrupt");
49493 }
49494diff --git a/drivers/net/wireless/ti/wl12xx/main.c b/drivers/net/wireless/ti/wl12xx/main.c
49495index 0bccf12..3d95068 100644
49496--- a/drivers/net/wireless/ti/wl12xx/main.c
49497+++ b/drivers/net/wireless/ti/wl12xx/main.c
49498@@ -656,7 +656,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
49499 sizeof(wl->conf.mem));
49500
49501 /* read data preparation is only needed by wl127x */
49502- wl->ops->prepare_read = wl127x_prepare_read;
49503+ pax_open_kernel();
49504+ *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
49505+ pax_close_kernel();
49506
49507 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
49508 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
49509@@ -681,7 +683,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
49510 sizeof(wl->conf.mem));
49511
49512 /* read data preparation is only needed by wl127x */
49513- wl->ops->prepare_read = wl127x_prepare_read;
49514+ pax_open_kernel();
49515+ *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
49516+ pax_close_kernel();
49517
49518 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
49519 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
49520diff --git a/drivers/net/wireless/ti/wl18xx/main.c b/drivers/net/wireless/ti/wl18xx/main.c
49521index 7af1936..128bb35 100644
49522--- a/drivers/net/wireless/ti/wl18xx/main.c
49523+++ b/drivers/net/wireless/ti/wl18xx/main.c
49524@@ -1916,8 +1916,10 @@ static int wl18xx_setup(struct wl1271 *wl)
49525 }
49526
49527 if (!checksum_param) {
49528- wl18xx_ops.set_rx_csum = NULL;
49529- wl18xx_ops.init_vif = NULL;
49530+ pax_open_kernel();
49531+ *(void **)&wl18xx_ops.set_rx_csum = NULL;
49532+ *(void **)&wl18xx_ops.init_vif = NULL;
49533+ pax_close_kernel();
49534 }
49535
49536 /* Enable 11a Band only if we have 5G antennas */
49537diff --git a/drivers/net/wireless/zd1211rw/zd_usb.c b/drivers/net/wireless/zd1211rw/zd_usb.c
49538index a912dc0..a8225ba 100644
49539--- a/drivers/net/wireless/zd1211rw/zd_usb.c
49540+++ b/drivers/net/wireless/zd1211rw/zd_usb.c
49541@@ -385,7 +385,7 @@ static inline void handle_regs_int(struct urb *urb)
49542 {
49543 struct zd_usb *usb = urb->context;
49544 struct zd_usb_interrupt *intr = &usb->intr;
49545- int len;
49546+ unsigned int len;
49547 u16 int_num;
49548
49549 ZD_ASSERT(in_interrupt());
49550diff --git a/drivers/nfc/nfcwilink.c b/drivers/nfc/nfcwilink.c
49551index 683671a..4519fc2 100644
49552--- a/drivers/nfc/nfcwilink.c
49553+++ b/drivers/nfc/nfcwilink.c
49554@@ -497,7 +497,7 @@ static struct nci_ops nfcwilink_ops = {
49555
49556 static int nfcwilink_probe(struct platform_device *pdev)
49557 {
49558- static struct nfcwilink *drv;
49559+ struct nfcwilink *drv;
49560 int rc;
49561 __u32 protocols;
49562
49563diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
49564index d93b2b6..ae50401 100644
49565--- a/drivers/oprofile/buffer_sync.c
49566+++ b/drivers/oprofile/buffer_sync.c
49567@@ -332,7 +332,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
49568 if (cookie == NO_COOKIE)
49569 offset = pc;
49570 if (cookie == INVALID_COOKIE) {
49571- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
49572+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
49573 offset = pc;
49574 }
49575 if (cookie != last_cookie) {
49576@@ -376,14 +376,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
49577 /* add userspace sample */
49578
49579 if (!mm) {
49580- atomic_inc(&oprofile_stats.sample_lost_no_mm);
49581+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
49582 return 0;
49583 }
49584
49585 cookie = lookup_dcookie(mm, s->eip, &offset);
49586
49587 if (cookie == INVALID_COOKIE) {
49588- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
49589+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
49590 return 0;
49591 }
49592
49593@@ -552,7 +552,7 @@ void sync_buffer(int cpu)
49594 /* ignore backtraces if failed to add a sample */
49595 if (state == sb_bt_start) {
49596 state = sb_bt_ignore;
49597- atomic_inc(&oprofile_stats.bt_lost_no_mapping);
49598+ atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
49599 }
49600 }
49601 release_mm(mm);
49602diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
49603index c0cc4e7..44d4e54 100644
49604--- a/drivers/oprofile/event_buffer.c
49605+++ b/drivers/oprofile/event_buffer.c
49606@@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
49607 }
49608
49609 if (buffer_pos == buffer_size) {
49610- atomic_inc(&oprofile_stats.event_lost_overflow);
49611+ atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
49612 return;
49613 }
49614
49615diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
49616index ed2c3ec..deda85a 100644
49617--- a/drivers/oprofile/oprof.c
49618+++ b/drivers/oprofile/oprof.c
49619@@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
49620 if (oprofile_ops.switch_events())
49621 return;
49622
49623- atomic_inc(&oprofile_stats.multiplex_counter);
49624+ atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
49625 start_switch_worker();
49626 }
49627
49628diff --git a/drivers/oprofile/oprofile_files.c b/drivers/oprofile/oprofile_files.c
49629index ee2cfce..7f8f699 100644
49630--- a/drivers/oprofile/oprofile_files.c
49631+++ b/drivers/oprofile/oprofile_files.c
49632@@ -27,7 +27,7 @@ unsigned long oprofile_time_slice;
49633
49634 #ifdef CONFIG_OPROFILE_EVENT_MULTIPLEX
49635
49636-static ssize_t timeout_read(struct file *file, char __user *buf,
49637+static ssize_t __intentional_overflow(-1) timeout_read(struct file *file, char __user *buf,
49638 size_t count, loff_t *offset)
49639 {
49640 return oprofilefs_ulong_to_user(jiffies_to_msecs(oprofile_time_slice),
49641diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
49642index 59659ce..6c860a0 100644
49643--- a/drivers/oprofile/oprofile_stats.c
49644+++ b/drivers/oprofile/oprofile_stats.c
49645@@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
49646 cpu_buf->sample_invalid_eip = 0;
49647 }
49648
49649- atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
49650- atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
49651- atomic_set(&oprofile_stats.event_lost_overflow, 0);
49652- atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
49653- atomic_set(&oprofile_stats.multiplex_counter, 0);
49654+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
49655+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
49656+ atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
49657+ atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
49658+ atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
49659 }
49660
49661
49662diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
49663index 1fc622b..8c48fc3 100644
49664--- a/drivers/oprofile/oprofile_stats.h
49665+++ b/drivers/oprofile/oprofile_stats.h
49666@@ -13,11 +13,11 @@
49667 #include <linux/atomic.h>
49668
49669 struct oprofile_stat_struct {
49670- atomic_t sample_lost_no_mm;
49671- atomic_t sample_lost_no_mapping;
49672- atomic_t bt_lost_no_mapping;
49673- atomic_t event_lost_overflow;
49674- atomic_t multiplex_counter;
49675+ atomic_unchecked_t sample_lost_no_mm;
49676+ atomic_unchecked_t sample_lost_no_mapping;
49677+ atomic_unchecked_t bt_lost_no_mapping;
49678+ atomic_unchecked_t event_lost_overflow;
49679+ atomic_unchecked_t multiplex_counter;
49680 };
49681
49682 extern struct oprofile_stat_struct oprofile_stats;
49683diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
49684index 3f49345..c750d0b 100644
49685--- a/drivers/oprofile/oprofilefs.c
49686+++ b/drivers/oprofile/oprofilefs.c
49687@@ -176,8 +176,8 @@ int oprofilefs_create_ro_ulong(struct dentry *root,
49688
49689 static ssize_t atomic_read_file(struct file *file, char __user *buf, size_t count, loff_t *offset)
49690 {
49691- atomic_t *val = file->private_data;
49692- return oprofilefs_ulong_to_user(atomic_read(val), buf, count, offset);
49693+ atomic_unchecked_t *val = file->private_data;
49694+ return oprofilefs_ulong_to_user(atomic_read_unchecked(val), buf, count, offset);
49695 }
49696
49697
49698@@ -189,7 +189,7 @@ static const struct file_operations atomic_ro_fops = {
49699
49700
49701 int oprofilefs_create_ro_atomic(struct dentry *root,
49702- char const *name, atomic_t *val)
49703+ char const *name, atomic_unchecked_t *val)
49704 {
49705 return __oprofilefs_create_file(root, name,
49706 &atomic_ro_fops, 0444, val);
49707diff --git a/drivers/oprofile/timer_int.c b/drivers/oprofile/timer_int.c
49708index bdef916..88c7dee 100644
49709--- a/drivers/oprofile/timer_int.c
49710+++ b/drivers/oprofile/timer_int.c
49711@@ -93,7 +93,7 @@ static int oprofile_cpu_notify(struct notifier_block *self,
49712 return NOTIFY_OK;
49713 }
49714
49715-static struct notifier_block __refdata oprofile_cpu_notifier = {
49716+static struct notifier_block oprofile_cpu_notifier = {
49717 .notifier_call = oprofile_cpu_notify,
49718 };
49719
49720diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
49721index 3b47080..6cd05dd 100644
49722--- a/drivers/parport/procfs.c
49723+++ b/drivers/parport/procfs.c
49724@@ -64,7 +64,7 @@ static int do_active_device(struct ctl_table *table, int write,
49725
49726 *ppos += len;
49727
49728- return copy_to_user(result, buffer, len) ? -EFAULT : 0;
49729+ return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
49730 }
49731
49732 #ifdef CONFIG_PARPORT_1284
49733@@ -106,7 +106,7 @@ static int do_autoprobe(struct ctl_table *table, int write,
49734
49735 *ppos += len;
49736
49737- return copy_to_user (result, buffer, len) ? -EFAULT : 0;
49738+ return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
49739 }
49740 #endif /* IEEE1284.3 support. */
49741
49742diff --git a/drivers/pci/hotplug/acpiphp_ibm.c b/drivers/pci/hotplug/acpiphp_ibm.c
49743index 6ca2399..68d866b 100644
49744--- a/drivers/pci/hotplug/acpiphp_ibm.c
49745+++ b/drivers/pci/hotplug/acpiphp_ibm.c
49746@@ -452,7 +452,9 @@ static int __init ibm_acpiphp_init(void)
49747 goto init_cleanup;
49748 }
49749
49750- ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
49751+ pax_open_kernel();
49752+ *(size_t *)&ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
49753+ pax_close_kernel();
49754 retval = sysfs_create_bin_file(sysdir, &ibm_apci_table_attr);
49755
49756 return retval;
49757diff --git a/drivers/pci/hotplug/cpcihp_generic.c b/drivers/pci/hotplug/cpcihp_generic.c
49758index 66b7bbe..26bee78 100644
49759--- a/drivers/pci/hotplug/cpcihp_generic.c
49760+++ b/drivers/pci/hotplug/cpcihp_generic.c
49761@@ -73,7 +73,6 @@ static u16 port;
49762 static unsigned int enum_bit;
49763 static u8 enum_mask;
49764
49765-static struct cpci_hp_controller_ops generic_hpc_ops;
49766 static struct cpci_hp_controller generic_hpc;
49767
49768 static int __init validate_parameters(void)
49769@@ -139,6 +138,10 @@ static int query_enum(void)
49770 return ((value & enum_mask) == enum_mask);
49771 }
49772
49773+static struct cpci_hp_controller_ops generic_hpc_ops = {
49774+ .query_enum = query_enum,
49775+};
49776+
49777 static int __init cpcihp_generic_init(void)
49778 {
49779 int status;
49780@@ -165,7 +168,6 @@ static int __init cpcihp_generic_init(void)
49781 pci_dev_put(dev);
49782
49783 memset(&generic_hpc, 0, sizeof (struct cpci_hp_controller));
49784- generic_hpc_ops.query_enum = query_enum;
49785 generic_hpc.ops = &generic_hpc_ops;
49786
49787 status = cpci_hp_register_controller(&generic_hpc);
49788diff --git a/drivers/pci/hotplug/cpcihp_zt5550.c b/drivers/pci/hotplug/cpcihp_zt5550.c
49789index 7ecf34e..effed62 100644
49790--- a/drivers/pci/hotplug/cpcihp_zt5550.c
49791+++ b/drivers/pci/hotplug/cpcihp_zt5550.c
49792@@ -59,7 +59,6 @@
49793 /* local variables */
49794 static bool debug;
49795 static bool poll;
49796-static struct cpci_hp_controller_ops zt5550_hpc_ops;
49797 static struct cpci_hp_controller zt5550_hpc;
49798
49799 /* Primary cPCI bus bridge device */
49800@@ -204,6 +203,10 @@ static int zt5550_hc_disable_irq(void)
49801 return 0;
49802 }
49803
49804+static struct cpci_hp_controller_ops zt5550_hpc_ops = {
49805+ .query_enum = zt5550_hc_query_enum,
49806+};
49807+
49808 static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
49809 {
49810 int status;
49811@@ -215,16 +218,17 @@ static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id
49812 dbg("returned from zt5550_hc_config");
49813
49814 memset(&zt5550_hpc, 0, sizeof (struct cpci_hp_controller));
49815- zt5550_hpc_ops.query_enum = zt5550_hc_query_enum;
49816 zt5550_hpc.ops = &zt5550_hpc_ops;
49817 if (!poll) {
49818 zt5550_hpc.irq = hc_dev->irq;
49819 zt5550_hpc.irq_flags = IRQF_SHARED;
49820 zt5550_hpc.dev_id = hc_dev;
49821
49822- zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
49823- zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
49824- zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
49825+ pax_open_kernel();
49826+ *(void **)&zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
49827+ *(void **)&zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
49828+ *(void **)&zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
49829+ pax_open_kernel();
49830 } else {
49831 info("using ENUM# polling mode");
49832 }
49833diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
49834index 1e08ff8c..3cd145f 100644
49835--- a/drivers/pci/hotplug/cpqphp_nvram.c
49836+++ b/drivers/pci/hotplug/cpqphp_nvram.c
49837@@ -425,8 +425,10 @@ static u32 store_HRT (void __iomem *rom_start)
49838
49839 void compaq_nvram_init (void __iomem *rom_start)
49840 {
49841+#ifndef CONFIG_PAX_KERNEXEC
49842 if (rom_start)
49843 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
49844+#endif
49845
49846 dbg("int15 entry = %p\n", compaq_int15_entry_point);
49847
49848diff --git a/drivers/pci/hotplug/pci_hotplug_core.c b/drivers/pci/hotplug/pci_hotplug_core.c
49849index 56d8486..f26113f 100644
49850--- a/drivers/pci/hotplug/pci_hotplug_core.c
49851+++ b/drivers/pci/hotplug/pci_hotplug_core.c
49852@@ -436,8 +436,10 @@ int __pci_hp_register(struct hotplug_slot *slot, struct pci_bus *bus,
49853 return -EINVAL;
49854 }
49855
49856- slot->ops->owner = owner;
49857- slot->ops->mod_name = mod_name;
49858+ pax_open_kernel();
49859+ *(struct module **)&slot->ops->owner = owner;
49860+ *(const char **)&slot->ops->mod_name = mod_name;
49861+ pax_close_kernel();
49862
49863 mutex_lock(&pci_hp_mutex);
49864 /*
49865diff --git a/drivers/pci/hotplug/pciehp_core.c b/drivers/pci/hotplug/pciehp_core.c
49866index 07aa722..84514b4 100644
49867--- a/drivers/pci/hotplug/pciehp_core.c
49868+++ b/drivers/pci/hotplug/pciehp_core.c
49869@@ -92,7 +92,7 @@ static int init_slot(struct controller *ctrl)
49870 struct slot *slot = ctrl->slot;
49871 struct hotplug_slot *hotplug = NULL;
49872 struct hotplug_slot_info *info = NULL;
49873- struct hotplug_slot_ops *ops = NULL;
49874+ hotplug_slot_ops_no_const *ops = NULL;
49875 char name[SLOT_NAME_SIZE];
49876 int retval = -ENOMEM;
49877
49878diff --git a/drivers/pci/msi.c b/drivers/pci/msi.c
49879index 084587d..4a8f9df 100644
49880--- a/drivers/pci/msi.c
49881+++ b/drivers/pci/msi.c
49882@@ -488,8 +488,8 @@ static int populate_msi_sysfs(struct pci_dev *pdev)
49883 {
49884 struct attribute **msi_attrs;
49885 struct attribute *msi_attr;
49886- struct device_attribute *msi_dev_attr;
49887- struct attribute_group *msi_irq_group;
49888+ device_attribute_no_const *msi_dev_attr;
49889+ attribute_group_no_const *msi_irq_group;
49890 const struct attribute_group **msi_irq_groups;
49891 struct msi_desc *entry;
49892 int ret = -ENOMEM;
49893@@ -549,7 +549,7 @@ error_attrs:
49894 count = 0;
49895 msi_attr = msi_attrs[count];
49896 while (msi_attr) {
49897- msi_dev_attr = container_of(msi_attr, struct device_attribute, attr);
49898+ msi_dev_attr = container_of(msi_attr, device_attribute_no_const, attr);
49899 kfree(msi_attr->name);
49900 kfree(msi_dev_attr);
49901 ++count;
49902diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
49903index 2c6643f..3a6d8e0 100644
49904--- a/drivers/pci/pci-sysfs.c
49905+++ b/drivers/pci/pci-sysfs.c
49906@@ -1133,7 +1133,7 @@ static int pci_create_attr(struct pci_dev *pdev, int num, int write_combine)
49907 {
49908 /* allocate attribute structure, piggyback attribute name */
49909 int name_len = write_combine ? 13 : 10;
49910- struct bin_attribute *res_attr;
49911+ bin_attribute_no_const *res_attr;
49912 int retval;
49913
49914 res_attr = kzalloc(sizeof(*res_attr) + name_len, GFP_ATOMIC);
49915@@ -1310,7 +1310,7 @@ static struct device_attribute reset_attr = __ATTR(reset, 0200, NULL, reset_stor
49916 static int pci_create_capabilities_sysfs(struct pci_dev *dev)
49917 {
49918 int retval;
49919- struct bin_attribute *attr;
49920+ bin_attribute_no_const *attr;
49921
49922 /* If the device has VPD, try to expose it in sysfs. */
49923 if (dev->vpd) {
49924@@ -1357,7 +1357,7 @@ int __must_check pci_create_sysfs_dev_files(struct pci_dev *pdev)
49925 {
49926 int retval;
49927 int rom_size = 0;
49928- struct bin_attribute *attr;
49929+ bin_attribute_no_const *attr;
49930
49931 if (!sysfs_initialized)
49932 return -EACCES;
49933diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
49934index 4a3902d..7f1fc42 100644
49935--- a/drivers/pci/pci.h
49936+++ b/drivers/pci/pci.h
49937@@ -93,7 +93,7 @@ struct pci_vpd_ops {
49938 struct pci_vpd {
49939 unsigned int len;
49940 const struct pci_vpd_ops *ops;
49941- struct bin_attribute *attr; /* descriptor for sysfs VPD entry */
49942+ bin_attribute_no_const *attr; /* descriptor for sysfs VPD entry */
49943 };
49944
49945 int pci_vpd_pci22_init(struct pci_dev *dev);
49946diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
49947index e1e7026..d28dd33 100644
49948--- a/drivers/pci/pcie/aspm.c
49949+++ b/drivers/pci/pcie/aspm.c
49950@@ -27,9 +27,9 @@
49951 #define MODULE_PARAM_PREFIX "pcie_aspm."
49952
49953 /* Note: those are not register definitions */
49954-#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
49955-#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
49956-#define ASPM_STATE_L1 (4) /* L1 state */
49957+#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
49958+#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
49959+#define ASPM_STATE_L1 (4U) /* L1 state */
49960 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
49961 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
49962
49963diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
49964index c8ca98c..b1bc005 100644
49965--- a/drivers/pci/probe.c
49966+++ b/drivers/pci/probe.c
49967@@ -177,7 +177,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
49968 struct pci_bus_region region, inverted_region;
49969 bool bar_too_big = false, bar_too_high = false, bar_invalid = false;
49970
49971- mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
49972+ mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
49973
49974 /* No printks while decoding is disabled! */
49975 if (!dev->mmio_always_on) {
49976diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
49977index 3f155e7..0f4b1f0 100644
49978--- a/drivers/pci/proc.c
49979+++ b/drivers/pci/proc.c
49980@@ -434,7 +434,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
49981 static int __init pci_proc_init(void)
49982 {
49983 struct pci_dev *dev = NULL;
49984+
49985+#ifdef CONFIG_GRKERNSEC_PROC_ADD
49986+#ifdef CONFIG_GRKERNSEC_PROC_USER
49987+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
49988+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49989+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
49990+#endif
49991+#else
49992 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
49993+#endif
49994 proc_create("devices", 0, proc_bus_pci_dir,
49995 &proc_bus_pci_dev_operations);
49996 proc_initialized = 1;
49997diff --git a/drivers/platform/chrome/chromeos_laptop.c b/drivers/platform/chrome/chromeos_laptop.c
49998index d866db8..c827d1f 100644
49999--- a/drivers/platform/chrome/chromeos_laptop.c
50000+++ b/drivers/platform/chrome/chromeos_laptop.c
50001@@ -479,7 +479,7 @@ static struct chromeos_laptop cr48 = {
50002 .callback = chromeos_laptop_dmi_matched, \
50003 .driver_data = (void *)&board_
50004
50005-static struct dmi_system_id chromeos_laptop_dmi_table[] __initdata = {
50006+static struct dmi_system_id chromeos_laptop_dmi_table[] __initconst = {
50007 {
50008 .ident = "Samsung Series 5 550",
50009 .matches = {
50010diff --git a/drivers/platform/x86/alienware-wmi.c b/drivers/platform/x86/alienware-wmi.c
50011index c5af23b..3d62d5e 100644
50012--- a/drivers/platform/x86/alienware-wmi.c
50013+++ b/drivers/platform/x86/alienware-wmi.c
50014@@ -150,7 +150,7 @@ struct wmax_led_args {
50015 } __packed;
50016
50017 static struct platform_device *platform_device;
50018-static struct device_attribute *zone_dev_attrs;
50019+static device_attribute_no_const *zone_dev_attrs;
50020 static struct attribute **zone_attrs;
50021 static struct platform_zone *zone_data;
50022
50023@@ -161,7 +161,7 @@ static struct platform_driver platform_driver = {
50024 }
50025 };
50026
50027-static struct attribute_group zone_attribute_group = {
50028+static attribute_group_no_const zone_attribute_group = {
50029 .name = "rgb_zones",
50030 };
50031
50032diff --git a/drivers/platform/x86/asus-wmi.c b/drivers/platform/x86/asus-wmi.c
50033index 21fc932..ee9394a 100644
50034--- a/drivers/platform/x86/asus-wmi.c
50035+++ b/drivers/platform/x86/asus-wmi.c
50036@@ -1590,6 +1590,10 @@ static int show_dsts(struct seq_file *m, void *data)
50037 int err;
50038 u32 retval = -1;
50039
50040+#ifdef CONFIG_GRKERNSEC_KMEM
50041+ return -EPERM;
50042+#endif
50043+
50044 err = asus_wmi_get_devstate(asus, asus->debug.dev_id, &retval);
50045
50046 if (err < 0)
50047@@ -1606,6 +1610,10 @@ static int show_devs(struct seq_file *m, void *data)
50048 int err;
50049 u32 retval = -1;
50050
50051+#ifdef CONFIG_GRKERNSEC_KMEM
50052+ return -EPERM;
50053+#endif
50054+
50055 err = asus_wmi_set_devstate(asus->debug.dev_id, asus->debug.ctrl_param,
50056 &retval);
50057
50058@@ -1630,6 +1638,10 @@ static int show_call(struct seq_file *m, void *data)
50059 union acpi_object *obj;
50060 acpi_status status;
50061
50062+#ifdef CONFIG_GRKERNSEC_KMEM
50063+ return -EPERM;
50064+#endif
50065+
50066 status = wmi_evaluate_method(ASUS_WMI_MGMT_GUID,
50067 1, asus->debug.method_id,
50068 &input, &output);
50069diff --git a/drivers/platform/x86/msi-laptop.c b/drivers/platform/x86/msi-laptop.c
50070index 62f8030..c7f2a45 100644
50071--- a/drivers/platform/x86/msi-laptop.c
50072+++ b/drivers/platform/x86/msi-laptop.c
50073@@ -1000,12 +1000,14 @@ static int __init load_scm_model_init(struct platform_device *sdev)
50074
50075 if (!quirks->ec_read_only) {
50076 /* allow userland write sysfs file */
50077- dev_attr_bluetooth.store = store_bluetooth;
50078- dev_attr_wlan.store = store_wlan;
50079- dev_attr_threeg.store = store_threeg;
50080- dev_attr_bluetooth.attr.mode |= S_IWUSR;
50081- dev_attr_wlan.attr.mode |= S_IWUSR;
50082- dev_attr_threeg.attr.mode |= S_IWUSR;
50083+ pax_open_kernel();
50084+ *(void **)&dev_attr_bluetooth.store = store_bluetooth;
50085+ *(void **)&dev_attr_wlan.store = store_wlan;
50086+ *(void **)&dev_attr_threeg.store = store_threeg;
50087+ *(umode_t *)&dev_attr_bluetooth.attr.mode |= S_IWUSR;
50088+ *(umode_t *)&dev_attr_wlan.attr.mode |= S_IWUSR;
50089+ *(umode_t *)&dev_attr_threeg.attr.mode |= S_IWUSR;
50090+ pax_close_kernel();
50091 }
50092
50093 /* disable hardware control by fn key */
50094diff --git a/drivers/platform/x86/msi-wmi.c b/drivers/platform/x86/msi-wmi.c
50095index 70222f2..8c8ce66 100644
50096--- a/drivers/platform/x86/msi-wmi.c
50097+++ b/drivers/platform/x86/msi-wmi.c
50098@@ -183,7 +183,7 @@ static const struct backlight_ops msi_backlight_ops = {
50099 static void msi_wmi_notify(u32 value, void *context)
50100 {
50101 struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL };
50102- static struct key_entry *key;
50103+ struct key_entry *key;
50104 union acpi_object *obj;
50105 acpi_status status;
50106
50107diff --git a/drivers/platform/x86/sony-laptop.c b/drivers/platform/x86/sony-laptop.c
50108index 26ad9ff..7c52909 100644
50109--- a/drivers/platform/x86/sony-laptop.c
50110+++ b/drivers/platform/x86/sony-laptop.c
50111@@ -2527,7 +2527,7 @@ static void sony_nc_gfx_switch_cleanup(struct platform_device *pd)
50112 }
50113
50114 /* High speed charging function */
50115-static struct device_attribute *hsc_handle;
50116+static device_attribute_no_const *hsc_handle;
50117
50118 static ssize_t sony_nc_highspeed_charging_store(struct device *dev,
50119 struct device_attribute *attr,
50120@@ -2601,7 +2601,7 @@ static void sony_nc_highspeed_charging_cleanup(struct platform_device *pd)
50121 }
50122
50123 /* low battery function */
50124-static struct device_attribute *lowbatt_handle;
50125+static device_attribute_no_const *lowbatt_handle;
50126
50127 static ssize_t sony_nc_lowbatt_store(struct device *dev,
50128 struct device_attribute *attr,
50129@@ -2667,7 +2667,7 @@ static void sony_nc_lowbatt_cleanup(struct platform_device *pd)
50130 }
50131
50132 /* fan speed function */
50133-static struct device_attribute *fan_handle, *hsf_handle;
50134+static device_attribute_no_const *fan_handle, *hsf_handle;
50135
50136 static ssize_t sony_nc_hsfan_store(struct device *dev,
50137 struct device_attribute *attr,
50138@@ -2774,7 +2774,7 @@ static void sony_nc_fanspeed_cleanup(struct platform_device *pd)
50139 }
50140
50141 /* USB charge function */
50142-static struct device_attribute *uc_handle;
50143+static device_attribute_no_const *uc_handle;
50144
50145 static ssize_t sony_nc_usb_charge_store(struct device *dev,
50146 struct device_attribute *attr,
50147@@ -2848,7 +2848,7 @@ static void sony_nc_usb_charge_cleanup(struct platform_device *pd)
50148 }
50149
50150 /* Panel ID function */
50151-static struct device_attribute *panel_handle;
50152+static device_attribute_no_const *panel_handle;
50153
50154 static ssize_t sony_nc_panelid_show(struct device *dev,
50155 struct device_attribute *attr, char *buffer)
50156@@ -2895,7 +2895,7 @@ static void sony_nc_panelid_cleanup(struct platform_device *pd)
50157 }
50158
50159 /* smart connect function */
50160-static struct device_attribute *sc_handle;
50161+static device_attribute_no_const *sc_handle;
50162
50163 static ssize_t sony_nc_smart_conn_store(struct device *dev,
50164 struct device_attribute *attr,
50165diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
50166index cf0f893..5955997 100644
50167--- a/drivers/platform/x86/thinkpad_acpi.c
50168+++ b/drivers/platform/x86/thinkpad_acpi.c
50169@@ -2094,7 +2094,7 @@ static int hotkey_mask_get(void)
50170 return 0;
50171 }
50172
50173-void static hotkey_mask_warn_incomplete_mask(void)
50174+static void hotkey_mask_warn_incomplete_mask(void)
50175 {
50176 /* log only what the user can fix... */
50177 const u32 wantedmask = hotkey_driver_mask &
50178@@ -2438,10 +2438,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
50179 && !tp_features.bright_unkfw)
50180 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
50181 }
50182+}
50183
50184 #undef TPACPI_COMPARE_KEY
50185 #undef TPACPI_MAY_SEND_KEY
50186-}
50187
50188 /*
50189 * Polling driver
50190diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
50191index 438d4c7..ca8a2fb 100644
50192--- a/drivers/pnp/pnpbios/bioscalls.c
50193+++ b/drivers/pnp/pnpbios/bioscalls.c
50194@@ -59,7 +59,7 @@ do { \
50195 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
50196 } while(0)
50197
50198-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
50199+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
50200 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
50201
50202 /*
50203@@ -96,7 +96,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
50204
50205 cpu = get_cpu();
50206 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
50207+
50208+ pax_open_kernel();
50209 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
50210+ pax_close_kernel();
50211
50212 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
50213 spin_lock_irqsave(&pnp_bios_lock, flags);
50214@@ -134,7 +137,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
50215 :"memory");
50216 spin_unlock_irqrestore(&pnp_bios_lock, flags);
50217
50218+ pax_open_kernel();
50219 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
50220+ pax_close_kernel();
50221+
50222 put_cpu();
50223
50224 /* If we get here and this is set then the PnP BIOS faulted on us. */
50225@@ -468,7 +474,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
50226 return status;
50227 }
50228
50229-void pnpbios_calls_init(union pnp_bios_install_struct *header)
50230+void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
50231 {
50232 int i;
50233
50234@@ -476,6 +482,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
50235 pnp_bios_callpoint.offset = header->fields.pm16offset;
50236 pnp_bios_callpoint.segment = PNP_CS16;
50237
50238+ pax_open_kernel();
50239+
50240 for_each_possible_cpu(i) {
50241 struct desc_struct *gdt = get_cpu_gdt_table(i);
50242 if (!gdt)
50243@@ -487,4 +495,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
50244 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
50245 (unsigned long)__va(header->fields.pm16dseg));
50246 }
50247+
50248+ pax_close_kernel();
50249 }
50250diff --git a/drivers/power/pda_power.c b/drivers/power/pda_power.c
50251index 0c52e2a..3421ab7 100644
50252--- a/drivers/power/pda_power.c
50253+++ b/drivers/power/pda_power.c
50254@@ -37,7 +37,11 @@ static int polling;
50255
50256 #if IS_ENABLED(CONFIG_USB_PHY)
50257 static struct usb_phy *transceiver;
50258-static struct notifier_block otg_nb;
50259+static int otg_handle_notification(struct notifier_block *nb,
50260+ unsigned long event, void *unused);
50261+static struct notifier_block otg_nb = {
50262+ .notifier_call = otg_handle_notification
50263+};
50264 #endif
50265
50266 static struct regulator *ac_draw;
50267@@ -369,7 +373,6 @@ static int pda_power_probe(struct platform_device *pdev)
50268
50269 #if IS_ENABLED(CONFIG_USB_PHY)
50270 if (!IS_ERR_OR_NULL(transceiver) && pdata->use_otg_notifier) {
50271- otg_nb.notifier_call = otg_handle_notification;
50272 ret = usb_register_notifier(transceiver, &otg_nb);
50273 if (ret) {
50274 dev_err(dev, "failure to register otg notifier\n");
50275diff --git a/drivers/power/power_supply.h b/drivers/power/power_supply.h
50276index cc439fd..8fa30df 100644
50277--- a/drivers/power/power_supply.h
50278+++ b/drivers/power/power_supply.h
50279@@ -16,12 +16,12 @@ struct power_supply;
50280
50281 #ifdef CONFIG_SYSFS
50282
50283-extern void power_supply_init_attrs(struct device_type *dev_type);
50284+extern void power_supply_init_attrs(void);
50285 extern int power_supply_uevent(struct device *dev, struct kobj_uevent_env *env);
50286
50287 #else
50288
50289-static inline void power_supply_init_attrs(struct device_type *dev_type) {}
50290+static inline void power_supply_init_attrs(void) {}
50291 #define power_supply_uevent NULL
50292
50293 #endif /* CONFIG_SYSFS */
50294diff --git a/drivers/power/power_supply_core.c b/drivers/power/power_supply_core.c
50295index 694e8cd..9f03483 100644
50296--- a/drivers/power/power_supply_core.c
50297+++ b/drivers/power/power_supply_core.c
50298@@ -28,7 +28,10 @@ EXPORT_SYMBOL_GPL(power_supply_class);
50299 ATOMIC_NOTIFIER_HEAD(power_supply_notifier);
50300 EXPORT_SYMBOL_GPL(power_supply_notifier);
50301
50302-static struct device_type power_supply_dev_type;
50303+extern const struct attribute_group *power_supply_attr_groups[];
50304+static struct device_type power_supply_dev_type = {
50305+ .groups = power_supply_attr_groups,
50306+};
50307
50308 static bool __power_supply_is_supplied_by(struct power_supply *supplier,
50309 struct power_supply *supply)
50310@@ -637,7 +640,7 @@ static int __init power_supply_class_init(void)
50311 return PTR_ERR(power_supply_class);
50312
50313 power_supply_class->dev_uevent = power_supply_uevent;
50314- power_supply_init_attrs(&power_supply_dev_type);
50315+ power_supply_init_attrs();
50316
50317 return 0;
50318 }
50319diff --git a/drivers/power/power_supply_sysfs.c b/drivers/power/power_supply_sysfs.c
50320index 62653f5..d0bb485 100644
50321--- a/drivers/power/power_supply_sysfs.c
50322+++ b/drivers/power/power_supply_sysfs.c
50323@@ -238,17 +238,15 @@ static struct attribute_group power_supply_attr_group = {
50324 .is_visible = power_supply_attr_is_visible,
50325 };
50326
50327-static const struct attribute_group *power_supply_attr_groups[] = {
50328+const struct attribute_group *power_supply_attr_groups[] = {
50329 &power_supply_attr_group,
50330 NULL,
50331 };
50332
50333-void power_supply_init_attrs(struct device_type *dev_type)
50334+void power_supply_init_attrs(void)
50335 {
50336 int i;
50337
50338- dev_type->groups = power_supply_attr_groups;
50339-
50340 for (i = 0; i < ARRAY_SIZE(power_supply_attrs); i++)
50341 __power_supply_attrs[i] = &power_supply_attrs[i].attr;
50342 }
50343diff --git a/drivers/powercap/powercap_sys.c b/drivers/powercap/powercap_sys.c
50344index 84419af..268ede8 100644
50345--- a/drivers/powercap/powercap_sys.c
50346+++ b/drivers/powercap/powercap_sys.c
50347@@ -154,8 +154,77 @@ struct powercap_constraint_attr {
50348 struct device_attribute name_attr;
50349 };
50350
50351+static ssize_t show_constraint_name(struct device *dev,
50352+ struct device_attribute *dev_attr,
50353+ char *buf);
50354+
50355 static struct powercap_constraint_attr
50356- constraint_attrs[MAX_CONSTRAINTS_PER_ZONE];
50357+ constraint_attrs[MAX_CONSTRAINTS_PER_ZONE] = {
50358+ [0 ... MAX_CONSTRAINTS_PER_ZONE - 1] = {
50359+ .power_limit_attr = {
50360+ .attr = {
50361+ .name = NULL,
50362+ .mode = S_IWUSR | S_IRUGO
50363+ },
50364+ .show = show_constraint_power_limit_uw,
50365+ .store = store_constraint_power_limit_uw
50366+ },
50367+
50368+ .time_window_attr = {
50369+ .attr = {
50370+ .name = NULL,
50371+ .mode = S_IWUSR | S_IRUGO
50372+ },
50373+ .show = show_constraint_time_window_us,
50374+ .store = store_constraint_time_window_us
50375+ },
50376+
50377+ .max_power_attr = {
50378+ .attr = {
50379+ .name = NULL,
50380+ .mode = S_IRUGO
50381+ },
50382+ .show = show_constraint_max_power_uw,
50383+ .store = NULL
50384+ },
50385+
50386+ .min_power_attr = {
50387+ .attr = {
50388+ .name = NULL,
50389+ .mode = S_IRUGO
50390+ },
50391+ .show = show_constraint_min_power_uw,
50392+ .store = NULL
50393+ },
50394+
50395+ .max_time_window_attr = {
50396+ .attr = {
50397+ .name = NULL,
50398+ .mode = S_IRUGO
50399+ },
50400+ .show = show_constraint_max_time_window_us,
50401+ .store = NULL
50402+ },
50403+
50404+ .min_time_window_attr = {
50405+ .attr = {
50406+ .name = NULL,
50407+ .mode = S_IRUGO
50408+ },
50409+ .show = show_constraint_min_time_window_us,
50410+ .store = NULL
50411+ },
50412+
50413+ .name_attr = {
50414+ .attr = {
50415+ .name = NULL,
50416+ .mode = S_IRUGO
50417+ },
50418+ .show = show_constraint_name,
50419+ .store = NULL
50420+ }
50421+ }
50422+};
50423
50424 /* A list of powercap control_types */
50425 static LIST_HEAD(powercap_cntrl_list);
50426@@ -193,23 +262,16 @@ static ssize_t show_constraint_name(struct device *dev,
50427 }
50428
50429 static int create_constraint_attribute(int id, const char *name,
50430- int mode,
50431- struct device_attribute *dev_attr,
50432- ssize_t (*show)(struct device *,
50433- struct device_attribute *, char *),
50434- ssize_t (*store)(struct device *,
50435- struct device_attribute *,
50436- const char *, size_t)
50437- )
50438+ struct device_attribute *dev_attr)
50439 {
50440+ name = kasprintf(GFP_KERNEL, "constraint_%d_%s", id, name);
50441
50442- dev_attr->attr.name = kasprintf(GFP_KERNEL, "constraint_%d_%s",
50443- id, name);
50444- if (!dev_attr->attr.name)
50445+ if (!name)
50446 return -ENOMEM;
50447- dev_attr->attr.mode = mode;
50448- dev_attr->show = show;
50449- dev_attr->store = store;
50450+
50451+ pax_open_kernel();
50452+ *(const char **)&dev_attr->attr.name = name;
50453+ pax_close_kernel();
50454
50455 return 0;
50456 }
50457@@ -236,49 +298,31 @@ static int seed_constraint_attributes(void)
50458
50459 for (i = 0; i < MAX_CONSTRAINTS_PER_ZONE; ++i) {
50460 ret = create_constraint_attribute(i, "power_limit_uw",
50461- S_IWUSR | S_IRUGO,
50462- &constraint_attrs[i].power_limit_attr,
50463- show_constraint_power_limit_uw,
50464- store_constraint_power_limit_uw);
50465+ &constraint_attrs[i].power_limit_attr);
50466 if (ret)
50467 goto err_alloc;
50468 ret = create_constraint_attribute(i, "time_window_us",
50469- S_IWUSR | S_IRUGO,
50470- &constraint_attrs[i].time_window_attr,
50471- show_constraint_time_window_us,
50472- store_constraint_time_window_us);
50473+ &constraint_attrs[i].time_window_attr);
50474 if (ret)
50475 goto err_alloc;
50476- ret = create_constraint_attribute(i, "name", S_IRUGO,
50477- &constraint_attrs[i].name_attr,
50478- show_constraint_name,
50479- NULL);
50480+ ret = create_constraint_attribute(i, "name",
50481+ &constraint_attrs[i].name_attr);
50482 if (ret)
50483 goto err_alloc;
50484- ret = create_constraint_attribute(i, "max_power_uw", S_IRUGO,
50485- &constraint_attrs[i].max_power_attr,
50486- show_constraint_max_power_uw,
50487- NULL);
50488+ ret = create_constraint_attribute(i, "max_power_uw",
50489+ &constraint_attrs[i].max_power_attr);
50490 if (ret)
50491 goto err_alloc;
50492- ret = create_constraint_attribute(i, "min_power_uw", S_IRUGO,
50493- &constraint_attrs[i].min_power_attr,
50494- show_constraint_min_power_uw,
50495- NULL);
50496+ ret = create_constraint_attribute(i, "min_power_uw",
50497+ &constraint_attrs[i].min_power_attr);
50498 if (ret)
50499 goto err_alloc;
50500 ret = create_constraint_attribute(i, "max_time_window_us",
50501- S_IRUGO,
50502- &constraint_attrs[i].max_time_window_attr,
50503- show_constraint_max_time_window_us,
50504- NULL);
50505+ &constraint_attrs[i].max_time_window_attr);
50506 if (ret)
50507 goto err_alloc;
50508 ret = create_constraint_attribute(i, "min_time_window_us",
50509- S_IRUGO,
50510- &constraint_attrs[i].min_time_window_attr,
50511- show_constraint_min_time_window_us,
50512- NULL);
50513+ &constraint_attrs[i].min_time_window_attr);
50514 if (ret)
50515 goto err_alloc;
50516
50517@@ -378,10 +422,12 @@ static void create_power_zone_common_attributes(
50518 power_zone->zone_dev_attrs[count++] =
50519 &dev_attr_max_energy_range_uj.attr;
50520 if (power_zone->ops->get_energy_uj) {
50521+ pax_open_kernel();
50522 if (power_zone->ops->reset_energy_uj)
50523- dev_attr_energy_uj.attr.mode = S_IWUSR | S_IRUGO;
50524+ *(umode_t *)&dev_attr_energy_uj.attr.mode = S_IWUSR | S_IRUGO;
50525 else
50526- dev_attr_energy_uj.attr.mode = S_IRUGO;
50527+ *(umode_t *)&dev_attr_energy_uj.attr.mode = S_IRUGO;
50528+ pax_close_kernel();
50529 power_zone->zone_dev_attrs[count++] =
50530 &dev_attr_energy_uj.attr;
50531 }
50532diff --git a/drivers/ptp/ptp_private.h b/drivers/ptp/ptp_private.h
50533index 9c5d414..c7900ce 100644
50534--- a/drivers/ptp/ptp_private.h
50535+++ b/drivers/ptp/ptp_private.h
50536@@ -51,7 +51,7 @@ struct ptp_clock {
50537 struct mutex pincfg_mux; /* protect concurrent info->pin_config access */
50538 wait_queue_head_t tsev_wq;
50539 int defunct; /* tells readers to go away when clock is being removed */
50540- struct device_attribute *pin_dev_attr;
50541+ device_attribute_no_const *pin_dev_attr;
50542 struct attribute **pin_attr;
50543 struct attribute_group pin_attr_group;
50544 };
50545diff --git a/drivers/ptp/ptp_sysfs.c b/drivers/ptp/ptp_sysfs.c
50546index 302e626..12579af 100644
50547--- a/drivers/ptp/ptp_sysfs.c
50548+++ b/drivers/ptp/ptp_sysfs.c
50549@@ -280,7 +280,7 @@ static int ptp_populate_pins(struct ptp_clock *ptp)
50550 goto no_pin_attr;
50551
50552 for (i = 0; i < n_pins; i++) {
50553- struct device_attribute *da = &ptp->pin_dev_attr[i];
50554+ device_attribute_no_const *da = &ptp->pin_dev_attr[i];
50555 sysfs_attr_init(&da->attr);
50556 da->attr.name = info->pin_config[i].name;
50557 da->attr.mode = 0644;
50558diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
50559index cd87c0c..715ecbe 100644
50560--- a/drivers/regulator/core.c
50561+++ b/drivers/regulator/core.c
50562@@ -3567,7 +3567,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
50563 {
50564 const struct regulation_constraints *constraints = NULL;
50565 const struct regulator_init_data *init_data;
50566- static atomic_t regulator_no = ATOMIC_INIT(0);
50567+ static atomic_unchecked_t regulator_no = ATOMIC_INIT(0);
50568 struct regulator_dev *rdev;
50569 struct device *dev;
50570 int ret, i;
50571@@ -3641,7 +3641,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
50572 rdev->dev.class = &regulator_class;
50573 rdev->dev.parent = dev;
50574 dev_set_name(&rdev->dev, "regulator.%d",
50575- atomic_inc_return(&regulator_no) - 1);
50576+ atomic_inc_return_unchecked(&regulator_no) - 1);
50577 ret = device_register(&rdev->dev);
50578 if (ret != 0) {
50579 put_device(&rdev->dev);
50580diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
50581index 7eee2ca..4024513 100644
50582--- a/drivers/regulator/max8660.c
50583+++ b/drivers/regulator/max8660.c
50584@@ -424,8 +424,10 @@ static int max8660_probe(struct i2c_client *client,
50585 max8660->shadow_regs[MAX8660_OVER1] = 5;
50586 } else {
50587 /* Otherwise devices can be toggled via software */
50588- max8660_dcdc_ops.enable = max8660_dcdc_enable;
50589- max8660_dcdc_ops.disable = max8660_dcdc_disable;
50590+ pax_open_kernel();
50591+ *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
50592+ *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
50593+ pax_close_kernel();
50594 }
50595
50596 /*
50597diff --git a/drivers/regulator/max8973-regulator.c b/drivers/regulator/max8973-regulator.c
50598index dbedf17..18ff6b7 100644
50599--- a/drivers/regulator/max8973-regulator.c
50600+++ b/drivers/regulator/max8973-regulator.c
50601@@ -403,9 +403,11 @@ static int max8973_probe(struct i2c_client *client,
50602 if (!pdata || !pdata->enable_ext_control) {
50603 max->desc.enable_reg = MAX8973_VOUT;
50604 max->desc.enable_mask = MAX8973_VOUT_ENABLE;
50605- max->ops.enable = regulator_enable_regmap;
50606- max->ops.disable = regulator_disable_regmap;
50607- max->ops.is_enabled = regulator_is_enabled_regmap;
50608+ pax_open_kernel();
50609+ *(void **)&max->ops.enable = regulator_enable_regmap;
50610+ *(void **)&max->ops.disable = regulator_disable_regmap;
50611+ *(void **)&max->ops.is_enabled = regulator_is_enabled_regmap;
50612+ pax_close_kernel();
50613 }
50614
50615 if (pdata) {
50616diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
50617index 793b662..85f74cd 100644
50618--- a/drivers/regulator/mc13892-regulator.c
50619+++ b/drivers/regulator/mc13892-regulator.c
50620@@ -584,10 +584,12 @@ static int mc13892_regulator_probe(struct platform_device *pdev)
50621 mc13xxx_unlock(mc13892);
50622
50623 /* update mc13892_vcam ops */
50624+ pax_open_kernel();
50625 memcpy(&mc13892_vcam_ops, mc13892_regulators[MC13892_VCAM].desc.ops,
50626 sizeof(struct regulator_ops));
50627- mc13892_vcam_ops.set_mode = mc13892_vcam_set_mode,
50628- mc13892_vcam_ops.get_mode = mc13892_vcam_get_mode,
50629+ *(void **)&mc13892_vcam_ops.set_mode = mc13892_vcam_set_mode,
50630+ *(void **)&mc13892_vcam_ops.get_mode = mc13892_vcam_get_mode,
50631+ pax_close_kernel();
50632 mc13892_regulators[MC13892_VCAM].desc.ops = &mc13892_vcam_ops;
50633
50634 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
50635diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c
50636index 5b2e761..c8c8a4a 100644
50637--- a/drivers/rtc/rtc-cmos.c
50638+++ b/drivers/rtc/rtc-cmos.c
50639@@ -789,7 +789,9 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq)
50640 hpet_rtc_timer_init();
50641
50642 /* export at least the first block of NVRAM */
50643- nvram.size = address_space - NVRAM_OFFSET;
50644+ pax_open_kernel();
50645+ *(size_t *)&nvram.size = address_space - NVRAM_OFFSET;
50646+ pax_close_kernel();
50647 retval = sysfs_create_bin_file(&dev->kobj, &nvram);
50648 if (retval < 0) {
50649 dev_dbg(dev, "can't create nvram file? %d\n", retval);
50650diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
50651index d049393..bb20be0 100644
50652--- a/drivers/rtc/rtc-dev.c
50653+++ b/drivers/rtc/rtc-dev.c
50654@@ -16,6 +16,7 @@
50655 #include <linux/module.h>
50656 #include <linux/rtc.h>
50657 #include <linux/sched.h>
50658+#include <linux/grsecurity.h>
50659 #include "rtc-core.h"
50660
50661 static dev_t rtc_devt;
50662@@ -347,6 +348,8 @@ static long rtc_dev_ioctl(struct file *file,
50663 if (copy_from_user(&tm, uarg, sizeof(tm)))
50664 return -EFAULT;
50665
50666+ gr_log_timechange();
50667+
50668 return rtc_set_time(rtc, &tm);
50669
50670 case RTC_PIE_ON:
50671diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c
50672index bb43cf7..ee4d274 100644
50673--- a/drivers/rtc/rtc-ds1307.c
50674+++ b/drivers/rtc/rtc-ds1307.c
50675@@ -107,7 +107,7 @@ struct ds1307 {
50676 u8 offset; /* register's offset */
50677 u8 regs[11];
50678 u16 nvram_offset;
50679- struct bin_attribute *nvram;
50680+ bin_attribute_no_const *nvram;
50681 enum ds_type type;
50682 unsigned long flags;
50683 #define HAS_NVRAM 0 /* bit 0 == sysfs file active */
50684diff --git a/drivers/rtc/rtc-m48t59.c b/drivers/rtc/rtc-m48t59.c
50685index 11880c1..b823aa4 100644
50686--- a/drivers/rtc/rtc-m48t59.c
50687+++ b/drivers/rtc/rtc-m48t59.c
50688@@ -483,7 +483,9 @@ static int m48t59_rtc_probe(struct platform_device *pdev)
50689 if (IS_ERR(m48t59->rtc))
50690 return PTR_ERR(m48t59->rtc);
50691
50692- m48t59_nvram_attr.size = pdata->offset;
50693+ pax_open_kernel();
50694+ *(size_t *)&m48t59_nvram_attr.size = pdata->offset;
50695+ pax_close_kernel();
50696
50697 ret = sysfs_create_bin_file(&pdev->dev.kobj, &m48t59_nvram_attr);
50698 if (ret)
50699diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
50700index e693af6..2e525b6 100644
50701--- a/drivers/scsi/bfa/bfa_fcpim.h
50702+++ b/drivers/scsi/bfa/bfa_fcpim.h
50703@@ -36,7 +36,7 @@ struct bfa_iotag_s {
50704
50705 struct bfa_itn_s {
50706 bfa_isr_func_t isr;
50707-};
50708+} __no_const;
50709
50710 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
50711 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
50712diff --git a/drivers/scsi/bfa/bfa_fcs.c b/drivers/scsi/bfa/bfa_fcs.c
50713index 0f19455..ef7adb5 100644
50714--- a/drivers/scsi/bfa/bfa_fcs.c
50715+++ b/drivers/scsi/bfa/bfa_fcs.c
50716@@ -38,10 +38,21 @@ struct bfa_fcs_mod_s {
50717 #define BFA_FCS_MODULE(_mod) { _mod ## _modinit, _mod ## _modexit }
50718
50719 static struct bfa_fcs_mod_s fcs_modules[] = {
50720- { bfa_fcs_port_attach, NULL, NULL },
50721- { bfa_fcs_uf_attach, NULL, NULL },
50722- { bfa_fcs_fabric_attach, bfa_fcs_fabric_modinit,
50723- bfa_fcs_fabric_modexit },
50724+ {
50725+ .attach = bfa_fcs_port_attach,
50726+ .modinit = NULL,
50727+ .modexit = NULL
50728+ },
50729+ {
50730+ .attach = bfa_fcs_uf_attach,
50731+ .modinit = NULL,
50732+ .modexit = NULL
50733+ },
50734+ {
50735+ .attach = bfa_fcs_fabric_attach,
50736+ .modinit = bfa_fcs_fabric_modinit,
50737+ .modexit = bfa_fcs_fabric_modexit
50738+ },
50739 };
50740
50741 /*
50742diff --git a/drivers/scsi/bfa/bfa_fcs_lport.c b/drivers/scsi/bfa/bfa_fcs_lport.c
50743index ff75ef8..2dfe00a 100644
50744--- a/drivers/scsi/bfa/bfa_fcs_lport.c
50745+++ b/drivers/scsi/bfa/bfa_fcs_lport.c
50746@@ -89,15 +89,26 @@ static struct {
50747 void (*offline) (struct bfa_fcs_lport_s *port);
50748 } __port_action[] = {
50749 {
50750- bfa_fcs_lport_unknown_init, bfa_fcs_lport_unknown_online,
50751- bfa_fcs_lport_unknown_offline}, {
50752- bfa_fcs_lport_fab_init, bfa_fcs_lport_fab_online,
50753- bfa_fcs_lport_fab_offline}, {
50754- bfa_fcs_lport_n2n_init, bfa_fcs_lport_n2n_online,
50755- bfa_fcs_lport_n2n_offline}, {
50756- bfa_fcs_lport_loop_init, bfa_fcs_lport_loop_online,
50757- bfa_fcs_lport_loop_offline},
50758- };
50759+ .init = bfa_fcs_lport_unknown_init,
50760+ .online = bfa_fcs_lport_unknown_online,
50761+ .offline = bfa_fcs_lport_unknown_offline
50762+ },
50763+ {
50764+ .init = bfa_fcs_lport_fab_init,
50765+ .online = bfa_fcs_lport_fab_online,
50766+ .offline = bfa_fcs_lport_fab_offline
50767+ },
50768+ {
50769+ .init = bfa_fcs_lport_n2n_init,
50770+ .online = bfa_fcs_lport_n2n_online,
50771+ .offline = bfa_fcs_lport_n2n_offline
50772+ },
50773+ {
50774+ .init = bfa_fcs_lport_loop_init,
50775+ .online = bfa_fcs_lport_loop_online,
50776+ .offline = bfa_fcs_lport_loop_offline
50777+ },
50778+};
50779
50780 /*
50781 * fcs_port_sm FCS logical port state machine
50782diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
50783index a38aafa0..fe8f03b 100644
50784--- a/drivers/scsi/bfa/bfa_ioc.h
50785+++ b/drivers/scsi/bfa/bfa_ioc.h
50786@@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
50787 bfa_ioc_disable_cbfn_t disable_cbfn;
50788 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
50789 bfa_ioc_reset_cbfn_t reset_cbfn;
50790-};
50791+} __no_const;
50792
50793 /*
50794 * IOC event notification mechanism.
50795@@ -352,7 +352,7 @@ struct bfa_ioc_hwif_s {
50796 void (*ioc_set_alt_fwstate) (struct bfa_ioc_s *ioc,
50797 enum bfi_ioc_state fwstate);
50798 enum bfi_ioc_state (*ioc_get_alt_fwstate) (struct bfa_ioc_s *ioc);
50799-};
50800+} __no_const;
50801
50802 /*
50803 * Queue element to wait for room in request queue. FIFO order is
50804diff --git a/drivers/scsi/bfa/bfa_modules.h b/drivers/scsi/bfa/bfa_modules.h
50805index a14c784..6de6790 100644
50806--- a/drivers/scsi/bfa/bfa_modules.h
50807+++ b/drivers/scsi/bfa/bfa_modules.h
50808@@ -78,12 +78,12 @@ enum {
50809 \
50810 extern struct bfa_module_s hal_mod_ ## __mod; \
50811 struct bfa_module_s hal_mod_ ## __mod = { \
50812- bfa_ ## __mod ## _meminfo, \
50813- bfa_ ## __mod ## _attach, \
50814- bfa_ ## __mod ## _detach, \
50815- bfa_ ## __mod ## _start, \
50816- bfa_ ## __mod ## _stop, \
50817- bfa_ ## __mod ## _iocdisable, \
50818+ .meminfo = bfa_ ## __mod ## _meminfo, \
50819+ .attach = bfa_ ## __mod ## _attach, \
50820+ .detach = bfa_ ## __mod ## _detach, \
50821+ .start = bfa_ ## __mod ## _start, \
50822+ .stop = bfa_ ## __mod ## _stop, \
50823+ .iocdisable = bfa_ ## __mod ## _iocdisable, \
50824 }
50825
50826 #define BFA_CACHELINE_SZ (256)
50827diff --git a/drivers/scsi/fcoe/fcoe_sysfs.c b/drivers/scsi/fcoe/fcoe_sysfs.c
50828index 045c4e1..13de803 100644
50829--- a/drivers/scsi/fcoe/fcoe_sysfs.c
50830+++ b/drivers/scsi/fcoe/fcoe_sysfs.c
50831@@ -33,8 +33,8 @@
50832 */
50833 #include "libfcoe.h"
50834
50835-static atomic_t ctlr_num;
50836-static atomic_t fcf_num;
50837+static atomic_unchecked_t ctlr_num;
50838+static atomic_unchecked_t fcf_num;
50839
50840 /*
50841 * fcoe_fcf_dev_loss_tmo: the default number of seconds that fcoe sysfs
50842@@ -685,7 +685,7 @@ struct fcoe_ctlr_device *fcoe_ctlr_device_add(struct device *parent,
50843 if (!ctlr)
50844 goto out;
50845
50846- ctlr->id = atomic_inc_return(&ctlr_num) - 1;
50847+ ctlr->id = atomic_inc_return_unchecked(&ctlr_num) - 1;
50848 ctlr->f = f;
50849 ctlr->mode = FIP_CONN_TYPE_FABRIC;
50850 INIT_LIST_HEAD(&ctlr->fcfs);
50851@@ -902,7 +902,7 @@ struct fcoe_fcf_device *fcoe_fcf_device_add(struct fcoe_ctlr_device *ctlr,
50852 fcf->dev.parent = &ctlr->dev;
50853 fcf->dev.bus = &fcoe_bus_type;
50854 fcf->dev.type = &fcoe_fcf_device_type;
50855- fcf->id = atomic_inc_return(&fcf_num) - 1;
50856+ fcf->id = atomic_inc_return_unchecked(&fcf_num) - 1;
50857 fcf->state = FCOE_FCF_STATE_UNKNOWN;
50858
50859 fcf->dev_loss_tmo = ctlr->fcf_dev_loss_tmo;
50860@@ -938,8 +938,8 @@ int __init fcoe_sysfs_setup(void)
50861 {
50862 int error;
50863
50864- atomic_set(&ctlr_num, 0);
50865- atomic_set(&fcf_num, 0);
50866+ atomic_set_unchecked(&ctlr_num, 0);
50867+ atomic_set_unchecked(&fcf_num, 0);
50868
50869 error = bus_register(&fcoe_bus_type);
50870 if (error)
50871diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
50872index 6de80e3..a11e0ac 100644
50873--- a/drivers/scsi/hosts.c
50874+++ b/drivers/scsi/hosts.c
50875@@ -42,7 +42,7 @@
50876 #include "scsi_logging.h"
50877
50878
50879-static atomic_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
50880+static atomic_unchecked_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
50881
50882
50883 static void scsi_host_cls_release(struct device *dev)
50884@@ -392,7 +392,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
50885 * subtract one because we increment first then return, but we need to
50886 * know what the next host number was before increment
50887 */
50888- shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
50889+ shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
50890 shost->dma_channel = 0xff;
50891
50892 /* These three are default values which can be overridden */
50893diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
50894index cef5d49..01e280e 100644
50895--- a/drivers/scsi/hpsa.c
50896+++ b/drivers/scsi/hpsa.c
50897@@ -701,10 +701,10 @@ static inline u32 next_command(struct ctlr_info *h, u8 q)
50898 unsigned long flags;
50899
50900 if (h->transMethod & CFGTBL_Trans_io_accel1)
50901- return h->access.command_completed(h, q);
50902+ return h->access->command_completed(h, q);
50903
50904 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
50905- return h->access.command_completed(h, q);
50906+ return h->access->command_completed(h, q);
50907
50908 if ((rq->head[rq->current_entry] & 1) == rq->wraparound) {
50909 a = rq->head[rq->current_entry];
50910@@ -5454,7 +5454,7 @@ static void start_io(struct ctlr_info *h, unsigned long *flags)
50911 while (!list_empty(&h->reqQ)) {
50912 c = list_entry(h->reqQ.next, struct CommandList, list);
50913 /* can't do anything if fifo is full */
50914- if ((h->access.fifo_full(h))) {
50915+ if ((h->access->fifo_full(h))) {
50916 h->fifo_recently_full = 1;
50917 dev_warn(&h->pdev->dev, "fifo full\n");
50918 break;
50919@@ -5476,7 +5476,7 @@ static void start_io(struct ctlr_info *h, unsigned long *flags)
50920
50921 /* Tell the controller execute command */
50922 spin_unlock_irqrestore(&h->lock, *flags);
50923- h->access.submit_command(h, c);
50924+ h->access->submit_command(h, c);
50925 spin_lock_irqsave(&h->lock, *flags);
50926 }
50927 }
50928@@ -5492,17 +5492,17 @@ static void lock_and_start_io(struct ctlr_info *h)
50929
50930 static inline unsigned long get_next_completion(struct ctlr_info *h, u8 q)
50931 {
50932- return h->access.command_completed(h, q);
50933+ return h->access->command_completed(h, q);
50934 }
50935
50936 static inline bool interrupt_pending(struct ctlr_info *h)
50937 {
50938- return h->access.intr_pending(h);
50939+ return h->access->intr_pending(h);
50940 }
50941
50942 static inline long interrupt_not_for_us(struct ctlr_info *h)
50943 {
50944- return (h->access.intr_pending(h) == 0) ||
50945+ return (h->access->intr_pending(h) == 0) ||
50946 (h->interrupts_enabled == 0);
50947 }
50948
50949@@ -6445,7 +6445,7 @@ static int hpsa_pci_init(struct ctlr_info *h)
50950 if (prod_index < 0)
50951 return -ENODEV;
50952 h->product_name = products[prod_index].product_name;
50953- h->access = *(products[prod_index].access);
50954+ h->access = products[prod_index].access;
50955
50956 pci_disable_link_state(h->pdev, PCIE_LINK_STATE_L0S |
50957 PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM);
50958@@ -6790,7 +6790,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
50959 unsigned long flags;
50960 u32 lockup_detected;
50961
50962- h->access.set_intr_mask(h, HPSA_INTR_OFF);
50963+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
50964 spin_lock_irqsave(&h->lock, flags);
50965 lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
50966 if (!lockup_detected) {
50967@@ -7037,7 +7037,7 @@ reinit_after_soft_reset:
50968 }
50969
50970 /* make sure the board interrupts are off */
50971- h->access.set_intr_mask(h, HPSA_INTR_OFF);
50972+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
50973
50974 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
50975 goto clean2;
50976@@ -7072,7 +7072,7 @@ reinit_after_soft_reset:
50977 * fake ones to scoop up any residual completions.
50978 */
50979 spin_lock_irqsave(&h->lock, flags);
50980- h->access.set_intr_mask(h, HPSA_INTR_OFF);
50981+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
50982 spin_unlock_irqrestore(&h->lock, flags);
50983 free_irqs(h);
50984 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
50985@@ -7091,9 +7091,9 @@ reinit_after_soft_reset:
50986 dev_info(&h->pdev->dev, "Board READY.\n");
50987 dev_info(&h->pdev->dev,
50988 "Waiting for stale completions to drain.\n");
50989- h->access.set_intr_mask(h, HPSA_INTR_ON);
50990+ h->access->set_intr_mask(h, HPSA_INTR_ON);
50991 msleep(10000);
50992- h->access.set_intr_mask(h, HPSA_INTR_OFF);
50993+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
50994
50995 rc = controller_reset_failed(h->cfgtable);
50996 if (rc)
50997@@ -7119,7 +7119,7 @@ reinit_after_soft_reset:
50998 h->drv_req_rescan = 0;
50999
51000 /* Turn the interrupts on so we can service requests */
51001- h->access.set_intr_mask(h, HPSA_INTR_ON);
51002+ h->access->set_intr_mask(h, HPSA_INTR_ON);
51003
51004 hpsa_hba_inquiry(h);
51005 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
51006@@ -7184,7 +7184,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
51007 * To write all data in the battery backed cache to disks
51008 */
51009 hpsa_flush_cache(h);
51010- h->access.set_intr_mask(h, HPSA_INTR_OFF);
51011+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
51012 hpsa_free_irqs_and_disable_msix(h);
51013 }
51014
51015@@ -7302,7 +7302,7 @@ static void hpsa_enter_performant_mode(struct ctlr_info *h, u32 trans_support)
51016 CFGTBL_Trans_enable_directed_msix |
51017 (trans_support & (CFGTBL_Trans_io_accel1 |
51018 CFGTBL_Trans_io_accel2));
51019- struct access_method access = SA5_performant_access;
51020+ struct access_method *access = &SA5_performant_access;
51021
51022 /* This is a bit complicated. There are 8 registers on
51023 * the controller which we write to to tell it 8 different
51024@@ -7344,7 +7344,7 @@ static void hpsa_enter_performant_mode(struct ctlr_info *h, u32 trans_support)
51025 * perform the superfluous readl() after each command submission.
51026 */
51027 if (trans_support & (CFGTBL_Trans_io_accel1 | CFGTBL_Trans_io_accel2))
51028- access = SA5_performant_access_no_read;
51029+ access = &SA5_performant_access_no_read;
51030
51031 /* Controller spec: zero out this buffer. */
51032 for (i = 0; i < h->nreply_queues; i++)
51033@@ -7374,12 +7374,12 @@ static void hpsa_enter_performant_mode(struct ctlr_info *h, u32 trans_support)
51034 * enable outbound interrupt coalescing in accelerator mode;
51035 */
51036 if (trans_support & CFGTBL_Trans_io_accel1) {
51037- access = SA5_ioaccel_mode1_access;
51038+ access = &SA5_ioaccel_mode1_access;
51039 writel(10, &h->cfgtable->HostWrite.CoalIntDelay);
51040 writel(4, &h->cfgtable->HostWrite.CoalIntCount);
51041 } else {
51042 if (trans_support & CFGTBL_Trans_io_accel2) {
51043- access = SA5_ioaccel_mode2_access;
51044+ access = &SA5_ioaccel_mode2_access;
51045 writel(10, &h->cfgtable->HostWrite.CoalIntDelay);
51046 writel(4, &h->cfgtable->HostWrite.CoalIntCount);
51047 }
51048diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
51049index 24472ce..8782caf 100644
51050--- a/drivers/scsi/hpsa.h
51051+++ b/drivers/scsi/hpsa.h
51052@@ -127,7 +127,7 @@ struct ctlr_info {
51053 unsigned int msix_vector;
51054 unsigned int msi_vector;
51055 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
51056- struct access_method access;
51057+ struct access_method *access;
51058 char hba_mode_enabled;
51059
51060 /* queue and queue Info */
51061@@ -536,43 +536,43 @@ static unsigned long SA5_ioaccel_mode1_completed(struct ctlr_info *h, u8 q)
51062 }
51063
51064 static struct access_method SA5_access = {
51065- SA5_submit_command,
51066- SA5_intr_mask,
51067- SA5_fifo_full,
51068- SA5_intr_pending,
51069- SA5_completed,
51070+ .submit_command = SA5_submit_command,
51071+ .set_intr_mask = SA5_intr_mask,
51072+ .fifo_full = SA5_fifo_full,
51073+ .intr_pending = SA5_intr_pending,
51074+ .command_completed = SA5_completed,
51075 };
51076
51077 static struct access_method SA5_ioaccel_mode1_access = {
51078- SA5_submit_command,
51079- SA5_performant_intr_mask,
51080- SA5_fifo_full,
51081- SA5_ioaccel_mode1_intr_pending,
51082- SA5_ioaccel_mode1_completed,
51083+ .submit_command = SA5_submit_command,
51084+ .set_intr_mask = SA5_performant_intr_mask,
51085+ .fifo_full = SA5_fifo_full,
51086+ .intr_pending = SA5_ioaccel_mode1_intr_pending,
51087+ .command_completed = SA5_ioaccel_mode1_completed,
51088 };
51089
51090 static struct access_method SA5_ioaccel_mode2_access = {
51091- SA5_submit_command_ioaccel2,
51092- SA5_performant_intr_mask,
51093- SA5_fifo_full,
51094- SA5_performant_intr_pending,
51095- SA5_performant_completed,
51096+ .submit_command = SA5_submit_command_ioaccel2,
51097+ .set_intr_mask = SA5_performant_intr_mask,
51098+ .fifo_full = SA5_fifo_full,
51099+ .intr_pending = SA5_performant_intr_pending,
51100+ .command_completed = SA5_performant_completed,
51101 };
51102
51103 static struct access_method SA5_performant_access = {
51104- SA5_submit_command,
51105- SA5_performant_intr_mask,
51106- SA5_fifo_full,
51107- SA5_performant_intr_pending,
51108- SA5_performant_completed,
51109+ .submit_command = SA5_submit_command,
51110+ .set_intr_mask = SA5_performant_intr_mask,
51111+ .fifo_full = SA5_fifo_full,
51112+ .intr_pending = SA5_performant_intr_pending,
51113+ .command_completed = SA5_performant_completed,
51114 };
51115
51116 static struct access_method SA5_performant_access_no_read = {
51117- SA5_submit_command_no_read,
51118- SA5_performant_intr_mask,
51119- SA5_fifo_full,
51120- SA5_performant_intr_pending,
51121- SA5_performant_completed,
51122+ .submit_command = SA5_submit_command_no_read,
51123+ .set_intr_mask = SA5_performant_intr_mask,
51124+ .fifo_full = SA5_fifo_full,
51125+ .intr_pending = SA5_performant_intr_pending,
51126+ .command_completed = SA5_performant_completed,
51127 };
51128
51129 struct board_type {
51130diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
51131index 1b3a094..068e683 100644
51132--- a/drivers/scsi/libfc/fc_exch.c
51133+++ b/drivers/scsi/libfc/fc_exch.c
51134@@ -101,12 +101,12 @@ struct fc_exch_mgr {
51135 u16 pool_max_index;
51136
51137 struct {
51138- atomic_t no_free_exch;
51139- atomic_t no_free_exch_xid;
51140- atomic_t xid_not_found;
51141- atomic_t xid_busy;
51142- atomic_t seq_not_found;
51143- atomic_t non_bls_resp;
51144+ atomic_unchecked_t no_free_exch;
51145+ atomic_unchecked_t no_free_exch_xid;
51146+ atomic_unchecked_t xid_not_found;
51147+ atomic_unchecked_t xid_busy;
51148+ atomic_unchecked_t seq_not_found;
51149+ atomic_unchecked_t non_bls_resp;
51150 } stats;
51151 };
51152
51153@@ -811,7 +811,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
51154 /* allocate memory for exchange */
51155 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
51156 if (!ep) {
51157- atomic_inc(&mp->stats.no_free_exch);
51158+ atomic_inc_unchecked(&mp->stats.no_free_exch);
51159 goto out;
51160 }
51161 memset(ep, 0, sizeof(*ep));
51162@@ -874,7 +874,7 @@ out:
51163 return ep;
51164 err:
51165 spin_unlock_bh(&pool->lock);
51166- atomic_inc(&mp->stats.no_free_exch_xid);
51167+ atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
51168 mempool_free(ep, mp->ep_pool);
51169 return NULL;
51170 }
51171@@ -1023,7 +1023,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
51172 xid = ntohs(fh->fh_ox_id); /* we originated exch */
51173 ep = fc_exch_find(mp, xid);
51174 if (!ep) {
51175- atomic_inc(&mp->stats.xid_not_found);
51176+ atomic_inc_unchecked(&mp->stats.xid_not_found);
51177 reject = FC_RJT_OX_ID;
51178 goto out;
51179 }
51180@@ -1053,7 +1053,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
51181 ep = fc_exch_find(mp, xid);
51182 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
51183 if (ep) {
51184- atomic_inc(&mp->stats.xid_busy);
51185+ atomic_inc_unchecked(&mp->stats.xid_busy);
51186 reject = FC_RJT_RX_ID;
51187 goto rel;
51188 }
51189@@ -1064,7 +1064,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
51190 }
51191 xid = ep->xid; /* get our XID */
51192 } else if (!ep) {
51193- atomic_inc(&mp->stats.xid_not_found);
51194+ atomic_inc_unchecked(&mp->stats.xid_not_found);
51195 reject = FC_RJT_RX_ID; /* XID not found */
51196 goto out;
51197 }
51198@@ -1082,7 +1082,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
51199 } else {
51200 sp = &ep->seq;
51201 if (sp->id != fh->fh_seq_id) {
51202- atomic_inc(&mp->stats.seq_not_found);
51203+ atomic_inc_unchecked(&mp->stats.seq_not_found);
51204 if (f_ctl & FC_FC_END_SEQ) {
51205 /*
51206 * Update sequence_id based on incoming last
51207@@ -1533,22 +1533,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
51208
51209 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
51210 if (!ep) {
51211- atomic_inc(&mp->stats.xid_not_found);
51212+ atomic_inc_unchecked(&mp->stats.xid_not_found);
51213 goto out;
51214 }
51215 if (ep->esb_stat & ESB_ST_COMPLETE) {
51216- atomic_inc(&mp->stats.xid_not_found);
51217+ atomic_inc_unchecked(&mp->stats.xid_not_found);
51218 goto rel;
51219 }
51220 if (ep->rxid == FC_XID_UNKNOWN)
51221 ep->rxid = ntohs(fh->fh_rx_id);
51222 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
51223- atomic_inc(&mp->stats.xid_not_found);
51224+ atomic_inc_unchecked(&mp->stats.xid_not_found);
51225 goto rel;
51226 }
51227 if (ep->did != ntoh24(fh->fh_s_id) &&
51228 ep->did != FC_FID_FLOGI) {
51229- atomic_inc(&mp->stats.xid_not_found);
51230+ atomic_inc_unchecked(&mp->stats.xid_not_found);
51231 goto rel;
51232 }
51233 sof = fr_sof(fp);
51234@@ -1557,7 +1557,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
51235 sp->ssb_stat |= SSB_ST_RESP;
51236 sp->id = fh->fh_seq_id;
51237 } else if (sp->id != fh->fh_seq_id) {
51238- atomic_inc(&mp->stats.seq_not_found);
51239+ atomic_inc_unchecked(&mp->stats.seq_not_found);
51240 goto rel;
51241 }
51242
51243@@ -1619,9 +1619,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
51244 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
51245
51246 if (!sp)
51247- atomic_inc(&mp->stats.xid_not_found);
51248+ atomic_inc_unchecked(&mp->stats.xid_not_found);
51249 else
51250- atomic_inc(&mp->stats.non_bls_resp);
51251+ atomic_inc_unchecked(&mp->stats.non_bls_resp);
51252
51253 fc_frame_free(fp);
51254 }
51255@@ -2261,13 +2261,13 @@ void fc_exch_update_stats(struct fc_lport *lport)
51256
51257 list_for_each_entry(ema, &lport->ema_list, ema_list) {
51258 mp = ema->mp;
51259- st->fc_no_free_exch += atomic_read(&mp->stats.no_free_exch);
51260+ st->fc_no_free_exch += atomic_read_unchecked(&mp->stats.no_free_exch);
51261 st->fc_no_free_exch_xid +=
51262- atomic_read(&mp->stats.no_free_exch_xid);
51263- st->fc_xid_not_found += atomic_read(&mp->stats.xid_not_found);
51264- st->fc_xid_busy += atomic_read(&mp->stats.xid_busy);
51265- st->fc_seq_not_found += atomic_read(&mp->stats.seq_not_found);
51266- st->fc_non_bls_resp += atomic_read(&mp->stats.non_bls_resp);
51267+ atomic_read_unchecked(&mp->stats.no_free_exch_xid);
51268+ st->fc_xid_not_found += atomic_read_unchecked(&mp->stats.xid_not_found);
51269+ st->fc_xid_busy += atomic_read_unchecked(&mp->stats.xid_busy);
51270+ st->fc_seq_not_found += atomic_read_unchecked(&mp->stats.seq_not_found);
51271+ st->fc_non_bls_resp += atomic_read_unchecked(&mp->stats.non_bls_resp);
51272 }
51273 }
51274 EXPORT_SYMBOL(fc_exch_update_stats);
51275diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
51276index 766098a..1c6c971 100644
51277--- a/drivers/scsi/libsas/sas_ata.c
51278+++ b/drivers/scsi/libsas/sas_ata.c
51279@@ -554,7 +554,7 @@ static struct ata_port_operations sas_sata_ops = {
51280 .postreset = ata_std_postreset,
51281 .error_handler = ata_std_error_handler,
51282 .post_internal_cmd = sas_ata_post_internal,
51283- .qc_defer = ata_std_qc_defer,
51284+ .qc_defer = ata_std_qc_defer,
51285 .qc_prep = ata_noop_qc_prep,
51286 .qc_issue = sas_ata_qc_issue,
51287 .qc_fill_rtf = sas_ata_qc_fill_rtf,
51288diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
51289index 434e903..5a4a79b 100644
51290--- a/drivers/scsi/lpfc/lpfc.h
51291+++ b/drivers/scsi/lpfc/lpfc.h
51292@@ -430,7 +430,7 @@ struct lpfc_vport {
51293 struct dentry *debug_nodelist;
51294 struct dentry *vport_debugfs_root;
51295 struct lpfc_debugfs_trc *disc_trc;
51296- atomic_t disc_trc_cnt;
51297+ atomic_unchecked_t disc_trc_cnt;
51298 #endif
51299 uint8_t stat_data_enabled;
51300 uint8_t stat_data_blocked;
51301@@ -880,8 +880,8 @@ struct lpfc_hba {
51302 struct timer_list fabric_block_timer;
51303 unsigned long bit_flags;
51304 #define FABRIC_COMANDS_BLOCKED 0
51305- atomic_t num_rsrc_err;
51306- atomic_t num_cmd_success;
51307+ atomic_unchecked_t num_rsrc_err;
51308+ atomic_unchecked_t num_cmd_success;
51309 unsigned long last_rsrc_error_time;
51310 unsigned long last_ramp_down_time;
51311 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
51312@@ -916,7 +916,7 @@ struct lpfc_hba {
51313
51314 struct dentry *debug_slow_ring_trc;
51315 struct lpfc_debugfs_trc *slow_ring_trc;
51316- atomic_t slow_ring_trc_cnt;
51317+ atomic_unchecked_t slow_ring_trc_cnt;
51318 /* iDiag debugfs sub-directory */
51319 struct dentry *idiag_root;
51320 struct dentry *idiag_pci_cfg;
51321diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
51322index 786a2af..562c6a2 100644
51323--- a/drivers/scsi/lpfc/lpfc_debugfs.c
51324+++ b/drivers/scsi/lpfc/lpfc_debugfs.c
51325@@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
51326
51327 #include <linux/debugfs.h>
51328
51329-static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
51330+static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
51331 static unsigned long lpfc_debugfs_start_time = 0L;
51332
51333 /* iDiag */
51334@@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
51335 lpfc_debugfs_enable = 0;
51336
51337 len = 0;
51338- index = (atomic_read(&vport->disc_trc_cnt) + 1) &
51339+ index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
51340 (lpfc_debugfs_max_disc_trc - 1);
51341 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
51342 dtp = vport->disc_trc + i;
51343@@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
51344 lpfc_debugfs_enable = 0;
51345
51346 len = 0;
51347- index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
51348+ index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
51349 (lpfc_debugfs_max_slow_ring_trc - 1);
51350 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
51351 dtp = phba->slow_ring_trc + i;
51352@@ -646,14 +646,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
51353 !vport || !vport->disc_trc)
51354 return;
51355
51356- index = atomic_inc_return(&vport->disc_trc_cnt) &
51357+ index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
51358 (lpfc_debugfs_max_disc_trc - 1);
51359 dtp = vport->disc_trc + index;
51360 dtp->fmt = fmt;
51361 dtp->data1 = data1;
51362 dtp->data2 = data2;
51363 dtp->data3 = data3;
51364- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
51365+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
51366 dtp->jif = jiffies;
51367 #endif
51368 return;
51369@@ -684,14 +684,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
51370 !phba || !phba->slow_ring_trc)
51371 return;
51372
51373- index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
51374+ index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
51375 (lpfc_debugfs_max_slow_ring_trc - 1);
51376 dtp = phba->slow_ring_trc + index;
51377 dtp->fmt = fmt;
51378 dtp->data1 = data1;
51379 dtp->data2 = data2;
51380 dtp->data3 = data3;
51381- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
51382+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
51383 dtp->jif = jiffies;
51384 #endif
51385 return;
51386@@ -4268,7 +4268,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
51387 "slow_ring buffer\n");
51388 goto debug_failed;
51389 }
51390- atomic_set(&phba->slow_ring_trc_cnt, 0);
51391+ atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
51392 memset(phba->slow_ring_trc, 0,
51393 (sizeof(struct lpfc_debugfs_trc) *
51394 lpfc_debugfs_max_slow_ring_trc));
51395@@ -4314,7 +4314,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
51396 "buffer\n");
51397 goto debug_failed;
51398 }
51399- atomic_set(&vport->disc_trc_cnt, 0);
51400+ atomic_set_unchecked(&vport->disc_trc_cnt, 0);
51401
51402 snprintf(name, sizeof(name), "discovery_trace");
51403 vport->debug_disc_trc =
51404diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
51405index 0b2c53a..aec2b45 100644
51406--- a/drivers/scsi/lpfc/lpfc_init.c
51407+++ b/drivers/scsi/lpfc/lpfc_init.c
51408@@ -11290,8 +11290,10 @@ lpfc_init(void)
51409 "misc_register returned with status %d", error);
51410
51411 if (lpfc_enable_npiv) {
51412- lpfc_transport_functions.vport_create = lpfc_vport_create;
51413- lpfc_transport_functions.vport_delete = lpfc_vport_delete;
51414+ pax_open_kernel();
51415+ *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
51416+ *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
51417+ pax_close_kernel();
51418 }
51419 lpfc_transport_template =
51420 fc_attach_transport(&lpfc_transport_functions);
51421diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
51422index b99399f..d29dc75 100644
51423--- a/drivers/scsi/lpfc/lpfc_scsi.c
51424+++ b/drivers/scsi/lpfc/lpfc_scsi.c
51425@@ -383,7 +383,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
51426 unsigned long expires;
51427
51428 spin_lock_irqsave(&phba->hbalock, flags);
51429- atomic_inc(&phba->num_rsrc_err);
51430+ atomic_inc_unchecked(&phba->num_rsrc_err);
51431 phba->last_rsrc_error_time = jiffies;
51432
51433 expires = phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL;
51434@@ -425,8 +425,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
51435 unsigned long num_rsrc_err, num_cmd_success;
51436 int i;
51437
51438- num_rsrc_err = atomic_read(&phba->num_rsrc_err);
51439- num_cmd_success = atomic_read(&phba->num_cmd_success);
51440+ num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
51441+ num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
51442
51443 /*
51444 * The error and success command counters are global per
51445@@ -454,8 +454,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
51446 }
51447 }
51448 lpfc_destroy_vport_work_array(phba, vports);
51449- atomic_set(&phba->num_rsrc_err, 0);
51450- atomic_set(&phba->num_cmd_success, 0);
51451+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
51452+ atomic_set_unchecked(&phba->num_cmd_success, 0);
51453 }
51454
51455 /**
51456diff --git a/drivers/scsi/mpt2sas/mpt2sas_scsih.c b/drivers/scsi/mpt2sas/mpt2sas_scsih.c
51457index c80ed04..e674f01 100644
51458--- a/drivers/scsi/mpt2sas/mpt2sas_scsih.c
51459+++ b/drivers/scsi/mpt2sas/mpt2sas_scsih.c
51460@@ -1561,7 +1561,7 @@ _scsih_get_resync(struct device *dev)
51461 {
51462 struct scsi_device *sdev = to_scsi_device(dev);
51463 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
51464- static struct _raid_device *raid_device;
51465+ struct _raid_device *raid_device;
51466 unsigned long flags;
51467 Mpi2RaidVolPage0_t vol_pg0;
51468 Mpi2ConfigReply_t mpi_reply;
51469@@ -1613,7 +1613,7 @@ _scsih_get_state(struct device *dev)
51470 {
51471 struct scsi_device *sdev = to_scsi_device(dev);
51472 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
51473- static struct _raid_device *raid_device;
51474+ struct _raid_device *raid_device;
51475 unsigned long flags;
51476 Mpi2RaidVolPage0_t vol_pg0;
51477 Mpi2ConfigReply_t mpi_reply;
51478@@ -6663,7 +6663,7 @@ _scsih_sas_ir_operation_status_event(struct MPT2SAS_ADAPTER *ioc,
51479 Mpi2EventDataIrOperationStatus_t *event_data =
51480 (Mpi2EventDataIrOperationStatus_t *)
51481 fw_event->event_data;
51482- static struct _raid_device *raid_device;
51483+ struct _raid_device *raid_device;
51484 unsigned long flags;
51485 u16 handle;
51486
51487@@ -7134,7 +7134,7 @@ _scsih_scan_for_devices_after_reset(struct MPT2SAS_ADAPTER *ioc)
51488 u64 sas_address;
51489 struct _sas_device *sas_device;
51490 struct _sas_node *expander_device;
51491- static struct _raid_device *raid_device;
51492+ struct _raid_device *raid_device;
51493 u8 retry_count;
51494 unsigned long flags;
51495
51496diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
51497index bcb64eb..f08cf71 100644
51498--- a/drivers/scsi/pmcraid.c
51499+++ b/drivers/scsi/pmcraid.c
51500@@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
51501 res->scsi_dev = scsi_dev;
51502 scsi_dev->hostdata = res;
51503 res->change_detected = 0;
51504- atomic_set(&res->read_failures, 0);
51505- atomic_set(&res->write_failures, 0);
51506+ atomic_set_unchecked(&res->read_failures, 0);
51507+ atomic_set_unchecked(&res->write_failures, 0);
51508 rc = 0;
51509 }
51510 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
51511@@ -2687,9 +2687,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
51512
51513 /* If this was a SCSI read/write command keep count of errors */
51514 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
51515- atomic_inc(&res->read_failures);
51516+ atomic_inc_unchecked(&res->read_failures);
51517 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
51518- atomic_inc(&res->write_failures);
51519+ atomic_inc_unchecked(&res->write_failures);
51520
51521 if (!RES_IS_GSCSI(res->cfg_entry) &&
51522 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
51523@@ -3545,7 +3545,7 @@ static int pmcraid_queuecommand_lck(
51524 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
51525 * hrrq_id assigned here in queuecommand
51526 */
51527- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
51528+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
51529 pinstance->num_hrrq;
51530 cmd->cmd_done = pmcraid_io_done;
51531
51532@@ -3857,7 +3857,7 @@ static long pmcraid_ioctl_passthrough(
51533 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
51534 * hrrq_id assigned here in queuecommand
51535 */
51536- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
51537+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
51538 pinstance->num_hrrq;
51539
51540 if (request_size) {
51541@@ -4495,7 +4495,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
51542
51543 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
51544 /* add resources only after host is added into system */
51545- if (!atomic_read(&pinstance->expose_resources))
51546+ if (!atomic_read_unchecked(&pinstance->expose_resources))
51547 return;
51548
51549 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
51550@@ -5312,8 +5312,8 @@ static int pmcraid_init_instance(struct pci_dev *pdev, struct Scsi_Host *host,
51551 init_waitqueue_head(&pinstance->reset_wait_q);
51552
51553 atomic_set(&pinstance->outstanding_cmds, 0);
51554- atomic_set(&pinstance->last_message_id, 0);
51555- atomic_set(&pinstance->expose_resources, 0);
51556+ atomic_set_unchecked(&pinstance->last_message_id, 0);
51557+ atomic_set_unchecked(&pinstance->expose_resources, 0);
51558
51559 INIT_LIST_HEAD(&pinstance->free_res_q);
51560 INIT_LIST_HEAD(&pinstance->used_res_q);
51561@@ -6026,7 +6026,7 @@ static int pmcraid_probe(struct pci_dev *pdev,
51562 /* Schedule worker thread to handle CCN and take care of adding and
51563 * removing devices to OS
51564 */
51565- atomic_set(&pinstance->expose_resources, 1);
51566+ atomic_set_unchecked(&pinstance->expose_resources, 1);
51567 schedule_work(&pinstance->worker_q);
51568 return rc;
51569
51570diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
51571index e1d150f..6c6df44 100644
51572--- a/drivers/scsi/pmcraid.h
51573+++ b/drivers/scsi/pmcraid.h
51574@@ -748,7 +748,7 @@ struct pmcraid_instance {
51575 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
51576
51577 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
51578- atomic_t last_message_id;
51579+ atomic_unchecked_t last_message_id;
51580
51581 /* configuration table */
51582 struct pmcraid_config_table *cfg_table;
51583@@ -777,7 +777,7 @@ struct pmcraid_instance {
51584 atomic_t outstanding_cmds;
51585
51586 /* should add/delete resources to mid-layer now ?*/
51587- atomic_t expose_resources;
51588+ atomic_unchecked_t expose_resources;
51589
51590
51591
51592@@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
51593 struct pmcraid_config_table_entry_ext cfg_entry_ext;
51594 };
51595 struct scsi_device *scsi_dev; /* Link scsi_device structure */
51596- atomic_t read_failures; /* count of failed READ commands */
51597- atomic_t write_failures; /* count of failed WRITE commands */
51598+ atomic_unchecked_t read_failures; /* count of failed READ commands */
51599+ atomic_unchecked_t write_failures; /* count of failed WRITE commands */
51600
51601 /* To indicate add/delete/modify during CCN */
51602 u8 change_detected;
51603diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
51604index 82b92c4..3178171 100644
51605--- a/drivers/scsi/qla2xxx/qla_attr.c
51606+++ b/drivers/scsi/qla2xxx/qla_attr.c
51607@@ -2192,7 +2192,7 @@ qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
51608 return 0;
51609 }
51610
51611-struct fc_function_template qla2xxx_transport_functions = {
51612+fc_function_template_no_const qla2xxx_transport_functions = {
51613
51614 .show_host_node_name = 1,
51615 .show_host_port_name = 1,
51616@@ -2240,7 +2240,7 @@ struct fc_function_template qla2xxx_transport_functions = {
51617 .bsg_timeout = qla24xx_bsg_timeout,
51618 };
51619
51620-struct fc_function_template qla2xxx_transport_vport_functions = {
51621+fc_function_template_no_const qla2xxx_transport_vport_functions = {
51622
51623 .show_host_node_name = 1,
51624 .show_host_port_name = 1,
51625diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
51626index b1865a7..a7723d3 100644
51627--- a/drivers/scsi/qla2xxx/qla_gbl.h
51628+++ b/drivers/scsi/qla2xxx/qla_gbl.h
51629@@ -571,8 +571,8 @@ extern void qla2x00_get_sym_node_name(scsi_qla_host_t *, uint8_t *, size_t);
51630 struct device_attribute;
51631 extern struct device_attribute *qla2x00_host_attrs[];
51632 struct fc_function_template;
51633-extern struct fc_function_template qla2xxx_transport_functions;
51634-extern struct fc_function_template qla2xxx_transport_vport_functions;
51635+extern fc_function_template_no_const qla2xxx_transport_functions;
51636+extern fc_function_template_no_const qla2xxx_transport_vport_functions;
51637 extern void qla2x00_alloc_sysfs_attr(scsi_qla_host_t *);
51638 extern void qla2x00_free_sysfs_attr(scsi_qla_host_t *, bool);
51639 extern void qla2x00_init_host_attr(scsi_qla_host_t *);
51640diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
51641index db3dbd9..2492392 100644
51642--- a/drivers/scsi/qla2xxx/qla_os.c
51643+++ b/drivers/scsi/qla2xxx/qla_os.c
51644@@ -1507,8 +1507,10 @@ qla2x00_config_dma_addressing(struct qla_hw_data *ha)
51645 !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
51646 /* Ok, a 64bit DMA mask is applicable. */
51647 ha->flags.enable_64bit_addressing = 1;
51648- ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
51649- ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
51650+ pax_open_kernel();
51651+ *(void **)&ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
51652+ *(void **)&ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
51653+ pax_close_kernel();
51654 return;
51655 }
51656 }
51657diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
51658index 8f6d0fb..1b21097 100644
51659--- a/drivers/scsi/qla4xxx/ql4_def.h
51660+++ b/drivers/scsi/qla4xxx/ql4_def.h
51661@@ -305,7 +305,7 @@ struct ddb_entry {
51662 * (4000 only) */
51663 atomic_t relogin_timer; /* Max Time to wait for
51664 * relogin to complete */
51665- atomic_t relogin_retry_count; /* Num of times relogin has been
51666+ atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
51667 * retried */
51668 uint32_t default_time2wait; /* Default Min time between
51669 * relogins (+aens) */
51670diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
51671index 199fcf7..3c3a918 100644
51672--- a/drivers/scsi/qla4xxx/ql4_os.c
51673+++ b/drivers/scsi/qla4xxx/ql4_os.c
51674@@ -4496,12 +4496,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
51675 */
51676 if (!iscsi_is_session_online(cls_sess)) {
51677 /* Reset retry relogin timer */
51678- atomic_inc(&ddb_entry->relogin_retry_count);
51679+ atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
51680 DEBUG2(ql4_printk(KERN_INFO, ha,
51681 "%s: index[%d] relogin timed out-retrying"
51682 " relogin (%d), retry (%d)\n", __func__,
51683 ddb_entry->fw_ddb_index,
51684- atomic_read(&ddb_entry->relogin_retry_count),
51685+ atomic_read_unchecked(&ddb_entry->relogin_retry_count),
51686 ddb_entry->default_time2wait + 4));
51687 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
51688 atomic_set(&ddb_entry->retry_relogin_timer,
51689@@ -6609,7 +6609,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
51690
51691 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
51692 atomic_set(&ddb_entry->relogin_timer, 0);
51693- atomic_set(&ddb_entry->relogin_retry_count, 0);
51694+ atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
51695 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
51696 ddb_entry->default_relogin_timeout =
51697 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
51698diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
51699index 79c77b4..ef6ec0b 100644
51700--- a/drivers/scsi/scsi.c
51701+++ b/drivers/scsi/scsi.c
51702@@ -645,7 +645,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
51703 struct Scsi_Host *host = cmd->device->host;
51704 int rtn = 0;
51705
51706- atomic_inc(&cmd->device->iorequest_cnt);
51707+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
51708
51709 /* check if the device is still usable */
51710 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
51711diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
51712index 50a6e1a..de5252e 100644
51713--- a/drivers/scsi/scsi_lib.c
51714+++ b/drivers/scsi/scsi_lib.c
51715@@ -1583,7 +1583,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
51716 shost = sdev->host;
51717 scsi_init_cmd_errh(cmd);
51718 cmd->result = DID_NO_CONNECT << 16;
51719- atomic_inc(&cmd->device->iorequest_cnt);
51720+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
51721
51722 /*
51723 * SCSI request completion path will do scsi_device_unbusy(),
51724@@ -1606,9 +1606,9 @@ static void scsi_softirq_done(struct request *rq)
51725
51726 INIT_LIST_HEAD(&cmd->eh_entry);
51727
51728- atomic_inc(&cmd->device->iodone_cnt);
51729+ atomic_inc_unchecked(&cmd->device->iodone_cnt);
51730 if (cmd->result)
51731- atomic_inc(&cmd->device->ioerr_cnt);
51732+ atomic_inc_unchecked(&cmd->device->ioerr_cnt);
51733
51734 disposition = scsi_decide_disposition(cmd);
51735 if (disposition != SUCCESS &&
51736diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
51737index f4cb7b3..dfa79c4 100644
51738--- a/drivers/scsi/scsi_sysfs.c
51739+++ b/drivers/scsi/scsi_sysfs.c
51740@@ -805,7 +805,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
51741 char *buf) \
51742 { \
51743 struct scsi_device *sdev = to_scsi_device(dev); \
51744- unsigned long long count = atomic_read(&sdev->field); \
51745+ unsigned long long count = atomic_read_unchecked(&sdev->field); \
51746 return snprintf(buf, 20, "0x%llx\n", count); \
51747 } \
51748 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
51749diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
51750index 5d6f348..18778a6b 100644
51751--- a/drivers/scsi/scsi_transport_fc.c
51752+++ b/drivers/scsi/scsi_transport_fc.c
51753@@ -501,7 +501,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
51754 * Netlink Infrastructure
51755 */
51756
51757-static atomic_t fc_event_seq;
51758+static atomic_unchecked_t fc_event_seq;
51759
51760 /**
51761 * fc_get_event_number - Obtain the next sequential FC event number
51762@@ -514,7 +514,7 @@ static atomic_t fc_event_seq;
51763 u32
51764 fc_get_event_number(void)
51765 {
51766- return atomic_add_return(1, &fc_event_seq);
51767+ return atomic_add_return_unchecked(1, &fc_event_seq);
51768 }
51769 EXPORT_SYMBOL(fc_get_event_number);
51770
51771@@ -658,7 +658,7 @@ static __init int fc_transport_init(void)
51772 {
51773 int error;
51774
51775- atomic_set(&fc_event_seq, 0);
51776+ atomic_set_unchecked(&fc_event_seq, 0);
51777
51778 error = transport_class_register(&fc_host_class);
51779 if (error)
51780@@ -848,7 +848,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
51781 char *cp;
51782
51783 *val = simple_strtoul(buf, &cp, 0);
51784- if ((*cp && (*cp != '\n')) || (*val < 0))
51785+ if (*cp && (*cp != '\n'))
51786 return -EINVAL;
51787 /*
51788 * Check for overflow; dev_loss_tmo is u32
51789diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
51790index 67d43e3..8cee73c 100644
51791--- a/drivers/scsi/scsi_transport_iscsi.c
51792+++ b/drivers/scsi/scsi_transport_iscsi.c
51793@@ -79,7 +79,7 @@ struct iscsi_internal {
51794 struct transport_container session_cont;
51795 };
51796
51797-static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
51798+static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
51799 static struct workqueue_struct *iscsi_eh_timer_workq;
51800
51801 static DEFINE_IDA(iscsi_sess_ida);
51802@@ -2071,7 +2071,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
51803 int err;
51804
51805 ihost = shost->shost_data;
51806- session->sid = atomic_add_return(1, &iscsi_session_nr);
51807+ session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
51808
51809 if (target_id == ISCSI_MAX_TARGET) {
51810 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
51811@@ -4515,7 +4515,7 @@ static __init int iscsi_transport_init(void)
51812 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
51813 ISCSI_TRANSPORT_VERSION);
51814
51815- atomic_set(&iscsi_session_nr, 0);
51816+ atomic_set_unchecked(&iscsi_session_nr, 0);
51817
51818 err = class_register(&iscsi_transport_class);
51819 if (err)
51820diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
51821index ae45bd9..c32a586 100644
51822--- a/drivers/scsi/scsi_transport_srp.c
51823+++ b/drivers/scsi/scsi_transport_srp.c
51824@@ -35,7 +35,7 @@
51825 #include "scsi_priv.h"
51826
51827 struct srp_host_attrs {
51828- atomic_t next_port_id;
51829+ atomic_unchecked_t next_port_id;
51830 };
51831 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
51832
51833@@ -100,7 +100,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
51834 struct Scsi_Host *shost = dev_to_shost(dev);
51835 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
51836
51837- atomic_set(&srp_host->next_port_id, 0);
51838+ atomic_set_unchecked(&srp_host->next_port_id, 0);
51839 return 0;
51840 }
51841
51842@@ -734,7 +734,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
51843 rport_fast_io_fail_timedout);
51844 INIT_DELAYED_WORK(&rport->dev_loss_work, rport_dev_loss_timedout);
51845
51846- id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
51847+ id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
51848 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
51849
51850 transport_setup_device(&rport->dev);
51851diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
51852index cfba74c..415f09b 100644
51853--- a/drivers/scsi/sd.c
51854+++ b/drivers/scsi/sd.c
51855@@ -3022,7 +3022,7 @@ static int sd_probe(struct device *dev)
51856 sdkp->disk = gd;
51857 sdkp->index = index;
51858 atomic_set(&sdkp->openers, 0);
51859- atomic_set(&sdkp->device->ioerr_cnt, 0);
51860+ atomic_set_unchecked(&sdkp->device->ioerr_cnt, 0);
51861
51862 if (!sdp->request_queue->rq_timeout) {
51863 if (sdp->type != TYPE_MOD)
51864diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
51865index 6035444..c82edd4 100644
51866--- a/drivers/scsi/sg.c
51867+++ b/drivers/scsi/sg.c
51868@@ -1138,7 +1138,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
51869 sdp->disk->disk_name,
51870 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
51871 NULL,
51872- (char *)arg);
51873+ (char __user *)arg);
51874 case BLKTRACESTART:
51875 return blk_trace_startstop(sdp->device->request_queue, 1);
51876 case BLKTRACESTOP:
51877diff --git a/drivers/soc/tegra/fuse/fuse-tegra.c b/drivers/soc/tegra/fuse/fuse-tegra.c
51878index 11a5043..e36f04c 100644
51879--- a/drivers/soc/tegra/fuse/fuse-tegra.c
51880+++ b/drivers/soc/tegra/fuse/fuse-tegra.c
51881@@ -70,7 +70,7 @@ static ssize_t fuse_read(struct file *fd, struct kobject *kobj,
51882 return i;
51883 }
51884
51885-static struct bin_attribute fuse_bin_attr = {
51886+static bin_attribute_no_const fuse_bin_attr = {
51887 .attr = { .name = "fuse", .mode = S_IRUGO, },
51888 .read = fuse_read,
51889 };
51890diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
51891index 50f20f2..6bd81e0 100644
51892--- a/drivers/spi/spi.c
51893+++ b/drivers/spi/spi.c
51894@@ -2224,7 +2224,7 @@ int spi_bus_unlock(struct spi_master *master)
51895 EXPORT_SYMBOL_GPL(spi_bus_unlock);
51896
51897 /* portable code must never pass more than 32 bytes */
51898-#define SPI_BUFSIZ max(32, SMP_CACHE_BYTES)
51899+#define SPI_BUFSIZ max(32UL, SMP_CACHE_BYTES)
51900
51901 static u8 *buf;
51902
51903diff --git a/drivers/staging/android/timed_output.c b/drivers/staging/android/timed_output.c
51904index b41429f..2de5373 100644
51905--- a/drivers/staging/android/timed_output.c
51906+++ b/drivers/staging/android/timed_output.c
51907@@ -25,7 +25,7 @@
51908 #include "timed_output.h"
51909
51910 static struct class *timed_output_class;
51911-static atomic_t device_count;
51912+static atomic_unchecked_t device_count;
51913
51914 static ssize_t enable_show(struct device *dev, struct device_attribute *attr,
51915 char *buf)
51916@@ -65,7 +65,7 @@ static int create_timed_output_class(void)
51917 timed_output_class = class_create(THIS_MODULE, "timed_output");
51918 if (IS_ERR(timed_output_class))
51919 return PTR_ERR(timed_output_class);
51920- atomic_set(&device_count, 0);
51921+ atomic_set_unchecked(&device_count, 0);
51922 timed_output_class->dev_groups = timed_output_groups;
51923 }
51924
51925@@ -83,7 +83,7 @@ int timed_output_dev_register(struct timed_output_dev *tdev)
51926 if (ret < 0)
51927 return ret;
51928
51929- tdev->index = atomic_inc_return(&device_count);
51930+ tdev->index = atomic_inc_return_unchecked(&device_count);
51931 tdev->dev = device_create(timed_output_class, NULL,
51932 MKDEV(0, tdev->index), NULL, "%s", tdev->name);
51933 if (IS_ERR(tdev->dev))
51934diff --git a/drivers/staging/gdm724x/gdm_tty.c b/drivers/staging/gdm724x/gdm_tty.c
51935index 001348c..cfaac8a 100644
51936--- a/drivers/staging/gdm724x/gdm_tty.c
51937+++ b/drivers/staging/gdm724x/gdm_tty.c
51938@@ -44,7 +44,7 @@
51939 #define gdm_tty_send_control(n, r, v, d, l) (\
51940 n->tty_dev->send_control(n->tty_dev->priv_dev, r, v, d, l))
51941
51942-#define GDM_TTY_READY(gdm) (gdm && gdm->tty_dev && gdm->port.count)
51943+#define GDM_TTY_READY(gdm) (gdm && gdm->tty_dev && atomic_read(&gdm->port.count))
51944
51945 static struct tty_driver *gdm_driver[TTY_MAX_COUNT];
51946 static struct gdm *gdm_table[TTY_MAX_COUNT][GDM_TTY_MINOR];
51947diff --git a/drivers/staging/imx-drm/imx-drm-core.c b/drivers/staging/imx-drm/imx-drm-core.c
51948index 9cb222e..8766f26 100644
51949--- a/drivers/staging/imx-drm/imx-drm-core.c
51950+++ b/drivers/staging/imx-drm/imx-drm-core.c
51951@@ -357,7 +357,7 @@ int imx_drm_add_crtc(struct drm_device *drm, struct drm_crtc *crtc,
51952 if (imxdrm->pipes >= MAX_CRTC)
51953 return -EINVAL;
51954
51955- if (imxdrm->drm->open_count)
51956+ if (local_read(&imxdrm->drm->open_count))
51957 return -EBUSY;
51958
51959 imx_drm_crtc = kzalloc(sizeof(*imx_drm_crtc), GFP_KERNEL);
51960diff --git a/drivers/staging/line6/driver.c b/drivers/staging/line6/driver.c
51961index 503b2d7..c918745 100644
51962--- a/drivers/staging/line6/driver.c
51963+++ b/drivers/staging/line6/driver.c
51964@@ -463,7 +463,7 @@ int line6_read_data(struct usb_line6 *line6, int address, void *data,
51965 {
51966 struct usb_device *usbdev = line6->usbdev;
51967 int ret;
51968- unsigned char len;
51969+ unsigned char *plen;
51970
51971 /* query the serial number: */
51972 ret = usb_control_msg(usbdev, usb_sndctrlpipe(usbdev, 0), 0x67,
51973@@ -476,27 +476,34 @@ int line6_read_data(struct usb_line6 *line6, int address, void *data,
51974 return ret;
51975 }
51976
51977+ plen = kmalloc(1, GFP_KERNEL);
51978+ if (plen == NULL)
51979+ return -ENOMEM;
51980+
51981 /* Wait for data length. We'll get 0xff until length arrives. */
51982 do {
51983 ret = usb_control_msg(usbdev, usb_rcvctrlpipe(usbdev, 0), 0x67,
51984 USB_TYPE_VENDOR | USB_RECIP_DEVICE |
51985 USB_DIR_IN,
51986- 0x0012, 0x0000, &len, 1,
51987+ 0x0012, 0x0000, plen, 1,
51988 LINE6_TIMEOUT * HZ);
51989 if (ret < 0) {
51990 dev_err(line6->ifcdev,
51991 "receive length failed (error %d)\n", ret);
51992+ kfree(plen);
51993 return ret;
51994 }
51995- } while (len == 0xff);
51996+ } while (*plen == 0xff);
51997
51998- if (len != datalen) {
51999+ if (*plen != datalen) {
52000 /* should be equal or something went wrong */
52001 dev_err(line6->ifcdev,
52002 "length mismatch (expected %d, got %d)\n",
52003- (int)datalen, (int)len);
52004+ (int)datalen, (int)*plen);
52005+ kfree(plen);
52006 return -EINVAL;
52007 }
52008+ kfree(plen);
52009
52010 /* receive the result: */
52011 ret = usb_control_msg(usbdev, usb_rcvctrlpipe(usbdev, 0), 0x67,
52012diff --git a/drivers/staging/lustre/lnet/selftest/brw_test.c b/drivers/staging/lustre/lnet/selftest/brw_test.c
52013index a94f336..6a1924d 100644
52014--- a/drivers/staging/lustre/lnet/selftest/brw_test.c
52015+++ b/drivers/staging/lustre/lnet/selftest/brw_test.c
52016@@ -488,13 +488,11 @@ brw_server_handle(struct srpc_server_rpc *rpc)
52017 return 0;
52018 }
52019
52020-sfw_test_client_ops_t brw_test_client;
52021-void brw_init_test_client(void)
52022-{
52023- brw_test_client.tso_init = brw_client_init;
52024- brw_test_client.tso_fini = brw_client_fini;
52025- brw_test_client.tso_prep_rpc = brw_client_prep_rpc;
52026- brw_test_client.tso_done_rpc = brw_client_done_rpc;
52027+sfw_test_client_ops_t brw_test_client = {
52028+ .tso_init = brw_client_init,
52029+ .tso_fini = brw_client_fini,
52030+ .tso_prep_rpc = brw_client_prep_rpc,
52031+ .tso_done_rpc = brw_client_done_rpc,
52032 };
52033
52034 srpc_service_t brw_test_service;
52035diff --git a/drivers/staging/lustre/lnet/selftest/framework.c b/drivers/staging/lustre/lnet/selftest/framework.c
52036index df04ab7..1deb1ac 100644
52037--- a/drivers/staging/lustre/lnet/selftest/framework.c
52038+++ b/drivers/staging/lustre/lnet/selftest/framework.c
52039@@ -1632,12 +1632,10 @@ static srpc_service_t sfw_services[] = {
52040
52041 extern sfw_test_client_ops_t ping_test_client;
52042 extern srpc_service_t ping_test_service;
52043-extern void ping_init_test_client(void);
52044 extern void ping_init_test_service(void);
52045
52046 extern sfw_test_client_ops_t brw_test_client;
52047 extern srpc_service_t brw_test_service;
52048-extern void brw_init_test_client(void);
52049 extern void brw_init_test_service(void);
52050
52051
52052@@ -1681,12 +1679,10 @@ sfw_startup (void)
52053 INIT_LIST_HEAD(&sfw_data.fw_zombie_rpcs);
52054 INIT_LIST_HEAD(&sfw_data.fw_zombie_sessions);
52055
52056- brw_init_test_client();
52057 brw_init_test_service();
52058 rc = sfw_register_test(&brw_test_service, &brw_test_client);
52059 LASSERT (rc == 0);
52060
52061- ping_init_test_client();
52062 ping_init_test_service();
52063 rc = sfw_register_test(&ping_test_service, &ping_test_client);
52064 LASSERT (rc == 0);
52065diff --git a/drivers/staging/lustre/lnet/selftest/ping_test.c b/drivers/staging/lustre/lnet/selftest/ping_test.c
52066index 750cac4..e4d751f 100644
52067--- a/drivers/staging/lustre/lnet/selftest/ping_test.c
52068+++ b/drivers/staging/lustre/lnet/selftest/ping_test.c
52069@@ -211,14 +211,12 @@ ping_server_handle(struct srpc_server_rpc *rpc)
52070 return 0;
52071 }
52072
52073-sfw_test_client_ops_t ping_test_client;
52074-void ping_init_test_client(void)
52075-{
52076- ping_test_client.tso_init = ping_client_init;
52077- ping_test_client.tso_fini = ping_client_fini;
52078- ping_test_client.tso_prep_rpc = ping_client_prep_rpc;
52079- ping_test_client.tso_done_rpc = ping_client_done_rpc;
52080-}
52081+sfw_test_client_ops_t ping_test_client = {
52082+ .tso_init = ping_client_init,
52083+ .tso_fini = ping_client_fini,
52084+ .tso_prep_rpc = ping_client_prep_rpc,
52085+ .tso_done_rpc = ping_client_done_rpc,
52086+};
52087
52088 srpc_service_t ping_test_service;
52089 void ping_init_test_service(void)
52090diff --git a/drivers/staging/lustre/lustre/include/lustre_dlm.h b/drivers/staging/lustre/lustre/include/lustre_dlm.h
52091index 14ac46f..eca2c16 100644
52092--- a/drivers/staging/lustre/lustre/include/lustre_dlm.h
52093+++ b/drivers/staging/lustre/lustre/include/lustre_dlm.h
52094@@ -1139,7 +1139,7 @@ struct ldlm_callback_suite {
52095 ldlm_completion_callback lcs_completion;
52096 ldlm_blocking_callback lcs_blocking;
52097 ldlm_glimpse_callback lcs_glimpse;
52098-};
52099+} __no_const;
52100
52101 /* ldlm_lockd.c */
52102 int ldlm_del_waiting_lock(struct ldlm_lock *lock);
52103diff --git a/drivers/staging/lustre/lustre/include/obd.h b/drivers/staging/lustre/lustre/include/obd.h
52104index 2a88b80..62e7e5f 100644
52105--- a/drivers/staging/lustre/lustre/include/obd.h
52106+++ b/drivers/staging/lustre/lustre/include/obd.h
52107@@ -1362,7 +1362,7 @@ struct md_ops {
52108 * lprocfs_alloc_md_stats() in obdclass/lprocfs_status.c. Also, add a
52109 * wrapper function in include/linux/obd_class.h.
52110 */
52111-};
52112+} __no_const;
52113
52114 struct lsm_operations {
52115 void (*lsm_free)(struct lov_stripe_md *);
52116diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c b/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
52117index b798daa..b28ca8f 100644
52118--- a/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
52119+++ b/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
52120@@ -258,7 +258,7 @@ ldlm_process_flock_lock(struct ldlm_lock *req, __u64 *flags, int first_enq,
52121 int added = (mode == LCK_NL);
52122 int overlaps = 0;
52123 int splitted = 0;
52124- const struct ldlm_callback_suite null_cbs = { NULL };
52125+ const struct ldlm_callback_suite null_cbs = { };
52126
52127 CDEBUG(D_DLMTRACE, "flags %#llx owner %llu pid %u mode %u start %llu end %llu\n",
52128 *flags, new->l_policy_data.l_flock.owner,
52129diff --git a/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c b/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
52130index bbe2c68..c6b4275 100644
52131--- a/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
52132+++ b/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
52133@@ -236,7 +236,7 @@ int proc_console_max_delay_cs(struct ctl_table *table, int write,
52134 void __user *buffer, size_t *lenp, loff_t *ppos)
52135 {
52136 int rc, max_delay_cs;
52137- struct ctl_table dummy = *table;
52138+ ctl_table_no_const dummy = *table;
52139 long d;
52140
52141 dummy.data = &max_delay_cs;
52142@@ -268,7 +268,7 @@ int proc_console_min_delay_cs(struct ctl_table *table, int write,
52143 void __user *buffer, size_t *lenp, loff_t *ppos)
52144 {
52145 int rc, min_delay_cs;
52146- struct ctl_table dummy = *table;
52147+ ctl_table_no_const dummy = *table;
52148 long d;
52149
52150 dummy.data = &min_delay_cs;
52151@@ -300,7 +300,7 @@ int proc_console_backoff(struct ctl_table *table, int write,
52152 void __user *buffer, size_t *lenp, loff_t *ppos)
52153 {
52154 int rc, backoff;
52155- struct ctl_table dummy = *table;
52156+ ctl_table_no_const dummy = *table;
52157
52158 dummy.data = &backoff;
52159 dummy.proc_handler = &proc_dointvec;
52160diff --git a/drivers/staging/lustre/lustre/libcfs/module.c b/drivers/staging/lustre/lustre/libcfs/module.c
52161index 2c4fc74..b04ca79 100644
52162--- a/drivers/staging/lustre/lustre/libcfs/module.c
52163+++ b/drivers/staging/lustre/lustre/libcfs/module.c
52164@@ -315,11 +315,11 @@ out:
52165
52166
52167 struct cfs_psdev_ops libcfs_psdev_ops = {
52168- libcfs_psdev_open,
52169- libcfs_psdev_release,
52170- NULL,
52171- NULL,
52172- libcfs_ioctl
52173+ .p_open = libcfs_psdev_open,
52174+ .p_close = libcfs_psdev_release,
52175+ .p_read = NULL,
52176+ .p_write = NULL,
52177+ .p_ioctl = libcfs_ioctl
52178 };
52179
52180 extern int insert_proc(void);
52181diff --git a/drivers/staging/lustre/lustre/llite/dir.c b/drivers/staging/lustre/lustre/llite/dir.c
52182index b0bb709..0117c96 100644
52183--- a/drivers/staging/lustre/lustre/llite/dir.c
52184+++ b/drivers/staging/lustre/lustre/llite/dir.c
52185@@ -661,7 +661,7 @@ int ll_dir_setdirstripe(struct inode *dir, struct lmv_user_md *lump,
52186 int mode;
52187 int err;
52188
52189- mode = (0755 & (S_IRWXUGO|S_ISVTX) & ~current->fs->umask) | S_IFDIR;
52190+ mode = (0755 & (S_IRWXUGO|S_ISVTX) & ~current_umask()) | S_IFDIR;
52191 op_data = ll_prep_md_op_data(NULL, dir, NULL, filename,
52192 strlen(filename), mode, LUSTRE_OPC_MKDIR,
52193 lump);
52194diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
52195index b2b6c3c..302e4e4 100644
52196--- a/drivers/staging/octeon/ethernet-rx.c
52197+++ b/drivers/staging/octeon/ethernet-rx.c
52198@@ -416,11 +416,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
52199 /* Increment RX stats for virtual ports */
52200 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
52201 #ifdef CONFIG_64BIT
52202- atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
52203- atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
52204+ atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
52205+ atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
52206 #else
52207- atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
52208- atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
52209+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
52210+ atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
52211 #endif
52212 }
52213 netif_receive_skb(skb);
52214@@ -431,9 +431,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
52215 dev->name);
52216 */
52217 #ifdef CONFIG_64BIT
52218- atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
52219+ atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
52220 #else
52221- atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
52222+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
52223 #endif
52224 dev_kfree_skb_irq(skb);
52225 }
52226diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
52227index 8f9e3fb..d283fb9 100644
52228--- a/drivers/staging/octeon/ethernet.c
52229+++ b/drivers/staging/octeon/ethernet.c
52230@@ -247,11 +247,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
52231 * since the RX tasklet also increments it.
52232 */
52233 #ifdef CONFIG_64BIT
52234- atomic64_add(rx_status.dropped_packets,
52235- (atomic64_t *)&priv->stats.rx_dropped);
52236+ atomic64_add_unchecked(rx_status.dropped_packets,
52237+ (atomic64_unchecked_t *)&priv->stats.rx_dropped);
52238 #else
52239- atomic_add(rx_status.dropped_packets,
52240- (atomic_t *)&priv->stats.rx_dropped);
52241+ atomic_add_unchecked(rx_status.dropped_packets,
52242+ (atomic_unchecked_t *)&priv->stats.rx_dropped);
52243 #endif
52244 }
52245
52246diff --git a/drivers/staging/rtl8188eu/include/hal_intf.h b/drivers/staging/rtl8188eu/include/hal_intf.h
52247index 9191993..30e9817 100644
52248--- a/drivers/staging/rtl8188eu/include/hal_intf.h
52249+++ b/drivers/staging/rtl8188eu/include/hal_intf.h
52250@@ -225,7 +225,7 @@ struct hal_ops {
52251
52252 void (*hal_notch_filter)(struct adapter *adapter, bool enable);
52253 void (*hal_reset_security_engine)(struct adapter *adapter);
52254-};
52255+} __no_const;
52256
52257 enum rt_eeprom_type {
52258 EEPROM_93C46,
52259diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
52260index 070cc03..6806e37 100644
52261--- a/drivers/staging/rtl8712/rtl871x_io.h
52262+++ b/drivers/staging/rtl8712/rtl871x_io.h
52263@@ -108,7 +108,7 @@ struct _io_ops {
52264 u8 *pmem);
52265 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
52266 u8 *pmem);
52267-};
52268+} __no_const;
52269
52270 struct io_req {
52271 struct list_head list;
52272diff --git a/drivers/staging/unisys/visorchipset/visorchipset.h b/drivers/staging/unisys/visorchipset/visorchipset.h
52273index 2bf2e2f..84421c9 100644
52274--- a/drivers/staging/unisys/visorchipset/visorchipset.h
52275+++ b/drivers/staging/unisys/visorchipset/visorchipset.h
52276@@ -228,7 +228,7 @@ typedef struct {
52277 void (*device_resume)(ulong busNo, ulong devNo);
52278 int (*get_channel_info)(uuid_le typeGuid, ulong *minSize,
52279 ulong *maxSize);
52280-} VISORCHIPSET_BUSDEV_NOTIFIERS;
52281+} __no_const VISORCHIPSET_BUSDEV_NOTIFIERS;
52282
52283 /* These functions live inside visorchipset, and will be called to indicate
52284 * responses to specific events (by code outside of visorchipset).
52285@@ -243,7 +243,7 @@ typedef struct {
52286 void (*device_destroy)(ulong busNo, ulong devNo, int response);
52287 void (*device_pause)(ulong busNo, ulong devNo, int response);
52288 void (*device_resume)(ulong busNo, ulong devNo, int response);
52289-} VISORCHIPSET_BUSDEV_RESPONDERS;
52290+} __no_const VISORCHIPSET_BUSDEV_RESPONDERS;
52291
52292 /** Register functions (in the bus driver) to get called by visorchipset
52293 * whenever a bus or device appears for which this service partition is
52294diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
52295index ae0dade..803d53a 100644
52296--- a/drivers/staging/vt6655/hostap.c
52297+++ b/drivers/staging/vt6655/hostap.c
52298@@ -65,14 +65,13 @@
52299 *
52300 */
52301
52302+static net_device_ops_no_const apdev_netdev_ops;
52303+
52304 static int hostap_enable_hostapd(struct vnt_private *pDevice, int rtnl_locked)
52305 {
52306 struct vnt_private *apdev_priv;
52307 struct net_device *dev = pDevice->dev;
52308 int ret;
52309- const struct net_device_ops apdev_netdev_ops = {
52310- .ndo_start_xmit = pDevice->tx_80211,
52311- };
52312
52313 pr_debug("%s: Enabling hostapd mode\n", dev->name);
52314
52315@@ -84,6 +83,8 @@ static int hostap_enable_hostapd(struct vnt_private *pDevice, int rtnl_locked)
52316 *apdev_priv = *pDevice;
52317 eth_hw_addr_inherit(pDevice->apdev, dev);
52318
52319+ /* only half broken now */
52320+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
52321 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
52322
52323 pDevice->apdev->type = ARPHRD_IEEE80211;
52324diff --git a/drivers/target/sbp/sbp_target.c b/drivers/target/sbp/sbp_target.c
52325index e7e9372..161f530 100644
52326--- a/drivers/target/sbp/sbp_target.c
52327+++ b/drivers/target/sbp/sbp_target.c
52328@@ -62,7 +62,7 @@ static const u32 sbp_unit_directory_template[] = {
52329
52330 #define SESSION_MAINTENANCE_INTERVAL HZ
52331
52332-static atomic_t login_id = ATOMIC_INIT(0);
52333+static atomic_unchecked_t login_id = ATOMIC_INIT(0);
52334
52335 static void session_maintenance_work(struct work_struct *);
52336 static int sbp_run_transaction(struct fw_card *, int, int, int, int,
52337@@ -444,7 +444,7 @@ static void sbp_management_request_login(
52338 login->lun = se_lun;
52339 login->status_fifo_addr = sbp2_pointer_to_addr(&req->orb.status_fifo);
52340 login->exclusive = LOGIN_ORB_EXCLUSIVE(be32_to_cpu(req->orb.misc));
52341- login->login_id = atomic_inc_return(&login_id);
52342+ login->login_id = atomic_inc_return_unchecked(&login_id);
52343
52344 login->tgt_agt = sbp_target_agent_register(login);
52345 if (IS_ERR(login->tgt_agt)) {
52346diff --git a/drivers/target/target_core_device.c b/drivers/target/target_core_device.c
52347index c45f9e9..00e85f0 100644
52348--- a/drivers/target/target_core_device.c
52349+++ b/drivers/target/target_core_device.c
52350@@ -1532,7 +1532,7 @@ struct se_device *target_alloc_device(struct se_hba *hba, const char *name)
52351 spin_lock_init(&dev->se_tmr_lock);
52352 spin_lock_init(&dev->qf_cmd_lock);
52353 sema_init(&dev->caw_sem, 1);
52354- atomic_set(&dev->dev_ordered_id, 0);
52355+ atomic_set_unchecked(&dev->dev_ordered_id, 0);
52356 INIT_LIST_HEAD(&dev->t10_wwn.t10_vpd_list);
52357 spin_lock_init(&dev->t10_wwn.t10_vpd_lock);
52358 INIT_LIST_HEAD(&dev->t10_pr.registration_list);
52359diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
52360index be877bf..7be9cd4 100644
52361--- a/drivers/target/target_core_transport.c
52362+++ b/drivers/target/target_core_transport.c
52363@@ -1168,7 +1168,7 @@ transport_check_alloc_task_attr(struct se_cmd *cmd)
52364 * Used to determine when ORDERED commands should go from
52365 * Dormant to Active status.
52366 */
52367- cmd->se_ordered_id = atomic_inc_return(&dev->dev_ordered_id);
52368+ cmd->se_ordered_id = atomic_inc_return_unchecked(&dev->dev_ordered_id);
52369 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
52370 cmd->se_ordered_id, cmd->sam_task_attr,
52371 dev->transport->name);
52372diff --git a/drivers/thermal/int340x_thermal/int3400_thermal.c b/drivers/thermal/int340x_thermal/int3400_thermal.c
52373index edc1cce..769e4cb 100644
52374--- a/drivers/thermal/int340x_thermal/int3400_thermal.c
52375+++ b/drivers/thermal/int340x_thermal/int3400_thermal.c
52376@@ -209,8 +209,10 @@ static int int3400_thermal_probe(struct platform_device *pdev)
52377 platform_set_drvdata(pdev, priv);
52378
52379 if (priv->uuid_bitmap & 1 << INT3400_THERMAL_PASSIVE_1) {
52380- int3400_thermal_ops.get_mode = int3400_thermal_get_mode;
52381- int3400_thermal_ops.set_mode = int3400_thermal_set_mode;
52382+ pax_open_kernel();
52383+ *(void **)&int3400_thermal_ops.get_mode = int3400_thermal_get_mode;
52384+ *(void **)&int3400_thermal_ops.set_mode = int3400_thermal_set_mode;
52385+ pax_close_kernel();
52386 }
52387 priv->thermal = thermal_zone_device_register("INT3400 Thermal", 0, 0,
52388 priv, &int3400_thermal_ops,
52389diff --git a/drivers/thermal/of-thermal.c b/drivers/thermal/of-thermal.c
52390index 62143ba..ae21165 100644
52391--- a/drivers/thermal/of-thermal.c
52392+++ b/drivers/thermal/of-thermal.c
52393@@ -30,6 +30,7 @@
52394 #include <linux/err.h>
52395 #include <linux/export.h>
52396 #include <linux/string.h>
52397+#include <linux/mm.h>
52398
52399 #include "thermal_core.h"
52400
52401@@ -341,8 +342,10 @@ thermal_zone_of_add_sensor(struct device_node *zone,
52402 tz->get_trend = get_trend;
52403 tz->sensor_data = data;
52404
52405- tzd->ops->get_temp = of_thermal_get_temp;
52406- tzd->ops->get_trend = of_thermal_get_trend;
52407+ pax_open_kernel();
52408+ *(void **)&tzd->ops->get_temp = of_thermal_get_temp;
52409+ *(void **)&tzd->ops->get_trend = of_thermal_get_trend;
52410+ pax_close_kernel();
52411 mutex_unlock(&tzd->lock);
52412
52413 return tzd;
52414@@ -473,8 +476,10 @@ void thermal_zone_of_sensor_unregister(struct device *dev,
52415 return;
52416
52417 mutex_lock(&tzd->lock);
52418- tzd->ops->get_temp = NULL;
52419- tzd->ops->get_trend = NULL;
52420+ pax_open_kernel();
52421+ *(void **)&tzd->ops->get_temp = NULL;
52422+ *(void **)&tzd->ops->get_trend = NULL;
52423+ pax_close_kernel();
52424
52425 tz->get_temp = NULL;
52426 tz->get_trend = NULL;
52427diff --git a/drivers/tty/cyclades.c b/drivers/tty/cyclades.c
52428index fd66f57..48e6376 100644
52429--- a/drivers/tty/cyclades.c
52430+++ b/drivers/tty/cyclades.c
52431@@ -1570,10 +1570,10 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
52432 printk(KERN_DEBUG "cyc:cy_open ttyC%d, count = %d\n", info->line,
52433 info->port.count);
52434 #endif
52435- info->port.count++;
52436+ atomic_inc(&info->port.count);
52437 #ifdef CY_DEBUG_COUNT
52438 printk(KERN_DEBUG "cyc:cy_open (%d): incrementing count to %d\n",
52439- current->pid, info->port.count);
52440+ current->pid, atomic_read(&info->port.count));
52441 #endif
52442
52443 /*
52444@@ -3974,7 +3974,7 @@ static int cyclades_proc_show(struct seq_file *m, void *v)
52445 for (j = 0; j < cy_card[i].nports; j++) {
52446 info = &cy_card[i].ports[j];
52447
52448- if (info->port.count) {
52449+ if (atomic_read(&info->port.count)) {
52450 /* XXX is the ldisc num worth this? */
52451 struct tty_struct *tty;
52452 struct tty_ldisc *ld;
52453diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
52454index 4fcec1d..5a036f7 100644
52455--- a/drivers/tty/hvc/hvc_console.c
52456+++ b/drivers/tty/hvc/hvc_console.c
52457@@ -342,7 +342,7 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
52458
52459 spin_lock_irqsave(&hp->port.lock, flags);
52460 /* Check and then increment for fast path open. */
52461- if (hp->port.count++ > 0) {
52462+ if (atomic_inc_return(&hp->port.count) > 1) {
52463 spin_unlock_irqrestore(&hp->port.lock, flags);
52464 hvc_kick();
52465 return 0;
52466@@ -397,7 +397,7 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
52467
52468 spin_lock_irqsave(&hp->port.lock, flags);
52469
52470- if (--hp->port.count == 0) {
52471+ if (atomic_dec_return(&hp->port.count) == 0) {
52472 spin_unlock_irqrestore(&hp->port.lock, flags);
52473 /* We are done with the tty pointer now. */
52474 tty_port_tty_set(&hp->port, NULL);
52475@@ -419,9 +419,9 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
52476 */
52477 tty_wait_until_sent_from_close(tty, HVC_CLOSE_WAIT);
52478 } else {
52479- if (hp->port.count < 0)
52480+ if (atomic_read(&hp->port.count) < 0)
52481 printk(KERN_ERR "hvc_close %X: oops, count is %d\n",
52482- hp->vtermno, hp->port.count);
52483+ hp->vtermno, atomic_read(&hp->port.count));
52484 spin_unlock_irqrestore(&hp->port.lock, flags);
52485 }
52486 }
52487@@ -451,12 +451,12 @@ static void hvc_hangup(struct tty_struct *tty)
52488 * open->hangup case this can be called after the final close so prevent
52489 * that from happening for now.
52490 */
52491- if (hp->port.count <= 0) {
52492+ if (atomic_read(&hp->port.count) <= 0) {
52493 spin_unlock_irqrestore(&hp->port.lock, flags);
52494 return;
52495 }
52496
52497- hp->port.count = 0;
52498+ atomic_set(&hp->port.count, 0);
52499 spin_unlock_irqrestore(&hp->port.lock, flags);
52500 tty_port_tty_set(&hp->port, NULL);
52501
52502@@ -504,7 +504,7 @@ static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count
52503 return -EPIPE;
52504
52505 /* FIXME what's this (unprotected) check for? */
52506- if (hp->port.count <= 0)
52507+ if (atomic_read(&hp->port.count) <= 0)
52508 return -EIO;
52509
52510 spin_lock_irqsave(&hp->lock, flags);
52511diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
52512index 81e939e..95ead10 100644
52513--- a/drivers/tty/hvc/hvcs.c
52514+++ b/drivers/tty/hvc/hvcs.c
52515@@ -83,6 +83,7 @@
52516 #include <asm/hvcserver.h>
52517 #include <asm/uaccess.h>
52518 #include <asm/vio.h>
52519+#include <asm/local.h>
52520
52521 /*
52522 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
52523@@ -416,7 +417,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
52524
52525 spin_lock_irqsave(&hvcsd->lock, flags);
52526
52527- if (hvcsd->port.count > 0) {
52528+ if (atomic_read(&hvcsd->port.count) > 0) {
52529 spin_unlock_irqrestore(&hvcsd->lock, flags);
52530 printk(KERN_INFO "HVCS: vterm state unchanged. "
52531 "The hvcs device node is still in use.\n");
52532@@ -1127,7 +1128,7 @@ static int hvcs_install(struct tty_driver *driver, struct tty_struct *tty)
52533 }
52534 }
52535
52536- hvcsd->port.count = 0;
52537+ atomic_set(&hvcsd->port.count, 0);
52538 hvcsd->port.tty = tty;
52539 tty->driver_data = hvcsd;
52540
52541@@ -1180,7 +1181,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
52542 unsigned long flags;
52543
52544 spin_lock_irqsave(&hvcsd->lock, flags);
52545- hvcsd->port.count++;
52546+ atomic_inc(&hvcsd->port.count);
52547 hvcsd->todo_mask |= HVCS_SCHED_READ;
52548 spin_unlock_irqrestore(&hvcsd->lock, flags);
52549
52550@@ -1216,7 +1217,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
52551 hvcsd = tty->driver_data;
52552
52553 spin_lock_irqsave(&hvcsd->lock, flags);
52554- if (--hvcsd->port.count == 0) {
52555+ if (atomic_dec_and_test(&hvcsd->port.count)) {
52556
52557 vio_disable_interrupts(hvcsd->vdev);
52558
52559@@ -1241,10 +1242,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
52560
52561 free_irq(irq, hvcsd);
52562 return;
52563- } else if (hvcsd->port.count < 0) {
52564+ } else if (atomic_read(&hvcsd->port.count) < 0) {
52565 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
52566 " is missmanaged.\n",
52567- hvcsd->vdev->unit_address, hvcsd->port.count);
52568+ hvcsd->vdev->unit_address, atomic_read(&hvcsd->port.count));
52569 }
52570
52571 spin_unlock_irqrestore(&hvcsd->lock, flags);
52572@@ -1266,7 +1267,7 @@ static void hvcs_hangup(struct tty_struct * tty)
52573
52574 spin_lock_irqsave(&hvcsd->lock, flags);
52575 /* Preserve this so that we know how many kref refs to put */
52576- temp_open_count = hvcsd->port.count;
52577+ temp_open_count = atomic_read(&hvcsd->port.count);
52578
52579 /*
52580 * Don't kref put inside the spinlock because the destruction
52581@@ -1281,7 +1282,7 @@ static void hvcs_hangup(struct tty_struct * tty)
52582 tty->driver_data = NULL;
52583 hvcsd->port.tty = NULL;
52584
52585- hvcsd->port.count = 0;
52586+ atomic_set(&hvcsd->port.count, 0);
52587
52588 /* This will drop any buffered data on the floor which is OK in a hangup
52589 * scenario. */
52590@@ -1352,7 +1353,7 @@ static int hvcs_write(struct tty_struct *tty,
52591 * the middle of a write operation? This is a crummy place to do this
52592 * but we want to keep it all in the spinlock.
52593 */
52594- if (hvcsd->port.count <= 0) {
52595+ if (atomic_read(&hvcsd->port.count) <= 0) {
52596 spin_unlock_irqrestore(&hvcsd->lock, flags);
52597 return -ENODEV;
52598 }
52599@@ -1426,7 +1427,7 @@ static int hvcs_write_room(struct tty_struct *tty)
52600 {
52601 struct hvcs_struct *hvcsd = tty->driver_data;
52602
52603- if (!hvcsd || hvcsd->port.count <= 0)
52604+ if (!hvcsd || atomic_read(&hvcsd->port.count) <= 0)
52605 return 0;
52606
52607 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
52608diff --git a/drivers/tty/hvc/hvsi.c b/drivers/tty/hvc/hvsi.c
52609index 4190199..06d5bfa 100644
52610--- a/drivers/tty/hvc/hvsi.c
52611+++ b/drivers/tty/hvc/hvsi.c
52612@@ -85,7 +85,7 @@ struct hvsi_struct {
52613 int n_outbuf;
52614 uint32_t vtermno;
52615 uint32_t virq;
52616- atomic_t seqno; /* HVSI packet sequence number */
52617+ atomic_unchecked_t seqno; /* HVSI packet sequence number */
52618 uint16_t mctrl;
52619 uint8_t state; /* HVSI protocol state */
52620 uint8_t flags;
52621@@ -295,7 +295,7 @@ static int hvsi_version_respond(struct hvsi_struct *hp, uint16_t query_seqno)
52622
52623 packet.hdr.type = VS_QUERY_RESPONSE_PACKET_HEADER;
52624 packet.hdr.len = sizeof(struct hvsi_query_response);
52625- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
52626+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
52627 packet.verb = VSV_SEND_VERSION_NUMBER;
52628 packet.u.version = HVSI_VERSION;
52629 packet.query_seqno = query_seqno+1;
52630@@ -555,7 +555,7 @@ static int hvsi_query(struct hvsi_struct *hp, uint16_t verb)
52631
52632 packet.hdr.type = VS_QUERY_PACKET_HEADER;
52633 packet.hdr.len = sizeof(struct hvsi_query);
52634- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
52635+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
52636 packet.verb = verb;
52637
52638 pr_debug("%s: sending %i bytes\n", __func__, packet.hdr.len);
52639@@ -597,7 +597,7 @@ static int hvsi_set_mctrl(struct hvsi_struct *hp, uint16_t mctrl)
52640 int wrote;
52641
52642 packet.hdr.type = VS_CONTROL_PACKET_HEADER,
52643- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
52644+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
52645 packet.hdr.len = sizeof(struct hvsi_control);
52646 packet.verb = VSV_SET_MODEM_CTL;
52647 packet.mask = HVSI_TSDTR;
52648@@ -680,7 +680,7 @@ static int hvsi_put_chars(struct hvsi_struct *hp, const char *buf, int count)
52649 BUG_ON(count > HVSI_MAX_OUTGOING_DATA);
52650
52651 packet.hdr.type = VS_DATA_PACKET_HEADER;
52652- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
52653+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
52654 packet.hdr.len = count + sizeof(struct hvsi_header);
52655 memcpy(&packet.data, buf, count);
52656
52657@@ -697,7 +697,7 @@ static void hvsi_close_protocol(struct hvsi_struct *hp)
52658 struct hvsi_control packet __ALIGNED__;
52659
52660 packet.hdr.type = VS_CONTROL_PACKET_HEADER;
52661- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
52662+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
52663 packet.hdr.len = 6;
52664 packet.verb = VSV_CLOSE_PROTOCOL;
52665
52666@@ -725,7 +725,7 @@ static int hvsi_open(struct tty_struct *tty, struct file *filp)
52667
52668 tty_port_tty_set(&hp->port, tty);
52669 spin_lock_irqsave(&hp->lock, flags);
52670- hp->port.count++;
52671+ atomic_inc(&hp->port.count);
52672 atomic_set(&hp->seqno, 0);
52673 h_vio_signal(hp->vtermno, VIO_IRQ_ENABLE);
52674 spin_unlock_irqrestore(&hp->lock, flags);
52675@@ -782,7 +782,7 @@ static void hvsi_close(struct tty_struct *tty, struct file *filp)
52676
52677 spin_lock_irqsave(&hp->lock, flags);
52678
52679- if (--hp->port.count == 0) {
52680+ if (atomic_dec_return(&hp->port.count) == 0) {
52681 tty_port_tty_set(&hp->port, NULL);
52682 hp->inbuf_end = hp->inbuf; /* discard remaining partial packets */
52683
52684@@ -815,9 +815,9 @@ static void hvsi_close(struct tty_struct *tty, struct file *filp)
52685
52686 spin_lock_irqsave(&hp->lock, flags);
52687 }
52688- } else if (hp->port.count < 0)
52689+ } else if (atomic_read(&hp->port.count) < 0)
52690 printk(KERN_ERR "hvsi_close %lu: oops, count is %d\n",
52691- hp - hvsi_ports, hp->port.count);
52692+ hp - hvsi_ports, atomic_read(&hp->port.count));
52693
52694 spin_unlock_irqrestore(&hp->lock, flags);
52695 }
52696@@ -832,7 +832,7 @@ static void hvsi_hangup(struct tty_struct *tty)
52697 tty_port_tty_set(&hp->port, NULL);
52698
52699 spin_lock_irqsave(&hp->lock, flags);
52700- hp->port.count = 0;
52701+ atomic_set(&hp->port.count, 0);
52702 hp->n_outbuf = 0;
52703 spin_unlock_irqrestore(&hp->lock, flags);
52704 }
52705diff --git a/drivers/tty/hvc/hvsi_lib.c b/drivers/tty/hvc/hvsi_lib.c
52706index 7ae6c29..05c6dba 100644
52707--- a/drivers/tty/hvc/hvsi_lib.c
52708+++ b/drivers/tty/hvc/hvsi_lib.c
52709@@ -8,7 +8,7 @@
52710
52711 static int hvsi_send_packet(struct hvsi_priv *pv, struct hvsi_header *packet)
52712 {
52713- packet->seqno = cpu_to_be16(atomic_inc_return(&pv->seqno));
52714+ packet->seqno = cpu_to_be16(atomic_inc_return_unchecked(&pv->seqno));
52715
52716 /* Assumes that always succeeds, works in practice */
52717 return pv->put_chars(pv->termno, (char *)packet, packet->len);
52718@@ -20,7 +20,7 @@ static void hvsi_start_handshake(struct hvsi_priv *pv)
52719
52720 /* Reset state */
52721 pv->established = 0;
52722- atomic_set(&pv->seqno, 0);
52723+ atomic_set_unchecked(&pv->seqno, 0);
52724
52725 pr_devel("HVSI@%x: Handshaking started\n", pv->termno);
52726
52727diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
52728index 345cebb..d5a1e9e 100644
52729--- a/drivers/tty/ipwireless/tty.c
52730+++ b/drivers/tty/ipwireless/tty.c
52731@@ -28,6 +28,7 @@
52732 #include <linux/tty_driver.h>
52733 #include <linux/tty_flip.h>
52734 #include <linux/uaccess.h>
52735+#include <asm/local.h>
52736
52737 #include "tty.h"
52738 #include "network.h"
52739@@ -93,10 +94,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
52740 return -ENODEV;
52741
52742 mutex_lock(&tty->ipw_tty_mutex);
52743- if (tty->port.count == 0)
52744+ if (atomic_read(&tty->port.count) == 0)
52745 tty->tx_bytes_queued = 0;
52746
52747- tty->port.count++;
52748+ atomic_inc(&tty->port.count);
52749
52750 tty->port.tty = linux_tty;
52751 linux_tty->driver_data = tty;
52752@@ -112,9 +113,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
52753
52754 static void do_ipw_close(struct ipw_tty *tty)
52755 {
52756- tty->port.count--;
52757-
52758- if (tty->port.count == 0) {
52759+ if (atomic_dec_return(&tty->port.count) == 0) {
52760 struct tty_struct *linux_tty = tty->port.tty;
52761
52762 if (linux_tty != NULL) {
52763@@ -135,7 +134,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
52764 return;
52765
52766 mutex_lock(&tty->ipw_tty_mutex);
52767- if (tty->port.count == 0) {
52768+ if (atomic_read(&tty->port.count) == 0) {
52769 mutex_unlock(&tty->ipw_tty_mutex);
52770 return;
52771 }
52772@@ -158,7 +157,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
52773
52774 mutex_lock(&tty->ipw_tty_mutex);
52775
52776- if (!tty->port.count) {
52777+ if (!atomic_read(&tty->port.count)) {
52778 mutex_unlock(&tty->ipw_tty_mutex);
52779 return;
52780 }
52781@@ -197,7 +196,7 @@ static int ipw_write(struct tty_struct *linux_tty,
52782 return -ENODEV;
52783
52784 mutex_lock(&tty->ipw_tty_mutex);
52785- if (!tty->port.count) {
52786+ if (!atomic_read(&tty->port.count)) {
52787 mutex_unlock(&tty->ipw_tty_mutex);
52788 return -EINVAL;
52789 }
52790@@ -237,7 +236,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
52791 if (!tty)
52792 return -ENODEV;
52793
52794- if (!tty->port.count)
52795+ if (!atomic_read(&tty->port.count))
52796 return -EINVAL;
52797
52798 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
52799@@ -279,7 +278,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
52800 if (!tty)
52801 return 0;
52802
52803- if (!tty->port.count)
52804+ if (!atomic_read(&tty->port.count))
52805 return 0;
52806
52807 return tty->tx_bytes_queued;
52808@@ -360,7 +359,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
52809 if (!tty)
52810 return -ENODEV;
52811
52812- if (!tty->port.count)
52813+ if (!atomic_read(&tty->port.count))
52814 return -EINVAL;
52815
52816 return get_control_lines(tty);
52817@@ -376,7 +375,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
52818 if (!tty)
52819 return -ENODEV;
52820
52821- if (!tty->port.count)
52822+ if (!atomic_read(&tty->port.count))
52823 return -EINVAL;
52824
52825 return set_control_lines(tty, set, clear);
52826@@ -390,7 +389,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
52827 if (!tty)
52828 return -ENODEV;
52829
52830- if (!tty->port.count)
52831+ if (!atomic_read(&tty->port.count))
52832 return -EINVAL;
52833
52834 /* FIXME: Exactly how is the tty object locked here .. */
52835@@ -546,7 +545,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
52836 * are gone */
52837 mutex_lock(&ttyj->ipw_tty_mutex);
52838 }
52839- while (ttyj->port.count)
52840+ while (atomic_read(&ttyj->port.count))
52841 do_ipw_close(ttyj);
52842 ipwireless_disassociate_network_ttys(network,
52843 ttyj->channel_idx);
52844diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
52845index 14c54e0..1efd4f2 100644
52846--- a/drivers/tty/moxa.c
52847+++ b/drivers/tty/moxa.c
52848@@ -1189,7 +1189,7 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
52849 }
52850
52851 ch = &brd->ports[port % MAX_PORTS_PER_BOARD];
52852- ch->port.count++;
52853+ atomic_inc(&ch->port.count);
52854 tty->driver_data = ch;
52855 tty_port_tty_set(&ch->port, tty);
52856 mutex_lock(&ch->port.mutex);
52857diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
52858index c434376..114ce13 100644
52859--- a/drivers/tty/n_gsm.c
52860+++ b/drivers/tty/n_gsm.c
52861@@ -1644,7 +1644,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
52862 spin_lock_init(&dlci->lock);
52863 mutex_init(&dlci->mutex);
52864 dlci->fifo = &dlci->_fifo;
52865- if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
52866+ if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
52867 kfree(dlci);
52868 return NULL;
52869 }
52870@@ -2958,7 +2958,7 @@ static int gsmtty_open(struct tty_struct *tty, struct file *filp)
52871 struct gsm_dlci *dlci = tty->driver_data;
52872 struct tty_port *port = &dlci->port;
52873
52874- port->count++;
52875+ atomic_inc(&port->count);
52876 tty_port_tty_set(port, tty);
52877
52878 dlci->modem_rx = 0;
52879diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
52880index 2e900a9..576d216 100644
52881--- a/drivers/tty/n_tty.c
52882+++ b/drivers/tty/n_tty.c
52883@@ -115,7 +115,7 @@ struct n_tty_data {
52884 int minimum_to_wake;
52885
52886 /* consumer-published */
52887- size_t read_tail;
52888+ size_t read_tail __intentional_overflow(-1);
52889 size_t line_start;
52890
52891 /* protected by output lock */
52892@@ -2522,6 +2522,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
52893 {
52894 *ops = tty_ldisc_N_TTY;
52895 ops->owner = NULL;
52896- ops->refcount = ops->flags = 0;
52897+ atomic_set(&ops->refcount, 0);
52898+ ops->flags = 0;
52899 }
52900 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
52901diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
52902index 7c4447a..70fbc1e 100644
52903--- a/drivers/tty/pty.c
52904+++ b/drivers/tty/pty.c
52905@@ -830,8 +830,10 @@ static void __init unix98_pty_init(void)
52906 panic("Couldn't register Unix98 pts driver");
52907
52908 /* Now create the /dev/ptmx special device */
52909+ pax_open_kernel();
52910 tty_default_fops(&ptmx_fops);
52911- ptmx_fops.open = ptmx_open;
52912+ *(void **)&ptmx_fops.open = ptmx_open;
52913+ pax_close_kernel();
52914
52915 cdev_init(&ptmx_cdev, &ptmx_fops);
52916 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
52917diff --git a/drivers/tty/rocket.c b/drivers/tty/rocket.c
52918index 383c4c7..d408e21 100644
52919--- a/drivers/tty/rocket.c
52920+++ b/drivers/tty/rocket.c
52921@@ -914,7 +914,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
52922 tty->driver_data = info;
52923 tty_port_tty_set(port, tty);
52924
52925- if (port->count++ == 0) {
52926+ if (atomic_inc_return(&port->count) == 1) {
52927 atomic_inc(&rp_num_ports_open);
52928
52929 #ifdef ROCKET_DEBUG_OPEN
52930@@ -923,7 +923,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
52931 #endif
52932 }
52933 #ifdef ROCKET_DEBUG_OPEN
52934- printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, info->port.count);
52935+ printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, atomic-read(&info->port.count));
52936 #endif
52937
52938 /*
52939@@ -1515,7 +1515,7 @@ static void rp_hangup(struct tty_struct *tty)
52940 spin_unlock_irqrestore(&info->port.lock, flags);
52941 return;
52942 }
52943- if (info->port.count)
52944+ if (atomic_read(&info->port.count))
52945 atomic_dec(&rp_num_ports_open);
52946 clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
52947 spin_unlock_irqrestore(&info->port.lock, flags);
52948diff --git a/drivers/tty/serial/ioc4_serial.c b/drivers/tty/serial/ioc4_serial.c
52949index aa28209..e08fb85 100644
52950--- a/drivers/tty/serial/ioc4_serial.c
52951+++ b/drivers/tty/serial/ioc4_serial.c
52952@@ -437,7 +437,7 @@ struct ioc4_soft {
52953 } is_intr_info[MAX_IOC4_INTR_ENTS];
52954
52955 /* Number of entries active in the above array */
52956- atomic_t is_num_intrs;
52957+ atomic_unchecked_t is_num_intrs;
52958 } is_intr_type[IOC4_NUM_INTR_TYPES];
52959
52960 /* is_ir_lock must be held while
52961@@ -974,7 +974,7 @@ intr_connect(struct ioc4_soft *soft, int type,
52962 BUG_ON(!((type == IOC4_SIO_INTR_TYPE)
52963 || (type == IOC4_OTHER_INTR_TYPE)));
52964
52965- i = atomic_inc_return(&soft-> is_intr_type[type].is_num_intrs) - 1;
52966+ i = atomic_inc_return_unchecked(&soft-> is_intr_type[type].is_num_intrs) - 1;
52967 BUG_ON(!(i < MAX_IOC4_INTR_ENTS || (printk("i %d\n", i), 0)));
52968
52969 /* Save off the lower level interrupt handler */
52970@@ -1001,7 +1001,7 @@ static irqreturn_t ioc4_intr(int irq, void *arg)
52971
52972 soft = arg;
52973 for (intr_type = 0; intr_type < IOC4_NUM_INTR_TYPES; intr_type++) {
52974- num_intrs = (int)atomic_read(
52975+ num_intrs = (int)atomic_read_unchecked(
52976 &soft->is_intr_type[intr_type].is_num_intrs);
52977
52978 this_mir = this_ir = pending_intrs(soft, intr_type);
52979diff --git a/drivers/tty/serial/kgdb_nmi.c b/drivers/tty/serial/kgdb_nmi.c
52980index 129dc5b..1da5bb8 100644
52981--- a/drivers/tty/serial/kgdb_nmi.c
52982+++ b/drivers/tty/serial/kgdb_nmi.c
52983@@ -53,7 +53,9 @@ static int kgdb_nmi_console_setup(struct console *co, char *options)
52984 * I/O utilities that messages sent to the console will automatically
52985 * be displayed on the dbg_io.
52986 */
52987- dbg_io_ops->is_console = true;
52988+ pax_open_kernel();
52989+ *(int *)&dbg_io_ops->is_console = true;
52990+ pax_close_kernel();
52991
52992 return 0;
52993 }
52994diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
52995index a260cde..6b2b5ce 100644
52996--- a/drivers/tty/serial/kgdboc.c
52997+++ b/drivers/tty/serial/kgdboc.c
52998@@ -24,8 +24,9 @@
52999 #define MAX_CONFIG_LEN 40
53000
53001 static struct kgdb_io kgdboc_io_ops;
53002+static struct kgdb_io kgdboc_io_ops_console;
53003
53004-/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
53005+/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
53006 static int configured = -1;
53007
53008 static char config[MAX_CONFIG_LEN];
53009@@ -151,6 +152,8 @@ static void cleanup_kgdboc(void)
53010 kgdboc_unregister_kbd();
53011 if (configured == 1)
53012 kgdb_unregister_io_module(&kgdboc_io_ops);
53013+ else if (configured == 2)
53014+ kgdb_unregister_io_module(&kgdboc_io_ops_console);
53015 }
53016
53017 static int configure_kgdboc(void)
53018@@ -160,13 +163,13 @@ static int configure_kgdboc(void)
53019 int err;
53020 char *cptr = config;
53021 struct console *cons;
53022+ int is_console = 0;
53023
53024 err = kgdboc_option_setup(config);
53025 if (err || !strlen(config) || isspace(config[0]))
53026 goto noconfig;
53027
53028 err = -ENODEV;
53029- kgdboc_io_ops.is_console = 0;
53030 kgdb_tty_driver = NULL;
53031
53032 kgdboc_use_kms = 0;
53033@@ -187,7 +190,7 @@ static int configure_kgdboc(void)
53034 int idx;
53035 if (cons->device && cons->device(cons, &idx) == p &&
53036 idx == tty_line) {
53037- kgdboc_io_ops.is_console = 1;
53038+ is_console = 1;
53039 break;
53040 }
53041 cons = cons->next;
53042@@ -197,7 +200,13 @@ static int configure_kgdboc(void)
53043 kgdb_tty_line = tty_line;
53044
53045 do_register:
53046- err = kgdb_register_io_module(&kgdboc_io_ops);
53047+ if (is_console) {
53048+ err = kgdb_register_io_module(&kgdboc_io_ops_console);
53049+ configured = 2;
53050+ } else {
53051+ err = kgdb_register_io_module(&kgdboc_io_ops);
53052+ configured = 1;
53053+ }
53054 if (err)
53055 goto noconfig;
53056
53057@@ -205,8 +214,6 @@ do_register:
53058 if (err)
53059 goto nmi_con_failed;
53060
53061- configured = 1;
53062-
53063 return 0;
53064
53065 nmi_con_failed:
53066@@ -223,7 +230,7 @@ noconfig:
53067 static int __init init_kgdboc(void)
53068 {
53069 /* Already configured? */
53070- if (configured == 1)
53071+ if (configured >= 1)
53072 return 0;
53073
53074 return configure_kgdboc();
53075@@ -272,7 +279,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
53076 if (config[len - 1] == '\n')
53077 config[len - 1] = '\0';
53078
53079- if (configured == 1)
53080+ if (configured >= 1)
53081 cleanup_kgdboc();
53082
53083 /* Go and configure with the new params. */
53084@@ -312,6 +319,15 @@ static struct kgdb_io kgdboc_io_ops = {
53085 .post_exception = kgdboc_post_exp_handler,
53086 };
53087
53088+static struct kgdb_io kgdboc_io_ops_console = {
53089+ .name = "kgdboc",
53090+ .read_char = kgdboc_get_char,
53091+ .write_char = kgdboc_put_char,
53092+ .pre_exception = kgdboc_pre_exp_handler,
53093+ .post_exception = kgdboc_post_exp_handler,
53094+ .is_console = 1
53095+};
53096+
53097 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
53098 /* This is only available if kgdboc is a built in for early debugging */
53099 static int __init kgdboc_early_init(char *opt)
53100diff --git a/drivers/tty/serial/msm_serial.c b/drivers/tty/serial/msm_serial.c
53101index 4b6c783..9a19db3 100644
53102--- a/drivers/tty/serial/msm_serial.c
53103+++ b/drivers/tty/serial/msm_serial.c
53104@@ -1028,7 +1028,7 @@ static struct uart_driver msm_uart_driver = {
53105 .cons = MSM_CONSOLE,
53106 };
53107
53108-static atomic_t msm_uart_next_id = ATOMIC_INIT(0);
53109+static atomic_unchecked_t msm_uart_next_id = ATOMIC_INIT(0);
53110
53111 static const struct of_device_id msm_uartdm_table[] = {
53112 { .compatible = "qcom,msm-uartdm-v1.1", .data = (void *)UARTDM_1P1 },
53113@@ -1047,7 +1047,7 @@ static int msm_serial_probe(struct platform_device *pdev)
53114 int irq;
53115
53116 if (pdev->id == -1)
53117- pdev->id = atomic_inc_return(&msm_uart_next_id) - 1;
53118+ pdev->id = atomic_inc_return_unchecked(&msm_uart_next_id) - 1;
53119
53120 if (unlikely(pdev->id < 0 || pdev->id >= UART_NR))
53121 return -ENXIO;
53122diff --git a/drivers/tty/serial/samsung.c b/drivers/tty/serial/samsung.c
53123index c78f43a..22b1dab 100644
53124--- a/drivers/tty/serial/samsung.c
53125+++ b/drivers/tty/serial/samsung.c
53126@@ -478,11 +478,16 @@ static void s3c24xx_serial_shutdown(struct uart_port *port)
53127 }
53128 }
53129
53130+static int s3c64xx_serial_startup(struct uart_port *port);
53131 static int s3c24xx_serial_startup(struct uart_port *port)
53132 {
53133 struct s3c24xx_uart_port *ourport = to_ourport(port);
53134 int ret;
53135
53136+ /* Startup sequence is different for s3c64xx and higher SoC's */
53137+ if (s3c24xx_serial_has_interrupt_mask(port))
53138+ return s3c64xx_serial_startup(port);
53139+
53140 dbg("s3c24xx_serial_startup: port=%p (%08llx,%p)\n",
53141 port, (unsigned long long)port->mapbase, port->membase);
53142
53143@@ -1155,10 +1160,6 @@ static int s3c24xx_serial_init_port(struct s3c24xx_uart_port *ourport,
53144 /* setup info for port */
53145 port->dev = &platdev->dev;
53146
53147- /* Startup sequence is different for s3c64xx and higher SoC's */
53148- if (s3c24xx_serial_has_interrupt_mask(port))
53149- s3c24xx_serial_ops.startup = s3c64xx_serial_startup;
53150-
53151 port->uartclk = 1;
53152
53153 if (cfg->uart_flags & UPF_CONS_FLOW) {
53154diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
53155index eaeb9a0..01a238c 100644
53156--- a/drivers/tty/serial/serial_core.c
53157+++ b/drivers/tty/serial/serial_core.c
53158@@ -1339,7 +1339,7 @@ static void uart_close(struct tty_struct *tty, struct file *filp)
53159
53160 pr_debug("uart_close(%d) called\n", uport ? uport->line : -1);
53161
53162- if (!port->count || tty_port_close_start(port, tty, filp) == 0)
53163+ if (!atomic_read(&port->count) || tty_port_close_start(port, tty, filp) == 0)
53164 return;
53165
53166 /*
53167@@ -1466,7 +1466,7 @@ static void uart_hangup(struct tty_struct *tty)
53168 uart_flush_buffer(tty);
53169 uart_shutdown(tty, state);
53170 spin_lock_irqsave(&port->lock, flags);
53171- port->count = 0;
53172+ atomic_set(&port->count, 0);
53173 clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
53174 spin_unlock_irqrestore(&port->lock, flags);
53175 tty_port_tty_set(port, NULL);
53176@@ -1564,7 +1564,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
53177 goto end;
53178 }
53179
53180- port->count++;
53181+ atomic_inc(&port->count);
53182 if (!state->uart_port || state->uart_port->flags & UPF_DEAD) {
53183 retval = -ENXIO;
53184 goto err_dec_count;
53185@@ -1596,7 +1596,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
53186 end:
53187 return retval;
53188 err_dec_count:
53189- port->count--;
53190+ atomic_dec(&port->count);
53191 mutex_unlock(&port->mutex);
53192 goto end;
53193 }
53194diff --git a/drivers/tty/synclink.c b/drivers/tty/synclink.c
53195index b799170..87dafd5 100644
53196--- a/drivers/tty/synclink.c
53197+++ b/drivers/tty/synclink.c
53198@@ -3090,7 +3090,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
53199
53200 if (debug_level >= DEBUG_LEVEL_INFO)
53201 printk("%s(%d):mgsl_close(%s) entry, count=%d\n",
53202- __FILE__,__LINE__, info->device_name, info->port.count);
53203+ __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
53204
53205 if (tty_port_close_start(&info->port, tty, filp) == 0)
53206 goto cleanup;
53207@@ -3108,7 +3108,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
53208 cleanup:
53209 if (debug_level >= DEBUG_LEVEL_INFO)
53210 printk("%s(%d):mgsl_close(%s) exit, count=%d\n", __FILE__,__LINE__,
53211- tty->driver->name, info->port.count);
53212+ tty->driver->name, atomic_read(&info->port.count));
53213
53214 } /* end of mgsl_close() */
53215
53216@@ -3207,8 +3207,8 @@ static void mgsl_hangup(struct tty_struct *tty)
53217
53218 mgsl_flush_buffer(tty);
53219 shutdown(info);
53220-
53221- info->port.count = 0;
53222+
53223+ atomic_set(&info->port.count, 0);
53224 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
53225 info->port.tty = NULL;
53226
53227@@ -3296,10 +3296,10 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
53228
53229 if (debug_level >= DEBUG_LEVEL_INFO)
53230 printk("%s(%d):block_til_ready before block on %s count=%d\n",
53231- __FILE__,__LINE__, tty->driver->name, port->count );
53232+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
53233
53234 spin_lock_irqsave(&info->irq_spinlock, flags);
53235- port->count--;
53236+ atomic_dec(&port->count);
53237 spin_unlock_irqrestore(&info->irq_spinlock, flags);
53238 port->blocked_open++;
53239
53240@@ -3327,7 +3327,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
53241
53242 if (debug_level >= DEBUG_LEVEL_INFO)
53243 printk("%s(%d):block_til_ready blocking on %s count=%d\n",
53244- __FILE__,__LINE__, tty->driver->name, port->count );
53245+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
53246
53247 tty_unlock(tty);
53248 schedule();
53249@@ -3339,12 +3339,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
53250
53251 /* FIXME: Racy on hangup during close wait */
53252 if (!tty_hung_up_p(filp))
53253- port->count++;
53254+ atomic_inc(&port->count);
53255 port->blocked_open--;
53256
53257 if (debug_level >= DEBUG_LEVEL_INFO)
53258 printk("%s(%d):block_til_ready after blocking on %s count=%d\n",
53259- __FILE__,__LINE__, tty->driver->name, port->count );
53260+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
53261
53262 if (!retval)
53263 port->flags |= ASYNC_NORMAL_ACTIVE;
53264@@ -3396,7 +3396,7 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
53265
53266 if (debug_level >= DEBUG_LEVEL_INFO)
53267 printk("%s(%d):mgsl_open(%s), old ref count = %d\n",
53268- __FILE__,__LINE__,tty->driver->name, info->port.count);
53269+ __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
53270
53271 /* If port is closing, signal caller to try again */
53272 if (info->port.flags & ASYNC_CLOSING){
53273@@ -3415,10 +3415,10 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
53274 spin_unlock_irqrestore(&info->netlock, flags);
53275 goto cleanup;
53276 }
53277- info->port.count++;
53278+ atomic_inc(&info->port.count);
53279 spin_unlock_irqrestore(&info->netlock, flags);
53280
53281- if (info->port.count == 1) {
53282+ if (atomic_read(&info->port.count) == 1) {
53283 /* 1st open on this device, init hardware */
53284 retval = startup(info);
53285 if (retval < 0)
53286@@ -3442,8 +3442,8 @@ cleanup:
53287 if (retval) {
53288 if (tty->count == 1)
53289 info->port.tty = NULL; /* tty layer will release tty struct */
53290- if(info->port.count)
53291- info->port.count--;
53292+ if (atomic_read(&info->port.count))
53293+ atomic_dec(&info->port.count);
53294 }
53295
53296 return retval;
53297@@ -7661,7 +7661,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
53298 unsigned short new_crctype;
53299
53300 /* return error if TTY interface open */
53301- if (info->port.count)
53302+ if (atomic_read(&info->port.count))
53303 return -EBUSY;
53304
53305 switch (encoding)
53306@@ -7756,7 +7756,7 @@ static int hdlcdev_open(struct net_device *dev)
53307
53308 /* arbitrate between network and tty opens */
53309 spin_lock_irqsave(&info->netlock, flags);
53310- if (info->port.count != 0 || info->netcount != 0) {
53311+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
53312 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
53313 spin_unlock_irqrestore(&info->netlock, flags);
53314 return -EBUSY;
53315@@ -7842,7 +7842,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
53316 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
53317
53318 /* return error if TTY interface open */
53319- if (info->port.count)
53320+ if (atomic_read(&info->port.count))
53321 return -EBUSY;
53322
53323 if (cmd != SIOCWANDEV)
53324diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
53325index 0e8c39b..e0cb171 100644
53326--- a/drivers/tty/synclink_gt.c
53327+++ b/drivers/tty/synclink_gt.c
53328@@ -670,7 +670,7 @@ static int open(struct tty_struct *tty, struct file *filp)
53329 tty->driver_data = info;
53330 info->port.tty = tty;
53331
53332- DBGINFO(("%s open, old ref count = %d\n", info->device_name, info->port.count));
53333+ DBGINFO(("%s open, old ref count = %d\n", info->device_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@@ -691,10 +691,10 @@ static int open(struct tty_struct *tty, struct file *filp)
53338 mutex_unlock(&info->port.mutex);
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@@ -715,8 +715,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 DBGINFO(("%s open rc=%d\n", info->device_name, retval));
53361@@ -729,7 +729,7 @@ static void close(struct tty_struct *tty, struct file *filp)
53362
53363 if (sanity_check(info, tty->name, "close"))
53364 return;
53365- DBGINFO(("%s close entry, count=%d\n", info->device_name, info->port.count));
53366+ DBGINFO(("%s close entry, count=%d\n", info->device_name, atomic_read(&info->port.count)));
53367
53368 if (tty_port_close_start(&info->port, tty, filp) == 0)
53369 goto cleanup;
53370@@ -746,7 +746,7 @@ static void close(struct tty_struct *tty, struct file *filp)
53371 tty_port_close_end(&info->port, tty);
53372 info->port.tty = NULL;
53373 cleanup:
53374- DBGINFO(("%s close exit, count=%d\n", tty->driver->name, info->port.count));
53375+ DBGINFO(("%s close exit, count=%d\n", tty->driver->name, atomic_read(&info->port.count)));
53376 }
53377
53378 static void hangup(struct tty_struct *tty)
53379@@ -764,7 +764,7 @@ static void hangup(struct tty_struct *tty)
53380 shutdown(info);
53381
53382 spin_lock_irqsave(&info->port.lock, flags);
53383- info->port.count = 0;
53384+ atomic_set(&info->port.count, 0);
53385 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
53386 info->port.tty = NULL;
53387 spin_unlock_irqrestore(&info->port.lock, flags);
53388@@ -1449,7 +1449,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
53389 unsigned short new_crctype;
53390
53391 /* return error if TTY interface open */
53392- if (info->port.count)
53393+ if (atomic_read(&info->port.count))
53394 return -EBUSY;
53395
53396 DBGINFO(("%s hdlcdev_attach\n", info->device_name));
53397@@ -1544,7 +1544,7 @@ static int hdlcdev_open(struct net_device *dev)
53398
53399 /* arbitrate between network and tty opens */
53400 spin_lock_irqsave(&info->netlock, flags);
53401- if (info->port.count != 0 || info->netcount != 0) {
53402+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
53403 DBGINFO(("%s hdlc_open busy\n", dev->name));
53404 spin_unlock_irqrestore(&info->netlock, flags);
53405 return -EBUSY;
53406@@ -1629,7 +1629,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
53407 DBGINFO(("%s hdlcdev_ioctl\n", dev->name));
53408
53409 /* return error if TTY interface open */
53410- if (info->port.count)
53411+ if (atomic_read(&info->port.count))
53412 return -EBUSY;
53413
53414 if (cmd != SIOCWANDEV)
53415@@ -2413,7 +2413,7 @@ static irqreturn_t slgt_interrupt(int dummy, void *dev_id)
53416 if (port == NULL)
53417 continue;
53418 spin_lock(&port->lock);
53419- if ((port->port.count || port->netcount) &&
53420+ if ((atomic_read(&port->port.count) || port->netcount) &&
53421 port->pending_bh && !port->bh_running &&
53422 !port->bh_requested) {
53423 DBGISR(("%s bh queued\n", port->device_name));
53424@@ -3299,7 +3299,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
53425 add_wait_queue(&port->open_wait, &wait);
53426
53427 spin_lock_irqsave(&info->lock, flags);
53428- port->count--;
53429+ atomic_dec(&port->count);
53430 spin_unlock_irqrestore(&info->lock, flags);
53431 port->blocked_open++;
53432
53433@@ -3335,7 +3335,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
53434 remove_wait_queue(&port->open_wait, &wait);
53435
53436 if (!tty_hung_up_p(filp))
53437- port->count++;
53438+ atomic_inc(&port->count);
53439 port->blocked_open--;
53440
53441 if (!retval)
53442diff --git a/drivers/tty/synclinkmp.c b/drivers/tty/synclinkmp.c
53443index c3f9091..abe4601 100644
53444--- a/drivers/tty/synclinkmp.c
53445+++ b/drivers/tty/synclinkmp.c
53446@@ -750,7 +750,7 @@ static int open(struct tty_struct *tty, struct file *filp)
53447
53448 if (debug_level >= DEBUG_LEVEL_INFO)
53449 printk("%s(%d):%s open(), old ref count = %d\n",
53450- __FILE__,__LINE__,tty->driver->name, info->port.count);
53451+ __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
53452
53453 /* If port is closing, signal caller to try again */
53454 if (info->port.flags & ASYNC_CLOSING){
53455@@ -769,10 +769,10 @@ static int open(struct tty_struct *tty, struct file *filp)
53456 spin_unlock_irqrestore(&info->netlock, flags);
53457 goto cleanup;
53458 }
53459- info->port.count++;
53460+ atomic_inc(&info->port.count);
53461 spin_unlock_irqrestore(&info->netlock, flags);
53462
53463- if (info->port.count == 1) {
53464+ if (atomic_read(&info->port.count) == 1) {
53465 /* 1st open on this device, init hardware */
53466 retval = startup(info);
53467 if (retval < 0)
53468@@ -796,8 +796,8 @@ cleanup:
53469 if (retval) {
53470 if (tty->count == 1)
53471 info->port.tty = NULL; /* tty layer will release tty struct */
53472- if(info->port.count)
53473- info->port.count--;
53474+ if(atomic_read(&info->port.count))
53475+ atomic_dec(&info->port.count);
53476 }
53477
53478 return retval;
53479@@ -815,7 +815,7 @@ static void close(struct tty_struct *tty, struct file *filp)
53480
53481 if (debug_level >= DEBUG_LEVEL_INFO)
53482 printk("%s(%d):%s close() entry, count=%d\n",
53483- __FILE__,__LINE__, info->device_name, info->port.count);
53484+ __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
53485
53486 if (tty_port_close_start(&info->port, tty, filp) == 0)
53487 goto cleanup;
53488@@ -834,7 +834,7 @@ static void close(struct tty_struct *tty, struct file *filp)
53489 cleanup:
53490 if (debug_level >= DEBUG_LEVEL_INFO)
53491 printk("%s(%d):%s close() exit, count=%d\n", __FILE__,__LINE__,
53492- tty->driver->name, info->port.count);
53493+ tty->driver->name, atomic_read(&info->port.count));
53494 }
53495
53496 /* Called by tty_hangup() when a hangup is signaled.
53497@@ -857,7 +857,7 @@ static void hangup(struct tty_struct *tty)
53498 shutdown(info);
53499
53500 spin_lock_irqsave(&info->port.lock, flags);
53501- info->port.count = 0;
53502+ atomic_set(&info->port.count, 0);
53503 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
53504 info->port.tty = NULL;
53505 spin_unlock_irqrestore(&info->port.lock, flags);
53506@@ -1565,7 +1565,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
53507 unsigned short new_crctype;
53508
53509 /* return error if TTY interface open */
53510- if (info->port.count)
53511+ if (atomic_read(&info->port.count))
53512 return -EBUSY;
53513
53514 switch (encoding)
53515@@ -1660,7 +1660,7 @@ static int hdlcdev_open(struct net_device *dev)
53516
53517 /* arbitrate between network and tty opens */
53518 spin_lock_irqsave(&info->netlock, flags);
53519- if (info->port.count != 0 || info->netcount != 0) {
53520+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
53521 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
53522 spin_unlock_irqrestore(&info->netlock, flags);
53523 return -EBUSY;
53524@@ -1746,7 +1746,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
53525 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
53526
53527 /* return error if TTY interface open */
53528- if (info->port.count)
53529+ if (atomic_read(&info->port.count))
53530 return -EBUSY;
53531
53532 if (cmd != SIOCWANDEV)
53533@@ -2621,7 +2621,7 @@ static irqreturn_t synclinkmp_interrupt(int dummy, void *dev_id)
53534 * do not request bottom half processing if the
53535 * device is not open in a normal mode.
53536 */
53537- if ( port && (port->port.count || port->netcount) &&
53538+ if ( port && (atomic_read(&port->port.count) || port->netcount) &&
53539 port->pending_bh && !port->bh_running &&
53540 !port->bh_requested ) {
53541 if ( debug_level >= DEBUG_LEVEL_ISR )
53542@@ -3318,10 +3318,10 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
53543
53544 if (debug_level >= DEBUG_LEVEL_INFO)
53545 printk("%s(%d):%s block_til_ready() before block, count=%d\n",
53546- __FILE__,__LINE__, tty->driver->name, port->count );
53547+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
53548
53549 spin_lock_irqsave(&info->lock, flags);
53550- port->count--;
53551+ atomic_dec(&port->count);
53552 spin_unlock_irqrestore(&info->lock, flags);
53553 port->blocked_open++;
53554
53555@@ -3349,7 +3349,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
53556
53557 if (debug_level >= DEBUG_LEVEL_INFO)
53558 printk("%s(%d):%s block_til_ready() count=%d\n",
53559- __FILE__,__LINE__, tty->driver->name, port->count );
53560+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
53561
53562 tty_unlock(tty);
53563 schedule();
53564@@ -3359,12 +3359,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
53565 set_current_state(TASK_RUNNING);
53566 remove_wait_queue(&port->open_wait, &wait);
53567 if (!tty_hung_up_p(filp))
53568- port->count++;
53569+ atomic_inc(&port->count);
53570 port->blocked_open--;
53571
53572 if (debug_level >= DEBUG_LEVEL_INFO)
53573 printk("%s(%d):%s block_til_ready() after, count=%d\n",
53574- __FILE__,__LINE__, tty->driver->name, port->count );
53575+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
53576
53577 if (!retval)
53578 port->flags |= ASYNC_NORMAL_ACTIVE;
53579diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
53580index 42bad18..447d7a2 100644
53581--- a/drivers/tty/sysrq.c
53582+++ b/drivers/tty/sysrq.c
53583@@ -1084,7 +1084,7 @@ EXPORT_SYMBOL(unregister_sysrq_key);
53584 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
53585 size_t count, loff_t *ppos)
53586 {
53587- if (count) {
53588+ if (count && capable(CAP_SYS_ADMIN)) {
53589 char c;
53590
53591 if (get_user(c, buf))
53592diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
53593index 0508a1d..b610592 100644
53594--- a/drivers/tty/tty_io.c
53595+++ b/drivers/tty/tty_io.c
53596@@ -3498,7 +3498,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
53597
53598 void tty_default_fops(struct file_operations *fops)
53599 {
53600- *fops = tty_fops;
53601+ memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
53602 }
53603
53604 /*
53605diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
53606index 2d822aa..a566234 100644
53607--- a/drivers/tty/tty_ldisc.c
53608+++ b/drivers/tty/tty_ldisc.c
53609@@ -71,7 +71,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
53610 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
53611 tty_ldiscs[disc] = new_ldisc;
53612 new_ldisc->num = disc;
53613- new_ldisc->refcount = 0;
53614+ atomic_set(&new_ldisc->refcount, 0);
53615 raw_spin_unlock_irqrestore(&tty_ldiscs_lock, flags);
53616
53617 return ret;
53618@@ -99,7 +99,7 @@ int tty_unregister_ldisc(int disc)
53619 return -EINVAL;
53620
53621 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
53622- if (tty_ldiscs[disc]->refcount)
53623+ if (atomic_read(&tty_ldiscs[disc]->refcount))
53624 ret = -EBUSY;
53625 else
53626 tty_ldiscs[disc] = NULL;
53627@@ -120,7 +120,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
53628 if (ldops) {
53629 ret = ERR_PTR(-EAGAIN);
53630 if (try_module_get(ldops->owner)) {
53631- ldops->refcount++;
53632+ atomic_inc(&ldops->refcount);
53633 ret = ldops;
53634 }
53635 }
53636@@ -133,7 +133,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
53637 unsigned long flags;
53638
53639 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
53640- ldops->refcount--;
53641+ atomic_dec(&ldops->refcount);
53642 module_put(ldops->owner);
53643 raw_spin_unlock_irqrestore(&tty_ldiscs_lock, flags);
53644 }
53645diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
53646index 1b93357..ea9f82c 100644
53647--- a/drivers/tty/tty_port.c
53648+++ b/drivers/tty/tty_port.c
53649@@ -237,7 +237,7 @@ void tty_port_hangup(struct tty_port *port)
53650 unsigned long flags;
53651
53652 spin_lock_irqsave(&port->lock, flags);
53653- port->count = 0;
53654+ atomic_set(&port->count, 0);
53655 port->flags &= ~ASYNC_NORMAL_ACTIVE;
53656 tty = port->tty;
53657 if (tty)
53658@@ -399,7 +399,7 @@ int tty_port_block_til_ready(struct tty_port *port,
53659
53660 /* The port lock protects the port counts */
53661 spin_lock_irqsave(&port->lock, flags);
53662- port->count--;
53663+ atomic_dec(&port->count);
53664 port->blocked_open++;
53665 spin_unlock_irqrestore(&port->lock, flags);
53666
53667@@ -441,7 +441,7 @@ int tty_port_block_til_ready(struct tty_port *port,
53668 we must not mess that up further */
53669 spin_lock_irqsave(&port->lock, flags);
53670 if (!tty_hung_up_p(filp))
53671- port->count++;
53672+ atomic_inc(&port->count);
53673 port->blocked_open--;
53674 if (retval == 0)
53675 port->flags |= ASYNC_NORMAL_ACTIVE;
53676@@ -479,19 +479,19 @@ int tty_port_close_start(struct tty_port *port,
53677 return 0;
53678 }
53679
53680- if (tty->count == 1 && port->count != 1) {
53681+ if (tty->count == 1 && atomic_read(&port->count) != 1) {
53682 printk(KERN_WARNING
53683 "tty_port_close_start: tty->count = 1 port count = %d.\n",
53684- port->count);
53685- port->count = 1;
53686+ atomic_read(&port->count));
53687+ atomic_set(&port->count, 1);
53688 }
53689- if (--port->count < 0) {
53690+ if (atomic_dec_return(&port->count) < 0) {
53691 printk(KERN_WARNING "tty_port_close_start: count = %d\n",
53692- port->count);
53693- port->count = 0;
53694+ atomic_read(&port->count));
53695+ atomic_set(&port->count, 0);
53696 }
53697
53698- if (port->count) {
53699+ if (atomic_read(&port->count)) {
53700 spin_unlock_irqrestore(&port->lock, flags);
53701 return 0;
53702 }
53703@@ -592,7 +592,7 @@ int tty_port_open(struct tty_port *port, struct tty_struct *tty,
53704 struct file *filp)
53705 {
53706 spin_lock_irq(&port->lock);
53707- ++port->count;
53708+ atomic_inc(&port->count);
53709 spin_unlock_irq(&port->lock);
53710 tty_port_tty_set(port, tty);
53711
53712diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
53713index c039cfe..0b463b0 100644
53714--- a/drivers/tty/vt/keyboard.c
53715+++ b/drivers/tty/vt/keyboard.c
53716@@ -641,6 +641,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
53717 kbd->kbdmode == VC_OFF) &&
53718 value != KVAL(K_SAK))
53719 return; /* SAK is allowed even in raw mode */
53720+
53721+#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
53722+ {
53723+ void *func = fn_handler[value];
53724+ if (func == fn_show_state || func == fn_show_ptregs ||
53725+ func == fn_show_mem)
53726+ return;
53727+ }
53728+#endif
53729+
53730 fn_handler[value](vc);
53731 }
53732
53733@@ -1776,9 +1786,6 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
53734 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
53735 return -EFAULT;
53736
53737- if (!capable(CAP_SYS_TTY_CONFIG))
53738- perm = 0;
53739-
53740 switch (cmd) {
53741 case KDGKBENT:
53742 /* Ensure another thread doesn't free it under us */
53743@@ -1793,6 +1800,9 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
53744 spin_unlock_irqrestore(&kbd_event_lock, flags);
53745 return put_user(val, &user_kbe->kb_value);
53746 case KDSKBENT:
53747+ if (!capable(CAP_SYS_TTY_CONFIG))
53748+ perm = 0;
53749+
53750 if (!perm)
53751 return -EPERM;
53752 if (!i && v == K_NOSUCHMAP) {
53753@@ -1883,9 +1893,6 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
53754 int i, j, k;
53755 int ret;
53756
53757- if (!capable(CAP_SYS_TTY_CONFIG))
53758- perm = 0;
53759-
53760 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
53761 if (!kbs) {
53762 ret = -ENOMEM;
53763@@ -1919,6 +1926,9 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
53764 kfree(kbs);
53765 return ((p && *p) ? -EOVERFLOW : 0);
53766 case KDSKBSENT:
53767+ if (!capable(CAP_SYS_TTY_CONFIG))
53768+ perm = 0;
53769+
53770 if (!perm) {
53771 ret = -EPERM;
53772 goto reterr;
53773diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
53774index 60fa627..7214965 100644
53775--- a/drivers/uio/uio.c
53776+++ b/drivers/uio/uio.c
53777@@ -25,6 +25,7 @@
53778 #include <linux/kobject.h>
53779 #include <linux/cdev.h>
53780 #include <linux/uio_driver.h>
53781+#include <asm/local.h>
53782
53783 #define UIO_MAX_DEVICES (1U << MINORBITS)
53784
53785@@ -231,7 +232,7 @@ static ssize_t event_show(struct device *dev,
53786 struct device_attribute *attr, char *buf)
53787 {
53788 struct uio_device *idev = dev_get_drvdata(dev);
53789- return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
53790+ return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
53791 }
53792 static DEVICE_ATTR_RO(event);
53793
53794@@ -393,7 +394,7 @@ void uio_event_notify(struct uio_info *info)
53795 {
53796 struct uio_device *idev = info->uio_dev;
53797
53798- atomic_inc(&idev->event);
53799+ atomic_inc_unchecked(&idev->event);
53800 wake_up_interruptible(&idev->wait);
53801 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
53802 }
53803@@ -446,7 +447,7 @@ static int uio_open(struct inode *inode, struct file *filep)
53804 }
53805
53806 listener->dev = idev;
53807- listener->event_count = atomic_read(&idev->event);
53808+ listener->event_count = atomic_read_unchecked(&idev->event);
53809 filep->private_data = listener;
53810
53811 if (idev->info->open) {
53812@@ -497,7 +498,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
53813 return -EIO;
53814
53815 poll_wait(filep, &idev->wait, wait);
53816- if (listener->event_count != atomic_read(&idev->event))
53817+ if (listener->event_count != atomic_read_unchecked(&idev->event))
53818 return POLLIN | POLLRDNORM;
53819 return 0;
53820 }
53821@@ -522,7 +523,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
53822 do {
53823 set_current_state(TASK_INTERRUPTIBLE);
53824
53825- event_count = atomic_read(&idev->event);
53826+ event_count = atomic_read_unchecked(&idev->event);
53827 if (event_count != listener->event_count) {
53828 if (copy_to_user(buf, &event_count, count))
53829 retval = -EFAULT;
53830@@ -579,9 +580,13 @@ static ssize_t uio_write(struct file *filep, const char __user *buf,
53831 static int uio_find_mem_index(struct vm_area_struct *vma)
53832 {
53833 struct uio_device *idev = vma->vm_private_data;
53834+ unsigned long size;
53835
53836 if (vma->vm_pgoff < MAX_UIO_MAPS) {
53837- if (idev->info->mem[vma->vm_pgoff].size == 0)
53838+ size = idev->info->mem[vma->vm_pgoff].size;
53839+ if (size == 0)
53840+ return -1;
53841+ if (vma->vm_end - vma->vm_start > size)
53842 return -1;
53843 return (int)vma->vm_pgoff;
53844 }
53845@@ -813,7 +818,7 @@ int __uio_register_device(struct module *owner,
53846 idev->owner = owner;
53847 idev->info = info;
53848 init_waitqueue_head(&idev->wait);
53849- atomic_set(&idev->event, 0);
53850+ atomic_set_unchecked(&idev->event, 0);
53851
53852 ret = uio_get_minor(idev);
53853 if (ret)
53854diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
53855index 813d4d3..a71934f 100644
53856--- a/drivers/usb/atm/cxacru.c
53857+++ b/drivers/usb/atm/cxacru.c
53858@@ -472,7 +472,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
53859 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
53860 if (ret < 2)
53861 return -EINVAL;
53862- if (index < 0 || index > 0x7f)
53863+ if (index > 0x7f)
53864 return -EINVAL;
53865 pos += tmp;
53866
53867diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
53868index dada014..1d0d517 100644
53869--- a/drivers/usb/atm/usbatm.c
53870+++ b/drivers/usb/atm/usbatm.c
53871@@ -331,7 +331,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
53872 if (printk_ratelimit())
53873 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
53874 __func__, vpi, vci);
53875- atomic_inc(&vcc->stats->rx_err);
53876+ atomic_inc_unchecked(&vcc->stats->rx_err);
53877 return;
53878 }
53879
53880@@ -358,7 +358,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
53881 if (length > ATM_MAX_AAL5_PDU) {
53882 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
53883 __func__, length, vcc);
53884- atomic_inc(&vcc->stats->rx_err);
53885+ atomic_inc_unchecked(&vcc->stats->rx_err);
53886 goto out;
53887 }
53888
53889@@ -367,14 +367,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
53890 if (sarb->len < pdu_length) {
53891 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
53892 __func__, pdu_length, sarb->len, vcc);
53893- atomic_inc(&vcc->stats->rx_err);
53894+ atomic_inc_unchecked(&vcc->stats->rx_err);
53895 goto out;
53896 }
53897
53898 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
53899 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
53900 __func__, vcc);
53901- atomic_inc(&vcc->stats->rx_err);
53902+ atomic_inc_unchecked(&vcc->stats->rx_err);
53903 goto out;
53904 }
53905
53906@@ -386,7 +386,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
53907 if (printk_ratelimit())
53908 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
53909 __func__, length);
53910- atomic_inc(&vcc->stats->rx_drop);
53911+ atomic_inc_unchecked(&vcc->stats->rx_drop);
53912 goto out;
53913 }
53914
53915@@ -414,7 +414,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
53916
53917 vcc->push(vcc, skb);
53918
53919- atomic_inc(&vcc->stats->rx);
53920+ atomic_inc_unchecked(&vcc->stats->rx);
53921 out:
53922 skb_trim(sarb, 0);
53923 }
53924@@ -612,7 +612,7 @@ static void usbatm_tx_process(unsigned long data)
53925 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
53926
53927 usbatm_pop(vcc, skb);
53928- atomic_inc(&vcc->stats->tx);
53929+ atomic_inc_unchecked(&vcc->stats->tx);
53930
53931 skb = skb_dequeue(&instance->sndqueue);
53932 }
53933@@ -756,11 +756,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t *pos, char *page
53934 if (!left--)
53935 return sprintf(page,
53936 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
53937- atomic_read(&atm_dev->stats.aal5.tx),
53938- atomic_read(&atm_dev->stats.aal5.tx_err),
53939- atomic_read(&atm_dev->stats.aal5.rx),
53940- atomic_read(&atm_dev->stats.aal5.rx_err),
53941- atomic_read(&atm_dev->stats.aal5.rx_drop));
53942+ atomic_read_unchecked(&atm_dev->stats.aal5.tx),
53943+ atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
53944+ atomic_read_unchecked(&atm_dev->stats.aal5.rx),
53945+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
53946+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
53947
53948 if (!left--) {
53949 if (instance->disconnected)
53950diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
53951index 2a3bbdf..91d72cf 100644
53952--- a/drivers/usb/core/devices.c
53953+++ b/drivers/usb/core/devices.c
53954@@ -126,7 +126,7 @@ static const char format_endpt[] =
53955 * time it gets called.
53956 */
53957 static struct device_connect_event {
53958- atomic_t count;
53959+ atomic_unchecked_t count;
53960 wait_queue_head_t wait;
53961 } device_event = {
53962 .count = ATOMIC_INIT(1),
53963@@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
53964
53965 void usbfs_conn_disc_event(void)
53966 {
53967- atomic_add(2, &device_event.count);
53968+ atomic_add_unchecked(2, &device_event.count);
53969 wake_up(&device_event.wait);
53970 }
53971
53972@@ -652,7 +652,7 @@ static unsigned int usb_device_poll(struct file *file,
53973
53974 poll_wait(file, &device_event.wait, wait);
53975
53976- event_count = atomic_read(&device_event.count);
53977+ event_count = atomic_read_unchecked(&device_event.count);
53978 if (file->f_version != event_count) {
53979 file->f_version = event_count;
53980 return POLLIN | POLLRDNORM;
53981diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c
53982index 0b59731..46ee7d1 100644
53983--- a/drivers/usb/core/devio.c
53984+++ b/drivers/usb/core/devio.c
53985@@ -187,7 +187,7 @@ static ssize_t usbdev_read(struct file *file, char __user *buf, size_t nbytes,
53986 struct usb_dev_state *ps = file->private_data;
53987 struct usb_device *dev = ps->dev;
53988 ssize_t ret = 0;
53989- unsigned len;
53990+ size_t len;
53991 loff_t pos;
53992 int i;
53993
53994@@ -229,22 +229,22 @@ static ssize_t usbdev_read(struct file *file, char __user *buf, size_t nbytes,
53995 for (i = 0; nbytes && i < dev->descriptor.bNumConfigurations; i++) {
53996 struct usb_config_descriptor *config =
53997 (struct usb_config_descriptor *)dev->rawdescriptors[i];
53998- unsigned int length = le16_to_cpu(config->wTotalLength);
53999+ size_t length = le16_to_cpu(config->wTotalLength);
54000
54001 if (*ppos < pos + length) {
54002
54003 /* The descriptor may claim to be longer than it
54004 * really is. Here is the actual allocated length. */
54005- unsigned alloclen =
54006+ size_t alloclen =
54007 le16_to_cpu(dev->config[i].desc.wTotalLength);
54008
54009- len = length - (*ppos - pos);
54010+ len = length + pos - *ppos;
54011 if (len > nbytes)
54012 len = nbytes;
54013
54014 /* Simply don't write (skip over) unallocated parts */
54015 if (alloclen > (*ppos - pos)) {
54016- alloclen -= (*ppos - pos);
54017+ alloclen = alloclen + pos - *ppos;
54018 if (copy_to_user(buf,
54019 dev->rawdescriptors[i] + (*ppos - pos),
54020 min(len, alloclen))) {
54021diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
54022index a6efb41..6f72549b 100644
54023--- a/drivers/usb/core/hcd.c
54024+++ b/drivers/usb/core/hcd.c
54025@@ -1551,7 +1551,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
54026 */
54027 usb_get_urb(urb);
54028 atomic_inc(&urb->use_count);
54029- atomic_inc(&urb->dev->urbnum);
54030+ atomic_inc_unchecked(&urb->dev->urbnum);
54031 usbmon_urb_submit(&hcd->self, urb);
54032
54033 /* NOTE requirements on root-hub callers (usbfs and the hub
54034@@ -1578,7 +1578,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
54035 urb->hcpriv = NULL;
54036 INIT_LIST_HEAD(&urb->urb_list);
54037 atomic_dec(&urb->use_count);
54038- atomic_dec(&urb->dev->urbnum);
54039+ atomic_dec_unchecked(&urb->dev->urbnum);
54040 if (atomic_read(&urb->reject))
54041 wake_up(&usb_kill_urb_queue);
54042 usb_put_urb(urb);
54043diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
54044index b649fef..c7107a0 100644
54045--- a/drivers/usb/core/hub.c
54046+++ b/drivers/usb/core/hub.c
54047@@ -26,6 +26,7 @@
54048 #include <linux/mutex.h>
54049 #include <linux/random.h>
54050 #include <linux/pm_qos.h>
54051+#include <linux/grsecurity.h>
54052
54053 #include <asm/uaccess.h>
54054 #include <asm/byteorder.h>
54055@@ -4666,6 +4667,10 @@ static void hub_port_connect(struct usb_hub *hub, int port1, u16 portstatus,
54056 goto done;
54057 return;
54058 }
54059+
54060+ if (gr_handle_new_usb())
54061+ goto done;
54062+
54063 if (hub_is_superspeed(hub->hdev))
54064 unit_load = 150;
54065 else
54066diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
54067index f7b7713..23d07ec 100644
54068--- a/drivers/usb/core/message.c
54069+++ b/drivers/usb/core/message.c
54070@@ -128,7 +128,7 @@ static int usb_internal_control_msg(struct usb_device *usb_dev,
54071 * Return: If successful, the number of bytes transferred. Otherwise, a negative
54072 * error number.
54073 */
54074-int usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
54075+int __intentional_overflow(-1) usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
54076 __u8 requesttype, __u16 value, __u16 index, void *data,
54077 __u16 size, int timeout)
54078 {
54079@@ -180,7 +180,7 @@ EXPORT_SYMBOL_GPL(usb_control_msg);
54080 * If successful, 0. Otherwise a negative error number. The number of actual
54081 * bytes transferred will be stored in the @actual_length parameter.
54082 */
54083-int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
54084+int __intentional_overflow(-1) usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
54085 void *data, int len, int *actual_length, int timeout)
54086 {
54087 return usb_bulk_msg(usb_dev, pipe, data, len, actual_length, timeout);
54088@@ -220,7 +220,7 @@ EXPORT_SYMBOL_GPL(usb_interrupt_msg);
54089 * bytes transferred will be stored in the @actual_length parameter.
54090 *
54091 */
54092-int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
54093+int __intentional_overflow(-1) usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
54094 void *data, int len, int *actual_length, int timeout)
54095 {
54096 struct urb *urb;
54097diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
54098index 1236c60..d47a51c 100644
54099--- a/drivers/usb/core/sysfs.c
54100+++ b/drivers/usb/core/sysfs.c
54101@@ -244,7 +244,7 @@ static ssize_t urbnum_show(struct device *dev, struct device_attribute *attr,
54102 struct usb_device *udev;
54103
54104 udev = to_usb_device(dev);
54105- return sprintf(buf, "%d\n", atomic_read(&udev->urbnum));
54106+ return sprintf(buf, "%d\n", atomic_read_unchecked(&udev->urbnum));
54107 }
54108 static DEVICE_ATTR_RO(urbnum);
54109
54110diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
54111index 2dd2362..1135437 100644
54112--- a/drivers/usb/core/usb.c
54113+++ b/drivers/usb/core/usb.c
54114@@ -433,7 +433,7 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent,
54115 set_dev_node(&dev->dev, dev_to_node(bus->controller));
54116 dev->state = USB_STATE_ATTACHED;
54117 dev->lpm_disable_count = 1;
54118- atomic_set(&dev->urbnum, 0);
54119+ atomic_set_unchecked(&dev->urbnum, 0);
54120
54121 INIT_LIST_HEAD(&dev->ep0.urb_list);
54122 dev->ep0.desc.bLength = USB_DT_ENDPOINT_SIZE;
54123diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
54124index 8cfc319..4868255 100644
54125--- a/drivers/usb/early/ehci-dbgp.c
54126+++ b/drivers/usb/early/ehci-dbgp.c
54127@@ -98,7 +98,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
54128
54129 #ifdef CONFIG_KGDB
54130 static struct kgdb_io kgdbdbgp_io_ops;
54131-#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
54132+static struct kgdb_io kgdbdbgp_io_ops_console;
54133+#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
54134 #else
54135 #define dbgp_kgdb_mode (0)
54136 #endif
54137@@ -1043,6 +1044,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
54138 .write_char = kgdbdbgp_write_char,
54139 };
54140
54141+static struct kgdb_io kgdbdbgp_io_ops_console = {
54142+ .name = "kgdbdbgp",
54143+ .read_char = kgdbdbgp_read_char,
54144+ .write_char = kgdbdbgp_write_char,
54145+ .is_console = 1
54146+};
54147+
54148 static int kgdbdbgp_wait_time;
54149
54150 static int __init kgdbdbgp_parse_config(char *str)
54151@@ -1058,8 +1066,10 @@ static int __init kgdbdbgp_parse_config(char *str)
54152 ptr++;
54153 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
54154 }
54155- kgdb_register_io_module(&kgdbdbgp_io_ops);
54156- kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
54157+ if (early_dbgp_console.index != -1)
54158+ kgdb_register_io_module(&kgdbdbgp_io_ops_console);
54159+ else
54160+ kgdb_register_io_module(&kgdbdbgp_io_ops);
54161
54162 return 0;
54163 }
54164diff --git a/drivers/usb/gadget/function/f_uac1.c b/drivers/usb/gadget/function/f_uac1.c
54165index f7b2032..fbb340c 100644
54166--- a/drivers/usb/gadget/function/f_uac1.c
54167+++ b/drivers/usb/gadget/function/f_uac1.c
54168@@ -14,6 +14,7 @@
54169 #include <linux/module.h>
54170 #include <linux/device.h>
54171 #include <linux/atomic.h>
54172+#include <linux/module.h>
54173
54174 #include "u_uac1.h"
54175
54176diff --git a/drivers/usb/gadget/function/u_serial.c b/drivers/usb/gadget/function/u_serial.c
54177index 491082a..dfd7d17 100644
54178--- a/drivers/usb/gadget/function/u_serial.c
54179+++ b/drivers/usb/gadget/function/u_serial.c
54180@@ -729,9 +729,9 @@ static int gs_open(struct tty_struct *tty, struct file *file)
54181 spin_lock_irq(&port->port_lock);
54182
54183 /* already open? Great. */
54184- if (port->port.count) {
54185+ if (atomic_read(&port->port.count)) {
54186 status = 0;
54187- port->port.count++;
54188+ atomic_inc(&port->port.count);
54189
54190 /* currently opening/closing? wait ... */
54191 } else if (port->openclose) {
54192@@ -790,7 +790,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
54193 tty->driver_data = port;
54194 port->port.tty = tty;
54195
54196- port->port.count = 1;
54197+ atomic_set(&port->port.count, 1);
54198 port->openclose = false;
54199
54200 /* if connected, start the I/O stream */
54201@@ -832,11 +832,11 @@ static void gs_close(struct tty_struct *tty, struct file *file)
54202
54203 spin_lock_irq(&port->port_lock);
54204
54205- if (port->port.count != 1) {
54206- if (port->port.count == 0)
54207+ if (atomic_read(&port->port.count) != 1) {
54208+ if (atomic_read(&port->port.count) == 0)
54209 WARN_ON(1);
54210 else
54211- --port->port.count;
54212+ atomic_dec(&port->port.count);
54213 goto exit;
54214 }
54215
54216@@ -846,7 +846,7 @@ static void gs_close(struct tty_struct *tty, struct file *file)
54217 * and sleep if necessary
54218 */
54219 port->openclose = true;
54220- port->port.count = 0;
54221+ atomic_set(&port->port.count, 0);
54222
54223 gser = port->port_usb;
54224 if (gser && gser->disconnect)
54225@@ -1062,7 +1062,7 @@ static int gs_closed(struct gs_port *port)
54226 int cond;
54227
54228 spin_lock_irq(&port->port_lock);
54229- cond = (port->port.count == 0) && !port->openclose;
54230+ cond = (atomic_read(&port->port.count) == 0) && !port->openclose;
54231 spin_unlock_irq(&port->port_lock);
54232 return cond;
54233 }
54234@@ -1205,7 +1205,7 @@ int gserial_connect(struct gserial *gser, u8 port_num)
54235 /* if it's already open, start I/O ... and notify the serial
54236 * protocol about open/close status (connect/disconnect).
54237 */
54238- if (port->port.count) {
54239+ if (atomic_read(&port->port.count)) {
54240 pr_debug("gserial_connect: start ttyGS%d\n", port->port_num);
54241 gs_start_io(port);
54242 if (gser->connect)
54243@@ -1252,7 +1252,7 @@ void gserial_disconnect(struct gserial *gser)
54244
54245 port->port_usb = NULL;
54246 gser->ioport = NULL;
54247- if (port->port.count > 0 || port->openclose) {
54248+ if (atomic_read(&port->port.count) > 0 || port->openclose) {
54249 wake_up_interruptible(&port->drain_wait);
54250 if (port->port.tty)
54251 tty_hangup(port->port.tty);
54252@@ -1268,7 +1268,7 @@ void gserial_disconnect(struct gserial *gser)
54253
54254 /* finally, free any unused/unusable I/O buffers */
54255 spin_lock_irqsave(&port->port_lock, flags);
54256- if (port->port.count == 0 && !port->openclose)
54257+ if (atomic_read(&port->port.count) == 0 && !port->openclose)
54258 gs_buf_free(&port->port_write_buf);
54259 gs_free_requests(gser->out, &port->read_pool, NULL);
54260 gs_free_requests(gser->out, &port->read_queue, NULL);
54261diff --git a/drivers/usb/gadget/function/u_uac1.c b/drivers/usb/gadget/function/u_uac1.c
54262index a44a07f..ecea924 100644
54263--- a/drivers/usb/gadget/function/u_uac1.c
54264+++ b/drivers/usb/gadget/function/u_uac1.c
54265@@ -17,6 +17,7 @@
54266 #include <linux/ctype.h>
54267 #include <linux/random.h>
54268 #include <linux/syscalls.h>
54269+#include <linux/module.h>
54270
54271 #include "u_uac1.h"
54272
54273diff --git a/drivers/usb/host/ehci-hub.c b/drivers/usb/host/ehci-hub.c
54274index 5728829..fefc6bf 100644
54275--- a/drivers/usb/host/ehci-hub.c
54276+++ b/drivers/usb/host/ehci-hub.c
54277@@ -771,7 +771,7 @@ static struct urb *request_single_step_set_feature_urb(
54278 urb->transfer_flags = URB_DIR_IN;
54279 usb_get_urb(urb);
54280 atomic_inc(&urb->use_count);
54281- atomic_inc(&urb->dev->urbnum);
54282+ atomic_inc_unchecked(&urb->dev->urbnum);
54283 urb->setup_dma = dma_map_single(
54284 hcd->self.controller,
54285 urb->setup_packet,
54286@@ -838,7 +838,7 @@ static int ehset_single_step_set_feature(struct usb_hcd *hcd, int port)
54287 urb->status = -EINPROGRESS;
54288 usb_get_urb(urb);
54289 atomic_inc(&urb->use_count);
54290- atomic_inc(&urb->dev->urbnum);
54291+ atomic_inc_unchecked(&urb->dev->urbnum);
54292 retval = submit_single_step_set_feature(hcd, urb, 0);
54293 if (!retval && !wait_for_completion_timeout(&done,
54294 msecs_to_jiffies(2000))) {
54295diff --git a/drivers/usb/host/hwa-hc.c b/drivers/usb/host/hwa-hc.c
54296index 1db0626..4948782 100644
54297--- a/drivers/usb/host/hwa-hc.c
54298+++ b/drivers/usb/host/hwa-hc.c
54299@@ -337,7 +337,10 @@ static int __hwahc_op_bwa_set(struct wusbhc *wusbhc, s8 stream_index,
54300 struct hwahc *hwahc = container_of(wusbhc, struct hwahc, wusbhc);
54301 struct wahc *wa = &hwahc->wa;
54302 struct device *dev = &wa->usb_iface->dev;
54303- u8 mas_le[UWB_NUM_MAS/8];
54304+ u8 *mas_le = kmalloc(UWB_NUM_MAS/8, GFP_KERNEL);
54305+
54306+ if (mas_le == NULL)
54307+ return -ENOMEM;
54308
54309 /* Set the stream index */
54310 result = usb_control_msg(wa->usb_dev, usb_sndctrlpipe(wa->usb_dev, 0),
54311@@ -356,10 +359,12 @@ static int __hwahc_op_bwa_set(struct wusbhc *wusbhc, s8 stream_index,
54312 WUSB_REQ_SET_WUSB_MAS,
54313 USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE,
54314 0, wa->usb_iface->cur_altsetting->desc.bInterfaceNumber,
54315- mas_le, 32, USB_CTRL_SET_TIMEOUT);
54316+ mas_le, UWB_NUM_MAS/8, USB_CTRL_SET_TIMEOUT);
54317 if (result < 0)
54318 dev_err(dev, "Cannot set WUSB MAS allocation: %d\n", result);
54319 out:
54320+ kfree(mas_le);
54321+
54322 return result;
54323 }
54324
54325diff --git a/drivers/usb/misc/appledisplay.c b/drivers/usb/misc/appledisplay.c
54326index b3d245e..99549ed 100644
54327--- a/drivers/usb/misc/appledisplay.c
54328+++ b/drivers/usb/misc/appledisplay.c
54329@@ -84,7 +84,7 @@ struct appledisplay {
54330 struct mutex sysfslock; /* concurrent read and write */
54331 };
54332
54333-static atomic_t count_displays = ATOMIC_INIT(0);
54334+static atomic_unchecked_t count_displays = ATOMIC_INIT(0);
54335 static struct workqueue_struct *wq;
54336
54337 static void appledisplay_complete(struct urb *urb)
54338@@ -288,7 +288,7 @@ static int appledisplay_probe(struct usb_interface *iface,
54339
54340 /* Register backlight device */
54341 snprintf(bl_name, sizeof(bl_name), "appledisplay%d",
54342- atomic_inc_return(&count_displays) - 1);
54343+ atomic_inc_return_unchecked(&count_displays) - 1);
54344 memset(&props, 0, sizeof(struct backlight_properties));
54345 props.type = BACKLIGHT_RAW;
54346 props.max_brightness = 0xff;
54347diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
54348index 8d7fc48..01c4986 100644
54349--- a/drivers/usb/serial/console.c
54350+++ b/drivers/usb/serial/console.c
54351@@ -123,7 +123,7 @@ static int usb_console_setup(struct console *co, char *options)
54352
54353 info->port = port;
54354
54355- ++port->port.count;
54356+ atomic_inc(&port->port.count);
54357 if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) {
54358 if (serial->type->set_termios) {
54359 /*
54360@@ -167,7 +167,7 @@ static int usb_console_setup(struct console *co, char *options)
54361 }
54362 /* Now that any required fake tty operations are completed restore
54363 * the tty port count */
54364- --port->port.count;
54365+ atomic_dec(&port->port.count);
54366 /* The console is special in terms of closing the device so
54367 * indicate this port is now acting as a system console. */
54368 port->port.console = 1;
54369@@ -180,7 +180,7 @@ static int usb_console_setup(struct console *co, char *options)
54370 free_tty:
54371 kfree(tty);
54372 reset_open_count:
54373- port->port.count = 0;
54374+ atomic_set(&port->port.count, 0);
54375 usb_autopm_put_interface(serial->interface);
54376 error_get_interface:
54377 usb_serial_put(serial);
54378@@ -191,7 +191,7 @@ static int usb_console_setup(struct console *co, char *options)
54379 static void usb_console_write(struct console *co,
54380 const char *buf, unsigned count)
54381 {
54382- static struct usbcons_info *info = &usbcons_info;
54383+ struct usbcons_info *info = &usbcons_info;
54384 struct usb_serial_port *port = info->port;
54385 struct usb_serial *serial;
54386 int retval = -ENODEV;
54387diff --git a/drivers/usb/storage/usb.h b/drivers/usb/storage/usb.h
54388index 307e339..6aa97cb 100644
54389--- a/drivers/usb/storage/usb.h
54390+++ b/drivers/usb/storage/usb.h
54391@@ -63,7 +63,7 @@ struct us_unusual_dev {
54392 __u8 useProtocol;
54393 __u8 useTransport;
54394 int (*initFunction)(struct us_data *);
54395-};
54396+} __do_const;
54397
54398
54399 /* Dynamic bitflag definitions (us->dflags): used in set_bit() etc. */
54400diff --git a/drivers/usb/usbip/vhci.h b/drivers/usb/usbip/vhci.h
54401index a863a98..d272795 100644
54402--- a/drivers/usb/usbip/vhci.h
54403+++ b/drivers/usb/usbip/vhci.h
54404@@ -83,7 +83,7 @@ struct vhci_hcd {
54405 unsigned resuming:1;
54406 unsigned long re_timeout;
54407
54408- atomic_t seqnum;
54409+ atomic_unchecked_t seqnum;
54410
54411 /*
54412 * NOTE:
54413diff --git a/drivers/usb/usbip/vhci_hcd.c b/drivers/usb/usbip/vhci_hcd.c
54414index c02374b..32d47a9 100644
54415--- a/drivers/usb/usbip/vhci_hcd.c
54416+++ b/drivers/usb/usbip/vhci_hcd.c
54417@@ -439,7 +439,7 @@ static void vhci_tx_urb(struct urb *urb)
54418
54419 spin_lock(&vdev->priv_lock);
54420
54421- priv->seqnum = atomic_inc_return(&the_controller->seqnum);
54422+ priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
54423 if (priv->seqnum == 0xffff)
54424 dev_info(&urb->dev->dev, "seqnum max\n");
54425
54426@@ -686,7 +686,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
54427 return -ENOMEM;
54428 }
54429
54430- unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
54431+ unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
54432 if (unlink->seqnum == 0xffff)
54433 pr_info("seqnum max\n");
54434
54435@@ -891,7 +891,7 @@ static int vhci_start(struct usb_hcd *hcd)
54436 vdev->rhport = rhport;
54437 }
54438
54439- atomic_set(&vhci->seqnum, 0);
54440+ atomic_set_unchecked(&vhci->seqnum, 0);
54441 spin_lock_init(&vhci->lock);
54442
54443 hcd->power_budget = 0; /* no limit */
54444diff --git a/drivers/usb/usbip/vhci_rx.c b/drivers/usb/usbip/vhci_rx.c
54445index 00e4a54..d676f85 100644
54446--- a/drivers/usb/usbip/vhci_rx.c
54447+++ b/drivers/usb/usbip/vhci_rx.c
54448@@ -80,7 +80,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
54449 if (!urb) {
54450 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
54451 pr_info("max seqnum %d\n",
54452- atomic_read(&the_controller->seqnum));
54453+ atomic_read_unchecked(&the_controller->seqnum));
54454 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
54455 return;
54456 }
54457diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
54458index edc7267..9f65ce2 100644
54459--- a/drivers/usb/wusbcore/wa-hc.h
54460+++ b/drivers/usb/wusbcore/wa-hc.h
54461@@ -240,7 +240,7 @@ struct wahc {
54462 spinlock_t xfer_list_lock;
54463 struct work_struct xfer_enqueue_work;
54464 struct work_struct xfer_error_work;
54465- atomic_t xfer_id_count;
54466+ atomic_unchecked_t xfer_id_count;
54467
54468 kernel_ulong_t quirks;
54469 };
54470@@ -305,7 +305,7 @@ static inline void wa_init(struct wahc *wa)
54471 INIT_WORK(&wa->xfer_enqueue_work, wa_urb_enqueue_run);
54472 INIT_WORK(&wa->xfer_error_work, wa_process_errored_transfers_run);
54473 wa->dto_in_use = 0;
54474- atomic_set(&wa->xfer_id_count, 1);
54475+ atomic_set_unchecked(&wa->xfer_id_count, 1);
54476 /* init the buf in URBs */
54477 for (index = 0; index < WA_MAX_BUF_IN_URBS; ++index)
54478 usb_init_urb(&(wa->buf_in_urbs[index]));
54479diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
54480index 69af4fd..da390d7 100644
54481--- a/drivers/usb/wusbcore/wa-xfer.c
54482+++ b/drivers/usb/wusbcore/wa-xfer.c
54483@@ -314,7 +314,7 @@ static void wa_xfer_completion(struct wa_xfer *xfer)
54484 */
54485 static void wa_xfer_id_init(struct wa_xfer *xfer)
54486 {
54487- xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
54488+ xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
54489 }
54490
54491 /* Return the xfer's ID. */
54492diff --git a/drivers/vfio/vfio.c b/drivers/vfio/vfio.c
54493index f018d8d..ccab63f 100644
54494--- a/drivers/vfio/vfio.c
54495+++ b/drivers/vfio/vfio.c
54496@@ -481,7 +481,7 @@ static int vfio_group_nb_add_dev(struct vfio_group *group, struct device *dev)
54497 return 0;
54498
54499 /* TODO Prevent device auto probing */
54500- WARN("Device %s added to live group %d!\n", dev_name(dev),
54501+ WARN(1, "Device %s added to live group %d!\n", dev_name(dev),
54502 iommu_group_id(group->iommu_group));
54503
54504 return 0;
54505diff --git a/drivers/vhost/vringh.c b/drivers/vhost/vringh.c
54506index 5174eba..451e6bc 100644
54507--- a/drivers/vhost/vringh.c
54508+++ b/drivers/vhost/vringh.c
54509@@ -530,17 +530,17 @@ static inline void __vringh_notify_disable(struct vringh *vrh,
54510 /* Userspace access helpers: in this case, addresses are really userspace. */
54511 static inline int getu16_user(u16 *val, const u16 *p)
54512 {
54513- return get_user(*val, (__force u16 __user *)p);
54514+ return get_user(*val, (u16 __force_user *)p);
54515 }
54516
54517 static inline int putu16_user(u16 *p, u16 val)
54518 {
54519- return put_user(val, (__force u16 __user *)p);
54520+ return put_user(val, (u16 __force_user *)p);
54521 }
54522
54523 static inline int copydesc_user(void *dst, const void *src, size_t len)
54524 {
54525- return copy_from_user(dst, (__force void __user *)src, len) ?
54526+ return copy_from_user(dst, (void __force_user *)src, len) ?
54527 -EFAULT : 0;
54528 }
54529
54530@@ -548,19 +548,19 @@ static inline int putused_user(struct vring_used_elem *dst,
54531 const struct vring_used_elem *src,
54532 unsigned int num)
54533 {
54534- return copy_to_user((__force void __user *)dst, src,
54535+ return copy_to_user((void __force_user *)dst, src,
54536 sizeof(*dst) * num) ? -EFAULT : 0;
54537 }
54538
54539 static inline int xfer_from_user(void *src, void *dst, size_t len)
54540 {
54541- return copy_from_user(dst, (__force void __user *)src, len) ?
54542+ return copy_from_user(dst, (void __force_user *)src, len) ?
54543 -EFAULT : 0;
54544 }
54545
54546 static inline int xfer_to_user(void *dst, void *src, size_t len)
54547 {
54548- return copy_to_user((__force void __user *)dst, src, len) ?
54549+ return copy_to_user((void __force_user *)dst, src, len) ?
54550 -EFAULT : 0;
54551 }
54552
54553@@ -596,9 +596,9 @@ int vringh_init_user(struct vringh *vrh, u32 features,
54554 vrh->last_used_idx = 0;
54555 vrh->vring.num = num;
54556 /* vring expects kernel addresses, but only used via accessors. */
54557- vrh->vring.desc = (__force struct vring_desc *)desc;
54558- vrh->vring.avail = (__force struct vring_avail *)avail;
54559- vrh->vring.used = (__force struct vring_used *)used;
54560+ vrh->vring.desc = (__force_kernel struct vring_desc *)desc;
54561+ vrh->vring.avail = (__force_kernel struct vring_avail *)avail;
54562+ vrh->vring.used = (__force_kernel struct vring_used *)used;
54563 return 0;
54564 }
54565 EXPORT_SYMBOL(vringh_init_user);
54566@@ -800,7 +800,7 @@ static inline int getu16_kern(u16 *val, const u16 *p)
54567
54568 static inline int putu16_kern(u16 *p, u16 val)
54569 {
54570- ACCESS_ONCE(*p) = val;
54571+ ACCESS_ONCE_RW(*p) = val;
54572 return 0;
54573 }
54574
54575diff --git a/drivers/video/backlight/kb3886_bl.c b/drivers/video/backlight/kb3886_bl.c
54576index 84a110a..96312c3 100644
54577--- a/drivers/video/backlight/kb3886_bl.c
54578+++ b/drivers/video/backlight/kb3886_bl.c
54579@@ -78,7 +78,7 @@ static struct kb3886bl_machinfo *bl_machinfo;
54580 static unsigned long kb3886bl_flags;
54581 #define KB3886BL_SUSPENDED 0x01
54582
54583-static struct dmi_system_id kb3886bl_device_table[] __initdata = {
54584+static const struct dmi_system_id kb3886bl_device_table[] __initconst = {
54585 {
54586 .ident = "Sahara Touch-iT",
54587 .matches = {
54588diff --git a/drivers/video/fbdev/arcfb.c b/drivers/video/fbdev/arcfb.c
54589index 1b0b233..6f34c2c 100644
54590--- a/drivers/video/fbdev/arcfb.c
54591+++ b/drivers/video/fbdev/arcfb.c
54592@@ -458,7 +458,7 @@ static ssize_t arcfb_write(struct fb_info *info, const char __user *buf,
54593 return -ENOSPC;
54594
54595 err = 0;
54596- if ((count + p) > fbmemlength) {
54597+ if (count > (fbmemlength - p)) {
54598 count = fbmemlength - p;
54599 err = -ENOSPC;
54600 }
54601diff --git a/drivers/video/fbdev/aty/aty128fb.c b/drivers/video/fbdev/aty/aty128fb.c
54602index aedf2fb..47c9aca 100644
54603--- a/drivers/video/fbdev/aty/aty128fb.c
54604+++ b/drivers/video/fbdev/aty/aty128fb.c
54605@@ -149,7 +149,7 @@ enum {
54606 };
54607
54608 /* Must match above enum */
54609-static char * const r128_family[] = {
54610+static const char * const r128_family[] = {
54611 "AGP",
54612 "PCI",
54613 "PRO AGP",
54614diff --git a/drivers/video/fbdev/aty/atyfb_base.c b/drivers/video/fbdev/aty/atyfb_base.c
54615index 37ec09b..98f8862 100644
54616--- a/drivers/video/fbdev/aty/atyfb_base.c
54617+++ b/drivers/video/fbdev/aty/atyfb_base.c
54618@@ -1326,10 +1326,14 @@ static int atyfb_set_par(struct fb_info *info)
54619 par->accel_flags = var->accel_flags; /* hack */
54620
54621 if (var->accel_flags) {
54622- info->fbops->fb_sync = atyfb_sync;
54623+ pax_open_kernel();
54624+ *(void **)&info->fbops->fb_sync = atyfb_sync;
54625+ pax_close_kernel();
54626 info->flags &= ~FBINFO_HWACCEL_DISABLED;
54627 } else {
54628- info->fbops->fb_sync = NULL;
54629+ pax_open_kernel();
54630+ *(void **)&info->fbops->fb_sync = NULL;
54631+ pax_close_kernel();
54632 info->flags |= FBINFO_HWACCEL_DISABLED;
54633 }
54634
54635diff --git a/drivers/video/fbdev/aty/mach64_cursor.c b/drivers/video/fbdev/aty/mach64_cursor.c
54636index 2fa0317..4983f2a 100644
54637--- a/drivers/video/fbdev/aty/mach64_cursor.c
54638+++ b/drivers/video/fbdev/aty/mach64_cursor.c
54639@@ -8,6 +8,7 @@
54640 #include "../core/fb_draw.h"
54641
54642 #include <asm/io.h>
54643+#include <asm/pgtable.h>
54644
54645 #ifdef __sparc__
54646 #include <asm/fbio.h>
54647@@ -218,7 +219,9 @@ int aty_init_cursor(struct fb_info *info)
54648 info->sprite.buf_align = 16; /* and 64 lines tall. */
54649 info->sprite.flags = FB_PIXMAP_IO;
54650
54651- info->fbops->fb_cursor = atyfb_cursor;
54652+ pax_open_kernel();
54653+ *(void **)&info->fbops->fb_cursor = atyfb_cursor;
54654+ pax_close_kernel();
54655
54656 return 0;
54657 }
54658diff --git a/drivers/video/fbdev/core/fb_defio.c b/drivers/video/fbdev/core/fb_defio.c
54659index 900aa4e..6d49418 100644
54660--- a/drivers/video/fbdev/core/fb_defio.c
54661+++ b/drivers/video/fbdev/core/fb_defio.c
54662@@ -206,7 +206,9 @@ void fb_deferred_io_init(struct fb_info *info)
54663
54664 BUG_ON(!fbdefio);
54665 mutex_init(&fbdefio->lock);
54666- info->fbops->fb_mmap = fb_deferred_io_mmap;
54667+ pax_open_kernel();
54668+ *(void **)&info->fbops->fb_mmap = fb_deferred_io_mmap;
54669+ pax_close_kernel();
54670 INIT_DELAYED_WORK(&info->deferred_work, fb_deferred_io_work);
54671 INIT_LIST_HEAD(&fbdefio->pagelist);
54672 if (fbdefio->delay == 0) /* set a default of 1 s */
54673@@ -237,7 +239,7 @@ void fb_deferred_io_cleanup(struct fb_info *info)
54674 page->mapping = NULL;
54675 }
54676
54677- info->fbops->fb_mmap = NULL;
54678+ *(void **)&info->fbops->fb_mmap = NULL;
54679 mutex_destroy(&fbdefio->lock);
54680 }
54681 EXPORT_SYMBOL_GPL(fb_deferred_io_cleanup);
54682diff --git a/drivers/video/fbdev/core/fbmem.c b/drivers/video/fbdev/core/fbmem.c
54683index 0705d88..d9429bf 100644
54684--- a/drivers/video/fbdev/core/fbmem.c
54685+++ b/drivers/video/fbdev/core/fbmem.c
54686@@ -1301,7 +1301,7 @@ static int do_fscreeninfo_to_user(struct fb_fix_screeninfo *fix,
54687 __u32 data;
54688 int err;
54689
54690- err = copy_to_user(&fix32->id, &fix->id, sizeof(fix32->id));
54691+ err = copy_to_user(fix32->id, &fix->id, sizeof(fix32->id));
54692
54693 data = (__u32) (unsigned long) fix->smem_start;
54694 err |= put_user(data, &fix32->smem_start);
54695diff --git a/drivers/video/fbdev/hyperv_fb.c b/drivers/video/fbdev/hyperv_fb.c
54696index 4254336..282567e 100644
54697--- a/drivers/video/fbdev/hyperv_fb.c
54698+++ b/drivers/video/fbdev/hyperv_fb.c
54699@@ -240,7 +240,7 @@ static uint screen_fb_size;
54700 static inline int synthvid_send(struct hv_device *hdev,
54701 struct synthvid_msg *msg)
54702 {
54703- static atomic64_t request_id = ATOMIC64_INIT(0);
54704+ static atomic64_unchecked_t request_id = ATOMIC64_INIT(0);
54705 int ret;
54706
54707 msg->pipe_hdr.type = PIPE_MSG_DATA;
54708@@ -248,7 +248,7 @@ static inline int synthvid_send(struct hv_device *hdev,
54709
54710 ret = vmbus_sendpacket(hdev->channel, msg,
54711 msg->vid_hdr.size + sizeof(struct pipe_msg_hdr),
54712- atomic64_inc_return(&request_id),
54713+ atomic64_inc_return_unchecked(&request_id),
54714 VM_PKT_DATA_INBAND, 0);
54715
54716 if (ret)
54717diff --git a/drivers/video/fbdev/i810/i810_accel.c b/drivers/video/fbdev/i810/i810_accel.c
54718index 7672d2e..b56437f 100644
54719--- a/drivers/video/fbdev/i810/i810_accel.c
54720+++ b/drivers/video/fbdev/i810/i810_accel.c
54721@@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
54722 }
54723 }
54724 printk("ringbuffer lockup!!!\n");
54725+ printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
54726 i810_report_error(mmio);
54727 par->dev_flags |= LOCKUP;
54728 info->pixmap.scan_align = 1;
54729diff --git a/drivers/video/fbdev/matrox/matroxfb_DAC1064.c b/drivers/video/fbdev/matrox/matroxfb_DAC1064.c
54730index a01147f..5d896f8 100644
54731--- a/drivers/video/fbdev/matrox/matroxfb_DAC1064.c
54732+++ b/drivers/video/fbdev/matrox/matroxfb_DAC1064.c
54733@@ -1088,14 +1088,20 @@ static void MGAG100_restore(struct matrox_fb_info *minfo)
54734
54735 #ifdef CONFIG_FB_MATROX_MYSTIQUE
54736 struct matrox_switch matrox_mystique = {
54737- MGA1064_preinit, MGA1064_reset, MGA1064_init, MGA1064_restore,
54738+ .preinit = MGA1064_preinit,
54739+ .reset = MGA1064_reset,
54740+ .init = MGA1064_init,
54741+ .restore = MGA1064_restore,
54742 };
54743 EXPORT_SYMBOL(matrox_mystique);
54744 #endif
54745
54746 #ifdef CONFIG_FB_MATROX_G
54747 struct matrox_switch matrox_G100 = {
54748- MGAG100_preinit, MGAG100_reset, MGAG100_init, MGAG100_restore,
54749+ .preinit = MGAG100_preinit,
54750+ .reset = MGAG100_reset,
54751+ .init = MGAG100_init,
54752+ .restore = MGAG100_restore,
54753 };
54754 EXPORT_SYMBOL(matrox_G100);
54755 #endif
54756diff --git a/drivers/video/fbdev/matrox/matroxfb_Ti3026.c b/drivers/video/fbdev/matrox/matroxfb_Ti3026.c
54757index 195ad7c..09743fc 100644
54758--- a/drivers/video/fbdev/matrox/matroxfb_Ti3026.c
54759+++ b/drivers/video/fbdev/matrox/matroxfb_Ti3026.c
54760@@ -738,7 +738,10 @@ static int Ti3026_preinit(struct matrox_fb_info *minfo)
54761 }
54762
54763 struct matrox_switch matrox_millennium = {
54764- Ti3026_preinit, Ti3026_reset, Ti3026_init, Ti3026_restore
54765+ .preinit = Ti3026_preinit,
54766+ .reset = Ti3026_reset,
54767+ .init = Ti3026_init,
54768+ .restore = Ti3026_restore
54769 };
54770 EXPORT_SYMBOL(matrox_millennium);
54771 #endif
54772diff --git a/drivers/video/fbdev/mb862xx/mb862xxfb_accel.c b/drivers/video/fbdev/mb862xx/mb862xxfb_accel.c
54773index fe92eed..106e085 100644
54774--- a/drivers/video/fbdev/mb862xx/mb862xxfb_accel.c
54775+++ b/drivers/video/fbdev/mb862xx/mb862xxfb_accel.c
54776@@ -312,14 +312,18 @@ void mb862xxfb_init_accel(struct fb_info *info, int xres)
54777 struct mb862xxfb_par *par = info->par;
54778
54779 if (info->var.bits_per_pixel == 32) {
54780- info->fbops->fb_fillrect = cfb_fillrect;
54781- info->fbops->fb_copyarea = cfb_copyarea;
54782- info->fbops->fb_imageblit = cfb_imageblit;
54783+ pax_open_kernel();
54784+ *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
54785+ *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
54786+ *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
54787+ pax_close_kernel();
54788 } else {
54789 outreg(disp, GC_L0EM, 3);
54790- info->fbops->fb_fillrect = mb86290fb_fillrect;
54791- info->fbops->fb_copyarea = mb86290fb_copyarea;
54792- info->fbops->fb_imageblit = mb86290fb_imageblit;
54793+ pax_open_kernel();
54794+ *(void **)&info->fbops->fb_fillrect = mb86290fb_fillrect;
54795+ *(void **)&info->fbops->fb_copyarea = mb86290fb_copyarea;
54796+ *(void **)&info->fbops->fb_imageblit = mb86290fb_imageblit;
54797+ pax_close_kernel();
54798 }
54799 outreg(draw, GDC_REG_DRAW_BASE, 0);
54800 outreg(draw, GDC_REG_MODE_MISC, 0x8000);
54801diff --git a/drivers/video/fbdev/nvidia/nvidia.c b/drivers/video/fbdev/nvidia/nvidia.c
54802index def0412..fed6529 100644
54803--- a/drivers/video/fbdev/nvidia/nvidia.c
54804+++ b/drivers/video/fbdev/nvidia/nvidia.c
54805@@ -669,19 +669,23 @@ static int nvidiafb_set_par(struct fb_info *info)
54806 info->fix.line_length = (info->var.xres_virtual *
54807 info->var.bits_per_pixel) >> 3;
54808 if (info->var.accel_flags) {
54809- info->fbops->fb_imageblit = nvidiafb_imageblit;
54810- info->fbops->fb_fillrect = nvidiafb_fillrect;
54811- info->fbops->fb_copyarea = nvidiafb_copyarea;
54812- info->fbops->fb_sync = nvidiafb_sync;
54813+ pax_open_kernel();
54814+ *(void **)&info->fbops->fb_imageblit = nvidiafb_imageblit;
54815+ *(void **)&info->fbops->fb_fillrect = nvidiafb_fillrect;
54816+ *(void **)&info->fbops->fb_copyarea = nvidiafb_copyarea;
54817+ *(void **)&info->fbops->fb_sync = nvidiafb_sync;
54818+ pax_close_kernel();
54819 info->pixmap.scan_align = 4;
54820 info->flags &= ~FBINFO_HWACCEL_DISABLED;
54821 info->flags |= FBINFO_READS_FAST;
54822 NVResetGraphics(info);
54823 } else {
54824- info->fbops->fb_imageblit = cfb_imageblit;
54825- info->fbops->fb_fillrect = cfb_fillrect;
54826- info->fbops->fb_copyarea = cfb_copyarea;
54827- info->fbops->fb_sync = NULL;
54828+ pax_open_kernel();
54829+ *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
54830+ *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
54831+ *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
54832+ *(void **)&info->fbops->fb_sync = NULL;
54833+ pax_close_kernel();
54834 info->pixmap.scan_align = 1;
54835 info->flags |= FBINFO_HWACCEL_DISABLED;
54836 info->flags &= ~FBINFO_READS_FAST;
54837@@ -1173,8 +1177,11 @@ static int nvidia_set_fbinfo(struct fb_info *info)
54838 info->pixmap.size = 8 * 1024;
54839 info->pixmap.flags = FB_PIXMAP_SYSTEM;
54840
54841- if (!hwcur)
54842- info->fbops->fb_cursor = NULL;
54843+ if (!hwcur) {
54844+ pax_open_kernel();
54845+ *(void **)&info->fbops->fb_cursor = NULL;
54846+ pax_close_kernel();
54847+ }
54848
54849 info->var.accel_flags = (!noaccel);
54850
54851diff --git a/drivers/video/fbdev/omap2/dss/display.c b/drivers/video/fbdev/omap2/dss/display.c
54852index 2412a0d..294215b 100644
54853--- a/drivers/video/fbdev/omap2/dss/display.c
54854+++ b/drivers/video/fbdev/omap2/dss/display.c
54855@@ -161,12 +161,14 @@ int omapdss_register_display(struct omap_dss_device *dssdev)
54856 if (dssdev->name == NULL)
54857 dssdev->name = dssdev->alias;
54858
54859+ pax_open_kernel();
54860 if (drv && drv->get_resolution == NULL)
54861- drv->get_resolution = omapdss_default_get_resolution;
54862+ *(void **)&drv->get_resolution = omapdss_default_get_resolution;
54863 if (drv && drv->get_recommended_bpp == NULL)
54864- drv->get_recommended_bpp = omapdss_default_get_recommended_bpp;
54865+ *(void **)&drv->get_recommended_bpp = omapdss_default_get_recommended_bpp;
54866 if (drv && drv->get_timings == NULL)
54867- drv->get_timings = omapdss_default_get_timings;
54868+ *(void **)&drv->get_timings = omapdss_default_get_timings;
54869+ pax_close_kernel();
54870
54871 mutex_lock(&panel_list_mutex);
54872 list_add_tail(&dssdev->panel_list, &panel_list);
54873diff --git a/drivers/video/fbdev/s1d13xxxfb.c b/drivers/video/fbdev/s1d13xxxfb.c
54874index 83433cb..71e9b98 100644
54875--- a/drivers/video/fbdev/s1d13xxxfb.c
54876+++ b/drivers/video/fbdev/s1d13xxxfb.c
54877@@ -881,8 +881,10 @@ static int s1d13xxxfb_probe(struct platform_device *pdev)
54878
54879 switch(prod_id) {
54880 case S1D13506_PROD_ID: /* activate acceleration */
54881- s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
54882- s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
54883+ pax_open_kernel();
54884+ *(void **)&s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
54885+ *(void **)&s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
54886+ pax_close_kernel();
54887 info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN |
54888 FBINFO_HWACCEL_FILLRECT | FBINFO_HWACCEL_COPYAREA;
54889 break;
54890diff --git a/drivers/video/fbdev/sh_mobile_lcdcfb.c b/drivers/video/fbdev/sh_mobile_lcdcfb.c
54891index 2bcc84a..29dd1ea 100644
54892--- a/drivers/video/fbdev/sh_mobile_lcdcfb.c
54893+++ b/drivers/video/fbdev/sh_mobile_lcdcfb.c
54894@@ -439,9 +439,9 @@ static unsigned long lcdc_sys_read_data(void *handle)
54895 }
54896
54897 static struct sh_mobile_lcdc_sys_bus_ops sh_mobile_lcdc_sys_bus_ops = {
54898- lcdc_sys_write_index,
54899- lcdc_sys_write_data,
54900- lcdc_sys_read_data,
54901+ .write_index = lcdc_sys_write_index,
54902+ .write_data = lcdc_sys_write_data,
54903+ .read_data = lcdc_sys_read_data,
54904 };
54905
54906 static int sh_mobile_lcdc_sginit(struct fb_info *info,
54907diff --git a/drivers/video/fbdev/smscufx.c b/drivers/video/fbdev/smscufx.c
54908index d513ed6..90b0de9 100644
54909--- a/drivers/video/fbdev/smscufx.c
54910+++ b/drivers/video/fbdev/smscufx.c
54911@@ -1175,7 +1175,9 @@ static int ufx_ops_release(struct fb_info *info, int user)
54912 fb_deferred_io_cleanup(info);
54913 kfree(info->fbdefio);
54914 info->fbdefio = NULL;
54915- info->fbops->fb_mmap = ufx_ops_mmap;
54916+ pax_open_kernel();
54917+ *(void **)&info->fbops->fb_mmap = ufx_ops_mmap;
54918+ pax_close_kernel();
54919 }
54920
54921 pr_debug("released /dev/fb%d user=%d count=%d",
54922diff --git a/drivers/video/fbdev/udlfb.c b/drivers/video/fbdev/udlfb.c
54923index 046d51d..be564da 100644
54924--- a/drivers/video/fbdev/udlfb.c
54925+++ b/drivers/video/fbdev/udlfb.c
54926@@ -623,11 +623,11 @@ static int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
54927 dlfb_urb_completion(urb);
54928
54929 error:
54930- atomic_add(bytes_sent, &dev->bytes_sent);
54931- atomic_add(bytes_identical, &dev->bytes_identical);
54932- atomic_add(width*height*2, &dev->bytes_rendered);
54933+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
54934+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
54935+ atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
54936 end_cycles = get_cycles();
54937- atomic_add(((unsigned int) ((end_cycles - start_cycles)
54938+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
54939 >> 10)), /* Kcycles */
54940 &dev->cpu_kcycles_used);
54941
54942@@ -748,11 +748,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
54943 dlfb_urb_completion(urb);
54944
54945 error:
54946- atomic_add(bytes_sent, &dev->bytes_sent);
54947- atomic_add(bytes_identical, &dev->bytes_identical);
54948- atomic_add(bytes_rendered, &dev->bytes_rendered);
54949+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
54950+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
54951+ atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
54952 end_cycles = get_cycles();
54953- atomic_add(((unsigned int) ((end_cycles - start_cycles)
54954+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
54955 >> 10)), /* Kcycles */
54956 &dev->cpu_kcycles_used);
54957 }
54958@@ -993,7 +993,9 @@ static int dlfb_ops_release(struct fb_info *info, int user)
54959 fb_deferred_io_cleanup(info);
54960 kfree(info->fbdefio);
54961 info->fbdefio = NULL;
54962- info->fbops->fb_mmap = dlfb_ops_mmap;
54963+ pax_open_kernel();
54964+ *(void **)&info->fbops->fb_mmap = dlfb_ops_mmap;
54965+ pax_close_kernel();
54966 }
54967
54968 pr_warn("released /dev/fb%d user=%d count=%d\n",
54969@@ -1376,7 +1378,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
54970 struct fb_info *fb_info = dev_get_drvdata(fbdev);
54971 struct dlfb_data *dev = fb_info->par;
54972 return snprintf(buf, PAGE_SIZE, "%u\n",
54973- atomic_read(&dev->bytes_rendered));
54974+ atomic_read_unchecked(&dev->bytes_rendered));
54975 }
54976
54977 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
54978@@ -1384,7 +1386,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
54979 struct fb_info *fb_info = dev_get_drvdata(fbdev);
54980 struct dlfb_data *dev = fb_info->par;
54981 return snprintf(buf, PAGE_SIZE, "%u\n",
54982- atomic_read(&dev->bytes_identical));
54983+ atomic_read_unchecked(&dev->bytes_identical));
54984 }
54985
54986 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
54987@@ -1392,7 +1394,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
54988 struct fb_info *fb_info = dev_get_drvdata(fbdev);
54989 struct dlfb_data *dev = fb_info->par;
54990 return snprintf(buf, PAGE_SIZE, "%u\n",
54991- atomic_read(&dev->bytes_sent));
54992+ atomic_read_unchecked(&dev->bytes_sent));
54993 }
54994
54995 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
54996@@ -1400,7 +1402,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
54997 struct fb_info *fb_info = dev_get_drvdata(fbdev);
54998 struct dlfb_data *dev = fb_info->par;
54999 return snprintf(buf, PAGE_SIZE, "%u\n",
55000- atomic_read(&dev->cpu_kcycles_used));
55001+ atomic_read_unchecked(&dev->cpu_kcycles_used));
55002 }
55003
55004 static ssize_t edid_show(
55005@@ -1460,10 +1462,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
55006 struct fb_info *fb_info = dev_get_drvdata(fbdev);
55007 struct dlfb_data *dev = fb_info->par;
55008
55009- atomic_set(&dev->bytes_rendered, 0);
55010- atomic_set(&dev->bytes_identical, 0);
55011- atomic_set(&dev->bytes_sent, 0);
55012- atomic_set(&dev->cpu_kcycles_used, 0);
55013+ atomic_set_unchecked(&dev->bytes_rendered, 0);
55014+ atomic_set_unchecked(&dev->bytes_identical, 0);
55015+ atomic_set_unchecked(&dev->bytes_sent, 0);
55016+ atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
55017
55018 return count;
55019 }
55020diff --git a/drivers/video/fbdev/uvesafb.c b/drivers/video/fbdev/uvesafb.c
55021index 509d452..7c9d2de 100644
55022--- a/drivers/video/fbdev/uvesafb.c
55023+++ b/drivers/video/fbdev/uvesafb.c
55024@@ -19,6 +19,7 @@
55025 #include <linux/io.h>
55026 #include <linux/mutex.h>
55027 #include <linux/slab.h>
55028+#include <linux/moduleloader.h>
55029 #include <video/edid.h>
55030 #include <video/uvesafb.h>
55031 #ifdef CONFIG_X86
55032@@ -565,10 +566,32 @@ static int uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
55033 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
55034 par->pmi_setpal = par->ypan = 0;
55035 } else {
55036+
55037+#ifdef CONFIG_PAX_KERNEXEC
55038+#ifdef CONFIG_MODULES
55039+ par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
55040+#endif
55041+ if (!par->pmi_code) {
55042+ par->pmi_setpal = par->ypan = 0;
55043+ return 0;
55044+ }
55045+#endif
55046+
55047 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
55048 + task->t.regs.edi);
55049+
55050+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55051+ pax_open_kernel();
55052+ memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
55053+ pax_close_kernel();
55054+
55055+ par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
55056+ par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
55057+#else
55058 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
55059 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
55060+#endif
55061+
55062 printk(KERN_INFO "uvesafb: protected mode interface info at "
55063 "%04x:%04x\n",
55064 (u16)task->t.regs.es, (u16)task->t.regs.edi);
55065@@ -813,13 +836,14 @@ static int uvesafb_vbe_init(struct fb_info *info)
55066 par->ypan = ypan;
55067
55068 if (par->pmi_setpal || par->ypan) {
55069+#if !defined(CONFIG_MODULES) || !defined(CONFIG_PAX_KERNEXEC)
55070 if (__supported_pte_mask & _PAGE_NX) {
55071 par->pmi_setpal = par->ypan = 0;
55072 printk(KERN_WARNING "uvesafb: NX protection is active, "
55073 "better not use the PMI.\n");
55074- } else {
55075+ } else
55076+#endif
55077 uvesafb_vbe_getpmi(task, par);
55078- }
55079 }
55080 #else
55081 /* The protected mode interface is not available on non-x86. */
55082@@ -1453,8 +1477,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
55083 info->fix.ywrapstep = (par->ypan > 1) ? 1 : 0;
55084
55085 /* Disable blanking if the user requested so. */
55086- if (!blank)
55087- info->fbops->fb_blank = NULL;
55088+ if (!blank) {
55089+ pax_open_kernel();
55090+ *(void **)&info->fbops->fb_blank = NULL;
55091+ pax_close_kernel();
55092+ }
55093
55094 /*
55095 * Find out how much IO memory is required for the mode with
55096@@ -1525,8 +1552,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
55097 info->flags = FBINFO_FLAG_DEFAULT |
55098 (par->ypan ? FBINFO_HWACCEL_YPAN : 0);
55099
55100- if (!par->ypan)
55101- info->fbops->fb_pan_display = NULL;
55102+ if (!par->ypan) {
55103+ pax_open_kernel();
55104+ *(void **)&info->fbops->fb_pan_display = NULL;
55105+ pax_close_kernel();
55106+ }
55107 }
55108
55109 static void uvesafb_init_mtrr(struct fb_info *info)
55110@@ -1787,6 +1817,11 @@ out_mode:
55111 out:
55112 kfree(par->vbe_modes);
55113
55114+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55115+ if (par->pmi_code)
55116+ module_free_exec(NULL, par->pmi_code);
55117+#endif
55118+
55119 framebuffer_release(info);
55120 return err;
55121 }
55122@@ -1811,6 +1846,11 @@ static int uvesafb_remove(struct platform_device *dev)
55123 kfree(par->vbe_state_orig);
55124 kfree(par->vbe_state_saved);
55125
55126+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55127+ if (par->pmi_code)
55128+ module_free_exec(NULL, par->pmi_code);
55129+#endif
55130+
55131 framebuffer_release(info);
55132 }
55133 return 0;
55134diff --git a/drivers/video/fbdev/vesafb.c b/drivers/video/fbdev/vesafb.c
55135index 6170e7f..dd63031 100644
55136--- a/drivers/video/fbdev/vesafb.c
55137+++ b/drivers/video/fbdev/vesafb.c
55138@@ -9,6 +9,7 @@
55139 */
55140
55141 #include <linux/module.h>
55142+#include <linux/moduleloader.h>
55143 #include <linux/kernel.h>
55144 #include <linux/errno.h>
55145 #include <linux/string.h>
55146@@ -52,8 +53,8 @@ static int vram_remap; /* Set amount of memory to be used */
55147 static int vram_total; /* Set total amount of memory */
55148 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
55149 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
55150-static void (*pmi_start)(void) __read_mostly;
55151-static void (*pmi_pal) (void) __read_mostly;
55152+static void (*pmi_start)(void) __read_only;
55153+static void (*pmi_pal) (void) __read_only;
55154 static int depth __read_mostly;
55155 static int vga_compat __read_mostly;
55156 /* --------------------------------------------------------------------- */
55157@@ -233,6 +234,7 @@ static int vesafb_probe(struct platform_device *dev)
55158 unsigned int size_remap;
55159 unsigned int size_total;
55160 char *option = NULL;
55161+ void *pmi_code = NULL;
55162
55163 /* ignore error return of fb_get_options */
55164 fb_get_options("vesafb", &option);
55165@@ -279,10 +281,6 @@ static int vesafb_probe(struct platform_device *dev)
55166 size_remap = size_total;
55167 vesafb_fix.smem_len = size_remap;
55168
55169-#ifndef __i386__
55170- screen_info.vesapm_seg = 0;
55171-#endif
55172-
55173 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
55174 printk(KERN_WARNING
55175 "vesafb: cannot reserve video memory at 0x%lx\n",
55176@@ -312,9 +310,21 @@ static int vesafb_probe(struct platform_device *dev)
55177 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
55178 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
55179
55180+#ifdef __i386__
55181+
55182+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55183+ pmi_code = module_alloc_exec(screen_info.vesapm_size);
55184+ if (!pmi_code)
55185+#elif !defined(CONFIG_PAX_KERNEXEC)
55186+ if (0)
55187+#endif
55188+
55189+#endif
55190+ screen_info.vesapm_seg = 0;
55191+
55192 if (screen_info.vesapm_seg) {
55193- printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
55194- screen_info.vesapm_seg,screen_info.vesapm_off);
55195+ printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
55196+ screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
55197 }
55198
55199 if (screen_info.vesapm_seg < 0xc000)
55200@@ -322,9 +332,25 @@ static int vesafb_probe(struct platform_device *dev)
55201
55202 if (ypan || pmi_setpal) {
55203 unsigned short *pmi_base;
55204+
55205 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
55206- pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
55207- pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
55208+
55209+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55210+ pax_open_kernel();
55211+ memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
55212+#else
55213+ pmi_code = pmi_base;
55214+#endif
55215+
55216+ pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
55217+ pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
55218+
55219+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55220+ pmi_start = ktva_ktla(pmi_start);
55221+ pmi_pal = ktva_ktla(pmi_pal);
55222+ pax_close_kernel();
55223+#endif
55224+
55225 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
55226 if (pmi_base[3]) {
55227 printk(KERN_INFO "vesafb: pmi: ports = ");
55228@@ -477,8 +503,11 @@ static int vesafb_probe(struct platform_device *dev)
55229 info->flags = FBINFO_FLAG_DEFAULT | FBINFO_MISC_FIRMWARE |
55230 (ypan ? FBINFO_HWACCEL_YPAN : 0);
55231
55232- if (!ypan)
55233- info->fbops->fb_pan_display = NULL;
55234+ if (!ypan) {
55235+ pax_open_kernel();
55236+ *(void **)&info->fbops->fb_pan_display = NULL;
55237+ pax_close_kernel();
55238+ }
55239
55240 if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) {
55241 err = -ENOMEM;
55242@@ -492,6 +521,11 @@ static int vesafb_probe(struct platform_device *dev)
55243 fb_info(info, "%s frame buffer device\n", info->fix.id);
55244 return 0;
55245 err:
55246+
55247+#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55248+ module_free_exec(NULL, pmi_code);
55249+#endif
55250+
55251 if (info->screen_base)
55252 iounmap(info->screen_base);
55253 framebuffer_release(info);
55254diff --git a/drivers/video/fbdev/via/via_clock.h b/drivers/video/fbdev/via/via_clock.h
55255index 88714ae..16c2e11 100644
55256--- a/drivers/video/fbdev/via/via_clock.h
55257+++ b/drivers/video/fbdev/via/via_clock.h
55258@@ -56,7 +56,7 @@ struct via_clock {
55259
55260 void (*set_engine_pll_state)(u8 state);
55261 void (*set_engine_pll)(struct via_pll_config config);
55262-};
55263+} __no_const;
55264
55265
55266 static inline u32 get_pll_internal_frequency(u32 ref_freq,
55267diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
55268index 3c14e43..2630570 100644
55269--- a/drivers/video/logo/logo_linux_clut224.ppm
55270+++ b/drivers/video/logo/logo_linux_clut224.ppm
55271@@ -2,1603 +2,1123 @@ P3
55272 # Standard 224-color Linux logo
55273 80 80
55274 255
55275- 0 0 0 0 0 0 0 0 0 0 0 0
55276- 0 0 0 0 0 0 0 0 0 0 0 0
55277- 0 0 0 0 0 0 0 0 0 0 0 0
55278- 0 0 0 0 0 0 0 0 0 0 0 0
55279- 0 0 0 0 0 0 0 0 0 0 0 0
55280- 0 0 0 0 0 0 0 0 0 0 0 0
55281- 0 0 0 0 0 0 0 0 0 0 0 0
55282- 0 0 0 0 0 0 0 0 0 0 0 0
55283- 0 0 0 0 0 0 0 0 0 0 0 0
55284- 6 6 6 6 6 6 10 10 10 10 10 10
55285- 10 10 10 6 6 6 6 6 6 6 6 6
55286- 0 0 0 0 0 0 0 0 0 0 0 0
55287- 0 0 0 0 0 0 0 0 0 0 0 0
55288- 0 0 0 0 0 0 0 0 0 0 0 0
55289- 0 0 0 0 0 0 0 0 0 0 0 0
55290- 0 0 0 0 0 0 0 0 0 0 0 0
55291- 0 0 0 0 0 0 0 0 0 0 0 0
55292- 0 0 0 0 0 0 0 0 0 0 0 0
55293- 0 0 0 0 0 0 0 0 0 0 0 0
55294- 0 0 0 0 0 0 0 0 0 0 0 0
55295- 0 0 0 0 0 0 0 0 0 0 0 0
55296- 0 0 0 0 0 0 0 0 0 0 0 0
55297- 0 0 0 0 0 0 0 0 0 0 0 0
55298- 0 0 0 0 0 0 0 0 0 0 0 0
55299- 0 0 0 0 0 0 0 0 0 0 0 0
55300- 0 0 0 0 0 0 0 0 0 0 0 0
55301- 0 0 0 0 0 0 0 0 0 0 0 0
55302- 0 0 0 0 0 0 0 0 0 0 0 0
55303- 0 0 0 6 6 6 10 10 10 14 14 14
55304- 22 22 22 26 26 26 30 30 30 34 34 34
55305- 30 30 30 30 30 30 26 26 26 18 18 18
55306- 14 14 14 10 10 10 6 6 6 0 0 0
55307- 0 0 0 0 0 0 0 0 0 0 0 0
55308- 0 0 0 0 0 0 0 0 0 0 0 0
55309- 0 0 0 0 0 0 0 0 0 0 0 0
55310- 0 0 0 0 0 0 0 0 0 0 0 0
55311- 0 0 0 0 0 0 0 0 0 0 0 0
55312- 0 0 0 0 0 0 0 0 0 0 0 0
55313- 0 0 0 0 0 0 0 0 0 0 0 0
55314- 0 0 0 0 0 0 0 0 0 0 0 0
55315- 0 0 0 0 0 0 0 0 0 0 0 0
55316- 0 0 0 0 0 1 0 0 1 0 0 0
55317- 0 0 0 0 0 0 0 0 0 0 0 0
55318- 0 0 0 0 0 0 0 0 0 0 0 0
55319- 0 0 0 0 0 0 0 0 0 0 0 0
55320- 0 0 0 0 0 0 0 0 0 0 0 0
55321- 0 0 0 0 0 0 0 0 0 0 0 0
55322- 0 0 0 0 0 0 0 0 0 0 0 0
55323- 6 6 6 14 14 14 26 26 26 42 42 42
55324- 54 54 54 66 66 66 78 78 78 78 78 78
55325- 78 78 78 74 74 74 66 66 66 54 54 54
55326- 42 42 42 26 26 26 18 18 18 10 10 10
55327- 6 6 6 0 0 0 0 0 0 0 0 0
55328- 0 0 0 0 0 0 0 0 0 0 0 0
55329- 0 0 0 0 0 0 0 0 0 0 0 0
55330- 0 0 0 0 0 0 0 0 0 0 0 0
55331- 0 0 0 0 0 0 0 0 0 0 0 0
55332- 0 0 0 0 0 0 0 0 0 0 0 0
55333- 0 0 0 0 0 0 0 0 0 0 0 0
55334- 0 0 0 0 0 0 0 0 0 0 0 0
55335- 0 0 0 0 0 0 0 0 0 0 0 0
55336- 0 0 1 0 0 0 0 0 0 0 0 0
55337- 0 0 0 0 0 0 0 0 0 0 0 0
55338- 0 0 0 0 0 0 0 0 0 0 0 0
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 10 10 10
55343- 22 22 22 42 42 42 66 66 66 86 86 86
55344- 66 66 66 38 38 38 38 38 38 22 22 22
55345- 26 26 26 34 34 34 54 54 54 66 66 66
55346- 86 86 86 70 70 70 46 46 46 26 26 26
55347- 14 14 14 6 6 6 0 0 0 0 0 0
55348- 0 0 0 0 0 0 0 0 0 0 0 0
55349- 0 0 0 0 0 0 0 0 0 0 0 0
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 1 0 0 1 0 0 1 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 10 10 10 26 26 26
55363- 50 50 50 82 82 82 58 58 58 6 6 6
55364- 2 2 6 2 2 6 2 2 6 2 2 6
55365- 2 2 6 2 2 6 2 2 6 2 2 6
55366- 6 6 6 54 54 54 86 86 86 66 66 66
55367- 38 38 38 18 18 18 6 6 6 0 0 0
55368- 0 0 0 0 0 0 0 0 0 0 0 0
55369- 0 0 0 0 0 0 0 0 0 0 0 0
55370- 0 0 0 0 0 0 0 0 0 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 0 0 0 0 0 0 0
55381- 0 0 0 0 0 0 0 0 0 0 0 0
55382- 0 0 0 6 6 6 22 22 22 50 50 50
55383- 78 78 78 34 34 34 2 2 6 2 2 6
55384- 2 2 6 2 2 6 2 2 6 2 2 6
55385- 2 2 6 2 2 6 2 2 6 2 2 6
55386- 2 2 6 2 2 6 6 6 6 70 70 70
55387- 78 78 78 46 46 46 22 22 22 6 6 6
55388- 0 0 0 0 0 0 0 0 0 0 0 0
55389- 0 0 0 0 0 0 0 0 0 0 0 0
55390- 0 0 0 0 0 0 0 0 0 0 0 0
55391- 0 0 0 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 1 0 0 1 0 0 1 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 0 0 0 0 0 0 0 0 0 0
55401- 0 0 0 0 0 0 0 0 0 0 0 0
55402- 6 6 6 18 18 18 42 42 42 82 82 82
55403- 26 26 26 2 2 6 2 2 6 2 2 6
55404- 2 2 6 2 2 6 2 2 6 2 2 6
55405- 2 2 6 2 2 6 2 2 6 14 14 14
55406- 46 46 46 34 34 34 6 6 6 2 2 6
55407- 42 42 42 78 78 78 42 42 42 18 18 18
55408- 6 6 6 0 0 0 0 0 0 0 0 0
55409- 0 0 0 0 0 0 0 0 0 0 0 0
55410- 0 0 0 0 0 0 0 0 0 0 0 0
55411- 0 0 0 0 0 0 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 1 0 0 0 0 0 1 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 0 0 0 0 0 0 0 0 0 0
55421- 0 0 0 0 0 0 0 0 0 0 0 0
55422- 10 10 10 30 30 30 66 66 66 58 58 58
55423- 2 2 6 2 2 6 2 2 6 2 2 6
55424- 2 2 6 2 2 6 2 2 6 2 2 6
55425- 2 2 6 2 2 6 2 2 6 26 26 26
55426- 86 86 86 101 101 101 46 46 46 10 10 10
55427- 2 2 6 58 58 58 70 70 70 34 34 34
55428- 10 10 10 0 0 0 0 0 0 0 0 0
55429- 0 0 0 0 0 0 0 0 0 0 0 0
55430- 0 0 0 0 0 0 0 0 0 0 0 0
55431- 0 0 0 0 0 0 0 0 0 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 1 0 0 1 0 0 1 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- 14 14 14 42 42 42 86 86 86 10 10 10
55443- 2 2 6 2 2 6 2 2 6 2 2 6
55444- 2 2 6 2 2 6 2 2 6 2 2 6
55445- 2 2 6 2 2 6 2 2 6 30 30 30
55446- 94 94 94 94 94 94 58 58 58 26 26 26
55447- 2 2 6 6 6 6 78 78 78 54 54 54
55448- 22 22 22 6 6 6 0 0 0 0 0 0
55449- 0 0 0 0 0 0 0 0 0 0 0 0
55450- 0 0 0 0 0 0 0 0 0 0 0 0
55451- 0 0 0 0 0 0 0 0 0 0 0 0
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 0 0 0 0 0 0 0 0 0 0
55461- 0 0 0 0 0 0 0 0 0 6 6 6
55462- 22 22 22 62 62 62 62 62 62 2 2 6
55463- 2 2 6 2 2 6 2 2 6 2 2 6
55464- 2 2 6 2 2 6 2 2 6 2 2 6
55465- 2 2 6 2 2 6 2 2 6 26 26 26
55466- 54 54 54 38 38 38 18 18 18 10 10 10
55467- 2 2 6 2 2 6 34 34 34 82 82 82
55468- 38 38 38 14 14 14 0 0 0 0 0 0
55469- 0 0 0 0 0 0 0 0 0 0 0 0
55470- 0 0 0 0 0 0 0 0 0 0 0 0
55471- 0 0 0 0 0 0 0 0 0 0 0 0
55472- 0 0 0 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 1 0 0 1 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 0 0 0 0 0 0 0 0 0 0
55481- 0 0 0 0 0 0 0 0 0 6 6 6
55482- 30 30 30 78 78 78 30 30 30 2 2 6
55483- 2 2 6 2 2 6 2 2 6 2 2 6
55484- 2 2 6 2 2 6 2 2 6 2 2 6
55485- 2 2 6 2 2 6 2 2 6 10 10 10
55486- 10 10 10 2 2 6 2 2 6 2 2 6
55487- 2 2 6 2 2 6 2 2 6 78 78 78
55488- 50 50 50 18 18 18 6 6 6 0 0 0
55489- 0 0 0 0 0 0 0 0 0 0 0 0
55490- 0 0 0 0 0 0 0 0 0 0 0 0
55491- 0 0 0 0 0 0 0 0 0 0 0 0
55492- 0 0 0 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 1 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 0 0 0 0 0 0 0 0 0 0
55501- 0 0 0 0 0 0 0 0 0 10 10 10
55502- 38 38 38 86 86 86 14 14 14 2 2 6
55503- 2 2 6 2 2 6 2 2 6 2 2 6
55504- 2 2 6 2 2 6 2 2 6 2 2 6
55505- 2 2 6 2 2 6 2 2 6 2 2 6
55506- 2 2 6 2 2 6 2 2 6 2 2 6
55507- 2 2 6 2 2 6 2 2 6 54 54 54
55508- 66 66 66 26 26 26 6 6 6 0 0 0
55509- 0 0 0 0 0 0 0 0 0 0 0 0
55510- 0 0 0 0 0 0 0 0 0 0 0 0
55511- 0 0 0 0 0 0 0 0 0 0 0 0
55512- 0 0 0 0 0 0 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 1 0 0 1 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 14 14 14
55522- 42 42 42 82 82 82 2 2 6 2 2 6
55523- 2 2 6 6 6 6 10 10 10 2 2 6
55524- 2 2 6 2 2 6 2 2 6 2 2 6
55525- 2 2 6 2 2 6 2 2 6 6 6 6
55526- 14 14 14 10 10 10 2 2 6 2 2 6
55527- 2 2 6 2 2 6 2 2 6 18 18 18
55528- 82 82 82 34 34 34 10 10 10 0 0 0
55529- 0 0 0 0 0 0 0 0 0 0 0 0
55530- 0 0 0 0 0 0 0 0 0 0 0 0
55531- 0 0 0 0 0 0 0 0 0 0 0 0
55532- 0 0 0 0 0 0 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 1 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 0 0 0 0 0 0 0
55541- 0 0 0 0 0 0 0 0 0 14 14 14
55542- 46 46 46 86 86 86 2 2 6 2 2 6
55543- 6 6 6 6 6 6 22 22 22 34 34 34
55544- 6 6 6 2 2 6 2 2 6 2 2 6
55545- 2 2 6 2 2 6 18 18 18 34 34 34
55546- 10 10 10 50 50 50 22 22 22 2 2 6
55547- 2 2 6 2 2 6 2 2 6 10 10 10
55548- 86 86 86 42 42 42 14 14 14 0 0 0
55549- 0 0 0 0 0 0 0 0 0 0 0 0
55550- 0 0 0 0 0 0 0 0 0 0 0 0
55551- 0 0 0 0 0 0 0 0 0 0 0 0
55552- 0 0 0 0 0 0 0 0 0 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 1 0 0 1 0 0 1 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 0 0 0 0 0 0 0 0 0 0
55561- 0 0 0 0 0 0 0 0 0 14 14 14
55562- 46 46 46 86 86 86 2 2 6 2 2 6
55563- 38 38 38 116 116 116 94 94 94 22 22 22
55564- 22 22 22 2 2 6 2 2 6 2 2 6
55565- 14 14 14 86 86 86 138 138 138 162 162 162
55566-154 154 154 38 38 38 26 26 26 6 6 6
55567- 2 2 6 2 2 6 2 2 6 2 2 6
55568- 86 86 86 46 46 46 14 14 14 0 0 0
55569- 0 0 0 0 0 0 0 0 0 0 0 0
55570- 0 0 0 0 0 0 0 0 0 0 0 0
55571- 0 0 0 0 0 0 0 0 0 0 0 0
55572- 0 0 0 0 0 0 0 0 0 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 0 0 0 0 0 0 0
55581- 0 0 0 0 0 0 0 0 0 14 14 14
55582- 46 46 46 86 86 86 2 2 6 14 14 14
55583-134 134 134 198 198 198 195 195 195 116 116 116
55584- 10 10 10 2 2 6 2 2 6 6 6 6
55585-101 98 89 187 187 187 210 210 210 218 218 218
55586-214 214 214 134 134 134 14 14 14 6 6 6
55587- 2 2 6 2 2 6 2 2 6 2 2 6
55588- 86 86 86 50 50 50 18 18 18 6 6 6
55589- 0 0 0 0 0 0 0 0 0 0 0 0
55590- 0 0 0 0 0 0 0 0 0 0 0 0
55591- 0 0 0 0 0 0 0 0 0 0 0 0
55592- 0 0 0 0 0 0 0 0 0 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 1 0 0 0
55596- 0 0 1 0 0 1 0 0 1 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 0 0 0 0 0 0 0 0 0 0
55601- 0 0 0 0 0 0 0 0 0 14 14 14
55602- 46 46 46 86 86 86 2 2 6 54 54 54
55603-218 218 218 195 195 195 226 226 226 246 246 246
55604- 58 58 58 2 2 6 2 2 6 30 30 30
55605-210 210 210 253 253 253 174 174 174 123 123 123
55606-221 221 221 234 234 234 74 74 74 2 2 6
55607- 2 2 6 2 2 6 2 2 6 2 2 6
55608- 70 70 70 58 58 58 22 22 22 6 6 6
55609- 0 0 0 0 0 0 0 0 0 0 0 0
55610- 0 0 0 0 0 0 0 0 0 0 0 0
55611- 0 0 0 0 0 0 0 0 0 0 0 0
55612- 0 0 0 0 0 0 0 0 0 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 0 0 0 0 0 0 0 0 0 0
55621- 0 0 0 0 0 0 0 0 0 14 14 14
55622- 46 46 46 82 82 82 2 2 6 106 106 106
55623-170 170 170 26 26 26 86 86 86 226 226 226
55624-123 123 123 10 10 10 14 14 14 46 46 46
55625-231 231 231 190 190 190 6 6 6 70 70 70
55626- 90 90 90 238 238 238 158 158 158 2 2 6
55627- 2 2 6 2 2 6 2 2 6 2 2 6
55628- 70 70 70 58 58 58 22 22 22 6 6 6
55629- 0 0 0 0 0 0 0 0 0 0 0 0
55630- 0 0 0 0 0 0 0 0 0 0 0 0
55631- 0 0 0 0 0 0 0 0 0 0 0 0
55632- 0 0 0 0 0 0 0 0 0 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 1 0 0 0
55636- 0 0 1 0 0 1 0 0 1 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 14 14 14
55642- 42 42 42 86 86 86 6 6 6 116 116 116
55643-106 106 106 6 6 6 70 70 70 149 149 149
55644-128 128 128 18 18 18 38 38 38 54 54 54
55645-221 221 221 106 106 106 2 2 6 14 14 14
55646- 46 46 46 190 190 190 198 198 198 2 2 6
55647- 2 2 6 2 2 6 2 2 6 2 2 6
55648- 74 74 74 62 62 62 22 22 22 6 6 6
55649- 0 0 0 0 0 0 0 0 0 0 0 0
55650- 0 0 0 0 0 0 0 0 0 0 0 0
55651- 0 0 0 0 0 0 0 0 0 0 0 0
55652- 0 0 0 0 0 0 0 0 0 0 0 0
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 1 0 0 0
55656- 0 0 1 0 0 0 0 0 1 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 0 0 0 0
55660- 0 0 0 0 0 0 0 0 0 0 0 0
55661- 0 0 0 0 0 0 0 0 0 14 14 14
55662- 42 42 42 94 94 94 14 14 14 101 101 101
55663-128 128 128 2 2 6 18 18 18 116 116 116
55664-118 98 46 121 92 8 121 92 8 98 78 10
55665-162 162 162 106 106 106 2 2 6 2 2 6
55666- 2 2 6 195 195 195 195 195 195 6 6 6
55667- 2 2 6 2 2 6 2 2 6 2 2 6
55668- 74 74 74 62 62 62 22 22 22 6 6 6
55669- 0 0 0 0 0 0 0 0 0 0 0 0
55670- 0 0 0 0 0 0 0 0 0 0 0 0
55671- 0 0 0 0 0 0 0 0 0 0 0 0
55672- 0 0 0 0 0 0 0 0 0 0 0 0
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 1 0 0 1
55676- 0 0 1 0 0 0 0 0 1 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 10 10 10
55682- 38 38 38 90 90 90 14 14 14 58 58 58
55683-210 210 210 26 26 26 54 38 6 154 114 10
55684-226 170 11 236 186 11 225 175 15 184 144 12
55685-215 174 15 175 146 61 37 26 9 2 2 6
55686- 70 70 70 246 246 246 138 138 138 2 2 6
55687- 2 2 6 2 2 6 2 2 6 2 2 6
55688- 70 70 70 66 66 66 26 26 26 6 6 6
55689- 0 0 0 0 0 0 0 0 0 0 0 0
55690- 0 0 0 0 0 0 0 0 0 0 0 0
55691- 0 0 0 0 0 0 0 0 0 0 0 0
55692- 0 0 0 0 0 0 0 0 0 0 0 0
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 0 0 0 0
55700- 0 0 0 0 0 0 0 0 0 0 0 0
55701- 0 0 0 0 0 0 0 0 0 10 10 10
55702- 38 38 38 86 86 86 14 14 14 10 10 10
55703-195 195 195 188 164 115 192 133 9 225 175 15
55704-239 182 13 234 190 10 232 195 16 232 200 30
55705-245 207 45 241 208 19 232 195 16 184 144 12
55706-218 194 134 211 206 186 42 42 42 2 2 6
55707- 2 2 6 2 2 6 2 2 6 2 2 6
55708- 50 50 50 74 74 74 30 30 30 6 6 6
55709- 0 0 0 0 0 0 0 0 0 0 0 0
55710- 0 0 0 0 0 0 0 0 0 0 0 0
55711- 0 0 0 0 0 0 0 0 0 0 0 0
55712- 0 0 0 0 0 0 0 0 0 0 0 0
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 0 0 0 0
55720- 0 0 0 0 0 0 0 0 0 0 0 0
55721- 0 0 0 0 0 0 0 0 0 10 10 10
55722- 34 34 34 86 86 86 14 14 14 2 2 6
55723-121 87 25 192 133 9 219 162 10 239 182 13
55724-236 186 11 232 195 16 241 208 19 244 214 54
55725-246 218 60 246 218 38 246 215 20 241 208 19
55726-241 208 19 226 184 13 121 87 25 2 2 6
55727- 2 2 6 2 2 6 2 2 6 2 2 6
55728- 50 50 50 82 82 82 34 34 34 10 10 10
55729- 0 0 0 0 0 0 0 0 0 0 0 0
55730- 0 0 0 0 0 0 0 0 0 0 0 0
55731- 0 0 0 0 0 0 0 0 0 0 0 0
55732- 0 0 0 0 0 0 0 0 0 0 0 0
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 0 0 0 0
55740- 0 0 0 0 0 0 0 0 0 0 0 0
55741- 0 0 0 0 0 0 0 0 0 10 10 10
55742- 34 34 34 82 82 82 30 30 30 61 42 6
55743-180 123 7 206 145 10 230 174 11 239 182 13
55744-234 190 10 238 202 15 241 208 19 246 218 74
55745-246 218 38 246 215 20 246 215 20 246 215 20
55746-226 184 13 215 174 15 184 144 12 6 6 6
55747- 2 2 6 2 2 6 2 2 6 2 2 6
55748- 26 26 26 94 94 94 42 42 42 14 14 14
55749- 0 0 0 0 0 0 0 0 0 0 0 0
55750- 0 0 0 0 0 0 0 0 0 0 0 0
55751- 0 0 0 0 0 0 0 0 0 0 0 0
55752- 0 0 0 0 0 0 0 0 0 0 0 0
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 10 10 10
55762- 30 30 30 78 78 78 50 50 50 104 69 6
55763-192 133 9 216 158 10 236 178 12 236 186 11
55764-232 195 16 241 208 19 244 214 54 245 215 43
55765-246 215 20 246 215 20 241 208 19 198 155 10
55766-200 144 11 216 158 10 156 118 10 2 2 6
55767- 2 2 6 2 2 6 2 2 6 2 2 6
55768- 6 6 6 90 90 90 54 54 54 18 18 18
55769- 6 6 6 0 0 0 0 0 0 0 0 0
55770- 0 0 0 0 0 0 0 0 0 0 0 0
55771- 0 0 0 0 0 0 0 0 0 0 0 0
55772- 0 0 0 0 0 0 0 0 0 0 0 0
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 10 10 10
55782- 30 30 30 78 78 78 46 46 46 22 22 22
55783-137 92 6 210 162 10 239 182 13 238 190 10
55784-238 202 15 241 208 19 246 215 20 246 215 20
55785-241 208 19 203 166 17 185 133 11 210 150 10
55786-216 158 10 210 150 10 102 78 10 2 2 6
55787- 6 6 6 54 54 54 14 14 14 2 2 6
55788- 2 2 6 62 62 62 74 74 74 30 30 30
55789- 10 10 10 0 0 0 0 0 0 0 0 0
55790- 0 0 0 0 0 0 0 0 0 0 0 0
55791- 0 0 0 0 0 0 0 0 0 0 0 0
55792- 0 0 0 0 0 0 0 0 0 0 0 0
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 10 10 10
55802- 34 34 34 78 78 78 50 50 50 6 6 6
55803- 94 70 30 139 102 15 190 146 13 226 184 13
55804-232 200 30 232 195 16 215 174 15 190 146 13
55805-168 122 10 192 133 9 210 150 10 213 154 11
55806-202 150 34 182 157 106 101 98 89 2 2 6
55807- 2 2 6 78 78 78 116 116 116 58 58 58
55808- 2 2 6 22 22 22 90 90 90 46 46 46
55809- 18 18 18 6 6 6 0 0 0 0 0 0
55810- 0 0 0 0 0 0 0 0 0 0 0 0
55811- 0 0 0 0 0 0 0 0 0 0 0 0
55812- 0 0 0 0 0 0 0 0 0 0 0 0
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 10 10 10
55822- 38 38 38 86 86 86 50 50 50 6 6 6
55823-128 128 128 174 154 114 156 107 11 168 122 10
55824-198 155 10 184 144 12 197 138 11 200 144 11
55825-206 145 10 206 145 10 197 138 11 188 164 115
55826-195 195 195 198 198 198 174 174 174 14 14 14
55827- 2 2 6 22 22 22 116 116 116 116 116 116
55828- 22 22 22 2 2 6 74 74 74 70 70 70
55829- 30 30 30 10 10 10 0 0 0 0 0 0
55830- 0 0 0 0 0 0 0 0 0 0 0 0
55831- 0 0 0 0 0 0 0 0 0 0 0 0
55832- 0 0 0 0 0 0 0 0 0 0 0 0
55833- 0 0 0 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 6 6 6 18 18 18
55842- 50 50 50 101 101 101 26 26 26 10 10 10
55843-138 138 138 190 190 190 174 154 114 156 107 11
55844-197 138 11 200 144 11 197 138 11 192 133 9
55845-180 123 7 190 142 34 190 178 144 187 187 187
55846-202 202 202 221 221 221 214 214 214 66 66 66
55847- 2 2 6 2 2 6 50 50 50 62 62 62
55848- 6 6 6 2 2 6 10 10 10 90 90 90
55849- 50 50 50 18 18 18 6 6 6 0 0 0
55850- 0 0 0 0 0 0 0 0 0 0 0 0
55851- 0 0 0 0 0 0 0 0 0 0 0 0
55852- 0 0 0 0 0 0 0 0 0 0 0 0
55853- 0 0 0 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 10 10 10 34 34 34
55862- 74 74 74 74 74 74 2 2 6 6 6 6
55863-144 144 144 198 198 198 190 190 190 178 166 146
55864-154 121 60 156 107 11 156 107 11 168 124 44
55865-174 154 114 187 187 187 190 190 190 210 210 210
55866-246 246 246 253 253 253 253 253 253 182 182 182
55867- 6 6 6 2 2 6 2 2 6 2 2 6
55868- 2 2 6 2 2 6 2 2 6 62 62 62
55869- 74 74 74 34 34 34 14 14 14 0 0 0
55870- 0 0 0 0 0 0 0 0 0 0 0 0
55871- 0 0 0 0 0 0 0 0 0 0 0 0
55872- 0 0 0 0 0 0 0 0 0 0 0 0
55873- 0 0 0 0 0 0 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 10 10 10 22 22 22 54 54 54
55882- 94 94 94 18 18 18 2 2 6 46 46 46
55883-234 234 234 221 221 221 190 190 190 190 190 190
55884-190 190 190 187 187 187 187 187 187 190 190 190
55885-190 190 190 195 195 195 214 214 214 242 242 242
55886-253 253 253 253 253 253 253 253 253 253 253 253
55887- 82 82 82 2 2 6 2 2 6 2 2 6
55888- 2 2 6 2 2 6 2 2 6 14 14 14
55889- 86 86 86 54 54 54 22 22 22 6 6 6
55890- 0 0 0 0 0 0 0 0 0 0 0 0
55891- 0 0 0 0 0 0 0 0 0 0 0 0
55892- 0 0 0 0 0 0 0 0 0 0 0 0
55893- 0 0 0 0 0 0 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- 6 6 6 18 18 18 46 46 46 90 90 90
55902- 46 46 46 18 18 18 6 6 6 182 182 182
55903-253 253 253 246 246 246 206 206 206 190 190 190
55904-190 190 190 190 190 190 190 190 190 190 190 190
55905-206 206 206 231 231 231 250 250 250 253 253 253
55906-253 253 253 253 253 253 253 253 253 253 253 253
55907-202 202 202 14 14 14 2 2 6 2 2 6
55908- 2 2 6 2 2 6 2 2 6 2 2 6
55909- 42 42 42 86 86 86 42 42 42 18 18 18
55910- 6 6 6 0 0 0 0 0 0 0 0 0
55911- 0 0 0 0 0 0 0 0 0 0 0 0
55912- 0 0 0 0 0 0 0 0 0 0 0 0
55913- 0 0 0 0 0 0 0 0 0 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 6 6 6
55921- 14 14 14 38 38 38 74 74 74 66 66 66
55922- 2 2 6 6 6 6 90 90 90 250 250 250
55923-253 253 253 253 253 253 238 238 238 198 198 198
55924-190 190 190 190 190 190 195 195 195 221 221 221
55925-246 246 246 253 253 253 253 253 253 253 253 253
55926-253 253 253 253 253 253 253 253 253 253 253 253
55927-253 253 253 82 82 82 2 2 6 2 2 6
55928- 2 2 6 2 2 6 2 2 6 2 2 6
55929- 2 2 6 78 78 78 70 70 70 34 34 34
55930- 14 14 14 6 6 6 0 0 0 0 0 0
55931- 0 0 0 0 0 0 0 0 0 0 0 0
55932- 0 0 0 0 0 0 0 0 0 0 0 0
55933- 0 0 0 0 0 0 0 0 0 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 14 14 14
55941- 34 34 34 66 66 66 78 78 78 6 6 6
55942- 2 2 6 18 18 18 218 218 218 253 253 253
55943-253 253 253 253 253 253 253 253 253 246 246 246
55944-226 226 226 231 231 231 246 246 246 253 253 253
55945-253 253 253 253 253 253 253 253 253 253 253 253
55946-253 253 253 253 253 253 253 253 253 253 253 253
55947-253 253 253 178 178 178 2 2 6 2 2 6
55948- 2 2 6 2 2 6 2 2 6 2 2 6
55949- 2 2 6 18 18 18 90 90 90 62 62 62
55950- 30 30 30 10 10 10 0 0 0 0 0 0
55951- 0 0 0 0 0 0 0 0 0 0 0 0
55952- 0 0 0 0 0 0 0 0 0 0 0 0
55953- 0 0 0 0 0 0 0 0 0 0 0 0
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 10 10 10 26 26 26
55961- 58 58 58 90 90 90 18 18 18 2 2 6
55962- 2 2 6 110 110 110 253 253 253 253 253 253
55963-253 253 253 253 253 253 253 253 253 253 253 253
55964-250 250 250 253 253 253 253 253 253 253 253 253
55965-253 253 253 253 253 253 253 253 253 253 253 253
55966-253 253 253 253 253 253 253 253 253 253 253 253
55967-253 253 253 231 231 231 18 18 18 2 2 6
55968- 2 2 6 2 2 6 2 2 6 2 2 6
55969- 2 2 6 2 2 6 18 18 18 94 94 94
55970- 54 54 54 26 26 26 10 10 10 0 0 0
55971- 0 0 0 0 0 0 0 0 0 0 0 0
55972- 0 0 0 0 0 0 0 0 0 0 0 0
55973- 0 0 0 0 0 0 0 0 0 0 0 0
55974- 0 0 0 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 6 6 6 22 22 22 50 50 50
55981- 90 90 90 26 26 26 2 2 6 2 2 6
55982- 14 14 14 195 195 195 250 250 250 253 253 253
55983-253 253 253 253 253 253 253 253 253 253 253 253
55984-253 253 253 253 253 253 253 253 253 253 253 253
55985-253 253 253 253 253 253 253 253 253 253 253 253
55986-253 253 253 253 253 253 253 253 253 253 253 253
55987-250 250 250 242 242 242 54 54 54 2 2 6
55988- 2 2 6 2 2 6 2 2 6 2 2 6
55989- 2 2 6 2 2 6 2 2 6 38 38 38
55990- 86 86 86 50 50 50 22 22 22 6 6 6
55991- 0 0 0 0 0 0 0 0 0 0 0 0
55992- 0 0 0 0 0 0 0 0 0 0 0 0
55993- 0 0 0 0 0 0 0 0 0 0 0 0
55994- 0 0 0 0 0 0 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- 6 6 6 14 14 14 38 38 38 82 82 82
56001- 34 34 34 2 2 6 2 2 6 2 2 6
56002- 42 42 42 195 195 195 246 246 246 253 253 253
56003-253 253 253 253 253 253 253 253 253 250 250 250
56004-242 242 242 242 242 242 250 250 250 253 253 253
56005-253 253 253 253 253 253 253 253 253 253 253 253
56006-253 253 253 250 250 250 246 246 246 238 238 238
56007-226 226 226 231 231 231 101 101 101 6 6 6
56008- 2 2 6 2 2 6 2 2 6 2 2 6
56009- 2 2 6 2 2 6 2 2 6 2 2 6
56010- 38 38 38 82 82 82 42 42 42 14 14 14
56011- 6 6 6 0 0 0 0 0 0 0 0 0
56012- 0 0 0 0 0 0 0 0 0 0 0 0
56013- 0 0 0 0 0 0 0 0 0 0 0 0
56014- 0 0 0 0 0 0 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- 10 10 10 26 26 26 62 62 62 66 66 66
56021- 2 2 6 2 2 6 2 2 6 6 6 6
56022- 70 70 70 170 170 170 206 206 206 234 234 234
56023-246 246 246 250 250 250 250 250 250 238 238 238
56024-226 226 226 231 231 231 238 238 238 250 250 250
56025-250 250 250 250 250 250 246 246 246 231 231 231
56026-214 214 214 206 206 206 202 202 202 202 202 202
56027-198 198 198 202 202 202 182 182 182 18 18 18
56028- 2 2 6 2 2 6 2 2 6 2 2 6
56029- 2 2 6 2 2 6 2 2 6 2 2 6
56030- 2 2 6 62 62 62 66 66 66 30 30 30
56031- 10 10 10 0 0 0 0 0 0 0 0 0
56032- 0 0 0 0 0 0 0 0 0 0 0 0
56033- 0 0 0 0 0 0 0 0 0 0 0 0
56034- 0 0 0 0 0 0 0 0 0 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- 14 14 14 42 42 42 82 82 82 18 18 18
56041- 2 2 6 2 2 6 2 2 6 10 10 10
56042- 94 94 94 182 182 182 218 218 218 242 242 242
56043-250 250 250 253 253 253 253 253 253 250 250 250
56044-234 234 234 253 253 253 253 253 253 253 253 253
56045-253 253 253 253 253 253 253 253 253 246 246 246
56046-238 238 238 226 226 226 210 210 210 202 202 202
56047-195 195 195 195 195 195 210 210 210 158 158 158
56048- 6 6 6 14 14 14 50 50 50 14 14 14
56049- 2 2 6 2 2 6 2 2 6 2 2 6
56050- 2 2 6 6 6 6 86 86 86 46 46 46
56051- 18 18 18 6 6 6 0 0 0 0 0 0
56052- 0 0 0 0 0 0 0 0 0 0 0 0
56053- 0 0 0 0 0 0 0 0 0 0 0 0
56054- 0 0 0 0 0 0 0 0 0 0 0 0
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 6 6 6
56060- 22 22 22 54 54 54 70 70 70 2 2 6
56061- 2 2 6 10 10 10 2 2 6 22 22 22
56062-166 166 166 231 231 231 250 250 250 253 253 253
56063-253 253 253 253 253 253 253 253 253 250 250 250
56064-242 242 242 253 253 253 253 253 253 253 253 253
56065-253 253 253 253 253 253 253 253 253 253 253 253
56066-253 253 253 253 253 253 253 253 253 246 246 246
56067-231 231 231 206 206 206 198 198 198 226 226 226
56068- 94 94 94 2 2 6 6 6 6 38 38 38
56069- 30 30 30 2 2 6 2 2 6 2 2 6
56070- 2 2 6 2 2 6 62 62 62 66 66 66
56071- 26 26 26 10 10 10 0 0 0 0 0 0
56072- 0 0 0 0 0 0 0 0 0 0 0 0
56073- 0 0 0 0 0 0 0 0 0 0 0 0
56074- 0 0 0 0 0 0 0 0 0 0 0 0
56075- 0 0 0 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 10 10 10
56080- 30 30 30 74 74 74 50 50 50 2 2 6
56081- 26 26 26 26 26 26 2 2 6 106 106 106
56082-238 238 238 253 253 253 253 253 253 253 253 253
56083-253 253 253 253 253 253 253 253 253 253 253 253
56084-253 253 253 253 253 253 253 253 253 253 253 253
56085-253 253 253 253 253 253 253 253 253 253 253 253
56086-253 253 253 253 253 253 253 253 253 253 253 253
56087-253 253 253 246 246 246 218 218 218 202 202 202
56088-210 210 210 14 14 14 2 2 6 2 2 6
56089- 30 30 30 22 22 22 2 2 6 2 2 6
56090- 2 2 6 2 2 6 18 18 18 86 86 86
56091- 42 42 42 14 14 14 0 0 0 0 0 0
56092- 0 0 0 0 0 0 0 0 0 0 0 0
56093- 0 0 0 0 0 0 0 0 0 0 0 0
56094- 0 0 0 0 0 0 0 0 0 0 0 0
56095- 0 0 0 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 14 14 14
56100- 42 42 42 90 90 90 22 22 22 2 2 6
56101- 42 42 42 2 2 6 18 18 18 218 218 218
56102-253 253 253 253 253 253 253 253 253 253 253 253
56103-253 253 253 253 253 253 253 253 253 253 253 253
56104-253 253 253 253 253 253 253 253 253 253 253 253
56105-253 253 253 253 253 253 253 253 253 253 253 253
56106-253 253 253 253 253 253 253 253 253 253 253 253
56107-253 253 253 253 253 253 250 250 250 221 221 221
56108-218 218 218 101 101 101 2 2 6 14 14 14
56109- 18 18 18 38 38 38 10 10 10 2 2 6
56110- 2 2 6 2 2 6 2 2 6 78 78 78
56111- 58 58 58 22 22 22 6 6 6 0 0 0
56112- 0 0 0 0 0 0 0 0 0 0 0 0
56113- 0 0 0 0 0 0 0 0 0 0 0 0
56114- 0 0 0 0 0 0 0 0 0 0 0 0
56115- 0 0 0 0 0 0 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 6 6 6 18 18 18
56120- 54 54 54 82 82 82 2 2 6 26 26 26
56121- 22 22 22 2 2 6 123 123 123 253 253 253
56122-253 253 253 253 253 253 253 253 253 253 253 253
56123-253 253 253 253 253 253 253 253 253 253 253 253
56124-253 253 253 253 253 253 253 253 253 253 253 253
56125-253 253 253 253 253 253 253 253 253 253 253 253
56126-253 253 253 253 253 253 253 253 253 253 253 253
56127-253 253 253 253 253 253 253 253 253 250 250 250
56128-238 238 238 198 198 198 6 6 6 38 38 38
56129- 58 58 58 26 26 26 38 38 38 2 2 6
56130- 2 2 6 2 2 6 2 2 6 46 46 46
56131- 78 78 78 30 30 30 10 10 10 0 0 0
56132- 0 0 0 0 0 0 0 0 0 0 0 0
56133- 0 0 0 0 0 0 0 0 0 0 0 0
56134- 0 0 0 0 0 0 0 0 0 0 0 0
56135- 0 0 0 0 0 0 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 10 10 10 30 30 30
56140- 74 74 74 58 58 58 2 2 6 42 42 42
56141- 2 2 6 22 22 22 231 231 231 253 253 253
56142-253 253 253 253 253 253 253 253 253 253 253 253
56143-253 253 253 253 253 253 253 253 253 250 250 250
56144-253 253 253 253 253 253 253 253 253 253 253 253
56145-253 253 253 253 253 253 253 253 253 253 253 253
56146-253 253 253 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 246 246 246 46 46 46 38 38 38
56149- 42 42 42 14 14 14 38 38 38 14 14 14
56150- 2 2 6 2 2 6 2 2 6 6 6 6
56151- 86 86 86 46 46 46 14 14 14 0 0 0
56152- 0 0 0 0 0 0 0 0 0 0 0 0
56153- 0 0 0 0 0 0 0 0 0 0 0 0
56154- 0 0 0 0 0 0 0 0 0 0 0 0
56155- 0 0 0 0 0 0 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 6 6 6 14 14 14 42 42 42
56160- 90 90 90 18 18 18 18 18 18 26 26 26
56161- 2 2 6 116 116 116 253 253 253 253 253 253
56162-253 253 253 253 253 253 253 253 253 253 253 253
56163-253 253 253 253 253 253 250 250 250 238 238 238
56164-253 253 253 253 253 253 253 253 253 253 253 253
56165-253 253 253 253 253 253 253 253 253 253 253 253
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 94 94 94 6 6 6
56169- 2 2 6 2 2 6 10 10 10 34 34 34
56170- 2 2 6 2 2 6 2 2 6 2 2 6
56171- 74 74 74 58 58 58 22 22 22 6 6 6
56172- 0 0 0 0 0 0 0 0 0 0 0 0
56173- 0 0 0 0 0 0 0 0 0 0 0 0
56174- 0 0 0 0 0 0 0 0 0 0 0 0
56175- 0 0 0 0 0 0 0 0 0 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 10 10 10 26 26 26 66 66 66
56180- 82 82 82 2 2 6 38 38 38 6 6 6
56181- 14 14 14 210 210 210 253 253 253 253 253 253
56182-253 253 253 253 253 253 253 253 253 253 253 253
56183-253 253 253 253 253 253 246 246 246 242 242 242
56184-253 253 253 253 253 253 253 253 253 253 253 253
56185-253 253 253 253 253 253 253 253 253 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 144 144 144 2 2 6
56189- 2 2 6 2 2 6 2 2 6 46 46 46
56190- 2 2 6 2 2 6 2 2 6 2 2 6
56191- 42 42 42 74 74 74 30 30 30 10 10 10
56192- 0 0 0 0 0 0 0 0 0 0 0 0
56193- 0 0 0 0 0 0 0 0 0 0 0 0
56194- 0 0 0 0 0 0 0 0 0 0 0 0
56195- 0 0 0 0 0 0 0 0 0 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- 6 6 6 14 14 14 42 42 42 90 90 90
56200- 26 26 26 6 6 6 42 42 42 2 2 6
56201- 74 74 74 250 250 250 253 253 253 253 253 253
56202-253 253 253 253 253 253 253 253 253 253 253 253
56203-253 253 253 253 253 253 242 242 242 242 242 242
56204-253 253 253 253 253 253 253 253 253 253 253 253
56205-253 253 253 253 253 253 253 253 253 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 253 253 253
56208-253 253 253 253 253 253 182 182 182 2 2 6
56209- 2 2 6 2 2 6 2 2 6 46 46 46
56210- 2 2 6 2 2 6 2 2 6 2 2 6
56211- 10 10 10 86 86 86 38 38 38 10 10 10
56212- 0 0 0 0 0 0 0 0 0 0 0 0
56213- 0 0 0 0 0 0 0 0 0 0 0 0
56214- 0 0 0 0 0 0 0 0 0 0 0 0
56215- 0 0 0 0 0 0 0 0 0 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- 10 10 10 26 26 26 66 66 66 82 82 82
56220- 2 2 6 22 22 22 18 18 18 2 2 6
56221-149 149 149 253 253 253 253 253 253 253 253 253
56222-253 253 253 253 253 253 253 253 253 253 253 253
56223-253 253 253 253 253 253 234 234 234 242 242 242
56224-253 253 253 253 253 253 253 253 253 253 253 253
56225-253 253 253 253 253 253 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 253 253 253 253 253 253
56228-253 253 253 253 253 253 206 206 206 2 2 6
56229- 2 2 6 2 2 6 2 2 6 38 38 38
56230- 2 2 6 2 2 6 2 2 6 2 2 6
56231- 6 6 6 86 86 86 46 46 46 14 14 14
56232- 0 0 0 0 0 0 0 0 0 0 0 0
56233- 0 0 0 0 0 0 0 0 0 0 0 0
56234- 0 0 0 0 0 0 0 0 0 0 0 0
56235- 0 0 0 0 0 0 0 0 0 0 0 0
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 6 6 6
56239- 18 18 18 46 46 46 86 86 86 18 18 18
56240- 2 2 6 34 34 34 10 10 10 6 6 6
56241-210 210 210 253 253 253 253 253 253 253 253 253
56242-253 253 253 253 253 253 253 253 253 253 253 253
56243-253 253 253 253 253 253 234 234 234 242 242 242
56244-253 253 253 253 253 253 253 253 253 253 253 253
56245-253 253 253 253 253 253 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 253 253 253 253 253 253
56248-253 253 253 253 253 253 221 221 221 6 6 6
56249- 2 2 6 2 2 6 6 6 6 30 30 30
56250- 2 2 6 2 2 6 2 2 6 2 2 6
56251- 2 2 6 82 82 82 54 54 54 18 18 18
56252- 6 6 6 0 0 0 0 0 0 0 0 0
56253- 0 0 0 0 0 0 0 0 0 0 0 0
56254- 0 0 0 0 0 0 0 0 0 0 0 0
56255- 0 0 0 0 0 0 0 0 0 0 0 0
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 10 10 10
56259- 26 26 26 66 66 66 62 62 62 2 2 6
56260- 2 2 6 38 38 38 10 10 10 26 26 26
56261-238 238 238 253 253 253 253 253 253 253 253 253
56262-253 253 253 253 253 253 253 253 253 253 253 253
56263-253 253 253 253 253 253 231 231 231 238 238 238
56264-253 253 253 253 253 253 253 253 253 253 253 253
56265-253 253 253 253 253 253 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 253 253 253 253 253 253
56268-253 253 253 253 253 253 231 231 231 6 6 6
56269- 2 2 6 2 2 6 10 10 10 30 30 30
56270- 2 2 6 2 2 6 2 2 6 2 2 6
56271- 2 2 6 66 66 66 58 58 58 22 22 22
56272- 6 6 6 0 0 0 0 0 0 0 0 0
56273- 0 0 0 0 0 0 0 0 0 0 0 0
56274- 0 0 0 0 0 0 0 0 0 0 0 0
56275- 0 0 0 0 0 0 0 0 0 0 0 0
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 10 10 10
56279- 38 38 38 78 78 78 6 6 6 2 2 6
56280- 2 2 6 46 46 46 14 14 14 42 42 42
56281-246 246 246 253 253 253 253 253 253 253 253 253
56282-253 253 253 253 253 253 253 253 253 253 253 253
56283-253 253 253 253 253 253 231 231 231 242 242 242
56284-253 253 253 253 253 253 253 253 253 253 253 253
56285-253 253 253 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 253 253 253 253 253 253
56288-253 253 253 253 253 253 234 234 234 10 10 10
56289- 2 2 6 2 2 6 22 22 22 14 14 14
56290- 2 2 6 2 2 6 2 2 6 2 2 6
56291- 2 2 6 66 66 66 62 62 62 22 22 22
56292- 6 6 6 0 0 0 0 0 0 0 0 0
56293- 0 0 0 0 0 0 0 0 0 0 0 0
56294- 0 0 0 0 0 0 0 0 0 0 0 0
56295- 0 0 0 0 0 0 0 0 0 0 0 0
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 6 6 6 18 18 18
56299- 50 50 50 74 74 74 2 2 6 2 2 6
56300- 14 14 14 70 70 70 34 34 34 62 62 62
56301-250 250 250 253 253 253 253 253 253 253 253 253
56302-253 253 253 253 253 253 253 253 253 253 253 253
56303-253 253 253 253 253 253 231 231 231 246 246 246
56304-253 253 253 253 253 253 253 253 253 253 253 253
56305-253 253 253 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 253 253 253 253 253 253
56308-253 253 253 253 253 253 234 234 234 14 14 14
56309- 2 2 6 2 2 6 30 30 30 2 2 6
56310- 2 2 6 2 2 6 2 2 6 2 2 6
56311- 2 2 6 66 66 66 62 62 62 22 22 22
56312- 6 6 6 0 0 0 0 0 0 0 0 0
56313- 0 0 0 0 0 0 0 0 0 0 0 0
56314- 0 0 0 0 0 0 0 0 0 0 0 0
56315- 0 0 0 0 0 0 0 0 0 0 0 0
56316- 0 0 0 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 6 6 6 18 18 18
56319- 54 54 54 62 62 62 2 2 6 2 2 6
56320- 2 2 6 30 30 30 46 46 46 70 70 70
56321-250 250 250 253 253 253 253 253 253 253 253 253
56322-253 253 253 253 253 253 253 253 253 253 253 253
56323-253 253 253 253 253 253 231 231 231 246 246 246
56324-253 253 253 253 253 253 253 253 253 253 253 253
56325-253 253 253 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 253 253 253 253 253 253
56328-253 253 253 253 253 253 226 226 226 10 10 10
56329- 2 2 6 6 6 6 30 30 30 2 2 6
56330- 2 2 6 2 2 6 2 2 6 2 2 6
56331- 2 2 6 66 66 66 58 58 58 22 22 22
56332- 6 6 6 0 0 0 0 0 0 0 0 0
56333- 0 0 0 0 0 0 0 0 0 0 0 0
56334- 0 0 0 0 0 0 0 0 0 0 0 0
56335- 0 0 0 0 0 0 0 0 0 0 0 0
56336- 0 0 0 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 6 6 6 22 22 22
56339- 58 58 58 62 62 62 2 2 6 2 2 6
56340- 2 2 6 2 2 6 30 30 30 78 78 78
56341-250 250 250 253 253 253 253 253 253 253 253 253
56342-253 253 253 253 253 253 253 253 253 253 253 253
56343-253 253 253 253 253 253 231 231 231 246 246 246
56344-253 253 253 253 253 253 253 253 253 253 253 253
56345-253 253 253 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 253 253 253 253 253 253
56348-253 253 253 253 253 253 206 206 206 2 2 6
56349- 22 22 22 34 34 34 18 14 6 22 22 22
56350- 26 26 26 18 18 18 6 6 6 2 2 6
56351- 2 2 6 82 82 82 54 54 54 18 18 18
56352- 6 6 6 0 0 0 0 0 0 0 0 0
56353- 0 0 0 0 0 0 0 0 0 0 0 0
56354- 0 0 0 0 0 0 0 0 0 0 0 0
56355- 0 0 0 0 0 0 0 0 0 0 0 0
56356- 0 0 0 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 6 6 6 26 26 26
56359- 62 62 62 106 106 106 74 54 14 185 133 11
56360-210 162 10 121 92 8 6 6 6 62 62 62
56361-238 238 238 253 253 253 253 253 253 253 253 253
56362-253 253 253 253 253 253 253 253 253 253 253 253
56363-253 253 253 253 253 253 231 231 231 246 246 246
56364-253 253 253 253 253 253 253 253 253 253 253 253
56365-253 253 253 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 253 253 253 253 253 253
56368-253 253 253 253 253 253 158 158 158 18 18 18
56369- 14 14 14 2 2 6 2 2 6 2 2 6
56370- 6 6 6 18 18 18 66 66 66 38 38 38
56371- 6 6 6 94 94 94 50 50 50 18 18 18
56372- 6 6 6 0 0 0 0 0 0 0 0 0
56373- 0 0 0 0 0 0 0 0 0 0 0 0
56374- 0 0 0 0 0 0 0 0 0 0 0 0
56375- 0 0 0 0 0 0 0 0 0 0 0 0
56376- 0 0 0 0 0 0 0 0 0 0 0 0
56377- 0 0 0 0 0 0 0 0 0 6 6 6
56378- 10 10 10 10 10 10 18 18 18 38 38 38
56379- 78 78 78 142 134 106 216 158 10 242 186 14
56380-246 190 14 246 190 14 156 118 10 10 10 10
56381- 90 90 90 238 238 238 253 253 253 253 253 253
56382-253 253 253 253 253 253 253 253 253 253 253 253
56383-253 253 253 253 253 253 231 231 231 250 250 250
56384-253 253 253 253 253 253 253 253 253 253 253 253
56385-253 253 253 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 253 253 253 246 230 190
56388-238 204 91 238 204 91 181 142 44 37 26 9
56389- 2 2 6 2 2 6 2 2 6 2 2 6
56390- 2 2 6 2 2 6 38 38 38 46 46 46
56391- 26 26 26 106 106 106 54 54 54 18 18 18
56392- 6 6 6 0 0 0 0 0 0 0 0 0
56393- 0 0 0 0 0 0 0 0 0 0 0 0
56394- 0 0 0 0 0 0 0 0 0 0 0 0
56395- 0 0 0 0 0 0 0 0 0 0 0 0
56396- 0 0 0 0 0 0 0 0 0 0 0 0
56397- 0 0 0 6 6 6 14 14 14 22 22 22
56398- 30 30 30 38 38 38 50 50 50 70 70 70
56399-106 106 106 190 142 34 226 170 11 242 186 14
56400-246 190 14 246 190 14 246 190 14 154 114 10
56401- 6 6 6 74 74 74 226 226 226 253 253 253
56402-253 253 253 253 253 253 253 253 253 253 253 253
56403-253 253 253 253 253 253 231 231 231 250 250 250
56404-253 253 253 253 253 253 253 253 253 253 253 253
56405-253 253 253 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 253 253 253 228 184 62
56408-241 196 14 241 208 19 232 195 16 38 30 10
56409- 2 2 6 2 2 6 2 2 6 2 2 6
56410- 2 2 6 6 6 6 30 30 30 26 26 26
56411-203 166 17 154 142 90 66 66 66 26 26 26
56412- 6 6 6 0 0 0 0 0 0 0 0 0
56413- 0 0 0 0 0 0 0 0 0 0 0 0
56414- 0 0 0 0 0 0 0 0 0 0 0 0
56415- 0 0 0 0 0 0 0 0 0 0 0 0
56416- 0 0 0 0 0 0 0 0 0 0 0 0
56417- 6 6 6 18 18 18 38 38 38 58 58 58
56418- 78 78 78 86 86 86 101 101 101 123 123 123
56419-175 146 61 210 150 10 234 174 13 246 186 14
56420-246 190 14 246 190 14 246 190 14 238 190 10
56421-102 78 10 2 2 6 46 46 46 198 198 198
56422-253 253 253 253 253 253 253 253 253 253 253 253
56423-253 253 253 253 253 253 234 234 234 242 242 242
56424-253 253 253 253 253 253 253 253 253 253 253 253
56425-253 253 253 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 253 253 253 224 178 62
56428-242 186 14 241 196 14 210 166 10 22 18 6
56429- 2 2 6 2 2 6 2 2 6 2 2 6
56430- 2 2 6 2 2 6 6 6 6 121 92 8
56431-238 202 15 232 195 16 82 82 82 34 34 34
56432- 10 10 10 0 0 0 0 0 0 0 0 0
56433- 0 0 0 0 0 0 0 0 0 0 0 0
56434- 0 0 0 0 0 0 0 0 0 0 0 0
56435- 0 0 0 0 0 0 0 0 0 0 0 0
56436- 0 0 0 0 0 0 0 0 0 0 0 0
56437- 14 14 14 38 38 38 70 70 70 154 122 46
56438-190 142 34 200 144 11 197 138 11 197 138 11
56439-213 154 11 226 170 11 242 186 14 246 190 14
56440-246 190 14 246 190 14 246 190 14 246 190 14
56441-225 175 15 46 32 6 2 2 6 22 22 22
56442-158 158 158 250 250 250 253 253 253 253 253 253
56443-253 253 253 253 253 253 253 253 253 253 253 253
56444-253 253 253 253 253 253 253 253 253 253 253 253
56445-253 253 253 253 253 253 253 253 253 253 253 253
56446-253 253 253 253 253 253 253 253 253 253 253 253
56447-253 253 253 250 250 250 242 242 242 224 178 62
56448-239 182 13 236 186 11 213 154 11 46 32 6
56449- 2 2 6 2 2 6 2 2 6 2 2 6
56450- 2 2 6 2 2 6 61 42 6 225 175 15
56451-238 190 10 236 186 11 112 100 78 42 42 42
56452- 14 14 14 0 0 0 0 0 0 0 0 0
56453- 0 0 0 0 0 0 0 0 0 0 0 0
56454- 0 0 0 0 0 0 0 0 0 0 0 0
56455- 0 0 0 0 0 0 0 0 0 0 0 0
56456- 0 0 0 0 0 0 0 0 0 6 6 6
56457- 22 22 22 54 54 54 154 122 46 213 154 11
56458-226 170 11 230 174 11 226 170 11 226 170 11
56459-236 178 12 242 186 14 246 190 14 246 190 14
56460-246 190 14 246 190 14 246 190 14 246 190 14
56461-241 196 14 184 144 12 10 10 10 2 2 6
56462- 6 6 6 116 116 116 242 242 242 253 253 253
56463-253 253 253 253 253 253 253 253 253 253 253 253
56464-253 253 253 253 253 253 253 253 253 253 253 253
56465-253 253 253 253 253 253 253 253 253 253 253 253
56466-253 253 253 253 253 253 253 253 253 253 253 253
56467-253 253 253 231 231 231 198 198 198 214 170 54
56468-236 178 12 236 178 12 210 150 10 137 92 6
56469- 18 14 6 2 2 6 2 2 6 2 2 6
56470- 6 6 6 70 47 6 200 144 11 236 178 12
56471-239 182 13 239 182 13 124 112 88 58 58 58
56472- 22 22 22 6 6 6 0 0 0 0 0 0
56473- 0 0 0 0 0 0 0 0 0 0 0 0
56474- 0 0 0 0 0 0 0 0 0 0 0 0
56475- 0 0 0 0 0 0 0 0 0 0 0 0
56476- 0 0 0 0 0 0 0 0 0 10 10 10
56477- 30 30 30 70 70 70 180 133 36 226 170 11
56478-239 182 13 242 186 14 242 186 14 246 186 14
56479-246 190 14 246 190 14 246 190 14 246 190 14
56480-246 190 14 246 190 14 246 190 14 246 190 14
56481-246 190 14 232 195 16 98 70 6 2 2 6
56482- 2 2 6 2 2 6 66 66 66 221 221 221
56483-253 253 253 253 253 253 253 253 253 253 253 253
56484-253 253 253 253 253 253 253 253 253 253 253 253
56485-253 253 253 253 253 253 253 253 253 253 253 253
56486-253 253 253 253 253 253 253 253 253 253 253 253
56487-253 253 253 206 206 206 198 198 198 214 166 58
56488-230 174 11 230 174 11 216 158 10 192 133 9
56489-163 110 8 116 81 8 102 78 10 116 81 8
56490-167 114 7 197 138 11 226 170 11 239 182 13
56491-242 186 14 242 186 14 162 146 94 78 78 78
56492- 34 34 34 14 14 14 6 6 6 0 0 0
56493- 0 0 0 0 0 0 0 0 0 0 0 0
56494- 0 0 0 0 0 0 0 0 0 0 0 0
56495- 0 0 0 0 0 0 0 0 0 0 0 0
56496- 0 0 0 0 0 0 0 0 0 6 6 6
56497- 30 30 30 78 78 78 190 142 34 226 170 11
56498-239 182 13 246 190 14 246 190 14 246 190 14
56499-246 190 14 246 190 14 246 190 14 246 190 14
56500-246 190 14 246 190 14 246 190 14 246 190 14
56501-246 190 14 241 196 14 203 166 17 22 18 6
56502- 2 2 6 2 2 6 2 2 6 38 38 38
56503-218 218 218 253 253 253 253 253 253 253 253 253
56504-253 253 253 253 253 253 253 253 253 253 253 253
56505-253 253 253 253 253 253 253 253 253 253 253 253
56506-253 253 253 253 253 253 253 253 253 253 253 253
56507-250 250 250 206 206 206 198 198 198 202 162 69
56508-226 170 11 236 178 12 224 166 10 210 150 10
56509-200 144 11 197 138 11 192 133 9 197 138 11
56510-210 150 10 226 170 11 242 186 14 246 190 14
56511-246 190 14 246 186 14 225 175 15 124 112 88
56512- 62 62 62 30 30 30 14 14 14 6 6 6
56513- 0 0 0 0 0 0 0 0 0 0 0 0
56514- 0 0 0 0 0 0 0 0 0 0 0 0
56515- 0 0 0 0 0 0 0 0 0 0 0 0
56516- 0 0 0 0 0 0 0 0 0 10 10 10
56517- 30 30 30 78 78 78 174 135 50 224 166 10
56518-239 182 13 246 190 14 246 190 14 246 190 14
56519-246 190 14 246 190 14 246 190 14 246 190 14
56520-246 190 14 246 190 14 246 190 14 246 190 14
56521-246 190 14 246 190 14 241 196 14 139 102 15
56522- 2 2 6 2 2 6 2 2 6 2 2 6
56523- 78 78 78 250 250 250 253 253 253 253 253 253
56524-253 253 253 253 253 253 253 253 253 253 253 253
56525-253 253 253 253 253 253 253 253 253 253 253 253
56526-253 253 253 253 253 253 253 253 253 253 253 253
56527-250 250 250 214 214 214 198 198 198 190 150 46
56528-219 162 10 236 178 12 234 174 13 224 166 10
56529-216 158 10 213 154 11 213 154 11 216 158 10
56530-226 170 11 239 182 13 246 190 14 246 190 14
56531-246 190 14 246 190 14 242 186 14 206 162 42
56532-101 101 101 58 58 58 30 30 30 14 14 14
56533- 6 6 6 0 0 0 0 0 0 0 0 0
56534- 0 0 0 0 0 0 0 0 0 0 0 0
56535- 0 0 0 0 0 0 0 0 0 0 0 0
56536- 0 0 0 0 0 0 0 0 0 10 10 10
56537- 30 30 30 74 74 74 174 135 50 216 158 10
56538-236 178 12 246 190 14 246 190 14 246 190 14
56539-246 190 14 246 190 14 246 190 14 246 190 14
56540-246 190 14 246 190 14 246 190 14 246 190 14
56541-246 190 14 246 190 14 241 196 14 226 184 13
56542- 61 42 6 2 2 6 2 2 6 2 2 6
56543- 22 22 22 238 238 238 253 253 253 253 253 253
56544-253 253 253 253 253 253 253 253 253 253 253 253
56545-253 253 253 253 253 253 253 253 253 253 253 253
56546-253 253 253 253 253 253 253 253 253 253 253 253
56547-253 253 253 226 226 226 187 187 187 180 133 36
56548-216 158 10 236 178 12 239 182 13 236 178 12
56549-230 174 11 226 170 11 226 170 11 230 174 11
56550-236 178 12 242 186 14 246 190 14 246 190 14
56551-246 190 14 246 190 14 246 186 14 239 182 13
56552-206 162 42 106 106 106 66 66 66 34 34 34
56553- 14 14 14 6 6 6 0 0 0 0 0 0
56554- 0 0 0 0 0 0 0 0 0 0 0 0
56555- 0 0 0 0 0 0 0 0 0 0 0 0
56556- 0 0 0 0 0 0 0 0 0 6 6 6
56557- 26 26 26 70 70 70 163 133 67 213 154 11
56558-236 178 12 246 190 14 246 190 14 246 190 14
56559-246 190 14 246 190 14 246 190 14 246 190 14
56560-246 190 14 246 190 14 246 190 14 246 190 14
56561-246 190 14 246 190 14 246 190 14 241 196 14
56562-190 146 13 18 14 6 2 2 6 2 2 6
56563- 46 46 46 246 246 246 253 253 253 253 253 253
56564-253 253 253 253 253 253 253 253 253 253 253 253
56565-253 253 253 253 253 253 253 253 253 253 253 253
56566-253 253 253 253 253 253 253 253 253 253 253 253
56567-253 253 253 221 221 221 86 86 86 156 107 11
56568-216 158 10 236 178 12 242 186 14 246 186 14
56569-242 186 14 239 182 13 239 182 13 242 186 14
56570-242 186 14 246 186 14 246 190 14 246 190 14
56571-246 190 14 246 190 14 246 190 14 246 190 14
56572-242 186 14 225 175 15 142 122 72 66 66 66
56573- 30 30 30 10 10 10 0 0 0 0 0 0
56574- 0 0 0 0 0 0 0 0 0 0 0 0
56575- 0 0 0 0 0 0 0 0 0 0 0 0
56576- 0 0 0 0 0 0 0 0 0 6 6 6
56577- 26 26 26 70 70 70 163 133 67 210 150 10
56578-236 178 12 246 190 14 246 190 14 246 190 14
56579-246 190 14 246 190 14 246 190 14 246 190 14
56580-246 190 14 246 190 14 246 190 14 246 190 14
56581-246 190 14 246 190 14 246 190 14 246 190 14
56582-232 195 16 121 92 8 34 34 34 106 106 106
56583-221 221 221 253 253 253 253 253 253 253 253 253
56584-253 253 253 253 253 253 253 253 253 253 253 253
56585-253 253 253 253 253 253 253 253 253 253 253 253
56586-253 253 253 253 253 253 253 253 253 253 253 253
56587-242 242 242 82 82 82 18 14 6 163 110 8
56588-216 158 10 236 178 12 242 186 14 246 190 14
56589-246 190 14 246 190 14 246 190 14 246 190 14
56590-246 190 14 246 190 14 246 190 14 246 190 14
56591-246 190 14 246 190 14 246 190 14 246 190 14
56592-246 190 14 246 190 14 242 186 14 163 133 67
56593- 46 46 46 18 18 18 6 6 6 0 0 0
56594- 0 0 0 0 0 0 0 0 0 0 0 0
56595- 0 0 0 0 0 0 0 0 0 0 0 0
56596- 0 0 0 0 0 0 0 0 0 10 10 10
56597- 30 30 30 78 78 78 163 133 67 210 150 10
56598-236 178 12 246 186 14 246 190 14 246 190 14
56599-246 190 14 246 190 14 246 190 14 246 190 14
56600-246 190 14 246 190 14 246 190 14 246 190 14
56601-246 190 14 246 190 14 246 190 14 246 190 14
56602-241 196 14 215 174 15 190 178 144 253 253 253
56603-253 253 253 253 253 253 253 253 253 253 253 253
56604-253 253 253 253 253 253 253 253 253 253 253 253
56605-253 253 253 253 253 253 253 253 253 253 253 253
56606-253 253 253 253 253 253 253 253 253 218 218 218
56607- 58 58 58 2 2 6 22 18 6 167 114 7
56608-216 158 10 236 178 12 246 186 14 246 190 14
56609-246 190 14 246 190 14 246 190 14 246 190 14
56610-246 190 14 246 190 14 246 190 14 246 190 14
56611-246 190 14 246 190 14 246 190 14 246 190 14
56612-246 190 14 246 186 14 242 186 14 190 150 46
56613- 54 54 54 22 22 22 6 6 6 0 0 0
56614- 0 0 0 0 0 0 0 0 0 0 0 0
56615- 0 0 0 0 0 0 0 0 0 0 0 0
56616- 0 0 0 0 0 0 0 0 0 14 14 14
56617- 38 38 38 86 86 86 180 133 36 213 154 11
56618-236 178 12 246 186 14 246 190 14 246 190 14
56619-246 190 14 246 190 14 246 190 14 246 190 14
56620-246 190 14 246 190 14 246 190 14 246 190 14
56621-246 190 14 246 190 14 246 190 14 246 190 14
56622-246 190 14 232 195 16 190 146 13 214 214 214
56623-253 253 253 253 253 253 253 253 253 253 253 253
56624-253 253 253 253 253 253 253 253 253 253 253 253
56625-253 253 253 253 253 253 253 253 253 253 253 253
56626-253 253 253 250 250 250 170 170 170 26 26 26
56627- 2 2 6 2 2 6 37 26 9 163 110 8
56628-219 162 10 239 182 13 246 186 14 246 190 14
56629-246 190 14 246 190 14 246 190 14 246 190 14
56630-246 190 14 246 190 14 246 190 14 246 190 14
56631-246 190 14 246 190 14 246 190 14 246 190 14
56632-246 186 14 236 178 12 224 166 10 142 122 72
56633- 46 46 46 18 18 18 6 6 6 0 0 0
56634- 0 0 0 0 0 0 0 0 0 0 0 0
56635- 0 0 0 0 0 0 0 0 0 0 0 0
56636- 0 0 0 0 0 0 6 6 6 18 18 18
56637- 50 50 50 109 106 95 192 133 9 224 166 10
56638-242 186 14 246 190 14 246 190 14 246 190 14
56639-246 190 14 246 190 14 246 190 14 246 190 14
56640-246 190 14 246 190 14 246 190 14 246 190 14
56641-246 190 14 246 190 14 246 190 14 246 190 14
56642-242 186 14 226 184 13 210 162 10 142 110 46
56643-226 226 226 253 253 253 253 253 253 253 253 253
56644-253 253 253 253 253 253 253 253 253 253 253 253
56645-253 253 253 253 253 253 253 253 253 253 253 253
56646-198 198 198 66 66 66 2 2 6 2 2 6
56647- 2 2 6 2 2 6 50 34 6 156 107 11
56648-219 162 10 239 182 13 246 186 14 246 190 14
56649-246 190 14 246 190 14 246 190 14 246 190 14
56650-246 190 14 246 190 14 246 190 14 246 190 14
56651-246 190 14 246 190 14 246 190 14 242 186 14
56652-234 174 13 213 154 11 154 122 46 66 66 66
56653- 30 30 30 10 10 10 0 0 0 0 0 0
56654- 0 0 0 0 0 0 0 0 0 0 0 0
56655- 0 0 0 0 0 0 0 0 0 0 0 0
56656- 0 0 0 0 0 0 6 6 6 22 22 22
56657- 58 58 58 154 121 60 206 145 10 234 174 13
56658-242 186 14 246 186 14 246 190 14 246 190 14
56659-246 190 14 246 190 14 246 190 14 246 190 14
56660-246 190 14 246 190 14 246 190 14 246 190 14
56661-246 190 14 246 190 14 246 190 14 246 190 14
56662-246 186 14 236 178 12 210 162 10 163 110 8
56663- 61 42 6 138 138 138 218 218 218 250 250 250
56664-253 253 253 253 253 253 253 253 253 250 250 250
56665-242 242 242 210 210 210 144 144 144 66 66 66
56666- 6 6 6 2 2 6 2 2 6 2 2 6
56667- 2 2 6 2 2 6 61 42 6 163 110 8
56668-216 158 10 236 178 12 246 190 14 246 190 14
56669-246 190 14 246 190 14 246 190 14 246 190 14
56670-246 190 14 246 190 14 246 190 14 246 190 14
56671-246 190 14 239 182 13 230 174 11 216 158 10
56672-190 142 34 124 112 88 70 70 70 38 38 38
56673- 18 18 18 6 6 6 0 0 0 0 0 0
56674- 0 0 0 0 0 0 0 0 0 0 0 0
56675- 0 0 0 0 0 0 0 0 0 0 0 0
56676- 0 0 0 0 0 0 6 6 6 22 22 22
56677- 62 62 62 168 124 44 206 145 10 224 166 10
56678-236 178 12 239 182 13 242 186 14 242 186 14
56679-246 186 14 246 190 14 246 190 14 246 190 14
56680-246 190 14 246 190 14 246 190 14 246 190 14
56681-246 190 14 246 190 14 246 190 14 246 190 14
56682-246 190 14 236 178 12 216 158 10 175 118 6
56683- 80 54 7 2 2 6 6 6 6 30 30 30
56684- 54 54 54 62 62 62 50 50 50 38 38 38
56685- 14 14 14 2 2 6 2 2 6 2 2 6
56686- 2 2 6 2 2 6 2 2 6 2 2 6
56687- 2 2 6 6 6 6 80 54 7 167 114 7
56688-213 154 11 236 178 12 246 190 14 246 190 14
56689-246 190 14 246 190 14 246 190 14 246 190 14
56690-246 190 14 242 186 14 239 182 13 239 182 13
56691-230 174 11 210 150 10 174 135 50 124 112 88
56692- 82 82 82 54 54 54 34 34 34 18 18 18
56693- 6 6 6 0 0 0 0 0 0 0 0 0
56694- 0 0 0 0 0 0 0 0 0 0 0 0
56695- 0 0 0 0 0 0 0 0 0 0 0 0
56696- 0 0 0 0 0 0 6 6 6 18 18 18
56697- 50 50 50 158 118 36 192 133 9 200 144 11
56698-216 158 10 219 162 10 224 166 10 226 170 11
56699-230 174 11 236 178 12 239 182 13 239 182 13
56700-242 186 14 246 186 14 246 190 14 246 190 14
56701-246 190 14 246 190 14 246 190 14 246 190 14
56702-246 186 14 230 174 11 210 150 10 163 110 8
56703-104 69 6 10 10 10 2 2 6 2 2 6
56704- 2 2 6 2 2 6 2 2 6 2 2 6
56705- 2 2 6 2 2 6 2 2 6 2 2 6
56706- 2 2 6 2 2 6 2 2 6 2 2 6
56707- 2 2 6 6 6 6 91 60 6 167 114 7
56708-206 145 10 230 174 11 242 186 14 246 190 14
56709-246 190 14 246 190 14 246 186 14 242 186 14
56710-239 182 13 230 174 11 224 166 10 213 154 11
56711-180 133 36 124 112 88 86 86 86 58 58 58
56712- 38 38 38 22 22 22 10 10 10 6 6 6
56713- 0 0 0 0 0 0 0 0 0 0 0 0
56714- 0 0 0 0 0 0 0 0 0 0 0 0
56715- 0 0 0 0 0 0 0 0 0 0 0 0
56716- 0 0 0 0 0 0 0 0 0 14 14 14
56717- 34 34 34 70 70 70 138 110 50 158 118 36
56718-167 114 7 180 123 7 192 133 9 197 138 11
56719-200 144 11 206 145 10 213 154 11 219 162 10
56720-224 166 10 230 174 11 239 182 13 242 186 14
56721-246 186 14 246 186 14 246 186 14 246 186 14
56722-239 182 13 216 158 10 185 133 11 152 99 6
56723-104 69 6 18 14 6 2 2 6 2 2 6
56724- 2 2 6 2 2 6 2 2 6 2 2 6
56725- 2 2 6 2 2 6 2 2 6 2 2 6
56726- 2 2 6 2 2 6 2 2 6 2 2 6
56727- 2 2 6 6 6 6 80 54 7 152 99 6
56728-192 133 9 219 162 10 236 178 12 239 182 13
56729-246 186 14 242 186 14 239 182 13 236 178 12
56730-224 166 10 206 145 10 192 133 9 154 121 60
56731- 94 94 94 62 62 62 42 42 42 22 22 22
56732- 14 14 14 6 6 6 0 0 0 0 0 0
56733- 0 0 0 0 0 0 0 0 0 0 0 0
56734- 0 0 0 0 0 0 0 0 0 0 0 0
56735- 0 0 0 0 0 0 0 0 0 0 0 0
56736- 0 0 0 0 0 0 0 0 0 6 6 6
56737- 18 18 18 34 34 34 58 58 58 78 78 78
56738-101 98 89 124 112 88 142 110 46 156 107 11
56739-163 110 8 167 114 7 175 118 6 180 123 7
56740-185 133 11 197 138 11 210 150 10 219 162 10
56741-226 170 11 236 178 12 236 178 12 234 174 13
56742-219 162 10 197 138 11 163 110 8 130 83 6
56743- 91 60 6 10 10 10 2 2 6 2 2 6
56744- 18 18 18 38 38 38 38 38 38 38 38 38
56745- 38 38 38 38 38 38 38 38 38 38 38 38
56746- 38 38 38 38 38 38 26 26 26 2 2 6
56747- 2 2 6 6 6 6 70 47 6 137 92 6
56748-175 118 6 200 144 11 219 162 10 230 174 11
56749-234 174 13 230 174 11 219 162 10 210 150 10
56750-192 133 9 163 110 8 124 112 88 82 82 82
56751- 50 50 50 30 30 30 14 14 14 6 6 6
56752- 0 0 0 0 0 0 0 0 0 0 0 0
56753- 0 0 0 0 0 0 0 0 0 0 0 0
56754- 0 0 0 0 0 0 0 0 0 0 0 0
56755- 0 0 0 0 0 0 0 0 0 0 0 0
56756- 0 0 0 0 0 0 0 0 0 0 0 0
56757- 6 6 6 14 14 14 22 22 22 34 34 34
56758- 42 42 42 58 58 58 74 74 74 86 86 86
56759-101 98 89 122 102 70 130 98 46 121 87 25
56760-137 92 6 152 99 6 163 110 8 180 123 7
56761-185 133 11 197 138 11 206 145 10 200 144 11
56762-180 123 7 156 107 11 130 83 6 104 69 6
56763- 50 34 6 54 54 54 110 110 110 101 98 89
56764- 86 86 86 82 82 82 78 78 78 78 78 78
56765- 78 78 78 78 78 78 78 78 78 78 78 78
56766- 78 78 78 82 82 82 86 86 86 94 94 94
56767-106 106 106 101 101 101 86 66 34 124 80 6
56768-156 107 11 180 123 7 192 133 9 200 144 11
56769-206 145 10 200 144 11 192 133 9 175 118 6
56770-139 102 15 109 106 95 70 70 70 42 42 42
56771- 22 22 22 10 10 10 0 0 0 0 0 0
56772- 0 0 0 0 0 0 0 0 0 0 0 0
56773- 0 0 0 0 0 0 0 0 0 0 0 0
56774- 0 0 0 0 0 0 0 0 0 0 0 0
56775- 0 0 0 0 0 0 0 0 0 0 0 0
56776- 0 0 0 0 0 0 0 0 0 0 0 0
56777- 0 0 0 0 0 0 6 6 6 10 10 10
56778- 14 14 14 22 22 22 30 30 30 38 38 38
56779- 50 50 50 62 62 62 74 74 74 90 90 90
56780-101 98 89 112 100 78 121 87 25 124 80 6
56781-137 92 6 152 99 6 152 99 6 152 99 6
56782-138 86 6 124 80 6 98 70 6 86 66 30
56783-101 98 89 82 82 82 58 58 58 46 46 46
56784- 38 38 38 34 34 34 34 34 34 34 34 34
56785- 34 34 34 34 34 34 34 34 34 34 34 34
56786- 34 34 34 34 34 34 38 38 38 42 42 42
56787- 54 54 54 82 82 82 94 86 76 91 60 6
56788-134 86 6 156 107 11 167 114 7 175 118 6
56789-175 118 6 167 114 7 152 99 6 121 87 25
56790-101 98 89 62 62 62 34 34 34 18 18 18
56791- 6 6 6 0 0 0 0 0 0 0 0 0
56792- 0 0 0 0 0 0 0 0 0 0 0 0
56793- 0 0 0 0 0 0 0 0 0 0 0 0
56794- 0 0 0 0 0 0 0 0 0 0 0 0
56795- 0 0 0 0 0 0 0 0 0 0 0 0
56796- 0 0 0 0 0 0 0 0 0 0 0 0
56797- 0 0 0 0 0 0 0 0 0 0 0 0
56798- 0 0 0 6 6 6 6 6 6 10 10 10
56799- 18 18 18 22 22 22 30 30 30 42 42 42
56800- 50 50 50 66 66 66 86 86 86 101 98 89
56801-106 86 58 98 70 6 104 69 6 104 69 6
56802-104 69 6 91 60 6 82 62 34 90 90 90
56803- 62 62 62 38 38 38 22 22 22 14 14 14
56804- 10 10 10 10 10 10 10 10 10 10 10 10
56805- 10 10 10 10 10 10 6 6 6 10 10 10
56806- 10 10 10 10 10 10 10 10 10 14 14 14
56807- 22 22 22 42 42 42 70 70 70 89 81 66
56808- 80 54 7 104 69 6 124 80 6 137 92 6
56809-134 86 6 116 81 8 100 82 52 86 86 86
56810- 58 58 58 30 30 30 14 14 14 6 6 6
56811- 0 0 0 0 0 0 0 0 0 0 0 0
56812- 0 0 0 0 0 0 0 0 0 0 0 0
56813- 0 0 0 0 0 0 0 0 0 0 0 0
56814- 0 0 0 0 0 0 0 0 0 0 0 0
56815- 0 0 0 0 0 0 0 0 0 0 0 0
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 6 6 6 10 10 10 14 14 14
56820- 18 18 18 26 26 26 38 38 38 54 54 54
56821- 70 70 70 86 86 86 94 86 76 89 81 66
56822- 89 81 66 86 86 86 74 74 74 50 50 50
56823- 30 30 30 14 14 14 6 6 6 0 0 0
56824- 0 0 0 0 0 0 0 0 0 0 0 0
56825- 0 0 0 0 0 0 0 0 0 0 0 0
56826- 0 0 0 0 0 0 0 0 0 0 0 0
56827- 6 6 6 18 18 18 34 34 34 58 58 58
56828- 82 82 82 89 81 66 89 81 66 89 81 66
56829- 94 86 66 94 86 76 74 74 74 50 50 50
56830- 26 26 26 14 14 14 6 6 6 0 0 0
56831- 0 0 0 0 0 0 0 0 0 0 0 0
56832- 0 0 0 0 0 0 0 0 0 0 0 0
56833- 0 0 0 0 0 0 0 0 0 0 0 0
56834- 0 0 0 0 0 0 0 0 0 0 0 0
56835- 0 0 0 0 0 0 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- 6 6 6 6 6 6 14 14 14 18 18 18
56841- 30 30 30 38 38 38 46 46 46 54 54 54
56842- 50 50 50 42 42 42 30 30 30 18 18 18
56843- 10 10 10 0 0 0 0 0 0 0 0 0
56844- 0 0 0 0 0 0 0 0 0 0 0 0
56845- 0 0 0 0 0 0 0 0 0 0 0 0
56846- 0 0 0 0 0 0 0 0 0 0 0 0
56847- 0 0 0 6 6 6 14 14 14 26 26 26
56848- 38 38 38 50 50 50 58 58 58 58 58 58
56849- 54 54 54 42 42 42 30 30 30 18 18 18
56850- 10 10 10 0 0 0 0 0 0 0 0 0
56851- 0 0 0 0 0 0 0 0 0 0 0 0
56852- 0 0 0 0 0 0 0 0 0 0 0 0
56853- 0 0 0 0 0 0 0 0 0 0 0 0
56854- 0 0 0 0 0 0 0 0 0 0 0 0
56855- 0 0 0 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 6 6 6
56861- 6 6 6 10 10 10 14 14 14 18 18 18
56862- 18 18 18 14 14 14 10 10 10 6 6 6
56863- 0 0 0 0 0 0 0 0 0 0 0 0
56864- 0 0 0 0 0 0 0 0 0 0 0 0
56865- 0 0 0 0 0 0 0 0 0 0 0 0
56866- 0 0 0 0 0 0 0 0 0 0 0 0
56867- 0 0 0 0 0 0 0 0 0 6 6 6
56868- 14 14 14 18 18 18 22 22 22 22 22 22
56869- 18 18 18 14 14 14 10 10 10 6 6 6
56870- 0 0 0 0 0 0 0 0 0 0 0 0
56871- 0 0 0 0 0 0 0 0 0 0 0 0
56872- 0 0 0 0 0 0 0 0 0 0 0 0
56873- 0 0 0 0 0 0 0 0 0 0 0 0
56874- 0 0 0 0 0 0 0 0 0 0 0 0
56875+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56876+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56877+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56878+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56879+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56880+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56881+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56882+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56883+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56884+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56885+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56886+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56887+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56888+4 4 4 4 4 4
56889+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56890+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56891+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56892+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56893+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56894+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56895+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56896+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56897+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56898+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56899+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56900+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56901+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56902+4 4 4 4 4 4
56903+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56904+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56905+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56906+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56907+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56908+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56909+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56910+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56911+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56912+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56913+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56914+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56915+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56916+4 4 4 4 4 4
56917+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56918+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56919+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56920+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56921+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56922+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56923+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56924+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56925+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56926+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56927+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56928+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56929+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56930+4 4 4 4 4 4
56931+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56932+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56933+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56934+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56935+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56936+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56937+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56938+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
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
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 4 4 4 4 4 4 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
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 3 3 3 0 0 0 0 0 0
56964+0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 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 4 4 4 4 4 4 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 1 1 1 0 0 0
56969+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
56970+4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
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
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 2 2 2 0 0 0 3 4 3 26 28 28
56978+37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
56979+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56980+4 4 4 4 4 4 4 4 4 4 4 4 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 3 3 3 0 0 0 1 1 1 6 6 6
56983+2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
56984+4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
56985+1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56986+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+2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
56992+153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
56993+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
56994+4 4 4 4 4 4 4 4 4 4 4 4 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 0 0 0 4 4 4 41 54 63 125 124 125
56997+60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
56998+4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
56999+2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
57000+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 5 5 5 5 5 5 2 2 2 0 0 0
57005+4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
57006+165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
57007+1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 4 4 4
57008+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57009+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
57010+3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
57011+163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
57012+0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
57013+37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
57014+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 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
57019+37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
57020+156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
57021+125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
57022+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
57023+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
57024+0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
57025+174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
57026+0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
57027+64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
57028+4 4 4 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 5 5 5
57032+5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
57033+156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
57034+156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
57035+174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
57036+1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
57037+4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
57038+13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
57039+174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
57040+22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
57041+90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
57042+4 4 4 4 4 4
57043+4 4 4 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 5 5 5 3 3 3
57046+0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
57047+174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
57048+156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
57049+163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
57050+4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
57051+5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
57052+131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
57053+190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
57054+90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
57055+31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
57056+4 4 4 4 4 4
57057+4 4 4 4 4 4 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 2 2 2 0 0 0 4 0 0
57060+4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
57061+155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
57062+167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
57063+153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
57064+41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
57065+1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
57066+177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
57067+125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
57068+136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
57069+7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
57070+4 4 4 4 4 4
57071+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 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 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
57074+125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
57075+156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
57076+137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
57077+156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
57078+167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
57079+0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
57080+166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
57081+6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
57082+90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
57083+1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
57084+4 4 4 4 4 4
57085+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57086+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57087+1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
57088+167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
57089+157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
57090+26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
57091+158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
57092+165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
57093+60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
57094+137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
57095+52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
57096+13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
57097+4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
57098+4 4 4 4 4 4
57099+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57100+4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
57101+0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
57102+158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
57103+167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
57104+4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
57105+174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
57106+155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
57107+137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
57108+16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
57109+136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
57110+2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
57111+4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
57112+4 4 4 4 4 4
57113+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57114+4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
57115+37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
57116+157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
57117+153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
57118+4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
57119+125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
57120+156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
57121+174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
57122+4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
57123+136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
57124+1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
57125+2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
57126+0 0 0 4 4 4
57127+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
57128+4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
57129+158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
57130+153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
57131+37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
57132+4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
57133+4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
57134+154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
57135+174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
57136+32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
57137+28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
57138+50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
57139+0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
57140+2 0 0 0 0 0
57141+4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
57142+0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
57143+174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
57144+165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
57145+4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
57146+4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
57147+4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
57148+174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
57149+60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
57150+136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
57151+22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
57152+136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
57153+26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
57154+37 38 37 0 0 0
57155+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
57156+13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
57157+153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
57158+177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
57159+4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
57160+5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
57161+6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
57162+166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
57163+4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
57164+146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
57165+71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
57166+90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
57167+125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
57168+85 115 134 4 0 0
57169+4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
57170+125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
57171+155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
57172+125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
57173+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
57174+0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
57175+5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
57176+37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
57177+4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
57178+90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
57179+2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
57180+13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
57181+166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
57182+60 73 81 4 0 0
57183+4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
57184+174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
57185+156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
57186+4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
57187+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
57188+10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
57189+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
57190+4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
57191+80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
57192+28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
57193+50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
57194+1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
57195+167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
57196+16 19 21 4 0 0
57197+4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
57198+158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
57199+167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
57200+4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
57201+4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
57202+80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
57203+4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
57204+3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
57205+146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
57206+68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
57207+136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
57208+24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
57209+163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
57210+4 0 0 4 3 3
57211+3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
57212+156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
57213+155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
57214+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
57215+2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
57216+136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
57217+0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
57218+0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
57219+136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
57220+28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
57221+22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
57222+137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
57223+60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
57224+3 2 2 4 4 4
57225+3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
57226+157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
57227+37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
57228+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
57229+0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
57230+101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
57231+14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
57232+22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
57233+136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
57234+17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
57235+2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
57236+166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
57237+13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
57238+4 4 4 4 4 4
57239+1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
57240+163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
57241+4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
57242+4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
57243+40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
57244+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
57245+101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
57246+136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
57247+136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
57248+136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
57249+3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
57250+174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
57251+4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
57252+4 4 4 4 4 4
57253+4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
57254+155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
57255+4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
57256+4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
57257+101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
57258+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
57259+136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
57260+136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
57261+136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
57262+90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
57263+85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
57264+167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
57265+6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
57266+5 5 5 5 5 5
57267+1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
57268+131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
57269+6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
57270+0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
57271+101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
57272+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
57273+101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
57274+136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
57275+101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
57276+7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
57277+174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
57278+24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
57279+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
57280+5 5 5 4 4 4
57281+4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
57282+131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
57283+6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
57284+13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
57285+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
57286+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
57287+101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
57288+136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
57289+136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
57290+2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
57291+174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
57292+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
57293+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57294+4 4 4 4 4 4
57295+1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
57296+137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
57297+4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
57298+64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
57299+90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
57300+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
57301+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
57302+136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
57303+101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
57304+37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
57305+167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
57306+3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
57307+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57308+4 4 4 4 4 4
57309+4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
57310+153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
57311+4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
57312+90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
57313+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
57314+90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
57315+101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
57316+101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
57317+35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
57318+154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
57319+60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
57320+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57321+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57322+4 4 4 4 4 4
57323+1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
57324+153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
57325+4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
57326+64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
57327+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
57328+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
57329+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
57330+136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
57331+13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
57332+174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
57333+6 6 6 4 0 0 4 0 0 4 4 4 4 4 4 4 4 4
57334+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57335+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57336+4 4 4 4 4 4
57337+4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
57338+156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
57339+4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
57340+90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
57341+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
57342+90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
57343+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
57344+101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
57345+2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
57346+174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
57347+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57348+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57349+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57350+4 4 4 4 4 4
57351+3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
57352+158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
57353+4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
57354+37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
57355+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
57356+90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
57357+101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
57358+90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
57359+5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
57360+167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
57361+6 6 6 4 0 0 6 6 6 4 4 4 4 4 4 4 4 4
57362+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57363+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57364+4 4 4 4 4 4
57365+4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
57366+163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
57367+4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
57368+18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
57369+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
57370+90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
57371+101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
57372+13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
57373+3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
57374+174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
57375+4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
57376+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57377+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57378+4 4 4 4 4 4
57379+1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
57380+167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
57381+4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
57382+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
57383+26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
57384+90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
57385+101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
57386+7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
57387+4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
57388+174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
57389+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57390+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57391+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57392+4 4 4 4 4 4
57393+4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
57394+174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
57395+5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
57396+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
57397+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
57398+90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
57399+101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
57400+2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
57401+3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
57402+153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
57403+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57404+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57405+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57406+4 4 4 4 4 4
57407+1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
57408+174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
57409+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
57410+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
57411+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
57412+26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
57413+35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
57414+2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
57415+3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
57416+131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
57417+4 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57418+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57419+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57420+4 4 4 4 4 4
57421+3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
57422+174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
57423+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
57424+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
57425+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
57426+26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
57427+7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
57428+4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
57429+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
57430+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57431+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57432+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57433+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57434+4 4 4 4 4 4
57435+1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
57436+174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
57437+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
57438+18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
57439+18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
57440+26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
57441+28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
57442+3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
57443+4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
57444+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57445+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57446+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57447+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57448+4 4 4 4 4 4
57449+4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
57450+174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
57451+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
57452+10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
57453+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
57454+18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
57455+90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
57456+3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
57457+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
57458+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57459+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57460+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57461+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57462+4 4 4 4 4 4
57463+1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
57464+177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
57465+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
57466+10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
57467+26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
57468+6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
57469+10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
57470+2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
57471+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
57472+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57473+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57474+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57475+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57476+4 4 4 4 4 4
57477+4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
57478+177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
57479+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
57480+10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
57481+26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
57482+7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
57483+3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
57484+21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
57485+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
57486+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57487+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57488+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57489+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57490+4 4 4 4 4 4
57491+3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
57492+190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
57493+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
57494+10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
57495+24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
57496+18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
57497+28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
57498+26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
57499+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
57500+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57501+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57502+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57503+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57504+4 4 4 4 4 4
57505+4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
57506+190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
57507+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
57508+10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
57509+0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
57510+26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
57511+37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
57512+90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
57513+4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
57514+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57515+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57516+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57517+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57518+4 4 4 4 4 4
57519+4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
57520+193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
57521+5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
57522+10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
57523+1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
57524+26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
57525+22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
57526+26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
57527+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
57528+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57529+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57530+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57531+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57532+4 4 4 4 4 4
57533+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
57534+190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
57535+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
57536+10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
57537+2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
57538+26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
57539+10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
57540+26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
57541+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
57542+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57543+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57544+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57545+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57546+4 4 4 4 4 4
57547+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
57548+193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
57549+5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
57550+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
57551+13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
57552+10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
57553+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
57554+26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
57555+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
57556+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57557+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57558+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57559+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57560+4 4 4 4 4 4
57561+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
57562+190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
57563+5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
57564+28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
57565+10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
57566+28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
57567+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
57568+26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
57569+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
57570+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57571+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57572+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57573+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57574+4 4 4 4 4 4
57575+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
57576+193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
57577+5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
57578+4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
57579+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
57580+10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
57581+18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
57582+22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
57583+4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
57584+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57585+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57586+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57587+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57588+4 4 4 4 4 4
57589+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
57590+190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
57591+6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
57592+1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
57593+18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
57594+10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
57595+26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
57596+1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
57597+5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
57598+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57599+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57600+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57601+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57602+4 4 4 4 4 4
57603+4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
57604+193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
57605+2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
57606+4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
57607+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
57608+10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
57609+26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
57610+2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
57611+3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
57612+131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57613+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57614+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57615+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57616+4 4 4 4 4 4
57617+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
57618+193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
57619+0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
57620+4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
57621+13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
57622+10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
57623+28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
57624+4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
57625+0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
57626+125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57627+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57628+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57629+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57630+4 4 4 4 4 4
57631+4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
57632+193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
57633+120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
57634+4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
57635+4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
57636+10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
57637+4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
57638+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
57639+24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
57640+125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
57641+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57642+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57643+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57644+4 4 4 4 4 4
57645+4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
57646+174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
57647+220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
57648+3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
57649+4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
57650+10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
57651+1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
57652+5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
57653+137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
57654+125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
57655+0 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57656+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57657+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57658+4 4 4 4 4 4
57659+5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
57660+193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
57661+220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
57662+4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
57663+4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
57664+22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
57665+4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57666+1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
57667+166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
57668+125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
57669+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
57670+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57671+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57672+4 4 4 4 4 4
57673+4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
57674+220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
57675+205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
57676+24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
57677+4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
57678+4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
57679+4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
57680+2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
57681+156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
57682+137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
57683+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57684+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57685+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57686+4 4 4 4 4 4
57687+5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
57688+125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
57689+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
57690+193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
57691+5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
57692+1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
57693+5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
57694+60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
57695+153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
57696+125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
57697+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57698+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57699+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57700+4 4 4 4 4 4
57701+4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
57702+6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
57703+193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
57704+244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
57705+0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
57706+4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
57707+3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
57708+220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
57709+153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
57710+13 16 17 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
57711+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57712+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57713+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57714+4 4 4 4 4 4
57715+5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
57716+6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
57717+244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
57718+220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
57719+3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
57720+4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
57721+0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
57722+177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
57723+158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
57724+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
57725+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57726+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57727+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57728+4 4 4 4 4 4
57729+5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
57730+6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
57731+177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
57732+220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
57733+125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
57734+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
57735+37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
57736+174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
57737+158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
57738+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
57739+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57740+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57741+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57742+4 4 4 4 4 4
57743+4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
57744+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
57745+26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
57746+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
57747+244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
57748+0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
57749+177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
57750+174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
57751+60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
57752+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57753+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57754+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57755+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57756+4 4 4 4 4 4
57757+5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
57758+6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
57759+6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
57760+220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
57761+220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
57762+0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
57763+220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
57764+174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
57765+4 0 0 4 0 0 4 0 0 6 6 6 4 4 4 4 4 4
57766+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57767+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57768+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57769+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57770+4 4 4 4 4 4
57771+4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
57772+6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
57773+4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
57774+220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
57775+205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
57776+60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
57777+177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
57778+190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
57779+4 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57780+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57781+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57782+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57783+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57784+4 4 4 4 4 4
57785+4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
57786+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
57787+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
57788+125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
57789+205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
57790+193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
57791+190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
57792+153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
57793+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57794+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57795+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57796+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57797+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57798+4 4 4 4 4 4
57799+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
57800+6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
57801+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
57802+4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
57803+205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
57804+220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
57805+174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
57806+6 6 6 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
57807+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57808+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57809+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57810+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57811+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57812+4 4 4 4 4 4
57813+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
57814+5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
57815+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
57816+4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
57817+220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
57818+190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
57819+193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
57820+4 0 0 4 3 3 6 6 6 4 4 4 4 4 4 4 4 4
57821+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57822+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57823+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57824+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57825+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57826+4 4 4 4 4 4
57827+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57828+4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
57829+4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
57830+6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
57831+174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
57832+193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
57833+193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
57834+6 6 6 6 6 6 4 3 3 5 5 5 4 4 4 4 4 4
57835+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57836+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57837+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57838+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57839+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57840+4 4 4 4 4 4
57841+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57842+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
57843+5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
57844+5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
57845+6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
57846+193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
57847+60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
57848+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
57849+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57850+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57851+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57852+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57853+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57854+4 4 4 4 4 4
57855+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57856+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57857+4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
57858+5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
57859+4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
57860+193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
57861+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
57862+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
57863+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57864+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57865+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57866+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57867+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57868+4 4 4 4 4 4
57869+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57870+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57871+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
57872+4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
57873+6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
57874+153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
57875+6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
57876+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57877+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57878+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57879+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57880+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57881+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57882+4 4 4 4 4 4
57883+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57884+4 4 4 4 4 4 4 4 4 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 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
57887+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
57888+24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
57889+6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
57890+4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57893+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57894+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57895+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57896+4 4 4 4 4 4
57897+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57898+4 4 4 4 4 4 4 4 4 4 4 4 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 5 5 5 4 3 3 5 5 5 6 6 6
57901+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
57902+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
57903+4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 4 4 4
57904+4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4
57907+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57908+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57909+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57910+4 4 4 4 4 4
57911+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57912+4 4 4 4 4 4 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 5 5 5 4 3 3 5 5 5
57915+5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
57916+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
57917+6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 4 4 4
57918+4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57922+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57923+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57924+4 4 4 4 4 4
57925+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57926+4 4 4 4 4 4 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 5 5 5
57929+4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
57930+4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
57931+6 6 6 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57932+4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4
57936+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57937+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57938+4 4 4 4 4 4
57939+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
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 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
57944+6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
57945+4 3 3 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
57946+4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57951+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57952+4 4 4 4 4 4
57953+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
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 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
57958+4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
57959+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57960+4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
57965+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57966+4 4 4 4 4 4
57967+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 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 5 5 5 4 3 3 6 6 6
57972+5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
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 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4
57979+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57980+4 4 4 4 4 4
57981+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 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 5 5 5 4 3 3
57986+5 5 5 4 3 3 5 5 5 5 5 5 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 4 4 4 4 4 4 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 4 4 4
57993+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57994+4 4 4 4 4 4
57995diff --git a/drivers/xen/xenfs/xenstored.c b/drivers/xen/xenfs/xenstored.c
57996index fef20db..d28b1ab 100644
57997--- a/drivers/xen/xenfs/xenstored.c
57998+++ b/drivers/xen/xenfs/xenstored.c
57999@@ -24,7 +24,12 @@ static int xsd_release(struct inode *inode, struct file *file)
58000 static int xsd_kva_open(struct inode *inode, struct file *file)
58001 {
58002 file->private_data = (void *)kasprintf(GFP_KERNEL, "0x%p",
58003+#ifdef CONFIG_GRKERNSEC_HIDESYM
58004+ NULL);
58005+#else
58006 xen_store_interface);
58007+#endif
58008+
58009 if (!file->private_data)
58010 return -ENOMEM;
58011 return 0;
58012diff --git a/fs/9p/vfs_addr.c b/fs/9p/vfs_addr.c
58013index eb14e05..5156de7 100644
58014--- a/fs/9p/vfs_addr.c
58015+++ b/fs/9p/vfs_addr.c
58016@@ -187,7 +187,7 @@ static int v9fs_vfs_writepage_locked(struct page *page)
58017
58018 retval = v9fs_file_write_internal(inode,
58019 v9inode->writeback_fid,
58020- (__force const char __user *)buffer,
58021+ (const char __force_user *)buffer,
58022 len, &offset, 0);
58023 if (retval > 0)
58024 retval = 0;
58025diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
58026index 296482f..183ddc3 100644
58027--- a/fs/9p/vfs_inode.c
58028+++ b/fs/9p/vfs_inode.c
58029@@ -1312,7 +1312,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
58030 void
58031 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
58032 {
58033- char *s = nd_get_link(nd);
58034+ const char *s = nd_get_link(nd);
58035
58036 p9_debug(P9_DEBUG_VFS, " %pd %s\n",
58037 dentry, IS_ERR(s) ? "<error>" : s);
58038diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
58039index 370b24c..ff0be7b 100644
58040--- a/fs/Kconfig.binfmt
58041+++ b/fs/Kconfig.binfmt
58042@@ -103,7 +103,7 @@ config HAVE_AOUT
58043
58044 config BINFMT_AOUT
58045 tristate "Kernel support for a.out and ECOFF binaries"
58046- depends on HAVE_AOUT
58047+ depends on HAVE_AOUT && BROKEN
58048 ---help---
58049 A.out (Assembler.OUTput) is a set of formats for libraries and
58050 executables used in the earliest versions of UNIX. Linux used
58051diff --git a/fs/afs/inode.c b/fs/afs/inode.c
58052index 2946712..f737435 100644
58053--- a/fs/afs/inode.c
58054+++ b/fs/afs/inode.c
58055@@ -141,7 +141,7 @@ struct inode *afs_iget_autocell(struct inode *dir, const char *dev_name,
58056 struct afs_vnode *vnode;
58057 struct super_block *sb;
58058 struct inode *inode;
58059- static atomic_t afs_autocell_ino;
58060+ static atomic_unchecked_t afs_autocell_ino;
58061
58062 _enter("{%x:%u},%*.*s,",
58063 AFS_FS_I(dir)->fid.vid, AFS_FS_I(dir)->fid.vnode,
58064@@ -154,7 +154,7 @@ struct inode *afs_iget_autocell(struct inode *dir, const char *dev_name,
58065 data.fid.unique = 0;
58066 data.fid.vnode = 0;
58067
58068- inode = iget5_locked(sb, atomic_inc_return(&afs_autocell_ino),
58069+ inode = iget5_locked(sb, atomic_inc_return_unchecked(&afs_autocell_ino),
58070 afs_iget5_autocell_test, afs_iget5_set,
58071 &data);
58072 if (!inode) {
58073diff --git a/fs/aio.c b/fs/aio.c
58074index 14b9315..365980f 100644
58075--- a/fs/aio.c
58076+++ b/fs/aio.c
58077@@ -388,7 +388,7 @@ static int aio_setup_ring(struct kioctx *ctx)
58078 size += sizeof(struct io_event) * nr_events;
58079
58080 nr_pages = PFN_UP(size);
58081- if (nr_pages < 0)
58082+ if (nr_pages <= 0)
58083 return -EINVAL;
58084
58085 file = aio_private_file(ctx, nr_pages);
58086diff --git a/fs/attr.c b/fs/attr.c
58087index 6530ced..4a827e2 100644
58088--- a/fs/attr.c
58089+++ b/fs/attr.c
58090@@ -102,6 +102,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
58091 unsigned long limit;
58092
58093 limit = rlimit(RLIMIT_FSIZE);
58094+ gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
58095 if (limit != RLIM_INFINITY && offset > limit)
58096 goto out_sig;
58097 if (offset > inode->i_sb->s_maxbytes)
58098diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
58099index 116fd38..c04182da 100644
58100--- a/fs/autofs4/waitq.c
58101+++ b/fs/autofs4/waitq.c
58102@@ -59,7 +59,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
58103 {
58104 unsigned long sigpipe, flags;
58105 mm_segment_t fs;
58106- const char *data = (const char *)addr;
58107+ const char __user *data = (const char __force_user *)addr;
58108 ssize_t wr = 0;
58109
58110 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
58111@@ -340,6 +340,10 @@ static int validate_request(struct autofs_wait_queue **wait,
58112 return 1;
58113 }
58114
58115+#ifdef CONFIG_GRKERNSEC_HIDESYM
58116+static atomic_unchecked_t autofs_dummy_name_id = ATOMIC_INIT(0);
58117+#endif
58118+
58119 int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
58120 enum autofs_notify notify)
58121 {
58122@@ -385,7 +389,12 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
58123
58124 /* If this is a direct mount request create a dummy name */
58125 if (IS_ROOT(dentry) && autofs_type_trigger(sbi->type))
58126+#ifdef CONFIG_GRKERNSEC_HIDESYM
58127+ /* this name does get written to userland via autofs4_write() */
58128+ qstr.len = sprintf(name, "%08x", atomic_inc_return_unchecked(&autofs_dummy_name_id));
58129+#else
58130 qstr.len = sprintf(name, "%p", dentry);
58131+#endif
58132 else {
58133 qstr.len = autofs4_getpath(sbi, dentry, &name);
58134 if (!qstr.len) {
58135diff --git a/fs/befs/endian.h b/fs/befs/endian.h
58136index 2722387..56059b5 100644
58137--- a/fs/befs/endian.h
58138+++ b/fs/befs/endian.h
58139@@ -11,7 +11,7 @@
58140
58141 #include <asm/byteorder.h>
58142
58143-static inline u64
58144+static inline u64 __intentional_overflow(-1)
58145 fs64_to_cpu(const struct super_block *sb, fs64 n)
58146 {
58147 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
58148@@ -29,7 +29,7 @@ cpu_to_fs64(const struct super_block *sb, u64 n)
58149 return (__force fs64)cpu_to_be64(n);
58150 }
58151
58152-static inline u32
58153+static inline u32 __intentional_overflow(-1)
58154 fs32_to_cpu(const struct super_block *sb, fs32 n)
58155 {
58156 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
58157@@ -47,7 +47,7 @@ cpu_to_fs32(const struct super_block *sb, u32 n)
58158 return (__force fs32)cpu_to_be32(n);
58159 }
58160
58161-static inline u16
58162+static inline u16 __intentional_overflow(-1)
58163 fs16_to_cpu(const struct super_block *sb, fs16 n)
58164 {
58165 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
58166diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
58167index 929dec0..84bd914 100644
58168--- a/fs/binfmt_aout.c
58169+++ b/fs/binfmt_aout.c
58170@@ -16,6 +16,7 @@
58171 #include <linux/string.h>
58172 #include <linux/fs.h>
58173 #include <linux/file.h>
58174+#include <linux/security.h>
58175 #include <linux/stat.h>
58176 #include <linux/fcntl.h>
58177 #include <linux/ptrace.h>
58178@@ -58,6 +59,8 @@ static int aout_core_dump(struct coredump_params *cprm)
58179 #endif
58180 # define START_STACK(u) ((void __user *)u.start_stack)
58181
58182+ memset(&dump, 0, sizeof(dump));
58183+
58184 fs = get_fs();
58185 set_fs(KERNEL_DS);
58186 has_dumped = 1;
58187@@ -68,10 +71,12 @@ static int aout_core_dump(struct coredump_params *cprm)
58188
58189 /* If the size of the dump file exceeds the rlimit, then see what would happen
58190 if we wrote the stack, but not the data area. */
58191+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
58192 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
58193 dump.u_dsize = 0;
58194
58195 /* Make sure we have enough room to write the stack and data areas. */
58196+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
58197 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
58198 dump.u_ssize = 0;
58199
58200@@ -232,6 +237,8 @@ static int load_aout_binary(struct linux_binprm * bprm)
58201 rlim = rlimit(RLIMIT_DATA);
58202 if (rlim >= RLIM_INFINITY)
58203 rlim = ~0;
58204+
58205+ gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
58206 if (ex.a_data + ex.a_bss > rlim)
58207 return -ENOMEM;
58208
58209@@ -261,6 +268,27 @@ static int load_aout_binary(struct linux_binprm * bprm)
58210
58211 install_exec_creds(bprm);
58212
58213+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
58214+ current->mm->pax_flags = 0UL;
58215+#endif
58216+
58217+#ifdef CONFIG_PAX_PAGEEXEC
58218+ if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
58219+ current->mm->pax_flags |= MF_PAX_PAGEEXEC;
58220+
58221+#ifdef CONFIG_PAX_EMUTRAMP
58222+ if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
58223+ current->mm->pax_flags |= MF_PAX_EMUTRAMP;
58224+#endif
58225+
58226+#ifdef CONFIG_PAX_MPROTECT
58227+ if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
58228+ current->mm->pax_flags |= MF_PAX_MPROTECT;
58229+#endif
58230+
58231+ }
58232+#endif
58233+
58234 if (N_MAGIC(ex) == OMAGIC) {
58235 unsigned long text_addr, map_size;
58236 loff_t pos;
58237@@ -312,7 +340,7 @@ static int load_aout_binary(struct linux_binprm * bprm)
58238 return error;
58239
58240 error = vm_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
58241- PROT_READ | PROT_WRITE | PROT_EXEC,
58242+ PROT_READ | PROT_WRITE,
58243 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
58244 fd_offset + ex.a_text);
58245 if (error != N_DATADDR(ex))
58246diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
58247index d8fc060..cbd44d5 100644
58248--- a/fs/binfmt_elf.c
58249+++ b/fs/binfmt_elf.c
58250@@ -34,6 +34,7 @@
58251 #include <linux/utsname.h>
58252 #include <linux/coredump.h>
58253 #include <linux/sched.h>
58254+#include <linux/xattr.h>
58255 #include <asm/uaccess.h>
58256 #include <asm/param.h>
58257 #include <asm/page.h>
58258@@ -47,7 +48,7 @@
58259
58260 static int load_elf_binary(struct linux_binprm *bprm);
58261 static unsigned long elf_map(struct file *, unsigned long, struct elf_phdr *,
58262- int, int, unsigned long);
58263+ int, int, unsigned long) __intentional_overflow(-1);
58264
58265 #ifdef CONFIG_USELIB
58266 static int load_elf_library(struct file *);
58267@@ -65,6 +66,14 @@ static int elf_core_dump(struct coredump_params *cprm);
58268 #define elf_core_dump NULL
58269 #endif
58270
58271+#ifdef CONFIG_PAX_MPROTECT
58272+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
58273+#endif
58274+
58275+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
58276+static void elf_handle_mmap(struct file *file);
58277+#endif
58278+
58279 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
58280 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
58281 #else
58282@@ -84,6 +93,15 @@ static struct linux_binfmt elf_format = {
58283 .load_binary = load_elf_binary,
58284 .load_shlib = load_elf_library,
58285 .core_dump = elf_core_dump,
58286+
58287+#ifdef CONFIG_PAX_MPROTECT
58288+ .handle_mprotect= elf_handle_mprotect,
58289+#endif
58290+
58291+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
58292+ .handle_mmap = elf_handle_mmap,
58293+#endif
58294+
58295 .min_coredump = ELF_EXEC_PAGESIZE,
58296 };
58297
58298@@ -91,6 +109,8 @@ static struct linux_binfmt elf_format = {
58299
58300 static int set_brk(unsigned long start, unsigned long end)
58301 {
58302+ unsigned long e = end;
58303+
58304 start = ELF_PAGEALIGN(start);
58305 end = ELF_PAGEALIGN(end);
58306 if (end > start) {
58307@@ -99,7 +119,7 @@ static int set_brk(unsigned long start, unsigned long end)
58308 if (BAD_ADDR(addr))
58309 return addr;
58310 }
58311- current->mm->start_brk = current->mm->brk = end;
58312+ current->mm->start_brk = current->mm->brk = e;
58313 return 0;
58314 }
58315
58316@@ -160,12 +180,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
58317 elf_addr_t __user *u_rand_bytes;
58318 const char *k_platform = ELF_PLATFORM;
58319 const char *k_base_platform = ELF_BASE_PLATFORM;
58320- unsigned char k_rand_bytes[16];
58321+ u32 k_rand_bytes[4];
58322 int items;
58323 elf_addr_t *elf_info;
58324 int ei_index = 0;
58325 const struct cred *cred = current_cred();
58326 struct vm_area_struct *vma;
58327+ unsigned long saved_auxv[AT_VECTOR_SIZE];
58328
58329 /*
58330 * In some cases (e.g. Hyper-Threading), we want to avoid L1
58331@@ -207,8 +228,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
58332 * Generate 16 random bytes for userspace PRNG seeding.
58333 */
58334 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
58335- u_rand_bytes = (elf_addr_t __user *)
58336- STACK_ALLOC(p, sizeof(k_rand_bytes));
58337+ prandom_seed(k_rand_bytes[0] ^ prandom_u32());
58338+ prandom_seed(k_rand_bytes[1] ^ prandom_u32());
58339+ prandom_seed(k_rand_bytes[2] ^ prandom_u32());
58340+ prandom_seed(k_rand_bytes[3] ^ prandom_u32());
58341+ p = STACK_ROUND(p, sizeof(k_rand_bytes));
58342+ u_rand_bytes = (elf_addr_t __user *) p;
58343 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
58344 return -EFAULT;
58345
58346@@ -323,9 +348,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
58347 return -EFAULT;
58348 current->mm->env_end = p;
58349
58350+ memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
58351+
58352 /* Put the elf_info on the stack in the right place. */
58353 sp = (elf_addr_t __user *)envp + 1;
58354- if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
58355+ if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
58356 return -EFAULT;
58357 return 0;
58358 }
58359@@ -393,15 +420,14 @@ static unsigned long total_mapping_size(struct elf_phdr *cmds, int nr)
58360 an ELF header */
58361
58362 static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
58363- struct file *interpreter, unsigned long *interp_map_addr,
58364- unsigned long no_base)
58365+ struct file *interpreter, unsigned long no_base)
58366 {
58367 struct elf_phdr *elf_phdata;
58368 struct elf_phdr *eppnt;
58369- unsigned long load_addr = 0;
58370+ unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
58371 int load_addr_set = 0;
58372 unsigned long last_bss = 0, elf_bss = 0;
58373- unsigned long error = ~0UL;
58374+ unsigned long error = -EINVAL;
58375 unsigned long total_size;
58376 int retval, i, size;
58377
58378@@ -447,6 +473,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
58379 goto out_close;
58380 }
58381
58382+#ifdef CONFIG_PAX_SEGMEXEC
58383+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
58384+ pax_task_size = SEGMEXEC_TASK_SIZE;
58385+#endif
58386+
58387 eppnt = elf_phdata;
58388 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
58389 if (eppnt->p_type == PT_LOAD) {
58390@@ -470,8 +501,6 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
58391 map_addr = elf_map(interpreter, load_addr + vaddr,
58392 eppnt, elf_prot, elf_type, total_size);
58393 total_size = 0;
58394- if (!*interp_map_addr)
58395- *interp_map_addr = map_addr;
58396 error = map_addr;
58397 if (BAD_ADDR(map_addr))
58398 goto out_close;
58399@@ -490,8 +519,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
58400 k = load_addr + eppnt->p_vaddr;
58401 if (BAD_ADDR(k) ||
58402 eppnt->p_filesz > eppnt->p_memsz ||
58403- eppnt->p_memsz > TASK_SIZE ||
58404- TASK_SIZE - eppnt->p_memsz < k) {
58405+ eppnt->p_memsz > pax_task_size ||
58406+ pax_task_size - eppnt->p_memsz < k) {
58407 error = -ENOMEM;
58408 goto out_close;
58409 }
58410@@ -530,9 +559,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
58411 elf_bss = ELF_PAGESTART(elf_bss + ELF_MIN_ALIGN - 1);
58412
58413 /* Map the last of the bss segment */
58414- error = vm_brk(elf_bss, last_bss - elf_bss);
58415- if (BAD_ADDR(error))
58416- goto out_close;
58417+ if (last_bss > elf_bss) {
58418+ error = vm_brk(elf_bss, last_bss - elf_bss);
58419+ if (BAD_ADDR(error))
58420+ goto out_close;
58421+ }
58422 }
58423
58424 error = load_addr;
58425@@ -543,6 +574,336 @@ out:
58426 return error;
58427 }
58428
58429+#ifdef CONFIG_PAX_PT_PAX_FLAGS
58430+#ifdef CONFIG_PAX_SOFTMODE
58431+static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
58432+{
58433+ unsigned long pax_flags = 0UL;
58434+
58435+#ifdef CONFIG_PAX_PAGEEXEC
58436+ if (elf_phdata->p_flags & PF_PAGEEXEC)
58437+ pax_flags |= MF_PAX_PAGEEXEC;
58438+#endif
58439+
58440+#ifdef CONFIG_PAX_SEGMEXEC
58441+ if (elf_phdata->p_flags & PF_SEGMEXEC)
58442+ pax_flags |= MF_PAX_SEGMEXEC;
58443+#endif
58444+
58445+#ifdef CONFIG_PAX_EMUTRAMP
58446+ if ((elf_phdata->p_flags & PF_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
58447+ pax_flags |= MF_PAX_EMUTRAMP;
58448+#endif
58449+
58450+#ifdef CONFIG_PAX_MPROTECT
58451+ if (elf_phdata->p_flags & PF_MPROTECT)
58452+ pax_flags |= MF_PAX_MPROTECT;
58453+#endif
58454+
58455+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
58456+ if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
58457+ pax_flags |= MF_PAX_RANDMMAP;
58458+#endif
58459+
58460+ return pax_flags;
58461+}
58462+#endif
58463+
58464+static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
58465+{
58466+ unsigned long pax_flags = 0UL;
58467+
58468+#ifdef CONFIG_PAX_PAGEEXEC
58469+ if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
58470+ pax_flags |= MF_PAX_PAGEEXEC;
58471+#endif
58472+
58473+#ifdef CONFIG_PAX_SEGMEXEC
58474+ if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
58475+ pax_flags |= MF_PAX_SEGMEXEC;
58476+#endif
58477+
58478+#ifdef CONFIG_PAX_EMUTRAMP
58479+ if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
58480+ pax_flags |= MF_PAX_EMUTRAMP;
58481+#endif
58482+
58483+#ifdef CONFIG_PAX_MPROTECT
58484+ if (!(elf_phdata->p_flags & PF_NOMPROTECT))
58485+ pax_flags |= MF_PAX_MPROTECT;
58486+#endif
58487+
58488+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
58489+ if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
58490+ pax_flags |= MF_PAX_RANDMMAP;
58491+#endif
58492+
58493+ return pax_flags;
58494+}
58495+#endif
58496+
58497+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
58498+#ifdef CONFIG_PAX_SOFTMODE
58499+static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
58500+{
58501+ unsigned long pax_flags = 0UL;
58502+
58503+#ifdef CONFIG_PAX_PAGEEXEC
58504+ if (pax_flags_softmode & MF_PAX_PAGEEXEC)
58505+ pax_flags |= MF_PAX_PAGEEXEC;
58506+#endif
58507+
58508+#ifdef CONFIG_PAX_SEGMEXEC
58509+ if (pax_flags_softmode & MF_PAX_SEGMEXEC)
58510+ pax_flags |= MF_PAX_SEGMEXEC;
58511+#endif
58512+
58513+#ifdef CONFIG_PAX_EMUTRAMP
58514+ if ((pax_flags_softmode & MF_PAX_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
58515+ pax_flags |= MF_PAX_EMUTRAMP;
58516+#endif
58517+
58518+#ifdef CONFIG_PAX_MPROTECT
58519+ if (pax_flags_softmode & MF_PAX_MPROTECT)
58520+ pax_flags |= MF_PAX_MPROTECT;
58521+#endif
58522+
58523+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
58524+ if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
58525+ pax_flags |= MF_PAX_RANDMMAP;
58526+#endif
58527+
58528+ return pax_flags;
58529+}
58530+#endif
58531+
58532+static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
58533+{
58534+ unsigned long pax_flags = 0UL;
58535+
58536+#ifdef CONFIG_PAX_PAGEEXEC
58537+ if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
58538+ pax_flags |= MF_PAX_PAGEEXEC;
58539+#endif
58540+
58541+#ifdef CONFIG_PAX_SEGMEXEC
58542+ if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
58543+ pax_flags |= MF_PAX_SEGMEXEC;
58544+#endif
58545+
58546+#ifdef CONFIG_PAX_EMUTRAMP
58547+ if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
58548+ pax_flags |= MF_PAX_EMUTRAMP;
58549+#endif
58550+
58551+#ifdef CONFIG_PAX_MPROTECT
58552+ if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
58553+ pax_flags |= MF_PAX_MPROTECT;
58554+#endif
58555+
58556+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
58557+ if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
58558+ pax_flags |= MF_PAX_RANDMMAP;
58559+#endif
58560+
58561+ return pax_flags;
58562+}
58563+#endif
58564+
58565+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
58566+static unsigned long pax_parse_defaults(void)
58567+{
58568+ unsigned long pax_flags = 0UL;
58569+
58570+#ifdef CONFIG_PAX_SOFTMODE
58571+ if (pax_softmode)
58572+ return pax_flags;
58573+#endif
58574+
58575+#ifdef CONFIG_PAX_PAGEEXEC
58576+ pax_flags |= MF_PAX_PAGEEXEC;
58577+#endif
58578+
58579+#ifdef CONFIG_PAX_SEGMEXEC
58580+ pax_flags |= MF_PAX_SEGMEXEC;
58581+#endif
58582+
58583+#ifdef CONFIG_PAX_MPROTECT
58584+ pax_flags |= MF_PAX_MPROTECT;
58585+#endif
58586+
58587+#ifdef CONFIG_PAX_RANDMMAP
58588+ if (randomize_va_space)
58589+ pax_flags |= MF_PAX_RANDMMAP;
58590+#endif
58591+
58592+ return pax_flags;
58593+}
58594+
58595+static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
58596+{
58597+ unsigned long pax_flags = PAX_PARSE_FLAGS_FALLBACK;
58598+
58599+#ifdef CONFIG_PAX_EI_PAX
58600+
58601+#ifdef CONFIG_PAX_SOFTMODE
58602+ if (pax_softmode)
58603+ return pax_flags;
58604+#endif
58605+
58606+ pax_flags = 0UL;
58607+
58608+#ifdef CONFIG_PAX_PAGEEXEC
58609+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
58610+ pax_flags |= MF_PAX_PAGEEXEC;
58611+#endif
58612+
58613+#ifdef CONFIG_PAX_SEGMEXEC
58614+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
58615+ pax_flags |= MF_PAX_SEGMEXEC;
58616+#endif
58617+
58618+#ifdef CONFIG_PAX_EMUTRAMP
58619+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
58620+ pax_flags |= MF_PAX_EMUTRAMP;
58621+#endif
58622+
58623+#ifdef CONFIG_PAX_MPROTECT
58624+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
58625+ pax_flags |= MF_PAX_MPROTECT;
58626+#endif
58627+
58628+#ifdef CONFIG_PAX_ASLR
58629+ if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
58630+ pax_flags |= MF_PAX_RANDMMAP;
58631+#endif
58632+
58633+#endif
58634+
58635+ return pax_flags;
58636+
58637+}
58638+
58639+static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
58640+{
58641+
58642+#ifdef CONFIG_PAX_PT_PAX_FLAGS
58643+ unsigned long i;
58644+
58645+ for (i = 0UL; i < elf_ex->e_phnum; i++)
58646+ if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
58647+ if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
58648+ ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
58649+ ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
58650+ ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
58651+ ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
58652+ return PAX_PARSE_FLAGS_FALLBACK;
58653+
58654+#ifdef CONFIG_PAX_SOFTMODE
58655+ if (pax_softmode)
58656+ return pax_parse_pt_pax_softmode(&elf_phdata[i]);
58657+ else
58658+#endif
58659+
58660+ return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
58661+ break;
58662+ }
58663+#endif
58664+
58665+ return PAX_PARSE_FLAGS_FALLBACK;
58666+}
58667+
58668+static unsigned long pax_parse_xattr_pax(struct file * const file)
58669+{
58670+
58671+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
58672+ ssize_t xattr_size, i;
58673+ unsigned char xattr_value[sizeof("pemrs") - 1];
58674+ unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
58675+
58676+ xattr_size = pax_getxattr(file->f_path.dentry, xattr_value, sizeof xattr_value);
58677+ if (xattr_size < 0 || xattr_size > sizeof xattr_value)
58678+ return PAX_PARSE_FLAGS_FALLBACK;
58679+
58680+ for (i = 0; i < xattr_size; i++)
58681+ switch (xattr_value[i]) {
58682+ default:
58683+ return PAX_PARSE_FLAGS_FALLBACK;
58684+
58685+#define parse_flag(option1, option2, flag) \
58686+ case option1: \
58687+ if (pax_flags_hardmode & MF_PAX_##flag) \
58688+ return PAX_PARSE_FLAGS_FALLBACK;\
58689+ pax_flags_hardmode |= MF_PAX_##flag; \
58690+ break; \
58691+ case option2: \
58692+ if (pax_flags_softmode & MF_PAX_##flag) \
58693+ return PAX_PARSE_FLAGS_FALLBACK;\
58694+ pax_flags_softmode |= MF_PAX_##flag; \
58695+ break;
58696+
58697+ parse_flag('p', 'P', PAGEEXEC);
58698+ parse_flag('e', 'E', EMUTRAMP);
58699+ parse_flag('m', 'M', MPROTECT);
58700+ parse_flag('r', 'R', RANDMMAP);
58701+ parse_flag('s', 'S', SEGMEXEC);
58702+
58703+#undef parse_flag
58704+ }
58705+
58706+ if (pax_flags_hardmode & pax_flags_softmode)
58707+ return PAX_PARSE_FLAGS_FALLBACK;
58708+
58709+#ifdef CONFIG_PAX_SOFTMODE
58710+ if (pax_softmode)
58711+ return pax_parse_xattr_pax_softmode(pax_flags_softmode);
58712+ else
58713+#endif
58714+
58715+ return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
58716+#else
58717+ return PAX_PARSE_FLAGS_FALLBACK;
58718+#endif
58719+
58720+}
58721+
58722+static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
58723+{
58724+ unsigned long pax_flags, ei_pax_flags, pt_pax_flags, xattr_pax_flags;
58725+
58726+ pax_flags = pax_parse_defaults();
58727+ ei_pax_flags = pax_parse_ei_pax(elf_ex);
58728+ pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
58729+ xattr_pax_flags = pax_parse_xattr_pax(file);
58730+
58731+ if (pt_pax_flags != PAX_PARSE_FLAGS_FALLBACK &&
58732+ xattr_pax_flags != PAX_PARSE_FLAGS_FALLBACK &&
58733+ pt_pax_flags != xattr_pax_flags)
58734+ return -EINVAL;
58735+ if (xattr_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
58736+ pax_flags = xattr_pax_flags;
58737+ else if (pt_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
58738+ pax_flags = pt_pax_flags;
58739+ else if (ei_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
58740+ pax_flags = ei_pax_flags;
58741+
58742+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
58743+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
58744+ if ((__supported_pte_mask & _PAGE_NX))
58745+ pax_flags &= ~MF_PAX_SEGMEXEC;
58746+ else
58747+ pax_flags &= ~MF_PAX_PAGEEXEC;
58748+ }
58749+#endif
58750+
58751+ if (0 > pax_check_flags(&pax_flags))
58752+ return -EINVAL;
58753+
58754+ current->mm->pax_flags = pax_flags;
58755+ return 0;
58756+}
58757+#endif
58758+
58759 /*
58760 * These are the functions used to load ELF style executables and shared
58761 * libraries. There is no binary dependent code anywhere else.
58762@@ -556,6 +917,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
58763 {
58764 unsigned int random_variable = 0;
58765
58766+#ifdef CONFIG_PAX_RANDUSTACK
58767+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
58768+ return stack_top - current->mm->delta_stack;
58769+#endif
58770+
58771 if ((current->flags & PF_RANDOMIZE) &&
58772 !(current->personality & ADDR_NO_RANDOMIZE)) {
58773 random_variable = get_random_int() & STACK_RND_MASK;
58774@@ -574,7 +940,7 @@ static int load_elf_binary(struct linux_binprm *bprm)
58775 unsigned long load_addr = 0, load_bias = 0;
58776 int load_addr_set = 0;
58777 char * elf_interpreter = NULL;
58778- unsigned long error;
58779+ unsigned long error = 0;
58780 struct elf_phdr *elf_ppnt, *elf_phdata;
58781 unsigned long elf_bss, elf_brk;
58782 int retval, i;
58783@@ -589,6 +955,7 @@ static int load_elf_binary(struct linux_binprm *bprm)
58784 struct elfhdr elf_ex;
58785 struct elfhdr interp_elf_ex;
58786 } *loc;
58787+ unsigned long pax_task_size;
58788
58789 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
58790 if (!loc) {
58791@@ -726,6 +1093,77 @@ static int load_elf_binary(struct linux_binprm *bprm)
58792 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
58793 may depend on the personality. */
58794 SET_PERSONALITY(loc->elf_ex);
58795+
58796+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
58797+ current->mm->pax_flags = 0UL;
58798+#endif
58799+
58800+#ifdef CONFIG_PAX_DLRESOLVE
58801+ current->mm->call_dl_resolve = 0UL;
58802+#endif
58803+
58804+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
58805+ current->mm->call_syscall = 0UL;
58806+#endif
58807+
58808+#ifdef CONFIG_PAX_ASLR
58809+ current->mm->delta_mmap = 0UL;
58810+ current->mm->delta_stack = 0UL;
58811+#endif
58812+
58813+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
58814+ if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
58815+ send_sig(SIGKILL, current, 0);
58816+ goto out_free_dentry;
58817+ }
58818+#endif
58819+
58820+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
58821+ pax_set_initial_flags(bprm);
58822+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
58823+ if (pax_set_initial_flags_func)
58824+ (pax_set_initial_flags_func)(bprm);
58825+#endif
58826+
58827+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
58828+ if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
58829+ current->mm->context.user_cs_limit = PAGE_SIZE;
58830+ current->mm->def_flags |= VM_PAGEEXEC | VM_NOHUGEPAGE;
58831+ }
58832+#endif
58833+
58834+#ifdef CONFIG_PAX_SEGMEXEC
58835+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
58836+ current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
58837+ current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
58838+ pax_task_size = SEGMEXEC_TASK_SIZE;
58839+ current->mm->def_flags |= VM_NOHUGEPAGE;
58840+ } else
58841+#endif
58842+
58843+ pax_task_size = TASK_SIZE;
58844+
58845+#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
58846+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
58847+ set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
58848+ put_cpu();
58849+ }
58850+#endif
58851+
58852+#ifdef CONFIG_PAX_ASLR
58853+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
58854+ current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
58855+ current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
58856+ }
58857+#endif
58858+
58859+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
58860+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
58861+ executable_stack = EXSTACK_DISABLE_X;
58862+ current->personality &= ~READ_IMPLIES_EXEC;
58863+ } else
58864+#endif
58865+
58866 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
58867 current->personality |= READ_IMPLIES_EXEC;
58868
58869@@ -811,6 +1249,20 @@ static int load_elf_binary(struct linux_binprm *bprm)
58870 #else
58871 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
58872 #endif
58873+
58874+#ifdef CONFIG_PAX_RANDMMAP
58875+ /* PaX: randomize base address at the default exe base if requested */
58876+ if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
58877+#ifdef CONFIG_SPARC64
58878+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
58879+#else
58880+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
58881+#endif
58882+ load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
58883+ elf_flags |= MAP_FIXED;
58884+ }
58885+#endif
58886+
58887 }
58888
58889 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
58890@@ -842,9 +1294,9 @@ static int load_elf_binary(struct linux_binprm *bprm)
58891 * allowed task size. Note that p_filesz must always be
58892 * <= p_memsz so it is only necessary to check p_memsz.
58893 */
58894- if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
58895- elf_ppnt->p_memsz > TASK_SIZE ||
58896- TASK_SIZE - elf_ppnt->p_memsz < k) {
58897+ if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
58898+ elf_ppnt->p_memsz > pax_task_size ||
58899+ pax_task_size - elf_ppnt->p_memsz < k) {
58900 /* set_brk can never work. Avoid overflows. */
58901 retval = -EINVAL;
58902 goto out_free_dentry;
58903@@ -880,16 +1332,43 @@ static int load_elf_binary(struct linux_binprm *bprm)
58904 if (retval)
58905 goto out_free_dentry;
58906 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
58907- retval = -EFAULT; /* Nobody gets to see this, but.. */
58908- goto out_free_dentry;
58909+ /*
58910+ * This bss-zeroing can fail if the ELF
58911+ * file specifies odd protections. So
58912+ * we don't check the return value
58913+ */
58914 }
58915
58916+#ifdef CONFIG_PAX_RANDMMAP
58917+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
58918+ unsigned long start, size, flags;
58919+ vm_flags_t vm_flags;
58920+
58921+ start = ELF_PAGEALIGN(elf_brk);
58922+ size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
58923+ flags = MAP_FIXED | MAP_PRIVATE;
58924+ vm_flags = VM_DONTEXPAND | VM_DONTDUMP;
58925+
58926+ down_write(&current->mm->mmap_sem);
58927+ start = get_unmapped_area(NULL, start, PAGE_ALIGN(size), 0, flags);
58928+ retval = -ENOMEM;
58929+ if (!IS_ERR_VALUE(start) && !find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
58930+// if (current->personality & ADDR_NO_RANDOMIZE)
58931+// vm_flags |= VM_READ | VM_MAYREAD;
58932+ start = mmap_region(NULL, start, PAGE_ALIGN(size), vm_flags, 0);
58933+ retval = IS_ERR_VALUE(start) ? start : 0;
58934+ }
58935+ up_write(&current->mm->mmap_sem);
58936+ if (retval == 0)
58937+ retval = set_brk(start + size, start + size + PAGE_SIZE);
58938+ if (retval < 0)
58939+ goto out_free_dentry;
58940+ }
58941+#endif
58942+
58943 if (elf_interpreter) {
58944- unsigned long interp_map_addr = 0;
58945-
58946 elf_entry = load_elf_interp(&loc->interp_elf_ex,
58947 interpreter,
58948- &interp_map_addr,
58949 load_bias);
58950 if (!IS_ERR((void *)elf_entry)) {
58951 /*
58952@@ -1115,7 +1594,7 @@ static bool always_dump_vma(struct vm_area_struct *vma)
58953 * Decide what to dump of a segment, part, all or none.
58954 */
58955 static unsigned long vma_dump_size(struct vm_area_struct *vma,
58956- unsigned long mm_flags)
58957+ unsigned long mm_flags, long signr)
58958 {
58959 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
58960
58961@@ -1153,7 +1632,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
58962 if (vma->vm_file == NULL)
58963 return 0;
58964
58965- if (FILTER(MAPPED_PRIVATE))
58966+ if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
58967 goto whole;
58968
58969 /*
58970@@ -1360,9 +1839,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
58971 {
58972 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
58973 int i = 0;
58974- do
58975+ do {
58976 i += 2;
58977- while (auxv[i - 2] != AT_NULL);
58978+ } while (auxv[i - 2] != AT_NULL);
58979 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
58980 }
58981
58982@@ -1371,7 +1850,7 @@ static void fill_siginfo_note(struct memelfnote *note, user_siginfo_t *csigdata,
58983 {
58984 mm_segment_t old_fs = get_fs();
58985 set_fs(KERNEL_DS);
58986- copy_siginfo_to_user((user_siginfo_t __user *) csigdata, siginfo);
58987+ copy_siginfo_to_user((user_siginfo_t __force_user *) csigdata, siginfo);
58988 set_fs(old_fs);
58989 fill_note(note, "CORE", NT_SIGINFO, sizeof(*csigdata), csigdata);
58990 }
58991@@ -1995,14 +2474,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
58992 }
58993
58994 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
58995- unsigned long mm_flags)
58996+ struct coredump_params *cprm)
58997 {
58998 struct vm_area_struct *vma;
58999 size_t size = 0;
59000
59001 for (vma = first_vma(current, gate_vma); vma != NULL;
59002 vma = next_vma(vma, gate_vma))
59003- size += vma_dump_size(vma, mm_flags);
59004+ size += vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
59005 return size;
59006 }
59007
59008@@ -2093,7 +2572,7 @@ static int elf_core_dump(struct coredump_params *cprm)
59009
59010 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
59011
59012- offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
59013+ offset += elf_core_vma_data_size(gate_vma, cprm);
59014 offset += elf_core_extra_data_size();
59015 e_shoff = offset;
59016
59017@@ -2121,7 +2600,7 @@ static int elf_core_dump(struct coredump_params *cprm)
59018 phdr.p_offset = offset;
59019 phdr.p_vaddr = vma->vm_start;
59020 phdr.p_paddr = 0;
59021- phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
59022+ phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
59023 phdr.p_memsz = vma->vm_end - vma->vm_start;
59024 offset += phdr.p_filesz;
59025 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
59026@@ -2154,7 +2633,7 @@ static int elf_core_dump(struct coredump_params *cprm)
59027 unsigned long addr;
59028 unsigned long end;
59029
59030- end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
59031+ end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
59032
59033 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
59034 struct page *page;
59035@@ -2195,6 +2674,167 @@ out:
59036
59037 #endif /* CONFIG_ELF_CORE */
59038
59039+#ifdef CONFIG_PAX_MPROTECT
59040+/* PaX: non-PIC ELF libraries need relocations on their executable segments
59041+ * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
59042+ * we'll remove VM_MAYWRITE for good on RELRO segments.
59043+ *
59044+ * The checks favour ld-linux.so behaviour which operates on a per ELF segment
59045+ * basis because we want to allow the common case and not the special ones.
59046+ */
59047+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
59048+{
59049+ struct elfhdr elf_h;
59050+ struct elf_phdr elf_p;
59051+ unsigned long i;
59052+ unsigned long oldflags;
59053+ bool is_textrel_rw, is_textrel_rx, is_relro;
59054+
59055+ if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT) || !vma->vm_file)
59056+ return;
59057+
59058+ oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
59059+ newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
59060+
59061+#ifdef CONFIG_PAX_ELFRELOCS
59062+ /* possible TEXTREL */
59063+ is_textrel_rw = !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
59064+ is_textrel_rx = vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_WRITE | VM_READ) && newflags == (VM_EXEC | VM_READ);
59065+#else
59066+ is_textrel_rw = false;
59067+ is_textrel_rx = false;
59068+#endif
59069+
59070+ /* possible RELRO */
59071+ is_relro = vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
59072+
59073+ if (!is_textrel_rw && !is_textrel_rx && !is_relro)
59074+ return;
59075+
59076+ if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
59077+ memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
59078+
59079+#ifdef CONFIG_PAX_ETEXECRELOCS
59080+ ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
59081+#else
59082+ ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
59083+#endif
59084+
59085+ (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
59086+ !elf_check_arch(&elf_h) ||
59087+ elf_h.e_phentsize != sizeof(struct elf_phdr) ||
59088+ elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
59089+ return;
59090+
59091+ for (i = 0UL; i < elf_h.e_phnum; i++) {
59092+ if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
59093+ return;
59094+ switch (elf_p.p_type) {
59095+ case PT_DYNAMIC:
59096+ if (!is_textrel_rw && !is_textrel_rx)
59097+ continue;
59098+ i = 0UL;
59099+ while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
59100+ elf_dyn dyn;
59101+
59102+ if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
59103+ break;
59104+ if (dyn.d_tag == DT_NULL)
59105+ break;
59106+ if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
59107+ gr_log_textrel(vma);
59108+ if (is_textrel_rw)
59109+ vma->vm_flags |= VM_MAYWRITE;
59110+ else
59111+ /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
59112+ vma->vm_flags &= ~VM_MAYWRITE;
59113+ break;
59114+ }
59115+ i++;
59116+ }
59117+ is_textrel_rw = false;
59118+ is_textrel_rx = false;
59119+ continue;
59120+
59121+ case PT_GNU_RELRO:
59122+ if (!is_relro)
59123+ continue;
59124+ if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
59125+ vma->vm_flags &= ~VM_MAYWRITE;
59126+ is_relro = false;
59127+ continue;
59128+
59129+#ifdef CONFIG_PAX_PT_PAX_FLAGS
59130+ case PT_PAX_FLAGS: {
59131+ const char *msg_mprotect = "", *msg_emutramp = "";
59132+ char *buffer_lib, *buffer_exe;
59133+
59134+ if (elf_p.p_flags & PF_NOMPROTECT)
59135+ msg_mprotect = "MPROTECT disabled";
59136+
59137+#ifdef CONFIG_PAX_EMUTRAMP
59138+ if (!(vma->vm_mm->pax_flags & MF_PAX_EMUTRAMP) && !(elf_p.p_flags & PF_NOEMUTRAMP))
59139+ msg_emutramp = "EMUTRAMP enabled";
59140+#endif
59141+
59142+ if (!msg_mprotect[0] && !msg_emutramp[0])
59143+ continue;
59144+
59145+ if (!printk_ratelimit())
59146+ continue;
59147+
59148+ buffer_lib = (char *)__get_free_page(GFP_KERNEL);
59149+ buffer_exe = (char *)__get_free_page(GFP_KERNEL);
59150+ if (buffer_lib && buffer_exe) {
59151+ char *path_lib, *path_exe;
59152+
59153+ path_lib = pax_get_path(&vma->vm_file->f_path, buffer_lib, PAGE_SIZE);
59154+ path_exe = pax_get_path(&vma->vm_mm->exe_file->f_path, buffer_exe, PAGE_SIZE);
59155+
59156+ pr_info("PAX: %s wants %s%s%s on %s\n", path_lib, msg_mprotect,
59157+ (msg_mprotect[0] && msg_emutramp[0] ? " and " : ""), msg_emutramp, path_exe);
59158+
59159+ }
59160+ free_page((unsigned long)buffer_exe);
59161+ free_page((unsigned long)buffer_lib);
59162+ continue;
59163+ }
59164+#endif
59165+
59166+ }
59167+ }
59168+}
59169+#endif
59170+
59171+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
59172+
59173+extern int grsec_enable_log_rwxmaps;
59174+
59175+static void elf_handle_mmap(struct file *file)
59176+{
59177+ struct elfhdr elf_h;
59178+ struct elf_phdr elf_p;
59179+ unsigned long i;
59180+
59181+ if (!grsec_enable_log_rwxmaps)
59182+ return;
59183+
59184+ if (sizeof(elf_h) != kernel_read(file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
59185+ memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
59186+ (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC) || !elf_check_arch(&elf_h) ||
59187+ elf_h.e_phentsize != sizeof(struct elf_phdr) ||
59188+ elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
59189+ return;
59190+
59191+ for (i = 0UL; i < elf_h.e_phnum; i++) {
59192+ if (sizeof(elf_p) != kernel_read(file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
59193+ return;
59194+ if (elf_p.p_type == PT_GNU_STACK && (elf_p.p_flags & PF_X))
59195+ gr_log_ptgnustack(file);
59196+ }
59197+}
59198+#endif
59199+
59200 static int __init init_elf_binfmt(void)
59201 {
59202 register_binfmt(&elf_format);
59203diff --git a/fs/block_dev.c b/fs/block_dev.c
59204index 1d9c9f3..2905786 100644
59205--- a/fs/block_dev.c
59206+++ b/fs/block_dev.c
59207@@ -697,7 +697,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
59208 else if (bdev->bd_contains == bdev)
59209 return true; /* is a whole device which isn't held */
59210
59211- else if (whole->bd_holder == bd_may_claim)
59212+ else if (whole->bd_holder == (void *)bd_may_claim)
59213 return true; /* is a partition of a device that is being partitioned */
59214 else if (whole->bd_holder != NULL)
59215 return false; /* is a partition of a held device */
59216diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
59217index 150822e..75bb326 100644
59218--- a/fs/btrfs/ctree.c
59219+++ b/fs/btrfs/ctree.c
59220@@ -1173,9 +1173,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
59221 free_extent_buffer(buf);
59222 add_root_to_dirty_list(root);
59223 } else {
59224- if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
59225- parent_start = parent->start;
59226- else
59227+ if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
59228+ if (parent)
59229+ parent_start = parent->start;
59230+ else
59231+ parent_start = 0;
59232+ } else
59233 parent_start = 0;
59234
59235 WARN_ON(trans->transid != btrfs_header_generation(parent));
59236diff --git a/fs/btrfs/delayed-inode.c b/fs/btrfs/delayed-inode.c
59237index 054577b..9b342cc 100644
59238--- a/fs/btrfs/delayed-inode.c
59239+++ b/fs/btrfs/delayed-inode.c
59240@@ -462,7 +462,7 @@ static int __btrfs_add_delayed_deletion_item(struct btrfs_delayed_node *node,
59241
59242 static void finish_one_item(struct btrfs_delayed_root *delayed_root)
59243 {
59244- int seq = atomic_inc_return(&delayed_root->items_seq);
59245+ int seq = atomic_inc_return_unchecked(&delayed_root->items_seq);
59246 if ((atomic_dec_return(&delayed_root->items) <
59247 BTRFS_DELAYED_BACKGROUND || seq % BTRFS_DELAYED_BATCH == 0) &&
59248 waitqueue_active(&delayed_root->wait))
59249@@ -1412,7 +1412,7 @@ void btrfs_assert_delayed_root_empty(struct btrfs_root *root)
59250
59251 static int could_end_wait(struct btrfs_delayed_root *delayed_root, int seq)
59252 {
59253- int val = atomic_read(&delayed_root->items_seq);
59254+ int val = atomic_read_unchecked(&delayed_root->items_seq);
59255
59256 if (val < seq || val >= seq + BTRFS_DELAYED_BATCH)
59257 return 1;
59258@@ -1436,7 +1436,7 @@ void btrfs_balance_delayed_items(struct btrfs_root *root)
59259 int seq;
59260 int ret;
59261
59262- seq = atomic_read(&delayed_root->items_seq);
59263+ seq = atomic_read_unchecked(&delayed_root->items_seq);
59264
59265 ret = btrfs_wq_run_delayed_node(delayed_root, root, 0);
59266 if (ret)
59267diff --git a/fs/btrfs/delayed-inode.h b/fs/btrfs/delayed-inode.h
59268index f70119f..ab5894d 100644
59269--- a/fs/btrfs/delayed-inode.h
59270+++ b/fs/btrfs/delayed-inode.h
59271@@ -43,7 +43,7 @@ struct btrfs_delayed_root {
59272 */
59273 struct list_head prepare_list;
59274 atomic_t items; /* for delayed items */
59275- atomic_t items_seq; /* for delayed items */
59276+ atomic_unchecked_t items_seq; /* for delayed items */
59277 int nodes; /* for delayed nodes */
59278 wait_queue_head_t wait;
59279 };
59280@@ -90,7 +90,7 @@ static inline void btrfs_init_delayed_root(
59281 struct btrfs_delayed_root *delayed_root)
59282 {
59283 atomic_set(&delayed_root->items, 0);
59284- atomic_set(&delayed_root->items_seq, 0);
59285+ atomic_set_unchecked(&delayed_root->items_seq, 0);
59286 delayed_root->nodes = 0;
59287 spin_lock_init(&delayed_root->lock);
59288 init_waitqueue_head(&delayed_root->wait);
59289diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
59290index 4399f0c..a34d8b4 100644
59291--- a/fs/btrfs/ioctl.c
59292+++ b/fs/btrfs/ioctl.c
59293@@ -3953,9 +3953,12 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
59294 for (i = 0; i < num_types; i++) {
59295 struct btrfs_space_info *tmp;
59296
59297+ /* Don't copy in more than we allocated */
59298 if (!slot_count)
59299 break;
59300
59301+ slot_count--;
59302+
59303 info = NULL;
59304 rcu_read_lock();
59305 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
59306@@ -3977,10 +3980,7 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
59307 memcpy(dest, &space, sizeof(space));
59308 dest++;
59309 space_args.total_spaces++;
59310- slot_count--;
59311 }
59312- if (!slot_count)
59313- break;
59314 }
59315 up_read(&info->groups_sem);
59316 }
59317diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
59318index 54bd91e..aefa810 100644
59319--- a/fs/btrfs/super.c
59320+++ b/fs/btrfs/super.c
59321@@ -271,7 +271,7 @@ void __btrfs_abort_transaction(struct btrfs_trans_handle *trans,
59322 function, line, errstr);
59323 return;
59324 }
59325- ACCESS_ONCE(trans->transaction->aborted) = errno;
59326+ ACCESS_ONCE_RW(trans->transaction->aborted) = errno;
59327 /* Wake up anybody who may be waiting on this transaction */
59328 wake_up(&root->fs_info->transaction_wait);
59329 wake_up(&root->fs_info->transaction_blocked_wait);
59330diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
59331index b2e7bb4..3719201 100644
59332--- a/fs/btrfs/sysfs.c
59333+++ b/fs/btrfs/sysfs.c
59334@@ -480,7 +480,7 @@ static int addrm_unknown_feature_attrs(struct btrfs_fs_info *fs_info, bool add)
59335 for (set = 0; set < FEAT_MAX; set++) {
59336 int i;
59337 struct attribute *attrs[2];
59338- struct attribute_group agroup = {
59339+ attribute_group_no_const agroup = {
59340 .name = "features",
59341 .attrs = attrs,
59342 };
59343diff --git a/fs/btrfs/tests/free-space-tests.c b/fs/btrfs/tests/free-space-tests.c
59344index 2299bfd..4098e72 100644
59345--- a/fs/btrfs/tests/free-space-tests.c
59346+++ b/fs/btrfs/tests/free-space-tests.c
59347@@ -463,7 +463,9 @@ test_steal_space_from_bitmap_to_extent(struct btrfs_block_group_cache *cache)
59348 * extent entry.
59349 */
59350 use_bitmap_op = cache->free_space_ctl->op->use_bitmap;
59351- cache->free_space_ctl->op->use_bitmap = test_use_bitmap;
59352+ pax_open_kernel();
59353+ *(void **)&cache->free_space_ctl->op->use_bitmap = test_use_bitmap;
59354+ pax_close_kernel();
59355
59356 /*
59357 * Extent entry covering free space range [128Mb - 256Kb, 128Mb - 128Kb[
59358@@ -870,7 +872,9 @@ test_steal_space_from_bitmap_to_extent(struct btrfs_block_group_cache *cache)
59359 if (ret)
59360 return ret;
59361
59362- cache->free_space_ctl->op->use_bitmap = use_bitmap_op;
59363+ pax_open_kernel();
59364+ *(void **)&cache->free_space_ctl->op->use_bitmap = use_bitmap_op;
59365+ pax_close_kernel();
59366 __btrfs_remove_free_space_cache(cache->free_space_ctl);
59367
59368 return 0;
59369diff --git a/fs/btrfs/tree-log.h b/fs/btrfs/tree-log.h
59370index 154990c..d0cf699 100644
59371--- a/fs/btrfs/tree-log.h
59372+++ b/fs/btrfs/tree-log.h
59373@@ -43,7 +43,7 @@ static inline void btrfs_init_log_ctx(struct btrfs_log_ctx *ctx)
59374 static inline void btrfs_set_log_full_commit(struct btrfs_fs_info *fs_info,
59375 struct btrfs_trans_handle *trans)
59376 {
59377- ACCESS_ONCE(fs_info->last_trans_log_full_commit) = trans->transid;
59378+ ACCESS_ONCE_RW(fs_info->last_trans_log_full_commit) = trans->transid;
59379 }
59380
59381 static inline int btrfs_need_log_full_commit(struct btrfs_fs_info *fs_info,
59382diff --git a/fs/buffer.c b/fs/buffer.c
59383index 20805db..2e8fc69 100644
59384--- a/fs/buffer.c
59385+++ b/fs/buffer.c
59386@@ -3417,7 +3417,7 @@ void __init buffer_init(void)
59387 bh_cachep = kmem_cache_create("buffer_head",
59388 sizeof(struct buffer_head), 0,
59389 (SLAB_RECLAIM_ACCOUNT|SLAB_PANIC|
59390- SLAB_MEM_SPREAD),
59391+ SLAB_MEM_SPREAD|SLAB_NO_SANITIZE),
59392 NULL);
59393
59394 /*
59395diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
59396index fbb08e9..0fda764 100644
59397--- a/fs/cachefiles/bind.c
59398+++ b/fs/cachefiles/bind.c
59399@@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
59400 args);
59401
59402 /* start by checking things over */
59403- ASSERT(cache->fstop_percent >= 0 &&
59404- cache->fstop_percent < cache->fcull_percent &&
59405+ ASSERT(cache->fstop_percent < cache->fcull_percent &&
59406 cache->fcull_percent < cache->frun_percent &&
59407 cache->frun_percent < 100);
59408
59409- ASSERT(cache->bstop_percent >= 0 &&
59410- cache->bstop_percent < cache->bcull_percent &&
59411+ ASSERT(cache->bstop_percent < cache->bcull_percent &&
59412 cache->bcull_percent < cache->brun_percent &&
59413 cache->brun_percent < 100);
59414
59415diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
59416index ce1b115..4a6852c 100644
59417--- a/fs/cachefiles/daemon.c
59418+++ b/fs/cachefiles/daemon.c
59419@@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
59420 if (n > buflen)
59421 return -EMSGSIZE;
59422
59423- if (copy_to_user(_buffer, buffer, n) != 0)
59424+ if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
59425 return -EFAULT;
59426
59427 return n;
59428@@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
59429 if (test_bit(CACHEFILES_DEAD, &cache->flags))
59430 return -EIO;
59431
59432- if (datalen < 0 || datalen > PAGE_SIZE - 1)
59433+ if (datalen > PAGE_SIZE - 1)
59434 return -EOPNOTSUPP;
59435
59436 /* drag the command string into the kernel so we can parse it */
59437@@ -385,7 +385,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
59438 if (args[0] != '%' || args[1] != '\0')
59439 return -EINVAL;
59440
59441- if (fstop < 0 || fstop >= cache->fcull_percent)
59442+ if (fstop >= cache->fcull_percent)
59443 return cachefiles_daemon_range_error(cache, args);
59444
59445 cache->fstop_percent = fstop;
59446@@ -457,7 +457,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
59447 if (args[0] != '%' || args[1] != '\0')
59448 return -EINVAL;
59449
59450- if (bstop < 0 || bstop >= cache->bcull_percent)
59451+ if (bstop >= cache->bcull_percent)
59452 return cachefiles_daemon_range_error(cache, args);
59453
59454 cache->bstop_percent = bstop;
59455diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
59456index 8c52472..c4e3a69 100644
59457--- a/fs/cachefiles/internal.h
59458+++ b/fs/cachefiles/internal.h
59459@@ -66,7 +66,7 @@ struct cachefiles_cache {
59460 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
59461 struct rb_root active_nodes; /* active nodes (can't be culled) */
59462 rwlock_t active_lock; /* lock for active_nodes */
59463- atomic_t gravecounter; /* graveyard uniquifier */
59464+ atomic_unchecked_t gravecounter; /* graveyard uniquifier */
59465 unsigned frun_percent; /* when to stop culling (% files) */
59466 unsigned fcull_percent; /* when to start culling (% files) */
59467 unsigned fstop_percent; /* when to stop allocating (% files) */
59468@@ -178,19 +178,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
59469 * proc.c
59470 */
59471 #ifdef CONFIG_CACHEFILES_HISTOGRAM
59472-extern atomic_t cachefiles_lookup_histogram[HZ];
59473-extern atomic_t cachefiles_mkdir_histogram[HZ];
59474-extern atomic_t cachefiles_create_histogram[HZ];
59475+extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
59476+extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
59477+extern atomic_unchecked_t cachefiles_create_histogram[HZ];
59478
59479 extern int __init cachefiles_proc_init(void);
59480 extern void cachefiles_proc_cleanup(void);
59481 static inline
59482-void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
59483+void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
59484 {
59485 unsigned long jif = jiffies - start_jif;
59486 if (jif >= HZ)
59487 jif = HZ - 1;
59488- atomic_inc(&histogram[jif]);
59489+ atomic_inc_unchecked(&histogram[jif]);
59490 }
59491
59492 #else
59493diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
59494index e12f189..ed17244 100644
59495--- a/fs/cachefiles/namei.c
59496+++ b/fs/cachefiles/namei.c
59497@@ -312,7 +312,7 @@ try_again:
59498 /* first step is to make up a grave dentry in the graveyard */
59499 sprintf(nbuffer, "%08x%08x",
59500 (uint32_t) get_seconds(),
59501- (uint32_t) atomic_inc_return(&cache->gravecounter));
59502+ (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
59503
59504 /* do the multiway lock magic */
59505 trap = lock_rename(cache->graveyard, dir);
59506diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
59507index eccd339..4c1d995 100644
59508--- a/fs/cachefiles/proc.c
59509+++ b/fs/cachefiles/proc.c
59510@@ -14,9 +14,9 @@
59511 #include <linux/seq_file.h>
59512 #include "internal.h"
59513
59514-atomic_t cachefiles_lookup_histogram[HZ];
59515-atomic_t cachefiles_mkdir_histogram[HZ];
59516-atomic_t cachefiles_create_histogram[HZ];
59517+atomic_unchecked_t cachefiles_lookup_histogram[HZ];
59518+atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
59519+atomic_unchecked_t cachefiles_create_histogram[HZ];
59520
59521 /*
59522 * display the latency histogram
59523@@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
59524 return 0;
59525 default:
59526 index = (unsigned long) v - 3;
59527- x = atomic_read(&cachefiles_lookup_histogram[index]);
59528- y = atomic_read(&cachefiles_mkdir_histogram[index]);
59529- z = atomic_read(&cachefiles_create_histogram[index]);
59530+ x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
59531+ y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
59532+ z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
59533 if (x == 0 && y == 0 && z == 0)
59534 return 0;
59535
59536diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
59537index 695e788..f4a9d4d 100644
59538--- a/fs/ceph/dir.c
59539+++ b/fs/ceph/dir.c
59540@@ -129,6 +129,8 @@ static int __dcache_readdir(struct file *file, struct dir_context *ctx,
59541 struct dentry *dentry, *last;
59542 struct ceph_dentry_info *di;
59543 int err = 0;
59544+ char d_name[DNAME_INLINE_LEN];
59545+ const unsigned char *name;
59546
59547 /* claim ref on last dentry we returned */
59548 last = fi->dentry;
59549@@ -192,7 +194,12 @@ more:
59550
59551 dout(" %llu (%llu) dentry %p %.*s %p\n", di->offset, ctx->pos,
59552 dentry, dentry->d_name.len, dentry->d_name.name, dentry->d_inode);
59553- if (!dir_emit(ctx, dentry->d_name.name,
59554+ name = dentry->d_name.name;
59555+ if (name == dentry->d_iname) {
59556+ memcpy(d_name, name, dentry->d_name.len);
59557+ name = d_name;
59558+ }
59559+ if (!dir_emit(ctx, name,
59560 dentry->d_name.len,
59561 ceph_translate_ino(dentry->d_sb, dentry->d_inode->i_ino),
59562 dentry->d_inode->i_mode >> 12)) {
59563@@ -250,7 +257,7 @@ static int ceph_readdir(struct file *file, struct dir_context *ctx)
59564 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
59565 struct ceph_mds_client *mdsc = fsc->mdsc;
59566 unsigned frag = fpos_frag(ctx->pos);
59567- int off = fpos_off(ctx->pos);
59568+ unsigned int off = fpos_off(ctx->pos);
59569 int err;
59570 u32 ftype;
59571 struct ceph_mds_reply_info_parsed *rinfo;
59572diff --git a/fs/ceph/super.c b/fs/ceph/super.c
59573index f6e1237..796ffd1 100644
59574--- a/fs/ceph/super.c
59575+++ b/fs/ceph/super.c
59576@@ -895,7 +895,7 @@ static int ceph_compare_super(struct super_block *sb, void *data)
59577 /*
59578 * construct our own bdi so we can control readahead, etc.
59579 */
59580-static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
59581+static atomic_long_unchecked_t bdi_seq = ATOMIC_LONG_INIT(0);
59582
59583 static int ceph_register_bdi(struct super_block *sb,
59584 struct ceph_fs_client *fsc)
59585@@ -912,7 +912,7 @@ static int ceph_register_bdi(struct super_block *sb,
59586 default_backing_dev_info.ra_pages;
59587
59588 err = bdi_register(&fsc->backing_dev_info, NULL, "ceph-%ld",
59589- atomic_long_inc_return(&bdi_seq));
59590+ atomic_long_inc_return_unchecked(&bdi_seq));
59591 if (!err)
59592 sb->s_bdi = &fsc->backing_dev_info;
59593 return err;
59594diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
59595index 44ec726..bcb06a3 100644
59596--- a/fs/cifs/cifs_debug.c
59597+++ b/fs/cifs/cifs_debug.c
59598@@ -286,8 +286,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
59599
59600 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
59601 #ifdef CONFIG_CIFS_STATS2
59602- atomic_set(&totBufAllocCount, 0);
59603- atomic_set(&totSmBufAllocCount, 0);
59604+ atomic_set_unchecked(&totBufAllocCount, 0);
59605+ atomic_set_unchecked(&totSmBufAllocCount, 0);
59606 #endif /* CONFIG_CIFS_STATS2 */
59607 spin_lock(&cifs_tcp_ses_lock);
59608 list_for_each(tmp1, &cifs_tcp_ses_list) {
59609@@ -300,7 +300,7 @@ static ssize_t cifs_stats_proc_write(struct file *file,
59610 tcon = list_entry(tmp3,
59611 struct cifs_tcon,
59612 tcon_list);
59613- atomic_set(&tcon->num_smbs_sent, 0);
59614+ atomic_set_unchecked(&tcon->num_smbs_sent, 0);
59615 if (server->ops->clear_stats)
59616 server->ops->clear_stats(tcon);
59617 }
59618@@ -332,8 +332,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
59619 smBufAllocCount.counter, cifs_min_small);
59620 #ifdef CONFIG_CIFS_STATS2
59621 seq_printf(m, "Total Large %d Small %d Allocations\n",
59622- atomic_read(&totBufAllocCount),
59623- atomic_read(&totSmBufAllocCount));
59624+ atomic_read_unchecked(&totBufAllocCount),
59625+ atomic_read_unchecked(&totSmBufAllocCount));
59626 #endif /* CONFIG_CIFS_STATS2 */
59627
59628 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
59629@@ -362,7 +362,7 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
59630 if (tcon->need_reconnect)
59631 seq_puts(m, "\tDISCONNECTED ");
59632 seq_printf(m, "\nSMBs: %d",
59633- atomic_read(&tcon->num_smbs_sent));
59634+ atomic_read_unchecked(&tcon->num_smbs_sent));
59635 if (server->ops->print_stats)
59636 server->ops->print_stats(m, tcon);
59637 }
59638diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
59639index 9d7996e..35ad5cf4 100644
59640--- a/fs/cifs/cifsfs.c
59641+++ b/fs/cifs/cifsfs.c
59642@@ -1093,7 +1093,7 @@ cifs_init_request_bufs(void)
59643 */
59644 cifs_req_cachep = kmem_cache_create("cifs_request",
59645 CIFSMaxBufSize + max_hdr_size, 0,
59646- SLAB_HWCACHE_ALIGN, NULL);
59647+ SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
59648 if (cifs_req_cachep == NULL)
59649 return -ENOMEM;
59650
59651@@ -1120,7 +1120,7 @@ cifs_init_request_bufs(void)
59652 efficient to alloc 1 per page off the slab compared to 17K (5page)
59653 alloc of large cifs buffers even when page debugging is on */
59654 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
59655- MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
59656+ MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
59657 NULL);
59658 if (cifs_sm_req_cachep == NULL) {
59659 mempool_destroy(cifs_req_poolp);
59660@@ -1205,8 +1205,8 @@ init_cifs(void)
59661 atomic_set(&bufAllocCount, 0);
59662 atomic_set(&smBufAllocCount, 0);
59663 #ifdef CONFIG_CIFS_STATS2
59664- atomic_set(&totBufAllocCount, 0);
59665- atomic_set(&totSmBufAllocCount, 0);
59666+ atomic_set_unchecked(&totBufAllocCount, 0);
59667+ atomic_set_unchecked(&totSmBufAllocCount, 0);
59668 #endif /* CONFIG_CIFS_STATS2 */
59669
59670 atomic_set(&midCount, 0);
59671diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
59672index 02a33e5..3a28b5a 100644
59673--- a/fs/cifs/cifsglob.h
59674+++ b/fs/cifs/cifsglob.h
59675@@ -823,35 +823,35 @@ struct cifs_tcon {
59676 __u16 Flags; /* optional support bits */
59677 enum statusEnum tidStatus;
59678 #ifdef CONFIG_CIFS_STATS
59679- atomic_t num_smbs_sent;
59680+ atomic_unchecked_t num_smbs_sent;
59681 union {
59682 struct {
59683- atomic_t num_writes;
59684- atomic_t num_reads;
59685- atomic_t num_flushes;
59686- atomic_t num_oplock_brks;
59687- atomic_t num_opens;
59688- atomic_t num_closes;
59689- atomic_t num_deletes;
59690- atomic_t num_mkdirs;
59691- atomic_t num_posixopens;
59692- atomic_t num_posixmkdirs;
59693- atomic_t num_rmdirs;
59694- atomic_t num_renames;
59695- atomic_t num_t2renames;
59696- atomic_t num_ffirst;
59697- atomic_t num_fnext;
59698- atomic_t num_fclose;
59699- atomic_t num_hardlinks;
59700- atomic_t num_symlinks;
59701- atomic_t num_locks;
59702- atomic_t num_acl_get;
59703- atomic_t num_acl_set;
59704+ atomic_unchecked_t num_writes;
59705+ atomic_unchecked_t num_reads;
59706+ atomic_unchecked_t num_flushes;
59707+ atomic_unchecked_t num_oplock_brks;
59708+ atomic_unchecked_t num_opens;
59709+ atomic_unchecked_t num_closes;
59710+ atomic_unchecked_t num_deletes;
59711+ atomic_unchecked_t num_mkdirs;
59712+ atomic_unchecked_t num_posixopens;
59713+ atomic_unchecked_t num_posixmkdirs;
59714+ atomic_unchecked_t num_rmdirs;
59715+ atomic_unchecked_t num_renames;
59716+ atomic_unchecked_t num_t2renames;
59717+ atomic_unchecked_t num_ffirst;
59718+ atomic_unchecked_t num_fnext;
59719+ atomic_unchecked_t num_fclose;
59720+ atomic_unchecked_t num_hardlinks;
59721+ atomic_unchecked_t num_symlinks;
59722+ atomic_unchecked_t num_locks;
59723+ atomic_unchecked_t num_acl_get;
59724+ atomic_unchecked_t num_acl_set;
59725 } cifs_stats;
59726 #ifdef CONFIG_CIFS_SMB2
59727 struct {
59728- atomic_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
59729- atomic_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
59730+ atomic_unchecked_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
59731+ atomic_unchecked_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
59732 } smb2_stats;
59733 #endif /* CONFIG_CIFS_SMB2 */
59734 } stats;
59735@@ -1192,7 +1192,7 @@ convert_delimiter(char *path, char delim)
59736 }
59737
59738 #ifdef CONFIG_CIFS_STATS
59739-#define cifs_stats_inc atomic_inc
59740+#define cifs_stats_inc atomic_inc_unchecked
59741
59742 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
59743 unsigned int bytes)
59744@@ -1559,8 +1559,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
59745 /* Various Debug counters */
59746 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
59747 #ifdef CONFIG_CIFS_STATS2
59748-GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
59749-GLOBAL_EXTERN atomic_t totSmBufAllocCount;
59750+GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
59751+GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
59752 #endif
59753 GLOBAL_EXTERN atomic_t smBufAllocCount;
59754 GLOBAL_EXTERN atomic_t midCount;
59755diff --git a/fs/cifs/file.c b/fs/cifs/file.c
59756index 3e4d00a..38a122d 100644
59757--- a/fs/cifs/file.c
59758+++ b/fs/cifs/file.c
59759@@ -2056,10 +2056,14 @@ static int cifs_writepages(struct address_space *mapping,
59760 index = mapping->writeback_index; /* Start from prev offset */
59761 end = -1;
59762 } else {
59763- index = wbc->range_start >> PAGE_CACHE_SHIFT;
59764- end = wbc->range_end >> PAGE_CACHE_SHIFT;
59765- if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX)
59766+ if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX) {
59767 range_whole = true;
59768+ index = 0;
59769+ end = ULONG_MAX;
59770+ } else {
59771+ index = wbc->range_start >> PAGE_CACHE_SHIFT;
59772+ end = wbc->range_end >> PAGE_CACHE_SHIFT;
59773+ }
59774 scanned = true;
59775 }
59776 server = cifs_sb_master_tcon(cifs_sb)->ses->server;
59777diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
59778index b7415d5..3984ec0 100644
59779--- a/fs/cifs/misc.c
59780+++ b/fs/cifs/misc.c
59781@@ -170,7 +170,7 @@ cifs_buf_get(void)
59782 memset(ret_buf, 0, buf_size + 3);
59783 atomic_inc(&bufAllocCount);
59784 #ifdef CONFIG_CIFS_STATS2
59785- atomic_inc(&totBufAllocCount);
59786+ atomic_inc_unchecked(&totBufAllocCount);
59787 #endif /* CONFIG_CIFS_STATS2 */
59788 }
59789
59790@@ -205,7 +205,7 @@ cifs_small_buf_get(void)
59791 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
59792 atomic_inc(&smBufAllocCount);
59793 #ifdef CONFIG_CIFS_STATS2
59794- atomic_inc(&totSmBufAllocCount);
59795+ atomic_inc_unchecked(&totSmBufAllocCount);
59796 #endif /* CONFIG_CIFS_STATS2 */
59797
59798 }
59799diff --git a/fs/cifs/smb1ops.c b/fs/cifs/smb1ops.c
59800index d297903..1cb7516 100644
59801--- a/fs/cifs/smb1ops.c
59802+++ b/fs/cifs/smb1ops.c
59803@@ -622,27 +622,27 @@ static void
59804 cifs_clear_stats(struct cifs_tcon *tcon)
59805 {
59806 #ifdef CONFIG_CIFS_STATS
59807- atomic_set(&tcon->stats.cifs_stats.num_writes, 0);
59808- atomic_set(&tcon->stats.cifs_stats.num_reads, 0);
59809- atomic_set(&tcon->stats.cifs_stats.num_flushes, 0);
59810- atomic_set(&tcon->stats.cifs_stats.num_oplock_brks, 0);
59811- atomic_set(&tcon->stats.cifs_stats.num_opens, 0);
59812- atomic_set(&tcon->stats.cifs_stats.num_posixopens, 0);
59813- atomic_set(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
59814- atomic_set(&tcon->stats.cifs_stats.num_closes, 0);
59815- atomic_set(&tcon->stats.cifs_stats.num_deletes, 0);
59816- atomic_set(&tcon->stats.cifs_stats.num_mkdirs, 0);
59817- atomic_set(&tcon->stats.cifs_stats.num_rmdirs, 0);
59818- atomic_set(&tcon->stats.cifs_stats.num_renames, 0);
59819- atomic_set(&tcon->stats.cifs_stats.num_t2renames, 0);
59820- atomic_set(&tcon->stats.cifs_stats.num_ffirst, 0);
59821- atomic_set(&tcon->stats.cifs_stats.num_fnext, 0);
59822- atomic_set(&tcon->stats.cifs_stats.num_fclose, 0);
59823- atomic_set(&tcon->stats.cifs_stats.num_hardlinks, 0);
59824- atomic_set(&tcon->stats.cifs_stats.num_symlinks, 0);
59825- atomic_set(&tcon->stats.cifs_stats.num_locks, 0);
59826- atomic_set(&tcon->stats.cifs_stats.num_acl_get, 0);
59827- atomic_set(&tcon->stats.cifs_stats.num_acl_set, 0);
59828+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_writes, 0);
59829+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_reads, 0);
59830+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_flushes, 0);
59831+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_oplock_brks, 0);
59832+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_opens, 0);
59833+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixopens, 0);
59834+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
59835+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_closes, 0);
59836+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_deletes, 0);
59837+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_mkdirs, 0);
59838+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_rmdirs, 0);
59839+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_renames, 0);
59840+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_t2renames, 0);
59841+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_ffirst, 0);
59842+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_fnext, 0);
59843+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_fclose, 0);
59844+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_hardlinks, 0);
59845+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_symlinks, 0);
59846+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_locks, 0);
59847+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_get, 0);
59848+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_set, 0);
59849 #endif
59850 }
59851
59852@@ -651,36 +651,36 @@ cifs_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
59853 {
59854 #ifdef CONFIG_CIFS_STATS
59855 seq_printf(m, " Oplocks breaks: %d",
59856- atomic_read(&tcon->stats.cifs_stats.num_oplock_brks));
59857+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_oplock_brks));
59858 seq_printf(m, "\nReads: %d Bytes: %llu",
59859- atomic_read(&tcon->stats.cifs_stats.num_reads),
59860+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_reads),
59861 (long long)(tcon->bytes_read));
59862 seq_printf(m, "\nWrites: %d Bytes: %llu",
59863- atomic_read(&tcon->stats.cifs_stats.num_writes),
59864+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_writes),
59865 (long long)(tcon->bytes_written));
59866 seq_printf(m, "\nFlushes: %d",
59867- atomic_read(&tcon->stats.cifs_stats.num_flushes));
59868+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_flushes));
59869 seq_printf(m, "\nLocks: %d HardLinks: %d Symlinks: %d",
59870- atomic_read(&tcon->stats.cifs_stats.num_locks),
59871- atomic_read(&tcon->stats.cifs_stats.num_hardlinks),
59872- atomic_read(&tcon->stats.cifs_stats.num_symlinks));
59873+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_locks),
59874+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_hardlinks),
59875+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_symlinks));
59876 seq_printf(m, "\nOpens: %d Closes: %d Deletes: %d",
59877- atomic_read(&tcon->stats.cifs_stats.num_opens),
59878- atomic_read(&tcon->stats.cifs_stats.num_closes),
59879- atomic_read(&tcon->stats.cifs_stats.num_deletes));
59880+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_opens),
59881+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_closes),
59882+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_deletes));
59883 seq_printf(m, "\nPosix Opens: %d Posix Mkdirs: %d",
59884- atomic_read(&tcon->stats.cifs_stats.num_posixopens),
59885- atomic_read(&tcon->stats.cifs_stats.num_posixmkdirs));
59886+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixopens),
59887+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs));
59888 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
59889- atomic_read(&tcon->stats.cifs_stats.num_mkdirs),
59890- atomic_read(&tcon->stats.cifs_stats.num_rmdirs));
59891+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_mkdirs),
59892+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_rmdirs));
59893 seq_printf(m, "\nRenames: %d T2 Renames %d",
59894- atomic_read(&tcon->stats.cifs_stats.num_renames),
59895- atomic_read(&tcon->stats.cifs_stats.num_t2renames));
59896+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_renames),
59897+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_t2renames));
59898 seq_printf(m, "\nFindFirst: %d FNext %d FClose %d",
59899- atomic_read(&tcon->stats.cifs_stats.num_ffirst),
59900- atomic_read(&tcon->stats.cifs_stats.num_fnext),
59901- atomic_read(&tcon->stats.cifs_stats.num_fclose));
59902+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_ffirst),
59903+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_fnext),
59904+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_fclose));
59905 #endif
59906 }
59907
59908diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
59909index c5f521b..1a40865 100644
59910--- a/fs/cifs/smb2ops.c
59911+++ b/fs/cifs/smb2ops.c
59912@@ -417,8 +417,8 @@ smb2_clear_stats(struct cifs_tcon *tcon)
59913 #ifdef CONFIG_CIFS_STATS
59914 int i;
59915 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
59916- atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
59917- atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
59918+ atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
59919+ atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
59920 }
59921 #endif
59922 }
59923@@ -458,65 +458,65 @@ static void
59924 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
59925 {
59926 #ifdef CONFIG_CIFS_STATS
59927- atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
59928- atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
59929+ atomic_unchecked_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
59930+ atomic_unchecked_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
59931 seq_printf(m, "\nNegotiates: %d sent %d failed",
59932- atomic_read(&sent[SMB2_NEGOTIATE_HE]),
59933- atomic_read(&failed[SMB2_NEGOTIATE_HE]));
59934+ atomic_read_unchecked(&sent[SMB2_NEGOTIATE_HE]),
59935+ atomic_read_unchecked(&failed[SMB2_NEGOTIATE_HE]));
59936 seq_printf(m, "\nSessionSetups: %d sent %d failed",
59937- atomic_read(&sent[SMB2_SESSION_SETUP_HE]),
59938- atomic_read(&failed[SMB2_SESSION_SETUP_HE]));
59939+ atomic_read_unchecked(&sent[SMB2_SESSION_SETUP_HE]),
59940+ atomic_read_unchecked(&failed[SMB2_SESSION_SETUP_HE]));
59941 seq_printf(m, "\nLogoffs: %d sent %d failed",
59942- atomic_read(&sent[SMB2_LOGOFF_HE]),
59943- atomic_read(&failed[SMB2_LOGOFF_HE]));
59944+ atomic_read_unchecked(&sent[SMB2_LOGOFF_HE]),
59945+ atomic_read_unchecked(&failed[SMB2_LOGOFF_HE]));
59946 seq_printf(m, "\nTreeConnects: %d sent %d failed",
59947- atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
59948- atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
59949+ atomic_read_unchecked(&sent[SMB2_TREE_CONNECT_HE]),
59950+ atomic_read_unchecked(&failed[SMB2_TREE_CONNECT_HE]));
59951 seq_printf(m, "\nTreeDisconnects: %d sent %d failed",
59952- atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
59953- atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
59954+ atomic_read_unchecked(&sent[SMB2_TREE_DISCONNECT_HE]),
59955+ atomic_read_unchecked(&failed[SMB2_TREE_DISCONNECT_HE]));
59956 seq_printf(m, "\nCreates: %d sent %d failed",
59957- atomic_read(&sent[SMB2_CREATE_HE]),
59958- atomic_read(&failed[SMB2_CREATE_HE]));
59959+ atomic_read_unchecked(&sent[SMB2_CREATE_HE]),
59960+ atomic_read_unchecked(&failed[SMB2_CREATE_HE]));
59961 seq_printf(m, "\nCloses: %d sent %d failed",
59962- atomic_read(&sent[SMB2_CLOSE_HE]),
59963- atomic_read(&failed[SMB2_CLOSE_HE]));
59964+ atomic_read_unchecked(&sent[SMB2_CLOSE_HE]),
59965+ atomic_read_unchecked(&failed[SMB2_CLOSE_HE]));
59966 seq_printf(m, "\nFlushes: %d sent %d failed",
59967- atomic_read(&sent[SMB2_FLUSH_HE]),
59968- atomic_read(&failed[SMB2_FLUSH_HE]));
59969+ atomic_read_unchecked(&sent[SMB2_FLUSH_HE]),
59970+ atomic_read_unchecked(&failed[SMB2_FLUSH_HE]));
59971 seq_printf(m, "\nReads: %d sent %d failed",
59972- atomic_read(&sent[SMB2_READ_HE]),
59973- atomic_read(&failed[SMB2_READ_HE]));
59974+ atomic_read_unchecked(&sent[SMB2_READ_HE]),
59975+ atomic_read_unchecked(&failed[SMB2_READ_HE]));
59976 seq_printf(m, "\nWrites: %d sent %d failed",
59977- atomic_read(&sent[SMB2_WRITE_HE]),
59978- atomic_read(&failed[SMB2_WRITE_HE]));
59979+ atomic_read_unchecked(&sent[SMB2_WRITE_HE]),
59980+ atomic_read_unchecked(&failed[SMB2_WRITE_HE]));
59981 seq_printf(m, "\nLocks: %d sent %d failed",
59982- atomic_read(&sent[SMB2_LOCK_HE]),
59983- atomic_read(&failed[SMB2_LOCK_HE]));
59984+ atomic_read_unchecked(&sent[SMB2_LOCK_HE]),
59985+ atomic_read_unchecked(&failed[SMB2_LOCK_HE]));
59986 seq_printf(m, "\nIOCTLs: %d sent %d failed",
59987- atomic_read(&sent[SMB2_IOCTL_HE]),
59988- atomic_read(&failed[SMB2_IOCTL_HE]));
59989+ atomic_read_unchecked(&sent[SMB2_IOCTL_HE]),
59990+ atomic_read_unchecked(&failed[SMB2_IOCTL_HE]));
59991 seq_printf(m, "\nCancels: %d sent %d failed",
59992- atomic_read(&sent[SMB2_CANCEL_HE]),
59993- atomic_read(&failed[SMB2_CANCEL_HE]));
59994+ atomic_read_unchecked(&sent[SMB2_CANCEL_HE]),
59995+ atomic_read_unchecked(&failed[SMB2_CANCEL_HE]));
59996 seq_printf(m, "\nEchos: %d sent %d failed",
59997- atomic_read(&sent[SMB2_ECHO_HE]),
59998- atomic_read(&failed[SMB2_ECHO_HE]));
59999+ atomic_read_unchecked(&sent[SMB2_ECHO_HE]),
60000+ atomic_read_unchecked(&failed[SMB2_ECHO_HE]));
60001 seq_printf(m, "\nQueryDirectories: %d sent %d failed",
60002- atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
60003- atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
60004+ atomic_read_unchecked(&sent[SMB2_QUERY_DIRECTORY_HE]),
60005+ atomic_read_unchecked(&failed[SMB2_QUERY_DIRECTORY_HE]));
60006 seq_printf(m, "\nChangeNotifies: %d sent %d failed",
60007- atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
60008- atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
60009+ atomic_read_unchecked(&sent[SMB2_CHANGE_NOTIFY_HE]),
60010+ atomic_read_unchecked(&failed[SMB2_CHANGE_NOTIFY_HE]));
60011 seq_printf(m, "\nQueryInfos: %d sent %d failed",
60012- atomic_read(&sent[SMB2_QUERY_INFO_HE]),
60013- atomic_read(&failed[SMB2_QUERY_INFO_HE]));
60014+ atomic_read_unchecked(&sent[SMB2_QUERY_INFO_HE]),
60015+ atomic_read_unchecked(&failed[SMB2_QUERY_INFO_HE]));
60016 seq_printf(m, "\nSetInfos: %d sent %d failed",
60017- atomic_read(&sent[SMB2_SET_INFO_HE]),
60018- atomic_read(&failed[SMB2_SET_INFO_HE]));
60019+ atomic_read_unchecked(&sent[SMB2_SET_INFO_HE]),
60020+ atomic_read_unchecked(&failed[SMB2_SET_INFO_HE]));
60021 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
60022- atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
60023- atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
60024+ atomic_read_unchecked(&sent[SMB2_OPLOCK_BREAK_HE]),
60025+ atomic_read_unchecked(&failed[SMB2_OPLOCK_BREAK_HE]));
60026 #endif
60027 }
60028
60029diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c
60030index 8f1672b..af339c07 100644
60031--- a/fs/cifs/smb2pdu.c
60032+++ b/fs/cifs/smb2pdu.c
60033@@ -2145,8 +2145,7 @@ SMB2_query_directory(const unsigned int xid, struct cifs_tcon *tcon,
60034 default:
60035 cifs_dbg(VFS, "info level %u isn't supported\n",
60036 srch_inf->info_level);
60037- rc = -EINVAL;
60038- goto qdir_exit;
60039+ return -EINVAL;
60040 }
60041
60042 req->FileIndex = cpu_to_le32(index);
60043diff --git a/fs/coda/cache.c b/fs/coda/cache.c
60044index 46ee6f2..89a9e7f 100644
60045--- a/fs/coda/cache.c
60046+++ b/fs/coda/cache.c
60047@@ -24,7 +24,7 @@
60048 #include "coda_linux.h"
60049 #include "coda_cache.h"
60050
60051-static atomic_t permission_epoch = ATOMIC_INIT(0);
60052+static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
60053
60054 /* replace or extend an acl cache hit */
60055 void coda_cache_enter(struct inode *inode, int mask)
60056@@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
60057 struct coda_inode_info *cii = ITOC(inode);
60058
60059 spin_lock(&cii->c_lock);
60060- cii->c_cached_epoch = atomic_read(&permission_epoch);
60061+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
60062 if (!uid_eq(cii->c_uid, current_fsuid())) {
60063 cii->c_uid = current_fsuid();
60064 cii->c_cached_perm = mask;
60065@@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
60066 {
60067 struct coda_inode_info *cii = ITOC(inode);
60068 spin_lock(&cii->c_lock);
60069- cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
60070+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
60071 spin_unlock(&cii->c_lock);
60072 }
60073
60074 /* remove all acl caches */
60075 void coda_cache_clear_all(struct super_block *sb)
60076 {
60077- atomic_inc(&permission_epoch);
60078+ atomic_inc_unchecked(&permission_epoch);
60079 }
60080
60081
60082@@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
60083 spin_lock(&cii->c_lock);
60084 hit = (mask & cii->c_cached_perm) == mask &&
60085 uid_eq(cii->c_uid, current_fsuid()) &&
60086- cii->c_cached_epoch == atomic_read(&permission_epoch);
60087+ cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
60088 spin_unlock(&cii->c_lock);
60089
60090 return hit;
60091diff --git a/fs/compat.c b/fs/compat.c
60092index b13df99..6f6f4a3 100644
60093--- a/fs/compat.c
60094+++ b/fs/compat.c
60095@@ -54,7 +54,7 @@
60096 #include <asm/ioctls.h>
60097 #include "internal.h"
60098
60099-int compat_log = 1;
60100+int compat_log = 0;
60101
60102 int compat_printk(const char *fmt, ...)
60103 {
60104@@ -512,7 +512,7 @@ COMPAT_SYSCALL_DEFINE2(io_setup, unsigned, nr_reqs, u32 __user *, ctx32p)
60105
60106 set_fs(KERNEL_DS);
60107 /* The __user pointer cast is valid because of the set_fs() */
60108- ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
60109+ ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
60110 set_fs(oldfs);
60111 /* truncating is ok because it's a user address */
60112 if (!ret)
60113@@ -562,7 +562,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
60114 goto out;
60115
60116 ret = -EINVAL;
60117- if (nr_segs > UIO_MAXIOV || nr_segs < 0)
60118+ if (nr_segs > UIO_MAXIOV)
60119 goto out;
60120 if (nr_segs > fast_segs) {
60121 ret = -ENOMEM;
60122@@ -844,6 +844,7 @@ struct compat_old_linux_dirent {
60123 struct compat_readdir_callback {
60124 struct dir_context ctx;
60125 struct compat_old_linux_dirent __user *dirent;
60126+ struct file * file;
60127 int result;
60128 };
60129
60130@@ -861,6 +862,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
60131 buf->result = -EOVERFLOW;
60132 return -EOVERFLOW;
60133 }
60134+
60135+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
60136+ return 0;
60137+
60138 buf->result++;
60139 dirent = buf->dirent;
60140 if (!access_ok(VERIFY_WRITE, dirent,
60141@@ -892,6 +897,7 @@ COMPAT_SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
60142 if (!f.file)
60143 return -EBADF;
60144
60145+ buf.file = f.file;
60146 error = iterate_dir(f.file, &buf.ctx);
60147 if (buf.result)
60148 error = buf.result;
60149@@ -911,6 +917,7 @@ struct compat_getdents_callback {
60150 struct dir_context ctx;
60151 struct compat_linux_dirent __user *current_dir;
60152 struct compat_linux_dirent __user *previous;
60153+ struct file * file;
60154 int count;
60155 int error;
60156 };
60157@@ -932,6 +939,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
60158 buf->error = -EOVERFLOW;
60159 return -EOVERFLOW;
60160 }
60161+
60162+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
60163+ return 0;
60164+
60165 dirent = buf->previous;
60166 if (dirent) {
60167 if (__put_user(offset, &dirent->d_off))
60168@@ -977,6 +988,7 @@ COMPAT_SYSCALL_DEFINE3(getdents, unsigned int, fd,
60169 if (!f.file)
60170 return -EBADF;
60171
60172+ buf.file = f.file;
60173 error = iterate_dir(f.file, &buf.ctx);
60174 if (error >= 0)
60175 error = buf.error;
60176@@ -997,6 +1009,7 @@ struct compat_getdents_callback64 {
60177 struct dir_context ctx;
60178 struct linux_dirent64 __user *current_dir;
60179 struct linux_dirent64 __user *previous;
60180+ struct file * file;
60181 int count;
60182 int error;
60183 };
60184@@ -1013,6 +1026,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
60185 buf->error = -EINVAL; /* only used if we fail.. */
60186 if (reclen > buf->count)
60187 return -EINVAL;
60188+
60189+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
60190+ return 0;
60191+
60192 dirent = buf->previous;
60193
60194 if (dirent) {
60195@@ -1062,6 +1079,7 @@ COMPAT_SYSCALL_DEFINE3(getdents64, unsigned int, fd,
60196 if (!f.file)
60197 return -EBADF;
60198
60199+ buf.file = f.file;
60200 error = iterate_dir(f.file, &buf.ctx);
60201 if (error >= 0)
60202 error = buf.error;
60203diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
60204index 4d24d17..4f8c09e 100644
60205--- a/fs/compat_binfmt_elf.c
60206+++ b/fs/compat_binfmt_elf.c
60207@@ -30,11 +30,13 @@
60208 #undef elf_phdr
60209 #undef elf_shdr
60210 #undef elf_note
60211+#undef elf_dyn
60212 #undef elf_addr_t
60213 #define elfhdr elf32_hdr
60214 #define elf_phdr elf32_phdr
60215 #define elf_shdr elf32_shdr
60216 #define elf_note elf32_note
60217+#define elf_dyn Elf32_Dyn
60218 #define elf_addr_t Elf32_Addr
60219
60220 /*
60221diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
60222index afec645..9c65620 100644
60223--- a/fs/compat_ioctl.c
60224+++ b/fs/compat_ioctl.c
60225@@ -621,7 +621,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
60226 return -EFAULT;
60227 if (__get_user(udata, &ss32->iomem_base))
60228 return -EFAULT;
60229- ss.iomem_base = compat_ptr(udata);
60230+ ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
60231 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
60232 __get_user(ss.port_high, &ss32->port_high))
60233 return -EFAULT;
60234@@ -703,8 +703,8 @@ static int do_i2c_rdwr_ioctl(unsigned int fd, unsigned int cmd,
60235 for (i = 0; i < nmsgs; i++) {
60236 if (copy_in_user(&tmsgs[i].addr, &umsgs[i].addr, 3*sizeof(u16)))
60237 return -EFAULT;
60238- if (get_user(datap, &umsgs[i].buf) ||
60239- put_user(compat_ptr(datap), &tmsgs[i].buf))
60240+ if (get_user(datap, (compat_caddr_t __user *)&umsgs[i].buf) ||
60241+ put_user(compat_ptr(datap), (u8 __user * __user *)&tmsgs[i].buf))
60242 return -EFAULT;
60243 }
60244 return sys_ioctl(fd, cmd, (unsigned long)tdata);
60245@@ -797,7 +797,7 @@ static int compat_ioctl_preallocate(struct file *file,
60246 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
60247 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
60248 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
60249- copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
60250+ copy_in_user(p->l_pad, p32->l_pad, 4*sizeof(u32)))
60251 return -EFAULT;
60252
60253 return ioctl_preallocate(file, p);
60254@@ -1618,8 +1618,8 @@ COMPAT_SYSCALL_DEFINE3(ioctl, unsigned int, fd, unsigned int, cmd,
60255 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
60256 {
60257 unsigned int a, b;
60258- a = *(unsigned int *)p;
60259- b = *(unsigned int *)q;
60260+ a = *(const unsigned int *)p;
60261+ b = *(const unsigned int *)q;
60262 if (a > b)
60263 return 1;
60264 if (a < b)
60265diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
60266index 668dcab..daebcd6 100644
60267--- a/fs/configfs/dir.c
60268+++ b/fs/configfs/dir.c
60269@@ -1548,7 +1548,8 @@ static int configfs_readdir(struct file *file, struct dir_context *ctx)
60270 }
60271 for (p = q->next; p != &parent_sd->s_children; p = p->next) {
60272 struct configfs_dirent *next;
60273- const char *name;
60274+ const unsigned char * name;
60275+ char d_name[sizeof(next->s_dentry->d_iname)];
60276 int len;
60277 struct inode *inode = NULL;
60278
60279@@ -1557,7 +1558,12 @@ static int configfs_readdir(struct file *file, struct dir_context *ctx)
60280 continue;
60281
60282 name = configfs_get_name(next);
60283- len = strlen(name);
60284+ if (next->s_dentry && name == next->s_dentry->d_iname) {
60285+ len = next->s_dentry->d_name.len;
60286+ memcpy(d_name, name, len);
60287+ name = d_name;
60288+ } else
60289+ len = strlen(name);
60290
60291 /*
60292 * We'll have a dentry and an inode for
60293diff --git a/fs/coredump.c b/fs/coredump.c
60294index b5c86ff..0dac262 100644
60295--- a/fs/coredump.c
60296+++ b/fs/coredump.c
60297@@ -450,8 +450,8 @@ static void wait_for_dump_helpers(struct file *file)
60298 struct pipe_inode_info *pipe = file->private_data;
60299
60300 pipe_lock(pipe);
60301- pipe->readers++;
60302- pipe->writers--;
60303+ atomic_inc(&pipe->readers);
60304+ atomic_dec(&pipe->writers);
60305 wake_up_interruptible_sync(&pipe->wait);
60306 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
60307 pipe_unlock(pipe);
60308@@ -460,11 +460,11 @@ static void wait_for_dump_helpers(struct file *file)
60309 * We actually want wait_event_freezable() but then we need
60310 * to clear TIF_SIGPENDING and improve dump_interrupted().
60311 */
60312- wait_event_interruptible(pipe->wait, pipe->readers == 1);
60313+ wait_event_interruptible(pipe->wait, atomic_read(&pipe->readers) == 1);
60314
60315 pipe_lock(pipe);
60316- pipe->readers--;
60317- pipe->writers++;
60318+ atomic_dec(&pipe->readers);
60319+ atomic_inc(&pipe->writers);
60320 pipe_unlock(pipe);
60321 }
60322
60323@@ -511,7 +511,9 @@ void do_coredump(const siginfo_t *siginfo)
60324 struct files_struct *displaced;
60325 bool need_nonrelative = false;
60326 bool core_dumped = false;
60327- static atomic_t core_dump_count = ATOMIC_INIT(0);
60328+ static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
60329+ long signr = siginfo->si_signo;
60330+ int dumpable;
60331 struct coredump_params cprm = {
60332 .siginfo = siginfo,
60333 .regs = signal_pt_regs(),
60334@@ -524,12 +526,17 @@ void do_coredump(const siginfo_t *siginfo)
60335 .mm_flags = mm->flags,
60336 };
60337
60338- audit_core_dumps(siginfo->si_signo);
60339+ audit_core_dumps(signr);
60340+
60341+ dumpable = __get_dumpable(cprm.mm_flags);
60342+
60343+ if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
60344+ gr_handle_brute_attach(dumpable);
60345
60346 binfmt = mm->binfmt;
60347 if (!binfmt || !binfmt->core_dump)
60348 goto fail;
60349- if (!__get_dumpable(cprm.mm_flags))
60350+ if (!dumpable)
60351 goto fail;
60352
60353 cred = prepare_creds();
60354@@ -548,7 +555,7 @@ void do_coredump(const siginfo_t *siginfo)
60355 need_nonrelative = true;
60356 }
60357
60358- retval = coredump_wait(siginfo->si_signo, &core_state);
60359+ retval = coredump_wait(signr, &core_state);
60360 if (retval < 0)
60361 goto fail_creds;
60362
60363@@ -591,7 +598,7 @@ void do_coredump(const siginfo_t *siginfo)
60364 }
60365 cprm.limit = RLIM_INFINITY;
60366
60367- dump_count = atomic_inc_return(&core_dump_count);
60368+ dump_count = atomic_inc_return_unchecked(&core_dump_count);
60369 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
60370 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
60371 task_tgid_vnr(current), current->comm);
60372@@ -623,6 +630,8 @@ void do_coredump(const siginfo_t *siginfo)
60373 } else {
60374 struct inode *inode;
60375
60376+ gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
60377+
60378 if (cprm.limit < binfmt->min_coredump)
60379 goto fail_unlock;
60380
60381@@ -681,7 +690,7 @@ close_fail:
60382 filp_close(cprm.file, NULL);
60383 fail_dropcount:
60384 if (ispipe)
60385- atomic_dec(&core_dump_count);
60386+ atomic_dec_unchecked(&core_dump_count);
60387 fail_unlock:
60388 kfree(cn.corename);
60389 coredump_finish(mm, core_dumped);
60390@@ -702,6 +711,8 @@ int dump_emit(struct coredump_params *cprm, const void *addr, int nr)
60391 struct file *file = cprm->file;
60392 loff_t pos = file->f_pos;
60393 ssize_t n;
60394+
60395+ gr_learn_resource(current, RLIMIT_CORE, cprm->written + nr, 1);
60396 if (cprm->written + nr > cprm->limit)
60397 return 0;
60398 while (nr) {
60399diff --git a/fs/dcache.c b/fs/dcache.c
60400index 71acf8d..815e743 100644
60401--- a/fs/dcache.c
60402+++ b/fs/dcache.c
60403@@ -508,7 +508,7 @@ static void __dentry_kill(struct dentry *dentry)
60404 * dentry_iput drops the locks, at which point nobody (except
60405 * transient RCU lookups) can reach this dentry.
60406 */
60407- BUG_ON((int)dentry->d_lockref.count > 0);
60408+ BUG_ON((int)__lockref_read(&dentry->d_lockref) > 0);
60409 this_cpu_dec(nr_dentry);
60410 if (dentry->d_op && dentry->d_op->d_release)
60411 dentry->d_op->d_release(dentry);
60412@@ -561,7 +561,7 @@ static inline struct dentry *lock_parent(struct dentry *dentry)
60413 struct dentry *parent = dentry->d_parent;
60414 if (IS_ROOT(dentry))
60415 return NULL;
60416- if (unlikely((int)dentry->d_lockref.count < 0))
60417+ if (unlikely((int)__lockref_read(&dentry->d_lockref) < 0))
60418 return NULL;
60419 if (likely(spin_trylock(&parent->d_lock)))
60420 return parent;
60421@@ -638,7 +638,7 @@ repeat:
60422 dentry->d_flags |= DCACHE_REFERENCED;
60423 dentry_lru_add(dentry);
60424
60425- dentry->d_lockref.count--;
60426+ __lockref_dec(&dentry->d_lockref);
60427 spin_unlock(&dentry->d_lock);
60428 return;
60429
60430@@ -653,7 +653,7 @@ EXPORT_SYMBOL(dput);
60431 /* This must be called with d_lock held */
60432 static inline void __dget_dlock(struct dentry *dentry)
60433 {
60434- dentry->d_lockref.count++;
60435+ __lockref_inc(&dentry->d_lockref);
60436 }
60437
60438 static inline void __dget(struct dentry *dentry)
60439@@ -694,8 +694,8 @@ repeat:
60440 goto repeat;
60441 }
60442 rcu_read_unlock();
60443- BUG_ON(!ret->d_lockref.count);
60444- ret->d_lockref.count++;
60445+ BUG_ON(!__lockref_read(&ret->d_lockref));
60446+ __lockref_inc(&ret->d_lockref);
60447 spin_unlock(&ret->d_lock);
60448 return ret;
60449 }
60450@@ -773,9 +773,9 @@ restart:
60451 spin_lock(&inode->i_lock);
60452 hlist_for_each_entry(dentry, &inode->i_dentry, d_u.d_alias) {
60453 spin_lock(&dentry->d_lock);
60454- if (!dentry->d_lockref.count) {
60455+ if (!__lockref_read(&dentry->d_lockref)) {
60456 struct dentry *parent = lock_parent(dentry);
60457- if (likely(!dentry->d_lockref.count)) {
60458+ if (likely(!__lockref_read(&dentry->d_lockref))) {
60459 __dentry_kill(dentry);
60460 dput(parent);
60461 goto restart;
60462@@ -810,7 +810,7 @@ static void shrink_dentry_list(struct list_head *list)
60463 * We found an inuse dentry which was not removed from
60464 * the LRU because of laziness during lookup. Do not free it.
60465 */
60466- if ((int)dentry->d_lockref.count > 0) {
60467+ if ((int)__lockref_read(&dentry->d_lockref) > 0) {
60468 spin_unlock(&dentry->d_lock);
60469 if (parent)
60470 spin_unlock(&parent->d_lock);
60471@@ -848,8 +848,8 @@ static void shrink_dentry_list(struct list_head *list)
60472 dentry = parent;
60473 while (dentry && !lockref_put_or_lock(&dentry->d_lockref)) {
60474 parent = lock_parent(dentry);
60475- if (dentry->d_lockref.count != 1) {
60476- dentry->d_lockref.count--;
60477+ if (__lockref_read(&dentry->d_lockref) != 1) {
60478+ __lockref_inc(&dentry->d_lockref);
60479 spin_unlock(&dentry->d_lock);
60480 if (parent)
60481 spin_unlock(&parent->d_lock);
60482@@ -889,7 +889,7 @@ dentry_lru_isolate(struct list_head *item, spinlock_t *lru_lock, void *arg)
60483 * counts, just remove them from the LRU. Otherwise give them
60484 * another pass through the LRU.
60485 */
60486- if (dentry->d_lockref.count) {
60487+ if (__lockref_read(&dentry->d_lockref) > 0) {
60488 d_lru_isolate(dentry);
60489 spin_unlock(&dentry->d_lock);
60490 return LRU_REMOVED;
60491@@ -1225,7 +1225,7 @@ static enum d_walk_ret select_collect(void *_data, struct dentry *dentry)
60492 } else {
60493 if (dentry->d_flags & DCACHE_LRU_LIST)
60494 d_lru_del(dentry);
60495- if (!dentry->d_lockref.count) {
60496+ if (!__lockref_read(&dentry->d_lockref)) {
60497 d_shrink_add(dentry, &data->dispose);
60498 data->found++;
60499 }
60500@@ -1273,7 +1273,7 @@ static enum d_walk_ret umount_check(void *_data, struct dentry *dentry)
60501 return D_WALK_CONTINUE;
60502
60503 /* root with refcount 1 is fine */
60504- if (dentry == _data && dentry->d_lockref.count == 1)
60505+ if (dentry == _data && __lockref_read(&dentry->d_lockref) == 1)
60506 return D_WALK_CONTINUE;
60507
60508 printk(KERN_ERR "BUG: Dentry %p{i=%lx,n=%pd} "
60509@@ -1282,7 +1282,7 @@ static enum d_walk_ret umount_check(void *_data, struct dentry *dentry)
60510 dentry->d_inode ?
60511 dentry->d_inode->i_ino : 0UL,
60512 dentry,
60513- dentry->d_lockref.count,
60514+ __lockref_read(&dentry->d_lockref),
60515 dentry->d_sb->s_type->name,
60516 dentry->d_sb->s_id);
60517 WARN_ON(1);
60518@@ -1423,7 +1423,7 @@ struct dentry *__d_alloc(struct super_block *sb, const struct qstr *name)
60519 dentry->d_iname[DNAME_INLINE_LEN-1] = 0;
60520 if (name->len > DNAME_INLINE_LEN-1) {
60521 size_t size = offsetof(struct external_name, name[1]);
60522- struct external_name *p = kmalloc(size + name->len, GFP_KERNEL);
60523+ struct external_name *p = kmalloc(round_up(size + name->len, sizeof(unsigned long)), GFP_KERNEL);
60524 if (!p) {
60525 kmem_cache_free(dentry_cache, dentry);
60526 return NULL;
60527@@ -1443,7 +1443,7 @@ struct dentry *__d_alloc(struct super_block *sb, const struct qstr *name)
60528 smp_wmb();
60529 dentry->d_name.name = dname;
60530
60531- dentry->d_lockref.count = 1;
60532+ __lockref_set(&dentry->d_lockref, 1);
60533 dentry->d_flags = 0;
60534 spin_lock_init(&dentry->d_lock);
60535 seqcount_init(&dentry->d_seq);
60536@@ -2183,7 +2183,7 @@ struct dentry *__d_lookup(const struct dentry *parent, const struct qstr *name)
60537 goto next;
60538 }
60539
60540- dentry->d_lockref.count++;
60541+ __lockref_inc(&dentry->d_lockref);
60542 found = dentry;
60543 spin_unlock(&dentry->d_lock);
60544 break;
60545@@ -2282,7 +2282,7 @@ again:
60546 spin_lock(&dentry->d_lock);
60547 inode = dentry->d_inode;
60548 isdir = S_ISDIR(inode->i_mode);
60549- if (dentry->d_lockref.count == 1) {
60550+ if (__lockref_read(&dentry->d_lockref) == 1) {
60551 if (!spin_trylock(&inode->i_lock)) {
60552 spin_unlock(&dentry->d_lock);
60553 cpu_relax();
60554@@ -3306,7 +3306,7 @@ static enum d_walk_ret d_genocide_kill(void *data, struct dentry *dentry)
60555
60556 if (!(dentry->d_flags & DCACHE_GENOCIDE)) {
60557 dentry->d_flags |= DCACHE_GENOCIDE;
60558- dentry->d_lockref.count--;
60559+ __lockref_dec(&dentry->d_lockref);
60560 }
60561 }
60562 return D_WALK_CONTINUE;
60563@@ -3422,7 +3422,8 @@ void __init vfs_caches_init(unsigned long mempages)
60564 mempages -= reserve;
60565
60566 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
60567- SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
60568+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY|
60569+ SLAB_NO_SANITIZE, NULL);
60570
60571 dcache_init();
60572 inode_init();
60573diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
60574index 05f2960..b012481 100644
60575--- a/fs/debugfs/inode.c
60576+++ b/fs/debugfs/inode.c
60577@@ -416,7 +416,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
60578 */
60579 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
60580 {
60581+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
60582+ return __create_file(name, S_IFDIR | S_IRWXU,
60583+#else
60584 return __create_file(name, S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
60585+#endif
60586 parent, NULL, NULL);
60587 }
60588 EXPORT_SYMBOL_GPL(debugfs_create_dir);
60589diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
60590index 1686dc2..9611c50 100644
60591--- a/fs/ecryptfs/inode.c
60592+++ b/fs/ecryptfs/inode.c
60593@@ -664,7 +664,7 @@ static char *ecryptfs_readlink_lower(struct dentry *dentry, size_t *bufsiz)
60594 old_fs = get_fs();
60595 set_fs(get_ds());
60596 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
60597- (char __user *)lower_buf,
60598+ (char __force_user *)lower_buf,
60599 PATH_MAX);
60600 set_fs(old_fs);
60601 if (rc < 0)
60602diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
60603index e4141f2..d8263e8 100644
60604--- a/fs/ecryptfs/miscdev.c
60605+++ b/fs/ecryptfs/miscdev.c
60606@@ -304,7 +304,7 @@ check_list:
60607 goto out_unlock_msg_ctx;
60608 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
60609 if (msg_ctx->msg) {
60610- if (copy_to_user(&buf[i], packet_length, packet_length_size))
60611+ if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
60612 goto out_unlock_msg_ctx;
60613 i += packet_length_size;
60614 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
60615diff --git a/fs/exec.c b/fs/exec.c
60616index 7302b75..7d61d19 100644
60617--- a/fs/exec.c
60618+++ b/fs/exec.c
60619@@ -56,8 +56,20 @@
60620 #include <linux/pipe_fs_i.h>
60621 #include <linux/oom.h>
60622 #include <linux/compat.h>
60623+#include <linux/random.h>
60624+#include <linux/seq_file.h>
60625+#include <linux/coredump.h>
60626+#include <linux/mman.h>
60627+
60628+#ifdef CONFIG_PAX_REFCOUNT
60629+#include <linux/kallsyms.h>
60630+#include <linux/kdebug.h>
60631+#endif
60632+
60633+#include <trace/events/fs.h>
60634
60635 #include <asm/uaccess.h>
60636+#include <asm/sections.h>
60637 #include <asm/mmu_context.h>
60638 #include <asm/tlb.h>
60639
60640@@ -66,19 +78,34 @@
60641
60642 #include <trace/events/sched.h>
60643
60644+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
60645+void __weak pax_set_initial_flags(struct linux_binprm *bprm)
60646+{
60647+ 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");
60648+}
60649+#endif
60650+
60651+#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
60652+void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
60653+EXPORT_SYMBOL(pax_set_initial_flags_func);
60654+#endif
60655+
60656 int suid_dumpable = 0;
60657
60658 static LIST_HEAD(formats);
60659 static DEFINE_RWLOCK(binfmt_lock);
60660
60661+extern int gr_process_kernel_exec_ban(void);
60662+extern int gr_process_suid_exec_ban(const struct linux_binprm *bprm);
60663+
60664 void __register_binfmt(struct linux_binfmt * fmt, int insert)
60665 {
60666 BUG_ON(!fmt);
60667 if (WARN_ON(!fmt->load_binary))
60668 return;
60669 write_lock(&binfmt_lock);
60670- insert ? list_add(&fmt->lh, &formats) :
60671- list_add_tail(&fmt->lh, &formats);
60672+ insert ? pax_list_add((struct list_head *)&fmt->lh, &formats) :
60673+ pax_list_add_tail((struct list_head *)&fmt->lh, &formats);
60674 write_unlock(&binfmt_lock);
60675 }
60676
60677@@ -87,7 +114,7 @@ EXPORT_SYMBOL(__register_binfmt);
60678 void unregister_binfmt(struct linux_binfmt * fmt)
60679 {
60680 write_lock(&binfmt_lock);
60681- list_del(&fmt->lh);
60682+ pax_list_del((struct list_head *)&fmt->lh);
60683 write_unlock(&binfmt_lock);
60684 }
60685
60686@@ -183,18 +210,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
60687 int write)
60688 {
60689 struct page *page;
60690- int ret;
60691
60692-#ifdef CONFIG_STACK_GROWSUP
60693- if (write) {
60694- ret = expand_downwards(bprm->vma, pos);
60695- if (ret < 0)
60696- return NULL;
60697- }
60698-#endif
60699- ret = get_user_pages(current, bprm->mm, pos,
60700- 1, write, 1, &page, NULL);
60701- if (ret <= 0)
60702+ if (0 > expand_downwards(bprm->vma, pos))
60703+ return NULL;
60704+ if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
60705 return NULL;
60706
60707 if (write) {
60708@@ -210,6 +229,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
60709 if (size <= ARG_MAX)
60710 return page;
60711
60712+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60713+ // only allow 512KB for argv+env on suid/sgid binaries
60714+ // to prevent easy ASLR exhaustion
60715+ if (((!uid_eq(bprm->cred->euid, current_euid())) ||
60716+ (!gid_eq(bprm->cred->egid, current_egid()))) &&
60717+ (size > (512 * 1024))) {
60718+ put_page(page);
60719+ return NULL;
60720+ }
60721+#endif
60722+
60723 /*
60724 * Limit to 1/4-th the stack size for the argv+env strings.
60725 * This ensures that:
60726@@ -269,6 +299,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
60727 vma->vm_end = STACK_TOP_MAX;
60728 vma->vm_start = vma->vm_end - PAGE_SIZE;
60729 vma->vm_flags = VM_SOFTDIRTY | VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
60730+
60731+#ifdef CONFIG_PAX_SEGMEXEC
60732+ vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
60733+#endif
60734+
60735 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
60736 INIT_LIST_HEAD(&vma->anon_vma_chain);
60737
60738@@ -279,6 +314,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
60739 mm->stack_vm = mm->total_vm = 1;
60740 up_write(&mm->mmap_sem);
60741 bprm->p = vma->vm_end - sizeof(void *);
60742+
60743+#ifdef CONFIG_PAX_RANDUSTACK
60744+ if (randomize_va_space)
60745+ bprm->p ^= prandom_u32() & ~PAGE_MASK;
60746+#endif
60747+
60748 return 0;
60749 err:
60750 up_write(&mm->mmap_sem);
60751@@ -395,7 +436,7 @@ struct user_arg_ptr {
60752 } ptr;
60753 };
60754
60755-static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
60756+const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
60757 {
60758 const char __user *native;
60759
60760@@ -404,14 +445,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
60761 compat_uptr_t compat;
60762
60763 if (get_user(compat, argv.ptr.compat + nr))
60764- return ERR_PTR(-EFAULT);
60765+ return (const char __force_user *)ERR_PTR(-EFAULT);
60766
60767 return compat_ptr(compat);
60768 }
60769 #endif
60770
60771 if (get_user(native, argv.ptr.native + nr))
60772- return ERR_PTR(-EFAULT);
60773+ return (const char __force_user *)ERR_PTR(-EFAULT);
60774
60775 return native;
60776 }
60777@@ -430,7 +471,7 @@ static int count(struct user_arg_ptr argv, int max)
60778 if (!p)
60779 break;
60780
60781- if (IS_ERR(p))
60782+ if (IS_ERR((const char __force_kernel *)p))
60783 return -EFAULT;
60784
60785 if (i >= max)
60786@@ -465,7 +506,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
60787
60788 ret = -EFAULT;
60789 str = get_user_arg_ptr(argv, argc);
60790- if (IS_ERR(str))
60791+ if (IS_ERR((const char __force_kernel *)str))
60792 goto out;
60793
60794 len = strnlen_user(str, MAX_ARG_STRLEN);
60795@@ -547,7 +588,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
60796 int r;
60797 mm_segment_t oldfs = get_fs();
60798 struct user_arg_ptr argv = {
60799- .ptr.native = (const char __user *const __user *)__argv,
60800+ .ptr.native = (const char __user * const __force_user *)__argv,
60801 };
60802
60803 set_fs(KERNEL_DS);
60804@@ -582,7 +623,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
60805 unsigned long new_end = old_end - shift;
60806 struct mmu_gather tlb;
60807
60808- BUG_ON(new_start > new_end);
60809+ if (new_start >= new_end || new_start < mmap_min_addr)
60810+ return -ENOMEM;
60811
60812 /*
60813 * ensure there are no vmas between where we want to go
60814@@ -591,6 +633,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
60815 if (vma != find_vma(mm, new_start))
60816 return -EFAULT;
60817
60818+#ifdef CONFIG_PAX_SEGMEXEC
60819+ BUG_ON(pax_find_mirror_vma(vma));
60820+#endif
60821+
60822 /*
60823 * cover the whole range: [new_start, old_end)
60824 */
60825@@ -671,10 +717,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
60826 stack_top = arch_align_stack(stack_top);
60827 stack_top = PAGE_ALIGN(stack_top);
60828
60829- if (unlikely(stack_top < mmap_min_addr) ||
60830- unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
60831- return -ENOMEM;
60832-
60833 stack_shift = vma->vm_end - stack_top;
60834
60835 bprm->p -= stack_shift;
60836@@ -686,8 +728,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
60837 bprm->exec -= stack_shift;
60838
60839 down_write(&mm->mmap_sem);
60840+
60841+ /* Move stack pages down in memory. */
60842+ if (stack_shift) {
60843+ ret = shift_arg_pages(vma, stack_shift);
60844+ if (ret)
60845+ goto out_unlock;
60846+ }
60847+
60848 vm_flags = VM_STACK_FLAGS;
60849
60850+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
60851+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
60852+ vm_flags &= ~VM_EXEC;
60853+
60854+#ifdef CONFIG_PAX_MPROTECT
60855+ if (mm->pax_flags & MF_PAX_MPROTECT)
60856+ vm_flags &= ~VM_MAYEXEC;
60857+#endif
60858+
60859+ }
60860+#endif
60861+
60862 /*
60863 * Adjust stack execute permissions; explicitly enable for
60864 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
60865@@ -706,13 +768,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
60866 goto out_unlock;
60867 BUG_ON(prev != vma);
60868
60869- /* Move stack pages down in memory. */
60870- if (stack_shift) {
60871- ret = shift_arg_pages(vma, stack_shift);
60872- if (ret)
60873- goto out_unlock;
60874- }
60875-
60876 /* mprotect_fixup is overkill to remove the temporary stack flags */
60877 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
60878
60879@@ -736,6 +791,27 @@ int setup_arg_pages(struct linux_binprm *bprm,
60880 #endif
60881 current->mm->start_stack = bprm->p;
60882 ret = expand_stack(vma, stack_base);
60883+
60884+#if !defined(CONFIG_STACK_GROWSUP) && defined(CONFIG_PAX_RANDMMAP)
60885+ if (!ret && (mm->pax_flags & MF_PAX_RANDMMAP) && STACK_TOP <= 0xFFFFFFFFU && STACK_TOP > vma->vm_end) {
60886+ unsigned long size;
60887+ vm_flags_t vm_flags;
60888+
60889+ size = STACK_TOP - vma->vm_end;
60890+ vm_flags = VM_NONE | VM_DONTEXPAND | VM_DONTDUMP;
60891+
60892+ ret = vma->vm_end != mmap_region(NULL, vma->vm_end, size, vm_flags, 0);
60893+
60894+#ifdef CONFIG_X86
60895+ if (!ret) {
60896+ size = PAGE_SIZE + mmap_min_addr + ((mm->delta_mmap ^ mm->delta_stack) & (0xFFUL << PAGE_SHIFT));
60897+ ret = 0 != mmap_region(NULL, 0, PAGE_ALIGN(size), vm_flags, 0);
60898+ }
60899+#endif
60900+
60901+ }
60902+#endif
60903+
60904 if (ret)
60905 ret = -EFAULT;
60906
60907@@ -771,6 +847,8 @@ static struct file *do_open_exec(struct filename *name)
60908
60909 fsnotify_open(file);
60910
60911+ trace_open_exec(name->name);
60912+
60913 err = deny_write_access(file);
60914 if (err)
60915 goto exit;
60916@@ -800,7 +878,7 @@ int kernel_read(struct file *file, loff_t offset,
60917 old_fs = get_fs();
60918 set_fs(get_ds());
60919 /* The cast to a user pointer is valid due to the set_fs() */
60920- result = vfs_read(file, (void __user *)addr, count, &pos);
60921+ result = vfs_read(file, (void __force_user *)addr, count, &pos);
60922 set_fs(old_fs);
60923 return result;
60924 }
60925@@ -845,6 +923,7 @@ static int exec_mmap(struct mm_struct *mm)
60926 tsk->mm = mm;
60927 tsk->active_mm = mm;
60928 activate_mm(active_mm, mm);
60929+ populate_stack();
60930 tsk->mm->vmacache_seqnum = 0;
60931 vmacache_flush(tsk);
60932 task_unlock(tsk);
60933@@ -1243,7 +1322,7 @@ static void check_unsafe_exec(struct linux_binprm *bprm)
60934 }
60935 rcu_read_unlock();
60936
60937- if (p->fs->users > n_fs)
60938+ if (atomic_read(&p->fs->users) > n_fs)
60939 bprm->unsafe |= LSM_UNSAFE_SHARE;
60940 else
60941 p->fs->in_exec = 1;
60942@@ -1424,6 +1503,31 @@ static int exec_binprm(struct linux_binprm *bprm)
60943 return ret;
60944 }
60945
60946+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60947+static DEFINE_PER_CPU(u64, exec_counter);
60948+static int __init init_exec_counters(void)
60949+{
60950+ unsigned int cpu;
60951+
60952+ for_each_possible_cpu(cpu) {
60953+ per_cpu(exec_counter, cpu) = (u64)cpu;
60954+ }
60955+
60956+ return 0;
60957+}
60958+early_initcall(init_exec_counters);
60959+static inline void increment_exec_counter(void)
60960+{
60961+ BUILD_BUG_ON(NR_CPUS > (1 << 16));
60962+ current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
60963+}
60964+#else
60965+static inline void increment_exec_counter(void) {}
60966+#endif
60967+
60968+extern void gr_handle_exec_args(struct linux_binprm *bprm,
60969+ struct user_arg_ptr argv);
60970+
60971 /*
60972 * sys_execve() executes a new program.
60973 */
60974@@ -1431,6 +1535,11 @@ static int do_execve_common(struct filename *filename,
60975 struct user_arg_ptr argv,
60976 struct user_arg_ptr envp)
60977 {
60978+#ifdef CONFIG_GRKERNSEC
60979+ struct file *old_exec_file;
60980+ struct acl_subject_label *old_acl;
60981+ struct rlimit old_rlim[RLIM_NLIMITS];
60982+#endif
60983 struct linux_binprm *bprm;
60984 struct file *file;
60985 struct files_struct *displaced;
60986@@ -1439,6 +1548,8 @@ static int do_execve_common(struct filename *filename,
60987 if (IS_ERR(filename))
60988 return PTR_ERR(filename);
60989
60990+ gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current_user()->processes), 1);
60991+
60992 /*
60993 * We move the actual failure in case of RLIMIT_NPROC excess from
60994 * set*uid() to execve() because too many poorly written programs
60995@@ -1476,11 +1587,21 @@ static int do_execve_common(struct filename *filename,
60996 if (IS_ERR(file))
60997 goto out_unmark;
60998
60999+ if (gr_ptrace_readexec(file, bprm->unsafe)) {
61000+ retval = -EPERM;
61001+ goto out_unmark;
61002+ }
61003+
61004 sched_exec();
61005
61006 bprm->file = file;
61007 bprm->filename = bprm->interp = filename->name;
61008
61009+ if (!gr_acl_handle_execve(file->f_path.dentry, file->f_path.mnt)) {
61010+ retval = -EACCES;
61011+ goto out_unmark;
61012+ }
61013+
61014 retval = bprm_mm_init(bprm);
61015 if (retval)
61016 goto out_unmark;
61017@@ -1497,24 +1618,70 @@ static int do_execve_common(struct filename *filename,
61018 if (retval < 0)
61019 goto out;
61020
61021+#ifdef CONFIG_GRKERNSEC
61022+ old_acl = current->acl;
61023+ memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
61024+ old_exec_file = current->exec_file;
61025+ get_file(file);
61026+ current->exec_file = file;
61027+#endif
61028+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
61029+ /* limit suid stack to 8MB
61030+ * we saved the old limits above and will restore them if this exec fails
61031+ */
61032+ if (((!uid_eq(bprm->cred->euid, current_euid())) || (!gid_eq(bprm->cred->egid, current_egid()))) &&
61033+ (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
61034+ current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
61035+#endif
61036+
61037+ if (gr_process_kernel_exec_ban() || gr_process_suid_exec_ban(bprm)) {
61038+ retval = -EPERM;
61039+ goto out_fail;
61040+ }
61041+
61042+ if (!gr_tpe_allow(file)) {
61043+ retval = -EACCES;
61044+ goto out_fail;
61045+ }
61046+
61047+ if (gr_check_crash_exec(file)) {
61048+ retval = -EACCES;
61049+ goto out_fail;
61050+ }
61051+
61052+ retval = gr_set_proc_label(file->f_path.dentry, file->f_path.mnt,
61053+ bprm->unsafe);
61054+ if (retval < 0)
61055+ goto out_fail;
61056+
61057 retval = copy_strings_kernel(1, &bprm->filename, bprm);
61058 if (retval < 0)
61059- goto out;
61060+ goto out_fail;
61061
61062 bprm->exec = bprm->p;
61063 retval = copy_strings(bprm->envc, envp, bprm);
61064 if (retval < 0)
61065- goto out;
61066+ goto out_fail;
61067
61068 retval = copy_strings(bprm->argc, argv, bprm);
61069 if (retval < 0)
61070- goto out;
61071+ goto out_fail;
61072+
61073+ gr_log_chroot_exec(file->f_path.dentry, file->f_path.mnt);
61074+
61075+ gr_handle_exec_args(bprm, argv);
61076
61077 retval = exec_binprm(bprm);
61078 if (retval < 0)
61079- goto out;
61080+ goto out_fail;
61081+#ifdef CONFIG_GRKERNSEC
61082+ if (old_exec_file)
61083+ fput(old_exec_file);
61084+#endif
61085
61086 /* execve succeeded */
61087+
61088+ increment_exec_counter();
61089 current->fs->in_exec = 0;
61090 current->in_execve = 0;
61091 acct_update_integrals(current);
61092@@ -1525,6 +1692,14 @@ static int do_execve_common(struct filename *filename,
61093 put_files_struct(displaced);
61094 return retval;
61095
61096+out_fail:
61097+#ifdef CONFIG_GRKERNSEC
61098+ current->acl = old_acl;
61099+ memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
61100+ fput(current->exec_file);
61101+ current->exec_file = old_exec_file;
61102+#endif
61103+
61104 out:
61105 if (bprm->mm) {
61106 acct_arg_size(bprm, 0);
61107@@ -1616,3 +1791,312 @@ COMPAT_SYSCALL_DEFINE3(execve, const char __user *, filename,
61108 return compat_do_execve(getname(filename), argv, envp);
61109 }
61110 #endif
61111+
61112+int pax_check_flags(unsigned long *flags)
61113+{
61114+ int retval = 0;
61115+
61116+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
61117+ if (*flags & MF_PAX_SEGMEXEC)
61118+ {
61119+ *flags &= ~MF_PAX_SEGMEXEC;
61120+ retval = -EINVAL;
61121+ }
61122+#endif
61123+
61124+ if ((*flags & MF_PAX_PAGEEXEC)
61125+
61126+#ifdef CONFIG_PAX_PAGEEXEC
61127+ && (*flags & MF_PAX_SEGMEXEC)
61128+#endif
61129+
61130+ )
61131+ {
61132+ *flags &= ~MF_PAX_PAGEEXEC;
61133+ retval = -EINVAL;
61134+ }
61135+
61136+ if ((*flags & MF_PAX_MPROTECT)
61137+
61138+#ifdef CONFIG_PAX_MPROTECT
61139+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
61140+#endif
61141+
61142+ )
61143+ {
61144+ *flags &= ~MF_PAX_MPROTECT;
61145+ retval = -EINVAL;
61146+ }
61147+
61148+ if ((*flags & MF_PAX_EMUTRAMP)
61149+
61150+#ifdef CONFIG_PAX_EMUTRAMP
61151+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
61152+#endif
61153+
61154+ )
61155+ {
61156+ *flags &= ~MF_PAX_EMUTRAMP;
61157+ retval = -EINVAL;
61158+ }
61159+
61160+ return retval;
61161+}
61162+
61163+EXPORT_SYMBOL(pax_check_flags);
61164+
61165+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
61166+char *pax_get_path(const struct path *path, char *buf, int buflen)
61167+{
61168+ char *pathname = d_path(path, buf, buflen);
61169+
61170+ if (IS_ERR(pathname))
61171+ goto toolong;
61172+
61173+ pathname = mangle_path(buf, pathname, "\t\n\\");
61174+ if (!pathname)
61175+ goto toolong;
61176+
61177+ *pathname = 0;
61178+ return buf;
61179+
61180+toolong:
61181+ return "<path too long>";
61182+}
61183+EXPORT_SYMBOL(pax_get_path);
61184+
61185+void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
61186+{
61187+ struct task_struct *tsk = current;
61188+ struct mm_struct *mm = current->mm;
61189+ char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
61190+ char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
61191+ char *path_exec = NULL;
61192+ char *path_fault = NULL;
61193+ unsigned long start = 0UL, end = 0UL, offset = 0UL;
61194+ siginfo_t info = { };
61195+
61196+ if (buffer_exec && buffer_fault) {
61197+ struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
61198+
61199+ down_read(&mm->mmap_sem);
61200+ vma = mm->mmap;
61201+ while (vma && (!vma_exec || !vma_fault)) {
61202+ if (vma->vm_file && mm->exe_file == vma->vm_file && (vma->vm_flags & VM_EXEC))
61203+ vma_exec = vma;
61204+ if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
61205+ vma_fault = vma;
61206+ vma = vma->vm_next;
61207+ }
61208+ if (vma_exec)
61209+ path_exec = pax_get_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
61210+ if (vma_fault) {
61211+ start = vma_fault->vm_start;
61212+ end = vma_fault->vm_end;
61213+ offset = vma_fault->vm_pgoff << PAGE_SHIFT;
61214+ if (vma_fault->vm_file)
61215+ path_fault = pax_get_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
61216+ else if ((unsigned long)pc >= mm->start_brk && (unsigned long)pc < mm->brk)
61217+ path_fault = "<heap>";
61218+ else if (vma_fault->vm_flags & (VM_GROWSDOWN | VM_GROWSUP))
61219+ path_fault = "<stack>";
61220+ else
61221+ path_fault = "<anonymous mapping>";
61222+ }
61223+ up_read(&mm->mmap_sem);
61224+ }
61225+ if (tsk->signal->curr_ip)
61226+ printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
61227+ else
61228+ printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
61229+ 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),
61230+ from_kuid_munged(&init_user_ns, task_uid(tsk)), from_kuid_munged(&init_user_ns, task_euid(tsk)), pc, sp);
61231+ free_page((unsigned long)buffer_exec);
61232+ free_page((unsigned long)buffer_fault);
61233+ pax_report_insns(regs, pc, sp);
61234+ info.si_signo = SIGKILL;
61235+ info.si_errno = 0;
61236+ info.si_code = SI_KERNEL;
61237+ info.si_pid = 0;
61238+ info.si_uid = 0;
61239+ do_coredump(&info);
61240+}
61241+#endif
61242+
61243+#ifdef CONFIG_PAX_REFCOUNT
61244+void pax_report_refcount_overflow(struct pt_regs *regs)
61245+{
61246+ if (current->signal->curr_ip)
61247+ printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
61248+ &current->signal->curr_ip, current->comm, task_pid_nr(current),
61249+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
61250+ else
61251+ printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n", current->comm, task_pid_nr(current),
61252+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
61253+ print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
61254+ preempt_disable();
61255+ show_regs(regs);
61256+ preempt_enable();
61257+ force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
61258+}
61259+#endif
61260+
61261+#ifdef CONFIG_PAX_USERCOPY
61262+/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
61263+static noinline int check_stack_object(const void *obj, unsigned long len)
61264+{
61265+ const void * const stack = task_stack_page(current);
61266+ const void * const stackend = stack + THREAD_SIZE;
61267+
61268+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
61269+ const void *frame = NULL;
61270+ const void *oldframe;
61271+#endif
61272+
61273+ if (obj + len < obj)
61274+ return -1;
61275+
61276+ if (obj + len <= stack || stackend <= obj)
61277+ return 0;
61278+
61279+ if (obj < stack || stackend < obj + len)
61280+ return -1;
61281+
61282+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
61283+ oldframe = __builtin_frame_address(1);
61284+ if (oldframe)
61285+ frame = __builtin_frame_address(2);
61286+ /*
61287+ low ----------------------------------------------> high
61288+ [saved bp][saved ip][args][local vars][saved bp][saved ip]
61289+ ^----------------^
61290+ allow copies only within here
61291+ */
61292+ while (stack <= frame && frame < stackend) {
61293+ /* if obj + len extends past the last frame, this
61294+ check won't pass and the next frame will be 0,
61295+ causing us to bail out and correctly report
61296+ the copy as invalid
61297+ */
61298+ if (obj + len <= frame)
61299+ return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
61300+ oldframe = frame;
61301+ frame = *(const void * const *)frame;
61302+ }
61303+ return -1;
61304+#else
61305+ return 1;
61306+#endif
61307+}
61308+
61309+static __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to_user, const char *type)
61310+{
61311+ if (current->signal->curr_ip)
61312+ printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
61313+ &current->signal->curr_ip, to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
61314+ else
61315+ printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
61316+ to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
61317+ dump_stack();
61318+ gr_handle_kernel_exploit();
61319+ do_group_exit(SIGKILL);
61320+}
61321+#endif
61322+
61323+#ifdef CONFIG_PAX_USERCOPY
61324+
61325+static inline bool check_kernel_text_object(unsigned long low, unsigned long high)
61326+{
61327+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
61328+ unsigned long textlow = ktla_ktva((unsigned long)_stext);
61329+#ifdef CONFIG_MODULES
61330+ unsigned long texthigh = (unsigned long)MODULES_EXEC_VADDR;
61331+#else
61332+ unsigned long texthigh = ktla_ktva((unsigned long)_etext);
61333+#endif
61334+
61335+#else
61336+ unsigned long textlow = (unsigned long)_stext;
61337+ unsigned long texthigh = (unsigned long)_etext;
61338+
61339+#ifdef CONFIG_X86_64
61340+ /* check against linear mapping as well */
61341+ if (high > (unsigned long)__va(__pa(textlow)) &&
61342+ low < (unsigned long)__va(__pa(texthigh)))
61343+ return true;
61344+#endif
61345+
61346+#endif
61347+
61348+ if (high <= textlow || low >= texthigh)
61349+ return false;
61350+ else
61351+ return true;
61352+}
61353+#endif
61354+
61355+void __check_object_size(const void *ptr, unsigned long n, bool to_user, bool const_size)
61356+{
61357+#ifdef CONFIG_PAX_USERCOPY
61358+ const char *type;
61359+#endif
61360+
61361+#ifndef CONFIG_STACK_GROWSUP
61362+ unsigned long stackstart = (unsigned long)task_stack_page(current);
61363+ unsigned long currentsp = (unsigned long)&stackstart;
61364+ if (unlikely((currentsp < stackstart + 512 ||
61365+ currentsp >= stackstart + THREAD_SIZE) && !in_interrupt()))
61366+ BUG();
61367+#endif
61368+
61369+#ifndef CONFIG_PAX_USERCOPY_DEBUG
61370+ if (const_size)
61371+ return;
61372+#endif
61373+
61374+#ifdef CONFIG_PAX_USERCOPY
61375+ if (!n)
61376+ return;
61377+
61378+ type = check_heap_object(ptr, n);
61379+ if (!type) {
61380+ int ret = check_stack_object(ptr, n);
61381+ if (ret == 1 || ret == 2)
61382+ return;
61383+ if (ret == 0) {
61384+ if (check_kernel_text_object((unsigned long)ptr, (unsigned long)ptr + n))
61385+ type = "<kernel text>";
61386+ else
61387+ return;
61388+ } else
61389+ type = "<process stack>";
61390+ }
61391+
61392+ pax_report_usercopy(ptr, n, to_user, type);
61393+#endif
61394+
61395+}
61396+EXPORT_SYMBOL(__check_object_size);
61397+
61398+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
61399+void pax_track_stack(void)
61400+{
61401+ unsigned long sp = (unsigned long)&sp;
61402+ if (sp < current_thread_info()->lowest_stack &&
61403+ sp > (unsigned long)task_stack_page(current))
61404+ current_thread_info()->lowest_stack = sp;
61405+ if (unlikely((sp & ~(THREAD_SIZE - 1)) < (THREAD_SIZE/16)))
61406+ BUG();
61407+}
61408+EXPORT_SYMBOL(pax_track_stack);
61409+#endif
61410+
61411+#ifdef CONFIG_PAX_SIZE_OVERFLOW
61412+void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
61413+{
61414+ printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u %s", func, file, line, ssa_name);
61415+ dump_stack();
61416+ do_group_exit(SIGKILL);
61417+}
61418+EXPORT_SYMBOL(report_size_overflow);
61419+#endif
61420diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
61421index 9f9992b..8b59411 100644
61422--- a/fs/ext2/balloc.c
61423+++ b/fs/ext2/balloc.c
61424@@ -1184,10 +1184,10 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
61425
61426 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
61427 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
61428- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
61429+ if (free_blocks < root_blocks + 1 &&
61430 !uid_eq(sbi->s_resuid, current_fsuid()) &&
61431 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
61432- !in_group_p (sbi->s_resgid))) {
61433+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
61434 return 0;
61435 }
61436 return 1;
61437diff --git a/fs/ext2/super.c b/fs/ext2/super.c
61438index 170dc41..62f6b18 100644
61439--- a/fs/ext2/super.c
61440+++ b/fs/ext2/super.c
61441@@ -264,10 +264,8 @@ static int ext2_show_options(struct seq_file *seq, struct dentry *root)
61442 #ifdef CONFIG_EXT2_FS_XATTR
61443 if (test_opt(sb, XATTR_USER))
61444 seq_puts(seq, ",user_xattr");
61445- if (!test_opt(sb, XATTR_USER) &&
61446- (def_mount_opts & EXT2_DEFM_XATTR_USER)) {
61447+ if (!test_opt(sb, XATTR_USER))
61448 seq_puts(seq, ",nouser_xattr");
61449- }
61450 #endif
61451
61452 #ifdef CONFIG_EXT2_FS_POSIX_ACL
61453@@ -841,8 +839,8 @@ static int ext2_fill_super(struct super_block *sb, void *data, int silent)
61454 if (def_mount_opts & EXT2_DEFM_UID16)
61455 set_opt(sbi->s_mount_opt, NO_UID32);
61456 #ifdef CONFIG_EXT2_FS_XATTR
61457- if (def_mount_opts & EXT2_DEFM_XATTR_USER)
61458- set_opt(sbi->s_mount_opt, XATTR_USER);
61459+ /* always enable user xattrs */
61460+ set_opt(sbi->s_mount_opt, XATTR_USER);
61461 #endif
61462 #ifdef CONFIG_EXT2_FS_POSIX_ACL
61463 if (def_mount_opts & EXT2_DEFM_ACL)
61464diff --git a/fs/ext2/xattr.c b/fs/ext2/xattr.c
61465index 9142614..97484fa 100644
61466--- a/fs/ext2/xattr.c
61467+++ b/fs/ext2/xattr.c
61468@@ -247,7 +247,7 @@ ext2_xattr_list(struct dentry *dentry, char *buffer, size_t buffer_size)
61469 struct buffer_head *bh = NULL;
61470 struct ext2_xattr_entry *entry;
61471 char *end;
61472- size_t rest = buffer_size;
61473+ size_t rest = buffer_size, total_size = 0;
61474 int error;
61475
61476 ea_idebug(inode, "buffer=%p, buffer_size=%ld",
61477@@ -305,9 +305,10 @@ bad_block: ext2_error(inode->i_sb, "ext2_xattr_list",
61478 buffer += size;
61479 }
61480 rest -= size;
61481+ total_size += size;
61482 }
61483 }
61484- error = buffer_size - rest; /* total size */
61485+ error = total_size;
61486
61487 cleanup:
61488 brelse(bh);
61489diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
61490index 158b5d4..2432610 100644
61491--- a/fs/ext3/balloc.c
61492+++ b/fs/ext3/balloc.c
61493@@ -1438,10 +1438,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
61494
61495 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
61496 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
61497- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
61498+ if (free_blocks < root_blocks + 1 &&
61499 !use_reservation && !uid_eq(sbi->s_resuid, current_fsuid()) &&
61500 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
61501- !in_group_p (sbi->s_resgid))) {
61502+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
61503 return 0;
61504 }
61505 return 1;
61506diff --git a/fs/ext3/super.c b/fs/ext3/super.c
61507index eb742d0..c19f705 100644
61508--- a/fs/ext3/super.c
61509+++ b/fs/ext3/super.c
61510@@ -649,10 +649,8 @@ static int ext3_show_options(struct seq_file *seq, struct dentry *root)
61511 #ifdef CONFIG_EXT3_FS_XATTR
61512 if (test_opt(sb, XATTR_USER))
61513 seq_puts(seq, ",user_xattr");
61514- if (!test_opt(sb, XATTR_USER) &&
61515- (def_mount_opts & EXT3_DEFM_XATTR_USER)) {
61516+ if (!test_opt(sb, XATTR_USER))
61517 seq_puts(seq, ",nouser_xattr");
61518- }
61519 #endif
61520 #ifdef CONFIG_EXT3_FS_POSIX_ACL
61521 if (test_opt(sb, POSIX_ACL))
61522@@ -1749,8 +1747,8 @@ static int ext3_fill_super (struct super_block *sb, void *data, int silent)
61523 if (def_mount_opts & EXT3_DEFM_UID16)
61524 set_opt(sbi->s_mount_opt, NO_UID32);
61525 #ifdef CONFIG_EXT3_FS_XATTR
61526- if (def_mount_opts & EXT3_DEFM_XATTR_USER)
61527- set_opt(sbi->s_mount_opt, XATTR_USER);
61528+ /* always enable user xattrs */
61529+ set_opt(sbi->s_mount_opt, XATTR_USER);
61530 #endif
61531 #ifdef CONFIG_EXT3_FS_POSIX_ACL
61532 if (def_mount_opts & EXT3_DEFM_ACL)
61533diff --git a/fs/ext3/xattr.c b/fs/ext3/xattr.c
61534index c6874be..f8a6ae8 100644
61535--- a/fs/ext3/xattr.c
61536+++ b/fs/ext3/xattr.c
61537@@ -330,7 +330,7 @@ static int
61538 ext3_xattr_list_entries(struct dentry *dentry, struct ext3_xattr_entry *entry,
61539 char *buffer, size_t buffer_size)
61540 {
61541- size_t rest = buffer_size;
61542+ size_t rest = buffer_size, total_size = 0;
61543
61544 for (; !IS_LAST_ENTRY(entry); entry = EXT3_XATTR_NEXT(entry)) {
61545 const struct xattr_handler *handler =
61546@@ -347,9 +347,10 @@ ext3_xattr_list_entries(struct dentry *dentry, struct ext3_xattr_entry *entry,
61547 buffer += size;
61548 }
61549 rest -= size;
61550+ total_size += size;
61551 }
61552 }
61553- return buffer_size - rest;
61554+ return total_size;
61555 }
61556
61557 static int
61558diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
61559index 83a6f49..d4e4d03 100644
61560--- a/fs/ext4/balloc.c
61561+++ b/fs/ext4/balloc.c
61562@@ -557,8 +557,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
61563 /* Hm, nope. Are (enough) root reserved clusters available? */
61564 if (uid_eq(sbi->s_resuid, current_fsuid()) ||
61565 (!gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) && in_group_p(sbi->s_resgid)) ||
61566- capable(CAP_SYS_RESOURCE) ||
61567- (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
61568+ (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
61569+ capable_nolog(CAP_SYS_RESOURCE)) {
61570
61571 if (free_clusters >= (nclusters + dirty_clusters +
61572 resv_clusters))
61573diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
61574index c55a1fa..9904ebb 100644
61575--- a/fs/ext4/ext4.h
61576+++ b/fs/ext4/ext4.h
61577@@ -1279,19 +1279,19 @@ struct ext4_sb_info {
61578 unsigned long s_mb_last_start;
61579
61580 /* stats for buddy allocator */
61581- atomic_t s_bal_reqs; /* number of reqs with len > 1 */
61582- atomic_t s_bal_success; /* we found long enough chunks */
61583- atomic_t s_bal_allocated; /* in blocks */
61584- atomic_t s_bal_ex_scanned; /* total extents scanned */
61585- atomic_t s_bal_goals; /* goal hits */
61586- atomic_t s_bal_breaks; /* too long searches */
61587- atomic_t s_bal_2orders; /* 2^order hits */
61588+ atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
61589+ atomic_unchecked_t s_bal_success; /* we found long enough chunks */
61590+ atomic_unchecked_t s_bal_allocated; /* in blocks */
61591+ atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
61592+ atomic_unchecked_t s_bal_goals; /* goal hits */
61593+ atomic_unchecked_t s_bal_breaks; /* too long searches */
61594+ atomic_unchecked_t s_bal_2orders; /* 2^order hits */
61595 spinlock_t s_bal_lock;
61596 unsigned long s_mb_buddies_generated;
61597 unsigned long long s_mb_generation_time;
61598- atomic_t s_mb_lost_chunks;
61599- atomic_t s_mb_preallocated;
61600- atomic_t s_mb_discarded;
61601+ atomic_unchecked_t s_mb_lost_chunks;
61602+ atomic_unchecked_t s_mb_preallocated;
61603+ atomic_unchecked_t s_mb_discarded;
61604 atomic_t s_lock_busy;
61605
61606 /* locality groups */
61607diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
61608index dbfe15c..9a6ee8d 100644
61609--- a/fs/ext4/mballoc.c
61610+++ b/fs/ext4/mballoc.c
61611@@ -1901,7 +1901,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
61612 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
61613
61614 if (EXT4_SB(sb)->s_mb_stats)
61615- atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
61616+ atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
61617
61618 break;
61619 }
61620@@ -2211,7 +2211,7 @@ repeat:
61621 ac->ac_status = AC_STATUS_CONTINUE;
61622 ac->ac_flags |= EXT4_MB_HINT_FIRST;
61623 cr = 3;
61624- atomic_inc(&sbi->s_mb_lost_chunks);
61625+ atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
61626 goto repeat;
61627 }
61628 }
61629@@ -2717,25 +2717,25 @@ int ext4_mb_release(struct super_block *sb)
61630 if (sbi->s_mb_stats) {
61631 ext4_msg(sb, KERN_INFO,
61632 "mballoc: %u blocks %u reqs (%u success)",
61633- atomic_read(&sbi->s_bal_allocated),
61634- atomic_read(&sbi->s_bal_reqs),
61635- atomic_read(&sbi->s_bal_success));
61636+ atomic_read_unchecked(&sbi->s_bal_allocated),
61637+ atomic_read_unchecked(&sbi->s_bal_reqs),
61638+ atomic_read_unchecked(&sbi->s_bal_success));
61639 ext4_msg(sb, KERN_INFO,
61640 "mballoc: %u extents scanned, %u goal hits, "
61641 "%u 2^N hits, %u breaks, %u lost",
61642- atomic_read(&sbi->s_bal_ex_scanned),
61643- atomic_read(&sbi->s_bal_goals),
61644- atomic_read(&sbi->s_bal_2orders),
61645- atomic_read(&sbi->s_bal_breaks),
61646- atomic_read(&sbi->s_mb_lost_chunks));
61647+ atomic_read_unchecked(&sbi->s_bal_ex_scanned),
61648+ atomic_read_unchecked(&sbi->s_bal_goals),
61649+ atomic_read_unchecked(&sbi->s_bal_2orders),
61650+ atomic_read_unchecked(&sbi->s_bal_breaks),
61651+ atomic_read_unchecked(&sbi->s_mb_lost_chunks));
61652 ext4_msg(sb, KERN_INFO,
61653 "mballoc: %lu generated and it took %Lu",
61654 sbi->s_mb_buddies_generated,
61655 sbi->s_mb_generation_time);
61656 ext4_msg(sb, KERN_INFO,
61657 "mballoc: %u preallocated, %u discarded",
61658- atomic_read(&sbi->s_mb_preallocated),
61659- atomic_read(&sbi->s_mb_discarded));
61660+ atomic_read_unchecked(&sbi->s_mb_preallocated),
61661+ atomic_read_unchecked(&sbi->s_mb_discarded));
61662 }
61663
61664 free_percpu(sbi->s_locality_groups);
61665@@ -3191,16 +3191,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
61666 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
61667
61668 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
61669- atomic_inc(&sbi->s_bal_reqs);
61670- atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
61671+ atomic_inc_unchecked(&sbi->s_bal_reqs);
61672+ atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
61673 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
61674- atomic_inc(&sbi->s_bal_success);
61675- atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
61676+ atomic_inc_unchecked(&sbi->s_bal_success);
61677+ atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
61678 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
61679 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
61680- atomic_inc(&sbi->s_bal_goals);
61681+ atomic_inc_unchecked(&sbi->s_bal_goals);
61682 if (ac->ac_found > sbi->s_mb_max_to_scan)
61683- atomic_inc(&sbi->s_bal_breaks);
61684+ atomic_inc_unchecked(&sbi->s_bal_breaks);
61685 }
61686
61687 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
61688@@ -3627,7 +3627,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
61689 trace_ext4_mb_new_inode_pa(ac, pa);
61690
61691 ext4_mb_use_inode_pa(ac, pa);
61692- atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
61693+ atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
61694
61695 ei = EXT4_I(ac->ac_inode);
61696 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
61697@@ -3687,7 +3687,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
61698 trace_ext4_mb_new_group_pa(ac, pa);
61699
61700 ext4_mb_use_group_pa(ac, pa);
61701- atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
61702+ atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
61703
61704 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
61705 lg = ac->ac_lg;
61706@@ -3776,7 +3776,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
61707 * from the bitmap and continue.
61708 */
61709 }
61710- atomic_add(free, &sbi->s_mb_discarded);
61711+ atomic_add_unchecked(free, &sbi->s_mb_discarded);
61712
61713 return err;
61714 }
61715@@ -3794,7 +3794,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
61716 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
61717 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
61718 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
61719- atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
61720+ atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
61721 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
61722
61723 return 0;
61724diff --git a/fs/ext4/mmp.c b/fs/ext4/mmp.c
61725index 8313ca3..8a37d08 100644
61726--- a/fs/ext4/mmp.c
61727+++ b/fs/ext4/mmp.c
61728@@ -111,7 +111,7 @@ static int read_mmp_block(struct super_block *sb, struct buffer_head **bh,
61729 void __dump_mmp_msg(struct super_block *sb, struct mmp_struct *mmp,
61730 const char *function, unsigned int line, const char *msg)
61731 {
61732- __ext4_warning(sb, function, line, msg);
61733+ __ext4_warning(sb, function, line, "%s", msg);
61734 __ext4_warning(sb, function, line,
61735 "MMP failure info: last update time: %llu, last update "
61736 "node: %s, last update device: %s\n",
61737diff --git a/fs/ext4/super.c b/fs/ext4/super.c
61738index 2c9e686..6a40edc 100644
61739--- a/fs/ext4/super.c
61740+++ b/fs/ext4/super.c
61741@@ -1254,7 +1254,7 @@ static ext4_fsblk_t get_sb_block(void **data)
61742 }
61743
61744 #define DEFAULT_JOURNAL_IOPRIO (IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, 3))
61745-static char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
61746+static const char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
61747 "Contact linux-ext4@vger.kernel.org if you think we should keep it.\n";
61748
61749 #ifdef CONFIG_QUOTA
61750@@ -2434,7 +2434,7 @@ struct ext4_attr {
61751 int offset;
61752 int deprecated_val;
61753 } u;
61754-};
61755+} __do_const;
61756
61757 static int parse_strtoull(const char *buf,
61758 unsigned long long max, unsigned long long *value)
61759diff --git a/fs/ext4/xattr.c b/fs/ext4/xattr.c
61760index 1e09fc7..0400dd4 100644
61761--- a/fs/ext4/xattr.c
61762+++ b/fs/ext4/xattr.c
61763@@ -399,7 +399,7 @@ static int
61764 ext4_xattr_list_entries(struct dentry *dentry, struct ext4_xattr_entry *entry,
61765 char *buffer, size_t buffer_size)
61766 {
61767- size_t rest = buffer_size;
61768+ size_t rest = buffer_size, total_size = 0;
61769
61770 for (; !IS_LAST_ENTRY(entry); entry = EXT4_XATTR_NEXT(entry)) {
61771 const struct xattr_handler *handler =
61772@@ -416,9 +416,10 @@ ext4_xattr_list_entries(struct dentry *dentry, struct ext4_xattr_entry *entry,
61773 buffer += size;
61774 }
61775 rest -= size;
61776+ total_size += size;
61777 }
61778 }
61779- return buffer_size - rest;
61780+ return total_size;
61781 }
61782
61783 static int
61784diff --git a/fs/fcntl.c b/fs/fcntl.c
61785index 99d440a..eb979d1 100644
61786--- a/fs/fcntl.c
61787+++ b/fs/fcntl.c
61788@@ -102,6 +102,10 @@ void __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
61789 int force)
61790 {
61791 security_file_set_fowner(filp);
61792+ if (gr_handle_chroot_fowner(pid, type))
61793+ return;
61794+ if (gr_check_protected_task_fowner(pid, type))
61795+ return;
61796 f_modown(filp, pid, type, force);
61797 }
61798 EXPORT_SYMBOL(__f_setown);
61799diff --git a/fs/fhandle.c b/fs/fhandle.c
61800index 999ff5c..ac037c9 100644
61801--- a/fs/fhandle.c
61802+++ b/fs/fhandle.c
61803@@ -8,6 +8,7 @@
61804 #include <linux/fs_struct.h>
61805 #include <linux/fsnotify.h>
61806 #include <linux/personality.h>
61807+#include <linux/grsecurity.h>
61808 #include <asm/uaccess.h>
61809 #include "internal.h"
61810 #include "mount.h"
61811@@ -67,8 +68,7 @@ static long do_sys_name_to_handle(struct path *path,
61812 } else
61813 retval = 0;
61814 /* copy the mount id */
61815- if (copy_to_user(mnt_id, &real_mount(path->mnt)->mnt_id,
61816- sizeof(*mnt_id)) ||
61817+ if (put_user(real_mount(path->mnt)->mnt_id, mnt_id) ||
61818 copy_to_user(ufh, handle,
61819 sizeof(struct file_handle) + handle_bytes))
61820 retval = -EFAULT;
61821@@ -175,7 +175,7 @@ static int handle_to_path(int mountdirfd, struct file_handle __user *ufh,
61822 * the directory. Ideally we would like CAP_DAC_SEARCH.
61823 * But we don't have that
61824 */
61825- if (!capable(CAP_DAC_READ_SEARCH)) {
61826+ if (!capable(CAP_DAC_READ_SEARCH) || !gr_chroot_fhandle()) {
61827 retval = -EPERM;
61828 goto out_err;
61829 }
61830diff --git a/fs/file.c b/fs/file.c
61831index ab3eb6a..8de2392 100644
61832--- a/fs/file.c
61833+++ b/fs/file.c
61834@@ -16,6 +16,7 @@
61835 #include <linux/slab.h>
61836 #include <linux/vmalloc.h>
61837 #include <linux/file.h>
61838+#include <linux/security.h>
61839 #include <linux/fdtable.h>
61840 #include <linux/bitops.h>
61841 #include <linux/interrupt.h>
61842@@ -139,7 +140,7 @@ out:
61843 * Return <0 error code on error; 1 on successful completion.
61844 * The files->file_lock should be held on entry, and will be held on exit.
61845 */
61846-static int expand_fdtable(struct files_struct *files, int nr)
61847+static int expand_fdtable(struct files_struct *files, unsigned int nr)
61848 __releases(files->file_lock)
61849 __acquires(files->file_lock)
61850 {
61851@@ -184,7 +185,7 @@ static int expand_fdtable(struct files_struct *files, int nr)
61852 * expanded and execution may have blocked.
61853 * The files->file_lock should be held on entry, and will be held on exit.
61854 */
61855-static int expand_files(struct files_struct *files, int nr)
61856+static int expand_files(struct files_struct *files, unsigned int nr)
61857 {
61858 struct fdtable *fdt;
61859
61860@@ -800,6 +801,7 @@ int replace_fd(unsigned fd, struct file *file, unsigned flags)
61861 if (!file)
61862 return __close_fd(files, fd);
61863
61864+ gr_learn_resource(current, RLIMIT_NOFILE, fd, 0);
61865 if (fd >= rlimit(RLIMIT_NOFILE))
61866 return -EBADF;
61867
61868@@ -826,6 +828,7 @@ SYSCALL_DEFINE3(dup3, unsigned int, oldfd, unsigned int, newfd, int, flags)
61869 if (unlikely(oldfd == newfd))
61870 return -EINVAL;
61871
61872+ gr_learn_resource(current, RLIMIT_NOFILE, newfd, 0);
61873 if (newfd >= rlimit(RLIMIT_NOFILE))
61874 return -EBADF;
61875
61876@@ -881,6 +884,7 @@ SYSCALL_DEFINE1(dup, unsigned int, fildes)
61877 int f_dupfd(unsigned int from, struct file *file, unsigned flags)
61878 {
61879 int err;
61880+ gr_learn_resource(current, RLIMIT_NOFILE, from, 0);
61881 if (from >= rlimit(RLIMIT_NOFILE))
61882 return -EINVAL;
61883 err = alloc_fd(from, flags);
61884diff --git a/fs/filesystems.c b/fs/filesystems.c
61885index 5797d45..7d7d79a 100644
61886--- a/fs/filesystems.c
61887+++ b/fs/filesystems.c
61888@@ -275,7 +275,11 @@ struct file_system_type *get_fs_type(const char *name)
61889 int len = dot ? dot - name : strlen(name);
61890
61891 fs = __get_fs_type(name, len);
61892+#ifdef CONFIG_GRKERNSEC_MODHARDEN
61893+ if (!fs && (___request_module(true, "grsec_modharden_fs", "fs-%.*s", len, name) == 0))
61894+#else
61895 if (!fs && (request_module("fs-%.*s", len, name) == 0))
61896+#endif
61897 fs = __get_fs_type(name, len);
61898
61899 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
61900diff --git a/fs/fs_struct.c b/fs/fs_struct.c
61901index 7dca743..543d620 100644
61902--- a/fs/fs_struct.c
61903+++ b/fs/fs_struct.c
61904@@ -4,6 +4,7 @@
61905 #include <linux/path.h>
61906 #include <linux/slab.h>
61907 #include <linux/fs_struct.h>
61908+#include <linux/grsecurity.h>
61909 #include "internal.h"
61910
61911 /*
61912@@ -19,6 +20,7 @@ void set_fs_root(struct fs_struct *fs, const struct path *path)
61913 write_seqcount_begin(&fs->seq);
61914 old_root = fs->root;
61915 fs->root = *path;
61916+ gr_set_chroot_entries(current, path);
61917 write_seqcount_end(&fs->seq);
61918 spin_unlock(&fs->lock);
61919 if (old_root.dentry)
61920@@ -67,6 +69,10 @@ void chroot_fs_refs(const struct path *old_root, const struct path *new_root)
61921 int hits = 0;
61922 spin_lock(&fs->lock);
61923 write_seqcount_begin(&fs->seq);
61924+ /* this root replacement is only done by pivot_root,
61925+ leave grsec's chroot tagging alone for this task
61926+ so that a pivoted root isn't treated as a chroot
61927+ */
61928 hits += replace_path(&fs->root, old_root, new_root);
61929 hits += replace_path(&fs->pwd, old_root, new_root);
61930 write_seqcount_end(&fs->seq);
61931@@ -99,7 +105,8 @@ void exit_fs(struct task_struct *tsk)
61932 task_lock(tsk);
61933 spin_lock(&fs->lock);
61934 tsk->fs = NULL;
61935- kill = !--fs->users;
61936+ gr_clear_chroot_entries(tsk);
61937+ kill = !atomic_dec_return(&fs->users);
61938 spin_unlock(&fs->lock);
61939 task_unlock(tsk);
61940 if (kill)
61941@@ -112,7 +119,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
61942 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
61943 /* We don't need to lock fs - think why ;-) */
61944 if (fs) {
61945- fs->users = 1;
61946+ atomic_set(&fs->users, 1);
61947 fs->in_exec = 0;
61948 spin_lock_init(&fs->lock);
61949 seqcount_init(&fs->seq);
61950@@ -121,6 +128,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
61951 spin_lock(&old->lock);
61952 fs->root = old->root;
61953 path_get(&fs->root);
61954+ /* instead of calling gr_set_chroot_entries here,
61955+ we call it from every caller of this function
61956+ */
61957 fs->pwd = old->pwd;
61958 path_get(&fs->pwd);
61959 spin_unlock(&old->lock);
61960@@ -139,8 +149,9 @@ int unshare_fs_struct(void)
61961
61962 task_lock(current);
61963 spin_lock(&fs->lock);
61964- kill = !--fs->users;
61965+ kill = !atomic_dec_return(&fs->users);
61966 current->fs = new_fs;
61967+ gr_set_chroot_entries(current, &new_fs->root);
61968 spin_unlock(&fs->lock);
61969 task_unlock(current);
61970
61971@@ -153,13 +164,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
61972
61973 int current_umask(void)
61974 {
61975- return current->fs->umask;
61976+ return current->fs->umask | gr_acl_umask();
61977 }
61978 EXPORT_SYMBOL(current_umask);
61979
61980 /* to be mentioned only in INIT_TASK */
61981 struct fs_struct init_fs = {
61982- .users = 1,
61983+ .users = ATOMIC_INIT(1),
61984 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
61985 .seq = SEQCNT_ZERO(init_fs.seq),
61986 .umask = 0022,
61987diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
61988index 89acec7..a575262 100644
61989--- a/fs/fscache/cookie.c
61990+++ b/fs/fscache/cookie.c
61991@@ -19,7 +19,7 @@
61992
61993 struct kmem_cache *fscache_cookie_jar;
61994
61995-static atomic_t fscache_object_debug_id = ATOMIC_INIT(0);
61996+static atomic_unchecked_t fscache_object_debug_id = ATOMIC_INIT(0);
61997
61998 static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie);
61999 static int fscache_alloc_object(struct fscache_cache *cache,
62000@@ -69,11 +69,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
62001 parent ? (char *) parent->def->name : "<no-parent>",
62002 def->name, netfs_data, enable);
62003
62004- fscache_stat(&fscache_n_acquires);
62005+ fscache_stat_unchecked(&fscache_n_acquires);
62006
62007 /* if there's no parent cookie, then we don't create one here either */
62008 if (!parent) {
62009- fscache_stat(&fscache_n_acquires_null);
62010+ fscache_stat_unchecked(&fscache_n_acquires_null);
62011 _leave(" [no parent]");
62012 return NULL;
62013 }
62014@@ -88,7 +88,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
62015 /* allocate and initialise a cookie */
62016 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
62017 if (!cookie) {
62018- fscache_stat(&fscache_n_acquires_oom);
62019+ fscache_stat_unchecked(&fscache_n_acquires_oom);
62020 _leave(" [ENOMEM]");
62021 return NULL;
62022 }
62023@@ -115,13 +115,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
62024
62025 switch (cookie->def->type) {
62026 case FSCACHE_COOKIE_TYPE_INDEX:
62027- fscache_stat(&fscache_n_cookie_index);
62028+ fscache_stat_unchecked(&fscache_n_cookie_index);
62029 break;
62030 case FSCACHE_COOKIE_TYPE_DATAFILE:
62031- fscache_stat(&fscache_n_cookie_data);
62032+ fscache_stat_unchecked(&fscache_n_cookie_data);
62033 break;
62034 default:
62035- fscache_stat(&fscache_n_cookie_special);
62036+ fscache_stat_unchecked(&fscache_n_cookie_special);
62037 break;
62038 }
62039
62040@@ -135,7 +135,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
62041 } else {
62042 atomic_dec(&parent->n_children);
62043 __fscache_cookie_put(cookie);
62044- fscache_stat(&fscache_n_acquires_nobufs);
62045+ fscache_stat_unchecked(&fscache_n_acquires_nobufs);
62046 _leave(" = NULL");
62047 return NULL;
62048 }
62049@@ -144,7 +144,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
62050 }
62051 }
62052
62053- fscache_stat(&fscache_n_acquires_ok);
62054+ fscache_stat_unchecked(&fscache_n_acquires_ok);
62055 _leave(" = %p", cookie);
62056 return cookie;
62057 }
62058@@ -213,7 +213,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
62059 cache = fscache_select_cache_for_object(cookie->parent);
62060 if (!cache) {
62061 up_read(&fscache_addremove_sem);
62062- fscache_stat(&fscache_n_acquires_no_cache);
62063+ fscache_stat_unchecked(&fscache_n_acquires_no_cache);
62064 _leave(" = -ENOMEDIUM [no cache]");
62065 return -ENOMEDIUM;
62066 }
62067@@ -297,14 +297,14 @@ static int fscache_alloc_object(struct fscache_cache *cache,
62068 object = cache->ops->alloc_object(cache, cookie);
62069 fscache_stat_d(&fscache_n_cop_alloc_object);
62070 if (IS_ERR(object)) {
62071- fscache_stat(&fscache_n_object_no_alloc);
62072+ fscache_stat_unchecked(&fscache_n_object_no_alloc);
62073 ret = PTR_ERR(object);
62074 goto error;
62075 }
62076
62077- fscache_stat(&fscache_n_object_alloc);
62078+ fscache_stat_unchecked(&fscache_n_object_alloc);
62079
62080- object->debug_id = atomic_inc_return(&fscache_object_debug_id);
62081+ object->debug_id = atomic_inc_return_unchecked(&fscache_object_debug_id);
62082
62083 _debug("ALLOC OBJ%x: %s {%lx}",
62084 object->debug_id, cookie->def->name, object->events);
62085@@ -418,7 +418,7 @@ void __fscache_invalidate(struct fscache_cookie *cookie)
62086
62087 _enter("{%s}", cookie->def->name);
62088
62089- fscache_stat(&fscache_n_invalidates);
62090+ fscache_stat_unchecked(&fscache_n_invalidates);
62091
62092 /* Only permit invalidation of data files. Invalidating an index will
62093 * require the caller to release all its attachments to the tree rooted
62094@@ -476,10 +476,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
62095 {
62096 struct fscache_object *object;
62097
62098- fscache_stat(&fscache_n_updates);
62099+ fscache_stat_unchecked(&fscache_n_updates);
62100
62101 if (!cookie) {
62102- fscache_stat(&fscache_n_updates_null);
62103+ fscache_stat_unchecked(&fscache_n_updates_null);
62104 _leave(" [no cookie]");
62105 return;
62106 }
62107@@ -580,12 +580,12 @@ EXPORT_SYMBOL(__fscache_disable_cookie);
62108 */
62109 void __fscache_relinquish_cookie(struct fscache_cookie *cookie, bool retire)
62110 {
62111- fscache_stat(&fscache_n_relinquishes);
62112+ fscache_stat_unchecked(&fscache_n_relinquishes);
62113 if (retire)
62114- fscache_stat(&fscache_n_relinquishes_retire);
62115+ fscache_stat_unchecked(&fscache_n_relinquishes_retire);
62116
62117 if (!cookie) {
62118- fscache_stat(&fscache_n_relinquishes_null);
62119+ fscache_stat_unchecked(&fscache_n_relinquishes_null);
62120 _leave(" [no cookie]");
62121 return;
62122 }
62123@@ -686,7 +686,7 @@ int __fscache_check_consistency(struct fscache_cookie *cookie)
62124 if (test_bit(FSCACHE_IOERROR, &object->cache->flags))
62125 goto inconsistent;
62126
62127- op->debug_id = atomic_inc_return(&fscache_op_debug_id);
62128+ op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
62129
62130 __fscache_use_cookie(cookie);
62131 if (fscache_submit_op(object, op) < 0)
62132diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
62133index 7872a62..d91b19f 100644
62134--- a/fs/fscache/internal.h
62135+++ b/fs/fscache/internal.h
62136@@ -137,8 +137,8 @@ extern void fscache_operation_gc(struct work_struct *);
62137 extern int fscache_wait_for_deferred_lookup(struct fscache_cookie *);
62138 extern int fscache_wait_for_operation_activation(struct fscache_object *,
62139 struct fscache_operation *,
62140- atomic_t *,
62141- atomic_t *,
62142+ atomic_unchecked_t *,
62143+ atomic_unchecked_t *,
62144 void (*)(struct fscache_operation *));
62145 extern void fscache_invalidate_writes(struct fscache_cookie *);
62146
62147@@ -157,101 +157,101 @@ extern void fscache_proc_cleanup(void);
62148 * stats.c
62149 */
62150 #ifdef CONFIG_FSCACHE_STATS
62151-extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
62152-extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
62153+extern atomic_unchecked_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
62154+extern atomic_unchecked_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
62155
62156-extern atomic_t fscache_n_op_pend;
62157-extern atomic_t fscache_n_op_run;
62158-extern atomic_t fscache_n_op_enqueue;
62159-extern atomic_t fscache_n_op_deferred_release;
62160-extern atomic_t fscache_n_op_release;
62161-extern atomic_t fscache_n_op_gc;
62162-extern atomic_t fscache_n_op_cancelled;
62163-extern atomic_t fscache_n_op_rejected;
62164+extern atomic_unchecked_t fscache_n_op_pend;
62165+extern atomic_unchecked_t fscache_n_op_run;
62166+extern atomic_unchecked_t fscache_n_op_enqueue;
62167+extern atomic_unchecked_t fscache_n_op_deferred_release;
62168+extern atomic_unchecked_t fscache_n_op_release;
62169+extern atomic_unchecked_t fscache_n_op_gc;
62170+extern atomic_unchecked_t fscache_n_op_cancelled;
62171+extern atomic_unchecked_t fscache_n_op_rejected;
62172
62173-extern atomic_t fscache_n_attr_changed;
62174-extern atomic_t fscache_n_attr_changed_ok;
62175-extern atomic_t fscache_n_attr_changed_nobufs;
62176-extern atomic_t fscache_n_attr_changed_nomem;
62177-extern atomic_t fscache_n_attr_changed_calls;
62178+extern atomic_unchecked_t fscache_n_attr_changed;
62179+extern atomic_unchecked_t fscache_n_attr_changed_ok;
62180+extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
62181+extern atomic_unchecked_t fscache_n_attr_changed_nomem;
62182+extern atomic_unchecked_t fscache_n_attr_changed_calls;
62183
62184-extern atomic_t fscache_n_allocs;
62185-extern atomic_t fscache_n_allocs_ok;
62186-extern atomic_t fscache_n_allocs_wait;
62187-extern atomic_t fscache_n_allocs_nobufs;
62188-extern atomic_t fscache_n_allocs_intr;
62189-extern atomic_t fscache_n_allocs_object_dead;
62190-extern atomic_t fscache_n_alloc_ops;
62191-extern atomic_t fscache_n_alloc_op_waits;
62192+extern atomic_unchecked_t fscache_n_allocs;
62193+extern atomic_unchecked_t fscache_n_allocs_ok;
62194+extern atomic_unchecked_t fscache_n_allocs_wait;
62195+extern atomic_unchecked_t fscache_n_allocs_nobufs;
62196+extern atomic_unchecked_t fscache_n_allocs_intr;
62197+extern atomic_unchecked_t fscache_n_allocs_object_dead;
62198+extern atomic_unchecked_t fscache_n_alloc_ops;
62199+extern atomic_unchecked_t fscache_n_alloc_op_waits;
62200
62201-extern atomic_t fscache_n_retrievals;
62202-extern atomic_t fscache_n_retrievals_ok;
62203-extern atomic_t fscache_n_retrievals_wait;
62204-extern atomic_t fscache_n_retrievals_nodata;
62205-extern atomic_t fscache_n_retrievals_nobufs;
62206-extern atomic_t fscache_n_retrievals_intr;
62207-extern atomic_t fscache_n_retrievals_nomem;
62208-extern atomic_t fscache_n_retrievals_object_dead;
62209-extern atomic_t fscache_n_retrieval_ops;
62210-extern atomic_t fscache_n_retrieval_op_waits;
62211+extern atomic_unchecked_t fscache_n_retrievals;
62212+extern atomic_unchecked_t fscache_n_retrievals_ok;
62213+extern atomic_unchecked_t fscache_n_retrievals_wait;
62214+extern atomic_unchecked_t fscache_n_retrievals_nodata;
62215+extern atomic_unchecked_t fscache_n_retrievals_nobufs;
62216+extern atomic_unchecked_t fscache_n_retrievals_intr;
62217+extern atomic_unchecked_t fscache_n_retrievals_nomem;
62218+extern atomic_unchecked_t fscache_n_retrievals_object_dead;
62219+extern atomic_unchecked_t fscache_n_retrieval_ops;
62220+extern atomic_unchecked_t fscache_n_retrieval_op_waits;
62221
62222-extern atomic_t fscache_n_stores;
62223-extern atomic_t fscache_n_stores_ok;
62224-extern atomic_t fscache_n_stores_again;
62225-extern atomic_t fscache_n_stores_nobufs;
62226-extern atomic_t fscache_n_stores_oom;
62227-extern atomic_t fscache_n_store_ops;
62228-extern atomic_t fscache_n_store_calls;
62229-extern atomic_t fscache_n_store_pages;
62230-extern atomic_t fscache_n_store_radix_deletes;
62231-extern atomic_t fscache_n_store_pages_over_limit;
62232+extern atomic_unchecked_t fscache_n_stores;
62233+extern atomic_unchecked_t fscache_n_stores_ok;
62234+extern atomic_unchecked_t fscache_n_stores_again;
62235+extern atomic_unchecked_t fscache_n_stores_nobufs;
62236+extern atomic_unchecked_t fscache_n_stores_oom;
62237+extern atomic_unchecked_t fscache_n_store_ops;
62238+extern atomic_unchecked_t fscache_n_store_calls;
62239+extern atomic_unchecked_t fscache_n_store_pages;
62240+extern atomic_unchecked_t fscache_n_store_radix_deletes;
62241+extern atomic_unchecked_t fscache_n_store_pages_over_limit;
62242
62243-extern atomic_t fscache_n_store_vmscan_not_storing;
62244-extern atomic_t fscache_n_store_vmscan_gone;
62245-extern atomic_t fscache_n_store_vmscan_busy;
62246-extern atomic_t fscache_n_store_vmscan_cancelled;
62247-extern atomic_t fscache_n_store_vmscan_wait;
62248+extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
62249+extern atomic_unchecked_t fscache_n_store_vmscan_gone;
62250+extern atomic_unchecked_t fscache_n_store_vmscan_busy;
62251+extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
62252+extern atomic_unchecked_t fscache_n_store_vmscan_wait;
62253
62254-extern atomic_t fscache_n_marks;
62255-extern atomic_t fscache_n_uncaches;
62256+extern atomic_unchecked_t fscache_n_marks;
62257+extern atomic_unchecked_t fscache_n_uncaches;
62258
62259-extern atomic_t fscache_n_acquires;
62260-extern atomic_t fscache_n_acquires_null;
62261-extern atomic_t fscache_n_acquires_no_cache;
62262-extern atomic_t fscache_n_acquires_ok;
62263-extern atomic_t fscache_n_acquires_nobufs;
62264-extern atomic_t fscache_n_acquires_oom;
62265+extern atomic_unchecked_t fscache_n_acquires;
62266+extern atomic_unchecked_t fscache_n_acquires_null;
62267+extern atomic_unchecked_t fscache_n_acquires_no_cache;
62268+extern atomic_unchecked_t fscache_n_acquires_ok;
62269+extern atomic_unchecked_t fscache_n_acquires_nobufs;
62270+extern atomic_unchecked_t fscache_n_acquires_oom;
62271
62272-extern atomic_t fscache_n_invalidates;
62273-extern atomic_t fscache_n_invalidates_run;
62274+extern atomic_unchecked_t fscache_n_invalidates;
62275+extern atomic_unchecked_t fscache_n_invalidates_run;
62276
62277-extern atomic_t fscache_n_updates;
62278-extern atomic_t fscache_n_updates_null;
62279-extern atomic_t fscache_n_updates_run;
62280+extern atomic_unchecked_t fscache_n_updates;
62281+extern atomic_unchecked_t fscache_n_updates_null;
62282+extern atomic_unchecked_t fscache_n_updates_run;
62283
62284-extern atomic_t fscache_n_relinquishes;
62285-extern atomic_t fscache_n_relinquishes_null;
62286-extern atomic_t fscache_n_relinquishes_waitcrt;
62287-extern atomic_t fscache_n_relinquishes_retire;
62288+extern atomic_unchecked_t fscache_n_relinquishes;
62289+extern atomic_unchecked_t fscache_n_relinquishes_null;
62290+extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
62291+extern atomic_unchecked_t fscache_n_relinquishes_retire;
62292
62293-extern atomic_t fscache_n_cookie_index;
62294-extern atomic_t fscache_n_cookie_data;
62295-extern atomic_t fscache_n_cookie_special;
62296+extern atomic_unchecked_t fscache_n_cookie_index;
62297+extern atomic_unchecked_t fscache_n_cookie_data;
62298+extern atomic_unchecked_t fscache_n_cookie_special;
62299
62300-extern atomic_t fscache_n_object_alloc;
62301-extern atomic_t fscache_n_object_no_alloc;
62302-extern atomic_t fscache_n_object_lookups;
62303-extern atomic_t fscache_n_object_lookups_negative;
62304-extern atomic_t fscache_n_object_lookups_positive;
62305-extern atomic_t fscache_n_object_lookups_timed_out;
62306-extern atomic_t fscache_n_object_created;
62307-extern atomic_t fscache_n_object_avail;
62308-extern atomic_t fscache_n_object_dead;
62309+extern atomic_unchecked_t fscache_n_object_alloc;
62310+extern atomic_unchecked_t fscache_n_object_no_alloc;
62311+extern atomic_unchecked_t fscache_n_object_lookups;
62312+extern atomic_unchecked_t fscache_n_object_lookups_negative;
62313+extern atomic_unchecked_t fscache_n_object_lookups_positive;
62314+extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
62315+extern atomic_unchecked_t fscache_n_object_created;
62316+extern atomic_unchecked_t fscache_n_object_avail;
62317+extern atomic_unchecked_t fscache_n_object_dead;
62318
62319-extern atomic_t fscache_n_checkaux_none;
62320-extern atomic_t fscache_n_checkaux_okay;
62321-extern atomic_t fscache_n_checkaux_update;
62322-extern atomic_t fscache_n_checkaux_obsolete;
62323+extern atomic_unchecked_t fscache_n_checkaux_none;
62324+extern atomic_unchecked_t fscache_n_checkaux_okay;
62325+extern atomic_unchecked_t fscache_n_checkaux_update;
62326+extern atomic_unchecked_t fscache_n_checkaux_obsolete;
62327
62328 extern atomic_t fscache_n_cop_alloc_object;
62329 extern atomic_t fscache_n_cop_lookup_object;
62330@@ -276,6 +276,11 @@ static inline void fscache_stat(atomic_t *stat)
62331 atomic_inc(stat);
62332 }
62333
62334+static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
62335+{
62336+ atomic_inc_unchecked(stat);
62337+}
62338+
62339 static inline void fscache_stat_d(atomic_t *stat)
62340 {
62341 atomic_dec(stat);
62342@@ -288,6 +293,7 @@ extern const struct file_operations fscache_stats_fops;
62343
62344 #define __fscache_stat(stat) (NULL)
62345 #define fscache_stat(stat) do {} while (0)
62346+#define fscache_stat_unchecked(stat) do {} while (0)
62347 #define fscache_stat_d(stat) do {} while (0)
62348 #endif
62349
62350diff --git a/fs/fscache/object.c b/fs/fscache/object.c
62351index da032da..0076ce7 100644
62352--- a/fs/fscache/object.c
62353+++ b/fs/fscache/object.c
62354@@ -454,7 +454,7 @@ static const struct fscache_state *fscache_look_up_object(struct fscache_object
62355 _debug("LOOKUP \"%s\" in \"%s\"",
62356 cookie->def->name, object->cache->tag->name);
62357
62358- fscache_stat(&fscache_n_object_lookups);
62359+ fscache_stat_unchecked(&fscache_n_object_lookups);
62360 fscache_stat(&fscache_n_cop_lookup_object);
62361 ret = object->cache->ops->lookup_object(object);
62362 fscache_stat_d(&fscache_n_cop_lookup_object);
62363@@ -464,7 +464,7 @@ static const struct fscache_state *fscache_look_up_object(struct fscache_object
62364 if (ret == -ETIMEDOUT) {
62365 /* probably stuck behind another object, so move this one to
62366 * the back of the queue */
62367- fscache_stat(&fscache_n_object_lookups_timed_out);
62368+ fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
62369 _leave(" [timeout]");
62370 return NO_TRANSIT;
62371 }
62372@@ -492,7 +492,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
62373 _enter("{OBJ%x,%s}", object->debug_id, object->state->name);
62374
62375 if (!test_and_set_bit(FSCACHE_OBJECT_IS_LOOKED_UP, &object->flags)) {
62376- fscache_stat(&fscache_n_object_lookups_negative);
62377+ fscache_stat_unchecked(&fscache_n_object_lookups_negative);
62378
62379 /* Allow write requests to begin stacking up and read requests to begin
62380 * returning ENODATA.
62381@@ -527,7 +527,7 @@ void fscache_obtained_object(struct fscache_object *object)
62382 /* if we were still looking up, then we must have a positive lookup
62383 * result, in which case there may be data available */
62384 if (!test_and_set_bit(FSCACHE_OBJECT_IS_LOOKED_UP, &object->flags)) {
62385- fscache_stat(&fscache_n_object_lookups_positive);
62386+ fscache_stat_unchecked(&fscache_n_object_lookups_positive);
62387
62388 /* We do (presumably) have data */
62389 clear_bit_unlock(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
62390@@ -539,7 +539,7 @@ void fscache_obtained_object(struct fscache_object *object)
62391 clear_bit_unlock(FSCACHE_COOKIE_LOOKING_UP, &cookie->flags);
62392 wake_up_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP);
62393 } else {
62394- fscache_stat(&fscache_n_object_created);
62395+ fscache_stat_unchecked(&fscache_n_object_created);
62396 }
62397
62398 set_bit(FSCACHE_OBJECT_IS_AVAILABLE, &object->flags);
62399@@ -575,7 +575,7 @@ static const struct fscache_state *fscache_object_available(struct fscache_objec
62400 fscache_stat_d(&fscache_n_cop_lookup_complete);
62401
62402 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
62403- fscache_stat(&fscache_n_object_avail);
62404+ fscache_stat_unchecked(&fscache_n_object_avail);
62405
62406 _leave("");
62407 return transit_to(JUMPSTART_DEPS);
62408@@ -722,7 +722,7 @@ static const struct fscache_state *fscache_drop_object(struct fscache_object *ob
62409
62410 /* this just shifts the object release to the work processor */
62411 fscache_put_object(object);
62412- fscache_stat(&fscache_n_object_dead);
62413+ fscache_stat_unchecked(&fscache_n_object_dead);
62414
62415 _leave("");
62416 return transit_to(OBJECT_DEAD);
62417@@ -887,7 +887,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
62418 enum fscache_checkaux result;
62419
62420 if (!object->cookie->def->check_aux) {
62421- fscache_stat(&fscache_n_checkaux_none);
62422+ fscache_stat_unchecked(&fscache_n_checkaux_none);
62423 return FSCACHE_CHECKAUX_OKAY;
62424 }
62425
62426@@ -896,17 +896,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
62427 switch (result) {
62428 /* entry okay as is */
62429 case FSCACHE_CHECKAUX_OKAY:
62430- fscache_stat(&fscache_n_checkaux_okay);
62431+ fscache_stat_unchecked(&fscache_n_checkaux_okay);
62432 break;
62433
62434 /* entry requires update */
62435 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
62436- fscache_stat(&fscache_n_checkaux_update);
62437+ fscache_stat_unchecked(&fscache_n_checkaux_update);
62438 break;
62439
62440 /* entry requires deletion */
62441 case FSCACHE_CHECKAUX_OBSOLETE:
62442- fscache_stat(&fscache_n_checkaux_obsolete);
62443+ fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
62444 break;
62445
62446 default:
62447@@ -993,7 +993,7 @@ static const struct fscache_state *fscache_invalidate_object(struct fscache_obje
62448 {
62449 const struct fscache_state *s;
62450
62451- fscache_stat(&fscache_n_invalidates_run);
62452+ fscache_stat_unchecked(&fscache_n_invalidates_run);
62453 fscache_stat(&fscache_n_cop_invalidate_object);
62454 s = _fscache_invalidate_object(object, event);
62455 fscache_stat_d(&fscache_n_cop_invalidate_object);
62456@@ -1008,7 +1008,7 @@ static const struct fscache_state *fscache_update_object(struct fscache_object *
62457 {
62458 _enter("{OBJ%x},%d", object->debug_id, event);
62459
62460- fscache_stat(&fscache_n_updates_run);
62461+ fscache_stat_unchecked(&fscache_n_updates_run);
62462 fscache_stat(&fscache_n_cop_update_object);
62463 object->cache->ops->update_object(object);
62464 fscache_stat_d(&fscache_n_cop_update_object);
62465diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
62466index e7b87a0..a85d47a 100644
62467--- a/fs/fscache/operation.c
62468+++ b/fs/fscache/operation.c
62469@@ -17,7 +17,7 @@
62470 #include <linux/slab.h>
62471 #include "internal.h"
62472
62473-atomic_t fscache_op_debug_id;
62474+atomic_unchecked_t fscache_op_debug_id;
62475 EXPORT_SYMBOL(fscache_op_debug_id);
62476
62477 /**
62478@@ -39,7 +39,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
62479 ASSERTCMP(atomic_read(&op->usage), >, 0);
62480 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_IN_PROGRESS);
62481
62482- fscache_stat(&fscache_n_op_enqueue);
62483+ fscache_stat_unchecked(&fscache_n_op_enqueue);
62484 switch (op->flags & FSCACHE_OP_TYPE) {
62485 case FSCACHE_OP_ASYNC:
62486 _debug("queue async");
62487@@ -72,7 +72,7 @@ static void fscache_run_op(struct fscache_object *object,
62488 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
62489 if (op->processor)
62490 fscache_enqueue_operation(op);
62491- fscache_stat(&fscache_n_op_run);
62492+ fscache_stat_unchecked(&fscache_n_op_run);
62493 }
62494
62495 /*
62496@@ -104,11 +104,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
62497 if (object->n_in_progress > 0) {
62498 atomic_inc(&op->usage);
62499 list_add_tail(&op->pend_link, &object->pending_ops);
62500- fscache_stat(&fscache_n_op_pend);
62501+ fscache_stat_unchecked(&fscache_n_op_pend);
62502 } else if (!list_empty(&object->pending_ops)) {
62503 atomic_inc(&op->usage);
62504 list_add_tail(&op->pend_link, &object->pending_ops);
62505- fscache_stat(&fscache_n_op_pend);
62506+ fscache_stat_unchecked(&fscache_n_op_pend);
62507 fscache_start_operations(object);
62508 } else {
62509 ASSERTCMP(object->n_in_progress, ==, 0);
62510@@ -124,7 +124,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
62511 object->n_exclusive++; /* reads and writes must wait */
62512 atomic_inc(&op->usage);
62513 list_add_tail(&op->pend_link, &object->pending_ops);
62514- fscache_stat(&fscache_n_op_pend);
62515+ fscache_stat_unchecked(&fscache_n_op_pend);
62516 ret = 0;
62517 } else {
62518 /* If we're in any other state, there must have been an I/O
62519@@ -211,11 +211,11 @@ int fscache_submit_op(struct fscache_object *object,
62520 if (object->n_exclusive > 0) {
62521 atomic_inc(&op->usage);
62522 list_add_tail(&op->pend_link, &object->pending_ops);
62523- fscache_stat(&fscache_n_op_pend);
62524+ fscache_stat_unchecked(&fscache_n_op_pend);
62525 } else if (!list_empty(&object->pending_ops)) {
62526 atomic_inc(&op->usage);
62527 list_add_tail(&op->pend_link, &object->pending_ops);
62528- fscache_stat(&fscache_n_op_pend);
62529+ fscache_stat_unchecked(&fscache_n_op_pend);
62530 fscache_start_operations(object);
62531 } else {
62532 ASSERTCMP(object->n_exclusive, ==, 0);
62533@@ -227,10 +227,10 @@ int fscache_submit_op(struct fscache_object *object,
62534 object->n_ops++;
62535 atomic_inc(&op->usage);
62536 list_add_tail(&op->pend_link, &object->pending_ops);
62537- fscache_stat(&fscache_n_op_pend);
62538+ fscache_stat_unchecked(&fscache_n_op_pend);
62539 ret = 0;
62540 } else if (fscache_object_is_dying(object)) {
62541- fscache_stat(&fscache_n_op_rejected);
62542+ fscache_stat_unchecked(&fscache_n_op_rejected);
62543 op->state = FSCACHE_OP_ST_CANCELLED;
62544 ret = -ENOBUFS;
62545 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
62546@@ -309,7 +309,7 @@ int fscache_cancel_op(struct fscache_operation *op,
62547 ret = -EBUSY;
62548 if (op->state == FSCACHE_OP_ST_PENDING) {
62549 ASSERT(!list_empty(&op->pend_link));
62550- fscache_stat(&fscache_n_op_cancelled);
62551+ fscache_stat_unchecked(&fscache_n_op_cancelled);
62552 list_del_init(&op->pend_link);
62553 if (do_cancel)
62554 do_cancel(op);
62555@@ -341,7 +341,7 @@ void fscache_cancel_all_ops(struct fscache_object *object)
62556 while (!list_empty(&object->pending_ops)) {
62557 op = list_entry(object->pending_ops.next,
62558 struct fscache_operation, pend_link);
62559- fscache_stat(&fscache_n_op_cancelled);
62560+ fscache_stat_unchecked(&fscache_n_op_cancelled);
62561 list_del_init(&op->pend_link);
62562
62563 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_PENDING);
62564@@ -413,7 +413,7 @@ void fscache_put_operation(struct fscache_operation *op)
62565 op->state, ==, FSCACHE_OP_ST_CANCELLED);
62566 op->state = FSCACHE_OP_ST_DEAD;
62567
62568- fscache_stat(&fscache_n_op_release);
62569+ fscache_stat_unchecked(&fscache_n_op_release);
62570
62571 if (op->release) {
62572 op->release(op);
62573@@ -432,7 +432,7 @@ void fscache_put_operation(struct fscache_operation *op)
62574 * lock, and defer it otherwise */
62575 if (!spin_trylock(&object->lock)) {
62576 _debug("defer put");
62577- fscache_stat(&fscache_n_op_deferred_release);
62578+ fscache_stat_unchecked(&fscache_n_op_deferred_release);
62579
62580 cache = object->cache;
62581 spin_lock(&cache->op_gc_list_lock);
62582@@ -485,7 +485,7 @@ void fscache_operation_gc(struct work_struct *work)
62583
62584 _debug("GC DEFERRED REL OBJ%x OP%x",
62585 object->debug_id, op->debug_id);
62586- fscache_stat(&fscache_n_op_gc);
62587+ fscache_stat_unchecked(&fscache_n_op_gc);
62588
62589 ASSERTCMP(atomic_read(&op->usage), ==, 0);
62590 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_DEAD);
62591diff --git a/fs/fscache/page.c b/fs/fscache/page.c
62592index de33b3f..8be4d29 100644
62593--- a/fs/fscache/page.c
62594+++ b/fs/fscache/page.c
62595@@ -74,7 +74,7 @@ try_again:
62596 val = radix_tree_lookup(&cookie->stores, page->index);
62597 if (!val) {
62598 rcu_read_unlock();
62599- fscache_stat(&fscache_n_store_vmscan_not_storing);
62600+ fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
62601 __fscache_uncache_page(cookie, page);
62602 return true;
62603 }
62604@@ -104,11 +104,11 @@ try_again:
62605 spin_unlock(&cookie->stores_lock);
62606
62607 if (xpage) {
62608- fscache_stat(&fscache_n_store_vmscan_cancelled);
62609- fscache_stat(&fscache_n_store_radix_deletes);
62610+ fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
62611+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
62612 ASSERTCMP(xpage, ==, page);
62613 } else {
62614- fscache_stat(&fscache_n_store_vmscan_gone);
62615+ fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
62616 }
62617
62618 wake_up_bit(&cookie->flags, 0);
62619@@ -123,11 +123,11 @@ page_busy:
62620 * sleeping on memory allocation, so we may need to impose a timeout
62621 * too. */
62622 if (!(gfp & __GFP_WAIT) || !(gfp & __GFP_FS)) {
62623- fscache_stat(&fscache_n_store_vmscan_busy);
62624+ fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
62625 return false;
62626 }
62627
62628- fscache_stat(&fscache_n_store_vmscan_wait);
62629+ fscache_stat_unchecked(&fscache_n_store_vmscan_wait);
62630 if (!release_page_wait_timeout(cookie, page))
62631 _debug("fscache writeout timeout page: %p{%lx}",
62632 page, page->index);
62633@@ -156,7 +156,7 @@ static void fscache_end_page_write(struct fscache_object *object,
62634 FSCACHE_COOKIE_STORING_TAG);
62635 if (!radix_tree_tag_get(&cookie->stores, page->index,
62636 FSCACHE_COOKIE_PENDING_TAG)) {
62637- fscache_stat(&fscache_n_store_radix_deletes);
62638+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
62639 xpage = radix_tree_delete(&cookie->stores, page->index);
62640 }
62641 spin_unlock(&cookie->stores_lock);
62642@@ -177,7 +177,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
62643
62644 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
62645
62646- fscache_stat(&fscache_n_attr_changed_calls);
62647+ fscache_stat_unchecked(&fscache_n_attr_changed_calls);
62648
62649 if (fscache_object_is_active(object)) {
62650 fscache_stat(&fscache_n_cop_attr_changed);
62651@@ -204,11 +204,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
62652
62653 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
62654
62655- fscache_stat(&fscache_n_attr_changed);
62656+ fscache_stat_unchecked(&fscache_n_attr_changed);
62657
62658 op = kzalloc(sizeof(*op), GFP_KERNEL);
62659 if (!op) {
62660- fscache_stat(&fscache_n_attr_changed_nomem);
62661+ fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
62662 _leave(" = -ENOMEM");
62663 return -ENOMEM;
62664 }
62665@@ -230,7 +230,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
62666 if (fscache_submit_exclusive_op(object, op) < 0)
62667 goto nobufs_dec;
62668 spin_unlock(&cookie->lock);
62669- fscache_stat(&fscache_n_attr_changed_ok);
62670+ fscache_stat_unchecked(&fscache_n_attr_changed_ok);
62671 fscache_put_operation(op);
62672 _leave(" = 0");
62673 return 0;
62674@@ -242,7 +242,7 @@ nobufs:
62675 kfree(op);
62676 if (wake_cookie)
62677 __fscache_wake_unused_cookie(cookie);
62678- fscache_stat(&fscache_n_attr_changed_nobufs);
62679+ fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
62680 _leave(" = %d", -ENOBUFS);
62681 return -ENOBUFS;
62682 }
62683@@ -281,7 +281,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
62684 /* allocate a retrieval operation and attempt to submit it */
62685 op = kzalloc(sizeof(*op), GFP_NOIO);
62686 if (!op) {
62687- fscache_stat(&fscache_n_retrievals_nomem);
62688+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
62689 return NULL;
62690 }
62691
62692@@ -311,12 +311,12 @@ int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
62693 return 0;
62694 }
62695
62696- fscache_stat(&fscache_n_retrievals_wait);
62697+ fscache_stat_unchecked(&fscache_n_retrievals_wait);
62698
62699 jif = jiffies;
62700 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
62701 TASK_INTERRUPTIBLE) != 0) {
62702- fscache_stat(&fscache_n_retrievals_intr);
62703+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
62704 _leave(" = -ERESTARTSYS");
62705 return -ERESTARTSYS;
62706 }
62707@@ -345,8 +345,8 @@ static void fscache_do_cancel_retrieval(struct fscache_operation *_op)
62708 */
62709 int fscache_wait_for_operation_activation(struct fscache_object *object,
62710 struct fscache_operation *op,
62711- atomic_t *stat_op_waits,
62712- atomic_t *stat_object_dead,
62713+ atomic_unchecked_t *stat_op_waits,
62714+ atomic_unchecked_t *stat_object_dead,
62715 void (*do_cancel)(struct fscache_operation *))
62716 {
62717 int ret;
62718@@ -356,7 +356,7 @@ int fscache_wait_for_operation_activation(struct fscache_object *object,
62719
62720 _debug(">>> WT");
62721 if (stat_op_waits)
62722- fscache_stat(stat_op_waits);
62723+ fscache_stat_unchecked(stat_op_waits);
62724 if (wait_on_bit(&op->flags, FSCACHE_OP_WAITING,
62725 TASK_INTERRUPTIBLE) != 0) {
62726 ret = fscache_cancel_op(op, do_cancel);
62727@@ -373,7 +373,7 @@ int fscache_wait_for_operation_activation(struct fscache_object *object,
62728 check_if_dead:
62729 if (op->state == FSCACHE_OP_ST_CANCELLED) {
62730 if (stat_object_dead)
62731- fscache_stat(stat_object_dead);
62732+ fscache_stat_unchecked(stat_object_dead);
62733 _leave(" = -ENOBUFS [cancelled]");
62734 return -ENOBUFS;
62735 }
62736@@ -381,7 +381,7 @@ check_if_dead:
62737 pr_err("%s() = -ENOBUFS [obj dead %d]\n", __func__, op->state);
62738 fscache_cancel_op(op, do_cancel);
62739 if (stat_object_dead)
62740- fscache_stat(stat_object_dead);
62741+ fscache_stat_unchecked(stat_object_dead);
62742 return -ENOBUFS;
62743 }
62744 return 0;
62745@@ -409,7 +409,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
62746
62747 _enter("%p,%p,,,", cookie, page);
62748
62749- fscache_stat(&fscache_n_retrievals);
62750+ fscache_stat_unchecked(&fscache_n_retrievals);
62751
62752 if (hlist_empty(&cookie->backing_objects))
62753 goto nobufs;
62754@@ -451,7 +451,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
62755 goto nobufs_unlock_dec;
62756 spin_unlock(&cookie->lock);
62757
62758- fscache_stat(&fscache_n_retrieval_ops);
62759+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
62760
62761 /* pin the netfs read context in case we need to do the actual netfs
62762 * read because we've encountered a cache read failure */
62763@@ -482,15 +482,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
62764
62765 error:
62766 if (ret == -ENOMEM)
62767- fscache_stat(&fscache_n_retrievals_nomem);
62768+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
62769 else if (ret == -ERESTARTSYS)
62770- fscache_stat(&fscache_n_retrievals_intr);
62771+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
62772 else if (ret == -ENODATA)
62773- fscache_stat(&fscache_n_retrievals_nodata);
62774+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
62775 else if (ret < 0)
62776- fscache_stat(&fscache_n_retrievals_nobufs);
62777+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
62778 else
62779- fscache_stat(&fscache_n_retrievals_ok);
62780+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
62781
62782 fscache_put_retrieval(op);
62783 _leave(" = %d", ret);
62784@@ -505,7 +505,7 @@ nobufs_unlock:
62785 __fscache_wake_unused_cookie(cookie);
62786 kfree(op);
62787 nobufs:
62788- fscache_stat(&fscache_n_retrievals_nobufs);
62789+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
62790 _leave(" = -ENOBUFS");
62791 return -ENOBUFS;
62792 }
62793@@ -544,7 +544,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
62794
62795 _enter("%p,,%d,,,", cookie, *nr_pages);
62796
62797- fscache_stat(&fscache_n_retrievals);
62798+ fscache_stat_unchecked(&fscache_n_retrievals);
62799
62800 if (hlist_empty(&cookie->backing_objects))
62801 goto nobufs;
62802@@ -582,7 +582,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
62803 goto nobufs_unlock_dec;
62804 spin_unlock(&cookie->lock);
62805
62806- fscache_stat(&fscache_n_retrieval_ops);
62807+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
62808
62809 /* pin the netfs read context in case we need to do the actual netfs
62810 * read because we've encountered a cache read failure */
62811@@ -613,15 +613,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
62812
62813 error:
62814 if (ret == -ENOMEM)
62815- fscache_stat(&fscache_n_retrievals_nomem);
62816+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
62817 else if (ret == -ERESTARTSYS)
62818- fscache_stat(&fscache_n_retrievals_intr);
62819+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
62820 else if (ret == -ENODATA)
62821- fscache_stat(&fscache_n_retrievals_nodata);
62822+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
62823 else if (ret < 0)
62824- fscache_stat(&fscache_n_retrievals_nobufs);
62825+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
62826 else
62827- fscache_stat(&fscache_n_retrievals_ok);
62828+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
62829
62830 fscache_put_retrieval(op);
62831 _leave(" = %d", ret);
62832@@ -636,7 +636,7 @@ nobufs_unlock:
62833 if (wake_cookie)
62834 __fscache_wake_unused_cookie(cookie);
62835 nobufs:
62836- fscache_stat(&fscache_n_retrievals_nobufs);
62837+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
62838 _leave(" = -ENOBUFS");
62839 return -ENOBUFS;
62840 }
62841@@ -661,7 +661,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
62842
62843 _enter("%p,%p,,,", cookie, page);
62844
62845- fscache_stat(&fscache_n_allocs);
62846+ fscache_stat_unchecked(&fscache_n_allocs);
62847
62848 if (hlist_empty(&cookie->backing_objects))
62849 goto nobufs;
62850@@ -695,7 +695,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
62851 goto nobufs_unlock_dec;
62852 spin_unlock(&cookie->lock);
62853
62854- fscache_stat(&fscache_n_alloc_ops);
62855+ fscache_stat_unchecked(&fscache_n_alloc_ops);
62856
62857 ret = fscache_wait_for_operation_activation(
62858 object, &op->op,
62859@@ -712,11 +712,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
62860
62861 error:
62862 if (ret == -ERESTARTSYS)
62863- fscache_stat(&fscache_n_allocs_intr);
62864+ fscache_stat_unchecked(&fscache_n_allocs_intr);
62865 else if (ret < 0)
62866- fscache_stat(&fscache_n_allocs_nobufs);
62867+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
62868 else
62869- fscache_stat(&fscache_n_allocs_ok);
62870+ fscache_stat_unchecked(&fscache_n_allocs_ok);
62871
62872 fscache_put_retrieval(op);
62873 _leave(" = %d", ret);
62874@@ -730,7 +730,7 @@ nobufs_unlock:
62875 if (wake_cookie)
62876 __fscache_wake_unused_cookie(cookie);
62877 nobufs:
62878- fscache_stat(&fscache_n_allocs_nobufs);
62879+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
62880 _leave(" = -ENOBUFS");
62881 return -ENOBUFS;
62882 }
62883@@ -806,7 +806,7 @@ static void fscache_write_op(struct fscache_operation *_op)
62884
62885 spin_lock(&cookie->stores_lock);
62886
62887- fscache_stat(&fscache_n_store_calls);
62888+ fscache_stat_unchecked(&fscache_n_store_calls);
62889
62890 /* find a page to store */
62891 page = NULL;
62892@@ -817,7 +817,7 @@ static void fscache_write_op(struct fscache_operation *_op)
62893 page = results[0];
62894 _debug("gang %d [%lx]", n, page->index);
62895 if (page->index > op->store_limit) {
62896- fscache_stat(&fscache_n_store_pages_over_limit);
62897+ fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
62898 goto superseded;
62899 }
62900
62901@@ -829,7 +829,7 @@ static void fscache_write_op(struct fscache_operation *_op)
62902 spin_unlock(&cookie->stores_lock);
62903 spin_unlock(&object->lock);
62904
62905- fscache_stat(&fscache_n_store_pages);
62906+ fscache_stat_unchecked(&fscache_n_store_pages);
62907 fscache_stat(&fscache_n_cop_write_page);
62908 ret = object->cache->ops->write_page(op, page);
62909 fscache_stat_d(&fscache_n_cop_write_page);
62910@@ -933,7 +933,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
62911 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
62912 ASSERT(PageFsCache(page));
62913
62914- fscache_stat(&fscache_n_stores);
62915+ fscache_stat_unchecked(&fscache_n_stores);
62916
62917 if (test_bit(FSCACHE_COOKIE_INVALIDATING, &cookie->flags)) {
62918 _leave(" = -ENOBUFS [invalidating]");
62919@@ -992,7 +992,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
62920 spin_unlock(&cookie->stores_lock);
62921 spin_unlock(&object->lock);
62922
62923- op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
62924+ op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
62925 op->store_limit = object->store_limit;
62926
62927 __fscache_use_cookie(cookie);
62928@@ -1001,8 +1001,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
62929
62930 spin_unlock(&cookie->lock);
62931 radix_tree_preload_end();
62932- fscache_stat(&fscache_n_store_ops);
62933- fscache_stat(&fscache_n_stores_ok);
62934+ fscache_stat_unchecked(&fscache_n_store_ops);
62935+ fscache_stat_unchecked(&fscache_n_stores_ok);
62936
62937 /* the work queue now carries its own ref on the object */
62938 fscache_put_operation(&op->op);
62939@@ -1010,14 +1010,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
62940 return 0;
62941
62942 already_queued:
62943- fscache_stat(&fscache_n_stores_again);
62944+ fscache_stat_unchecked(&fscache_n_stores_again);
62945 already_pending:
62946 spin_unlock(&cookie->stores_lock);
62947 spin_unlock(&object->lock);
62948 spin_unlock(&cookie->lock);
62949 radix_tree_preload_end();
62950 kfree(op);
62951- fscache_stat(&fscache_n_stores_ok);
62952+ fscache_stat_unchecked(&fscache_n_stores_ok);
62953 _leave(" = 0");
62954 return 0;
62955
62956@@ -1039,14 +1039,14 @@ nobufs:
62957 kfree(op);
62958 if (wake_cookie)
62959 __fscache_wake_unused_cookie(cookie);
62960- fscache_stat(&fscache_n_stores_nobufs);
62961+ fscache_stat_unchecked(&fscache_n_stores_nobufs);
62962 _leave(" = -ENOBUFS");
62963 return -ENOBUFS;
62964
62965 nomem_free:
62966 kfree(op);
62967 nomem:
62968- fscache_stat(&fscache_n_stores_oom);
62969+ fscache_stat_unchecked(&fscache_n_stores_oom);
62970 _leave(" = -ENOMEM");
62971 return -ENOMEM;
62972 }
62973@@ -1064,7 +1064,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
62974 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
62975 ASSERTCMP(page, !=, NULL);
62976
62977- fscache_stat(&fscache_n_uncaches);
62978+ fscache_stat_unchecked(&fscache_n_uncaches);
62979
62980 /* cache withdrawal may beat us to it */
62981 if (!PageFsCache(page))
62982@@ -1115,7 +1115,7 @@ void fscache_mark_page_cached(struct fscache_retrieval *op, struct page *page)
62983 struct fscache_cookie *cookie = op->op.object->cookie;
62984
62985 #ifdef CONFIG_FSCACHE_STATS
62986- atomic_inc(&fscache_n_marks);
62987+ atomic_inc_unchecked(&fscache_n_marks);
62988 #endif
62989
62990 _debug("- mark %p{%lx}", page, page->index);
62991diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
62992index 40d13c7..ddf52b9 100644
62993--- a/fs/fscache/stats.c
62994+++ b/fs/fscache/stats.c
62995@@ -18,99 +18,99 @@
62996 /*
62997 * operation counters
62998 */
62999-atomic_t fscache_n_op_pend;
63000-atomic_t fscache_n_op_run;
63001-atomic_t fscache_n_op_enqueue;
63002-atomic_t fscache_n_op_requeue;
63003-atomic_t fscache_n_op_deferred_release;
63004-atomic_t fscache_n_op_release;
63005-atomic_t fscache_n_op_gc;
63006-atomic_t fscache_n_op_cancelled;
63007-atomic_t fscache_n_op_rejected;
63008+atomic_unchecked_t fscache_n_op_pend;
63009+atomic_unchecked_t fscache_n_op_run;
63010+atomic_unchecked_t fscache_n_op_enqueue;
63011+atomic_unchecked_t fscache_n_op_requeue;
63012+atomic_unchecked_t fscache_n_op_deferred_release;
63013+atomic_unchecked_t fscache_n_op_release;
63014+atomic_unchecked_t fscache_n_op_gc;
63015+atomic_unchecked_t fscache_n_op_cancelled;
63016+atomic_unchecked_t fscache_n_op_rejected;
63017
63018-atomic_t fscache_n_attr_changed;
63019-atomic_t fscache_n_attr_changed_ok;
63020-atomic_t fscache_n_attr_changed_nobufs;
63021-atomic_t fscache_n_attr_changed_nomem;
63022-atomic_t fscache_n_attr_changed_calls;
63023+atomic_unchecked_t fscache_n_attr_changed;
63024+atomic_unchecked_t fscache_n_attr_changed_ok;
63025+atomic_unchecked_t fscache_n_attr_changed_nobufs;
63026+atomic_unchecked_t fscache_n_attr_changed_nomem;
63027+atomic_unchecked_t fscache_n_attr_changed_calls;
63028
63029-atomic_t fscache_n_allocs;
63030-atomic_t fscache_n_allocs_ok;
63031-atomic_t fscache_n_allocs_wait;
63032-atomic_t fscache_n_allocs_nobufs;
63033-atomic_t fscache_n_allocs_intr;
63034-atomic_t fscache_n_allocs_object_dead;
63035-atomic_t fscache_n_alloc_ops;
63036-atomic_t fscache_n_alloc_op_waits;
63037+atomic_unchecked_t fscache_n_allocs;
63038+atomic_unchecked_t fscache_n_allocs_ok;
63039+atomic_unchecked_t fscache_n_allocs_wait;
63040+atomic_unchecked_t fscache_n_allocs_nobufs;
63041+atomic_unchecked_t fscache_n_allocs_intr;
63042+atomic_unchecked_t fscache_n_allocs_object_dead;
63043+atomic_unchecked_t fscache_n_alloc_ops;
63044+atomic_unchecked_t fscache_n_alloc_op_waits;
63045
63046-atomic_t fscache_n_retrievals;
63047-atomic_t fscache_n_retrievals_ok;
63048-atomic_t fscache_n_retrievals_wait;
63049-atomic_t fscache_n_retrievals_nodata;
63050-atomic_t fscache_n_retrievals_nobufs;
63051-atomic_t fscache_n_retrievals_intr;
63052-atomic_t fscache_n_retrievals_nomem;
63053-atomic_t fscache_n_retrievals_object_dead;
63054-atomic_t fscache_n_retrieval_ops;
63055-atomic_t fscache_n_retrieval_op_waits;
63056+atomic_unchecked_t fscache_n_retrievals;
63057+atomic_unchecked_t fscache_n_retrievals_ok;
63058+atomic_unchecked_t fscache_n_retrievals_wait;
63059+atomic_unchecked_t fscache_n_retrievals_nodata;
63060+atomic_unchecked_t fscache_n_retrievals_nobufs;
63061+atomic_unchecked_t fscache_n_retrievals_intr;
63062+atomic_unchecked_t fscache_n_retrievals_nomem;
63063+atomic_unchecked_t fscache_n_retrievals_object_dead;
63064+atomic_unchecked_t fscache_n_retrieval_ops;
63065+atomic_unchecked_t fscache_n_retrieval_op_waits;
63066
63067-atomic_t fscache_n_stores;
63068-atomic_t fscache_n_stores_ok;
63069-atomic_t fscache_n_stores_again;
63070-atomic_t fscache_n_stores_nobufs;
63071-atomic_t fscache_n_stores_oom;
63072-atomic_t fscache_n_store_ops;
63073-atomic_t fscache_n_store_calls;
63074-atomic_t fscache_n_store_pages;
63075-atomic_t fscache_n_store_radix_deletes;
63076-atomic_t fscache_n_store_pages_over_limit;
63077+atomic_unchecked_t fscache_n_stores;
63078+atomic_unchecked_t fscache_n_stores_ok;
63079+atomic_unchecked_t fscache_n_stores_again;
63080+atomic_unchecked_t fscache_n_stores_nobufs;
63081+atomic_unchecked_t fscache_n_stores_oom;
63082+atomic_unchecked_t fscache_n_store_ops;
63083+atomic_unchecked_t fscache_n_store_calls;
63084+atomic_unchecked_t fscache_n_store_pages;
63085+atomic_unchecked_t fscache_n_store_radix_deletes;
63086+atomic_unchecked_t fscache_n_store_pages_over_limit;
63087
63088-atomic_t fscache_n_store_vmscan_not_storing;
63089-atomic_t fscache_n_store_vmscan_gone;
63090-atomic_t fscache_n_store_vmscan_busy;
63091-atomic_t fscache_n_store_vmscan_cancelled;
63092-atomic_t fscache_n_store_vmscan_wait;
63093+atomic_unchecked_t fscache_n_store_vmscan_not_storing;
63094+atomic_unchecked_t fscache_n_store_vmscan_gone;
63095+atomic_unchecked_t fscache_n_store_vmscan_busy;
63096+atomic_unchecked_t fscache_n_store_vmscan_cancelled;
63097+atomic_unchecked_t fscache_n_store_vmscan_wait;
63098
63099-atomic_t fscache_n_marks;
63100-atomic_t fscache_n_uncaches;
63101+atomic_unchecked_t fscache_n_marks;
63102+atomic_unchecked_t fscache_n_uncaches;
63103
63104-atomic_t fscache_n_acquires;
63105-atomic_t fscache_n_acquires_null;
63106-atomic_t fscache_n_acquires_no_cache;
63107-atomic_t fscache_n_acquires_ok;
63108-atomic_t fscache_n_acquires_nobufs;
63109-atomic_t fscache_n_acquires_oom;
63110+atomic_unchecked_t fscache_n_acquires;
63111+atomic_unchecked_t fscache_n_acquires_null;
63112+atomic_unchecked_t fscache_n_acquires_no_cache;
63113+atomic_unchecked_t fscache_n_acquires_ok;
63114+atomic_unchecked_t fscache_n_acquires_nobufs;
63115+atomic_unchecked_t fscache_n_acquires_oom;
63116
63117-atomic_t fscache_n_invalidates;
63118-atomic_t fscache_n_invalidates_run;
63119+atomic_unchecked_t fscache_n_invalidates;
63120+atomic_unchecked_t fscache_n_invalidates_run;
63121
63122-atomic_t fscache_n_updates;
63123-atomic_t fscache_n_updates_null;
63124-atomic_t fscache_n_updates_run;
63125+atomic_unchecked_t fscache_n_updates;
63126+atomic_unchecked_t fscache_n_updates_null;
63127+atomic_unchecked_t fscache_n_updates_run;
63128
63129-atomic_t fscache_n_relinquishes;
63130-atomic_t fscache_n_relinquishes_null;
63131-atomic_t fscache_n_relinquishes_waitcrt;
63132-atomic_t fscache_n_relinquishes_retire;
63133+atomic_unchecked_t fscache_n_relinquishes;
63134+atomic_unchecked_t fscache_n_relinquishes_null;
63135+atomic_unchecked_t fscache_n_relinquishes_waitcrt;
63136+atomic_unchecked_t fscache_n_relinquishes_retire;
63137
63138-atomic_t fscache_n_cookie_index;
63139-atomic_t fscache_n_cookie_data;
63140-atomic_t fscache_n_cookie_special;
63141+atomic_unchecked_t fscache_n_cookie_index;
63142+atomic_unchecked_t fscache_n_cookie_data;
63143+atomic_unchecked_t fscache_n_cookie_special;
63144
63145-atomic_t fscache_n_object_alloc;
63146-atomic_t fscache_n_object_no_alloc;
63147-atomic_t fscache_n_object_lookups;
63148-atomic_t fscache_n_object_lookups_negative;
63149-atomic_t fscache_n_object_lookups_positive;
63150-atomic_t fscache_n_object_lookups_timed_out;
63151-atomic_t fscache_n_object_created;
63152-atomic_t fscache_n_object_avail;
63153-atomic_t fscache_n_object_dead;
63154+atomic_unchecked_t fscache_n_object_alloc;
63155+atomic_unchecked_t fscache_n_object_no_alloc;
63156+atomic_unchecked_t fscache_n_object_lookups;
63157+atomic_unchecked_t fscache_n_object_lookups_negative;
63158+atomic_unchecked_t fscache_n_object_lookups_positive;
63159+atomic_unchecked_t fscache_n_object_lookups_timed_out;
63160+atomic_unchecked_t fscache_n_object_created;
63161+atomic_unchecked_t fscache_n_object_avail;
63162+atomic_unchecked_t fscache_n_object_dead;
63163
63164-atomic_t fscache_n_checkaux_none;
63165-atomic_t fscache_n_checkaux_okay;
63166-atomic_t fscache_n_checkaux_update;
63167-atomic_t fscache_n_checkaux_obsolete;
63168+atomic_unchecked_t fscache_n_checkaux_none;
63169+atomic_unchecked_t fscache_n_checkaux_okay;
63170+atomic_unchecked_t fscache_n_checkaux_update;
63171+atomic_unchecked_t fscache_n_checkaux_obsolete;
63172
63173 atomic_t fscache_n_cop_alloc_object;
63174 atomic_t fscache_n_cop_lookup_object;
63175@@ -138,118 +138,118 @@ static int fscache_stats_show(struct seq_file *m, void *v)
63176 seq_puts(m, "FS-Cache statistics\n");
63177
63178 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
63179- atomic_read(&fscache_n_cookie_index),
63180- atomic_read(&fscache_n_cookie_data),
63181- atomic_read(&fscache_n_cookie_special));
63182+ atomic_read_unchecked(&fscache_n_cookie_index),
63183+ atomic_read_unchecked(&fscache_n_cookie_data),
63184+ atomic_read_unchecked(&fscache_n_cookie_special));
63185
63186 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
63187- atomic_read(&fscache_n_object_alloc),
63188- atomic_read(&fscache_n_object_no_alloc),
63189- atomic_read(&fscache_n_object_avail),
63190- atomic_read(&fscache_n_object_dead));
63191+ atomic_read_unchecked(&fscache_n_object_alloc),
63192+ atomic_read_unchecked(&fscache_n_object_no_alloc),
63193+ atomic_read_unchecked(&fscache_n_object_avail),
63194+ atomic_read_unchecked(&fscache_n_object_dead));
63195 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
63196- atomic_read(&fscache_n_checkaux_none),
63197- atomic_read(&fscache_n_checkaux_okay),
63198- atomic_read(&fscache_n_checkaux_update),
63199- atomic_read(&fscache_n_checkaux_obsolete));
63200+ atomic_read_unchecked(&fscache_n_checkaux_none),
63201+ atomic_read_unchecked(&fscache_n_checkaux_okay),
63202+ atomic_read_unchecked(&fscache_n_checkaux_update),
63203+ atomic_read_unchecked(&fscache_n_checkaux_obsolete));
63204
63205 seq_printf(m, "Pages : mrk=%u unc=%u\n",
63206- atomic_read(&fscache_n_marks),
63207- atomic_read(&fscache_n_uncaches));
63208+ atomic_read_unchecked(&fscache_n_marks),
63209+ atomic_read_unchecked(&fscache_n_uncaches));
63210
63211 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
63212 " oom=%u\n",
63213- atomic_read(&fscache_n_acquires),
63214- atomic_read(&fscache_n_acquires_null),
63215- atomic_read(&fscache_n_acquires_no_cache),
63216- atomic_read(&fscache_n_acquires_ok),
63217- atomic_read(&fscache_n_acquires_nobufs),
63218- atomic_read(&fscache_n_acquires_oom));
63219+ atomic_read_unchecked(&fscache_n_acquires),
63220+ atomic_read_unchecked(&fscache_n_acquires_null),
63221+ atomic_read_unchecked(&fscache_n_acquires_no_cache),
63222+ atomic_read_unchecked(&fscache_n_acquires_ok),
63223+ atomic_read_unchecked(&fscache_n_acquires_nobufs),
63224+ atomic_read_unchecked(&fscache_n_acquires_oom));
63225
63226 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
63227- atomic_read(&fscache_n_object_lookups),
63228- atomic_read(&fscache_n_object_lookups_negative),
63229- atomic_read(&fscache_n_object_lookups_positive),
63230- atomic_read(&fscache_n_object_created),
63231- atomic_read(&fscache_n_object_lookups_timed_out));
63232+ atomic_read_unchecked(&fscache_n_object_lookups),
63233+ atomic_read_unchecked(&fscache_n_object_lookups_negative),
63234+ atomic_read_unchecked(&fscache_n_object_lookups_positive),
63235+ atomic_read_unchecked(&fscache_n_object_created),
63236+ atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
63237
63238 seq_printf(m, "Invals : n=%u run=%u\n",
63239- atomic_read(&fscache_n_invalidates),
63240- atomic_read(&fscache_n_invalidates_run));
63241+ atomic_read_unchecked(&fscache_n_invalidates),
63242+ atomic_read_unchecked(&fscache_n_invalidates_run));
63243
63244 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
63245- atomic_read(&fscache_n_updates),
63246- atomic_read(&fscache_n_updates_null),
63247- atomic_read(&fscache_n_updates_run));
63248+ atomic_read_unchecked(&fscache_n_updates),
63249+ atomic_read_unchecked(&fscache_n_updates_null),
63250+ atomic_read_unchecked(&fscache_n_updates_run));
63251
63252 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
63253- atomic_read(&fscache_n_relinquishes),
63254- atomic_read(&fscache_n_relinquishes_null),
63255- atomic_read(&fscache_n_relinquishes_waitcrt),
63256- atomic_read(&fscache_n_relinquishes_retire));
63257+ atomic_read_unchecked(&fscache_n_relinquishes),
63258+ atomic_read_unchecked(&fscache_n_relinquishes_null),
63259+ atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
63260+ atomic_read_unchecked(&fscache_n_relinquishes_retire));
63261
63262 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
63263- atomic_read(&fscache_n_attr_changed),
63264- atomic_read(&fscache_n_attr_changed_ok),
63265- atomic_read(&fscache_n_attr_changed_nobufs),
63266- atomic_read(&fscache_n_attr_changed_nomem),
63267- atomic_read(&fscache_n_attr_changed_calls));
63268+ atomic_read_unchecked(&fscache_n_attr_changed),
63269+ atomic_read_unchecked(&fscache_n_attr_changed_ok),
63270+ atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
63271+ atomic_read_unchecked(&fscache_n_attr_changed_nomem),
63272+ atomic_read_unchecked(&fscache_n_attr_changed_calls));
63273
63274 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
63275- atomic_read(&fscache_n_allocs),
63276- atomic_read(&fscache_n_allocs_ok),
63277- atomic_read(&fscache_n_allocs_wait),
63278- atomic_read(&fscache_n_allocs_nobufs),
63279- atomic_read(&fscache_n_allocs_intr));
63280+ atomic_read_unchecked(&fscache_n_allocs),
63281+ atomic_read_unchecked(&fscache_n_allocs_ok),
63282+ atomic_read_unchecked(&fscache_n_allocs_wait),
63283+ atomic_read_unchecked(&fscache_n_allocs_nobufs),
63284+ atomic_read_unchecked(&fscache_n_allocs_intr));
63285 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
63286- atomic_read(&fscache_n_alloc_ops),
63287- atomic_read(&fscache_n_alloc_op_waits),
63288- atomic_read(&fscache_n_allocs_object_dead));
63289+ atomic_read_unchecked(&fscache_n_alloc_ops),
63290+ atomic_read_unchecked(&fscache_n_alloc_op_waits),
63291+ atomic_read_unchecked(&fscache_n_allocs_object_dead));
63292
63293 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
63294 " int=%u oom=%u\n",
63295- atomic_read(&fscache_n_retrievals),
63296- atomic_read(&fscache_n_retrievals_ok),
63297- atomic_read(&fscache_n_retrievals_wait),
63298- atomic_read(&fscache_n_retrievals_nodata),
63299- atomic_read(&fscache_n_retrievals_nobufs),
63300- atomic_read(&fscache_n_retrievals_intr),
63301- atomic_read(&fscache_n_retrievals_nomem));
63302+ atomic_read_unchecked(&fscache_n_retrievals),
63303+ atomic_read_unchecked(&fscache_n_retrievals_ok),
63304+ atomic_read_unchecked(&fscache_n_retrievals_wait),
63305+ atomic_read_unchecked(&fscache_n_retrievals_nodata),
63306+ atomic_read_unchecked(&fscache_n_retrievals_nobufs),
63307+ atomic_read_unchecked(&fscache_n_retrievals_intr),
63308+ atomic_read_unchecked(&fscache_n_retrievals_nomem));
63309 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
63310- atomic_read(&fscache_n_retrieval_ops),
63311- atomic_read(&fscache_n_retrieval_op_waits),
63312- atomic_read(&fscache_n_retrievals_object_dead));
63313+ atomic_read_unchecked(&fscache_n_retrieval_ops),
63314+ atomic_read_unchecked(&fscache_n_retrieval_op_waits),
63315+ atomic_read_unchecked(&fscache_n_retrievals_object_dead));
63316
63317 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
63318- atomic_read(&fscache_n_stores),
63319- atomic_read(&fscache_n_stores_ok),
63320- atomic_read(&fscache_n_stores_again),
63321- atomic_read(&fscache_n_stores_nobufs),
63322- atomic_read(&fscache_n_stores_oom));
63323+ atomic_read_unchecked(&fscache_n_stores),
63324+ atomic_read_unchecked(&fscache_n_stores_ok),
63325+ atomic_read_unchecked(&fscache_n_stores_again),
63326+ atomic_read_unchecked(&fscache_n_stores_nobufs),
63327+ atomic_read_unchecked(&fscache_n_stores_oom));
63328 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
63329- atomic_read(&fscache_n_store_ops),
63330- atomic_read(&fscache_n_store_calls),
63331- atomic_read(&fscache_n_store_pages),
63332- atomic_read(&fscache_n_store_radix_deletes),
63333- atomic_read(&fscache_n_store_pages_over_limit));
63334+ atomic_read_unchecked(&fscache_n_store_ops),
63335+ atomic_read_unchecked(&fscache_n_store_calls),
63336+ atomic_read_unchecked(&fscache_n_store_pages),
63337+ atomic_read_unchecked(&fscache_n_store_radix_deletes),
63338+ atomic_read_unchecked(&fscache_n_store_pages_over_limit));
63339
63340 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u wt=%u\n",
63341- atomic_read(&fscache_n_store_vmscan_not_storing),
63342- atomic_read(&fscache_n_store_vmscan_gone),
63343- atomic_read(&fscache_n_store_vmscan_busy),
63344- atomic_read(&fscache_n_store_vmscan_cancelled),
63345- atomic_read(&fscache_n_store_vmscan_wait));
63346+ atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
63347+ atomic_read_unchecked(&fscache_n_store_vmscan_gone),
63348+ atomic_read_unchecked(&fscache_n_store_vmscan_busy),
63349+ atomic_read_unchecked(&fscache_n_store_vmscan_cancelled),
63350+ atomic_read_unchecked(&fscache_n_store_vmscan_wait));
63351
63352 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
63353- atomic_read(&fscache_n_op_pend),
63354- atomic_read(&fscache_n_op_run),
63355- atomic_read(&fscache_n_op_enqueue),
63356- atomic_read(&fscache_n_op_cancelled),
63357- atomic_read(&fscache_n_op_rejected));
63358+ atomic_read_unchecked(&fscache_n_op_pend),
63359+ atomic_read_unchecked(&fscache_n_op_run),
63360+ atomic_read_unchecked(&fscache_n_op_enqueue),
63361+ atomic_read_unchecked(&fscache_n_op_cancelled),
63362+ atomic_read_unchecked(&fscache_n_op_rejected));
63363 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
63364- atomic_read(&fscache_n_op_deferred_release),
63365- atomic_read(&fscache_n_op_release),
63366- atomic_read(&fscache_n_op_gc));
63367+ atomic_read_unchecked(&fscache_n_op_deferred_release),
63368+ atomic_read_unchecked(&fscache_n_op_release),
63369+ atomic_read_unchecked(&fscache_n_op_gc));
63370
63371 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
63372 atomic_read(&fscache_n_cop_alloc_object),
63373diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
63374index 966ace8..030a03a 100644
63375--- a/fs/fuse/cuse.c
63376+++ b/fs/fuse/cuse.c
63377@@ -611,10 +611,12 @@ static int __init cuse_init(void)
63378 INIT_LIST_HEAD(&cuse_conntbl[i]);
63379
63380 /* inherit and extend fuse_dev_operations */
63381- cuse_channel_fops = fuse_dev_operations;
63382- cuse_channel_fops.owner = THIS_MODULE;
63383- cuse_channel_fops.open = cuse_channel_open;
63384- cuse_channel_fops.release = cuse_channel_release;
63385+ pax_open_kernel();
63386+ memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
63387+ *(void **)&cuse_channel_fops.owner = THIS_MODULE;
63388+ *(void **)&cuse_channel_fops.open = cuse_channel_open;
63389+ *(void **)&cuse_channel_fops.release = cuse_channel_release;
63390+ pax_close_kernel();
63391
63392 cuse_class = class_create(THIS_MODULE, "cuse");
63393 if (IS_ERR(cuse_class))
63394diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
63395index ca88731..8e9c55d 100644
63396--- a/fs/fuse/dev.c
63397+++ b/fs/fuse/dev.c
63398@@ -1318,7 +1318,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
63399 ret = 0;
63400 pipe_lock(pipe);
63401
63402- if (!pipe->readers) {
63403+ if (!atomic_read(&pipe->readers)) {
63404 send_sig(SIGPIPE, current, 0);
63405 if (!ret)
63406 ret = -EPIPE;
63407@@ -1347,7 +1347,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
63408 page_nr++;
63409 ret += buf->len;
63410
63411- if (pipe->files)
63412+ if (atomic_read(&pipe->files))
63413 do_wakeup = 1;
63414 }
63415
63416diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
63417index dbab798..fefa22b 100644
63418--- a/fs/fuse/dir.c
63419+++ b/fs/fuse/dir.c
63420@@ -1474,7 +1474,7 @@ static char *read_link(struct dentry *dentry)
63421 return link;
63422 }
63423
63424-static void free_link(char *link)
63425+static void free_link(const char *link)
63426 {
63427 if (!IS_ERR(link))
63428 free_page((unsigned long) link);
63429diff --git a/fs/hostfs/hostfs_kern.c b/fs/hostfs/hostfs_kern.c
63430index fd62cae..3494dfa 100644
63431--- a/fs/hostfs/hostfs_kern.c
63432+++ b/fs/hostfs/hostfs_kern.c
63433@@ -908,7 +908,7 @@ static void *hostfs_follow_link(struct dentry *dentry, struct nameidata *nd)
63434
63435 static void hostfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
63436 {
63437- char *s = nd_get_link(nd);
63438+ const char *s = nd_get_link(nd);
63439 if (!IS_ERR(s))
63440 __putname(s);
63441 }
63442diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
63443index 1e2872b..7aea000 100644
63444--- a/fs/hugetlbfs/inode.c
63445+++ b/fs/hugetlbfs/inode.c
63446@@ -154,6 +154,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
63447 struct mm_struct *mm = current->mm;
63448 struct vm_area_struct *vma;
63449 struct hstate *h = hstate_file(file);
63450+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
63451 struct vm_unmapped_area_info info;
63452
63453 if (len & ~huge_page_mask(h))
63454@@ -167,17 +168,26 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
63455 return addr;
63456 }
63457
63458+#ifdef CONFIG_PAX_RANDMMAP
63459+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
63460+#endif
63461+
63462 if (addr) {
63463 addr = ALIGN(addr, huge_page_size(h));
63464 vma = find_vma(mm, addr);
63465- if (TASK_SIZE - len >= addr &&
63466- (!vma || addr + len <= vma->vm_start))
63467+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
63468 return addr;
63469 }
63470
63471 info.flags = 0;
63472 info.length = len;
63473 info.low_limit = TASK_UNMAPPED_BASE;
63474+
63475+#ifdef CONFIG_PAX_RANDMMAP
63476+ if (mm->pax_flags & MF_PAX_RANDMMAP)
63477+ info.low_limit += mm->delta_mmap;
63478+#endif
63479+
63480 info.high_limit = TASK_SIZE;
63481 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
63482 info.align_offset = 0;
63483@@ -919,7 +929,7 @@ static struct file_system_type hugetlbfs_fs_type = {
63484 };
63485 MODULE_ALIAS_FS("hugetlbfs");
63486
63487-static struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
63488+struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
63489
63490 static int can_do_hugetlb_shm(void)
63491 {
63492diff --git a/fs/inode.c b/fs/inode.c
63493index 26753ba..d19eb34 100644
63494--- a/fs/inode.c
63495+++ b/fs/inode.c
63496@@ -840,16 +840,20 @@ unsigned int get_next_ino(void)
63497 unsigned int *p = &get_cpu_var(last_ino);
63498 unsigned int res = *p;
63499
63500+start:
63501+
63502 #ifdef CONFIG_SMP
63503 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
63504- static atomic_t shared_last_ino;
63505- int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
63506+ static atomic_unchecked_t shared_last_ino;
63507+ int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
63508
63509 res = next - LAST_INO_BATCH;
63510 }
63511 #endif
63512
63513- *p = ++res;
63514+ if (unlikely(!++res))
63515+ goto start; /* never zero */
63516+ *p = res;
63517 put_cpu_var(last_ino);
63518 return res;
63519 }
63520diff --git a/fs/isofs/rock.c b/fs/isofs/rock.c
63521index f488bba..735d752 100644
63522--- a/fs/isofs/rock.c
63523+++ b/fs/isofs/rock.c
63524@@ -30,6 +30,7 @@ struct rock_state {
63525 int cont_size;
63526 int cont_extent;
63527 int cont_offset;
63528+ int cont_loops;
63529 struct inode *inode;
63530 };
63531
63532@@ -73,6 +74,9 @@ static void init_rock_state(struct rock_state *rs, struct inode *inode)
63533 rs->inode = inode;
63534 }
63535
63536+/* Maximum number of Rock Ridge continuation entries */
63537+#define RR_MAX_CE_ENTRIES 32
63538+
63539 /*
63540 * Returns 0 if the caller should continue scanning, 1 if the scan must end
63541 * and -ve on error.
63542@@ -105,6 +109,8 @@ static int rock_continue(struct rock_state *rs)
63543 goto out;
63544 }
63545 ret = -EIO;
63546+ if (++rs->cont_loops >= RR_MAX_CE_ENTRIES)
63547+ goto out;
63548 bh = sb_bread(rs->inode->i_sb, rs->cont_extent);
63549 if (bh) {
63550 memcpy(rs->buffer, bh->b_data + rs->cont_offset,
63551@@ -356,6 +362,9 @@ repeat:
63552 rs.cont_size = isonum_733(rr->u.CE.size);
63553 break;
63554 case SIG('E', 'R'):
63555+ /* Invalid length of ER tag id? */
63556+ if (rr->u.ER.len_id + offsetof(struct rock_ridge, u.ER.data) > rr->len)
63557+ goto out;
63558 ISOFS_SB(inode->i_sb)->s_rock = 1;
63559 printk(KERN_DEBUG "ISO 9660 Extensions: ");
63560 {
63561diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
63562index 4a6cf28..d3a29d3 100644
63563--- a/fs/jffs2/erase.c
63564+++ b/fs/jffs2/erase.c
63565@@ -452,7 +452,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
63566 struct jffs2_unknown_node marker = {
63567 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
63568 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
63569- .totlen = cpu_to_je32(c->cleanmarker_size)
63570+ .totlen = cpu_to_je32(c->cleanmarker_size),
63571+ .hdr_crc = cpu_to_je32(0)
63572 };
63573
63574 jffs2_prealloc_raw_node_refs(c, jeb, 1);
63575diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
63576index 09ed551..45684f8 100644
63577--- a/fs/jffs2/wbuf.c
63578+++ b/fs/jffs2/wbuf.c
63579@@ -1023,7 +1023,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
63580 {
63581 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
63582 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
63583- .totlen = constant_cpu_to_je32(8)
63584+ .totlen = constant_cpu_to_je32(8),
63585+ .hdr_crc = constant_cpu_to_je32(0)
63586 };
63587
63588 /*
63589diff --git a/fs/jfs/super.c b/fs/jfs/super.c
63590index 93e897e..a863de4 100644
63591--- a/fs/jfs/super.c
63592+++ b/fs/jfs/super.c
63593@@ -893,7 +893,7 @@ static int __init init_jfs_fs(void)
63594
63595 jfs_inode_cachep =
63596 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
63597- SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
63598+ SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
63599 init_once);
63600 if (jfs_inode_cachep == NULL)
63601 return -ENOMEM;
63602diff --git a/fs/kernfs/dir.c b/fs/kernfs/dir.c
63603index 1c77193..5cfb7b57 100644
63604--- a/fs/kernfs/dir.c
63605+++ b/fs/kernfs/dir.c
63606@@ -182,7 +182,7 @@ struct kernfs_node *kernfs_get_parent(struct kernfs_node *kn)
63607 *
63608 * Returns 31 bit hash of ns + name (so it fits in an off_t )
63609 */
63610-static unsigned int kernfs_name_hash(const char *name, const void *ns)
63611+static unsigned int kernfs_name_hash(const unsigned char *name, const void *ns)
63612 {
63613 unsigned long hash = init_name_hash();
63614 unsigned int len = strlen(name);
63615@@ -829,6 +829,10 @@ static int kernfs_iop_mkdir(struct inode *dir, struct dentry *dentry,
63616 ret = scops->mkdir(parent, dentry->d_name.name, mode);
63617
63618 kernfs_put_active(parent);
63619+
63620+ if (!ret)
63621+ ret = kernfs_iop_lookup(dir, dentry, 0);
63622+
63623 return ret;
63624 }
63625
63626diff --git a/fs/kernfs/file.c b/fs/kernfs/file.c
63627index 4429d6d..9831f52 100644
63628--- a/fs/kernfs/file.c
63629+++ b/fs/kernfs/file.c
63630@@ -34,7 +34,7 @@ static DEFINE_MUTEX(kernfs_open_file_mutex);
63631
63632 struct kernfs_open_node {
63633 atomic_t refcnt;
63634- atomic_t event;
63635+ atomic_unchecked_t event;
63636 wait_queue_head_t poll;
63637 struct list_head files; /* goes through kernfs_open_file.list */
63638 };
63639@@ -163,7 +163,7 @@ static int kernfs_seq_show(struct seq_file *sf, void *v)
63640 {
63641 struct kernfs_open_file *of = sf->private;
63642
63643- of->event = atomic_read(&of->kn->attr.open->event);
63644+ of->event = atomic_read_unchecked(&of->kn->attr.open->event);
63645
63646 return of->kn->attr.ops->seq_show(sf, v);
63647 }
63648@@ -375,12 +375,12 @@ static int kernfs_vma_page_mkwrite(struct vm_area_struct *vma,
63649 return ret;
63650 }
63651
63652-static int kernfs_vma_access(struct vm_area_struct *vma, unsigned long addr,
63653- void *buf, int len, int write)
63654+static ssize_t kernfs_vma_access(struct vm_area_struct *vma, unsigned long addr,
63655+ void *buf, size_t len, int write)
63656 {
63657 struct file *file = vma->vm_file;
63658 struct kernfs_open_file *of = kernfs_of(file);
63659- int ret;
63660+ ssize_t ret;
63661
63662 if (!of->vm_ops)
63663 return -EINVAL;
63664@@ -581,7 +581,7 @@ static int kernfs_get_open_node(struct kernfs_node *kn,
63665 return -ENOMEM;
63666
63667 atomic_set(&new_on->refcnt, 0);
63668- atomic_set(&new_on->event, 1);
63669+ atomic_set_unchecked(&new_on->event, 1);
63670 init_waitqueue_head(&new_on->poll);
63671 INIT_LIST_HEAD(&new_on->files);
63672 goto retry;
63673@@ -787,7 +787,7 @@ static unsigned int kernfs_fop_poll(struct file *filp, poll_table *wait)
63674
63675 kernfs_put_active(kn);
63676
63677- if (of->event != atomic_read(&on->event))
63678+ if (of->event != atomic_read_unchecked(&on->event))
63679 goto trigger;
63680
63681 return DEFAULT_POLLMASK;
63682@@ -818,7 +818,7 @@ repeat:
63683
63684 on = kn->attr.open;
63685 if (on) {
63686- atomic_inc(&on->event);
63687+ atomic_inc_unchecked(&on->event);
63688 wake_up_interruptible(&on->poll);
63689 }
63690
63691diff --git a/fs/kernfs/symlink.c b/fs/kernfs/symlink.c
63692index 8a19889..4c3069a 100644
63693--- a/fs/kernfs/symlink.c
63694+++ b/fs/kernfs/symlink.c
63695@@ -128,7 +128,7 @@ static void *kernfs_iop_follow_link(struct dentry *dentry, struct nameidata *nd)
63696 static void kernfs_iop_put_link(struct dentry *dentry, struct nameidata *nd,
63697 void *cookie)
63698 {
63699- char *page = nd_get_link(nd);
63700+ const char *page = nd_get_link(nd);
63701 if (!IS_ERR(page))
63702 free_page((unsigned long)page);
63703 }
63704diff --git a/fs/libfs.c b/fs/libfs.c
63705index 005843c..06c4191 100644
63706--- a/fs/libfs.c
63707+++ b/fs/libfs.c
63708@@ -160,6 +160,9 @@ int dcache_readdir(struct file *file, struct dir_context *ctx)
63709
63710 for (p = q->next; p != &dentry->d_subdirs; p = p->next) {
63711 struct dentry *next = list_entry(p, struct dentry, d_child);
63712+ char d_name[sizeof(next->d_iname)];
63713+ const unsigned char *name;
63714+
63715 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
63716 if (!simple_positive(next)) {
63717 spin_unlock(&next->d_lock);
63718@@ -168,7 +171,12 @@ int dcache_readdir(struct file *file, struct dir_context *ctx)
63719
63720 spin_unlock(&next->d_lock);
63721 spin_unlock(&dentry->d_lock);
63722- if (!dir_emit(ctx, next->d_name.name, next->d_name.len,
63723+ name = next->d_name.name;
63724+ if (name == next->d_iname) {
63725+ memcpy(d_name, name, next->d_name.len);
63726+ name = d_name;
63727+ }
63728+ if (!dir_emit(ctx, name, next->d_name.len,
63729 next->d_inode->i_ino, dt_type(next->d_inode)))
63730 return 0;
63731 spin_lock(&dentry->d_lock);
63732@@ -1027,7 +1035,7 @@ EXPORT_SYMBOL(noop_fsync);
63733 void kfree_put_link(struct dentry *dentry, struct nameidata *nd,
63734 void *cookie)
63735 {
63736- char *s = nd_get_link(nd);
63737+ const char *s = nd_get_link(nd);
63738 if (!IS_ERR(s))
63739 kfree(s);
63740 }
63741diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
63742index acd3947..1f896e2 100644
63743--- a/fs/lockd/clntproc.c
63744+++ b/fs/lockd/clntproc.c
63745@@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
63746 /*
63747 * Cookie counter for NLM requests
63748 */
63749-static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
63750+static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
63751
63752 void nlmclnt_next_cookie(struct nlm_cookie *c)
63753 {
63754- u32 cookie = atomic_inc_return(&nlm_cookie);
63755+ u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
63756
63757 memcpy(c->data, &cookie, 4);
63758 c->len=4;
63759diff --git a/fs/locks.c b/fs/locks.c
63760index 735b8d3..dfc44a2 100644
63761--- a/fs/locks.c
63762+++ b/fs/locks.c
63763@@ -2374,7 +2374,7 @@ void locks_remove_file(struct file *filp)
63764 locks_remove_posix(filp, filp);
63765
63766 if (filp->f_op->flock) {
63767- struct file_lock fl = {
63768+ struct file_lock flock = {
63769 .fl_owner = filp,
63770 .fl_pid = current->tgid,
63771 .fl_file = filp,
63772@@ -2382,9 +2382,9 @@ void locks_remove_file(struct file *filp)
63773 .fl_type = F_UNLCK,
63774 .fl_end = OFFSET_MAX,
63775 };
63776- filp->f_op->flock(filp, F_SETLKW, &fl);
63777- if (fl.fl_ops && fl.fl_ops->fl_release_private)
63778- fl.fl_ops->fl_release_private(&fl);
63779+ filp->f_op->flock(filp, F_SETLKW, &flock);
63780+ if (flock.fl_ops && flock.fl_ops->fl_release_private)
63781+ flock.fl_ops->fl_release_private(&flock);
63782 }
63783
63784 spin_lock(&inode->i_lock);
63785diff --git a/fs/mount.h b/fs/mount.h
63786index f82c628..9492b99 100644
63787--- a/fs/mount.h
63788+++ b/fs/mount.h
63789@@ -11,7 +11,7 @@ struct mnt_namespace {
63790 u64 seq; /* Sequence number to prevent loops */
63791 wait_queue_head_t poll;
63792 u64 event;
63793-};
63794+} __randomize_layout;
63795
63796 struct mnt_pcp {
63797 int mnt_count;
63798@@ -62,7 +62,7 @@ struct mount {
63799 int mnt_expiry_mark; /* true if marked for expiry */
63800 struct hlist_head mnt_pins;
63801 struct path mnt_ex_mountpoint;
63802-};
63803+} __randomize_layout;
63804
63805 #define MNT_NS_INTERNAL ERR_PTR(-EINVAL) /* distinct from any mnt_namespace */
63806
63807diff --git a/fs/namei.c b/fs/namei.c
63808index db5fe86..d3dcc14 100644
63809--- a/fs/namei.c
63810+++ b/fs/namei.c
63811@@ -331,17 +331,32 @@ int generic_permission(struct inode *inode, int mask)
63812 if (ret != -EACCES)
63813 return ret;
63814
63815+#ifdef CONFIG_GRKERNSEC
63816+ /* we'll block if we have to log due to a denied capability use */
63817+ if (mask & MAY_NOT_BLOCK)
63818+ return -ECHILD;
63819+#endif
63820+
63821 if (S_ISDIR(inode->i_mode)) {
63822 /* DACs are overridable for directories */
63823- if (capable_wrt_inode_uidgid(inode, CAP_DAC_OVERRIDE))
63824- return 0;
63825 if (!(mask & MAY_WRITE))
63826- if (capable_wrt_inode_uidgid(inode,
63827- CAP_DAC_READ_SEARCH))
63828+ if (capable_wrt_inode_uidgid_nolog(inode, CAP_DAC_OVERRIDE) ||
63829+ capable_wrt_inode_uidgid(inode, CAP_DAC_READ_SEARCH))
63830 return 0;
63831+ if (capable_wrt_inode_uidgid(inode, CAP_DAC_OVERRIDE))
63832+ return 0;
63833 return -EACCES;
63834 }
63835 /*
63836+ * Searching includes executable on directories, else just read.
63837+ */
63838+ mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
63839+ if (mask == MAY_READ)
63840+ if (capable_wrt_inode_uidgid_nolog(inode, CAP_DAC_OVERRIDE) ||
63841+ capable_wrt_inode_uidgid(inode, CAP_DAC_READ_SEARCH))
63842+ return 0;
63843+
63844+ /*
63845 * Read/write DACs are always overridable.
63846 * Executable DACs are overridable when there is
63847 * at least one exec bit set.
63848@@ -350,14 +365,6 @@ int generic_permission(struct inode *inode, int mask)
63849 if (capable_wrt_inode_uidgid(inode, CAP_DAC_OVERRIDE))
63850 return 0;
63851
63852- /*
63853- * Searching includes executable on directories, else just read.
63854- */
63855- mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
63856- if (mask == MAY_READ)
63857- if (capable_wrt_inode_uidgid(inode, CAP_DAC_READ_SEARCH))
63858- return 0;
63859-
63860 return -EACCES;
63861 }
63862 EXPORT_SYMBOL(generic_permission);
63863@@ -824,7 +831,7 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
63864 {
63865 struct dentry *dentry = link->dentry;
63866 int error;
63867- char *s;
63868+ const char *s;
63869
63870 BUG_ON(nd->flags & LOOKUP_RCU);
63871
63872@@ -845,6 +852,12 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
63873 if (error)
63874 goto out_put_nd_path;
63875
63876+ if (gr_handle_follow_link(dentry->d_parent->d_inode,
63877+ dentry->d_inode, dentry, nd->path.mnt)) {
63878+ error = -EACCES;
63879+ goto out_put_nd_path;
63880+ }
63881+
63882 nd->last_type = LAST_BIND;
63883 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
63884 error = PTR_ERR(*p);
63885@@ -1608,6 +1621,8 @@ static inline int nested_symlink(struct path *path, struct nameidata *nd)
63886 if (res)
63887 break;
63888 res = walk_component(nd, path, LOOKUP_FOLLOW);
63889+ if (res >= 0 && gr_handle_symlink_owner(&link, nd->inode))
63890+ res = -EACCES;
63891 put_link(nd, &link, cookie);
63892 } while (res > 0);
63893
63894@@ -1680,7 +1695,7 @@ EXPORT_SYMBOL(full_name_hash);
63895 static inline u64 hash_name(const char *name)
63896 {
63897 unsigned long a, b, adata, bdata, mask, hash, len;
63898- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
63899+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
63900
63901 hash = a = 0;
63902 len = -sizeof(unsigned long);
63903@@ -1969,6 +1984,8 @@ static int path_lookupat(int dfd, const char *name,
63904 if (err)
63905 break;
63906 err = lookup_last(nd, &path);
63907+ if (!err && gr_handle_symlink_owner(&link, nd->inode))
63908+ err = -EACCES;
63909 put_link(nd, &link, cookie);
63910 }
63911 }
63912@@ -1976,6 +1993,13 @@ static int path_lookupat(int dfd, const char *name,
63913 if (!err)
63914 err = complete_walk(nd);
63915
63916+ if (!err && !(nd->flags & LOOKUP_PARENT)) {
63917+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
63918+ path_put(&nd->path);
63919+ err = -ENOENT;
63920+ }
63921+ }
63922+
63923 if (!err && nd->flags & LOOKUP_DIRECTORY) {
63924 if (!d_can_lookup(nd->path.dentry)) {
63925 path_put(&nd->path);
63926@@ -2004,8 +2028,15 @@ static int filename_lookup(int dfd, struct filename *name,
63927 retval = path_lookupat(dfd, name->name,
63928 flags | LOOKUP_REVAL, nd);
63929
63930- if (likely(!retval))
63931+ if (likely(!retval)) {
63932 audit_inode(name, nd->path.dentry, flags & LOOKUP_PARENT);
63933+ if (name->name[0] != '/' && nd->path.dentry && nd->inode) {
63934+ if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt)) {
63935+ path_put(&nd->path);
63936+ return -ENOENT;
63937+ }
63938+ }
63939+ }
63940 return retval;
63941 }
63942
63943@@ -2582,6 +2613,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
63944 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
63945 return -EPERM;
63946
63947+ if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
63948+ return -EPERM;
63949+ if (gr_handle_rawio(inode))
63950+ return -EPERM;
63951+ if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
63952+ return -EACCES;
63953+
63954 return 0;
63955 }
63956
63957@@ -2813,7 +2851,7 @@ looked_up:
63958 * cleared otherwise prior to returning.
63959 */
63960 static int lookup_open(struct nameidata *nd, struct path *path,
63961- struct file *file,
63962+ struct path *link, struct file *file,
63963 const struct open_flags *op,
63964 bool got_write, int *opened)
63965 {
63966@@ -2848,6 +2886,17 @@ static int lookup_open(struct nameidata *nd, struct path *path,
63967 /* Negative dentry, just create the file */
63968 if (!dentry->d_inode && (op->open_flag & O_CREAT)) {
63969 umode_t mode = op->mode;
63970+
63971+ if (link && gr_handle_symlink_owner(link, dir->d_inode)) {
63972+ error = -EACCES;
63973+ goto out_dput;
63974+ }
63975+
63976+ if (!gr_acl_handle_creat(dentry, dir, nd->path.mnt, op->open_flag, op->acc_mode, mode)) {
63977+ error = -EACCES;
63978+ goto out_dput;
63979+ }
63980+
63981 if (!IS_POSIXACL(dir->d_inode))
63982 mode &= ~current_umask();
63983 /*
63984@@ -2869,6 +2918,8 @@ static int lookup_open(struct nameidata *nd, struct path *path,
63985 nd->flags & LOOKUP_EXCL);
63986 if (error)
63987 goto out_dput;
63988+ else
63989+ gr_handle_create(dentry, nd->path.mnt);
63990 }
63991 out_no_open:
63992 path->dentry = dentry;
63993@@ -2883,7 +2934,7 @@ out_dput:
63994 /*
63995 * Handle the last step of open()
63996 */
63997-static int do_last(struct nameidata *nd, struct path *path,
63998+static int do_last(struct nameidata *nd, struct path *path, struct path *link,
63999 struct file *file, const struct open_flags *op,
64000 int *opened, struct filename *name)
64001 {
64002@@ -2933,6 +2984,15 @@ static int do_last(struct nameidata *nd, struct path *path,
64003 if (error)
64004 return error;
64005
64006+ if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
64007+ error = -ENOENT;
64008+ goto out;
64009+ }
64010+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
64011+ error = -EACCES;
64012+ goto out;
64013+ }
64014+
64015 audit_inode(name, dir, LOOKUP_PARENT);
64016 error = -EISDIR;
64017 /* trailing slashes? */
64018@@ -2952,7 +3012,7 @@ retry_lookup:
64019 */
64020 }
64021 mutex_lock(&dir->d_inode->i_mutex);
64022- error = lookup_open(nd, path, file, op, got_write, opened);
64023+ error = lookup_open(nd, path, link, file, op, got_write, opened);
64024 mutex_unlock(&dir->d_inode->i_mutex);
64025
64026 if (error <= 0) {
64027@@ -2976,11 +3036,28 @@ retry_lookup:
64028 goto finish_open_created;
64029 }
64030
64031+ if (!gr_acl_handle_hidden_file(path->dentry, nd->path.mnt)) {
64032+ error = -ENOENT;
64033+ goto exit_dput;
64034+ }
64035+ if (link && gr_handle_symlink_owner(link, path->dentry->d_inode)) {
64036+ error = -EACCES;
64037+ goto exit_dput;
64038+ }
64039+
64040 /*
64041 * create/update audit record if it already exists.
64042 */
64043- if (d_is_positive(path->dentry))
64044+ if (d_is_positive(path->dentry)) {
64045+ /* only check if O_CREAT is specified, all other checks need to go
64046+ into may_open */
64047+ if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
64048+ error = -EACCES;
64049+ goto exit_dput;
64050+ }
64051+
64052 audit_inode(name, path->dentry, 0);
64053+ }
64054
64055 /*
64056 * If atomic_open() acquired write access it is dropped now due to
64057@@ -3021,6 +3098,11 @@ finish_lookup:
64058 }
64059 }
64060 BUG_ON(inode != path->dentry->d_inode);
64061+ /* if we're resolving a symlink to another symlink */
64062+ if (link && gr_handle_symlink_owner(link, inode)) {
64063+ error = -EACCES;
64064+ goto out;
64065+ }
64066 return 1;
64067 }
64068
64069@@ -3040,7 +3122,18 @@ finish_open:
64070 path_put(&save_parent);
64071 return error;
64072 }
64073+
64074+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
64075+ error = -ENOENT;
64076+ goto out;
64077+ }
64078+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
64079+ error = -EACCES;
64080+ goto out;
64081+ }
64082+
64083 audit_inode(name, nd->path.dentry, 0);
64084+
64085 error = -EISDIR;
64086 if ((open_flag & O_CREAT) && d_is_dir(nd->path.dentry))
64087 goto out;
64088@@ -3207,7 +3300,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
64089 if (unlikely(error))
64090 goto out;
64091
64092- error = do_last(nd, &path, file, op, &opened, pathname);
64093+ error = do_last(nd, &path, NULL, file, op, &opened, pathname);
64094 while (unlikely(error > 0)) { /* trailing symlink */
64095 struct path link = path;
64096 void *cookie;
64097@@ -3225,7 +3318,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
64098 error = follow_link(&link, nd, &cookie);
64099 if (unlikely(error))
64100 break;
64101- error = do_last(nd, &path, file, op, &opened, pathname);
64102+ error = do_last(nd, &path, &link, file, op, &opened, pathname);
64103 put_link(nd, &link, cookie);
64104 }
64105 out:
64106@@ -3325,9 +3418,11 @@ struct dentry *kern_path_create(int dfd, const char *pathname,
64107 goto unlock;
64108
64109 error = -EEXIST;
64110- if (d_is_positive(dentry))
64111+ if (d_is_positive(dentry)) {
64112+ if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt))
64113+ error = -ENOENT;
64114 goto fail;
64115-
64116+ }
64117 /*
64118 * Special case - lookup gave negative, but... we had foo/bar/
64119 * From the vfs_mknod() POV we just have a negative dentry -
64120@@ -3379,6 +3474,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname,
64121 }
64122 EXPORT_SYMBOL(user_path_create);
64123
64124+static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, struct filename **to, unsigned int lookup_flags)
64125+{
64126+ struct filename *tmp = getname(pathname);
64127+ struct dentry *res;
64128+ if (IS_ERR(tmp))
64129+ return ERR_CAST(tmp);
64130+ res = kern_path_create(dfd, tmp->name, path, lookup_flags);
64131+ if (IS_ERR(res))
64132+ putname(tmp);
64133+ else
64134+ *to = tmp;
64135+ return res;
64136+}
64137+
64138 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
64139 {
64140 int error = may_create(dir, dentry);
64141@@ -3442,6 +3551,17 @@ retry:
64142
64143 if (!IS_POSIXACL(path.dentry->d_inode))
64144 mode &= ~current_umask();
64145+
64146+ if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
64147+ error = -EPERM;
64148+ goto out;
64149+ }
64150+
64151+ if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
64152+ error = -EACCES;
64153+ goto out;
64154+ }
64155+
64156 error = security_path_mknod(&path, dentry, mode, dev);
64157 if (error)
64158 goto out;
64159@@ -3457,6 +3577,8 @@ retry:
64160 error = vfs_mknod(path.dentry->d_inode,dentry,mode,0);
64161 break;
64162 }
64163+ if (!error)
64164+ gr_handle_create(dentry, path.mnt);
64165 out:
64166 done_path_create(&path, dentry);
64167 if (retry_estale(error, lookup_flags)) {
64168@@ -3511,9 +3633,16 @@ retry:
64169
64170 if (!IS_POSIXACL(path.dentry->d_inode))
64171 mode &= ~current_umask();
64172+ if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
64173+ error = -EACCES;
64174+ goto out;
64175+ }
64176 error = security_path_mkdir(&path, dentry, mode);
64177 if (!error)
64178 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
64179+ if (!error)
64180+ gr_handle_create(dentry, path.mnt);
64181+out:
64182 done_path_create(&path, dentry);
64183 if (retry_estale(error, lookup_flags)) {
64184 lookup_flags |= LOOKUP_REVAL;
64185@@ -3597,6 +3726,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
64186 struct filename *name;
64187 struct dentry *dentry;
64188 struct nameidata nd;
64189+ ino_t saved_ino = 0;
64190+ dev_t saved_dev = 0;
64191 unsigned int lookup_flags = 0;
64192 retry:
64193 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
64194@@ -3629,10 +3760,21 @@ retry:
64195 error = -ENOENT;
64196 goto exit3;
64197 }
64198+
64199+ saved_ino = dentry->d_inode->i_ino;
64200+ saved_dev = gr_get_dev_from_dentry(dentry);
64201+
64202+ if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
64203+ error = -EACCES;
64204+ goto exit3;
64205+ }
64206+
64207 error = security_path_rmdir(&nd.path, dentry);
64208 if (error)
64209 goto exit3;
64210 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
64211+ if (!error && (saved_dev || saved_ino))
64212+ gr_handle_delete(saved_ino, saved_dev);
64213 exit3:
64214 dput(dentry);
64215 exit2:
64216@@ -3725,6 +3867,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
64217 struct nameidata nd;
64218 struct inode *inode = NULL;
64219 struct inode *delegated_inode = NULL;
64220+ ino_t saved_ino = 0;
64221+ dev_t saved_dev = 0;
64222 unsigned int lookup_flags = 0;
64223 retry:
64224 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
64225@@ -3751,10 +3895,22 @@ retry_deleg:
64226 if (d_is_negative(dentry))
64227 goto slashes;
64228 ihold(inode);
64229+
64230+ if (inode->i_nlink <= 1) {
64231+ saved_ino = inode->i_ino;
64232+ saved_dev = gr_get_dev_from_dentry(dentry);
64233+ }
64234+ if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
64235+ error = -EACCES;
64236+ goto exit2;
64237+ }
64238+
64239 error = security_path_unlink(&nd.path, dentry);
64240 if (error)
64241 goto exit2;
64242 error = vfs_unlink(nd.path.dentry->d_inode, dentry, &delegated_inode);
64243+ if (!error && (saved_ino || saved_dev))
64244+ gr_handle_delete(saved_ino, saved_dev);
64245 exit2:
64246 dput(dentry);
64247 }
64248@@ -3843,9 +3999,17 @@ retry:
64249 if (IS_ERR(dentry))
64250 goto out_putname;
64251
64252+ if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
64253+ error = -EACCES;
64254+ goto out;
64255+ }
64256+
64257 error = security_path_symlink(&path, dentry, from->name);
64258 if (!error)
64259 error = vfs_symlink(path.dentry->d_inode, dentry, from->name);
64260+ if (!error)
64261+ gr_handle_create(dentry, path.mnt);
64262+out:
64263 done_path_create(&path, dentry);
64264 if (retry_estale(error, lookup_flags)) {
64265 lookup_flags |= LOOKUP_REVAL;
64266@@ -3949,6 +4113,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
64267 struct dentry *new_dentry;
64268 struct path old_path, new_path;
64269 struct inode *delegated_inode = NULL;
64270+ struct filename *to = NULL;
64271 int how = 0;
64272 int error;
64273
64274@@ -3972,7 +4137,7 @@ retry:
64275 if (error)
64276 return error;
64277
64278- new_dentry = user_path_create(newdfd, newname, &new_path,
64279+ new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to,
64280 (how & LOOKUP_REVAL));
64281 error = PTR_ERR(new_dentry);
64282 if (IS_ERR(new_dentry))
64283@@ -3984,11 +4149,28 @@ retry:
64284 error = may_linkat(&old_path);
64285 if (unlikely(error))
64286 goto out_dput;
64287+
64288+ if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
64289+ old_path.dentry->d_inode,
64290+ old_path.dentry->d_inode->i_mode, to)) {
64291+ error = -EACCES;
64292+ goto out_dput;
64293+ }
64294+
64295+ if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
64296+ old_path.dentry, old_path.mnt, to)) {
64297+ error = -EACCES;
64298+ goto out_dput;
64299+ }
64300+
64301 error = security_path_link(old_path.dentry, &new_path, new_dentry);
64302 if (error)
64303 goto out_dput;
64304 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry, &delegated_inode);
64305+ if (!error)
64306+ gr_handle_create(new_dentry, new_path.mnt);
64307 out_dput:
64308+ putname(to);
64309 done_path_create(&new_path, new_dentry);
64310 if (delegated_inode) {
64311 error = break_deleg_wait(&delegated_inode);
64312@@ -4304,6 +4486,12 @@ retry_deleg:
64313 if (new_dentry == trap)
64314 goto exit5;
64315
64316+ error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
64317+ old_dentry, old_dir->d_inode, oldnd.path.mnt,
64318+ to, flags);
64319+ if (error)
64320+ goto exit5;
64321+
64322 error = security_path_rename(&oldnd.path, old_dentry,
64323 &newnd.path, new_dentry, flags);
64324 if (error)
64325@@ -4311,6 +4499,9 @@ retry_deleg:
64326 error = vfs_rename(old_dir->d_inode, old_dentry,
64327 new_dir->d_inode, new_dentry,
64328 &delegated_inode, flags);
64329+ if (!error)
64330+ gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
64331+ new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0, flags);
64332 exit5:
64333 dput(new_dentry);
64334 exit4:
64335@@ -4367,14 +4558,24 @@ EXPORT_SYMBOL(vfs_whiteout);
64336
64337 int readlink_copy(char __user *buffer, int buflen, const char *link)
64338 {
64339+ char tmpbuf[64];
64340+ const char *newlink;
64341 int len = PTR_ERR(link);
64342+
64343 if (IS_ERR(link))
64344 goto out;
64345
64346 len = strlen(link);
64347 if (len > (unsigned) buflen)
64348 len = buflen;
64349- if (copy_to_user(buffer, link, len))
64350+
64351+ if (len < sizeof(tmpbuf)) {
64352+ memcpy(tmpbuf, link, len);
64353+ newlink = tmpbuf;
64354+ } else
64355+ newlink = link;
64356+
64357+ if (copy_to_user(buffer, newlink, len))
64358 len = -EFAULT;
64359 out:
64360 return len;
64361diff --git a/fs/namespace.c b/fs/namespace.c
64362index 5b66b2b..4d8290d 100644
64363--- a/fs/namespace.c
64364+++ b/fs/namespace.c
64365@@ -1369,6 +1369,8 @@ void umount_tree(struct mount *mnt, int how)
64366 }
64367 if (last) {
64368 last->mnt_hash.next = unmounted.first;
64369+ if (unmounted.first)
64370+ unmounted.first->pprev = &last->mnt_hash.next;
64371 unmounted.first = tmp_list.first;
64372 unmounted.first->pprev = &unmounted.first;
64373 }
64374@@ -1445,6 +1447,9 @@ static int do_umount(struct mount *mnt, int flags)
64375 if (!(sb->s_flags & MS_RDONLY))
64376 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
64377 up_write(&sb->s_umount);
64378+
64379+ gr_log_remount(mnt->mnt_devname, retval);
64380+
64381 return retval;
64382 }
64383
64384@@ -1467,6 +1472,9 @@ static int do_umount(struct mount *mnt, int flags)
64385 }
64386 unlock_mount_hash();
64387 namespace_unlock();
64388+
64389+ gr_log_unmount(mnt->mnt_devname, retval);
64390+
64391 return retval;
64392 }
64393
64394@@ -1517,7 +1525,7 @@ static inline bool may_mount(void)
64395 * unixes. Our API is identical to OSF/1 to avoid making a mess of AMD
64396 */
64397
64398-SYSCALL_DEFINE2(umount, char __user *, name, int, flags)
64399+SYSCALL_DEFINE2(umount, const char __user *, name, int, flags)
64400 {
64401 struct path path;
64402 struct mount *mnt;
64403@@ -1559,7 +1567,7 @@ out:
64404 /*
64405 * The 2.0 compatible umount. No flags.
64406 */
64407-SYSCALL_DEFINE1(oldumount, char __user *, name)
64408+SYSCALL_DEFINE1(oldumount, const char __user *, name)
64409 {
64410 return sys_umount(name, 0);
64411 }
64412@@ -2621,6 +2629,16 @@ long do_mount(const char *dev_name, const char __user *dir_name,
64413 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
64414 MS_STRICTATIME);
64415
64416+ if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
64417+ retval = -EPERM;
64418+ goto dput_out;
64419+ }
64420+
64421+ if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
64422+ retval = -EPERM;
64423+ goto dput_out;
64424+ }
64425+
64426 if (flags & MS_REMOUNT)
64427 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
64428 data_page);
64429@@ -2634,7 +2652,10 @@ long do_mount(const char *dev_name, const char __user *dir_name,
64430 retval = do_new_mount(&path, type_page, flags, mnt_flags,
64431 dev_name, data_page);
64432 dput_out:
64433+ gr_log_mount(dev_name, &path, retval);
64434+
64435 path_put(&path);
64436+
64437 return retval;
64438 }
64439
64440@@ -2652,7 +2673,7 @@ static void free_mnt_ns(struct mnt_namespace *ns)
64441 * number incrementing at 10Ghz will take 12,427 years to wrap which
64442 * is effectively never, so we can ignore the possibility.
64443 */
64444-static atomic64_t mnt_ns_seq = ATOMIC64_INIT(1);
64445+static atomic64_unchecked_t mnt_ns_seq = ATOMIC64_INIT(1);
64446
64447 static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
64448 {
64449@@ -2667,7 +2688,7 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
64450 kfree(new_ns);
64451 return ERR_PTR(ret);
64452 }
64453- new_ns->seq = atomic64_add_return(1, &mnt_ns_seq);
64454+ new_ns->seq = atomic64_inc_return_unchecked(&mnt_ns_seq);
64455 atomic_set(&new_ns->count, 1);
64456 new_ns->root = NULL;
64457 INIT_LIST_HEAD(&new_ns->list);
64458@@ -2677,7 +2698,7 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
64459 return new_ns;
64460 }
64461
64462-struct mnt_namespace *copy_mnt_ns(unsigned long flags, struct mnt_namespace *ns,
64463+__latent_entropy struct mnt_namespace *copy_mnt_ns(unsigned long flags, struct mnt_namespace *ns,
64464 struct user_namespace *user_ns, struct fs_struct *new_fs)
64465 {
64466 struct mnt_namespace *new_ns;
64467@@ -2798,8 +2819,8 @@ struct dentry *mount_subtree(struct vfsmount *mnt, const char *name)
64468 }
64469 EXPORT_SYMBOL(mount_subtree);
64470
64471-SYSCALL_DEFINE5(mount, char __user *, dev_name, char __user *, dir_name,
64472- char __user *, type, unsigned long, flags, void __user *, data)
64473+SYSCALL_DEFINE5(mount, const char __user *, dev_name, const char __user *, dir_name,
64474+ const char __user *, type, unsigned long, flags, void __user *, data)
64475 {
64476 int ret;
64477 char *kernel_type;
64478@@ -2905,6 +2926,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
64479 if (error)
64480 goto out2;
64481
64482+ if (gr_handle_chroot_pivot()) {
64483+ error = -EPERM;
64484+ goto out2;
64485+ }
64486+
64487 get_fs_root(current->fs, &root);
64488 old_mp = lock_mount(&old);
64489 error = PTR_ERR(old_mp);
64490@@ -3176,7 +3202,7 @@ static int mntns_install(struct nsproxy *nsproxy, void *ns)
64491 !ns_capable(current_user_ns(), CAP_SYS_ADMIN))
64492 return -EPERM;
64493
64494- if (fs->users != 1)
64495+ if (atomic_read(&fs->users) != 1)
64496 return -EINVAL;
64497
64498 get_mnt_ns(mnt_ns);
64499diff --git a/fs/nfs/callback_xdr.c b/fs/nfs/callback_xdr.c
64500index f4ccfe6..a5cf064 100644
64501--- a/fs/nfs/callback_xdr.c
64502+++ b/fs/nfs/callback_xdr.c
64503@@ -51,7 +51,7 @@ struct callback_op {
64504 callback_decode_arg_t decode_args;
64505 callback_encode_res_t encode_res;
64506 long res_maxsize;
64507-};
64508+} __do_const;
64509
64510 static struct callback_op callback_ops[];
64511
64512diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
64513index 00689a8..b162632 100644
64514--- a/fs/nfs/inode.c
64515+++ b/fs/nfs/inode.c
64516@@ -1232,16 +1232,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
64517 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
64518 }
64519
64520-static atomic_long_t nfs_attr_generation_counter;
64521+static atomic_long_unchecked_t nfs_attr_generation_counter;
64522
64523 static unsigned long nfs_read_attr_generation_counter(void)
64524 {
64525- return atomic_long_read(&nfs_attr_generation_counter);
64526+ return atomic_long_read_unchecked(&nfs_attr_generation_counter);
64527 }
64528
64529 unsigned long nfs_inc_attr_generation_counter(void)
64530 {
64531- return atomic_long_inc_return(&nfs_attr_generation_counter);
64532+ return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
64533 }
64534
64535 void nfs_fattr_init(struct nfs_fattr *fattr)
64536diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c
64537index 0beb023..3f685ec 100644
64538--- a/fs/nfsd/nfs4proc.c
64539+++ b/fs/nfsd/nfs4proc.c
64540@@ -1198,7 +1198,7 @@ struct nfsd4_operation {
64541 nfsd4op_rsize op_rsize_bop;
64542 stateid_getter op_get_currentstateid;
64543 stateid_setter op_set_currentstateid;
64544-};
64545+} __do_const;
64546
64547 static struct nfsd4_operation nfsd4_ops[];
64548
64549diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
64550index eeea7a9..f3ba422 100644
64551--- a/fs/nfsd/nfs4xdr.c
64552+++ b/fs/nfsd/nfs4xdr.c
64553@@ -1543,7 +1543,7 @@ nfsd4_decode_notsupp(struct nfsd4_compoundargs *argp, void *p)
64554
64555 typedef __be32(*nfsd4_dec)(struct nfsd4_compoundargs *argp, void *);
64556
64557-static nfsd4_dec nfsd4_dec_ops[] = {
64558+static const nfsd4_dec nfsd4_dec_ops[] = {
64559 [OP_ACCESS] = (nfsd4_dec)nfsd4_decode_access,
64560 [OP_CLOSE] = (nfsd4_dec)nfsd4_decode_close,
64561 [OP_COMMIT] = (nfsd4_dec)nfsd4_decode_commit,
64562diff --git a/fs/nfsd/nfscache.c b/fs/nfsd/nfscache.c
64563index 122f691..a00e2e0 100644
64564--- a/fs/nfsd/nfscache.c
64565+++ b/fs/nfsd/nfscache.c
64566@@ -537,7 +537,7 @@ nfsd_cache_update(struct svc_rqst *rqstp, int cachetype, __be32 *statp)
64567 struct kvec *resv = &rqstp->rq_res.head[0], *cachv;
64568 u32 hash;
64569 struct nfsd_drc_bucket *b;
64570- int len;
64571+ long len;
64572 size_t bufsize = 0;
64573
64574 if (!rp)
64575@@ -546,11 +546,14 @@ nfsd_cache_update(struct svc_rqst *rqstp, int cachetype, __be32 *statp)
64576 hash = nfsd_cache_hash(rp->c_xid);
64577 b = &drc_hashtbl[hash];
64578
64579- len = resv->iov_len - ((char*)statp - (char*)resv->iov_base);
64580- len >>= 2;
64581+ if (statp) {
64582+ len = (char*)statp - (char*)resv->iov_base;
64583+ len = resv->iov_len - len;
64584+ len >>= 2;
64585+ }
64586
64587 /* Don't cache excessive amounts of data and XDR failures */
64588- if (!statp || len > (256 >> 2)) {
64589+ if (!statp || len > (256 >> 2) || len < 0) {
64590 nfsd_reply_cache_free(b, rp);
64591 return;
64592 }
64593@@ -558,7 +561,7 @@ nfsd_cache_update(struct svc_rqst *rqstp, int cachetype, __be32 *statp)
64594 switch (cachetype) {
64595 case RC_REPLSTAT:
64596 if (len != 1)
64597- printk("nfsd: RC_REPLSTAT/reply len %d!\n",len);
64598+ printk("nfsd: RC_REPLSTAT/reply len %ld!\n",len);
64599 rp->c_replstat = *statp;
64600 break;
64601 case RC_REPLBUFF:
64602diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
64603index 989129e..42e019e 100644
64604--- a/fs/nfsd/vfs.c
64605+++ b/fs/nfsd/vfs.c
64606@@ -872,7 +872,7 @@ __be32 nfsd_readv(struct file *file, loff_t offset, struct kvec *vec, int vlen,
64607
64608 oldfs = get_fs();
64609 set_fs(KERNEL_DS);
64610- host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
64611+ host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
64612 set_fs(oldfs);
64613 return nfsd_finish_read(file, count, host_err);
64614 }
64615@@ -960,7 +960,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
64616
64617 /* Write the data. */
64618 oldfs = get_fs(); set_fs(KERNEL_DS);
64619- host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &pos);
64620+ host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &pos);
64621 set_fs(oldfs);
64622 if (host_err < 0)
64623 goto out_nfserr;
64624@@ -1502,7 +1502,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
64625 */
64626
64627 oldfs = get_fs(); set_fs(KERNEL_DS);
64628- host_err = inode->i_op->readlink(path.dentry, (char __user *)buf, *lenp);
64629+ host_err = inode->i_op->readlink(path.dentry, (char __force_user *)buf, *lenp);
64630 set_fs(oldfs);
64631
64632 if (host_err < 0)
64633diff --git a/fs/nls/nls_base.c b/fs/nls/nls_base.c
64634index 52ccd34..7a6b202 100644
64635--- a/fs/nls/nls_base.c
64636+++ b/fs/nls/nls_base.c
64637@@ -234,21 +234,25 @@ EXPORT_SYMBOL(utf16s_to_utf8s);
64638
64639 int __register_nls(struct nls_table *nls, struct module *owner)
64640 {
64641- struct nls_table ** tmp = &tables;
64642+ struct nls_table *tmp = tables;
64643
64644 if (nls->next)
64645 return -EBUSY;
64646
64647- nls->owner = owner;
64648+ pax_open_kernel();
64649+ *(void **)&nls->owner = owner;
64650+ pax_close_kernel();
64651 spin_lock(&nls_lock);
64652- while (*tmp) {
64653- if (nls == *tmp) {
64654+ while (tmp) {
64655+ if (nls == tmp) {
64656 spin_unlock(&nls_lock);
64657 return -EBUSY;
64658 }
64659- tmp = &(*tmp)->next;
64660+ tmp = tmp->next;
64661 }
64662- nls->next = tables;
64663+ pax_open_kernel();
64664+ *(struct nls_table **)&nls->next = tables;
64665+ pax_close_kernel();
64666 tables = nls;
64667 spin_unlock(&nls_lock);
64668 return 0;
64669@@ -257,12 +261,14 @@ EXPORT_SYMBOL(__register_nls);
64670
64671 int unregister_nls(struct nls_table * nls)
64672 {
64673- struct nls_table ** tmp = &tables;
64674+ struct nls_table * const * tmp = &tables;
64675
64676 spin_lock(&nls_lock);
64677 while (*tmp) {
64678 if (nls == *tmp) {
64679- *tmp = nls->next;
64680+ pax_open_kernel();
64681+ *(struct nls_table **)tmp = nls->next;
64682+ pax_close_kernel();
64683 spin_unlock(&nls_lock);
64684 return 0;
64685 }
64686@@ -272,7 +278,7 @@ int unregister_nls(struct nls_table * nls)
64687 return -EINVAL;
64688 }
64689
64690-static struct nls_table *find_nls(char *charset)
64691+static struct nls_table *find_nls(const char *charset)
64692 {
64693 struct nls_table *nls;
64694 spin_lock(&nls_lock);
64695@@ -288,7 +294,7 @@ static struct nls_table *find_nls(char *charset)
64696 return nls;
64697 }
64698
64699-struct nls_table *load_nls(char *charset)
64700+struct nls_table *load_nls(const char *charset)
64701 {
64702 return try_then_request_module(find_nls(charset), "nls_%s", charset);
64703 }
64704diff --git a/fs/nls/nls_euc-jp.c b/fs/nls/nls_euc-jp.c
64705index 162b3f1..6076a7c 100644
64706--- a/fs/nls/nls_euc-jp.c
64707+++ b/fs/nls/nls_euc-jp.c
64708@@ -560,8 +560,10 @@ static int __init init_nls_euc_jp(void)
64709 p_nls = load_nls("cp932");
64710
64711 if (p_nls) {
64712- table.charset2upper = p_nls->charset2upper;
64713- table.charset2lower = p_nls->charset2lower;
64714+ pax_open_kernel();
64715+ *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
64716+ *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
64717+ pax_close_kernel();
64718 return register_nls(&table);
64719 }
64720
64721diff --git a/fs/nls/nls_koi8-ru.c b/fs/nls/nls_koi8-ru.c
64722index a80a741..7b96e1b 100644
64723--- a/fs/nls/nls_koi8-ru.c
64724+++ b/fs/nls/nls_koi8-ru.c
64725@@ -62,8 +62,10 @@ static int __init init_nls_koi8_ru(void)
64726 p_nls = load_nls("koi8-u");
64727
64728 if (p_nls) {
64729- table.charset2upper = p_nls->charset2upper;
64730- table.charset2lower = p_nls->charset2lower;
64731+ pax_open_kernel();
64732+ *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
64733+ *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
64734+ pax_close_kernel();
64735 return register_nls(&table);
64736 }
64737
64738diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
64739index c991616..5ae51af 100644
64740--- a/fs/notify/fanotify/fanotify_user.c
64741+++ b/fs/notify/fanotify/fanotify_user.c
64742@@ -216,8 +216,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
64743
64744 fd = fanotify_event_metadata.fd;
64745 ret = -EFAULT;
64746- if (copy_to_user(buf, &fanotify_event_metadata,
64747- fanotify_event_metadata.event_len))
64748+ if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
64749+ copy_to_user(buf, &fanotify_event_metadata, fanotify_event_metadata.event_len))
64750 goto out_close_fd;
64751
64752 #ifdef CONFIG_FANOTIFY_ACCESS_PERMISSIONS
64753diff --git a/fs/notify/notification.c b/fs/notify/notification.c
64754index a95d8e0..a91a5fd 100644
64755--- a/fs/notify/notification.c
64756+++ b/fs/notify/notification.c
64757@@ -48,7 +48,7 @@
64758 #include <linux/fsnotify_backend.h>
64759 #include "fsnotify.h"
64760
64761-static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
64762+static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
64763
64764 /**
64765 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
64766@@ -56,7 +56,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
64767 */
64768 u32 fsnotify_get_cookie(void)
64769 {
64770- return atomic_inc_return(&fsnotify_sync_cookie);
64771+ return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
64772 }
64773 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
64774
64775diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
64776index 9e38daf..5727cae 100644
64777--- a/fs/ntfs/dir.c
64778+++ b/fs/ntfs/dir.c
64779@@ -1310,7 +1310,7 @@ find_next_index_buffer:
64780 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
64781 ~(s64)(ndir->itype.index.block_size - 1)));
64782 /* Bounds checks. */
64783- if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
64784+ if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
64785 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
64786 "inode 0x%lx or driver bug.", vdir->i_ino);
64787 goto err_out;
64788diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
64789index 643faa4..ef9027e 100644
64790--- a/fs/ntfs/file.c
64791+++ b/fs/ntfs/file.c
64792@@ -1280,7 +1280,7 @@ static inline size_t ntfs_copy_from_user(struct page **pages,
64793 char *addr;
64794 size_t total = 0;
64795 unsigned len;
64796- int left;
64797+ unsigned left;
64798
64799 do {
64800 len = PAGE_CACHE_SIZE - ofs;
64801diff --git a/fs/ntfs/super.c b/fs/ntfs/super.c
64802index 9e1e112..241a52a 100644
64803--- a/fs/ntfs/super.c
64804+++ b/fs/ntfs/super.c
64805@@ -688,7 +688,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
64806 if (!silent)
64807 ntfs_error(sb, "Primary boot sector is invalid.");
64808 } else if (!silent)
64809- ntfs_error(sb, read_err_str, "primary");
64810+ ntfs_error(sb, read_err_str, "%s", "primary");
64811 if (!(NTFS_SB(sb)->on_errors & ON_ERRORS_RECOVER)) {
64812 if (bh_primary)
64813 brelse(bh_primary);
64814@@ -704,7 +704,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
64815 goto hotfix_primary_boot_sector;
64816 brelse(bh_backup);
64817 } else if (!silent)
64818- ntfs_error(sb, read_err_str, "backup");
64819+ ntfs_error(sb, read_err_str, "%s", "backup");
64820 /* Try to read NT3.51- backup boot sector. */
64821 if ((bh_backup = sb_bread(sb, nr_blocks >> 1))) {
64822 if (is_boot_sector_ntfs(sb, (NTFS_BOOT_SECTOR*)
64823@@ -715,7 +715,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
64824 "sector.");
64825 brelse(bh_backup);
64826 } else if (!silent)
64827- ntfs_error(sb, read_err_str, "backup");
64828+ ntfs_error(sb, read_err_str, "%s", "backup");
64829 /* We failed. Cleanup and return. */
64830 if (bh_primary)
64831 brelse(bh_primary);
64832diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
64833index 0440134..d52c93a 100644
64834--- a/fs/ocfs2/localalloc.c
64835+++ b/fs/ocfs2/localalloc.c
64836@@ -1320,7 +1320,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
64837 goto bail;
64838 }
64839
64840- atomic_inc(&osb->alloc_stats.moves);
64841+ atomic_inc_unchecked(&osb->alloc_stats.moves);
64842
64843 bail:
64844 if (handle)
64845diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
64846index bbec539..7b266d5 100644
64847--- a/fs/ocfs2/ocfs2.h
64848+++ b/fs/ocfs2/ocfs2.h
64849@@ -236,11 +236,11 @@ enum ocfs2_vol_state
64850
64851 struct ocfs2_alloc_stats
64852 {
64853- atomic_t moves;
64854- atomic_t local_data;
64855- atomic_t bitmap_data;
64856- atomic_t bg_allocs;
64857- atomic_t bg_extends;
64858+ atomic_unchecked_t moves;
64859+ atomic_unchecked_t local_data;
64860+ atomic_unchecked_t bitmap_data;
64861+ atomic_unchecked_t bg_allocs;
64862+ atomic_unchecked_t bg_extends;
64863 };
64864
64865 enum ocfs2_local_alloc_state
64866diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
64867index 0cb889a..6a26b24 100644
64868--- a/fs/ocfs2/suballoc.c
64869+++ b/fs/ocfs2/suballoc.c
64870@@ -867,7 +867,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
64871 mlog_errno(status);
64872 goto bail;
64873 }
64874- atomic_inc(&osb->alloc_stats.bg_extends);
64875+ atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
64876
64877 /* You should never ask for this much metadata */
64878 BUG_ON(bits_wanted >
64879@@ -2014,7 +2014,7 @@ int ocfs2_claim_metadata(handle_t *handle,
64880 mlog_errno(status);
64881 goto bail;
64882 }
64883- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
64884+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
64885
64886 *suballoc_loc = res.sr_bg_blkno;
64887 *suballoc_bit_start = res.sr_bit_offset;
64888@@ -2180,7 +2180,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
64889 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
64890 res->sr_bits);
64891
64892- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
64893+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
64894
64895 BUG_ON(res->sr_bits != 1);
64896
64897@@ -2222,7 +2222,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
64898 mlog_errno(status);
64899 goto bail;
64900 }
64901- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
64902+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
64903
64904 BUG_ON(res.sr_bits != 1);
64905
64906@@ -2326,7 +2326,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
64907 cluster_start,
64908 num_clusters);
64909 if (!status)
64910- atomic_inc(&osb->alloc_stats.local_data);
64911+ atomic_inc_unchecked(&osb->alloc_stats.local_data);
64912 } else {
64913 if (min_clusters > (osb->bitmap_cpg - 1)) {
64914 /* The only paths asking for contiguousness
64915@@ -2352,7 +2352,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
64916 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
64917 res.sr_bg_blkno,
64918 res.sr_bit_offset);
64919- atomic_inc(&osb->alloc_stats.bitmap_data);
64920+ atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
64921 *num_clusters = res.sr_bits;
64922 }
64923 }
64924diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
64925index 93c85bc..02f68a4 100644
64926--- a/fs/ocfs2/super.c
64927+++ b/fs/ocfs2/super.c
64928@@ -300,11 +300,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
64929 "%10s => GlobalAllocs: %d LocalAllocs: %d "
64930 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
64931 "Stats",
64932- atomic_read(&osb->alloc_stats.bitmap_data),
64933- atomic_read(&osb->alloc_stats.local_data),
64934- atomic_read(&osb->alloc_stats.bg_allocs),
64935- atomic_read(&osb->alloc_stats.moves),
64936- atomic_read(&osb->alloc_stats.bg_extends));
64937+ atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
64938+ atomic_read_unchecked(&osb->alloc_stats.local_data),
64939+ atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
64940+ atomic_read_unchecked(&osb->alloc_stats.moves),
64941+ atomic_read_unchecked(&osb->alloc_stats.bg_extends));
64942
64943 out += snprintf(buf + out, len - out,
64944 "%10s => State: %u Descriptor: %llu Size: %u bits "
64945@@ -2104,11 +2104,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
64946
64947 mutex_init(&osb->system_file_mutex);
64948
64949- atomic_set(&osb->alloc_stats.moves, 0);
64950- atomic_set(&osb->alloc_stats.local_data, 0);
64951- atomic_set(&osb->alloc_stats.bitmap_data, 0);
64952- atomic_set(&osb->alloc_stats.bg_allocs, 0);
64953- atomic_set(&osb->alloc_stats.bg_extends, 0);
64954+ atomic_set_unchecked(&osb->alloc_stats.moves, 0);
64955+ atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
64956+ atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
64957+ atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
64958+ atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
64959
64960 /* Copy the blockcheck stats from the superblock probe */
64961 osb->osb_ecc_stats = *stats;
64962diff --git a/fs/open.c b/fs/open.c
64963index de92c13..52d2a6c 100644
64964--- a/fs/open.c
64965+++ b/fs/open.c
64966@@ -32,6 +32,8 @@
64967 #include <linux/dnotify.h>
64968 #include <linux/compat.h>
64969
64970+#define CREATE_TRACE_POINTS
64971+#include <trace/events/fs.h>
64972 #include "internal.h"
64973
64974 int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
64975@@ -103,6 +105,8 @@ long vfs_truncate(struct path *path, loff_t length)
64976 error = locks_verify_truncate(inode, NULL, length);
64977 if (!error)
64978 error = security_path_truncate(path);
64979+ if (!error && !gr_acl_handle_truncate(path->dentry, path->mnt))
64980+ error = -EACCES;
64981 if (!error)
64982 error = do_truncate(path->dentry, length, 0, NULL);
64983
64984@@ -187,6 +191,8 @@ static long do_sys_ftruncate(unsigned int fd, loff_t length, int small)
64985 error = locks_verify_truncate(inode, f.file, length);
64986 if (!error)
64987 error = security_path_truncate(&f.file->f_path);
64988+ if (!error && !gr_acl_handle_truncate(f.file->f_path.dentry, f.file->f_path.mnt))
64989+ error = -EACCES;
64990 if (!error)
64991 error = do_truncate(dentry, length, ATTR_MTIME|ATTR_CTIME, f.file);
64992 sb_end_write(inode->i_sb);
64993@@ -380,6 +386,9 @@ retry:
64994 if (__mnt_is_readonly(path.mnt))
64995 res = -EROFS;
64996
64997+ if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
64998+ res = -EACCES;
64999+
65000 out_path_release:
65001 path_put(&path);
65002 if (retry_estale(res, lookup_flags)) {
65003@@ -411,6 +420,8 @@ retry:
65004 if (error)
65005 goto dput_and_out;
65006
65007+ gr_log_chdir(path.dentry, path.mnt);
65008+
65009 set_fs_pwd(current->fs, &path);
65010
65011 dput_and_out:
65012@@ -440,6 +451,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
65013 goto out_putf;
65014
65015 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
65016+
65017+ if (!error && !gr_chroot_fchdir(f.file->f_path.dentry, f.file->f_path.mnt))
65018+ error = -EPERM;
65019+
65020+ if (!error)
65021+ gr_log_chdir(f.file->f_path.dentry, f.file->f_path.mnt);
65022+
65023 if (!error)
65024 set_fs_pwd(current->fs, &f.file->f_path);
65025 out_putf:
65026@@ -469,7 +487,13 @@ retry:
65027 if (error)
65028 goto dput_and_out;
65029
65030+ if (gr_handle_chroot_chroot(path.dentry, path.mnt))
65031+ goto dput_and_out;
65032+
65033 set_fs_root(current->fs, &path);
65034+
65035+ gr_handle_chroot_chdir(&path);
65036+
65037 error = 0;
65038 dput_and_out:
65039 path_put(&path);
65040@@ -493,6 +517,16 @@ static int chmod_common(struct path *path, umode_t mode)
65041 return error;
65042 retry_deleg:
65043 mutex_lock(&inode->i_mutex);
65044+
65045+ if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
65046+ error = -EACCES;
65047+ goto out_unlock;
65048+ }
65049+ if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
65050+ error = -EACCES;
65051+ goto out_unlock;
65052+ }
65053+
65054 error = security_path_chmod(path, mode);
65055 if (error)
65056 goto out_unlock;
65057@@ -558,6 +592,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
65058 uid = make_kuid(current_user_ns(), user);
65059 gid = make_kgid(current_user_ns(), group);
65060
65061+ if (!gr_acl_handle_chown(path->dentry, path->mnt))
65062+ return -EACCES;
65063+
65064 newattrs.ia_valid = ATTR_CTIME;
65065 if (user != (uid_t) -1) {
65066 if (!uid_valid(uid))
65067@@ -1002,6 +1039,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
65068 } else {
65069 fsnotify_open(f);
65070 fd_install(fd, f);
65071+ trace_do_sys_open(tmp->name, flags, mode);
65072 }
65073 }
65074 putname(tmp);
65075diff --git a/fs/pipe.c b/fs/pipe.c
65076index 21981e5..3d5f55c 100644
65077--- a/fs/pipe.c
65078+++ b/fs/pipe.c
65079@@ -56,7 +56,7 @@ unsigned int pipe_min_size = PAGE_SIZE;
65080
65081 static void pipe_lock_nested(struct pipe_inode_info *pipe, int subclass)
65082 {
65083- if (pipe->files)
65084+ if (atomic_read(&pipe->files))
65085 mutex_lock_nested(&pipe->mutex, subclass);
65086 }
65087
65088@@ -71,7 +71,7 @@ EXPORT_SYMBOL(pipe_lock);
65089
65090 void pipe_unlock(struct pipe_inode_info *pipe)
65091 {
65092- if (pipe->files)
65093+ if (atomic_read(&pipe->files))
65094 mutex_unlock(&pipe->mutex);
65095 }
65096 EXPORT_SYMBOL(pipe_unlock);
65097@@ -292,9 +292,9 @@ pipe_read(struct kiocb *iocb, struct iov_iter *to)
65098 }
65099 if (bufs) /* More to do? */
65100 continue;
65101- if (!pipe->writers)
65102+ if (!atomic_read(&pipe->writers))
65103 break;
65104- if (!pipe->waiting_writers) {
65105+ if (!atomic_read(&pipe->waiting_writers)) {
65106 /* syscall merging: Usually we must not sleep
65107 * if O_NONBLOCK is set, or if we got some data.
65108 * But if a writer sleeps in kernel space, then
65109@@ -351,7 +351,7 @@ pipe_write(struct kiocb *iocb, struct iov_iter *from)
65110
65111 __pipe_lock(pipe);
65112
65113- if (!pipe->readers) {
65114+ if (!atomic_read(&pipe->readers)) {
65115 send_sig(SIGPIPE, current, 0);
65116 ret = -EPIPE;
65117 goto out;
65118@@ -387,7 +387,7 @@ pipe_write(struct kiocb *iocb, struct iov_iter *from)
65119 for (;;) {
65120 int bufs;
65121
65122- if (!pipe->readers) {
65123+ if (!atomic_read(&pipe->readers)) {
65124 send_sig(SIGPIPE, current, 0);
65125 if (!ret)
65126 ret = -EPIPE;
65127@@ -455,9 +455,9 @@ pipe_write(struct kiocb *iocb, struct iov_iter *from)
65128 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
65129 do_wakeup = 0;
65130 }
65131- pipe->waiting_writers++;
65132+ atomic_inc(&pipe->waiting_writers);
65133 pipe_wait(pipe);
65134- pipe->waiting_writers--;
65135+ atomic_dec(&pipe->waiting_writers);
65136 }
65137 out:
65138 __pipe_unlock(pipe);
65139@@ -512,7 +512,7 @@ pipe_poll(struct file *filp, poll_table *wait)
65140 mask = 0;
65141 if (filp->f_mode & FMODE_READ) {
65142 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
65143- if (!pipe->writers && filp->f_version != pipe->w_counter)
65144+ if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
65145 mask |= POLLHUP;
65146 }
65147
65148@@ -522,7 +522,7 @@ pipe_poll(struct file *filp, poll_table *wait)
65149 * Most Unices do not set POLLERR for FIFOs but on Linux they
65150 * behave exactly like pipes for poll().
65151 */
65152- if (!pipe->readers)
65153+ if (!atomic_read(&pipe->readers))
65154 mask |= POLLERR;
65155 }
65156
65157@@ -534,7 +534,7 @@ static void put_pipe_info(struct inode *inode, struct pipe_inode_info *pipe)
65158 int kill = 0;
65159
65160 spin_lock(&inode->i_lock);
65161- if (!--pipe->files) {
65162+ if (atomic_dec_and_test(&pipe->files)) {
65163 inode->i_pipe = NULL;
65164 kill = 1;
65165 }
65166@@ -551,11 +551,11 @@ pipe_release(struct inode *inode, struct file *file)
65167
65168 __pipe_lock(pipe);
65169 if (file->f_mode & FMODE_READ)
65170- pipe->readers--;
65171+ atomic_dec(&pipe->readers);
65172 if (file->f_mode & FMODE_WRITE)
65173- pipe->writers--;
65174+ atomic_dec(&pipe->writers);
65175
65176- if (pipe->readers || pipe->writers) {
65177+ if (atomic_read(&pipe->readers) || atomic_read(&pipe->writers)) {
65178 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
65179 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
65180 kill_fasync(&pipe->fasync_writers, SIGIO, POLL_OUT);
65181@@ -620,7 +620,7 @@ void free_pipe_info(struct pipe_inode_info *pipe)
65182 kfree(pipe);
65183 }
65184
65185-static struct vfsmount *pipe_mnt __read_mostly;
65186+struct vfsmount *pipe_mnt __read_mostly;
65187
65188 /*
65189 * pipefs_dname() is called from d_path().
65190@@ -650,8 +650,9 @@ static struct inode * get_pipe_inode(void)
65191 goto fail_iput;
65192
65193 inode->i_pipe = pipe;
65194- pipe->files = 2;
65195- pipe->readers = pipe->writers = 1;
65196+ atomic_set(&pipe->files, 2);
65197+ atomic_set(&pipe->readers, 1);
65198+ atomic_set(&pipe->writers, 1);
65199 inode->i_fop = &pipefifo_fops;
65200
65201 /*
65202@@ -830,17 +831,17 @@ static int fifo_open(struct inode *inode, struct file *filp)
65203 spin_lock(&inode->i_lock);
65204 if (inode->i_pipe) {
65205 pipe = inode->i_pipe;
65206- pipe->files++;
65207+ atomic_inc(&pipe->files);
65208 spin_unlock(&inode->i_lock);
65209 } else {
65210 spin_unlock(&inode->i_lock);
65211 pipe = alloc_pipe_info();
65212 if (!pipe)
65213 return -ENOMEM;
65214- pipe->files = 1;
65215+ atomic_set(&pipe->files, 1);
65216 spin_lock(&inode->i_lock);
65217 if (unlikely(inode->i_pipe)) {
65218- inode->i_pipe->files++;
65219+ atomic_inc(&inode->i_pipe->files);
65220 spin_unlock(&inode->i_lock);
65221 free_pipe_info(pipe);
65222 pipe = inode->i_pipe;
65223@@ -865,10 +866,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
65224 * opened, even when there is no process writing the FIFO.
65225 */
65226 pipe->r_counter++;
65227- if (pipe->readers++ == 0)
65228+ if (atomic_inc_return(&pipe->readers) == 1)
65229 wake_up_partner(pipe);
65230
65231- if (!is_pipe && !pipe->writers) {
65232+ if (!is_pipe && !atomic_read(&pipe->writers)) {
65233 if ((filp->f_flags & O_NONBLOCK)) {
65234 /* suppress POLLHUP until we have
65235 * seen a writer */
65236@@ -887,14 +888,14 @@ static int fifo_open(struct inode *inode, struct file *filp)
65237 * errno=ENXIO when there is no process reading the FIFO.
65238 */
65239 ret = -ENXIO;
65240- if (!is_pipe && (filp->f_flags & O_NONBLOCK) && !pipe->readers)
65241+ if (!is_pipe && (filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
65242 goto err;
65243
65244 pipe->w_counter++;
65245- if (!pipe->writers++)
65246+ if (atomic_inc_return(&pipe->writers) == 1)
65247 wake_up_partner(pipe);
65248
65249- if (!is_pipe && !pipe->readers) {
65250+ if (!is_pipe && !atomic_read(&pipe->readers)) {
65251 if (wait_for_partner(pipe, &pipe->r_counter))
65252 goto err_wr;
65253 }
65254@@ -908,11 +909,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
65255 * the process can at least talk to itself.
65256 */
65257
65258- pipe->readers++;
65259- pipe->writers++;
65260+ atomic_inc(&pipe->readers);
65261+ atomic_inc(&pipe->writers);
65262 pipe->r_counter++;
65263 pipe->w_counter++;
65264- if (pipe->readers == 1 || pipe->writers == 1)
65265+ if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
65266 wake_up_partner(pipe);
65267 break;
65268
65269@@ -926,13 +927,13 @@ static int fifo_open(struct inode *inode, struct file *filp)
65270 return 0;
65271
65272 err_rd:
65273- if (!--pipe->readers)
65274+ if (atomic_dec_and_test(&pipe->readers))
65275 wake_up_interruptible(&pipe->wait);
65276 ret = -ERESTARTSYS;
65277 goto err;
65278
65279 err_wr:
65280- if (!--pipe->writers)
65281+ if (atomic_dec_and_test(&pipe->writers))
65282 wake_up_interruptible(&pipe->wait);
65283 ret = -ERESTARTSYS;
65284 goto err;
65285diff --git a/fs/posix_acl.c b/fs/posix_acl.c
65286index 0855f77..6787d50 100644
65287--- a/fs/posix_acl.c
65288+++ b/fs/posix_acl.c
65289@@ -20,6 +20,7 @@
65290 #include <linux/xattr.h>
65291 #include <linux/export.h>
65292 #include <linux/user_namespace.h>
65293+#include <linux/grsecurity.h>
65294
65295 struct posix_acl **acl_by_type(struct inode *inode, int type)
65296 {
65297@@ -277,7 +278,7 @@ posix_acl_equiv_mode(const struct posix_acl *acl, umode_t *mode_p)
65298 }
65299 }
65300 if (mode_p)
65301- *mode_p = (*mode_p & ~S_IRWXUGO) | mode;
65302+ *mode_p = ((*mode_p & ~S_IRWXUGO) | mode) & ~gr_acl_umask();
65303 return not_equiv;
65304 }
65305 EXPORT_SYMBOL(posix_acl_equiv_mode);
65306@@ -427,7 +428,7 @@ static int posix_acl_create_masq(struct posix_acl *acl, umode_t *mode_p)
65307 mode &= (group_obj->e_perm << 3) | ~S_IRWXG;
65308 }
65309
65310- *mode_p = (*mode_p & ~S_IRWXUGO) | mode;
65311+ *mode_p = ((*mode_p & ~S_IRWXUGO) | mode) & ~gr_acl_umask();
65312 return not_equiv;
65313 }
65314
65315@@ -485,6 +486,8 @@ __posix_acl_create(struct posix_acl **acl, gfp_t gfp, umode_t *mode_p)
65316 struct posix_acl *clone = posix_acl_clone(*acl, gfp);
65317 int err = -ENOMEM;
65318 if (clone) {
65319+ *mode_p &= ~gr_acl_umask();
65320+
65321 err = posix_acl_create_masq(clone, mode_p);
65322 if (err < 0) {
65323 posix_acl_release(clone);
65324@@ -659,11 +662,12 @@ struct posix_acl *
65325 posix_acl_from_xattr(struct user_namespace *user_ns,
65326 const void *value, size_t size)
65327 {
65328- posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
65329- posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
65330+ const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
65331+ const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
65332 int count;
65333 struct posix_acl *acl;
65334 struct posix_acl_entry *acl_e;
65335+ umode_t umask = gr_acl_umask();
65336
65337 if (!value)
65338 return NULL;
65339@@ -689,12 +693,18 @@ posix_acl_from_xattr(struct user_namespace *user_ns,
65340
65341 switch(acl_e->e_tag) {
65342 case ACL_USER_OBJ:
65343+ acl_e->e_perm &= ~((umask & S_IRWXU) >> 6);
65344+ break;
65345 case ACL_GROUP_OBJ:
65346 case ACL_MASK:
65347+ acl_e->e_perm &= ~((umask & S_IRWXG) >> 3);
65348+ break;
65349 case ACL_OTHER:
65350+ acl_e->e_perm &= ~(umask & S_IRWXO);
65351 break;
65352
65353 case ACL_USER:
65354+ acl_e->e_perm &= ~((umask & S_IRWXU) >> 6);
65355 acl_e->e_uid =
65356 make_kuid(user_ns,
65357 le32_to_cpu(entry->e_id));
65358@@ -702,6 +712,7 @@ posix_acl_from_xattr(struct user_namespace *user_ns,
65359 goto fail;
65360 break;
65361 case ACL_GROUP:
65362+ acl_e->e_perm &= ~((umask & S_IRWXG) >> 3);
65363 acl_e->e_gid =
65364 make_kgid(user_ns,
65365 le32_to_cpu(entry->e_id));
65366diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
65367index 2183fcf..3c32a98 100644
65368--- a/fs/proc/Kconfig
65369+++ b/fs/proc/Kconfig
65370@@ -30,7 +30,7 @@ config PROC_FS
65371
65372 config PROC_KCORE
65373 bool "/proc/kcore support" if !ARM
65374- depends on PROC_FS && MMU
65375+ depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
65376 help
65377 Provides a virtual ELF core file of the live kernel. This can
65378 be read with gdb and other ELF tools. No modifications can be
65379@@ -38,8 +38,8 @@ config PROC_KCORE
65380
65381 config PROC_VMCORE
65382 bool "/proc/vmcore support"
65383- depends on PROC_FS && CRASH_DUMP
65384- default y
65385+ depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
65386+ default n
65387 help
65388 Exports the dump image of crashed kernel in ELF format.
65389
65390@@ -63,8 +63,8 @@ config PROC_SYSCTL
65391 limited in memory.
65392
65393 config PROC_PAGE_MONITOR
65394- default y
65395- depends on PROC_FS && MMU
65396+ default n
65397+ depends on PROC_FS && MMU && !GRKERNSEC
65398 bool "Enable /proc page monitoring" if EXPERT
65399 help
65400 Various /proc files exist to monitor process memory utilization:
65401diff --git a/fs/proc/array.c b/fs/proc/array.c
65402index cd3653e..9b9b79a 100644
65403--- a/fs/proc/array.c
65404+++ b/fs/proc/array.c
65405@@ -60,6 +60,7 @@
65406 #include <linux/tty.h>
65407 #include <linux/string.h>
65408 #include <linux/mman.h>
65409+#include <linux/grsecurity.h>
65410 #include <linux/proc_fs.h>
65411 #include <linux/ioport.h>
65412 #include <linux/uaccess.h>
65413@@ -347,6 +348,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
65414 seq_putc(m, '\n');
65415 }
65416
65417+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
65418+static inline void task_pax(struct seq_file *m, struct task_struct *p)
65419+{
65420+ if (p->mm)
65421+ seq_printf(m, "PaX:\t%c%c%c%c%c\n",
65422+ p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
65423+ p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
65424+ p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
65425+ p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
65426+ p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
65427+ else
65428+ seq_printf(m, "PaX:\t-----\n");
65429+}
65430+#endif
65431+
65432 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
65433 struct pid *pid, struct task_struct *task)
65434 {
65435@@ -365,9 +381,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
65436 task_cpus_allowed(m, task);
65437 cpuset_task_status_allowed(m, task);
65438 task_context_switch_counts(m, task);
65439+
65440+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
65441+ task_pax(m, task);
65442+#endif
65443+
65444+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
65445+ task_grsec_rbac(m, task);
65446+#endif
65447+
65448 return 0;
65449 }
65450
65451+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65452+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
65453+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
65454+ _mm->pax_flags & MF_PAX_SEGMEXEC))
65455+#endif
65456+
65457 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
65458 struct pid *pid, struct task_struct *task, int whole)
65459 {
65460@@ -389,6 +420,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
65461 char tcomm[sizeof(task->comm)];
65462 unsigned long flags;
65463
65464+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65465+ if (current->exec_id != m->exec_id) {
65466+ gr_log_badprocpid("stat");
65467+ return 0;
65468+ }
65469+#endif
65470+
65471 state = *get_task_state(task);
65472 vsize = eip = esp = 0;
65473 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
65474@@ -459,6 +497,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
65475 gtime = task_gtime(task);
65476 }
65477
65478+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65479+ if (PAX_RAND_FLAGS(mm)) {
65480+ eip = 0;
65481+ esp = 0;
65482+ wchan = 0;
65483+ }
65484+#endif
65485+#ifdef CONFIG_GRKERNSEC_HIDESYM
65486+ wchan = 0;
65487+ eip =0;
65488+ esp =0;
65489+#endif
65490+
65491 /* scale priority and nice values from timeslices to -20..20 */
65492 /* to make it look like a "normal" Unix priority/nice value */
65493 priority = task_prio(task);
65494@@ -490,9 +541,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
65495 seq_put_decimal_ull(m, ' ', vsize);
65496 seq_put_decimal_ull(m, ' ', mm ? get_mm_rss(mm) : 0);
65497 seq_put_decimal_ull(m, ' ', rsslim);
65498+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65499+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0));
65500+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0));
65501+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0));
65502+#else
65503 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->start_code : 1) : 0);
65504 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->end_code : 1) : 0);
65505 seq_put_decimal_ull(m, ' ', (permitted && mm) ? mm->start_stack : 0);
65506+#endif
65507 seq_put_decimal_ull(m, ' ', esp);
65508 seq_put_decimal_ull(m, ' ', eip);
65509 /* The signal information here is obsolete.
65510@@ -514,7 +571,11 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
65511 seq_put_decimal_ull(m, ' ', cputime_to_clock_t(gtime));
65512 seq_put_decimal_ll(m, ' ', cputime_to_clock_t(cgtime));
65513
65514- if (mm && permitted) {
65515+ if (mm && permitted
65516+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65517+ && !PAX_RAND_FLAGS(mm)
65518+#endif
65519+ ) {
65520 seq_put_decimal_ull(m, ' ', mm->start_data);
65521 seq_put_decimal_ull(m, ' ', mm->end_data);
65522 seq_put_decimal_ull(m, ' ', mm->start_brk);
65523@@ -552,8 +613,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
65524 struct pid *pid, struct task_struct *task)
65525 {
65526 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
65527- struct mm_struct *mm = get_task_mm(task);
65528+ struct mm_struct *mm;
65529
65530+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65531+ if (current->exec_id != m->exec_id) {
65532+ gr_log_badprocpid("statm");
65533+ return 0;
65534+ }
65535+#endif
65536+ mm = get_task_mm(task);
65537 if (mm) {
65538 size = task_statm(mm, &shared, &text, &data, &resident);
65539 mmput(mm);
65540@@ -576,6 +644,20 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
65541 return 0;
65542 }
65543
65544+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
65545+int proc_pid_ipaddr(struct seq_file *m, struct pid_namespace *ns, struct pid *pid, struct task_struct *task)
65546+{
65547+ unsigned long flags;
65548+ u32 curr_ip = 0;
65549+
65550+ if (lock_task_sighand(task, &flags)) {
65551+ curr_ip = task->signal->curr_ip;
65552+ unlock_task_sighand(task, &flags);
65553+ }
65554+ return seq_printf(m, "%pI4\n", &curr_ip);
65555+}
65556+#endif
65557+
65558 #ifdef CONFIG_CHECKPOINT_RESTORE
65559 static struct pid *
65560 get_children_pid(struct inode *inode, struct pid *pid_prev, loff_t pos)
65561diff --git a/fs/proc/base.c b/fs/proc/base.c
65562index 772efa4..e7f1a5c 100644
65563--- a/fs/proc/base.c
65564+++ b/fs/proc/base.c
65565@@ -113,6 +113,14 @@ struct pid_entry {
65566 union proc_op op;
65567 };
65568
65569+struct getdents_callback {
65570+ struct linux_dirent __user * current_dir;
65571+ struct linux_dirent __user * previous;
65572+ struct file * file;
65573+ int count;
65574+ int error;
65575+};
65576+
65577 #define NOD(NAME, MODE, IOP, FOP, OP) { \
65578 .name = (NAME), \
65579 .len = sizeof(NAME) - 1, \
65580@@ -208,12 +216,28 @@ static int proc_pid_cmdline(struct seq_file *m, struct pid_namespace *ns,
65581 return 0;
65582 }
65583
65584+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65585+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
65586+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
65587+ _mm->pax_flags & MF_PAX_SEGMEXEC))
65588+#endif
65589+
65590 static int proc_pid_auxv(struct seq_file *m, struct pid_namespace *ns,
65591 struct pid *pid, struct task_struct *task)
65592 {
65593 struct mm_struct *mm = mm_access(task, PTRACE_MODE_READ);
65594 if (mm && !IS_ERR(mm)) {
65595 unsigned int nwords = 0;
65596+
65597+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65598+ /* allow if we're currently ptracing this task */
65599+ if (PAX_RAND_FLAGS(mm) &&
65600+ (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
65601+ mmput(mm);
65602+ return 0;
65603+ }
65604+#endif
65605+
65606 do {
65607 nwords += 2;
65608 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
65609@@ -225,7 +249,7 @@ static int proc_pid_auxv(struct seq_file *m, struct pid_namespace *ns,
65610 }
65611
65612
65613-#ifdef CONFIG_KALLSYMS
65614+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
65615 /*
65616 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
65617 * Returns the resolved symbol. If that fails, simply return the address.
65618@@ -265,7 +289,7 @@ static void unlock_trace(struct task_struct *task)
65619 mutex_unlock(&task->signal->cred_guard_mutex);
65620 }
65621
65622-#ifdef CONFIG_STACKTRACE
65623+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
65624
65625 #define MAX_STACK_TRACE_DEPTH 64
65626
65627@@ -456,7 +480,7 @@ static int proc_pid_limits(struct seq_file *m, struct pid_namespace *ns,
65628 return 0;
65629 }
65630
65631-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
65632+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
65633 static int proc_pid_syscall(struct seq_file *m, struct pid_namespace *ns,
65634 struct pid *pid, struct task_struct *task)
65635 {
65636@@ -486,7 +510,7 @@ static int proc_pid_syscall(struct seq_file *m, struct pid_namespace *ns,
65637 /************************************************************************/
65638
65639 /* permission checks */
65640-static int proc_fd_access_allowed(struct inode *inode)
65641+static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
65642 {
65643 struct task_struct *task;
65644 int allowed = 0;
65645@@ -496,7 +520,10 @@ static int proc_fd_access_allowed(struct inode *inode)
65646 */
65647 task = get_proc_task(inode);
65648 if (task) {
65649- allowed = ptrace_may_access(task, PTRACE_MODE_READ);
65650+ if (log)
65651+ allowed = ptrace_may_access(task, PTRACE_MODE_READ);
65652+ else
65653+ allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
65654 put_task_struct(task);
65655 }
65656 return allowed;
65657@@ -527,10 +554,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
65658 struct task_struct *task,
65659 int hide_pid_min)
65660 {
65661+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
65662+ return false;
65663+
65664+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
65665+ rcu_read_lock();
65666+ {
65667+ const struct cred *tmpcred = current_cred();
65668+ const struct cred *cred = __task_cred(task);
65669+
65670+ if (uid_eq(tmpcred->uid, GLOBAL_ROOT_UID) || uid_eq(tmpcred->uid, cred->uid)
65671+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
65672+ || in_group_p(grsec_proc_gid)
65673+#endif
65674+ ) {
65675+ rcu_read_unlock();
65676+ return true;
65677+ }
65678+ }
65679+ rcu_read_unlock();
65680+
65681+ if (!pid->hide_pid)
65682+ return false;
65683+#endif
65684+
65685 if (pid->hide_pid < hide_pid_min)
65686 return true;
65687 if (in_group_p(pid->pid_gid))
65688 return true;
65689+
65690 return ptrace_may_access(task, PTRACE_MODE_READ);
65691 }
65692
65693@@ -548,7 +600,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
65694 put_task_struct(task);
65695
65696 if (!has_perms) {
65697+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
65698+ {
65699+#else
65700 if (pid->hide_pid == 2) {
65701+#endif
65702 /*
65703 * Let's make getdents(), stat(), and open()
65704 * consistent with each other. If a process
65705@@ -609,6 +665,8 @@ struct mm_struct *proc_mem_open(struct inode *inode, unsigned int mode)
65706
65707 if (task) {
65708 mm = mm_access(task, mode);
65709+ if (gr_acl_handle_procpidmem(task))
65710+ mm = ERR_PTR(-EPERM);
65711 put_task_struct(task);
65712
65713 if (!IS_ERR_OR_NULL(mm)) {
65714@@ -630,6 +688,11 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
65715 return PTR_ERR(mm);
65716
65717 file->private_data = mm;
65718+
65719+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65720+ file->f_version = current->exec_id;
65721+#endif
65722+
65723 return 0;
65724 }
65725
65726@@ -651,6 +714,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
65727 ssize_t copied;
65728 char *page;
65729
65730+#ifdef CONFIG_GRKERNSEC
65731+ if (write)
65732+ return -EPERM;
65733+#endif
65734+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65735+ if (file->f_version != current->exec_id) {
65736+ gr_log_badprocpid("mem");
65737+ return 0;
65738+ }
65739+#endif
65740+
65741 if (!mm)
65742 return 0;
65743
65744@@ -663,7 +737,7 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
65745 goto free;
65746
65747 while (count > 0) {
65748- int this_len = min_t(int, count, PAGE_SIZE);
65749+ ssize_t this_len = min_t(ssize_t, count, PAGE_SIZE);
65750
65751 if (write && copy_from_user(page, buf, this_len)) {
65752 copied = -EFAULT;
65753@@ -755,6 +829,13 @@ static ssize_t environ_read(struct file *file, char __user *buf,
65754 if (!mm)
65755 return 0;
65756
65757+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65758+ if (file->f_version != current->exec_id) {
65759+ gr_log_badprocpid("environ");
65760+ return 0;
65761+ }
65762+#endif
65763+
65764 page = (char *)__get_free_page(GFP_TEMPORARY);
65765 if (!page)
65766 return -ENOMEM;
65767@@ -764,7 +845,7 @@ static ssize_t environ_read(struct file *file, char __user *buf,
65768 goto free;
65769 while (count > 0) {
65770 size_t this_len, max_len;
65771- int retval;
65772+ ssize_t retval;
65773
65774 if (src >= (mm->env_end - mm->env_start))
65775 break;
65776@@ -1378,7 +1459,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
65777 int error = -EACCES;
65778
65779 /* Are we allowed to snoop on the tasks file descriptors? */
65780- if (!proc_fd_access_allowed(inode))
65781+ if (!proc_fd_access_allowed(inode, 0))
65782 goto out;
65783
65784 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
65785@@ -1422,8 +1503,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
65786 struct path path;
65787
65788 /* Are we allowed to snoop on the tasks file descriptors? */
65789- if (!proc_fd_access_allowed(inode))
65790- goto out;
65791+ /* logging this is needed for learning on chromium to work properly,
65792+ but we don't want to flood the logs from 'ps' which does a readlink
65793+ on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
65794+ CAP_SYS_PTRACE as it's not necessary for its basic functionality
65795+ */
65796+ if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
65797+ if (!proc_fd_access_allowed(inode,0))
65798+ goto out;
65799+ } else {
65800+ if (!proc_fd_access_allowed(inode,1))
65801+ goto out;
65802+ }
65803
65804 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
65805 if (error)
65806@@ -1473,7 +1564,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
65807 rcu_read_lock();
65808 cred = __task_cred(task);
65809 inode->i_uid = cred->euid;
65810+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
65811+ inode->i_gid = grsec_proc_gid;
65812+#else
65813 inode->i_gid = cred->egid;
65814+#endif
65815 rcu_read_unlock();
65816 }
65817 security_task_to_inode(task, inode);
65818@@ -1509,10 +1604,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
65819 return -ENOENT;
65820 }
65821 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
65822+#ifdef CONFIG_GRKERNSEC_PROC_USER
65823+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
65824+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
65825+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
65826+#endif
65827 task_dumpable(task)) {
65828 cred = __task_cred(task);
65829 stat->uid = cred->euid;
65830+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
65831+ stat->gid = grsec_proc_gid;
65832+#else
65833 stat->gid = cred->egid;
65834+#endif
65835 }
65836 }
65837 rcu_read_unlock();
65838@@ -1550,11 +1654,20 @@ int pid_revalidate(struct dentry *dentry, unsigned int flags)
65839
65840 if (task) {
65841 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
65842+#ifdef CONFIG_GRKERNSEC_PROC_USER
65843+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
65844+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
65845+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
65846+#endif
65847 task_dumpable(task)) {
65848 rcu_read_lock();
65849 cred = __task_cred(task);
65850 inode->i_uid = cred->euid;
65851+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
65852+ inode->i_gid = grsec_proc_gid;
65853+#else
65854 inode->i_gid = cred->egid;
65855+#endif
65856 rcu_read_unlock();
65857 } else {
65858 inode->i_uid = GLOBAL_ROOT_UID;
65859@@ -2085,6 +2198,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
65860 if (!task)
65861 goto out_no_task;
65862
65863+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
65864+ goto out;
65865+
65866 /*
65867 * Yes, it does not scale. And it should not. Don't add
65868 * new entries into /proc/<tgid>/ without very good reasons.
65869@@ -2115,6 +2231,9 @@ static int proc_pident_readdir(struct file *file, struct dir_context *ctx,
65870 if (!task)
65871 return -ENOENT;
65872
65873+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
65874+ goto out;
65875+
65876 if (!dir_emit_dots(file, ctx))
65877 goto out;
65878
65879@@ -2506,7 +2625,7 @@ static const struct pid_entry tgid_base_stuff[] = {
65880 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
65881 #endif
65882 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
65883-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
65884+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
65885 ONE("syscall", S_IRUSR, proc_pid_syscall),
65886 #endif
65887 ONE("cmdline", S_IRUGO, proc_pid_cmdline),
65888@@ -2531,10 +2650,10 @@ static const struct pid_entry tgid_base_stuff[] = {
65889 #ifdef CONFIG_SECURITY
65890 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
65891 #endif
65892-#ifdef CONFIG_KALLSYMS
65893+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
65894 ONE("wchan", S_IRUGO, proc_pid_wchan),
65895 #endif
65896-#ifdef CONFIG_STACKTRACE
65897+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
65898 ONE("stack", S_IRUSR, proc_pid_stack),
65899 #endif
65900 #ifdef CONFIG_SCHEDSTATS
65901@@ -2568,6 +2687,9 @@ static const struct pid_entry tgid_base_stuff[] = {
65902 #ifdef CONFIG_HARDWALL
65903 ONE("hardwall", S_IRUGO, proc_pid_hardwall),
65904 #endif
65905+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
65906+ ONE("ipaddr", S_IRUSR, proc_pid_ipaddr),
65907+#endif
65908 #ifdef CONFIG_USER_NS
65909 REG("uid_map", S_IRUGO|S_IWUSR, proc_uid_map_operations),
65910 REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations),
65911@@ -2696,7 +2818,14 @@ static int proc_pid_instantiate(struct inode *dir,
65912 if (!inode)
65913 goto out;
65914
65915+#ifdef CONFIG_GRKERNSEC_PROC_USER
65916+ inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
65917+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
65918+ inode->i_gid = grsec_proc_gid;
65919+ inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
65920+#else
65921 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
65922+#endif
65923 inode->i_op = &proc_tgid_base_inode_operations;
65924 inode->i_fop = &proc_tgid_base_operations;
65925 inode->i_flags|=S_IMMUTABLE;
65926@@ -2734,7 +2863,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, unsign
65927 if (!task)
65928 goto out;
65929
65930+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
65931+ goto out_put_task;
65932+
65933 result = proc_pid_instantiate(dir, dentry, task, NULL);
65934+out_put_task:
65935 put_task_struct(task);
65936 out:
65937 return ERR_PTR(result);
65938@@ -2848,7 +2981,7 @@ static const struct pid_entry tid_base_stuff[] = {
65939 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
65940 #endif
65941 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
65942-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
65943+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
65944 ONE("syscall", S_IRUSR, proc_pid_syscall),
65945 #endif
65946 ONE("cmdline", S_IRUGO, proc_pid_cmdline),
65947@@ -2875,10 +3008,10 @@ static const struct pid_entry tid_base_stuff[] = {
65948 #ifdef CONFIG_SECURITY
65949 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
65950 #endif
65951-#ifdef CONFIG_KALLSYMS
65952+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
65953 ONE("wchan", S_IRUGO, proc_pid_wchan),
65954 #endif
65955-#ifdef CONFIG_STACKTRACE
65956+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
65957 ONE("stack", S_IRUSR, proc_pid_stack),
65958 #endif
65959 #ifdef CONFIG_SCHEDSTATS
65960diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
65961index cbd82df..c0407d2 100644
65962--- a/fs/proc/cmdline.c
65963+++ b/fs/proc/cmdline.c
65964@@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
65965
65966 static int __init proc_cmdline_init(void)
65967 {
65968+#ifdef CONFIG_GRKERNSEC_PROC_ADD
65969+ proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
65970+#else
65971 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
65972+#endif
65973 return 0;
65974 }
65975 fs_initcall(proc_cmdline_init);
65976diff --git a/fs/proc/devices.c b/fs/proc/devices.c
65977index 50493ed..248166b 100644
65978--- a/fs/proc/devices.c
65979+++ b/fs/proc/devices.c
65980@@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
65981
65982 static int __init proc_devices_init(void)
65983 {
65984+#ifdef CONFIG_GRKERNSEC_PROC_ADD
65985+ proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
65986+#else
65987 proc_create("devices", 0, NULL, &proc_devinfo_operations);
65988+#endif
65989 return 0;
65990 }
65991 fs_initcall(proc_devices_init);
65992diff --git a/fs/proc/fd.c b/fs/proc/fd.c
65993index e11d7c5..9128ce06 100644
65994--- a/fs/proc/fd.c
65995+++ b/fs/proc/fd.c
65996@@ -26,7 +26,8 @@ static int seq_show(struct seq_file *m, void *v)
65997 if (!task)
65998 return -ENOENT;
65999
66000- files = get_files_struct(task);
66001+ if (!gr_acl_handle_procpidmem(task))
66002+ files = get_files_struct(task);
66003 put_task_struct(task);
66004
66005 if (files) {
66006@@ -283,11 +284,21 @@ static struct dentry *proc_lookupfd(struct inode *dir, struct dentry *dentry,
66007 */
66008 int proc_fd_permission(struct inode *inode, int mask)
66009 {
66010+ struct task_struct *task;
66011 int rv = generic_permission(inode, mask);
66012- if (rv == 0)
66013- return 0;
66014+
66015 if (task_tgid(current) == proc_pid(inode))
66016 rv = 0;
66017+
66018+ task = get_proc_task(inode);
66019+ if (task == NULL)
66020+ return rv;
66021+
66022+ if (gr_acl_handle_procpidmem(task))
66023+ rv = -EACCES;
66024+
66025+ put_task_struct(task);
66026+
66027 return rv;
66028 }
66029
66030diff --git a/fs/proc/generic.c b/fs/proc/generic.c
66031index 317b726..e329aed 100644
66032--- a/fs/proc/generic.c
66033+++ b/fs/proc/generic.c
66034@@ -23,6 +23,7 @@
66035 #include <linux/bitops.h>
66036 #include <linux/spinlock.h>
66037 #include <linux/completion.h>
66038+#include <linux/grsecurity.h>
66039 #include <asm/uaccess.h>
66040
66041 #include "internal.h"
66042@@ -207,6 +208,15 @@ struct dentry *proc_lookup(struct inode *dir, struct dentry *dentry,
66043 return proc_lookup_de(PDE(dir), dir, dentry);
66044 }
66045
66046+struct dentry *proc_lookup_restrict(struct inode *dir, struct dentry *dentry,
66047+ unsigned int flags)
66048+{
66049+ if (gr_proc_is_restricted())
66050+ return ERR_PTR(-EACCES);
66051+
66052+ return proc_lookup_de(PDE(dir), dir, dentry);
66053+}
66054+
66055 /*
66056 * This returns non-zero if at EOF, so that the /proc
66057 * root directory can use this and check if it should
66058@@ -264,6 +274,16 @@ int proc_readdir(struct file *file, struct dir_context *ctx)
66059 return proc_readdir_de(PDE(inode), file, ctx);
66060 }
66061
66062+int proc_readdir_restrict(struct file *file, struct dir_context *ctx)
66063+{
66064+ struct inode *inode = file_inode(file);
66065+
66066+ if (gr_proc_is_restricted())
66067+ return -EACCES;
66068+
66069+ return proc_readdir_de(PDE(inode), file, ctx);
66070+}
66071+
66072 /*
66073 * These are the generic /proc directory operations. They
66074 * use the in-memory "struct proc_dir_entry" tree to parse
66075@@ -275,6 +295,12 @@ static const struct file_operations proc_dir_operations = {
66076 .iterate = proc_readdir,
66077 };
66078
66079+static const struct file_operations proc_dir_restricted_operations = {
66080+ .llseek = generic_file_llseek,
66081+ .read = generic_read_dir,
66082+ .iterate = proc_readdir_restrict,
66083+};
66084+
66085 /*
66086 * proc directories can do almost nothing..
66087 */
66088@@ -284,6 +310,12 @@ static const struct inode_operations proc_dir_inode_operations = {
66089 .setattr = proc_notify_change,
66090 };
66091
66092+static const struct inode_operations proc_dir_restricted_inode_operations = {
66093+ .lookup = proc_lookup_restrict,
66094+ .getattr = proc_getattr,
66095+ .setattr = proc_notify_change,
66096+};
66097+
66098 static int proc_register(struct proc_dir_entry * dir, struct proc_dir_entry * dp)
66099 {
66100 struct proc_dir_entry *tmp;
66101@@ -294,8 +326,13 @@ static int proc_register(struct proc_dir_entry * dir, struct proc_dir_entry * dp
66102 return ret;
66103
66104 if (S_ISDIR(dp->mode)) {
66105- dp->proc_fops = &proc_dir_operations;
66106- dp->proc_iops = &proc_dir_inode_operations;
66107+ if (dp->restricted) {
66108+ dp->proc_fops = &proc_dir_restricted_operations;
66109+ dp->proc_iops = &proc_dir_restricted_inode_operations;
66110+ } else {
66111+ dp->proc_fops = &proc_dir_operations;
66112+ dp->proc_iops = &proc_dir_inode_operations;
66113+ }
66114 dir->nlink++;
66115 } else if (S_ISLNK(dp->mode)) {
66116 dp->proc_iops = &proc_link_inode_operations;
66117@@ -407,6 +444,27 @@ struct proc_dir_entry *proc_mkdir_data(const char *name, umode_t mode,
66118 }
66119 EXPORT_SYMBOL_GPL(proc_mkdir_data);
66120
66121+struct proc_dir_entry *proc_mkdir_data_restrict(const char *name, umode_t mode,
66122+ struct proc_dir_entry *parent, void *data)
66123+{
66124+ struct proc_dir_entry *ent;
66125+
66126+ if (mode == 0)
66127+ mode = S_IRUGO | S_IXUGO;
66128+
66129+ ent = __proc_create(&parent, name, S_IFDIR | mode, 2);
66130+ if (ent) {
66131+ ent->data = data;
66132+ ent->restricted = 1;
66133+ if (proc_register(parent, ent) < 0) {
66134+ kfree(ent);
66135+ ent = NULL;
66136+ }
66137+ }
66138+ return ent;
66139+}
66140+EXPORT_SYMBOL_GPL(proc_mkdir_data_restrict);
66141+
66142 struct proc_dir_entry *proc_mkdir_mode(const char *name, umode_t mode,
66143 struct proc_dir_entry *parent)
66144 {
66145@@ -421,6 +479,13 @@ struct proc_dir_entry *proc_mkdir(const char *name,
66146 }
66147 EXPORT_SYMBOL(proc_mkdir);
66148
66149+struct proc_dir_entry *proc_mkdir_restrict(const char *name,
66150+ struct proc_dir_entry *parent)
66151+{
66152+ return proc_mkdir_data_restrict(name, 0, parent, NULL);
66153+}
66154+EXPORT_SYMBOL(proc_mkdir_restrict);
66155+
66156 struct proc_dir_entry *proc_create_data(const char *name, umode_t mode,
66157 struct proc_dir_entry *parent,
66158 const struct file_operations *proc_fops,
66159diff --git a/fs/proc/inode.c b/fs/proc/inode.c
66160index 333080d..0a35ec4 100644
66161--- a/fs/proc/inode.c
66162+++ b/fs/proc/inode.c
66163@@ -23,11 +23,17 @@
66164 #include <linux/slab.h>
66165 #include <linux/mount.h>
66166 #include <linux/magic.h>
66167+#include <linux/grsecurity.h>
66168
66169 #include <asm/uaccess.h>
66170
66171 #include "internal.h"
66172
66173+#ifdef CONFIG_PROC_SYSCTL
66174+extern const struct inode_operations proc_sys_inode_operations;
66175+extern const struct inode_operations proc_sys_dir_operations;
66176+#endif
66177+
66178 static void proc_evict_inode(struct inode *inode)
66179 {
66180 struct proc_dir_entry *de;
66181@@ -55,6 +61,13 @@ static void proc_evict_inode(struct inode *inode)
66182 ns = PROC_I(inode)->ns.ns;
66183 if (ns_ops && ns)
66184 ns_ops->put(ns);
66185+
66186+#ifdef CONFIG_PROC_SYSCTL
66187+ if (inode->i_op == &proc_sys_inode_operations ||
66188+ inode->i_op == &proc_sys_dir_operations)
66189+ gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
66190+#endif
66191+
66192 }
66193
66194 static struct kmem_cache * proc_inode_cachep;
66195@@ -413,7 +426,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
66196 if (de->mode) {
66197 inode->i_mode = de->mode;
66198 inode->i_uid = de->uid;
66199+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
66200+ inode->i_gid = grsec_proc_gid;
66201+#else
66202 inode->i_gid = de->gid;
66203+#endif
66204 }
66205 if (de->size)
66206 inode->i_size = de->size;
66207diff --git a/fs/proc/internal.h b/fs/proc/internal.h
66208index aa7a0ee..f2318df 100644
66209--- a/fs/proc/internal.h
66210+++ b/fs/proc/internal.h
66211@@ -46,9 +46,10 @@ struct proc_dir_entry {
66212 struct completion *pde_unload_completion;
66213 struct list_head pde_openers; /* who did ->open, but not ->release */
66214 spinlock_t pde_unload_lock; /* proc_fops checks and pde_users bumps */
66215+ u8 restricted; /* a directory in /proc/net that should be restricted via GRKERNSEC_PROC */
66216 u8 namelen;
66217 char name[];
66218-};
66219+} __randomize_layout;
66220
66221 union proc_op {
66222 int (*proc_get_link)(struct dentry *, struct path *);
66223@@ -66,7 +67,7 @@ struct proc_inode {
66224 struct ctl_table *sysctl_entry;
66225 struct proc_ns ns;
66226 struct inode vfs_inode;
66227-};
66228+} __randomize_layout;
66229
66230 /*
66231 * General functions
66232@@ -154,6 +155,10 @@ extern int proc_pid_status(struct seq_file *, struct pid_namespace *,
66233 struct pid *, struct task_struct *);
66234 extern int proc_pid_statm(struct seq_file *, struct pid_namespace *,
66235 struct pid *, struct task_struct *);
66236+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
66237+extern int proc_pid_ipaddr(struct seq_file *, struct pid_namespace *,
66238+ struct pid *, struct task_struct *);
66239+#endif
66240
66241 /*
66242 * base.c
66243@@ -178,9 +183,11 @@ extern bool proc_fill_cache(struct file *, struct dir_context *, const char *, i
66244 * generic.c
66245 */
66246 extern struct dentry *proc_lookup(struct inode *, struct dentry *, unsigned int);
66247+extern struct dentry *proc_lookup_restrict(struct inode *, struct dentry *, unsigned int);
66248 extern struct dentry *proc_lookup_de(struct proc_dir_entry *, struct inode *,
66249 struct dentry *);
66250 extern int proc_readdir(struct file *, struct dir_context *);
66251+extern int proc_readdir_restrict(struct file *, struct dir_context *);
66252 extern int proc_readdir_de(struct proc_dir_entry *, struct file *, struct dir_context *);
66253
66254 static inline struct proc_dir_entry *pde_get(struct proc_dir_entry *pde)
66255diff --git a/fs/proc/interrupts.c b/fs/proc/interrupts.c
66256index a352d57..cb94a5c 100644
66257--- a/fs/proc/interrupts.c
66258+++ b/fs/proc/interrupts.c
66259@@ -47,7 +47,11 @@ static const struct file_operations proc_interrupts_operations = {
66260
66261 static int __init proc_interrupts_init(void)
66262 {
66263+#ifdef CONFIG_GRKERNSEC_PROC_ADD
66264+ proc_create_grsec("interrupts", 0, NULL, &proc_interrupts_operations);
66265+#else
66266 proc_create("interrupts", 0, NULL, &proc_interrupts_operations);
66267+#endif
66268 return 0;
66269 }
66270 fs_initcall(proc_interrupts_init);
66271diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
66272index 91a4e64..cb007c0 100644
66273--- a/fs/proc/kcore.c
66274+++ b/fs/proc/kcore.c
66275@@ -483,9 +483,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
66276 * the addresses in the elf_phdr on our list.
66277 */
66278 start = kc_offset_to_vaddr(*fpos - elf_buflen);
66279- if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
66280+ tsz = PAGE_SIZE - (start & ~PAGE_MASK);
66281+ if (tsz > buflen)
66282 tsz = buflen;
66283-
66284+
66285 while (buflen) {
66286 struct kcore_list *m;
66287
66288@@ -514,20 +515,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
66289 kfree(elf_buf);
66290 } else {
66291 if (kern_addr_valid(start)) {
66292- unsigned long n;
66293+ char *elf_buf;
66294+ mm_segment_t oldfs;
66295
66296- n = copy_to_user(buffer, (char *)start, tsz);
66297- /*
66298- * We cannot distinguish between fault on source
66299- * and fault on destination. When this happens
66300- * we clear too and hope it will trigger the
66301- * EFAULT again.
66302- */
66303- if (n) {
66304- if (clear_user(buffer + tsz - n,
66305- n))
66306+ elf_buf = kmalloc(tsz, GFP_KERNEL);
66307+ if (!elf_buf)
66308+ return -ENOMEM;
66309+ oldfs = get_fs();
66310+ set_fs(KERNEL_DS);
66311+ if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
66312+ set_fs(oldfs);
66313+ if (copy_to_user(buffer, elf_buf, tsz)) {
66314+ kfree(elf_buf);
66315 return -EFAULT;
66316+ }
66317 }
66318+ set_fs(oldfs);
66319+ kfree(elf_buf);
66320 } else {
66321 if (clear_user(buffer, tsz))
66322 return -EFAULT;
66323@@ -547,6 +551,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
66324
66325 static int open_kcore(struct inode *inode, struct file *filp)
66326 {
66327+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
66328+ return -EPERM;
66329+#endif
66330 if (!capable(CAP_SYS_RAWIO))
66331 return -EPERM;
66332 if (kcore_need_update)
66333diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
66334index aa1eee0..03dda72 100644
66335--- a/fs/proc/meminfo.c
66336+++ b/fs/proc/meminfo.c
66337@@ -187,7 +187,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
66338 vmi.used >> 10,
66339 vmi.largest_chunk >> 10
66340 #ifdef CONFIG_MEMORY_FAILURE
66341- ,atomic_long_read(&num_poisoned_pages) << (PAGE_SHIFT - 10)
66342+ ,atomic_long_read_unchecked(&num_poisoned_pages) << (PAGE_SHIFT - 10)
66343 #endif
66344 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
66345 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
66346diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
66347index d4a3574..b421ce9 100644
66348--- a/fs/proc/nommu.c
66349+++ b/fs/proc/nommu.c
66350@@ -64,7 +64,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
66351
66352 if (file) {
66353 seq_pad(m, ' ');
66354- seq_path(m, &file->f_path, "");
66355+ seq_path(m, &file->f_path, "\n\\");
66356 }
66357
66358 seq_putc(m, '\n');
66359diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
66360index a63af3e..b4f262a 100644
66361--- a/fs/proc/proc_net.c
66362+++ b/fs/proc/proc_net.c
66363@@ -23,9 +23,27 @@
66364 #include <linux/nsproxy.h>
66365 #include <net/net_namespace.h>
66366 #include <linux/seq_file.h>
66367+#include <linux/grsecurity.h>
66368
66369 #include "internal.h"
66370
66371+#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
66372+static struct seq_operations *ipv6_seq_ops_addr;
66373+
66374+void register_ipv6_seq_ops_addr(struct seq_operations *addr)
66375+{
66376+ ipv6_seq_ops_addr = addr;
66377+}
66378+
66379+void unregister_ipv6_seq_ops_addr(void)
66380+{
66381+ ipv6_seq_ops_addr = NULL;
66382+}
66383+
66384+EXPORT_SYMBOL_GPL(register_ipv6_seq_ops_addr);
66385+EXPORT_SYMBOL_GPL(unregister_ipv6_seq_ops_addr);
66386+#endif
66387+
66388 static inline struct net *PDE_NET(struct proc_dir_entry *pde)
66389 {
66390 return pde->parent->data;
66391@@ -36,6 +54,8 @@ static struct net *get_proc_net(const struct inode *inode)
66392 return maybe_get_net(PDE_NET(PDE(inode)));
66393 }
66394
66395+extern const struct seq_operations dev_seq_ops;
66396+
66397 int seq_open_net(struct inode *ino, struct file *f,
66398 const struct seq_operations *ops, int size)
66399 {
66400@@ -44,6 +64,14 @@ int seq_open_net(struct inode *ino, struct file *f,
66401
66402 BUG_ON(size < sizeof(*p));
66403
66404+ /* only permit access to /proc/net/dev */
66405+ if (
66406+#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
66407+ ops != ipv6_seq_ops_addr &&
66408+#endif
66409+ ops != &dev_seq_ops && gr_proc_is_restricted())
66410+ return -EACCES;
66411+
66412 net = get_proc_net(ino);
66413 if (net == NULL)
66414 return -ENXIO;
66415@@ -66,6 +94,9 @@ int single_open_net(struct inode *inode, struct file *file,
66416 int err;
66417 struct net *net;
66418
66419+ if (gr_proc_is_restricted())
66420+ return -EACCES;
66421+
66422 err = -ENXIO;
66423 net = get_proc_net(inode);
66424 if (net == NULL)
66425diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
66426index f92d5dd..26398ac 100644
66427--- a/fs/proc/proc_sysctl.c
66428+++ b/fs/proc/proc_sysctl.c
66429@@ -11,13 +11,21 @@
66430 #include <linux/namei.h>
66431 #include <linux/mm.h>
66432 #include <linux/module.h>
66433+#include <linux/nsproxy.h>
66434+#ifdef CONFIG_GRKERNSEC
66435+#include <net/net_namespace.h>
66436+#endif
66437 #include "internal.h"
66438
66439+extern int gr_handle_chroot_sysctl(const int op);
66440+extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
66441+ const int op);
66442+
66443 static const struct dentry_operations proc_sys_dentry_operations;
66444 static const struct file_operations proc_sys_file_operations;
66445-static const struct inode_operations proc_sys_inode_operations;
66446+const struct inode_operations proc_sys_inode_operations;
66447 static const struct file_operations proc_sys_dir_file_operations;
66448-static const struct inode_operations proc_sys_dir_operations;
66449+const struct inode_operations proc_sys_dir_operations;
66450
66451 void proc_sys_poll_notify(struct ctl_table_poll *poll)
66452 {
66453@@ -467,6 +475,9 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
66454
66455 err = NULL;
66456 d_set_d_op(dentry, &proc_sys_dentry_operations);
66457+
66458+ gr_handle_proc_create(dentry, inode);
66459+
66460 d_add(dentry, inode);
66461
66462 out:
66463@@ -482,6 +493,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
66464 struct inode *inode = file_inode(filp);
66465 struct ctl_table_header *head = grab_header(inode);
66466 struct ctl_table *table = PROC_I(inode)->sysctl_entry;
66467+ int op = write ? MAY_WRITE : MAY_READ;
66468 ssize_t error;
66469 size_t res;
66470
66471@@ -493,7 +505,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
66472 * and won't be until we finish.
66473 */
66474 error = -EPERM;
66475- if (sysctl_perm(head, table, write ? MAY_WRITE : MAY_READ))
66476+ if (sysctl_perm(head, table, op))
66477 goto out;
66478
66479 /* if that can happen at all, it should be -EINVAL, not -EISDIR */
66480@@ -501,6 +513,27 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
66481 if (!table->proc_handler)
66482 goto out;
66483
66484+#ifdef CONFIG_GRKERNSEC
66485+ error = -EPERM;
66486+ if (gr_handle_chroot_sysctl(op))
66487+ goto out;
66488+ dget(filp->f_path.dentry);
66489+ if (gr_handle_sysctl_mod(filp->f_path.dentry->d_parent->d_name.name, table->procname, op)) {
66490+ dput(filp->f_path.dentry);
66491+ goto out;
66492+ }
66493+ dput(filp->f_path.dentry);
66494+ if (!gr_acl_handle_open(filp->f_path.dentry, filp->f_path.mnt, op))
66495+ goto out;
66496+ if (write) {
66497+ if (current->nsproxy->net_ns != table->extra2) {
66498+ if (!capable(CAP_SYS_ADMIN))
66499+ goto out;
66500+ } else if (!ns_capable(current->nsproxy->net_ns->user_ns, CAP_NET_ADMIN))
66501+ goto out;
66502+ }
66503+#endif
66504+
66505 /* careful: calling conventions are nasty here */
66506 res = count;
66507 error = table->proc_handler(table, write, buf, &res, ppos);
66508@@ -598,6 +631,9 @@ static bool proc_sys_fill_cache(struct file *file,
66509 return false;
66510 } else {
66511 d_set_d_op(child, &proc_sys_dentry_operations);
66512+
66513+ gr_handle_proc_create(child, inode);
66514+
66515 d_add(child, inode);
66516 }
66517 } else {
66518@@ -641,6 +677,9 @@ static int scan(struct ctl_table_header *head, struct ctl_table *table,
66519 if ((*pos)++ < ctx->pos)
66520 return true;
66521
66522+ if (!gr_acl_handle_hidden_file(file->f_path.dentry, file->f_path.mnt))
66523+ return 0;
66524+
66525 if (unlikely(S_ISLNK(table->mode)))
66526 res = proc_sys_link_fill_cache(file, ctx, head, table);
66527 else
66528@@ -734,6 +773,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
66529 if (IS_ERR(head))
66530 return PTR_ERR(head);
66531
66532+ if (table && !gr_acl_handle_hidden_file(dentry, mnt))
66533+ return -ENOENT;
66534+
66535 generic_fillattr(inode, stat);
66536 if (table)
66537 stat->mode = (stat->mode & S_IFMT) | table->mode;
66538@@ -756,13 +798,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
66539 .llseek = generic_file_llseek,
66540 };
66541
66542-static const struct inode_operations proc_sys_inode_operations = {
66543+const struct inode_operations proc_sys_inode_operations = {
66544 .permission = proc_sys_permission,
66545 .setattr = proc_sys_setattr,
66546 .getattr = proc_sys_getattr,
66547 };
66548
66549-static const struct inode_operations proc_sys_dir_operations = {
66550+const struct inode_operations proc_sys_dir_operations = {
66551 .lookup = proc_sys_lookup,
66552 .permission = proc_sys_permission,
66553 .setattr = proc_sys_setattr,
66554@@ -839,7 +881,7 @@ static struct ctl_dir *find_subdir(struct ctl_dir *dir,
66555 static struct ctl_dir *new_dir(struct ctl_table_set *set,
66556 const char *name, int namelen)
66557 {
66558- struct ctl_table *table;
66559+ ctl_table_no_const *table;
66560 struct ctl_dir *new;
66561 struct ctl_node *node;
66562 char *new_name;
66563@@ -851,7 +893,7 @@ static struct ctl_dir *new_dir(struct ctl_table_set *set,
66564 return NULL;
66565
66566 node = (struct ctl_node *)(new + 1);
66567- table = (struct ctl_table *)(node + 1);
66568+ table = (ctl_table_no_const *)(node + 1);
66569 new_name = (char *)(table + 2);
66570 memcpy(new_name, name, namelen);
66571 new_name[namelen] = '\0';
66572@@ -1020,7 +1062,8 @@ static int sysctl_check_table(const char *path, struct ctl_table *table)
66573 static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table *table,
66574 struct ctl_table_root *link_root)
66575 {
66576- struct ctl_table *link_table, *entry, *link;
66577+ ctl_table_no_const *link_table, *link;
66578+ struct ctl_table *entry;
66579 struct ctl_table_header *links;
66580 struct ctl_node *node;
66581 char *link_name;
66582@@ -1043,7 +1086,7 @@ static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table
66583 return NULL;
66584
66585 node = (struct ctl_node *)(links + 1);
66586- link_table = (struct ctl_table *)(node + nr_entries);
66587+ link_table = (ctl_table_no_const *)(node + nr_entries);
66588 link_name = (char *)&link_table[nr_entries + 1];
66589
66590 for (link = link_table, entry = table; entry->procname; link++, entry++) {
66591@@ -1291,8 +1334,8 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
66592 struct ctl_table_header ***subheader, struct ctl_table_set *set,
66593 struct ctl_table *table)
66594 {
66595- struct ctl_table *ctl_table_arg = NULL;
66596- struct ctl_table *entry, *files;
66597+ ctl_table_no_const *ctl_table_arg = NULL, *files = NULL;
66598+ struct ctl_table *entry;
66599 int nr_files = 0;
66600 int nr_dirs = 0;
66601 int err = -ENOMEM;
66602@@ -1304,10 +1347,9 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
66603 nr_files++;
66604 }
66605
66606- files = table;
66607 /* If there are mixed files and directories we need a new table */
66608 if (nr_dirs && nr_files) {
66609- struct ctl_table *new;
66610+ ctl_table_no_const *new;
66611 files = kzalloc(sizeof(struct ctl_table) * (nr_files + 1),
66612 GFP_KERNEL);
66613 if (!files)
66614@@ -1325,7 +1367,7 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
66615 /* Register everything except a directory full of subdirectories */
66616 if (nr_files || !nr_dirs) {
66617 struct ctl_table_header *header;
66618- header = __register_sysctl_table(set, path, files);
66619+ header = __register_sysctl_table(set, path, files ? files : table);
66620 if (!header) {
66621 kfree(ctl_table_arg);
66622 goto out;
66623diff --git a/fs/proc/root.c b/fs/proc/root.c
66624index 094e44d..085a877 100644
66625--- a/fs/proc/root.c
66626+++ b/fs/proc/root.c
66627@@ -188,7 +188,15 @@ void __init proc_root_init(void)
66628 proc_mkdir("openprom", NULL);
66629 #endif
66630 proc_tty_init();
66631+#ifdef CONFIG_GRKERNSEC_PROC_ADD
66632+#ifdef CONFIG_GRKERNSEC_PROC_USER
66633+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
66634+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66635+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
66636+#endif
66637+#else
66638 proc_mkdir("bus", NULL);
66639+#endif
66640 proc_sys_init();
66641 }
66642
66643diff --git a/fs/proc/stat.c b/fs/proc/stat.c
66644index bf2d03f..f058f9c 100644
66645--- a/fs/proc/stat.c
66646+++ b/fs/proc/stat.c
66647@@ -11,6 +11,7 @@
66648 #include <linux/irqnr.h>
66649 #include <linux/cputime.h>
66650 #include <linux/tick.h>
66651+#include <linux/grsecurity.h>
66652
66653 #ifndef arch_irq_stat_cpu
66654 #define arch_irq_stat_cpu(cpu) 0
66655@@ -87,6 +88,18 @@ static int show_stat(struct seq_file *p, void *v)
66656 u64 sum_softirq = 0;
66657 unsigned int per_softirq_sums[NR_SOFTIRQS] = {0};
66658 struct timespec boottime;
66659+ int unrestricted = 1;
66660+
66661+#ifdef CONFIG_GRKERNSEC_PROC_ADD
66662+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66663+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)
66664+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
66665+ && !in_group_p(grsec_proc_gid)
66666+#endif
66667+ )
66668+ unrestricted = 0;
66669+#endif
66670+#endif
66671
66672 user = nice = system = idle = iowait =
66673 irq = softirq = steal = 0;
66674@@ -99,23 +112,25 @@ static int show_stat(struct seq_file *p, void *v)
66675 nice += kcpustat_cpu(i).cpustat[CPUTIME_NICE];
66676 system += kcpustat_cpu(i).cpustat[CPUTIME_SYSTEM];
66677 idle += get_idle_time(i);
66678- iowait += get_iowait_time(i);
66679- irq += kcpustat_cpu(i).cpustat[CPUTIME_IRQ];
66680- softirq += kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ];
66681- steal += kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
66682- guest += kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
66683- guest_nice += kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
66684- sum += kstat_cpu_irqs_sum(i);
66685- sum += arch_irq_stat_cpu(i);
66686+ if (unrestricted) {
66687+ iowait += get_iowait_time(i);
66688+ irq += kcpustat_cpu(i).cpustat[CPUTIME_IRQ];
66689+ softirq += kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ];
66690+ steal += kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
66691+ guest += kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
66692+ guest_nice += kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
66693+ sum += kstat_cpu_irqs_sum(i);
66694+ sum += arch_irq_stat_cpu(i);
66695+ for (j = 0; j < NR_SOFTIRQS; j++) {
66696+ unsigned int softirq_stat = kstat_softirqs_cpu(j, i);
66697
66698- for (j = 0; j < NR_SOFTIRQS; j++) {
66699- unsigned int softirq_stat = kstat_softirqs_cpu(j, i);
66700-
66701- per_softirq_sums[j] += softirq_stat;
66702- sum_softirq += softirq_stat;
66703+ per_softirq_sums[j] += softirq_stat;
66704+ sum_softirq += softirq_stat;
66705+ }
66706 }
66707 }
66708- sum += arch_irq_stat();
66709+ if (unrestricted)
66710+ sum += arch_irq_stat();
66711
66712 seq_puts(p, "cpu ");
66713 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(user));
66714@@ -136,12 +151,14 @@ static int show_stat(struct seq_file *p, void *v)
66715 nice = kcpustat_cpu(i).cpustat[CPUTIME_NICE];
66716 system = kcpustat_cpu(i).cpustat[CPUTIME_SYSTEM];
66717 idle = get_idle_time(i);
66718- iowait = get_iowait_time(i);
66719- irq = kcpustat_cpu(i).cpustat[CPUTIME_IRQ];
66720- softirq = kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ];
66721- steal = kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
66722- guest = kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
66723- guest_nice = kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
66724+ if (unrestricted) {
66725+ iowait = get_iowait_time(i);
66726+ irq = kcpustat_cpu(i).cpustat[CPUTIME_IRQ];
66727+ softirq = kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ];
66728+ steal = kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
66729+ guest = kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
66730+ guest_nice = kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
66731+ }
66732 seq_printf(p, "cpu%d", i);
66733 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(user));
66734 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(nice));
66735@@ -159,7 +176,7 @@ static int show_stat(struct seq_file *p, void *v)
66736
66737 /* sum again ? it could be updated? */
66738 for_each_irq_nr(j)
66739- seq_put_decimal_ull(p, ' ', kstat_irqs(j));
66740+ seq_put_decimal_ull(p, ' ', unrestricted ? kstat_irqs(j) : 0ULL);
66741
66742 seq_printf(p,
66743 "\nctxt %llu\n"
66744@@ -167,11 +184,11 @@ static int show_stat(struct seq_file *p, void *v)
66745 "processes %lu\n"
66746 "procs_running %lu\n"
66747 "procs_blocked %lu\n",
66748- nr_context_switches(),
66749+ unrestricted ? nr_context_switches() : 0ULL,
66750 (unsigned long)jif,
66751- total_forks,
66752- nr_running(),
66753- nr_iowait());
66754+ unrestricted ? total_forks : 0UL,
66755+ unrestricted ? nr_running() : 0UL,
66756+ unrestricted ? nr_iowait() : 0UL);
66757
66758 seq_printf(p, "softirq %llu", (unsigned long long)sum_softirq);
66759
66760diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
66761index 4e0388c..fc6a0e1 100644
66762--- a/fs/proc/task_mmu.c
66763+++ b/fs/proc/task_mmu.c
66764@@ -13,12 +13,19 @@
66765 #include <linux/swap.h>
66766 #include <linux/swapops.h>
66767 #include <linux/mmu_notifier.h>
66768+#include <linux/grsecurity.h>
66769
66770 #include <asm/elf.h>
66771 #include <asm/uaccess.h>
66772 #include <asm/tlbflush.h>
66773 #include "internal.h"
66774
66775+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66776+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
66777+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
66778+ _mm->pax_flags & MF_PAX_SEGMEXEC))
66779+#endif
66780+
66781 void task_mem(struct seq_file *m, struct mm_struct *mm)
66782 {
66783 unsigned long data, text, lib, swap;
66784@@ -54,8 +61,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
66785 "VmExe:\t%8lu kB\n"
66786 "VmLib:\t%8lu kB\n"
66787 "VmPTE:\t%8lu kB\n"
66788- "VmSwap:\t%8lu kB\n",
66789- hiwater_vm << (PAGE_SHIFT-10),
66790+ "VmSwap:\t%8lu kB\n"
66791+
66792+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
66793+ "CsBase:\t%8lx\nCsLim:\t%8lx\n"
66794+#endif
66795+
66796+ ,hiwater_vm << (PAGE_SHIFT-10),
66797 total_vm << (PAGE_SHIFT-10),
66798 mm->locked_vm << (PAGE_SHIFT-10),
66799 mm->pinned_vm << (PAGE_SHIFT-10),
66800@@ -65,7 +77,19 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
66801 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
66802 (PTRS_PER_PTE * sizeof(pte_t) *
66803 atomic_long_read(&mm->nr_ptes)) >> 10,
66804- swap << (PAGE_SHIFT-10));
66805+ swap << (PAGE_SHIFT-10)
66806+
66807+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
66808+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66809+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_base
66810+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_limit
66811+#else
66812+ , mm->context.user_cs_base
66813+ , mm->context.user_cs_limit
66814+#endif
66815+#endif
66816+
66817+ );
66818 }
66819
66820 unsigned long task_vsize(struct mm_struct *mm)
66821@@ -282,13 +306,13 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
66822 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
66823 }
66824
66825- /* We don't show the stack guard page in /proc/maps */
66826+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66827+ start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
66828+ end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
66829+#else
66830 start = vma->vm_start;
66831- if (stack_guard_page_start(vma, start))
66832- start += PAGE_SIZE;
66833 end = vma->vm_end;
66834- if (stack_guard_page_end(vma, end))
66835- end -= PAGE_SIZE;
66836+#endif
66837
66838 seq_setwidth(m, 25 + sizeof(void *) * 6 - 1);
66839 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu ",
66840@@ -298,7 +322,11 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
66841 flags & VM_WRITE ? 'w' : '-',
66842 flags & VM_EXEC ? 'x' : '-',
66843 flags & VM_MAYSHARE ? 's' : 'p',
66844+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66845+ PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
66846+#else
66847 pgoff,
66848+#endif
66849 MAJOR(dev), MINOR(dev), ino);
66850
66851 /*
66852@@ -307,7 +335,7 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
66853 */
66854 if (file) {
66855 seq_pad(m, ' ');
66856- seq_path(m, &file->f_path, "\n");
66857+ seq_path(m, &file->f_path, "\n\\");
66858 goto done;
66859 }
66860
66861@@ -338,8 +366,9 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
66862 * Thread stack in /proc/PID/task/TID/maps or
66863 * the main process stack.
66864 */
66865- if (!is_pid || (vma->vm_start <= mm->start_stack &&
66866- vma->vm_end >= mm->start_stack)) {
66867+ if (!is_pid || (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
66868+ (vma->vm_start <= mm->start_stack &&
66869+ vma->vm_end >= mm->start_stack)) {
66870 name = "[stack]";
66871 } else {
66872 /* Thread stack in /proc/PID/maps */
66873@@ -359,6 +388,12 @@ done:
66874
66875 static int show_map(struct seq_file *m, void *v, int is_pid)
66876 {
66877+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66878+ if (current->exec_id != m->exec_id) {
66879+ gr_log_badprocpid("maps");
66880+ return 0;
66881+ }
66882+#endif
66883 show_map_vma(m, v, is_pid);
66884 m_cache_vma(m, v);
66885 return 0;
66886@@ -594,12 +629,23 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
66887 .private = &mss,
66888 };
66889
66890+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66891+ if (current->exec_id != m->exec_id) {
66892+ gr_log_badprocpid("smaps");
66893+ return 0;
66894+ }
66895+#endif
66896 memset(&mss, 0, sizeof mss);
66897- mss.vma = vma;
66898- /* mmap_sem is held in m_start */
66899- if (vma->vm_mm && !is_vm_hugetlb_page(vma))
66900- walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
66901-
66902+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66903+ if (!PAX_RAND_FLAGS(vma->vm_mm)) {
66904+#endif
66905+ mss.vma = vma;
66906+ /* mmap_sem is held in m_start */
66907+ if (vma->vm_mm && !is_vm_hugetlb_page(vma))
66908+ walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
66909+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66910+ }
66911+#endif
66912 show_map_vma(m, vma, is_pid);
66913
66914 seq_printf(m,
66915@@ -617,7 +663,11 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
66916 "KernelPageSize: %8lu kB\n"
66917 "MMUPageSize: %8lu kB\n"
66918 "Locked: %8lu kB\n",
66919+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66920+ PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
66921+#else
66922 (vma->vm_end - vma->vm_start) >> 10,
66923+#endif
66924 mss.resident >> 10,
66925 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
66926 mss.shared_clean >> 10,
66927@@ -1447,6 +1497,13 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
66928 char buffer[64];
66929 int nid;
66930
66931+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66932+ if (current->exec_id != m->exec_id) {
66933+ gr_log_badprocpid("numa_maps");
66934+ return 0;
66935+ }
66936+#endif
66937+
66938 if (!mm)
66939 return 0;
66940
66941@@ -1468,11 +1525,15 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
66942 mpol_to_str(buffer, sizeof(buffer), proc_priv->task_mempolicy);
66943 }
66944
66945+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66946+ seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
66947+#else
66948 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
66949+#endif
66950
66951 if (file) {
66952 seq_puts(m, " file=");
66953- seq_path(m, &file->f_path, "\n\t= ");
66954+ seq_path(m, &file->f_path, "\n\t\\= ");
66955 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
66956 seq_puts(m, " heap");
66957 } else {
66958diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
66959index 599ec2e..f1413ae 100644
66960--- a/fs/proc/task_nommu.c
66961+++ b/fs/proc/task_nommu.c
66962@@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
66963 else
66964 bytes += kobjsize(mm);
66965
66966- if (current->fs && current->fs->users > 1)
66967+ if (current->fs && atomic_read(&current->fs->users) > 1)
66968 sbytes += kobjsize(current->fs);
66969 else
66970 bytes += kobjsize(current->fs);
66971@@ -180,7 +180,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
66972
66973 if (file) {
66974 seq_pad(m, ' ');
66975- seq_path(m, &file->f_path, "");
66976+ seq_path(m, &file->f_path, "\n\\");
66977 } else if (mm) {
66978 pid_t tid = pid_of_stack(priv, vma, is_pid);
66979
66980diff --git a/fs/proc/vmcore.c b/fs/proc/vmcore.c
66981index a90d6d35..d08047c 100644
66982--- a/fs/proc/vmcore.c
66983+++ b/fs/proc/vmcore.c
66984@@ -105,9 +105,13 @@ static ssize_t read_from_oldmem(char *buf, size_t count,
66985 nr_bytes = count;
66986
66987 /* If pfn is not ram, return zeros for sparse dump files */
66988- if (pfn_is_ram(pfn) == 0)
66989- memset(buf, 0, nr_bytes);
66990- else {
66991+ if (pfn_is_ram(pfn) == 0) {
66992+ if (userbuf) {
66993+ if (clear_user((char __force_user *)buf, nr_bytes))
66994+ return -EFAULT;
66995+ } else
66996+ memset(buf, 0, nr_bytes);
66997+ } else {
66998 tmp = copy_oldmem_page(pfn, buf, nr_bytes,
66999 offset, userbuf);
67000 if (tmp < 0)
67001@@ -170,7 +174,7 @@ int __weak remap_oldmem_pfn_range(struct vm_area_struct *vma,
67002 static int copy_to(void *target, void *src, size_t size, int userbuf)
67003 {
67004 if (userbuf) {
67005- if (copy_to_user((char __user *) target, src, size))
67006+ if (copy_to_user((char __force_user *) target, src, size))
67007 return -EFAULT;
67008 } else {
67009 memcpy(target, src, size);
67010@@ -233,7 +237,7 @@ static ssize_t __read_vmcore(char *buffer, size_t buflen, loff_t *fpos,
67011 if (*fpos < m->offset + m->size) {
67012 tsz = min_t(size_t, m->offset + m->size - *fpos, buflen);
67013 start = m->paddr + *fpos - m->offset;
67014- tmp = read_from_oldmem(buffer, tsz, &start, userbuf);
67015+ tmp = read_from_oldmem((char __force_kernel *)buffer, tsz, &start, userbuf);
67016 if (tmp < 0)
67017 return tmp;
67018 buflen -= tsz;
67019@@ -253,7 +257,7 @@ static ssize_t __read_vmcore(char *buffer, size_t buflen, loff_t *fpos,
67020 static ssize_t read_vmcore(struct file *file, char __user *buffer,
67021 size_t buflen, loff_t *fpos)
67022 {
67023- return __read_vmcore((__force char *) buffer, buflen, fpos, 1);
67024+ return __read_vmcore((__force_kernel char *) buffer, buflen, fpos, 1);
67025 }
67026
67027 /*
67028diff --git a/fs/qnx6/qnx6.h b/fs/qnx6/qnx6.h
67029index d3fb2b6..43a8140 100644
67030--- a/fs/qnx6/qnx6.h
67031+++ b/fs/qnx6/qnx6.h
67032@@ -74,7 +74,7 @@ enum {
67033 BYTESEX_BE,
67034 };
67035
67036-static inline __u64 fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
67037+static inline __u64 __intentional_overflow(-1) fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
67038 {
67039 if (sbi->s_bytesex == BYTESEX_LE)
67040 return le64_to_cpu((__force __le64)n);
67041@@ -90,7 +90,7 @@ static inline __fs64 cpu_to_fs64(struct qnx6_sb_info *sbi, __u64 n)
67042 return (__force __fs64)cpu_to_be64(n);
67043 }
67044
67045-static inline __u32 fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
67046+static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
67047 {
67048 if (sbi->s_bytesex == BYTESEX_LE)
67049 return le32_to_cpu((__force __le32)n);
67050diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
67051index bb2869f..d34ada8 100644
67052--- a/fs/quota/netlink.c
67053+++ b/fs/quota/netlink.c
67054@@ -44,7 +44,7 @@ static struct genl_family quota_genl_family = {
67055 void quota_send_warning(struct kqid qid, dev_t dev,
67056 const char warntype)
67057 {
67058- static atomic_t seq;
67059+ static atomic_unchecked_t seq;
67060 struct sk_buff *skb;
67061 void *msg_head;
67062 int ret;
67063@@ -60,7 +60,7 @@ void quota_send_warning(struct kqid qid, dev_t dev,
67064 "VFS: Not enough memory to send quota warning.\n");
67065 return;
67066 }
67067- msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
67068+ msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
67069 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
67070 if (!msg_head) {
67071 printk(KERN_ERR
67072diff --git a/fs/read_write.c b/fs/read_write.c
67073index 7d9318c..51b336f 100644
67074--- a/fs/read_write.c
67075+++ b/fs/read_write.c
67076@@ -495,7 +495,7 @@ ssize_t __kernel_write(struct file *file, const char *buf, size_t count, loff_t
67077
67078 old_fs = get_fs();
67079 set_fs(get_ds());
67080- p = (__force const char __user *)buf;
67081+ p = (const char __force_user *)buf;
67082 if (count > MAX_RW_COUNT)
67083 count = MAX_RW_COUNT;
67084 if (file->f_op->write)
67085diff --git a/fs/readdir.c b/fs/readdir.c
67086index 33fd922..e0d6094 100644
67087--- a/fs/readdir.c
67088+++ b/fs/readdir.c
67089@@ -18,6 +18,7 @@
67090 #include <linux/security.h>
67091 #include <linux/syscalls.h>
67092 #include <linux/unistd.h>
67093+#include <linux/namei.h>
67094
67095 #include <asm/uaccess.h>
67096
67097@@ -71,6 +72,7 @@ struct old_linux_dirent {
67098 struct readdir_callback {
67099 struct dir_context ctx;
67100 struct old_linux_dirent __user * dirent;
67101+ struct file * file;
67102 int result;
67103 };
67104
67105@@ -88,6 +90,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
67106 buf->result = -EOVERFLOW;
67107 return -EOVERFLOW;
67108 }
67109+
67110+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
67111+ return 0;
67112+
67113 buf->result++;
67114 dirent = buf->dirent;
67115 if (!access_ok(VERIFY_WRITE, dirent,
67116@@ -119,6 +125,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
67117 if (!f.file)
67118 return -EBADF;
67119
67120+ buf.file = f.file;
67121 error = iterate_dir(f.file, &buf.ctx);
67122 if (buf.result)
67123 error = buf.result;
67124@@ -144,6 +151,7 @@ struct getdents_callback {
67125 struct dir_context ctx;
67126 struct linux_dirent __user * current_dir;
67127 struct linux_dirent __user * previous;
67128+ struct file * file;
67129 int count;
67130 int error;
67131 };
67132@@ -165,6 +173,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
67133 buf->error = -EOVERFLOW;
67134 return -EOVERFLOW;
67135 }
67136+
67137+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
67138+ return 0;
67139+
67140 dirent = buf->previous;
67141 if (dirent) {
67142 if (__put_user(offset, &dirent->d_off))
67143@@ -210,6 +222,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
67144 if (!f.file)
67145 return -EBADF;
67146
67147+ buf.file = f.file;
67148 error = iterate_dir(f.file, &buf.ctx);
67149 if (error >= 0)
67150 error = buf.error;
67151@@ -228,6 +241,7 @@ struct getdents_callback64 {
67152 struct dir_context ctx;
67153 struct linux_dirent64 __user * current_dir;
67154 struct linux_dirent64 __user * previous;
67155+ struct file *file;
67156 int count;
67157 int error;
67158 };
67159@@ -243,6 +257,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
67160 buf->error = -EINVAL; /* only used if we fail.. */
67161 if (reclen > buf->count)
67162 return -EINVAL;
67163+
67164+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
67165+ return 0;
67166+
67167 dirent = buf->previous;
67168 if (dirent) {
67169 if (__put_user(offset, &dirent->d_off))
67170@@ -290,6 +308,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
67171 if (!f.file)
67172 return -EBADF;
67173
67174+ buf.file = f.file;
67175 error = iterate_dir(f.file, &buf.ctx);
67176 if (error >= 0)
67177 error = buf.error;
67178diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
67179index 9c02d96..6562c10 100644
67180--- a/fs/reiserfs/do_balan.c
67181+++ b/fs/reiserfs/do_balan.c
67182@@ -1887,7 +1887,7 @@ void do_balance(struct tree_balance *tb, struct item_head *ih,
67183 return;
67184 }
67185
67186- atomic_inc(&fs_generation(tb->tb_sb));
67187+ atomic_inc_unchecked(&fs_generation(tb->tb_sb));
67188 do_balance_starts(tb);
67189
67190 /*
67191diff --git a/fs/reiserfs/item_ops.c b/fs/reiserfs/item_ops.c
67192index aca73dd..e3c558d 100644
67193--- a/fs/reiserfs/item_ops.c
67194+++ b/fs/reiserfs/item_ops.c
67195@@ -724,18 +724,18 @@ static void errcatch_print_vi(struct virtual_item *vi)
67196 }
67197
67198 static struct item_operations errcatch_ops = {
67199- errcatch_bytes_number,
67200- errcatch_decrement_key,
67201- errcatch_is_left_mergeable,
67202- errcatch_print_item,
67203- errcatch_check_item,
67204+ .bytes_number = errcatch_bytes_number,
67205+ .decrement_key = errcatch_decrement_key,
67206+ .is_left_mergeable = errcatch_is_left_mergeable,
67207+ .print_item = errcatch_print_item,
67208+ .check_item = errcatch_check_item,
67209
67210- errcatch_create_vi,
67211- errcatch_check_left,
67212- errcatch_check_right,
67213- errcatch_part_size,
67214- errcatch_unit_num,
67215- errcatch_print_vi
67216+ .create_vi = errcatch_create_vi,
67217+ .check_left = errcatch_check_left,
67218+ .check_right = errcatch_check_right,
67219+ .part_size = errcatch_part_size,
67220+ .unit_num = errcatch_unit_num,
67221+ .print_vi = errcatch_print_vi
67222 };
67223
67224 #if ! (TYPE_STAT_DATA == 0 && TYPE_INDIRECT == 1 && TYPE_DIRECT == 2 && TYPE_DIRENTRY == 3)
67225diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
67226index 621b9f3..af527fd 100644
67227--- a/fs/reiserfs/procfs.c
67228+++ b/fs/reiserfs/procfs.c
67229@@ -114,7 +114,7 @@ static int show_super(struct seq_file *m, void *unused)
67230 "SMALL_TAILS " : "NO_TAILS ",
67231 replay_only(sb) ? "REPLAY_ONLY " : "",
67232 convert_reiserfs(sb) ? "CONV " : "",
67233- atomic_read(&r->s_generation_counter),
67234+ atomic_read_unchecked(&r->s_generation_counter),
67235 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
67236 SF(s_do_balance), SF(s_unneeded_left_neighbor),
67237 SF(s_good_search_by_key_reada), SF(s_bmaps),
67238diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h
67239index 1894d96..1dfd1c2 100644
67240--- a/fs/reiserfs/reiserfs.h
67241+++ b/fs/reiserfs/reiserfs.h
67242@@ -576,7 +576,7 @@ struct reiserfs_sb_info {
67243 /* Comment? -Hans */
67244 wait_queue_head_t s_wait;
67245 /* increased by one every time the tree gets re-balanced */
67246- atomic_t s_generation_counter;
67247+ atomic_unchecked_t s_generation_counter;
67248
67249 /* File system properties. Currently holds on-disk FS format */
67250 unsigned long s_properties;
67251@@ -2297,7 +2297,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
67252 #define REISERFS_USER_MEM 1 /* user memory mode */
67253
67254 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
67255-#define get_generation(s) atomic_read (&fs_generation(s))
67256+#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
67257 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
67258 #define __fs_changed(gen,s) (gen != get_generation (s))
67259 #define fs_changed(gen,s) \
67260diff --git a/fs/reiserfs/super.c b/fs/reiserfs/super.c
67261index f1376c9..f9378e9 100644
67262--- a/fs/reiserfs/super.c
67263+++ b/fs/reiserfs/super.c
67264@@ -1857,6 +1857,10 @@ static int reiserfs_fill_super(struct super_block *s, void *data, int silent)
67265 sbi->s_mount_opt |= (1 << REISERFS_SMALLTAIL);
67266 sbi->s_mount_opt |= (1 << REISERFS_ERROR_RO);
67267 sbi->s_mount_opt |= (1 << REISERFS_BARRIER_FLUSH);
67268+#ifdef CONFIG_REISERFS_FS_XATTR
67269+ /* turn on user xattrs by default */
67270+ sbi->s_mount_opt |= (1 << REISERFS_XATTRS_USER);
67271+#endif
67272 /* no preallocation minimum, be smart in reiserfs_file_write instead */
67273 sbi->s_alloc_options.preallocmin = 0;
67274 /* Preallocate by 16 blocks (17-1) at once */
67275diff --git a/fs/select.c b/fs/select.c
67276index 467bb1c..cf9d65a 100644
67277--- a/fs/select.c
67278+++ b/fs/select.c
67279@@ -20,6 +20,7 @@
67280 #include <linux/export.h>
67281 #include <linux/slab.h>
67282 #include <linux/poll.h>
67283+#include <linux/security.h>
67284 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
67285 #include <linux/file.h>
67286 #include <linux/fdtable.h>
67287@@ -880,6 +881,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
67288 struct poll_list *walk = head;
67289 unsigned long todo = nfds;
67290
67291+ gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
67292 if (nfds > rlimit(RLIMIT_NOFILE))
67293 return -EINVAL;
67294
67295diff --git a/fs/seq_file.c b/fs/seq_file.c
67296index 3857b72..0b7281e 100644
67297--- a/fs/seq_file.c
67298+++ b/fs/seq_file.c
67299@@ -12,6 +12,8 @@
67300 #include <linux/slab.h>
67301 #include <linux/cred.h>
67302 #include <linux/mm.h>
67303+#include <linux/sched.h>
67304+#include <linux/grsecurity.h>
67305
67306 #include <asm/uaccess.h>
67307 #include <asm/page.h>
67308@@ -34,12 +36,7 @@ static void seq_set_overflow(struct seq_file *m)
67309
67310 static void *seq_buf_alloc(unsigned long size)
67311 {
67312- void *buf;
67313-
67314- buf = kmalloc(size, GFP_KERNEL | __GFP_NOWARN);
67315- if (!buf && size > PAGE_SIZE)
67316- buf = vmalloc(size);
67317- return buf;
67318+ return kmalloc(size, GFP_KERNEL | GFP_USERCOPY);
67319 }
67320
67321 /**
67322@@ -72,6 +69,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
67323 #ifdef CONFIG_USER_NS
67324 p->user_ns = file->f_cred->user_ns;
67325 #endif
67326+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67327+ p->exec_id = current->exec_id;
67328+#endif
67329
67330 /*
67331 * Wrappers around seq_open(e.g. swaps_open) need to be
67332@@ -94,6 +94,16 @@ int seq_open(struct file *file, const struct seq_operations *op)
67333 }
67334 EXPORT_SYMBOL(seq_open);
67335
67336+
67337+int seq_open_restrict(struct file *file, const struct seq_operations *op)
67338+{
67339+ if (gr_proc_is_restricted())
67340+ return -EACCES;
67341+
67342+ return seq_open(file, op);
67343+}
67344+EXPORT_SYMBOL(seq_open_restrict);
67345+
67346 static int traverse(struct seq_file *m, loff_t offset)
67347 {
67348 loff_t pos = 0, index;
67349@@ -165,7 +175,7 @@ Eoverflow:
67350 ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
67351 {
67352 struct seq_file *m = file->private_data;
67353- size_t copied = 0;
67354+ ssize_t copied = 0;
67355 loff_t pos;
67356 size_t n;
67357 void *p;
67358@@ -596,7 +606,7 @@ static void single_stop(struct seq_file *p, void *v)
67359 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
67360 void *data)
67361 {
67362- struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
67363+ seq_operations_no_const *op = kzalloc(sizeof(*op), GFP_KERNEL);
67364 int res = -ENOMEM;
67365
67366 if (op) {
67367@@ -632,6 +642,17 @@ int single_open_size(struct file *file, int (*show)(struct seq_file *, void *),
67368 }
67369 EXPORT_SYMBOL(single_open_size);
67370
67371+int single_open_restrict(struct file *file, int (*show)(struct seq_file *, void *),
67372+ void *data)
67373+{
67374+ if (gr_proc_is_restricted())
67375+ return -EACCES;
67376+
67377+ return single_open(file, show, data);
67378+}
67379+EXPORT_SYMBOL(single_open_restrict);
67380+
67381+
67382 int single_release(struct inode *inode, struct file *file)
67383 {
67384 const struct seq_operations *op = ((struct seq_file *)file->private_data)->op;
67385diff --git a/fs/splice.c b/fs/splice.c
67386index 75c6058..770d40c 100644
67387--- a/fs/splice.c
67388+++ b/fs/splice.c
67389@@ -193,7 +193,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
67390 pipe_lock(pipe);
67391
67392 for (;;) {
67393- if (!pipe->readers) {
67394+ if (!atomic_read(&pipe->readers)) {
67395 send_sig(SIGPIPE, current, 0);
67396 if (!ret)
67397 ret = -EPIPE;
67398@@ -216,7 +216,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
67399 page_nr++;
67400 ret += buf->len;
67401
67402- if (pipe->files)
67403+ if (atomic_read(&pipe->files))
67404 do_wakeup = 1;
67405
67406 if (!--spd->nr_pages)
67407@@ -247,9 +247,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
67408 do_wakeup = 0;
67409 }
67410
67411- pipe->waiting_writers++;
67412+ atomic_inc(&pipe->waiting_writers);
67413 pipe_wait(pipe);
67414- pipe->waiting_writers--;
67415+ atomic_dec(&pipe->waiting_writers);
67416 }
67417
67418 pipe_unlock(pipe);
67419@@ -576,7 +576,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
67420 old_fs = get_fs();
67421 set_fs(get_ds());
67422 /* The cast to a user pointer is valid due to the set_fs() */
67423- res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
67424+ res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
67425 set_fs(old_fs);
67426
67427 return res;
67428@@ -591,7 +591,7 @@ ssize_t kernel_write(struct file *file, const char *buf, size_t count,
67429 old_fs = get_fs();
67430 set_fs(get_ds());
67431 /* The cast to a user pointer is valid due to the set_fs() */
67432- res = vfs_write(file, (__force const char __user *)buf, count, &pos);
67433+ res = vfs_write(file, (const char __force_user *)buf, count, &pos);
67434 set_fs(old_fs);
67435
67436 return res;
67437@@ -644,7 +644,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
67438 goto err;
67439
67440 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
67441- vec[i].iov_base = (void __user *) page_address(page);
67442+ vec[i].iov_base = (void __force_user *) page_address(page);
67443 vec[i].iov_len = this_len;
67444 spd.pages[i] = page;
67445 spd.nr_pages++;
67446@@ -783,7 +783,7 @@ static int splice_from_pipe_feed(struct pipe_inode_info *pipe, struct splice_des
67447 ops->release(pipe, buf);
67448 pipe->curbuf = (pipe->curbuf + 1) & (pipe->buffers - 1);
67449 pipe->nrbufs--;
67450- if (pipe->files)
67451+ if (atomic_read(&pipe->files))
67452 sd->need_wakeup = true;
67453 }
67454
67455@@ -807,10 +807,10 @@ static int splice_from_pipe_feed(struct pipe_inode_info *pipe, struct splice_des
67456 static int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
67457 {
67458 while (!pipe->nrbufs) {
67459- if (!pipe->writers)
67460+ if (!atomic_read(&pipe->writers))
67461 return 0;
67462
67463- if (!pipe->waiting_writers && sd->num_spliced)
67464+ if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
67465 return 0;
67466
67467 if (sd->flags & SPLICE_F_NONBLOCK)
67468@@ -1040,7 +1040,7 @@ iter_file_splice_write(struct pipe_inode_info *pipe, struct file *out,
67469 ops->release(pipe, buf);
67470 pipe->curbuf = (pipe->curbuf + 1) & (pipe->buffers - 1);
67471 pipe->nrbufs--;
67472- if (pipe->files)
67473+ if (atomic_read(&pipe->files))
67474 sd.need_wakeup = true;
67475 } else {
67476 buf->offset += ret;
67477@@ -1200,7 +1200,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
67478 * out of the pipe right after the splice_to_pipe(). So set
67479 * PIPE_READERS appropriately.
67480 */
67481- pipe->readers = 1;
67482+ atomic_set(&pipe->readers, 1);
67483
67484 current->splice_pipe = pipe;
67485 }
67486@@ -1497,6 +1497,7 @@ static int get_iovec_page_array(const struct iovec __user *iov,
67487
67488 partial[buffers].offset = off;
67489 partial[buffers].len = plen;
67490+ partial[buffers].private = 0;
67491
67492 off = 0;
67493 len -= plen;
67494@@ -1733,9 +1734,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
67495 ret = -ERESTARTSYS;
67496 break;
67497 }
67498- if (!pipe->writers)
67499+ if (!atomic_read(&pipe->writers))
67500 break;
67501- if (!pipe->waiting_writers) {
67502+ if (!atomic_read(&pipe->waiting_writers)) {
67503 if (flags & SPLICE_F_NONBLOCK) {
67504 ret = -EAGAIN;
67505 break;
67506@@ -1767,7 +1768,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
67507 pipe_lock(pipe);
67508
67509 while (pipe->nrbufs >= pipe->buffers) {
67510- if (!pipe->readers) {
67511+ if (!atomic_read(&pipe->readers)) {
67512 send_sig(SIGPIPE, current, 0);
67513 ret = -EPIPE;
67514 break;
67515@@ -1780,9 +1781,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
67516 ret = -ERESTARTSYS;
67517 break;
67518 }
67519- pipe->waiting_writers++;
67520+ atomic_inc(&pipe->waiting_writers);
67521 pipe_wait(pipe);
67522- pipe->waiting_writers--;
67523+ atomic_dec(&pipe->waiting_writers);
67524 }
67525
67526 pipe_unlock(pipe);
67527@@ -1818,14 +1819,14 @@ retry:
67528 pipe_double_lock(ipipe, opipe);
67529
67530 do {
67531- if (!opipe->readers) {
67532+ if (!atomic_read(&opipe->readers)) {
67533 send_sig(SIGPIPE, current, 0);
67534 if (!ret)
67535 ret = -EPIPE;
67536 break;
67537 }
67538
67539- if (!ipipe->nrbufs && !ipipe->writers)
67540+ if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
67541 break;
67542
67543 /*
67544@@ -1922,7 +1923,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
67545 pipe_double_lock(ipipe, opipe);
67546
67547 do {
67548- if (!opipe->readers) {
67549+ if (!atomic_read(&opipe->readers)) {
67550 send_sig(SIGPIPE, current, 0);
67551 if (!ret)
67552 ret = -EPIPE;
67553@@ -1967,7 +1968,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
67554 * return EAGAIN if we have the potential of some data in the
67555 * future, otherwise just return 0
67556 */
67557- if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
67558+ if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
67559 ret = -EAGAIN;
67560
67561 pipe_unlock(ipipe);
67562diff --git a/fs/stat.c b/fs/stat.c
67563index ae0c3ce..9ee641c 100644
67564--- a/fs/stat.c
67565+++ b/fs/stat.c
67566@@ -28,8 +28,13 @@ void generic_fillattr(struct inode *inode, struct kstat *stat)
67567 stat->gid = inode->i_gid;
67568 stat->rdev = inode->i_rdev;
67569 stat->size = i_size_read(inode);
67570- stat->atime = inode->i_atime;
67571- stat->mtime = inode->i_mtime;
67572+ if (is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
67573+ stat->atime = inode->i_ctime;
67574+ stat->mtime = inode->i_ctime;
67575+ } else {
67576+ stat->atime = inode->i_atime;
67577+ stat->mtime = inode->i_mtime;
67578+ }
67579 stat->ctime = inode->i_ctime;
67580 stat->blksize = (1 << inode->i_blkbits);
67581 stat->blocks = inode->i_blocks;
67582@@ -52,9 +57,16 @@ EXPORT_SYMBOL(generic_fillattr);
67583 int vfs_getattr_nosec(struct path *path, struct kstat *stat)
67584 {
67585 struct inode *inode = path->dentry->d_inode;
67586+ int retval;
67587
67588- if (inode->i_op->getattr)
67589- return inode->i_op->getattr(path->mnt, path->dentry, stat);
67590+ if (inode->i_op->getattr) {
67591+ retval = inode->i_op->getattr(path->mnt, path->dentry, stat);
67592+ if (!retval && is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
67593+ stat->atime = stat->ctime;
67594+ stat->mtime = stat->ctime;
67595+ }
67596+ return retval;
67597+ }
67598
67599 generic_fillattr(inode, stat);
67600 return 0;
67601diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
67602index 0b45ff4..847de5b 100644
67603--- a/fs/sysfs/dir.c
67604+++ b/fs/sysfs/dir.c
67605@@ -41,9 +41,16 @@ void sysfs_warn_dup(struct kernfs_node *parent, const char *name)
67606 int sysfs_create_dir_ns(struct kobject *kobj, const void *ns)
67607 {
67608 struct kernfs_node *parent, *kn;
67609+ const char *name;
67610+ umode_t mode = S_IRWXU | S_IRUGO | S_IXUGO;
67611+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
67612+ const char *parent_name;
67613+#endif
67614
67615 BUG_ON(!kobj);
67616
67617+ name = kobject_name(kobj);
67618+
67619 if (kobj->parent)
67620 parent = kobj->parent->sd;
67621 else
67622@@ -52,11 +59,22 @@ int sysfs_create_dir_ns(struct kobject *kobj, const void *ns)
67623 if (!parent)
67624 return -ENOENT;
67625
67626- kn = kernfs_create_dir_ns(parent, kobject_name(kobj),
67627- S_IRWXU | S_IRUGO | S_IXUGO, kobj, ns);
67628+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
67629+ parent_name = parent->name;
67630+ mode = S_IRWXU;
67631+
67632+ if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
67633+ (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
67634+ (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse") || !strcmp(name, "ecryptfs"))) ||
67635+ (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
67636+ mode = S_IRWXU | S_IRUGO | S_IXUGO;
67637+#endif
67638+
67639+ kn = kernfs_create_dir_ns(parent, name,
67640+ mode, kobj, ns);
67641 if (IS_ERR(kn)) {
67642 if (PTR_ERR(kn) == -EEXIST)
67643- sysfs_warn_dup(parent, kobject_name(kobj));
67644+ sysfs_warn_dup(parent, name);
67645 return PTR_ERR(kn);
67646 }
67647
67648diff --git a/fs/sysv/sysv.h b/fs/sysv/sysv.h
67649index 69d4889..a810bd4 100644
67650--- a/fs/sysv/sysv.h
67651+++ b/fs/sysv/sysv.h
67652@@ -188,7 +188,7 @@ static inline u32 PDP_swab(u32 x)
67653 #endif
67654 }
67655
67656-static inline __u32 fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
67657+static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
67658 {
67659 if (sbi->s_bytesex == BYTESEX_PDP)
67660 return PDP_swab((__force __u32)n);
67661diff --git a/fs/ubifs/io.c b/fs/ubifs/io.c
67662index fb08b0c..65fcc7e 100644
67663--- a/fs/ubifs/io.c
67664+++ b/fs/ubifs/io.c
67665@@ -155,7 +155,7 @@ int ubifs_leb_change(struct ubifs_info *c, int lnum, const void *buf, int len)
67666 return err;
67667 }
67668
67669-int ubifs_leb_unmap(struct ubifs_info *c, int lnum)
67670+int __intentional_overflow(-1) ubifs_leb_unmap(struct ubifs_info *c, int lnum)
67671 {
67672 int err;
67673
67674diff --git a/fs/udf/dir.c b/fs/udf/dir.c
67675index a012c51..a7690b4 100644
67676--- a/fs/udf/dir.c
67677+++ b/fs/udf/dir.c
67678@@ -167,7 +167,8 @@ static int udf_readdir(struct file *file, struct dir_context *ctx)
67679 continue;
67680 }
67681
67682- flen = udf_get_filename(dir->i_sb, nameptr, fname, lfi);
67683+ flen = udf_get_filename(dir->i_sb, nameptr, lfi, fname,
67684+ UDF_NAME_LEN);
67685 if (!flen)
67686 continue;
67687
67688diff --git a/fs/udf/inode.c b/fs/udf/inode.c
67689index c9b4df5..5bc71d9 100644
67690--- a/fs/udf/inode.c
67691+++ b/fs/udf/inode.c
67692@@ -1489,6 +1489,20 @@ reread:
67693 }
67694 inode->i_generation = iinfo->i_unique;
67695
67696+ /* Sanity checks for files in ICB so that we don't get confused later */
67697+ if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB) {
67698+ /*
67699+ * For file in ICB data is stored in allocation descriptor
67700+ * so sizes should match
67701+ */
67702+ if (iinfo->i_lenAlloc != inode->i_size)
67703+ goto out;
67704+ /* File in ICB has to fit in there... */
67705+ if (inode->i_size > inode->i_sb->s_blocksize -
67706+ udf_file_entry_alloc_offset(inode))
67707+ goto out;
67708+ }
67709+
67710 switch (fe->icbTag.fileType) {
67711 case ICBTAG_FILE_TYPE_DIRECTORY:
67712 inode->i_op = &udf_dir_inode_operations;
67713diff --git a/fs/udf/misc.c b/fs/udf/misc.c
67714index c175b4d..8f36a16 100644
67715--- a/fs/udf/misc.c
67716+++ b/fs/udf/misc.c
67717@@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
67718
67719 u8 udf_tag_checksum(const struct tag *t)
67720 {
67721- u8 *data = (u8 *)t;
67722+ const u8 *data = (const u8 *)t;
67723 u8 checksum = 0;
67724 int i;
67725 for (i = 0; i < sizeof(struct tag); ++i)
67726diff --git a/fs/udf/namei.c b/fs/udf/namei.c
67727index c12e260..6ff19b5 100644
67728--- a/fs/udf/namei.c
67729+++ b/fs/udf/namei.c
67730@@ -233,7 +233,8 @@ static struct fileIdentDesc *udf_find_entry(struct inode *dir,
67731 if (!lfi)
67732 continue;
67733
67734- flen = udf_get_filename(dir->i_sb, nameptr, fname, lfi);
67735+ flen = udf_get_filename(dir->i_sb, nameptr, lfi, fname,
67736+ UDF_NAME_LEN);
67737 if (flen && udf_match(flen, fname, child->len, child->name))
67738 goto out_ok;
67739 }
67740diff --git a/fs/udf/symlink.c b/fs/udf/symlink.c
67741index 6fb7945..ac10ca9 100644
67742--- a/fs/udf/symlink.c
67743+++ b/fs/udf/symlink.c
67744@@ -30,49 +30,73 @@
67745 #include <linux/buffer_head.h>
67746 #include "udf_i.h"
67747
67748-static void udf_pc_to_char(struct super_block *sb, unsigned char *from,
67749- int fromlen, unsigned char *to)
67750+static int udf_pc_to_char(struct super_block *sb, unsigned char *from,
67751+ int fromlen, unsigned char *to, int tolen)
67752 {
67753 struct pathComponent *pc;
67754 int elen = 0;
67755+ int comp_len;
67756 unsigned char *p = to;
67757
67758+ /* Reserve one byte for terminating \0 */
67759+ tolen--;
67760 while (elen < fromlen) {
67761 pc = (struct pathComponent *)(from + elen);
67762+ elen += sizeof(struct pathComponent);
67763 switch (pc->componentType) {
67764 case 1:
67765 /*
67766 * Symlink points to some place which should be agreed
67767 * upon between originator and receiver of the media. Ignore.
67768 */
67769- if (pc->lengthComponentIdent > 0)
67770+ if (pc->lengthComponentIdent > 0) {
67771+ elen += pc->lengthComponentIdent;
67772 break;
67773+ }
67774 /* Fall through */
67775 case 2:
67776+ if (tolen == 0)
67777+ return -ENAMETOOLONG;
67778 p = to;
67779 *p++ = '/';
67780+ tolen--;
67781 break;
67782 case 3:
67783+ if (tolen < 3)
67784+ return -ENAMETOOLONG;
67785 memcpy(p, "../", 3);
67786 p += 3;
67787+ tolen -= 3;
67788 break;
67789 case 4:
67790+ if (tolen < 2)
67791+ return -ENAMETOOLONG;
67792 memcpy(p, "./", 2);
67793 p += 2;
67794+ tolen -= 2;
67795 /* that would be . - just ignore */
67796 break;
67797 case 5:
67798- p += udf_get_filename(sb, pc->componentIdent, p,
67799- pc->lengthComponentIdent);
67800+ elen += pc->lengthComponentIdent;
67801+ if (elen > fromlen)
67802+ return -EIO;
67803+ comp_len = udf_get_filename(sb, pc->componentIdent,
67804+ pc->lengthComponentIdent,
67805+ p, tolen);
67806+ p += comp_len;
67807+ tolen -= comp_len;
67808+ if (tolen == 0)
67809+ return -ENAMETOOLONG;
67810 *p++ = '/';
67811+ tolen--;
67812 break;
67813 }
67814- elen += sizeof(struct pathComponent) + pc->lengthComponentIdent;
67815 }
67816 if (p > to + 1)
67817 p[-1] = '\0';
67818 else
67819 p[0] = '\0';
67820+ return 0;
67821 }
67822
67823 static int udf_symlink_filler(struct file *file, struct page *page)
67824@@ -80,11 +104,17 @@ static int udf_symlink_filler(struct file *file, struct page *page)
67825 struct inode *inode = page->mapping->host;
67826 struct buffer_head *bh = NULL;
67827 unsigned char *symlink;
67828- int err = -EIO;
67829+ int err;
67830 unsigned char *p = kmap(page);
67831 struct udf_inode_info *iinfo;
67832 uint32_t pos;
67833
67834+ /* We don't support symlinks longer than one block */
67835+ if (inode->i_size > inode->i_sb->s_blocksize) {
67836+ err = -ENAMETOOLONG;
67837+ goto out_unmap;
67838+ }
67839+
67840 iinfo = UDF_I(inode);
67841 pos = udf_block_map(inode, 0);
67842
67843@@ -94,14 +124,18 @@ static int udf_symlink_filler(struct file *file, struct page *page)
67844 } else {
67845 bh = sb_bread(inode->i_sb, pos);
67846
67847- if (!bh)
67848- goto out;
67849+ if (!bh) {
67850+ err = -EIO;
67851+ goto out_unlock_inode;
67852+ }
67853
67854 symlink = bh->b_data;
67855 }
67856
67857- udf_pc_to_char(inode->i_sb, symlink, inode->i_size, p);
67858+ err = udf_pc_to_char(inode->i_sb, symlink, inode->i_size, p, PAGE_SIZE);
67859 brelse(bh);
67860+ if (err)
67861+ goto out_unlock_inode;
67862
67863 up_read(&iinfo->i_data_sem);
67864 SetPageUptodate(page);
67865@@ -109,9 +143,10 @@ static int udf_symlink_filler(struct file *file, struct page *page)
67866 unlock_page(page);
67867 return 0;
67868
67869-out:
67870+out_unlock_inode:
67871 up_read(&iinfo->i_data_sem);
67872 SetPageError(page);
67873+out_unmap:
67874 kunmap(page);
67875 unlock_page(page);
67876 return err;
67877diff --git a/fs/udf/udfdecl.h b/fs/udf/udfdecl.h
67878index 1cc3c99..47bb3f5 100644
67879--- a/fs/udf/udfdecl.h
67880+++ b/fs/udf/udfdecl.h
67881@@ -211,7 +211,8 @@ udf_get_lb_pblock(struct super_block *sb, struct kernel_lb_addr *loc,
67882 }
67883
67884 /* unicode.c */
67885-extern int udf_get_filename(struct super_block *, uint8_t *, uint8_t *, int);
67886+extern int udf_get_filename(struct super_block *, uint8_t *, int, uint8_t *,
67887+ int);
67888 extern int udf_put_filename(struct super_block *, const uint8_t *, uint8_t *,
67889 int);
67890 extern int udf_build_ustr(struct ustr *, dstring *, int);
67891diff --git a/fs/udf/unicode.c b/fs/udf/unicode.c
67892index afd470e..b84fee3 100644
67893--- a/fs/udf/unicode.c
67894+++ b/fs/udf/unicode.c
67895@@ -28,7 +28,8 @@
67896
67897 #include "udf_sb.h"
67898
67899-static int udf_translate_to_linux(uint8_t *, uint8_t *, int, uint8_t *, int);
67900+static int udf_translate_to_linux(uint8_t *, int, uint8_t *, int, uint8_t *,
67901+ int);
67902
67903 static int udf_char_to_ustr(struct ustr *dest, const uint8_t *src, int strlen)
67904 {
67905@@ -333,8 +334,8 @@ try_again:
67906 return u_len + 1;
67907 }
67908
67909-int udf_get_filename(struct super_block *sb, uint8_t *sname, uint8_t *dname,
67910- int flen)
67911+int udf_get_filename(struct super_block *sb, uint8_t *sname, int slen,
67912+ uint8_t *dname, int dlen)
67913 {
67914 struct ustr *filename, *unifilename;
67915 int len = 0;
67916@@ -347,7 +348,7 @@ int udf_get_filename(struct super_block *sb, uint8_t *sname, uint8_t *dname,
67917 if (!unifilename)
67918 goto out1;
67919
67920- if (udf_build_ustr_exact(unifilename, sname, flen))
67921+ if (udf_build_ustr_exact(unifilename, sname, slen))
67922 goto out2;
67923
67924 if (UDF_QUERY_FLAG(sb, UDF_FLAG_UTF8)) {
67925@@ -366,7 +367,8 @@ int udf_get_filename(struct super_block *sb, uint8_t *sname, uint8_t *dname,
67926 } else
67927 goto out2;
67928
67929- len = udf_translate_to_linux(dname, filename->u_name, filename->u_len,
67930+ len = udf_translate_to_linux(dname, dlen,
67931+ filename->u_name, filename->u_len,
67932 unifilename->u_name, unifilename->u_len);
67933 out2:
67934 kfree(unifilename);
67935@@ -403,10 +405,12 @@ int udf_put_filename(struct super_block *sb, const uint8_t *sname,
67936 #define EXT_MARK '.'
67937 #define CRC_MARK '#'
67938 #define EXT_SIZE 5
67939+/* Number of chars we need to store generated CRC to make filename unique */
67940+#define CRC_LEN 5
67941
67942-static int udf_translate_to_linux(uint8_t *newName, uint8_t *udfName,
67943- int udfLen, uint8_t *fidName,
67944- int fidNameLen)
67945+static int udf_translate_to_linux(uint8_t *newName, int newLen,
67946+ uint8_t *udfName, int udfLen,
67947+ uint8_t *fidName, int fidNameLen)
67948 {
67949 int index, newIndex = 0, needsCRC = 0;
67950 int extIndex = 0, newExtIndex = 0, hasExt = 0;
67951@@ -439,7 +443,7 @@ static int udf_translate_to_linux(uint8_t *newName, uint8_t *udfName,
67952 newExtIndex = newIndex;
67953 }
67954 }
67955- if (newIndex < 256)
67956+ if (newIndex < newLen)
67957 newName[newIndex++] = curr;
67958 else
67959 needsCRC = 1;
67960@@ -467,13 +471,13 @@ static int udf_translate_to_linux(uint8_t *newName, uint8_t *udfName,
67961 }
67962 ext[localExtIndex++] = curr;
67963 }
67964- maxFilenameLen = 250 - localExtIndex;
67965+ maxFilenameLen = newLen - CRC_LEN - localExtIndex;
67966 if (newIndex > maxFilenameLen)
67967 newIndex = maxFilenameLen;
67968 else
67969 newIndex = newExtIndex;
67970- } else if (newIndex > 250)
67971- newIndex = 250;
67972+ } else if (newIndex > newLen - CRC_LEN)
67973+ newIndex = newLen - CRC_LEN;
67974 newName[newIndex++] = CRC_MARK;
67975 valueCRC = crc_itu_t(0, fidName, fidNameLen);
67976 newName[newIndex++] = hex_asc_upper_hi(valueCRC >> 8);
67977diff --git a/fs/ufs/swab.h b/fs/ufs/swab.h
67978index 8d974c4..b82f6ec 100644
67979--- a/fs/ufs/swab.h
67980+++ b/fs/ufs/swab.h
67981@@ -22,7 +22,7 @@ enum {
67982 BYTESEX_BE
67983 };
67984
67985-static inline u64
67986+static inline u64 __intentional_overflow(-1)
67987 fs64_to_cpu(struct super_block *sbp, __fs64 n)
67988 {
67989 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
67990@@ -40,7 +40,7 @@ cpu_to_fs64(struct super_block *sbp, u64 n)
67991 return (__force __fs64)cpu_to_be64(n);
67992 }
67993
67994-static inline u32
67995+static inline u32 __intentional_overflow(-1)
67996 fs32_to_cpu(struct super_block *sbp, __fs32 n)
67997 {
67998 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
67999diff --git a/fs/utimes.c b/fs/utimes.c
68000index aa138d6..5f3a811 100644
68001--- a/fs/utimes.c
68002+++ b/fs/utimes.c
68003@@ -1,6 +1,7 @@
68004 #include <linux/compiler.h>
68005 #include <linux/file.h>
68006 #include <linux/fs.h>
68007+#include <linux/security.h>
68008 #include <linux/linkage.h>
68009 #include <linux/mount.h>
68010 #include <linux/namei.h>
68011@@ -103,6 +104,12 @@ static int utimes_common(struct path *path, struct timespec *times)
68012 }
68013 }
68014 retry_deleg:
68015+
68016+ if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
68017+ error = -EACCES;
68018+ goto mnt_drop_write_and_out;
68019+ }
68020+
68021 mutex_lock(&inode->i_mutex);
68022 error = notify_change(path->dentry, &newattrs, &delegated_inode);
68023 mutex_unlock(&inode->i_mutex);
68024diff --git a/fs/xattr.c b/fs/xattr.c
68025index 64e83ef..b6be154 100644
68026--- a/fs/xattr.c
68027+++ b/fs/xattr.c
68028@@ -227,6 +227,27 @@ int vfs_xattr_cmp(struct dentry *dentry, const char *xattr_name,
68029 return rc;
68030 }
68031
68032+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
68033+ssize_t
68034+pax_getxattr(struct dentry *dentry, void *value, size_t size)
68035+{
68036+ struct inode *inode = dentry->d_inode;
68037+ ssize_t error;
68038+
68039+ error = inode_permission(inode, MAY_EXEC);
68040+ if (error)
68041+ return error;
68042+
68043+ if (inode->i_op->getxattr)
68044+ error = inode->i_op->getxattr(dentry, XATTR_NAME_PAX_FLAGS, value, size);
68045+ else
68046+ error = -EOPNOTSUPP;
68047+
68048+ return error;
68049+}
68050+EXPORT_SYMBOL(pax_getxattr);
68051+#endif
68052+
68053 ssize_t
68054 vfs_getxattr(struct dentry *dentry, const char *name, void *value, size_t size)
68055 {
68056@@ -319,7 +340,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
68057 * Extended attribute SET operations
68058 */
68059 static long
68060-setxattr(struct dentry *d, const char __user *name, const void __user *value,
68061+setxattr(struct path *path, const char __user *name, const void __user *value,
68062 size_t size, int flags)
68063 {
68064 int error;
68065@@ -355,7 +376,12 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
68066 posix_acl_fix_xattr_from_user(kvalue, size);
68067 }
68068
68069- error = vfs_setxattr(d, kname, kvalue, size, flags);
68070+ if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
68071+ error = -EACCES;
68072+ goto out;
68073+ }
68074+
68075+ error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
68076 out:
68077 if (vvalue)
68078 vfree(vvalue);
68079@@ -376,7 +402,7 @@ retry:
68080 return error;
68081 error = mnt_want_write(path.mnt);
68082 if (!error) {
68083- error = setxattr(path.dentry, name, value, size, flags);
68084+ error = setxattr(&path, name, value, size, flags);
68085 mnt_drop_write(path.mnt);
68086 }
68087 path_put(&path);
68088@@ -405,16 +431,14 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
68089 const void __user *,value, size_t, size, int, flags)
68090 {
68091 struct fd f = fdget(fd);
68092- struct dentry *dentry;
68093 int error = -EBADF;
68094
68095 if (!f.file)
68096 return error;
68097- dentry = f.file->f_path.dentry;
68098- audit_inode(NULL, dentry, 0);
68099+ audit_inode(NULL, f.file->f_path.dentry, 0);
68100 error = mnt_want_write_file(f.file);
68101 if (!error) {
68102- error = setxattr(dentry, name, value, size, flags);
68103+ error = setxattr(&f.file->f_path, name, value, size, flags);
68104 mnt_drop_write_file(f.file);
68105 }
68106 fdput(f);
68107@@ -600,7 +624,7 @@ SYSCALL_DEFINE3(flistxattr, int, fd, char __user *, list, size_t, size)
68108 * Extended attribute REMOVE operations
68109 */
68110 static long
68111-removexattr(struct dentry *d, const char __user *name)
68112+removexattr(struct path *path, const char __user *name)
68113 {
68114 int error;
68115 char kname[XATTR_NAME_MAX + 1];
68116@@ -611,7 +635,10 @@ removexattr(struct dentry *d, const char __user *name)
68117 if (error < 0)
68118 return error;
68119
68120- return vfs_removexattr(d, kname);
68121+ if (!gr_acl_handle_removexattr(path->dentry, path->mnt))
68122+ return -EACCES;
68123+
68124+ return vfs_removexattr(path->dentry, kname);
68125 }
68126
68127 static int path_removexattr(const char __user *pathname,
68128@@ -625,7 +652,7 @@ retry:
68129 return error;
68130 error = mnt_want_write(path.mnt);
68131 if (!error) {
68132- error = removexattr(path.dentry, name);
68133+ error = removexattr(&path, name);
68134 mnt_drop_write(path.mnt);
68135 }
68136 path_put(&path);
68137@@ -651,16 +678,16 @@ SYSCALL_DEFINE2(lremovexattr, const char __user *, pathname,
68138 SYSCALL_DEFINE2(fremovexattr, int, fd, const char __user *, name)
68139 {
68140 struct fd f = fdget(fd);
68141- struct dentry *dentry;
68142+ struct path *path;
68143 int error = -EBADF;
68144
68145 if (!f.file)
68146 return error;
68147- dentry = f.file->f_path.dentry;
68148- audit_inode(NULL, dentry, 0);
68149+ path = &f.file->f_path;
68150+ audit_inode(NULL, path->dentry, 0);
68151 error = mnt_want_write_file(f.file);
68152 if (!error) {
68153- error = removexattr(dentry, name);
68154+ error = removexattr(path, name);
68155 mnt_drop_write_file(f.file);
68156 }
68157 fdput(f);
68158diff --git a/fs/xfs/libxfs/xfs_bmap.c b/fs/xfs/libxfs/xfs_bmap.c
68159index 79c9819..22226b4 100644
68160--- a/fs/xfs/libxfs/xfs_bmap.c
68161+++ b/fs/xfs/libxfs/xfs_bmap.c
68162@@ -583,7 +583,7 @@ xfs_bmap_validate_ret(
68163
68164 #else
68165 #define xfs_bmap_check_leaf_extents(cur, ip, whichfork) do { } while (0)
68166-#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
68167+#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do { } while (0)
68168 #endif /* DEBUG */
68169
68170 /*
68171diff --git a/fs/xfs/xfs_dir2_readdir.c b/fs/xfs/xfs_dir2_readdir.c
68172index f1b69ed..3d0222f 100644
68173--- a/fs/xfs/xfs_dir2_readdir.c
68174+++ b/fs/xfs/xfs_dir2_readdir.c
68175@@ -159,7 +159,12 @@ xfs_dir2_sf_getdents(
68176 ino = dp->d_ops->sf_get_ino(sfp, sfep);
68177 filetype = dp->d_ops->sf_get_ftype(sfep);
68178 ctx->pos = off & 0x7fffffff;
68179- if (!dir_emit(ctx, (char *)sfep->name, sfep->namelen, ino,
68180+ if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
68181+ char name[sfep->namelen];
68182+ memcpy(name, sfep->name, sfep->namelen);
68183+ if (!dir_emit(ctx, name, sfep->namelen, ino, xfs_dir3_get_dtype(dp->i_mount, filetype)))
68184+ return 0;
68185+ } else if (!dir_emit(ctx, (char *)sfep->name, sfep->namelen, ino,
68186 xfs_dir3_get_dtype(dp->i_mount, filetype)))
68187 return 0;
68188 sfep = dp->d_ops->sf_nextentry(sfp, sfep);
68189diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
68190index 24c926b6..8726af88 100644
68191--- a/fs/xfs/xfs_ioctl.c
68192+++ b/fs/xfs/xfs_ioctl.c
68193@@ -122,7 +122,7 @@ xfs_find_handle(
68194 }
68195
68196 error = -EFAULT;
68197- if (copy_to_user(hreq->ohandle, &handle, hsize) ||
68198+ if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
68199 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
68200 goto out_put;
68201
68202diff --git a/fs/xfs/xfs_linux.h b/fs/xfs/xfs_linux.h
68203index 6a51619..9592e1b 100644
68204--- a/fs/xfs/xfs_linux.h
68205+++ b/fs/xfs/xfs_linux.h
68206@@ -234,7 +234,7 @@ static inline kgid_t xfs_gid_to_kgid(__uint32_t gid)
68207 * of the compiler which do not like us using do_div in the middle
68208 * of large functions.
68209 */
68210-static inline __u32 xfs_do_div(void *a, __u32 b, int n)
68211+static inline __u32 __intentional_overflow(-1) xfs_do_div(void *a, __u32 b, int n)
68212 {
68213 __u32 mod;
68214
68215@@ -290,7 +290,7 @@ static inline __u32 xfs_do_mod(void *a, __u32 b, int n)
68216 return 0;
68217 }
68218 #else
68219-static inline __u32 xfs_do_div(void *a, __u32 b, int n)
68220+static inline __u32 __intentional_overflow(-1) xfs_do_div(void *a, __u32 b, int n)
68221 {
68222 __u32 mod;
68223
68224diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
68225new file mode 100644
68226index 0000000..f27264e
68227--- /dev/null
68228+++ b/grsecurity/Kconfig
68229@@ -0,0 +1,1166 @@
68230+#
68231+# grecurity configuration
68232+#
68233+menu "Memory Protections"
68234+depends on GRKERNSEC
68235+
68236+config GRKERNSEC_KMEM
68237+ bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
68238+ default y if GRKERNSEC_CONFIG_AUTO
68239+ select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
68240+ help
68241+ If you say Y here, /dev/kmem and /dev/mem won't be allowed to
68242+ be written to or read from to modify or leak the contents of the running
68243+ kernel. /dev/port will also not be allowed to be opened, writing to
68244+ /dev/cpu/*/msr will be prevented, and support for kexec will be removed.
68245+ If you have module support disabled, enabling this will close up several
68246+ ways that are currently used to insert malicious code into the running
68247+ kernel.
68248+
68249+ Even with this feature enabled, we still highly recommend that
68250+ you use the RBAC system, as it is still possible for an attacker to
68251+ modify the running kernel through other more obscure methods.
68252+
68253+ It is highly recommended that you say Y here if you meet all the
68254+ conditions above.
68255+
68256+config GRKERNSEC_VM86
68257+ bool "Restrict VM86 mode"
68258+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
68259+ depends on X86_32
68260+
68261+ help
68262+ If you say Y here, only processes with CAP_SYS_RAWIO will be able to
68263+ make use of a special execution mode on 32bit x86 processors called
68264+ Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
68265+ video cards and will still work with this option enabled. The purpose
68266+ of the option is to prevent exploitation of emulation errors in
68267+ virtualization of vm86 mode like the one discovered in VMWare in 2009.
68268+ Nearly all users should be able to enable this option.
68269+
68270+config GRKERNSEC_IO
68271+ bool "Disable privileged I/O"
68272+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
68273+ depends on X86
68274+ select RTC_CLASS
68275+ select RTC_INTF_DEV
68276+ select RTC_DRV_CMOS
68277+
68278+ help
68279+ If you say Y here, all ioperm and iopl calls will return an error.
68280+ Ioperm and iopl can be used to modify the running kernel.
68281+ Unfortunately, some programs need this access to operate properly,
68282+ the most notable of which are XFree86 and hwclock. hwclock can be
68283+ remedied by having RTC support in the kernel, so real-time
68284+ clock support is enabled if this option is enabled, to ensure
68285+ that hwclock operates correctly. If hwclock still does not work,
68286+ either update udev or symlink /dev/rtc to /dev/rtc0.
68287+
68288+ If you're using XFree86 or a version of Xorg from 2012 or earlier,
68289+ you may not be able to boot into a graphical environment with this
68290+ option enabled. In this case, you should use the RBAC system instead.
68291+
68292+config GRKERNSEC_BPF_HARDEN
68293+ bool "Harden BPF interpreter"
68294+ default y if GRKERNSEC_CONFIG_AUTO
68295+ help
68296+ Unlike previous versions of grsecurity that hardened both the BPF
68297+ interpreted code against corruption at rest as well as the JIT code
68298+ against JIT-spray attacks and attacker-controlled immediate values
68299+ for ROP, this feature will enforce disabling of the new eBPF JIT engine
68300+ and will ensure the interpreted code is read-only at rest. This feature
68301+ may be removed at a later time when eBPF stabilizes to entirely revert
68302+ back to the more secure pre-3.16 BPF interpreter/JIT.
68303+
68304+ If you're using KERNEXEC, it's recommended that you enable this option
68305+ to supplement the hardening of the kernel.
68306+
68307+config GRKERNSEC_PERF_HARDEN
68308+ bool "Disable unprivileged PERF_EVENTS usage by default"
68309+ default y if GRKERNSEC_CONFIG_AUTO
68310+ depends on PERF_EVENTS
68311+ help
68312+ If you say Y here, the range of acceptable values for the
68313+ /proc/sys/kernel/perf_event_paranoid sysctl will be expanded to allow and
68314+ default to a new value: 3. When the sysctl is set to this value, no
68315+ unprivileged use of the PERF_EVENTS syscall interface will be permitted.
68316+
68317+ Though PERF_EVENTS can be used legitimately for performance monitoring
68318+ and low-level application profiling, it is forced on regardless of
68319+ configuration, has been at fault for several vulnerabilities, and
68320+ creates new opportunities for side channels and other information leaks.
68321+
68322+ This feature puts PERF_EVENTS into a secure default state and permits
68323+ the administrator to change out of it temporarily if unprivileged
68324+ application profiling is needed.
68325+
68326+config GRKERNSEC_RAND_THREADSTACK
68327+ bool "Insert random gaps between thread stacks"
68328+ default y if GRKERNSEC_CONFIG_AUTO
68329+ depends on PAX_RANDMMAP && !PPC
68330+ help
68331+ If you say Y here, a random-sized gap will be enforced between allocated
68332+ thread stacks. Glibc's NPTL and other threading libraries that
68333+ pass MAP_STACK to the kernel for thread stack allocation are supported.
68334+ The implementation currently provides 8 bits of entropy for the gap.
68335+
68336+ Many distributions do not compile threaded remote services with the
68337+ -fstack-check argument to GCC, causing the variable-sized stack-based
68338+ allocator, alloca(), to not probe the stack on allocation. This
68339+ permits an unbounded alloca() to skip over any guard page and potentially
68340+ modify another thread's stack reliably. An enforced random gap
68341+ reduces the reliability of such an attack and increases the chance
68342+ that such a read/write to another thread's stack instead lands in
68343+ an unmapped area, causing a crash and triggering grsecurity's
68344+ anti-bruteforcing logic.
68345+
68346+config GRKERNSEC_PROC_MEMMAP
68347+ bool "Harden ASLR against information leaks and entropy reduction"
68348+ default y if (GRKERNSEC_CONFIG_AUTO || PAX_NOEXEC || PAX_ASLR)
68349+ depends on PAX_NOEXEC || PAX_ASLR
68350+ help
68351+ If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
68352+ give no information about the addresses of its mappings if
68353+ PaX features that rely on random addresses are enabled on the task.
68354+ In addition to sanitizing this information and disabling other
68355+ dangerous sources of information, this option causes reads of sensitive
68356+ /proc/<pid> entries where the file descriptor was opened in a different
68357+ task than the one performing the read. Such attempts are logged.
68358+ This option also limits argv/env strings for suid/sgid binaries
68359+ to 512KB to prevent a complete exhaustion of the stack entropy provided
68360+ by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
68361+ binaries to prevent alternative mmap layouts from being abused.
68362+
68363+ If you use PaX it is essential that you say Y here as it closes up
68364+ several holes that make full ASLR useless locally.
68365+
68366+
68367+config GRKERNSEC_KSTACKOVERFLOW
68368+ bool "Prevent kernel stack overflows"
68369+ default y if GRKERNSEC_CONFIG_AUTO
68370+ depends on !IA64 && 64BIT
68371+ help
68372+ If you say Y here, the kernel's process stacks will be allocated
68373+ with vmalloc instead of the kernel's default allocator. This
68374+ introduces guard pages that in combination with the alloca checking
68375+ of the STACKLEAK feature prevents all forms of kernel process stack
68376+ overflow abuse. Note that this is different from kernel stack
68377+ buffer overflows.
68378+
68379+config GRKERNSEC_BRUTE
68380+ bool "Deter exploit bruteforcing"
68381+ default y if GRKERNSEC_CONFIG_AUTO
68382+ help
68383+ If you say Y here, attempts to bruteforce exploits against forking
68384+ daemons such as apache or sshd, as well as against suid/sgid binaries
68385+ will be deterred. When a child of a forking daemon is killed by PaX
68386+ or crashes due to an illegal instruction or other suspicious signal,
68387+ the parent process will be delayed 30 seconds upon every subsequent
68388+ fork until the administrator is able to assess the situation and
68389+ restart the daemon.
68390+ In the suid/sgid case, the attempt is logged, the user has all their
68391+ existing instances of the suid/sgid binary terminated and will
68392+ be unable to execute any suid/sgid binaries for 15 minutes.
68393+
68394+ It is recommended that you also enable signal logging in the auditing
68395+ section so that logs are generated when a process triggers a suspicious
68396+ signal.
68397+ If the sysctl option is enabled, a sysctl option with name
68398+ "deter_bruteforce" is created.
68399+
68400+config GRKERNSEC_MODHARDEN
68401+ bool "Harden module auto-loading"
68402+ default y if GRKERNSEC_CONFIG_AUTO
68403+ depends on MODULES
68404+ help
68405+ If you say Y here, module auto-loading in response to use of some
68406+ feature implemented by an unloaded module will be restricted to
68407+ root users. Enabling this option helps defend against attacks
68408+ by unprivileged users who abuse the auto-loading behavior to
68409+ cause a vulnerable module to load that is then exploited.
68410+
68411+ If this option prevents a legitimate use of auto-loading for a
68412+ non-root user, the administrator can execute modprobe manually
68413+ with the exact name of the module mentioned in the alert log.
68414+ Alternatively, the administrator can add the module to the list
68415+ of modules loaded at boot by modifying init scripts.
68416+
68417+ Modification of init scripts will most likely be needed on
68418+ Ubuntu servers with encrypted home directory support enabled,
68419+ as the first non-root user logging in will cause the ecb(aes),
68420+ ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
68421+
68422+config GRKERNSEC_HIDESYM
68423+ bool "Hide kernel symbols"
68424+ default y if GRKERNSEC_CONFIG_AUTO
68425+ select PAX_USERCOPY_SLABS
68426+ help
68427+ If you say Y here, getting information on loaded modules, and
68428+ displaying all kernel symbols through a syscall will be restricted
68429+ to users with CAP_SYS_MODULE. For software compatibility reasons,
68430+ /proc/kallsyms will be restricted to the root user. The RBAC
68431+ system can hide that entry even from root.
68432+
68433+ This option also prevents leaking of kernel addresses through
68434+ several /proc entries.
68435+
68436+ Note that this option is only effective provided the following
68437+ conditions are met:
68438+ 1) The kernel using grsecurity is not precompiled by some distribution
68439+ 2) You have also enabled GRKERNSEC_DMESG
68440+ 3) You are using the RBAC system and hiding other files such as your
68441+ kernel image and System.map. Alternatively, enabling this option
68442+ causes the permissions on /boot, /lib/modules, and the kernel
68443+ source directory to change at compile time to prevent
68444+ reading by non-root users.
68445+ If the above conditions are met, this option will aid in providing a
68446+ useful protection against local kernel exploitation of overflows
68447+ and arbitrary read/write vulnerabilities.
68448+
68449+ It is highly recommended that you enable GRKERNSEC_PERF_HARDEN
68450+ in addition to this feature.
68451+
68452+config GRKERNSEC_RANDSTRUCT
68453+ bool "Randomize layout of sensitive kernel structures"
68454+ default y if GRKERNSEC_CONFIG_AUTO
68455+ select GRKERNSEC_HIDESYM
68456+ select MODVERSIONS if MODULES
68457+ help
68458+ If you say Y here, the layouts of a number of sensitive kernel
68459+ structures (task, fs, cred, etc) and all structures composed entirely
68460+ of function pointers (aka "ops" structs) will be randomized at compile-time.
68461+ This can introduce the requirement of an additional infoleak
68462+ vulnerability for exploits targeting these structure types.
68463+
68464+ Enabling this feature will introduce some performance impact, slightly
68465+ increase memory usage, and prevent the use of forensic tools like
68466+ Volatility against the system (unless the kernel source tree isn't
68467+ cleaned after kernel installation).
68468+
68469+ The seed used for compilation is located at tools/gcc/randomize_layout_seed.h.
68470+ It remains after a make clean to allow for external modules to be compiled
68471+ with the existing seed and will be removed by a make mrproper or
68472+ make distclean.
68473+
68474+ Note that the implementation requires gcc 4.6.4. or newer. You may need
68475+ to install the supporting headers explicitly in addition to the normal
68476+ gcc package.
68477+
68478+config GRKERNSEC_RANDSTRUCT_PERFORMANCE
68479+ bool "Use cacheline-aware structure randomization"
68480+ depends on GRKERNSEC_RANDSTRUCT
68481+ default y if GRKERNSEC_CONFIG_PRIORITY_PERF
68482+ help
68483+ If you say Y here, the RANDSTRUCT randomization will make a best effort
68484+ at restricting randomization to cacheline-sized groups of elements. It
68485+ will further not randomize bitfields in structures. This reduces the
68486+ performance hit of RANDSTRUCT at the cost of weakened randomization.
68487+
68488+config GRKERNSEC_KERN_LOCKOUT
68489+ bool "Active kernel exploit response"
68490+ default y if GRKERNSEC_CONFIG_AUTO
68491+ depends on X86 || ARM || PPC || SPARC
68492+ help
68493+ If you say Y here, when a PaX alert is triggered due to suspicious
68494+ activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
68495+ or an OOPS occurs due to bad memory accesses, instead of just
68496+ terminating the offending process (and potentially allowing
68497+ a subsequent exploit from the same user), we will take one of two
68498+ actions:
68499+ If the user was root, we will panic the system
68500+ If the user was non-root, we will log the attempt, terminate
68501+ all processes owned by the user, then prevent them from creating
68502+ any new processes until the system is restarted
68503+ This deters repeated kernel exploitation/bruteforcing attempts
68504+ and is useful for later forensics.
68505+
68506+config GRKERNSEC_OLD_ARM_USERLAND
68507+ bool "Old ARM userland compatibility"
68508+ depends on ARM && (CPU_V6 || CPU_V6K || CPU_V7)
68509+ help
68510+ If you say Y here, stubs of executable code to perform such operations
68511+ as "compare-exchange" will be placed at fixed locations in the ARM vector
68512+ table. This is unfortunately needed for old ARM userland meant to run
68513+ across a wide range of processors. Without this option enabled,
68514+ the get_tls and data memory barrier stubs will be emulated by the kernel,
68515+ which is enough for Linaro userlands or other userlands designed for v6
68516+ and newer ARM CPUs. It's recommended that you try without this option enabled
68517+ first, and only enable it if your userland does not boot (it will likely fail
68518+ at init time).
68519+
68520+endmenu
68521+menu "Role Based Access Control Options"
68522+depends on GRKERNSEC
68523+
68524+config GRKERNSEC_RBAC_DEBUG
68525+ bool
68526+
68527+config GRKERNSEC_NO_RBAC
68528+ bool "Disable RBAC system"
68529+ help
68530+ If you say Y here, the /dev/grsec device will be removed from the kernel,
68531+ preventing the RBAC system from being enabled. You should only say Y
68532+ here if you have no intention of using the RBAC system, so as to prevent
68533+ an attacker with root access from misusing the RBAC system to hide files
68534+ and processes when loadable module support and /dev/[k]mem have been
68535+ locked down.
68536+
68537+config GRKERNSEC_ACL_HIDEKERN
68538+ bool "Hide kernel processes"
68539+ help
68540+ If you say Y here, all kernel threads will be hidden to all
68541+ processes but those whose subject has the "view hidden processes"
68542+ flag.
68543+
68544+config GRKERNSEC_ACL_MAXTRIES
68545+ int "Maximum tries before password lockout"
68546+ default 3
68547+ help
68548+ This option enforces the maximum number of times a user can attempt
68549+ to authorize themselves with the grsecurity RBAC system before being
68550+ denied the ability to attempt authorization again for a specified time.
68551+ The lower the number, the harder it will be to brute-force a password.
68552+
68553+config GRKERNSEC_ACL_TIMEOUT
68554+ int "Time to wait after max password tries, in seconds"
68555+ default 30
68556+ help
68557+ This option specifies the time the user must wait after attempting to
68558+ authorize to the RBAC system with the maximum number of invalid
68559+ passwords. The higher the number, the harder it will be to brute-force
68560+ a password.
68561+
68562+endmenu
68563+menu "Filesystem Protections"
68564+depends on GRKERNSEC
68565+
68566+config GRKERNSEC_PROC
68567+ bool "Proc restrictions"
68568+ default y if GRKERNSEC_CONFIG_AUTO
68569+ help
68570+ If you say Y here, the permissions of the /proc filesystem
68571+ will be altered to enhance system security and privacy. You MUST
68572+ choose either a user only restriction or a user and group restriction.
68573+ Depending upon the option you choose, you can either restrict users to
68574+ see only the processes they themselves run, or choose a group that can
68575+ view all processes and files normally restricted to root if you choose
68576+ the "restrict to user only" option. NOTE: If you're running identd or
68577+ ntpd as a non-root user, you will have to run it as the group you
68578+ specify here.
68579+
68580+config GRKERNSEC_PROC_USER
68581+ bool "Restrict /proc to user only"
68582+ depends on GRKERNSEC_PROC
68583+ help
68584+ If you say Y here, non-root users will only be able to view their own
68585+ processes, and restricts them from viewing network-related information,
68586+ and viewing kernel symbol and module information.
68587+
68588+config GRKERNSEC_PROC_USERGROUP
68589+ bool "Allow special group"
68590+ default y if GRKERNSEC_CONFIG_AUTO
68591+ depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
68592+ help
68593+ If you say Y here, you will be able to select a group that will be
68594+ able to view all processes and network-related information. If you've
68595+ enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
68596+ remain hidden. This option is useful if you want to run identd as
68597+ a non-root user. The group you select may also be chosen at boot time
68598+ via "grsec_proc_gid=" on the kernel commandline.
68599+
68600+config GRKERNSEC_PROC_GID
68601+ int "GID for special group"
68602+ depends on GRKERNSEC_PROC_USERGROUP
68603+ default 1001
68604+
68605+config GRKERNSEC_PROC_ADD
68606+ bool "Additional restrictions"
68607+ default y if GRKERNSEC_CONFIG_AUTO
68608+ depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
68609+ help
68610+ If you say Y here, additional restrictions will be placed on
68611+ /proc that keep normal users from viewing device information and
68612+ slabinfo information that could be useful for exploits.
68613+
68614+config GRKERNSEC_LINK
68615+ bool "Linking restrictions"
68616+ default y if GRKERNSEC_CONFIG_AUTO
68617+ help
68618+ If you say Y here, /tmp race exploits will be prevented, since users
68619+ will no longer be able to follow symlinks owned by other users in
68620+ world-writable +t directories (e.g. /tmp), unless the owner of the
68621+ symlink is the owner of the directory. users will also not be
68622+ able to hardlink to files they do not own. If the sysctl option is
68623+ enabled, a sysctl option with name "linking_restrictions" is created.
68624+
68625+config GRKERNSEC_SYMLINKOWN
68626+ bool "Kernel-enforced SymlinksIfOwnerMatch"
68627+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
68628+ help
68629+ Apache's SymlinksIfOwnerMatch option has an inherent race condition
68630+ that prevents it from being used as a security feature. As Apache
68631+ verifies the symlink by performing a stat() against the target of
68632+ the symlink before it is followed, an attacker can setup a symlink
68633+ to point to a same-owned file, then replace the symlink with one
68634+ that targets another user's file just after Apache "validates" the
68635+ symlink -- a classic TOCTOU race. If you say Y here, a complete,
68636+ race-free replacement for Apache's "SymlinksIfOwnerMatch" option
68637+ will be in place for the group you specify. If the sysctl option
68638+ is enabled, a sysctl option with name "enforce_symlinksifowner" is
68639+ created.
68640+
68641+config GRKERNSEC_SYMLINKOWN_GID
68642+ int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
68643+ depends on GRKERNSEC_SYMLINKOWN
68644+ default 1006
68645+ help
68646+ Setting this GID determines what group kernel-enforced
68647+ SymlinksIfOwnerMatch will be enabled for. If the sysctl option
68648+ is enabled, a sysctl option with name "symlinkown_gid" is created.
68649+
68650+config GRKERNSEC_FIFO
68651+ bool "FIFO restrictions"
68652+ default y if GRKERNSEC_CONFIG_AUTO
68653+ help
68654+ If you say Y here, users will not be able to write to FIFOs they don't
68655+ own in world-writable +t directories (e.g. /tmp), unless the owner of
68656+ the FIFO is the same owner of the directory it's held in. If the sysctl
68657+ option is enabled, a sysctl option with name "fifo_restrictions" is
68658+ created.
68659+
68660+config GRKERNSEC_SYSFS_RESTRICT
68661+ bool "Sysfs/debugfs restriction"
68662+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
68663+ depends on SYSFS
68664+ help
68665+ If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
68666+ any filesystem normally mounted under it (e.g. debugfs) will be
68667+ mostly accessible only by root. These filesystems generally provide access
68668+ to hardware and debug information that isn't appropriate for unprivileged
68669+ users of the system. Sysfs and debugfs have also become a large source
68670+ of new vulnerabilities, ranging from infoleaks to local compromise.
68671+ There has been very little oversight with an eye toward security involved
68672+ in adding new exporters of information to these filesystems, so their
68673+ use is discouraged.
68674+ For reasons of compatibility, a few directories have been whitelisted
68675+ for access by non-root users:
68676+ /sys/fs/selinux
68677+ /sys/fs/fuse
68678+ /sys/devices/system/cpu
68679+
68680+config GRKERNSEC_ROFS
68681+ bool "Runtime read-only mount protection"
68682+ depends on SYSCTL
68683+ help
68684+ If you say Y here, a sysctl option with name "romount_protect" will
68685+ be created. By setting this option to 1 at runtime, filesystems
68686+ will be protected in the following ways:
68687+ * No new writable mounts will be allowed
68688+ * Existing read-only mounts won't be able to be remounted read/write
68689+ * Write operations will be denied on all block devices
68690+ This option acts independently of grsec_lock: once it is set to 1,
68691+ it cannot be turned off. Therefore, please be mindful of the resulting
68692+ behavior if this option is enabled in an init script on a read-only
68693+ filesystem.
68694+ Also be aware that as with other root-focused features, GRKERNSEC_KMEM
68695+ and GRKERNSEC_IO should be enabled and module loading disabled via
68696+ config or at runtime.
68697+ This feature is mainly intended for secure embedded systems.
68698+
68699+
68700+config GRKERNSEC_DEVICE_SIDECHANNEL
68701+ bool "Eliminate stat/notify-based device sidechannels"
68702+ default y if GRKERNSEC_CONFIG_AUTO
68703+ help
68704+ If you say Y here, timing analyses on block or character
68705+ devices like /dev/ptmx using stat or inotify/dnotify/fanotify
68706+ will be thwarted for unprivileged users. If a process without
68707+ CAP_MKNOD stats such a device, the last access and last modify times
68708+ will match the device's create time. No access or modify events
68709+ will be triggered through inotify/dnotify/fanotify for such devices.
68710+ This feature will prevent attacks that may at a minimum
68711+ allow an attacker to determine the administrator's password length.
68712+
68713+config GRKERNSEC_CHROOT
68714+ bool "Chroot jail restrictions"
68715+ default y if GRKERNSEC_CONFIG_AUTO
68716+ help
68717+ If you say Y here, you will be able to choose several options that will
68718+ make breaking out of a chrooted jail much more difficult. If you
68719+ encounter no software incompatibilities with the following options, it
68720+ is recommended that you enable each one.
68721+
68722+ Note that the chroot restrictions are not intended to apply to "chroots"
68723+ to directories that are simple bind mounts of the global root filesystem.
68724+ For several other reasons, a user shouldn't expect any significant
68725+ security by performing such a chroot.
68726+
68727+config GRKERNSEC_CHROOT_MOUNT
68728+ bool "Deny mounts"
68729+ default y if GRKERNSEC_CONFIG_AUTO
68730+ depends on GRKERNSEC_CHROOT
68731+ help
68732+ If you say Y here, processes inside a chroot will not be able to
68733+ mount or remount filesystems. If the sysctl option is enabled, a
68734+ sysctl option with name "chroot_deny_mount" is created.
68735+
68736+config GRKERNSEC_CHROOT_DOUBLE
68737+ bool "Deny double-chroots"
68738+ default y if GRKERNSEC_CONFIG_AUTO
68739+ depends on GRKERNSEC_CHROOT
68740+ help
68741+ If you say Y here, processes inside a chroot will not be able to chroot
68742+ again outside the chroot. This is a widely used method of breaking
68743+ out of a chroot jail and should not be allowed. If the sysctl
68744+ option is enabled, a sysctl option with name
68745+ "chroot_deny_chroot" is created.
68746+
68747+config GRKERNSEC_CHROOT_PIVOT
68748+ bool "Deny pivot_root in chroot"
68749+ default y if GRKERNSEC_CONFIG_AUTO
68750+ depends on GRKERNSEC_CHROOT
68751+ help
68752+ If you say Y here, processes inside a chroot will not be able to use
68753+ a function called pivot_root() that was introduced in Linux 2.3.41. It
68754+ works similar to chroot in that it changes the root filesystem. This
68755+ function could be misused in a chrooted process to attempt to break out
68756+ of the chroot, and therefore should not be allowed. If the sysctl
68757+ option is enabled, a sysctl option with name "chroot_deny_pivot" is
68758+ created.
68759+
68760+config GRKERNSEC_CHROOT_CHDIR
68761+ bool "Enforce chdir(\"/\") on all chroots"
68762+ default y if GRKERNSEC_CONFIG_AUTO
68763+ depends on GRKERNSEC_CHROOT
68764+ help
68765+ If you say Y here, the current working directory of all newly-chrooted
68766+ applications will be set to the the root directory of the chroot.
68767+ The man page on chroot(2) states:
68768+ Note that this call does not change the current working
68769+ directory, so that `.' can be outside the tree rooted at
68770+ `/'. In particular, the super-user can escape from a
68771+ `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
68772+
68773+ It is recommended that you say Y here, since it's not known to break
68774+ any software. If the sysctl option is enabled, a sysctl option with
68775+ name "chroot_enforce_chdir" is created.
68776+
68777+config GRKERNSEC_CHROOT_CHMOD
68778+ bool "Deny (f)chmod +s"
68779+ default y if GRKERNSEC_CONFIG_AUTO
68780+ depends on GRKERNSEC_CHROOT
68781+ help
68782+ If you say Y here, processes inside a chroot will not be able to chmod
68783+ or fchmod files to make them have suid or sgid bits. This protects
68784+ against another published method of breaking a chroot. If the sysctl
68785+ option is enabled, a sysctl option with name "chroot_deny_chmod" is
68786+ created.
68787+
68788+config GRKERNSEC_CHROOT_FCHDIR
68789+ bool "Deny fchdir and fhandle out of chroot"
68790+ default y if GRKERNSEC_CONFIG_AUTO
68791+ depends on GRKERNSEC_CHROOT
68792+ help
68793+ If you say Y here, a well-known method of breaking chroots by fchdir'ing
68794+ to a file descriptor of the chrooting process that points to a directory
68795+ outside the filesystem will be stopped. Additionally, this option prevents
68796+ use of the recently-created syscall for opening files by a guessable "file
68797+ handle" inside a chroot. If the sysctl option is enabled, a sysctl option
68798+ with name "chroot_deny_fchdir" is created.
68799+
68800+config GRKERNSEC_CHROOT_MKNOD
68801+ bool "Deny mknod"
68802+ default y if GRKERNSEC_CONFIG_AUTO
68803+ depends on GRKERNSEC_CHROOT
68804+ help
68805+ If you say Y here, processes inside a chroot will not be allowed to
68806+ mknod. The problem with using mknod inside a chroot is that it
68807+ would allow an attacker to create a device entry that is the same
68808+ as one on the physical root of your system, which could range from
68809+ anything from the console device to a device for your harddrive (which
68810+ they could then use to wipe the drive or steal data). It is recommended
68811+ that you say Y here, unless you run into software incompatibilities.
68812+ If the sysctl option is enabled, a sysctl option with name
68813+ "chroot_deny_mknod" is created.
68814+
68815+config GRKERNSEC_CHROOT_SHMAT
68816+ bool "Deny shmat() out of chroot"
68817+ default y if GRKERNSEC_CONFIG_AUTO
68818+ depends on GRKERNSEC_CHROOT
68819+ help
68820+ If you say Y here, processes inside a chroot will not be able to attach
68821+ to shared memory segments that were created outside of the chroot jail.
68822+ It is recommended that you say Y here. If the sysctl option is enabled,
68823+ a sysctl option with name "chroot_deny_shmat" is created.
68824+
68825+config GRKERNSEC_CHROOT_UNIX
68826+ bool "Deny access to abstract AF_UNIX sockets out of chroot"
68827+ default y if GRKERNSEC_CONFIG_AUTO
68828+ depends on GRKERNSEC_CHROOT
68829+ help
68830+ If you say Y here, processes inside a chroot will not be able to
68831+ connect to abstract (meaning not belonging to a filesystem) Unix
68832+ domain sockets that were bound outside of a chroot. It is recommended
68833+ that you say Y here. If the sysctl option is enabled, a sysctl option
68834+ with name "chroot_deny_unix" is created.
68835+
68836+config GRKERNSEC_CHROOT_FINDTASK
68837+ bool "Protect outside processes"
68838+ default y if GRKERNSEC_CONFIG_AUTO
68839+ depends on GRKERNSEC_CHROOT
68840+ help
68841+ If you say Y here, processes inside a chroot will not be able to
68842+ kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
68843+ getsid, or view any process outside of the chroot. If the sysctl
68844+ option is enabled, a sysctl option with name "chroot_findtask" is
68845+ created.
68846+
68847+config GRKERNSEC_CHROOT_NICE
68848+ bool "Restrict priority changes"
68849+ default y if GRKERNSEC_CONFIG_AUTO
68850+ depends on GRKERNSEC_CHROOT
68851+ help
68852+ If you say Y here, processes inside a chroot will not be able to raise
68853+ the priority of processes in the chroot, or alter the priority of
68854+ processes outside the chroot. This provides more security than simply
68855+ removing CAP_SYS_NICE from the process' capability set. If the
68856+ sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
68857+ is created.
68858+
68859+config GRKERNSEC_CHROOT_SYSCTL
68860+ bool "Deny sysctl writes"
68861+ default y if GRKERNSEC_CONFIG_AUTO
68862+ depends on GRKERNSEC_CHROOT
68863+ help
68864+ If you say Y here, an attacker in a chroot will not be able to
68865+ write to sysctl entries, either by sysctl(2) or through a /proc
68866+ interface. It is strongly recommended that you say Y here. If the
68867+ sysctl option is enabled, a sysctl option with name
68868+ "chroot_deny_sysctl" is created.
68869+
68870+config GRKERNSEC_CHROOT_CAPS
68871+ bool "Capability restrictions"
68872+ default y if GRKERNSEC_CONFIG_AUTO
68873+ depends on GRKERNSEC_CHROOT
68874+ help
68875+ If you say Y here, the capabilities on all processes within a
68876+ chroot jail will be lowered to stop module insertion, raw i/o,
68877+ system and net admin tasks, rebooting the system, modifying immutable
68878+ files, modifying IPC owned by another, and changing the system time.
68879+ This is left an option because it can break some apps. Disable this
68880+ if your chrooted apps are having problems performing those kinds of
68881+ tasks. If the sysctl option is enabled, a sysctl option with
68882+ name "chroot_caps" is created.
68883+
68884+config GRKERNSEC_CHROOT_INITRD
68885+ bool "Exempt initrd tasks from restrictions"
68886+ default y if GRKERNSEC_CONFIG_AUTO
68887+ depends on GRKERNSEC_CHROOT && BLK_DEV_INITRD
68888+ help
68889+ If you say Y here, tasks started prior to init will be exempted from
68890+ grsecurity's chroot restrictions. This option is mainly meant to
68891+ resolve Plymouth's performing privileged operations unnecessarily
68892+ in a chroot.
68893+
68894+endmenu
68895+menu "Kernel Auditing"
68896+depends on GRKERNSEC
68897+
68898+config GRKERNSEC_AUDIT_GROUP
68899+ bool "Single group for auditing"
68900+ help
68901+ If you say Y here, the exec and chdir logging features will only operate
68902+ on a group you specify. This option is recommended if you only want to
68903+ watch certain users instead of having a large amount of logs from the
68904+ entire system. If the sysctl option is enabled, a sysctl option with
68905+ name "audit_group" is created.
68906+
68907+config GRKERNSEC_AUDIT_GID
68908+ int "GID for auditing"
68909+ depends on GRKERNSEC_AUDIT_GROUP
68910+ default 1007
68911+
68912+config GRKERNSEC_EXECLOG
68913+ bool "Exec logging"
68914+ help
68915+ If you say Y here, all execve() calls will be logged (since the
68916+ other exec*() calls are frontends to execve(), all execution
68917+ will be logged). Useful for shell-servers that like to keep track
68918+ of their users. If the sysctl option is enabled, a sysctl option with
68919+ name "exec_logging" is created.
68920+ WARNING: This option when enabled will produce a LOT of logs, especially
68921+ on an active system.
68922+
68923+config GRKERNSEC_RESLOG
68924+ bool "Resource logging"
68925+ default y if GRKERNSEC_CONFIG_AUTO
68926+ help
68927+ If you say Y here, all attempts to overstep resource limits will
68928+ be logged with the resource name, the requested size, and the current
68929+ limit. It is highly recommended that you say Y here. If the sysctl
68930+ option is enabled, a sysctl option with name "resource_logging" is
68931+ created. If the RBAC system is enabled, the sysctl value is ignored.
68932+
68933+config GRKERNSEC_CHROOT_EXECLOG
68934+ bool "Log execs within chroot"
68935+ help
68936+ If you say Y here, all executions inside a chroot jail will be logged
68937+ to syslog. This can cause a large amount of logs if certain
68938+ applications (eg. djb's daemontools) are installed on the system, and
68939+ is therefore left as an option. If the sysctl option is enabled, a
68940+ sysctl option with name "chroot_execlog" is created.
68941+
68942+config GRKERNSEC_AUDIT_PTRACE
68943+ bool "Ptrace logging"
68944+ help
68945+ If you say Y here, all attempts to attach to a process via ptrace
68946+ will be logged. If the sysctl option is enabled, a sysctl option
68947+ with name "audit_ptrace" is created.
68948+
68949+config GRKERNSEC_AUDIT_CHDIR
68950+ bool "Chdir logging"
68951+ help
68952+ If you say Y here, all chdir() calls will be logged. If the sysctl
68953+ option is enabled, a sysctl option with name "audit_chdir" is created.
68954+
68955+config GRKERNSEC_AUDIT_MOUNT
68956+ bool "(Un)Mount logging"
68957+ help
68958+ If you say Y here, all mounts and unmounts will be logged. If the
68959+ sysctl option is enabled, a sysctl option with name "audit_mount" is
68960+ created.
68961+
68962+config GRKERNSEC_SIGNAL
68963+ bool "Signal logging"
68964+ default y if GRKERNSEC_CONFIG_AUTO
68965+ help
68966+ If you say Y here, certain important signals will be logged, such as
68967+ SIGSEGV, which will as a result inform you of when a error in a program
68968+ occurred, which in some cases could mean a possible exploit attempt.
68969+ If the sysctl option is enabled, a sysctl option with name
68970+ "signal_logging" is created.
68971+
68972+config GRKERNSEC_FORKFAIL
68973+ bool "Fork failure logging"
68974+ help
68975+ If you say Y here, all failed fork() attempts will be logged.
68976+ This could suggest a fork bomb, or someone attempting to overstep
68977+ their process limit. If the sysctl option is enabled, a sysctl option
68978+ with name "forkfail_logging" is created.
68979+
68980+config GRKERNSEC_TIME
68981+ bool "Time change logging"
68982+ default y if GRKERNSEC_CONFIG_AUTO
68983+ help
68984+ If you say Y here, any changes of the system clock will be logged.
68985+ If the sysctl option is enabled, a sysctl option with name
68986+ "timechange_logging" is created.
68987+
68988+config GRKERNSEC_PROC_IPADDR
68989+ bool "/proc/<pid>/ipaddr support"
68990+ default y if GRKERNSEC_CONFIG_AUTO
68991+ help
68992+ If you say Y here, a new entry will be added to each /proc/<pid>
68993+ directory that contains the IP address of the person using the task.
68994+ The IP is carried across local TCP and AF_UNIX stream sockets.
68995+ This information can be useful for IDS/IPSes to perform remote response
68996+ to a local attack. The entry is readable by only the owner of the
68997+ process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
68998+ the RBAC system), and thus does not create privacy concerns.
68999+
69000+config GRKERNSEC_RWXMAP_LOG
69001+ bool 'Denied RWX mmap/mprotect logging'
69002+ default y if GRKERNSEC_CONFIG_AUTO
69003+ depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
69004+ help
69005+ If you say Y here, calls to mmap() and mprotect() with explicit
69006+ usage of PROT_WRITE and PROT_EXEC together will be logged when
69007+ denied by the PAX_MPROTECT feature. This feature will also
69008+ log other problematic scenarios that can occur when PAX_MPROTECT
69009+ is enabled on a binary, like textrels and PT_GNU_STACK. If the
69010+ sysctl option is enabled, a sysctl option with name "rwxmap_logging"
69011+ is created.
69012+
69013+endmenu
69014+
69015+menu "Executable Protections"
69016+depends on GRKERNSEC
69017+
69018+config GRKERNSEC_DMESG
69019+ bool "Dmesg(8) restriction"
69020+ default y if GRKERNSEC_CONFIG_AUTO
69021+ help
69022+ If you say Y here, non-root users will not be able to use dmesg(8)
69023+ to view the contents of the kernel's circular log buffer.
69024+ The kernel's log buffer often contains kernel addresses and other
69025+ identifying information useful to an attacker in fingerprinting a
69026+ system for a targeted exploit.
69027+ If the sysctl option is enabled, a sysctl option with name "dmesg" is
69028+ created.
69029+
69030+config GRKERNSEC_HARDEN_PTRACE
69031+ bool "Deter ptrace-based process snooping"
69032+ default y if GRKERNSEC_CONFIG_AUTO
69033+ help
69034+ If you say Y here, TTY sniffers and other malicious monitoring
69035+ programs implemented through ptrace will be defeated. If you
69036+ have been using the RBAC system, this option has already been
69037+ enabled for several years for all users, with the ability to make
69038+ fine-grained exceptions.
69039+
69040+ This option only affects the ability of non-root users to ptrace
69041+ processes that are not a descendent of the ptracing process.
69042+ This means that strace ./binary and gdb ./binary will still work,
69043+ but attaching to arbitrary processes will not. If the sysctl
69044+ option is enabled, a sysctl option with name "harden_ptrace" is
69045+ created.
69046+
69047+config GRKERNSEC_PTRACE_READEXEC
69048+ bool "Require read access to ptrace sensitive binaries"
69049+ default y if GRKERNSEC_CONFIG_AUTO
69050+ help
69051+ If you say Y here, unprivileged users will not be able to ptrace unreadable
69052+ binaries. This option is useful in environments that
69053+ remove the read bits (e.g. file mode 4711) from suid binaries to
69054+ prevent infoleaking of their contents. This option adds
69055+ consistency to the use of that file mode, as the binary could normally
69056+ be read out when run without privileges while ptracing.
69057+
69058+ If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
69059+ is created.
69060+
69061+config GRKERNSEC_SETXID
69062+ bool "Enforce consistent multithreaded privileges"
69063+ default y if GRKERNSEC_CONFIG_AUTO
69064+ depends on (X86 || SPARC64 || PPC || ARM || MIPS)
69065+ help
69066+ If you say Y here, a change from a root uid to a non-root uid
69067+ in a multithreaded application will cause the resulting uids,
69068+ gids, supplementary groups, and capabilities in that thread
69069+ to be propagated to the other threads of the process. In most
69070+ cases this is unnecessary, as glibc will emulate this behavior
69071+ on behalf of the application. Other libcs do not act in the
69072+ same way, allowing the other threads of the process to continue
69073+ running with root privileges. If the sysctl option is enabled,
69074+ a sysctl option with name "consistent_setxid" is created.
69075+
69076+config GRKERNSEC_HARDEN_IPC
69077+ bool "Disallow access to overly-permissive IPC objects"
69078+ default y if GRKERNSEC_CONFIG_AUTO
69079+ depends on SYSVIPC
69080+ help
69081+ If you say Y here, access to overly-permissive IPC objects (shared
69082+ memory, message queues, and semaphores) will be denied for processes
69083+ given the following criteria beyond normal permission checks:
69084+ 1) If the IPC object is world-accessible and the euid doesn't match
69085+ that of the creator or current uid for the IPC object
69086+ 2) If the IPC object is group-accessible and the egid doesn't
69087+ match that of the creator or current gid for the IPC object
69088+ It's a common error to grant too much permission to these objects,
69089+ with impact ranging from denial of service and information leaking to
69090+ privilege escalation. This feature was developed in response to
69091+ research by Tim Brown:
69092+ http://labs.portcullis.co.uk/whitepapers/memory-squatting-attacks-on-system-v-shared-memory/
69093+ who found hundreds of such insecure usages. Processes with
69094+ CAP_IPC_OWNER are still permitted to access these IPC objects.
69095+ If the sysctl option is enabled, a sysctl option with name
69096+ "harden_ipc" is created.
69097+
69098+config GRKERNSEC_TPE
69099+ bool "Trusted Path Execution (TPE)"
69100+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
69101+ help
69102+ If you say Y here, you will be able to choose a gid to add to the
69103+ supplementary groups of users you want to mark as "untrusted."
69104+ These users will not be able to execute any files that are not in
69105+ root-owned directories writable only by root. If the sysctl option
69106+ is enabled, a sysctl option with name "tpe" is created.
69107+
69108+config GRKERNSEC_TPE_ALL
69109+ bool "Partially restrict all non-root users"
69110+ depends on GRKERNSEC_TPE
69111+ help
69112+ If you say Y here, all non-root users will be covered under
69113+ a weaker TPE restriction. This is separate from, and in addition to,
69114+ the main TPE options that you have selected elsewhere. Thus, if a
69115+ "trusted" GID is chosen, this restriction applies to even that GID.
69116+ Under this restriction, all non-root users will only be allowed to
69117+ execute files in directories they own that are not group or
69118+ world-writable, or in directories owned by root and writable only by
69119+ root. If the sysctl option is enabled, a sysctl option with name
69120+ "tpe_restrict_all" is created.
69121+
69122+config GRKERNSEC_TPE_INVERT
69123+ bool "Invert GID option"
69124+ depends on GRKERNSEC_TPE
69125+ help
69126+ If you say Y here, the group you specify in the TPE configuration will
69127+ decide what group TPE restrictions will be *disabled* for. This
69128+ option is useful if you want TPE restrictions to be applied to most
69129+ users on the system. If the sysctl option is enabled, a sysctl option
69130+ with name "tpe_invert" is created. Unlike other sysctl options, this
69131+ entry will default to on for backward-compatibility.
69132+
69133+config GRKERNSEC_TPE_GID
69134+ int
69135+ default GRKERNSEC_TPE_UNTRUSTED_GID if (GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT)
69136+ default GRKERNSEC_TPE_TRUSTED_GID if (GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT)
69137+
69138+config GRKERNSEC_TPE_UNTRUSTED_GID
69139+ int "GID for TPE-untrusted users"
69140+ depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
69141+ default 1005
69142+ help
69143+ Setting this GID determines what group TPE restrictions will be
69144+ *enabled* for. If the sysctl option is enabled, a sysctl option
69145+ with name "tpe_gid" is created.
69146+
69147+config GRKERNSEC_TPE_TRUSTED_GID
69148+ int "GID for TPE-trusted users"
69149+ depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
69150+ default 1005
69151+ help
69152+ Setting this GID determines what group TPE restrictions will be
69153+ *disabled* for. If the sysctl option is enabled, a sysctl option
69154+ with name "tpe_gid" is created.
69155+
69156+endmenu
69157+menu "Network Protections"
69158+depends on GRKERNSEC
69159+
69160+config GRKERNSEC_BLACKHOLE
69161+ bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
69162+ default y if GRKERNSEC_CONFIG_AUTO
69163+ depends on NET
69164+ help
69165+ If you say Y here, neither TCP resets nor ICMP
69166+ destination-unreachable packets will be sent in response to packets
69167+ sent to ports for which no associated listening process exists.
69168+ It will also prevent the sending of ICMP protocol unreachable packets
69169+ in response to packets with unknown protocols.
69170+ This feature supports both IPV4 and IPV6 and exempts the
69171+ loopback interface from blackholing. Enabling this feature
69172+ makes a host more resilient to DoS attacks and reduces network
69173+ visibility against scanners.
69174+
69175+ The blackhole feature as-implemented is equivalent to the FreeBSD
69176+ blackhole feature, as it prevents RST responses to all packets, not
69177+ just SYNs. Under most application behavior this causes no
69178+ problems, but applications (like haproxy) may not close certain
69179+ connections in a way that cleanly terminates them on the remote
69180+ end, leaving the remote host in LAST_ACK state. Because of this
69181+ side-effect and to prevent intentional LAST_ACK DoSes, this
69182+ feature also adds automatic mitigation against such attacks.
69183+ The mitigation drastically reduces the amount of time a socket
69184+ can spend in LAST_ACK state. If you're using haproxy and not
69185+ all servers it connects to have this option enabled, consider
69186+ disabling this feature on the haproxy host.
69187+
69188+ If the sysctl option is enabled, two sysctl options with names
69189+ "ip_blackhole" and "lastack_retries" will be created.
69190+ While "ip_blackhole" takes the standard zero/non-zero on/off
69191+ toggle, "lastack_retries" uses the same kinds of values as
69192+ "tcp_retries1" and "tcp_retries2". The default value of 4
69193+ prevents a socket from lasting more than 45 seconds in LAST_ACK
69194+ state.
69195+
69196+config GRKERNSEC_NO_SIMULT_CONNECT
69197+ bool "Disable TCP Simultaneous Connect"
69198+ default y if GRKERNSEC_CONFIG_AUTO
69199+ depends on NET
69200+ help
69201+ If you say Y here, a feature by Willy Tarreau will be enabled that
69202+ removes a weakness in Linux's strict implementation of TCP that
69203+ allows two clients to connect to each other without either entering
69204+ a listening state. The weakness allows an attacker to easily prevent
69205+ a client from connecting to a known server provided the source port
69206+ for the connection is guessed correctly.
69207+
69208+ As the weakness could be used to prevent an antivirus or IPS from
69209+ fetching updates, or prevent an SSL gateway from fetching a CRL,
69210+ it should be eliminated by enabling this option. Though Linux is
69211+ one of few operating systems supporting simultaneous connect, it
69212+ has no legitimate use in practice and is rarely supported by firewalls.
69213+
69214+config GRKERNSEC_SOCKET
69215+ bool "Socket restrictions"
69216+ depends on NET
69217+ help
69218+ If you say Y here, you will be able to choose from several options.
69219+ If you assign a GID on your system and add it to the supplementary
69220+ groups of users you want to restrict socket access to, this patch
69221+ will perform up to three things, based on the option(s) you choose.
69222+
69223+config GRKERNSEC_SOCKET_ALL
69224+ bool "Deny any sockets to group"
69225+ depends on GRKERNSEC_SOCKET
69226+ help
69227+ If you say Y here, you will be able to choose a GID of whose users will
69228+ be unable to connect to other hosts from your machine or run server
69229+ applications from your machine. If the sysctl option is enabled, a
69230+ sysctl option with name "socket_all" is created.
69231+
69232+config GRKERNSEC_SOCKET_ALL_GID
69233+ int "GID to deny all sockets for"
69234+ depends on GRKERNSEC_SOCKET_ALL
69235+ default 1004
69236+ help
69237+ Here you can choose the GID to disable socket access for. Remember to
69238+ add the users you want socket access disabled for to the GID
69239+ specified here. If the sysctl option is enabled, a sysctl option
69240+ with name "socket_all_gid" is created.
69241+
69242+config GRKERNSEC_SOCKET_CLIENT
69243+ bool "Deny client sockets to group"
69244+ depends on GRKERNSEC_SOCKET
69245+ help
69246+ If you say Y here, you will be able to choose a GID of whose users will
69247+ be unable to connect to other hosts from your machine, but will be
69248+ able to run servers. If this option is enabled, all users in the group
69249+ you specify will have to use passive mode when initiating ftp transfers
69250+ from the shell on your machine. If the sysctl option is enabled, a
69251+ sysctl option with name "socket_client" is created.
69252+
69253+config GRKERNSEC_SOCKET_CLIENT_GID
69254+ int "GID to deny client sockets for"
69255+ depends on GRKERNSEC_SOCKET_CLIENT
69256+ default 1003
69257+ help
69258+ Here you can choose the GID to disable client socket access for.
69259+ Remember to add the users you want client socket access disabled for to
69260+ the GID specified here. If the sysctl option is enabled, a sysctl
69261+ option with name "socket_client_gid" is created.
69262+
69263+config GRKERNSEC_SOCKET_SERVER
69264+ bool "Deny server sockets to group"
69265+ depends on GRKERNSEC_SOCKET
69266+ help
69267+ If you say Y here, you will be able to choose a GID of whose users will
69268+ be unable to run server applications from your machine. If the sysctl
69269+ option is enabled, a sysctl option with name "socket_server" is created.
69270+
69271+config GRKERNSEC_SOCKET_SERVER_GID
69272+ int "GID to deny server sockets for"
69273+ depends on GRKERNSEC_SOCKET_SERVER
69274+ default 1002
69275+ help
69276+ Here you can choose the GID to disable server socket access for.
69277+ Remember to add the users you want server socket access disabled for to
69278+ the GID specified here. If the sysctl option is enabled, a sysctl
69279+ option with name "socket_server_gid" is created.
69280+
69281+endmenu
69282+
69283+menu "Physical Protections"
69284+depends on GRKERNSEC
69285+
69286+config GRKERNSEC_DENYUSB
69287+ bool "Deny new USB connections after toggle"
69288+ default y if GRKERNSEC_CONFIG_AUTO
69289+ depends on SYSCTL && USB_SUPPORT
69290+ help
69291+ If you say Y here, a new sysctl option with name "deny_new_usb"
69292+ will be created. Setting its value to 1 will prevent any new
69293+ USB devices from being recognized by the OS. Any attempted USB
69294+ device insertion will be logged. This option is intended to be
69295+ used against custom USB devices designed to exploit vulnerabilities
69296+ in various USB device drivers.
69297+
69298+ For greatest effectiveness, this sysctl should be set after any
69299+ relevant init scripts. This option is safe to enable in distros
69300+ as each user can choose whether or not to toggle the sysctl.
69301+
69302+config GRKERNSEC_DENYUSB_FORCE
69303+ bool "Reject all USB devices not connected at boot"
69304+ select USB
69305+ depends on GRKERNSEC_DENYUSB
69306+ help
69307+ If you say Y here, a variant of GRKERNSEC_DENYUSB will be enabled
69308+ that doesn't involve a sysctl entry. This option should only be
69309+ enabled if you're sure you want to deny all new USB connections
69310+ at runtime and don't want to modify init scripts. This should not
69311+ be enabled by distros. It forces the core USB code to be built
69312+ into the kernel image so that all devices connected at boot time
69313+ can be recognized and new USB device connections can be prevented
69314+ prior to init running.
69315+
69316+endmenu
69317+
69318+menu "Sysctl Support"
69319+depends on GRKERNSEC && SYSCTL
69320+
69321+config GRKERNSEC_SYSCTL
69322+ bool "Sysctl support"
69323+ default y if GRKERNSEC_CONFIG_AUTO
69324+ help
69325+ If you say Y here, you will be able to change the options that
69326+ grsecurity runs with at bootup, without having to recompile your
69327+ kernel. You can echo values to files in /proc/sys/kernel/grsecurity
69328+ to enable (1) or disable (0) various features. All the sysctl entries
69329+ are mutable until the "grsec_lock" entry is set to a non-zero value.
69330+ All features enabled in the kernel configuration are disabled at boot
69331+ if you do not say Y to the "Turn on features by default" option.
69332+ All options should be set at startup, and the grsec_lock entry should
69333+ be set to a non-zero value after all the options are set.
69334+ *THIS IS EXTREMELY IMPORTANT*
69335+
69336+config GRKERNSEC_SYSCTL_DISTRO
69337+ bool "Extra sysctl support for distro makers (READ HELP)"
69338+ depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
69339+ help
69340+ If you say Y here, additional sysctl options will be created
69341+ for features that affect processes running as root. Therefore,
69342+ it is critical when using this option that the grsec_lock entry be
69343+ enabled after boot. Only distros with prebuilt kernel packages
69344+ with this option enabled that can ensure grsec_lock is enabled
69345+ after boot should use this option.
69346+ *Failure to set grsec_lock after boot makes all grsec features
69347+ this option covers useless*
69348+
69349+ Currently this option creates the following sysctl entries:
69350+ "Disable Privileged I/O": "disable_priv_io"
69351+
69352+config GRKERNSEC_SYSCTL_ON
69353+ bool "Turn on features by default"
69354+ default y if GRKERNSEC_CONFIG_AUTO
69355+ depends on GRKERNSEC_SYSCTL
69356+ help
69357+ If you say Y here, instead of having all features enabled in the
69358+ kernel configuration disabled at boot time, the features will be
69359+ enabled at boot time. It is recommended you say Y here unless
69360+ there is some reason you would want all sysctl-tunable features to
69361+ be disabled by default. As mentioned elsewhere, it is important
69362+ to enable the grsec_lock entry once you have finished modifying
69363+ the sysctl entries.
69364+
69365+endmenu
69366+menu "Logging Options"
69367+depends on GRKERNSEC
69368+
69369+config GRKERNSEC_FLOODTIME
69370+ int "Seconds in between log messages (minimum)"
69371+ default 10
69372+ help
69373+ This option allows you to enforce the number of seconds between
69374+ grsecurity log messages. The default should be suitable for most
69375+ people, however, if you choose to change it, choose a value small enough
69376+ to allow informative logs to be produced, but large enough to
69377+ prevent flooding.
69378+
69379+ Setting both this value and GRKERNSEC_FLOODBURST to 0 will disable
69380+ any rate limiting on grsecurity log messages.
69381+
69382+config GRKERNSEC_FLOODBURST
69383+ int "Number of messages in a burst (maximum)"
69384+ default 6
69385+ help
69386+ This option allows you to choose the maximum number of messages allowed
69387+ within the flood time interval you chose in a separate option. The
69388+ default should be suitable for most people, however if you find that
69389+ many of your logs are being interpreted as flooding, you may want to
69390+ raise this value.
69391+
69392+ Setting both this value and GRKERNSEC_FLOODTIME to 0 will disable
69393+ any rate limiting on grsecurity log messages.
69394+
69395+endmenu
69396diff --git a/grsecurity/Makefile b/grsecurity/Makefile
69397new file mode 100644
69398index 0000000..30ababb
69399--- /dev/null
69400+++ b/grsecurity/Makefile
69401@@ -0,0 +1,54 @@
69402+# grsecurity – access control and security hardening for Linux
69403+# All code in this directory and various hooks located throughout the Linux kernel are
69404+# Copyright (C) 2001-2014 Bradley Spengler, Open Source Security, Inc.
69405+# http://www.grsecurity.net spender@grsecurity.net
69406+#
69407+# This program is free software; you can redistribute it and/or
69408+# modify it under the terms of the GNU General Public License version 2
69409+# as published by the Free Software Foundation.
69410+#
69411+# This program is distributed in the hope that it will be useful,
69412+# but WITHOUT ANY WARRANTY; without even the implied warranty of
69413+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
69414+# GNU General Public License for more details.
69415+#
69416+# You should have received a copy of the GNU General Public License
69417+# along with this program; if not, write to the Free Software
69418+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
69419+
69420+KBUILD_CFLAGS += -Werror
69421+
69422+obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
69423+ grsec_mount.o grsec_sig.o grsec_sysctl.o \
69424+ grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o \
69425+ grsec_usb.o grsec_ipc.o grsec_proc.o
69426+
69427+obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
69428+ gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
69429+ gracl_learn.o grsec_log.o gracl_policy.o
69430+ifdef CONFIG_COMPAT
69431+obj-$(CONFIG_GRKERNSEC) += gracl_compat.o
69432+endif
69433+
69434+obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
69435+
69436+ifdef CONFIG_NET
69437+obj-y += grsec_sock.o
69438+obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
69439+endif
69440+
69441+ifndef CONFIG_GRKERNSEC
69442+obj-y += grsec_disabled.o
69443+endif
69444+
69445+ifdef CONFIG_GRKERNSEC_HIDESYM
69446+extra-y := grsec_hidesym.o
69447+$(obj)/grsec_hidesym.o:
69448+ @-chmod -f 500 /boot
69449+ @-chmod -f 500 /lib/modules
69450+ @-chmod -f 500 /lib64/modules
69451+ @-chmod -f 500 /lib32/modules
69452+ @-chmod -f 700 .
69453+ @-chmod -f 700 $(objtree)
69454+ @echo ' grsec: protected kernel image paths'
69455+endif
69456diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
69457new file mode 100644
69458index 0000000..6ae3aa0
69459--- /dev/null
69460+++ b/grsecurity/gracl.c
69461@@ -0,0 +1,2703 @@
69462+#include <linux/kernel.h>
69463+#include <linux/module.h>
69464+#include <linux/sched.h>
69465+#include <linux/mm.h>
69466+#include <linux/file.h>
69467+#include <linux/fs.h>
69468+#include <linux/namei.h>
69469+#include <linux/mount.h>
69470+#include <linux/tty.h>
69471+#include <linux/proc_fs.h>
69472+#include <linux/lglock.h>
69473+#include <linux/slab.h>
69474+#include <linux/vmalloc.h>
69475+#include <linux/types.h>
69476+#include <linux/sysctl.h>
69477+#include <linux/netdevice.h>
69478+#include <linux/ptrace.h>
69479+#include <linux/gracl.h>
69480+#include <linux/gralloc.h>
69481+#include <linux/security.h>
69482+#include <linux/grinternal.h>
69483+#include <linux/pid_namespace.h>
69484+#include <linux/stop_machine.h>
69485+#include <linux/fdtable.h>
69486+#include <linux/percpu.h>
69487+#include <linux/lglock.h>
69488+#include <linux/hugetlb.h>
69489+#include <linux/posix-timers.h>
69490+#include <linux/prefetch.h>
69491+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
69492+#include <linux/magic.h>
69493+#include <linux/pagemap.h>
69494+#include "../fs/btrfs/async-thread.h"
69495+#include "../fs/btrfs/ctree.h"
69496+#include "../fs/btrfs/btrfs_inode.h"
69497+#endif
69498+#include "../fs/mount.h"
69499+
69500+#include <asm/uaccess.h>
69501+#include <asm/errno.h>
69502+#include <asm/mman.h>
69503+
69504+#define FOR_EACH_ROLE_START(role) \
69505+ role = running_polstate.role_list; \
69506+ while (role) {
69507+
69508+#define FOR_EACH_ROLE_END(role) \
69509+ role = role->prev; \
69510+ }
69511+
69512+extern struct path gr_real_root;
69513+
69514+static struct gr_policy_state running_polstate;
69515+struct gr_policy_state *polstate = &running_polstate;
69516+extern struct gr_alloc_state *current_alloc_state;
69517+
69518+extern char *gr_shared_page[4];
69519+DEFINE_RWLOCK(gr_inode_lock);
69520+
69521+static unsigned int gr_status __read_only = GR_STATUS_INIT;
69522+
69523+#ifdef CONFIG_NET
69524+extern struct vfsmount *sock_mnt;
69525+#endif
69526+
69527+extern struct vfsmount *pipe_mnt;
69528+extern struct vfsmount *shm_mnt;
69529+
69530+#ifdef CONFIG_HUGETLBFS
69531+extern struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
69532+#endif
69533+
69534+extern u16 acl_sp_role_value;
69535+extern struct acl_object_label *fakefs_obj_rw;
69536+extern struct acl_object_label *fakefs_obj_rwx;
69537+
69538+int gr_acl_is_enabled(void)
69539+{
69540+ return (gr_status & GR_READY);
69541+}
69542+
69543+void gr_enable_rbac_system(void)
69544+{
69545+ pax_open_kernel();
69546+ gr_status |= GR_READY;
69547+ pax_close_kernel();
69548+}
69549+
69550+int gr_rbac_disable(void *unused)
69551+{
69552+ pax_open_kernel();
69553+ gr_status &= ~GR_READY;
69554+ pax_close_kernel();
69555+
69556+ return 0;
69557+}
69558+
69559+static inline dev_t __get_dev(const struct dentry *dentry)
69560+{
69561+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
69562+ if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
69563+ return BTRFS_I(dentry->d_inode)->root->anon_dev;
69564+ else
69565+#endif
69566+ return dentry->d_sb->s_dev;
69567+}
69568+
69569+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
69570+{
69571+ return __get_dev(dentry);
69572+}
69573+
69574+static char gr_task_roletype_to_char(struct task_struct *task)
69575+{
69576+ switch (task->role->roletype &
69577+ (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
69578+ GR_ROLE_SPECIAL)) {
69579+ case GR_ROLE_DEFAULT:
69580+ return 'D';
69581+ case GR_ROLE_USER:
69582+ return 'U';
69583+ case GR_ROLE_GROUP:
69584+ return 'G';
69585+ case GR_ROLE_SPECIAL:
69586+ return 'S';
69587+ }
69588+
69589+ return 'X';
69590+}
69591+
69592+char gr_roletype_to_char(void)
69593+{
69594+ return gr_task_roletype_to_char(current);
69595+}
69596+
69597+__inline__ int
69598+gr_acl_tpe_check(void)
69599+{
69600+ if (unlikely(!(gr_status & GR_READY)))
69601+ return 0;
69602+ if (current->role->roletype & GR_ROLE_TPE)
69603+ return 1;
69604+ else
69605+ return 0;
69606+}
69607+
69608+int
69609+gr_handle_rawio(const struct inode *inode)
69610+{
69611+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
69612+ if (inode && (S_ISBLK(inode->i_mode) || (S_ISCHR(inode->i_mode) && imajor(inode) == RAW_MAJOR)) &&
69613+ grsec_enable_chroot_caps && proc_is_chrooted(current) &&
69614+ !capable(CAP_SYS_RAWIO))
69615+ return 1;
69616+#endif
69617+ return 0;
69618+}
69619+
69620+int
69621+gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
69622+{
69623+ if (likely(lena != lenb))
69624+ return 0;
69625+
69626+ return !memcmp(a, b, lena);
69627+}
69628+
69629+static int prepend(char **buffer, int *buflen, const char *str, int namelen)
69630+{
69631+ *buflen -= namelen;
69632+ if (*buflen < 0)
69633+ return -ENAMETOOLONG;
69634+ *buffer -= namelen;
69635+ memcpy(*buffer, str, namelen);
69636+ return 0;
69637+}
69638+
69639+static int prepend_name(char **buffer, int *buflen, struct qstr *name)
69640+{
69641+ return prepend(buffer, buflen, name->name, name->len);
69642+}
69643+
69644+static int prepend_path(const struct path *path, struct path *root,
69645+ char **buffer, int *buflen)
69646+{
69647+ struct dentry *dentry = path->dentry;
69648+ struct vfsmount *vfsmnt = path->mnt;
69649+ struct mount *mnt = real_mount(vfsmnt);
69650+ bool slash = false;
69651+ int error = 0;
69652+
69653+ while (dentry != root->dentry || vfsmnt != root->mnt) {
69654+ struct dentry * parent;
69655+
69656+ if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
69657+ /* Global root? */
69658+ if (!mnt_has_parent(mnt)) {
69659+ goto out;
69660+ }
69661+ dentry = mnt->mnt_mountpoint;
69662+ mnt = mnt->mnt_parent;
69663+ vfsmnt = &mnt->mnt;
69664+ continue;
69665+ }
69666+ parent = dentry->d_parent;
69667+ prefetch(parent);
69668+ spin_lock(&dentry->d_lock);
69669+ error = prepend_name(buffer, buflen, &dentry->d_name);
69670+ spin_unlock(&dentry->d_lock);
69671+ if (!error)
69672+ error = prepend(buffer, buflen, "/", 1);
69673+ if (error)
69674+ break;
69675+
69676+ slash = true;
69677+ dentry = parent;
69678+ }
69679+
69680+out:
69681+ if (!error && !slash)
69682+ error = prepend(buffer, buflen, "/", 1);
69683+
69684+ return error;
69685+}
69686+
69687+/* this must be called with mount_lock and rename_lock held */
69688+
69689+static char *__our_d_path(const struct path *path, struct path *root,
69690+ char *buf, int buflen)
69691+{
69692+ char *res = buf + buflen;
69693+ int error;
69694+
69695+ prepend(&res, &buflen, "\0", 1);
69696+ error = prepend_path(path, root, &res, &buflen);
69697+ if (error)
69698+ return ERR_PTR(error);
69699+
69700+ return res;
69701+}
69702+
69703+static char *
69704+gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
69705+{
69706+ char *retval;
69707+
69708+ retval = __our_d_path(path, root, buf, buflen);
69709+ if (unlikely(IS_ERR(retval)))
69710+ retval = strcpy(buf, "<path too long>");
69711+ else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
69712+ retval[1] = '\0';
69713+
69714+ return retval;
69715+}
69716+
69717+static char *
69718+__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
69719+ char *buf, int buflen)
69720+{
69721+ struct path path;
69722+ char *res;
69723+
69724+ path.dentry = (struct dentry *)dentry;
69725+ path.mnt = (struct vfsmount *)vfsmnt;
69726+
69727+ /* we can use gr_real_root.dentry, gr_real_root.mnt, because this is only called
69728+ by the RBAC system */
69729+ res = gen_full_path(&path, &gr_real_root, buf, buflen);
69730+
69731+ return res;
69732+}
69733+
69734+static char *
69735+d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
69736+ char *buf, int buflen)
69737+{
69738+ char *res;
69739+ struct path path;
69740+ struct path root;
69741+ struct task_struct *reaper = init_pid_ns.child_reaper;
69742+
69743+ path.dentry = (struct dentry *)dentry;
69744+ path.mnt = (struct vfsmount *)vfsmnt;
69745+
69746+ /* we can't use gr_real_root.dentry, gr_real_root.mnt, because they belong only to the RBAC system */
69747+ get_fs_root(reaper->fs, &root);
69748+
69749+ read_seqlock_excl(&mount_lock);
69750+ write_seqlock(&rename_lock);
69751+ res = gen_full_path(&path, &root, buf, buflen);
69752+ write_sequnlock(&rename_lock);
69753+ read_sequnlock_excl(&mount_lock);
69754+
69755+ path_put(&root);
69756+ return res;
69757+}
69758+
69759+char *
69760+gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
69761+{
69762+ char *ret;
69763+ read_seqlock_excl(&mount_lock);
69764+ write_seqlock(&rename_lock);
69765+ ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
69766+ PAGE_SIZE);
69767+ write_sequnlock(&rename_lock);
69768+ read_sequnlock_excl(&mount_lock);
69769+ return ret;
69770+}
69771+
69772+static char *
69773+gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
69774+{
69775+ char *ret;
69776+ char *buf;
69777+ int buflen;
69778+
69779+ read_seqlock_excl(&mount_lock);
69780+ write_seqlock(&rename_lock);
69781+ buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
69782+ ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
69783+ buflen = (int)(ret - buf);
69784+ if (buflen >= 5)
69785+ prepend(&ret, &buflen, "/proc", 5);
69786+ else
69787+ ret = strcpy(buf, "<path too long>");
69788+ write_sequnlock(&rename_lock);
69789+ read_sequnlock_excl(&mount_lock);
69790+ return ret;
69791+}
69792+
69793+char *
69794+gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
69795+{
69796+ return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
69797+ PAGE_SIZE);
69798+}
69799+
69800+char *
69801+gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
69802+{
69803+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
69804+ PAGE_SIZE);
69805+}
69806+
69807+char *
69808+gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
69809+{
69810+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
69811+ PAGE_SIZE);
69812+}
69813+
69814+char *
69815+gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
69816+{
69817+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
69818+ PAGE_SIZE);
69819+}
69820+
69821+char *
69822+gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
69823+{
69824+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
69825+ PAGE_SIZE);
69826+}
69827+
69828+__inline__ __u32
69829+to_gr_audit(const __u32 reqmode)
69830+{
69831+ /* masks off auditable permission flags, then shifts them to create
69832+ auditing flags, and adds the special case of append auditing if
69833+ we're requesting write */
69834+ return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
69835+}
69836+
69837+struct acl_role_label *
69838+__lookup_acl_role_label(const struct gr_policy_state *state, const struct task_struct *task, const uid_t uid,
69839+ const gid_t gid)
69840+{
69841+ unsigned int index = gr_rhash(uid, GR_ROLE_USER, state->acl_role_set.r_size);
69842+ struct acl_role_label *match;
69843+ struct role_allowed_ip *ipp;
69844+ unsigned int x;
69845+ u32 curr_ip = task->signal->saved_ip;
69846+
69847+ match = state->acl_role_set.r_hash[index];
69848+
69849+ while (match) {
69850+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
69851+ for (x = 0; x < match->domain_child_num; x++) {
69852+ if (match->domain_children[x] == uid)
69853+ goto found;
69854+ }
69855+ } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
69856+ break;
69857+ match = match->next;
69858+ }
69859+found:
69860+ if (match == NULL) {
69861+ try_group:
69862+ index = gr_rhash(gid, GR_ROLE_GROUP, state->acl_role_set.r_size);
69863+ match = state->acl_role_set.r_hash[index];
69864+
69865+ while (match) {
69866+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
69867+ for (x = 0; x < match->domain_child_num; x++) {
69868+ if (match->domain_children[x] == gid)
69869+ goto found2;
69870+ }
69871+ } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
69872+ break;
69873+ match = match->next;
69874+ }
69875+found2:
69876+ if (match == NULL)
69877+ match = state->default_role;
69878+ if (match->allowed_ips == NULL)
69879+ return match;
69880+ else {
69881+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
69882+ if (likely
69883+ ((ntohl(curr_ip) & ipp->netmask) ==
69884+ (ntohl(ipp->addr) & ipp->netmask)))
69885+ return match;
69886+ }
69887+ match = state->default_role;
69888+ }
69889+ } else if (match->allowed_ips == NULL) {
69890+ return match;
69891+ } else {
69892+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
69893+ if (likely
69894+ ((ntohl(curr_ip) & ipp->netmask) ==
69895+ (ntohl(ipp->addr) & ipp->netmask)))
69896+ return match;
69897+ }
69898+ goto try_group;
69899+ }
69900+
69901+ return match;
69902+}
69903+
69904+static struct acl_role_label *
69905+lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
69906+ const gid_t gid)
69907+{
69908+ return __lookup_acl_role_label(&running_polstate, task, uid, gid);
69909+}
69910+
69911+struct acl_subject_label *
69912+lookup_acl_subj_label(const ino_t ino, const dev_t dev,
69913+ const struct acl_role_label *role)
69914+{
69915+ unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
69916+ struct acl_subject_label *match;
69917+
69918+ match = role->subj_hash[index];
69919+
69920+ while (match && (match->inode != ino || match->device != dev ||
69921+ (match->mode & GR_DELETED))) {
69922+ match = match->next;
69923+ }
69924+
69925+ if (match && !(match->mode & GR_DELETED))
69926+ return match;
69927+ else
69928+ return NULL;
69929+}
69930+
69931+struct acl_subject_label *
69932+lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
69933+ const struct acl_role_label *role)
69934+{
69935+ unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
69936+ struct acl_subject_label *match;
69937+
69938+ match = role->subj_hash[index];
69939+
69940+ while (match && (match->inode != ino || match->device != dev ||
69941+ !(match->mode & GR_DELETED))) {
69942+ match = match->next;
69943+ }
69944+
69945+ if (match && (match->mode & GR_DELETED))
69946+ return match;
69947+ else
69948+ return NULL;
69949+}
69950+
69951+static struct acl_object_label *
69952+lookup_acl_obj_label(const ino_t ino, const dev_t dev,
69953+ const struct acl_subject_label *subj)
69954+{
69955+ unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
69956+ struct acl_object_label *match;
69957+
69958+ match = subj->obj_hash[index];
69959+
69960+ while (match && (match->inode != ino || match->device != dev ||
69961+ (match->mode & GR_DELETED))) {
69962+ match = match->next;
69963+ }
69964+
69965+ if (match && !(match->mode & GR_DELETED))
69966+ return match;
69967+ else
69968+ return NULL;
69969+}
69970+
69971+static struct acl_object_label *
69972+lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
69973+ const struct acl_subject_label *subj)
69974+{
69975+ unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
69976+ struct acl_object_label *match;
69977+
69978+ match = subj->obj_hash[index];
69979+
69980+ while (match && (match->inode != ino || match->device != dev ||
69981+ !(match->mode & GR_DELETED))) {
69982+ match = match->next;
69983+ }
69984+
69985+ if (match && (match->mode & GR_DELETED))
69986+ return match;
69987+
69988+ match = subj->obj_hash[index];
69989+
69990+ while (match && (match->inode != ino || match->device != dev ||
69991+ (match->mode & GR_DELETED))) {
69992+ match = match->next;
69993+ }
69994+
69995+ if (match && !(match->mode & GR_DELETED))
69996+ return match;
69997+ else
69998+ return NULL;
69999+}
70000+
70001+struct name_entry *
70002+__lookup_name_entry(const struct gr_policy_state *state, const char *name)
70003+{
70004+ unsigned int len = strlen(name);
70005+ unsigned int key = full_name_hash(name, len);
70006+ unsigned int index = key % state->name_set.n_size;
70007+ struct name_entry *match;
70008+
70009+ match = state->name_set.n_hash[index];
70010+
70011+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
70012+ match = match->next;
70013+
70014+ return match;
70015+}
70016+
70017+static struct name_entry *
70018+lookup_name_entry(const char *name)
70019+{
70020+ return __lookup_name_entry(&running_polstate, name);
70021+}
70022+
70023+static struct name_entry *
70024+lookup_name_entry_create(const char *name)
70025+{
70026+ unsigned int len = strlen(name);
70027+ unsigned int key = full_name_hash(name, len);
70028+ unsigned int index = key % running_polstate.name_set.n_size;
70029+ struct name_entry *match;
70030+
70031+ match = running_polstate.name_set.n_hash[index];
70032+
70033+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
70034+ !match->deleted))
70035+ match = match->next;
70036+
70037+ if (match && match->deleted)
70038+ return match;
70039+
70040+ match = running_polstate.name_set.n_hash[index];
70041+
70042+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
70043+ match->deleted))
70044+ match = match->next;
70045+
70046+ if (match && !match->deleted)
70047+ return match;
70048+ else
70049+ return NULL;
70050+}
70051+
70052+static struct inodev_entry *
70053+lookup_inodev_entry(const ino_t ino, const dev_t dev)
70054+{
70055+ unsigned int index = gr_fhash(ino, dev, running_polstate.inodev_set.i_size);
70056+ struct inodev_entry *match;
70057+
70058+ match = running_polstate.inodev_set.i_hash[index];
70059+
70060+ while (match && (match->nentry->inode != ino || match->nentry->device != dev))
70061+ match = match->next;
70062+
70063+ return match;
70064+}
70065+
70066+void
70067+__insert_inodev_entry(const struct gr_policy_state *state, struct inodev_entry *entry)
70068+{
70069+ unsigned int index = gr_fhash(entry->nentry->inode, entry->nentry->device,
70070+ state->inodev_set.i_size);
70071+ struct inodev_entry **curr;
70072+
70073+ entry->prev = NULL;
70074+
70075+ curr = &state->inodev_set.i_hash[index];
70076+ if (*curr != NULL)
70077+ (*curr)->prev = entry;
70078+
70079+ entry->next = *curr;
70080+ *curr = entry;
70081+
70082+ return;
70083+}
70084+
70085+static void
70086+insert_inodev_entry(struct inodev_entry *entry)
70087+{
70088+ __insert_inodev_entry(&running_polstate, entry);
70089+}
70090+
70091+void
70092+insert_acl_obj_label(struct acl_object_label *obj,
70093+ struct acl_subject_label *subj)
70094+{
70095+ unsigned int index =
70096+ gr_fhash(obj->inode, obj->device, subj->obj_hash_size);
70097+ struct acl_object_label **curr;
70098+
70099+ obj->prev = NULL;
70100+
70101+ curr = &subj->obj_hash[index];
70102+ if (*curr != NULL)
70103+ (*curr)->prev = obj;
70104+
70105+ obj->next = *curr;
70106+ *curr = obj;
70107+
70108+ return;
70109+}
70110+
70111+void
70112+insert_acl_subj_label(struct acl_subject_label *obj,
70113+ struct acl_role_label *role)
70114+{
70115+ unsigned int index = gr_fhash(obj->inode, obj->device, role->subj_hash_size);
70116+ struct acl_subject_label **curr;
70117+
70118+ obj->prev = NULL;
70119+
70120+ curr = &role->subj_hash[index];
70121+ if (*curr != NULL)
70122+ (*curr)->prev = obj;
70123+
70124+ obj->next = *curr;
70125+ *curr = obj;
70126+
70127+ return;
70128+}
70129+
70130+/* derived from glibc fnmatch() 0: match, 1: no match*/
70131+
70132+static int
70133+glob_match(const char *p, const char *n)
70134+{
70135+ char c;
70136+
70137+ while ((c = *p++) != '\0') {
70138+ switch (c) {
70139+ case '?':
70140+ if (*n == '\0')
70141+ return 1;
70142+ else if (*n == '/')
70143+ return 1;
70144+ break;
70145+ case '\\':
70146+ if (*n != c)
70147+ return 1;
70148+ break;
70149+ case '*':
70150+ for (c = *p++; c == '?' || c == '*'; c = *p++) {
70151+ if (*n == '/')
70152+ return 1;
70153+ else if (c == '?') {
70154+ if (*n == '\0')
70155+ return 1;
70156+ else
70157+ ++n;
70158+ }
70159+ }
70160+ if (c == '\0') {
70161+ return 0;
70162+ } else {
70163+ const char *endp;
70164+
70165+ if ((endp = strchr(n, '/')) == NULL)
70166+ endp = n + strlen(n);
70167+
70168+ if (c == '[') {
70169+ for (--p; n < endp; ++n)
70170+ if (!glob_match(p, n))
70171+ return 0;
70172+ } else if (c == '/') {
70173+ while (*n != '\0' && *n != '/')
70174+ ++n;
70175+ if (*n == '/' && !glob_match(p, n + 1))
70176+ return 0;
70177+ } else {
70178+ for (--p; n < endp; ++n)
70179+ if (*n == c && !glob_match(p, n))
70180+ return 0;
70181+ }
70182+
70183+ return 1;
70184+ }
70185+ case '[':
70186+ {
70187+ int not;
70188+ char cold;
70189+
70190+ if (*n == '\0' || *n == '/')
70191+ return 1;
70192+
70193+ not = (*p == '!' || *p == '^');
70194+ if (not)
70195+ ++p;
70196+
70197+ c = *p++;
70198+ for (;;) {
70199+ unsigned char fn = (unsigned char)*n;
70200+
70201+ if (c == '\0')
70202+ return 1;
70203+ else {
70204+ if (c == fn)
70205+ goto matched;
70206+ cold = c;
70207+ c = *p++;
70208+
70209+ if (c == '-' && *p != ']') {
70210+ unsigned char cend = *p++;
70211+
70212+ if (cend == '\0')
70213+ return 1;
70214+
70215+ if (cold <= fn && fn <= cend)
70216+ goto matched;
70217+
70218+ c = *p++;
70219+ }
70220+ }
70221+
70222+ if (c == ']')
70223+ break;
70224+ }
70225+ if (!not)
70226+ return 1;
70227+ break;
70228+ matched:
70229+ while (c != ']') {
70230+ if (c == '\0')
70231+ return 1;
70232+
70233+ c = *p++;
70234+ }
70235+ if (not)
70236+ return 1;
70237+ }
70238+ break;
70239+ default:
70240+ if (c != *n)
70241+ return 1;
70242+ }
70243+
70244+ ++n;
70245+ }
70246+
70247+ if (*n == '\0')
70248+ return 0;
70249+
70250+ if (*n == '/')
70251+ return 0;
70252+
70253+ return 1;
70254+}
70255+
70256+static struct acl_object_label *
70257+chk_glob_label(struct acl_object_label *globbed,
70258+ const struct dentry *dentry, const struct vfsmount *mnt, char **path)
70259+{
70260+ struct acl_object_label *tmp;
70261+
70262+ if (*path == NULL)
70263+ *path = gr_to_filename_nolock(dentry, mnt);
70264+
70265+ tmp = globbed;
70266+
70267+ while (tmp) {
70268+ if (!glob_match(tmp->filename, *path))
70269+ return tmp;
70270+ tmp = tmp->next;
70271+ }
70272+
70273+ return NULL;
70274+}
70275+
70276+static struct acl_object_label *
70277+__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
70278+ const ino_t curr_ino, const dev_t curr_dev,
70279+ const struct acl_subject_label *subj, char **path, const int checkglob)
70280+{
70281+ struct acl_subject_label *tmpsubj;
70282+ struct acl_object_label *retval;
70283+ struct acl_object_label *retval2;
70284+
70285+ tmpsubj = (struct acl_subject_label *) subj;
70286+ read_lock(&gr_inode_lock);
70287+ do {
70288+ retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
70289+ if (retval) {
70290+ if (checkglob && retval->globbed) {
70291+ retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
70292+ if (retval2)
70293+ retval = retval2;
70294+ }
70295+ break;
70296+ }
70297+ } while ((tmpsubj = tmpsubj->parent_subject));
70298+ read_unlock(&gr_inode_lock);
70299+
70300+ return retval;
70301+}
70302+
70303+static __inline__ struct acl_object_label *
70304+full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
70305+ struct dentry *curr_dentry,
70306+ const struct acl_subject_label *subj, char **path, const int checkglob)
70307+{
70308+ int newglob = checkglob;
70309+ ino_t inode;
70310+ dev_t device;
70311+
70312+ /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
70313+ as we don't want a / * rule to match instead of the / object
70314+ don't do this for create lookups that call this function though, since they're looking up
70315+ on the parent and thus need globbing checks on all paths
70316+ */
70317+ if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
70318+ newglob = GR_NO_GLOB;
70319+
70320+ spin_lock(&curr_dentry->d_lock);
70321+ inode = curr_dentry->d_inode->i_ino;
70322+ device = __get_dev(curr_dentry);
70323+ spin_unlock(&curr_dentry->d_lock);
70324+
70325+ return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
70326+}
70327+
70328+#ifdef CONFIG_HUGETLBFS
70329+static inline bool
70330+is_hugetlbfs_mnt(const struct vfsmount *mnt)
70331+{
70332+ int i;
70333+ for (i = 0; i < HUGE_MAX_HSTATE; i++) {
70334+ if (unlikely(hugetlbfs_vfsmount[i] == mnt))
70335+ return true;
70336+ }
70337+
70338+ return false;
70339+}
70340+#endif
70341+
70342+static struct acl_object_label *
70343+__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
70344+ const struct acl_subject_label *subj, char *path, const int checkglob)
70345+{
70346+ struct dentry *dentry = (struct dentry *) l_dentry;
70347+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
70348+ struct mount *real_mnt = real_mount(mnt);
70349+ struct acl_object_label *retval;
70350+ struct dentry *parent;
70351+
70352+ read_seqlock_excl(&mount_lock);
70353+ write_seqlock(&rename_lock);
70354+
70355+ if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
70356+#ifdef CONFIG_NET
70357+ mnt == sock_mnt ||
70358+#endif
70359+#ifdef CONFIG_HUGETLBFS
70360+ (is_hugetlbfs_mnt(mnt) && dentry->d_inode->i_nlink == 0) ||
70361+#endif
70362+ /* ignore Eric Biederman */
70363+ IS_PRIVATE(l_dentry->d_inode))) {
70364+ retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
70365+ goto out;
70366+ }
70367+
70368+ for (;;) {
70369+ if (dentry == gr_real_root.dentry && mnt == gr_real_root.mnt)
70370+ break;
70371+
70372+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
70373+ if (!mnt_has_parent(real_mnt))
70374+ break;
70375+
70376+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
70377+ if (retval != NULL)
70378+ goto out;
70379+
70380+ dentry = real_mnt->mnt_mountpoint;
70381+ real_mnt = real_mnt->mnt_parent;
70382+ mnt = &real_mnt->mnt;
70383+ continue;
70384+ }
70385+
70386+ parent = dentry->d_parent;
70387+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
70388+ if (retval != NULL)
70389+ goto out;
70390+
70391+ dentry = parent;
70392+ }
70393+
70394+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
70395+
70396+ /* gr_real_root is pinned so we don't have to hold a reference */
70397+ if (retval == NULL)
70398+ retval = full_lookup(l_dentry, l_mnt, gr_real_root.dentry, subj, &path, checkglob);
70399+out:
70400+ write_sequnlock(&rename_lock);
70401+ read_sequnlock_excl(&mount_lock);
70402+
70403+ BUG_ON(retval == NULL);
70404+
70405+ return retval;
70406+}
70407+
70408+static __inline__ struct acl_object_label *
70409+chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
70410+ const struct acl_subject_label *subj)
70411+{
70412+ char *path = NULL;
70413+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
70414+}
70415+
70416+static __inline__ struct acl_object_label *
70417+chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
70418+ const struct acl_subject_label *subj)
70419+{
70420+ char *path = NULL;
70421+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
70422+}
70423+
70424+static __inline__ struct acl_object_label *
70425+chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
70426+ const struct acl_subject_label *subj, char *path)
70427+{
70428+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
70429+}
70430+
70431+struct acl_subject_label *
70432+chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
70433+ const struct acl_role_label *role)
70434+{
70435+ struct dentry *dentry = (struct dentry *) l_dentry;
70436+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
70437+ struct mount *real_mnt = real_mount(mnt);
70438+ struct acl_subject_label *retval;
70439+ struct dentry *parent;
70440+
70441+ read_seqlock_excl(&mount_lock);
70442+ write_seqlock(&rename_lock);
70443+
70444+ for (;;) {
70445+ if (dentry == gr_real_root.dentry && mnt == gr_real_root.mnt)
70446+ break;
70447+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
70448+ if (!mnt_has_parent(real_mnt))
70449+ break;
70450+
70451+ spin_lock(&dentry->d_lock);
70452+ read_lock(&gr_inode_lock);
70453+ retval =
70454+ lookup_acl_subj_label(dentry->d_inode->i_ino,
70455+ __get_dev(dentry), role);
70456+ read_unlock(&gr_inode_lock);
70457+ spin_unlock(&dentry->d_lock);
70458+ if (retval != NULL)
70459+ goto out;
70460+
70461+ dentry = real_mnt->mnt_mountpoint;
70462+ real_mnt = real_mnt->mnt_parent;
70463+ mnt = &real_mnt->mnt;
70464+ continue;
70465+ }
70466+
70467+ spin_lock(&dentry->d_lock);
70468+ read_lock(&gr_inode_lock);
70469+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
70470+ __get_dev(dentry), role);
70471+ read_unlock(&gr_inode_lock);
70472+ parent = dentry->d_parent;
70473+ spin_unlock(&dentry->d_lock);
70474+
70475+ if (retval != NULL)
70476+ goto out;
70477+
70478+ dentry = parent;
70479+ }
70480+
70481+ spin_lock(&dentry->d_lock);
70482+ read_lock(&gr_inode_lock);
70483+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
70484+ __get_dev(dentry), role);
70485+ read_unlock(&gr_inode_lock);
70486+ spin_unlock(&dentry->d_lock);
70487+
70488+ if (unlikely(retval == NULL)) {
70489+ /* gr_real_root is pinned, we don't need to hold a reference */
70490+ read_lock(&gr_inode_lock);
70491+ retval = lookup_acl_subj_label(gr_real_root.dentry->d_inode->i_ino,
70492+ __get_dev(gr_real_root.dentry), role);
70493+ read_unlock(&gr_inode_lock);
70494+ }
70495+out:
70496+ write_sequnlock(&rename_lock);
70497+ read_sequnlock_excl(&mount_lock);
70498+
70499+ BUG_ON(retval == NULL);
70500+
70501+ return retval;
70502+}
70503+
70504+void
70505+assign_special_role(const char *rolename)
70506+{
70507+ struct acl_object_label *obj;
70508+ struct acl_role_label *r;
70509+ struct acl_role_label *assigned = NULL;
70510+ struct task_struct *tsk;
70511+ struct file *filp;
70512+
70513+ FOR_EACH_ROLE_START(r)
70514+ if (!strcmp(rolename, r->rolename) &&
70515+ (r->roletype & GR_ROLE_SPECIAL)) {
70516+ assigned = r;
70517+ break;
70518+ }
70519+ FOR_EACH_ROLE_END(r)
70520+
70521+ if (!assigned)
70522+ return;
70523+
70524+ read_lock(&tasklist_lock);
70525+ read_lock(&grsec_exec_file_lock);
70526+
70527+ tsk = current->real_parent;
70528+ if (tsk == NULL)
70529+ goto out_unlock;
70530+
70531+ filp = tsk->exec_file;
70532+ if (filp == NULL)
70533+ goto out_unlock;
70534+
70535+ tsk->is_writable = 0;
70536+ tsk->inherited = 0;
70537+
70538+ tsk->acl_sp_role = 1;
70539+ tsk->acl_role_id = ++acl_sp_role_value;
70540+ tsk->role = assigned;
70541+ tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
70542+
70543+ /* ignore additional mmap checks for processes that are writable
70544+ by the default ACL */
70545+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
70546+ if (unlikely(obj->mode & GR_WRITE))
70547+ tsk->is_writable = 1;
70548+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
70549+ if (unlikely(obj->mode & GR_WRITE))
70550+ tsk->is_writable = 1;
70551+
70552+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
70553+ printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename,
70554+ tsk->acl->filename, tsk->comm, task_pid_nr(tsk));
70555+#endif
70556+
70557+out_unlock:
70558+ read_unlock(&grsec_exec_file_lock);
70559+ read_unlock(&tasklist_lock);
70560+ return;
70561+}
70562+
70563+
70564+static void
70565+gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
70566+{
70567+ struct task_struct *task = current;
70568+ const struct cred *cred = current_cred();
70569+
70570+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
70571+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
70572+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
70573+ 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
70574+
70575+ return;
70576+}
70577+
70578+static void
70579+gr_log_learn_uid_change(const kuid_t real, const kuid_t effective, const kuid_t fs)
70580+{
70581+ struct task_struct *task = current;
70582+ const struct cred *cred = current_cred();
70583+
70584+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
70585+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
70586+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
70587+ 'u', GR_GLOBAL_UID(real), GR_GLOBAL_UID(effective), GR_GLOBAL_UID(fs), &task->signal->saved_ip);
70588+
70589+ return;
70590+}
70591+
70592+static void
70593+gr_log_learn_gid_change(const kgid_t real, const kgid_t effective, const kgid_t fs)
70594+{
70595+ struct task_struct *task = current;
70596+ const struct cred *cred = current_cred();
70597+
70598+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
70599+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
70600+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
70601+ 'g', GR_GLOBAL_GID(real), GR_GLOBAL_GID(effective), GR_GLOBAL_GID(fs), &task->signal->saved_ip);
70602+
70603+ return;
70604+}
70605+
70606+static void
70607+gr_set_proc_res(struct task_struct *task)
70608+{
70609+ struct acl_subject_label *proc;
70610+ unsigned short i;
70611+
70612+ proc = task->acl;
70613+
70614+ if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
70615+ return;
70616+
70617+ for (i = 0; i < RLIM_NLIMITS; i++) {
70618+ if (!(proc->resmask & (1U << i)))
70619+ continue;
70620+
70621+ task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
70622+ task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
70623+
70624+ if (i == RLIMIT_CPU)
70625+ update_rlimit_cpu(task, proc->res[i].rlim_cur);
70626+ }
70627+
70628+ return;
70629+}
70630+
70631+/* both of the below must be called with
70632+ rcu_read_lock();
70633+ read_lock(&tasklist_lock);
70634+ read_lock(&grsec_exec_file_lock);
70635+*/
70636+
70637+struct acl_subject_label *__gr_get_subject_for_task(const struct gr_policy_state *state, struct task_struct *task, const char *filename)
70638+{
70639+ char *tmpname;
70640+ struct acl_subject_label *tmpsubj;
70641+ struct file *filp;
70642+ struct name_entry *nmatch;
70643+
70644+ filp = task->exec_file;
70645+ if (filp == NULL)
70646+ return NULL;
70647+
70648+ /* the following is to apply the correct subject
70649+ on binaries running when the RBAC system
70650+ is enabled, when the binaries have been
70651+ replaced or deleted since their execution
70652+ -----
70653+ when the RBAC system starts, the inode/dev
70654+ from exec_file will be one the RBAC system
70655+ is unaware of. It only knows the inode/dev
70656+ of the present file on disk, or the absence
70657+ of it.
70658+ */
70659+
70660+ if (filename)
70661+ nmatch = __lookup_name_entry(state, filename);
70662+ else {
70663+ preempt_disable();
70664+ tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
70665+
70666+ nmatch = __lookup_name_entry(state, tmpname);
70667+ preempt_enable();
70668+ }
70669+ tmpsubj = NULL;
70670+ if (nmatch) {
70671+ if (nmatch->deleted)
70672+ tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
70673+ else
70674+ tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
70675+ }
70676+ /* this also works for the reload case -- if we don't match a potentially inherited subject
70677+ then we fall back to a normal lookup based on the binary's ino/dev
70678+ */
70679+ if (tmpsubj == NULL)
70680+ tmpsubj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, task->role);
70681+
70682+ return tmpsubj;
70683+}
70684+
70685+static struct acl_subject_label *gr_get_subject_for_task(struct task_struct *task, const char *filename)
70686+{
70687+ return __gr_get_subject_for_task(&running_polstate, task, filename);
70688+}
70689+
70690+void __gr_apply_subject_to_task(const struct gr_policy_state *state, struct task_struct *task, struct acl_subject_label *subj)
70691+{
70692+ struct acl_object_label *obj;
70693+ struct file *filp;
70694+
70695+ filp = task->exec_file;
70696+
70697+ task->acl = subj;
70698+ task->is_writable = 0;
70699+ /* ignore additional mmap checks for processes that are writable
70700+ by the default ACL */
70701+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, state->default_role->root_label);
70702+ if (unlikely(obj->mode & GR_WRITE))
70703+ task->is_writable = 1;
70704+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
70705+ if (unlikely(obj->mode & GR_WRITE))
70706+ task->is_writable = 1;
70707+
70708+ gr_set_proc_res(task);
70709+
70710+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
70711+ 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);
70712+#endif
70713+}
70714+
70715+static void gr_apply_subject_to_task(struct task_struct *task, struct acl_subject_label *subj)
70716+{
70717+ __gr_apply_subject_to_task(&running_polstate, task, subj);
70718+}
70719+
70720+__u32
70721+gr_search_file(const struct dentry * dentry, const __u32 mode,
70722+ const struct vfsmount * mnt)
70723+{
70724+ __u32 retval = mode;
70725+ struct acl_subject_label *curracl;
70726+ struct acl_object_label *currobj;
70727+
70728+ if (unlikely(!(gr_status & GR_READY)))
70729+ return (mode & ~GR_AUDITS);
70730+
70731+ curracl = current->acl;
70732+
70733+ currobj = chk_obj_label(dentry, mnt, curracl);
70734+ retval = currobj->mode & mode;
70735+
70736+ /* if we're opening a specified transfer file for writing
70737+ (e.g. /dev/initctl), then transfer our role to init
70738+ */
70739+ if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
70740+ current->role->roletype & GR_ROLE_PERSIST)) {
70741+ struct task_struct *task = init_pid_ns.child_reaper;
70742+
70743+ if (task->role != current->role) {
70744+ struct acl_subject_label *subj;
70745+
70746+ task->acl_sp_role = 0;
70747+ task->acl_role_id = current->acl_role_id;
70748+ task->role = current->role;
70749+ rcu_read_lock();
70750+ read_lock(&grsec_exec_file_lock);
70751+ subj = gr_get_subject_for_task(task, NULL);
70752+ gr_apply_subject_to_task(task, subj);
70753+ read_unlock(&grsec_exec_file_lock);
70754+ rcu_read_unlock();
70755+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
70756+ }
70757+ }
70758+
70759+ if (unlikely
70760+ ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
70761+ && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
70762+ __u32 new_mode = mode;
70763+
70764+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
70765+
70766+ retval = new_mode;
70767+
70768+ if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
70769+ new_mode |= GR_INHERIT;
70770+
70771+ if (!(mode & GR_NOLEARN))
70772+ gr_log_learn(dentry, mnt, new_mode);
70773+ }
70774+
70775+ return retval;
70776+}
70777+
70778+struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
70779+ const struct dentry *parent,
70780+ const struct vfsmount *mnt)
70781+{
70782+ struct name_entry *match;
70783+ struct acl_object_label *matchpo;
70784+ struct acl_subject_label *curracl;
70785+ char *path;
70786+
70787+ if (unlikely(!(gr_status & GR_READY)))
70788+ return NULL;
70789+
70790+ preempt_disable();
70791+ path = gr_to_filename_rbac(new_dentry, mnt);
70792+ match = lookup_name_entry_create(path);
70793+
70794+ curracl = current->acl;
70795+
70796+ if (match) {
70797+ read_lock(&gr_inode_lock);
70798+ matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
70799+ read_unlock(&gr_inode_lock);
70800+
70801+ if (matchpo) {
70802+ preempt_enable();
70803+ return matchpo;
70804+ }
70805+ }
70806+
70807+ // lookup parent
70808+
70809+ matchpo = chk_obj_create_label(parent, mnt, curracl, path);
70810+
70811+ preempt_enable();
70812+ return matchpo;
70813+}
70814+
70815+__u32
70816+gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
70817+ const struct vfsmount * mnt, const __u32 mode)
70818+{
70819+ struct acl_object_label *matchpo;
70820+ __u32 retval;
70821+
70822+ if (unlikely(!(gr_status & GR_READY)))
70823+ return (mode & ~GR_AUDITS);
70824+
70825+ matchpo = gr_get_create_object(new_dentry, parent, mnt);
70826+
70827+ retval = matchpo->mode & mode;
70828+
70829+ if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
70830+ && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
70831+ __u32 new_mode = mode;
70832+
70833+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
70834+
70835+ gr_log_learn(new_dentry, mnt, new_mode);
70836+ return new_mode;
70837+ }
70838+
70839+ return retval;
70840+}
70841+
70842+__u32
70843+gr_check_link(const struct dentry * new_dentry,
70844+ const struct dentry * parent_dentry,
70845+ const struct vfsmount * parent_mnt,
70846+ const struct dentry * old_dentry, const struct vfsmount * old_mnt)
70847+{
70848+ struct acl_object_label *obj;
70849+ __u32 oldmode, newmode;
70850+ __u32 needmode;
70851+ __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
70852+ GR_DELETE | GR_INHERIT;
70853+
70854+ if (unlikely(!(gr_status & GR_READY)))
70855+ return (GR_CREATE | GR_LINK);
70856+
70857+ obj = chk_obj_label(old_dentry, old_mnt, current->acl);
70858+ oldmode = obj->mode;
70859+
70860+ obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
70861+ newmode = obj->mode;
70862+
70863+ needmode = newmode & checkmodes;
70864+
70865+ // old name for hardlink must have at least the permissions of the new name
70866+ if ((oldmode & needmode) != needmode)
70867+ goto bad;
70868+
70869+ // if old name had restrictions/auditing, make sure the new name does as well
70870+ needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
70871+
70872+ // don't allow hardlinking of suid/sgid/fcapped files without permission
70873+ if (is_privileged_binary(old_dentry))
70874+ needmode |= GR_SETID;
70875+
70876+ if ((newmode & needmode) != needmode)
70877+ goto bad;
70878+
70879+ // enforce minimum permissions
70880+ if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
70881+ return newmode;
70882+bad:
70883+ needmode = oldmode;
70884+ if (is_privileged_binary(old_dentry))
70885+ needmode |= GR_SETID;
70886+
70887+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
70888+ gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
70889+ return (GR_CREATE | GR_LINK);
70890+ } else if (newmode & GR_SUPPRESS)
70891+ return GR_SUPPRESS;
70892+ else
70893+ return 0;
70894+}
70895+
70896+int
70897+gr_check_hidden_task(const struct task_struct *task)
70898+{
70899+ if (unlikely(!(gr_status & GR_READY)))
70900+ return 0;
70901+
70902+ if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
70903+ return 1;
70904+
70905+ return 0;
70906+}
70907+
70908+int
70909+gr_check_protected_task(const struct task_struct *task)
70910+{
70911+ if (unlikely(!(gr_status & GR_READY) || !task))
70912+ return 0;
70913+
70914+ if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
70915+ task->acl != current->acl)
70916+ return 1;
70917+
70918+ return 0;
70919+}
70920+
70921+int
70922+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
70923+{
70924+ struct task_struct *p;
70925+ int ret = 0;
70926+
70927+ if (unlikely(!(gr_status & GR_READY) || !pid))
70928+ return ret;
70929+
70930+ read_lock(&tasklist_lock);
70931+ do_each_pid_task(pid, type, p) {
70932+ if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
70933+ p->acl != current->acl) {
70934+ ret = 1;
70935+ goto out;
70936+ }
70937+ } while_each_pid_task(pid, type, p);
70938+out:
70939+ read_unlock(&tasklist_lock);
70940+
70941+ return ret;
70942+}
70943+
70944+void
70945+gr_copy_label(struct task_struct *tsk)
70946+{
70947+ struct task_struct *p = current;
70948+
70949+ tsk->inherited = p->inherited;
70950+ tsk->acl_sp_role = 0;
70951+ tsk->acl_role_id = p->acl_role_id;
70952+ tsk->acl = p->acl;
70953+ tsk->role = p->role;
70954+ tsk->signal->used_accept = 0;
70955+ tsk->signal->curr_ip = p->signal->curr_ip;
70956+ tsk->signal->saved_ip = p->signal->saved_ip;
70957+ if (p->exec_file)
70958+ get_file(p->exec_file);
70959+ tsk->exec_file = p->exec_file;
70960+ tsk->is_writable = p->is_writable;
70961+ if (unlikely(p->signal->used_accept)) {
70962+ p->signal->curr_ip = 0;
70963+ p->signal->saved_ip = 0;
70964+ }
70965+
70966+ return;
70967+}
70968+
70969+extern int gr_process_kernel_setuid_ban(struct user_struct *user);
70970+
70971+int
70972+gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
70973+{
70974+ unsigned int i;
70975+ __u16 num;
70976+ uid_t *uidlist;
70977+ uid_t curuid;
70978+ int realok = 0;
70979+ int effectiveok = 0;
70980+ int fsok = 0;
70981+ uid_t globalreal, globaleffective, globalfs;
70982+
70983+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT)
70984+ struct user_struct *user;
70985+
70986+ if (!uid_valid(real))
70987+ goto skipit;
70988+
70989+ /* find user based on global namespace */
70990+
70991+ globalreal = GR_GLOBAL_UID(real);
70992+
70993+ user = find_user(make_kuid(&init_user_ns, globalreal));
70994+ if (user == NULL)
70995+ goto skipit;
70996+
70997+ if (gr_process_kernel_setuid_ban(user)) {
70998+ /* for find_user */
70999+ free_uid(user);
71000+ return 1;
71001+ }
71002+
71003+ /* for find_user */
71004+ free_uid(user);
71005+
71006+skipit:
71007+#endif
71008+
71009+ if (unlikely(!(gr_status & GR_READY)))
71010+ return 0;
71011+
71012+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
71013+ gr_log_learn_uid_change(real, effective, fs);
71014+
71015+ num = current->acl->user_trans_num;
71016+ uidlist = current->acl->user_transitions;
71017+
71018+ if (uidlist == NULL)
71019+ return 0;
71020+
71021+ if (!uid_valid(real)) {
71022+ realok = 1;
71023+ globalreal = (uid_t)-1;
71024+ } else {
71025+ globalreal = GR_GLOBAL_UID(real);
71026+ }
71027+ if (!uid_valid(effective)) {
71028+ effectiveok = 1;
71029+ globaleffective = (uid_t)-1;
71030+ } else {
71031+ globaleffective = GR_GLOBAL_UID(effective);
71032+ }
71033+ if (!uid_valid(fs)) {
71034+ fsok = 1;
71035+ globalfs = (uid_t)-1;
71036+ } else {
71037+ globalfs = GR_GLOBAL_UID(fs);
71038+ }
71039+
71040+ if (current->acl->user_trans_type & GR_ID_ALLOW) {
71041+ for (i = 0; i < num; i++) {
71042+ curuid = uidlist[i];
71043+ if (globalreal == curuid)
71044+ realok = 1;
71045+ if (globaleffective == curuid)
71046+ effectiveok = 1;
71047+ if (globalfs == curuid)
71048+ fsok = 1;
71049+ }
71050+ } else if (current->acl->user_trans_type & GR_ID_DENY) {
71051+ for (i = 0; i < num; i++) {
71052+ curuid = uidlist[i];
71053+ if (globalreal == curuid)
71054+ break;
71055+ if (globaleffective == curuid)
71056+ break;
71057+ if (globalfs == curuid)
71058+ break;
71059+ }
71060+ /* not in deny list */
71061+ if (i == num) {
71062+ realok = 1;
71063+ effectiveok = 1;
71064+ fsok = 1;
71065+ }
71066+ }
71067+
71068+ if (realok && effectiveok && fsok)
71069+ return 0;
71070+ else {
71071+ gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
71072+ return 1;
71073+ }
71074+}
71075+
71076+int
71077+gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
71078+{
71079+ unsigned int i;
71080+ __u16 num;
71081+ gid_t *gidlist;
71082+ gid_t curgid;
71083+ int realok = 0;
71084+ int effectiveok = 0;
71085+ int fsok = 0;
71086+ gid_t globalreal, globaleffective, globalfs;
71087+
71088+ if (unlikely(!(gr_status & GR_READY)))
71089+ return 0;
71090+
71091+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
71092+ gr_log_learn_gid_change(real, effective, fs);
71093+
71094+ num = current->acl->group_trans_num;
71095+ gidlist = current->acl->group_transitions;
71096+
71097+ if (gidlist == NULL)
71098+ return 0;
71099+
71100+ if (!gid_valid(real)) {
71101+ realok = 1;
71102+ globalreal = (gid_t)-1;
71103+ } else {
71104+ globalreal = GR_GLOBAL_GID(real);
71105+ }
71106+ if (!gid_valid(effective)) {
71107+ effectiveok = 1;
71108+ globaleffective = (gid_t)-1;
71109+ } else {
71110+ globaleffective = GR_GLOBAL_GID(effective);
71111+ }
71112+ if (!gid_valid(fs)) {
71113+ fsok = 1;
71114+ globalfs = (gid_t)-1;
71115+ } else {
71116+ globalfs = GR_GLOBAL_GID(fs);
71117+ }
71118+
71119+ if (current->acl->group_trans_type & GR_ID_ALLOW) {
71120+ for (i = 0; i < num; i++) {
71121+ curgid = gidlist[i];
71122+ if (globalreal == curgid)
71123+ realok = 1;
71124+ if (globaleffective == curgid)
71125+ effectiveok = 1;
71126+ if (globalfs == curgid)
71127+ fsok = 1;
71128+ }
71129+ } else if (current->acl->group_trans_type & GR_ID_DENY) {
71130+ for (i = 0; i < num; i++) {
71131+ curgid = gidlist[i];
71132+ if (globalreal == curgid)
71133+ break;
71134+ if (globaleffective == curgid)
71135+ break;
71136+ if (globalfs == curgid)
71137+ break;
71138+ }
71139+ /* not in deny list */
71140+ if (i == num) {
71141+ realok = 1;
71142+ effectiveok = 1;
71143+ fsok = 1;
71144+ }
71145+ }
71146+
71147+ if (realok && effectiveok && fsok)
71148+ return 0;
71149+ else {
71150+ gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
71151+ return 1;
71152+ }
71153+}
71154+
71155+extern int gr_acl_is_capable(const int cap);
71156+
71157+void
71158+gr_set_role_label(struct task_struct *task, const kuid_t kuid, const kgid_t kgid)
71159+{
71160+ struct acl_role_label *role = task->role;
71161+ struct acl_subject_label *subj = NULL;
71162+ struct acl_object_label *obj;
71163+ struct file *filp;
71164+ uid_t uid;
71165+ gid_t gid;
71166+
71167+ if (unlikely(!(gr_status & GR_READY)))
71168+ return;
71169+
71170+ uid = GR_GLOBAL_UID(kuid);
71171+ gid = GR_GLOBAL_GID(kgid);
71172+
71173+ filp = task->exec_file;
71174+
71175+ /* kernel process, we'll give them the kernel role */
71176+ if (unlikely(!filp)) {
71177+ task->role = running_polstate.kernel_role;
71178+ task->acl = running_polstate.kernel_role->root_label;
71179+ return;
71180+ } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL)) {
71181+ /* save the current ip at time of role lookup so that the proper
71182+ IP will be learned for role_allowed_ip */
71183+ task->signal->saved_ip = task->signal->curr_ip;
71184+ role = lookup_acl_role_label(task, uid, gid);
71185+ }
71186+
71187+ /* don't change the role if we're not a privileged process */
71188+ if (role && task->role != role &&
71189+ (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
71190+ ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
71191+ return;
71192+
71193+ /* perform subject lookup in possibly new role
71194+ we can use this result below in the case where role == task->role
71195+ */
71196+ subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
71197+
71198+ /* if we changed uid/gid, but result in the same role
71199+ and are using inheritance, don't lose the inherited subject
71200+ if current subject is other than what normal lookup
71201+ would result in, we arrived via inheritance, don't
71202+ lose subject
71203+ */
71204+ if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
71205+ (subj == task->acl)))
71206+ task->acl = subj;
71207+
71208+ /* leave task->inherited unaffected */
71209+
71210+ task->role = role;
71211+
71212+ task->is_writable = 0;
71213+
71214+ /* ignore additional mmap checks for processes that are writable
71215+ by the default ACL */
71216+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
71217+ if (unlikely(obj->mode & GR_WRITE))
71218+ task->is_writable = 1;
71219+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
71220+ if (unlikely(obj->mode & GR_WRITE))
71221+ task->is_writable = 1;
71222+
71223+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
71224+ 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);
71225+#endif
71226+
71227+ gr_set_proc_res(task);
71228+
71229+ return;
71230+}
71231+
71232+int
71233+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
71234+ const int unsafe_flags)
71235+{
71236+ struct task_struct *task = current;
71237+ struct acl_subject_label *newacl;
71238+ struct acl_object_label *obj;
71239+ __u32 retmode;
71240+
71241+ if (unlikely(!(gr_status & GR_READY)))
71242+ return 0;
71243+
71244+ newacl = chk_subj_label(dentry, mnt, task->role);
71245+
71246+ /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
71247+ did an exec
71248+ */
71249+ rcu_read_lock();
71250+ read_lock(&tasklist_lock);
71251+ if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
71252+ (task->parent->acl->mode & GR_POVERRIDE))) {
71253+ read_unlock(&tasklist_lock);
71254+ rcu_read_unlock();
71255+ goto skip_check;
71256+ }
71257+ read_unlock(&tasklist_lock);
71258+ rcu_read_unlock();
71259+
71260+ if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
71261+ !(task->role->roletype & GR_ROLE_GOD) &&
71262+ !gr_search_file(dentry, GR_PTRACERD, mnt) &&
71263+ !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
71264+ if (unsafe_flags & LSM_UNSAFE_SHARE)
71265+ gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
71266+ else
71267+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
71268+ return -EACCES;
71269+ }
71270+
71271+skip_check:
71272+
71273+ obj = chk_obj_label(dentry, mnt, task->acl);
71274+ retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
71275+
71276+ if (!(task->acl->mode & GR_INHERITLEARN) &&
71277+ ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
71278+ if (obj->nested)
71279+ task->acl = obj->nested;
71280+ else
71281+ task->acl = newacl;
71282+ task->inherited = 0;
71283+ } else {
71284+ task->inherited = 1;
71285+ if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
71286+ gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
71287+ }
71288+
71289+ task->is_writable = 0;
71290+
71291+ /* ignore additional mmap checks for processes that are writable
71292+ by the default ACL */
71293+ obj = chk_obj_label(dentry, mnt, running_polstate.default_role->root_label);
71294+ if (unlikely(obj->mode & GR_WRITE))
71295+ task->is_writable = 1;
71296+ obj = chk_obj_label(dentry, mnt, task->role->root_label);
71297+ if (unlikely(obj->mode & GR_WRITE))
71298+ task->is_writable = 1;
71299+
71300+ gr_set_proc_res(task);
71301+
71302+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
71303+ 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);
71304+#endif
71305+ return 0;
71306+}
71307+
71308+/* always called with valid inodev ptr */
71309+static void
71310+do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
71311+{
71312+ struct acl_object_label *matchpo;
71313+ struct acl_subject_label *matchps;
71314+ struct acl_subject_label *subj;
71315+ struct acl_role_label *role;
71316+ unsigned int x;
71317+
71318+ FOR_EACH_ROLE_START(role)
71319+ FOR_EACH_SUBJECT_START(role, subj, x)
71320+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
71321+ matchpo->mode |= GR_DELETED;
71322+ FOR_EACH_SUBJECT_END(subj,x)
71323+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
71324+ /* nested subjects aren't in the role's subj_hash table */
71325+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
71326+ matchpo->mode |= GR_DELETED;
71327+ FOR_EACH_NESTED_SUBJECT_END(subj)
71328+ if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
71329+ matchps->mode |= GR_DELETED;
71330+ FOR_EACH_ROLE_END(role)
71331+
71332+ inodev->nentry->deleted = 1;
71333+
71334+ return;
71335+}
71336+
71337+void
71338+gr_handle_delete(const ino_t ino, const dev_t dev)
71339+{
71340+ struct inodev_entry *inodev;
71341+
71342+ if (unlikely(!(gr_status & GR_READY)))
71343+ return;
71344+
71345+ write_lock(&gr_inode_lock);
71346+ inodev = lookup_inodev_entry(ino, dev);
71347+ if (inodev != NULL)
71348+ do_handle_delete(inodev, ino, dev);
71349+ write_unlock(&gr_inode_lock);
71350+
71351+ return;
71352+}
71353+
71354+static void
71355+update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
71356+ const ino_t newinode, const dev_t newdevice,
71357+ struct acl_subject_label *subj)
71358+{
71359+ unsigned int index = gr_fhash(oldinode, olddevice, subj->obj_hash_size);
71360+ struct acl_object_label *match;
71361+
71362+ match = subj->obj_hash[index];
71363+
71364+ while (match && (match->inode != oldinode ||
71365+ match->device != olddevice ||
71366+ !(match->mode & GR_DELETED)))
71367+ match = match->next;
71368+
71369+ if (match && (match->inode == oldinode)
71370+ && (match->device == olddevice)
71371+ && (match->mode & GR_DELETED)) {
71372+ if (match->prev == NULL) {
71373+ subj->obj_hash[index] = match->next;
71374+ if (match->next != NULL)
71375+ match->next->prev = NULL;
71376+ } else {
71377+ match->prev->next = match->next;
71378+ if (match->next != NULL)
71379+ match->next->prev = match->prev;
71380+ }
71381+ match->prev = NULL;
71382+ match->next = NULL;
71383+ match->inode = newinode;
71384+ match->device = newdevice;
71385+ match->mode &= ~GR_DELETED;
71386+
71387+ insert_acl_obj_label(match, subj);
71388+ }
71389+
71390+ return;
71391+}
71392+
71393+static void
71394+update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
71395+ const ino_t newinode, const dev_t newdevice,
71396+ struct acl_role_label *role)
71397+{
71398+ unsigned int index = gr_fhash(oldinode, olddevice, role->subj_hash_size);
71399+ struct acl_subject_label *match;
71400+
71401+ match = role->subj_hash[index];
71402+
71403+ while (match && (match->inode != oldinode ||
71404+ match->device != olddevice ||
71405+ !(match->mode & GR_DELETED)))
71406+ match = match->next;
71407+
71408+ if (match && (match->inode == oldinode)
71409+ && (match->device == olddevice)
71410+ && (match->mode & GR_DELETED)) {
71411+ if (match->prev == NULL) {
71412+ role->subj_hash[index] = match->next;
71413+ if (match->next != NULL)
71414+ match->next->prev = NULL;
71415+ } else {
71416+ match->prev->next = match->next;
71417+ if (match->next != NULL)
71418+ match->next->prev = match->prev;
71419+ }
71420+ match->prev = NULL;
71421+ match->next = NULL;
71422+ match->inode = newinode;
71423+ match->device = newdevice;
71424+ match->mode &= ~GR_DELETED;
71425+
71426+ insert_acl_subj_label(match, role);
71427+ }
71428+
71429+ return;
71430+}
71431+
71432+static void
71433+update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
71434+ const ino_t newinode, const dev_t newdevice)
71435+{
71436+ unsigned int index = gr_fhash(oldinode, olddevice, running_polstate.inodev_set.i_size);
71437+ struct inodev_entry *match;
71438+
71439+ match = running_polstate.inodev_set.i_hash[index];
71440+
71441+ while (match && (match->nentry->inode != oldinode ||
71442+ match->nentry->device != olddevice || !match->nentry->deleted))
71443+ match = match->next;
71444+
71445+ if (match && (match->nentry->inode == oldinode)
71446+ && (match->nentry->device == olddevice) &&
71447+ match->nentry->deleted) {
71448+ if (match->prev == NULL) {
71449+ running_polstate.inodev_set.i_hash[index] = match->next;
71450+ if (match->next != NULL)
71451+ match->next->prev = NULL;
71452+ } else {
71453+ match->prev->next = match->next;
71454+ if (match->next != NULL)
71455+ match->next->prev = match->prev;
71456+ }
71457+ match->prev = NULL;
71458+ match->next = NULL;
71459+ match->nentry->inode = newinode;
71460+ match->nentry->device = newdevice;
71461+ match->nentry->deleted = 0;
71462+
71463+ insert_inodev_entry(match);
71464+ }
71465+
71466+ return;
71467+}
71468+
71469+static void
71470+__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
71471+{
71472+ struct acl_subject_label *subj;
71473+ struct acl_role_label *role;
71474+ unsigned int x;
71475+
71476+ FOR_EACH_ROLE_START(role)
71477+ update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
71478+
71479+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
71480+ if ((subj->inode == ino) && (subj->device == dev)) {
71481+ subj->inode = ino;
71482+ subj->device = dev;
71483+ }
71484+ /* nested subjects aren't in the role's subj_hash table */
71485+ update_acl_obj_label(matchn->inode, matchn->device,
71486+ ino, dev, subj);
71487+ FOR_EACH_NESTED_SUBJECT_END(subj)
71488+ FOR_EACH_SUBJECT_START(role, subj, x)
71489+ update_acl_obj_label(matchn->inode, matchn->device,
71490+ ino, dev, subj);
71491+ FOR_EACH_SUBJECT_END(subj,x)
71492+ FOR_EACH_ROLE_END(role)
71493+
71494+ update_inodev_entry(matchn->inode, matchn->device, ino, dev);
71495+
71496+ return;
71497+}
71498+
71499+static void
71500+do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
71501+ const struct vfsmount *mnt)
71502+{
71503+ ino_t ino = dentry->d_inode->i_ino;
71504+ dev_t dev = __get_dev(dentry);
71505+
71506+ __do_handle_create(matchn, ino, dev);
71507+
71508+ return;
71509+}
71510+
71511+void
71512+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
71513+{
71514+ struct name_entry *matchn;
71515+
71516+ if (unlikely(!(gr_status & GR_READY)))
71517+ return;
71518+
71519+ preempt_disable();
71520+ matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
71521+
71522+ if (unlikely((unsigned long)matchn)) {
71523+ write_lock(&gr_inode_lock);
71524+ do_handle_create(matchn, dentry, mnt);
71525+ write_unlock(&gr_inode_lock);
71526+ }
71527+ preempt_enable();
71528+
71529+ return;
71530+}
71531+
71532+void
71533+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
71534+{
71535+ struct name_entry *matchn;
71536+
71537+ if (unlikely(!(gr_status & GR_READY)))
71538+ return;
71539+
71540+ preempt_disable();
71541+ matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
71542+
71543+ if (unlikely((unsigned long)matchn)) {
71544+ write_lock(&gr_inode_lock);
71545+ __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
71546+ write_unlock(&gr_inode_lock);
71547+ }
71548+ preempt_enable();
71549+
71550+ return;
71551+}
71552+
71553+void
71554+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
71555+ struct dentry *old_dentry,
71556+ struct dentry *new_dentry,
71557+ struct vfsmount *mnt, const __u8 replace, unsigned int flags)
71558+{
71559+ struct name_entry *matchn;
71560+ struct name_entry *matchn2 = NULL;
71561+ struct inodev_entry *inodev;
71562+ struct inode *inode = new_dentry->d_inode;
71563+ ino_t old_ino = old_dentry->d_inode->i_ino;
71564+ dev_t old_dev = __get_dev(old_dentry);
71565+ unsigned int exchange = flags & RENAME_EXCHANGE;
71566+
71567+ /* vfs_rename swaps the name and parent link for old_dentry and
71568+ new_dentry
71569+ at this point, old_dentry has the new name, parent link, and inode
71570+ for the renamed file
71571+ if a file is being replaced by a rename, new_dentry has the inode
71572+ and name for the replaced file
71573+ */
71574+
71575+ if (unlikely(!(gr_status & GR_READY)))
71576+ return;
71577+
71578+ preempt_disable();
71579+ matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
71580+
71581+ /* exchange cases:
71582+ a filename exists for the source, but not dest
71583+ do a recreate on source
71584+ a filename exists for the dest, but not source
71585+ do a recreate on dest
71586+ a filename exists for both source and dest
71587+ delete source and dest, then create source and dest
71588+ a filename exists for neither source nor dest
71589+ no updates needed
71590+
71591+ the name entry lookups get us the old inode/dev associated with
71592+ each name, so do the deletes first (if possible) so that when
71593+ we do the create, we pick up on the right entries
71594+ */
71595+
71596+ if (exchange)
71597+ matchn2 = lookup_name_entry(gr_to_filename_rbac(new_dentry, mnt));
71598+
71599+ /* we wouldn't have to check d_inode if it weren't for
71600+ NFS silly-renaming
71601+ */
71602+
71603+ write_lock(&gr_inode_lock);
71604+ if (unlikely((replace || exchange) && inode)) {
71605+ ino_t new_ino = inode->i_ino;
71606+ dev_t new_dev = __get_dev(new_dentry);
71607+
71608+ inodev = lookup_inodev_entry(new_ino, new_dev);
71609+ if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
71610+ do_handle_delete(inodev, new_ino, new_dev);
71611+ }
71612+
71613+ inodev = lookup_inodev_entry(old_ino, old_dev);
71614+ if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
71615+ do_handle_delete(inodev, old_ino, old_dev);
71616+
71617+ if (unlikely(matchn != NULL))
71618+ do_handle_create(matchn, old_dentry, mnt);
71619+
71620+ if (unlikely(matchn2 != NULL))
71621+ do_handle_create(matchn2, new_dentry, mnt);
71622+
71623+ write_unlock(&gr_inode_lock);
71624+ preempt_enable();
71625+
71626+ return;
71627+}
71628+
71629+#if defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC)
71630+static const unsigned long res_learn_bumps[GR_NLIMITS] = {
71631+ [RLIMIT_CPU] = GR_RLIM_CPU_BUMP,
71632+ [RLIMIT_FSIZE] = GR_RLIM_FSIZE_BUMP,
71633+ [RLIMIT_DATA] = GR_RLIM_DATA_BUMP,
71634+ [RLIMIT_STACK] = GR_RLIM_STACK_BUMP,
71635+ [RLIMIT_CORE] = GR_RLIM_CORE_BUMP,
71636+ [RLIMIT_RSS] = GR_RLIM_RSS_BUMP,
71637+ [RLIMIT_NPROC] = GR_RLIM_NPROC_BUMP,
71638+ [RLIMIT_NOFILE] = GR_RLIM_NOFILE_BUMP,
71639+ [RLIMIT_MEMLOCK] = GR_RLIM_MEMLOCK_BUMP,
71640+ [RLIMIT_AS] = GR_RLIM_AS_BUMP,
71641+ [RLIMIT_LOCKS] = GR_RLIM_LOCKS_BUMP,
71642+ [RLIMIT_SIGPENDING] = GR_RLIM_SIGPENDING_BUMP,
71643+ [RLIMIT_MSGQUEUE] = GR_RLIM_MSGQUEUE_BUMP,
71644+ [RLIMIT_NICE] = GR_RLIM_NICE_BUMP,
71645+ [RLIMIT_RTPRIO] = GR_RLIM_RTPRIO_BUMP,
71646+ [RLIMIT_RTTIME] = GR_RLIM_RTTIME_BUMP
71647+};
71648+
71649+void
71650+gr_learn_resource(const struct task_struct *task,
71651+ const int res, const unsigned long wanted, const int gt)
71652+{
71653+ struct acl_subject_label *acl;
71654+ const struct cred *cred;
71655+
71656+ if (unlikely((gr_status & GR_READY) &&
71657+ task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
71658+ goto skip_reslog;
71659+
71660+ gr_log_resource(task, res, wanted, gt);
71661+skip_reslog:
71662+
71663+ if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
71664+ return;
71665+
71666+ acl = task->acl;
71667+
71668+ if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
71669+ !(acl->resmask & (1U << (unsigned short) res))))
71670+ return;
71671+
71672+ if (wanted >= acl->res[res].rlim_cur) {
71673+ unsigned long res_add;
71674+
71675+ res_add = wanted + res_learn_bumps[res];
71676+
71677+ acl->res[res].rlim_cur = res_add;
71678+
71679+ if (wanted > acl->res[res].rlim_max)
71680+ acl->res[res].rlim_max = res_add;
71681+
71682+ /* only log the subject filename, since resource logging is supported for
71683+ single-subject learning only */
71684+ rcu_read_lock();
71685+ cred = __task_cred(task);
71686+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
71687+ task->role->roletype, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), acl->filename,
71688+ acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
71689+ "", (unsigned long) res, &task->signal->saved_ip);
71690+ rcu_read_unlock();
71691+ }
71692+
71693+ return;
71694+}
71695+EXPORT_SYMBOL_GPL(gr_learn_resource);
71696+#endif
71697+
71698+#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
71699+void
71700+pax_set_initial_flags(struct linux_binprm *bprm)
71701+{
71702+ struct task_struct *task = current;
71703+ struct acl_subject_label *proc;
71704+ unsigned long flags;
71705+
71706+ if (unlikely(!(gr_status & GR_READY)))
71707+ return;
71708+
71709+ flags = pax_get_flags(task);
71710+
71711+ proc = task->acl;
71712+
71713+ if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
71714+ flags &= ~MF_PAX_PAGEEXEC;
71715+ if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
71716+ flags &= ~MF_PAX_SEGMEXEC;
71717+ if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
71718+ flags &= ~MF_PAX_RANDMMAP;
71719+ if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
71720+ flags &= ~MF_PAX_EMUTRAMP;
71721+ if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
71722+ flags &= ~MF_PAX_MPROTECT;
71723+
71724+ if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
71725+ flags |= MF_PAX_PAGEEXEC;
71726+ if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
71727+ flags |= MF_PAX_SEGMEXEC;
71728+ if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
71729+ flags |= MF_PAX_RANDMMAP;
71730+ if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
71731+ flags |= MF_PAX_EMUTRAMP;
71732+ if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
71733+ flags |= MF_PAX_MPROTECT;
71734+
71735+ pax_set_flags(task, flags);
71736+
71737+ return;
71738+}
71739+#endif
71740+
71741+int
71742+gr_handle_proc_ptrace(struct task_struct *task)
71743+{
71744+ struct file *filp;
71745+ struct task_struct *tmp = task;
71746+ struct task_struct *curtemp = current;
71747+ __u32 retmode;
71748+
71749+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
71750+ if (unlikely(!(gr_status & GR_READY)))
71751+ return 0;
71752+#endif
71753+
71754+ read_lock(&tasklist_lock);
71755+ read_lock(&grsec_exec_file_lock);
71756+ filp = task->exec_file;
71757+
71758+ while (task_pid_nr(tmp) > 0) {
71759+ if (tmp == curtemp)
71760+ break;
71761+ tmp = tmp->real_parent;
71762+ }
71763+
71764+ if (!filp || (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
71765+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
71766+ read_unlock(&grsec_exec_file_lock);
71767+ read_unlock(&tasklist_lock);
71768+ return 1;
71769+ }
71770+
71771+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
71772+ if (!(gr_status & GR_READY)) {
71773+ read_unlock(&grsec_exec_file_lock);
71774+ read_unlock(&tasklist_lock);
71775+ return 0;
71776+ }
71777+#endif
71778+
71779+ retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
71780+ read_unlock(&grsec_exec_file_lock);
71781+ read_unlock(&tasklist_lock);
71782+
71783+ if (retmode & GR_NOPTRACE)
71784+ return 1;
71785+
71786+ if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
71787+ && (current->acl != task->acl || (current->acl != current->role->root_label
71788+ && task_pid_nr(current) != task_pid_nr(task))))
71789+ return 1;
71790+
71791+ return 0;
71792+}
71793+
71794+void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
71795+{
71796+ if (unlikely(!(gr_status & GR_READY)))
71797+ return;
71798+
71799+ if (!(current->role->roletype & GR_ROLE_GOD))
71800+ return;
71801+
71802+ seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
71803+ p->role->rolename, gr_task_roletype_to_char(p),
71804+ p->acl->filename);
71805+}
71806+
71807+int
71808+gr_handle_ptrace(struct task_struct *task, const long request)
71809+{
71810+ struct task_struct *tmp = task;
71811+ struct task_struct *curtemp = current;
71812+ __u32 retmode;
71813+
71814+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
71815+ if (unlikely(!(gr_status & GR_READY)))
71816+ return 0;
71817+#endif
71818+ if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
71819+ read_lock(&tasklist_lock);
71820+ while (task_pid_nr(tmp) > 0) {
71821+ if (tmp == curtemp)
71822+ break;
71823+ tmp = tmp->real_parent;
71824+ }
71825+
71826+ if (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
71827+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
71828+ read_unlock(&tasklist_lock);
71829+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
71830+ return 1;
71831+ }
71832+ read_unlock(&tasklist_lock);
71833+ }
71834+
71835+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
71836+ if (!(gr_status & GR_READY))
71837+ return 0;
71838+#endif
71839+
71840+ read_lock(&grsec_exec_file_lock);
71841+ if (unlikely(!task->exec_file)) {
71842+ read_unlock(&grsec_exec_file_lock);
71843+ return 0;
71844+ }
71845+
71846+ retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
71847+ read_unlock(&grsec_exec_file_lock);
71848+
71849+ if (retmode & GR_NOPTRACE) {
71850+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
71851+ return 1;
71852+ }
71853+
71854+ if (retmode & GR_PTRACERD) {
71855+ switch (request) {
71856+ case PTRACE_SEIZE:
71857+ case PTRACE_POKETEXT:
71858+ case PTRACE_POKEDATA:
71859+ case PTRACE_POKEUSR:
71860+#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
71861+ case PTRACE_SETREGS:
71862+ case PTRACE_SETFPREGS:
71863+#endif
71864+#ifdef CONFIG_X86
71865+ case PTRACE_SETFPXREGS:
71866+#endif
71867+#ifdef CONFIG_ALTIVEC
71868+ case PTRACE_SETVRREGS:
71869+#endif
71870+ return 1;
71871+ default:
71872+ return 0;
71873+ }
71874+ } else if (!(current->acl->mode & GR_POVERRIDE) &&
71875+ !(current->role->roletype & GR_ROLE_GOD) &&
71876+ (current->acl != task->acl)) {
71877+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
71878+ return 1;
71879+ }
71880+
71881+ return 0;
71882+}
71883+
71884+static int is_writable_mmap(const struct file *filp)
71885+{
71886+ struct task_struct *task = current;
71887+ struct acl_object_label *obj, *obj2;
71888+
71889+ if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
71890+ !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))) {
71891+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
71892+ obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
71893+ task->role->root_label);
71894+ if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
71895+ gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
71896+ return 1;
71897+ }
71898+ }
71899+ return 0;
71900+}
71901+
71902+int
71903+gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
71904+{
71905+ __u32 mode;
71906+
71907+ if (unlikely(!file || !(prot & PROT_EXEC)))
71908+ return 1;
71909+
71910+ if (is_writable_mmap(file))
71911+ return 0;
71912+
71913+ mode =
71914+ gr_search_file(file->f_path.dentry,
71915+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
71916+ file->f_path.mnt);
71917+
71918+ if (!gr_tpe_allow(file))
71919+ return 0;
71920+
71921+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
71922+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
71923+ return 0;
71924+ } else if (unlikely(!(mode & GR_EXEC))) {
71925+ return 0;
71926+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
71927+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
71928+ return 1;
71929+ }
71930+
71931+ return 1;
71932+}
71933+
71934+int
71935+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
71936+{
71937+ __u32 mode;
71938+
71939+ if (unlikely(!file || !(prot & PROT_EXEC)))
71940+ return 1;
71941+
71942+ if (is_writable_mmap(file))
71943+ return 0;
71944+
71945+ mode =
71946+ gr_search_file(file->f_path.dentry,
71947+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
71948+ file->f_path.mnt);
71949+
71950+ if (!gr_tpe_allow(file))
71951+ return 0;
71952+
71953+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
71954+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
71955+ return 0;
71956+ } else if (unlikely(!(mode & GR_EXEC))) {
71957+ return 0;
71958+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
71959+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
71960+ return 1;
71961+ }
71962+
71963+ return 1;
71964+}
71965+
71966+void
71967+gr_acl_handle_psacct(struct task_struct *task, const long code)
71968+{
71969+ unsigned long runtime, cputime;
71970+ cputime_t utime, stime;
71971+ unsigned int wday, cday;
71972+ __u8 whr, chr;
71973+ __u8 wmin, cmin;
71974+ __u8 wsec, csec;
71975+ struct timespec curtime, starttime;
71976+
71977+ if (unlikely(!(gr_status & GR_READY) || !task->acl ||
71978+ !(task->acl->mode & GR_PROCACCT)))
71979+ return;
71980+
71981+ curtime = ns_to_timespec(ktime_get_ns());
71982+ starttime = ns_to_timespec(task->start_time);
71983+ runtime = curtime.tv_sec - starttime.tv_sec;
71984+ wday = runtime / (60 * 60 * 24);
71985+ runtime -= wday * (60 * 60 * 24);
71986+ whr = runtime / (60 * 60);
71987+ runtime -= whr * (60 * 60);
71988+ wmin = runtime / 60;
71989+ runtime -= wmin * 60;
71990+ wsec = runtime;
71991+
71992+ task_cputime(task, &utime, &stime);
71993+ cputime = cputime_to_secs(utime + stime);
71994+ cday = cputime / (60 * 60 * 24);
71995+ cputime -= cday * (60 * 60 * 24);
71996+ chr = cputime / (60 * 60);
71997+ cputime -= chr * (60 * 60);
71998+ cmin = cputime / 60;
71999+ cputime -= cmin * 60;
72000+ csec = cputime;
72001+
72002+ gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
72003+
72004+ return;
72005+}
72006+
72007+#ifdef CONFIG_TASKSTATS
72008+int gr_is_taskstats_denied(int pid)
72009+{
72010+ struct task_struct *task;
72011+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
72012+ const struct cred *cred;
72013+#endif
72014+ int ret = 0;
72015+
72016+ /* restrict taskstats viewing to un-chrooted root users
72017+ who have the 'view' subject flag if the RBAC system is enabled
72018+ */
72019+
72020+ rcu_read_lock();
72021+ read_lock(&tasklist_lock);
72022+ task = find_task_by_vpid(pid);
72023+ if (task) {
72024+#ifdef CONFIG_GRKERNSEC_CHROOT
72025+ if (proc_is_chrooted(task))
72026+ ret = -EACCES;
72027+#endif
72028+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
72029+ cred = __task_cred(task);
72030+#ifdef CONFIG_GRKERNSEC_PROC_USER
72031+ if (gr_is_global_nonroot(cred->uid))
72032+ ret = -EACCES;
72033+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
72034+ if (gr_is_global_nonroot(cred->uid) && !groups_search(cred->group_info, grsec_proc_gid))
72035+ ret = -EACCES;
72036+#endif
72037+#endif
72038+ if (gr_status & GR_READY) {
72039+ if (!(task->acl->mode & GR_VIEW))
72040+ ret = -EACCES;
72041+ }
72042+ } else
72043+ ret = -ENOENT;
72044+
72045+ read_unlock(&tasklist_lock);
72046+ rcu_read_unlock();
72047+
72048+ return ret;
72049+}
72050+#endif
72051+
72052+/* AUXV entries are filled via a descendant of search_binary_handler
72053+ after we've already applied the subject for the target
72054+*/
72055+int gr_acl_enable_at_secure(void)
72056+{
72057+ if (unlikely(!(gr_status & GR_READY)))
72058+ return 0;
72059+
72060+ if (current->acl->mode & GR_ATSECURE)
72061+ return 1;
72062+
72063+ return 0;
72064+}
72065+
72066+int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
72067+{
72068+ struct task_struct *task = current;
72069+ struct dentry *dentry = file->f_path.dentry;
72070+ struct vfsmount *mnt = file->f_path.mnt;
72071+ struct acl_object_label *obj, *tmp;
72072+ struct acl_subject_label *subj;
72073+ unsigned int bufsize;
72074+ int is_not_root;
72075+ char *path;
72076+ dev_t dev = __get_dev(dentry);
72077+
72078+ if (unlikely(!(gr_status & GR_READY)))
72079+ return 1;
72080+
72081+ if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
72082+ return 1;
72083+
72084+ /* ignore Eric Biederman */
72085+ if (IS_PRIVATE(dentry->d_inode))
72086+ return 1;
72087+
72088+ subj = task->acl;
72089+ read_lock(&gr_inode_lock);
72090+ do {
72091+ obj = lookup_acl_obj_label(ino, dev, subj);
72092+ if (obj != NULL) {
72093+ read_unlock(&gr_inode_lock);
72094+ return (obj->mode & GR_FIND) ? 1 : 0;
72095+ }
72096+ } while ((subj = subj->parent_subject));
72097+ read_unlock(&gr_inode_lock);
72098+
72099+ /* this is purely an optimization since we're looking for an object
72100+ for the directory we're doing a readdir on
72101+ if it's possible for any globbed object to match the entry we're
72102+ filling into the directory, then the object we find here will be
72103+ an anchor point with attached globbed objects
72104+ */
72105+ obj = chk_obj_label_noglob(dentry, mnt, task->acl);
72106+ if (obj->globbed == NULL)
72107+ return (obj->mode & GR_FIND) ? 1 : 0;
72108+
72109+ is_not_root = ((obj->filename[0] == '/') &&
72110+ (obj->filename[1] == '\0')) ? 0 : 1;
72111+ bufsize = PAGE_SIZE - namelen - is_not_root;
72112+
72113+ /* check bufsize > PAGE_SIZE || bufsize == 0 */
72114+ if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
72115+ return 1;
72116+
72117+ preempt_disable();
72118+ path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
72119+ bufsize);
72120+
72121+ bufsize = strlen(path);
72122+
72123+ /* if base is "/", don't append an additional slash */
72124+ if (is_not_root)
72125+ *(path + bufsize) = '/';
72126+ memcpy(path + bufsize + is_not_root, name, namelen);
72127+ *(path + bufsize + namelen + is_not_root) = '\0';
72128+
72129+ tmp = obj->globbed;
72130+ while (tmp) {
72131+ if (!glob_match(tmp->filename, path)) {
72132+ preempt_enable();
72133+ return (tmp->mode & GR_FIND) ? 1 : 0;
72134+ }
72135+ tmp = tmp->next;
72136+ }
72137+ preempt_enable();
72138+ return (obj->mode & GR_FIND) ? 1 : 0;
72139+}
72140+
72141+void gr_put_exec_file(struct task_struct *task)
72142+{
72143+ struct file *filp;
72144+
72145+ write_lock(&grsec_exec_file_lock);
72146+ filp = task->exec_file;
72147+ task->exec_file = NULL;
72148+ write_unlock(&grsec_exec_file_lock);
72149+
72150+ if (filp)
72151+ fput(filp);
72152+
72153+ return;
72154+}
72155+
72156+
72157+#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
72158+EXPORT_SYMBOL_GPL(gr_acl_is_enabled);
72159+#endif
72160+#ifdef CONFIG_SECURITY
72161+EXPORT_SYMBOL_GPL(gr_check_user_change);
72162+EXPORT_SYMBOL_GPL(gr_check_group_change);
72163+#endif
72164+
72165diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
72166new file mode 100644
72167index 0000000..18ffbbd
72168--- /dev/null
72169+++ b/grsecurity/gracl_alloc.c
72170@@ -0,0 +1,105 @@
72171+#include <linux/kernel.h>
72172+#include <linux/mm.h>
72173+#include <linux/slab.h>
72174+#include <linux/vmalloc.h>
72175+#include <linux/gracl.h>
72176+#include <linux/grsecurity.h>
72177+
72178+static struct gr_alloc_state __current_alloc_state = { 1, 1, NULL };
72179+struct gr_alloc_state *current_alloc_state = &__current_alloc_state;
72180+
72181+static __inline__ int
72182+alloc_pop(void)
72183+{
72184+ if (current_alloc_state->alloc_stack_next == 1)
72185+ return 0;
72186+
72187+ kfree(current_alloc_state->alloc_stack[current_alloc_state->alloc_stack_next - 2]);
72188+
72189+ current_alloc_state->alloc_stack_next--;
72190+
72191+ return 1;
72192+}
72193+
72194+static __inline__ int
72195+alloc_push(void *buf)
72196+{
72197+ if (current_alloc_state->alloc_stack_next >= current_alloc_state->alloc_stack_size)
72198+ return 1;
72199+
72200+ current_alloc_state->alloc_stack[current_alloc_state->alloc_stack_next - 1] = buf;
72201+
72202+ current_alloc_state->alloc_stack_next++;
72203+
72204+ return 0;
72205+}
72206+
72207+void *
72208+acl_alloc(unsigned long len)
72209+{
72210+ void *ret = NULL;
72211+
72212+ if (!len || len > PAGE_SIZE)
72213+ goto out;
72214+
72215+ ret = kmalloc(len, GFP_KERNEL);
72216+
72217+ if (ret) {
72218+ if (alloc_push(ret)) {
72219+ kfree(ret);
72220+ ret = NULL;
72221+ }
72222+ }
72223+
72224+out:
72225+ return ret;
72226+}
72227+
72228+void *
72229+acl_alloc_num(unsigned long num, unsigned long len)
72230+{
72231+ if (!len || (num > (PAGE_SIZE / len)))
72232+ return NULL;
72233+
72234+ return acl_alloc(num * len);
72235+}
72236+
72237+void
72238+acl_free_all(void)
72239+{
72240+ if (!current_alloc_state->alloc_stack)
72241+ return;
72242+
72243+ while (alloc_pop()) ;
72244+
72245+ if (current_alloc_state->alloc_stack) {
72246+ if ((current_alloc_state->alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
72247+ kfree(current_alloc_state->alloc_stack);
72248+ else
72249+ vfree(current_alloc_state->alloc_stack);
72250+ }
72251+
72252+ current_alloc_state->alloc_stack = NULL;
72253+ current_alloc_state->alloc_stack_size = 1;
72254+ current_alloc_state->alloc_stack_next = 1;
72255+
72256+ return;
72257+}
72258+
72259+int
72260+acl_alloc_stack_init(unsigned long size)
72261+{
72262+ if ((size * sizeof (void *)) <= PAGE_SIZE)
72263+ current_alloc_state->alloc_stack =
72264+ (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
72265+ else
72266+ current_alloc_state->alloc_stack = (void **) vmalloc(size * sizeof (void *));
72267+
72268+ current_alloc_state->alloc_stack_size = size;
72269+ current_alloc_state->alloc_stack_next = 1;
72270+
72271+ if (!current_alloc_state->alloc_stack)
72272+ return 0;
72273+ else
72274+ return 1;
72275+}
72276diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
72277new file mode 100644
72278index 0000000..1a94c11
72279--- /dev/null
72280+++ b/grsecurity/gracl_cap.c
72281@@ -0,0 +1,127 @@
72282+#include <linux/kernel.h>
72283+#include <linux/module.h>
72284+#include <linux/sched.h>
72285+#include <linux/gracl.h>
72286+#include <linux/grsecurity.h>
72287+#include <linux/grinternal.h>
72288+
72289+extern const char *captab_log[];
72290+extern int captab_log_entries;
72291+
72292+int gr_learn_cap(const struct task_struct *task, const struct cred *cred, const int cap)
72293+{
72294+ struct acl_subject_label *curracl;
72295+
72296+ if (!gr_acl_is_enabled())
72297+ return 1;
72298+
72299+ curracl = task->acl;
72300+
72301+ if (curracl->mode & (GR_LEARN | GR_INHERITLEARN)) {
72302+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
72303+ task->role->roletype, GR_GLOBAL_UID(cred->uid),
72304+ GR_GLOBAL_GID(cred->gid), task->exec_file ?
72305+ gr_to_filename(task->exec_file->f_path.dentry,
72306+ task->exec_file->f_path.mnt) : curracl->filename,
72307+ curracl->filename, 0UL,
72308+ 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
72309+ return 1;
72310+ }
72311+
72312+ return 0;
72313+}
72314+
72315+int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
72316+{
72317+ struct acl_subject_label *curracl;
72318+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
72319+ kernel_cap_t cap_audit = __cap_empty_set;
72320+
72321+ if (!gr_acl_is_enabled())
72322+ return 1;
72323+
72324+ curracl = task->acl;
72325+
72326+ cap_drop = curracl->cap_lower;
72327+ cap_mask = curracl->cap_mask;
72328+ cap_audit = curracl->cap_invert_audit;
72329+
72330+ while ((curracl = curracl->parent_subject)) {
72331+ /* if the cap isn't specified in the current computed mask but is specified in the
72332+ current level subject, and is lowered in the current level subject, then add
72333+ it to the set of dropped capabilities
72334+ otherwise, add the current level subject's mask to the current computed mask
72335+ */
72336+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
72337+ cap_raise(cap_mask, cap);
72338+ if (cap_raised(curracl->cap_lower, cap))
72339+ cap_raise(cap_drop, cap);
72340+ if (cap_raised(curracl->cap_invert_audit, cap))
72341+ cap_raise(cap_audit, cap);
72342+ }
72343+ }
72344+
72345+ if (!cap_raised(cap_drop, cap)) {
72346+ if (cap_raised(cap_audit, cap))
72347+ gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
72348+ return 1;
72349+ }
72350+
72351+ /* only learn the capability use if the process has the capability in the
72352+ general case, the two uses in sys.c of gr_learn_cap are an exception
72353+ to this rule to ensure any role transition involves what the full-learned
72354+ policy believes in a privileged process
72355+ */
72356+ if (cap_raised(cred->cap_effective, cap) && gr_learn_cap(task, cred, cap))
72357+ return 1;
72358+
72359+ if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
72360+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
72361+
72362+ return 0;
72363+}
72364+
72365+int
72366+gr_acl_is_capable(const int cap)
72367+{
72368+ return gr_task_acl_is_capable(current, current_cred(), cap);
72369+}
72370+
72371+int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
72372+{
72373+ struct acl_subject_label *curracl;
72374+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
72375+
72376+ if (!gr_acl_is_enabled())
72377+ return 1;
72378+
72379+ curracl = task->acl;
72380+
72381+ cap_drop = curracl->cap_lower;
72382+ cap_mask = curracl->cap_mask;
72383+
72384+ while ((curracl = curracl->parent_subject)) {
72385+ /* if the cap isn't specified in the current computed mask but is specified in the
72386+ current level subject, and is lowered in the current level subject, then add
72387+ it to the set of dropped capabilities
72388+ otherwise, add the current level subject's mask to the current computed mask
72389+ */
72390+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
72391+ cap_raise(cap_mask, cap);
72392+ if (cap_raised(curracl->cap_lower, cap))
72393+ cap_raise(cap_drop, cap);
72394+ }
72395+ }
72396+
72397+ if (!cap_raised(cap_drop, cap))
72398+ return 1;
72399+
72400+ return 0;
72401+}
72402+
72403+int
72404+gr_acl_is_capable_nolog(const int cap)
72405+{
72406+ return gr_task_acl_is_capable_nolog(current, cap);
72407+}
72408+
72409diff --git a/grsecurity/gracl_compat.c b/grsecurity/gracl_compat.c
72410new file mode 100644
72411index 0000000..ca25605
72412--- /dev/null
72413+++ b/grsecurity/gracl_compat.c
72414@@ -0,0 +1,270 @@
72415+#include <linux/kernel.h>
72416+#include <linux/gracl.h>
72417+#include <linux/compat.h>
72418+#include <linux/gracl_compat.h>
72419+
72420+#include <asm/uaccess.h>
72421+
72422+int copy_gr_arg_wrapper_compat(const char *buf, struct gr_arg_wrapper *uwrap)
72423+{
72424+ struct gr_arg_wrapper_compat uwrapcompat;
72425+
72426+ if (copy_from_user(&uwrapcompat, buf, sizeof(uwrapcompat)))
72427+ return -EFAULT;
72428+
72429+ if (((uwrapcompat.version != GRSECURITY_VERSION) &&
72430+ (uwrapcompat.version != 0x2901)) ||
72431+ (uwrapcompat.size != sizeof(struct gr_arg_compat)))
72432+ return -EINVAL;
72433+
72434+ uwrap->arg = compat_ptr(uwrapcompat.arg);
72435+ uwrap->version = uwrapcompat.version;
72436+ uwrap->size = sizeof(struct gr_arg);
72437+
72438+ return 0;
72439+}
72440+
72441+int copy_gr_arg_compat(const struct gr_arg __user *buf, struct gr_arg *arg)
72442+{
72443+ struct gr_arg_compat argcompat;
72444+
72445+ if (copy_from_user(&argcompat, buf, sizeof(argcompat)))
72446+ return -EFAULT;
72447+
72448+ arg->role_db.r_table = compat_ptr(argcompat.role_db.r_table);
72449+ arg->role_db.num_pointers = argcompat.role_db.num_pointers;
72450+ arg->role_db.num_roles = argcompat.role_db.num_roles;
72451+ arg->role_db.num_domain_children = argcompat.role_db.num_domain_children;
72452+ arg->role_db.num_subjects = argcompat.role_db.num_subjects;
72453+ arg->role_db.num_objects = argcompat.role_db.num_objects;
72454+
72455+ memcpy(&arg->pw, &argcompat.pw, sizeof(arg->pw));
72456+ memcpy(&arg->salt, &argcompat.salt, sizeof(arg->salt));
72457+ memcpy(&arg->sum, &argcompat.sum, sizeof(arg->sum));
72458+ memcpy(&arg->sp_role, &argcompat.sp_role, sizeof(arg->sp_role));
72459+ arg->sprole_pws = compat_ptr(argcompat.sprole_pws);
72460+ arg->segv_device = argcompat.segv_device;
72461+ arg->segv_inode = argcompat.segv_inode;
72462+ arg->segv_uid = argcompat.segv_uid;
72463+ arg->num_sprole_pws = argcompat.num_sprole_pws;
72464+ arg->mode = argcompat.mode;
72465+
72466+ return 0;
72467+}
72468+
72469+int copy_acl_object_label_compat(struct acl_object_label *obj, const struct acl_object_label *userp)
72470+{
72471+ struct acl_object_label_compat objcompat;
72472+
72473+ if (copy_from_user(&objcompat, userp, sizeof(objcompat)))
72474+ return -EFAULT;
72475+
72476+ obj->filename = compat_ptr(objcompat.filename);
72477+ obj->inode = objcompat.inode;
72478+ obj->device = objcompat.device;
72479+ obj->mode = objcompat.mode;
72480+
72481+ obj->nested = compat_ptr(objcompat.nested);
72482+ obj->globbed = compat_ptr(objcompat.globbed);
72483+
72484+ obj->prev = compat_ptr(objcompat.prev);
72485+ obj->next = compat_ptr(objcompat.next);
72486+
72487+ return 0;
72488+}
72489+
72490+int copy_acl_subject_label_compat(struct acl_subject_label *subj, const struct acl_subject_label *userp)
72491+{
72492+ unsigned int i;
72493+ struct acl_subject_label_compat subjcompat;
72494+
72495+ if (copy_from_user(&subjcompat, userp, sizeof(subjcompat)))
72496+ return -EFAULT;
72497+
72498+ subj->filename = compat_ptr(subjcompat.filename);
72499+ subj->inode = subjcompat.inode;
72500+ subj->device = subjcompat.device;
72501+ subj->mode = subjcompat.mode;
72502+ subj->cap_mask = subjcompat.cap_mask;
72503+ subj->cap_lower = subjcompat.cap_lower;
72504+ subj->cap_invert_audit = subjcompat.cap_invert_audit;
72505+
72506+ for (i = 0; i < GR_NLIMITS; i++) {
72507+ if (subjcompat.res[i].rlim_cur == COMPAT_RLIM_INFINITY)
72508+ subj->res[i].rlim_cur = RLIM_INFINITY;
72509+ else
72510+ subj->res[i].rlim_cur = subjcompat.res[i].rlim_cur;
72511+ if (subjcompat.res[i].rlim_max == COMPAT_RLIM_INFINITY)
72512+ subj->res[i].rlim_max = RLIM_INFINITY;
72513+ else
72514+ subj->res[i].rlim_max = subjcompat.res[i].rlim_max;
72515+ }
72516+ subj->resmask = subjcompat.resmask;
72517+
72518+ subj->user_trans_type = subjcompat.user_trans_type;
72519+ subj->group_trans_type = subjcompat.group_trans_type;
72520+ subj->user_transitions = compat_ptr(subjcompat.user_transitions);
72521+ subj->group_transitions = compat_ptr(subjcompat.group_transitions);
72522+ subj->user_trans_num = subjcompat.user_trans_num;
72523+ subj->group_trans_num = subjcompat.group_trans_num;
72524+
72525+ memcpy(&subj->sock_families, &subjcompat.sock_families, sizeof(subj->sock_families));
72526+ memcpy(&subj->ip_proto, &subjcompat.ip_proto, sizeof(subj->ip_proto));
72527+ subj->ip_type = subjcompat.ip_type;
72528+ subj->ips = compat_ptr(subjcompat.ips);
72529+ subj->ip_num = subjcompat.ip_num;
72530+ subj->inaddr_any_override = subjcompat.inaddr_any_override;
72531+
72532+ subj->crashes = subjcompat.crashes;
72533+ subj->expires = subjcompat.expires;
72534+
72535+ subj->parent_subject = compat_ptr(subjcompat.parent_subject);
72536+ subj->hash = compat_ptr(subjcompat.hash);
72537+ subj->prev = compat_ptr(subjcompat.prev);
72538+ subj->next = compat_ptr(subjcompat.next);
72539+
72540+ subj->obj_hash = compat_ptr(subjcompat.obj_hash);
72541+ subj->obj_hash_size = subjcompat.obj_hash_size;
72542+ subj->pax_flags = subjcompat.pax_flags;
72543+
72544+ return 0;
72545+}
72546+
72547+int copy_acl_role_label_compat(struct acl_role_label *role, const struct acl_role_label *userp)
72548+{
72549+ struct acl_role_label_compat rolecompat;
72550+
72551+ if (copy_from_user(&rolecompat, userp, sizeof(rolecompat)))
72552+ return -EFAULT;
72553+
72554+ role->rolename = compat_ptr(rolecompat.rolename);
72555+ role->uidgid = rolecompat.uidgid;
72556+ role->roletype = rolecompat.roletype;
72557+
72558+ role->auth_attempts = rolecompat.auth_attempts;
72559+ role->expires = rolecompat.expires;
72560+
72561+ role->root_label = compat_ptr(rolecompat.root_label);
72562+ role->hash = compat_ptr(rolecompat.hash);
72563+
72564+ role->prev = compat_ptr(rolecompat.prev);
72565+ role->next = compat_ptr(rolecompat.next);
72566+
72567+ role->transitions = compat_ptr(rolecompat.transitions);
72568+ role->allowed_ips = compat_ptr(rolecompat.allowed_ips);
72569+ role->domain_children = compat_ptr(rolecompat.domain_children);
72570+ role->domain_child_num = rolecompat.domain_child_num;
72571+
72572+ role->umask = rolecompat.umask;
72573+
72574+ role->subj_hash = compat_ptr(rolecompat.subj_hash);
72575+ role->subj_hash_size = rolecompat.subj_hash_size;
72576+
72577+ return 0;
72578+}
72579+
72580+int copy_role_allowed_ip_compat(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp)
72581+{
72582+ struct role_allowed_ip_compat roleip_compat;
72583+
72584+ if (copy_from_user(&roleip_compat, userp, sizeof(roleip_compat)))
72585+ return -EFAULT;
72586+
72587+ roleip->addr = roleip_compat.addr;
72588+ roleip->netmask = roleip_compat.netmask;
72589+
72590+ roleip->prev = compat_ptr(roleip_compat.prev);
72591+ roleip->next = compat_ptr(roleip_compat.next);
72592+
72593+ return 0;
72594+}
72595+
72596+int copy_role_transition_compat(struct role_transition *trans, const struct role_transition *userp)
72597+{
72598+ struct role_transition_compat trans_compat;
72599+
72600+ if (copy_from_user(&trans_compat, userp, sizeof(trans_compat)))
72601+ return -EFAULT;
72602+
72603+ trans->rolename = compat_ptr(trans_compat.rolename);
72604+
72605+ trans->prev = compat_ptr(trans_compat.prev);
72606+ trans->next = compat_ptr(trans_compat.next);
72607+
72608+ return 0;
72609+
72610+}
72611+
72612+int copy_gr_hash_struct_compat(struct gr_hash_struct *hash, const struct gr_hash_struct *userp)
72613+{
72614+ struct gr_hash_struct_compat hash_compat;
72615+
72616+ if (copy_from_user(&hash_compat, userp, sizeof(hash_compat)))
72617+ return -EFAULT;
72618+
72619+ hash->table = compat_ptr(hash_compat.table);
72620+ hash->nametable = compat_ptr(hash_compat.nametable);
72621+ hash->first = compat_ptr(hash_compat.first);
72622+
72623+ hash->table_size = hash_compat.table_size;
72624+ hash->used_size = hash_compat.used_size;
72625+
72626+ hash->type = hash_compat.type;
72627+
72628+ return 0;
72629+}
72630+
72631+int copy_pointer_from_array_compat(void *ptr, unsigned long idx, const void *userp)
72632+{
72633+ compat_uptr_t ptrcompat;
72634+
72635+ if (copy_from_user(&ptrcompat, userp + (idx * sizeof(ptrcompat)), sizeof(ptrcompat)))
72636+ return -EFAULT;
72637+
72638+ *(void **)ptr = compat_ptr(ptrcompat);
72639+
72640+ return 0;
72641+}
72642+
72643+int copy_acl_ip_label_compat(struct acl_ip_label *ip, const struct acl_ip_label *userp)
72644+{
72645+ struct acl_ip_label_compat ip_compat;
72646+
72647+ if (copy_from_user(&ip_compat, userp, sizeof(ip_compat)))
72648+ return -EFAULT;
72649+
72650+ ip->iface = compat_ptr(ip_compat.iface);
72651+ ip->addr = ip_compat.addr;
72652+ ip->netmask = ip_compat.netmask;
72653+ ip->low = ip_compat.low;
72654+ ip->high = ip_compat.high;
72655+ ip->mode = ip_compat.mode;
72656+ ip->type = ip_compat.type;
72657+
72658+ memcpy(&ip->proto, &ip_compat.proto, sizeof(ip->proto));
72659+
72660+ ip->prev = compat_ptr(ip_compat.prev);
72661+ ip->next = compat_ptr(ip_compat.next);
72662+
72663+ return 0;
72664+}
72665+
72666+int copy_sprole_pw_compat(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp)
72667+{
72668+ struct sprole_pw_compat pw_compat;
72669+
72670+ if (copy_from_user(&pw_compat, (const void *)userp + (sizeof(pw_compat) * idx), sizeof(pw_compat)))
72671+ return -EFAULT;
72672+
72673+ pw->rolename = compat_ptr(pw_compat.rolename);
72674+ memcpy(&pw->salt, pw_compat.salt, sizeof(pw->salt));
72675+ memcpy(&pw->sum, pw_compat.sum, sizeof(pw->sum));
72676+
72677+ return 0;
72678+}
72679+
72680+size_t get_gr_arg_wrapper_size_compat(void)
72681+{
72682+ return sizeof(struct gr_arg_wrapper_compat);
72683+}
72684+
72685diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
72686new file mode 100644
72687index 0000000..4008fdc
72688--- /dev/null
72689+++ b/grsecurity/gracl_fs.c
72690@@ -0,0 +1,445 @@
72691+#include <linux/kernel.h>
72692+#include <linux/sched.h>
72693+#include <linux/types.h>
72694+#include <linux/fs.h>
72695+#include <linux/file.h>
72696+#include <linux/stat.h>
72697+#include <linux/grsecurity.h>
72698+#include <linux/grinternal.h>
72699+#include <linux/gracl.h>
72700+
72701+umode_t
72702+gr_acl_umask(void)
72703+{
72704+ if (unlikely(!gr_acl_is_enabled()))
72705+ return 0;
72706+
72707+ return current->role->umask;
72708+}
72709+
72710+__u32
72711+gr_acl_handle_hidden_file(const struct dentry * dentry,
72712+ const struct vfsmount * mnt)
72713+{
72714+ __u32 mode;
72715+
72716+ if (unlikely(d_is_negative(dentry)))
72717+ return GR_FIND;
72718+
72719+ mode =
72720+ gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
72721+
72722+ if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
72723+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
72724+ return mode;
72725+ } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
72726+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
72727+ return 0;
72728+ } else if (unlikely(!(mode & GR_FIND)))
72729+ return 0;
72730+
72731+ return GR_FIND;
72732+}
72733+
72734+__u32
72735+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
72736+ int acc_mode)
72737+{
72738+ __u32 reqmode = GR_FIND;
72739+ __u32 mode;
72740+
72741+ if (unlikely(d_is_negative(dentry)))
72742+ return reqmode;
72743+
72744+ if (acc_mode & MAY_APPEND)
72745+ reqmode |= GR_APPEND;
72746+ else if (acc_mode & MAY_WRITE)
72747+ reqmode |= GR_WRITE;
72748+ if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
72749+ reqmode |= GR_READ;
72750+
72751+ mode =
72752+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
72753+ mnt);
72754+
72755+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
72756+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
72757+ reqmode & GR_READ ? " reading" : "",
72758+ reqmode & GR_WRITE ? " writing" : reqmode &
72759+ GR_APPEND ? " appending" : "");
72760+ return reqmode;
72761+ } else
72762+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
72763+ {
72764+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
72765+ reqmode & GR_READ ? " reading" : "",
72766+ reqmode & GR_WRITE ? " writing" : reqmode &
72767+ GR_APPEND ? " appending" : "");
72768+ return 0;
72769+ } else if (unlikely((mode & reqmode) != reqmode))
72770+ return 0;
72771+
72772+ return reqmode;
72773+}
72774+
72775+__u32
72776+gr_acl_handle_creat(const struct dentry * dentry,
72777+ const struct dentry * p_dentry,
72778+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
72779+ const int imode)
72780+{
72781+ __u32 reqmode = GR_WRITE | GR_CREATE;
72782+ __u32 mode;
72783+
72784+ if (acc_mode & MAY_APPEND)
72785+ reqmode |= GR_APPEND;
72786+ // if a directory was required or the directory already exists, then
72787+ // don't count this open as a read
72788+ if ((acc_mode & MAY_READ) &&
72789+ !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
72790+ reqmode |= GR_READ;
72791+ if ((open_flags & O_CREAT) &&
72792+ ((imode & S_ISUID) || ((imode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
72793+ reqmode |= GR_SETID;
72794+
72795+ mode =
72796+ gr_check_create(dentry, p_dentry, p_mnt,
72797+ reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
72798+
72799+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
72800+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
72801+ reqmode & GR_READ ? " reading" : "",
72802+ reqmode & GR_WRITE ? " writing" : reqmode &
72803+ GR_APPEND ? " appending" : "");
72804+ return reqmode;
72805+ } else
72806+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
72807+ {
72808+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
72809+ reqmode & GR_READ ? " reading" : "",
72810+ reqmode & GR_WRITE ? " writing" : reqmode &
72811+ GR_APPEND ? " appending" : "");
72812+ return 0;
72813+ } else if (unlikely((mode & reqmode) != reqmode))
72814+ return 0;
72815+
72816+ return reqmode;
72817+}
72818+
72819+__u32
72820+gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
72821+ const int fmode)
72822+{
72823+ __u32 mode, reqmode = GR_FIND;
72824+
72825+ if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
72826+ reqmode |= GR_EXEC;
72827+ if (fmode & S_IWOTH)
72828+ reqmode |= GR_WRITE;
72829+ if (fmode & S_IROTH)
72830+ reqmode |= GR_READ;
72831+
72832+ mode =
72833+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
72834+ mnt);
72835+
72836+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
72837+ gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
72838+ reqmode & GR_READ ? " reading" : "",
72839+ reqmode & GR_WRITE ? " writing" : "",
72840+ reqmode & GR_EXEC ? " executing" : "");
72841+ return reqmode;
72842+ } else
72843+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
72844+ {
72845+ gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
72846+ reqmode & GR_READ ? " reading" : "",
72847+ reqmode & GR_WRITE ? " writing" : "",
72848+ reqmode & GR_EXEC ? " executing" : "");
72849+ return 0;
72850+ } else if (unlikely((mode & reqmode) != reqmode))
72851+ return 0;
72852+
72853+ return reqmode;
72854+}
72855+
72856+static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
72857+{
72858+ __u32 mode;
72859+
72860+ mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
72861+
72862+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
72863+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
72864+ return mode;
72865+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
72866+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
72867+ return 0;
72868+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
72869+ return 0;
72870+
72871+ return (reqmode);
72872+}
72873+
72874+__u32
72875+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
72876+{
72877+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
72878+}
72879+
72880+__u32
72881+gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
72882+{
72883+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
72884+}
72885+
72886+__u32
72887+gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
72888+{
72889+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
72890+}
72891+
72892+__u32
72893+gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
72894+{
72895+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
72896+}
72897+
72898+__u32
72899+gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
72900+ umode_t *modeptr)
72901+{
72902+ umode_t mode;
72903+
72904+ *modeptr &= ~gr_acl_umask();
72905+ mode = *modeptr;
72906+
72907+ if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
72908+ return 1;
72909+
72910+ if (unlikely(dentry->d_inode && !S_ISDIR(dentry->d_inode->i_mode) &&
72911+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))) {
72912+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
72913+ GR_CHMOD_ACL_MSG);
72914+ } else {
72915+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
72916+ }
72917+}
72918+
72919+__u32
72920+gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
72921+{
72922+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
72923+}
72924+
72925+__u32
72926+gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
72927+{
72928+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
72929+}
72930+
72931+__u32
72932+gr_acl_handle_removexattr(const struct dentry *dentry, const struct vfsmount *mnt)
72933+{
72934+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_REMOVEXATTR_ACL_MSG);
72935+}
72936+
72937+__u32
72938+gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
72939+{
72940+ return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
72941+}
72942+
72943+__u32
72944+gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
72945+{
72946+ return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
72947+ GR_UNIXCONNECT_ACL_MSG);
72948+}
72949+
72950+/* hardlinks require at minimum create and link permission,
72951+ any additional privilege required is based on the
72952+ privilege of the file being linked to
72953+*/
72954+__u32
72955+gr_acl_handle_link(const struct dentry * new_dentry,
72956+ const struct dentry * parent_dentry,
72957+ const struct vfsmount * parent_mnt,
72958+ const struct dentry * old_dentry,
72959+ const struct vfsmount * old_mnt, const struct filename *to)
72960+{
72961+ __u32 mode;
72962+ __u32 needmode = GR_CREATE | GR_LINK;
72963+ __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
72964+
72965+ mode =
72966+ gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
72967+ old_mnt);
72968+
72969+ if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
72970+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
72971+ return mode;
72972+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
72973+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
72974+ return 0;
72975+ } else if (unlikely((mode & needmode) != needmode))
72976+ return 0;
72977+
72978+ return 1;
72979+}
72980+
72981+__u32
72982+gr_acl_handle_symlink(const struct dentry * new_dentry,
72983+ const struct dentry * parent_dentry,
72984+ const struct vfsmount * parent_mnt, const struct filename *from)
72985+{
72986+ __u32 needmode = GR_WRITE | GR_CREATE;
72987+ __u32 mode;
72988+
72989+ mode =
72990+ gr_check_create(new_dentry, parent_dentry, parent_mnt,
72991+ GR_CREATE | GR_AUDIT_CREATE |
72992+ GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
72993+
72994+ if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
72995+ gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
72996+ return mode;
72997+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
72998+ gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
72999+ return 0;
73000+ } else if (unlikely((mode & needmode) != needmode))
73001+ return 0;
73002+
73003+ return (GR_WRITE | GR_CREATE);
73004+}
73005+
73006+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)
73007+{
73008+ __u32 mode;
73009+
73010+ mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
73011+
73012+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
73013+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
73014+ return mode;
73015+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
73016+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
73017+ return 0;
73018+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
73019+ return 0;
73020+
73021+ return (reqmode);
73022+}
73023+
73024+__u32
73025+gr_acl_handle_mknod(const struct dentry * new_dentry,
73026+ const struct dentry * parent_dentry,
73027+ const struct vfsmount * parent_mnt,
73028+ const int mode)
73029+{
73030+ __u32 reqmode = GR_WRITE | GR_CREATE;
73031+ if (unlikely((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
73032+ reqmode |= GR_SETID;
73033+
73034+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
73035+ reqmode, GR_MKNOD_ACL_MSG);
73036+}
73037+
73038+__u32
73039+gr_acl_handle_mkdir(const struct dentry *new_dentry,
73040+ const struct dentry *parent_dentry,
73041+ const struct vfsmount *parent_mnt)
73042+{
73043+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
73044+ GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
73045+}
73046+
73047+#define RENAME_CHECK_SUCCESS(old, new) \
73048+ (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
73049+ ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
73050+
73051+int
73052+gr_acl_handle_rename(struct dentry *new_dentry,
73053+ struct dentry *parent_dentry,
73054+ const struct vfsmount *parent_mnt,
73055+ struct dentry *old_dentry,
73056+ struct inode *old_parent_inode,
73057+ struct vfsmount *old_mnt, const struct filename *newname, unsigned int flags)
73058+{
73059+ __u32 comp1, comp2;
73060+ int error = 0;
73061+
73062+ if (unlikely(!gr_acl_is_enabled()))
73063+ return 0;
73064+
73065+ if (flags & RENAME_EXCHANGE) {
73066+ comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
73067+ GR_AUDIT_READ | GR_AUDIT_WRITE |
73068+ GR_SUPPRESS, parent_mnt);
73069+ comp2 =
73070+ gr_search_file(old_dentry,
73071+ GR_READ | GR_WRITE | GR_AUDIT_READ |
73072+ GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
73073+ } else if (d_is_negative(new_dentry)) {
73074+ comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
73075+ GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
73076+ GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
73077+ comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
73078+ GR_DELETE | GR_AUDIT_DELETE |
73079+ GR_AUDIT_READ | GR_AUDIT_WRITE |
73080+ GR_SUPPRESS, old_mnt);
73081+ } else {
73082+ comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
73083+ GR_CREATE | GR_DELETE |
73084+ GR_AUDIT_CREATE | GR_AUDIT_DELETE |
73085+ GR_AUDIT_READ | GR_AUDIT_WRITE |
73086+ GR_SUPPRESS, parent_mnt);
73087+ comp2 =
73088+ gr_search_file(old_dentry,
73089+ GR_READ | GR_WRITE | GR_AUDIT_READ |
73090+ GR_DELETE | GR_AUDIT_DELETE |
73091+ GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
73092+ }
73093+
73094+ if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
73095+ ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
73096+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
73097+ else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
73098+ && !(comp2 & GR_SUPPRESS)) {
73099+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
73100+ error = -EACCES;
73101+ } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
73102+ error = -EACCES;
73103+
73104+ return error;
73105+}
73106+
73107+void
73108+gr_acl_handle_exit(void)
73109+{
73110+ u16 id;
73111+ char *rolename;
73112+
73113+ if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
73114+ !(current->role->roletype & GR_ROLE_PERSIST))) {
73115+ id = current->acl_role_id;
73116+ rolename = current->role->rolename;
73117+ gr_set_acls(1);
73118+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
73119+ }
73120+
73121+ gr_put_exec_file(current);
73122+ return;
73123+}
73124+
73125+int
73126+gr_acl_handle_procpidmem(const struct task_struct *task)
73127+{
73128+ if (unlikely(!gr_acl_is_enabled()))
73129+ return 0;
73130+
73131+ if (task != current && task->acl->mode & GR_PROTPROCFD)
73132+ return -EACCES;
73133+
73134+ return 0;
73135+}
73136diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
73137new file mode 100644
73138index 0000000..f056b81
73139--- /dev/null
73140+++ b/grsecurity/gracl_ip.c
73141@@ -0,0 +1,386 @@
73142+#include <linux/kernel.h>
73143+#include <asm/uaccess.h>
73144+#include <asm/errno.h>
73145+#include <net/sock.h>
73146+#include <linux/file.h>
73147+#include <linux/fs.h>
73148+#include <linux/net.h>
73149+#include <linux/in.h>
73150+#include <linux/skbuff.h>
73151+#include <linux/ip.h>
73152+#include <linux/udp.h>
73153+#include <linux/types.h>
73154+#include <linux/sched.h>
73155+#include <linux/netdevice.h>
73156+#include <linux/inetdevice.h>
73157+#include <linux/gracl.h>
73158+#include <linux/grsecurity.h>
73159+#include <linux/grinternal.h>
73160+
73161+#define GR_BIND 0x01
73162+#define GR_CONNECT 0x02
73163+#define GR_INVERT 0x04
73164+#define GR_BINDOVERRIDE 0x08
73165+#define GR_CONNECTOVERRIDE 0x10
73166+#define GR_SOCK_FAMILY 0x20
73167+
73168+static const char * gr_protocols[IPPROTO_MAX] = {
73169+ "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
73170+ "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
73171+ "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
73172+ "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
73173+ "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
73174+ "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
73175+ "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
73176+ "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
73177+ "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
73178+ "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
73179+ "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
73180+ "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
73181+ "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
73182+ "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
73183+ "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
73184+ "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
73185+ "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
73186+ "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
73187+ "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
73188+ "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
73189+ "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
73190+ "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
73191+ "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
73192+ "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
73193+ "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
73194+ "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
73195+ "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
73196+ "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
73197+ "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
73198+ "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
73199+ "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
73200+ "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
73201+ };
73202+
73203+static const char * gr_socktypes[SOCK_MAX] = {
73204+ "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
73205+ "unknown:7", "unknown:8", "unknown:9", "packet"
73206+ };
73207+
73208+static const char * gr_sockfamilies[AF_MAX+1] = {
73209+ "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
73210+ "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
73211+ "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
73212+ "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
73213+ };
73214+
73215+const char *
73216+gr_proto_to_name(unsigned char proto)
73217+{
73218+ return gr_protocols[proto];
73219+}
73220+
73221+const char *
73222+gr_socktype_to_name(unsigned char type)
73223+{
73224+ return gr_socktypes[type];
73225+}
73226+
73227+const char *
73228+gr_sockfamily_to_name(unsigned char family)
73229+{
73230+ return gr_sockfamilies[family];
73231+}
73232+
73233+extern const struct net_proto_family __rcu *net_families[NPROTO] __read_mostly;
73234+
73235+int
73236+gr_search_socket(const int domain, const int type, const int protocol)
73237+{
73238+ struct acl_subject_label *curr;
73239+ const struct cred *cred = current_cred();
73240+
73241+ if (unlikely(!gr_acl_is_enabled()))
73242+ goto exit;
73243+
73244+ if ((domain < 0) || (type < 0) || (protocol < 0) ||
73245+ (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
73246+ goto exit; // let the kernel handle it
73247+
73248+ curr = current->acl;
73249+
73250+ if (curr->sock_families[domain / 32] & (1U << (domain % 32))) {
73251+ /* the family is allowed, if this is PF_INET allow it only if
73252+ the extra sock type/protocol checks pass */
73253+ if (domain == PF_INET)
73254+ goto inet_check;
73255+ goto exit;
73256+ } else {
73257+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
73258+ __u32 fakeip = 0;
73259+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
73260+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
73261+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
73262+ gr_to_filename(current->exec_file->f_path.dentry,
73263+ current->exec_file->f_path.mnt) :
73264+ curr->filename, curr->filename,
73265+ &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
73266+ &current->signal->saved_ip);
73267+ goto exit;
73268+ }
73269+ goto exit_fail;
73270+ }
73271+
73272+inet_check:
73273+ /* the rest of this checking is for IPv4 only */
73274+ if (!curr->ips)
73275+ goto exit;
73276+
73277+ if ((curr->ip_type & (1U << type)) &&
73278+ (curr->ip_proto[protocol / 32] & (1U << (protocol % 32))))
73279+ goto exit;
73280+
73281+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
73282+ /* we don't place acls on raw sockets , and sometimes
73283+ dgram/ip sockets are opened for ioctl and not
73284+ bind/connect, so we'll fake a bind learn log */
73285+ if (type == SOCK_RAW || type == SOCK_PACKET) {
73286+ __u32 fakeip = 0;
73287+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
73288+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
73289+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
73290+ gr_to_filename(current->exec_file->f_path.dentry,
73291+ current->exec_file->f_path.mnt) :
73292+ curr->filename, curr->filename,
73293+ &fakeip, 0, type,
73294+ protocol, GR_CONNECT, &current->signal->saved_ip);
73295+ } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
73296+ __u32 fakeip = 0;
73297+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
73298+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
73299+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
73300+ gr_to_filename(current->exec_file->f_path.dentry,
73301+ current->exec_file->f_path.mnt) :
73302+ curr->filename, curr->filename,
73303+ &fakeip, 0, type,
73304+ protocol, GR_BIND, &current->signal->saved_ip);
73305+ }
73306+ /* we'll log when they use connect or bind */
73307+ goto exit;
73308+ }
73309+
73310+exit_fail:
73311+ if (domain == PF_INET)
73312+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
73313+ gr_socktype_to_name(type), gr_proto_to_name(protocol));
73314+ else if (rcu_access_pointer(net_families[domain]) != NULL)
73315+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
73316+ gr_socktype_to_name(type), protocol);
73317+
73318+ return 0;
73319+exit:
73320+ return 1;
73321+}
73322+
73323+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)
73324+{
73325+ if ((ip->mode & mode) &&
73326+ (ip_port >= ip->low) &&
73327+ (ip_port <= ip->high) &&
73328+ ((ntohl(ip_addr) & our_netmask) ==
73329+ (ntohl(our_addr) & our_netmask))
73330+ && (ip->proto[protocol / 32] & (1U << (protocol % 32)))
73331+ && (ip->type & (1U << type))) {
73332+ if (ip->mode & GR_INVERT)
73333+ return 2; // specifically denied
73334+ else
73335+ return 1; // allowed
73336+ }
73337+
73338+ return 0; // not specifically allowed, may continue parsing
73339+}
73340+
73341+static int
73342+gr_search_connectbind(const int full_mode, struct sock *sk,
73343+ struct sockaddr_in *addr, const int type)
73344+{
73345+ char iface[IFNAMSIZ] = {0};
73346+ struct acl_subject_label *curr;
73347+ struct acl_ip_label *ip;
73348+ struct inet_sock *isk;
73349+ struct net_device *dev;
73350+ struct in_device *idev;
73351+ unsigned long i;
73352+ int ret;
73353+ int mode = full_mode & (GR_BIND | GR_CONNECT);
73354+ __u32 ip_addr = 0;
73355+ __u32 our_addr;
73356+ __u32 our_netmask;
73357+ char *p;
73358+ __u16 ip_port = 0;
73359+ const struct cred *cred = current_cred();
73360+
73361+ if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
73362+ return 0;
73363+
73364+ curr = current->acl;
73365+ isk = inet_sk(sk);
73366+
73367+ /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
73368+ if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
73369+ addr->sin_addr.s_addr = curr->inaddr_any_override;
73370+ if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
73371+ struct sockaddr_in saddr;
73372+ int err;
73373+
73374+ saddr.sin_family = AF_INET;
73375+ saddr.sin_addr.s_addr = curr->inaddr_any_override;
73376+ saddr.sin_port = isk->inet_sport;
73377+
73378+ err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
73379+ if (err)
73380+ return err;
73381+
73382+ err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
73383+ if (err)
73384+ return err;
73385+ }
73386+
73387+ if (!curr->ips)
73388+ return 0;
73389+
73390+ ip_addr = addr->sin_addr.s_addr;
73391+ ip_port = ntohs(addr->sin_port);
73392+
73393+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
73394+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
73395+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
73396+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
73397+ gr_to_filename(current->exec_file->f_path.dentry,
73398+ current->exec_file->f_path.mnt) :
73399+ curr->filename, curr->filename,
73400+ &ip_addr, ip_port, type,
73401+ sk->sk_protocol, mode, &current->signal->saved_ip);
73402+ return 0;
73403+ }
73404+
73405+ for (i = 0; i < curr->ip_num; i++) {
73406+ ip = *(curr->ips + i);
73407+ if (ip->iface != NULL) {
73408+ strncpy(iface, ip->iface, IFNAMSIZ - 1);
73409+ p = strchr(iface, ':');
73410+ if (p != NULL)
73411+ *p = '\0';
73412+ dev = dev_get_by_name(sock_net(sk), iface);
73413+ if (dev == NULL)
73414+ continue;
73415+ idev = in_dev_get(dev);
73416+ if (idev == NULL) {
73417+ dev_put(dev);
73418+ continue;
73419+ }
73420+ rcu_read_lock();
73421+ for_ifa(idev) {
73422+ if (!strcmp(ip->iface, ifa->ifa_label)) {
73423+ our_addr = ifa->ifa_address;
73424+ our_netmask = 0xffffffff;
73425+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
73426+ if (ret == 1) {
73427+ rcu_read_unlock();
73428+ in_dev_put(idev);
73429+ dev_put(dev);
73430+ return 0;
73431+ } else if (ret == 2) {
73432+ rcu_read_unlock();
73433+ in_dev_put(idev);
73434+ dev_put(dev);
73435+ goto denied;
73436+ }
73437+ }
73438+ } endfor_ifa(idev);
73439+ rcu_read_unlock();
73440+ in_dev_put(idev);
73441+ dev_put(dev);
73442+ } else {
73443+ our_addr = ip->addr;
73444+ our_netmask = ip->netmask;
73445+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
73446+ if (ret == 1)
73447+ return 0;
73448+ else if (ret == 2)
73449+ goto denied;
73450+ }
73451+ }
73452+
73453+denied:
73454+ if (mode == GR_BIND)
73455+ 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));
73456+ else if (mode == GR_CONNECT)
73457+ 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));
73458+
73459+ return -EACCES;
73460+}
73461+
73462+int
73463+gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
73464+{
73465+ /* always allow disconnection of dgram sockets with connect */
73466+ if (addr->sin_family == AF_UNSPEC)
73467+ return 0;
73468+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
73469+}
73470+
73471+int
73472+gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
73473+{
73474+ return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
73475+}
73476+
73477+int gr_search_listen(struct socket *sock)
73478+{
73479+ struct sock *sk = sock->sk;
73480+ struct sockaddr_in addr;
73481+
73482+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
73483+ addr.sin_port = inet_sk(sk)->inet_sport;
73484+
73485+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
73486+}
73487+
73488+int gr_search_accept(struct socket *sock)
73489+{
73490+ struct sock *sk = sock->sk;
73491+ struct sockaddr_in addr;
73492+
73493+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
73494+ addr.sin_port = inet_sk(sk)->inet_sport;
73495+
73496+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
73497+}
73498+
73499+int
73500+gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
73501+{
73502+ if (addr)
73503+ return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
73504+ else {
73505+ struct sockaddr_in sin;
73506+ const struct inet_sock *inet = inet_sk(sk);
73507+
73508+ sin.sin_addr.s_addr = inet->inet_daddr;
73509+ sin.sin_port = inet->inet_dport;
73510+
73511+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
73512+ }
73513+}
73514+
73515+int
73516+gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
73517+{
73518+ struct sockaddr_in sin;
73519+
73520+ if (unlikely(skb->len < sizeof (struct udphdr)))
73521+ return 0; // skip this packet
73522+
73523+ sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
73524+ sin.sin_port = udp_hdr(skb)->source;
73525+
73526+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
73527+}
73528diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
73529new file mode 100644
73530index 0000000..25f54ef
73531--- /dev/null
73532+++ b/grsecurity/gracl_learn.c
73533@@ -0,0 +1,207 @@
73534+#include <linux/kernel.h>
73535+#include <linux/mm.h>
73536+#include <linux/sched.h>
73537+#include <linux/poll.h>
73538+#include <linux/string.h>
73539+#include <linux/file.h>
73540+#include <linux/types.h>
73541+#include <linux/vmalloc.h>
73542+#include <linux/grinternal.h>
73543+
73544+extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
73545+ size_t count, loff_t *ppos);
73546+extern int gr_acl_is_enabled(void);
73547+
73548+static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
73549+static int gr_learn_attached;
73550+
73551+/* use a 512k buffer */
73552+#define LEARN_BUFFER_SIZE (512 * 1024)
73553+
73554+static DEFINE_SPINLOCK(gr_learn_lock);
73555+static DEFINE_MUTEX(gr_learn_user_mutex);
73556+
73557+/* we need to maintain two buffers, so that the kernel context of grlearn
73558+ uses a semaphore around the userspace copying, and the other kernel contexts
73559+ use a spinlock when copying into the buffer, since they cannot sleep
73560+*/
73561+static char *learn_buffer;
73562+static char *learn_buffer_user;
73563+static int learn_buffer_len;
73564+static int learn_buffer_user_len;
73565+
73566+static ssize_t
73567+read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
73568+{
73569+ DECLARE_WAITQUEUE(wait, current);
73570+ ssize_t retval = 0;
73571+
73572+ add_wait_queue(&learn_wait, &wait);
73573+ set_current_state(TASK_INTERRUPTIBLE);
73574+ do {
73575+ mutex_lock(&gr_learn_user_mutex);
73576+ spin_lock(&gr_learn_lock);
73577+ if (learn_buffer_len)
73578+ break;
73579+ spin_unlock(&gr_learn_lock);
73580+ mutex_unlock(&gr_learn_user_mutex);
73581+ if (file->f_flags & O_NONBLOCK) {
73582+ retval = -EAGAIN;
73583+ goto out;
73584+ }
73585+ if (signal_pending(current)) {
73586+ retval = -ERESTARTSYS;
73587+ goto out;
73588+ }
73589+
73590+ schedule();
73591+ } while (1);
73592+
73593+ memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
73594+ learn_buffer_user_len = learn_buffer_len;
73595+ retval = learn_buffer_len;
73596+ learn_buffer_len = 0;
73597+
73598+ spin_unlock(&gr_learn_lock);
73599+
73600+ if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
73601+ retval = -EFAULT;
73602+
73603+ mutex_unlock(&gr_learn_user_mutex);
73604+out:
73605+ set_current_state(TASK_RUNNING);
73606+ remove_wait_queue(&learn_wait, &wait);
73607+ return retval;
73608+}
73609+
73610+static unsigned int
73611+poll_learn(struct file * file, poll_table * wait)
73612+{
73613+ poll_wait(file, &learn_wait, wait);
73614+
73615+ if (learn_buffer_len)
73616+ return (POLLIN | POLLRDNORM);
73617+
73618+ return 0;
73619+}
73620+
73621+void
73622+gr_clear_learn_entries(void)
73623+{
73624+ char *tmp;
73625+
73626+ mutex_lock(&gr_learn_user_mutex);
73627+ spin_lock(&gr_learn_lock);
73628+ tmp = learn_buffer;
73629+ learn_buffer = NULL;
73630+ spin_unlock(&gr_learn_lock);
73631+ if (tmp)
73632+ vfree(tmp);
73633+ if (learn_buffer_user != NULL) {
73634+ vfree(learn_buffer_user);
73635+ learn_buffer_user = NULL;
73636+ }
73637+ learn_buffer_len = 0;
73638+ mutex_unlock(&gr_learn_user_mutex);
73639+
73640+ return;
73641+}
73642+
73643+void
73644+gr_add_learn_entry(const char *fmt, ...)
73645+{
73646+ va_list args;
73647+ unsigned int len;
73648+
73649+ if (!gr_learn_attached)
73650+ return;
73651+
73652+ spin_lock(&gr_learn_lock);
73653+
73654+ /* leave a gap at the end so we know when it's "full" but don't have to
73655+ compute the exact length of the string we're trying to append
73656+ */
73657+ if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
73658+ spin_unlock(&gr_learn_lock);
73659+ wake_up_interruptible(&learn_wait);
73660+ return;
73661+ }
73662+ if (learn_buffer == NULL) {
73663+ spin_unlock(&gr_learn_lock);
73664+ return;
73665+ }
73666+
73667+ va_start(args, fmt);
73668+ len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
73669+ va_end(args);
73670+
73671+ learn_buffer_len += len + 1;
73672+
73673+ spin_unlock(&gr_learn_lock);
73674+ wake_up_interruptible(&learn_wait);
73675+
73676+ return;
73677+}
73678+
73679+static int
73680+open_learn(struct inode *inode, struct file *file)
73681+{
73682+ if (file->f_mode & FMODE_READ && gr_learn_attached)
73683+ return -EBUSY;
73684+ if (file->f_mode & FMODE_READ) {
73685+ int retval = 0;
73686+ mutex_lock(&gr_learn_user_mutex);
73687+ if (learn_buffer == NULL)
73688+ learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
73689+ if (learn_buffer_user == NULL)
73690+ learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
73691+ if (learn_buffer == NULL) {
73692+ retval = -ENOMEM;
73693+ goto out_error;
73694+ }
73695+ if (learn_buffer_user == NULL) {
73696+ retval = -ENOMEM;
73697+ goto out_error;
73698+ }
73699+ learn_buffer_len = 0;
73700+ learn_buffer_user_len = 0;
73701+ gr_learn_attached = 1;
73702+out_error:
73703+ mutex_unlock(&gr_learn_user_mutex);
73704+ return retval;
73705+ }
73706+ return 0;
73707+}
73708+
73709+static int
73710+close_learn(struct inode *inode, struct file *file)
73711+{
73712+ if (file->f_mode & FMODE_READ) {
73713+ char *tmp = NULL;
73714+ mutex_lock(&gr_learn_user_mutex);
73715+ spin_lock(&gr_learn_lock);
73716+ tmp = learn_buffer;
73717+ learn_buffer = NULL;
73718+ spin_unlock(&gr_learn_lock);
73719+ if (tmp)
73720+ vfree(tmp);
73721+ if (learn_buffer_user != NULL) {
73722+ vfree(learn_buffer_user);
73723+ learn_buffer_user = NULL;
73724+ }
73725+ learn_buffer_len = 0;
73726+ learn_buffer_user_len = 0;
73727+ gr_learn_attached = 0;
73728+ mutex_unlock(&gr_learn_user_mutex);
73729+ }
73730+
73731+ return 0;
73732+}
73733+
73734+const struct file_operations grsec_fops = {
73735+ .read = read_learn,
73736+ .write = write_grsec_handler,
73737+ .open = open_learn,
73738+ .release = close_learn,
73739+ .poll = poll_learn,
73740+};
73741diff --git a/grsecurity/gracl_policy.c b/grsecurity/gracl_policy.c
73742new file mode 100644
73743index 0000000..3f8ade0
73744--- /dev/null
73745+++ b/grsecurity/gracl_policy.c
73746@@ -0,0 +1,1782 @@
73747+#include <linux/kernel.h>
73748+#include <linux/module.h>
73749+#include <linux/sched.h>
73750+#include <linux/mm.h>
73751+#include <linux/file.h>
73752+#include <linux/fs.h>
73753+#include <linux/namei.h>
73754+#include <linux/mount.h>
73755+#include <linux/tty.h>
73756+#include <linux/proc_fs.h>
73757+#include <linux/lglock.h>
73758+#include <linux/slab.h>
73759+#include <linux/vmalloc.h>
73760+#include <linux/types.h>
73761+#include <linux/sysctl.h>
73762+#include <linux/netdevice.h>
73763+#include <linux/ptrace.h>
73764+#include <linux/gracl.h>
73765+#include <linux/gralloc.h>
73766+#include <linux/security.h>
73767+#include <linux/grinternal.h>
73768+#include <linux/pid_namespace.h>
73769+#include <linux/stop_machine.h>
73770+#include <linux/fdtable.h>
73771+#include <linux/percpu.h>
73772+#include <linux/lglock.h>
73773+#include <linux/hugetlb.h>
73774+#include <linux/posix-timers.h>
73775+#include "../fs/mount.h"
73776+
73777+#include <asm/uaccess.h>
73778+#include <asm/errno.h>
73779+#include <asm/mman.h>
73780+
73781+extern struct gr_policy_state *polstate;
73782+
73783+#define FOR_EACH_ROLE_START(role) \
73784+ role = polstate->role_list; \
73785+ while (role) {
73786+
73787+#define FOR_EACH_ROLE_END(role) \
73788+ role = role->prev; \
73789+ }
73790+
73791+struct path gr_real_root;
73792+
73793+extern struct gr_alloc_state *current_alloc_state;
73794+
73795+u16 acl_sp_role_value;
73796+
73797+static DEFINE_MUTEX(gr_dev_mutex);
73798+
73799+extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
73800+extern void gr_clear_learn_entries(void);
73801+
73802+struct gr_arg *gr_usermode __read_only;
73803+unsigned char *gr_system_salt __read_only;
73804+unsigned char *gr_system_sum __read_only;
73805+
73806+static unsigned int gr_auth_attempts = 0;
73807+static unsigned long gr_auth_expires = 0UL;
73808+
73809+struct acl_object_label *fakefs_obj_rw;
73810+struct acl_object_label *fakefs_obj_rwx;
73811+
73812+extern int gr_init_uidset(void);
73813+extern void gr_free_uidset(void);
73814+extern void gr_remove_uid(uid_t uid);
73815+extern int gr_find_uid(uid_t uid);
73816+
73817+extern struct acl_subject_label *__gr_get_subject_for_task(const struct gr_policy_state *state, struct task_struct *task, const char *filename);
73818+extern void __gr_apply_subject_to_task(struct gr_policy_state *state, struct task_struct *task, struct acl_subject_label *subj);
73819+extern int gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb);
73820+extern void __insert_inodev_entry(const struct gr_policy_state *state, struct inodev_entry *entry);
73821+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);
73822+extern void insert_acl_obj_label(struct acl_object_label *obj, struct acl_subject_label *subj);
73823+extern void insert_acl_subj_label(struct acl_subject_label *obj, struct acl_role_label *role);
73824+extern struct name_entry * __lookup_name_entry(const struct gr_policy_state *state, const char *name);
73825+extern char *gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt);
73826+extern struct acl_subject_label *lookup_acl_subj_label(const ino_t ino, const dev_t dev, const struct acl_role_label *role);
73827+extern struct acl_subject_label *lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev, const struct acl_role_label *role);
73828+extern void assign_special_role(const char *rolename);
73829+extern struct acl_subject_label *chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt, const struct acl_role_label *role);
73830+extern int gr_rbac_disable(void *unused);
73831+extern void gr_enable_rbac_system(void);
73832+
73833+static int copy_acl_object_label_normal(struct acl_object_label *obj, const struct acl_object_label *userp)
73834+{
73835+ if (copy_from_user(obj, userp, sizeof(struct acl_object_label)))
73836+ return -EFAULT;
73837+
73838+ return 0;
73839+}
73840+
73841+static int copy_acl_ip_label_normal(struct acl_ip_label *ip, const struct acl_ip_label *userp)
73842+{
73843+ if (copy_from_user(ip, userp, sizeof(struct acl_ip_label)))
73844+ return -EFAULT;
73845+
73846+ return 0;
73847+}
73848+
73849+static int copy_acl_subject_label_normal(struct acl_subject_label *subj, const struct acl_subject_label *userp)
73850+{
73851+ if (copy_from_user(subj, userp, sizeof(struct acl_subject_label)))
73852+ return -EFAULT;
73853+
73854+ return 0;
73855+}
73856+
73857+static int copy_acl_role_label_normal(struct acl_role_label *role, const struct acl_role_label *userp)
73858+{
73859+ if (copy_from_user(role, userp, sizeof(struct acl_role_label)))
73860+ return -EFAULT;
73861+
73862+ return 0;
73863+}
73864+
73865+static int copy_role_allowed_ip_normal(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp)
73866+{
73867+ if (copy_from_user(roleip, userp, sizeof(struct role_allowed_ip)))
73868+ return -EFAULT;
73869+
73870+ return 0;
73871+}
73872+
73873+static int copy_sprole_pw_normal(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp)
73874+{
73875+ if (copy_from_user(pw, userp + idx, sizeof(struct sprole_pw)))
73876+ return -EFAULT;
73877+
73878+ return 0;
73879+}
73880+
73881+static int copy_gr_hash_struct_normal(struct gr_hash_struct *hash, const struct gr_hash_struct *userp)
73882+{
73883+ if (copy_from_user(hash, userp, sizeof(struct gr_hash_struct)))
73884+ return -EFAULT;
73885+
73886+ return 0;
73887+}
73888+
73889+static int copy_role_transition_normal(struct role_transition *trans, const struct role_transition *userp)
73890+{
73891+ if (copy_from_user(trans, userp, sizeof(struct role_transition)))
73892+ return -EFAULT;
73893+
73894+ return 0;
73895+}
73896+
73897+int copy_pointer_from_array_normal(void *ptr, unsigned long idx, const void *userp)
73898+{
73899+ if (copy_from_user(ptr, userp + (idx * sizeof(void *)), sizeof(void *)))
73900+ return -EFAULT;
73901+
73902+ return 0;
73903+}
73904+
73905+static int copy_gr_arg_wrapper_normal(const char __user *buf, struct gr_arg_wrapper *uwrap)
73906+{
73907+ if (copy_from_user(uwrap, buf, sizeof (struct gr_arg_wrapper)))
73908+ return -EFAULT;
73909+
73910+ if (((uwrap->version != GRSECURITY_VERSION) &&
73911+ (uwrap->version != 0x2901)) ||
73912+ (uwrap->size != sizeof(struct gr_arg)))
73913+ return -EINVAL;
73914+
73915+ return 0;
73916+}
73917+
73918+static int copy_gr_arg_normal(const struct gr_arg __user *buf, struct gr_arg *arg)
73919+{
73920+ if (copy_from_user(arg, buf, sizeof (struct gr_arg)))
73921+ return -EFAULT;
73922+
73923+ return 0;
73924+}
73925+
73926+static size_t get_gr_arg_wrapper_size_normal(void)
73927+{
73928+ return sizeof(struct gr_arg_wrapper);
73929+}
73930+
73931+#ifdef CONFIG_COMPAT
73932+extern int copy_gr_arg_wrapper_compat(const char *buf, struct gr_arg_wrapper *uwrap);
73933+extern int copy_gr_arg_compat(const struct gr_arg __user *buf, struct gr_arg *arg);
73934+extern int copy_acl_object_label_compat(struct acl_object_label *obj, const struct acl_object_label *userp);
73935+extern int copy_acl_subject_label_compat(struct acl_subject_label *subj, const struct acl_subject_label *userp);
73936+extern int copy_acl_role_label_compat(struct acl_role_label *role, const struct acl_role_label *userp);
73937+extern int copy_role_allowed_ip_compat(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp);
73938+extern int copy_role_transition_compat(struct role_transition *trans, const struct role_transition *userp);
73939+extern int copy_gr_hash_struct_compat(struct gr_hash_struct *hash, const struct gr_hash_struct *userp);
73940+extern int copy_pointer_from_array_compat(void *ptr, unsigned long idx, const void *userp);
73941+extern int copy_acl_ip_label_compat(struct acl_ip_label *ip, const struct acl_ip_label *userp);
73942+extern int copy_sprole_pw_compat(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp);
73943+extern size_t get_gr_arg_wrapper_size_compat(void);
73944+
73945+int (* copy_gr_arg_wrapper)(const char *buf, struct gr_arg_wrapper *uwrap) __read_only;
73946+int (* copy_gr_arg)(const struct gr_arg *buf, struct gr_arg *arg) __read_only;
73947+int (* copy_acl_object_label)(struct acl_object_label *obj, const struct acl_object_label *userp) __read_only;
73948+int (* copy_acl_subject_label)(struct acl_subject_label *subj, const struct acl_subject_label *userp) __read_only;
73949+int (* copy_acl_role_label)(struct acl_role_label *role, const struct acl_role_label *userp) __read_only;
73950+int (* copy_acl_ip_label)(struct acl_ip_label *ip, const struct acl_ip_label *userp) __read_only;
73951+int (* copy_pointer_from_array)(void *ptr, unsigned long idx, const void *userp) __read_only;
73952+int (* copy_sprole_pw)(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp) __read_only;
73953+int (* copy_gr_hash_struct)(struct gr_hash_struct *hash, const struct gr_hash_struct *userp) __read_only;
73954+int (* copy_role_transition)(struct role_transition *trans, const struct role_transition *userp) __read_only;
73955+int (* copy_role_allowed_ip)(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp) __read_only;
73956+size_t (* get_gr_arg_wrapper_size)(void) __read_only;
73957+
73958+#else
73959+#define copy_gr_arg_wrapper copy_gr_arg_wrapper_normal
73960+#define copy_gr_arg copy_gr_arg_normal
73961+#define copy_gr_hash_struct copy_gr_hash_struct_normal
73962+#define copy_acl_object_label copy_acl_object_label_normal
73963+#define copy_acl_subject_label copy_acl_subject_label_normal
73964+#define copy_acl_role_label copy_acl_role_label_normal
73965+#define copy_acl_ip_label copy_acl_ip_label_normal
73966+#define copy_pointer_from_array copy_pointer_from_array_normal
73967+#define copy_sprole_pw copy_sprole_pw_normal
73968+#define copy_role_transition copy_role_transition_normal
73969+#define copy_role_allowed_ip copy_role_allowed_ip_normal
73970+#define get_gr_arg_wrapper_size get_gr_arg_wrapper_size_normal
73971+#endif
73972+
73973+static struct acl_subject_label *
73974+lookup_subject_map(const struct acl_subject_label *userp)
73975+{
73976+ unsigned int index = gr_shash(userp, polstate->subj_map_set.s_size);
73977+ struct subject_map *match;
73978+
73979+ match = polstate->subj_map_set.s_hash[index];
73980+
73981+ while (match && match->user != userp)
73982+ match = match->next;
73983+
73984+ if (match != NULL)
73985+ return match->kernel;
73986+ else
73987+ return NULL;
73988+}
73989+
73990+static void
73991+insert_subj_map_entry(struct subject_map *subjmap)
73992+{
73993+ unsigned int index = gr_shash(subjmap->user, polstate->subj_map_set.s_size);
73994+ struct subject_map **curr;
73995+
73996+ subjmap->prev = NULL;
73997+
73998+ curr = &polstate->subj_map_set.s_hash[index];
73999+ if (*curr != NULL)
74000+ (*curr)->prev = subjmap;
74001+
74002+ subjmap->next = *curr;
74003+ *curr = subjmap;
74004+
74005+ return;
74006+}
74007+
74008+static void
74009+__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
74010+{
74011+ unsigned int index =
74012+ gr_rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), polstate->acl_role_set.r_size);
74013+ struct acl_role_label **curr;
74014+ struct acl_role_label *tmp, *tmp2;
74015+
74016+ curr = &polstate->acl_role_set.r_hash[index];
74017+
74018+ /* simple case, slot is empty, just set it to our role */
74019+ if (*curr == NULL) {
74020+ *curr = role;
74021+ } else {
74022+ /* example:
74023+ 1 -> 2 -> 3 (adding 2 -> 3 to here)
74024+ 2 -> 3
74025+ */
74026+ /* first check to see if we can already be reached via this slot */
74027+ tmp = *curr;
74028+ while (tmp && tmp != role)
74029+ tmp = tmp->next;
74030+ if (tmp == role) {
74031+ /* we don't need to add ourselves to this slot's chain */
74032+ return;
74033+ }
74034+ /* we need to add ourselves to this chain, two cases */
74035+ if (role->next == NULL) {
74036+ /* simple case, append the current chain to our role */
74037+ role->next = *curr;
74038+ *curr = role;
74039+ } else {
74040+ /* 1 -> 2 -> 3 -> 4
74041+ 2 -> 3 -> 4
74042+ 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
74043+ */
74044+ /* trickier case: walk our role's chain until we find
74045+ the role for the start of the current slot's chain */
74046+ tmp = role;
74047+ tmp2 = *curr;
74048+ while (tmp->next && tmp->next != tmp2)
74049+ tmp = tmp->next;
74050+ if (tmp->next == tmp2) {
74051+ /* from example above, we found 3, so just
74052+ replace this slot's chain with ours */
74053+ *curr = role;
74054+ } else {
74055+ /* we didn't find a subset of our role's chain
74056+ in the current slot's chain, so append their
74057+ chain to ours, and set us as the first role in
74058+ the slot's chain
74059+
74060+ we could fold this case with the case above,
74061+ but making it explicit for clarity
74062+ */
74063+ tmp->next = tmp2;
74064+ *curr = role;
74065+ }
74066+ }
74067+ }
74068+
74069+ return;
74070+}
74071+
74072+static void
74073+insert_acl_role_label(struct acl_role_label *role)
74074+{
74075+ int i;
74076+
74077+ if (polstate->role_list == NULL) {
74078+ polstate->role_list = role;
74079+ role->prev = NULL;
74080+ } else {
74081+ role->prev = polstate->role_list;
74082+ polstate->role_list = role;
74083+ }
74084+
74085+ /* used for hash chains */
74086+ role->next = NULL;
74087+
74088+ if (role->roletype & GR_ROLE_DOMAIN) {
74089+ for (i = 0; i < role->domain_child_num; i++)
74090+ __insert_acl_role_label(role, role->domain_children[i]);
74091+ } else
74092+ __insert_acl_role_label(role, role->uidgid);
74093+}
74094+
74095+static int
74096+insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
74097+{
74098+ struct name_entry **curr, *nentry;
74099+ struct inodev_entry *ientry;
74100+ unsigned int len = strlen(name);
74101+ unsigned int key = full_name_hash(name, len);
74102+ unsigned int index = key % polstate->name_set.n_size;
74103+
74104+ curr = &polstate->name_set.n_hash[index];
74105+
74106+ while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
74107+ curr = &((*curr)->next);
74108+
74109+ if (*curr != NULL)
74110+ return 1;
74111+
74112+ nentry = acl_alloc(sizeof (struct name_entry));
74113+ if (nentry == NULL)
74114+ return 0;
74115+ ientry = acl_alloc(sizeof (struct inodev_entry));
74116+ if (ientry == NULL)
74117+ return 0;
74118+ ientry->nentry = nentry;
74119+
74120+ nentry->key = key;
74121+ nentry->name = name;
74122+ nentry->inode = inode;
74123+ nentry->device = device;
74124+ nentry->len = len;
74125+ nentry->deleted = deleted;
74126+
74127+ nentry->prev = NULL;
74128+ curr = &polstate->name_set.n_hash[index];
74129+ if (*curr != NULL)
74130+ (*curr)->prev = nentry;
74131+ nentry->next = *curr;
74132+ *curr = nentry;
74133+
74134+ /* insert us into the table searchable by inode/dev */
74135+ __insert_inodev_entry(polstate, ientry);
74136+
74137+ return 1;
74138+}
74139+
74140+/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
74141+
74142+static void *
74143+create_table(__u32 * len, int elementsize)
74144+{
74145+ unsigned int table_sizes[] = {
74146+ 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
74147+ 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
74148+ 4194301, 8388593, 16777213, 33554393, 67108859
74149+ };
74150+ void *newtable = NULL;
74151+ unsigned int pwr = 0;
74152+
74153+ while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
74154+ table_sizes[pwr] <= *len)
74155+ pwr++;
74156+
74157+ if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
74158+ return newtable;
74159+
74160+ if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
74161+ newtable =
74162+ kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
74163+ else
74164+ newtable = vmalloc(table_sizes[pwr] * elementsize);
74165+
74166+ *len = table_sizes[pwr];
74167+
74168+ return newtable;
74169+}
74170+
74171+static int
74172+init_variables(const struct gr_arg *arg, bool reload)
74173+{
74174+ struct task_struct *reaper = init_pid_ns.child_reaper;
74175+ unsigned int stacksize;
74176+
74177+ polstate->subj_map_set.s_size = arg->role_db.num_subjects;
74178+ polstate->acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
74179+ polstate->name_set.n_size = arg->role_db.num_objects;
74180+ polstate->inodev_set.i_size = arg->role_db.num_objects;
74181+
74182+ if (!polstate->subj_map_set.s_size || !polstate->acl_role_set.r_size ||
74183+ !polstate->name_set.n_size || !polstate->inodev_set.i_size)
74184+ return 1;
74185+
74186+ if (!reload) {
74187+ if (!gr_init_uidset())
74188+ return 1;
74189+ }
74190+
74191+ /* set up the stack that holds allocation info */
74192+
74193+ stacksize = arg->role_db.num_pointers + 5;
74194+
74195+ if (!acl_alloc_stack_init(stacksize))
74196+ return 1;
74197+
74198+ if (!reload) {
74199+ /* grab reference for the real root dentry and vfsmount */
74200+ get_fs_root(reaper->fs, &gr_real_root);
74201+
74202+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
74203+ 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);
74204+#endif
74205+
74206+ fakefs_obj_rw = kzalloc(sizeof(struct acl_object_label), GFP_KERNEL);
74207+ if (fakefs_obj_rw == NULL)
74208+ return 1;
74209+ fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
74210+
74211+ fakefs_obj_rwx = kzalloc(sizeof(struct acl_object_label), GFP_KERNEL);
74212+ if (fakefs_obj_rwx == NULL)
74213+ return 1;
74214+ fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
74215+ }
74216+
74217+ polstate->subj_map_set.s_hash =
74218+ (struct subject_map **) create_table(&polstate->subj_map_set.s_size, sizeof(void *));
74219+ polstate->acl_role_set.r_hash =
74220+ (struct acl_role_label **) create_table(&polstate->acl_role_set.r_size, sizeof(void *));
74221+ polstate->name_set.n_hash = (struct name_entry **) create_table(&polstate->name_set.n_size, sizeof(void *));
74222+ polstate->inodev_set.i_hash =
74223+ (struct inodev_entry **) create_table(&polstate->inodev_set.i_size, sizeof(void *));
74224+
74225+ if (!polstate->subj_map_set.s_hash || !polstate->acl_role_set.r_hash ||
74226+ !polstate->name_set.n_hash || !polstate->inodev_set.i_hash)
74227+ return 1;
74228+
74229+ memset(polstate->subj_map_set.s_hash, 0,
74230+ sizeof(struct subject_map *) * polstate->subj_map_set.s_size);
74231+ memset(polstate->acl_role_set.r_hash, 0,
74232+ sizeof (struct acl_role_label *) * polstate->acl_role_set.r_size);
74233+ memset(polstate->name_set.n_hash, 0,
74234+ sizeof (struct name_entry *) * polstate->name_set.n_size);
74235+ memset(polstate->inodev_set.i_hash, 0,
74236+ sizeof (struct inodev_entry *) * polstate->inodev_set.i_size);
74237+
74238+ return 0;
74239+}
74240+
74241+/* free information not needed after startup
74242+ currently contains user->kernel pointer mappings for subjects
74243+*/
74244+
74245+static void
74246+free_init_variables(void)
74247+{
74248+ __u32 i;
74249+
74250+ if (polstate->subj_map_set.s_hash) {
74251+ for (i = 0; i < polstate->subj_map_set.s_size; i++) {
74252+ if (polstate->subj_map_set.s_hash[i]) {
74253+ kfree(polstate->subj_map_set.s_hash[i]);
74254+ polstate->subj_map_set.s_hash[i] = NULL;
74255+ }
74256+ }
74257+
74258+ if ((polstate->subj_map_set.s_size * sizeof (struct subject_map *)) <=
74259+ PAGE_SIZE)
74260+ kfree(polstate->subj_map_set.s_hash);
74261+ else
74262+ vfree(polstate->subj_map_set.s_hash);
74263+ }
74264+
74265+ return;
74266+}
74267+
74268+static void
74269+free_variables(bool reload)
74270+{
74271+ struct acl_subject_label *s;
74272+ struct acl_role_label *r;
74273+ struct task_struct *task, *task2;
74274+ unsigned int x;
74275+
74276+ if (!reload) {
74277+ gr_clear_learn_entries();
74278+
74279+ read_lock(&tasklist_lock);
74280+ do_each_thread(task2, task) {
74281+ task->acl_sp_role = 0;
74282+ task->acl_role_id = 0;
74283+ task->inherited = 0;
74284+ task->acl = NULL;
74285+ task->role = NULL;
74286+ } while_each_thread(task2, task);
74287+ read_unlock(&tasklist_lock);
74288+
74289+ kfree(fakefs_obj_rw);
74290+ fakefs_obj_rw = NULL;
74291+ kfree(fakefs_obj_rwx);
74292+ fakefs_obj_rwx = NULL;
74293+
74294+ /* release the reference to the real root dentry and vfsmount */
74295+ path_put(&gr_real_root);
74296+ memset(&gr_real_root, 0, sizeof(gr_real_root));
74297+ }
74298+
74299+ /* free all object hash tables */
74300+
74301+ FOR_EACH_ROLE_START(r)
74302+ if (r->subj_hash == NULL)
74303+ goto next_role;
74304+ FOR_EACH_SUBJECT_START(r, s, x)
74305+ if (s->obj_hash == NULL)
74306+ break;
74307+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
74308+ kfree(s->obj_hash);
74309+ else
74310+ vfree(s->obj_hash);
74311+ FOR_EACH_SUBJECT_END(s, x)
74312+ FOR_EACH_NESTED_SUBJECT_START(r, s)
74313+ if (s->obj_hash == NULL)
74314+ break;
74315+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
74316+ kfree(s->obj_hash);
74317+ else
74318+ vfree(s->obj_hash);
74319+ FOR_EACH_NESTED_SUBJECT_END(s)
74320+ if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
74321+ kfree(r->subj_hash);
74322+ else
74323+ vfree(r->subj_hash);
74324+ r->subj_hash = NULL;
74325+next_role:
74326+ FOR_EACH_ROLE_END(r)
74327+
74328+ acl_free_all();
74329+
74330+ if (polstate->acl_role_set.r_hash) {
74331+ if ((polstate->acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
74332+ PAGE_SIZE)
74333+ kfree(polstate->acl_role_set.r_hash);
74334+ else
74335+ vfree(polstate->acl_role_set.r_hash);
74336+ }
74337+ if (polstate->name_set.n_hash) {
74338+ if ((polstate->name_set.n_size * sizeof (struct name_entry *)) <=
74339+ PAGE_SIZE)
74340+ kfree(polstate->name_set.n_hash);
74341+ else
74342+ vfree(polstate->name_set.n_hash);
74343+ }
74344+
74345+ if (polstate->inodev_set.i_hash) {
74346+ if ((polstate->inodev_set.i_size * sizeof (struct inodev_entry *)) <=
74347+ PAGE_SIZE)
74348+ kfree(polstate->inodev_set.i_hash);
74349+ else
74350+ vfree(polstate->inodev_set.i_hash);
74351+ }
74352+
74353+ if (!reload)
74354+ gr_free_uidset();
74355+
74356+ memset(&polstate->name_set, 0, sizeof (struct name_db));
74357+ memset(&polstate->inodev_set, 0, sizeof (struct inodev_db));
74358+ memset(&polstate->acl_role_set, 0, sizeof (struct acl_role_db));
74359+ memset(&polstate->subj_map_set, 0, sizeof (struct acl_subj_map_db));
74360+
74361+ polstate->default_role = NULL;
74362+ polstate->kernel_role = NULL;
74363+ polstate->role_list = NULL;
74364+
74365+ return;
74366+}
74367+
74368+static struct acl_subject_label *
74369+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied);
74370+
74371+static int alloc_and_copy_string(char **name, unsigned int maxlen)
74372+{
74373+ unsigned int len = strnlen_user(*name, maxlen);
74374+ char *tmp;
74375+
74376+ if (!len || len >= maxlen)
74377+ return -EINVAL;
74378+
74379+ if ((tmp = (char *) acl_alloc(len)) == NULL)
74380+ return -ENOMEM;
74381+
74382+ if (copy_from_user(tmp, *name, len))
74383+ return -EFAULT;
74384+
74385+ tmp[len-1] = '\0';
74386+ *name = tmp;
74387+
74388+ return 0;
74389+}
74390+
74391+static int
74392+copy_user_glob(struct acl_object_label *obj)
74393+{
74394+ struct acl_object_label *g_tmp, **guser;
74395+ int error;
74396+
74397+ if (obj->globbed == NULL)
74398+ return 0;
74399+
74400+ guser = &obj->globbed;
74401+ while (*guser) {
74402+ g_tmp = (struct acl_object_label *)
74403+ acl_alloc(sizeof (struct acl_object_label));
74404+ if (g_tmp == NULL)
74405+ return -ENOMEM;
74406+
74407+ if (copy_acl_object_label(g_tmp, *guser))
74408+ return -EFAULT;
74409+
74410+ error = alloc_and_copy_string(&g_tmp->filename, PATH_MAX);
74411+ if (error)
74412+ return error;
74413+
74414+ *guser = g_tmp;
74415+ guser = &(g_tmp->next);
74416+ }
74417+
74418+ return 0;
74419+}
74420+
74421+static int
74422+copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
74423+ struct acl_role_label *role)
74424+{
74425+ struct acl_object_label *o_tmp;
74426+ int ret;
74427+
74428+ while (userp) {
74429+ if ((o_tmp = (struct acl_object_label *)
74430+ acl_alloc(sizeof (struct acl_object_label))) == NULL)
74431+ return -ENOMEM;
74432+
74433+ if (copy_acl_object_label(o_tmp, userp))
74434+ return -EFAULT;
74435+
74436+ userp = o_tmp->prev;
74437+
74438+ ret = alloc_and_copy_string(&o_tmp->filename, PATH_MAX);
74439+ if (ret)
74440+ return ret;
74441+
74442+ insert_acl_obj_label(o_tmp, subj);
74443+ if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
74444+ o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
74445+ return -ENOMEM;
74446+
74447+ ret = copy_user_glob(o_tmp);
74448+ if (ret)
74449+ return ret;
74450+
74451+ if (o_tmp->nested) {
74452+ int already_copied;
74453+
74454+ o_tmp->nested = do_copy_user_subj(o_tmp->nested, role, &already_copied);
74455+ if (IS_ERR(o_tmp->nested))
74456+ return PTR_ERR(o_tmp->nested);
74457+
74458+ /* insert into nested subject list if we haven't copied this one yet
74459+ to prevent duplicate entries */
74460+ if (!already_copied) {
74461+ o_tmp->nested->next = role->hash->first;
74462+ role->hash->first = o_tmp->nested;
74463+ }
74464+ }
74465+ }
74466+
74467+ return 0;
74468+}
74469+
74470+static __u32
74471+count_user_subjs(struct acl_subject_label *userp)
74472+{
74473+ struct acl_subject_label s_tmp;
74474+ __u32 num = 0;
74475+
74476+ while (userp) {
74477+ if (copy_acl_subject_label(&s_tmp, userp))
74478+ break;
74479+
74480+ userp = s_tmp.prev;
74481+ }
74482+
74483+ return num;
74484+}
74485+
74486+static int
74487+copy_user_allowedips(struct acl_role_label *rolep)
74488+{
74489+ struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
74490+
74491+ ruserip = rolep->allowed_ips;
74492+
74493+ while (ruserip) {
74494+ rlast = rtmp;
74495+
74496+ if ((rtmp = (struct role_allowed_ip *)
74497+ acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
74498+ return -ENOMEM;
74499+
74500+ if (copy_role_allowed_ip(rtmp, ruserip))
74501+ return -EFAULT;
74502+
74503+ ruserip = rtmp->prev;
74504+
74505+ if (!rlast) {
74506+ rtmp->prev = NULL;
74507+ rolep->allowed_ips = rtmp;
74508+ } else {
74509+ rlast->next = rtmp;
74510+ rtmp->prev = rlast;
74511+ }
74512+
74513+ if (!ruserip)
74514+ rtmp->next = NULL;
74515+ }
74516+
74517+ return 0;
74518+}
74519+
74520+static int
74521+copy_user_transitions(struct acl_role_label *rolep)
74522+{
74523+ struct role_transition *rusertp, *rtmp = NULL, *rlast;
74524+ int error;
74525+
74526+ rusertp = rolep->transitions;
74527+
74528+ while (rusertp) {
74529+ rlast = rtmp;
74530+
74531+ if ((rtmp = (struct role_transition *)
74532+ acl_alloc(sizeof (struct role_transition))) == NULL)
74533+ return -ENOMEM;
74534+
74535+ if (copy_role_transition(rtmp, rusertp))
74536+ return -EFAULT;
74537+
74538+ rusertp = rtmp->prev;
74539+
74540+ error = alloc_and_copy_string(&rtmp->rolename, GR_SPROLE_LEN);
74541+ if (error)
74542+ return error;
74543+
74544+ if (!rlast) {
74545+ rtmp->prev = NULL;
74546+ rolep->transitions = rtmp;
74547+ } else {
74548+ rlast->next = rtmp;
74549+ rtmp->prev = rlast;
74550+ }
74551+
74552+ if (!rusertp)
74553+ rtmp->next = NULL;
74554+ }
74555+
74556+ return 0;
74557+}
74558+
74559+static __u32 count_user_objs(const struct acl_object_label __user *userp)
74560+{
74561+ struct acl_object_label o_tmp;
74562+ __u32 num = 0;
74563+
74564+ while (userp) {
74565+ if (copy_acl_object_label(&o_tmp, userp))
74566+ break;
74567+
74568+ userp = o_tmp.prev;
74569+ num++;
74570+ }
74571+
74572+ return num;
74573+}
74574+
74575+static struct acl_subject_label *
74576+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied)
74577+{
74578+ struct acl_subject_label *s_tmp = NULL, *s_tmp2;
74579+ __u32 num_objs;
74580+ struct acl_ip_label **i_tmp, *i_utmp2;
74581+ struct gr_hash_struct ghash;
74582+ struct subject_map *subjmap;
74583+ unsigned int i_num;
74584+ int err;
74585+
74586+ if (already_copied != NULL)
74587+ *already_copied = 0;
74588+
74589+ s_tmp = lookup_subject_map(userp);
74590+
74591+ /* we've already copied this subject into the kernel, just return
74592+ the reference to it, and don't copy it over again
74593+ */
74594+ if (s_tmp) {
74595+ if (already_copied != NULL)
74596+ *already_copied = 1;
74597+ return(s_tmp);
74598+ }
74599+
74600+ if ((s_tmp = (struct acl_subject_label *)
74601+ acl_alloc(sizeof (struct acl_subject_label))) == NULL)
74602+ return ERR_PTR(-ENOMEM);
74603+
74604+ subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
74605+ if (subjmap == NULL)
74606+ return ERR_PTR(-ENOMEM);
74607+
74608+ subjmap->user = userp;
74609+ subjmap->kernel = s_tmp;
74610+ insert_subj_map_entry(subjmap);
74611+
74612+ if (copy_acl_subject_label(s_tmp, userp))
74613+ return ERR_PTR(-EFAULT);
74614+
74615+ err = alloc_and_copy_string(&s_tmp->filename, PATH_MAX);
74616+ if (err)
74617+ return ERR_PTR(err);
74618+
74619+ if (!strcmp(s_tmp->filename, "/"))
74620+ role->root_label = s_tmp;
74621+
74622+ if (copy_gr_hash_struct(&ghash, s_tmp->hash))
74623+ return ERR_PTR(-EFAULT);
74624+
74625+ /* copy user and group transition tables */
74626+
74627+ if (s_tmp->user_trans_num) {
74628+ uid_t *uidlist;
74629+
74630+ uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
74631+ if (uidlist == NULL)
74632+ return ERR_PTR(-ENOMEM);
74633+ if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
74634+ return ERR_PTR(-EFAULT);
74635+
74636+ s_tmp->user_transitions = uidlist;
74637+ }
74638+
74639+ if (s_tmp->group_trans_num) {
74640+ gid_t *gidlist;
74641+
74642+ gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
74643+ if (gidlist == NULL)
74644+ return ERR_PTR(-ENOMEM);
74645+ if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
74646+ return ERR_PTR(-EFAULT);
74647+
74648+ s_tmp->group_transitions = gidlist;
74649+ }
74650+
74651+ /* set up object hash table */
74652+ num_objs = count_user_objs(ghash.first);
74653+
74654+ s_tmp->obj_hash_size = num_objs;
74655+ s_tmp->obj_hash =
74656+ (struct acl_object_label **)
74657+ create_table(&(s_tmp->obj_hash_size), sizeof(void *));
74658+
74659+ if (!s_tmp->obj_hash)
74660+ return ERR_PTR(-ENOMEM);
74661+
74662+ memset(s_tmp->obj_hash, 0,
74663+ s_tmp->obj_hash_size *
74664+ sizeof (struct acl_object_label *));
74665+
74666+ /* add in objects */
74667+ err = copy_user_objs(ghash.first, s_tmp, role);
74668+
74669+ if (err)
74670+ return ERR_PTR(err);
74671+
74672+ /* set pointer for parent subject */
74673+ if (s_tmp->parent_subject) {
74674+ s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role, NULL);
74675+
74676+ if (IS_ERR(s_tmp2))
74677+ return s_tmp2;
74678+
74679+ s_tmp->parent_subject = s_tmp2;
74680+ }
74681+
74682+ /* add in ip acls */
74683+
74684+ if (!s_tmp->ip_num) {
74685+ s_tmp->ips = NULL;
74686+ goto insert;
74687+ }
74688+
74689+ i_tmp =
74690+ (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
74691+ sizeof (struct acl_ip_label *));
74692+
74693+ if (!i_tmp)
74694+ return ERR_PTR(-ENOMEM);
74695+
74696+ for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
74697+ *(i_tmp + i_num) =
74698+ (struct acl_ip_label *)
74699+ acl_alloc(sizeof (struct acl_ip_label));
74700+ if (!*(i_tmp + i_num))
74701+ return ERR_PTR(-ENOMEM);
74702+
74703+ if (copy_pointer_from_array(&i_utmp2, i_num, s_tmp->ips))
74704+ return ERR_PTR(-EFAULT);
74705+
74706+ if (copy_acl_ip_label(*(i_tmp + i_num), i_utmp2))
74707+ return ERR_PTR(-EFAULT);
74708+
74709+ if ((*(i_tmp + i_num))->iface == NULL)
74710+ continue;
74711+
74712+ err = alloc_and_copy_string(&(*(i_tmp + i_num))->iface, IFNAMSIZ);
74713+ if (err)
74714+ return ERR_PTR(err);
74715+ }
74716+
74717+ s_tmp->ips = i_tmp;
74718+
74719+insert:
74720+ if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
74721+ s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
74722+ return ERR_PTR(-ENOMEM);
74723+
74724+ return s_tmp;
74725+}
74726+
74727+static int
74728+copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
74729+{
74730+ struct acl_subject_label s_pre;
74731+ struct acl_subject_label * ret;
74732+ int err;
74733+
74734+ while (userp) {
74735+ if (copy_acl_subject_label(&s_pre, userp))
74736+ return -EFAULT;
74737+
74738+ ret = do_copy_user_subj(userp, role, NULL);
74739+
74740+ err = PTR_ERR(ret);
74741+ if (IS_ERR(ret))
74742+ return err;
74743+
74744+ insert_acl_subj_label(ret, role);
74745+
74746+ userp = s_pre.prev;
74747+ }
74748+
74749+ return 0;
74750+}
74751+
74752+static int
74753+copy_user_acl(struct gr_arg *arg)
74754+{
74755+ struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
74756+ struct acl_subject_label *subj_list;
74757+ struct sprole_pw *sptmp;
74758+ struct gr_hash_struct *ghash;
74759+ uid_t *domainlist;
74760+ unsigned int r_num;
74761+ int err = 0;
74762+ __u16 i;
74763+ __u32 num_subjs;
74764+
74765+ /* we need a default and kernel role */
74766+ if (arg->role_db.num_roles < 2)
74767+ return -EINVAL;
74768+
74769+ /* copy special role authentication info from userspace */
74770+
74771+ polstate->num_sprole_pws = arg->num_sprole_pws;
74772+ polstate->acl_special_roles = (struct sprole_pw **) acl_alloc_num(polstate->num_sprole_pws, sizeof(struct sprole_pw *));
74773+
74774+ if (!polstate->acl_special_roles && polstate->num_sprole_pws)
74775+ return -ENOMEM;
74776+
74777+ for (i = 0; i < polstate->num_sprole_pws; i++) {
74778+ sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
74779+ if (!sptmp)
74780+ return -ENOMEM;
74781+ if (copy_sprole_pw(sptmp, i, arg->sprole_pws))
74782+ return -EFAULT;
74783+
74784+ err = alloc_and_copy_string((char **)&sptmp->rolename, GR_SPROLE_LEN);
74785+ if (err)
74786+ return err;
74787+
74788+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
74789+ printk(KERN_ALERT "Copying special role %s\n", sptmp->rolename);
74790+#endif
74791+
74792+ polstate->acl_special_roles[i] = sptmp;
74793+ }
74794+
74795+ r_utmp = (struct acl_role_label **) arg->role_db.r_table;
74796+
74797+ for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
74798+ r_tmp = acl_alloc(sizeof (struct acl_role_label));
74799+
74800+ if (!r_tmp)
74801+ return -ENOMEM;
74802+
74803+ if (copy_pointer_from_array(&r_utmp2, r_num, r_utmp))
74804+ return -EFAULT;
74805+
74806+ if (copy_acl_role_label(r_tmp, r_utmp2))
74807+ return -EFAULT;
74808+
74809+ err = alloc_and_copy_string(&r_tmp->rolename, GR_SPROLE_LEN);
74810+ if (err)
74811+ return err;
74812+
74813+ if (!strcmp(r_tmp->rolename, "default")
74814+ && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
74815+ polstate->default_role = r_tmp;
74816+ } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
74817+ polstate->kernel_role = r_tmp;
74818+ }
74819+
74820+ if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
74821+ return -ENOMEM;
74822+
74823+ if (copy_gr_hash_struct(ghash, r_tmp->hash))
74824+ return -EFAULT;
74825+
74826+ r_tmp->hash = ghash;
74827+
74828+ num_subjs = count_user_subjs(r_tmp->hash->first);
74829+
74830+ r_tmp->subj_hash_size = num_subjs;
74831+ r_tmp->subj_hash =
74832+ (struct acl_subject_label **)
74833+ create_table(&(r_tmp->subj_hash_size), sizeof(void *));
74834+
74835+ if (!r_tmp->subj_hash)
74836+ return -ENOMEM;
74837+
74838+ err = copy_user_allowedips(r_tmp);
74839+ if (err)
74840+ return err;
74841+
74842+ /* copy domain info */
74843+ if (r_tmp->domain_children != NULL) {
74844+ domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
74845+ if (domainlist == NULL)
74846+ return -ENOMEM;
74847+
74848+ if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
74849+ return -EFAULT;
74850+
74851+ r_tmp->domain_children = domainlist;
74852+ }
74853+
74854+ err = copy_user_transitions(r_tmp);
74855+ if (err)
74856+ return err;
74857+
74858+ memset(r_tmp->subj_hash, 0,
74859+ r_tmp->subj_hash_size *
74860+ sizeof (struct acl_subject_label *));
74861+
74862+ /* acquire the list of subjects, then NULL out
74863+ the list prior to parsing the subjects for this role,
74864+ as during this parsing the list is replaced with a list
74865+ of *nested* subjects for the role
74866+ */
74867+ subj_list = r_tmp->hash->first;
74868+
74869+ /* set nested subject list to null */
74870+ r_tmp->hash->first = NULL;
74871+
74872+ err = copy_user_subjs(subj_list, r_tmp);
74873+
74874+ if (err)
74875+ return err;
74876+
74877+ insert_acl_role_label(r_tmp);
74878+ }
74879+
74880+ if (polstate->default_role == NULL || polstate->kernel_role == NULL)
74881+ return -EINVAL;
74882+
74883+ return err;
74884+}
74885+
74886+static int gracl_reload_apply_policies(void *reload)
74887+{
74888+ struct gr_reload_state *reload_state = (struct gr_reload_state *)reload;
74889+ struct task_struct *task, *task2;
74890+ struct acl_role_label *role, *rtmp;
74891+ struct acl_subject_label *subj;
74892+ const struct cred *cred;
74893+ int role_applied;
74894+ int ret = 0;
74895+
74896+ memcpy(&reload_state->oldpolicy, reload_state->oldpolicy_ptr, sizeof(struct gr_policy_state));
74897+ memcpy(&reload_state->oldalloc, reload_state->oldalloc_ptr, sizeof(struct gr_alloc_state));
74898+
74899+ /* first make sure we'll be able to apply the new policy cleanly */
74900+ do_each_thread(task2, task) {
74901+ if (task->exec_file == NULL)
74902+ continue;
74903+ role_applied = 0;
74904+ if (!reload_state->oldmode && task->role->roletype & GR_ROLE_SPECIAL) {
74905+ /* preserve special roles */
74906+ FOR_EACH_ROLE_START(role)
74907+ if ((role->roletype & GR_ROLE_SPECIAL) && !strcmp(task->role->rolename, role->rolename)) {
74908+ rtmp = task->role;
74909+ task->role = role;
74910+ role_applied = 1;
74911+ break;
74912+ }
74913+ FOR_EACH_ROLE_END(role)
74914+ }
74915+ if (!role_applied) {
74916+ cred = __task_cred(task);
74917+ rtmp = task->role;
74918+ task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
74919+ }
74920+ /* this handles non-nested inherited subjects, nested subjects will still
74921+ be dropped currently */
74922+ subj = __gr_get_subject_for_task(polstate, task, task->acl->filename);
74923+ task->tmpacl = __gr_get_subject_for_task(polstate, task, NULL);
74924+ /* change the role back so that we've made no modifications to the policy */
74925+ task->role = rtmp;
74926+
74927+ if (subj == NULL || task->tmpacl == NULL) {
74928+ ret = -EINVAL;
74929+ goto out;
74930+ }
74931+ } while_each_thread(task2, task);
74932+
74933+ /* now actually apply the policy */
74934+
74935+ do_each_thread(task2, task) {
74936+ if (task->exec_file) {
74937+ role_applied = 0;
74938+ if (!reload_state->oldmode && task->role->roletype & GR_ROLE_SPECIAL) {
74939+ /* preserve special roles */
74940+ FOR_EACH_ROLE_START(role)
74941+ if ((role->roletype & GR_ROLE_SPECIAL) && !strcmp(task->role->rolename, role->rolename)) {
74942+ task->role = role;
74943+ role_applied = 1;
74944+ break;
74945+ }
74946+ FOR_EACH_ROLE_END(role)
74947+ }
74948+ if (!role_applied) {
74949+ cred = __task_cred(task);
74950+ task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
74951+ }
74952+ /* this handles non-nested inherited subjects, nested subjects will still
74953+ be dropped currently */
74954+ if (!reload_state->oldmode && task->inherited)
74955+ subj = __gr_get_subject_for_task(polstate, task, task->acl->filename);
74956+ else {
74957+ /* looked up and tagged to the task previously */
74958+ subj = task->tmpacl;
74959+ }
74960+ /* subj will be non-null */
74961+ __gr_apply_subject_to_task(polstate, task, subj);
74962+ if (reload_state->oldmode) {
74963+ task->acl_role_id = 0;
74964+ task->acl_sp_role = 0;
74965+ task->inherited = 0;
74966+ }
74967+ } else {
74968+ // it's a kernel process
74969+ task->role = polstate->kernel_role;
74970+ task->acl = polstate->kernel_role->root_label;
74971+#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
74972+ task->acl->mode &= ~GR_PROCFIND;
74973+#endif
74974+ }
74975+ } while_each_thread(task2, task);
74976+
74977+ memcpy(reload_state->oldpolicy_ptr, &reload_state->newpolicy, sizeof(struct gr_policy_state));
74978+ memcpy(reload_state->oldalloc_ptr, &reload_state->newalloc, sizeof(struct gr_alloc_state));
74979+
74980+out:
74981+
74982+ return ret;
74983+}
74984+
74985+static int gracl_reload(struct gr_arg *args, unsigned char oldmode)
74986+{
74987+ struct gr_reload_state new_reload_state = { };
74988+ int err;
74989+
74990+ new_reload_state.oldpolicy_ptr = polstate;
74991+ new_reload_state.oldalloc_ptr = current_alloc_state;
74992+ new_reload_state.oldmode = oldmode;
74993+
74994+ current_alloc_state = &new_reload_state.newalloc;
74995+ polstate = &new_reload_state.newpolicy;
74996+
74997+ /* everything relevant is now saved off, copy in the new policy */
74998+ if (init_variables(args, true)) {
74999+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
75000+ err = -ENOMEM;
75001+ goto error;
75002+ }
75003+
75004+ err = copy_user_acl(args);
75005+ free_init_variables();
75006+ if (err)
75007+ goto error;
75008+ /* the new policy is copied in, with the old policy available via saved_state
75009+ first go through applying roles, making sure to preserve special roles
75010+ then apply new subjects, making sure to preserve inherited and nested subjects,
75011+ though currently only inherited subjects will be preserved
75012+ */
75013+ err = stop_machine(gracl_reload_apply_policies, &new_reload_state, NULL);
75014+ if (err)
75015+ goto error;
75016+
75017+ /* we've now applied the new policy, so restore the old policy state to free it */
75018+ polstate = &new_reload_state.oldpolicy;
75019+ current_alloc_state = &new_reload_state.oldalloc;
75020+ free_variables(true);
75021+
75022+ /* oldpolicy/oldalloc_ptr point to the new policy/alloc states as they were copied
75023+ to running_polstate/current_alloc_state inside stop_machine
75024+ */
75025+ err = 0;
75026+ goto out;
75027+error:
75028+ /* on error of loading the new policy, we'll just keep the previous
75029+ policy set around
75030+ */
75031+ free_variables(true);
75032+
75033+ /* doesn't affect runtime, but maintains consistent state */
75034+out:
75035+ polstate = new_reload_state.oldpolicy_ptr;
75036+ current_alloc_state = new_reload_state.oldalloc_ptr;
75037+
75038+ return err;
75039+}
75040+
75041+static int
75042+gracl_init(struct gr_arg *args)
75043+{
75044+ int error = 0;
75045+
75046+ memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
75047+ memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
75048+
75049+ if (init_variables(args, false)) {
75050+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
75051+ error = -ENOMEM;
75052+ goto out;
75053+ }
75054+
75055+ error = copy_user_acl(args);
75056+ free_init_variables();
75057+ if (error)
75058+ goto out;
75059+
75060+ error = gr_set_acls(0);
75061+ if (error)
75062+ goto out;
75063+
75064+ gr_enable_rbac_system();
75065+
75066+ return 0;
75067+
75068+out:
75069+ free_variables(false);
75070+ return error;
75071+}
75072+
75073+static int
75074+lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
75075+ unsigned char **sum)
75076+{
75077+ struct acl_role_label *r;
75078+ struct role_allowed_ip *ipp;
75079+ struct role_transition *trans;
75080+ unsigned int i;
75081+ int found = 0;
75082+ u32 curr_ip = current->signal->curr_ip;
75083+
75084+ current->signal->saved_ip = curr_ip;
75085+
75086+ /* check transition table */
75087+
75088+ for (trans = current->role->transitions; trans; trans = trans->next) {
75089+ if (!strcmp(rolename, trans->rolename)) {
75090+ found = 1;
75091+ break;
75092+ }
75093+ }
75094+
75095+ if (!found)
75096+ return 0;
75097+
75098+ /* handle special roles that do not require authentication
75099+ and check ip */
75100+
75101+ FOR_EACH_ROLE_START(r)
75102+ if (!strcmp(rolename, r->rolename) &&
75103+ (r->roletype & GR_ROLE_SPECIAL)) {
75104+ found = 0;
75105+ if (r->allowed_ips != NULL) {
75106+ for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
75107+ if ((ntohl(curr_ip) & ipp->netmask) ==
75108+ (ntohl(ipp->addr) & ipp->netmask))
75109+ found = 1;
75110+ }
75111+ } else
75112+ found = 2;
75113+ if (!found)
75114+ return 0;
75115+
75116+ if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
75117+ ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
75118+ *salt = NULL;
75119+ *sum = NULL;
75120+ return 1;
75121+ }
75122+ }
75123+ FOR_EACH_ROLE_END(r)
75124+
75125+ for (i = 0; i < polstate->num_sprole_pws; i++) {
75126+ if (!strcmp(rolename, polstate->acl_special_roles[i]->rolename)) {
75127+ *salt = polstate->acl_special_roles[i]->salt;
75128+ *sum = polstate->acl_special_roles[i]->sum;
75129+ return 1;
75130+ }
75131+ }
75132+
75133+ return 0;
75134+}
75135+
75136+int gr_check_secure_terminal(struct task_struct *task)
75137+{
75138+ struct task_struct *p, *p2, *p3;
75139+ struct files_struct *files;
75140+ struct fdtable *fdt;
75141+ struct file *our_file = NULL, *file;
75142+ int i;
75143+
75144+ if (task->signal->tty == NULL)
75145+ return 1;
75146+
75147+ files = get_files_struct(task);
75148+ if (files != NULL) {
75149+ rcu_read_lock();
75150+ fdt = files_fdtable(files);
75151+ for (i=0; i < fdt->max_fds; i++) {
75152+ file = fcheck_files(files, i);
75153+ if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
75154+ get_file(file);
75155+ our_file = file;
75156+ }
75157+ }
75158+ rcu_read_unlock();
75159+ put_files_struct(files);
75160+ }
75161+
75162+ if (our_file == NULL)
75163+ return 1;
75164+
75165+ read_lock(&tasklist_lock);
75166+ do_each_thread(p2, p) {
75167+ files = get_files_struct(p);
75168+ if (files == NULL ||
75169+ (p->signal && p->signal->tty == task->signal->tty)) {
75170+ if (files != NULL)
75171+ put_files_struct(files);
75172+ continue;
75173+ }
75174+ rcu_read_lock();
75175+ fdt = files_fdtable(files);
75176+ for (i=0; i < fdt->max_fds; i++) {
75177+ file = fcheck_files(files, i);
75178+ if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
75179+ file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
75180+ p3 = task;
75181+ while (task_pid_nr(p3) > 0) {
75182+ if (p3 == p)
75183+ break;
75184+ p3 = p3->real_parent;
75185+ }
75186+ if (p3 == p)
75187+ break;
75188+ gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
75189+ gr_handle_alertkill(p);
75190+ rcu_read_unlock();
75191+ put_files_struct(files);
75192+ read_unlock(&tasklist_lock);
75193+ fput(our_file);
75194+ return 0;
75195+ }
75196+ }
75197+ rcu_read_unlock();
75198+ put_files_struct(files);
75199+ } while_each_thread(p2, p);
75200+ read_unlock(&tasklist_lock);
75201+
75202+ fput(our_file);
75203+ return 1;
75204+}
75205+
75206+ssize_t
75207+write_grsec_handler(struct file *file, const char __user * buf, size_t count, loff_t *ppos)
75208+{
75209+ struct gr_arg_wrapper uwrap;
75210+ unsigned char *sprole_salt = NULL;
75211+ unsigned char *sprole_sum = NULL;
75212+ int error = 0;
75213+ int error2 = 0;
75214+ size_t req_count = 0;
75215+ unsigned char oldmode = 0;
75216+
75217+ mutex_lock(&gr_dev_mutex);
75218+
75219+ if (gr_acl_is_enabled() && !(current->acl->mode & GR_KERNELAUTH)) {
75220+ error = -EPERM;
75221+ goto out;
75222+ }
75223+
75224+#ifdef CONFIG_COMPAT
75225+ pax_open_kernel();
75226+ if (is_compat_task()) {
75227+ copy_gr_arg_wrapper = &copy_gr_arg_wrapper_compat;
75228+ copy_gr_arg = &copy_gr_arg_compat;
75229+ copy_acl_object_label = &copy_acl_object_label_compat;
75230+ copy_acl_subject_label = &copy_acl_subject_label_compat;
75231+ copy_acl_role_label = &copy_acl_role_label_compat;
75232+ copy_acl_ip_label = &copy_acl_ip_label_compat;
75233+ copy_role_allowed_ip = &copy_role_allowed_ip_compat;
75234+ copy_role_transition = &copy_role_transition_compat;
75235+ copy_sprole_pw = &copy_sprole_pw_compat;
75236+ copy_gr_hash_struct = &copy_gr_hash_struct_compat;
75237+ copy_pointer_from_array = &copy_pointer_from_array_compat;
75238+ get_gr_arg_wrapper_size = &get_gr_arg_wrapper_size_compat;
75239+ } else {
75240+ copy_gr_arg_wrapper = &copy_gr_arg_wrapper_normal;
75241+ copy_gr_arg = &copy_gr_arg_normal;
75242+ copy_acl_object_label = &copy_acl_object_label_normal;
75243+ copy_acl_subject_label = &copy_acl_subject_label_normal;
75244+ copy_acl_role_label = &copy_acl_role_label_normal;
75245+ copy_acl_ip_label = &copy_acl_ip_label_normal;
75246+ copy_role_allowed_ip = &copy_role_allowed_ip_normal;
75247+ copy_role_transition = &copy_role_transition_normal;
75248+ copy_sprole_pw = &copy_sprole_pw_normal;
75249+ copy_gr_hash_struct = &copy_gr_hash_struct_normal;
75250+ copy_pointer_from_array = &copy_pointer_from_array_normal;
75251+ get_gr_arg_wrapper_size = &get_gr_arg_wrapper_size_normal;
75252+ }
75253+ pax_close_kernel();
75254+#endif
75255+
75256+ req_count = get_gr_arg_wrapper_size();
75257+
75258+ if (count != req_count) {
75259+ gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)req_count);
75260+ error = -EINVAL;
75261+ goto out;
75262+ }
75263+
75264+
75265+ if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
75266+ gr_auth_expires = 0;
75267+ gr_auth_attempts = 0;
75268+ }
75269+
75270+ error = copy_gr_arg_wrapper(buf, &uwrap);
75271+ if (error)
75272+ goto out;
75273+
75274+ error = copy_gr_arg(uwrap.arg, gr_usermode);
75275+ if (error)
75276+ goto out;
75277+
75278+ if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_SPROLEPAM &&
75279+ gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
75280+ time_after(gr_auth_expires, get_seconds())) {
75281+ error = -EBUSY;
75282+ goto out;
75283+ }
75284+
75285+ /* if non-root trying to do anything other than use a special role,
75286+ do not attempt authentication, do not count towards authentication
75287+ locking
75288+ */
75289+
75290+ if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_STATUS &&
75291+ gr_usermode->mode != GR_UNSPROLE && gr_usermode->mode != GR_SPROLEPAM &&
75292+ gr_is_global_nonroot(current_uid())) {
75293+ error = -EPERM;
75294+ goto out;
75295+ }
75296+
75297+ /* ensure pw and special role name are null terminated */
75298+
75299+ gr_usermode->pw[GR_PW_LEN - 1] = '\0';
75300+ gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
75301+
75302+ /* Okay.
75303+ * We have our enough of the argument structure..(we have yet
75304+ * to copy_from_user the tables themselves) . Copy the tables
75305+ * only if we need them, i.e. for loading operations. */
75306+
75307+ switch (gr_usermode->mode) {
75308+ case GR_STATUS:
75309+ if (gr_acl_is_enabled()) {
75310+ error = 1;
75311+ if (!gr_check_secure_terminal(current))
75312+ error = 3;
75313+ } else
75314+ error = 2;
75315+ goto out;
75316+ case GR_SHUTDOWN:
75317+ if (gr_acl_is_enabled() && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
75318+ stop_machine(gr_rbac_disable, NULL, NULL);
75319+ free_variables(false);
75320+ memset(gr_usermode, 0, sizeof(struct gr_arg));
75321+ memset(gr_system_salt, 0, GR_SALT_LEN);
75322+ memset(gr_system_sum, 0, GR_SHA_LEN);
75323+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
75324+ } else if (gr_acl_is_enabled()) {
75325+ gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
75326+ error = -EPERM;
75327+ } else {
75328+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
75329+ error = -EAGAIN;
75330+ }
75331+ break;
75332+ case GR_ENABLE:
75333+ if (!gr_acl_is_enabled() && !(error2 = gracl_init(gr_usermode)))
75334+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
75335+ else {
75336+ if (gr_acl_is_enabled())
75337+ error = -EAGAIN;
75338+ else
75339+ error = error2;
75340+ gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
75341+ }
75342+ break;
75343+ case GR_OLDRELOAD:
75344+ oldmode = 1;
75345+ case GR_RELOAD:
75346+ if (!gr_acl_is_enabled()) {
75347+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
75348+ error = -EAGAIN;
75349+ } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
75350+ error2 = gracl_reload(gr_usermode, oldmode);
75351+ if (!error2)
75352+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
75353+ else {
75354+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
75355+ error = error2;
75356+ }
75357+ } else {
75358+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
75359+ error = -EPERM;
75360+ }
75361+ break;
75362+ case GR_SEGVMOD:
75363+ if (unlikely(!gr_acl_is_enabled())) {
75364+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
75365+ error = -EAGAIN;
75366+ break;
75367+ }
75368+
75369+ if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
75370+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
75371+ if (gr_usermode->segv_device && gr_usermode->segv_inode) {
75372+ struct acl_subject_label *segvacl;
75373+ segvacl =
75374+ lookup_acl_subj_label(gr_usermode->segv_inode,
75375+ gr_usermode->segv_device,
75376+ current->role);
75377+ if (segvacl) {
75378+ segvacl->crashes = 0;
75379+ segvacl->expires = 0;
75380+ }
75381+ } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
75382+ gr_remove_uid(gr_usermode->segv_uid);
75383+ }
75384+ } else {
75385+ gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
75386+ error = -EPERM;
75387+ }
75388+ break;
75389+ case GR_SPROLE:
75390+ case GR_SPROLEPAM:
75391+ if (unlikely(!gr_acl_is_enabled())) {
75392+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
75393+ error = -EAGAIN;
75394+ break;
75395+ }
75396+
75397+ if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
75398+ current->role->expires = 0;
75399+ current->role->auth_attempts = 0;
75400+ }
75401+
75402+ if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
75403+ time_after(current->role->expires, get_seconds())) {
75404+ error = -EBUSY;
75405+ goto out;
75406+ }
75407+
75408+ if (lookup_special_role_auth
75409+ (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
75410+ && ((!sprole_salt && !sprole_sum)
75411+ || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
75412+ char *p = "";
75413+ assign_special_role(gr_usermode->sp_role);
75414+ read_lock(&tasklist_lock);
75415+ if (current->real_parent)
75416+ p = current->real_parent->role->rolename;
75417+ read_unlock(&tasklist_lock);
75418+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
75419+ p, acl_sp_role_value);
75420+ } else {
75421+ gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
75422+ error = -EPERM;
75423+ if(!(current->role->auth_attempts++))
75424+ current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
75425+
75426+ goto out;
75427+ }
75428+ break;
75429+ case GR_UNSPROLE:
75430+ if (unlikely(!gr_acl_is_enabled())) {
75431+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
75432+ error = -EAGAIN;
75433+ break;
75434+ }
75435+
75436+ if (current->role->roletype & GR_ROLE_SPECIAL) {
75437+ char *p = "";
75438+ int i = 0;
75439+
75440+ read_lock(&tasklist_lock);
75441+ if (current->real_parent) {
75442+ p = current->real_parent->role->rolename;
75443+ i = current->real_parent->acl_role_id;
75444+ }
75445+ read_unlock(&tasklist_lock);
75446+
75447+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
75448+ gr_set_acls(1);
75449+ } else {
75450+ error = -EPERM;
75451+ goto out;
75452+ }
75453+ break;
75454+ default:
75455+ gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
75456+ error = -EINVAL;
75457+ break;
75458+ }
75459+
75460+ if (error != -EPERM)
75461+ goto out;
75462+
75463+ if(!(gr_auth_attempts++))
75464+ gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
75465+
75466+ out:
75467+ mutex_unlock(&gr_dev_mutex);
75468+
75469+ if (!error)
75470+ error = req_count;
75471+
75472+ return error;
75473+}
75474+
75475+int
75476+gr_set_acls(const int type)
75477+{
75478+ struct task_struct *task, *task2;
75479+ struct acl_role_label *role = current->role;
75480+ struct acl_subject_label *subj;
75481+ __u16 acl_role_id = current->acl_role_id;
75482+ const struct cred *cred;
75483+ int ret;
75484+
75485+ rcu_read_lock();
75486+ read_lock(&tasklist_lock);
75487+ read_lock(&grsec_exec_file_lock);
75488+ do_each_thread(task2, task) {
75489+ /* check to see if we're called from the exit handler,
75490+ if so, only replace ACLs that have inherited the admin
75491+ ACL */
75492+
75493+ if (type && (task->role != role ||
75494+ task->acl_role_id != acl_role_id))
75495+ continue;
75496+
75497+ task->acl_role_id = 0;
75498+ task->acl_sp_role = 0;
75499+ task->inherited = 0;
75500+
75501+ if (task->exec_file) {
75502+ cred = __task_cred(task);
75503+ task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
75504+ subj = __gr_get_subject_for_task(polstate, task, NULL);
75505+ if (subj == NULL) {
75506+ ret = -EINVAL;
75507+ read_unlock(&grsec_exec_file_lock);
75508+ read_unlock(&tasklist_lock);
75509+ rcu_read_unlock();
75510+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task_pid_nr(task));
75511+ return ret;
75512+ }
75513+ __gr_apply_subject_to_task(polstate, task, subj);
75514+ } else {
75515+ // it's a kernel process
75516+ task->role = polstate->kernel_role;
75517+ task->acl = polstate->kernel_role->root_label;
75518+#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
75519+ task->acl->mode &= ~GR_PROCFIND;
75520+#endif
75521+ }
75522+ } while_each_thread(task2, task);
75523+ read_unlock(&grsec_exec_file_lock);
75524+ read_unlock(&tasklist_lock);
75525+ rcu_read_unlock();
75526+
75527+ return 0;
75528+}
75529diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
75530new file mode 100644
75531index 0000000..39645c9
75532--- /dev/null
75533+++ b/grsecurity/gracl_res.c
75534@@ -0,0 +1,68 @@
75535+#include <linux/kernel.h>
75536+#include <linux/sched.h>
75537+#include <linux/gracl.h>
75538+#include <linux/grinternal.h>
75539+
75540+static const char *restab_log[] = {
75541+ [RLIMIT_CPU] = "RLIMIT_CPU",
75542+ [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
75543+ [RLIMIT_DATA] = "RLIMIT_DATA",
75544+ [RLIMIT_STACK] = "RLIMIT_STACK",
75545+ [RLIMIT_CORE] = "RLIMIT_CORE",
75546+ [RLIMIT_RSS] = "RLIMIT_RSS",
75547+ [RLIMIT_NPROC] = "RLIMIT_NPROC",
75548+ [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
75549+ [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
75550+ [RLIMIT_AS] = "RLIMIT_AS",
75551+ [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
75552+ [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
75553+ [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
75554+ [RLIMIT_NICE] = "RLIMIT_NICE",
75555+ [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
75556+ [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
75557+ [GR_CRASH_RES] = "RLIMIT_CRASH"
75558+};
75559+
75560+void
75561+gr_log_resource(const struct task_struct *task,
75562+ const int res, const unsigned long wanted, const int gt)
75563+{
75564+ const struct cred *cred;
75565+ unsigned long rlim;
75566+
75567+ if (!gr_acl_is_enabled() && !grsec_resource_logging)
75568+ return;
75569+
75570+ // not yet supported resource
75571+ if (unlikely(!restab_log[res]))
75572+ return;
75573+
75574+ if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
75575+ rlim = task_rlimit_max(task, res);
75576+ else
75577+ rlim = task_rlimit(task, res);
75578+
75579+ if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
75580+ return;
75581+
75582+ rcu_read_lock();
75583+ cred = __task_cred(task);
75584+
75585+ if (res == RLIMIT_NPROC &&
75586+ (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
75587+ cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
75588+ goto out_rcu_unlock;
75589+ else if (res == RLIMIT_MEMLOCK &&
75590+ cap_raised(cred->cap_effective, CAP_IPC_LOCK))
75591+ goto out_rcu_unlock;
75592+ else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
75593+ goto out_rcu_unlock;
75594+ rcu_read_unlock();
75595+
75596+ gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
75597+
75598+ return;
75599+out_rcu_unlock:
75600+ rcu_read_unlock();
75601+ return;
75602+}
75603diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
75604new file mode 100644
75605index 0000000..2040e61
75606--- /dev/null
75607+++ b/grsecurity/gracl_segv.c
75608@@ -0,0 +1,313 @@
75609+#include <linux/kernel.h>
75610+#include <linux/mm.h>
75611+#include <asm/uaccess.h>
75612+#include <asm/errno.h>
75613+#include <asm/mman.h>
75614+#include <net/sock.h>
75615+#include <linux/file.h>
75616+#include <linux/fs.h>
75617+#include <linux/net.h>
75618+#include <linux/in.h>
75619+#include <linux/slab.h>
75620+#include <linux/types.h>
75621+#include <linux/sched.h>
75622+#include <linux/timer.h>
75623+#include <linux/gracl.h>
75624+#include <linux/grsecurity.h>
75625+#include <linux/grinternal.h>
75626+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
75627+#include <linux/magic.h>
75628+#include <linux/pagemap.h>
75629+#include "../fs/btrfs/async-thread.h"
75630+#include "../fs/btrfs/ctree.h"
75631+#include "../fs/btrfs/btrfs_inode.h"
75632+#endif
75633+
75634+static struct crash_uid *uid_set;
75635+static unsigned short uid_used;
75636+static DEFINE_SPINLOCK(gr_uid_lock);
75637+extern rwlock_t gr_inode_lock;
75638+extern struct acl_subject_label *
75639+ lookup_acl_subj_label(const ino_t inode, const dev_t dev,
75640+ struct acl_role_label *role);
75641+
75642+static inline dev_t __get_dev(const struct dentry *dentry)
75643+{
75644+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
75645+ if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
75646+ return BTRFS_I(dentry->d_inode)->root->anon_dev;
75647+ else
75648+#endif
75649+ return dentry->d_sb->s_dev;
75650+}
75651+
75652+int
75653+gr_init_uidset(void)
75654+{
75655+ uid_set =
75656+ kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
75657+ uid_used = 0;
75658+
75659+ return uid_set ? 1 : 0;
75660+}
75661+
75662+void
75663+gr_free_uidset(void)
75664+{
75665+ if (uid_set) {
75666+ struct crash_uid *tmpset;
75667+ spin_lock(&gr_uid_lock);
75668+ tmpset = uid_set;
75669+ uid_set = NULL;
75670+ uid_used = 0;
75671+ spin_unlock(&gr_uid_lock);
75672+ if (tmpset)
75673+ kfree(tmpset);
75674+ }
75675+
75676+ return;
75677+}
75678+
75679+int
75680+gr_find_uid(const uid_t uid)
75681+{
75682+ struct crash_uid *tmp = uid_set;
75683+ uid_t buid;
75684+ int low = 0, high = uid_used - 1, mid;
75685+
75686+ while (high >= low) {
75687+ mid = (low + high) >> 1;
75688+ buid = tmp[mid].uid;
75689+ if (buid == uid)
75690+ return mid;
75691+ if (buid > uid)
75692+ high = mid - 1;
75693+ if (buid < uid)
75694+ low = mid + 1;
75695+ }
75696+
75697+ return -1;
75698+}
75699+
75700+static __inline__ void
75701+gr_insertsort(void)
75702+{
75703+ unsigned short i, j;
75704+ struct crash_uid index;
75705+
75706+ for (i = 1; i < uid_used; i++) {
75707+ index = uid_set[i];
75708+ j = i;
75709+ while ((j > 0) && uid_set[j - 1].uid > index.uid) {
75710+ uid_set[j] = uid_set[j - 1];
75711+ j--;
75712+ }
75713+ uid_set[j] = index;
75714+ }
75715+
75716+ return;
75717+}
75718+
75719+static __inline__ void
75720+gr_insert_uid(const kuid_t kuid, const unsigned long expires)
75721+{
75722+ int loc;
75723+ uid_t uid = GR_GLOBAL_UID(kuid);
75724+
75725+ if (uid_used == GR_UIDTABLE_MAX)
75726+ return;
75727+
75728+ loc = gr_find_uid(uid);
75729+
75730+ if (loc >= 0) {
75731+ uid_set[loc].expires = expires;
75732+ return;
75733+ }
75734+
75735+ uid_set[uid_used].uid = uid;
75736+ uid_set[uid_used].expires = expires;
75737+ uid_used++;
75738+
75739+ gr_insertsort();
75740+
75741+ return;
75742+}
75743+
75744+void
75745+gr_remove_uid(const unsigned short loc)
75746+{
75747+ unsigned short i;
75748+
75749+ for (i = loc + 1; i < uid_used; i++)
75750+ uid_set[i - 1] = uid_set[i];
75751+
75752+ uid_used--;
75753+
75754+ return;
75755+}
75756+
75757+int
75758+gr_check_crash_uid(const kuid_t kuid)
75759+{
75760+ int loc;
75761+ int ret = 0;
75762+ uid_t uid;
75763+
75764+ if (unlikely(!gr_acl_is_enabled()))
75765+ return 0;
75766+
75767+ uid = GR_GLOBAL_UID(kuid);
75768+
75769+ spin_lock(&gr_uid_lock);
75770+ loc = gr_find_uid(uid);
75771+
75772+ if (loc < 0)
75773+ goto out_unlock;
75774+
75775+ if (time_before_eq(uid_set[loc].expires, get_seconds()))
75776+ gr_remove_uid(loc);
75777+ else
75778+ ret = 1;
75779+
75780+out_unlock:
75781+ spin_unlock(&gr_uid_lock);
75782+ return ret;
75783+}
75784+
75785+static __inline__ int
75786+proc_is_setxid(const struct cred *cred)
75787+{
75788+ if (!uid_eq(cred->uid, cred->euid) || !uid_eq(cred->uid, cred->suid) ||
75789+ !uid_eq(cred->uid, cred->fsuid))
75790+ return 1;
75791+ if (!gid_eq(cred->gid, cred->egid) || !gid_eq(cred->gid, cred->sgid) ||
75792+ !gid_eq(cred->gid, cred->fsgid))
75793+ return 1;
75794+
75795+ return 0;
75796+}
75797+
75798+extern int gr_fake_force_sig(int sig, struct task_struct *t);
75799+
75800+void
75801+gr_handle_crash(struct task_struct *task, const int sig)
75802+{
75803+ struct acl_subject_label *curr;
75804+ struct task_struct *tsk, *tsk2;
75805+ const struct cred *cred;
75806+ const struct cred *cred2;
75807+
75808+ if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
75809+ return;
75810+
75811+ if (unlikely(!gr_acl_is_enabled()))
75812+ return;
75813+
75814+ curr = task->acl;
75815+
75816+ if (!(curr->resmask & (1U << GR_CRASH_RES)))
75817+ return;
75818+
75819+ if (time_before_eq(curr->expires, get_seconds())) {
75820+ curr->expires = 0;
75821+ curr->crashes = 0;
75822+ }
75823+
75824+ curr->crashes++;
75825+
75826+ if (!curr->expires)
75827+ curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
75828+
75829+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
75830+ time_after(curr->expires, get_seconds())) {
75831+ rcu_read_lock();
75832+ cred = __task_cred(task);
75833+ if (gr_is_global_nonroot(cred->uid) && proc_is_setxid(cred)) {
75834+ gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
75835+ spin_lock(&gr_uid_lock);
75836+ gr_insert_uid(cred->uid, curr->expires);
75837+ spin_unlock(&gr_uid_lock);
75838+ curr->expires = 0;
75839+ curr->crashes = 0;
75840+ read_lock(&tasklist_lock);
75841+ do_each_thread(tsk2, tsk) {
75842+ cred2 = __task_cred(tsk);
75843+ if (tsk != task && uid_eq(cred2->uid, cred->uid))
75844+ gr_fake_force_sig(SIGKILL, tsk);
75845+ } while_each_thread(tsk2, tsk);
75846+ read_unlock(&tasklist_lock);
75847+ } else {
75848+ gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
75849+ read_lock(&tasklist_lock);
75850+ read_lock(&grsec_exec_file_lock);
75851+ do_each_thread(tsk2, tsk) {
75852+ if (likely(tsk != task)) {
75853+ // if this thread has the same subject as the one that triggered
75854+ // RES_CRASH and it's the same binary, kill it
75855+ if (tsk->acl == task->acl && gr_is_same_file(tsk->exec_file, task->exec_file))
75856+ gr_fake_force_sig(SIGKILL, tsk);
75857+ }
75858+ } while_each_thread(tsk2, tsk);
75859+ read_unlock(&grsec_exec_file_lock);
75860+ read_unlock(&tasklist_lock);
75861+ }
75862+ rcu_read_unlock();
75863+ }
75864+
75865+ return;
75866+}
75867+
75868+int
75869+gr_check_crash_exec(const struct file *filp)
75870+{
75871+ struct acl_subject_label *curr;
75872+
75873+ if (unlikely(!gr_acl_is_enabled()))
75874+ return 0;
75875+
75876+ read_lock(&gr_inode_lock);
75877+ curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
75878+ __get_dev(filp->f_path.dentry),
75879+ current->role);
75880+ read_unlock(&gr_inode_lock);
75881+
75882+ if (!curr || !(curr->resmask & (1U << GR_CRASH_RES)) ||
75883+ (!curr->crashes && !curr->expires))
75884+ return 0;
75885+
75886+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
75887+ time_after(curr->expires, get_seconds()))
75888+ return 1;
75889+ else if (time_before_eq(curr->expires, get_seconds())) {
75890+ curr->crashes = 0;
75891+ curr->expires = 0;
75892+ }
75893+
75894+ return 0;
75895+}
75896+
75897+void
75898+gr_handle_alertkill(struct task_struct *task)
75899+{
75900+ struct acl_subject_label *curracl;
75901+ __u32 curr_ip;
75902+ struct task_struct *p, *p2;
75903+
75904+ if (unlikely(!gr_acl_is_enabled()))
75905+ return;
75906+
75907+ curracl = task->acl;
75908+ curr_ip = task->signal->curr_ip;
75909+
75910+ if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
75911+ read_lock(&tasklist_lock);
75912+ do_each_thread(p2, p) {
75913+ if (p->signal->curr_ip == curr_ip)
75914+ gr_fake_force_sig(SIGKILL, p);
75915+ } while_each_thread(p2, p);
75916+ read_unlock(&tasklist_lock);
75917+ } else if (curracl->mode & GR_KILLPROC)
75918+ gr_fake_force_sig(SIGKILL, task);
75919+
75920+ return;
75921+}
75922diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
75923new file mode 100644
75924index 0000000..6b0c9cc
75925--- /dev/null
75926+++ b/grsecurity/gracl_shm.c
75927@@ -0,0 +1,40 @@
75928+#include <linux/kernel.h>
75929+#include <linux/mm.h>
75930+#include <linux/sched.h>
75931+#include <linux/file.h>
75932+#include <linux/ipc.h>
75933+#include <linux/gracl.h>
75934+#include <linux/grsecurity.h>
75935+#include <linux/grinternal.h>
75936+
75937+int
75938+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
75939+ const u64 shm_createtime, const kuid_t cuid, const int shmid)
75940+{
75941+ struct task_struct *task;
75942+
75943+ if (!gr_acl_is_enabled())
75944+ return 1;
75945+
75946+ rcu_read_lock();
75947+ read_lock(&tasklist_lock);
75948+
75949+ task = find_task_by_vpid(shm_cprid);
75950+
75951+ if (unlikely(!task))
75952+ task = find_task_by_vpid(shm_lapid);
75953+
75954+ if (unlikely(task && (time_before_eq64(task->start_time, shm_createtime) ||
75955+ (task_pid_nr(task) == shm_lapid)) &&
75956+ (task->acl->mode & GR_PROTSHM) &&
75957+ (task->acl != current->acl))) {
75958+ read_unlock(&tasklist_lock);
75959+ rcu_read_unlock();
75960+ gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, GR_GLOBAL_UID(cuid), shm_cprid, shmid);
75961+ return 0;
75962+ }
75963+ read_unlock(&tasklist_lock);
75964+ rcu_read_unlock();
75965+
75966+ return 1;
75967+}
75968diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
75969new file mode 100644
75970index 0000000..bc0be01
75971--- /dev/null
75972+++ b/grsecurity/grsec_chdir.c
75973@@ -0,0 +1,19 @@
75974+#include <linux/kernel.h>
75975+#include <linux/sched.h>
75976+#include <linux/fs.h>
75977+#include <linux/file.h>
75978+#include <linux/grsecurity.h>
75979+#include <linux/grinternal.h>
75980+
75981+void
75982+gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
75983+{
75984+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
75985+ if ((grsec_enable_chdir && grsec_enable_group &&
75986+ in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
75987+ !grsec_enable_group)) {
75988+ gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
75989+ }
75990+#endif
75991+ return;
75992+}
75993diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
75994new file mode 100644
75995index 0000000..6d99cec
75996--- /dev/null
75997+++ b/grsecurity/grsec_chroot.c
75998@@ -0,0 +1,385 @@
75999+#include <linux/kernel.h>
76000+#include <linux/module.h>
76001+#include <linux/sched.h>
76002+#include <linux/file.h>
76003+#include <linux/fs.h>
76004+#include <linux/mount.h>
76005+#include <linux/types.h>
76006+#include "../fs/mount.h"
76007+#include <linux/grsecurity.h>
76008+#include <linux/grinternal.h>
76009+
76010+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
76011+int gr_init_ran;
76012+#endif
76013+
76014+void gr_set_chroot_entries(struct task_struct *task, const struct path *path)
76015+{
76016+#ifdef CONFIG_GRKERNSEC
76017+ if (task_pid_nr(task) > 1 && path->dentry != init_task.fs->root.dentry &&
76018+ path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root
76019+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
76020+ && gr_init_ran
76021+#endif
76022+ )
76023+ task->gr_is_chrooted = 1;
76024+ else {
76025+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
76026+ if (task_pid_nr(task) == 1 && !gr_init_ran)
76027+ gr_init_ran = 1;
76028+#endif
76029+ task->gr_is_chrooted = 0;
76030+ }
76031+
76032+ task->gr_chroot_dentry = path->dentry;
76033+#endif
76034+ return;
76035+}
76036+
76037+void gr_clear_chroot_entries(struct task_struct *task)
76038+{
76039+#ifdef CONFIG_GRKERNSEC
76040+ task->gr_is_chrooted = 0;
76041+ task->gr_chroot_dentry = NULL;
76042+#endif
76043+ return;
76044+}
76045+
76046+int
76047+gr_handle_chroot_unix(const pid_t pid)
76048+{
76049+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
76050+ struct task_struct *p;
76051+
76052+ if (unlikely(!grsec_enable_chroot_unix))
76053+ return 1;
76054+
76055+ if (likely(!proc_is_chrooted(current)))
76056+ return 1;
76057+
76058+ rcu_read_lock();
76059+ read_lock(&tasklist_lock);
76060+ p = find_task_by_vpid_unrestricted(pid);
76061+ if (unlikely(p && !have_same_root(current, p))) {
76062+ read_unlock(&tasklist_lock);
76063+ rcu_read_unlock();
76064+ gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
76065+ return 0;
76066+ }
76067+ read_unlock(&tasklist_lock);
76068+ rcu_read_unlock();
76069+#endif
76070+ return 1;
76071+}
76072+
76073+int
76074+gr_handle_chroot_nice(void)
76075+{
76076+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
76077+ if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
76078+ gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
76079+ return -EPERM;
76080+ }
76081+#endif
76082+ return 0;
76083+}
76084+
76085+int
76086+gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
76087+{
76088+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
76089+ if (grsec_enable_chroot_nice && (niceval < task_nice(p))
76090+ && proc_is_chrooted(current)) {
76091+ gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, task_pid_nr(p));
76092+ return -EACCES;
76093+ }
76094+#endif
76095+ return 0;
76096+}
76097+
76098+int
76099+gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
76100+{
76101+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
76102+ struct task_struct *p;
76103+ int ret = 0;
76104+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
76105+ return ret;
76106+
76107+ read_lock(&tasklist_lock);
76108+ do_each_pid_task(pid, type, p) {
76109+ if (!have_same_root(current, p)) {
76110+ ret = 1;
76111+ goto out;
76112+ }
76113+ } while_each_pid_task(pid, type, p);
76114+out:
76115+ read_unlock(&tasklist_lock);
76116+ return ret;
76117+#endif
76118+ return 0;
76119+}
76120+
76121+int
76122+gr_pid_is_chrooted(struct task_struct *p)
76123+{
76124+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
76125+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
76126+ return 0;
76127+
76128+ if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
76129+ !have_same_root(current, p)) {
76130+ return 1;
76131+ }
76132+#endif
76133+ return 0;
76134+}
76135+
76136+EXPORT_SYMBOL_GPL(gr_pid_is_chrooted);
76137+
76138+#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
76139+int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
76140+{
76141+ struct path path, currentroot;
76142+ int ret = 0;
76143+
76144+ path.dentry = (struct dentry *)u_dentry;
76145+ path.mnt = (struct vfsmount *)u_mnt;
76146+ get_fs_root(current->fs, &currentroot);
76147+ if (path_is_under(&path, &currentroot))
76148+ ret = 1;
76149+ path_put(&currentroot);
76150+
76151+ return ret;
76152+}
76153+#endif
76154+
76155+int
76156+gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
76157+{
76158+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
76159+ if (!grsec_enable_chroot_fchdir)
76160+ return 1;
76161+
76162+ if (!proc_is_chrooted(current))
76163+ return 1;
76164+ else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
76165+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
76166+ return 0;
76167+ }
76168+#endif
76169+ return 1;
76170+}
76171+
76172+int
76173+gr_chroot_fhandle(void)
76174+{
76175+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
76176+ if (!grsec_enable_chroot_fchdir)
76177+ return 1;
76178+
76179+ if (!proc_is_chrooted(current))
76180+ return 1;
76181+ else {
76182+ gr_log_noargs(GR_DONT_AUDIT, GR_CHROOT_FHANDLE_MSG);
76183+ return 0;
76184+ }
76185+#endif
76186+ return 1;
76187+}
76188+
76189+int
76190+gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
76191+ const u64 shm_createtime)
76192+{
76193+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
76194+ struct task_struct *p;
76195+
76196+ if (unlikely(!grsec_enable_chroot_shmat))
76197+ return 1;
76198+
76199+ if (likely(!proc_is_chrooted(current)))
76200+ return 1;
76201+
76202+ rcu_read_lock();
76203+ read_lock(&tasklist_lock);
76204+
76205+ if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
76206+ if (time_before_eq64(p->start_time, shm_createtime)) {
76207+ if (have_same_root(current, p)) {
76208+ goto allow;
76209+ } else {
76210+ read_unlock(&tasklist_lock);
76211+ rcu_read_unlock();
76212+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
76213+ return 0;
76214+ }
76215+ }
76216+ /* creator exited, pid reuse, fall through to next check */
76217+ }
76218+ if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
76219+ if (unlikely(!have_same_root(current, p))) {
76220+ read_unlock(&tasklist_lock);
76221+ rcu_read_unlock();
76222+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
76223+ return 0;
76224+ }
76225+ }
76226+
76227+allow:
76228+ read_unlock(&tasklist_lock);
76229+ rcu_read_unlock();
76230+#endif
76231+ return 1;
76232+}
76233+
76234+void
76235+gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
76236+{
76237+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
76238+ if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
76239+ gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
76240+#endif
76241+ return;
76242+}
76243+
76244+int
76245+gr_handle_chroot_mknod(const struct dentry *dentry,
76246+ const struct vfsmount *mnt, const int mode)
76247+{
76248+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
76249+ if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
76250+ proc_is_chrooted(current)) {
76251+ gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
76252+ return -EPERM;
76253+ }
76254+#endif
76255+ return 0;
76256+}
76257+
76258+int
76259+gr_handle_chroot_mount(const struct dentry *dentry,
76260+ const struct vfsmount *mnt, const char *dev_name)
76261+{
76262+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
76263+ if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
76264+ gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
76265+ return -EPERM;
76266+ }
76267+#endif
76268+ return 0;
76269+}
76270+
76271+int
76272+gr_handle_chroot_pivot(void)
76273+{
76274+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
76275+ if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
76276+ gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
76277+ return -EPERM;
76278+ }
76279+#endif
76280+ return 0;
76281+}
76282+
76283+int
76284+gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
76285+{
76286+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
76287+ if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
76288+ !gr_is_outside_chroot(dentry, mnt)) {
76289+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
76290+ return -EPERM;
76291+ }
76292+#endif
76293+ return 0;
76294+}
76295+
76296+extern const char *captab_log[];
76297+extern int captab_log_entries;
76298+
76299+int
76300+gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
76301+{
76302+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
76303+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
76304+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
76305+ if (cap_raised(chroot_caps, cap)) {
76306+ if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
76307+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
76308+ }
76309+ return 0;
76310+ }
76311+ }
76312+#endif
76313+ return 1;
76314+}
76315+
76316+int
76317+gr_chroot_is_capable(const int cap)
76318+{
76319+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
76320+ return gr_task_chroot_is_capable(current, current_cred(), cap);
76321+#endif
76322+ return 1;
76323+}
76324+
76325+int
76326+gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
76327+{
76328+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
76329+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
76330+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
76331+ if (cap_raised(chroot_caps, cap)) {
76332+ return 0;
76333+ }
76334+ }
76335+#endif
76336+ return 1;
76337+}
76338+
76339+int
76340+gr_chroot_is_capable_nolog(const int cap)
76341+{
76342+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
76343+ return gr_task_chroot_is_capable_nolog(current, cap);
76344+#endif
76345+ return 1;
76346+}
76347+
76348+int
76349+gr_handle_chroot_sysctl(const int op)
76350+{
76351+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
76352+ if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
76353+ proc_is_chrooted(current))
76354+ return -EACCES;
76355+#endif
76356+ return 0;
76357+}
76358+
76359+void
76360+gr_handle_chroot_chdir(const struct path *path)
76361+{
76362+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
76363+ if (grsec_enable_chroot_chdir)
76364+ set_fs_pwd(current->fs, path);
76365+#endif
76366+ return;
76367+}
76368+
76369+int
76370+gr_handle_chroot_chmod(const struct dentry *dentry,
76371+ const struct vfsmount *mnt, const int mode)
76372+{
76373+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
76374+ /* allow chmod +s on directories, but not files */
76375+ if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
76376+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
76377+ proc_is_chrooted(current)) {
76378+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
76379+ return -EPERM;
76380+ }
76381+#endif
76382+ return 0;
76383+}
76384diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
76385new file mode 100644
76386index 0000000..0f9ac91
76387--- /dev/null
76388+++ b/grsecurity/grsec_disabled.c
76389@@ -0,0 +1,440 @@
76390+#include <linux/kernel.h>
76391+#include <linux/module.h>
76392+#include <linux/sched.h>
76393+#include <linux/file.h>
76394+#include <linux/fs.h>
76395+#include <linux/kdev_t.h>
76396+#include <linux/net.h>
76397+#include <linux/in.h>
76398+#include <linux/ip.h>
76399+#include <linux/skbuff.h>
76400+#include <linux/sysctl.h>
76401+
76402+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
76403+void
76404+pax_set_initial_flags(struct linux_binprm *bprm)
76405+{
76406+ return;
76407+}
76408+#endif
76409+
76410+#ifdef CONFIG_SYSCTL
76411+__u32
76412+gr_handle_sysctl(const struct ctl_table * table, const int op)
76413+{
76414+ return 0;
76415+}
76416+#endif
76417+
76418+#ifdef CONFIG_TASKSTATS
76419+int gr_is_taskstats_denied(int pid)
76420+{
76421+ return 0;
76422+}
76423+#endif
76424+
76425+int
76426+gr_acl_is_enabled(void)
76427+{
76428+ return 0;
76429+}
76430+
76431+int
76432+gr_learn_cap(const struct task_struct *task, const struct cred *cred, const int cap)
76433+{
76434+ return 0;
76435+}
76436+
76437+void
76438+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
76439+{
76440+ return;
76441+}
76442+
76443+int
76444+gr_handle_rawio(const struct inode *inode)
76445+{
76446+ return 0;
76447+}
76448+
76449+void
76450+gr_acl_handle_psacct(struct task_struct *task, const long code)
76451+{
76452+ return;
76453+}
76454+
76455+int
76456+gr_handle_ptrace(struct task_struct *task, const long request)
76457+{
76458+ return 0;
76459+}
76460+
76461+int
76462+gr_handle_proc_ptrace(struct task_struct *task)
76463+{
76464+ return 0;
76465+}
76466+
76467+int
76468+gr_set_acls(const int type)
76469+{
76470+ return 0;
76471+}
76472+
76473+int
76474+gr_check_hidden_task(const struct task_struct *tsk)
76475+{
76476+ return 0;
76477+}
76478+
76479+int
76480+gr_check_protected_task(const struct task_struct *task)
76481+{
76482+ return 0;
76483+}
76484+
76485+int
76486+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
76487+{
76488+ return 0;
76489+}
76490+
76491+void
76492+gr_copy_label(struct task_struct *tsk)
76493+{
76494+ return;
76495+}
76496+
76497+void
76498+gr_set_pax_flags(struct task_struct *task)
76499+{
76500+ return;
76501+}
76502+
76503+int
76504+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
76505+ const int unsafe_share)
76506+{
76507+ return 0;
76508+}
76509+
76510+void
76511+gr_handle_delete(const ino_t ino, const dev_t dev)
76512+{
76513+ return;
76514+}
76515+
76516+void
76517+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
76518+{
76519+ return;
76520+}
76521+
76522+void
76523+gr_handle_crash(struct task_struct *task, const int sig)
76524+{
76525+ return;
76526+}
76527+
76528+int
76529+gr_check_crash_exec(const struct file *filp)
76530+{
76531+ return 0;
76532+}
76533+
76534+int
76535+gr_check_crash_uid(const kuid_t uid)
76536+{
76537+ return 0;
76538+}
76539+
76540+void
76541+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
76542+ struct dentry *old_dentry,
76543+ struct dentry *new_dentry,
76544+ struct vfsmount *mnt, const __u8 replace, unsigned int flags)
76545+{
76546+ return;
76547+}
76548+
76549+int
76550+gr_search_socket(const int family, const int type, const int protocol)
76551+{
76552+ return 1;
76553+}
76554+
76555+int
76556+gr_search_connectbind(const int mode, const struct socket *sock,
76557+ const struct sockaddr_in *addr)
76558+{
76559+ return 0;
76560+}
76561+
76562+void
76563+gr_handle_alertkill(struct task_struct *task)
76564+{
76565+ return;
76566+}
76567+
76568+__u32
76569+gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
76570+{
76571+ return 1;
76572+}
76573+
76574+__u32
76575+gr_acl_handle_hidden_file(const struct dentry * dentry,
76576+ const struct vfsmount * mnt)
76577+{
76578+ return 1;
76579+}
76580+
76581+__u32
76582+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
76583+ int acc_mode)
76584+{
76585+ return 1;
76586+}
76587+
76588+__u32
76589+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
76590+{
76591+ return 1;
76592+}
76593+
76594+__u32
76595+gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
76596+{
76597+ return 1;
76598+}
76599+
76600+int
76601+gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
76602+ unsigned int *vm_flags)
76603+{
76604+ return 1;
76605+}
76606+
76607+__u32
76608+gr_acl_handle_truncate(const struct dentry * dentry,
76609+ const struct vfsmount * mnt)
76610+{
76611+ return 1;
76612+}
76613+
76614+__u32
76615+gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
76616+{
76617+ return 1;
76618+}
76619+
76620+__u32
76621+gr_acl_handle_access(const struct dentry * dentry,
76622+ const struct vfsmount * mnt, const int fmode)
76623+{
76624+ return 1;
76625+}
76626+
76627+__u32
76628+gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
76629+ umode_t *mode)
76630+{
76631+ return 1;
76632+}
76633+
76634+__u32
76635+gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
76636+{
76637+ return 1;
76638+}
76639+
76640+__u32
76641+gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
76642+{
76643+ return 1;
76644+}
76645+
76646+__u32
76647+gr_acl_handle_removexattr(const struct dentry * dentry, const struct vfsmount * mnt)
76648+{
76649+ return 1;
76650+}
76651+
76652+void
76653+grsecurity_init(void)
76654+{
76655+ return;
76656+}
76657+
76658+umode_t gr_acl_umask(void)
76659+{
76660+ return 0;
76661+}
76662+
76663+__u32
76664+gr_acl_handle_mknod(const struct dentry * new_dentry,
76665+ const struct dentry * parent_dentry,
76666+ const struct vfsmount * parent_mnt,
76667+ const int mode)
76668+{
76669+ return 1;
76670+}
76671+
76672+__u32
76673+gr_acl_handle_mkdir(const struct dentry * new_dentry,
76674+ const struct dentry * parent_dentry,
76675+ const struct vfsmount * parent_mnt)
76676+{
76677+ return 1;
76678+}
76679+
76680+__u32
76681+gr_acl_handle_symlink(const struct dentry * new_dentry,
76682+ const struct dentry * parent_dentry,
76683+ const struct vfsmount * parent_mnt, const struct filename *from)
76684+{
76685+ return 1;
76686+}
76687+
76688+__u32
76689+gr_acl_handle_link(const struct dentry * new_dentry,
76690+ const struct dentry * parent_dentry,
76691+ const struct vfsmount * parent_mnt,
76692+ const struct dentry * old_dentry,
76693+ const struct vfsmount * old_mnt, const struct filename *to)
76694+{
76695+ return 1;
76696+}
76697+
76698+int
76699+gr_acl_handle_rename(const struct dentry *new_dentry,
76700+ const struct dentry *parent_dentry,
76701+ const struct vfsmount *parent_mnt,
76702+ const struct dentry *old_dentry,
76703+ const struct inode *old_parent_inode,
76704+ const struct vfsmount *old_mnt, const struct filename *newname,
76705+ unsigned int flags)
76706+{
76707+ return 0;
76708+}
76709+
76710+int
76711+gr_acl_handle_filldir(const struct file *file, const char *name,
76712+ const int namelen, const ino_t ino)
76713+{
76714+ return 1;
76715+}
76716+
76717+int
76718+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
76719+ const u64 shm_createtime, const kuid_t cuid, const int shmid)
76720+{
76721+ return 1;
76722+}
76723+
76724+int
76725+gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
76726+{
76727+ return 0;
76728+}
76729+
76730+int
76731+gr_search_accept(const struct socket *sock)
76732+{
76733+ return 0;
76734+}
76735+
76736+int
76737+gr_search_listen(const struct socket *sock)
76738+{
76739+ return 0;
76740+}
76741+
76742+int
76743+gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
76744+{
76745+ return 0;
76746+}
76747+
76748+__u32
76749+gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
76750+{
76751+ return 1;
76752+}
76753+
76754+__u32
76755+gr_acl_handle_creat(const struct dentry * dentry,
76756+ const struct dentry * p_dentry,
76757+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
76758+ const int imode)
76759+{
76760+ return 1;
76761+}
76762+
76763+void
76764+gr_acl_handle_exit(void)
76765+{
76766+ return;
76767+}
76768+
76769+int
76770+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
76771+{
76772+ return 1;
76773+}
76774+
76775+void
76776+gr_set_role_label(const kuid_t uid, const kgid_t gid)
76777+{
76778+ return;
76779+}
76780+
76781+int
76782+gr_acl_handle_procpidmem(const struct task_struct *task)
76783+{
76784+ return 0;
76785+}
76786+
76787+int
76788+gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
76789+{
76790+ return 0;
76791+}
76792+
76793+int
76794+gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
76795+{
76796+ return 0;
76797+}
76798+
76799+int
76800+gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
76801+{
76802+ return 0;
76803+}
76804+
76805+int
76806+gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
76807+{
76808+ return 0;
76809+}
76810+
76811+int gr_acl_enable_at_secure(void)
76812+{
76813+ return 0;
76814+}
76815+
76816+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
76817+{
76818+ return dentry->d_sb->s_dev;
76819+}
76820+
76821+void gr_put_exec_file(struct task_struct *task)
76822+{
76823+ return;
76824+}
76825+
76826+#ifdef CONFIG_SECURITY
76827+EXPORT_SYMBOL_GPL(gr_check_user_change);
76828+EXPORT_SYMBOL_GPL(gr_check_group_change);
76829+#endif
76830diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
76831new file mode 100644
76832index 0000000..14638ff
76833--- /dev/null
76834+++ b/grsecurity/grsec_exec.c
76835@@ -0,0 +1,188 @@
76836+#include <linux/kernel.h>
76837+#include <linux/sched.h>
76838+#include <linux/file.h>
76839+#include <linux/binfmts.h>
76840+#include <linux/fs.h>
76841+#include <linux/types.h>
76842+#include <linux/grdefs.h>
76843+#include <linux/grsecurity.h>
76844+#include <linux/grinternal.h>
76845+#include <linux/capability.h>
76846+#include <linux/module.h>
76847+#include <linux/compat.h>
76848+
76849+#include <asm/uaccess.h>
76850+
76851+#ifdef CONFIG_GRKERNSEC_EXECLOG
76852+static char gr_exec_arg_buf[132];
76853+static DEFINE_MUTEX(gr_exec_arg_mutex);
76854+#endif
76855+
76856+struct user_arg_ptr {
76857+#ifdef CONFIG_COMPAT
76858+ bool is_compat;
76859+#endif
76860+ union {
76861+ const char __user *const __user *native;
76862+#ifdef CONFIG_COMPAT
76863+ const compat_uptr_t __user *compat;
76864+#endif
76865+ } ptr;
76866+};
76867+
76868+extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
76869+
76870+void
76871+gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
76872+{
76873+#ifdef CONFIG_GRKERNSEC_EXECLOG
76874+ char *grarg = gr_exec_arg_buf;
76875+ unsigned int i, x, execlen = 0;
76876+ char c;
76877+
76878+ if (!((grsec_enable_execlog && grsec_enable_group &&
76879+ in_group_p(grsec_audit_gid))
76880+ || (grsec_enable_execlog && !grsec_enable_group)))
76881+ return;
76882+
76883+ mutex_lock(&gr_exec_arg_mutex);
76884+ memset(grarg, 0, sizeof(gr_exec_arg_buf));
76885+
76886+ for (i = 0; i < bprm->argc && execlen < 128; i++) {
76887+ const char __user *p;
76888+ unsigned int len;
76889+
76890+ p = get_user_arg_ptr(argv, i);
76891+ if (IS_ERR(p))
76892+ goto log;
76893+
76894+ len = strnlen_user(p, 128 - execlen);
76895+ if (len > 128 - execlen)
76896+ len = 128 - execlen;
76897+ else if (len > 0)
76898+ len--;
76899+ if (copy_from_user(grarg + execlen, p, len))
76900+ goto log;
76901+
76902+ /* rewrite unprintable characters */
76903+ for (x = 0; x < len; x++) {
76904+ c = *(grarg + execlen + x);
76905+ if (c < 32 || c > 126)
76906+ *(grarg + execlen + x) = ' ';
76907+ }
76908+
76909+ execlen += len;
76910+ *(grarg + execlen) = ' ';
76911+ *(grarg + execlen + 1) = '\0';
76912+ execlen++;
76913+ }
76914+
76915+ log:
76916+ gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
76917+ bprm->file->f_path.mnt, grarg);
76918+ mutex_unlock(&gr_exec_arg_mutex);
76919+#endif
76920+ return;
76921+}
76922+
76923+#ifdef CONFIG_GRKERNSEC
76924+extern int gr_acl_is_capable(const int cap);
76925+extern int gr_acl_is_capable_nolog(const int cap);
76926+extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
76927+extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
76928+extern int gr_chroot_is_capable(const int cap);
76929+extern int gr_chroot_is_capable_nolog(const int cap);
76930+extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
76931+extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
76932+#endif
76933+
76934+const char *captab_log[] = {
76935+ "CAP_CHOWN",
76936+ "CAP_DAC_OVERRIDE",
76937+ "CAP_DAC_READ_SEARCH",
76938+ "CAP_FOWNER",
76939+ "CAP_FSETID",
76940+ "CAP_KILL",
76941+ "CAP_SETGID",
76942+ "CAP_SETUID",
76943+ "CAP_SETPCAP",
76944+ "CAP_LINUX_IMMUTABLE",
76945+ "CAP_NET_BIND_SERVICE",
76946+ "CAP_NET_BROADCAST",
76947+ "CAP_NET_ADMIN",
76948+ "CAP_NET_RAW",
76949+ "CAP_IPC_LOCK",
76950+ "CAP_IPC_OWNER",
76951+ "CAP_SYS_MODULE",
76952+ "CAP_SYS_RAWIO",
76953+ "CAP_SYS_CHROOT",
76954+ "CAP_SYS_PTRACE",
76955+ "CAP_SYS_PACCT",
76956+ "CAP_SYS_ADMIN",
76957+ "CAP_SYS_BOOT",
76958+ "CAP_SYS_NICE",
76959+ "CAP_SYS_RESOURCE",
76960+ "CAP_SYS_TIME",
76961+ "CAP_SYS_TTY_CONFIG",
76962+ "CAP_MKNOD",
76963+ "CAP_LEASE",
76964+ "CAP_AUDIT_WRITE",
76965+ "CAP_AUDIT_CONTROL",
76966+ "CAP_SETFCAP",
76967+ "CAP_MAC_OVERRIDE",
76968+ "CAP_MAC_ADMIN",
76969+ "CAP_SYSLOG",
76970+ "CAP_WAKE_ALARM",
76971+ "CAP_BLOCK_SUSPEND"
76972+};
76973+
76974+int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
76975+
76976+int gr_is_capable(const int cap)
76977+{
76978+#ifdef CONFIG_GRKERNSEC
76979+ if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
76980+ return 1;
76981+ return 0;
76982+#else
76983+ return 1;
76984+#endif
76985+}
76986+
76987+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
76988+{
76989+#ifdef CONFIG_GRKERNSEC
76990+ if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
76991+ return 1;
76992+ return 0;
76993+#else
76994+ return 1;
76995+#endif
76996+}
76997+
76998+int gr_is_capable_nolog(const int cap)
76999+{
77000+#ifdef CONFIG_GRKERNSEC
77001+ if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
77002+ return 1;
77003+ return 0;
77004+#else
77005+ return 1;
77006+#endif
77007+}
77008+
77009+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
77010+{
77011+#ifdef CONFIG_GRKERNSEC
77012+ if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
77013+ return 1;
77014+ return 0;
77015+#else
77016+ return 1;
77017+#endif
77018+}
77019+
77020+EXPORT_SYMBOL_GPL(gr_is_capable);
77021+EXPORT_SYMBOL_GPL(gr_is_capable_nolog);
77022+EXPORT_SYMBOL_GPL(gr_task_is_capable);
77023+EXPORT_SYMBOL_GPL(gr_task_is_capable_nolog);
77024diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
77025new file mode 100644
77026index 0000000..06cc6ea
77027--- /dev/null
77028+++ b/grsecurity/grsec_fifo.c
77029@@ -0,0 +1,24 @@
77030+#include <linux/kernel.h>
77031+#include <linux/sched.h>
77032+#include <linux/fs.h>
77033+#include <linux/file.h>
77034+#include <linux/grinternal.h>
77035+
77036+int
77037+gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
77038+ const struct dentry *dir, const int flag, const int acc_mode)
77039+{
77040+#ifdef CONFIG_GRKERNSEC_FIFO
77041+ const struct cred *cred = current_cred();
77042+
77043+ if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
77044+ !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
77045+ !uid_eq(dentry->d_inode->i_uid, dir->d_inode->i_uid) &&
77046+ !uid_eq(cred->fsuid, dentry->d_inode->i_uid)) {
77047+ if (!inode_permission(dentry->d_inode, acc_mode))
77048+ 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));
77049+ return -EACCES;
77050+ }
77051+#endif
77052+ return 0;
77053+}
77054diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
77055new file mode 100644
77056index 0000000..8ca18bf
77057--- /dev/null
77058+++ b/grsecurity/grsec_fork.c
77059@@ -0,0 +1,23 @@
77060+#include <linux/kernel.h>
77061+#include <linux/sched.h>
77062+#include <linux/grsecurity.h>
77063+#include <linux/grinternal.h>
77064+#include <linux/errno.h>
77065+
77066+void
77067+gr_log_forkfail(const int retval)
77068+{
77069+#ifdef CONFIG_GRKERNSEC_FORKFAIL
77070+ if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
77071+ switch (retval) {
77072+ case -EAGAIN:
77073+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
77074+ break;
77075+ case -ENOMEM:
77076+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
77077+ break;
77078+ }
77079+ }
77080+#endif
77081+ return;
77082+}
77083diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
77084new file mode 100644
77085index 0000000..b7cb191
77086--- /dev/null
77087+++ b/grsecurity/grsec_init.c
77088@@ -0,0 +1,286 @@
77089+#include <linux/kernel.h>
77090+#include <linux/sched.h>
77091+#include <linux/mm.h>
77092+#include <linux/gracl.h>
77093+#include <linux/slab.h>
77094+#include <linux/vmalloc.h>
77095+#include <linux/percpu.h>
77096+#include <linux/module.h>
77097+
77098+int grsec_enable_ptrace_readexec;
77099+int grsec_enable_setxid;
77100+int grsec_enable_symlinkown;
77101+kgid_t grsec_symlinkown_gid;
77102+int grsec_enable_brute;
77103+int grsec_enable_link;
77104+int grsec_enable_dmesg;
77105+int grsec_enable_harden_ptrace;
77106+int grsec_enable_harden_ipc;
77107+int grsec_enable_fifo;
77108+int grsec_enable_execlog;
77109+int grsec_enable_signal;
77110+int grsec_enable_forkfail;
77111+int grsec_enable_audit_ptrace;
77112+int grsec_enable_time;
77113+int grsec_enable_group;
77114+kgid_t grsec_audit_gid;
77115+int grsec_enable_chdir;
77116+int grsec_enable_mount;
77117+int grsec_enable_rofs;
77118+int grsec_deny_new_usb;
77119+int grsec_enable_chroot_findtask;
77120+int grsec_enable_chroot_mount;
77121+int grsec_enable_chroot_shmat;
77122+int grsec_enable_chroot_fchdir;
77123+int grsec_enable_chroot_double;
77124+int grsec_enable_chroot_pivot;
77125+int grsec_enable_chroot_chdir;
77126+int grsec_enable_chroot_chmod;
77127+int grsec_enable_chroot_mknod;
77128+int grsec_enable_chroot_nice;
77129+int grsec_enable_chroot_execlog;
77130+int grsec_enable_chroot_caps;
77131+int grsec_enable_chroot_sysctl;
77132+int grsec_enable_chroot_unix;
77133+int grsec_enable_tpe;
77134+kgid_t grsec_tpe_gid;
77135+int grsec_enable_blackhole;
77136+#ifdef CONFIG_IPV6_MODULE
77137+EXPORT_SYMBOL_GPL(grsec_enable_blackhole);
77138+#endif
77139+int grsec_lastack_retries;
77140+int grsec_enable_tpe_all;
77141+int grsec_enable_tpe_invert;
77142+int grsec_enable_socket_all;
77143+kgid_t grsec_socket_all_gid;
77144+int grsec_enable_socket_client;
77145+kgid_t grsec_socket_client_gid;
77146+int grsec_enable_socket_server;
77147+kgid_t grsec_socket_server_gid;
77148+int grsec_resource_logging;
77149+int grsec_disable_privio;
77150+int grsec_enable_log_rwxmaps;
77151+int grsec_lock;
77152+
77153+DEFINE_SPINLOCK(grsec_alert_lock);
77154+unsigned long grsec_alert_wtime = 0;
77155+unsigned long grsec_alert_fyet = 0;
77156+
77157+DEFINE_SPINLOCK(grsec_audit_lock);
77158+
77159+DEFINE_RWLOCK(grsec_exec_file_lock);
77160+
77161+char *gr_shared_page[4];
77162+
77163+char *gr_alert_log_fmt;
77164+char *gr_audit_log_fmt;
77165+char *gr_alert_log_buf;
77166+char *gr_audit_log_buf;
77167+
77168+extern struct gr_arg *gr_usermode;
77169+extern unsigned char *gr_system_salt;
77170+extern unsigned char *gr_system_sum;
77171+
77172+void __init
77173+grsecurity_init(void)
77174+{
77175+ int j;
77176+ /* create the per-cpu shared pages */
77177+
77178+#ifdef CONFIG_X86
77179+ memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
77180+#endif
77181+
77182+ for (j = 0; j < 4; j++) {
77183+ gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
77184+ if (gr_shared_page[j] == NULL) {
77185+ panic("Unable to allocate grsecurity shared page");
77186+ return;
77187+ }
77188+ }
77189+
77190+ /* allocate log buffers */
77191+ gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
77192+ if (!gr_alert_log_fmt) {
77193+ panic("Unable to allocate grsecurity alert log format buffer");
77194+ return;
77195+ }
77196+ gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
77197+ if (!gr_audit_log_fmt) {
77198+ panic("Unable to allocate grsecurity audit log format buffer");
77199+ return;
77200+ }
77201+ gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
77202+ if (!gr_alert_log_buf) {
77203+ panic("Unable to allocate grsecurity alert log buffer");
77204+ return;
77205+ }
77206+ gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
77207+ if (!gr_audit_log_buf) {
77208+ panic("Unable to allocate grsecurity audit log buffer");
77209+ return;
77210+ }
77211+
77212+ /* allocate memory for authentication structure */
77213+ gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
77214+ gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
77215+ gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
77216+
77217+ if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
77218+ panic("Unable to allocate grsecurity authentication structure");
77219+ return;
77220+ }
77221+
77222+#ifdef CONFIG_GRKERNSEC_IO
77223+#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
77224+ grsec_disable_privio = 1;
77225+#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
77226+ grsec_disable_privio = 1;
77227+#else
77228+ grsec_disable_privio = 0;
77229+#endif
77230+#endif
77231+
77232+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
77233+ /* for backward compatibility, tpe_invert always defaults to on if
77234+ enabled in the kernel
77235+ */
77236+ grsec_enable_tpe_invert = 1;
77237+#endif
77238+
77239+#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
77240+#ifndef CONFIG_GRKERNSEC_SYSCTL
77241+ grsec_lock = 1;
77242+#endif
77243+
77244+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
77245+ grsec_enable_log_rwxmaps = 1;
77246+#endif
77247+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
77248+ grsec_enable_group = 1;
77249+ grsec_audit_gid = KGIDT_INIT(CONFIG_GRKERNSEC_AUDIT_GID);
77250+#endif
77251+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
77252+ grsec_enable_ptrace_readexec = 1;
77253+#endif
77254+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
77255+ grsec_enable_chdir = 1;
77256+#endif
77257+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
77258+ grsec_enable_harden_ptrace = 1;
77259+#endif
77260+#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
77261+ grsec_enable_harden_ipc = 1;
77262+#endif
77263+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
77264+ grsec_enable_mount = 1;
77265+#endif
77266+#ifdef CONFIG_GRKERNSEC_LINK
77267+ grsec_enable_link = 1;
77268+#endif
77269+#ifdef CONFIG_GRKERNSEC_BRUTE
77270+ grsec_enable_brute = 1;
77271+#endif
77272+#ifdef CONFIG_GRKERNSEC_DMESG
77273+ grsec_enable_dmesg = 1;
77274+#endif
77275+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77276+ grsec_enable_blackhole = 1;
77277+ grsec_lastack_retries = 4;
77278+#endif
77279+#ifdef CONFIG_GRKERNSEC_FIFO
77280+ grsec_enable_fifo = 1;
77281+#endif
77282+#ifdef CONFIG_GRKERNSEC_EXECLOG
77283+ grsec_enable_execlog = 1;
77284+#endif
77285+#ifdef CONFIG_GRKERNSEC_SETXID
77286+ grsec_enable_setxid = 1;
77287+#endif
77288+#ifdef CONFIG_GRKERNSEC_SIGNAL
77289+ grsec_enable_signal = 1;
77290+#endif
77291+#ifdef CONFIG_GRKERNSEC_FORKFAIL
77292+ grsec_enable_forkfail = 1;
77293+#endif
77294+#ifdef CONFIG_GRKERNSEC_TIME
77295+ grsec_enable_time = 1;
77296+#endif
77297+#ifdef CONFIG_GRKERNSEC_RESLOG
77298+ grsec_resource_logging = 1;
77299+#endif
77300+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
77301+ grsec_enable_chroot_findtask = 1;
77302+#endif
77303+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
77304+ grsec_enable_chroot_unix = 1;
77305+#endif
77306+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
77307+ grsec_enable_chroot_mount = 1;
77308+#endif
77309+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
77310+ grsec_enable_chroot_fchdir = 1;
77311+#endif
77312+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
77313+ grsec_enable_chroot_shmat = 1;
77314+#endif
77315+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
77316+ grsec_enable_audit_ptrace = 1;
77317+#endif
77318+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
77319+ grsec_enable_chroot_double = 1;
77320+#endif
77321+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
77322+ grsec_enable_chroot_pivot = 1;
77323+#endif
77324+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
77325+ grsec_enable_chroot_chdir = 1;
77326+#endif
77327+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
77328+ grsec_enable_chroot_chmod = 1;
77329+#endif
77330+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
77331+ grsec_enable_chroot_mknod = 1;
77332+#endif
77333+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
77334+ grsec_enable_chroot_nice = 1;
77335+#endif
77336+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
77337+ grsec_enable_chroot_execlog = 1;
77338+#endif
77339+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
77340+ grsec_enable_chroot_caps = 1;
77341+#endif
77342+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
77343+ grsec_enable_chroot_sysctl = 1;
77344+#endif
77345+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
77346+ grsec_enable_symlinkown = 1;
77347+ grsec_symlinkown_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SYMLINKOWN_GID);
77348+#endif
77349+#ifdef CONFIG_GRKERNSEC_TPE
77350+ grsec_enable_tpe = 1;
77351+ grsec_tpe_gid = KGIDT_INIT(CONFIG_GRKERNSEC_TPE_GID);
77352+#ifdef CONFIG_GRKERNSEC_TPE_ALL
77353+ grsec_enable_tpe_all = 1;
77354+#endif
77355+#endif
77356+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
77357+ grsec_enable_socket_all = 1;
77358+ grsec_socket_all_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_ALL_GID);
77359+#endif
77360+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
77361+ grsec_enable_socket_client = 1;
77362+ grsec_socket_client_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_CLIENT_GID);
77363+#endif
77364+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
77365+ grsec_enable_socket_server = 1;
77366+ grsec_socket_server_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_SERVER_GID);
77367+#endif
77368+#endif
77369+#ifdef CONFIG_GRKERNSEC_DENYUSB_FORCE
77370+ grsec_deny_new_usb = 1;
77371+#endif
77372+
77373+ return;
77374+}
77375diff --git a/grsecurity/grsec_ipc.c b/grsecurity/grsec_ipc.c
77376new file mode 100644
77377index 0000000..1773300
77378--- /dev/null
77379+++ b/grsecurity/grsec_ipc.c
77380@@ -0,0 +1,48 @@
77381+#include <linux/kernel.h>
77382+#include <linux/mm.h>
77383+#include <linux/sched.h>
77384+#include <linux/file.h>
77385+#include <linux/ipc.h>
77386+#include <linux/ipc_namespace.h>
77387+#include <linux/grsecurity.h>
77388+#include <linux/grinternal.h>
77389+
77390+int
77391+gr_ipc_permitted(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, int requested_mode, int granted_mode)
77392+{
77393+#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
77394+ int write;
77395+ int orig_granted_mode;
77396+ kuid_t euid;
77397+ kgid_t egid;
77398+
77399+ if (!grsec_enable_harden_ipc)
77400+ return 1;
77401+
77402+ euid = current_euid();
77403+ egid = current_egid();
77404+
77405+ write = requested_mode & 00002;
77406+ orig_granted_mode = ipcp->mode;
77407+
77408+ if (uid_eq(euid, ipcp->cuid) || uid_eq(euid, ipcp->uid))
77409+ orig_granted_mode >>= 6;
77410+ else {
77411+ /* if likely wrong permissions, lock to user */
77412+ if (orig_granted_mode & 0007)
77413+ orig_granted_mode = 0;
77414+ /* otherwise do a egid-only check */
77415+ else if (gid_eq(egid, ipcp->cgid) || gid_eq(egid, ipcp->gid))
77416+ orig_granted_mode >>= 3;
77417+ /* otherwise, no access */
77418+ else
77419+ orig_granted_mode = 0;
77420+ }
77421+ if (!(requested_mode & ~granted_mode & 0007) && (requested_mode & ~orig_granted_mode & 0007) &&
77422+ !ns_capable_nolog(ns->user_ns, CAP_IPC_OWNER)) {
77423+ gr_log_str_int(GR_DONT_AUDIT, GR_IPC_DENIED_MSG, write ? "write" : "read", GR_GLOBAL_UID(ipcp->cuid));
77424+ return 0;
77425+ }
77426+#endif
77427+ return 1;
77428+}
77429diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
77430new file mode 100644
77431index 0000000..5e05e20
77432--- /dev/null
77433+++ b/grsecurity/grsec_link.c
77434@@ -0,0 +1,58 @@
77435+#include <linux/kernel.h>
77436+#include <linux/sched.h>
77437+#include <linux/fs.h>
77438+#include <linux/file.h>
77439+#include <linux/grinternal.h>
77440+
77441+int gr_handle_symlink_owner(const struct path *link, const struct inode *target)
77442+{
77443+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
77444+ const struct inode *link_inode = link->dentry->d_inode;
77445+
77446+ if (grsec_enable_symlinkown && in_group_p(grsec_symlinkown_gid) &&
77447+ /* ignore root-owned links, e.g. /proc/self */
77448+ gr_is_global_nonroot(link_inode->i_uid) && target &&
77449+ !uid_eq(link_inode->i_uid, target->i_uid)) {
77450+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINKOWNER_MSG, link->dentry, link->mnt, link_inode->i_uid, target->i_uid);
77451+ return 1;
77452+ }
77453+#endif
77454+ return 0;
77455+}
77456+
77457+int
77458+gr_handle_follow_link(const struct inode *parent,
77459+ const struct inode *inode,
77460+ const struct dentry *dentry, const struct vfsmount *mnt)
77461+{
77462+#ifdef CONFIG_GRKERNSEC_LINK
77463+ const struct cred *cred = current_cred();
77464+
77465+ if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
77466+ (parent->i_mode & S_ISVTX) && !uid_eq(parent->i_uid, inode->i_uid) &&
77467+ (parent->i_mode & S_IWOTH) && !uid_eq(cred->fsuid, inode->i_uid)) {
77468+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
77469+ return -EACCES;
77470+ }
77471+#endif
77472+ return 0;
77473+}
77474+
77475+int
77476+gr_handle_hardlink(const struct dentry *dentry,
77477+ const struct vfsmount *mnt,
77478+ struct inode *inode, const int mode, const struct filename *to)
77479+{
77480+#ifdef CONFIG_GRKERNSEC_LINK
77481+ const struct cred *cred = current_cred();
77482+
77483+ if (grsec_enable_link && !uid_eq(cred->fsuid, inode->i_uid) &&
77484+ (!S_ISREG(mode) || is_privileged_binary(dentry) ||
77485+ (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
77486+ !capable(CAP_FOWNER) && gr_is_global_nonroot(cred->uid)) {
77487+ gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to->name);
77488+ return -EPERM;
77489+ }
77490+#endif
77491+ return 0;
77492+}
77493diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
77494new file mode 100644
77495index 0000000..dbe0a6b
77496--- /dev/null
77497+++ b/grsecurity/grsec_log.c
77498@@ -0,0 +1,341 @@
77499+#include <linux/kernel.h>
77500+#include <linux/sched.h>
77501+#include <linux/file.h>
77502+#include <linux/tty.h>
77503+#include <linux/fs.h>
77504+#include <linux/mm.h>
77505+#include <linux/grinternal.h>
77506+
77507+#ifdef CONFIG_TREE_PREEMPT_RCU
77508+#define DISABLE_PREEMPT() preempt_disable()
77509+#define ENABLE_PREEMPT() preempt_enable()
77510+#else
77511+#define DISABLE_PREEMPT()
77512+#define ENABLE_PREEMPT()
77513+#endif
77514+
77515+#define BEGIN_LOCKS(x) \
77516+ DISABLE_PREEMPT(); \
77517+ rcu_read_lock(); \
77518+ read_lock(&tasklist_lock); \
77519+ read_lock(&grsec_exec_file_lock); \
77520+ if (x != GR_DO_AUDIT) \
77521+ spin_lock(&grsec_alert_lock); \
77522+ else \
77523+ spin_lock(&grsec_audit_lock)
77524+
77525+#define END_LOCKS(x) \
77526+ if (x != GR_DO_AUDIT) \
77527+ spin_unlock(&grsec_alert_lock); \
77528+ else \
77529+ spin_unlock(&grsec_audit_lock); \
77530+ read_unlock(&grsec_exec_file_lock); \
77531+ read_unlock(&tasklist_lock); \
77532+ rcu_read_unlock(); \
77533+ ENABLE_PREEMPT(); \
77534+ if (x == GR_DONT_AUDIT) \
77535+ gr_handle_alertkill(current)
77536+
77537+enum {
77538+ FLOODING,
77539+ NO_FLOODING
77540+};
77541+
77542+extern char *gr_alert_log_fmt;
77543+extern char *gr_audit_log_fmt;
77544+extern char *gr_alert_log_buf;
77545+extern char *gr_audit_log_buf;
77546+
77547+static int gr_log_start(int audit)
77548+{
77549+ char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
77550+ char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
77551+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
77552+#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
77553+ unsigned long curr_secs = get_seconds();
77554+
77555+ if (audit == GR_DO_AUDIT)
77556+ goto set_fmt;
77557+
77558+ if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
77559+ grsec_alert_wtime = curr_secs;
77560+ grsec_alert_fyet = 0;
77561+ } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
77562+ && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
77563+ grsec_alert_fyet++;
77564+ } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
77565+ grsec_alert_wtime = curr_secs;
77566+ grsec_alert_fyet++;
77567+ printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
77568+ return FLOODING;
77569+ }
77570+ else return FLOODING;
77571+
77572+set_fmt:
77573+#endif
77574+ memset(buf, 0, PAGE_SIZE);
77575+ if (current->signal->curr_ip && gr_acl_is_enabled()) {
77576+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
77577+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
77578+ } else if (current->signal->curr_ip) {
77579+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
77580+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
77581+ } else if (gr_acl_is_enabled()) {
77582+ sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
77583+ snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
77584+ } else {
77585+ sprintf(fmt, "%s%s", loglevel, "grsec: ");
77586+ strcpy(buf, fmt);
77587+ }
77588+
77589+ return NO_FLOODING;
77590+}
77591+
77592+static void gr_log_middle(int audit, const char *msg, va_list ap)
77593+ __attribute__ ((format (printf, 2, 0)));
77594+
77595+static void gr_log_middle(int audit, const char *msg, va_list ap)
77596+{
77597+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
77598+ unsigned int len = strlen(buf);
77599+
77600+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
77601+
77602+ return;
77603+}
77604+
77605+static void gr_log_middle_varargs(int audit, const char *msg, ...)
77606+ __attribute__ ((format (printf, 2, 3)));
77607+
77608+static void gr_log_middle_varargs(int audit, const char *msg, ...)
77609+{
77610+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
77611+ unsigned int len = strlen(buf);
77612+ va_list ap;
77613+
77614+ va_start(ap, msg);
77615+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
77616+ va_end(ap);
77617+
77618+ return;
77619+}
77620+
77621+static void gr_log_end(int audit, int append_default)
77622+{
77623+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
77624+ if (append_default) {
77625+ struct task_struct *task = current;
77626+ struct task_struct *parent = task->real_parent;
77627+ const struct cred *cred = __task_cred(task);
77628+ const struct cred *pcred = __task_cred(parent);
77629+ unsigned int len = strlen(buf);
77630+
77631+ 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));
77632+ }
77633+
77634+ printk("%s\n", buf);
77635+
77636+ return;
77637+}
77638+
77639+void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
77640+{
77641+ int logtype;
77642+ char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
77643+ char *str1 = NULL, *str2 = NULL, *str3 = NULL;
77644+ void *voidptr = NULL;
77645+ int num1 = 0, num2 = 0;
77646+ unsigned long ulong1 = 0, ulong2 = 0;
77647+ struct dentry *dentry = NULL;
77648+ struct vfsmount *mnt = NULL;
77649+ struct file *file = NULL;
77650+ struct task_struct *task = NULL;
77651+ struct vm_area_struct *vma = NULL;
77652+ const struct cred *cred, *pcred;
77653+ va_list ap;
77654+
77655+ BEGIN_LOCKS(audit);
77656+ logtype = gr_log_start(audit);
77657+ if (logtype == FLOODING) {
77658+ END_LOCKS(audit);
77659+ return;
77660+ }
77661+ va_start(ap, argtypes);
77662+ switch (argtypes) {
77663+ case GR_TTYSNIFF:
77664+ task = va_arg(ap, struct task_struct *);
77665+ 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));
77666+ break;
77667+ case GR_SYSCTL_HIDDEN:
77668+ str1 = va_arg(ap, char *);
77669+ gr_log_middle_varargs(audit, msg, result, str1);
77670+ break;
77671+ case GR_RBAC:
77672+ dentry = va_arg(ap, struct dentry *);
77673+ mnt = va_arg(ap, struct vfsmount *);
77674+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
77675+ break;
77676+ case GR_RBAC_STR:
77677+ dentry = va_arg(ap, struct dentry *);
77678+ mnt = va_arg(ap, struct vfsmount *);
77679+ str1 = va_arg(ap, char *);
77680+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
77681+ break;
77682+ case GR_STR_RBAC:
77683+ str1 = va_arg(ap, char *);
77684+ dentry = va_arg(ap, struct dentry *);
77685+ mnt = va_arg(ap, struct vfsmount *);
77686+ gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
77687+ break;
77688+ case GR_RBAC_MODE2:
77689+ dentry = va_arg(ap, struct dentry *);
77690+ mnt = va_arg(ap, struct vfsmount *);
77691+ str1 = va_arg(ap, char *);
77692+ str2 = va_arg(ap, char *);
77693+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
77694+ break;
77695+ case GR_RBAC_MODE3:
77696+ dentry = va_arg(ap, struct dentry *);
77697+ mnt = va_arg(ap, struct vfsmount *);
77698+ str1 = va_arg(ap, char *);
77699+ str2 = va_arg(ap, char *);
77700+ str3 = va_arg(ap, char *);
77701+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
77702+ break;
77703+ case GR_FILENAME:
77704+ dentry = va_arg(ap, struct dentry *);
77705+ mnt = va_arg(ap, struct vfsmount *);
77706+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
77707+ break;
77708+ case GR_STR_FILENAME:
77709+ str1 = va_arg(ap, char *);
77710+ dentry = va_arg(ap, struct dentry *);
77711+ mnt = va_arg(ap, struct vfsmount *);
77712+ gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
77713+ break;
77714+ case GR_FILENAME_STR:
77715+ dentry = va_arg(ap, struct dentry *);
77716+ mnt = va_arg(ap, struct vfsmount *);
77717+ str1 = va_arg(ap, char *);
77718+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
77719+ break;
77720+ case GR_FILENAME_TWO_INT:
77721+ dentry = va_arg(ap, struct dentry *);
77722+ mnt = va_arg(ap, struct vfsmount *);
77723+ num1 = va_arg(ap, int);
77724+ num2 = va_arg(ap, int);
77725+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
77726+ break;
77727+ case GR_FILENAME_TWO_INT_STR:
77728+ dentry = va_arg(ap, struct dentry *);
77729+ mnt = va_arg(ap, struct vfsmount *);
77730+ num1 = va_arg(ap, int);
77731+ num2 = va_arg(ap, int);
77732+ str1 = va_arg(ap, char *);
77733+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
77734+ break;
77735+ case GR_TEXTREL:
77736+ file = va_arg(ap, struct file *);
77737+ ulong1 = va_arg(ap, unsigned long);
77738+ ulong2 = va_arg(ap, unsigned long);
77739+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
77740+ break;
77741+ case GR_PTRACE:
77742+ task = va_arg(ap, struct task_struct *);
77743+ 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));
77744+ break;
77745+ case GR_RESOURCE:
77746+ task = va_arg(ap, struct task_struct *);
77747+ cred = __task_cred(task);
77748+ pcred = __task_cred(task->real_parent);
77749+ ulong1 = va_arg(ap, unsigned long);
77750+ str1 = va_arg(ap, char *);
77751+ ulong2 = va_arg(ap, unsigned long);
77752+ 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));
77753+ break;
77754+ case GR_CAP:
77755+ task = va_arg(ap, struct task_struct *);
77756+ cred = __task_cred(task);
77757+ pcred = __task_cred(task->real_parent);
77758+ str1 = va_arg(ap, char *);
77759+ 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));
77760+ break;
77761+ case GR_SIG:
77762+ str1 = va_arg(ap, char *);
77763+ voidptr = va_arg(ap, void *);
77764+ gr_log_middle_varargs(audit, msg, str1, voidptr);
77765+ break;
77766+ case GR_SIG2:
77767+ task = va_arg(ap, struct task_struct *);
77768+ cred = __task_cred(task);
77769+ pcred = __task_cred(task->real_parent);
77770+ num1 = va_arg(ap, int);
77771+ 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));
77772+ break;
77773+ case GR_CRASH1:
77774+ task = va_arg(ap, struct task_struct *);
77775+ cred = __task_cred(task);
77776+ pcred = __task_cred(task->real_parent);
77777+ ulong1 = va_arg(ap, unsigned long);
77778+ 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);
77779+ break;
77780+ case GR_CRASH2:
77781+ task = va_arg(ap, struct task_struct *);
77782+ cred = __task_cred(task);
77783+ pcred = __task_cred(task->real_parent);
77784+ ulong1 = va_arg(ap, unsigned long);
77785+ 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);
77786+ break;
77787+ case GR_RWXMAP:
77788+ file = va_arg(ap, struct file *);
77789+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
77790+ break;
77791+ case GR_RWXMAPVMA:
77792+ vma = va_arg(ap, struct vm_area_struct *);
77793+ if (vma->vm_file)
77794+ str1 = gr_to_filename(vma->vm_file->f_path.dentry, vma->vm_file->f_path.mnt);
77795+ else if (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP))
77796+ str1 = "<stack>";
77797+ else if (vma->vm_start <= current->mm->brk &&
77798+ vma->vm_end >= current->mm->start_brk)
77799+ str1 = "<heap>";
77800+ else
77801+ str1 = "<anonymous mapping>";
77802+ gr_log_middle_varargs(audit, msg, str1);
77803+ break;
77804+ case GR_PSACCT:
77805+ {
77806+ unsigned int wday, cday;
77807+ __u8 whr, chr;
77808+ __u8 wmin, cmin;
77809+ __u8 wsec, csec;
77810+ char cur_tty[64] = { 0 };
77811+ char parent_tty[64] = { 0 };
77812+
77813+ task = va_arg(ap, struct task_struct *);
77814+ wday = va_arg(ap, unsigned int);
77815+ cday = va_arg(ap, unsigned int);
77816+ whr = va_arg(ap, int);
77817+ chr = va_arg(ap, int);
77818+ wmin = va_arg(ap, int);
77819+ cmin = va_arg(ap, int);
77820+ wsec = va_arg(ap, int);
77821+ csec = va_arg(ap, int);
77822+ ulong1 = va_arg(ap, unsigned long);
77823+ cred = __task_cred(task);
77824+ pcred = __task_cred(task->real_parent);
77825+
77826+ 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));
77827+ }
77828+ break;
77829+ default:
77830+ gr_log_middle(audit, msg, ap);
77831+ }
77832+ va_end(ap);
77833+ // these don't need DEFAULTSECARGS printed on the end
77834+ if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
77835+ gr_log_end(audit, 0);
77836+ else
77837+ gr_log_end(audit, 1);
77838+ END_LOCKS(audit);
77839+}
77840diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
77841new file mode 100644
77842index 0000000..0e39d8c
77843--- /dev/null
77844+++ b/grsecurity/grsec_mem.c
77845@@ -0,0 +1,48 @@
77846+#include <linux/kernel.h>
77847+#include <linux/sched.h>
77848+#include <linux/mm.h>
77849+#include <linux/mman.h>
77850+#include <linux/module.h>
77851+#include <linux/grinternal.h>
77852+
77853+void gr_handle_msr_write(void)
77854+{
77855+ gr_log_noargs(GR_DONT_AUDIT, GR_MSRWRITE_MSG);
77856+ return;
77857+}
77858+EXPORT_SYMBOL_GPL(gr_handle_msr_write);
77859+
77860+void
77861+gr_handle_ioperm(void)
77862+{
77863+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
77864+ return;
77865+}
77866+
77867+void
77868+gr_handle_iopl(void)
77869+{
77870+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
77871+ return;
77872+}
77873+
77874+void
77875+gr_handle_mem_readwrite(u64 from, u64 to)
77876+{
77877+ gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
77878+ return;
77879+}
77880+
77881+void
77882+gr_handle_vm86(void)
77883+{
77884+ gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
77885+ return;
77886+}
77887+
77888+void
77889+gr_log_badprocpid(const char *entry)
77890+{
77891+ gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
77892+ return;
77893+}
77894diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
77895new file mode 100644
77896index 0000000..6f9eb73
77897--- /dev/null
77898+++ b/grsecurity/grsec_mount.c
77899@@ -0,0 +1,65 @@
77900+#include <linux/kernel.h>
77901+#include <linux/sched.h>
77902+#include <linux/mount.h>
77903+#include <linux/major.h>
77904+#include <linux/grsecurity.h>
77905+#include <linux/grinternal.h>
77906+
77907+void
77908+gr_log_remount(const char *devname, const int retval)
77909+{
77910+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
77911+ if (grsec_enable_mount && (retval >= 0))
77912+ gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
77913+#endif
77914+ return;
77915+}
77916+
77917+void
77918+gr_log_unmount(const char *devname, const int retval)
77919+{
77920+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
77921+ if (grsec_enable_mount && (retval >= 0))
77922+ gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
77923+#endif
77924+ return;
77925+}
77926+
77927+void
77928+gr_log_mount(const char *from, struct path *to, const int retval)
77929+{
77930+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
77931+ if (grsec_enable_mount && (retval >= 0))
77932+ gr_log_str_fs(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to->dentry, to->mnt);
77933+#endif
77934+ return;
77935+}
77936+
77937+int
77938+gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
77939+{
77940+#ifdef CONFIG_GRKERNSEC_ROFS
77941+ if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
77942+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
77943+ return -EPERM;
77944+ } else
77945+ return 0;
77946+#endif
77947+ return 0;
77948+}
77949+
77950+int
77951+gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
77952+{
77953+#ifdef CONFIG_GRKERNSEC_ROFS
77954+ struct inode *inode = dentry->d_inode;
77955+
77956+ if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
77957+ inode && (S_ISBLK(inode->i_mode) || (S_ISCHR(inode->i_mode) && imajor(inode) == RAW_MAJOR))) {
77958+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
77959+ return -EPERM;
77960+ } else
77961+ return 0;
77962+#endif
77963+ return 0;
77964+}
77965diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
77966new file mode 100644
77967index 0000000..6ee9d50
77968--- /dev/null
77969+++ b/grsecurity/grsec_pax.c
77970@@ -0,0 +1,45 @@
77971+#include <linux/kernel.h>
77972+#include <linux/sched.h>
77973+#include <linux/mm.h>
77974+#include <linux/file.h>
77975+#include <linux/grinternal.h>
77976+#include <linux/grsecurity.h>
77977+
77978+void
77979+gr_log_textrel(struct vm_area_struct * vma)
77980+{
77981+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
77982+ if (grsec_enable_log_rwxmaps)
77983+ gr_log_textrel_ulong_ulong(GR_DONT_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
77984+#endif
77985+ return;
77986+}
77987+
77988+void gr_log_ptgnustack(struct file *file)
77989+{
77990+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
77991+ if (grsec_enable_log_rwxmaps)
77992+ gr_log_rwxmap(GR_DONT_AUDIT, GR_PTGNUSTACK_MSG, file);
77993+#endif
77994+ return;
77995+}
77996+
77997+void
77998+gr_log_rwxmmap(struct file *file)
77999+{
78000+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
78001+ if (grsec_enable_log_rwxmaps)
78002+ gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
78003+#endif
78004+ return;
78005+}
78006+
78007+void
78008+gr_log_rwxmprotect(struct vm_area_struct *vma)
78009+{
78010+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
78011+ if (grsec_enable_log_rwxmaps)
78012+ gr_log_rwxmap_vma(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, vma);
78013+#endif
78014+ return;
78015+}
78016diff --git a/grsecurity/grsec_proc.c b/grsecurity/grsec_proc.c
78017new file mode 100644
78018index 0000000..2005a3a
78019--- /dev/null
78020+++ b/grsecurity/grsec_proc.c
78021@@ -0,0 +1,20 @@
78022+#include <linux/kernel.h>
78023+#include <linux/sched.h>
78024+#include <linux/grsecurity.h>
78025+#include <linux/grinternal.h>
78026+
78027+int gr_proc_is_restricted(void)
78028+{
78029+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
78030+ const struct cred *cred = current_cred();
78031+#endif
78032+
78033+#ifdef CONFIG_GRKERNSEC_PROC_USER
78034+ if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID))
78035+ return -EACCES;
78036+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
78037+ if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID) && !in_group_p(grsec_proc_gid))
78038+ return -EACCES;
78039+#endif
78040+ return 0;
78041+}
78042diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
78043new file mode 100644
78044index 0000000..f7f29aa
78045--- /dev/null
78046+++ b/grsecurity/grsec_ptrace.c
78047@@ -0,0 +1,30 @@
78048+#include <linux/kernel.h>
78049+#include <linux/sched.h>
78050+#include <linux/grinternal.h>
78051+#include <linux/security.h>
78052+
78053+void
78054+gr_audit_ptrace(struct task_struct *task)
78055+{
78056+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
78057+ if (grsec_enable_audit_ptrace)
78058+ gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
78059+#endif
78060+ return;
78061+}
78062+
78063+int
78064+gr_ptrace_readexec(struct file *file, int unsafe_flags)
78065+{
78066+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
78067+ const struct dentry *dentry = file->f_path.dentry;
78068+ const struct vfsmount *mnt = file->f_path.mnt;
78069+
78070+ if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
78071+ (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
78072+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
78073+ return -EACCES;
78074+ }
78075+#endif
78076+ return 0;
78077+}
78078diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
78079new file mode 100644
78080index 0000000..3860c7e
78081--- /dev/null
78082+++ b/grsecurity/grsec_sig.c
78083@@ -0,0 +1,236 @@
78084+#include <linux/kernel.h>
78085+#include <linux/sched.h>
78086+#include <linux/fs.h>
78087+#include <linux/delay.h>
78088+#include <linux/grsecurity.h>
78089+#include <linux/grinternal.h>
78090+#include <linux/hardirq.h>
78091+
78092+char *signames[] = {
78093+ [SIGSEGV] = "Segmentation fault",
78094+ [SIGILL] = "Illegal instruction",
78095+ [SIGABRT] = "Abort",
78096+ [SIGBUS] = "Invalid alignment/Bus error"
78097+};
78098+
78099+void
78100+gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
78101+{
78102+#ifdef CONFIG_GRKERNSEC_SIGNAL
78103+ if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
78104+ (sig == SIGABRT) || (sig == SIGBUS))) {
78105+ if (task_pid_nr(t) == task_pid_nr(current)) {
78106+ gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
78107+ } else {
78108+ gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
78109+ }
78110+ }
78111+#endif
78112+ return;
78113+}
78114+
78115+int
78116+gr_handle_signal(const struct task_struct *p, const int sig)
78117+{
78118+#ifdef CONFIG_GRKERNSEC
78119+ /* ignore the 0 signal for protected task checks */
78120+ if (task_pid_nr(current) > 1 && sig && gr_check_protected_task(p)) {
78121+ gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
78122+ return -EPERM;
78123+ } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
78124+ return -EPERM;
78125+ }
78126+#endif
78127+ return 0;
78128+}
78129+
78130+#ifdef CONFIG_GRKERNSEC
78131+extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
78132+
78133+int gr_fake_force_sig(int sig, struct task_struct *t)
78134+{
78135+ unsigned long int flags;
78136+ int ret, blocked, ignored;
78137+ struct k_sigaction *action;
78138+
78139+ spin_lock_irqsave(&t->sighand->siglock, flags);
78140+ action = &t->sighand->action[sig-1];
78141+ ignored = action->sa.sa_handler == SIG_IGN;
78142+ blocked = sigismember(&t->blocked, sig);
78143+ if (blocked || ignored) {
78144+ action->sa.sa_handler = SIG_DFL;
78145+ if (blocked) {
78146+ sigdelset(&t->blocked, sig);
78147+ recalc_sigpending_and_wake(t);
78148+ }
78149+ }
78150+ if (action->sa.sa_handler == SIG_DFL)
78151+ t->signal->flags &= ~SIGNAL_UNKILLABLE;
78152+ ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
78153+
78154+ spin_unlock_irqrestore(&t->sighand->siglock, flags);
78155+
78156+ return ret;
78157+}
78158+#endif
78159+
78160+#define GR_USER_BAN_TIME (15 * 60)
78161+#define GR_DAEMON_BRUTE_TIME (30 * 60)
78162+
78163+void gr_handle_brute_attach(int dumpable)
78164+{
78165+#ifdef CONFIG_GRKERNSEC_BRUTE
78166+ struct task_struct *p = current;
78167+ kuid_t uid = GLOBAL_ROOT_UID;
78168+ int daemon = 0;
78169+
78170+ if (!grsec_enable_brute)
78171+ return;
78172+
78173+ rcu_read_lock();
78174+ read_lock(&tasklist_lock);
78175+ read_lock(&grsec_exec_file_lock);
78176+ if (p->real_parent && gr_is_same_file(p->real_parent->exec_file, p->exec_file)) {
78177+ p->real_parent->brute_expires = get_seconds() + GR_DAEMON_BRUTE_TIME;
78178+ p->real_parent->brute = 1;
78179+ daemon = 1;
78180+ } else {
78181+ const struct cred *cred = __task_cred(p), *cred2;
78182+ struct task_struct *tsk, *tsk2;
78183+
78184+ if (dumpable != SUID_DUMP_USER && gr_is_global_nonroot(cred->uid)) {
78185+ struct user_struct *user;
78186+
78187+ uid = cred->uid;
78188+
78189+ /* this is put upon execution past expiration */
78190+ user = find_user(uid);
78191+ if (user == NULL)
78192+ goto unlock;
78193+ user->suid_banned = 1;
78194+ user->suid_ban_expires = get_seconds() + GR_USER_BAN_TIME;
78195+ if (user->suid_ban_expires == ~0UL)
78196+ user->suid_ban_expires--;
78197+
78198+ /* only kill other threads of the same binary, from the same user */
78199+ do_each_thread(tsk2, tsk) {
78200+ cred2 = __task_cred(tsk);
78201+ if (tsk != p && uid_eq(cred2->uid, uid) && gr_is_same_file(tsk->exec_file, p->exec_file))
78202+ gr_fake_force_sig(SIGKILL, tsk);
78203+ } while_each_thread(tsk2, tsk);
78204+ }
78205+ }
78206+unlock:
78207+ read_unlock(&grsec_exec_file_lock);
78208+ read_unlock(&tasklist_lock);
78209+ rcu_read_unlock();
78210+
78211+ if (gr_is_global_nonroot(uid))
78212+ 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);
78213+ else if (daemon)
78214+ gr_log_noargs(GR_DONT_AUDIT, GR_BRUTE_DAEMON_MSG);
78215+
78216+#endif
78217+ return;
78218+}
78219+
78220+void gr_handle_brute_check(void)
78221+{
78222+#ifdef CONFIG_GRKERNSEC_BRUTE
78223+ struct task_struct *p = current;
78224+
78225+ if (unlikely(p->brute)) {
78226+ if (!grsec_enable_brute)
78227+ p->brute = 0;
78228+ else if (time_before(get_seconds(), p->brute_expires))
78229+ msleep(30 * 1000);
78230+ }
78231+#endif
78232+ return;
78233+}
78234+
78235+void gr_handle_kernel_exploit(void)
78236+{
78237+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
78238+ const struct cred *cred;
78239+ struct task_struct *tsk, *tsk2;
78240+ struct user_struct *user;
78241+ kuid_t uid;
78242+
78243+ if (in_irq() || in_serving_softirq() || in_nmi())
78244+ panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
78245+
78246+ uid = current_uid();
78247+
78248+ if (gr_is_global_root(uid))
78249+ panic("grsec: halting the system due to suspicious kernel crash caused by root");
78250+ else {
78251+ /* kill all the processes of this user, hold a reference
78252+ to their creds struct, and prevent them from creating
78253+ another process until system reset
78254+ */
78255+ printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n",
78256+ GR_GLOBAL_UID(uid));
78257+ /* we intentionally leak this ref */
78258+ user = get_uid(current->cred->user);
78259+ if (user)
78260+ user->kernel_banned = 1;
78261+
78262+ /* kill all processes of this user */
78263+ read_lock(&tasklist_lock);
78264+ do_each_thread(tsk2, tsk) {
78265+ cred = __task_cred(tsk);
78266+ if (uid_eq(cred->uid, uid))
78267+ gr_fake_force_sig(SIGKILL, tsk);
78268+ } while_each_thread(tsk2, tsk);
78269+ read_unlock(&tasklist_lock);
78270+ }
78271+#endif
78272+}
78273+
78274+#ifdef CONFIG_GRKERNSEC_BRUTE
78275+static bool suid_ban_expired(struct user_struct *user)
78276+{
78277+ if (user->suid_ban_expires != ~0UL && time_after_eq(get_seconds(), user->suid_ban_expires)) {
78278+ user->suid_banned = 0;
78279+ user->suid_ban_expires = 0;
78280+ free_uid(user);
78281+ return true;
78282+ }
78283+
78284+ return false;
78285+}
78286+#endif
78287+
78288+int gr_process_kernel_exec_ban(void)
78289+{
78290+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
78291+ if (unlikely(current->cred->user->kernel_banned))
78292+ return -EPERM;
78293+#endif
78294+ return 0;
78295+}
78296+
78297+int gr_process_kernel_setuid_ban(struct user_struct *user)
78298+{
78299+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
78300+ if (unlikely(user->kernel_banned))
78301+ gr_fake_force_sig(SIGKILL, current);
78302+#endif
78303+ return 0;
78304+}
78305+
78306+int gr_process_suid_exec_ban(const struct linux_binprm *bprm)
78307+{
78308+#ifdef CONFIG_GRKERNSEC_BRUTE
78309+ struct user_struct *user = current->cred->user;
78310+ if (unlikely(user->suid_banned)) {
78311+ if (suid_ban_expired(user))
78312+ return 0;
78313+ /* disallow execution of suid binaries only */
78314+ else if (!uid_eq(bprm->cred->euid, current->cred->uid))
78315+ return -EPERM;
78316+ }
78317+#endif
78318+ return 0;
78319+}
78320diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
78321new file mode 100644
78322index 0000000..e3650b6
78323--- /dev/null
78324+++ b/grsecurity/grsec_sock.c
78325@@ -0,0 +1,244 @@
78326+#include <linux/kernel.h>
78327+#include <linux/module.h>
78328+#include <linux/sched.h>
78329+#include <linux/file.h>
78330+#include <linux/net.h>
78331+#include <linux/in.h>
78332+#include <linux/ip.h>
78333+#include <net/sock.h>
78334+#include <net/inet_sock.h>
78335+#include <linux/grsecurity.h>
78336+#include <linux/grinternal.h>
78337+#include <linux/gracl.h>
78338+
78339+extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
78340+extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
78341+
78342+EXPORT_SYMBOL_GPL(gr_search_udp_recvmsg);
78343+EXPORT_SYMBOL_GPL(gr_search_udp_sendmsg);
78344+
78345+#ifdef CONFIG_UNIX_MODULE
78346+EXPORT_SYMBOL_GPL(gr_acl_handle_unix);
78347+EXPORT_SYMBOL_GPL(gr_acl_handle_mknod);
78348+EXPORT_SYMBOL_GPL(gr_handle_chroot_unix);
78349+EXPORT_SYMBOL_GPL(gr_handle_create);
78350+#endif
78351+
78352+#ifdef CONFIG_GRKERNSEC
78353+#define gr_conn_table_size 32749
78354+struct conn_table_entry {
78355+ struct conn_table_entry *next;
78356+ struct signal_struct *sig;
78357+};
78358+
78359+struct conn_table_entry *gr_conn_table[gr_conn_table_size];
78360+DEFINE_SPINLOCK(gr_conn_table_lock);
78361+
78362+extern const char * gr_socktype_to_name(unsigned char type);
78363+extern const char * gr_proto_to_name(unsigned char proto);
78364+extern const char * gr_sockfamily_to_name(unsigned char family);
78365+
78366+static __inline__ int
78367+conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
78368+{
78369+ return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
78370+}
78371+
78372+static __inline__ int
78373+conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
78374+ __u16 sport, __u16 dport)
78375+{
78376+ if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
78377+ sig->gr_sport == sport && sig->gr_dport == dport))
78378+ return 1;
78379+ else
78380+ return 0;
78381+}
78382+
78383+static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
78384+{
78385+ struct conn_table_entry **match;
78386+ unsigned int index;
78387+
78388+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
78389+ sig->gr_sport, sig->gr_dport,
78390+ gr_conn_table_size);
78391+
78392+ newent->sig = sig;
78393+
78394+ match = &gr_conn_table[index];
78395+ newent->next = *match;
78396+ *match = newent;
78397+
78398+ return;
78399+}
78400+
78401+static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
78402+{
78403+ struct conn_table_entry *match, *last = NULL;
78404+ unsigned int index;
78405+
78406+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
78407+ sig->gr_sport, sig->gr_dport,
78408+ gr_conn_table_size);
78409+
78410+ match = gr_conn_table[index];
78411+ while (match && !conn_match(match->sig,
78412+ sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
78413+ sig->gr_dport)) {
78414+ last = match;
78415+ match = match->next;
78416+ }
78417+
78418+ if (match) {
78419+ if (last)
78420+ last->next = match->next;
78421+ else
78422+ gr_conn_table[index] = NULL;
78423+ kfree(match);
78424+ }
78425+
78426+ return;
78427+}
78428+
78429+static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
78430+ __u16 sport, __u16 dport)
78431+{
78432+ struct conn_table_entry *match;
78433+ unsigned int index;
78434+
78435+ index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
78436+
78437+ match = gr_conn_table[index];
78438+ while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
78439+ match = match->next;
78440+
78441+ if (match)
78442+ return match->sig;
78443+ else
78444+ return NULL;
78445+}
78446+
78447+#endif
78448+
78449+void gr_update_task_in_ip_table(const struct inet_sock *inet)
78450+{
78451+#ifdef CONFIG_GRKERNSEC
78452+ struct signal_struct *sig = current->signal;
78453+ struct conn_table_entry *newent;
78454+
78455+ newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
78456+ if (newent == NULL)
78457+ return;
78458+ /* no bh lock needed since we are called with bh disabled */
78459+ spin_lock(&gr_conn_table_lock);
78460+ gr_del_task_from_ip_table_nolock(sig);
78461+ sig->gr_saddr = inet->inet_rcv_saddr;
78462+ sig->gr_daddr = inet->inet_daddr;
78463+ sig->gr_sport = inet->inet_sport;
78464+ sig->gr_dport = inet->inet_dport;
78465+ gr_add_to_task_ip_table_nolock(sig, newent);
78466+ spin_unlock(&gr_conn_table_lock);
78467+#endif
78468+ return;
78469+}
78470+
78471+void gr_del_task_from_ip_table(struct task_struct *task)
78472+{
78473+#ifdef CONFIG_GRKERNSEC
78474+ spin_lock_bh(&gr_conn_table_lock);
78475+ gr_del_task_from_ip_table_nolock(task->signal);
78476+ spin_unlock_bh(&gr_conn_table_lock);
78477+#endif
78478+ return;
78479+}
78480+
78481+void
78482+gr_attach_curr_ip(const struct sock *sk)
78483+{
78484+#ifdef CONFIG_GRKERNSEC
78485+ struct signal_struct *p, *set;
78486+ const struct inet_sock *inet = inet_sk(sk);
78487+
78488+ if (unlikely(sk->sk_protocol != IPPROTO_TCP))
78489+ return;
78490+
78491+ set = current->signal;
78492+
78493+ spin_lock_bh(&gr_conn_table_lock);
78494+ p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
78495+ inet->inet_dport, inet->inet_sport);
78496+ if (unlikely(p != NULL)) {
78497+ set->curr_ip = p->curr_ip;
78498+ set->used_accept = 1;
78499+ gr_del_task_from_ip_table_nolock(p);
78500+ spin_unlock_bh(&gr_conn_table_lock);
78501+ return;
78502+ }
78503+ spin_unlock_bh(&gr_conn_table_lock);
78504+
78505+ set->curr_ip = inet->inet_daddr;
78506+ set->used_accept = 1;
78507+#endif
78508+ return;
78509+}
78510+
78511+int
78512+gr_handle_sock_all(const int family, const int type, const int protocol)
78513+{
78514+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
78515+ if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
78516+ (family != AF_UNIX)) {
78517+ if (family == AF_INET)
78518+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
78519+ else
78520+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
78521+ return -EACCES;
78522+ }
78523+#endif
78524+ return 0;
78525+}
78526+
78527+int
78528+gr_handle_sock_server(const struct sockaddr *sck)
78529+{
78530+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
78531+ if (grsec_enable_socket_server &&
78532+ in_group_p(grsec_socket_server_gid) &&
78533+ sck && (sck->sa_family != AF_UNIX) &&
78534+ (sck->sa_family != AF_LOCAL)) {
78535+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
78536+ return -EACCES;
78537+ }
78538+#endif
78539+ return 0;
78540+}
78541+
78542+int
78543+gr_handle_sock_server_other(const struct sock *sck)
78544+{
78545+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
78546+ if (grsec_enable_socket_server &&
78547+ in_group_p(grsec_socket_server_gid) &&
78548+ sck && (sck->sk_family != AF_UNIX) &&
78549+ (sck->sk_family != AF_LOCAL)) {
78550+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
78551+ return -EACCES;
78552+ }
78553+#endif
78554+ return 0;
78555+}
78556+
78557+int
78558+gr_handle_sock_client(const struct sockaddr *sck)
78559+{
78560+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
78561+ if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
78562+ sck && (sck->sa_family != AF_UNIX) &&
78563+ (sck->sa_family != AF_LOCAL)) {
78564+ gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
78565+ return -EACCES;
78566+ }
78567+#endif
78568+ return 0;
78569+}
78570diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
78571new file mode 100644
78572index 0000000..8159888
78573--- /dev/null
78574+++ b/grsecurity/grsec_sysctl.c
78575@@ -0,0 +1,479 @@
78576+#include <linux/kernel.h>
78577+#include <linux/sched.h>
78578+#include <linux/sysctl.h>
78579+#include <linux/grsecurity.h>
78580+#include <linux/grinternal.h>
78581+
78582+int
78583+gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
78584+{
78585+#ifdef CONFIG_GRKERNSEC_SYSCTL
78586+ if (dirname == NULL || name == NULL)
78587+ return 0;
78588+ if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
78589+ gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
78590+ return -EACCES;
78591+ }
78592+#endif
78593+ return 0;
78594+}
78595+
78596+#if defined(CONFIG_GRKERNSEC_ROFS) || defined(CONFIG_GRKERNSEC_DENYUSB)
78597+static int __maybe_unused __read_only one = 1;
78598+#endif
78599+
78600+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS) || \
78601+ defined(CONFIG_GRKERNSEC_DENYUSB)
78602+struct ctl_table grsecurity_table[] = {
78603+#ifdef CONFIG_GRKERNSEC_SYSCTL
78604+#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
78605+#ifdef CONFIG_GRKERNSEC_IO
78606+ {
78607+ .procname = "disable_priv_io",
78608+ .data = &grsec_disable_privio,
78609+ .maxlen = sizeof(int),
78610+ .mode = 0600,
78611+ .proc_handler = &proc_dointvec,
78612+ },
78613+#endif
78614+#endif
78615+#ifdef CONFIG_GRKERNSEC_LINK
78616+ {
78617+ .procname = "linking_restrictions",
78618+ .data = &grsec_enable_link,
78619+ .maxlen = sizeof(int),
78620+ .mode = 0600,
78621+ .proc_handler = &proc_dointvec,
78622+ },
78623+#endif
78624+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
78625+ {
78626+ .procname = "enforce_symlinksifowner",
78627+ .data = &grsec_enable_symlinkown,
78628+ .maxlen = sizeof(int),
78629+ .mode = 0600,
78630+ .proc_handler = &proc_dointvec,
78631+ },
78632+ {
78633+ .procname = "symlinkown_gid",
78634+ .data = &grsec_symlinkown_gid,
78635+ .maxlen = sizeof(int),
78636+ .mode = 0600,
78637+ .proc_handler = &proc_dointvec,
78638+ },
78639+#endif
78640+#ifdef CONFIG_GRKERNSEC_BRUTE
78641+ {
78642+ .procname = "deter_bruteforce",
78643+ .data = &grsec_enable_brute,
78644+ .maxlen = sizeof(int),
78645+ .mode = 0600,
78646+ .proc_handler = &proc_dointvec,
78647+ },
78648+#endif
78649+#ifdef CONFIG_GRKERNSEC_FIFO
78650+ {
78651+ .procname = "fifo_restrictions",
78652+ .data = &grsec_enable_fifo,
78653+ .maxlen = sizeof(int),
78654+ .mode = 0600,
78655+ .proc_handler = &proc_dointvec,
78656+ },
78657+#endif
78658+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
78659+ {
78660+ .procname = "ptrace_readexec",
78661+ .data = &grsec_enable_ptrace_readexec,
78662+ .maxlen = sizeof(int),
78663+ .mode = 0600,
78664+ .proc_handler = &proc_dointvec,
78665+ },
78666+#endif
78667+#ifdef CONFIG_GRKERNSEC_SETXID
78668+ {
78669+ .procname = "consistent_setxid",
78670+ .data = &grsec_enable_setxid,
78671+ .maxlen = sizeof(int),
78672+ .mode = 0600,
78673+ .proc_handler = &proc_dointvec,
78674+ },
78675+#endif
78676+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
78677+ {
78678+ .procname = "ip_blackhole",
78679+ .data = &grsec_enable_blackhole,
78680+ .maxlen = sizeof(int),
78681+ .mode = 0600,
78682+ .proc_handler = &proc_dointvec,
78683+ },
78684+ {
78685+ .procname = "lastack_retries",
78686+ .data = &grsec_lastack_retries,
78687+ .maxlen = sizeof(int),
78688+ .mode = 0600,
78689+ .proc_handler = &proc_dointvec,
78690+ },
78691+#endif
78692+#ifdef CONFIG_GRKERNSEC_EXECLOG
78693+ {
78694+ .procname = "exec_logging",
78695+ .data = &grsec_enable_execlog,
78696+ .maxlen = sizeof(int),
78697+ .mode = 0600,
78698+ .proc_handler = &proc_dointvec,
78699+ },
78700+#endif
78701+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
78702+ {
78703+ .procname = "rwxmap_logging",
78704+ .data = &grsec_enable_log_rwxmaps,
78705+ .maxlen = sizeof(int),
78706+ .mode = 0600,
78707+ .proc_handler = &proc_dointvec,
78708+ },
78709+#endif
78710+#ifdef CONFIG_GRKERNSEC_SIGNAL
78711+ {
78712+ .procname = "signal_logging",
78713+ .data = &grsec_enable_signal,
78714+ .maxlen = sizeof(int),
78715+ .mode = 0600,
78716+ .proc_handler = &proc_dointvec,
78717+ },
78718+#endif
78719+#ifdef CONFIG_GRKERNSEC_FORKFAIL
78720+ {
78721+ .procname = "forkfail_logging",
78722+ .data = &grsec_enable_forkfail,
78723+ .maxlen = sizeof(int),
78724+ .mode = 0600,
78725+ .proc_handler = &proc_dointvec,
78726+ },
78727+#endif
78728+#ifdef CONFIG_GRKERNSEC_TIME
78729+ {
78730+ .procname = "timechange_logging",
78731+ .data = &grsec_enable_time,
78732+ .maxlen = sizeof(int),
78733+ .mode = 0600,
78734+ .proc_handler = &proc_dointvec,
78735+ },
78736+#endif
78737+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
78738+ {
78739+ .procname = "chroot_deny_shmat",
78740+ .data = &grsec_enable_chroot_shmat,
78741+ .maxlen = sizeof(int),
78742+ .mode = 0600,
78743+ .proc_handler = &proc_dointvec,
78744+ },
78745+#endif
78746+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
78747+ {
78748+ .procname = "chroot_deny_unix",
78749+ .data = &grsec_enable_chroot_unix,
78750+ .maxlen = sizeof(int),
78751+ .mode = 0600,
78752+ .proc_handler = &proc_dointvec,
78753+ },
78754+#endif
78755+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
78756+ {
78757+ .procname = "chroot_deny_mount",
78758+ .data = &grsec_enable_chroot_mount,
78759+ .maxlen = sizeof(int),
78760+ .mode = 0600,
78761+ .proc_handler = &proc_dointvec,
78762+ },
78763+#endif
78764+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
78765+ {
78766+ .procname = "chroot_deny_fchdir",
78767+ .data = &grsec_enable_chroot_fchdir,
78768+ .maxlen = sizeof(int),
78769+ .mode = 0600,
78770+ .proc_handler = &proc_dointvec,
78771+ },
78772+#endif
78773+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
78774+ {
78775+ .procname = "chroot_deny_chroot",
78776+ .data = &grsec_enable_chroot_double,
78777+ .maxlen = sizeof(int),
78778+ .mode = 0600,
78779+ .proc_handler = &proc_dointvec,
78780+ },
78781+#endif
78782+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
78783+ {
78784+ .procname = "chroot_deny_pivot",
78785+ .data = &grsec_enable_chroot_pivot,
78786+ .maxlen = sizeof(int),
78787+ .mode = 0600,
78788+ .proc_handler = &proc_dointvec,
78789+ },
78790+#endif
78791+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
78792+ {
78793+ .procname = "chroot_enforce_chdir",
78794+ .data = &grsec_enable_chroot_chdir,
78795+ .maxlen = sizeof(int),
78796+ .mode = 0600,
78797+ .proc_handler = &proc_dointvec,
78798+ },
78799+#endif
78800+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
78801+ {
78802+ .procname = "chroot_deny_chmod",
78803+ .data = &grsec_enable_chroot_chmod,
78804+ .maxlen = sizeof(int),
78805+ .mode = 0600,
78806+ .proc_handler = &proc_dointvec,
78807+ },
78808+#endif
78809+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
78810+ {
78811+ .procname = "chroot_deny_mknod",
78812+ .data = &grsec_enable_chroot_mknod,
78813+ .maxlen = sizeof(int),
78814+ .mode = 0600,
78815+ .proc_handler = &proc_dointvec,
78816+ },
78817+#endif
78818+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
78819+ {
78820+ .procname = "chroot_restrict_nice",
78821+ .data = &grsec_enable_chroot_nice,
78822+ .maxlen = sizeof(int),
78823+ .mode = 0600,
78824+ .proc_handler = &proc_dointvec,
78825+ },
78826+#endif
78827+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
78828+ {
78829+ .procname = "chroot_execlog",
78830+ .data = &grsec_enable_chroot_execlog,
78831+ .maxlen = sizeof(int),
78832+ .mode = 0600,
78833+ .proc_handler = &proc_dointvec,
78834+ },
78835+#endif
78836+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
78837+ {
78838+ .procname = "chroot_caps",
78839+ .data = &grsec_enable_chroot_caps,
78840+ .maxlen = sizeof(int),
78841+ .mode = 0600,
78842+ .proc_handler = &proc_dointvec,
78843+ },
78844+#endif
78845+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
78846+ {
78847+ .procname = "chroot_deny_sysctl",
78848+ .data = &grsec_enable_chroot_sysctl,
78849+ .maxlen = sizeof(int),
78850+ .mode = 0600,
78851+ .proc_handler = &proc_dointvec,
78852+ },
78853+#endif
78854+#ifdef CONFIG_GRKERNSEC_TPE
78855+ {
78856+ .procname = "tpe",
78857+ .data = &grsec_enable_tpe,
78858+ .maxlen = sizeof(int),
78859+ .mode = 0600,
78860+ .proc_handler = &proc_dointvec,
78861+ },
78862+ {
78863+ .procname = "tpe_gid",
78864+ .data = &grsec_tpe_gid,
78865+ .maxlen = sizeof(int),
78866+ .mode = 0600,
78867+ .proc_handler = &proc_dointvec,
78868+ },
78869+#endif
78870+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
78871+ {
78872+ .procname = "tpe_invert",
78873+ .data = &grsec_enable_tpe_invert,
78874+ .maxlen = sizeof(int),
78875+ .mode = 0600,
78876+ .proc_handler = &proc_dointvec,
78877+ },
78878+#endif
78879+#ifdef CONFIG_GRKERNSEC_TPE_ALL
78880+ {
78881+ .procname = "tpe_restrict_all",
78882+ .data = &grsec_enable_tpe_all,
78883+ .maxlen = sizeof(int),
78884+ .mode = 0600,
78885+ .proc_handler = &proc_dointvec,
78886+ },
78887+#endif
78888+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
78889+ {
78890+ .procname = "socket_all",
78891+ .data = &grsec_enable_socket_all,
78892+ .maxlen = sizeof(int),
78893+ .mode = 0600,
78894+ .proc_handler = &proc_dointvec,
78895+ },
78896+ {
78897+ .procname = "socket_all_gid",
78898+ .data = &grsec_socket_all_gid,
78899+ .maxlen = sizeof(int),
78900+ .mode = 0600,
78901+ .proc_handler = &proc_dointvec,
78902+ },
78903+#endif
78904+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
78905+ {
78906+ .procname = "socket_client",
78907+ .data = &grsec_enable_socket_client,
78908+ .maxlen = sizeof(int),
78909+ .mode = 0600,
78910+ .proc_handler = &proc_dointvec,
78911+ },
78912+ {
78913+ .procname = "socket_client_gid",
78914+ .data = &grsec_socket_client_gid,
78915+ .maxlen = sizeof(int),
78916+ .mode = 0600,
78917+ .proc_handler = &proc_dointvec,
78918+ },
78919+#endif
78920+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
78921+ {
78922+ .procname = "socket_server",
78923+ .data = &grsec_enable_socket_server,
78924+ .maxlen = sizeof(int),
78925+ .mode = 0600,
78926+ .proc_handler = &proc_dointvec,
78927+ },
78928+ {
78929+ .procname = "socket_server_gid",
78930+ .data = &grsec_socket_server_gid,
78931+ .maxlen = sizeof(int),
78932+ .mode = 0600,
78933+ .proc_handler = &proc_dointvec,
78934+ },
78935+#endif
78936+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
78937+ {
78938+ .procname = "audit_group",
78939+ .data = &grsec_enable_group,
78940+ .maxlen = sizeof(int),
78941+ .mode = 0600,
78942+ .proc_handler = &proc_dointvec,
78943+ },
78944+ {
78945+ .procname = "audit_gid",
78946+ .data = &grsec_audit_gid,
78947+ .maxlen = sizeof(int),
78948+ .mode = 0600,
78949+ .proc_handler = &proc_dointvec,
78950+ },
78951+#endif
78952+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
78953+ {
78954+ .procname = "audit_chdir",
78955+ .data = &grsec_enable_chdir,
78956+ .maxlen = sizeof(int),
78957+ .mode = 0600,
78958+ .proc_handler = &proc_dointvec,
78959+ },
78960+#endif
78961+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
78962+ {
78963+ .procname = "audit_mount",
78964+ .data = &grsec_enable_mount,
78965+ .maxlen = sizeof(int),
78966+ .mode = 0600,
78967+ .proc_handler = &proc_dointvec,
78968+ },
78969+#endif
78970+#ifdef CONFIG_GRKERNSEC_DMESG
78971+ {
78972+ .procname = "dmesg",
78973+ .data = &grsec_enable_dmesg,
78974+ .maxlen = sizeof(int),
78975+ .mode = 0600,
78976+ .proc_handler = &proc_dointvec,
78977+ },
78978+#endif
78979+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
78980+ {
78981+ .procname = "chroot_findtask",
78982+ .data = &grsec_enable_chroot_findtask,
78983+ .maxlen = sizeof(int),
78984+ .mode = 0600,
78985+ .proc_handler = &proc_dointvec,
78986+ },
78987+#endif
78988+#ifdef CONFIG_GRKERNSEC_RESLOG
78989+ {
78990+ .procname = "resource_logging",
78991+ .data = &grsec_resource_logging,
78992+ .maxlen = sizeof(int),
78993+ .mode = 0600,
78994+ .proc_handler = &proc_dointvec,
78995+ },
78996+#endif
78997+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
78998+ {
78999+ .procname = "audit_ptrace",
79000+ .data = &grsec_enable_audit_ptrace,
79001+ .maxlen = sizeof(int),
79002+ .mode = 0600,
79003+ .proc_handler = &proc_dointvec,
79004+ },
79005+#endif
79006+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
79007+ {
79008+ .procname = "harden_ptrace",
79009+ .data = &grsec_enable_harden_ptrace,
79010+ .maxlen = sizeof(int),
79011+ .mode = 0600,
79012+ .proc_handler = &proc_dointvec,
79013+ },
79014+#endif
79015+#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
79016+ {
79017+ .procname = "harden_ipc",
79018+ .data = &grsec_enable_harden_ipc,
79019+ .maxlen = sizeof(int),
79020+ .mode = 0600,
79021+ .proc_handler = &proc_dointvec,
79022+ },
79023+#endif
79024+ {
79025+ .procname = "grsec_lock",
79026+ .data = &grsec_lock,
79027+ .maxlen = sizeof(int),
79028+ .mode = 0600,
79029+ .proc_handler = &proc_dointvec,
79030+ },
79031+#endif
79032+#ifdef CONFIG_GRKERNSEC_ROFS
79033+ {
79034+ .procname = "romount_protect",
79035+ .data = &grsec_enable_rofs,
79036+ .maxlen = sizeof(int),
79037+ .mode = 0600,
79038+ .proc_handler = &proc_dointvec_minmax,
79039+ .extra1 = &one,
79040+ .extra2 = &one,
79041+ },
79042+#endif
79043+#if defined(CONFIG_GRKERNSEC_DENYUSB) && !defined(CONFIG_GRKERNSEC_DENYUSB_FORCE)
79044+ {
79045+ .procname = "deny_new_usb",
79046+ .data = &grsec_deny_new_usb,
79047+ .maxlen = sizeof(int),
79048+ .mode = 0600,
79049+ .proc_handler = &proc_dointvec,
79050+ },
79051+#endif
79052+ { }
79053+};
79054+#endif
79055diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
79056new file mode 100644
79057index 0000000..61b514e
79058--- /dev/null
79059+++ b/grsecurity/grsec_time.c
79060@@ -0,0 +1,16 @@
79061+#include <linux/kernel.h>
79062+#include <linux/sched.h>
79063+#include <linux/grinternal.h>
79064+#include <linux/module.h>
79065+
79066+void
79067+gr_log_timechange(void)
79068+{
79069+#ifdef CONFIG_GRKERNSEC_TIME
79070+ if (grsec_enable_time)
79071+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
79072+#endif
79073+ return;
79074+}
79075+
79076+EXPORT_SYMBOL_GPL(gr_log_timechange);
79077diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
79078new file mode 100644
79079index 0000000..d1953de
79080--- /dev/null
79081+++ b/grsecurity/grsec_tpe.c
79082@@ -0,0 +1,78 @@
79083+#include <linux/kernel.h>
79084+#include <linux/sched.h>
79085+#include <linux/file.h>
79086+#include <linux/fs.h>
79087+#include <linux/grinternal.h>
79088+
79089+extern int gr_acl_tpe_check(void);
79090+
79091+int
79092+gr_tpe_allow(const struct file *file)
79093+{
79094+#ifdef CONFIG_GRKERNSEC
79095+ struct inode *inode = file->f_path.dentry->d_parent->d_inode;
79096+ struct inode *file_inode = file->f_path.dentry->d_inode;
79097+ const struct cred *cred = current_cred();
79098+ char *msg = NULL;
79099+ char *msg2 = NULL;
79100+
79101+ // never restrict root
79102+ if (gr_is_global_root(cred->uid))
79103+ return 1;
79104+
79105+ if (grsec_enable_tpe) {
79106+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
79107+ if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
79108+ msg = "not being in trusted group";
79109+ else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
79110+ msg = "being in untrusted group";
79111+#else
79112+ if (in_group_p(grsec_tpe_gid))
79113+ msg = "being in untrusted group";
79114+#endif
79115+ }
79116+ if (!msg && gr_acl_tpe_check())
79117+ msg = "being in untrusted role";
79118+
79119+ // not in any affected group/role
79120+ if (!msg)
79121+ goto next_check;
79122+
79123+ if (gr_is_global_nonroot(inode->i_uid))
79124+ msg2 = "file in non-root-owned directory";
79125+ else if (inode->i_mode & S_IWOTH)
79126+ msg2 = "file in world-writable directory";
79127+ else if (inode->i_mode & S_IWGRP)
79128+ msg2 = "file in group-writable directory";
79129+ else if (file_inode->i_mode & S_IWOTH)
79130+ msg2 = "file is world-writable";
79131+
79132+ if (msg && msg2) {
79133+ char fullmsg[70] = {0};
79134+ snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
79135+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
79136+ return 0;
79137+ }
79138+ msg = NULL;
79139+next_check:
79140+#ifdef CONFIG_GRKERNSEC_TPE_ALL
79141+ if (!grsec_enable_tpe || !grsec_enable_tpe_all)
79142+ return 1;
79143+
79144+ if (gr_is_global_nonroot(inode->i_uid) && !uid_eq(inode->i_uid, cred->uid))
79145+ msg = "directory not owned by user";
79146+ else if (inode->i_mode & S_IWOTH)
79147+ msg = "file in world-writable directory";
79148+ else if (inode->i_mode & S_IWGRP)
79149+ msg = "file in group-writable directory";
79150+ else if (file_inode->i_mode & S_IWOTH)
79151+ msg = "file is world-writable";
79152+
79153+ if (msg) {
79154+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
79155+ return 0;
79156+ }
79157+#endif
79158+#endif
79159+ return 1;
79160+}
79161diff --git a/grsecurity/grsec_usb.c b/grsecurity/grsec_usb.c
79162new file mode 100644
79163index 0000000..ae02d8e
79164--- /dev/null
79165+++ b/grsecurity/grsec_usb.c
79166@@ -0,0 +1,15 @@
79167+#include <linux/kernel.h>
79168+#include <linux/grinternal.h>
79169+#include <linux/module.h>
79170+
79171+int gr_handle_new_usb(void)
79172+{
79173+#ifdef CONFIG_GRKERNSEC_DENYUSB
79174+ if (grsec_deny_new_usb) {
79175+ printk(KERN_ALERT "grsec: denied insert of new USB device\n");
79176+ return 1;
79177+ }
79178+#endif
79179+ return 0;
79180+}
79181+EXPORT_SYMBOL_GPL(gr_handle_new_usb);
79182diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
79183new file mode 100644
79184index 0000000..158b330
79185--- /dev/null
79186+++ b/grsecurity/grsum.c
79187@@ -0,0 +1,64 @@
79188+#include <linux/err.h>
79189+#include <linux/kernel.h>
79190+#include <linux/sched.h>
79191+#include <linux/mm.h>
79192+#include <linux/scatterlist.h>
79193+#include <linux/crypto.h>
79194+#include <linux/gracl.h>
79195+
79196+
79197+#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
79198+#error "crypto and sha256 must be built into the kernel"
79199+#endif
79200+
79201+int
79202+chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
79203+{
79204+ struct crypto_hash *tfm;
79205+ struct hash_desc desc;
79206+ struct scatterlist sg[2];
79207+ unsigned char temp_sum[GR_SHA_LEN] __attribute__((aligned(__alignof__(unsigned long))));
79208+ unsigned long *tmpsumptr = (unsigned long *)temp_sum;
79209+ unsigned long *sumptr = (unsigned long *)sum;
79210+ int cryptres;
79211+ int retval = 1;
79212+ volatile int mismatched = 0;
79213+ volatile int dummy = 0;
79214+ unsigned int i;
79215+
79216+ tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
79217+ if (IS_ERR(tfm)) {
79218+ /* should never happen, since sha256 should be built in */
79219+ memset(entry->pw, 0, GR_PW_LEN);
79220+ return 1;
79221+ }
79222+
79223+ sg_init_table(sg, 2);
79224+ sg_set_buf(&sg[0], salt, GR_SALT_LEN);
79225+ sg_set_buf(&sg[1], entry->pw, strlen(entry->pw));
79226+
79227+ desc.tfm = tfm;
79228+ desc.flags = 0;
79229+
79230+ cryptres = crypto_hash_digest(&desc, sg, GR_SALT_LEN + strlen(entry->pw),
79231+ temp_sum);
79232+
79233+ memset(entry->pw, 0, GR_PW_LEN);
79234+
79235+ if (cryptres)
79236+ goto out;
79237+
79238+ for (i = 0; i < GR_SHA_LEN/sizeof(tmpsumptr[0]); i++)
79239+ if (sumptr[i] != tmpsumptr[i])
79240+ mismatched = 1;
79241+ else
79242+ dummy = 1; // waste a cycle
79243+
79244+ if (!mismatched)
79245+ retval = dummy - 1;
79246+
79247+out:
79248+ crypto_free_hash(tfm);
79249+
79250+ return retval;
79251+}
79252diff --git a/include/asm-generic/4level-fixup.h b/include/asm-generic/4level-fixup.h
79253index 77ff547..181834f 100644
79254--- a/include/asm-generic/4level-fixup.h
79255+++ b/include/asm-generic/4level-fixup.h
79256@@ -13,8 +13,10 @@
79257 #define pmd_alloc(mm, pud, address) \
79258 ((unlikely(pgd_none(*(pud))) && __pmd_alloc(mm, pud, address))? \
79259 NULL: pmd_offset(pud, address))
79260+#define pmd_alloc_kernel(mm, pud, address) pmd_alloc((mm), (pud), (address))
79261
79262 #define pud_alloc(mm, pgd, address) (pgd)
79263+#define pud_alloc_kernel(mm, pgd, address) pud_alloc((mm), (pgd), (address))
79264 #define pud_offset(pgd, start) (pgd)
79265 #define pud_none(pud) 0
79266 #define pud_bad(pud) 0
79267diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
79268index b7babf0..1e4b4f1 100644
79269--- a/include/asm-generic/atomic-long.h
79270+++ b/include/asm-generic/atomic-long.h
79271@@ -22,6 +22,12 @@
79272
79273 typedef atomic64_t atomic_long_t;
79274
79275+#ifdef CONFIG_PAX_REFCOUNT
79276+typedef atomic64_unchecked_t atomic_long_unchecked_t;
79277+#else
79278+typedef atomic64_t atomic_long_unchecked_t;
79279+#endif
79280+
79281 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
79282
79283 static inline long atomic_long_read(atomic_long_t *l)
79284@@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
79285 return (long)atomic64_read(v);
79286 }
79287
79288+#ifdef CONFIG_PAX_REFCOUNT
79289+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
79290+{
79291+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
79292+
79293+ return (long)atomic64_read_unchecked(v);
79294+}
79295+#endif
79296+
79297 static inline void atomic_long_set(atomic_long_t *l, long i)
79298 {
79299 atomic64_t *v = (atomic64_t *)l;
79300@@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
79301 atomic64_set(v, i);
79302 }
79303
79304+#ifdef CONFIG_PAX_REFCOUNT
79305+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
79306+{
79307+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
79308+
79309+ atomic64_set_unchecked(v, i);
79310+}
79311+#endif
79312+
79313 static inline void atomic_long_inc(atomic_long_t *l)
79314 {
79315 atomic64_t *v = (atomic64_t *)l;
79316@@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
79317 atomic64_inc(v);
79318 }
79319
79320+#ifdef CONFIG_PAX_REFCOUNT
79321+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
79322+{
79323+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
79324+
79325+ atomic64_inc_unchecked(v);
79326+}
79327+#endif
79328+
79329 static inline void atomic_long_dec(atomic_long_t *l)
79330 {
79331 atomic64_t *v = (atomic64_t *)l;
79332@@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
79333 atomic64_dec(v);
79334 }
79335
79336+#ifdef CONFIG_PAX_REFCOUNT
79337+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
79338+{
79339+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
79340+
79341+ atomic64_dec_unchecked(v);
79342+}
79343+#endif
79344+
79345 static inline void atomic_long_add(long i, atomic_long_t *l)
79346 {
79347 atomic64_t *v = (atomic64_t *)l;
79348@@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
79349 atomic64_add(i, v);
79350 }
79351
79352+#ifdef CONFIG_PAX_REFCOUNT
79353+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
79354+{
79355+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
79356+
79357+ atomic64_add_unchecked(i, v);
79358+}
79359+#endif
79360+
79361 static inline void atomic_long_sub(long i, atomic_long_t *l)
79362 {
79363 atomic64_t *v = (atomic64_t *)l;
79364@@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
79365 atomic64_sub(i, v);
79366 }
79367
79368+#ifdef CONFIG_PAX_REFCOUNT
79369+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
79370+{
79371+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
79372+
79373+ atomic64_sub_unchecked(i, v);
79374+}
79375+#endif
79376+
79377 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
79378 {
79379 atomic64_t *v = (atomic64_t *)l;
79380@@ -94,13 +154,22 @@ static inline int atomic_long_add_negative(long i, atomic_long_t *l)
79381 return atomic64_add_negative(i, v);
79382 }
79383
79384-static inline long atomic_long_add_return(long i, atomic_long_t *l)
79385+static inline long __intentional_overflow(-1) atomic_long_add_return(long i, atomic_long_t *l)
79386 {
79387 atomic64_t *v = (atomic64_t *)l;
79388
79389 return (long)atomic64_add_return(i, v);
79390 }
79391
79392+#ifdef CONFIG_PAX_REFCOUNT
79393+static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
79394+{
79395+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
79396+
79397+ return (long)atomic64_add_return_unchecked(i, v);
79398+}
79399+#endif
79400+
79401 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
79402 {
79403 atomic64_t *v = (atomic64_t *)l;
79404@@ -115,6 +184,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
79405 return (long)atomic64_inc_return(v);
79406 }
79407
79408+#ifdef CONFIG_PAX_REFCOUNT
79409+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
79410+{
79411+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
79412+
79413+ return (long)atomic64_inc_return_unchecked(v);
79414+}
79415+#endif
79416+
79417 static inline long atomic_long_dec_return(atomic_long_t *l)
79418 {
79419 atomic64_t *v = (atomic64_t *)l;
79420@@ -140,6 +218,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
79421
79422 typedef atomic_t atomic_long_t;
79423
79424+#ifdef CONFIG_PAX_REFCOUNT
79425+typedef atomic_unchecked_t atomic_long_unchecked_t;
79426+#else
79427+typedef atomic_t atomic_long_unchecked_t;
79428+#endif
79429+
79430 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
79431 static inline long atomic_long_read(atomic_long_t *l)
79432 {
79433@@ -148,6 +232,15 @@ static inline long atomic_long_read(atomic_long_t *l)
79434 return (long)atomic_read(v);
79435 }
79436
79437+#ifdef CONFIG_PAX_REFCOUNT
79438+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
79439+{
79440+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
79441+
79442+ return (long)atomic_read_unchecked(v);
79443+}
79444+#endif
79445+
79446 static inline void atomic_long_set(atomic_long_t *l, long i)
79447 {
79448 atomic_t *v = (atomic_t *)l;
79449@@ -155,6 +248,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
79450 atomic_set(v, i);
79451 }
79452
79453+#ifdef CONFIG_PAX_REFCOUNT
79454+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
79455+{
79456+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
79457+
79458+ atomic_set_unchecked(v, i);
79459+}
79460+#endif
79461+
79462 static inline void atomic_long_inc(atomic_long_t *l)
79463 {
79464 atomic_t *v = (atomic_t *)l;
79465@@ -162,6 +264,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
79466 atomic_inc(v);
79467 }
79468
79469+#ifdef CONFIG_PAX_REFCOUNT
79470+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
79471+{
79472+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
79473+
79474+ atomic_inc_unchecked(v);
79475+}
79476+#endif
79477+
79478 static inline void atomic_long_dec(atomic_long_t *l)
79479 {
79480 atomic_t *v = (atomic_t *)l;
79481@@ -169,6 +280,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
79482 atomic_dec(v);
79483 }
79484
79485+#ifdef CONFIG_PAX_REFCOUNT
79486+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
79487+{
79488+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
79489+
79490+ atomic_dec_unchecked(v);
79491+}
79492+#endif
79493+
79494 static inline void atomic_long_add(long i, atomic_long_t *l)
79495 {
79496 atomic_t *v = (atomic_t *)l;
79497@@ -176,6 +296,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
79498 atomic_add(i, v);
79499 }
79500
79501+#ifdef CONFIG_PAX_REFCOUNT
79502+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
79503+{
79504+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
79505+
79506+ atomic_add_unchecked(i, v);
79507+}
79508+#endif
79509+
79510 static inline void atomic_long_sub(long i, atomic_long_t *l)
79511 {
79512 atomic_t *v = (atomic_t *)l;
79513@@ -183,6 +312,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
79514 atomic_sub(i, v);
79515 }
79516
79517+#ifdef CONFIG_PAX_REFCOUNT
79518+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
79519+{
79520+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
79521+
79522+ atomic_sub_unchecked(i, v);
79523+}
79524+#endif
79525+
79526 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
79527 {
79528 atomic_t *v = (atomic_t *)l;
79529@@ -211,13 +349,23 @@ static inline int atomic_long_add_negative(long i, atomic_long_t *l)
79530 return atomic_add_negative(i, v);
79531 }
79532
79533-static inline long atomic_long_add_return(long i, atomic_long_t *l)
79534+static inline long __intentional_overflow(-1) atomic_long_add_return(long i, atomic_long_t *l)
79535 {
79536 atomic_t *v = (atomic_t *)l;
79537
79538 return (long)atomic_add_return(i, v);
79539 }
79540
79541+#ifdef CONFIG_PAX_REFCOUNT
79542+static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
79543+{
79544+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
79545+
79546+ return (long)atomic_add_return_unchecked(i, v);
79547+}
79548+
79549+#endif
79550+
79551 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
79552 {
79553 atomic_t *v = (atomic_t *)l;
79554@@ -232,6 +380,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
79555 return (long)atomic_inc_return(v);
79556 }
79557
79558+#ifdef CONFIG_PAX_REFCOUNT
79559+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
79560+{
79561+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
79562+
79563+ return (long)atomic_inc_return_unchecked(v);
79564+}
79565+#endif
79566+
79567 static inline long atomic_long_dec_return(atomic_long_t *l)
79568 {
79569 atomic_t *v = (atomic_t *)l;
79570@@ -255,4 +412,57 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
79571
79572 #endif /* BITS_PER_LONG == 64 */
79573
79574+#ifdef CONFIG_PAX_REFCOUNT
79575+static inline void pax_refcount_needs_these_functions(void)
79576+{
79577+ atomic_read_unchecked((atomic_unchecked_t *)NULL);
79578+ atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
79579+ atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
79580+ atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
79581+ atomic_inc_unchecked((atomic_unchecked_t *)NULL);
79582+ (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
79583+ atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
79584+ atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
79585+ atomic_dec_unchecked((atomic_unchecked_t *)NULL);
79586+ atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
79587+ (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
79588+#ifdef CONFIG_X86
79589+ atomic_clear_mask_unchecked(0, NULL);
79590+ atomic_set_mask_unchecked(0, NULL);
79591+#endif
79592+
79593+ atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
79594+ atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
79595+ atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
79596+ atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
79597+ atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
79598+ atomic_long_add_return_unchecked(0, (atomic_long_unchecked_t *)NULL);
79599+ atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
79600+ atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
79601+}
79602+#else
79603+#define atomic_read_unchecked(v) atomic_read(v)
79604+#define atomic_set_unchecked(v, i) atomic_set((v), (i))
79605+#define atomic_add_unchecked(i, v) atomic_add((i), (v))
79606+#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
79607+#define atomic_inc_unchecked(v) atomic_inc(v)
79608+#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
79609+#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
79610+#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
79611+#define atomic_dec_unchecked(v) atomic_dec(v)
79612+#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
79613+#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
79614+#define atomic_clear_mask_unchecked(mask, v) atomic_clear_mask((mask), (v))
79615+#define atomic_set_mask_unchecked(mask, v) atomic_set_mask((mask), (v))
79616+
79617+#define atomic_long_read_unchecked(v) atomic_long_read(v)
79618+#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
79619+#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
79620+#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
79621+#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
79622+#define atomic_long_add_return_unchecked(i, v) atomic_long_add_return((i), (v))
79623+#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
79624+#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
79625+#endif
79626+
79627 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
79628diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
79629index 30ad9c8..c70c170 100644
79630--- a/include/asm-generic/atomic64.h
79631+++ b/include/asm-generic/atomic64.h
79632@@ -16,6 +16,8 @@ typedef struct {
79633 long long counter;
79634 } atomic64_t;
79635
79636+typedef atomic64_t atomic64_unchecked_t;
79637+
79638 #define ATOMIC64_INIT(i) { (i) }
79639
79640 extern long long atomic64_read(const atomic64_t *v);
79641@@ -51,4 +53,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
79642 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
79643 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
79644
79645+#define atomic64_read_unchecked(v) atomic64_read(v)
79646+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
79647+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
79648+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
79649+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
79650+#define atomic64_inc_unchecked(v) atomic64_inc(v)
79651+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
79652+#define atomic64_dec_unchecked(v) atomic64_dec(v)
79653+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
79654+
79655 #endif /* _ASM_GENERIC_ATOMIC64_H */
79656diff --git a/include/asm-generic/barrier.h b/include/asm-generic/barrier.h
79657index 1402fa8..025a736 100644
79658--- a/include/asm-generic/barrier.h
79659+++ b/include/asm-generic/barrier.h
79660@@ -74,7 +74,7 @@
79661 do { \
79662 compiletime_assert_atomic_type(*p); \
79663 smp_mb(); \
79664- ACCESS_ONCE(*p) = (v); \
79665+ ACCESS_ONCE_RW(*p) = (v); \
79666 } while (0)
79667
79668 #define smp_load_acquire(p) \
79669diff --git a/include/asm-generic/bitops/__fls.h b/include/asm-generic/bitops/__fls.h
79670index a60a7cc..0fe12f2 100644
79671--- a/include/asm-generic/bitops/__fls.h
79672+++ b/include/asm-generic/bitops/__fls.h
79673@@ -9,7 +9,7 @@
79674 *
79675 * Undefined if no set bit exists, so code should check against 0 first.
79676 */
79677-static __always_inline unsigned long __fls(unsigned long word)
79678+static __always_inline unsigned long __intentional_overflow(-1) __fls(unsigned long word)
79679 {
79680 int num = BITS_PER_LONG - 1;
79681
79682diff --git a/include/asm-generic/bitops/fls.h b/include/asm-generic/bitops/fls.h
79683index 0576d1f..dad6c71 100644
79684--- a/include/asm-generic/bitops/fls.h
79685+++ b/include/asm-generic/bitops/fls.h
79686@@ -9,7 +9,7 @@
79687 * Note fls(0) = 0, fls(1) = 1, fls(0x80000000) = 32.
79688 */
79689
79690-static __always_inline int fls(int x)
79691+static __always_inline int __intentional_overflow(-1) fls(int x)
79692 {
79693 int r = 32;
79694
79695diff --git a/include/asm-generic/bitops/fls64.h b/include/asm-generic/bitops/fls64.h
79696index b097cf8..3d40e14 100644
79697--- a/include/asm-generic/bitops/fls64.h
79698+++ b/include/asm-generic/bitops/fls64.h
79699@@ -15,7 +15,7 @@
79700 * at position 64.
79701 */
79702 #if BITS_PER_LONG == 32
79703-static __always_inline int fls64(__u64 x)
79704+static __always_inline int __intentional_overflow(-1) fls64(__u64 x)
79705 {
79706 __u32 h = x >> 32;
79707 if (h)
79708@@ -23,7 +23,7 @@ static __always_inline int fls64(__u64 x)
79709 return fls(x);
79710 }
79711 #elif BITS_PER_LONG == 64
79712-static __always_inline int fls64(__u64 x)
79713+static __always_inline int __intentional_overflow(-1) fls64(__u64 x)
79714 {
79715 if (x == 0)
79716 return 0;
79717diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
79718index 1bfcfe5..e04c5c9 100644
79719--- a/include/asm-generic/cache.h
79720+++ b/include/asm-generic/cache.h
79721@@ -6,7 +6,7 @@
79722 * cache lines need to provide their own cache.h.
79723 */
79724
79725-#define L1_CACHE_SHIFT 5
79726-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
79727+#define L1_CACHE_SHIFT 5UL
79728+#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
79729
79730 #endif /* __ASM_GENERIC_CACHE_H */
79731diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
79732index 0d68a1e..b74a761 100644
79733--- a/include/asm-generic/emergency-restart.h
79734+++ b/include/asm-generic/emergency-restart.h
79735@@ -1,7 +1,7 @@
79736 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
79737 #define _ASM_GENERIC_EMERGENCY_RESTART_H
79738
79739-static inline void machine_emergency_restart(void)
79740+static inline __noreturn void machine_emergency_restart(void)
79741 {
79742 machine_restart(NULL);
79743 }
79744diff --git a/include/asm-generic/io.h b/include/asm-generic/io.h
79745index b8fdc57..c6d5a5c 100644
79746--- a/include/asm-generic/io.h
79747+++ b/include/asm-generic/io.h
79748@@ -289,7 +289,7 @@ static inline void pci_iounmap(struct pci_dev *dev, void __iomem *p)
79749 * These are pretty trivial
79750 */
79751 #ifndef virt_to_phys
79752-static inline unsigned long virt_to_phys(volatile void *address)
79753+static inline unsigned long __intentional_overflow(-1) virt_to_phys(volatile void *address)
79754 {
79755 return __pa((unsigned long)address);
79756 }
79757diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
79758index 90f99c7..00ce236 100644
79759--- a/include/asm-generic/kmap_types.h
79760+++ b/include/asm-generic/kmap_types.h
79761@@ -2,9 +2,9 @@
79762 #define _ASM_GENERIC_KMAP_TYPES_H
79763
79764 #ifdef __WITH_KM_FENCE
79765-# define KM_TYPE_NR 41
79766+# define KM_TYPE_NR 42
79767 #else
79768-# define KM_TYPE_NR 20
79769+# define KM_TYPE_NR 21
79770 #endif
79771
79772 #endif
79773diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
79774index 9ceb03b..62b0b8f 100644
79775--- a/include/asm-generic/local.h
79776+++ b/include/asm-generic/local.h
79777@@ -23,24 +23,37 @@ typedef struct
79778 atomic_long_t a;
79779 } local_t;
79780
79781+typedef struct {
79782+ atomic_long_unchecked_t a;
79783+} local_unchecked_t;
79784+
79785 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
79786
79787 #define local_read(l) atomic_long_read(&(l)->a)
79788+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
79789 #define local_set(l,i) atomic_long_set((&(l)->a),(i))
79790+#define local_set_unchecked(l,i) atomic_long_set_unchecked((&(l)->a),(i))
79791 #define local_inc(l) atomic_long_inc(&(l)->a)
79792+#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
79793 #define local_dec(l) atomic_long_dec(&(l)->a)
79794+#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
79795 #define local_add(i,l) atomic_long_add((i),(&(l)->a))
79796+#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
79797 #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
79798+#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
79799
79800 #define local_sub_and_test(i, l) atomic_long_sub_and_test((i), (&(l)->a))
79801 #define local_dec_and_test(l) atomic_long_dec_and_test(&(l)->a)
79802 #define local_inc_and_test(l) atomic_long_inc_and_test(&(l)->a)
79803 #define local_add_negative(i, l) atomic_long_add_negative((i), (&(l)->a))
79804 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
79805+#define local_add_return_unchecked(i, l) atomic_long_add_return_unchecked((i), (&(l)->a))
79806 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
79807 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
79808+#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
79809
79810 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
79811+#define local_cmpxchg_unchecked(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
79812 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
79813 #define local_add_unless(l, _a, u) atomic_long_add_unless((&(l)->a), (_a), (u))
79814 #define local_inc_not_zero(l) atomic_long_inc_not_zero(&(l)->a)
79815diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
79816index 725612b..9cc513a 100644
79817--- a/include/asm-generic/pgtable-nopmd.h
79818+++ b/include/asm-generic/pgtable-nopmd.h
79819@@ -1,14 +1,19 @@
79820 #ifndef _PGTABLE_NOPMD_H
79821 #define _PGTABLE_NOPMD_H
79822
79823-#ifndef __ASSEMBLY__
79824-
79825 #include <asm-generic/pgtable-nopud.h>
79826
79827-struct mm_struct;
79828-
79829 #define __PAGETABLE_PMD_FOLDED
79830
79831+#define PMD_SHIFT PUD_SHIFT
79832+#define PTRS_PER_PMD 1
79833+#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
79834+#define PMD_MASK (~(PMD_SIZE-1))
79835+
79836+#ifndef __ASSEMBLY__
79837+
79838+struct mm_struct;
79839+
79840 /*
79841 * Having the pmd type consist of a pud gets the size right, and allows
79842 * us to conceptually access the pud entry that this pmd is folded into
79843@@ -16,11 +21,6 @@ struct mm_struct;
79844 */
79845 typedef struct { pud_t pud; } pmd_t;
79846
79847-#define PMD_SHIFT PUD_SHIFT
79848-#define PTRS_PER_PMD 1
79849-#define PMD_SIZE (1UL << PMD_SHIFT)
79850-#define PMD_MASK (~(PMD_SIZE-1))
79851-
79852 /*
79853 * The "pud_xxx()" functions here are trivial for a folded two-level
79854 * setup: the pmd is never bad, and a pmd always exists (as it's folded
79855diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
79856index 810431d..0ec4804f 100644
79857--- a/include/asm-generic/pgtable-nopud.h
79858+++ b/include/asm-generic/pgtable-nopud.h
79859@@ -1,10 +1,15 @@
79860 #ifndef _PGTABLE_NOPUD_H
79861 #define _PGTABLE_NOPUD_H
79862
79863-#ifndef __ASSEMBLY__
79864-
79865 #define __PAGETABLE_PUD_FOLDED
79866
79867+#define PUD_SHIFT PGDIR_SHIFT
79868+#define PTRS_PER_PUD 1
79869+#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
79870+#define PUD_MASK (~(PUD_SIZE-1))
79871+
79872+#ifndef __ASSEMBLY__
79873+
79874 /*
79875 * Having the pud type consist of a pgd gets the size right, and allows
79876 * us to conceptually access the pgd entry that this pud is folded into
79877@@ -12,11 +17,6 @@
79878 */
79879 typedef struct { pgd_t pgd; } pud_t;
79880
79881-#define PUD_SHIFT PGDIR_SHIFT
79882-#define PTRS_PER_PUD 1
79883-#define PUD_SIZE (1UL << PUD_SHIFT)
79884-#define PUD_MASK (~(PUD_SIZE-1))
79885-
79886 /*
79887 * The "pgd_xxx()" functions here are trivial for a folded two-level
79888 * setup: the pud is never bad, and a pud always exists (as it's folded
79889@@ -29,6 +29,7 @@ static inline void pgd_clear(pgd_t *pgd) { }
79890 #define pud_ERROR(pud) (pgd_ERROR((pud).pgd))
79891
79892 #define pgd_populate(mm, pgd, pud) do { } while (0)
79893+#define pgd_populate_kernel(mm, pgd, pud) do { } while (0)
79894 /*
79895 * (puds are folded into pgds so this doesn't get actually called,
79896 * but the define is needed for a generic inline function.)
79897diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
79898index 752e30d..87f172d 100644
79899--- a/include/asm-generic/pgtable.h
79900+++ b/include/asm-generic/pgtable.h
79901@@ -828,6 +828,22 @@ static inline void pmdp_set_numa(struct mm_struct *mm, unsigned long addr,
79902 }
79903 #endif /* CONFIG_NUMA_BALANCING */
79904
79905+#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
79906+#ifdef CONFIG_PAX_KERNEXEC
79907+#error KERNEXEC requires pax_open_kernel
79908+#else
79909+static inline unsigned long pax_open_kernel(void) { return 0; }
79910+#endif
79911+#endif
79912+
79913+#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
79914+#ifdef CONFIG_PAX_KERNEXEC
79915+#error KERNEXEC requires pax_close_kernel
79916+#else
79917+static inline unsigned long pax_close_kernel(void) { return 0; }
79918+#endif
79919+#endif
79920+
79921 #endif /* CONFIG_MMU */
79922
79923 #endif /* !__ASSEMBLY__ */
79924diff --git a/include/asm-generic/uaccess.h b/include/asm-generic/uaccess.h
79925index 72d8803..cb9749c 100644
79926--- a/include/asm-generic/uaccess.h
79927+++ b/include/asm-generic/uaccess.h
79928@@ -343,4 +343,20 @@ clear_user(void __user *to, unsigned long n)
79929 return __clear_user(to, n);
79930 }
79931
79932+#ifndef __HAVE_ARCH_PAX_OPEN_USERLAND
79933+#ifdef CONFIG_PAX_MEMORY_UDEREF
79934+#error UDEREF requires pax_open_userland
79935+#else
79936+static inline unsigned long pax_open_userland(void) { return 0; }
79937+#endif
79938+#endif
79939+
79940+#ifndef __HAVE_ARCH_PAX_CLOSE_USERLAND
79941+#ifdef CONFIG_PAX_MEMORY_UDEREF
79942+#error UDEREF requires pax_close_userland
79943+#else
79944+static inline unsigned long pax_close_userland(void) { return 0; }
79945+#endif
79946+#endif
79947+
79948 #endif /* __ASM_GENERIC_UACCESS_H */
79949diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
79950index aa70cbd..fd72c7a 100644
79951--- a/include/asm-generic/vmlinux.lds.h
79952+++ b/include/asm-generic/vmlinux.lds.h
79953@@ -233,6 +233,7 @@
79954 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
79955 VMLINUX_SYMBOL(__start_rodata) = .; \
79956 *(.rodata) *(.rodata.*) \
79957+ *(.data..read_only) \
79958 *(__vermagic) /* Kernel version magic */ \
79959 . = ALIGN(8); \
79960 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
79961@@ -724,17 +725,18 @@
79962 * section in the linker script will go there too. @phdr should have
79963 * a leading colon.
79964 *
79965- * Note that this macros defines __per_cpu_load as an absolute symbol.
79966+ * Note that this macros defines per_cpu_load as an absolute symbol.
79967 * If there is no need to put the percpu section at a predetermined
79968 * address, use PERCPU_SECTION.
79969 */
79970 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
79971- VMLINUX_SYMBOL(__per_cpu_load) = .; \
79972- .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
79973+ per_cpu_load = .; \
79974+ .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
79975 - LOAD_OFFSET) { \
79976+ VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
79977 PERCPU_INPUT(cacheline) \
79978 } phdr \
79979- . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
79980+ . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
79981
79982 /**
79983 * PERCPU_SECTION - define output section for percpu area, simple version
79984diff --git a/include/crypto/algapi.h b/include/crypto/algapi.h
79985index 623a59c..1e79ab9 100644
79986--- a/include/crypto/algapi.h
79987+++ b/include/crypto/algapi.h
79988@@ -34,7 +34,7 @@ struct crypto_type {
79989 unsigned int maskclear;
79990 unsigned int maskset;
79991 unsigned int tfmsize;
79992-};
79993+} __do_const;
79994
79995 struct crypto_instance {
79996 struct crypto_alg alg;
79997diff --git a/include/drm/drmP.h b/include/drm/drmP.h
79998index 53ed876..5bb09be 100644
79999--- a/include/drm/drmP.h
80000+++ b/include/drm/drmP.h
80001@@ -59,6 +59,7 @@
80002
80003 #include <asm/mman.h>
80004 #include <asm/pgalloc.h>
80005+#include <asm/local.h>
80006 #include <asm/uaccess.h>
80007
80008 #include <uapi/drm/drm.h>
80009@@ -223,10 +224,12 @@ void drm_err(const char *func, const char *format, ...);
80010 * \param cmd command.
80011 * \param arg argument.
80012 */
80013-typedef int drm_ioctl_t(struct drm_device *dev, void *data,
80014+typedef int (* const drm_ioctl_t)(struct drm_device *dev, void *data,
80015+ struct drm_file *file_priv);
80016+typedef int (* drm_ioctl_no_const_t)(struct drm_device *dev, void *data,
80017 struct drm_file *file_priv);
80018
80019-typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
80020+typedef int (* const drm_ioctl_compat_t)(struct file *filp, unsigned int cmd,
80021 unsigned long arg);
80022
80023 #define DRM_IOCTL_NR(n) _IOC_NR(n)
80024@@ -242,10 +245,10 @@ typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
80025 struct drm_ioctl_desc {
80026 unsigned int cmd;
80027 int flags;
80028- drm_ioctl_t *func;
80029+ drm_ioctl_t func;
80030 unsigned int cmd_drv;
80031 const char *name;
80032-};
80033+} __do_const;
80034
80035 /**
80036 * Creates a driver or general drm_ioctl_desc array entry for the given
80037@@ -629,7 +632,8 @@ struct drm_info_list {
80038 int (*show)(struct seq_file*, void*); /** show callback */
80039 u32 driver_features; /**< Required driver features for this entry */
80040 void *data;
80041-};
80042+} __do_const;
80043+typedef struct drm_info_list __no_const drm_info_list_no_const;
80044
80045 /**
80046 * debugfs node structure. This structure represents a debugfs file.
80047@@ -713,7 +717,7 @@ struct drm_device {
80048
80049 /** \name Usage Counters */
80050 /*@{ */
80051- int open_count; /**< Outstanding files open, protected by drm_global_mutex. */
80052+ local_t open_count; /**< Outstanding files open, protected by drm_global_mutex. */
80053 spinlock_t buf_lock; /**< For drm_device::buf_use and a few other things. */
80054 int buf_use; /**< Buffers in use -- cannot alloc */
80055 atomic_t buf_alloc; /**< Buffer allocation in progress */
80056diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
80057index a3d75fe..6802f9c 100644
80058--- a/include/drm/drm_crtc_helper.h
80059+++ b/include/drm/drm_crtc_helper.h
80060@@ -109,7 +109,7 @@ struct drm_encoder_helper_funcs {
80061 struct drm_connector *connector);
80062 /* disable encoder when not in use - more explicit than dpms off */
80063 void (*disable)(struct drm_encoder *encoder);
80064-};
80065+} __no_const;
80066
80067 /**
80068 * drm_connector_helper_funcs - helper operations for connectors
80069diff --git a/include/drm/i915_pciids.h b/include/drm/i915_pciids.h
80070index a70d456..6ea07cd 100644
80071--- a/include/drm/i915_pciids.h
80072+++ b/include/drm/i915_pciids.h
80073@@ -37,7 +37,7 @@
80074 */
80075 #define INTEL_VGA_DEVICE(id, info) { \
80076 0x8086, id, \
80077- ~0, ~0, \
80078+ PCI_ANY_ID, PCI_ANY_ID, \
80079 0x030000, 0xff0000, \
80080 (unsigned long) info }
80081
80082diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
80083index 72dcbe8..8db58d7 100644
80084--- a/include/drm/ttm/ttm_memory.h
80085+++ b/include/drm/ttm/ttm_memory.h
80086@@ -48,7 +48,7 @@
80087
80088 struct ttm_mem_shrink {
80089 int (*do_shrink) (struct ttm_mem_shrink *);
80090-};
80091+} __no_const;
80092
80093 /**
80094 * struct ttm_mem_global - Global memory accounting structure.
80095diff --git a/include/drm/ttm/ttm_page_alloc.h b/include/drm/ttm/ttm_page_alloc.h
80096index 49a8284..9643967 100644
80097--- a/include/drm/ttm/ttm_page_alloc.h
80098+++ b/include/drm/ttm/ttm_page_alloc.h
80099@@ -80,6 +80,7 @@ void ttm_dma_page_alloc_fini(void);
80100 */
80101 extern int ttm_dma_page_alloc_debugfs(struct seq_file *m, void *data);
80102
80103+struct device;
80104 extern int ttm_dma_populate(struct ttm_dma_tt *ttm_dma, struct device *dev);
80105 extern void ttm_dma_unpopulate(struct ttm_dma_tt *ttm_dma, struct device *dev);
80106
80107diff --git a/include/keys/asymmetric-subtype.h b/include/keys/asymmetric-subtype.h
80108index 4b840e8..155d235 100644
80109--- a/include/keys/asymmetric-subtype.h
80110+++ b/include/keys/asymmetric-subtype.h
80111@@ -37,7 +37,7 @@ struct asymmetric_key_subtype {
80112 /* Verify the signature on a key of this subtype (optional) */
80113 int (*verify_signature)(const struct key *key,
80114 const struct public_key_signature *sig);
80115-};
80116+} __do_const;
80117
80118 /**
80119 * asymmetric_key_subtype - Get the subtype from an asymmetric key
80120diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
80121index c1da539..1dcec55 100644
80122--- a/include/linux/atmdev.h
80123+++ b/include/linux/atmdev.h
80124@@ -28,7 +28,7 @@ struct compat_atm_iobuf {
80125 #endif
80126
80127 struct k_atm_aal_stats {
80128-#define __HANDLE_ITEM(i) atomic_t i
80129+#define __HANDLE_ITEM(i) atomic_unchecked_t i
80130 __AAL_STAT_ITEMS
80131 #undef __HANDLE_ITEM
80132 };
80133@@ -200,7 +200,7 @@ struct atmdev_ops { /* only send is required */
80134 int (*change_qos)(struct atm_vcc *vcc,struct atm_qos *qos,int flags);
80135 int (*proc_read)(struct atm_dev *dev,loff_t *pos,char *page);
80136 struct module *owner;
80137-};
80138+} __do_const ;
80139
80140 struct atmphy_ops {
80141 int (*start)(struct atm_dev *dev);
80142diff --git a/include/linux/audit.h b/include/linux/audit.h
80143index e58fe7d..be9f6d8 100644
80144--- a/include/linux/audit.h
80145+++ b/include/linux/audit.h
80146@@ -215,7 +215,7 @@ static inline void audit_ptrace(struct task_struct *t)
80147 extern unsigned int audit_serial(void);
80148 extern int auditsc_get_stamp(struct audit_context *ctx,
80149 struct timespec *t, unsigned int *serial);
80150-extern int audit_set_loginuid(kuid_t loginuid);
80151+extern int __intentional_overflow(-1) audit_set_loginuid(kuid_t loginuid);
80152
80153 static inline kuid_t audit_get_loginuid(struct task_struct *tsk)
80154 {
80155diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
80156index 61f29e5..e67c658 100644
80157--- a/include/linux/binfmts.h
80158+++ b/include/linux/binfmts.h
80159@@ -44,7 +44,7 @@ struct linux_binprm {
80160 unsigned interp_flags;
80161 unsigned interp_data;
80162 unsigned long loader, exec;
80163-};
80164+} __randomize_layout;
80165
80166 #define BINPRM_FLAGS_ENFORCE_NONDUMP_BIT 0
80167 #define BINPRM_FLAGS_ENFORCE_NONDUMP (1 << BINPRM_FLAGS_ENFORCE_NONDUMP_BIT)
80168@@ -73,8 +73,10 @@ struct linux_binfmt {
80169 int (*load_binary)(struct linux_binprm *);
80170 int (*load_shlib)(struct file *);
80171 int (*core_dump)(struct coredump_params *cprm);
80172+ void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
80173+ void (*handle_mmap)(struct file *);
80174 unsigned long min_coredump; /* minimal dump size */
80175-};
80176+} __do_const __randomize_layout;
80177
80178 extern void __register_binfmt(struct linux_binfmt *fmt, int insert);
80179
80180diff --git a/include/linux/bitops.h b/include/linux/bitops.h
80181index 5d858e0..336c1d9 100644
80182--- a/include/linux/bitops.h
80183+++ b/include/linux/bitops.h
80184@@ -105,7 +105,7 @@ static inline __u64 ror64(__u64 word, unsigned int shift)
80185 * @word: value to rotate
80186 * @shift: bits to roll
80187 */
80188-static inline __u32 rol32(__u32 word, unsigned int shift)
80189+static inline __u32 __intentional_overflow(-1) rol32(__u32 word, unsigned int shift)
80190 {
80191 return (word << shift) | (word >> (32 - shift));
80192 }
80193@@ -115,7 +115,7 @@ static inline __u32 rol32(__u32 word, unsigned int shift)
80194 * @word: value to rotate
80195 * @shift: bits to roll
80196 */
80197-static inline __u32 ror32(__u32 word, unsigned int shift)
80198+static inline __u32 __intentional_overflow(-1) ror32(__u32 word, unsigned int shift)
80199 {
80200 return (word >> shift) | (word << (32 - shift));
80201 }
80202@@ -171,7 +171,7 @@ static inline __s32 sign_extend32(__u32 value, int index)
80203 return (__s32)(value << shift) >> shift;
80204 }
80205
80206-static inline unsigned fls_long(unsigned long l)
80207+static inline unsigned __intentional_overflow(-1) fls_long(unsigned long l)
80208 {
80209 if (sizeof(l) == 4)
80210 return fls(l);
80211diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
80212index aac0f9e..73c9869 100644
80213--- a/include/linux/blkdev.h
80214+++ b/include/linux/blkdev.h
80215@@ -1615,7 +1615,7 @@ struct block_device_operations {
80216 /* this callback is with swap_lock and sometimes page table lock held */
80217 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
80218 struct module *owner;
80219-};
80220+} __do_const;
80221
80222 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
80223 unsigned long);
80224diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
80225index afc1343..9735539 100644
80226--- a/include/linux/blktrace_api.h
80227+++ b/include/linux/blktrace_api.h
80228@@ -25,7 +25,7 @@ struct blk_trace {
80229 struct dentry *dropped_file;
80230 struct dentry *msg_file;
80231 struct list_head running_list;
80232- atomic_t dropped;
80233+ atomic_unchecked_t dropped;
80234 };
80235
80236 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
80237diff --git a/include/linux/cache.h b/include/linux/cache.h
80238index 17e7e82..1d7da26 100644
80239--- a/include/linux/cache.h
80240+++ b/include/linux/cache.h
80241@@ -16,6 +16,14 @@
80242 #define __read_mostly
80243 #endif
80244
80245+#ifndef __read_only
80246+#ifdef CONFIG_PAX_KERNEXEC
80247+#error KERNEXEC requires __read_only
80248+#else
80249+#define __read_only __read_mostly
80250+#endif
80251+#endif
80252+
80253 #ifndef ____cacheline_aligned
80254 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
80255 #endif
80256diff --git a/include/linux/capability.h b/include/linux/capability.h
80257index aa93e5e..985a1b0 100644
80258--- a/include/linux/capability.h
80259+++ b/include/linux/capability.h
80260@@ -214,9 +214,14 @@ extern bool has_ns_capability_noaudit(struct task_struct *t,
80261 extern bool capable(int cap);
80262 extern bool ns_capable(struct user_namespace *ns, int cap);
80263 extern bool capable_wrt_inode_uidgid(const struct inode *inode, int cap);
80264+extern bool capable_wrt_inode_uidgid_nolog(const struct inode *inode, int cap);
80265 extern bool file_ns_capable(const struct file *file, struct user_namespace *ns, int cap);
80266+extern bool capable_nolog(int cap);
80267+extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
80268
80269 /* audit system wants to get cap info from files as well */
80270 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
80271
80272+extern int is_privileged_binary(const struct dentry *dentry);
80273+
80274 #endif /* !_LINUX_CAPABILITY_H */
80275diff --git a/include/linux/cdrom.h b/include/linux/cdrom.h
80276index 8609d57..86e4d79 100644
80277--- a/include/linux/cdrom.h
80278+++ b/include/linux/cdrom.h
80279@@ -87,7 +87,6 @@ struct cdrom_device_ops {
80280
80281 /* driver specifications */
80282 const int capability; /* capability flags */
80283- int n_minors; /* number of active minor devices */
80284 /* handle uniform packets for scsi type devices (scsi,atapi) */
80285 int (*generic_packet) (struct cdrom_device_info *,
80286 struct packet_command *);
80287diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
80288index 4ce9056..86caac6 100644
80289--- a/include/linux/cleancache.h
80290+++ b/include/linux/cleancache.h
80291@@ -31,7 +31,7 @@ struct cleancache_ops {
80292 void (*invalidate_page)(int, struct cleancache_filekey, pgoff_t);
80293 void (*invalidate_inode)(int, struct cleancache_filekey);
80294 void (*invalidate_fs)(int);
80295-};
80296+} __no_const;
80297
80298 extern struct cleancache_ops *
80299 cleancache_register_ops(struct cleancache_ops *ops);
80300diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h
80301index 2839c63..5b06b6b 100644
80302--- a/include/linux/clk-provider.h
80303+++ b/include/linux/clk-provider.h
80304@@ -191,6 +191,7 @@ struct clk_ops {
80305 void (*init)(struct clk_hw *hw);
80306 int (*debug_init)(struct clk_hw *hw, struct dentry *dentry);
80307 };
80308+typedef struct clk_ops __no_const clk_ops_no_const;
80309
80310 /**
80311 * struct clk_init_data - holds init data that's common to all clocks and is
80312diff --git a/include/linux/compat.h b/include/linux/compat.h
80313index e649426..a74047b 100644
80314--- a/include/linux/compat.h
80315+++ b/include/linux/compat.h
80316@@ -316,7 +316,7 @@ compat_sys_get_robust_list(int pid, compat_uptr_t __user *head_ptr,
80317 compat_size_t __user *len_ptr);
80318
80319 asmlinkage long compat_sys_ipc(u32, int, int, u32, compat_uptr_t, u32);
80320-asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg);
80321+asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg) __intentional_overflow(0);
80322 asmlinkage long compat_sys_semctl(int semid, int semnum, int cmd, int arg);
80323 asmlinkage long compat_sys_msgsnd(int msqid, compat_uptr_t msgp,
80324 compat_ssize_t msgsz, int msgflg);
80325@@ -436,7 +436,7 @@ extern int compat_ptrace_request(struct task_struct *child,
80326 extern long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
80327 compat_ulong_t addr, compat_ulong_t data);
80328 asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
80329- compat_long_t addr, compat_long_t data);
80330+ compat_ulong_t addr, compat_ulong_t data);
80331
80332 asmlinkage long compat_sys_lookup_dcookie(u32, u32, char __user *, compat_size_t);
80333 /*
80334diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
80335index d1a5582..4424efa 100644
80336--- a/include/linux/compiler-gcc4.h
80337+++ b/include/linux/compiler-gcc4.h
80338@@ -39,9 +39,34 @@
80339 # define __compiletime_warning(message) __attribute__((warning(message)))
80340 # define __compiletime_error(message) __attribute__((error(message)))
80341 #endif /* __CHECKER__ */
80342+
80343+#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
80344+#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
80345+#define __bos0(ptr) __bos((ptr), 0)
80346+#define __bos1(ptr) __bos((ptr), 1)
80347 #endif /* GCC_VERSION >= 40300 */
80348
80349 #if GCC_VERSION >= 40500
80350+
80351+#ifdef RANDSTRUCT_PLUGIN
80352+#define __randomize_layout __attribute__((randomize_layout))
80353+#define __no_randomize_layout __attribute__((no_randomize_layout))
80354+#endif
80355+
80356+#ifdef CONSTIFY_PLUGIN
80357+#define __no_const __attribute__((no_const))
80358+#define __do_const __attribute__((do_const))
80359+#endif
80360+
80361+#ifdef SIZE_OVERFLOW_PLUGIN
80362+#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
80363+#define __intentional_overflow(...) __attribute__((intentional_overflow(__VA_ARGS__)))
80364+#endif
80365+
80366+#ifdef LATENT_ENTROPY_PLUGIN
80367+#define __latent_entropy __attribute__((latent_entropy))
80368+#endif
80369+
80370 /*
80371 * Mark a position in code as unreachable. This can be used to
80372 * suppress control flow warnings after asm blocks that transfer
80373diff --git a/include/linux/compiler.h b/include/linux/compiler.h
80374index d5ad7b1..3b74638 100644
80375--- a/include/linux/compiler.h
80376+++ b/include/linux/compiler.h
80377@@ -5,11 +5,14 @@
80378
80379 #ifdef __CHECKER__
80380 # define __user __attribute__((noderef, address_space(1)))
80381+# define __force_user __force __user
80382 # define __kernel __attribute__((address_space(0)))
80383+# define __force_kernel __force __kernel
80384 # define __safe __attribute__((safe))
80385 # define __force __attribute__((force))
80386 # define __nocast __attribute__((nocast))
80387 # define __iomem __attribute__((noderef, address_space(2)))
80388+# define __force_iomem __force __iomem
80389 # define __must_hold(x) __attribute__((context(x,1,1)))
80390 # define __acquires(x) __attribute__((context(x,0,1)))
80391 # define __releases(x) __attribute__((context(x,1,0)))
80392@@ -17,20 +20,37 @@
80393 # define __release(x) __context__(x,-1)
80394 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
80395 # define __percpu __attribute__((noderef, address_space(3)))
80396+# define __force_percpu __force __percpu
80397 #ifdef CONFIG_SPARSE_RCU_POINTER
80398 # define __rcu __attribute__((noderef, address_space(4)))
80399+# define __force_rcu __force __rcu
80400 #else
80401 # define __rcu
80402+# define __force_rcu
80403 #endif
80404 extern void __chk_user_ptr(const volatile void __user *);
80405 extern void __chk_io_ptr(const volatile void __iomem *);
80406 #else
80407-# define __user
80408-# define __kernel
80409+# ifdef CHECKER_PLUGIN
80410+//# define __user
80411+//# define __force_user
80412+//# define __kernel
80413+//# define __force_kernel
80414+# else
80415+# ifdef STRUCTLEAK_PLUGIN
80416+# define __user __attribute__((user))
80417+# else
80418+# define __user
80419+# endif
80420+# define __force_user
80421+# define __kernel
80422+# define __force_kernel
80423+# endif
80424 # define __safe
80425 # define __force
80426 # define __nocast
80427 # define __iomem
80428+# define __force_iomem
80429 # define __chk_user_ptr(x) (void)0
80430 # define __chk_io_ptr(x) (void)0
80431 # define __builtin_warning(x, y...) (1)
80432@@ -41,7 +61,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
80433 # define __release(x) (void)0
80434 # define __cond_lock(x,c) (c)
80435 # define __percpu
80436+# define __force_percpu
80437 # define __rcu
80438+# define __force_rcu
80439 #endif
80440
80441 /* Indirect macros required for expanded argument pasting, eg. __LINE__. */
80442@@ -286,6 +308,34 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
80443 # define __attribute_const__ /* unimplemented */
80444 #endif
80445
80446+#ifndef __randomize_layout
80447+# define __randomize_layout
80448+#endif
80449+
80450+#ifndef __no_randomize_layout
80451+# define __no_randomize_layout
80452+#endif
80453+
80454+#ifndef __no_const
80455+# define __no_const
80456+#endif
80457+
80458+#ifndef __do_const
80459+# define __do_const
80460+#endif
80461+
80462+#ifndef __size_overflow
80463+# define __size_overflow(...)
80464+#endif
80465+
80466+#ifndef __intentional_overflow
80467+# define __intentional_overflow(...)
80468+#endif
80469+
80470+#ifndef __latent_entropy
80471+# define __latent_entropy
80472+#endif
80473+
80474 /*
80475 * Tell gcc if a function is cold. The compiler will assume any path
80476 * directly leading to the call is unlikely.
80477@@ -295,6 +345,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
80478 #define __cold
80479 #endif
80480
80481+#ifndef __alloc_size
80482+#define __alloc_size(...)
80483+#endif
80484+
80485+#ifndef __bos
80486+#define __bos(ptr, arg)
80487+#endif
80488+
80489+#ifndef __bos0
80490+#define __bos0(ptr)
80491+#endif
80492+
80493+#ifndef __bos1
80494+#define __bos1(ptr)
80495+#endif
80496+
80497 /* Simple shorthand for a section definition */
80498 #ifndef __section
80499 # define __section(S) __attribute__ ((__section__(#S)))
80500@@ -378,7 +444,8 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
80501 * use is to mediate communication between process-level code and irq/NMI
80502 * handlers, all running on the same CPU.
80503 */
80504-#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
80505+#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
80506+#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
80507
80508 /* Ignore/forbid kprobes attach on very low level functions marked by this attribute: */
80509 #ifdef CONFIG_KPROBES
80510diff --git a/include/linux/completion.h b/include/linux/completion.h
80511index 5d5aaae..0ea9b84 100644
80512--- a/include/linux/completion.h
80513+++ b/include/linux/completion.h
80514@@ -90,16 +90,16 @@ static inline void reinit_completion(struct completion *x)
80515
80516 extern void wait_for_completion(struct completion *);
80517 extern void wait_for_completion_io(struct completion *);
80518-extern int wait_for_completion_interruptible(struct completion *x);
80519-extern int wait_for_completion_killable(struct completion *x);
80520+extern int wait_for_completion_interruptible(struct completion *x) __intentional_overflow(-1);
80521+extern int wait_for_completion_killable(struct completion *x) __intentional_overflow(-1);
80522 extern unsigned long wait_for_completion_timeout(struct completion *x,
80523- unsigned long timeout);
80524+ unsigned long timeout) __intentional_overflow(-1);
80525 extern unsigned long wait_for_completion_io_timeout(struct completion *x,
80526- unsigned long timeout);
80527+ unsigned long timeout) __intentional_overflow(-1);
80528 extern long wait_for_completion_interruptible_timeout(
80529- struct completion *x, unsigned long timeout);
80530+ struct completion *x, unsigned long timeout) __intentional_overflow(-1);
80531 extern long wait_for_completion_killable_timeout(
80532- struct completion *x, unsigned long timeout);
80533+ struct completion *x, unsigned long timeout) __intentional_overflow(-1);
80534 extern bool try_wait_for_completion(struct completion *x);
80535 extern bool completion_done(struct completion *x);
80536
80537diff --git a/include/linux/configfs.h b/include/linux/configfs.h
80538index 34025df..d94bbbc 100644
80539--- a/include/linux/configfs.h
80540+++ b/include/linux/configfs.h
80541@@ -125,7 +125,7 @@ struct configfs_attribute {
80542 const char *ca_name;
80543 struct module *ca_owner;
80544 umode_t ca_mode;
80545-};
80546+} __do_const;
80547
80548 /*
80549 * Users often need to create attribute structures for their configurable
80550diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h
80551index 503b085b..1638c9e 100644
80552--- a/include/linux/cpufreq.h
80553+++ b/include/linux/cpufreq.h
80554@@ -206,6 +206,7 @@ struct global_attr {
80555 ssize_t (*store)(struct kobject *a, struct attribute *b,
80556 const char *c, size_t count);
80557 };
80558+typedef struct global_attr __no_const global_attr_no_const;
80559
80560 #define define_one_global_ro(_name) \
80561 static struct global_attr _name = \
80562@@ -273,7 +274,7 @@ struct cpufreq_driver {
80563 bool boost_supported;
80564 bool boost_enabled;
80565 int (*set_boost) (int state);
80566-};
80567+} __do_const;
80568
80569 /* flags */
80570 #define CPUFREQ_STICKY (1 << 0) /* driver isn't removed even if
80571diff --git a/include/linux/cpuidle.h b/include/linux/cpuidle.h
80572index 25e0df6..952dffd 100644
80573--- a/include/linux/cpuidle.h
80574+++ b/include/linux/cpuidle.h
80575@@ -50,7 +50,8 @@ struct cpuidle_state {
80576 int index);
80577
80578 int (*enter_dead) (struct cpuidle_device *dev, int index);
80579-};
80580+} __do_const;
80581+typedef struct cpuidle_state __no_const cpuidle_state_no_const;
80582
80583 /* Idle State Flags */
80584 #define CPUIDLE_FLAG_TIME_VALID (0x01) /* is residency time measurable? */
80585@@ -209,7 +210,7 @@ struct cpuidle_governor {
80586 void (*reflect) (struct cpuidle_device *dev, int index);
80587
80588 struct module *owner;
80589-};
80590+} __do_const;
80591
80592 #ifdef CONFIG_CPU_IDLE
80593 extern int cpuidle_register_governor(struct cpuidle_governor *gov);
80594diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h
80595index 0a9a6da..ea597ca 100644
80596--- a/include/linux/cpumask.h
80597+++ b/include/linux/cpumask.h
80598@@ -118,17 +118,17 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
80599 }
80600
80601 /* Valid inputs for n are -1 and 0. */
80602-static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
80603+static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
80604 {
80605 return n+1;
80606 }
80607
80608-static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
80609+static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
80610 {
80611 return n+1;
80612 }
80613
80614-static inline unsigned int cpumask_next_and(int n,
80615+static inline unsigned int __intentional_overflow(-1) cpumask_next_and(int n,
80616 const struct cpumask *srcp,
80617 const struct cpumask *andp)
80618 {
80619@@ -174,7 +174,7 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
80620 *
80621 * Returns >= nr_cpu_ids if no further cpus set.
80622 */
80623-static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
80624+static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
80625 {
80626 /* -1 is a legal arg here. */
80627 if (n != -1)
80628@@ -189,7 +189,7 @@ static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
80629 *
80630 * Returns >= nr_cpu_ids if no further cpus unset.
80631 */
80632-static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
80633+static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
80634 {
80635 /* -1 is a legal arg here. */
80636 if (n != -1)
80637@@ -197,7 +197,7 @@ static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
80638 return find_next_zero_bit(cpumask_bits(srcp), nr_cpumask_bits, n+1);
80639 }
80640
80641-int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *);
80642+int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *) __intentional_overflow(-1);
80643 int cpumask_any_but(const struct cpumask *mask, unsigned int cpu);
80644 int cpumask_set_cpu_local_first(int i, int numa_node, cpumask_t *dstp);
80645
80646diff --git a/include/linux/cred.h b/include/linux/cred.h
80647index b2d0820..2ecafd3 100644
80648--- a/include/linux/cred.h
80649+++ b/include/linux/cred.h
80650@@ -35,7 +35,7 @@ struct group_info {
80651 int nblocks;
80652 kgid_t small_block[NGROUPS_SMALL];
80653 kgid_t *blocks[0];
80654-};
80655+} __randomize_layout;
80656
80657 /**
80658 * get_group_info - Get a reference to a group info structure
80659@@ -136,7 +136,7 @@ struct cred {
80660 struct user_namespace *user_ns; /* user_ns the caps and keyrings are relative to. */
80661 struct group_info *group_info; /* supplementary groups for euid/fsgid */
80662 struct rcu_head rcu; /* RCU deletion hook */
80663-};
80664+} __randomize_layout;
80665
80666 extern void __put_cred(struct cred *);
80667 extern void exit_creds(struct task_struct *);
80668@@ -194,6 +194,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
80669 static inline void validate_process_creds(void)
80670 {
80671 }
80672+static inline void validate_task_creds(struct task_struct *task)
80673+{
80674+}
80675 #endif
80676
80677 /**
80678@@ -331,6 +334,7 @@ static inline void put_cred(const struct cred *_cred)
80679
80680 #define task_uid(task) (task_cred_xxx((task), uid))
80681 #define task_euid(task) (task_cred_xxx((task), euid))
80682+#define task_securebits(task) (task_cred_xxx((task), securebits))
80683
80684 #define current_cred_xxx(xxx) \
80685 ({ \
80686diff --git a/include/linux/crypto.h b/include/linux/crypto.h
80687index d45e949..51cf5ea 100644
80688--- a/include/linux/crypto.h
80689+++ b/include/linux/crypto.h
80690@@ -373,7 +373,7 @@ struct cipher_tfm {
80691 const u8 *key, unsigned int keylen);
80692 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
80693 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
80694-};
80695+} __no_const;
80696
80697 struct hash_tfm {
80698 int (*init)(struct hash_desc *desc);
80699@@ -394,13 +394,13 @@ struct compress_tfm {
80700 int (*cot_decompress)(struct crypto_tfm *tfm,
80701 const u8 *src, unsigned int slen,
80702 u8 *dst, unsigned int *dlen);
80703-};
80704+} __no_const;
80705
80706 struct rng_tfm {
80707 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
80708 unsigned int dlen);
80709 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
80710-};
80711+} __no_const;
80712
80713 #define crt_ablkcipher crt_u.ablkcipher
80714 #define crt_aead crt_u.aead
80715diff --git a/include/linux/ctype.h b/include/linux/ctype.h
80716index 653589e..4ef254a 100644
80717--- a/include/linux/ctype.h
80718+++ b/include/linux/ctype.h
80719@@ -56,7 +56,7 @@ static inline unsigned char __toupper(unsigned char c)
80720 * Fast implementation of tolower() for internal usage. Do not use in your
80721 * code.
80722 */
80723-static inline char _tolower(const char c)
80724+static inline unsigned char _tolower(const unsigned char c)
80725 {
80726 return c | 0x20;
80727 }
80728diff --git a/include/linux/dcache.h b/include/linux/dcache.h
80729index 1c2f1b8..c67151e 100644
80730--- a/include/linux/dcache.h
80731+++ b/include/linux/dcache.h
80732@@ -133,7 +133,7 @@ struct dentry {
80733 struct hlist_node d_alias; /* inode alias list */
80734 struct rcu_head d_rcu;
80735 } d_u;
80736-};
80737+} __randomize_layout;
80738
80739 /*
80740 * dentry->d_lock spinlock nesting subclasses:
80741diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
80742index 7925bf0..d5143d2 100644
80743--- a/include/linux/decompress/mm.h
80744+++ b/include/linux/decompress/mm.h
80745@@ -77,7 +77,7 @@ static void free(void *where)
80746 * warnings when not needed (indeed large_malloc / large_free are not
80747 * needed by inflate */
80748
80749-#define malloc(a) kmalloc(a, GFP_KERNEL)
80750+#define malloc(a) kmalloc((a), GFP_KERNEL)
80751 #define free(a) kfree(a)
80752
80753 #define large_malloc(a) vmalloc(a)
80754diff --git a/include/linux/devfreq.h b/include/linux/devfreq.h
80755index f1863dc..5c26074 100644
80756--- a/include/linux/devfreq.h
80757+++ b/include/linux/devfreq.h
80758@@ -114,7 +114,7 @@ struct devfreq_governor {
80759 int (*get_target_freq)(struct devfreq *this, unsigned long *freq);
80760 int (*event_handler)(struct devfreq *devfreq,
80761 unsigned int event, void *data);
80762-};
80763+} __do_const;
80764
80765 /**
80766 * struct devfreq - Device devfreq structure
80767diff --git a/include/linux/device.h b/include/linux/device.h
80768index ce1f2160..189bc33 100644
80769--- a/include/linux/device.h
80770+++ b/include/linux/device.h
80771@@ -311,7 +311,7 @@ struct subsys_interface {
80772 struct list_head node;
80773 int (*add_dev)(struct device *dev, struct subsys_interface *sif);
80774 int (*remove_dev)(struct device *dev, struct subsys_interface *sif);
80775-};
80776+} __do_const;
80777
80778 int subsys_interface_register(struct subsys_interface *sif);
80779 void subsys_interface_unregister(struct subsys_interface *sif);
80780@@ -507,7 +507,7 @@ struct device_type {
80781 void (*release)(struct device *dev);
80782
80783 const struct dev_pm_ops *pm;
80784-};
80785+} __do_const;
80786
80787 /* interface for exporting device attributes */
80788 struct device_attribute {
80789@@ -517,11 +517,12 @@ struct device_attribute {
80790 ssize_t (*store)(struct device *dev, struct device_attribute *attr,
80791 const char *buf, size_t count);
80792 };
80793+typedef struct device_attribute __no_const device_attribute_no_const;
80794
80795 struct dev_ext_attribute {
80796 struct device_attribute attr;
80797 void *var;
80798-};
80799+} __do_const;
80800
80801 ssize_t device_show_ulong(struct device *dev, struct device_attribute *attr,
80802 char *buf);
80803diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
80804index d5d3881..7ed54af 100644
80805--- a/include/linux/dma-mapping.h
80806+++ b/include/linux/dma-mapping.h
80807@@ -60,7 +60,7 @@ struct dma_map_ops {
80808 u64 (*get_required_mask)(struct device *dev);
80809 #endif
80810 int is_phys;
80811-};
80812+} __do_const;
80813
80814 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
80815
80816diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
80817index 653a1fd..9133cd1 100644
80818--- a/include/linux/dmaengine.h
80819+++ b/include/linux/dmaengine.h
80820@@ -1136,9 +1136,9 @@ struct dma_pinned_list {
80821 struct dma_pinned_list *dma_pin_iovec_pages(struct iovec *iov, size_t len);
80822 void dma_unpin_iovec_pages(struct dma_pinned_list* pinned_list);
80823
80824-dma_cookie_t dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
80825+dma_cookie_t __intentional_overflow(0) dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
80826 struct dma_pinned_list *pinned_list, unsigned char *kdata, size_t len);
80827-dma_cookie_t dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
80828+dma_cookie_t __intentional_overflow(0) dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
80829 struct dma_pinned_list *pinned_list, struct page *page,
80830 unsigned int offset, size_t len);
80831
80832diff --git a/include/linux/efi.h b/include/linux/efi.h
80833index 0949f9c..04cb9a5 100644
80834--- a/include/linux/efi.h
80835+++ b/include/linux/efi.h
80836@@ -1050,6 +1050,7 @@ struct efivar_operations {
80837 efi_set_variable_nonblocking_t *set_variable_nonblocking;
80838 efi_query_variable_store_t *query_variable_store;
80839 };
80840+typedef struct efivar_operations __no_const efivar_operations_no_const;
80841
80842 struct efivars {
80843 /*
80844diff --git a/include/linux/elf.h b/include/linux/elf.h
80845index 67a5fa7..b817372 100644
80846--- a/include/linux/elf.h
80847+++ b/include/linux/elf.h
80848@@ -24,6 +24,7 @@ extern Elf32_Dyn _DYNAMIC [];
80849 #define elf_note elf32_note
80850 #define elf_addr_t Elf32_Off
80851 #define Elf_Half Elf32_Half
80852+#define elf_dyn Elf32_Dyn
80853
80854 #else
80855
80856@@ -34,6 +35,7 @@ extern Elf64_Dyn _DYNAMIC [];
80857 #define elf_note elf64_note
80858 #define elf_addr_t Elf64_Off
80859 #define Elf_Half Elf64_Half
80860+#define elf_dyn Elf64_Dyn
80861
80862 #endif
80863
80864diff --git a/include/linux/err.h b/include/linux/err.h
80865index a729120..6ede2c9 100644
80866--- a/include/linux/err.h
80867+++ b/include/linux/err.h
80868@@ -20,12 +20,12 @@
80869
80870 #define IS_ERR_VALUE(x) unlikely((x) >= (unsigned long)-MAX_ERRNO)
80871
80872-static inline void * __must_check ERR_PTR(long error)
80873+static inline void * __must_check __intentional_overflow(-1) ERR_PTR(long error)
80874 {
80875 return (void *) error;
80876 }
80877
80878-static inline long __must_check PTR_ERR(__force const void *ptr)
80879+static inline long __must_check __intentional_overflow(-1) PTR_ERR(__force const void *ptr)
80880 {
80881 return (long) ptr;
80882 }
80883diff --git a/include/linux/extcon.h b/include/linux/extcon.h
80884index 36f49c4..a2a1f4c 100644
80885--- a/include/linux/extcon.h
80886+++ b/include/linux/extcon.h
80887@@ -135,7 +135,7 @@ struct extcon_dev {
80888 /* /sys/class/extcon/.../mutually_exclusive/... */
80889 struct attribute_group attr_g_muex;
80890 struct attribute **attrs_muex;
80891- struct device_attribute *d_attrs_muex;
80892+ device_attribute_no_const *d_attrs_muex;
80893 };
80894
80895 /**
80896diff --git a/include/linux/fb.h b/include/linux/fb.h
80897index 09bb7a1..d98870a 100644
80898--- a/include/linux/fb.h
80899+++ b/include/linux/fb.h
80900@@ -305,7 +305,7 @@ struct fb_ops {
80901 /* called at KDB enter and leave time to prepare the console */
80902 int (*fb_debug_enter)(struct fb_info *info);
80903 int (*fb_debug_leave)(struct fb_info *info);
80904-};
80905+} __do_const;
80906
80907 #ifdef CONFIG_FB_TILEBLITTING
80908 #define FB_TILE_CURSOR_NONE 0
80909diff --git a/include/linux/fdtable.h b/include/linux/fdtable.h
80910index 230f87b..1fd0485 100644
80911--- a/include/linux/fdtable.h
80912+++ b/include/linux/fdtable.h
80913@@ -100,7 +100,7 @@ struct files_struct *get_files_struct(struct task_struct *);
80914 void put_files_struct(struct files_struct *fs);
80915 void reset_files_struct(struct files_struct *);
80916 int unshare_files(struct files_struct **);
80917-struct files_struct *dup_fd(struct files_struct *, int *);
80918+struct files_struct *dup_fd(struct files_struct *, int *) __latent_entropy;
80919 void do_close_on_exec(struct files_struct *);
80920 int iterate_fd(struct files_struct *, unsigned,
80921 int (*)(const void *, struct file *, unsigned),
80922diff --git a/include/linux/frontswap.h b/include/linux/frontswap.h
80923index 8293262..2b3b8bd 100644
80924--- a/include/linux/frontswap.h
80925+++ b/include/linux/frontswap.h
80926@@ -11,7 +11,7 @@ struct frontswap_ops {
80927 int (*load)(unsigned, pgoff_t, struct page *);
80928 void (*invalidate_page)(unsigned, pgoff_t);
80929 void (*invalidate_area)(unsigned);
80930-};
80931+} __no_const;
80932
80933 extern bool frontswap_enabled;
80934 extern struct frontswap_ops *
80935diff --git a/include/linux/fs.h b/include/linux/fs.h
80936index 9ab779e..0c636f2 100644
80937--- a/include/linux/fs.h
80938+++ b/include/linux/fs.h
80939@@ -412,7 +412,7 @@ struct address_space {
80940 spinlock_t private_lock; /* for use by the address_space */
80941 struct list_head private_list; /* ditto */
80942 void *private_data; /* ditto */
80943-} __attribute__((aligned(sizeof(long))));
80944+} __attribute__((aligned(sizeof(long)))) __randomize_layout;
80945 /*
80946 * On most architectures that alignment is already the case; but
80947 * must be enforced here for CRIS, to let the least significant bit
80948@@ -455,7 +455,7 @@ struct block_device {
80949 int bd_fsfreeze_count;
80950 /* Mutex for freeze */
80951 struct mutex bd_fsfreeze_mutex;
80952-};
80953+} __randomize_layout;
80954
80955 /*
80956 * Radix-tree tags, for tagging dirty and writeback pages within the pagecache
80957@@ -624,7 +624,7 @@ struct inode {
80958 #endif
80959
80960 void *i_private; /* fs or device private pointer */
80961-};
80962+} __randomize_layout;
80963
80964 static inline int inode_unhashed(struct inode *inode)
80965 {
80966@@ -820,7 +820,7 @@ struct file {
80967 struct list_head f_tfile_llink;
80968 #endif /* #ifdef CONFIG_EPOLL */
80969 struct address_space *f_mapping;
80970-} __attribute__((aligned(4))); /* lest something weird decides that 2 is OK */
80971+} __attribute__((aligned(4))) __randomize_layout; /* lest something weird decides that 2 is OK */
80972
80973 struct file_handle {
80974 __u32 handle_bytes;
80975@@ -945,7 +945,7 @@ struct file_lock {
80976 int state; /* state of grant or error if -ve */
80977 } afs;
80978 } fl_u;
80979-};
80980+} __randomize_layout;
80981
80982 /* The following constant reflects the upper bound of the file/locking space */
80983 #ifndef OFFSET_MAX
80984@@ -1287,7 +1287,7 @@ struct super_block {
80985 * Indicates how deep in a filesystem stack this SB is
80986 */
80987 int s_stack_depth;
80988-};
80989+} __randomize_layout;
80990
80991 extern struct timespec current_fs_time(struct super_block *sb);
80992
80993@@ -1514,7 +1514,8 @@ struct file_operations {
80994 long (*fallocate)(struct file *file, int mode, loff_t offset,
80995 loff_t len);
80996 int (*show_fdinfo)(struct seq_file *m, struct file *f);
80997-};
80998+} __do_const __randomize_layout;
80999+typedef struct file_operations __no_const file_operations_no_const;
81000
81001 struct inode_operations {
81002 struct dentry * (*lookup) (struct inode *,struct dentry *, unsigned int);
81003@@ -2823,4 +2824,14 @@ static inline bool dir_relax(struct inode *inode)
81004 return !IS_DEADDIR(inode);
81005 }
81006
81007+static inline bool is_sidechannel_device(const struct inode *inode)
81008+{
81009+#ifdef CONFIG_GRKERNSEC_DEVICE_SIDECHANNEL
81010+ umode_t mode = inode->i_mode;
81011+ return ((S_ISCHR(mode) || S_ISBLK(mode)) && (mode & (S_IROTH | S_IWOTH)));
81012+#else
81013+ return false;
81014+#endif
81015+}
81016+
81017 #endif /* _LINUX_FS_H */
81018diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
81019index 0efc3e6..fd23610 100644
81020--- a/include/linux/fs_struct.h
81021+++ b/include/linux/fs_struct.h
81022@@ -6,13 +6,13 @@
81023 #include <linux/seqlock.h>
81024
81025 struct fs_struct {
81026- int users;
81027+ atomic_t users;
81028 spinlock_t lock;
81029 seqcount_t seq;
81030 int umask;
81031 int in_exec;
81032 struct path root, pwd;
81033-};
81034+} __randomize_layout;
81035
81036 extern struct kmem_cache *fs_cachep;
81037
81038diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
81039index 7714849..a4a5c7a 100644
81040--- a/include/linux/fscache-cache.h
81041+++ b/include/linux/fscache-cache.h
81042@@ -113,7 +113,7 @@ struct fscache_operation {
81043 fscache_operation_release_t release;
81044 };
81045
81046-extern atomic_t fscache_op_debug_id;
81047+extern atomic_unchecked_t fscache_op_debug_id;
81048 extern void fscache_op_work_func(struct work_struct *work);
81049
81050 extern void fscache_enqueue_operation(struct fscache_operation *);
81051@@ -135,7 +135,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
81052 INIT_WORK(&op->work, fscache_op_work_func);
81053 atomic_set(&op->usage, 1);
81054 op->state = FSCACHE_OP_ST_INITIALISED;
81055- op->debug_id = atomic_inc_return(&fscache_op_debug_id);
81056+ op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
81057 op->processor = processor;
81058 op->release = release;
81059 INIT_LIST_HEAD(&op->pend_link);
81060diff --git a/include/linux/fscache.h b/include/linux/fscache.h
81061index 115bb81..e7b812b 100644
81062--- a/include/linux/fscache.h
81063+++ b/include/linux/fscache.h
81064@@ -152,7 +152,7 @@ struct fscache_cookie_def {
81065 * - this is mandatory for any object that may have data
81066 */
81067 void (*now_uncached)(void *cookie_netfs_data);
81068-};
81069+} __do_const;
81070
81071 /*
81072 * fscache cached network filesystem type
81073diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
81074index 1c804b0..1432c2b 100644
81075--- a/include/linux/fsnotify.h
81076+++ b/include/linux/fsnotify.h
81077@@ -195,6 +195,9 @@ static inline void fsnotify_access(struct file *file)
81078 struct inode *inode = file_inode(file);
81079 __u32 mask = FS_ACCESS;
81080
81081+ if (is_sidechannel_device(inode))
81082+ return;
81083+
81084 if (S_ISDIR(inode->i_mode))
81085 mask |= FS_ISDIR;
81086
81087@@ -213,6 +216,9 @@ static inline void fsnotify_modify(struct file *file)
81088 struct inode *inode = file_inode(file);
81089 __u32 mask = FS_MODIFY;
81090
81091+ if (is_sidechannel_device(inode))
81092+ return;
81093+
81094 if (S_ISDIR(inode->i_mode))
81095 mask |= FS_ISDIR;
81096
81097@@ -315,7 +321,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
81098 */
81099 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
81100 {
81101- return kstrdup(name, GFP_KERNEL);
81102+ return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
81103 }
81104
81105 /*
81106diff --git a/include/linux/genhd.h b/include/linux/genhd.h
81107index ec274e0..e678159 100644
81108--- a/include/linux/genhd.h
81109+++ b/include/linux/genhd.h
81110@@ -194,7 +194,7 @@ struct gendisk {
81111 struct kobject *slave_dir;
81112
81113 struct timer_rand_state *random;
81114- atomic_t sync_io; /* RAID */
81115+ atomic_unchecked_t sync_io; /* RAID */
81116 struct disk_events *ev;
81117 #ifdef CONFIG_BLK_DEV_INTEGRITY
81118 struct blk_integrity *integrity;
81119@@ -435,7 +435,7 @@ extern void disk_flush_events(struct gendisk *disk, unsigned int mask);
81120 extern unsigned int disk_clear_events(struct gendisk *disk, unsigned int mask);
81121
81122 /* drivers/char/random.c */
81123-extern void add_disk_randomness(struct gendisk *disk);
81124+extern void add_disk_randomness(struct gendisk *disk) __latent_entropy;
81125 extern void rand_initialize_disk(struct gendisk *disk);
81126
81127 static inline sector_t get_start_sect(struct block_device *bdev)
81128diff --git a/include/linux/genl_magic_func.h b/include/linux/genl_magic_func.h
81129index 667c311..abac2a7 100644
81130--- a/include/linux/genl_magic_func.h
81131+++ b/include/linux/genl_magic_func.h
81132@@ -246,7 +246,7 @@ const char *CONCAT_(GENL_MAGIC_FAMILY, _genl_cmd_to_str)(__u8 cmd)
81133 },
81134
81135 #define ZZZ_genl_ops CONCAT_(GENL_MAGIC_FAMILY, _genl_ops)
81136-static struct genl_ops ZZZ_genl_ops[] __read_mostly = {
81137+static struct genl_ops ZZZ_genl_ops[] = {
81138 #include GENL_MAGIC_INCLUDE_FILE
81139 };
81140
81141diff --git a/include/linux/gfp.h b/include/linux/gfp.h
81142index 41b30fd..a3718cf 100644
81143--- a/include/linux/gfp.h
81144+++ b/include/linux/gfp.h
81145@@ -34,6 +34,13 @@ struct vm_area_struct;
81146 #define ___GFP_NO_KSWAPD 0x400000u
81147 #define ___GFP_OTHER_NODE 0x800000u
81148 #define ___GFP_WRITE 0x1000000u
81149+
81150+#ifdef CONFIG_PAX_USERCOPY_SLABS
81151+#define ___GFP_USERCOPY 0x2000000u
81152+#else
81153+#define ___GFP_USERCOPY 0
81154+#endif
81155+
81156 /* If the above are modified, __GFP_BITS_SHIFT may need updating */
81157
81158 /*
81159@@ -90,6 +97,7 @@ struct vm_area_struct;
81160 #define __GFP_NO_KSWAPD ((__force gfp_t)___GFP_NO_KSWAPD)
81161 #define __GFP_OTHER_NODE ((__force gfp_t)___GFP_OTHER_NODE) /* On behalf of other node */
81162 #define __GFP_WRITE ((__force gfp_t)___GFP_WRITE) /* Allocator intends to dirty page */
81163+#define __GFP_USERCOPY ((__force gfp_t)___GFP_USERCOPY)/* Allocator intends to copy page to/from userland */
81164
81165 /*
81166 * This may seem redundant, but it's a way of annotating false positives vs.
81167@@ -97,7 +105,7 @@ struct vm_area_struct;
81168 */
81169 #define __GFP_NOTRACK_FALSE_POSITIVE (__GFP_NOTRACK)
81170
81171-#define __GFP_BITS_SHIFT 25 /* Room for N __GFP_FOO bits */
81172+#define __GFP_BITS_SHIFT 26 /* Room for N __GFP_FOO bits */
81173 #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))
81174
81175 /* This equals 0, but use constants in case they ever change */
81176@@ -155,6 +163,8 @@ struct vm_area_struct;
81177 /* 4GB DMA on some platforms */
81178 #define GFP_DMA32 __GFP_DMA32
81179
81180+#define GFP_USERCOPY __GFP_USERCOPY
81181+
81182 /* Convert GFP flags to their corresponding migrate type */
81183 static inline int gfpflags_to_migratetype(const gfp_t gfp_flags)
81184 {
81185diff --git a/include/linux/gracl.h b/include/linux/gracl.h
81186new file mode 100644
81187index 0000000..edb2cb6
81188--- /dev/null
81189+++ b/include/linux/gracl.h
81190@@ -0,0 +1,340 @@
81191+#ifndef GR_ACL_H
81192+#define GR_ACL_H
81193+
81194+#include <linux/grdefs.h>
81195+#include <linux/resource.h>
81196+#include <linux/capability.h>
81197+#include <linux/dcache.h>
81198+#include <asm/resource.h>
81199+
81200+/* Major status information */
81201+
81202+#define GR_VERSION "grsecurity 3.0"
81203+#define GRSECURITY_VERSION 0x3000
81204+
81205+enum {
81206+ GR_SHUTDOWN = 0,
81207+ GR_ENABLE = 1,
81208+ GR_SPROLE = 2,
81209+ GR_OLDRELOAD = 3,
81210+ GR_SEGVMOD = 4,
81211+ GR_STATUS = 5,
81212+ GR_UNSPROLE = 6,
81213+ GR_PASSSET = 7,
81214+ GR_SPROLEPAM = 8,
81215+ GR_RELOAD = 9,
81216+};
81217+
81218+/* Password setup definitions
81219+ * kernel/grhash.c */
81220+enum {
81221+ GR_PW_LEN = 128,
81222+ GR_SALT_LEN = 16,
81223+ GR_SHA_LEN = 32,
81224+};
81225+
81226+enum {
81227+ GR_SPROLE_LEN = 64,
81228+};
81229+
81230+enum {
81231+ GR_NO_GLOB = 0,
81232+ GR_REG_GLOB,
81233+ GR_CREATE_GLOB
81234+};
81235+
81236+#define GR_NLIMITS 32
81237+
81238+/* Begin Data Structures */
81239+
81240+struct sprole_pw {
81241+ unsigned char *rolename;
81242+ unsigned char salt[GR_SALT_LEN];
81243+ unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
81244+};
81245+
81246+struct name_entry {
81247+ __u32 key;
81248+ ino_t inode;
81249+ dev_t device;
81250+ char *name;
81251+ __u16 len;
81252+ __u8 deleted;
81253+ struct name_entry *prev;
81254+ struct name_entry *next;
81255+};
81256+
81257+struct inodev_entry {
81258+ struct name_entry *nentry;
81259+ struct inodev_entry *prev;
81260+ struct inodev_entry *next;
81261+};
81262+
81263+struct acl_role_db {
81264+ struct acl_role_label **r_hash;
81265+ __u32 r_size;
81266+};
81267+
81268+struct inodev_db {
81269+ struct inodev_entry **i_hash;
81270+ __u32 i_size;
81271+};
81272+
81273+struct name_db {
81274+ struct name_entry **n_hash;
81275+ __u32 n_size;
81276+};
81277+
81278+struct crash_uid {
81279+ uid_t uid;
81280+ unsigned long expires;
81281+};
81282+
81283+struct gr_hash_struct {
81284+ void **table;
81285+ void **nametable;
81286+ void *first;
81287+ __u32 table_size;
81288+ __u32 used_size;
81289+ int type;
81290+};
81291+
81292+/* Userspace Grsecurity ACL data structures */
81293+
81294+struct acl_subject_label {
81295+ char *filename;
81296+ ino_t inode;
81297+ dev_t device;
81298+ __u32 mode;
81299+ kernel_cap_t cap_mask;
81300+ kernel_cap_t cap_lower;
81301+ kernel_cap_t cap_invert_audit;
81302+
81303+ struct rlimit res[GR_NLIMITS];
81304+ __u32 resmask;
81305+
81306+ __u8 user_trans_type;
81307+ __u8 group_trans_type;
81308+ uid_t *user_transitions;
81309+ gid_t *group_transitions;
81310+ __u16 user_trans_num;
81311+ __u16 group_trans_num;
81312+
81313+ __u32 sock_families[2];
81314+ __u32 ip_proto[8];
81315+ __u32 ip_type;
81316+ struct acl_ip_label **ips;
81317+ __u32 ip_num;
81318+ __u32 inaddr_any_override;
81319+
81320+ __u32 crashes;
81321+ unsigned long expires;
81322+
81323+ struct acl_subject_label *parent_subject;
81324+ struct gr_hash_struct *hash;
81325+ struct acl_subject_label *prev;
81326+ struct acl_subject_label *next;
81327+
81328+ struct acl_object_label **obj_hash;
81329+ __u32 obj_hash_size;
81330+ __u16 pax_flags;
81331+};
81332+
81333+struct role_allowed_ip {
81334+ __u32 addr;
81335+ __u32 netmask;
81336+
81337+ struct role_allowed_ip *prev;
81338+ struct role_allowed_ip *next;
81339+};
81340+
81341+struct role_transition {
81342+ char *rolename;
81343+
81344+ struct role_transition *prev;
81345+ struct role_transition *next;
81346+};
81347+
81348+struct acl_role_label {
81349+ char *rolename;
81350+ uid_t uidgid;
81351+ __u16 roletype;
81352+
81353+ __u16 auth_attempts;
81354+ unsigned long expires;
81355+
81356+ struct acl_subject_label *root_label;
81357+ struct gr_hash_struct *hash;
81358+
81359+ struct acl_role_label *prev;
81360+ struct acl_role_label *next;
81361+
81362+ struct role_transition *transitions;
81363+ struct role_allowed_ip *allowed_ips;
81364+ uid_t *domain_children;
81365+ __u16 domain_child_num;
81366+
81367+ umode_t umask;
81368+
81369+ struct acl_subject_label **subj_hash;
81370+ __u32 subj_hash_size;
81371+};
81372+
81373+struct user_acl_role_db {
81374+ struct acl_role_label **r_table;
81375+ __u32 num_pointers; /* Number of allocations to track */
81376+ __u32 num_roles; /* Number of roles */
81377+ __u32 num_domain_children; /* Number of domain children */
81378+ __u32 num_subjects; /* Number of subjects */
81379+ __u32 num_objects; /* Number of objects */
81380+};
81381+
81382+struct acl_object_label {
81383+ char *filename;
81384+ ino_t inode;
81385+ dev_t device;
81386+ __u32 mode;
81387+
81388+ struct acl_subject_label *nested;
81389+ struct acl_object_label *globbed;
81390+
81391+ /* next two structures not used */
81392+
81393+ struct acl_object_label *prev;
81394+ struct acl_object_label *next;
81395+};
81396+
81397+struct acl_ip_label {
81398+ char *iface;
81399+ __u32 addr;
81400+ __u32 netmask;
81401+ __u16 low, high;
81402+ __u8 mode;
81403+ __u32 type;
81404+ __u32 proto[8];
81405+
81406+ /* next two structures not used */
81407+
81408+ struct acl_ip_label *prev;
81409+ struct acl_ip_label *next;
81410+};
81411+
81412+struct gr_arg {
81413+ struct user_acl_role_db role_db;
81414+ unsigned char pw[GR_PW_LEN];
81415+ unsigned char salt[GR_SALT_LEN];
81416+ unsigned char sum[GR_SHA_LEN];
81417+ unsigned char sp_role[GR_SPROLE_LEN];
81418+ struct sprole_pw *sprole_pws;
81419+ dev_t segv_device;
81420+ ino_t segv_inode;
81421+ uid_t segv_uid;
81422+ __u16 num_sprole_pws;
81423+ __u16 mode;
81424+};
81425+
81426+struct gr_arg_wrapper {
81427+ struct gr_arg *arg;
81428+ __u32 version;
81429+ __u32 size;
81430+};
81431+
81432+struct subject_map {
81433+ struct acl_subject_label *user;
81434+ struct acl_subject_label *kernel;
81435+ struct subject_map *prev;
81436+ struct subject_map *next;
81437+};
81438+
81439+struct acl_subj_map_db {
81440+ struct subject_map **s_hash;
81441+ __u32 s_size;
81442+};
81443+
81444+struct gr_policy_state {
81445+ struct sprole_pw **acl_special_roles;
81446+ __u16 num_sprole_pws;
81447+ struct acl_role_label *kernel_role;
81448+ struct acl_role_label *role_list;
81449+ struct acl_role_label *default_role;
81450+ struct acl_role_db acl_role_set;
81451+ struct acl_subj_map_db subj_map_set;
81452+ struct name_db name_set;
81453+ struct inodev_db inodev_set;
81454+};
81455+
81456+struct gr_alloc_state {
81457+ unsigned long alloc_stack_next;
81458+ unsigned long alloc_stack_size;
81459+ void **alloc_stack;
81460+};
81461+
81462+struct gr_reload_state {
81463+ struct gr_policy_state oldpolicy;
81464+ struct gr_alloc_state oldalloc;
81465+ struct gr_policy_state newpolicy;
81466+ struct gr_alloc_state newalloc;
81467+ struct gr_policy_state *oldpolicy_ptr;
81468+ struct gr_alloc_state *oldalloc_ptr;
81469+ unsigned char oldmode;
81470+};
81471+
81472+/* End Data Structures Section */
81473+
81474+/* Hash functions generated by empirical testing by Brad Spengler
81475+ Makes good use of the low bits of the inode. Generally 0-1 times
81476+ in loop for successful match. 0-3 for unsuccessful match.
81477+ Shift/add algorithm with modulus of table size and an XOR*/
81478+
81479+static __inline__ unsigned int
81480+gr_rhash(const uid_t uid, const __u16 type, const unsigned int sz)
81481+{
81482+ return ((((uid + type) << (16 + type)) ^ uid) % sz);
81483+}
81484+
81485+ static __inline__ unsigned int
81486+gr_shash(const struct acl_subject_label *userp, const unsigned int sz)
81487+{
81488+ return ((const unsigned long)userp % sz);
81489+}
81490+
81491+static __inline__ unsigned int
81492+gr_fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
81493+{
81494+ return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
81495+}
81496+
81497+static __inline__ unsigned int
81498+gr_nhash(const char *name, const __u16 len, const unsigned int sz)
81499+{
81500+ return full_name_hash((const unsigned char *)name, len) % sz;
81501+}
81502+
81503+#define FOR_EACH_SUBJECT_START(role,subj,iter) \
81504+ subj = NULL; \
81505+ iter = 0; \
81506+ while (iter < role->subj_hash_size) { \
81507+ if (subj == NULL) \
81508+ subj = role->subj_hash[iter]; \
81509+ if (subj == NULL) { \
81510+ iter++; \
81511+ continue; \
81512+ }
81513+
81514+#define FOR_EACH_SUBJECT_END(subj,iter) \
81515+ subj = subj->next; \
81516+ if (subj == NULL) \
81517+ iter++; \
81518+ }
81519+
81520+
81521+#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
81522+ subj = role->hash->first; \
81523+ while (subj != NULL) {
81524+
81525+#define FOR_EACH_NESTED_SUBJECT_END(subj) \
81526+ subj = subj->next; \
81527+ }
81528+
81529+#endif
81530+
81531diff --git a/include/linux/gracl_compat.h b/include/linux/gracl_compat.h
81532new file mode 100644
81533index 0000000..33ebd1f
81534--- /dev/null
81535+++ b/include/linux/gracl_compat.h
81536@@ -0,0 +1,156 @@
81537+#ifndef GR_ACL_COMPAT_H
81538+#define GR_ACL_COMPAT_H
81539+
81540+#include <linux/resource.h>
81541+#include <asm/resource.h>
81542+
81543+struct sprole_pw_compat {
81544+ compat_uptr_t rolename;
81545+ unsigned char salt[GR_SALT_LEN];
81546+ unsigned char sum[GR_SHA_LEN];
81547+};
81548+
81549+struct gr_hash_struct_compat {
81550+ compat_uptr_t table;
81551+ compat_uptr_t nametable;
81552+ compat_uptr_t first;
81553+ __u32 table_size;
81554+ __u32 used_size;
81555+ int type;
81556+};
81557+
81558+struct acl_subject_label_compat {
81559+ compat_uptr_t filename;
81560+ compat_ino_t inode;
81561+ __u32 device;
81562+ __u32 mode;
81563+ kernel_cap_t cap_mask;
81564+ kernel_cap_t cap_lower;
81565+ kernel_cap_t cap_invert_audit;
81566+
81567+ struct compat_rlimit res[GR_NLIMITS];
81568+ __u32 resmask;
81569+
81570+ __u8 user_trans_type;
81571+ __u8 group_trans_type;
81572+ compat_uptr_t user_transitions;
81573+ compat_uptr_t group_transitions;
81574+ __u16 user_trans_num;
81575+ __u16 group_trans_num;
81576+
81577+ __u32 sock_families[2];
81578+ __u32 ip_proto[8];
81579+ __u32 ip_type;
81580+ compat_uptr_t ips;
81581+ __u32 ip_num;
81582+ __u32 inaddr_any_override;
81583+
81584+ __u32 crashes;
81585+ compat_ulong_t expires;
81586+
81587+ compat_uptr_t parent_subject;
81588+ compat_uptr_t hash;
81589+ compat_uptr_t prev;
81590+ compat_uptr_t next;
81591+
81592+ compat_uptr_t obj_hash;
81593+ __u32 obj_hash_size;
81594+ __u16 pax_flags;
81595+};
81596+
81597+struct role_allowed_ip_compat {
81598+ __u32 addr;
81599+ __u32 netmask;
81600+
81601+ compat_uptr_t prev;
81602+ compat_uptr_t next;
81603+};
81604+
81605+struct role_transition_compat {
81606+ compat_uptr_t rolename;
81607+
81608+ compat_uptr_t prev;
81609+ compat_uptr_t next;
81610+};
81611+
81612+struct acl_role_label_compat {
81613+ compat_uptr_t rolename;
81614+ uid_t uidgid;
81615+ __u16 roletype;
81616+
81617+ __u16 auth_attempts;
81618+ compat_ulong_t expires;
81619+
81620+ compat_uptr_t root_label;
81621+ compat_uptr_t hash;
81622+
81623+ compat_uptr_t prev;
81624+ compat_uptr_t next;
81625+
81626+ compat_uptr_t transitions;
81627+ compat_uptr_t allowed_ips;
81628+ compat_uptr_t domain_children;
81629+ __u16 domain_child_num;
81630+
81631+ umode_t umask;
81632+
81633+ compat_uptr_t subj_hash;
81634+ __u32 subj_hash_size;
81635+};
81636+
81637+struct user_acl_role_db_compat {
81638+ compat_uptr_t r_table;
81639+ __u32 num_pointers;
81640+ __u32 num_roles;
81641+ __u32 num_domain_children;
81642+ __u32 num_subjects;
81643+ __u32 num_objects;
81644+};
81645+
81646+struct acl_object_label_compat {
81647+ compat_uptr_t filename;
81648+ compat_ino_t inode;
81649+ __u32 device;
81650+ __u32 mode;
81651+
81652+ compat_uptr_t nested;
81653+ compat_uptr_t globbed;
81654+
81655+ compat_uptr_t prev;
81656+ compat_uptr_t next;
81657+};
81658+
81659+struct acl_ip_label_compat {
81660+ compat_uptr_t iface;
81661+ __u32 addr;
81662+ __u32 netmask;
81663+ __u16 low, high;
81664+ __u8 mode;
81665+ __u32 type;
81666+ __u32 proto[8];
81667+
81668+ compat_uptr_t prev;
81669+ compat_uptr_t next;
81670+};
81671+
81672+struct gr_arg_compat {
81673+ struct user_acl_role_db_compat role_db;
81674+ unsigned char pw[GR_PW_LEN];
81675+ unsigned char salt[GR_SALT_LEN];
81676+ unsigned char sum[GR_SHA_LEN];
81677+ unsigned char sp_role[GR_SPROLE_LEN];
81678+ compat_uptr_t sprole_pws;
81679+ __u32 segv_device;
81680+ compat_ino_t segv_inode;
81681+ uid_t segv_uid;
81682+ __u16 num_sprole_pws;
81683+ __u16 mode;
81684+};
81685+
81686+struct gr_arg_wrapper_compat {
81687+ compat_uptr_t arg;
81688+ __u32 version;
81689+ __u32 size;
81690+};
81691+
81692+#endif
81693diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
81694new file mode 100644
81695index 0000000..323ecf2
81696--- /dev/null
81697+++ b/include/linux/gralloc.h
81698@@ -0,0 +1,9 @@
81699+#ifndef __GRALLOC_H
81700+#define __GRALLOC_H
81701+
81702+void acl_free_all(void);
81703+int acl_alloc_stack_init(unsigned long size);
81704+void *acl_alloc(unsigned long len);
81705+void *acl_alloc_num(unsigned long num, unsigned long len);
81706+
81707+#endif
81708diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
81709new file mode 100644
81710index 0000000..be66033
81711--- /dev/null
81712+++ b/include/linux/grdefs.h
81713@@ -0,0 +1,140 @@
81714+#ifndef GRDEFS_H
81715+#define GRDEFS_H
81716+
81717+/* Begin grsecurity status declarations */
81718+
81719+enum {
81720+ GR_READY = 0x01,
81721+ GR_STATUS_INIT = 0x00 // disabled state
81722+};
81723+
81724+/* Begin ACL declarations */
81725+
81726+/* Role flags */
81727+
81728+enum {
81729+ GR_ROLE_USER = 0x0001,
81730+ GR_ROLE_GROUP = 0x0002,
81731+ GR_ROLE_DEFAULT = 0x0004,
81732+ GR_ROLE_SPECIAL = 0x0008,
81733+ GR_ROLE_AUTH = 0x0010,
81734+ GR_ROLE_NOPW = 0x0020,
81735+ GR_ROLE_GOD = 0x0040,
81736+ GR_ROLE_LEARN = 0x0080,
81737+ GR_ROLE_TPE = 0x0100,
81738+ GR_ROLE_DOMAIN = 0x0200,
81739+ GR_ROLE_PAM = 0x0400,
81740+ GR_ROLE_PERSIST = 0x0800
81741+};
81742+
81743+/* ACL Subject and Object mode flags */
81744+enum {
81745+ GR_DELETED = 0x80000000
81746+};
81747+
81748+/* ACL Object-only mode flags */
81749+enum {
81750+ GR_READ = 0x00000001,
81751+ GR_APPEND = 0x00000002,
81752+ GR_WRITE = 0x00000004,
81753+ GR_EXEC = 0x00000008,
81754+ GR_FIND = 0x00000010,
81755+ GR_INHERIT = 0x00000020,
81756+ GR_SETID = 0x00000040,
81757+ GR_CREATE = 0x00000080,
81758+ GR_DELETE = 0x00000100,
81759+ GR_LINK = 0x00000200,
81760+ GR_AUDIT_READ = 0x00000400,
81761+ GR_AUDIT_APPEND = 0x00000800,
81762+ GR_AUDIT_WRITE = 0x00001000,
81763+ GR_AUDIT_EXEC = 0x00002000,
81764+ GR_AUDIT_FIND = 0x00004000,
81765+ GR_AUDIT_INHERIT= 0x00008000,
81766+ GR_AUDIT_SETID = 0x00010000,
81767+ GR_AUDIT_CREATE = 0x00020000,
81768+ GR_AUDIT_DELETE = 0x00040000,
81769+ GR_AUDIT_LINK = 0x00080000,
81770+ GR_PTRACERD = 0x00100000,
81771+ GR_NOPTRACE = 0x00200000,
81772+ GR_SUPPRESS = 0x00400000,
81773+ GR_NOLEARN = 0x00800000,
81774+ GR_INIT_TRANSFER= 0x01000000
81775+};
81776+
81777+#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
81778+ GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
81779+ GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
81780+
81781+/* ACL subject-only mode flags */
81782+enum {
81783+ GR_KILL = 0x00000001,
81784+ GR_VIEW = 0x00000002,
81785+ GR_PROTECTED = 0x00000004,
81786+ GR_LEARN = 0x00000008,
81787+ GR_OVERRIDE = 0x00000010,
81788+ /* just a placeholder, this mode is only used in userspace */
81789+ GR_DUMMY = 0x00000020,
81790+ GR_PROTSHM = 0x00000040,
81791+ GR_KILLPROC = 0x00000080,
81792+ GR_KILLIPPROC = 0x00000100,
81793+ /* just a placeholder, this mode is only used in userspace */
81794+ GR_NOTROJAN = 0x00000200,
81795+ GR_PROTPROCFD = 0x00000400,
81796+ GR_PROCACCT = 0x00000800,
81797+ GR_RELAXPTRACE = 0x00001000,
81798+ //GR_NESTED = 0x00002000,
81799+ GR_INHERITLEARN = 0x00004000,
81800+ GR_PROCFIND = 0x00008000,
81801+ GR_POVERRIDE = 0x00010000,
81802+ GR_KERNELAUTH = 0x00020000,
81803+ GR_ATSECURE = 0x00040000,
81804+ GR_SHMEXEC = 0x00080000
81805+};
81806+
81807+enum {
81808+ GR_PAX_ENABLE_SEGMEXEC = 0x0001,
81809+ GR_PAX_ENABLE_PAGEEXEC = 0x0002,
81810+ GR_PAX_ENABLE_MPROTECT = 0x0004,
81811+ GR_PAX_ENABLE_RANDMMAP = 0x0008,
81812+ GR_PAX_ENABLE_EMUTRAMP = 0x0010,
81813+ GR_PAX_DISABLE_SEGMEXEC = 0x0100,
81814+ GR_PAX_DISABLE_PAGEEXEC = 0x0200,
81815+ GR_PAX_DISABLE_MPROTECT = 0x0400,
81816+ GR_PAX_DISABLE_RANDMMAP = 0x0800,
81817+ GR_PAX_DISABLE_EMUTRAMP = 0x1000,
81818+};
81819+
81820+enum {
81821+ GR_ID_USER = 0x01,
81822+ GR_ID_GROUP = 0x02,
81823+};
81824+
81825+enum {
81826+ GR_ID_ALLOW = 0x01,
81827+ GR_ID_DENY = 0x02,
81828+};
81829+
81830+#define GR_CRASH_RES 31
81831+#define GR_UIDTABLE_MAX 500
81832+
81833+/* begin resource learning section */
81834+enum {
81835+ GR_RLIM_CPU_BUMP = 60,
81836+ GR_RLIM_FSIZE_BUMP = 50000,
81837+ GR_RLIM_DATA_BUMP = 10000,
81838+ GR_RLIM_STACK_BUMP = 1000,
81839+ GR_RLIM_CORE_BUMP = 10000,
81840+ GR_RLIM_RSS_BUMP = 500000,
81841+ GR_RLIM_NPROC_BUMP = 1,
81842+ GR_RLIM_NOFILE_BUMP = 5,
81843+ GR_RLIM_MEMLOCK_BUMP = 50000,
81844+ GR_RLIM_AS_BUMP = 500000,
81845+ GR_RLIM_LOCKS_BUMP = 2,
81846+ GR_RLIM_SIGPENDING_BUMP = 5,
81847+ GR_RLIM_MSGQUEUE_BUMP = 10000,
81848+ GR_RLIM_NICE_BUMP = 1,
81849+ GR_RLIM_RTPRIO_BUMP = 1,
81850+ GR_RLIM_RTTIME_BUMP = 1000000
81851+};
81852+
81853+#endif
81854diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
81855new file mode 100644
81856index 0000000..d25522e
81857--- /dev/null
81858+++ b/include/linux/grinternal.h
81859@@ -0,0 +1,229 @@
81860+#ifndef __GRINTERNAL_H
81861+#define __GRINTERNAL_H
81862+
81863+#ifdef CONFIG_GRKERNSEC
81864+
81865+#include <linux/fs.h>
81866+#include <linux/mnt_namespace.h>
81867+#include <linux/nsproxy.h>
81868+#include <linux/gracl.h>
81869+#include <linux/grdefs.h>
81870+#include <linux/grmsg.h>
81871+
81872+void gr_add_learn_entry(const char *fmt, ...)
81873+ __attribute__ ((format (printf, 1, 2)));
81874+__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
81875+ const struct vfsmount *mnt);
81876+__u32 gr_check_create(const struct dentry *new_dentry,
81877+ const struct dentry *parent,
81878+ const struct vfsmount *mnt, const __u32 mode);
81879+int gr_check_protected_task(const struct task_struct *task);
81880+__u32 to_gr_audit(const __u32 reqmode);
81881+int gr_set_acls(const int type);
81882+int gr_acl_is_enabled(void);
81883+char gr_roletype_to_char(void);
81884+
81885+void gr_handle_alertkill(struct task_struct *task);
81886+char *gr_to_filename(const struct dentry *dentry,
81887+ const struct vfsmount *mnt);
81888+char *gr_to_filename1(const struct dentry *dentry,
81889+ const struct vfsmount *mnt);
81890+char *gr_to_filename2(const struct dentry *dentry,
81891+ const struct vfsmount *mnt);
81892+char *gr_to_filename3(const struct dentry *dentry,
81893+ const struct vfsmount *mnt);
81894+
81895+extern int grsec_enable_ptrace_readexec;
81896+extern int grsec_enable_harden_ptrace;
81897+extern int grsec_enable_link;
81898+extern int grsec_enable_fifo;
81899+extern int grsec_enable_execve;
81900+extern int grsec_enable_shm;
81901+extern int grsec_enable_execlog;
81902+extern int grsec_enable_signal;
81903+extern int grsec_enable_audit_ptrace;
81904+extern int grsec_enable_forkfail;
81905+extern int grsec_enable_time;
81906+extern int grsec_enable_rofs;
81907+extern int grsec_deny_new_usb;
81908+extern int grsec_enable_chroot_shmat;
81909+extern int grsec_enable_chroot_mount;
81910+extern int grsec_enable_chroot_double;
81911+extern int grsec_enable_chroot_pivot;
81912+extern int grsec_enable_chroot_chdir;
81913+extern int grsec_enable_chroot_chmod;
81914+extern int grsec_enable_chroot_mknod;
81915+extern int grsec_enable_chroot_fchdir;
81916+extern int grsec_enable_chroot_nice;
81917+extern int grsec_enable_chroot_execlog;
81918+extern int grsec_enable_chroot_caps;
81919+extern int grsec_enable_chroot_sysctl;
81920+extern int grsec_enable_chroot_unix;
81921+extern int grsec_enable_symlinkown;
81922+extern kgid_t grsec_symlinkown_gid;
81923+extern int grsec_enable_tpe;
81924+extern kgid_t grsec_tpe_gid;
81925+extern int grsec_enable_tpe_all;
81926+extern int grsec_enable_tpe_invert;
81927+extern int grsec_enable_socket_all;
81928+extern kgid_t grsec_socket_all_gid;
81929+extern int grsec_enable_socket_client;
81930+extern kgid_t grsec_socket_client_gid;
81931+extern int grsec_enable_socket_server;
81932+extern kgid_t grsec_socket_server_gid;
81933+extern kgid_t grsec_audit_gid;
81934+extern int grsec_enable_group;
81935+extern int grsec_enable_log_rwxmaps;
81936+extern int grsec_enable_mount;
81937+extern int grsec_enable_chdir;
81938+extern int grsec_resource_logging;
81939+extern int grsec_enable_blackhole;
81940+extern int grsec_lastack_retries;
81941+extern int grsec_enable_brute;
81942+extern int grsec_enable_harden_ipc;
81943+extern int grsec_lock;
81944+
81945+extern spinlock_t grsec_alert_lock;
81946+extern unsigned long grsec_alert_wtime;
81947+extern unsigned long grsec_alert_fyet;
81948+
81949+extern spinlock_t grsec_audit_lock;
81950+
81951+extern rwlock_t grsec_exec_file_lock;
81952+
81953+#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
81954+ gr_to_filename2((tsk)->exec_file->f_path.dentry, \
81955+ (tsk)->exec_file->f_path.mnt) : "/")
81956+
81957+#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
81958+ gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
81959+ (tsk)->real_parent->exec_file->f_path.mnt) : "/")
81960+
81961+#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
81962+ gr_to_filename((tsk)->exec_file->f_path.dentry, \
81963+ (tsk)->exec_file->f_path.mnt) : "/")
81964+
81965+#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
81966+ gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
81967+ (tsk)->real_parent->exec_file->f_path.mnt) : "/")
81968+
81969+#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
81970+
81971+#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
81972+
81973+static inline bool gr_is_same_file(const struct file *file1, const struct file *file2)
81974+{
81975+ if (file1 && file2) {
81976+ const struct inode *inode1 = file1->f_path.dentry->d_inode;
81977+ const struct inode *inode2 = file2->f_path.dentry->d_inode;
81978+ if (inode1->i_ino == inode2->i_ino && inode1->i_sb->s_dev == inode2->i_sb->s_dev)
81979+ return true;
81980+ }
81981+
81982+ return false;
81983+}
81984+
81985+#define GR_CHROOT_CAPS {{ \
81986+ CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
81987+ CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
81988+ CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
81989+ CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
81990+ CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
81991+ CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
81992+ CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
81993+
81994+#define security_learn(normal_msg,args...) \
81995+({ \
81996+ read_lock(&grsec_exec_file_lock); \
81997+ gr_add_learn_entry(normal_msg "\n", ## args); \
81998+ read_unlock(&grsec_exec_file_lock); \
81999+})
82000+
82001+enum {
82002+ GR_DO_AUDIT,
82003+ GR_DONT_AUDIT,
82004+ /* used for non-audit messages that we shouldn't kill the task on */
82005+ GR_DONT_AUDIT_GOOD
82006+};
82007+
82008+enum {
82009+ GR_TTYSNIFF,
82010+ GR_RBAC,
82011+ GR_RBAC_STR,
82012+ GR_STR_RBAC,
82013+ GR_RBAC_MODE2,
82014+ GR_RBAC_MODE3,
82015+ GR_FILENAME,
82016+ GR_SYSCTL_HIDDEN,
82017+ GR_NOARGS,
82018+ GR_ONE_INT,
82019+ GR_ONE_INT_TWO_STR,
82020+ GR_ONE_STR,
82021+ GR_STR_INT,
82022+ GR_TWO_STR_INT,
82023+ GR_TWO_INT,
82024+ GR_TWO_U64,
82025+ GR_THREE_INT,
82026+ GR_FIVE_INT_TWO_STR,
82027+ GR_TWO_STR,
82028+ GR_THREE_STR,
82029+ GR_FOUR_STR,
82030+ GR_STR_FILENAME,
82031+ GR_FILENAME_STR,
82032+ GR_FILENAME_TWO_INT,
82033+ GR_FILENAME_TWO_INT_STR,
82034+ GR_TEXTREL,
82035+ GR_PTRACE,
82036+ GR_RESOURCE,
82037+ GR_CAP,
82038+ GR_SIG,
82039+ GR_SIG2,
82040+ GR_CRASH1,
82041+ GR_CRASH2,
82042+ GR_PSACCT,
82043+ GR_RWXMAP,
82044+ GR_RWXMAPVMA
82045+};
82046+
82047+#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
82048+#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
82049+#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
82050+#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
82051+#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
82052+#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
82053+#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)
82054+#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
82055+#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
82056+#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
82057+#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
82058+#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
82059+#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
82060+#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
82061+#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
82062+#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
82063+#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)
82064+#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
82065+#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
82066+#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
82067+#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
82068+#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
82069+#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
82070+#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
82071+#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)
82072+#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
82073+#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
82074+#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
82075+#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
82076+#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
82077+#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
82078+#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
82079+#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
82080+#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)
82081+#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
82082+#define gr_log_rwxmap_vma(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAPVMA, str)
82083+
82084+void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
82085+
82086+#endif
82087+
82088+#endif
82089diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
82090new file mode 100644
82091index 0000000..b02ba9d
82092--- /dev/null
82093+++ b/include/linux/grmsg.h
82094@@ -0,0 +1,117 @@
82095+#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"
82096+#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"
82097+#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
82098+#define GR_STOPMOD_MSG "denied modification of module state by "
82099+#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
82100+#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
82101+#define GR_IOPERM_MSG "denied use of ioperm() by "
82102+#define GR_IOPL_MSG "denied use of iopl() by "
82103+#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
82104+#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
82105+#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
82106+#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
82107+#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
82108+#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"
82109+#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"
82110+#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
82111+#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
82112+#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
82113+#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
82114+#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
82115+#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
82116+#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
82117+#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
82118+#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
82119+#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
82120+#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
82121+#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
82122+#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
82123+#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
82124+#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
82125+#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
82126+#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
82127+#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
82128+#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
82129+#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
82130+#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
82131+#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
82132+#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
82133+#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
82134+#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
82135+#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
82136+#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
82137+#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
82138+#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
82139+#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
82140+#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
82141+#define GR_CHROOT_FHANDLE_MSG "denied use of file handles inside chroot by "
82142+#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
82143+#define GR_SETXATTR_ACL_MSG "%s setting extended attribute of %.950s by "
82144+#define GR_REMOVEXATTR_ACL_MSG "%s removing extended attribute of %.950s by "
82145+#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
82146+#define GR_INITF_ACL_MSG "init_variables() failed %s by "
82147+#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"
82148+#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
82149+#define GR_SHUTS_ACL_MSG "shutdown auth success for "
82150+#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
82151+#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
82152+#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
82153+#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
82154+#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
82155+#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
82156+#define GR_ENABLEF_ACL_MSG "unable to load %s for "
82157+#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
82158+#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
82159+#define GR_RELOADF_ACL_MSG "failed reload of %s for "
82160+#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
82161+#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
82162+#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
82163+#define GR_SPROLEF_ACL_MSG "special role %s failure for "
82164+#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
82165+#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
82166+#define GR_INVMODE_ACL_MSG "invalid mode %d by "
82167+#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
82168+#define GR_FAILFORK_MSG "failed fork with errno %s by "
82169+#define GR_NICE_CHROOT_MSG "denied priority change by "
82170+#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
82171+#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
82172+#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
82173+#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
82174+#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
82175+#define GR_TIME_MSG "time set by "
82176+#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
82177+#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
82178+#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
82179+#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
82180+#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
82181+#define GR_BIND_MSG "denied bind() by "
82182+#define GR_CONNECT_MSG "denied connect() by "
82183+#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
82184+#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
82185+#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"
82186+#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
82187+#define GR_CAP_ACL_MSG "use of %s denied for "
82188+#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
82189+#define GR_CAP_ACL_MSG2 "use of %s permitted for "
82190+#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
82191+#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
82192+#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
82193+#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
82194+#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
82195+#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
82196+#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
82197+#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
82198+#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
82199+#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
82200+#define GR_TEXTREL_AUDIT_MSG "denied text relocation in %.950s, VMA:0x%08lx 0x%08lx by "
82201+#define GR_PTGNUSTACK_MSG "denied marking stack executable as requested by PT_GNU_STACK marking in %.950s by "
82202+#define GR_VM86_MSG "denied use of vm86 by "
82203+#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
82204+#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
82205+#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
82206+#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
82207+#define GR_SYMLINKOWNER_MSG "denied following symlink %.950s since symlink owner %u does not match target owner %u, by "
82208+#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 "
82209+#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 "
82210+#define GR_IPC_DENIED_MSG "denied %s of overly-permissive IPC object with creator uid %u by "
82211+#define GR_MSRWRITE_MSG "denied write to CPU MSR by "
82212diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
82213new file mode 100644
82214index 0000000..c3b0738
82215--- /dev/null
82216+++ b/include/linux/grsecurity.h
82217@@ -0,0 +1,244 @@
82218+#ifndef GR_SECURITY_H
82219+#define GR_SECURITY_H
82220+#include <linux/fs.h>
82221+#include <linux/fs_struct.h>
82222+#include <linux/binfmts.h>
82223+#include <linux/gracl.h>
82224+
82225+/* notify of brain-dead configs */
82226+#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
82227+#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
82228+#endif
82229+#if defined(CONFIG_GRKERNSEC_PROC) && !defined(CONFIG_GRKERNSEC_PROC_USER) && !defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
82230+#error "CONFIG_GRKERNSEC_PROC enabled, but neither CONFIG_GRKERNSEC_PROC_USER nor CONFIG_GRKERNSEC_PROC_USERGROUP enabled"
82231+#endif
82232+#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
82233+#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
82234+#endif
82235+#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
82236+#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
82237+#endif
82238+#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
82239+#error "CONFIG_PAX enabled, but no PaX options are enabled."
82240+#endif
82241+
82242+int gr_handle_new_usb(void);
82243+
82244+void gr_handle_brute_attach(int dumpable);
82245+void gr_handle_brute_check(void);
82246+void gr_handle_kernel_exploit(void);
82247+
82248+char gr_roletype_to_char(void);
82249+
82250+int gr_proc_is_restricted(void);
82251+
82252+int gr_acl_enable_at_secure(void);
82253+
82254+int gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs);
82255+int gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs);
82256+
82257+int gr_learn_cap(const struct task_struct *task, const struct cred *cred, const int cap);
82258+
82259+void gr_del_task_from_ip_table(struct task_struct *p);
82260+
82261+int gr_pid_is_chrooted(struct task_struct *p);
82262+int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
82263+int gr_handle_chroot_nice(void);
82264+int gr_handle_chroot_sysctl(const int op);
82265+int gr_handle_chroot_setpriority(struct task_struct *p,
82266+ const int niceval);
82267+int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
82268+int gr_chroot_fhandle(void);
82269+int gr_handle_chroot_chroot(const struct dentry *dentry,
82270+ const struct vfsmount *mnt);
82271+void gr_handle_chroot_chdir(const struct path *path);
82272+int gr_handle_chroot_chmod(const struct dentry *dentry,
82273+ const struct vfsmount *mnt, const int mode);
82274+int gr_handle_chroot_mknod(const struct dentry *dentry,
82275+ const struct vfsmount *mnt, const int mode);
82276+int gr_handle_chroot_mount(const struct dentry *dentry,
82277+ const struct vfsmount *mnt,
82278+ const char *dev_name);
82279+int gr_handle_chroot_pivot(void);
82280+int gr_handle_chroot_unix(const pid_t pid);
82281+
82282+int gr_handle_rawio(const struct inode *inode);
82283+
82284+void gr_handle_ioperm(void);
82285+void gr_handle_iopl(void);
82286+void gr_handle_msr_write(void);
82287+
82288+umode_t gr_acl_umask(void);
82289+
82290+int gr_tpe_allow(const struct file *file);
82291+
82292+void gr_set_chroot_entries(struct task_struct *task, const struct path *path);
82293+void gr_clear_chroot_entries(struct task_struct *task);
82294+
82295+void gr_log_forkfail(const int retval);
82296+void gr_log_timechange(void);
82297+void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
82298+void gr_log_chdir(const struct dentry *dentry,
82299+ const struct vfsmount *mnt);
82300+void gr_log_chroot_exec(const struct dentry *dentry,
82301+ const struct vfsmount *mnt);
82302+void gr_log_remount(const char *devname, const int retval);
82303+void gr_log_unmount(const char *devname, const int retval);
82304+void gr_log_mount(const char *from, struct path *to, const int retval);
82305+void gr_log_textrel(struct vm_area_struct *vma);
82306+void gr_log_ptgnustack(struct file *file);
82307+void gr_log_rwxmmap(struct file *file);
82308+void gr_log_rwxmprotect(struct vm_area_struct *vma);
82309+
82310+int gr_handle_follow_link(const struct inode *parent,
82311+ const struct inode *inode,
82312+ const struct dentry *dentry,
82313+ const struct vfsmount *mnt);
82314+int gr_handle_fifo(const struct dentry *dentry,
82315+ const struct vfsmount *mnt,
82316+ const struct dentry *dir, const int flag,
82317+ const int acc_mode);
82318+int gr_handle_hardlink(const struct dentry *dentry,
82319+ const struct vfsmount *mnt,
82320+ struct inode *inode,
82321+ const int mode, const struct filename *to);
82322+
82323+int gr_is_capable(const int cap);
82324+int gr_is_capable_nolog(const int cap);
82325+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
82326+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
82327+
82328+void gr_copy_label(struct task_struct *tsk);
82329+void gr_handle_crash(struct task_struct *task, const int sig);
82330+int gr_handle_signal(const struct task_struct *p, const int sig);
82331+int gr_check_crash_uid(const kuid_t uid);
82332+int gr_check_protected_task(const struct task_struct *task);
82333+int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
82334+int gr_acl_handle_mmap(const struct file *file,
82335+ const unsigned long prot);
82336+int gr_acl_handle_mprotect(const struct file *file,
82337+ const unsigned long prot);
82338+int gr_check_hidden_task(const struct task_struct *tsk);
82339+__u32 gr_acl_handle_truncate(const struct dentry *dentry,
82340+ const struct vfsmount *mnt);
82341+__u32 gr_acl_handle_utime(const struct dentry *dentry,
82342+ const struct vfsmount *mnt);
82343+__u32 gr_acl_handle_access(const struct dentry *dentry,
82344+ const struct vfsmount *mnt, const int fmode);
82345+__u32 gr_acl_handle_chmod(const struct dentry *dentry,
82346+ const struct vfsmount *mnt, umode_t *mode);
82347+__u32 gr_acl_handle_chown(const struct dentry *dentry,
82348+ const struct vfsmount *mnt);
82349+__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
82350+ const struct vfsmount *mnt);
82351+__u32 gr_acl_handle_removexattr(const struct dentry *dentry,
82352+ const struct vfsmount *mnt);
82353+int gr_handle_ptrace(struct task_struct *task, const long request);
82354+int gr_handle_proc_ptrace(struct task_struct *task);
82355+__u32 gr_acl_handle_execve(const struct dentry *dentry,
82356+ const struct vfsmount *mnt);
82357+int gr_check_crash_exec(const struct file *filp);
82358+int gr_acl_is_enabled(void);
82359+void gr_set_role_label(struct task_struct *task, const kuid_t uid,
82360+ const kgid_t gid);
82361+int gr_set_proc_label(const struct dentry *dentry,
82362+ const struct vfsmount *mnt,
82363+ const int unsafe_flags);
82364+__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
82365+ const struct vfsmount *mnt);
82366+__u32 gr_acl_handle_open(const struct dentry *dentry,
82367+ const struct vfsmount *mnt, int acc_mode);
82368+__u32 gr_acl_handle_creat(const struct dentry *dentry,
82369+ const struct dentry *p_dentry,
82370+ const struct vfsmount *p_mnt,
82371+ int open_flags, int acc_mode, const int imode);
82372+void gr_handle_create(const struct dentry *dentry,
82373+ const struct vfsmount *mnt);
82374+void gr_handle_proc_create(const struct dentry *dentry,
82375+ const struct inode *inode);
82376+__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
82377+ const struct dentry *parent_dentry,
82378+ const struct vfsmount *parent_mnt,
82379+ const int mode);
82380+__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
82381+ const struct dentry *parent_dentry,
82382+ const struct vfsmount *parent_mnt);
82383+__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
82384+ const struct vfsmount *mnt);
82385+void gr_handle_delete(const ino_t ino, const dev_t dev);
82386+__u32 gr_acl_handle_unlink(const struct dentry *dentry,
82387+ const struct vfsmount *mnt);
82388+__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
82389+ const struct dentry *parent_dentry,
82390+ const struct vfsmount *parent_mnt,
82391+ const struct filename *from);
82392+__u32 gr_acl_handle_link(const struct dentry *new_dentry,
82393+ const struct dentry *parent_dentry,
82394+ const struct vfsmount *parent_mnt,
82395+ const struct dentry *old_dentry,
82396+ const struct vfsmount *old_mnt, const struct filename *to);
82397+int gr_handle_symlink_owner(const struct path *link, const struct inode *target);
82398+int gr_acl_handle_rename(struct dentry *new_dentry,
82399+ struct dentry *parent_dentry,
82400+ const struct vfsmount *parent_mnt,
82401+ struct dentry *old_dentry,
82402+ struct inode *old_parent_inode,
82403+ struct vfsmount *old_mnt, const struct filename *newname, unsigned int flags);
82404+void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
82405+ struct dentry *old_dentry,
82406+ struct dentry *new_dentry,
82407+ struct vfsmount *mnt, const __u8 replace, unsigned int flags);
82408+__u32 gr_check_link(const struct dentry *new_dentry,
82409+ const struct dentry *parent_dentry,
82410+ const struct vfsmount *parent_mnt,
82411+ const struct dentry *old_dentry,
82412+ const struct vfsmount *old_mnt);
82413+int gr_acl_handle_filldir(const struct file *file, const char *name,
82414+ const unsigned int namelen, const ino_t ino);
82415+
82416+__u32 gr_acl_handle_unix(const struct dentry *dentry,
82417+ const struct vfsmount *mnt);
82418+void gr_acl_handle_exit(void);
82419+void gr_acl_handle_psacct(struct task_struct *task, const long code);
82420+int gr_acl_handle_procpidmem(const struct task_struct *task);
82421+int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
82422+int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
82423+void gr_audit_ptrace(struct task_struct *task);
82424+dev_t gr_get_dev_from_dentry(struct dentry *dentry);
82425+void gr_put_exec_file(struct task_struct *task);
82426+
82427+int gr_ptrace_readexec(struct file *file, int unsafe_flags);
82428+
82429+#ifdef CONFIG_GRKERNSEC_RESLOG
82430+extern void gr_log_resource(const struct task_struct *task, const int res,
82431+ const unsigned long wanted, const int gt);
82432+#else
82433+static inline void gr_log_resource(const struct task_struct *task, const int res,
82434+ const unsigned long wanted, const int gt)
82435+{
82436+}
82437+#endif
82438+
82439+#ifdef CONFIG_GRKERNSEC
82440+void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
82441+void gr_handle_vm86(void);
82442+void gr_handle_mem_readwrite(u64 from, u64 to);
82443+
82444+void gr_log_badprocpid(const char *entry);
82445+
82446+extern int grsec_enable_dmesg;
82447+extern int grsec_disable_privio;
82448+
82449+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
82450+extern kgid_t grsec_proc_gid;
82451+#endif
82452+
82453+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
82454+extern int grsec_enable_chroot_findtask;
82455+#endif
82456+#ifdef CONFIG_GRKERNSEC_SETXID
82457+extern int grsec_enable_setxid;
82458+#endif
82459+#endif
82460+
82461+#endif
82462diff --git a/include/linux/grsock.h b/include/linux/grsock.h
82463new file mode 100644
82464index 0000000..e7ffaaf
82465--- /dev/null
82466+++ b/include/linux/grsock.h
82467@@ -0,0 +1,19 @@
82468+#ifndef __GRSOCK_H
82469+#define __GRSOCK_H
82470+
82471+extern void gr_attach_curr_ip(const struct sock *sk);
82472+extern int gr_handle_sock_all(const int family, const int type,
82473+ const int protocol);
82474+extern int gr_handle_sock_server(const struct sockaddr *sck);
82475+extern int gr_handle_sock_server_other(const struct sock *sck);
82476+extern int gr_handle_sock_client(const struct sockaddr *sck);
82477+extern int gr_search_connect(struct socket * sock,
82478+ struct sockaddr_in * addr);
82479+extern int gr_search_bind(struct socket * sock,
82480+ struct sockaddr_in * addr);
82481+extern int gr_search_listen(struct socket * sock);
82482+extern int gr_search_accept(struct socket * sock);
82483+extern int gr_search_socket(const int domain, const int type,
82484+ const int protocol);
82485+
82486+#endif
82487diff --git a/include/linux/hash.h b/include/linux/hash.h
82488index d0494c3..69b7715 100644
82489--- a/include/linux/hash.h
82490+++ b/include/linux/hash.h
82491@@ -87,7 +87,7 @@ static inline u32 hash32_ptr(const void *ptr)
82492 struct fast_hash_ops {
82493 u32 (*hash)(const void *data, u32 len, u32 seed);
82494 u32 (*hash2)(const u32 *data, u32 len, u32 seed);
82495-};
82496+} __no_const;
82497
82498 /**
82499 * arch_fast_hash - Caclulates a hash over a given buffer that can have
82500diff --git a/include/linux/highmem.h b/include/linux/highmem.h
82501index 9286a46..373f27f 100644
82502--- a/include/linux/highmem.h
82503+++ b/include/linux/highmem.h
82504@@ -189,6 +189,18 @@ static inline void clear_highpage(struct page *page)
82505 kunmap_atomic(kaddr);
82506 }
82507
82508+static inline void sanitize_highpage(struct page *page)
82509+{
82510+ void *kaddr;
82511+ unsigned long flags;
82512+
82513+ local_irq_save(flags);
82514+ kaddr = kmap_atomic(page);
82515+ clear_page(kaddr);
82516+ kunmap_atomic(kaddr);
82517+ local_irq_restore(flags);
82518+}
82519+
82520 static inline void zero_user_segments(struct page *page,
82521 unsigned start1, unsigned end1,
82522 unsigned start2, unsigned end2)
82523diff --git a/include/linux/hwmon-sysfs.h b/include/linux/hwmon-sysfs.h
82524index 1c7b89a..7dda400 100644
82525--- a/include/linux/hwmon-sysfs.h
82526+++ b/include/linux/hwmon-sysfs.h
82527@@ -25,7 +25,8 @@
82528 struct sensor_device_attribute{
82529 struct device_attribute dev_attr;
82530 int index;
82531-};
82532+} __do_const;
82533+typedef struct sensor_device_attribute __no_const sensor_device_attribute_no_const;
82534 #define to_sensor_dev_attr(_dev_attr) \
82535 container_of(_dev_attr, struct sensor_device_attribute, dev_attr)
82536
82537@@ -41,7 +42,8 @@ struct sensor_device_attribute_2 {
82538 struct device_attribute dev_attr;
82539 u8 index;
82540 u8 nr;
82541-};
82542+} __do_const;
82543+typedef struct sensor_device_attribute_2 __no_const sensor_device_attribute_2_no_const;
82544 #define to_sensor_dev_attr_2(_dev_attr) \
82545 container_of(_dev_attr, struct sensor_device_attribute_2, dev_attr)
82546
82547diff --git a/include/linux/i2c.h b/include/linux/i2c.h
82548index b556e0a..c10a515 100644
82549--- a/include/linux/i2c.h
82550+++ b/include/linux/i2c.h
82551@@ -378,6 +378,7 @@ struct i2c_algorithm {
82552 /* To determine what the adapter supports */
82553 u32 (*functionality) (struct i2c_adapter *);
82554 };
82555+typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
82556
82557 /**
82558 * struct i2c_bus_recovery_info - I2C bus recovery information
82559diff --git a/include/linux/i2o.h b/include/linux/i2o.h
82560index d23c3c2..eb63c81 100644
82561--- a/include/linux/i2o.h
82562+++ b/include/linux/i2o.h
82563@@ -565,7 +565,7 @@ struct i2o_controller {
82564 struct i2o_device *exec; /* Executive */
82565 #if BITS_PER_LONG == 64
82566 spinlock_t context_list_lock; /* lock for context_list */
82567- atomic_t context_list_counter; /* needed for unique contexts */
82568+ atomic_unchecked_t context_list_counter; /* needed for unique contexts */
82569 struct list_head context_list; /* list of context id's
82570 and pointers */
82571 #endif
82572diff --git a/include/linux/if_pppox.h b/include/linux/if_pppox.h
82573index aff7ad8..3942bbd 100644
82574--- a/include/linux/if_pppox.h
82575+++ b/include/linux/if_pppox.h
82576@@ -76,7 +76,7 @@ struct pppox_proto {
82577 int (*ioctl)(struct socket *sock, unsigned int cmd,
82578 unsigned long arg);
82579 struct module *owner;
82580-};
82581+} __do_const;
82582
82583 extern int register_pppox_proto(int proto_num, const struct pppox_proto *pp);
82584 extern void unregister_pppox_proto(int proto_num);
82585diff --git a/include/linux/init.h b/include/linux/init.h
82586index 2df8e8d..3e1280d 100644
82587--- a/include/linux/init.h
82588+++ b/include/linux/init.h
82589@@ -37,9 +37,17 @@
82590 * section.
82591 */
82592
82593+#define add_init_latent_entropy __latent_entropy
82594+
82595+#ifdef CONFIG_MEMORY_HOTPLUG
82596+#define add_meminit_latent_entropy
82597+#else
82598+#define add_meminit_latent_entropy __latent_entropy
82599+#endif
82600+
82601 /* These are for everybody (although not all archs will actually
82602 discard it in modules) */
82603-#define __init __section(.init.text) __cold notrace
82604+#define __init __section(.init.text) __cold notrace add_init_latent_entropy
82605 #define __initdata __section(.init.data)
82606 #define __initconst __constsection(.init.rodata)
82607 #define __exitdata __section(.exit.data)
82608@@ -100,7 +108,7 @@
82609 #define __cpuexitconst
82610
82611 /* Used for MEMORY_HOTPLUG */
82612-#define __meminit __section(.meminit.text) __cold notrace
82613+#define __meminit __section(.meminit.text) __cold notrace add_meminit_latent_entropy
82614 #define __meminitdata __section(.meminit.data)
82615 #define __meminitconst __constsection(.meminit.rodata)
82616 #define __memexit __section(.memexit.text) __exitused __cold notrace
82617diff --git a/include/linux/init_task.h b/include/linux/init_task.h
82618index 77fc43f..73caf92 100644
82619--- a/include/linux/init_task.h
82620+++ b/include/linux/init_task.h
82621@@ -158,6 +158,12 @@ extern struct task_group root_task_group;
82622
82623 #define INIT_TASK_COMM "swapper"
82624
82625+#ifdef CONFIG_X86
82626+#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
82627+#else
82628+#define INIT_TASK_THREAD_INFO
82629+#endif
82630+
82631 #ifdef CONFIG_RT_MUTEXES
82632 # define INIT_RT_MUTEXES(tsk) \
82633 .pi_waiters = RB_ROOT, \
82634@@ -205,6 +211,7 @@ extern struct task_group root_task_group;
82635 RCU_POINTER_INITIALIZER(cred, &init_cred), \
82636 .comm = INIT_TASK_COMM, \
82637 .thread = INIT_THREAD, \
82638+ INIT_TASK_THREAD_INFO \
82639 .fs = &init_fs, \
82640 .files = &init_files, \
82641 .signal = &init_signals, \
82642diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
82643index 69517a2..6b12d37 100644
82644--- a/include/linux/interrupt.h
82645+++ b/include/linux/interrupt.h
82646@@ -413,8 +413,8 @@ extern const char * const softirq_to_name[NR_SOFTIRQS];
82647
82648 struct softirq_action
82649 {
82650- void (*action)(struct softirq_action *);
82651-};
82652+ void (*action)(void);
82653+} __no_const;
82654
82655 asmlinkage void do_softirq(void);
82656 asmlinkage void __do_softirq(void);
82657@@ -428,7 +428,7 @@ static inline void do_softirq_own_stack(void)
82658 }
82659 #endif
82660
82661-extern void open_softirq(int nr, void (*action)(struct softirq_action *));
82662+extern void open_softirq(int nr, void (*action)(void));
82663 extern void softirq_init(void);
82664 extern void __raise_softirq_irqoff(unsigned int nr);
82665
82666diff --git a/include/linux/iommu.h b/include/linux/iommu.h
82667index e6a7c9f..5804745 100644
82668--- a/include/linux/iommu.h
82669+++ b/include/linux/iommu.h
82670@@ -133,7 +133,7 @@ struct iommu_ops {
82671 u32 (*domain_get_windows)(struct iommu_domain *domain);
82672
82673 unsigned long pgsize_bitmap;
82674-};
82675+} __do_const;
82676
82677 #define IOMMU_GROUP_NOTIFY_ADD_DEVICE 1 /* Device added */
82678 #define IOMMU_GROUP_NOTIFY_DEL_DEVICE 2 /* Pre Device removed */
82679diff --git a/include/linux/ioport.h b/include/linux/ioport.h
82680index 2c525022..345b106 100644
82681--- a/include/linux/ioport.h
82682+++ b/include/linux/ioport.h
82683@@ -161,7 +161,7 @@ struct resource *lookup_resource(struct resource *root, resource_size_t start);
82684 int adjust_resource(struct resource *res, resource_size_t start,
82685 resource_size_t size);
82686 resource_size_t resource_alignment(struct resource *res);
82687-static inline resource_size_t resource_size(const struct resource *res)
82688+static inline resource_size_t __intentional_overflow(-1) resource_size(const struct resource *res)
82689 {
82690 return res->end - res->start + 1;
82691 }
82692diff --git a/include/linux/ipc_namespace.h b/include/linux/ipc_namespace.h
82693index 35e7eca..6afb7ad 100644
82694--- a/include/linux/ipc_namespace.h
82695+++ b/include/linux/ipc_namespace.h
82696@@ -69,7 +69,7 @@ struct ipc_namespace {
82697 struct user_namespace *user_ns;
82698
82699 unsigned int proc_inum;
82700-};
82701+} __randomize_layout;
82702
82703 extern struct ipc_namespace init_ipc_ns;
82704 extern atomic_t nr_ipc_ns;
82705diff --git a/include/linux/irq.h b/include/linux/irq.h
82706index 03f48d9..e86af0c 100644
82707--- a/include/linux/irq.h
82708+++ b/include/linux/irq.h
82709@@ -352,7 +352,8 @@ struct irq_chip {
82710 void (*irq_release_resources)(struct irq_data *data);
82711
82712 unsigned long flags;
82713-};
82714+} __do_const;
82715+typedef struct irq_chip __no_const irq_chip_no_const;
82716
82717 /*
82718 * irq_chip specific flags
82719diff --git a/include/linux/irqchip/arm-gic.h b/include/linux/irqchip/arm-gic.h
82720index 13eed92..3261c86 100644
82721--- a/include/linux/irqchip/arm-gic.h
82722+++ b/include/linux/irqchip/arm-gic.h
82723@@ -91,9 +91,11 @@
82724
82725 #ifndef __ASSEMBLY__
82726
82727+#include <linux/irq.h>
82728+
82729 struct device_node;
82730
82731-extern struct irq_chip gic_arch_extn;
82732+extern irq_chip_no_const gic_arch_extn;
82733
82734 void gic_init_bases(unsigned int, int, void __iomem *, void __iomem *,
82735 u32 offset, struct device_node *);
82736diff --git a/include/linux/jiffies.h b/include/linux/jiffies.h
82737index c367cbd..c9b79e6 100644
82738--- a/include/linux/jiffies.h
82739+++ b/include/linux/jiffies.h
82740@@ -280,20 +280,20 @@ extern unsigned long preset_lpj;
82741 /*
82742 * Convert various time units to each other:
82743 */
82744-extern unsigned int jiffies_to_msecs(const unsigned long j);
82745-extern unsigned int jiffies_to_usecs(const unsigned long j);
82746+extern unsigned int jiffies_to_msecs(const unsigned long j) __intentional_overflow(-1);
82747+extern unsigned int jiffies_to_usecs(const unsigned long j) __intentional_overflow(-1);
82748
82749-static inline u64 jiffies_to_nsecs(const unsigned long j)
82750+static inline u64 __intentional_overflow(-1) jiffies_to_nsecs(const unsigned long j)
82751 {
82752 return (u64)jiffies_to_usecs(j) * NSEC_PER_USEC;
82753 }
82754
82755-extern unsigned long msecs_to_jiffies(const unsigned int m);
82756-extern unsigned long usecs_to_jiffies(const unsigned int u);
82757+extern unsigned long msecs_to_jiffies(const unsigned int m) __intentional_overflow(-1);
82758+extern unsigned long usecs_to_jiffies(const unsigned int u) __intentional_overflow(-1);
82759 extern unsigned long timespec_to_jiffies(const struct timespec *value);
82760 extern void jiffies_to_timespec(const unsigned long jiffies,
82761- struct timespec *value);
82762-extern unsigned long timeval_to_jiffies(const struct timeval *value);
82763+ struct timespec *value) __intentional_overflow(-1);
82764+extern unsigned long timeval_to_jiffies(const struct timeval *value) __intentional_overflow(-1);
82765 extern void jiffies_to_timeval(const unsigned long jiffies,
82766 struct timeval *value);
82767
82768diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
82769index 6883e19..e854fcb 100644
82770--- a/include/linux/kallsyms.h
82771+++ b/include/linux/kallsyms.h
82772@@ -15,7 +15,8 @@
82773
82774 struct module;
82775
82776-#ifdef CONFIG_KALLSYMS
82777+#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
82778+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
82779 /* Lookup the address for a symbol. Returns 0 if not found. */
82780 unsigned long kallsyms_lookup_name(const char *name);
82781
82782@@ -106,6 +107,21 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
82783 /* Stupid that this does nothing, but I didn't create this mess. */
82784 #define __print_symbol(fmt, addr)
82785 #endif /*CONFIG_KALLSYMS*/
82786+#else /* when included by kallsyms.c, vsnprintf.c, kprobes.c, or
82787+ arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
82788+extern unsigned long kallsyms_lookup_name(const char *name);
82789+extern void __print_symbol(const char *fmt, unsigned long address);
82790+extern int sprint_backtrace(char *buffer, unsigned long address);
82791+extern int sprint_symbol(char *buffer, unsigned long address);
82792+extern int sprint_symbol_no_offset(char *buffer, unsigned long address);
82793+const char *kallsyms_lookup(unsigned long addr,
82794+ unsigned long *symbolsize,
82795+ unsigned long *offset,
82796+ char **modname, char *namebuf);
82797+extern int kallsyms_lookup_size_offset(unsigned long addr,
82798+ unsigned long *symbolsize,
82799+ unsigned long *offset);
82800+#endif
82801
82802 /* This macro allows us to keep printk typechecking */
82803 static __printf(1, 2)
82804diff --git a/include/linux/key-type.h b/include/linux/key-type.h
82805index ff9f1d3..6712be5 100644
82806--- a/include/linux/key-type.h
82807+++ b/include/linux/key-type.h
82808@@ -152,7 +152,7 @@ struct key_type {
82809 /* internal fields */
82810 struct list_head link; /* link in types list */
82811 struct lock_class_key lock_class; /* key->sem lock class */
82812-};
82813+} __do_const;
82814
82815 extern struct key_type key_type_keyring;
82816
82817diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
82818index e465bb1..19f605f 100644
82819--- a/include/linux/kgdb.h
82820+++ b/include/linux/kgdb.h
82821@@ -52,7 +52,7 @@ extern int kgdb_connected;
82822 extern int kgdb_io_module_registered;
82823
82824 extern atomic_t kgdb_setting_breakpoint;
82825-extern atomic_t kgdb_cpu_doing_single_step;
82826+extern atomic_unchecked_t kgdb_cpu_doing_single_step;
82827
82828 extern struct task_struct *kgdb_usethread;
82829 extern struct task_struct *kgdb_contthread;
82830@@ -254,7 +254,7 @@ struct kgdb_arch {
82831 void (*correct_hw_break)(void);
82832
82833 void (*enable_nmi)(bool on);
82834-};
82835+} __do_const;
82836
82837 /**
82838 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
82839@@ -279,7 +279,7 @@ struct kgdb_io {
82840 void (*pre_exception) (void);
82841 void (*post_exception) (void);
82842 int is_console;
82843-};
82844+} __do_const;
82845
82846 extern struct kgdb_arch arch_kgdb_ops;
82847
82848diff --git a/include/linux/kmod.h b/include/linux/kmod.h
82849index 0555cc6..40116ce 100644
82850--- a/include/linux/kmod.h
82851+++ b/include/linux/kmod.h
82852@@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
82853 * usually useless though. */
82854 extern __printf(2, 3)
82855 int __request_module(bool wait, const char *name, ...);
82856+extern __printf(3, 4)
82857+int ___request_module(bool wait, char *param_name, const char *name, ...);
82858 #define request_module(mod...) __request_module(true, mod)
82859 #define request_module_nowait(mod...) __request_module(false, mod)
82860 #define try_then_request_module(x, mod...) \
82861@@ -57,6 +59,9 @@ struct subprocess_info {
82862 struct work_struct work;
82863 struct completion *complete;
82864 char *path;
82865+#ifdef CONFIG_GRKERNSEC
82866+ char *origpath;
82867+#endif
82868 char **argv;
82869 char **envp;
82870 int wait;
82871diff --git a/include/linux/kobject.h b/include/linux/kobject.h
82872index 2d61b90..a1d0a13 100644
82873--- a/include/linux/kobject.h
82874+++ b/include/linux/kobject.h
82875@@ -118,7 +118,7 @@ struct kobj_type {
82876 struct attribute **default_attrs;
82877 const struct kobj_ns_type_operations *(*child_ns_type)(struct kobject *kobj);
82878 const void *(*namespace)(struct kobject *kobj);
82879-};
82880+} __do_const;
82881
82882 struct kobj_uevent_env {
82883 char *argv[3];
82884@@ -142,6 +142,7 @@ struct kobj_attribute {
82885 ssize_t (*store)(struct kobject *kobj, struct kobj_attribute *attr,
82886 const char *buf, size_t count);
82887 };
82888+typedef struct kobj_attribute __no_const kobj_attribute_no_const;
82889
82890 extern const struct sysfs_ops kobj_sysfs_ops;
82891
82892@@ -169,7 +170,7 @@ struct kset {
82893 spinlock_t list_lock;
82894 struct kobject kobj;
82895 const struct kset_uevent_ops *uevent_ops;
82896-};
82897+} __randomize_layout;
82898
82899 extern void kset_init(struct kset *kset);
82900 extern int __must_check kset_register(struct kset *kset);
82901diff --git a/include/linux/kobject_ns.h b/include/linux/kobject_ns.h
82902index df32d25..fb52e27 100644
82903--- a/include/linux/kobject_ns.h
82904+++ b/include/linux/kobject_ns.h
82905@@ -44,7 +44,7 @@ struct kobj_ns_type_operations {
82906 const void *(*netlink_ns)(struct sock *sk);
82907 const void *(*initial_ns)(void);
82908 void (*drop_ns)(void *);
82909-};
82910+} __do_const;
82911
82912 int kobj_ns_type_register(const struct kobj_ns_type_operations *ops);
82913 int kobj_ns_type_registered(enum kobj_ns_type type);
82914diff --git a/include/linux/kref.h b/include/linux/kref.h
82915index 484604d..0f6c5b6 100644
82916--- a/include/linux/kref.h
82917+++ b/include/linux/kref.h
82918@@ -68,7 +68,7 @@ static inline void kref_get(struct kref *kref)
82919 static inline int kref_sub(struct kref *kref, unsigned int count,
82920 void (*release)(struct kref *kref))
82921 {
82922- WARN_ON(release == NULL);
82923+ BUG_ON(release == NULL);
82924
82925 if (atomic_sub_and_test((int) count, &kref->refcount)) {
82926 release(kref);
82927diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
82928index a6059bd..8126d5c 100644
82929--- a/include/linux/kvm_host.h
82930+++ b/include/linux/kvm_host.h
82931@@ -460,7 +460,7 @@ static inline void kvm_irqfd_exit(void)
82932 {
82933 }
82934 #endif
82935-int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
82936+int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
82937 struct module *module);
82938 void kvm_exit(void);
82939
82940@@ -629,7 +629,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
82941 struct kvm_guest_debug *dbg);
82942 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
82943
82944-int kvm_arch_init(void *opaque);
82945+int kvm_arch_init(const void *opaque);
82946 void kvm_arch_exit(void);
82947
82948 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
82949diff --git a/include/linux/libata.h b/include/linux/libata.h
82950index bd5fefe..2a8a8d2 100644
82951--- a/include/linux/libata.h
82952+++ b/include/linux/libata.h
82953@@ -976,7 +976,7 @@ struct ata_port_operations {
82954 * fields must be pointers.
82955 */
82956 const struct ata_port_operations *inherits;
82957-};
82958+} __do_const;
82959
82960 struct ata_port_info {
82961 unsigned long flags;
82962diff --git a/include/linux/linkage.h b/include/linux/linkage.h
82963index a6a42dd..6c5ebce 100644
82964--- a/include/linux/linkage.h
82965+++ b/include/linux/linkage.h
82966@@ -36,6 +36,7 @@
82967 #endif
82968
82969 #define __page_aligned_data __section(.data..page_aligned) __aligned(PAGE_SIZE)
82970+#define __page_aligned_rodata __read_only __aligned(PAGE_SIZE)
82971 #define __page_aligned_bss __section(.bss..page_aligned) __aligned(PAGE_SIZE)
82972
82973 /*
82974diff --git a/include/linux/list.h b/include/linux/list.h
82975index f33f831..1ffe5e2 100644
82976--- a/include/linux/list.h
82977+++ b/include/linux/list.h
82978@@ -113,6 +113,19 @@ extern void __list_del_entry(struct list_head *entry);
82979 extern void list_del(struct list_head *entry);
82980 #endif
82981
82982+extern void __pax_list_add(struct list_head *new,
82983+ struct list_head *prev,
82984+ struct list_head *next);
82985+static inline void pax_list_add(struct list_head *new, struct list_head *head)
82986+{
82987+ __pax_list_add(new, head, head->next);
82988+}
82989+static inline void pax_list_add_tail(struct list_head *new, struct list_head *head)
82990+{
82991+ __pax_list_add(new, head->prev, head);
82992+}
82993+extern void pax_list_del(struct list_head *entry);
82994+
82995 /**
82996 * list_replace - replace old entry by new one
82997 * @old : the element to be replaced
82998@@ -146,6 +159,8 @@ static inline void list_del_init(struct list_head *entry)
82999 INIT_LIST_HEAD(entry);
83000 }
83001
83002+extern void pax_list_del_init(struct list_head *entry);
83003+
83004 /**
83005 * list_move - delete from one list and add as another's head
83006 * @list: the entry to move
83007diff --git a/include/linux/lockref.h b/include/linux/lockref.h
83008index 4bfde0e..d6e2e09 100644
83009--- a/include/linux/lockref.h
83010+++ b/include/linux/lockref.h
83011@@ -47,4 +47,36 @@ static inline int __lockref_is_dead(const struct lockref *l)
83012 return ((int)l->count < 0);
83013 }
83014
83015+static inline unsigned int __lockref_read(struct lockref *lockref)
83016+{
83017+ return lockref->count;
83018+}
83019+
83020+static inline void __lockref_set(struct lockref *lockref, unsigned int count)
83021+{
83022+ lockref->count = count;
83023+}
83024+
83025+static inline void __lockref_inc(struct lockref *lockref)
83026+{
83027+
83028+#ifdef CONFIG_PAX_REFCOUNT
83029+ atomic_inc((atomic_t *)&lockref->count);
83030+#else
83031+ lockref->count++;
83032+#endif
83033+
83034+}
83035+
83036+static inline void __lockref_dec(struct lockref *lockref)
83037+{
83038+
83039+#ifdef CONFIG_PAX_REFCOUNT
83040+ atomic_dec((atomic_t *)&lockref->count);
83041+#else
83042+ lockref->count--;
83043+#endif
83044+
83045+}
83046+
83047 #endif /* __LINUX_LOCKREF_H */
83048diff --git a/include/linux/math64.h b/include/linux/math64.h
83049index c45c089..298841c 100644
83050--- a/include/linux/math64.h
83051+++ b/include/linux/math64.h
83052@@ -15,7 +15,7 @@
83053 * This is commonly provided by 32bit archs to provide an optimized 64bit
83054 * divide.
83055 */
83056-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
83057+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
83058 {
83059 *remainder = dividend % divisor;
83060 return dividend / divisor;
83061@@ -42,7 +42,7 @@ static inline u64 div64_u64_rem(u64 dividend, u64 divisor, u64 *remainder)
83062 /**
83063 * div64_u64 - unsigned 64bit divide with 64bit divisor
83064 */
83065-static inline u64 div64_u64(u64 dividend, u64 divisor)
83066+static inline u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor)
83067 {
83068 return dividend / divisor;
83069 }
83070@@ -61,7 +61,7 @@ static inline s64 div64_s64(s64 dividend, s64 divisor)
83071 #define div64_ul(x, y) div_u64((x), (y))
83072
83073 #ifndef div_u64_rem
83074-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
83075+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
83076 {
83077 *remainder = do_div(dividend, divisor);
83078 return dividend;
83079@@ -77,7 +77,7 @@ extern u64 div64_u64_rem(u64 dividend, u64 divisor, u64 *remainder);
83080 #endif
83081
83082 #ifndef div64_u64
83083-extern u64 div64_u64(u64 dividend, u64 divisor);
83084+extern u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor);
83085 #endif
83086
83087 #ifndef div64_s64
83088@@ -94,7 +94,7 @@ extern s64 div64_s64(s64 dividend, s64 divisor);
83089 * divide.
83090 */
83091 #ifndef div_u64
83092-static inline u64 div_u64(u64 dividend, u32 divisor)
83093+static inline u64 __intentional_overflow(-1) div_u64(u64 dividend, u32 divisor)
83094 {
83095 u32 remainder;
83096 return div_u64_rem(dividend, divisor, &remainder);
83097diff --git a/include/linux/mempolicy.h b/include/linux/mempolicy.h
83098index 3d385c8..deacb6a 100644
83099--- a/include/linux/mempolicy.h
83100+++ b/include/linux/mempolicy.h
83101@@ -91,6 +91,10 @@ static inline struct mempolicy *mpol_dup(struct mempolicy *pol)
83102 }
83103
83104 #define vma_policy(vma) ((vma)->vm_policy)
83105+static inline void set_vma_policy(struct vm_area_struct *vma, struct mempolicy *pol)
83106+{
83107+ vma->vm_policy = pol;
83108+}
83109
83110 static inline void mpol_get(struct mempolicy *pol)
83111 {
83112@@ -229,6 +233,9 @@ static inline void mpol_free_shared_policy(struct shared_policy *p)
83113 }
83114
83115 #define vma_policy(vma) NULL
83116+static inline void set_vma_policy(struct vm_area_struct *vma, struct mempolicy *pol)
83117+{
83118+}
83119
83120 static inline int
83121 vma_dup_policy(struct vm_area_struct *src, struct vm_area_struct *dst)
83122diff --git a/include/linux/mm.h b/include/linux/mm.h
83123index b464611..77cbfc1 100644
83124--- a/include/linux/mm.h
83125+++ b/include/linux/mm.h
83126@@ -128,6 +128,11 @@ extern unsigned int kobjsize(const void *objp);
83127 #define VM_HUGETLB 0x00400000 /* Huge TLB Page VM */
83128 #define VM_NONLINEAR 0x00800000 /* Is non-linear (remap_file_pages) */
83129 #define VM_ARCH_1 0x01000000 /* Architecture-specific flag */
83130+
83131+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
83132+#define VM_PAGEEXEC 0x02000000 /* vma->vm_page_prot needs special handling */
83133+#endif
83134+
83135 #define VM_DONTDUMP 0x04000000 /* Do not include in the core dump */
83136
83137 #ifdef CONFIG_MEM_SOFT_DIRTY
83138@@ -238,8 +243,8 @@ struct vm_operations_struct {
83139 /* called by access_process_vm when get_user_pages() fails, typically
83140 * for use by special VMAs that can switch between memory and hardware
83141 */
83142- int (*access)(struct vm_area_struct *vma, unsigned long addr,
83143- void *buf, int len, int write);
83144+ ssize_t (*access)(struct vm_area_struct *vma, unsigned long addr,
83145+ void *buf, size_t len, int write);
83146
83147 /* Called by the /proc/PID/maps code to ask the vma whether it
83148 * has a special name. Returning non-NULL will also cause this
83149@@ -275,6 +280,7 @@ struct vm_operations_struct {
83150 int (*remap_pages)(struct vm_area_struct *vma, unsigned long addr,
83151 unsigned long size, pgoff_t pgoff);
83152 };
83153+typedef struct vm_operations_struct __no_const vm_operations_struct_no_const;
83154
83155 struct mmu_gather;
83156 struct inode;
83157@@ -1165,8 +1171,8 @@ int follow_pfn(struct vm_area_struct *vma, unsigned long address,
83158 unsigned long *pfn);
83159 int follow_phys(struct vm_area_struct *vma, unsigned long address,
83160 unsigned int flags, unsigned long *prot, resource_size_t *phys);
83161-int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
83162- void *buf, int len, int write);
83163+ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
83164+ void *buf, size_t len, int write);
83165
83166 static inline void unmap_shared_mapping_range(struct address_space *mapping,
83167 loff_t const holebegin, loff_t const holelen)
83168@@ -1206,9 +1212,9 @@ static inline int fixup_user_fault(struct task_struct *tsk,
83169 }
83170 #endif
83171
83172-extern int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write);
83173-extern int access_remote_vm(struct mm_struct *mm, unsigned long addr,
83174- void *buf, int len, int write);
83175+extern ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write);
83176+extern ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
83177+ void *buf, size_t len, int write);
83178
83179 long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
83180 unsigned long start, unsigned long nr_pages,
83181@@ -1240,34 +1246,6 @@ int set_page_dirty_lock(struct page *page);
83182 int clear_page_dirty_for_io(struct page *page);
83183 int get_cmdline(struct task_struct *task, char *buffer, int buflen);
83184
83185-/* Is the vma a continuation of the stack vma above it? */
83186-static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
83187-{
83188- return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
83189-}
83190-
83191-static inline int stack_guard_page_start(struct vm_area_struct *vma,
83192- unsigned long addr)
83193-{
83194- return (vma->vm_flags & VM_GROWSDOWN) &&
83195- (vma->vm_start == addr) &&
83196- !vma_growsdown(vma->vm_prev, addr);
83197-}
83198-
83199-/* Is the vma a continuation of the stack vma below it? */
83200-static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
83201-{
83202- return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
83203-}
83204-
83205-static inline int stack_guard_page_end(struct vm_area_struct *vma,
83206- unsigned long addr)
83207-{
83208- return (vma->vm_flags & VM_GROWSUP) &&
83209- (vma->vm_end == addr) &&
83210- !vma_growsup(vma->vm_next, addr);
83211-}
83212-
83213 extern struct task_struct *task_of_stack(struct task_struct *task,
83214 struct vm_area_struct *vma, bool in_group);
83215
83216@@ -1385,8 +1363,15 @@ static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
83217 {
83218 return 0;
83219 }
83220+
83221+static inline int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd,
83222+ unsigned long address)
83223+{
83224+ return 0;
83225+}
83226 #else
83227 int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
83228+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
83229 #endif
83230
83231 #ifdef __PAGETABLE_PMD_FOLDED
83232@@ -1395,8 +1380,15 @@ static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
83233 {
83234 return 0;
83235 }
83236+
83237+static inline int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud,
83238+ unsigned long address)
83239+{
83240+ return 0;
83241+}
83242 #else
83243 int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
83244+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address);
83245 #endif
83246
83247 int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
83248@@ -1414,11 +1406,23 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long a
83249 NULL: pud_offset(pgd, address);
83250 }
83251
83252+static inline pud_t *pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
83253+{
83254+ return (unlikely(pgd_none(*pgd)) && __pud_alloc_kernel(mm, pgd, address))?
83255+ NULL: pud_offset(pgd, address);
83256+}
83257+
83258 static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
83259 {
83260 return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
83261 NULL: pmd_offset(pud, address);
83262 }
83263+
83264+static inline pmd_t *pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
83265+{
83266+ return (unlikely(pud_none(*pud)) && __pmd_alloc_kernel(mm, pud, address))?
83267+ NULL: pmd_offset(pud, address);
83268+}
83269 #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
83270
83271 #if USE_SPLIT_PTE_PTLOCKS
83272@@ -1801,12 +1805,23 @@ extern struct vm_area_struct *copy_vma(struct vm_area_struct **,
83273 bool *need_rmap_locks);
83274 extern void exit_mmap(struct mm_struct *);
83275
83276+#if defined(CONFIG_GRKERNSEC) && (defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC))
83277+extern void gr_learn_resource(const struct task_struct *task, const int res,
83278+ const unsigned long wanted, const int gt);
83279+#else
83280+static inline void gr_learn_resource(const struct task_struct *task, const int res,
83281+ const unsigned long wanted, const int gt)
83282+{
83283+}
83284+#endif
83285+
83286 static inline int check_data_rlimit(unsigned long rlim,
83287 unsigned long new,
83288 unsigned long start,
83289 unsigned long end_data,
83290 unsigned long start_data)
83291 {
83292+ gr_learn_resource(current, RLIMIT_DATA, (new - start) + (end_data - start_data), 1);
83293 if (rlim < RLIM_INFINITY) {
83294 if (((new - start) + (end_data - start_data)) > rlim)
83295 return -ENOSPC;
83296@@ -1831,7 +1846,7 @@ extern int install_special_mapping(struct mm_struct *mm,
83297 unsigned long addr, unsigned long len,
83298 unsigned long flags, struct page **pages);
83299
83300-extern unsigned long get_unmapped_area(struct file *, unsigned long, unsigned long, unsigned long, unsigned long);
83301+extern unsigned long get_unmapped_area(struct file *, unsigned long, unsigned long, unsigned long, unsigned long) __intentional_overflow(-1);
83302
83303 extern unsigned long mmap_region(struct file *file, unsigned long addr,
83304 unsigned long len, vm_flags_t vm_flags, unsigned long pgoff);
83305@@ -1839,6 +1854,7 @@ extern unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
83306 unsigned long len, unsigned long prot, unsigned long flags,
83307 unsigned long pgoff, unsigned long *populate);
83308 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
83309+extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
83310
83311 #ifdef CONFIG_MMU
83312 extern int __mm_populate(unsigned long addr, unsigned long len,
83313@@ -1867,10 +1883,11 @@ struct vm_unmapped_area_info {
83314 unsigned long high_limit;
83315 unsigned long align_mask;
83316 unsigned long align_offset;
83317+ unsigned long threadstack_offset;
83318 };
83319
83320-extern unsigned long unmapped_area(struct vm_unmapped_area_info *info);
83321-extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
83322+extern unsigned long unmapped_area(const struct vm_unmapped_area_info *info);
83323+extern unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info);
83324
83325 /*
83326 * Search for an unmapped address range.
83327@@ -1882,7 +1899,7 @@ extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
83328 * - satisfies (begin_addr & align_mask) == (align_offset & align_mask)
83329 */
83330 static inline unsigned long
83331-vm_unmapped_area(struct vm_unmapped_area_info *info)
83332+vm_unmapped_area(const struct vm_unmapped_area_info *info)
83333 {
83334 if (!(info->flags & VM_UNMAPPED_AREA_TOPDOWN))
83335 return unmapped_area(info);
83336@@ -1944,6 +1961,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
83337 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
83338 struct vm_area_struct **pprev);
83339
83340+extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
83341+extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
83342+extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
83343+
83344 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
83345 NULL if none. Assume start_addr < end_addr. */
83346 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
83347@@ -1973,10 +1994,10 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
83348 }
83349
83350 #ifdef CONFIG_MMU
83351-pgprot_t vm_get_page_prot(unsigned long vm_flags);
83352+pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
83353 void vma_set_page_prot(struct vm_area_struct *vma);
83354 #else
83355-static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
83356+static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
83357 {
83358 return __pgprot(0);
83359 }
83360@@ -2038,6 +2059,11 @@ void vm_stat_account(struct mm_struct *, unsigned long, struct file *, long);
83361 static inline void vm_stat_account(struct mm_struct *mm,
83362 unsigned long flags, struct file *file, long pages)
83363 {
83364+
83365+#ifdef CONFIG_PAX_RANDMMAP
83366+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
83367+#endif
83368+
83369 mm->total_vm += pages;
83370 }
83371 #endif /* CONFIG_PROC_FS */
83372@@ -2126,7 +2152,7 @@ extern int unpoison_memory(unsigned long pfn);
83373 extern int sysctl_memory_failure_early_kill;
83374 extern int sysctl_memory_failure_recovery;
83375 extern void shake_page(struct page *p, int access);
83376-extern atomic_long_t num_poisoned_pages;
83377+extern atomic_long_unchecked_t num_poisoned_pages;
83378 extern int soft_offline_page(struct page *page, int flags);
83379
83380 #if defined(CONFIG_TRANSPARENT_HUGEPAGE) || defined(CONFIG_HUGETLBFS)
83381@@ -2161,5 +2187,11 @@ void __init setup_nr_node_ids(void);
83382 static inline void setup_nr_node_ids(void) {}
83383 #endif
83384
83385+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
83386+extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
83387+#else
83388+static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
83389+#endif
83390+
83391 #endif /* __KERNEL__ */
83392 #endif /* _LINUX_MM_H */
83393diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
83394index 6e0b286..90d9c0d 100644
83395--- a/include/linux/mm_types.h
83396+++ b/include/linux/mm_types.h
83397@@ -308,7 +308,9 @@ struct vm_area_struct {
83398 #ifdef CONFIG_NUMA
83399 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
83400 #endif
83401-};
83402+
83403+ struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
83404+} __randomize_layout;
83405
83406 struct core_thread {
83407 struct task_struct *task;
83408@@ -454,7 +456,25 @@ struct mm_struct {
83409 bool tlb_flush_pending;
83410 #endif
83411 struct uprobes_state uprobes_state;
83412-};
83413+
83414+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
83415+ unsigned long pax_flags;
83416+#endif
83417+
83418+#ifdef CONFIG_PAX_DLRESOLVE
83419+ unsigned long call_dl_resolve;
83420+#endif
83421+
83422+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
83423+ unsigned long call_syscall;
83424+#endif
83425+
83426+#ifdef CONFIG_PAX_ASLR
83427+ unsigned long delta_mmap; /* randomized offset */
83428+ unsigned long delta_stack; /* randomized offset */
83429+#endif
83430+
83431+} __randomize_layout;
83432
83433 static inline void mm_init_cpumask(struct mm_struct *mm)
83434 {
83435diff --git a/include/linux/mmiotrace.h b/include/linux/mmiotrace.h
83436index c5d5278..f0b68c8 100644
83437--- a/include/linux/mmiotrace.h
83438+++ b/include/linux/mmiotrace.h
83439@@ -46,7 +46,7 @@ extern int kmmio_handler(struct pt_regs *regs, unsigned long addr);
83440 /* Called from ioremap.c */
83441 extern void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
83442 void __iomem *addr);
83443-extern void mmiotrace_iounmap(volatile void __iomem *addr);
83444+extern void mmiotrace_iounmap(const volatile void __iomem *addr);
83445
83446 /* For anyone to insert markers. Remember trailing newline. */
83447 extern __printf(1, 2) int mmiotrace_printk(const char *fmt, ...);
83448@@ -66,7 +66,7 @@ static inline void mmiotrace_ioremap(resource_size_t offset,
83449 {
83450 }
83451
83452-static inline void mmiotrace_iounmap(volatile void __iomem *addr)
83453+static inline void mmiotrace_iounmap(const volatile void __iomem *addr)
83454 {
83455 }
83456
83457diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
83458index ffe66e3..b310722 100644
83459--- a/include/linux/mmzone.h
83460+++ b/include/linux/mmzone.h
83461@@ -527,7 +527,7 @@ struct zone {
83462
83463 ZONE_PADDING(_pad3_)
83464 /* Zone statistics */
83465- atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
83466+ atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
83467 } ____cacheline_internodealigned_in_smp;
83468
83469 enum zone_flags {
83470diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
83471index 44eeef0..a92d3f9 100644
83472--- a/include/linux/mod_devicetable.h
83473+++ b/include/linux/mod_devicetable.h
83474@@ -139,7 +139,7 @@ struct usb_device_id {
83475 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
83476 #define USB_DEVICE_ID_MATCH_INT_NUMBER 0x0400
83477
83478-#define HID_ANY_ID (~0)
83479+#define HID_ANY_ID (~0U)
83480 #define HID_BUS_ANY 0xffff
83481 #define HID_GROUP_ANY 0x0000
83482
83483@@ -475,7 +475,7 @@ struct dmi_system_id {
83484 const char *ident;
83485 struct dmi_strmatch matches[4];
83486 void *driver_data;
83487-};
83488+} __do_const;
83489 /*
83490 * struct dmi_device_id appears during expansion of
83491 * "MODULE_DEVICE_TABLE(dmi, x)". Compiler doesn't look inside it
83492diff --git a/include/linux/module.h b/include/linux/module.h
83493index 71f282a..b2387e2 100644
83494--- a/include/linux/module.h
83495+++ b/include/linux/module.h
83496@@ -17,9 +17,11 @@
83497 #include <linux/moduleparam.h>
83498 #include <linux/jump_label.h>
83499 #include <linux/export.h>
83500+#include <linux/fs.h>
83501
83502 #include <linux/percpu.h>
83503 #include <asm/module.h>
83504+#include <asm/pgtable.h>
83505
83506 /* In stripped ARM and x86-64 modules, ~ is surprisingly rare. */
83507 #define MODULE_SIG_STRING "~Module signature appended~\n"
83508@@ -42,7 +44,7 @@ struct module_kobject {
83509 struct kobject *drivers_dir;
83510 struct module_param_attrs *mp;
83511 struct completion *kobj_completion;
83512-};
83513+} __randomize_layout;
83514
83515 struct module_attribute {
83516 struct attribute attr;
83517@@ -54,12 +56,13 @@ struct module_attribute {
83518 int (*test)(struct module *);
83519 void (*free)(struct module *);
83520 };
83521+typedef struct module_attribute __no_const module_attribute_no_const;
83522
83523 struct module_version_attribute {
83524 struct module_attribute mattr;
83525 const char *module_name;
83526 const char *version;
83527-} __attribute__ ((__aligned__(sizeof(void *))));
83528+} __do_const __attribute__ ((__aligned__(sizeof(void *))));
83529
83530 extern ssize_t __modver_version_show(struct module_attribute *,
83531 struct module_kobject *, char *);
83532@@ -235,7 +238,7 @@ struct module {
83533
83534 /* Sysfs stuff. */
83535 struct module_kobject mkobj;
83536- struct module_attribute *modinfo_attrs;
83537+ module_attribute_no_const *modinfo_attrs;
83538 const char *version;
83539 const char *srcversion;
83540 struct kobject *holders_dir;
83541@@ -284,19 +287,16 @@ struct module {
83542 int (*init)(void);
83543
83544 /* If this is non-NULL, vfree after init() returns */
83545- void *module_init;
83546+ void *module_init_rx, *module_init_rw;
83547
83548 /* Here is the actual code + data, vfree'd on unload. */
83549- void *module_core;
83550+ void *module_core_rx, *module_core_rw;
83551
83552 /* Here are the sizes of the init and core sections */
83553- unsigned int init_size, core_size;
83554+ unsigned int init_size_rw, core_size_rw;
83555
83556 /* The size of the executable code in each section. */
83557- unsigned int init_text_size, core_text_size;
83558-
83559- /* Size of RO sections of the module (text+rodata) */
83560- unsigned int init_ro_size, core_ro_size;
83561+ unsigned int init_size_rx, core_size_rx;
83562
83563 /* Arch-specific module values */
83564 struct mod_arch_specific arch;
83565@@ -352,6 +352,10 @@ struct module {
83566 #ifdef CONFIG_EVENT_TRACING
83567 struct ftrace_event_call **trace_events;
83568 unsigned int num_trace_events;
83569+ struct file_operations trace_id;
83570+ struct file_operations trace_enable;
83571+ struct file_operations trace_format;
83572+ struct file_operations trace_filter;
83573 #endif
83574 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
83575 unsigned int num_ftrace_callsites;
83576@@ -375,7 +379,7 @@ struct module {
83577 ctor_fn_t *ctors;
83578 unsigned int num_ctors;
83579 #endif
83580-};
83581+} __randomize_layout;
83582 #ifndef MODULE_ARCH_INIT
83583 #define MODULE_ARCH_INIT {}
83584 #endif
83585@@ -396,18 +400,48 @@ bool is_module_address(unsigned long addr);
83586 bool is_module_percpu_address(unsigned long addr);
83587 bool is_module_text_address(unsigned long addr);
83588
83589+static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
83590+{
83591+
83592+#ifdef CONFIG_PAX_KERNEXEC
83593+ if (ktla_ktva(addr) >= (unsigned long)start &&
83594+ ktla_ktva(addr) < (unsigned long)start + size)
83595+ return 1;
83596+#endif
83597+
83598+ return ((void *)addr >= start && (void *)addr < start + size);
83599+}
83600+
83601+static inline int within_module_core_rx(unsigned long addr, const struct module *mod)
83602+{
83603+ return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
83604+}
83605+
83606+static inline int within_module_core_rw(unsigned long addr, const struct module *mod)
83607+{
83608+ return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
83609+}
83610+
83611+static inline int within_module_init_rx(unsigned long addr, const struct module *mod)
83612+{
83613+ return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
83614+}
83615+
83616+static inline int within_module_init_rw(unsigned long addr, const struct module *mod)
83617+{
83618+ return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
83619+}
83620+
83621 static inline bool within_module_core(unsigned long addr,
83622 const struct module *mod)
83623 {
83624- return (unsigned long)mod->module_core <= addr &&
83625- addr < (unsigned long)mod->module_core + mod->core_size;
83626+ return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
83627 }
83628
83629 static inline bool within_module_init(unsigned long addr,
83630 const struct module *mod)
83631 {
83632- return (unsigned long)mod->module_init <= addr &&
83633- addr < (unsigned long)mod->module_init + mod->init_size;
83634+ return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
83635 }
83636
83637 static inline bool within_module(unsigned long addr, const struct module *mod)
83638diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
83639index 7eeb9bb..68f37e0 100644
83640--- a/include/linux/moduleloader.h
83641+++ b/include/linux/moduleloader.h
83642@@ -25,9 +25,21 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
83643 sections. Returns NULL on failure. */
83644 void *module_alloc(unsigned long size);
83645
83646+#ifdef CONFIG_PAX_KERNEXEC
83647+void *module_alloc_exec(unsigned long size);
83648+#else
83649+#define module_alloc_exec(x) module_alloc(x)
83650+#endif
83651+
83652 /* Free memory returned from module_alloc. */
83653 void module_free(struct module *mod, void *module_region);
83654
83655+#ifdef CONFIG_PAX_KERNEXEC
83656+void module_free_exec(struct module *mod, void *module_region);
83657+#else
83658+#define module_free_exec(x, y) module_free((x), (y))
83659+#endif
83660+
83661 /*
83662 * Apply the given relocation to the (simplified) ELF. Return -error
83663 * or 0.
83664@@ -45,8 +57,10 @@ static inline int apply_relocate(Elf_Shdr *sechdrs,
83665 unsigned int relsec,
83666 struct module *me)
83667 {
83668+#ifdef CONFIG_MODULES
83669 printk(KERN_ERR "module %s: REL relocation unsupported\n",
83670 module_name(me));
83671+#endif
83672 return -ENOEXEC;
83673 }
83674 #endif
83675@@ -68,8 +82,10 @@ static inline int apply_relocate_add(Elf_Shdr *sechdrs,
83676 unsigned int relsec,
83677 struct module *me)
83678 {
83679+#ifdef CONFIG_MODULES
83680 printk(KERN_ERR "module %s: REL relocation unsupported\n",
83681 module_name(me));
83682+#endif
83683 return -ENOEXEC;
83684 }
83685 #endif
83686diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
83687index 1c9effa..1160bdd 100644
83688--- a/include/linux/moduleparam.h
83689+++ b/include/linux/moduleparam.h
83690@@ -323,7 +323,7 @@ static inline void __kernel_param_unlock(void)
83691 * @len is usually just sizeof(string).
83692 */
83693 #define module_param_string(name, string, len, perm) \
83694- static const struct kparam_string __param_string_##name \
83695+ static const struct kparam_string __param_string_##name __used \
83696 = { len, string }; \
83697 __module_param_call(MODULE_PARAM_PREFIX, name, \
83698 &param_ops_string, \
83699@@ -467,7 +467,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
83700 */
83701 #define module_param_array_named(name, array, type, nump, perm) \
83702 param_check_##type(name, &(array)[0]); \
83703- static const struct kparam_array __param_arr_##name \
83704+ static const struct kparam_array __param_arr_##name __used \
83705 = { .max = ARRAY_SIZE(array), .num = nump, \
83706 .ops = &param_ops_##type, \
83707 .elemsize = sizeof(array[0]), .elem = array }; \
83708diff --git a/include/linux/mount.h b/include/linux/mount.h
83709index c2c561d..a5f2a8c 100644
83710--- a/include/linux/mount.h
83711+++ b/include/linux/mount.h
83712@@ -66,7 +66,7 @@ struct vfsmount {
83713 struct dentry *mnt_root; /* root of the mounted tree */
83714 struct super_block *mnt_sb; /* pointer to superblock */
83715 int mnt_flags;
83716-};
83717+} __randomize_layout;
83718
83719 struct file; /* forward dec */
83720 struct path;
83721diff --git a/include/linux/namei.h b/include/linux/namei.h
83722index 492de72..1bddcd4 100644
83723--- a/include/linux/namei.h
83724+++ b/include/linux/namei.h
83725@@ -19,7 +19,7 @@ struct nameidata {
83726 unsigned seq, m_seq;
83727 int last_type;
83728 unsigned depth;
83729- char *saved_names[MAX_NESTED_LINKS + 1];
83730+ const char *saved_names[MAX_NESTED_LINKS + 1];
83731 };
83732
83733 /*
83734@@ -83,12 +83,12 @@ extern void unlock_rename(struct dentry *, struct dentry *);
83735
83736 extern void nd_jump_link(struct nameidata *nd, struct path *path);
83737
83738-static inline void nd_set_link(struct nameidata *nd, char *path)
83739+static inline void nd_set_link(struct nameidata *nd, const char *path)
83740 {
83741 nd->saved_names[nd->depth] = path;
83742 }
83743
83744-static inline char *nd_get_link(struct nameidata *nd)
83745+static inline const char *nd_get_link(const struct nameidata *nd)
83746 {
83747 return nd->saved_names[nd->depth];
83748 }
83749diff --git a/include/linux/net.h b/include/linux/net.h
83750index 17d8339..81656c0 100644
83751--- a/include/linux/net.h
83752+++ b/include/linux/net.h
83753@@ -192,7 +192,7 @@ struct net_proto_family {
83754 int (*create)(struct net *net, struct socket *sock,
83755 int protocol, int kern);
83756 struct module *owner;
83757-};
83758+} __do_const;
83759
83760 struct iovec;
83761 struct kvec;
83762diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
83763index 74fd5d3..86a1e4f 100644
83764--- a/include/linux/netdevice.h
83765+++ b/include/linux/netdevice.h
83766@@ -1156,6 +1156,7 @@ struct net_device_ops {
83767 bool (*ndo_gso_check) (struct sk_buff *skb,
83768 struct net_device *dev);
83769 };
83770+typedef struct net_device_ops __no_const net_device_ops_no_const;
83771
83772 /**
83773 * enum net_device_priv_flags - &struct net_device priv_flags
83774@@ -1498,10 +1499,10 @@ struct net_device {
83775
83776 struct net_device_stats stats;
83777
83778- atomic_long_t rx_dropped;
83779- atomic_long_t tx_dropped;
83780+ atomic_long_unchecked_t rx_dropped;
83781+ atomic_long_unchecked_t tx_dropped;
83782
83783- atomic_t carrier_changes;
83784+ atomic_unchecked_t carrier_changes;
83785
83786 #ifdef CONFIG_WIRELESS_EXT
83787 const struct iw_handler_def * wireless_handlers;
83788diff --git a/include/linux/netfilter.h b/include/linux/netfilter.h
83789index 2517ece..0bbfcfb 100644
83790--- a/include/linux/netfilter.h
83791+++ b/include/linux/netfilter.h
83792@@ -85,7 +85,7 @@ struct nf_sockopt_ops {
83793 #endif
83794 /* Use the module struct to lock set/get code in place */
83795 struct module *owner;
83796-};
83797+} __do_const;
83798
83799 /* Function to register/unregister hook points. */
83800 int nf_register_hook(struct nf_hook_ops *reg);
83801diff --git a/include/linux/netfilter/nfnetlink.h b/include/linux/netfilter/nfnetlink.h
83802index e955d47..04a5338 100644
83803--- a/include/linux/netfilter/nfnetlink.h
83804+++ b/include/linux/netfilter/nfnetlink.h
83805@@ -19,7 +19,7 @@ struct nfnl_callback {
83806 const struct nlattr * const cda[]);
83807 const struct nla_policy *policy; /* netlink attribute policy */
83808 const u_int16_t attr_count; /* number of nlattr's */
83809-};
83810+} __do_const;
83811
83812 struct nfnetlink_subsystem {
83813 const char *name;
83814diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
83815new file mode 100644
83816index 0000000..33f4af8
83817--- /dev/null
83818+++ b/include/linux/netfilter/xt_gradm.h
83819@@ -0,0 +1,9 @@
83820+#ifndef _LINUX_NETFILTER_XT_GRADM_H
83821+#define _LINUX_NETFILTER_XT_GRADM_H 1
83822+
83823+struct xt_gradm_mtinfo {
83824+ __u16 flags;
83825+ __u16 invflags;
83826+};
83827+
83828+#endif
83829diff --git a/include/linux/nls.h b/include/linux/nls.h
83830index 520681b..2b7fabb 100644
83831--- a/include/linux/nls.h
83832+++ b/include/linux/nls.h
83833@@ -31,7 +31,7 @@ struct nls_table {
83834 const unsigned char *charset2upper;
83835 struct module *owner;
83836 struct nls_table *next;
83837-};
83838+} __do_const;
83839
83840 /* this value hold the maximum octet of charset */
83841 #define NLS_MAX_CHARSET_SIZE 6 /* for UTF-8 */
83842@@ -46,7 +46,7 @@ enum utf16_endian {
83843 /* nls_base.c */
83844 extern int __register_nls(struct nls_table *, struct module *);
83845 extern int unregister_nls(struct nls_table *);
83846-extern struct nls_table *load_nls(char *);
83847+extern struct nls_table *load_nls(const char *);
83848 extern void unload_nls(struct nls_table *);
83849 extern struct nls_table *load_nls_default(void);
83850 #define register_nls(nls) __register_nls((nls), THIS_MODULE)
83851diff --git a/include/linux/notifier.h b/include/linux/notifier.h
83852index d14a4c3..a078786 100644
83853--- a/include/linux/notifier.h
83854+++ b/include/linux/notifier.h
83855@@ -54,7 +54,8 @@ struct notifier_block {
83856 notifier_fn_t notifier_call;
83857 struct notifier_block __rcu *next;
83858 int priority;
83859-};
83860+} __do_const;
83861+typedef struct notifier_block __no_const notifier_block_no_const;
83862
83863 struct atomic_notifier_head {
83864 spinlock_t lock;
83865diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
83866index b2a0f15..4d7da32 100644
83867--- a/include/linux/oprofile.h
83868+++ b/include/linux/oprofile.h
83869@@ -138,9 +138,9 @@ int oprofilefs_create_ulong(struct dentry * root,
83870 int oprofilefs_create_ro_ulong(struct dentry * root,
83871 char const * name, ulong * val);
83872
83873-/** Create a file for read-only access to an atomic_t. */
83874+/** Create a file for read-only access to an atomic_unchecked_t. */
83875 int oprofilefs_create_ro_atomic(struct dentry * root,
83876- char const * name, atomic_t * val);
83877+ char const * name, atomic_unchecked_t * val);
83878
83879 /** create a directory */
83880 struct dentry *oprofilefs_mkdir(struct dentry *parent, char const *name);
83881diff --git a/include/linux/padata.h b/include/linux/padata.h
83882index 4386946..f50c615 100644
83883--- a/include/linux/padata.h
83884+++ b/include/linux/padata.h
83885@@ -129,7 +129,7 @@ struct parallel_data {
83886 struct padata_serial_queue __percpu *squeue;
83887 atomic_t reorder_objects;
83888 atomic_t refcnt;
83889- atomic_t seq_nr;
83890+ atomic_unchecked_t seq_nr;
83891 struct padata_cpumask cpumask;
83892 spinlock_t lock ____cacheline_aligned;
83893 unsigned int processed;
83894diff --git a/include/linux/path.h b/include/linux/path.h
83895index d137218..be0c176 100644
83896--- a/include/linux/path.h
83897+++ b/include/linux/path.h
83898@@ -1,13 +1,15 @@
83899 #ifndef _LINUX_PATH_H
83900 #define _LINUX_PATH_H
83901
83902+#include <linux/compiler.h>
83903+
83904 struct dentry;
83905 struct vfsmount;
83906
83907 struct path {
83908 struct vfsmount *mnt;
83909 struct dentry *dentry;
83910-};
83911+} __randomize_layout;
83912
83913 extern void path_get(const struct path *);
83914 extern void path_put(const struct path *);
83915diff --git a/include/linux/pci_hotplug.h b/include/linux/pci_hotplug.h
83916index 2706ee9..e691f7c 100644
83917--- a/include/linux/pci_hotplug.h
83918+++ b/include/linux/pci_hotplug.h
83919@@ -71,7 +71,8 @@ struct hotplug_slot_ops {
83920 int (*get_latch_status) (struct hotplug_slot *slot, u8 *value);
83921 int (*get_adapter_status) (struct hotplug_slot *slot, u8 *value);
83922 int (*reset_slot) (struct hotplug_slot *slot, int probe);
83923-};
83924+} __do_const;
83925+typedef struct hotplug_slot_ops __no_const hotplug_slot_ops_no_const;
83926
83927 /**
83928 * struct hotplug_slot_info - used to notify the hotplug pci core of the state of the slot
83929diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
83930index 893a0d0..d5f996e 100644
83931--- a/include/linux/perf_event.h
83932+++ b/include/linux/perf_event.h
83933@@ -341,8 +341,8 @@ struct perf_event {
83934
83935 enum perf_event_active_state state;
83936 unsigned int attach_state;
83937- local64_t count;
83938- atomic64_t child_count;
83939+ local64_t count; /* PaX: fix it one day */
83940+ atomic64_unchecked_t child_count;
83941
83942 /*
83943 * These are the total time in nanoseconds that the event
83944@@ -393,8 +393,8 @@ struct perf_event {
83945 * These accumulate total time (in nanoseconds) that children
83946 * events have been enabled and running, respectively.
83947 */
83948- atomic64_t child_total_time_enabled;
83949- atomic64_t child_total_time_running;
83950+ atomic64_unchecked_t child_total_time_enabled;
83951+ atomic64_unchecked_t child_total_time_running;
83952
83953 /*
83954 * Protect attach/detach and child_list:
83955@@ -734,7 +734,7 @@ static inline void perf_callchain_store(struct perf_callchain_entry *entry, u64
83956 entry->ip[entry->nr++] = ip;
83957 }
83958
83959-extern int sysctl_perf_event_paranoid;
83960+extern int sysctl_perf_event_legitimately_concerned;
83961 extern int sysctl_perf_event_mlock;
83962 extern int sysctl_perf_event_sample_rate;
83963 extern int sysctl_perf_cpu_time_max_percent;
83964@@ -749,19 +749,24 @@ extern int perf_cpu_time_max_percent_handler(struct ctl_table *table, int write,
83965 loff_t *ppos);
83966
83967
83968+static inline bool perf_paranoid_any(void)
83969+{
83970+ return sysctl_perf_event_legitimately_concerned > 2;
83971+}
83972+
83973 static inline bool perf_paranoid_tracepoint_raw(void)
83974 {
83975- return sysctl_perf_event_paranoid > -1;
83976+ return sysctl_perf_event_legitimately_concerned > -1;
83977 }
83978
83979 static inline bool perf_paranoid_cpu(void)
83980 {
83981- return sysctl_perf_event_paranoid > 0;
83982+ return sysctl_perf_event_legitimately_concerned > 0;
83983 }
83984
83985 static inline bool perf_paranoid_kernel(void)
83986 {
83987- return sysctl_perf_event_paranoid > 1;
83988+ return sysctl_perf_event_legitimately_concerned > 1;
83989 }
83990
83991 extern void perf_event_init(void);
83992@@ -892,7 +897,7 @@ struct perf_pmu_events_attr {
83993 struct device_attribute attr;
83994 u64 id;
83995 const char *event_str;
83996-};
83997+} __do_const;
83998
83999 #define PMU_EVENT_ATTR(_name, _var, _id, _show) \
84000 static struct perf_pmu_events_attr _var = { \
84001diff --git a/include/linux/pid_namespace.h b/include/linux/pid_namespace.h
84002index 1997ffc..4f1f44d 100644
84003--- a/include/linux/pid_namespace.h
84004+++ b/include/linux/pid_namespace.h
84005@@ -44,7 +44,7 @@ struct pid_namespace {
84006 int hide_pid;
84007 int reboot; /* group exit code if this pidns was rebooted */
84008 unsigned int proc_inum;
84009-};
84010+} __randomize_layout;
84011
84012 extern struct pid_namespace init_pid_ns;
84013
84014diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
84015index eb8b8ac..62649e1 100644
84016--- a/include/linux/pipe_fs_i.h
84017+++ b/include/linux/pipe_fs_i.h
84018@@ -47,10 +47,10 @@ struct pipe_inode_info {
84019 struct mutex mutex;
84020 wait_queue_head_t wait;
84021 unsigned int nrbufs, curbuf, buffers;
84022- unsigned int readers;
84023- unsigned int writers;
84024- unsigned int files;
84025- unsigned int waiting_writers;
84026+ atomic_t readers;
84027+ atomic_t writers;
84028+ atomic_t files;
84029+ atomic_t waiting_writers;
84030 unsigned int r_counter;
84031 unsigned int w_counter;
84032 struct page *tmp_page;
84033diff --git a/include/linux/pm.h b/include/linux/pm.h
84034index 383fd68..7a11504 100644
84035--- a/include/linux/pm.h
84036+++ b/include/linux/pm.h
84037@@ -621,6 +621,7 @@ struct dev_pm_domain {
84038 struct dev_pm_ops ops;
84039 void (*detach)(struct device *dev, bool power_off);
84040 };
84041+typedef struct dev_pm_domain __no_const dev_pm_domain_no_const;
84042
84043 /*
84044 * The PM_EVENT_ messages are also used by drivers implementing the legacy
84045diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h
84046index 2e0e06d..824cc9b 100644
84047--- a/include/linux/pm_domain.h
84048+++ b/include/linux/pm_domain.h
84049@@ -36,11 +36,11 @@ struct gpd_dev_ops {
84050 int (*save_state)(struct device *dev);
84051 int (*restore_state)(struct device *dev);
84052 bool (*active_wakeup)(struct device *dev);
84053-};
84054+} __no_const;
84055
84056 struct gpd_cpuidle_data {
84057 unsigned int saved_exit_latency;
84058- struct cpuidle_state *idle_state;
84059+ cpuidle_state_no_const *idle_state;
84060 };
84061
84062 struct generic_pm_domain {
84063diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
84064index 367f49b..d2f5a14 100644
84065--- a/include/linux/pm_runtime.h
84066+++ b/include/linux/pm_runtime.h
84067@@ -125,7 +125,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
84068
84069 static inline void pm_runtime_mark_last_busy(struct device *dev)
84070 {
84071- ACCESS_ONCE(dev->power.last_busy) = jiffies;
84072+ ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
84073 }
84074
84075 #else /* !CONFIG_PM_RUNTIME */
84076diff --git a/include/linux/pnp.h b/include/linux/pnp.h
84077index 195aafc..49a7bc2 100644
84078--- a/include/linux/pnp.h
84079+++ b/include/linux/pnp.h
84080@@ -297,7 +297,7 @@ static inline void pnp_set_drvdata(struct pnp_dev *pdev, void *data)
84081 struct pnp_fixup {
84082 char id[7];
84083 void (*quirk_function) (struct pnp_dev * dev); /* fixup function */
84084-};
84085+} __do_const;
84086
84087 /* config parameters */
84088 #define PNP_CONFIG_NORMAL 0x0001
84089diff --git a/include/linux/poison.h b/include/linux/poison.h
84090index 2110a81..13a11bb 100644
84091--- a/include/linux/poison.h
84092+++ b/include/linux/poison.h
84093@@ -19,8 +19,8 @@
84094 * under normal circumstances, used to verify that nobody uses
84095 * non-initialized list entries.
84096 */
84097-#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
84098-#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
84099+#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
84100+#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
84101
84102 /********** include/linux/timer.h **********/
84103 /*
84104diff --git a/include/linux/power/smartreflex.h b/include/linux/power/smartreflex.h
84105index d8b187c3..9a9257a 100644
84106--- a/include/linux/power/smartreflex.h
84107+++ b/include/linux/power/smartreflex.h
84108@@ -238,7 +238,7 @@ struct omap_sr_class_data {
84109 int (*notify)(struct omap_sr *sr, u32 status);
84110 u8 notify_flags;
84111 u8 class_type;
84112-};
84113+} __do_const;
84114
84115 /**
84116 * struct omap_sr_nvalue_table - Smartreflex n-target value info
84117diff --git a/include/linux/ppp-comp.h b/include/linux/ppp-comp.h
84118index 4ea1d37..80f4b33 100644
84119--- a/include/linux/ppp-comp.h
84120+++ b/include/linux/ppp-comp.h
84121@@ -84,7 +84,7 @@ struct compressor {
84122 struct module *owner;
84123 /* Extra skb space needed by the compressor algorithm */
84124 unsigned int comp_extra;
84125-};
84126+} __do_const;
84127
84128 /*
84129 * The return value from decompress routine is the length of the
84130diff --git a/include/linux/preempt.h b/include/linux/preempt.h
84131index de83b4e..c4b997d 100644
84132--- a/include/linux/preempt.h
84133+++ b/include/linux/preempt.h
84134@@ -27,11 +27,16 @@ extern void preempt_count_sub(int val);
84135 #define preempt_count_dec_and_test() __preempt_count_dec_and_test()
84136 #endif
84137
84138+#define raw_preempt_count_add(val) __preempt_count_add(val)
84139+#define raw_preempt_count_sub(val) __preempt_count_sub(val)
84140+
84141 #define __preempt_count_inc() __preempt_count_add(1)
84142 #define __preempt_count_dec() __preempt_count_sub(1)
84143
84144 #define preempt_count_inc() preempt_count_add(1)
84145+#define raw_preempt_count_inc() raw_preempt_count_add(1)
84146 #define preempt_count_dec() preempt_count_sub(1)
84147+#define raw_preempt_count_dec() raw_preempt_count_sub(1)
84148
84149 #ifdef CONFIG_PREEMPT_COUNT
84150
84151@@ -41,6 +46,12 @@ do { \
84152 barrier(); \
84153 } while (0)
84154
84155+#define raw_preempt_disable() \
84156+do { \
84157+ raw_preempt_count_inc(); \
84158+ barrier(); \
84159+} while (0)
84160+
84161 #define sched_preempt_enable_no_resched() \
84162 do { \
84163 barrier(); \
84164@@ -49,6 +60,12 @@ do { \
84165
84166 #define preempt_enable_no_resched() sched_preempt_enable_no_resched()
84167
84168+#define raw_preempt_enable_no_resched() \
84169+do { \
84170+ barrier(); \
84171+ raw_preempt_count_dec(); \
84172+} while (0)
84173+
84174 #ifdef CONFIG_PREEMPT
84175 #define preempt_enable() \
84176 do { \
84177@@ -113,8 +130,10 @@ do { \
84178 * region.
84179 */
84180 #define preempt_disable() barrier()
84181+#define raw_preempt_disable() barrier()
84182 #define sched_preempt_enable_no_resched() barrier()
84183 #define preempt_enable_no_resched() barrier()
84184+#define raw_preempt_enable_no_resched() barrier()
84185 #define preempt_enable() barrier()
84186 #define preempt_check_resched() do { } while (0)
84187
84188@@ -128,11 +147,13 @@ do { \
84189 /*
84190 * Modules have no business playing preemption tricks.
84191 */
84192+#ifndef CONFIG_PAX_KERNEXEC
84193 #undef sched_preempt_enable_no_resched
84194 #undef preempt_enable_no_resched
84195 #undef preempt_enable_no_resched_notrace
84196 #undef preempt_check_resched
84197 #endif
84198+#endif
84199
84200 #define preempt_set_need_resched() \
84201 do { \
84202diff --git a/include/linux/printk.h b/include/linux/printk.h
84203index d78125f..7f36596 100644
84204--- a/include/linux/printk.h
84205+++ b/include/linux/printk.h
84206@@ -124,6 +124,8 @@ static inline __printf(1, 2) __cold
84207 void early_printk(const char *s, ...) { }
84208 #endif
84209
84210+extern int kptr_restrict;
84211+
84212 #ifdef CONFIG_PRINTK
84213 asmlinkage __printf(5, 0)
84214 int vprintk_emit(int facility, int level,
84215@@ -158,7 +160,6 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
84216
84217 extern int printk_delay_msec;
84218 extern int dmesg_restrict;
84219-extern int kptr_restrict;
84220
84221 extern void wake_up_klogd(void);
84222
84223diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
84224index b97bf2e..f14c92d4 100644
84225--- a/include/linux/proc_fs.h
84226+++ b/include/linux/proc_fs.h
84227@@ -17,8 +17,11 @@ extern void proc_flush_task(struct task_struct *);
84228 extern struct proc_dir_entry *proc_symlink(const char *,
84229 struct proc_dir_entry *, const char *);
84230 extern struct proc_dir_entry *proc_mkdir(const char *, struct proc_dir_entry *);
84231+extern struct proc_dir_entry *proc_mkdir_restrict(const char *, struct proc_dir_entry *);
84232 extern struct proc_dir_entry *proc_mkdir_data(const char *, umode_t,
84233 struct proc_dir_entry *, void *);
84234+extern struct proc_dir_entry *proc_mkdir_data_restrict(const char *, umode_t,
84235+ struct proc_dir_entry *, void *);
84236 extern struct proc_dir_entry *proc_mkdir_mode(const char *, umode_t,
84237 struct proc_dir_entry *);
84238
84239@@ -34,6 +37,19 @@ static inline struct proc_dir_entry *proc_create(
84240 return proc_create_data(name, mode, parent, proc_fops, NULL);
84241 }
84242
84243+static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
84244+ struct proc_dir_entry *parent, const struct file_operations *proc_fops)
84245+{
84246+#ifdef CONFIG_GRKERNSEC_PROC_USER
84247+ return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
84248+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
84249+ return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
84250+#else
84251+ return proc_create_data(name, mode, parent, proc_fops, NULL);
84252+#endif
84253+}
84254+
84255+
84256 extern void proc_set_size(struct proc_dir_entry *, loff_t);
84257 extern void proc_set_user(struct proc_dir_entry *, kuid_t, kgid_t);
84258 extern void *PDE_DATA(const struct inode *);
84259@@ -56,8 +72,12 @@ static inline struct proc_dir_entry *proc_symlink(const char *name,
84260 struct proc_dir_entry *parent,const char *dest) { return NULL;}
84261 static inline struct proc_dir_entry *proc_mkdir(const char *name,
84262 struct proc_dir_entry *parent) {return NULL;}
84263+static inline struct proc_dir_entry *proc_mkdir_restrict(const char *name,
84264+ struct proc_dir_entry *parent) { return NULL; }
84265 static inline struct proc_dir_entry *proc_mkdir_data(const char *name,
84266 umode_t mode, struct proc_dir_entry *parent, void *data) { return NULL; }
84267+static inline struct proc_dir_entry *proc_mkdir_data_restrict(const char *name,
84268+ umode_t mode, struct proc_dir_entry *parent, void *data) { return NULL; }
84269 static inline struct proc_dir_entry *proc_mkdir_mode(const char *name,
84270 umode_t mode, struct proc_dir_entry *parent) { return NULL; }
84271 #define proc_create(name, mode, parent, proc_fops) ({NULL;})
84272@@ -79,7 +99,7 @@ struct net;
84273 static inline struct proc_dir_entry *proc_net_mkdir(
84274 struct net *net, const char *name, struct proc_dir_entry *parent)
84275 {
84276- return proc_mkdir_data(name, 0, parent, net);
84277+ return proc_mkdir_data_restrict(name, 0, parent, net);
84278 }
84279
84280 #endif /* _LINUX_PROC_FS_H */
84281diff --git a/include/linux/proc_ns.h b/include/linux/proc_ns.h
84282index 34a1e10..70f6bde 100644
84283--- a/include/linux/proc_ns.h
84284+++ b/include/linux/proc_ns.h
84285@@ -14,7 +14,7 @@ struct proc_ns_operations {
84286 void (*put)(void *ns);
84287 int (*install)(struct nsproxy *nsproxy, void *ns);
84288 unsigned int (*inum)(void *ns);
84289-};
84290+} __do_const __randomize_layout;
84291
84292 struct proc_ns {
84293 void *ns;
84294diff --git a/include/linux/quota.h b/include/linux/quota.h
84295index 80d345a..9e89a9a 100644
84296--- a/include/linux/quota.h
84297+++ b/include/linux/quota.h
84298@@ -70,7 +70,7 @@ struct kqid { /* Type in which we store the quota identifier */
84299
84300 extern bool qid_eq(struct kqid left, struct kqid right);
84301 extern bool qid_lt(struct kqid left, struct kqid right);
84302-extern qid_t from_kqid(struct user_namespace *to, struct kqid qid);
84303+extern qid_t from_kqid(struct user_namespace *to, struct kqid qid) __intentional_overflow(-1);
84304 extern qid_t from_kqid_munged(struct user_namespace *to, struct kqid qid);
84305 extern bool qid_valid(struct kqid qid);
84306
84307diff --git a/include/linux/random.h b/include/linux/random.h
84308index b05856e..0a9f14e 100644
84309--- a/include/linux/random.h
84310+++ b/include/linux/random.h
84311@@ -9,9 +9,19 @@
84312 #include <uapi/linux/random.h>
84313
84314 extern void add_device_randomness(const void *, unsigned int);
84315+
84316+static inline void add_latent_entropy(void)
84317+{
84318+
84319+#ifdef LATENT_ENTROPY_PLUGIN
84320+ add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
84321+#endif
84322+
84323+}
84324+
84325 extern void add_input_randomness(unsigned int type, unsigned int code,
84326- unsigned int value);
84327-extern void add_interrupt_randomness(int irq, int irq_flags);
84328+ unsigned int value) __latent_entropy;
84329+extern void add_interrupt_randomness(int irq, int irq_flags) __latent_entropy;
84330
84331 extern void get_random_bytes(void *buf, int nbytes);
84332 extern void get_random_bytes_arch(void *buf, int nbytes);
84333@@ -22,10 +32,10 @@ extern int random_int_secret_init(void);
84334 extern const struct file_operations random_fops, urandom_fops;
84335 #endif
84336
84337-unsigned int get_random_int(void);
84338+unsigned int __intentional_overflow(-1) get_random_int(void);
84339 unsigned long randomize_range(unsigned long start, unsigned long end, unsigned long len);
84340
84341-u32 prandom_u32(void);
84342+u32 prandom_u32(void) __intentional_overflow(-1);
84343 void prandom_bytes(void *buf, size_t nbytes);
84344 void prandom_seed(u32 seed);
84345 void prandom_reseed_late(void);
84346@@ -37,6 +47,11 @@ struct rnd_state {
84347 u32 prandom_u32_state(struct rnd_state *state);
84348 void prandom_bytes_state(struct rnd_state *state, void *buf, size_t nbytes);
84349
84350+static inline unsigned long __intentional_overflow(-1) pax_get_random_long(void)
84351+{
84352+ return prandom_u32() + (sizeof(long) > 4 ? (unsigned long)prandom_u32() << 32 : 0);
84353+}
84354+
84355 /**
84356 * prandom_u32_max - returns a pseudo-random number in interval [0, ep_ro)
84357 * @ep_ro: right open interval endpoint
84358@@ -49,7 +64,7 @@ void prandom_bytes_state(struct rnd_state *state, void *buf, size_t nbytes);
84359 *
84360 * Returns: pseudo-random number in interval [0, ep_ro)
84361 */
84362-static inline u32 prandom_u32_max(u32 ep_ro)
84363+static inline u32 __intentional_overflow(-1) prandom_u32_max(u32 ep_ro)
84364 {
84365 return (u32)(((u64) prandom_u32() * ep_ro) >> 32);
84366 }
84367diff --git a/include/linux/rbtree_augmented.h b/include/linux/rbtree_augmented.h
84368index 378c5ee..aa84a47 100644
84369--- a/include/linux/rbtree_augmented.h
84370+++ b/include/linux/rbtree_augmented.h
84371@@ -90,7 +90,9 @@ rbname ## _rotate(struct rb_node *rb_old, struct rb_node *rb_new) \
84372 old->rbaugmented = rbcompute(old); \
84373 } \
84374 rbstatic const struct rb_augment_callbacks rbname = { \
84375- rbname ## _propagate, rbname ## _copy, rbname ## _rotate \
84376+ .propagate = rbname ## _propagate, \
84377+ .copy = rbname ## _copy, \
84378+ .rotate = rbname ## _rotate \
84379 };
84380
84381
84382diff --git a/include/linux/rculist.h b/include/linux/rculist.h
84383index 372ad5e..d4373f8 100644
84384--- a/include/linux/rculist.h
84385+++ b/include/linux/rculist.h
84386@@ -29,8 +29,8 @@
84387 */
84388 static inline void INIT_LIST_HEAD_RCU(struct list_head *list)
84389 {
84390- ACCESS_ONCE(list->next) = list;
84391- ACCESS_ONCE(list->prev) = list;
84392+ ACCESS_ONCE_RW(list->next) = list;
84393+ ACCESS_ONCE_RW(list->prev) = list;
84394 }
84395
84396 /*
84397@@ -59,6 +59,9 @@ void __list_add_rcu(struct list_head *new,
84398 struct list_head *prev, struct list_head *next);
84399 #endif
84400
84401+void __pax_list_add_rcu(struct list_head *new,
84402+ struct list_head *prev, struct list_head *next);
84403+
84404 /**
84405 * list_add_rcu - add a new entry to rcu-protected list
84406 * @new: new entry to be added
84407@@ -80,6 +83,11 @@ static inline void list_add_rcu(struct list_head *new, struct list_head *head)
84408 __list_add_rcu(new, head, head->next);
84409 }
84410
84411+static inline void pax_list_add_rcu(struct list_head *new, struct list_head *head)
84412+{
84413+ __pax_list_add_rcu(new, head, head->next);
84414+}
84415+
84416 /**
84417 * list_add_tail_rcu - add a new entry to rcu-protected list
84418 * @new: new entry to be added
84419@@ -102,6 +110,12 @@ static inline void list_add_tail_rcu(struct list_head *new,
84420 __list_add_rcu(new, head->prev, head);
84421 }
84422
84423+static inline void pax_list_add_tail_rcu(struct list_head *new,
84424+ struct list_head *head)
84425+{
84426+ __pax_list_add_rcu(new, head->prev, head);
84427+}
84428+
84429 /**
84430 * list_del_rcu - deletes entry from list without re-initialization
84431 * @entry: the element to delete from the list.
84432@@ -132,6 +146,8 @@ static inline void list_del_rcu(struct list_head *entry)
84433 entry->prev = LIST_POISON2;
84434 }
84435
84436+extern void pax_list_del_rcu(struct list_head *entry);
84437+
84438 /**
84439 * hlist_del_init_rcu - deletes entry from hash list with re-initialization
84440 * @n: the element to delete from the hash list.
84441diff --git a/include/linux/rcupdate.h b/include/linux/rcupdate.h
84442index 53ff1a7..c40f0ab 100644
84443--- a/include/linux/rcupdate.h
84444+++ b/include/linux/rcupdate.h
84445@@ -332,7 +332,7 @@ extern struct srcu_struct tasks_rcu_exit_srcu;
84446 #define rcu_note_voluntary_context_switch(t) \
84447 do { \
84448 if (ACCESS_ONCE((t)->rcu_tasks_holdout)) \
84449- ACCESS_ONCE((t)->rcu_tasks_holdout) = false; \
84450+ ACCESS_ONCE_RW((t)->rcu_tasks_holdout) = false; \
84451 } while (0)
84452 #else /* #ifdef CONFIG_TASKS_RCU */
84453 #define TASKS_RCU(x) do { } while (0)
84454diff --git a/include/linux/reboot.h b/include/linux/reboot.h
84455index 67fc8fc..a90f7d8 100644
84456--- a/include/linux/reboot.h
84457+++ b/include/linux/reboot.h
84458@@ -47,9 +47,9 @@ extern void do_kernel_restart(char *cmd);
84459 */
84460
84461 extern void migrate_to_reboot_cpu(void);
84462-extern void machine_restart(char *cmd);
84463-extern void machine_halt(void);
84464-extern void machine_power_off(void);
84465+extern void machine_restart(char *cmd) __noreturn;
84466+extern void machine_halt(void) __noreturn;
84467+extern void machine_power_off(void) __noreturn;
84468
84469 extern void machine_shutdown(void);
84470 struct pt_regs;
84471@@ -60,9 +60,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
84472 */
84473
84474 extern void kernel_restart_prepare(char *cmd);
84475-extern void kernel_restart(char *cmd);
84476-extern void kernel_halt(void);
84477-extern void kernel_power_off(void);
84478+extern void kernel_restart(char *cmd) __noreturn;
84479+extern void kernel_halt(void) __noreturn;
84480+extern void kernel_power_off(void) __noreturn;
84481
84482 extern int C_A_D; /* for sysctl */
84483 void ctrl_alt_del(void);
84484@@ -76,7 +76,7 @@ extern int orderly_poweroff(bool force);
84485 * Emergency restart, callable from an interrupt handler.
84486 */
84487
84488-extern void emergency_restart(void);
84489+extern void emergency_restart(void) __noreturn;
84490 #include <asm/emergency-restart.h>
84491
84492 #endif /* _LINUX_REBOOT_H */
84493diff --git a/include/linux/regset.h b/include/linux/regset.h
84494index 8e0c9fe..ac4d221 100644
84495--- a/include/linux/regset.h
84496+++ b/include/linux/regset.h
84497@@ -161,7 +161,8 @@ struct user_regset {
84498 unsigned int align;
84499 unsigned int bias;
84500 unsigned int core_note_type;
84501-};
84502+} __do_const;
84503+typedef struct user_regset __no_const user_regset_no_const;
84504
84505 /**
84506 * struct user_regset_view - available regsets
84507diff --git a/include/linux/relay.h b/include/linux/relay.h
84508index d7c8359..818daf5 100644
84509--- a/include/linux/relay.h
84510+++ b/include/linux/relay.h
84511@@ -157,7 +157,7 @@ struct rchan_callbacks
84512 * The callback should return 0 if successful, negative if not.
84513 */
84514 int (*remove_buf_file)(struct dentry *dentry);
84515-};
84516+} __no_const;
84517
84518 /*
84519 * CONFIG_RELAY kernel API, kernel/relay.c
84520diff --git a/include/linux/rio.h b/include/linux/rio.h
84521index 6bda06f..bf39a9b 100644
84522--- a/include/linux/rio.h
84523+++ b/include/linux/rio.h
84524@@ -358,7 +358,7 @@ struct rio_ops {
84525 int (*map_inb)(struct rio_mport *mport, dma_addr_t lstart,
84526 u64 rstart, u32 size, u32 flags);
84527 void (*unmap_inb)(struct rio_mport *mport, dma_addr_t lstart);
84528-};
84529+} __no_const;
84530
84531 #define RIO_RESOURCE_MEM 0x00000100
84532 #define RIO_RESOURCE_DOORBELL 0x00000200
84533diff --git a/include/linux/rmap.h b/include/linux/rmap.h
84534index c0c2bce..4813524 100644
84535--- a/include/linux/rmap.h
84536+++ b/include/linux/rmap.h
84537@@ -144,8 +144,8 @@ static inline void anon_vma_unlock_read(struct anon_vma *anon_vma)
84538 void anon_vma_init(void); /* create anon_vma_cachep */
84539 int anon_vma_prepare(struct vm_area_struct *);
84540 void unlink_anon_vmas(struct vm_area_struct *);
84541-int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
84542-int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
84543+int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
84544+int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
84545
84546 static inline void anon_vma_merge(struct vm_area_struct *vma,
84547 struct vm_area_struct *next)
84548diff --git a/include/linux/scatterlist.h b/include/linux/scatterlist.h
84549index ed8f9e7..999bc96 100644
84550--- a/include/linux/scatterlist.h
84551+++ b/include/linux/scatterlist.h
84552@@ -1,6 +1,7 @@
84553 #ifndef _LINUX_SCATTERLIST_H
84554 #define _LINUX_SCATTERLIST_H
84555
84556+#include <linux/sched.h>
84557 #include <linux/string.h>
84558 #include <linux/bug.h>
84559 #include <linux/mm.h>
84560@@ -114,6 +115,12 @@ static inline void sg_set_buf(struct scatterlist *sg, const void *buf,
84561 #ifdef CONFIG_DEBUG_SG
84562 BUG_ON(!virt_addr_valid(buf));
84563 #endif
84564+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
84565+ if (object_starts_on_stack(buf)) {
84566+ void *adjbuf = buf - current->stack + current->lowmem_stack;
84567+ sg_set_page(sg, virt_to_page(adjbuf), buflen, offset_in_page(adjbuf));
84568+ } else
84569+#endif
84570 sg_set_page(sg, virt_to_page(buf), buflen, offset_in_page(buf));
84571 }
84572
84573diff --git a/include/linux/sched.h b/include/linux/sched.h
84574index 5e344bb..0743255 100644
84575--- a/include/linux/sched.h
84576+++ b/include/linux/sched.h
84577@@ -133,6 +133,7 @@ struct fs_struct;
84578 struct perf_event_context;
84579 struct blk_plug;
84580 struct filename;
84581+struct linux_binprm;
84582
84583 #define VMACACHE_BITS 2
84584 #define VMACACHE_SIZE (1U << VMACACHE_BITS)
84585@@ -376,7 +377,7 @@ extern char __sched_text_start[], __sched_text_end[];
84586 extern int in_sched_functions(unsigned long addr);
84587
84588 #define MAX_SCHEDULE_TIMEOUT LONG_MAX
84589-extern signed long schedule_timeout(signed long timeout);
84590+extern signed long schedule_timeout(signed long timeout) __intentional_overflow(-1);
84591 extern signed long schedule_timeout_interruptible(signed long timeout);
84592 extern signed long schedule_timeout_killable(signed long timeout);
84593 extern signed long schedule_timeout_uninterruptible(signed long timeout);
84594@@ -387,6 +388,19 @@ struct nsproxy;
84595 struct user_namespace;
84596
84597 #ifdef CONFIG_MMU
84598+
84599+#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
84600+extern unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags);
84601+#else
84602+static inline unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
84603+{
84604+ return 0;
84605+}
84606+#endif
84607+
84608+extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset);
84609+extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset);
84610+
84611 extern void arch_pick_mmap_layout(struct mm_struct *mm);
84612 extern unsigned long
84613 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
84614@@ -685,6 +699,17 @@ struct signal_struct {
84615 #ifdef CONFIG_TASKSTATS
84616 struct taskstats *stats;
84617 #endif
84618+
84619+#ifdef CONFIG_GRKERNSEC
84620+ u32 curr_ip;
84621+ u32 saved_ip;
84622+ u32 gr_saddr;
84623+ u32 gr_daddr;
84624+ u16 gr_sport;
84625+ u16 gr_dport;
84626+ u8 used_accept:1;
84627+#endif
84628+
84629 #ifdef CONFIG_AUDIT
84630 unsigned audit_tty;
84631 unsigned audit_tty_log_passwd;
84632@@ -711,7 +736,7 @@ struct signal_struct {
84633 struct mutex cred_guard_mutex; /* guard against foreign influences on
84634 * credential calculations
84635 * (notably. ptrace) */
84636-};
84637+} __randomize_layout;
84638
84639 /*
84640 * Bits in flags field of signal_struct.
84641@@ -764,6 +789,14 @@ struct user_struct {
84642 struct key *session_keyring; /* UID's default session keyring */
84643 #endif
84644
84645+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
84646+ unsigned char kernel_banned;
84647+#endif
84648+#ifdef CONFIG_GRKERNSEC_BRUTE
84649+ unsigned char suid_banned;
84650+ unsigned long suid_ban_expires;
84651+#endif
84652+
84653 /* Hash table maintenance information */
84654 struct hlist_node uidhash_node;
84655 kuid_t uid;
84656@@ -771,7 +804,7 @@ struct user_struct {
84657 #ifdef CONFIG_PERF_EVENTS
84658 atomic_long_t locked_vm;
84659 #endif
84660-};
84661+} __randomize_layout;
84662
84663 extern int uids_sysfs_init(void);
84664
84665@@ -1235,6 +1268,9 @@ enum perf_event_task_context {
84666 struct task_struct {
84667 volatile long state; /* -1 unrunnable, 0 runnable, >0 stopped */
84668 void *stack;
84669+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
84670+ void *lowmem_stack;
84671+#endif
84672 atomic_t usage;
84673 unsigned int flags; /* per process flags, defined below */
84674 unsigned int ptrace;
84675@@ -1362,8 +1398,8 @@ struct task_struct {
84676 struct list_head thread_node;
84677
84678 struct completion *vfork_done; /* for vfork() */
84679- int __user *set_child_tid; /* CLONE_CHILD_SETTID */
84680- int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
84681+ pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
84682+ pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
84683
84684 cputime_t utime, stime, utimescaled, stimescaled;
84685 cputime_t gtime;
84686@@ -1388,11 +1424,6 @@ struct task_struct {
84687 struct task_cputime cputime_expires;
84688 struct list_head cpu_timers[3];
84689
84690-/* process credentials */
84691- const struct cred __rcu *real_cred; /* objective and real subjective task
84692- * credentials (COW) */
84693- const struct cred __rcu *cred; /* effective (overridable) subjective task
84694- * credentials (COW) */
84695 char comm[TASK_COMM_LEN]; /* executable name excluding path
84696 - access with [gs]et_task_comm (which lock
84697 it with task_lock())
84698@@ -1410,6 +1441,10 @@ struct task_struct {
84699 #endif
84700 /* CPU-specific state of this task */
84701 struct thread_struct thread;
84702+/* thread_info moved to task_struct */
84703+#ifdef CONFIG_X86
84704+ struct thread_info tinfo;
84705+#endif
84706 /* filesystem information */
84707 struct fs_struct *fs;
84708 /* open file information */
84709@@ -1484,6 +1519,10 @@ struct task_struct {
84710 gfp_t lockdep_reclaim_gfp;
84711 #endif
84712
84713+/* process credentials */
84714+ const struct cred __rcu *real_cred; /* objective and real subjective task
84715+ * credentials (COW) */
84716+
84717 /* journalling filesystem info */
84718 void *journal_info;
84719
84720@@ -1522,6 +1561,10 @@ struct task_struct {
84721 /* cg_list protected by css_set_lock and tsk->alloc_lock */
84722 struct list_head cg_list;
84723 #endif
84724+
84725+ const struct cred __rcu *cred; /* effective (overridable) subjective task
84726+ * credentials (COW) */
84727+
84728 #ifdef CONFIG_FUTEX
84729 struct robust_list_head __user *robust_list;
84730 #ifdef CONFIG_COMPAT
84731@@ -1635,7 +1678,7 @@ struct task_struct {
84732 * Number of functions that haven't been traced
84733 * because of depth overrun.
84734 */
84735- atomic_t trace_overrun;
84736+ atomic_unchecked_t trace_overrun;
84737 /* Pause for the tracing */
84738 atomic_t tracing_graph_pause;
84739 #endif
84740@@ -1661,7 +1704,78 @@ struct task_struct {
84741 unsigned int sequential_io;
84742 unsigned int sequential_io_avg;
84743 #endif
84744-};
84745+
84746+#ifdef CONFIG_GRKERNSEC
84747+ /* grsecurity */
84748+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
84749+ u64 exec_id;
84750+#endif
84751+#ifdef CONFIG_GRKERNSEC_SETXID
84752+ const struct cred *delayed_cred;
84753+#endif
84754+ struct dentry *gr_chroot_dentry;
84755+ struct acl_subject_label *acl;
84756+ struct acl_subject_label *tmpacl;
84757+ struct acl_role_label *role;
84758+ struct file *exec_file;
84759+ unsigned long brute_expires;
84760+ u16 acl_role_id;
84761+ u8 inherited;
84762+ /* is this the task that authenticated to the special role */
84763+ u8 acl_sp_role;
84764+ u8 is_writable;
84765+ u8 brute;
84766+ u8 gr_is_chrooted;
84767+#endif
84768+
84769+} __randomize_layout;
84770+
84771+#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
84772+#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
84773+#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
84774+#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
84775+/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
84776+#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
84777+
84778+#ifdef CONFIG_PAX_SOFTMODE
84779+extern int pax_softmode;
84780+#endif
84781+
84782+extern int pax_check_flags(unsigned long *);
84783+#define PAX_PARSE_FLAGS_FALLBACK (~0UL)
84784+
84785+/* if tsk != current then task_lock must be held on it */
84786+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
84787+static inline unsigned long pax_get_flags(struct task_struct *tsk)
84788+{
84789+ if (likely(tsk->mm))
84790+ return tsk->mm->pax_flags;
84791+ else
84792+ return 0UL;
84793+}
84794+
84795+/* if tsk != current then task_lock must be held on it */
84796+static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
84797+{
84798+ if (likely(tsk->mm)) {
84799+ tsk->mm->pax_flags = flags;
84800+ return 0;
84801+ }
84802+ return -EINVAL;
84803+}
84804+#endif
84805+
84806+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
84807+extern void pax_set_initial_flags(struct linux_binprm *bprm);
84808+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
84809+extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
84810+#endif
84811+
84812+struct path;
84813+extern char *pax_get_path(const struct path *path, char *buf, int buflen);
84814+extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
84815+extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
84816+extern void pax_report_refcount_overflow(struct pt_regs *regs);
84817
84818 /* Future-safe accessor for struct task_struct's cpus_allowed. */
84819 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
84820@@ -1743,7 +1857,7 @@ struct pid_namespace;
84821 pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
84822 struct pid_namespace *ns);
84823
84824-static inline pid_t task_pid_nr(struct task_struct *tsk)
84825+static inline pid_t task_pid_nr(const struct task_struct *tsk)
84826 {
84827 return tsk->pid;
84828 }
84829@@ -2106,6 +2220,25 @@ extern u64 sched_clock_cpu(int cpu);
84830
84831 extern void sched_clock_init(void);
84832
84833+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
84834+static inline void populate_stack(void)
84835+{
84836+ struct task_struct *curtask = current;
84837+ int c;
84838+ int *ptr = curtask->stack;
84839+ int *end = curtask->stack + THREAD_SIZE;
84840+
84841+ while (ptr < end) {
84842+ c = *(volatile int *)ptr;
84843+ ptr += PAGE_SIZE/sizeof(int);
84844+ }
84845+}
84846+#else
84847+static inline void populate_stack(void)
84848+{
84849+}
84850+#endif
84851+
84852 #ifndef CONFIG_HAVE_UNSTABLE_SCHED_CLOCK
84853 static inline void sched_clock_tick(void)
84854 {
84855@@ -2239,7 +2372,9 @@ void yield(void);
84856 extern struct exec_domain default_exec_domain;
84857
84858 union thread_union {
84859+#ifndef CONFIG_X86
84860 struct thread_info thread_info;
84861+#endif
84862 unsigned long stack[THREAD_SIZE/sizeof(long)];
84863 };
84864
84865@@ -2272,6 +2407,7 @@ extern struct pid_namespace init_pid_ns;
84866 */
84867
84868 extern struct task_struct *find_task_by_vpid(pid_t nr);
84869+extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
84870 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
84871 struct pid_namespace *ns);
84872
84873@@ -2436,7 +2572,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
84874 extern void exit_itimers(struct signal_struct *);
84875 extern void flush_itimer_signals(void);
84876
84877-extern void do_group_exit(int);
84878+extern __noreturn void do_group_exit(int);
84879
84880 extern int do_execve(struct filename *,
84881 const char __user * const __user *,
84882@@ -2653,9 +2789,9 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
84883 #define task_stack_end_corrupted(task) \
84884 (*(end_of_stack(task)) != STACK_END_MAGIC)
84885
84886-static inline int object_is_on_stack(void *obj)
84887+static inline int object_starts_on_stack(const void *obj)
84888 {
84889- void *stack = task_stack_page(current);
84890+ const void *stack = task_stack_page(current);
84891
84892 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
84893 }
84894diff --git a/include/linux/sched/sysctl.h b/include/linux/sched/sysctl.h
84895index 596a0e0..bea77ec 100644
84896--- a/include/linux/sched/sysctl.h
84897+++ b/include/linux/sched/sysctl.h
84898@@ -34,6 +34,7 @@ enum { sysctl_hung_task_timeout_secs = 0 };
84899 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
84900
84901 extern int sysctl_max_map_count;
84902+extern unsigned long sysctl_heap_stack_gap;
84903
84904 extern unsigned int sysctl_sched_latency;
84905 extern unsigned int sysctl_sched_min_granularity;
84906diff --git a/include/linux/security.h b/include/linux/security.h
84907index ba96471..74fb3f6 100644
84908--- a/include/linux/security.h
84909+++ b/include/linux/security.h
84910@@ -27,6 +27,7 @@
84911 #include <linux/slab.h>
84912 #include <linux/err.h>
84913 #include <linux/string.h>
84914+#include <linux/grsecurity.h>
84915
84916 struct linux_binprm;
84917 struct cred;
84918@@ -116,8 +117,6 @@ struct seq_file;
84919
84920 extern int cap_netlink_send(struct sock *sk, struct sk_buff *skb);
84921
84922-void reset_security_ops(void);
84923-
84924 #ifdef CONFIG_MMU
84925 extern unsigned long mmap_min_addr;
84926 extern unsigned long dac_mmap_min_addr;
84927@@ -1729,7 +1728,7 @@ struct security_operations {
84928 struct audit_context *actx);
84929 void (*audit_rule_free) (void *lsmrule);
84930 #endif /* CONFIG_AUDIT */
84931-};
84932+} __randomize_layout;
84933
84934 /* prototypes */
84935 extern int security_init(void);
84936diff --git a/include/linux/semaphore.h b/include/linux/semaphore.h
84937index dc368b8..e895209 100644
84938--- a/include/linux/semaphore.h
84939+++ b/include/linux/semaphore.h
84940@@ -37,7 +37,7 @@ static inline void sema_init(struct semaphore *sem, int val)
84941 }
84942
84943 extern void down(struct semaphore *sem);
84944-extern int __must_check down_interruptible(struct semaphore *sem);
84945+extern int __must_check down_interruptible(struct semaphore *sem) __intentional_overflow(-1);
84946 extern int __must_check down_killable(struct semaphore *sem);
84947 extern int __must_check down_trylock(struct semaphore *sem);
84948 extern int __must_check down_timeout(struct semaphore *sem, long jiffies);
84949diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
84950index 52e0097..383f21d 100644
84951--- a/include/linux/seq_file.h
84952+++ b/include/linux/seq_file.h
84953@@ -27,6 +27,9 @@ struct seq_file {
84954 struct mutex lock;
84955 const struct seq_operations *op;
84956 int poll_event;
84957+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
84958+ u64 exec_id;
84959+#endif
84960 #ifdef CONFIG_USER_NS
84961 struct user_namespace *user_ns;
84962 #endif
84963@@ -39,6 +42,7 @@ struct seq_operations {
84964 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
84965 int (*show) (struct seq_file *m, void *v);
84966 };
84967+typedef struct seq_operations __no_const seq_operations_no_const;
84968
84969 #define SEQ_SKIP 1
84970
84971@@ -96,6 +100,7 @@ void seq_pad(struct seq_file *m, char c);
84972
84973 char *mangle_path(char *s, const char *p, const char *esc);
84974 int seq_open(struct file *, const struct seq_operations *);
84975+int seq_open_restrict(struct file *, const struct seq_operations *);
84976 ssize_t seq_read(struct file *, char __user *, size_t, loff_t *);
84977 loff_t seq_lseek(struct file *, loff_t, int);
84978 int seq_release(struct inode *, struct file *);
84979@@ -138,6 +143,7 @@ static inline int seq_nodemask_list(struct seq_file *m, nodemask_t *mask)
84980 }
84981
84982 int single_open(struct file *, int (*)(struct seq_file *, void *), void *);
84983+int single_open_restrict(struct file *, int (*)(struct seq_file *, void *), void *);
84984 int single_open_size(struct file *, int (*)(struct seq_file *, void *), void *, size_t);
84985 int single_release(struct inode *, struct file *);
84986 void *__seq_open_private(struct file *, const struct seq_operations *, int);
84987diff --git a/include/linux/shm.h b/include/linux/shm.h
84988index 6fb8016..ab4465e 100644
84989--- a/include/linux/shm.h
84990+++ b/include/linux/shm.h
84991@@ -22,6 +22,10 @@ struct shmid_kernel /* private to the kernel */
84992 /* The task created the shm object. NULL if the task is dead. */
84993 struct task_struct *shm_creator;
84994 struct list_head shm_clist; /* list by creator */
84995+#ifdef CONFIG_GRKERNSEC
84996+ u64 shm_createtime;
84997+ pid_t shm_lapid;
84998+#endif
84999 };
85000
85001 /* shm_mode upper byte flags */
85002diff --git a/include/linux/signal.h b/include/linux/signal.h
85003index ab1e039..ad4229e 100644
85004--- a/include/linux/signal.h
85005+++ b/include/linux/signal.h
85006@@ -289,7 +289,7 @@ static inline void allow_signal(int sig)
85007 * know it'll be handled, so that they don't get converted to
85008 * SIGKILL or just silently dropped.
85009 */
85010- kernel_sigaction(sig, (__force __sighandler_t)2);
85011+ kernel_sigaction(sig, (__force_user __sighandler_t)2);
85012 }
85013
85014 static inline void disallow_signal(int sig)
85015diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
85016index 6c8b6f6..5a0f4bd 100644
85017--- a/include/linux/skbuff.h
85018+++ b/include/linux/skbuff.h
85019@@ -773,7 +773,7 @@ bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
85020 struct sk_buff *__alloc_skb(unsigned int size, gfp_t priority, int flags,
85021 int node);
85022 struct sk_buff *build_skb(void *data, unsigned int frag_size);
85023-static inline struct sk_buff *alloc_skb(unsigned int size,
85024+static inline struct sk_buff * __intentional_overflow(0) alloc_skb(unsigned int size,
85025 gfp_t priority)
85026 {
85027 return __alloc_skb(size, priority, 0, NUMA_NO_NODE);
85028@@ -1962,7 +1962,7 @@ static inline u32 skb_inner_network_header_len(const struct sk_buff *skb)
85029 return skb->inner_transport_header - skb->inner_network_header;
85030 }
85031
85032-static inline int skb_network_offset(const struct sk_buff *skb)
85033+static inline int __intentional_overflow(0) skb_network_offset(const struct sk_buff *skb)
85034 {
85035 return skb_network_header(skb) - skb->data;
85036 }
85037@@ -2022,7 +2022,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
85038 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
85039 */
85040 #ifndef NET_SKB_PAD
85041-#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
85042+#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
85043 #endif
85044
85045 int ___pskb_trim(struct sk_buff *skb, unsigned int len);
85046@@ -2629,7 +2629,7 @@ struct sk_buff *skb_recv_datagram(struct sock *sk, unsigned flags, int noblock,
85047 int *err);
85048 unsigned int datagram_poll(struct file *file, struct socket *sock,
85049 struct poll_table_struct *wait);
85050-int skb_copy_datagram_iovec(const struct sk_buff *from, int offset,
85051+int __intentional_overflow(0) skb_copy_datagram_iovec(const struct sk_buff *from, int offset,
85052 struct iovec *to, int size);
85053 int skb_copy_and_csum_datagram_iovec(struct sk_buff *skb, int hlen,
85054 struct iovec *iov);
85055@@ -3091,6 +3091,9 @@ static inline void nf_reset(struct sk_buff *skb)
85056 nf_bridge_put(skb->nf_bridge);
85057 skb->nf_bridge = NULL;
85058 #endif
85059+#if IS_ENABLED(CONFIG_NETFILTER_XT_TARGET_TRACE)
85060+ skb->nf_trace = 0;
85061+#endif
85062 }
85063
85064 static inline void nf_reset_trace(struct sk_buff *skb)
85065diff --git a/include/linux/slab.h b/include/linux/slab.h
85066index c265bec..4867d28 100644
85067--- a/include/linux/slab.h
85068+++ b/include/linux/slab.h
85069@@ -14,15 +14,29 @@
85070 #include <linux/gfp.h>
85071 #include <linux/types.h>
85072 #include <linux/workqueue.h>
85073-
85074+#include <linux/err.h>
85075
85076 /*
85077 * Flags to pass to kmem_cache_create().
85078 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
85079 */
85080 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
85081+
85082+#ifdef CONFIG_PAX_USERCOPY_SLABS
85083+#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
85084+#else
85085+#define SLAB_USERCOPY 0x00000000UL
85086+#endif
85087+
85088 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
85089 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
85090+
85091+#ifdef CONFIG_PAX_MEMORY_SANITIZE
85092+#define SLAB_NO_SANITIZE 0x00001000UL /* PaX: Do not sanitize objs on free */
85093+#else
85094+#define SLAB_NO_SANITIZE 0x00000000UL
85095+#endif
85096+
85097 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
85098 #define SLAB_CACHE_DMA 0x00004000UL /* Use GFP_DMA memory */
85099 #define SLAB_STORE_USER 0x00010000UL /* DEBUG: Store the last owner for bug hunting */
85100@@ -98,10 +112,13 @@
85101 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
85102 * Both make kfree a no-op.
85103 */
85104-#define ZERO_SIZE_PTR ((void *)16)
85105+#define ZERO_SIZE_PTR \
85106+({ \
85107+ BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
85108+ (void *)(-MAX_ERRNO-1L); \
85109+})
85110
85111-#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
85112- (unsigned long)ZERO_SIZE_PTR)
85113+#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
85114
85115 #include <linux/kmemleak.h>
85116
85117@@ -144,6 +161,8 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
85118 void kfree(const void *);
85119 void kzfree(const void *);
85120 size_t ksize(const void *);
85121+const char *check_heap_object(const void *ptr, unsigned long n);
85122+bool is_usercopy_object(const void *ptr);
85123
85124 /*
85125 * Some archs want to perform DMA into kmalloc caches and need a guaranteed
85126@@ -236,6 +255,10 @@ extern struct kmem_cache *kmalloc_caches[KMALLOC_SHIFT_HIGH + 1];
85127 extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
85128 #endif
85129
85130+#ifdef CONFIG_PAX_USERCOPY_SLABS
85131+extern struct kmem_cache *kmalloc_usercopy_caches[KMALLOC_SHIFT_HIGH + 1];
85132+#endif
85133+
85134 /*
85135 * Figure out which kmalloc slab an allocation of a certain size
85136 * belongs to.
85137@@ -244,7 +267,7 @@ extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
85138 * 2 = 120 .. 192 bytes
85139 * n = 2^(n-1) .. 2^n -1
85140 */
85141-static __always_inline int kmalloc_index(size_t size)
85142+static __always_inline __size_overflow(1) int kmalloc_index(size_t size)
85143 {
85144 if (!size)
85145 return 0;
85146@@ -287,11 +310,11 @@ static __always_inline int kmalloc_index(size_t size)
85147 }
85148 #endif /* !CONFIG_SLOB */
85149
85150-void *__kmalloc(size_t size, gfp_t flags);
85151+void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1);
85152 void *kmem_cache_alloc(struct kmem_cache *, gfp_t flags);
85153
85154 #ifdef CONFIG_NUMA
85155-void *__kmalloc_node(size_t size, gfp_t flags, int node);
85156+void *__kmalloc_node(size_t size, gfp_t flags, int node) __alloc_size(1);
85157 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
85158 #else
85159 static __always_inline void *__kmalloc_node(size_t size, gfp_t flags, int node)
85160diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
85161index b869d16..1453c73 100644
85162--- a/include/linux/slab_def.h
85163+++ b/include/linux/slab_def.h
85164@@ -40,7 +40,7 @@ struct kmem_cache {
85165 /* 4) cache creation/removal */
85166 const char *name;
85167 struct list_head list;
85168- int refcount;
85169+ atomic_t refcount;
85170 int object_size;
85171 int align;
85172
85173@@ -56,10 +56,14 @@ struct kmem_cache {
85174 unsigned long node_allocs;
85175 unsigned long node_frees;
85176 unsigned long node_overflow;
85177- atomic_t allochit;
85178- atomic_t allocmiss;
85179- atomic_t freehit;
85180- atomic_t freemiss;
85181+ atomic_unchecked_t allochit;
85182+ atomic_unchecked_t allocmiss;
85183+ atomic_unchecked_t freehit;
85184+ atomic_unchecked_t freemiss;
85185+#ifdef CONFIG_PAX_MEMORY_SANITIZE
85186+ atomic_unchecked_t sanitized;
85187+ atomic_unchecked_t not_sanitized;
85188+#endif
85189
85190 /*
85191 * If debugging is enabled, then the allocator can add additional
85192diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
85193index d82abd4..408c3a0 100644
85194--- a/include/linux/slub_def.h
85195+++ b/include/linux/slub_def.h
85196@@ -74,7 +74,7 @@ struct kmem_cache {
85197 struct kmem_cache_order_objects max;
85198 struct kmem_cache_order_objects min;
85199 gfp_t allocflags; /* gfp flags to use on each alloc */
85200- int refcount; /* Refcount for slab cache destroy */
85201+ atomic_t refcount; /* Refcount for slab cache destroy */
85202 void (*ctor)(void *);
85203 int inuse; /* Offset to metadata */
85204 int align; /* Alignment */
85205diff --git a/include/linux/smp.h b/include/linux/smp.h
85206index 93dff5f..933c561 100644
85207--- a/include/linux/smp.h
85208+++ b/include/linux/smp.h
85209@@ -176,7 +176,9 @@ static inline void wake_up_all_idle_cpus(void) { }
85210 #endif
85211
85212 #define get_cpu() ({ preempt_disable(); smp_processor_id(); })
85213+#define raw_get_cpu() ({ raw_preempt_disable(); raw_smp_processor_id(); })
85214 #define put_cpu() preempt_enable()
85215+#define raw_put_cpu_no_resched() raw_preempt_enable_no_resched()
85216
85217 /*
85218 * Callback to arch code if there's nosmp or maxcpus=0 on the
85219diff --git a/include/linux/sock_diag.h b/include/linux/sock_diag.h
85220index 46cca4c..3323536 100644
85221--- a/include/linux/sock_diag.h
85222+++ b/include/linux/sock_diag.h
85223@@ -11,7 +11,7 @@ struct sock;
85224 struct sock_diag_handler {
85225 __u8 family;
85226 int (*dump)(struct sk_buff *skb, struct nlmsghdr *nlh);
85227-};
85228+} __do_const;
85229
85230 int sock_diag_register(const struct sock_diag_handler *h);
85231 void sock_diag_unregister(const struct sock_diag_handler *h);
85232diff --git a/include/linux/sonet.h b/include/linux/sonet.h
85233index 680f9a3..f13aeb0 100644
85234--- a/include/linux/sonet.h
85235+++ b/include/linux/sonet.h
85236@@ -7,7 +7,7 @@
85237 #include <uapi/linux/sonet.h>
85238
85239 struct k_sonet_stats {
85240-#define __HANDLE_ITEM(i) atomic_t i
85241+#define __HANDLE_ITEM(i) atomic_unchecked_t i
85242 __SONET_ITEMS
85243 #undef __HANDLE_ITEM
85244 };
85245diff --git a/include/linux/sunrpc/addr.h b/include/linux/sunrpc/addr.h
85246index 07d8e53..dc934c9 100644
85247--- a/include/linux/sunrpc/addr.h
85248+++ b/include/linux/sunrpc/addr.h
85249@@ -23,9 +23,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
85250 {
85251 switch (sap->sa_family) {
85252 case AF_INET:
85253- return ntohs(((struct sockaddr_in *)sap)->sin_port);
85254+ return ntohs(((const struct sockaddr_in *)sap)->sin_port);
85255 case AF_INET6:
85256- return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
85257+ return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
85258 }
85259 return 0;
85260 }
85261@@ -58,7 +58,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
85262 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
85263 const struct sockaddr *src)
85264 {
85265- const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
85266+ const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
85267 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
85268
85269 dsin->sin_family = ssin->sin_family;
85270@@ -164,7 +164,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
85271 if (sa->sa_family != AF_INET6)
85272 return 0;
85273
85274- return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
85275+ return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
85276 }
85277
85278 #endif /* _LINUX_SUNRPC_ADDR_H */
85279diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
85280index 70736b9..37f33db 100644
85281--- a/include/linux/sunrpc/clnt.h
85282+++ b/include/linux/sunrpc/clnt.h
85283@@ -97,7 +97,7 @@ struct rpc_procinfo {
85284 unsigned int p_timer; /* Which RTT timer to use */
85285 u32 p_statidx; /* Which procedure to account */
85286 const char * p_name; /* name of procedure */
85287-};
85288+} __do_const;
85289
85290 #ifdef __KERNEL__
85291
85292diff --git a/include/linux/sunrpc/svc.h b/include/linux/sunrpc/svc.h
85293index 2167846..0648fc3 100644
85294--- a/include/linux/sunrpc/svc.h
85295+++ b/include/linux/sunrpc/svc.h
85296@@ -416,7 +416,7 @@ struct svc_procedure {
85297 unsigned int pc_count; /* call count */
85298 unsigned int pc_cachetype; /* cache info (NFS) */
85299 unsigned int pc_xdrressize; /* maximum size of XDR reply */
85300-};
85301+} __do_const;
85302
85303 /*
85304 * Function prototypes.
85305diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
85306index 975da75..318c083 100644
85307--- a/include/linux/sunrpc/svc_rdma.h
85308+++ b/include/linux/sunrpc/svc_rdma.h
85309@@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
85310 extern unsigned int svcrdma_max_requests;
85311 extern unsigned int svcrdma_max_req_size;
85312
85313-extern atomic_t rdma_stat_recv;
85314-extern atomic_t rdma_stat_read;
85315-extern atomic_t rdma_stat_write;
85316-extern atomic_t rdma_stat_sq_starve;
85317-extern atomic_t rdma_stat_rq_starve;
85318-extern atomic_t rdma_stat_rq_poll;
85319-extern atomic_t rdma_stat_rq_prod;
85320-extern atomic_t rdma_stat_sq_poll;
85321-extern atomic_t rdma_stat_sq_prod;
85322+extern atomic_unchecked_t rdma_stat_recv;
85323+extern atomic_unchecked_t rdma_stat_read;
85324+extern atomic_unchecked_t rdma_stat_write;
85325+extern atomic_unchecked_t rdma_stat_sq_starve;
85326+extern atomic_unchecked_t rdma_stat_rq_starve;
85327+extern atomic_unchecked_t rdma_stat_rq_poll;
85328+extern atomic_unchecked_t rdma_stat_rq_prod;
85329+extern atomic_unchecked_t rdma_stat_sq_poll;
85330+extern atomic_unchecked_t rdma_stat_sq_prod;
85331
85332 #define RPCRDMA_VERSION 1
85333
85334diff --git a/include/linux/sunrpc/svcauth.h b/include/linux/sunrpc/svcauth.h
85335index 8d71d65..f79586e 100644
85336--- a/include/linux/sunrpc/svcauth.h
85337+++ b/include/linux/sunrpc/svcauth.h
85338@@ -120,7 +120,7 @@ struct auth_ops {
85339 int (*release)(struct svc_rqst *rq);
85340 void (*domain_release)(struct auth_domain *);
85341 int (*set_client)(struct svc_rqst *rq);
85342-};
85343+} __do_const;
85344
85345 #define SVC_GARBAGE 1
85346 #define SVC_SYSERR 2
85347diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
85348index e7a018e..49f8b17 100644
85349--- a/include/linux/swiotlb.h
85350+++ b/include/linux/swiotlb.h
85351@@ -60,7 +60,8 @@ extern void
85352
85353 extern void
85354 swiotlb_free_coherent(struct device *hwdev, size_t size,
85355- void *vaddr, dma_addr_t dma_handle);
85356+ void *vaddr, dma_addr_t dma_handle,
85357+ struct dma_attrs *attrs);
85358
85359 extern dma_addr_t swiotlb_map_page(struct device *dev, struct page *page,
85360 unsigned long offset, size_t size,
85361diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h
85362index bda9b81..629e06e 100644
85363--- a/include/linux/syscalls.h
85364+++ b/include/linux/syscalls.h
85365@@ -99,10 +99,16 @@ union bpf_attr;
85366 #define __MAP(n,...) __MAP##n(__VA_ARGS__)
85367
85368 #define __SC_DECL(t, a) t a
85369+#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))
85370 #define __TYPE_IS_L(t) (__same_type((t)0, 0L))
85371 #define __TYPE_IS_UL(t) (__same_type((t)0, 0UL))
85372 #define __TYPE_IS_LL(t) (__same_type((t)0, 0LL) || __same_type((t)0, 0ULL))
85373-#define __SC_LONG(t, a) __typeof(__builtin_choose_expr(__TYPE_IS_LL(t), 0LL, 0L)) a
85374+#define __SC_LONG(t, a) __typeof( \
85375+ __builtin_choose_expr( \
85376+ sizeof(t) > sizeof(int), \
85377+ (t) 0, \
85378+ __builtin_choose_expr(__TYPE_IS_U(t), 0UL, 0L) \
85379+ )) a
85380 #define __SC_CAST(t, a) (t) a
85381 #define __SC_ARGS(t, a) a
85382 #define __SC_TEST(t, a) (void)BUILD_BUG_ON_ZERO(!__TYPE_IS_LL(t) && sizeof(t) > sizeof(long))
85383@@ -384,11 +390,11 @@ asmlinkage long sys_sync(void);
85384 asmlinkage long sys_fsync(unsigned int fd);
85385 asmlinkage long sys_fdatasync(unsigned int fd);
85386 asmlinkage long sys_bdflush(int func, long data);
85387-asmlinkage long sys_mount(char __user *dev_name, char __user *dir_name,
85388- char __user *type, unsigned long flags,
85389+asmlinkage long sys_mount(const char __user *dev_name, const char __user *dir_name,
85390+ const char __user *type, unsigned long flags,
85391 void __user *data);
85392-asmlinkage long sys_umount(char __user *name, int flags);
85393-asmlinkage long sys_oldumount(char __user *name);
85394+asmlinkage long sys_umount(const char __user *name, int flags);
85395+asmlinkage long sys_oldumount(const char __user *name);
85396 asmlinkage long sys_truncate(const char __user *path, long length);
85397 asmlinkage long sys_ftruncate(unsigned int fd, unsigned long length);
85398 asmlinkage long sys_stat(const char __user *filename,
85399@@ -600,7 +606,7 @@ asmlinkage long sys_getsockname(int, struct sockaddr __user *, int __user *);
85400 asmlinkage long sys_getpeername(int, struct sockaddr __user *, int __user *);
85401 asmlinkage long sys_send(int, void __user *, size_t, unsigned);
85402 asmlinkage long sys_sendto(int, void __user *, size_t, unsigned,
85403- struct sockaddr __user *, int);
85404+ struct sockaddr __user *, int) __intentional_overflow(0);
85405 asmlinkage long sys_sendmsg(int fd, struct msghdr __user *msg, unsigned flags);
85406 asmlinkage long sys_sendmmsg(int fd, struct mmsghdr __user *msg,
85407 unsigned int vlen, unsigned flags);
85408diff --git a/include/linux/syscore_ops.h b/include/linux/syscore_ops.h
85409index 27b3b0b..e093dd9 100644
85410--- a/include/linux/syscore_ops.h
85411+++ b/include/linux/syscore_ops.h
85412@@ -16,7 +16,7 @@ struct syscore_ops {
85413 int (*suspend)(void);
85414 void (*resume)(void);
85415 void (*shutdown)(void);
85416-};
85417+} __do_const;
85418
85419 extern void register_syscore_ops(struct syscore_ops *ops);
85420 extern void unregister_syscore_ops(struct syscore_ops *ops);
85421diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
85422index b7361f8..341a15a 100644
85423--- a/include/linux/sysctl.h
85424+++ b/include/linux/sysctl.h
85425@@ -39,6 +39,8 @@ typedef int proc_handler (struct ctl_table *ctl, int write,
85426
85427 extern int proc_dostring(struct ctl_table *, int,
85428 void __user *, size_t *, loff_t *);
85429+extern int proc_dostring_modpriv(struct ctl_table *, int,
85430+ void __user *, size_t *, loff_t *);
85431 extern int proc_dointvec(struct ctl_table *, int,
85432 void __user *, size_t *, loff_t *);
85433 extern int proc_dointvec_minmax(struct ctl_table *, int,
85434@@ -113,7 +115,8 @@ struct ctl_table
85435 struct ctl_table_poll *poll;
85436 void *extra1;
85437 void *extra2;
85438-};
85439+} __do_const __randomize_layout;
85440+typedef struct ctl_table __no_const ctl_table_no_const;
85441
85442 struct ctl_node {
85443 struct rb_node node;
85444diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h
85445index f97d0db..c1187dc 100644
85446--- a/include/linux/sysfs.h
85447+++ b/include/linux/sysfs.h
85448@@ -34,7 +34,8 @@ struct attribute {
85449 struct lock_class_key *key;
85450 struct lock_class_key skey;
85451 #endif
85452-};
85453+} __do_const;
85454+typedef struct attribute __no_const attribute_no_const;
85455
85456 /**
85457 * sysfs_attr_init - initialize a dynamically allocated sysfs attribute
85458@@ -63,7 +64,8 @@ struct attribute_group {
85459 struct attribute *, int);
85460 struct attribute **attrs;
85461 struct bin_attribute **bin_attrs;
85462-};
85463+} __do_const;
85464+typedef struct attribute_group __no_const attribute_group_no_const;
85465
85466 /**
85467 * Use these macros to make defining attributes easier. See include/linux/device.h
85468@@ -128,7 +130,8 @@ struct bin_attribute {
85469 char *, loff_t, size_t);
85470 int (*mmap)(struct file *, struct kobject *, struct bin_attribute *attr,
85471 struct vm_area_struct *vma);
85472-};
85473+} __do_const;
85474+typedef struct bin_attribute __no_const bin_attribute_no_const;
85475
85476 /**
85477 * sysfs_bin_attr_init - initialize a dynamically allocated bin_attribute
85478diff --git a/include/linux/sysrq.h b/include/linux/sysrq.h
85479index 387fa7d..3fcde6b 100644
85480--- a/include/linux/sysrq.h
85481+++ b/include/linux/sysrq.h
85482@@ -16,6 +16,7 @@
85483
85484 #include <linux/errno.h>
85485 #include <linux/types.h>
85486+#include <linux/compiler.h>
85487
85488 /* Possible values of bitmask for enabling sysrq functions */
85489 /* 0x0001 is reserved for enable everything */
85490@@ -33,7 +34,7 @@ struct sysrq_key_op {
85491 char *help_msg;
85492 char *action_msg;
85493 int enable_mask;
85494-};
85495+} __do_const;
85496
85497 #ifdef CONFIG_MAGIC_SYSRQ
85498
85499diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h
85500index ff307b5..f1a4468 100644
85501--- a/include/linux/thread_info.h
85502+++ b/include/linux/thread_info.h
85503@@ -145,6 +145,13 @@ static inline bool test_and_clear_restore_sigmask(void)
85504 #error "no set_restore_sigmask() provided and default one won't work"
85505 #endif
85506
85507+extern void __check_object_size(const void *ptr, unsigned long n, bool to_user, bool const_size);
85508+
85509+static inline void check_object_size(const void *ptr, unsigned long n, bool to_user)
85510+{
85511+ __check_object_size(ptr, n, to_user, __builtin_constant_p(n));
85512+}
85513+
85514 #endif /* __KERNEL__ */
85515
85516 #endif /* _LINUX_THREAD_INFO_H */
85517diff --git a/include/linux/tty.h b/include/linux/tty.h
85518index 5171ef8..1048d83e 100644
85519--- a/include/linux/tty.h
85520+++ b/include/linux/tty.h
85521@@ -202,7 +202,7 @@ struct tty_port {
85522 const struct tty_port_operations *ops; /* Port operations */
85523 spinlock_t lock; /* Lock protecting tty field */
85524 int blocked_open; /* Waiting to open */
85525- int count; /* Usage count */
85526+ atomic_t count; /* Usage count */
85527 wait_queue_head_t open_wait; /* Open waiters */
85528 wait_queue_head_t close_wait; /* Close waiters */
85529 wait_queue_head_t delta_msr_wait; /* Modem status change */
85530@@ -290,7 +290,7 @@ struct tty_struct {
85531 /* If the tty has a pending do_SAK, queue it here - akpm */
85532 struct work_struct SAK_work;
85533 struct tty_port *port;
85534-};
85535+} __randomize_layout;
85536
85537 /* Each of a tty's open files has private_data pointing to tty_file_private */
85538 struct tty_file_private {
85539@@ -555,7 +555,7 @@ extern int tty_port_open(struct tty_port *port,
85540 struct tty_struct *tty, struct file *filp);
85541 static inline int tty_port_users(struct tty_port *port)
85542 {
85543- return port->count + port->blocked_open;
85544+ return atomic_read(&port->count) + port->blocked_open;
85545 }
85546
85547 extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc);
85548diff --git a/include/linux/tty_driver.h b/include/linux/tty_driver.h
85549index 92e337c..f46757b 100644
85550--- a/include/linux/tty_driver.h
85551+++ b/include/linux/tty_driver.h
85552@@ -291,7 +291,7 @@ struct tty_operations {
85553 void (*poll_put_char)(struct tty_driver *driver, int line, char ch);
85554 #endif
85555 const struct file_operations *proc_fops;
85556-};
85557+} __do_const __randomize_layout;
85558
85559 struct tty_driver {
85560 int magic; /* magic number for this structure */
85561@@ -325,7 +325,7 @@ struct tty_driver {
85562
85563 const struct tty_operations *ops;
85564 struct list_head tty_drivers;
85565-};
85566+} __randomize_layout;
85567
85568 extern struct list_head tty_drivers;
85569
85570diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
85571index 00c9d68..bc0188b 100644
85572--- a/include/linux/tty_ldisc.h
85573+++ b/include/linux/tty_ldisc.h
85574@@ -215,7 +215,7 @@ struct tty_ldisc_ops {
85575
85576 struct module *owner;
85577
85578- int refcount;
85579+ atomic_t refcount;
85580 };
85581
85582 struct tty_ldisc {
85583diff --git a/include/linux/types.h b/include/linux/types.h
85584index a0bb704..f511c77 100644
85585--- a/include/linux/types.h
85586+++ b/include/linux/types.h
85587@@ -177,10 +177,26 @@ typedef struct {
85588 int counter;
85589 } atomic_t;
85590
85591+#ifdef CONFIG_PAX_REFCOUNT
85592+typedef struct {
85593+ int counter;
85594+} atomic_unchecked_t;
85595+#else
85596+typedef atomic_t atomic_unchecked_t;
85597+#endif
85598+
85599 #ifdef CONFIG_64BIT
85600 typedef struct {
85601 long counter;
85602 } atomic64_t;
85603+
85604+#ifdef CONFIG_PAX_REFCOUNT
85605+typedef struct {
85606+ long counter;
85607+} atomic64_unchecked_t;
85608+#else
85609+typedef atomic64_t atomic64_unchecked_t;
85610+#endif
85611 #endif
85612
85613 struct list_head {
85614diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
85615index ecd3319..8a36ded 100644
85616--- a/include/linux/uaccess.h
85617+++ b/include/linux/uaccess.h
85618@@ -75,11 +75,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
85619 long ret; \
85620 mm_segment_t old_fs = get_fs(); \
85621 \
85622- set_fs(KERNEL_DS); \
85623 pagefault_disable(); \
85624- ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
85625- pagefault_enable(); \
85626+ set_fs(KERNEL_DS); \
85627+ ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
85628 set_fs(old_fs); \
85629+ pagefault_enable(); \
85630 ret; \
85631 })
85632
85633diff --git a/include/linux/uidgid.h b/include/linux/uidgid.h
85634index 2d1f9b6..d7a9fce 100644
85635--- a/include/linux/uidgid.h
85636+++ b/include/linux/uidgid.h
85637@@ -175,4 +175,9 @@ static inline bool kgid_has_mapping(struct user_namespace *ns, kgid_t gid)
85638
85639 #endif /* CONFIG_USER_NS */
85640
85641+#define GR_GLOBAL_UID(x) from_kuid_munged(&init_user_ns, (x))
85642+#define GR_GLOBAL_GID(x) from_kgid_munged(&init_user_ns, (x))
85643+#define gr_is_global_root(x) uid_eq((x), GLOBAL_ROOT_UID)
85644+#define gr_is_global_nonroot(x) (!uid_eq((x), GLOBAL_ROOT_UID))
85645+
85646 #endif /* _LINUX_UIDGID_H */
85647diff --git a/include/linux/uio_driver.h b/include/linux/uio_driver.h
85648index baa8171..9ca98ba 100644
85649--- a/include/linux/uio_driver.h
85650+++ b/include/linux/uio_driver.h
85651@@ -67,7 +67,7 @@ struct uio_device {
85652 struct module *owner;
85653 struct device *dev;
85654 int minor;
85655- atomic_t event;
85656+ atomic_unchecked_t event;
85657 struct fasync_struct *async_queue;
85658 wait_queue_head_t wait;
85659 struct uio_info *info;
85660diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
85661index 99c1b4d..562e6f3 100644
85662--- a/include/linux/unaligned/access_ok.h
85663+++ b/include/linux/unaligned/access_ok.h
85664@@ -4,34 +4,34 @@
85665 #include <linux/kernel.h>
85666 #include <asm/byteorder.h>
85667
85668-static inline u16 get_unaligned_le16(const void *p)
85669+static inline u16 __intentional_overflow(-1) get_unaligned_le16(const void *p)
85670 {
85671- return le16_to_cpup((__le16 *)p);
85672+ return le16_to_cpup((const __le16 *)p);
85673 }
85674
85675-static inline u32 get_unaligned_le32(const void *p)
85676+static inline u32 __intentional_overflow(-1) get_unaligned_le32(const void *p)
85677 {
85678- return le32_to_cpup((__le32 *)p);
85679+ return le32_to_cpup((const __le32 *)p);
85680 }
85681
85682-static inline u64 get_unaligned_le64(const void *p)
85683+static inline u64 __intentional_overflow(-1) get_unaligned_le64(const void *p)
85684 {
85685- return le64_to_cpup((__le64 *)p);
85686+ return le64_to_cpup((const __le64 *)p);
85687 }
85688
85689-static inline u16 get_unaligned_be16(const void *p)
85690+static inline u16 __intentional_overflow(-1) get_unaligned_be16(const void *p)
85691 {
85692- return be16_to_cpup((__be16 *)p);
85693+ return be16_to_cpup((const __be16 *)p);
85694 }
85695
85696-static inline u32 get_unaligned_be32(const void *p)
85697+static inline u32 __intentional_overflow(-1) get_unaligned_be32(const void *p)
85698 {
85699- return be32_to_cpup((__be32 *)p);
85700+ return be32_to_cpup((const __be32 *)p);
85701 }
85702
85703-static inline u64 get_unaligned_be64(const void *p)
85704+static inline u64 __intentional_overflow(-1) get_unaligned_be64(const void *p)
85705 {
85706- return be64_to_cpup((__be64 *)p);
85707+ return be64_to_cpup((const __be64 *)p);
85708 }
85709
85710 static inline void put_unaligned_le16(u16 val, void *p)
85711diff --git a/include/linux/usb.h b/include/linux/usb.h
85712index 447a7e2..9cea7e9 100644
85713--- a/include/linux/usb.h
85714+++ b/include/linux/usb.h
85715@@ -571,7 +571,7 @@ struct usb_device {
85716 int maxchild;
85717
85718 u32 quirks;
85719- atomic_t urbnum;
85720+ atomic_unchecked_t urbnum;
85721
85722 unsigned long active_duration;
85723
85724@@ -1655,7 +1655,7 @@ void usb_buffer_unmap_sg(const struct usb_device *dev, int is_in,
85725
85726 extern int usb_control_msg(struct usb_device *dev, unsigned int pipe,
85727 __u8 request, __u8 requesttype, __u16 value, __u16 index,
85728- void *data, __u16 size, int timeout);
85729+ void *data, __u16 size, int timeout) __intentional_overflow(-1);
85730 extern int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
85731 void *data, int len, int *actual_length, int timeout);
85732 extern int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
85733diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
85734index d5952bb..9a626d4 100644
85735--- a/include/linux/usb/renesas_usbhs.h
85736+++ b/include/linux/usb/renesas_usbhs.h
85737@@ -39,7 +39,7 @@ enum {
85738 */
85739 struct renesas_usbhs_driver_callback {
85740 int (*notify_hotplug)(struct platform_device *pdev);
85741-};
85742+} __no_const;
85743
85744 /*
85745 * callback functions for platform
85746diff --git a/include/linux/user_namespace.h b/include/linux/user_namespace.h
85747index e953726..8edb26a 100644
85748--- a/include/linux/user_namespace.h
85749+++ b/include/linux/user_namespace.h
85750@@ -33,7 +33,7 @@ struct user_namespace {
85751 struct key *persistent_keyring_register;
85752 struct rw_semaphore persistent_keyring_register_sem;
85753 #endif
85754-};
85755+} __randomize_layout;
85756
85757 extern struct user_namespace init_user_ns;
85758
85759diff --git a/include/linux/utsname.h b/include/linux/utsname.h
85760index 239e277..22a5cf5 100644
85761--- a/include/linux/utsname.h
85762+++ b/include/linux/utsname.h
85763@@ -24,7 +24,7 @@ struct uts_namespace {
85764 struct new_utsname name;
85765 struct user_namespace *user_ns;
85766 unsigned int proc_inum;
85767-};
85768+} __randomize_layout;
85769 extern struct uts_namespace init_uts_ns;
85770
85771 #ifdef CONFIG_UTS_NS
85772diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
85773index 6f8fbcf..4efc177 100644
85774--- a/include/linux/vermagic.h
85775+++ b/include/linux/vermagic.h
85776@@ -25,9 +25,42 @@
85777 #define MODULE_ARCH_VERMAGIC ""
85778 #endif
85779
85780+#ifdef CONFIG_PAX_REFCOUNT
85781+#define MODULE_PAX_REFCOUNT "REFCOUNT "
85782+#else
85783+#define MODULE_PAX_REFCOUNT ""
85784+#endif
85785+
85786+#ifdef CONSTIFY_PLUGIN
85787+#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
85788+#else
85789+#define MODULE_CONSTIFY_PLUGIN ""
85790+#endif
85791+
85792+#ifdef STACKLEAK_PLUGIN
85793+#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
85794+#else
85795+#define MODULE_STACKLEAK_PLUGIN ""
85796+#endif
85797+
85798+#ifdef RANDSTRUCT_PLUGIN
85799+#include <generated/randomize_layout_hash.h>
85800+#define MODULE_RANDSTRUCT_PLUGIN "RANDSTRUCT_PLUGIN_" RANDSTRUCT_HASHED_SEED
85801+#else
85802+#define MODULE_RANDSTRUCT_PLUGIN
85803+#endif
85804+
85805+#ifdef CONFIG_GRKERNSEC
85806+#define MODULE_GRSEC "GRSEC "
85807+#else
85808+#define MODULE_GRSEC ""
85809+#endif
85810+
85811 #define VERMAGIC_STRING \
85812 UTS_RELEASE " " \
85813 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
85814 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
85815- MODULE_ARCH_VERMAGIC
85816+ MODULE_ARCH_VERMAGIC \
85817+ MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
85818+ MODULE_GRSEC MODULE_RANDSTRUCT_PLUGIN
85819
85820diff --git a/include/linux/vga_switcheroo.h b/include/linux/vga_switcheroo.h
85821index b483abd..af305ad 100644
85822--- a/include/linux/vga_switcheroo.h
85823+++ b/include/linux/vga_switcheroo.h
85824@@ -63,9 +63,9 @@ int vga_switcheroo_get_client_state(struct pci_dev *dev);
85825
85826 void vga_switcheroo_set_dynamic_switch(struct pci_dev *pdev, enum vga_switcheroo_state dynamic);
85827
85828-int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain);
85829+int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain);
85830 void vga_switcheroo_fini_domain_pm_ops(struct device *dev);
85831-int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain);
85832+int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain);
85833 #else
85834
85835 static inline void vga_switcheroo_unregister_client(struct pci_dev *dev) {}
85836@@ -82,9 +82,9 @@ static inline int vga_switcheroo_get_client_state(struct pci_dev *dev) { return
85837
85838 static inline void vga_switcheroo_set_dynamic_switch(struct pci_dev *pdev, enum vga_switcheroo_state dynamic) {}
85839
85840-static inline int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain) { return -EINVAL; }
85841+static inline int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain) { return -EINVAL; }
85842 static inline void vga_switcheroo_fini_domain_pm_ops(struct device *dev) {}
85843-static inline int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain) { return -EINVAL; }
85844+static inline int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain) { return -EINVAL; }
85845
85846 #endif
85847 #endif /* _LINUX_VGA_SWITCHEROO_H_ */
85848diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
85849index b87696f..1d11de7 100644
85850--- a/include/linux/vmalloc.h
85851+++ b/include/linux/vmalloc.h
85852@@ -16,6 +16,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
85853 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
85854 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
85855 #define VM_UNINITIALIZED 0x00000020 /* vm_struct is not fully initialized */
85856+
85857+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
85858+#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
85859+#endif
85860+
85861 /* bits [20..32] reserved for arch specific ioremap internals */
85862
85863 /*
85864@@ -82,6 +87,10 @@ extern void *vmap(struct page **pages, unsigned int count,
85865 unsigned long flags, pgprot_t prot);
85866 extern void vunmap(const void *addr);
85867
85868+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
85869+extern void unmap_process_stacks(struct task_struct *task);
85870+#endif
85871+
85872 extern int remap_vmalloc_range_partial(struct vm_area_struct *vma,
85873 unsigned long uaddr, void *kaddr,
85874 unsigned long size);
85875@@ -142,7 +151,7 @@ extern void free_vm_area(struct vm_struct *area);
85876
85877 /* for /dev/kmem */
85878 extern long vread(char *buf, char *addr, unsigned long count);
85879-extern long vwrite(char *buf, char *addr, unsigned long count);
85880+extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
85881
85882 /*
85883 * Internals. Dont't use..
85884diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
85885index 82e7db7..f8ce3d0 100644
85886--- a/include/linux/vmstat.h
85887+++ b/include/linux/vmstat.h
85888@@ -108,18 +108,18 @@ static inline void vm_events_fold_cpu(int cpu)
85889 /*
85890 * Zone based page accounting with per cpu differentials.
85891 */
85892-extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
85893+extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
85894
85895 static inline void zone_page_state_add(long x, struct zone *zone,
85896 enum zone_stat_item item)
85897 {
85898- atomic_long_add(x, &zone->vm_stat[item]);
85899- atomic_long_add(x, &vm_stat[item]);
85900+ atomic_long_add_unchecked(x, &zone->vm_stat[item]);
85901+ atomic_long_add_unchecked(x, &vm_stat[item]);
85902 }
85903
85904-static inline unsigned long global_page_state(enum zone_stat_item item)
85905+static inline unsigned long __intentional_overflow(-1) global_page_state(enum zone_stat_item item)
85906 {
85907- long x = atomic_long_read(&vm_stat[item]);
85908+ long x = atomic_long_read_unchecked(&vm_stat[item]);
85909 #ifdef CONFIG_SMP
85910 if (x < 0)
85911 x = 0;
85912@@ -127,10 +127,10 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
85913 return x;
85914 }
85915
85916-static inline unsigned long zone_page_state(struct zone *zone,
85917+static inline unsigned long __intentional_overflow(-1) zone_page_state(struct zone *zone,
85918 enum zone_stat_item item)
85919 {
85920- long x = atomic_long_read(&zone->vm_stat[item]);
85921+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
85922 #ifdef CONFIG_SMP
85923 if (x < 0)
85924 x = 0;
85925@@ -147,7 +147,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
85926 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
85927 enum zone_stat_item item)
85928 {
85929- long x = atomic_long_read(&zone->vm_stat[item]);
85930+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
85931
85932 #ifdef CONFIG_SMP
85933 int cpu;
85934@@ -234,14 +234,14 @@ static inline void __mod_zone_page_state(struct zone *zone,
85935
85936 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
85937 {
85938- atomic_long_inc(&zone->vm_stat[item]);
85939- atomic_long_inc(&vm_stat[item]);
85940+ atomic_long_inc_unchecked(&zone->vm_stat[item]);
85941+ atomic_long_inc_unchecked(&vm_stat[item]);
85942 }
85943
85944 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
85945 {
85946- atomic_long_dec(&zone->vm_stat[item]);
85947- atomic_long_dec(&vm_stat[item]);
85948+ atomic_long_dec_unchecked(&zone->vm_stat[item]);
85949+ atomic_long_dec_unchecked(&vm_stat[item]);
85950 }
85951
85952 static inline void __inc_zone_page_state(struct page *page,
85953diff --git a/include/linux/xattr.h b/include/linux/xattr.h
85954index 91b0a68..0e9adf6 100644
85955--- a/include/linux/xattr.h
85956+++ b/include/linux/xattr.h
85957@@ -28,7 +28,7 @@ struct xattr_handler {
85958 size_t size, int handler_flags);
85959 int (*set)(struct dentry *dentry, const char *name, const void *buffer,
85960 size_t size, int flags, int handler_flags);
85961-};
85962+} __do_const;
85963
85964 struct xattr {
85965 const char *name;
85966@@ -37,6 +37,9 @@ struct xattr {
85967 };
85968
85969 ssize_t xattr_getsecurity(struct inode *, const char *, void *, size_t);
85970+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
85971+ssize_t pax_getxattr(struct dentry *, void *, size_t);
85972+#endif
85973 ssize_t vfs_getxattr(struct dentry *, const char *, void *, size_t);
85974 ssize_t vfs_listxattr(struct dentry *d, char *list, size_t size);
85975 int __vfs_setxattr_noperm(struct dentry *, const char *, const void *, size_t, int);
85976diff --git a/include/linux/zlib.h b/include/linux/zlib.h
85977index 92dbbd3..13ab0b3 100644
85978--- a/include/linux/zlib.h
85979+++ b/include/linux/zlib.h
85980@@ -31,6 +31,7 @@
85981 #define _ZLIB_H
85982
85983 #include <linux/zconf.h>
85984+#include <linux/compiler.h>
85985
85986 /* zlib deflate based on ZLIB_VERSION "1.1.3" */
85987 /* zlib inflate based on ZLIB_VERSION "1.2.3" */
85988@@ -179,7 +180,7 @@ typedef z_stream *z_streamp;
85989
85990 /* basic functions */
85991
85992-extern int zlib_deflate_workspacesize (int windowBits, int memLevel);
85993+extern int zlib_deflate_workspacesize (int windowBits, int memLevel) __intentional_overflow(0);
85994 /*
85995 Returns the number of bytes that needs to be allocated for a per-
85996 stream workspace with the specified parameters. A pointer to this
85997diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
85998index eb76cfd..9fd0e7c 100644
85999--- a/include/media/v4l2-dev.h
86000+++ b/include/media/v4l2-dev.h
86001@@ -75,7 +75,7 @@ struct v4l2_file_operations {
86002 int (*mmap) (struct file *, struct vm_area_struct *);
86003 int (*open) (struct file *);
86004 int (*release) (struct file *);
86005-};
86006+} __do_const;
86007
86008 /*
86009 * Newer version of video_device, handled by videodev2.c
86010diff --git a/include/media/v4l2-device.h b/include/media/v4l2-device.h
86011index ffb69da..040393e 100644
86012--- a/include/media/v4l2-device.h
86013+++ b/include/media/v4l2-device.h
86014@@ -95,7 +95,7 @@ int __must_check v4l2_device_register(struct device *dev, struct v4l2_device *v4
86015 this function returns 0. If the name ends with a digit (e.g. cx18),
86016 then the name will be set to cx18-0 since cx180 looks really odd. */
86017 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
86018- atomic_t *instance);
86019+ atomic_unchecked_t *instance);
86020
86021 /* Set v4l2_dev->dev to NULL. Call when the USB parent disconnects.
86022 Since the parent disappears this ensures that v4l2_dev doesn't have an
86023diff --git a/include/net/9p/transport.h b/include/net/9p/transport.h
86024index 2a25dec..bf6dd8a 100644
86025--- a/include/net/9p/transport.h
86026+++ b/include/net/9p/transport.h
86027@@ -62,7 +62,7 @@ struct p9_trans_module {
86028 int (*cancelled)(struct p9_client *, struct p9_req_t *req);
86029 int (*zc_request)(struct p9_client *, struct p9_req_t *,
86030 char *, char *, int , int, int, int);
86031-};
86032+} __do_const;
86033
86034 void v9fs_register_trans(struct p9_trans_module *m);
86035 void v9fs_unregister_trans(struct p9_trans_module *m);
86036diff --git a/include/net/af_unix.h b/include/net/af_unix.h
86037index a175ba4..196eb8242 100644
86038--- a/include/net/af_unix.h
86039+++ b/include/net/af_unix.h
86040@@ -36,7 +36,7 @@ struct unix_skb_parms {
86041 u32 secid; /* Security ID */
86042 #endif
86043 u32 consumed;
86044-};
86045+} __randomize_layout;
86046
86047 #define UNIXCB(skb) (*(struct unix_skb_parms *)&((skb)->cb))
86048 #define UNIXSID(skb) (&UNIXCB((skb)).secid)
86049diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h
86050index ead99f0..6263c4b 100644
86051--- a/include/net/bluetooth/l2cap.h
86052+++ b/include/net/bluetooth/l2cap.h
86053@@ -608,7 +608,7 @@ struct l2cap_ops {
86054 unsigned char *kdata,
86055 struct iovec *iov,
86056 int len);
86057-};
86058+} __do_const;
86059
86060 struct l2cap_conn {
86061 struct hci_conn *hcon;
86062diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
86063index f2ae33d..c457cf0 100644
86064--- a/include/net/caif/cfctrl.h
86065+++ b/include/net/caif/cfctrl.h
86066@@ -52,7 +52,7 @@ struct cfctrl_rsp {
86067 void (*radioset_rsp)(void);
86068 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
86069 struct cflayer *client_layer);
86070-};
86071+} __no_const;
86072
86073 /* Link Setup Parameters for CAIF-Links. */
86074 struct cfctrl_link_param {
86075@@ -101,8 +101,8 @@ struct cfctrl_request_info {
86076 struct cfctrl {
86077 struct cfsrvl serv;
86078 struct cfctrl_rsp res;
86079- atomic_t req_seq_no;
86080- atomic_t rsp_seq_no;
86081+ atomic_unchecked_t req_seq_no;
86082+ atomic_unchecked_t rsp_seq_no;
86083 struct list_head list;
86084 /* Protects from simultaneous access to first_req list */
86085 spinlock_t info_list_lock;
86086diff --git a/include/net/flow.h b/include/net/flow.h
86087index 8109a15..504466d 100644
86088--- a/include/net/flow.h
86089+++ b/include/net/flow.h
86090@@ -231,6 +231,6 @@ void flow_cache_fini(struct net *net);
86091
86092 void flow_cache_flush(struct net *net);
86093 void flow_cache_flush_deferred(struct net *net);
86094-extern atomic_t flow_cache_genid;
86095+extern atomic_unchecked_t flow_cache_genid;
86096
86097 #endif
86098diff --git a/include/net/genetlink.h b/include/net/genetlink.h
86099index af10c2c..a431cc5 100644
86100--- a/include/net/genetlink.h
86101+++ b/include/net/genetlink.h
86102@@ -120,7 +120,7 @@ struct genl_ops {
86103 u8 cmd;
86104 u8 internal_flags;
86105 u8 flags;
86106-};
86107+} __do_const;
86108
86109 int __genl_register_family(struct genl_family *family);
86110
86111diff --git a/include/net/gro_cells.h b/include/net/gro_cells.h
86112index 734d9b5..48a9a4b 100644
86113--- a/include/net/gro_cells.h
86114+++ b/include/net/gro_cells.h
86115@@ -29,7 +29,7 @@ static inline void gro_cells_receive(struct gro_cells *gcells, struct sk_buff *s
86116 cell += skb_get_rx_queue(skb) & gcells->gro_cells_mask;
86117
86118 if (skb_queue_len(&cell->napi_skbs) > netdev_max_backlog) {
86119- atomic_long_inc(&dev->rx_dropped);
86120+ atomic_long_inc_unchecked(&dev->rx_dropped);
86121 kfree_skb(skb);
86122 return;
86123 }
86124diff --git a/include/net/inet_connection_sock.h b/include/net/inet_connection_sock.h
86125index 848e85c..051c7de 100644
86126--- a/include/net/inet_connection_sock.h
86127+++ b/include/net/inet_connection_sock.h
86128@@ -63,7 +63,7 @@ struct inet_connection_sock_af_ops {
86129 int (*bind_conflict)(const struct sock *sk,
86130 const struct inet_bind_bucket *tb, bool relax);
86131 void (*mtu_reduced)(struct sock *sk);
86132-};
86133+} __do_const;
86134
86135 /** inet_connection_sock - INET connection oriented sock
86136 *
86137diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
86138index 80479ab..0c3f647 100644
86139--- a/include/net/inetpeer.h
86140+++ b/include/net/inetpeer.h
86141@@ -47,7 +47,7 @@ struct inet_peer {
86142 */
86143 union {
86144 struct {
86145- atomic_t rid; /* Frag reception counter */
86146+ atomic_unchecked_t rid; /* Frag reception counter */
86147 };
86148 struct rcu_head rcu;
86149 struct inet_peer *gc_next;
86150diff --git a/include/net/ip.h b/include/net/ip.h
86151index 0bb6207..a8878af 100644
86152--- a/include/net/ip.h
86153+++ b/include/net/ip.h
86154@@ -316,7 +316,7 @@ static inline unsigned int ip_skb_dst_mtu(const struct sk_buff *skb)
86155 }
86156 }
86157
86158-u32 ip_idents_reserve(u32 hash, int segs);
86159+u32 ip_idents_reserve(u32 hash, int segs) __intentional_overflow(-1);
86160 void __ip_select_ident(struct iphdr *iph, int segs);
86161
86162 static inline void ip_select_ident_segs(struct sk_buff *skb, struct sock *sk, int segs)
86163diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
86164index dc9d2a2..d985691 100644
86165--- a/include/net/ip_fib.h
86166+++ b/include/net/ip_fib.h
86167@@ -170,7 +170,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
86168
86169 #define FIB_RES_SADDR(net, res) \
86170 ((FIB_RES_NH(res).nh_saddr_genid == \
86171- atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
86172+ atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
86173 FIB_RES_NH(res).nh_saddr : \
86174 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
86175 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
86176diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
86177index 615b20b..fd4cbd8 100644
86178--- a/include/net/ip_vs.h
86179+++ b/include/net/ip_vs.h
86180@@ -534,7 +534,7 @@ struct ip_vs_conn {
86181 struct ip_vs_conn *control; /* Master control connection */
86182 atomic_t n_control; /* Number of controlled ones */
86183 struct ip_vs_dest *dest; /* real server */
86184- atomic_t in_pkts; /* incoming packet counter */
86185+ atomic_unchecked_t in_pkts; /* incoming packet counter */
86186
86187 /* Packet transmitter for different forwarding methods. If it
86188 * mangles the packet, it must return NF_DROP or better NF_STOLEN,
86189@@ -682,7 +682,7 @@ struct ip_vs_dest {
86190 __be16 port; /* port number of the server */
86191 union nf_inet_addr addr; /* IP address of the server */
86192 volatile unsigned int flags; /* dest status flags */
86193- atomic_t conn_flags; /* flags to copy to conn */
86194+ atomic_unchecked_t conn_flags; /* flags to copy to conn */
86195 atomic_t weight; /* server weight */
86196
86197 atomic_t refcnt; /* reference counter */
86198@@ -928,11 +928,11 @@ struct netns_ipvs {
86199 /* ip_vs_lblc */
86200 int sysctl_lblc_expiration;
86201 struct ctl_table_header *lblc_ctl_header;
86202- struct ctl_table *lblc_ctl_table;
86203+ ctl_table_no_const *lblc_ctl_table;
86204 /* ip_vs_lblcr */
86205 int sysctl_lblcr_expiration;
86206 struct ctl_table_header *lblcr_ctl_header;
86207- struct ctl_table *lblcr_ctl_table;
86208+ ctl_table_no_const *lblcr_ctl_table;
86209 /* ip_vs_est */
86210 struct list_head est_list; /* estimator list */
86211 spinlock_t est_lock;
86212diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
86213index 8d4f588..2e37ad2 100644
86214--- a/include/net/irda/ircomm_tty.h
86215+++ b/include/net/irda/ircomm_tty.h
86216@@ -33,6 +33,7 @@
86217 #include <linux/termios.h>
86218 #include <linux/timer.h>
86219 #include <linux/tty.h> /* struct tty_struct */
86220+#include <asm/local.h>
86221
86222 #include <net/irda/irias_object.h>
86223 #include <net/irda/ircomm_core.h>
86224diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
86225index 714cc9a..ea05f3e 100644
86226--- a/include/net/iucv/af_iucv.h
86227+++ b/include/net/iucv/af_iucv.h
86228@@ -149,7 +149,7 @@ struct iucv_skb_cb {
86229 struct iucv_sock_list {
86230 struct hlist_head head;
86231 rwlock_t lock;
86232- atomic_t autobind_name;
86233+ atomic_unchecked_t autobind_name;
86234 };
86235
86236 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
86237diff --git a/include/net/llc_c_ac.h b/include/net/llc_c_ac.h
86238index f3be818..bf46196 100644
86239--- a/include/net/llc_c_ac.h
86240+++ b/include/net/llc_c_ac.h
86241@@ -87,7 +87,7 @@
86242 #define LLC_CONN_AC_STOP_SENDACK_TMR 70
86243 #define LLC_CONN_AC_START_SENDACK_TMR_IF_NOT_RUNNING 71
86244
86245-typedef int (*llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
86246+typedef int (* const llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
86247
86248 int llc_conn_ac_clear_remote_busy(struct sock *sk, struct sk_buff *skb);
86249 int llc_conn_ac_conn_ind(struct sock *sk, struct sk_buff *skb);
86250diff --git a/include/net/llc_c_ev.h b/include/net/llc_c_ev.h
86251index 3948cf1..83b28c4 100644
86252--- a/include/net/llc_c_ev.h
86253+++ b/include/net/llc_c_ev.h
86254@@ -125,8 +125,8 @@ static __inline__ struct llc_conn_state_ev *llc_conn_ev(struct sk_buff *skb)
86255 return (struct llc_conn_state_ev *)skb->cb;
86256 }
86257
86258-typedef int (*llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
86259-typedef int (*llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
86260+typedef int (* const llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
86261+typedef int (* const llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
86262
86263 int llc_conn_ev_conn_req(struct sock *sk, struct sk_buff *skb);
86264 int llc_conn_ev_data_req(struct sock *sk, struct sk_buff *skb);
86265diff --git a/include/net/llc_c_st.h b/include/net/llc_c_st.h
86266index 0e79cfb..f46db31 100644
86267--- a/include/net/llc_c_st.h
86268+++ b/include/net/llc_c_st.h
86269@@ -37,7 +37,7 @@ struct llc_conn_state_trans {
86270 u8 next_state;
86271 llc_conn_ev_qfyr_t *ev_qualifiers;
86272 llc_conn_action_t *ev_actions;
86273-};
86274+} __do_const;
86275
86276 struct llc_conn_state {
86277 u8 current_state;
86278diff --git a/include/net/llc_s_ac.h b/include/net/llc_s_ac.h
86279index a61b98c..aade1eb 100644
86280--- a/include/net/llc_s_ac.h
86281+++ b/include/net/llc_s_ac.h
86282@@ -23,7 +23,7 @@
86283 #define SAP_ACT_TEST_IND 9
86284
86285 /* All action functions must look like this */
86286-typedef int (*llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
86287+typedef int (* const llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
86288
86289 int llc_sap_action_unitdata_ind(struct llc_sap *sap, struct sk_buff *skb);
86290 int llc_sap_action_send_ui(struct llc_sap *sap, struct sk_buff *skb);
86291diff --git a/include/net/llc_s_st.h b/include/net/llc_s_st.h
86292index 567c681..cd73ac02 100644
86293--- a/include/net/llc_s_st.h
86294+++ b/include/net/llc_s_st.h
86295@@ -20,7 +20,7 @@ struct llc_sap_state_trans {
86296 llc_sap_ev_t ev;
86297 u8 next_state;
86298 llc_sap_action_t *ev_actions;
86299-};
86300+} __do_const;
86301
86302 struct llc_sap_state {
86303 u8 curr_state;
86304diff --git a/include/net/mac80211.h b/include/net/mac80211.h
86305index 0ad1f47..aaea45b 100644
86306--- a/include/net/mac80211.h
86307+++ b/include/net/mac80211.h
86308@@ -4648,7 +4648,7 @@ struct rate_control_ops {
86309 void (*remove_sta_debugfs)(void *priv, void *priv_sta);
86310
86311 u32 (*get_expected_throughput)(void *priv_sta);
86312-};
86313+} __do_const;
86314
86315 static inline int rate_supported(struct ieee80211_sta *sta,
86316 enum ieee80211_band band,
86317diff --git a/include/net/neighbour.h b/include/net/neighbour.h
86318index f60558d..e5ed9bd 100644
86319--- a/include/net/neighbour.h
86320+++ b/include/net/neighbour.h
86321@@ -163,7 +163,7 @@ struct neigh_ops {
86322 void (*error_report)(struct neighbour *, struct sk_buff *);
86323 int (*output)(struct neighbour *, struct sk_buff *);
86324 int (*connected_output)(struct neighbour *, struct sk_buff *);
86325-};
86326+} __do_const;
86327
86328 struct pneigh_entry {
86329 struct pneigh_entry *next;
86330@@ -217,7 +217,7 @@ struct neigh_table {
86331 struct neigh_statistics __percpu *stats;
86332 struct neigh_hash_table __rcu *nht;
86333 struct pneigh_entry **phash_buckets;
86334-};
86335+} __randomize_layout;
86336
86337 static inline int neigh_parms_family(struct neigh_parms *p)
86338 {
86339diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
86340index e0d6466..e2f3003 100644
86341--- a/include/net/net_namespace.h
86342+++ b/include/net/net_namespace.h
86343@@ -129,8 +129,8 @@ struct net {
86344 struct netns_ipvs *ipvs;
86345 #endif
86346 struct sock *diag_nlsk;
86347- atomic_t fnhe_genid;
86348-};
86349+ atomic_unchecked_t fnhe_genid;
86350+} __randomize_layout;
86351
86352 #include <linux/seq_file_net.h>
86353
86354@@ -286,7 +286,11 @@ static inline struct net *read_pnet(struct net * const *pnet)
86355 #define __net_init __init
86356 #define __net_exit __exit_refok
86357 #define __net_initdata __initdata
86358+#ifdef CONSTIFY_PLUGIN
86359 #define __net_initconst __initconst
86360+#else
86361+#define __net_initconst __initdata
86362+#endif
86363 #endif
86364
86365 struct pernet_operations {
86366@@ -296,7 +300,7 @@ struct pernet_operations {
86367 void (*exit_batch)(struct list_head *net_exit_list);
86368 int *id;
86369 size_t size;
86370-};
86371+} __do_const;
86372
86373 /*
86374 * Use these carefully. If you implement a network device and it
86375@@ -344,12 +348,12 @@ static inline void unregister_net_sysctl_table(struct ctl_table_header *header)
86376
86377 static inline int rt_genid_ipv4(struct net *net)
86378 {
86379- return atomic_read(&net->ipv4.rt_genid);
86380+ return atomic_read_unchecked(&net->ipv4.rt_genid);
86381 }
86382
86383 static inline void rt_genid_bump_ipv4(struct net *net)
86384 {
86385- atomic_inc(&net->ipv4.rt_genid);
86386+ atomic_inc_unchecked(&net->ipv4.rt_genid);
86387 }
86388
86389 extern void (*__fib6_flush_trees)(struct net *net);
86390@@ -376,12 +380,12 @@ static inline void rt_genid_bump_all(struct net *net)
86391
86392 static inline int fnhe_genid(struct net *net)
86393 {
86394- return atomic_read(&net->fnhe_genid);
86395+ return atomic_read_unchecked(&net->fnhe_genid);
86396 }
86397
86398 static inline void fnhe_genid_bump(struct net *net)
86399 {
86400- atomic_inc(&net->fnhe_genid);
86401+ atomic_inc_unchecked(&net->fnhe_genid);
86402 }
86403
86404 #endif /* __NET_NET_NAMESPACE_H */
86405diff --git a/include/net/netlink.h b/include/net/netlink.h
86406index 7b903e1..ad9ca4b 100644
86407--- a/include/net/netlink.h
86408+++ b/include/net/netlink.h
86409@@ -521,7 +521,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
86410 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
86411 {
86412 if (mark)
86413- skb_trim(skb, (unsigned char *) mark - skb->data);
86414+ skb_trim(skb, (const unsigned char *) mark - skb->data);
86415 }
86416
86417 /**
86418diff --git a/include/net/netns/conntrack.h b/include/net/netns/conntrack.h
86419index 29d6a94..235d3d84 100644
86420--- a/include/net/netns/conntrack.h
86421+++ b/include/net/netns/conntrack.h
86422@@ -14,10 +14,10 @@ struct nf_conntrack_ecache;
86423 struct nf_proto_net {
86424 #ifdef CONFIG_SYSCTL
86425 struct ctl_table_header *ctl_table_header;
86426- struct ctl_table *ctl_table;
86427+ ctl_table_no_const *ctl_table;
86428 #ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT
86429 struct ctl_table_header *ctl_compat_header;
86430- struct ctl_table *ctl_compat_table;
86431+ ctl_table_no_const *ctl_compat_table;
86432 #endif
86433 #endif
86434 unsigned int users;
86435@@ -60,7 +60,7 @@ struct nf_ip_net {
86436 struct nf_icmp_net icmpv6;
86437 #if defined(CONFIG_SYSCTL) && defined(CONFIG_NF_CONNTRACK_PROC_COMPAT)
86438 struct ctl_table_header *ctl_table_header;
86439- struct ctl_table *ctl_table;
86440+ ctl_table_no_const *ctl_table;
86441 #endif
86442 };
86443
86444diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
86445index 24945ce..f19e42f 100644
86446--- a/include/net/netns/ipv4.h
86447+++ b/include/net/netns/ipv4.h
86448@@ -83,7 +83,7 @@ struct netns_ipv4 {
86449
86450 struct ping_group_range ping_group_range;
86451
86452- atomic_t dev_addr_genid;
86453+ atomic_unchecked_t dev_addr_genid;
86454
86455 #ifdef CONFIG_SYSCTL
86456 unsigned long *sysctl_local_reserved_ports;
86457@@ -97,6 +97,6 @@ struct netns_ipv4 {
86458 struct fib_rules_ops *mr_rules_ops;
86459 #endif
86460 #endif
86461- atomic_t rt_genid;
86462+ atomic_unchecked_t rt_genid;
86463 };
86464 #endif
86465diff --git a/include/net/netns/ipv6.h b/include/net/netns/ipv6.h
86466index 69ae41f..4f94868 100644
86467--- a/include/net/netns/ipv6.h
86468+++ b/include/net/netns/ipv6.h
86469@@ -75,8 +75,8 @@ struct netns_ipv6 {
86470 struct fib_rules_ops *mr6_rules_ops;
86471 #endif
86472 #endif
86473- atomic_t dev_addr_genid;
86474- atomic_t fib6_sernum;
86475+ atomic_unchecked_t dev_addr_genid;
86476+ atomic_unchecked_t fib6_sernum;
86477 };
86478
86479 #if IS_ENABLED(CONFIG_NF_DEFRAG_IPV6)
86480diff --git a/include/net/netns/xfrm.h b/include/net/netns/xfrm.h
86481index 9da7982..099321b9 100644
86482--- a/include/net/netns/xfrm.h
86483+++ b/include/net/netns/xfrm.h
86484@@ -78,7 +78,7 @@ struct netns_xfrm {
86485
86486 /* flow cache part */
86487 struct flow_cache flow_cache_global;
86488- atomic_t flow_cache_genid;
86489+ atomic_unchecked_t flow_cache_genid;
86490 struct list_head flow_cache_gc_list;
86491 spinlock_t flow_cache_gc_lock;
86492 struct work_struct flow_cache_gc_work;
86493diff --git a/include/net/ping.h b/include/net/ping.h
86494index 026479b..d9b2829 100644
86495--- a/include/net/ping.h
86496+++ b/include/net/ping.h
86497@@ -54,7 +54,7 @@ struct ping_iter_state {
86498
86499 extern struct proto ping_prot;
86500 #if IS_ENABLED(CONFIG_IPV6)
86501-extern struct pingv6_ops pingv6_ops;
86502+extern struct pingv6_ops *pingv6_ops;
86503 #endif
86504
86505 struct pingfakehdr {
86506diff --git a/include/net/protocol.h b/include/net/protocol.h
86507index d6fcc1f..ca277058 100644
86508--- a/include/net/protocol.h
86509+++ b/include/net/protocol.h
86510@@ -49,7 +49,7 @@ struct net_protocol {
86511 * socket lookup?
86512 */
86513 icmp_strict_tag_validation:1;
86514-};
86515+} __do_const;
86516
86517 #if IS_ENABLED(CONFIG_IPV6)
86518 struct inet6_protocol {
86519@@ -62,7 +62,7 @@ struct inet6_protocol {
86520 u8 type, u8 code, int offset,
86521 __be32 info);
86522 unsigned int flags; /* INET6_PROTO_xxx */
86523-};
86524+} __do_const;
86525
86526 #define INET6_PROTO_NOPOLICY 0x1
86527 #define INET6_PROTO_FINAL 0x2
86528diff --git a/include/net/rtnetlink.h b/include/net/rtnetlink.h
86529index e21b9f9..0191ef0 100644
86530--- a/include/net/rtnetlink.h
86531+++ b/include/net/rtnetlink.h
86532@@ -93,7 +93,7 @@ struct rtnl_link_ops {
86533 int (*fill_slave_info)(struct sk_buff *skb,
86534 const struct net_device *dev,
86535 const struct net_device *slave_dev);
86536-};
86537+} __do_const;
86538
86539 int __rtnl_link_register(struct rtnl_link_ops *ops);
86540 void __rtnl_link_unregister(struct rtnl_link_ops *ops);
86541diff --git a/include/net/sctp/checksum.h b/include/net/sctp/checksum.h
86542index 4a5b9a3..ca27d73 100644
86543--- a/include/net/sctp/checksum.h
86544+++ b/include/net/sctp/checksum.h
86545@@ -61,8 +61,8 @@ static inline __le32 sctp_compute_cksum(const struct sk_buff *skb,
86546 unsigned int offset)
86547 {
86548 struct sctphdr *sh = sctp_hdr(skb);
86549- __le32 ret, old = sh->checksum;
86550- const struct skb_checksum_ops ops = {
86551+ __le32 ret, old = sh->checksum;
86552+ static const struct skb_checksum_ops ops = {
86553 .update = sctp_csum_update,
86554 .combine = sctp_csum_combine,
86555 };
86556diff --git a/include/net/sctp/sm.h b/include/net/sctp/sm.h
86557index 72a31db..aaa63d9 100644
86558--- a/include/net/sctp/sm.h
86559+++ b/include/net/sctp/sm.h
86560@@ -80,7 +80,7 @@ typedef void (sctp_timer_event_t) (unsigned long);
86561 typedef struct {
86562 sctp_state_fn_t *fn;
86563 const char *name;
86564-} sctp_sm_table_entry_t;
86565+} __do_const sctp_sm_table_entry_t;
86566
86567 /* A naming convention of "sctp_sf_xxx" applies to all the state functions
86568 * currently in use.
86569@@ -292,7 +292,7 @@ __u32 sctp_generate_tag(const struct sctp_endpoint *);
86570 __u32 sctp_generate_tsn(const struct sctp_endpoint *);
86571
86572 /* Extern declarations for major data structures. */
86573-extern sctp_timer_event_t *sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
86574+extern sctp_timer_event_t * const sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
86575
86576
86577 /* Get the size of a DATA chunk payload. */
86578diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
86579index 4ff3f67..89ae38e 100644
86580--- a/include/net/sctp/structs.h
86581+++ b/include/net/sctp/structs.h
86582@@ -509,7 +509,7 @@ struct sctp_pf {
86583 void (*to_sk_saddr)(union sctp_addr *, struct sock *sk);
86584 void (*to_sk_daddr)(union sctp_addr *, struct sock *sk);
86585 struct sctp_af *af;
86586-};
86587+} __do_const;
86588
86589
86590 /* Structure to track chunk fragments that have been acked, but peer
86591diff --git a/include/net/sock.h b/include/net/sock.h
86592index 7db3db1..a915cca 100644
86593--- a/include/net/sock.h
86594+++ b/include/net/sock.h
86595@@ -355,7 +355,7 @@ struct sock {
86596 unsigned int sk_napi_id;
86597 unsigned int sk_ll_usec;
86598 #endif
86599- atomic_t sk_drops;
86600+ atomic_unchecked_t sk_drops;
86601 int sk_rcvbuf;
86602
86603 struct sk_filter __rcu *sk_filter;
86604@@ -1048,7 +1048,7 @@ struct proto {
86605 void (*destroy_cgroup)(struct mem_cgroup *memcg);
86606 struct cg_proto *(*proto_cgroup)(struct mem_cgroup *memcg);
86607 #endif
86608-};
86609+} __randomize_layout;
86610
86611 /*
86612 * Bits in struct cg_proto.flags
86613@@ -1235,7 +1235,7 @@ static inline u64 memcg_memory_allocated_read(struct cg_proto *prot)
86614 return ret >> PAGE_SHIFT;
86615 }
86616
86617-static inline long
86618+static inline long __intentional_overflow(-1)
86619 sk_memory_allocated(const struct sock *sk)
86620 {
86621 struct proto *prot = sk->sk_prot;
86622@@ -1380,7 +1380,7 @@ struct sock_iocb {
86623 struct scm_cookie *scm;
86624 struct msghdr *msg, async_msg;
86625 struct kiocb *kiocb;
86626-};
86627+} __randomize_layout;
86628
86629 static inline struct sock_iocb *kiocb_to_siocb(struct kiocb *iocb)
86630 {
86631@@ -1820,7 +1820,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
86632 }
86633
86634 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
86635- char __user *from, char *to,
86636+ char __user *from, unsigned char *to,
86637 int copy, int offset)
86638 {
86639 if (skb->ip_summed == CHECKSUM_NONE) {
86640@@ -2092,7 +2092,7 @@ static inline void sk_stream_moderate_sndbuf(struct sock *sk)
86641 }
86642 }
86643
86644-struct sk_buff *sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
86645+struct sk_buff * __intentional_overflow(0) sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
86646
86647 /**
86648 * sk_page_frag - return an appropriate page_frag
86649diff --git a/include/net/tcp.h b/include/net/tcp.h
86650index 4062b4f..9ff45e7 100644
86651--- a/include/net/tcp.h
86652+++ b/include/net/tcp.h
86653@@ -519,7 +519,7 @@ void tcp_retransmit_timer(struct sock *sk);
86654 void tcp_xmit_retransmit_queue(struct sock *);
86655 void tcp_simple_retransmit(struct sock *);
86656 int tcp_trim_head(struct sock *, struct sk_buff *, u32);
86657-int tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int, gfp_t);
86658+int __intentional_overflow(3) tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int, gfp_t);
86659
86660 void tcp_send_probe0(struct sock *);
86661 void tcp_send_partial(struct sock *);
86662@@ -692,8 +692,8 @@ static inline u32 tcp_skb_timestamp(const struct sk_buff *skb)
86663 * If this grows please adjust skbuff.h:skbuff->cb[xxx] size appropriately.
86664 */
86665 struct tcp_skb_cb {
86666- __u32 seq; /* Starting sequence number */
86667- __u32 end_seq; /* SEQ + FIN + SYN + datalen */
86668+ __u32 seq __intentional_overflow(0); /* Starting sequence number */
86669+ __u32 end_seq __intentional_overflow(0); /* SEQ + FIN + SYN + datalen */
86670 union {
86671 /* Note : tcp_tw_isn is used in input path only
86672 * (isn chosen by tcp_timewait_state_process())
86673@@ -718,7 +718,7 @@ struct tcp_skb_cb {
86674
86675 __u8 ip_dsfield; /* IPv4 tos or IPv6 dsfield */
86676 /* 1 byte hole */
86677- __u32 ack_seq; /* Sequence number ACK'd */
86678+ __u32 ack_seq __intentional_overflow(0); /* Sequence number ACK'd */
86679 union {
86680 struct inet_skb_parm h4;
86681 #if IS_ENABLED(CONFIG_IPV6)
86682diff --git a/include/net/xfrm.h b/include/net/xfrm.h
86683index dc4865e..152ee4c 100644
86684--- a/include/net/xfrm.h
86685+++ b/include/net/xfrm.h
86686@@ -285,7 +285,6 @@ struct xfrm_dst;
86687 struct xfrm_policy_afinfo {
86688 unsigned short family;
86689 struct dst_ops *dst_ops;
86690- void (*garbage_collect)(struct net *net);
86691 struct dst_entry *(*dst_lookup)(struct net *net, int tos,
86692 const xfrm_address_t *saddr,
86693 const xfrm_address_t *daddr);
86694@@ -303,7 +302,7 @@ struct xfrm_policy_afinfo {
86695 struct net_device *dev,
86696 const struct flowi *fl);
86697 struct dst_entry *(*blackhole_route)(struct net *net, struct dst_entry *orig);
86698-};
86699+} __do_const;
86700
86701 int xfrm_policy_register_afinfo(struct xfrm_policy_afinfo *afinfo);
86702 int xfrm_policy_unregister_afinfo(struct xfrm_policy_afinfo *afinfo);
86703@@ -342,7 +341,7 @@ struct xfrm_state_afinfo {
86704 int (*transport_finish)(struct sk_buff *skb,
86705 int async);
86706 void (*local_error)(struct sk_buff *skb, u32 mtu);
86707-};
86708+} __do_const;
86709
86710 int xfrm_state_register_afinfo(struct xfrm_state_afinfo *afinfo);
86711 int xfrm_state_unregister_afinfo(struct xfrm_state_afinfo *afinfo);
86712@@ -437,7 +436,7 @@ struct xfrm_mode {
86713 struct module *owner;
86714 unsigned int encap;
86715 int flags;
86716-};
86717+} __do_const;
86718
86719 /* Flags for xfrm_mode. */
86720 enum {
86721@@ -534,7 +533,7 @@ struct xfrm_policy {
86722 struct timer_list timer;
86723
86724 struct flow_cache_object flo;
86725- atomic_t genid;
86726+ atomic_unchecked_t genid;
86727 u32 priority;
86728 u32 index;
86729 struct xfrm_mark mark;
86730@@ -1167,6 +1166,7 @@ static inline void xfrm_sk_free_policy(struct sock *sk)
86731 }
86732
86733 void xfrm_garbage_collect(struct net *net);
86734+void xfrm_garbage_collect_deferred(struct net *net);
86735
86736 #else
86737
86738@@ -1205,6 +1205,9 @@ static inline int xfrm6_policy_check_reverse(struct sock *sk, int dir,
86739 static inline void xfrm_garbage_collect(struct net *net)
86740 {
86741 }
86742+static inline void xfrm_garbage_collect_deferred(struct net *net)
86743+{
86744+}
86745 #endif
86746
86747 static __inline__
86748diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
86749index 1017e0b..227aa4d 100644
86750--- a/include/rdma/iw_cm.h
86751+++ b/include/rdma/iw_cm.h
86752@@ -122,7 +122,7 @@ struct iw_cm_verbs {
86753 int backlog);
86754
86755 int (*destroy_listen)(struct iw_cm_id *cm_id);
86756-};
86757+} __no_const;
86758
86759 /**
86760 * iw_create_cm_id - Create an IW CM identifier.
86761diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
86762index 52beadf..598734c 100644
86763--- a/include/scsi/libfc.h
86764+++ b/include/scsi/libfc.h
86765@@ -771,6 +771,7 @@ struct libfc_function_template {
86766 */
86767 void (*disc_stop_final) (struct fc_lport *);
86768 };
86769+typedef struct libfc_function_template __no_const libfc_function_template_no_const;
86770
86771 /**
86772 * struct fc_disc - Discovery context
86773@@ -875,7 +876,7 @@ struct fc_lport {
86774 struct fc_vport *vport;
86775
86776 /* Operational Information */
86777- struct libfc_function_template tt;
86778+ libfc_function_template_no_const tt;
86779 u8 link_up;
86780 u8 qfull;
86781 enum fc_lport_state state;
86782diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
86783index 27ecee7..5f42632 100644
86784--- a/include/scsi/scsi_device.h
86785+++ b/include/scsi/scsi_device.h
86786@@ -186,9 +186,9 @@ struct scsi_device {
86787 unsigned int max_device_blocked; /* what device_blocked counts down from */
86788 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
86789
86790- atomic_t iorequest_cnt;
86791- atomic_t iodone_cnt;
86792- atomic_t ioerr_cnt;
86793+ atomic_unchecked_t iorequest_cnt;
86794+ atomic_unchecked_t iodone_cnt;
86795+ atomic_unchecked_t ioerr_cnt;
86796
86797 struct device sdev_gendev,
86798 sdev_dev;
86799diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
86800index 007a0bc..7188db8 100644
86801--- a/include/scsi/scsi_transport_fc.h
86802+++ b/include/scsi/scsi_transport_fc.h
86803@@ -756,7 +756,8 @@ struct fc_function_template {
86804 unsigned long show_host_system_hostname:1;
86805
86806 unsigned long disable_target_scan:1;
86807-};
86808+} __do_const;
86809+typedef struct fc_function_template __no_const fc_function_template_no_const;
86810
86811
86812 /**
86813diff --git a/include/sound/compress_driver.h b/include/sound/compress_driver.h
86814index ae6c3b8..fd748ac 100644
86815--- a/include/sound/compress_driver.h
86816+++ b/include/sound/compress_driver.h
86817@@ -128,7 +128,7 @@ struct snd_compr_ops {
86818 struct snd_compr_caps *caps);
86819 int (*get_codec_caps) (struct snd_compr_stream *stream,
86820 struct snd_compr_codec_caps *codec);
86821-};
86822+} __no_const;
86823
86824 /**
86825 * struct snd_compr: Compressed device
86826diff --git a/include/sound/soc.h b/include/sound/soc.h
86827index 7ba7130..d46594d 100644
86828--- a/include/sound/soc.h
86829+++ b/include/sound/soc.h
86830@@ -853,7 +853,7 @@ struct snd_soc_codec_driver {
86831 enum snd_soc_dapm_type, int);
86832
86833 bool ignore_pmdown_time; /* Doesn't benefit from pmdown delay */
86834-};
86835+} __do_const;
86836
86837 /* SoC platform interface */
86838 struct snd_soc_platform_driver {
86839@@ -882,7 +882,7 @@ struct snd_soc_platform_driver {
86840 const struct snd_compr_ops *compr_ops;
86841
86842 int (*bespoke_trigger)(struct snd_pcm_substream *, int);
86843-};
86844+} __do_const;
86845
86846 struct snd_soc_dai_link_component {
86847 const char *name;
86848diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
86849index 23c518a..d6ef510 100644
86850--- a/include/target/target_core_base.h
86851+++ b/include/target/target_core_base.h
86852@@ -764,7 +764,7 @@ struct se_device {
86853 atomic_long_t write_bytes;
86854 /* Active commands on this virtual SE device */
86855 atomic_t simple_cmds;
86856- atomic_t dev_ordered_id;
86857+ atomic_unchecked_t dev_ordered_id;
86858 atomic_t dev_ordered_sync;
86859 atomic_t dev_qf_count;
86860 int export_count;
86861diff --git a/include/trace/events/fs.h b/include/trace/events/fs.h
86862new file mode 100644
86863index 0000000..fb634b7
86864--- /dev/null
86865+++ b/include/trace/events/fs.h
86866@@ -0,0 +1,53 @@
86867+#undef TRACE_SYSTEM
86868+#define TRACE_SYSTEM fs
86869+
86870+#if !defined(_TRACE_FS_H) || defined(TRACE_HEADER_MULTI_READ)
86871+#define _TRACE_FS_H
86872+
86873+#include <linux/fs.h>
86874+#include <linux/tracepoint.h>
86875+
86876+TRACE_EVENT(do_sys_open,
86877+
86878+ TP_PROTO(const char *filename, int flags, int mode),
86879+
86880+ TP_ARGS(filename, flags, mode),
86881+
86882+ TP_STRUCT__entry(
86883+ __string( filename, filename )
86884+ __field( int, flags )
86885+ __field( int, mode )
86886+ ),
86887+
86888+ TP_fast_assign(
86889+ __assign_str(filename, filename);
86890+ __entry->flags = flags;
86891+ __entry->mode = mode;
86892+ ),
86893+
86894+ TP_printk("\"%s\" %x %o",
86895+ __get_str(filename), __entry->flags, __entry->mode)
86896+);
86897+
86898+TRACE_EVENT(open_exec,
86899+
86900+ TP_PROTO(const char *filename),
86901+
86902+ TP_ARGS(filename),
86903+
86904+ TP_STRUCT__entry(
86905+ __string( filename, filename )
86906+ ),
86907+
86908+ TP_fast_assign(
86909+ __assign_str(filename, filename);
86910+ ),
86911+
86912+ TP_printk("\"%s\"",
86913+ __get_str(filename))
86914+);
86915+
86916+#endif /* _TRACE_FS_H */
86917+
86918+/* This part must be outside protection */
86919+#include <trace/define_trace.h>
86920diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
86921index 3608beb..df39d8a 100644
86922--- a/include/trace/events/irq.h
86923+++ b/include/trace/events/irq.h
86924@@ -36,7 +36,7 @@ struct softirq_action;
86925 */
86926 TRACE_EVENT(irq_handler_entry,
86927
86928- TP_PROTO(int irq, struct irqaction *action),
86929+ TP_PROTO(int irq, const struct irqaction *action),
86930
86931 TP_ARGS(irq, action),
86932
86933@@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
86934 */
86935 TRACE_EVENT(irq_handler_exit,
86936
86937- TP_PROTO(int irq, struct irqaction *action, int ret),
86938+ TP_PROTO(int irq, const struct irqaction *action, int ret),
86939
86940 TP_ARGS(irq, action, ret),
86941
86942diff --git a/include/uapi/linux/a.out.h b/include/uapi/linux/a.out.h
86943index 7caf44c..23c6f27 100644
86944--- a/include/uapi/linux/a.out.h
86945+++ b/include/uapi/linux/a.out.h
86946@@ -39,6 +39,14 @@ enum machine_type {
86947 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
86948 };
86949
86950+/* Constants for the N_FLAGS field */
86951+#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
86952+#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
86953+#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
86954+#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
86955+/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
86956+#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
86957+
86958 #if !defined (N_MAGIC)
86959 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
86960 #endif
86961diff --git a/include/uapi/linux/bcache.h b/include/uapi/linux/bcache.h
86962index 22b6ad3..aeba37e 100644
86963--- a/include/uapi/linux/bcache.h
86964+++ b/include/uapi/linux/bcache.h
86965@@ -5,6 +5,7 @@
86966 * Bcache on disk data structures
86967 */
86968
86969+#include <linux/compiler.h>
86970 #include <asm/types.h>
86971
86972 #define BITMASK(name, type, field, offset, size) \
86973@@ -20,8 +21,8 @@ static inline void SET_##name(type *k, __u64 v) \
86974 /* Btree keys - all units are in sectors */
86975
86976 struct bkey {
86977- __u64 high;
86978- __u64 low;
86979+ __u64 high __intentional_overflow(-1);
86980+ __u64 low __intentional_overflow(-1);
86981 __u64 ptr[];
86982 };
86983
86984diff --git a/include/uapi/linux/byteorder/little_endian.h b/include/uapi/linux/byteorder/little_endian.h
86985index d876736..ccce5c0 100644
86986--- a/include/uapi/linux/byteorder/little_endian.h
86987+++ b/include/uapi/linux/byteorder/little_endian.h
86988@@ -42,51 +42,51 @@
86989
86990 static inline __le64 __cpu_to_le64p(const __u64 *p)
86991 {
86992- return (__force __le64)*p;
86993+ return (__force const __le64)*p;
86994 }
86995-static inline __u64 __le64_to_cpup(const __le64 *p)
86996+static inline __u64 __intentional_overflow(-1) __le64_to_cpup(const __le64 *p)
86997 {
86998- return (__force __u64)*p;
86999+ return (__force const __u64)*p;
87000 }
87001 static inline __le32 __cpu_to_le32p(const __u32 *p)
87002 {
87003- return (__force __le32)*p;
87004+ return (__force const __le32)*p;
87005 }
87006 static inline __u32 __le32_to_cpup(const __le32 *p)
87007 {
87008- return (__force __u32)*p;
87009+ return (__force const __u32)*p;
87010 }
87011 static inline __le16 __cpu_to_le16p(const __u16 *p)
87012 {
87013- return (__force __le16)*p;
87014+ return (__force const __le16)*p;
87015 }
87016 static inline __u16 __le16_to_cpup(const __le16 *p)
87017 {
87018- return (__force __u16)*p;
87019+ return (__force const __u16)*p;
87020 }
87021 static inline __be64 __cpu_to_be64p(const __u64 *p)
87022 {
87023- return (__force __be64)__swab64p(p);
87024+ return (__force const __be64)__swab64p(p);
87025 }
87026 static inline __u64 __be64_to_cpup(const __be64 *p)
87027 {
87028- return __swab64p((__u64 *)p);
87029+ return __swab64p((const __u64 *)p);
87030 }
87031 static inline __be32 __cpu_to_be32p(const __u32 *p)
87032 {
87033- return (__force __be32)__swab32p(p);
87034+ return (__force const __be32)__swab32p(p);
87035 }
87036-static inline __u32 __be32_to_cpup(const __be32 *p)
87037+static inline __u32 __intentional_overflow(-1) __be32_to_cpup(const __be32 *p)
87038 {
87039- return __swab32p((__u32 *)p);
87040+ return __swab32p((const __u32 *)p);
87041 }
87042 static inline __be16 __cpu_to_be16p(const __u16 *p)
87043 {
87044- return (__force __be16)__swab16p(p);
87045+ return (__force const __be16)__swab16p(p);
87046 }
87047 static inline __u16 __be16_to_cpup(const __be16 *p)
87048 {
87049- return __swab16p((__u16 *)p);
87050+ return __swab16p((const __u16 *)p);
87051 }
87052 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
87053 #define __le64_to_cpus(x) do { (void)(x); } while (0)
87054diff --git a/include/uapi/linux/elf.h b/include/uapi/linux/elf.h
87055index ea9bf25..5140c61 100644
87056--- a/include/uapi/linux/elf.h
87057+++ b/include/uapi/linux/elf.h
87058@@ -37,6 +37,17 @@ typedef __s64 Elf64_Sxword;
87059 #define PT_GNU_EH_FRAME 0x6474e550
87060
87061 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
87062+#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
87063+
87064+#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
87065+
87066+/* Constants for the e_flags field */
87067+#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
87068+#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
87069+#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
87070+#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
87071+/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
87072+#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
87073
87074 /*
87075 * Extended Numbering
87076@@ -94,6 +105,8 @@ typedef __s64 Elf64_Sxword;
87077 #define DT_DEBUG 21
87078 #define DT_TEXTREL 22
87079 #define DT_JMPREL 23
87080+#define DT_FLAGS 30
87081+ #define DF_TEXTREL 0x00000004
87082 #define DT_ENCODING 32
87083 #define OLD_DT_LOOS 0x60000000
87084 #define DT_LOOS 0x6000000d
87085@@ -240,6 +253,19 @@ typedef struct elf64_hdr {
87086 #define PF_W 0x2
87087 #define PF_X 0x1
87088
87089+#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
87090+#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
87091+#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
87092+#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
87093+#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
87094+#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
87095+/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
87096+/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
87097+#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
87098+#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
87099+#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
87100+#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
87101+
87102 typedef struct elf32_phdr{
87103 Elf32_Word p_type;
87104 Elf32_Off p_offset;
87105@@ -332,6 +358,8 @@ typedef struct elf64_shdr {
87106 #define EI_OSABI 7
87107 #define EI_PAD 8
87108
87109+#define EI_PAX 14
87110+
87111 #define ELFMAG0 0x7f /* EI_MAG */
87112 #define ELFMAG1 'E'
87113 #define ELFMAG2 'L'
87114diff --git a/include/uapi/linux/personality.h b/include/uapi/linux/personality.h
87115index aa169c4..6a2771d 100644
87116--- a/include/uapi/linux/personality.h
87117+++ b/include/uapi/linux/personality.h
87118@@ -30,6 +30,7 @@ enum {
87119 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
87120 ADDR_NO_RANDOMIZE | \
87121 ADDR_COMPAT_LAYOUT | \
87122+ ADDR_LIMIT_3GB | \
87123 MMAP_PAGE_ZERO)
87124
87125 /*
87126diff --git a/include/uapi/linux/screen_info.h b/include/uapi/linux/screen_info.h
87127index 7530e74..e714828 100644
87128--- a/include/uapi/linux/screen_info.h
87129+++ b/include/uapi/linux/screen_info.h
87130@@ -43,7 +43,8 @@ struct screen_info {
87131 __u16 pages; /* 0x32 */
87132 __u16 vesa_attributes; /* 0x34 */
87133 __u32 capabilities; /* 0x36 */
87134- __u8 _reserved[6]; /* 0x3a */
87135+ __u16 vesapm_size; /* 0x3a */
87136+ __u8 _reserved[4]; /* 0x3c */
87137 } __attribute__((packed));
87138
87139 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
87140diff --git a/include/uapi/linux/swab.h b/include/uapi/linux/swab.h
87141index 0e011eb..82681b1 100644
87142--- a/include/uapi/linux/swab.h
87143+++ b/include/uapi/linux/swab.h
87144@@ -43,7 +43,7 @@
87145 * ___swab16, ___swab32, ___swab64, ___swahw32, ___swahb32
87146 */
87147
87148-static inline __attribute_const__ __u16 __fswab16(__u16 val)
87149+static inline __intentional_overflow(-1) __attribute_const__ __u16 __fswab16(__u16 val)
87150 {
87151 #ifdef __HAVE_BUILTIN_BSWAP16__
87152 return __builtin_bswap16(val);
87153@@ -54,7 +54,7 @@ static inline __attribute_const__ __u16 __fswab16(__u16 val)
87154 #endif
87155 }
87156
87157-static inline __attribute_const__ __u32 __fswab32(__u32 val)
87158+static inline __intentional_overflow(-1) __attribute_const__ __u32 __fswab32(__u32 val)
87159 {
87160 #ifdef __HAVE_BUILTIN_BSWAP32__
87161 return __builtin_bswap32(val);
87162@@ -65,7 +65,7 @@ static inline __attribute_const__ __u32 __fswab32(__u32 val)
87163 #endif
87164 }
87165
87166-static inline __attribute_const__ __u64 __fswab64(__u64 val)
87167+static inline __intentional_overflow(-1) __attribute_const__ __u64 __fswab64(__u64 val)
87168 {
87169 #ifdef __HAVE_BUILTIN_BSWAP64__
87170 return __builtin_bswap64(val);
87171diff --git a/include/uapi/linux/sysctl.h b/include/uapi/linux/sysctl.h
87172index 43aaba1..1c30b48 100644
87173--- a/include/uapi/linux/sysctl.h
87174+++ b/include/uapi/linux/sysctl.h
87175@@ -155,8 +155,6 @@ enum
87176 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
87177 };
87178
87179-
87180-
87181 /* CTL_VM names: */
87182 enum
87183 {
87184diff --git a/include/uapi/linux/xattr.h b/include/uapi/linux/xattr.h
87185index 1590c49..5eab462 100644
87186--- a/include/uapi/linux/xattr.h
87187+++ b/include/uapi/linux/xattr.h
87188@@ -73,5 +73,9 @@
87189 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
87190 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
87191
87192+/* User namespace */
87193+#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
87194+#define XATTR_PAX_FLAGS_SUFFIX "flags"
87195+#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
87196
87197 #endif /* _UAPI_LINUX_XATTR_H */
87198diff --git a/include/video/udlfb.h b/include/video/udlfb.h
87199index f9466fa..f4e2b81 100644
87200--- a/include/video/udlfb.h
87201+++ b/include/video/udlfb.h
87202@@ -53,10 +53,10 @@ struct dlfb_data {
87203 u32 pseudo_palette[256];
87204 int blank_mode; /*one of FB_BLANK_ */
87205 /* blit-only rendering path metrics, exposed through sysfs */
87206- atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
87207- atomic_t bytes_identical; /* saved effort with backbuffer comparison */
87208- atomic_t bytes_sent; /* to usb, after compression including overhead */
87209- atomic_t cpu_kcycles_used; /* transpired during pixel processing */
87210+ atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
87211+ atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
87212+ atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
87213+ atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
87214 };
87215
87216 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
87217diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
87218index 30f5362..8ed8ac9 100644
87219--- a/include/video/uvesafb.h
87220+++ b/include/video/uvesafb.h
87221@@ -122,6 +122,7 @@ struct uvesafb_par {
87222 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
87223 u8 pmi_setpal; /* PMI for palette changes */
87224 u16 *pmi_base; /* protected mode interface location */
87225+ u8 *pmi_code; /* protected mode code location */
87226 void *pmi_start;
87227 void *pmi_pal;
87228 u8 *vbe_state_orig; /*
87229diff --git a/init/Kconfig b/init/Kconfig
87230index 2081a4d..98d1149 100644
87231--- a/init/Kconfig
87232+++ b/init/Kconfig
87233@@ -1150,6 +1150,7 @@ endif # CGROUPS
87234
87235 config CHECKPOINT_RESTORE
87236 bool "Checkpoint/restore support" if EXPERT
87237+ depends on !GRKERNSEC
87238 default n
87239 help
87240 Enables additional kernel features in a sake of checkpoint/restore.
87241@@ -1659,7 +1660,7 @@ config SLUB_DEBUG
87242
87243 config COMPAT_BRK
87244 bool "Disable heap randomization"
87245- default y
87246+ default n
87247 help
87248 Randomizing heap placement makes heap exploits harder, but it
87249 also breaks ancient binaries (including anything libc5 based).
87250@@ -1990,7 +1991,7 @@ config INIT_ALL_POSSIBLE
87251 config STOP_MACHINE
87252 bool
87253 default y
87254- depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU
87255+ depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU || GRKERNSEC
87256 help
87257 Need stop_machine() primitive.
87258
87259diff --git a/init/Makefile b/init/Makefile
87260index 7bc47ee..6da2dc7 100644
87261--- a/init/Makefile
87262+++ b/init/Makefile
87263@@ -2,6 +2,9 @@
87264 # Makefile for the linux kernel.
87265 #
87266
87267+ccflags-y := $(GCC_PLUGINS_CFLAGS)
87268+asflags-y := $(GCC_PLUGINS_AFLAGS)
87269+
87270 obj-y := main.o version.o mounts.o
87271 ifneq ($(CONFIG_BLK_DEV_INITRD),y)
87272 obj-y += noinitramfs.o
87273diff --git a/init/do_mounts.c b/init/do_mounts.c
87274index 9b3565c..3f90cf9 100644
87275--- a/init/do_mounts.c
87276+++ b/init/do_mounts.c
87277@@ -360,11 +360,11 @@ static void __init get_fs_names(char *page)
87278 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
87279 {
87280 struct super_block *s;
87281- int err = sys_mount(name, "/root", fs, flags, data);
87282+ int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
87283 if (err)
87284 return err;
87285
87286- sys_chdir("/root");
87287+ sys_chdir((const char __force_user *)"/root");
87288 s = current->fs->pwd.dentry->d_sb;
87289 ROOT_DEV = s->s_dev;
87290 printk(KERN_INFO
87291@@ -485,18 +485,18 @@ void __init change_floppy(char *fmt, ...)
87292 va_start(args, fmt);
87293 vsprintf(buf, fmt, args);
87294 va_end(args);
87295- fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
87296+ fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
87297 if (fd >= 0) {
87298 sys_ioctl(fd, FDEJECT, 0);
87299 sys_close(fd);
87300 }
87301 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
87302- fd = sys_open("/dev/console", O_RDWR, 0);
87303+ fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
87304 if (fd >= 0) {
87305 sys_ioctl(fd, TCGETS, (long)&termios);
87306 termios.c_lflag &= ~ICANON;
87307 sys_ioctl(fd, TCSETSF, (long)&termios);
87308- sys_read(fd, &c, 1);
87309+ sys_read(fd, (char __user *)&c, 1);
87310 termios.c_lflag |= ICANON;
87311 sys_ioctl(fd, TCSETSF, (long)&termios);
87312 sys_close(fd);
87313@@ -590,8 +590,8 @@ void __init prepare_namespace(void)
87314 mount_root();
87315 out:
87316 devtmpfs_mount("dev");
87317- sys_mount(".", "/", NULL, MS_MOVE, NULL);
87318- sys_chroot(".");
87319+ sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
87320+ sys_chroot((const char __force_user *)".");
87321 }
87322
87323 static bool is_tmpfs;
87324diff --git a/init/do_mounts.h b/init/do_mounts.h
87325index f5b978a..69dbfe8 100644
87326--- a/init/do_mounts.h
87327+++ b/init/do_mounts.h
87328@@ -15,15 +15,15 @@ extern int root_mountflags;
87329
87330 static inline int create_dev(char *name, dev_t dev)
87331 {
87332- sys_unlink(name);
87333- return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
87334+ sys_unlink((char __force_user *)name);
87335+ return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
87336 }
87337
87338 #if BITS_PER_LONG == 32
87339 static inline u32 bstat(char *name)
87340 {
87341 struct stat64 stat;
87342- if (sys_stat64(name, &stat) != 0)
87343+ if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
87344 return 0;
87345 if (!S_ISBLK(stat.st_mode))
87346 return 0;
87347@@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
87348 static inline u32 bstat(char *name)
87349 {
87350 struct stat stat;
87351- if (sys_newstat(name, &stat) != 0)
87352+ if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
87353 return 0;
87354 if (!S_ISBLK(stat.st_mode))
87355 return 0;
87356diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
87357index 3e0878e..8a9d7a0 100644
87358--- a/init/do_mounts_initrd.c
87359+++ b/init/do_mounts_initrd.c
87360@@ -37,13 +37,13 @@ static int init_linuxrc(struct subprocess_info *info, struct cred *new)
87361 {
87362 sys_unshare(CLONE_FS | CLONE_FILES);
87363 /* stdin/stdout/stderr for /linuxrc */
87364- sys_open("/dev/console", O_RDWR, 0);
87365+ sys_open((const char __force_user *)"/dev/console", O_RDWR, 0);
87366 sys_dup(0);
87367 sys_dup(0);
87368 /* move initrd over / and chdir/chroot in initrd root */
87369- sys_chdir("/root");
87370- sys_mount(".", "/", NULL, MS_MOVE, NULL);
87371- sys_chroot(".");
87372+ sys_chdir((const char __force_user *)"/root");
87373+ sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
87374+ sys_chroot((const char __force_user *)".");
87375 sys_setsid();
87376 return 0;
87377 }
87378@@ -59,8 +59,8 @@ static void __init handle_initrd(void)
87379 create_dev("/dev/root.old", Root_RAM0);
87380 /* mount initrd on rootfs' /root */
87381 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
87382- sys_mkdir("/old", 0700);
87383- sys_chdir("/old");
87384+ sys_mkdir((const char __force_user *)"/old", 0700);
87385+ sys_chdir((const char __force_user *)"/old");
87386
87387 /* try loading default modules from initrd */
87388 load_default_modules();
87389@@ -80,31 +80,31 @@ static void __init handle_initrd(void)
87390 current->flags &= ~PF_FREEZER_SKIP;
87391
87392 /* move initrd to rootfs' /old */
87393- sys_mount("..", ".", NULL, MS_MOVE, NULL);
87394+ sys_mount((char __force_user *)"..", (char __force_user *)".", NULL, MS_MOVE, NULL);
87395 /* switch root and cwd back to / of rootfs */
87396- sys_chroot("..");
87397+ sys_chroot((const char __force_user *)"..");
87398
87399 if (new_decode_dev(real_root_dev) == Root_RAM0) {
87400- sys_chdir("/old");
87401+ sys_chdir((const char __force_user *)"/old");
87402 return;
87403 }
87404
87405- sys_chdir("/");
87406+ sys_chdir((const char __force_user *)"/");
87407 ROOT_DEV = new_decode_dev(real_root_dev);
87408 mount_root();
87409
87410 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
87411- error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
87412+ error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
87413 if (!error)
87414 printk("okay\n");
87415 else {
87416- int fd = sys_open("/dev/root.old", O_RDWR, 0);
87417+ int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
87418 if (error == -ENOENT)
87419 printk("/initrd does not exist. Ignored.\n");
87420 else
87421 printk("failed\n");
87422 printk(KERN_NOTICE "Unmounting old root\n");
87423- sys_umount("/old", MNT_DETACH);
87424+ sys_umount((char __force_user *)"/old", MNT_DETACH);
87425 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
87426 if (fd < 0) {
87427 error = fd;
87428@@ -127,11 +127,11 @@ int __init initrd_load(void)
87429 * mounted in the normal path.
87430 */
87431 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
87432- sys_unlink("/initrd.image");
87433+ sys_unlink((const char __force_user *)"/initrd.image");
87434 handle_initrd();
87435 return 1;
87436 }
87437 }
87438- sys_unlink("/initrd.image");
87439+ sys_unlink((const char __force_user *)"/initrd.image");
87440 return 0;
87441 }
87442diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
87443index 8cb6db5..d729f50 100644
87444--- a/init/do_mounts_md.c
87445+++ b/init/do_mounts_md.c
87446@@ -180,7 +180,7 @@ static void __init md_setup_drive(void)
87447 partitioned ? "_d" : "", minor,
87448 md_setup_args[ent].device_names);
87449
87450- fd = sys_open(name, 0, 0);
87451+ fd = sys_open((char __force_user *)name, 0, 0);
87452 if (fd < 0) {
87453 printk(KERN_ERR "md: open failed - cannot start "
87454 "array %s\n", name);
87455@@ -243,7 +243,7 @@ static void __init md_setup_drive(void)
87456 * array without it
87457 */
87458 sys_close(fd);
87459- fd = sys_open(name, 0, 0);
87460+ fd = sys_open((char __force_user *)name, 0, 0);
87461 sys_ioctl(fd, BLKRRPART, 0);
87462 }
87463 sys_close(fd);
87464@@ -293,7 +293,7 @@ static void __init autodetect_raid(void)
87465
87466 wait_for_device_probe();
87467
87468- fd = sys_open("/dev/md0", 0, 0);
87469+ fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
87470 if (fd >= 0) {
87471 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
87472 sys_close(fd);
87473diff --git a/init/init_task.c b/init/init_task.c
87474index ba0a7f36..2bcf1d5 100644
87475--- a/init/init_task.c
87476+++ b/init/init_task.c
87477@@ -22,5 +22,9 @@ EXPORT_SYMBOL(init_task);
87478 * Initial thread structure. Alignment of this is handled by a special
87479 * linker map entry.
87480 */
87481+#ifdef CONFIG_X86
87482+union thread_union init_thread_union __init_task_data;
87483+#else
87484 union thread_union init_thread_union __init_task_data =
87485 { INIT_THREAD_INFO(init_task) };
87486+#endif
87487diff --git a/init/initramfs.c b/init/initramfs.c
87488index ad1bd77..dca2c1b 100644
87489--- a/init/initramfs.c
87490+++ b/init/initramfs.c
87491@@ -25,7 +25,7 @@ static ssize_t __init xwrite(int fd, const char *p, size_t count)
87492
87493 /* sys_write only can write MAX_RW_COUNT aka 2G-4K bytes at most */
87494 while (count) {
87495- ssize_t rv = sys_write(fd, p, count);
87496+ ssize_t rv = sys_write(fd, (char __force_user *)p, count);
87497
87498 if (rv < 0) {
87499 if (rv == -EINTR || rv == -EAGAIN)
87500@@ -107,7 +107,7 @@ static void __init free_hash(void)
87501 }
87502 }
87503
87504-static long __init do_utime(char *filename, time_t mtime)
87505+static long __init do_utime(char __force_user *filename, time_t mtime)
87506 {
87507 struct timespec t[2];
87508
87509@@ -142,7 +142,7 @@ static void __init dir_utime(void)
87510 struct dir_entry *de, *tmp;
87511 list_for_each_entry_safe(de, tmp, &dir_list, list) {
87512 list_del(&de->list);
87513- do_utime(de->name, de->mtime);
87514+ do_utime((char __force_user *)de->name, de->mtime);
87515 kfree(de->name);
87516 kfree(de);
87517 }
87518@@ -304,7 +304,7 @@ static int __init maybe_link(void)
87519 if (nlink >= 2) {
87520 char *old = find_link(major, minor, ino, mode, collected);
87521 if (old)
87522- return (sys_link(old, collected) < 0) ? -1 : 1;
87523+ return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
87524 }
87525 return 0;
87526 }
87527@@ -313,11 +313,11 @@ static void __init clean_path(char *path, umode_t fmode)
87528 {
87529 struct stat st;
87530
87531- if (!sys_newlstat(path, &st) && (st.st_mode ^ fmode) & S_IFMT) {
87532+ if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode ^ fmode) & S_IFMT) {
87533 if (S_ISDIR(st.st_mode))
87534- sys_rmdir(path);
87535+ sys_rmdir((char __force_user *)path);
87536 else
87537- sys_unlink(path);
87538+ sys_unlink((char __force_user *)path);
87539 }
87540 }
87541
87542@@ -338,7 +338,7 @@ static int __init do_name(void)
87543 int openflags = O_WRONLY|O_CREAT;
87544 if (ml != 1)
87545 openflags |= O_TRUNC;
87546- wfd = sys_open(collected, openflags, mode);
87547+ wfd = sys_open((char __force_user *)collected, openflags, mode);
87548
87549 if (wfd >= 0) {
87550 sys_fchown(wfd, uid, gid);
87551@@ -350,17 +350,17 @@ static int __init do_name(void)
87552 }
87553 }
87554 } else if (S_ISDIR(mode)) {
87555- sys_mkdir(collected, mode);
87556- sys_chown(collected, uid, gid);
87557- sys_chmod(collected, mode);
87558+ sys_mkdir((char __force_user *)collected, mode);
87559+ sys_chown((char __force_user *)collected, uid, gid);
87560+ sys_chmod((char __force_user *)collected, mode);
87561 dir_add(collected, mtime);
87562 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
87563 S_ISFIFO(mode) || S_ISSOCK(mode)) {
87564 if (maybe_link() == 0) {
87565- sys_mknod(collected, mode, rdev);
87566- sys_chown(collected, uid, gid);
87567- sys_chmod(collected, mode);
87568- do_utime(collected, mtime);
87569+ sys_mknod((char __force_user *)collected, mode, rdev);
87570+ sys_chown((char __force_user *)collected, uid, gid);
87571+ sys_chmod((char __force_user *)collected, mode);
87572+ do_utime((char __force_user *)collected, mtime);
87573 }
87574 }
87575 return 0;
87576@@ -372,7 +372,7 @@ static int __init do_copy(void)
87577 if (xwrite(wfd, victim, body_len) != body_len)
87578 error("write error");
87579 sys_close(wfd);
87580- do_utime(vcollected, mtime);
87581+ do_utime((char __force_user *)vcollected, mtime);
87582 kfree(vcollected);
87583 eat(body_len);
87584 state = SkipIt;
87585@@ -390,9 +390,9 @@ static int __init do_symlink(void)
87586 {
87587 collected[N_ALIGN(name_len) + body_len] = '\0';
87588 clean_path(collected, 0);
87589- sys_symlink(collected + N_ALIGN(name_len), collected);
87590- sys_lchown(collected, uid, gid);
87591- do_utime(collected, mtime);
87592+ sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
87593+ sys_lchown((char __force_user *)collected, uid, gid);
87594+ do_utime((char __force_user *)collected, mtime);
87595 state = SkipIt;
87596 next_state = Reset;
87597 return 0;
87598diff --git a/init/main.c b/init/main.c
87599index 321d0ce..91b53e5 100644
87600--- a/init/main.c
87601+++ b/init/main.c
87602@@ -98,6 +98,8 @@ extern void radix_tree_init(void);
87603 static inline void mark_rodata_ro(void) { }
87604 #endif
87605
87606+extern void grsecurity_init(void);
87607+
87608 /*
87609 * Debug helper: via this flag we know that we are in 'early bootup code'
87610 * where only the boot processor is running with IRQ disabled. This means
87611@@ -159,6 +161,75 @@ static int __init set_reset_devices(char *str)
87612
87613 __setup("reset_devices", set_reset_devices);
87614
87615+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
87616+kgid_t grsec_proc_gid = KGIDT_INIT(CONFIG_GRKERNSEC_PROC_GID);
87617+static int __init setup_grsec_proc_gid(char *str)
87618+{
87619+ grsec_proc_gid = KGIDT_INIT(simple_strtol(str, NULL, 0));
87620+ return 1;
87621+}
87622+__setup("grsec_proc_gid=", setup_grsec_proc_gid);
87623+#endif
87624+
87625+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
87626+unsigned long pax_user_shadow_base __read_only;
87627+EXPORT_SYMBOL(pax_user_shadow_base);
87628+extern char pax_enter_kernel_user[];
87629+extern char pax_exit_kernel_user[];
87630+#endif
87631+
87632+#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
87633+static int __init setup_pax_nouderef(char *str)
87634+{
87635+#ifdef CONFIG_X86_32
87636+ unsigned int cpu;
87637+ struct desc_struct *gdt;
87638+
87639+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
87640+ gdt = get_cpu_gdt_table(cpu);
87641+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
87642+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
87643+ gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
87644+ gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
87645+ }
87646+ loadsegment(ds, __KERNEL_DS);
87647+ loadsegment(es, __KERNEL_DS);
87648+ loadsegment(ss, __KERNEL_DS);
87649+#else
87650+ memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
87651+ memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
87652+ clone_pgd_mask = ~(pgdval_t)0UL;
87653+ pax_user_shadow_base = 0UL;
87654+ setup_clear_cpu_cap(X86_FEATURE_PCID);
87655+ setup_clear_cpu_cap(X86_FEATURE_INVPCID);
87656+#endif
87657+
87658+ return 0;
87659+}
87660+early_param("pax_nouderef", setup_pax_nouderef);
87661+
87662+#ifdef CONFIG_X86_64
87663+static int __init setup_pax_weakuderef(char *str)
87664+{
87665+ if (clone_pgd_mask != ~(pgdval_t)0UL)
87666+ pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
87667+ return 1;
87668+}
87669+__setup("pax_weakuderef", setup_pax_weakuderef);
87670+#endif
87671+#endif
87672+
87673+#ifdef CONFIG_PAX_SOFTMODE
87674+int pax_softmode;
87675+
87676+static int __init setup_pax_softmode(char *str)
87677+{
87678+ get_option(&str, &pax_softmode);
87679+ return 1;
87680+}
87681+__setup("pax_softmode=", setup_pax_softmode);
87682+#endif
87683+
87684 static const char *argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
87685 const char *envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
87686 static const char *panic_later, *panic_param;
87687@@ -728,7 +799,7 @@ static bool __init_or_module initcall_blacklisted(initcall_t fn)
87688 struct blacklist_entry *entry;
87689 char *fn_name;
87690
87691- fn_name = kasprintf(GFP_KERNEL, "%pf", fn);
87692+ fn_name = kasprintf(GFP_KERNEL, "%pX", fn);
87693 if (!fn_name)
87694 return false;
87695
87696@@ -780,7 +851,7 @@ int __init_or_module do_one_initcall(initcall_t fn)
87697 {
87698 int count = preempt_count();
87699 int ret;
87700- char msgbuf[64];
87701+ const char *msg1 = "", *msg2 = "";
87702
87703 if (initcall_blacklisted(fn))
87704 return -EPERM;
87705@@ -790,18 +861,17 @@ int __init_or_module do_one_initcall(initcall_t fn)
87706 else
87707 ret = fn();
87708
87709- msgbuf[0] = 0;
87710-
87711 if (preempt_count() != count) {
87712- sprintf(msgbuf, "preemption imbalance ");
87713+ msg1 = " preemption imbalance";
87714 preempt_count_set(count);
87715 }
87716 if (irqs_disabled()) {
87717- strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
87718+ msg2 = " disabled interrupts";
87719 local_irq_enable();
87720 }
87721- WARN(msgbuf[0], "initcall %pF returned with %s\n", fn, msgbuf);
87722+ WARN(*msg1 || *msg2, "initcall %pF returned with%s%s\n", fn, msg1, msg2);
87723
87724+ add_latent_entropy();
87725 return ret;
87726 }
87727
87728@@ -907,8 +977,8 @@ static int run_init_process(const char *init_filename)
87729 {
87730 argv_init[0] = init_filename;
87731 return do_execve(getname_kernel(init_filename),
87732- (const char __user *const __user *)argv_init,
87733- (const char __user *const __user *)envp_init);
87734+ (const char __user *const __force_user *)argv_init,
87735+ (const char __user *const __force_user *)envp_init);
87736 }
87737
87738 static int try_to_run_init_process(const char *init_filename)
87739@@ -925,6 +995,10 @@ static int try_to_run_init_process(const char *init_filename)
87740 return ret;
87741 }
87742
87743+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
87744+extern int gr_init_ran;
87745+#endif
87746+
87747 static noinline void __init kernel_init_freeable(void);
87748
87749 static int __ref kernel_init(void *unused)
87750@@ -949,6 +1023,11 @@ static int __ref kernel_init(void *unused)
87751 ramdisk_execute_command, ret);
87752 }
87753
87754+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
87755+ /* if no initrd was used, be extra sure we enforce chroot restrictions */
87756+ gr_init_ran = 1;
87757+#endif
87758+
87759 /*
87760 * We try each of these until one succeeds.
87761 *
87762@@ -1004,7 +1083,7 @@ static noinline void __init kernel_init_freeable(void)
87763 do_basic_setup();
87764
87765 /* Open the /dev/console on the rootfs, this should never fail */
87766- if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
87767+ if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
87768 pr_err("Warning: unable to open an initial console.\n");
87769
87770 (void) sys_dup(0);
87771@@ -1017,11 +1096,13 @@ static noinline void __init kernel_init_freeable(void)
87772 if (!ramdisk_execute_command)
87773 ramdisk_execute_command = "/init";
87774
87775- if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
87776+ if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
87777 ramdisk_execute_command = NULL;
87778 prepare_namespace();
87779 }
87780
87781+ grsecurity_init();
87782+
87783 /*
87784 * Ok, we have completed the initial bootup, and
87785 * we're essentially up and running. Get rid of the
87786diff --git a/ipc/compat.c b/ipc/compat.c
87787index 9b3c85f..1c4d897 100644
87788--- a/ipc/compat.c
87789+++ b/ipc/compat.c
87790@@ -396,7 +396,7 @@ COMPAT_SYSCALL_DEFINE6(ipc, u32, call, int, first, int, second,
87791 COMPAT_SHMLBA);
87792 if (err < 0)
87793 return err;
87794- return put_user(raddr, (compat_ulong_t *)compat_ptr(third));
87795+ return put_user(raddr, (compat_ulong_t __user *)compat_ptr(third));
87796 }
87797 case SHMDT:
87798 return sys_shmdt(compat_ptr(ptr));
87799diff --git a/ipc/ipc_sysctl.c b/ipc/ipc_sysctl.c
87800index e8075b2..76f2c6a 100644
87801--- a/ipc/ipc_sysctl.c
87802+++ b/ipc/ipc_sysctl.c
87803@@ -30,7 +30,7 @@ static void *get_ipc(struct ctl_table *table)
87804 static int proc_ipc_dointvec(struct ctl_table *table, int write,
87805 void __user *buffer, size_t *lenp, loff_t *ppos)
87806 {
87807- struct ctl_table ipc_table;
87808+ ctl_table_no_const ipc_table;
87809
87810 memcpy(&ipc_table, table, sizeof(ipc_table));
87811 ipc_table.data = get_ipc(table);
87812@@ -41,7 +41,7 @@ static int proc_ipc_dointvec(struct ctl_table *table, int write,
87813 static int proc_ipc_dointvec_minmax(struct ctl_table *table, int write,
87814 void __user *buffer, size_t *lenp, loff_t *ppos)
87815 {
87816- struct ctl_table ipc_table;
87817+ ctl_table_no_const ipc_table;
87818
87819 memcpy(&ipc_table, table, sizeof(ipc_table));
87820 ipc_table.data = get_ipc(table);
87821@@ -65,7 +65,7 @@ static int proc_ipc_dointvec_minmax_orphans(struct ctl_table *table, int write,
87822 static int proc_ipc_callback_dointvec_minmax(struct ctl_table *table, int write,
87823 void __user *buffer, size_t *lenp, loff_t *ppos)
87824 {
87825- struct ctl_table ipc_table;
87826+ ctl_table_no_const ipc_table;
87827 size_t lenp_bef = *lenp;
87828 int rc;
87829
87830@@ -88,7 +88,7 @@ static int proc_ipc_callback_dointvec_minmax(struct ctl_table *table, int write,
87831 static int proc_ipc_doulongvec_minmax(struct ctl_table *table, int write,
87832 void __user *buffer, size_t *lenp, loff_t *ppos)
87833 {
87834- struct ctl_table ipc_table;
87835+ ctl_table_no_const ipc_table;
87836 memcpy(&ipc_table, table, sizeof(ipc_table));
87837 ipc_table.data = get_ipc(table);
87838
87839@@ -122,7 +122,7 @@ static void ipc_auto_callback(int val)
87840 static int proc_ipcauto_dointvec_minmax(struct ctl_table *table, int write,
87841 void __user *buffer, size_t *lenp, loff_t *ppos)
87842 {
87843- struct ctl_table ipc_table;
87844+ ctl_table_no_const ipc_table;
87845 int oldval;
87846 int rc;
87847
87848diff --git a/ipc/mq_sysctl.c b/ipc/mq_sysctl.c
87849index 68d4e95..1477ded 100644
87850--- a/ipc/mq_sysctl.c
87851+++ b/ipc/mq_sysctl.c
87852@@ -25,7 +25,7 @@ static void *get_mq(struct ctl_table *table)
87853 static int proc_mq_dointvec(struct ctl_table *table, int write,
87854 void __user *buffer, size_t *lenp, loff_t *ppos)
87855 {
87856- struct ctl_table mq_table;
87857+ ctl_table_no_const mq_table;
87858 memcpy(&mq_table, table, sizeof(mq_table));
87859 mq_table.data = get_mq(table);
87860
87861@@ -35,7 +35,7 @@ static int proc_mq_dointvec(struct ctl_table *table, int write,
87862 static int proc_mq_dointvec_minmax(struct ctl_table *table, int write,
87863 void __user *buffer, size_t *lenp, loff_t *ppos)
87864 {
87865- struct ctl_table mq_table;
87866+ ctl_table_no_const mq_table;
87867 memcpy(&mq_table, table, sizeof(mq_table));
87868 mq_table.data = get_mq(table);
87869
87870diff --git a/ipc/mqueue.c b/ipc/mqueue.c
87871index 4fcf39a..d3cc2ec 100644
87872--- a/ipc/mqueue.c
87873+++ b/ipc/mqueue.c
87874@@ -278,6 +278,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
87875 mq_bytes = mq_treesize + (info->attr.mq_maxmsg *
87876 info->attr.mq_msgsize);
87877
87878+ gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
87879 spin_lock(&mq_lock);
87880 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
87881 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
87882diff --git a/ipc/shm.c b/ipc/shm.c
87883index 0145479..3d27947 100644
87884--- a/ipc/shm.c
87885+++ b/ipc/shm.c
87886@@ -72,6 +72,14 @@ static void shm_destroy(struct ipc_namespace *ns, struct shmid_kernel *shp);
87887 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
87888 #endif
87889
87890+#ifdef CONFIG_GRKERNSEC
87891+extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
87892+ const u64 shm_createtime, const kuid_t cuid,
87893+ const int shmid);
87894+extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
87895+ const u64 shm_createtime);
87896+#endif
87897+
87898 void shm_init_ns(struct ipc_namespace *ns)
87899 {
87900 ns->shm_ctlmax = SHMMAX;
87901@@ -559,6 +567,9 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
87902 shp->shm_lprid = 0;
87903 shp->shm_atim = shp->shm_dtim = 0;
87904 shp->shm_ctim = get_seconds();
87905+#ifdef CONFIG_GRKERNSEC
87906+ shp->shm_createtime = ktime_get_ns();
87907+#endif
87908 shp->shm_segsz = size;
87909 shp->shm_nattch = 0;
87910 shp->shm_file = file;
87911@@ -1095,6 +1106,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
87912 f_mode = FMODE_READ | FMODE_WRITE;
87913 }
87914 if (shmflg & SHM_EXEC) {
87915+
87916+#ifdef CONFIG_PAX_MPROTECT
87917+ if (current->mm->pax_flags & MF_PAX_MPROTECT)
87918+ goto out;
87919+#endif
87920+
87921 prot |= PROT_EXEC;
87922 acc_mode |= S_IXUGO;
87923 }
87924@@ -1119,6 +1136,15 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
87925 if (err)
87926 goto out_unlock;
87927
87928+#ifdef CONFIG_GRKERNSEC
87929+ if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
87930+ shp->shm_perm.cuid, shmid) ||
87931+ !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
87932+ err = -EACCES;
87933+ goto out_unlock;
87934+ }
87935+#endif
87936+
87937 ipc_lock_object(&shp->shm_perm);
87938
87939 /* check if shm_destroy() is tearing down shp */
87940@@ -1131,6 +1157,9 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
87941 path = shp->shm_file->f_path;
87942 path_get(&path);
87943 shp->shm_nattch++;
87944+#ifdef CONFIG_GRKERNSEC
87945+ shp->shm_lapid = current->pid;
87946+#endif
87947 size = i_size_read(path.dentry->d_inode);
87948 ipc_unlock_object(&shp->shm_perm);
87949 rcu_read_unlock();
87950diff --git a/ipc/util.c b/ipc/util.c
87951index 88adc32..3867c68 100644
87952--- a/ipc/util.c
87953+++ b/ipc/util.c
87954@@ -71,6 +71,8 @@ struct ipc_proc_iface {
87955 int (*show)(struct seq_file *, void *);
87956 };
87957
87958+extern int gr_ipc_permitted(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, int requested_mode, int granted_mode);
87959+
87960 static void ipc_memory_notifier(struct work_struct *work)
87961 {
87962 ipcns_notify(IPCNS_MEMCHANGED);
87963@@ -537,6 +539,10 @@ int ipcperms(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, short flag)
87964 granted_mode >>= 6;
87965 else if (in_group_p(ipcp->cgid) || in_group_p(ipcp->gid))
87966 granted_mode >>= 3;
87967+
87968+ if (!gr_ipc_permitted(ns, ipcp, requested_mode, granted_mode))
87969+ return -1;
87970+
87971 /* is there some bit set in requested_mode but not in granted_mode? */
87972 if ((requested_mode & ~granted_mode & 0007) &&
87973 !ns_capable(ns->user_ns, CAP_IPC_OWNER))
87974diff --git a/kernel/audit.c b/kernel/audit.c
87975index cebb11d..4e0295f 100644
87976--- a/kernel/audit.c
87977+++ b/kernel/audit.c
87978@@ -122,7 +122,7 @@ u32 audit_sig_sid = 0;
87979 3) suppressed due to audit_rate_limit
87980 4) suppressed due to audit_backlog_limit
87981 */
87982-static atomic_t audit_lost = ATOMIC_INIT(0);
87983+static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
87984
87985 /* The netlink socket. */
87986 static struct sock *audit_sock;
87987@@ -256,7 +256,7 @@ void audit_log_lost(const char *message)
87988 unsigned long now;
87989 int print;
87990
87991- atomic_inc(&audit_lost);
87992+ atomic_inc_unchecked(&audit_lost);
87993
87994 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
87995
87996@@ -273,7 +273,7 @@ void audit_log_lost(const char *message)
87997 if (print) {
87998 if (printk_ratelimit())
87999 pr_warn("audit_lost=%u audit_rate_limit=%u audit_backlog_limit=%u\n",
88000- atomic_read(&audit_lost),
88001+ atomic_read_unchecked(&audit_lost),
88002 audit_rate_limit,
88003 audit_backlog_limit);
88004 audit_panic(message);
88005@@ -840,7 +840,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
88006 s.pid = audit_pid;
88007 s.rate_limit = audit_rate_limit;
88008 s.backlog_limit = audit_backlog_limit;
88009- s.lost = atomic_read(&audit_lost);
88010+ s.lost = atomic_read_unchecked(&audit_lost);
88011 s.backlog = skb_queue_len(&audit_skb_queue);
88012 s.version = AUDIT_VERSION_LATEST;
88013 s.backlog_wait_time = audit_backlog_wait_time;
88014diff --git a/kernel/auditsc.c b/kernel/auditsc.c
88015index e420a0c..38137fa 100644
88016--- a/kernel/auditsc.c
88017+++ b/kernel/auditsc.c
88018@@ -2014,7 +2014,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
88019 }
88020
88021 /* global counter which is incremented every time something logs in */
88022-static atomic_t session_id = ATOMIC_INIT(0);
88023+static atomic_unchecked_t session_id = ATOMIC_INIT(0);
88024
88025 static int audit_set_loginuid_perm(kuid_t loginuid)
88026 {
88027@@ -2081,7 +2081,7 @@ int audit_set_loginuid(kuid_t loginuid)
88028
88029 /* are we setting or clearing? */
88030 if (uid_valid(loginuid))
88031- sessionid = (unsigned int)atomic_inc_return(&session_id);
88032+ sessionid = (unsigned int)atomic_inc_return_unchecked(&session_id);
88033
88034 task->sessionid = sessionid;
88035 task->loginuid = loginuid;
88036diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c
88037index d6594e4..597264b 100644
88038--- a/kernel/bpf/core.c
88039+++ b/kernel/bpf/core.c
88040@@ -143,14 +143,17 @@ bpf_jit_binary_alloc(unsigned int proglen, u8 **image_ptr,
88041 * random section of illegal instructions.
88042 */
88043 size = round_up(proglen + sizeof(*hdr) + 128, PAGE_SIZE);
88044- hdr = module_alloc(size);
88045+ hdr = module_alloc_exec(size);
88046 if (hdr == NULL)
88047 return NULL;
88048
88049 /* Fill space with illegal/arch-dep instructions. */
88050 bpf_fill_ill_insns(hdr, size);
88051
88052+ pax_open_kernel();
88053 hdr->pages = size / PAGE_SIZE;
88054+ pax_close_kernel();
88055+
88056 hole = min_t(unsigned int, size - (proglen + sizeof(*hdr)),
88057 PAGE_SIZE - sizeof(*hdr));
88058 start = (prandom_u32() % hole) & ~(alignment - 1);
88059@@ -163,7 +166,7 @@ bpf_jit_binary_alloc(unsigned int proglen, u8 **image_ptr,
88060
88061 void bpf_jit_binary_free(struct bpf_binary_header *hdr)
88062 {
88063- module_free(NULL, hdr);
88064+ module_free_exec(NULL, hdr);
88065 }
88066 #endif /* CONFIG_BPF_JIT */
88067
88068diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
88069index ba61c8c..c60c486 100644
88070--- a/kernel/bpf/syscall.c
88071+++ b/kernel/bpf/syscall.c
88072@@ -539,11 +539,15 @@ SYSCALL_DEFINE3(bpf, int, cmd, union bpf_attr __user *, uattr, unsigned int, siz
88073 int err;
88074
88075 /* the syscall is limited to root temporarily. This restriction will be
88076- * lifted when security audit is clean. Note that eBPF+tracing must have
88077- * this restriction, since it may pass kernel data to user space
88078+ * lifted by upstream when a half-assed security audit is clean. Note
88079+ * that eBPF+tracing must have this restriction, since it may pass
88080+ * kernel data to user space
88081 */
88082 if (!capable(CAP_SYS_ADMIN))
88083 return -EPERM;
88084+#ifdef CONFIG_GRKERNSEC
88085+ return -EPERM;
88086+#endif
88087
88088 if (!access_ok(VERIFY_READ, uattr, 1))
88089 return -EFAULT;
88090diff --git a/kernel/capability.c b/kernel/capability.c
88091index 989f5bf..d317ca0 100644
88092--- a/kernel/capability.c
88093+++ b/kernel/capability.c
88094@@ -192,6 +192,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
88095 * before modification is attempted and the application
88096 * fails.
88097 */
88098+ if (tocopy > ARRAY_SIZE(kdata))
88099+ return -EFAULT;
88100+
88101 if (copy_to_user(dataptr, kdata, tocopy
88102 * sizeof(struct __user_cap_data_struct))) {
88103 return -EFAULT;
88104@@ -297,10 +300,11 @@ bool has_ns_capability(struct task_struct *t,
88105 int ret;
88106
88107 rcu_read_lock();
88108- ret = security_capable(__task_cred(t), ns, cap);
88109+ ret = security_capable(__task_cred(t), ns, cap) == 0 &&
88110+ gr_task_is_capable(t, __task_cred(t), cap);
88111 rcu_read_unlock();
88112
88113- return (ret == 0);
88114+ return ret;
88115 }
88116
88117 /**
88118@@ -337,10 +341,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
88119 int ret;
88120
88121 rcu_read_lock();
88122- ret = security_capable_noaudit(__task_cred(t), ns, cap);
88123+ ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
88124 rcu_read_unlock();
88125
88126- return (ret == 0);
88127+ return ret;
88128 }
88129
88130 /**
88131@@ -378,7 +382,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
88132 BUG();
88133 }
88134
88135- if (security_capable(current_cred(), ns, cap) == 0) {
88136+ if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
88137 current->flags |= PF_SUPERPRIV;
88138 return true;
88139 }
88140@@ -386,6 +390,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
88141 }
88142 EXPORT_SYMBOL(ns_capable);
88143
88144+bool ns_capable_nolog(struct user_namespace *ns, int cap)
88145+{
88146+ if (unlikely(!cap_valid(cap))) {
88147+ printk(KERN_CRIT "capable_nolog() called with invalid cap=%u\n", cap);
88148+ BUG();
88149+ }
88150+
88151+ if (security_capable_noaudit(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
88152+ current->flags |= PF_SUPERPRIV;
88153+ return true;
88154+ }
88155+ return false;
88156+}
88157+EXPORT_SYMBOL(ns_capable_nolog);
88158+
88159 /**
88160 * file_ns_capable - Determine if the file's opener had a capability in effect
88161 * @file: The file we want to check
88162@@ -427,6 +446,12 @@ bool capable(int cap)
88163 }
88164 EXPORT_SYMBOL(capable);
88165
88166+bool capable_nolog(int cap)
88167+{
88168+ return ns_capable_nolog(&init_user_ns, cap);
88169+}
88170+EXPORT_SYMBOL(capable_nolog);
88171+
88172 /**
88173 * capable_wrt_inode_uidgid - Check nsown_capable and uid and gid mapped
88174 * @inode: The inode in question
88175@@ -444,3 +469,12 @@ bool capable_wrt_inode_uidgid(const struct inode *inode, int cap)
88176 kgid_has_mapping(ns, inode->i_gid);
88177 }
88178 EXPORT_SYMBOL(capable_wrt_inode_uidgid);
88179+
88180+bool capable_wrt_inode_uidgid_nolog(const struct inode *inode, int cap)
88181+{
88182+ struct user_namespace *ns = current_user_ns();
88183+
88184+ return ns_capable_nolog(ns, cap) && kuid_has_mapping(ns, inode->i_uid) &&
88185+ kgid_has_mapping(ns, inode->i_gid);
88186+}
88187+EXPORT_SYMBOL(capable_wrt_inode_uidgid_nolog);
88188diff --git a/kernel/cgroup.c b/kernel/cgroup.c
88189index 136ecea..45157a6 100644
88190--- a/kernel/cgroup.c
88191+++ b/kernel/cgroup.c
88192@@ -5276,6 +5276,9 @@ static void cgroup_release_agent(struct work_struct *work)
88193 if (!pathbuf || !agentbuf)
88194 goto out;
88195
88196+ if (agentbuf[0] == '\0')
88197+ goto out;
88198+
88199 path = cgroup_path(cgrp, pathbuf, PATH_MAX);
88200 if (!path)
88201 goto out;
88202@@ -5461,7 +5464,7 @@ static int cgroup_css_links_read(struct seq_file *seq, void *v)
88203 struct task_struct *task;
88204 int count = 0;
88205
88206- seq_printf(seq, "css_set %p\n", cset);
88207+ seq_printf(seq, "css_set %pK\n", cset);
88208
88209 list_for_each_entry(task, &cset->tasks, cg_list) {
88210 if (count++ > MAX_TASKS_SHOWN_PER_CSS)
88211diff --git a/kernel/compat.c b/kernel/compat.c
88212index ebb3c36..1df606e 100644
88213--- a/kernel/compat.c
88214+++ b/kernel/compat.c
88215@@ -13,6 +13,7 @@
88216
88217 #include <linux/linkage.h>
88218 #include <linux/compat.h>
88219+#include <linux/module.h>
88220 #include <linux/errno.h>
88221 #include <linux/time.h>
88222 #include <linux/signal.h>
88223@@ -220,7 +221,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
88224 mm_segment_t oldfs;
88225 long ret;
88226
88227- restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
88228+ restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
88229 oldfs = get_fs();
88230 set_fs(KERNEL_DS);
88231 ret = hrtimer_nanosleep_restart(restart);
88232@@ -252,7 +253,7 @@ COMPAT_SYSCALL_DEFINE2(nanosleep, struct compat_timespec __user *, rqtp,
88233 oldfs = get_fs();
88234 set_fs(KERNEL_DS);
88235 ret = hrtimer_nanosleep(&tu,
88236- rmtp ? (struct timespec __user *)&rmt : NULL,
88237+ rmtp ? (struct timespec __force_user *)&rmt : NULL,
88238 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
88239 set_fs(oldfs);
88240
88241@@ -379,7 +380,7 @@ COMPAT_SYSCALL_DEFINE1(sigpending, compat_old_sigset_t __user *, set)
88242 mm_segment_t old_fs = get_fs();
88243
88244 set_fs(KERNEL_DS);
88245- ret = sys_sigpending((old_sigset_t __user *) &s);
88246+ ret = sys_sigpending((old_sigset_t __force_user *) &s);
88247 set_fs(old_fs);
88248 if (ret == 0)
88249 ret = put_user(s, set);
88250@@ -469,7 +470,7 @@ COMPAT_SYSCALL_DEFINE2(old_getrlimit, unsigned int, resource,
88251 mm_segment_t old_fs = get_fs();
88252
88253 set_fs(KERNEL_DS);
88254- ret = sys_old_getrlimit(resource, (struct rlimit __user *)&r);
88255+ ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
88256 set_fs(old_fs);
88257
88258 if (!ret) {
88259@@ -551,8 +552,8 @@ COMPAT_SYSCALL_DEFINE4(wait4,
88260 set_fs (KERNEL_DS);
88261 ret = sys_wait4(pid,
88262 (stat_addr ?
88263- (unsigned int __user *) &status : NULL),
88264- options, (struct rusage __user *) &r);
88265+ (unsigned int __force_user *) &status : NULL),
88266+ options, (struct rusage __force_user *) &r);
88267 set_fs (old_fs);
88268
88269 if (ret > 0) {
88270@@ -578,8 +579,8 @@ COMPAT_SYSCALL_DEFINE5(waitid,
88271 memset(&info, 0, sizeof(info));
88272
88273 set_fs(KERNEL_DS);
88274- ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
88275- uru ? (struct rusage __user *)&ru : NULL);
88276+ ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
88277+ uru ? (struct rusage __force_user *)&ru : NULL);
88278 set_fs(old_fs);
88279
88280 if ((ret < 0) || (info.si_signo == 0))
88281@@ -713,8 +714,8 @@ COMPAT_SYSCALL_DEFINE4(timer_settime, timer_t, timer_id, int, flags,
88282 oldfs = get_fs();
88283 set_fs(KERNEL_DS);
88284 err = sys_timer_settime(timer_id, flags,
88285- (struct itimerspec __user *) &newts,
88286- (struct itimerspec __user *) &oldts);
88287+ (struct itimerspec __force_user *) &newts,
88288+ (struct itimerspec __force_user *) &oldts);
88289 set_fs(oldfs);
88290 if (!err && old && put_compat_itimerspec(old, &oldts))
88291 return -EFAULT;
88292@@ -731,7 +732,7 @@ COMPAT_SYSCALL_DEFINE2(timer_gettime, timer_t, timer_id,
88293 oldfs = get_fs();
88294 set_fs(KERNEL_DS);
88295 err = sys_timer_gettime(timer_id,
88296- (struct itimerspec __user *) &ts);
88297+ (struct itimerspec __force_user *) &ts);
88298 set_fs(oldfs);
88299 if (!err && put_compat_itimerspec(setting, &ts))
88300 return -EFAULT;
88301@@ -750,7 +751,7 @@ COMPAT_SYSCALL_DEFINE2(clock_settime, clockid_t, which_clock,
88302 oldfs = get_fs();
88303 set_fs(KERNEL_DS);
88304 err = sys_clock_settime(which_clock,
88305- (struct timespec __user *) &ts);
88306+ (struct timespec __force_user *) &ts);
88307 set_fs(oldfs);
88308 return err;
88309 }
88310@@ -765,7 +766,7 @@ COMPAT_SYSCALL_DEFINE2(clock_gettime, clockid_t, which_clock,
88311 oldfs = get_fs();
88312 set_fs(KERNEL_DS);
88313 err = sys_clock_gettime(which_clock,
88314- (struct timespec __user *) &ts);
88315+ (struct timespec __force_user *) &ts);
88316 set_fs(oldfs);
88317 if (!err && compat_put_timespec(&ts, tp))
88318 return -EFAULT;
88319@@ -785,7 +786,7 @@ COMPAT_SYSCALL_DEFINE2(clock_adjtime, clockid_t, which_clock,
88320
88321 oldfs = get_fs();
88322 set_fs(KERNEL_DS);
88323- ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
88324+ ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
88325 set_fs(oldfs);
88326
88327 err = compat_put_timex(utp, &txc);
88328@@ -805,7 +806,7 @@ COMPAT_SYSCALL_DEFINE2(clock_getres, clockid_t, which_clock,
88329 oldfs = get_fs();
88330 set_fs(KERNEL_DS);
88331 err = sys_clock_getres(which_clock,
88332- (struct timespec __user *) &ts);
88333+ (struct timespec __force_user *) &ts);
88334 set_fs(oldfs);
88335 if (!err && tp && compat_put_timespec(&ts, tp))
88336 return -EFAULT;
88337@@ -819,7 +820,7 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
88338 struct timespec tu;
88339 struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
88340
88341- restart->nanosleep.rmtp = (struct timespec __user *) &tu;
88342+ restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
88343 oldfs = get_fs();
88344 set_fs(KERNEL_DS);
88345 err = clock_nanosleep_restart(restart);
88346@@ -851,8 +852,8 @@ COMPAT_SYSCALL_DEFINE4(clock_nanosleep, clockid_t, which_clock, int, flags,
88347 oldfs = get_fs();
88348 set_fs(KERNEL_DS);
88349 err = sys_clock_nanosleep(which_clock, flags,
88350- (struct timespec __user *) &in,
88351- (struct timespec __user *) &out);
88352+ (struct timespec __force_user *) &in,
88353+ (struct timespec __force_user *) &out);
88354 set_fs(oldfs);
88355
88356 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
88357@@ -1146,7 +1147,7 @@ COMPAT_SYSCALL_DEFINE2(sched_rr_get_interval,
88358 mm_segment_t old_fs = get_fs();
88359
88360 set_fs(KERNEL_DS);
88361- ret = sys_sched_rr_get_interval(pid, (struct timespec __user *)&t);
88362+ ret = sys_sched_rr_get_interval(pid, (struct timespec __force_user *)&t);
88363 set_fs(old_fs);
88364 if (compat_put_timespec(&t, interval))
88365 return -EFAULT;
88366diff --git a/kernel/configs.c b/kernel/configs.c
88367index c18b1f1..b9a0132 100644
88368--- a/kernel/configs.c
88369+++ b/kernel/configs.c
88370@@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
88371 struct proc_dir_entry *entry;
88372
88373 /* create the current config file */
88374+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
88375+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
88376+ entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
88377+ &ikconfig_file_ops);
88378+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
88379+ entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
88380+ &ikconfig_file_ops);
88381+#endif
88382+#else
88383 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
88384 &ikconfig_file_ops);
88385+#endif
88386+
88387 if (!entry)
88388 return -ENOMEM;
88389
88390diff --git a/kernel/cred.c b/kernel/cred.c
88391index e0573a4..26c0fd3 100644
88392--- a/kernel/cred.c
88393+++ b/kernel/cred.c
88394@@ -164,6 +164,16 @@ void exit_creds(struct task_struct *tsk)
88395 validate_creds(cred);
88396 alter_cred_subscribers(cred, -1);
88397 put_cred(cred);
88398+
88399+#ifdef CONFIG_GRKERNSEC_SETXID
88400+ cred = (struct cred *) tsk->delayed_cred;
88401+ if (cred != NULL) {
88402+ tsk->delayed_cred = NULL;
88403+ validate_creds(cred);
88404+ alter_cred_subscribers(cred, -1);
88405+ put_cred(cred);
88406+ }
88407+#endif
88408 }
88409
88410 /**
88411@@ -411,7 +421,7 @@ static bool cred_cap_issubset(const struct cred *set, const struct cred *subset)
88412 * Always returns 0 thus allowing this function to be tail-called at the end
88413 * of, say, sys_setgid().
88414 */
88415-int commit_creds(struct cred *new)
88416+static int __commit_creds(struct cred *new)
88417 {
88418 struct task_struct *task = current;
88419 const struct cred *old = task->real_cred;
88420@@ -430,6 +440,8 @@ int commit_creds(struct cred *new)
88421
88422 get_cred(new); /* we will require a ref for the subj creds too */
88423
88424+ gr_set_role_label(task, new->uid, new->gid);
88425+
88426 /* dumpability changes */
88427 if (!uid_eq(old->euid, new->euid) ||
88428 !gid_eq(old->egid, new->egid) ||
88429@@ -479,6 +491,105 @@ int commit_creds(struct cred *new)
88430 put_cred(old);
88431 return 0;
88432 }
88433+#ifdef CONFIG_GRKERNSEC_SETXID
88434+extern int set_user(struct cred *new);
88435+
88436+void gr_delayed_cred_worker(void)
88437+{
88438+ const struct cred *new = current->delayed_cred;
88439+ struct cred *ncred;
88440+
88441+ current->delayed_cred = NULL;
88442+
88443+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID) && new != NULL) {
88444+ // from doing get_cred on it when queueing this
88445+ put_cred(new);
88446+ return;
88447+ } else if (new == NULL)
88448+ return;
88449+
88450+ ncred = prepare_creds();
88451+ if (!ncred)
88452+ goto die;
88453+ // uids
88454+ ncred->uid = new->uid;
88455+ ncred->euid = new->euid;
88456+ ncred->suid = new->suid;
88457+ ncred->fsuid = new->fsuid;
88458+ // gids
88459+ ncred->gid = new->gid;
88460+ ncred->egid = new->egid;
88461+ ncred->sgid = new->sgid;
88462+ ncred->fsgid = new->fsgid;
88463+ // groups
88464+ set_groups(ncred, new->group_info);
88465+ // caps
88466+ ncred->securebits = new->securebits;
88467+ ncred->cap_inheritable = new->cap_inheritable;
88468+ ncred->cap_permitted = new->cap_permitted;
88469+ ncred->cap_effective = new->cap_effective;
88470+ ncred->cap_bset = new->cap_bset;
88471+
88472+ if (set_user(ncred)) {
88473+ abort_creds(ncred);
88474+ goto die;
88475+ }
88476+
88477+ // from doing get_cred on it when queueing this
88478+ put_cred(new);
88479+
88480+ __commit_creds(ncred);
88481+ return;
88482+die:
88483+ // from doing get_cred on it when queueing this
88484+ put_cred(new);
88485+ do_group_exit(SIGKILL);
88486+}
88487+#endif
88488+
88489+int commit_creds(struct cred *new)
88490+{
88491+#ifdef CONFIG_GRKERNSEC_SETXID
88492+ int ret;
88493+ int schedule_it = 0;
88494+ struct task_struct *t;
88495+ unsigned oldsecurebits = current_cred()->securebits;
88496+
88497+ /* we won't get called with tasklist_lock held for writing
88498+ and interrupts disabled as the cred struct in that case is
88499+ init_cred
88500+ */
88501+ if (grsec_enable_setxid && !current_is_single_threaded() &&
88502+ uid_eq(current_uid(), GLOBAL_ROOT_UID) &&
88503+ !uid_eq(new->uid, GLOBAL_ROOT_UID)) {
88504+ schedule_it = 1;
88505+ }
88506+ ret = __commit_creds(new);
88507+ if (schedule_it) {
88508+ rcu_read_lock();
88509+ read_lock(&tasklist_lock);
88510+ for (t = next_thread(current); t != current;
88511+ t = next_thread(t)) {
88512+ /* we'll check if the thread has uid 0 in
88513+ * the delayed worker routine
88514+ */
88515+ if (task_securebits(t) == oldsecurebits &&
88516+ t->delayed_cred == NULL) {
88517+ t->delayed_cred = get_cred(new);
88518+ set_tsk_thread_flag(t, TIF_GRSEC_SETXID);
88519+ set_tsk_need_resched(t);
88520+ }
88521+ }
88522+ read_unlock(&tasklist_lock);
88523+ rcu_read_unlock();
88524+ }
88525+
88526+ return ret;
88527+#else
88528+ return __commit_creds(new);
88529+#endif
88530+}
88531+
88532 EXPORT_SYMBOL(commit_creds);
88533
88534 /**
88535diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
88536index 1adf62b..7736e06 100644
88537--- a/kernel/debug/debug_core.c
88538+++ b/kernel/debug/debug_core.c
88539@@ -124,7 +124,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
88540 */
88541 static atomic_t masters_in_kgdb;
88542 static atomic_t slaves_in_kgdb;
88543-static atomic_t kgdb_break_tasklet_var;
88544+static atomic_unchecked_t kgdb_break_tasklet_var;
88545 atomic_t kgdb_setting_breakpoint;
88546
88547 struct task_struct *kgdb_usethread;
88548@@ -134,7 +134,7 @@ int kgdb_single_step;
88549 static pid_t kgdb_sstep_pid;
88550
88551 /* to keep track of the CPU which is doing the single stepping*/
88552-atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
88553+atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
88554
88555 /*
88556 * If you are debugging a problem where roundup (the collection of
88557@@ -549,7 +549,7 @@ return_normal:
88558 * kernel will only try for the value of sstep_tries before
88559 * giving up and continuing on.
88560 */
88561- if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
88562+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
88563 (kgdb_info[cpu].task &&
88564 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
88565 atomic_set(&kgdb_active, -1);
88566@@ -647,8 +647,8 @@ cpu_master_loop:
88567 }
88568
88569 kgdb_restore:
88570- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
88571- int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
88572+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
88573+ int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
88574 if (kgdb_info[sstep_cpu].task)
88575 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
88576 else
88577@@ -925,18 +925,18 @@ static void kgdb_unregister_callbacks(void)
88578 static void kgdb_tasklet_bpt(unsigned long ing)
88579 {
88580 kgdb_breakpoint();
88581- atomic_set(&kgdb_break_tasklet_var, 0);
88582+ atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
88583 }
88584
88585 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
88586
88587 void kgdb_schedule_breakpoint(void)
88588 {
88589- if (atomic_read(&kgdb_break_tasklet_var) ||
88590+ if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
88591 atomic_read(&kgdb_active) != -1 ||
88592 atomic_read(&kgdb_setting_breakpoint))
88593 return;
88594- atomic_inc(&kgdb_break_tasklet_var);
88595+ atomic_inc_unchecked(&kgdb_break_tasklet_var);
88596 tasklet_schedule(&kgdb_tasklet_breakpoint);
88597 }
88598 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
88599diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
88600index 379650b..30c5180 100644
88601--- a/kernel/debug/kdb/kdb_main.c
88602+++ b/kernel/debug/kdb/kdb_main.c
88603@@ -1977,7 +1977,7 @@ static int kdb_lsmod(int argc, const char **argv)
88604 continue;
88605
88606 kdb_printf("%-20s%8u 0x%p ", mod->name,
88607- mod->core_size, (void *)mod);
88608+ mod->core_size_rx + mod->core_size_rw, (void *)mod);
88609 #ifdef CONFIG_MODULE_UNLOAD
88610 kdb_printf("%4ld ", module_refcount(mod));
88611 #endif
88612@@ -1987,7 +1987,7 @@ static int kdb_lsmod(int argc, const char **argv)
88613 kdb_printf(" (Loading)");
88614 else
88615 kdb_printf(" (Live)");
88616- kdb_printf(" 0x%p", mod->module_core);
88617+ kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
88618
88619 #ifdef CONFIG_MODULE_UNLOAD
88620 {
88621diff --git a/kernel/events/core.c b/kernel/events/core.c
88622index 1cd5eef..e8b5af9 100644
88623--- a/kernel/events/core.c
88624+++ b/kernel/events/core.c
88625@@ -170,8 +170,15 @@ static struct srcu_struct pmus_srcu;
88626 * 0 - disallow raw tracepoint access for unpriv
88627 * 1 - disallow cpu events for unpriv
88628 * 2 - disallow kernel profiling for unpriv
88629+ * 3 - disallow all unpriv perf event use
88630 */
88631-int sysctl_perf_event_paranoid __read_mostly = 1;
88632+#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
88633+int sysctl_perf_event_legitimately_concerned __read_mostly = 3;
88634+#elif defined(CONFIG_GRKERNSEC_HIDESYM)
88635+int sysctl_perf_event_legitimately_concerned __read_mostly = 2;
88636+#else
88637+int sysctl_perf_event_legitimately_concerned __read_mostly = 1;
88638+#endif
88639
88640 /* Minimum for 512 kiB + 1 user control page */
88641 int sysctl_perf_event_mlock __read_mostly = 512 + (PAGE_SIZE / 1024); /* 'free' kiB per user */
88642@@ -197,7 +204,7 @@ void update_perf_cpu_limits(void)
88643
88644 tmp *= sysctl_perf_cpu_time_max_percent;
88645 do_div(tmp, 100);
88646- ACCESS_ONCE(perf_sample_allowed_ns) = tmp;
88647+ ACCESS_ONCE_RW(perf_sample_allowed_ns) = tmp;
88648 }
88649
88650 static int perf_rotate_context(struct perf_cpu_context *cpuctx);
88651@@ -303,7 +310,7 @@ void perf_sample_event_took(u64 sample_len_ns)
88652 }
88653 }
88654
88655-static atomic64_t perf_event_id;
88656+static atomic64_unchecked_t perf_event_id;
88657
88658 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
88659 enum event_type_t event_type);
88660@@ -3102,7 +3109,7 @@ static void __perf_event_read(void *info)
88661
88662 static inline u64 perf_event_count(struct perf_event *event)
88663 {
88664- return local64_read(&event->count) + atomic64_read(&event->child_count);
88665+ return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
88666 }
88667
88668 static u64 perf_event_read(struct perf_event *event)
88669@@ -3528,9 +3535,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
88670 mutex_lock(&event->child_mutex);
88671 total += perf_event_read(event);
88672 *enabled += event->total_time_enabled +
88673- atomic64_read(&event->child_total_time_enabled);
88674+ atomic64_read_unchecked(&event->child_total_time_enabled);
88675 *running += event->total_time_running +
88676- atomic64_read(&event->child_total_time_running);
88677+ atomic64_read_unchecked(&event->child_total_time_running);
88678
88679 list_for_each_entry(child, &event->child_list, child_list) {
88680 total += perf_event_read(child);
88681@@ -3994,10 +4001,10 @@ void perf_event_update_userpage(struct perf_event *event)
88682 userpg->offset -= local64_read(&event->hw.prev_count);
88683
88684 userpg->time_enabled = enabled +
88685- atomic64_read(&event->child_total_time_enabled);
88686+ atomic64_read_unchecked(&event->child_total_time_enabled);
88687
88688 userpg->time_running = running +
88689- atomic64_read(&event->child_total_time_running);
88690+ atomic64_read_unchecked(&event->child_total_time_running);
88691
88692 arch_perf_update_userpage(userpg, now);
88693
88694@@ -4561,7 +4568,7 @@ perf_output_sample_ustack(struct perf_output_handle *handle, u64 dump_size,
88695
88696 /* Data. */
88697 sp = perf_user_stack_pointer(regs);
88698- rem = __output_copy_user(handle, (void *) sp, dump_size);
88699+ rem = __output_copy_user(handle, (void __user *) sp, dump_size);
88700 dyn_size = dump_size - rem;
88701
88702 perf_output_skip(handle, rem);
88703@@ -4652,11 +4659,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
88704 values[n++] = perf_event_count(event);
88705 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
88706 values[n++] = enabled +
88707- atomic64_read(&event->child_total_time_enabled);
88708+ atomic64_read_unchecked(&event->child_total_time_enabled);
88709 }
88710 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
88711 values[n++] = running +
88712- atomic64_read(&event->child_total_time_running);
88713+ atomic64_read_unchecked(&event->child_total_time_running);
88714 }
88715 if (read_format & PERF_FORMAT_ID)
88716 values[n++] = primary_event_id(event);
88717@@ -6958,7 +6965,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
88718 event->parent = parent_event;
88719
88720 event->ns = get_pid_ns(task_active_pid_ns(current));
88721- event->id = atomic64_inc_return(&perf_event_id);
88722+ event->id = atomic64_inc_return_unchecked(&perf_event_id);
88723
88724 event->state = PERF_EVENT_STATE_INACTIVE;
88725
88726@@ -7237,6 +7244,11 @@ SYSCALL_DEFINE5(perf_event_open,
88727 if (flags & ~PERF_FLAG_ALL)
88728 return -EINVAL;
88729
88730+#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
88731+ if (perf_paranoid_any() && !capable(CAP_SYS_ADMIN))
88732+ return -EACCES;
88733+#endif
88734+
88735 err = perf_copy_attr(attr_uptr, &attr);
88736 if (err)
88737 return err;
88738@@ -7592,10 +7604,10 @@ static void sync_child_event(struct perf_event *child_event,
88739 /*
88740 * Add back the child's count to the parent's count:
88741 */
88742- atomic64_add(child_val, &parent_event->child_count);
88743- atomic64_add(child_event->total_time_enabled,
88744+ atomic64_add_unchecked(child_val, &parent_event->child_count);
88745+ atomic64_add_unchecked(child_event->total_time_enabled,
88746 &parent_event->child_total_time_enabled);
88747- atomic64_add(child_event->total_time_running,
88748+ atomic64_add_unchecked(child_event->total_time_running,
88749 &parent_event->child_total_time_running);
88750
88751 /*
88752diff --git a/kernel/events/internal.h b/kernel/events/internal.h
88753index 569b2187..19940d9 100644
88754--- a/kernel/events/internal.h
88755+++ b/kernel/events/internal.h
88756@@ -81,10 +81,10 @@ static inline unsigned long perf_data_size(struct ring_buffer *rb)
88757 return rb->nr_pages << (PAGE_SHIFT + page_order(rb));
88758 }
88759
88760-#define DEFINE_OUTPUT_COPY(func_name, memcpy_func) \
88761+#define DEFINE_OUTPUT_COPY(func_name, memcpy_func, user) \
88762 static inline unsigned long \
88763 func_name(struct perf_output_handle *handle, \
88764- const void *buf, unsigned long len) \
88765+ const void user *buf, unsigned long len) \
88766 { \
88767 unsigned long size, written; \
88768 \
88769@@ -117,7 +117,7 @@ memcpy_common(void *dst, const void *src, unsigned long n)
88770 return 0;
88771 }
88772
88773-DEFINE_OUTPUT_COPY(__output_copy, memcpy_common)
88774+DEFINE_OUTPUT_COPY(__output_copy, memcpy_common, )
88775
88776 static inline unsigned long
88777 memcpy_skip(void *dst, const void *src, unsigned long n)
88778@@ -125,7 +125,7 @@ memcpy_skip(void *dst, const void *src, unsigned long n)
88779 return 0;
88780 }
88781
88782-DEFINE_OUTPUT_COPY(__output_skip, memcpy_skip)
88783+DEFINE_OUTPUT_COPY(__output_skip, memcpy_skip, )
88784
88785 #ifndef arch_perf_out_copy_user
88786 #define arch_perf_out_copy_user arch_perf_out_copy_user
88787@@ -143,7 +143,7 @@ arch_perf_out_copy_user(void *dst, const void *src, unsigned long n)
88788 }
88789 #endif
88790
88791-DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user)
88792+DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user, __user)
88793
88794 /* Callchain handling */
88795 extern struct perf_callchain_entry *
88796diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
88797index ed8f2cd..fe8030c 100644
88798--- a/kernel/events/uprobes.c
88799+++ b/kernel/events/uprobes.c
88800@@ -1670,7 +1670,7 @@ static int is_trap_at_addr(struct mm_struct *mm, unsigned long vaddr)
88801 {
88802 struct page *page;
88803 uprobe_opcode_t opcode;
88804- int result;
88805+ long result;
88806
88807 pagefault_disable();
88808 result = __copy_from_user_inatomic(&opcode, (void __user*)vaddr,
88809diff --git a/kernel/exit.c b/kernel/exit.c
88810index 5d30019..934add5 100644
88811--- a/kernel/exit.c
88812+++ b/kernel/exit.c
88813@@ -174,6 +174,10 @@ void release_task(struct task_struct *p)
88814 struct task_struct *leader;
88815 int zap_leader;
88816 repeat:
88817+#ifdef CONFIG_NET
88818+ gr_del_task_from_ip_table(p);
88819+#endif
88820+
88821 /* don't need to get the RCU readlock here - the process is dead and
88822 * can't be modifying its own credentials. But shut RCU-lockdep up */
88823 rcu_read_lock();
88824@@ -670,6 +674,8 @@ void do_exit(long code)
88825 int group_dead;
88826 TASKS_RCU(int tasks_rcu_i);
88827
88828+ set_fs(USER_DS);
88829+
88830 profile_task_exit(tsk);
88831
88832 WARN_ON(blk_needs_flush_plug(tsk));
88833@@ -686,7 +692,6 @@ void do_exit(long code)
88834 * mm_release()->clear_child_tid() from writing to a user-controlled
88835 * kernel address.
88836 */
88837- set_fs(USER_DS);
88838
88839 ptrace_event(PTRACE_EVENT_EXIT, code);
88840
88841@@ -744,6 +749,9 @@ void do_exit(long code)
88842 tsk->exit_code = code;
88843 taskstats_exit(tsk, group_dead);
88844
88845+ gr_acl_handle_psacct(tsk, code);
88846+ gr_acl_handle_exit();
88847+
88848 exit_mm(tsk);
88849
88850 if (group_dead)
88851@@ -863,7 +871,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
88852 * Take down every thread in the group. This is called by fatal signals
88853 * as well as by sys_exit_group (below).
88854 */
88855-void
88856+__noreturn void
88857 do_group_exit(int exit_code)
88858 {
88859 struct signal_struct *sig = current->signal;
88860diff --git a/kernel/fork.c b/kernel/fork.c
88861index 9b7d746..5b898ab 100644
88862--- a/kernel/fork.c
88863+++ b/kernel/fork.c
88864@@ -183,6 +183,48 @@ void thread_info_cache_init(void)
88865 # endif
88866 #endif
88867
88868+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
88869+static inline struct thread_info *gr_alloc_thread_info_node(struct task_struct *tsk,
88870+ int node, void **lowmem_stack)
88871+{
88872+ struct page *pages[THREAD_SIZE / PAGE_SIZE];
88873+ void *ret = NULL;
88874+ unsigned int i;
88875+
88876+ *lowmem_stack = alloc_thread_info_node(tsk, node);
88877+ if (*lowmem_stack == NULL)
88878+ goto out;
88879+
88880+ for (i = 0; i < THREAD_SIZE / PAGE_SIZE; i++)
88881+ pages[i] = virt_to_page(*lowmem_stack + (i * PAGE_SIZE));
88882+
88883+ /* use VM_IOREMAP to gain THREAD_SIZE alignment */
88884+ ret = vmap(pages, THREAD_SIZE / PAGE_SIZE, VM_IOREMAP, PAGE_KERNEL);
88885+ if (ret == NULL) {
88886+ free_thread_info(*lowmem_stack);
88887+ *lowmem_stack = NULL;
88888+ }
88889+
88890+out:
88891+ return ret;
88892+}
88893+
88894+static inline void gr_free_thread_info(struct task_struct *tsk, struct thread_info *ti)
88895+{
88896+ unmap_process_stacks(tsk);
88897+}
88898+#else
88899+static inline struct thread_info *gr_alloc_thread_info_node(struct task_struct *tsk,
88900+ int node, void **lowmem_stack)
88901+{
88902+ return alloc_thread_info_node(tsk, node);
88903+}
88904+static inline void gr_free_thread_info(struct task_struct *tsk, struct thread_info *ti)
88905+{
88906+ free_thread_info(ti);
88907+}
88908+#endif
88909+
88910 /* SLAB cache for signal_struct structures (tsk->signal) */
88911 static struct kmem_cache *signal_cachep;
88912
88913@@ -201,18 +243,22 @@ struct kmem_cache *vm_area_cachep;
88914 /* SLAB cache for mm_struct structures (tsk->mm) */
88915 static struct kmem_cache *mm_cachep;
88916
88917-static void account_kernel_stack(struct thread_info *ti, int account)
88918+static void account_kernel_stack(struct task_struct *tsk, struct thread_info *ti, int account)
88919 {
88920+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
88921+ struct zone *zone = page_zone(virt_to_page(tsk->lowmem_stack));
88922+#else
88923 struct zone *zone = page_zone(virt_to_page(ti));
88924+#endif
88925
88926 mod_zone_page_state(zone, NR_KERNEL_STACK, account);
88927 }
88928
88929 void free_task(struct task_struct *tsk)
88930 {
88931- account_kernel_stack(tsk->stack, -1);
88932+ account_kernel_stack(tsk, tsk->stack, -1);
88933 arch_release_thread_info(tsk->stack);
88934- free_thread_info(tsk->stack);
88935+ gr_free_thread_info(tsk, tsk->stack);
88936 rt_mutex_debug_task_free(tsk);
88937 ftrace_graph_exit_task(tsk);
88938 put_seccomp_filter(tsk);
88939@@ -306,6 +352,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
88940 {
88941 struct task_struct *tsk;
88942 struct thread_info *ti;
88943+ void *lowmem_stack;
88944 int node = tsk_fork_get_node(orig);
88945 int err;
88946
88947@@ -313,7 +360,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
88948 if (!tsk)
88949 return NULL;
88950
88951- ti = alloc_thread_info_node(tsk, node);
88952+ ti = gr_alloc_thread_info_node(tsk, node, &lowmem_stack);
88953 if (!ti)
88954 goto free_tsk;
88955
88956@@ -322,6 +369,9 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
88957 goto free_ti;
88958
88959 tsk->stack = ti;
88960+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
88961+ tsk->lowmem_stack = lowmem_stack;
88962+#endif
88963 #ifdef CONFIG_SECCOMP
88964 /*
88965 * We must handle setting up seccomp filters once we're under
88966@@ -338,7 +388,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
88967 set_task_stack_end_magic(tsk);
88968
88969 #ifdef CONFIG_CC_STACKPROTECTOR
88970- tsk->stack_canary = get_random_int();
88971+ tsk->stack_canary = pax_get_random_long();
88972 #endif
88973
88974 /*
88975@@ -352,24 +402,92 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
88976 tsk->splice_pipe = NULL;
88977 tsk->task_frag.page = NULL;
88978
88979- account_kernel_stack(ti, 1);
88980+ account_kernel_stack(tsk, ti, 1);
88981
88982 return tsk;
88983
88984 free_ti:
88985- free_thread_info(ti);
88986+ gr_free_thread_info(tsk, ti);
88987 free_tsk:
88988 free_task_struct(tsk);
88989 return NULL;
88990 }
88991
88992 #ifdef CONFIG_MMU
88993-static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
88994+static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct mm_struct *oldmm, struct vm_area_struct *mpnt)
88995+{
88996+ struct vm_area_struct *tmp;
88997+ unsigned long charge;
88998+ struct file *file;
88999+ int retval;
89000+
89001+ charge = 0;
89002+ if (mpnt->vm_flags & VM_ACCOUNT) {
89003+ unsigned long len = vma_pages(mpnt);
89004+
89005+ if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
89006+ goto fail_nomem;
89007+ charge = len;
89008+ }
89009+ tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
89010+ if (!tmp)
89011+ goto fail_nomem;
89012+ *tmp = *mpnt;
89013+ tmp->vm_mm = mm;
89014+ INIT_LIST_HEAD(&tmp->anon_vma_chain);
89015+ retval = vma_dup_policy(mpnt, tmp);
89016+ if (retval)
89017+ goto fail_nomem_policy;
89018+ if (anon_vma_fork(tmp, mpnt))
89019+ goto fail_nomem_anon_vma_fork;
89020+ tmp->vm_flags &= ~VM_LOCKED;
89021+ tmp->vm_next = tmp->vm_prev = NULL;
89022+ tmp->vm_mirror = NULL;
89023+ file = tmp->vm_file;
89024+ if (file) {
89025+ struct inode *inode = file_inode(file);
89026+ struct address_space *mapping = file->f_mapping;
89027+
89028+ get_file(file);
89029+ if (tmp->vm_flags & VM_DENYWRITE)
89030+ atomic_dec(&inode->i_writecount);
89031+ mutex_lock(&mapping->i_mmap_mutex);
89032+ if (tmp->vm_flags & VM_SHARED)
89033+ atomic_inc(&mapping->i_mmap_writable);
89034+ flush_dcache_mmap_lock(mapping);
89035+ /* insert tmp into the share list, just after mpnt */
89036+ if (unlikely(tmp->vm_flags & VM_NONLINEAR))
89037+ vma_nonlinear_insert(tmp, &mapping->i_mmap_nonlinear);
89038+ else
89039+ vma_interval_tree_insert_after(tmp, mpnt, &mapping->i_mmap);
89040+ flush_dcache_mmap_unlock(mapping);
89041+ mutex_unlock(&mapping->i_mmap_mutex);
89042+ }
89043+
89044+ /*
89045+ * Clear hugetlb-related page reserves for children. This only
89046+ * affects MAP_PRIVATE mappings. Faults generated by the child
89047+ * are not guaranteed to succeed, even if read-only
89048+ */
89049+ if (is_vm_hugetlb_page(tmp))
89050+ reset_vma_resv_huge_pages(tmp);
89051+
89052+ return tmp;
89053+
89054+fail_nomem_anon_vma_fork:
89055+ mpol_put(vma_policy(tmp));
89056+fail_nomem_policy:
89057+ kmem_cache_free(vm_area_cachep, tmp);
89058+fail_nomem:
89059+ vm_unacct_memory(charge);
89060+ return NULL;
89061+}
89062+
89063+static __latent_entropy int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
89064 {
89065 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
89066 struct rb_node **rb_link, *rb_parent;
89067 int retval;
89068- unsigned long charge;
89069
89070 uprobe_start_dup_mmap();
89071 down_write(&oldmm->mmap_sem);
89072@@ -397,55 +515,15 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
89073
89074 prev = NULL;
89075 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
89076- struct file *file;
89077-
89078 if (mpnt->vm_flags & VM_DONTCOPY) {
89079 vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
89080 -vma_pages(mpnt));
89081 continue;
89082 }
89083- charge = 0;
89084- if (mpnt->vm_flags & VM_ACCOUNT) {
89085- unsigned long len = vma_pages(mpnt);
89086-
89087- if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
89088- goto fail_nomem;
89089- charge = len;
89090- }
89091- tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
89092- if (!tmp)
89093- goto fail_nomem;
89094- *tmp = *mpnt;
89095- INIT_LIST_HEAD(&tmp->anon_vma_chain);
89096- retval = vma_dup_policy(mpnt, tmp);
89097- if (retval)
89098- goto fail_nomem_policy;
89099- tmp->vm_mm = mm;
89100- if (anon_vma_fork(tmp, mpnt))
89101- goto fail_nomem_anon_vma_fork;
89102- tmp->vm_flags &= ~VM_LOCKED;
89103- tmp->vm_next = tmp->vm_prev = NULL;
89104- file = tmp->vm_file;
89105- if (file) {
89106- struct inode *inode = file_inode(file);
89107- struct address_space *mapping = file->f_mapping;
89108-
89109- get_file(file);
89110- if (tmp->vm_flags & VM_DENYWRITE)
89111- atomic_dec(&inode->i_writecount);
89112- mutex_lock(&mapping->i_mmap_mutex);
89113- if (tmp->vm_flags & VM_SHARED)
89114- atomic_inc(&mapping->i_mmap_writable);
89115- flush_dcache_mmap_lock(mapping);
89116- /* insert tmp into the share list, just after mpnt */
89117- if (unlikely(tmp->vm_flags & VM_NONLINEAR))
89118- vma_nonlinear_insert(tmp,
89119- &mapping->i_mmap_nonlinear);
89120- else
89121- vma_interval_tree_insert_after(tmp, mpnt,
89122- &mapping->i_mmap);
89123- flush_dcache_mmap_unlock(mapping);
89124- mutex_unlock(&mapping->i_mmap_mutex);
89125+ tmp = dup_vma(mm, oldmm, mpnt);
89126+ if (!tmp) {
89127+ retval = -ENOMEM;
89128+ goto out;
89129 }
89130
89131 /*
89132@@ -477,6 +555,31 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
89133 if (retval)
89134 goto out;
89135 }
89136+
89137+#ifdef CONFIG_PAX_SEGMEXEC
89138+ if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
89139+ struct vm_area_struct *mpnt_m;
89140+
89141+ for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
89142+ BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
89143+
89144+ if (!mpnt->vm_mirror)
89145+ continue;
89146+
89147+ if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
89148+ BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
89149+ mpnt->vm_mirror = mpnt_m;
89150+ } else {
89151+ BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
89152+ mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
89153+ mpnt_m->vm_mirror->vm_mirror = mpnt_m;
89154+ mpnt->vm_mirror->vm_mirror = mpnt;
89155+ }
89156+ }
89157+ BUG_ON(mpnt_m);
89158+ }
89159+#endif
89160+
89161 /* a new mm has just been created */
89162 arch_dup_mmap(oldmm, mm);
89163 retval = 0;
89164@@ -486,14 +589,6 @@ out:
89165 up_write(&oldmm->mmap_sem);
89166 uprobe_end_dup_mmap();
89167 return retval;
89168-fail_nomem_anon_vma_fork:
89169- mpol_put(vma_policy(tmp));
89170-fail_nomem_policy:
89171- kmem_cache_free(vm_area_cachep, tmp);
89172-fail_nomem:
89173- retval = -ENOMEM;
89174- vm_unacct_memory(charge);
89175- goto out;
89176 }
89177
89178 static inline int mm_alloc_pgd(struct mm_struct *mm)
89179@@ -734,8 +829,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
89180 return ERR_PTR(err);
89181
89182 mm = get_task_mm(task);
89183- if (mm && mm != current->mm &&
89184- !ptrace_may_access(task, mode)) {
89185+ if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
89186+ (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
89187 mmput(mm);
89188 mm = ERR_PTR(-EACCES);
89189 }
89190@@ -938,13 +1033,20 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
89191 spin_unlock(&fs->lock);
89192 return -EAGAIN;
89193 }
89194- fs->users++;
89195+ atomic_inc(&fs->users);
89196 spin_unlock(&fs->lock);
89197 return 0;
89198 }
89199 tsk->fs = copy_fs_struct(fs);
89200 if (!tsk->fs)
89201 return -ENOMEM;
89202+ /* Carry through gr_chroot_dentry and is_chrooted instead
89203+ of recomputing it here. Already copied when the task struct
89204+ is duplicated. This allows pivot_root to not be treated as
89205+ a chroot
89206+ */
89207+ //gr_set_chroot_entries(tsk, &tsk->fs->root);
89208+
89209 return 0;
89210 }
89211
89212@@ -1179,7 +1281,7 @@ init_task_pid(struct task_struct *task, enum pid_type type, struct pid *pid)
89213 * parts of the process environment (as per the clone
89214 * flags). The actual kick-off is left to the caller.
89215 */
89216-static struct task_struct *copy_process(unsigned long clone_flags,
89217+static __latent_entropy struct task_struct *copy_process(unsigned long clone_flags,
89218 unsigned long stack_start,
89219 unsigned long stack_size,
89220 int __user *child_tidptr,
89221@@ -1250,6 +1352,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
89222 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
89223 #endif
89224 retval = -EAGAIN;
89225+
89226+ gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
89227+
89228 if (atomic_read(&p->real_cred->user->processes) >=
89229 task_rlimit(p, RLIMIT_NPROC)) {
89230 if (p->real_cred->user != INIT_USER &&
89231@@ -1499,6 +1604,11 @@ static struct task_struct *copy_process(unsigned long clone_flags,
89232 goto bad_fork_free_pid;
89233 }
89234
89235+ /* synchronizes with gr_set_acls()
89236+ we need to call this past the point of no return for fork()
89237+ */
89238+ gr_copy_label(p);
89239+
89240 if (likely(p->pid)) {
89241 ptrace_init_task(p, (clone_flags & CLONE_PTRACE) || trace);
89242
89243@@ -1589,6 +1699,8 @@ bad_fork_cleanup_count:
89244 bad_fork_free:
89245 free_task(p);
89246 fork_out:
89247+ gr_log_forkfail(retval);
89248+
89249 return ERR_PTR(retval);
89250 }
89251
89252@@ -1650,6 +1762,7 @@ long do_fork(unsigned long clone_flags,
89253
89254 p = copy_process(clone_flags, stack_start, stack_size,
89255 child_tidptr, NULL, trace);
89256+ add_latent_entropy();
89257 /*
89258 * Do this prior waking up the new thread - the thread pointer
89259 * might get invalid after that point, if the thread exits quickly.
89260@@ -1666,6 +1779,8 @@ long do_fork(unsigned long clone_flags,
89261 if (clone_flags & CLONE_PARENT_SETTID)
89262 put_user(nr, parent_tidptr);
89263
89264+ gr_handle_brute_check();
89265+
89266 if (clone_flags & CLONE_VFORK) {
89267 p->vfork_done = &vfork;
89268 init_completion(&vfork);
89269@@ -1784,7 +1899,7 @@ void __init proc_caches_init(void)
89270 mm_cachep = kmem_cache_create("mm_struct",
89271 sizeof(struct mm_struct), ARCH_MIN_MMSTRUCT_ALIGN,
89272 SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_NOTRACK, NULL);
89273- vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC);
89274+ vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC | SLAB_NO_SANITIZE);
89275 mmap_init();
89276 nsproxy_cache_init();
89277 }
89278@@ -1824,7 +1939,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
89279 return 0;
89280
89281 /* don't need lock here; in the worst case we'll do useless copy */
89282- if (fs->users == 1)
89283+ if (atomic_read(&fs->users) == 1)
89284 return 0;
89285
89286 *new_fsp = copy_fs_struct(fs);
89287@@ -1936,7 +2051,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
89288 fs = current->fs;
89289 spin_lock(&fs->lock);
89290 current->fs = new_fs;
89291- if (--fs->users)
89292+ gr_set_chroot_entries(current, &current->fs->root);
89293+ if (atomic_dec_return(&fs->users))
89294 new_fs = NULL;
89295 else
89296 new_fs = fs;
89297diff --git a/kernel/futex.c b/kernel/futex.c
89298index 63678b5..512f9af 100644
89299--- a/kernel/futex.c
89300+++ b/kernel/futex.c
89301@@ -201,7 +201,7 @@ struct futex_pi_state {
89302 atomic_t refcount;
89303
89304 union futex_key key;
89305-};
89306+} __randomize_layout;
89307
89308 /**
89309 * struct futex_q - The hashed futex queue entry, one per waiting task
89310@@ -235,7 +235,7 @@ struct futex_q {
89311 struct rt_mutex_waiter *rt_waiter;
89312 union futex_key *requeue_pi_key;
89313 u32 bitset;
89314-};
89315+} __randomize_layout;
89316
89317 static const struct futex_q futex_q_init = {
89318 /* list gets initialized in queue_me()*/
89319@@ -402,6 +402,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
89320 struct page *page, *page_head;
89321 int err, ro = 0;
89322
89323+#ifdef CONFIG_PAX_SEGMEXEC
89324+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
89325+ return -EFAULT;
89326+#endif
89327+
89328 /*
89329 * The futex address must be "naturally" aligned.
89330 */
89331@@ -601,7 +606,7 @@ static int cmpxchg_futex_value_locked(u32 *curval, u32 __user *uaddr,
89332
89333 static int get_futex_value_locked(u32 *dest, u32 __user *from)
89334 {
89335- int ret;
89336+ unsigned long ret;
89337
89338 pagefault_disable();
89339 ret = __copy_from_user_inatomic(dest, from, sizeof(u32));
89340@@ -3006,6 +3011,7 @@ static void __init futex_detect_cmpxchg(void)
89341 {
89342 #ifndef CONFIG_HAVE_FUTEX_CMPXCHG
89343 u32 curval;
89344+ mm_segment_t oldfs;
89345
89346 /*
89347 * This will fail and we want it. Some arch implementations do
89348@@ -3017,8 +3023,11 @@ static void __init futex_detect_cmpxchg(void)
89349 * implementation, the non-functional ones will return
89350 * -ENOSYS.
89351 */
89352+ oldfs = get_fs();
89353+ set_fs(USER_DS);
89354 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
89355 futex_cmpxchg_enabled = 1;
89356+ set_fs(oldfs);
89357 #endif
89358 }
89359
89360diff --git a/kernel/futex_compat.c b/kernel/futex_compat.c
89361index 55c8c93..9ba7ad6 100644
89362--- a/kernel/futex_compat.c
89363+++ b/kernel/futex_compat.c
89364@@ -32,7 +32,7 @@ fetch_robust_entry(compat_uptr_t *uentry, struct robust_list __user **entry,
89365 return 0;
89366 }
89367
89368-static void __user *futex_uaddr(struct robust_list __user *entry,
89369+static void __user __intentional_overflow(-1) *futex_uaddr(struct robust_list __user *entry,
89370 compat_long_t futex_offset)
89371 {
89372 compat_uptr_t base = ptr_to_compat(entry);
89373diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
89374index b358a80..fc25240 100644
89375--- a/kernel/gcov/base.c
89376+++ b/kernel/gcov/base.c
89377@@ -114,11 +114,6 @@ void gcov_enable_events(void)
89378 }
89379
89380 #ifdef CONFIG_MODULES
89381-static inline int within(void *addr, void *start, unsigned long size)
89382-{
89383- return ((addr >= start) && (addr < start + size));
89384-}
89385-
89386 /* Update list and generate events when modules are unloaded. */
89387 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
89388 void *data)
89389@@ -133,7 +128,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
89390
89391 /* Remove entries located in module from linked list. */
89392 while ((info = gcov_info_next(info))) {
89393- if (within(info, mod->module_core, mod->core_size)) {
89394+ if (within_module_core_rw((unsigned long)info, mod)) {
89395 gcov_info_unlink(prev, info);
89396 if (gcov_events_enabled)
89397 gcov_event(GCOV_REMOVE, info);
89398diff --git a/kernel/jump_label.c b/kernel/jump_label.c
89399index 9019f15..9a3c42e 100644
89400--- a/kernel/jump_label.c
89401+++ b/kernel/jump_label.c
89402@@ -14,6 +14,7 @@
89403 #include <linux/err.h>
89404 #include <linux/static_key.h>
89405 #include <linux/jump_label_ratelimit.h>
89406+#include <linux/mm.h>
89407
89408 #ifdef HAVE_JUMP_LABEL
89409
89410@@ -51,7 +52,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
89411
89412 size = (((unsigned long)stop - (unsigned long)start)
89413 / sizeof(struct jump_entry));
89414+ pax_open_kernel();
89415 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
89416+ pax_close_kernel();
89417 }
89418
89419 static void jump_label_update(struct static_key *key, int enable);
89420@@ -363,10 +366,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
89421 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
89422 struct jump_entry *iter;
89423
89424+ pax_open_kernel();
89425 for (iter = iter_start; iter < iter_stop; iter++) {
89426 if (within_module_init(iter->code, mod))
89427 iter->code = 0;
89428 }
89429+ pax_close_kernel();
89430 }
89431
89432 static int
89433diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
89434index 5c5987f..bc502b0 100644
89435--- a/kernel/kallsyms.c
89436+++ b/kernel/kallsyms.c
89437@@ -11,6 +11,9 @@
89438 * Changed the compression method from stem compression to "table lookup"
89439 * compression (see scripts/kallsyms.c for a more complete description)
89440 */
89441+#ifdef CONFIG_GRKERNSEC_HIDESYM
89442+#define __INCLUDED_BY_HIDESYM 1
89443+#endif
89444 #include <linux/kallsyms.h>
89445 #include <linux/module.h>
89446 #include <linux/init.h>
89447@@ -54,12 +57,33 @@ extern const unsigned long kallsyms_markers[] __weak;
89448
89449 static inline int is_kernel_inittext(unsigned long addr)
89450 {
89451+ if (system_state != SYSTEM_BOOTING)
89452+ return 0;
89453+
89454 if (addr >= (unsigned long)_sinittext
89455 && addr <= (unsigned long)_einittext)
89456 return 1;
89457 return 0;
89458 }
89459
89460+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
89461+#ifdef CONFIG_MODULES
89462+static inline int is_module_text(unsigned long addr)
89463+{
89464+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
89465+ return 1;
89466+
89467+ addr = ktla_ktva(addr);
89468+ return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
89469+}
89470+#else
89471+static inline int is_module_text(unsigned long addr)
89472+{
89473+ return 0;
89474+}
89475+#endif
89476+#endif
89477+
89478 static inline int is_kernel_text(unsigned long addr)
89479 {
89480 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
89481@@ -70,13 +94,28 @@ static inline int is_kernel_text(unsigned long addr)
89482
89483 static inline int is_kernel(unsigned long addr)
89484 {
89485+
89486+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
89487+ if (is_kernel_text(addr) || is_kernel_inittext(addr))
89488+ return 1;
89489+
89490+ if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
89491+#else
89492 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
89493+#endif
89494+
89495 return 1;
89496 return in_gate_area_no_mm(addr);
89497 }
89498
89499 static int is_ksym_addr(unsigned long addr)
89500 {
89501+
89502+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
89503+ if (is_module_text(addr))
89504+ return 0;
89505+#endif
89506+
89507 if (all_var)
89508 return is_kernel(addr);
89509
89510@@ -481,7 +520,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
89511
89512 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
89513 {
89514- iter->name[0] = '\0';
89515 iter->nameoff = get_symbol_offset(new_pos);
89516 iter->pos = new_pos;
89517 }
89518@@ -529,6 +567,11 @@ static int s_show(struct seq_file *m, void *p)
89519 {
89520 struct kallsym_iter *iter = m->private;
89521
89522+#ifdef CONFIG_GRKERNSEC_HIDESYM
89523+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID))
89524+ return 0;
89525+#endif
89526+
89527 /* Some debugging symbols have no name. Ignore them. */
89528 if (!iter->name[0])
89529 return 0;
89530@@ -542,6 +585,7 @@ static int s_show(struct seq_file *m, void *p)
89531 */
89532 type = iter->exported ? toupper(iter->type) :
89533 tolower(iter->type);
89534+
89535 seq_printf(m, "%pK %c %s\t[%s]\n", (void *)iter->value,
89536 type, iter->name, iter->module_name);
89537 } else
89538diff --git a/kernel/kcmp.c b/kernel/kcmp.c
89539index 0aa69ea..a7fcafb 100644
89540--- a/kernel/kcmp.c
89541+++ b/kernel/kcmp.c
89542@@ -100,6 +100,10 @@ SYSCALL_DEFINE5(kcmp, pid_t, pid1, pid_t, pid2, int, type,
89543 struct task_struct *task1, *task2;
89544 int ret;
89545
89546+#ifdef CONFIG_GRKERNSEC
89547+ return -ENOSYS;
89548+#endif
89549+
89550 rcu_read_lock();
89551
89552 /*
89553diff --git a/kernel/kexec.c b/kernel/kexec.c
89554index 2abf9f6..c40cf85 100644
89555--- a/kernel/kexec.c
89556+++ b/kernel/kexec.c
89557@@ -1349,7 +1349,8 @@ COMPAT_SYSCALL_DEFINE4(kexec_load, compat_ulong_t, entry,
89558 compat_ulong_t, flags)
89559 {
89560 struct compat_kexec_segment in;
89561- struct kexec_segment out, __user *ksegments;
89562+ struct kexec_segment out;
89563+ struct kexec_segment __user *ksegments;
89564 unsigned long i, result;
89565
89566 /* Don't allow clients that don't understand the native
89567diff --git a/kernel/kmod.c b/kernel/kmod.c
89568index 80f7a6d..3c476d3 100644
89569--- a/kernel/kmod.c
89570+++ b/kernel/kmod.c
89571@@ -75,7 +75,7 @@ static void free_modprobe_argv(struct subprocess_info *info)
89572 kfree(info->argv);
89573 }
89574
89575-static int call_modprobe(char *module_name, int wait)
89576+static int call_modprobe(char *module_name, char *module_param, int wait)
89577 {
89578 struct subprocess_info *info;
89579 static char *envp[] = {
89580@@ -85,7 +85,7 @@ static int call_modprobe(char *module_name, int wait)
89581 NULL
89582 };
89583
89584- char **argv = kmalloc(sizeof(char *[5]), GFP_KERNEL);
89585+ char **argv = kmalloc(sizeof(char *[6]), GFP_KERNEL);
89586 if (!argv)
89587 goto out;
89588
89589@@ -97,7 +97,8 @@ static int call_modprobe(char *module_name, int wait)
89590 argv[1] = "-q";
89591 argv[2] = "--";
89592 argv[3] = module_name; /* check free_modprobe_argv() */
89593- argv[4] = NULL;
89594+ argv[4] = module_param;
89595+ argv[5] = NULL;
89596
89597 info = call_usermodehelper_setup(modprobe_path, argv, envp, GFP_KERNEL,
89598 NULL, free_modprobe_argv, NULL);
89599@@ -129,9 +130,8 @@ out:
89600 * If module auto-loading support is disabled then this function
89601 * becomes a no-operation.
89602 */
89603-int __request_module(bool wait, const char *fmt, ...)
89604+static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
89605 {
89606- va_list args;
89607 char module_name[MODULE_NAME_LEN];
89608 unsigned int max_modprobes;
89609 int ret;
89610@@ -150,9 +150,7 @@ int __request_module(bool wait, const char *fmt, ...)
89611 if (!modprobe_path[0])
89612 return 0;
89613
89614- va_start(args, fmt);
89615- ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
89616- va_end(args);
89617+ ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
89618 if (ret >= MODULE_NAME_LEN)
89619 return -ENAMETOOLONG;
89620
89621@@ -160,6 +158,20 @@ int __request_module(bool wait, const char *fmt, ...)
89622 if (ret)
89623 return ret;
89624
89625+#ifdef CONFIG_GRKERNSEC_MODHARDEN
89626+ if (uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
89627+ /* hack to workaround consolekit/udisks stupidity */
89628+ read_lock(&tasklist_lock);
89629+ if (!strcmp(current->comm, "mount") &&
89630+ current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
89631+ read_unlock(&tasklist_lock);
89632+ printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
89633+ return -EPERM;
89634+ }
89635+ read_unlock(&tasklist_lock);
89636+ }
89637+#endif
89638+
89639 /* If modprobe needs a service that is in a module, we get a recursive
89640 * loop. Limit the number of running kmod threads to max_threads/2 or
89641 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
89642@@ -188,16 +200,61 @@ int __request_module(bool wait, const char *fmt, ...)
89643
89644 trace_module_request(module_name, wait, _RET_IP_);
89645
89646- ret = call_modprobe(module_name, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
89647+ ret = call_modprobe(module_name, module_param, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
89648
89649 atomic_dec(&kmod_concurrent);
89650 return ret;
89651 }
89652+
89653+int ___request_module(bool wait, char *module_param, const char *fmt, ...)
89654+{
89655+ va_list args;
89656+ int ret;
89657+
89658+ va_start(args, fmt);
89659+ ret = ____request_module(wait, module_param, fmt, args);
89660+ va_end(args);
89661+
89662+ return ret;
89663+}
89664+
89665+int __request_module(bool wait, const char *fmt, ...)
89666+{
89667+ va_list args;
89668+ int ret;
89669+
89670+#ifdef CONFIG_GRKERNSEC_MODHARDEN
89671+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
89672+ char module_param[MODULE_NAME_LEN];
89673+
89674+ memset(module_param, 0, sizeof(module_param));
89675+
89676+ snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", GR_GLOBAL_UID(current_uid()));
89677+
89678+ va_start(args, fmt);
89679+ ret = ____request_module(wait, module_param, fmt, args);
89680+ va_end(args);
89681+
89682+ return ret;
89683+ }
89684+#endif
89685+
89686+ va_start(args, fmt);
89687+ ret = ____request_module(wait, NULL, fmt, args);
89688+ va_end(args);
89689+
89690+ return ret;
89691+}
89692+
89693 EXPORT_SYMBOL(__request_module);
89694 #endif /* CONFIG_MODULES */
89695
89696 static void call_usermodehelper_freeinfo(struct subprocess_info *info)
89697 {
89698+#ifdef CONFIG_GRKERNSEC
89699+ kfree(info->path);
89700+ info->path = info->origpath;
89701+#endif
89702 if (info->cleanup)
89703 (*info->cleanup)(info);
89704 kfree(info);
89705@@ -240,6 +297,20 @@ static int ____call_usermodehelper(void *data)
89706 */
89707 set_user_nice(current, 0);
89708
89709+#ifdef CONFIG_GRKERNSEC
89710+ /* this is race-free as far as userland is concerned as we copied
89711+ out the path to be used prior to this point and are now operating
89712+ on that copy
89713+ */
89714+ if ((strncmp(sub_info->path, "/sbin/", 6) && strncmp(sub_info->path, "/usr/lib/", 9) &&
89715+ strncmp(sub_info->path, "/lib/", 5) && strncmp(sub_info->path, "/lib64/", 7) &&
89716+ strcmp(sub_info->path, "/usr/share/apport/apport")) || strstr(sub_info->path, "..")) {
89717+ printk(KERN_ALERT "grsec: denied exec of usermode helper binary %.950s located outside of /sbin and system library paths\n", sub_info->path);
89718+ retval = -EPERM;
89719+ goto out;
89720+ }
89721+#endif
89722+
89723 retval = -ENOMEM;
89724 new = prepare_kernel_cred(current);
89725 if (!new)
89726@@ -262,8 +333,8 @@ static int ____call_usermodehelper(void *data)
89727 commit_creds(new);
89728
89729 retval = do_execve(getname_kernel(sub_info->path),
89730- (const char __user *const __user *)sub_info->argv,
89731- (const char __user *const __user *)sub_info->envp);
89732+ (const char __user *const __force_user *)sub_info->argv,
89733+ (const char __user *const __force_user *)sub_info->envp);
89734 out:
89735 sub_info->retval = retval;
89736 /* wait_for_helper() will call umh_complete if UHM_WAIT_PROC. */
89737@@ -303,7 +374,7 @@ static int wait_for_helper(void *data)
89738 *
89739 * Thus the __user pointer cast is valid here.
89740 */
89741- sys_wait4(pid, (int __user *)&ret, 0, NULL);
89742+ sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
89743
89744 /*
89745 * If ret is 0, either ____call_usermodehelper failed and the
89746@@ -532,7 +603,12 @@ struct subprocess_info *call_usermodehelper_setup(char *path, char **argv,
89747 goto out;
89748
89749 INIT_WORK(&sub_info->work, __call_usermodehelper);
89750+#ifdef CONFIG_GRKERNSEC
89751+ sub_info->origpath = path;
89752+ sub_info->path = kstrdup(path, gfp_mask);
89753+#else
89754 sub_info->path = path;
89755+#endif
89756 sub_info->argv = argv;
89757 sub_info->envp = envp;
89758
89759@@ -645,7 +721,7 @@ EXPORT_SYMBOL(call_usermodehelper);
89760 static int proc_cap_handler(struct ctl_table *table, int write,
89761 void __user *buffer, size_t *lenp, loff_t *ppos)
89762 {
89763- struct ctl_table t;
89764+ ctl_table_no_const t;
89765 unsigned long cap_array[_KERNEL_CAPABILITY_U32S];
89766 kernel_cap_t new_cap;
89767 int err, i;
89768diff --git a/kernel/kprobes.c b/kernel/kprobes.c
89769index 3995f54..e247879 100644
89770--- a/kernel/kprobes.c
89771+++ b/kernel/kprobes.c
89772@@ -31,6 +31,9 @@
89773 * <jkenisto@us.ibm.com> and Prasanna S Panchamukhi
89774 * <prasanna@in.ibm.com> added function-return probes.
89775 */
89776+#ifdef CONFIG_GRKERNSEC_HIDESYM
89777+#define __INCLUDED_BY_HIDESYM 1
89778+#endif
89779 #include <linux/kprobes.h>
89780 #include <linux/hash.h>
89781 #include <linux/init.h>
89782@@ -122,12 +125,12 @@ enum kprobe_slot_state {
89783
89784 static void *alloc_insn_page(void)
89785 {
89786- return module_alloc(PAGE_SIZE);
89787+ return module_alloc_exec(PAGE_SIZE);
89788 }
89789
89790 static void free_insn_page(void *page)
89791 {
89792- module_free(NULL, page);
89793+ module_free_exec(NULL, page);
89794 }
89795
89796 struct kprobe_insn_cache kprobe_insn_slots = {
89797@@ -2187,11 +2190,11 @@ static void report_probe(struct seq_file *pi, struct kprobe *p,
89798 kprobe_type = "k";
89799
89800 if (sym)
89801- seq_printf(pi, "%p %s %s+0x%x %s ",
89802+ seq_printf(pi, "%pK %s %s+0x%x %s ",
89803 p->addr, kprobe_type, sym, offset,
89804 (modname ? modname : " "));
89805 else
89806- seq_printf(pi, "%p %s %p ",
89807+ seq_printf(pi, "%pK %s %pK ",
89808 p->addr, kprobe_type, p->addr);
89809
89810 if (!pp)
89811diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
89812index 6683cce..daf8999 100644
89813--- a/kernel/ksysfs.c
89814+++ b/kernel/ksysfs.c
89815@@ -50,6 +50,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
89816 {
89817 if (count+1 > UEVENT_HELPER_PATH_LEN)
89818 return -ENOENT;
89819+ if (!capable(CAP_SYS_ADMIN))
89820+ return -EPERM;
89821 memcpy(uevent_helper, buf, count);
89822 uevent_helper[count] = '\0';
89823 if (count && uevent_helper[count-1] == '\n')
89824@@ -176,7 +178,7 @@ static ssize_t notes_read(struct file *filp, struct kobject *kobj,
89825 return count;
89826 }
89827
89828-static struct bin_attribute notes_attr = {
89829+static bin_attribute_no_const notes_attr __read_only = {
89830 .attr = {
89831 .name = "notes",
89832 .mode = S_IRUGO,
89833diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
89834index 88d0d44..e9ce0ee 100644
89835--- a/kernel/locking/lockdep.c
89836+++ b/kernel/locking/lockdep.c
89837@@ -599,6 +599,10 @@ static int static_obj(void *obj)
89838 end = (unsigned long) &_end,
89839 addr = (unsigned long) obj;
89840
89841+#ifdef CONFIG_PAX_KERNEXEC
89842+ start = ktla_ktva(start);
89843+#endif
89844+
89845 /*
89846 * static variable?
89847 */
89848@@ -740,6 +744,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
89849 if (!static_obj(lock->key)) {
89850 debug_locks_off();
89851 printk("INFO: trying to register non-static key.\n");
89852+ printk("lock:%pS key:%pS.\n", lock, lock->key);
89853 printk("the code is fine but needs lockdep annotation.\n");
89854 printk("turning off the locking correctness validator.\n");
89855 dump_stack();
89856@@ -3081,7 +3086,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
89857 if (!class)
89858 return 0;
89859 }
89860- atomic_inc((atomic_t *)&class->ops);
89861+ atomic_long_inc_unchecked((atomic_long_unchecked_t *)&class->ops);
89862 if (very_verbose(class)) {
89863 printk("\nacquire class [%p] %s", class->key, class->name);
89864 if (class->name_version > 1)
89865diff --git a/kernel/locking/lockdep_proc.c b/kernel/locking/lockdep_proc.c
89866index ef43ac4..2720dfa 100644
89867--- a/kernel/locking/lockdep_proc.c
89868+++ b/kernel/locking/lockdep_proc.c
89869@@ -65,7 +65,7 @@ static int l_show(struct seq_file *m, void *v)
89870 return 0;
89871 }
89872
89873- seq_printf(m, "%p", class->key);
89874+ seq_printf(m, "%pK", class->key);
89875 #ifdef CONFIG_DEBUG_LOCKDEP
89876 seq_printf(m, " OPS:%8ld", class->ops);
89877 #endif
89878@@ -83,7 +83,7 @@ static int l_show(struct seq_file *m, void *v)
89879
89880 list_for_each_entry(entry, &class->locks_after, entry) {
89881 if (entry->distance == 1) {
89882- seq_printf(m, " -> [%p] ", entry->class->key);
89883+ seq_printf(m, " -> [%pK] ", entry->class->key);
89884 print_name(m, entry->class);
89885 seq_puts(m, "\n");
89886 }
89887@@ -152,7 +152,7 @@ static int lc_show(struct seq_file *m, void *v)
89888 if (!class->key)
89889 continue;
89890
89891- seq_printf(m, "[%p] ", class->key);
89892+ seq_printf(m, "[%pK] ", class->key);
89893 print_name(m, class);
89894 seq_puts(m, "\n");
89895 }
89896@@ -496,7 +496,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
89897 if (!i)
89898 seq_line(m, '-', 40-namelen, namelen);
89899
89900- snprintf(ip, sizeof(ip), "[<%p>]",
89901+ snprintf(ip, sizeof(ip), "[<%pK>]",
89902 (void *)class->contention_point[i]);
89903 seq_printf(m, "%40s %14lu %29s %pS\n",
89904 name, stats->contention_point[i],
89905@@ -511,7 +511,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
89906 if (!i)
89907 seq_line(m, '-', 40-namelen, namelen);
89908
89909- snprintf(ip, sizeof(ip), "[<%p>]",
89910+ snprintf(ip, sizeof(ip), "[<%pK>]",
89911 (void *)class->contending_point[i]);
89912 seq_printf(m, "%40s %14lu %29s %pS\n",
89913 name, stats->contending_point[i],
89914diff --git a/kernel/locking/mcs_spinlock.c b/kernel/locking/mcs_spinlock.c
89915index 9887a90..0cd2b1d 100644
89916--- a/kernel/locking/mcs_spinlock.c
89917+++ b/kernel/locking/mcs_spinlock.c
89918@@ -100,7 +100,7 @@ bool osq_lock(struct optimistic_spin_queue *lock)
89919
89920 prev = decode_cpu(old);
89921 node->prev = prev;
89922- ACCESS_ONCE(prev->next) = node;
89923+ ACCESS_ONCE_RW(prev->next) = node;
89924
89925 /*
89926 * Normally @prev is untouchable after the above store; because at that
89927@@ -172,8 +172,8 @@ unqueue:
89928 * it will wait in Step-A.
89929 */
89930
89931- ACCESS_ONCE(next->prev) = prev;
89932- ACCESS_ONCE(prev->next) = next;
89933+ ACCESS_ONCE_RW(next->prev) = prev;
89934+ ACCESS_ONCE_RW(prev->next) = next;
89935
89936 return false;
89937 }
89938@@ -195,13 +195,13 @@ void osq_unlock(struct optimistic_spin_queue *lock)
89939 node = this_cpu_ptr(&osq_node);
89940 next = xchg(&node->next, NULL);
89941 if (next) {
89942- ACCESS_ONCE(next->locked) = 1;
89943+ ACCESS_ONCE_RW(next->locked) = 1;
89944 return;
89945 }
89946
89947 next = osq_wait_next(lock, node, NULL);
89948 if (next)
89949- ACCESS_ONCE(next->locked) = 1;
89950+ ACCESS_ONCE_RW(next->locked) = 1;
89951 }
89952
89953 #endif
89954diff --git a/kernel/locking/mcs_spinlock.h b/kernel/locking/mcs_spinlock.h
89955index 4d60986..5d351c1 100644
89956--- a/kernel/locking/mcs_spinlock.h
89957+++ b/kernel/locking/mcs_spinlock.h
89958@@ -78,7 +78,7 @@ void mcs_spin_lock(struct mcs_spinlock **lock, struct mcs_spinlock *node)
89959 */
89960 return;
89961 }
89962- ACCESS_ONCE(prev->next) = node;
89963+ ACCESS_ONCE_RW(prev->next) = node;
89964
89965 /* Wait until the lock holder passes the lock down. */
89966 arch_mcs_spin_lock_contended(&node->locked);
89967diff --git a/kernel/locking/mutex-debug.c b/kernel/locking/mutex-debug.c
89968index 5cf6731..ce3bc5a 100644
89969--- a/kernel/locking/mutex-debug.c
89970+++ b/kernel/locking/mutex-debug.c
89971@@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
89972 }
89973
89974 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
89975- struct thread_info *ti)
89976+ struct task_struct *task)
89977 {
89978 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
89979
89980 /* Mark the current thread as blocked on the lock: */
89981- ti->task->blocked_on = waiter;
89982+ task->blocked_on = waiter;
89983 }
89984
89985 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
89986- struct thread_info *ti)
89987+ struct task_struct *task)
89988 {
89989 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
89990- DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
89991- DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
89992- ti->task->blocked_on = NULL;
89993+ DEBUG_LOCKS_WARN_ON(waiter->task != task);
89994+ DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
89995+ task->blocked_on = NULL;
89996
89997 list_del_init(&waiter->list);
89998 waiter->task = NULL;
89999diff --git a/kernel/locking/mutex-debug.h b/kernel/locking/mutex-debug.h
90000index 0799fd3..d06ae3b 100644
90001--- a/kernel/locking/mutex-debug.h
90002+++ b/kernel/locking/mutex-debug.h
90003@@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
90004 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
90005 extern void debug_mutex_add_waiter(struct mutex *lock,
90006 struct mutex_waiter *waiter,
90007- struct thread_info *ti);
90008+ struct task_struct *task);
90009 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
90010- struct thread_info *ti);
90011+ struct task_struct *task);
90012 extern void debug_mutex_unlock(struct mutex *lock);
90013 extern void debug_mutex_init(struct mutex *lock, const char *name,
90014 struct lock_class_key *key);
90015diff --git a/kernel/locking/mutex.c b/kernel/locking/mutex.c
90016index dadbf88..4500507 100644
90017--- a/kernel/locking/mutex.c
90018+++ b/kernel/locking/mutex.c
90019@@ -518,7 +518,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
90020 goto skip_wait;
90021
90022 debug_mutex_lock_common(lock, &waiter);
90023- debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
90024+ debug_mutex_add_waiter(lock, &waiter, task);
90025
90026 /* add waiting tasks to the end of the waitqueue (FIFO): */
90027 list_add_tail(&waiter.list, &lock->wait_list);
90028@@ -563,7 +563,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
90029 schedule_preempt_disabled();
90030 spin_lock_mutex(&lock->wait_lock, flags);
90031 }
90032- mutex_remove_waiter(lock, &waiter, current_thread_info());
90033+ mutex_remove_waiter(lock, &waiter, task);
90034 /* set it to 0 if there are no waiters left: */
90035 if (likely(list_empty(&lock->wait_list)))
90036 atomic_set(&lock->count, 0);
90037@@ -600,7 +600,7 @@ skip_wait:
90038 return 0;
90039
90040 err:
90041- mutex_remove_waiter(lock, &waiter, task_thread_info(task));
90042+ mutex_remove_waiter(lock, &waiter, task);
90043 spin_unlock_mutex(&lock->wait_lock, flags);
90044 debug_mutex_free_waiter(&waiter);
90045 mutex_release(&lock->dep_map, 1, ip);
90046diff --git a/kernel/locking/rtmutex-tester.c b/kernel/locking/rtmutex-tester.c
90047index 1d96dd0..994ff19 100644
90048--- a/kernel/locking/rtmutex-tester.c
90049+++ b/kernel/locking/rtmutex-tester.c
90050@@ -22,7 +22,7 @@
90051 #define MAX_RT_TEST_MUTEXES 8
90052
90053 static spinlock_t rttest_lock;
90054-static atomic_t rttest_event;
90055+static atomic_unchecked_t rttest_event;
90056
90057 struct test_thread_data {
90058 int opcode;
90059@@ -63,7 +63,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
90060
90061 case RTTEST_LOCKCONT:
90062 td->mutexes[td->opdata] = 1;
90063- td->event = atomic_add_return(1, &rttest_event);
90064+ td->event = atomic_add_return_unchecked(1, &rttest_event);
90065 return 0;
90066
90067 case RTTEST_RESET:
90068@@ -76,7 +76,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
90069 return 0;
90070
90071 case RTTEST_RESETEVENT:
90072- atomic_set(&rttest_event, 0);
90073+ atomic_set_unchecked(&rttest_event, 0);
90074 return 0;
90075
90076 default:
90077@@ -93,9 +93,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
90078 return ret;
90079
90080 td->mutexes[id] = 1;
90081- td->event = atomic_add_return(1, &rttest_event);
90082+ td->event = atomic_add_return_unchecked(1, &rttest_event);
90083 rt_mutex_lock(&mutexes[id]);
90084- td->event = atomic_add_return(1, &rttest_event);
90085+ td->event = atomic_add_return_unchecked(1, &rttest_event);
90086 td->mutexes[id] = 4;
90087 return 0;
90088
90089@@ -106,9 +106,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
90090 return ret;
90091
90092 td->mutexes[id] = 1;
90093- td->event = atomic_add_return(1, &rttest_event);
90094+ td->event = atomic_add_return_unchecked(1, &rttest_event);
90095 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
90096- td->event = atomic_add_return(1, &rttest_event);
90097+ td->event = atomic_add_return_unchecked(1, &rttest_event);
90098 td->mutexes[id] = ret ? 0 : 4;
90099 return ret ? -EINTR : 0;
90100
90101@@ -117,9 +117,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
90102 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
90103 return ret;
90104
90105- td->event = atomic_add_return(1, &rttest_event);
90106+ td->event = atomic_add_return_unchecked(1, &rttest_event);
90107 rt_mutex_unlock(&mutexes[id]);
90108- td->event = atomic_add_return(1, &rttest_event);
90109+ td->event = atomic_add_return_unchecked(1, &rttest_event);
90110 td->mutexes[id] = 0;
90111 return 0;
90112
90113@@ -166,7 +166,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
90114 break;
90115
90116 td->mutexes[dat] = 2;
90117- td->event = atomic_add_return(1, &rttest_event);
90118+ td->event = atomic_add_return_unchecked(1, &rttest_event);
90119 break;
90120
90121 default:
90122@@ -186,7 +186,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
90123 return;
90124
90125 td->mutexes[dat] = 3;
90126- td->event = atomic_add_return(1, &rttest_event);
90127+ td->event = atomic_add_return_unchecked(1, &rttest_event);
90128 break;
90129
90130 case RTTEST_LOCKNOWAIT:
90131@@ -198,7 +198,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
90132 return;
90133
90134 td->mutexes[dat] = 1;
90135- td->event = atomic_add_return(1, &rttest_event);
90136+ td->event = atomic_add_return_unchecked(1, &rttest_event);
90137 return;
90138
90139 default:
90140diff --git a/kernel/module.c b/kernel/module.c
90141index 88cec1d..d097c28 100644
90142--- a/kernel/module.c
90143+++ b/kernel/module.c
90144@@ -60,6 +60,7 @@
90145 #include <linux/jump_label.h>
90146 #include <linux/pfn.h>
90147 #include <linux/bsearch.h>
90148+#include <linux/grsecurity.h>
90149 #include <uapi/linux/module.h>
90150 #include "module-internal.h"
90151
90152@@ -156,7 +157,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
90153
90154 /* Bounds of module allocation, for speeding __module_address.
90155 * Protected by module_mutex. */
90156-static unsigned long module_addr_min = -1UL, module_addr_max = 0;
90157+static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
90158+static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
90159
90160 int register_module_notifier(struct notifier_block * nb)
90161 {
90162@@ -323,7 +325,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
90163 return true;
90164
90165 list_for_each_entry_rcu(mod, &modules, list) {
90166- struct symsearch arr[] = {
90167+ struct symsearch modarr[] = {
90168 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
90169 NOT_GPL_ONLY, false },
90170 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
90171@@ -348,7 +350,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
90172 if (mod->state == MODULE_STATE_UNFORMED)
90173 continue;
90174
90175- if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
90176+ if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
90177 return true;
90178 }
90179 return false;
90180@@ -488,7 +490,7 @@ static int percpu_modalloc(struct module *mod, struct load_info *info)
90181 if (!pcpusec->sh_size)
90182 return 0;
90183
90184- if (align > PAGE_SIZE) {
90185+ if (align-1 >= PAGE_SIZE) {
90186 pr_warn("%s: per-cpu alignment %li > %li\n",
90187 mod->name, align, PAGE_SIZE);
90188 align = PAGE_SIZE;
90189@@ -1060,7 +1062,7 @@ struct module_attribute module_uevent =
90190 static ssize_t show_coresize(struct module_attribute *mattr,
90191 struct module_kobject *mk, char *buffer)
90192 {
90193- return sprintf(buffer, "%u\n", mk->mod->core_size);
90194+ return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
90195 }
90196
90197 static struct module_attribute modinfo_coresize =
90198@@ -1069,7 +1071,7 @@ static struct module_attribute modinfo_coresize =
90199 static ssize_t show_initsize(struct module_attribute *mattr,
90200 struct module_kobject *mk, char *buffer)
90201 {
90202- return sprintf(buffer, "%u\n", mk->mod->init_size);
90203+ return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
90204 }
90205
90206 static struct module_attribute modinfo_initsize =
90207@@ -1161,12 +1163,29 @@ static int check_version(Elf_Shdr *sechdrs,
90208 goto bad_version;
90209 }
90210
90211+#ifdef CONFIG_GRKERNSEC_RANDSTRUCT
90212+ /*
90213+ * avoid potentially printing jibberish on attempted load
90214+ * of a module randomized with a different seed
90215+ */
90216+ pr_warn("no symbol version for %s\n", symname);
90217+#else
90218 pr_warn("%s: no symbol version for %s\n", mod->name, symname);
90219+#endif
90220 return 0;
90221
90222 bad_version:
90223+#ifdef CONFIG_GRKERNSEC_RANDSTRUCT
90224+ /*
90225+ * avoid potentially printing jibberish on attempted load
90226+ * of a module randomized with a different seed
90227+ */
90228+ printk("attempted module disagrees about version of symbol %s\n",
90229+ symname);
90230+#else
90231 printk("%s: disagrees about version of symbol %s\n",
90232 mod->name, symname);
90233+#endif
90234 return 0;
90235 }
90236
90237@@ -1282,7 +1301,7 @@ resolve_symbol_wait(struct module *mod,
90238 */
90239 #ifdef CONFIG_SYSFS
90240
90241-#ifdef CONFIG_KALLSYMS
90242+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
90243 static inline bool sect_empty(const Elf_Shdr *sect)
90244 {
90245 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
90246@@ -1422,7 +1441,7 @@ static void add_notes_attrs(struct module *mod, const struct load_info *info)
90247 {
90248 unsigned int notes, loaded, i;
90249 struct module_notes_attrs *notes_attrs;
90250- struct bin_attribute *nattr;
90251+ bin_attribute_no_const *nattr;
90252
90253 /* failed to create section attributes, so can't create notes */
90254 if (!mod->sect_attrs)
90255@@ -1534,7 +1553,7 @@ static void del_usage_links(struct module *mod)
90256 static int module_add_modinfo_attrs(struct module *mod)
90257 {
90258 struct module_attribute *attr;
90259- struct module_attribute *temp_attr;
90260+ module_attribute_no_const *temp_attr;
90261 int error = 0;
90262 int i;
90263
90264@@ -1755,21 +1774,21 @@ static void set_section_ro_nx(void *base,
90265
90266 static void unset_module_core_ro_nx(struct module *mod)
90267 {
90268- set_page_attributes(mod->module_core + mod->core_text_size,
90269- mod->module_core + mod->core_size,
90270+ set_page_attributes(mod->module_core_rw,
90271+ mod->module_core_rw + mod->core_size_rw,
90272 set_memory_x);
90273- set_page_attributes(mod->module_core,
90274- mod->module_core + mod->core_ro_size,
90275+ set_page_attributes(mod->module_core_rx,
90276+ mod->module_core_rx + mod->core_size_rx,
90277 set_memory_rw);
90278 }
90279
90280 static void unset_module_init_ro_nx(struct module *mod)
90281 {
90282- set_page_attributes(mod->module_init + mod->init_text_size,
90283- mod->module_init + mod->init_size,
90284+ set_page_attributes(mod->module_init_rw,
90285+ mod->module_init_rw + mod->init_size_rw,
90286 set_memory_x);
90287- set_page_attributes(mod->module_init,
90288- mod->module_init + mod->init_ro_size,
90289+ set_page_attributes(mod->module_init_rx,
90290+ mod->module_init_rx + mod->init_size_rx,
90291 set_memory_rw);
90292 }
90293
90294@@ -1782,14 +1801,14 @@ void set_all_modules_text_rw(void)
90295 list_for_each_entry_rcu(mod, &modules, list) {
90296 if (mod->state == MODULE_STATE_UNFORMED)
90297 continue;
90298- if ((mod->module_core) && (mod->core_text_size)) {
90299- set_page_attributes(mod->module_core,
90300- mod->module_core + mod->core_text_size,
90301+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
90302+ set_page_attributes(mod->module_core_rx,
90303+ mod->module_core_rx + mod->core_size_rx,
90304 set_memory_rw);
90305 }
90306- if ((mod->module_init) && (mod->init_text_size)) {
90307- set_page_attributes(mod->module_init,
90308- mod->module_init + mod->init_text_size,
90309+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
90310+ set_page_attributes(mod->module_init_rx,
90311+ mod->module_init_rx + mod->init_size_rx,
90312 set_memory_rw);
90313 }
90314 }
90315@@ -1805,14 +1824,14 @@ void set_all_modules_text_ro(void)
90316 list_for_each_entry_rcu(mod, &modules, list) {
90317 if (mod->state == MODULE_STATE_UNFORMED)
90318 continue;
90319- if ((mod->module_core) && (mod->core_text_size)) {
90320- set_page_attributes(mod->module_core,
90321- mod->module_core + mod->core_text_size,
90322+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
90323+ set_page_attributes(mod->module_core_rx,
90324+ mod->module_core_rx + mod->core_size_rx,
90325 set_memory_ro);
90326 }
90327- if ((mod->module_init) && (mod->init_text_size)) {
90328- set_page_attributes(mod->module_init,
90329- mod->module_init + mod->init_text_size,
90330+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
90331+ set_page_attributes(mod->module_init_rx,
90332+ mod->module_init_rx + mod->init_size_rx,
90333 set_memory_ro);
90334 }
90335 }
90336@@ -1865,16 +1884,19 @@ static void free_module(struct module *mod)
90337
90338 /* This may be NULL, but that's OK */
90339 unset_module_init_ro_nx(mod);
90340- module_free(mod, mod->module_init);
90341+ module_free(mod, mod->module_init_rw);
90342+ module_free_exec(mod, mod->module_init_rx);
90343 kfree(mod->args);
90344 percpu_modfree(mod);
90345
90346 /* Free lock-classes: */
90347- lockdep_free_key_range(mod->module_core, mod->core_size);
90348+ lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
90349+ lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
90350
90351 /* Finally, free the core (containing the module structure) */
90352 unset_module_core_ro_nx(mod);
90353- module_free(mod, mod->module_core);
90354+ module_free_exec(mod, mod->module_core_rx);
90355+ module_free(mod, mod->module_core_rw);
90356
90357 #ifdef CONFIG_MPU
90358 update_protections(current->mm);
90359@@ -1943,9 +1965,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
90360 int ret = 0;
90361 const struct kernel_symbol *ksym;
90362
90363+#ifdef CONFIG_GRKERNSEC_MODHARDEN
90364+ int is_fs_load = 0;
90365+ int register_filesystem_found = 0;
90366+ char *p;
90367+
90368+ p = strstr(mod->args, "grsec_modharden_fs");
90369+ if (p) {
90370+ char *endptr = p + sizeof("grsec_modharden_fs") - 1;
90371+ /* copy \0 as well */
90372+ memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
90373+ is_fs_load = 1;
90374+ }
90375+#endif
90376+
90377 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
90378 const char *name = info->strtab + sym[i].st_name;
90379
90380+#ifdef CONFIG_GRKERNSEC_MODHARDEN
90381+ /* it's a real shame this will never get ripped and copied
90382+ upstream! ;(
90383+ */
90384+ if (is_fs_load && !strcmp(name, "register_filesystem"))
90385+ register_filesystem_found = 1;
90386+#endif
90387+
90388 switch (sym[i].st_shndx) {
90389 case SHN_COMMON:
90390 /* Ignore common symbols */
90391@@ -1970,7 +2014,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
90392 ksym = resolve_symbol_wait(mod, info, name);
90393 /* Ok if resolved. */
90394 if (ksym && !IS_ERR(ksym)) {
90395+ pax_open_kernel();
90396 sym[i].st_value = ksym->value;
90397+ pax_close_kernel();
90398 break;
90399 }
90400
90401@@ -1989,11 +2035,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
90402 secbase = (unsigned long)mod_percpu(mod);
90403 else
90404 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
90405+ pax_open_kernel();
90406 sym[i].st_value += secbase;
90407+ pax_close_kernel();
90408 break;
90409 }
90410 }
90411
90412+#ifdef CONFIG_GRKERNSEC_MODHARDEN
90413+ if (is_fs_load && !register_filesystem_found) {
90414+ printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
90415+ ret = -EPERM;
90416+ }
90417+#endif
90418+
90419 return ret;
90420 }
90421
90422@@ -2077,22 +2132,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
90423 || s->sh_entsize != ~0UL
90424 || strstarts(sname, ".init"))
90425 continue;
90426- s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
90427+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
90428+ s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
90429+ else
90430+ s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
90431 pr_debug("\t%s\n", sname);
90432 }
90433- switch (m) {
90434- case 0: /* executable */
90435- mod->core_size = debug_align(mod->core_size);
90436- mod->core_text_size = mod->core_size;
90437- break;
90438- case 1: /* RO: text and ro-data */
90439- mod->core_size = debug_align(mod->core_size);
90440- mod->core_ro_size = mod->core_size;
90441- break;
90442- case 3: /* whole core */
90443- mod->core_size = debug_align(mod->core_size);
90444- break;
90445- }
90446 }
90447
90448 pr_debug("Init section allocation order:\n");
90449@@ -2106,23 +2151,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
90450 || s->sh_entsize != ~0UL
90451 || !strstarts(sname, ".init"))
90452 continue;
90453- s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
90454- | INIT_OFFSET_MASK);
90455+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
90456+ s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
90457+ else
90458+ s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
90459+ s->sh_entsize |= INIT_OFFSET_MASK;
90460 pr_debug("\t%s\n", sname);
90461 }
90462- switch (m) {
90463- case 0: /* executable */
90464- mod->init_size = debug_align(mod->init_size);
90465- mod->init_text_size = mod->init_size;
90466- break;
90467- case 1: /* RO: text and ro-data */
90468- mod->init_size = debug_align(mod->init_size);
90469- mod->init_ro_size = mod->init_size;
90470- break;
90471- case 3: /* whole init */
90472- mod->init_size = debug_align(mod->init_size);
90473- break;
90474- }
90475 }
90476 }
90477
90478@@ -2295,7 +2330,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
90479
90480 /* Put symbol section at end of init part of module. */
90481 symsect->sh_flags |= SHF_ALLOC;
90482- symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
90483+ symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
90484 info->index.sym) | INIT_OFFSET_MASK;
90485 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
90486
90487@@ -2312,13 +2347,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
90488 }
90489
90490 /* Append room for core symbols at end of core part. */
90491- info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
90492- info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
90493- mod->core_size += strtab_size;
90494+ info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
90495+ info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
90496+ mod->core_size_rx += strtab_size;
90497
90498 /* Put string table section at end of init part of module. */
90499 strsect->sh_flags |= SHF_ALLOC;
90500- strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
90501+ strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
90502 info->index.str) | INIT_OFFSET_MASK;
90503 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
90504 }
90505@@ -2336,12 +2371,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
90506 /* Make sure we get permanent strtab: don't use info->strtab. */
90507 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
90508
90509+ pax_open_kernel();
90510+
90511 /* Set types up while we still have access to sections. */
90512 for (i = 0; i < mod->num_symtab; i++)
90513 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
90514
90515- mod->core_symtab = dst = mod->module_core + info->symoffs;
90516- mod->core_strtab = s = mod->module_core + info->stroffs;
90517+ mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
90518+ mod->core_strtab = s = mod->module_core_rx + info->stroffs;
90519 src = mod->symtab;
90520 for (ndst = i = 0; i < mod->num_symtab; i++) {
90521 if (i == 0 ||
90522@@ -2353,6 +2390,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
90523 }
90524 }
90525 mod->core_num_syms = ndst;
90526+
90527+ pax_close_kernel();
90528 }
90529 #else
90530 static inline void layout_symtab(struct module *mod, struct load_info *info)
90531@@ -2386,17 +2425,33 @@ void * __weak module_alloc(unsigned long size)
90532 return vmalloc_exec(size);
90533 }
90534
90535-static void *module_alloc_update_bounds(unsigned long size)
90536+static void *module_alloc_update_bounds_rw(unsigned long size)
90537 {
90538 void *ret = module_alloc(size);
90539
90540 if (ret) {
90541 mutex_lock(&module_mutex);
90542 /* Update module bounds. */
90543- if ((unsigned long)ret < module_addr_min)
90544- module_addr_min = (unsigned long)ret;
90545- if ((unsigned long)ret + size > module_addr_max)
90546- module_addr_max = (unsigned long)ret + size;
90547+ if ((unsigned long)ret < module_addr_min_rw)
90548+ module_addr_min_rw = (unsigned long)ret;
90549+ if ((unsigned long)ret + size > module_addr_max_rw)
90550+ module_addr_max_rw = (unsigned long)ret + size;
90551+ mutex_unlock(&module_mutex);
90552+ }
90553+ return ret;
90554+}
90555+
90556+static void *module_alloc_update_bounds_rx(unsigned long size)
90557+{
90558+ void *ret = module_alloc_exec(size);
90559+
90560+ if (ret) {
90561+ mutex_lock(&module_mutex);
90562+ /* Update module bounds. */
90563+ if ((unsigned long)ret < module_addr_min_rx)
90564+ module_addr_min_rx = (unsigned long)ret;
90565+ if ((unsigned long)ret + size > module_addr_max_rx)
90566+ module_addr_max_rx = (unsigned long)ret + size;
90567 mutex_unlock(&module_mutex);
90568 }
90569 return ret;
90570@@ -2650,7 +2705,15 @@ static struct module *setup_load_info(struct load_info *info, int flags)
90571 mod = (void *)info->sechdrs[info->index.mod].sh_addr;
90572
90573 if (info->index.sym == 0) {
90574+#ifdef CONFIG_GRKERNSEC_RANDSTRUCT
90575+ /*
90576+ * avoid potentially printing jibberish on attempted load
90577+ * of a module randomized with a different seed
90578+ */
90579+ pr_warn("module has no symbols (stripped?)\n");
90580+#else
90581 pr_warn("%s: module has no symbols (stripped?)\n", mod->name);
90582+#endif
90583 return ERR_PTR(-ENOEXEC);
90584 }
90585
90586@@ -2666,8 +2729,14 @@ static struct module *setup_load_info(struct load_info *info, int flags)
90587 static int check_modinfo(struct module *mod, struct load_info *info, int flags)
90588 {
90589 const char *modmagic = get_modinfo(info, "vermagic");
90590+ const char *license = get_modinfo(info, "license");
90591 int err;
90592
90593+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
90594+ if (!license || !license_is_gpl_compatible(license))
90595+ return -ENOEXEC;
90596+#endif
90597+
90598 if (flags & MODULE_INIT_IGNORE_VERMAGIC)
90599 modmagic = NULL;
90600
90601@@ -2692,7 +2761,7 @@ static int check_modinfo(struct module *mod, struct load_info *info, int flags)
90602 }
90603
90604 /* Set up license info based on the info section */
90605- set_license(mod, get_modinfo(info, "license"));
90606+ set_license(mod, license);
90607
90608 return 0;
90609 }
90610@@ -2786,7 +2855,7 @@ static int move_module(struct module *mod, struct load_info *info)
90611 void *ptr;
90612
90613 /* Do the allocs. */
90614- ptr = module_alloc_update_bounds(mod->core_size);
90615+ ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
90616 /*
90617 * The pointer to this block is stored in the module structure
90618 * which is inside the block. Just mark it as not being a
90619@@ -2796,11 +2865,11 @@ static int move_module(struct module *mod, struct load_info *info)
90620 if (!ptr)
90621 return -ENOMEM;
90622
90623- memset(ptr, 0, mod->core_size);
90624- mod->module_core = ptr;
90625+ memset(ptr, 0, mod->core_size_rw);
90626+ mod->module_core_rw = ptr;
90627
90628- if (mod->init_size) {
90629- ptr = module_alloc_update_bounds(mod->init_size);
90630+ if (mod->init_size_rw) {
90631+ ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
90632 /*
90633 * The pointer to this block is stored in the module structure
90634 * which is inside the block. This block doesn't need to be
90635@@ -2809,13 +2878,45 @@ static int move_module(struct module *mod, struct load_info *info)
90636 */
90637 kmemleak_ignore(ptr);
90638 if (!ptr) {
90639- module_free(mod, mod->module_core);
90640+ module_free(mod, mod->module_core_rw);
90641 return -ENOMEM;
90642 }
90643- memset(ptr, 0, mod->init_size);
90644- mod->module_init = ptr;
90645+ memset(ptr, 0, mod->init_size_rw);
90646+ mod->module_init_rw = ptr;
90647 } else
90648- mod->module_init = NULL;
90649+ mod->module_init_rw = NULL;
90650+
90651+ ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
90652+ kmemleak_not_leak(ptr);
90653+ if (!ptr) {
90654+ if (mod->module_init_rw)
90655+ module_free(mod, mod->module_init_rw);
90656+ module_free(mod, mod->module_core_rw);
90657+ return -ENOMEM;
90658+ }
90659+
90660+ pax_open_kernel();
90661+ memset(ptr, 0, mod->core_size_rx);
90662+ pax_close_kernel();
90663+ mod->module_core_rx = ptr;
90664+
90665+ if (mod->init_size_rx) {
90666+ ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
90667+ kmemleak_ignore(ptr);
90668+ if (!ptr && mod->init_size_rx) {
90669+ module_free_exec(mod, mod->module_core_rx);
90670+ if (mod->module_init_rw)
90671+ module_free(mod, mod->module_init_rw);
90672+ module_free(mod, mod->module_core_rw);
90673+ return -ENOMEM;
90674+ }
90675+
90676+ pax_open_kernel();
90677+ memset(ptr, 0, mod->init_size_rx);
90678+ pax_close_kernel();
90679+ mod->module_init_rx = ptr;
90680+ } else
90681+ mod->module_init_rx = NULL;
90682
90683 /* Transfer each section which specifies SHF_ALLOC */
90684 pr_debug("final section addresses:\n");
90685@@ -2826,16 +2927,45 @@ static int move_module(struct module *mod, struct load_info *info)
90686 if (!(shdr->sh_flags & SHF_ALLOC))
90687 continue;
90688
90689- if (shdr->sh_entsize & INIT_OFFSET_MASK)
90690- dest = mod->module_init
90691- + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
90692- else
90693- dest = mod->module_core + shdr->sh_entsize;
90694+ if (shdr->sh_entsize & INIT_OFFSET_MASK) {
90695+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
90696+ dest = mod->module_init_rw
90697+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
90698+ else
90699+ dest = mod->module_init_rx
90700+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
90701+ } else {
90702+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
90703+ dest = mod->module_core_rw + shdr->sh_entsize;
90704+ else
90705+ dest = mod->module_core_rx + shdr->sh_entsize;
90706+ }
90707+
90708+ if (shdr->sh_type != SHT_NOBITS) {
90709+
90710+#ifdef CONFIG_PAX_KERNEXEC
90711+#ifdef CONFIG_X86_64
90712+ if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
90713+ set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
90714+#endif
90715+ if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
90716+ pax_open_kernel();
90717+ memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
90718+ pax_close_kernel();
90719+ } else
90720+#endif
90721
90722- if (shdr->sh_type != SHT_NOBITS)
90723 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
90724+ }
90725 /* Update sh_addr to point to copy in image. */
90726- shdr->sh_addr = (unsigned long)dest;
90727+
90728+#ifdef CONFIG_PAX_KERNEXEC
90729+ if (shdr->sh_flags & SHF_EXECINSTR)
90730+ shdr->sh_addr = ktva_ktla((unsigned long)dest);
90731+ else
90732+#endif
90733+
90734+ shdr->sh_addr = (unsigned long)dest;
90735 pr_debug("\t0x%lx %s\n",
90736 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
90737 }
90738@@ -2892,12 +3022,12 @@ static void flush_module_icache(const struct module *mod)
90739 * Do it before processing of module parameters, so the module
90740 * can provide parameter accessor functions of its own.
90741 */
90742- if (mod->module_init)
90743- flush_icache_range((unsigned long)mod->module_init,
90744- (unsigned long)mod->module_init
90745- + mod->init_size);
90746- flush_icache_range((unsigned long)mod->module_core,
90747- (unsigned long)mod->module_core + mod->core_size);
90748+ if (mod->module_init_rx)
90749+ flush_icache_range((unsigned long)mod->module_init_rx,
90750+ (unsigned long)mod->module_init_rx
90751+ + mod->init_size_rx);
90752+ flush_icache_range((unsigned long)mod->module_core_rx,
90753+ (unsigned long)mod->module_core_rx + mod->core_size_rx);
90754
90755 set_fs(old_fs);
90756 }
90757@@ -2954,8 +3084,10 @@ static struct module *layout_and_allocate(struct load_info *info, int flags)
90758 static void module_deallocate(struct module *mod, struct load_info *info)
90759 {
90760 percpu_modfree(mod);
90761- module_free(mod, mod->module_init);
90762- module_free(mod, mod->module_core);
90763+ module_free_exec(mod, mod->module_init_rx);
90764+ module_free_exec(mod, mod->module_core_rx);
90765+ module_free(mod, mod->module_init_rw);
90766+ module_free(mod, mod->module_core_rw);
90767 }
90768
90769 int __weak module_finalize(const Elf_Ehdr *hdr,
90770@@ -2968,7 +3100,9 @@ int __weak module_finalize(const Elf_Ehdr *hdr,
90771 static int post_relocation(struct module *mod, const struct load_info *info)
90772 {
90773 /* Sort exception table now relocations are done. */
90774+ pax_open_kernel();
90775 sort_extable(mod->extable, mod->extable + mod->num_exentries);
90776+ pax_close_kernel();
90777
90778 /* Copy relocated percpu area over. */
90779 percpu_modcopy(mod, (void *)info->sechdrs[info->index.pcpu].sh_addr,
90780@@ -3077,11 +3211,12 @@ static int do_init_module(struct module *mod)
90781 mod->strtab = mod->core_strtab;
90782 #endif
90783 unset_module_init_ro_nx(mod);
90784- module_free(mod, mod->module_init);
90785- mod->module_init = NULL;
90786- mod->init_size = 0;
90787- mod->init_ro_size = 0;
90788- mod->init_text_size = 0;
90789+ module_free(mod, mod->module_init_rw);
90790+ module_free_exec(mod, mod->module_init_rx);
90791+ mod->module_init_rw = NULL;
90792+ mod->module_init_rx = NULL;
90793+ mod->init_size_rw = 0;
90794+ mod->init_size_rx = 0;
90795 mutex_unlock(&module_mutex);
90796 wake_up_all(&module_wq);
90797
90798@@ -3149,16 +3284,16 @@ static int complete_formation(struct module *mod, struct load_info *info)
90799 module_bug_finalize(info->hdr, info->sechdrs, mod);
90800
90801 /* Set RO and NX regions for core */
90802- set_section_ro_nx(mod->module_core,
90803- mod->core_text_size,
90804- mod->core_ro_size,
90805- mod->core_size);
90806+ set_section_ro_nx(mod->module_core_rx,
90807+ mod->core_size_rx,
90808+ mod->core_size_rx,
90809+ mod->core_size_rx);
90810
90811 /* Set RO and NX regions for init */
90812- set_section_ro_nx(mod->module_init,
90813- mod->init_text_size,
90814- mod->init_ro_size,
90815- mod->init_size);
90816+ set_section_ro_nx(mod->module_init_rx,
90817+ mod->init_size_rx,
90818+ mod->init_size_rx,
90819+ mod->init_size_rx);
90820
90821 /* Mark state as coming so strong_try_module_get() ignores us,
90822 * but kallsyms etc. can see us. */
90823@@ -3242,9 +3377,38 @@ static int load_module(struct load_info *info, const char __user *uargs,
90824 if (err)
90825 goto free_unload;
90826
90827+ /* Now copy in args */
90828+ mod->args = strndup_user(uargs, ~0UL >> 1);
90829+ if (IS_ERR(mod->args)) {
90830+ err = PTR_ERR(mod->args);
90831+ goto free_unload;
90832+ }
90833+
90834 /* Set up MODINFO_ATTR fields */
90835 setup_modinfo(mod, info);
90836
90837+#ifdef CONFIG_GRKERNSEC_MODHARDEN
90838+ {
90839+ char *p, *p2;
90840+
90841+ if (strstr(mod->args, "grsec_modharden_netdev")) {
90842+ 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);
90843+ err = -EPERM;
90844+ goto free_modinfo;
90845+ } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
90846+ p += sizeof("grsec_modharden_normal") - 1;
90847+ p2 = strstr(p, "_");
90848+ if (p2) {
90849+ *p2 = '\0';
90850+ printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
90851+ *p2 = '_';
90852+ }
90853+ err = -EPERM;
90854+ goto free_modinfo;
90855+ }
90856+ }
90857+#endif
90858+
90859 /* Fix up syms, so that st_value is a pointer to location. */
90860 err = simplify_symbols(mod, info);
90861 if (err < 0)
90862@@ -3260,13 +3424,6 @@ static int load_module(struct load_info *info, const char __user *uargs,
90863
90864 flush_module_icache(mod);
90865
90866- /* Now copy in args */
90867- mod->args = strndup_user(uargs, ~0UL >> 1);
90868- if (IS_ERR(mod->args)) {
90869- err = PTR_ERR(mod->args);
90870- goto free_arch_cleanup;
90871- }
90872-
90873 dynamic_debug_setup(info->debug, info->num_debug);
90874
90875 /* Ftrace init must be called in the MODULE_STATE_UNFORMED state */
90876@@ -3314,11 +3471,10 @@ static int load_module(struct load_info *info, const char __user *uargs,
90877 ddebug_cleanup:
90878 dynamic_debug_remove(info->debug);
90879 synchronize_sched();
90880- kfree(mod->args);
90881- free_arch_cleanup:
90882 module_arch_cleanup(mod);
90883 free_modinfo:
90884 free_modinfo(mod);
90885+ kfree(mod->args);
90886 free_unload:
90887 module_unload_free(mod);
90888 unlink_mod:
90889@@ -3403,10 +3559,16 @@ static const char *get_ksymbol(struct module *mod,
90890 unsigned long nextval;
90891
90892 /* At worse, next value is at end of module */
90893- if (within_module_init(addr, mod))
90894- nextval = (unsigned long)mod->module_init+mod->init_text_size;
90895+ if (within_module_init_rx(addr, mod))
90896+ nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
90897+ else if (within_module_init_rw(addr, mod))
90898+ nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
90899+ else if (within_module_core_rx(addr, mod))
90900+ nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
90901+ else if (within_module_core_rw(addr, mod))
90902+ nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
90903 else
90904- nextval = (unsigned long)mod->module_core+mod->core_text_size;
90905+ return NULL;
90906
90907 /* Scan for closest preceding symbol, and next symbol. (ELF
90908 starts real symbols at 1). */
90909@@ -3654,7 +3816,7 @@ static int m_show(struct seq_file *m, void *p)
90910 return 0;
90911
90912 seq_printf(m, "%s %u",
90913- mod->name, mod->init_size + mod->core_size);
90914+ mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
90915 print_unload_info(m, mod);
90916
90917 /* Informative for users. */
90918@@ -3663,7 +3825,7 @@ static int m_show(struct seq_file *m, void *p)
90919 mod->state == MODULE_STATE_COMING ? "Loading":
90920 "Live");
90921 /* Used by oprofile and other similar tools. */
90922- seq_printf(m, " 0x%pK", mod->module_core);
90923+ seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
90924
90925 /* Taints info */
90926 if (mod->taints)
90927@@ -3699,7 +3861,17 @@ static const struct file_operations proc_modules_operations = {
90928
90929 static int __init proc_modules_init(void)
90930 {
90931+#ifndef CONFIG_GRKERNSEC_HIDESYM
90932+#ifdef CONFIG_GRKERNSEC_PROC_USER
90933+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
90934+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
90935+ proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
90936+#else
90937 proc_create("modules", 0, NULL, &proc_modules_operations);
90938+#endif
90939+#else
90940+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
90941+#endif
90942 return 0;
90943 }
90944 module_init(proc_modules_init);
90945@@ -3760,7 +3932,8 @@ struct module *__module_address(unsigned long addr)
90946 {
90947 struct module *mod;
90948
90949- if (addr < module_addr_min || addr > module_addr_max)
90950+ if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
90951+ (addr < module_addr_min_rw || addr > module_addr_max_rw))
90952 return NULL;
90953
90954 list_for_each_entry_rcu(mod, &modules, list) {
90955@@ -3801,11 +3974,20 @@ bool is_module_text_address(unsigned long addr)
90956 */
90957 struct module *__module_text_address(unsigned long addr)
90958 {
90959- struct module *mod = __module_address(addr);
90960+ struct module *mod;
90961+
90962+#ifdef CONFIG_X86_32
90963+ addr = ktla_ktva(addr);
90964+#endif
90965+
90966+ if (addr < module_addr_min_rx || addr > module_addr_max_rx)
90967+ return NULL;
90968+
90969+ mod = __module_address(addr);
90970+
90971 if (mod) {
90972 /* Make sure it's within the text section. */
90973- if (!within(addr, mod->module_init, mod->init_text_size)
90974- && !within(addr, mod->module_core, mod->core_text_size))
90975+ if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
90976 mod = NULL;
90977 }
90978 return mod;
90979diff --git a/kernel/notifier.c b/kernel/notifier.c
90980index 4803da6..1c5eea6 100644
90981--- a/kernel/notifier.c
90982+++ b/kernel/notifier.c
90983@@ -5,6 +5,7 @@
90984 #include <linux/rcupdate.h>
90985 #include <linux/vmalloc.h>
90986 #include <linux/reboot.h>
90987+#include <linux/mm.h>
90988
90989 /*
90990 * Notifier list for kernel code which wants to be called
90991@@ -24,10 +25,12 @@ static int notifier_chain_register(struct notifier_block **nl,
90992 while ((*nl) != NULL) {
90993 if (n->priority > (*nl)->priority)
90994 break;
90995- nl = &((*nl)->next);
90996+ nl = (struct notifier_block **)&((*nl)->next);
90997 }
90998- n->next = *nl;
90999+ pax_open_kernel();
91000+ *(const void **)&n->next = *nl;
91001 rcu_assign_pointer(*nl, n);
91002+ pax_close_kernel();
91003 return 0;
91004 }
91005
91006@@ -39,10 +42,12 @@ static int notifier_chain_cond_register(struct notifier_block **nl,
91007 return 0;
91008 if (n->priority > (*nl)->priority)
91009 break;
91010- nl = &((*nl)->next);
91011+ nl = (struct notifier_block **)&((*nl)->next);
91012 }
91013- n->next = *nl;
91014+ pax_open_kernel();
91015+ *(const void **)&n->next = *nl;
91016 rcu_assign_pointer(*nl, n);
91017+ pax_close_kernel();
91018 return 0;
91019 }
91020
91021@@ -51,10 +56,12 @@ static int notifier_chain_unregister(struct notifier_block **nl,
91022 {
91023 while ((*nl) != NULL) {
91024 if ((*nl) == n) {
91025+ pax_open_kernel();
91026 rcu_assign_pointer(*nl, n->next);
91027+ pax_close_kernel();
91028 return 0;
91029 }
91030- nl = &((*nl)->next);
91031+ nl = (struct notifier_block **)&((*nl)->next);
91032 }
91033 return -ENOENT;
91034 }
91035diff --git a/kernel/padata.c b/kernel/padata.c
91036index 161402f..598814c 100644
91037--- a/kernel/padata.c
91038+++ b/kernel/padata.c
91039@@ -54,7 +54,7 @@ static int padata_cpu_hash(struct parallel_data *pd)
91040 * seq_nr mod. number of cpus in use.
91041 */
91042
91043- seq_nr = atomic_inc_return(&pd->seq_nr);
91044+ seq_nr = atomic_inc_return_unchecked(&pd->seq_nr);
91045 cpu_index = seq_nr % cpumask_weight(pd->cpumask.pcpu);
91046
91047 return padata_index_to_cpu(pd, cpu_index);
91048@@ -428,7 +428,7 @@ static struct parallel_data *padata_alloc_pd(struct padata_instance *pinst,
91049 padata_init_pqueues(pd);
91050 padata_init_squeues(pd);
91051 setup_timer(&pd->timer, padata_reorder_timer, (unsigned long)pd);
91052- atomic_set(&pd->seq_nr, -1);
91053+ atomic_set_unchecked(&pd->seq_nr, -1);
91054 atomic_set(&pd->reorder_objects, 0);
91055 atomic_set(&pd->refcnt, 0);
91056 pd->pinst = pinst;
91057diff --git a/kernel/panic.c b/kernel/panic.c
91058index cf80672..f6771b2 100644
91059--- a/kernel/panic.c
91060+++ b/kernel/panic.c
91061@@ -53,7 +53,7 @@ EXPORT_SYMBOL(panic_blink);
91062 /*
91063 * Stop ourself in panic -- architecture code may override this
91064 */
91065-void __weak panic_smp_self_stop(void)
91066+void __weak __noreturn panic_smp_self_stop(void)
91067 {
91068 while (1)
91069 cpu_relax();
91070@@ -422,7 +422,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
91071 disable_trace_on_warning();
91072
91073 pr_warn("------------[ cut here ]------------\n");
91074- pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pS()\n",
91075+ pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pA()\n",
91076 raw_smp_processor_id(), current->pid, file, line, caller);
91077
91078 if (args)
91079@@ -476,7 +476,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
91080 */
91081 __visible void __stack_chk_fail(void)
91082 {
91083- panic("stack-protector: Kernel stack is corrupted in: %p\n",
91084+ dump_stack();
91085+ panic("stack-protector: Kernel stack is corrupted in: %pA\n",
91086 __builtin_return_address(0));
91087 }
91088 EXPORT_SYMBOL(__stack_chk_fail);
91089diff --git a/kernel/pid.c b/kernel/pid.c
91090index 9b9a266..c20ef80 100644
91091--- a/kernel/pid.c
91092+++ b/kernel/pid.c
91093@@ -33,6 +33,7 @@
91094 #include <linux/rculist.h>
91095 #include <linux/bootmem.h>
91096 #include <linux/hash.h>
91097+#include <linux/security.h>
91098 #include <linux/pid_namespace.h>
91099 #include <linux/init_task.h>
91100 #include <linux/syscalls.h>
91101@@ -47,7 +48,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
91102
91103 int pid_max = PID_MAX_DEFAULT;
91104
91105-#define RESERVED_PIDS 300
91106+#define RESERVED_PIDS 500
91107
91108 int pid_max_min = RESERVED_PIDS + 1;
91109 int pid_max_max = PID_MAX_LIMIT;
91110@@ -445,10 +446,18 @@ EXPORT_SYMBOL(pid_task);
91111 */
91112 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
91113 {
91114+ struct task_struct *task;
91115+
91116 rcu_lockdep_assert(rcu_read_lock_held(),
91117 "find_task_by_pid_ns() needs rcu_read_lock()"
91118 " protection");
91119- return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
91120+
91121+ task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
91122+
91123+ if (gr_pid_is_chrooted(task))
91124+ return NULL;
91125+
91126+ return task;
91127 }
91128
91129 struct task_struct *find_task_by_vpid(pid_t vnr)
91130@@ -456,6 +465,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
91131 return find_task_by_pid_ns(vnr, task_active_pid_ns(current));
91132 }
91133
91134+struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
91135+{
91136+ rcu_lockdep_assert(rcu_read_lock_held(),
91137+ "find_task_by_pid_ns() needs rcu_read_lock()"
91138+ " protection");
91139+ return pid_task(find_pid_ns(vnr, task_active_pid_ns(current)), PIDTYPE_PID);
91140+}
91141+
91142 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
91143 {
91144 struct pid *pid;
91145diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c
91146index db95d8e..a0ca23f 100644
91147--- a/kernel/pid_namespace.c
91148+++ b/kernel/pid_namespace.c
91149@@ -253,7 +253,7 @@ static int pid_ns_ctl_handler(struct ctl_table *table, int write,
91150 void __user *buffer, size_t *lenp, loff_t *ppos)
91151 {
91152 struct pid_namespace *pid_ns = task_active_pid_ns(current);
91153- struct ctl_table tmp = *table;
91154+ ctl_table_no_const tmp = *table;
91155
91156 if (write && !ns_capable(pid_ns->user_ns, CAP_SYS_ADMIN))
91157 return -EPERM;
91158diff --git a/kernel/power/Kconfig b/kernel/power/Kconfig
91159index bbef57f..5f94462 100644
91160--- a/kernel/power/Kconfig
91161+++ b/kernel/power/Kconfig
91162@@ -24,6 +24,8 @@ config HIBERNATE_CALLBACKS
91163 config HIBERNATION
91164 bool "Hibernation (aka 'suspend to disk')"
91165 depends on SWAP && ARCH_HIBERNATION_POSSIBLE
91166+ depends on !GRKERNSEC_KMEM
91167+ depends on !PAX_MEMORY_SANITIZE
91168 select HIBERNATE_CALLBACKS
91169 select LZO_COMPRESS
91170 select LZO_DECOMPRESS
91171diff --git a/kernel/power/process.c b/kernel/power/process.c
91172index 5a6ec86..3a8c884 100644
91173--- a/kernel/power/process.c
91174+++ b/kernel/power/process.c
91175@@ -35,6 +35,7 @@ static int try_to_freeze_tasks(bool user_only)
91176 unsigned int elapsed_msecs;
91177 bool wakeup = false;
91178 int sleep_usecs = USEC_PER_MSEC;
91179+ bool timedout = false;
91180
91181 do_gettimeofday(&start);
91182
91183@@ -45,13 +46,20 @@ static int try_to_freeze_tasks(bool user_only)
91184
91185 while (true) {
91186 todo = 0;
91187+ if (time_after(jiffies, end_time))
91188+ timedout = true;
91189 read_lock(&tasklist_lock);
91190 for_each_process_thread(g, p) {
91191 if (p == current || !freeze_task(p))
91192 continue;
91193
91194- if (!freezer_should_skip(p))
91195+ if (!freezer_should_skip(p)) {
91196 todo++;
91197+ if (timedout) {
91198+ printk(KERN_ERR "Task refusing to freeze:\n");
91199+ sched_show_task(p);
91200+ }
91201+ }
91202 }
91203 read_unlock(&tasklist_lock);
91204
91205@@ -60,7 +68,7 @@ static int try_to_freeze_tasks(bool user_only)
91206 todo += wq_busy;
91207 }
91208
91209- if (!todo || time_after(jiffies, end_time))
91210+ if (!todo || timedout)
91211 break;
91212
91213 if (pm_wakeup_pending()) {
91214diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
91215index ced2b84..ffc4791 100644
91216--- a/kernel/printk/printk.c
91217+++ b/kernel/printk/printk.c
91218@@ -489,6 +489,11 @@ static int check_syslog_permissions(int type, bool from_file)
91219 if (from_file && type != SYSLOG_ACTION_OPEN)
91220 return 0;
91221
91222+#ifdef CONFIG_GRKERNSEC_DMESG
91223+ if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
91224+ return -EPERM;
91225+#endif
91226+
91227 if (syslog_action_restricted(type)) {
91228 if (capable(CAP_SYSLOG))
91229 return 0;
91230diff --git a/kernel/profile.c b/kernel/profile.c
91231index 54bf5ba..df6e0a2 100644
91232--- a/kernel/profile.c
91233+++ b/kernel/profile.c
91234@@ -37,7 +37,7 @@ struct profile_hit {
91235 #define NR_PROFILE_HIT (PAGE_SIZE/sizeof(struct profile_hit))
91236 #define NR_PROFILE_GRP (NR_PROFILE_HIT/PROFILE_GRPSZ)
91237
91238-static atomic_t *prof_buffer;
91239+static atomic_unchecked_t *prof_buffer;
91240 static unsigned long prof_len, prof_shift;
91241
91242 int prof_on __read_mostly;
91243@@ -256,7 +256,7 @@ static void profile_flip_buffers(void)
91244 hits[i].pc = 0;
91245 continue;
91246 }
91247- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
91248+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
91249 hits[i].hits = hits[i].pc = 0;
91250 }
91251 }
91252@@ -317,9 +317,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
91253 * Add the current hit(s) and flush the write-queue out
91254 * to the global buffer:
91255 */
91256- atomic_add(nr_hits, &prof_buffer[pc]);
91257+ atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
91258 for (i = 0; i < NR_PROFILE_HIT; ++i) {
91259- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
91260+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
91261 hits[i].pc = hits[i].hits = 0;
91262 }
91263 out:
91264@@ -394,7 +394,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
91265 {
91266 unsigned long pc;
91267 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
91268- atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
91269+ atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
91270 }
91271 #endif /* !CONFIG_SMP */
91272
91273@@ -490,7 +490,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
91274 return -EFAULT;
91275 buf++; p++; count--; read++;
91276 }
91277- pnt = (char *)prof_buffer + p - sizeof(atomic_t);
91278+ pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
91279 if (copy_to_user(buf, (void *)pnt, count))
91280 return -EFAULT;
91281 read += count;
91282@@ -521,7 +521,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
91283 }
91284 #endif
91285 profile_discard_flip_buffers();
91286- memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
91287+ memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
91288 return count;
91289 }
91290
91291diff --git a/kernel/ptrace.c b/kernel/ptrace.c
91292index 54e7522..5b82dd6 100644
91293--- a/kernel/ptrace.c
91294+++ b/kernel/ptrace.c
91295@@ -321,7 +321,7 @@ static int ptrace_attach(struct task_struct *task, long request,
91296 if (seize)
91297 flags |= PT_SEIZED;
91298 rcu_read_lock();
91299- if (ns_capable(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
91300+ if (ns_capable_nolog(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
91301 flags |= PT_PTRACE_CAP;
91302 rcu_read_unlock();
91303 task->ptrace = flags;
91304@@ -532,7 +532,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
91305 break;
91306 return -EIO;
91307 }
91308- if (copy_to_user(dst, buf, retval))
91309+ if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
91310 return -EFAULT;
91311 copied += retval;
91312 src += retval;
91313@@ -800,7 +800,7 @@ int ptrace_request(struct task_struct *child, long request,
91314 bool seized = child->ptrace & PT_SEIZED;
91315 int ret = -EIO;
91316 siginfo_t siginfo, *si;
91317- void __user *datavp = (void __user *) data;
91318+ void __user *datavp = (__force void __user *) data;
91319 unsigned long __user *datalp = datavp;
91320 unsigned long flags;
91321
91322@@ -1046,14 +1046,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
91323 goto out;
91324 }
91325
91326+ if (gr_handle_ptrace(child, request)) {
91327+ ret = -EPERM;
91328+ goto out_put_task_struct;
91329+ }
91330+
91331 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
91332 ret = ptrace_attach(child, request, addr, data);
91333 /*
91334 * Some architectures need to do book-keeping after
91335 * a ptrace attach.
91336 */
91337- if (!ret)
91338+ if (!ret) {
91339 arch_ptrace_attach(child);
91340+ gr_audit_ptrace(child);
91341+ }
91342 goto out_put_task_struct;
91343 }
91344
91345@@ -1081,7 +1088,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
91346 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
91347 if (copied != sizeof(tmp))
91348 return -EIO;
91349- return put_user(tmp, (unsigned long __user *)data);
91350+ return put_user(tmp, (__force unsigned long __user *)data);
91351 }
91352
91353 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
91354@@ -1175,7 +1182,7 @@ int compat_ptrace_request(struct task_struct *child, compat_long_t request,
91355 }
91356
91357 COMPAT_SYSCALL_DEFINE4(ptrace, compat_long_t, request, compat_long_t, pid,
91358- compat_long_t, addr, compat_long_t, data)
91359+ compat_ulong_t, addr, compat_ulong_t, data)
91360 {
91361 struct task_struct *child;
91362 long ret;
91363@@ -1191,14 +1198,21 @@ COMPAT_SYSCALL_DEFINE4(ptrace, compat_long_t, request, compat_long_t, pid,
91364 goto out;
91365 }
91366
91367+ if (gr_handle_ptrace(child, request)) {
91368+ ret = -EPERM;
91369+ goto out_put_task_struct;
91370+ }
91371+
91372 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
91373 ret = ptrace_attach(child, request, addr, data);
91374 /*
91375 * Some architectures need to do book-keeping after
91376 * a ptrace attach.
91377 */
91378- if (!ret)
91379+ if (!ret) {
91380 arch_ptrace_attach(child);
91381+ gr_audit_ptrace(child);
91382+ }
91383 goto out_put_task_struct;
91384 }
91385
91386diff --git a/kernel/rcu/rcutorture.c b/kernel/rcu/rcutorture.c
91387index 240fa90..5fa56bd 100644
91388--- a/kernel/rcu/rcutorture.c
91389+++ b/kernel/rcu/rcutorture.c
91390@@ -134,12 +134,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1],
91391 rcu_torture_count) = { 0 };
91392 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1],
91393 rcu_torture_batch) = { 0 };
91394-static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
91395-static atomic_t n_rcu_torture_alloc;
91396-static atomic_t n_rcu_torture_alloc_fail;
91397-static atomic_t n_rcu_torture_free;
91398-static atomic_t n_rcu_torture_mberror;
91399-static atomic_t n_rcu_torture_error;
91400+static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
91401+static atomic_unchecked_t n_rcu_torture_alloc;
91402+static atomic_unchecked_t n_rcu_torture_alloc_fail;
91403+static atomic_unchecked_t n_rcu_torture_free;
91404+static atomic_unchecked_t n_rcu_torture_mberror;
91405+static atomic_unchecked_t n_rcu_torture_error;
91406 static long n_rcu_torture_barrier_error;
91407 static long n_rcu_torture_boost_ktrerror;
91408 static long n_rcu_torture_boost_rterror;
91409@@ -148,7 +148,7 @@ static long n_rcu_torture_boosts;
91410 static long n_rcu_torture_timers;
91411 static long n_barrier_attempts;
91412 static long n_barrier_successes;
91413-static atomic_long_t n_cbfloods;
91414+static atomic_long_unchecked_t n_cbfloods;
91415 static struct list_head rcu_torture_removed;
91416
91417 static int rcu_torture_writer_state;
91418@@ -211,11 +211,11 @@ rcu_torture_alloc(void)
91419
91420 spin_lock_bh(&rcu_torture_lock);
91421 if (list_empty(&rcu_torture_freelist)) {
91422- atomic_inc(&n_rcu_torture_alloc_fail);
91423+ atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
91424 spin_unlock_bh(&rcu_torture_lock);
91425 return NULL;
91426 }
91427- atomic_inc(&n_rcu_torture_alloc);
91428+ atomic_inc_unchecked(&n_rcu_torture_alloc);
91429 p = rcu_torture_freelist.next;
91430 list_del_init(p);
91431 spin_unlock_bh(&rcu_torture_lock);
91432@@ -228,7 +228,7 @@ rcu_torture_alloc(void)
91433 static void
91434 rcu_torture_free(struct rcu_torture *p)
91435 {
91436- atomic_inc(&n_rcu_torture_free);
91437+ atomic_inc_unchecked(&n_rcu_torture_free);
91438 spin_lock_bh(&rcu_torture_lock);
91439 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
91440 spin_unlock_bh(&rcu_torture_lock);
91441@@ -312,7 +312,7 @@ rcu_torture_pipe_update_one(struct rcu_torture *rp)
91442 i = rp->rtort_pipe_count;
91443 if (i > RCU_TORTURE_PIPE_LEN)
91444 i = RCU_TORTURE_PIPE_LEN;
91445- atomic_inc(&rcu_torture_wcount[i]);
91446+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
91447 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
91448 rp->rtort_mbtest = 0;
91449 return true;
91450@@ -799,7 +799,7 @@ rcu_torture_cbflood(void *arg)
91451 VERBOSE_TOROUT_STRING("rcu_torture_cbflood task started");
91452 do {
91453 schedule_timeout_interruptible(cbflood_inter_holdoff);
91454- atomic_long_inc(&n_cbfloods);
91455+ atomic_long_inc_unchecked(&n_cbfloods);
91456 WARN_ON(signal_pending(current));
91457 for (i = 0; i < cbflood_n_burst; i++) {
91458 for (j = 0; j < cbflood_n_per_burst; j++) {
91459@@ -917,7 +917,7 @@ rcu_torture_writer(void *arg)
91460 i = old_rp->rtort_pipe_count;
91461 if (i > RCU_TORTURE_PIPE_LEN)
91462 i = RCU_TORTURE_PIPE_LEN;
91463- atomic_inc(&rcu_torture_wcount[i]);
91464+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
91465 old_rp->rtort_pipe_count++;
91466 switch (synctype[torture_random(&rand) % nsynctypes]) {
91467 case RTWS_DEF_FREE:
91468@@ -1035,7 +1035,7 @@ static void rcu_torture_timer(unsigned long unused)
91469 return;
91470 }
91471 if (p->rtort_mbtest == 0)
91472- atomic_inc(&n_rcu_torture_mberror);
91473+ atomic_inc_unchecked(&n_rcu_torture_mberror);
91474 spin_lock(&rand_lock);
91475 cur_ops->read_delay(&rand);
91476 n_rcu_torture_timers++;
91477@@ -1105,7 +1105,7 @@ rcu_torture_reader(void *arg)
91478 continue;
91479 }
91480 if (p->rtort_mbtest == 0)
91481- atomic_inc(&n_rcu_torture_mberror);
91482+ atomic_inc_unchecked(&n_rcu_torture_mberror);
91483 cur_ops->read_delay(&rand);
91484 preempt_disable();
91485 pipe_count = p->rtort_pipe_count;
91486@@ -1172,11 +1172,11 @@ rcu_torture_stats_print(void)
91487 rcu_torture_current,
91488 rcu_torture_current_version,
91489 list_empty(&rcu_torture_freelist),
91490- atomic_read(&n_rcu_torture_alloc),
91491- atomic_read(&n_rcu_torture_alloc_fail),
91492- atomic_read(&n_rcu_torture_free));
91493+ atomic_read_unchecked(&n_rcu_torture_alloc),
91494+ atomic_read_unchecked(&n_rcu_torture_alloc_fail),
91495+ atomic_read_unchecked(&n_rcu_torture_free));
91496 pr_cont("rtmbe: %d rtbke: %ld rtbre: %ld ",
91497- atomic_read(&n_rcu_torture_mberror),
91498+ atomic_read_unchecked(&n_rcu_torture_mberror),
91499 n_rcu_torture_boost_ktrerror,
91500 n_rcu_torture_boost_rterror);
91501 pr_cont("rtbf: %ld rtb: %ld nt: %ld ",
91502@@ -1188,17 +1188,17 @@ rcu_torture_stats_print(void)
91503 n_barrier_successes,
91504 n_barrier_attempts,
91505 n_rcu_torture_barrier_error);
91506- pr_cont("cbflood: %ld\n", atomic_long_read(&n_cbfloods));
91507+ pr_cont("cbflood: %ld\n", atomic_long_read_unchecked(&n_cbfloods));
91508
91509 pr_alert("%s%s ", torture_type, TORTURE_FLAG);
91510- if (atomic_read(&n_rcu_torture_mberror) != 0 ||
91511+ if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
91512 n_rcu_torture_barrier_error != 0 ||
91513 n_rcu_torture_boost_ktrerror != 0 ||
91514 n_rcu_torture_boost_rterror != 0 ||
91515 n_rcu_torture_boost_failure != 0 ||
91516 i > 1) {
91517 pr_cont("%s", "!!! ");
91518- atomic_inc(&n_rcu_torture_error);
91519+ atomic_inc_unchecked(&n_rcu_torture_error);
91520 WARN_ON_ONCE(1);
91521 }
91522 pr_cont("Reader Pipe: ");
91523@@ -1215,7 +1215,7 @@ rcu_torture_stats_print(void)
91524 pr_alert("%s%s ", torture_type, TORTURE_FLAG);
91525 pr_cont("Free-Block Circulation: ");
91526 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
91527- pr_cont(" %d", atomic_read(&rcu_torture_wcount[i]));
91528+ pr_cont(" %d", atomic_read_unchecked(&rcu_torture_wcount[i]));
91529 }
91530 pr_cont("\n");
91531
91532@@ -1559,7 +1559,7 @@ rcu_torture_cleanup(void)
91533
91534 rcu_torture_stats_print(); /* -After- the stats thread is stopped! */
91535
91536- if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
91537+ if (atomic_read_unchecked(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
91538 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
91539 else if (torture_onoff_failures())
91540 rcu_torture_print_module_parms(cur_ops,
91541@@ -1684,18 +1684,18 @@ rcu_torture_init(void)
91542
91543 rcu_torture_current = NULL;
91544 rcu_torture_current_version = 0;
91545- atomic_set(&n_rcu_torture_alloc, 0);
91546- atomic_set(&n_rcu_torture_alloc_fail, 0);
91547- atomic_set(&n_rcu_torture_free, 0);
91548- atomic_set(&n_rcu_torture_mberror, 0);
91549- atomic_set(&n_rcu_torture_error, 0);
91550+ atomic_set_unchecked(&n_rcu_torture_alloc, 0);
91551+ atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
91552+ atomic_set_unchecked(&n_rcu_torture_free, 0);
91553+ atomic_set_unchecked(&n_rcu_torture_mberror, 0);
91554+ atomic_set_unchecked(&n_rcu_torture_error, 0);
91555 n_rcu_torture_barrier_error = 0;
91556 n_rcu_torture_boost_ktrerror = 0;
91557 n_rcu_torture_boost_rterror = 0;
91558 n_rcu_torture_boost_failure = 0;
91559 n_rcu_torture_boosts = 0;
91560 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
91561- atomic_set(&rcu_torture_wcount[i], 0);
91562+ atomic_set_unchecked(&rcu_torture_wcount[i], 0);
91563 for_each_possible_cpu(cpu) {
91564 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
91565 per_cpu(rcu_torture_count, cpu)[i] = 0;
91566diff --git a/kernel/rcu/tiny.c b/kernel/rcu/tiny.c
91567index c0623fc..329c091 100644
91568--- a/kernel/rcu/tiny.c
91569+++ b/kernel/rcu/tiny.c
91570@@ -42,7 +42,7 @@
91571 /* Forward declarations for tiny_plugin.h. */
91572 struct rcu_ctrlblk;
91573 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
91574-static void rcu_process_callbacks(struct softirq_action *unused);
91575+static void rcu_process_callbacks(void);
91576 static void __call_rcu(struct rcu_head *head,
91577 void (*func)(struct rcu_head *rcu),
91578 struct rcu_ctrlblk *rcp);
91579@@ -310,7 +310,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
91580 false));
91581 }
91582
91583-static void rcu_process_callbacks(struct softirq_action *unused)
91584+static __latent_entropy void rcu_process_callbacks(void)
91585 {
91586 __rcu_process_callbacks(&rcu_sched_ctrlblk);
91587 __rcu_process_callbacks(&rcu_bh_ctrlblk);
91588diff --git a/kernel/rcu/tiny_plugin.h b/kernel/rcu/tiny_plugin.h
91589index 858c565..7efd915 100644
91590--- a/kernel/rcu/tiny_plugin.h
91591+++ b/kernel/rcu/tiny_plugin.h
91592@@ -152,17 +152,17 @@ static void check_cpu_stall(struct rcu_ctrlblk *rcp)
91593 dump_stack();
91594 }
91595 if (*rcp->curtail && ULONG_CMP_GE(j, js))
91596- ACCESS_ONCE(rcp->jiffies_stall) = jiffies +
91597+ ACCESS_ONCE_RW(rcp->jiffies_stall) = jiffies +
91598 3 * rcu_jiffies_till_stall_check() + 3;
91599 else if (ULONG_CMP_GE(j, js))
91600- ACCESS_ONCE(rcp->jiffies_stall) = jiffies + rcu_jiffies_till_stall_check();
91601+ ACCESS_ONCE_RW(rcp->jiffies_stall) = jiffies + rcu_jiffies_till_stall_check();
91602 }
91603
91604 static void reset_cpu_stall_ticks(struct rcu_ctrlblk *rcp)
91605 {
91606 rcp->ticks_this_gp = 0;
91607 rcp->gp_start = jiffies;
91608- ACCESS_ONCE(rcp->jiffies_stall) = jiffies + rcu_jiffies_till_stall_check();
91609+ ACCESS_ONCE_RW(rcp->jiffies_stall) = jiffies + rcu_jiffies_till_stall_check();
91610 }
91611
91612 static void check_cpu_stalls(void)
91613diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c
91614index 9815447..2cdf92a 100644
91615--- a/kernel/rcu/tree.c
91616+++ b/kernel/rcu/tree.c
91617@@ -274,7 +274,7 @@ static void rcu_momentary_dyntick_idle(void)
91618 */
91619 rdtp = this_cpu_ptr(&rcu_dynticks);
91620 smp_mb__before_atomic(); /* Earlier stuff before QS. */
91621- atomic_add(2, &rdtp->dynticks); /* QS. */
91622+ atomic_add_unchecked(2, &rdtp->dynticks); /* QS. */
91623 smp_mb__after_atomic(); /* Later stuff after QS. */
91624 break;
91625 }
91626@@ -534,9 +534,9 @@ static void rcu_eqs_enter_common(struct rcu_dynticks *rdtp, long long oldval,
91627 rcu_prepare_for_idle(smp_processor_id());
91628 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
91629 smp_mb__before_atomic(); /* See above. */
91630- atomic_inc(&rdtp->dynticks);
91631+ atomic_inc_unchecked(&rdtp->dynticks);
91632 smp_mb__after_atomic(); /* Force ordering with next sojourn. */
91633- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
91634+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
91635 rcu_dynticks_task_enter();
91636
91637 /*
91638@@ -656,10 +656,10 @@ static void rcu_eqs_exit_common(struct rcu_dynticks *rdtp, long long oldval,
91639 {
91640 rcu_dynticks_task_exit();
91641 smp_mb__before_atomic(); /* Force ordering w/previous sojourn. */
91642- atomic_inc(&rdtp->dynticks);
91643+ atomic_inc_unchecked(&rdtp->dynticks);
91644 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
91645 smp_mb__after_atomic(); /* See above. */
91646- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
91647+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
91648 rcu_cleanup_after_idle(smp_processor_id());
91649 trace_rcu_dyntick(TPS("End"), oldval, rdtp->dynticks_nesting);
91650 if (!user && !is_idle_task(current)) {
91651@@ -780,14 +780,14 @@ void rcu_nmi_enter(void)
91652 struct rcu_dynticks *rdtp = this_cpu_ptr(&rcu_dynticks);
91653
91654 if (rdtp->dynticks_nmi_nesting == 0 &&
91655- (atomic_read(&rdtp->dynticks) & 0x1))
91656+ (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
91657 return;
91658 rdtp->dynticks_nmi_nesting++;
91659 smp_mb__before_atomic(); /* Force delay from prior write. */
91660- atomic_inc(&rdtp->dynticks);
91661+ atomic_inc_unchecked(&rdtp->dynticks);
91662 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
91663 smp_mb__after_atomic(); /* See above. */
91664- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
91665+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
91666 }
91667
91668 /**
91669@@ -806,9 +806,9 @@ void rcu_nmi_exit(void)
91670 return;
91671 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
91672 smp_mb__before_atomic(); /* See above. */
91673- atomic_inc(&rdtp->dynticks);
91674+ atomic_inc_unchecked(&rdtp->dynticks);
91675 smp_mb__after_atomic(); /* Force delay to next write. */
91676- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
91677+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
91678 }
91679
91680 /**
91681@@ -821,7 +821,7 @@ void rcu_nmi_exit(void)
91682 */
91683 bool notrace __rcu_is_watching(void)
91684 {
91685- return atomic_read(this_cpu_ptr(&rcu_dynticks.dynticks)) & 0x1;
91686+ return atomic_read_unchecked(this_cpu_ptr(&rcu_dynticks.dynticks)) & 0x1;
91687 }
91688
91689 /**
91690@@ -904,7 +904,7 @@ static int rcu_is_cpu_rrupt_from_idle(void)
91691 static int dyntick_save_progress_counter(struct rcu_data *rdp,
91692 bool *isidle, unsigned long *maxj)
91693 {
91694- rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
91695+ rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
91696 rcu_sysidle_check_cpu(rdp, isidle, maxj);
91697 if ((rdp->dynticks_snap & 0x1) == 0) {
91698 trace_rcu_fqs(rdp->rsp->name, rdp->gpnum, rdp->cpu, TPS("dti"));
91699@@ -933,7 +933,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp,
91700 int *rcrmp;
91701 unsigned int snap;
91702
91703- curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
91704+ curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
91705 snap = (unsigned int)rdp->dynticks_snap;
91706
91707 /*
91708@@ -996,10 +996,10 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp,
91709 rdp->rsp->gp_start + jiffies_till_sched_qs) ||
91710 ULONG_CMP_GE(jiffies, rdp->rsp->jiffies_resched)) {
91711 if (!(ACCESS_ONCE(*rcrmp) & rdp->rsp->flavor_mask)) {
91712- ACCESS_ONCE(rdp->cond_resched_completed) =
91713+ ACCESS_ONCE_RW(rdp->cond_resched_completed) =
91714 ACCESS_ONCE(rdp->mynode->completed);
91715 smp_mb(); /* ->cond_resched_completed before *rcrmp. */
91716- ACCESS_ONCE(*rcrmp) =
91717+ ACCESS_ONCE_RW(*rcrmp) =
91718 ACCESS_ONCE(*rcrmp) + rdp->rsp->flavor_mask;
91719 resched_cpu(rdp->cpu); /* Force CPU into scheduler. */
91720 rdp->rsp->jiffies_resched += 5; /* Enable beating. */
91721@@ -1021,7 +1021,7 @@ static void record_gp_stall_check_time(struct rcu_state *rsp)
91722 rsp->gp_start = j;
91723 smp_wmb(); /* Record start time before stall time. */
91724 j1 = rcu_jiffies_till_stall_check();
91725- ACCESS_ONCE(rsp->jiffies_stall) = j + j1;
91726+ ACCESS_ONCE_RW(rsp->jiffies_stall) = j + j1;
91727 rsp->jiffies_resched = j + j1 / 2;
91728 }
91729
91730@@ -1062,7 +1062,7 @@ static void print_other_cpu_stall(struct rcu_state *rsp)
91731 raw_spin_unlock_irqrestore(&rnp->lock, flags);
91732 return;
91733 }
91734- ACCESS_ONCE(rsp->jiffies_stall) = jiffies + 3 * rcu_jiffies_till_stall_check() + 3;
91735+ ACCESS_ONCE_RW(rsp->jiffies_stall) = jiffies + 3 * rcu_jiffies_till_stall_check() + 3;
91736 raw_spin_unlock_irqrestore(&rnp->lock, flags);
91737
91738 /*
91739@@ -1139,7 +1139,7 @@ static void print_cpu_stall(struct rcu_state *rsp)
91740
91741 raw_spin_lock_irqsave(&rnp->lock, flags);
91742 if (ULONG_CMP_GE(jiffies, ACCESS_ONCE(rsp->jiffies_stall)))
91743- ACCESS_ONCE(rsp->jiffies_stall) = jiffies +
91744+ ACCESS_ONCE_RW(rsp->jiffies_stall) = jiffies +
91745 3 * rcu_jiffies_till_stall_check() + 3;
91746 raw_spin_unlock_irqrestore(&rnp->lock, flags);
91747
91748@@ -1223,7 +1223,7 @@ void rcu_cpu_stall_reset(void)
91749 struct rcu_state *rsp;
91750
91751 for_each_rcu_flavor(rsp)
91752- ACCESS_ONCE(rsp->jiffies_stall) = jiffies + ULONG_MAX / 2;
91753+ ACCESS_ONCE_RW(rsp->jiffies_stall) = jiffies + ULONG_MAX / 2;
91754 }
91755
91756 /*
91757@@ -1609,7 +1609,7 @@ static int rcu_gp_init(struct rcu_state *rsp)
91758 raw_spin_unlock_irq(&rnp->lock);
91759 return 0;
91760 }
91761- ACCESS_ONCE(rsp->gp_flags) = 0; /* Clear all flags: New grace period. */
91762+ ACCESS_ONCE_RW(rsp->gp_flags) = 0; /* Clear all flags: New grace period. */
91763
91764 if (WARN_ON_ONCE(rcu_gp_in_progress(rsp))) {
91765 /*
91766@@ -1650,9 +1650,9 @@ static int rcu_gp_init(struct rcu_state *rsp)
91767 rdp = this_cpu_ptr(rsp->rda);
91768 rcu_preempt_check_blocked_tasks(rnp);
91769 rnp->qsmask = rnp->qsmaskinit;
91770- ACCESS_ONCE(rnp->gpnum) = rsp->gpnum;
91771+ ACCESS_ONCE_RW(rnp->gpnum) = rsp->gpnum;
91772 WARN_ON_ONCE(rnp->completed != rsp->completed);
91773- ACCESS_ONCE(rnp->completed) = rsp->completed;
91774+ ACCESS_ONCE_RW(rnp->completed) = rsp->completed;
91775 if (rnp == rdp->mynode)
91776 (void)__note_gp_changes(rsp, rnp, rdp);
91777 rcu_preempt_boost_start_gp(rnp);
91778@@ -1697,7 +1697,7 @@ static int rcu_gp_fqs(struct rcu_state *rsp, int fqs_state_in)
91779 if (ACCESS_ONCE(rsp->gp_flags) & RCU_GP_FLAG_FQS) {
91780 raw_spin_lock_irq(&rnp->lock);
91781 smp_mb__after_unlock_lock();
91782- ACCESS_ONCE(rsp->gp_flags) =
91783+ ACCESS_ONCE_RW(rsp->gp_flags) =
91784 ACCESS_ONCE(rsp->gp_flags) & ~RCU_GP_FLAG_FQS;
91785 raw_spin_unlock_irq(&rnp->lock);
91786 }
91787@@ -1743,7 +1743,7 @@ static void rcu_gp_cleanup(struct rcu_state *rsp)
91788 rcu_for_each_node_breadth_first(rsp, rnp) {
91789 raw_spin_lock_irq(&rnp->lock);
91790 smp_mb__after_unlock_lock();
91791- ACCESS_ONCE(rnp->completed) = rsp->gpnum;
91792+ ACCESS_ONCE_RW(rnp->completed) = rsp->gpnum;
91793 rdp = this_cpu_ptr(rsp->rda);
91794 if (rnp == rdp->mynode)
91795 needgp = __note_gp_changes(rsp, rnp, rdp) || needgp;
91796@@ -1758,14 +1758,14 @@ static void rcu_gp_cleanup(struct rcu_state *rsp)
91797 rcu_nocb_gp_set(rnp, nocb);
91798
91799 /* Declare grace period done. */
91800- ACCESS_ONCE(rsp->completed) = rsp->gpnum;
91801+ ACCESS_ONCE_RW(rsp->completed) = rsp->gpnum;
91802 trace_rcu_grace_period(rsp->name, rsp->completed, TPS("end"));
91803 rsp->fqs_state = RCU_GP_IDLE;
91804 rdp = this_cpu_ptr(rsp->rda);
91805 /* Advance CBs to reduce false positives below. */
91806 needgp = rcu_advance_cbs(rsp, rnp, rdp) || needgp;
91807 if (needgp || cpu_needs_another_gp(rsp, rdp)) {
91808- ACCESS_ONCE(rsp->gp_flags) = RCU_GP_FLAG_INIT;
91809+ ACCESS_ONCE_RW(rsp->gp_flags) = RCU_GP_FLAG_INIT;
91810 trace_rcu_grace_period(rsp->name,
91811 ACCESS_ONCE(rsp->gpnum),
91812 TPS("newreq"));
91813@@ -1890,7 +1890,7 @@ rcu_start_gp_advanced(struct rcu_state *rsp, struct rcu_node *rnp,
91814 */
91815 return false;
91816 }
91817- ACCESS_ONCE(rsp->gp_flags) = RCU_GP_FLAG_INIT;
91818+ ACCESS_ONCE_RW(rsp->gp_flags) = RCU_GP_FLAG_INIT;
91819 trace_rcu_grace_period(rsp->name, ACCESS_ONCE(rsp->gpnum),
91820 TPS("newreq"));
91821
91822@@ -2111,7 +2111,7 @@ rcu_send_cbs_to_orphanage(int cpu, struct rcu_state *rsp,
91823 rsp->qlen += rdp->qlen;
91824 rdp->n_cbs_orphaned += rdp->qlen;
91825 rdp->qlen_lazy = 0;
91826- ACCESS_ONCE(rdp->qlen) = 0;
91827+ ACCESS_ONCE_RW(rdp->qlen) = 0;
91828 }
91829
91830 /*
91831@@ -2356,7 +2356,7 @@ static void rcu_do_batch(struct rcu_state *rsp, struct rcu_data *rdp)
91832 }
91833 smp_mb(); /* List handling before counting for rcu_barrier(). */
91834 rdp->qlen_lazy -= count_lazy;
91835- ACCESS_ONCE(rdp->qlen) = rdp->qlen - count;
91836+ ACCESS_ONCE_RW(rdp->qlen) = rdp->qlen - count;
91837 rdp->n_cbs_invoked += count;
91838
91839 /* Reinstate batch limit if we have worked down the excess. */
91840@@ -2519,7 +2519,7 @@ static void force_quiescent_state(struct rcu_state *rsp)
91841 raw_spin_unlock_irqrestore(&rnp_old->lock, flags);
91842 return; /* Someone beat us to it. */
91843 }
91844- ACCESS_ONCE(rsp->gp_flags) =
91845+ ACCESS_ONCE_RW(rsp->gp_flags) =
91846 ACCESS_ONCE(rsp->gp_flags) | RCU_GP_FLAG_FQS;
91847 raw_spin_unlock_irqrestore(&rnp_old->lock, flags);
91848 rcu_gp_kthread_wake(rsp);
91849@@ -2565,7 +2565,7 @@ __rcu_process_callbacks(struct rcu_state *rsp)
91850 /*
91851 * Do RCU core processing for the current CPU.
91852 */
91853-static void rcu_process_callbacks(struct softirq_action *unused)
91854+static void rcu_process_callbacks(void)
91855 {
91856 struct rcu_state *rsp;
91857
91858@@ -2677,7 +2677,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
91859 WARN_ON_ONCE((unsigned long)head & 0x1); /* Misaligned rcu_head! */
91860 if (debug_rcu_head_queue(head)) {
91861 /* Probable double call_rcu(), so leak the callback. */
91862- ACCESS_ONCE(head->func) = rcu_leak_callback;
91863+ ACCESS_ONCE_RW(head->func) = rcu_leak_callback;
91864 WARN_ONCE(1, "__call_rcu(): Leaked duplicate callback\n");
91865 return;
91866 }
91867@@ -2705,7 +2705,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
91868 local_irq_restore(flags);
91869 return;
91870 }
91871- ACCESS_ONCE(rdp->qlen) = rdp->qlen + 1;
91872+ ACCESS_ONCE_RW(rdp->qlen) = rdp->qlen + 1;
91873 if (lazy)
91874 rdp->qlen_lazy++;
91875 else
91876@@ -2975,11 +2975,11 @@ void synchronize_sched_expedited(void)
91877 * counter wrap on a 32-bit system. Quite a few more CPUs would of
91878 * course be required on a 64-bit system.
91879 */
91880- if (ULONG_CMP_GE((ulong)atomic_long_read(&rsp->expedited_start),
91881+ if (ULONG_CMP_GE((ulong)atomic_long_read_unchecked(&rsp->expedited_start),
91882 (ulong)atomic_long_read(&rsp->expedited_done) +
91883 ULONG_MAX / 8)) {
91884 synchronize_sched();
91885- atomic_long_inc(&rsp->expedited_wrap);
91886+ atomic_long_inc_unchecked(&rsp->expedited_wrap);
91887 return;
91888 }
91889
91890@@ -2987,12 +2987,12 @@ void synchronize_sched_expedited(void)
91891 * Take a ticket. Note that atomic_inc_return() implies a
91892 * full memory barrier.
91893 */
91894- snap = atomic_long_inc_return(&rsp->expedited_start);
91895+ snap = atomic_long_inc_return_unchecked(&rsp->expedited_start);
91896 firstsnap = snap;
91897 if (!try_get_online_cpus()) {
91898 /* CPU hotplug operation in flight, fall back to normal GP. */
91899 wait_rcu_gp(call_rcu_sched);
91900- atomic_long_inc(&rsp->expedited_normal);
91901+ atomic_long_inc_unchecked(&rsp->expedited_normal);
91902 return;
91903 }
91904 WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id()));
91905@@ -3005,14 +3005,14 @@ void synchronize_sched_expedited(void)
91906 synchronize_sched_expedited_cpu_stop,
91907 NULL) == -EAGAIN) {
91908 put_online_cpus();
91909- atomic_long_inc(&rsp->expedited_tryfail);
91910+ atomic_long_inc_unchecked(&rsp->expedited_tryfail);
91911
91912 /* Check to see if someone else did our work for us. */
91913 s = atomic_long_read(&rsp->expedited_done);
91914 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
91915 /* ensure test happens before caller kfree */
91916 smp_mb__before_atomic(); /* ^^^ */
91917- atomic_long_inc(&rsp->expedited_workdone1);
91918+ atomic_long_inc_unchecked(&rsp->expedited_workdone1);
91919 return;
91920 }
91921
91922@@ -3021,7 +3021,7 @@ void synchronize_sched_expedited(void)
91923 udelay(trycount * num_online_cpus());
91924 } else {
91925 wait_rcu_gp(call_rcu_sched);
91926- atomic_long_inc(&rsp->expedited_normal);
91927+ atomic_long_inc_unchecked(&rsp->expedited_normal);
91928 return;
91929 }
91930
91931@@ -3030,7 +3030,7 @@ void synchronize_sched_expedited(void)
91932 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
91933 /* ensure test happens before caller kfree */
91934 smp_mb__before_atomic(); /* ^^^ */
91935- atomic_long_inc(&rsp->expedited_workdone2);
91936+ atomic_long_inc_unchecked(&rsp->expedited_workdone2);
91937 return;
91938 }
91939
91940@@ -3044,13 +3044,13 @@ void synchronize_sched_expedited(void)
91941 if (!try_get_online_cpus()) {
91942 /* CPU hotplug operation in flight, use normal GP. */
91943 wait_rcu_gp(call_rcu_sched);
91944- atomic_long_inc(&rsp->expedited_normal);
91945+ atomic_long_inc_unchecked(&rsp->expedited_normal);
91946 return;
91947 }
91948- snap = atomic_long_read(&rsp->expedited_start);
91949+ snap = atomic_long_read_unchecked(&rsp->expedited_start);
91950 smp_mb(); /* ensure read is before try_stop_cpus(). */
91951 }
91952- atomic_long_inc(&rsp->expedited_stoppedcpus);
91953+ atomic_long_inc_unchecked(&rsp->expedited_stoppedcpus);
91954
91955 /*
91956 * Everyone up to our most recent fetch is covered by our grace
91957@@ -3059,16 +3059,16 @@ void synchronize_sched_expedited(void)
91958 * than we did already did their update.
91959 */
91960 do {
91961- atomic_long_inc(&rsp->expedited_done_tries);
91962+ atomic_long_inc_unchecked(&rsp->expedited_done_tries);
91963 s = atomic_long_read(&rsp->expedited_done);
91964 if (ULONG_CMP_GE((ulong)s, (ulong)snap)) {
91965 /* ensure test happens before caller kfree */
91966 smp_mb__before_atomic(); /* ^^^ */
91967- atomic_long_inc(&rsp->expedited_done_lost);
91968+ atomic_long_inc_unchecked(&rsp->expedited_done_lost);
91969 break;
91970 }
91971 } while (atomic_long_cmpxchg(&rsp->expedited_done, s, snap) != s);
91972- atomic_long_inc(&rsp->expedited_done_exit);
91973+ atomic_long_inc_unchecked(&rsp->expedited_done_exit);
91974
91975 put_online_cpus();
91976 }
91977@@ -3274,7 +3274,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
91978 * ACCESS_ONCE() to prevent the compiler from speculating
91979 * the increment to precede the early-exit check.
91980 */
91981- ACCESS_ONCE(rsp->n_barrier_done) = rsp->n_barrier_done + 1;
91982+ ACCESS_ONCE_RW(rsp->n_barrier_done) = rsp->n_barrier_done + 1;
91983 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 1);
91984 _rcu_barrier_trace(rsp, "Inc1", -1, rsp->n_barrier_done);
91985 smp_mb(); /* Order ->n_barrier_done increment with below mechanism. */
91986@@ -3329,7 +3329,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
91987
91988 /* Increment ->n_barrier_done to prevent duplicate work. */
91989 smp_mb(); /* Keep increment after above mechanism. */
91990- ACCESS_ONCE(rsp->n_barrier_done) = rsp->n_barrier_done + 1;
91991+ ACCESS_ONCE_RW(rsp->n_barrier_done) = rsp->n_barrier_done + 1;
91992 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 0);
91993 _rcu_barrier_trace(rsp, "Inc2", -1, rsp->n_barrier_done);
91994 smp_mb(); /* Keep increment before caller's subsequent code. */
91995@@ -3374,10 +3374,10 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
91996 rdp->grpmask = 1UL << (cpu - rdp->mynode->grplo);
91997 init_callback_list(rdp);
91998 rdp->qlen_lazy = 0;
91999- ACCESS_ONCE(rdp->qlen) = 0;
92000+ ACCESS_ONCE_RW(rdp->qlen) = 0;
92001 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
92002 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE);
92003- WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
92004+ WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
92005 rdp->cpu = cpu;
92006 rdp->rsp = rsp;
92007 rcu_boot_init_nocb_percpu_data(rdp);
92008@@ -3410,8 +3410,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp)
92009 init_callback_list(rdp); /* Re-enable callbacks on this CPU. */
92010 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
92011 rcu_sysidle_init_percpu_data(rdp->dynticks);
92012- atomic_set(&rdp->dynticks->dynticks,
92013- (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
92014+ atomic_set_unchecked(&rdp->dynticks->dynticks,
92015+ (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
92016 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
92017
92018 /* Add CPU to rcu_node bitmasks. */
92019diff --git a/kernel/rcu/tree.h b/kernel/rcu/tree.h
92020index bbdc45d..c882ccb 100644
92021--- a/kernel/rcu/tree.h
92022+++ b/kernel/rcu/tree.h
92023@@ -87,11 +87,11 @@ struct rcu_dynticks {
92024 long long dynticks_nesting; /* Track irq/process nesting level. */
92025 /* Process level is worth LLONG_MAX/2. */
92026 int dynticks_nmi_nesting; /* Track NMI nesting level. */
92027- atomic_t dynticks; /* Even value for idle, else odd. */
92028+ atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
92029 #ifdef CONFIG_NO_HZ_FULL_SYSIDLE
92030 long long dynticks_idle_nesting;
92031 /* irq/process nesting level from idle. */
92032- atomic_t dynticks_idle; /* Even value for idle, else odd. */
92033+ atomic_unchecked_t dynticks_idle;/* Even value for idle, else odd. */
92034 /* "Idle" excludes userspace execution. */
92035 unsigned long dynticks_idle_jiffies;
92036 /* End of last non-NMI non-idle period. */
92037@@ -466,17 +466,17 @@ struct rcu_state {
92038 /* _rcu_barrier(). */
92039 /* End of fields guarded by barrier_mutex. */
92040
92041- atomic_long_t expedited_start; /* Starting ticket. */
92042- atomic_long_t expedited_done; /* Done ticket. */
92043- atomic_long_t expedited_wrap; /* # near-wrap incidents. */
92044- atomic_long_t expedited_tryfail; /* # acquisition failures. */
92045- atomic_long_t expedited_workdone1; /* # done by others #1. */
92046- atomic_long_t expedited_workdone2; /* # done by others #2. */
92047- atomic_long_t expedited_normal; /* # fallbacks to normal. */
92048- atomic_long_t expedited_stoppedcpus; /* # successful stop_cpus. */
92049- atomic_long_t expedited_done_tries; /* # tries to update _done. */
92050- atomic_long_t expedited_done_lost; /* # times beaten to _done. */
92051- atomic_long_t expedited_done_exit; /* # times exited _done loop. */
92052+ atomic_long_unchecked_t expedited_start; /* Starting ticket. */
92053+ atomic_long_t expedited_done; /* Done ticket. */
92054+ atomic_long_unchecked_t expedited_wrap; /* # near-wrap incidents. */
92055+ atomic_long_unchecked_t expedited_tryfail; /* # acquisition failures. */
92056+ atomic_long_unchecked_t expedited_workdone1; /* # done by others #1. */
92057+ atomic_long_unchecked_t expedited_workdone2; /* # done by others #2. */
92058+ atomic_long_unchecked_t expedited_normal; /* # fallbacks to normal. */
92059+ atomic_long_unchecked_t expedited_stoppedcpus; /* # successful stop_cpus. */
92060+ atomic_long_unchecked_t expedited_done_tries; /* # tries to update _done. */
92061+ atomic_long_unchecked_t expedited_done_lost; /* # times beaten to _done. */
92062+ atomic_long_unchecked_t expedited_done_exit; /* # times exited _done loop. */
92063
92064 unsigned long jiffies_force_qs; /* Time at which to invoke */
92065 /* force_quiescent_state(). */
92066diff --git a/kernel/rcu/tree_plugin.h b/kernel/rcu/tree_plugin.h
92067index c1d7f27..a64bf49 100644
92068--- a/kernel/rcu/tree_plugin.h
92069+++ b/kernel/rcu/tree_plugin.h
92070@@ -709,7 +709,7 @@ static int rcu_preempted_readers_exp(struct rcu_node *rnp)
92071 static int sync_rcu_preempt_exp_done(struct rcu_node *rnp)
92072 {
92073 return !rcu_preempted_readers_exp(rnp) &&
92074- ACCESS_ONCE(rnp->expmask) == 0;
92075+ ACCESS_ONCE_RW(rnp->expmask) == 0;
92076 }
92077
92078 /*
92079@@ -870,7 +870,7 @@ void synchronize_rcu_expedited(void)
92080
92081 /* Clean up and exit. */
92082 smp_mb(); /* ensure expedited GP seen before counter increment. */
92083- ACCESS_ONCE(sync_rcu_preempt_exp_count) =
92084+ ACCESS_ONCE_RW(sync_rcu_preempt_exp_count) =
92085 sync_rcu_preempt_exp_count + 1;
92086 unlock_mb_ret:
92087 mutex_unlock(&sync_rcu_preempt_exp_mutex);
92088@@ -1426,7 +1426,7 @@ static void rcu_boost_kthread_setaffinity(struct rcu_node *rnp, int outgoingcpu)
92089 free_cpumask_var(cm);
92090 }
92091
92092-static struct smp_hotplug_thread rcu_cpu_thread_spec = {
92093+static struct smp_hotplug_thread rcu_cpu_thread_spec __read_only = {
92094 .store = &rcu_cpu_kthread_task,
92095 .thread_should_run = rcu_cpu_kthread_should_run,
92096 .thread_fn = rcu_cpu_kthread,
92097@@ -1900,7 +1900,7 @@ static void print_cpu_stall_info(struct rcu_state *rsp, int cpu)
92098 print_cpu_stall_fast_no_hz(fast_no_hz, cpu);
92099 pr_err("\t%d: (%lu %s) idle=%03x/%llx/%d softirq=%u/%u %s\n",
92100 cpu, ticks_value, ticks_title,
92101- atomic_read(&rdtp->dynticks) & 0xfff,
92102+ atomic_read_unchecked(&rdtp->dynticks) & 0xfff,
92103 rdtp->dynticks_nesting, rdtp->dynticks_nmi_nesting,
92104 rdp->softirq_snap, kstat_softirqs_cpu(RCU_SOFTIRQ, cpu),
92105 fast_no_hz);
92106@@ -2044,7 +2044,7 @@ static void wake_nocb_leader(struct rcu_data *rdp, bool force)
92107 return;
92108 if (ACCESS_ONCE(rdp_leader->nocb_leader_sleep) || force) {
92109 /* Prior smp_mb__after_atomic() orders against prior enqueue. */
92110- ACCESS_ONCE(rdp_leader->nocb_leader_sleep) = false;
92111+ ACCESS_ONCE_RW(rdp_leader->nocb_leader_sleep) = false;
92112 wake_up(&rdp_leader->nocb_wq);
92113 }
92114 }
92115@@ -2096,7 +2096,7 @@ static void __call_rcu_nocb_enqueue(struct rcu_data *rdp,
92116
92117 /* Enqueue the callback on the nocb list and update counts. */
92118 old_rhpp = xchg(&rdp->nocb_tail, rhtp);
92119- ACCESS_ONCE(*old_rhpp) = rhp;
92120+ ACCESS_ONCE_RW(*old_rhpp) = rhp;
92121 atomic_long_add(rhcount, &rdp->nocb_q_count);
92122 atomic_long_add(rhcount_lazy, &rdp->nocb_q_count_lazy);
92123 smp_mb__after_atomic(); /* Store *old_rhpp before _wake test. */
92124@@ -2286,7 +2286,7 @@ wait_again:
92125 continue; /* No CBs here, try next follower. */
92126
92127 /* Move callbacks to wait-for-GP list, which is empty. */
92128- ACCESS_ONCE(rdp->nocb_head) = NULL;
92129+ ACCESS_ONCE_RW(rdp->nocb_head) = NULL;
92130 rdp->nocb_gp_tail = xchg(&rdp->nocb_tail, &rdp->nocb_head);
92131 rdp->nocb_gp_count = atomic_long_xchg(&rdp->nocb_q_count, 0);
92132 rdp->nocb_gp_count_lazy =
92133@@ -2413,7 +2413,7 @@ static int rcu_nocb_kthread(void *arg)
92134 list = ACCESS_ONCE(rdp->nocb_follower_head);
92135 BUG_ON(!list);
92136 trace_rcu_nocb_wake(rdp->rsp->name, rdp->cpu, "WokeNonEmpty");
92137- ACCESS_ONCE(rdp->nocb_follower_head) = NULL;
92138+ ACCESS_ONCE_RW(rdp->nocb_follower_head) = NULL;
92139 tail = xchg(&rdp->nocb_follower_tail, &rdp->nocb_follower_head);
92140 c = atomic_long_xchg(&rdp->nocb_follower_count, 0);
92141 cl = atomic_long_xchg(&rdp->nocb_follower_count_lazy, 0);
92142@@ -2443,8 +2443,8 @@ static int rcu_nocb_kthread(void *arg)
92143 list = next;
92144 }
92145 trace_rcu_batch_end(rdp->rsp->name, c, !!list, 0, 0, 1);
92146- ACCESS_ONCE(rdp->nocb_p_count) = rdp->nocb_p_count - c;
92147- ACCESS_ONCE(rdp->nocb_p_count_lazy) =
92148+ ACCESS_ONCE_RW(rdp->nocb_p_count) = rdp->nocb_p_count - c;
92149+ ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) =
92150 rdp->nocb_p_count_lazy - cl;
92151 rdp->n_nocbs_invoked += c;
92152 }
92153@@ -2465,7 +2465,7 @@ static void do_nocb_deferred_wakeup(struct rcu_data *rdp)
92154 if (!rcu_nocb_need_deferred_wakeup(rdp))
92155 return;
92156 ndw = ACCESS_ONCE(rdp->nocb_defer_wakeup);
92157- ACCESS_ONCE(rdp->nocb_defer_wakeup) = RCU_NOGP_WAKE_NOT;
92158+ ACCESS_ONCE_RW(rdp->nocb_defer_wakeup) = RCU_NOGP_WAKE_NOT;
92159 wake_nocb_leader(rdp, ndw == RCU_NOGP_WAKE_FORCE);
92160 trace_rcu_nocb_wake(rdp->rsp->name, rdp->cpu, TPS("DeferredWake"));
92161 }
92162@@ -2584,7 +2584,7 @@ static void rcu_spawn_one_nocb_kthread(struct rcu_state *rsp, int cpu)
92163 t = kthread_run(rcu_nocb_kthread, rdp_spawn,
92164 "rcuo%c/%d", rsp->abbr, cpu);
92165 BUG_ON(IS_ERR(t));
92166- ACCESS_ONCE(rdp_spawn->nocb_kthread) = t;
92167+ ACCESS_ONCE_RW(rdp_spawn->nocb_kthread) = t;
92168 }
92169
92170 /*
92171@@ -2788,11 +2788,11 @@ static void rcu_sysidle_enter(struct rcu_dynticks *rdtp, int irq)
92172
92173 /* Record start of fully idle period. */
92174 j = jiffies;
92175- ACCESS_ONCE(rdtp->dynticks_idle_jiffies) = j;
92176+ ACCESS_ONCE_RW(rdtp->dynticks_idle_jiffies) = j;
92177 smp_mb__before_atomic();
92178- atomic_inc(&rdtp->dynticks_idle);
92179+ atomic_inc_unchecked(&rdtp->dynticks_idle);
92180 smp_mb__after_atomic();
92181- WARN_ON_ONCE(atomic_read(&rdtp->dynticks_idle) & 0x1);
92182+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks_idle) & 0x1);
92183 }
92184
92185 /*
92186@@ -2861,9 +2861,9 @@ static void rcu_sysidle_exit(struct rcu_dynticks *rdtp, int irq)
92187
92188 /* Record end of idle period. */
92189 smp_mb__before_atomic();
92190- atomic_inc(&rdtp->dynticks_idle);
92191+ atomic_inc_unchecked(&rdtp->dynticks_idle);
92192 smp_mb__after_atomic();
92193- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks_idle) & 0x1));
92194+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks_idle) & 0x1));
92195
92196 /*
92197 * If we are the timekeeping CPU, we are permitted to be non-idle
92198@@ -2908,7 +2908,7 @@ static void rcu_sysidle_check_cpu(struct rcu_data *rdp, bool *isidle,
92199 WARN_ON_ONCE(smp_processor_id() != tick_do_timer_cpu);
92200
92201 /* Pick up current idle and NMI-nesting counter and check. */
92202- cur = atomic_read(&rdtp->dynticks_idle);
92203+ cur = atomic_read_unchecked(&rdtp->dynticks_idle);
92204 if (cur & 0x1) {
92205 *isidle = false; /* We are not idle! */
92206 return;
92207@@ -2957,7 +2957,7 @@ static void rcu_sysidle(unsigned long j)
92208 case RCU_SYSIDLE_NOT:
92209
92210 /* First time all are idle, so note a short idle period. */
92211- ACCESS_ONCE(full_sysidle_state) = RCU_SYSIDLE_SHORT;
92212+ ACCESS_ONCE_RW(full_sysidle_state) = RCU_SYSIDLE_SHORT;
92213 break;
92214
92215 case RCU_SYSIDLE_SHORT:
92216@@ -2995,7 +2995,7 @@ static void rcu_sysidle_cancel(void)
92217 {
92218 smp_mb();
92219 if (full_sysidle_state > RCU_SYSIDLE_SHORT)
92220- ACCESS_ONCE(full_sysidle_state) = RCU_SYSIDLE_NOT;
92221+ ACCESS_ONCE_RW(full_sysidle_state) = RCU_SYSIDLE_NOT;
92222 }
92223
92224 /*
92225@@ -3047,7 +3047,7 @@ static void rcu_sysidle_cb(struct rcu_head *rhp)
92226 smp_mb(); /* grace period precedes setting inuse. */
92227
92228 rshp = container_of(rhp, struct rcu_sysidle_head, rh);
92229- ACCESS_ONCE(rshp->inuse) = 0;
92230+ ACCESS_ONCE_RW(rshp->inuse) = 0;
92231 }
92232
92233 /*
92234@@ -3200,7 +3200,7 @@ static void rcu_bind_gp_kthread(void)
92235 static void rcu_dynticks_task_enter(void)
92236 {
92237 #if defined(CONFIG_TASKS_RCU) && defined(CONFIG_NO_HZ_FULL)
92238- ACCESS_ONCE(current->rcu_tasks_idle_cpu) = smp_processor_id();
92239+ ACCESS_ONCE_RW(current->rcu_tasks_idle_cpu) = smp_processor_id();
92240 #endif /* #if defined(CONFIG_TASKS_RCU) && defined(CONFIG_NO_HZ_FULL) */
92241 }
92242
92243@@ -3208,6 +3208,6 @@ static void rcu_dynticks_task_enter(void)
92244 static void rcu_dynticks_task_exit(void)
92245 {
92246 #if defined(CONFIG_TASKS_RCU) && defined(CONFIG_NO_HZ_FULL)
92247- ACCESS_ONCE(current->rcu_tasks_idle_cpu) = -1;
92248+ ACCESS_ONCE_RW(current->rcu_tasks_idle_cpu) = -1;
92249 #endif /* #if defined(CONFIG_TASKS_RCU) && defined(CONFIG_NO_HZ_FULL) */
92250 }
92251diff --git a/kernel/rcu/tree_trace.c b/kernel/rcu/tree_trace.c
92252index 5cdc62e..cc52e88 100644
92253--- a/kernel/rcu/tree_trace.c
92254+++ b/kernel/rcu/tree_trace.c
92255@@ -121,7 +121,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
92256 ulong2long(rdp->completed), ulong2long(rdp->gpnum),
92257 rdp->passed_quiesce, rdp->qs_pending);
92258 seq_printf(m, " dt=%d/%llx/%d df=%lu",
92259- atomic_read(&rdp->dynticks->dynticks),
92260+ atomic_read_unchecked(&rdp->dynticks->dynticks),
92261 rdp->dynticks->dynticks_nesting,
92262 rdp->dynticks->dynticks_nmi_nesting,
92263 rdp->dynticks_fqs);
92264@@ -182,17 +182,17 @@ static int show_rcuexp(struct seq_file *m, void *v)
92265 struct rcu_state *rsp = (struct rcu_state *)m->private;
92266
92267 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",
92268- atomic_long_read(&rsp->expedited_start),
92269+ atomic_long_read_unchecked(&rsp->expedited_start),
92270 atomic_long_read(&rsp->expedited_done),
92271- atomic_long_read(&rsp->expedited_wrap),
92272- atomic_long_read(&rsp->expedited_tryfail),
92273- atomic_long_read(&rsp->expedited_workdone1),
92274- atomic_long_read(&rsp->expedited_workdone2),
92275- atomic_long_read(&rsp->expedited_normal),
92276- atomic_long_read(&rsp->expedited_stoppedcpus),
92277- atomic_long_read(&rsp->expedited_done_tries),
92278- atomic_long_read(&rsp->expedited_done_lost),
92279- atomic_long_read(&rsp->expedited_done_exit));
92280+ atomic_long_read_unchecked(&rsp->expedited_wrap),
92281+ atomic_long_read_unchecked(&rsp->expedited_tryfail),
92282+ atomic_long_read_unchecked(&rsp->expedited_workdone1),
92283+ atomic_long_read_unchecked(&rsp->expedited_workdone2),
92284+ atomic_long_read_unchecked(&rsp->expedited_normal),
92285+ atomic_long_read_unchecked(&rsp->expedited_stoppedcpus),
92286+ atomic_long_read_unchecked(&rsp->expedited_done_tries),
92287+ atomic_long_read_unchecked(&rsp->expedited_done_lost),
92288+ atomic_long_read_unchecked(&rsp->expedited_done_exit));
92289 return 0;
92290 }
92291
92292diff --git a/kernel/rcu/update.c b/kernel/rcu/update.c
92293index 3ef8ba5..8c5ebfb6 100644
92294--- a/kernel/rcu/update.c
92295+++ b/kernel/rcu/update.c
92296@@ -342,10 +342,10 @@ int rcu_jiffies_till_stall_check(void)
92297 * for CONFIG_RCU_CPU_STALL_TIMEOUT.
92298 */
92299 if (till_stall_check < 3) {
92300- ACCESS_ONCE(rcu_cpu_stall_timeout) = 3;
92301+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 3;
92302 till_stall_check = 3;
92303 } else if (till_stall_check > 300) {
92304- ACCESS_ONCE(rcu_cpu_stall_timeout) = 300;
92305+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 300;
92306 till_stall_check = 300;
92307 }
92308 return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;
92309@@ -501,7 +501,7 @@ static void check_holdout_task(struct task_struct *t,
92310 !ACCESS_ONCE(t->on_rq) ||
92311 (IS_ENABLED(CONFIG_NO_HZ_FULL) &&
92312 !is_idle_task(t) && t->rcu_tasks_idle_cpu >= 0)) {
92313- ACCESS_ONCE(t->rcu_tasks_holdout) = false;
92314+ ACCESS_ONCE_RW(t->rcu_tasks_holdout) = false;
92315 list_del_init(&t->rcu_tasks_holdout_list);
92316 put_task_struct(t);
92317 return;
92318@@ -588,7 +588,7 @@ static int __noreturn rcu_tasks_kthread(void *arg)
92319 !is_idle_task(t)) {
92320 get_task_struct(t);
92321 t->rcu_tasks_nvcsw = ACCESS_ONCE(t->nvcsw);
92322- ACCESS_ONCE(t->rcu_tasks_holdout) = true;
92323+ ACCESS_ONCE_RW(t->rcu_tasks_holdout) = true;
92324 list_add(&t->rcu_tasks_holdout_list,
92325 &rcu_tasks_holdouts);
92326 }
92327@@ -685,7 +685,7 @@ static void rcu_spawn_tasks_kthread(void)
92328 t = kthread_run(rcu_tasks_kthread, NULL, "rcu_tasks_kthread");
92329 BUG_ON(IS_ERR(t));
92330 smp_mb(); /* Ensure others see full kthread. */
92331- ACCESS_ONCE(rcu_tasks_kthread_ptr) = t;
92332+ ACCESS_ONCE_RW(rcu_tasks_kthread_ptr) = t;
92333 mutex_unlock(&rcu_tasks_kthread_mutex);
92334 }
92335
92336diff --git a/kernel/resource.c b/kernel/resource.c
92337index 0bcebff..e7cd5b2 100644
92338--- a/kernel/resource.c
92339+++ b/kernel/resource.c
92340@@ -161,8 +161,18 @@ static const struct file_operations proc_iomem_operations = {
92341
92342 static int __init ioresources_init(void)
92343 {
92344+#ifdef CONFIG_GRKERNSEC_PROC_ADD
92345+#ifdef CONFIG_GRKERNSEC_PROC_USER
92346+ proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
92347+ proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
92348+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
92349+ proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
92350+ proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
92351+#endif
92352+#else
92353 proc_create("ioports", 0, NULL, &proc_ioports_operations);
92354 proc_create("iomem", 0, NULL, &proc_iomem_operations);
92355+#endif
92356 return 0;
92357 }
92358 __initcall(ioresources_init);
92359diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
92360index 8a2e230..6020954 100644
92361--- a/kernel/sched/auto_group.c
92362+++ b/kernel/sched/auto_group.c
92363@@ -11,7 +11,7 @@
92364
92365 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
92366 static struct autogroup autogroup_default;
92367-static atomic_t autogroup_seq_nr;
92368+static atomic_unchecked_t autogroup_seq_nr;
92369
92370 void __init autogroup_init(struct task_struct *init_task)
92371 {
92372@@ -79,7 +79,7 @@ static inline struct autogroup *autogroup_create(void)
92373
92374 kref_init(&ag->kref);
92375 init_rwsem(&ag->lock);
92376- ag->id = atomic_inc_return(&autogroup_seq_nr);
92377+ ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
92378 ag->tg = tg;
92379 #ifdef CONFIG_RT_GROUP_SCHED
92380 /*
92381diff --git a/kernel/sched/completion.c b/kernel/sched/completion.c
92382index a63f4dc..349bbb0 100644
92383--- a/kernel/sched/completion.c
92384+++ b/kernel/sched/completion.c
92385@@ -204,7 +204,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible);
92386 * Return: -ERESTARTSYS if interrupted, 0 if timed out, positive (at least 1,
92387 * or number of jiffies left till timeout) if completed.
92388 */
92389-long __sched
92390+long __sched __intentional_overflow(-1)
92391 wait_for_completion_interruptible_timeout(struct completion *x,
92392 unsigned long timeout)
92393 {
92394@@ -221,7 +221,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible_timeout);
92395 *
92396 * Return: -ERESTARTSYS if interrupted, 0 if completed.
92397 */
92398-int __sched wait_for_completion_killable(struct completion *x)
92399+int __sched __intentional_overflow(-1) wait_for_completion_killable(struct completion *x)
92400 {
92401 long t = wait_for_common(x, MAX_SCHEDULE_TIMEOUT, TASK_KILLABLE);
92402 if (t == -ERESTARTSYS)
92403@@ -242,7 +242,7 @@ EXPORT_SYMBOL(wait_for_completion_killable);
92404 * Return: -ERESTARTSYS if interrupted, 0 if timed out, positive (at least 1,
92405 * or number of jiffies left till timeout) if completed.
92406 */
92407-long __sched
92408+long __sched __intentional_overflow(-1)
92409 wait_for_completion_killable_timeout(struct completion *x,
92410 unsigned long timeout)
92411 {
92412diff --git a/kernel/sched/core.c b/kernel/sched/core.c
92413index 89e7283..072bc26 100644
92414--- a/kernel/sched/core.c
92415+++ b/kernel/sched/core.c
92416@@ -1885,7 +1885,7 @@ void set_numabalancing_state(bool enabled)
92417 int sysctl_numa_balancing(struct ctl_table *table, int write,
92418 void __user *buffer, size_t *lenp, loff_t *ppos)
92419 {
92420- struct ctl_table t;
92421+ ctl_table_no_const t;
92422 int err;
92423 int state = numabalancing_enabled;
92424
92425@@ -2348,8 +2348,10 @@ context_switch(struct rq *rq, struct task_struct *prev,
92426 next->active_mm = oldmm;
92427 atomic_inc(&oldmm->mm_count);
92428 enter_lazy_tlb(oldmm, next);
92429- } else
92430+ } else {
92431 switch_mm(oldmm, mm, next);
92432+ populate_stack();
92433+ }
92434
92435 if (!prev->mm) {
92436 prev->active_mm = NULL;
92437@@ -3160,6 +3162,8 @@ int can_nice(const struct task_struct *p, const int nice)
92438 /* convert nice value [19,-20] to rlimit style value [1,40] */
92439 int nice_rlim = nice_to_rlimit(nice);
92440
92441+ gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
92442+
92443 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
92444 capable(CAP_SYS_NICE));
92445 }
92446@@ -3186,7 +3190,8 @@ SYSCALL_DEFINE1(nice, int, increment)
92447 nice = task_nice(current) + increment;
92448
92449 nice = clamp_val(nice, MIN_NICE, MAX_NICE);
92450- if (increment < 0 && !can_nice(current, nice))
92451+ if (increment < 0 && (!can_nice(current, nice) ||
92452+ gr_handle_chroot_nice()))
92453 return -EPERM;
92454
92455 retval = security_task_setnice(current, nice);
92456@@ -3465,6 +3470,7 @@ recheck:
92457 if (policy != p->policy && !rlim_rtprio)
92458 return -EPERM;
92459
92460+ gr_learn_resource(p, RLIMIT_RTPRIO, attr->sched_priority, 1);
92461 /* can't increase priority */
92462 if (attr->sched_priority > p->rt_priority &&
92463 attr->sched_priority > rlim_rtprio)
92464@@ -4885,6 +4891,7 @@ void idle_task_exit(void)
92465
92466 if (mm != &init_mm) {
92467 switch_mm(mm, &init_mm, current);
92468+ populate_stack();
92469 finish_arch_post_lock_switch();
92470 }
92471 mmdrop(mm);
92472@@ -4980,7 +4987,7 @@ static void migrate_tasks(unsigned int dead_cpu)
92473
92474 #if defined(CONFIG_SCHED_DEBUG) && defined(CONFIG_SYSCTL)
92475
92476-static struct ctl_table sd_ctl_dir[] = {
92477+static ctl_table_no_const sd_ctl_dir[] __read_only = {
92478 {
92479 .procname = "sched_domain",
92480 .mode = 0555,
92481@@ -4997,17 +5004,17 @@ static struct ctl_table sd_ctl_root[] = {
92482 {}
92483 };
92484
92485-static struct ctl_table *sd_alloc_ctl_entry(int n)
92486+static ctl_table_no_const *sd_alloc_ctl_entry(int n)
92487 {
92488- struct ctl_table *entry =
92489+ ctl_table_no_const *entry =
92490 kcalloc(n, sizeof(struct ctl_table), GFP_KERNEL);
92491
92492 return entry;
92493 }
92494
92495-static void sd_free_ctl_entry(struct ctl_table **tablep)
92496+static void sd_free_ctl_entry(ctl_table_no_const *tablep)
92497 {
92498- struct ctl_table *entry;
92499+ ctl_table_no_const *entry;
92500
92501 /*
92502 * In the intermediate directories, both the child directory and
92503@@ -5015,22 +5022,25 @@ static void sd_free_ctl_entry(struct ctl_table **tablep)
92504 * will always be set. In the lowest directory the names are
92505 * static strings and all have proc handlers.
92506 */
92507- for (entry = *tablep; entry->mode; entry++) {
92508- if (entry->child)
92509- sd_free_ctl_entry(&entry->child);
92510+ for (entry = tablep; entry->mode; entry++) {
92511+ if (entry->child) {
92512+ sd_free_ctl_entry(entry->child);
92513+ pax_open_kernel();
92514+ entry->child = NULL;
92515+ pax_close_kernel();
92516+ }
92517 if (entry->proc_handler == NULL)
92518 kfree(entry->procname);
92519 }
92520
92521- kfree(*tablep);
92522- *tablep = NULL;
92523+ kfree(tablep);
92524 }
92525
92526 static int min_load_idx = 0;
92527 static int max_load_idx = CPU_LOAD_IDX_MAX-1;
92528
92529 static void
92530-set_table_entry(struct ctl_table *entry,
92531+set_table_entry(ctl_table_no_const *entry,
92532 const char *procname, void *data, int maxlen,
92533 umode_t mode, proc_handler *proc_handler,
92534 bool load_idx)
92535@@ -5050,7 +5060,7 @@ set_table_entry(struct ctl_table *entry,
92536 static struct ctl_table *
92537 sd_alloc_ctl_domain_table(struct sched_domain *sd)
92538 {
92539- struct ctl_table *table = sd_alloc_ctl_entry(14);
92540+ ctl_table_no_const *table = sd_alloc_ctl_entry(14);
92541
92542 if (table == NULL)
92543 return NULL;
92544@@ -5088,9 +5098,9 @@ sd_alloc_ctl_domain_table(struct sched_domain *sd)
92545 return table;
92546 }
92547
92548-static struct ctl_table *sd_alloc_ctl_cpu_table(int cpu)
92549+static ctl_table_no_const *sd_alloc_ctl_cpu_table(int cpu)
92550 {
92551- struct ctl_table *entry, *table;
92552+ ctl_table_no_const *entry, *table;
92553 struct sched_domain *sd;
92554 int domain_num = 0, i;
92555 char buf[32];
92556@@ -5117,11 +5127,13 @@ static struct ctl_table_header *sd_sysctl_header;
92557 static void register_sched_domain_sysctl(void)
92558 {
92559 int i, cpu_num = num_possible_cpus();
92560- struct ctl_table *entry = sd_alloc_ctl_entry(cpu_num + 1);
92561+ ctl_table_no_const *entry = sd_alloc_ctl_entry(cpu_num + 1);
92562 char buf[32];
92563
92564 WARN_ON(sd_ctl_dir[0].child);
92565+ pax_open_kernel();
92566 sd_ctl_dir[0].child = entry;
92567+ pax_close_kernel();
92568
92569 if (entry == NULL)
92570 return;
92571@@ -5144,8 +5156,12 @@ static void unregister_sched_domain_sysctl(void)
92572 if (sd_sysctl_header)
92573 unregister_sysctl_table(sd_sysctl_header);
92574 sd_sysctl_header = NULL;
92575- if (sd_ctl_dir[0].child)
92576- sd_free_ctl_entry(&sd_ctl_dir[0].child);
92577+ if (sd_ctl_dir[0].child) {
92578+ sd_free_ctl_entry(sd_ctl_dir[0].child);
92579+ pax_open_kernel();
92580+ sd_ctl_dir[0].child = NULL;
92581+ pax_close_kernel();
92582+ }
92583 }
92584 #else
92585 static void register_sched_domain_sysctl(void)
92586diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
92587index ef2b104..69961f6 100644
92588--- a/kernel/sched/fair.c
92589+++ b/kernel/sched/fair.c
92590@@ -1906,7 +1906,7 @@ void task_numa_fault(int last_cpupid, int mem_node, int pages, int flags)
92591
92592 static void reset_ptenuma_scan(struct task_struct *p)
92593 {
92594- ACCESS_ONCE(p->mm->numa_scan_seq)++;
92595+ ACCESS_ONCE_RW(p->mm->numa_scan_seq)++;
92596 p->mm->numa_scan_offset = 0;
92597 }
92598
92599@@ -7465,7 +7465,7 @@ static void nohz_idle_balance(struct rq *this_rq, enum cpu_idle_type idle) { }
92600 * run_rebalance_domains is triggered when needed from the scheduler tick.
92601 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
92602 */
92603-static void run_rebalance_domains(struct softirq_action *h)
92604+static __latent_entropy void run_rebalance_domains(void)
92605 {
92606 struct rq *this_rq = this_rq();
92607 enum cpu_idle_type idle = this_rq->idle_balance ?
92608diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
92609index 2df8ef0..aae070f 100644
92610--- a/kernel/sched/sched.h
92611+++ b/kernel/sched/sched.h
92612@@ -1140,7 +1140,7 @@ struct sched_class {
92613 #ifdef CONFIG_FAIR_GROUP_SCHED
92614 void (*task_move_group) (struct task_struct *p, int on_rq);
92615 #endif
92616-};
92617+} __do_const;
92618
92619 static inline void put_prev_task(struct rq *rq, struct task_struct *prev)
92620 {
92621diff --git a/kernel/signal.c b/kernel/signal.c
92622index 8f0876f..1153a5a 100644
92623--- a/kernel/signal.c
92624+++ b/kernel/signal.c
92625@@ -53,12 +53,12 @@ static struct kmem_cache *sigqueue_cachep;
92626
92627 int print_fatal_signals __read_mostly;
92628
92629-static void __user *sig_handler(struct task_struct *t, int sig)
92630+static __sighandler_t sig_handler(struct task_struct *t, int sig)
92631 {
92632 return t->sighand->action[sig - 1].sa.sa_handler;
92633 }
92634
92635-static int sig_handler_ignored(void __user *handler, int sig)
92636+static int sig_handler_ignored(__sighandler_t handler, int sig)
92637 {
92638 /* Is it explicitly or implicitly ignored? */
92639 return handler == SIG_IGN ||
92640@@ -67,7 +67,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
92641
92642 static int sig_task_ignored(struct task_struct *t, int sig, bool force)
92643 {
92644- void __user *handler;
92645+ __sighandler_t handler;
92646
92647 handler = sig_handler(t, sig);
92648
92649@@ -372,6 +372,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
92650 atomic_inc(&user->sigpending);
92651 rcu_read_unlock();
92652
92653+ if (!override_rlimit)
92654+ gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
92655+
92656 if (override_rlimit ||
92657 atomic_read(&user->sigpending) <=
92658 task_rlimit(t, RLIMIT_SIGPENDING)) {
92659@@ -499,7 +502,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
92660
92661 int unhandled_signal(struct task_struct *tsk, int sig)
92662 {
92663- void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
92664+ __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
92665 if (is_global_init(tsk))
92666 return 1;
92667 if (handler != SIG_IGN && handler != SIG_DFL)
92668@@ -793,6 +796,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
92669 }
92670 }
92671
92672+ /* allow glibc communication via tgkill to other threads in our
92673+ thread group */
92674+ if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
92675+ sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
92676+ && gr_handle_signal(t, sig))
92677+ return -EPERM;
92678+
92679 return security_task_kill(t, info, sig, 0);
92680 }
92681
92682@@ -1176,7 +1186,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
92683 return send_signal(sig, info, p, 1);
92684 }
92685
92686-static int
92687+int
92688 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
92689 {
92690 return send_signal(sig, info, t, 0);
92691@@ -1213,6 +1223,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
92692 unsigned long int flags;
92693 int ret, blocked, ignored;
92694 struct k_sigaction *action;
92695+ int is_unhandled = 0;
92696
92697 spin_lock_irqsave(&t->sighand->siglock, flags);
92698 action = &t->sighand->action[sig-1];
92699@@ -1227,9 +1238,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
92700 }
92701 if (action->sa.sa_handler == SIG_DFL)
92702 t->signal->flags &= ~SIGNAL_UNKILLABLE;
92703+ if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
92704+ is_unhandled = 1;
92705 ret = specific_send_sig_info(sig, info, t);
92706 spin_unlock_irqrestore(&t->sighand->siglock, flags);
92707
92708+ /* only deal with unhandled signals, java etc trigger SIGSEGV during
92709+ normal operation */
92710+ if (is_unhandled) {
92711+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
92712+ gr_handle_crash(t, sig);
92713+ }
92714+
92715 return ret;
92716 }
92717
92718@@ -1300,8 +1320,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
92719 ret = check_kill_permission(sig, info, p);
92720 rcu_read_unlock();
92721
92722- if (!ret && sig)
92723+ if (!ret && sig) {
92724 ret = do_send_sig_info(sig, info, p, true);
92725+ if (!ret)
92726+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
92727+ }
92728
92729 return ret;
92730 }
92731@@ -2903,7 +2926,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
92732 int error = -ESRCH;
92733
92734 rcu_read_lock();
92735- p = find_task_by_vpid(pid);
92736+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
92737+ /* allow glibc communication via tgkill to other threads in our
92738+ thread group */
92739+ if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
92740+ sig == (SIGRTMIN+1) && tgid == info->si_pid)
92741+ p = find_task_by_vpid_unrestricted(pid);
92742+ else
92743+#endif
92744+ p = find_task_by_vpid(pid);
92745 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
92746 error = check_kill_permission(sig, info, p);
92747 /*
92748@@ -3236,8 +3267,8 @@ COMPAT_SYSCALL_DEFINE2(sigaltstack,
92749 }
92750 seg = get_fs();
92751 set_fs(KERNEL_DS);
92752- ret = do_sigaltstack((stack_t __force __user *) (uss_ptr ? &uss : NULL),
92753- (stack_t __force __user *) &uoss,
92754+ ret = do_sigaltstack((stack_t __force_user *) (uss_ptr ? &uss : NULL),
92755+ (stack_t __force_user *) &uoss,
92756 compat_user_stack_pointer());
92757 set_fs(seg);
92758 if (ret >= 0 && uoss_ptr) {
92759diff --git a/kernel/smpboot.c b/kernel/smpboot.c
92760index eb89e18..a4e6792 100644
92761--- a/kernel/smpboot.c
92762+++ b/kernel/smpboot.c
92763@@ -288,7 +288,7 @@ int smpboot_register_percpu_thread(struct smp_hotplug_thread *plug_thread)
92764 }
92765 smpboot_unpark_thread(plug_thread, cpu);
92766 }
92767- list_add(&plug_thread->list, &hotplug_threads);
92768+ pax_list_add(&plug_thread->list, &hotplug_threads);
92769 out:
92770 mutex_unlock(&smpboot_threads_lock);
92771 return ret;
92772@@ -305,7 +305,7 @@ void smpboot_unregister_percpu_thread(struct smp_hotplug_thread *plug_thread)
92773 {
92774 get_online_cpus();
92775 mutex_lock(&smpboot_threads_lock);
92776- list_del(&plug_thread->list);
92777+ pax_list_del(&plug_thread->list);
92778 smpboot_destroy_threads(plug_thread);
92779 mutex_unlock(&smpboot_threads_lock);
92780 put_online_cpus();
92781diff --git a/kernel/softirq.c b/kernel/softirq.c
92782index 0699add..d365ad8 100644
92783--- a/kernel/softirq.c
92784+++ b/kernel/softirq.c
92785@@ -53,7 +53,7 @@ irq_cpustat_t irq_stat[NR_CPUS] ____cacheline_aligned;
92786 EXPORT_SYMBOL(irq_stat);
92787 #endif
92788
92789-static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp;
92790+static struct softirq_action softirq_vec[NR_SOFTIRQS] __read_only __aligned(PAGE_SIZE);
92791
92792 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
92793
92794@@ -266,7 +266,7 @@ restart:
92795 kstat_incr_softirqs_this_cpu(vec_nr);
92796
92797 trace_softirq_entry(vec_nr);
92798- h->action(h);
92799+ h->action();
92800 trace_softirq_exit(vec_nr);
92801 if (unlikely(prev_count != preempt_count())) {
92802 pr_err("huh, entered softirq %u %s %p with preempt_count %08x, exited with %08x?\n",
92803@@ -426,7 +426,7 @@ void __raise_softirq_irqoff(unsigned int nr)
92804 or_softirq_pending(1UL << nr);
92805 }
92806
92807-void open_softirq(int nr, void (*action)(struct softirq_action *))
92808+void __init open_softirq(int nr, void (*action)(void))
92809 {
92810 softirq_vec[nr].action = action;
92811 }
92812@@ -478,7 +478,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
92813 }
92814 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
92815
92816-static void tasklet_action(struct softirq_action *a)
92817+static void tasklet_action(void)
92818 {
92819 struct tasklet_struct *list;
92820
92821@@ -514,7 +514,7 @@ static void tasklet_action(struct softirq_action *a)
92822 }
92823 }
92824
92825-static void tasklet_hi_action(struct softirq_action *a)
92826+static __latent_entropy void tasklet_hi_action(void)
92827 {
92828 struct tasklet_struct *list;
92829
92830@@ -741,7 +741,7 @@ static struct notifier_block cpu_nfb = {
92831 .notifier_call = cpu_callback
92832 };
92833
92834-static struct smp_hotplug_thread softirq_threads = {
92835+static struct smp_hotplug_thread softirq_threads __read_only = {
92836 .store = &ksoftirqd,
92837 .thread_should_run = ksoftirqd_should_run,
92838 .thread_fn = run_ksoftirqd,
92839diff --git a/kernel/sys.c b/kernel/sys.c
92840index 1eaa2f0..d80d27c 100644
92841--- a/kernel/sys.c
92842+++ b/kernel/sys.c
92843@@ -148,6 +148,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
92844 error = -EACCES;
92845 goto out;
92846 }
92847+
92848+ if (gr_handle_chroot_setpriority(p, niceval)) {
92849+ error = -EACCES;
92850+ goto out;
92851+ }
92852+
92853 no_nice = security_task_setnice(p, niceval);
92854 if (no_nice) {
92855 error = no_nice;
92856@@ -353,6 +359,20 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
92857 goto error;
92858 }
92859
92860+ if (gr_check_group_change(new->gid, new->egid, INVALID_GID))
92861+ goto error;
92862+
92863+ if (!gid_eq(new->gid, old->gid)) {
92864+ /* make sure we generate a learn log for what will
92865+ end up being a role transition after a full-learning
92866+ policy is generated
92867+ CAP_SETGID is required to perform a transition
92868+ we may not log a CAP_SETGID check above, e.g.
92869+ in the case where new rgid = old egid
92870+ */
92871+ gr_learn_cap(current, new, CAP_SETGID);
92872+ }
92873+
92874 if (rgid != (gid_t) -1 ||
92875 (egid != (gid_t) -1 && !gid_eq(kegid, old->gid)))
92876 new->sgid = new->egid;
92877@@ -388,6 +408,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
92878 old = current_cred();
92879
92880 retval = -EPERM;
92881+
92882+ if (gr_check_group_change(kgid, kgid, kgid))
92883+ goto error;
92884+
92885 if (ns_capable(old->user_ns, CAP_SETGID))
92886 new->gid = new->egid = new->sgid = new->fsgid = kgid;
92887 else if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->sgid))
92888@@ -405,7 +429,7 @@ error:
92889 /*
92890 * change the user struct in a credentials set to match the new UID
92891 */
92892-static int set_user(struct cred *new)
92893+int set_user(struct cred *new)
92894 {
92895 struct user_struct *new_user;
92896
92897@@ -485,7 +509,18 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
92898 goto error;
92899 }
92900
92901+ if (gr_check_user_change(new->uid, new->euid, INVALID_UID))
92902+ goto error;
92903+
92904 if (!uid_eq(new->uid, old->uid)) {
92905+ /* make sure we generate a learn log for what will
92906+ end up being a role transition after a full-learning
92907+ policy is generated
92908+ CAP_SETUID is required to perform a transition
92909+ we may not log a CAP_SETUID check above, e.g.
92910+ in the case where new ruid = old euid
92911+ */
92912+ gr_learn_cap(current, new, CAP_SETUID);
92913 retval = set_user(new);
92914 if (retval < 0)
92915 goto error;
92916@@ -535,6 +570,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
92917 old = current_cred();
92918
92919 retval = -EPERM;
92920+
92921+ if (gr_check_crash_uid(kuid))
92922+ goto error;
92923+ if (gr_check_user_change(kuid, kuid, kuid))
92924+ goto error;
92925+
92926 if (ns_capable(old->user_ns, CAP_SETUID)) {
92927 new->suid = new->uid = kuid;
92928 if (!uid_eq(kuid, old->uid)) {
92929@@ -604,6 +645,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
92930 goto error;
92931 }
92932
92933+ if (gr_check_user_change(kruid, keuid, INVALID_UID))
92934+ goto error;
92935+
92936 if (ruid != (uid_t) -1) {
92937 new->uid = kruid;
92938 if (!uid_eq(kruid, old->uid)) {
92939@@ -688,6 +732,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
92940 goto error;
92941 }
92942
92943+ if (gr_check_group_change(krgid, kegid, INVALID_GID))
92944+ goto error;
92945+
92946 if (rgid != (gid_t) -1)
92947 new->gid = krgid;
92948 if (egid != (gid_t) -1)
92949@@ -752,12 +799,16 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
92950 uid_eq(kuid, old->suid) || uid_eq(kuid, old->fsuid) ||
92951 ns_capable(old->user_ns, CAP_SETUID)) {
92952 if (!uid_eq(kuid, old->fsuid)) {
92953+ if (gr_check_user_change(INVALID_UID, INVALID_UID, kuid))
92954+ goto error;
92955+
92956 new->fsuid = kuid;
92957 if (security_task_fix_setuid(new, old, LSM_SETID_FS) == 0)
92958 goto change_okay;
92959 }
92960 }
92961
92962+error:
92963 abort_creds(new);
92964 return old_fsuid;
92965
92966@@ -790,12 +841,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
92967 if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->egid) ||
92968 gid_eq(kgid, old->sgid) || gid_eq(kgid, old->fsgid) ||
92969 ns_capable(old->user_ns, CAP_SETGID)) {
92970+ if (gr_check_group_change(INVALID_GID, INVALID_GID, kgid))
92971+ goto error;
92972+
92973 if (!gid_eq(kgid, old->fsgid)) {
92974 new->fsgid = kgid;
92975 goto change_okay;
92976 }
92977 }
92978
92979+error:
92980 abort_creds(new);
92981 return old_fsgid;
92982
92983@@ -1172,19 +1227,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
92984 return -EFAULT;
92985
92986 down_read(&uts_sem);
92987- error = __copy_to_user(&name->sysname, &utsname()->sysname,
92988+ error = __copy_to_user(name->sysname, &utsname()->sysname,
92989 __OLD_UTS_LEN);
92990 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
92991- error |= __copy_to_user(&name->nodename, &utsname()->nodename,
92992+ error |= __copy_to_user(name->nodename, &utsname()->nodename,
92993 __OLD_UTS_LEN);
92994 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
92995- error |= __copy_to_user(&name->release, &utsname()->release,
92996+ error |= __copy_to_user(name->release, &utsname()->release,
92997 __OLD_UTS_LEN);
92998 error |= __put_user(0, name->release + __OLD_UTS_LEN);
92999- error |= __copy_to_user(&name->version, &utsname()->version,
93000+ error |= __copy_to_user(name->version, &utsname()->version,
93001 __OLD_UTS_LEN);
93002 error |= __put_user(0, name->version + __OLD_UTS_LEN);
93003- error |= __copy_to_user(&name->machine, &utsname()->machine,
93004+ error |= __copy_to_user(name->machine, &utsname()->machine,
93005 __OLD_UTS_LEN);
93006 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
93007 up_read(&uts_sem);
93008@@ -1385,6 +1440,13 @@ int do_prlimit(struct task_struct *tsk, unsigned int resource,
93009 */
93010 new_rlim->rlim_cur = 1;
93011 }
93012+ /* Handle the case where a fork and setuid occur and then RLIMIT_NPROC
93013+ is changed to a lower value. Since tasks can be created by the same
93014+ user in between this limit change and an execve by this task, force
93015+ a recheck only for this task by setting PF_NPROC_EXCEEDED
93016+ */
93017+ if (resource == RLIMIT_NPROC && tsk->real_cred->user != INIT_USER)
93018+ tsk->flags |= PF_NPROC_EXCEEDED;
93019 }
93020 if (!retval) {
93021 if (old_rlim)
93022diff --git a/kernel/sysctl.c b/kernel/sysctl.c
93023index 15f2511..181b356 100644
93024--- a/kernel/sysctl.c
93025+++ b/kernel/sysctl.c
93026@@ -94,7 +94,6 @@
93027
93028
93029 #if defined(CONFIG_SYSCTL)
93030-
93031 /* External variables not in a header file. */
93032 extern int max_threads;
93033 extern int suid_dumpable;
93034@@ -115,19 +114,20 @@ extern int sysctl_nr_trim_pages;
93035
93036 /* Constants used for minimum and maximum */
93037 #ifdef CONFIG_LOCKUP_DETECTOR
93038-static int sixty = 60;
93039+static int sixty __read_only = 60;
93040 #endif
93041
93042-static int __maybe_unused neg_one = -1;
93043+static int __maybe_unused neg_one __read_only = -1;
93044
93045-static int zero;
93046-static int __maybe_unused one = 1;
93047-static int __maybe_unused two = 2;
93048-static int __maybe_unused four = 4;
93049-static unsigned long one_ul = 1;
93050-static int one_hundred = 100;
93051+static int zero __read_only = 0;
93052+static int __maybe_unused one __read_only = 1;
93053+static int __maybe_unused two __read_only = 2;
93054+static int __maybe_unused three __read_only = 3;
93055+static int __maybe_unused four __read_only = 4;
93056+static unsigned long one_ul __read_only = 1;
93057+static int one_hundred __read_only = 100;
93058 #ifdef CONFIG_PRINTK
93059-static int ten_thousand = 10000;
93060+static int ten_thousand __read_only = 10000;
93061 #endif
93062
93063 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
93064@@ -181,10 +181,8 @@ static int proc_taint(struct ctl_table *table, int write,
93065 void __user *buffer, size_t *lenp, loff_t *ppos);
93066 #endif
93067
93068-#ifdef CONFIG_PRINTK
93069 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
93070 void __user *buffer, size_t *lenp, loff_t *ppos);
93071-#endif
93072
93073 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
93074 void __user *buffer, size_t *lenp, loff_t *ppos);
93075@@ -215,6 +213,8 @@ static int sysrq_sysctl_handler(struct ctl_table *table, int write,
93076
93077 #endif
93078
93079+extern struct ctl_table grsecurity_table[];
93080+
93081 static struct ctl_table kern_table[];
93082 static struct ctl_table vm_table[];
93083 static struct ctl_table fs_table[];
93084@@ -229,6 +229,20 @@ extern struct ctl_table epoll_table[];
93085 int sysctl_legacy_va_layout;
93086 #endif
93087
93088+#ifdef CONFIG_PAX_SOFTMODE
93089+static struct ctl_table pax_table[] = {
93090+ {
93091+ .procname = "softmode",
93092+ .data = &pax_softmode,
93093+ .maxlen = sizeof(unsigned int),
93094+ .mode = 0600,
93095+ .proc_handler = &proc_dointvec,
93096+ },
93097+
93098+ { }
93099+};
93100+#endif
93101+
93102 /* The default sysctl tables: */
93103
93104 static struct ctl_table sysctl_base_table[] = {
93105@@ -277,6 +291,22 @@ static int max_extfrag_threshold = 1000;
93106 #endif
93107
93108 static struct ctl_table kern_table[] = {
93109+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
93110+ {
93111+ .procname = "grsecurity",
93112+ .mode = 0500,
93113+ .child = grsecurity_table,
93114+ },
93115+#endif
93116+
93117+#ifdef CONFIG_PAX_SOFTMODE
93118+ {
93119+ .procname = "pax",
93120+ .mode = 0500,
93121+ .child = pax_table,
93122+ },
93123+#endif
93124+
93125 {
93126 .procname = "sched_child_runs_first",
93127 .data = &sysctl_sched_child_runs_first,
93128@@ -642,7 +672,7 @@ static struct ctl_table kern_table[] = {
93129 .data = &modprobe_path,
93130 .maxlen = KMOD_PATH_LEN,
93131 .mode = 0644,
93132- .proc_handler = proc_dostring,
93133+ .proc_handler = proc_dostring_modpriv,
93134 },
93135 {
93136 .procname = "modules_disabled",
93137@@ -809,16 +839,20 @@ static struct ctl_table kern_table[] = {
93138 .extra1 = &zero,
93139 .extra2 = &one,
93140 },
93141+#endif
93142 {
93143 .procname = "kptr_restrict",
93144 .data = &kptr_restrict,
93145 .maxlen = sizeof(int),
93146 .mode = 0644,
93147 .proc_handler = proc_dointvec_minmax_sysadmin,
93148+#ifdef CONFIG_GRKERNSEC_HIDESYM
93149+ .extra1 = &two,
93150+#else
93151 .extra1 = &zero,
93152+#endif
93153 .extra2 = &two,
93154 },
93155-#endif
93156 {
93157 .procname = "ngroups_max",
93158 .data = &ngroups_max,
93159@@ -1065,10 +1099,17 @@ static struct ctl_table kern_table[] = {
93160 */
93161 {
93162 .procname = "perf_event_paranoid",
93163- .data = &sysctl_perf_event_paranoid,
93164- .maxlen = sizeof(sysctl_perf_event_paranoid),
93165+ .data = &sysctl_perf_event_legitimately_concerned,
93166+ .maxlen = sizeof(sysctl_perf_event_legitimately_concerned),
93167 .mode = 0644,
93168- .proc_handler = proc_dointvec,
93169+ /* go ahead, be a hero */
93170+ .proc_handler = proc_dointvec_minmax_sysadmin,
93171+ .extra1 = &neg_one,
93172+#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
93173+ .extra2 = &three,
93174+#else
93175+ .extra2 = &two,
93176+#endif
93177 },
93178 {
93179 .procname = "perf_event_mlock_kb",
93180@@ -1327,6 +1368,13 @@ static struct ctl_table vm_table[] = {
93181 .proc_handler = proc_dointvec_minmax,
93182 .extra1 = &zero,
93183 },
93184+ {
93185+ .procname = "heap_stack_gap",
93186+ .data = &sysctl_heap_stack_gap,
93187+ .maxlen = sizeof(sysctl_heap_stack_gap),
93188+ .mode = 0644,
93189+ .proc_handler = proc_doulongvec_minmax,
93190+ },
93191 #else
93192 {
93193 .procname = "nr_trim_pages",
93194@@ -1809,6 +1857,16 @@ int proc_dostring(struct ctl_table *table, int write,
93195 (char __user *)buffer, lenp, ppos);
93196 }
93197
93198+int proc_dostring_modpriv(struct ctl_table *table, int write,
93199+ void __user *buffer, size_t *lenp, loff_t *ppos)
93200+{
93201+ if (write && !capable(CAP_SYS_MODULE))
93202+ return -EPERM;
93203+
93204+ return _proc_do_string(table->data, table->maxlen, write,
93205+ buffer, lenp, ppos);
93206+}
93207+
93208 static size_t proc_skip_spaces(char **buf)
93209 {
93210 size_t ret;
93211@@ -1914,6 +1972,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
93212 len = strlen(tmp);
93213 if (len > *size)
93214 len = *size;
93215+ if (len > sizeof(tmp))
93216+ len = sizeof(tmp);
93217 if (copy_to_user(*buf, tmp, len))
93218 return -EFAULT;
93219 *size -= len;
93220@@ -2091,7 +2151,7 @@ int proc_dointvec(struct ctl_table *table, int write,
93221 static int proc_taint(struct ctl_table *table, int write,
93222 void __user *buffer, size_t *lenp, loff_t *ppos)
93223 {
93224- struct ctl_table t;
93225+ ctl_table_no_const t;
93226 unsigned long tmptaint = get_taint();
93227 int err;
93228
93229@@ -2119,7 +2179,6 @@ static int proc_taint(struct ctl_table *table, int write,
93230 return err;
93231 }
93232
93233-#ifdef CONFIG_PRINTK
93234 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
93235 void __user *buffer, size_t *lenp, loff_t *ppos)
93236 {
93237@@ -2128,7 +2187,6 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
93238
93239 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
93240 }
93241-#endif
93242
93243 struct do_proc_dointvec_minmax_conv_param {
93244 int *min;
93245@@ -2688,6 +2746,12 @@ int proc_dostring(struct ctl_table *table, int write,
93246 return -ENOSYS;
93247 }
93248
93249+int proc_dostring_modpriv(struct ctl_table *table, int write,
93250+ void __user *buffer, size_t *lenp, loff_t *ppos)
93251+{
93252+ return -ENOSYS;
93253+}
93254+
93255 int proc_dointvec(struct ctl_table *table, int write,
93256 void __user *buffer, size_t *lenp, loff_t *ppos)
93257 {
93258@@ -2744,5 +2808,6 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
93259 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
93260 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
93261 EXPORT_SYMBOL(proc_dostring);
93262+EXPORT_SYMBOL(proc_dostring_modpriv);
93263 EXPORT_SYMBOL(proc_doulongvec_minmax);
93264 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
93265diff --git a/kernel/taskstats.c b/kernel/taskstats.c
93266index b312fcc7..753d72d 100644
93267--- a/kernel/taskstats.c
93268+++ b/kernel/taskstats.c
93269@@ -28,9 +28,12 @@
93270 #include <linux/fs.h>
93271 #include <linux/file.h>
93272 #include <linux/pid_namespace.h>
93273+#include <linux/grsecurity.h>
93274 #include <net/genetlink.h>
93275 #include <linux/atomic.h>
93276
93277+extern int gr_is_taskstats_denied(int pid);
93278+
93279 /*
93280 * Maximum length of a cpumask that can be specified in
93281 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
93282@@ -576,6 +579,9 @@ err:
93283
93284 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
93285 {
93286+ if (gr_is_taskstats_denied(current->pid))
93287+ return -EACCES;
93288+
93289 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
93290 return cmd_attr_register_cpumask(info);
93291 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
93292diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
93293index a7077d3..dd48a49 100644
93294--- a/kernel/time/alarmtimer.c
93295+++ b/kernel/time/alarmtimer.c
93296@@ -823,7 +823,7 @@ static int __init alarmtimer_init(void)
93297 struct platform_device *pdev;
93298 int error = 0;
93299 int i;
93300- struct k_clock alarm_clock = {
93301+ static struct k_clock alarm_clock = {
93302 .clock_getres = alarm_clock_getres,
93303 .clock_get = alarm_clock_get,
93304 .timer_create = alarm_timer_create,
93305diff --git a/kernel/time/hrtimer.c b/kernel/time/hrtimer.c
93306index 37e50aa..57a9501 100644
93307--- a/kernel/time/hrtimer.c
93308+++ b/kernel/time/hrtimer.c
93309@@ -1399,7 +1399,7 @@ void hrtimer_peek_ahead_timers(void)
93310 local_irq_restore(flags);
93311 }
93312
93313-static void run_hrtimer_softirq(struct softirq_action *h)
93314+static __latent_entropy void run_hrtimer_softirq(void)
93315 {
93316 hrtimer_peek_ahead_timers();
93317 }
93318diff --git a/kernel/time/posix-cpu-timers.c b/kernel/time/posix-cpu-timers.c
93319index a16b678..8c5bd9d 100644
93320--- a/kernel/time/posix-cpu-timers.c
93321+++ b/kernel/time/posix-cpu-timers.c
93322@@ -1450,14 +1450,14 @@ struct k_clock clock_posix_cpu = {
93323
93324 static __init int init_posix_cpu_timers(void)
93325 {
93326- struct k_clock process = {
93327+ static struct k_clock process = {
93328 .clock_getres = process_cpu_clock_getres,
93329 .clock_get = process_cpu_clock_get,
93330 .timer_create = process_cpu_timer_create,
93331 .nsleep = process_cpu_nsleep,
93332 .nsleep_restart = process_cpu_nsleep_restart,
93333 };
93334- struct k_clock thread = {
93335+ static struct k_clock thread = {
93336 .clock_getres = thread_cpu_clock_getres,
93337 .clock_get = thread_cpu_clock_get,
93338 .timer_create = thread_cpu_timer_create,
93339diff --git a/kernel/time/posix-timers.c b/kernel/time/posix-timers.c
93340index 31ea01f..7fc61ef 100644
93341--- a/kernel/time/posix-timers.c
93342+++ b/kernel/time/posix-timers.c
93343@@ -43,6 +43,7 @@
93344 #include <linux/hash.h>
93345 #include <linux/posix-clock.h>
93346 #include <linux/posix-timers.h>
93347+#include <linux/grsecurity.h>
93348 #include <linux/syscalls.h>
93349 #include <linux/wait.h>
93350 #include <linux/workqueue.h>
93351@@ -124,7 +125,7 @@ static DEFINE_SPINLOCK(hash_lock);
93352 * which we beg off on and pass to do_sys_settimeofday().
93353 */
93354
93355-static struct k_clock posix_clocks[MAX_CLOCKS];
93356+static struct k_clock *posix_clocks[MAX_CLOCKS];
93357
93358 /*
93359 * These ones are defined below.
93360@@ -277,7 +278,7 @@ static int posix_get_tai(clockid_t which_clock, struct timespec *tp)
93361 */
93362 static __init int init_posix_timers(void)
93363 {
93364- struct k_clock clock_realtime = {
93365+ static struct k_clock clock_realtime = {
93366 .clock_getres = hrtimer_get_res,
93367 .clock_get = posix_clock_realtime_get,
93368 .clock_set = posix_clock_realtime_set,
93369@@ -289,7 +290,7 @@ static __init int init_posix_timers(void)
93370 .timer_get = common_timer_get,
93371 .timer_del = common_timer_del,
93372 };
93373- struct k_clock clock_monotonic = {
93374+ static struct k_clock clock_monotonic = {
93375 .clock_getres = hrtimer_get_res,
93376 .clock_get = posix_ktime_get_ts,
93377 .nsleep = common_nsleep,
93378@@ -299,19 +300,19 @@ static __init int init_posix_timers(void)
93379 .timer_get = common_timer_get,
93380 .timer_del = common_timer_del,
93381 };
93382- struct k_clock clock_monotonic_raw = {
93383+ static struct k_clock clock_monotonic_raw = {
93384 .clock_getres = hrtimer_get_res,
93385 .clock_get = posix_get_monotonic_raw,
93386 };
93387- struct k_clock clock_realtime_coarse = {
93388+ static struct k_clock clock_realtime_coarse = {
93389 .clock_getres = posix_get_coarse_res,
93390 .clock_get = posix_get_realtime_coarse,
93391 };
93392- struct k_clock clock_monotonic_coarse = {
93393+ static struct k_clock clock_monotonic_coarse = {
93394 .clock_getres = posix_get_coarse_res,
93395 .clock_get = posix_get_monotonic_coarse,
93396 };
93397- struct k_clock clock_tai = {
93398+ static struct k_clock clock_tai = {
93399 .clock_getres = hrtimer_get_res,
93400 .clock_get = posix_get_tai,
93401 .nsleep = common_nsleep,
93402@@ -321,7 +322,7 @@ static __init int init_posix_timers(void)
93403 .timer_get = common_timer_get,
93404 .timer_del = common_timer_del,
93405 };
93406- struct k_clock clock_boottime = {
93407+ static struct k_clock clock_boottime = {
93408 .clock_getres = hrtimer_get_res,
93409 .clock_get = posix_get_boottime,
93410 .nsleep = common_nsleep,
93411@@ -533,7 +534,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
93412 return;
93413 }
93414
93415- posix_clocks[clock_id] = *new_clock;
93416+ posix_clocks[clock_id] = new_clock;
93417 }
93418 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
93419
93420@@ -579,9 +580,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
93421 return (id & CLOCKFD_MASK) == CLOCKFD ?
93422 &clock_posix_dynamic : &clock_posix_cpu;
93423
93424- if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
93425+ if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
93426 return NULL;
93427- return &posix_clocks[id];
93428+ return posix_clocks[id];
93429 }
93430
93431 static int common_timer_create(struct k_itimer *new_timer)
93432@@ -599,7 +600,7 @@ SYSCALL_DEFINE3(timer_create, const clockid_t, which_clock,
93433 struct k_clock *kc = clockid_to_kclock(which_clock);
93434 struct k_itimer *new_timer;
93435 int error, new_timer_id;
93436- sigevent_t event;
93437+ sigevent_t event = { };
93438 int it_id_set = IT_ID_NOT_SET;
93439
93440 if (!kc)
93441@@ -1014,6 +1015,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
93442 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
93443 return -EFAULT;
93444
93445+ /* only the CLOCK_REALTIME clock can be set, all other clocks
93446+ have their clock_set fptr set to a nosettime dummy function
93447+ CLOCK_REALTIME has a NULL clock_set fptr which causes it to
93448+ call common_clock_set, which calls do_sys_settimeofday, which
93449+ we hook
93450+ */
93451+
93452 return kc->clock_set(which_clock, &new_tp);
93453 }
93454
93455diff --git a/kernel/time/time.c b/kernel/time/time.c
93456index a9ae20f..d3fbde7 100644
93457--- a/kernel/time/time.c
93458+++ b/kernel/time/time.c
93459@@ -173,6 +173,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
93460 return error;
93461
93462 if (tz) {
93463+ /* we log in do_settimeofday called below, so don't log twice
93464+ */
93465+ if (!tv)
93466+ gr_log_timechange();
93467+
93468 sys_tz = *tz;
93469 update_vsyscall_tz();
93470 if (firsttime) {
93471diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
93472index ec1791f..6a086cd 100644
93473--- a/kernel/time/timekeeping.c
93474+++ b/kernel/time/timekeeping.c
93475@@ -15,6 +15,7 @@
93476 #include <linux/init.h>
93477 #include <linux/mm.h>
93478 #include <linux/sched.h>
93479+#include <linux/grsecurity.h>
93480 #include <linux/syscore_ops.h>
93481 #include <linux/clocksource.h>
93482 #include <linux/jiffies.h>
93483@@ -717,6 +718,8 @@ int do_settimeofday(const struct timespec *tv)
93484 if (!timespec_valid_strict(tv))
93485 return -EINVAL;
93486
93487+ gr_log_timechange();
93488+
93489 raw_spin_lock_irqsave(&timekeeper_lock, flags);
93490 write_seqcount_begin(&tk_core.seq);
93491
93492diff --git a/kernel/time/timer.c b/kernel/time/timer.c
93493index 3260ffd..c93cd5e 100644
93494--- a/kernel/time/timer.c
93495+++ b/kernel/time/timer.c
93496@@ -1394,7 +1394,7 @@ void update_process_times(int user_tick)
93497 /*
93498 * This function runs timers and the timer-tq in bottom half context.
93499 */
93500-static void run_timer_softirq(struct softirq_action *h)
93501+static __latent_entropy void run_timer_softirq(void)
93502 {
93503 struct tvec_base *base = __this_cpu_read(tvec_bases);
93504
93505@@ -1457,7 +1457,7 @@ static void process_timeout(unsigned long __data)
93506 *
93507 * In all cases the return value is guaranteed to be non-negative.
93508 */
93509-signed long __sched schedule_timeout(signed long timeout)
93510+signed long __sched __intentional_overflow(-1) schedule_timeout(signed long timeout)
93511 {
93512 struct timer_list timer;
93513 unsigned long expire;
93514diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
93515index 61ed862..3b52c65 100644
93516--- a/kernel/time/timer_list.c
93517+++ b/kernel/time/timer_list.c
93518@@ -45,12 +45,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
93519
93520 static void print_name_offset(struct seq_file *m, void *sym)
93521 {
93522+#ifdef CONFIG_GRKERNSEC_HIDESYM
93523+ SEQ_printf(m, "<%p>", NULL);
93524+#else
93525 char symname[KSYM_NAME_LEN];
93526
93527 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
93528 SEQ_printf(m, "<%pK>", sym);
93529 else
93530 SEQ_printf(m, "%s", symname);
93531+#endif
93532 }
93533
93534 static void
93535@@ -119,7 +123,11 @@ next_one:
93536 static void
93537 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
93538 {
93539+#ifdef CONFIG_GRKERNSEC_HIDESYM
93540+ SEQ_printf(m, " .base: %p\n", NULL);
93541+#else
93542 SEQ_printf(m, " .base: %pK\n", base);
93543+#endif
93544 SEQ_printf(m, " .index: %d\n",
93545 base->index);
93546 SEQ_printf(m, " .resolution: %Lu nsecs\n",
93547@@ -362,7 +370,11 @@ static int __init init_timer_list_procfs(void)
93548 {
93549 struct proc_dir_entry *pe;
93550
93551+#ifdef CONFIG_GRKERNSEC_PROC_ADD
93552+ pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
93553+#else
93554 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
93555+#endif
93556 if (!pe)
93557 return -ENOMEM;
93558 return 0;
93559diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
93560index 1fb08f2..ca4bb1e 100644
93561--- a/kernel/time/timer_stats.c
93562+++ b/kernel/time/timer_stats.c
93563@@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
93564 static unsigned long nr_entries;
93565 static struct entry entries[MAX_ENTRIES];
93566
93567-static atomic_t overflow_count;
93568+static atomic_unchecked_t overflow_count;
93569
93570 /*
93571 * The entries are in a hash-table, for fast lookup:
93572@@ -140,7 +140,7 @@ static void reset_entries(void)
93573 nr_entries = 0;
93574 memset(entries, 0, sizeof(entries));
93575 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
93576- atomic_set(&overflow_count, 0);
93577+ atomic_set_unchecked(&overflow_count, 0);
93578 }
93579
93580 static struct entry *alloc_entry(void)
93581@@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
93582 if (likely(entry))
93583 entry->count++;
93584 else
93585- atomic_inc(&overflow_count);
93586+ atomic_inc_unchecked(&overflow_count);
93587
93588 out_unlock:
93589 raw_spin_unlock_irqrestore(lock, flags);
93590@@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
93591
93592 static void print_name_offset(struct seq_file *m, unsigned long addr)
93593 {
93594+#ifdef CONFIG_GRKERNSEC_HIDESYM
93595+ seq_printf(m, "<%p>", NULL);
93596+#else
93597 char symname[KSYM_NAME_LEN];
93598
93599 if (lookup_symbol_name(addr, symname) < 0)
93600- seq_printf(m, "<%p>", (void *)addr);
93601+ seq_printf(m, "<%pK>", (void *)addr);
93602 else
93603 seq_printf(m, "%s", symname);
93604+#endif
93605 }
93606
93607 static int tstats_show(struct seq_file *m, void *v)
93608@@ -300,8 +304,8 @@ static int tstats_show(struct seq_file *m, void *v)
93609
93610 seq_puts(m, "Timer Stats Version: v0.3\n");
93611 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
93612- if (atomic_read(&overflow_count))
93613- seq_printf(m, "Overflow: %d entries\n", atomic_read(&overflow_count));
93614+ if (atomic_read_unchecked(&overflow_count))
93615+ seq_printf(m, "Overflow: %d entries\n", atomic_read_unchecked(&overflow_count));
93616 seq_printf(m, "Collection: %s\n", timer_stats_active ? "active" : "inactive");
93617
93618 for (i = 0; i < nr_entries; i++) {
93619@@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
93620 {
93621 struct proc_dir_entry *pe;
93622
93623+#ifdef CONFIG_GRKERNSEC_PROC_ADD
93624+ pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
93625+#else
93626 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
93627+#endif
93628 if (!pe)
93629 return -ENOMEM;
93630 return 0;
93631diff --git a/kernel/torture.c b/kernel/torture.c
93632index dd70993..0bf694b 100644
93633--- a/kernel/torture.c
93634+++ b/kernel/torture.c
93635@@ -482,7 +482,7 @@ static int torture_shutdown_notify(struct notifier_block *unused1,
93636 mutex_lock(&fullstop_mutex);
93637 if (ACCESS_ONCE(fullstop) == FULLSTOP_DONTSTOP) {
93638 VERBOSE_TOROUT_STRING("Unscheduled system shutdown detected");
93639- ACCESS_ONCE(fullstop) = FULLSTOP_SHUTDOWN;
93640+ ACCESS_ONCE_RW(fullstop) = FULLSTOP_SHUTDOWN;
93641 } else {
93642 pr_warn("Concurrent rmmod and shutdown illegal!\n");
93643 }
93644@@ -549,14 +549,14 @@ static int torture_stutter(void *arg)
93645 if (!torture_must_stop()) {
93646 if (stutter > 1) {
93647 schedule_timeout_interruptible(stutter - 1);
93648- ACCESS_ONCE(stutter_pause_test) = 2;
93649+ ACCESS_ONCE_RW(stutter_pause_test) = 2;
93650 }
93651 schedule_timeout_interruptible(1);
93652- ACCESS_ONCE(stutter_pause_test) = 1;
93653+ ACCESS_ONCE_RW(stutter_pause_test) = 1;
93654 }
93655 if (!torture_must_stop())
93656 schedule_timeout_interruptible(stutter);
93657- ACCESS_ONCE(stutter_pause_test) = 0;
93658+ ACCESS_ONCE_RW(stutter_pause_test) = 0;
93659 torture_shutdown_absorb("torture_stutter");
93660 } while (!torture_must_stop());
93661 torture_kthread_stopping("torture_stutter");
93662@@ -648,7 +648,7 @@ bool torture_cleanup_begin(void)
93663 schedule_timeout_uninterruptible(10);
93664 return true;
93665 }
93666- ACCESS_ONCE(fullstop) = FULLSTOP_RMMOD;
93667+ ACCESS_ONCE_RW(fullstop) = FULLSTOP_RMMOD;
93668 mutex_unlock(&fullstop_mutex);
93669 torture_shutdown_cleanup();
93670 torture_shuffle_cleanup();
93671diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
93672index c1bd4ad..4b861dc 100644
93673--- a/kernel/trace/blktrace.c
93674+++ b/kernel/trace/blktrace.c
93675@@ -328,7 +328,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
93676 struct blk_trace *bt = filp->private_data;
93677 char buf[16];
93678
93679- snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
93680+ snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
93681
93682 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
93683 }
93684@@ -386,7 +386,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
93685 return 1;
93686
93687 bt = buf->chan->private_data;
93688- atomic_inc(&bt->dropped);
93689+ atomic_inc_unchecked(&bt->dropped);
93690 return 0;
93691 }
93692
93693@@ -487,7 +487,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
93694
93695 bt->dir = dir;
93696 bt->dev = dev;
93697- atomic_set(&bt->dropped, 0);
93698+ atomic_set_unchecked(&bt->dropped, 0);
93699 INIT_LIST_HEAD(&bt->running_list);
93700
93701 ret = -EIO;
93702diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
93703index 31c90fe..051ce98 100644
93704--- a/kernel/trace/ftrace.c
93705+++ b/kernel/trace/ftrace.c
93706@@ -2183,12 +2183,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
93707 if (unlikely(ftrace_disabled))
93708 return 0;
93709
93710+ ret = ftrace_arch_code_modify_prepare();
93711+ FTRACE_WARN_ON(ret);
93712+ if (ret)
93713+ return 0;
93714+
93715 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
93716+ FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
93717 if (ret) {
93718 ftrace_bug(ret, ip);
93719- return 0;
93720 }
93721- return 1;
93722+ return ret ? 0 : 1;
93723 }
93724
93725 /*
93726@@ -4492,8 +4497,10 @@ static int ftrace_process_locs(struct module *mod,
93727 if (!count)
93728 return 0;
93729
93730+ pax_open_kernel();
93731 sort(start, count, sizeof(*start),
93732 ftrace_cmp_ips, ftrace_swap_ips);
93733+ pax_close_kernel();
93734
93735 start_pg = ftrace_allocate_pages(count);
93736 if (!start_pg)
93737@@ -5340,7 +5347,7 @@ static int alloc_retstack_tasklist(struct ftrace_ret_stack **ret_stack_list)
93738
93739 if (t->ret_stack == NULL) {
93740 atomic_set(&t->tracing_graph_pause, 0);
93741- atomic_set(&t->trace_overrun, 0);
93742+ atomic_set_unchecked(&t->trace_overrun, 0);
93743 t->curr_ret_stack = -1;
93744 /* Make sure the tasks see the -1 first: */
93745 smp_wmb();
93746@@ -5553,7 +5560,7 @@ static void
93747 graph_init_task(struct task_struct *t, struct ftrace_ret_stack *ret_stack)
93748 {
93749 atomic_set(&t->tracing_graph_pause, 0);
93750- atomic_set(&t->trace_overrun, 0);
93751+ atomic_set_unchecked(&t->trace_overrun, 0);
93752 t->ftrace_timestamp = 0;
93753 /* make curr_ret_stack visible before we add the ret_stack */
93754 smp_wmb();
93755diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
93756index a56e07c..d46f0ba 100644
93757--- a/kernel/trace/ring_buffer.c
93758+++ b/kernel/trace/ring_buffer.c
93759@@ -352,9 +352,9 @@ struct buffer_data_page {
93760 */
93761 struct buffer_page {
93762 struct list_head list; /* list of buffer pages */
93763- local_t write; /* index for next write */
93764+ local_unchecked_t write; /* index for next write */
93765 unsigned read; /* index for next read */
93766- local_t entries; /* entries on this page */
93767+ local_unchecked_t entries; /* entries on this page */
93768 unsigned long real_end; /* real end of data */
93769 struct buffer_data_page *page; /* Actual data page */
93770 };
93771@@ -473,8 +473,8 @@ struct ring_buffer_per_cpu {
93772 unsigned long last_overrun;
93773 local_t entries_bytes;
93774 local_t entries;
93775- local_t overrun;
93776- local_t commit_overrun;
93777+ local_unchecked_t overrun;
93778+ local_unchecked_t commit_overrun;
93779 local_t dropped_events;
93780 local_t committing;
93781 local_t commits;
93782@@ -1032,8 +1032,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
93783 *
93784 * We add a counter to the write field to denote this.
93785 */
93786- old_write = local_add_return(RB_WRITE_INTCNT, &next_page->write);
93787- old_entries = local_add_return(RB_WRITE_INTCNT, &next_page->entries);
93788+ old_write = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->write);
93789+ old_entries = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->entries);
93790
93791 /*
93792 * Just make sure we have seen our old_write and synchronize
93793@@ -1061,8 +1061,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
93794 * cmpxchg to only update if an interrupt did not already
93795 * do it for us. If the cmpxchg fails, we don't care.
93796 */
93797- (void)local_cmpxchg(&next_page->write, old_write, val);
93798- (void)local_cmpxchg(&next_page->entries, old_entries, eval);
93799+ (void)local_cmpxchg_unchecked(&next_page->write, old_write, val);
93800+ (void)local_cmpxchg_unchecked(&next_page->entries, old_entries, eval);
93801
93802 /*
93803 * No need to worry about races with clearing out the commit.
93804@@ -1429,12 +1429,12 @@ static void rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer);
93805
93806 static inline unsigned long rb_page_entries(struct buffer_page *bpage)
93807 {
93808- return local_read(&bpage->entries) & RB_WRITE_MASK;
93809+ return local_read_unchecked(&bpage->entries) & RB_WRITE_MASK;
93810 }
93811
93812 static inline unsigned long rb_page_write(struct buffer_page *bpage)
93813 {
93814- return local_read(&bpage->write) & RB_WRITE_MASK;
93815+ return local_read_unchecked(&bpage->write) & RB_WRITE_MASK;
93816 }
93817
93818 static int
93819@@ -1529,7 +1529,7 @@ rb_remove_pages(struct ring_buffer_per_cpu *cpu_buffer, unsigned int nr_pages)
93820 * bytes consumed in ring buffer from here.
93821 * Increment overrun to account for the lost events.
93822 */
93823- local_add(page_entries, &cpu_buffer->overrun);
93824+ local_add_unchecked(page_entries, &cpu_buffer->overrun);
93825 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
93826 }
93827
93828@@ -2091,7 +2091,7 @@ rb_handle_head_page(struct ring_buffer_per_cpu *cpu_buffer,
93829 * it is our responsibility to update
93830 * the counters.
93831 */
93832- local_add(entries, &cpu_buffer->overrun);
93833+ local_add_unchecked(entries, &cpu_buffer->overrun);
93834 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
93835
93836 /*
93837@@ -2241,7 +2241,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
93838 if (tail == BUF_PAGE_SIZE)
93839 tail_page->real_end = 0;
93840
93841- local_sub(length, &tail_page->write);
93842+ local_sub_unchecked(length, &tail_page->write);
93843 return;
93844 }
93845
93846@@ -2276,7 +2276,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
93847 rb_event_set_padding(event);
93848
93849 /* Set the write back to the previous setting */
93850- local_sub(length, &tail_page->write);
93851+ local_sub_unchecked(length, &tail_page->write);
93852 return;
93853 }
93854
93855@@ -2288,7 +2288,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
93856
93857 /* Set write to end of buffer */
93858 length = (tail + length) - BUF_PAGE_SIZE;
93859- local_sub(length, &tail_page->write);
93860+ local_sub_unchecked(length, &tail_page->write);
93861 }
93862
93863 /*
93864@@ -2314,7 +2314,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
93865 * about it.
93866 */
93867 if (unlikely(next_page == commit_page)) {
93868- local_inc(&cpu_buffer->commit_overrun);
93869+ local_inc_unchecked(&cpu_buffer->commit_overrun);
93870 goto out_reset;
93871 }
93872
93873@@ -2370,7 +2370,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
93874 cpu_buffer->tail_page) &&
93875 (cpu_buffer->commit_page ==
93876 cpu_buffer->reader_page))) {
93877- local_inc(&cpu_buffer->commit_overrun);
93878+ local_inc_unchecked(&cpu_buffer->commit_overrun);
93879 goto out_reset;
93880 }
93881 }
93882@@ -2418,7 +2418,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
93883 length += RB_LEN_TIME_EXTEND;
93884
93885 tail_page = cpu_buffer->tail_page;
93886- write = local_add_return(length, &tail_page->write);
93887+ write = local_add_return_unchecked(length, &tail_page->write);
93888
93889 /* set write to only the index of the write */
93890 write &= RB_WRITE_MASK;
93891@@ -2442,7 +2442,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
93892 kmemcheck_annotate_bitfield(event, bitfield);
93893 rb_update_event(cpu_buffer, event, length, add_timestamp, delta);
93894
93895- local_inc(&tail_page->entries);
93896+ local_inc_unchecked(&tail_page->entries);
93897
93898 /*
93899 * If this is the first commit on the page, then update
93900@@ -2475,7 +2475,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
93901
93902 if (bpage->page == (void *)addr && rb_page_write(bpage) == old_index) {
93903 unsigned long write_mask =
93904- local_read(&bpage->write) & ~RB_WRITE_MASK;
93905+ local_read_unchecked(&bpage->write) & ~RB_WRITE_MASK;
93906 unsigned long event_length = rb_event_length(event);
93907 /*
93908 * This is on the tail page. It is possible that
93909@@ -2485,7 +2485,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
93910 */
93911 old_index += write_mask;
93912 new_index += write_mask;
93913- index = local_cmpxchg(&bpage->write, old_index, new_index);
93914+ index = local_cmpxchg_unchecked(&bpage->write, old_index, new_index);
93915 if (index == old_index) {
93916 /* update counters */
93917 local_sub(event_length, &cpu_buffer->entries_bytes);
93918@@ -2877,7 +2877,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
93919
93920 /* Do the likely case first */
93921 if (likely(bpage->page == (void *)addr)) {
93922- local_dec(&bpage->entries);
93923+ local_dec_unchecked(&bpage->entries);
93924 return;
93925 }
93926
93927@@ -2889,7 +2889,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
93928 start = bpage;
93929 do {
93930 if (bpage->page == (void *)addr) {
93931- local_dec(&bpage->entries);
93932+ local_dec_unchecked(&bpage->entries);
93933 return;
93934 }
93935 rb_inc_page(cpu_buffer, &bpage);
93936@@ -3173,7 +3173,7 @@ static inline unsigned long
93937 rb_num_of_entries(struct ring_buffer_per_cpu *cpu_buffer)
93938 {
93939 return local_read(&cpu_buffer->entries) -
93940- (local_read(&cpu_buffer->overrun) + cpu_buffer->read);
93941+ (local_read_unchecked(&cpu_buffer->overrun) + cpu_buffer->read);
93942 }
93943
93944 /**
93945@@ -3262,7 +3262,7 @@ unsigned long ring_buffer_overrun_cpu(struct ring_buffer *buffer, int cpu)
93946 return 0;
93947
93948 cpu_buffer = buffer->buffers[cpu];
93949- ret = local_read(&cpu_buffer->overrun);
93950+ ret = local_read_unchecked(&cpu_buffer->overrun);
93951
93952 return ret;
93953 }
93954@@ -3285,7 +3285,7 @@ ring_buffer_commit_overrun_cpu(struct ring_buffer *buffer, int cpu)
93955 return 0;
93956
93957 cpu_buffer = buffer->buffers[cpu];
93958- ret = local_read(&cpu_buffer->commit_overrun);
93959+ ret = local_read_unchecked(&cpu_buffer->commit_overrun);
93960
93961 return ret;
93962 }
93963@@ -3370,7 +3370,7 @@ unsigned long ring_buffer_overruns(struct ring_buffer *buffer)
93964 /* if you care about this being correct, lock the buffer */
93965 for_each_buffer_cpu(buffer, cpu) {
93966 cpu_buffer = buffer->buffers[cpu];
93967- overruns += local_read(&cpu_buffer->overrun);
93968+ overruns += local_read_unchecked(&cpu_buffer->overrun);
93969 }
93970
93971 return overruns;
93972@@ -3541,8 +3541,8 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
93973 /*
93974 * Reset the reader page to size zero.
93975 */
93976- local_set(&cpu_buffer->reader_page->write, 0);
93977- local_set(&cpu_buffer->reader_page->entries, 0);
93978+ local_set_unchecked(&cpu_buffer->reader_page->write, 0);
93979+ local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
93980 local_set(&cpu_buffer->reader_page->page->commit, 0);
93981 cpu_buffer->reader_page->real_end = 0;
93982
93983@@ -3576,7 +3576,7 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
93984 * want to compare with the last_overrun.
93985 */
93986 smp_mb();
93987- overwrite = local_read(&(cpu_buffer->overrun));
93988+ overwrite = local_read_unchecked(&(cpu_buffer->overrun));
93989
93990 /*
93991 * Here's the tricky part.
93992@@ -4148,8 +4148,8 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
93993
93994 cpu_buffer->head_page
93995 = list_entry(cpu_buffer->pages, struct buffer_page, list);
93996- local_set(&cpu_buffer->head_page->write, 0);
93997- local_set(&cpu_buffer->head_page->entries, 0);
93998+ local_set_unchecked(&cpu_buffer->head_page->write, 0);
93999+ local_set_unchecked(&cpu_buffer->head_page->entries, 0);
94000 local_set(&cpu_buffer->head_page->page->commit, 0);
94001
94002 cpu_buffer->head_page->read = 0;
94003@@ -4159,14 +4159,14 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
94004
94005 INIT_LIST_HEAD(&cpu_buffer->reader_page->list);
94006 INIT_LIST_HEAD(&cpu_buffer->new_pages);
94007- local_set(&cpu_buffer->reader_page->write, 0);
94008- local_set(&cpu_buffer->reader_page->entries, 0);
94009+ local_set_unchecked(&cpu_buffer->reader_page->write, 0);
94010+ local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
94011 local_set(&cpu_buffer->reader_page->page->commit, 0);
94012 cpu_buffer->reader_page->read = 0;
94013
94014 local_set(&cpu_buffer->entries_bytes, 0);
94015- local_set(&cpu_buffer->overrun, 0);
94016- local_set(&cpu_buffer->commit_overrun, 0);
94017+ local_set_unchecked(&cpu_buffer->overrun, 0);
94018+ local_set_unchecked(&cpu_buffer->commit_overrun, 0);
94019 local_set(&cpu_buffer->dropped_events, 0);
94020 local_set(&cpu_buffer->entries, 0);
94021 local_set(&cpu_buffer->committing, 0);
94022@@ -4571,8 +4571,8 @@ int ring_buffer_read_page(struct ring_buffer *buffer,
94023 rb_init_page(bpage);
94024 bpage = reader->page;
94025 reader->page = *data_page;
94026- local_set(&reader->write, 0);
94027- local_set(&reader->entries, 0);
94028+ local_set_unchecked(&reader->write, 0);
94029+ local_set_unchecked(&reader->entries, 0);
94030 reader->read = 0;
94031 *data_page = bpage;
94032
94033diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
94034index 426962b..e8e2d9a 100644
94035--- a/kernel/trace/trace.c
94036+++ b/kernel/trace/trace.c
94037@@ -3488,7 +3488,7 @@ int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set)
94038 return 0;
94039 }
94040
94041-int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled)
94042+int set_tracer_flag(struct trace_array *tr, unsigned long mask, int enabled)
94043 {
94044 /* do nothing if flag is already set */
94045 if (!!(trace_flags & mask) == !!enabled)
94046diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h
94047index 385391f..8d2250f 100644
94048--- a/kernel/trace/trace.h
94049+++ b/kernel/trace/trace.h
94050@@ -1280,7 +1280,7 @@ extern const char *__stop___tracepoint_str[];
94051 void trace_printk_init_buffers(void);
94052 void trace_printk_start_comm(void);
94053 int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set);
94054-int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled);
94055+int set_tracer_flag(struct trace_array *tr, unsigned long mask, int enabled);
94056
94057 /*
94058 * Normal trace_printk() and friends allocates special buffers
94059diff --git a/kernel/trace/trace_clock.c b/kernel/trace/trace_clock.c
94060index 57b67b1..66082a9 100644
94061--- a/kernel/trace/trace_clock.c
94062+++ b/kernel/trace/trace_clock.c
94063@@ -124,7 +124,7 @@ u64 notrace trace_clock_global(void)
94064 return now;
94065 }
94066
94067-static atomic64_t trace_counter;
94068+static atomic64_unchecked_t trace_counter;
94069
94070 /*
94071 * trace_clock_counter(): simply an atomic counter.
94072@@ -133,5 +133,5 @@ static atomic64_t trace_counter;
94073 */
94074 u64 notrace trace_clock_counter(void)
94075 {
94076- return atomic64_add_return(1, &trace_counter);
94077+ return atomic64_inc_return_unchecked(&trace_counter);
94078 }
94079diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
94080index 1b0df1e..4ebb965 100644
94081--- a/kernel/trace/trace_events.c
94082+++ b/kernel/trace/trace_events.c
94083@@ -1720,7 +1720,6 @@ __trace_early_add_new_event(struct ftrace_event_call *call,
94084 return 0;
94085 }
94086
94087-struct ftrace_module_file_ops;
94088 static void __add_event_to_tracers(struct ftrace_event_call *call);
94089
94090 /* Add an additional event_call dynamically */
94091diff --git a/kernel/trace/trace_functions_graph.c b/kernel/trace/trace_functions_graph.c
94092index f0a0c98..3692dc8 100644
94093--- a/kernel/trace/trace_functions_graph.c
94094+++ b/kernel/trace/trace_functions_graph.c
94095@@ -133,7 +133,7 @@ ftrace_push_return_trace(unsigned long ret, unsigned long func, int *depth,
94096
94097 /* The return trace stack is full */
94098 if (current->curr_ret_stack == FTRACE_RETFUNC_DEPTH - 1) {
94099- atomic_inc(&current->trace_overrun);
94100+ atomic_inc_unchecked(&current->trace_overrun);
94101 return -EBUSY;
94102 }
94103
94104@@ -230,7 +230,7 @@ ftrace_pop_return_trace(struct ftrace_graph_ret *trace, unsigned long *ret,
94105 *ret = current->ret_stack[index].ret;
94106 trace->func = current->ret_stack[index].func;
94107 trace->calltime = current->ret_stack[index].calltime;
94108- trace->overrun = atomic_read(&current->trace_overrun);
94109+ trace->overrun = atomic_read_unchecked(&current->trace_overrun);
94110 trace->depth = index;
94111 }
94112
94113diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
94114index 0abd9b8..6a663a2 100644
94115--- a/kernel/trace/trace_mmiotrace.c
94116+++ b/kernel/trace/trace_mmiotrace.c
94117@@ -24,7 +24,7 @@ struct header_iter {
94118 static struct trace_array *mmio_trace_array;
94119 static bool overrun_detected;
94120 static unsigned long prev_overruns;
94121-static atomic_t dropped_count;
94122+static atomic_unchecked_t dropped_count;
94123
94124 static void mmio_reset_data(struct trace_array *tr)
94125 {
94126@@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
94127
94128 static unsigned long count_overruns(struct trace_iterator *iter)
94129 {
94130- unsigned long cnt = atomic_xchg(&dropped_count, 0);
94131+ unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
94132 unsigned long over = ring_buffer_overruns(iter->trace_buffer->buffer);
94133
94134 if (over > prev_overruns)
94135@@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
94136 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
94137 sizeof(*entry), 0, pc);
94138 if (!event) {
94139- atomic_inc(&dropped_count);
94140+ atomic_inc_unchecked(&dropped_count);
94141 return;
94142 }
94143 entry = ring_buffer_event_data(event);
94144@@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
94145 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
94146 sizeof(*entry), 0, pc);
94147 if (!event) {
94148- atomic_inc(&dropped_count);
94149+ atomic_inc_unchecked(&dropped_count);
94150 return;
94151 }
94152 entry = ring_buffer_event_data(event);
94153diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
94154index c6977d5..d243785 100644
94155--- a/kernel/trace/trace_output.c
94156+++ b/kernel/trace/trace_output.c
94157@@ -712,14 +712,16 @@ int register_ftrace_event(struct trace_event *event)
94158 goto out;
94159 }
94160
94161+ pax_open_kernel();
94162 if (event->funcs->trace == NULL)
94163- event->funcs->trace = trace_nop_print;
94164+ *(void **)&event->funcs->trace = trace_nop_print;
94165 if (event->funcs->raw == NULL)
94166- event->funcs->raw = trace_nop_print;
94167+ *(void **)&event->funcs->raw = trace_nop_print;
94168 if (event->funcs->hex == NULL)
94169- event->funcs->hex = trace_nop_print;
94170+ *(void **)&event->funcs->hex = trace_nop_print;
94171 if (event->funcs->binary == NULL)
94172- event->funcs->binary = trace_nop_print;
94173+ *(void **)&event->funcs->binary = trace_nop_print;
94174+ pax_close_kernel();
94175
94176 key = event->type & (EVENT_HASHSIZE - 1);
94177
94178diff --git a/kernel/trace/trace_seq.c b/kernel/trace/trace_seq.c
94179index 1f24ed9..10407ec 100644
94180--- a/kernel/trace/trace_seq.c
94181+++ b/kernel/trace/trace_seq.c
94182@@ -367,7 +367,7 @@ int trace_seq_path(struct trace_seq *s, const struct path *path)
94183
94184 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
94185 if (!IS_ERR(p)) {
94186- p = mangle_path(s->buffer + s->len, p, "\n");
94187+ p = mangle_path(s->buffer + s->len, p, "\n\\");
94188 if (p) {
94189 s->len = p - s->buffer;
94190 return 1;
94191diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
94192index 16eddb3..758b308 100644
94193--- a/kernel/trace/trace_stack.c
94194+++ b/kernel/trace/trace_stack.c
94195@@ -90,7 +90,7 @@ check_stack(unsigned long ip, unsigned long *stack)
94196 return;
94197
94198 /* we do not handle interrupt stacks yet */
94199- if (!object_is_on_stack(stack))
94200+ if (!object_starts_on_stack(stack))
94201 return;
94202
94203 local_irq_save(flags);
94204diff --git a/kernel/trace/trace_syscalls.c b/kernel/trace/trace_syscalls.c
94205index 29228c4..301bc8c 100644
94206--- a/kernel/trace/trace_syscalls.c
94207+++ b/kernel/trace/trace_syscalls.c
94208@@ -602,6 +602,8 @@ static int perf_sysenter_enable(struct ftrace_event_call *call)
94209 int num;
94210
94211 num = ((struct syscall_metadata *)call->data)->syscall_nr;
94212+ if (WARN_ON_ONCE(num < 0 || num >= NR_syscalls))
94213+ return -EINVAL;
94214
94215 mutex_lock(&syscall_trace_lock);
94216 if (!sys_perf_refcount_enter)
94217@@ -622,6 +624,8 @@ static void perf_sysenter_disable(struct ftrace_event_call *call)
94218 int num;
94219
94220 num = ((struct syscall_metadata *)call->data)->syscall_nr;
94221+ if (WARN_ON_ONCE(num < 0 || num >= NR_syscalls))
94222+ return;
94223
94224 mutex_lock(&syscall_trace_lock);
94225 sys_perf_refcount_enter--;
94226@@ -674,6 +678,8 @@ static int perf_sysexit_enable(struct ftrace_event_call *call)
94227 int num;
94228
94229 num = ((struct syscall_metadata *)call->data)->syscall_nr;
94230+ if (WARN_ON_ONCE(num < 0 || num >= NR_syscalls))
94231+ return -EINVAL;
94232
94233 mutex_lock(&syscall_trace_lock);
94234 if (!sys_perf_refcount_exit)
94235@@ -694,6 +700,8 @@ static void perf_sysexit_disable(struct ftrace_event_call *call)
94236 int num;
94237
94238 num = ((struct syscall_metadata *)call->data)->syscall_nr;
94239+ if (WARN_ON_ONCE(num < 0 || num >= NR_syscalls))
94240+ return;
94241
94242 mutex_lock(&syscall_trace_lock);
94243 sys_perf_refcount_exit--;
94244diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c
94245index aa312b0..395f343 100644
94246--- a/kernel/user_namespace.c
94247+++ b/kernel/user_namespace.c
94248@@ -82,6 +82,21 @@ int create_user_ns(struct cred *new)
94249 !kgid_has_mapping(parent_ns, group))
94250 return -EPERM;
94251
94252+#ifdef CONFIG_GRKERNSEC
94253+ /*
94254+ * This doesn't really inspire confidence:
94255+ * http://marc.info/?l=linux-kernel&m=135543612731939&w=2
94256+ * http://marc.info/?l=linux-kernel&m=135545831607095&w=2
94257+ * Increases kernel attack surface in areas developers
94258+ * previously cared little about ("low importance due
94259+ * to requiring "root" capability")
94260+ * To be removed when this code receives *proper* review
94261+ */
94262+ if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SETUID) ||
94263+ !capable(CAP_SETGID))
94264+ return -EPERM;
94265+#endif
94266+
94267 ns = kmem_cache_zalloc(user_ns_cachep, GFP_KERNEL);
94268 if (!ns)
94269 return -ENOMEM;
94270@@ -872,7 +887,7 @@ static int userns_install(struct nsproxy *nsproxy, void *ns)
94271 if (atomic_read(&current->mm->mm_users) > 1)
94272 return -EINVAL;
94273
94274- if (current->fs->users != 1)
94275+ if (atomic_read(&current->fs->users) != 1)
94276 return -EINVAL;
94277
94278 if (!ns_capable(user_ns, CAP_SYS_ADMIN))
94279diff --git a/kernel/utsname_sysctl.c b/kernel/utsname_sysctl.c
94280index c8eac43..4b5f08f 100644
94281--- a/kernel/utsname_sysctl.c
94282+++ b/kernel/utsname_sysctl.c
94283@@ -47,7 +47,7 @@ static void put_uts(struct ctl_table *table, int write, void *which)
94284 static int proc_do_uts_string(struct ctl_table *table, int write,
94285 void __user *buffer, size_t *lenp, loff_t *ppos)
94286 {
94287- struct ctl_table uts_table;
94288+ ctl_table_no_const uts_table;
94289 int r;
94290 memcpy(&uts_table, table, sizeof(uts_table));
94291 uts_table.data = get_uts(table, write);
94292diff --git a/kernel/watchdog.c b/kernel/watchdog.c
94293index 70bf118..4be3c37 100644
94294--- a/kernel/watchdog.c
94295+++ b/kernel/watchdog.c
94296@@ -572,7 +572,7 @@ static int watchdog_nmi_enable(unsigned int cpu) { return 0; }
94297 static void watchdog_nmi_disable(unsigned int cpu) { return; }
94298 #endif /* CONFIG_HARDLOCKUP_DETECTOR */
94299
94300-static struct smp_hotplug_thread watchdog_threads = {
94301+static struct smp_hotplug_thread watchdog_threads __read_only = {
94302 .store = &softlockup_watchdog,
94303 .thread_should_run = watchdog_should_run,
94304 .thread_fn = watchdog,
94305diff --git a/kernel/workqueue.c b/kernel/workqueue.c
94306index 09b685d..d3565e3 100644
94307--- a/kernel/workqueue.c
94308+++ b/kernel/workqueue.c
94309@@ -4508,7 +4508,7 @@ static void rebind_workers(struct worker_pool *pool)
94310 WARN_ON_ONCE(!(worker_flags & WORKER_UNBOUND));
94311 worker_flags |= WORKER_REBOUND;
94312 worker_flags &= ~WORKER_UNBOUND;
94313- ACCESS_ONCE(worker->flags) = worker_flags;
94314+ ACCESS_ONCE_RW(worker->flags) = worker_flags;
94315 }
94316
94317 spin_unlock_irq(&pool->lock);
94318diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
94319index 4e35a5d..8a1f3f0 100644
94320--- a/lib/Kconfig.debug
94321+++ b/lib/Kconfig.debug
94322@@ -894,7 +894,7 @@ config DEBUG_MUTEXES
94323
94324 config DEBUG_WW_MUTEX_SLOWPATH
94325 bool "Wait/wound mutex debugging: Slowpath testing"
94326- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
94327+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
94328 select DEBUG_LOCK_ALLOC
94329 select DEBUG_SPINLOCK
94330 select DEBUG_MUTEXES
94331@@ -911,7 +911,7 @@ config DEBUG_WW_MUTEX_SLOWPATH
94332
94333 config DEBUG_LOCK_ALLOC
94334 bool "Lock debugging: detect incorrect freeing of live locks"
94335- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
94336+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
94337 select DEBUG_SPINLOCK
94338 select DEBUG_MUTEXES
94339 select LOCKDEP
94340@@ -925,7 +925,7 @@ config DEBUG_LOCK_ALLOC
94341
94342 config PROVE_LOCKING
94343 bool "Lock debugging: prove locking correctness"
94344- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
94345+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
94346 select LOCKDEP
94347 select DEBUG_SPINLOCK
94348 select DEBUG_MUTEXES
94349@@ -976,7 +976,7 @@ config LOCKDEP
94350
94351 config LOCK_STAT
94352 bool "Lock usage statistics"
94353- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
94354+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
94355 select LOCKDEP
94356 select DEBUG_SPINLOCK
94357 select DEBUG_MUTEXES
94358@@ -1449,6 +1449,7 @@ config LATENCYTOP
94359 depends on DEBUG_KERNEL
94360 depends on STACKTRACE_SUPPORT
94361 depends on PROC_FS
94362+ depends on !GRKERNSEC_HIDESYM
94363 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND && !ARC
94364 select KALLSYMS
94365 select KALLSYMS_ALL
94366@@ -1465,7 +1466,7 @@ config ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
94367 config DEBUG_STRICT_USER_COPY_CHECKS
94368 bool "Strict user copy size checks"
94369 depends on ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
94370- depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING
94371+ depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING && !PAX_SIZE_OVERFLOW
94372 help
94373 Enabling this option turns a certain set of sanity checks for user
94374 copy operations into compile time failures.
94375@@ -1593,7 +1594,7 @@ endmenu # runtime tests
94376
94377 config PROVIDE_OHCI1394_DMA_INIT
94378 bool "Remote debugging over FireWire early on boot"
94379- depends on PCI && X86
94380+ depends on PCI && X86 && !GRKERNSEC
94381 help
94382 If you want to debug problems which hang or crash the kernel early
94383 on boot and the crashing machine has a FireWire port, you can use
94384diff --git a/lib/Makefile b/lib/Makefile
94385index 0211d2b..93f5cc3 100644
94386--- a/lib/Makefile
94387+++ b/lib/Makefile
94388@@ -55,7 +55,7 @@ obj-$(CONFIG_BTREE) += btree.o
94389 obj-$(CONFIG_INTERVAL_TREE) += interval_tree.o
94390 obj-$(CONFIG_ASSOCIATIVE_ARRAY) += assoc_array.o
94391 obj-$(CONFIG_DEBUG_PREEMPT) += smp_processor_id.o
94392-obj-$(CONFIG_DEBUG_LIST) += list_debug.o
94393+obj-y += list_debug.o
94394 obj-$(CONFIG_DEBUG_OBJECTS) += debugobjects.o
94395
94396 ifneq ($(CONFIG_HAVE_DEC_LOCK),y)
94397diff --git a/lib/average.c b/lib/average.c
94398index 114d1be..ab0350c 100644
94399--- a/lib/average.c
94400+++ b/lib/average.c
94401@@ -55,7 +55,7 @@ struct ewma *ewma_add(struct ewma *avg, unsigned long val)
94402 {
94403 unsigned long internal = ACCESS_ONCE(avg->internal);
94404
94405- ACCESS_ONCE(avg->internal) = internal ?
94406+ ACCESS_ONCE_RW(avg->internal) = internal ?
94407 (((internal << avg->weight) - internal) +
94408 (val << avg->factor)) >> avg->weight :
94409 (val << avg->factor);
94410diff --git a/lib/bitmap.c b/lib/bitmap.c
94411index b499ab6..fbdb76c 100644
94412--- a/lib/bitmap.c
94413+++ b/lib/bitmap.c
94414@@ -433,7 +433,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
94415 {
94416 int c, old_c, totaldigits, ndigits, nchunks, nbits;
94417 u32 chunk;
94418- const char __user __force *ubuf = (const char __user __force *)buf;
94419+ const char __user *ubuf = (const char __force_user *)buf;
94420
94421 bitmap_zero(maskp, nmaskbits);
94422
94423@@ -518,7 +518,7 @@ int bitmap_parse_user(const char __user *ubuf,
94424 {
94425 if (!access_ok(VERIFY_READ, ubuf, ulen))
94426 return -EFAULT;
94427- return __bitmap_parse((const char __force *)ubuf,
94428+ return __bitmap_parse((const char __force_kernel *)ubuf,
94429 ulen, 1, maskp, nmaskbits);
94430
94431 }
94432@@ -609,7 +609,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
94433 {
94434 unsigned a, b;
94435 int c, old_c, totaldigits;
94436- const char __user __force *ubuf = (const char __user __force *)buf;
94437+ const char __user *ubuf = (const char __force_user *)buf;
94438 int exp_digit, in_range;
94439
94440 totaldigits = c = 0;
94441@@ -704,7 +704,7 @@ int bitmap_parselist_user(const char __user *ubuf,
94442 {
94443 if (!access_ok(VERIFY_READ, ubuf, ulen))
94444 return -EFAULT;
94445- return __bitmap_parselist((const char __force *)ubuf,
94446+ return __bitmap_parselist((const char __force_kernel *)ubuf,
94447 ulen, 1, maskp, nmaskbits);
94448 }
94449 EXPORT_SYMBOL(bitmap_parselist_user);
94450diff --git a/lib/bug.c b/lib/bug.c
94451index d1d7c78..b354235 100644
94452--- a/lib/bug.c
94453+++ b/lib/bug.c
94454@@ -137,6 +137,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
94455 return BUG_TRAP_TYPE_NONE;
94456
94457 bug = find_bug(bugaddr);
94458+ if (!bug)
94459+ return BUG_TRAP_TYPE_NONE;
94460
94461 file = NULL;
94462 line = 0;
94463diff --git a/lib/debugobjects.c b/lib/debugobjects.c
94464index 547f7f9..a6d4ba0 100644
94465--- a/lib/debugobjects.c
94466+++ b/lib/debugobjects.c
94467@@ -289,7 +289,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
94468 if (limit > 4)
94469 return;
94470
94471- is_on_stack = object_is_on_stack(addr);
94472+ is_on_stack = object_starts_on_stack(addr);
94473 if (is_on_stack == onstack)
94474 return;
94475
94476diff --git a/lib/div64.c b/lib/div64.c
94477index 4382ad7..08aa558 100644
94478--- a/lib/div64.c
94479+++ b/lib/div64.c
94480@@ -59,7 +59,7 @@ uint32_t __attribute__((weak)) __div64_32(uint64_t *n, uint32_t base)
94481 EXPORT_SYMBOL(__div64_32);
94482
94483 #ifndef div_s64_rem
94484-s64 div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
94485+s64 __intentional_overflow(-1) div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
94486 {
94487 u64 quotient;
94488
94489@@ -130,7 +130,7 @@ EXPORT_SYMBOL(div64_u64_rem);
94490 * 'http://www.hackersdelight.org/HDcode/newCode/divDouble.c.txt'
94491 */
94492 #ifndef div64_u64
94493-u64 div64_u64(u64 dividend, u64 divisor)
94494+u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor)
94495 {
94496 u32 high = divisor >> 32;
94497 u64 quot;
94498diff --git a/lib/dma-debug.c b/lib/dma-debug.c
94499index add80cc..0d27550 100644
94500--- a/lib/dma-debug.c
94501+++ b/lib/dma-debug.c
94502@@ -971,7 +971,7 @@ static int dma_debug_device_change(struct notifier_block *nb, unsigned long acti
94503
94504 void dma_debug_add_bus(struct bus_type *bus)
94505 {
94506- struct notifier_block *nb;
94507+ notifier_block_no_const *nb;
94508
94509 if (global_disable)
94510 return;
94511@@ -1148,7 +1148,7 @@ static void check_unmap(struct dma_debug_entry *ref)
94512
94513 static void check_for_stack(struct device *dev, void *addr)
94514 {
94515- if (object_is_on_stack(addr))
94516+ if (object_starts_on_stack(addr))
94517 err_printk(dev, NULL, "DMA-API: device driver maps memory from "
94518 "stack [addr=%p]\n", addr);
94519 }
94520diff --git a/lib/hash.c b/lib/hash.c
94521index fea973f..386626f 100644
94522--- a/lib/hash.c
94523+++ b/lib/hash.c
94524@@ -14,7 +14,7 @@
94525 #include <linux/hash.h>
94526 #include <linux/cache.h>
94527
94528-static struct fast_hash_ops arch_hash_ops __read_mostly = {
94529+static struct fast_hash_ops arch_hash_ops __read_only = {
94530 .hash = jhash,
94531 .hash2 = jhash2,
94532 };
94533diff --git a/lib/inflate.c b/lib/inflate.c
94534index 013a761..c28f3fc 100644
94535--- a/lib/inflate.c
94536+++ b/lib/inflate.c
94537@@ -269,7 +269,7 @@ static void free(void *where)
94538 malloc_ptr = free_mem_ptr;
94539 }
94540 #else
94541-#define malloc(a) kmalloc(a, GFP_KERNEL)
94542+#define malloc(a) kmalloc((a), GFP_KERNEL)
94543 #define free(a) kfree(a)
94544 #endif
94545
94546diff --git a/lib/ioremap.c b/lib/ioremap.c
94547index 0c9216c..863bd89 100644
94548--- a/lib/ioremap.c
94549+++ b/lib/ioremap.c
94550@@ -38,7 +38,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
94551 unsigned long next;
94552
94553 phys_addr -= addr;
94554- pmd = pmd_alloc(&init_mm, pud, addr);
94555+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
94556 if (!pmd)
94557 return -ENOMEM;
94558 do {
94559@@ -56,7 +56,7 @@ static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
94560 unsigned long next;
94561
94562 phys_addr -= addr;
94563- pud = pud_alloc(&init_mm, pgd, addr);
94564+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
94565 if (!pud)
94566 return -ENOMEM;
94567 do {
94568diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
94569index bd2bea9..6b3c95e 100644
94570--- a/lib/is_single_threaded.c
94571+++ b/lib/is_single_threaded.c
94572@@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
94573 struct task_struct *p, *t;
94574 bool ret;
94575
94576+ if (!mm)
94577+ return true;
94578+
94579 if (atomic_read(&task->signal->live) != 1)
94580 return false;
94581
94582diff --git a/lib/kobject.c b/lib/kobject.c
94583index 58751bb..93a1853 100644
94584--- a/lib/kobject.c
94585+++ b/lib/kobject.c
94586@@ -931,9 +931,9 @@ EXPORT_SYMBOL_GPL(kset_create_and_add);
94587
94588
94589 static DEFINE_SPINLOCK(kobj_ns_type_lock);
94590-static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES];
94591+static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES] __read_only;
94592
94593-int kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
94594+int __init kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
94595 {
94596 enum kobj_ns_type type = ops->type;
94597 int error;
94598diff --git a/lib/list_debug.c b/lib/list_debug.c
94599index c24c2f7..f0296f4 100644
94600--- a/lib/list_debug.c
94601+++ b/lib/list_debug.c
94602@@ -11,7 +11,9 @@
94603 #include <linux/bug.h>
94604 #include <linux/kernel.h>
94605 #include <linux/rculist.h>
94606+#include <linux/mm.h>
94607
94608+#ifdef CONFIG_DEBUG_LIST
94609 /*
94610 * Insert a new entry between two known consecutive entries.
94611 *
94612@@ -19,21 +21,40 @@
94613 * the prev/next entries already!
94614 */
94615
94616+static bool __list_add_debug(struct list_head *new,
94617+ struct list_head *prev,
94618+ struct list_head *next)
94619+{
94620+ if (unlikely(next->prev != prev)) {
94621+ printk(KERN_ERR "list_add corruption. next->prev should be "
94622+ "prev (%p), but was %p. (next=%p).\n",
94623+ prev, next->prev, next);
94624+ BUG();
94625+ return false;
94626+ }
94627+ if (unlikely(prev->next != next)) {
94628+ printk(KERN_ERR "list_add corruption. prev->next should be "
94629+ "next (%p), but was %p. (prev=%p).\n",
94630+ next, prev->next, prev);
94631+ BUG();
94632+ return false;
94633+ }
94634+ if (unlikely(new == prev || new == next)) {
94635+ printk(KERN_ERR "list_add double add: new=%p, prev=%p, next=%p.\n",
94636+ new, prev, next);
94637+ BUG();
94638+ return false;
94639+ }
94640+ return true;
94641+}
94642+
94643 void __list_add(struct list_head *new,
94644- struct list_head *prev,
94645- struct list_head *next)
94646+ struct list_head *prev,
94647+ struct list_head *next)
94648 {
94649- WARN(next->prev != prev,
94650- "list_add corruption. next->prev should be "
94651- "prev (%p), but was %p. (next=%p).\n",
94652- prev, next->prev, next);
94653- WARN(prev->next != next,
94654- "list_add corruption. prev->next should be "
94655- "next (%p), but was %p. (prev=%p).\n",
94656- next, prev->next, prev);
94657- WARN(new == prev || new == next,
94658- "list_add double add: new=%p, prev=%p, next=%p.\n",
94659- new, prev, next);
94660+ if (!__list_add_debug(new, prev, next))
94661+ return;
94662+
94663 next->prev = new;
94664 new->next = next;
94665 new->prev = prev;
94666@@ -41,28 +62,46 @@ void __list_add(struct list_head *new,
94667 }
94668 EXPORT_SYMBOL(__list_add);
94669
94670-void __list_del_entry(struct list_head *entry)
94671+static bool __list_del_entry_debug(struct list_head *entry)
94672 {
94673 struct list_head *prev, *next;
94674
94675 prev = entry->prev;
94676 next = entry->next;
94677
94678- if (WARN(next == LIST_POISON1,
94679- "list_del corruption, %p->next is LIST_POISON1 (%p)\n",
94680- entry, LIST_POISON1) ||
94681- WARN(prev == LIST_POISON2,
94682- "list_del corruption, %p->prev is LIST_POISON2 (%p)\n",
94683- entry, LIST_POISON2) ||
94684- WARN(prev->next != entry,
94685- "list_del corruption. prev->next should be %p, "
94686- "but was %p\n", entry, prev->next) ||
94687- WARN(next->prev != entry,
94688- "list_del corruption. next->prev should be %p, "
94689- "but was %p\n", entry, next->prev))
94690+ if (unlikely(next == LIST_POISON1)) {
94691+ printk(KERN_ERR "list_del corruption, %p->next is LIST_POISON1 (%p)\n",
94692+ entry, LIST_POISON1);
94693+ BUG();
94694+ return false;
94695+ }
94696+ if (unlikely(prev == LIST_POISON2)) {
94697+ printk(KERN_ERR "list_del corruption, %p->prev is LIST_POISON2 (%p)\n",
94698+ entry, LIST_POISON2);
94699+ BUG();
94700+ return false;
94701+ }
94702+ if (unlikely(entry->prev->next != entry)) {
94703+ printk(KERN_ERR "list_del corruption. prev->next should be %p, "
94704+ "but was %p\n", entry, prev->next);
94705+ BUG();
94706+ return false;
94707+ }
94708+ if (unlikely(entry->next->prev != entry)) {
94709+ printk(KERN_ERR "list_del corruption. next->prev should be %p, "
94710+ "but was %p\n", entry, next->prev);
94711+ BUG();
94712+ return false;
94713+ }
94714+ return true;
94715+}
94716+
94717+void __list_del_entry(struct list_head *entry)
94718+{
94719+ if (!__list_del_entry_debug(entry))
94720 return;
94721
94722- __list_del(prev, next);
94723+ __list_del(entry->prev, entry->next);
94724 }
94725 EXPORT_SYMBOL(__list_del_entry);
94726
94727@@ -86,15 +125,85 @@ EXPORT_SYMBOL(list_del);
94728 void __list_add_rcu(struct list_head *new,
94729 struct list_head *prev, struct list_head *next)
94730 {
94731- WARN(next->prev != prev,
94732- "list_add_rcu corruption. next->prev should be prev (%p), but was %p. (next=%p).\n",
94733- prev, next->prev, next);
94734- WARN(prev->next != next,
94735- "list_add_rcu corruption. prev->next should be next (%p), but was %p. (prev=%p).\n",
94736- next, prev->next, prev);
94737+ if (!__list_add_debug(new, prev, next))
94738+ return;
94739+
94740 new->next = next;
94741 new->prev = prev;
94742 rcu_assign_pointer(list_next_rcu(prev), new);
94743 next->prev = new;
94744 }
94745 EXPORT_SYMBOL(__list_add_rcu);
94746+#endif
94747+
94748+void __pax_list_add(struct list_head *new, struct list_head *prev, struct list_head *next)
94749+{
94750+#ifdef CONFIG_DEBUG_LIST
94751+ if (!__list_add_debug(new, prev, next))
94752+ return;
94753+#endif
94754+
94755+ pax_open_kernel();
94756+ next->prev = new;
94757+ new->next = next;
94758+ new->prev = prev;
94759+ prev->next = new;
94760+ pax_close_kernel();
94761+}
94762+EXPORT_SYMBOL(__pax_list_add);
94763+
94764+void pax_list_del(struct list_head *entry)
94765+{
94766+#ifdef CONFIG_DEBUG_LIST
94767+ if (!__list_del_entry_debug(entry))
94768+ return;
94769+#endif
94770+
94771+ pax_open_kernel();
94772+ __list_del(entry->prev, entry->next);
94773+ entry->next = LIST_POISON1;
94774+ entry->prev = LIST_POISON2;
94775+ pax_close_kernel();
94776+}
94777+EXPORT_SYMBOL(pax_list_del);
94778+
94779+void pax_list_del_init(struct list_head *entry)
94780+{
94781+ pax_open_kernel();
94782+ __list_del(entry->prev, entry->next);
94783+ INIT_LIST_HEAD(entry);
94784+ pax_close_kernel();
94785+}
94786+EXPORT_SYMBOL(pax_list_del_init);
94787+
94788+void __pax_list_add_rcu(struct list_head *new,
94789+ struct list_head *prev, struct list_head *next)
94790+{
94791+#ifdef CONFIG_DEBUG_LIST
94792+ if (!__list_add_debug(new, prev, next))
94793+ return;
94794+#endif
94795+
94796+ pax_open_kernel();
94797+ new->next = next;
94798+ new->prev = prev;
94799+ rcu_assign_pointer(list_next_rcu(prev), new);
94800+ next->prev = new;
94801+ pax_close_kernel();
94802+}
94803+EXPORT_SYMBOL(__pax_list_add_rcu);
94804+
94805+void pax_list_del_rcu(struct list_head *entry)
94806+{
94807+#ifdef CONFIG_DEBUG_LIST
94808+ if (!__list_del_entry_debug(entry))
94809+ return;
94810+#endif
94811+
94812+ pax_open_kernel();
94813+ __list_del(entry->prev, entry->next);
94814+ entry->next = LIST_POISON1;
94815+ entry->prev = LIST_POISON2;
94816+ pax_close_kernel();
94817+}
94818+EXPORT_SYMBOL(pax_list_del_rcu);
94819diff --git a/lib/lockref.c b/lib/lockref.c
94820index d2233de..fa1a2f6 100644
94821--- a/lib/lockref.c
94822+++ b/lib/lockref.c
94823@@ -48,13 +48,13 @@
94824 void lockref_get(struct lockref *lockref)
94825 {
94826 CMPXCHG_LOOP(
94827- new.count++;
94828+ __lockref_inc(&new);
94829 ,
94830 return;
94831 );
94832
94833 spin_lock(&lockref->lock);
94834- lockref->count++;
94835+ __lockref_inc(lockref);
94836 spin_unlock(&lockref->lock);
94837 }
94838 EXPORT_SYMBOL(lockref_get);
94839@@ -69,7 +69,7 @@ int lockref_get_not_zero(struct lockref *lockref)
94840 int retval;
94841
94842 CMPXCHG_LOOP(
94843- new.count++;
94844+ __lockref_inc(&new);
94845 if (!old.count)
94846 return 0;
94847 ,
94848@@ -79,7 +79,7 @@ int lockref_get_not_zero(struct lockref *lockref)
94849 spin_lock(&lockref->lock);
94850 retval = 0;
94851 if (lockref->count) {
94852- lockref->count++;
94853+ __lockref_inc(lockref);
94854 retval = 1;
94855 }
94856 spin_unlock(&lockref->lock);
94857@@ -96,7 +96,7 @@ EXPORT_SYMBOL(lockref_get_not_zero);
94858 int lockref_get_or_lock(struct lockref *lockref)
94859 {
94860 CMPXCHG_LOOP(
94861- new.count++;
94862+ __lockref_inc(&new);
94863 if (!old.count)
94864 break;
94865 ,
94866@@ -106,7 +106,7 @@ int lockref_get_or_lock(struct lockref *lockref)
94867 spin_lock(&lockref->lock);
94868 if (!lockref->count)
94869 return 0;
94870- lockref->count++;
94871+ __lockref_inc(lockref);
94872 spin_unlock(&lockref->lock);
94873 return 1;
94874 }
94875@@ -120,7 +120,7 @@ EXPORT_SYMBOL(lockref_get_or_lock);
94876 int lockref_put_or_lock(struct lockref *lockref)
94877 {
94878 CMPXCHG_LOOP(
94879- new.count--;
94880+ __lockref_dec(&new);
94881 if (old.count <= 1)
94882 break;
94883 ,
94884@@ -130,7 +130,7 @@ int lockref_put_or_lock(struct lockref *lockref)
94885 spin_lock(&lockref->lock);
94886 if (lockref->count <= 1)
94887 return 0;
94888- lockref->count--;
94889+ __lockref_dec(lockref);
94890 spin_unlock(&lockref->lock);
94891 return 1;
94892 }
94893@@ -157,7 +157,7 @@ int lockref_get_not_dead(struct lockref *lockref)
94894 int retval;
94895
94896 CMPXCHG_LOOP(
94897- new.count++;
94898+ __lockref_inc(&new);
94899 if ((int)old.count < 0)
94900 return 0;
94901 ,
94902@@ -167,7 +167,7 @@ int lockref_get_not_dead(struct lockref *lockref)
94903 spin_lock(&lockref->lock);
94904 retval = 0;
94905 if ((int) lockref->count >= 0) {
94906- lockref->count++;
94907+ __lockref_inc(lockref);
94908 retval = 1;
94909 }
94910 spin_unlock(&lockref->lock);
94911diff --git a/lib/percpu-refcount.c b/lib/percpu-refcount.c
94912index 6111bcb..02e816b 100644
94913--- a/lib/percpu-refcount.c
94914+++ b/lib/percpu-refcount.c
94915@@ -31,7 +31,7 @@
94916 * atomic_long_t can't hit 0 before we've added up all the percpu refs.
94917 */
94918
94919-#define PERCPU_COUNT_BIAS (1LU << (BITS_PER_LONG - 1))
94920+#define PERCPU_COUNT_BIAS (1LU << (BITS_PER_LONG - 2))
94921
94922 static DECLARE_WAIT_QUEUE_HEAD(percpu_ref_switch_waitq);
94923
94924diff --git a/lib/radix-tree.c b/lib/radix-tree.c
94925index 3291a8e..346a91e 100644
94926--- a/lib/radix-tree.c
94927+++ b/lib/radix-tree.c
94928@@ -67,7 +67,7 @@ struct radix_tree_preload {
94929 int nr;
94930 struct radix_tree_node *nodes[RADIX_TREE_PRELOAD_SIZE];
94931 };
94932-static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
94933+static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
94934
94935 static inline void *ptr_to_indirect(void *ptr)
94936 {
94937diff --git a/lib/random32.c b/lib/random32.c
94938index 0bee183..526f12f 100644
94939--- a/lib/random32.c
94940+++ b/lib/random32.c
94941@@ -47,7 +47,7 @@ static inline void prandom_state_selftest(void)
94942 }
94943 #endif
94944
94945-static DEFINE_PER_CPU(struct rnd_state, net_rand_state);
94946+static DEFINE_PER_CPU(struct rnd_state, net_rand_state) __latent_entropy;
94947
94948 /**
94949 * prandom_u32_state - seeded pseudo-random number generator.
94950diff --git a/lib/rbtree.c b/lib/rbtree.c
94951index c16c81a..4dcbda1 100644
94952--- a/lib/rbtree.c
94953+++ b/lib/rbtree.c
94954@@ -380,7 +380,9 @@ static inline void dummy_copy(struct rb_node *old, struct rb_node *new) {}
94955 static inline void dummy_rotate(struct rb_node *old, struct rb_node *new) {}
94956
94957 static const struct rb_augment_callbacks dummy_callbacks = {
94958- dummy_propagate, dummy_copy, dummy_rotate
94959+ .propagate = dummy_propagate,
94960+ .copy = dummy_copy,
94961+ .rotate = dummy_rotate
94962 };
94963
94964 void rb_insert_color(struct rb_node *node, struct rb_root *root)
94965diff --git a/lib/show_mem.c b/lib/show_mem.c
94966index 5e25627..3ed9d7f 100644
94967--- a/lib/show_mem.c
94968+++ b/lib/show_mem.c
94969@@ -44,6 +44,6 @@ void show_mem(unsigned int filter)
94970 quicklist_total_size());
94971 #endif
94972 #ifdef CONFIG_MEMORY_FAILURE
94973- printk("%lu pages hwpoisoned\n", atomic_long_read(&num_poisoned_pages));
94974+ printk("%lu pages hwpoisoned\n", atomic_long_read_unchecked(&num_poisoned_pages));
94975 #endif
94976 }
94977diff --git a/lib/strncpy_from_user.c b/lib/strncpy_from_user.c
94978index bb2b201..46abaf9 100644
94979--- a/lib/strncpy_from_user.c
94980+++ b/lib/strncpy_from_user.c
94981@@ -21,7 +21,7 @@
94982 */
94983 static inline long do_strncpy_from_user(char *dst, const char __user *src, long count, unsigned long max)
94984 {
94985- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
94986+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
94987 long res = 0;
94988
94989 /*
94990diff --git a/lib/strnlen_user.c b/lib/strnlen_user.c
94991index a28df52..3d55877 100644
94992--- a/lib/strnlen_user.c
94993+++ b/lib/strnlen_user.c
94994@@ -26,7 +26,7 @@
94995 */
94996 static inline long do_strnlen_user(const char __user *src, unsigned long count, unsigned long max)
94997 {
94998- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
94999+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
95000 long align, res = 0;
95001 unsigned long c;
95002
95003diff --git a/lib/swiotlb.c b/lib/swiotlb.c
95004index 4abda07..b9d3765 100644
95005--- a/lib/swiotlb.c
95006+++ b/lib/swiotlb.c
95007@@ -682,7 +682,7 @@ EXPORT_SYMBOL(swiotlb_alloc_coherent);
95008
95009 void
95010 swiotlb_free_coherent(struct device *hwdev, size_t size, void *vaddr,
95011- dma_addr_t dev_addr)
95012+ dma_addr_t dev_addr, struct dma_attrs *attrs)
95013 {
95014 phys_addr_t paddr = dma_to_phys(hwdev, dev_addr);
95015
95016diff --git a/lib/usercopy.c b/lib/usercopy.c
95017index 4f5b1dd..7cab418 100644
95018--- a/lib/usercopy.c
95019+++ b/lib/usercopy.c
95020@@ -7,3 +7,9 @@ void copy_from_user_overflow(void)
95021 WARN(1, "Buffer overflow detected!\n");
95022 }
95023 EXPORT_SYMBOL(copy_from_user_overflow);
95024+
95025+void copy_to_user_overflow(void)
95026+{
95027+ WARN(1, "Buffer overflow detected!\n");
95028+}
95029+EXPORT_SYMBOL(copy_to_user_overflow);
95030diff --git a/lib/vsprintf.c b/lib/vsprintf.c
95031index ec337f6..8484eb2 100644
95032--- a/lib/vsprintf.c
95033+++ b/lib/vsprintf.c
95034@@ -16,6 +16,9 @@
95035 * - scnprintf and vscnprintf
95036 */
95037
95038+#ifdef CONFIG_GRKERNSEC_HIDESYM
95039+#define __INCLUDED_BY_HIDESYM 1
95040+#endif
95041 #include <stdarg.h>
95042 #include <linux/module.h> /* for KSYM_SYMBOL_LEN */
95043 #include <linux/types.h>
95044@@ -625,7 +628,7 @@ char *symbol_string(char *buf, char *end, void *ptr,
95045 #ifdef CONFIG_KALLSYMS
95046 if (*fmt == 'B')
95047 sprint_backtrace(sym, value);
95048- else if (*fmt != 'f' && *fmt != 's')
95049+ else if (*fmt != 'f' && *fmt != 's' && *fmt != 'X')
95050 sprint_symbol(sym, value);
95051 else
95052 sprint_symbol_no_offset(sym, value);
95053@@ -1240,7 +1243,11 @@ char *address_val(char *buf, char *end, const void *addr,
95054 return number(buf, end, num, spec);
95055 }
95056
95057+#ifdef CONFIG_GRKERNSEC_HIDESYM
95058+int kptr_restrict __read_mostly = 2;
95059+#else
95060 int kptr_restrict __read_mostly;
95061+#endif
95062
95063 /*
95064 * Show a '%p' thing. A kernel extension is that the '%p' is followed
95065@@ -1251,8 +1258,10 @@ int kptr_restrict __read_mostly;
95066 *
95067 * - 'F' For symbolic function descriptor pointers with offset
95068 * - 'f' For simple symbolic function names without offset
95069+ * - 'X' For simple symbolic function names without offset approved for use with GRKERNSEC_HIDESYM
95070 * - 'S' For symbolic direct pointers with offset
95071 * - 's' For symbolic direct pointers without offset
95072+ * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
95073 * - '[FfSs]R' as above with __builtin_extract_return_addr() translation
95074 * - 'B' For backtraced symbolic direct pointers with offset
95075 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
95076@@ -1331,12 +1340,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
95077
95078 if (!ptr && *fmt != 'K') {
95079 /*
95080- * Print (null) with the same width as a pointer so it makes
95081+ * Print (nil) with the same width as a pointer so it makes
95082 * tabular output look nice.
95083 */
95084 if (spec.field_width == -1)
95085 spec.field_width = default_width;
95086- return string(buf, end, "(null)", spec);
95087+ return string(buf, end, "(nil)", spec);
95088 }
95089
95090 switch (*fmt) {
95091@@ -1346,6 +1355,14 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
95092 /* Fallthrough */
95093 case 'S':
95094 case 's':
95095+#ifdef CONFIG_GRKERNSEC_HIDESYM
95096+ break;
95097+#else
95098+ return symbol_string(buf, end, ptr, spec, fmt);
95099+#endif
95100+ case 'X':
95101+ ptr = dereference_function_descriptor(ptr);
95102+ case 'A':
95103 case 'B':
95104 return symbol_string(buf, end, ptr, spec, fmt);
95105 case 'R':
95106@@ -1403,6 +1420,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
95107 va_end(va);
95108 return buf;
95109 }
95110+ case 'P':
95111+ break;
95112 case 'K':
95113 /*
95114 * %pK cannot be used in IRQ context because its test
95115@@ -1460,6 +1479,22 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
95116 ((const struct file *)ptr)->f_path.dentry,
95117 spec, fmt);
95118 }
95119+
95120+#ifdef CONFIG_GRKERNSEC_HIDESYM
95121+ /* 'P' = approved pointers to copy to userland,
95122+ as in the /proc/kallsyms case, as we make it display nothing
95123+ for non-root users, and the real contents for root users
95124+ 'X' = approved simple symbols
95125+ Also ignore 'K' pointers, since we force their NULLing for non-root users
95126+ above
95127+ */
95128+ if ((unsigned long)ptr > TASK_SIZE && *fmt != 'P' && *fmt != 'X' && *fmt != 'K' && is_usercopy_object(buf)) {
95129+ printk(KERN_ALERT "grsec: kernel infoleak detected! Please report this log to spender@grsecurity.net.\n");
95130+ dump_stack();
95131+ ptr = NULL;
95132+ }
95133+#endif
95134+
95135 spec.flags |= SMALL;
95136 if (spec.field_width == -1) {
95137 spec.field_width = default_width;
95138@@ -2160,11 +2195,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
95139 typeof(type) value; \
95140 if (sizeof(type) == 8) { \
95141 args = PTR_ALIGN(args, sizeof(u32)); \
95142- *(u32 *)&value = *(u32 *)args; \
95143- *((u32 *)&value + 1) = *(u32 *)(args + 4); \
95144+ *(u32 *)&value = *(const u32 *)args; \
95145+ *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
95146 } else { \
95147 args = PTR_ALIGN(args, sizeof(type)); \
95148- value = *(typeof(type) *)args; \
95149+ value = *(const typeof(type) *)args; \
95150 } \
95151 args += sizeof(type); \
95152 value; \
95153@@ -2227,7 +2262,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
95154 case FORMAT_TYPE_STR: {
95155 const char *str_arg = args;
95156 args += strlen(str_arg) + 1;
95157- str = string(str, end, (char *)str_arg, spec);
95158+ str = string(str, end, str_arg, spec);
95159 break;
95160 }
95161
95162diff --git a/localversion-grsec b/localversion-grsec
95163new file mode 100644
95164index 0000000..7cd6065
95165--- /dev/null
95166+++ b/localversion-grsec
95167@@ -0,0 +1 @@
95168+-grsec
95169diff --git a/mm/Kconfig b/mm/Kconfig
95170index 1d1ae6b..0f05885 100644
95171--- a/mm/Kconfig
95172+++ b/mm/Kconfig
95173@@ -341,10 +341,11 @@ config KSM
95174 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
95175
95176 config DEFAULT_MMAP_MIN_ADDR
95177- int "Low address space to protect from user allocation"
95178+ int "Low address space to protect from user allocation"
95179 depends on MMU
95180- default 4096
95181- help
95182+ default 32768 if ALPHA || ARM || PARISC || SPARC32
95183+ default 65536
95184+ help
95185 This is the portion of low virtual memory which should be protected
95186 from userspace allocation. Keeping a user from writing to low pages
95187 can help reduce the impact of kernel NULL pointer bugs.
95188@@ -375,7 +376,7 @@ config MEMORY_FAILURE
95189
95190 config HWPOISON_INJECT
95191 tristate "HWPoison pages injector"
95192- depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS
95193+ depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS && !GRKERNSEC
95194 select PROC_PAGE_MONITOR
95195
95196 config NOMMU_INITIAL_TRIM_EXCESS
95197diff --git a/mm/backing-dev.c b/mm/backing-dev.c
95198index 0ae0df5..82ac56b 100644
95199--- a/mm/backing-dev.c
95200+++ b/mm/backing-dev.c
95201@@ -12,7 +12,7 @@
95202 #include <linux/device.h>
95203 #include <trace/events/writeback.h>
95204
95205-static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
95206+static atomic_long_unchecked_t bdi_seq = ATOMIC_LONG_INIT(0);
95207
95208 struct backing_dev_info default_backing_dev_info = {
95209 .name = "default",
95210@@ -525,7 +525,7 @@ int bdi_setup_and_register(struct backing_dev_info *bdi, char *name,
95211 return err;
95212
95213 err = bdi_register(bdi, NULL, "%.28s-%ld", name,
95214- atomic_long_inc_return(&bdi_seq));
95215+ atomic_long_inc_return_unchecked(&bdi_seq));
95216 if (err) {
95217 bdi_destroy(bdi);
95218 return err;
95219diff --git a/mm/filemap.c b/mm/filemap.c
95220index 14b4642..d71ba82 100644
95221--- a/mm/filemap.c
95222+++ b/mm/filemap.c
95223@@ -2101,7 +2101,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
95224 struct address_space *mapping = file->f_mapping;
95225
95226 if (!mapping->a_ops->readpage)
95227- return -ENOEXEC;
95228+ return -ENODEV;
95229 file_accessed(file);
95230 vma->vm_ops = &generic_file_vm_ops;
95231 return 0;
95232@@ -2279,6 +2279,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
95233 *pos = i_size_read(inode);
95234
95235 if (limit != RLIM_INFINITY) {
95236+ gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
95237 if (*pos >= limit) {
95238 send_sig(SIGXFSZ, current, 0);
95239 return -EFBIG;
95240diff --git a/mm/fremap.c b/mm/fremap.c
95241index 72b8fa3..c5b39f1 100644
95242--- a/mm/fremap.c
95243+++ b/mm/fremap.c
95244@@ -180,6 +180,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
95245 retry:
95246 vma = find_vma(mm, start);
95247
95248+#ifdef CONFIG_PAX_SEGMEXEC
95249+ if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
95250+ goto out;
95251+#endif
95252+
95253 /*
95254 * Make sure the vma is shared, that it supports prefaulting,
95255 * and that the remapped range is valid and fully within
95256diff --git a/mm/gup.c b/mm/gup.c
95257index cd62c8c..3bb2053 100644
95258--- a/mm/gup.c
95259+++ b/mm/gup.c
95260@@ -274,11 +274,6 @@ static int faultin_page(struct task_struct *tsk, struct vm_area_struct *vma,
95261 unsigned int fault_flags = 0;
95262 int ret;
95263
95264- /* For mlock, just skip the stack guard page. */
95265- if ((*flags & FOLL_MLOCK) &&
95266- (stack_guard_page_start(vma, address) ||
95267- stack_guard_page_end(vma, address + PAGE_SIZE)))
95268- return -ENOENT;
95269 if (*flags & FOLL_WRITE)
95270 fault_flags |= FAULT_FLAG_WRITE;
95271 if (nonblocking)
95272@@ -444,14 +439,14 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
95273 if (!(gup_flags & FOLL_FORCE))
95274 gup_flags |= FOLL_NUMA;
95275
95276- do {
95277+ while (nr_pages) {
95278 struct page *page;
95279 unsigned int foll_flags = gup_flags;
95280 unsigned int page_increm;
95281
95282 /* first iteration or cross vma bound */
95283 if (!vma || start >= vma->vm_end) {
95284- vma = find_extend_vma(mm, start);
95285+ vma = find_vma(mm, start);
95286 if (!vma && in_gate_area(mm, start)) {
95287 int ret;
95288 ret = get_gate_page(mm, start & PAGE_MASK,
95289@@ -463,7 +458,7 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
95290 goto next_page;
95291 }
95292
95293- if (!vma || check_vma_flags(vma, gup_flags))
95294+ if (!vma || start < vma->vm_start || check_vma_flags(vma, gup_flags))
95295 return i ? : -EFAULT;
95296 if (is_vm_hugetlb_page(vma)) {
95297 i = follow_hugetlb_page(mm, vma, pages, vmas,
95298@@ -518,7 +513,7 @@ next_page:
95299 i += page_increm;
95300 start += page_increm * PAGE_SIZE;
95301 nr_pages -= page_increm;
95302- } while (nr_pages);
95303+ }
95304 return i;
95305 }
95306 EXPORT_SYMBOL(__get_user_pages);
95307diff --git a/mm/highmem.c b/mm/highmem.c
95308index 123bcd3..0de52ba 100644
95309--- a/mm/highmem.c
95310+++ b/mm/highmem.c
95311@@ -195,8 +195,9 @@ static void flush_all_zero_pkmaps(void)
95312 * So no dangers, even with speculative execution.
95313 */
95314 page = pte_page(pkmap_page_table[i]);
95315+ pax_open_kernel();
95316 pte_clear(&init_mm, PKMAP_ADDR(i), &pkmap_page_table[i]);
95317-
95318+ pax_close_kernel();
95319 set_page_address(page, NULL);
95320 need_flush = 1;
95321 }
95322@@ -259,9 +260,11 @@ start:
95323 }
95324 }
95325 vaddr = PKMAP_ADDR(last_pkmap_nr);
95326+
95327+ pax_open_kernel();
95328 set_pte_at(&init_mm, vaddr,
95329 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
95330-
95331+ pax_close_kernel();
95332 pkmap_count[last_pkmap_nr] = 1;
95333 set_page_address(page, (void *)vaddr);
95334
95335diff --git a/mm/hugetlb.c b/mm/hugetlb.c
95336index 9fd7227..5628939 100644
95337--- a/mm/hugetlb.c
95338+++ b/mm/hugetlb.c
95339@@ -2258,6 +2258,7 @@ static int hugetlb_sysctl_handler_common(bool obey_mempolicy,
95340 struct ctl_table *table, int write,
95341 void __user *buffer, size_t *length, loff_t *ppos)
95342 {
95343+ ctl_table_no_const t;
95344 struct hstate *h = &default_hstate;
95345 unsigned long tmp = h->max_huge_pages;
95346 int ret;
95347@@ -2265,9 +2266,10 @@ static int hugetlb_sysctl_handler_common(bool obey_mempolicy,
95348 if (!hugepages_supported())
95349 return -ENOTSUPP;
95350
95351- table->data = &tmp;
95352- table->maxlen = sizeof(unsigned long);
95353- ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
95354+ t = *table;
95355+ t.data = &tmp;
95356+ t.maxlen = sizeof(unsigned long);
95357+ ret = proc_doulongvec_minmax(&t, write, buffer, length, ppos);
95358 if (ret)
95359 goto out;
95360
95361@@ -2302,6 +2304,7 @@ int hugetlb_overcommit_handler(struct ctl_table *table, int write,
95362 struct hstate *h = &default_hstate;
95363 unsigned long tmp;
95364 int ret;
95365+ ctl_table_no_const hugetlb_table;
95366
95367 if (!hugepages_supported())
95368 return -ENOTSUPP;
95369@@ -2311,9 +2314,10 @@ int hugetlb_overcommit_handler(struct ctl_table *table, int write,
95370 if (write && hstate_is_gigantic(h))
95371 return -EINVAL;
95372
95373- table->data = &tmp;
95374- table->maxlen = sizeof(unsigned long);
95375- ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
95376+ hugetlb_table = *table;
95377+ hugetlb_table.data = &tmp;
95378+ hugetlb_table.maxlen = sizeof(unsigned long);
95379+ ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
95380 if (ret)
95381 goto out;
95382
95383@@ -2792,6 +2796,27 @@ static void unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
95384 mutex_unlock(&mapping->i_mmap_mutex);
95385 }
95386
95387+#ifdef CONFIG_PAX_SEGMEXEC
95388+static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
95389+{
95390+ struct mm_struct *mm = vma->vm_mm;
95391+ struct vm_area_struct *vma_m;
95392+ unsigned long address_m;
95393+ pte_t *ptep_m;
95394+
95395+ vma_m = pax_find_mirror_vma(vma);
95396+ if (!vma_m)
95397+ return;
95398+
95399+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
95400+ address_m = address + SEGMEXEC_TASK_SIZE;
95401+ ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
95402+ get_page(page_m);
95403+ hugepage_add_anon_rmap(page_m, vma_m, address_m);
95404+ set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
95405+}
95406+#endif
95407+
95408 /*
95409 * Hugetlb_cow() should be called with page lock of the original hugepage held.
95410 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
95411@@ -2903,6 +2928,11 @@ retry_avoidcopy:
95412 make_huge_pte(vma, new_page, 1));
95413 page_remove_rmap(old_page);
95414 hugepage_add_new_anon_rmap(new_page, vma, address);
95415+
95416+#ifdef CONFIG_PAX_SEGMEXEC
95417+ pax_mirror_huge_pte(vma, address, new_page);
95418+#endif
95419+
95420 /* Make the old page be freed below */
95421 new_page = old_page;
95422 }
95423@@ -3063,6 +3093,10 @@ retry:
95424 && (vma->vm_flags & VM_SHARED)));
95425 set_huge_pte_at(mm, address, ptep, new_pte);
95426
95427+#ifdef CONFIG_PAX_SEGMEXEC
95428+ pax_mirror_huge_pte(vma, address, page);
95429+#endif
95430+
95431 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
95432 /* Optimization, do the COW without a second fault */
95433 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page, ptl);
95434@@ -3129,6 +3163,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
95435 struct hstate *h = hstate_vma(vma);
95436 struct address_space *mapping;
95437
95438+#ifdef CONFIG_PAX_SEGMEXEC
95439+ struct vm_area_struct *vma_m;
95440+#endif
95441+
95442 address &= huge_page_mask(h);
95443
95444 ptep = huge_pte_offset(mm, address);
95445@@ -3142,6 +3180,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
95446 VM_FAULT_SET_HINDEX(hstate_index(h));
95447 }
95448
95449+#ifdef CONFIG_PAX_SEGMEXEC
95450+ vma_m = pax_find_mirror_vma(vma);
95451+ if (vma_m) {
95452+ unsigned long address_m;
95453+
95454+ if (vma->vm_start > vma_m->vm_start) {
95455+ address_m = address;
95456+ address -= SEGMEXEC_TASK_SIZE;
95457+ vma = vma_m;
95458+ h = hstate_vma(vma);
95459+ } else
95460+ address_m = address + SEGMEXEC_TASK_SIZE;
95461+
95462+ if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
95463+ return VM_FAULT_OOM;
95464+ address_m &= HPAGE_MASK;
95465+ unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
95466+ }
95467+#endif
95468+
95469 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
95470 if (!ptep)
95471 return VM_FAULT_OOM;
95472diff --git a/mm/internal.h b/mm/internal.h
95473index a4f90ba..fbdc32b 100644
95474--- a/mm/internal.h
95475+++ b/mm/internal.h
95476@@ -134,6 +134,7 @@ __find_buddy_index(unsigned long page_idx, unsigned int order)
95477
95478 extern int __isolate_free_page(struct page *page, unsigned int order);
95479 extern void __free_pages_bootmem(struct page *page, unsigned int order);
95480+extern void free_compound_page(struct page *page);
95481 extern void prep_compound_page(struct page *page, unsigned long order);
95482 #ifdef CONFIG_MEMORY_FAILURE
95483 extern bool is_free_buddy_page(struct page *page);
95484@@ -390,7 +391,7 @@ extern u32 hwpoison_filter_enable;
95485
95486 extern unsigned long vm_mmap_pgoff(struct file *, unsigned long,
95487 unsigned long, unsigned long,
95488- unsigned long, unsigned long);
95489+ unsigned long, unsigned long) __intentional_overflow(-1);
95490
95491 extern void set_pageblock_order(void);
95492 unsigned long reclaim_clean_pages_from_list(struct zone *zone,
95493diff --git a/mm/iov_iter.c b/mm/iov_iter.c
95494index e34a3cb..a810efe 100644
95495--- a/mm/iov_iter.c
95496+++ b/mm/iov_iter.c
95497@@ -307,7 +307,7 @@ static size_t __iovec_copy_from_user_inatomic(char *vaddr,
95498
95499 while (bytes) {
95500 char __user *buf = iov->iov_base + base;
95501- int copy = min(bytes, iov->iov_len - base);
95502+ size_t copy = min(bytes, iov->iov_len - base);
95503
95504 base = 0;
95505 left = __copy_from_user_inatomic(vaddr, buf, copy);
95506@@ -335,7 +335,7 @@ static size_t copy_from_user_atomic_iovec(struct page *page,
95507
95508 kaddr = kmap_atomic(page);
95509 if (likely(i->nr_segs == 1)) {
95510- int left;
95511+ size_t left;
95512 char __user *buf = i->iov->iov_base + i->iov_offset;
95513 left = __copy_from_user_inatomic(kaddr + offset, buf, bytes);
95514 copied = bytes - left;
95515@@ -365,7 +365,7 @@ static void advance_iovec(struct iov_iter *i, size_t bytes)
95516 * zero-length segments (without overruning the iovec).
95517 */
95518 while (bytes || unlikely(i->count && !iov->iov_len)) {
95519- int copy;
95520+ size_t copy;
95521
95522 copy = min(bytes, iov->iov_len - base);
95523 BUG_ON(!i->count || i->count < copy);
95524diff --git a/mm/kmemleak.c b/mm/kmemleak.c
95525index 3cda50c..032ba634 100644
95526--- a/mm/kmemleak.c
95527+++ b/mm/kmemleak.c
95528@@ -364,7 +364,7 @@ static void print_unreferenced(struct seq_file *seq,
95529
95530 for (i = 0; i < object->trace_len; i++) {
95531 void *ptr = (void *)object->trace[i];
95532- seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
95533+ seq_printf(seq, " [<%pP>] %pA\n", ptr, ptr);
95534 }
95535 }
95536
95537@@ -1905,7 +1905,7 @@ static int __init kmemleak_late_init(void)
95538 return -ENOMEM;
95539 }
95540
95541- dentry = debugfs_create_file("kmemleak", S_IRUGO, NULL, NULL,
95542+ dentry = debugfs_create_file("kmemleak", S_IRUSR, NULL, NULL,
95543 &kmemleak_fops);
95544 if (!dentry)
95545 pr_warning("Failed to create the debugfs kmemleak file\n");
95546diff --git a/mm/maccess.c b/mm/maccess.c
95547index d53adf9..03a24bf 100644
95548--- a/mm/maccess.c
95549+++ b/mm/maccess.c
95550@@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
95551 set_fs(KERNEL_DS);
95552 pagefault_disable();
95553 ret = __copy_from_user_inatomic(dst,
95554- (__force const void __user *)src, size);
95555+ (const void __force_user *)src, size);
95556 pagefault_enable();
95557 set_fs(old_fs);
95558
95559@@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
95560
95561 set_fs(KERNEL_DS);
95562 pagefault_disable();
95563- ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
95564+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
95565 pagefault_enable();
95566 set_fs(old_fs);
95567
95568diff --git a/mm/madvise.c b/mm/madvise.c
95569index 0938b30..199abe8 100644
95570--- a/mm/madvise.c
95571+++ b/mm/madvise.c
95572@@ -51,6 +51,10 @@ static long madvise_behavior(struct vm_area_struct *vma,
95573 pgoff_t pgoff;
95574 unsigned long new_flags = vma->vm_flags;
95575
95576+#ifdef CONFIG_PAX_SEGMEXEC
95577+ struct vm_area_struct *vma_m;
95578+#endif
95579+
95580 switch (behavior) {
95581 case MADV_NORMAL:
95582 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
95583@@ -126,6 +130,13 @@ success:
95584 /*
95585 * vm_flags is protected by the mmap_sem held in write mode.
95586 */
95587+
95588+#ifdef CONFIG_PAX_SEGMEXEC
95589+ vma_m = pax_find_mirror_vma(vma);
95590+ if (vma_m)
95591+ vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
95592+#endif
95593+
95594 vma->vm_flags = new_flags;
95595
95596 out:
95597@@ -274,6 +285,11 @@ static long madvise_dontneed(struct vm_area_struct *vma,
95598 struct vm_area_struct **prev,
95599 unsigned long start, unsigned long end)
95600 {
95601+
95602+#ifdef CONFIG_PAX_SEGMEXEC
95603+ struct vm_area_struct *vma_m;
95604+#endif
95605+
95606 *prev = vma;
95607 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
95608 return -EINVAL;
95609@@ -286,6 +302,21 @@ static long madvise_dontneed(struct vm_area_struct *vma,
95610 zap_page_range(vma, start, end - start, &details);
95611 } else
95612 zap_page_range(vma, start, end - start, NULL);
95613+
95614+#ifdef CONFIG_PAX_SEGMEXEC
95615+ vma_m = pax_find_mirror_vma(vma);
95616+ if (vma_m) {
95617+ if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
95618+ struct zap_details details = {
95619+ .nonlinear_vma = vma_m,
95620+ .last_index = ULONG_MAX,
95621+ };
95622+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
95623+ } else
95624+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
95625+ }
95626+#endif
95627+
95628 return 0;
95629 }
95630
95631@@ -488,6 +519,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
95632 if (end < start)
95633 return error;
95634
95635+#ifdef CONFIG_PAX_SEGMEXEC
95636+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
95637+ if (end > SEGMEXEC_TASK_SIZE)
95638+ return error;
95639+ } else
95640+#endif
95641+
95642+ if (end > TASK_SIZE)
95643+ return error;
95644+
95645 error = 0;
95646 if (end == start)
95647 return error;
95648diff --git a/mm/memory-failure.c b/mm/memory-failure.c
95649index 8639f6b..b623882a 100644
95650--- a/mm/memory-failure.c
95651+++ b/mm/memory-failure.c
95652@@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
95653
95654 int sysctl_memory_failure_recovery __read_mostly = 1;
95655
95656-atomic_long_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
95657+atomic_long_unchecked_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
95658
95659 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
95660
95661@@ -198,7 +198,7 @@ static int kill_proc(struct task_struct *t, unsigned long addr, int trapno,
95662 pfn, t->comm, t->pid);
95663 si.si_signo = SIGBUS;
95664 si.si_errno = 0;
95665- si.si_addr = (void *)addr;
95666+ si.si_addr = (void __user *)addr;
95667 #ifdef __ARCH_SI_TRAPNO
95668 si.si_trapno = trapno;
95669 #endif
95670@@ -791,7 +791,7 @@ static struct page_state {
95671 unsigned long res;
95672 char *msg;
95673 int (*action)(struct page *p, unsigned long pfn);
95674-} error_states[] = {
95675+} __do_const error_states[] = {
95676 { reserved, reserved, "reserved kernel", me_kernel },
95677 /*
95678 * free pages are specially detected outside this table:
95679@@ -1099,7 +1099,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
95680 nr_pages = 1 << compound_order(hpage);
95681 else /* normal page or thp */
95682 nr_pages = 1;
95683- atomic_long_add(nr_pages, &num_poisoned_pages);
95684+ atomic_long_add_unchecked(nr_pages, &num_poisoned_pages);
95685
95686 /*
95687 * We need/can do nothing about count=0 pages.
95688@@ -1128,7 +1128,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
95689 if (PageHWPoison(hpage)) {
95690 if ((hwpoison_filter(p) && TestClearPageHWPoison(p))
95691 || (p != hpage && TestSetPageHWPoison(hpage))) {
95692- atomic_long_sub(nr_pages, &num_poisoned_pages);
95693+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
95694 unlock_page(hpage);
95695 return 0;
95696 }
95697@@ -1196,14 +1196,14 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
95698 */
95699 if (!PageHWPoison(p)) {
95700 printk(KERN_ERR "MCE %#lx: just unpoisoned\n", pfn);
95701- atomic_long_sub(nr_pages, &num_poisoned_pages);
95702+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
95703 put_page(hpage);
95704 res = 0;
95705 goto out;
95706 }
95707 if (hwpoison_filter(p)) {
95708 if (TestClearPageHWPoison(p))
95709- atomic_long_sub(nr_pages, &num_poisoned_pages);
95710+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
95711 unlock_page(hpage);
95712 put_page(hpage);
95713 return 0;
95714@@ -1433,7 +1433,7 @@ int unpoison_memory(unsigned long pfn)
95715 return 0;
95716 }
95717 if (TestClearPageHWPoison(p))
95718- atomic_long_dec(&num_poisoned_pages);
95719+ atomic_long_dec_unchecked(&num_poisoned_pages);
95720 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
95721 return 0;
95722 }
95723@@ -1447,7 +1447,7 @@ int unpoison_memory(unsigned long pfn)
95724 */
95725 if (TestClearPageHWPoison(page)) {
95726 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
95727- atomic_long_sub(nr_pages, &num_poisoned_pages);
95728+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
95729 freeit = 1;
95730 if (PageHuge(page))
95731 clear_page_hwpoison_huge_page(page);
95732@@ -1572,11 +1572,11 @@ static int soft_offline_huge_page(struct page *page, int flags)
95733 if (PageHuge(page)) {
95734 set_page_hwpoison_huge_page(hpage);
95735 dequeue_hwpoisoned_huge_page(hpage);
95736- atomic_long_add(1 << compound_order(hpage),
95737+ atomic_long_add_unchecked(1 << compound_order(hpage),
95738 &num_poisoned_pages);
95739 } else {
95740 SetPageHWPoison(page);
95741- atomic_long_inc(&num_poisoned_pages);
95742+ atomic_long_inc_unchecked(&num_poisoned_pages);
95743 }
95744 }
95745 return ret;
95746@@ -1615,7 +1615,7 @@ static int __soft_offline_page(struct page *page, int flags)
95747 put_page(page);
95748 pr_info("soft_offline: %#lx: invalidated\n", pfn);
95749 SetPageHWPoison(page);
95750- atomic_long_inc(&num_poisoned_pages);
95751+ atomic_long_inc_unchecked(&num_poisoned_pages);
95752 return 0;
95753 }
95754
95755@@ -1666,7 +1666,7 @@ static int __soft_offline_page(struct page *page, int flags)
95756 if (!is_free_buddy_page(page))
95757 pr_info("soft offline: %#lx: page leaked\n",
95758 pfn);
95759- atomic_long_inc(&num_poisoned_pages);
95760+ atomic_long_inc_unchecked(&num_poisoned_pages);
95761 }
95762 } else {
95763 pr_info("soft offline: %#lx: isolation failed: %d, page count %d, type %lx\n",
95764@@ -1736,11 +1736,11 @@ int soft_offline_page(struct page *page, int flags)
95765 if (PageHuge(page)) {
95766 set_page_hwpoison_huge_page(hpage);
95767 dequeue_hwpoisoned_huge_page(hpage);
95768- atomic_long_add(1 << compound_order(hpage),
95769+ atomic_long_add_unchecked(1 << compound_order(hpage),
95770 &num_poisoned_pages);
95771 } else {
95772 SetPageHWPoison(page);
95773- atomic_long_inc(&num_poisoned_pages);
95774+ atomic_long_inc_unchecked(&num_poisoned_pages);
95775 }
95776 }
95777 unset_migratetype_isolate(page, MIGRATE_MOVABLE);
95778diff --git a/mm/memory.c b/mm/memory.c
95779index d5f2ae9..4d678b2 100644
95780--- a/mm/memory.c
95781+++ b/mm/memory.c
95782@@ -415,6 +415,7 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
95783 free_pte_range(tlb, pmd, addr);
95784 } while (pmd++, addr = next, addr != end);
95785
95786+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
95787 start &= PUD_MASK;
95788 if (start < floor)
95789 return;
95790@@ -429,6 +430,8 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
95791 pmd = pmd_offset(pud, start);
95792 pud_clear(pud);
95793 pmd_free_tlb(tlb, pmd, start);
95794+#endif
95795+
95796 }
95797
95798 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
95799@@ -448,6 +451,7 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
95800 free_pmd_range(tlb, pud, addr, next, floor, ceiling);
95801 } while (pud++, addr = next, addr != end);
95802
95803+#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
95804 start &= PGDIR_MASK;
95805 if (start < floor)
95806 return;
95807@@ -462,6 +466,8 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
95808 pud = pud_offset(pgd, start);
95809 pgd_clear(pgd);
95810 pud_free_tlb(tlb, pud, start);
95811+#endif
95812+
95813 }
95814
95815 /*
95816@@ -691,10 +697,10 @@ static void print_bad_pte(struct vm_area_struct *vma, unsigned long addr,
95817 * Choose text because data symbols depend on CONFIG_KALLSYMS_ALL=y
95818 */
95819 if (vma->vm_ops)
95820- printk(KERN_ALERT "vma->vm_ops->fault: %pSR\n",
95821+ printk(KERN_ALERT "vma->vm_ops->fault: %pAR\n",
95822 vma->vm_ops->fault);
95823 if (vma->vm_file)
95824- printk(KERN_ALERT "vma->vm_file->f_op->mmap: %pSR\n",
95825+ printk(KERN_ALERT "vma->vm_file->f_op->mmap: %pAR\n",
95826 vma->vm_file->f_op->mmap);
95827 dump_stack();
95828 add_taint(TAINT_BAD_PAGE, LOCKDEP_NOW_UNRELIABLE);
95829@@ -1501,6 +1507,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
95830 page_add_file_rmap(page);
95831 set_pte_at(mm, addr, pte, mk_pte(page, prot));
95832
95833+#ifdef CONFIG_PAX_SEGMEXEC
95834+ pax_mirror_file_pte(vma, addr, page, ptl);
95835+#endif
95836+
95837 retval = 0;
95838 pte_unmap_unlock(pte, ptl);
95839 return retval;
95840@@ -1545,9 +1555,21 @@ int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
95841 if (!page_count(page))
95842 return -EINVAL;
95843 if (!(vma->vm_flags & VM_MIXEDMAP)) {
95844+
95845+#ifdef CONFIG_PAX_SEGMEXEC
95846+ struct vm_area_struct *vma_m;
95847+#endif
95848+
95849 BUG_ON(down_read_trylock(&vma->vm_mm->mmap_sem));
95850 BUG_ON(vma->vm_flags & VM_PFNMAP);
95851 vma->vm_flags |= VM_MIXEDMAP;
95852+
95853+#ifdef CONFIG_PAX_SEGMEXEC
95854+ vma_m = pax_find_mirror_vma(vma);
95855+ if (vma_m)
95856+ vma_m->vm_flags |= VM_MIXEDMAP;
95857+#endif
95858+
95859 }
95860 return insert_page(vma, addr, page, vma->vm_page_prot);
95861 }
95862@@ -1630,6 +1652,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
95863 unsigned long pfn)
95864 {
95865 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
95866+ BUG_ON(vma->vm_mirror);
95867
95868 if (addr < vma->vm_start || addr >= vma->vm_end)
95869 return -EFAULT;
95870@@ -1877,7 +1900,9 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud,
95871
95872 BUG_ON(pud_huge(*pud));
95873
95874- pmd = pmd_alloc(mm, pud, addr);
95875+ pmd = (mm == &init_mm) ?
95876+ pmd_alloc_kernel(mm, pud, addr) :
95877+ pmd_alloc(mm, pud, addr);
95878 if (!pmd)
95879 return -ENOMEM;
95880 do {
95881@@ -1897,7 +1922,9 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,
95882 unsigned long next;
95883 int err;
95884
95885- pud = pud_alloc(mm, pgd, addr);
95886+ pud = (mm == &init_mm) ?
95887+ pud_alloc_kernel(mm, pgd, addr) :
95888+ pud_alloc(mm, pgd, addr);
95889 if (!pud)
95890 return -ENOMEM;
95891 do {
95892@@ -2019,6 +2046,186 @@ static int do_page_mkwrite(struct vm_area_struct *vma, struct page *page,
95893 return ret;
95894 }
95895
95896+#ifdef CONFIG_PAX_SEGMEXEC
95897+static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
95898+{
95899+ struct mm_struct *mm = vma->vm_mm;
95900+ spinlock_t *ptl;
95901+ pte_t *pte, entry;
95902+
95903+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
95904+ entry = *pte;
95905+ if (!pte_present(entry)) {
95906+ if (!pte_none(entry)) {
95907+ BUG_ON(pte_file(entry));
95908+ free_swap_and_cache(pte_to_swp_entry(entry));
95909+ pte_clear_not_present_full(mm, address, pte, 0);
95910+ }
95911+ } else {
95912+ struct page *page;
95913+
95914+ flush_cache_page(vma, address, pte_pfn(entry));
95915+ entry = ptep_clear_flush(vma, address, pte);
95916+ BUG_ON(pte_dirty(entry));
95917+ page = vm_normal_page(vma, address, entry);
95918+ if (page) {
95919+ update_hiwater_rss(mm);
95920+ if (PageAnon(page))
95921+ dec_mm_counter_fast(mm, MM_ANONPAGES);
95922+ else
95923+ dec_mm_counter_fast(mm, MM_FILEPAGES);
95924+ page_remove_rmap(page);
95925+ page_cache_release(page);
95926+ }
95927+ }
95928+ pte_unmap_unlock(pte, ptl);
95929+}
95930+
95931+/* PaX: if vma is mirrored, synchronize the mirror's PTE
95932+ *
95933+ * the ptl of the lower mapped page is held on entry and is not released on exit
95934+ * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
95935+ */
95936+static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
95937+{
95938+ struct mm_struct *mm = vma->vm_mm;
95939+ unsigned long address_m;
95940+ spinlock_t *ptl_m;
95941+ struct vm_area_struct *vma_m;
95942+ pmd_t *pmd_m;
95943+ pte_t *pte_m, entry_m;
95944+
95945+ BUG_ON(!page_m || !PageAnon(page_m));
95946+
95947+ vma_m = pax_find_mirror_vma(vma);
95948+ if (!vma_m)
95949+ return;
95950+
95951+ BUG_ON(!PageLocked(page_m));
95952+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
95953+ address_m = address + SEGMEXEC_TASK_SIZE;
95954+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
95955+ pte_m = pte_offset_map(pmd_m, address_m);
95956+ ptl_m = pte_lockptr(mm, pmd_m);
95957+ if (ptl != ptl_m) {
95958+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
95959+ if (!pte_none(*pte_m))
95960+ goto out;
95961+ }
95962+
95963+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
95964+ page_cache_get(page_m);
95965+ page_add_anon_rmap(page_m, vma_m, address_m);
95966+ inc_mm_counter_fast(mm, MM_ANONPAGES);
95967+ set_pte_at(mm, address_m, pte_m, entry_m);
95968+ update_mmu_cache(vma_m, address_m, pte_m);
95969+out:
95970+ if (ptl != ptl_m)
95971+ spin_unlock(ptl_m);
95972+ pte_unmap(pte_m);
95973+ unlock_page(page_m);
95974+}
95975+
95976+void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
95977+{
95978+ struct mm_struct *mm = vma->vm_mm;
95979+ unsigned long address_m;
95980+ spinlock_t *ptl_m;
95981+ struct vm_area_struct *vma_m;
95982+ pmd_t *pmd_m;
95983+ pte_t *pte_m, entry_m;
95984+
95985+ BUG_ON(!page_m || PageAnon(page_m));
95986+
95987+ vma_m = pax_find_mirror_vma(vma);
95988+ if (!vma_m)
95989+ return;
95990+
95991+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
95992+ address_m = address + SEGMEXEC_TASK_SIZE;
95993+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
95994+ pte_m = pte_offset_map(pmd_m, address_m);
95995+ ptl_m = pte_lockptr(mm, pmd_m);
95996+ if (ptl != ptl_m) {
95997+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
95998+ if (!pte_none(*pte_m))
95999+ goto out;
96000+ }
96001+
96002+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
96003+ page_cache_get(page_m);
96004+ page_add_file_rmap(page_m);
96005+ inc_mm_counter_fast(mm, MM_FILEPAGES);
96006+ set_pte_at(mm, address_m, pte_m, entry_m);
96007+ update_mmu_cache(vma_m, address_m, pte_m);
96008+out:
96009+ if (ptl != ptl_m)
96010+ spin_unlock(ptl_m);
96011+ pte_unmap(pte_m);
96012+}
96013+
96014+static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
96015+{
96016+ struct mm_struct *mm = vma->vm_mm;
96017+ unsigned long address_m;
96018+ spinlock_t *ptl_m;
96019+ struct vm_area_struct *vma_m;
96020+ pmd_t *pmd_m;
96021+ pte_t *pte_m, entry_m;
96022+
96023+ vma_m = pax_find_mirror_vma(vma);
96024+ if (!vma_m)
96025+ return;
96026+
96027+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
96028+ address_m = address + SEGMEXEC_TASK_SIZE;
96029+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
96030+ pte_m = pte_offset_map(pmd_m, address_m);
96031+ ptl_m = pte_lockptr(mm, pmd_m);
96032+ if (ptl != ptl_m) {
96033+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
96034+ if (!pte_none(*pte_m))
96035+ goto out;
96036+ }
96037+
96038+ entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
96039+ set_pte_at(mm, address_m, pte_m, entry_m);
96040+out:
96041+ if (ptl != ptl_m)
96042+ spin_unlock(ptl_m);
96043+ pte_unmap(pte_m);
96044+}
96045+
96046+static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
96047+{
96048+ struct page *page_m;
96049+ pte_t entry;
96050+
96051+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
96052+ goto out;
96053+
96054+ entry = *pte;
96055+ page_m = vm_normal_page(vma, address, entry);
96056+ if (!page_m)
96057+ pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
96058+ else if (PageAnon(page_m)) {
96059+ if (pax_find_mirror_vma(vma)) {
96060+ pte_unmap_unlock(pte, ptl);
96061+ lock_page(page_m);
96062+ pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
96063+ if (pte_same(entry, *pte))
96064+ pax_mirror_anon_pte(vma, address, page_m, ptl);
96065+ else
96066+ unlock_page(page_m);
96067+ }
96068+ } else
96069+ pax_mirror_file_pte(vma, address, page_m, ptl);
96070+
96071+out:
96072+ pte_unmap_unlock(pte, ptl);
96073+}
96074+#endif
96075+
96076 /*
96077 * This routine handles present pages, when users try to write
96078 * to a shared page. It is done by copying the page to a new address
96079@@ -2218,6 +2425,12 @@ gotten:
96080 */
96081 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
96082 if (likely(pte_same(*page_table, orig_pte))) {
96083+
96084+#ifdef CONFIG_PAX_SEGMEXEC
96085+ if (pax_find_mirror_vma(vma))
96086+ BUG_ON(!trylock_page(new_page));
96087+#endif
96088+
96089 if (old_page) {
96090 if (!PageAnon(old_page)) {
96091 dec_mm_counter_fast(mm, MM_FILEPAGES);
96092@@ -2271,6 +2484,10 @@ gotten:
96093 page_remove_rmap(old_page);
96094 }
96095
96096+#ifdef CONFIG_PAX_SEGMEXEC
96097+ pax_mirror_anon_pte(vma, address, new_page, ptl);
96098+#endif
96099+
96100 /* Free the old page.. */
96101 new_page = old_page;
96102 ret |= VM_FAULT_WRITE;
96103@@ -2545,6 +2762,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
96104 swap_free(entry);
96105 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
96106 try_to_free_swap(page);
96107+
96108+#ifdef CONFIG_PAX_SEGMEXEC
96109+ if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
96110+#endif
96111+
96112 unlock_page(page);
96113 if (page != swapcache) {
96114 /*
96115@@ -2568,6 +2790,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
96116
96117 /* No need to invalidate - it was non-present before */
96118 update_mmu_cache(vma, address, page_table);
96119+
96120+#ifdef CONFIG_PAX_SEGMEXEC
96121+ pax_mirror_anon_pte(vma, address, page, ptl);
96122+#endif
96123+
96124 unlock:
96125 pte_unmap_unlock(page_table, ptl);
96126 out:
96127@@ -2587,40 +2814,6 @@ out_release:
96128 }
96129
96130 /*
96131- * This is like a special single-page "expand_{down|up}wards()",
96132- * except we must first make sure that 'address{-|+}PAGE_SIZE'
96133- * doesn't hit another vma.
96134- */
96135-static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
96136-{
96137- address &= PAGE_MASK;
96138- if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
96139- struct vm_area_struct *prev = vma->vm_prev;
96140-
96141- /*
96142- * Is there a mapping abutting this one below?
96143- *
96144- * That's only ok if it's the same stack mapping
96145- * that has gotten split..
96146- */
96147- if (prev && prev->vm_end == address)
96148- return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
96149-
96150- expand_downwards(vma, address - PAGE_SIZE);
96151- }
96152- if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
96153- struct vm_area_struct *next = vma->vm_next;
96154-
96155- /* As VM_GROWSDOWN but s/below/above/ */
96156- if (next && next->vm_start == address + PAGE_SIZE)
96157- return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
96158-
96159- expand_upwards(vma, address + PAGE_SIZE);
96160- }
96161- return 0;
96162-}
96163-
96164-/*
96165 * We enter with non-exclusive mmap_sem (to exclude vma changes,
96166 * but allow concurrent faults), and pte mapped but not yet locked.
96167 * We return with mmap_sem still held, but pte unmapped and unlocked.
96168@@ -2630,27 +2823,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
96169 unsigned int flags)
96170 {
96171 struct mem_cgroup *memcg;
96172- struct page *page;
96173+ struct page *page = NULL;
96174 spinlock_t *ptl;
96175 pte_t entry;
96176
96177- pte_unmap(page_table);
96178-
96179- /* Check if we need to add a guard page to the stack */
96180- if (check_stack_guard_page(vma, address) < 0)
96181- return VM_FAULT_SIGBUS;
96182-
96183- /* Use the zero-page for reads */
96184 if (!(flags & FAULT_FLAG_WRITE)) {
96185 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
96186 vma->vm_page_prot));
96187- page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
96188+ ptl = pte_lockptr(mm, pmd);
96189+ spin_lock(ptl);
96190 if (!pte_none(*page_table))
96191 goto unlock;
96192 goto setpte;
96193 }
96194
96195 /* Allocate our own private page. */
96196+ pte_unmap(page_table);
96197+
96198 if (unlikely(anon_vma_prepare(vma)))
96199 goto oom;
96200 page = alloc_zeroed_user_highpage_movable(vma, address);
96201@@ -2674,6 +2863,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
96202 if (!pte_none(*page_table))
96203 goto release;
96204
96205+#ifdef CONFIG_PAX_SEGMEXEC
96206+ if (pax_find_mirror_vma(vma))
96207+ BUG_ON(!trylock_page(page));
96208+#endif
96209+
96210 inc_mm_counter_fast(mm, MM_ANONPAGES);
96211 page_add_new_anon_rmap(page, vma, address);
96212 mem_cgroup_commit_charge(page, memcg, false);
96213@@ -2683,6 +2877,12 @@ setpte:
96214
96215 /* No need to invalidate - it was non-present before */
96216 update_mmu_cache(vma, address, page_table);
96217+
96218+#ifdef CONFIG_PAX_SEGMEXEC
96219+ if (page)
96220+ pax_mirror_anon_pte(vma, address, page, ptl);
96221+#endif
96222+
96223 unlock:
96224 pte_unmap_unlock(page_table, ptl);
96225 return 0;
96226@@ -2913,6 +3113,11 @@ static int do_read_fault(struct mm_struct *mm, struct vm_area_struct *vma,
96227 return ret;
96228 }
96229 do_set_pte(vma, address, fault_page, pte, false, false);
96230+
96231+#ifdef CONFIG_PAX_SEGMEXEC
96232+ pax_mirror_file_pte(vma, address, fault_page, ptl);
96233+#endif
96234+
96235 unlock_page(fault_page);
96236 unlock_out:
96237 pte_unmap_unlock(pte, ptl);
96238@@ -2955,7 +3160,18 @@ static int do_cow_fault(struct mm_struct *mm, struct vm_area_struct *vma,
96239 page_cache_release(fault_page);
96240 goto uncharge_out;
96241 }
96242+
96243+#ifdef CONFIG_PAX_SEGMEXEC
96244+ if (pax_find_mirror_vma(vma))
96245+ BUG_ON(!trylock_page(new_page));
96246+#endif
96247+
96248 do_set_pte(vma, address, new_page, pte, true, true);
96249+
96250+#ifdef CONFIG_PAX_SEGMEXEC
96251+ pax_mirror_anon_pte(vma, address, new_page, ptl);
96252+#endif
96253+
96254 mem_cgroup_commit_charge(new_page, memcg, false);
96255 lru_cache_add_active_or_unevictable(new_page, vma);
96256 pte_unmap_unlock(pte, ptl);
96257@@ -3005,6 +3221,11 @@ static int do_shared_fault(struct mm_struct *mm, struct vm_area_struct *vma,
96258 return ret;
96259 }
96260 do_set_pte(vma, address, fault_page, pte, true, false);
96261+
96262+#ifdef CONFIG_PAX_SEGMEXEC
96263+ pax_mirror_file_pte(vma, address, fault_page, ptl);
96264+#endif
96265+
96266 pte_unmap_unlock(pte, ptl);
96267
96268 if (set_page_dirty(fault_page))
96269@@ -3246,6 +3467,12 @@ static int handle_pte_fault(struct mm_struct *mm,
96270 if (flags & FAULT_FLAG_WRITE)
96271 flush_tlb_fix_spurious_fault(vma, address);
96272 }
96273+
96274+#ifdef CONFIG_PAX_SEGMEXEC
96275+ pax_mirror_pte(vma, address, pte, pmd, ptl);
96276+ return 0;
96277+#endif
96278+
96279 unlock:
96280 pte_unmap_unlock(pte, ptl);
96281 return 0;
96282@@ -3265,9 +3492,41 @@ static int __handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
96283 pmd_t *pmd;
96284 pte_t *pte;
96285
96286+#ifdef CONFIG_PAX_SEGMEXEC
96287+ struct vm_area_struct *vma_m;
96288+#endif
96289+
96290 if (unlikely(is_vm_hugetlb_page(vma)))
96291 return hugetlb_fault(mm, vma, address, flags);
96292
96293+#ifdef CONFIG_PAX_SEGMEXEC
96294+ vma_m = pax_find_mirror_vma(vma);
96295+ if (vma_m) {
96296+ unsigned long address_m;
96297+ pgd_t *pgd_m;
96298+ pud_t *pud_m;
96299+ pmd_t *pmd_m;
96300+
96301+ if (vma->vm_start > vma_m->vm_start) {
96302+ address_m = address;
96303+ address -= SEGMEXEC_TASK_SIZE;
96304+ vma = vma_m;
96305+ } else
96306+ address_m = address + SEGMEXEC_TASK_SIZE;
96307+
96308+ pgd_m = pgd_offset(mm, address_m);
96309+ pud_m = pud_alloc(mm, pgd_m, address_m);
96310+ if (!pud_m)
96311+ return VM_FAULT_OOM;
96312+ pmd_m = pmd_alloc(mm, pud_m, address_m);
96313+ if (!pmd_m)
96314+ return VM_FAULT_OOM;
96315+ if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
96316+ return VM_FAULT_OOM;
96317+ pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
96318+ }
96319+#endif
96320+
96321 pgd = pgd_offset(mm, address);
96322 pud = pud_alloc(mm, pgd, address);
96323 if (!pud)
96324@@ -3401,6 +3660,23 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
96325 spin_unlock(&mm->page_table_lock);
96326 return 0;
96327 }
96328+
96329+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
96330+{
96331+ pud_t *new = pud_alloc_one(mm, address);
96332+ if (!new)
96333+ return -ENOMEM;
96334+
96335+ smp_wmb(); /* See comment in __pte_alloc */
96336+
96337+ spin_lock(&mm->page_table_lock);
96338+ if (pgd_present(*pgd)) /* Another has populated it */
96339+ pud_free(mm, new);
96340+ else
96341+ pgd_populate_kernel(mm, pgd, new);
96342+ spin_unlock(&mm->page_table_lock);
96343+ return 0;
96344+}
96345 #endif /* __PAGETABLE_PUD_FOLDED */
96346
96347 #ifndef __PAGETABLE_PMD_FOLDED
96348@@ -3431,6 +3707,30 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
96349 spin_unlock(&mm->page_table_lock);
96350 return 0;
96351 }
96352+
96353+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
96354+{
96355+ pmd_t *new = pmd_alloc_one(mm, address);
96356+ if (!new)
96357+ return -ENOMEM;
96358+
96359+ smp_wmb(); /* See comment in __pte_alloc */
96360+
96361+ spin_lock(&mm->page_table_lock);
96362+#ifndef __ARCH_HAS_4LEVEL_HACK
96363+ if (pud_present(*pud)) /* Another has populated it */
96364+ pmd_free(mm, new);
96365+ else
96366+ pud_populate_kernel(mm, pud, new);
96367+#else
96368+ if (pgd_present(*pud)) /* Another has populated it */
96369+ pmd_free(mm, new);
96370+ else
96371+ pgd_populate_kernel(mm, pud, new);
96372+#endif /* __ARCH_HAS_4LEVEL_HACK */
96373+ spin_unlock(&mm->page_table_lock);
96374+ return 0;
96375+}
96376 #endif /* __PAGETABLE_PMD_FOLDED */
96377
96378 static int __follow_pte(struct mm_struct *mm, unsigned long address,
96379@@ -3540,8 +3840,8 @@ out:
96380 return ret;
96381 }
96382
96383-int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
96384- void *buf, int len, int write)
96385+ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
96386+ void *buf, size_t len, int write)
96387 {
96388 resource_size_t phys_addr;
96389 unsigned long prot = 0;
96390@@ -3567,8 +3867,8 @@ EXPORT_SYMBOL_GPL(generic_access_phys);
96391 * Access another process' address space as given in mm. If non-NULL, use the
96392 * given task for page fault accounting.
96393 */
96394-static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
96395- unsigned long addr, void *buf, int len, int write)
96396+static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
96397+ unsigned long addr, void *buf, size_t len, int write)
96398 {
96399 struct vm_area_struct *vma;
96400 void *old_buf = buf;
96401@@ -3576,7 +3876,7 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
96402 down_read(&mm->mmap_sem);
96403 /* ignore errors, just check how much was successfully transferred */
96404 while (len) {
96405- int bytes, ret, offset;
96406+ ssize_t bytes, ret, offset;
96407 void *maddr;
96408 struct page *page = NULL;
96409
96410@@ -3637,8 +3937,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
96411 *
96412 * The caller must hold a reference on @mm.
96413 */
96414-int access_remote_vm(struct mm_struct *mm, unsigned long addr,
96415- void *buf, int len, int write)
96416+ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
96417+ void *buf, size_t len, int write)
96418 {
96419 return __access_remote_vm(NULL, mm, addr, buf, len, write);
96420 }
96421@@ -3648,11 +3948,11 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
96422 * Source/target buffer must be kernel space,
96423 * Do not walk the page table directly, use get_user_pages
96424 */
96425-int access_process_vm(struct task_struct *tsk, unsigned long addr,
96426- void *buf, int len, int write)
96427+ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr,
96428+ void *buf, size_t len, int write)
96429 {
96430 struct mm_struct *mm;
96431- int ret;
96432+ ssize_t ret;
96433
96434 mm = get_task_mm(tsk);
96435 if (!mm)
96436diff --git a/mm/mempolicy.c b/mm/mempolicy.c
96437index e58725a..e0be017 100644
96438--- a/mm/mempolicy.c
96439+++ b/mm/mempolicy.c
96440@@ -750,6 +750,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
96441 unsigned long vmstart;
96442 unsigned long vmend;
96443
96444+#ifdef CONFIG_PAX_SEGMEXEC
96445+ struct vm_area_struct *vma_m;
96446+#endif
96447+
96448 vma = find_vma(mm, start);
96449 if (!vma || vma->vm_start > start)
96450 return -EFAULT;
96451@@ -793,6 +797,16 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
96452 err = vma_replace_policy(vma, new_pol);
96453 if (err)
96454 goto out;
96455+
96456+#ifdef CONFIG_PAX_SEGMEXEC
96457+ vma_m = pax_find_mirror_vma(vma);
96458+ if (vma_m) {
96459+ err = vma_replace_policy(vma_m, new_pol);
96460+ if (err)
96461+ goto out;
96462+ }
96463+#endif
96464+
96465 }
96466
96467 out:
96468@@ -1212,6 +1226,17 @@ static long do_mbind(unsigned long start, unsigned long len,
96469
96470 if (end < start)
96471 return -EINVAL;
96472+
96473+#ifdef CONFIG_PAX_SEGMEXEC
96474+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
96475+ if (end > SEGMEXEC_TASK_SIZE)
96476+ return -EINVAL;
96477+ } else
96478+#endif
96479+
96480+ if (end > TASK_SIZE)
96481+ return -EINVAL;
96482+
96483 if (end == start)
96484 return 0;
96485
96486@@ -1437,8 +1462,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
96487 */
96488 tcred = __task_cred(task);
96489 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
96490- !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
96491- !capable(CAP_SYS_NICE)) {
96492+ !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
96493 rcu_read_unlock();
96494 err = -EPERM;
96495 goto out_put;
96496@@ -1469,6 +1493,15 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
96497 goto out;
96498 }
96499
96500+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
96501+ if (mm != current->mm &&
96502+ (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
96503+ mmput(mm);
96504+ err = -EPERM;
96505+ goto out;
96506+ }
96507+#endif
96508+
96509 err = do_migrate_pages(mm, old, new,
96510 capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
96511
96512diff --git a/mm/migrate.c b/mm/migrate.c
96513index 0143995..b294728 100644
96514--- a/mm/migrate.c
96515+++ b/mm/migrate.c
96516@@ -1495,8 +1495,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
96517 */
96518 tcred = __task_cred(task);
96519 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
96520- !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
96521- !capable(CAP_SYS_NICE)) {
96522+ !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
96523 rcu_read_unlock();
96524 err = -EPERM;
96525 goto out;
96526diff --git a/mm/mlock.c b/mm/mlock.c
96527index 73cf098..ab547c7 100644
96528--- a/mm/mlock.c
96529+++ b/mm/mlock.c
96530@@ -14,6 +14,7 @@
96531 #include <linux/pagevec.h>
96532 #include <linux/mempolicy.h>
96533 #include <linux/syscalls.h>
96534+#include <linux/security.h>
96535 #include <linux/sched.h>
96536 #include <linux/export.h>
96537 #include <linux/rmap.h>
96538@@ -613,7 +614,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
96539 {
96540 unsigned long nstart, end, tmp;
96541 struct vm_area_struct * vma, * prev;
96542- int error;
96543+ int error = 0;
96544
96545 VM_BUG_ON(start & ~PAGE_MASK);
96546 VM_BUG_ON(len != PAGE_ALIGN(len));
96547@@ -622,6 +623,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
96548 return -EINVAL;
96549 if (end == start)
96550 return 0;
96551+ if (end > TASK_SIZE)
96552+ return -EINVAL;
96553+
96554 vma = find_vma(current->mm, start);
96555 if (!vma || vma->vm_start > start)
96556 return -ENOMEM;
96557@@ -633,6 +637,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
96558 for (nstart = start ; ; ) {
96559 vm_flags_t newflags;
96560
96561+#ifdef CONFIG_PAX_SEGMEXEC
96562+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
96563+ break;
96564+#endif
96565+
96566 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
96567
96568 newflags = vma->vm_flags & ~VM_LOCKED;
96569@@ -746,6 +755,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
96570 locked += current->mm->locked_vm;
96571
96572 /* check against resource limits */
96573+ gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
96574 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
96575 error = do_mlock(start, len, 1);
96576
96577@@ -783,6 +793,11 @@ static int do_mlockall(int flags)
96578 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
96579 vm_flags_t newflags;
96580
96581+#ifdef CONFIG_PAX_SEGMEXEC
96582+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
96583+ break;
96584+#endif
96585+
96586 newflags = vma->vm_flags & ~VM_LOCKED;
96587 if (flags & MCL_CURRENT)
96588 newflags |= VM_LOCKED;
96589@@ -814,8 +829,10 @@ SYSCALL_DEFINE1(mlockall, int, flags)
96590 lock_limit >>= PAGE_SHIFT;
96591
96592 ret = -ENOMEM;
96593+
96594+ gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
96595+
96596 down_write(&current->mm->mmap_sem);
96597-
96598 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
96599 capable(CAP_IPC_LOCK))
96600 ret = do_mlockall(flags);
96601diff --git a/mm/mmap.c b/mm/mmap.c
96602index ae91989..d8308c7 100644
96603--- a/mm/mmap.c
96604+++ b/mm/mmap.c
96605@@ -41,6 +41,7 @@
96606 #include <linux/notifier.h>
96607 #include <linux/memory.h>
96608 #include <linux/printk.h>
96609+#include <linux/random.h>
96610
96611 #include <asm/uaccess.h>
96612 #include <asm/cacheflush.h>
96613@@ -57,6 +58,16 @@
96614 #define arch_rebalance_pgtables(addr, len) (addr)
96615 #endif
96616
96617+static inline void verify_mm_writelocked(struct mm_struct *mm)
96618+{
96619+#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
96620+ if (unlikely(down_read_trylock(&mm->mmap_sem))) {
96621+ up_read(&mm->mmap_sem);
96622+ BUG();
96623+ }
96624+#endif
96625+}
96626+
96627 static void unmap_region(struct mm_struct *mm,
96628 struct vm_area_struct *vma, struct vm_area_struct *prev,
96629 unsigned long start, unsigned long end);
96630@@ -76,16 +87,25 @@ static void unmap_region(struct mm_struct *mm,
96631 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
96632 *
96633 */
96634-pgprot_t protection_map[16] = {
96635+pgprot_t protection_map[16] __read_only = {
96636 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
96637 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
96638 };
96639
96640-pgprot_t vm_get_page_prot(unsigned long vm_flags)
96641+pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
96642 {
96643- return __pgprot(pgprot_val(protection_map[vm_flags &
96644+ pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
96645 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
96646 pgprot_val(arch_vm_get_page_prot(vm_flags)));
96647+
96648+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
96649+ if (!(__supported_pte_mask & _PAGE_NX) &&
96650+ (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
96651+ (vm_flags & (VM_READ | VM_WRITE)))
96652+ prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
96653+#endif
96654+
96655+ return prot;
96656 }
96657 EXPORT_SYMBOL(vm_get_page_prot);
96658
96659@@ -114,6 +134,7 @@ unsigned long sysctl_overcommit_kbytes __read_mostly;
96660 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
96661 unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
96662 unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
96663+unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
96664 /*
96665 * Make sure vm_committed_as in one cacheline and not cacheline shared with
96666 * other variables. It can be updated by several CPUs frequently.
96667@@ -274,6 +295,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
96668 struct vm_area_struct *next = vma->vm_next;
96669
96670 might_sleep();
96671+ BUG_ON(vma->vm_mirror);
96672 if (vma->vm_ops && vma->vm_ops->close)
96673 vma->vm_ops->close(vma);
96674 if (vma->vm_file)
96675@@ -287,6 +309,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len);
96676
96677 SYSCALL_DEFINE1(brk, unsigned long, brk)
96678 {
96679+ unsigned long rlim;
96680 unsigned long retval;
96681 unsigned long newbrk, oldbrk;
96682 struct mm_struct *mm = current->mm;
96683@@ -317,7 +340,13 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
96684 * segment grow beyond its set limit the in case where the limit is
96685 * not page aligned -Ram Gupta
96686 */
96687- if (check_data_rlimit(rlimit(RLIMIT_DATA), brk, mm->start_brk,
96688+ rlim = rlimit(RLIMIT_DATA);
96689+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
96690+ /* force a minimum 16MB brk heap on setuid/setgid binaries */
96691+ if (rlim < PAGE_SIZE && (get_dumpable(mm) != SUID_DUMP_USER) && gr_is_global_nonroot(current_uid()))
96692+ rlim = 4096 * PAGE_SIZE;
96693+#endif
96694+ if (check_data_rlimit(rlim, brk, mm->start_brk,
96695 mm->end_data, mm->start_data))
96696 goto out;
96697
96698@@ -976,6 +1005,12 @@ static int
96699 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
96700 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
96701 {
96702+
96703+#ifdef CONFIG_PAX_SEGMEXEC
96704+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
96705+ return 0;
96706+#endif
96707+
96708 if (is_mergeable_vma(vma, file, vm_flags) &&
96709 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
96710 if (vma->vm_pgoff == vm_pgoff)
96711@@ -995,6 +1030,12 @@ static int
96712 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
96713 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
96714 {
96715+
96716+#ifdef CONFIG_PAX_SEGMEXEC
96717+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
96718+ return 0;
96719+#endif
96720+
96721 if (is_mergeable_vma(vma, file, vm_flags) &&
96722 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
96723 pgoff_t vm_pglen;
96724@@ -1044,6 +1085,13 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
96725 struct vm_area_struct *area, *next;
96726 int err;
96727
96728+#ifdef CONFIG_PAX_SEGMEXEC
96729+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
96730+ struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
96731+
96732+ BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
96733+#endif
96734+
96735 /*
96736 * We later require that vma->vm_flags == vm_flags,
96737 * so this tests vma->vm_flags & VM_SPECIAL, too.
96738@@ -1059,6 +1107,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
96739 if (next && next->vm_end == end) /* cases 6, 7, 8 */
96740 next = next->vm_next;
96741
96742+#ifdef CONFIG_PAX_SEGMEXEC
96743+ if (prev)
96744+ prev_m = pax_find_mirror_vma(prev);
96745+ if (area)
96746+ area_m = pax_find_mirror_vma(area);
96747+ if (next)
96748+ next_m = pax_find_mirror_vma(next);
96749+#endif
96750+
96751 /*
96752 * Can it merge with the predecessor?
96753 */
96754@@ -1078,9 +1135,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
96755 /* cases 1, 6 */
96756 err = vma_adjust(prev, prev->vm_start,
96757 next->vm_end, prev->vm_pgoff, NULL);
96758- } else /* cases 2, 5, 7 */
96759+
96760+#ifdef CONFIG_PAX_SEGMEXEC
96761+ if (!err && prev_m)
96762+ err = vma_adjust(prev_m, prev_m->vm_start,
96763+ next_m->vm_end, prev_m->vm_pgoff, NULL);
96764+#endif
96765+
96766+ } else { /* cases 2, 5, 7 */
96767 err = vma_adjust(prev, prev->vm_start,
96768 end, prev->vm_pgoff, NULL);
96769+
96770+#ifdef CONFIG_PAX_SEGMEXEC
96771+ if (!err && prev_m)
96772+ err = vma_adjust(prev_m, prev_m->vm_start,
96773+ end_m, prev_m->vm_pgoff, NULL);
96774+#endif
96775+
96776+ }
96777 if (err)
96778 return NULL;
96779 khugepaged_enter_vma_merge(prev, vm_flags);
96780@@ -1094,12 +1166,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
96781 mpol_equal(policy, vma_policy(next)) &&
96782 can_vma_merge_before(next, vm_flags,
96783 anon_vma, file, pgoff+pglen)) {
96784- if (prev && addr < prev->vm_end) /* case 4 */
96785+ if (prev && addr < prev->vm_end) { /* case 4 */
96786 err = vma_adjust(prev, prev->vm_start,
96787 addr, prev->vm_pgoff, NULL);
96788- else /* cases 3, 8 */
96789+
96790+#ifdef CONFIG_PAX_SEGMEXEC
96791+ if (!err && prev_m)
96792+ err = vma_adjust(prev_m, prev_m->vm_start,
96793+ addr_m, prev_m->vm_pgoff, NULL);
96794+#endif
96795+
96796+ } else { /* cases 3, 8 */
96797 err = vma_adjust(area, addr, next->vm_end,
96798 next->vm_pgoff - pglen, NULL);
96799+
96800+#ifdef CONFIG_PAX_SEGMEXEC
96801+ if (!err && area_m)
96802+ err = vma_adjust(area_m, addr_m, next_m->vm_end,
96803+ next_m->vm_pgoff - pglen, NULL);
96804+#endif
96805+
96806+ }
96807 if (err)
96808 return NULL;
96809 khugepaged_enter_vma_merge(area, vm_flags);
96810@@ -1208,8 +1295,10 @@ none:
96811 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
96812 struct file *file, long pages)
96813 {
96814- const unsigned long stack_flags
96815- = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
96816+
96817+#ifdef CONFIG_PAX_RANDMMAP
96818+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
96819+#endif
96820
96821 mm->total_vm += pages;
96822
96823@@ -1217,7 +1306,7 @@ void vm_stat_account(struct mm_struct *mm, unsigned long flags,
96824 mm->shared_vm += pages;
96825 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
96826 mm->exec_vm += pages;
96827- } else if (flags & stack_flags)
96828+ } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
96829 mm->stack_vm += pages;
96830 }
96831 #endif /* CONFIG_PROC_FS */
96832@@ -1247,6 +1336,7 @@ static inline int mlock_future_check(struct mm_struct *mm,
96833 locked += mm->locked_vm;
96834 lock_limit = rlimit(RLIMIT_MEMLOCK);
96835 lock_limit >>= PAGE_SHIFT;
96836+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
96837 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
96838 return -EAGAIN;
96839 }
96840@@ -1273,7 +1363,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
96841 * (the exception is when the underlying filesystem is noexec
96842 * mounted, in which case we dont add PROT_EXEC.)
96843 */
96844- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
96845+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
96846 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
96847 prot |= PROT_EXEC;
96848
96849@@ -1299,7 +1389,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
96850 /* Obtain the address to map to. we verify (or select) it and ensure
96851 * that it represents a valid section of the address space.
96852 */
96853- addr = get_unmapped_area(file, addr, len, pgoff, flags);
96854+ addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
96855 if (addr & ~PAGE_MASK)
96856 return addr;
96857
96858@@ -1310,6 +1400,43 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
96859 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
96860 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
96861
96862+#ifdef CONFIG_PAX_MPROTECT
96863+ if (mm->pax_flags & MF_PAX_MPROTECT) {
96864+
96865+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
96866+ if (file && !pgoff && (vm_flags & VM_EXEC) && mm->binfmt &&
96867+ mm->binfmt->handle_mmap)
96868+ mm->binfmt->handle_mmap(file);
96869+#endif
96870+
96871+#ifndef CONFIG_PAX_MPROTECT_COMPAT
96872+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
96873+ gr_log_rwxmmap(file);
96874+
96875+#ifdef CONFIG_PAX_EMUPLT
96876+ vm_flags &= ~VM_EXEC;
96877+#else
96878+ return -EPERM;
96879+#endif
96880+
96881+ }
96882+
96883+ if (!(vm_flags & VM_EXEC))
96884+ vm_flags &= ~VM_MAYEXEC;
96885+#else
96886+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
96887+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
96888+#endif
96889+ else
96890+ vm_flags &= ~VM_MAYWRITE;
96891+ }
96892+#endif
96893+
96894+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
96895+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
96896+ vm_flags &= ~VM_PAGEEXEC;
96897+#endif
96898+
96899 if (flags & MAP_LOCKED)
96900 if (!can_do_mlock())
96901 return -EPERM;
96902@@ -1397,6 +1524,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
96903 vm_flags |= VM_NORESERVE;
96904 }
96905
96906+ if (!gr_acl_handle_mmap(file, prot))
96907+ return -EACCES;
96908+
96909 addr = mmap_region(file, addr, len, vm_flags, pgoff);
96910 if (!IS_ERR_VALUE(addr) &&
96911 ((vm_flags & VM_LOCKED) ||
96912@@ -1490,7 +1620,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
96913 vm_flags_t vm_flags = vma->vm_flags;
96914
96915 /* If it was private or non-writable, the write bit is already clear */
96916- if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
96917+ if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
96918 return 0;
96919
96920 /* The backer wishes to know when pages are first written to? */
96921@@ -1541,7 +1671,22 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
96922 struct rb_node **rb_link, *rb_parent;
96923 unsigned long charged = 0;
96924
96925+#ifdef CONFIG_PAX_SEGMEXEC
96926+ struct vm_area_struct *vma_m = NULL;
96927+#endif
96928+
96929+ /*
96930+ * mm->mmap_sem is required to protect against another thread
96931+ * changing the mappings in case we sleep.
96932+ */
96933+ verify_mm_writelocked(mm);
96934+
96935 /* Check against address space limit. */
96936+
96937+#ifdef CONFIG_PAX_RANDMMAP
96938+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (vm_flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
96939+#endif
96940+
96941 if (!may_expand_vm(mm, len >> PAGE_SHIFT)) {
96942 unsigned long nr_pages;
96943
96944@@ -1560,11 +1705,10 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
96945
96946 /* Clear old maps */
96947 error = -ENOMEM;
96948-munmap_back:
96949 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
96950 if (do_munmap(mm, addr, len))
96951 return -ENOMEM;
96952- goto munmap_back;
96953+ BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
96954 }
96955
96956 /*
96957@@ -1595,6 +1739,16 @@ munmap_back:
96958 goto unacct_error;
96959 }
96960
96961+#ifdef CONFIG_PAX_SEGMEXEC
96962+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
96963+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
96964+ if (!vma_m) {
96965+ error = -ENOMEM;
96966+ goto free_vma;
96967+ }
96968+ }
96969+#endif
96970+
96971 vma->vm_mm = mm;
96972 vma->vm_start = addr;
96973 vma->vm_end = addr + len;
96974@@ -1625,6 +1779,13 @@ munmap_back:
96975 if (error)
96976 goto unmap_and_free_vma;
96977
96978+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
96979+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
96980+ vma->vm_flags |= VM_PAGEEXEC;
96981+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
96982+ }
96983+#endif
96984+
96985 /* Can addr have changed??
96986 *
96987 * Answer: Yes, several device drivers can do it in their
96988@@ -1643,6 +1804,12 @@ munmap_back:
96989 }
96990
96991 vma_link(mm, vma, prev, rb_link, rb_parent);
96992+
96993+#ifdef CONFIG_PAX_SEGMEXEC
96994+ if (vma_m)
96995+ BUG_ON(pax_mirror_vma(vma_m, vma));
96996+#endif
96997+
96998 /* Once vma denies write, undo our temporary denial count */
96999 if (file) {
97000 if (vm_flags & VM_SHARED)
97001@@ -1655,6 +1822,7 @@ out:
97002 perf_event_mmap(vma);
97003
97004 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
97005+ track_exec_limit(mm, addr, addr + len, vm_flags);
97006 if (vm_flags & VM_LOCKED) {
97007 if (!((vm_flags & VM_SPECIAL) || is_vm_hugetlb_page(vma) ||
97008 vma == get_gate_vma(current->mm)))
97009@@ -1692,6 +1860,12 @@ allow_write_and_free_vma:
97010 if (vm_flags & VM_DENYWRITE)
97011 allow_write_access(file);
97012 free_vma:
97013+
97014+#ifdef CONFIG_PAX_SEGMEXEC
97015+ if (vma_m)
97016+ kmem_cache_free(vm_area_cachep, vma_m);
97017+#endif
97018+
97019 kmem_cache_free(vm_area_cachep, vma);
97020 unacct_error:
97021 if (charged)
97022@@ -1699,7 +1873,63 @@ unacct_error:
97023 return error;
97024 }
97025
97026-unsigned long unmapped_area(struct vm_unmapped_area_info *info)
97027+#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
97028+unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
97029+{
97030+ if ((mm->pax_flags & MF_PAX_RANDMMAP) && !filp && (flags & MAP_STACK))
97031+ return ((prandom_u32() & 0xFF) + 1) << PAGE_SHIFT;
97032+
97033+ return 0;
97034+}
97035+#endif
97036+
97037+bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset)
97038+{
97039+ if (!vma) {
97040+#ifdef CONFIG_STACK_GROWSUP
97041+ if (addr > sysctl_heap_stack_gap)
97042+ vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
97043+ else
97044+ vma = find_vma(current->mm, 0);
97045+ if (vma && (vma->vm_flags & VM_GROWSUP))
97046+ return false;
97047+#endif
97048+ return true;
97049+ }
97050+
97051+ if (addr + len > vma->vm_start)
97052+ return false;
97053+
97054+ if (vma->vm_flags & VM_GROWSDOWN)
97055+ return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
97056+#ifdef CONFIG_STACK_GROWSUP
97057+ else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
97058+ return addr - vma->vm_prev->vm_end >= sysctl_heap_stack_gap;
97059+#endif
97060+ else if (offset)
97061+ return offset <= vma->vm_start - addr - len;
97062+
97063+ return true;
97064+}
97065+
97066+unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset)
97067+{
97068+ if (vma->vm_start < len)
97069+ return -ENOMEM;
97070+
97071+ if (!(vma->vm_flags & VM_GROWSDOWN)) {
97072+ if (offset <= vma->vm_start - len)
97073+ return vma->vm_start - len - offset;
97074+ else
97075+ return -ENOMEM;
97076+ }
97077+
97078+ if (sysctl_heap_stack_gap <= vma->vm_start - len)
97079+ return vma->vm_start - len - sysctl_heap_stack_gap;
97080+ return -ENOMEM;
97081+}
97082+
97083+unsigned long unmapped_area(const struct vm_unmapped_area_info *info)
97084 {
97085 /*
97086 * We implement the search by looking for an rbtree node that
97087@@ -1747,11 +1977,29 @@ unsigned long unmapped_area(struct vm_unmapped_area_info *info)
97088 }
97089 }
97090
97091- gap_start = vma->vm_prev ? vma->vm_prev->vm_end : 0;
97092+ gap_start = vma->vm_prev ? vma->vm_prev->vm_end: 0;
97093 check_current:
97094 /* Check if current node has a suitable gap */
97095 if (gap_start > high_limit)
97096 return -ENOMEM;
97097+
97098+ if (gap_end - gap_start > info->threadstack_offset)
97099+ gap_start += info->threadstack_offset;
97100+ else
97101+ gap_start = gap_end;
97102+
97103+ if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
97104+ if (gap_end - gap_start > sysctl_heap_stack_gap)
97105+ gap_start += sysctl_heap_stack_gap;
97106+ else
97107+ gap_start = gap_end;
97108+ }
97109+ if (vma->vm_flags & VM_GROWSDOWN) {
97110+ if (gap_end - gap_start > sysctl_heap_stack_gap)
97111+ gap_end -= sysctl_heap_stack_gap;
97112+ else
97113+ gap_end = gap_start;
97114+ }
97115 if (gap_end >= low_limit && gap_end - gap_start >= length)
97116 goto found;
97117
97118@@ -1801,7 +2049,7 @@ found:
97119 return gap_start;
97120 }
97121
97122-unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info)
97123+unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info)
97124 {
97125 struct mm_struct *mm = current->mm;
97126 struct vm_area_struct *vma;
97127@@ -1855,6 +2103,24 @@ check_current:
97128 gap_end = vma->vm_start;
97129 if (gap_end < low_limit)
97130 return -ENOMEM;
97131+
97132+ if (gap_end - gap_start > info->threadstack_offset)
97133+ gap_end -= info->threadstack_offset;
97134+ else
97135+ gap_end = gap_start;
97136+
97137+ if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
97138+ if (gap_end - gap_start > sysctl_heap_stack_gap)
97139+ gap_start += sysctl_heap_stack_gap;
97140+ else
97141+ gap_start = gap_end;
97142+ }
97143+ if (vma->vm_flags & VM_GROWSDOWN) {
97144+ if (gap_end - gap_start > sysctl_heap_stack_gap)
97145+ gap_end -= sysctl_heap_stack_gap;
97146+ else
97147+ gap_end = gap_start;
97148+ }
97149 if (gap_start <= high_limit && gap_end - gap_start >= length)
97150 goto found;
97151
97152@@ -1918,6 +2184,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
97153 struct mm_struct *mm = current->mm;
97154 struct vm_area_struct *vma;
97155 struct vm_unmapped_area_info info;
97156+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
97157
97158 if (len > TASK_SIZE - mmap_min_addr)
97159 return -ENOMEM;
97160@@ -1925,11 +2192,15 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
97161 if (flags & MAP_FIXED)
97162 return addr;
97163
97164+#ifdef CONFIG_PAX_RANDMMAP
97165+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
97166+#endif
97167+
97168 if (addr) {
97169 addr = PAGE_ALIGN(addr);
97170 vma = find_vma(mm, addr);
97171 if (TASK_SIZE - len >= addr && addr >= mmap_min_addr &&
97172- (!vma || addr + len <= vma->vm_start))
97173+ check_heap_stack_gap(vma, addr, len, offset))
97174 return addr;
97175 }
97176
97177@@ -1938,6 +2209,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
97178 info.low_limit = mm->mmap_base;
97179 info.high_limit = TASK_SIZE;
97180 info.align_mask = 0;
97181+ info.threadstack_offset = offset;
97182 return vm_unmapped_area(&info);
97183 }
97184 #endif
97185@@ -1956,6 +2228,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
97186 struct mm_struct *mm = current->mm;
97187 unsigned long addr = addr0;
97188 struct vm_unmapped_area_info info;
97189+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
97190
97191 /* requested length too big for entire address space */
97192 if (len > TASK_SIZE - mmap_min_addr)
97193@@ -1964,12 +2237,16 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
97194 if (flags & MAP_FIXED)
97195 return addr;
97196
97197+#ifdef CONFIG_PAX_RANDMMAP
97198+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
97199+#endif
97200+
97201 /* requesting a specific address */
97202 if (addr) {
97203 addr = PAGE_ALIGN(addr);
97204 vma = find_vma(mm, addr);
97205 if (TASK_SIZE - len >= addr && addr >= mmap_min_addr &&
97206- (!vma || addr + len <= vma->vm_start))
97207+ check_heap_stack_gap(vma, addr, len, offset))
97208 return addr;
97209 }
97210
97211@@ -1978,6 +2255,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
97212 info.low_limit = max(PAGE_SIZE, mmap_min_addr);
97213 info.high_limit = mm->mmap_base;
97214 info.align_mask = 0;
97215+ info.threadstack_offset = offset;
97216 addr = vm_unmapped_area(&info);
97217
97218 /*
97219@@ -1990,6 +2268,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
97220 VM_BUG_ON(addr != -ENOMEM);
97221 info.flags = 0;
97222 info.low_limit = TASK_UNMAPPED_BASE;
97223+
97224+#ifdef CONFIG_PAX_RANDMMAP
97225+ if (mm->pax_flags & MF_PAX_RANDMMAP)
97226+ info.low_limit += mm->delta_mmap;
97227+#endif
97228+
97229 info.high_limit = TASK_SIZE;
97230 addr = vm_unmapped_area(&info);
97231 }
97232@@ -2090,6 +2374,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
97233 return vma;
97234 }
97235
97236+#ifdef CONFIG_PAX_SEGMEXEC
97237+struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
97238+{
97239+ struct vm_area_struct *vma_m;
97240+
97241+ BUG_ON(!vma || vma->vm_start >= vma->vm_end);
97242+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
97243+ BUG_ON(vma->vm_mirror);
97244+ return NULL;
97245+ }
97246+ BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
97247+ vma_m = vma->vm_mirror;
97248+ BUG_ON(!vma_m || vma_m->vm_mirror != vma);
97249+ BUG_ON(vma->vm_file != vma_m->vm_file);
97250+ BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
97251+ BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
97252+ BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
97253+ BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED));
97254+ return vma_m;
97255+}
97256+#endif
97257+
97258 /*
97259 * Verify that the stack growth is acceptable and
97260 * update accounting. This is shared with both the
97261@@ -2106,6 +2412,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
97262 return -ENOMEM;
97263
97264 /* Stack limit test */
97265+ gr_learn_resource(current, RLIMIT_STACK, size, 1);
97266 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
97267 return -ENOMEM;
97268
97269@@ -2116,6 +2423,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
97270 locked = mm->locked_vm + grow;
97271 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
97272 limit >>= PAGE_SHIFT;
97273+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
97274 if (locked > limit && !capable(CAP_IPC_LOCK))
97275 return -ENOMEM;
97276 }
97277@@ -2145,37 +2453,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
97278 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
97279 * vma is the last one with address > vma->vm_end. Have to extend vma.
97280 */
97281+#ifndef CONFIG_IA64
97282+static
97283+#endif
97284 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
97285 {
97286 int error;
97287+ bool locknext;
97288
97289 if (!(vma->vm_flags & VM_GROWSUP))
97290 return -EFAULT;
97291
97292+ /* Also guard against wrapping around to address 0. */
97293+ if (address < PAGE_ALIGN(address+1))
97294+ address = PAGE_ALIGN(address+1);
97295+ else
97296+ return -ENOMEM;
97297+
97298 /*
97299 * We must make sure the anon_vma is allocated
97300 * so that the anon_vma locking is not a noop.
97301 */
97302 if (unlikely(anon_vma_prepare(vma)))
97303 return -ENOMEM;
97304+ locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
97305+ if (locknext && anon_vma_prepare(vma->vm_next))
97306+ return -ENOMEM;
97307 vma_lock_anon_vma(vma);
97308+ if (locknext)
97309+ vma_lock_anon_vma(vma->vm_next);
97310
97311 /*
97312 * vma->vm_start/vm_end cannot change under us because the caller
97313 * is required to hold the mmap_sem in read mode. We need the
97314- * anon_vma lock to serialize against concurrent expand_stacks.
97315- * Also guard against wrapping around to address 0.
97316+ * anon_vma locks to serialize against concurrent expand_stacks
97317+ * and expand_upwards.
97318 */
97319- if (address < PAGE_ALIGN(address+4))
97320- address = PAGE_ALIGN(address+4);
97321- else {
97322- vma_unlock_anon_vma(vma);
97323- return -ENOMEM;
97324- }
97325 error = 0;
97326
97327 /* Somebody else might have raced and expanded it already */
97328- if (address > vma->vm_end) {
97329+ 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)
97330+ error = -ENOMEM;
97331+ else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
97332 unsigned long size, grow;
97333
97334 size = address - vma->vm_start;
97335@@ -2210,6 +2529,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
97336 }
97337 }
97338 }
97339+ if (locknext)
97340+ vma_unlock_anon_vma(vma->vm_next);
97341 vma_unlock_anon_vma(vma);
97342 khugepaged_enter_vma_merge(vma, vma->vm_flags);
97343 validate_mm(vma->vm_mm);
97344@@ -2224,6 +2545,8 @@ int expand_downwards(struct vm_area_struct *vma,
97345 unsigned long address)
97346 {
97347 int error;
97348+ bool lockprev = false;
97349+ struct vm_area_struct *prev;
97350
97351 /*
97352 * We must make sure the anon_vma is allocated
97353@@ -2237,6 +2560,15 @@ int expand_downwards(struct vm_area_struct *vma,
97354 if (error)
97355 return error;
97356
97357+ prev = vma->vm_prev;
97358+#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
97359+ lockprev = prev && (prev->vm_flags & VM_GROWSUP);
97360+#endif
97361+ if (lockprev && anon_vma_prepare(prev))
97362+ return -ENOMEM;
97363+ if (lockprev)
97364+ vma_lock_anon_vma(prev);
97365+
97366 vma_lock_anon_vma(vma);
97367
97368 /*
97369@@ -2246,9 +2578,17 @@ int expand_downwards(struct vm_area_struct *vma,
97370 */
97371
97372 /* Somebody else might have raced and expanded it already */
97373- if (address < vma->vm_start) {
97374+ if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
97375+ error = -ENOMEM;
97376+ else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
97377 unsigned long size, grow;
97378
97379+#ifdef CONFIG_PAX_SEGMEXEC
97380+ struct vm_area_struct *vma_m;
97381+
97382+ vma_m = pax_find_mirror_vma(vma);
97383+#endif
97384+
97385 size = vma->vm_end - address;
97386 grow = (vma->vm_start - address) >> PAGE_SHIFT;
97387
97388@@ -2273,13 +2613,27 @@ int expand_downwards(struct vm_area_struct *vma,
97389 vma->vm_pgoff -= grow;
97390 anon_vma_interval_tree_post_update_vma(vma);
97391 vma_gap_update(vma);
97392+
97393+#ifdef CONFIG_PAX_SEGMEXEC
97394+ if (vma_m) {
97395+ anon_vma_interval_tree_pre_update_vma(vma_m);
97396+ vma_m->vm_start -= grow << PAGE_SHIFT;
97397+ vma_m->vm_pgoff -= grow;
97398+ anon_vma_interval_tree_post_update_vma(vma_m);
97399+ vma_gap_update(vma_m);
97400+ }
97401+#endif
97402+
97403 spin_unlock(&vma->vm_mm->page_table_lock);
97404
97405+ track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
97406 perf_event_mmap(vma);
97407 }
97408 }
97409 }
97410 vma_unlock_anon_vma(vma);
97411+ if (lockprev)
97412+ vma_unlock_anon_vma(prev);
97413 khugepaged_enter_vma_merge(vma, vma->vm_flags);
97414 validate_mm(vma->vm_mm);
97415 return error;
97416@@ -2377,6 +2731,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
97417 do {
97418 long nrpages = vma_pages(vma);
97419
97420+#ifdef CONFIG_PAX_SEGMEXEC
97421+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
97422+ vma = remove_vma(vma);
97423+ continue;
97424+ }
97425+#endif
97426+
97427 if (vma->vm_flags & VM_ACCOUNT)
97428 nr_accounted += nrpages;
97429 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
97430@@ -2421,6 +2782,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
97431 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
97432 vma->vm_prev = NULL;
97433 do {
97434+
97435+#ifdef CONFIG_PAX_SEGMEXEC
97436+ if (vma->vm_mirror) {
97437+ BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
97438+ vma->vm_mirror->vm_mirror = NULL;
97439+ vma->vm_mirror->vm_flags &= ~VM_EXEC;
97440+ vma->vm_mirror = NULL;
97441+ }
97442+#endif
97443+
97444 vma_rb_erase(vma, &mm->mm_rb);
97445 mm->map_count--;
97446 tail_vma = vma;
97447@@ -2448,14 +2819,33 @@ static int __split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
97448 struct vm_area_struct *new;
97449 int err = -ENOMEM;
97450
97451+#ifdef CONFIG_PAX_SEGMEXEC
97452+ struct vm_area_struct *vma_m, *new_m = NULL;
97453+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
97454+#endif
97455+
97456 if (is_vm_hugetlb_page(vma) && (addr &
97457 ~(huge_page_mask(hstate_vma(vma)))))
97458 return -EINVAL;
97459
97460+#ifdef CONFIG_PAX_SEGMEXEC
97461+ vma_m = pax_find_mirror_vma(vma);
97462+#endif
97463+
97464 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
97465 if (!new)
97466 goto out_err;
97467
97468+#ifdef CONFIG_PAX_SEGMEXEC
97469+ if (vma_m) {
97470+ new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
97471+ if (!new_m) {
97472+ kmem_cache_free(vm_area_cachep, new);
97473+ goto out_err;
97474+ }
97475+ }
97476+#endif
97477+
97478 /* most fields are the same, copy all, and then fixup */
97479 *new = *vma;
97480
97481@@ -2468,6 +2858,22 @@ static int __split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
97482 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
97483 }
97484
97485+#ifdef CONFIG_PAX_SEGMEXEC
97486+ if (vma_m) {
97487+ *new_m = *vma_m;
97488+ INIT_LIST_HEAD(&new_m->anon_vma_chain);
97489+ new_m->vm_mirror = new;
97490+ new->vm_mirror = new_m;
97491+
97492+ if (new_below)
97493+ new_m->vm_end = addr_m;
97494+ else {
97495+ new_m->vm_start = addr_m;
97496+ new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
97497+ }
97498+ }
97499+#endif
97500+
97501 err = vma_dup_policy(vma, new);
97502 if (err)
97503 goto out_free_vma;
97504@@ -2488,6 +2894,38 @@ static int __split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
97505 else
97506 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
97507
97508+#ifdef CONFIG_PAX_SEGMEXEC
97509+ if (!err && vma_m) {
97510+ struct mempolicy *pol = vma_policy(new);
97511+
97512+ if (anon_vma_clone(new_m, vma_m))
97513+ goto out_free_mpol;
97514+
97515+ mpol_get(pol);
97516+ set_vma_policy(new_m, pol);
97517+
97518+ if (new_m->vm_file)
97519+ get_file(new_m->vm_file);
97520+
97521+ if (new_m->vm_ops && new_m->vm_ops->open)
97522+ new_m->vm_ops->open(new_m);
97523+
97524+ if (new_below)
97525+ err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
97526+ ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
97527+ else
97528+ err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
97529+
97530+ if (err) {
97531+ if (new_m->vm_ops && new_m->vm_ops->close)
97532+ new_m->vm_ops->close(new_m);
97533+ if (new_m->vm_file)
97534+ fput(new_m->vm_file);
97535+ mpol_put(pol);
97536+ }
97537+ }
97538+#endif
97539+
97540 /* Success. */
97541 if (!err)
97542 return 0;
97543@@ -2497,10 +2935,18 @@ static int __split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
97544 new->vm_ops->close(new);
97545 if (new->vm_file)
97546 fput(new->vm_file);
97547- unlink_anon_vmas(new);
97548 out_free_mpol:
97549 mpol_put(vma_policy(new));
97550 out_free_vma:
97551+
97552+#ifdef CONFIG_PAX_SEGMEXEC
97553+ if (new_m) {
97554+ unlink_anon_vmas(new_m);
97555+ kmem_cache_free(vm_area_cachep, new_m);
97556+ }
97557+#endif
97558+
97559+ unlink_anon_vmas(new);
97560 kmem_cache_free(vm_area_cachep, new);
97561 out_err:
97562 return err;
97563@@ -2513,6 +2959,15 @@ static int __split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
97564 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
97565 unsigned long addr, int new_below)
97566 {
97567+
97568+#ifdef CONFIG_PAX_SEGMEXEC
97569+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
97570+ BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
97571+ if (mm->map_count >= sysctl_max_map_count-1)
97572+ return -ENOMEM;
97573+ } else
97574+#endif
97575+
97576 if (mm->map_count >= sysctl_max_map_count)
97577 return -ENOMEM;
97578
97579@@ -2524,11 +2979,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
97580 * work. This now handles partial unmappings.
97581 * Jeremy Fitzhardinge <jeremy@goop.org>
97582 */
97583+#ifdef CONFIG_PAX_SEGMEXEC
97584 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
97585 {
97586+ int ret = __do_munmap(mm, start, len);
97587+ if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
97588+ return ret;
97589+
97590+ return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
97591+}
97592+
97593+int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
97594+#else
97595+int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
97596+#endif
97597+{
97598 unsigned long end;
97599 struct vm_area_struct *vma, *prev, *last;
97600
97601+ /*
97602+ * mm->mmap_sem is required to protect against another thread
97603+ * changing the mappings in case we sleep.
97604+ */
97605+ verify_mm_writelocked(mm);
97606+
97607 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
97608 return -EINVAL;
97609
97610@@ -2604,6 +3078,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
97611 /* Fix up all other VM information */
97612 remove_vma_list(mm, vma);
97613
97614+ track_exec_limit(mm, start, end, 0UL);
97615+
97616 return 0;
97617 }
97618
97619@@ -2612,6 +3088,13 @@ int vm_munmap(unsigned long start, size_t len)
97620 int ret;
97621 struct mm_struct *mm = current->mm;
97622
97623+
97624+#ifdef CONFIG_PAX_SEGMEXEC
97625+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
97626+ (len > SEGMEXEC_TASK_SIZE || start > SEGMEXEC_TASK_SIZE-len))
97627+ return -EINVAL;
97628+#endif
97629+
97630 down_write(&mm->mmap_sem);
97631 ret = do_munmap(mm, start, len);
97632 up_write(&mm->mmap_sem);
97633@@ -2625,16 +3108,6 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
97634 return vm_munmap(addr, len);
97635 }
97636
97637-static inline void verify_mm_writelocked(struct mm_struct *mm)
97638-{
97639-#ifdef CONFIG_DEBUG_VM
97640- if (unlikely(down_read_trylock(&mm->mmap_sem))) {
97641- WARN_ON(1);
97642- up_read(&mm->mmap_sem);
97643- }
97644-#endif
97645-}
97646-
97647 /*
97648 * this is really a simplified "do_mmap". it only handles
97649 * anonymous maps. eventually we may be able to do some
97650@@ -2648,6 +3121,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
97651 struct rb_node **rb_link, *rb_parent;
97652 pgoff_t pgoff = addr >> PAGE_SHIFT;
97653 int error;
97654+ unsigned long charged;
97655
97656 len = PAGE_ALIGN(len);
97657 if (!len)
97658@@ -2655,10 +3129,24 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
97659
97660 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
97661
97662+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
97663+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
97664+ flags &= ~VM_EXEC;
97665+
97666+#ifdef CONFIG_PAX_MPROTECT
97667+ if (mm->pax_flags & MF_PAX_MPROTECT)
97668+ flags &= ~VM_MAYEXEC;
97669+#endif
97670+
97671+ }
97672+#endif
97673+
97674 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
97675 if (error & ~PAGE_MASK)
97676 return error;
97677
97678+ charged = len >> PAGE_SHIFT;
97679+
97680 error = mlock_future_check(mm, mm->def_flags, len);
97681 if (error)
97682 return error;
97683@@ -2672,21 +3160,20 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
97684 /*
97685 * Clear old maps. this also does some error checking for us
97686 */
97687- munmap_back:
97688 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
97689 if (do_munmap(mm, addr, len))
97690 return -ENOMEM;
97691- goto munmap_back;
97692+ BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
97693 }
97694
97695 /* Check against address space limits *after* clearing old maps... */
97696- if (!may_expand_vm(mm, len >> PAGE_SHIFT))
97697+ if (!may_expand_vm(mm, charged))
97698 return -ENOMEM;
97699
97700 if (mm->map_count > sysctl_max_map_count)
97701 return -ENOMEM;
97702
97703- if (security_vm_enough_memory_mm(mm, len >> PAGE_SHIFT))
97704+ if (security_vm_enough_memory_mm(mm, charged))
97705 return -ENOMEM;
97706
97707 /* Can we just expand an old private anonymous mapping? */
97708@@ -2700,7 +3187,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
97709 */
97710 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
97711 if (!vma) {
97712- vm_unacct_memory(len >> PAGE_SHIFT);
97713+ vm_unacct_memory(charged);
97714 return -ENOMEM;
97715 }
97716
97717@@ -2714,10 +3201,11 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
97718 vma_link(mm, vma, prev, rb_link, rb_parent);
97719 out:
97720 perf_event_mmap(vma);
97721- mm->total_vm += len >> PAGE_SHIFT;
97722+ mm->total_vm += charged;
97723 if (flags & VM_LOCKED)
97724- mm->locked_vm += (len >> PAGE_SHIFT);
97725+ mm->locked_vm += charged;
97726 vma->vm_flags |= VM_SOFTDIRTY;
97727+ track_exec_limit(mm, addr, addr + len, flags);
97728 return addr;
97729 }
97730
97731@@ -2779,6 +3267,7 @@ void exit_mmap(struct mm_struct *mm)
97732 while (vma) {
97733 if (vma->vm_flags & VM_ACCOUNT)
97734 nr_accounted += vma_pages(vma);
97735+ vma->vm_mirror = NULL;
97736 vma = remove_vma(vma);
97737 }
97738 vm_unacct_memory(nr_accounted);
97739@@ -2796,6 +3285,13 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
97740 struct vm_area_struct *prev;
97741 struct rb_node **rb_link, *rb_parent;
97742
97743+#ifdef CONFIG_PAX_SEGMEXEC
97744+ struct vm_area_struct *vma_m = NULL;
97745+#endif
97746+
97747+ if (security_mmap_addr(vma->vm_start))
97748+ return -EPERM;
97749+
97750 /*
97751 * The vm_pgoff of a purely anonymous vma should be irrelevant
97752 * until its first write fault, when page's anon_vma and index
97753@@ -2819,7 +3315,21 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
97754 security_vm_enough_memory_mm(mm, vma_pages(vma)))
97755 return -ENOMEM;
97756
97757+#ifdef CONFIG_PAX_SEGMEXEC
97758+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
97759+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
97760+ if (!vma_m)
97761+ return -ENOMEM;
97762+ }
97763+#endif
97764+
97765 vma_link(mm, vma, prev, rb_link, rb_parent);
97766+
97767+#ifdef CONFIG_PAX_SEGMEXEC
97768+ if (vma_m)
97769+ BUG_ON(pax_mirror_vma(vma_m, vma));
97770+#endif
97771+
97772 return 0;
97773 }
97774
97775@@ -2838,6 +3348,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
97776 struct rb_node **rb_link, *rb_parent;
97777 bool faulted_in_anon_vma = true;
97778
97779+ BUG_ON(vma->vm_mirror);
97780+
97781 /*
97782 * If anonymous vma has not yet been faulted, update new pgoff
97783 * to match new location, to increase its chance of merging.
97784@@ -2902,6 +3414,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
97785 return NULL;
97786 }
97787
97788+#ifdef CONFIG_PAX_SEGMEXEC
97789+long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
97790+{
97791+ struct vm_area_struct *prev_m;
97792+ struct rb_node **rb_link_m, *rb_parent_m;
97793+ struct mempolicy *pol_m;
97794+
97795+ BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
97796+ BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
97797+ BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
97798+ *vma_m = *vma;
97799+ INIT_LIST_HEAD(&vma_m->anon_vma_chain);
97800+ if (anon_vma_clone(vma_m, vma))
97801+ return -ENOMEM;
97802+ pol_m = vma_policy(vma_m);
97803+ mpol_get(pol_m);
97804+ set_vma_policy(vma_m, pol_m);
97805+ vma_m->vm_start += SEGMEXEC_TASK_SIZE;
97806+ vma_m->vm_end += SEGMEXEC_TASK_SIZE;
97807+ vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
97808+ vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
97809+ if (vma_m->vm_file)
97810+ get_file(vma_m->vm_file);
97811+ if (vma_m->vm_ops && vma_m->vm_ops->open)
97812+ vma_m->vm_ops->open(vma_m);
97813+ BUG_ON(find_vma_links(vma->vm_mm, vma_m->vm_start, vma_m->vm_end, &prev_m, &rb_link_m, &rb_parent_m));
97814+ vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
97815+ vma_m->vm_mirror = vma;
97816+ vma->vm_mirror = vma_m;
97817+ return 0;
97818+}
97819+#endif
97820+
97821 /*
97822 * Return true if the calling process may expand its vm space by the passed
97823 * number of pages
97824@@ -2913,6 +3458,7 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
97825
97826 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
97827
97828+ gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
97829 if (cur + npages > lim)
97830 return 0;
97831 return 1;
97832@@ -2995,6 +3541,22 @@ static struct vm_area_struct *__install_special_mapping(
97833 vma->vm_start = addr;
97834 vma->vm_end = addr + len;
97835
97836+#ifdef CONFIG_PAX_MPROTECT
97837+ if (mm->pax_flags & MF_PAX_MPROTECT) {
97838+#ifndef CONFIG_PAX_MPROTECT_COMPAT
97839+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
97840+ return ERR_PTR(-EPERM);
97841+ if (!(vm_flags & VM_EXEC))
97842+ vm_flags &= ~VM_MAYEXEC;
97843+#else
97844+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
97845+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
97846+#endif
97847+ else
97848+ vm_flags &= ~VM_MAYWRITE;
97849+ }
97850+#endif
97851+
97852 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND | VM_SOFTDIRTY;
97853 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
97854
97855diff --git a/mm/mprotect.c b/mm/mprotect.c
97856index ace9345..63320dc 100644
97857--- a/mm/mprotect.c
97858+++ b/mm/mprotect.c
97859@@ -24,10 +24,18 @@
97860 #include <linux/migrate.h>
97861 #include <linux/perf_event.h>
97862 #include <linux/ksm.h>
97863+#include <linux/sched/sysctl.h>
97864+
97865+#ifdef CONFIG_PAX_MPROTECT
97866+#include <linux/elf.h>
97867+#include <linux/binfmts.h>
97868+#endif
97869+
97870 #include <asm/uaccess.h>
97871 #include <asm/pgtable.h>
97872 #include <asm/cacheflush.h>
97873 #include <asm/tlbflush.h>
97874+#include <asm/mmu_context.h>
97875
97876 /*
97877 * For a prot_numa update we only hold mmap_sem for read so there is a
97878@@ -251,6 +259,48 @@ unsigned long change_protection(struct vm_area_struct *vma, unsigned long start,
97879 return pages;
97880 }
97881
97882+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
97883+/* called while holding the mmap semaphor for writing except stack expansion */
97884+void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
97885+{
97886+ unsigned long oldlimit, newlimit = 0UL;
97887+
97888+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
97889+ return;
97890+
97891+ spin_lock(&mm->page_table_lock);
97892+ oldlimit = mm->context.user_cs_limit;
97893+ if ((prot & VM_EXEC) && oldlimit < end)
97894+ /* USER_CS limit moved up */
97895+ newlimit = end;
97896+ else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
97897+ /* USER_CS limit moved down */
97898+ newlimit = start;
97899+
97900+ if (newlimit) {
97901+ mm->context.user_cs_limit = newlimit;
97902+
97903+#ifdef CONFIG_SMP
97904+ wmb();
97905+ cpus_clear(mm->context.cpu_user_cs_mask);
97906+ cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
97907+#endif
97908+
97909+ set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
97910+ }
97911+ spin_unlock(&mm->page_table_lock);
97912+ if (newlimit == end) {
97913+ struct vm_area_struct *vma = find_vma(mm, oldlimit);
97914+
97915+ for (; vma && vma->vm_start < end; vma = vma->vm_next)
97916+ if (is_vm_hugetlb_page(vma))
97917+ hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
97918+ else
97919+ change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma), 0);
97920+ }
97921+}
97922+#endif
97923+
97924 int
97925 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
97926 unsigned long start, unsigned long end, unsigned long newflags)
97927@@ -263,11 +313,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
97928 int error;
97929 int dirty_accountable = 0;
97930
97931+#ifdef CONFIG_PAX_SEGMEXEC
97932+ struct vm_area_struct *vma_m = NULL;
97933+ unsigned long start_m, end_m;
97934+
97935+ start_m = start + SEGMEXEC_TASK_SIZE;
97936+ end_m = end + SEGMEXEC_TASK_SIZE;
97937+#endif
97938+
97939 if (newflags == oldflags) {
97940 *pprev = vma;
97941 return 0;
97942 }
97943
97944+ if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
97945+ struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
97946+
97947+ if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
97948+ return -ENOMEM;
97949+
97950+ if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
97951+ return -ENOMEM;
97952+ }
97953+
97954 /*
97955 * If we make a private mapping writable we increase our commit;
97956 * but (without finer accounting) cannot reduce our commit if we
97957@@ -284,6 +352,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
97958 }
97959 }
97960
97961+#ifdef CONFIG_PAX_SEGMEXEC
97962+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
97963+ if (start != vma->vm_start) {
97964+ error = split_vma(mm, vma, start, 1);
97965+ if (error)
97966+ goto fail;
97967+ BUG_ON(!*pprev || (*pprev)->vm_next == vma);
97968+ *pprev = (*pprev)->vm_next;
97969+ }
97970+
97971+ if (end != vma->vm_end) {
97972+ error = split_vma(mm, vma, end, 0);
97973+ if (error)
97974+ goto fail;
97975+ }
97976+
97977+ if (pax_find_mirror_vma(vma)) {
97978+ error = __do_munmap(mm, start_m, end_m - start_m);
97979+ if (error)
97980+ goto fail;
97981+ } else {
97982+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
97983+ if (!vma_m) {
97984+ error = -ENOMEM;
97985+ goto fail;
97986+ }
97987+ vma->vm_flags = newflags;
97988+ error = pax_mirror_vma(vma_m, vma);
97989+ if (error) {
97990+ vma->vm_flags = oldflags;
97991+ goto fail;
97992+ }
97993+ }
97994+ }
97995+#endif
97996+
97997 /*
97998 * First try to merge with previous and/or next vma.
97999 */
98000@@ -314,7 +418,19 @@ success:
98001 * vm_flags and vm_page_prot are protected by the mmap_sem
98002 * held in write mode.
98003 */
98004+
98005+#ifdef CONFIG_PAX_SEGMEXEC
98006+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
98007+ pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
98008+#endif
98009+
98010 vma->vm_flags = newflags;
98011+
98012+#ifdef CONFIG_PAX_MPROTECT
98013+ if (mm->binfmt && mm->binfmt->handle_mprotect)
98014+ mm->binfmt->handle_mprotect(vma, newflags);
98015+#endif
98016+
98017 dirty_accountable = vma_wants_writenotify(vma);
98018 vma_set_page_prot(vma);
98019
98020@@ -350,6 +466,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
98021 end = start + len;
98022 if (end <= start)
98023 return -ENOMEM;
98024+
98025+#ifdef CONFIG_PAX_SEGMEXEC
98026+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
98027+ if (end > SEGMEXEC_TASK_SIZE)
98028+ return -EINVAL;
98029+ } else
98030+#endif
98031+
98032+ if (end > TASK_SIZE)
98033+ return -EINVAL;
98034+
98035 if (!arch_validate_prot(prot))
98036 return -EINVAL;
98037
98038@@ -357,7 +484,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
98039 /*
98040 * Does the application expect PROT_READ to imply PROT_EXEC:
98041 */
98042- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
98043+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
98044 prot |= PROT_EXEC;
98045
98046 vm_flags = calc_vm_prot_bits(prot);
98047@@ -389,6 +516,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
98048 if (start > vma->vm_start)
98049 prev = vma;
98050
98051+#ifdef CONFIG_PAX_MPROTECT
98052+ if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
98053+ current->mm->binfmt->handle_mprotect(vma, vm_flags);
98054+#endif
98055+
98056 for (nstart = start ; ; ) {
98057 unsigned long newflags;
98058
98059@@ -399,6 +531,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
98060
98061 /* newflags >> 4 shift VM_MAY% in place of VM_% */
98062 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
98063+ if (prot & (PROT_WRITE | PROT_EXEC))
98064+ gr_log_rwxmprotect(vma);
98065+
98066+ error = -EACCES;
98067+ goto out;
98068+ }
98069+
98070+ if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
98071 error = -EACCES;
98072 goto out;
98073 }
98074@@ -413,6 +553,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
98075 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
98076 if (error)
98077 goto out;
98078+
98079+ track_exec_limit(current->mm, nstart, tmp, vm_flags);
98080+
98081 nstart = tmp;
98082
98083 if (nstart < prev->vm_end)
98084diff --git a/mm/mremap.c b/mm/mremap.c
98085index b147f66..98a695a 100644
98086--- a/mm/mremap.c
98087+++ b/mm/mremap.c
98088@@ -144,6 +144,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
98089 continue;
98090 pte = ptep_get_and_clear(mm, old_addr, old_pte);
98091 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
98092+
98093+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
98094+ if (!(__supported_pte_mask & _PAGE_NX) && pte_present(pte) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
98095+ pte = pte_exprotect(pte);
98096+#endif
98097+
98098 pte = move_soft_dirty_pte(pte);
98099 set_pte_at(mm, new_addr, new_pte, pte);
98100 }
98101@@ -345,6 +351,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
98102 if (is_vm_hugetlb_page(vma))
98103 goto Einval;
98104
98105+#ifdef CONFIG_PAX_SEGMEXEC
98106+ if (pax_find_mirror_vma(vma))
98107+ goto Einval;
98108+#endif
98109+
98110 /* We can't remap across vm area boundaries */
98111 if (old_len > vma->vm_end - addr)
98112 goto Efault;
98113@@ -400,20 +411,25 @@ static unsigned long mremap_to(unsigned long addr, unsigned long old_len,
98114 unsigned long ret = -EINVAL;
98115 unsigned long charged = 0;
98116 unsigned long map_flags;
98117+ unsigned long pax_task_size = TASK_SIZE;
98118
98119 if (new_addr & ~PAGE_MASK)
98120 goto out;
98121
98122- if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
98123+#ifdef CONFIG_PAX_SEGMEXEC
98124+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
98125+ pax_task_size = SEGMEXEC_TASK_SIZE;
98126+#endif
98127+
98128+ pax_task_size -= PAGE_SIZE;
98129+
98130+ if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
98131 goto out;
98132
98133 /* Check if the location we're moving into overlaps the
98134 * old location at all, and fail if it does.
98135 */
98136- if ((new_addr <= addr) && (new_addr+new_len) > addr)
98137- goto out;
98138-
98139- if ((addr <= new_addr) && (addr+old_len) > new_addr)
98140+ if (addr + old_len > new_addr && new_addr + new_len > addr)
98141 goto out;
98142
98143 ret = do_munmap(mm, new_addr, new_len);
98144@@ -482,6 +498,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
98145 unsigned long ret = -EINVAL;
98146 unsigned long charged = 0;
98147 bool locked = false;
98148+ unsigned long pax_task_size = TASK_SIZE;
98149
98150 if (flags & ~(MREMAP_FIXED | MREMAP_MAYMOVE))
98151 return ret;
98152@@ -503,6 +520,17 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
98153 if (!new_len)
98154 return ret;
98155
98156+#ifdef CONFIG_PAX_SEGMEXEC
98157+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
98158+ pax_task_size = SEGMEXEC_TASK_SIZE;
98159+#endif
98160+
98161+ pax_task_size -= PAGE_SIZE;
98162+
98163+ if (new_len > pax_task_size || addr > pax_task_size-new_len ||
98164+ old_len > pax_task_size || addr > pax_task_size-old_len)
98165+ return ret;
98166+
98167 down_write(&current->mm->mmap_sem);
98168
98169 if (flags & MREMAP_FIXED) {
98170@@ -553,6 +581,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
98171 new_addr = addr;
98172 }
98173 ret = addr;
98174+ track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
98175 goto out;
98176 }
98177 }
98178@@ -576,7 +605,12 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
98179 goto out;
98180 }
98181
98182+ map_flags = vma->vm_flags;
98183 ret = move_vma(vma, addr, old_len, new_len, new_addr, &locked);
98184+ if (!(ret & ~PAGE_MASK)) {
98185+ track_exec_limit(current->mm, addr, addr + old_len, 0UL);
98186+ track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
98187+ }
98188 }
98189 out:
98190 if (ret & ~PAGE_MASK)
98191diff --git a/mm/nommu.c b/mm/nommu.c
98192index bd1808e..b63d87c 100644
98193--- a/mm/nommu.c
98194+++ b/mm/nommu.c
98195@@ -70,7 +70,6 @@ int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
98196 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
98197 unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
98198 unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
98199-int heap_stack_gap = 0;
98200
98201 atomic_long_t mmap_pages_allocated;
98202
98203@@ -857,15 +856,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
98204 EXPORT_SYMBOL(find_vma);
98205
98206 /*
98207- * find a VMA
98208- * - we don't extend stack VMAs under NOMMU conditions
98209- */
98210-struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
98211-{
98212- return find_vma(mm, addr);
98213-}
98214-
98215-/*
98216 * expand a stack to a given address
98217 * - not supported under NOMMU conditions
98218 */
98219@@ -1572,6 +1562,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
98220
98221 /* most fields are the same, copy all, and then fixup */
98222 *new = *vma;
98223+ INIT_LIST_HEAD(&new->anon_vma_chain);
98224 *region = *vma->vm_region;
98225 new->vm_region = region;
98226
98227@@ -2002,8 +1993,8 @@ int generic_file_remap_pages(struct vm_area_struct *vma, unsigned long addr,
98228 }
98229 EXPORT_SYMBOL(generic_file_remap_pages);
98230
98231-static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
98232- unsigned long addr, void *buf, int len, int write)
98233+static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
98234+ unsigned long addr, void *buf, size_t len, int write)
98235 {
98236 struct vm_area_struct *vma;
98237
98238@@ -2044,8 +2035,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
98239 *
98240 * The caller must hold a reference on @mm.
98241 */
98242-int access_remote_vm(struct mm_struct *mm, unsigned long addr,
98243- void *buf, int len, int write)
98244+ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
98245+ void *buf, size_t len, int write)
98246 {
98247 return __access_remote_vm(NULL, mm, addr, buf, len, write);
98248 }
98249@@ -2054,7 +2045,7 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
98250 * Access another process' address space.
98251 * - source/target buffer must be kernel space
98252 */
98253-int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write)
98254+ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write)
98255 {
98256 struct mm_struct *mm;
98257
98258diff --git a/mm/page-writeback.c b/mm/page-writeback.c
98259index 19ceae8..70848ee 100644
98260--- a/mm/page-writeback.c
98261+++ b/mm/page-writeback.c
98262@@ -664,7 +664,7 @@ static long long pos_ratio_polynom(unsigned long setpoint,
98263 * card's bdi_dirty may rush to many times higher than bdi_setpoint.
98264 * - the bdi dirty thresh drops quickly due to change of JBOD workload
98265 */
98266-static unsigned long bdi_position_ratio(struct backing_dev_info *bdi,
98267+static unsigned long __intentional_overflow(-1) bdi_position_ratio(struct backing_dev_info *bdi,
98268 unsigned long thresh,
98269 unsigned long bg_thresh,
98270 unsigned long dirty,
98271diff --git a/mm/page_alloc.c b/mm/page_alloc.c
98272index 616a2c9..0e755f6 100644
98273--- a/mm/page_alloc.c
98274+++ b/mm/page_alloc.c
98275@@ -59,6 +59,7 @@
98276 #include <linux/page-debug-flags.h>
98277 #include <linux/hugetlb.h>
98278 #include <linux/sched/rt.h>
98279+#include <linux/random.h>
98280
98281 #include <asm/sections.h>
98282 #include <asm/tlbflush.h>
98283@@ -356,7 +357,7 @@ out:
98284 * This usage means that zero-order pages may not be compound.
98285 */
98286
98287-static void free_compound_page(struct page *page)
98288+void free_compound_page(struct page *page)
98289 {
98290 __free_pages_ok(page, compound_order(page));
98291 }
98292@@ -741,6 +742,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
98293 int i;
98294 int bad = 0;
98295
98296+#ifdef CONFIG_PAX_MEMORY_SANITIZE
98297+ unsigned long index = 1UL << order;
98298+#endif
98299+
98300 trace_mm_page_free(page, order);
98301 kmemcheck_free_shadow(page, order);
98302
98303@@ -757,6 +762,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
98304 debug_check_no_obj_freed(page_address(page),
98305 PAGE_SIZE << order);
98306 }
98307+
98308+#ifdef CONFIG_PAX_MEMORY_SANITIZE
98309+ for (; index; --index)
98310+ sanitize_highpage(page + index - 1);
98311+#endif
98312+
98313 arch_free_page(page, order);
98314 kernel_map_pages(page, 1 << order, 0);
98315
98316@@ -780,6 +791,20 @@ static void __free_pages_ok(struct page *page, unsigned int order)
98317 local_irq_restore(flags);
98318 }
98319
98320+#ifdef CONFIG_PAX_LATENT_ENTROPY
98321+bool __meminitdata extra_latent_entropy;
98322+
98323+static int __init setup_pax_extra_latent_entropy(char *str)
98324+{
98325+ extra_latent_entropy = true;
98326+ return 0;
98327+}
98328+early_param("pax_extra_latent_entropy", setup_pax_extra_latent_entropy);
98329+
98330+volatile u64 latent_entropy __latent_entropy;
98331+EXPORT_SYMBOL(latent_entropy);
98332+#endif
98333+
98334 void __init __free_pages_bootmem(struct page *page, unsigned int order)
98335 {
98336 unsigned int nr_pages = 1 << order;
98337@@ -795,6 +820,19 @@ void __init __free_pages_bootmem(struct page *page, unsigned int order)
98338 __ClearPageReserved(p);
98339 set_page_count(p, 0);
98340
98341+#ifdef CONFIG_PAX_LATENT_ENTROPY
98342+ if (extra_latent_entropy && !PageHighMem(page) && page_to_pfn(page) < 0x100000) {
98343+ u64 hash = 0;
98344+ size_t index, end = PAGE_SIZE * nr_pages / sizeof hash;
98345+ const u64 *data = lowmem_page_address(page);
98346+
98347+ for (index = 0; index < end; index++)
98348+ hash ^= hash + data[index];
98349+ latent_entropy ^= hash;
98350+ add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
98351+ }
98352+#endif
98353+
98354 page_zone(page)->managed_pages += nr_pages;
98355 set_page_refcounted(page);
98356 __free_pages(page, order);
98357@@ -923,8 +961,10 @@ static int prep_new_page(struct page *page, unsigned int order, gfp_t gfp_flags)
98358 arch_alloc_page(page, order);
98359 kernel_map_pages(page, 1 << order, 1);
98360
98361+#ifndef CONFIG_PAX_MEMORY_SANITIZE
98362 if (gfp_flags & __GFP_ZERO)
98363 prep_zero_page(page, order, gfp_flags);
98364+#endif
98365
98366 if (order && (gfp_flags & __GFP_COMP))
98367 prep_compound_page(page, order);
98368@@ -1602,7 +1642,7 @@ again:
98369 }
98370
98371 __mod_zone_page_state(zone, NR_ALLOC_BATCH, -(1 << order));
98372- if (atomic_long_read(&zone->vm_stat[NR_ALLOC_BATCH]) <= 0 &&
98373+ if (atomic_long_read_unchecked(&zone->vm_stat[NR_ALLOC_BATCH]) <= 0 &&
98374 !test_bit(ZONE_FAIR_DEPLETED, &zone->flags))
98375 set_bit(ZONE_FAIR_DEPLETED, &zone->flags);
98376
98377@@ -1923,7 +1963,7 @@ static void reset_alloc_batches(struct zone *preferred_zone)
98378 do {
98379 mod_zone_page_state(zone, NR_ALLOC_BATCH,
98380 high_wmark_pages(zone) - low_wmark_pages(zone) -
98381- atomic_long_read(&zone->vm_stat[NR_ALLOC_BATCH]));
98382+ atomic_long_read_unchecked(&zone->vm_stat[NR_ALLOC_BATCH]));
98383 clear_bit(ZONE_FAIR_DEPLETED, &zone->flags);
98384 } while (zone++ != preferred_zone);
98385 }
98386@@ -5698,7 +5738,7 @@ static void __setup_per_zone_wmarks(void)
98387
98388 __mod_zone_page_state(zone, NR_ALLOC_BATCH,
98389 high_wmark_pages(zone) - low_wmark_pages(zone) -
98390- atomic_long_read(&zone->vm_stat[NR_ALLOC_BATCH]));
98391+ atomic_long_read_unchecked(&zone->vm_stat[NR_ALLOC_BATCH]));
98392
98393 setup_zone_migrate_reserve(zone);
98394 spin_unlock_irqrestore(&zone->lock, flags);
98395diff --git a/mm/percpu.c b/mm/percpu.c
98396index 014bab6..db5a76f 100644
98397--- a/mm/percpu.c
98398+++ b/mm/percpu.c
98399@@ -131,7 +131,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
98400 static unsigned int pcpu_high_unit_cpu __read_mostly;
98401
98402 /* the address of the first chunk which starts with the kernel static area */
98403-void *pcpu_base_addr __read_mostly;
98404+void *pcpu_base_addr __read_only;
98405 EXPORT_SYMBOL_GPL(pcpu_base_addr);
98406
98407 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
98408diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
98409index 5077afc..846c9ef 100644
98410--- a/mm/process_vm_access.c
98411+++ b/mm/process_vm_access.c
98412@@ -13,6 +13,7 @@
98413 #include <linux/uio.h>
98414 #include <linux/sched.h>
98415 #include <linux/highmem.h>
98416+#include <linux/security.h>
98417 #include <linux/ptrace.h>
98418 #include <linux/slab.h>
98419 #include <linux/syscalls.h>
98420@@ -157,19 +158,19 @@ static ssize_t process_vm_rw_core(pid_t pid, struct iov_iter *iter,
98421 ssize_t iov_len;
98422 size_t total_len = iov_iter_count(iter);
98423
98424+ return -ENOSYS; // PaX: until properly audited
98425+
98426 /*
98427 * Work out how many pages of struct pages we're going to need
98428 * when eventually calling get_user_pages
98429 */
98430 for (i = 0; i < riovcnt; i++) {
98431 iov_len = rvec[i].iov_len;
98432- if (iov_len > 0) {
98433- nr_pages_iov = ((unsigned long)rvec[i].iov_base
98434- + iov_len)
98435- / PAGE_SIZE - (unsigned long)rvec[i].iov_base
98436- / PAGE_SIZE + 1;
98437- nr_pages = max(nr_pages, nr_pages_iov);
98438- }
98439+ if (iov_len <= 0)
98440+ continue;
98441+ nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
98442+ (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
98443+ nr_pages = max(nr_pages, nr_pages_iov);
98444 }
98445
98446 if (nr_pages == 0)
98447@@ -197,6 +198,11 @@ static ssize_t process_vm_rw_core(pid_t pid, struct iov_iter *iter,
98448 goto free_proc_pages;
98449 }
98450
98451+ if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
98452+ rc = -EPERM;
98453+ goto put_task_struct;
98454+ }
98455+
98456 mm = mm_access(task, PTRACE_MODE_ATTACH);
98457 if (!mm || IS_ERR(mm)) {
98458 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
98459diff --git a/mm/rmap.c b/mm/rmap.c
98460index 3e4c721..a5e3e39 100644
98461--- a/mm/rmap.c
98462+++ b/mm/rmap.c
98463@@ -164,6 +164,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
98464 struct anon_vma *anon_vma = vma->anon_vma;
98465 struct anon_vma_chain *avc;
98466
98467+#ifdef CONFIG_PAX_SEGMEXEC
98468+ struct anon_vma_chain *avc_m = NULL;
98469+#endif
98470+
98471 might_sleep();
98472 if (unlikely(!anon_vma)) {
98473 struct mm_struct *mm = vma->vm_mm;
98474@@ -173,6 +177,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
98475 if (!avc)
98476 goto out_enomem;
98477
98478+#ifdef CONFIG_PAX_SEGMEXEC
98479+ avc_m = anon_vma_chain_alloc(GFP_KERNEL);
98480+ if (!avc_m)
98481+ goto out_enomem_free_avc;
98482+#endif
98483+
98484 anon_vma = find_mergeable_anon_vma(vma);
98485 allocated = NULL;
98486 if (!anon_vma) {
98487@@ -186,6 +196,18 @@ int anon_vma_prepare(struct vm_area_struct *vma)
98488 /* page_table_lock to protect against threads */
98489 spin_lock(&mm->page_table_lock);
98490 if (likely(!vma->anon_vma)) {
98491+
98492+#ifdef CONFIG_PAX_SEGMEXEC
98493+ struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
98494+
98495+ if (vma_m) {
98496+ BUG_ON(vma_m->anon_vma);
98497+ vma_m->anon_vma = anon_vma;
98498+ anon_vma_chain_link(vma_m, avc_m, anon_vma);
98499+ avc_m = NULL;
98500+ }
98501+#endif
98502+
98503 vma->anon_vma = anon_vma;
98504 anon_vma_chain_link(vma, avc, anon_vma);
98505 allocated = NULL;
98506@@ -196,12 +218,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
98507
98508 if (unlikely(allocated))
98509 put_anon_vma(allocated);
98510+
98511+#ifdef CONFIG_PAX_SEGMEXEC
98512+ if (unlikely(avc_m))
98513+ anon_vma_chain_free(avc_m);
98514+#endif
98515+
98516 if (unlikely(avc))
98517 anon_vma_chain_free(avc);
98518 }
98519 return 0;
98520
98521 out_enomem_free_avc:
98522+
98523+#ifdef CONFIG_PAX_SEGMEXEC
98524+ if (avc_m)
98525+ anon_vma_chain_free(avc_m);
98526+#endif
98527+
98528 anon_vma_chain_free(avc);
98529 out_enomem:
98530 return -ENOMEM;
98531@@ -237,7 +271,7 @@ static inline void unlock_anon_vma_root(struct anon_vma *root)
98532 * Attach the anon_vmas from src to dst.
98533 * Returns 0 on success, -ENOMEM on failure.
98534 */
98535-int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
98536+int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
98537 {
98538 struct anon_vma_chain *avc, *pavc;
98539 struct anon_vma *root = NULL;
98540@@ -270,7 +304,7 @@ int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
98541 * the corresponding VMA in the parent process is attached to.
98542 * Returns 0 on success, non-zero on failure.
98543 */
98544-int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
98545+int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
98546 {
98547 struct anon_vma_chain *avc;
98548 struct anon_vma *anon_vma;
98549@@ -376,8 +410,10 @@ static void anon_vma_ctor(void *data)
98550 void __init anon_vma_init(void)
98551 {
98552 anon_vma_cachep = kmem_cache_create("anon_vma", sizeof(struct anon_vma),
98553- 0, SLAB_DESTROY_BY_RCU|SLAB_PANIC, anon_vma_ctor);
98554- anon_vma_chain_cachep = KMEM_CACHE(anon_vma_chain, SLAB_PANIC);
98555+ 0, SLAB_DESTROY_BY_RCU|SLAB_PANIC|SLAB_NO_SANITIZE,
98556+ anon_vma_ctor);
98557+ anon_vma_chain_cachep = KMEM_CACHE(anon_vma_chain,
98558+ SLAB_PANIC|SLAB_NO_SANITIZE);
98559 }
98560
98561 /*
98562diff --git a/mm/shmem.c b/mm/shmem.c
98563index 185836b..d7255a1 100644
98564--- a/mm/shmem.c
98565+++ b/mm/shmem.c
98566@@ -33,7 +33,7 @@
98567 #include <linux/swap.h>
98568 #include <linux/aio.h>
98569
98570-static struct vfsmount *shm_mnt;
98571+struct vfsmount *shm_mnt;
98572
98573 #ifdef CONFIG_SHMEM
98574 /*
98575@@ -80,7 +80,7 @@ static struct vfsmount *shm_mnt;
98576 #define BOGO_DIRENT_SIZE 20
98577
98578 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
98579-#define SHORT_SYMLINK_LEN 128
98580+#define SHORT_SYMLINK_LEN 64
98581
98582 /*
98583 * shmem_fallocate communicates with shmem_fault or shmem_writepage via
98584@@ -2558,6 +2558,11 @@ static const struct xattr_handler *shmem_xattr_handlers[] = {
98585 static int shmem_xattr_validate(const char *name)
98586 {
98587 struct { const char *prefix; size_t len; } arr[] = {
98588+
98589+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
98590+ { XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN},
98591+#endif
98592+
98593 { XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN },
98594 { XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN }
98595 };
98596@@ -2613,6 +2618,15 @@ static int shmem_setxattr(struct dentry *dentry, const char *name,
98597 if (err)
98598 return err;
98599
98600+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
98601+ if (!strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN)) {
98602+ if (strcmp(name, XATTR_NAME_PAX_FLAGS))
98603+ return -EOPNOTSUPP;
98604+ if (size > 8)
98605+ return -EINVAL;
98606+ }
98607+#endif
98608+
98609 return simple_xattr_set(&info->xattrs, name, value, size, flags);
98610 }
98611
98612@@ -2996,8 +3010,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
98613 int err = -ENOMEM;
98614
98615 /* Round up to L1_CACHE_BYTES to resist false sharing */
98616- sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
98617- L1_CACHE_BYTES), GFP_KERNEL);
98618+ sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
98619 if (!sbinfo)
98620 return -ENOMEM;
98621
98622diff --git a/mm/slab.c b/mm/slab.c
98623index f34e053..78a3839 100644
98624--- a/mm/slab.c
98625+++ b/mm/slab.c
98626@@ -314,10 +314,12 @@ static void kmem_cache_node_init(struct kmem_cache_node *parent)
98627 if ((x)->max_freeable < i) \
98628 (x)->max_freeable = i; \
98629 } while (0)
98630-#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
98631-#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
98632-#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
98633-#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
98634+#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
98635+#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
98636+#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
98637+#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
98638+#define STATS_INC_SANITIZED(x) atomic_inc_unchecked(&(x)->sanitized)
98639+#define STATS_INC_NOT_SANITIZED(x) atomic_inc_unchecked(&(x)->not_sanitized)
98640 #else
98641 #define STATS_INC_ACTIVE(x) do { } while (0)
98642 #define STATS_DEC_ACTIVE(x) do { } while (0)
98643@@ -334,6 +336,8 @@ static void kmem_cache_node_init(struct kmem_cache_node *parent)
98644 #define STATS_INC_ALLOCMISS(x) do { } while (0)
98645 #define STATS_INC_FREEHIT(x) do { } while (0)
98646 #define STATS_INC_FREEMISS(x) do { } while (0)
98647+#define STATS_INC_SANITIZED(x) do { } while (0)
98648+#define STATS_INC_NOT_SANITIZED(x) do { } while (0)
98649 #endif
98650
98651 #if DEBUG
98652@@ -450,7 +454,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct page *page,
98653 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
98654 */
98655 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
98656- const struct page *page, void *obj)
98657+ const struct page *page, const void *obj)
98658 {
98659 u32 offset = (obj - page->s_mem);
98660 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
98661@@ -1438,7 +1442,7 @@ void __init kmem_cache_init(void)
98662 * structures first. Without this, further allocations will bug.
98663 */
98664 kmalloc_caches[INDEX_NODE] = create_kmalloc_cache("kmalloc-node",
98665- kmalloc_size(INDEX_NODE), ARCH_KMALLOC_FLAGS);
98666+ kmalloc_size(INDEX_NODE), SLAB_USERCOPY | ARCH_KMALLOC_FLAGS);
98667 slab_state = PARTIAL_NODE;
98668
98669 slab_early_init = 0;
98670@@ -2059,7 +2063,7 @@ __kmem_cache_alias(const char *name, size_t size, size_t align,
98671
98672 cachep = find_mergeable(size, align, flags, name, ctor);
98673 if (cachep) {
98674- cachep->refcount++;
98675+ atomic_inc(&cachep->refcount);
98676
98677 /*
98678 * Adjust the object sizes so that we clear
98679@@ -3352,6 +3356,20 @@ static inline void __cache_free(struct kmem_cache *cachep, void *objp,
98680 struct array_cache *ac = cpu_cache_get(cachep);
98681
98682 check_irq_off();
98683+
98684+#ifdef CONFIG_PAX_MEMORY_SANITIZE
98685+ if (cachep->flags & (SLAB_POISON | SLAB_NO_SANITIZE))
98686+ STATS_INC_NOT_SANITIZED(cachep);
98687+ else {
98688+ memset(objp, PAX_MEMORY_SANITIZE_VALUE, cachep->object_size);
98689+
98690+ if (cachep->ctor)
98691+ cachep->ctor(objp);
98692+
98693+ STATS_INC_SANITIZED(cachep);
98694+ }
98695+#endif
98696+
98697 kmemleak_free_recursive(objp, cachep->flags);
98698 objp = cache_free_debugcheck(cachep, objp, caller);
98699
98700@@ -3557,6 +3575,7 @@ void kfree(const void *objp)
98701
98702 if (unlikely(ZERO_OR_NULL_PTR(objp)))
98703 return;
98704+ VM_BUG_ON(!virt_addr_valid(objp));
98705 local_irq_save(flags);
98706 kfree_debugcheck(objp);
98707 c = virt_to_cache(objp);
98708@@ -3979,14 +3998,22 @@ void slabinfo_show_stats(struct seq_file *m, struct kmem_cache *cachep)
98709 }
98710 /* cpu stats */
98711 {
98712- unsigned long allochit = atomic_read(&cachep->allochit);
98713- unsigned long allocmiss = atomic_read(&cachep->allocmiss);
98714- unsigned long freehit = atomic_read(&cachep->freehit);
98715- unsigned long freemiss = atomic_read(&cachep->freemiss);
98716+ unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
98717+ unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
98718+ unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
98719+ unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
98720
98721 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
98722 allochit, allocmiss, freehit, freemiss);
98723 }
98724+#ifdef CONFIG_PAX_MEMORY_SANITIZE
98725+ {
98726+ unsigned long sanitized = atomic_read_unchecked(&cachep->sanitized);
98727+ unsigned long not_sanitized = atomic_read_unchecked(&cachep->not_sanitized);
98728+
98729+ seq_printf(m, " : pax %6lu %6lu", sanitized, not_sanitized);
98730+ }
98731+#endif
98732 #endif
98733 }
98734
98735@@ -4200,13 +4227,69 @@ static const struct file_operations proc_slabstats_operations = {
98736 static int __init slab_proc_init(void)
98737 {
98738 #ifdef CONFIG_DEBUG_SLAB_LEAK
98739- proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
98740+ proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
98741 #endif
98742 return 0;
98743 }
98744 module_init(slab_proc_init);
98745 #endif
98746
98747+bool is_usercopy_object(const void *ptr)
98748+{
98749+ struct page *page;
98750+ struct kmem_cache *cachep;
98751+
98752+ if (ZERO_OR_NULL_PTR(ptr))
98753+ return false;
98754+
98755+ if (!slab_is_available())
98756+ return false;
98757+
98758+ if (!virt_addr_valid(ptr))
98759+ return false;
98760+
98761+ page = virt_to_head_page(ptr);
98762+
98763+ if (!PageSlab(page))
98764+ return false;
98765+
98766+ cachep = page->slab_cache;
98767+ return cachep->flags & SLAB_USERCOPY;
98768+}
98769+
98770+#ifdef CONFIG_PAX_USERCOPY
98771+const char *check_heap_object(const void *ptr, unsigned long n)
98772+{
98773+ struct page *page;
98774+ struct kmem_cache *cachep;
98775+ unsigned int objnr;
98776+ unsigned long offset;
98777+
98778+ if (ZERO_OR_NULL_PTR(ptr))
98779+ return "<null>";
98780+
98781+ if (!virt_addr_valid(ptr))
98782+ return NULL;
98783+
98784+ page = virt_to_head_page(ptr);
98785+
98786+ if (!PageSlab(page))
98787+ return NULL;
98788+
98789+ cachep = page->slab_cache;
98790+ if (!(cachep->flags & SLAB_USERCOPY))
98791+ return cachep->name;
98792+
98793+ objnr = obj_to_index(cachep, page, ptr);
98794+ BUG_ON(objnr >= cachep->num);
98795+ offset = ptr - index_to_obj(cachep, page, objnr) - obj_offset(cachep);
98796+ if (offset <= cachep->object_size && n <= cachep->object_size - offset)
98797+ return NULL;
98798+
98799+ return cachep->name;
98800+}
98801+#endif
98802+
98803 /**
98804 * ksize - get the actual amount of memory allocated for a given object
98805 * @objp: Pointer to the object
98806diff --git a/mm/slab.h b/mm/slab.h
98807index ab019e6..fbcac34 100644
98808--- a/mm/slab.h
98809+++ b/mm/slab.h
98810@@ -22,7 +22,7 @@ struct kmem_cache {
98811 unsigned int align; /* Alignment as calculated */
98812 unsigned long flags; /* Active flags on the slab */
98813 const char *name; /* Slab name for sysfs */
98814- int refcount; /* Use counter */
98815+ atomic_t refcount; /* Use counter */
98816 void (*ctor)(void *); /* Called on object slot creation */
98817 struct list_head list; /* List of all slab caches on the system */
98818 };
98819@@ -66,6 +66,20 @@ extern struct list_head slab_caches;
98820 /* The slab cache that manages slab cache information */
98821 extern struct kmem_cache *kmem_cache;
98822
98823+#ifdef CONFIG_PAX_MEMORY_SANITIZE
98824+#ifdef CONFIG_X86_64
98825+#define PAX_MEMORY_SANITIZE_VALUE '\xfe'
98826+#else
98827+#define PAX_MEMORY_SANITIZE_VALUE '\xff'
98828+#endif
98829+enum pax_sanitize_mode {
98830+ PAX_SANITIZE_SLAB_OFF = 0,
98831+ PAX_SANITIZE_SLAB_FAST,
98832+ PAX_SANITIZE_SLAB_FULL,
98833+};
98834+extern enum pax_sanitize_mode pax_sanitize_slab;
98835+#endif
98836+
98837 unsigned long calculate_alignment(unsigned long flags,
98838 unsigned long align, unsigned long size);
98839
98840@@ -116,7 +130,8 @@ static inline unsigned long kmem_cache_flags(unsigned long object_size,
98841
98842 /* Legal flag mask for kmem_cache_create(), for various configurations */
98843 #define SLAB_CORE_FLAGS (SLAB_HWCACHE_ALIGN | SLAB_CACHE_DMA | SLAB_PANIC | \
98844- SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS )
98845+ SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS | \
98846+ SLAB_USERCOPY | SLAB_NO_SANITIZE)
98847
98848 #if defined(CONFIG_DEBUG_SLAB)
98849 #define SLAB_DEBUG_FLAGS (SLAB_RED_ZONE | SLAB_POISON | SLAB_STORE_USER)
98850@@ -300,6 +315,9 @@ static inline struct kmem_cache *cache_from_obj(struct kmem_cache *s, void *x)
98851 return s;
98852
98853 page = virt_to_head_page(x);
98854+
98855+ BUG_ON(!PageSlab(page));
98856+
98857 cachep = page->slab_cache;
98858 if (slab_equal_or_root(cachep, s))
98859 return cachep;
98860diff --git a/mm/slab_common.c b/mm/slab_common.c
98861index dcdab81..3576646 100644
98862--- a/mm/slab_common.c
98863+++ b/mm/slab_common.c
98864@@ -25,11 +25,35 @@
98865
98866 #include "slab.h"
98867
98868-enum slab_state slab_state;
98869+enum slab_state slab_state __read_only;
98870 LIST_HEAD(slab_caches);
98871 DEFINE_MUTEX(slab_mutex);
98872 struct kmem_cache *kmem_cache;
98873
98874+#ifdef CONFIG_PAX_MEMORY_SANITIZE
98875+enum pax_sanitize_mode pax_sanitize_slab __read_only = PAX_SANITIZE_SLAB_FAST;
98876+static int __init pax_sanitize_slab_setup(char *str)
98877+{
98878+ if (!str)
98879+ return 0;
98880+
98881+ if (!strcmp(str, "0") || !strcmp(str, "off")) {
98882+ pr_info("PaX slab sanitization: %s\n", "disabled");
98883+ pax_sanitize_slab = PAX_SANITIZE_SLAB_OFF;
98884+ } else if (!strcmp(str, "1") || !strcmp(str, "fast")) {
98885+ pr_info("PaX slab sanitization: %s\n", "fast");
98886+ pax_sanitize_slab = PAX_SANITIZE_SLAB_FAST;
98887+ } else if (!strcmp(str, "full")) {
98888+ pr_info("PaX slab sanitization: %s\n", "full");
98889+ pax_sanitize_slab = PAX_SANITIZE_SLAB_FULL;
98890+ } else
98891+ pr_err("PaX slab sanitization: unsupported option '%s'\n", str);
98892+
98893+ return 0;
98894+}
98895+early_param("pax_sanitize_slab", pax_sanitize_slab_setup);
98896+#endif
98897+
98898 /*
98899 * Set of flags that will prevent slab merging
98900 */
98901@@ -44,7 +68,7 @@ struct kmem_cache *kmem_cache;
98902 * Merge control. If this is set then no merging of slab caches will occur.
98903 * (Could be removed. This was introduced to pacify the merge skeptics.)
98904 */
98905-static int slab_nomerge;
98906+static int slab_nomerge = 1;
98907
98908 static int __init setup_slab_nomerge(char *str)
98909 {
98910@@ -218,7 +242,7 @@ int slab_unmergeable(struct kmem_cache *s)
98911 /*
98912 * We may have set a slab to be unmergeable during bootstrap.
98913 */
98914- if (s->refcount < 0)
98915+ if (atomic_read(&s->refcount) < 0)
98916 return 1;
98917
98918 return 0;
98919@@ -322,7 +346,7 @@ do_kmem_cache_create(char *name, size_t object_size, size_t size, size_t align,
98920 if (err)
98921 goto out_free_cache;
98922
98923- s->refcount = 1;
98924+ atomic_set(&s->refcount, 1);
98925 list_add(&s->list, &slab_caches);
98926 out:
98927 if (err)
98928@@ -386,6 +410,13 @@ kmem_cache_create(const char *name, size_t size, size_t align,
98929 */
98930 flags &= CACHE_CREATE_MASK;
98931
98932+#ifdef CONFIG_PAX_MEMORY_SANITIZE
98933+ if (pax_sanitize_slab == PAX_SANITIZE_SLAB_OFF || (flags & SLAB_DESTROY_BY_RCU))
98934+ flags |= SLAB_NO_SANITIZE;
98935+ else if (pax_sanitize_slab == PAX_SANITIZE_SLAB_FULL)
98936+ flags &= ~SLAB_NO_SANITIZE;
98937+#endif
98938+
98939 s = __kmem_cache_alias(name, size, align, flags, ctor);
98940 if (s)
98941 goto out_unlock;
98942@@ -505,8 +536,7 @@ void kmem_cache_destroy(struct kmem_cache *s)
98943
98944 mutex_lock(&slab_mutex);
98945
98946- s->refcount--;
98947- if (s->refcount)
98948+ if (!atomic_dec_and_test(&s->refcount))
98949 goto out_unlock;
98950
98951 if (memcg_cleanup_cache_params(s) != 0)
98952@@ -526,7 +556,7 @@ void kmem_cache_destroy(struct kmem_cache *s)
98953 rcu_barrier();
98954
98955 memcg_free_cache_params(s);
98956-#ifdef SLAB_SUPPORTS_SYSFS
98957+#if defined(SLAB_SUPPORTS_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
98958 sysfs_slab_remove(s);
98959 #else
98960 slab_kmem_cache_release(s);
98961@@ -582,7 +612,7 @@ void __init create_boot_cache(struct kmem_cache *s, const char *name, size_t siz
98962 panic("Creation of kmalloc slab %s size=%zu failed. Reason %d\n",
98963 name, size, err);
98964
98965- s->refcount = -1; /* Exempt from merging for now */
98966+ atomic_set(&s->refcount, -1); /* Exempt from merging for now */
98967 }
98968
98969 struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
98970@@ -595,7 +625,7 @@ struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
98971
98972 create_boot_cache(s, name, size, flags);
98973 list_add(&s->list, &slab_caches);
98974- s->refcount = 1;
98975+ atomic_set(&s->refcount, 1);
98976 return s;
98977 }
98978
98979@@ -607,6 +637,11 @@ struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
98980 EXPORT_SYMBOL(kmalloc_dma_caches);
98981 #endif
98982
98983+#ifdef CONFIG_PAX_USERCOPY_SLABS
98984+struct kmem_cache *kmalloc_usercopy_caches[KMALLOC_SHIFT_HIGH + 1];
98985+EXPORT_SYMBOL(kmalloc_usercopy_caches);
98986+#endif
98987+
98988 /*
98989 * Conversion table for small slabs sizes / 8 to the index in the
98990 * kmalloc array. This is necessary for slabs < 192 since we have non power
98991@@ -671,6 +706,13 @@ struct kmem_cache *kmalloc_slab(size_t size, gfp_t flags)
98992 return kmalloc_dma_caches[index];
98993
98994 #endif
98995+
98996+#ifdef CONFIG_PAX_USERCOPY_SLABS
98997+ if (unlikely((flags & GFP_USERCOPY)))
98998+ return kmalloc_usercopy_caches[index];
98999+
99000+#endif
99001+
99002 return kmalloc_caches[index];
99003 }
99004
99005@@ -727,7 +769,7 @@ void __init create_kmalloc_caches(unsigned long flags)
99006 for (i = KMALLOC_SHIFT_LOW; i <= KMALLOC_SHIFT_HIGH; i++) {
99007 if (!kmalloc_caches[i]) {
99008 kmalloc_caches[i] = create_kmalloc_cache(NULL,
99009- 1 << i, flags);
99010+ 1 << i, SLAB_USERCOPY | flags);
99011 }
99012
99013 /*
99014@@ -736,10 +778,10 @@ void __init create_kmalloc_caches(unsigned long flags)
99015 * earlier power of two caches
99016 */
99017 if (KMALLOC_MIN_SIZE <= 32 && !kmalloc_caches[1] && i == 6)
99018- kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, flags);
99019+ kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, SLAB_USERCOPY | flags);
99020
99021 if (KMALLOC_MIN_SIZE <= 64 && !kmalloc_caches[2] && i == 7)
99022- kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, flags);
99023+ kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, SLAB_USERCOPY | flags);
99024 }
99025
99026 /* Kmalloc array is now usable */
99027@@ -772,6 +814,23 @@ void __init create_kmalloc_caches(unsigned long flags)
99028 }
99029 }
99030 #endif
99031+
99032+#ifdef CONFIG_PAX_USERCOPY_SLABS
99033+ for (i = 0; i <= KMALLOC_SHIFT_HIGH; i++) {
99034+ struct kmem_cache *s = kmalloc_caches[i];
99035+
99036+ if (s) {
99037+ int size = kmalloc_size(i);
99038+ char *n = kasprintf(GFP_NOWAIT,
99039+ "usercopy-kmalloc-%d", size);
99040+
99041+ BUG_ON(!n);
99042+ kmalloc_usercopy_caches[i] = create_kmalloc_cache(n,
99043+ size, SLAB_USERCOPY | flags);
99044+ }
99045+ }
99046+#endif
99047+
99048 }
99049 #endif /* !CONFIG_SLOB */
99050
99051@@ -830,6 +889,9 @@ void print_slabinfo_header(struct seq_file *m)
99052 seq_puts(m, " : globalstat <listallocs> <maxobjs> <grown> <reaped> "
99053 "<error> <maxfreeable> <nodeallocs> <remotefrees> <alienoverflow>");
99054 seq_puts(m, " : cpustat <allochit> <allocmiss> <freehit> <freemiss>");
99055+#ifdef CONFIG_PAX_MEMORY_SANITIZE
99056+ seq_puts(m, " : pax <sanitized> <not_sanitized>");
99057+#endif
99058 #endif
99059 seq_putc(m, '\n');
99060 }
99061diff --git a/mm/slob.c b/mm/slob.c
99062index 96a8620..3e7e663 100644
99063--- a/mm/slob.c
99064+++ b/mm/slob.c
99065@@ -157,7 +157,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
99066 /*
99067 * Return the size of a slob block.
99068 */
99069-static slobidx_t slob_units(slob_t *s)
99070+static slobidx_t slob_units(const slob_t *s)
99071 {
99072 if (s->units > 0)
99073 return s->units;
99074@@ -167,7 +167,7 @@ static slobidx_t slob_units(slob_t *s)
99075 /*
99076 * Return the next free slob block pointer after this one.
99077 */
99078-static slob_t *slob_next(slob_t *s)
99079+static slob_t *slob_next(const slob_t *s)
99080 {
99081 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
99082 slobidx_t next;
99083@@ -182,14 +182,14 @@ static slob_t *slob_next(slob_t *s)
99084 /*
99085 * Returns true if s is the last free block in its page.
99086 */
99087-static int slob_last(slob_t *s)
99088+static int slob_last(const slob_t *s)
99089 {
99090 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
99091 }
99092
99093-static void *slob_new_pages(gfp_t gfp, int order, int node)
99094+static struct page *slob_new_pages(gfp_t gfp, unsigned int order, int node)
99095 {
99096- void *page;
99097+ struct page *page;
99098
99099 #ifdef CONFIG_NUMA
99100 if (node != NUMA_NO_NODE)
99101@@ -201,14 +201,18 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
99102 if (!page)
99103 return NULL;
99104
99105- return page_address(page);
99106+ __SetPageSlab(page);
99107+ return page;
99108 }
99109
99110-static void slob_free_pages(void *b, int order)
99111+static void slob_free_pages(struct page *sp, int order)
99112 {
99113 if (current->reclaim_state)
99114 current->reclaim_state->reclaimed_slab += 1 << order;
99115- free_pages((unsigned long)b, order);
99116+ __ClearPageSlab(sp);
99117+ page_mapcount_reset(sp);
99118+ sp->private = 0;
99119+ __free_pages(sp, order);
99120 }
99121
99122 /*
99123@@ -313,15 +317,15 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
99124
99125 /* Not enough space: must allocate a new page */
99126 if (!b) {
99127- b = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
99128- if (!b)
99129+ sp = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
99130+ if (!sp)
99131 return NULL;
99132- sp = virt_to_page(b);
99133- __SetPageSlab(sp);
99134+ b = page_address(sp);
99135
99136 spin_lock_irqsave(&slob_lock, flags);
99137 sp->units = SLOB_UNITS(PAGE_SIZE);
99138 sp->freelist = b;
99139+ sp->private = 0;
99140 INIT_LIST_HEAD(&sp->lru);
99141 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
99142 set_slob_page_free(sp, slob_list);
99143@@ -337,7 +341,7 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
99144 /*
99145 * slob_free: entry point into the slob allocator.
99146 */
99147-static void slob_free(void *block, int size)
99148+static void slob_free(struct kmem_cache *c, void *block, int size)
99149 {
99150 struct page *sp;
99151 slob_t *prev, *next, *b = (slob_t *)block;
99152@@ -359,12 +363,15 @@ static void slob_free(void *block, int size)
99153 if (slob_page_free(sp))
99154 clear_slob_page_free(sp);
99155 spin_unlock_irqrestore(&slob_lock, flags);
99156- __ClearPageSlab(sp);
99157- page_mapcount_reset(sp);
99158- slob_free_pages(b, 0);
99159+ slob_free_pages(sp, 0);
99160 return;
99161 }
99162
99163+#ifdef CONFIG_PAX_MEMORY_SANITIZE
99164+ if (pax_sanitize_slab && !(c && (c->flags & SLAB_NO_SANITIZE)))
99165+ memset(block, PAX_MEMORY_SANITIZE_VALUE, size);
99166+#endif
99167+
99168 if (!slob_page_free(sp)) {
99169 /* This slob page is about to become partially free. Easy! */
99170 sp->units = units;
99171@@ -424,11 +431,10 @@ out:
99172 */
99173
99174 static __always_inline void *
99175-__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
99176+__do_kmalloc_node_align(size_t size, gfp_t gfp, int node, unsigned long caller, int align)
99177 {
99178- unsigned int *m;
99179- int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
99180- void *ret;
99181+ slob_t *m;
99182+ void *ret = NULL;
99183
99184 gfp &= gfp_allowed_mask;
99185
99186@@ -442,23 +448,41 @@ __do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
99187
99188 if (!m)
99189 return NULL;
99190- *m = size;
99191+ BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
99192+ BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
99193+ m[0].units = size;
99194+ m[1].units = align;
99195 ret = (void *)m + align;
99196
99197 trace_kmalloc_node(caller, ret,
99198 size, size + align, gfp, node);
99199 } else {
99200 unsigned int order = get_order(size);
99201+ struct page *page;
99202
99203 if (likely(order))
99204 gfp |= __GFP_COMP;
99205- ret = slob_new_pages(gfp, order, node);
99206+ page = slob_new_pages(gfp, order, node);
99207+ if (page) {
99208+ ret = page_address(page);
99209+ page->private = size;
99210+ }
99211
99212 trace_kmalloc_node(caller, ret,
99213 size, PAGE_SIZE << order, gfp, node);
99214 }
99215
99216- kmemleak_alloc(ret, size, 1, gfp);
99217+ return ret;
99218+}
99219+
99220+static __always_inline void *
99221+__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
99222+{
99223+ int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
99224+ void *ret = __do_kmalloc_node_align(size, gfp, node, caller, align);
99225+
99226+ if (!ZERO_OR_NULL_PTR(ret))
99227+ kmemleak_alloc(ret, size, 1, gfp);
99228 return ret;
99229 }
99230
99231@@ -491,34 +515,112 @@ void kfree(const void *block)
99232 return;
99233 kmemleak_free(block);
99234
99235+ VM_BUG_ON(!virt_addr_valid(block));
99236 sp = virt_to_page(block);
99237- if (PageSlab(sp)) {
99238+ VM_BUG_ON(!PageSlab(sp));
99239+ if (!sp->private) {
99240 int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
99241- unsigned int *m = (unsigned int *)(block - align);
99242- slob_free(m, *m + align);
99243- } else
99244+ slob_t *m = (slob_t *)(block - align);
99245+ slob_free(NULL, m, m[0].units + align);
99246+ } else {
99247+ __ClearPageSlab(sp);
99248+ page_mapcount_reset(sp);
99249+ sp->private = 0;
99250 __free_pages(sp, compound_order(sp));
99251+ }
99252 }
99253 EXPORT_SYMBOL(kfree);
99254
99255+bool is_usercopy_object(const void *ptr)
99256+{
99257+ if (!slab_is_available())
99258+ return false;
99259+
99260+ // PAX: TODO
99261+
99262+ return false;
99263+}
99264+
99265+#ifdef CONFIG_PAX_USERCOPY
99266+const char *check_heap_object(const void *ptr, unsigned long n)
99267+{
99268+ struct page *page;
99269+ const slob_t *free;
99270+ const void *base;
99271+ unsigned long flags;
99272+
99273+ if (ZERO_OR_NULL_PTR(ptr))
99274+ return "<null>";
99275+
99276+ if (!virt_addr_valid(ptr))
99277+ return NULL;
99278+
99279+ page = virt_to_head_page(ptr);
99280+ if (!PageSlab(page))
99281+ return NULL;
99282+
99283+ if (page->private) {
99284+ base = page;
99285+ if (base <= ptr && n <= page->private - (ptr - base))
99286+ return NULL;
99287+ return "<slob>";
99288+ }
99289+
99290+ /* some tricky double walking to find the chunk */
99291+ spin_lock_irqsave(&slob_lock, flags);
99292+ base = (void *)((unsigned long)ptr & PAGE_MASK);
99293+ free = page->freelist;
99294+
99295+ while (!slob_last(free) && (void *)free <= ptr) {
99296+ base = free + slob_units(free);
99297+ free = slob_next(free);
99298+ }
99299+
99300+ while (base < (void *)free) {
99301+ slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
99302+ int size = SLOB_UNIT * SLOB_UNITS(m + align);
99303+ int offset;
99304+
99305+ if (ptr < base + align)
99306+ break;
99307+
99308+ offset = ptr - base - align;
99309+ if (offset >= m) {
99310+ base += size;
99311+ continue;
99312+ }
99313+
99314+ if (n > m - offset)
99315+ break;
99316+
99317+ spin_unlock_irqrestore(&slob_lock, flags);
99318+ return NULL;
99319+ }
99320+
99321+ spin_unlock_irqrestore(&slob_lock, flags);
99322+ return "<slob>";
99323+}
99324+#endif
99325+
99326 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
99327 size_t ksize(const void *block)
99328 {
99329 struct page *sp;
99330 int align;
99331- unsigned int *m;
99332+ slob_t *m;
99333
99334 BUG_ON(!block);
99335 if (unlikely(block == ZERO_SIZE_PTR))
99336 return 0;
99337
99338 sp = virt_to_page(block);
99339- if (unlikely(!PageSlab(sp)))
99340- return PAGE_SIZE << compound_order(sp);
99341+ VM_BUG_ON(!PageSlab(sp));
99342+ if (sp->private)
99343+ return sp->private;
99344
99345 align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
99346- m = (unsigned int *)(block - align);
99347- return SLOB_UNITS(*m) * SLOB_UNIT;
99348+ m = (slob_t *)(block - align);
99349+ return SLOB_UNITS(m[0].units) * SLOB_UNIT;
99350 }
99351 EXPORT_SYMBOL(ksize);
99352
99353@@ -534,23 +636,33 @@ int __kmem_cache_create(struct kmem_cache *c, unsigned long flags)
99354
99355 void *slob_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
99356 {
99357- void *b;
99358+ void *b = NULL;
99359
99360 flags &= gfp_allowed_mask;
99361
99362 lockdep_trace_alloc(flags);
99363
99364+#ifdef CONFIG_PAX_USERCOPY_SLABS
99365+ b = __do_kmalloc_node_align(c->size, flags, node, _RET_IP_, c->align);
99366+#else
99367 if (c->size < PAGE_SIZE) {
99368 b = slob_alloc(c->size, flags, c->align, node);
99369 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
99370 SLOB_UNITS(c->size) * SLOB_UNIT,
99371 flags, node);
99372 } else {
99373- b = slob_new_pages(flags, get_order(c->size), node);
99374+ struct page *sp;
99375+
99376+ sp = slob_new_pages(flags, get_order(c->size), node);
99377+ if (sp) {
99378+ b = page_address(sp);
99379+ sp->private = c->size;
99380+ }
99381 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
99382 PAGE_SIZE << get_order(c->size),
99383 flags, node);
99384 }
99385+#endif
99386
99387 if (b && c->ctor)
99388 c->ctor(b);
99389@@ -580,12 +692,16 @@ void *kmem_cache_alloc_node(struct kmem_cache *cachep, gfp_t gfp, int node)
99390 EXPORT_SYMBOL(kmem_cache_alloc_node);
99391 #endif
99392
99393-static void __kmem_cache_free(void *b, int size)
99394+static void __kmem_cache_free(struct kmem_cache *c, void *b, int size)
99395 {
99396- if (size < PAGE_SIZE)
99397- slob_free(b, size);
99398+ struct page *sp;
99399+
99400+ sp = virt_to_page(b);
99401+ BUG_ON(!PageSlab(sp));
99402+ if (!sp->private)
99403+ slob_free(c, b, size);
99404 else
99405- slob_free_pages(b, get_order(size));
99406+ slob_free_pages(sp, get_order(size));
99407 }
99408
99409 static void kmem_rcu_free(struct rcu_head *head)
99410@@ -593,22 +709,36 @@ static void kmem_rcu_free(struct rcu_head *head)
99411 struct slob_rcu *slob_rcu = (struct slob_rcu *)head;
99412 void *b = (void *)slob_rcu - (slob_rcu->size - sizeof(struct slob_rcu));
99413
99414- __kmem_cache_free(b, slob_rcu->size);
99415+ __kmem_cache_free(NULL, b, slob_rcu->size);
99416 }
99417
99418 void kmem_cache_free(struct kmem_cache *c, void *b)
99419 {
99420+ int size = c->size;
99421+
99422+#ifdef CONFIG_PAX_USERCOPY_SLABS
99423+ if (size + c->align < PAGE_SIZE) {
99424+ size += c->align;
99425+ b -= c->align;
99426+ }
99427+#endif
99428+
99429 kmemleak_free_recursive(b, c->flags);
99430 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
99431 struct slob_rcu *slob_rcu;
99432- slob_rcu = b + (c->size - sizeof(struct slob_rcu));
99433- slob_rcu->size = c->size;
99434+ slob_rcu = b + (size - sizeof(struct slob_rcu));
99435+ slob_rcu->size = size;
99436 call_rcu(&slob_rcu->head, kmem_rcu_free);
99437 } else {
99438- __kmem_cache_free(b, c->size);
99439+ __kmem_cache_free(c, b, size);
99440 }
99441
99442+#ifdef CONFIG_PAX_USERCOPY_SLABS
99443+ trace_kfree(_RET_IP_, b);
99444+#else
99445 trace_kmem_cache_free(_RET_IP_, b);
99446+#endif
99447+
99448 }
99449 EXPORT_SYMBOL(kmem_cache_free);
99450
99451diff --git a/mm/slub.c b/mm/slub.c
99452index ae7b9f1..7b3fdbe 100644
99453--- a/mm/slub.c
99454+++ b/mm/slub.c
99455@@ -197,7 +197,7 @@ struct track {
99456
99457 enum track_item { TRACK_ALLOC, TRACK_FREE };
99458
99459-#ifdef CONFIG_SYSFS
99460+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
99461 static int sysfs_slab_add(struct kmem_cache *);
99462 static int sysfs_slab_alias(struct kmem_cache *, const char *);
99463 static void memcg_propagate_slab_attrs(struct kmem_cache *s);
99464@@ -535,7 +535,7 @@ static void print_track(const char *s, struct track *t)
99465 if (!t->addr)
99466 return;
99467
99468- pr_err("INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
99469+ pr_err("INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
99470 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
99471 #ifdef CONFIG_STACKTRACE
99472 {
99473@@ -2645,6 +2645,14 @@ static __always_inline void slab_free(struct kmem_cache *s,
99474
99475 slab_free_hook(s, x);
99476
99477+#ifdef CONFIG_PAX_MEMORY_SANITIZE
99478+ if (!(s->flags & SLAB_NO_SANITIZE)) {
99479+ memset(x, PAX_MEMORY_SANITIZE_VALUE, s->object_size);
99480+ if (s->ctor)
99481+ s->ctor(x);
99482+ }
99483+#endif
99484+
99485 redo:
99486 /*
99487 * Determine the currently cpus per cpu slab.
99488@@ -2982,6 +2990,9 @@ static int calculate_sizes(struct kmem_cache *s, int forced_order)
99489 s->inuse = size;
99490
99491 if (((flags & (SLAB_DESTROY_BY_RCU | SLAB_POISON)) ||
99492+#ifdef CONFIG_PAX_MEMORY_SANITIZE
99493+ (!(flags & SLAB_NO_SANITIZE)) ||
99494+#endif
99495 s->ctor)) {
99496 /*
99497 * Relocate free pointer after the object if it is not
99498@@ -3301,6 +3312,59 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
99499 EXPORT_SYMBOL(__kmalloc_node);
99500 #endif
99501
99502+bool is_usercopy_object(const void *ptr)
99503+{
99504+ struct page *page;
99505+ struct kmem_cache *s;
99506+
99507+ if (ZERO_OR_NULL_PTR(ptr))
99508+ return false;
99509+
99510+ if (!slab_is_available())
99511+ return false;
99512+
99513+ if (!virt_addr_valid(ptr))
99514+ return false;
99515+
99516+ page = virt_to_head_page(ptr);
99517+
99518+ if (!PageSlab(page))
99519+ return false;
99520+
99521+ s = page->slab_cache;
99522+ return s->flags & SLAB_USERCOPY;
99523+}
99524+
99525+#ifdef CONFIG_PAX_USERCOPY
99526+const char *check_heap_object(const void *ptr, unsigned long n)
99527+{
99528+ struct page *page;
99529+ struct kmem_cache *s;
99530+ unsigned long offset;
99531+
99532+ if (ZERO_OR_NULL_PTR(ptr))
99533+ return "<null>";
99534+
99535+ if (!virt_addr_valid(ptr))
99536+ return NULL;
99537+
99538+ page = virt_to_head_page(ptr);
99539+
99540+ if (!PageSlab(page))
99541+ return NULL;
99542+
99543+ s = page->slab_cache;
99544+ if (!(s->flags & SLAB_USERCOPY))
99545+ return s->name;
99546+
99547+ offset = (ptr - page_address(page)) % s->size;
99548+ if (offset <= s->object_size && n <= s->object_size - offset)
99549+ return NULL;
99550+
99551+ return s->name;
99552+}
99553+#endif
99554+
99555 size_t ksize(const void *object)
99556 {
99557 struct page *page;
99558@@ -3329,6 +3393,7 @@ void kfree(const void *x)
99559 if (unlikely(ZERO_OR_NULL_PTR(x)))
99560 return;
99561
99562+ VM_BUG_ON(!virt_addr_valid(x));
99563 page = virt_to_head_page(x);
99564 if (unlikely(!PageSlab(page))) {
99565 BUG_ON(!PageCompound(page));
99566@@ -3624,7 +3689,7 @@ __kmem_cache_alias(const char *name, size_t size, size_t align,
99567 int i;
99568 struct kmem_cache *c;
99569
99570- s->refcount++;
99571+ atomic_inc(&s->refcount);
99572
99573 /*
99574 * Adjust the object sizes so that we clear
99575@@ -3643,7 +3708,7 @@ __kmem_cache_alias(const char *name, size_t size, size_t align,
99576 }
99577
99578 if (sysfs_slab_alias(s, name)) {
99579- s->refcount--;
99580+ atomic_dec(&s->refcount);
99581 s = NULL;
99582 }
99583 }
99584@@ -3760,7 +3825,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
99585 }
99586 #endif
99587
99588-#ifdef CONFIG_SYSFS
99589+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
99590 static int count_inuse(struct page *page)
99591 {
99592 return page->inuse;
99593@@ -4041,7 +4106,11 @@ static int list_locations(struct kmem_cache *s, char *buf,
99594 len += sprintf(buf + len, "%7ld ", l->count);
99595
99596 if (l->addr)
99597+#ifdef CONFIG_GRKERNSEC_HIDESYM
99598+ len += sprintf(buf + len, "%pS", NULL);
99599+#else
99600 len += sprintf(buf + len, "%pS", (void *)l->addr);
99601+#endif
99602 else
99603 len += sprintf(buf + len, "<not-available>");
99604
99605@@ -4143,12 +4212,12 @@ static void __init resiliency_test(void)
99606 validate_slab_cache(kmalloc_caches[9]);
99607 }
99608 #else
99609-#ifdef CONFIG_SYSFS
99610+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
99611 static void resiliency_test(void) {};
99612 #endif
99613 #endif
99614
99615-#ifdef CONFIG_SYSFS
99616+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
99617 enum slab_stat_type {
99618 SL_ALL, /* All slabs */
99619 SL_PARTIAL, /* Only partially allocated slabs */
99620@@ -4385,13 +4454,17 @@ static ssize_t ctor_show(struct kmem_cache *s, char *buf)
99621 {
99622 if (!s->ctor)
99623 return 0;
99624+#ifdef CONFIG_GRKERNSEC_HIDESYM
99625+ return sprintf(buf, "%pS\n", NULL);
99626+#else
99627 return sprintf(buf, "%pS\n", s->ctor);
99628+#endif
99629 }
99630 SLAB_ATTR_RO(ctor);
99631
99632 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
99633 {
99634- return sprintf(buf, "%d\n", s->refcount < 0 ? 0 : s->refcount - 1);
99635+ return sprintf(buf, "%d\n", atomic_read(&s->refcount) < 0 ? 0 : atomic_read(&s->refcount) - 1);
99636 }
99637 SLAB_ATTR_RO(aliases);
99638
99639@@ -4479,6 +4552,22 @@ static ssize_t cache_dma_show(struct kmem_cache *s, char *buf)
99640 SLAB_ATTR_RO(cache_dma);
99641 #endif
99642
99643+#ifdef CONFIG_PAX_USERCOPY_SLABS
99644+static ssize_t usercopy_show(struct kmem_cache *s, char *buf)
99645+{
99646+ return sprintf(buf, "%d\n", !!(s->flags & SLAB_USERCOPY));
99647+}
99648+SLAB_ATTR_RO(usercopy);
99649+#endif
99650+
99651+#ifdef CONFIG_PAX_MEMORY_SANITIZE
99652+static ssize_t sanitize_show(struct kmem_cache *s, char *buf)
99653+{
99654+ return sprintf(buf, "%d\n", !(s->flags & SLAB_NO_SANITIZE));
99655+}
99656+SLAB_ATTR_RO(sanitize);
99657+#endif
99658+
99659 static ssize_t destroy_by_rcu_show(struct kmem_cache *s, char *buf)
99660 {
99661 return sprintf(buf, "%d\n", !!(s->flags & SLAB_DESTROY_BY_RCU));
99662@@ -4534,7 +4623,7 @@ static ssize_t trace_store(struct kmem_cache *s, const char *buf,
99663 * as well as cause other issues like converting a mergeable
99664 * cache into an umergeable one.
99665 */
99666- if (s->refcount > 1)
99667+ if (atomic_read(&s->refcount) > 1)
99668 return -EINVAL;
99669
99670 s->flags &= ~SLAB_TRACE;
99671@@ -4654,7 +4743,7 @@ static ssize_t failslab_show(struct kmem_cache *s, char *buf)
99672 static ssize_t failslab_store(struct kmem_cache *s, const char *buf,
99673 size_t length)
99674 {
99675- if (s->refcount > 1)
99676+ if (atomic_read(&s->refcount) > 1)
99677 return -EINVAL;
99678
99679 s->flags &= ~SLAB_FAILSLAB;
99680@@ -4824,6 +4913,12 @@ static struct attribute *slab_attrs[] = {
99681 #ifdef CONFIG_ZONE_DMA
99682 &cache_dma_attr.attr,
99683 #endif
99684+#ifdef CONFIG_PAX_USERCOPY_SLABS
99685+ &usercopy_attr.attr,
99686+#endif
99687+#ifdef CONFIG_PAX_MEMORY_SANITIZE
99688+ &sanitize_attr.attr,
99689+#endif
99690 #ifdef CONFIG_NUMA
99691 &remote_node_defrag_ratio_attr.attr,
99692 #endif
99693@@ -5068,6 +5163,7 @@ static char *create_unique_id(struct kmem_cache *s)
99694 return name;
99695 }
99696
99697+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
99698 static int sysfs_slab_add(struct kmem_cache *s)
99699 {
99700 int err;
99701@@ -5141,6 +5237,7 @@ void sysfs_slab_remove(struct kmem_cache *s)
99702 kobject_del(&s->kobj);
99703 kobject_put(&s->kobj);
99704 }
99705+#endif
99706
99707 /*
99708 * Need to buffer aliases during bootup until sysfs becomes
99709@@ -5154,6 +5251,7 @@ struct saved_alias {
99710
99711 static struct saved_alias *alias_list;
99712
99713+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
99714 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
99715 {
99716 struct saved_alias *al;
99717@@ -5176,6 +5274,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
99718 alias_list = al;
99719 return 0;
99720 }
99721+#endif
99722
99723 static int __init slab_sysfs_init(void)
99724 {
99725diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
99726index 4cba9c2..b4f9fcc 100644
99727--- a/mm/sparse-vmemmap.c
99728+++ b/mm/sparse-vmemmap.c
99729@@ -131,7 +131,7 @@ pud_t * __meminit vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node)
99730 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
99731 if (!p)
99732 return NULL;
99733- pud_populate(&init_mm, pud, p);
99734+ pud_populate_kernel(&init_mm, pud, p);
99735 }
99736 return pud;
99737 }
99738@@ -143,7 +143,7 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
99739 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
99740 if (!p)
99741 return NULL;
99742- pgd_populate(&init_mm, pgd, p);
99743+ pgd_populate_kernel(&init_mm, pgd, p);
99744 }
99745 return pgd;
99746 }
99747diff --git a/mm/sparse.c b/mm/sparse.c
99748index d1b48b6..6e8590e 100644
99749--- a/mm/sparse.c
99750+++ b/mm/sparse.c
99751@@ -750,7 +750,7 @@ static void clear_hwpoisoned_pages(struct page *memmap, int nr_pages)
99752
99753 for (i = 0; i < PAGES_PER_SECTION; i++) {
99754 if (PageHWPoison(&memmap[i])) {
99755- atomic_long_sub(1, &num_poisoned_pages);
99756+ atomic_long_sub_unchecked(1, &num_poisoned_pages);
99757 ClearPageHWPoison(&memmap[i]);
99758 }
99759 }
99760diff --git a/mm/swap.c b/mm/swap.c
99761index 8a12b33..7068e78 100644
99762--- a/mm/swap.c
99763+++ b/mm/swap.c
99764@@ -31,6 +31,7 @@
99765 #include <linux/memcontrol.h>
99766 #include <linux/gfp.h>
99767 #include <linux/uio.h>
99768+#include <linux/hugetlb.h>
99769
99770 #include "internal.h"
99771
99772@@ -77,6 +78,8 @@ static void __put_compound_page(struct page *page)
99773
99774 __page_cache_release(page);
99775 dtor = get_compound_page_dtor(page);
99776+ if (!PageHuge(page))
99777+ BUG_ON(dtor != free_compound_page);
99778 (*dtor)(page);
99779 }
99780
99781diff --git a/mm/swapfile.c b/mm/swapfile.c
99782index 8798b2e..348f9dd 100644
99783--- a/mm/swapfile.c
99784+++ b/mm/swapfile.c
99785@@ -84,7 +84,7 @@ static DEFINE_MUTEX(swapon_mutex);
99786
99787 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
99788 /* Activity counter to indicate that a swapon or swapoff has occurred */
99789-static atomic_t proc_poll_event = ATOMIC_INIT(0);
99790+static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
99791
99792 static inline unsigned char swap_count(unsigned char ent)
99793 {
99794@@ -1944,7 +1944,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
99795 spin_unlock(&swap_lock);
99796
99797 err = 0;
99798- atomic_inc(&proc_poll_event);
99799+ atomic_inc_unchecked(&proc_poll_event);
99800 wake_up_interruptible(&proc_poll_wait);
99801
99802 out_dput:
99803@@ -1961,8 +1961,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
99804
99805 poll_wait(file, &proc_poll_wait, wait);
99806
99807- if (seq->poll_event != atomic_read(&proc_poll_event)) {
99808- seq->poll_event = atomic_read(&proc_poll_event);
99809+ if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
99810+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
99811 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
99812 }
99813
99814@@ -2060,7 +2060,7 @@ static int swaps_open(struct inode *inode, struct file *file)
99815 return ret;
99816
99817 seq = file->private_data;
99818- seq->poll_event = atomic_read(&proc_poll_event);
99819+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
99820 return 0;
99821 }
99822
99823@@ -2520,7 +2520,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
99824 (frontswap_map) ? "FS" : "");
99825
99826 mutex_unlock(&swapon_mutex);
99827- atomic_inc(&proc_poll_event);
99828+ atomic_inc_unchecked(&proc_poll_event);
99829 wake_up_interruptible(&proc_poll_wait);
99830
99831 if (S_ISREG(inode->i_mode))
99832diff --git a/mm/util.c b/mm/util.c
99833index fec39d4..3e60325 100644
99834--- a/mm/util.c
99835+++ b/mm/util.c
99836@@ -195,6 +195,12 @@ struct task_struct *task_of_stack(struct task_struct *task,
99837 void arch_pick_mmap_layout(struct mm_struct *mm)
99838 {
99839 mm->mmap_base = TASK_UNMAPPED_BASE;
99840+
99841+#ifdef CONFIG_PAX_RANDMMAP
99842+ if (mm->pax_flags & MF_PAX_RANDMMAP)
99843+ mm->mmap_base += mm->delta_mmap;
99844+#endif
99845+
99846 mm->get_unmapped_area = arch_get_unmapped_area;
99847 }
99848 #endif
99849@@ -371,6 +377,9 @@ int get_cmdline(struct task_struct *task, char *buffer, int buflen)
99850 if (!mm->arg_end)
99851 goto out_mm; /* Shh! No looking before we're done */
99852
99853+ if (gr_acl_handle_procpidmem(task))
99854+ goto out_mm;
99855+
99856 len = mm->arg_end - mm->arg_start;
99857
99858 if (len > buflen)
99859diff --git a/mm/vmalloc.c b/mm/vmalloc.c
99860index 90520af..24231aa 100644
99861--- a/mm/vmalloc.c
99862+++ b/mm/vmalloc.c
99863@@ -40,6 +40,21 @@ struct vfree_deferred {
99864 };
99865 static DEFINE_PER_CPU(struct vfree_deferred, vfree_deferred);
99866
99867+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
99868+struct stack_deferred_llist {
99869+ struct llist_head list;
99870+ void *stack;
99871+ void *lowmem_stack;
99872+};
99873+
99874+struct stack_deferred {
99875+ struct stack_deferred_llist list;
99876+ struct work_struct wq;
99877+};
99878+
99879+static DEFINE_PER_CPU(struct stack_deferred, stack_deferred);
99880+#endif
99881+
99882 static void __vunmap(const void *, int);
99883
99884 static void free_work(struct work_struct *w)
99885@@ -47,12 +62,30 @@ static void free_work(struct work_struct *w)
99886 struct vfree_deferred *p = container_of(w, struct vfree_deferred, wq);
99887 struct llist_node *llnode = llist_del_all(&p->list);
99888 while (llnode) {
99889- void *p = llnode;
99890+ void *x = llnode;
99891 llnode = llist_next(llnode);
99892- __vunmap(p, 1);
99893+ __vunmap(x, 1);
99894 }
99895 }
99896
99897+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
99898+static void unmap_work(struct work_struct *w)
99899+{
99900+ struct stack_deferred *p = container_of(w, struct stack_deferred, wq);
99901+ struct llist_node *llnode = llist_del_all(&p->list.list);
99902+ while (llnode) {
99903+ struct stack_deferred_llist *x =
99904+ llist_entry((struct llist_head *)llnode,
99905+ struct stack_deferred_llist, list);
99906+ void *stack = ACCESS_ONCE(x->stack);
99907+ void *lowmem_stack = ACCESS_ONCE(x->lowmem_stack);
99908+ llnode = llist_next(llnode);
99909+ __vunmap(stack, 0);
99910+ free_kmem_pages((unsigned long)lowmem_stack, THREAD_SIZE_ORDER);
99911+ }
99912+}
99913+#endif
99914+
99915 /*** Page table manipulation functions ***/
99916
99917 static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
99918@@ -61,8 +94,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
99919
99920 pte = pte_offset_kernel(pmd, addr);
99921 do {
99922- pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
99923- WARN_ON(!pte_none(ptent) && !pte_present(ptent));
99924+
99925+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
99926+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
99927+ BUG_ON(!pte_exec(*pte));
99928+ set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
99929+ continue;
99930+ }
99931+#endif
99932+
99933+ {
99934+ pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
99935+ WARN_ON(!pte_none(ptent) && !pte_present(ptent));
99936+ }
99937 } while (pte++, addr += PAGE_SIZE, addr != end);
99938 }
99939
99940@@ -122,16 +166,29 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
99941 pte = pte_alloc_kernel(pmd, addr);
99942 if (!pte)
99943 return -ENOMEM;
99944+
99945+ pax_open_kernel();
99946 do {
99947 struct page *page = pages[*nr];
99948
99949- if (WARN_ON(!pte_none(*pte)))
99950+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
99951+ if (pgprot_val(prot) & _PAGE_NX)
99952+#endif
99953+
99954+ if (!pte_none(*pte)) {
99955+ pax_close_kernel();
99956+ WARN_ON(1);
99957 return -EBUSY;
99958- if (WARN_ON(!page))
99959+ }
99960+ if (!page) {
99961+ pax_close_kernel();
99962+ WARN_ON(1);
99963 return -ENOMEM;
99964+ }
99965 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
99966 (*nr)++;
99967 } while (pte++, addr += PAGE_SIZE, addr != end);
99968+ pax_close_kernel();
99969 return 0;
99970 }
99971
99972@@ -141,7 +198,7 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
99973 pmd_t *pmd;
99974 unsigned long next;
99975
99976- pmd = pmd_alloc(&init_mm, pud, addr);
99977+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
99978 if (!pmd)
99979 return -ENOMEM;
99980 do {
99981@@ -158,7 +215,7 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
99982 pud_t *pud;
99983 unsigned long next;
99984
99985- pud = pud_alloc(&init_mm, pgd, addr);
99986+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
99987 if (!pud)
99988 return -ENOMEM;
99989 do {
99990@@ -218,6 +275,12 @@ int is_vmalloc_or_module_addr(const void *x)
99991 if (addr >= MODULES_VADDR && addr < MODULES_END)
99992 return 1;
99993 #endif
99994+
99995+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
99996+ if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
99997+ return 1;
99998+#endif
99999+
100000 return is_vmalloc_addr(x);
100001 }
100002
100003@@ -238,8 +301,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
100004
100005 if (!pgd_none(*pgd)) {
100006 pud_t *pud = pud_offset(pgd, addr);
100007+#ifdef CONFIG_X86
100008+ if (!pud_large(*pud))
100009+#endif
100010 if (!pud_none(*pud)) {
100011 pmd_t *pmd = pmd_offset(pud, addr);
100012+#ifdef CONFIG_X86
100013+ if (!pmd_large(*pmd))
100014+#endif
100015 if (!pmd_none(*pmd)) {
100016 pte_t *ptep, pte;
100017
100018@@ -1183,13 +1252,23 @@ void __init vmalloc_init(void)
100019 for_each_possible_cpu(i) {
100020 struct vmap_block_queue *vbq;
100021 struct vfree_deferred *p;
100022+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
100023+ struct stack_deferred *p2;
100024+#endif
100025
100026 vbq = &per_cpu(vmap_block_queue, i);
100027 spin_lock_init(&vbq->lock);
100028 INIT_LIST_HEAD(&vbq->free);
100029+
100030 p = &per_cpu(vfree_deferred, i);
100031 init_llist_head(&p->list);
100032 INIT_WORK(&p->wq, free_work);
100033+
100034+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
100035+ p2 = &per_cpu(stack_deferred, i);
100036+ init_llist_head(&p2->list.list);
100037+ INIT_WORK(&p2->wq, unmap_work);
100038+#endif
100039 }
100040
100041 /* Import existing vmlist entries. */
100042@@ -1314,6 +1393,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
100043 struct vm_struct *area;
100044
100045 BUG_ON(in_interrupt());
100046+
100047+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
100048+ if (flags & VM_KERNEXEC) {
100049+ if (start != VMALLOC_START || end != VMALLOC_END)
100050+ return NULL;
100051+ start = (unsigned long)MODULES_EXEC_VADDR;
100052+ end = (unsigned long)MODULES_EXEC_END;
100053+ }
100054+#endif
100055+
100056 if (flags & VM_IOREMAP)
100057 align = 1ul << clamp(fls(size), PAGE_SHIFT, IOREMAP_MAX_ORDER);
100058
100059@@ -1519,6 +1608,23 @@ void vunmap(const void *addr)
100060 }
100061 EXPORT_SYMBOL(vunmap);
100062
100063+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
100064+void unmap_process_stacks(struct task_struct *task)
100065+{
100066+ if (unlikely(in_interrupt())) {
100067+ struct stack_deferred *p = &__get_cpu_var(stack_deferred);
100068+ struct stack_deferred_llist *list = task->stack;
100069+ list->stack = task->stack;
100070+ list->lowmem_stack = task->lowmem_stack;
100071+ if (llist_add((struct llist_node *)&list->list, &p->list.list))
100072+ schedule_work(&p->wq);
100073+ } else {
100074+ __vunmap(task->stack, 0);
100075+ free_kmem_pages((unsigned long)task->lowmem_stack, THREAD_SIZE_ORDER);
100076+ }
100077+}
100078+#endif
100079+
100080 /**
100081 * vmap - map an array of pages into virtually contiguous space
100082 * @pages: array of page pointers
100083@@ -1539,6 +1645,11 @@ void *vmap(struct page **pages, unsigned int count,
100084 if (count > totalram_pages)
100085 return NULL;
100086
100087+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
100088+ if (!(pgprot_val(prot) & _PAGE_NX))
100089+ flags |= VM_KERNEXEC;
100090+#endif
100091+
100092 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
100093 __builtin_return_address(0));
100094 if (!area)
100095@@ -1641,6 +1752,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
100096 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
100097 goto fail;
100098
100099+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
100100+ if (!(pgprot_val(prot) & _PAGE_NX))
100101+ area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNINITIALIZED | VM_KERNEXEC,
100102+ VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
100103+ else
100104+#endif
100105+
100106 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNINITIALIZED,
100107 start, end, node, gfp_mask, caller);
100108 if (!area)
100109@@ -1817,10 +1935,9 @@ EXPORT_SYMBOL(vzalloc_node);
100110 * For tight control over page level allocator and protection flags
100111 * use __vmalloc() instead.
100112 */
100113-
100114 void *vmalloc_exec(unsigned long size)
100115 {
100116- return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
100117+ return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
100118 NUMA_NO_NODE, __builtin_return_address(0));
100119 }
100120
100121@@ -2127,6 +2244,8 @@ int remap_vmalloc_range_partial(struct vm_area_struct *vma, unsigned long uaddr,
100122 {
100123 struct vm_struct *area;
100124
100125+ BUG_ON(vma->vm_mirror);
100126+
100127 size = PAGE_ALIGN(size);
100128
100129 if (!PAGE_ALIGNED(uaddr) || !PAGE_ALIGNED(kaddr))
100130@@ -2609,7 +2728,11 @@ static int s_show(struct seq_file *m, void *p)
100131 v->addr, v->addr + v->size, v->size);
100132
100133 if (v->caller)
100134+#ifdef CONFIG_GRKERNSEC_HIDESYM
100135+ seq_printf(m, " %pK", v->caller);
100136+#else
100137 seq_printf(m, " %pS", v->caller);
100138+#endif
100139
100140 if (v->nr_pages)
100141 seq_printf(m, " pages=%d", v->nr_pages);
100142diff --git a/mm/vmstat.c b/mm/vmstat.c
100143index 1b12d39..57b29b2 100644
100144--- a/mm/vmstat.c
100145+++ b/mm/vmstat.c
100146@@ -22,6 +22,7 @@
100147 #include <linux/writeback.h>
100148 #include <linux/compaction.h>
100149 #include <linux/mm_inline.h>
100150+#include <linux/grsecurity.h>
100151
100152 #include "internal.h"
100153
100154@@ -81,7 +82,7 @@ void vm_events_fold_cpu(int cpu)
100155 *
100156 * vm_stat contains the global counters
100157 */
100158-atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
100159+atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
100160 EXPORT_SYMBOL(vm_stat);
100161
100162 #ifdef CONFIG_SMP
100163@@ -433,7 +434,7 @@ static int fold_diff(int *diff)
100164
100165 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
100166 if (diff[i]) {
100167- atomic_long_add(diff[i], &vm_stat[i]);
100168+ atomic_long_add_unchecked(diff[i], &vm_stat[i]);
100169 changes++;
100170 }
100171 return changes;
100172@@ -471,7 +472,7 @@ static int refresh_cpu_vm_stats(void)
100173 v = this_cpu_xchg(p->vm_stat_diff[i], 0);
100174 if (v) {
100175
100176- atomic_long_add(v, &zone->vm_stat[i]);
100177+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
100178 global_diff[i] += v;
100179 #ifdef CONFIG_NUMA
100180 /* 3 seconds idle till flush */
100181@@ -535,7 +536,7 @@ void cpu_vm_stats_fold(int cpu)
100182
100183 v = p->vm_stat_diff[i];
100184 p->vm_stat_diff[i] = 0;
100185- atomic_long_add(v, &zone->vm_stat[i]);
100186+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
100187 global_diff[i] += v;
100188 }
100189 }
100190@@ -555,8 +556,8 @@ void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
100191 if (pset->vm_stat_diff[i]) {
100192 int v = pset->vm_stat_diff[i];
100193 pset->vm_stat_diff[i] = 0;
100194- atomic_long_add(v, &zone->vm_stat[i]);
100195- atomic_long_add(v, &vm_stat[i]);
100196+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
100197+ atomic_long_add_unchecked(v, &vm_stat[i]);
100198 }
100199 }
100200 #endif
100201@@ -1189,10 +1190,22 @@ static void *vmstat_start(struct seq_file *m, loff_t *pos)
100202 stat_items_size += sizeof(struct vm_event_state);
100203 #endif
100204
100205- v = kmalloc(stat_items_size, GFP_KERNEL);
100206+ v = kzalloc(stat_items_size, GFP_KERNEL);
100207 m->private = v;
100208 if (!v)
100209 return ERR_PTR(-ENOMEM);
100210+
100211+#ifdef CONFIG_GRKERNSEC_PROC_ADD
100212+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
100213+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)
100214+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
100215+ && !in_group_p(grsec_proc_gid)
100216+#endif
100217+ )
100218+ return (unsigned long *)m->private + *pos;
100219+#endif
100220+#endif
100221+
100222 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
100223 v[i] = global_page_state(i);
100224 v += NR_VM_ZONE_STAT_ITEMS;
100225@@ -1424,10 +1437,16 @@ static int __init setup_vmstat(void)
100226 cpu_notifier_register_done();
100227 #endif
100228 #ifdef CONFIG_PROC_FS
100229- proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
100230- proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
100231- proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
100232- proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
100233+ {
100234+ mode_t gr_mode = S_IRUGO;
100235+#ifdef CONFIG_GRKERNSEC_PROC_ADD
100236+ gr_mode = S_IRUSR;
100237+#endif
100238+ proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
100239+ proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
100240+ proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
100241+ proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
100242+ }
100243 #endif
100244 return 0;
100245 }
100246diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
100247index 64c6bed..b79a5de 100644
100248--- a/net/8021q/vlan.c
100249+++ b/net/8021q/vlan.c
100250@@ -481,7 +481,7 @@ out:
100251 return NOTIFY_DONE;
100252 }
100253
100254-static struct notifier_block vlan_notifier_block __read_mostly = {
100255+static struct notifier_block vlan_notifier_block = {
100256 .notifier_call = vlan_device_event,
100257 };
100258
100259@@ -556,8 +556,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
100260 err = -EPERM;
100261 if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
100262 break;
100263- if ((args.u.name_type >= 0) &&
100264- (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
100265+ if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
100266 struct vlan_net *vn;
100267
100268 vn = net_generic(net, vlan_net_id);
100269diff --git a/net/8021q/vlan_netlink.c b/net/8021q/vlan_netlink.c
100270index 8ac8a5c..991defc 100644
100271--- a/net/8021q/vlan_netlink.c
100272+++ b/net/8021q/vlan_netlink.c
100273@@ -238,7 +238,7 @@ nla_put_failure:
100274 return -EMSGSIZE;
100275 }
100276
100277-struct rtnl_link_ops vlan_link_ops __read_mostly = {
100278+struct rtnl_link_ops vlan_link_ops = {
100279 .kind = "vlan",
100280 .maxtype = IFLA_VLAN_MAX,
100281 .policy = vlan_policy,
100282diff --git a/net/9p/client.c b/net/9p/client.c
100283index e86a9bea..e91f70e 100644
100284--- a/net/9p/client.c
100285+++ b/net/9p/client.c
100286@@ -596,7 +596,7 @@ static int p9_check_zc_errors(struct p9_client *c, struct p9_req_t *req,
100287 len - inline_len);
100288 } else {
100289 err = copy_from_user(ename + inline_len,
100290- uidata, len - inline_len);
100291+ (char __force_user *)uidata, len - inline_len);
100292 if (err) {
100293 err = -EFAULT;
100294 goto out_err;
100295@@ -1570,7 +1570,7 @@ p9_client_read(struct p9_fid *fid, char *data, char __user *udata, u64 offset,
100296 kernel_buf = 1;
100297 indata = data;
100298 } else
100299- indata = (__force char *)udata;
100300+ indata = (__force_kernel char *)udata;
100301 /*
100302 * response header len is 11
100303 * PDU Header(7) + IO Size (4)
100304@@ -1645,7 +1645,7 @@ p9_client_write(struct p9_fid *fid, char *data, const char __user *udata,
100305 kernel_buf = 1;
100306 odata = data;
100307 } else
100308- odata = (char *)udata;
100309+ odata = (char __force_kernel *)udata;
100310 req = p9_client_zc_rpc(clnt, P9_TWRITE, NULL, odata, 0, rsize,
100311 P9_ZC_HDR_SZ, kernel_buf, "dqd",
100312 fid->fid, offset, rsize);
100313diff --git a/net/9p/mod.c b/net/9p/mod.c
100314index 6ab36ae..6f1841b 100644
100315--- a/net/9p/mod.c
100316+++ b/net/9p/mod.c
100317@@ -84,7 +84,7 @@ static LIST_HEAD(v9fs_trans_list);
100318 void v9fs_register_trans(struct p9_trans_module *m)
100319 {
100320 spin_lock(&v9fs_trans_lock);
100321- list_add_tail(&m->list, &v9fs_trans_list);
100322+ pax_list_add_tail((struct list_head *)&m->list, &v9fs_trans_list);
100323 spin_unlock(&v9fs_trans_lock);
100324 }
100325 EXPORT_SYMBOL(v9fs_register_trans);
100326@@ -97,7 +97,7 @@ EXPORT_SYMBOL(v9fs_register_trans);
100327 void v9fs_unregister_trans(struct p9_trans_module *m)
100328 {
100329 spin_lock(&v9fs_trans_lock);
100330- list_del_init(&m->list);
100331+ pax_list_del_init((struct list_head *)&m->list);
100332 spin_unlock(&v9fs_trans_lock);
100333 }
100334 EXPORT_SYMBOL(v9fs_unregister_trans);
100335diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
100336index 80d08f6..de63fd1 100644
100337--- a/net/9p/trans_fd.c
100338+++ b/net/9p/trans_fd.c
100339@@ -428,7 +428,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
100340 oldfs = get_fs();
100341 set_fs(get_ds());
100342 /* The cast to a user pointer is valid due to the set_fs() */
100343- ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
100344+ ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
100345 set_fs(oldfs);
100346
100347 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
100348diff --git a/net/appletalk/atalk_proc.c b/net/appletalk/atalk_proc.c
100349index af46bc4..f9adfcd 100644
100350--- a/net/appletalk/atalk_proc.c
100351+++ b/net/appletalk/atalk_proc.c
100352@@ -256,7 +256,7 @@ int __init atalk_proc_init(void)
100353 struct proc_dir_entry *p;
100354 int rc = -ENOMEM;
100355
100356- atalk_proc_dir = proc_mkdir("atalk", init_net.proc_net);
100357+ atalk_proc_dir = proc_mkdir_restrict("atalk", init_net.proc_net);
100358 if (!atalk_proc_dir)
100359 goto out;
100360
100361diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
100362index 876fbe8..8bbea9f 100644
100363--- a/net/atm/atm_misc.c
100364+++ b/net/atm/atm_misc.c
100365@@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
100366 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
100367 return 1;
100368 atm_return(vcc, truesize);
100369- atomic_inc(&vcc->stats->rx_drop);
100370+ atomic_inc_unchecked(&vcc->stats->rx_drop);
100371 return 0;
100372 }
100373 EXPORT_SYMBOL(atm_charge);
100374@@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
100375 }
100376 }
100377 atm_return(vcc, guess);
100378- atomic_inc(&vcc->stats->rx_drop);
100379+ atomic_inc_unchecked(&vcc->stats->rx_drop);
100380 return NULL;
100381 }
100382 EXPORT_SYMBOL(atm_alloc_charge);
100383@@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
100384
100385 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
100386 {
100387-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
100388+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
100389 __SONET_ITEMS
100390 #undef __HANDLE_ITEM
100391 }
100392@@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
100393
100394 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
100395 {
100396-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
100397+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
100398 __SONET_ITEMS
100399 #undef __HANDLE_ITEM
100400 }
100401diff --git a/net/atm/lec.c b/net/atm/lec.c
100402index 4b98f89..5a2f6cb 100644
100403--- a/net/atm/lec.c
100404+++ b/net/atm/lec.c
100405@@ -111,9 +111,9 @@ static inline void lec_arp_put(struct lec_arp_table *entry)
100406 }
100407
100408 static struct lane2_ops lane2_ops = {
100409- lane2_resolve, /* resolve, spec 3.1.3 */
100410- lane2_associate_req, /* associate_req, spec 3.1.4 */
100411- NULL /* associate indicator, spec 3.1.5 */
100412+ .resolve = lane2_resolve,
100413+ .associate_req = lane2_associate_req,
100414+ .associate_indicator = NULL
100415 };
100416
100417 static unsigned char bus_mac[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
100418diff --git a/net/atm/lec.h b/net/atm/lec.h
100419index 4149db1..f2ab682 100644
100420--- a/net/atm/lec.h
100421+++ b/net/atm/lec.h
100422@@ -48,7 +48,7 @@ struct lane2_ops {
100423 const u8 *tlvs, u32 sizeoftlvs);
100424 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
100425 const u8 *tlvs, u32 sizeoftlvs);
100426-};
100427+} __no_const;
100428
100429 /*
100430 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
100431diff --git a/net/atm/mpoa_caches.c b/net/atm/mpoa_caches.c
100432index d1b2d9a..d549f7f 100644
100433--- a/net/atm/mpoa_caches.c
100434+++ b/net/atm/mpoa_caches.c
100435@@ -535,30 +535,30 @@ static void eg_destroy_cache(struct mpoa_client *mpc)
100436
100437
100438 static struct in_cache_ops ingress_ops = {
100439- in_cache_add_entry, /* add_entry */
100440- in_cache_get, /* get */
100441- in_cache_get_with_mask, /* get_with_mask */
100442- in_cache_get_by_vcc, /* get_by_vcc */
100443- in_cache_put, /* put */
100444- in_cache_remove_entry, /* remove_entry */
100445- cache_hit, /* cache_hit */
100446- clear_count_and_expired, /* clear_count */
100447- check_resolving_entries, /* check_resolving */
100448- refresh_entries, /* refresh */
100449- in_destroy_cache /* destroy_cache */
100450+ .add_entry = in_cache_add_entry,
100451+ .get = in_cache_get,
100452+ .get_with_mask = in_cache_get_with_mask,
100453+ .get_by_vcc = in_cache_get_by_vcc,
100454+ .put = in_cache_put,
100455+ .remove_entry = in_cache_remove_entry,
100456+ .cache_hit = cache_hit,
100457+ .clear_count = clear_count_and_expired,
100458+ .check_resolving = check_resolving_entries,
100459+ .refresh = refresh_entries,
100460+ .destroy_cache = in_destroy_cache
100461 };
100462
100463 static struct eg_cache_ops egress_ops = {
100464- eg_cache_add_entry, /* add_entry */
100465- eg_cache_get_by_cache_id, /* get_by_cache_id */
100466- eg_cache_get_by_tag, /* get_by_tag */
100467- eg_cache_get_by_vcc, /* get_by_vcc */
100468- eg_cache_get_by_src_ip, /* get_by_src_ip */
100469- eg_cache_put, /* put */
100470- eg_cache_remove_entry, /* remove_entry */
100471- update_eg_cache_entry, /* update */
100472- clear_expired, /* clear_expired */
100473- eg_destroy_cache /* destroy_cache */
100474+ .add_entry = eg_cache_add_entry,
100475+ .get_by_cache_id = eg_cache_get_by_cache_id,
100476+ .get_by_tag = eg_cache_get_by_tag,
100477+ .get_by_vcc = eg_cache_get_by_vcc,
100478+ .get_by_src_ip = eg_cache_get_by_src_ip,
100479+ .put = eg_cache_put,
100480+ .remove_entry = eg_cache_remove_entry,
100481+ .update = update_eg_cache_entry,
100482+ .clear_expired = clear_expired,
100483+ .destroy_cache = eg_destroy_cache
100484 };
100485
100486
100487diff --git a/net/atm/proc.c b/net/atm/proc.c
100488index bbb6461..cf04016 100644
100489--- a/net/atm/proc.c
100490+++ b/net/atm/proc.c
100491@@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
100492 const struct k_atm_aal_stats *stats)
100493 {
100494 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
100495- atomic_read(&stats->tx), atomic_read(&stats->tx_err),
100496- atomic_read(&stats->rx), atomic_read(&stats->rx_err),
100497- atomic_read(&stats->rx_drop));
100498+ atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
100499+ atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
100500+ atomic_read_unchecked(&stats->rx_drop));
100501 }
100502
100503 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
100504diff --git a/net/atm/resources.c b/net/atm/resources.c
100505index 0447d5d..3cf4728 100644
100506--- a/net/atm/resources.c
100507+++ b/net/atm/resources.c
100508@@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
100509 static void copy_aal_stats(struct k_atm_aal_stats *from,
100510 struct atm_aal_stats *to)
100511 {
100512-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
100513+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
100514 __AAL_STAT_ITEMS
100515 #undef __HANDLE_ITEM
100516 }
100517@@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
100518 static void subtract_aal_stats(struct k_atm_aal_stats *from,
100519 struct atm_aal_stats *to)
100520 {
100521-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
100522+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
100523 __AAL_STAT_ITEMS
100524 #undef __HANDLE_ITEM
100525 }
100526diff --git a/net/ax25/sysctl_net_ax25.c b/net/ax25/sysctl_net_ax25.c
100527index 919a5ce..cc6b444 100644
100528--- a/net/ax25/sysctl_net_ax25.c
100529+++ b/net/ax25/sysctl_net_ax25.c
100530@@ -152,7 +152,7 @@ int ax25_register_dev_sysctl(ax25_dev *ax25_dev)
100531 {
100532 char path[sizeof("net/ax25/") + IFNAMSIZ];
100533 int k;
100534- struct ctl_table *table;
100535+ ctl_table_no_const *table;
100536
100537 table = kmemdup(ax25_param_table, sizeof(ax25_param_table), GFP_KERNEL);
100538 if (!table)
100539diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
100540index 1e80539..676c37a 100644
100541--- a/net/batman-adv/bat_iv_ogm.c
100542+++ b/net/batman-adv/bat_iv_ogm.c
100543@@ -313,7 +313,7 @@ static int batadv_iv_ogm_iface_enable(struct batadv_hard_iface *hard_iface)
100544
100545 /* randomize initial seqno to avoid collision */
100546 get_random_bytes(&random_seqno, sizeof(random_seqno));
100547- atomic_set(&hard_iface->bat_iv.ogm_seqno, random_seqno);
100548+ atomic_set_unchecked(&hard_iface->bat_iv.ogm_seqno, random_seqno);
100549
100550 hard_iface->bat_iv.ogm_buff_len = BATADV_OGM_HLEN;
100551 ogm_buff = kmalloc(hard_iface->bat_iv.ogm_buff_len, GFP_ATOMIC);
100552@@ -918,9 +918,9 @@ static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
100553 batadv_ogm_packet->tvlv_len = htons(tvlv_len);
100554
100555 /* change sequence number to network order */
100556- seqno = (uint32_t)atomic_read(&hard_iface->bat_iv.ogm_seqno);
100557+ seqno = (uint32_t)atomic_read_unchecked(&hard_iface->bat_iv.ogm_seqno);
100558 batadv_ogm_packet->seqno = htonl(seqno);
100559- atomic_inc(&hard_iface->bat_iv.ogm_seqno);
100560+ atomic_inc_unchecked(&hard_iface->bat_iv.ogm_seqno);
100561
100562 batadv_iv_ogm_slide_own_bcast_window(hard_iface);
100563
100564@@ -1597,7 +1597,7 @@ static void batadv_iv_ogm_process(const struct sk_buff *skb, int ogm_offset,
100565 return;
100566
100567 /* could be changed by schedule_own_packet() */
100568- if_incoming_seqno = atomic_read(&if_incoming->bat_iv.ogm_seqno);
100569+ if_incoming_seqno = atomic_read_unchecked(&if_incoming->bat_iv.ogm_seqno);
100570
100571 if (ogm_packet->flags & BATADV_DIRECTLINK)
100572 has_directlink_flag = true;
100573diff --git a/net/batman-adv/fragmentation.c b/net/batman-adv/fragmentation.c
100574index fc1835c..42f2c2f 100644
100575--- a/net/batman-adv/fragmentation.c
100576+++ b/net/batman-adv/fragmentation.c
100577@@ -251,7 +251,7 @@ batadv_frag_merge_packets(struct hlist_head *chain, struct sk_buff *skb)
100578 kfree(entry);
100579
100580 /* Make room for the rest of the fragments. */
100581- if (pskb_expand_head(skb_out, 0, size - skb->len, GFP_ATOMIC) < 0) {
100582+ if (pskb_expand_head(skb_out, 0, size - skb_out->len, GFP_ATOMIC) < 0) {
100583 kfree_skb(skb_out);
100584 skb_out = NULL;
100585 goto free;
100586@@ -450,7 +450,7 @@ bool batadv_frag_send_packet(struct sk_buff *skb,
100587 frag_header.packet_type = BATADV_UNICAST_FRAG;
100588 frag_header.version = BATADV_COMPAT_VERSION;
100589 frag_header.ttl = BATADV_TTL;
100590- frag_header.seqno = htons(atomic_inc_return(&bat_priv->frag_seqno));
100591+ frag_header.seqno = htons(atomic_inc_return_unchecked(&bat_priv->frag_seqno));
100592 frag_header.reserved = 0;
100593 frag_header.no = 0;
100594 frag_header.total_size = htons(skb->len);
100595diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
100596index 5467955..75ad4e3 100644
100597--- a/net/batman-adv/soft-interface.c
100598+++ b/net/batman-adv/soft-interface.c
100599@@ -296,7 +296,7 @@ send:
100600 primary_if->net_dev->dev_addr);
100601
100602 /* set broadcast sequence number */
100603- seqno = atomic_inc_return(&bat_priv->bcast_seqno);
100604+ seqno = atomic_inc_return_unchecked(&bat_priv->bcast_seqno);
100605 bcast_packet->seqno = htonl(seqno);
100606
100607 batadv_add_bcast_packet_to_list(bat_priv, skb, brd_delay);
100608@@ -761,7 +761,7 @@ static int batadv_softif_init_late(struct net_device *dev)
100609 atomic_set(&bat_priv->batman_queue_left, BATADV_BATMAN_QUEUE_LEN);
100610
100611 atomic_set(&bat_priv->mesh_state, BATADV_MESH_INACTIVE);
100612- atomic_set(&bat_priv->bcast_seqno, 1);
100613+ atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
100614 atomic_set(&bat_priv->tt.vn, 0);
100615 atomic_set(&bat_priv->tt.local_changes, 0);
100616 atomic_set(&bat_priv->tt.ogm_append_cnt, 0);
100617@@ -775,7 +775,7 @@ static int batadv_softif_init_late(struct net_device *dev)
100618
100619 /* randomize initial seqno to avoid collision */
100620 get_random_bytes(&random_seqno, sizeof(random_seqno));
100621- atomic_set(&bat_priv->frag_seqno, random_seqno);
100622+ atomic_set_unchecked(&bat_priv->frag_seqno, random_seqno);
100623
100624 bat_priv->primary_if = NULL;
100625 bat_priv->num_ifaces = 0;
100626@@ -983,7 +983,7 @@ int batadv_softif_is_valid(const struct net_device *net_dev)
100627 return 0;
100628 }
100629
100630-struct rtnl_link_ops batadv_link_ops __read_mostly = {
100631+struct rtnl_link_ops batadv_link_ops = {
100632 .kind = "batadv",
100633 .priv_size = sizeof(struct batadv_priv),
100634 .setup = batadv_softif_init_early,
100635diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
100636index 8854c05..ee5d5497 100644
100637--- a/net/batman-adv/types.h
100638+++ b/net/batman-adv/types.h
100639@@ -67,7 +67,7 @@ enum batadv_dhcp_recipient {
100640 struct batadv_hard_iface_bat_iv {
100641 unsigned char *ogm_buff;
100642 int ogm_buff_len;
100643- atomic_t ogm_seqno;
100644+ atomic_unchecked_t ogm_seqno;
100645 };
100646
100647 /**
100648@@ -768,7 +768,7 @@ struct batadv_priv {
100649 atomic_t bonding;
100650 atomic_t fragmentation;
100651 atomic_t packet_size_max;
100652- atomic_t frag_seqno;
100653+ atomic_unchecked_t frag_seqno;
100654 #ifdef CONFIG_BATMAN_ADV_BLA
100655 atomic_t bridge_loop_avoidance;
100656 #endif
100657@@ -787,7 +787,7 @@ struct batadv_priv {
100658 #endif
100659 uint32_t isolation_mark;
100660 uint32_t isolation_mark_mask;
100661- atomic_t bcast_seqno;
100662+ atomic_unchecked_t bcast_seqno;
100663 atomic_t bcast_queue_left;
100664 atomic_t batman_queue_left;
100665 char num_ifaces;
100666diff --git a/net/bluetooth/6lowpan.c b/net/bluetooth/6lowpan.c
100667index c2e0d14..bfa852b 100644
100668--- a/net/bluetooth/6lowpan.c
100669+++ b/net/bluetooth/6lowpan.c
100670@@ -367,7 +367,6 @@ static int recv_pkt(struct sk_buff *skb, struct net_device *dev,
100671
100672 drop:
100673 dev->stats.rx_dropped++;
100674- kfree_skb(skb);
100675 return NET_RX_DROP;
100676 }
100677
100678diff --git a/net/bluetooth/bnep/core.c b/net/bluetooth/bnep/core.c
100679index 85bcc21..ce82722d 100644
100680--- a/net/bluetooth/bnep/core.c
100681+++ b/net/bluetooth/bnep/core.c
100682@@ -533,6 +533,9 @@ int bnep_add_connection(struct bnep_connadd_req *req, struct socket *sock)
100683
100684 BT_DBG("");
100685
100686+ if (!l2cap_is_socket(sock))
100687+ return -EBADFD;
100688+
100689 baswap((void *) dst, &l2cap_pi(sock->sk)->chan->dst);
100690 baswap((void *) src, &l2cap_pi(sock->sk)->chan->src);
100691
100692diff --git a/net/bluetooth/cmtp/core.c b/net/bluetooth/cmtp/core.c
100693index 67fe5e8..278a194 100644
100694--- a/net/bluetooth/cmtp/core.c
100695+++ b/net/bluetooth/cmtp/core.c
100696@@ -334,6 +334,9 @@ int cmtp_add_connection(struct cmtp_connadd_req *req, struct socket *sock)
100697
100698 BT_DBG("");
100699
100700+ if (!l2cap_is_socket(sock))
100701+ return -EBADFD;
100702+
100703 session = kzalloc(sizeof(struct cmtp_session), GFP_KERNEL);
100704 if (!session)
100705 return -ENOMEM;
100706diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
100707index 115f149..f0ba286 100644
100708--- a/net/bluetooth/hci_sock.c
100709+++ b/net/bluetooth/hci_sock.c
100710@@ -1067,7 +1067,7 @@ static int hci_sock_setsockopt(struct socket *sock, int level, int optname,
100711 uf.event_mask[1] = *((u32 *) f->event_mask + 1);
100712 }
100713
100714- len = min_t(unsigned int, len, sizeof(uf));
100715+ len = min((size_t)len, sizeof(uf));
100716 if (copy_from_user(&uf, optval, len)) {
100717 err = -EFAULT;
100718 break;
100719diff --git a/net/bluetooth/hidp/core.c b/net/bluetooth/hidp/core.c
100720index 1b7d605..02ebd10 100644
100721--- a/net/bluetooth/hidp/core.c
100722+++ b/net/bluetooth/hidp/core.c
100723@@ -1318,13 +1318,14 @@ int hidp_connection_add(struct hidp_connadd_req *req,
100724 {
100725 struct hidp_session *session;
100726 struct l2cap_conn *conn;
100727- struct l2cap_chan *chan = l2cap_pi(ctrl_sock->sk)->chan;
100728+ struct l2cap_chan *chan;
100729 int ret;
100730
100731 ret = hidp_verify_sockets(ctrl_sock, intr_sock);
100732 if (ret)
100733 return ret;
100734
100735+ chan = l2cap_pi(ctrl_sock->sk)->chan;
100736 conn = NULL;
100737 l2cap_chan_lock(chan);
100738 if (chan->conn)
100739diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
100740index b6f9777..36d3039 100644
100741--- a/net/bluetooth/l2cap_core.c
100742+++ b/net/bluetooth/l2cap_core.c
100743@@ -3512,8 +3512,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len,
100744 break;
100745
100746 case L2CAP_CONF_RFC:
100747- if (olen == sizeof(rfc))
100748- memcpy(&rfc, (void *)val, olen);
100749+ if (olen != sizeof(rfc))
100750+ break;
100751+
100752+ memcpy(&rfc, (void *)val, olen);
100753
100754 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
100755 rfc.mode != chan->mode)
100756diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
100757index 31f106e..323f606 100644
100758--- a/net/bluetooth/l2cap_sock.c
100759+++ b/net/bluetooth/l2cap_sock.c
100760@@ -628,7 +628,8 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
100761 struct sock *sk = sock->sk;
100762 struct l2cap_chan *chan = l2cap_pi(sk)->chan;
100763 struct l2cap_options opts;
100764- int len, err = 0;
100765+ int err = 0;
100766+ size_t len = optlen;
100767 u32 opt;
100768
100769 BT_DBG("sk %p", sk);
100770@@ -655,7 +656,7 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
100771 opts.max_tx = chan->max_tx;
100772 opts.txwin_size = chan->tx_win;
100773
100774- len = min_t(unsigned int, sizeof(opts), optlen);
100775+ len = min(sizeof(opts), len);
100776 if (copy_from_user((char *) &opts, optval, len)) {
100777 err = -EFAULT;
100778 break;
100779@@ -742,7 +743,8 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
100780 struct bt_security sec;
100781 struct bt_power pwr;
100782 struct l2cap_conn *conn;
100783- int len, err = 0;
100784+ int err = 0;
100785+ size_t len = optlen;
100786 u32 opt;
100787
100788 BT_DBG("sk %p", sk);
100789@@ -766,7 +768,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
100790
100791 sec.level = BT_SECURITY_LOW;
100792
100793- len = min_t(unsigned int, sizeof(sec), optlen);
100794+ len = min(sizeof(sec), len);
100795 if (copy_from_user((char *) &sec, optval, len)) {
100796 err = -EFAULT;
100797 break;
100798@@ -862,7 +864,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
100799
100800 pwr.force_active = BT_POWER_FORCE_ACTIVE_ON;
100801
100802- len = min_t(unsigned int, sizeof(pwr), optlen);
100803+ len = min(sizeof(pwr), len);
100804 if (copy_from_user((char *) &pwr, optval, len)) {
100805 err = -EFAULT;
100806 break;
100807diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
100808index 8bbbb5e..6fc0950 100644
100809--- a/net/bluetooth/rfcomm/sock.c
100810+++ b/net/bluetooth/rfcomm/sock.c
100811@@ -687,7 +687,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
100812 struct sock *sk = sock->sk;
100813 struct bt_security sec;
100814 int err = 0;
100815- size_t len;
100816+ size_t len = optlen;
100817 u32 opt;
100818
100819 BT_DBG("sk %p", sk);
100820@@ -709,7 +709,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
100821
100822 sec.level = BT_SECURITY_LOW;
100823
100824- len = min_t(unsigned int, sizeof(sec), optlen);
100825+ len = min(sizeof(sec), len);
100826 if (copy_from_user((char *) &sec, optval, len)) {
100827 err = -EFAULT;
100828 break;
100829diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
100830index 8e385a0..a5bdd8e 100644
100831--- a/net/bluetooth/rfcomm/tty.c
100832+++ b/net/bluetooth/rfcomm/tty.c
100833@@ -752,7 +752,7 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
100834 BT_DBG("tty %p id %d", tty, tty->index);
100835
100836 BT_DBG("dev %p dst %pMR channel %d opened %d", dev, &dev->dst,
100837- dev->channel, dev->port.count);
100838+ dev->channel, atomic_read(&dev->port.count));
100839
100840 err = tty_port_open(&dev->port, tty, filp);
100841 if (err)
100842@@ -775,7 +775,7 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
100843 struct rfcomm_dev *dev = (struct rfcomm_dev *) tty->driver_data;
100844
100845 BT_DBG("tty %p dev %p dlc %p opened %d", tty, dev, dev->dlc,
100846- dev->port.count);
100847+ atomic_read(&dev->port.count));
100848
100849 tty_port_close(&dev->port, tty, filp);
100850 }
100851diff --git a/net/bridge/br_netlink.c b/net/bridge/br_netlink.c
100852index e5ec470..cbfabd1 100644
100853--- a/net/bridge/br_netlink.c
100854+++ b/net/bridge/br_netlink.c
100855@@ -564,7 +564,7 @@ static struct rtnl_af_ops br_af_ops = {
100856 .get_link_af_size = br_get_link_af_size,
100857 };
100858
100859-struct rtnl_link_ops br_link_ops __read_mostly = {
100860+struct rtnl_link_ops br_link_ops = {
100861 .kind = "bridge",
100862 .priv_size = sizeof(struct net_bridge),
100863 .setup = br_dev_setup,
100864diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
100865index d9a8c05..8dadc6c6 100644
100866--- a/net/bridge/netfilter/ebtables.c
100867+++ b/net/bridge/netfilter/ebtables.c
100868@@ -1533,7 +1533,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
100869 tmp.valid_hooks = t->table->valid_hooks;
100870 }
100871 mutex_unlock(&ebt_mutex);
100872- if (copy_to_user(user, &tmp, *len) != 0) {
100873+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
100874 BUGPRINT("c2u Didn't work\n");
100875 ret = -EFAULT;
100876 break;
100877@@ -2339,7 +2339,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
100878 goto out;
100879 tmp.valid_hooks = t->valid_hooks;
100880
100881- if (copy_to_user(user, &tmp, *len) != 0) {
100882+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
100883 ret = -EFAULT;
100884 break;
100885 }
100886@@ -2350,7 +2350,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
100887 tmp.entries_size = t->table->entries_size;
100888 tmp.valid_hooks = t->table->valid_hooks;
100889
100890- if (copy_to_user(user, &tmp, *len) != 0) {
100891+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
100892 ret = -EFAULT;
100893 break;
100894 }
100895diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
100896index f5afda1..dcf770a 100644
100897--- a/net/caif/cfctrl.c
100898+++ b/net/caif/cfctrl.c
100899@@ -10,6 +10,7 @@
100900 #include <linux/spinlock.h>
100901 #include <linux/slab.h>
100902 #include <linux/pkt_sched.h>
100903+#include <linux/sched.h>
100904 #include <net/caif/caif_layer.h>
100905 #include <net/caif/cfpkt.h>
100906 #include <net/caif/cfctrl.h>
100907@@ -43,8 +44,8 @@ struct cflayer *cfctrl_create(void)
100908 memset(&dev_info, 0, sizeof(dev_info));
100909 dev_info.id = 0xff;
100910 cfsrvl_init(&this->serv, 0, &dev_info, false);
100911- atomic_set(&this->req_seq_no, 1);
100912- atomic_set(&this->rsp_seq_no, 1);
100913+ atomic_set_unchecked(&this->req_seq_no, 1);
100914+ atomic_set_unchecked(&this->rsp_seq_no, 1);
100915 this->serv.layer.receive = cfctrl_recv;
100916 sprintf(this->serv.layer.name, "ctrl");
100917 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
100918@@ -130,8 +131,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
100919 struct cfctrl_request_info *req)
100920 {
100921 spin_lock_bh(&ctrl->info_list_lock);
100922- atomic_inc(&ctrl->req_seq_no);
100923- req->sequence_no = atomic_read(&ctrl->req_seq_no);
100924+ atomic_inc_unchecked(&ctrl->req_seq_no);
100925+ req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
100926 list_add_tail(&req->list, &ctrl->list);
100927 spin_unlock_bh(&ctrl->info_list_lock);
100928 }
100929@@ -149,7 +150,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
100930 if (p != first)
100931 pr_warn("Requests are not received in order\n");
100932
100933- atomic_set(&ctrl->rsp_seq_no,
100934+ atomic_set_unchecked(&ctrl->rsp_seq_no,
100935 p->sequence_no);
100936 list_del(&p->list);
100937 goto out;
100938diff --git a/net/caif/chnl_net.c b/net/caif/chnl_net.c
100939index 4589ff67..46d6b8f 100644
100940--- a/net/caif/chnl_net.c
100941+++ b/net/caif/chnl_net.c
100942@@ -516,7 +516,7 @@ static const struct nla_policy ipcaif_policy[IFLA_CAIF_MAX + 1] = {
100943 };
100944
100945
100946-static struct rtnl_link_ops ipcaif_link_ops __read_mostly = {
100947+static struct rtnl_link_ops ipcaif_link_ops = {
100948 .kind = "caif",
100949 .priv_size = sizeof(struct chnl_net),
100950 .setup = ipcaif_net_setup,
100951diff --git a/net/can/af_can.c b/net/can/af_can.c
100952index ce82337..5d17b4d 100644
100953--- a/net/can/af_can.c
100954+++ b/net/can/af_can.c
100955@@ -884,7 +884,7 @@ static const struct net_proto_family can_family_ops = {
100956 };
100957
100958 /* notifier block for netdevice event */
100959-static struct notifier_block can_netdev_notifier __read_mostly = {
100960+static struct notifier_block can_netdev_notifier = {
100961 .notifier_call = can_notifier,
100962 };
100963
100964diff --git a/net/can/bcm.c b/net/can/bcm.c
100965index dcb75c0..24b1b43 100644
100966--- a/net/can/bcm.c
100967+++ b/net/can/bcm.c
100968@@ -1624,7 +1624,7 @@ static int __init bcm_module_init(void)
100969 }
100970
100971 /* create /proc/net/can-bcm directory */
100972- proc_dir = proc_mkdir("can-bcm", init_net.proc_net);
100973+ proc_dir = proc_mkdir_restrict("can-bcm", init_net.proc_net);
100974 return 0;
100975 }
100976
100977diff --git a/net/can/gw.c b/net/can/gw.c
100978index 050a211..bb9fe33 100644
100979--- a/net/can/gw.c
100980+++ b/net/can/gw.c
100981@@ -80,7 +80,6 @@ MODULE_PARM_DESC(max_hops,
100982 "default: " __stringify(CGW_DEFAULT_HOPS) ")");
100983
100984 static HLIST_HEAD(cgw_list);
100985-static struct notifier_block notifier;
100986
100987 static struct kmem_cache *cgw_cache __read_mostly;
100988
100989@@ -947,6 +946,10 @@ static int cgw_remove_job(struct sk_buff *skb, struct nlmsghdr *nlh)
100990 return err;
100991 }
100992
100993+static struct notifier_block notifier = {
100994+ .notifier_call = cgw_notifier
100995+};
100996+
100997 static __init int cgw_module_init(void)
100998 {
100999 /* sanitize given module parameter */
101000@@ -962,7 +965,6 @@ static __init int cgw_module_init(void)
101001 return -ENOMEM;
101002
101003 /* set notifier */
101004- notifier.notifier_call = cgw_notifier;
101005 register_netdevice_notifier(&notifier);
101006
101007 if (__rtnl_register(PF_CAN, RTM_GETROUTE, NULL, cgw_dump_jobs, NULL)) {
101008diff --git a/net/can/proc.c b/net/can/proc.c
101009index 1a19b98..df2b4ec 100644
101010--- a/net/can/proc.c
101011+++ b/net/can/proc.c
101012@@ -514,7 +514,7 @@ static void can_remove_proc_readentry(const char *name)
101013 void can_init_proc(void)
101014 {
101015 /* create /proc/net/can directory */
101016- can_dir = proc_mkdir("can", init_net.proc_net);
101017+ can_dir = proc_mkdir_restrict("can", init_net.proc_net);
101018
101019 if (!can_dir) {
101020 printk(KERN_INFO "can: failed to create /proc/net/can . "
101021diff --git a/net/ceph/messenger.c b/net/ceph/messenger.c
101022index 8d1653c..77ad145 100644
101023--- a/net/ceph/messenger.c
101024+++ b/net/ceph/messenger.c
101025@@ -188,7 +188,7 @@ static void con_fault(struct ceph_connection *con);
101026 #define MAX_ADDR_STR_LEN 64 /* 54 is enough */
101027
101028 static char addr_str[ADDR_STR_COUNT][MAX_ADDR_STR_LEN];
101029-static atomic_t addr_str_seq = ATOMIC_INIT(0);
101030+static atomic_unchecked_t addr_str_seq = ATOMIC_INIT(0);
101031
101032 static struct page *zero_page; /* used in certain error cases */
101033
101034@@ -199,7 +199,7 @@ const char *ceph_pr_addr(const struct sockaddr_storage *ss)
101035 struct sockaddr_in *in4 = (struct sockaddr_in *) ss;
101036 struct sockaddr_in6 *in6 = (struct sockaddr_in6 *) ss;
101037
101038- i = atomic_inc_return(&addr_str_seq) & ADDR_STR_COUNT_MASK;
101039+ i = atomic_inc_return_unchecked(&addr_str_seq) & ADDR_STR_COUNT_MASK;
101040 s = addr_str[i];
101041
101042 switch (ss->ss_family) {
101043diff --git a/net/compat.c b/net/compat.c
101044index bc8aeef..f9c070c 100644
101045--- a/net/compat.c
101046+++ b/net/compat.c
101047@@ -73,9 +73,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
101048 return -EFAULT;
101049 if (kmsg->msg_namelen > sizeof(struct sockaddr_storage))
101050 kmsg->msg_namelen = sizeof(struct sockaddr_storage);
101051- kmsg->msg_name = compat_ptr(tmp1);
101052- kmsg->msg_iov = compat_ptr(tmp2);
101053- kmsg->msg_control = compat_ptr(tmp3);
101054+ kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
101055+ kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
101056+ kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
101057 return 0;
101058 }
101059
101060@@ -87,7 +87,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
101061
101062 if (kern_msg->msg_name && kern_msg->msg_namelen) {
101063 if (mode == VERIFY_READ) {
101064- int err = move_addr_to_kernel(kern_msg->msg_name,
101065+ int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
101066 kern_msg->msg_namelen,
101067 kern_address);
101068 if (err < 0)
101069@@ -100,7 +100,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
101070 }
101071
101072 tot_len = iov_from_user_compat_to_kern(kern_iov,
101073- (struct compat_iovec __user *)kern_msg->msg_iov,
101074+ (struct compat_iovec __force_user *)kern_msg->msg_iov,
101075 kern_msg->msg_iovlen);
101076 if (tot_len >= 0)
101077 kern_msg->msg_iov = kern_iov;
101078@@ -120,20 +120,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
101079
101080 #define CMSG_COMPAT_FIRSTHDR(msg) \
101081 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
101082- (struct compat_cmsghdr __user *)((msg)->msg_control) : \
101083+ (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
101084 (struct compat_cmsghdr __user *)NULL)
101085
101086 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
101087 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
101088 (ucmlen) <= (unsigned long) \
101089 ((mhdr)->msg_controllen - \
101090- ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
101091+ ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
101092
101093 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
101094 struct compat_cmsghdr __user *cmsg, int cmsg_len)
101095 {
101096 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
101097- if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
101098+ if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
101099 msg->msg_controllen)
101100 return NULL;
101101 return (struct compat_cmsghdr __user *)ptr;
101102@@ -223,7 +223,7 @@ Efault:
101103
101104 int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
101105 {
101106- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
101107+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
101108 struct compat_cmsghdr cmhdr;
101109 struct compat_timeval ctv;
101110 struct compat_timespec cts[3];
101111@@ -279,7 +279,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
101112
101113 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
101114 {
101115- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
101116+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
101117 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
101118 int fdnum = scm->fp->count;
101119 struct file **fp = scm->fp->fp;
101120@@ -367,7 +367,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
101121 return -EFAULT;
101122 old_fs = get_fs();
101123 set_fs(KERNEL_DS);
101124- err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
101125+ err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
101126 set_fs(old_fs);
101127
101128 return err;
101129@@ -428,7 +428,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
101130 len = sizeof(ktime);
101131 old_fs = get_fs();
101132 set_fs(KERNEL_DS);
101133- err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
101134+ err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
101135 set_fs(old_fs);
101136
101137 if (!err) {
101138@@ -571,7 +571,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
101139 case MCAST_JOIN_GROUP:
101140 case MCAST_LEAVE_GROUP:
101141 {
101142- struct compat_group_req __user *gr32 = (void *)optval;
101143+ struct compat_group_req __user *gr32 = (void __user *)optval;
101144 struct group_req __user *kgr =
101145 compat_alloc_user_space(sizeof(struct group_req));
101146 u32 interface;
101147@@ -592,7 +592,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
101148 case MCAST_BLOCK_SOURCE:
101149 case MCAST_UNBLOCK_SOURCE:
101150 {
101151- struct compat_group_source_req __user *gsr32 = (void *)optval;
101152+ struct compat_group_source_req __user *gsr32 = (void __user *)optval;
101153 struct group_source_req __user *kgsr = compat_alloc_user_space(
101154 sizeof(struct group_source_req));
101155 u32 interface;
101156@@ -613,7 +613,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
101157 }
101158 case MCAST_MSFILTER:
101159 {
101160- struct compat_group_filter __user *gf32 = (void *)optval;
101161+ struct compat_group_filter __user *gf32 = (void __user *)optval;
101162 struct group_filter __user *kgf;
101163 u32 interface, fmode, numsrc;
101164
101165@@ -651,7 +651,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
101166 char __user *optval, int __user *optlen,
101167 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
101168 {
101169- struct compat_group_filter __user *gf32 = (void *)optval;
101170+ struct compat_group_filter __user *gf32 = (void __user *)optval;
101171 struct group_filter __user *kgf;
101172 int __user *koptlen;
101173 u32 interface, fmode, numsrc;
101174@@ -804,7 +804,7 @@ COMPAT_SYSCALL_DEFINE2(socketcall, int, call, u32 __user *, args)
101175
101176 if (call < SYS_SOCKET || call > SYS_SENDMMSG)
101177 return -EINVAL;
101178- if (copy_from_user(a, args, nas[call]))
101179+ if (nas[call] > sizeof a || copy_from_user(a, args, nas[call]))
101180 return -EFAULT;
101181 a0 = a[0];
101182 a1 = a[1];
101183diff --git a/net/core/datagram.c b/net/core/datagram.c
101184index fdbc9a8..cd6972c 100644
101185--- a/net/core/datagram.c
101186+++ b/net/core/datagram.c
101187@@ -301,7 +301,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
101188 }
101189
101190 kfree_skb(skb);
101191- atomic_inc(&sk->sk_drops);
101192+ atomic_inc_unchecked(&sk->sk_drops);
101193 sk_mem_reclaim_partial(sk);
101194
101195 return err;
101196diff --git a/net/core/dev.c b/net/core/dev.c
101197index 945bbd0..8b1a370 100644
101198--- a/net/core/dev.c
101199+++ b/net/core/dev.c
101200@@ -1683,14 +1683,14 @@ int __dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
101201 {
101202 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
101203 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
101204- atomic_long_inc(&dev->rx_dropped);
101205+ atomic_long_inc_unchecked(&dev->rx_dropped);
101206 kfree_skb(skb);
101207 return NET_RX_DROP;
101208 }
101209 }
101210
101211 if (unlikely(!is_skb_forwardable(dev, skb))) {
101212- atomic_long_inc(&dev->rx_dropped);
101213+ atomic_long_inc_unchecked(&dev->rx_dropped);
101214 kfree_skb(skb);
101215 return NET_RX_DROP;
101216 }
101217@@ -2985,7 +2985,7 @@ recursion_alert:
101218 drop:
101219 rcu_read_unlock_bh();
101220
101221- atomic_long_inc(&dev->tx_dropped);
101222+ atomic_long_inc_unchecked(&dev->tx_dropped);
101223 kfree_skb_list(skb);
101224 return rc;
101225 out:
101226@@ -3328,7 +3328,7 @@ enqueue:
101227
101228 local_irq_restore(flags);
101229
101230- atomic_long_inc(&skb->dev->rx_dropped);
101231+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
101232 kfree_skb(skb);
101233 return NET_RX_DROP;
101234 }
101235@@ -3405,7 +3405,7 @@ int netif_rx_ni(struct sk_buff *skb)
101236 }
101237 EXPORT_SYMBOL(netif_rx_ni);
101238
101239-static void net_tx_action(struct softirq_action *h)
101240+static __latent_entropy void net_tx_action(void)
101241 {
101242 struct softnet_data *sd = this_cpu_ptr(&softnet_data);
101243
101244@@ -3738,7 +3738,7 @@ ncls:
101245 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
101246 } else {
101247 drop:
101248- atomic_long_inc(&skb->dev->rx_dropped);
101249+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
101250 kfree_skb(skb);
101251 /* Jamal, now you will not able to escape explaining
101252 * me how you were going to use this. :-)
101253@@ -4502,7 +4502,7 @@ void netif_napi_del(struct napi_struct *napi)
101254 }
101255 EXPORT_SYMBOL(netif_napi_del);
101256
101257-static void net_rx_action(struct softirq_action *h)
101258+static __latent_entropy void net_rx_action(void)
101259 {
101260 struct softnet_data *sd = this_cpu_ptr(&softnet_data);
101261 unsigned long time_limit = jiffies + 2;
101262@@ -6548,8 +6548,8 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
101263 } else {
101264 netdev_stats_to_stats64(storage, &dev->stats);
101265 }
101266- storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
101267- storage->tx_dropped += atomic_long_read(&dev->tx_dropped);
101268+ storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
101269+ storage->tx_dropped += atomic_long_read_unchecked(&dev->tx_dropped);
101270 return storage;
101271 }
101272 EXPORT_SYMBOL(dev_get_stats);
101273diff --git a/net/core/dev_ioctl.c b/net/core/dev_ioctl.c
101274index 72e899a..79a9409 100644
101275--- a/net/core/dev_ioctl.c
101276+++ b/net/core/dev_ioctl.c
101277@@ -365,8 +365,13 @@ void dev_load(struct net *net, const char *name)
101278 no_module = !dev;
101279 if (no_module && capable(CAP_NET_ADMIN))
101280 no_module = request_module("netdev-%s", name);
101281- if (no_module && capable(CAP_SYS_MODULE))
101282+ if (no_module && capable(CAP_SYS_MODULE)) {
101283+#ifdef CONFIG_GRKERNSEC_MODHARDEN
101284+ ___request_module(true, "grsec_modharden_netdev", "%s", name);
101285+#else
101286 request_module("%s", name);
101287+#endif
101288+ }
101289 }
101290 EXPORT_SYMBOL(dev_load);
101291
101292diff --git a/net/core/filter.c b/net/core/filter.c
101293index 647b122..18a7ff6 100644
101294--- a/net/core/filter.c
101295+++ b/net/core/filter.c
101296@@ -532,7 +532,11 @@ do_pass:
101297
101298 /* Unkown instruction. */
101299 default:
101300- goto err;
101301+ WARN(1, KERN_ALERT "Unknown sock filter code:%u jt:%u tf:%u k:%u\n",
101302+ fp->code, fp->jt, fp->jf, fp->k);
101303+ kfree(addrs);
101304+ BUG();
101305+ return -EINVAL;
101306 }
101307
101308 insn++;
101309@@ -576,7 +580,7 @@ static int check_load_and_stores(const struct sock_filter *filter, int flen)
101310 u16 *masks, memvalid = 0; /* One bit per cell, 16 cells */
101311 int pc, ret = 0;
101312
101313- BUILD_BUG_ON(BPF_MEMWORDS > 16);
101314+ BUILD_BUG_ON(BPF_MEMWORDS != 16);
101315
101316 masks = kmalloc_array(flen, sizeof(*masks), GFP_KERNEL);
101317 if (!masks)
101318@@ -987,7 +991,7 @@ int bpf_prog_create(struct bpf_prog **pfp, struct sock_fprog_kern *fprog)
101319 if (!fp)
101320 return -ENOMEM;
101321
101322- memcpy(fp->insns, fprog->filter, fsize);
101323+ memcpy(fp->insns, (void __force_kernel *)fprog->filter, fsize);
101324
101325 fp->len = fprog->len;
101326 /* Since unattached filters are not copied back to user
101327diff --git a/net/core/flow.c b/net/core/flow.c
101328index a0348fd..6951c76 100644
101329--- a/net/core/flow.c
101330+++ b/net/core/flow.c
101331@@ -65,7 +65,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
101332 static int flow_entry_valid(struct flow_cache_entry *fle,
101333 struct netns_xfrm *xfrm)
101334 {
101335- if (atomic_read(&xfrm->flow_cache_genid) != fle->genid)
101336+ if (atomic_read_unchecked(&xfrm->flow_cache_genid) != fle->genid)
101337 return 0;
101338 if (fle->object && !fle->object->ops->check(fle->object))
101339 return 0;
101340@@ -242,7 +242,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
101341 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
101342 fcp->hash_count++;
101343 }
101344- } else if (likely(fle->genid == atomic_read(&net->xfrm.flow_cache_genid))) {
101345+ } else if (likely(fle->genid == atomic_read_unchecked(&net->xfrm.flow_cache_genid))) {
101346 flo = fle->object;
101347 if (!flo)
101348 goto ret_object;
101349@@ -263,7 +263,7 @@ nocache:
101350 }
101351 flo = resolver(net, key, family, dir, flo, ctx);
101352 if (fle) {
101353- fle->genid = atomic_read(&net->xfrm.flow_cache_genid);
101354+ fle->genid = atomic_read_unchecked(&net->xfrm.flow_cache_genid);
101355 if (!IS_ERR(flo))
101356 fle->object = flo;
101357 else
101358diff --git a/net/core/iovec.c b/net/core/iovec.c
101359index e1ec45a..e5c6f16 100644
101360--- a/net/core/iovec.c
101361+++ b/net/core/iovec.c
101362@@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
101363 if (m->msg_name && m->msg_namelen) {
101364 if (mode == VERIFY_READ) {
101365 void __user *namep;
101366- namep = (void __user __force *) m->msg_name;
101367+ namep = (void __force_user *) m->msg_name;
101368 err = move_addr_to_kernel(namep, m->msg_namelen,
101369 address);
101370 if (err < 0)
101371@@ -55,7 +55,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
101372 }
101373
101374 size = m->msg_iovlen * sizeof(struct iovec);
101375- if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
101376+ if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
101377 return -EFAULT;
101378
101379 m->msg_iov = iov;
101380diff --git a/net/core/neighbour.c b/net/core/neighbour.c
101381index ef31fef..8be66d9 100644
101382--- a/net/core/neighbour.c
101383+++ b/net/core/neighbour.c
101384@@ -2825,7 +2825,7 @@ static int proc_unres_qlen(struct ctl_table *ctl, int write,
101385 void __user *buffer, size_t *lenp, loff_t *ppos)
101386 {
101387 int size, ret;
101388- struct ctl_table tmp = *ctl;
101389+ ctl_table_no_const tmp = *ctl;
101390
101391 tmp.extra1 = &zero;
101392 tmp.extra2 = &unres_qlen_max;
101393@@ -2887,7 +2887,7 @@ static int neigh_proc_dointvec_zero_intmax(struct ctl_table *ctl, int write,
101394 void __user *buffer,
101395 size_t *lenp, loff_t *ppos)
101396 {
101397- struct ctl_table tmp = *ctl;
101398+ ctl_table_no_const tmp = *ctl;
101399 int ret;
101400
101401 tmp.extra1 = &zero;
101402diff --git a/net/core/net-procfs.c b/net/core/net-procfs.c
101403index 2bf8329..2eb1423 100644
101404--- a/net/core/net-procfs.c
101405+++ b/net/core/net-procfs.c
101406@@ -79,7 +79,13 @@ static void dev_seq_printf_stats(struct seq_file *seq, struct net_device *dev)
101407 struct rtnl_link_stats64 temp;
101408 const struct rtnl_link_stats64 *stats = dev_get_stats(dev, &temp);
101409
101410- seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
101411+ if (gr_proc_is_restricted())
101412+ seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
101413+ "%8llu %7llu %4llu %4llu %4llu %5llu %7llu %10llu\n",
101414+ dev->name, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL,
101415+ 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL);
101416+ else
101417+ seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
101418 "%8llu %7llu %4llu %4llu %4llu %5llu %7llu %10llu\n",
101419 dev->name, stats->rx_bytes, stats->rx_packets,
101420 stats->rx_errors,
101421@@ -166,7 +172,7 @@ static int softnet_seq_show(struct seq_file *seq, void *v)
101422 return 0;
101423 }
101424
101425-static const struct seq_operations dev_seq_ops = {
101426+const struct seq_operations dev_seq_ops = {
101427 .start = dev_seq_start,
101428 .next = dev_seq_next,
101429 .stop = dev_seq_stop,
101430@@ -196,7 +202,7 @@ static const struct seq_operations softnet_seq_ops = {
101431
101432 static int softnet_seq_open(struct inode *inode, struct file *file)
101433 {
101434- return seq_open(file, &softnet_seq_ops);
101435+ return seq_open_restrict(file, &softnet_seq_ops);
101436 }
101437
101438 static const struct file_operations softnet_seq_fops = {
101439@@ -283,8 +289,13 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
101440 else
101441 seq_printf(seq, "%04x", ntohs(pt->type));
101442
101443+#ifdef CONFIG_GRKERNSEC_HIDESYM
101444+ seq_printf(seq, " %-8s %pf\n",
101445+ pt->dev ? pt->dev->name : "", NULL);
101446+#else
101447 seq_printf(seq, " %-8s %pf\n",
101448 pt->dev ? pt->dev->name : "", pt->func);
101449+#endif
101450 }
101451
101452 return 0;
101453diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
101454index 9dd0669..c52fb1b 100644
101455--- a/net/core/net-sysfs.c
101456+++ b/net/core/net-sysfs.c
101457@@ -278,7 +278,7 @@ static ssize_t carrier_changes_show(struct device *dev,
101458 {
101459 struct net_device *netdev = to_net_dev(dev);
101460 return sprintf(buf, fmt_dec,
101461- atomic_read(&netdev->carrier_changes));
101462+ atomic_read_unchecked(&netdev->carrier_changes));
101463 }
101464 static DEVICE_ATTR_RO(carrier_changes);
101465
101466diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
101467index 7f15517..f7d65c0 100644
101468--- a/net/core/net_namespace.c
101469+++ b/net/core/net_namespace.c
101470@@ -445,7 +445,7 @@ static int __register_pernet_operations(struct list_head *list,
101471 int error;
101472 LIST_HEAD(net_exit_list);
101473
101474- list_add_tail(&ops->list, list);
101475+ pax_list_add_tail((struct list_head *)&ops->list, list);
101476 if (ops->init || (ops->id && ops->size)) {
101477 for_each_net(net) {
101478 error = ops_init(ops, net);
101479@@ -458,7 +458,7 @@ static int __register_pernet_operations(struct list_head *list,
101480
101481 out_undo:
101482 /* If I have an error cleanup all namespaces I initialized */
101483- list_del(&ops->list);
101484+ pax_list_del((struct list_head *)&ops->list);
101485 ops_exit_list(ops, &net_exit_list);
101486 ops_free_list(ops, &net_exit_list);
101487 return error;
101488@@ -469,7 +469,7 @@ static void __unregister_pernet_operations(struct pernet_operations *ops)
101489 struct net *net;
101490 LIST_HEAD(net_exit_list);
101491
101492- list_del(&ops->list);
101493+ pax_list_del((struct list_head *)&ops->list);
101494 for_each_net(net)
101495 list_add_tail(&net->exit_list, &net_exit_list);
101496 ops_exit_list(ops, &net_exit_list);
101497@@ -603,7 +603,7 @@ int register_pernet_device(struct pernet_operations *ops)
101498 mutex_lock(&net_mutex);
101499 error = register_pernet_operations(&pernet_list, ops);
101500 if (!error && (first_device == &pernet_list))
101501- first_device = &ops->list;
101502+ first_device = (struct list_head *)&ops->list;
101503 mutex_unlock(&net_mutex);
101504 return error;
101505 }
101506diff --git a/net/core/netpoll.c b/net/core/netpoll.c
101507index e6645b4..43e1af9 100644
101508--- a/net/core/netpoll.c
101509+++ b/net/core/netpoll.c
101510@@ -379,7 +379,7 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len)
101511 struct udphdr *udph;
101512 struct iphdr *iph;
101513 struct ethhdr *eth;
101514- static atomic_t ip_ident;
101515+ static atomic_unchecked_t ip_ident;
101516 struct ipv6hdr *ip6h;
101517
101518 udp_len = len + sizeof(*udph);
101519@@ -450,7 +450,7 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len)
101520 put_unaligned(0x45, (unsigned char *)iph);
101521 iph->tos = 0;
101522 put_unaligned(htons(ip_len), &(iph->tot_len));
101523- iph->id = htons(atomic_inc_return(&ip_ident));
101524+ iph->id = htons(atomic_inc_return_unchecked(&ip_ident));
101525 iph->frag_off = 0;
101526 iph->ttl = 64;
101527 iph->protocol = IPPROTO_UDP;
101528diff --git a/net/core/pktgen.c b/net/core/pktgen.c
101529index 443256b..bbff424 100644
101530--- a/net/core/pktgen.c
101531+++ b/net/core/pktgen.c
101532@@ -3753,7 +3753,7 @@ static int __net_init pg_net_init(struct net *net)
101533 pn->net = net;
101534 INIT_LIST_HEAD(&pn->pktgen_threads);
101535 pn->pktgen_exiting = false;
101536- pn->proc_dir = proc_mkdir(PG_PROC_DIR, pn->net->proc_net);
101537+ pn->proc_dir = proc_mkdir_restrict(PG_PROC_DIR, pn->net->proc_net);
101538 if (!pn->proc_dir) {
101539 pr_warn("cannot create /proc/net/%s\n", PG_PROC_DIR);
101540 return -ENODEV;
101541diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
101542index 76321ea..3129bd6 100644
101543--- a/net/core/rtnetlink.c
101544+++ b/net/core/rtnetlink.c
101545@@ -58,7 +58,7 @@ struct rtnl_link {
101546 rtnl_doit_func doit;
101547 rtnl_dumpit_func dumpit;
101548 rtnl_calcit_func calcit;
101549-};
101550+} __no_const;
101551
101552 static DEFINE_MUTEX(rtnl_mutex);
101553
101554@@ -304,10 +304,13 @@ int __rtnl_link_register(struct rtnl_link_ops *ops)
101555 * to use the ops for creating device. So do not
101556 * fill up dellink as well. That disables rtnl_dellink.
101557 */
101558- if (ops->setup && !ops->dellink)
101559- ops->dellink = unregister_netdevice_queue;
101560+ if (ops->setup && !ops->dellink) {
101561+ pax_open_kernel();
101562+ *(void **)&ops->dellink = unregister_netdevice_queue;
101563+ pax_close_kernel();
101564+ }
101565
101566- list_add_tail(&ops->list, &link_ops);
101567+ pax_list_add_tail((struct list_head *)&ops->list, &link_ops);
101568 return 0;
101569 }
101570 EXPORT_SYMBOL_GPL(__rtnl_link_register);
101571@@ -354,7 +357,7 @@ void __rtnl_link_unregister(struct rtnl_link_ops *ops)
101572 for_each_net(net) {
101573 __rtnl_kill_links(net, ops);
101574 }
101575- list_del(&ops->list);
101576+ pax_list_del((struct list_head *)&ops->list);
101577 }
101578 EXPORT_SYMBOL_GPL(__rtnl_link_unregister);
101579
101580@@ -1014,7 +1017,7 @@ static int rtnl_fill_ifinfo(struct sk_buff *skb, struct net_device *dev,
101581 (dev->ifalias &&
101582 nla_put_string(skb, IFLA_IFALIAS, dev->ifalias)) ||
101583 nla_put_u32(skb, IFLA_CARRIER_CHANGES,
101584- atomic_read(&dev->carrier_changes)))
101585+ atomic_read_unchecked(&dev->carrier_changes)))
101586 goto nla_put_failure;
101587
101588 if (1) {
101589diff --git a/net/core/scm.c b/net/core/scm.c
101590index b442e7e..6f5b5a2 100644
101591--- a/net/core/scm.c
101592+++ b/net/core/scm.c
101593@@ -210,7 +210,7 @@ EXPORT_SYMBOL(__scm_send);
101594 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
101595 {
101596 struct cmsghdr __user *cm
101597- = (__force struct cmsghdr __user *)msg->msg_control;
101598+ = (struct cmsghdr __force_user *)msg->msg_control;
101599 struct cmsghdr cmhdr;
101600 int cmlen = CMSG_LEN(len);
101601 int err;
101602@@ -233,7 +233,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
101603 err = -EFAULT;
101604 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
101605 goto out;
101606- if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
101607+ if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
101608 goto out;
101609 cmlen = CMSG_SPACE(len);
101610 if (msg->msg_controllen < cmlen)
101611@@ -249,7 +249,7 @@ EXPORT_SYMBOL(put_cmsg);
101612 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
101613 {
101614 struct cmsghdr __user *cm
101615- = (__force struct cmsghdr __user*)msg->msg_control;
101616+ = (struct cmsghdr __force_user *)msg->msg_control;
101617
101618 int fdmax = 0;
101619 int fdnum = scm->fp->count;
101620@@ -269,7 +269,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
101621 if (fdnum < fdmax)
101622 fdmax = fdnum;
101623
101624- for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
101625+ for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
101626 i++, cmfptr++)
101627 {
101628 struct socket *sock;
101629diff --git a/net/core/skbuff.c b/net/core/skbuff.c
101630index 32e31c2..e981248 100644
101631--- a/net/core/skbuff.c
101632+++ b/net/core/skbuff.c
101633@@ -2025,7 +2025,7 @@ EXPORT_SYMBOL(__skb_checksum);
101634 __wsum skb_checksum(const struct sk_buff *skb, int offset,
101635 int len, __wsum csum)
101636 {
101637- const struct skb_checksum_ops ops = {
101638+ static const struct skb_checksum_ops ops = {
101639 .update = csum_partial_ext,
101640 .combine = csum_block_add_ext,
101641 };
101642@@ -3255,12 +3255,14 @@ void __init skb_init(void)
101643 skbuff_head_cache = kmem_cache_create("skbuff_head_cache",
101644 sizeof(struct sk_buff),
101645 0,
101646- SLAB_HWCACHE_ALIGN|SLAB_PANIC,
101647+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|
101648+ SLAB_NO_SANITIZE,
101649 NULL);
101650 skbuff_fclone_cache = kmem_cache_create("skbuff_fclone_cache",
101651 sizeof(struct sk_buff_fclones),
101652 0,
101653- SLAB_HWCACHE_ALIGN|SLAB_PANIC,
101654+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|
101655+ SLAB_NO_SANITIZE,
101656 NULL);
101657 }
101658
101659diff --git a/net/core/sock.c b/net/core/sock.c
101660index 15e0c67..0310f4a 100644
101661--- a/net/core/sock.c
101662+++ b/net/core/sock.c
101663@@ -441,7 +441,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
101664 struct sk_buff_head *list = &sk->sk_receive_queue;
101665
101666 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
101667- atomic_inc(&sk->sk_drops);
101668+ atomic_inc_unchecked(&sk->sk_drops);
101669 trace_sock_rcvqueue_full(sk, skb);
101670 return -ENOMEM;
101671 }
101672@@ -451,7 +451,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
101673 return err;
101674
101675 if (!sk_rmem_schedule(sk, skb, skb->truesize)) {
101676- atomic_inc(&sk->sk_drops);
101677+ atomic_inc_unchecked(&sk->sk_drops);
101678 return -ENOBUFS;
101679 }
101680
101681@@ -464,7 +464,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
101682 skb_dst_force(skb);
101683
101684 spin_lock_irqsave(&list->lock, flags);
101685- skb->dropcount = atomic_read(&sk->sk_drops);
101686+ skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
101687 __skb_queue_tail(list, skb);
101688 spin_unlock_irqrestore(&list->lock, flags);
101689
101690@@ -484,7 +484,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
101691 skb->dev = NULL;
101692
101693 if (sk_rcvqueues_full(sk, sk->sk_rcvbuf)) {
101694- atomic_inc(&sk->sk_drops);
101695+ atomic_inc_unchecked(&sk->sk_drops);
101696 goto discard_and_relse;
101697 }
101698 if (nested)
101699@@ -502,7 +502,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
101700 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
101701 } else if (sk_add_backlog(sk, skb, sk->sk_rcvbuf)) {
101702 bh_unlock_sock(sk);
101703- atomic_inc(&sk->sk_drops);
101704+ atomic_inc_unchecked(&sk->sk_drops);
101705 goto discard_and_relse;
101706 }
101707
101708@@ -991,12 +991,12 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
101709 struct timeval tm;
101710 } v;
101711
101712- int lv = sizeof(int);
101713- int len;
101714+ unsigned int lv = sizeof(int);
101715+ unsigned int len;
101716
101717 if (get_user(len, optlen))
101718 return -EFAULT;
101719- if (len < 0)
101720+ if (len > INT_MAX)
101721 return -EINVAL;
101722
101723 memset(&v, 0, sizeof(v));
101724@@ -1134,11 +1134,11 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
101725
101726 case SO_PEERNAME:
101727 {
101728- char address[128];
101729+ char address[_K_SS_MAXSIZE];
101730
101731 if (sock->ops->getname(sock, (struct sockaddr *)address, &lv, 2))
101732 return -ENOTCONN;
101733- if (lv < len)
101734+ if (lv < len || sizeof address < len)
101735 return -EINVAL;
101736 if (copy_to_user(optval, address, len))
101737 return -EFAULT;
101738@@ -1219,7 +1219,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
101739
101740 if (len > lv)
101741 len = lv;
101742- if (copy_to_user(optval, &v, len))
101743+ if (len > sizeof(v) || copy_to_user(optval, &v, len))
101744 return -EFAULT;
101745 lenout:
101746 if (put_user(len, optlen))
101747@@ -2315,7 +2315,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
101748 */
101749 smp_wmb();
101750 atomic_set(&sk->sk_refcnt, 1);
101751- atomic_set(&sk->sk_drops, 0);
101752+ atomic_set_unchecked(&sk->sk_drops, 0);
101753 }
101754 EXPORT_SYMBOL(sock_init_data);
101755
101756@@ -2443,6 +2443,7 @@ void sock_enable_timestamp(struct sock *sk, int flag)
101757 int sock_recv_errqueue(struct sock *sk, struct msghdr *msg, int len,
101758 int level, int type)
101759 {
101760+ struct sock_extended_err ee;
101761 struct sock_exterr_skb *serr;
101762 struct sk_buff *skb;
101763 int copied, err;
101764@@ -2464,7 +2465,8 @@ int sock_recv_errqueue(struct sock *sk, struct msghdr *msg, int len,
101765 sock_recv_timestamp(msg, sk, skb);
101766
101767 serr = SKB_EXT_ERR(skb);
101768- put_cmsg(msg, level, type, sizeof(serr->ee), &serr->ee);
101769+ ee = serr->ee;
101770+ put_cmsg(msg, level, type, sizeof ee, &ee);
101771
101772 msg->msg_flags |= MSG_ERRQUEUE;
101773 err = copied;
101774diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
101775index ad704c7..ca48aff 100644
101776--- a/net/core/sock_diag.c
101777+++ b/net/core/sock_diag.c
101778@@ -9,26 +9,33 @@
101779 #include <linux/inet_diag.h>
101780 #include <linux/sock_diag.h>
101781
101782-static const struct sock_diag_handler *sock_diag_handlers[AF_MAX];
101783+static const struct sock_diag_handler *sock_diag_handlers[AF_MAX] __read_only;
101784 static int (*inet_rcv_compat)(struct sk_buff *skb, struct nlmsghdr *nlh);
101785 static DEFINE_MUTEX(sock_diag_table_mutex);
101786
101787 int sock_diag_check_cookie(void *sk, __u32 *cookie)
101788 {
101789+#ifndef CONFIG_GRKERNSEC_HIDESYM
101790 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
101791 cookie[1] != INET_DIAG_NOCOOKIE) &&
101792 ((u32)(unsigned long)sk != cookie[0] ||
101793 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
101794 return -ESTALE;
101795 else
101796+#endif
101797 return 0;
101798 }
101799 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
101800
101801 void sock_diag_save_cookie(void *sk, __u32 *cookie)
101802 {
101803+#ifdef CONFIG_GRKERNSEC_HIDESYM
101804+ cookie[0] = 0;
101805+ cookie[1] = 0;
101806+#else
101807 cookie[0] = (u32)(unsigned long)sk;
101808 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
101809+#endif
101810 }
101811 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
101812
101813@@ -110,8 +117,11 @@ int sock_diag_register(const struct sock_diag_handler *hndl)
101814 mutex_lock(&sock_diag_table_mutex);
101815 if (sock_diag_handlers[hndl->family])
101816 err = -EBUSY;
101817- else
101818+ else {
101819+ pax_open_kernel();
101820 sock_diag_handlers[hndl->family] = hndl;
101821+ pax_close_kernel();
101822+ }
101823 mutex_unlock(&sock_diag_table_mutex);
101824
101825 return err;
101826@@ -127,7 +137,9 @@ void sock_diag_unregister(const struct sock_diag_handler *hnld)
101827
101828 mutex_lock(&sock_diag_table_mutex);
101829 BUG_ON(sock_diag_handlers[family] != hnld);
101830+ pax_open_kernel();
101831 sock_diag_handlers[family] = NULL;
101832+ pax_close_kernel();
101833 mutex_unlock(&sock_diag_table_mutex);
101834 }
101835 EXPORT_SYMBOL_GPL(sock_diag_unregister);
101836diff --git a/net/core/sysctl_net_core.c b/net/core/sysctl_net_core.c
101837index cf9cd13..50683950 100644
101838--- a/net/core/sysctl_net_core.c
101839+++ b/net/core/sysctl_net_core.c
101840@@ -32,7 +32,7 @@ static int rps_sock_flow_sysctl(struct ctl_table *table, int write,
101841 {
101842 unsigned int orig_size, size;
101843 int ret, i;
101844- struct ctl_table tmp = {
101845+ ctl_table_no_const tmp = {
101846 .data = &size,
101847 .maxlen = sizeof(size),
101848 .mode = table->mode
101849@@ -200,7 +200,7 @@ static int set_default_qdisc(struct ctl_table *table, int write,
101850 void __user *buffer, size_t *lenp, loff_t *ppos)
101851 {
101852 char id[IFNAMSIZ];
101853- struct ctl_table tbl = {
101854+ ctl_table_no_const tbl = {
101855 .data = id,
101856 .maxlen = IFNAMSIZ,
101857 };
101858@@ -263,7 +263,7 @@ static struct ctl_table net_core_table[] = {
101859 .mode = 0644,
101860 .proc_handler = proc_dointvec
101861 },
101862-#ifdef CONFIG_BPF_JIT
101863+#if defined(CONFIG_BPF_JIT) && !defined(CONFIG_GRKERNSEC_BPF_HARDEN)
101864 {
101865 .procname = "bpf_jit_enable",
101866 .data = &bpf_jit_enable,
101867@@ -379,13 +379,12 @@ static struct ctl_table netns_core_table[] = {
101868
101869 static __net_init int sysctl_core_net_init(struct net *net)
101870 {
101871- struct ctl_table *tbl;
101872+ ctl_table_no_const *tbl = NULL;
101873
101874 net->core.sysctl_somaxconn = SOMAXCONN;
101875
101876- tbl = netns_core_table;
101877 if (!net_eq(net, &init_net)) {
101878- tbl = kmemdup(tbl, sizeof(netns_core_table), GFP_KERNEL);
101879+ tbl = kmemdup(netns_core_table, sizeof(netns_core_table), GFP_KERNEL);
101880 if (tbl == NULL)
101881 goto err_dup;
101882
101883@@ -395,17 +394,16 @@ static __net_init int sysctl_core_net_init(struct net *net)
101884 if (net->user_ns != &init_user_ns) {
101885 tbl[0].procname = NULL;
101886 }
101887- }
101888-
101889- net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
101890+ net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
101891+ } else
101892+ net->core.sysctl_hdr = register_net_sysctl(net, "net/core", netns_core_table);
101893 if (net->core.sysctl_hdr == NULL)
101894 goto err_reg;
101895
101896 return 0;
101897
101898 err_reg:
101899- if (tbl != netns_core_table)
101900- kfree(tbl);
101901+ kfree(tbl);
101902 err_dup:
101903 return -ENOMEM;
101904 }
101905@@ -420,7 +418,7 @@ static __net_exit void sysctl_core_net_exit(struct net *net)
101906 kfree(tbl);
101907 }
101908
101909-static __net_initdata struct pernet_operations sysctl_core_ops = {
101910+static __net_initconst struct pernet_operations sysctl_core_ops = {
101911 .init = sysctl_core_net_init,
101912 .exit = sysctl_core_net_exit,
101913 };
101914diff --git a/net/decnet/af_decnet.c b/net/decnet/af_decnet.c
101915index 25733d5..b9360f0 100644
101916--- a/net/decnet/af_decnet.c
101917+++ b/net/decnet/af_decnet.c
101918@@ -466,6 +466,7 @@ static struct proto dn_proto = {
101919 .sysctl_rmem = sysctl_decnet_rmem,
101920 .max_header = DN_MAX_NSP_DATA_HEADER + 64,
101921 .obj_size = sizeof(struct dn_sock),
101922+ .slab_flags = SLAB_USERCOPY,
101923 };
101924
101925 static struct sock *dn_alloc_sock(struct net *net, struct socket *sock, gfp_t gfp)
101926diff --git a/net/decnet/dn_dev.c b/net/decnet/dn_dev.c
101927index 4400da7..3429972 100644
101928--- a/net/decnet/dn_dev.c
101929+++ b/net/decnet/dn_dev.c
101930@@ -201,7 +201,7 @@ static struct dn_dev_sysctl_table {
101931 .extra1 = &min_t3,
101932 .extra2 = &max_t3
101933 },
101934- {0}
101935+ { }
101936 },
101937 };
101938
101939diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
101940index 5325b54..a0d4d69 100644
101941--- a/net/decnet/sysctl_net_decnet.c
101942+++ b/net/decnet/sysctl_net_decnet.c
101943@@ -174,7 +174,7 @@ static int dn_node_address_handler(struct ctl_table *table, int write,
101944
101945 if (len > *lenp) len = *lenp;
101946
101947- if (copy_to_user(buffer, addr, len))
101948+ if (len > sizeof addr || copy_to_user(buffer, addr, len))
101949 return -EFAULT;
101950
101951 *lenp = len;
101952@@ -237,7 +237,7 @@ static int dn_def_dev_handler(struct ctl_table *table, int write,
101953
101954 if (len > *lenp) len = *lenp;
101955
101956- if (copy_to_user(buffer, devname, len))
101957+ if (len > sizeof devname || copy_to_user(buffer, devname, len))
101958 return -EFAULT;
101959
101960 *lenp = len;
101961diff --git a/net/hsr/hsr_netlink.c b/net/hsr/hsr_netlink.c
101962index a2c7e4c..3dc9f67 100644
101963--- a/net/hsr/hsr_netlink.c
101964+++ b/net/hsr/hsr_netlink.c
101965@@ -102,7 +102,7 @@ nla_put_failure:
101966 return -EMSGSIZE;
101967 }
101968
101969-static struct rtnl_link_ops hsr_link_ops __read_mostly = {
101970+static struct rtnl_link_ops hsr_link_ops = {
101971 .kind = "hsr",
101972 .maxtype = IFLA_HSR_MAX,
101973 .policy = hsr_policy,
101974diff --git a/net/ieee802154/6lowpan_rtnl.c b/net/ieee802154/6lowpan_rtnl.c
101975index 4413629..dea596a 100644
101976--- a/net/ieee802154/6lowpan_rtnl.c
101977+++ b/net/ieee802154/6lowpan_rtnl.c
101978@@ -635,7 +635,7 @@ static void lowpan_dellink(struct net_device *dev, struct list_head *head)
101979 dev_put(real_dev);
101980 }
101981
101982-static struct rtnl_link_ops lowpan_link_ops __read_mostly = {
101983+static struct rtnl_link_ops lowpan_link_ops = {
101984 .kind = "lowpan",
101985 .priv_size = sizeof(struct lowpan_dev_info),
101986 .setup = lowpan_setup,
101987diff --git a/net/ieee802154/reassembly.c b/net/ieee802154/reassembly.c
101988index 7cfcd68..84ca5b7 100644
101989--- a/net/ieee802154/reassembly.c
101990+++ b/net/ieee802154/reassembly.c
101991@@ -433,14 +433,13 @@ static struct ctl_table lowpan_frags_ctl_table[] = {
101992
101993 static int __net_init lowpan_frags_ns_sysctl_register(struct net *net)
101994 {
101995- struct ctl_table *table;
101996+ ctl_table_no_const *table = NULL;
101997 struct ctl_table_header *hdr;
101998 struct netns_ieee802154_lowpan *ieee802154_lowpan =
101999 net_ieee802154_lowpan(net);
102000
102001- table = lowpan_frags_ns_ctl_table;
102002 if (!net_eq(net, &init_net)) {
102003- table = kmemdup(table, sizeof(lowpan_frags_ns_ctl_table),
102004+ table = kmemdup(lowpan_frags_ns_ctl_table, sizeof(lowpan_frags_ns_ctl_table),
102005 GFP_KERNEL);
102006 if (table == NULL)
102007 goto err_alloc;
102008@@ -455,9 +454,9 @@ static int __net_init lowpan_frags_ns_sysctl_register(struct net *net)
102009 /* Don't export sysctls to unprivileged users */
102010 if (net->user_ns != &init_user_ns)
102011 table[0].procname = NULL;
102012- }
102013-
102014- hdr = register_net_sysctl(net, "net/ieee802154/6lowpan", table);
102015+ hdr = register_net_sysctl(net, "net/ieee802154/6lowpan", table);
102016+ } else
102017+ hdr = register_net_sysctl(net, "net/ieee802154/6lowpan", lowpan_frags_ns_ctl_table);
102018 if (hdr == NULL)
102019 goto err_reg;
102020
102021@@ -465,8 +464,7 @@ static int __net_init lowpan_frags_ns_sysctl_register(struct net *net)
102022 return 0;
102023
102024 err_reg:
102025- if (!net_eq(net, &init_net))
102026- kfree(table);
102027+ kfree(table);
102028 err_alloc:
102029 return -ENOMEM;
102030 }
102031diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c
102032index e67da4e..da217942 100644
102033--- a/net/ipv4/af_inet.c
102034+++ b/net/ipv4/af_inet.c
102035@@ -1392,7 +1392,7 @@ int inet_recv_error(struct sock *sk, struct msghdr *msg, int len, int *addr_len)
102036 return ip_recv_error(sk, msg, len, addr_len);
102037 #if IS_ENABLED(CONFIG_IPV6)
102038 if (sk->sk_family == AF_INET6)
102039- return pingv6_ops.ipv6_recv_error(sk, msg, len, addr_len);
102040+ return pingv6_ops->ipv6_recv_error(sk, msg, len, addr_len);
102041 #endif
102042 return -EINVAL;
102043 }
102044diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
102045index 214882e..ec032f6 100644
102046--- a/net/ipv4/devinet.c
102047+++ b/net/ipv4/devinet.c
102048@@ -69,7 +69,8 @@
102049
102050 static struct ipv4_devconf ipv4_devconf = {
102051 .data = {
102052- [IPV4_DEVCONF_ACCEPT_REDIRECTS - 1] = 1,
102053+ [IPV4_DEVCONF_ACCEPT_REDIRECTS - 1] = 0,
102054+ [IPV4_DEVCONF_RP_FILTER - 1] = 1,
102055 [IPV4_DEVCONF_SEND_REDIRECTS - 1] = 1,
102056 [IPV4_DEVCONF_SECURE_REDIRECTS - 1] = 1,
102057 [IPV4_DEVCONF_SHARED_MEDIA - 1] = 1,
102058@@ -80,7 +81,8 @@ static struct ipv4_devconf ipv4_devconf = {
102059
102060 static struct ipv4_devconf ipv4_devconf_dflt = {
102061 .data = {
102062- [IPV4_DEVCONF_ACCEPT_REDIRECTS - 1] = 1,
102063+ [IPV4_DEVCONF_ACCEPT_REDIRECTS - 1] = 0,
102064+ [IPV4_DEVCONF_RP_FILTER - 1] = 1,
102065 [IPV4_DEVCONF_SEND_REDIRECTS - 1] = 1,
102066 [IPV4_DEVCONF_SECURE_REDIRECTS - 1] = 1,
102067 [IPV4_DEVCONF_SHARED_MEDIA - 1] = 1,
102068@@ -1548,7 +1550,7 @@ static int inet_dump_ifaddr(struct sk_buff *skb, struct netlink_callback *cb)
102069 idx = 0;
102070 head = &net->dev_index_head[h];
102071 rcu_read_lock();
102072- cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
102073+ cb->seq = atomic_read_unchecked(&net->ipv4.dev_addr_genid) ^
102074 net->dev_base_seq;
102075 hlist_for_each_entry_rcu(dev, head, index_hlist) {
102076 if (idx < s_idx)
102077@@ -1866,7 +1868,7 @@ static int inet_netconf_dump_devconf(struct sk_buff *skb,
102078 idx = 0;
102079 head = &net->dev_index_head[h];
102080 rcu_read_lock();
102081- cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
102082+ cb->seq = atomic_read_unchecked(&net->ipv4.dev_addr_genid) ^
102083 net->dev_base_seq;
102084 hlist_for_each_entry_rcu(dev, head, index_hlist) {
102085 if (idx < s_idx)
102086@@ -2101,7 +2103,7 @@ static int ipv4_doint_and_flush(struct ctl_table *ctl, int write,
102087 #define DEVINET_SYSCTL_FLUSHING_ENTRY(attr, name) \
102088 DEVINET_SYSCTL_COMPLEX_ENTRY(attr, name, ipv4_doint_and_flush)
102089
102090-static struct devinet_sysctl_table {
102091+static const struct devinet_sysctl_table {
102092 struct ctl_table_header *sysctl_header;
102093 struct ctl_table devinet_vars[__IPV4_DEVCONF_MAX];
102094 } devinet_sysctl = {
102095@@ -2233,7 +2235,7 @@ static __net_init int devinet_init_net(struct net *net)
102096 int err;
102097 struct ipv4_devconf *all, *dflt;
102098 #ifdef CONFIG_SYSCTL
102099- struct ctl_table *tbl = ctl_forward_entry;
102100+ ctl_table_no_const *tbl = NULL;
102101 struct ctl_table_header *forw_hdr;
102102 #endif
102103
102104@@ -2251,7 +2253,7 @@ static __net_init int devinet_init_net(struct net *net)
102105 goto err_alloc_dflt;
102106
102107 #ifdef CONFIG_SYSCTL
102108- tbl = kmemdup(tbl, sizeof(ctl_forward_entry), GFP_KERNEL);
102109+ tbl = kmemdup(ctl_forward_entry, sizeof(ctl_forward_entry), GFP_KERNEL);
102110 if (tbl == NULL)
102111 goto err_alloc_ctl;
102112
102113@@ -2271,7 +2273,10 @@ static __net_init int devinet_init_net(struct net *net)
102114 goto err_reg_dflt;
102115
102116 err = -ENOMEM;
102117- forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
102118+ if (!net_eq(net, &init_net))
102119+ forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
102120+ else
102121+ forw_hdr = register_net_sysctl(net, "net/ipv4", ctl_forward_entry);
102122 if (forw_hdr == NULL)
102123 goto err_reg_ctl;
102124 net->ipv4.forw_hdr = forw_hdr;
102125@@ -2287,8 +2292,7 @@ err_reg_ctl:
102126 err_reg_dflt:
102127 __devinet_sysctl_unregister(all);
102128 err_reg_all:
102129- if (tbl != ctl_forward_entry)
102130- kfree(tbl);
102131+ kfree(tbl);
102132 err_alloc_ctl:
102133 #endif
102134 if (dflt != &ipv4_devconf_dflt)
102135diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
102136index 23104a3..9f5570b 100644
102137--- a/net/ipv4/fib_frontend.c
102138+++ b/net/ipv4/fib_frontend.c
102139@@ -1017,12 +1017,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
102140 #ifdef CONFIG_IP_ROUTE_MULTIPATH
102141 fib_sync_up(dev);
102142 #endif
102143- atomic_inc(&net->ipv4.dev_addr_genid);
102144+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
102145 rt_cache_flush(dev_net(dev));
102146 break;
102147 case NETDEV_DOWN:
102148 fib_del_ifaddr(ifa, NULL);
102149- atomic_inc(&net->ipv4.dev_addr_genid);
102150+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
102151 if (ifa->ifa_dev->ifa_list == NULL) {
102152 /* Last address was deleted from this interface.
102153 * Disable IP.
102154@@ -1060,7 +1060,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
102155 #ifdef CONFIG_IP_ROUTE_MULTIPATH
102156 fib_sync_up(dev);
102157 #endif
102158- atomic_inc(&net->ipv4.dev_addr_genid);
102159+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
102160 rt_cache_flush(net);
102161 break;
102162 case NETDEV_DOWN:
102163diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
102164index f99f41b..1879da9 100644
102165--- a/net/ipv4/fib_semantics.c
102166+++ b/net/ipv4/fib_semantics.c
102167@@ -770,7 +770,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
102168 nh->nh_saddr = inet_select_addr(nh->nh_dev,
102169 nh->nh_gw,
102170 nh->nh_parent->fib_scope);
102171- nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
102172+ nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
102173
102174 return nh->nh_saddr;
102175 }
102176diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
102177index 9111a4e..3576905 100644
102178--- a/net/ipv4/inet_hashtables.c
102179+++ b/net/ipv4/inet_hashtables.c
102180@@ -18,6 +18,7 @@
102181 #include <linux/sched.h>
102182 #include <linux/slab.h>
102183 #include <linux/wait.h>
102184+#include <linux/security.h>
102185
102186 #include <net/inet_connection_sock.h>
102187 #include <net/inet_hashtables.h>
102188@@ -49,6 +50,8 @@ static unsigned int inet_sk_ehashfn(const struct sock *sk)
102189 return inet_ehashfn(net, laddr, lport, faddr, fport);
102190 }
102191
102192+extern void gr_update_task_in_ip_table(const struct inet_sock *inet);
102193+
102194 /*
102195 * Allocate and initialize a new local port bind bucket.
102196 * The bindhash mutex for snum's hash chain must be held here.
102197@@ -554,6 +557,8 @@ ok:
102198 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
102199 spin_unlock(&head->lock);
102200
102201+ gr_update_task_in_ip_table(inet_sk(sk));
102202+
102203 if (tw) {
102204 inet_twsk_deschedule(tw, death_row);
102205 while (twrefcnt) {
102206diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
102207index 241afd7..31b95d5 100644
102208--- a/net/ipv4/inetpeer.c
102209+++ b/net/ipv4/inetpeer.c
102210@@ -461,7 +461,7 @@ relookup:
102211 if (p) {
102212 p->daddr = *daddr;
102213 atomic_set(&p->refcnt, 1);
102214- atomic_set(&p->rid, 0);
102215+ atomic_set_unchecked(&p->rid, 0);
102216 p->metrics[RTAX_LOCK-1] = INETPEER_METRICS_NEW;
102217 p->rate_tokens = 0;
102218 /* 60*HZ is arbitrary, but chosen enough high so that the first
102219diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
102220index 2811cc1..ad5a534 100644
102221--- a/net/ipv4/ip_fragment.c
102222+++ b/net/ipv4/ip_fragment.c
102223@@ -268,7 +268,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
102224 return 0;
102225
102226 start = qp->rid;
102227- end = atomic_inc_return(&peer->rid);
102228+ end = atomic_inc_return_unchecked(&peer->rid);
102229 qp->rid = end;
102230
102231 rc = qp->q.fragments && (end - start) > max;
102232@@ -746,12 +746,11 @@ static struct ctl_table ip4_frags_ctl_table[] = {
102233
102234 static int __net_init ip4_frags_ns_ctl_register(struct net *net)
102235 {
102236- struct ctl_table *table;
102237+ ctl_table_no_const *table = NULL;
102238 struct ctl_table_header *hdr;
102239
102240- table = ip4_frags_ns_ctl_table;
102241 if (!net_eq(net, &init_net)) {
102242- table = kmemdup(table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
102243+ table = kmemdup(ip4_frags_ns_ctl_table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
102244 if (table == NULL)
102245 goto err_alloc;
102246
102247@@ -765,9 +764,10 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
102248 /* Don't export sysctls to unprivileged users */
102249 if (net->user_ns != &init_user_ns)
102250 table[0].procname = NULL;
102251- }
102252+ hdr = register_net_sysctl(net, "net/ipv4", table);
102253+ } else
102254+ hdr = register_net_sysctl(net, "net/ipv4", ip4_frags_ns_ctl_table);
102255
102256- hdr = register_net_sysctl(net, "net/ipv4", table);
102257 if (hdr == NULL)
102258 goto err_reg;
102259
102260@@ -775,8 +775,7 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
102261 return 0;
102262
102263 err_reg:
102264- if (!net_eq(net, &init_net))
102265- kfree(table);
102266+ kfree(table);
102267 err_alloc:
102268 return -ENOMEM;
102269 }
102270diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c
102271index 12055fd..df852c4 100644
102272--- a/net/ipv4/ip_gre.c
102273+++ b/net/ipv4/ip_gre.c
102274@@ -115,7 +115,7 @@ static bool log_ecn_error = true;
102275 module_param(log_ecn_error, bool, 0644);
102276 MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
102277
102278-static struct rtnl_link_ops ipgre_link_ops __read_mostly;
102279+static struct rtnl_link_ops ipgre_link_ops;
102280 static int ipgre_tunnel_init(struct net_device *dev);
102281
102282 static int ipgre_net_id __read_mostly;
102283@@ -815,7 +815,7 @@ static const struct nla_policy ipgre_policy[IFLA_GRE_MAX + 1] = {
102284 [IFLA_GRE_ENCAP_DPORT] = { .type = NLA_U16 },
102285 };
102286
102287-static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
102288+static struct rtnl_link_ops ipgre_link_ops = {
102289 .kind = "gre",
102290 .maxtype = IFLA_GRE_MAX,
102291 .policy = ipgre_policy,
102292@@ -829,7 +829,7 @@ static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
102293 .fill_info = ipgre_fill_info,
102294 };
102295
102296-static struct rtnl_link_ops ipgre_tap_ops __read_mostly = {
102297+static struct rtnl_link_ops ipgre_tap_ops = {
102298 .kind = "gretap",
102299 .maxtype = IFLA_GRE_MAX,
102300 .policy = ipgre_policy,
102301diff --git a/net/ipv4/ip_input.c b/net/ipv4/ip_input.c
102302index 3d4da2c..40f9c29 100644
102303--- a/net/ipv4/ip_input.c
102304+++ b/net/ipv4/ip_input.c
102305@@ -147,6 +147,10 @@
102306 #include <linux/mroute.h>
102307 #include <linux/netlink.h>
102308
102309+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
102310+extern int grsec_enable_blackhole;
102311+#endif
102312+
102313 /*
102314 * Process Router Attention IP option (RFC 2113)
102315 */
102316@@ -223,6 +227,9 @@ static int ip_local_deliver_finish(struct sk_buff *skb)
102317 if (!raw) {
102318 if (xfrm4_policy_check(NULL, XFRM_POLICY_IN, skb)) {
102319 IP_INC_STATS_BH(net, IPSTATS_MIB_INUNKNOWNPROTOS);
102320+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
102321+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
102322+#endif
102323 icmp_send(skb, ICMP_DEST_UNREACH,
102324 ICMP_PROT_UNREACH, 0);
102325 }
102326diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
102327index 9daf217..dc6972d 100644
102328--- a/net/ipv4/ip_sockglue.c
102329+++ b/net/ipv4/ip_sockglue.c
102330@@ -1177,7 +1177,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
102331 len = min_t(unsigned int, len, opt->optlen);
102332 if (put_user(len, optlen))
102333 return -EFAULT;
102334- if (copy_to_user(optval, opt->__data, len))
102335+ if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
102336+ copy_to_user(optval, opt->__data, len))
102337 return -EFAULT;
102338 return 0;
102339 }
102340@@ -1308,7 +1309,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
102341 if (sk->sk_type != SOCK_STREAM)
102342 return -ENOPROTOOPT;
102343
102344- msg.msg_control = (__force void *) optval;
102345+ msg.msg_control = (__force_kernel void *) optval;
102346 msg.msg_controllen = len;
102347 msg.msg_flags = flags;
102348
102349diff --git a/net/ipv4/ip_vti.c b/net/ipv4/ip_vti.c
102350index 1a7e979..fd05aa4 100644
102351--- a/net/ipv4/ip_vti.c
102352+++ b/net/ipv4/ip_vti.c
102353@@ -45,7 +45,7 @@
102354 #include <net/net_namespace.h>
102355 #include <net/netns/generic.h>
102356
102357-static struct rtnl_link_ops vti_link_ops __read_mostly;
102358+static struct rtnl_link_ops vti_link_ops;
102359
102360 static int vti_net_id __read_mostly;
102361 static int vti_tunnel_init(struct net_device *dev);
102362@@ -519,7 +519,7 @@ static const struct nla_policy vti_policy[IFLA_VTI_MAX + 1] = {
102363 [IFLA_VTI_REMOTE] = { .len = FIELD_SIZEOF(struct iphdr, daddr) },
102364 };
102365
102366-static struct rtnl_link_ops vti_link_ops __read_mostly = {
102367+static struct rtnl_link_ops vti_link_ops = {
102368 .kind = "vti",
102369 .maxtype = IFLA_VTI_MAX,
102370 .policy = vti_policy,
102371diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
102372index 648fa14..97864d0 100644
102373--- a/net/ipv4/ipconfig.c
102374+++ b/net/ipv4/ipconfig.c
102375@@ -333,7 +333,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
102376
102377 mm_segment_t oldfs = get_fs();
102378 set_fs(get_ds());
102379- res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
102380+ res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
102381 set_fs(oldfs);
102382 return res;
102383 }
102384@@ -344,7 +344,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
102385
102386 mm_segment_t oldfs = get_fs();
102387 set_fs(get_ds());
102388- res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
102389+ res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
102390 set_fs(oldfs);
102391 return res;
102392 }
102393@@ -355,7 +355,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
102394
102395 mm_segment_t oldfs = get_fs();
102396 set_fs(get_ds());
102397- res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
102398+ res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
102399 set_fs(oldfs);
102400 return res;
102401 }
102402diff --git a/net/ipv4/ipip.c b/net/ipv4/ipip.c
102403index 37096d6..86abb03 100644
102404--- a/net/ipv4/ipip.c
102405+++ b/net/ipv4/ipip.c
102406@@ -124,7 +124,7 @@ MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
102407 static int ipip_net_id __read_mostly;
102408
102409 static int ipip_tunnel_init(struct net_device *dev);
102410-static struct rtnl_link_ops ipip_link_ops __read_mostly;
102411+static struct rtnl_link_ops ipip_link_ops;
102412
102413 static int ipip_err(struct sk_buff *skb, u32 info)
102414 {
102415@@ -487,7 +487,7 @@ static const struct nla_policy ipip_policy[IFLA_IPTUN_MAX + 1] = {
102416 [IFLA_IPTUN_ENCAP_DPORT] = { .type = NLA_U16 },
102417 };
102418
102419-static struct rtnl_link_ops ipip_link_ops __read_mostly = {
102420+static struct rtnl_link_ops ipip_link_ops = {
102421 .kind = "ipip",
102422 .maxtype = IFLA_IPTUN_MAX,
102423 .policy = ipip_policy,
102424diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
102425index f95b6f9..2ee2097 100644
102426--- a/net/ipv4/netfilter/arp_tables.c
102427+++ b/net/ipv4/netfilter/arp_tables.c
102428@@ -885,14 +885,14 @@ static int compat_table_info(const struct xt_table_info *info,
102429 #endif
102430
102431 static int get_info(struct net *net, void __user *user,
102432- const int *len, int compat)
102433+ int len, int compat)
102434 {
102435 char name[XT_TABLE_MAXNAMELEN];
102436 struct xt_table *t;
102437 int ret;
102438
102439- if (*len != sizeof(struct arpt_getinfo)) {
102440- duprintf("length %u != %Zu\n", *len,
102441+ if (len != sizeof(struct arpt_getinfo)) {
102442+ duprintf("length %u != %Zu\n", len,
102443 sizeof(struct arpt_getinfo));
102444 return -EINVAL;
102445 }
102446@@ -929,7 +929,7 @@ static int get_info(struct net *net, void __user *user,
102447 info.size = private->size;
102448 strcpy(info.name, name);
102449
102450- if (copy_to_user(user, &info, *len) != 0)
102451+ if (copy_to_user(user, &info, len) != 0)
102452 ret = -EFAULT;
102453 else
102454 ret = 0;
102455@@ -1690,7 +1690,7 @@ static int compat_do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user,
102456
102457 switch (cmd) {
102458 case ARPT_SO_GET_INFO:
102459- ret = get_info(sock_net(sk), user, len, 1);
102460+ ret = get_info(sock_net(sk), user, *len, 1);
102461 break;
102462 case ARPT_SO_GET_ENTRIES:
102463 ret = compat_get_entries(sock_net(sk), user, len);
102464@@ -1735,7 +1735,7 @@ static int do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len
102465
102466 switch (cmd) {
102467 case ARPT_SO_GET_INFO:
102468- ret = get_info(sock_net(sk), user, len, 0);
102469+ ret = get_info(sock_net(sk), user, *len, 0);
102470 break;
102471
102472 case ARPT_SO_GET_ENTRIES:
102473diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
102474index 99e810f..3711b81 100644
102475--- a/net/ipv4/netfilter/ip_tables.c
102476+++ b/net/ipv4/netfilter/ip_tables.c
102477@@ -1073,14 +1073,14 @@ static int compat_table_info(const struct xt_table_info *info,
102478 #endif
102479
102480 static int get_info(struct net *net, void __user *user,
102481- const int *len, int compat)
102482+ int len, int compat)
102483 {
102484 char name[XT_TABLE_MAXNAMELEN];
102485 struct xt_table *t;
102486 int ret;
102487
102488- if (*len != sizeof(struct ipt_getinfo)) {
102489- duprintf("length %u != %zu\n", *len,
102490+ if (len != sizeof(struct ipt_getinfo)) {
102491+ duprintf("length %u != %zu\n", len,
102492 sizeof(struct ipt_getinfo));
102493 return -EINVAL;
102494 }
102495@@ -1117,7 +1117,7 @@ static int get_info(struct net *net, void __user *user,
102496 info.size = private->size;
102497 strcpy(info.name, name);
102498
102499- if (copy_to_user(user, &info, *len) != 0)
102500+ if (copy_to_user(user, &info, len) != 0)
102501 ret = -EFAULT;
102502 else
102503 ret = 0;
102504@@ -1973,7 +1973,7 @@ compat_do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
102505
102506 switch (cmd) {
102507 case IPT_SO_GET_INFO:
102508- ret = get_info(sock_net(sk), user, len, 1);
102509+ ret = get_info(sock_net(sk), user, *len, 1);
102510 break;
102511 case IPT_SO_GET_ENTRIES:
102512 ret = compat_get_entries(sock_net(sk), user, len);
102513@@ -2020,7 +2020,7 @@ do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
102514
102515 switch (cmd) {
102516 case IPT_SO_GET_INFO:
102517- ret = get_info(sock_net(sk), user, len, 0);
102518+ ret = get_info(sock_net(sk), user, *len, 0);
102519 break;
102520
102521 case IPT_SO_GET_ENTRIES:
102522diff --git a/net/ipv4/netfilter/ipt_CLUSTERIP.c b/net/ipv4/netfilter/ipt_CLUSTERIP.c
102523index e90f83a..3e6acca 100644
102524--- a/net/ipv4/netfilter/ipt_CLUSTERIP.c
102525+++ b/net/ipv4/netfilter/ipt_CLUSTERIP.c
102526@@ -720,7 +720,7 @@ static int clusterip_net_init(struct net *net)
102527 spin_lock_init(&cn->lock);
102528
102529 #ifdef CONFIG_PROC_FS
102530- cn->procdir = proc_mkdir("ipt_CLUSTERIP", net->proc_net);
102531+ cn->procdir = proc_mkdir_restrict("ipt_CLUSTERIP", net->proc_net);
102532 if (!cn->procdir) {
102533 pr_err("Unable to proc dir entry\n");
102534 return -ENOMEM;
102535diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
102536index 5d740cc..b2842b9 100644
102537--- a/net/ipv4/ping.c
102538+++ b/net/ipv4/ping.c
102539@@ -59,7 +59,7 @@ struct ping_table {
102540 };
102541
102542 static struct ping_table ping_table;
102543-struct pingv6_ops pingv6_ops;
102544+struct pingv6_ops *pingv6_ops;
102545 EXPORT_SYMBOL_GPL(pingv6_ops);
102546
102547 static u16 ping_port_rover;
102548@@ -350,7 +350,7 @@ static int ping_check_bind_addr(struct sock *sk, struct inet_sock *isk,
102549 return -ENODEV;
102550 }
102551 }
102552- has_addr = pingv6_ops.ipv6_chk_addr(net, &addr->sin6_addr, dev,
102553+ has_addr = pingv6_ops->ipv6_chk_addr(net, &addr->sin6_addr, dev,
102554 scoped);
102555 rcu_read_unlock();
102556
102557@@ -558,7 +558,7 @@ void ping_err(struct sk_buff *skb, int offset, u32 info)
102558 }
102559 #if IS_ENABLED(CONFIG_IPV6)
102560 } else if (skb->protocol == htons(ETH_P_IPV6)) {
102561- harderr = pingv6_ops.icmpv6_err_convert(type, code, &err);
102562+ harderr = pingv6_ops->icmpv6_err_convert(type, code, &err);
102563 #endif
102564 }
102565
102566@@ -576,7 +576,7 @@ void ping_err(struct sk_buff *skb, int offset, u32 info)
102567 info, (u8 *)icmph);
102568 #if IS_ENABLED(CONFIG_IPV6)
102569 } else if (family == AF_INET6) {
102570- pingv6_ops.ipv6_icmp_error(sk, skb, err, 0,
102571+ pingv6_ops->ipv6_icmp_error(sk, skb, err, 0,
102572 info, (u8 *)icmph);
102573 #endif
102574 }
102575@@ -910,10 +910,10 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
102576 }
102577
102578 if (inet6_sk(sk)->rxopt.all)
102579- pingv6_ops.ip6_datagram_recv_common_ctl(sk, msg, skb);
102580+ pingv6_ops->ip6_datagram_recv_common_ctl(sk, msg, skb);
102581 if (skb->protocol == htons(ETH_P_IPV6) &&
102582 inet6_sk(sk)->rxopt.all)
102583- pingv6_ops.ip6_datagram_recv_specific_ctl(sk, msg, skb);
102584+ pingv6_ops->ip6_datagram_recv_specific_ctl(sk, msg, skb);
102585 else if (skb->protocol == htons(ETH_P_IP) && isk->cmsg_flags)
102586 ip_cmsg_recv(msg, skb);
102587 #endif
102588@@ -1105,7 +1105,7 @@ static void ping_v4_format_sock(struct sock *sp, struct seq_file *f,
102589 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
102590 0, sock_i_ino(sp),
102591 atomic_read(&sp->sk_refcnt), sp,
102592- atomic_read(&sp->sk_drops));
102593+ atomic_read_unchecked(&sp->sk_drops));
102594 }
102595
102596 static int ping_v4_seq_show(struct seq_file *seq, void *v)
102597diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
102598index 739db31..74f0210 100644
102599--- a/net/ipv4/raw.c
102600+++ b/net/ipv4/raw.c
102601@@ -314,7 +314,7 @@ static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
102602 int raw_rcv(struct sock *sk, struct sk_buff *skb)
102603 {
102604 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
102605- atomic_inc(&sk->sk_drops);
102606+ atomic_inc_unchecked(&sk->sk_drops);
102607 kfree_skb(skb);
102608 return NET_RX_DROP;
102609 }
102610@@ -755,16 +755,20 @@ static int raw_init(struct sock *sk)
102611
102612 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
102613 {
102614+ struct icmp_filter filter;
102615+
102616 if (optlen > sizeof(struct icmp_filter))
102617 optlen = sizeof(struct icmp_filter);
102618- if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
102619+ if (copy_from_user(&filter, optval, optlen))
102620 return -EFAULT;
102621+ raw_sk(sk)->filter = filter;
102622 return 0;
102623 }
102624
102625 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
102626 {
102627 int len, ret = -EFAULT;
102628+ struct icmp_filter filter;
102629
102630 if (get_user(len, optlen))
102631 goto out;
102632@@ -774,8 +778,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
102633 if (len > sizeof(struct icmp_filter))
102634 len = sizeof(struct icmp_filter);
102635 ret = -EFAULT;
102636- if (put_user(len, optlen) ||
102637- copy_to_user(optval, &raw_sk(sk)->filter, len))
102638+ filter = raw_sk(sk)->filter;
102639+ if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
102640 goto out;
102641 ret = 0;
102642 out: return ret;
102643@@ -1004,7 +1008,7 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
102644 0, 0L, 0,
102645 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
102646 0, sock_i_ino(sp),
102647- atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
102648+ atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
102649 }
102650
102651 static int raw_seq_show(struct seq_file *seq, void *v)
102652diff --git a/net/ipv4/route.c b/net/ipv4/route.c
102653index 6a2155b..d426880 100644
102654--- a/net/ipv4/route.c
102655+++ b/net/ipv4/route.c
102656@@ -228,7 +228,7 @@ static const struct seq_operations rt_cache_seq_ops = {
102657
102658 static int rt_cache_seq_open(struct inode *inode, struct file *file)
102659 {
102660- return seq_open(file, &rt_cache_seq_ops);
102661+ return seq_open_restrict(file, &rt_cache_seq_ops);
102662 }
102663
102664 static const struct file_operations rt_cache_seq_fops = {
102665@@ -319,7 +319,7 @@ static const struct seq_operations rt_cpu_seq_ops = {
102666
102667 static int rt_cpu_seq_open(struct inode *inode, struct file *file)
102668 {
102669- return seq_open(file, &rt_cpu_seq_ops);
102670+ return seq_open_restrict(file, &rt_cpu_seq_ops);
102671 }
102672
102673 static const struct file_operations rt_cpu_seq_fops = {
102674@@ -357,7 +357,7 @@ static int rt_acct_proc_show(struct seq_file *m, void *v)
102675
102676 static int rt_acct_proc_open(struct inode *inode, struct file *file)
102677 {
102678- return single_open(file, rt_acct_proc_show, NULL);
102679+ return single_open_restrict(file, rt_acct_proc_show, NULL);
102680 }
102681
102682 static const struct file_operations rt_acct_proc_fops = {
102683@@ -459,11 +459,11 @@ static struct neighbour *ipv4_neigh_lookup(const struct dst_entry *dst,
102684
102685 #define IP_IDENTS_SZ 2048u
102686 struct ip_ident_bucket {
102687- atomic_t id;
102688+ atomic_unchecked_t id;
102689 u32 stamp32;
102690 };
102691
102692-static struct ip_ident_bucket *ip_idents __read_mostly;
102693+static struct ip_ident_bucket ip_idents[IP_IDENTS_SZ] __read_mostly;
102694
102695 /* In order to protect privacy, we add a perturbation to identifiers
102696 * if one generator is seldom used. This makes hard for an attacker
102697@@ -479,7 +479,7 @@ u32 ip_idents_reserve(u32 hash, int segs)
102698 if (old != now && cmpxchg(&bucket->stamp32, old, now) == old)
102699 delta = prandom_u32_max(now - old);
102700
102701- return atomic_add_return(segs + delta, &bucket->id) - segs;
102702+ return atomic_add_return_unchecked(segs + delta, &bucket->id) - segs;
102703 }
102704 EXPORT_SYMBOL(ip_idents_reserve);
102705
102706@@ -2624,34 +2624,34 @@ static struct ctl_table ipv4_route_flush_table[] = {
102707 .maxlen = sizeof(int),
102708 .mode = 0200,
102709 .proc_handler = ipv4_sysctl_rtcache_flush,
102710+ .extra1 = &init_net,
102711 },
102712 { },
102713 };
102714
102715 static __net_init int sysctl_route_net_init(struct net *net)
102716 {
102717- struct ctl_table *tbl;
102718+ ctl_table_no_const *tbl = NULL;
102719
102720- tbl = ipv4_route_flush_table;
102721 if (!net_eq(net, &init_net)) {
102722- tbl = kmemdup(tbl, sizeof(ipv4_route_flush_table), GFP_KERNEL);
102723+ tbl = kmemdup(ipv4_route_flush_table, sizeof(ipv4_route_flush_table), GFP_KERNEL);
102724 if (tbl == NULL)
102725 goto err_dup;
102726
102727 /* Don't export sysctls to unprivileged users */
102728 if (net->user_ns != &init_user_ns)
102729 tbl[0].procname = NULL;
102730- }
102731- tbl[0].extra1 = net;
102732+ tbl[0].extra1 = net;
102733+ net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
102734+ } else
102735+ net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", ipv4_route_flush_table);
102736
102737- net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
102738 if (net->ipv4.route_hdr == NULL)
102739 goto err_reg;
102740 return 0;
102741
102742 err_reg:
102743- if (tbl != ipv4_route_flush_table)
102744- kfree(tbl);
102745+ kfree(tbl);
102746 err_dup:
102747 return -ENOMEM;
102748 }
102749@@ -2674,8 +2674,8 @@ static __net_initdata struct pernet_operations sysctl_route_ops = {
102750
102751 static __net_init int rt_genid_init(struct net *net)
102752 {
102753- atomic_set(&net->ipv4.rt_genid, 0);
102754- atomic_set(&net->fnhe_genid, 0);
102755+ atomic_set_unchecked(&net->ipv4.rt_genid, 0);
102756+ atomic_set_unchecked(&net->fnhe_genid, 0);
102757 get_random_bytes(&net->ipv4.dev_addr_genid,
102758 sizeof(net->ipv4.dev_addr_genid));
102759 return 0;
102760@@ -2718,11 +2718,7 @@ int __init ip_rt_init(void)
102761 {
102762 int rc = 0;
102763
102764- ip_idents = kmalloc(IP_IDENTS_SZ * sizeof(*ip_idents), GFP_KERNEL);
102765- if (!ip_idents)
102766- panic("IP: failed to allocate ip_idents\n");
102767-
102768- prandom_bytes(ip_idents, IP_IDENTS_SZ * sizeof(*ip_idents));
102769+ prandom_bytes(ip_idents, sizeof(ip_idents));
102770
102771 #ifdef CONFIG_IP_ROUTE_CLASSID
102772 ip_rt_acct = __alloc_percpu(256 * sizeof(struct ip_rt_acct), __alignof__(struct ip_rt_acct));
102773diff --git a/net/ipv4/sysctl_net_ipv4.c b/net/ipv4/sysctl_net_ipv4.c
102774index b3c53c8..35cc18d 100644
102775--- a/net/ipv4/sysctl_net_ipv4.c
102776+++ b/net/ipv4/sysctl_net_ipv4.c
102777@@ -60,7 +60,7 @@ static int ipv4_local_port_range(struct ctl_table *table, int write,
102778 container_of(table->data, struct net, ipv4.ip_local_ports.range);
102779 int ret;
102780 int range[2];
102781- struct ctl_table tmp = {
102782+ ctl_table_no_const tmp = {
102783 .data = &range,
102784 .maxlen = sizeof(range),
102785 .mode = table->mode,
102786@@ -118,7 +118,7 @@ static int ipv4_ping_group_range(struct ctl_table *table, int write,
102787 int ret;
102788 gid_t urange[2];
102789 kgid_t low, high;
102790- struct ctl_table tmp = {
102791+ ctl_table_no_const tmp = {
102792 .data = &urange,
102793 .maxlen = sizeof(urange),
102794 .mode = table->mode,
102795@@ -149,7 +149,7 @@ static int proc_tcp_congestion_control(struct ctl_table *ctl, int write,
102796 void __user *buffer, size_t *lenp, loff_t *ppos)
102797 {
102798 char val[TCP_CA_NAME_MAX];
102799- struct ctl_table tbl = {
102800+ ctl_table_no_const tbl = {
102801 .data = val,
102802 .maxlen = TCP_CA_NAME_MAX,
102803 };
102804@@ -168,7 +168,7 @@ static int proc_tcp_available_congestion_control(struct ctl_table *ctl,
102805 void __user *buffer, size_t *lenp,
102806 loff_t *ppos)
102807 {
102808- struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX, };
102809+ ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX, };
102810 int ret;
102811
102812 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
102813@@ -185,7 +185,7 @@ static int proc_allowed_congestion_control(struct ctl_table *ctl,
102814 void __user *buffer, size_t *lenp,
102815 loff_t *ppos)
102816 {
102817- struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX };
102818+ ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX };
102819 int ret;
102820
102821 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
102822@@ -204,7 +204,7 @@ static int proc_tcp_fastopen_key(struct ctl_table *ctl, int write,
102823 void __user *buffer, size_t *lenp,
102824 loff_t *ppos)
102825 {
102826- struct ctl_table tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
102827+ ctl_table_no_const tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
102828 struct tcp_fastopen_context *ctxt;
102829 int ret;
102830 u32 user_key[4]; /* 16 bytes, matching TCP_FASTOPEN_KEY_LENGTH */
102831@@ -874,13 +874,12 @@ static struct ctl_table ipv4_net_table[] = {
102832
102833 static __net_init int ipv4_sysctl_init_net(struct net *net)
102834 {
102835- struct ctl_table *table;
102836+ ctl_table_no_const *table = NULL;
102837
102838- table = ipv4_net_table;
102839 if (!net_eq(net, &init_net)) {
102840 int i;
102841
102842- table = kmemdup(table, sizeof(ipv4_net_table), GFP_KERNEL);
102843+ table = kmemdup(ipv4_net_table, sizeof(ipv4_net_table), GFP_KERNEL);
102844 if (table == NULL)
102845 goto err_alloc;
102846
102847@@ -889,7 +888,10 @@ static __net_init int ipv4_sysctl_init_net(struct net *net)
102848 table[i].data += (void *)net - (void *)&init_net;
102849 }
102850
102851- net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
102852+ if (!net_eq(net, &init_net))
102853+ net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
102854+ else
102855+ net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", ipv4_net_table);
102856 if (net->ipv4.ipv4_hdr == NULL)
102857 goto err_reg;
102858
102859diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
102860index d107ee2..bcebf11 100644
102861--- a/net/ipv4/tcp_input.c
102862+++ b/net/ipv4/tcp_input.c
102863@@ -765,7 +765,7 @@ static void tcp_update_pacing_rate(struct sock *sk)
102864 * without any lock. We want to make sure compiler wont store
102865 * intermediate values in this location.
102866 */
102867- ACCESS_ONCE(sk->sk_pacing_rate) = min_t(u64, rate,
102868+ ACCESS_ONCE_RW(sk->sk_pacing_rate) = min_t(u64, rate,
102869 sk->sk_max_pacing_rate);
102870 }
102871
102872@@ -4527,7 +4527,7 @@ static struct sk_buff *tcp_collapse_one(struct sock *sk, struct sk_buff *skb,
102873 * simplifies code)
102874 */
102875 static void
102876-tcp_collapse(struct sock *sk, struct sk_buff_head *list,
102877+__intentional_overflow(5,6) tcp_collapse(struct sock *sk, struct sk_buff_head *list,
102878 struct sk_buff *head, struct sk_buff *tail,
102879 u32 start, u32 end)
102880 {
102881@@ -5506,6 +5506,7 @@ discard:
102882 tcp_paws_reject(&tp->rx_opt, 0))
102883 goto discard_and_undo;
102884
102885+#ifndef CONFIG_GRKERNSEC_NO_SIMULT_CONNECT
102886 if (th->syn) {
102887 /* We see SYN without ACK. It is attempt of
102888 * simultaneous connect with crossed SYNs.
102889@@ -5556,6 +5557,7 @@ discard:
102890 goto discard;
102891 #endif
102892 }
102893+#endif
102894 /* "fifth, if neither of the SYN or RST bits is set then
102895 * drop the segment and return."
102896 */
102897@@ -5602,7 +5604,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
102898 goto discard;
102899
102900 if (th->syn) {
102901- if (th->fin)
102902+ if (th->fin || th->urg || th->psh)
102903 goto discard;
102904 if (icsk->icsk_af_ops->conn_request(sk, skb) < 0)
102905 return 1;
102906diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
102907index ef7089c..a3e65fb 100644
102908--- a/net/ipv4/tcp_ipv4.c
102909+++ b/net/ipv4/tcp_ipv4.c
102910@@ -89,6 +89,10 @@ int sysctl_tcp_tw_reuse __read_mostly;
102911 int sysctl_tcp_low_latency __read_mostly;
102912 EXPORT_SYMBOL(sysctl_tcp_low_latency);
102913
102914+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
102915+extern int grsec_enable_blackhole;
102916+#endif
102917+
102918 #ifdef CONFIG_TCP_MD5SIG
102919 static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key,
102920 __be32 daddr, __be32 saddr, const struct tcphdr *th);
102921@@ -1469,6 +1473,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
102922 return 0;
102923
102924 reset:
102925+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
102926+ if (!grsec_enable_blackhole)
102927+#endif
102928 tcp_v4_send_reset(rsk, skb);
102929 discard:
102930 kfree_skb(skb);
102931@@ -1633,12 +1640,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
102932 TCP_SKB_CB(skb)->sacked = 0;
102933
102934 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
102935- if (!sk)
102936+ if (!sk) {
102937+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
102938+ ret = 1;
102939+#endif
102940 goto no_tcp_socket;
102941-
102942+ }
102943 process:
102944- if (sk->sk_state == TCP_TIME_WAIT)
102945+ if (sk->sk_state == TCP_TIME_WAIT) {
102946+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
102947+ ret = 2;
102948+#endif
102949 goto do_time_wait;
102950+ }
102951
102952 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
102953 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
102954@@ -1694,6 +1708,10 @@ csum_error:
102955 bad_packet:
102956 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
102957 } else {
102958+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
102959+ if (!grsec_enable_blackhole || (ret == 1 &&
102960+ (skb->dev->flags & IFF_LOOPBACK)))
102961+#endif
102962 tcp_v4_send_reset(NULL, skb);
102963 }
102964
102965diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
102966index 63d2680..2db9d6b 100644
102967--- a/net/ipv4/tcp_minisocks.c
102968+++ b/net/ipv4/tcp_minisocks.c
102969@@ -27,6 +27,10 @@
102970 #include <net/inet_common.h>
102971 #include <net/xfrm.h>
102972
102973+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
102974+extern int grsec_enable_blackhole;
102975+#endif
102976+
102977 int sysctl_tcp_syncookies __read_mostly = 1;
102978 EXPORT_SYMBOL(sysctl_tcp_syncookies);
102979
102980@@ -739,7 +743,10 @@ embryonic_reset:
102981 * avoid becoming vulnerable to outside attack aiming at
102982 * resetting legit local connections.
102983 */
102984- req->rsk_ops->send_reset(sk, skb);
102985+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
102986+ if (!grsec_enable_blackhole)
102987+#endif
102988+ req->rsk_ops->send_reset(sk, skb);
102989 } else if (fastopen) { /* received a valid RST pkt */
102990 reqsk_fastopen_remove(sk, req, true);
102991 tcp_reset(sk);
102992diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
102993index ebf5ff5..4d1ff32 100644
102994--- a/net/ipv4/tcp_probe.c
102995+++ b/net/ipv4/tcp_probe.c
102996@@ -236,7 +236,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
102997 if (cnt + width >= len)
102998 break;
102999
103000- if (copy_to_user(buf + cnt, tbuf, width))
103001+ if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
103002 return -EFAULT;
103003 cnt += width;
103004 }
103005diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
103006index 9b21ae8..4eb67df 100644
103007--- a/net/ipv4/tcp_timer.c
103008+++ b/net/ipv4/tcp_timer.c
103009@@ -22,6 +22,10 @@
103010 #include <linux/gfp.h>
103011 #include <net/tcp.h>
103012
103013+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103014+extern int grsec_lastack_retries;
103015+#endif
103016+
103017 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
103018 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
103019 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
103020@@ -191,6 +195,13 @@ static int tcp_write_timeout(struct sock *sk)
103021 }
103022 }
103023
103024+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103025+ if ((sk->sk_state == TCP_LAST_ACK) &&
103026+ (grsec_lastack_retries > 0) &&
103027+ (grsec_lastack_retries < retry_until))
103028+ retry_until = grsec_lastack_retries;
103029+#endif
103030+
103031 if (retransmits_timed_out(sk, retry_until,
103032 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
103033 /* Has it gone just too far? */
103034diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
103035index cd0db54..93a6518 100644
103036--- a/net/ipv4/udp.c
103037+++ b/net/ipv4/udp.c
103038@@ -87,6 +87,7 @@
103039 #include <linux/types.h>
103040 #include <linux/fcntl.h>
103041 #include <linux/module.h>
103042+#include <linux/security.h>
103043 #include <linux/socket.h>
103044 #include <linux/sockios.h>
103045 #include <linux/igmp.h>
103046@@ -114,6 +115,10 @@
103047 #include <net/busy_poll.h>
103048 #include "udp_impl.h"
103049
103050+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103051+extern int grsec_enable_blackhole;
103052+#endif
103053+
103054 struct udp_table udp_table __read_mostly;
103055 EXPORT_SYMBOL(udp_table);
103056
103057@@ -595,6 +600,9 @@ static inline bool __udp_is_mcast_sock(struct net *net, struct sock *sk,
103058 return true;
103059 }
103060
103061+extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
103062+extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
103063+
103064 /*
103065 * This routine is called by the ICMP module when it gets some
103066 * sort of error condition. If err < 0 then the socket should
103067@@ -932,9 +940,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
103068 dport = usin->sin_port;
103069 if (dport == 0)
103070 return -EINVAL;
103071+
103072+ err = gr_search_udp_sendmsg(sk, usin);
103073+ if (err)
103074+ return err;
103075 } else {
103076 if (sk->sk_state != TCP_ESTABLISHED)
103077 return -EDESTADDRREQ;
103078+
103079+ err = gr_search_udp_sendmsg(sk, NULL);
103080+ if (err)
103081+ return err;
103082+
103083 daddr = inet->inet_daddr;
103084 dport = inet->inet_dport;
103085 /* Open fast path for connected socket.
103086@@ -1182,7 +1199,7 @@ static unsigned int first_packet_length(struct sock *sk)
103087 IS_UDPLITE(sk));
103088 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
103089 IS_UDPLITE(sk));
103090- atomic_inc(&sk->sk_drops);
103091+ atomic_inc_unchecked(&sk->sk_drops);
103092 __skb_unlink(skb, rcvq);
103093 __skb_queue_tail(&list_kill, skb);
103094 }
103095@@ -1262,6 +1279,10 @@ try_again:
103096 if (!skb)
103097 goto out;
103098
103099+ err = gr_search_udp_recvmsg(sk, skb);
103100+ if (err)
103101+ goto out_free;
103102+
103103 ulen = skb->len - sizeof(struct udphdr);
103104 copied = len;
103105 if (copied > ulen)
103106@@ -1295,7 +1316,7 @@ try_again:
103107 if (unlikely(err)) {
103108 trace_kfree_skb(skb, udp_recvmsg);
103109 if (!peeked) {
103110- atomic_inc(&sk->sk_drops);
103111+ atomic_inc_unchecked(&sk->sk_drops);
103112 UDP_INC_STATS_USER(sock_net(sk),
103113 UDP_MIB_INERRORS, is_udplite);
103114 }
103115@@ -1592,7 +1613,7 @@ csum_error:
103116 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
103117 drop:
103118 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
103119- atomic_inc(&sk->sk_drops);
103120+ atomic_inc_unchecked(&sk->sk_drops);
103121 kfree_skb(skb);
103122 return -1;
103123 }
103124@@ -1611,7 +1632,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
103125 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
103126
103127 if (!skb1) {
103128- atomic_inc(&sk->sk_drops);
103129+ atomic_inc_unchecked(&sk->sk_drops);
103130 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
103131 IS_UDPLITE(sk));
103132 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
103133@@ -1812,6 +1833,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
103134 goto csum_error;
103135
103136 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
103137+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103138+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
103139+#endif
103140 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
103141
103142 /*
103143@@ -2398,7 +2422,7 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
103144 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
103145 0, sock_i_ino(sp),
103146 atomic_read(&sp->sk_refcnt), sp,
103147- atomic_read(&sp->sk_drops));
103148+ atomic_read_unchecked(&sp->sk_drops));
103149 }
103150
103151 int udp4_seq_show(struct seq_file *seq, void *v)
103152diff --git a/net/ipv4/xfrm4_policy.c b/net/ipv4/xfrm4_policy.c
103153index 6156f68..d6ab46d 100644
103154--- a/net/ipv4/xfrm4_policy.c
103155+++ b/net/ipv4/xfrm4_policy.c
103156@@ -186,11 +186,11 @@ _decode_session4(struct sk_buff *skb, struct flowi *fl, int reverse)
103157 fl4->flowi4_tos = iph->tos;
103158 }
103159
103160-static inline int xfrm4_garbage_collect(struct dst_ops *ops)
103161+static int xfrm4_garbage_collect(struct dst_ops *ops)
103162 {
103163 struct net *net = container_of(ops, struct net, xfrm.xfrm4_dst_ops);
103164
103165- xfrm4_policy_afinfo.garbage_collect(net);
103166+ xfrm_garbage_collect_deferred(net);
103167 return (dst_entries_get_slow(ops) > ops->gc_thresh * 2);
103168 }
103169
103170@@ -269,19 +269,18 @@ static struct ctl_table xfrm4_policy_table[] = {
103171
103172 static int __net_init xfrm4_net_init(struct net *net)
103173 {
103174- struct ctl_table *table;
103175+ ctl_table_no_const *table = NULL;
103176 struct ctl_table_header *hdr;
103177
103178- table = xfrm4_policy_table;
103179 if (!net_eq(net, &init_net)) {
103180- table = kmemdup(table, sizeof(xfrm4_policy_table), GFP_KERNEL);
103181+ table = kmemdup(xfrm4_policy_table, sizeof(xfrm4_policy_table), GFP_KERNEL);
103182 if (!table)
103183 goto err_alloc;
103184
103185 table[0].data = &net->xfrm.xfrm4_dst_ops.gc_thresh;
103186- }
103187-
103188- hdr = register_net_sysctl(net, "net/ipv4", table);
103189+ hdr = register_net_sysctl(net, "net/ipv4", table);
103190+ } else
103191+ hdr = register_net_sysctl(net, "net/ipv4", xfrm4_policy_table);
103192 if (!hdr)
103193 goto err_reg;
103194
103195@@ -289,8 +288,7 @@ static int __net_init xfrm4_net_init(struct net *net)
103196 return 0;
103197
103198 err_reg:
103199- if (!net_eq(net, &init_net))
103200- kfree(table);
103201+ kfree(table);
103202 err_alloc:
103203 return -ENOMEM;
103204 }
103205diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
103206index 0169ccf..50d7b04 100644
103207--- a/net/ipv6/addrconf.c
103208+++ b/net/ipv6/addrconf.c
103209@@ -171,7 +171,7 @@ static struct ipv6_devconf ipv6_devconf __read_mostly = {
103210 .hop_limit = IPV6_DEFAULT_HOPLIMIT,
103211 .mtu6 = IPV6_MIN_MTU,
103212 .accept_ra = 1,
103213- .accept_redirects = 1,
103214+ .accept_redirects = 0,
103215 .autoconf = 1,
103216 .force_mld_version = 0,
103217 .mldv1_unsolicited_report_interval = 10 * HZ,
103218@@ -208,7 +208,7 @@ static struct ipv6_devconf ipv6_devconf_dflt __read_mostly = {
103219 .hop_limit = IPV6_DEFAULT_HOPLIMIT,
103220 .mtu6 = IPV6_MIN_MTU,
103221 .accept_ra = 1,
103222- .accept_redirects = 1,
103223+ .accept_redirects = 0,
103224 .autoconf = 1,
103225 .force_mld_version = 0,
103226 .mldv1_unsolicited_report_interval = 10 * HZ,
103227@@ -604,7 +604,7 @@ static int inet6_netconf_dump_devconf(struct sk_buff *skb,
103228 idx = 0;
103229 head = &net->dev_index_head[h];
103230 rcu_read_lock();
103231- cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^
103232+ cb->seq = atomic_read_unchecked(&net->ipv6.dev_addr_genid) ^
103233 net->dev_base_seq;
103234 hlist_for_each_entry_rcu(dev, head, index_hlist) {
103235 if (idx < s_idx)
103236@@ -2396,7 +2396,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
103237 p.iph.ihl = 5;
103238 p.iph.protocol = IPPROTO_IPV6;
103239 p.iph.ttl = 64;
103240- ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
103241+ ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
103242
103243 if (ops->ndo_do_ioctl) {
103244 mm_segment_t oldfs = get_fs();
103245@@ -3534,16 +3534,23 @@ static const struct file_operations if6_fops = {
103246 .release = seq_release_net,
103247 };
103248
103249+extern void register_ipv6_seq_ops_addr(struct seq_operations *addr);
103250+extern void unregister_ipv6_seq_ops_addr(void);
103251+
103252 static int __net_init if6_proc_net_init(struct net *net)
103253 {
103254- if (!proc_create("if_inet6", S_IRUGO, net->proc_net, &if6_fops))
103255+ register_ipv6_seq_ops_addr(&if6_seq_ops);
103256+ if (!proc_create("if_inet6", S_IRUGO, net->proc_net, &if6_fops)) {
103257+ unregister_ipv6_seq_ops_addr();
103258 return -ENOMEM;
103259+ }
103260 return 0;
103261 }
103262
103263 static void __net_exit if6_proc_net_exit(struct net *net)
103264 {
103265 remove_proc_entry("if_inet6", net->proc_net);
103266+ unregister_ipv6_seq_ops_addr();
103267 }
103268
103269 static struct pernet_operations if6_proc_net_ops = {
103270@@ -4159,7 +4166,7 @@ static int inet6_dump_addr(struct sk_buff *skb, struct netlink_callback *cb,
103271 s_ip_idx = ip_idx = cb->args[2];
103272
103273 rcu_read_lock();
103274- cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
103275+ cb->seq = atomic_read_unchecked(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
103276 for (h = s_h; h < NETDEV_HASHENTRIES; h++, s_idx = 0) {
103277 idx = 0;
103278 head = &net->dev_index_head[h];
103279@@ -4788,7 +4795,7 @@ static void __ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)
103280 rt_genid_bump_ipv6(net);
103281 break;
103282 }
103283- atomic_inc(&net->ipv6.dev_addr_genid);
103284+ atomic_inc_unchecked(&net->ipv6.dev_addr_genid);
103285 }
103286
103287 static void ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)
103288@@ -4808,7 +4815,7 @@ int addrconf_sysctl_forward(struct ctl_table *ctl, int write,
103289 int *valp = ctl->data;
103290 int val = *valp;
103291 loff_t pos = *ppos;
103292- struct ctl_table lctl;
103293+ ctl_table_no_const lctl;
103294 int ret;
103295
103296 /*
103297@@ -4893,7 +4900,7 @@ int addrconf_sysctl_disable(struct ctl_table *ctl, int write,
103298 int *valp = ctl->data;
103299 int val = *valp;
103300 loff_t pos = *ppos;
103301- struct ctl_table lctl;
103302+ ctl_table_no_const lctl;
103303 int ret;
103304
103305 /*
103306diff --git a/net/ipv6/af_inet6.c b/net/ipv6/af_inet6.c
103307index e8c4400..a4cd5da 100644
103308--- a/net/ipv6/af_inet6.c
103309+++ b/net/ipv6/af_inet6.c
103310@@ -766,7 +766,7 @@ static int __net_init inet6_net_init(struct net *net)
103311 net->ipv6.sysctl.icmpv6_time = 1*HZ;
103312 net->ipv6.sysctl.flowlabel_consistency = 1;
103313 net->ipv6.sysctl.auto_flowlabels = 0;
103314- atomic_set(&net->ipv6.fib6_sernum, 1);
103315+ atomic_set_unchecked(&net->ipv6.fib6_sernum, 1);
103316
103317 err = ipv6_init_mibs(net);
103318 if (err)
103319diff --git a/net/ipv6/datagram.c b/net/ipv6/datagram.c
103320index 2cdc383..09cffb8 100644
103321--- a/net/ipv6/datagram.c
103322+++ b/net/ipv6/datagram.c
103323@@ -928,5 +928,5 @@ void ip6_dgram_sock_seq_show(struct seq_file *seq, struct sock *sp,
103324 0,
103325 sock_i_ino(sp),
103326 atomic_read(&sp->sk_refcnt), sp,
103327- atomic_read(&sp->sk_drops));
103328+ atomic_read_unchecked(&sp->sk_drops));
103329 }
103330diff --git a/net/ipv6/icmp.c b/net/ipv6/icmp.c
103331index 97ae700..18dcae0 100644
103332--- a/net/ipv6/icmp.c
103333+++ b/net/ipv6/icmp.c
103334@@ -997,7 +997,7 @@ static struct ctl_table ipv6_icmp_table_template[] = {
103335
103336 struct ctl_table * __net_init ipv6_icmp_sysctl_init(struct net *net)
103337 {
103338- struct ctl_table *table;
103339+ ctl_table_no_const *table;
103340
103341 table = kmemdup(ipv6_icmp_table_template,
103342 sizeof(ipv6_icmp_table_template),
103343diff --git a/net/ipv6/ip6_fib.c b/net/ipv6/ip6_fib.c
103344index b2d1838..0194c04 100644
103345--- a/net/ipv6/ip6_fib.c
103346+++ b/net/ipv6/ip6_fib.c
103347@@ -99,9 +99,9 @@ static int fib6_new_sernum(struct net *net)
103348 int new, old;
103349
103350 do {
103351- old = atomic_read(&net->ipv6.fib6_sernum);
103352+ old = atomic_read_unchecked(&net->ipv6.fib6_sernum);
103353 new = old < INT_MAX ? old + 1 : 1;
103354- } while (atomic_cmpxchg(&net->ipv6.fib6_sernum,
103355+ } while (atomic_cmpxchg_unchecked(&net->ipv6.fib6_sernum,
103356 old, new) != old);
103357 return new;
103358 }
103359diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
103360index 0e32d2e..98cbe65 100644
103361--- a/net/ipv6/ip6_gre.c
103362+++ b/net/ipv6/ip6_gre.c
103363@@ -71,8 +71,8 @@ struct ip6gre_net {
103364 struct net_device *fb_tunnel_dev;
103365 };
103366
103367-static struct rtnl_link_ops ip6gre_link_ops __read_mostly;
103368-static struct rtnl_link_ops ip6gre_tap_ops __read_mostly;
103369+static struct rtnl_link_ops ip6gre_link_ops;
103370+static struct rtnl_link_ops ip6gre_tap_ops;
103371 static int ip6gre_tunnel_init(struct net_device *dev);
103372 static void ip6gre_tunnel_setup(struct net_device *dev);
103373 static void ip6gre_tunnel_link(struct ip6gre_net *ign, struct ip6_tnl *t);
103374@@ -1289,7 +1289,7 @@ static void ip6gre_fb_tunnel_init(struct net_device *dev)
103375 }
103376
103377
103378-static struct inet6_protocol ip6gre_protocol __read_mostly = {
103379+static struct inet6_protocol ip6gre_protocol = {
103380 .handler = ip6gre_rcv,
103381 .err_handler = ip6gre_err,
103382 .flags = INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL,
103383@@ -1650,7 +1650,7 @@ static const struct nla_policy ip6gre_policy[IFLA_GRE_MAX + 1] = {
103384 [IFLA_GRE_FLAGS] = { .type = NLA_U32 },
103385 };
103386
103387-static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
103388+static struct rtnl_link_ops ip6gre_link_ops = {
103389 .kind = "ip6gre",
103390 .maxtype = IFLA_GRE_MAX,
103391 .policy = ip6gre_policy,
103392@@ -1664,7 +1664,7 @@ static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
103393 .fill_info = ip6gre_fill_info,
103394 };
103395
103396-static struct rtnl_link_ops ip6gre_tap_ops __read_mostly = {
103397+static struct rtnl_link_ops ip6gre_tap_ops = {
103398 .kind = "ip6gretap",
103399 .maxtype = IFLA_GRE_MAX,
103400 .policy = ip6gre_policy,
103401diff --git a/net/ipv6/ip6_tunnel.c b/net/ipv6/ip6_tunnel.c
103402index 9cb94cf..5678108 100644
103403--- a/net/ipv6/ip6_tunnel.c
103404+++ b/net/ipv6/ip6_tunnel.c
103405@@ -86,7 +86,7 @@ static u32 HASH(const struct in6_addr *addr1, const struct in6_addr *addr2)
103406
103407 static int ip6_tnl_dev_init(struct net_device *dev);
103408 static void ip6_tnl_dev_setup(struct net_device *dev);
103409-static struct rtnl_link_ops ip6_link_ops __read_mostly;
103410+static struct rtnl_link_ops ip6_link_ops;
103411
103412 static int ip6_tnl_net_id __read_mostly;
103413 struct ip6_tnl_net {
103414@@ -1706,7 +1706,7 @@ static const struct nla_policy ip6_tnl_policy[IFLA_IPTUN_MAX + 1] = {
103415 [IFLA_IPTUN_PROTO] = { .type = NLA_U8 },
103416 };
103417
103418-static struct rtnl_link_ops ip6_link_ops __read_mostly = {
103419+static struct rtnl_link_ops ip6_link_ops = {
103420 .kind = "ip6tnl",
103421 .maxtype = IFLA_IPTUN_MAX,
103422 .policy = ip6_tnl_policy,
103423diff --git a/net/ipv6/ip6_vti.c b/net/ipv6/ip6_vti.c
103424index bcda14d..49378c9 100644
103425--- a/net/ipv6/ip6_vti.c
103426+++ b/net/ipv6/ip6_vti.c
103427@@ -62,7 +62,7 @@ static u32 HASH(const struct in6_addr *addr1, const struct in6_addr *addr2)
103428
103429 static int vti6_dev_init(struct net_device *dev);
103430 static void vti6_dev_setup(struct net_device *dev);
103431-static struct rtnl_link_ops vti6_link_ops __read_mostly;
103432+static struct rtnl_link_ops vti6_link_ops;
103433
103434 static int vti6_net_id __read_mostly;
103435 struct vti6_net {
103436@@ -981,7 +981,7 @@ static const struct nla_policy vti6_policy[IFLA_VTI_MAX + 1] = {
103437 [IFLA_VTI_OKEY] = { .type = NLA_U32 },
103438 };
103439
103440-static struct rtnl_link_ops vti6_link_ops __read_mostly = {
103441+static struct rtnl_link_ops vti6_link_ops = {
103442 .kind = "vti6",
103443 .maxtype = IFLA_VTI_MAX,
103444 .policy = vti6_policy,
103445diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
103446index e1a9583..7dd8f4d 100644
103447--- a/net/ipv6/ipv6_sockglue.c
103448+++ b/net/ipv6/ipv6_sockglue.c
103449@@ -993,7 +993,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
103450 if (sk->sk_type != SOCK_STREAM)
103451 return -ENOPROTOOPT;
103452
103453- msg.msg_control = optval;
103454+ msg.msg_control = (void __force_kernel *)optval;
103455 msg.msg_controllen = len;
103456 msg.msg_flags = flags;
103457
103458diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
103459index e080fbb..412b3cf 100644
103460--- a/net/ipv6/netfilter/ip6_tables.c
103461+++ b/net/ipv6/netfilter/ip6_tables.c
103462@@ -1083,14 +1083,14 @@ static int compat_table_info(const struct xt_table_info *info,
103463 #endif
103464
103465 static int get_info(struct net *net, void __user *user,
103466- const int *len, int compat)
103467+ int len, int compat)
103468 {
103469 char name[XT_TABLE_MAXNAMELEN];
103470 struct xt_table *t;
103471 int ret;
103472
103473- if (*len != sizeof(struct ip6t_getinfo)) {
103474- duprintf("length %u != %zu\n", *len,
103475+ if (len != sizeof(struct ip6t_getinfo)) {
103476+ duprintf("length %u != %zu\n", len,
103477 sizeof(struct ip6t_getinfo));
103478 return -EINVAL;
103479 }
103480@@ -1127,7 +1127,7 @@ static int get_info(struct net *net, void __user *user,
103481 info.size = private->size;
103482 strcpy(info.name, name);
103483
103484- if (copy_to_user(user, &info, *len) != 0)
103485+ if (copy_to_user(user, &info, len) != 0)
103486 ret = -EFAULT;
103487 else
103488 ret = 0;
103489@@ -1983,7 +1983,7 @@ compat_do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
103490
103491 switch (cmd) {
103492 case IP6T_SO_GET_INFO:
103493- ret = get_info(sock_net(sk), user, len, 1);
103494+ ret = get_info(sock_net(sk), user, *len, 1);
103495 break;
103496 case IP6T_SO_GET_ENTRIES:
103497 ret = compat_get_entries(sock_net(sk), user, len);
103498@@ -2030,7 +2030,7 @@ do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
103499
103500 switch (cmd) {
103501 case IP6T_SO_GET_INFO:
103502- ret = get_info(sock_net(sk), user, len, 0);
103503+ ret = get_info(sock_net(sk), user, *len, 0);
103504 break;
103505
103506 case IP6T_SO_GET_ENTRIES:
103507diff --git a/net/ipv6/netfilter/nf_conntrack_reasm.c b/net/ipv6/netfilter/nf_conntrack_reasm.c
103508index 6f187c8..34b367f 100644
103509--- a/net/ipv6/netfilter/nf_conntrack_reasm.c
103510+++ b/net/ipv6/netfilter/nf_conntrack_reasm.c
103511@@ -96,12 +96,11 @@ static struct ctl_table nf_ct_frag6_sysctl_table[] = {
103512
103513 static int nf_ct_frag6_sysctl_register(struct net *net)
103514 {
103515- struct ctl_table *table;
103516+ ctl_table_no_const *table = NULL;
103517 struct ctl_table_header *hdr;
103518
103519- table = nf_ct_frag6_sysctl_table;
103520 if (!net_eq(net, &init_net)) {
103521- table = kmemdup(table, sizeof(nf_ct_frag6_sysctl_table),
103522+ table = kmemdup(nf_ct_frag6_sysctl_table, sizeof(nf_ct_frag6_sysctl_table),
103523 GFP_KERNEL);
103524 if (table == NULL)
103525 goto err_alloc;
103526@@ -112,9 +111,9 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
103527 table[2].data = &net->nf_frag.frags.high_thresh;
103528 table[2].extra1 = &net->nf_frag.frags.low_thresh;
103529 table[2].extra2 = &init_net.nf_frag.frags.high_thresh;
103530- }
103531-
103532- hdr = register_net_sysctl(net, "net/netfilter", table);
103533+ hdr = register_net_sysctl(net, "net/netfilter", table);
103534+ } else
103535+ hdr = register_net_sysctl(net, "net/netfilter", nf_ct_frag6_sysctl_table);
103536 if (hdr == NULL)
103537 goto err_reg;
103538
103539@@ -122,8 +121,7 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
103540 return 0;
103541
103542 err_reg:
103543- if (!net_eq(net, &init_net))
103544- kfree(table);
103545+ kfree(table);
103546 err_alloc:
103547 return -ENOMEM;
103548 }
103549diff --git a/net/ipv6/ping.c b/net/ipv6/ping.c
103550index 5b7a1ed..d9da205 100644
103551--- a/net/ipv6/ping.c
103552+++ b/net/ipv6/ping.c
103553@@ -240,6 +240,24 @@ static struct pernet_operations ping_v6_net_ops = {
103554 };
103555 #endif
103556
103557+static struct pingv6_ops real_pingv6_ops = {
103558+ .ipv6_recv_error = ipv6_recv_error,
103559+ .ip6_datagram_recv_common_ctl = ip6_datagram_recv_common_ctl,
103560+ .ip6_datagram_recv_specific_ctl = ip6_datagram_recv_specific_ctl,
103561+ .icmpv6_err_convert = icmpv6_err_convert,
103562+ .ipv6_icmp_error = ipv6_icmp_error,
103563+ .ipv6_chk_addr = ipv6_chk_addr,
103564+};
103565+
103566+static struct pingv6_ops dummy_pingv6_ops = {
103567+ .ipv6_recv_error = dummy_ipv6_recv_error,
103568+ .ip6_datagram_recv_common_ctl = dummy_ip6_datagram_recv_ctl,
103569+ .ip6_datagram_recv_specific_ctl = dummy_ip6_datagram_recv_ctl,
103570+ .icmpv6_err_convert = dummy_icmpv6_err_convert,
103571+ .ipv6_icmp_error = dummy_ipv6_icmp_error,
103572+ .ipv6_chk_addr = dummy_ipv6_chk_addr,
103573+};
103574+
103575 int __init pingv6_init(void)
103576 {
103577 #ifdef CONFIG_PROC_FS
103578@@ -247,13 +265,7 @@ int __init pingv6_init(void)
103579 if (ret)
103580 return ret;
103581 #endif
103582- pingv6_ops.ipv6_recv_error = ipv6_recv_error;
103583- pingv6_ops.ip6_datagram_recv_common_ctl = ip6_datagram_recv_common_ctl;
103584- pingv6_ops.ip6_datagram_recv_specific_ctl =
103585- ip6_datagram_recv_specific_ctl;
103586- pingv6_ops.icmpv6_err_convert = icmpv6_err_convert;
103587- pingv6_ops.ipv6_icmp_error = ipv6_icmp_error;
103588- pingv6_ops.ipv6_chk_addr = ipv6_chk_addr;
103589+ pingv6_ops = &real_pingv6_ops;
103590 return inet6_register_protosw(&pingv6_protosw);
103591 }
103592
103593@@ -262,14 +274,9 @@ int __init pingv6_init(void)
103594 */
103595 void pingv6_exit(void)
103596 {
103597- pingv6_ops.ipv6_recv_error = dummy_ipv6_recv_error;
103598- pingv6_ops.ip6_datagram_recv_common_ctl = dummy_ip6_datagram_recv_ctl;
103599- pingv6_ops.ip6_datagram_recv_specific_ctl = dummy_ip6_datagram_recv_ctl;
103600- pingv6_ops.icmpv6_err_convert = dummy_icmpv6_err_convert;
103601- pingv6_ops.ipv6_icmp_error = dummy_ipv6_icmp_error;
103602- pingv6_ops.ipv6_chk_addr = dummy_ipv6_chk_addr;
103603 #ifdef CONFIG_PROC_FS
103604 unregister_pernet_subsys(&ping_v6_net_ops);
103605 #endif
103606+ pingv6_ops = &dummy_pingv6_ops;
103607 inet6_unregister_protosw(&pingv6_protosw);
103608 }
103609diff --git a/net/ipv6/proc.c b/net/ipv6/proc.c
103610index 1752cd0..3c6af41 100644
103611--- a/net/ipv6/proc.c
103612+++ b/net/ipv6/proc.c
103613@@ -309,7 +309,7 @@ static int __net_init ipv6_proc_init_net(struct net *net)
103614 if (!proc_create("snmp6", S_IRUGO, net->proc_net, &snmp6_seq_fops))
103615 goto proc_snmp6_fail;
103616
103617- net->mib.proc_net_devsnmp6 = proc_mkdir("dev_snmp6", net->proc_net);
103618+ net->mib.proc_net_devsnmp6 = proc_mkdir_restrict("dev_snmp6", net->proc_net);
103619 if (!net->mib.proc_net_devsnmp6)
103620 goto proc_dev_snmp6_fail;
103621 return 0;
103622diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
103623index 896af88..6e2ba628 100644
103624--- a/net/ipv6/raw.c
103625+++ b/net/ipv6/raw.c
103626@@ -388,7 +388,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
103627 {
103628 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
103629 skb_checksum_complete(skb)) {
103630- atomic_inc(&sk->sk_drops);
103631+ atomic_inc_unchecked(&sk->sk_drops);
103632 kfree_skb(skb);
103633 return NET_RX_DROP;
103634 }
103635@@ -416,7 +416,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
103636 struct raw6_sock *rp = raw6_sk(sk);
103637
103638 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
103639- atomic_inc(&sk->sk_drops);
103640+ atomic_inc_unchecked(&sk->sk_drops);
103641 kfree_skb(skb);
103642 return NET_RX_DROP;
103643 }
103644@@ -440,7 +440,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
103645
103646 if (inet->hdrincl) {
103647 if (skb_checksum_complete(skb)) {
103648- atomic_inc(&sk->sk_drops);
103649+ atomic_inc_unchecked(&sk->sk_drops);
103650 kfree_skb(skb);
103651 return NET_RX_DROP;
103652 }
103653@@ -608,7 +608,7 @@ out:
103654 return err;
103655 }
103656
103657-static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
103658+static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
103659 struct flowi6 *fl6, struct dst_entry **dstp,
103660 unsigned int flags)
103661 {
103662@@ -914,12 +914,15 @@ do_confirm:
103663 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
103664 char __user *optval, int optlen)
103665 {
103666+ struct icmp6_filter filter;
103667+
103668 switch (optname) {
103669 case ICMPV6_FILTER:
103670 if (optlen > sizeof(struct icmp6_filter))
103671 optlen = sizeof(struct icmp6_filter);
103672- if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
103673+ if (copy_from_user(&filter, optval, optlen))
103674 return -EFAULT;
103675+ raw6_sk(sk)->filter = filter;
103676 return 0;
103677 default:
103678 return -ENOPROTOOPT;
103679@@ -932,6 +935,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
103680 char __user *optval, int __user *optlen)
103681 {
103682 int len;
103683+ struct icmp6_filter filter;
103684
103685 switch (optname) {
103686 case ICMPV6_FILTER:
103687@@ -943,7 +947,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
103688 len = sizeof(struct icmp6_filter);
103689 if (put_user(len, optlen))
103690 return -EFAULT;
103691- if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
103692+ filter = raw6_sk(sk)->filter;
103693+ if (len > sizeof filter || copy_to_user(optval, &filter, len))
103694 return -EFAULT;
103695 return 0;
103696 default:
103697diff --git a/net/ipv6/reassembly.c b/net/ipv6/reassembly.c
103698index 1a157ca..9fc05f4 100644
103699--- a/net/ipv6/reassembly.c
103700+++ b/net/ipv6/reassembly.c
103701@@ -625,12 +625,11 @@ static struct ctl_table ip6_frags_ctl_table[] = {
103702
103703 static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
103704 {
103705- struct ctl_table *table;
103706+ ctl_table_no_const *table = NULL;
103707 struct ctl_table_header *hdr;
103708
103709- table = ip6_frags_ns_ctl_table;
103710 if (!net_eq(net, &init_net)) {
103711- table = kmemdup(table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
103712+ table = kmemdup(ip6_frags_ns_ctl_table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
103713 if (table == NULL)
103714 goto err_alloc;
103715
103716@@ -644,9 +643,10 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
103717 /* Don't export sysctls to unprivileged users */
103718 if (net->user_ns != &init_user_ns)
103719 table[0].procname = NULL;
103720- }
103721+ hdr = register_net_sysctl(net, "net/ipv6", table);
103722+ } else
103723+ hdr = register_net_sysctl(net, "net/ipv6", ip6_frags_ns_ctl_table);
103724
103725- hdr = register_net_sysctl(net, "net/ipv6", table);
103726 if (hdr == NULL)
103727 goto err_reg;
103728
103729@@ -654,8 +654,7 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
103730 return 0;
103731
103732 err_reg:
103733- if (!net_eq(net, &init_net))
103734- kfree(table);
103735+ kfree(table);
103736 err_alloc:
103737 return -ENOMEM;
103738 }
103739diff --git a/net/ipv6/route.c b/net/ipv6/route.c
103740index a318dd89..7ecfea6 100644
103741--- a/net/ipv6/route.c
103742+++ b/net/ipv6/route.c
103743@@ -2965,7 +2965,7 @@ struct ctl_table ipv6_route_table_template[] = {
103744
103745 struct ctl_table * __net_init ipv6_route_sysctl_init(struct net *net)
103746 {
103747- struct ctl_table *table;
103748+ ctl_table_no_const *table;
103749
103750 table = kmemdup(ipv6_route_table_template,
103751 sizeof(ipv6_route_table_template),
103752diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c
103753index a24557a..00a9ed1 100644
103754--- a/net/ipv6/sit.c
103755+++ b/net/ipv6/sit.c
103756@@ -74,7 +74,7 @@ static void ipip6_tunnel_setup(struct net_device *dev);
103757 static void ipip6_dev_free(struct net_device *dev);
103758 static bool check_6rd(struct ip_tunnel *tunnel, const struct in6_addr *v6dst,
103759 __be32 *v4dst);
103760-static struct rtnl_link_ops sit_link_ops __read_mostly;
103761+static struct rtnl_link_ops sit_link_ops;
103762
103763 static int sit_net_id __read_mostly;
103764 struct sit_net {
103765@@ -1750,7 +1750,7 @@ static void ipip6_dellink(struct net_device *dev, struct list_head *head)
103766 unregister_netdevice_queue(dev, head);
103767 }
103768
103769-static struct rtnl_link_ops sit_link_ops __read_mostly = {
103770+static struct rtnl_link_ops sit_link_ops = {
103771 .kind = "sit",
103772 .maxtype = IFLA_IPTUN_MAX,
103773 .policy = ipip6_policy,
103774diff --git a/net/ipv6/sysctl_net_ipv6.c b/net/ipv6/sysctl_net_ipv6.c
103775index c5c10fa..2577d51 100644
103776--- a/net/ipv6/sysctl_net_ipv6.c
103777+++ b/net/ipv6/sysctl_net_ipv6.c
103778@@ -78,7 +78,7 @@ static struct ctl_table ipv6_rotable[] = {
103779
103780 static int __net_init ipv6_sysctl_net_init(struct net *net)
103781 {
103782- struct ctl_table *ipv6_table;
103783+ ctl_table_no_const *ipv6_table;
103784 struct ctl_table *ipv6_route_table;
103785 struct ctl_table *ipv6_icmp_table;
103786 int err;
103787diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
103788index c277951..c7ee5bf 100644
103789--- a/net/ipv6/tcp_ipv6.c
103790+++ b/net/ipv6/tcp_ipv6.c
103791@@ -104,6 +104,10 @@ static void inet6_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb)
103792 }
103793 }
103794
103795+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103796+extern int grsec_enable_blackhole;
103797+#endif
103798+
103799 static void tcp_v6_hash(struct sock *sk)
103800 {
103801 if (sk->sk_state != TCP_CLOSE) {
103802@@ -1341,6 +1345,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
103803 return 0;
103804
103805 reset:
103806+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103807+ if (!grsec_enable_blackhole)
103808+#endif
103809 tcp_v6_send_reset(sk, skb);
103810 discard:
103811 if (opt_skb)
103812@@ -1434,12 +1441,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
103813
103814 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest,
103815 tcp_v6_iif(skb));
103816- if (!sk)
103817+ if (!sk) {
103818+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103819+ ret = 1;
103820+#endif
103821 goto no_tcp_socket;
103822+ }
103823
103824 process:
103825- if (sk->sk_state == TCP_TIME_WAIT)
103826+ if (sk->sk_state == TCP_TIME_WAIT) {
103827+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103828+ ret = 2;
103829+#endif
103830 goto do_time_wait;
103831+ }
103832
103833 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
103834 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
103835@@ -1486,6 +1501,10 @@ csum_error:
103836 bad_packet:
103837 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
103838 } else {
103839+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103840+ if (!grsec_enable_blackhole || (ret == 1 &&
103841+ (skb->dev->flags & IFF_LOOPBACK)))
103842+#endif
103843 tcp_v6_send_reset(NULL, skb);
103844 }
103845
103846diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
103847index f6ba535..b41033f 100644
103848--- a/net/ipv6/udp.c
103849+++ b/net/ipv6/udp.c
103850@@ -76,6 +76,10 @@ static unsigned int udp6_ehashfn(struct net *net,
103851 udp_ipv6_hash_secret + net_hash_mix(net));
103852 }
103853
103854+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103855+extern int grsec_enable_blackhole;
103856+#endif
103857+
103858 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
103859 {
103860 const struct in6_addr *sk2_rcv_saddr6 = inet6_rcv_saddr(sk2);
103861@@ -434,7 +438,7 @@ try_again:
103862 if (unlikely(err)) {
103863 trace_kfree_skb(skb, udpv6_recvmsg);
103864 if (!peeked) {
103865- atomic_inc(&sk->sk_drops);
103866+ atomic_inc_unchecked(&sk->sk_drops);
103867 if (is_udp4)
103868 UDP_INC_STATS_USER(sock_net(sk),
103869 UDP_MIB_INERRORS,
103870@@ -701,7 +705,7 @@ csum_error:
103871 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
103872 drop:
103873 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
103874- atomic_inc(&sk->sk_drops);
103875+ atomic_inc_unchecked(&sk->sk_drops);
103876 kfree_skb(skb);
103877 return -1;
103878 }
103879@@ -740,7 +744,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
103880 if (likely(skb1 == NULL))
103881 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
103882 if (!skb1) {
103883- atomic_inc(&sk->sk_drops);
103884+ atomic_inc_unchecked(&sk->sk_drops);
103885 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
103886 IS_UDPLITE(sk));
103887 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
103888@@ -919,6 +923,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
103889 goto csum_error;
103890
103891 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
103892+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103893+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
103894+#endif
103895 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
103896
103897 kfree_skb(skb);
103898diff --git a/net/ipv6/xfrm6_policy.c b/net/ipv6/xfrm6_policy.c
103899index 5f98364..5ca982a 100644
103900--- a/net/ipv6/xfrm6_policy.c
103901+++ b/net/ipv6/xfrm6_policy.c
103902@@ -130,8 +130,8 @@ _decode_session6(struct sk_buff *skb, struct flowi *fl, int reverse)
103903 {
103904 struct flowi6 *fl6 = &fl->u.ip6;
103905 int onlyproto = 0;
103906- u16 offset = skb_network_header_len(skb);
103907 const struct ipv6hdr *hdr = ipv6_hdr(skb);
103908+ u16 offset = sizeof(*hdr);
103909 struct ipv6_opt_hdr *exthdr;
103910 const unsigned char *nh = skb_network_header(skb);
103911 u8 nexthdr = nh[IP6CB(skb)->nhoff];
103912@@ -217,11 +217,11 @@ _decode_session6(struct sk_buff *skb, struct flowi *fl, int reverse)
103913 }
103914 }
103915
103916-static inline int xfrm6_garbage_collect(struct dst_ops *ops)
103917+static int xfrm6_garbage_collect(struct dst_ops *ops)
103918 {
103919 struct net *net = container_of(ops, struct net, xfrm.xfrm6_dst_ops);
103920
103921- xfrm6_policy_afinfo.garbage_collect(net);
103922+ xfrm_garbage_collect_deferred(net);
103923 return dst_entries_get_fast(ops) > ops->gc_thresh * 2;
103924 }
103925
103926@@ -334,19 +334,19 @@ static struct ctl_table xfrm6_policy_table[] = {
103927
103928 static int __net_init xfrm6_net_init(struct net *net)
103929 {
103930- struct ctl_table *table;
103931+ ctl_table_no_const *table = NULL;
103932 struct ctl_table_header *hdr;
103933
103934- table = xfrm6_policy_table;
103935 if (!net_eq(net, &init_net)) {
103936- table = kmemdup(table, sizeof(xfrm6_policy_table), GFP_KERNEL);
103937+ table = kmemdup(xfrm6_policy_table, sizeof(xfrm6_policy_table), GFP_KERNEL);
103938 if (!table)
103939 goto err_alloc;
103940
103941 table[0].data = &net->xfrm.xfrm6_dst_ops.gc_thresh;
103942- }
103943+ hdr = register_net_sysctl(net, "net/ipv6", table);
103944+ } else
103945+ hdr = register_net_sysctl(net, "net/ipv6", xfrm6_policy_table);
103946
103947- hdr = register_net_sysctl(net, "net/ipv6", table);
103948 if (!hdr)
103949 goto err_reg;
103950
103951@@ -354,8 +354,7 @@ static int __net_init xfrm6_net_init(struct net *net)
103952 return 0;
103953
103954 err_reg:
103955- if (!net_eq(net, &init_net))
103956- kfree(table);
103957+ kfree(table);
103958 err_alloc:
103959 return -ENOMEM;
103960 }
103961diff --git a/net/ipx/ipx_proc.c b/net/ipx/ipx_proc.c
103962index e15c16a..7cf07aa 100644
103963--- a/net/ipx/ipx_proc.c
103964+++ b/net/ipx/ipx_proc.c
103965@@ -289,7 +289,7 @@ int __init ipx_proc_init(void)
103966 struct proc_dir_entry *p;
103967 int rc = -ENOMEM;
103968
103969- ipx_proc_dir = proc_mkdir("ipx", init_net.proc_net);
103970+ ipx_proc_dir = proc_mkdir_restrict("ipx", init_net.proc_net);
103971
103972 if (!ipx_proc_dir)
103973 goto out;
103974diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
103975index 61ceb4c..e788eb8 100644
103976--- a/net/irda/ircomm/ircomm_tty.c
103977+++ b/net/irda/ircomm/ircomm_tty.c
103978@@ -317,10 +317,10 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
103979 add_wait_queue(&port->open_wait, &wait);
103980
103981 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
103982- __FILE__, __LINE__, tty->driver->name, port->count);
103983+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
103984
103985 spin_lock_irqsave(&port->lock, flags);
103986- port->count--;
103987+ atomic_dec(&port->count);
103988 port->blocked_open++;
103989 spin_unlock_irqrestore(&port->lock, flags);
103990
103991@@ -355,7 +355,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
103992 }
103993
103994 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
103995- __FILE__, __LINE__, tty->driver->name, port->count);
103996+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
103997
103998 schedule();
103999 }
104000@@ -365,12 +365,12 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
104001
104002 spin_lock_irqsave(&port->lock, flags);
104003 if (!tty_hung_up_p(filp))
104004- port->count++;
104005+ atomic_inc(&port->count);
104006 port->blocked_open--;
104007 spin_unlock_irqrestore(&port->lock, flags);
104008
104009 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
104010- __FILE__, __LINE__, tty->driver->name, port->count);
104011+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
104012
104013 if (!retval)
104014 port->flags |= ASYNC_NORMAL_ACTIVE;
104015@@ -444,12 +444,12 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
104016
104017 /* ++ is not atomic, so this should be protected - Jean II */
104018 spin_lock_irqsave(&self->port.lock, flags);
104019- self->port.count++;
104020+ atomic_inc(&self->port.count);
104021 spin_unlock_irqrestore(&self->port.lock, flags);
104022 tty_port_tty_set(&self->port, tty);
104023
104024 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
104025- self->line, self->port.count);
104026+ self->line, atomic_read(&self->port.count));
104027
104028 /* Not really used by us, but lets do it anyway */
104029 self->port.low_latency = (self->port.flags & ASYNC_LOW_LATENCY) ? 1 : 0;
104030@@ -985,7 +985,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
104031 tty_kref_put(port->tty);
104032 }
104033 port->tty = NULL;
104034- port->count = 0;
104035+ atomic_set(&port->count, 0);
104036 spin_unlock_irqrestore(&port->lock, flags);
104037
104038 wake_up_interruptible(&port->open_wait);
104039@@ -1342,7 +1342,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
104040 seq_putc(m, '\n');
104041
104042 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
104043- seq_printf(m, "Open count: %d\n", self->port.count);
104044+ seq_printf(m, "Open count: %d\n", atomic_read(&self->port.count));
104045 seq_printf(m, "Max data size: %d\n", self->max_data_size);
104046 seq_printf(m, "Max header size: %d\n", self->max_header_size);
104047
104048diff --git a/net/irda/irproc.c b/net/irda/irproc.c
104049index b9ac598..f88cc56 100644
104050--- a/net/irda/irproc.c
104051+++ b/net/irda/irproc.c
104052@@ -66,7 +66,7 @@ void __init irda_proc_register(void)
104053 {
104054 int i;
104055
104056- proc_irda = proc_mkdir("irda", init_net.proc_net);
104057+ proc_irda = proc_mkdir_restrict("irda", init_net.proc_net);
104058 if (proc_irda == NULL)
104059 return;
104060
104061diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
104062index a089b6b..3ca3b60 100644
104063--- a/net/iucv/af_iucv.c
104064+++ b/net/iucv/af_iucv.c
104065@@ -686,10 +686,10 @@ static void __iucv_auto_name(struct iucv_sock *iucv)
104066 {
104067 char name[12];
104068
104069- sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
104070+ sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
104071 while (__iucv_get_sock_by_name(name)) {
104072 sprintf(name, "%08x",
104073- atomic_inc_return(&iucv_sk_list.autobind_name));
104074+ atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
104075 }
104076 memcpy(iucv->src_name, name, 8);
104077 }
104078diff --git a/net/iucv/iucv.c b/net/iucv/iucv.c
104079index 2a6a1fd..6c112b0 100644
104080--- a/net/iucv/iucv.c
104081+++ b/net/iucv/iucv.c
104082@@ -702,7 +702,7 @@ static int iucv_cpu_notify(struct notifier_block *self,
104083 return NOTIFY_OK;
104084 }
104085
104086-static struct notifier_block __refdata iucv_cpu_notifier = {
104087+static struct notifier_block iucv_cpu_notifier = {
104088 .notifier_call = iucv_cpu_notify,
104089 };
104090
104091diff --git a/net/key/af_key.c b/net/key/af_key.c
104092index 1847ec4..26ef732 100644
104093--- a/net/key/af_key.c
104094+++ b/net/key/af_key.c
104095@@ -3049,10 +3049,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
104096 static u32 get_acqseq(void)
104097 {
104098 u32 res;
104099- static atomic_t acqseq;
104100+ static atomic_unchecked_t acqseq;
104101
104102 do {
104103- res = atomic_inc_return(&acqseq);
104104+ res = atomic_inc_return_unchecked(&acqseq);
104105 } while (!res);
104106 return res;
104107 }
104108diff --git a/net/l2tp/l2tp_eth.c b/net/l2tp/l2tp_eth.c
104109index edb78e6..8dc654a 100644
104110--- a/net/l2tp/l2tp_eth.c
104111+++ b/net/l2tp/l2tp_eth.c
104112@@ -42,12 +42,12 @@ struct l2tp_eth {
104113 struct sock *tunnel_sock;
104114 struct l2tp_session *session;
104115 struct list_head list;
104116- atomic_long_t tx_bytes;
104117- atomic_long_t tx_packets;
104118- atomic_long_t tx_dropped;
104119- atomic_long_t rx_bytes;
104120- atomic_long_t rx_packets;
104121- atomic_long_t rx_errors;
104122+ atomic_long_unchecked_t tx_bytes;
104123+ atomic_long_unchecked_t tx_packets;
104124+ atomic_long_unchecked_t tx_dropped;
104125+ atomic_long_unchecked_t rx_bytes;
104126+ atomic_long_unchecked_t rx_packets;
104127+ atomic_long_unchecked_t rx_errors;
104128 };
104129
104130 /* via l2tp_session_priv() */
104131@@ -98,10 +98,10 @@ static int l2tp_eth_dev_xmit(struct sk_buff *skb, struct net_device *dev)
104132 int ret = l2tp_xmit_skb(session, skb, session->hdr_len);
104133
104134 if (likely(ret == NET_XMIT_SUCCESS)) {
104135- atomic_long_add(len, &priv->tx_bytes);
104136- atomic_long_inc(&priv->tx_packets);
104137+ atomic_long_add_unchecked(len, &priv->tx_bytes);
104138+ atomic_long_inc_unchecked(&priv->tx_packets);
104139 } else {
104140- atomic_long_inc(&priv->tx_dropped);
104141+ atomic_long_inc_unchecked(&priv->tx_dropped);
104142 }
104143 return NETDEV_TX_OK;
104144 }
104145@@ -111,12 +111,12 @@ static struct rtnl_link_stats64 *l2tp_eth_get_stats64(struct net_device *dev,
104146 {
104147 struct l2tp_eth *priv = netdev_priv(dev);
104148
104149- stats->tx_bytes = atomic_long_read(&priv->tx_bytes);
104150- stats->tx_packets = atomic_long_read(&priv->tx_packets);
104151- stats->tx_dropped = atomic_long_read(&priv->tx_dropped);
104152- stats->rx_bytes = atomic_long_read(&priv->rx_bytes);
104153- stats->rx_packets = atomic_long_read(&priv->rx_packets);
104154- stats->rx_errors = atomic_long_read(&priv->rx_errors);
104155+ stats->tx_bytes = atomic_long_read_unchecked(&priv->tx_bytes);
104156+ stats->tx_packets = atomic_long_read_unchecked(&priv->tx_packets);
104157+ stats->tx_dropped = atomic_long_read_unchecked(&priv->tx_dropped);
104158+ stats->rx_bytes = atomic_long_read_unchecked(&priv->rx_bytes);
104159+ stats->rx_packets = atomic_long_read_unchecked(&priv->rx_packets);
104160+ stats->rx_errors = atomic_long_read_unchecked(&priv->rx_errors);
104161 return stats;
104162 }
104163
104164@@ -166,15 +166,15 @@ static void l2tp_eth_dev_recv(struct l2tp_session *session, struct sk_buff *skb,
104165 nf_reset(skb);
104166
104167 if (dev_forward_skb(dev, skb) == NET_RX_SUCCESS) {
104168- atomic_long_inc(&priv->rx_packets);
104169- atomic_long_add(data_len, &priv->rx_bytes);
104170+ atomic_long_inc_unchecked(&priv->rx_packets);
104171+ atomic_long_add_unchecked(data_len, &priv->rx_bytes);
104172 } else {
104173- atomic_long_inc(&priv->rx_errors);
104174+ atomic_long_inc_unchecked(&priv->rx_errors);
104175 }
104176 return;
104177
104178 error:
104179- atomic_long_inc(&priv->rx_errors);
104180+ atomic_long_inc_unchecked(&priv->rx_errors);
104181 kfree_skb(skb);
104182 }
104183
104184diff --git a/net/llc/llc_proc.c b/net/llc/llc_proc.c
104185index 1a3c7e0..80f8b0c 100644
104186--- a/net/llc/llc_proc.c
104187+++ b/net/llc/llc_proc.c
104188@@ -247,7 +247,7 @@ int __init llc_proc_init(void)
104189 int rc = -ENOMEM;
104190 struct proc_dir_entry *p;
104191
104192- llc_proc_dir = proc_mkdir("llc", init_net.proc_net);
104193+ llc_proc_dir = proc_mkdir_restrict("llc", init_net.proc_net);
104194 if (!llc_proc_dir)
104195 goto out;
104196
104197diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
104198index 343da1e..509873f 100644
104199--- a/net/mac80211/cfg.c
104200+++ b/net/mac80211/cfg.c
104201@@ -541,7 +541,7 @@ static int ieee80211_set_monitor_channel(struct wiphy *wiphy,
104202 ret = ieee80211_vif_use_channel(sdata, chandef,
104203 IEEE80211_CHANCTX_EXCLUSIVE);
104204 }
104205- } else if (local->open_count == local->monitors) {
104206+ } else if (local_read(&local->open_count) == local->monitors) {
104207 local->_oper_chandef = *chandef;
104208 ieee80211_hw_config(local, 0);
104209 }
104210@@ -3326,7 +3326,7 @@ static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
104211 else
104212 local->probe_req_reg--;
104213
104214- if (!local->open_count)
104215+ if (!local_read(&local->open_count))
104216 break;
104217
104218 ieee80211_queue_work(&local->hw, &local->reconfig_filter);
104219@@ -3460,8 +3460,8 @@ static int ieee80211_cfg_get_channel(struct wiphy *wiphy,
104220 if (chanctx_conf) {
104221 *chandef = sdata->vif.bss_conf.chandef;
104222 ret = 0;
104223- } else if (local->open_count > 0 &&
104224- local->open_count == local->monitors &&
104225+ } else if (local_read(&local->open_count) > 0 &&
104226+ local_read(&local->open_count) == local->monitors &&
104227 sdata->vif.type == NL80211_IFTYPE_MONITOR) {
104228 if (local->use_chanctx)
104229 *chandef = local->monitor_chandef;
104230diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
104231index 8c68da3..0695016 100644
104232--- a/net/mac80211/ieee80211_i.h
104233+++ b/net/mac80211/ieee80211_i.h
104234@@ -29,6 +29,7 @@
104235 #include <net/ieee80211_radiotap.h>
104236 #include <net/cfg80211.h>
104237 #include <net/mac80211.h>
104238+#include <asm/local.h>
104239 #include "key.h"
104240 #include "sta_info.h"
104241 #include "debug.h"
104242@@ -1057,7 +1058,7 @@ struct ieee80211_local {
104243 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
104244 spinlock_t queue_stop_reason_lock;
104245
104246- int open_count;
104247+ local_t open_count;
104248 int monitors, cooked_mntrs;
104249 /* number of interfaces with corresponding FIF_ flags */
104250 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
104251diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
104252index 653f5eb..02994ee 100644
104253--- a/net/mac80211/iface.c
104254+++ b/net/mac80211/iface.c
104255@@ -532,7 +532,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
104256 break;
104257 }
104258
104259- if (local->open_count == 0) {
104260+ if (local_read(&local->open_count) == 0) {
104261 res = drv_start(local);
104262 if (res)
104263 goto err_del_bss;
104264@@ -579,7 +579,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
104265 res = drv_add_interface(local, sdata);
104266 if (res)
104267 goto err_stop;
104268- } else if (local->monitors == 0 && local->open_count == 0) {
104269+ } else if (local->monitors == 0 && local_read(&local->open_count) == 0) {
104270 res = ieee80211_add_virtual_monitor(local);
104271 if (res)
104272 goto err_stop;
104273@@ -688,7 +688,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
104274 atomic_inc(&local->iff_promiscs);
104275
104276 if (coming_up)
104277- local->open_count++;
104278+ local_inc(&local->open_count);
104279
104280 if (hw_reconf_flags)
104281 ieee80211_hw_config(local, hw_reconf_flags);
104282@@ -726,7 +726,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
104283 err_del_interface:
104284 drv_remove_interface(local, sdata);
104285 err_stop:
104286- if (!local->open_count)
104287+ if (!local_read(&local->open_count))
104288 drv_stop(local);
104289 err_del_bss:
104290 sdata->bss = NULL;
104291@@ -892,7 +892,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
104292 }
104293
104294 if (going_down)
104295- local->open_count--;
104296+ local_dec(&local->open_count);
104297
104298 switch (sdata->vif.type) {
104299 case NL80211_IFTYPE_AP_VLAN:
104300@@ -954,7 +954,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
104301 }
104302 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
104303
104304- if (local->open_count == 0)
104305+ if (local_read(&local->open_count) == 0)
104306 ieee80211_clear_tx_pending(local);
104307
104308 /*
104309@@ -997,7 +997,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
104310 if (cancel_scan)
104311 flush_delayed_work(&local->scan_work);
104312
104313- if (local->open_count == 0) {
104314+ if (local_read(&local->open_count) == 0) {
104315 ieee80211_stop_device(local);
104316
104317 /* no reconfiguring after stop! */
104318@@ -1008,7 +1008,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
104319 ieee80211_configure_filter(local);
104320 ieee80211_hw_config(local, hw_reconf_flags);
104321
104322- if (local->monitors == local->open_count)
104323+ if (local->monitors == local_read(&local->open_count))
104324 ieee80211_add_virtual_monitor(local);
104325 }
104326
104327diff --git a/net/mac80211/main.c b/net/mac80211/main.c
104328index 0de7c93..884b2ca 100644
104329--- a/net/mac80211/main.c
104330+++ b/net/mac80211/main.c
104331@@ -175,7 +175,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
104332 changed &= ~(IEEE80211_CONF_CHANGE_CHANNEL |
104333 IEEE80211_CONF_CHANGE_POWER);
104334
104335- if (changed && local->open_count) {
104336+ if (changed && local_read(&local->open_count)) {
104337 ret = drv_config(local, changed);
104338 /*
104339 * Goal:
104340diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
104341index 4c5192e..04cc0d8 100644
104342--- a/net/mac80211/pm.c
104343+++ b/net/mac80211/pm.c
104344@@ -12,7 +12,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
104345 struct ieee80211_sub_if_data *sdata;
104346 struct sta_info *sta;
104347
104348- if (!local->open_count)
104349+ if (!local_read(&local->open_count))
104350 goto suspend;
104351
104352 ieee80211_scan_cancel(local);
104353@@ -59,7 +59,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
104354 cancel_work_sync(&local->dynamic_ps_enable_work);
104355 del_timer_sync(&local->dynamic_ps_timer);
104356
104357- local->wowlan = wowlan && local->open_count;
104358+ local->wowlan = wowlan && local_read(&local->open_count);
104359 if (local->wowlan) {
104360 int err = drv_suspend(local, wowlan);
104361 if (err < 0) {
104362@@ -125,7 +125,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
104363 WARN_ON(!list_empty(&local->chanctx_list));
104364
104365 /* stop hardware - this must stop RX */
104366- if (local->open_count)
104367+ if (local_read(&local->open_count))
104368 ieee80211_stop_device(local);
104369
104370 suspend:
104371diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
104372index 6081329..ab23834 100644
104373--- a/net/mac80211/rate.c
104374+++ b/net/mac80211/rate.c
104375@@ -720,7 +720,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
104376
104377 ASSERT_RTNL();
104378
104379- if (local->open_count)
104380+ if (local_read(&local->open_count))
104381 return -EBUSY;
104382
104383 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
104384diff --git a/net/mac80211/util.c b/net/mac80211/util.c
104385index 3c61060..7bed2e3 100644
104386--- a/net/mac80211/util.c
104387+++ b/net/mac80211/util.c
104388@@ -1669,7 +1669,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
104389 }
104390 #endif
104391 /* everything else happens only if HW was up & running */
104392- if (!local->open_count)
104393+ if (!local_read(&local->open_count))
104394 goto wake_up;
104395
104396 /*
104397@@ -1895,7 +1895,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
104398 local->in_reconfig = false;
104399 barrier();
104400
104401- if (local->monitors == local->open_count && local->monitors > 0)
104402+ if (local->monitors == local_read(&local->open_count) && local->monitors > 0)
104403 ieee80211_add_virtual_monitor(local);
104404
104405 /*
104406diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
104407index ae5096ab..e5aa70a 100644
104408--- a/net/netfilter/Kconfig
104409+++ b/net/netfilter/Kconfig
104410@@ -1105,6 +1105,16 @@ config NETFILTER_XT_MATCH_ESP
104411
104412 To compile it as a module, choose M here. If unsure, say N.
104413
104414+config NETFILTER_XT_MATCH_GRADM
104415+ tristate '"gradm" match support'
104416+ depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
104417+ depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
104418+ ---help---
104419+ The gradm match allows to match on grsecurity RBAC being enabled.
104420+ It is useful when iptables rules are applied early on bootup to
104421+ prevent connections to the machine (except from a trusted host)
104422+ while the RBAC system is disabled.
104423+
104424 config NETFILTER_XT_MATCH_HASHLIMIT
104425 tristate '"hashlimit" match support'
104426 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
104427diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
104428index a9571be..c59e173 100644
104429--- a/net/netfilter/Makefile
104430+++ b/net/netfilter/Makefile
104431@@ -137,6 +137,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
104432 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
104433 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
104434 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
104435+obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
104436 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
104437 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
104438 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
104439diff --git a/net/netfilter/ipset/ip_set_core.c b/net/netfilter/ipset/ip_set_core.c
104440index d259da3..6a32b2c 100644
104441--- a/net/netfilter/ipset/ip_set_core.c
104442+++ b/net/netfilter/ipset/ip_set_core.c
104443@@ -1952,7 +1952,7 @@ done:
104444 return ret;
104445 }
104446
104447-static struct nf_sockopt_ops so_set __read_mostly = {
104448+static struct nf_sockopt_ops so_set = {
104449 .pf = PF_INET,
104450 .get_optmin = SO_IP_SET,
104451 .get_optmax = SO_IP_SET + 1,
104452diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
104453index b0f7b62..0541842 100644
104454--- a/net/netfilter/ipvs/ip_vs_conn.c
104455+++ b/net/netfilter/ipvs/ip_vs_conn.c
104456@@ -572,7 +572,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
104457 /* Increase the refcnt counter of the dest */
104458 ip_vs_dest_hold(dest);
104459
104460- conn_flags = atomic_read(&dest->conn_flags);
104461+ conn_flags = atomic_read_unchecked(&dest->conn_flags);
104462 if (cp->protocol != IPPROTO_UDP)
104463 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
104464 flags = cp->flags;
104465@@ -922,7 +922,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p, int dest_af,
104466
104467 cp->control = NULL;
104468 atomic_set(&cp->n_control, 0);
104469- atomic_set(&cp->in_pkts, 0);
104470+ atomic_set_unchecked(&cp->in_pkts, 0);
104471
104472 cp->packet_xmit = NULL;
104473 cp->app = NULL;
104474@@ -1229,7 +1229,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
104475
104476 /* Don't drop the entry if its number of incoming packets is not
104477 located in [0, 8] */
104478- i = atomic_read(&cp->in_pkts);
104479+ i = atomic_read_unchecked(&cp->in_pkts);
104480 if (i > 8 || i < 0) return 0;
104481
104482 if (!todrop_rate[i]) return 0;
104483diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
104484index 990decb..5075248 100644
104485--- a/net/netfilter/ipvs/ip_vs_core.c
104486+++ b/net/netfilter/ipvs/ip_vs_core.c
104487@@ -568,7 +568,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
104488 ret = cp->packet_xmit(skb, cp, pd->pp, iph);
104489 /* do not touch skb anymore */
104490
104491- atomic_inc(&cp->in_pkts);
104492+ atomic_inc_unchecked(&cp->in_pkts);
104493 ip_vs_conn_put(cp);
104494 return ret;
104495 }
104496@@ -1712,7 +1712,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
104497 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
104498 pkts = sysctl_sync_threshold(ipvs);
104499 else
104500- pkts = atomic_add_return(1, &cp->in_pkts);
104501+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
104502
104503 if (ipvs->sync_state & IP_VS_STATE_MASTER)
104504 ip_vs_sync_conn(net, cp, pkts);
104505diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
104506index ac7ba68..9735acb9 100644
104507--- a/net/netfilter/ipvs/ip_vs_ctl.c
104508+++ b/net/netfilter/ipvs/ip_vs_ctl.c
104509@@ -800,7 +800,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
104510 */
104511 ip_vs_rs_hash(ipvs, dest);
104512 }
104513- atomic_set(&dest->conn_flags, conn_flags);
104514+ atomic_set_unchecked(&dest->conn_flags, conn_flags);
104515
104516 /* bind the service */
104517 old_svc = rcu_dereference_protected(dest->svc, 1);
104518@@ -1665,7 +1665,7 @@ proc_do_sync_ports(struct ctl_table *table, int write,
104519 * align with netns init in ip_vs_control_net_init()
104520 */
104521
104522-static struct ctl_table vs_vars[] = {
104523+static ctl_table_no_const vs_vars[] __read_only = {
104524 {
104525 .procname = "amemthresh",
104526 .maxlen = sizeof(int),
104527@@ -2000,7 +2000,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
104528 " %-7s %-6d %-10d %-10d\n",
104529 &dest->addr.in6,
104530 ntohs(dest->port),
104531- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
104532+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
104533 atomic_read(&dest->weight),
104534 atomic_read(&dest->activeconns),
104535 atomic_read(&dest->inactconns));
104536@@ -2011,7 +2011,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
104537 "%-7s %-6d %-10d %-10d\n",
104538 ntohl(dest->addr.ip),
104539 ntohs(dest->port),
104540- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
104541+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
104542 atomic_read(&dest->weight),
104543 atomic_read(&dest->activeconns),
104544 atomic_read(&dest->inactconns));
104545@@ -2500,7 +2500,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
104546
104547 entry.addr = dest->addr.ip;
104548 entry.port = dest->port;
104549- entry.conn_flags = atomic_read(&dest->conn_flags);
104550+ entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
104551 entry.weight = atomic_read(&dest->weight);
104552 entry.u_threshold = dest->u_threshold;
104553 entry.l_threshold = dest->l_threshold;
104554@@ -3040,7 +3040,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
104555 if (nla_put(skb, IPVS_DEST_ATTR_ADDR, sizeof(dest->addr), &dest->addr) ||
104556 nla_put_be16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
104557 nla_put_u32(skb, IPVS_DEST_ATTR_FWD_METHOD,
104558- (atomic_read(&dest->conn_flags) &
104559+ (atomic_read_unchecked(&dest->conn_flags) &
104560 IP_VS_CONN_F_FWD_MASK)) ||
104561 nla_put_u32(skb, IPVS_DEST_ATTR_WEIGHT,
104562 atomic_read(&dest->weight)) ||
104563@@ -3673,7 +3673,7 @@ static int __net_init ip_vs_control_net_init_sysctl(struct net *net)
104564 {
104565 int idx;
104566 struct netns_ipvs *ipvs = net_ipvs(net);
104567- struct ctl_table *tbl;
104568+ ctl_table_no_const *tbl;
104569
104570 atomic_set(&ipvs->dropentry, 0);
104571 spin_lock_init(&ipvs->dropentry_lock);
104572diff --git a/net/netfilter/ipvs/ip_vs_lblc.c b/net/netfilter/ipvs/ip_vs_lblc.c
104573index 127f140..553d652 100644
104574--- a/net/netfilter/ipvs/ip_vs_lblc.c
104575+++ b/net/netfilter/ipvs/ip_vs_lblc.c
104576@@ -118,7 +118,7 @@ struct ip_vs_lblc_table {
104577 * IPVS LBLC sysctl table
104578 */
104579 #ifdef CONFIG_SYSCTL
104580-static struct ctl_table vs_vars_table[] = {
104581+static ctl_table_no_const vs_vars_table[] __read_only = {
104582 {
104583 .procname = "lblc_expiration",
104584 .data = NULL,
104585diff --git a/net/netfilter/ipvs/ip_vs_lblcr.c b/net/netfilter/ipvs/ip_vs_lblcr.c
104586index 2229d2d..b32b785 100644
104587--- a/net/netfilter/ipvs/ip_vs_lblcr.c
104588+++ b/net/netfilter/ipvs/ip_vs_lblcr.c
104589@@ -289,7 +289,7 @@ struct ip_vs_lblcr_table {
104590 * IPVS LBLCR sysctl table
104591 */
104592
104593-static struct ctl_table vs_vars_table[] = {
104594+static ctl_table_no_const vs_vars_table[] __read_only = {
104595 {
104596 .procname = "lblcr_expiration",
104597 .data = NULL,
104598diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
104599index 7162c86..9eeb60e 100644
104600--- a/net/netfilter/ipvs/ip_vs_sync.c
104601+++ b/net/netfilter/ipvs/ip_vs_sync.c
104602@@ -609,7 +609,7 @@ static void ip_vs_sync_conn_v0(struct net *net, struct ip_vs_conn *cp,
104603 cp = cp->control;
104604 if (cp) {
104605 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
104606- pkts = atomic_add_return(1, &cp->in_pkts);
104607+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
104608 else
104609 pkts = sysctl_sync_threshold(ipvs);
104610 ip_vs_sync_conn(net, cp->control, pkts);
104611@@ -771,7 +771,7 @@ control:
104612 if (!cp)
104613 return;
104614 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
104615- pkts = atomic_add_return(1, &cp->in_pkts);
104616+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
104617 else
104618 pkts = sysctl_sync_threshold(ipvs);
104619 goto sloop;
104620@@ -901,7 +901,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
104621
104622 if (opt)
104623 memcpy(&cp->in_seq, opt, sizeof(*opt));
104624- atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
104625+ atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
104626 cp->state = state;
104627 cp->old_state = cp->state;
104628 /*
104629diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
104630index bd90bf8..816a020d 100644
104631--- a/net/netfilter/ipvs/ip_vs_xmit.c
104632+++ b/net/netfilter/ipvs/ip_vs_xmit.c
104633@@ -1215,7 +1215,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
104634 else
104635 rc = NF_ACCEPT;
104636 /* do not touch skb anymore */
104637- atomic_inc(&cp->in_pkts);
104638+ atomic_inc_unchecked(&cp->in_pkts);
104639 goto out;
104640 }
104641
104642@@ -1308,7 +1308,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
104643 else
104644 rc = NF_ACCEPT;
104645 /* do not touch skb anymore */
104646- atomic_inc(&cp->in_pkts);
104647+ atomic_inc_unchecked(&cp->in_pkts);
104648 goto out;
104649 }
104650
104651diff --git a/net/netfilter/nf_conntrack_acct.c b/net/netfilter/nf_conntrack_acct.c
104652index a4b5e2a..13b1de3 100644
104653--- a/net/netfilter/nf_conntrack_acct.c
104654+++ b/net/netfilter/nf_conntrack_acct.c
104655@@ -62,7 +62,7 @@ static struct nf_ct_ext_type acct_extend __read_mostly = {
104656 #ifdef CONFIG_SYSCTL
104657 static int nf_conntrack_acct_init_sysctl(struct net *net)
104658 {
104659- struct ctl_table *table;
104660+ ctl_table_no_const *table;
104661
104662 table = kmemdup(acct_sysctl_table, sizeof(acct_sysctl_table),
104663 GFP_KERNEL);
104664diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
104665index 5016a69..594f8e9 100644
104666--- a/net/netfilter/nf_conntrack_core.c
104667+++ b/net/netfilter/nf_conntrack_core.c
104668@@ -1739,6 +1739,10 @@ void nf_conntrack_init_end(void)
104669 #define DYING_NULLS_VAL ((1<<30)+1)
104670 #define TEMPLATE_NULLS_VAL ((1<<30)+2)
104671
104672+#ifdef CONFIG_GRKERNSEC_HIDESYM
104673+static atomic_unchecked_t conntrack_cache_id = ATOMIC_INIT(0);
104674+#endif
104675+
104676 int nf_conntrack_init_net(struct net *net)
104677 {
104678 int ret = -ENOMEM;
104679@@ -1764,7 +1768,11 @@ int nf_conntrack_init_net(struct net *net)
104680 if (!net->ct.stat)
104681 goto err_pcpu_lists;
104682
104683+#ifdef CONFIG_GRKERNSEC_HIDESYM
104684+ net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%08x", atomic_inc_return_unchecked(&conntrack_cache_id));
104685+#else
104686 net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%p", net);
104687+#endif
104688 if (!net->ct.slabname)
104689 goto err_slabname;
104690
104691diff --git a/net/netfilter/nf_conntrack_ecache.c b/net/netfilter/nf_conntrack_ecache.c
104692index 4e78c57..ec8fb74 100644
104693--- a/net/netfilter/nf_conntrack_ecache.c
104694+++ b/net/netfilter/nf_conntrack_ecache.c
104695@@ -264,7 +264,7 @@ static struct nf_ct_ext_type event_extend __read_mostly = {
104696 #ifdef CONFIG_SYSCTL
104697 static int nf_conntrack_event_init_sysctl(struct net *net)
104698 {
104699- struct ctl_table *table;
104700+ ctl_table_no_const *table;
104701
104702 table = kmemdup(event_sysctl_table, sizeof(event_sysctl_table),
104703 GFP_KERNEL);
104704diff --git a/net/netfilter/nf_conntrack_helper.c b/net/netfilter/nf_conntrack_helper.c
104705index 5b3eae7..dd4b8fe 100644
104706--- a/net/netfilter/nf_conntrack_helper.c
104707+++ b/net/netfilter/nf_conntrack_helper.c
104708@@ -57,7 +57,7 @@ static struct ctl_table helper_sysctl_table[] = {
104709
104710 static int nf_conntrack_helper_init_sysctl(struct net *net)
104711 {
104712- struct ctl_table *table;
104713+ ctl_table_no_const *table;
104714
104715 table = kmemdup(helper_sysctl_table, sizeof(helper_sysctl_table),
104716 GFP_KERNEL);
104717diff --git a/net/netfilter/nf_conntrack_proto.c b/net/netfilter/nf_conntrack_proto.c
104718index b65d586..beec902 100644
104719--- a/net/netfilter/nf_conntrack_proto.c
104720+++ b/net/netfilter/nf_conntrack_proto.c
104721@@ -52,7 +52,7 @@ nf_ct_register_sysctl(struct net *net,
104722
104723 static void
104724 nf_ct_unregister_sysctl(struct ctl_table_header **header,
104725- struct ctl_table **table,
104726+ ctl_table_no_const **table,
104727 unsigned int users)
104728 {
104729 if (users > 0)
104730diff --git a/net/netfilter/nf_conntrack_standalone.c b/net/netfilter/nf_conntrack_standalone.c
104731index cf65a1e..2f291e9 100644
104732--- a/net/netfilter/nf_conntrack_standalone.c
104733+++ b/net/netfilter/nf_conntrack_standalone.c
104734@@ -471,7 +471,7 @@ static struct ctl_table nf_ct_netfilter_table[] = {
104735
104736 static int nf_conntrack_standalone_init_sysctl(struct net *net)
104737 {
104738- struct ctl_table *table;
104739+ ctl_table_no_const *table;
104740
104741 table = kmemdup(nf_ct_sysctl_table, sizeof(nf_ct_sysctl_table),
104742 GFP_KERNEL);
104743diff --git a/net/netfilter/nf_conntrack_timestamp.c b/net/netfilter/nf_conntrack_timestamp.c
104744index 7a394df..bd91a8a 100644
104745--- a/net/netfilter/nf_conntrack_timestamp.c
104746+++ b/net/netfilter/nf_conntrack_timestamp.c
104747@@ -42,7 +42,7 @@ static struct nf_ct_ext_type tstamp_extend __read_mostly = {
104748 #ifdef CONFIG_SYSCTL
104749 static int nf_conntrack_tstamp_init_sysctl(struct net *net)
104750 {
104751- struct ctl_table *table;
104752+ ctl_table_no_const *table;
104753
104754 table = kmemdup(tstamp_sysctl_table, sizeof(tstamp_sysctl_table),
104755 GFP_KERNEL);
104756diff --git a/net/netfilter/nf_log.c b/net/netfilter/nf_log.c
104757index d719764..311bc60 100644
104758--- a/net/netfilter/nf_log.c
104759+++ b/net/netfilter/nf_log.c
104760@@ -353,7 +353,7 @@ static const struct file_operations nflog_file_ops = {
104761
104762 #ifdef CONFIG_SYSCTL
104763 static char nf_log_sysctl_fnames[NFPROTO_NUMPROTO-NFPROTO_UNSPEC][3];
104764-static struct ctl_table nf_log_sysctl_table[NFPROTO_NUMPROTO+1];
104765+static ctl_table_no_const nf_log_sysctl_table[NFPROTO_NUMPROTO+1] __read_only;
104766
104767 static int nf_log_proc_dostring(struct ctl_table *table, int write,
104768 void __user *buffer, size_t *lenp, loff_t *ppos)
104769@@ -384,14 +384,16 @@ static int nf_log_proc_dostring(struct ctl_table *table, int write,
104770 rcu_assign_pointer(net->nf.nf_loggers[tindex], logger);
104771 mutex_unlock(&nf_log_mutex);
104772 } else {
104773+ ctl_table_no_const nf_log_table = *table;
104774+
104775 mutex_lock(&nf_log_mutex);
104776 logger = rcu_dereference_protected(net->nf.nf_loggers[tindex],
104777 lockdep_is_held(&nf_log_mutex));
104778 if (!logger)
104779- table->data = "NONE";
104780+ nf_log_table.data = "NONE";
104781 else
104782- table->data = logger->name;
104783- r = proc_dostring(table, write, buffer, lenp, ppos);
104784+ nf_log_table.data = logger->name;
104785+ r = proc_dostring(&nf_log_table, write, buffer, lenp, ppos);
104786 mutex_unlock(&nf_log_mutex);
104787 }
104788
104789diff --git a/net/netfilter/nf_sockopt.c b/net/netfilter/nf_sockopt.c
104790index c68c1e5..8b5d670 100644
104791--- a/net/netfilter/nf_sockopt.c
104792+++ b/net/netfilter/nf_sockopt.c
104793@@ -43,7 +43,7 @@ int nf_register_sockopt(struct nf_sockopt_ops *reg)
104794 }
104795 }
104796
104797- list_add(&reg->list, &nf_sockopts);
104798+ pax_list_add((struct list_head *)&reg->list, &nf_sockopts);
104799 out:
104800 mutex_unlock(&nf_sockopt_mutex);
104801 return ret;
104802@@ -53,7 +53,7 @@ EXPORT_SYMBOL(nf_register_sockopt);
104803 void nf_unregister_sockopt(struct nf_sockopt_ops *reg)
104804 {
104805 mutex_lock(&nf_sockopt_mutex);
104806- list_del(&reg->list);
104807+ pax_list_del((struct list_head *)&reg->list);
104808 mutex_unlock(&nf_sockopt_mutex);
104809 }
104810 EXPORT_SYMBOL(nf_unregister_sockopt);
104811diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
104812index 5f1be5b..2cba8cd 100644
104813--- a/net/netfilter/nfnetlink_log.c
104814+++ b/net/netfilter/nfnetlink_log.c
104815@@ -80,7 +80,7 @@ static int nfnl_log_net_id __read_mostly;
104816 struct nfnl_log_net {
104817 spinlock_t instances_lock;
104818 struct hlist_head instance_table[INSTANCE_BUCKETS];
104819- atomic_t global_seq;
104820+ atomic_unchecked_t global_seq;
104821 };
104822
104823 static struct nfnl_log_net *nfnl_log_pernet(struct net *net)
104824@@ -563,7 +563,7 @@ __build_packet_message(struct nfnl_log_net *log,
104825 /* global sequence number */
104826 if ((inst->flags & NFULNL_CFG_F_SEQ_GLOBAL) &&
104827 nla_put_be32(inst->skb, NFULA_SEQ_GLOBAL,
104828- htonl(atomic_inc_return(&log->global_seq))))
104829+ htonl(atomic_inc_return_unchecked(&log->global_seq))))
104830 goto nla_put_failure;
104831
104832 if (data_len) {
104833diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
104834new file mode 100644
104835index 0000000..c566332
104836--- /dev/null
104837+++ b/net/netfilter/xt_gradm.c
104838@@ -0,0 +1,51 @@
104839+/*
104840+ * gradm match for netfilter
104841